[clang] 1739a0e - [clang][bytecode] Error if calls have fewer arguments than parameters (#155151)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 25 21:17:43 PDT 2025


Author: Timm Baeder
Date: 2025-08-26T06:17:39+02:00
New Revision: 1739a0e5fba4b2af820a95db0fb3fda4cc054a09

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

LOG: [clang][bytecode] Error if calls have fewer arguments than parameters (#155151)

Shouldn't happen, but does.

Fixes #155147

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index e61d5e085a036..8610267ff6650 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5230,6 +5230,12 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
     const Function *Func = getFunction(FuncDecl);
     if (!Func)
       return false;
+
+    // In error cases, the function may be called with fewer arguments than
+    // parameters.
+    if (E->getNumArgs() < Func->getNumWrittenParams())
+      return false;
+
     assert(HasRVO == Func->hasRVO());
 
     bool HasQualifier = false;

diff  --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index eb46330c7d35f..05af00c040f45 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -351,3 +351,14 @@ 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 foo(x) // all-warning {{a function definition without a prototype is deprecated in all versions of C}}
+int x;
+{
+  return x;
+}
+
+void bar() { // pedantic-warning {{a function declaration without a prototype}}
+  int x;
+  x = foo(); // all-warning {{too few arguments}}
+}


        


More information about the cfe-commits mailing list