[cfe-commits] r70142 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaStmt.cpp test/Sema/asm.c

Chris Lattner sabre at nondot.org
Sun Apr 26 11:22:24 PDT 2009


Author: lattner
Date: Sun Apr 26 13:22:24 2009
New Revision: 70142

URL: http://llvm.org/viewvc/llvm-project?rev=70142&view=rev
Log:
implement PR4077: [Linux kernel] inscrutable error on inline asm input/output constraint mismatch
Before we emitted:

$ clang t.c -S -m64 
llvm: error: Unsupported asm: input constraint with a matching output constraint of incompatible type!

Now we produce:
$ clang t.c -S -m64 
t.c:5:40: error: unsupported inline asm: input with type 'unsigned long' matching output with type 'int'
  asm volatile("foo " : "=a" (a) :"0" (b));
                             ~~~      ~^~


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/Sema/asm.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=70142&r1=70141&r2=70142&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Apr 26 13:22:24 2009
@@ -1326,6 +1326,8 @@
   "invalid input constraint '%0' in asm">;
 def err_asm_invalid_type_in_input : Error<
   "invalid type %0 in asm input for constraint '%1'">;
+def err_asm_tying_incompatible_types : Error<
+  "unsupported inline asm: input with type %0 matching output with type %1">;
 def err_asm_unknown_register_name : Error<"unknown register name '%0' in asm">;
 def err_invalid_asm_cast_lvalue : Error<
   "invalid use of a cast in a inline asm context requiring an l-value: "

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=70142&r1=70141&r2=70142&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Apr 26 13:22:24 2009
@@ -978,6 +978,24 @@
     }
     
     DefaultFunctionArrayConversion(Exprs[i]);
+    
+    // If this is a tied constraint, verify that the output and input have
+    // either exactly the same type, or that they are int/ptr operands with the
+    // same size (int/long, int*/long, are ok etc).
+    if (Info.hasTiedOperand()) {
+      unsigned TiedTo = Info.getTiedOperand();
+      QualType T1 = Exprs[TiedTo]->getType(), T2 = Exprs[i]->getType();
+      if (!Context.hasSameType(T1, T2)) {
+        // Int/ptr operands are ok if they are the same size.
+        if (!(T1->isIntegerType() || T1->isPointerType()) ||
+            !(T2->isIntegerType() || T2->isPointerType()) ||
+            Context.getTypeSize(T1) != Context.getTypeSize(T2))
+          return StmtError(Diag(InputExpr->getSubExpr()->getLocStart(),
+                                diag::err_asm_tying_incompatible_types)
+                           << T2 << T1 << Exprs[TiedTo]->getSourceRange()
+                           << Exprs[i]->getSourceRange());
+      }
+    }
   }
 
   // Check that the clobbers are valid.

Modified: cfe/trunk/test/Sema/asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/asm.c?rev=70142&r1=70141&r2=70142&view=diff

==============================================================================
--- cfe/trunk/test/Sema/asm.c (original)
+++ cfe/trunk/test/Sema/asm.c Sun Apr 26 13:22:24 2009
@@ -69,3 +69,10 @@
   asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}}
   asm("%1" : "+r"(i)); // ok, referring to input.
 }
+
+// PR4077
+int test7(unsigned long long b) {
+  int a;
+  asm volatile("foo " : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}}
+  return a;
+}





More information about the cfe-commits mailing list