[PATCH] C99 partial re-initialization behavior (DR-253)

Richard Smith richard at metafoo.co.uk
Fri Jun 5 17:56:47 PDT 2015


+    // Bail out if the type of the ConstantStruct does not have the same
layout
+    // as the type of the InitListExpr.
+    if (CGM.getTypes().ConvertType(Field->getType()) != EltInit->getType())
+      return false;

I don't think that's quite enough; even if all the types of the
`ConstantStruct` match the types of the fields, the fields might be at
different offsets (due to an alignment attribute). This could happen if the
original initializer initializes one member of a union and the update
expression initializes a different member. Use `getStructLayout` on the
`DataLayout` object to find the offset of the fields within the
`ConstantStruct` and compare them to the offset from the `ASTRecordLayout`
object.

On Fri, Jun 5, 2015 at 5:50 PM, Yunzhong Gao <
Yunzhong_Gao at playstation.sony.com> wrote:

> http://reviews.llvm.org/D5789
>
> Files:
>   include/clang/AST/DataRecursiveASTVisitor.h
>   include/clang/AST/Expr.h
>   include/clang/AST/RecursiveASTVisitor.h
>   include/clang/Basic/StmtNodes.td
>   include/clang/Serialization/ASTBitCodes.h
>   lib/AST/Expr.cpp
>   lib/AST/ExprClassification.cpp
>   lib/AST/ExprConstant.cpp
>   lib/AST/ItaniumMangle.cpp
>   lib/AST/StmtPrinter.cpp
>   lib/AST/StmtProfile.cpp
>   lib/CodeGen/CGExprAgg.cpp
>   lib/CodeGen/CGExprCXX.cpp
>   lib/CodeGen/CGExprConstant.cpp
>   lib/Sema/SemaExceptionSpec.cpp
>   lib/Sema/SemaInit.cpp
>   lib/Sema/TreeTransform.h
>   lib/Serialization/ASTReaderStmt.cpp
>   lib/Serialization/ASTWriter.cpp
>   lib/Serialization/ASTWriterStmt.cpp
>   lib/StaticAnalyzer/Core/ExprEngine.cpp
>   test/Analysis/designated-initializer.c
>   test/CodeGen/partial-reinitialization1.c
>   test/CodeGen/partial-reinitialization2.c
>   test/PCH/designated-init.c.h
>   test/Sema/designated-initializers.c
>   test/SemaCXX/decltype.cpp
>   tools/libclang/CXCursor.cpp
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150605/5d0234eb/attachment.html>


More information about the cfe-commits mailing list