[cfe-commits] r121734 - in /cfe/trunk: lib/CodeGen/CodeGenTBAA.cpp test/CodeGen/may-alias.c
Dan Gohman
gohman at apple.com
Mon Dec 13 15:51:08 PST 2010
Author: djg
Date: Mon Dec 13 17:51:08 2010
New Revision: 121734
URL: http://llvm.org/viewvc/llvm-project?rev=121734&view=rev
Log:
Implement CodeGen support for the may_alias attribute.
Added:
cfe/trunk/test/CodeGen/may-alias.c
Modified:
cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=121734&r1=121733&r2=121734&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Mon Dec 13 17:51:08 2010
@@ -77,8 +77,29 @@
return llvm::MDNode::get(VMContext, Ops, llvm::array_lengthof(Ops) - !Flags);
}
+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>();
+
+ // Typedef types have declarations, and therefore may have attributes.
+ if (const TypedefType *TTy = dyn_cast<TypedefType>(QTy)) {
+ if (TTy->getDecl()->hasAttr<MayAliasAttr>())
+ return true;
+ // Also, their underlying types may have relevant attributes.
+ return TypeHasMayAlias(TTy->desugar());
+ }
+
+ return false;
+}
+
llvm::MDNode *
CodeGenTBAA::getTBAAInfo(QualType QTy) {
+ // If the type has the may_alias attribute (even on a typedef), it is
+ // effectively in the general char alias class.
+ if (TypeHasMayAlias(QTy))
+ return getChar();
+
Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
if (llvm::MDNode *N = MetadataCache[Ty])
Added: cfe/trunk/test/CodeGen/may-alias.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/may-alias.c?rev=121734&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/may-alias.c (added)
+++ cfe/trunk/test/CodeGen/may-alias.c Mon Dec 13 17:51:08 2010
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -Werror -triple i386-unknown-unknown -emit-llvm -O1 -disable-llvm-optzns -o %t %s
+// RUN: FileCheck < %t %s
+
+// Types with the may_alias attribute should be considered equivalent
+// to char for aliasing.
+
+typedef int __attribute__((may_alias)) aliasing_int;
+
+void test0(aliasing_int *ai, int *i)
+{
+ *ai = 0;
+ *i = 1;
+}
+
+// CHECK: store i32 0, i32* %tmp, !tbaa !1
+// CHECK: store i32 1, i32* %tmp1, !tbaa !3
+
+// CHECK: !0 = metadata !{metadata !"any pointer", metadata !1}
+// CHECK: !1 = metadata !{metadata !"omnipotent char", metadata !2}
+// CHECK: !2 = metadata !{metadata !"Simple C/C++ TBAA", null}
+// CHECK: !3 = metadata !{metadata !"int", metadata !1}
More information about the cfe-commits
mailing list