diff options
author | Richard Smith <richard@metafoo.co.uk> | 2019-12-11 14:03:35 -0800 |
---|---|---|
committer | Richard Smith <richard@metafoo.co.uk> | 2019-12-11 14:04:37 -0800 |
commit | e0e07a7e414e818788144511de0c6328285c43cd (patch) | |
tree | 9954f1e102f4018ffeef2a799beef484980ab9cc /clang/lib | |
parent | cdf5cfea8e5204e5d2facd6663c4b49b9e0378e9 (diff) | |
download | bcm5719-llvm-e0e07a7e414e818788144511de0c6328285c43cd.tar.gz bcm5719-llvm-e0e07a7e414e818788144511de0c6328285c43cd.zip |
Fix detection of __attribute__((may_alias)) to properly look through
type sugar.
We previously missed the attribute in a lot of cases in C++, because
there's often other type sugar there (eg, ElaboratedType).
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CodeGenTBAA.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp index 09de9591de7..7d730cb1ed1 100644 --- a/clang/lib/CodeGen/CodeGenTBAA.cpp +++ b/clang/lib/CodeGen/CodeGenTBAA.cpp @@ -78,17 +78,18 @@ llvm::MDNode *CodeGenTBAA::getChar() { static bool TypeHasMayAlias(QualType QTy) { // Tagged types have declarations, and therefore may have attributes. - if (const TagType *TTy = dyn_cast<TagType>(QTy)) - return TTy->getDecl()->hasAttr<MayAliasAttr>(); + if (auto *TD = QTy->getAsTagDecl()) + if (TD->hasAttr<MayAliasAttr>()) + return true; - // Typedef types have declarations, and therefore may have attributes. - if (const TypedefType *TTy = dyn_cast<TypedefType>(QTy)) { - if (TTy->getDecl()->hasAttr<MayAliasAttr>()) + // Also look for may_alias as a declaration attribute on a typedef. + // FIXME: We should follow GCC and model may_alias as a type attribute + // rather than as a declaration attribute. + while (auto *TT = QTy->getAs<TypedefType>()) { + if (TT->getDecl()->hasAttr<MayAliasAttr>()) return true; - // Also, their underlying types may have relevant attributes. - return TypeHasMayAlias(TTy->desugar()); + QTy = TT->desugar(); } - return false; } |