-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
__builtin_shufflevector
runs into an assertion if no integer expressions are passed
#92342
Comments
Hi! This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below. |
@llvm/issue-subscribers-good-first-issue Author: Timm Baeder (tbaederr)
See https://godbolt.org/z/M5x5Kdnc3, which uses a test case adapted from `test/Sema/constant_builtins_vector.cpp`.
clang++: /root/llvm-project/clang/include/clang/AST/Expr.h:4483: llvm::APSInt clang::ShuffleVectorExpr::getShuffleMaskIdx(const clang::ASTContext&, unsigned int) const: Assertion `(N < NumExprs - 2) && "Shuffle idx out of range!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++2b <source>
1. <source>:22:66: current parser token ';'
#<!-- -->0 0x00000000039a1548 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39a1548)
#<!-- -->1 0x000000000399f22c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x399f22c)
#<!-- -->2 0x00000000038f0288 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#<!-- -->3 0x000072fd01a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#<!-- -->4 0x000072fd01a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#<!-- -->5 0x000072fd01a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#<!-- -->6 0x000072fd01a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#<!-- -->7 0x000072fd01a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#<!-- -->8 0x000072fd01a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) We should just check for this case in Sema and reject it. |
@llvm/issue-subscribers-clang-frontend Author: Timm Baeder (tbaederr)
See https://godbolt.org/z/M5x5Kdnc3, which uses a test case adapted from `test/Sema/constant_builtins_vector.cpp`.
clang++: /root/llvm-project/clang/include/clang/AST/Expr.h:4483: llvm::APSInt clang::ShuffleVectorExpr::getShuffleMaskIdx(const clang::ASTContext&, unsigned int) const: Assertion `(N < NumExprs - 2) && "Shuffle idx out of range!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++2b <source>
1. <source>:22:66: current parser token ';'
#<!-- -->0 0x00000000039a1548 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39a1548)
#<!-- -->1 0x000000000399f22c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x399f22c)
#<!-- -->2 0x00000000038f0288 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#<!-- -->3 0x000072fd01a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#<!-- -->4 0x000072fd01a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#<!-- -->5 0x000072fd01a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#<!-- -->6 0x000072fd01a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#<!-- -->7 0x000072fd01a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#<!-- -->8 0x000072fd01a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) We should just check for this case in Sema and reject it. |
Hello, I'd like to give this issue a try :) |
@tbaederr Hello! I believe I've located the source of the bug. In QualType LHSType = TheCall->getArg(0)->getType();
QualType RHSType = TheCall->getArg(1)->getType();
// ...
if (TheCall->getNumArgs() == 2) {
if (!RHSType->hasIntegerRepresentation() || RHSType->castAs<VectorType>()->getNumElements() != numElements)
return ExprError(Diag(TheCall->getBeginLoc(),
diag::err_vec_builtin_incompatible_vector)
<< TheCall->getDirectCallee()
<< /*isMorethantwoArgs*/ false
<< SourceRange(TheCall->getArg(1)->getBeginLoc(), TheCall->getArg(1)->getEndLoc()));
// ... This is done to "support unary // Determine which of the following types of shufflevector we're checking:
// 1) unary, vector mask: (lhs, mask)
// 2) binary, scalar mask: (lhs, rhs, index, ..., index) However, I'm a little confused as to why. According to the clang 19.0.0 documentation,
thus there should be no reason it's called with only 2 vectors provided. Could it be that whoever wrote this comment was confusing clang's |
It seems like this was introduced in a011002, so seems intentional. |
@tbaederr So do we want to allow the programmer to use constexpr vector4char vector4charConst = {0, 1, 2, 3};
constexpr vector4int vector4intMask = {3, 2, 1, 0};
constexpr vector4char vectorShuffle = __builtin_shufflevector(vector4charConst, vector4intMask); despite the documentation saying this is invalid? Because GCC doesn't allow this either. GCC's implementation expects that you provide two vector arguments followed by indices. |
Even the documentation for If no tests break, there's an opportunity for cleanup up the |
See https://godbolt.org/z/M5x5Kdnc3, which uses a test case adapted from
test/Sema/constant_builtins_vector.cpp
.We should just check for this case in Sema and reject it.
The text was updated successfully, but these errors were encountered: