[all-commits] [llvm/llvm-project] d08cf7: [clang][bytecode] Implement __builtin_constant_p (...

Timm Baeder via All-commits all-commits at lists.llvm.org
Fri Mar 7 21:06:35 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d08cf7900d2aaff9e7483ea74a58871edbdc45f2
      https://github.com/llvm/llvm-project/commit/d08cf7900d2aaff9e7483ea74a58871edbdc45f2
  Author: Timm Baeder <tbaeder at redhat.com>
  Date:   2025-03-08 (Sat, 08 Mar 2025)

  Changed paths:
    M clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
    M clang/lib/AST/ByteCode/ByteCodeEmitter.h
    M clang/lib/AST/ByteCode/Compiler.cpp
    M clang/lib/AST/ByteCode/Compiler.h
    M clang/lib/AST/ByteCode/EvalEmitter.cpp
    M clang/lib/AST/ByteCode/EvalEmitter.h
    M clang/lib/AST/ByteCode/Interp.cpp
    M clang/lib/AST/ByteCode/Interp.h
    M clang/lib/AST/ByteCode/InterpBuiltin.cpp
    M clang/lib/AST/ByteCode/InterpState.h
    M clang/lib/AST/ByteCode/Opcodes.td
    M clang/test/AST/ByteCode/builtin-constant-p.cpp
    M clang/test/CodeGen/builtin-constant-p.c
    M clang/test/CodeGenCXX/builtin-constant-p.cpp

  Log Message:
  -----------
  [clang][bytecode] Implement __builtin_constant_p (#130143)

Use the regular code paths for interpreting.

Add new instructions: `StartSpeculation` will reset the diagnostics
pointers to `nullptr`, which will keep us from reporting any diagnostics
during speculation. `EndSpeculation` will undo this.

The rest depends on what `Emitter` we use.

For `EvalEmitter`, we have no bytecode, so we implement `speculate()` by
simply visiting the first argument of `__builtin_constant_p`. If the
evaluation fails, we push a `0` on the stack, otherwise a `1`.

For `ByteCodeEmitter`, add another instrucion called `BCP`, that
interprets all the instructions following it until the next
`EndSpeculation` instruction. If any of those instructions fails, we
jump to the `EndLabel`, which brings us right before the
`EndSpeculation`. We then push the result on the stack.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list