[all-commits] [llvm/llvm-project] bab6df: Rework how UuidAttr, CXXUuidofExpr, and GUID templ...

Richard Smith via All-commits all-commits at lists.llvm.org
Wed Apr 15 12:21:04 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: bab6df86aefc5ea4aa3895da7cf46be37add676d
      https://github.com/llvm/llvm-project/commit/bab6df86aefc5ea4aa3895da7cf46be37add676d
  Author: Richard Smith <richard at metafoo.co.uk>
  Date:   2020-04-15 (Wed, 15 Apr 2020)

  Changed paths:
    M clang/include/clang/AST/ASTContext.h
    M clang/include/clang/AST/DeclCXX.h
    M clang/include/clang/AST/ExprCXX.h
    M clang/include/clang/AST/Mangle.h
    M clang/include/clang/AST/RecursiveASTVisitor.h
    M clang/include/clang/AST/TemplateBase.h
    M clang/include/clang/Basic/Attr.td
    M clang/include/clang/Basic/DeclNodes.td
    M clang/include/clang/Basic/DiagnosticASTKinds.td
    M clang/include/clang/Sema/Sema.h
    M clang/include/clang/Serialization/ASTBitCodes.h
    M clang/lib/AST/ASTContext.cpp
    M clang/lib/AST/Decl.cpp
    M clang/lib/AST/DeclBase.cpp
    M clang/lib/AST/DeclCXX.cpp
    M clang/lib/AST/ExprClassification.cpp
    M clang/lib/AST/ExprConstant.cpp
    M clang/lib/AST/ItaniumMangle.cpp
    M clang/lib/AST/Mangle.cpp
    M clang/lib/AST/MicrosoftMangle.cpp
    M clang/lib/CodeGen/CGDebugInfo.cpp
    M clang/lib/CodeGen/CGDecl.cpp
    M clang/lib/CodeGen/CGExpr.cpp
    M clang/lib/CodeGen/CGExprConstant.cpp
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/lib/CodeGen/CodeGenModule.h
    M clang/lib/Sema/SemaDecl.cpp
    M clang/lib/Sema/SemaDeclAttr.cpp
    M clang/lib/Sema/SemaExpr.cpp
    M clang/lib/Sema/SemaExprCXX.cpp
    M clang/lib/Sema/SemaTemplate.cpp
    M clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
    M clang/lib/Sema/SemaType.cpp
    M clang/lib/Sema/TreeTransform.h
    M clang/lib/Serialization/ASTCommon.cpp
    M clang/lib/Serialization/ASTReader.cpp
    M clang/lib/Serialization/ASTReaderDecl.cpp
    M clang/lib/Serialization/ASTReaderStmt.cpp
    M clang/lib/Serialization/ASTWriter.cpp
    M clang/lib/Serialization/ASTWriterDecl.cpp
    M clang/lib/Serialization/ASTWriterStmt.cpp
    M clang/test/CodeGenCXX/debug-info-uuid.cpp
    M clang/test/CodeGenCXX/microsoft-templ-uuidof.cpp
    M clang/test/CodeGenCXX/microsoft-uuidof-mangling.cpp
    M clang/test/CodeGenCXX/microsoft-uuidof.cpp
    M clang/test/Parser/MicrosoftExtensions.cpp
    M clang/test/SemaCXX/ms-uuid.cpp
    M clang/tools/libclang/CIndex.cpp

  Log Message:
  -----------
  Rework how UuidAttr, CXXUuidofExpr, and GUID template arguments and constants are represented.

Summary:
Previously, we treated CXXUuidofExpr as quite a special case: it was the
only kind of expression that could be a canonical template argument, it
could be a constant lvalue base object, and so on. In addition, we
represented the UUID value as a string, whose source form we did not
preserve faithfully, and that we partially parsed in multiple different
places.

With this patch, we create an MSGuidDecl object to represent the
implicit object of type 'struct _GUID' created by a UuidAttr. Each
UuidAttr holds a pointer to its 'struct _GUID' and its original
(as-written) UUID string. A non-value-dependent CXXUuidofExpr behaves
like a DeclRefExpr denoting that MSGuidDecl object. We cache an APValue
representation of the GUID on the MSGuidDecl and use it from constant
evaluation where needed.

This allows removing a lot of the special-case logic to handle these
expressions. Unfortunately, many parts of Clang assume there are only
a couple of interesting kinds of ValueDecl, so the total amount of
special-case logic is not really reduced very much.

This fixes a few bugs and issues:
 * PR38490: we now support reading from GUID objects returned from
   __uuidof during constant evaluation.
 * Our Itanium mangling for a non-instantiation-dependent template
   argument involving __uuidof no longer depends on which CXXUuidofExpr
   template argument we happened to see first.
 * We now predeclare ::_GUID, and permit use of __uuidof without
   any header inclusion, better matching MSVC's behavior. We do not
   predefine ::__s_GUID, though; that seems like a step too far.
 * Our IR representation for GUID constants now uses the correct IR type
   wherever possible. We will still fall back to using the
      {i32, i16, i16, [8 x i8]}
   layout if a definition of struct _GUID is not available. This is not
   ideal: in principle the two layouts could have different padding.

Reviewers: rnk, jdoerfert

Subscribers: arphaman, cfe-commits, aeubanks

Tags: #clang

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




More information about the All-commits mailing list