[cfe-commits] r53947 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/SemaStmt.cpp test/Sema/asm.c

Chris Lattner sabre at nondot.org
Tue Jul 22 23:46:56 PDT 2008


Author: lattner
Date: Wed Jul 23 01:46:56 2008
New Revision: 53947

URL: http://llvm.org/viewvc/llvm-project?rev=53947&view=rev
Log:
Fix rdar://6094010 various asserts happening with wide strings in inline asm.

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=53947&r1=53946&r2=53947&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 23 01:46:56 2008
@@ -985,6 +985,8 @@
      "expression result unused")
 DIAG(err_pascal_string_too_long, ERROR,
     "Pascal string is too long")
+DIAG(err_asm_wide_character, ERROR,
+    "wide string is invalid in 'asm'")
 DIAG(err_invalid_lvalue_in_asm_output, ERROR,
     "invalid lvalue in asm output")
 DIAG(err_invalid_output_constraint_in_asm, ERROR,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Jul 23 01:46:56 2008
@@ -676,28 +676,33 @@
                                     std::string *Names,
                                     ExprTy **Constraints,
                                     ExprTy **Exprs,
-                                    ExprTy *AsmString,
+                                    ExprTy *asmString,
                                     unsigned NumClobbers,
                                     ExprTy **Clobbers,
                                     SourceLocation RParenLoc) {
-  Expr *E = (Expr *)AsmString;
- 
+  // The parser verifies that there is a string literal here.
+  StringLiteral *AsmString = cast<StringLiteral>((Expr *)asmString);
+  if (AsmString->isWide())
+    // FIXME: We currently leak memory here.
+    return Diag(AsmString->getLocStart(), diag::err_asm_wide_character,
+                AsmString->getSourceRange());
+  
+  
   for (unsigned i = 0; i < NumOutputs; i++) {
     StringLiteral *Literal = cast<StringLiteral>((Expr *)Constraints[i]);
-    assert(!Literal->isWide() && 
-           "Output constraint strings should not be wide!");
-
+    if (Literal->isWide())
+      // FIXME: We currently leak memory here.
+      return Diag(Literal->getLocStart(), diag::err_asm_wide_character,
+                  Literal->getSourceRange());
+    
     std::string OutputConstraint(Literal->getStrData(), 
                                  Literal->getByteLength());
     
     TargetInfo::ConstraintInfo info;
-    if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),
-                                                 info)) {
+    if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),info))
       // FIXME: We currently leak memory here.
-      Diag(Literal->getLocStart(),
-           diag::err_invalid_output_constraint_in_asm);
-      return true;
-    }
+      return Diag(Literal->getLocStart(),
+                  diag::err_invalid_output_constraint_in_asm);
     
     // Check that the output exprs are valid lvalues.
     Expr *OutputExpr = (Expr *)Exprs[i];
@@ -705,19 +710,19 @@
     if (Result != Expr::LV_Valid) {
       ParenExpr *PE = cast<ParenExpr>(OutputExpr);
       
-      Diag(PE->getSubExpr()->getLocStart(), 
-           diag::err_invalid_lvalue_in_asm_output,
-           PE->getSubExpr()->getSourceRange());
-      
       // FIXME: We currently leak memory here.
-      return true;
+      return Diag(PE->getSubExpr()->getLocStart(), 
+                  diag::err_invalid_lvalue_in_asm_output,
+                  PE->getSubExpr()->getSourceRange());
     }
   }
   
   for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
     StringLiteral *Literal = cast<StringLiteral>((Expr *)Constraints[i]);
-    assert(!Literal->isWide() && 
-           "Output constraint strings should not be wide!");
+    if (Literal->isWide())
+      // FIXME: We currently leak memory here.
+      return Diag(Literal->getLocStart(), diag::err_asm_wide_character,
+                  Literal->getSourceRange());
     
     std::string InputConstraint(Literal->getStrData(), 
                                 Literal->getByteLength());
@@ -727,9 +732,8 @@
                                                 NumOutputs,                                                
                                                 info)) {
       // FIXME: We currently leak memory here.
-      Diag(Literal->getLocStart(),
-           diag::err_invalid_input_constraint_in_asm);
-      return true;
+      return Diag(Literal->getLocStart(),
+                  diag::err_invalid_input_constraint_in_asm);
     }
     
     // Check that the input exprs aren't of type void.
@@ -737,33 +741,30 @@
     if (InputExpr->getType()->isVoidType()) {
       ParenExpr *PE = cast<ParenExpr>(InputExpr);
       
-      Diag(PE->getSubExpr()->getLocStart(),
-           diag::err_invalid_type_in_asm_input,
-           PE->getType().getAsString(), 
-           PE->getSubExpr()->getSourceRange());
-      
       // FIXME: We currently leak memory here.
-      return true;
+      return Diag(PE->getSubExpr()->getLocStart(),
+                  diag::err_invalid_type_in_asm_input,
+                  PE->getType().getAsString(), 
+                  PE->getSubExpr()->getSourceRange());
     }
   }
   
   // Check that the clobbers are valid.
   for (unsigned i = 0; i < NumClobbers; i++) {
     StringLiteral *Literal = cast<StringLiteral>((Expr *)Clobbers[i]);
-    assert(!Literal->isWide() && "Clobber strings should not be wide!");
+    if (Literal->isWide())
+      // FIXME: We currently leak memory here.
+      return Diag(Literal->getLocStart(), diag::err_asm_wide_character,
+                  Literal->getSourceRange());
     
     llvm::SmallString<16> Clobber(Literal->getStrData(), 
                                   Literal->getStrData() + 
                                   Literal->getByteLength());
     
-    if (!Context.Target.isValidGCCRegisterName(Clobber.c_str())) {
-      Diag(Literal->getLocStart(),
-           diag::err_unknown_register_name_in_asm,
-           Clobber.c_str());
-      
+    if (!Context.Target.isValidGCCRegisterName(Clobber.c_str()))
       // FIXME: We currently leak memory here.
-      return true;
-    }
+      return Diag(Literal->getLocStart(),
+                  diag::err_unknown_register_name_in_asm, Clobber.c_str());
   }
   
   return new AsmStmt(AsmLoc,
@@ -774,8 +775,7 @@
                      Names,
                      reinterpret_cast<StringLiteral**>(Constraints),
                      reinterpret_cast<Expr**>(Exprs),
-                     cast<StringLiteral>(E),
-                     NumClobbers,
+                     AsmString, NumClobbers,
                      reinterpret_cast<StringLiteral**>(Clobbers),
                      RParenLoc);
 }

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

==============================================================================
--- cfe/trunk/test/Sema/asm.c (original)
+++ cfe/trunk/test/Sema/asm.c Wed Jul 23 01:46:56 2008
@@ -25,3 +25,11 @@
   asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}}
   asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}}
 }
+
+// rdar://6094010
+void test3() {
+  int x;
+  asm(L"foo" : "=r"(x)); // expected-error {{wide string}}
+  asm("foo" : L"=r"(x)); // expected-error {{wide string}}
+}
+





More information about the cfe-commits mailing list