cjdb created this revision.
cjdb added a reviewer: aaron.ballman.
Herald added a subscriber: dexonsmith.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116205

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Format/FormatToken.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/add_cv.cpp

Index: clang/test/SemaCXX/add_cv.cpp
===================================================================
--- clang/test/SemaCXX/add_cv.cpp
+++ clang/test/SemaCXX/add_cv.cpp
@@ -6,6 +6,7 @@
 template <class T>
 constexpr bool check_add_cv() {
   static_assert(__is_same(__add_const(T), const T), "");
+  static_assert(__is_same(__add_volatile(T), volatile T), "");
   return true;
 }
 
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1262,6 +1262,8 @@
   switch (SwitchTST) {
   case TST_add_const:
     return UnaryTransformType::AddConst;
+  case TST_add_volatile:
+    return UnaryTransformType::AddVolatile;
   case TST_underlyingType:
     return UnaryTransformType::EnumUnderlyingType;
   default:
@@ -1653,6 +1655,7 @@
   }
   case DeclSpec::TST_underlyingType:
   case DeclSpec::TST_add_const:
+  case DeclSpec::TST_add_volatile:
     Result = S.GetTypeFromParser(DS.getRepAsType());
     assert(!Result.isNull() && "Didn't get a type for the transformation?");
     Result = S.BuildUnaryTransformType(
@@ -5990,7 +5993,7 @@
     void VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
       // Make sure it is a unary transform type
       assert(DS.getTypeSpecType() >= DeclSpec::TST_underlyingType &&
-             DS.getTypeSpecType() <= DeclSpec::TST_add_const);
+             DS.getTypeSpecType() <= DeclSpec::TST_add_volatile);
       TL.setKWLoc(DS.getTypeSpecTypeLoc());
       TL.setParensRange(DS.getTypeofParensRange());
       assert(DS.getRepAsType());
@@ -9090,6 +9093,16 @@
     return Context.getUnaryTransformType(BaseType, Underlying,
                                          UnaryTransformType::AddConst);
   }
+  case UnaryTransformType::AddVolatile: {
+    SplitQualType Split = BaseType.getSplitUnqualifiedType();
+    Qualifiers Quals = BaseType.getQualifiers();
+    if (BaseType->isReferenceType() || BaseType->isFunctionType())
+      return BaseType;
+    Quals.addVolatile();
+    QualType Underlying(Split.Ty, Quals.getAsOpaqueValue());
+    return Context.getUnaryTransformType(BaseType, Underlying,
+                                         UnaryTransformType::AddVolatile);
+  }
   }
   llvm_unreachable("unknown unary transform type");
 }
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -862,6 +862,7 @@
   case TST_typeofType:
   case TST_underlyingType:
   case TST_add_const:
+  case TST_add_volatile:
   case TST_atomic: {
     QualType T = DS.getRepAsType().get();
     if (!T.isNull() && T->containsUnexpandedParameterPack())
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -146,6 +146,7 @@
   case tok::kw_bool:
   case tok::kw___underlying_type:
   case tok::kw___add_const:
+  case tok::kw___add_volatile:
   case tok::kw___auto_type:
     return true;
 
@@ -5601,6 +5602,7 @@
   case DeclSpec::TST_typeofType:
   case DeclSpec::TST_underlyingType:
   case DeclSpec::TST_add_const:
+  case DeclSpec::TST_add_volatile:
   case DeclSpec::TST_atomic: {
     // Grab the type from the parser.
     TypeSourceInfo *TSI = nullptr;
Index: clang/lib/Sema/DeclSpec.cpp
===================================================================
--- clang/lib/Sema/DeclSpec.cpp
+++ clang/lib/Sema/DeclSpec.cpp
@@ -391,6 +391,7 @@
 
     case TST_underlyingType:
     case TST_add_const:
+    case TST_add_volatile:
     case TST_typename:
     case TST_typeofType: {
       QualType QT = DS.getRepAsType().get();
@@ -580,6 +581,8 @@
   case DeclSpec::TST_underlyingType: return "__underlying_type";
   case DeclSpec::TST_add_const:
     return "__add_const";
+  case DeclSpec::TST_add_volatile:
+    return "__add_volatile";
   case DeclSpec::TST_unknown_anytype: return "__unknown_anytype";
   case DeclSpec::TST_atomic: return "_Atomic";
   case DeclSpec::TST_BFloat16: return "__bf16";
Index: clang/lib/Parse/ParseDeclCXX.cpp
===================================================================
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1511,14 +1511,14 @@
   if (TagType == DeclSpec::TST_struct && Tok.isNot(tok::identifier) &&
       !Tok.isAnnotation() && Tok.getIdentifierInfo() &&
       Tok.isOneOf(
-          tok::kw___add_const, tok::kw___is_abstract, tok::kw___is_aggregate,
-          tok::kw___is_arithmetic, tok::kw___is_array, tok::kw___is_assignable,
-          tok::kw___is_base_of, tok::kw___is_class, tok::kw___is_complete_type,
-          tok::kw___is_compound, tok::kw___is_const, tok::kw___is_constructible,
-          tok::kw___is_convertible, tok::kw___is_convertible_to,
-          tok::kw___is_destructible, tok::kw___is_empty, tok::kw___is_enum,
-          tok::kw___is_floating_point, tok::kw___is_final,
-          tok::kw___is_function, tok::kw___is_fundamental,
+          tok::kw___add_const, tok::kw___add_volatile, tok::kw___is_abstract,
+          tok::kw___is_aggregate, tok::kw___is_arithmetic, tok::kw___is_array,
+          tok::kw___is_assignable, tok::kw___is_base_of, tok::kw___is_class,
+          tok::kw___is_complete_type, tok::kw___is_compound, tok::kw___is_const,
+          tok::kw___is_constructible, tok::kw___is_convertible,
+          tok::kw___is_convertible_to, tok::kw___is_destructible,
+          tok::kw___is_empty, tok::kw___is_enum, tok::kw___is_floating_point,
+          tok::kw___is_final, tok::kw___is_function, tok::kw___is_fundamental,
           tok::kw___is_integral, tok::kw___is_interface_class,
           tok::kw___is_literal, tok::kw___is_lvalue_expr,
           tok::kw___is_lvalue_reference, tok::kw___is_member_function_pointer,
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -4116,6 +4116,7 @@
       continue;
 
     case tok::kw___add_const:
+    case tok::kw___add_volatile:
       ParseTypeTransformTypeSpecifier(DS);
       continue;
 
@@ -4223,6 +4224,8 @@
   switch (Tok.getKind()) {
   case tok::kw___add_const:
     return DeclSpec::TST_add_const;
+  case tok::kw___add_volatile:
+    return DeclSpec::TST_add_volatile;
   }
 
   __builtin_unreachable();
Index: clang/lib/Lex/PPMacroExpansion.cpp
===================================================================
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -1659,6 +1659,7 @@
               .Case("__reference_binds_to_temporary", true)
               .Case("__underlying_type", true)
               .Case("__add_const", true)
+              .Case("__add_volatile", true)
               .Default(false);
         } else {
           return llvm::StringSwitch<bool>(II->getName())
Index: clang/lib/Format/FormatToken.cpp
===================================================================
--- clang/lib/Format/FormatToken.cpp
+++ clang/lib/Format/FormatToken.cpp
@@ -58,6 +58,7 @@
   case tok::kw_bool:
   case tok::kw___underlying_type:
   case tok::kw___add_const:
+  case tok::kw___add_volatile:
   case tok::annot_typename:
   case tok::kw_char8_t:
   case tok::kw_char16_t:
Index: clang/lib/AST/TypePrinter.cpp
===================================================================
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1120,9 +1120,10 @@
 
   switch (T->getUTTKind()) {
     case UnaryTransformType::EnumUnderlyingType:
-    case UnaryTransformType::AddConst: {
-      constexpr std::array<const char *, 2> Transformation = {
-          "__underlying_type", "__add_const"};
+    case UnaryTransformType::AddConst:
+    case UnaryTransformType::AddVolatile: {
+      constexpr std::array<const char *, 3> Transformation = {
+          "__underlying_type", "__add_const", "__add_volatile"};
       OS << Transformation[T->getUTTKind()] << '(';
       print(T->getBaseType(), OS, StringRef());
       OS << ')';
@@ -1141,6 +1142,7 @@
   switch (T->getUTTKind()) {
     case UnaryTransformType::EnumUnderlyingType:
     case UnaryTransformType::AddConst:
+    case UnaryTransformType::AddVolatile:
       return;
   }
 
Index: clang/lib/AST/JSONNodeDumper.cpp
===================================================================
--- clang/lib/AST/JSONNodeDumper.cpp
+++ clang/lib/AST/JSONNodeDumper.cpp
@@ -668,6 +668,9 @@
   case UnaryTransformType::AddConst:
     JOS.attribute("transformedKind", "add_const");
     break;
+  case UnaryTransformType::AddVolatile:
+    JOS.attribute("transformedKind", "add_volatile");
+    break;
   }
 }
 
Index: clang/lib/AST/ItaniumMangle.cpp
===================================================================
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -3928,6 +3928,9 @@
       case UnaryTransformType::AddConst:
         Out << "3ac";
         break;
+      case UnaryTransformType::AddVolatile:
+        Out << "3av";
+        break;
     }
   }
 
Index: clang/include/clang/Sema/DeclSpec.h
===================================================================
--- clang/include/clang/Sema/DeclSpec.h
+++ clang/include/clang/Sema/DeclSpec.h
@@ -292,6 +292,7 @@
   static const TST TST_decltype_auto = clang::TST_decltype_auto;
   static const TST TST_underlyingType = clang::TST_underlyingType;
   static const TST TST_add_const = clang::TST_add_const;
+  static const TST TST_add_volatile = clang::TST_add_volatile;
   static const TST TST_auto = clang::TST_auto;
   static const TST TST_auto_type = clang::TST_auto_type;
   static const TST TST_unknown_anytype = clang::TST_unknown_anytype;
Index: clang/include/clang/Basic/TokenKinds.def
===================================================================
--- clang/include/clang/Basic/TokenKinds.def
+++ clang/include/clang/Basic/TokenKinds.def
@@ -509,6 +509,7 @@
              HasUniqueObjectRepresentations, KEYCXX)
 KEYWORD(__underlying_type           , KEYCXX)
 KEYWORD(__add_const, KEYCXX)
+KEYWORD(__add_volatile, KEYCXX)
 
 // Clang-only C++ Type Traits
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
Index: clang/include/clang/Basic/Specifiers.h
===================================================================
--- clang/include/clang/Basic/Specifiers.h
+++ clang/include/clang/Basic/Specifiers.h
@@ -84,6 +84,7 @@
     TST_decltype,        // C++11 decltype
     TST_underlyingType,  // __underlying_type for C++11
     TST_add_const,       // __add_const extension
+    TST_add_volatile,    // __add_volatile extension
     TST_auto,            // C++11 auto
     TST_decltype_auto,   // C++1y decltype(auto)
     TST_auto_type,       // __auto_type extension
Index: clang/include/clang/AST/Type.h
===================================================================
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -4555,6 +4555,7 @@
   enum UTTKind {
     EnumUnderlyingType,
     AddConst,
+    AddVolatile,
   };
 
 private:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D116205: [cla... Christopher Di Bella via Phabricator via cfe-commits

Reply via email to