[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 02:31:17 PDT 2019


void updated this revision to Diff 195992.
void added a comment.

Put constraint string check in the correct place.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60943/new/

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
@@ -379,7 +379,7 @@
                          << Info.getConstraintStr()
                          << InputExpr->getSourceRange());
     } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
-      if (!InputExpr->isValueDependent()) {
+      if (!InputExpr->isValueDependent() && Literal->getString() != "n") {
         Expr::EvalResult EVResult;
         if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
           return StmtError(
@@ -401,7 +401,6 @@
                            << IntResult.toString(10) << Info.getConstraintStr()
                            << InputExpr->getSourceRange());
       }
-
     } else {
       ExprResult Result = DefaultFunctionArrayLvalueConversion(Exprs[i]);
       if (Result.isInvalid())
Index: lib/CodeGen/CGStmt.cpp
===================================================================
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1842,11 +1842,13 @@
       InputExpr->EvaluateAsRValue(EVResult, getContext(), true);
 
       llvm::APSInt IntResult;
-      if (!EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
-                                           getContext()))
-        llvm_unreachable("Invalid immediate constant!");
+      if (EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
+                                          getContext()))
+        return llvm::ConstantInt::get(getLLVMContext(), IntResult);
 
-      return llvm::ConstantInt::get(getLLVMContext(), IntResult);
+      if (Info.getConstraintStr() != "n")
+        // We can delay diagnosing the "n" constraint until after inlining.
+        llvm_unreachable("Invalid immediate constant!");
     }
 
     Expr::EvalResult Result;


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


More information about the cfe-commits mailing list