Skip to content

Constructing, destructing and returning a value of arbitrary type T causes static assertion failure inside LLVM's frontend #115658

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

Closed
TymianekPL opened this issue Nov 10, 2024 · 4 comments
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid] duplicate Resolved as duplicate

Comments

@TymianekPL
Copy link

TymianekPL commented Nov 10, 2024

Program: x86-64 clang 19.1.0 (assertions)
Example: Compiler Explorer
Log (same output inside the CE link above): clang-log.txt
Given the code:

void nop(void) noexcept
{
    typedef int T;
    return T{}.~T();
}

LLVM frontend crashes with assertion failure:

clang++: /root/llvm-project/clang/lib/AST/ExprConstant.cpp:10704: bool EvaluateTemporary(const clang::Expr*, {anonymous}::LValue&, {anonymous}::EvalInfo&): Assertion `E->isPRValue() && E->getType()->isRecordType()' failed.

Removing return keyword and leaving T{}.~T(); compiles successfully.

@TymianekPL
Copy link
Author

Seems to break on all versions after 10.0 (inclusive).
It compiles successfully on Clang 9.0.0, 8.0.0, ... up to Clang 2.7.0, and then it does not compile on Clang 2.6.0 with an error:

<source>:4:16: error: expected identifier
    return T().~T();

(note: changing brace initialisation to default constructor call produces the same issue on clang 10.*+)

@EugeneZelenko EugeneZelenko added clang:codegen IR generation bugs: mangling, exceptions, etc. confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Nov 10, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 10, 2024

@llvm/issue-subscribers-clang-codegen

Author: Tymianek (TymianekPL)

Program: x86-64 clang 19.1.0 (assertions) Example: [Compiler Explorer](https://godbolt.org/z/PWKsa6Tfc) Log (same output inside the CE link above): [clang-log.txt](https://github.com/user-attachments/files/17691513/clang-log.txt) Given the code: ```cpp void nop(void) noexcept { typedef int T; return T{}.~T(); } ``` LLVM frontend crashes with assertion failure: ``` clang++: /root/llvm-project/clang/lib/AST/ExprConstant.cpp:10704: bool EvaluateTemporary(const clang::Expr*, {anonymous}::LValue&, {anonymous}::EvalInfo&): Assertion `E->isPRValue() && E->getType()->isRecordType()' failed. ```

Removing return keyword and leaving T{}.~T(); compiles successfully.

@TymianekPL
Copy link
Author

Seems like the code below compiles successfully.

void yes(void)
{
     using U = decltype([]{});
     using T = decltype([]{ return U(); });
     return T()().~U();
}

@TymianekPL
Copy link
Author

So does

void yes(void)
{
     using U = decltype([]consteval{ using I = int; return I().~I(); });
     using T = decltype([]consteval{ return U(); });
     return T()().~U();
}

Which is a little weird, considering it uses the same code inside the lambda as the one that did indeed crash the compiler.. aha..

@shafik shafik closed this as completed Feb 4, 2025
@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid] duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants