void created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

An inline asm call may result in an immediate input value after inlining.
Therefore, don't emit a diagnostic here if the input isn't an immediate.


Repository:
  rC Clang

https://reviews.llvm.org/D60943

Files:
  lib/CodeGen/CGStmt.cpp
  lib/Sema/SemaStmtAsm.cpp


Index: lib/Sema/SemaStmtAsm.cpp
===================================================================
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -381,7 +381,8 @@
     } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
       if (!InputExpr->isValueDependent()) {
         Expr::EvalResult EVResult;
-        if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
+        if (!InputExpr->EvaluateAsRValue(EVResult, Context, true) &&
+            Literal->getString() != "n")
           return StmtError(
               Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
               << Info.getConstraintStr() << InputExpr->getSourceRange());
@@ -395,7 +396,7 @@
               Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
               << Info.getConstraintStr() << InputExpr->getSourceRange());
 
-        if (!Info.isValidAsmImmediate(IntResult))
+        if (!Info.isValidAsmImmediate(IntResult) && Literal->getString() != 
"n")
           return StmtError(Diag(InputExpr->getBeginLoc(),
                                 diag::err_invalid_asm_value_for_constraint)
                            << IntResult.toString(10) << Info.getConstraintStr()
Index: lib/CodeGen/CGStmt.cpp
===================================================================
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1837,7 +1837,8 @@
   // If this can't be a register or memory, i.e., has to be a constant
   // (immediate or symbolic), try to emit it as such.
   if (!Info.allowsRegister() && !Info.allowsMemory()) {
-    if (Info.requiresImmediateConstant()) {
+    // We can delay diagnosing the "n" constraint until after inlining.
+    if (Info.requiresImmediateConstant() && ConstraintStr != "n") {
       Expr::EvalResult EVResult;
       InputExpr->EvaluateAsRValue(EVResult, getContext(), true);
 


Index: lib/Sema/SemaStmtAsm.cpp
===================================================================
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -381,7 +381,8 @@
     } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
       if (!InputExpr->isValueDependent()) {
         Expr::EvalResult EVResult;
-        if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
+        if (!InputExpr->EvaluateAsRValue(EVResult, Context, true) &&
+            Literal->getString() != "n")
           return StmtError(
               Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
               << Info.getConstraintStr() << InputExpr->getSourceRange());
@@ -395,7 +396,7 @@
               Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
               << Info.getConstraintStr() << InputExpr->getSourceRange());
 
-        if (!Info.isValidAsmImmediate(IntResult))
+        if (!Info.isValidAsmImmediate(IntResult) && Literal->getString() != "n")
           return StmtError(Diag(InputExpr->getBeginLoc(),
                                 diag::err_invalid_asm_value_for_constraint)
                            << IntResult.toString(10) << Info.getConstraintStr()
Index: lib/CodeGen/CGStmt.cpp
===================================================================
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1837,7 +1837,8 @@
   // If this can't be a register or memory, i.e., has to be a constant
   // (immediate or symbolic), try to emit it as such.
   if (!Info.allowsRegister() && !Info.allowsMemory()) {
-    if (Info.requiresImmediateConstant()) {
+    // We can delay diagnosing the "n" constraint until after inlining.
+    if (Info.requiresImmediateConstant() && ConstraintStr != "n") {
       Expr::EvalResult EVResult;
       InputExpr->EvaluateAsRValue(EVResult, getContext(), true);
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to