Skip to content

[clang][bytecode] Error if calls have fewer arguments than parameters #155151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tbaederr
Copy link
Contributor

Shouldn't happen, but does.

Fixes #155147

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Aug 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 24, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

Shouldn't happen, but does.

Fixes #155147


Full diff: https://github.com/llvm/llvm-project/pull/155151.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Compiler.cpp (+5)
  • (modified) clang/test/AST/ByteCode/c.c (+9)
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();
+}
+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clang][bytecode] Assertion `!ItemTypes.empty()' failed.
2 participants