[clang] [AST] Avoid typedef alias for PointerUnion member in DeclGroupRef (PR #248015)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 2 02:37:24 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Romaric Jodin (rjodinchr)
<details>
<summary>Changes</summary>
In #<!-- -->238331, `DeclGroupRef` declared `using UnionTy = llvm::PointerUnion<Decl *, DeclGroup *>;` before `UnionTy D;`.
GCC 12 and earlier do not propagate `TYPE_TYPELESS_STORAGE` from `PointerUnion`'s `PunnedPointer` byte storage to pre-existing typedef variants created before template instantiation (fixed in GCC 13 by commit b332131359). As a result, `DeclGroupRef` did not inherit typeless storage and GCC's DSE dropped stores to `DeclGroupRef` before `getAddrOfPtr1()` reads, causing OpenMP parser crashes on GCC 11/12 buildbots.
Declare `D` directly with `llvm::PointerUnion<Decl *, DeclGroup *>` instead of through `UnionTy`.
Follow-up to #<!-- -->238331
---
Full diff: https://github.com/llvm/llvm-project/pull/248015.diff
1 Files Affected:
- (modified) clang/include/clang/AST/DeclGroup.h (+6-3)
``````````diff
diff --git a/clang/include/clang/AST/DeclGroup.h b/clang/include/clang/AST/DeclGroup.h
index 9e27c791482f4..24dc72697c086 100644
--- a/clang/include/clang/AST/DeclGroup.h
+++ b/clang/include/clang/AST/DeclGroup.h
@@ -46,8 +46,11 @@ class DeclGroup final : private llvm::TrailingObjects<DeclGroup, Decl *> {
};
class DeclGroupRef {
- using UnionTy = llvm::PointerUnion<Decl *, DeclGroup *>;
- UnionTy D;
+ // Declare D using llvm::PointerUnion directly rather than a type alias to an
+ // incomplete instantiation: GCC <= 12 does not propagate
+ // TYPE_TYPELESS_STORAGE to pre-existing typedef variants, which causes DSE to
+ // drop stores to DeclGroupRef before getAddrOfPtr1() reads.
+ llvm::PointerUnion<Decl *, DeclGroup *> D;
public:
DeclGroupRef() = default;
@@ -114,7 +117,7 @@ class DeclGroupRef {
void *getAsOpaquePtr() const { return D.getOpaqueValue(); }
static DeclGroupRef getFromOpaquePtr(void *Ptr) {
DeclGroupRef X;
- X.D = UnionTy::getFromOpaqueValue(Ptr);
+ X.D = llvm::PointerUnion<Decl *, DeclGroup *>::getFromOpaqueValue(Ptr);
return X;
}
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/248015
More information about the cfe-commits
mailing list