Commit Graph
70 Commits
Author SHA1 Message Date
Timm Baeder a8977005b6 [clang][Interp] Don't diagnose undefined functions when checking... (#75051)
... for a potential constant expression. They are not defined now, but
might be defined later when the function is actually called.
2023-12-13 12:14:53 +01:00
Timm Baeder 965d301dff [clang][Interp] Implement __builtin_classify_type (#71972)
This adds some infrastructure for unevaluated builtin calls, and uses the implementation from ExprConstant.cpp
2023-11-17 16:13:23 +01:00
Timm Bäder 8ff81deeaa [clang][Interp][NFC] Remove some redundant code
The needsRuntimeArgPop() stuff is now handled by the
cleanupAfterFunctionCall() function.
2023-11-12 06:37:51 +01:00
Takuya Shimizu b88a9f9670 [clang][ExprConst] Fix crash on uninitialized array subobject (#67817)
https://reviews.llvm.org/D146358 was assuming that all subobjects have
their own name (`SubobjectDecl`), but it was not true for array
elements.

Fixes https://github.com/llvm/llvm-project/issues/67317
2023-10-27 14:11:27 +09:00
Timm Baeder ba11d314a6 [clang][Interp] Only diagnose null field access in constant contexts (#69223)
Looks like this should work as long as we don't dereference the value.
2023-10-26 16:15:29 +02:00
Timm Baeder 7f677fe310 [clang][Interp] Add explicit dummy descriptors (#68888)
Instead of (ab)using incomplete array types for this, add a 'Dummy' bit
to Descriptor. We need to be able to differentiate between the two when
adding an offset.
2023-10-26 15:15:25 +02:00
Timm Baeder 658874e084 [clang][Interp] Handle unknown-size arrays better (#68868)
We unfortunately actually need to do some checks for array-to-pointer
decays it seems.
2023-10-26 13:53:54 +02:00
Timm Baeder c8b267e98f [clang][Interp] Handle variadic functions (#67814)
Similarly to the code we already had for builtin functions, we need to
check the call expression for the arguments passed.
2023-10-24 12:33:29 +02:00
Timm Baeder c45466cd9a [clang][Interp] Only emit function_param_value_unknown in C++11 (#67990)
This is also what the current interpreter does.
2023-10-24 09:28:30 +02:00
Timm Baeder 2bed2a7a5c [clang][Interp] Emit dummy values for unknown C variables (#66749)
We can't load anything from them, but we can still take their address or
return them as lvalues.
2023-10-07 16:00:19 +02:00
Timm Baeder f58d54ab96 [clang][Interp] Diagnose uninitialized bases (#67131) 2023-10-03 06:46:31 +02:00
Timm Bäder 23c39f9a9e [clang][Interp] Diagnose unknown parameter values
Differential Revision: https://reviews.llvm.org/D156509
2023-09-15 13:10:19 +02:00
Timm Bäder 4b5fe9c42d [clang][Interp] Check floating results for NaNs
Differential Revision: https://reviews.llvm.org/D156506
2023-09-11 12:21:36 +02:00
Timm Baeder fedc982731 [clang][Diagnostics] Add source range to uninitialized diagnostics (#65896)
Before:

```
array.cpp:319:10: note: read of uninitialized object is not allowed in a constant expression
  319 |    return aaa;
      |           ^
```

After:

```
array.cpp:319:10: note: read of uninitialized object is not allowed in a constant expression
  319 |    return aaa;
      |           ^~~
```
2023-09-11 07:03:18 +02:00
Timm Bäder a13f036949 [clang][Interp] Check one-past-the-end pointers in GetPtrField
Rename CheckBaseDerived to something more general and call it in
GetPtrField() as well, so we don't crash later in Pointer::toAPValue().

Differential Revision: https://reviews.llvm.org/D149149
2023-09-05 11:00:40 +02:00
Timm Bäder 12a789710e [clang][Interp] BaseToDerived casts
We can implement these similarly to DerivedToBase casts. We just have to
walk the class hierarchy, sum the base offsets and subtract it from the
current base offset of the pointer.

Differential Revision: https://reviews.llvm.org/D149133
2023-09-05 10:53:54 +02:00
Timm Bäder ff80fc0ea2 [clang][Interp] Implement __builtin_isnan()
The previous version was using llvm::reverse(CallExpr::arguments()),
which causes problems when clang is compiled with GCC.

Differential Revision: https://reviews.llvm.org/D155369
2023-07-29 10:48:10 +02:00
Timm Bäder 9016514c6b Revert "[clang][Interp] Implement __builtin_isnan()"
This reverts commit 8ad9dcb386.

This breaks builders:
https://lab.llvm.org/buildbot/#/builders/139/builds/46363/steps/6/logs/FAIL__Clang__constant-builtins-fmin_cpp

Revert while I figure out what's going wrong.
2023-07-28 20:59:38 +02:00
Timm Bäder 8ad9dcb386 [clang][Interp] Implement __builtin_isnan()
Differential Revision: https://reviews.llvm.org/D155369
2023-07-28 20:49:45 +02:00
Timm Bäder 81fb216245 [clang][Diagnostics] Provide source range to invalid casts in const expr
Differential Revision: https://reviews.llvm.org/D153241
2023-07-28 12:28:45 +02:00
Timm Bäder ae4849f967 [clang][Interp] PointerToIntegral casts
Differential Revision: https://reviews.llvm.org/D150946
2023-07-26 13:39:37 +02:00
Timm Bäder c54ff51be9 [clang][Interp] Emit correct diagnostic for uninitialized reads
Differential Revision: https://reviews.llvm.org/D154758
2023-07-09 16:27:49 +02:00
Timm Bäder 0d40973644 [clang][Interp][NFC] Move CastFP to Interp.h
It's not a Check* function, so try to stay consistent and move this to
the header.
2023-07-04 17:35:28 +02:00
Timm Bäder df5213c442 [clang][Interp][NFC] Return a const pointer from Pointer::getRecord() 2023-07-04 17:21:51 +02:00
Timm Bäder 044be8f5d1 [clang][Interp][NFC] Add some missing const qualifiers 2023-07-04 16:16:17 +02:00
Timm Bäder 1c8c5a89c5 [clang][Interp][NFC] Merge two if statements 2023-07-04 16:16:17 +02:00
Takuya Shimizu dfb85c3ce0 [Clang][Interp] Diagnose uninitialized ctor of global record arrays
This patch adds a check for uninitialized subobjects of global variables that are record arrays.
e.g. `constexpr Foo f[2];`

Reviewed By: tbaeder

Differential Revision: https://reviews.llvm.org/D152548
2023-06-21 19:03:01 +09:00
Timm Bäder 459f495f49 [clang][Interp] Check inc/dec family of ops for initialization
Differential Revision: https://reviews.llvm.org/D149846
2023-06-16 15:19:23 +02:00
Timm Bäder da836b36bc [clang][Interp] Track frame depth
Save the depth of each InterpFrame and bail out if we're too deep.

Differential Revision: https://reviews.llvm.org/D148614
2023-05-31 12:08:03 +02:00
Timm Bäder 40c26ec48c [clang][Interp] Fix diagnosing uninitialized ctor record arrays
Differential Revision: https://reviews.llvm.org/D143334
2023-05-31 11:39:40 +02:00
Takuya Shimizu 456d072405 Reland: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables
This patch improves the diagnostic on uninitialized subobjects in constexpr variables by modifying the diagnostic message to display the subobject's name instead of its type.

Fixes https://github.com/llvm/llvm-project/issues/58601
Differential Revision: https://reviews.llvm.org/D146358
2023-05-24 21:31:25 +09:00
Erich Keane 34e49d3e85 Revert "[clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables"
This reverts commit 0e167fc0a2.

This patch causes its assertion to fire when doing AST-dump, so
reverting so that the author has time to fix this.
2023-05-18 06:44:39 -07:00
Takuya Shimizu 0e167fc0a2 [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables
This patch improves the diagnostic on uninitialized subobjects in constexpr variables by modifying the diagnostic message to display the subobject's name instead of its type.

Fixes https://github.com/llvm/llvm-project/issues/58601
Differential Revision: https://reviews.llvm.org/D146358
2023-05-16 21:49:57 +09:00
Timm Bäder db3dcdc08c [clang][Interp] Fix initializing base class members
For the given test case, we were trying to initialize a member of C,
which doesn't have any. Get the proper base pointer instead and
initialize the members there.

Differential Revision: https://reviews.llvm.org/D143466
2023-04-03 13:51:04 +02:00
Timm Bäder 569222e172 [clang][Interp] Only check constructors for global variables
Local variables may be partially initialized.

Differential Revision: https://reviews.llvm.org/D140723
2023-03-02 09:13:47 +01:00
Timm Bäder 8d09bd616b [clang][Interp] This pointers are writable in de-/constructors
This is possible in C++20, so we need to check this when doing stores.

Differential Revision: https://reviews.llvm.org/D136751
2023-03-01 15:41:10 +01:00
Timm Bäder 760136ff13 [clang][Interp] Implement __builtin_assume
Just ignore it.

As part of this, move the Ret and RetVoid implementation to Interp.h, so
they can be shared with InterpBuiltin.cpp.

Differential Revision: https://reviews.llvm.org/D141193
2023-01-27 07:54:37 +01:00
Timm Bäder cb703434cb [clang][Interp] Add back Run() call
We need to run the functions we compiled immediately after to check if
they can ever be a constant expression.

Differential Revision: https://reviews.llvm.org/D140724
2023-01-25 17:01:55 +01:00
Timm Bäder 5de6b94f85 [clang][Interp][NFC] Replace remaining dyn_cast_or_null uses 2023-01-25 16:39:26 +01:00
Timm Bäder cb7f582211 Re-apply "[clang][Interp] Support floating-point values"
Don't move the Repr struct into Integral this time.

Differential Revision: https://reviews.llvm.org/D134859
2023-01-25 15:13:09 +01:00
Timm Bäder b3b1d86137 Revert "[clang][Interp] Support floating-point values"
This reverts commit 62f43c3eae.

This breaks a couple of builders, e.g.

https://lab.llvm.org/buildbot/#/builders/139/builds/34925
2023-01-25 14:48:39 +01:00
Timm Bäder 62f43c3eae [clang][Interp] Support floating-point values
Add a new Floating type and a few new opcodes to support floating point
values.

Differential Revision: https://reviews.llvm.org/D134859
2023-01-25 14:41:26 +01:00
Timm Bäder 85acfc6425 Revert "[clang][Interp][NFC] Remove shift error checking code duplication"
This reverts commit fddf6418e8.

Apparently this also breaks some builders:

/usr/bin/ld: EvalEmitter.cpp:(.text._ZN5clang6interp11EvalEmitter7emitShlENS0_8PrimTypeES2_RKNS0_10SourceInfoE+0x1f54): undefined reference to `bool clang::interp::CheckShift<clang::interp::Integral<16u, true> >(clang::interp::InterpState&, clang::interp::CodePtr, clang::interp::Integral<16u, true> const&, unsigned int)'
/usr/bin/ld: EvalEmitter.cpp:(.text._ZN5clang6interp11EvalEmitter7emitShlENS0_8PrimTypeES2_RKNS0_10SourceInfoE+0x1fd4): undefined reference to `bool clang::interp::CheckShift<clang::interp::Integral<32u, true> >(clang::interp::InterpState&, clang::interp::CodePtr, clang::interp::Integral<32u, true> const&, unsigned int)'
/usr/bin/ld: EvalEmitter.cpp:(.text._ZN5clang6interp11EvalEmitter7emitShlENS0_8PrimTypeES2_RKNS0_10SourceInfoE+0x2058): undefined reference to `bool clang::interp::CheckShift<clang::interp::Integral<32u, true> >(clang::interp::InterpState&, clang::interp::CodePtr, clang::interp::Integral<32u, true> const&, unsigned int)'

(etc)
2023-01-19 13:03:20 +01:00
Timm Bäder 2dbcfd298f Revert "[clang][Interp][NFC] Move CheckDivRem() implementation into Interp.cpp"
This reverts commit 9ee0d7494e.
2023-01-19 12:37:20 +01:00
Timm Bäder 9ee0d7494e [clang][Interp][NFC] Move CheckDivRem() implementation into Interp.cpp
Just like we do with all the other Check* functions.
2023-01-19 12:18:34 +01:00
Timm Bäder fddf6418e8 [clang][Interp][NFC] Remove shift error checking code duplication 2023-01-19 12:18:26 +01:00
Timm Bäder 9308014195 [clang][Interp] Diagnose uninitialized array record fields
Just like we do for record members, diagnose uninitialized array record
fields.

Differential Revision: https://reviews.llvm.org/D136828
2023-01-19 11:07:51 +01:00
Timm Bäder 6b0cd497b0 [clang][Interp] Check Field initialization after constructor call
Differential Revision: https://reviews.llvm.org/D136694
2023-01-19 09:42:22 +01:00
Timm Bäder 48655f72f9 [clang][Interp][NFC] Fix typo in comment 2022-12-28 12:08:29 +01:00
Timm Bäder c3380c32f8 [clang][Interp] Handle undefined functions better
Differential Revision: https://reviews.llvm.org/D136936
2022-11-30 10:09:52 +01:00