[clang] [clang][NFC] Annotate `Type` bit-fields with `clang::preferred_type` (PR #70349)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/70349 >From 7329f68092d5f8f5a5978e5a6cbad6ada87d4fe8 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 26 Oct 2023 16:09:25 +0300 Subject: [PATCH 1/3] [clang][NFC] Annotate `Type` bit-fields with `clang::preferred_type` --- clang/include/clang/AST/DeclBase.h| 2 +- clang/include/clang/AST/DependenceFlags.h | 2 +- clang/include/clang/AST/Type.h| 46 ++- clang/include/clang/Basic/Linkage.h | 2 +- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index 978e4255e877ec2..0307691fdd480bf 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -49,7 +49,7 @@ class ExternalSourceSymbolAttr; class FunctionDecl; class FunctionType; class IdentifierInfo; -enum Linkage : unsigned char; +enum Linkage : unsigned; class LinkageSpecDecl; class Module; class NamedDecl; diff --git a/clang/include/clang/AST/DependenceFlags.h b/clang/include/clang/AST/DependenceFlags.h index 3b3c1afb096addd..e91b6ff35b34966 100644 --- a/clang/include/clang/AST/DependenceFlags.h +++ b/clang/include/clang/AST/DependenceFlags.h @@ -49,7 +49,7 @@ struct ExprDependenceScope { using ExprDependence = ExprDependenceScope::ExprDependence; struct TypeDependenceScope { - enum TypeDependence : uint8_t { + enum TypeDependence : unsigned { /// Whether this type contains an unexpanded parameter pack /// (for C++11 variadic templates) UnexpandedPack = 1, diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 1e8e1303e65f6ba..f24b1dccc240785 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1611,22 +1611,28 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { template friend class TypePropertyCache; /// TypeClass bitfield - Enum that specifies what subclass this belongs to. +[[clang::preferred_type(TypeClass)]] unsigned TC : 8; /// Store information on the type dependency. +[[clang::preferred_type(TypeDependence)]] unsigned Dependence : llvm::BitWidth; /// True if the cache (i.e. the bitfields here starting with /// 'Cache') is valid. +[[clang::preferred_type(bool)]] mutable unsigned CacheValid : 1; /// Linkage of this type. +[[clang::preferred_type(Linkage)]] mutable unsigned CachedLinkage : 3; /// Whether this type involves and local or unnamed types. +[[clang::preferred_type(bool)]] mutable unsigned CachedLocalOrUnnamed : 1; /// Whether this type comes from an AST file. +[[clang::preferred_type(bool)]] mutable unsigned FromAST : 1; bool isCacheValid() const { @@ -1652,10 +1658,12 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { class ArrayTypeBitfields { friend class ArrayType; +[[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits; /// CVR qualifiers from declarations like /// 'int X[static restrict 4]'. For function parameters only. +[[clang::preferred_type(Qualifiers)]] unsigned IndexTypeQuals : 3; /// Storage class qualifiers from declarations like @@ -1671,12 +1679,14 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { unsigned : NumArrayTypeBits; /// Whether we have a stored size expression. +[[clang::preferred_type(bool)]] unsigned HasStoredSizeExpr : 1; }; class BuiltinTypeBitfields { friend class BuiltinType; +[[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits; /// The kind (BuiltinType::Kind) of builtin type this is. @@ -1691,15 +1701,18 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { friend class FunctionProtoType; friend class FunctionType; +[[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits; /// Extra information which affects how the function is called, like /// regparm and the calling convention. +[[clang::preferred_type(CallingConv)]] unsigned ExtInfo : 13; /// The ref-qualifier associated with a \c FunctionProtoType. /// /// This is a value of type \c RefQualifierKind. +[[clang::preferred_type(RefQualifierKind)]] unsigned RefQualifier : 2; /// Used only by FunctionProtoType, put here to pack with the @@ -1708,8 +1721,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { /// /// C++ 8.3.5p4: The return type, the parameter type list and the /// cv-qualifier-seq, [...], are part of the function type. +[[clang::preferred_type(Qualifiers)]] unsigned FastTypeQuals : Qualifiers::FastWidth; /// Whether this function has extended Qualifiers. +[[clang::preferred_type(bool)]] unsigned HasExtQuals : 1; /// The number of parameters
[clang] [clang][NFC] Refactor `Selector` to use `PointerIntPair` inside (PR #69916)
@@ -809,43 +927,42 @@ class Selector { enum IdentifierInfoFlag { // Empty selector = 0. Note that these enumeration values must // correspond to the enumeration values of DeclarationName::StoredNameKind -ZeroArg = 0x01, -OneArg = 0x02, +ZeroArg = 0x01, +OneArg = 0x02, MultiArg = 0x07, Endilll wrote: Applied. https://github.com/llvm/llvm-project/pull/69916 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Refactor `Selector` to use `PointerIntPair` inside (PR #69916)
@@ -809,43 +927,42 @@ class Selector { enum IdentifierInfoFlag { // Empty selector = 0. Note that these enumeration values must // correspond to the enumeration values of DeclarationName::StoredNameKind -ZeroArg = 0x01, -OneArg = 0x02, +ZeroArg = 0x01, +OneArg = 0x02, MultiArg = 0x07, -ArgFlags = 0x07 }; /// A pointer to the MultiKeywordSelector or IdentifierInfo. We use the low - /// three bits of InfoPtr to store an IdentifierInfoFlag. Note that in any + /// three bits of InfoPtr to store an IdentifierInfoFlag, but the highest + /// of them is also a discriminator for pointer type. Note that in any /// case IdentifierInfo and MultiKeywordSelector are already aligned to /// 8 bytes even on 32 bits archs because of DeclarationName. - uintptr_t InfoPtr = 0; + llvm::PointerIntPair< + llvm::PointerUnion, 2> + InfoPtr; Endilll wrote: Applied with an addition we discussed offline. https://github.com/llvm/llvm-project/pull/69916 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 421d6cc - [clang][NFC] Annotate `CXXInheritance.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T10:00:42+03:00 New Revision: 421d6ccc4c663b90aa03be7b7598fff50478e997 URL: https://github.com/llvm/llvm-project/commit/421d6ccc4c663b90aa03be7b7598fff50478e997 DIFF: https://github.com/llvm/llvm-project/commit/421d6ccc4c663b90aa03be7b7598fff50478e997.diff LOG: [clang][NFC] Annotate `CXXInheritance.h` with `preferred_type` Added: Modified: clang/include/clang/AST/CXXInheritance.h Removed: diff --git a/clang/include/clang/AST/CXXInheritance.h b/clang/include/clang/AST/CXXInheritance.h index eec2119f4a1801e..d18e1ce7e0e9e4d 100644 --- a/clang/include/clang/AST/CXXInheritance.h +++ b/clang/include/clang/AST/CXXInheritance.h @@ -131,6 +131,7 @@ class CXXBasePaths { /// class subobjects for that class type. The key of the map is /// the cv-unqualified canonical type of the base class subobject. struct IsVirtBaseAndNumberNonVirtBases { +LLVM_PREFERRED_TYPE(bool) unsigned IsVirtBase : 1; unsigned NumberOfNonVirtBases : 31; }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] a5d2570 - [clang][NFC] Annotate ``DependentDiagnostic.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T10:04:21+03:00 New Revision: a5d25708616d692592e705a0913afd78237698af URL: https://github.com/llvm/llvm-project/commit/a5d25708616d692592e705a0913afd78237698af DIFF: https://github.com/llvm/llvm-project/commit/a5d25708616d692592e705a0913afd78237698af.diff LOG: [clang][NFC] Annotate ``DependentDiagnostic.h` with `preferred_type` Added: Modified: clang/include/clang/AST/DependentDiagnostic.h Removed: diff --git a/clang/include/clang/AST/DependentDiagnostic.h b/clang/include/clang/AST/DependentDiagnostic.h index 18276d54d540471..cadf970620041e6 100644 --- a/clang/include/clang/AST/DependentDiagnostic.h +++ b/clang/include/clang/AST/DependentDiagnostic.h @@ -113,7 +113,9 @@ class DependentDiagnostic { struct { SourceLocation Loc; +LLVM_PREFERRED_TYPE(AccessSpecifier) unsigned Access : 2; +LLVM_PREFERRED_TYPE(bool) unsigned IsMember : 1; NamedDecl *TargetDecl; CXXRecordDecl *NamingClass; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 61d17b1 - [clang][NFC] Annotate `DeclCXX.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T10:14:49+03:00 New Revision: 61d17b116880b34b6639e2780b9d46865d811be2 URL: https://github.com/llvm/llvm-project/commit/61d17b116880b34b6639e2780b9d46865d811be2 DIFF: https://github.com/llvm/llvm-project/commit/61d17b116880b34b6639e2780b9d46865d811be2.diff LOG: [clang][NFC] Annotate `DeclCXX.h` with `preferred_type` Added: Modified: clang/include/clang/AST/DeclCXX.h Removed: diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index df1dc5a401f39a5..432293583576b5a 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -154,22 +154,26 @@ class CXXBaseSpecifier { SourceLocation EllipsisLoc; /// Whether this is a virtual base class or not. + LLVM_PREFERRED_TYPE(bool) unsigned Virtual : 1; /// Whether this is the base of a class (true) or of a struct (false). /// /// This determines the mapping from the access specifier as written in the /// source code to the access specifier used for semantic analysis. + LLVM_PREFERRED_TYPE(bool) unsigned BaseOfClass : 1; /// Access specifier as written in the source code (may be AS_none). /// /// The actual type of data stored here is an AccessSpecifier, but we use - /// "unsigned" here to work around a VC++ bug. + /// "unsigned" here to work around Microsoft ABI. + LLVM_PREFERRED_TYPE(AccessSpecifier) unsigned Access : 2; /// Whether the class contains a using declaration /// to inherit the named class's constructors. + LLVM_PREFERRED_TYPE(bool) unsigned InheritConstructors : 1; /// The type of the base class. @@ -290,15 +294,19 @@ class CXXRecordDecl : public RecordDecl { #include "CXXRecordDeclDefinitionBits.def" /// Whether this class describes a C++ lambda. +LLVM_PREFERRED_TYPE(bool) unsigned IsLambda : 1; /// Whether we are currently parsing base specifiers. +LLVM_PREFERRED_TYPE(bool) unsigned IsParsingBaseSpecifiers : 1; /// True when visible conversion functions are already computed /// and are available. +LLVM_PREFERRED_TYPE(bool) unsigned ComputedVisibleConversions : 1; +LLVM_PREFERRED_TYPE(bool) unsigned HasODRHash : 1; /// A hash of parts of the class to help in ODR checking. @@ -383,12 +391,15 @@ class CXXRecordDecl : public RecordDecl { /// lambda will have been created with the enclosing context as its /// declaration context, rather than function. This is an unfortunate /// artifact of having to parse the default arguments before. +LLVM_PREFERRED_TYPE(LambdaDependencyKind) unsigned DependencyKind : 2; /// Whether this lambda is a generic lambda. +LLVM_PREFERRED_TYPE(bool) unsigned IsGenericLambda : 1; /// The Default Capture. +LLVM_PREFERRED_TYPE(LambdaCaptureDefault) unsigned CaptureDefault : 2; /// The number of captures in this lambda is limited 2^NumCaptures. @@ -398,6 +409,7 @@ class CXXRecordDecl : public RecordDecl { unsigned NumExplicitCaptures : 12; /// Has known `internal` linkage. +LLVM_PREFERRED_TYPE(bool) unsigned HasKnownInternalLinkage : 1; /// The number used to indicate this lambda expression for name @@ -2305,14 +2317,17 @@ class CXXCtorInitializer final { /// If the initializee is a type, whether that type makes this /// a delegating initialization. + LLVM_PREFERRED_TYPE(bool) unsigned IsDelegating : 1; /// If the initializer is a base initializer, this keeps track /// of whether the base is virtual or not. + LLVM_PREFERRED_TYPE(bool) unsigned IsVirtual : 1; /// Whether or not the initializer is explicitly written /// in the sources. + LLVM_PREFERRED_TYPE(bool) unsigned IsWritten : 1; /// If IsWritten is true, then this number keeps track of the textual order @@ -3588,6 +3603,7 @@ class ConstructorUsingShadowDecl final : public UsingShadowDecl { /// \c true if the constructor ultimately named by this using shadow /// declaration is within a virtual base class subobject of the class that /// contains this declaration. + LLVM_PREFERRED_TYPE(bool) unsigned IsVirtual : 1; ConstructorUsingShadowDecl(ASTContext , DeclContext *DC, SourceLocation Loc, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c032225 - [clang][NFC] Annotate `RawCommentList.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T10:43:53+03:00 New Revision: c032225bfcac9322661fac8c943a63ba70eb0e19 URL: https://github.com/llvm/llvm-project/commit/c032225bfcac9322661fac8c943a63ba70eb0e19 DIFF: https://github.com/llvm/llvm-project/commit/c032225bfcac9322661fac8c943a63ba70eb0e19.diff LOG: [clang][NFC] Annotate `RawCommentList.h` with `preferred_type` Added: Modified: clang/include/clang/AST/RawCommentList.h Removed: diff --git a/clang/include/clang/AST/RawCommentList.h b/clang/include/clang/AST/RawCommentList.h index 2f44a77d4503d31..53aae24fa7bbc1b 100644 --- a/clang/include/clang/AST/RawCommentList.h +++ b/clang/include/clang/AST/RawCommentList.h @@ -178,6 +178,7 @@ class RawComment { mutable bool RawTextValid : 1; ///< True if RawText is valid mutable bool BriefTextValid : 1; ///< True if BriefText is valid + LLVM_PREFERRED_TYPE(CommentKind) unsigned Kind : 3; /// True if comment is attached to a declaration in ASTContext. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] a07dbf1 - [clang][NFC] Annotate `PrettyPrinter.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T10:58:27+03:00 New Revision: a07dbf1fb0f4ba36911233c82914a9ddf3eb4a09 URL: https://github.com/llvm/llvm-project/commit/a07dbf1fb0f4ba36911233c82914a9ddf3eb4a09 DIFF: https://github.com/llvm/llvm-project/commit/a07dbf1fb0f4ba36911233c82914a9ddf3eb4a09.diff LOG: [clang][NFC] Annotate `PrettyPrinter.h` with `preferred_type` Added: Modified: clang/include/clang/AST/PrettyPrinter.h Removed: diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h index cee3cce7729c30f..da276e26049b00a 100644 --- a/clang/include/clang/AST/PrettyPrinter.h +++ b/clang/include/clang/AST/PrettyPrinter.h @@ -106,6 +106,7 @@ struct PrintingPolicy { /// declaration for "x", so that we will print "int *x"; it will be /// \c true when we print "y", so that we suppress printing the /// "const int" type specifier and instead only print the "*y". + LLVM_PREFERRED_TYPE(bool) unsigned SuppressSpecifiers : 1; /// Whether type printing should skip printing the tag keyword. @@ -116,6 +117,7 @@ struct PrintingPolicy { /// \code /// struct Geometry::Point; /// \endcode + LLVM_PREFERRED_TYPE(bool) unsigned SuppressTagKeyword : 1; /// When true, include the body of a tag definition. @@ -126,22 +128,27 @@ struct PrintingPolicy { /// \code /// typedef struct { int x, y; } Point; /// \endcode + LLVM_PREFERRED_TYPE(bool) unsigned IncludeTagDefinition : 1; /// Suppresses printing of scope specifiers. + LLVM_PREFERRED_TYPE(bool) unsigned SuppressScope : 1; /// Suppress printing parts of scope specifiers that are never /// written, e.g., for anonymous namespaces. + LLVM_PREFERRED_TYPE(bool) unsigned SuppressUnwrittenScope : 1; /// Suppress printing parts of scope specifiers that correspond /// to inline namespaces, where the name is unambiguous with the specifier /// removed. + LLVM_PREFERRED_TYPE(bool) unsigned SuppressInlineNamespace : 1; /// Ignore qualifiers and tag keywords as specified by elaborated type sugar, /// instead letting the underlying type print as normal. + LLVM_PREFERRED_TYPE(bool) unsigned SuppressElaboration : 1; /// Suppress printing of variable initializers. @@ -155,6 +162,7 @@ struct PrintingPolicy { /// /// SuppressInitializers will be true when printing "auto x", so that the /// internal initializer constructed for x will not be printed. + LLVM_PREFERRED_TYPE(bool) unsigned SuppressInitializers : 1; /// Whether we should print the sizes of constant array expressions as written @@ -173,53 +181,67 @@ struct PrintingPolicy { /// int a[104]; /// char a[9] = "A string"; /// \endcode + LLVM_PREFERRED_TYPE(bool) unsigned ConstantArraySizeAsWritten : 1; /// When printing an anonymous tag name, also print the location of that /// entity (e.g., "enum "). Otherwise, just prints /// "(anonymous)" for the name. + LLVM_PREFERRED_TYPE(bool) unsigned AnonymousTagLocations : 1; /// When true, suppress printing of the __strong lifetime qualifier in ARC. + LLVM_PREFERRED_TYPE(bool) unsigned SuppressStrongLifetime : 1; /// When true, suppress printing of lifetime qualifier in ARC. + LLVM_PREFERRED_TYPE(bool) unsigned SuppressLifetimeQualifiers : 1; /// When true, suppresses printing template arguments in names of C++ /// constructors. + LLVM_PREFERRED_TYPE(bool) unsigned SuppressTemplateArgsInCXXConstructors : 1; /// When true, attempt to suppress template arguments that match the default /// argument for the parameter. + LLVM_PREFERRED_TYPE(bool) unsigned SuppressDefaultTemplateArgs : 1; /// Whether we can use 'bool' rather than '_Bool' (even if the language /// doesn't actually have 'bool', because, e.g., it is defined as a macro). + LLVM_PREFERRED_TYPE(bool) unsigned Bool : 1; /// Whether we should use 'nullptr' rather than '0' as a null pointer /// constant. + LLVM_PREFERRED_TYPE(bool) unsigned Nullptr : 1; /// Whether 'nullptr_t' is in namespace 'std' or not. + LLVM_PREFERRED_TYPE(bool) unsigned NullptrTypeInNamespace : 1; /// Whether we can use 'restrict' rather than '__restrict'. + LLVM_PREFERRED_TYPE(bool) unsigned Restrict : 1; /// Whether we can use 'alignof' rather than '__alignof'. + LLVM_PREFERRED_TYPE(bool) unsigned Alignof : 1; /// Whether we can use '_Alignof' rather than '__alignof'. + LLVM_PREFERRED_TYPE(bool) unsigned UnderscoreAlignof : 1; /// Whether we should use '(void)' rather than '()' for a function prototype /// with zero parameters. + LLVM_PREFERRED_TYPE(bool) unsigned UseVoidForZeroParams : 1; /// Whether nested templates must be closed like 'a\ \>' rather than /// 'a\\>'. + LLVM_PREFERRED_TYPE(bool) unsigned SplitTemplateClosers : 1; /// Provide a 'terse'
[clang] fb9d124 - [clang][NFC] Clean up commented-out code in `StringLiteral`
Author: Vlad Serebrennikov Date: 2023-11-06T09:20:04+03:00 New Revision: fb9d1243f535a8b678824d2b63d33eb183a7f2bc URL: https://github.com/llvm/llvm-project/commit/fb9d1243f535a8b678824d2b63d33eb183a7f2bc DIFF: https://github.com/llvm/llvm-project/commit/fb9d1243f535a8b678824d2b63d33eb183a7f2bc.diff LOG: [clang][NFC] Clean up commented-out code in `StringLiteral` Leftovers from 3e6ce58701a3a8463b53fb3fd2023c02b4e90554. Added: Modified: clang/include/clang/AST/Expr.h Removed: diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index c2691f80dc54a7e..a9c4c67a60e8e8e 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -1827,10 +1827,6 @@ class StringLiteral final /// /// * An array of getByteLength() char used to store the string data. -public: - // enum StringKind { Ordinary, Wide, UTF8, UTF16, UTF32, Unevaluated }; - -private: unsigned numTrailingObjects(OverloadToken) const { return 1; } unsigned numTrailingObjects(OverloadToken) const { return getNumConcatenated(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f1fdbcb - [clang]]NFC] Annotate `DeclObjC.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T10:28:58+03:00 New Revision: f1fdbcba5fc0f88a481f105c2a16f56db0dd2940 URL: https://github.com/llvm/llvm-project/commit/f1fdbcba5fc0f88a481f105c2a16f56db0dd2940 DIFF: https://github.com/llvm/llvm-project/commit/f1fdbcba5fc0f88a481f105c2a16f56db0dd2940.diff LOG: [clang]]NFC] Annotate `DeclObjC.h` with `preferred_type` Added: Modified: clang/include/clang/AST/DeclObjC.h Removed: diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index e0b31c58c39a2c5..f8f894b4b10d191 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -580,6 +580,7 @@ class ObjCTypeParamDecl : public TypedefNameDecl { unsigned Index : 14; /// The variance of the type parameter. + LLVM_PREFERRED_TYPE(ObjCTypeParamVariance) unsigned Variance : 2; /// The location of the variance, if any. @@ -741,10 +742,13 @@ class ObjCPropertyDecl : public NamedDecl { QualType DeclType; TypeSourceInfo *DeclTypeSourceInfo; + LLVM_PREFERRED_TYPE(ObjCPropertyAttribute::Kind) unsigned PropertyAttributes : NumObjCPropertyAttrsBits; + LLVM_PREFERRED_TYPE(ObjCPropertyAttribute::Kind) unsigned PropertyAttributesAsWritten : NumObjCPropertyAttrsBits; // \@required/\@optional + LLVM_PREFERRED_TYPE(PropertyControl) unsigned PropertyImplementation : 2; // getter name of NULL if no getter @@ -1178,14 +1182,17 @@ class ObjCInterfaceDecl : public ObjCContainerDecl /// Indicates that the contents of this Objective-C class will be /// completed by the external AST source when required. +LLVM_PREFERRED_TYPE(bool) mutable unsigned ExternallyCompleted : 1; /// Indicates that the ivar cache does not yet include ivars /// declared in the implementation. +LLVM_PREFERRED_TYPE(bool) mutable unsigned IvarListMissingImplementation : 1; /// Indicates that this interface decl contains at least one initializer /// marked with the 'objc_designated_initializer' attribute. +LLVM_PREFERRED_TYPE(bool) unsigned HasDesignatedInitializers : 1; enum InheritedDesignatedInitializersState { @@ -1201,9 +1208,11 @@ class ObjCInterfaceDecl : public ObjCContainerDecl }; /// One of the \c InheritedDesignatedInitializersState enumeratos. +LLVM_PREFERRED_TYPE(InheritedDesignatedInitializersState) mutable unsigned InheritedDesignatedInitializers : 2; /// Tracks whether a ODR hash has been computed for this interface. +LLVM_PREFERRED_TYPE(bool) unsigned HasODRHash : 1; /// A hash of parts of the class to help in ODR checking. @@ -2007,7 +2016,9 @@ class ObjCIvarDecl : public FieldDecl { ObjCIvarDecl *NextIvar = nullptr; // NOTE: VC++ treats enums as signed, avoid using the AccessControl enum + LLVM_PREFERRED_TYPE(AccessControl) unsigned DeclAccess : 3; + LLVM_PREFERRED_TYPE(bool) unsigned Synthesized : 1; }; @@ -2074,6 +2085,7 @@ class ObjCProtocolDecl : public ObjCContainerDecl, ObjCProtocolList ReferencedProtocols; /// Tracks whether a ODR hash has been computed for this protocol. +LLVM_PREFERRED_TYPE(bool) unsigned HasODRHash : 1; /// A hash of parts of the class to help in ODR checking. @@ -2596,9 +2608,11 @@ class ObjCImplementationDecl : public ObjCImplDecl { /// Do the ivars of this class require initialization other than /// zero-initialization? + LLVM_PREFERRED_TYPE(bool) bool HasNonZeroConstructors : 1; /// Do the ivars of this class require non-trivial destruction? + LLVM_PREFERRED_TYPE(bool) bool HasDestructors : 1; ObjCImplementationDecl(DeclContext *DC, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)
@@ -2388,15 +2389,20 @@ class CXXNewExpr final /// Whether this new-expression has any initializer at all. bool hasInitializer() const { -return CXXNewExprBits.StoredInitializationStyle > 0; +switch (getInitializationStyle()) { +case CXXNewInitializationStyle::None: + return true; +case CXXNewInitializationStyle::Implicit: +case CXXNewInitializationStyle::Call: +case CXXNewInitializationStyle::List: + return false; +} Endilll wrote: Behavioral change wasn't intended and is now fixed (thank you!) I find inequality checks against enums not very robust, so I refactored this into switch. https://github.com/llvm/llvm-project/pull/71322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 58679ea - [clang][NFC] Annotate `clang/Lex` headers with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T12:34:10+03:00 New Revision: 58679ea576f9e48e20e43dcd99fd75c98fb7e6ba URL: https://github.com/llvm/llvm-project/commit/58679ea576f9e48e20e43dcd99fd75c98fb7e6ba DIFF: https://github.com/llvm/llvm-project/commit/58679ea576f9e48e20e43dcd99fd75c98fb7e6ba.diff LOG: [clang][NFC] Annotate `clang/Lex` headers with `preferred_type` This helps debuggers display unsigned bit-fields correctly. Added: Modified: clang/include/clang/Lex/DirectoryLookup.h clang/include/clang/Lex/HeaderSearch.h clang/include/clang/Lex/HeaderSearchOptions.h clang/include/clang/Lex/MacroInfo.h clang/include/clang/Lex/ModuleMap.h clang/include/clang/Lex/PreprocessingRecord.h clang/include/clang/Lex/VariadicMacroSupport.h Removed: diff --git a/clang/include/clang/Lex/DirectoryLookup.h b/clang/include/clang/Lex/DirectoryLookup.h index d668a830db38fd1..81680d3b271e081 100644 --- a/clang/include/clang/Lex/DirectoryLookup.h +++ b/clang/include/clang/Lex/DirectoryLookup.h @@ -50,17 +50,21 @@ class DirectoryLookup { /// DirCharacteristic - The type of directory this is: this is an instance of /// SrcMgr::CharacteristicKind. + LLVM_PREFERRED_TYPE(SrcMgr::CharacteristicKind) unsigned DirCharacteristic : 3; /// LookupType - This indicates whether this DirectoryLookup object is a /// normal directory, a framework, or a headermap. + LLVM_PREFERRED_TYPE(LookupType_t) unsigned LookupType : 2; /// Whether this is a header map used when building a framework. + LLVM_PREFERRED_TYPE(bool) unsigned IsIndexHeaderMap : 1; /// Whether we've performed an exhaustive search for module maps /// within the subdirectories of this directory. + LLVM_PREFERRED_TYPE(bool) unsigned SearchedAllModuleMaps : 1; public: diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index a212eea7cfd0cb9..a100598c80155fa 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -59,29 +59,36 @@ struct HeaderFileInfo { // TODO: Whether the file was imported is not a property of the file itself. // It's a preprocessor state, move it there. /// True if this is a \#import'd file. + LLVM_PREFERRED_TYPE(bool) unsigned isImport : 1; /// True if this is a \#pragma once file. + LLVM_PREFERRED_TYPE(bool) unsigned isPragmaOnce : 1; /// Keep track of whether this is a system header, and if so, /// whether it is C++ clean or not. This can be set by the include paths or /// by \#pragma gcc system_header. This is an instance of /// SrcMgr::CharacteristicKind. + LLVM_PREFERRED_TYPE(SrcMgr::CharacteristicKind) unsigned DirInfo : 3; /// Whether this header file info was supplied by an external source, /// and has not changed since. + LLVM_PREFERRED_TYPE(bool) unsigned External : 1; /// Whether this header is part of a module. + LLVM_PREFERRED_TYPE(bool) unsigned isModuleHeader : 1; /// Whether this header is part of the module that we are building. + LLVM_PREFERRED_TYPE(bool) unsigned isCompilingModuleHeader : 1; /// Whether this structure is considered to already have been /// "resolved", meaning that it was loaded from the external source. + LLVM_PREFERRED_TYPE(bool) unsigned Resolved : 1; /// Whether this is a header inside a framework that is currently @@ -91,9 +98,11 @@ struct HeaderFileInfo { /// into the appropriate framework subdirectories, and therefore are /// provided via a header map. This bit indicates when this is one of /// those framework headers. + LLVM_PREFERRED_TYPE(bool) unsigned IndexHeaderMapHeader : 1; /// Whether this file has been looked up as a header. + LLVM_PREFERRED_TYPE(bool) unsigned IsValid : 1; /// The ID number of the controlling macro. diff --git a/clang/include/clang/Lex/HeaderSearchOptions.h b/clang/include/clang/Lex/HeaderSearchOptions.h index 7f162efe4f0d4b3..114af14dec7f5a8 100644 --- a/clang/include/clang/Lex/HeaderSearchOptions.h +++ b/clang/include/clang/Lex/HeaderSearchOptions.h @@ -70,11 +70,13 @@ class HeaderSearchOptions { struct Entry { std::string Path; frontend::IncludeDirGroup Group; +LLVM_PREFERRED_TYPE(bool) unsigned IsFramework : 1; /// IgnoreSysRoot - This is false if an absolute path should be treated /// relative to the sysroot, or true if it should always be the absolute /// path. +LLVM_PREFERRED_TYPE(bool) unsigned IgnoreSysRoot : 1; Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework, @@ -128,10 +130,12 @@ class HeaderSearchOptions { /// module cache. /// /// Note: Only used for testing! + LLVM_PREFERRED_TYPE(bool) unsigned DisableModuleHash : 1; /// Implicit module maps. This option is enabld by default when /// modules is
[clang] acb714c - [clang][NFC] Annotate `DeclTemplate.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T10:35:53+03:00 New Revision: acb714c10126192a2ead8b7fd3d5e16e4653d656 URL: https://github.com/llvm/llvm-project/commit/acb714c10126192a2ead8b7fd3d5e16e4653d656 DIFF: https://github.com/llvm/llvm-project/commit/acb714c10126192a2ead8b7fd3d5e16e4653d656.diff LOG: [clang][NFC] Annotate `DeclTemplate.h` with `preferred_type` Added: Modified: clang/include/clang/AST/DeclTemplate.h Removed: diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 54d28227a4ae91b..832ad2de6b08a82 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -83,13 +83,16 @@ class TemplateParameterList final /// Whether this template parameter list contains an unexpanded parameter /// pack. + LLVM_PREFERRED_TYPE(bool) unsigned ContainsUnexpandedParameterPack : 1; /// Whether this template parameter list has a requires clause. + LLVM_PREFERRED_TYPE(bool) unsigned HasRequiresClause : 1; /// Whether any of the template parameters has constrained-parameter /// constraint-expression. + LLVM_PREFERRED_TYPE(bool) unsigned HasConstrainedParameters : 1; protected: @@ -1833,7 +1836,7 @@ class ClassTemplateSpecializationDecl SourceLocation PointOfInstantiation; /// The kind of specialization this declaration refers to. - /// Really a value of type TemplateSpecializationKind. + LLVM_PREFERRED_TYPE(TemplateSpecializationKind) unsigned SpecializationKind : 3; protected: @@ -2638,13 +2641,14 @@ class VarTemplateSpecializationDecl : public VarDecl, SourceLocation PointOfInstantiation; /// The kind of specialization this declaration refers to. - /// Really a value of type TemplateSpecializationKind. + LLVM_PREFERRED_TYPE(TemplateSpecializationKind) unsigned SpecializationKind : 3; /// Whether this declaration is a complete definition of the /// variable template specialization. We can't otherwise tell apart /// an instantiated declaration from an instantiated definition with /// no initializer. + LLVM_PREFERRED_TYPE(bool) unsigned IsCompleteDefinition : 1; protected: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ad27848 - [clang][NFC] Annotate `Decl.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T12:17:53+03:00 New Revision: ad278482095242cc20f5988c25381f4586fed589 URL: https://github.com/llvm/llvm-project/commit/ad278482095242cc20f5988c25381f4586fed589 DIFF: https://github.com/llvm/llvm-project/commit/ad278482095242cc20f5988c25381f4586fed589.diff LOG: [clang][NFC] Annotate `Decl.h` with `preferred_type` Added: Modified: clang/include/clang/AST/Decl.h Removed: diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 115b08802d9a298..cd0878d7082514c 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -75,6 +75,7 @@ class TemplateParameterList; class TypeAliasTemplateDecl; class UnresolvedSetImpl; class VarTemplateDecl; +enum class ImplicitParamKind; /// The top declaration context. class TranslationUnitDecl : public Decl, @@ -969,12 +970,16 @@ class VarDecl : public DeclaratorDecl, public Redeclarable { friend class ASTDeclReader; friend class VarDecl; +LLVM_PREFERRED_TYPE(StorageClass) unsigned SClass : 3; +LLVM_PREFERRED_TYPE(ThreadStorageClassSpecifier) unsigned TSCSpec : 2; +LLVM_PREFERRED_TYPE(InitializationStyle) unsigned InitStyle : 2; /// Whether this variable is an ARC pseudo-__strong variable; see /// isARCPseudoStrong() for details. +LLVM_PREFERRED_TYPE(bool) unsigned ARCPseudoStrong : 1; }; enum { NumVarDeclBits = 8 }; @@ -995,22 +1000,27 @@ class VarDecl : public DeclaratorDecl, public Redeclarable { friend class ASTDeclReader; friend class ParmVarDecl; +LLVM_PREFERRED_TYPE(VarDeclBitfields) unsigned : NumVarDeclBits; /// Whether this parameter inherits a default argument from a /// prior declaration. +LLVM_PREFERRED_TYPE(bool) unsigned HasInheritedDefaultArg : 1; /// Describes the kind of default argument for this parameter. By default /// this is none. If this is normal, then the default argument is stored in /// the \c VarDecl initializer expression unless we were unable to parse /// (even an invalid) expression for the default argument. +LLVM_PREFERRED_TYPE(DefaultArgKind) unsigned DefaultArgKind : 2; /// Whether this parameter undergoes K argument promotion. +LLVM_PREFERRED_TYPE(bool) unsigned IsKNRPromoted : 1; /// Whether this parameter is an ObjC method parameter or not. +LLVM_PREFERRED_TYPE(bool) unsigned IsObjCMethodParam : 1; /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier. @@ -1029,51 +1039,64 @@ class VarDecl : public DeclaratorDecl, public Redeclarable { friend class ImplicitParamDecl; friend class VarDecl; +LLVM_PREFERRED_TYPE(VarDeclBitfields) unsigned : NumVarDeclBits; // FIXME: We need something similar to CXXRecordDecl::DefinitionData. /// Whether this variable is a definition which was demoted due to /// module merge. +LLVM_PREFERRED_TYPE(bool) unsigned IsThisDeclarationADemotedDefinition : 1; /// Whether this variable is the exception variable in a C++ catch /// or an Objective-C @catch statement. +LLVM_PREFERRED_TYPE(bool) unsigned ExceptionVar : 1; /// Whether this local variable could be allocated in the return /// slot of its function, enabling the named return value optimization /// (NRVO). +LLVM_PREFERRED_TYPE(bool) unsigned NRVOVariable : 1; /// Whether this variable is the for-range-declaration in a C++0x /// for-range statement. +LLVM_PREFERRED_TYPE(bool) unsigned CXXForRangeDecl : 1; /// Whether this variable is the for-in loop declaration in Objective-C. +LLVM_PREFERRED_TYPE(bool) unsigned ObjCForDecl : 1; /// Whether this variable is (C++1z) inline. +LLVM_PREFERRED_TYPE(bool) unsigned IsInline : 1; /// Whether this variable has (C++1z) inline explicitly specified. +LLVM_PREFERRED_TYPE(bool) unsigned IsInlineSpecified : 1; /// Whether this variable is (C++0x) constexpr. +LLVM_PREFERRED_TYPE(bool) unsigned IsConstexpr : 1; /// Whether this variable is the implicit variable for a lambda /// init-capture. +LLVM_PREFERRED_TYPE(bool) unsigned IsInitCapture : 1; /// Whether this local extern variable's previous declaration was /// declared in the same block scope. This controls whether we should merge /// the type of this declaration with its previous declaration. +LLVM_PREFERRED_TYPE(bool) unsigned PreviousDeclInSameBlockScope : 1; /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or /// something else. +LLVM_PREFERRED_TYPE(ImplicitParamKind) unsigned ImplicitParamKind : 3; +LLVM_PREFERRED_TYPE(bool) unsigned EscapingByref : 1; }; @@ -3013,8 +3036,11 @@ class FieldDecl : public
[clang] b89aadf - [clang][NFC] Annotate `TemplateName.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T09:35:57+03:00 New Revision: b89aadf084feb025c2625f7bf7e206d666035ab1 URL: https://github.com/llvm/llvm-project/commit/b89aadf084feb025c2625f7bf7e206d666035ab1 DIFF: https://github.com/llvm/llvm-project/commit/b89aadf084feb025c2625f7bf7e206d666035ab1.diff LOG: [clang][NFC] Annotate `TemplateName.h` with `preferred_type` Added: Modified: clang/include/clang/AST/TemplateName.h Removed: diff --git a/clang/include/clang/AST/TemplateName.h b/clang/include/clang/AST/TemplateName.h index d56361b50059637..b7732e54ba1079f 100644 --- a/clang/include/clang/AST/TemplateName.h +++ b/clang/include/clang/AST/TemplateName.h @@ -55,7 +55,7 @@ class UncommonTemplateNameStorage { }; struct BitsTag { -/// A Kind. +LLVM_PREFERRED_TYPE(Kind) unsigned Kind : 2; // The template parameter index. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 17db462 - [clang][NFC] Annotate `TemplateBase.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T09:46:41+03:00 New Revision: 17db462810436e6cb5c422208d0d7718a8adb168 URL: https://github.com/llvm/llvm-project/commit/17db462810436e6cb5c422208d0d7718a8adb168 DIFF: https://github.com/llvm/llvm-project/commit/17db462810436e6cb5c422208d0d7718a8adb168.diff LOG: [clang][NFC] Annotate `TemplateBase.h` with `preferred_type` Added: Modified: clang/include/clang/AST/TemplateBase.h Removed: diff --git a/clang/include/clang/AST/TemplateBase.h b/clang/include/clang/AST/TemplateBase.h index 8e6b4d819740642..b7cd71f17c9442c 100644 --- a/clang/include/clang/AST/TemplateBase.h +++ b/clang/include/clang/AST/TemplateBase.h @@ -103,18 +103,23 @@ class TemplateArgument { /// The kind of template argument we're storing. struct DA { +LLVM_PREFERRED_TYPE(ArgKind) unsigned Kind : 31; +LLVM_PREFERRED_TYPE(bool) unsigned IsDefaulted : 1; void *QT; ValueDecl *D; }; struct I { +LLVM_PREFERRED_TYPE(ArgKind) unsigned Kind : 31; +LLVM_PREFERRED_TYPE(bool) unsigned IsDefaulted : 1; // We store a decomposed APSInt with the data allocated by ASTContext if // BitWidth > 64. The memory may be shared between multiple // TemplateArgument instances. unsigned BitWidth : 31; +LLVM_PREFERRED_TYPE(bool) unsigned IsUnsigned : 1; union { /// Used to store the <= 64 bits integer value. @@ -126,19 +131,25 @@ class TemplateArgument { void *Type; }; struct A { +LLVM_PREFERRED_TYPE(ArgKind) unsigned Kind : 31; +LLVM_PREFERRED_TYPE(bool) unsigned IsDefaulted : 1; unsigned NumArgs; const TemplateArgument *Args; }; struct TA { +LLVM_PREFERRED_TYPE(ArgKind) unsigned Kind : 31; +LLVM_PREFERRED_TYPE(bool) unsigned IsDefaulted : 1; unsigned NumExpansions; void *Name; }; struct TV { +LLVM_PREFERRED_TYPE(ArgKind) unsigned Kind : 31; +LLVM_PREFERRED_TYPE(bool) unsigned IsDefaulted : 1; uintptr_t V; }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 24faf3b - [clang][NFC] Annotate `Attr.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T09:58:02+03:00 New Revision: 24faf3b0b8e9b68304d9dd87c63afd5a0e813daa URL: https://github.com/llvm/llvm-project/commit/24faf3b0b8e9b68304d9dd87c63afd5a0e813daa DIFF: https://github.com/llvm/llvm-project/commit/24faf3b0b8e9b68304d9dd87c63afd5a0e813daa.diff LOG: [clang][NFC] Annotate `Attr.h` with `preferred_type` Added: Modified: clang/include/clang/AST/Attr.h Removed: diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h index 8884bd5a90de198..1b831c9511e2720 100644 --- a/clang/include/clang/AST/Attr.h +++ b/clang/include/clang/AST/Attr.h @@ -40,17 +40,23 @@ class OMPTraitInfo; /// Attr - This represents one attribute. class Attr : public AttributeCommonInfo { private: + LLVM_PREFERRED_TYPE(attr::Kind) unsigned AttrKind : 16; protected: /// An index into the spelling list of an /// attribute defined in Attr.td file. + LLVM_PREFERRED_TYPE(bool) unsigned Inherited : 1; + LLVM_PREFERRED_TYPE(bool) unsigned IsPackExpansion : 1; + LLVM_PREFERRED_TYPE(bool) unsigned Implicit : 1; // FIXME: These are properties of the attribute kind, not state for this // instance of the attribute. + LLVM_PREFERRED_TYPE(bool) unsigned IsLateParsed : 1; + LLVM_PREFERRED_TYPE(bool) unsigned InheritEvenIfAlreadyPresent : 1; void *operator new(size_t bytes) noexcept { @@ -243,7 +249,9 @@ class ParameterABIAttr : public InheritableParamAttr { class ParamIdx { // Idx is exposed only via accessors that specify specific encodings. unsigned Idx : 30; + LLVM_PREFERRED_TYPE(bool) unsigned HasThis : 1; + LLVM_PREFERRED_TYPE(bool) unsigned IsValid : 1; void assertComparable(const ParamIdx ) const { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 13023ed - [clang][NFC] Annotate `DeclFriend.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T10:18:30+03:00 New Revision: 13023ed1d606a6e4a7c2590e1b698593bc317a61 URL: https://github.com/llvm/llvm-project/commit/13023ed1d606a6e4a7c2590e1b698593bc317a61 DIFF: https://github.com/llvm/llvm-project/commit/13023ed1d606a6e4a7c2590e1b698593bc317a61.diff LOG: [clang][NFC] Annotate `DeclFriend.h` with `preferred_type` Added: Modified: clang/include/clang/AST/DeclFriend.h Removed: diff --git a/clang/include/clang/AST/DeclFriend.h b/clang/include/clang/AST/DeclFriend.h index 52efbb13063188d..3e6ca5b3219259e 100644 --- a/clang/include/clang/AST/DeclFriend.h +++ b/clang/include/clang/AST/DeclFriend.h @@ -73,6 +73,7 @@ class FriendDecl final /// True if this 'friend' declaration is unsupported. Eventually we /// will support every possible friend declaration, but for now we /// silently ignore some and set this flag to authorize all access. + LLVM_PREFERRED_TYPE(bool) unsigned UnsupportedFriend : 1; // The number of "outer" template parameter lists in non-templatic ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] a0029a8 - [clang][NFC] Annotate `Sema.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T11:03:23+03:00 New Revision: a0029a8a765f2bfe938de2c34ffb0264724ca04a URL: https://github.com/llvm/llvm-project/commit/a0029a8a765f2bfe938de2c34ffb0264724ca04a DIFF: https://github.com/llvm/llvm-project/commit/a0029a8a765f2bfe938de2c34ffb0264724ca04a.diff LOG: [clang][NFC] Annotate `Sema.h` with `preferred_type` Added: Modified: clang/include/clang/Sema/Sema.h Removed: diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 831972495d38ff0..a8c41492b61ac4c 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -14030,7 +14030,9 @@ class Sema final { /// If true, \c Type should be compared with other expression's types for /// layout-compatibility. +LLVM_PREFERRED_TYPE(bool) unsigned LayoutCompatible : 1; +LLVM_PREFERRED_TYPE(bool) unsigned MustBeNull : 1; }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] dda8e3d - [clang][NFC] Refactor `ImplicitParamDecl::ImplicitParamKind`
Author: Vlad Serebrennikov Date: 2023-11-06T12:01:09+03:00 New Revision: dda8e3de35ead65498094e75adf6f6efd2641323 URL: https://github.com/llvm/llvm-project/commit/dda8e3de35ead65498094e75adf6f6efd2641323 DIFF: https://github.com/llvm/llvm-project/commit/dda8e3de35ead65498094e75adf6f6efd2641323.diff LOG: [clang][NFC] Refactor `ImplicitParamDecl::ImplicitParamKind` This patch converts `ImplicitParamDecl::ImplicitParamKind` into a scoped enum at namespace scope, making it eligible for forward declaring. This is useful for `preferred_type` annotations on bit-fields. Added: Modified: clang/include/clang/AST/Decl.h clang/lib/AST/DeclObjC.cpp clang/lib/AST/ODRHash.cpp clang/lib/AST/StmtPrinter.cpp clang/lib/CodeGen/CGBlocks.cpp clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGCXXABI.cpp clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CGDeclCXX.cpp clang/lib/CodeGen/CGException.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGNonTrivialStruct.cpp clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp clang/lib/CodeGen/CGStmtOpenMP.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp clang/lib/Sema/SemaStmt.cpp clang/lib/Serialization/ASTWriterDecl.cpp clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Removed: diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index d8495f2c34940c5..115b08802d9a298 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -1654,36 +1654,36 @@ class VarDecl : public DeclaratorDecl, public Redeclarable { static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; } }; -class ImplicitParamDecl : public VarDecl { - void anchor() override; +/// Defines the kind of the implicit parameter: is this an implicit parameter +/// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured +/// context or something else. +enum class ImplicitParamKind { + /// Parameter for Objective-C 'self' argument + ObjCSelf, -public: - /// Defines the kind of the implicit parameter: is this an implicit parameter - /// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured - /// context or something else. - enum ImplicitParamKind : unsigned { -/// Parameter for Objective-C 'self' argument -ObjCSelf, + /// Parameter for Objective-C '_cmd' argument + ObjCCmd, -/// Parameter for Objective-C '_cmd' argument -ObjCCmd, + /// Parameter for C++ 'this' argument + CXXThis, -/// Parameter for C++ 'this' argument -CXXThis, + /// Parameter for C++ virtual table pointers + CXXVTT, -/// Parameter for C++ virtual table pointers -CXXVTT, + /// Parameter for captured context + CapturedContext, -/// Parameter for captured context -CapturedContext, + /// Parameter for Thread private variable + ThreadPrivateVar, -/// Parameter for Thread private variable -ThreadPrivateVar, + /// Other implicit parameter + Other, +}; -/// Other implicit parameter -Other, - }; +class ImplicitParamDecl : public VarDecl { + void anchor() override; +public: /// Create implicit parameter. static ImplicitParamDecl *Create(ASTContext , DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, @@ -1698,7 +1698,7 @@ class ImplicitParamDecl : public VarDecl { ImplicitParamKind ParamKind) : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type, /*TInfo=*/nullptr, SC_None) { -NonParmVarDeclBits.ImplicitParamKind = ParamKind; +NonParmVarDeclBits.ImplicitParamKind = llvm::to_underlying(ParamKind); setImplicit(); } @@ -1706,7 +1706,7 @@ class ImplicitParamDecl : public VarDecl { : VarDecl(ImplicitParam, C, /*DC=*/nullptr, SourceLocation(), SourceLocation(), /*Id=*/nullptr, Type, /*TInfo=*/nullptr, SC_None) { -NonParmVarDeclBits.ImplicitParamKind = ParamKind; +NonParmVarDeclBits.ImplicitParamKind = llvm::to_underlying(ParamKind); setImplicit(); } diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 2c88d05dc07ea9a..962f503306a0f0d 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -1194,7 +1194,7 @@ void ObjCMethodDecl::createImplicitParams(ASTContext , getSelfType(Context, OID, selfIsPseudoStrong, selfIsConsumed); auto *Self = ImplicitParamDecl::Create(Context, this, SourceLocation(), ("self"), selfTy, - ImplicitParamDecl::ObjCSelf); + ImplicitParamKind::ObjCSelf); setSelfDecl(Self); if (selfIsConsumed)
[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/71322 >From 40d25b8009f1c8734a99fd1350adaced6884cc7f Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Sun, 5 Nov 2023 18:53:48 +0300 Subject: [PATCH 1/3] [clang][NFC] Refacator `CXXNewExpr::InitializationStyle` This patch converts `CXXNewExpr::InitializationStyle` into a scoped enum at namespace scope. It also affirms the status quo by adding a new enumerator to represent implicit initializer. --- .../modernize/MakeSmartPtrCheck.cpp | 7 +-- clang/include/clang/AST/ExprCXX.h | 48 +++ clang/lib/AST/ExprCXX.cpp | 12 ++--- clang/lib/AST/ItaniumMangle.cpp | 4 +- clang/lib/AST/JSONNodeDumper.cpp | 7 +-- clang/lib/AST/StmtPrinter.cpp | 6 +-- clang/lib/AST/StmtProfile.cpp | 2 +- clang/lib/Sema/SemaExprCXX.cpp| 22 - 8 files changed, 58 insertions(+), 50 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp index 71fd8eca300c1b2..616e57efa76ded5 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -323,7 +323,8 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , return false; }; switch (New->getInitializationStyle()) { - case CXXNewExpr::NoInit: { + case CXXNewInitializationStyle::None: + case CXXNewInitializationStyle::Implicit: { if (ArraySizeExpr.empty()) { Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd)); } else { @@ -334,7 +335,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , } break; } - case CXXNewExpr::CallInit: { + case CXXNewInitializationStyle::Call: { // FIXME: Add fixes for constructors with parameters that can be created // with a C++11 braced-init-list (e.g. std::vector, std::map). // Unlike ordinal cases, braced list can not be deduced in @@ -371,7 +372,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , } break; } - case CXXNewExpr::ListInit: { + case CXXNewInitializationStyle::List: { // Range of the substring that we do not want to remove. SourceRange InitRange; if (const auto *NewConstruct = New->getConstructExpr()) { diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index a106bafcfa3e021..d713bcf8eb70258 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -2206,6 +2206,20 @@ class CXXScalarValueInitExpr : public Expr { } }; +enum class CXXNewInitializationStyle { + /// New-expression has no initializer as written. + None, + + /// New-expression has no written initializer, but has an implicit one. + Implicit, + + /// New-expression has a C++98 paren-delimited initializer. + Call, + + /// New-expression has a C++11 list-initializer. + List +}; + /// Represents a new-expression for memory allocation and constructor /// calls, e.g: "new CXXNewExpr(foo)". class CXXNewExpr final @@ -2259,25 +2273,12 @@ class CXXNewExpr final return isParenTypeId(); } -public: - enum InitializationStyle { -/// New-expression has no initializer as written. -NoInit, - -/// New-expression has a C++98 paren-delimited initializer. -CallInit, - -/// New-expression has a C++11 list-initializer. -ListInit - }; - -private: /// Build a c++ new expression. CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs, SourceRange TypeIdParens, std::optional ArraySize, - InitializationStyle InitializationStyle, Expr *Initializer, + CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -2292,7 +2293,7 @@ class CXXNewExpr final FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs, SourceRange TypeIdParens, std::optional ArraySize, - InitializationStyle InitializationStyle, Expr *Initializer, + CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -2388,15 +2389,20 @@ class CXXNewExpr final /// Whether this new-expression has any initializer at all. bool hasInitializer() const { -return CXXNewExprBits.StoredInitializationStyle > 0; +switch(getInitializationStyle()) { +case CXXNewInitializationStyle::None: + return true; +case CXXNewInitializationStyle::Implicit: +case
[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/71322 >From 40d25b8009f1c8734a99fd1350adaced6884cc7f Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Sun, 5 Nov 2023 18:53:48 +0300 Subject: [PATCH 1/5] [clang][NFC] Refacator `CXXNewExpr::InitializationStyle` This patch converts `CXXNewExpr::InitializationStyle` into a scoped enum at namespace scope. It also affirms the status quo by adding a new enumerator to represent implicit initializer. --- .../modernize/MakeSmartPtrCheck.cpp | 7 +-- clang/include/clang/AST/ExprCXX.h | 48 +++ clang/lib/AST/ExprCXX.cpp | 12 ++--- clang/lib/AST/ItaniumMangle.cpp | 4 +- clang/lib/AST/JSONNodeDumper.cpp | 7 +-- clang/lib/AST/StmtPrinter.cpp | 6 +-- clang/lib/AST/StmtProfile.cpp | 2 +- clang/lib/Sema/SemaExprCXX.cpp| 22 - 8 files changed, 58 insertions(+), 50 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp index 71fd8eca300c1b2..616e57efa76ded5 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -323,7 +323,8 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , return false; }; switch (New->getInitializationStyle()) { - case CXXNewExpr::NoInit: { + case CXXNewInitializationStyle::None: + case CXXNewInitializationStyle::Implicit: { if (ArraySizeExpr.empty()) { Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd)); } else { @@ -334,7 +335,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , } break; } - case CXXNewExpr::CallInit: { + case CXXNewInitializationStyle::Call: { // FIXME: Add fixes for constructors with parameters that can be created // with a C++11 braced-init-list (e.g. std::vector, std::map). // Unlike ordinal cases, braced list can not be deduced in @@ -371,7 +372,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , } break; } - case CXXNewExpr::ListInit: { + case CXXNewInitializationStyle::List: { // Range of the substring that we do not want to remove. SourceRange InitRange; if (const auto *NewConstruct = New->getConstructExpr()) { diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index a106bafcfa3e021..d713bcf8eb70258 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -2206,6 +2206,20 @@ class CXXScalarValueInitExpr : public Expr { } }; +enum class CXXNewInitializationStyle { + /// New-expression has no initializer as written. + None, + + /// New-expression has no written initializer, but has an implicit one. + Implicit, + + /// New-expression has a C++98 paren-delimited initializer. + Call, + + /// New-expression has a C++11 list-initializer. + List +}; + /// Represents a new-expression for memory allocation and constructor /// calls, e.g: "new CXXNewExpr(foo)". class CXXNewExpr final @@ -2259,25 +2273,12 @@ class CXXNewExpr final return isParenTypeId(); } -public: - enum InitializationStyle { -/// New-expression has no initializer as written. -NoInit, - -/// New-expression has a C++98 paren-delimited initializer. -CallInit, - -/// New-expression has a C++11 list-initializer. -ListInit - }; - -private: /// Build a c++ new expression. CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs, SourceRange TypeIdParens, std::optional ArraySize, - InitializationStyle InitializationStyle, Expr *Initializer, + CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -2292,7 +2293,7 @@ class CXXNewExpr final FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs, SourceRange TypeIdParens, std::optional ArraySize, - InitializationStyle InitializationStyle, Expr *Initializer, + CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -2388,15 +2389,20 @@ class CXXNewExpr final /// Whether this new-expression has any initializer at all. bool hasInitializer() const { -return CXXNewExprBits.StoredInitializationStyle > 0; +switch(getInitializationStyle()) { +case CXXNewInitializationStyle::None: + return true; +case CXXNewInitializationStyle::Implicit: +case
[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)
@@ -2008,22 +2008,23 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal, SourceRange TypeRange = AllocTypeInfo->getTypeLoc().getSourceRange(); SourceLocation StartLoc = Range.getBegin(); - CXXNewExpr::InitializationStyle initStyle; + CXXNewInitializationStyle initStyle; Endilll wrote: Done! https://github.com/llvm/llvm-project/pull/71322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b178cec - [clang][NFC] Annotate most of `clang/Basic` headers with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T14:18:26+03:00 New Revision: b178cec84f95210db615cfa0a84e78585445f16b URL: https://github.com/llvm/llvm-project/commit/b178cec84f95210db615cfa0a84e78585445f16b DIFF: https://github.com/llvm/llvm-project/commit/b178cec84f95210db615cfa0a84e78585445f16b.diff LOG: [clang][NFC] Annotate most of `clang/Basic` headers with `preferred_type` This patch doesn't touch `CodeGenOptions.h`, `DiagnosticOptions.h`, `LangOptions.h`, `IdentifierTable.h`. Added: Modified: clang/include/clang/Basic/AttributeCommonInfo.h clang/include/clang/Basic/Diagnostic.h clang/include/clang/Basic/DiagnosticIDs.h clang/include/clang/Basic/Module.h clang/include/clang/Basic/ParsedAttrInfo.h clang/include/clang/Basic/SourceManager.h clang/include/clang/Basic/Specifiers.h clang/include/clang/Basic/TargetInfo.h Removed: diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index 7dc05418498d0ae..908e0c71544279c 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -74,11 +74,16 @@ class AttributeCommonInfo { SourceRange AttrRange; const SourceLocation ScopeLoc; // Corresponds to the Kind enum. + LLVM_PREFERRED_TYPE(Kind) unsigned AttrKind : 16; /// Corresponds to the Syntax enum. + LLVM_PREFERRED_TYPE(Syntax) unsigned SyntaxUsed : 4; + LLVM_PREFERRED_TYPE(bool) unsigned SpellingIndex : 4; + LLVM_PREFERRED_TYPE(bool) unsigned IsAlignas : 1; + LLVM_PREFERRED_TYPE(bool) unsigned IsRegularKeywordAttribute : 1; protected: @@ -123,9 +128,12 @@ class AttributeCommonInfo { : SyntaxUsed(SyntaxUsed), SpellingIndex(SpellingNotCalculated), IsAlignas(0), IsRegularKeywordAttribute(0) {} +LLVM_PREFERRED_TYPE(Syntax) unsigned SyntaxUsed : 4; unsigned SpellingIndex : 4; +LLVM_PREFERRED_TYPE(bool) unsigned IsAlignas : 1; +LLVM_PREFERRED_TYPE(bool) unsigned IsRegularKeywordAttribute : 1; }; diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h index 3df037b793b3946..0c7836c2ea569cc 100644 --- a/clang/include/clang/Basic/Diagnostic.h +++ b/clang/include/clang/Basic/Diagnostic.h @@ -314,18 +314,23 @@ class DiagnosticsEngine : public RefCountedBase { // "Global" configuration state that can actually vary between modules. // Ignore all warnings: -w +LLVM_PREFERRED_TYPE(bool) unsigned IgnoreAllWarnings : 1; // Enable all warnings. +LLVM_PREFERRED_TYPE(bool) unsigned EnableAllWarnings : 1; // Treat warnings like errors. +LLVM_PREFERRED_TYPE(bool) unsigned WarningsAsErrors : 1; // Treat errors like fatal errors. +LLVM_PREFERRED_TYPE(bool) unsigned ErrorsAsFatal : 1; // Suppress warnings in system headers. +LLVM_PREFERRED_TYPE(bool) unsigned SuppressSystemWarnings : 1; // Map extensions to warnings or errors? @@ -1822,12 +1827,17 @@ class ForwardingDiagnosticConsumer : public DiagnosticConsumer { struct TemplateDiffTypes { intptr_t FromType; intptr_t ToType; + LLVM_PREFERRED_TYPE(bool) unsigned PrintTree : 1; + LLVM_PREFERRED_TYPE(bool) unsigned PrintFromType : 1; + LLVM_PREFERRED_TYPE(bool) unsigned ElideType : 1; + LLVM_PREFERRED_TYPE(bool) unsigned ShowColors : 1; // The printer sets this variable to true if the template diff was used. + LLVM_PREFERRED_TYPE(bool) unsigned TemplateDiffUsed : 1; }; diff --git a/clang/include/clang/Basic/DiagnosticIDs.h b/clang/include/clang/Basic/DiagnosticIDs.h index 06ef1c6904c31d1..0cdda42793f6f0a 100644 --- a/clang/include/clang/Basic/DiagnosticIDs.h +++ b/clang/include/clang/Basic/DiagnosticIDs.h @@ -100,11 +100,17 @@ namespace clang { } class DiagnosticMapping { + LLVM_PREFERRED_TYPE(diag::Severity) unsigned Severity : 3; + LLVM_PREFERRED_TYPE(bool) unsigned IsUser : 1; + LLVM_PREFERRED_TYPE(bool) unsigned IsPragma : 1; + LLVM_PREFERRED_TYPE(bool) unsigned HasNoWarningAsError : 1; + LLVM_PREFERRED_TYPE(bool) unsigned HasNoErrorAsFatal : 1; + LLVM_PREFERRED_TYPE(bool) unsigned WasUpgradedFromWarning : 1; public: diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h index 6a7423938bdb8fa..239eb5a637f3ecf 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -298,50 +298,62 @@ class alignas(8) Module { /// Whether this module has declared itself unimportable, either because /// it's missing a requirement from \p Requirements or because it's been /// shadowed by another module. + LLVM_PREFERRED_TYPE(bool) unsigned IsUnimportable : 1; /// Whether we tried and failed to load a module file for this module. + LLVM_PREFERRED_TYPE(bool) unsigned
[clang] 1a0e743 - [clang][NFC] Annotate `clang/Frontend` headers with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T13:38:12+03:00 New Revision: 1a0e743ab01716ecafeb33858d9975cf90017c59 URL: https://github.com/llvm/llvm-project/commit/1a0e743ab01716ecafeb33858d9975cf90017c59 DIFF: https://github.com/llvm/llvm-project/commit/1a0e743ab01716ecafeb33858d9975cf90017c59.diff LOG: [clang][NFC] Annotate `clang/Frontend` headers with `preferred_type` Added: Modified: clang/include/clang/Frontend/ASTUnit.h clang/include/clang/Frontend/DependencyOutputOptions.h clang/include/clang/Frontend/FrontendOptions.h clang/include/clang/Frontend/MigratorOptions.h clang/include/clang/Frontend/PreprocessorOutputOptions.h clang/include/clang/Frontend/TextDiagnosticPrinter.h Removed: diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index c6d0d4d7e90233e..bcb28634a2b8841 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -355,6 +355,7 @@ class ASTUnit { /// Bit used by CIndex to mark when a translation unit may be in an /// inconsistent state, and is not safe to free. + LLVM_PREFERRED_TYPE(bool) unsigned UnsafeToFree : 1; /// \brief Enumerator specifying the scope for skipping function bodies. diff --git a/clang/include/clang/Frontend/DependencyOutputOptions.h b/clang/include/clang/Frontend/DependencyOutputOptions.h index e4b26d92647d0a7..558d8a0a0ab693b 100644 --- a/clang/include/clang/Frontend/DependencyOutputOptions.h +++ b/clang/include/clang/Frontend/DependencyOutputOptions.h @@ -33,15 +33,22 @@ enum ExtraDepKind { /// file generation. class DependencyOutputOptions { public: + LLVM_PREFERRED_TYPE(bool) unsigned IncludeSystemHeaders : 1; ///< Include system header dependencies. + LLVM_PREFERRED_TYPE(bool) unsigned CanonicalSystemHeaders : 1; ///< canonicalize system header dependencies. + LLVM_PREFERRED_TYPE(bool) unsigned ShowHeaderIncludes : 1; ///< Show header inclusions (-H). + LLVM_PREFERRED_TYPE(bool) unsigned UsePhonyTargets : 1; ///< Include phony targets for each /// dependency, which can avoid some 'make' /// problems. + LLVM_PREFERRED_TYPE(bool) unsigned AddMissingHeaderDeps : 1; ///< Add missing headers to dependency list + LLVM_PREFERRED_TYPE(bool) unsigned IncludeModuleFiles : 1; ///< Include module file dependencies. + LLVM_PREFERRED_TYPE(bool) unsigned ShowSkippedHeaderIncludes : 1; ///< With ShowHeaderIncludes, show /// also includes that were skipped /// due to the "include guard diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h index 117e35de6f76c4c..53a8681cfdbba04 100644 --- a/clang/include/clang/Frontend/FrontendOptions.h +++ b/clang/include/clang/Frontend/FrontendOptions.h @@ -147,13 +147,6 @@ enum ActionKind { /// The kind of a file that we've been handed as an input. class InputKind { -private: - Language Lang; - unsigned Fmt : 3; - unsigned Preprocessed : 1; - unsigned HeaderUnit : 3; - unsigned IsHeader : 1; - public: /// The input file format. enum Format { @@ -172,6 +165,18 @@ class InputKind { HeaderUnit_Abs }; +private: + Language Lang; + LLVM_PREFERRED_TYPE(Format) + unsigned Fmt : 3; + LLVM_PREFERRED_TYPE(bool) + unsigned Preprocessed : 1; + LLVM_PREFERRED_TYPE(HeaderUnitKind) + unsigned HeaderUnit : 3; + LLVM_PREFERRED_TYPE(bool) + unsigned IsHeader : 1; + +public: constexpr InputKind(Language L = Language::Unknown, Format F = Source, bool PP = false, HeaderUnitKind HU = HeaderUnit_None, bool HD = false) @@ -266,88 +271,116 @@ class FrontendInputFile { class FrontendOptions { public: /// Disable memory freeing on exit. + LLVM_PREFERRED_TYPE(bool) unsigned DisableFree : 1; /// When generating PCH files, instruct the AST writer to create relocatable /// PCH files. + LLVM_PREFERRED_TYPE(bool) unsigned RelocatablePCH : 1; /// Show the -help text. + LLVM_PREFERRED_TYPE(bool) unsigned ShowHelp : 1; /// Show frontend performance metrics and statistics. + LLVM_PREFERRED_TYPE(bool) unsigned ShowStats : 1; + LLVM_PREFERRED_TYPE(bool) unsigned AppendStats : 1; /// print the supported cpus for the current target + LLVM_PREFERRED_TYPE(bool) unsigned PrintSupportedCPUs : 1; /// Print the supported extensions for the current target. + LLVM_PREFERRED_TYPE(bool) unsigned PrintSupportedExtensions : 1; /// Show the -version text. + LLVM_PREFERRED_TYPE(bool) unsigned ShowVersion : 1; /// Apply fixes even if there are unfixable errors. + LLVM_PREFERRED_TYPE(bool) unsigned FixWhatYouCan : 1; /// Apply fixes only
[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)
@@ -2034,18 +2035,19 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal, // - If the new-initializer is omitted, the object is default- // initialized (8.5); if no initialization is performed, // the object has indeterminate value - = initStyle == CXXNewExpr::NoInit + = initStyle == CXXNewInitializationStyle::None || +initStyle == CXXNewInitializationStyle::Implicit ? InitializationKind::CreateDefault(TypeRange.getBegin()) -// - Otherwise, the new-initializer is interpreted according to -// the -// initialization rules of 8.5 for direct-initialization. -: initStyle == CXXNewExpr::ListInit - ? InitializationKind::CreateDirectList( -TypeRange.getBegin(), Initializer->getBeginLoc(), -Initializer->getEndLoc()) - : InitializationKind::CreateDirect(TypeRange.getBegin(), - DirectInitRange.getBegin(), - DirectInitRange.getEnd()); +// - Otherwise, the new-initializer is interpreted according to +// the +// initialization rules of 8.5 for direct-initialization. +: initStyle == CXXNewInitializationStyle::List +? InitializationKind::CreateDirectList(TypeRange.getBegin(), + Initializer->getBeginLoc(), + Initializer->getEndLoc()) +: InitializationKind::CreateDirect(TypeRange.getBegin(), + DirectInitRange.getBegin(), + DirectInitRange.getEnd()); Endilll wrote: Because `InitializationKind` doesn't have default constructor, I had to resort to immediately invoked lambda expression (IILE). I think it is an improvement, but I haven't seen IILE in Clang code base before, so I'm not sure. https://github.com/llvm/llvm-project/pull/71322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] Revert "[clang][NFC] Refactor `CXXNewExpr::InitializationStyle`" (PR #71395)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/71395 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] Revert "[clang][NFC] Refactor `CXXNewExpr::InitializationStyle`" (PR #71395)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/71395 Reverts llvm/llvm-project#71322 >From 40921a217a4bda5ce739561606a4e16677ee48f5 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Mon, 6 Nov 2023 17:53:21 +0400 Subject: [PATCH] Revert "[clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (#71322)" This reverts commit ace4489397d17abfb20d36de1404cfbe102401a7. --- .../modernize/MakeSmartPtrCheck.cpp | 7 +-- clang/include/clang/AST/ExprCXX.h | 48 +++ clang/lib/AST/ExprCXX.cpp | 29 + clang/lib/AST/ItaniumMangle.cpp | 5 +- clang/lib/AST/JSONNodeDumper.cpp | 12 +--- clang/lib/AST/StmtPrinter.cpp | 7 +-- clang/lib/AST/StmtProfile.cpp | 2 +- clang/lib/Sema/SemaExprCXX.cpp| 60 +-- 8 files changed, 74 insertions(+), 96 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp index 616e57efa76ded5..71fd8eca300c1b2 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -323,8 +323,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , return false; }; switch (New->getInitializationStyle()) { - case CXXNewInitializationStyle::None: - case CXXNewInitializationStyle::Implicit: { + case CXXNewExpr::NoInit: { if (ArraySizeExpr.empty()) { Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd)); } else { @@ -335,7 +334,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , } break; } - case CXXNewInitializationStyle::Call: { + case CXXNewExpr::CallInit: { // FIXME: Add fixes for constructors with parameters that can be created // with a C++11 braced-init-list (e.g. std::vector, std::map). // Unlike ordinal cases, braced list can not be deduced in @@ -372,7 +371,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , } break; } - case CXXNewInitializationStyle::List: { + case CXXNewExpr::ListInit: { // Range of the substring that we do not want to remove. SourceRange InitRange; if (const auto *NewConstruct = New->getConstructExpr()) { diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 37d310ef967d9c0..a106bafcfa3e021 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -2206,20 +2206,6 @@ class CXXScalarValueInitExpr : public Expr { } }; -enum class CXXNewInitializationStyle { - /// New-expression has no initializer as written. - None, - - /// New-expression has no written initializer, but has an implicit one. - Implicit, - - /// New-expression has a C++98 paren-delimited initializer. - Call, - - /// New-expression has a C++11 list-initializer. - List -}; - /// Represents a new-expression for memory allocation and constructor /// calls, e.g: "new CXXNewExpr(foo)". class CXXNewExpr final @@ -2273,12 +2259,25 @@ class CXXNewExpr final return isParenTypeId(); } +public: + enum InitializationStyle { +/// New-expression has no initializer as written. +NoInit, + +/// New-expression has a C++98 paren-delimited initializer. +CallInit, + +/// New-expression has a C++11 list-initializer. +ListInit + }; + +private: /// Build a c++ new expression. CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs, SourceRange TypeIdParens, std::optional ArraySize, - CXXNewInitializationStyle InitializationStyle, Expr *Initializer, + InitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -2293,7 +2292,7 @@ class CXXNewExpr final FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs, SourceRange TypeIdParens, std::optional ArraySize, - CXXNewInitializationStyle InitializationStyle, Expr *Initializer, + InitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -2389,20 +2388,15 @@ class CXXNewExpr final /// Whether this new-expression has any initializer at all. bool hasInitializer() const { -switch (getInitializationStyle()) { -case CXXNewInitializationStyle::None: - return false; -case CXXNewInitializationStyle::Implicit: -case CXXNewInitializationStyle::Call: -case CXXNewInitializationStyle::List: - return true; -} +return
[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)
https://github.com/Endilll ready_for_review https://github.com/llvm/llvm-project/pull/71322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/71322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)
Endilll wrote: I've seen those exact test failures locally, but since precommit CI was fine, I landed this PR and kept a close eye on the bots. Me and Aaron are also wondering now how did it pass CI, and what's wrong with changes here. I'm sorry @zmodem that we got you involved. > It catches > (https://buildkite.com/llvm-project/github-pull-requests/builds/12931#018ba4b7-1e05-425f-a30d-46ac33f582b6), > you just didn't wait for a results (or ignored them) and forced a merge. Me and Aaron seen them, and deemed them unrelated. For a comparison, here is a list of tests that fails locally for me (and post-commit bots seem to agree): ``` Failed Tests (49): Clang :: Analysis/NewDelete-checker-test.cpp Clang :: Analysis/bstring.cpp Clang :: Analysis/cfg.cpp Clang :: Analysis/ctor-array.cpp Clang :: Analysis/cxxctr-array-evalcall-analysis-order.cpp Clang :: Analysis/dtor-array.cpp Clang :: Analysis/dump_egraph.cpp Clang :: Analysis/exploded-graph-rewriter/dynamic_types.cpp Clang :: Analysis/flexible-array-member.cpp Clang :: Analysis/handle_constructors_with_new_array.cpp Clang :: Analysis/more-dtors-cfg-output.cpp Clang :: Analysis/new-ctor-conservative.cpp Clang :: Analysis/new-ctor-inlined.cpp Clang :: Analysis/this-pointer.cpp Clang :: CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp Clang :: CXX/drs/dr1748.cpp Clang :: CodeGen/available-externally-hidden.cpp Clang :: CodeGen/debug-prefix-map.cpp Clang :: CodeGen/split-lto-unit-input.cpp Clang :: CodeGen/tbaa-for-vptr.cpp Clang :: CodeGenCUDA/member-init.cu Clang :: CodeGenCXX/attr-disable-tail-calls.cpp Clang :: CodeGenCXX/catch-undef-behavior.cpp Clang :: CodeGenCXX/cfi-ms-vbase-derived-cast.cpp Clang :: CodeGenCXX/code-seg.cpp Clang :: CodeGenCXX/ctor-dtor-alias.cpp Clang :: CodeGenCXX/cxx1z-aligned-allocation.cpp Clang :: CodeGenCXX/cxx2a-destroying-delete.cpp Clang :: CodeGenCXX/default-arguments.cpp Clang :: CodeGenCXX/destructors.cpp Clang :: CodeGenCXX/exceptions.cpp Clang :: CodeGenCXX/invariant.group-for-vptrs.cpp Clang :: CodeGenCXX/key-function-vtable.cpp Clang :: CodeGenCXX/microsoft-abi-structors-delayed-template.cpp Clang :: CodeGenCXX/new-overflow.cpp Clang :: CodeGenCXX/new.cpp Clang :: CodeGenCXX/static-init.cpp Clang :: CodeGenCXX/strict-vtable-pointers.cpp Clang :: CodeGenCXX/type-metadata-thinlto.cpp Clang :: CodeGenCXX/ubsan-new-checks.cpp Clang :: CodeGenCXX/ubsan-suppress-checks.cpp Clang :: CodeGenCXX/vtable-assume-load-address-space.cpp Clang :: CodeGenCXX/vtable-assume-load.cpp Clang :: CodeGenCXX/vtable-available-externally.cpp Clang :: CodeGenObjCXX/arc-new-delete.mm Clang :: CodeGenObjCXX/destroy.mm Clang :: LibClang/symbols.test Clang :: SemaCXX/constant-expression-cxx2a.cpp Clang :: SemaCXX/constexpr-turing-cxx2a.cpp ``` https://github.com/llvm/llvm-project/pull/71322 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 565e21b - [clang][NFC] Refactor `InlineCommandComment::RenderKind`
Author: Vlad Serebrennikov Date: 2023-11-06T22:39:26+03:00 New Revision: 565e21b3e079e53c4fcf47d2ec898dbc248fbd3a URL: https://github.com/llvm/llvm-project/commit/565e21b3e079e53c4fcf47d2ec898dbc248fbd3a DIFF: https://github.com/llvm/llvm-project/commit/565e21b3e079e53c4fcf47d2ec898dbc248fbd3a.diff LOG: [clang][NFC] Refactor `InlineCommandComment::RenderKind` This patch converts `InlineCommandComment::RenderKind` to a scoped enum at namespace scope, making it eligible for forward declaring. This is useful for e.g. annotating bit-fields with `preferred_type`. Added: Modified: clang/include/clang/AST/Comment.h clang/include/clang/AST/CommentSema.h clang/lib/AST/CommentSema.cpp clang/lib/AST/JSONNodeDumper.cpp clang/lib/AST/TextNodeDumper.cpp clang/lib/Index/CommentToXML.cpp clang/tools/libclang/CXComment.cpp Removed: diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h index 7cbed3600d28287..06effad42db45e6 100644 --- a/clang/include/clang/AST/Comment.h +++ b/clang/include/clang/AST/Comment.h @@ -297,31 +297,24 @@ class TextComment : public InlineContentComment { bool isWhitespaceNoCache() const; }; +/// The most appropriate rendering mode for this command, chosen on command +/// semantics in Doxygen. +enum InlineCommandRenderKind { Normal, Bold, Monospaced, Emphasized, Anchor }; + /// A command with word-like arguments that is considered inline content. class InlineCommandComment : public InlineContentComment { -public: - /// The most appropriate rendering mode for this command, chosen on command - /// semantics in Doxygen. - enum RenderKind { -RenderNormal, -RenderBold, -RenderMonospaced, -RenderEmphasized, -RenderAnchor - }; - protected: /// Command arguments. ArrayRef Args; public: InlineCommandComment(SourceLocation LocBegin, SourceLocation LocEnd, - unsigned CommandID, RenderKind RK, + unsigned CommandID, InlineCommandRenderKind RK, ArrayRef Args) : InlineContentComment(CommentKind::InlineCommandComment, LocBegin, LocEnd), Args(Args) { -InlineCommandCommentBits.RenderKind = RK; +InlineCommandCommentBits.RenderKind = llvm::to_underlying(RK); InlineCommandCommentBits.CommandID = CommandID; } @@ -345,8 +338,9 @@ class InlineCommandComment : public InlineContentComment { return SourceRange(getBeginLoc().getLocWithOffset(-1), getEndLoc()); } - RenderKind getRenderKind() const { -return static_cast(InlineCommandCommentBits.RenderKind); + InlineCommandRenderKind getRenderKind() const { +return static_cast( +InlineCommandCommentBits.RenderKind); } unsigned getNumArgs() const { diff --git a/clang/include/clang/AST/CommentSema.h b/clang/include/clang/AST/CommentSema.h index 5d8df7dbf385a12..03f13283ac0d977 100644 --- a/clang/include/clang/AST/CommentSema.h +++ b/clang/include/clang/AST/CommentSema.h @@ -244,8 +244,7 @@ class Sema { StringRef Typo, const TemplateParameterList *TemplateParameters); - InlineCommandComment::RenderKind - getInlineCommandRenderKind(StringRef Name) const; + InlineCommandRenderKind getInlineCommandRenderKind(StringRef Name) const; }; } // end namespace comments diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp index 0512d6af5ce..6f68577954137f3 100644 --- a/clang/lib/AST/CommentSema.cpp +++ b/clang/lib/AST/CommentSema.cpp @@ -380,9 +380,7 @@ InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin, unsigned CommandID) { ArrayRef Args; return new (Allocator) InlineCommandComment( - LocBegin, LocEnd, CommandID, - InlineCommandComment::RenderNormal, - Args); + LocBegin, LocEnd, CommandID, InlineCommandRenderKind::Normal, Args); } TextComment *Sema::actOnText(SourceLocation LocBegin, @@ -1108,16 +1106,15 @@ StringRef Sema::correctTypoInTParamReference( return StringRef(); } -InlineCommandComment::RenderKind -Sema::getInlineCommandRenderKind(StringRef Name) const { +InlineCommandRenderKind Sema::getInlineCommandRenderKind(StringRef Name) const { assert(Traits.getCommandInfo(Name)->IsInlineCommand); - return llvm::StringSwitch(Name) - .Case("b", InlineCommandComment::RenderBold) - .Cases("c", "p", InlineCommandComment::RenderMonospaced) - .Cases("a", "e", "em", InlineCommandComment::RenderEmphasized) - .Case("anchor", InlineCommandComment::RenderAnchor) - .Default(InlineCommandComment::RenderNormal); + return llvm::StringSwitch(Name) + .Case("b", InlineCommandRenderKind::Bold) + .Cases("c",
[clang] f2d8a0a - [clang][NFC] Refactor `ParamCommandComment::PassDirection`
Author: Vlad Serebrennikov Date: 2023-11-06T22:55:51+03:00 New Revision: f2d8a0ac1dd1fe55b2c3b358c525fbc01b0121ed URL: https://github.com/llvm/llvm-project/commit/f2d8a0ac1dd1fe55b2c3b358c525fbc01b0121ed DIFF: https://github.com/llvm/llvm-project/commit/f2d8a0ac1dd1fe55b2c3b358c525fbc01b0121ed.diff LOG: [clang][NFC] Refactor `ParamCommandComment::PassDirection` This patch converts `ParamCommandComment::PassDirection` to a scoped enum at namespace scope, making it eligible for forward declaring. This is useful for e.g. annotating bit-fields with `preferred_type`. Added: Modified: clang/include/clang/AST/Comment.h clang/lib/AST/Comment.cpp clang/lib/AST/CommentSema.cpp clang/lib/AST/JSONNodeDumper.cpp clang/lib/Index/CommentToXML.cpp clang/tools/libclang/CXComment.cpp clang/unittests/AST/CommentParser.cpp Removed: diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h index 06effad42db45e6..d501ce1822862d9 100644 --- a/clang/include/clang/AST/Comment.h +++ b/clang/include/clang/AST/Comment.h @@ -675,6 +675,8 @@ class BlockCommandComment : public BlockContentComment { } }; +enum class ParamCommandPassDirection { In, Out, InOut }; + /// Doxygen \\param command. class ParamCommandComment : public BlockCommandComment { private: @@ -692,7 +694,8 @@ class ParamCommandComment : public BlockCommandComment { : BlockCommandComment(CommentKind::ParamCommandComment, LocBegin, LocEnd, CommandID, CommandMarker), ParamIndex(InvalidParamIndex) { -ParamCommandCommentBits.Direction = In; +ParamCommandCommentBits.Direction = +llvm::to_underlying(ParamCommandPassDirection::In); ParamCommandCommentBits.IsDirectionExplicit = false; } @@ -700,24 +703,19 @@ class ParamCommandComment : public BlockCommandComment { return C->getCommentKind() == CommentKind::ParamCommandComment; } - enum PassDirection { -In, -Out, -InOut - }; - - static const char *getDirectionAsString(PassDirection D); + static const char *getDirectionAsString(ParamCommandPassDirection D); - PassDirection getDirection() const LLVM_READONLY { -return static_cast(ParamCommandCommentBits.Direction); + ParamCommandPassDirection getDirection() const LLVM_READONLY { +return static_cast( +ParamCommandCommentBits.Direction); } bool isDirectionExplicit() const LLVM_READONLY { return ParamCommandCommentBits.IsDirectionExplicit; } - void setDirection(PassDirection Direction, bool Explicit) { -ParamCommandCommentBits.Direction = Direction; + void setDirection(ParamCommandPassDirection Direction, bool Explicit) { +ParamCommandCommentBits.Direction = llvm::to_underlying(Direction); ParamCommandCommentBits.IsDirectionExplicit = Explicit; } diff --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp index 0a2d310e5b48911..cce8b12170f21fd 100644 --- a/clang/lib/AST/Comment.cpp +++ b/clang/lib/AST/Comment.cpp @@ -187,13 +187,14 @@ static bool getFunctionTypeLoc(TypeLoc TL, FunctionTypeLoc ) { return false; } -const char *ParamCommandComment::getDirectionAsString(PassDirection D) { +const char * +ParamCommandComment::getDirectionAsString(ParamCommandPassDirection D) { switch (D) { - case ParamCommandComment::In: + case ParamCommandPassDirection::In: return "[in]"; - case ParamCommandComment::Out: + case ParamCommandPassDirection::Out: return "[out]"; - case ParamCommandComment::InOut: + case ParamCommandPassDirection::InOut: return "[in,out]"; } llvm_unreachable("unknown PassDirection"); diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp index 6f68577954137f3..bc01baa1d917b57 100644 --- a/clang/lib/AST/CommentSema.cpp +++ b/clang/lib/AST/CommentSema.cpp @@ -219,12 +219,12 @@ void Sema::checkContainerDecl(const BlockCommandComment *Comment) { /// Turn a string into the corresponding PassDirection or -1 if it's not /// valid. -static int getParamPassDirection(StringRef Arg) { - return llvm::StringSwitch(Arg) - .Case("[in]", ParamCommandComment::In) - .Case("[out]", ParamCommandComment::Out) - .Cases("[in,out]", "[out,in]", ParamCommandComment::InOut) - .Default(-1); +static ParamCommandPassDirection getParamPassDirection(StringRef Arg) { + return llvm::StringSwitch(Arg) + .Case("[in]", ParamCommandPassDirection::In) + .Case("[out]", ParamCommandPassDirection::Out) + .Cases("[in,out]", "[out,in]", ParamCommandPassDirection::InOut) + .Default(static_cast(-1)); } void Sema::actOnParamCommandDirectionArg(ParamCommandComment *Command, @@ -232,25 +232,25 @@ void Sema::actOnParamCommandDirectionArg(ParamCommandComment *Command, SourceLocation ArgLocEnd, StringRef
[clang] 088932d - [clang][NFC] Annotate `AST/Comment.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T23:08:39+03:00 New Revision: 088932d8ef1f80ba9e1349ce7cda95accd2f745e URL: https://github.com/llvm/llvm-project/commit/088932d8ef1f80ba9e1349ce7cda95accd2f745e DIFF: https://github.com/llvm/llvm-project/commit/088932d8ef1f80ba9e1349ce7cda95accd2f745e.diff LOG: [clang][NFC] Annotate `AST/Comment.h` with `preferred_type` Also declare `InlineCommandRenderKind` as scoped enum, which 565e21b3e079e53c4fcf47d2ec898dbc248fbd3a forgot to do. Added: Modified: clang/include/clang/AST/Comment.h Removed: diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h index d501ce1822862d9..dd9906727293fce 100644 --- a/clang/include/clang/AST/Comment.h +++ b/clang/include/clang/AST/Comment.h @@ -27,6 +27,8 @@ class TemplateParameterList; namespace comments { class FullComment; +enum class InlineCommandRenderKind; +enum class ParamCommandPassDirection; /// Describes the syntax that was used in a documentation command. /// @@ -72,6 +74,7 @@ class Comment { friend class Comment; /// Type of this AST node. +LLVM_PREFERRED_TYPE(CommentKind) unsigned Kind : 8; }; enum { NumCommentBits = 8 }; @@ -79,10 +82,12 @@ class Comment { class InlineContentCommentBitfields { friend class InlineContentComment; +LLVM_PREFERRED_TYPE(CommentBitfields) unsigned : NumCommentBits; /// True if there is a newline after this inline content node. /// (There is no separate AST node for a newline.) +LLVM_PREFERRED_TYPE(bool) unsigned HasTrailingNewline : 1; }; enum { NumInlineContentCommentBits = NumCommentBits + 1 }; @@ -90,12 +95,15 @@ class Comment { class TextCommentBitfields { friend class TextComment; +LLVM_PREFERRED_TYPE(InlineContentCommentBitfields) unsigned : NumInlineContentCommentBits; /// True if \c IsWhitespace field contains a valid value. +LLVM_PREFERRED_TYPE(bool) mutable unsigned IsWhitespaceValid : 1; /// True if this comment AST node contains only whitespace. +LLVM_PREFERRED_TYPE(bool) mutable unsigned IsWhitespace : 1; }; enum { NumTextCommentBits = NumInlineContentCommentBits + 2 }; @@ -103,10 +111,13 @@ class Comment { class InlineCommandCommentBitfields { friend class InlineCommandComment; +LLVM_PREFERRED_TYPE(InlineContentCommentBitfields) unsigned : NumInlineContentCommentBits; +LLVM_PREFERRED_TYPE(InlineCommandRenderKind) unsigned RenderKind : 3; +LLVM_PREFERRED_TYPE(CommandTraits::KnownCommandIDs) unsigned CommandID : CommandInfo::NumCommandIDBits; }; enum { NumInlineCommandCommentBits = NumInlineContentCommentBits + 3 + @@ -115,9 +126,11 @@ class Comment { class HTMLTagCommentBitfields { friend class HTMLTagComment; +LLVM_PREFERRED_TYPE(InlineContentCommentBitfields) unsigned : NumInlineContentCommentBits; /// True if we found that this tag is malformed in some way. +LLVM_PREFERRED_TYPE(bool) unsigned IsMalformed : 1; }; enum { NumHTMLTagCommentBits = NumInlineContentCommentBits + 1 }; @@ -125,10 +138,12 @@ class Comment { class HTMLStartTagCommentBitfields { friend class HTMLStartTagComment; +LLVM_PREFERRED_TYPE(HTMLTagCommentBitfields) unsigned : NumHTMLTagCommentBits; /// True if this tag is self-closing (e. g., ). This is based on tag /// spelling in comment (plain would not set this flag). +LLVM_PREFERRED_TYPE(bool) unsigned IsSelfClosing : 1; }; enum { NumHTMLStartTagCommentBits = NumHTMLTagCommentBits + 1 }; @@ -136,12 +151,15 @@ class Comment { class ParagraphCommentBitfields { friend class ParagraphComment; +LLVM_PREFERRED_TYPE(CommentBitfields) unsigned : NumCommentBits; /// True if \c IsWhitespace field contains a valid value. +LLVM_PREFERRED_TYPE(bool) mutable unsigned IsWhitespaceValid : 1; /// True if this comment AST node contains only whitespace. +LLVM_PREFERRED_TYPE(bool) mutable unsigned IsWhitespace : 1; }; enum { NumParagraphCommentBits = NumCommentBits + 2 }; @@ -149,12 +167,15 @@ class Comment { class BlockCommandCommentBitfields { friend class BlockCommandComment; +LLVM_PREFERRED_TYPE(CommentBitfields) unsigned : NumCommentBits; +LLVM_PREFERRED_TYPE(CommandTraits::KnownCommandIDs) unsigned CommandID : CommandInfo::NumCommandIDBits; /// Describes the syntax that was used in a documentation command. /// Contains values from CommandMarkerKind enum. +LLVM_PREFERRED_TYPE(CommandMarkerKind) unsigned CommandMarker : 1; }; enum { NumBlockCommandCommentBits = NumCommentBits + @@ -163,12 +184,15 @@ class Comment { class ParamCommandCommentBitfields { friend class ParamCommandComment; +LLVM_PREFERRED_TYPE(BlockCommandCommentBitfields)
[clang] b6f2597 - Add missing `llvm::to_underlying` in `AST/CommentParser.cpp` unit test
Author: Vlad Serebrennikov Date: 2023-11-06T23:27:13+03:00 New Revision: b6f2597a45f426f3a276c1c59f7ff5521b6dcc89 URL: https://github.com/llvm/llvm-project/commit/b6f2597a45f426f3a276c1c59f7ff5521b6dcc89 DIFF: https://github.com/llvm/llvm-project/commit/b6f2597a45f426f3a276c1c59f7ff5521b6dcc89.diff LOG: Add missing `llvm::to_underlying` in `AST/CommentParser.cpp` unit test This fixed a test failure introduced in f2d8a0ac1dd1fe55b2c3b358c525fbc01b0121ed. Added: Modified: clang/unittests/AST/CommentParser.cpp Removed: diff --git a/clang/unittests/AST/CommentParser.cpp b/clang/unittests/AST/CommentParser.cpp index 1368f56d0f8eddc..c3479672ae2a3cf 100644 --- a/clang/unittests/AST/CommentParser.cpp +++ b/clang/unittests/AST/CommentParser.cpp @@ -193,8 +193,9 @@ HasParamCommandAt(const Comment *C, const CommandTraits , size_t Idx, if (PCC->getDirection() != Direction) return ::testing::AssertionFailure() -<< "ParamCommandComment has direction " << PCC->getDirection() << ", " - "expected " << Direction; + << "ParamCommandComment has direction " + << llvm::to_underlying(PCC->getDirection()) << ", expected " + << llvm::to_underlying(Direction); if (PCC->isDirectionExplicit() != IsDirectionExplicit) return ::testing::AssertionFailure() ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (re-land) (PR #71417)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/71417 This patch converts CXXNewExpr::InitializationStyle into a scoped enum at namespace scope. It also affirms the status quo by adding a new enumerator to represent implicit initializer. This is a re-land of https://github.com/llvm/llvm-project/pull/71322 >From 40d25b8009f1c8734a99fd1350adaced6884cc7f Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Sun, 5 Nov 2023 18:53:48 +0300 Subject: [PATCH 1/6] [clang][NFC] Refacator `CXXNewExpr::InitializationStyle` This patch converts `CXXNewExpr::InitializationStyle` into a scoped enum at namespace scope. It also affirms the status quo by adding a new enumerator to represent implicit initializer. --- .../modernize/MakeSmartPtrCheck.cpp | 7 +-- clang/include/clang/AST/ExprCXX.h | 48 +++ clang/lib/AST/ExprCXX.cpp | 12 ++--- clang/lib/AST/ItaniumMangle.cpp | 4 +- clang/lib/AST/JSONNodeDumper.cpp | 7 +-- clang/lib/AST/StmtPrinter.cpp | 6 +-- clang/lib/AST/StmtProfile.cpp | 2 +- clang/lib/Sema/SemaExprCXX.cpp| 22 - 8 files changed, 58 insertions(+), 50 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp index 71fd8eca300c1b2..616e57efa76ded5 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -323,7 +323,8 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , return false; }; switch (New->getInitializationStyle()) { - case CXXNewExpr::NoInit: { + case CXXNewInitializationStyle::None: + case CXXNewInitializationStyle::Implicit: { if (ArraySizeExpr.empty()) { Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd)); } else { @@ -334,7 +335,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , } break; } - case CXXNewExpr::CallInit: { + case CXXNewInitializationStyle::Call: { // FIXME: Add fixes for constructors with parameters that can be created // with a C++11 braced-init-list (e.g. std::vector, std::map). // Unlike ordinal cases, braced list can not be deduced in @@ -371,7 +372,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder , } break; } - case CXXNewExpr::ListInit: { + case CXXNewInitializationStyle::List: { // Range of the substring that we do not want to remove. SourceRange InitRange; if (const auto *NewConstruct = New->getConstructExpr()) { diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index a106bafcfa3e021..d713bcf8eb70258 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -2206,6 +2206,20 @@ class CXXScalarValueInitExpr : public Expr { } }; +enum class CXXNewInitializationStyle { + /// New-expression has no initializer as written. + None, + + /// New-expression has no written initializer, but has an implicit one. + Implicit, + + /// New-expression has a C++98 paren-delimited initializer. + Call, + + /// New-expression has a C++11 list-initializer. + List +}; + /// Represents a new-expression for memory allocation and constructor /// calls, e.g: "new CXXNewExpr(foo)". class CXXNewExpr final @@ -2259,25 +2273,12 @@ class CXXNewExpr final return isParenTypeId(); } -public: - enum InitializationStyle { -/// New-expression has no initializer as written. -NoInit, - -/// New-expression has a C++98 paren-delimited initializer. -CallInit, - -/// New-expression has a C++11 list-initializer. -ListInit - }; - -private: /// Build a c++ new expression. CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs, SourceRange TypeIdParens, std::optional ArraySize, - InitializationStyle InitializationStyle, Expr *Initializer, + CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -2292,7 +2293,7 @@ class CXXNewExpr final FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef PlacementArgs, SourceRange TypeIdParens, std::optional ArraySize, - InitializationStyle InitializationStyle, Expr *Initializer, + CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange); @@ -2388,15 +2389,20 @@ class CXXNewExpr final /// Whether this new-expression has any initializer at all.
[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (re-land) (PR #71417)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/71417 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] cd60229 - [clang][NFC] Refactor `ConstantExpr::ResultStorageKind`
Author: Vlad Serebrennikov Date: 2023-11-04T13:28:29+03:00 New Revision: cd6022916bff1d6fab007b554810b631549ba43c URL: https://github.com/llvm/llvm-project/commit/cd6022916bff1d6fab007b554810b631549ba43c DIFF: https://github.com/llvm/llvm-project/commit/cd6022916bff1d6fab007b554810b631549ba43c.diff LOG: [clang][NFC] Refactor `ConstantExpr::ResultStorageKind` This patch converts `ConstantExpr::ResultStorageKind` to a scoped enum in namespace scoped `ConstantResultStorageKind`. This patch makes it possible to forward-declare this enum where it's necessery, e.g. for `preferred_type` annotation for bit-fields. Added: Modified: clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp clang/include/clang/AST/Expr.h clang/include/clang/AST/Stmt.h clang/lib/AST/Expr.cpp clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriterStmt.cpp Removed: diff --git a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp index a152fb5cfabd1db..43cfc769f7f71d1 100644 --- a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp @@ -176,7 +176,7 @@ bool PopulateSwitch::prepare(const Selection ) { // We need a stored value in order to continue; currently both C and ObjC // enums won't have one. -if (CE->getResultStorageKind() == ConstantExpr::RSK_None) +if (CE->getResultStorageKind() == ConstantResultStorageKind::None) return false; auto Iter = ExpectedCases.find(Normalize(CE->getResultAsAPSInt())); if (Iter != ExpectedCases.end()) diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 36f004d64617055..37821982000ea1b 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -1049,6 +1049,9 @@ class FullExpr : public Expr { } }; +/// Describes the kind of result that can be tail-allocated. +enum class ConstantResultStorageKind { None, Int64, APValue }; + /// ConstantExpr - An expression that occurs in a constant context and /// optionally the result of evaluating the expression. class ConstantExpr final @@ -1061,20 +1064,15 @@ class ConstantExpr final friend class ASTStmtReader; friend class ASTStmtWriter; -public: - /// Describes the kind of result that can be tail-allocated. - enum ResultStorageKind { RSK_None, RSK_Int64, RSK_APValue }; - -private: size_t numTrailingObjects(OverloadToken) const { -return ConstantExprBits.ResultKind == ConstantExpr::RSK_APValue; +return getResultStorageKind() == ConstantResultStorageKind::APValue; } size_t numTrailingObjects(OverloadToken) const { -return ConstantExprBits.ResultKind == ConstantExpr::RSK_Int64; +return getResultStorageKind() == ConstantResultStorageKind::Int64; } uint64_t () { -assert(ConstantExprBits.ResultKind == ConstantExpr::RSK_Int64 && +assert(getResultStorageKind() == ConstantResultStorageKind::Int64 && "invalid accessor"); return *getTrailingObjects(); } @@ -1082,7 +1080,7 @@ class ConstantExpr final return const_cast(this)->Int64Result(); } APValue () { -assert(ConstantExprBits.ResultKind == ConstantExpr::RSK_APValue && +assert(getResultStorageKind() == ConstantResultStorageKind::APValue && "invalid accessor"); return *getTrailingObjects(); } @@ -1090,22 +1088,23 @@ class ConstantExpr final return const_cast(this)->APValueResult(); } - ConstantExpr(Expr *SubExpr, ResultStorageKind StorageKind, + ConstantExpr(Expr *SubExpr, ConstantResultStorageKind StorageKind, bool IsImmediateInvocation); - ConstantExpr(EmptyShell Empty, ResultStorageKind StorageKind); + ConstantExpr(EmptyShell Empty, ConstantResultStorageKind StorageKind); public: static ConstantExpr *Create(const ASTContext , Expr *E, const APValue ); - static ConstantExpr *Create(const ASTContext , Expr *E, - ResultStorageKind Storage = RSK_None, - bool IsImmediateInvocation = false); + static ConstantExpr * + Create(const ASTContext , Expr *E, + ConstantResultStorageKind Storage = ConstantResultStorageKind::None, + bool IsImmediateInvocation = false); static ConstantExpr *CreateEmpty(const ASTContext , - ResultStorageKind StorageKind); + ConstantResultStorageKind StorageKind); - static ResultStorageKind getStorageKind(const APValue ); - static ResultStorageKind getStorageKind(const Type *T, - const ASTContext ); + static ConstantResultStorageKind getStorageKind(const APValue ); + static ConstantResultStorageKind getStorageKind(const Type *T, +
[clang] 99e7e7a - [clang][NFC] Refactor `SourceLocExpr::IdentKind`
Author: Vlad Serebrennikov Date: 2023-11-04T12:43:26+03:00 New Revision: 99e7e7a597fa4ebaa8ebacdc42eae9f0b976f54c URL: https://github.com/llvm/llvm-project/commit/99e7e7a597fa4ebaa8ebacdc42eae9f0b976f54c DIFF: https://github.com/llvm/llvm-project/commit/99e7e7a597fa4ebaa8ebacdc42eae9f0b976f54c.diff LOG: [clang][NFC] Refactor `SourceLocExpr::IdentKind` This patch converts `SourceLocExpr::IdentKind` into a scoped enum at namespace scope, making it eligible to be forward-declared. This is needed by `preferred_type` annotations on bit-fields. Added: Modified: clang/include/clang/AST/Expr.h clang/include/clang/Sema/Sema.h clang/lib/AST/Expr.cpp clang/lib/Parse/ParseExpr.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriterStmt.cpp Removed: diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 87e80a5a37750ac..36f004d64617055 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -4735,6 +4735,16 @@ class VAArgExpr : public Expr { } }; +enum class SourceLocIdentKind { + Function, + FuncSig, + File, + FileName, + Line, + Column, + SourceLocStruct +}; + /// Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), /// __builtin_FUNCTION(), __builtin_FUNCSIG(), __builtin_FILE(), /// __builtin_FILE_NAME() or __builtin_source_location(). @@ -4743,19 +4753,9 @@ class SourceLocExpr final : public Expr { DeclContext *ParentContext; public: - enum IdentKind { -Function, -FuncSig, -File, -FileName, -Line, -Column, -SourceLocStruct - }; - - SourceLocExpr(const ASTContext , IdentKind Type, QualType ResultTy, -SourceLocation BLoc, SourceLocation RParenLoc, -DeclContext *Context); + SourceLocExpr(const ASTContext , SourceLocIdentKind Type, +QualType ResultTy, SourceLocation BLoc, +SourceLocation RParenLoc, DeclContext *Context); /// Build an empty call expression. explicit SourceLocExpr(EmptyShell Empty) : Expr(SourceLocExprClass, Empty) {} @@ -4768,20 +4768,20 @@ class SourceLocExpr final : public Expr { /// Return a string representing the name of the specific builtin function. StringRef getBuiltinStr() const; - IdentKind getIdentKind() const { -return static_cast(SourceLocExprBits.Kind); + SourceLocIdentKind getIdentKind() const { +return static_cast(SourceLocExprBits.Kind); } bool isIntType() const { switch (getIdentKind()) { -case File: -case FileName: -case Function: -case FuncSig: -case SourceLocStruct: +case SourceLocIdentKind::File: +case SourceLocIdentKind::FileName: +case SourceLocIdentKind::Function: +case SourceLocIdentKind::FuncSig: +case SourceLocIdentKind::SourceLocStruct: return false; -case Line: -case Column: +case SourceLocIdentKind::Line: +case SourceLocIdentKind::Column: return true; } llvm_unreachable("unknown source location expression kind"); diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index daed24be0a86d11..8a35cbe3e9502b6 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -6086,14 +6086,13 @@ class Sema final { // __builtin_LINE(), __builtin_FUNCTION(), __builtin_FUNCSIG(), // __builtin_FILE(), __builtin_COLUMN(), __builtin_source_location() - ExprResult ActOnSourceLocExpr(SourceLocExpr::IdentKind Kind, + ExprResult ActOnSourceLocExpr(SourceLocIdentKind Kind, SourceLocation BuiltinLoc, SourceLocation RPLoc); // Build a potentially resolved SourceLocExpr. - ExprResult BuildSourceLocExpr(SourceLocExpr::IdentKind Kind, -QualType ResultTy, SourceLocation BuiltinLoc, -SourceLocation RPLoc, + ExprResult BuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, +SourceLocation BuiltinLoc, SourceLocation RPLoc, DeclContext *ParentContext); // __null diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 5d3b510df1ef9b3..62467493e386e8d 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -2196,31 +2196,31 @@ bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext , return true; } -SourceLocExpr::SourceLocExpr(const ASTContext , IdentKind Kind, +SourceLocExpr::SourceLocExpr(const ASTContext , SourceLocIdentKind Kind, QualType ResultTy, SourceLocation BLoc, SourceLocation RParenLoc, DeclContext *ParentContext) : Expr(SourceLocExprClass, ResultTy,
[clang] 7ec8a6f - [clang][NFC] Annotate `Stmt.h` with `preferred_type`
Author: Vlad Serebrennikov Date: 2023-11-06T21:02:14+03:00 New Revision: 7ec8a6fd31d8ddb161b06067fb6b7f9026a460df URL: https://github.com/llvm/llvm-project/commit/7ec8a6fd31d8ddb161b06067fb6b7f9026a460df DIFF: https://github.com/llvm/llvm-project/commit/7ec8a6fd31d8ddb161b06067fb6b7f9026a460df.diff LOG: [clang][NFC] Annotate `Stmt.h` with `preferred_type` This helps debuggers to display values in bit-fields in a more helpful way. Added: Modified: clang/include/clang/AST/Stmt.h Removed: diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h index 9fb49e99da1073f..da7b37ce0e1211f 100644 --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -13,15 +13,20 @@ #ifndef LLVM_CLANG_AST_STMT_H #define LLVM_CLANG_AST_STMT_H +#include "clang/AST/APValue.h" #include "clang/AST/DeclGroup.h" #include "clang/AST/DependenceFlags.h" +#include "clang/AST/OperationKinds.h" #include "clang/AST/StmtIterator.h" #include "clang/Basic/CapturedStmt.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" +#include "clang/Basic/Lambda.h" #include "clang/Basic/LangOptions.h" +#include "clang/Basic/OperatorKinds.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/Specifiers.h" +#include "clang/Basic/TypeTraits.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/BitmaskEnum.h" @@ -62,6 +67,13 @@ class SourceManager; class StringLiteral; class Token; class VarDecl; +enum class CharacterLiteralKind; +enum class ConstantResultStorageKind; +enum class CXXConstructionKind; +enum class CXXNewInitializationStyle; +enum class PredefinedIdentKind; +enum class SourceLocIdentKind; +enum class StringLiteralKind; //===--===// // AST classes for statements. @@ -103,6 +115,7 @@ class alignas(void *) Stmt { friend class Stmt; /// The statement class. +LLVM_PREFERRED_TYPE(StmtClass) unsigned sClass : 8; }; enum { NumStmtBits = 8 }; @@ -112,6 +125,7 @@ class alignas(void *) Stmt { friend class ASTStmtWriter; friend class NullStmt; +LLVM_PREFERRED_TYPE(StmtBitfields) unsigned : NumStmtBits; /// True if the null statement was preceded by an empty macro, e.g: @@ -119,6 +133,7 @@ class alignas(void *) Stmt { /// #define CALL(x) /// CALL(0); /// @endcode +LLVM_PREFERRED_TYPE(bool) unsigned HasLeadingEmptyMacro : 1; /// The location of the semi-colon. @@ -129,10 +144,12 @@ class alignas(void *) Stmt { friend class ASTStmtReader; friend class CompoundStmt; +LLVM_PREFERRED_TYPE(StmtBitfields) unsigned : NumStmtBits; /// True if the compound statement has one or more pragmas that set some /// floating-point features. +LLVM_PREFERRED_TYPE(bool) unsigned HasFPFeatures : 1; unsigned NumStmts; @@ -141,6 +158,7 @@ class alignas(void *) Stmt { class LabelStmtBitfields { friend class LabelStmt; +LLVM_PREFERRED_TYPE(StmtBitfields) unsigned : NumStmtBits; SourceLocation IdentLoc; @@ -150,6 +168,7 @@ class alignas(void *) Stmt { friend class ASTStmtReader; friend class AttributedStmt; +LLVM_PREFERRED_TYPE(StmtBitfields) unsigned : NumStmtBits; /// Number of attributes. @@ -163,18 +182,23 @@ class alignas(void *) Stmt { friend class ASTStmtReader; friend class IfStmt; +LLVM_PREFERRED_TYPE(StmtBitfields) unsigned : NumStmtBits; /// Whether this is a constexpr if, or a consteval if, or neither. +LLVM_PREFERRED_TYPE(IfStatementKind) unsigned Kind : 3; /// True if this if statement has storage for an else statement. +LLVM_PREFERRED_TYPE(bool) unsigned HasElse : 1; /// True if this if statement has storage for a variable declaration. +LLVM_PREFERRED_TYPE(bool) unsigned HasVar : 1; /// True if this if statement has storage for an init statement. +LLVM_PREFERRED_TYPE(bool) unsigned HasInit : 1; /// The location of the "if". @@ -184,17 +208,21 @@ class alignas(void *) Stmt { class SwitchStmtBitfields { friend class SwitchStmt; +LLVM_PREFERRED_TYPE(StmtBitfields) unsigned : NumStmtBits; /// True if the SwitchStmt has storage for an init statement. +LLVM_PREFERRED_TYPE(bool) unsigned HasInit : 1; /// True if the SwitchStmt has storage for a condition variable. +LLVM_PREFERRED_TYPE(bool) unsigned HasVar : 1; /// If the SwitchStmt is a switch on an enum value, records whether all /// the enum values were covered by CaseStmts. The coverage information /// value is meant to be a hint for possible clients. +LLVM_PREFERRED_TYPE(bool) unsigned AllEnumCasesCovered : 1; /// The location of the "switch". @@ -205,9 +233,11 @@
[clang] 60f7fa1 - [clang][NFC] Refactor `Comment::CommentKind`
Author: Vlad Serebrennikov Date: 2023-11-06T22:17:03+03:00 New Revision: 60f7fa123d77ecf8e138be35ad8880622586fa03 URL: https://github.com/llvm/llvm-project/commit/60f7fa123d77ecf8e138be35ad8880622586fa03 DIFF: https://github.com/llvm/llvm-project/commit/60f7fa123d77ecf8e138be35ad8880622586fa03.diff LOG: [clang][NFC] Refactor `Comment::CommentKind` This patch converts `Comment::CommentKind` into a scoped enum at namespace scope, making it eligible for forward declaring. This is useful for e.g. annotating bit-fields with `preferred_type`. Added: Modified: clang/include/clang/AST/Comment.h clang/include/clang/AST/CommentVisitor.h clang/lib/AST/Comment.cpp clang/lib/Index/CommentToXML.cpp clang/tools/libclang/CXComment.cpp Removed: diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h index 0b68c11316649aa..7cbed3600d28287 100644 --- a/clang/include/clang/AST/Comment.h +++ b/clang/include/clang/AST/Comment.h @@ -47,6 +47,17 @@ enum CommandMarkerKind { CMK_At = 1 }; +enum class CommentKind { + None = 0, +#define COMMENT(CLASS, PARENT) CLASS, +#define COMMENT_RANGE(BASE, FIRST, LAST) \ + First##BASE##Constant = FIRST, Last##BASE##Constant = LAST, +#define LAST_COMMENT_RANGE(BASE, FIRST, LAST) \ + First##BASE##Constant = FIRST, Last##BASE##Constant = LAST +#define ABSTRACT_COMMENT(COMMENT) +#include "clang/AST/CommentNodes.inc" +}; + /// Any part of the comment. /// Abstract class. class Comment { @@ -183,17 +194,6 @@ class Comment { } public: - enum CommentKind { -NoCommentKind = 0, -#define COMMENT(CLASS, PARENT) CLASS##Kind, -#define COMMENT_RANGE(BASE, FIRST, LAST) \ -First##BASE##Constant=FIRST##Kind, Last##BASE##Constant=LAST##Kind, -#define LAST_COMMENT_RANGE(BASE, FIRST, LAST) \ -First##BASE##Constant=FIRST##Kind, Last##BASE##Constant=LAST##Kind -#define ABSTRACT_COMMENT(COMMENT) -#include "clang/AST/CommentNodes.inc" - }; - struct Argument { SourceRange Range; StringRef Text; @@ -203,7 +203,7 @@ class Comment { SourceLocation LocBegin, SourceLocation LocEnd) : Loc(LocBegin), Range(SourceRange(LocBegin, LocEnd)) { -CommentBits.Kind = K; +CommentBits.Kind = llvm::to_underlying(K); } CommentKind getCommentKind() const { @@ -249,8 +249,9 @@ class InlineContentComment : public Comment { public: static bool classof(const Comment *C) { -return C->getCommentKind() >= FirstInlineContentCommentConstant && - C->getCommentKind() <= LastInlineContentCommentConstant; +return C->getCommentKind() >= + CommentKind::FirstInlineContentCommentConstant && + C->getCommentKind() <= CommentKind::LastInlineContentCommentConstant; } void addTrailingNewline() { @@ -267,16 +268,14 @@ class TextComment : public InlineContentComment { StringRef Text; public: - TextComment(SourceLocation LocBegin, - SourceLocation LocEnd, - StringRef Text) : - InlineContentComment(TextCommentKind, LocBegin, LocEnd), - Text(Text) { + TextComment(SourceLocation LocBegin, SourceLocation LocEnd, StringRef Text) + : InlineContentComment(CommentKind::TextComment, LocBegin, LocEnd), +Text(Text) { TextCommentBits.IsWhitespaceValid = false; } static bool classof(const Comment *C) { -return C->getCommentKind() == TextCommentKind; +return C->getCommentKind() == CommentKind::TextComment; } child_iterator child_begin() const { return nullptr; } @@ -316,19 +315,18 @@ class InlineCommandComment : public InlineContentComment { ArrayRef Args; public: - InlineCommandComment(SourceLocation LocBegin, - SourceLocation LocEnd, - unsigned CommandID, - RenderKind RK, - ArrayRef Args) : - InlineContentComment(InlineCommandCommentKind, LocBegin, LocEnd), - Args(Args) { + InlineCommandComment(SourceLocation LocBegin, SourceLocation LocEnd, + unsigned CommandID, RenderKind RK, + ArrayRef Args) + : InlineContentComment(CommentKind::InlineCommandComment, LocBegin, + LocEnd), +Args(Args) { InlineCommandCommentBits.RenderKind = RK; InlineCommandCommentBits.CommandID = CommandID; } static bool classof(const Comment *C) { -return C->getCommentKind() == InlineCommandCommentKind; +return C->getCommentKind() == CommentKind::InlineCommandComment; } child_iterator child_begin() const { return nullptr; } @@ -386,8 +384,8 @@ class HTMLTagComment : public InlineContentComment { public: static bool classof(const Comment *C) { -return C->getCommentKind() >= FirstHTMLTagCommentConstant && -
[clang] [clang] Remove diagnostic that came with `[[clang::preferred_type]]` (PR #70632)
Endilll wrote: > Why doesn't this result in any changes to tests? I would expect having to > remove them, right? There was a single test that was relying on sign mismatch, and then during code review we made the diagnostic to ignore signness. So it ended up merged without test case where this diagnostic was triggered. https://github.com/llvm/llvm-project/pull/70632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Refactor `Selector` to use `PointerIntPair` inside (PR #69916)
@@ -809,43 +927,42 @@ class Selector { enum IdentifierInfoFlag { // Empty selector = 0. Note that these enumeration values must // correspond to the enumeration values of DeclarationName::StoredNameKind -ZeroArg = 0x01, -OneArg = 0x02, +ZeroArg = 0x01, +OneArg = 0x02, MultiArg = 0x07, -ArgFlags = 0x07 }; /// A pointer to the MultiKeywordSelector or IdentifierInfo. We use the low - /// three bits of InfoPtr to store an IdentifierInfoFlag. Note that in any + /// three bits of InfoPtr to store an IdentifierInfoFlag, but the highest + /// of them is also a discriminator for pointer type. Note that in any /// case IdentifierInfo and MultiKeywordSelector are already aligned to /// 8 bytes even on 32 bits archs because of DeclarationName. - uintptr_t InfoPtr = 0; + llvm::PointerIntPair< + llvm::PointerUnion, 2> + InfoPtr; Selector(IdentifierInfo *II, unsigned nArgs) { -InfoPtr = reinterpret_cast(II); -assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo"); assert(nArgs < 2 && "nArgs not equal to 0/1"); -InfoPtr |= nArgs+1; +InfoPtr.setPointerAndInt(II, nArgs + 1); } Selector(MultiKeywordSelector *SI) { -InfoPtr = reinterpret_cast(SI); -assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo"); -InfoPtr |= MultiArg; +InfoPtr.setPointerAndInt(SI, MultiArg & 0b11); Endilll wrote: Applied. https://github.com/llvm/llvm-project/pull/69916 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Refactor `Selector` to use `PointerIntPair` inside (PR #69916)
@@ -809,43 +927,42 @@ class Selector { enum IdentifierInfoFlag { // Empty selector = 0. Note that these enumeration values must // correspond to the enumeration values of DeclarationName::StoredNameKind -ZeroArg = 0x01, -OneArg = 0x02, +ZeroArg = 0x01, +OneArg = 0x02, MultiArg = 0x07, -ArgFlags = 0x07 }; /// A pointer to the MultiKeywordSelector or IdentifierInfo. We use the low - /// three bits of InfoPtr to store an IdentifierInfoFlag. Note that in any + /// three bits of InfoPtr to store an IdentifierInfoFlag, but the highest + /// of them is also a discriminator for pointer type. Note that in any /// case IdentifierInfo and MultiKeywordSelector are already aligned to /// 8 bytes even on 32 bits archs because of DeclarationName. - uintptr_t InfoPtr = 0; + llvm::PointerIntPair< + llvm::PointerUnion, 2> + InfoPtr; Selector(IdentifierInfo *II, unsigned nArgs) { -InfoPtr = reinterpret_cast(II); -assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo"); assert(nArgs < 2 && "nArgs not equal to 0/1"); -InfoPtr |= nArgs+1; +InfoPtr.setPointerAndInt(II, nArgs + 1); } Selector(MultiKeywordSelector *SI) { -InfoPtr = reinterpret_cast(SI); -assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo"); -InfoPtr |= MultiArg; +InfoPtr.setPointerAndInt(SI, MultiArg & 0b11); } IdentifierInfo *getAsIdentifierInfo() const { -if (getIdentifierInfoFlag() < MultiArg) - return reinterpret_cast(InfoPtr & ~ArgFlags); -return nullptr; +return InfoPtr.getPointer().dyn_cast(); } MultiKeywordSelector *getMultiKeywordSelector() const { -return reinterpret_cast(InfoPtr & ~ArgFlags); +return InfoPtr.getPointer().get(); } unsigned getIdentifierInfoFlag() const { -return InfoPtr & ArgFlags; +unsigned new_flags = InfoPtr.getInt(); +if (InfoPtr.getPointer().is()) + new_flags |= MultiArg; Endilll wrote: Applied. https://github.com/llvm/llvm-project/pull/69916 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change LLVM style to BreakAfterAttributes == ABS_Leave (PR #70360)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/70360 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
Endilll wrote: @erichkeane I guess you'd be pretty happy if our enums were declared the following way: ```cpp enum E : unsigned _BitInt(4) { e0 = 16, }; ``` Then you'd be warned on the spot if you have more values than bits can hold, and bit-fields side check would be trivial to implement: ``` :3:8: error: enumerator value evaluates to 16, which cannot be narrowed to type 'unsigned _BitInt(4)' [-Wc++11-narrowing] e0 = 16, ``` Unfortunately, Clang 14+ is the only major implementation that accepts this: https://godbolt.org/z/9rn87d8hc https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Bump latest release to 17 for C++ DR Status page (PR #67996)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/67996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG472 (PR #67948)
Endilll wrote: > None of the implementations seem to agree with the resolution of the DR: > https://godbolt.org/z/a7nEvW5Gr It's definitely not the first time CWG goes against every major implementation with their DR resolution. https://github.com/llvm/llvm-project/pull/67948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2267 (PR #67931)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/67931 Related: #63416 >From 4720a0f6bce7b1531dec2005d642938db1370335 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Sun, 1 Oct 2023 21:28:21 +0300 Subject: [PATCH] [clang] Add test for CWG2267 --- clang/test/CXX/drs/dr22xx.cpp | 22 ++ clang/www/cxx_dr_status.html | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/clang/test/CXX/drs/dr22xx.cpp b/clang/test/CXX/drs/dr22xx.cpp index 414925f0d74cc2e..cd849443b1119ba 100644 --- a/clang/test/CXX/drs/dr22xx.cpp +++ b/clang/test/CXX/drs/dr22xx.cpp @@ -123,6 +123,28 @@ namespace CheckAfterMerging2 { #endif } // namespace dr2233 +namespace dr2267 { // dr2267: no +#if __cplusplus >= 201103L +struct A {} a; +struct B { explicit B(const A&); }; // #dr2267-struct-B + +struct D { D(); }; +struct C { explicit operator D(); } c; + +B b1(a); +const B {a}; // FIXME ill-formed +const B (a); +// expected-error@-1 {{no viable conversion from 'struct A' to 'const B'}} +// expected-note@#dr2267-struct-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'struct A' to 'const B &' for 1st argument}} +// expected-note@#dr2267-struct-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'struct A' to 'B &&' for 1st argument}} +// expected-note@#dr2267-struct-B {{explicit constructor is not a candidate}} + +D d1(c); +const D {c}; // FIXME ill-formed +const D (c); // FIXME ill-formed +#endif +} + namespace dr2292 { // dr2292: 9 #if __cplusplus >= 201103L template using id = T; diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index ee9712e9bab9949..49386bbbc44c80f 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -13409,7 +13409,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/2267.html;>2267 CD5 Copy-initialization of temporary in reference direct-initialization -Unknown +No https://cplusplus.github.io/CWG/issues/2268.html;>2268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG472 (PR #67948)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/67948 https://cplusplus.github.io/CWG/issues/472.html It has drafting status, but I think CWG has reached consesus on the behavior. >From ad0df2131e12c59e57b603b955626e27e3067505 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Mon, 2 Oct 2023 08:12:56 +0300 Subject: [PATCH] [clang] Add test for CWG472 --- clang/test/CXX/drs/dr4xx.cpp | 17 + clang/www/cxx_dr_status.html | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/clang/test/CXX/drs/dr4xx.cpp b/clang/test/CXX/drs/dr4xx.cpp index d8bdf49d0b2dde7..cc12e9f158061f8 100644 --- a/clang/test/CXX/drs/dr4xx.cpp +++ b/clang/test/CXX/drs/dr4xx.cpp @@ -924,6 +924,23 @@ namespace dr471 { // dr471: yes struct H : B, G { int f() { return n; } }; // expected-error {{private}} } +namespace dr472 { // dr472: no drafting +struct B { + int i; // #dr472-i-decl +}; +struct I : protected B {}; // #dr472-inheritance +struct D : public I { + void f(I *ip) { +ip->i = 0; +// expected-error@-1{{'i' is a protected member of 'dr472::B'}} +// expected-note@#dr472-inheritance {{constrained by protected inheritance here}} +// expected-note@#dr472-i-decl {{member is declared here}} +B *bp = ip; +bp->i = 5; + } +}; +} + namespace dr474 { // dr474: yes namespace N { struct S { diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index ee9712e9bab9949..b02f7ccfd371411 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -2871,7 +2871,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/472.html;>472 drafting Casting across protected inheritance -Not resolved +No https://cplusplus.github.io/CWG/issues/473.html;>473 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2267 (PR #67931)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/67931 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG472 (PR #67948)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/67948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2267 (PR #67931)
https://github.com/Endilll unassigned https://github.com/llvm/llvm-project/pull/67931 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add check for duplicates to make_cxx_dr_status script (PR #67969)
@@ -7145,7 +7145,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/1223.html;>1223 drafting Syntactic disambiguation and trailing-return-types -Not resolved +Clang 17 Endilll wrote: `make_cxx_dr_status` is not yet updated to know that 17 has been released. I'll address it in a separate PR. https://github.com/llvm/llvm-project/pull/67969 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG1341 (PR #67965)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/67965 https://cplusplus.github.io/CWG/issues/1341.html https://wg21.link/p0683r1 >From 92fec6fe49de0392596e7f7d4a1c5524dd436747 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Mon, 2 Oct 2023 13:17:40 +0300 Subject: [PATCH] [clang] Add test for CWG1341 --- clang/test/CXX/drs/dr13xx.cpp | 17 + clang/www/cxx_dr_status.html | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp index feaf523c44fc27c..3510695954e27c1 100644 --- a/clang/test/CXX/drs/dr13xx.cpp +++ b/clang/test/CXX/drs/dr13xx.cpp @@ -254,6 +254,23 @@ namespace dr1330 { // dr1330: 4 c++11 #endif } +namespace dr1341 { // dr1341: sup P0683R1 +#if __cplusplus >= 202002L +int a; +const int b = 0; // #dr1341-b-decl +struct S { + int x1 : 8 = 42; + int x2 : 8 { 42 }; + int y1 : true ? 8 : a = 42; + int y2 : true ? 8 : b = 42; + // expected-error@-1{{cannot assign to variable 'b' with const-qualified type 'const int'}} + // expected-note@#dr1341-b-decl {{variable 'b' declared const here}} + int y3 : (true ? 8 : b) = 42; + int z : 1 || new int { 0 }; +}; +#endif +} + namespace dr1346 { // dr1346: 3.5 auto a(1); // expected-error 0-1{{extension}} auto b(1, 2); // expected-error {{multiple expressions}} expected-error 0-1{{extension}} diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index ee9712e9bab9949..6b351a3eb72f3d1 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -7853,7 +7853,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/1341.html;>1341 NAD Bit-field initializers -Unknown +Superseded by https://wg21.link/P0683R1;>P0683R1 https://cplusplus.github.io/CWG/issues/1342.html;>1342 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add check for duplicates to make_cxx_dr_status script (PR #67969)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/67969 While working on #67965, I stumbled upon the fact that `make_cxx_dr_status` script doesn't check for duplicated comment (last comment wins), so I added this check. It even found another instance of duplicated comment: CWG1223 was marked as CWG1227. I fixed status of the former. >From 6b488467b6e6b40027e6ba1f5abbeeecbfeeef5b Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Mon, 2 Oct 2023 14:02:16 +0300 Subject: [PATCH] [clang] Add check for duplicates to make_cxx_dr_status script --- clang/test/CXX/drs/dr12xx.cpp | 2 +- clang/www/cxx_dr_status.html | 2 +- clang/www/make_cxx_dr_status | 6 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/clang/test/CXX/drs/dr12xx.cpp b/clang/test/CXX/drs/dr12xx.cpp index a941366050e1ab5..c23a515ba56cb99 100644 --- a/clang/test/CXX/drs/dr12xx.cpp +++ b/clang/test/CXX/drs/dr12xx.cpp @@ -32,7 +32,7 @@ namespace dr1213 { // dr1213: 7 } #if __cplusplus >= 201103L -namespace dr1223 { // dr1227: yes open +namespace dr1223 { // dr1223: 17 drafting struct M; template struct V; diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index ee9712e9bab9949..80a80d9940df254 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -7145,7 +7145,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/1223.html;>1223 drafting Syntactic disambiguation and trailing-return-types -Not resolved +Clang 17 https://cplusplus.github.io/CWG/issues/1224.html;>1224 diff --git a/clang/www/make_cxx_dr_status b/clang/www/make_cxx_dr_status index afb7189c0ececc5..c44a5910d53daeb 100755 --- a/clang/www/make_cxx_dr_status +++ b/clang/www/make_cxx_dr_status @@ -39,7 +39,11 @@ def collect_tests(): test_cpp = os.path.join(dr_test_dir, test_cpp) found_any = False; for match in re.finditer(status_re, open(test_cpp, 'r').read()): - status_map[int(match.group(1))] = match.group(2) + dr_number = int(match.group(1)) + if dr_number in status_map: +print("error: Comment for dr{} encountered more than once. Duplicate found in {}".format(dr_number, test_cpp)) +sys.exit(1) + status_map[dr_number] = match.group(2) found_any = True if not found_any: print("warning:%s: no '// dr123: foo' comments in this file" % test_cpp, file=sys.stderr) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG1341 (PR #67965)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/67965 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][driver] Use platform specific calls to get the executable absolute path (PR #68091)
Endilll wrote: You have failed tests on Linux CI: ``` Failed Tests (4): Clang :: Driver/mingw-sysroot.cpp Clang :: Driver/no-canonical-prefixes.c Clang :: Driver/program-path-priority.c Clang :: Driver/rocm-detect.hip ``` Windows CI has another test in Clang interpreter failing, but that might be not related to you. You should be able to reproduce those test failures with `clang --build . -t check-clang-driver` (or `ninja check-clang-driver`). https://github.com/llvm/llvm-project/pull/68091 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Bump latest release to 17 for C++ DR Status page (PR #67996)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/67996 `make_cxx_dr_status` has a hardcoded number of the latest release, for the puproses of determining whether a particular DR is available to users or not yet. I'm bumping it to 17. >From ecea1993e65880c077eec769bed49ccf3f980f31 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Mon, 2 Oct 2023 17:56:50 +0300 Subject: [PATCH] [clang] Bump latest release to 17 for C++ DR Status page --- clang/www/cxx_dr_status.html | 10 +- clang/www/make_cxx_dr_status | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index ee9712e9bab9949..f3ffc9edf6ce42c 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -12653,7 +12653,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/2141.html;>2141 CD4 Ambiguity in new-expression with elaborated-type-specifier -Clang 17 +Clang 17 https://cplusplus.github.io/CWG/issues/2142.html;>2142 @@ -14189,7 +14189,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/2397.html;>2397 CD6 auto specifier for pointers and references to arrays -Clang 17 +Clang 17 https://cplusplus.github.io/CWG/issues/2398.html;>2398 @@ -14915,7 +14915,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/2518.html;>2518 C++23 Conformance requirements and #error/#warning -Clang 17 +Clang 17 https://cplusplus.github.io/CWG/issues/2519.html;>2519 @@ -14933,7 +14933,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/2521.html;>2521 C++23 User-defined literals and reserved identifiers -Clang 17 +Clang 17 https://cplusplus.github.io/CWG/issues/2522.html;>2522 @@ -15893,7 +15893,7 @@ C++ defect report implementation status https://cplusplus.github.io/CWG/issues/2681.html;>2681 C++23 Deducing member array type from string literal -Clang 17 +Clang 17 https://cplusplus.github.io/CWG/issues/2682.html;>2682 diff --git a/clang/www/make_cxx_dr_status b/clang/www/make_cxx_dr_status index afb7189c0ececc5..da139be87967008 100755 --- a/clang/www/make_cxx_dr_status +++ b/clang/www/make_cxx_dr_status @@ -122,7 +122,7 @@ out_file.write('''\ Available in Clang? ''') -latest_release = 16 +latest_release = 17 def availability(issue): status = status_map.get(issue, 'unknown') ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add check for duplicates to make_cxx_dr_status script (PR #67969)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/67969 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Bump latest release to 17 for C++ DR Status page (PR #67996)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/67996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Bump latest release to 17 for C++ DR Status page (PR #67996)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/67996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for CWG2267 (PR #67931)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/67931 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/68377 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] remove ClassScopeFunctionSpecializationDecl (PR #66636)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/66636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/68377 >From 8503ff3e70e585a4a3597e3ee8111269f48105cc Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 5 Oct 2023 13:18:14 +0300 Subject: [PATCH 1/3] [clang] Align Type and ExtQuals on 16-byte boundary --- clang/include/clang/AST/Type.h | 17 ++--- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index a78d8f60462b231..4e98858f6e9432a 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1482,7 +1482,7 @@ class ExtQualsTypeCommonBase { /// in three low bits on the QualType pointer; a fourth bit records whether /// the pointer is an ExtQuals node. The extended qualifiers (address spaces, /// Objective-C GC attributes) are much more rare. -class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { +class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { // NOTE: changing the fast qualifiers should be straightforward as // long as you don't make 'const' non-fast. // 1. Qualifiers: @@ -1507,6 +1507,9 @@ class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { : ExtQualsTypeCommonBase(baseType, canon.isNull() ? QualType(this_(), 0) : canon), Quals(quals) { +static_assert(alignof(decltype(*this)) % TypeAlignment == 0, + "Insufficient alignment!"); + assert(Quals.hasNonFastQualifiers() && "ExtQuals created with no fast qualifiers"); assert(!Quals.hasFastQualifiers() @@ -1594,7 +1597,7 @@ enum class AutoTypeKeyword { /// /// Types, once created, are immutable. /// -class alignas(8) Type : public ExtQualsTypeCommonBase { +class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { public: enum TypeClass { #define TYPE(Class, Base) Class, @@ -1982,9 +1985,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase { Type(TypeClass tc, QualType canon, TypeDependence Dependence) : ExtQualsTypeCommonBase(this, canon.isNull() ? QualType(this_(), 0) : canon) { -static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase), +static_assert(sizeof(*this) <= 16 + sizeof(ExtQualsTypeCommonBase), "changing bitfields changed sizeof(Type)!"); -static_assert(alignof(decltype(*this)) % sizeof(void *) == 0, +static_assert(alignof(decltype(*this)) % TypeAlignment == 0, "Insufficient alignment!"); TypeBits.TC = tc; TypeBits.Dependence = static_cast(Dependence); @@ -5348,7 +5351,7 @@ class DeducedType : public Type { /// Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained /// by a type-constraint. -class alignas(8) AutoType : public DeducedType, public llvm::FoldingSetNode { +class AutoType : public DeducedType, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these ConceptDecl *TypeConstraintConcept; @@ -5456,7 +5459,7 @@ class DeducedTemplateSpecializationType : public DeducedType, /// TemplateArguments, followed by a QualType representing the /// non-canonical aliased type when the template is a type alias /// template. -class alignas(8) TemplateSpecializationType +class TemplateSpecializationType : public Type, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these @@ -5872,7 +5875,7 @@ class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { /// Represents a template specialization type whose template cannot be /// resolved, e.g. /// A::template B -class alignas(8) DependentTemplateSpecializationType +class DependentTemplateSpecializationType : public TypeWithKeyword, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these >From d08f8f92026026e9d02502307bd1810e516f4f06 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Fri, 6 Oct 2023 06:32:27 +0300 Subject: [PATCH 2/3] Run clang-format --- clang/include/clang/AST/Type.h | 12 +--- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 4e98858f6e9432a..2ba82d6624a 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1482,7 +1482,8 @@ class ExtQualsTypeCommonBase { /// in three low bits on the QualType pointer; a fourth bit records whether /// the pointer is an ExtQuals node. The extended qualifiers (address spaces, /// Objective-C GC attributes) are much more rare. -class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { +class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase, +public llvm::FoldingSetNode { // NOTE: changing the fast qualifiers
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
@@ -1982,9 +1986,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase { Type(TypeClass tc, QualType canon, TypeDependence Dependence) : ExtQualsTypeCommonBase(this, canon.isNull() ? QualType(this_(), 0) : canon) { -static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase), +static_assert(sizeof(*this) <= 16 + sizeof(ExtQualsTypeCommonBase), "changing bitfields changed sizeof(Type)!"); Endilll wrote: Good suggestion! https://github.com/llvm/llvm-project/pull/68377 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
@@ -1507,6 +1508,9 @@ class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { : ExtQualsTypeCommonBase(baseType, canon.isNull() ? QualType(this_(), 0) : canon), Quals(quals) { +static_assert(alignof(decltype(*this)) % TypeAlignment == 0, Endilll wrote: Makes sense. I removed this static assert. https://github.com/llvm/llvm-project/pull/68377 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
Endilll wrote: My plan is to phase-out `TypeAlignment` in subsequent patches, because we have proper language support for `alignas` and `alignof` now. It's the only one of its kind passed to `Allocate()` (I inspected all references to this function). CC @zygolod as the author of ee0ce302c5eb4f26738f334f2fd8b165fa65dfca https://github.com/llvm/llvm-project/pull/68377 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Add missing placement-new after Allocate() calls (PR #68382)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/68382 >From d987a8523086ab8b6d49f395429afda75769a731 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Fri, 6 Oct 2023 07:20:07 +0300 Subject: [PATCH 1/2] [clang][NFC] Add missing placement-new after Allocate() calls --- clang/lib/AST/DeclCXX.cpp | 3 ++- clang/lib/AST/DeclObjC.cpp| 4 ++-- clang/lib/Serialization/ASTReaderDecl.cpp | 6 -- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 42bab4ed51b7290..a92b788366434ce 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -1484,7 +1484,8 @@ void CXXRecordDecl::setCaptures(ASTContext , if (Captures[I].isExplicit()) ++Data.NumExplicitCaptures; -*ToCapture++ = Captures[I]; +new (ToCapture) LambdaCapture(Captures[I]); +ToCapture++; } if (!lambdaIsDefaultConstructibleAndAssignable()) diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index e934a81d086e3c0..e1eef2dbd9c3d28 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -931,8 +931,8 @@ void ObjCMethodDecl::setParamsAndSelLocs(ASTContext , unsigned Size = sizeof(ParmVarDecl *) * NumParams + sizeof(SourceLocation) * SelLocs.size(); ParamsAndSelLocs = C.Allocate(Size); - std::copy(Params.begin(), Params.end(), getParams()); - std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); + std::uninitialized_copy(Params.begin(), Params.end(), getParams()); + std::uninitialized_copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); } void ObjCMethodDecl::getSelectorLocs( diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index d553b3c6d78dedc..7bf1bcceccf584e 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -2002,13 +2002,15 @@ void ASTDeclReader::ReadCXXDefinitionData( case LCK_StarThis: case LCK_This: case LCK_VLAType: -*ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); +new (ToCapture) Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); +ToCapture++; break; case LCK_ByCopy: case LCK_ByRef: auto *Var = readDeclAs(); SourceLocation EllipsisLoc = readSourceLocation(); -*ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); +new (ToCapture) Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); +ToCapture++; break; } } >From ba88e02ced2a97bfe37396de3c0746a07339cb89 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Fri, 6 Oct 2023 07:58:05 +0300 Subject: [PATCH 2/2] Run clang-format --- clang/lib/Serialization/ASTReaderDecl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 7bf1bcceccf584e..6a2f607d916c472 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -2002,7 +2002,8 @@ void ASTDeclReader::ReadCXXDefinitionData( case LCK_StarThis: case LCK_This: case LCK_VLAType: -new (ToCapture) Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); +new (ToCapture) +Capture(Loc, IsImplicit, Kind, nullptr, SourceLocation()); ToCapture++; break; case LCK_ByCopy: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Add missing placement-new after Allocate() calls (PR #68382)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/68382 While working on #68377 inspecting `Allocate()` calls, I found out that there are couple of places where we forget to use placement-new to create objects in the allocated memory. >From d987a8523086ab8b6d49f395429afda75769a731 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Fri, 6 Oct 2023 07:20:07 +0300 Subject: [PATCH] [clang][NFC] Add missing placement-new after Allocate() calls --- clang/lib/AST/DeclCXX.cpp | 3 ++- clang/lib/AST/DeclObjC.cpp| 4 ++-- clang/lib/Serialization/ASTReaderDecl.cpp | 6 -- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 42bab4ed51b7290..a92b788366434ce 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -1484,7 +1484,8 @@ void CXXRecordDecl::setCaptures(ASTContext , if (Captures[I].isExplicit()) ++Data.NumExplicitCaptures; -*ToCapture++ = Captures[I]; +new (ToCapture) LambdaCapture(Captures[I]); +ToCapture++; } if (!lambdaIsDefaultConstructibleAndAssignable()) diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index e934a81d086e3c0..e1eef2dbd9c3d28 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -931,8 +931,8 @@ void ObjCMethodDecl::setParamsAndSelLocs(ASTContext , unsigned Size = sizeof(ParmVarDecl *) * NumParams + sizeof(SourceLocation) * SelLocs.size(); ParamsAndSelLocs = C.Allocate(Size); - std::copy(Params.begin(), Params.end(), getParams()); - std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); + std::uninitialized_copy(Params.begin(), Params.end(), getParams()); + std::uninitialized_copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); } void ObjCMethodDecl::getSelectorLocs( diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index d553b3c6d78dedc..7bf1bcceccf584e 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -2002,13 +2002,15 @@ void ASTDeclReader::ReadCXXDefinitionData( case LCK_StarThis: case LCK_This: case LCK_VLAType: -*ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); +new (ToCapture) Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); +ToCapture++; break; case LCK_ByCopy: case LCK_ByRef: auto *Var = readDeclAs(); SourceLocation EllipsisLoc = readSourceLocation(); -*ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); +new (ToCapture) Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); +ToCapture++; break; } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
@@ -1982,9 +1986,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase { Type(TypeClass tc, QualType canon, TypeDependence Dependence) : ExtQualsTypeCommonBase(this, canon.isNull() ? QualType(this_(), 0) : canon) { -static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase), +static_assert(sizeof(*this) <= 16 + sizeof(ExtQualsTypeCommonBase), "changing bitfields changed sizeof(Type)!"); Endilll wrote: This check has been broken, because `sizeof` didn't take into the account that `Type` objects are actually laid out in memory on 16-byte boundary, which results in 24 bytes of data and 8 bytes of padding. My change just affirms the status quo that Type is indeed takes 16 bytes more memory than `ExtQuals`, which has size 16. https://github.com/llvm/llvm-project/pull/68377 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/68377 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
Endilll wrote: Relevant code snippets: https://github.com/llvm/llvm-project/blob/777a6e6f10b2b90496d248b7fa904fce834484be/clang/lib/AST/ASTContext.cpp#L5813C1-L5816C33 https://github.com/llvm/llvm-project/blob/777a6e6f10b2b90496d248b7fa904fce834484be/clang/lib/AST/ASTContext.cpp#L4997C1-L5002C70 https://github.com/llvm/llvm-project/blob/777a6e6f10b2b90496d248b7fa904fce834484be/clang/lib/AST/ASTContext.cpp#L5192C1-L5195C66 https://github.com/llvm/llvm-project/pull/68377 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
Endilll wrote: CC @zygoloid as the author of ee0ce302c5eb4f26738f334f2fd8b165fa65dfca https://github.com/llvm/llvm-project/pull/68377 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/68377 >From 8503ff3e70e585a4a3597e3ee8111269f48105cc Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 5 Oct 2023 13:18:14 +0300 Subject: [PATCH 1/2] [clang] Align Type and ExtQuals on 16-byte boundary --- clang/include/clang/AST/Type.h | 17 ++--- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index a78d8f60462b231..4e98858f6e9432a 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1482,7 +1482,7 @@ class ExtQualsTypeCommonBase { /// in three low bits on the QualType pointer; a fourth bit records whether /// the pointer is an ExtQuals node. The extended qualifiers (address spaces, /// Objective-C GC attributes) are much more rare. -class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { +class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { // NOTE: changing the fast qualifiers should be straightforward as // long as you don't make 'const' non-fast. // 1. Qualifiers: @@ -1507,6 +1507,9 @@ class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { : ExtQualsTypeCommonBase(baseType, canon.isNull() ? QualType(this_(), 0) : canon), Quals(quals) { +static_assert(alignof(decltype(*this)) % TypeAlignment == 0, + "Insufficient alignment!"); + assert(Quals.hasNonFastQualifiers() && "ExtQuals created with no fast qualifiers"); assert(!Quals.hasFastQualifiers() @@ -1594,7 +1597,7 @@ enum class AutoTypeKeyword { /// /// Types, once created, are immutable. /// -class alignas(8) Type : public ExtQualsTypeCommonBase { +class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { public: enum TypeClass { #define TYPE(Class, Base) Class, @@ -1982,9 +1985,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase { Type(TypeClass tc, QualType canon, TypeDependence Dependence) : ExtQualsTypeCommonBase(this, canon.isNull() ? QualType(this_(), 0) : canon) { -static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase), +static_assert(sizeof(*this) <= 16 + sizeof(ExtQualsTypeCommonBase), "changing bitfields changed sizeof(Type)!"); -static_assert(alignof(decltype(*this)) % sizeof(void *) == 0, +static_assert(alignof(decltype(*this)) % TypeAlignment == 0, "Insufficient alignment!"); TypeBits.TC = tc; TypeBits.Dependence = static_cast(Dependence); @@ -5348,7 +5351,7 @@ class DeducedType : public Type { /// Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained /// by a type-constraint. -class alignas(8) AutoType : public DeducedType, public llvm::FoldingSetNode { +class AutoType : public DeducedType, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these ConceptDecl *TypeConstraintConcept; @@ -5456,7 +5459,7 @@ class DeducedTemplateSpecializationType : public DeducedType, /// TemplateArguments, followed by a QualType representing the /// non-canonical aliased type when the template is a type alias /// template. -class alignas(8) TemplateSpecializationType +class TemplateSpecializationType : public Type, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these @@ -5872,7 +5875,7 @@ class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { /// Represents a template specialization type whose template cannot be /// resolved, e.g. /// A::template B -class alignas(8) DependentTemplateSpecializationType +class DependentTemplateSpecializationType : public TypeWithKeyword, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these >From d08f8f92026026e9d02502307bd1810e516f4f06 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Fri, 6 Oct 2023 06:32:27 +0300 Subject: [PATCH 2/2] Run clang-format --- clang/include/clang/AST/Type.h | 12 +--- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 4e98858f6e9432a..2ba82d6624a 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1482,7 +1482,8 @@ class ExtQualsTypeCommonBase { /// in three low bits on the QualType pointer; a fourth bit records whether /// the pointer is an ExtQuals node. The extended qualifiers (address spaces, /// Objective-C GC attributes) are much more rare. -class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { +class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase, +public llvm::FoldingSetNode { // NOTE: changing the fast qualifiers
[clang] [clang][NFC] Specify Type and ExtQuals as having 16-byte alignment (PR #68377)
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/68377 While working on LLDB visualizer for `QualType`, I stumbled upon `Type` and `ExtQuals` defined with `alignas(8)`. Such alignment leaves only 3 lower bits available for pointer tagging, whereas `QualType` requires 4 (3 qualifiers + discriminator between `Type *` and `ExtQuals *`). Turns out `Type` and its derived classes are allocated with `TypeAlignment == 16` passed to `Allocate()`. So I'm removing misleading `alignas(8)` and fixing corresponding static asserts. Since they are already allocated with 16-byte alignment, this is a non-functional change. >From 8503ff3e70e585a4a3597e3ee8111269f48105cc Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Thu, 5 Oct 2023 13:18:14 +0300 Subject: [PATCH] [clang] Align Type and ExtQuals on 16-byte boundary --- clang/include/clang/AST/Type.h | 17 ++--- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index a78d8f60462b231..4e98858f6e9432a 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1482,7 +1482,7 @@ class ExtQualsTypeCommonBase { /// in three low bits on the QualType pointer; a fourth bit records whether /// the pointer is an ExtQuals node. The extended qualifiers (address spaces, /// Objective-C GC attributes) are much more rare. -class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { +class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { // NOTE: changing the fast qualifiers should be straightforward as // long as you don't make 'const' non-fast. // 1. Qualifiers: @@ -1507,6 +1507,9 @@ class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { : ExtQualsTypeCommonBase(baseType, canon.isNull() ? QualType(this_(), 0) : canon), Quals(quals) { +static_assert(alignof(decltype(*this)) % TypeAlignment == 0, + "Insufficient alignment!"); + assert(Quals.hasNonFastQualifiers() && "ExtQuals created with no fast qualifiers"); assert(!Quals.hasFastQualifiers() @@ -1594,7 +1597,7 @@ enum class AutoTypeKeyword { /// /// Types, once created, are immutable. /// -class alignas(8) Type : public ExtQualsTypeCommonBase { +class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { public: enum TypeClass { #define TYPE(Class, Base) Class, @@ -1982,9 +1985,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase { Type(TypeClass tc, QualType canon, TypeDependence Dependence) : ExtQualsTypeCommonBase(this, canon.isNull() ? QualType(this_(), 0) : canon) { -static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase), +static_assert(sizeof(*this) <= 16 + sizeof(ExtQualsTypeCommonBase), "changing bitfields changed sizeof(Type)!"); -static_assert(alignof(decltype(*this)) % sizeof(void *) == 0, +static_assert(alignof(decltype(*this)) % TypeAlignment == 0, "Insufficient alignment!"); TypeBits.TC = tc; TypeBits.Dependence = static_cast(Dependence); @@ -5348,7 +5351,7 @@ class DeducedType : public Type { /// Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained /// by a type-constraint. -class alignas(8) AutoType : public DeducedType, public llvm::FoldingSetNode { +class AutoType : public DeducedType, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these ConceptDecl *TypeConstraintConcept; @@ -5456,7 +5459,7 @@ class DeducedTemplateSpecializationType : public DeducedType, /// TemplateArguments, followed by a QualType representing the /// non-canonical aliased type when the template is a type alias /// template. -class alignas(8) TemplateSpecializationType +class TemplateSpecializationType : public Type, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these @@ -5872,7 +5875,7 @@ class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { /// Represents a template specialization type whose template cannot be /// resolved, e.g. /// A::template B -class alignas(8) DependentTemplateSpecializationType +class DependentTemplateSpecializationType : public TypeWithKeyword, public llvm::FoldingSetNode { friend class ASTContext; // ASTContext creates these ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
@@ -5910,6 +5910,30 @@ static void handleBuiltinAliasAttr(Sema , Decl *D, D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); } +static void handleDebugInfoTypeAttr(Sema , Decl *D, const ParsedAttr ) { + if (!AL.hasParsedType()) { +S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; +return; + } + + TypeSourceInfo *ParmTSI = nullptr; + QualType type = S.GetTypeFromParser(AL.getTypeArg(), ); + assert(ParmTSI && "no type source info for attribute argument"); + + if (type->isEnumeralType()) { +QualType BitfieldType = llvm::cast(D)->getType(); Endilll wrote: Fixed https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
@@ -0,0 +1,14 @@ +// RUN: %clang -target x86_64-linux -g -S -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -verify -DMISMATCH %s Endilll wrote: Tests are split now. `const` case is now checked and working as expected (qualifiers are ignored). https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
@@ -5910,6 +5910,30 @@ static void handleBuiltinAliasAttr(Sema , Decl *D, D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); } +static void handleDebugInfoTypeAttr(Sema , Decl *D, const ParsedAttr ) { + if (!AL.hasParsedType()) { +S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; +return; + } Endilll wrote: I don't know what do we do in generated boilerplate, but without this check, test that pass no arguments crashes the compiler in this function. https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
@@ -5910,6 +5910,30 @@ static void handleBuiltinAliasAttr(Sema , Decl *D, D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); } +static void handleDebugInfoTypeAttr(Sema , Decl *D, const ParsedAttr ) { + if (!AL.hasParsedType()) { +S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; +return; + } + + TypeSourceInfo *ParmTSI = nullptr; + QualType type = S.GetTypeFromParser(AL.getTypeArg(), ); Endilll wrote: Fixed https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/69104 >From 976aa5c8f3d936a15e7123069a49d97ad3bf7a05 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Sun, 15 Oct 2023 13:14:55 +0300 Subject: [PATCH 1/5] [clang] Add clang::debug_info_type attribute --- clang/include/clang/Basic/Attr.td | 11 clang/include/clang/Basic/AttrDocs.td | 12 + .../clang/Basic/DiagnosticSemaKinds.td| 2 ++ clang/lib/CodeGen/CGDebugInfo.cpp | 2 ++ clang/lib/Sema/SemaDeclAttr.cpp | 26 +++ .../CodeGen/debug-info-debug-info-type.cpp| 14 ++ 6 files changed, 67 insertions(+) create mode 100644 clang/test/CodeGen/debug-info-debug-info-type.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 5c9eb7b8a981037..024421c0583c019 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -107,6 +107,10 @@ def NonBitField : SubsetSubjectisBitField()}], "non-bit-field non-static data members">; +def BitField : SubsetSubjectisBitField()}], + "bit-field non-static data members">; + def NonStaticCXXMethod : SubsetSubjectisStatic()}], "non-static member functions">; @@ -4264,3 +4268,10 @@ def CountedBy : InheritableAttr { void setCountedByFieldLoc(SourceRange Loc) { CountedByFieldLoc = Loc; } }]; } + +def DebugInfoType: InheritableAttr { + let Spellings = [Clang<"debug_info_type">]; + let Subjects = SubjectList<[BitField], ErrorDiag>; + let Args = [TypeArgument<"Type", 1>]; + let Documentation = [DebugInfoTypeDocumentation]; +} diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 9f9991bdae36155..6cceba1e0e0ad01 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7219,6 +7219,18 @@ its underlying representation to be a WebAssembly ``funcref``. }]; } +def DebugInfoTypeDocumentation : Documentation { + let Category = DocCatField; + let Content = [{ +This attribute allows to alter type of a bitfield in debug information. +Such a need might arise when bitfield is intended to store an enumeration value, +but has to be specified as having enumeration's underlying type, in order to +facilitate compiler optimizations. But this also causes underlying type to be +emitted in debug information, making it hard for debuggers to map bitfield's +value back to enumeration. This attribute helps with this. + }]; +} + def CleanupDocs : Documentation { let Category = DocCatType; let Content = [{ diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index e85cd4d1a1ddc0d..b5c73494df367a6 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3153,6 +3153,8 @@ def err_invalid_branch_protection_spec : Error< "invalid or misplaced branch protection specification '%0'">; def warn_unsupported_branch_protection_spec : Warning< "unsupported branch protection specification '%0'">, InGroup; +def warn_attribute_underlying_type_mismatch : Warning< + "underlying type %0 of enumeration %1 doesn't match bitfield type %2">; def warn_unsupported_target_attribute : Warning<"%select{unsupported|duplicate|unknown}0%select{| CPU|" diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index c73a63e12f03aab..85aedd87b21d41e 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1497,6 +1497,8 @@ CGDebugInfo::createBitFieldType(const FieldDecl *BitFieldDecl, llvm::DIScope *RecordTy, const RecordDecl *RD) { StringRef Name = BitFieldDecl->getName(); QualType Ty = BitFieldDecl->getType(); + if (BitFieldDecl->hasAttr()) +Ty = BitFieldDecl->getAttr()->getType(); SourceLocation Loc = BitFieldDecl->getLocation(); llvm::DIFile *VUnit = getOrCreateFile(Loc); llvm::DIType *DebugType = getOrCreateType(Ty, VUnit); diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index feb02cad9080e3e..8d58968b7f985c8 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -5910,6 +5910,28 @@ static void handleBuiltinAliasAttr(Sema , Decl *D, D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); } +static void handleDebugInfoTypeAttr(Sema , Decl *D, const ParsedAttr ) { + if (!AL.hasParsedType()) { +S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; +return; + } + + TypeSourceInfo *ParmTSI = nullptr; + QualType type = S.GetTypeFromParser(AL.getTypeArg(), ); + assert(ParmTSI && "no type source info for attribute argument"); + + if (type->isEnumeralType()) { +QualType BitfieldType =
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
@@ -5910,6 +5910,30 @@ static void handleBuiltinAliasAttr(Sema , Decl *D, D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); } +static void handleDebugInfoTypeAttr(Sema , Decl *D, const ParsedAttr ) { + if (!AL.hasParsedType()) { +S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; +return; + } + + TypeSourceInfo *ParmTSI = nullptr; + QualType type = S.GetTypeFromParser(AL.getTypeArg(), ); + assert(ParmTSI && "no type source info for attribute argument"); + + if (type->isEnumeralType()) { +QualType BitfieldType = llvm::cast(D)->getType(); +QualType EnumUnderlyingType = +type->getAs()->getDecl()->getIntegerType(); +if (EnumUnderlyingType != BitfieldType) { Endilll wrote: > and only prevent situations where the specified type is not an enumeration or > integral type. > This ALSO makes me wonder if forcing it to be an enum type is necessary. I intentionally haven't been restricting the set of types that can be passed as the argument to `preferred_type`. This makes even more sense now that we are going with more generic name. I'm just making sure that enum-related diagnostics are triggered only when enum was passed by the user. > Another case we should consider would be whether we want to allow signed > unsigned mismatches: > I think in the signed/unsigned mismatch, we should allow it (thanks to the > layout rules) > 1 enum that can represent a negative value I disagree. We shouldn't pretend that our enums can hold negative values, while we store them in unsigned bit-fields (save for rare exceptions, if any). Now that we are not bound by C++98 compilers, I believe we should propagate underlying type of our enums from bit-field type they are stored in (usually `unsigned`, `uint64_t` for `DeclBase.h`), and deal with negative values at enumerator declaration (I guess we'll have to explicitly cast them to the underlying type). I can do that while adding `clang::preferred_type` to bit-fields. Ideally I'd propagate bit-field width as well, but that doesn't seem possible at the moment: https://github.com/llvm/llvm-project/pull/69104#issuecomment-1770189229 https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
@@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -verify %s + +struct A { + enum E : unsigned {}; + [[clang::preferred_type(E)]] unsigned b : 2; + [[clang::preferred_type(E)]] int b2 : 2; + // expected-warning@-1 {{underlying type 'unsigned int' of enumeration 'E' doesn't match bit-field type 'int'}} + [[clang::preferred_type(E)]] const unsigned b3 : 2; + [[clang::preferred_type(bool)]] unsigned b4 : 1; + [[clang::preferred_type(bool)]] unsigned b5 : 2; + // expected-warning@-1 {{bit-field that holds a boolean value should have width of 1 instead of 2}} + [[clang::preferred_type()]] unsigned b6 : 2; + // expected-error@-1 {{'preferred_type' attribute takes one argument}} + [[clang::preferred_type]] unsigned b7 : 2; + // expected-error@-1 {{'preferred_type' attribute takes one argument}} + [[clang::preferred_type(E, int)]] unsigned b8 : 2; Endilll wrote: @AaronBallman On the topic of automatically-generated diagnostics: ``` /home/user/endill/llvm-project/clang/test/Sema/attr-preferred-type.cpp:16:28: error: expected ')' 16 | [[clang::preferred_type(E, int)]] unsigned b8 : 2; |^ |) /home/user/endill/llvm-project/clang/test/Sema/attr-preferred-type.cpp:16:33: error: expected ',' 16 | [[clang::preferred_type(E, int)]] unsigned b8 : 2; | ^ | , /home/user/endill/llvm-project/clang/test/Sema/attr-preferred-type.cpp:16:30: warning: unknown attribute 'int' ignored [-Wunknown-attributes] 16 | [[clang::preferred_type(E, int)]] unsigned b8 : 2; | ^~~ ``` 3 diagnostics are issued, 0 says that wrong number of attribute arguments is passed. https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/69104 >From 976aa5c8f3d936a15e7123069a49d97ad3bf7a05 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov Date: Sun, 15 Oct 2023 13:14:55 +0300 Subject: [PATCH 1/4] [clang] Add clang::debug_info_type attribute --- clang/include/clang/Basic/Attr.td | 11 clang/include/clang/Basic/AttrDocs.td | 12 + .../clang/Basic/DiagnosticSemaKinds.td| 2 ++ clang/lib/CodeGen/CGDebugInfo.cpp | 2 ++ clang/lib/Sema/SemaDeclAttr.cpp | 26 +++ .../CodeGen/debug-info-debug-info-type.cpp| 14 ++ 6 files changed, 67 insertions(+) create mode 100644 clang/test/CodeGen/debug-info-debug-info-type.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 5c9eb7b8a981037..024421c0583c019 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -107,6 +107,10 @@ def NonBitField : SubsetSubjectisBitField()}], "non-bit-field non-static data members">; +def BitField : SubsetSubjectisBitField()}], + "bit-field non-static data members">; + def NonStaticCXXMethod : SubsetSubjectisStatic()}], "non-static member functions">; @@ -4264,3 +4268,10 @@ def CountedBy : InheritableAttr { void setCountedByFieldLoc(SourceRange Loc) { CountedByFieldLoc = Loc; } }]; } + +def DebugInfoType: InheritableAttr { + let Spellings = [Clang<"debug_info_type">]; + let Subjects = SubjectList<[BitField], ErrorDiag>; + let Args = [TypeArgument<"Type", 1>]; + let Documentation = [DebugInfoTypeDocumentation]; +} diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 9f9991bdae36155..6cceba1e0e0ad01 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7219,6 +7219,18 @@ its underlying representation to be a WebAssembly ``funcref``. }]; } +def DebugInfoTypeDocumentation : Documentation { + let Category = DocCatField; + let Content = [{ +This attribute allows to alter type of a bitfield in debug information. +Such a need might arise when bitfield is intended to store an enumeration value, +but has to be specified as having enumeration's underlying type, in order to +facilitate compiler optimizations. But this also causes underlying type to be +emitted in debug information, making it hard for debuggers to map bitfield's +value back to enumeration. This attribute helps with this. + }]; +} + def CleanupDocs : Documentation { let Category = DocCatType; let Content = [{ diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index e85cd4d1a1ddc0d..b5c73494df367a6 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3153,6 +3153,8 @@ def err_invalid_branch_protection_spec : Error< "invalid or misplaced branch protection specification '%0'">; def warn_unsupported_branch_protection_spec : Warning< "unsupported branch protection specification '%0'">, InGroup; +def warn_attribute_underlying_type_mismatch : Warning< + "underlying type %0 of enumeration %1 doesn't match bitfield type %2">; def warn_unsupported_target_attribute : Warning<"%select{unsupported|duplicate|unknown}0%select{| CPU|" diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index c73a63e12f03aab..85aedd87b21d41e 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1497,6 +1497,8 @@ CGDebugInfo::createBitFieldType(const FieldDecl *BitFieldDecl, llvm::DIScope *RecordTy, const RecordDecl *RD) { StringRef Name = BitFieldDecl->getName(); QualType Ty = BitFieldDecl->getType(); + if (BitFieldDecl->hasAttr()) +Ty = BitFieldDecl->getAttr()->getType(); SourceLocation Loc = BitFieldDecl->getLocation(); llvm::DIFile *VUnit = getOrCreateFile(Loc); llvm::DIType *DebugType = getOrCreateType(Ty, VUnit); diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index feb02cad9080e3e..8d58968b7f985c8 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -5910,6 +5910,28 @@ static void handleBuiltinAliasAttr(Sema , Decl *D, D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); } +static void handleDebugInfoTypeAttr(Sema , Decl *D, const ParsedAttr ) { + if (!AL.hasParsedType()) { +S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; +return; + } + + TypeSourceInfo *ParmTSI = nullptr; + QualType type = S.GetTypeFromParser(AL.getTypeArg(), ); + assert(ParmTSI && "no type source info for attribute argument"); + + if (type->isEnumeralType()) { +QualType BitfieldType =
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
@@ -7219,6 +7219,18 @@ its underlying representation to be a WebAssembly ``funcref``. }]; } +def DebugInfoTypeDocumentation : Documentation { + let Category = DocCatField; + let Content = [{ +This attribute allows to alter type of a bitfield in debug information. +Such a need might arise when bitfield is intended to store an enumeration value, +but has to be specified as having enumeration's underlying type, in order to +facilitate compiler optimizations. But this also causes underlying type to be +emitted in debug information, making it hard for debuggers to map bitfield's +value back to enumeration. This attribute helps with this. + }]; Endilll wrote: Applied the text suggested by Aaron https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
@@ -107,6 +107,10 @@ def NonBitField : SubsetSubjectisBitField()}], "non-bit-field non-static data members">; +def BitField : SubsetSubjectisBitField()}], + "bit-field non-static data members">; Endilll wrote: Fixed https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
@@ -3153,6 +3153,8 @@ def err_invalid_branch_protection_spec : Error< "invalid or misplaced branch protection specification '%0'">; def warn_unsupported_branch_protection_spec : Warning< "unsupported branch protection specification '%0'">, InGroup; +def warn_attribute_underlying_type_mismatch : Warning< + "underlying type %0 of enumeration %1 doesn't match bitfield type %2">; Endilll wrote: Fixed https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
@@ -7219,6 +7219,18 @@ its underlying representation to be a WebAssembly ``funcref``. }]; } +def DebugInfoTypeDocumentation : Documentation { + let Category = DocCatField; + let Content = [{ +This attribute allows to alter type of a bitfield in debug information. +Such a need might arise when bitfield is intended to store an enumeration value, +but has to be specified as having enumeration's underlying type, in order to +facilitate compiler optimizations. But this also causes underlying type to be +emitted in debug information, making it hard for debuggers to map bitfield's +value back to enumeration. This attribute helps with this. + }]; Endilll wrote: Thank you very much for rewriting it! https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::debug_info_type attribute for bitfields (PR #69104)
@@ -5910,6 +5910,28 @@ static void handleBuiltinAliasAttr(Sema , Decl *D, D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); } +static void handleDebugInfoTypeAttr(Sema , Decl *D, const ParsedAttr ) { + if (!AL.hasParsedType()) { +S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; +return; + } + + TypeSourceInfo *ParmTSI = nullptr; + QualType type = S.GetTypeFromParser(AL.getTypeArg(), ); + assert(ParmTSI && "no type source info for attribute argument"); + + if (type->isEnumeralType()) { +QualType BitfieldType = llvm::cast(D)->getType(); +QualType EnumUnderlyingType = type->getAs()->getDecl()->getIntegerType(); +if (EnumUnderlyingType != BitfieldType) { + S.Diag(AL.getLoc(), diag::warn_attribute_underlying_type_mismatch) << EnumUnderlyingType << type << BitfieldType; Endilll wrote: @AaronBallman @erichkeane Can I request some attention here? https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
@@ -5910,6 +5910,30 @@ static void handleBuiltinAliasAttr(Sema , Decl *D, D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); } +static void handleDebugInfoTypeAttr(Sema , Decl *D, const ParsedAttr ) { + if (!AL.hasParsedType()) { +S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; +return; + } + + TypeSourceInfo *ParmTSI = nullptr; + QualType type = S.GetTypeFromParser(AL.getTypeArg(), ); + assert(ParmTSI && "no type source info for attribute argument"); + + if (type->isEnumeralType()) { +QualType BitfieldType = llvm::cast(D)->getType(); +QualType EnumUnderlyingType = +type->getAs()->getDecl()->getIntegerType(); +if (EnumUnderlyingType != BitfieldType) { Endilll wrote: We don't really care about the underlying type compiler deduced, right? We just shove them into unsigned bit-fields. All the more reason to move towards fixed underlying type, I believe. https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
Endilll wrote: Taking the example above, I think it would have to look the following way to fully complement a check for bit-field width in `preferred_type`: ```cpp enum StoredNameKind : unsigned _BitInt(3) { StoredIdentifier = 0, StoredObjCZeroArgSelector = Selector::ZeroArg, StoredObjCOneArgSelector = Selector::OneArg, StoredCXXConstructorName = 3, StoredCXXDestructorName = 4, StoredCXXConversionFunctionName = 5, StoredCXXOperatorName = 6, StoredDeclarationNameExtra = Selector::MultiArg, PtrMask = 7, [[clang::non_storable]] UncommonNameKindOffset = 8 }; class DeclarationName { [[clang::preferred_type(StoredNameKind)]] unsigned Kind : 3; }; ``` Breaking it down: 1) `3` in `unsigned _BitInt(3)` is checked against enumerator values to ensure it's sufficient 2) `UncommonNameKindOffset` does not trigger diagnostic above, because it's marked as (newly-invented) `non_storable` 3) `unsigned` and `3` in `unsigned Kind : 3` are checked against `unsigned _BitInt(3)` because of `preferred_type` 4) (in other code) `Kind = UncommonNameKindOffset` will be catched, because of `non_storable`. I think we can robustly diagnose new enumerators if the code is written this way. Implementation seem trivial to me. Today `_BitInt(3)` in underlying type of an enum has poor support across compilers we support. It doesn't block implementation of this idea, but make it a bit less trivial to implement in performant manner, and makes enum declaration a bit less declarative. https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
@@ -5910,6 +5910,28 @@ static void handleBuiltinAliasAttr(Sema , Decl *D, D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); } +static void handleDebugInfoTypeAttr(Sema , Decl *D, const ParsedAttr ) { + if (!AL.hasParsedType()) { +S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; +return; + } + + TypeSourceInfo *ParmTSI = nullptr; + QualType type = S.GetTypeFromParser(AL.getTypeArg(), ); + assert(ParmTSI && "no type source info for attribute argument"); + + if (type->isEnumeralType()) { +QualType BitfieldType = llvm::cast(D)->getType(); +QualType EnumUnderlyingType = type->getAs()->getDecl()->getIntegerType(); +if (EnumUnderlyingType != BitfieldType) { + S.Diag(AL.getLoc(), diag::warn_attribute_underlying_type_mismatch) << EnumUnderlyingType << type << BitfieldType; Endilll wrote: > We have getTypeArg() (which is a pretty bad code smell because this only > allows one type argument for an attribute -- it would probably be a > reasonable idea to refactor this so it works through getArg() at some point. I think it comes from `let Args = [TypeArgument<"Type", 1>];`, but yeah, it's a confusing naming. I'm open for suggestions. https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
Endilll wrote: >>@erichkeane I guess you'd be pretty happy if our enums were declared the >> following way: >Not really? That doesn't gain us the 'we must change where this is stored' >situation like a preferred_type attribute would/could. We MIGHT be able to get >away with a comment on top of that with a list of places that needs to ALSO be >changed, but we end up missing similar comments today anyway. I meant `unsigned _BitInt(N)` underlying type to complement `preferred_type`'s check that a bit-field is wide enough. Otherwise such a check will have to incorporate heuristics to prevent false-positives for cases like the following: https://github.com/llvm/llvm-project/blob/180eae1f1e5a08595ed2278d93f01fb321284649/clang/include/clang/AST/DeclarationName.h#L174-L185 One might argue that this particular case might be resolved by transition to `PointerIntPair`, which is true. It's just the only case I was able to find. I have a recollection of an enum that ends with `Size` enumerator, possibly TableGen'ed, but I can't find it. https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
Endilll wrote: > when does someone have an enum value that they don't intend to ever be in the > enum In my previous comments (https://github.com/llvm/llvm-project/pull/69104#issuecomment-1771167758, https://github.com/llvm/llvm-project/pull/69104#issuecomment-1771204043) I provided an example of `StoredNameKind` enum that has enumerators 0 through 8 (9 total, 4 bits to store), but we store it in a bit-fields of width 3, because the last enumerator is there to count other enumerators, and is used for offset purposes. If we apply `-Wbitfield-enum-conversion` to it as-is, we get a false-positive: https://godbolt.org/z/4xPs6qPTY. https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
Endilll wrote: > which brings up an additional concern/thing to deal with for the non_storable > attribute (that is, do we apply it to assignments? how about > exact-assignments like you've done there?). Conservative approach would be to issue diagnostics based on `non_storable` only when LHS of assignment was checked taking it into account. In other words, LHS is a bit-field with `preferred_type`, so `non_storable` enumerator was excluded when computing how many bits are required to store the enum. https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
Endilll wrote: > See how on the assignment to a bitfield we check to make sure the largest > value of the enum will fit in the bitfield? I'm saying I want us to do this > EARLIER, on declaration with this attribute. I totally do. Thank you for pointing out to `-Wbitfield-enum-conversion`! But you should be able to see in my example above that we need a way to exclude an enumerator from this check (in my example it's `[[clang::non_storable]]` applied to `UncommonNameKindOffset`), otherwise we'll get false-positives. https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
Endilll wrote: > While I think that warning is accurate, I somewhat question the value of the > 'bool' as working on this type I'm not sure what you mean by "working" here, but I'd like to highlight that we have hundreds of single-bit bit-fields across Clang that would benefit from `[[clang::preferred_type(bool)]]`. > as, I'm not sure what it really means to put a non-enum here? When it was `clang::debug_info_type`, the meaning was as simple as "I want the value of this bit-field to be interpreted as T". Now that we moved to `preferred_type`, there might be more interpretations. > What types ARE we allowing in this now? As I mentioned in https://github.com/llvm/llvm-project/pull/69104#discussion_r1365269451, I'm not putting any restrictions on type parameter of the attribute, which makes even more sense for more generic `preferred_type`. But I'm confused by the fact you are raising this question. In https://github.com/llvm/llvm-project/pull/69104#discussion_r1364432624, you wrote: > I can see potential value of a "OpaqueValueOfStruct" storage type thing, that > perhaps we should just 'trust' that the user is doing something sensible with > it. I read that as you being in favor of trusting user to pass whatever type they want to `preferred_type`. I feel like I'm getting mixed signals from you on this topic, so it'd be nice if you can make yourself clear. > I think the wording of the diagnostic is perhaps awkward, so we should > bikeshed that as well Sure. > though I'm on the fence about the diagnostic existing at all. On one hand, > this would be such a special case, as typically 'too large' for the type > isn't an issue for any reason. On the other, the 'bool' case is perhaps > uniquely an issue. As we are going to attach semantic type information to our bit-fields, I see an opportunity to raise valid questions like "Why do you need 2 bits to hold a boolean value?". If intention is to reserve bits for future extensions, I believe it should be stated more explicitly via something along the lines of `enum E { False, True, Reserved = 3}`. > What about if the person prefers the type be 'char', but has it be a size of > 9? THIS is a case where it is reasonable (consider cases where you need to > store the result of one of those calls to the C library that returns 'an int > that is either a char or -1'). I'd like to state upfront that I'm diagnosing only booleans, because I see how it can help maintaining Clang headers. Now, on `CHAR_BIT == 8` platform, your example results in 8 bits for value, and 1 bit of padding (http://eel.is/c++draft/class.bit#1.sentence-6). I find such bit-field somewhat strange (why can't padding be declared explicitly via unnamed bit-field?), but maybe I haven't seen enough bit-fields in my life to appreciate it. > So I guess I'm really questioning how accurate/error-free we could make that > diagnostic. In it's current form (only `bool` is checked), I consider it rather accurate. I'm yet to see a use case where `[[clang::preferred_type(bool)]] unsigned Predicate : 2` is the best solution available. https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
Endilll wrote: > However, will this actually work in practice in the debugger? If not, perhaps > we should limit to just integer and enumeration types for now, leaving the > extension for the future. I composed an example of that: ```cpp struct A { short a1; short a2; }; struct B { [[clang::preferred_type(A)]] unsigned b1 : 32 = 0x000F'000C; }; int main() { B b; return b.b1; } ``` Nightly build of LLDB from apt.llvm.org handles it just fine: ``` Process 2755547 stopped * thread #1, name = 'test-preferred-', stop reason = step in frame #0: 0x5148 test-preferred-type`main at test.cxx:13:14 10 int main() 11 { 12 B b; -> 13 return b.b1; 14 } (lldb) v -T (B) b = { (A:32) b1 = { (short) a1 = 12 (short) a2 = 15 } } ``` @erichkeane Do you still insist on restricting type argument to integral and enumeration types? https://github.com/llvm/llvm-project/pull/69104 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits