diff options
author | Richard Smith <richard@metafoo.co.uk> | 2020-07-13 16:54:39 -0700 |
---|---|---|
committer | Richard Smith <richard@metafoo.co.uk> | 2020-07-13 16:57:53 -0700 |
commit | 746b8c400bd3f975b49f4092aa6ecd30ade7cfa5 (patch) | |
tree | 5c109f2c1ebcca935e0498362fb18ce48b1c9361 /clang/lib/AST/ExprConstant.cpp | |
parent | eafe7c14ea38946e8c1fb64d548effaee7614718 (diff) | |
download | llvm-746b8c400bd3f975b49f4092aa6ecd30ade7cfa5.zip llvm-746b8c400bd3f975b49f4092aa6ecd30ade7cfa5.tar.gz llvm-746b8c400bd3f975b49f4092aa6ecd30ade7cfa5.tar.bz2 |
Basic support for flexible array members in constant evaluation.
We don't allow runtime-sized flexible array members, nor initialization
of flexible array members, but it seems reasonable to support the most
basic case where the flexible array member is empty.
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index a4dc0cc..d20c238 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9929,8 +9929,18 @@ namespace { bool ZeroInitialization(const Expr *E) { const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(E->getType()); - if (!CAT) + if (!CAT) { + if (const IncompleteArrayType *IAT = + Info.Ctx.getAsIncompleteArrayType(E->getType())) { + // We can be asked to zero-initialize a flexible array member; this + // is represented as an ImplicitValueInitExpr of incomplete array + // type. In this case, the array has zero elements. + Result = APValue(APValue::UninitArray(), 0, 0); + return true; + } + // FIXME: We could handle VLAs here. return Error(E); + } Result = APValue(APValue::UninitArray(), 0, CAT->getSize().getZExtValue()); |