Skip to content

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

@AdUhTkJm

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.

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