Skip to content

Commit 3a8491d

Browse files
committed
[CHERI CSA] Disable subobject-representability diagnostics on packed structs.
On a packed struct, the layout is likely to have been intentionally chosen, often to conform with some external definition, so diagnostics here are very likely to be noise.
1 parent eb519f6 commit 3a8491d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/CHERI/SubObjectRepresentabilityChecker.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ std::unique_ptr<BugReport> checkFieldImpl(const FieldDecl *D, BugReporter &BR,
102102
const BugType &BT) {
103103
QualType T = D->getType();
104104

105+
// If the parent struct is explicitly marked as packed, then don't emit a
106+
// diagnostic, as this layout is likely intentional.
107+
if (D->getParent()->hasAttr<PackedAttr>())
108+
return nullptr;
109+
105110
ASTContext &ASTCtx = BR.getContext();
106111
uint64_t Offset = ASTCtx.getFieldOffset(D) / 8;
107112
if (Offset > 0) {

clang/test/Analysis/Checkers/CHERI/subobject-representability-mips64.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ struct R1 {
1515
int c[2];
1616
char a[0x1000]; // no warn
1717
} f3good __attribute__((aligned(8)));
18+
struct __attribute__((packed)) {
19+
char c;
20+
char a[0x1000]; // no warn
21+
} f4good;
1822
} s2;
1923
} s1;
2024

0 commit comments

Comments
 (0)