File tree Expand file tree Collapse file tree 2 files changed +34
-8
lines changed Expand file tree Collapse file tree 2 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -78,17 +78,18 @@ llvm::MDNode *CodeGenTBAA::getChar() {
78
78
79
79
static bool TypeHasMayAlias (QualType QTy) {
80
80
// Tagged types have declarations, and therefore may have attributes.
81
- if (const TagType *TTy = dyn_cast<TagType>(QTy))
82
- return TTy->getDecl ()->hasAttr <MayAliasAttr>();
81
+ if (auto *TD = QTy->getAsTagDecl ())
82
+ if (TD->hasAttr <MayAliasAttr>())
83
+ return true ;
83
84
84
- // Typedef types have declarations, and therefore may have attributes.
85
- if (const TypedefType *TTy = dyn_cast<TypedefType>(QTy)) {
86
- if (TTy->getDecl ()->hasAttr <MayAliasAttr>())
85
+ // Also look for may_alias as a declaration attribute on a typedef.
86
+ // FIXME: We should follow GCC and model may_alias as a type attribute
87
+ // rather than as a declaration attribute.
88
+ while (auto *TT = QTy->getAs <TypedefType>()) {
89
+ if (TT->getDecl ()->hasAttr <MayAliasAttr>())
87
90
return true ;
88
- // Also, their underlying types may have relevant attributes.
89
- return TypeHasMayAlias (TTy->desugar ());
91
+ QTy = TT->desugar ();
90
92
}
91
-
92
93
return false ;
93
94
}
94
95
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 %s -triple %itanium_abi_triple -emit-llvm -O2 -disable-llvm-passes -o - | FileCheck %s
2
+ // RUN: %clang_cc1 %s -triple %ms_abi_triple -emit-llvm -O2 -disable-llvm-passes -o - | FileCheck %s
3
+
4
+ enum class __attribute__ ((may_alias)) E {};
5
+
6
+ template <typename T> struct A {
7
+ using B __attribute__ ((may_alias)) = enum {};
8
+ };
9
+
10
+ template <typename T> using Alias = typename A<T>::B;
11
+
12
+ // CHECK-LABEL: define {{.*}}foo
13
+ // CHECK: load i{{[0-9]*}}, {{.*}}, !tbaa ![[MAY_ALIAS:[^ ,]*]]
14
+ auto foo (E &r) { return r; }
15
+
16
+ // CHECK-LABEL: define {{.*}}goo
17
+ // CHECK: load i{{[0-9]*}}, {{.*}}, !tbaa ![[MAY_ALIAS]]
18
+ auto goo (A<int >::B &r) { return r; }
19
+
20
+ // CHECK-LABEL: define {{.*}}hoo
21
+ // CHECK: load i{{[0-9]*}}, {{.*}}, !tbaa ![[MAY_ALIAS]]
22
+ auto hoo (Alias<int > &r) { return r; }
23
+
24
+ // CHECK: ![[CHAR:.*]] = !{!"omnipotent char", !{{.*}}, i64 0}
25
+ // CHECK: ![[MAY_ALIAS]] = !{![[CHAR]], ![[CHAR]], i64 0}
You can’t perform that action at this time.
0 commit comments