Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Cannot compile AVR sample #43068

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR44098
Status NEW
Importance P normal
Reported by Blake W. Ford (blakewford@gmail.com)
Reported on 2019-11-20 23:44:12 -0800
Last modified on 2021-01-24 01:18:11 -0800
Version trunk
Hardware Other other
CC blakewford@gmail.com, kamleshbhalui@gmail.com, llvm-bugs@lists.llvm.org, me@dylanmckay.io, neeilans@live.com, richard-llvm@metafoo.co.uk, stappers@stappers.nl
Fixed by commit(s)
Attachments main-58e3db.cpp (584319 bytes, text/x-c++src)
main-58e3db.sh (2023 bytes, application/x-shellscript)
Blocks
Blocked by
See also
Created attachment 22850
Preprocessed source

Trying to compile avr-runner from https://github.com/blakewford/ID-15-Shadow-
Runner/tree/headless
Quuxplusone commented 4 years ago

Attached main-58e3db.cpp (584319 bytes, text/x-c++src): Preprocessed source

Quuxplusone commented 4 years ago

Attached main-58e3db.sh (2023 bytes, application/x-shellscript): Run script

Quuxplusone commented 4 years ago
clang-10: /home/llvm-project/llvm/lib/IR/Constants.cpp:1588: static
llvm::Constant* llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*,
llvm::Type*, bool): Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid
constantexpr cast!"' failed.
Stack dump:
0.  Program arguments: /home/build/bin/clang-10 -cc1 -triple avr-atmel-none -
emit-obj -mrelax-all -disable-free -main-file-name main.cpp -mrelocation-model
static -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose -
mconstructor-aliases -target-cpu atmega32u4 -dwarf-column-info -debug-info-
kind=limited -dwarf-version=4 -debugger-tuning=gdb -resource-dir
/home/build/lib/clang/10.0.0 -include port.h -include avr/pgmspace.h -I
/usr/lib/avr/include -I . -O0 -Wno-narrowing -std=c++11 -fdeprecated-macro -
fdebug-compilation-dir /home/ID-15-Shadow-Runner -ferror-limit 19 -fmessage-
length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -
fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o avr-runner -x c++
main.cpp
1.  ./SHRUN_AB/globals.h:30:1: current parser token 'byte'
2.  ./SHRUN_AB/globals.h:27:14: LLVM IR generation of declaration 'sound'
3.  ./SHRUN_AB/globals.h:27:14: Generating code for declaration 'sound'
 #0 0x00000000044600bb llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/llvm-project/llvm/lib/Support/Unix/Signals.inc:548:0
 #1 0x000000000446014e PrintStackTraceSignalHandler(void*) /home/llvm-project/llvm/lib/Support/Unix/Signals.inc:609:0
 #2 0x000000000445df70 llvm::sys::RunSignalHandlers() /home/llvm-project/llvm/lib/Support/Signals.cpp:68:0
 #3 0x000000000445fa35 SignalHandler(int) /home/llvm-project/llvm/lib/Support/Unix/Signals.inc:390:0
 #4 0x00007f02a7a6d390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
 #5 0x00007f02a67df428 raise /build/glibc-LK5gWL/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
 #6 0x00007f02a67e102a abort /build/glibc-LK5gWL/glibc-2.23/stdlib/abort.c:91:0
 #7 0x00007f02a67d7bd7 __assert_fail_base /build/glibc-LK5gWL/glibc-2.23/assert/assert.c:92:0
 #8 0x00007f02a67d7c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
 #9 0x0000000003afb13c llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool) /home/llvm-project/llvm/lib/IR/Constants.cpp:1590:0
#10 0x0000000002a7f8aa
llvm::ConstantFolder::CreateCast(llvm::Instruction::CastOps, llvm::Constant*,
llvm::Type*) const /home/llvm-
project/llvm/include/llvm/IR/ConstantFolder.h:187:0
#11 0x000000000483d7f5 llvm::IRBuilder<llvm::ConstantFolder,
clang::CodeGen::CGBuilderInserter>::CreateCast(llvm::Instruction::CastOps,
llvm::Value*, llvm::Type*, llvm::Twine const&) /home/llvm-
project/llvm/include/llvm/IR/IRBuilder.h:2021:0
#12 0x000000000483d064 llvm::IRBuilder<llvm::ConstantFolder,
clang::CodeGen::CGBuilderInserter>::CreateBitCast(llvm::Value*, llvm::Type*,
llvm::Twine const&) /home/llvm-project/llvm/include/llvm/IR/IRBuilder.h:1982:0
#13 0x0000000004b63528
clang::CodeGen::CodeGenFunction::EmitCall(clang::CodeGen::CGFunctionInfo
const&, clang::CodeGen::CGCallee const&, clang::CodeGen::ReturnValueSlot,
clang::CodeGen::CallArgList const&, llvm::CallBase**, clang::SourceLocation)
/home/llvm-project/clang/lib/CodeGen/CGCall.cpp:4098:0
#14 0x00000000048c608e
clang::CodeGen::CodeGenFunction::EmitCall(clang::CodeGen::CGFunctionInfo
const&, clang::CodeGen::CGCallee const&, clang::CodeGen::ReturnValueSlot,
clang::CodeGen::CallArgList const&, llvm::CallBase**) /home/llvm-
project/clang/lib/CodeGen/CodeGenFunction.h:3608:0
#15 0x0000000004b80647
clang::CodeGen::CodeGenFunction::EmitCXXConstructorCall(clang::CXXConstructorDecl
const*, clang::CXXCtorType, bool, bool, clang::CodeGen::Address,
clang::CodeGen::CallArgList&, clang::CodeGen::AggValueSlot::Overlap_t,
clang::SourceLocation, bool) /home/llvm-
project/clang/lib/CodeGen/CGClass.cpp:2160:0
#16 0x0000000004b7fe3e
clang::CodeGen::CodeGenFunction::EmitCXXConstructorCall(clang::CXXConstructorDecl
const*, clang::CXXCtorType, bool, bool, clang::CodeGen::AggValueSlot,
clang::CXXConstructExpr const*) /home/llvm-
project/clang/lib/CodeGen/CGClass.cpp:2076:0
#17 0x0000000004c02969
clang::CodeGen::CodeGenFunction::EmitCXXConstructExpr(clang::CXXConstructExpr
const*, clang::CodeGen::AggValueSlot) /home/llvm-
project/clang/lib/CodeGen/CGExprCXX.cpp:634:0
#18 0x0000000004bf5a60 (anonymous
namespace)::AggExprEmitter::VisitCXXConstructExpr(clang::CXXConstructExpr
const*) /home/llvm-project/clang/lib/CodeGen/CGExprAgg.cpp:1278:0
#19 0x0000000004bfa668 clang::StmtVisitorBase<std::add_pointer, (anonymous
namespace)::AggExprEmitter, void>::Visit(clang::Stmt*)
/home/build/tools/clang/include/clang/AST/StmtNodes.inc:673:0
#20 0x0000000004befd52 (anonymous
namespace)::AggExprEmitter::Visit(clang::Expr*) /home/llvm-
project/clang/lib/CodeGen/CGExprAgg.cpp:104:0
#21 0x0000000004bf8bbb clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr
const*, clang::CodeGen::AggValueSlot) /home/llvm-
project/clang/lib/CodeGen/CGExprAgg.cpp:1861:0
#22 0x0000000004bb0dc6 EmitDeclInit(clang::CodeGen::CodeGenFunction&,
clang::VarDecl const&, clang::CodeGen::ConstantAddress) /home/llvm-
project/clang/lib/CodeGen/CGDeclCXX.cpp:60:0
#23 0x0000000004bb17d9
clang::CodeGen::CodeGenFunction::EmitCXXGlobalVarDeclInit(clang::VarDecl
const&, llvm::Constant*, bool) /home/llvm-
project/clang/lib/CodeGen/CGDeclCXX.cpp:213:0
#24 0x0000000004bb3e85
clang::CodeGen::CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function*,
clang::VarDecl const*, llvm::GlobalVariable*, bool) /home/llvm-
project/clang/lib/CodeGen/CGDeclCXX.cpp:665:0
#25 0x0000000004bb2cf5
clang::CodeGen::CodeGenModule::EmitCXXGlobalVarDeclInitFunc(clang::VarDecl
const*, llvm::GlobalVariable*, bool) /home/llvm-
project/clang/lib/CodeGen/CGDeclCXX.cpp:468:0
#26 0x00000000048fb8d8
clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*,
bool) /home/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4094:0
#27 0x00000000048f599f
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*) /home/llvm-
project/clang/lib/CodeGen/CodeGenModule.cpp:2835:0
#28 0x00000000048f4432
clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) /home/llvm-
project/clang/lib/CodeGen/CodeGenModule.cpp:2535:0
#29 0x0000000004900d1c
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) /home/llvm-
project/clang/lib/CodeGen/CodeGenModule.cpp:5245:0
#30 0x00000000059925ef (anonymous
namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef)
/home/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:169:0
#31 0x000000000598b0ee
clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) /home/llvm-
project/clang/lib/CodeGen/CodeGenAction.cpp:175:0
#32 0x0000000006bb3e49 clang::ParseAST(clang::Sema&, bool, bool) /home/llvm-
project/clang/lib/Parse/ParseAST.cpp:162:0
#33 0x0000000004f21daf clang::ASTFrontendAction::ExecuteAction() /home/llvm-
project/clang/lib/Frontend/FrontendAction.cpp:1044:0
#34 0x0000000005989a85 clang::CodeGenAction::ExecuteAction() /home/llvm-
project/clang/lib/CodeGen/CodeGenAction.cpp:1089:0
#35 0x0000000004f216fe clang::FrontendAction::Execute() /home/llvm-
project/clang/lib/Frontend/FrontendAction.cpp:940:0
#36 0x0000000004eb7209
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/llvm-
project/clang/lib/Frontend/CompilerInstance.cpp:964:0
#37 0x000000000508afe6
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/llvm-
project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:290:0
#38 0x00000000029ffffa cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) /home/llvm-project/clang/tools/driver/cc1_main.cpp:250:0
#39 0x00000000029f5591 ExecuteCC1Tool(llvm::ArrayRef<char const*>,
llvm::StringRef) /home/llvm-project/clang/tools/driver/driver.cpp:309:0
#40 0x00000000029f5ce6 main /home/llvm-
project/clang/tools/driver/driver.cpp:382:0
#41 0x00007f02a67ca830 __libc_start_main /build/glibc-LK5gWL/glibc-
2.23/csu/../csu/libc-start.c:325:0
#42 0x00000000029f3d59 _start (/home/build/bin/clang-10+0x29f3d59)
Quuxplusone commented 4 years ago

I suspect this will be caused by a middle-end pass inserting a cast instruction or rewriting IR, dropping the address space from the qualification causing an invalid cast to be generated.

The AVR backend places functions in addrspace(1), for program memory. The LLVM middle end can sometimes make incorrect assumptions about functions always residing in the default address space 0. (c.f. Pointer::getUnqual()).

This has propped up a couple times before, and is generally easily fixable.

We can --print-after-all passes to see where the addrspace(1) is dropped. Once the pass is identified, replace the existing pointer address space assumption in the code with a call to DataLayout::getProgramMemoryAddressSpace().

Quuxplusone commented 4 years ago
(In reply to Dylan McKay from comment #3)
> I suspect this will be caused by a middle-end pass inserting a cast

It is failing during IRGen by clang.