[clang] [clang][bytecode] Error if calls have fewer arguments than parameters (PR #155151)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 24 01:57:49 PDT 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/155151
Shouldn't happen, but does.
Fixes #155147
>From a48107184367e99e173875e34f1bc063f2114006 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sun, 24 Aug 2025 10:56:05 +0200
Subject: [PATCH] [clang][bytecode] Error if calls have fewer arguments than
parameters
---
clang/lib/AST/ByteCode/Compiler.cpp | 5 +++++
clang/test/AST/ByteCode/c.c | 9 +++++++++
2 files changed, 14 insertions(+)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index e3235d34e230e..efd4efad5733a 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5230,6 +5230,11 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
return false;
assert(HasRVO == Func->hasRVO());
+ // This should already be checked in sema, but in error cases it might still
+ // happen.
+ if (Args.size() < Func->getNumWrittenParams())
+ return false;
+
bool HasQualifier = false;
if (const auto *ME = dyn_cast<MemberExpr>(E->getCallee()))
HasQualifier = ME->hasQualifier();
diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index 73469d7fd6cc4..113cc75bd0098 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -347,3 +347,12 @@ const int compared = strcmp(_str, (const char *)_str2); // all-error {{initializ
const int compared2 = strcmp(strcmp, _str); // all-warning {{incompatible pointer types}} \
// all-error {{initializer element is not a compile-time constant}}
+
+int apple(x) // all-error{{parameter 'x' was not declared}} \
+ // all-warning {{a function definition without a prototype}}
+void pear() { // all-error {{parameter named}} \
+ // all-error {{expected ';'}} \
+ // pedantic-warning {{a function declaration without a prototype}}
+ x = apple();
+}
+
More information about the cfe-commits
mailing list