[PATCH] D60943: Delay diagnosing "n" constraint until after inlining

Bill Wendling via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 21 01:39:13 PDT 2019


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);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60943.195989.patch
Type: text/x-patch
Size: 1875 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190421/46dbd2b1/attachment.bin>


More information about the cfe-commits mailing list