205 Commits

Author SHA1 Message Date
Timm Baeder
abc27039be
[clang][bytecode] Pass __builtin_memcpy size along (#118649)
To DoBitCastPtr, so we know how many bytes we want to read.
2024-12-05 06:55:18 +01:00
Timm Baeder
44be794658
[clang][bytecode] Not all null pointers are 0 (#118601)
Get the Value from the ASTContext instead.
2024-12-05 06:03:50 +01:00
Timm Baeder
7aec6dc477
[clang][bytecode] Initialize bases when bitcasting (#117179)
Base pointers do not get passed to the callback, so initialize them when iterating bases.
2024-12-04 16:49:03 +01:00
Timm Bäder
12ca72ba7f Reapply "[clang][bytecode] Handle bitcasts involving bitfields (#116843)"
This reverts commit 54db16221c92eb52efbea90ad5b5d2a1d00cda3e.

Check for existence of __SIZOEF_INT128__ so we don't run those
tests on targets that don't have int128.
2024-12-04 11:53:37 +01:00
Timm Bäder
54db16221c Revert "[clang][bytecode] Handle bitcasts involving bitfields (#116843)"
This reverts commit 4b5e7fa4de54e00df007ae5e2675393fd046aa59.

This breaks builders:
https://lab.llvm.org/buildbot/#/builders/154/builds/8464

I guess some more testing on 32 bit hosts is needed.
2024-12-04 11:43:43 +01:00
Timm Baeder
4b5e7fa4de
[clang][bytecode] Handle bitcasts involving bitfields (#116843)
Copy the data one bit at a time, leaving optimizations for future work.
Adds a BitcastBuffer that takes care of pushing the bits in the right
order.
2024-12-04 11:25:04 +01:00
Timm Baeder
7802fb5f51
[clang][bytecode] Fix __extension__ handling for vector operators (#118482)
Don't reject them, but delegate to the subexpression.
2024-12-03 14:48:55 +01:00
Timm Baeder
ff0babc917
[clang][bytecode] Fix discarded pointer subtractions (#118477)
We need to pop the value.
2024-12-03 14:34:32 +01:00
Timm Bäder
61c2ac03d8 Revert "[clang][bytecode] Handle __builtin_wcslen (#118446)"
This reverts commit 89a0ee89973c3d213c4bc11c26b41eab67e06da0.

This breaks builders:
https://lab.llvm.org/buildbot/#/builders/13/builds/3885
2024-12-03 13:35:57 +01:00
Timm Baeder
3f39c5df08
[clang][bytecode] Reject memcpy dummy pointers after null check (#118460)
To match the diagnostic output of the current interpreter.
2024-12-03 11:51:49 +01:00
Timm Baeder
0f4dc4276f
[clang][bytecode] Initialize elements in __builtin_elementwise_popcount (#118457) 2024-12-03 11:14:06 +01:00
Timm Baeder
89a0ee8997
[clang][bytecode] Handle __builtin_wcslen (#118446)
... just like strlen.
2024-12-03 10:20:30 +01:00
Timm Baeder
46446bb2d3
[clang][bytecode][NFC] Diagnose non-constexpr builtin strcmp calls (#118442) 2024-12-03 09:49:26 +01:00
Timm Baeder
789551362e
[clang][bytecode] Handle memmove like memcpy (#118431)
This is the same thing for us, except for diagnostic differences.
2024-12-03 07:56:06 +01:00
Timm Baeder
dac9736d05
[clang][bytecode][NFC] Diagnose no-constexpr memcpy/strlen versions (#118429) 2024-12-03 06:59:56 +01:00
Timm Baeder
fc9052ee25
[clang][bytecode] Check __builtin_memcpy for null pointers (#118313) 2024-12-03 03:36:57 +01:00
Timm Baeder
637a1ae855
[clang][bytecode] Implement __builtin_elementwise_popcount (#118307) 2024-12-02 16:48:22 +01:00
Timm Baeder
b587b910d5
[clang][bytecode] Implement __builtin_reduce_xor (#118299) 2024-12-02 16:04:49 +01:00
Timm Baeder
1288f6d405
[clang][bytecode] Implement __builtin_reduce_or (#118292) 2024-12-02 15:28:26 +01:00
Timm Baeder
ccc471fe3e
[clang][bytecode] Implement __builtin_reduce_and (#118289) 2024-12-02 14:29:38 +01:00
Timm Baeder
c1dcf75a7c
[clang][bytecode] Implement __builtin_reduce_mul (#118287) 2024-12-02 14:03:53 +01:00
Timm Baeder
0611fdd320
[clang][bytecode] Add simple __builtin_memcpy implementation (#118278)
Not handling all the special- and error cases yet. Just making sure the
bitcast code can be used for this as well.
2024-12-02 13:11:22 +01:00
Timm Baeder
541d5d9111
[clang][bytecode][NFC] Reject invalid FromTypes in emitBuiltinBitcast (#118274)
instead of silently accepting them and failing later.
2024-12-02 11:12:20 +01:00
Timm Baeder
dd0d9561b8
[clang][bytecode] Support vector-to-vector bitcasts (#118230) 2024-12-02 08:20:41 +01:00
Timm Baeder
31bde711c4
[clang][bytecode] Support __builtin_reduce_add (#117672) 2024-12-01 17:39:11 +01:00
Timm Baeder
82ed9c0319
[clang][bytecode][NFC] Remove APValue Result argument where unnecessary (#118199)
This is unneeded in almost all circumstances. We only return an APValue
back to clang when the evaluation is finished, and that is always done
by an EvalEmitter - which has its own implementation of the Ret
instructions.
2024-12-01 17:36:19 +01:00
Timm Baeder
6f16a8bf17
[clang][bytecode] Use bitcasts to cast from integer to vector (#117547)
In C, a cast from an integer to a vector is a CK_BitCast. Implement this
using the same code we use for __builtin_bit_cast.
2024-11-25 14:51:26 +01:00
Timm Baeder
ceaf6e912a
[clang][bytecode] Support ImplicitValueInitExpr for multi-dim arrays (#117312)
The attached test case from
https://github.com/llvm/llvm-project/issues/117294 used to cause an
assertion because we called classifPrim() on an array type.

The new result doesn't crash but isn't exactly perfect either. Since the
problem arises when evaluating an ImplicitValueInitExpr, we have no
proper source location to point to. Point to the caller instead.
2024-11-25 12:15:31 +01:00
Congcong Cai
cbdd14ee9d
[clang][NFC]add static for internal linkage function (#117482)
Detected by misc-use-internal-linkage
2024-11-25 06:48:33 +08:00
Kazu Hirata
63d9ef5e37
[AST] Migrate away from PointerUnion::{is,get} (NFC) (#117469)
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
2024-11-24 07:28:20 -08:00
Timm Baeder
a9731dff0a
[clang][bytecode][NFC] Avoid a getSource() call (#117311)
This is only needed when we actually emit a diagnostic, so move the
getSource() after the early return.
2024-11-22 14:00:10 +01:00
smanna12
95f4aa44ae
[clang][bytecode] Add assert to ensure correct state restoration in CallBI function (#115496)
This commit adds an assert statement to the CallBI function to ensure
that the interpreter state (S.Current) is correctly reset to the
previous frame (FrameBefore) after InterpretBuiltin returns true. This
helps catch any potential issues during development and debugging.
2024-11-21 08:45:34 -06:00
Simon Pilgrim
d800ea7cb1
Adjust MSVC disabled optimization pragmas to be _MSC_VER only (#116704)
Alter the #ifdef values from #110986 and #115292 to use _MSC_VER instead of _WIN32 to stop the pragmas being used on gcc/mingw builds

Noticed by @mstorsjo
2024-11-21 13:33:13 +00:00
Timm Baeder
1425fa915d
[clang][bytecode] Check FromPtr in BitCastPtr (#117142) 2024-11-21 13:21:00 +01:00
Timm Baeder
476b208e01
[clang][bytecode] Fix ToType/FromType diagnostic ordering (#116988)
We need to check the ToType first, then the FromType. Additionally,
remove qualifiers from the parent type of the field we're emitting a
note for.
2024-11-21 07:54:38 +01:00
Kazu Hirata
dec6324cb0
[AST] Remove unused includes (NFC) (#116549)
Identified with misc-include-cleaner.
2024-11-17 09:36:48 -08:00
Timm Baeder
202ad47fe1
[clang][bytecode] SourceInfo::Source might be null (#115905)
This broke in 23fbaff9a3fd2b26418e0c2f10b701049399251f, but the old
.dyn_cast<> handled null.
2024-11-13 08:35:50 +01:00
Kazu Hirata
23fbaff9a3
[ByteCode] Migrate away from PointerUnion::{is,get,dyn_cast} (NFC) (#115809)
Note that PointerUnion::{is,get,dyn_cast} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>
2024-11-11 22:49:58 -08:00
Richard Smith
de18fa1ace
Don't redundantly specify the default template argument to BumpPtrAllocatorImpl (#114857) 2024-11-06 18:45:27 -08:00
Timm Baeder
1b3da362c5
[clang][bytecode] Fix bitcasting packed bool vectors (#114937)
This is a special case we need to handle. We don't do bitcasting _into_
such vectors yet though.
2024-11-05 11:43:09 +01:00
Timm Baeder
5f84b332ec
[clang][bytecode] Fix discarding __builtin_bit_cast calls (#114926)
Optionally prepare storage for the result and do the bitcast anyway, to
get the right diagnostic output.
2024-11-05 11:05:23 +01:00
Timm Baeder
2f13fbfcd1
[clang][bytecode] Support bitcasting into float fields (#114825) 2024-11-05 05:52:03 +01:00
Timm Baeder
1f55d77189
[clang][bytecode][NFC] Remove unused parameter from pushData() (#114801) 2024-11-04 17:14:05 +01:00
Timm Baeder
3268d51a5c
[clang][bytecode][NFC] Fix a possible build warning (#114800)
InterpBuiltinBitCast.cpp:95:3: warning: non-void function does not
return a value in all control paths [-Wreturn-type]
   95 |   }
      |   ^
1 warning generated.
2024-11-04 16:58:44 +01:00
Timm Baeder
2588b8be56
[clang][bytecode] Implement bitcasts to composite types (#114776)
Only fixed-size, non-bitfield integral fields for now.
2024-11-04 15:10:10 +01:00
Timm Baeder
fb30208d1e
[clang][bytecode][NFC] Make Floating::bitcastToMemory const (#114777)
The other functions like this are also const.
2024-11-04 14:00:24 +01:00
Timm Baeder
5b32c5954b
[clang][bytecode] Implement bitcasts to floating-point values (#114485) (#114712)
This time I tested on big-endian hosts.
2024-11-03 19:42:26 +01:00
Timm Baeder
88823d08ab
[clang][bytecode][NFC] Switch BitcastBuffer to SmallVector (#114677)
This is a little easier to work with since we are guaranteed that the
item type of the vector is byte sized and not something else.
2024-11-03 11:16:59 +01:00
Timm Bäder
c2a892f49a Revert "[clang][bytecode] Implement bitcasts to floating-point values (#114485)"
This reverts commit c752efbdcc1ebd81f879633d6b798248064e2ae2.

This broke bots:
 - https://lab.llvm.org/buildbot/#/builders/13/builds/3268
 - https://lab.llvm.org/buildbot/#/builders/42/builds/1718
2024-11-02 01:54:38 +01:00
Timm Baeder
c752efbdcc
[clang][bytecode] Implement bitcasts to floating-point values (#114485) 2024-11-01 14:58:19 +01:00