Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AlignmentFromAssumptions asserts on constexpr align operand bundle #50322

Closed
chengniansun opened this issue Jul 4, 2021 · 4 comments
Closed
Labels
bugzilla Issues migrated from bugzilla llvm:optimizations

Comments

@chengniansun
Copy link

Bugzilla Link 50978
Version trunk
OS All
CC @nikic,@zygoloid,@rotateright

Extended Description

$ clang-trunk -v
clang version 13.0.0 (https://github.com/llvm/llvm-project.git 6b0d266)
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, b;
*c(int, int) attribute((alloc_align(2)));
d() {
int e;
double *f = c(a, d);
b = f[e];
}

$ clang-trunk -w -O1 mutant.c
clang-13: /tmp/tmp.OKn6kNiY8c-clang-builder/llvm-project/llvm/include/llvm/Support/Casting.h:269: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::SCEVConstant; Y = const llvm::SCEV; typename llvm::cast_retty<X, Y*>::ret_type = const llvm::SCEVConstant*]: Assertion `isa(Val) && "cast() argument of incompatible type!"' 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_20210703_070011_023b/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 -w -fdebug-compilation-dir=/scratch/cnsun/workspace/perses-fuzzer/default_c_finding_folder/crash_20210703_070011_023b/delta/perses_result -ferror-limit 19 -fgnuc-version=4.2.1 -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/mutant-c4eb9b.o -x c mutant.c

  1. parser at end of file
  2. Optimizer
    #​0 0x00005608a5de1714 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
    #​1 0x00005608a5ddeece SignalHandler(int) Signals.cpp:0:0
    #​2 0x00007fb1563ac3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
    #​3 0x00007fb155e4b18b raise /build/glibc-ZN95T4/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
    #​4 0x00007fb155e2a859 abort /build/glibc-ZN95T4/glibc-2.31/stdlib/abort.c:81:7
    #​5 0x00007fb155e2a729 get_sysdep_segment_value /build/glibc-ZN95T4/glibc-2.31/intl/loadmsgcat.c:509:8
    #​6 0x00007fb155e2a729 _nl_load_domain /build/glibc-ZN95T4/glibc-2.31/intl/loadmsgcat.c:970:34
    #​7 0x00007fb155e3bf36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
    #​8 0x00005608a5a3473e getNewAlignmentDiff(llvm::SCEV const*, llvm::SCEV const*, llvm::ScalarEvolution*) AlignmentFromAssumptions.cpp:0:0
    #​9 0x00005608a5a34bf2 getNewAlignment(llvm::SCEV const*, llvm::SCEV const*, llvm::SCEV const*, llvm::Value*, llvm::ScalarEvolution*) AlignmentFromAssumptions.cpp:0:0
    #​10 0x00005608a5a35a6e llvm::AlignmentFromAssumptionsPass::processAssumption(llvm::CallInst*, unsigned int) (/scratch/software/clang-trunk/bin/clang-13+0x35e9a6e)
    #​11 0x00005608a5a36f2f llvm::AlignmentFromAssumptionsPass::runImpl(llvm::Function&, llvm::AssumptionCache&, llvm::ScalarEvolution*, llvm::DominatorTree*) (/scratch/software/clang-trunk/bin/clang-13+0x35eaf2f)
    #​12 0x00005608a5a370e8 llvm::AlignmentFromAssumptionsPass::run(llvm::Function&, llvm::AnalysisManagerllvm::Function&) (/scratch/software/clang-trunk/bin/clang-13+0x35eb0e8)
    #​13 0x00005608a71178d6 llvm::detail::PassModel<llvm::Function, llvm::AlignmentFromAssumptionsPass, llvm::PreservedAnalyses, llvm::AnalysisManagerllvm::Function >::run(llvm::Function&, llvm::AnalysisManagerllvm::Function&) (/scratch/software/clang-trunk/bin/clang-13+0x4ccb8d6)
    #​14 0x00005608a5517d26 llvm::PassManager<llvm::Function, llvm::AnalysisManagerllvm::Function >::run(llvm::Function&, llvm::AnalysisManagerllvm::Function&) (/scratch/software/clang-trunk/bin/clang-13+0x30cbd26)
    #​15 0x00005608a398f666 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManagerllvm::Function >, llvm::PreservedAnalyses, llvm::AnalysisManagerllvm::Function >::run(llvm::Function&, llvm::AnalysisManagerllvm::Function&) (/scratch/software/clang-trunk/bin/clang-13+0x1543666)
    #​16 0x00005608a5516849 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManagerllvm::Module&) (/scratch/software/clang-trunk/bin/clang-13+0x30ca849)
    #​17 0x00005608a398fed6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManagerllvm::Module >::run(llvm::Module&, llvm::AnalysisManagerllvm::Module&) (/scratch/software/clang-trunk/bin/clang-13+0x1543ed6)
    #​18 0x00005608a551412f llvm::PassManager<llvm::Module, llvm::AnalysisManagerllvm::Module >::run(llvm::Module&, llvm::AnalysisManagerllvm::Module&) (/scratch/software/clang-trunk/bin/clang-13+0x30c812f)
    #​19 0x00005608a61189fd (anonymous namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_deletellvm::raw_pwrite_stream >) BackendUtil.cpp:0:0
    #​20 0x00005608a611bc7d 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_deletellvm::raw_pwrite_stream >) (/scratch/software/clang-trunk/bin/clang-13+0x3ccfc7d)
    #​21 0x00005608a6f5275f clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/scratch/software/clang-trunk/bin/clang-13+0x4b0675f)
    #​22 0x00005608a800a419 clang::ParseAST(clang::Sema&, bool, bool) (/scratch/software/clang-trunk/bin/clang-13+0x5bbe419)
    #​23 0x00005608a6f512a8 clang::CodeGenAction::ExecuteAction() (/scratch/software/clang-trunk/bin/clang-13+0x4b052a8)
    #​24 0x00005608a67f4399 clang::FrontendAction::Execute() (/scratch/software/clang-trunk/bin/clang-13+0x43a8399)
    #​25 0x00005608a67873b6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/scratch/software/clang-trunk/bin/clang-13+0x433b3b6)
    #​26 0x00005608a68d20c0 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/scratch/software/clang-trunk/bin/clang-13+0x44860c0)
    #​27 0x00005608a36c4846 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/scratch/software/clang-trunk/bin/clang-13+0x1278846)
    #​28 0x00005608a36c0b88 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
    #​29 0x00005608a35ee156 main (/scratch/software/clang-trunk/bin/clang-13+0x11a2156)
    #​30 0x00007fb155e2c0b3 __libc_start_main /build/glibc-ZN95T4/glibc-2.31/csu/../csu/libc-start.c:342:3
    #​31 0x00005608a36c06fe _start (/scratch/software/clang-trunk/bin/clang-13+0x12746fe)
    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 6b0d266)
    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-fc9c62.c
clang-13: note: diagnostic msg: /tmp/mutant-fc9c62.sh
clang-13: note: diagnostic msg:


@nikic
Copy link
Contributor

nikic commented Jul 4, 2021

; RUN: opt -S -alignment-from-assumptions < %s

@​g = global i32 0

define void @​test(i32* %arg) {
call void @​llvm.assume(i1 true) [ "align"(i32* %arg, i64 zext (i32 ptrtoint (i32* @​g to i32) to i64)) ]
load i32, i32* %arg
ret void
}

declare void @​llvm.assume(i1)

@rotateright
Copy link
Contributor

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@kallisti5
Copy link

Witnessed in the Haiku clang build.

#53159

  • -O2 results in a crash
  • -O0 fixes the crash
  • Fixing the (incorrectly reported) alignment bug fixes the crash.

Technically memalign can accept a 0 alignment per the spec. "If size is 0, then posix_memalign() returns either NULL, or a unique pointer value that can later be successfully passed to free(3)."

@nikic nikic changed the title ICE on valid code with -O1: llvm::cast(Y*) [with X = llvm::SCEVConstant; Y = const llvm::SCEV; typename llvm::cast_retty<X, Y*>::ret_type = const llvm::SCEVConstant*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed. AlignmentFromAssumptions asserts on constexpr align operand bundle Apr 5, 2022
@nikic
Copy link
Contributor

nikic commented Apr 5, 2022

This has been fixed by 9b45fd9 in the meantime.

@nikic nikic closed this as completed Apr 5, 2022
@EugeneZelenko EugeneZelenko added llvm:optimizations and removed clang Clang issues not falling into any other category labels Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm:optimizations
Projects
None yet
Development

No branches or pull requests

5 participants