]> granicus.if.org Git - clang/commitdiff
When reporting constraints that should be constant, the type doesn't
authorJoerg Sonnenberger <joerg@bec.de>
Thu, 22 Jan 2015 21:01:00 +0000 (21:01 +0000)
committerJoerg Sonnenberger <joerg@bec.de>
Thu, 22 Jan 2015 21:01:00 +0000 (21:01 +0000)
really help. Improve diagnostics.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226863 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaStmtAsm.cpp
test/Sema/inline-asm-validate-x86.c

index 3e41564a39cad40c333b303d95e49727a7401117..19e6861685a72b9f0228c27c5ea8ea04dcd88166 100644 (file)
@@ -6173,6 +6173,8 @@ let CategoryName = "Inline Assembly Issue" in {
     "invalid lvalue in asm input for constraint '%0'">;
   def err_asm_invalid_input_constraint : Error<
     "invalid input constraint '%0' in asm">;
+  def err_asm_immediate_expected : Error<"constraint '%0' expects "
+    "an integer constant expression">;
   def err_asm_invalid_type_in_input : Error<
     "invalid type %0 in asm input for constraint '%1'">;
   def err_asm_tying_incompatible_types : Error<
index 286c7619ed409e5f0c04ba2fe7ce76fda8fcf6c2..0d32581e8daa8adf63b0f8f2482b311b485dc52f 100644 (file)
@@ -230,9 +230,8 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
       llvm::APSInt Result;
       if (!InputExpr->EvaluateAsInt(Result, Context))
         return StmtError(
-            Diag(InputExpr->getLocStart(), diag::err_asm_invalid_type_in_input)
-            << InputExpr->getType() << Info.getConstraintStr()
-            << InputExpr->getSourceRange());
+            Diag(InputExpr->getLocStart(), diag::err_asm_immediate_expected)
+            << Info.getConstraintStr() << InputExpr->getSourceRange());
       if (Result.slt(Info.getImmConstantMin()) ||
           Result.sgt(Info.getImmConstantMax()))
         return StmtError(Diag(InputExpr->getLocStart(),
index 174deca80b43ba846abcc1d28b454cb80413bef8..658b714056f81c588ca2ec8cc6ab9c262b49ef9a 100644 (file)
@@ -6,7 +6,7 @@ void I(int i, int j) {
   static const int AboveMax = 32;
   __asm__("xorl %0,%2"
           : "=r"(i)
-          : "0"(i), "I"(j)); // expected-error{{invalid type 'int' in asm input for constraint 'I'}}
+          : "0"(i), "I"(j)); // expected-error{{constraint 'I' expects an integer constant expression}}
   __asm__("xorl %0,%2"
           : "=r"(i)
           : "0"(i), "I"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'I'}}
@@ -23,7 +23,7 @@ void J(int i, int j) {
   static const int AboveMax = 64;
   __asm__("xorl %0,%2"
           : "=r"(i)
-          : "0"(i), "J"(j)); // expected-error{{invalid type 'int' in asm input for constraint 'J'}}
+          : "0"(i), "J"(j)); // expected-error{{constraint 'J' expects an integer constant expression}}
   __asm__("xorl %0,%2"
           : "=r"(i)
           : "0"(i), "J"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'J'}}
@@ -40,7 +40,7 @@ void K(int i, int j) {
   static const int AboveMax = 128;
   __asm__("xorl %0,%2"
           : "=r"(i)
-          : "0"(i), "K"(j)); // expected-error{{invalid type 'int' in asm input for constraint 'K'}}
+          : "0"(i), "K"(j)); // expected-error{{constraint 'K' expects an integer constant expression}}
   __asm__("xorl %0,%2"
           : "=r"(i)
           : "0"(i), "K"(BelowMin)); // expected-error{{value '-129' out of range for constraint 'K'}}
@@ -57,7 +57,7 @@ void M(int i, int j) {
   static const int AboveMax = 4;
   __asm__("xorl %0,%2"
           : "=r"(i)
-          : "0"(i), "M"(j)); // expected-error{{invalid type 'int' in asm input for constraint 'M'}}
+          : "0"(i), "M"(j)); // expected-error{{constraint 'M' expects an integer constant expression}}
   __asm__("xorl %0,%2"
           : "=r"(i)
           : "0"(i), "M"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'M'}}
@@ -74,7 +74,7 @@ void N(int i, int j) {
   static const int AboveMax = 256;
   __asm__("xorl %0,%2"
           : "=r"(i)
-          : "0"(i), "N"(j)); // expected-error{{invalid type 'int' in asm input for constraint 'N'}}
+          : "0"(i), "N"(j)); // expected-error{{constraint 'N' expects an integer constant expression}}
   __asm__("xorl %0,%2"
           : "=r"(i)
           : "0"(i), "N"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'N'}}
@@ -91,7 +91,7 @@ void O(int i, int j) {
   static const int AboveMax = 128;
   __asm__("xorl %0,%2"
           : "=r"(i)
-          : "0"(i), "O"(j)); // expected-error{{invalid type 'int' in asm input for constraint 'O'}}
+          : "0"(i), "O"(j)); // expected-error{{constraint 'O' expects an integer constant expression}}
   __asm__("xorl %0,%2"
           : "=r"(i)
           : "0"(i), "O"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'O'}}