Skip to content

Conversation

@jofrn
Copy link
Contributor

@jofrn jofrn commented Oct 6, 2025

It is undefined behavior to call a function with a mismatched calling convention. Rather than crash on this behavior, it should compile.

This LLVM defect was identified via the AMD Fuzzing project.

@llvmbot
Copy link
Member

llvmbot commented Oct 6, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: None (jofrn)

Changes

It is undefined behavior to call a function with a mismatched calling convention. Rather than crash on this behavior, it should compile.


Full diff: https://github.com/llvm/llvm-project/pull/162080.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp (-7)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp b/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
index 0ea9add891111..b03d50f2d451d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
@@ -261,13 +261,6 @@ AMDGPUResourceUsageAnalysisImpl::analyzeResourceUsage(
 
         const Function *Callee = getCalleeFunction(*CalleeOp);
 
-        // Avoid crashing on undefined behavior with an illegal call to a
-        // kernel. If a callsite's calling convention doesn't match the
-        // function's, it's undefined behavior. If the callsite calling
-        // convention does match, that would have errored earlier.
-        if (Callee && AMDGPU::isEntryFunctionCC(Callee->getCallingConv()))
-          report_fatal_error("invalid call to entry function");
-
         auto isSameFunction = [](const MachineFunction &MF, const Function *F) {
           return F == &MF.getFunction();
         };

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs test

@CatherineMoore
Copy link
Contributor

@CatherineMoore for awareness

@jofrn jofrn force-pushed the users/jofrn/cc.entry-fn branch from 988f6de to 2f3d478 Compare October 13, 2025 12:45
Copy link
Contributor

@shiltian shiltian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything less fatal that will not crash the backend? I think the comment wanted it to behave like that, but the description of the PR seems to say other way.

@jofrn
Copy link
Contributor Author

jofrn commented Nov 10, 2025

Is there anything less fatal that will not crash the backend? I think the comment wanted it to behave like that, but the description of the PR seems to say other way.

The original comment is contradictory: it says to avoid crashing on undefined behavior but then crashes with report_fatal_error(). While crashing is still undefined behavior, it's less fatal to compile it (even if the result is incorrect) than to crash the backend. We have a lint check to catch the mismatched cc.

It is undefined behavior to call a function with a
mismatched calling convention. Rather than crash on
this behavior, it should compile.
@jofrn jofrn force-pushed the users/jofrn/cc.entry-fn branch from 7886359 to 03c691d Compare November 10, 2025 13:00
@jofrn jofrn merged commit fb2fa21 into main Nov 10, 2025
10 checks passed
@jofrn jofrn deleted the users/jofrn/cc.entry-fn branch November 10, 2025 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants