[all-commits] [llvm/llvm-project] 6dfe55: [clang][Interp] Rework initializers

Timm Baeder via All-commits all-commits at lists.llvm.org
Sun Aug 20 04:33:36 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6dfe55569d88ff654d13e6c09267eff0cd9c9f0d
      https://github.com/llvm/llvm-project/commit/6dfe55569d88ff654d13e6c09267eff0cd9c9f0d
  Author: Timm B├Ąder <tbaeder at redhat.com>
  Date:   2023-08-20 (Sun, 20 Aug 2023)

  Changed paths:
    M clang/lib/AST/Interp/ByteCodeExprGen.cpp
    M clang/lib/AST/Interp/ByteCodeExprGen.h
    M clang/lib/AST/Interp/Context.cpp
    M clang/test/AST/Interp/lambda.cpp
    M clang/test/AST/Interp/records.cpp

  Log Message:
  -----------
  [clang][Interp] Rework initializers

Before this patch, we had visitRecordInitializer() and
visitArrayInitializer(), which were different from the regular visit()
in that they expected a pointer on the top of the stack, which they
initialized. For example, visitArrayInitializer handled InitListExprs by
looping over the members and initializing the elements of that pointer.

However, this had a few corner cases and problems. For example, in
visitLambdaExpr() (a lambda is always of record type), it was not clear
whether we should always create a new local variable to save the lambda
to, or not. This is why https://reviews.llvm.org/D153616 changed
things around.

This patch changes the visiting functions to:

 - visit(): Always leaves a new value on the stack. If the expression
   can be mapped to a primitive type, it's just visited and the value is
   put on the stack. If it's of composite type, this function will
   create a local variable for the expression value and call
   visitInitializer(). The pointer to the local variable will stay on
   the stack.

 - visitInitializer(): Visits the given expression, assuming there is a
   pointer on top of the stack that will be initialized by it.

 - discard(): Visit the expression for side-effects, but don't leave a
   value on the stack.

It also adds an additional Initializing flag to differentiate between the initializing and non-initializing case.

Differential Revision: https://reviews.llvm.org/D156027




More information about the All-commits mailing list