[llvm-dev] pointer arithmetic with address space attribute not working
Doerfert, Johannes via llvm-dev
llvm-dev at lists.llvm.org
Wed Oct 30 23:15:07 PDT 2019
Thanks for the detailed info!
The problem was that I tried without assertions and didn't inspect the IR closely as it contained this,
for now, illegal instruction: %6 = bitcast i8* %5 to i8 addrspace(1)*
This is clearly a clang error.
I suggest opening a bug report, or sending the reproducer to cfe-dev at llvm.lists.org so someone will take a look that has more clang experience.
@Matt Do you want to take this or ping the right person?
Cheers,
Johannes
________________________________________
From: Y Song <ys114321 at gmail.com>
Sent: Thursday, October 31, 2019 01:03
To: Doerfert, Johannes
Cc: LLVM Developers Mailing List; Alexei Starovoitov
Subject: Re: [llvm-dev] pointer arithmetic with address space attribute not working
The latest trunk. I am using llvm mono repo. The top two commits are:
b1209d74e3426e7aaa6e5f657d8b2a7554218767 (HEAD -> master,
origin/master, origin/HEAD) gn build: Merge 33a745e6fe7
33a745e6fe7e81d3793f7831d2832aa0785ef327 [clang][clang-scan-deps] Add
support for extracting full module dependencies.
This is my cmake flag, which has assertion turned on. I am tested on
linux platform.
cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja \
-DLLVM_ENABLE_PROJECTS="clang" \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DLLVM_TARGETS_TO_BUILD="BPF;X86" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_INSTALL_PREFIX=$PWD/install
On Wed, Oct 30, 2019 at 7:03 PM Doerfert, Johannes <jdoerfert at anl.gov> wrote:
>
> I forgot the -DADD flag earlier but the result did not change: https://godbolt.org/z/NPcn22
>
> ________________________________________
> From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Doerfert, Johannes via llvm-dev <llvm-dev at lists.llvm.org>
> Sent: Wednesday, October 30, 2019 20:18
> To: LLVM Developers Mailing List; Y Song
> Cc: Alexei Starovoitov
> Subject: Re: [llvm-dev] pointer arithmetic with address space attribute not working
>
> What clang version is that?
> I tried to reproduce it but failed: https://godbolt.org/z/AM1tPp
>
> ________________________________________
> From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Y Song via llvm-dev <llvm-dev at lists.llvm.org>
> Sent: Wednesday, October 30, 2019 17:56
> To: LLVM Developers Mailing List
> Cc: Alexei Starovoitov
> Subject: [llvm-dev] pointer arithmetic with address space attribute not working
>
> Hi,
>
> I have a case that for pointer with address space attribute, pointer
> arithmetic is not work.
>
> For example,
> -bash-4.4$ cat test.c
> #define __user __attribute__((address_space(1)))
> void __user * test(void __user *arg) {
> #ifdef ADD
> return arg + 4;
> #else
> return arg;
> #endif
> }
> -bash-4.4$
>
> -bash-4.4$ clang -g -c test.c
> -bash-4.4$ clang -g -c -DADD test.c
> clang-10: ../lib/IR/Instructions.cpp:2749: static llvm::CastInst
> *llvm::CastInst::Create(Instruction::CastOps, llvm::Value *,
> llvm::Type *, const llvm::Twine
> &, llvm::Instruction *): Assertion `castIsValid(op, S, Ty) && "Invalid
> cast!"' failed.
> Stack dump:
> 0. Program arguments:
> /data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10 -cc1
> -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disa
> ble-free -main-file-name test.c -mrelocation-model static
> -mthread-model posix -mframe-pointer=all -fmath-errno -masm-verbose
> -mconstructor-aliases -munwind-t
> ables -fuse-init-array -target-cpu x86-64 -dwarf-column-info
> -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb
> -resource-dir /data/users/yhs/work
> /llvm-project/llvm/build/install/lib/clang/10.0.0 -D ADD
> -internal-isystem /usr/local/include -internal-isystem
> /data/users/yhs/work/llvm-project/llvm/build/i
> nstall/lib/clang/10.0.0/include -internal-externc-isystem /include
> -internal-externc-isystem /usr/include -fdebug-compilation-dir
> /home/yhs/work/tests/user -f
> error-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1
> -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics
> -faddrsig -o test.o -x c test.c
> 1. <eof> parser at end of file
> 2. test.c:2:15: LLVM IR generation of declaration 'test'
> 3. test.c:2:15: Generating code for declaration 'test'
> #0 0x00000000017067bf llvm::sys::PrintStackTrace(llvm::raw_ostream&)
> (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x17067bf)
> #1 0x0000000001704a50 llvm::sys::RunSignalHandlers()
> (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x1704a50)
> #2 0x0000000001706d28 SignalHandler(int)
> (/data/users/yhs/work/llvm-project/llvm/build/install/bin/clang-10+0x1706d28)
> #3 0x00007fed0c6c3b10 __restore_rt
> (/usr/local/fbcode/platform007/lib/libpthread.so.0+0x12b10)
> #4 0x00007fed0b81214f raise
> (/usr/local/fbcode/platform007/lib/libc.so.6+0x3714f)
> #5 0x00007fed0b7fb935 abort
> (/usr/local/fbcode/platform007/lib/libc.so.6+0x20935)
> #6 0x00007fed0b80a107 __assert_fail_base
> (/usr/local/fbcode/platform007/lib/libc.so.6+0x2f107)
> #7 0x00007fed0b80a173 (/usr/local/fbcode/platform007/lib/libc.so.6+0x2f173)
> #8 0x00000000011b9381
> llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*,
> llvm::Type*, llvm::Twine const&, llvm::Instruction*) (/data/users/yhs/
> work/llvm-project/llvm/build/install/bin/clang-10+0x11b9381)
> #9 0x0000000001b5177f
> emitPointerArithmetic(clang::CodeGen::CodeGenFunction&, (anonymous
> namespace)::BinOpInfo const&, bool) (/data/users/yhs/work/llvm-proje
> ct/llvm/build/install/bin/clang-10+0x1b5177f)
> #10 0x0000000001b42b86 clang::StmtVisitorBase<std::add_pointer,
> (anonymous namespace)::ScalarExprEmitter,
> llvm::Value*>::Visit(clang::Stmt*) (/data/users/yhs/
> work/llvm-project/llvm/build/install/bin/clang-10+0x1b42b86)
> #11 0x0000000001b3a245
> clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*,
> bool) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/cla
> ng-10+0x1b3a245)
> #12 0x00000000019226c8
> clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt
> const&) (/data/users/yhs/work/llvm-project/llvm/build/install/bin/cla
> ng-10+0x19226c8)
>
> For pointer arithmetic failure, the clang tries to create a regular
> pointer and failed since non-None address space is specified in the
> type.
>
> Is this a bug? Or this is the expected behavior? I am asking since
> linux kernel has a lot of codes which did pointer arithmetic where
> pointers have address space attributes. (currently those address
> spaces are sparse tool checking only.)
>
> Thanks,
>
> Yonghong
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
More information about the llvm-dev
mailing list