Open Quuxplusone opened 3 years ago
Bugzilla Link | PR48713 |
Status | NEW |
Importance | P enhancement |
Reported by | Ryan Mansfield (rmansfield@gmail.com) |
Reported on | 2021-01-11 06:36:09 -0800 |
Last modified on | 2021-06-29 11:10:09 -0700 |
Version | trunk |
Hardware | PC All |
CC | cnsun@uwaterloo.ca, jdoerfert@anl.gov, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
Your patch seems right to me - we have to guard against "align 0" because the
LangRef says:
"if the alignment is set to zero, the alignment of the function is set by the
target to whatever it feels convenient"
Do you want to post a patch on Phabricator?
Here's a reduced IR testcase that fails with "opt -instsimplify":
define i8* @PR48713() {
%call = call i8* @a()
call void @llvm.assume(i1 true) [ "align"(i8* %call, i64 0) ]
%cmp = icmp eq i8* %call, null
%conv = zext i1 %cmp to i32
ret i8* null
}
declare void @llvm.assume(i1 noundef)
(In reply to Sanjay Patel from comment #1)
> define i8* @PR48713() {
> %call = call i8* @a()
> call void @llvm.assume(i1 true) [ "align"(i8* %call, i64 0) ]
> %cmp = icmp eq i8* %call, null
> %conv = zext i1 %cmp to i32
> ret i8* null
> }
>
> declare void @llvm.assume(i1 noundef)
Forgot to update the function name in the call instruction:
define i8* @PR48713() {
%call = call i8* @PR48713()
call void @llvm.assume(i1 true) [ "align"(i8* %call, i64 0) ]
%cmp = icmp eq i8* %call, null
%conv = zext i1 %cmp to i32
ret i8* null
}
(In reply to Sanjay Patel from comment #1)
> Your patch seems right to me - we have to guard against "align 0" because
> the LangRef says:
> "if the alignment is set to zero, the alignment of the function is set by
> the target to whatever it feels convenient"
>
> Do you want to post a patch on Phabricator?
>
Thanks, I can. Should I included the reduced IR testcase in the patch?
(In reply to Ryan Mansfield from comment #3)
Thanks, I can. Should I included the reduced IR testcase in the patch?
Yes - we always try to include a minimal regression test to ensure that a bug doesn't come back to life after being killed.
Patch is posted here: https://reviews.llvm.org/D94433
A possible duplicate here.
$ clang-trunk -v
clang version 13.0.0 (https://github.com/llvm/llvm-project.git
2e9c75daffddd65e37c3236708b5b133e6f5f2f5)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cnsun/usr/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
$ cat mutant.c
*a(int, int) __attribute__((alloc_align(1)));
b() {
int c;
double d = a(c, b)[c] = d;
}
$ clang-trunk -O1 mutant.c
mutant.c:1:2: warning: type specifier missing, defaults to 'int' [-Wimplicit-
int]
*a(int, int) __attribute__((alloc_align(1)));
^
mutant.c:2:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-
int]
b() {
^
mutant.c:4:19: warning: incompatible pointer to integer conversion passing 'int
()' to parameter of type 'int' [-Wint-conversion]
double d = a(c, b)[c] = d;
^
mutant.c:1:12: note: passing argument to parameter here
*a(int, int) __attribute__((alloc_align(1)));
^
mutant.c:5:1: warning: non-void function does not return a value [-Wreturn-type]
}
^
clang-13: /tmp/tmp.xjN6dMkdrg-clang-builder/llvm-
project/llvm/include/llvm/ADT/APInt.h:1482: void llvm::APInt::setBits(unsigned
int, unsigned int): Assertion `hiBit <= BitWidth && "hiBit out of range"'
failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /scratch/software/clang-trunk/bin/clang-13 -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj --mrelax-relocations -disable-free -main-
file-name mutant.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=/scratch/cnsun/workspace/perses-
fuzzer/default_c_finding_folder/crash_20210624_112258_040b/delta/perses_result -
resource-dir /scratch/software/clang-trunk/lib/clang/13.0.0 -c-isystem . -c-
isystem /usr/local/include/cmsith -internal-isystem /scratch/software/clang-
trunk/lib/clang/13.0.0/include -internal-isystem /usr/local/include -internal-
isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -
internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-
isystem /include -internal-externc-isystem /usr/include -O1 -fdebug-compilation-
dir=/scratch/cnsun/workspace/perses-
fuzzer/default_c_finding_folder/crash_20210624_112258_040b/delta/perses_result -
ferror-limit 19 -fgnuc-version=4.2.1 -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o
/tmp/mutant-cdf9ec.o -x c mutant.c
1. <eof> parser at end of file
2. Optimizer
#0 0x000056537237a184 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x000056537237793e SignalHandler(int) Signals.cpp:0:0
#2 0x00007f71f9d1c3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
#3 0x00007f71f97bb18b raise /build/glibc-ZN95T4/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#4 0x00007f71f979a859 abort /build/glibc-ZN95T4/glibc-2.31/stdlib/abort.c:81:7
#5 0x00007f71f979a729 get_sysdep_segment_value /build/glibc-ZN95T4/glibc-2.31/intl/loadmsgcat.c:509:8
#6 0x00007f71f979a729 _nl_load_domain /build/glibc-ZN95T4/glibc-2.31/intl/loadmsgcat.c:970:34
#7 0x00007f71f97abf36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
#8 0x0000565370054696 (/scratch/software/clang-trunk/bin/clang-13+0x1635696)
#9 0x00005653713bb6bc computeKnownBitsFromAssume(llvm::Value const*, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) ValueTracking.cpp:0:0
#10 0x00005653713bc8cb computeKnownBits(llvm::Value const*, llvm::APInt const&,
llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&)
ValueTracking.cpp:0:0
#11 0x00005653713bcf5e computeKnownBits(llvm::Value const*, llvm::KnownBits&,
unsigned int, (anonymous namespace)::Query const&) ValueTracking.cpp:0:0
#12 0x00005653713bf157 computeKnownBits(llvm::Value const*, unsigned int,
(anonymous namespace)::Query const&) ValueTracking.cpp:0:0
#13 0x00005653713bf202 llvm::computeKnownBits(llvm::Value const*,
llvm::DataLayout const&, unsigned int, llvm::AssumptionCache*,
llvm::Instruction const*, llvm::DominatorTree const*,
llvm::OptimizationRemarkEmitter*, bool) (/scratch/software/clang-
trunk/bin/clang-13+0x29a0202)
#14 0x000056537243c87e llvm::getOrEnforceKnownAlignment(llvm::Value*,
llvm::MaybeAlign, llvm::DataLayout const&, llvm::Instruction const*,
llvm::AssumptionCache*, llvm::DominatorTree const*) (/scratch/software/clang-
trunk/bin/clang-13+0x3a1d87e)
#15 0x0000565371d72f7f llvm::InstCombinerImpl::visitStoreInst(llvm::StoreInst&)
(/scratch/software/clang-trunk/bin/clang-13+0x3353f7f)
#16 0x0000565371cecfa8 llvm::InstCombinerImpl::run() (/scratch/software/clang-
trunk/bin/clang-13+0x32cdfa8)
#17 0x0000565371cef6e3 combineInstructionsOverFunction(llvm::Function&,
llvm::InstCombineWorklist&, llvm::AAResults*, llvm::AssumptionCache&,
llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&,
llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*,
llvm::ProfileSummaryInfo*, unsigned int, llvm::LoopInfo*)
InstructionCombining.cpp:0:0
#18 0x0000565371cf1741 llvm::InstCombinePass::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&) (/scratch/software/clang-
trunk/bin/clang-13+0x32d2741)
#19 0x0000565373552456 llvm::detail::PassModel<llvm::Function,
llvm::InstCombinePass, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&) (/scratch/software/clang-
trunk/bin/clang-13+0x4b33456)
#20 0x0000565371ab64d6 llvm::PassManager<llvm::Function,
llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&,
llvm::AnalysisManager<llvm::Function>&) (/scratch/software/clang-
trunk/bin/clang-13+0x30974d6)
#21 0x000056536ff4b836 llvm::detail::PassModel<llvm::Function,
llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >,
llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>
>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&)
(/scratch/software/clang-trunk/bin/clang-13+0x152c836)
#22 0x0000565371ab4ff9 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&) (/scratch/software/clang-trunk/bin/clang-
13+0x3095ff9)
#23 0x000056536ff4c0a6 llvm::detail::PassModel<llvm::Module,
llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses,
llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&) (/scratch/software/clang-trunk/bin/clang-
13+0x152d0a6)
#24 0x0000565371ab28df llvm::PassManager<llvm::Module,
llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&,
llvm::AnalysisManager<llvm::Module>&) (/scratch/software/clang-trunk/bin/clang-
13+0x30938df)
#25 0x00005653726ab6ad (anonymous
namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >) BackendUtil.cpp:0:0
#26 0x00005653726ae92d 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> >) (/scratch/software/clang-
trunk/bin/clang-13+0x3c8f92d)
#27 0x00005653734d7e1f
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/scratch/software/clang-trunk/bin/clang-13+0x4ab8e1f)
#28 0x000056537458f4d9 clang::ParseAST(clang::Sema&, bool, bool)
(/scratch/software/clang-trunk/bin/clang-13+0x5b704d9)
#29 0x00005653734d6968 clang::CodeGenAction::ExecuteAction()
(/scratch/software/clang-trunk/bin/clang-13+0x4ab7968)
#30 0x0000565372d86599 clang::FrontendAction::Execute()
(/scratch/software/clang-trunk/bin/clang-13+0x4367599)
#31 0x0000565372d197e6
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/scratch/software/clang-trunk/bin/clang-13+0x42fa7e6)
#32 0x0000565372e64480
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/scratch/software/clang-trunk/bin/clang-13+0x4445480)
#33 0x000056536fc84696 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/scratch/software/clang-trunk/bin/clang-13+0x1265696)
#34 0x000056536fc809d8 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
driver.cpp:0:0
#35 0x000056536fbae0e6 main (/scratch/software/clang-trunk/bin/clang-
13+0x118f0e6)
#36 0x00007f71f979c0b3 __libc_start_main /build/glibc-ZN95T4/glibc-
2.31/csu/../csu/libc-start.c:342:3
#37 0x000056536fc8054e _start (/scratch/software/clang-trunk/bin/clang-
13+0x126154e)
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 (https://github.com/llvm/llvm-project.git
2e9c75daffddd65e37c3236708b5b133e6f5f2f5)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cnsun/usr/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/mutant-8b3c17.c
clang-13: note: diagnostic msg: /tmp/mutant-8b3c17.sh
clang-13: note: diagnostic msg:
********************
I posted a comment on https://reviews.llvm.org/D94433 to see if we can make progress.