[cfe-commits] r99688 - in /cfe/trunk: lib/CodeGen/CGCall.cpp test/CodeGen/restrict.c

John McCall rjmccall at apple.com
Fri Mar 26 17:47:27 PDT 2010


Author: rjmccall
Date: Fri Mar 26 19:47:27 2010
New Revision: 99688

URL: http://llvm.org/viewvc/llvm-project?rev=99688&view=rev
Log:
When mapping restrict to noalias, look for 'restrict' on the parameter variable
instead of the canonical parameter type (which has correctly dropped all such
direct qualifiers).  Fixes PR6695.


Added:
    cfe/trunk/test/CodeGen/restrict.c
Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=99688&r1=99687&r2=99688&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Mar 26 19:47:27 2010
@@ -623,8 +623,9 @@
     const ABIArgInfo &AI = it->info;
     unsigned Attributes = 0;
 
-    if (ParamType.isRestrictQualified())
-      Attributes |= llvm::Attribute::NoAlias;
+    // 'restrict' -> 'noalias' is done in EmitFunctionProlog when we
+    // have the corresponding parameter variable.  It doesn't make
+    // sense to do it here because parameters are so fucked up.
 
     switch (AI.getKind()) {
     case ABIArgInfo::Coerce:
@@ -749,6 +750,9 @@
         V = CreateMemTemp(Ty);
         Builder.CreateStore(AI, V);
       } else {
+        if (Arg->getType().isRestrictQualified())
+          AI->addAttr(llvm::Attribute::NoAlias);
+
         if (!getContext().typesAreCompatible(Ty, Arg->getType())) {
           // This must be a promotion, for something like
           // "void a(x) short x; {..."

Added: cfe/trunk/test/CodeGen/restrict.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/restrict.c?rev=99688&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/restrict.c (added)
+++ cfe/trunk/test/CodeGen/restrict.c Fri Mar 26 19:47:27 2010
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple x86_64-darwin-apple -emit-llvm %s -o - | FileCheck %s
+
+// PR6695
+
+// CHECK: define void @test0(i32* %{{.*}}, i32 %{{.*}})
+void test0(int *x, int y) {
+}
+
+// CHECK: define void @test1(i32* noalias %{{.*}}, i32 %{{.*}})
+void test1(int * restrict x, int y) {
+}
+
+// CHECK: define void @test2(i32* %{{.*}}, i32* noalias %{{.*}})
+void test2(int *x, int * restrict y) {
+}
+
+typedef int * restrict rp;
+
+// CHECK: define void @test3(i32* noalias %{{.*}}, i32 %{{.*}})
+void test3(rp x, int y) {
+}
+
+// CHECK: define void @test4(i32* %{{.*}}, i32* noalias %{{.*}})
+void test4(int *x, rp y) {
+}
+





More information about the cfe-commits mailing list