[llvm-bugs] [Bug 49620] New: Assertion failure when using overloaded non-binary operator in requires clause

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 17 12:38:58 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=49620

            Bug ID: 49620
           Summary: Assertion failure when using overloaded non-binary
                    operator in requires clause
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david at doublewise.net
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

The following translation unit

```
struct s
{
};
bool operator!(const s &);

void f() requires(!s());
```

causes clang to crash with

```
clang-13: /home/david/llvm/clang/include/clang/AST/Expr.h:2926: const
clang::Expr* clang::CallExpr::getArg(unsigned int) const: Assertion `Arg <
getNumArgs() && "Arg access 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: /home/david/llvm/build/bin/clang-13 -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations
-disable-free -main-file-name llvm-crash.cpp -mrelocation-model static
-mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases
-munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb
-fcoverage-compilation-dir=/home/david/llvm -resource-dir
/home/david/llvm/build/lib/clang/13.0.0 -internal-isystem
/usr/lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0
-internal-isystem
/usr/lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/x86_64-pc-linux-gnu
-internal-isystem
/usr/lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/backward
-internal-isystem /usr/local/include -internal-isystem
/home/david/llvm/build/lib/clang/13.0.0/include -internal-externc-isystem
/include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro
-fdebug-compilation-dir=/home/david/llvm -ferror-limit 19 -fgnuc-version=4.2.1
-fno-implicit-modules -fcxx-exceptions -fexceptions -fcolor-diagnostics
-faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/llvm-crash-3d77a6.o -x c++
/home/david/llvm-crash.cpp
1.      /home/david/llvm-crash.cpp:6:24: current parser token ';'
 #0 0x000055c122bc6f6d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/home/david/llvm/build/bin/clang-13+0x1f46f6d)
 #1 0x000055c122bc4b84 llvm::sys::RunSignalHandlers()
(/home/david/llvm/build/bin/clang-13+0x1f44b84)
 #2 0x000055c122bc4cf3 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007ff65c519960 __restore_rt sigaction.c:0:0
 #4 0x00007ff65bf5eef5 raise (/usr/lib/libc.so.6+0x3cef5)
 #5 0x00007ff65bf48862 abort (/usr/lib/libc.so.6+0x26862)
 #6 0x00007ff65bf48747 _nl_load_domain.cold loadmsgcat.c:0:0
 #7 0x00007ff65bf57646 (/usr/lib/libc.so.6+0x35646)
 #8 0x000055c124e47265 clang::Sema::CheckConstraintExpression(clang::Expr
const*, clang::Token, bool*, bool)
(/home/david/llvm/build/bin/clang-13+0x41c7265)
 #9 0x000055c124c72308 clang::Parser::ParseConstraintLogicalAndExpression(bool)
(/home/david/llvm/build/bin/clang-13+0x3ff2308)
#10 0x000055c124c7272d clang::Parser::ParseConstraintLogicalOrExpression(bool)
(/home/david/llvm/build/bin/clang-13+0x3ff272d)
#11 0x000055c124c4c2aa
clang::Parser::ParseTrailingRequiresClause(clang::Declarator&)
(/home/david/llvm/build/bin/clang-13+0x3fcc2aa)
#12 0x000055c124c402d3 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&,
clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*)
(/home/david/llvm/build/bin/clang-13+0x3fc02d3)
#13 0x000055c124c10582
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#14 0x000055c124c16ad6
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) (/home/david/llvm/build/bin/clang-13+0x3f96ad6)
#15 0x000055c124c177b8
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)
(/home/david/llvm/build/bin/clang-13+0x3f977b8)
#16 0x000055c124c09e09 clang::ParseAST(clang::Sema&, bool, bool)
(/home/david/llvm/build/bin/clang-13+0x3f89e09)
#17 0x000055c1235556a9 clang::FrontendAction::Execute()
(/home/david/llvm/build/bin/clang-13+0x28d56a9)
#18 0x000055c1234e6095
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/david/llvm/build/bin/clang-13+0x2866095)
#19 0x000055c123618663
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/david/llvm/build/bin/clang-13+0x2998663)
#20 0x000055c121841641 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/david/llvm/build/bin/clang-13+0xbc1641)
#21 0x000055c12183cdf0 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
driver.cpp:0:0
#22 0x000055c1217a86b9 main (/home/david/llvm/build/bin/clang-13+0xb286b9)
#23 0x00007ff65bf49b25 __libc_start_main (/usr/lib/libc.so.6+0x27b25)
#24 0x000055c12183c76e _start (/home/david/llvm/build/bin/clang-13+0xbbc76e)
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
420d90d8137e9de7cda7c948f43ea4e50703d75f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/david/llvm/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/llvm-crash-b6d081.cpp
clang-13: note: diagnostic msg: /tmp/llvm-crash-b6d081.sh
clang-13: note: diagnostic msg: 

********************
```

Note that the issue can also come up if an overloaded `operator!` is found as a
candidate by overload resolution in a dependent context (which is almost all
uses of requires clauses), so this issue is harder to avoid than it seems. For
example, the following code causes the same crash:

```
struct s
{
};
bool operator!(const s &) {
        return false;
}

template <class T>
constexpr bool false_ = false;

template <class T>
void f() requires(!false_<T>);
```

It looks like the constructor for `LogicalBinOp` accepts any expression and is
boolean testable, such that if it is `true` it's a logical binary operator
(`and` or `or`), but its constructor actually just checks for whether it got
any kind of operator and then grabs the first two parameters. In other words,
the same issue occurs for any unary operator, including prefix `operator*`,
`operator+`, `operator++`, `operator--`, and additionally `operator()` when
passed no parameters.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210317/0d6ac0ba/attachment.html>


More information about the llvm-bugs mailing list