Skip to content

Commit c332952

Browse files
authored
[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
1 parent 80b311a commit c332952

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clang/lib/AST/ByteCode/Context.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,15 @@ const Function *Context::getOrCreateFunction(const FunctionDecl *FuncDecl) {
566566

567567
// Assign descriptors to all parameters.
568568
// Composite objects are lowered to pointers.
569-
for (const ParmVarDecl *PD : FuncDecl->parameters()) {
569+
const auto *FuncProto = FuncDecl->getType()->getAs<FunctionProtoType>();
570+
for (auto [ParamIndex, PD] : llvm::enumerate(FuncDecl->parameters())) {
570571
bool IsConst = PD->getType().isConstQualified();
571572
bool IsVolatile = PD->getType().isVolatileQualified();
572573

574+
if (!getASTContext().hasSameType(PD->getType(),
575+
FuncProto->getParamType(ParamIndex)))
576+
return nullptr;
577+
573578
OptPrimType T = classify(PD->getType());
574579
PrimType PT = T.value_or(PT_Ptr);
575580
Descriptor *Desc = P->createDescriptor(PD, PT, nullptr, std::nullopt,

clang/test/AST/ByteCode/c.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,12 @@ void discardedCmp(void)
372372
/// ArraySubscriptExpr that's not an lvalue
373373
typedef unsigned char U __attribute__((vector_size(1)));
374374
void nonLValueASE(U f) { f[0] = f[((U)(U){0})[0]]; }
375+
376+
static char foo_(a) // all-warning {{definition without a prototype}}
377+
char a;
378+
{
379+
return 'a';
380+
}
381+
static void bar_(void) {
382+
foo_(foo_(1));
383+
}

0 commit comments

Comments
 (0)