[clang] [clang][bytecode] Check param types against function prototype (PR #163920)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 16 23:50:38 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/163920.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Context.cpp (+6-1)
- (modified) clang/test/AST/ByteCode/c.c (+9)
``````````diff
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));
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/163920
More information about the cfe-commits
mailing list