Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

[CIR] Undefined behaviour of clang reported by Valgrind#1969

Description

@AdUhTkJm

If we compile this program with invocation valgrind clang++ -fclangir -emit-cir test.c:

void f(int);

int main() {
  int a[160];
  for (int i = 0; i < 160; i++) {
    for (int j = 40; j < 120; j++) {
      f(a[j]);
      f(a[i]);
    }
  }
}

Valgrind gives the following output:

==1632227== Conditional jump or move depends on uninitialised value(s)
==1632227==    at 0xE2C5BE5: clang::FunctionProtoType::FunctionProtoType(clang::QualType, llvm::ArrayRef<clang::QualType>, clang::QualType, clang::FunctionProtoType::ExtProtoInfo const&) (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==    by 0xDB31028: clang::ASTContext::getFunctionTypeInternal(clang::QualType, llvm::ArrayRef<clang::QualType>, clang::FunctionProtoType::ExtProtoInfo const&, bool) const (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==    by 0xD941710: GetFullTypeForDeclarator((anonymous namespace)::TypeProcessingState&, clang::QualType, clang::TypeSourceInfo*) (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==    by 0xD93B9A6: clang::Sema::GetTypeForDeclarator(clang::Declarator&) (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==    by 0xD25C759: clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==    by 0xD25C339: clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==    by 0xCFE7D59: clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==    by 0xCFE6260: clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==    by 0xCF7B6C4: clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==    by 0xCF7AEF2: clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==    by 0xCF79E9C: clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==    by 0xCF781FF: clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (in /home/aduhtkjm/llvm/clangir/build/bin/clang-22)
==1632227==

However, if we do not pass -emit-cir then no error is reported. This feels quite strange, as it seems more code should have been executed without -emit-cir.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions