[llvm] [SPIR-V] Reject builtin calls if mangled argument types do not match the IR (PR #208152)

Juan Manuel Martinez CaamaƱo via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 20 08:03:07 PDT 2026


================
@@ -3485,6 +3485,77 @@ mapBuiltinToOpcode(StringRef DemangledCall,
   return std::make_tuple(-1, 0, 0);
 }
 
+/// Checks that scalar/vector numeric arguments of \p Call match the types
+/// implied by their mangling in \p DemangledCall. Pointers and opaque
+/// builtin types (images, samplers, pipes, etc.) are not validated here, as
+/// mangling does not enforce their exact spelling.
+///
+/// \returns false if a numeric argument's SPIR-V type disagrees with the
+/// type implied by the mangled name, true otherwise.
+static bool demangledArgTypesMatchIR(const SPIRV::IncomingCall *Call,
+                                     StringRef DemangledCall,
+                                     SPIRVGlobalRegistry *GR,
+                                     LLVMContext &Ctx) {
+  if (Call->isSpirvOp())
+    return true;
+
+  SmallVector<StringRef, 10> ArgTypeStrs;
+  SPIRV::parseBuiltinTypeStr(ArgTypeStrs, DemangledCall, Ctx);
+
+  for (unsigned ArgIdx = 0; ArgIdx < Call->Arguments.size(); ++ArgIdx) {
+    if (ArgIdx >= ArgTypeStrs.size())
+      continue;
----------------
jmmartinez wrote:

Should we skip the first argument if it's sret and check the number on the rest?

https://github.com/llvm/llvm-project/pull/208152


More information about the llvm-commits mailing list