[clang] [Clang] Loop over FieldDecls instead of all Decls (PR #99574)

Nathan Chancellor via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 21 16:35:12 PDT 2024


nathanchance wrote:

I see a crash in `drivers/thermal/thermal_core.c` in Linux kernels without commit [daeeb032f42d](https://git.kernel.org/linus/daeeb032f42d066a49e07b7f6effc9f51b7a5479) ("thermal: core: Move threshold out of struct thermal_trip") after this change. `cvise` spits out:

```c
struct swait_queue_head {};
struct completion {
  int done;
  struct swait_queue_head wait;
};
struct {
  struct completion removal;
  int num_trips;
  int trips[] __attribute__((__counted_by__(num_trips)));
} *thermal_zone_device_register_with_trips_tz;
int thermal_zone_device_register_with_trips() {
  if (thermal_zone_device_register_with_trips_tz)
    goto free_tz;
  if (0)
    goto free_tzp;
  {
    long __p_size_field = __builtin_dynamic_object_size(
        thermal_zone_device_register_with_trips_tz, 1);
    _Bool __ret_do_once = __p_size_field, __ret_cond = __ret_do_once;
    static _Bool __already_done;
    if (__builtin_expect(__ret_cond && __already_done, 0))
      ;
  }
free_tzp:
free_tz:
  return 0;
}
```

```
$ clang -c -o /dev/null thermal_core.i
clang: /home/nathan/tmp/cvise.YrEYUS5WBZ/src/clang/lib/CodeGen/CGRecordLayout.h:200: unsigned int clang::CodeGen::CGRecordLayout::getLLVMFieldNo(const FieldDecl *) const: Assertion `FieldInfo.count(FD) && "Invalid field for record!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: clang -c -o /dev/null thermal_core.i
1.	<eof> parser at end of file
2.	thermal_core.i:11:5: LLVM IR generation of declaration 'thermal_zone_device_register_with_trips'
3.	thermal_core.i:11:5: Generating code for declaration 'thermal_zone_device_register_with_trips'
4.	thermal_core.i:16:3: LLVM IR generation of compound statement ('{}')
 #0 0x00005585369d0446 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x55fc446)
 #1 0x00005585369cdf0e llvm::sys::RunSignalHandlers() (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x55f9f0e)
 #2 0x00005585369513ad CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f3d209bdae0 (/usr/lib/libc.so.6+0x3cae0)
 #4 0x00007f3d20a15e44 (/usr/lib/libc.so.6+0x94e44)
 #5 0x00007f3d209bda30 raise (/usr/lib/libc.so.6+0x3ca30)
 #6 0x00007f3d209a54c3 abort (/usr/lib/libc.so.6+0x244c3)
 #7 0x00007f3d209a53df (/usr/lib/libc.so.6+0x243df)
 #8 0x00007f3d209b5c67 (/usr/lib/libc.so.6+0x34c67)
 #9 0x0000558536de6281 clang::CodeGen::CGRecordLayout::getLLVMFieldNo(clang::FieldDecl const*) const CGExpr.cpp:0:0
#10 0x0000558536dcd526 getGEPIndicesToField(clang::CodeGen::CodeGenFunction&, clang::RecordDecl const*, clang::FieldDecl const*, llvm::SmallVector<std::pair<clang::RecordDecl const*, llvm::Value*>, 8u>&) CGExpr.cpp:0:0
#11 0x0000558536dcd581 getGEPIndicesToField(clang::CodeGen::CodeGenFunction&, clang::RecordDecl const*, clang::FieldDecl const*, llvm::SmallVector<std::pair<clang::RecordDecl const*, llvm::Value*>, 8u>&) CGExpr.cpp:0:0
#12 0x0000558536dca542 clang::CodeGen::CodeGenFunction::EmitCountedByFieldExpr(clang::Expr const*, clang::FieldDecl const*, clang::FieldDecl const*) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x59f6542)
#13 0x0000558536fb0927 clang::CodeGen::CodeGenFunction::emitFlexibleArrayMemberSize(clang::Expr const*, unsigned int, llvm::IntegerType*) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5bdc927)
#14 0x0000558536fafdf8 clang::CodeGen::CodeGenFunction::emitBuiltinObjectSize(clang::Expr const*, unsigned int, llvm::IntegerType*, llvm::Value*, bool) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5bdbdf8)
#15 0x0000558536fb9cfc clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(clang::GlobalDecl, unsigned int, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5be5cfc)
#16 0x0000558536de827c clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5a1427c)
#17 0x0000558536e024cb (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#18 0x0000558536dee27b (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#19 0x0000558536e0bedd (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#20 0x0000558536dee11c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5a1a11c)
#21 0x0000558536e301e4 clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5a5c1e4)
#22 0x0000558536e335d1 clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission const&) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5a5f5d1)
#23 0x0000558536e2da7d clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5a59a7d)
#24 0x0000558536e2d4b7 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5a594b7)
#25 0x0000558536d66ddb clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5992ddb)
#26 0x0000558536d59acb clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5985acb)
#27 0x0000558536d58b33 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5984b33)
#28 0x0000558536d59aa1 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5985aa1)
#29 0x0000558536d58b33 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5984b33)
#30 0x0000558536d67f40 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5993f40)
#31 0x0000558536d44ee6 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5970ee6)
#32 0x0000558536bfb47b clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x582747b)
#33 0x0000558536bf2a75 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x581ea75)
#34 0x0000558536bf7a1a clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5823a1a)
#35 0x0000558536bf13e2 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x581d3e2)
#36 0x0000558537240fbc (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#37 0x0000558537237057 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x5e63057)
#38 0x00005585386c199a clang::ParseAST(clang::Sema&, bool, bool) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x72ed99a)
#39 0x00005585376ca08d clang::FrontendAction::Execute() (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x62f608d)
#40 0x000055853762e7ad clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x625a7ad)
#41 0x00005585377a673c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x63d273c)
#42 0x0000558534a3220a cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x365e20a)
#43 0x0000558534a2e85d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#44 0x0000558537454199 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0>(long) Job.cpp:0:0
#45 0x00005585369510e6 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x557d0e6)
#46 0x0000558537453833 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x607f833)
#47 0x000055853740b427 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x6037427)
#48 0x000055853740b987 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x6037987)
#49 0x000055853742e0e9 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x605a0e9)
#50 0x0000558534a2dcfd clang_main(int, char**, llvm::ToolContext const&) (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x3659cfd)
#51 0x0000558534a3f806 main (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x366b806)
#52 0x00007f3d209a6c88 (/usr/lib/libc.so.6+0x25c88)
#53 0x00007f3d209a6d4c __libc_start_main (/usr/lib/libc.so.6+0x25d4c)
#54 0x0000558534a2c125 _start (/home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin/clang-19+0x3658125)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
ClangBuiltLinux clang version 19.0.0git (https://github.com/llvm/llvm-project.git 1f6f97e2b64a9c4c51712d32b53e07d2a20e0cc0)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /home/nathan/tmp/cvise.YrEYUS5WBZ/install/llvm-bad/bin
Build config: +assertions
clang: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
```

https://github.com/llvm/llvm-project/pull/99574


More information about the cfe-commits mailing list