<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - clang crash in llvm/lib/IR/Constants.cpp:1981 Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!"' failed (under -O2 or -O3)"
href="https://bugs.llvm.org/show_bug.cgi?id=50368">50368</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang crash in llvm/lib/IR/Constants.cpp:1981 Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!"' failed (under -O2 or -O3)
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>haoxintu@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Hi all.
$cat small.c
#include <stdint.h>
int b;
uint64_t a;
void i(int c) {
int64_t d;
int64_t *e = &d;
uint64_t *f = &a;
for (; b; b++) {
int16_t *g = 1;
*g = (*e = *f) | (c %= *e);
a = 0;
}
}
$clang -w -O2 small.c (-O3 also crashes but without Assertion information)
clang-13: /home/tuhaoxin/compilers/llvm-project/llvm/lib/IR/Constants.cpp:1981:
static llvm::Constant *llvm::ConstantExpr::getCast(unsigned int, llvm::Constant
*, llvm::Type *, bool): Assertion `CastInst::castIsValid(opc, C, Ty) &&
"Invalid constantexpr cast!"' failed.
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments:
/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13 -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj --mrelax-relocations -disable-free
-main-file-name small.c -mrelocation-model static -mframe-pointer=none
-fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables
-target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb
-fcoverage-compilation-dir=/home/tuhaoxin/dut-research/covsmith-test/20210502/4
-resource-dir /home/tuhaoxin/compilers/llvm-project/build/lib/clang/13.0.0
-c-isystem /usr/local/include/csmith-2.4.0 -cxx-isystem
/usr/local/include/csmith-2.4.0 -internal-isystem
/home/tuhaoxin/compilers/llvm-project/build/lib/clang/13.0.0/include
-internal-isystem /usr/local/include -internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include -O2
-w -fdebug-compilation-dir=/home/tuhaoxin/dut-research/covsmith-test/20210502/4
-ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops
-vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-7f2a71.o
-x c small.c
1. <eof> parser at end of file
2. Optimizer
#0 0x0000000002a98d33 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x2a98d33)
#1 0x0000000002a96a7e llvm::sys::RunSignalHandlers()
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x2a96a7e)
#2 0x0000000002a990bf SignalHandler(int)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x2a990bf)
#3 0x00007fb74b9d13c0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
#4 0x00007fb74b46618b raise
/build/glibc-eX1tMB/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#5 0x00007fb74b445859 abort /build/glibc-eX1tMB/glibc-2.31/stdlib/abort.c:81:7
#6 0x00007fb74b445729 get_sysdep_segment_value
/build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:509:8
#7 0x00007fb74b445729 _nl_load_domain
/build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:970:34
#8 0x00007fb74b456f36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
#9 0x0000000002218cdc llvm::ConstantExpr::getCast(unsigned int,
llvm::Constant*, llvm::Type*, bool)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x2218cdc)
#10 0x0000000001baa3b4 llvm::SimplifyInstruction(llvm::Instruction*,
llvm::SimplifyQuery const&, llvm::OptimizationRemarkEmitter*)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x1baa3b4)
#11 0x0000000002b460ce llvm::simplifyLoopAfterUnroll(llvm::Loop*, bool,
llvm::LoopInfo*, llvm::ScalarEvolution*, llvm::DominatorTree*,
llvm::AssumptionCache*, llvm::TargetTransformInfo const*)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x2b460ce)
#12 0x0000000002b4b0c5 llvm::UnrollLoop(llvm::Loop*, llvm::UnrollLoopOptions,
llvm::LoopInfo*, llvm::ScalarEvolution*, llvm::DominatorTree*,
llvm::AssumptionCache*, llvm::TargetTransformInfo const*,
llvm::OptimizationRemarkEmitter*, bool, llvm::Loop**)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x2b4b0c5)
#13 0x00000000028c6f4b tryToUnrollLoop(llvm::Loop*, llvm::DominatorTree&,
llvm::LoopInfo*, llvm::ScalarEvolution&, llvm::TargetTransformInfo const&,
llvm::AssumptionCache&, llvm::OptimizationRemarkEmitter&,
llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, bool, int, bool, bool,
llvm::Optional<unsigned int>, llvm::Optional<unsigned int>,
llvm::Optional<bool>, llvm::Optional<bool>, llvm::Optional<bool>,
llvm::Optional<bool>, llvm::Optional<bool>, llvm::Optional<unsigned int>)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x28c6f4b)
#14 0x00000000028c58b8 llvm::LoopFullUnrollPass::run(llvm::Loop&,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&,
llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x28c58b8)
#15 0x0000000003a8b73d llvm::detail::PassModel<llvm::Loop,
llvm::LoopFullUnrollPass, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>,
llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&,
llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x3a8b73d)
#16 0x0000000003b681df llvm::Optional<llvm::PreservedAnalyses>
llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop,
llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&,
llvm::LPMUpdater&>::runSinglePass<llvm::Loop,
std::unique_ptr<llvm::detail::PassConcept<llvm::Loop,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>,
llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>,
std::default_delete<llvm::detail::PassConcept<llvm::Loop,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>,
llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&> > > >(llvm::Loop&,
std::unique_ptr<llvm::detail::PassConcept<llvm::Loop,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>,
llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>,
std::default_delete<llvm::detail::PassConcept<llvm::Loop,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>,
llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&> > >&,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&,
llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&,
llvm::PassInstrumentation&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x3b681df)
#17 0x0000000003b67f46 llvm::PassManager<llvm::Loop,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>,
llvm::LoopStandardAnalysisResults&,
llvm::LPMUpdater&>::runWithoutLoopNestPasses(llvm::Loop&,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&,
llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x3b67f46)
#18 0x0000000003b67638 llvm::PassManager<llvm::Loop,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>,
llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&,
llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&,
llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x3b67638)
#19 0x0000000003a800ad llvm::detail::PassModel<llvm::Loop,
llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop,
llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&,
llvm::LPMUpdater&>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Loop,
llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&,
llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop,
llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&,
llvm::LPMUpdater&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x3a800ad)
#20 0x0000000003b6936b llvm::FunctionToLoopPassAdaptor::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x3b6936b)
#21 0x0000000003a8be1d llvm::detail::PassModel<llvm::Function,
llvm::FunctionToLoopPassAdaptor, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x3a8be1d)
#22 0x000000000231e5c1 llvm::PassManager<llvm::Function,
llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x231e5c1)
#23 0x0000000000c315cd llvm::detail::PassModel<llvm::Function,
llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >,
llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>
<span class="quote">>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&)</span >
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0xc315cd)
#24 0x0000000001b364f0
llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC&,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x1b364f0)
#25 0x0000000000c3322d llvm::detail::PassModel<llvm::LazyCallGraph::SCC,
llvm::CGSCCToFunctionPassAdaptor, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0xc3322d)
#26 0x0000000001b30d21 llvm::PassManager<llvm::LazyCallGraph::SCC,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x1b30d21)
#27 0x000000000242105d llvm::detail::PassModel<llvm::LazyCallGraph::SCC,
llvm::PassManager<llvm::LazyCallGraph::SCC,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x242105d)
#28 0x0000000001b34abc
llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x1b34abc)
#29 0x000000000242153d llvm::detail::PassModel<llvm::LazyCallGraph::SCC,
llvm::DevirtSCCRepeatedPass, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&,
llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&,
llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x242153d)
#30 0x0000000001b331c3
llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x1b331c3)
#31 0x000000000242138d llvm::detail::PassModel<llvm::Module,
llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x242138d)
#32 0x000000000231d7e4 llvm::PassManager<llvm::Module,
llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x231d7e4)
#33 0x000000000241ecdb llvm::ModuleInlinerWrapperPass::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x241ecdb)
#34 0x0000000003a8fd4d llvm::detail::PassModel<llvm::Module,
llvm::ModuleInlinerWrapperPass, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x3a8fd4d)
#35 0x000000000231d7e4 llvm::PassManager<llvm::Module,
llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x231d7e4)
#36 0x0000000002d1da7e (anonymous
namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x2d1da7e)
#37 0x0000000002d171dd clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&,
clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef,
llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x2d171dd)
#38 0x00000000039cf178
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x39cf178)
#39 0x0000000004389003 clang::ParseAST(clang::Sema&, bool, bool)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x4389003)
#40 0x000000000334f443 clang::FrontendAction::Execute()
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x334f443)
#41 0x00000000032bf578
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x32bf578)
#42 0x00000000033ff4e2
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x33ff4e2)
#43 0x00000000009dc4bb cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x9dc4bb)
#44 0x00000000009da2dd ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x9da2dd)
#45 0x00000000009d9fc4 main
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x9d9fc4)
#46 0x00007fb74b4470b3 __libc_start_main
/build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:342:3
#47 0x00000000009d6f7e _start
(/home/tuhaoxin/compilers/llvm-project/build/bin/clang-13+0x9d6f7e)
clang-13: error: unable to execute command: Aborted (core dumped)
clang-13: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 13.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
06a9b0c6f445585393cdac3d488b7e9b28c7c5d5)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/tuhaoxin/compilers/llvm-project/build/bin
clang-13: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-13: note: diagnostic msg: /tmp/small-d35bed.c
clang-13: note: diagnostic msg: /tmp/small-d35bed.sh
clang-13: note: diagnostic msg:
********************
Reproduced on Godbolt: <a href="https://godbolt.org/z/98bzKEx3c">https://godbolt.org/z/98bzKEx3c</a>
Thanks,
Haoxin</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>