[PATCH] D60942: Emit diagnostic if inline asm "n" constraint isn't an immediate

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


void created this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

An inline asm call can result in an immediate after inlining. Therefore emit a
diagnostic here if the "n" constraint doesn't have an immediate.


Repository:
  rL LLVM

https://reviews.llvm.org/D60942

Files:
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp


Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -7865,6 +7865,7 @@
 
 /// visitInlineAsm - Handle a call to an InlineAsm object.
 void SelectionDAGBuilder::visitInlineAsm(ImmutableCallSite CS) {
+  LLVMContext &Ctx = *DAG.getContext();
   const InlineAsm *IA = cast<InlineAsm>(CS.getCalledValue());
 
   /// ConstraintOperands - Information about all of the constraints.
@@ -7907,7 +7908,7 @@
 
       OpInfo.ConstraintVT =
           OpInfo
-              .getCallOperandValEVT(*DAG.getContext(), TLI, DAG.getDataLayout())
+              .getCallOperandValEVT(Ctx, TLI, DAG.getDataLayout())
               .getSimpleVT();
     } else if (OpInfo.Type == InlineAsm::isOutput && !OpInfo.isIndirect) {
       // The return value of the call is this value.  As such, there is no
@@ -7935,6 +7936,12 @@
     // Compute the constraint code and ConstraintType to use.
     TLI.ComputeConstraintToUse(T, SDValue());
 
+    if (T.ConstraintCode == "n" && !isa<ConstantSDNode>(OpInfo.CallOperand))
+      // We've delayed emitting a diagnostic for the "n" constraint because
+      // inlining could cause an integer showing up.
+      return emitInlineAsmError(CS, "constraint 'n' expects an integer "
+                                "constant expression");
+
     ExtraInfo.update(T);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60942.195988.patch
Type: text/x-patch
Size: 1470 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190421/28f839b7/attachment.bin>


More information about the llvm-commits mailing list