[clang] [Sema] Diagnose taking the address of a #pragma pack member (PR #219096)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 5 02:55:41 PDT 2026


================
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-linux-gnu -fpack-struct=1 -DPACK_STRUCT -verify=pack-struct %s
+// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-darwin -DMAC68K -verify=mac68k %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-linux-gnu -target-feature +avx512f -DPACK16 -verify=itanium %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-windows-msvc -target-feature +avx512f -DPACK16 -verify=ms %s
+
+extern void f1(int *);
+
+#ifdef PACK_STRUCT
+struct S {
+  char c;
+  int x;
+};
+
+void g0(struct S *p) {
+  f1(&p->x); // pack-struct-warning {{packed member 'x' of class or structure 'S'}}
----------------
Endilll wrote:

It's out of scope of this PR, but I don't particularly like the wording of the existing diagnostic. I'd prefer something along the lines of `taking address of a packed member [. . .]` at very least, if not followed by `; this can result in an invalid pointer`.

https://github.com/llvm/llvm-project/pull/219096


More information about the cfe-commits mailing list