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(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(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); } Index: test/CodeGen/X86/inline-asm-bad-constraint-n.ll =================================================================== --- test/CodeGen/X86/inline-asm-bad-constraint-n.ll +++ test/CodeGen/X86/inline-asm-bad-constraint-n.ll @@ -2,7 +2,7 @@ @x = global i32 0, align 4 -;CHECK: error: invalid operand for inline asm constraint 'n' +; CHECK: error: constraint 'n' expects an integer constant expression define void @foo() { %a = getelementptr i32, i32* @x, i32 1 call void asm sideeffect "foo $0", "n"(i32* %a) nounwind