https://github.com/isanbard updated https://github.com/llvm/llvm-project/pull/235940
>From 214aeb3f3d612d83ad317e9b2ec1bae8cd1db3d9 Mon Sep 17 00:00:00 2001 From: Bill Wendling <[email protected]> Date: Mon, 26 Oct 2026 14:25:23 -0700 Subject: [PATCH 1/3] [SelectionDAG] Report an error for a callbr's indirect register output An indirect output with a register constraint, e.g. "=*r", is stored to its pointer after the asm. But a callbr's asm can branch to an indirect target before then, so the store was silently skipped on the indirect paths. Clang emits such an output for a _Complex lvalue with a register constraint: _Complex float c; asm goto("" : "=r"(c) : : : l); Report an error instead. A callbr without indirect targets has no such path, so it's still allowed. Assisted-by: Claude Opus 5.5 --- .../SelectionDAG/SelectionDAGBuilder.cpp | 8 ++++ .../CodeGen/X86/callbr-asm-indirect-output.ll | 47 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 llvm/test/CodeGen/X86/callbr-asm-indirect-output.ll diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 28995545724531..ff1124c443784a 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -11004,6 +11004,14 @@ void SelectionDAGBuilder::visitInlineAsm(const CallBase &Call, // Indirect output manifest as stores. Record output chains. if (OpInfo.isIndirect) { + // The store is only on the path to a callbr's default target, since + // the asm can branch to an indirect target before it. + if (IsCallBr && cast<CallBrInst>(Call).getNumIndirectDests()) + DAG.getContext()->diagnose(DiagnosticInfoInlineAsm( + Call, "callbr cannot store indirect output for constraint '" + + Twine(OpInfo.ConstraintCode) + + "' on its indirect paths")); + const Value *Ptr = OpInfo.CallOperandVal; assert(Ptr && "Expected value CallOperandVal for indirect asm operand"); SDValue Store = DAG.getStore(Chain, getCurSDLoc(), Val, getValue(Ptr), diff --git a/llvm/test/CodeGen/X86/callbr-asm-indirect-output.ll b/llvm/test/CodeGen/X86/callbr-asm-indirect-output.ll new file mode 100644 index 00000000000000..60a3b079feb900 --- /dev/null +++ b/llvm/test/CodeGen/X86/callbr-asm-indirect-output.ll @@ -0,0 +1,47 @@ +; RUN: split-file %s %t +; RUN: not llc -mtriple=x86_64-linux-gnu < %t/error.ll 2>&1 | FileCheck %s --check-prefix=ERROR +; RUN: llc -mtriple=x86_64-linux-gnu < %t/ok.ll | FileCheck %s --check-prefix=OK + +; An indirect output with a register constraint is stored after the asm, but a +; callbr's asm can branch to an indirect target before then. + +;--- error.ll +; ERROR: error: callbr cannot store indirect output for constraint 'r' on its indirect paths +define void @indirect_reg_output(ptr %p) { +entry: + callbr void asm "", "=*r,!i"(ptr elementtype(i32) %p) + to label %a [label %b] +a: + ret void +b: + ret void +} + +;--- ok.ll +; Without indirect targets, the store is on the only path. +; OK-LABEL: no_indirect_targets: +; OK: #APP +; OK-NEXT: #NO_APP +; OK-NEXT: movl %eax, (%rdi) +define void @no_indirect_targets(ptr %p) { +entry: + callbr void asm "", "=*r"(ptr elementtype(i32) %p) + to label %a [] +a: + ret void +} + +; The asm writes a memory output itself. +; OK-LABEL: indirect_mem_output: +; OK: #APP +; OK-NEXT: # (%rdi) +; OK-NEXT: #NO_APP +define void @indirect_mem_output(ptr %p) { +entry: + callbr void asm "# $0", "=*m,!i"(ptr elementtype(i32) %p) + to label %a [label %b] +a: + ret void +b: + ret void +} >From e0adbab5f125f77e32af3210fd615532923d1616 Mon Sep 17 00:00:00 2001 From: Bill Wendling <[email protected]> Date: Thu, 5 Nov 2026 19:38:42 -0800 Subject: [PATCH 2/3] use -filetype=null Co-authored-by: Matt Arsenault <[email protected]> --- llvm/test/CodeGen/X86/callbr-asm-indirect-output.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/test/CodeGen/X86/callbr-asm-indirect-output.ll b/llvm/test/CodeGen/X86/callbr-asm-indirect-output.ll index 60a3b079feb900..caa1b05a8ffb99 100644 --- a/llvm/test/CodeGen/X86/callbr-asm-indirect-output.ll +++ b/llvm/test/CodeGen/X86/callbr-asm-indirect-output.ll @@ -1,5 +1,5 @@ ; RUN: split-file %s %t -; RUN: not llc -mtriple=x86_64-linux-gnu < %t/error.ll 2>&1 | FileCheck %s --check-prefix=ERROR +; RUN: not llc -mtriple=x86_64-linux-gnu -filetype=null < %t/error.ll 2>&1 | FileCheck %s --check-prefix=ERROR ; RUN: llc -mtriple=x86_64-linux-gnu < %t/ok.ll | FileCheck %s --check-prefix=OK ; An indirect output with a register constraint is stored after the asm, but a >From ae1c514808b29b022f5aa5fdff157bc9b17af277 Mon Sep 17 00:00:00 2001 From: Bill Wendling <[email protected]> Date: Thu, 5 Nov 2026 19:40:20 -0800 Subject: [PATCH 3/3] Add braces for a large single statement. --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 08729de554b76b..4d43b0d67ce280 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -11014,11 +11014,12 @@ void SelectionDAGBuilder::visitInlineAsm(const CallBase &Call, if (OpInfo.isIndirect) { // The store is only on the path to a callbr's default target, since // the asm can branch to an indirect target before it. - if (IsCallBr && cast<CallBrInst>(Call).getNumIndirectDests()) + if (IsCallBr && cast<CallBrInst>(Call).getNumIndirectDests()) { DAG.getContext()->diagnose(DiagnosticInfoInlineAsm( Call, "callbr cannot store indirect output for constraint '" + Twine(OpInfo.ConstraintCode) + "' on its indirect paths")); + } const Value *Ptr = OpInfo.CallOperandVal; assert(Ptr && "Expected value CallOperandVal for indirect asm operand"); _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
