[clang] a07dbf1 - [clang][NFC] Annotate `PrettyPrinter.h` with `preferred_type`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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] c032225 - [clang][NFC] Annotate `RawCommentList.h` with `preferred_type`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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] acb714c - [clang][NFC] Annotate `DeclTemplate.h` with `preferred_type`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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] f1fdbcb - [clang]]NFC] Annotate `DeclObjC.h` with `preferred_type`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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] 13023ed - [clang][NFC] Annotate `DeclFriend.h` with `preferred_type`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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] 61d17b1 - [clang][NFC] Annotate `DeclCXX.h` with `preferred_type`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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] [clang] Change representation of CurLexerKind (PR #70381)

2023-11-05 Thread via cfe-commits

https://github.com/serge-sans-paille closed 
https://github.com/llvm/llvm-project/pull/70381
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 95dd178 - [clang] Change representation of CurLexerKind (#70381)

2023-11-05 Thread via cfe-commits

Author: serge-sans-paille
Date: 2023-11-06T07:13:05Z
New Revision: 95dd17848383315050a5d64051bd695d0a653c51

URL: 
https://github.com/llvm/llvm-project/commit/95dd17848383315050a5d64051bd695d0a653c51
DIFF: 
https://github.com/llvm/llvm-project/commit/95dd17848383315050a5d64051bd695d0a653c51.diff

LOG: [clang] Change representation of CurLexerKind (#70381)

Previous representation used an enumeration combined to a switch to
dispatch to the appropriate lexer.

Use function pointer so that the dispatching is just an indirect call,
which is actually better because lexing is a costly task compared to a
function call.

This also makes the code slightly cleaner, speedup on compile time
tracker are consistent and range form -0.05% to -0.20% for NewPM-O0-g,
see


https://llvm-compile-time-tracker.com/compare.php?from=f9906508bc4f05d3950e2219b4c56f6c078a61ef=608c85ec1283638db949d73e062bcc3355001ce4=instructions:u

Considering just the preprocessing task, preprocessing the sqlite
amalgametion takes -0.6% instructions (according to valgrind
--tool=callgrind)

-

Co-authored-by: serge-sans-paille 
Co-authored-by: cor3ntin 

Added: 


Modified: 
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/PPCaching.cpp
clang/lib/Lex/PPLexerChange.cpp
clang/lib/Lex/Preprocessor.cpp
clang/utils/ClangVisualizers/clang.natvis

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 4a99447e757c6ac..4ec21a8b6be2c85 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -751,13 +751,8 @@ class Preprocessor {
   std::unique_ptr CurTokenLexer;
 
   /// The kind of lexer we're currently working with.
-  enum CurLexerKind {
-CLK_Lexer,
-CLK_TokenLexer,
-CLK_CachingLexer,
-CLK_DependencyDirectivesLexer,
-CLK_LexAfterModuleImport
-  } CurLexerKind = CLK_Lexer;
+  typedef bool (*LexerCallback)(Preprocessor &, Token &);
+  LexerCallback CurLexerCallback = _Lexer;
 
   /// If the current lexer is for a submodule that is being built, this
   /// is that submodule.
@@ -767,7 +762,7 @@ class Preprocessor {
   /// \#included, and macros currently being expanded from, not counting
   /// CurLexer/CurTokenLexer.
   struct IncludeStackInfo {
-enum CurLexerKind   CurLexerKind;
+LexerCallback   CurLexerCallback;
 Module *TheSubmodule;
 std::unique_ptr  TheLexer;
 PreprocessorLexer  *ThePPLexer;
@@ -776,12 +771,12 @@ class Preprocessor {
 
 // The following constructors are completely useless copies of the default
 // versions, only needed to pacify MSVC.
-IncludeStackInfo(enum CurLexerKind CurLexerKind, Module *TheSubmodule,
+IncludeStackInfo(LexerCallback CurLexerCallback, Module *TheSubmodule,
  std::unique_ptr &,
  PreprocessorLexer *ThePPLexer,
  std::unique_ptr &,
  ConstSearchDirIterator TheDirLookup)
-: CurLexerKind(std::move(CurLexerKind)),
+: CurLexerCallback(std::move(CurLexerCallback)),
   TheSubmodule(std::move(TheSubmodule)), TheLexer(std::move(TheLexer)),
   ThePPLexer(std::move(ThePPLexer)),
   TheTokenLexer(std::move(TheTokenLexer)),
@@ -1901,7 +1896,7 @@ class Preprocessor {
   /// Determine whether it's possible for a future call to Lex to produce an
   /// annotation token created by a previous call to EnterAnnotationToken.
   bool mightHavePendingAnnotationTokens() {
-return CurLexerKind != CLK_Lexer;
+return CurLexerCallback != CLK_Lexer;
   }
 
   /// Update the current token to represent the provided
@@ -2430,8 +2425,9 @@ class Preprocessor {
   friend void TokenLexer::ExpandFunctionArguments();
 
   void PushIncludeMacroStack() {
-assert(CurLexerKind != CLK_CachingLexer && "cannot push a caching lexer");
-IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
+assert(CurLexerCallback != CLK_CachingLexer &&
+   "cannot push a caching lexer");
+IncludeMacroStack.emplace_back(CurLexerCallback, CurLexerSubmodule,
std::move(CurLexer), CurPPLexer,
std::move(CurTokenLexer), CurDirLookup);
 CurPPLexer = nullptr;
@@ -2443,7 +2439,7 @@ class Preprocessor {
 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
 CurDirLookup  = IncludeMacroStack.back().TheDirLookup;
 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
-CurLexerKind = IncludeMacroStack.back().CurLexerKind;
+CurLexerCallback = IncludeMacroStack.back().CurLexerCallback;
 IncludeMacroStack.pop_back();
   }
 
@@ -2899,6 +2895,26 @@ class Preprocessor {
   /// \return true iff this PP is currently in a "-Wunsafe-buffer-usage"
   ///  opt-out region
   bool 

[clang] a5d2570 - [clang][NFC] Annotate ``DependentDiagnostic.h` with `preferred_type`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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] 421d6cc - [clang][NFC] Annotate `CXXInheritance.h` with `preferred_type`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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] 24faf3b - [clang][NFC] Annotate `Attr.h` with `preferred_type`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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] [Driver][LTO] Copy fix empty stats filename to AVR, FreeBSD, Fuchsia (PR #71359)

2023-11-05 Thread Brad Smith via cfe-commits

https://github.com/brad0 closed https://github.com/llvm/llvm-project/pull/71359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1881832 - [Driver][LTO] Copy fix empty stats filename to AVR, FreeBSD, Fuchsia (#71359)

2023-11-05 Thread via cfe-commits

Author: Brad Smith
Date: 2023-11-06T01:56:27-05:00
New Revision: 1881832994840baa6e42f908b8822ce4d15ab632

URL: 
https://github.com/llvm/llvm-project/commit/1881832994840baa6e42f908b8822ce4d15ab632
DIFF: 
https://github.com/llvm/llvm-project/commit/1881832994840baa6e42f908b8822ce4d15ab632.diff

LOG: [Driver][LTO] Copy fix empty stats filename to AVR, FreeBSD, Fuchsia 
(#71359)

Copy 85451f486d8144f8aacd94a47802c77da5a04d27 over to AVR, FreeBSD and
Fuchsia.

Added: 


Modified: 
clang/lib/Driver/ToolChains/AVR.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/test/Driver/save-stats.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 27505b9462c4492..a4ce2258c3d812f 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -513,7 +513,15 @@ void AVR::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo ) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(TC, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 

diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 0b70ac7b76e6765..685616a9bfd4662 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -264,7 +264,15 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo ) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 

diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 00de63c15522973..6525cf8356d184b 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -138,7 +138,15 @@ void fuchsia::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo ) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 

diff  --git a/clang/test/Driver/save-stats.c b/clang/test/Driver/save-stats.c
index 2208c229b91e56c..7b35b80b9f629f8 100644
--- a/clang/test/Driver/save-stats.c
+++ b/clang/test/Driver/save-stats.c
@@ -19,14 +19,20 @@
 // RUN: not %clang -target x86_64-apple-darwin -save-stats=bla -c %s -### 2>&1 
| FileCheck %s -check-prefix=CHECK-INVALID
 // CHECK-INVALID: invalid value 'bla' in '-save-stats=bla'
 
-// RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-linux -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
 // Previously `-plugin-opt=stats-file` would use empty filename if a linker 
flag (i.e. -Wl) is presented before any input filename.
-// RUN: %clang --target=x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-linux -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-freebsd -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-freebsd -save-stats -flto -o 
obj/dir/save-stats.exe 

[clang] 17db462 - [clang][NFC] Annotate `TemplateBase.h` with `preferred_type`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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] b89aadf - [clang][NFC] Annotate `TemplateName.h` with `preferred_type`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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] [Driver][LTO] Copy fix empty stats filename to AVR, FreeBSD, Fuchsia (PR #71359)

2023-11-05 Thread Brad Smith via cfe-commits

brad0 wrote:

AIX, AMDGPU, HIPAMD, MinGW

There are a few other ToolChains that support LTO linking that I have not 
touched at the moment.

https://github.com/llvm/llvm-project/pull/71359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][LTO] Copy fix empty stats filename to AVR, FreeBSD, Fuchsia (PR #71359)

2023-11-05 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/71359
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][LTO] Copy fix empty stats filename to AVR, FreeBSD, Fuchsia (PR #71359)

2023-11-05 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Brad Smith (brad0)


Changes

Copy 85451f486d8144f8aacd94a47802c77da5a04d27 over to AVR, FreeBSD and Fuchsia.

---
Full diff: https://github.com/llvm/llvm-project/pull/71359.diff


4 Files Affected:

- (modified) clang/lib/Driver/ToolChains/AVR.cpp (+9-1) 
- (modified) clang/lib/Driver/ToolChains/FreeBSD.cpp (+9-1) 
- (modified) clang/lib/Driver/ToolChains/Fuchsia.cpp (+9-1) 
- (modified) clang/test/Driver/save-stats.c (+9-3) 


``diff
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 27505b9462c4492..a4ce2258c3d812f 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -513,7 +513,15 @@ void AVR::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo ) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(TC, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 0b70ac7b76e6765..685616a9bfd4662 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -264,7 +264,15 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo ) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 00de63c15522973..6525cf8356d184b 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -138,7 +138,15 @@ void fuchsia::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo ) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 
diff --git a/clang/test/Driver/save-stats.c b/clang/test/Driver/save-stats.c
index 2208c229b91e56c..7b35b80b9f629f8 100644
--- a/clang/test/Driver/save-stats.c
+++ b/clang/test/Driver/save-stats.c
@@ -19,14 +19,20 @@
 // RUN: not %clang -target x86_64-apple-darwin -save-stats=bla -c %s -### 2>&1 
| FileCheck %s -check-prefix=CHECK-INVALID
 // CHECK-INVALID: invalid value 'bla' in '-save-stats=bla'
 
-// RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-linux -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
 // Previously `-plugin-opt=stats-file` would use empty filename if a linker 
flag (i.e. -Wl) is presented before any input filename.
-// RUN: %clang --target=x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-linux -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-freebsd -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-freebsd -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-fuchsia -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO

[clang] [Driver][LTO] Copy fix empty stats filename to AVR, FreeBSD, Fuchsia (PR #71359)

2023-11-05 Thread Brad Smith via cfe-commits

https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/71359

Copy 85451f486d8144f8aacd94a47802c77da5a04d27 over to AVR, FreeBSD and Fuchsia.

>From 6578c1955274684350b2a7de3369c4646930ac6b Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sun, 5 Nov 2023 19:29:02 -0500
Subject: [PATCH] [Driver][LTO] Copy fix empty stats filename to AVR, FreeBSD,
 Fuchsia

Copy 85451f486d8144f8aacd94a47802c77da5a04d27 over to AVR, FreeBSD
and Fuchsia.
---
 clang/lib/Driver/ToolChains/AVR.cpp | 10 +-
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 10 +-
 clang/lib/Driver/ToolChains/Fuchsia.cpp | 10 +-
 clang/test/Driver/save-stats.c  | 12 +---
 4 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 27505b9462c4492..a4ce2258c3d812f 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -513,7 +513,15 @@ void AVR::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo ) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(TC, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 0b70ac7b76e6765..685616a9bfd4662 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -264,7 +264,15 @@ void freebsd::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo ) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 00de63c15522973..6525cf8356d184b 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -138,7 +138,15 @@ void fuchsia::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo ) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 
diff --git a/clang/test/Driver/save-stats.c b/clang/test/Driver/save-stats.c
index 2208c229b91e56c..7b35b80b9f629f8 100644
--- a/clang/test/Driver/save-stats.c
+++ b/clang/test/Driver/save-stats.c
@@ -19,14 +19,20 @@
 // RUN: not %clang -target x86_64-apple-darwin -save-stats=bla -c %s -### 2>&1 
| FileCheck %s -check-prefix=CHECK-INVALID
 // CHECK-INVALID: invalid value 'bla' in '-save-stats=bla'
 
-// RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-linux -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
 // Previously `-plugin-opt=stats-file` would use empty filename if a linker 
flag (i.e. -Wl) is presented before any input filename.
-// RUN: %clang --target=x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-linux -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-freebsd -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-freebsd -save-stats -flto -o 
obj/dir/save-stats.exe 

[clang] fb9d124 - [clang][NFC] Clean up commented-out code in `StringLiteral`

2023-11-05 Thread Vlad Serebrennikov via cfe-commits

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-tools-extra] [libc] [clang] [lldb] [libcxx] [flang] [compiler-rt] [llvm] [PowerPC] Support mcmodel=small/large for AIX (PR #70652)

2023-11-05 Thread Qiu Chaofan via cfe-commits

ecnelises wrote:

https://github.com/llvm/llvm-project/issues/71356 to track SPE issue

https://github.com/llvm/llvm-project/pull/70652
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] [clang] [lldb] [libcxx] [flang] [compiler-rt] [llvm] [PowerPC] Support mcmodel=small/large for AIX (PR #70652)

2023-11-05 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises closed 
https://github.com/llvm/llvm-project/pull/70652
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4704eaf - [PowerPC] Support more mcmodel options for AIX (#70652)

2023-11-05 Thread via cfe-commits

Author: Qiu Chaofan
Date: 2023-11-06T13:24:07+08:00
New Revision: 4704eaf234c3c30117caacd7b073d6dd63fd0f65

URL: 
https://github.com/llvm/llvm-project/commit/4704eaf234c3c30117caacd7b073d6dd63fd0f65
DIFF: 
https://github.com/llvm/llvm-project/commit/4704eaf234c3c30117caacd7b073d6dd63fd0f65.diff

LOG: [PowerPC] Support more mcmodel options for AIX (#70652)

7e42545 rejects unsupported mcmodel options, but small and large
should be a supported model for 32-bit AIX targets.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/mcmodel.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 8bf07a10274e737..3e2c13069612876 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5726,16 +5726,14 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
   if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
 StringRef CM = A->getValue();
 bool Ok = false;
-if (Triple.isOSAIX() && CM == "medium") {
+if (Triple.isOSAIX() && CM == "medium")
   CM = "large";
-  Ok = true;
-}
 if (Triple.isAArch64(64)) {
   Ok = CM == "tiny" || CM == "small" || CM == "large";
   if (CM == "large" && RelocationModel != llvm::Reloc::Static)
 D.Diag(diag::err_drv_argument_only_allowed_with)
 << A->getAsString(Args) << "-fno-pic";
-} else if (Triple.isPPC64()) {
+} else if (Triple.isPPC64() || Triple.isOSAIX()) {
   Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isRISCV()) {
   if (CM == "medlow")

diff  --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c
index fb3bbccb0c68157..d8a41b0f5abd9aa 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -5,6 +5,8 @@
 // RUN: %clang --target=x86_64 -### -c -mcmodel=medium %s 2>&1 | FileCheck 
--check-prefix=MEDIUM %s
 // RUN: %clang --target=x86_64 -### -S -mcmodel=large %s 2>&1 | FileCheck 
--check-prefix=LARGE %s
 // RUN: not %clang -### -c --target=powerpc-linux-gnu -mcmodel=medium %s 2>&1 
| FileCheck --check-prefix=ERR-MEDIUM %s
+// RUN: %clang --target=powerpc-unknown-aix -### -S -mcmodel=small %s 2>&1 | 
FileCheck --check-prefix=SMALL %s
+// RUN: %clang --target=powerpc-unknown-aix -### -S -mcmodel=large %s 2>&1 | 
FileCheck --check-prefix=LARGE %s
 // RUN: %clang --target=powerpc-unknown-aix -### -S -mcmodel=medium %s 2> 
%t.log
 // RUN: FileCheck --check-prefix=AIX-MCMEDIUM-OVERRIDE %s < %t.log
 // RUN: not %clang -### -c -mcmodel=lager %s 2>&1 | FileCheck 
--check-prefix=INVALID %s



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] [clang] [lldb] [libcxx] [flang] [compiler-rt] [llvm] [PowerPC] Support mcmodel=small/large for AIX (PR #70652)

2023-11-05 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises edited 
https://github.com/llvm/llvm-project/pull/70652
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)

2023-11-05 Thread via cfe-commits

https://github.com/h-vetinari commented:

There is substantial inconsistency between "coro only destroy when complete" 
and "... when done" throughout the PR (in various forms; e.g. literal strings, 
snake_case, CamelCase, ALL_CAPS as well as file names).

Presumably there should only be one spelling everywhere.

https://github.com/llvm/llvm-project/pull/71014
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add space in Verilog tagged unions (PR #71354)

2023-11-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (sstwcw)


Changes

In a tagged union expression, there should be a space between the field name 
and the data.  Previously, the tag could be recognized as part of a dotted 
identifier or a struct literal, and the space would be omitted.

---
Full diff: https://github.com/llvm/llvm-project/pull/71354.diff


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+8-1) 
- (modified) clang/unittests/Format/FormatTestVerilog.cpp (+12-2) 


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..263125d5711a95b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4694,8 +4694,15 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 Left.isOneOf(TT_VerilogDimensionedTypeName, Keywords.kw_function)) {
   return true;
 }
+// In a tagged union expression, there should be a space after the tag.
+if (Right.isOneOf(tok::period, Keywords.kw_apostrophe) &&
+Keywords.isVerilogIdentifier(Left) && Left.getPreviousNonComment() &&
+Left.getPreviousNonComment()->is(Keywords.kw_tagged)) {
+  return true;
+}
 // Don't add spaces between a casting type and the quote or repetition 
count
-// and the brace.
+// and the brace.  The case of tagged union expressions is handled by the
+// previous rule.
 if ((Right.is(Keywords.kw_apostrophe) ||
  (Right.is(BK_BracedInit) && Right.is(tok::l_brace))) &&
 !(Left.isOneOf(Keywords.kw_assign, Keywords.kw_unique) ||
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index 1c2692467987d9b..99d0fcca38c3993 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -359,6 +359,11 @@ TEST_F(FormatTestVerilog, Case) {
"  arg);\n"
"endcase",
Style);
+
+  verifyFormat("case (v) matches\n"
+   "  tagged Valid .n:\n"
+   ";\n"
+   "endcase");
 }
 
 TEST_F(FormatTestVerilog, Coverage) {
@@ -1278,12 +1283,17 @@ TEST_F(FormatTestVerilog, StructLiteral) {
   verifyFormat("c = '{'{1, 1.0}, '{2, 2.0}};");
   verifyFormat("c = '{a: 0, b: 0.0};");
   verifyFormat("c = '{a: 0, b: 0.0, default: 0};");
+  verifyFormat("d = {int: 1, shortreal: 1.0};");
+  verifyFormat("c = '{default: 0};");
+
+  // The identifier before the quote can be either a tag or a type case.  There
+  // should be a space between the tag and the quote.
   verifyFormat("c = ab'{a: 0, b: 0.0};");
   verifyFormat("c = ab'{cd: cd'{1, 1.0}, ef: ef'{2, 2.0}};");
   verifyFormat("c = ab'{cd'{1, 1.0}, ef'{2, 2.0}};");
-  verifyFormat("d = {int: 1, shortreal: 1.0};");
   verifyFormat("d = ab'{int: 1, shortreal: 1.0};");
-  verifyFormat("c = '{default: 0};");
+  verifyFormat("x = tagged Add '{e1, 4, ed};");
+
   auto Style = getDefaultStyle();
   Style.SpacesInContainerLiterals = true;
   verifyFormat("c = '{a : 0, b : 0.0};", Style);

``




https://github.com/llvm/llvm-project/pull/71354
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add space in Verilog tagged unions (PR #71354)

2023-11-05 Thread via cfe-commits

https://github.com/sstwcw created 
https://github.com/llvm/llvm-project/pull/71354

In a tagged union expression, there should be a space between the field name 
and the data.  Previously, the tag could be recognized as part of a dotted 
identifier or a struct literal, and the space would be omitted.

>From 758fc8c9240452b90c3df2781429ae07699ef577 Mon Sep 17 00:00:00 2001
From: sstwcw 
Date: Mon, 6 Nov 2023 03:26:02 +
Subject: [PATCH] [clang-format] Add space in Verilog tagged unions

In a tagged union expression, there should be a space between the field
name and the data.  Previously, the tag could be recognized as part of a
dotted identifier or a struct literal, and the space would be omitted.
---
 clang/lib/Format/TokenAnnotator.cpp  |  9 -
 clang/unittests/Format/FormatTestVerilog.cpp | 14 --
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..263125d5711a95b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4694,8 +4694,15 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 Left.isOneOf(TT_VerilogDimensionedTypeName, Keywords.kw_function)) {
   return true;
 }
+// In a tagged union expression, there should be a space after the tag.
+if (Right.isOneOf(tok::period, Keywords.kw_apostrophe) &&
+Keywords.isVerilogIdentifier(Left) && Left.getPreviousNonComment() &&
+Left.getPreviousNonComment()->is(Keywords.kw_tagged)) {
+  return true;
+}
 // Don't add spaces between a casting type and the quote or repetition 
count
-// and the brace.
+// and the brace.  The case of tagged union expressions is handled by the
+// previous rule.
 if ((Right.is(Keywords.kw_apostrophe) ||
  (Right.is(BK_BracedInit) && Right.is(tok::l_brace))) &&
 !(Left.isOneOf(Keywords.kw_assign, Keywords.kw_unique) ||
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index 1c2692467987d9b..99d0fcca38c3993 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -359,6 +359,11 @@ TEST_F(FormatTestVerilog, Case) {
"  arg);\n"
"endcase",
Style);
+
+  verifyFormat("case (v) matches\n"
+   "  tagged Valid .n:\n"
+   ";\n"
+   "endcase");
 }
 
 TEST_F(FormatTestVerilog, Coverage) {
@@ -1278,12 +1283,17 @@ TEST_F(FormatTestVerilog, StructLiteral) {
   verifyFormat("c = '{'{1, 1.0}, '{2, 2.0}};");
   verifyFormat("c = '{a: 0, b: 0.0};");
   verifyFormat("c = '{a: 0, b: 0.0, default: 0};");
+  verifyFormat("d = {int: 1, shortreal: 1.0};");
+  verifyFormat("c = '{default: 0};");
+
+  // The identifier before the quote can be either a tag or a type case.  There
+  // should be a space between the tag and the quote.
   verifyFormat("c = ab'{a: 0, b: 0.0};");
   verifyFormat("c = ab'{cd: cd'{1, 1.0}, ef: ef'{2, 2.0}};");
   verifyFormat("c = ab'{cd'{1, 1.0}, ef'{2, 2.0}};");
-  verifyFormat("d = {int: 1, shortreal: 1.0};");
   verifyFormat("d = ab'{int: 1, shortreal: 1.0};");
-  verifyFormat("c = '{default: 0};");
+  verifyFormat("x = tagged Add '{e1, 4, ed};");
+
   auto Style = getDefaultStyle();
   Style.SpacesInContainerLiterals = true;
   verifyFormat("c = '{a : 0, b : 0.0};", Style);

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Stop breaking unbreakable strings in JS (PR #66168)

2023-11-05 Thread via cfe-commits

sstwcw wrote:

> Here are string literal context from closure - This still misses contexts 
> when string literal is required, for example 
> https://github.com/search?q=repo%3Agoogle%2Fclosure-compiler%20%22%20must%20be%20a%20string%20literal%22=code
> 
> I wonder, if splitting the literal with `+` is a good option at all.

I was trying to stop the formatter from breaking the arguments to certain 
functions by marking the lines as not breakable.  Then I found the commit 
53c38f4e79ae which says that lines containing `goog.module` should not be 
broken but lines containing `goog.module.get` should be broken.  Who knows the 
rationale behind it?  Among the functions whose arguments must be a string 
literal, which ones make the entire line unbreakable?

https://github.com/llvm/llvm-project/pull/66168
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Indent Verilog case statements with comments (PR #71353)

2023-11-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (sstwcw)


Changes

If a line contains a comment outside of (fake) parentheses, the part following 
it is indented according to `CurrentState.Indent`.  A Verilog case label and 
the statement that follows are broken with mustBreakBefore.  So the part that 
follows the case label needs some special handling.  Previously, that variable 
was left out.  So the indentation was wrong when there was a comment.

old:

```Verilog
case (data)
  16'd0:
result = //
10'b01;
endcase
case (data)
  16'd0:
//

  //
  result = //
  10'b01;
endcase
```

new:

```Verilog
case (data)
  16'd0:
result = //
10'b01;
endcase
case (data)
  16'd0:
//

//
result = //
10'b01;
endcase
```

---
Full diff: https://github.com/llvm/llvm-project/pull/71353.diff


2 Files Affected:

- (modified) clang/lib/Format/ContinuationIndenter.cpp (+4-1) 
- (modified) clang/unittests/Format/FormatTestVerilog.cpp (+14) 


``diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 3a829cdedb77fc7..17a039abb30f8da 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1208,8 +1208,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
 
   // Indentation of the statement following a Verilog case label is taken care
   // of in moveStateToNextToken.
-  if (Style.isVerilog() && Keywords.isVerilogEndOfLabel(Previous))
+  if (Style.isVerilog() && PreviousNonComment &&
+  Keywords.isVerilogEndOfLabel(*PreviousNonComment)) {
 return State.FirstIndent;
+  }
 
   if (Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths &&
   State.Line->First->is(tok::kw_enum)) {
@@ -1612,6 +1614,7 @@ unsigned 
ContinuationIndenter::moveStateToNextToken(LineState ,
   State.NextToken->MustBreakBefore &&
   Keywords.isVerilogEndOfLabel(Current)) {
 State.FirstIndent += Style.IndentWidth;
+CurrentState.Indent = State.FirstIndent;
   }
 
   unsigned Penalty =
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index 1c2692467987d9b..9d5306c039ec334 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -344,6 +344,20 @@ TEST_F(FormatTestVerilog, Case) {
"longfunction( //\n"
"arg);\n"
"endcase");
+  verifyFormat("case (data)\n"
+   "  16'd0:\n"
+   "//\n"
+   "result = //\n"
+   "10'b01;\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  16'd0:\n"
+   "//\n"
+   "\n"
+   "//\n"
+   "result = //\n"
+   "10'b01;\n"
+   "endcase");
   Style = getDefaultStyle();
   Style.ContinuationIndentWidth = 1;
   verifyFormat("case (data)\n"

``




https://github.com/llvm/llvm-project/pull/71353
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add spaces around the Verilog implication operator (PR #71352)

2023-11-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (sstwcw)


Changes

The Verilog implication operator `-` is a binary operator meaning either 
the left hand side is false or the right hand side is true. Previously it was 
treated as the C++ struct member operator.

I didn't even know it existed when I added the operator formatting part. And I 
didn't check all the tests for all the operators I added.  That is how the bad 
test got in.

---
Full diff: https://github.com/llvm/llvm-project/pull/71352.diff


4 Files Affected:

- (modified) clang/lib/Format/FormatTokenLexer.cpp (+4-2) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+6) 
- (modified) clang/unittests/Format/FormatTestVerilog.cpp (+1-1) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+12-11) 


``diff
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a90ba4af2da8408..db52add50a97763 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -253,7 +253,8 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   TT_BinaryOperator)) {
   return;
 }
-// Module paths in specify blocks and implications in properties.
+// Module paths in specify blocks and the implication and boolean equality
+// operators.
 if (tryMergeTokensAny({{tok::plusequal, tok::greater},
{tok::plus, tok::star, tok::greater},
{tok::minusequal, tok::greater},
@@ -265,7 +266,8 @@ void FormatTokenLexer::tryMergePreviousTokens() {
{tok::pipe, tok::arrow},
{tok::hash, tok::minus, tok::hash},
{tok::hash, tok::equal, tok::hash}},
-  TT_BinaryOperator)) {
+  TT_BinaryOperator) ||
+Tokens.back()->is(tok::arrow)) {
   Tokens.back()->ForcedPrecedence = prec::Comma;
   return;
 }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..39dac2917d2063c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2010,6 +2010,9 @@ class AnnotatingParser {
 } else if (Current.is(tok::arrow) &&
Style.Language == FormatStyle::LK_Java) {
   Current.setType(TT_TrailingReturnArrow);
+} else if (Current.is(tok::arrow) && Style.isVerilog()) {
+  // The implication operator.
+  Current.setType(TT_BinaryOperator);
 } else if (Current.is(tok::arrow) && AutoFound &&
Line.MightBeFunctionDecl && Current.NestingLevel == 0 &&
!Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) {
@@ -4684,6 +4687,9 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 (Left.is(TT_VerilogNumberBase) && Right.is(tok::numeric_constant))) {
   return false;
 }
+// Add spaces around the implication operator `->`.
+if (Left.is(tok::arrow) || Right.is(tok::arrow))
+  return true;
 // Don't add spaces between two at signs. Like in a coverage event.
 // Don't add spaces between at and a sensitivity list like
 // `@(posedge clk)`.
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index 1c2692467987d9b..6650caea80b0524 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -1005,7 +1005,7 @@ TEST_F(FormatTestVerilog, Operators) {
   verifyFormat("x = x ^~ x;");
   verifyFormat("x = x && x;");
   verifyFormat("x = x || x;");
-  verifyFormat("x = x->x;");
+  verifyFormat("x = x -> x;");
   verifyFormat("x = x <-> x;");
   verifyFormat("x += x;");
   verifyFormat("x -= x;");
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ed730307074963f..c797ddb367086d5 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1980,17 +1980,18 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) 
{
   // joined operators, we don't have a separate type, so we only test for their
   // precedence.
   std::pair JoinedBinary[] = {
-  {prec::Comma, "<->"},   {prec::Assignment, "+="},
-  {prec::Assignment, "-="},   {prec::Assignment, "*="},
-  {prec::Assignment, "/="},   {prec::Assignment, "%="},
-  {prec::Assignment, "&="},   {prec::Assignment, "^="},
-  {prec::Assignment, "<<="},  {prec::Assignment, ">>="},
-  {prec::Assignment, "<<<="}, {prec::Assignment, ">>>="},
-  {prec::LogicalOr, "||"},{prec::LogicalAnd, "&&"},
-  {prec::Equality, "=="}, {prec::Equality, "!="},
-  {prec::Equality, "==="},{prec::Equality, "!=="},
-  {prec::Equality, "==?"},{prec::Equality, "!=?"},
-  {prec::ExclusiveOr, "~^"},  {prec::ExclusiveOr, "^~"},
+  {prec::Comma, "->"},

[clang] [clang-format] Indent Verilog case statements with comments (PR #71353)

2023-11-05 Thread via cfe-commits

https://github.com/sstwcw created 
https://github.com/llvm/llvm-project/pull/71353

If a line contains a comment outside of (fake) parentheses, the part following 
it is indented according to `CurrentState.Indent`.  A Verilog case label and 
the statement that follows are broken with mustBreakBefore.  So the part that 
follows the case label needs some special handling.  Previously, that variable 
was left out.  So the indentation was wrong when there was a comment.

old:

```Verilog
case (data)
  16'd0:
result = //
10'b01;
endcase
case (data)
  16'd0:
//

  //
  result = //
  10'b01;
endcase
```

new:

```Verilog
case (data)
  16'd0:
result = //
10'b01;
endcase
case (data)
  16'd0:
//

//
result = //
10'b01;
endcase
```

>From 0f191a5972b1e937cdf63994e438cd769e758919 Mon Sep 17 00:00:00 2001
From: sstwcw 
Date: Mon, 6 Nov 2023 03:26:02 +
Subject: [PATCH] [clang-format] Indent Verilog case statements with comments

If a line contains a comment outside of (fake) parentheses, the part
following it is indented according to `CurrentState.Indent`.  A Verilog
case label and the statement that follows are broken with
mustBreakBefore.  So the part that follows the case label needs some
special handling.  Previously, that variable was left out.  So the
indentation was wrong when there was a comment.

old:

```Verilog
case (data)
  16'd0:
result = //
10'b01;
endcase
case (data)
  16'd0:
//

  //
  result = //
  10'b01;
endcase
```

new:

```Verilog
case (data)
  16'd0:
result = //
10'b01;
endcase
case (data)
  16'd0:
//

//
result = //
10'b01;
endcase
```
---
 clang/lib/Format/ContinuationIndenter.cpp|  5 -
 clang/unittests/Format/FormatTestVerilog.cpp | 14 ++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 3a829cdedb77fc7..17a039abb30f8da 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1208,8 +1208,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
 
   // Indentation of the statement following a Verilog case label is taken care
   // of in moveStateToNextToken.
-  if (Style.isVerilog() && Keywords.isVerilogEndOfLabel(Previous))
+  if (Style.isVerilog() && PreviousNonComment &&
+  Keywords.isVerilogEndOfLabel(*PreviousNonComment)) {
 return State.FirstIndent;
+  }
 
   if (Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths &&
   State.Line->First->is(tok::kw_enum)) {
@@ -1612,6 +1614,7 @@ unsigned 
ContinuationIndenter::moveStateToNextToken(LineState ,
   State.NextToken->MustBreakBefore &&
   Keywords.isVerilogEndOfLabel(Current)) {
 State.FirstIndent += Style.IndentWidth;
+CurrentState.Indent = State.FirstIndent;
   }
 
   unsigned Penalty =
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index 1c2692467987d9b..9d5306c039ec334 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -344,6 +344,20 @@ TEST_F(FormatTestVerilog, Case) {
"longfunction( //\n"
"arg);\n"
"endcase");
+  verifyFormat("case (data)\n"
+   "  16'd0:\n"
+   "//\n"
+   "result = //\n"
+   "10'b01;\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  16'd0:\n"
+   "//\n"
+   "\n"
+   "//\n"
+   "result = //\n"
+   "10'b01;\n"
+   "endcase");
   Style = getDefaultStyle();
   Style.ContinuationIndentWidth = 1;
   verifyFormat("case (data)\n"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add spaces around the Verilog implication operator (PR #71352)

2023-11-05 Thread via cfe-commits

https://github.com/sstwcw created 
https://github.com/llvm/llvm-project/pull/71352

The Verilog implication operator `->` is a binary operator meaning either the 
left hand side is false or the right hand side is true. Previously it was 
treated as the C++ struct member operator.

I didn't even know it existed when I added the operator formatting part. And I 
didn't check all the tests for all the operators I added.  That is how the bad 
test got in.

>From 0d3118c491f1fc540a6c2e98e111a6265b0399b1 Mon Sep 17 00:00:00 2001
From: sstwcw 
Date: Mon, 6 Nov 2023 03:26:02 +
Subject: [PATCH] [clang-format] Add spaces around the Verilog implication
 operator

The Verilog implication operator `->` is a binary operator meaning
either the left hand side is false or the right hand side is true.
Previously it was treated as the C++ struct member operator.

I didn't even know it existed when I added the operator formatting part.
And I didn't check all the tests for all the operators I added.  That is
how the bad test got in.
---
 clang/lib/Format/FormatTokenLexer.cpp |  6 +++--
 clang/lib/Format/TokenAnnotator.cpp   |  6 +
 clang/unittests/Format/FormatTestVerilog.cpp  |  2 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 23 ++-
 4 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a90ba4af2da8408..db52add50a97763 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -253,7 +253,8 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   TT_BinaryOperator)) {
   return;
 }
-// Module paths in specify blocks and implications in properties.
+// Module paths in specify blocks and the implication and boolean equality
+// operators.
 if (tryMergeTokensAny({{tok::plusequal, tok::greater},
{tok::plus, tok::star, tok::greater},
{tok::minusequal, tok::greater},
@@ -265,7 +266,8 @@ void FormatTokenLexer::tryMergePreviousTokens() {
{tok::pipe, tok::arrow},
{tok::hash, tok::minus, tok::hash},
{tok::hash, tok::equal, tok::hash}},
-  TT_BinaryOperator)) {
+  TT_BinaryOperator) ||
+Tokens.back()->is(tok::arrow)) {
   Tokens.back()->ForcedPrecedence = prec::Comma;
   return;
 }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..39dac2917d2063c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2010,6 +2010,9 @@ class AnnotatingParser {
 } else if (Current.is(tok::arrow) &&
Style.Language == FormatStyle::LK_Java) {
   Current.setType(TT_TrailingReturnArrow);
+} else if (Current.is(tok::arrow) && Style.isVerilog()) {
+  // The implication operator.
+  Current.setType(TT_BinaryOperator);
 } else if (Current.is(tok::arrow) && AutoFound &&
Line.MightBeFunctionDecl && Current.NestingLevel == 0 &&
!Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) {
@@ -4684,6 +4687,9 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 (Left.is(TT_VerilogNumberBase) && Right.is(tok::numeric_constant))) {
   return false;
 }
+// Add spaces around the implication operator `->`.
+if (Left.is(tok::arrow) || Right.is(tok::arrow))
+  return true;
 // Don't add spaces between two at signs. Like in a coverage event.
 // Don't add spaces between at and a sensitivity list like
 // `@(posedge clk)`.
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index 1c2692467987d9b..6650caea80b0524 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -1005,7 +1005,7 @@ TEST_F(FormatTestVerilog, Operators) {
   verifyFormat("x = x ^~ x;");
   verifyFormat("x = x && x;");
   verifyFormat("x = x || x;");
-  verifyFormat("x = x->x;");
+  verifyFormat("x = x -> x;");
   verifyFormat("x = x <-> x;");
   verifyFormat("x += x;");
   verifyFormat("x -= x;");
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ed730307074963f..c797ddb367086d5 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1980,17 +1980,18 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) 
{
   // joined operators, we don't have a separate type, so we only test for their
   // precedence.
   std::pair JoinedBinary[] = {
-  {prec::Comma, "<->"},   {prec::Assignment, "+="},
-  {prec::Assignment, "-="},   {prec::Assignment, "*="},
-  {prec::Assignment, "/="},   {prec::Assignment, "%="},
-  

[llvm] [clang] [clang-tools-extra] [Clang][Sema] Skip RecordDecl when checking scope of declarations (PR #69432)

2023-11-05 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises edited 
https://github.com/llvm/llvm-project/pull/69432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [llvm] [Clang][Sema] Skip RecordDecl when checking scope of declarations (PR #69432)

2023-11-05 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises edited 
https://github.com/llvm/llvm-project/pull/69432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [llvm] [Clang][Sema] Skip RecordDecl when checking scope of declarations (PR #69432)

2023-11-05 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises closed 
https://github.com/llvm/llvm-project/pull/69432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 267a437 - [Clang][Sema] Skip RecordDecl when checking scope of declarations (#69432)

2023-11-05 Thread via cfe-commits

Author: Qiu Chaofan
Date: 2023-11-06T11:54:51+08:00
New Revision: 267a437920904723360cb2837172bd776db73057

URL: 
https://github.com/llvm/llvm-project/commit/267a437920904723360cb2837172bd776db73057
DIFF: 
https://github.com/llvm/llvm-project/commit/267a437920904723360cb2837172bd776db73057.diff

LOG: [Clang][Sema] Skip RecordDecl when checking scope of declarations (#69432)

In non C++ mode, struct definitions does not create a scope for
declaration.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/IdentifierResolver.cpp
clang/test/Sema/nested-redef.c
clang/test/SemaObjC/ivar-lookup.m

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3edf480665ba10c..5e19dbea6608486 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -712,6 +712,8 @@ Miscellaneous Clang Crashes Fixed
   `Issue 64564 `_
 - Fixed a crash when an ObjC ivar has an invalid type. See
   (`#68001 `_)
+- Fixed a crash in C when redefined struct is another nested redefinition.
+  `Issue 41302 `_
 
 Target Specific Changes
 ---

diff  --git a/clang/lib/Sema/IdentifierResolver.cpp 
b/clang/lib/Sema/IdentifierResolver.cpp
index 98a6f3b45089b3a..2213c3c837243ad 100644
--- a/clang/lib/Sema/IdentifierResolver.cpp
+++ b/clang/lib/Sema/IdentifierResolver.cpp
@@ -109,7 +109,9 @@ bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext 
*Ctx, Scope *S,
 return false;
   if (Ctx->isFunctionOrMethod() || (S && S->isFunctionPrototypeScope())) {
 // Ignore the scopes associated within transparent declaration contexts.
-while (S->getEntity() && S->getEntity()->isTransparentContext())
+while (S->getEntity() &&
+   (S->getEntity()->isTransparentContext() ||
+(!LangOpt.CPlusPlus && isa(S->getEntity()
   S = S->getParent();
 
 if (S->isDeclScope(D))

diff  --git a/clang/test/Sema/nested-redef.c b/clang/test/Sema/nested-redef.c
index bbc485936770478..adc57ff4e04ab29 100644
--- a/clang/test/Sema/nested-redef.c
+++ b/clang/test/Sema/nested-redef.c
@@ -19,4 +19,16 @@ void f2(void) {
   struct U u;
 }
 
+void f3(void) {
+  struct G { // expected-note{{previous definition is here}}
+struct G {}; // expected-error{{nested redefinition of 'G'}}
+  };
+}
+
+void f4(void) {
+  struct G { // expected-note 2{{previous definition is here}}
+struct G {}; // expected-error{{nested redefinition of 'G'}}
+  };
 
+  struct G {}; // expected-error{{redefinition of 'G'}}
+}

diff  --git a/clang/test/SemaObjC/ivar-lookup.m 
b/clang/test/SemaObjC/ivar-lookup.m
index 898ffac99692ced..d88299e58e0f594 100644
--- a/clang/test/SemaObjC/ivar-lookup.m
+++ b/clang/test/SemaObjC/ivar-lookup.m
@@ -95,11 +95,11 @@ - (int) test
   union U {
 __typeof(myStatus) __in;  // fails.
   };
-  struct S {
+  struct S { // expected-note{{previous definition is here}}
 __typeof(myStatus) __in;  // fails.
 struct S1 { // expected-warning {{declaration does not declare anything}}
   __typeof(myStatus) __in;  // fails.
-  struct S { // expected-warning {{declaration does not declare anything}}
+  struct S { // expected-error {{nested redefinition of 'S'}}
 __typeof(myStatus) __in;  // fails.
   };
 };



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [llvm] [Clang][Sema] Skip RecordDecl when checking scope of declarations (PR #69432)

2023-11-05 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises edited 
https://github.com/llvm/llvm-project/pull/69432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [flang] [libcxx] [libc] [lldb] [clang-tools-extra] [clang] [llvm] [PowerPC] Support mcmodel=large for AIX (PR #70652)

2023-11-05 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 approved this pull request.

@ecnelises Let's first fix this for AIX. Could you please help to create a 
github issue for the SPE? Thanks.

https://github.com/llvm/llvm-project/pull/70652
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [flang] [libcxx] [libc] [lldb] [clang-tools-extra] [clang] [llvm] [PowerPC] Support mcmodel=large for AIX (PR #70652)

2023-11-05 Thread Chen Zheng via cfe-commits


@@ -5723,16 +5723,14 @@ void Clang::ConstructJob(Compilation , const 
JobAction ,
   if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
 StringRef CM = A->getValue();
 bool Ok = false;
-if (Triple.isOSAIX() && CM == "medium") {
+if (Triple.isOSAIX() && CM == "medium")
   CM = "large";
-  Ok = true;
-}
 if (Triple.isAArch64(64)) {
   Ok = CM == "tiny" || CM == "small" || CM == "large";
   if (CM == "large" && RelocationModel != llvm::Reloc::Static)
 D.Diag(diag::err_drv_argument_only_allowed_with)
 << A->getAsString(Args) << "-fno-pic";
-} else if (Triple.isPPC64()) {
+} else if (Triple.isPPC64() || Triple.isOSAIX()) {

chenzheng1030 wrote:

```
int b = 20;
int foo()
{
  return b;
}
```

- Small code model:
```
.foo:
# %bb.0:# %entry
lwz 3, L..C0(2) # @b  ;; Use one instruction to 
load b's address in the TOC. So only 2^16 bytes TOC range can be accessed 
because of encoding limitation of `lwz` instruction.
lwz 3, 0(3)
blr
```

- large code model
```
.foo:
# %bb.0:# %entry
addis 3, L..C0@u(2)
lwz 3, L..C0@l(3)  ;; Use two instructions to load b's address. 
So that bigger TOC range can be accessed.
lwz 3, 0(3)
blr
```

https://github.com/llvm/llvm-project/pull/70652
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Shao-Ce SUN via cfe-commits

https://github.com/sunshaoce closed 
https://github.com/llvm/llvm-project/pull/71140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fbdf6e2 - [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (#71140)

2023-11-05 Thread via cfe-commits

Author: Shao-Ce SUN
Date: 2023-11-06T11:22:14+08:00
New Revision: fbdf6e2724e11baa4441cd053804fb2d2375817a

URL: 
https://github.com/llvm/llvm-project/commit/fbdf6e2724e11baa4441cd053804fb2d2375817a
DIFF: 
https://github.com/llvm/llvm-project/commit/fbdf6e2724e11baa4441cd053804fb2d2375817a.diff

LOG: [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (#71140)

BF16 implementation based on @joshua-arch1's
https://reviews.llvm.org/D152498
Fixed the incorrect f16 type introduced in
https://github.com/llvm/llvm-project/pull/68296

-

Co-authored-by: Jun Sha (Joshua) 

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/include/clang/Basic/RISCVVTypes.def
clang/include/clang/Basic/riscv_sifive_vector.td
clang/include/clang/Basic/riscv_vector_common.td
clang/include/clang/Support/RISCVVIntrinsicUtils.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaRISCVVectorLookup.cpp
clang/lib/Support/RISCVVIntrinsicUtils.cpp

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfwmacc_4x4x4.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfwmacc_4x4x4.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfwmacc_4x4x4.c

clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-intrinsic-datatypes.cpp
clang/test/Sema/riscv-types.c
clang/test/Sema/rvv-required-features.c
clang/utils/TableGen/RISCVVEmitter.cpp
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ca94d30da217f62..6c147eb8f640623 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2386,7 +2386,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 
   bool isRVVType() const;
 
-  bool isRVVType(unsigned Bitwidth, bool IsFloat) const;
+  bool isRVVType(unsigned Bitwidth, bool IsFloat, bool IsBFloat = false) const;
 
   /// Return the implicit lifetime for this type, which must not be dependent.
   Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
@@ -7295,19 +7295,20 @@ inline bool Type::isRVVType() const {
 inline bool Type::isRVVType(unsigned ElementCount) const {
   bool Ret = false;
 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP)  
\
+IsFP, IsBF)
\
   if (NumEls == ElementCount)  
\
 Ret |= isSpecificBuiltinType(BuiltinType::Id);
 #include "clang/Basic/RISCVVTypes.def"
   return Ret;
 }
 
-inline bool Type::isRVVType(unsigned Bitwidth, bool IsFloat) const {
+inline bool Type::isRVVType(unsigned Bitwidth, bool IsFloat,
+bool IsBFloat) const {
   bool Ret = false;
 #define RVV_TYPE(Name, Id, SingletonId)
 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP)  
\
-  if (ElBits == Bitwidth && IsFloat == IsFP)   
\
+IsFP, IsBF)
\
+  if (ElBits == Bitwidth && IsFloat == IsFP && IsBFloat == IsBF)   
\
 Ret |= isSpecificBuiltinType(BuiltinType::Id);
 #include "clang/Basic/RISCVVTypes.def"
   return Ret;

diff  --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index 575bca58b51e023..af44cdcd53e5bd0 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -12,7 +12,8 @@
 //   A builtin type that has not been covered by any other #define
 //   Defining this macro covers all the builtins.
 //
-// - RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, IsSigned, IsFP)
+// - RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, IsSigned, IsFP,
+// IsBF)
 //   A RISC-V V scalable vector.
 //
 // - RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls)
@@ -45,7 +46,8 @@
 #endif
 
 #ifndef RVV_VECTOR_TYPE
-#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, 
IsFP)\
+#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
+IsFP, IsBF)
\
   RVV_TYPE(Name, Id, SingletonId)
 #endif
 
@@ -55,13 +57,20 @@
 #endif
 
 #ifndef RVV_VECTOR_TYPE_INT
-#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, 
IsSigned) \
-  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, 

[compiler-rt] [llvm] [clang-tools-extra] [clang] [flang] [lldb] [mlir] [libcxx] [mlir] Prepare convert-gpu-to-spirv for OpenCL support (PR #69941)

2023-11-05 Thread Lei Zhang via cfe-commits

antiagainst wrote:

> @antiagainst @joker-eph Can someone merge this PR? Thanks in advance.

Done. Thanks for the contribution again!

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [llvm] [clang-tools-extra] [clang] [flang] [lldb] [mlir] [libcxx] [mlir] Prepare convert-gpu-to-spirv for OpenCL support (PR #69941)

2023-11-05 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst closed 
https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [llvm] [clang-tools-extra] [clang] [flang] [libc] [mlir] [libcxx] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits


@@ -15,6 +15,7 @@
 
 #include "Utils.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"

antiagainst wrote:

SG. Thanks @jpienaar & @fabianmcg!

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Craig Topper via cfe-commits

https://github.com/topperc approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/71140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Shao-Ce SUN via cfe-commits

https://github.com/sunshaoce updated 
https://github.com/llvm/llvm-project/pull/71140

>From d8d0fcdd00b422e48af733ef638fe9857a05686e Mon Sep 17 00:00:00 2001
From: Shao-Ce SUN 
Date: Fri, 3 Nov 2023 11:50:58 +0800
Subject: [PATCH 1/6] [RISCV][Clang] Add bf16-type vector support for RVV

---
 clang/include/clang/AST/Type.h|  4 +--
 clang/include/clang/Basic/RISCVVTypes.def | 35 +++
 .../clang/Basic/riscv_vector_common.td|  1 +
 .../clang/Support/RISCVVIntrinsicUtils.h  | 11 +++---
 clang/lib/AST/ASTContext.cpp  | 12 +--
 clang/lib/AST/Type.cpp|  7 ++--
 clang/lib/Sema/SemaRISCVVectorLookup.cpp  |  3 ++
 clang/lib/Support/RISCVVIntrinsicUtils.cpp| 25 +
 .../rvv-intrinsic-datatypes.cpp   | 13 +++
 clang/test/Sema/riscv-types.c | 19 ++
 clang/utils/TableGen/RISCVVEmitter.cpp|  8 +++--
 11 files changed, 117 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index f64cd5e0ef64910..f99c4faa7170527 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -7294,7 +7294,7 @@ inline bool Type::isRVVType() const {
 inline bool Type::isRVVType(unsigned ElementCount) const {
   bool Ret = false;
 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP)  
\
+IsFP, IsBF)
\
   if (NumEls == ElementCount)  
\
 Ret |= isSpecificBuiltinType(BuiltinType::Id);
 #include "clang/Basic/RISCVVTypes.def"
@@ -7305,7 +7305,7 @@ inline bool Type::isRVVType(unsigned Bitwidth, bool 
IsFloat) const {
   bool Ret = false;
 #define RVV_TYPE(Name, Id, SingletonId)
 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP)  
\
+IsFP, IsBF)
\
   if (ElBits == Bitwidth && IsFloat == IsFP)   
\
 Ret |= isSpecificBuiltinType(BuiltinType::Id);
 #include "clang/Basic/RISCVVTypes.def"
diff --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index 575bca58b51e023..af44cdcd53e5bd0 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -12,7 +12,8 @@
 //   A builtin type that has not been covered by any other #define
 //   Defining this macro covers all the builtins.
 //
-// - RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, IsSigned, IsFP)
+// - RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, IsSigned, IsFP,
+// IsBF)
 //   A RISC-V V scalable vector.
 //
 // - RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls)
@@ -45,7 +46,8 @@
 #endif
 
 #ifndef RVV_VECTOR_TYPE
-#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, 
IsFP)\
+#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
+IsFP, IsBF)
\
   RVV_TYPE(Name, Id, SingletonId)
 #endif
 
@@ -55,13 +57,20 @@
 #endif
 
 #ifndef RVV_VECTOR_TYPE_INT
-#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, 
IsSigned) \
-  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, false)
+#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, 
\
+IsSigned)  
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, false,  
\
+  false)
 #endif
 
 #ifndef RVV_VECTOR_TYPE_FLOAT
-#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF) \
-  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, true)
+#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF)   
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, true, 
false)
+#endif
+
+#ifndef RVV_VECTOR_TYPE_BFLOAT
+#define RVV_VECTOR_TYPE_BFLOAT(Name, Id, SingletonId, NumEls, ElBits, NF)  
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, false, 
true)
 #endif
 
 //===- Vector types 
---===//
@@ -125,6 +134,19 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float16m2_t", RvvFloat16m2, 
RvvFloat16m2Ty, 8,  16,
 RVV_VECTOR_TYPE_FLOAT("__rvv_float16m4_t", RvvFloat16m4, RvvFloat16m4Ty, 16, 
16, 1)
 RVV_VECTOR_TYPE_FLOAT("__rvv_float16m8_t", RvvFloat16m8, RvvFloat16m8Ty, 32, 
16, 1)
 
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4_t", RvvBFloat16mf4, RvvBFloat16mf4Ty,
+   1, 16, 1)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2_t", RvvBFloat16mf2, RvvBFloat16mf2Ty,
+   2, 

[llvm] [clang] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Craig Topper via cfe-commits

https://github.com/topperc edited 
https://github.com/llvm/llvm-project/pull/71140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Craig Topper via cfe-commits


@@ -6046,6 +6046,12 @@ void Sema::checkRVVTypeSupport(QualType Ty, 
SourceLocation Loc, Decl *D) {
   !TI.hasFeature("zvfh") && !TI.hasFeature("zvfhmin"))
 Diag(Loc, diag::err_riscv_type_requires_extension, D)
 << Ty << "zvfh or zvfhmin";
+  // Check if enabled zvfbfmin for BFloat16
+  if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ false,
+/* IsBFloat */ true) &&
+  !TI.hasFeature("experimental-zvfbfmin"))
+Diag(Loc, diag::err_riscv_type_requires_extension, D)
+<< Ty << "experimental-zvfbfmin";

topperc wrote:

Drop the "experimental-". That's not part of the extension name.

https://github.com/llvm/llvm-project/pull/71140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] [lldb] [clang] [flang] [IndVars] Add check of loop invariant for trunc instructions (PR #71072)

2023-11-05 Thread via cfe-commits

vfdff wrote:

LGTM

https://github.com/llvm/llvm-project/pull/71072
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Shao-Ce SUN via cfe-commits

https://github.com/sunshaoce updated 
https://github.com/llvm/llvm-project/pull/71140

>From d8d0fcdd00b422e48af733ef638fe9857a05686e Mon Sep 17 00:00:00 2001
From: Shao-Ce SUN 
Date: Fri, 3 Nov 2023 11:50:58 +0800
Subject: [PATCH 1/5] [RISCV][Clang] Add bf16-type vector support for RVV

---
 clang/include/clang/AST/Type.h|  4 +--
 clang/include/clang/Basic/RISCVVTypes.def | 35 +++
 .../clang/Basic/riscv_vector_common.td|  1 +
 .../clang/Support/RISCVVIntrinsicUtils.h  | 11 +++---
 clang/lib/AST/ASTContext.cpp  | 12 +--
 clang/lib/AST/Type.cpp|  7 ++--
 clang/lib/Sema/SemaRISCVVectorLookup.cpp  |  3 ++
 clang/lib/Support/RISCVVIntrinsicUtils.cpp| 25 +
 .../rvv-intrinsic-datatypes.cpp   | 13 +++
 clang/test/Sema/riscv-types.c | 19 ++
 clang/utils/TableGen/RISCVVEmitter.cpp|  8 +++--
 11 files changed, 117 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index f64cd5e0ef64910..f99c4faa7170527 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -7294,7 +7294,7 @@ inline bool Type::isRVVType() const {
 inline bool Type::isRVVType(unsigned ElementCount) const {
   bool Ret = false;
 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP)  
\
+IsFP, IsBF)
\
   if (NumEls == ElementCount)  
\
 Ret |= isSpecificBuiltinType(BuiltinType::Id);
 #include "clang/Basic/RISCVVTypes.def"
@@ -7305,7 +7305,7 @@ inline bool Type::isRVVType(unsigned Bitwidth, bool 
IsFloat) const {
   bool Ret = false;
 #define RVV_TYPE(Name, Id, SingletonId)
 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP)  
\
+IsFP, IsBF)
\
   if (ElBits == Bitwidth && IsFloat == IsFP)   
\
 Ret |= isSpecificBuiltinType(BuiltinType::Id);
 #include "clang/Basic/RISCVVTypes.def"
diff --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index 575bca58b51e023..af44cdcd53e5bd0 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -12,7 +12,8 @@
 //   A builtin type that has not been covered by any other #define
 //   Defining this macro covers all the builtins.
 //
-// - RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, IsSigned, IsFP)
+// - RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, IsSigned, IsFP,
+// IsBF)
 //   A RISC-V V scalable vector.
 //
 // - RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls)
@@ -45,7 +46,8 @@
 #endif
 
 #ifndef RVV_VECTOR_TYPE
-#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, 
IsFP)\
+#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
+IsFP, IsBF)
\
   RVV_TYPE(Name, Id, SingletonId)
 #endif
 
@@ -55,13 +57,20 @@
 #endif
 
 #ifndef RVV_VECTOR_TYPE_INT
-#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, 
IsSigned) \
-  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, false)
+#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, 
\
+IsSigned)  
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, false,  
\
+  false)
 #endif
 
 #ifndef RVV_VECTOR_TYPE_FLOAT
-#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF) \
-  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, true)
+#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF)   
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, true, 
false)
+#endif
+
+#ifndef RVV_VECTOR_TYPE_BFLOAT
+#define RVV_VECTOR_TYPE_BFLOAT(Name, Id, SingletonId, NumEls, ElBits, NF)  
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, false, 
true)
 #endif
 
 //===- Vector types 
---===//
@@ -125,6 +134,19 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float16m2_t", RvvFloat16m2, 
RvvFloat16m2Ty, 8,  16,
 RVV_VECTOR_TYPE_FLOAT("__rvv_float16m4_t", RvvFloat16m4, RvvFloat16m4Ty, 16, 
16, 1)
 RVV_VECTOR_TYPE_FLOAT("__rvv_float16m8_t", RvvFloat16m8, RvvFloat16m8Ty, 32, 
16, 1)
 
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4_t", RvvBFloat16mf4, RvvBFloat16mf4Ty,
+   1, 16, 1)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2_t", RvvBFloat16mf2, RvvBFloat16mf2Ty,
+   2, 

[llvm] [clang] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Shao-Ce SUN via cfe-commits


@@ -6046,6 +6046,13 @@ void Sema::checkRVVTypeSupport(QualType Ty, 
SourceLocation Loc, Decl *D) {
   !TI.hasFeature("zvfh") && !TI.hasFeature("zvfhmin"))
 Diag(Loc, diag::err_riscv_type_requires_extension, D)
 << Ty << "zvfh or zvfhmin";
+  // Check if enabled zfbfmin/zvfbfmin for BFloat16
+  if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ false,
+/* IsBFloat */ true) &&
+  !TI.hasFeature("experimental-zfbfmin") &&

sunshaoce wrote:

Removed. Thanks!

https://github.com/llvm/llvm-project/pull/71140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Shao-Ce SUN via cfe-commits

https://github.com/sunshaoce updated 
https://github.com/llvm/llvm-project/pull/71140

>From d8d0fcdd00b422e48af733ef638fe9857a05686e Mon Sep 17 00:00:00 2001
From: Shao-Ce SUN 
Date: Fri, 3 Nov 2023 11:50:58 +0800
Subject: [PATCH 1/4] [RISCV][Clang] Add bf16-type vector support for RVV

---
 clang/include/clang/AST/Type.h|  4 +--
 clang/include/clang/Basic/RISCVVTypes.def | 35 +++
 .../clang/Basic/riscv_vector_common.td|  1 +
 .../clang/Support/RISCVVIntrinsicUtils.h  | 11 +++---
 clang/lib/AST/ASTContext.cpp  | 12 +--
 clang/lib/AST/Type.cpp|  7 ++--
 clang/lib/Sema/SemaRISCVVectorLookup.cpp  |  3 ++
 clang/lib/Support/RISCVVIntrinsicUtils.cpp| 25 +
 .../rvv-intrinsic-datatypes.cpp   | 13 +++
 clang/test/Sema/riscv-types.c | 19 ++
 clang/utils/TableGen/RISCVVEmitter.cpp|  8 +++--
 11 files changed, 117 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index f64cd5e0ef64910..f99c4faa7170527 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -7294,7 +7294,7 @@ inline bool Type::isRVVType() const {
 inline bool Type::isRVVType(unsigned ElementCount) const {
   bool Ret = false;
 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP)  
\
+IsFP, IsBF)
\
   if (NumEls == ElementCount)  
\
 Ret |= isSpecificBuiltinType(BuiltinType::Id);
 #include "clang/Basic/RISCVVTypes.def"
@@ -7305,7 +7305,7 @@ inline bool Type::isRVVType(unsigned Bitwidth, bool 
IsFloat) const {
   bool Ret = false;
 #define RVV_TYPE(Name, Id, SingletonId)
 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP)  
\
+IsFP, IsBF)
\
   if (ElBits == Bitwidth && IsFloat == IsFP)   
\
 Ret |= isSpecificBuiltinType(BuiltinType::Id);
 #include "clang/Basic/RISCVVTypes.def"
diff --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index 575bca58b51e023..af44cdcd53e5bd0 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -12,7 +12,8 @@
 //   A builtin type that has not been covered by any other #define
 //   Defining this macro covers all the builtins.
 //
-// - RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, IsSigned, IsFP)
+// - RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, IsSigned, IsFP,
+// IsBF)
 //   A RISC-V V scalable vector.
 //
 // - RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls)
@@ -45,7 +46,8 @@
 #endif
 
 #ifndef RVV_VECTOR_TYPE
-#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, 
IsFP)\
+#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
+IsFP, IsBF)
\
   RVV_TYPE(Name, Id, SingletonId)
 #endif
 
@@ -55,13 +57,20 @@
 #endif
 
 #ifndef RVV_VECTOR_TYPE_INT
-#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, 
IsSigned) \
-  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, false)
+#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, 
\
+IsSigned)  
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, false,  
\
+  false)
 #endif
 
 #ifndef RVV_VECTOR_TYPE_FLOAT
-#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF) \
-  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, true)
+#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF)   
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, true, 
false)
+#endif
+
+#ifndef RVV_VECTOR_TYPE_BFLOAT
+#define RVV_VECTOR_TYPE_BFLOAT(Name, Id, SingletonId, NumEls, ElBits, NF)  
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, false, 
true)
 #endif
 
 //===- Vector types 
---===//
@@ -125,6 +134,19 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float16m2_t", RvvFloat16m2, 
RvvFloat16m2Ty, 8,  16,
 RVV_VECTOR_TYPE_FLOAT("__rvv_float16m4_t", RvvFloat16m4, RvvFloat16m4Ty, 16, 
16, 1)
 RVV_VECTOR_TYPE_FLOAT("__rvv_float16m8_t", RvvFloat16m8, RvvFloat16m8Ty, 32, 
16, 1)
 
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4_t", RvvBFloat16mf4, RvvBFloat16mf4Ty,
+   1, 16, 1)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2_t", RvvBFloat16mf2, RvvBFloat16mf2Ty,
+   2, 

[llvm] [clang] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Craig Topper via cfe-commits


@@ -6046,6 +6046,13 @@ void Sema::checkRVVTypeSupport(QualType Ty, 
SourceLocation Loc, Decl *D) {
   !TI.hasFeature("zvfh") && !TI.hasFeature("zvfhmin"))
 Diag(Loc, diag::err_riscv_type_requires_extension, D)
 << Ty << "zvfh or zvfhmin";
+  // Check if enabled zfbfmin/zvfbfmin for BFloat16
+  if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ false,
+/* IsBFloat */ true) &&
+  !TI.hasFeature("experimental-zfbfmin") &&

topperc wrote:

Does zfbfmin provide vector support?

https://github.com/llvm/llvm-project/pull/71140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Shao-Ce SUN via cfe-commits

sunshaoce wrote:

> I believe we need to update `Sema::checkRVVTypeSupport` too

Addressed.

https://github.com/llvm/llvm-project/pull/71140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Shao-Ce SUN via cfe-commits

https://github.com/sunshaoce updated 
https://github.com/llvm/llvm-project/pull/71140

>From d8d0fcdd00b422e48af733ef638fe9857a05686e Mon Sep 17 00:00:00 2001
From: Shao-Ce SUN 
Date: Fri, 3 Nov 2023 11:50:58 +0800
Subject: [PATCH 1/3] [RISCV][Clang] Add bf16-type vector support for RVV

---
 clang/include/clang/AST/Type.h|  4 +--
 clang/include/clang/Basic/RISCVVTypes.def | 35 +++
 .../clang/Basic/riscv_vector_common.td|  1 +
 .../clang/Support/RISCVVIntrinsicUtils.h  | 11 +++---
 clang/lib/AST/ASTContext.cpp  | 12 +--
 clang/lib/AST/Type.cpp|  7 ++--
 clang/lib/Sema/SemaRISCVVectorLookup.cpp  |  3 ++
 clang/lib/Support/RISCVVIntrinsicUtils.cpp| 25 +
 .../rvv-intrinsic-datatypes.cpp   | 13 +++
 clang/test/Sema/riscv-types.c | 19 ++
 clang/utils/TableGen/RISCVVEmitter.cpp|  8 +++--
 11 files changed, 117 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index f64cd5e0ef64910..f99c4faa7170527 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -7294,7 +7294,7 @@ inline bool Type::isRVVType() const {
 inline bool Type::isRVVType(unsigned ElementCount) const {
   bool Ret = false;
 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP)  
\
+IsFP, IsBF)
\
   if (NumEls == ElementCount)  
\
 Ret |= isSpecificBuiltinType(BuiltinType::Id);
 #include "clang/Basic/RISCVVTypes.def"
@@ -7305,7 +7305,7 @@ inline bool Type::isRVVType(unsigned Bitwidth, bool 
IsFloat) const {
   bool Ret = false;
 #define RVV_TYPE(Name, Id, SingletonId)
 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP)  
\
+IsFP, IsBF)
\
   if (ElBits == Bitwidth && IsFloat == IsFP)   
\
 Ret |= isSpecificBuiltinType(BuiltinType::Id);
 #include "clang/Basic/RISCVVTypes.def"
diff --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index 575bca58b51e023..af44cdcd53e5bd0 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -12,7 +12,8 @@
 //   A builtin type that has not been covered by any other #define
 //   Defining this macro covers all the builtins.
 //
-// - RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, IsSigned, IsFP)
+// - RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, IsSigned, IsFP,
+// IsBF)
 //   A RISC-V V scalable vector.
 //
 // - RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls)
@@ -45,7 +46,8 @@
 #endif
 
 #ifndef RVV_VECTOR_TYPE
-#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, 
IsFP)\
+#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
+IsFP, IsBF)
\
   RVV_TYPE(Name, Id, SingletonId)
 #endif
 
@@ -55,13 +57,20 @@
 #endif
 
 #ifndef RVV_VECTOR_TYPE_INT
-#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, 
IsSigned) \
-  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, false)
+#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, 
\
+IsSigned)  
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, false,  
\
+  false)
 #endif
 
 #ifndef RVV_VECTOR_TYPE_FLOAT
-#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF) \
-  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, true)
+#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF)   
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, true, 
false)
+#endif
+
+#ifndef RVV_VECTOR_TYPE_BFLOAT
+#define RVV_VECTOR_TYPE_BFLOAT(Name, Id, SingletonId, NumEls, ElBits, NF)  
\
+  RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, false, false, 
true)
 #endif
 
 //===- Vector types 
---===//
@@ -125,6 +134,19 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float16m2_t", RvvFloat16m2, 
RvvFloat16m2Ty, 8,  16,
 RVV_VECTOR_TYPE_FLOAT("__rvv_float16m4_t", RvvFloat16m4, RvvFloat16m4Ty, 16, 
16, 1)
 RVV_VECTOR_TYPE_FLOAT("__rvv_float16m8_t", RvvFloat16m8, RvvFloat16m8Ty, 32, 
16, 1)
 
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4_t", RvvBFloat16mf4, RvvBFloat16mf4Ty,
+   1, 16, 1)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2_t", RvvBFloat16mf2, RvvBFloat16mf2Ty,
+   2, 

[llvm] [clang] [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (PR #71140)

2023-11-05 Thread Shao-Ce SUN via cfe-commits

https://github.com/sunshaoce edited 
https://github.com/llvm/llvm-project/pull/71140
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-05 Thread Chen Zheng via cfe-commits


@@ -197,6 +197,7 @@ CODEGENOPT(HIPCorrectlyRoundedDivSqrt, 1, 1) ///< 
-fno-hip-fp32-correctly-rounde
 CODEGENOPT(HIPSaveKernelArgName, 1, 0) ///< Set when -fhip-kernel-arg-name is 
enabled.
 CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get 
unique names.
 CODEGENOPT(SplitMachineFunctions, 1, 0) ///< Split machine functions using 
profile information.
+CODEGENOPT(PPCUseFullRegisterNames, 1, 0) ///< Print full register names in 
assembly -mregnames

chenzheng1030 wrote:

Nit: the last `-mregnames` seems unnecessary?

https://github.com/llvm/llvm-project/pull/70255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-05 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 edited 
https://github.com/llvm/llvm-project/pull/70255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-11-05 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 approved this pull request.

Thanks for adding this. LGTM

https://github.com/llvm/llvm-project/pull/70255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread Jimmy Z via cfe-commits

https://github.com/jimmy-zx updated 
https://github.com/llvm/llvm-project/pull/71341

>From 887751e365ca72515679f61d0734b1631ac38335 Mon Sep 17 00:00:00 2001
From: Jimmy Z <51149050+jimmy...@users.noreply.github.com>
Date: Mon, 6 Nov 2023 00:25:39 +
Subject: [PATCH 1/5] [libclang/python] Expose Rewriter to the libclang python
 binding.

---
 clang/bindings/python/clang/cindex.py | 62 
 .../python/tests/cindex/test_rewrite.py   | 74 +++
 2 files changed, 136 insertions(+)
 create mode 100644 clang/bindings/python/tests/cindex/test_rewrite.py

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 6a16f3a9ef6e957..e51d558ab73fbce 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3531,6 +3531,61 @@ def cursor(self):
 return cursor
 
 
+class Rewriter(ClangObject):
+"""
+The Rewriter is a wrapper class around clang::Rewriter
+
+It enables rewriting buffers.
+"""
+
+@staticmethod
+def create(tu):
+"""
+Creates a new Rewriter
+Parameters:
+tu -- The translation unit for the target AST.
+"""
+return Rewriter(conf.lib.clang_CXRewriter_create(tu))
+
+def __init__(self, ptr):
+ClangObject.__init__(self, ptr)
+
+def __del__(self):
+conf.lib.clang_CXRewriter_dispose(self)
+
+def insertTextBefore(self, loc, insert):
+"""
+Insert the specified string at the specified location in the original 
buffer.
+"""
+conf.lib.clang_CXRewriter_insertTextBefore(self, loc, insert)
+
+def replaceText(self, toBeReplaced, replacement):
+"""
+This method replaces a range of characters in the input buffer with a 
new string.
+"""
+conf.lib.clang_CXRewriter_replaceText(self, toBeReplaced, replacement)
+
+def removeText(self, toBeRemoved):
+"""
+Remove the specified text region.
+"""
+conf.lib.clang_CXRewriter_removeText(self, toBeRemoved)
+
+def overwriteChangedFiles(self):
+"""
+Save all changed files to disk.
+"""
+conf.lib.clang_CXRewriter_overwriteChangedFiles(self)
+
+def writeMainFileToStdOut(self):
+"""
+Writes the main file to stdout.
+"""
+conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
+
+
+
+
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types in common container.
@@ -3596,6 +3651,13 @@ def cursor(self):
 ("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int),
 ("clang_createIndex", [c_int, c_int], c_object_p),
 ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p),
+("clang_CXRewriter_create", [TranslationUnit], c_object_p),
+("clang_CXRewriter_dispose", [Rewriter]),
+("clang_CXRewriter_insertTextBefore", [Rewriter, SourceLocation, 
c_interop_string]),
+("clang_CXRewriter_overwriteChangedFiles", [Rewriter], c_int),
+("clang_CXRewriter_removeText", [Rewriter, SourceRange]),
+("clang_CXRewriter_replaceText", [Rewriter, SourceRange, 
c_interop_string]),
+("clang_CXRewriter_writeMainFileToStdOut", [Rewriter]),
 ("clang_CXXConstructor_isConvertingConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isCopyConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isDefaultConstructor", [Cursor], bool),
diff --git a/clang/bindings/python/tests/cindex/test_rewrite.py 
b/clang/bindings/python/tests/cindex/test_rewrite.py
new file mode 100644
index 000..eb697f72a923030
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_rewrite.py
@@ -0,0 +1,74 @@
+import sys
+import io
+import unittest
+import tempfile
+
+from clang.cindex import Rewriter, TranslationUnit, Config, File, 
SourceLocation, SourceRange
+
+class TestRewrite(unittest.TestCase):
+code = '''
+int test1;
+
+void test2(void);
+
+int f(int c) {
+return c;
+}
+'''
+
+@classmethod
+def setUpClass(cls):
+Config.set_compatibility_check(False)
+
+def setUp(self):
+self.tmp = tempfile.NamedTemporaryFile(suffix='.cpp', buffering=0)
+self.tmp.write(TestRewrite.code.encode('utf-8'))
+self.tmp.flush()
+self.tu = TranslationUnit.from_source(self.tmp.name)
+self.rew = Rewriter.create(self.tu)
+self.file = File.from_name(self.tu, self.tmp.name)
+
+def tearDown(self):
+self.tmp.close()
+
+
+def test_insert(self):
+snip = '#include \n'
+
+beginning = SourceLocation.from_offset(self.tu, self.file, 0)
+self.rew.insertTextBefore(beginning, snip)
+self.rew.overwriteChangedFiles()
+
+with open(self.tmp.name, 'r', encoding='utf-8') as f:
+self.assertEqual(f.read(), snip + TestRewrite.code)
+
+
+def test_replace(self):
+pattern = 'test2'
+replacement = 'func'
+
+offset = 

[clang] [X86] Add a EVEX256 macro to match with GCC and MSVC (PR #71317)

2023-11-05 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/71317
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2023-11-05 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@sam-mccall gentle ping~

https://github.com/llvm/llvm-project/pull/66462
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang-tools-extra] [clang] [llvm] [flang] [IndVars] Add check of loop invariant for trunc instructions (PR #71072)

2023-11-05 Thread via cfe-commits


@@ -0,0 +1,28 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=indvars -S | FileCheck %s
+
+declare void @foo(i16 noundef)
+
+; Function Attrs: mustprogress noreturn uwtable
+define void @bar(i64 noundef %ptr) {
+; CHECK-LABEL: @bar(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[TMP0:%.*]] = trunc i64 [[PTR:%.*]] to i4
+; CHECK-NEXT:[[TMP1:%.*]] = zext i4 [[TMP0]] to i16
+; CHECK-NEXT:br label [[WHILE_BODY:%.*]]
+; CHECK:   while.body:
+; CHECK-NEXT:tail call void @foo(i16 noundef signext [[TMP1]])
+; CHECK-NEXT:br label [[WHILE_BODY]]
+;
+entry:
+  br label %while.body
+
+while.body:   ; preds = %entry, %while.body
+  %0 = phi i64 [ %ptr, %entry ], [ %add.ptr, %while.body ]
+  %1 = trunc i64 %0 to i16
+  %and = and i16 %1, 15   ; loop invariant
+  tail call void @foo(i16 noundef signext %and)

vfdff wrote:

Oh, sorry, ignore this. 
yes, it is correct.  https://alive2.llvm.org/ce/z/Esz3Vt

https://github.com/llvm/llvm-project/pull/71072
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154396: [clang] Add support for SerenityOS

2023-11-05 Thread Andrew Kaster via Phabricator via cfe-commits
ADKaster updated this revision to Diff 558012.
ADKaster added a comment.

Add more tests and remove items per comments

More tests for crt*, eh-frame-hdr, stdlib arguments
remove /usr/local/include
remove -fno-use-init-array
claim stdlib= args
remove -nopie

I hope that the new tests are more robust, but I could be missing something


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154396/new/

https://reviews.llvm.org/D154396

Files:
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Serenity.cpp
  clang/lib/Driver/ToolChains/Serenity.h
  clang/lib/Lex/InitHeaderSearch.cpp
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/include/c++/v1/.keep
  
clang/test/Driver/Inputs/serenity_x86_64_tree/usr/include/x86_64-pc-serenity/c++/v1/.keep
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/lib/crt0.o
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/lib/crt0_shared.o
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/lib/crti.o
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/lib/crtn.o
  clang/test/Driver/Inputs/serenity_x86_64_tree/usr/local/.keep
  clang/test/Driver/pic.c
  clang/test/Driver/serenity.cpp

Index: clang/test/Driver/serenity.cpp
===
--- /dev/null
+++ clang/test/Driver/serenity.cpp
@@ -0,0 +1,196 @@
+// UNSUPPORTED: system-windows
+
+/// Check default header and linker paths
+// RUN: %clang -### %s --target=x86_64-pc-serenity --sysroot=%S/Inputs/serenity_x86_64_tree \
+// RUN:   -ccc-install-dir %S/Inputs/serenity_x86_64/usr/local/bin -resource-dir=%S/Inputs/resource_dir \
+// RUN:   2>&1 | FileCheck %s --check-prefix=PATHS_X86_64
+// PATHS_X86_64:  "-resource-dir" "[[RESOURCE:[^"]+]]"
+// PATHS_X86_64:  "-internal-isystem"
+// PATHS_X86_64-SAME: {{^}} "[[SYSROOT:[^"]+]]/usr/include/x86_64-pc-serenity/c++/v1"
+// PATHS_X86_64-SAME: {{^}} "-internal-isystem" "[[SYSROOT:[^"]+]]/usr/include/c++/v1"
+// PATHS_X86_64-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
+// PATHS_X86_64-SAME: {{^}} "-internal-isystem" "[[SYSROOT:[^"]+]]/usr/include"
+// PATHS_X86_64:  "-L
+// PATHS_X86_64-SAME: {{^}}[[SYSROOT]]/usr/lib"
+
+/// Check default linker args for each supported triple
+// RUN: %clang -### %s --target=x86_64-pc-serenity --sysroot= 2>&1 | FileCheck %s --check-prefix=SERENITY_X86_64
+// SERENITY_X86_64: "-cc1" "-triple" "x86_64-pc-serenity"
+// SERENITY_X86_64: "{{(.*[^-.0-9A-Z_a-z])?}}ld.lld"
+// SERENITY_X86_64: "-pie"
+// SERENITY_X86_64: "-dynamic-linker" "/usr/lib/Loader.so" "--eh-frame-hdr"
+// SERENITY_X86_64: "-o" "a.out"
+// SERENITY_X86_64: "-z" "pack-relative-relocs"
+// SERENITY_X86_64: "crt0.o" "crti.o" "crtbeginS.o"
+// SERENITY_X86_64: "-lc" "crtendS.o" "crtn.o"
+
+// RUN: %clang -### %s --target=aarch64-pc-serenity --sysroot= 2>&1 | FileCheck %s --check-prefix=SERENITY_AARCH64
+// SERENITY_AARCH64: "-cc1" "-triple" "aarch64-pc-serenity"
+// SERENITY_AARCH64: "{{(.*[^-.0-9A-Z_a-z])?}}ld.lld"
+// SERENITY_AARCH64: "-pie"
+// SERENITY_AARCH64: "-dynamic-linker" "/usr/lib/Loader.so" "--eh-frame-hdr"
+// SERENITY_AARCH64: "-o" "a.out"
+// SERENITY_AARCH64: "-z" "pack-relative-relocs"
+// SERENITY_AARCH64: "crt0.o" "crti.o" "crtbeginS.o"
+// SERENITY_AARCH64: "-lc" "crtendS.o" "crtn.o"
+
+// RUN: %clang -### %s --target=riscv64-pc-serenity --sysroot= 2>&1 | FileCheck %s --check-prefix=SERENITY_RISCV64
+// SERENITY_RISCV64: "-cc1" "-triple" "riscv64-pc-serenity"
+// SERENITY_RISCV64: "{{(.*[^-.0-9A-Z_a-z])?}}ld.lld"
+// SERENITY_RISCV64: "-pie"
+// SERENITY_RISCV64: "-dynamic-linker" "/usr/lib/Loader.so" "--eh-frame-hdr"
+// SERENITY_RISCV64: "-o" "a.out"
+// SERENITY_RISCV64: "-z" "pack-relative-relocs"
+// SERENITY_RISCV64: "crt0.o" "crti.o" "crtbeginS.o"
+// SERENITY_RISCV64: "-lc" "crtendS.o" "crtn.o"
+
+/// -static-pie suppresses -dynamic-linker
+// RUN: %clang -### %s --target=x86_64-pc-serenity --sysroot= \
+//  -static-pie 2>&1 | FileCheck %s --check-prefix=STATIC_PIE
+// STATIC_PIE: "-pie" "-static"
+// STATIC_PIE-NOT: "-dynamic-linker"
+// STATIC_PIE: "--no-dynamic-linker" "-z" "text"
+// STATIC_PIE:  "--eh-frame-hdr" "-z" "pack-relative-relocs"
+// STATIC_PIE: "crt0.o" "crti.o" "crtbeginS.o"
+// STATIC_PIE: "-lc" "crtendS.o" "crtn.o"
+
+/// -shared forces use of shared crt files
+// RUN: %clang -### %s --target=x86_64-pc-serenity --sysroot= \
+//  -shared 2>&1 | FileCheck %s --check-prefix=SHARED
+// SHARED: "-shared"
+// SHARED:  "--eh-frame-hdr" "-z" "pack-relative-relocs"
+// SHARED: "crt0_shared.o" "crti.o" "crtbeginS.o"
+// SHARED: "-lc" "crtendS.o" "crtn.o"
+
+/// -static forces use of static crt files
+// RUN: %clang -### %s --target=x86_64-pc-serenity --sysroot= \
+//  -static 2>&1 | FileCheck %s --check-prefix=STATIC
+// STATIC: "-static"
+// STATIC:  "--eh-frame-hdr" "-z" 

[mlir] [openmp] [llvm] [clang] [OpenMP] Introduce the KernelLaunchEnvironment as implicit argument (PR #70401)

2023-11-05 Thread via cfe-commits

ronlieb wrote:

performance degradation observed for this patch on trunk build :  hpc2021 8 
mpi210's reference run 
518.tealeaf   10.8%
534.hpgmg7.3%


https://github.com/llvm/llvm-project/pull/70401
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread Jimmy Z via cfe-commits

https://github.com/jimmy-zx updated 
https://github.com/llvm/llvm-project/pull/71341

>From 887751e365ca72515679f61d0734b1631ac38335 Mon Sep 17 00:00:00 2001
From: Jimmy Z <51149050+jimmy...@users.noreply.github.com>
Date: Mon, 6 Nov 2023 00:25:39 +
Subject: [PATCH 1/4] [libclang/python] Expose Rewriter to the libclang python
 binding.

---
 clang/bindings/python/clang/cindex.py | 62 
 .../python/tests/cindex/test_rewrite.py   | 74 +++
 2 files changed, 136 insertions(+)
 create mode 100644 clang/bindings/python/tests/cindex/test_rewrite.py

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 6a16f3a9ef6e957..e51d558ab73fbce 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3531,6 +3531,61 @@ def cursor(self):
 return cursor
 
 
+class Rewriter(ClangObject):
+"""
+The Rewriter is a wrapper class around clang::Rewriter
+
+It enables rewriting buffers.
+"""
+
+@staticmethod
+def create(tu):
+"""
+Creates a new Rewriter
+Parameters:
+tu -- The translation unit for the target AST.
+"""
+return Rewriter(conf.lib.clang_CXRewriter_create(tu))
+
+def __init__(self, ptr):
+ClangObject.__init__(self, ptr)
+
+def __del__(self):
+conf.lib.clang_CXRewriter_dispose(self)
+
+def insertTextBefore(self, loc, insert):
+"""
+Insert the specified string at the specified location in the original 
buffer.
+"""
+conf.lib.clang_CXRewriter_insertTextBefore(self, loc, insert)
+
+def replaceText(self, toBeReplaced, replacement):
+"""
+This method replaces a range of characters in the input buffer with a 
new string.
+"""
+conf.lib.clang_CXRewriter_replaceText(self, toBeReplaced, replacement)
+
+def removeText(self, toBeRemoved):
+"""
+Remove the specified text region.
+"""
+conf.lib.clang_CXRewriter_removeText(self, toBeRemoved)
+
+def overwriteChangedFiles(self):
+"""
+Save all changed files to disk.
+"""
+conf.lib.clang_CXRewriter_overwriteChangedFiles(self)
+
+def writeMainFileToStdOut(self):
+"""
+Writes the main file to stdout.
+"""
+conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
+
+
+
+
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types in common container.
@@ -3596,6 +3651,13 @@ def cursor(self):
 ("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int),
 ("clang_createIndex", [c_int, c_int], c_object_p),
 ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p),
+("clang_CXRewriter_create", [TranslationUnit], c_object_p),
+("clang_CXRewriter_dispose", [Rewriter]),
+("clang_CXRewriter_insertTextBefore", [Rewriter, SourceLocation, 
c_interop_string]),
+("clang_CXRewriter_overwriteChangedFiles", [Rewriter], c_int),
+("clang_CXRewriter_removeText", [Rewriter, SourceRange]),
+("clang_CXRewriter_replaceText", [Rewriter, SourceRange, 
c_interop_string]),
+("clang_CXRewriter_writeMainFileToStdOut", [Rewriter]),
 ("clang_CXXConstructor_isConvertingConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isCopyConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isDefaultConstructor", [Cursor], bool),
diff --git a/clang/bindings/python/tests/cindex/test_rewrite.py 
b/clang/bindings/python/tests/cindex/test_rewrite.py
new file mode 100644
index 000..eb697f72a923030
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_rewrite.py
@@ -0,0 +1,74 @@
+import sys
+import io
+import unittest
+import tempfile
+
+from clang.cindex import Rewriter, TranslationUnit, Config, File, 
SourceLocation, SourceRange
+
+class TestRewrite(unittest.TestCase):
+code = '''
+int test1;
+
+void test2(void);
+
+int f(int c) {
+return c;
+}
+'''
+
+@classmethod
+def setUpClass(cls):
+Config.set_compatibility_check(False)
+
+def setUp(self):
+self.tmp = tempfile.NamedTemporaryFile(suffix='.cpp', buffering=0)
+self.tmp.write(TestRewrite.code.encode('utf-8'))
+self.tmp.flush()
+self.tu = TranslationUnit.from_source(self.tmp.name)
+self.rew = Rewriter.create(self.tu)
+self.file = File.from_name(self.tu, self.tmp.name)
+
+def tearDown(self):
+self.tmp.close()
+
+
+def test_insert(self):
+snip = '#include \n'
+
+beginning = SourceLocation.from_offset(self.tu, self.file, 0)
+self.rew.insertTextBefore(beginning, snip)
+self.rew.overwriteChangedFiles()
+
+with open(self.tmp.name, 'r', encoding='utf-8') as f:
+self.assertEqual(f.read(), snip + TestRewrite.code)
+
+
+def test_replace(self):
+pattern = 'test2'
+replacement = 'func'
+
+offset = 

[PATCH] D154396: [clang] Add support for SerenityOS

2023-11-05 Thread Andrew Kaster via Phabricator via cfe-commits
ADKaster added inline comments.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:76
+  if (!IsStatic || IsStaticPIE)
+CmdArgs.push_back("--eh-frame-hdr");
+

MaskRay wrote:
> ADKaster wrote:
> > MaskRay wrote:
> > > This is not tested
> > Hm. this also seems like incorrect logic. In my next push I will remove 
> > this condition around --eh-frame-hdr to match the other ToolChains.
> https://maskray.me/blog/2020-11-08-stack-unwinding I have some notes on 
> ".eh_frame_hdr and PT_GNU_EH_FRAME". 
> 
> > Clang and GCC usually pass --eh-frame-hdr to ld, with the exception that 
> > gcc -static does not pass --eh-frame-hdr. The difference is a historical 
> > choice related to `__register_frame_info`.
Ah, this explains where @BertalanD got the original logic from, as we had a gcc 
port first. It was probably copied from our patched gcc spec files.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154396/new/

https://reviews.llvm.org/D154396

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] [llvm] [clang-tools-extra] [clang] [libcxx] [libc++] Allow running the test suite with optimizations (PR #68753)

2023-11-05 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff e3c2eacfd8b95346cfa4e71ba08b91cab124047b 
8499198a4d7b3b1e269f843ee71108cb6d7fc03c -- libcxx/test/support/escape.h 
libunwind/test/libunwind_02.pass.cpp libunwind/test/unw_resume.pass.cpp 
libunwind/test/unwind_leaffunction.pass.cpp
``





View the diff from clang-format here.


``diff
diff --git a/libunwind/test/libunwind_02.pass.cpp 
b/libunwind/test/libunwind_02.pass.cpp
index 499cc3b69ab3..32cbd40fb7cb 100644
--- a/libunwind/test/libunwind_02.pass.cpp
+++ b/libunwind/test/libunwind_02.pass.cpp
@@ -18,7 +18,8 @@
 #define EXPECTED_NUM_FRAMES 50
 #define NUM_FRAMES_UPPER_BOUND 100
 
-__attribute__((noinline)) _Unwind_Reason_Code callback(_Unwind_Context 
*context, void *cnt) {
+__attribute__((noinline)) _Unwind_Reason_Code callback(_Unwind_Context 
*context,
+   void *cnt) {
   (void)context;
   int *i = (int *)cnt;
   ++*i;
@@ -36,10 +37,11 @@ __attribute__((noinline)) void test_backtrace() {
   }
 }
 
-// These functions are effectively the same, but we have to be careful to 
avoid unwanted
-// optimizations that would mess with the number of frames we expect. 
Surprisingly,
-// slapping `noinline` is not sufficient -- we also have to avoid writing the 
function
-// in a way that the compiler can easily spot tail recursion.
+// These functions are effectively the same, but we have to be careful to avoid
+// unwanted optimizations that would mess with the number of frames we expect.
+// Surprisingly, slapping `noinline` is not sufficient -- we also have to avoid
+// writing the function in a way that the compiler can easily spot tail
+// recursion.
 __attribute__((noinline)) int test1(int i);
 __attribute__((noinline)) int test2(int i);
 
diff --git a/libunwind/test/unwind_leaffunction.pass.cpp 
b/libunwind/test/unwind_leaffunction.pass.cpp
index 6e6d9a0ed80d..9187368c66d0 100644
--- a/libunwind/test/unwind_leaffunction.pass.cpp
+++ b/libunwind/test/unwind_leaffunction.pass.cpp
@@ -24,7 +24,8 @@
 #include 
 #include 
 
-__attribute__((noinline)) _Unwind_Reason_Code frame_handler(struct 
_Unwind_Context* ctx, void* arg) {
+__attribute__((noinline)) _Unwind_Reason_Code
+frame_handler(struct _Unwind_Context *ctx, void *arg) {
   (void)arg;
   Dl_info info = { 0, 0, 0, 0 };
 

``




https://github.com/llvm/llvm-project/pull/68753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread Jimmy Z via cfe-commits

https://github.com/jimmy-zx updated 
https://github.com/llvm/llvm-project/pull/71341

>From 887751e365ca72515679f61d0734b1631ac38335 Mon Sep 17 00:00:00 2001
From: Jimmy Z <51149050+jimmy...@users.noreply.github.com>
Date: Mon, 6 Nov 2023 00:25:39 +
Subject: [PATCH 1/3] [libclang/python] Expose Rewriter to the libclang python
 binding.

---
 clang/bindings/python/clang/cindex.py | 62 
 .../python/tests/cindex/test_rewrite.py   | 74 +++
 2 files changed, 136 insertions(+)
 create mode 100644 clang/bindings/python/tests/cindex/test_rewrite.py

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 6a16f3a9ef6e957..e51d558ab73fbce 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3531,6 +3531,61 @@ def cursor(self):
 return cursor
 
 
+class Rewriter(ClangObject):
+"""
+The Rewriter is a wrapper class around clang::Rewriter
+
+It enables rewriting buffers.
+"""
+
+@staticmethod
+def create(tu):
+"""
+Creates a new Rewriter
+Parameters:
+tu -- The translation unit for the target AST.
+"""
+return Rewriter(conf.lib.clang_CXRewriter_create(tu))
+
+def __init__(self, ptr):
+ClangObject.__init__(self, ptr)
+
+def __del__(self):
+conf.lib.clang_CXRewriter_dispose(self)
+
+def insertTextBefore(self, loc, insert):
+"""
+Insert the specified string at the specified location in the original 
buffer.
+"""
+conf.lib.clang_CXRewriter_insertTextBefore(self, loc, insert)
+
+def replaceText(self, toBeReplaced, replacement):
+"""
+This method replaces a range of characters in the input buffer with a 
new string.
+"""
+conf.lib.clang_CXRewriter_replaceText(self, toBeReplaced, replacement)
+
+def removeText(self, toBeRemoved):
+"""
+Remove the specified text region.
+"""
+conf.lib.clang_CXRewriter_removeText(self, toBeRemoved)
+
+def overwriteChangedFiles(self):
+"""
+Save all changed files to disk.
+"""
+conf.lib.clang_CXRewriter_overwriteChangedFiles(self)
+
+def writeMainFileToStdOut(self):
+"""
+Writes the main file to stdout.
+"""
+conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
+
+
+
+
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types in common container.
@@ -3596,6 +3651,13 @@ def cursor(self):
 ("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int),
 ("clang_createIndex", [c_int, c_int], c_object_p),
 ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p),
+("clang_CXRewriter_create", [TranslationUnit], c_object_p),
+("clang_CXRewriter_dispose", [Rewriter]),
+("clang_CXRewriter_insertTextBefore", [Rewriter, SourceLocation, 
c_interop_string]),
+("clang_CXRewriter_overwriteChangedFiles", [Rewriter], c_int),
+("clang_CXRewriter_removeText", [Rewriter, SourceRange]),
+("clang_CXRewriter_replaceText", [Rewriter, SourceRange, 
c_interop_string]),
+("clang_CXRewriter_writeMainFileToStdOut", [Rewriter]),
 ("clang_CXXConstructor_isConvertingConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isCopyConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isDefaultConstructor", [Cursor], bool),
diff --git a/clang/bindings/python/tests/cindex/test_rewrite.py 
b/clang/bindings/python/tests/cindex/test_rewrite.py
new file mode 100644
index 000..eb697f72a923030
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_rewrite.py
@@ -0,0 +1,74 @@
+import sys
+import io
+import unittest
+import tempfile
+
+from clang.cindex import Rewriter, TranslationUnit, Config, File, 
SourceLocation, SourceRange
+
+class TestRewrite(unittest.TestCase):
+code = '''
+int test1;
+
+void test2(void);
+
+int f(int c) {
+return c;
+}
+'''
+
+@classmethod
+def setUpClass(cls):
+Config.set_compatibility_check(False)
+
+def setUp(self):
+self.tmp = tempfile.NamedTemporaryFile(suffix='.cpp', buffering=0)
+self.tmp.write(TestRewrite.code.encode('utf-8'))
+self.tmp.flush()
+self.tu = TranslationUnit.from_source(self.tmp.name)
+self.rew = Rewriter.create(self.tu)
+self.file = File.from_name(self.tu, self.tmp.name)
+
+def tearDown(self):
+self.tmp.close()
+
+
+def test_insert(self):
+snip = '#include \n'
+
+beginning = SourceLocation.from_offset(self.tu, self.file, 0)
+self.rew.insertTextBefore(beginning, snip)
+self.rew.overwriteChangedFiles()
+
+with open(self.tmp.name, 'r', encoding='utf-8') as f:
+self.assertEqual(f.read(), snip + TestRewrite.code)
+
+
+def test_replace(self):
+pattern = 'test2'
+replacement = 'func'
+
+offset = 

[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
cf7d4f543c73c2707e0c53bae1e7b8419e12b871..887751e365ca72515679f61d0734b1631ac38335
 clang/bindings/python/tests/cindex/test_rewrite.py 
clang/bindings/python/clang/cindex.py
``





View the diff from darker here.


``diff
--- clang/cindex.py 2023-11-06 00:25:39.00 +
+++ clang/cindex.py 2023-11-06 00:40:17.188462 +
@@ -3580,12 +3580,10 @@
 def writeMainFileToStdOut(self):
 """
 Writes the main file to stdout.
 """
 conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
-
-
 
 
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types in common container.

``




https://github.com/llvm/llvm-project/pull/71341
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] [clang] [InstCombine] Convert or concat to fshl if opposite or concat exists (PR #68502)

2023-11-05 Thread via cfe-commits

HaohaiWen wrote:




> > Any more comments? I'd like to merge it if no objection.
> 
> I think there are outstanding objections, or at least blocking concerns from 
> nikic.

gentle ping @nikic 

https://github.com/llvm/llvm-project/pull/68502
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread Jimmy Z via cfe-commits

https://github.com/jimmy-zx edited 
https://github.com/llvm/llvm-project/pull/71341
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] [libcxx] [clang] [libunwind] [libc++] Allow running the test suite with optimizations (PR #68753)

2023-11-05 Thread Louis Dionne via cfe-commits

https://github.com/ldionne updated 
https://github.com/llvm/llvm-project/pull/68753

>From 9824ef111975386152173916c1fd6a85264be0a0 Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Tue, 10 Oct 2023 16:35:11 -0700
Subject: [PATCH 1/5] [libc++] Allow running the test suite with optimizations

This patch adds a configuration of the libc++ test suite that enables
optimizations when building the tests. It also adds a new CI configuration
to exercise this on a regular basis. This is added in the context of [1],
which requires building with optimizations in order to hit the bug.

[1]: https://github.com/llvm/llvm-project/issues/68552
---
 libcxx/cmake/caches/Generic-optimized.cmake |  4 +++
 libcxx/utils/ci/buildkite-pipeline.yml  | 18 +
 libcxx/utils/ci/run-buildbot|  5 
 libcxx/utils/libcxx/test/params.py  | 28 -
 4 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/cmake/caches/Generic-optimized.cmake

diff --git a/libcxx/cmake/caches/Generic-optimized.cmake 
b/libcxx/cmake/caches/Generic-optimized.cmake
new file mode 100644
index 000..577a5de9f34c539
--- /dev/null
+++ b/libcxx/cmake/caches/Generic-optimized.cmake
@@ -0,0 +1,4 @@
+set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(LIBCXX_TEST_PARAMS "optimization=speed" CACHE STRING "")
+set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
+set(LIBUNWIND_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
diff --git a/libcxx/utils/ci/buildkite-pipeline.yml 
b/libcxx/utils/ci/buildkite-pipeline.yml
index ebfb35eee91e1ed..1b52d994081c46f 100644
--- a/libcxx/utils/ci/buildkite-pipeline.yml
+++ b/libcxx/utils/ci/buildkite-pipeline.yml
@@ -743,6 +743,24 @@ steps:
   limit: 2
 timeout_in_minutes: 120
 
+  - label: "Optimized build and test suite"
+command: "libcxx/utils/ci/run-buildbot generic-optimized"
+artifact_paths:
+  - "**/test-results.xml"
+  - "**/*.abilist"
+env:
+CC: "clang-${LLVM_HEAD_VERSION}"
+CXX: "clang++-${LLVM_HEAD_VERSION}"
+ENABLE_CLANG_TIDY: "On"
+agents:
+  queue: "libcxx-builders"
+  os: "linux"
+retry:
+  automatic:
+- exit_status: -1  # Agent was lost
+  limit: 2
+timeout_in_minutes: 120
+
   # Other non-testing CI jobs
   - label: "Benchmarks"
 command: "libcxx/utils/ci/run-buildbot benchmarks"
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index a71318123db3b12..18243b44a3d745c 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -479,6 +479,11 @@ generic-abi-unstable)
 generate-cmake -C 
"${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-abi-unstable.cmake"
 check-runtimes
 ;;
+generic-optimized)
+clean
+generate-cmake -C 
"${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-optimized.cmake"
+check-runtimes
+;;
 apple-system)
 clean
 
diff --git a/libcxx/utils/libcxx/test/params.py 
b/libcxx/utils/libcxx/test/params.py
index 456794b9b1cce95..9452f179aea3fec 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -11,7 +11,7 @@
 from pathlib import Path
 
 from libcxx.test.dsl import *
-from libcxx.test.features import _isMSVC
+from libcxx.test.features import _isClang, _isAppleClang, _isGCC, _isMSVC
 
 
 _warningFlags = [
@@ -90,6 +90,21 @@ def getStdFlag(cfg, std):
 return "-std=" + fallbacks[std]
 return None
 
+def getSpeedOptimizationFlag(cfg):
+if _isClang(cfg) or _isAppleClang(cfg) or _isGCC(cfg):
+return "-O3"
+elif _isMSVC(cfg):
+return "/O2"
+else:
+raise RuntimeError("Can't figure out what compiler is used in the 
configuration")
+
+def getSizeOptimizationFlag(cfg):
+if _isClang(cfg) or _isAppleClang(cfg) or _isGCC(cfg):
+return "-Os"
+elif _isMSVC(cfg):
+return "/O1"
+else:
+raise RuntimeError("Can't figure out what compiler is used in the 
configuration")
 
 # fmt: off
 DEFAULT_PARAMETERS = [
@@ -121,6 +136,17 @@ def getStdFlag(cfg, std):
 AddCompileFlag(lambda cfg: getStdFlag(cfg, std)),
 ],
 ),
+Parameter(
+name="optimization",
+choices=["none", "speed", "size"],
+type=str,
+help="The version of the standard to compile the test suite with.",
+default="none",
+actions=lambda opt: filter(None, [
+AddCompileFlag(lambda cfg: getSpeedOptimizationFlag(cfg)) if opt 
== "speed" else None,
+AddCompileFlag(lambda cfg: getSizeOptimizationFlag(cfg)) if opt == 
"size" else None,
+]),
+),
 Parameter(
 name="enable_modules",
 choices=["none", "clang", "clang-lsv"],

>From f799be39afed6b82d1942a87cea66a4d1192d765 Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Wed, 1 Nov 2023 10:56:30 -0400
Subject: [PATCH 2/5] Fix incorrect help

---
 libcxx/utils/libcxx/test/params.py | 2 +-
 1 file changed, 1 

[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread Jimmy Z via cfe-commits

https://github.com/jimmy-zx updated 
https://github.com/llvm/llvm-project/pull/71341

>From 887751e365ca72515679f61d0734b1631ac38335 Mon Sep 17 00:00:00 2001
From: Jimmy Z <51149050+jimmy...@users.noreply.github.com>
Date: Mon, 6 Nov 2023 00:25:39 +
Subject: [PATCH 1/2] [libclang/python] Expose Rewriter to the libclang python
 binding.

---
 clang/bindings/python/clang/cindex.py | 62 
 .../python/tests/cindex/test_rewrite.py   | 74 +++
 2 files changed, 136 insertions(+)
 create mode 100644 clang/bindings/python/tests/cindex/test_rewrite.py

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 6a16f3a9ef6e957..e51d558ab73fbce 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3531,6 +3531,61 @@ def cursor(self):
 return cursor
 
 
+class Rewriter(ClangObject):
+"""
+The Rewriter is a wrapper class around clang::Rewriter
+
+It enables rewriting buffers.
+"""
+
+@staticmethod
+def create(tu):
+"""
+Creates a new Rewriter
+Parameters:
+tu -- The translation unit for the target AST.
+"""
+return Rewriter(conf.lib.clang_CXRewriter_create(tu))
+
+def __init__(self, ptr):
+ClangObject.__init__(self, ptr)
+
+def __del__(self):
+conf.lib.clang_CXRewriter_dispose(self)
+
+def insertTextBefore(self, loc, insert):
+"""
+Insert the specified string at the specified location in the original 
buffer.
+"""
+conf.lib.clang_CXRewriter_insertTextBefore(self, loc, insert)
+
+def replaceText(self, toBeReplaced, replacement):
+"""
+This method replaces a range of characters in the input buffer with a 
new string.
+"""
+conf.lib.clang_CXRewriter_replaceText(self, toBeReplaced, replacement)
+
+def removeText(self, toBeRemoved):
+"""
+Remove the specified text region.
+"""
+conf.lib.clang_CXRewriter_removeText(self, toBeRemoved)
+
+def overwriteChangedFiles(self):
+"""
+Save all changed files to disk.
+"""
+conf.lib.clang_CXRewriter_overwriteChangedFiles(self)
+
+def writeMainFileToStdOut(self):
+"""
+Writes the main file to stdout.
+"""
+conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
+
+
+
+
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types in common container.
@@ -3596,6 +3651,13 @@ def cursor(self):
 ("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int),
 ("clang_createIndex", [c_int, c_int], c_object_p),
 ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p),
+("clang_CXRewriter_create", [TranslationUnit], c_object_p),
+("clang_CXRewriter_dispose", [Rewriter]),
+("clang_CXRewriter_insertTextBefore", [Rewriter, SourceLocation, 
c_interop_string]),
+("clang_CXRewriter_overwriteChangedFiles", [Rewriter], c_int),
+("clang_CXRewriter_removeText", [Rewriter, SourceRange]),
+("clang_CXRewriter_replaceText", [Rewriter, SourceRange, 
c_interop_string]),
+("clang_CXRewriter_writeMainFileToStdOut", [Rewriter]),
 ("clang_CXXConstructor_isConvertingConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isCopyConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isDefaultConstructor", [Cursor], bool),
diff --git a/clang/bindings/python/tests/cindex/test_rewrite.py 
b/clang/bindings/python/tests/cindex/test_rewrite.py
new file mode 100644
index 000..eb697f72a923030
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_rewrite.py
@@ -0,0 +1,74 @@
+import sys
+import io
+import unittest
+import tempfile
+
+from clang.cindex import Rewriter, TranslationUnit, Config, File, 
SourceLocation, SourceRange
+
+class TestRewrite(unittest.TestCase):
+code = '''
+int test1;
+
+void test2(void);
+
+int f(int c) {
+return c;
+}
+'''
+
+@classmethod
+def setUpClass(cls):
+Config.set_compatibility_check(False)
+
+def setUp(self):
+self.tmp = tempfile.NamedTemporaryFile(suffix='.cpp', buffering=0)
+self.tmp.write(TestRewrite.code.encode('utf-8'))
+self.tmp.flush()
+self.tu = TranslationUnit.from_source(self.tmp.name)
+self.rew = Rewriter.create(self.tu)
+self.file = File.from_name(self.tu, self.tmp.name)
+
+def tearDown(self):
+self.tmp.close()
+
+
+def test_insert(self):
+snip = '#include \n'
+
+beginning = SourceLocation.from_offset(self.tu, self.file, 0)
+self.rew.insertTextBefore(beginning, snip)
+self.rew.overwriteChangedFiles()
+
+with open(self.tmp.name, 'r', encoding='utf-8') as f:
+self.assertEqual(f.read(), snip + TestRewrite.code)
+
+
+def test_replace(self):
+pattern = 'test2'
+replacement = 'func'
+
+offset = 

[PATCH] D154396: [clang] Add support for SerenityOS

2023-11-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:76
+  if (!IsStatic || IsStaticPIE)
+CmdArgs.push_back("--eh-frame-hdr");
+

ADKaster wrote:
> MaskRay wrote:
> > This is not tested
> Hm. this also seems like incorrect logic. In my next push I will remove this 
> condition around --eh-frame-hdr to match the other ToolChains.
https://maskray.me/blog/2020-11-08-stack-unwinding I have some notes on 
".eh_frame_hdr and PT_GNU_EH_FRAME". 

> Clang and GCC usually pass --eh-frame-hdr to ld, with the exception that gcc 
> -static does not pass --eh-frame-hdr. The difference is a historical choice 
> related to `__register_frame_info`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154396/new/

https://reviews.llvm.org/D154396

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jimmy Z (jimmy-zx)


Changes

Exposes `CXRewriter` API in 
https://github.com/llvm/llvm-project/commit/69e5abb57b70570cf04671a93246e5e624023650.

---
Full diff: https://github.com/llvm/llvm-project/pull/71341.diff


2 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+62) 
- (added) clang/bindings/python/tests/cindex/test_rewrite.py (+74) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 6a16f3a9ef6e957..e51d558ab73fbce 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3531,6 +3531,61 @@ def cursor(self):
 return cursor
 
 
+class Rewriter(ClangObject):
+"""
+The Rewriter is a wrapper class around clang::Rewriter
+
+It enables rewriting buffers.
+"""
+
+@staticmethod
+def create(tu):
+"""
+Creates a new Rewriter
+Parameters:
+tu -- The translation unit for the target AST.
+"""
+return Rewriter(conf.lib.clang_CXRewriter_create(tu))
+
+def __init__(self, ptr):
+ClangObject.__init__(self, ptr)
+
+def __del__(self):
+conf.lib.clang_CXRewriter_dispose(self)
+
+def insertTextBefore(self, loc, insert):
+"""
+Insert the specified string at the specified location in the original 
buffer.
+"""
+conf.lib.clang_CXRewriter_insertTextBefore(self, loc, insert)
+
+def replaceText(self, toBeReplaced, replacement):
+"""
+This method replaces a range of characters in the input buffer with a 
new string.
+"""
+conf.lib.clang_CXRewriter_replaceText(self, toBeReplaced, replacement)
+
+def removeText(self, toBeRemoved):
+"""
+Remove the specified text region.
+"""
+conf.lib.clang_CXRewriter_removeText(self, toBeRemoved)
+
+def overwriteChangedFiles(self):
+"""
+Save all changed files to disk.
+"""
+conf.lib.clang_CXRewriter_overwriteChangedFiles(self)
+
+def writeMainFileToStdOut(self):
+"""
+Writes the main file to stdout.
+"""
+conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
+
+
+
+
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types in common container.
@@ -3596,6 +3651,13 @@ def cursor(self):
 ("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int),
 ("clang_createIndex", [c_int, c_int], c_object_p),
 ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p),
+("clang_CXRewriter_create", [TranslationUnit], c_object_p),
+("clang_CXRewriter_dispose", [Rewriter]),
+("clang_CXRewriter_insertTextBefore", [Rewriter, SourceLocation, 
c_interop_string]),
+("clang_CXRewriter_overwriteChangedFiles", [Rewriter], c_int),
+("clang_CXRewriter_removeText", [Rewriter, SourceRange]),
+("clang_CXRewriter_replaceText", [Rewriter, SourceRange, 
c_interop_string]),
+("clang_CXRewriter_writeMainFileToStdOut", [Rewriter]),
 ("clang_CXXConstructor_isConvertingConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isCopyConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isDefaultConstructor", [Cursor], bool),
diff --git a/clang/bindings/python/tests/cindex/test_rewrite.py 
b/clang/bindings/python/tests/cindex/test_rewrite.py
new file mode 100644
index 000..eb697f72a923030
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_rewrite.py
@@ -0,0 +1,74 @@
+import sys
+import io
+import unittest
+import tempfile
+
+from clang.cindex import Rewriter, TranslationUnit, Config, File, 
SourceLocation, SourceRange
+
+class TestRewrite(unittest.TestCase):
+code = '''
+int test1;
+
+void test2(void);
+
+int f(int c) {
+return c;
+}
+'''
+
+@classmethod
+def setUpClass(cls):
+Config.set_compatibility_check(False)
+
+def setUp(self):
+self.tmp = tempfile.NamedTemporaryFile(suffix='.cpp', buffering=0)
+self.tmp.write(TestRewrite.code.encode('utf-8'))
+self.tmp.flush()
+self.tu = TranslationUnit.from_source(self.tmp.name)
+self.rew = Rewriter.create(self.tu)
+self.file = File.from_name(self.tu, self.tmp.name)
+
+def tearDown(self):
+self.tmp.close()
+
+
+def test_insert(self):
+snip = '#include \n'
+
+beginning = SourceLocation.from_offset(self.tu, self.file, 0)
+self.rew.insertTextBefore(beginning, snip)
+self.rew.overwriteChangedFiles()
+
+with open(self.tmp.name, 'r', encoding='utf-8') as f:
+self.assertEqual(f.read(), snip + TestRewrite.code)
+
+
+def test_replace(self):
+pattern = 'test2'
+replacement = 'func'
+
+offset = TestRewrite.code.find(pattern)
+pattern_range = SourceRange.from_locations(
+SourceLocation.from_offset(self.tu, self.file, offset),
+

[clang] [libclang/python] Expose Rewriter to the libclang python binding. (PR #71341)

2023-11-05 Thread Jimmy Z via cfe-commits

https://github.com/jimmy-zx created 
https://github.com/llvm/llvm-project/pull/71341

Exposes `CXRewriter` API in 
https://github.com/llvm/llvm-project/commit/69e5abb57b70570cf04671a93246e5e624023650.

>From 887751e365ca72515679f61d0734b1631ac38335 Mon Sep 17 00:00:00 2001
From: Jimmy Z <51149050+jimmy...@users.noreply.github.com>
Date: Mon, 6 Nov 2023 00:25:39 +
Subject: [PATCH] [libclang/python] Expose Rewriter to the libclang python
 binding.

---
 clang/bindings/python/clang/cindex.py | 62 
 .../python/tests/cindex/test_rewrite.py   | 74 +++
 2 files changed, 136 insertions(+)
 create mode 100644 clang/bindings/python/tests/cindex/test_rewrite.py

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 6a16f3a9ef6e957..e51d558ab73fbce 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3531,6 +3531,61 @@ def cursor(self):
 return cursor
 
 
+class Rewriter(ClangObject):
+"""
+The Rewriter is a wrapper class around clang::Rewriter
+
+It enables rewriting buffers.
+"""
+
+@staticmethod
+def create(tu):
+"""
+Creates a new Rewriter
+Parameters:
+tu -- The translation unit for the target AST.
+"""
+return Rewriter(conf.lib.clang_CXRewriter_create(tu))
+
+def __init__(self, ptr):
+ClangObject.__init__(self, ptr)
+
+def __del__(self):
+conf.lib.clang_CXRewriter_dispose(self)
+
+def insertTextBefore(self, loc, insert):
+"""
+Insert the specified string at the specified location in the original 
buffer.
+"""
+conf.lib.clang_CXRewriter_insertTextBefore(self, loc, insert)
+
+def replaceText(self, toBeReplaced, replacement):
+"""
+This method replaces a range of characters in the input buffer with a 
new string.
+"""
+conf.lib.clang_CXRewriter_replaceText(self, toBeReplaced, replacement)
+
+def removeText(self, toBeRemoved):
+"""
+Remove the specified text region.
+"""
+conf.lib.clang_CXRewriter_removeText(self, toBeRemoved)
+
+def overwriteChangedFiles(self):
+"""
+Save all changed files to disk.
+"""
+conf.lib.clang_CXRewriter_overwriteChangedFiles(self)
+
+def writeMainFileToStdOut(self):
+"""
+Writes the main file to stdout.
+"""
+conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
+
+
+
+
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types in common container.
@@ -3596,6 +3651,13 @@ def cursor(self):
 ("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int),
 ("clang_createIndex", [c_int, c_int], c_object_p),
 ("clang_createTranslationUnit", [Index, c_interop_string], c_object_p),
+("clang_CXRewriter_create", [TranslationUnit], c_object_p),
+("clang_CXRewriter_dispose", [Rewriter]),
+("clang_CXRewriter_insertTextBefore", [Rewriter, SourceLocation, 
c_interop_string]),
+("clang_CXRewriter_overwriteChangedFiles", [Rewriter], c_int),
+("clang_CXRewriter_removeText", [Rewriter, SourceRange]),
+("clang_CXRewriter_replaceText", [Rewriter, SourceRange, 
c_interop_string]),
+("clang_CXRewriter_writeMainFileToStdOut", [Rewriter]),
 ("clang_CXXConstructor_isConvertingConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isCopyConstructor", [Cursor], bool),
 ("clang_CXXConstructor_isDefaultConstructor", [Cursor], bool),
diff --git a/clang/bindings/python/tests/cindex/test_rewrite.py 
b/clang/bindings/python/tests/cindex/test_rewrite.py
new file mode 100644
index 000..eb697f72a923030
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_rewrite.py
@@ -0,0 +1,74 @@
+import sys
+import io
+import unittest
+import tempfile
+
+from clang.cindex import Rewriter, TranslationUnit, Config, File, 
SourceLocation, SourceRange
+
+class TestRewrite(unittest.TestCase):
+code = '''
+int test1;
+
+void test2(void);
+
+int f(int c) {
+return c;
+}
+'''
+
+@classmethod
+def setUpClass(cls):
+Config.set_compatibility_check(False)
+
+def setUp(self):
+self.tmp = tempfile.NamedTemporaryFile(suffix='.cpp', buffering=0)
+self.tmp.write(TestRewrite.code.encode('utf-8'))
+self.tmp.flush()
+self.tu = TranslationUnit.from_source(self.tmp.name)
+self.rew = Rewriter.create(self.tu)
+self.file = File.from_name(self.tu, self.tmp.name)
+
+def tearDown(self):
+self.tmp.close()
+
+
+def test_insert(self):
+snip = '#include \n'
+
+beginning = SourceLocation.from_offset(self.tu, self.file, 0)
+self.rew.insertTextBefore(beginning, snip)
+self.rew.overwriteChangedFiles()
+
+with open(self.tmp.name, 'r', encoding='utf-8') as f:
+self.assertEqual(f.read(), snip + TestRewrite.code)
+
+
+  

[clang] [clang] Allow MCTargetOptions to be parseable by -mllvm. (PR #66347)

2023-11-05 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay requested changes to this pull request.

Agree that the motivation should be communicated. Driver options have stronger 
stability guarantee. If there are sufficient motivation and useful 
MCTargetOptions that we don't feel comfortable exposing driver options, I think 
this is probably fine.

We probably don't want to test every option. Just 2 or 3 suffices.

https://github.com/llvm/llvm-project/pull/66347
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libc] [libcxx] [clang] [libcxxabi] [llvm] [lld] [flang] [clang-tools-extra] [compiler-rt] [libc++] Fix the behavior of throwing `operator new` under -fno-exceptions (PR #69498)

2023-11-05 Thread Louis Dionne via cfe-commits

ldionne wrote:

> I think we can check whether it's been overridden more easily using an asm 
> alias like this (when libc++ is built under -fno-exceptions):

This doesn't work on Darwin (apparently we don't support the alias attribute on 
that platform). I could investigate doing this all non-Darwin platforms, 
however that would make the utility a lot less generic than in my latest patch, 
since I'd have to handle each function I want to check for overrides 
individually.


https://github.com/llvm/llvm-project/pull/69498
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libc] [libcxx] [clang] [libcxxabi] [llvm] [lld] [flang] [clang-tools-extra] [compiler-rt] [libc++] Fix the behavior of throwing `operator new` under -fno-exceptions (PR #69498)

2023-11-05 Thread Louis Dionne via cfe-commits

https://github.com/ldionne updated 
https://github.com/llvm/llvm-project/pull/69498

>From 77c0256c3ae99808a8def68bfcf5eee2fad704ca Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Wed, 14 Jun 2023 17:49:22 -0700
Subject: [PATCH 1/7] [libc++] Fix the behavior of throwing `operator new`
 under -fno-exceptions

In D144319, Clang tried to land a change that would cause some functions
that are not supposed to return nullptr to optimize better. As reported
in https://reviews.llvm.org/D144319#4203982, libc++ started seeing failures
in its CI shortly after this change was landed.

As explained in D146379, the reason for these failures is that libc++'s
throwing `operator new` can in fact return nullptr when compiled with
exceptions disabled. However, this contradicts the Standard, which
clearly says that the throwing version of `operator new(size_t)`
should never return nullptr. This is actually a long standing issue.
I've previously seen a case where LTO would optimize incorrectly based
on the assumption that `operator new` doesn't return nullptr, an
assumption that was violated in that case because libc++.dylib was
compiled with -fno-exceptions.

Unfortunately, fixing this is kind of tricky. The Standard has a few
requirements for the allocation functions, some of which are impossible
to satisfy under -fno-exceptions:
1. `operator new(size_t)` must never return nullptr
2. `operator new(size_t, nothrow_t)` must call the throwing version
 and return nullptr on failure to allocate
3. We can't throw exceptions when compiled with -fno-exceptions

In the case where exceptions are enabled, things work nicely. `new(size_t)`
throws and `new(size_t, nothrow_t)` uses a try-catch to return nullptr.
However, when compiling the library with -fno-exceptions, we can't throw
an exception from `new(size_t)`, and we can't catch anything from
`new(size_t, nothrow_t)`. The only thing we can do from `new(size_t)`
is actually abort the program, which does not make it possible for
`new(size_t, nothrow_t)` to catch something and return nullptr.

This patch makes the following changes:
1. When compiled with -fno-exceptions, the throwing version of
   `operator new` will now abort on failure instead of returning
   nullptr on failure. This resolves the issue that the compiler
   could mis-compile based on the assumption that nullptr is never
   returned. This constitutes an API and ABI breaking change for
   folks compiling the library with -fno-exceptions (which is not
   the general public, who merely uses libc++ headers but use a
   shared library that has already been compiled). This should mostly
   impact vendors and other folks who compile libc++.dylib themselves.

2. When the library is compiled with -fexceptions, the nothrow version
   of `operator new` has no change. When the library is compiled with
   -fno-exceptions, the nothrow version of `operator new` will now check
   whether the throwing version of `operator new` has been overridden.
   If it has not been overridden, then it will use an implementation
   equivalent to that of the throwing `operator new`, except it will
   return nullptr on failure to allocate (instead of terminating).
   However, if the throwing `operator new` has been overridden, it is
   now an error NOT to also override the nothrow `operator new`. Indeed,
   there is no way for us to implement a valid nothrow `operator new`
   without knowing the exact implementation of the throwing version.

rdar://103958777

Differential Revision: https://reviews.llvm.org/D150610
---
 libcxx/docs/ReleaseNotes/18.rst   | 23 +
 libcxx/include/CMakeLists.txt |  1 +
 libcxx/include/__overridable_function | 38 
 libcxx/include/new|  9 +-
 libcxx/src/new.cpp| 79 +++-
 ...new_not_overridden_fno_exceptions.pass.cpp | 56 
 .../new_dont_return_nullptr.pass.cpp  | 37 
 libcxx/test/support/check_assertion.h |  6 ++
 libcxxabi/src/stdlib_new_delete.cpp   | 90 ++-
 9 files changed, 291 insertions(+), 48 deletions(-)
 create mode 100644 libcxx/include/__overridable_function
 create mode 100644 
libcxx/test/libcxx/language.support/support.dynamic/assert.nothrow_new_not_overridden_fno_exceptions.pass.cpp
 create mode 100644 
libcxx/test/libcxx/language.support/support.dynamic/new_dont_return_nullptr.pass.cpp

diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index ac78563aa73848f..bf017613a01b892 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -118,6 +118,29 @@ LLVM 20
 ABI Affecting Changes
 -
 
+- When the shared/static library is built with ``-fno-exceptions``, the 
behavior of ``operator new`` was changed
+  to make it standards-conforming. In LLVM 17 and before, the throwing 
versions of ``operator new`` would return
+  ``nullptr`` upon failure to allocate, when 

[libcxx] [clang] [llvm] [libc] [clang-tools-extra] [compiler-rt] [flang] [libcxxabi] [lld] [libc++] Fix the behavior of throwing `operator new` under -fno-exceptions (PR #69498)

2023-11-05 Thread Louis Dionne via cfe-commits


@@ -0,0 +1,38 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___OVERRIDABLE_FUNCTION
+#define _LIBCPP___OVERRIDABLE_FUNCTION
+
+#include <__config>
+#include 
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#define _LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE   
\
+  
__attribute__((__section__("__TEXT,__lcxx_override,regular,pure_instructions")))

ldionne wrote:

I think I finally got this to work for ELF! The next revision will tell.

https://github.com/llvm/llvm-project/pull/69498
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Do not pass -canonical-system-headers on Windows by default (PR #71097)

2023-11-05 Thread Fangrui Song via cfe-commits


@@ -1,3 +1,6 @@
+// REQUIRES: !system-windows

MaskRay wrote:

`UNSUPPORTED: system-windows`

https://github.com/llvm/llvm-project/pull/71097
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Do not pass -canonical-system-headers on Windows by default (PR #71097)

2023-11-05 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/71097
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Do not pass -canonical-system-headers on Windows by default (PR #71097)

2023-11-05 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/71097
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Do not pass -canonical-system-headers on Windows by default (PR #71097)

2023-11-05 Thread Fangrui Song via cfe-commits


@@ -1180,8 +1180,19 @@ void Clang::AddPreprocessingOptions(Compilation , 
const JobAction ,
 if (ArgM->getOption().matches(options::OPT_M) ||
 ArgM->getOption().matches(options::OPT_MD))
   CmdArgs.push_back("-sys-header-deps");
+
+  // #70011: Canonicalization on Windows does unexpected things like change
+  // drive letters.
+  // FIXME: find and use Windows API that canonicalizes paths except for
+  // drive letter.
+#if defined(_WIN32) || defined(_WIN64)

MaskRay wrote:

`_WIN32` is defined on 64-bit Windows.

https://github.com/llvm/llvm-project/pull/71097
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154396: [clang] Add support for SerenityOS

2023-11-05 Thread Andrew Kaster via Phabricator via cfe-commits
ADKaster added inline comments.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:76
+  if (!IsStatic || IsStaticPIE)
+CmdArgs.push_back("--eh-frame-hdr");
+

MaskRay wrote:
> This is not tested
Hm. this also seems like incorrect logic. In my next push I will remove this 
condition around --eh-frame-hdr to match the other ToolChains.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154396/new/

https://reviews.llvm.org/D154396

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer][solver] On SymSym RelOps, check EQClass members for contradictions (PR #71284)

2023-11-05 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

I think every time we need to iterate over all member of an equivalence class, 
we might do something wrong. The point of the equivalence class would be to 
make sure those elements are equivalent. One way to avoid iteration would be to 
always use the representative of the equivalence class. E.g., each time we 
record a new constraint to a member of the class, we add this information to 
the representative element. Every time we do a query, we first look up the 
representative element which already should have all the info from the class 
and use it instead of the original symbol.

Would something like this work or am I missing something?

https://github.com/llvm/llvm-project/pull/71284
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150083: [clang-format] ObjCPropertyAttributeOrder to sort ObjC property attributes

2023-11-05 Thread Jared Grubb via Phabricator via cfe-commits
jaredgrubb updated this revision to Diff 558010.
jaredgrubb added a comment.

Adjusting the Style comments, since the behavior changed and were not updated 
to reflect that leading/trailing comments no longer have special handling.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150083/new/

https://reviews.llvm.org/D150083

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp
  clang/lib/Format/ObjCPropertyAttributeOrderFixer.h
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp

Index: clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp
@@ -0,0 +1,412 @@
+//===- unittest/Format/ObjCPropertyAttributeOrderFixerTest.cpp - unit tests
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "../lib/Format/ObjCPropertyAttributeOrderFixer.h"
+#include "FormatTestBase.h"
+#include "TestLexer.h"
+
+#define DEBUG_TYPE "format-objc-property-attribute-order-fixer-test"
+
+namespace clang {
+namespace format {
+namespace test {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, ).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, ).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class ObjCPropertyAttributeOrderFixerTest : public FormatTestBase {
+protected:
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle  = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+};
+
+TEST_F(ObjCPropertyAttributeOrderFixerTest, ParsesStyleOption) {
+  FormatStyle Style = {};
+  Style.Language = FormatStyle::LK_ObjC;
+
+  CHECK_PARSE("ObjCPropertyAttributeOrder: [class]", ObjCPropertyAttributeOrder,
+  std::vector({"class"}));
+
+  CHECK_PARSE("ObjCPropertyAttributeOrder: ["
+  "class, direct, atomic, nonatomic, "
+  "assign, retain, strong, copy, weak, unsafe_unretained, "
+  "readonly, readwrite, getter, setter, "
+  "nullable, nonnull, null_resettable, null_unspecified"
+  "]",
+  ObjCPropertyAttributeOrder,
+  std::vector({
+  "class",
+  "direct",
+  "atomic",
+  "nonatomic",
+  "assign",
+  "retain",
+  "strong",
+  "copy",
+  "weak",
+  "unsafe_unretained",
+  "readonly",
+  "readwrite",
+  "getter",
+  "setter",
+  "nullable",
+  "nonnull",
+  "null_resettable",
+  "null_unspecified",
+  }));
+}
+
+TEST_F(ObjCPropertyAttributeOrderFixerTest, SortsSpecifiedAttributes) {
+  FormatStyle Style = getLLVMStyle();
+  Style.Language = FormatStyle::LK_ObjC;
+  Style.ObjCPropertyAttributeOrder = {"a", "b", "c"};
+
+  // Zero: nothing to do, but is legal.
+  verifyFormat("@property() int p;", Style);
+
+  // One: shouldn't move.
+  verifyFormat("@property(a) int p;", Style);
+  verifyFormat("@property(b) int p;", Style);
+  verifyFormat("@property(c) int p;", Style);
+
+  // Two in correct order already: no change.
+  verifyFormat("@property(a, b) int p;", Style);
+  verifyFormat("@property(a, c) int p;", Style);
+  verifyFormat("@property(b, c) int p;", Style);
+
+  // Three in correct order already: no change.
+  verifyFormat("@property(a, b, c) int p;", Style);
+
+  // Two wrong order.
+  verifyFormat("@property(a, b) int p;", "@property(b, a) int p;", Style);
+  verifyFormat("@property(a, c) int p;", "@property(c, a) int p;", Style);
+  verifyFormat("@property(b, c) int p;", "@property(c, b) int p;", Style);
+
+  // Three wrong order.
+  verifyFormat("@property(a, b, c) int p;", "@property(b, a, c) int p;", Style);
+  verifyFormat("@property(a, b, c) int p;", "@property(c, b, a) int p;", Style);
+
+  // Check that properties preceded by @optional/@required work.
+  

[PATCH] D154396: [clang] Add support for SerenityOS

2023-11-05 Thread Andrew Kaster via Phabricator via cfe-commits
ADKaster added inline comments.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:202
+  addSystemInclude(DriverArgs, CC1Args,
+   concat(D.SysRoot, "/usr/local/include"));
+  addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, "/usr/include"));

brad wrote:
> IMO if the library path is removed then the header path should be as well.
Fair. /usr/local is the prefix that all ports in the Ports/ tree are installed 
into by default (though some end up with files in /opt). We can for sure work a 
bit harder to make those headers/libs available to ports in our build 
infrastructure for them rather than putting that logic in the compiler.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:211
+  options::OPT_fno_use_init_array, true))
+CC1Args.push_back("-fno-use-init-array");
+}

MaskRay wrote:
> This is for systems that historically support .ctors/.dtors 
> https://maskray.me/blog/2021-11-07-init-ctors-init-array
> 
> If Serenity doesn't, this should be removed.
It's my understanding that we don't currently support .ctors/.dtors, though we 
did a few years ago. It is a bit confusing to me how those are related to 
.init/.fini though. We have some stubs here for `crti.S` and `crtn.S` 
https://github.com/SerenityOS/serenity/blob/cf3c8a216be5aa496844aadb43ca05ad5c47bb46/Userland/Libraries/LibC/arch/x86_64/crti.S
 which end up giving every .so and executable a DT_INIT section, but all the 
actual global ctors and dtors end up in .init_array/.fini_array.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154396/new/

https://reviews.llvm.org/D154396

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [libcxx] [clang] [libc] [flang] [llvm] [clang-tools-extra] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-11-05 Thread Anton Rydahl via cfe-commits

https://github.com/AntonRydahl updated 
https://github.com/llvm/llvm-project/pull/68642

>From f0d93cc6a5cd485c654ab38221691db038bacc7d Mon Sep 17 00:00:00 2001
From: AntonRydahl 
Date: Mon, 9 Oct 2023 15:13:22 -0700
Subject: [PATCH 1/5] Merged __is_trivial_equality_predicate and
 __is_trivial_plus_operation into __desugars_to

---
 libcxx/include/CMakeLists.txt |  1 -
 libcxx/include/__algorithm/comp.h |  7 ++---
 libcxx/include/__algorithm/equal.h| 22 
 .../cpu_backends/transform_reduce.h   | 23 
 libcxx/include/__functional/operations.h  | 15 +--
 .../include/__functional/ranges_operations.h  |  7 ++---
 .../include/__numeric/pstl_transform_reduce.h |  2 +-
 .../include/__type_traits/operation_traits.h  |  4 +--
 .../include/__type_traits/predicate_traits.h  | 26 ---
 libcxx/include/module.modulemap.in|  1 -
 10 files changed, 40 insertions(+), 68 deletions(-)
 delete mode 100644 libcxx/include/__type_traits/predicate_traits.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 340353f8ebb41c4..7eb09a06ccd482e 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -813,7 +813,6 @@ set(files
   __type_traits/negation.h
   __type_traits/noexcept_move_assign_container.h
   __type_traits/operation_traits.h
-  __type_traits/predicate_traits.h
   __type_traits/promote.h
   __type_traits/rank.h
   __type_traits/remove_all_extents.h
diff --git a/libcxx/include/__algorithm/comp.h 
b/libcxx/include/__algorithm/comp.h
index 9474536615ffb67..0993c37cce36a6b 100644
--- a/libcxx/include/__algorithm/comp.h
+++ b/libcxx/include/__algorithm/comp.h
@@ -10,8 +10,9 @@
 #define _LIBCPP___ALGORITHM_COMP_H
 
 #include <__config>
+#include <__functional/operations.h>
 #include <__type_traits/integral_constant.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -26,8 +27,8 @@ struct __equal_to {
   }
 };
 
-template 
-struct __is_trivial_equality_predicate<__equal_to, _Lhs, _Rhs> : true_type {};
+template <>
+struct __desugars_to<__equal_to, std::equal_to<>> : true_type {};
 
 // The definition is required because __less is part of the ABI, but it's empty
 // because all comparisons should be transparent.
diff --git a/libcxx/include/__algorithm/equal.h 
b/libcxx/include/__algorithm/equal.h
index b69aeff92bb9289..35e82da15e4d058 100644
--- a/libcxx/include/__algorithm/equal.h
+++ b/libcxx/include/__algorithm/equal.h
@@ -15,6 +15,7 @@
 #include <__config>
 #include <__functional/identity.h>
 #include <__functional/invoke.h>
+#include <__functional/operations.h>
 #include <__iterator/distance.h>
 #include <__iterator/iterator_traits.h>
 #include <__string/constexpr_c_functions.h>
@@ -23,7 +24,7 @@
 #include <__type_traits/is_constant_evaluated.h>
 #include <__type_traits/is_equality_comparable.h>
 #include <__type_traits/is_volatile.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 #include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -41,13 +42,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI 
_LIBCPP_CONSTEXPR_SINCE_CXX20 boo
   return true;
 }
 
-template <
-class _Tp,
-class _Up,
-class _BinaryPredicate,
-__enable_if_t<__is_trivial_equality_predicate<_BinaryPredicate, _Tp, 
_Up>::value && !is_volatile<_Tp>::value &&
-  !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
-  int> = 0>
+template < class _Tp,
+   class _Up,
+   class _BinaryPredicate,
+   __enable_if_t<__desugars_to<_BinaryPredicate, 
std::equal_to<>>::value && !is_volatile<_Tp>::value &&
+ !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
+ int> = 0>
 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool
 __equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, 
_BinaryPredicate&) {
   return std::__constexpr_memcmp_equal(__first1, __first2, 
__element_count(__last1 - __first1));
@@ -94,12 +94,12 @@ template ::value && __is_identity<_Proj1>::value &&
+  __enable_if_t<__desugars_to<_Pred, std::equal_to<>>::value && 
__is_identity<_Proj1>::value &&
 __is_identity<_Proj2>::value && 
!is_volatile<_Tp>::value && !is_volatile<_Up>::value &&
 __libcpp_is_trivially_equality_comparable<_Tp, 
_Up>::value,
 int> = 0>
-_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool __equal_impl(
-_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, 
_Proj2&) {
+_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool

[libcxx] [clang] [libc] [flang] [llvm] [compiler-rt] [clang-tools-extra] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-11-05 Thread Anton Rydahl via cfe-commits

https://github.com/AntonRydahl updated 
https://github.com/llvm/llvm-project/pull/68642

>From f0d93cc6a5cd485c654ab38221691db038bacc7d Mon Sep 17 00:00:00 2001
From: AntonRydahl 
Date: Mon, 9 Oct 2023 15:13:22 -0700
Subject: [PATCH 1/5] Merged __is_trivial_equality_predicate and
 __is_trivial_plus_operation into __desugars_to

---
 libcxx/include/CMakeLists.txt |  1 -
 libcxx/include/__algorithm/comp.h |  7 ++---
 libcxx/include/__algorithm/equal.h| 22 
 .../cpu_backends/transform_reduce.h   | 23 
 libcxx/include/__functional/operations.h  | 15 +--
 .../include/__functional/ranges_operations.h  |  7 ++---
 .../include/__numeric/pstl_transform_reduce.h |  2 +-
 .../include/__type_traits/operation_traits.h  |  4 +--
 .../include/__type_traits/predicate_traits.h  | 26 ---
 libcxx/include/module.modulemap.in|  1 -
 10 files changed, 40 insertions(+), 68 deletions(-)
 delete mode 100644 libcxx/include/__type_traits/predicate_traits.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 340353f8ebb41c4..7eb09a06ccd482e 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -813,7 +813,6 @@ set(files
   __type_traits/negation.h
   __type_traits/noexcept_move_assign_container.h
   __type_traits/operation_traits.h
-  __type_traits/predicate_traits.h
   __type_traits/promote.h
   __type_traits/rank.h
   __type_traits/remove_all_extents.h
diff --git a/libcxx/include/__algorithm/comp.h 
b/libcxx/include/__algorithm/comp.h
index 9474536615ffb67..0993c37cce36a6b 100644
--- a/libcxx/include/__algorithm/comp.h
+++ b/libcxx/include/__algorithm/comp.h
@@ -10,8 +10,9 @@
 #define _LIBCPP___ALGORITHM_COMP_H
 
 #include <__config>
+#include <__functional/operations.h>
 #include <__type_traits/integral_constant.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -26,8 +27,8 @@ struct __equal_to {
   }
 };
 
-template 
-struct __is_trivial_equality_predicate<__equal_to, _Lhs, _Rhs> : true_type {};
+template <>
+struct __desugars_to<__equal_to, std::equal_to<>> : true_type {};
 
 // The definition is required because __less is part of the ABI, but it's empty
 // because all comparisons should be transparent.
diff --git a/libcxx/include/__algorithm/equal.h 
b/libcxx/include/__algorithm/equal.h
index b69aeff92bb9289..35e82da15e4d058 100644
--- a/libcxx/include/__algorithm/equal.h
+++ b/libcxx/include/__algorithm/equal.h
@@ -15,6 +15,7 @@
 #include <__config>
 #include <__functional/identity.h>
 #include <__functional/invoke.h>
+#include <__functional/operations.h>
 #include <__iterator/distance.h>
 #include <__iterator/iterator_traits.h>
 #include <__string/constexpr_c_functions.h>
@@ -23,7 +24,7 @@
 #include <__type_traits/is_constant_evaluated.h>
 #include <__type_traits/is_equality_comparable.h>
 #include <__type_traits/is_volatile.h>
-#include <__type_traits/predicate_traits.h>
+#include <__type_traits/operation_traits.h>
 #include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -41,13 +42,12 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI 
_LIBCPP_CONSTEXPR_SINCE_CXX20 boo
   return true;
 }
 
-template <
-class _Tp,
-class _Up,
-class _BinaryPredicate,
-__enable_if_t<__is_trivial_equality_predicate<_BinaryPredicate, _Tp, 
_Up>::value && !is_volatile<_Tp>::value &&
-  !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
-  int> = 0>
+template < class _Tp,
+   class _Up,
+   class _BinaryPredicate,
+   __enable_if_t<__desugars_to<_BinaryPredicate, 
std::equal_to<>>::value && !is_volatile<_Tp>::value &&
+ !is_volatile<_Up>::value && 
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
+ int> = 0>
 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool
 __equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, 
_BinaryPredicate&) {
   return std::__constexpr_memcmp_equal(__first1, __first2, 
__element_count(__last1 - __first1));
@@ -94,12 +94,12 @@ template ::value && __is_identity<_Proj1>::value &&
+  __enable_if_t<__desugars_to<_Pred, std::equal_to<>>::value && 
__is_identity<_Proj1>::value &&
 __is_identity<_Proj2>::value && 
!is_volatile<_Tp>::value && !is_volatile<_Up>::value &&
 __libcpp_is_trivially_equality_comparable<_Tp, 
_Up>::value,
 int> = 0>
-_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool __equal_impl(
-_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, 
_Proj2&) {
+_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 
bool

[clang] [StackProtector] Do not emit the stack protector on GPU architectures (PR #70799)

2023-11-05 Thread Fangrui Song via cfe-commits

MaskRay wrote:

I think this is fine, but we probably should think about the general option 
compatibility problem 
https://github.com/llvm/llvm-project/pull/70740#issuecomment-1786180822

https://github.com/llvm/llvm-project/pull/70799
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Added removal of file extension when guessing the toolchain (PR #69887)

2023-11-05 Thread Fangrui Song via cfe-commits

MaskRay wrote:

In quite a few places we only detect `.exe` as the extension name. I am not 
sure we should commit to arbitrary extension name now. The build systems can 
consider `--driver-mode=cl`

https://github.com/llvm/llvm-project/pull/69887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][Solaris][NFC] A little bit of clean up (PR #69867)

2023-11-05 Thread Brad Smith via cfe-commits

https://github.com/brad0 closed https://github.com/llvm/llvm-project/pull/69867
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8103ae6 - [Driver][Solaris][NFC] A little bit of clean up (#69867)

2023-11-05 Thread via cfe-commits

Author: Brad Smith
Date: 2023-11-05T15:09:31-05:00
New Revision: 8103ae666402fbcfd68839994bfd848c3925fbed

URL: 
https://github.com/llvm/llvm-project/commit/8103ae666402fbcfd68839994bfd848c3925fbed
DIFF: 
https://github.com/llvm/llvm-project/commit/8103ae666402fbcfd68839994bfd848c3925fbed.diff

LOG: [Driver][Solaris][NFC] A little bit of clean up (#69867)

Added: 


Modified: 
clang/lib/Driver/ToolChains/Solaris.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Solaris.cpp 
b/clang/lib/Driver/ToolChains/Solaris.cpp
index 5421c029562abca..e45932008a65ab8 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -87,10 +87,12 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
const InputInfoList ,
const ArgList ,
const char *LinkingOutput) const {
-  const Driver  = getToolChain().getDriver();
-  const bool IsPIE = getPIE(Args, getToolChain());
+  const auto  = static_cast(getToolChain());
+  const Driver  = ToolChain.getDriver();
+  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const bool IsPIE = getPIE(Args, ToolChain);
+  const bool LinkerIsGnuLd = isLinkerGnuLd(ToolChain, Args);
   ArgStringList CmdArgs;
-  bool LinkerIsGnuLd = isLinkerGnuLd(getToolChain(), Args);
 
   // Demangle C++ names in errors.  GNU ld already defaults to --demangle.
   if (!LinkerIsGnuLd)
@@ -126,9 +128,6 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   if (LinkerIsGnuLd) {
 // Set the correct linker emulation for 32- and 64-bit Solaris.
-const auto  = static_cast(getToolChain());
-const llvm::Triple::ArchType Arch = ToolChain.getArch();
-
 switch (Arch) {
 case llvm::Triple::x86:
   CmdArgs.push_back("-m");
@@ -168,10 +167,9 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
options::OPT_r)) {
 if (!Args.hasArg(options::OPT_shared))
-  CmdArgs.push_back(
-  Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
+  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
 
-
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
 
 const Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi);
 bool HaveAnsi = false;
@@ -186,43 +184,42 @@ void solaris::Linker::ConstructJob(Compilation , const 
JobAction ,
 // Use values-Xc.o for -ansi, -std=c*, -std=iso9899:199409.
 if (HaveAnsi || (LangStd && !LangStd->isGNUMode()))
   values_X = "values-Xc.o";
-
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(values_X)));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(values_X)));
 
 const char *values_xpg = "values-xpg6.o";
 // Use values-xpg4.o for -std=c90, -std=gnu90, -std=iso9899:199409.
 if (LangStd && LangStd->getLanguage() == Language::C && !LangStd->isC99())
   values_xpg = "values-xpg4.o";
-CmdArgs.push_back(
-Args.MakeArgString(getToolChain().GetFilePath(values_xpg)));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(values_xpg)));
 
 const char *crtbegin = nullptr;
 if (Args.hasArg(options::OPT_shared) || IsPIE)
   crtbegin = "crtbeginS.o";
 else
   crtbegin = "crtbegin.o";
-
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(crtbegin)));
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
 // Add crtfastmath.o if available and fast math is enabled.
-getToolChain().addFastMathRuntimeIfAvailable(Args, CmdArgs);
+ToolChain.addFastMathRuntimeIfAvailable(Args, CmdArgs);
   }
 
-  getToolChain().AddFilePathLibArgs(Args, CmdArgs);
+  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
   Args.addAllArgs(CmdArgs,
   {options::OPT_L, options::OPT_T_Group, options::OPT_r});
 
-  bool NeedsSanitizerDeps = addSanitizerRuntimes(getToolChain(), Args, 
CmdArgs);
-  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+  bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
 // Use the static OpenMP runtime with -static-openmp
 bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
 !Args.hasArg(options::OPT_static);
-addOpenMPRuntime(CmdArgs, getToolChain(), Args, StaticOpenMP);
+addOpenMPRuntime(CmdArgs, ToolChain, Args, StaticOpenMP);
 
 if (D.CCCIsCXX()) {
-  if (getToolChain().ShouldLinkCXXStdlib(Args))
-

[clang-tools-extra] [libc] [libcxx] [compiler-rt] [flang] [clang] [llvm] [libcxx] Unifying __is_trivial_equality_predicate and __is_trivial_plus_operation into __desugars_to (PR #68642)

2023-11-05 Thread Anton Rydahl via cfe-commits


@@ -18,8 +18,11 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template 
-struct __is_trivial_plus_operation : false_type {};
+template 

AntonRydahl wrote:

Hi @ldionne!

I am unsure about what I am supposed to do with the following:
```C++
template  struct __desugars_to<__equal_tag, __equal, _Tp, 
_Up> : true_type {};
```
Do we want to match the function from `include/__algorithm/equal.h`?

https://github.com/llvm/llvm-project/pull/68642
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] [libcxx] [compiler-rt] [flang] [mlir] [clang] [llvm] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Fabian Mora via cfe-commits


@@ -15,6 +15,7 @@
 
 #include "Utils.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"

fabianmcg wrote:

Back when the compilation redesign was happening we decided to add the attach* 
passes in GPU to avoid polluting lower level dialects with GPU includes. 
However, I do agree that include shouldn't be there, as far as I could tell, 
that include is only needed by one pass option 
`mlir::spirv::TargetEnvAttr::kUnknownDeviceID`, so it should be possible to 
remove it. I'll fix it.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [llvm] [libc] [flang] [mlir] [compiler-rt] [libcxx] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Jacques Pienaar via cfe-commits


@@ -15,6 +15,7 @@
 
 #include "Utils.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"

jpienaar wrote:

This feels off: you have GPU dialect transforms depending on SPIRV 
attributes/dialect (esp in header). Why is this pass in GPU dialect rather than 
SPIRV one?

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver][LTO] Fix empty stats filename when in LTO mode (PR #71197)

2023-11-05 Thread Min-Yih Hsu via cfe-commits

https://github.com/mshockwave closed 
https://github.com/llvm/llvm-project/pull/71197
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 85451f4 - [Clang][Driver][LTO] Fix empty stats filename when in LTO mode (#71197)

2023-11-05 Thread via cfe-commits

Author: Min-Yih Hsu
Date: 2023-11-05T11:31:26-08:00
New Revision: 85451f486d8144f8aacd94a47802c77da5a04d27

URL: 
https://github.com/llvm/llvm-project/commit/85451f486d8144f8aacd94a47802c77da5a04d27
DIFF: 
https://github.com/llvm/llvm-project/commit/85451f486d8144f8aacd94a47802c77da5a04d27.diff

LOG: [Clang][Driver][LTO] Fix empty stats filename when in LTO mode (#71197)

Previously, if a linker argument (i.e. -Wl) is presented before any input
filenames, Gnu driver would use the InputInfo object of that argument to 
generate stats filename for LTO backend, causing an empty filename. This patch 
fixes such issue.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/save-stats.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 5237951f84cce03..3276590729e47ea 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -535,7 +535,15 @@ void tools::gnutools::Linker::ConstructJob(Compilation , 
const JobAction ,
 
   if (D.isUsingLTO()) {
 assert(!Inputs.empty() && "Must have at least one input.");
-addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
+// Find the first filename InputInfo object.
+auto Input = llvm::find_if(
+Inputs, [](const InputInfo ) -> bool { return II.isFilename(); });
+if (Input == Inputs.end())
+  // For a very rare case, all of the inputs to the linker are
+  // InputArg. If that happens, just use the first InputInfo.
+  Input = Inputs.begin();
+
+addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
   D.getLTOMode() == LTOK_Thin);
   }
 

diff  --git a/clang/test/Driver/save-stats.c b/clang/test/Driver/save-stats.c
index ca8f2a457d4488c..2208c229b91e56c 100644
--- a/clang/test/Driver/save-stats.c
+++ b/clang/test/Driver/save-stats.c
@@ -20,6 +20,8 @@
 // CHECK-INVALID: invalid value 'bla' in '-save-stats=bla'
 
 // RUN: %clang -target x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// Previously `-plugin-opt=stats-file` would use empty filename if a linker 
flag (i.e. -Wl) is presented before any input filename.
+// RUN: %clang --target=x86_64-linux-unknown -save-stats -flto -o 
obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s 
-check-prefix=CHECK-LTO
 // CHECK-LTO: "-stats-file=save-stats.stats"
 // CHECK-LTO: "-o" "obj/dir{{/|}}save-stats.exe"
 // CHECK-LTO: "-plugin-opt=stats-file=save-stats.stats"



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >