Author: Timm Baeder
Date: 2025-10-20T17:14:04+02:00
New Revision: c332952ed06a9e74dfd1a416fba3ba536c55661c

URL: 
https://github.com/llvm/llvm-project/commit/c332952ed06a9e74dfd1a416fba3ba536c55661c
DIFF: 
https://github.com/llvm/llvm-project/commit/c332952ed06a9e74dfd1a416fba3ba536c55661c.diff

LOG: [clang][bytecode] Check param types against function prototype (#163920)

If the type of the ParmVarDecl and the parameter type from the
FunctionProtoType don't match, we're in for trouble. Just reject those
functions.

Fixes #163568

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Context.cpp
    clang/test/AST/ByteCode/c.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Context.cpp 
b/clang/lib/AST/ByteCode/Context.cpp
index 683e916391337..4f4b122ce8c9d 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -566,10 +566,15 @@ const Function *Context::getOrCreateFunction(const 
FunctionDecl *FuncDecl) {
 
   // Assign descriptors to all parameters.
   // Composite objects are lowered to pointers.
-  for (const ParmVarDecl *PD : FuncDecl->parameters()) {
+  const auto *FuncProto = FuncDecl->getType()->getAs<FunctionProtoType>();
+  for (auto [ParamIndex, PD] : llvm::enumerate(FuncDecl->parameters())) {
     bool IsConst = PD->getType().isConstQualified();
     bool IsVolatile = PD->getType().isVolatileQualified();
 
+    if (!getASTContext().hasSameType(PD->getType(),
+                                     FuncProto->getParamType(ParamIndex)))
+      return nullptr;
+
     OptPrimType T = classify(PD->getType());
     PrimType PT = T.value_or(PT_Ptr);
     Descriptor *Desc = P->createDescriptor(PD, PT, nullptr, std::nullopt,

diff  --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index 657a920e7d02c..cfdc9d0d3dd86 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -372,3 +372,12 @@ void discardedCmp(void)
 /// ArraySubscriptExpr that's not an lvalue
 typedef unsigned char U __attribute__((vector_size(1)));
 void nonLValueASE(U f) { f[0] = f[((U)(U){0})[0]]; }
+
+static char foo_(a) // all-warning {{definition without a prototype}}
+  char a;
+{
+  return 'a';
+}
+static void bar_(void) {
+  foo_(foo_(1));
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to