Skip to content

Commit 1739a0e

Browse files
authored
[clang][bytecode] Error if calls have fewer arguments than parameters (llvm#155151)
Shouldn't happen, but does. Fixes llvm#155147
1 parent 1a55c63 commit 1739a0e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,6 +5230,12 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
52305230
const Function *Func = getFunction(FuncDecl);
52315231
if (!Func)
52325232
return false;
5233+
5234+
// In error cases, the function may be called with fewer arguments than
5235+
// parameters.
5236+
if (E->getNumArgs() < Func->getNumWrittenParams())
5237+
return false;
5238+
52335239
assert(HasRVO == Func->hasRVO());
52345240

52355241
bool HasQualifier = false;

clang/test/AST/ByteCode/c.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,14 @@ const int compared = strcmp(_str, (const char *)_str2); // all-error {{initializ
351351

352352
const int compared2 = strcmp(strcmp, _str); // all-warning {{incompatible pointer types}} \
353353
// all-error {{initializer element is not a compile-time constant}}
354+
355+
int foo(x) // all-warning {{a function definition without a prototype is deprecated in all versions of C}}
356+
int x;
357+
{
358+
return x;
359+
}
360+
361+
void bar() { // pedantic-warning {{a function declaration without a prototype}}
362+
int x;
363+
x = foo(); // all-warning {{too few arguments}}
364+
}

0 commit comments

Comments
 (0)