mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 09:26:41 +00:00

The commit adds serialization and de-serialization implementations for the stored regions. Basically, the serialized representation of the regions of a PP is a (ordered) sequence of source location encodings. For de-serialization, regions from loaded files are stored by their ASTs. When later one queries if a loaded location L is in an opt-out region, PP looks up the regions of the loaded AST where L is at. (Background if helps: a pair of `#pragma clang unsafe_buffer_usage begin/end` pragmas marks a warning-opt-out region. The begin and end locations (opt-out regions) are stored in preprocessor instances (PP) and will be queried by the `-Wunsafe-buffer-usage` analyzer.) The reported issue at upstream: https://github.com/llvm/llvm-project/issues/90501 rdar://124035402
28 lines
761 B
C++
28 lines
761 B
C++
// The original example from https://github.com/llvm/llvm-project/issues/90501
|
|
|
|
// Test without PCH
|
|
// RUN: %clang_cc1 -Wno-unused-value -Wunsafe-buffer-usage -std=c++20 -include %s -verify %s
|
|
// Test with PCH
|
|
// RUN: %clang_cc1 -Wno-unused-value -std=c++20 -emit-pch -o %t %s
|
|
// RUN: %clang_cc1 -Wno-unused-value -Wunsafe-buffer-usage -std=c++20 -include-pch %t -verify %s
|
|
|
|
#ifndef A_H
|
|
#define A_H
|
|
|
|
int a(int *s) {
|
|
s[2]; // <- expected warning here
|
|
#pragma clang unsafe_buffer_usage begin
|
|
return s[1];
|
|
#pragma clang unsafe_buffer_usage end
|
|
}
|
|
|
|
#else
|
|
// expected-warning@-7{{unsafe buffer access}}
|
|
// expected-note@-8{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}}
|
|
int main() {
|
|
int s[] = {1, 2, 3};
|
|
return a(s);
|
|
}
|
|
|
|
#endif
|