[all-commits] [llvm/llvm-project] 311f72: [clang][Interp] Create only globals when initializ...

Timm Baeder via All-commits all-commits at lists.llvm.org
Thu Oct 19 05:52:45 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 311f725d9a6fa29b5672a2dd26a078c6c6dcd01a
      https://github.com/llvm/llvm-project/commit/311f725d9a6fa29b5672a2dd26a078c6c6dcd01a
  Author: Timm Bäder <tbaeder at redhat.com>
  Date:   2023-10-19 (Thu, 19 Oct 2023)

  Changed paths:
    M clang/lib/AST/Interp/ByteCodeExprGen.cpp
    M clang/lib/AST/Interp/ByteCodeExprGen.h
    M clang/test/AST/Interp/records.cpp
    M clang/test/SemaCXX/paren-list-agg-init.cpp

  Log Message:
  -----------
  [clang][Interp] Create only globals when initializing a global variable

For this code:

struct O {
  int &&j;
};

O o1(0);

The generated AST for the initializer of o1 is:

VarDecl 0x62100006ab08 <array.cpp:119:3, col:9> col:5 o1 'O':'O' parenlistinit
`-ExprWithCleanups 0x62100006b250 <col:7, col:9> 'O':'O'
  `-CXXParenListInitExpr 0x62100006b210 <col:7, col:9> 'O':'O'
    `-MaterializeTemporaryExpr 0x62100006b1f0 <col:8> 'int' xvalue
      `-IntegerLiteral 0x62100006abd0 <col:8> 'int' 0

Before this patch, we create a local temporary variable for the
MaterializeTemporaryExpr and destroy it again when destroying the
EvalEmitter we create to interpret the initializer. However, since
O::j is a reference, this reference now points to a local variable
that doesn't exist anymore.

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




More information about the All-commits mailing list