From ddd352f5f0eef233d24e299cdb68ea8ac6919bc3 Mon Sep 17 00:00:00 2001 From: ZhouGuangyuan Date: Sat, 1 Aug 2026 16:28:37 +0800 Subject: [PATCH] cmd/llvmplugin: accept non-ABI pointer parameter attributes --- src/cmd/llvmplugin/CMakeLists.txt | 26 +++++++++++++++++++ src/cmd/llvmplugin/GoALLCStatepoints.cpp | 15 ++++++++--- .../testdata/supported-param-attrs.ll | 11 ++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/cmd/llvmplugin/testdata/supported-param-attrs.ll diff --git a/src/cmd/llvmplugin/CMakeLists.txt b/src/cmd/llvmplugin/CMakeLists.txt index 5e0c6254bb612e..9c5d7c3572035f 100644 --- a/src/cmd/llvmplugin/CMakeLists.txt +++ b/src/cmd/llvmplugin/CMakeLists.txt @@ -129,6 +129,32 @@ if(BUILD_TESTING) "ptr nest %context" ) + add_test( + NAME GoALLCStatepoints.SupportedParamAttrsRewrite + COMMAND + "${GOALLC_LLC_EXECUTABLE}" + "-load-pass-plugin=$" + -goallc-pass-plugin-emit-ir + -filetype=null + -o - + "${CMAKE_CURRENT_SOURCE_DIR}/testdata/supported-param-attrs.ll" + ) + set_tests_properties(GoALLCStatepoints.SupportedParamAttrsRewrite PROPERTIES + PASS_REGULAR_EXPRESSION + "ptr noundef nonnull align 8 %argument" + ) + + add_test( + NAME GoALLCStatepoints.SupportedParamAttrsCodegen + COMMAND + "${GOALLC_LLC_EXECUTABLE}" + "-load-pass-plugin=$" + -verify-machineinstrs + -filetype=obj + -o "${CMAKE_CURRENT_BINARY_DIR}/supported-param-attrs.goobj" + "${CMAKE_CURRENT_SOURCE_DIR}/testdata/supported-param-attrs.ll" + ) + add_test( NAME GoALLCStatepoints.CallOnlyPointersNotLive COMMAND diff --git a/src/cmd/llvmplugin/GoALLCStatepoints.cpp b/src/cmd/llvmplugin/GoALLCStatepoints.cpp index 35be200bd4b564..fad824330521e4 100644 --- a/src/cmd/llvmplugin/GoALLCStatepoints.cpp +++ b/src/cmd/llvmplugin/GoALLCStatepoints.cpp @@ -692,13 +692,22 @@ Error validateSafepoint(const SafepointRecord &Record) { "GoALLC statepoints only support a single deopt call operand bundle"); for (unsigned I = 0; I != Call.arg_size(); ++I) { for (Attribute Attr : Call.getAttributes().getParamAttrs(I)) { + // These non-ABI attributes remain valid after LLVM's generic + // RewriteStatepointsForGC pass and are natively accepted by both the + // statepoint verifier and SelectionDAG call lowering. O2 commonly + // infers them on otherwise ordinary runtime calls. Keep ABI-affecting + // attributes fail closed except for nest, whose Go closure ABI lowering + // is covered separately. if (!Attr.hasAttribute(Attribute::Nest) && !Attr.hasAttribute(Attribute::Captures) && - !Attr.hasAttribute(Attribute::ReadOnly)) + !Attr.hasAttribute(Attribute::ReadOnly) && + !Attr.hasAttribute(Attribute::NonNull) && + !Attr.hasAttribute(Attribute::NoUndef) && + !Attr.hasAttribute(Attribute::Alignment)) return createStringError( std::errc::not_supported, - "GoALLC statepoints only support nest, captures, and readonly " - "call parameter attributes"); + "GoALLC statepoints do not support call parameter attribute '%s'", + Attr.getAsString().c_str()); } } for (Value *V : Record.Live) { diff --git a/src/cmd/llvmplugin/testdata/supported-param-attrs.ll b/src/cmd/llvmplugin/testdata/supported-param-attrs.ll new file mode 100644 index 00000000000000..2a3375dcf78f11 --- /dev/null +++ b/src/cmd/llvmplugin/testdata/supported-param-attrs.ll @@ -0,0 +1,11 @@ +target triple = "aarch64-unknown-linux-goobj" + +declare goabiinternal void @supported_callee(ptr) + +define goabiinternal void @supported_param_attrs(ptr %argument) #0 gc "goallc" { +entry: + call goabiinternal void @supported_callee(ptr noundef nonnull align 8 %argument) + ret void +} + +attributes #0 = { "frame-pointer"="non-leaf" "go-stack-growth-statepoint" }