[PATCH] D94237: [clang] Use SourceLocations in unions

Mikhail Maltsev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 7 08:48:28 PST 2021


miyuki created this revision.
miyuki added reviewers: dexonsmith, aprantl, rsmith.
Herald added a subscriber: jfb.
miyuki requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently, there are many instances where `SourceLocation` objects are
converted to raw representation to be stored in structs that are
used as fields of tagged unions.

This is done to make the corresponding structs trivial.
Triviality allows avoiding undefined behavior when implicitly changing
the active member of the union.

However, in most cases, we can explicitly construct an active member
using placement new. This patch adds the required active member
selections and replaces `SourceLocation`-s represented as
`unsigned int` with proper `SourceLocation`-s.

One notable exception is `DeclarationNameLoc`: the objects of this class
are often not properly initialized (so the code currently relies on
its default constructor which uses memset). This class will be fixed
in a separate patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94237

Files:
  clang/include/clang/AST/DependentDiagnostic.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/Designator.h
  clang/include/clang/Sema/Initialization.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94237.315149.patch
Type: text/x-patch
Size: 29079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210107/06769380/attachment-0001.bin>


More information about the cfe-commits mailing list