Timm Baeder
890cdbe653
[clang][bytecode] Handle a null record better ( #179645 )
...
This would otherwise later assert in vsitZeroRecordInitializer().
2026-02-04 14:17:11 +01:00
Timm Baeder
cd31effb0a
[clang][bytecode] Reject invalid CXXNewExprs ( #179629 )
...
If they contain errors, we can't rely on any of their API returning sane
values.
2026-02-04 13:55:50 +01:00
Timm Baeder
68850427ba
[clang][bytecode] Reject CK_BitCast nodes with errors early ( #179087 )
...
Fixes https://github.com/llvm/llvm-project/issues/179020
2026-02-01 10:08:06 +01:00
Serosh
60250aaa25
[clang][bytecode] Fix crash in void functions returning non-void expr… ( #176550 )
...
The bytecode compiler was incorrectly emitting an
RVOPtr
opcode for void functions if the return expression had a non-void type
(e.g. from a conditional operator). This triggered an assertion in the
interpreter because void functions lack RVO metadata.
This patch updates
visitReturnStmt
to check the function’s return type and use
discard()
for the expression in void contexts, preventing erroneous RVO pathing.
Fixes #176536
2026-01-27 07:18:22 +01:00
FYLGQ
e68eadf849
[clang][bytecode] Fix crash on discarded complex comparison ( #177731 )
...
Fixes llvm#176902: [clang][bytecode] crashes on ill-formed
_Static_assert comparing complex value
This patch resolves a crash in Clang's constant evaluation when handling
complex number comparisons in discarded expressions, such as those
involving short-circuiting logical operators. The crash occurred due to
unnecessary evaluation of the comparison in the experimental constant
interpreter.
The issue was originally observed and minimized in the following
example:
```cpp
#define EVAL(a, b) _Static_assert(a == b, "")
void foo() {
EVAL(; + 0, 1i);
}
```
This patch ensures that such comparisons are handled correctly without
triggering assertions when the result is discarded.
Tests
A regression test has been added to verify that complex comparisons in
discarded expressions no longer cause crashes during constant
evaluation.
Local verification:
llvm-project-main/clang/lib/AST/ByteCode/constant-eval-complex-discard.c
passes.
Full ninja check-clang may fail locally due to a known GCC ICE when
building Clang unittests; this is unrelated to the change itself.
2026-01-26 07:52:17 +01:00
Timm Baeder
323bb14349
[clang][bytecode] Finish support for msvc::constexpr ( #177388 )
...
Keep track of whether an `InterpFrame` is allowed to call
`msvc::constexpr` functions via two new opcodes.
2026-01-23 11:25:21 +01:00
Timm Baeder
d904de0806
[clang][bytecode] Fix a diagnostic discrepancy ( #177384 )
...
The current interpreter does _not_ evaluate function calls when checking
for a potential constant expression.
However, it _does_ evaluate the initializers of constructors. In the
bytecode interpreter, this is harder because we compile the initializers
and the body of a constructor all in the same function.
Add a special opcode that we emit after the constructor initializers and
that aborts when we're checking for a potential constant expression.
2026-01-23 08:36:03 +01:00
Timm Baeder
bba7942006
[clang][bytecode] LValueBitCasts are not fatal ( #176947 )
...
We can cast from lvalue to lvalue (they are Pointers), so don't
prematurely abort here.
2026-01-20 17:31:39 +01:00
Timm Baeder
25b4d1e1de
[clang][bytecode] Don't evaluate builtin_assume argument ( #175740 )
...
This is what the current interpreter does.
2026-01-13 12:33:58 +01:00
Timm Baeder
b0445a1ee6
[clang][bytecode] Diagnose regular CK_LValueBitCast cast nodes ( #175721 )
...
We already do this similarly for CXXReinterpretCastExprs, except in that
case we try harder to make things work.
2026-01-13 09:28:02 +01:00
Timm Baeder
dc1a886fb9
[clang][bytecode] Fix CK_ToVoid casts for Complex values ( #175709 )
...
We need to remove the pointer to the local variable we've created
specifically for this complex binary operator.
Fixes https://github.com/llvm/llvm-project/issues/175670
2026-01-13 08:19:27 +01:00
Timm Baeder
3c51ed9870
[clang][bytecode] Fix initializing array elems from string ( #175170 )
...
In the `= {"foo"}` case, we don't have an array filler we can use and we
need to explicitily zero the remaining elements.
2026-01-09 16:35:07 +01:00
Timm Baeder
eec258dcf3
[clang][bytecode] Diagnose unknown reference params pre-C++23 ( #175013 )
...
Otherwise, we will ultimately create dummy pointers for them and
possibly not diagnose anything.
2026-01-09 08:11:17 +01:00
Timm Baeder
4da37d3295
[clang][bytecode] Check for non-trivial default ctors in unions ( #174745 )
...
When activating a union member, none of the unions in that path can have
a non-trivial constructor. Unfortunately, this is something we have to
do when evaluating the bytecode, not while compiling it.
2026-01-08 06:07:12 +01:00
Timm Baeder
4fdbe05d6e
[clang][bytecode] Fix some imag/real corner cases ( #174764 )
...
Fix real/imag when taking a primitive parameter _and_ being discarded,
and fix the case where their subexpression can't be classified.
Fixes https://github.com/llvm/llvm-project/issues/174668
2026-01-07 14:49:23 +01:00
Timm Baeder
787a476c92
[clang][bytecode] Mark volatile composite locals as such ( #174407 )
...
We were forgetting to pass the volatile-ness along.
2026-01-05 16:41:50 +01:00
Timm Baeder
bd784b6222
[clang][bytecode] Fix typeid test under msan ( #174317 )
...
The original problem description sounded sane but it was lacking a bit.
What happens where is that the global block is ultimately not
initialized simply because it was already created before and its
initializer failed, causing us to call invokeDtor() in a previous
evaluation.
Check for the initialion state earlier and abort there instead of
accessing the (now uninitialized) data of the block, causing msan
failures.
See the failed msan build at
https://lab.llvm.org/buildbot/#/builders/164/builds/17206
2026-01-04 19:05:17 +01:00
Aiden Grossman
22390cd741
Revert "[clang][bytecode] Check if block is initialized before invoking destructor ( #174082 )"
...
This reverts commit 7976ac990000a58a7474269a3ca95e16aed8c35b.
This is causing msan failures. msan-track-origins stack trace:
==9441==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x55c20df74ad3 in clang::interp::Pointer::operator=(clang::interp::Pointer&&) llvm-project/clang/lib/AST/ByteCode/Pointer.cpp:137:7
#1 0x55c20db81010 in bool clang::interp::InitGlobal<(clang::interp::PrimType)13, clang::interp::Pointer>(clang::interp::InterpState&, clang::interp::CodePtr, unsigned int) llvm-project/clang/lib/AST/ByteCode/Interp.h:1478:16
#2 0x55c20db7ec56 in emitInitGlobalPtr blaze-out/k8-fastbuild-msan/bin/llvm-project/clang/_virtual_includes/ast_bytecode_opcodes_gen/Opcodes.inc:26162:10
#3 0x55c20db7ec56 in clang::interp::EvalEmitter::emitInitGlobal(clang::interp::PrimType, unsigned int, clang::interp::SourceInfo) blaze-out/k8-fastbuild-msan/bin/llvm-project/clang/_virtual_includes/ast_bytecode_opcodes_gen/Opcodes.inc:26042:12
#4 0x55c20da58b87 in clang::interp::Compiler<clang::interp::EvalEmitter>::visitVarDecl(clang::VarDecl const*, clang::Expr const*, bool, bool) llvm-project/clang/lib/AST/ByteCode/Compiler.cpp:4924:20
#5 0x55c20da64a61 in clang::interp::Compiler<clang::interp::EvalEmitter>::visitDeclAndReturn(clang::VarDecl const*, clang::Expr const*, bool) llvm-project/clang/lib/AST/ByteCode/Compiler.cpp:4831:14
#6 0x55c20da7f290 in clang::interp::EvalEmitter::interpretDecl(clang::VarDecl const*, clang::Expr const*, bool) llvm-project/clang/lib/AST/ByteCode/EvalEmitter.cpp:66:14
#7 0x55c20d970d23 in clang::interp::Context::evaluateAsInitializer(clang::interp::State&, clang::VarDecl const*, clang::Expr const*, clang::APValue&) llvm-project/clang/lib/AST/ByteCode/Context.cpp:141:16
#8 0x55c20e25b8de in clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::__msan::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const llvm-project/clang/lib/AST/ExprConstant.cpp:20754:20
#9 0x55c20da368d5 in clang::interp::Compiler<clang::interp::EvalEmitter>::visitDeclRef(clang::ValueDecl const*, clang::Expr const*) llvm-project/clang/lib/AST/ByteCode/Compiler.cpp:7162:19
#10 0x55c20da34986 in clang::interp::Compiler<clang::interp::EvalEmitter>::VisitDeclRefExpr(clang::DeclRefExpr const*) llvm-project/clang/lib/AST/ByteCode/Compiler.cpp:7192:16
#11 0x55c20da66666 in clang::StmtVisitorBase<llvm::make_const_ptr, clang::interp::Compiler<clang::interp::EvalEmitter>, bool>::Visit(clang::Stmt const*) blaze-out/k8-fastbuild-msan/bin/llvm-project/clang/include/clang/AST/StmtNodes.inc:474:1
#12 0x55c20da65d3f in clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) llvm-project/clang/lib/AST/ByteCode/Compiler.cpp:4293:16
#13 0x55c20da57348 in clang::interp::Compiler<clang::interp::EvalEmitter>::VisitCXXTypeidExpr(clang::CXXTypeidExpr const*) llvm-project/clang/lib/AST/ByteCode/Compiler.cpp:3893:14
#14 0x55c20da66760 in clang::StmtVisitorBase<llvm::make_const_ptr, clang::interp::Compiler<clang::interp::EvalEmitter>, bool>::Visit(clang::Stmt const*) blaze-out/k8-fastbuild-msan/bin/llvm-project/clang/include/clang/AST/StmtNodes.inc:658:1
#15 0x55c20da65d3f in clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) llvm-project/clang/lib/AST/ByteCode/Compiler.cpp:4293:16
#16 0x55c20da58afc in clang::interp::Compiler<clang::interp::EvalEmitter>::visitVarDecl(clang::VarDecl const*, clang::Expr const*, bool, bool) llvm-project/clang/lib/AST/ByteCode/Compiler.cpp:4921:18
#17 0x55c20da64a61 in clang::interp::Compiler<clang::interp::EvalEmitter>::visitDeclAndReturn(clang::VarDecl const*, clang::Expr const*, bool) llvm-project/clang/lib/AST/ByteCode/Compiler.cpp:4831:14
#18 0x55c20da7f290 in clang::interp::EvalEmitter::interpretDecl(clang::VarDecl const*, clang::Expr const*, bool) llvm-project/clang/lib/AST/ByteCode/EvalEmitter.cpp:66:14
#19 0x55c20d970d23 in clang::interp::Context::evaluateAsInitializer(clang::interp::State&, clang::VarDecl const*, clang::Expr const*, clang::APValue&) llvm-project/clang/lib/AST/ByteCode/Context.cpp:141:16
#20 0x55c20e25b8de in clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::__msan::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const llvm-project/clang/lib/AST/ExprConstant.cpp:20754:20
#21 0x55c20dfdcc38 in clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::__msan::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const llvm-project/clang/lib/AST/Decl.cpp:2608:23
#22 0x55c20dfdd1a2 in clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::__msan::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const llvm-project/clang/lib/AST/Decl.cpp:2687:7
#23 0x55c20b9154da in clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) llvm-project/clang/lib/Sema/SemaDecl.cpp:14941:27
#24 0x55c20b910f36 in clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) llvm-project/clang/lib/Sema/SemaDecl.cpp:14280:3
#25 0x55c20ad044ee in clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) llvm-project/clang/lib/Parse/ParseDecl.cpp:2639:17
#26 0x55c20acfe9f8 in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) llvm-project/clang/lib/Parse/ParseDecl.cpp:2356:7
#27 0x55c20abd8a43 in clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) llvm-project/clang/lib/Parse/Parser.cpp:1181:10
#28 0x55c20abd7654 in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) llvm-project/clang/lib/Parse/Parser.cpp:1203:12
#29 0x55c20abd4d9c in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) llvm-project/clang/lib/Parse/Parser.cpp:1031:14
#30 0x55c20ac96f31 in clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:240:7
#31 0x55c20ac950c7 in clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:218:3
#32 0x55c20acfb09b in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) llvm-project/clang/lib/Parse/ParseDecl.cpp:1909:12
#33 0x55c20abd3f88 in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) llvm-project/clang/lib/Parse/Parser.cpp
#34 0x55c20abcfe33 in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) llvm-project/clang/lib/Parse/Parser.cpp:744:12
#35 0x55c20abb214e in clang::ParseAST(clang::Sema&, bool, bool) llvm-project/clang/lib/Parse/ParseAST.cpp:170:20
#36 0x55c20a90adaa in clang::ASTFrontendAction::ExecuteAction() llvm-project/clang/lib/Frontend/FrontendAction.cpp:1432:3
#37 0x55c20a9095bf in clang::FrontendAction::Execute() llvm-project/clang/lib/Frontend/FrontendAction.cpp:1312:3
#38 0x55c20a76cdc7 in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1004:33
#39 0x55c20805aab0 in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:310:25
#40 0x55c20802e823 in cc1_main(llvm::ArrayRef<char const*>, char const*, void*) llvm-project/clang/tools/driver/cc1_main.cpp:304:15
#41 0x55c2080218ec in ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) llvm-project/clang/tools/driver/driver.cpp:225:12
#42 0x55c20801ea91 in clang_main(int, char**, llvm::ToolContext const&) llvm-project/clang/tools/driver/driver.cpp:268:12
#43 0x55c20801a6af in main blaze-out/k8-fastbuild-msan/bin/llvm-project/clang/clang-driver.cpp:17:10
#44 0x7f79c4214351 in __libc_start_main (/usr/libc/lib64/libc.so.6+0x61351) (BuildId: ca23ec6d935352118622ce674a8bb52d)
#45 0x55c207f8c2e9 in _start /usr/libc/debug-src/src/csu/../sysdeps/x86_64/start.S:120
Member fields were destroyed
#0 0x55c207f9f5fd in __sanitizer_dtor_callback_fields llvm-project/compiler-rt/lib/msan/msan_interceptors.cpp:1074:5
#1 0x55c20df74380 in ~Pointer llvm-project/clang/lib/AST/ByteCode/Pointer.h:826:12
#2 0x55c20df74380 in clang::interp::Pointer::~Pointer() llvm-project/clang/lib/AST/ByteCode/Pointer.cpp:93:1
#3 0x55c20da7c5ab in void dtorTy<clang::interp::Pointer>(clang::interp::Block*, std::byte*, clang::interp::Descriptor const*) llvm-project/clang/lib/AST/ByteCode/Descriptor.cpp:49:32
#4 0x55c20d976b91 in clang::interp::Block::invokeDtor() llvm-project/clang/lib/AST/ByteCode/InterpBlock.h:149:7
#5 0x55c20da651a1 in clang::interp::Compiler<clang::interp::EvalEmitter>::visitDeclAndReturn(clang::VarDecl const*, clang::Expr const*, bool) llvm-project/clang/lib/AST/ByteCode/Compiler.cpp:4869:22
#6 0x55c20da7f290 in clang::interp::EvalEmitter::interpretDecl(clang::VarDecl const*, clang::Expr const*, bool) llvm-project/clang/lib/AST/ByteCode/EvalEmitter.cpp:66:14
#7 0x55c20d970d23 in clang::interp::Context::evaluateAsInitializer(clang::interp::State&, clang::VarDecl const*, clang::Expr const*, clang::APValue&) llvm-project/clang/lib/AST/ByteCode/Context.cpp:141:16
#8 0x55c20e25b8de in clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::__msan::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const llvm-project/clang/lib/AST/ExprConstant.cpp:20754:20
#9 0x55c20dfdcc38 in clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::__msan::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const llvm-project/clang/lib/AST/Decl.cpp:2608:23
#10 0x55c20dfdd1a2 in clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::__msan::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const llvm-project/clang/lib/AST/Decl.cpp:2687:7
#11 0x55c20b9154da in clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) llvm-project/clang/lib/Sema/SemaDecl.cpp:14941:27
#12 0x55c20b910f36 in clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) llvm-project/clang/lib/Sema/SemaDecl.cpp:14280:3
#13 0x55c20ad044ee in clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) llvm-project/clang/lib/Parse/ParseDecl.cpp:2639:17
#14 0x55c20acfe9f8 in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) llvm-project/clang/lib/Parse/ParseDecl.cpp:2356:7
#15 0x55c20abd8a43 in clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) llvm-project/clang/lib/Parse/Parser.cpp:1181:10
#16 0x55c20abd7654 in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) llvm-project/clang/lib/Parse/Parser.cpp:1203:12
#17 0x55c20abd4d9c in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) llvm-project/clang/lib/Parse/Parser.cpp:1031:14
#18 0x55c20ac96f31 in clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:240:7
#19 0x55c20ac950c7 in clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:218:3
#20 0x55c20acfb09b in clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) llvm-project/clang/lib/Parse/ParseDecl.cpp:1909:12
2026-01-04 08:37:02 +00:00
nataliakokoromyti
7976ac9900
[clang][bytecode] Check if block is initialized before invoking destructor ( #174082 )
...
Fixes #173950 .
The bytecode interpreter was crashing when evaluating typeid() on
references to dynamically allocated objects. For example, this would
cause an assertion failure:
static A &a = *new A;
const std::type_info &a_ti = typeid(a);
The problem was that when initialization failed, the code tried to call
invokeDtor() on blocks that were never marked as initialized. This
caused the assertion "IsInitialized" to fail. With this fix, we first
check if the block is actually initialized before trying to invoke its
destructor.
The test case I added reproduces the original crash and with the fix, it
now passes.
2026-01-02 16:49:44 +01:00
Timm Baeder
508e3cb7e7
[clang][bytecode] Check for null Record ( #174193 )
...
This is an error case that results in a null Record, so don't crash
later in that case.
Fixes #173941
2026-01-02 11:59:24 +01:00
Timm Baeder
db557bee1e
[clang][bytecode][NFC] Add Block::getBlockDesc<T>() ( #172218 )
...
Which returns the block-level descriptor. This way we don't have to do
the reinterpret_cast dance everywhere.
2025-12-15 09:21:41 +01:00
Timm Baeder
ad29ee51f4
[clang][bytecode] Always initialize scope before conditional operator ( #171133 )
...
Otherwise, the scope might be (lazily) initialized in one of the arms of
the conditional operator, which means the will NOT be intialized in the
other arm.
Fixes https://github.com/llvm/llvm-project/issues/170981
2025-12-09 08:03:27 +01:00
Timm Baeder
5b2eb0dcb7
[clang][bytecode][NFC] Add FullExpression scopes ( #170705 )
...
And use them instead of the extending decl. This is close to what the
current interpreter is doing.
This is NFC right now but fixes a problem I encountered while looking
into the expansion statement stuff.
2025-12-05 10:22:37 +01:00
Timm Baeder
b1620996f4
[clang][bytecode] Fix discarding ImplitiValueInitExprs ( #170089 )
...
They don't have side-effects, so this should be fine.
Fixes https://github.com/llvm/llvm-project/issues/170064
2025-12-01 11:33:33 +01:00
Timm Baeder
d44d329c0b
[clang][bytecode] Fix compound assign operators for IntAP(S) ( #169303 )
...
We didn't take `IntAP`/`IntAPS` into account when casting to and from
the computation LHS type. This broke the
`std/ranges/range.factories/range.iota.view/end.pass.cpp` test.
2025-11-24 11:48:00 +01:00
Timm Baeder
95f0fab7fa
[clang][bytecode] Fix conditional operator scoping wrt. local variables ( #169030 )
...
We used to create a scope for the true- and false expression of a
conditional operator. This was done so e.g. in this example:
```c++
struct A { constexpr A(){}; ~A(); constexpr int get() { return 10; } }; // all-note 2{{declared here}}
static_assert( (false ? A().get() : 1) == 1);
```
we did _not_ evaluate the true branch at all, meaning we did not
register the local variable for the temporary of type `A`, which means
we also didn't call it destructor.
However, this breaks the case where the temporary needs to outlive the
conditional operator and instead be destroyed via the surrounding
`ExprWithCleanups`:
```
constexpr bool test2(bool b) {
unsigned long __ms = b ? (const unsigned long &)0 : __ms;
return true;
}
static_assert(test2(true));
```
Before this patch, we diagnosed this example:
```console
./array.cpp:180:15: error: static assertion expression is not an integral constant expression
180 | static_assert(test2(true));
| ^~~~~~~~~~~
./array.cpp:177:24: note: read of temporary whose lifetime has ended
177 | unsigned long __ms = b ? (const unsigned long &)0 : __ms;
| ^
./array.cpp:180:15: note: in call to 'test2(true)'
180 | static_assert(test2(true));
| ^~~~~~~~~~~
./array.cpp:177:51: note: temporary created here
177 | unsigned long __ms = b ? (const unsigned long &)0 : __ms;
| ^
1 error generated.
```
because the temporary created for the true branch got immediately
destroyed.
The problem in essence is that since the conditional operator doesn't
create a scope at all, we register the local variables for both its
branches, but we later only execute one of them, which means we should
also only destroy the locals of one of the branches.
We fix this similar to clang codgen's `is_active` flag: In the case of a
conditional operator (which is so far the only case where this is
problematic, and this also helps minimize the performance impact of this
change), we make local variables as disabled-by-default and then emit a
`EnableLocal` opcode later, which marks them as enabled. The code
calling their destructors checks whether the local was enabled at all.
2025-11-24 07:34:48 +01:00
Timm Baeder
cc4dd015ad
[clang][bytecode][NFC] Remove VariableScope::emitDestruction ( #169148 )
...
destroyLocals() does the same thing.
2025-11-22 16:41:00 +01:00
marius doerner
7198279707
[clang][bytecode] Implement case ranges ( #168418 )
...
Fixes #165969
Implement GNU case ranges for constexpr bytecode interpreter.
2025-11-20 04:50:32 +01:00
Timm Baeder
886d24d03a
[clang][bytecode] Fix fallthrough to switch labels ( #168484 )
...
We need to fallthrough here in case we're not jumping to the labels.
This is only needed in expression contexts.
2025-11-18 07:46:46 +01:00
Timm Baeder
746e5d0492
[clang][bytecode] Don't outright reject dynamic casts ( #167517 )
...
Just delegate to the subexpr instead for now.
2025-11-14 13:03:51 +01:00
Timm Baeder
70eb4b0a60
[clang][bytecode] Fix diagnosing subtration of zero-size pointers ( #167839 )
...
We need to get the element type size at bytecode generation time to
check. We also need to diagnose this in the LHS == RHS case.
2025-11-13 09:58:43 +01:00
Timm Baeder
8e3188a47f
[clang][bytecode] Mark CXXDefaultInitExprs in InitLink chain ( #166395 )
...
So we know before _what_ entry in the chain we need to look for the
InitList.
Fixes https://github.com/llvm/llvm-project/issues/166171
2025-11-11 10:36:00 +01:00
Timm Baeder
a8a0ffba73
[clang][bytecode] Check source pointer for bitcast validity ( #166907 )
...
Unfortunately this is more dynamic than anticipated.
Fixes https://github.com/llvm/llvm-project/issues/165006
2025-11-10 08:17:08 +01:00
Timm Baeder
6c12623d62
[clang][bytecode] Fix a std::optional<bool> mishap ( #167091 )
...
This is about the value saved in the std::optional, not about whether
the optional has a value at all.
2025-11-08 05:31:30 +00:00
Timm Baeder
6fac21e404
[clang][bytecode] Avoid copies with elidable CXXConstructExprs ( #166931 )
...
To fix the newly added cwg6.cpp.
2025-11-08 05:30:01 +01:00
KaiWeng
d9c7c76269
Revert "Ignore trailing NullStmts in StmtExprs for GCC compatibility." ( #166036 )
...
This reverts commit b1e511bf5a4c702ace445848b30070ac2e021241.
https://github.com/llvm/llvm-project/issues/160243
Reverting because the GCC C front end is incorrect.
---------
Co-authored-by: Jim Lin <jim@andestech.com>
2025-11-07 09:30:53 -05:00
Timm Baeder
e4467fbf30
[clang][ExprConst] Handle dependent switch case statements ( #166533 )
...
By rejecting them.
Fixes https://github.com/llvm/llvm-project/issues/165555
2025-11-06 12:52:11 +01:00
Timm Baeder
14c76437ee
[clang][bytecode] Check types when loading values ( #165385 )
...
We need to allow BitCasts between pointer types to different prim types,
but that means we need to catch the problem at a later stage, i.e. when
loading the values.
Fixes https://github.com/llvm/llvm-project/issues/158527
Fixes https://github.com/llvm/llvm-project/issues/163778
2025-11-05 16:02:19 +01:00
Timm Baeder
9af49ee474
[clang][bytecode] Handle discarded AddrLabelExprs properly ( #165000 )
...
emitDummyPtr() doesn't like to be called with DiscardResult set, so
check this first.
Fixes https://github.com/llvm/llvm-project/issues/164979
2025-10-27 10:28:09 +01:00
Timm Baeder
7c441b21b7
[clang][bytecode] Catch placement-new into invalid destination ( #164804 )
...
We failed to check for null and non-block pointers.
Fixes https://github.com/llvm/llvm-project/issues/152952
2025-10-24 08:08:18 +02:00
Timm Baeder
93bb5c699f
[clang][bytecode] Fix CXXConstructExpr for multidim arrays ( #164760 )
...
This is a thing apparently.
Fixes https://github.com/llvm/llvm-project/issues/153803
2025-10-24 06:36:05 +02:00
Timm Baeder
ece83ed7df
[clang][bytecode] Fix instance pointer in IndirectFieldDecl inits ( #164751 )
...
Points to the first chain link in this case.
2025-10-23 15:22:17 +02:00
Timm Baeder
0591297c8a
[clang][bytecode] Fix initializing primitive fields via initlist ( #164789 )
...
Fixes https://github.com/llvm/llvm-project/issues/152901
2025-10-23 14:19:13 +02:00
Timm Baeder
954a719056
[clang][bytecode] Fix unsigned wraparound behavior with bitfields ( #164445 )
...
and inc/dec operations. We need to truncate the new value to the
bitfield bitwidth.
2025-10-22 11:01:33 +02:00
Timm Baeder
9e7209c061
[clang][bytecode][NFC] Clean up variable creation ( #164415 )
2025-10-21 17:31:05 +02:00
Timm Baeder
7b91bb2046
[clang][bytecode] Fix redeclaring global externs without initializer ( #164409 )
...
Return the same value, whether we've already allocated the variable or
not.
2025-10-21 15:14:26 +02:00
Timm Baeder
c5f9a2a2b2
[clang][bytecode] Don't emit checkNull for function pointers ( #164376 )
...
Diagnose them later when we try to call the function pointer.
2025-10-21 14:49:03 +02:00
Matheus Izvekov
b516dcc998
[clang] NFC: rename TagType::getOriginalDecl back to getDecl ( #163271 )
...
This rename was made as part of
https://github.com/llvm/llvm-project/pull/147835 in order to ease
rebasing the PR, and give a nice window for other patches to get rebased
as well.
It has been a while already, so lets go ahead and rename it back.
2025-10-15 16:11:17 -03:00
Timm Baeder
93c830597c
[clang][bytecode] Fix integral cast edge case ( #161506 )
...
We were converting the `ASInt` to as sign-less `APInt` too early and
losing the sign information.
2025-10-01 13:56:38 +02:00
Timm Baeder
c750487292
[clang][bytecode] Diagnose volatile writes ( #160350 )
2025-09-28 07:21:40 +02:00