[PATCH] D134523: [clang][Interp] Fix copy constructors with record array members

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 27 00:43:11 PDT 2022


tbaeder added inline comments.


================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:332
+  // ArrayIndex might not be set if a ArrayInitIndexExpr is being evaluated
+  // stand-alone, e.g. via EvaluateAsInt().
+  if (!ArrayIndex)
----------------
erichkeane wrote:
> For my edification: what reproducer causes us to do this?
The copy constructor in the test added in this patch:
```
constexpr FourBoolPairs LT2 = LT;
```

The backtrace is:

```
#0  0x00007fffca0a2c4c in __pthread_kill_implementation () from /lib64/libc.so.6
#1  0x00007fffca0529c6 in raise () from /lib64/libc.so.6
#2  0x00007fffca03c7f4 in abort () from /lib64/libc.so.6
#3  0x00007fffca03c71b in __assert_fail_base.cold () from /lib64/libc.so.6
#4  0x00007fffca04b576 in __assert_fail () from /lib64/libc.so.6
#5  0x00007fffeab8823e in clang::interp::ByteCodeExprGen<clang::interp::EvalEmitter>::VisitArrayInitIndexExpr (this=0x7ffffffd9580, E=0x621000093ab0)
    at /home/tbaeder/code/llvm-project/clang/lib/AST/Interp/ByteCodeExprGen.cpp:335
#6  0x00007fffeab806aa in clang::StmtVisitorBase<llvm::make_const_ptr, clang::interp::ByteCodeExprGen<clang::interp::EvalEmitter>, bool>::Visit (this=0x7ffffffd9580, S=0x621000093ab0)
    at tools/clang/include/clang/AST/StmtNodes.inc:741
#7  0x00007fffeab83b0f in clang::interp::ByteCodeExprGen<clang::interp::EvalEmitter>::visit (
    this=0x7ffffffd9580, E=0x621000093ab0)
    at /home/tbaeder/code/llvm-project/clang/lib/AST/Interp/ByteCodeExprGen.cpp:352
#8  0x00007fffeab884a7 in clang::interp::ByteCodeExprGen<clang::interp::EvalEmitter>::visitExpr (
    this=0x7ffffffd9580, Exp=0x621000093ab0)
    at /home/tbaeder/code/llvm-project/clang/lib/AST/Interp/ByteCodeExprGen.cpp:845
#9  0x00007fffeabcdef4 in clang::interp::EvalEmitter::interpretExpr (this=0x7ffffffd9580,
    E=0x621000093ab0) at /home/tbaeder/code/llvm-project/clang/lib/AST/Interp/EvalEmitter.cpp:30
#10 0x00007fffeaba93a4 in clang::interp::Context::evaluateAsRValue (this=0x606000010340, Parent=...,
    E=0x621000093ab0, Result=...) at /home/tbaeder/code/llvm-project/clang/lib/AST/Interp/Context.cpp:61
#11 0x00007fffea8e1ae7 in EvaluateAsRValue (Info=..., E=0x621000093ab0, Result=...)
    at /home/tbaeder/code/llvm-project/clang/lib/AST/ExprConstant.cpp:14949
#12 0x00007fffea8d69c5 in EvaluateAsRValue (E=0x621000093ab0, Result=..., Ctx=..., Info=...)
    at /home/tbaeder/code/llvm-project/clang/lib/AST/ExprConstant.cpp:15012
#13 0x00007fffea8d7490 in EvaluateAsInt (E=0x621000093ab0, ExprResult=..., Ctx=...,
    AllowSideEffects=clang::Expr::SE_AllowSideEffects, Info=...)
    at /home/tbaeder/code/llvm-project/clang/lib/AST/ExprConstant.cpp:15023
#14 0x00007fffea8d7290 in clang::Expr::EvaluateAsInt (this=0x621000093ab0, Result=..., Ctx=...,
    AllowSideEffects=clang::Expr::SE_AllowSideEffects, InConstantContext=false)
    at /home/tbaeder/code/llvm-project/clang/lib/AST/ExprConstant.cpp:15079
#15 0x00007fffec9e1d8c in clang::Sema::CheckArrayAccess (this=0x628000000100, BaseExpr=0x621000093a90,
    IndexExpr=0x621000093ab0, ASE=0x621000093b50, AllowOnePastEnd=false, IndexNegated=false)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:16002
#16 0x00007fffec9d9926 in clang::Sema::CheckArrayAccess (this=0x628000000100, expr=0x621000093b50)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:16177
#17 0x00007fffed8293df in clang::Sema::GatherArgumentsForCall (this=0x628000000100, CallLoc=...,
    FDecl=0x6210000900e8, Proto=0x621000090c20, FirstParam=0, Args=..., AllArgs=...,
    CallType=clang::Sema::VariadicDoesNotApply, AllowExplicit=true, IsListInitialization=false)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaExpr.cpp:6193
#18 0x00007fffed3f48aa in clang::Sema::CompleteConstructorCall (this=0x628000000100,
    Constructor=0x6210000900e8, DeclInitType=..., ArgsPtr=..., Loc=..., ConvertedArgs=..., AllowExplicit=true,
    IsListInitialization=false) at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:15715
#19 0x00007fffee39ca73 in PerformConstructorInitialization (S=..., Entity=..., Kind=..., Args=...,
    Step=..., ConstructorInitRequiresZeroInit=@0x7ffffffdd5b0: false, IsListInitialization=false,
    IsStdInitListInitialization=false, LBraceLoc=..., RBraceLoc=...)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaInit.cpp:6591

#20 0x00007fffee3841bf in clang::InitializationSequence::Perform (this=0x7ffffffe1390, S=...,
--Type <RET> for more, q to quit, c to continue without paging--
    Entity=..., Kind=..., Args=..., ResultType=0x0)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaInit.cpp:8635
#21 0x00007fffed4423e5 in BuildImplicitMemberInitializer (SemaRef=..., Constructor=0x6210000904c8,
    ImplicitInitKind=IIK_Copy, Field=0x62100006c340, Indirect=0x0, CXXMemberInit=@0x7ffffffe5ac0: 0x0)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:4854
#22 0x00007fffed36f025 in CollectFieldInitializer (SemaRef=..., Info=..., Field=0x62100006c340,
    Indirect=0x0) at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:5107
#23 0x00007fffed36af43 in clang::Sema::SetCtorInitializers (this=0x628000000100,
    Constructor=0x6210000904c8, AnyErrors=false, Initializers=...)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:5273
#24 0x00007fffed3ec223 in clang::Sema::DefineImplicitCopyConstructor (this=0x628000000100,
    CurrentLocation=..., CopyConstructor=0x6210000904c8)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:15182
#25 0x00007fffedcdef61 in clang::Sema::MarkFunctionReferenced(clang::SourceLocation, clang::FunctionDecl*, bool)::$_13::operator()() const (this=0x7ffffffe7b20)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaExpr.cpp:18040
#26 0x00007fffedcde8d5 in llvm::function_ref<void ()>::callback_fn<clang::Sema::MarkFunctionReferenced(clang::SourceLocation, clang::FunctionDecl*, bool)::$_13>(long) (callable=140737488255776)
    at /home/tbaeder/code/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45
#27 0x00007fffe90d6438 in llvm::function_ref<void ()>::operator()() const (this=0x7ffffffe7700)
    at /home/tbaeder/code/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68
#28 0x00007fffec4842b2 in clang::runWithSufficientStackSpace(llvm::function_ref<void ()>, llvm::function_ref<void ()>) (Diag=..., Fn=...) at /home/tbaeder/code/llvm-project/clang/include/clang/Basic/Stack.h:46
#29 0x00007fffec45425a in clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (this=0x628000000100, Loc=..., Fn=...)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/Sema.cpp:503
#30 0x00007fffed8d9289 in clang::Sema::MarkFunctionReferenced (this=0x628000000100, Loc=...,
    Func=0x6210000904c8, MightBeOdrUse=true)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaExpr.cpp:18029
#31 0x00007fffed3f15ec in clang::Sema::BuildCXXConstructExpr (this=0x628000000100, ConstructLoc=...,
    DeclInitType=..., Constructor=0x6210000904c8, Elidable=false, ExprArgs=...,
    HadMultipleCandidates=true, IsListInitialization=false, IsStdInitListInitialization=false,
    RequiresZeroInit=false, ConstructKind=0, ParenRange=...)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:15550
#32 0x00007fffed3f0f70 in clang::Sema::BuildCXXConstructExpr (this=0x628000000100, ConstructLoc=...,
    DeclInitType=..., FoundDecl=0x6210000904c8, Constructor=0x6210000904c8, Elidable=false,
    ExprArgs=..., HadMultipleCandidates=true, IsListInitialization=false,
    IsStdInitListInitialization=false, RequiresZeroInit=false, ConstructKind=0, ParenRange=...)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:15527
#33 0x00007fffed3f0343 in clang::Sema::BuildCXXConstructExpr (this=0x628000000100, ConstructLoc=...,
    DeclInitType=..., FoundDecl=0x6210000904c8, Constructor=0x6210000904c8, ExprArgs=...,
    HadMultipleCandidates=true, IsListInitialization=false, IsStdInitListInitialization=false,
    RequiresZeroInit=false, ConstructKind=0, ParenRange=...)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:15501
#34 0x00007fffee39e2a5 in PerformConstructorInitialization (S=..., Entity=..., Kind=..., Args=...,
    Step=..., ConstructorInitRequiresZeroInit=@0x7ffffffea3b0: false, IsListInitialization=false,
    IsStdInitListInitialization=false, LBraceLoc=..., RBraceLoc=...)
    at /home/tbaeder/code/llvm-project/clang/lib/Sema/SemaInit.cpp:6660
```

The `EvaluateAsInt()` call in Frame 13 is simply a `ArrayInitIndexExpr` with no context around it, so `ArrayIndex` will never be set. I assume this is also the case in the current interpreter(?).


================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:665
+        // Narrow to our array element and recurse into visitInitializer()
+        if (!this->emitConstSint32(I, SubExpr))
+          return false;
----------------
erichkeane wrote:
> So why are these signed-int32?  Indexes are 64 bit on 64 bit machines, right?
Right, and `I` here is `size_t` anyway, so I should be using uint64 instead. I'll change that, thanks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134523/new/

https://reviews.llvm.org/D134523



More information about the cfe-commits mailing list