https://github.com/andykaylor created 
https://github.com/llvm/llvm-project/pull/140322

There was a problem introduced today where sometimes the CIR for functions with 
no arguments would be generated with phantom arguments. This was causing 
intermittent test failures.

The problem appears to have been that we were using two different Profile 
implementations to generate the FoldingSetNodeID for CIRGenFunctionInfo so 
occaissionally when we tried to look for a pre-existing entry for a function 
with no arguments it would incorrectly match a CIRGenFunctionInfo entry that 
had arguments.

To prevent this from happening again, I rewrote one of the two Profile 
functions to call the other.

>From 303469f78c951eb25d57b1309ad00e9670a7d475 Mon Sep 17 00:00:00 2001
From: Andy Kaylor <akay...@nvidia.com>
Date: Fri, 16 May 2025 17:07:16 -0700
Subject: [PATCH] [CIR] Fix problem with phantom function arguments

There was a problem introduced today where sometimes the CIR for functions
with no arguments would be generated with phantom arguments. This was
causing intermittent test failures.

The problem appears to have been that we were using two different Profile
implementations to generate the FoldingSetNodeID for CIRGenFunctionInfo
so occaissionally when we tried to look for a pre-existing entry for
a function with no arguments it would incorrectly match a
CIRGenFunctionInfo entry that had arguments.

To prevent this from happening again, I rewrote one of the two Profile
functions to call the other.
---
 clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h 
b/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
index 1e06599575fbd..b74460b09a44e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h
@@ -112,8 +112,16 @@ class CIRGenFunctionInfo final
 
   // NOLINTNEXTLINE(readability-identifier-naming)
   void Profile(llvm::FoldingSetNodeID &id) {
-    id.AddBoolean(required.getOpaqueData());
-    getReturnType().Profile(id);
+    // It's unfortunate that we are looping over the arguments twice (here and
+    // in the static Profile function we call from here), but if the Profile
+    // functions get out of sync, we can end up with incorrect function
+    // signatures, and we don't have the argument types in the format that the
+    // static Profile function requires.
+    llvm::SmallVector<CanQualType, 16> argTypes;
+    for (const ArgInfo &argInfo : arguments())
+      argTypes.push_back(argInfo.type);
+
+    Profile(id, required, getReturnType(), argTypes);
   }
 
   llvm::ArrayRef<ArgInfo> arguments() const {

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to