[PATCH] D159092: [APINotes] Initial support for C++ namespaces

2023-08-30 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG993955662554: [APINotes] Initial support for C++ namespaces 
(authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159092

Files:
  clang/include/clang/APINotes/Types.h
  clang/lib/APINotes/APINotesFormat.h
  clang/lib/APINotes/APINotesWriter.cpp
  clang/lib/APINotes/APINotesYAMLCompiler.cpp

Index: clang/lib/APINotes/APINotesYAMLCompiler.cpp
===
--- clang/lib/APINotes/APINotesYAMLCompiler.cpp
+++ clang/lib/APINotes/APINotesYAMLCompiler.cpp
@@ -495,6 +495,9 @@
 } // namespace llvm
 
 namespace {
+struct Namespace;
+typedef std::vector NamespacesSeq;
+
 struct TopLevelItems {
   ClassesSeq Classes;
   ClassesSeq Protocols;
@@ -503,6 +506,7 @@
   EnumConstantsSeq EnumConstants;
   TagsSeq Tags;
   TypedefsSeq Typedefs;
+  NamespacesSeq Namespaces;
 };
 } // namespace
 
@@ -516,10 +520,39 @@
   IO.mapOptional("Enumerators", TLI.EnumConstants);
   IO.mapOptional("Tags", TLI.Tags);
   IO.mapOptional("Typedefs", TLI.Typedefs);
+  IO.mapOptional("Namespaces", TLI.Namespaces);
 }
 } // namespace yaml
 } // namespace llvm
 
+namespace {
+struct Namespace {
+  StringRef Name;
+  AvailabilityItem Availability;
+  StringRef SwiftName;
+  std::optional SwiftPrivate;
+  TopLevelItems Items;
+};
+} // namespace
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(Namespace)
+
+namespace llvm {
+namespace yaml {
+template <> struct MappingTraits {
+  static void mapping(IO , Namespace ) {
+IO.mapRequired("Name", T.Name);
+IO.mapOptional("Availability", T.Availability.Mode,
+   APIAvailability::Available);
+IO.mapOptional("AvailabilityMsg", T.Availability.Msg, StringRef(""));
+IO.mapOptional("SwiftPrivate", T.SwiftPrivate);
+IO.mapOptional("SwiftName", T.SwiftName, StringRef(""));
+mapTopLevelItems(IO, T.Items);
+  }
+};
+} // namespace yaml
+} // namespace llvm
+
 namespace {
 struct Versioned {
   VersionTuple Version;
Index: clang/lib/APINotes/APINotesWriter.cpp
===
--- clang/lib/APINotes/APINotesWriter.cpp
+++ clang/lib/APINotes/APINotesWriter.cpp
@@ -33,15 +33,21 @@
   /// Mapping from strings to identifier IDs.
   llvm::StringMap IdentifierIDs;
 
-  /// Information about Objective-C contexts (classes or protocols).
+  /// Information about contexts (Objective-C classes or protocols or C++
+  /// namespaces).
   ///
-  /// Indexed by the identifier ID and a bit indication whether we're looking
-  /// for a class (0) or protocol (1) and provides both the context ID and
-  /// information describing the context within that module.
-  llvm::DenseMap,
+  /// Indexed by the parent context ID, context kind and the identifier ID of
+  /// this context and provides both the context ID and information describing
+  /// the context within that module.
+  llvm::DenseMap>>
   ObjCContexts;
 
+  /// Information about parent contexts for each context.
+  ///
+  /// Indexed by context ID, provides the parent context ID.
+  llvm::DenseMap ParentContexts;
+
   /// Information about Objective-C properties.
   ///
   /// Indexed by the context ID, property name, and whether this is an
@@ -64,16 +70,18 @@
 
   /// Information about global variables.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
+  /// Indexed by the context ID, contextKind, identifier ID.
+  llvm::DenseMap<
+  ContextTableKey,
+  llvm::SmallVector, 1>>
   GlobalVariables;
 
   /// Information about global functions.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
+  /// Indexed by the context ID, contextKind, identifier ID.
+  llvm::DenseMap<
+  ContextTableKey,
+  llvm::SmallVector, 1>>
   GlobalFunctions;
 
   /// Information about enumerators.
@@ -85,15 +93,15 @@
 
   /// Information about tags.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
   Tags;
 
   /// Information about typedefs.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
   Typedefs;
 
@@ -292,7 +300,7 @@
 /// Used to serialize the on-disk Objective-C context table.
 class ObjCContextIDTableInfo {
 public:
-  using key_type = std::pair; // identifier ID, is-protocol
+  using key_type = ContextTableKey;
   using key_type_ref = key_type;
   using data_type = unsigned;
   using data_type_ref = const data_type &;
@@ -300,12 +308,12 @@
   using offset_type = unsigned;
 
   hash_value_type ComputeHash(key_type_ref Key) {
-return static_cast(llvm::hash_value(Key));
+return static_cast(Key.hashValue());
   }
 
   std::pair EmitKeyDataLength(raw_ostream , key_type_ref,
   data_type_ref) {
-uint32_t KeyLength = sizeof(uint32_t) + 1;
+uint32_t 

[PATCH] D159092: [APINotes] Initial support for C++ namespaces

2023-08-29 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
egorzhdan added a reviewer: compnerd.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This upstreams a part of the C++ namespaces support in Clang API Notes.

The complete patch was recently merged downstream in the Apple fork: 
https://github.com/apple/llvm-project/pull/7230.

This patch only adds the parts of the namespace support that can be cleanly 
applied on top of the API Notes infrastructure that was upstreamed previously.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159092

Files:
  clang/include/clang/APINotes/Types.h
  clang/lib/APINotes/APINotesFormat.h
  clang/lib/APINotes/APINotesWriter.cpp
  clang/lib/APINotes/APINotesYAMLCompiler.cpp

Index: clang/lib/APINotes/APINotesYAMLCompiler.cpp
===
--- clang/lib/APINotes/APINotesYAMLCompiler.cpp
+++ clang/lib/APINotes/APINotesYAMLCompiler.cpp
@@ -495,6 +495,9 @@
 } // namespace llvm
 
 namespace {
+struct Namespace;
+typedef std::vector NamespacesSeq;
+
 struct TopLevelItems {
   ClassesSeq Classes;
   ClassesSeq Protocols;
@@ -503,6 +506,7 @@
   EnumConstantsSeq EnumConstants;
   TagsSeq Tags;
   TypedefsSeq Typedefs;
+  NamespacesSeq Namespaces;
 };
 } // namespace
 
@@ -516,10 +520,39 @@
   IO.mapOptional("Enumerators", TLI.EnumConstants);
   IO.mapOptional("Tags", TLI.Tags);
   IO.mapOptional("Typedefs", TLI.Typedefs);
+  IO.mapOptional("Namespaces", TLI.Namespaces);
 }
 } // namespace yaml
 } // namespace llvm
 
+namespace {
+struct Namespace {
+  StringRef Name;
+  AvailabilityItem Availability;
+  StringRef SwiftName;
+  std::optional SwiftPrivate;
+  TopLevelItems Items;
+};
+} // namespace
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(Namespace)
+
+namespace llvm {
+namespace yaml {
+template <> struct MappingTraits {
+  static void mapping(IO , Namespace ) {
+IO.mapRequired("Name", T.Name);
+IO.mapOptional("Availability", T.Availability.Mode,
+   APIAvailability::Available);
+IO.mapOptional("AvailabilityMsg", T.Availability.Msg, StringRef(""));
+IO.mapOptional("SwiftPrivate", T.SwiftPrivate);
+IO.mapOptional("SwiftName", T.SwiftName, StringRef(""));
+mapTopLevelItems(IO, T.Items);
+  }
+};
+} // namespace yaml
+} // namespace llvm
+
 namespace {
 struct Versioned {
   VersionTuple Version;
Index: clang/lib/APINotes/APINotesWriter.cpp
===
--- clang/lib/APINotes/APINotesWriter.cpp
+++ clang/lib/APINotes/APINotesWriter.cpp
@@ -33,15 +33,21 @@
   /// Mapping from strings to identifier IDs.
   llvm::StringMap IdentifierIDs;
 
-  /// Information about Objective-C contexts (classes or protocols).
+  /// Information about contexts (Objective-C classes or protocols or C++
+  /// namespaces).
   ///
-  /// Indexed by the identifier ID and a bit indication whether we're looking
-  /// for a class (0) or protocol (1) and provides both the context ID and
-  /// information describing the context within that module.
-  llvm::DenseMap,
+  /// Indexed by the parent context ID, context kind and the identifier ID of
+  /// this context and provides both the context ID and information describing
+  /// the context within that module.
+  llvm::DenseMap>>
   ObjCContexts;
 
+  /// Information about parent contexts for each context.
+  ///
+  /// Indexed by context ID, provides the parent context ID.
+  llvm::DenseMap ParentContexts;
+
   /// Information about Objective-C properties.
   ///
   /// Indexed by the context ID, property name, and whether this is an
@@ -64,16 +70,18 @@
 
   /// Information about global variables.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
+  /// Indexed by the context ID, contextKind, identifier ID.
+  llvm::DenseMap<
+  ContextTableKey,
+  llvm::SmallVector, 1>>
   GlobalVariables;
 
   /// Information about global functions.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
+  /// Indexed by the context ID, contextKind, identifier ID.
+  llvm::DenseMap<
+  ContextTableKey,
+  llvm::SmallVector, 1>>
   GlobalFunctions;
 
   /// Information about enumerators.
@@ -85,15 +93,15 @@
 
   /// Information about tags.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
   Tags;
 
   /// Information about typedefs.
   ///
-  /// Indexed by the identifier ID.
-  llvm::DenseMap, 1>>
   Typedefs;
 
@@ -292,7 +300,7 @@
 /// Used to serialize the on-disk Objective-C context table.
 class ObjCContextIDTableInfo {
 public:
-  using key_type = std::pair; // identifier ID, is-protocol
+  using key_type = ContextTableKey;
   using key_type_ref = key_type;
   using data_type = unsigned;
   using data_type_ref = const data_type &;
@@ -300,12 +308,12 @@
   using offset_type = unsigned;
 
   hash_value_type ComputeHash(key_type_ref Key) {
-return 

[PATCH] D146434: [clang-format] Fix support for ObjC blocks with pointer return types

2023-07-17 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan closed this revision.
egorzhdan added a comment.

Merged as 63d6659a 
.


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

https://reviews.llvm.org/D146434

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


[PATCH] D92797: APINotes: add initial stub of APINotesWriter

2023-06-20 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

@compnerd @martong would you be OK with merging this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92797

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


[PATCH] D149850: [Clang][Modules] Support `requires cplusplus20` in a modulemap

2023-06-06 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan closed this revision.
egorzhdan added a comment.

Looks like https://reviews.llvm.org/D150773 got there first.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149850

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


[PATCH] D92797: APINotes: add initial stub of APINotesWriter

2023-06-05 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

Apologies for pinging an old review. Would it be possible to land this to 
facilitate future work to upstream API notes support?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92797

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


[PATCH] D149850: [Clang][Modules] Support `requires cplusplus20` in a modulemap

2023-05-15 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

@Bigcheese, @ChuanqiXu, could you please take a look at this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149850

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


[PATCH] D149850: [Clang][Modules] Support `requires cplusplus20` in a modulemap

2023-05-04 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change adds the support for `requires cplusplus20` directive for a module 
declared in a Clang modulemap, similarly to existing directives `requires 
cplusplus17`, `requires cplusplus14`, etc.

rdar://108891417


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149850

Files:
  clang/docs/Modules.rst
  clang/lib/Basic/Module.cpp
  clang/test/Modules/Inputs/DependsOnModule.framework/module.map
  clang/test/Modules/requires.m


Index: clang/test/Modules/requires.m
===
--- clang/test/Modules/requires.m
+++ clang/test/Modules/requires.m
@@ -22,11 +22,13 @@
 @import DependsOnModule.CXX14; // expected-note {{module imported here}}
 // expected-error@DependsOnModule.framework/module.map:46 {{module 
'DependsOnModule.CXX17' requires feature 'cplusplus17'}}
 @import DependsOnModule.CXX17; // expected-note {{module imported here}}
+// expected-error@DependsOnModule.framework/module.map:49 {{module 
'DependsOnModule.CXX20' requires feature 'cplusplus20'}}
+@import DependsOnModule.CXX20; // expected-note {{module imported here}}
 #else
-// expected-error@DependsOnModule.framework/module.map:49 {{module 
'DependsOnModule.C99' requires feature 'c99'}}
+// expected-error@DependsOnModule.framework/module.map:52 {{module 
'DependsOnModule.C99' requires feature 'c99'}}
 @import DependsOnModule.C99; // expected-note {{module imported here}}
-// expected-error@DependsOnModule.framework/module.map:52 {{module 
'DependsOnModule.C11' requires feature 'c11'}}
+// expected-error@DependsOnModule.framework/module.map:55 {{module 
'DependsOnModule.C11' requires feature 'c11'}}
 @import DependsOnModule.C11; // expected-note {{module imported here}}
-// expected-error@DependsOnModule.framework/module.map:55 {{module 
'DependsOnModule.C17' requires feature 'c17'}}
+// expected-error@DependsOnModule.framework/module.map:58 {{module 
'DependsOnModule.C17' requires feature 'c17'}}
 @import DependsOnModule.C17; // expected-note {{module imported here}}
 #endif
Index: clang/test/Modules/Inputs/DependsOnModule.framework/module.map
===
--- clang/test/Modules/Inputs/DependsOnModule.framework/module.map
+++ clang/test/Modules/Inputs/DependsOnModule.framework/module.map
@@ -46,6 +46,9 @@
   explicit module CXX17 {
 requires cplusplus17
   }
+  explicit module CXX20 {
+requires cplusplus20
+  }
   explicit module C99 {
 requires c99
   }
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -107,6 +107,7 @@
 .Case("cplusplus11", LangOpts.CPlusPlus11)
 .Case("cplusplus14", LangOpts.CPlusPlus14)
 .Case("cplusplus17", LangOpts.CPlusPlus17)
+.Case("cplusplus20", LangOpts.CPlusPlus20)
 .Case("c99", LangOpts.C99)
 .Case("c11", LangOpts.C11)
 .Case("c17", LangOpts.C17)
Index: clang/docs/Modules.rst
===
--- clang/docs/Modules.rst
+++ clang/docs/Modules.rst
@@ -573,6 +573,9 @@
 cplusplus17
   C++17 support is available.
 
+cplusplus20
+  C++20 support is available.
+
 c99
   C99 support is available.
 


Index: clang/test/Modules/requires.m
===
--- clang/test/Modules/requires.m
+++ clang/test/Modules/requires.m
@@ -22,11 +22,13 @@
 @import DependsOnModule.CXX14; // expected-note {{module imported here}}
 // expected-error@DependsOnModule.framework/module.map:46 {{module 'DependsOnModule.CXX17' requires feature 'cplusplus17'}}
 @import DependsOnModule.CXX17; // expected-note {{module imported here}}
+// expected-error@DependsOnModule.framework/module.map:49 {{module 'DependsOnModule.CXX20' requires feature 'cplusplus20'}}
+@import DependsOnModule.CXX20; // expected-note {{module imported here}}
 #else
-// expected-error@DependsOnModule.framework/module.map:49 {{module 'DependsOnModule.C99' requires feature 'c99'}}
+// expected-error@DependsOnModule.framework/module.map:52 {{module 'DependsOnModule.C99' requires feature 'c99'}}
 @import DependsOnModule.C99; // expected-note {{module imported here}}
-// expected-error@DependsOnModule.framework/module.map:52 {{module 'DependsOnModule.C11' requires feature 'c11'}}
+// expected-error@DependsOnModule.framework/module.map:55 {{module 'DependsOnModule.C11' requires feature 'c11'}}
 @import DependsOnModule.C11; // expected-note {{module imported here}}
-// expected-error@DependsOnModule.framework/module.map:55 {{module 'DependsOnModule.C17' requires feature 'c17'}}
+// 

[PATCH] D138630: [modules] Fix marking `ObjCMethodDecl::isOverriding` when there a no overrides.

2022-11-24 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan accepted this revision.
egorzhdan added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138630

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


[PATCH] D138434: [Clang][Sema] Added space after ',' in a warning

2022-11-22 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan closed this revision.
egorzhdan added a comment.

Merged: https://reviews.llvm.org/rGcdfb65e5e7182a02005b3611aa28288890b9e296


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138434

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


[PATCH] D138434: [Clang][Sema] Added space after ',' in a warning

2022-11-21 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan accepted this revision.
egorzhdan added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138434

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


[PATCH] D136844: [libclang] Expose completion result kind in `CXCompletionResult`

2022-11-10 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG97105e5bf70f: [libclang] Expose completion result kind in 
`CXCompletionResult` (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136844

Files:
  clang/include/clang-c/Index.h
  clang/test/Index/arc-complete.m
  clang/test/Index/code-completion.cpp
  clang/test/Index/complete-at-directives.m
  clang/test/Index/complete-at-exprstmt.m
  clang/test/Index/complete-declarators.cpp
  clang/test/Index/complete-declarators.m
  clang/test/Index/complete-exprs.c
  clang/test/Index/complete-exprs.cpp
  clang/test/Index/complete-exprs.m
  clang/test/Index/complete-lambdas.cpp
  clang/test/Index/complete-lambdas.mm
  clang/test/Index/complete-memfunc-cvquals.cpp
  clang/test/Index/complete-method-decls.m
  clang/test/Index/complete-modules.m
  clang/test/Index/complete-preprocessor.m
  clang/test/Index/complete-recovery.m
  clang/test/Index/complete-stmt.c
  clang/test/Index/complete-super.cpp
  clang/test/Index/complete-synthesized.m
  clang/test/Index/complete-type-factors.m
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  clang/tools/libclang/libclang.map

Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -4,6 +4,11 @@
 # On platforms where versions scripts are not used, this file will be used to
 # generate a list of exports for libclang.so
 
+LLVM_15 {
+  global:
+clang_getCompletionResultKindSpelling;
+};
+
 LLVM_13 {
   global:
 clang_BlockCommandComment_getArgText;
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -586,6 +586,20 @@
   includeBriefComments());
 
 CXCompletionResult R;
+switch (Results[I].Kind) {
+case CodeCompletionResult::RK_Declaration:
+  R.ResultKind = CXCompletionResult_Declaration;
+  break;
+case CodeCompletionResult::RK_Keyword:
+  R.ResultKind = CXCompletionResult_Keyword;
+  break;
+case CodeCompletionResult::RK_Macro:
+  R.ResultKind = CXCompletionResult_Macro;
+  break;
+case CodeCompletionResult::RK_Pattern:
+  R.ResultKind = CXCompletionResult_Pattern;
+  break;
+}
 R.CursorKind = Results[I].CursorKind;
 R.CompletionString = StoredCompletion;
 StoredResults.push_back(R);
@@ -666,6 +680,7 @@
 includeBriefComments(), Braced);
 
 CXCompletionResult R;
+R.ResultKind = CXCompletionResult_Declaration;
 R.CursorKind = CXCursor_OverloadCandidate;
 R.CompletionString = StoredCompletion;
 StoredResults.push_back(R);
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5403,6 +5403,22 @@
   return clang_getCursorSpelling(C);
 }
 
+CXString
+clang_getCompletionResultKindSpelling(enum CXCompletionResultKind Kind) {
+  switch (Kind) {
+  case CXCompletionResult_Declaration:
+return cxstring::createRef("Declaration");
+  case CXCompletionResult_Keyword:
+return cxstring::createRef("Keyword");
+  case CXCompletionResult_Macro:
+return cxstring::createRef("Macro");
+  case CXCompletionResult_Pattern:
+return cxstring::createRef("Pattern");
+  }
+
+  llvm_unreachable("Unhandled CXCompletionResultKind");
+}
+
 CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
   switch (Kind) {
   case CXCursor_FunctionDecl:
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -2512,7 +2512,10 @@
 unsigned index,
 FILE *file) {
   CXCompletionResult *completion_result = completion_results->Results + index;
-  CXString ks = clang_getCursorKindSpelling(completion_result->CursorKind);
+  CXString ks =
+  completion_result->CursorKind == CXCursor_NotImplemented
+  ? clang_getCompletionResultKindSpelling(completion_result->ResultKind)
+  : clang_getCursorKindSpelling(completion_result->CursorKind);
   unsigned annotationCount;
   enum CXCursorKind ParentKind;
   CXString ParentName;
Index: clang/test/Index/complete-type-factors.m
===
--- clang/test/Index/complete-type-factors.m
+++ 

[PATCH] D136844: [libclang] Expose completion result kind in `CXCompletionResult`

2022-10-31 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 472171.
egorzhdan added a comment.

Preserve `CodeCompletionResult::ResultKind` and do the conversion to 
`CXCompletionResultKind` in `CIndexCodeCompletion.cpp`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136844

Files:
  clang/include/clang-c/Index.h
  clang/test/Index/arc-complete.m
  clang/test/Index/code-completion.cpp
  clang/test/Index/complete-at-directives.m
  clang/test/Index/complete-at-exprstmt.m
  clang/test/Index/complete-declarators.cpp
  clang/test/Index/complete-declarators.m
  clang/test/Index/complete-exprs.c
  clang/test/Index/complete-exprs.cpp
  clang/test/Index/complete-exprs.m
  clang/test/Index/complete-lambdas.cpp
  clang/test/Index/complete-lambdas.mm
  clang/test/Index/complete-memfunc-cvquals.cpp
  clang/test/Index/complete-method-decls.m
  clang/test/Index/complete-modules.m
  clang/test/Index/complete-preprocessor.m
  clang/test/Index/complete-recovery.m
  clang/test/Index/complete-stmt.c
  clang/test/Index/complete-super.cpp
  clang/test/Index/complete-synthesized.m
  clang/test/Index/complete-type-factors.m
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  clang/tools/libclang/libclang.map

Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -4,6 +4,11 @@
 # On platforms where versions scripts are not used, this file will be used to
 # generate a list of exports for libclang.so
 
+LLVM_15 {
+  global:
+clang_getCompletionResultKindSpelling;
+};
+
 LLVM_13 {
   global:
 clang_BlockCommandComment_getArgText;
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -586,6 +586,20 @@
   includeBriefComments());
 
 CXCompletionResult R;
+switch (Results[I].Kind) {
+case CodeCompletionResult::RK_Declaration:
+  R.ResultKind = CXCompletionResult_Declaration;
+  break;
+case CodeCompletionResult::RK_Keyword:
+  R.ResultKind = CXCompletionResult_Keyword;
+  break;
+case CodeCompletionResult::RK_Macro:
+  R.ResultKind = CXCompletionResult_Macro;
+  break;
+case CodeCompletionResult::RK_Pattern:
+  R.ResultKind = CXCompletionResult_Pattern;
+  break;
+}
 R.CursorKind = Results[I].CursorKind;
 R.CompletionString = StoredCompletion;
 StoredResults.push_back(R);
@@ -666,6 +680,7 @@
 includeBriefComments(), Braced);
 
 CXCompletionResult R;
+R.ResultKind = CXCompletionResult_Declaration;
 R.CursorKind = CXCursor_OverloadCandidate;
 R.CompletionString = StoredCompletion;
 StoredResults.push_back(R);
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5390,6 +5390,22 @@
   return clang_getCursorSpelling(C);
 }
 
+CXString
+clang_getCompletionResultKindSpelling(enum CXCompletionResultKind Kind) {
+  switch (Kind) {
+  case CXCompletionResult_Declaration:
+return cxstring::createRef("Declaration");
+  case CXCompletionResult_Keyword:
+return cxstring::createRef("Keyword");
+  case CXCompletionResult_Macro:
+return cxstring::createRef("Macro");
+  case CXCompletionResult_Pattern:
+return cxstring::createRef("Pattern");
+  }
+
+  llvm_unreachable("Unhandled CXCompletionResultKind");
+}
+
 CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
   switch (Kind) {
   case CXCursor_FunctionDecl:
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -2505,7 +2505,10 @@
 unsigned index,
 FILE *file) {
   CXCompletionResult *completion_result = completion_results->Results + index;
-  CXString ks = clang_getCursorKindSpelling(completion_result->CursorKind);
+  CXString ks =
+  completion_result->CursorKind == CXCursor_NotImplemented
+  ? clang_getCompletionResultKindSpelling(completion_result->ResultKind)
+  : clang_getCursorKindSpelling(completion_result->CursorKind);
   unsigned annotationCount;
   enum CXCursorKind ParentKind;
   CXString ParentName;
Index: clang/test/Index/complete-type-factors.m
===
--- clang/test/Index/complete-type-factors.m
+++ 

[PATCH] D136844: [libclang] Expose completion result kind in `CXCompletionResult`

2022-10-31 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added inline comments.



Comment at: clang/include/clang/Sema/CodeCompleteConsumer.h:755
-  /// Describes the kind of result generated.
-  enum ResultKind {
-/// Refers to a declaration.

kadircet wrote:
> egorzhdan wrote:
> > kadircet wrote:
> > > i don't follow the reason for replacing this struct with 
> > > `CXCompletionResultKind` and renaming occurrences in half of the 
> > > codebase. can we keep this around, introduce the new enum type into 
> > > `Index.h` and have `clang/tools/libclang/CIndexCodeCompletion.cpp` do the 
> > > conversion from Sema type to Index type instead?
> > > 
> > > Unless I am missing some other requirement for doing so. i feel like the 
> > > conceptual dependency from Sema to Index is one we should get rid of, 
> > > rather than make tighter.
> > This was mostly done to be consistent with the way `CXCursorKind` and 
> > `CXAvailabilityKind` are declared in `Index.h` and used as fields of 
> > `CodeCompletionResult`. I think updating the enum name in a few source 
> > files shouldn't be a major problem, but I can avoid it if you feel strongly 
> > against this approach.
> I completely agree with the consistency argument, but IMO the conceptual 
> dependency from clang-sema to clang-cindex is just wrong.
> 
> cindex is mostly implemented by `libclang`, which is part of clang-tools. all 
> of this works today because clang-sema is only using declarations visible in 
> headers and doesn't properly depend on `libclang` in the build files.
> 
> Hence I believe rather than preserving consistency here, we should be moving 
> towards breaking that dependency over time. Therefore I was opposing the idea 
> of introducing another type usage that'll make this dependency more strong.
>  all of this works today because clang-sema is only using declarations 
> visible in headers and doesn't properly depend on libclang in the build files.

Oh I see, this is a great point, I didn't realize that. I'll update the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136844

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


[PATCH] D136844: [libclang] Expose completion result kind in `CXCompletionResult`

2022-10-30 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added inline comments.
Herald added subscribers: Michael137, JDevlieghere.



Comment at: clang/include/clang/Sema/CodeCompleteConsumer.h:755
-  /// Describes the kind of result generated.
-  enum ResultKind {
-/// Refers to a declaration.

kadircet wrote:
> i don't follow the reason for replacing this struct with 
> `CXCompletionResultKind` and renaming occurrences in half of the codebase. 
> can we keep this around, introduce the new enum type into `Index.h` and have 
> `clang/tools/libclang/CIndexCodeCompletion.cpp` do the conversion from Sema 
> type to Index type instead?
> 
> Unless I am missing some other requirement for doing so. i feel like the 
> conceptual dependency from Sema to Index is one we should get rid of, rather 
> than make tighter.
This was mostly done to be consistent with the way `CXCursorKind` and 
`CXAvailabilityKind` are declared in `Index.h` and used as fields of 
`CodeCompletionResult`. I think updating the enum name in a few source files 
shouldn't be a major problem, but I can avoid it if you feel strongly against 
this approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136844

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


[PATCH] D136844: [libclang] Expose completion result kind in `CXCompletionResult`

2022-10-30 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 471838.
egorzhdan added a comment.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Fix clangd compilation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136844

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/Quality.cpp
  clang/include/clang-c/Index.h
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/Index/arc-complete.m
  clang/test/Index/code-completion.cpp
  clang/test/Index/complete-at-directives.m
  clang/test/Index/complete-at-exprstmt.m
  clang/test/Index/complete-declarators.cpp
  clang/test/Index/complete-declarators.m
  clang/test/Index/complete-exprs.c
  clang/test/Index/complete-exprs.cpp
  clang/test/Index/complete-exprs.m
  clang/test/Index/complete-lambdas.cpp
  clang/test/Index/complete-lambdas.mm
  clang/test/Index/complete-memfunc-cvquals.cpp
  clang/test/Index/complete-method-decls.m
  clang/test/Index/complete-modules.m
  clang/test/Index/complete-preprocessor.m
  clang/test/Index/complete-recovery.m
  clang/test/Index/complete-stmt.c
  clang/test/Index/complete-super.cpp
  clang/test/Index/complete-synthesized.m
  clang/test/Index/complete-type-factors.m
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  clang/tools/libclang/libclang.map
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -859,15 +859,15 @@
CodeCompletionResult Result) override {
 // This code is mostly copied from CodeCompleteConsumer.
 switch (Result.Kind) {
-case CodeCompletionResult::RK_Declaration:
+case CXCompletionResult_Declaration:
   return !(
   Result.Declaration->getIdentifier() &&
   Result.Declaration->getIdentifier()->getName().startswith(Filter));
-case CodeCompletionResult::RK_Keyword:
+case CXCompletionResult_Keyword:
   return !StringRef(Result.Keyword).startswith(Filter);
-case CodeCompletionResult::RK_Macro:
+case CXCompletionResult_Macro:
   return !Result.Macro->getName().startswith(Filter);
-case CodeCompletionResult::RK_Pattern:
+case CXCompletionResult_Pattern:
   return !StringRef(Result.Pattern->getAsString()).startswith(Filter);
 }
 // If we trigger this assert or the above switch yields a warning, then
@@ -894,7 +894,7 @@
 std::string Description;
 // Handle the different completion kinds that come from the Sema.
 switch (R.Kind) {
-case CodeCompletionResult::RK_Declaration: {
+case CXCompletionResult_Declaration: {
   const NamedDecl *D = R.Declaration;
   ToInsert = R.Declaration->getNameAsString();
   // If we have a function decl that has no arguments we want to
@@ -920,13 +920,13 @@
   }
   break;
 }
-case CodeCompletionResult::RK_Keyword:
+case CXCompletionResult_Keyword:
   ToInsert = R.Keyword;
   break;
-case CodeCompletionResult::RK_Macro:
+case CXCompletionResult_Macro:
   ToInsert = R.Macro->getName().str();
   break;
-case CodeCompletionResult::RK_Pattern:
+case CXCompletionResult_Pattern:
   ToInsert = R.Pattern->getTypedText();
   break;
 }
Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -4,6 +4,10 @@
 # On platforms where versions scripts are not used, this file will be used to
 # generate a list of exports for libclang.so
 
+LLVM_15 {
+  global:
+clang_getCompletionResultKindSpelling;
+}
 LLVM_13 {
   global:
 clang_BlockCommandComment_getArgText;
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -586,6 +586,7 @@
   includeBriefComments());
 
 CXCompletionResult R;
+R.ResultKind = Results[I].Kind;
 R.CursorKind = Results[I].CursorKind;
 R.CompletionString = StoredCompletion;
 StoredResults.push_back(R);
@@ -666,6 +667,7 @@
 includeBriefComments(), Braced);
 
 CXCompletionResult R;
+R.ResultKind = CXCompletionResult_Declaration;
 R.CursorKind = 

[PATCH] D136844: [libclang] Expose completion result kind in `CXCompletionResult`

2022-10-27 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
egorzhdan added reviewers: arphaman, bnbarham.
Herald added a subscriber: kadircet.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

This allows clients of libclang to check whether a completion result is a 
keyword. Previously, keywords had `CursorKind == CXCursor_NotImplemented` and 
it wasn't trivial to distinguish a keyword from a pattern.

This change moves `CodeCompletionResult::ResultKind` to `clang-c` under a new 
name `CXCompletionResultKind`. It also tweaks `c-index-test` to print the 
result kind instead of `NotImplemented`, and adjusts the tests for the new 
output.

rdar://91852088


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136844

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang/include/clang-c/Index.h
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/Index/arc-complete.m
  clang/test/Index/code-completion.cpp
  clang/test/Index/complete-at-directives.m
  clang/test/Index/complete-at-exprstmt.m
  clang/test/Index/complete-declarators.cpp
  clang/test/Index/complete-declarators.m
  clang/test/Index/complete-exprs.c
  clang/test/Index/complete-exprs.cpp
  clang/test/Index/complete-exprs.m
  clang/test/Index/complete-lambdas.cpp
  clang/test/Index/complete-lambdas.mm
  clang/test/Index/complete-memfunc-cvquals.cpp
  clang/test/Index/complete-method-decls.m
  clang/test/Index/complete-modules.m
  clang/test/Index/complete-preprocessor.m
  clang/test/Index/complete-recovery.m
  clang/test/Index/complete-stmt.c
  clang/test/Index/complete-super.cpp
  clang/test/Index/complete-synthesized.m
  clang/test/Index/complete-type-factors.m
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  clang/tools/libclang/libclang.map

Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -4,6 +4,10 @@
 # On platforms where versions scripts are not used, this file will be used to
 # generate a list of exports for libclang.so
 
+LLVM_15 {
+  global:
+clang_getCompletionResultKindSpelling;
+}
 LLVM_13 {
   global:
 clang_BlockCommandComment_getArgText;
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -586,6 +586,7 @@
   includeBriefComments());
 
 CXCompletionResult R;
+R.ResultKind = Results[I].Kind;
 R.CursorKind = Results[I].CursorKind;
 R.CompletionString = StoredCompletion;
 StoredResults.push_back(R);
@@ -666,6 +667,7 @@
 includeBriefComments(), Braced);
 
 CXCompletionResult R;
+R.ResultKind = CXCompletionResult_Declaration;
 R.CursorKind = CXCursor_OverloadCandidate;
 R.CompletionString = StoredCompletion;
 StoredResults.push_back(R);
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5390,6 +5390,22 @@
   return clang_getCursorSpelling(C);
 }
 
+CXString
+clang_getCompletionResultKindSpelling(enum CXCompletionResultKind Kind) {
+  switch (Kind) {
+  case CXCompletionResult_Declaration:
+return cxstring::createRef("Declaration");
+  case CXCompletionResult_Keyword:
+return cxstring::createRef("Keyword");
+  case CXCompletionResult_Macro:
+return cxstring::createRef("Macro");
+  case CXCompletionResult_Pattern:
+return cxstring::createRef("Pattern");
+  }
+
+  llvm_unreachable("Unhandled CXCompletionResultKind");
+}
+
 CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
   switch (Kind) {
   case CXCursor_FunctionDecl:
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -2505,7 +2505,10 @@
 unsigned index,
 FILE *file) {
   CXCompletionResult *completion_result = completion_results->Results + index;
-  CXString ks = clang_getCursorKindSpelling(completion_result->CursorKind);
+  CXString ks =
+  completion_result->CursorKind == CXCursor_NotImplemented
+  ? clang_getCompletionResultKindSpelling(completion_result->ResultKind)
+  : clang_getCursorKindSpelling(completion_result->CursorKind);
   

[PATCH] D133105: [Clang][Comments] Fix `Index/comment-lots-of-unknown-commands.c`

2022-09-02 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7c232b086720: [Clang][Comments] Fix 
`Index/comment-lots-of-unknown-commands.c` (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133105

Files:
  clang/test/Index/comment-lots-of-unknown-commands.c


Index: clang/test/Index/comment-lots-of-unknown-commands.c
===
--- clang/test/Index/comment-lots-of-unknown-commands.c
+++ clang/test/Index/comment-lots-of-unknown-commands.c
@@ -1,7 +1,5 @@
 // RUN: c-index-test -test-load-source-reparse 1 local %s | FileCheck %s
 
-// XFAIL: *
-
 // See PR 21254. We had too few bits to encode command IDs so if you created
 // enough of them the ID codes would wrap around. This test creates commands up
 // to an ID of 258. Ideally we should check for large numbers, but that would
@@ -37,7 +35,7 @@
 @ei
 @oun
 @ou
-@nl
+@nlnl
 @ien
 @fr
 @en
@@ -58,7 +56,7 @@
 @fro
 @ast
 @ae
-@nN
+@nNnN
 @pc
 @tae
 @ws
@@ -122,10 +120,10 @@
 @an
 @de
 @tel
-@nd
-@dic
+@ndnd
+@dict
 @Lo
-@il
+@ilil
 @tle
 @axt
 @ba
@@ -137,7 +135,7 @@
 @ru
 @m
 @tG
-@it
+@itit
 @rh
 @G
 @rpc
@@ -183,7 +181,7 @@
 // CHECK: (CXComment_InlineCommand CommandName=[ei] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[oun] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ou] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[nl] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[nlnl] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ien] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[fr] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[en] RenderNormal 
HasTrailingNewline)
@@ -204,7 +202,7 @@
 // CHECK: (CXComment_InlineCommand CommandName=[fro] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ast] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ae] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[nN] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[nNnN] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[pc] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[tae] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ws] RenderNormal 
HasTrailingNewline)
@@ -268,10 +266,10 @@
 // CHECK: (CXComment_InlineCommand CommandName=[an] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[de] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[tel] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[nd] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[dic] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[ndnd] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[dict] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[Lo] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[il] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[ilil] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[tle] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[axt] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ba] RenderNormal 
HasTrailingNewline)
@@ -283,7 +281,7 @@
 // CHECK: (CXComment_InlineCommand CommandName=[ru] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[m] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[tG] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[it] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[itit] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[rh] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[G] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[rpc] RenderNormal 
HasTrailingNewline)


Index: clang/test/Index/comment-lots-of-unknown-commands.c

[PATCH] D133105: [Clang][Comments] Fix `Index/comment-lots-of-unknown-commands.c`

2022-09-01 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
egorzhdan added a reviewer: aaronpuchert.
Herald added a subscriber: arphaman.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This re-enables a test after it was disabled in 
https://reviews.llvm.org/D133009.

Fixes #57484.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133105

Files:
  clang/test/Index/comment-lots-of-unknown-commands.c


Index: clang/test/Index/comment-lots-of-unknown-commands.c
===
--- clang/test/Index/comment-lots-of-unknown-commands.c
+++ clang/test/Index/comment-lots-of-unknown-commands.c
@@ -1,7 +1,5 @@
 // RUN: c-index-test -test-load-source-reparse 1 local %s | FileCheck %s
 
-// XFAIL: *
-
 // See PR 21254. We had too few bits to encode command IDs so if you created
 // enough of them the ID codes would wrap around. This test creates commands up
 // to an ID of 258. Ideally we should check for large numbers, but that would
@@ -37,7 +35,7 @@
 @ei
 @oun
 @ou
-@nl
+@nlnl
 @ien
 @fr
 @en
@@ -58,7 +56,7 @@
 @fro
 @ast
 @ae
-@nN
+@nNnN
 @pc
 @tae
 @ws
@@ -122,10 +120,10 @@
 @an
 @de
 @tel
-@nd
-@dic
+@ndnd
+@dict
 @Lo
-@il
+@ilil
 @tle
 @axt
 @ba
@@ -137,7 +135,7 @@
 @ru
 @m
 @tG
-@it
+@itit
 @rh
 @G
 @rpc
@@ -183,7 +181,7 @@
 // CHECK: (CXComment_InlineCommand CommandName=[ei] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[oun] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ou] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[nl] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[nlnl] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ien] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[fr] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[en] RenderNormal 
HasTrailingNewline)
@@ -204,7 +202,7 @@
 // CHECK: (CXComment_InlineCommand CommandName=[fro] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ast] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ae] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[nN] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[nNnN] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[pc] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[tae] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ws] RenderNormal 
HasTrailingNewline)
@@ -268,10 +266,10 @@
 // CHECK: (CXComment_InlineCommand CommandName=[an] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[de] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[tel] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[nd] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[dic] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[ndnd] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[dict] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[Lo] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[il] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[ilil] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[tle] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[axt] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[ba] RenderNormal 
HasTrailingNewline)
@@ -283,7 +281,7 @@
 // CHECK: (CXComment_InlineCommand CommandName=[ru] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[m] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[tG] RenderNormal 
HasTrailingNewline)
-// CHECK: (CXComment_InlineCommand CommandName=[it] RenderNormal 
HasTrailingNewline)
+// CHECK: (CXComment_InlineCommand CommandName=[itit] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[rh] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[G] RenderNormal 
HasTrailingNewline)
 // CHECK: (CXComment_InlineCommand CommandName=[rpc] RenderNormal 
HasTrailingNewline)


Index: 

[PATCH] D133009: [libclang] Fix conversion from `StringRef` to `CXString`

2022-09-01 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added inline comments.



Comment at: clang/test/Index/comment-lots-of-unknown-commands.c:3
 
+// XFAIL: *
+

aaronpuchert wrote:
> egorzhdan wrote:
> > gribozavr2 wrote:
> > > egorzhdan wrote:
> > > > This test was never properly passing. Because of the bug in string 
> > > > conversion, the printed comments contained the entire source file and 
> > > > not just the comments' text, which was enough to cause `// CHECK`-s in 
> > > > the test to succeed.
> > > > ```
> > > > // CHECK: (CXComment_InlineCommand CommandName=[tel] 
> > > > RenderNormal HasTrailingNewline)
> > > > // CHECK: (CXComment_InlineCommand CommandName=[n] RenderNormal 
> > > > HasTrailingNewline))
> > > > // CHECK:   (CXComment_VerbatimLine 
> > > > Text=[\n@Lo\n@il\n@tle\n@axt\n@ba\n@ust\n@ac\n@tpe\n@tpl\n@ctG\n@ru\n@m\n@tG\n@it\n@rh\n@G\n@rpc\n@el\n@er\n@w\n@eo\n@tx\n@oo\n@dD\n@dD\n*/\nvoid
> > > >  f();\n\n// CHECK:  CommentAST=[\n// CHECK:
> > > > (CXComment_FullComment\n// CHECK:   (CXComment_Paragraph\n// CHECK: 
> > > >  ...
> > > > ```
> > > Please update the test to pass then. Here's the diff:
> > > 
> > > ```
> > > diff --git a/clang/test/Index/comment-lots-of-unknown-commands.c 
> > > b/clang/test/Index/comment-lots-of-unknown-commands.c
> > > index 41a03d394488..e1adcc150b1e 100644
> > > --- a/clang/test/Index/comment-lots-of-unknown-commands.c
> > > +++ b/clang/test/Index/comment-lots-of-unknown-commands.c
> > > @@ -1,6 +1,5 @@
> > >  // RUN: c-index-test -test-load-source-reparse 1 local %s | FileCheck %s
> > > 
> > > -// XFAIL: *
> > > 
> > >  // See PR 21254. We had too few bits to encode command IDs so if you 
> > > created
> > >  // enough of them the ID codes would wrap around. This test creates 
> > > commands up
> > > @@ -183,7 +182,7 @@ void f();
> > >  // CHECK: (CXComment_InlineCommand CommandName=[ei] RenderNormal 
> > > HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[oun] 
> > > RenderNormal HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[ou] RenderNormal 
> > > HasTrailingNewline)
> > > -// CHECK: (CXComment_InlineCommand CommandName=[nl] RenderNormal 
> > > HasTrailingNewline)
> > > +// CHECK: (CXComment_InlineCommand CommandName=[n] RenderNormal 
> > > HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[ien] 
> > > RenderNormal HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[fr] RenderNormal 
> > > HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[en] RenderNormal 
> > > HasTrailingNewline)
> > > @@ -204,7 +203,7 @@ void f();
> > >  // CHECK: (CXComment_InlineCommand CommandName=[fro] 
> > > RenderNormal HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[ast] 
> > > RenderNormal HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[ae] RenderNormal 
> > > HasTrailingNewline)
> > > -// CHECK: (CXComment_InlineCommand CommandName=[nN] RenderNormal 
> > > HasTrailingNewline)
> > > +// CHECK: (CXComment_InlineCommand CommandName=[n] RenderNormal 
> > > HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[pc] RenderNormal 
> > > HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[tae] 
> > > RenderNormal HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[ws] RenderNormal 
> > > HasTrailingNewline)
> > > @@ -268,10 +267,8 @@ void f();
> > >  // CHECK: (CXComment_InlineCommand CommandName=[an] RenderNormal 
> > > HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[de] RenderNormal 
> > > HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[tel] 
> > > RenderNormal HasTrailingNewline)
> > > -// CHECK: (CXComment_InlineCommand CommandName=[nd] RenderNormal 
> > > HasTrailingNewline)
> > > -// CHECK: (CXComment_InlineCommand CommandName=[dic] 
> > > RenderNormal HasTrailingNewline)
> > > +// CHECK: (CXComment_InlineCommand CommandName=[n] RenderNormal 
> > > HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[Lo] RenderNormal 
> > > HasTrailingNewline)
> > > -// CHECK: (CXComment_InlineCommand CommandName=[il] RenderNormal 
> > > HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[tle] 
> > > RenderNormal HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[axt] 
> > > RenderNormal HasTrailingNewline)
> > >  // CHECK: (CXComment_InlineCommand CommandName=[ba] RenderNormal 
> > > HasTrailingNewline)
> > > @@ -283,7 +280,6 @@ void f();
> > >  // CHECK: (CXComment_InlineCommand CommandName=[ru] RenderNormal 
> > > HasTrailingNewline)
> > >  // CHECK: 

[PATCH] D132932: [Clang][Comments] Parse `` in doc comments correctly

2022-09-01 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0cb080933654: [Clang][Comments] Parse `img 
src=/` in doc comments correctly (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132932

Files:
  clang/lib/AST/CommentLexer.cpp
  clang/test/Index/comment-to-html-xml-conversion.cpp
  clang/test/Sema/warn-documentation.cpp

Index: clang/test/Sema/warn-documentation.cpp
===
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -62,6 +62,21 @@
 /// 
 int test_html11(int);
 
+/// Aaa bbb
+int test_html12(int);
+
+/// Aaa bbb
+int test_html13(int);
+
+/// Aaa bbb
+int test_html14(int);
+
+/// Aaa bbb
+int test_html15(int);
+
+/// Aaa bbb
+int test_html16(int);
+
 /// Meow
 int test_html_nesting1(int);
 
Index: clang/test/Index/comment-to-html-xml-conversion.cpp
===
--- clang/test/Index/comment-to-html-xml-conversion.cpp
+++ clang/test/Index/comment-to-html-xml-conversion.cpp
@@ -744,6 +744,26 @@
 // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)
 // CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] RenderAnchor Arg[0]=A)))]
 
+/// Aaa bbb
+void comment_to_html_conversion_38();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_38:{{.*}} FullCommentAsHTML=[ Aaa bbb] FullCommentAsXML=[comment_to_html_conversion_38c:@F@comment_to_html_conversion_38#void comment_to_html_conversion_38() Aaa bbb]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa bbb])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] SelfClosing)
+
+/// Aaa ccc
+void comment_to_html_conversion_39();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_39:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_39c:@F@comment_to_html_conversion_39#void comment_to_html_conversion_39() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] SelfClosing)
+
 /// Aaa ccc
 void comment_to_html_conversion_40();
 
@@ -754,6 +774,36 @@
 // CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
 // CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=)
 
+/// Aaa ccc
+void comment_to_html_conversion_41();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_41:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_41c:@F@comment_to_html_conversion_41#void comment_to_html_conversion_41() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=path)
+
+/// Aaa ccc
+void comment_to_html_conversion_42();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_42:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_42c:@F@comment_to_html_conversion_42#void comment_to_html_conversion_42() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=path SelfClosing)
+
+/// Aaa ddd
+void comment_to_html_conversion_43();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_43:{{.*}} FullCommentAsHTML=[ Aaa ddd] FullCommentAsXML=[comment_to_html_conversion_43c:@F@comment_to_html_conversion_43#void comment_to_html_conversion_43() Aaa ddd]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ddd])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src= SelfClosing)
+
 /// Aaa.
 class comment_to_xml_conversion_01 {
 // CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:7: ClassDecl=comment_to_xml_conversion_01:{{.*}} FullCommentAsXML=[comment_to_xml_conversion_01c:@S@comment_to_xml_conversion_01class comment_to_xml_conversion_01 {} Aaa.]
Index: clang/lib/AST/CommentLexer.cpp
===
--- clang/lib/AST/CommentLexer.cpp
+++ clang/lib/AST/CommentLexer.cpp
@@ -701,7 +701,7 @@
 
   C = 

[PATCH] D132932: [Clang][Comments] Parse `` in doc comments correctly

2022-08-31 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 456989.
egorzhdan added a comment.

Rebase to apply fixes to string conversion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132932

Files:
  clang/lib/AST/CommentLexer.cpp
  clang/test/Index/comment-to-html-xml-conversion.cpp
  clang/test/Sema/warn-documentation.cpp

Index: clang/test/Sema/warn-documentation.cpp
===
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -62,6 +62,21 @@
 /// 
 int test_html11(int);
 
+/// Aaa bbb
+int test_html12(int);
+
+/// Aaa bbb
+int test_html13(int);
+
+/// Aaa bbb
+int test_html14(int);
+
+/// Aaa bbb
+int test_html15(int);
+
+/// Aaa bbb
+int test_html16(int);
+
 /// Meow
 int test_html_nesting1(int);
 
Index: clang/test/Index/comment-to-html-xml-conversion.cpp
===
--- clang/test/Index/comment-to-html-xml-conversion.cpp
+++ clang/test/Index/comment-to-html-xml-conversion.cpp
@@ -744,6 +744,26 @@
 // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)
 // CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] RenderAnchor Arg[0]=A)))]
 
+/// Aaa bbb
+void comment_to_html_conversion_38();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_38:{{.*}} FullCommentAsHTML=[ Aaa bbb] FullCommentAsXML=[comment_to_html_conversion_38c:@F@comment_to_html_conversion_38#void comment_to_html_conversion_38() Aaa bbb]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa bbb])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] SelfClosing)
+
+/// Aaa ccc
+void comment_to_html_conversion_39();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_39:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_39c:@F@comment_to_html_conversion_39#void comment_to_html_conversion_39() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] SelfClosing)
+
 /// Aaa ccc
 void comment_to_html_conversion_40();
 
@@ -754,6 +774,36 @@
 // CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
 // CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=)
 
+/// Aaa ccc
+void comment_to_html_conversion_41();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_41:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_41c:@F@comment_to_html_conversion_41#void comment_to_html_conversion_41() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=path)
+
+/// Aaa ccc
+void comment_to_html_conversion_42();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_42:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_42c:@F@comment_to_html_conversion_42#void comment_to_html_conversion_42() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=path SelfClosing)
+
+/// Aaa ddd
+void comment_to_html_conversion_43();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_43:{{.*}} FullCommentAsHTML=[ Aaa ddd] FullCommentAsXML=[comment_to_html_conversion_43c:@F@comment_to_html_conversion_43#void comment_to_html_conversion_43() Aaa ddd]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ddd])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src= SelfClosing)
+
 /// Aaa.
 class comment_to_xml_conversion_01 {
 // CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:7: ClassDecl=comment_to_xml_conversion_01:{{.*}} FullCommentAsXML=[comment_to_xml_conversion_01c:@S@comment_to_xml_conversion_01class comment_to_xml_conversion_01 {} Aaa.]
Index: clang/lib/AST/CommentLexer.cpp
===
--- clang/lib/AST/CommentLexer.cpp
+++ clang/lib/AST/CommentLexer.cpp
@@ -701,7 +701,7 @@
 
   C = *BufferPtr;
   if (!isHTMLIdentifierStartingCharacter(C) &&
-  C != '=' && C != '\"' && C != '\'' && C != '>') {
+  C != '=' && C 

[PATCH] D133009: [libclang] Fix conversion from `StringRef` to `CXString`

2022-08-31 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8c0935238527: [libclang] Fix conversion from `StringRef` to 
`CXString` (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133009

Files:
  clang/test/Index/comment-lots-of-unknown-commands.c
  clang/test/Index/comment-to-html-xml-conversion.cpp
  clang/tools/libclang/CXString.cpp


Index: clang/tools/libclang/CXString.cpp
===
--- clang/tools/libclang/CXString.cpp
+++ clang/tools/libclang/CXString.cpp
@@ -78,13 +78,22 @@
 }
 
 CXString createRef(StringRef String) {
+  if (!String.data())
+return createNull();
+
+  // If the string is empty, it might point to a position in another string
+  // while having zero length. Make sure we don't create a reference to the
+  // larger string.
+  if (String.empty())
+return createEmpty();
+
   // If the string is not nul-terminated, we have to make a copy.
 
   // FIXME: This is doing a one past end read, and should be removed! For 
memory
   // we don't manage, the API string can become unterminated at any time 
outside
   // our control.
 
-  if (!String.empty() && String.data()[String.size()] != 0)
+  if (String.data()[String.size()] != 0)
 return createDup(String);
 
   CXString Result;
Index: clang/test/Index/comment-to-html-xml-conversion.cpp
===
--- clang/test/Index/comment-to-html-xml-conversion.cpp
+++ clang/test/Index/comment-to-html-xml-conversion.cpp
@@ -744,6 +744,15 @@
 // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)
 // CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] 
RenderAnchor Arg[0]=A)))]
 
+/// Aaa ccc
+void comment_to_html_conversion_40();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: 
FunctionDecl=comment_to_html_conversion_40:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_40c:@F@comment_to_html_conversion_40#void
 comment_to_html_conversion_40() Aaa 
ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=)
 
 /// Aaa.
 class comment_to_xml_conversion_01 {
Index: clang/test/Index/comment-lots-of-unknown-commands.c
===
--- clang/test/Index/comment-lots-of-unknown-commands.c
+++ clang/test/Index/comment-lots-of-unknown-commands.c
@@ -1,5 +1,7 @@
 // RUN: c-index-test -test-load-source-reparse 1 local %s | FileCheck %s
 
+// XFAIL: *
+
 // See PR 21254. We had too few bits to encode command IDs so if you created
 // enough of them the ID codes would wrap around. This test creates commands up
 // to an ID of 258. Ideally we should check for large numbers, but that would


Index: clang/tools/libclang/CXString.cpp
===
--- clang/tools/libclang/CXString.cpp
+++ clang/tools/libclang/CXString.cpp
@@ -78,13 +78,22 @@
 }
 
 CXString createRef(StringRef String) {
+  if (!String.data())
+return createNull();
+
+  // If the string is empty, it might point to a position in another string
+  // while having zero length. Make sure we don't create a reference to the
+  // larger string.
+  if (String.empty())
+return createEmpty();
+
   // If the string is not nul-terminated, we have to make a copy.
 
   // FIXME: This is doing a one past end read, and should be removed! For memory
   // we don't manage, the API string can become unterminated at any time outside
   // our control.
 
-  if (!String.empty() && String.data()[String.size()] != 0)
+  if (String.data()[String.size()] != 0)
 return createDup(String);
 
   CXString Result;
Index: clang/test/Index/comment-to-html-xml-conversion.cpp
===
--- clang/test/Index/comment-to-html-xml-conversion.cpp
+++ clang/test/Index/comment-to-html-xml-conversion.cpp
@@ -744,6 +744,15 @@
 // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)
 // CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] RenderAnchor Arg[0]=A)))]
 
+/// Aaa ccc
+void comment_to_html_conversion_40();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_40:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_40c:@F@comment_to_html_conversion_40#void comment_to_html_conversion_40() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=)
 
 /// Aaa.
 class 

[PATCH] D133009: [libclang] Fix conversion from `StringRef` to `CXString`

2022-08-31 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added inline comments.



Comment at: clang/test/Index/comment-lots-of-unknown-commands.c:3
 
+// XFAIL: *
+

gribozavr2 wrote:
> egorzhdan wrote:
> > This test was never properly passing. Because of the bug in string 
> > conversion, the printed comments contained the entire source file and not 
> > just the comments' text, which was enough to cause `// CHECK`-s in the test 
> > to succeed.
> > ```
> > // CHECK: (CXComment_InlineCommand CommandName=[tel] RenderNormal 
> > HasTrailingNewline)
> > // CHECK: (CXComment_InlineCommand CommandName=[n] RenderNormal 
> > HasTrailingNewline))
> > // CHECK:   (CXComment_VerbatimLine 
> > Text=[\n@Lo\n@il\n@tle\n@axt\n@ba\n@ust\n@ac\n@tpe\n@tpl\n@ctG\n@ru\n@m\n@tG\n@it\n@rh\n@G\n@rpc\n@el\n@er\n@w\n@eo\n@tx\n@oo\n@dD\n@dD\n*/\nvoid
> >  f();\n\n// CHECK:  CommentAST=[\n// CHECK:(CXComment_FullComment\n// 
> > CHECK:   (CXComment_Paragraph\n// CHECK:  ...
> > ```
> Please update the test to pass then. Here's the diff:
> 
> ```
> diff --git a/clang/test/Index/comment-lots-of-unknown-commands.c 
> b/clang/test/Index/comment-lots-of-unknown-commands.c
> index 41a03d394488..e1adcc150b1e 100644
> --- a/clang/test/Index/comment-lots-of-unknown-commands.c
> +++ b/clang/test/Index/comment-lots-of-unknown-commands.c
> @@ -1,6 +1,5 @@
>  // RUN: c-index-test -test-load-source-reparse 1 local %s | FileCheck %s
> 
> -// XFAIL: *
> 
>  // See PR 21254. We had too few bits to encode command IDs so if you created
>  // enough of them the ID codes would wrap around. This test creates commands 
> up
> @@ -183,7 +182,7 @@ void f();
>  // CHECK: (CXComment_InlineCommand CommandName=[ei] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[oun] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[ou] RenderNormal 
> HasTrailingNewline)
> -// CHECK: (CXComment_InlineCommand CommandName=[nl] RenderNormal 
> HasTrailingNewline)
> +// CHECK: (CXComment_InlineCommand CommandName=[n] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[ien] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[fr] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[en] RenderNormal 
> HasTrailingNewline)
> @@ -204,7 +203,7 @@ void f();
>  // CHECK: (CXComment_InlineCommand CommandName=[fro] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[ast] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[ae] RenderNormal 
> HasTrailingNewline)
> -// CHECK: (CXComment_InlineCommand CommandName=[nN] RenderNormal 
> HasTrailingNewline)
> +// CHECK: (CXComment_InlineCommand CommandName=[n] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[pc] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[tae] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[ws] RenderNormal 
> HasTrailingNewline)
> @@ -268,10 +267,8 @@ void f();
>  // CHECK: (CXComment_InlineCommand CommandName=[an] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[de] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[tel] RenderNormal 
> HasTrailingNewline)
> -// CHECK: (CXComment_InlineCommand CommandName=[nd] RenderNormal 
> HasTrailingNewline)
> -// CHECK: (CXComment_InlineCommand CommandName=[dic] RenderNormal 
> HasTrailingNewline)
> +// CHECK: (CXComment_InlineCommand CommandName=[n] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[Lo] RenderNormal 
> HasTrailingNewline)
> -// CHECK: (CXComment_InlineCommand CommandName=[il] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[tle] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[axt] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[ba] RenderNormal 
> HasTrailingNewline)
> @@ -283,7 +280,6 @@ void f();
>  // CHECK: (CXComment_InlineCommand CommandName=[ru] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[m] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[tG] RenderNormal 
> HasTrailingNewline)
> -// CHECK: (CXComment_InlineCommand CommandName=[it] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[rh] RenderNormal 
> HasTrailingNewline)
>  // CHECK: (CXComment_InlineCommand CommandName=[G] RenderNormal 

[PATCH] D133009: [libclang] Fix conversion from `StringRef` to `CXString`

2022-08-31 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added inline comments.



Comment at: clang/test/Index/comment-lots-of-unknown-commands.c:3
 
+// XFAIL: *
+

This test was never properly passing. Because of the bug in string conversion, 
the printed comments contained the entire source file and not just the 
comments' text, which was enough to cause `// CHECK`-s in the test to succeed.
```
// CHECK: (CXComment_InlineCommand CommandName=[tel] RenderNormal 
HasTrailingNewline)
// CHECK: (CXComment_InlineCommand CommandName=[n] RenderNormal 
HasTrailingNewline))
// CHECK:   (CXComment_VerbatimLine 
Text=[\n@Lo\n@il\n@tle\n@axt\n@ba\n@ust\n@ac\n@tpe\n@tpl\n@ctG\n@ru\n@m\n@tG\n@it\n@rh\n@G\n@rpc\n@el\n@er\n@w\n@eo\n@tx\n@oo\n@dD\n@dD\n*/\nvoid
 f();\n\n// CHECK:  CommentAST=[\n// CHECK:(CXComment_FullComment\n// 
CHECK:   (CXComment_Paragraph\n// CHECK:  ...
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133009

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


[PATCH] D133009: [libclang] Fix conversion from `StringRef` to `CXString`

2022-08-31 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 456942.
egorzhdan added a comment.

XFAIL a test that was accidentally passing because of incorrect behavior


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133009

Files:
  clang/test/Index/comment-lots-of-unknown-commands.c
  clang/test/Index/comment-to-html-xml-conversion.cpp
  clang/tools/libclang/CXString.cpp


Index: clang/tools/libclang/CXString.cpp
===
--- clang/tools/libclang/CXString.cpp
+++ clang/tools/libclang/CXString.cpp
@@ -78,13 +78,22 @@
 }
 
 CXString createRef(StringRef String) {
+  if (!String.data())
+return createNull();
+
+  // If the string is empty, it might point to a position in another string
+  // while having zero length. Make sure we don't create a reference to the
+  // larger string.
+  if (String.empty())
+return createEmpty();
+
   // If the string is not nul-terminated, we have to make a copy.
 
   // FIXME: This is doing a one past end read, and should be removed! For 
memory
   // we don't manage, the API string can become unterminated at any time 
outside
   // our control.
 
-  if (!String.empty() && String.data()[String.size()] != 0)
+  if (String.data()[String.size()] != 0)
 return createDup(String);
 
   CXString Result;
Index: clang/test/Index/comment-to-html-xml-conversion.cpp
===
--- clang/test/Index/comment-to-html-xml-conversion.cpp
+++ clang/test/Index/comment-to-html-xml-conversion.cpp
@@ -744,6 +744,15 @@
 // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)
 // CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] 
RenderAnchor Arg[0]=A)))]
 
+/// Aaa ccc
+void comment_to_html_conversion_40();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: 
FunctionDecl=comment_to_html_conversion_40:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_40c:@F@comment_to_html_conversion_40#void
 comment_to_html_conversion_40() Aaa 
ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=)
 
 /// Aaa.
 class comment_to_xml_conversion_01 {
Index: clang/test/Index/comment-lots-of-unknown-commands.c
===
--- clang/test/Index/comment-lots-of-unknown-commands.c
+++ clang/test/Index/comment-lots-of-unknown-commands.c
@@ -1,5 +1,7 @@
 // RUN: c-index-test -test-load-source-reparse 1 local %s | FileCheck %s
 
+// XFAIL: *
+
 // See PR 21254. We had too few bits to encode command IDs so if you created
 // enough of them the ID codes would wrap around. This test creates commands up
 // to an ID of 258. Ideally we should check for large numbers, but that would


Index: clang/tools/libclang/CXString.cpp
===
--- clang/tools/libclang/CXString.cpp
+++ clang/tools/libclang/CXString.cpp
@@ -78,13 +78,22 @@
 }
 
 CXString createRef(StringRef String) {
+  if (!String.data())
+return createNull();
+
+  // If the string is empty, it might point to a position in another string
+  // while having zero length. Make sure we don't create a reference to the
+  // larger string.
+  if (String.empty())
+return createEmpty();
+
   // If the string is not nul-terminated, we have to make a copy.
 
   // FIXME: This is doing a one past end read, and should be removed! For memory
   // we don't manage, the API string can become unterminated at any time outside
   // our control.
 
-  if (!String.empty() && String.data()[String.size()] != 0)
+  if (String.data()[String.size()] != 0)
 return createDup(String);
 
   CXString Result;
Index: clang/test/Index/comment-to-html-xml-conversion.cpp
===
--- clang/test/Index/comment-to-html-xml-conversion.cpp
+++ clang/test/Index/comment-to-html-xml-conversion.cpp
@@ -744,6 +744,15 @@
 // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)
 // CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] RenderAnchor Arg[0]=A)))]
 
+/// Aaa ccc
+void comment_to_html_conversion_40();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_40:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_40c:@F@comment_to_html_conversion_40#void comment_to_html_conversion_40() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=)
 
 /// Aaa.
 class comment_to_xml_conversion_01 {
Index: 

[PATCH] D133009: [libclang] Fix conversion from `StringRef` to `CXString`

2022-08-31 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
egorzhdan added a reviewer: gribozavr2.
Herald added a subscriber: arphaman.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`CXString createRef(StringRef String)` used to return an invalid string when 
invoked with some empty strings:

If a `StringRef` holds a non-nullptr pointer, for instance, pointing into 
contents of a larger string, and has a zero length, `createRef` previously 
returned the entire larger string, ignoring the fact that the actual string 
passed to it as a param is empty.

This was discovered when invoking `c-index-test` to dump the contents of 
documentation comments, in case the comment contains an empty HTML attribute, 
such as `src=""`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133009

Files:
  clang/test/Index/comment-to-html-xml-conversion.cpp
  clang/tools/libclang/CXString.cpp


Index: clang/tools/libclang/CXString.cpp
===
--- clang/tools/libclang/CXString.cpp
+++ clang/tools/libclang/CXString.cpp
@@ -78,13 +78,22 @@
 }
 
 CXString createRef(StringRef String) {
+  if (!String.data())
+return createNull();
+
+  // If the string is empty, it might point to a position in another string
+  // while having zero length. Make sure we don't create a reference to the
+  // larger string.
+  if (String.empty())
+return createEmpty();
+
   // If the string is not nul-terminated, we have to make a copy.
 
   // FIXME: This is doing a one past end read, and should be removed! For 
memory
   // we don't manage, the API string can become unterminated at any time 
outside
   // our control.
 
-  if (!String.empty() && String.data()[String.size()] != 0)
+  if (String.data()[String.size()] != 0)
 return createDup(String);
 
   CXString Result;
Index: clang/test/Index/comment-to-html-xml-conversion.cpp
===
--- clang/test/Index/comment-to-html-xml-conversion.cpp
+++ clang/test/Index/comment-to-html-xml-conversion.cpp
@@ -744,6 +744,15 @@
 // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)
 // CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] 
RenderAnchor Arg[0]=A)))]
 
+/// Aaa ccc
+void comment_to_html_conversion_40();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: 
FunctionDecl=comment_to_html_conversion_40:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_40c:@F@comment_to_html_conversion_40#void
 comment_to_html_conversion_40() Aaa 
ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=)
 
 /// Aaa.
 class comment_to_xml_conversion_01 {


Index: clang/tools/libclang/CXString.cpp
===
--- clang/tools/libclang/CXString.cpp
+++ clang/tools/libclang/CXString.cpp
@@ -78,13 +78,22 @@
 }
 
 CXString createRef(StringRef String) {
+  if (!String.data())
+return createNull();
+
+  // If the string is empty, it might point to a position in another string
+  // while having zero length. Make sure we don't create a reference to the
+  // larger string.
+  if (String.empty())
+return createEmpty();
+
   // If the string is not nul-terminated, we have to make a copy.
 
   // FIXME: This is doing a one past end read, and should be removed! For memory
   // we don't manage, the API string can become unterminated at any time outside
   // our control.
 
-  if (!String.empty() && String.data()[String.size()] != 0)
+  if (String.data()[String.size()] != 0)
 return createDup(String);
 
   CXString Result;
Index: clang/test/Index/comment-to-html-xml-conversion.cpp
===
--- clang/test/Index/comment-to-html-xml-conversion.cpp
+++ clang/test/Index/comment-to-html-xml-conversion.cpp
@@ -744,6 +744,15 @@
 // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)
 // CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] RenderAnchor Arg[0]=A)))]
 
+/// Aaa ccc
+void comment_to_html_conversion_40();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_40:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_40c:@F@comment_to_html_conversion_40#void comment_to_html_conversion_40() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=)
 
 /// Aaa.
 class comment_to_xml_conversion_01 {
___
cfe-commits 

[PATCH] D132932: [Clang][Comments] Parse `` in doc comments correctly

2022-08-30 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan marked an inline comment as done.
egorzhdan added inline comments.



Comment at: clang/tools/libclang/CXString.cpp:85
+  if (String.empty())
+return createEmpty();
+

gribozavr2 wrote:
> Please split this change into a separate patch and add a unit test.
> 
Do you know a good way to add a unit-test for this? This function only gets 
called from within libclang, it isn't exposed to clients of libclang, including 
libclangTest. So I think a unit test would probably need to invoke the same 
CXComment API that `c-index-test` invokes while running 
`comment-to-html-xml-conversion.cpp`. Would that be worth it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132932

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


[PATCH] D132932: [Clang][Comments] Parse `` in doc comments correctly

2022-08-30 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan marked an inline comment as done.
egorzhdan added inline comments.



Comment at: clang/test/Sema/warn-documentation.cpp:78
+/// Aaa bbb
+int test_html_img4(int);
+

gribozavr2 wrote:
> Could you also add these tests to 
> clang/test/Index/comment-to-html-xml-conversion.cpp to show that the whole 
> tag is captured correctly? (for example, the ">" is correctly captured as a 
> part of the tag, not as plain text)
Thanks, added a few tests there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132932

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


[PATCH] D132932: [Clang][Comments] Parse `` in doc comments correctly

2022-08-30 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 456674.
egorzhdan added a comment.

- Add tests for conversion of doc comments to HTML/XML
- Fix a bug in `StringRef` -> `CXString` conversion logic for an empty

string


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132932

Files:
  clang/lib/AST/CommentLexer.cpp
  clang/test/Index/comment-to-html-xml-conversion.cpp
  clang/test/Sema/warn-documentation.cpp
  clang/tools/libclang/CXString.cpp

Index: clang/tools/libclang/CXString.cpp
===
--- clang/tools/libclang/CXString.cpp
+++ clang/tools/libclang/CXString.cpp
@@ -78,13 +78,19 @@
 }
 
 CXString createRef(StringRef String) {
+  // If the string is empty, it might point to a position in another string
+  // while having zero length. Make sure we don't create a reference to the
+  // larger string.
+  if (String.empty())
+return createEmpty();
+
   // If the string is not nul-terminated, we have to make a copy.
 
   // FIXME: This is doing a one past end read, and should be removed! For memory
   // we don't manage, the API string can become unterminated at any time outside
   // our control.
 
-  if (!String.empty() && String.data()[String.size()] != 0)
+  if (String.data()[String.size()] != 0)
 return createDup(String);
 
   CXString Result;
Index: clang/test/Sema/warn-documentation.cpp
===
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -62,6 +62,21 @@
 /// 
 int test_html11(int);
 
+/// Aaa bbb
+int test_html12(int);
+
+/// Aaa bbb
+int test_html13(int);
+
+/// Aaa bbb
+int test_html14(int);
+
+/// Aaa bbb
+int test_html15(int);
+
+/// Aaa bbb
+int test_html16(int);
+
 /// Meow
 int test_html_nesting1(int);
 
Index: clang/test/Index/comment-to-html-xml-conversion.cpp
===
--- clang/test/Index/comment-to-html-xml-conversion.cpp
+++ clang/test/Index/comment-to-html-xml-conversion.cpp
@@ -744,6 +744,65 @@
 // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)
 // CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] RenderAnchor Arg[0]=A)))]
 
+/// Aaa bbb
+void comment_to_html_conversion_38();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_38:{{.*}} FullCommentAsHTML=[ Aaa bbb] FullCommentAsXML=[comment_to_html_conversion_38c:@F@comment_to_html_conversion_38#void comment_to_html_conversion_38() Aaa bbb]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa bbb])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] SelfClosing)
+
+/// Aaa ccc
+void comment_to_html_conversion_39();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_39:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_39c:@F@comment_to_html_conversion_39#void comment_to_html_conversion_39() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] SelfClosing)
+
+/// Aaa ccc
+void comment_to_html_conversion_40();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_40:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_40c:@F@comment_to_html_conversion_40#void comment_to_html_conversion_40() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=)
+
+/// Aaa ccc
+void comment_to_html_conversion_41();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_41:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_41c:@F@comment_to_html_conversion_41#void comment_to_html_conversion_41() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// CHECK-NEXT:   (CXComment_Paragraph
+// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc])
+// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=path)
+
+/// Aaa ccc
+void comment_to_html_conversion_42();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_42:{{.*}} FullCommentAsHTML=[ Aaa ccc] FullCommentAsXML=[comment_to_html_conversion_42c:@F@comment_to_html_conversion_42#void comment_to_html_conversion_42() Aaa ccc]
+// CHECK-NEXT:  CommentAST=[
+// CHECK-NEXT:(CXComment_FullComment
+// 

[PATCH] D132932: [Clang][Comments] Parse `` in doc comments correctly

2022-08-30 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a valid HTML5 tag. Previously it triggered a Clang error (`HTML start 
tag prematurely ended, expected attribute name or '>'`) since Clang was 
treating `/>` as a text token. This was happening because after lexing the 
closing quote (`"`) the lexer state was reset to "Normal" while the tag was not 
actually closed yet: `>` was not yet parsed at that point.

rdar://91464292


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132932

Files:
  clang/lib/AST/CommentLexer.cpp
  clang/test/Sema/warn-documentation.cpp


Index: clang/test/Sema/warn-documentation.cpp
===
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -62,6 +62,21 @@
 /// 
 int test_html11(int);
 
+/// Aaa bbb
+int test_html_img1(int);
+
+/// Aaa bbb
+int test_html_img2(int);
+
+/// Aaa bbb
+int test_html_img3(int);
+
+/// Aaa bbb
+int test_html_img3(int);
+
+/// Aaa bbb
+int test_html_img4(int);
+
 /// Meow
 int test_html_nesting1(int);
 
Index: clang/lib/AST/CommentLexer.cpp
===
--- clang/lib/AST/CommentLexer.cpp
+++ clang/lib/AST/CommentLexer.cpp
@@ -701,7 +701,7 @@
 
   C = *BufferPtr;
   if (!isHTMLIdentifierStartingCharacter(C) &&
-  C != '=' && C != '\"' && C != '\'' && C != '>') {
+  C != '=' && C != '\"' && C != '\'' && C != '>' && C != '/') {
 State = LS_Normal;
 return;
   }


Index: clang/test/Sema/warn-documentation.cpp
===
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -62,6 +62,21 @@
 /// 
 int test_html11(int);
 
+/// Aaa bbb
+int test_html_img1(int);
+
+/// Aaa bbb
+int test_html_img2(int);
+
+/// Aaa bbb
+int test_html_img3(int);
+
+/// Aaa bbb
+int test_html_img3(int);
+
+/// Aaa bbb
+int test_html_img4(int);
+
 /// Meow
 int test_html_nesting1(int);
 
Index: clang/lib/AST/CommentLexer.cpp
===
--- clang/lib/AST/CommentLexer.cpp
+++ clang/lib/AST/CommentLexer.cpp
@@ -701,7 +701,7 @@
 
   C = *BufferPtr;
   if (!isHTMLIdentifierStartingCharacter(C) &&
-  C != '=' && C != '\"' && C != '\'' && C != '>') {
+  C != '=' && C != '\"' && C != '\'' && C != '>' && C != '/') {
 State = LS_Normal;
 return;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129654: [Clang][Driver] Fix include paths for `--sysroot /` on OpenBSD/FreeBSD

2022-07-22 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d0cc510516d: [Clang][Driver] Fix include paths for 
`--sysroot /` on OpenBSD/FreeBSD (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129654

Files:
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/test/Driver/Inputs/basic_freebsd_libcxx_tree/usr/bin/.keep
  clang/test/Driver/Inputs/basic_freebsd_libcxx_tree/usr/include/c++/v1/.keep
  clang/test/Driver/Inputs/basic_freebsd_libcxx_tree/usr/lib/.keep
  clang/test/Driver/Inputs/basic_openbsd_libcxx_tree/usr/bin/.keep
  clang/test/Driver/Inputs/basic_openbsd_libcxx_tree/usr/include/c++/v1/.keep
  clang/test/Driver/Inputs/basic_openbsd_libcxx_tree/usr/lib/.keep
  clang/test/Driver/freebsd.cpp
  clang/test/Driver/openbsd.cpp

Index: clang/test/Driver/openbsd.cpp
===
--- clang/test/Driver/openbsd.cpp
+++ clang/test/Driver/openbsd.cpp
@@ -19,3 +19,23 @@
 // RUN: %clangxx %s -### -pg -o %t.o -target arm-unknown-openbsd 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-PG-CXX %s
 // CHECK-PG-CXX: "-lc++_p" "-lc++abi_p" "-lpthread_p" "-lm_p"
+
+// Test include paths with a sysroot.
+// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
+// RUN: --target=amd64-pc-openbsd \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT %s
+// CHECK-LIBCXX-SYSROOT: "-cc1"
+// CHECK-LIBCXX-SYSROOT-SAME: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LIBCXX-SYSROOT-SAME: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
+
+// Test include paths when the sysroot path ends with `/`.
+// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
+// RUN: --target=amd64-pc-openbsd \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree/ \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT-SLASH %s
+// CHECK-LIBCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"
Index: clang/test/Driver/freebsd.cpp
===
--- clang/test/Driver/freebsd.cpp
+++ clang/test/Driver/freebsd.cpp
@@ -20,3 +20,23 @@
 // CHECK-PG-FOURTEEN: "-lc++" "-lm"
 // CHECK-PG-TEN: "-lc++_p" "-lm_p"
 // CHECK-PG-NINE: "-lstdc++_p" "-lm_p"
+
+// Test include paths with a sysroot.
+// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
+// RUN: --target=amd64-unknown-freebsd \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT %s
+// CHECK-LIBCXX-SYSROOT: "-cc1"
+// CHECK-LIBCXX-SYSROOT-SAME: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LIBCXX-SYSROOT-SAME: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
+
+// Test include paths when the sysroot path ends with `/`.
+// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
+// RUN: --target=amd64-unknown-freebsd \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree/ \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT-SLASH %s
+// CHECK-LIBCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -284,7 +284,7 @@
 OpenBSD::OpenBSD(const Driver , const llvm::Triple ,
  const ArgList )
 : Generic_ELF(D, Triple, Args) {
-  getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
+  getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
 }
 
 void OpenBSD::AddClangSystemIncludeArgs(
@@ -317,13 +317,14 @@
 return;
   }
 
-  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include");
+  addExternCSystemInclude(DriverArgs, CC1Args,
+  concat(D.SysRoot, "/usr/include"));
 }
 
 void OpenBSD::addLibCxxIncludePaths(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const {
   addSystemInclude(DriverArgs, CC1Args,
-   getDriver().SysRoot + "/usr/include/c++/v1");
+   concat(getDriver().SysRoot, "/usr/include/c++/v1"));
 }
 
 void OpenBSD::AddCXXStdlibLibArgs(const ArgList ,
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ 

[PATCH] D129654: [Clang][Driver] Fix include paths for `--sysroot /` on OpenBSD/FreeBSD

2022-07-22 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

Thanks @brad @3405691582 @MaskRay for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129654

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


[PATCH] D129654: [Clang][Driver] Fix include paths for `--sysroot /` on OpenBSD/FreeBSD

2022-07-20 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 446223.
egorzhdan added a comment.

- Add a test for OpenBSD
- Modify existing test file instead of adding a new file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129654

Files:
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/test/Driver/Inputs/basic_freebsd_libcxx_tree/usr/bin/.keep
  clang/test/Driver/Inputs/basic_freebsd_libcxx_tree/usr/include/c++/v1/.keep
  clang/test/Driver/Inputs/basic_freebsd_libcxx_tree/usr/lib/.keep
  clang/test/Driver/Inputs/basic_openbsd_libcxx_tree/usr/bin/.keep
  clang/test/Driver/Inputs/basic_openbsd_libcxx_tree/usr/include/c++/v1/.keep
  clang/test/Driver/Inputs/basic_openbsd_libcxx_tree/usr/lib/.keep
  clang/test/Driver/freebsd.cpp
  clang/test/Driver/openbsd.cpp

Index: clang/test/Driver/openbsd.cpp
===
--- clang/test/Driver/openbsd.cpp
+++ clang/test/Driver/openbsd.cpp
@@ -19,3 +19,23 @@
 // RUN: %clangxx %s -### -pg -o %t.o -target arm-unknown-openbsd 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-PG-CXX %s
 // CHECK-PG-CXX: "-lc++_p" "-lc++abi_p" "-lpthread_p" "-lm_p"
+
+// Test include paths with a sysroot.
+// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
+// RUN: --target=amd64-pc-openbsd \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT %s
+// CHECK-LIBCXX-SYSROOT: "-cc1"
+// CHECK-LIBCXX-SYSROOT-SAME: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LIBCXX-SYSROOT-SAME: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
+
+// Test include paths when the sysroot path ends with `/`.
+// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
+// RUN: --target=amd64-pc-openbsd \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree/ \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT-SLASH %s
+// CHECK-LIBCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"
Index: clang/test/Driver/freebsd.cpp
===
--- clang/test/Driver/freebsd.cpp
+++ clang/test/Driver/freebsd.cpp
@@ -20,3 +20,23 @@
 // CHECK-PG-FOURTEEN: "-lc++" "-lm"
 // CHECK-PG-TEN: "-lc++_p" "-lm_p"
 // CHECK-PG-NINE: "-lstdc++_p" "-lm_p"
+
+// Test include paths with a sysroot.
+// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
+// RUN: --target=amd64-unknown-freebsd \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT %s
+// CHECK-LIBCXX-SYSROOT: "-cc1"
+// CHECK-LIBCXX-SYSROOT-SAME: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LIBCXX-SYSROOT-SAME: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
+
+// Test include paths when the sysroot path ends with `/`.
+// RUN: %clangxx %s -### -fsyntax-only 2>&1 \
+// RUN: --target=amd64-unknown-freebsd \
+// RUN: --sysroot=%S/Inputs/basic_openbsd_libcxx_tree/ \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX-SYSROOT-SLASH %s
+// CHECK-LIBCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -284,7 +284,7 @@
 OpenBSD::OpenBSD(const Driver , const llvm::Triple ,
  const ArgList )
 : Generic_ELF(D, Triple, Args) {
-  getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
+  getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
 }
 
 void OpenBSD::AddClangSystemIncludeArgs(
@@ -317,13 +317,14 @@
 return;
   }
 
-  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include");
+  addExternCSystemInclude(DriverArgs, CC1Args,
+  concat(D.SysRoot, "/usr/include"));
 }
 
 void OpenBSD::addLibCxxIncludePaths(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const {
   addSystemInclude(DriverArgs, CC1Args,
-   getDriver().SysRoot + "/usr/include/c++/v1");
+   concat(getDriver().SysRoot, "/usr/include/c++/v1"));
 }
 
 void OpenBSD::AddCXXStdlibLibArgs(const ArgList ,
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -389,10 +389,10 @@
   // back to '/usr/lib' if it 

[PATCH] D129654: [Clang][Driver] Fix include paths for `--sysroot /` on OpenBSD/FreeBSD

2022-07-13 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
Herald added subscribers: krytarowski, arichardson, emaste.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

This is the same change as https://reviews.llvm.org/D126289, but applied for 
OpenBSD & FreeBSD.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129654

Files:
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  llvm/clang/test/Driver/freebsd-header-search.cpp


Index: llvm/clang/test/Driver/freebsd-header-search.cpp
===
--- /dev/null
+++ llvm/clang/test/Driver/freebsd-header-search.cpp
@@ -0,0 +1,12 @@
+// Test include paths when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=amd64-unknown-freebsd \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_freebsd_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" 
"[[SYSROOT]]usr/include/c++/v1"
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -284,7 +284,7 @@
 OpenBSD::OpenBSD(const Driver , const llvm::Triple ,
  const ArgList )
 : Generic_ELF(D, Triple, Args) {
-  getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
+  getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
 }
 
 void OpenBSD::AddClangSystemIncludeArgs(
@@ -317,13 +317,14 @@
 return;
   }
 
-  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include");
+  addExternCSystemInclude(DriverArgs, CC1Args,
+  concat(D.SysRoot, "/usr/include"));
 }
 
 void OpenBSD::addLibCxxIncludePaths(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const {
   addSystemInclude(DriverArgs, CC1Args,
-   getDriver().SysRoot + "/usr/include/c++/v1");
+   concat(getDriver().SysRoot, "/usr/include/c++/v1"));
 }
 
 void OpenBSD::AddCXXStdlibLibArgs(const ArgList ,
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -389,10 +389,10 @@
   // back to '/usr/lib' if it doesn't exist.
   if ((Triple.getArch() == llvm::Triple::x86 || Triple.isMIPS32() ||
Triple.isPPC32()) &&
-  D.getVFS().exists(getDriver().SysRoot + "/usr/lib32/crt1.o"))
-getFilePaths().push_back(getDriver().SysRoot + "/usr/lib32");
+  D.getVFS().exists(concat(getDriver().SysRoot, "/usr/lib32/crt1.o")))
+getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib32"));
   else
-getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
+getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib"));
 }
 
 ToolChain::CXXStdlibType FreeBSD::GetDefaultCXXStdlibType() const {
@@ -411,14 +411,14 @@
 void FreeBSD::addLibCxxIncludePaths(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const {
   addSystemInclude(DriverArgs, CC1Args,
-   getDriver().SysRoot + "/usr/include/c++/v1");
+   concat(getDriver().SysRoot, "/usr/include/c++/v1"));
 }
 
 void FreeBSD::addLibStdCxxIncludePaths(
 const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const {
-  addLibStdCXXIncludePaths(getDriver().SysRoot + "/usr/include/c++/4.2", "", 
"",
-   DriverArgs, CC1Args);
+  addLibStdCXXIncludePaths(concat(getDriver().SysRoot, "/usr/include/c++/4.2"),
+   "", "", DriverArgs, CC1Args);
 }
 
 void FreeBSD::AddCXXStdlibLibArgs(const ArgList ,


Index: llvm/clang/test/Driver/freebsd-header-search.cpp
===
--- /dev/null
+++ llvm/clang/test/Driver/freebsd-header-search.cpp
@@ -0,0 +1,12 @@
+// Test include paths when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=amd64-unknown-freebsd \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_freebsd_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH: "-cc1"

[PATCH] D128814: [Clang][Preprocessor] Fix inconsistent `FLT_EVAL_METHOD` when compiling vs preprocessing

2022-06-29 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5f2cf3a21f3a: [Clang][Preprocessor] Fix inconsistent 
`FLT_EVAL_METHOD` when compiling vs… (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128814

Files:
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/Preprocessor/flt_eval_macro.cpp


Index: clang/test/Preprocessor/flt_eval_macro.cpp
===
--- clang/test/Preprocessor/flt_eval_macro.cpp
+++ clang/test/Preprocessor/flt_eval_macro.cpp
@@ -16,6 +16,9 @@
 // RUN: %clang_cc1 -E -dM -triple=arm64_32-apple-ios -target-feature -sse \
 // RUN:   %s -o - | FileCheck %s  -strict-whitespace
 
+// RUN: %clang_cc1 -E -dM -triple=x86_64-apple-macos13.0 -ffast-math \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-MINUS-ONE 
-strict-whitespace
+
 // RUN: %clang_cc1 -E -dM -triple i386-pc-windows -target-cpu pentium4 %s -o - 
\
 // RUN:   | FileCheck %s  -strict-whitespace
 
@@ -35,7 +38,9 @@
 #define __GLIBC_FLT_EVAL_METHOD 2
 #endif
 
-#if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
+#if __GLIBC_FLT_EVAL_METHOD == -1
+#define Name "MinusOne"
+#elif __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
 #define Name "One"
 #elif __GLIBC_FLT_EVAL_METHOD == 1
 #define Name "Two"
@@ -59,6 +64,7 @@
 
 int foo() {
   // CHECK: #define Name "One"
+  // CHECK-MINUS-ONE: #define Name "MinusOne"
   // EXT: #define Name "Three"
   return Name;
 }
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -249,21 +249,8 @@
   SemaPPCallbackHandler = Callbacks.get();
   PP.addPPCallbacks(std::move(Callbacks));
   SemaPPCallbackHandler->set(*this);
-  if (getLangOpts().getFPEvalMethod() == LangOptions::FEM_UnsetOnCommandLine)
-// Use setting from TargetInfo.
-PP.setCurrentFPEvalMethod(SourceLocation(),
-  ctxt.getTargetInfo().getFPEvalMethod());
-  else
-// Set initial value of __FLT_EVAL_METHOD__ from the command line.
-PP.setCurrentFPEvalMethod(SourceLocation(),
-  getLangOpts().getFPEvalMethod());
+
   CurFPFeatures.setFPEvalMethod(PP.getCurrentFPEvalMethod());
-  // When `-ffast-math` option is enabled, it triggers several driver math
-  // options to be enabled. Among those, only one the following two modes
-  // affect the eval-method:  reciprocal or reassociate.
-  if (getLangOpts().AllowFPReassoc || getLangOpts().AllowRecip)
-PP.setCurrentFPEvalMethod(SourceLocation(),
-  LangOptions::FEM_Indeterminable);
 }
 
 // Anchor Sema's type info to this TU.
Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -206,6 +206,18 @@
 
   // Initialize the __FTL_EVAL_METHOD__ macro to the TargetInfo.
   setTUFPEvalMethod(getTargetInfo().getFPEvalMethod());
+
+  if (getLangOpts().getFPEvalMethod() == LangOptions::FEM_UnsetOnCommandLine)
+// Use setting from TargetInfo.
+setCurrentFPEvalMethod(SourceLocation(), Target.getFPEvalMethod());
+  else
+// Set initial value of __FLT_EVAL_METHOD__ from the command line.
+setCurrentFPEvalMethod(SourceLocation(), getLangOpts().getFPEvalMethod());
+  // When `-ffast-math` option is enabled, it triggers several driver math
+  // options to be enabled. Among those, only one the following two modes
+  // affect the eval-method:  reciprocal or reassociate.
+  if (getLangOpts().AllowFPReassoc || getLangOpts().AllowRecip)
+setCurrentFPEvalMethod(SourceLocation(), LangOptions::FEM_Indeterminable);
 }
 
 void Preprocessor::InitializeForModelFile() {


Index: clang/test/Preprocessor/flt_eval_macro.cpp
===
--- clang/test/Preprocessor/flt_eval_macro.cpp
+++ clang/test/Preprocessor/flt_eval_macro.cpp
@@ -16,6 +16,9 @@
 // RUN: %clang_cc1 -E -dM -triple=arm64_32-apple-ios -target-feature -sse \
 // RUN:   %s -o - | FileCheck %s  -strict-whitespace
 
+// RUN: %clang_cc1 -E -dM -triple=x86_64-apple-macos13.0 -ffast-math \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-MINUS-ONE -strict-whitespace
+
 // RUN: %clang_cc1 -E -dM -triple i386-pc-windows -target-cpu pentium4 %s -o - \
 // RUN:   | FileCheck %s  -strict-whitespace
 
@@ -35,7 +38,9 @@
 #define __GLIBC_FLT_EVAL_METHOD 2
 #endif
 
-#if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
+#if __GLIBC_FLT_EVAL_METHOD == -1
+#define Name "MinusOne"
+#elif __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
 #define Name "One"
 #elif __GLIBC_FLT_EVAL_METHOD == 1
 #define Name "Two"
@@ -59,6 +64,7 @@
 
 int foo() {
   // CHECK: #define Name "One"
+  // CHECK-MINUS-ONE: 

[PATCH] D128814: [Clang][Preprocessor] Fix inconsistent `FLT_EVAL_METHOD` when compiling vs preprocessing

2022-06-29 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 440978.
egorzhdan added a comment.

Adjust commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128814

Files:
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/Preprocessor/flt_eval_macro.cpp


Index: clang/test/Preprocessor/flt_eval_macro.cpp
===
--- clang/test/Preprocessor/flt_eval_macro.cpp
+++ clang/test/Preprocessor/flt_eval_macro.cpp
@@ -16,6 +16,9 @@
 // RUN: %clang_cc1 -E -dM -triple=arm64_32-apple-ios -target-feature -sse \
 // RUN:   %s -o - | FileCheck %s  -strict-whitespace
 
+// RUN: %clang_cc1 -E -dM -triple=x86_64-apple-macos13.0 -ffast-math \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-MINUS-ONE 
-strict-whitespace
+
 // RUN: %clang_cc1 -E -dM -triple i386-pc-windows -target-cpu pentium4 %s -o - 
\
 // RUN:   | FileCheck %s  -strict-whitespace
 
@@ -35,7 +38,9 @@
 #define __GLIBC_FLT_EVAL_METHOD 2
 #endif
 
-#if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
+#if __GLIBC_FLT_EVAL_METHOD == -1
+#define Name "MinusOne"
+#elif __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
 #define Name "One"
 #elif __GLIBC_FLT_EVAL_METHOD == 1
 #define Name "Two"
@@ -59,6 +64,7 @@
 
 int foo() {
   // CHECK: #define Name "One"
+  // CHECK-MINUS-ONE: #define Name "MinusOne"
   // EXT: #define Name "Three"
   return Name;
 }
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -249,21 +249,8 @@
   SemaPPCallbackHandler = Callbacks.get();
   PP.addPPCallbacks(std::move(Callbacks));
   SemaPPCallbackHandler->set(*this);
-  if (getLangOpts().getFPEvalMethod() == LangOptions::FEM_UnsetOnCommandLine)
-// Use setting from TargetInfo.
-PP.setCurrentFPEvalMethod(SourceLocation(),
-  ctxt.getTargetInfo().getFPEvalMethod());
-  else
-// Set initial value of __FLT_EVAL_METHOD__ from the command line.
-PP.setCurrentFPEvalMethod(SourceLocation(),
-  getLangOpts().getFPEvalMethod());
+
   CurFPFeatures.setFPEvalMethod(PP.getCurrentFPEvalMethod());
-  // When `-ffast-math` option is enabled, it triggers several driver math
-  // options to be enabled. Among those, only one the following two modes
-  // affect the eval-method:  reciprocal or reassociate.
-  if (getLangOpts().AllowFPReassoc || getLangOpts().AllowRecip)
-PP.setCurrentFPEvalMethod(SourceLocation(),
-  LangOptions::FEM_Indeterminable);
 }
 
 // Anchor Sema's type info to this TU.
Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -206,6 +206,18 @@
 
   // Initialize the __FTL_EVAL_METHOD__ macro to the TargetInfo.
   setTUFPEvalMethod(getTargetInfo().getFPEvalMethod());
+
+  if (getLangOpts().getFPEvalMethod() == LangOptions::FEM_UnsetOnCommandLine)
+// Use setting from TargetInfo.
+setCurrentFPEvalMethod(SourceLocation(), Target.getFPEvalMethod());
+  else
+// Set initial value of __FLT_EVAL_METHOD__ from the command line.
+setCurrentFPEvalMethod(SourceLocation(), getLangOpts().getFPEvalMethod());
+  // When `-ffast-math` option is enabled, it triggers several driver math
+  // options to be enabled. Among those, only one the following two modes
+  // affect the eval-method:  reciprocal or reassociate.
+  if (getLangOpts().AllowFPReassoc || getLangOpts().AllowRecip)
+setCurrentFPEvalMethod(SourceLocation(), LangOptions::FEM_Indeterminable);
 }
 
 void Preprocessor::InitializeForModelFile() {


Index: clang/test/Preprocessor/flt_eval_macro.cpp
===
--- clang/test/Preprocessor/flt_eval_macro.cpp
+++ clang/test/Preprocessor/flt_eval_macro.cpp
@@ -16,6 +16,9 @@
 // RUN: %clang_cc1 -E -dM -triple=arm64_32-apple-ios -target-feature -sse \
 // RUN:   %s -o - | FileCheck %s  -strict-whitespace
 
+// RUN: %clang_cc1 -E -dM -triple=x86_64-apple-macos13.0 -ffast-math \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-MINUS-ONE -strict-whitespace
+
 // RUN: %clang_cc1 -E -dM -triple i386-pc-windows -target-cpu pentium4 %s -o - \
 // RUN:   | FileCheck %s  -strict-whitespace
 
@@ -35,7 +38,9 @@
 #define __GLIBC_FLT_EVAL_METHOD 2
 #endif
 
-#if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
+#if __GLIBC_FLT_EVAL_METHOD == -1
+#define Name "MinusOne"
+#elif __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
 #define Name "One"
 #elif __GLIBC_FLT_EVAL_METHOD == 1
 #define Name "Two"
@@ -59,6 +64,7 @@
 
 int foo() {
   // CHECK: #define Name "One"
+  // CHECK-MINUS-ONE: #define Name "MinusOne"
   // EXT: #define Name "Three"
   return Name;
 }
Index: clang/lib/Sema/Sema.cpp

[PATCH] D128814: [Clang][Preprocessor] Fix inconsistent `FLT_EVAL_METHOD` when compiling vs preprocessing

2022-06-29 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
egorzhdan added a reviewer: zahiraam.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When running `clang -E -Ofast` on macOS, the `__FLT_EVAL_METHOD__` macro is 
`0`, which causes the following typedef to be emitted into the preprocessed 
source: `typedef float float_t`.

However, when running `clang -c -Ofast`, `__FLT_EVAL_METHOD__` is `-1`, and 
`typedef long double float_t` is emitted.

This causes build errors for certain projects, which are not reproducible when 
compiling from preprocessed source.

The issue is that `__FLT_EVAL_METHOD__` is configured in `Sema::Sema` which is 
not executed when running in `-E` mode.

This change moves that logic into the preprocessor initialization method, which 
is invoked correctly in `-E` mode.

rdar://92748429


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128814

Files:
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/Preprocessor/flt_eval_macro.cpp


Index: clang/test/Preprocessor/flt_eval_macro.cpp
===
--- clang/test/Preprocessor/flt_eval_macro.cpp
+++ clang/test/Preprocessor/flt_eval_macro.cpp
@@ -16,6 +16,9 @@
 // RUN: %clang_cc1 -E -dM -triple=arm64_32-apple-ios -target-feature -sse \
 // RUN:   %s -o - | FileCheck %s  -strict-whitespace
 
+// RUN: %clang_cc1 -E -dM -triple=x86_64-apple-macos13.0 -ffast-math \
+// RUN:   %s -o - | FileCheck %s -check-prefix=CHECK-MINUS-ONE 
-strict-whitespace
+
 // RUN: %clang_cc1 -E -dM -triple i386-pc-windows -target-cpu pentium4 %s -o - 
\
 // RUN:   | FileCheck %s  -strict-whitespace
 
@@ -35,7 +38,9 @@
 #define __GLIBC_FLT_EVAL_METHOD 2
 #endif
 
-#if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
+#if __GLIBC_FLT_EVAL_METHOD == -1
+#define Name "MinusOne"
+#elif __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
 #define Name "One"
 #elif __GLIBC_FLT_EVAL_METHOD == 1
 #define Name "Two"
@@ -59,6 +64,7 @@
 
 int foo() {
   // CHECK: #define Name "One"
+  // CHECK-MINUS-ONE: #define Name "MinusOne"
   // EXT: #define Name "Three"
   return Name;
 }
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -249,21 +249,8 @@
   SemaPPCallbackHandler = Callbacks.get();
   PP.addPPCallbacks(std::move(Callbacks));
   SemaPPCallbackHandler->set(*this);
-  if (getLangOpts().getFPEvalMethod() == LangOptions::FEM_UnsetOnCommandLine)
-// Use setting from TargetInfo.
-PP.setCurrentFPEvalMethod(SourceLocation(),
-  ctxt.getTargetInfo().getFPEvalMethod());
-  else
-// Set initial value of __FLT_EVAL_METHOD__ from the command line.
-PP.setCurrentFPEvalMethod(SourceLocation(),
-  getLangOpts().getFPEvalMethod());
+
   CurFPFeatures.setFPEvalMethod(PP.getCurrentFPEvalMethod());
-  // When `-ffast-math` option is enabled, it triggers several driver math
-  // options to be enabled. Among those, only one the following two modes
-  // affect the eval-method:  reciprocal or reassociate.
-  if (getLangOpts().AllowFPReassoc || getLangOpts().AllowRecip)
-PP.setCurrentFPEvalMethod(SourceLocation(),
-  LangOptions::FEM_Indeterminable);
 }
 
 // Anchor Sema's type info to this TU.
Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -206,6 +206,18 @@
 
   // Initialize the __FTL_EVAL_METHOD__ macro to the TargetInfo.
   setTUFPEvalMethod(getTargetInfo().getFPEvalMethod());
+
+  if (getLangOpts().getFPEvalMethod() == LangOptions::FEM_UnsetOnCommandLine)
+// Use setting from TargetInfo.
+setCurrentFPEvalMethod(SourceLocation(), Target.getFPEvalMethod());
+  else
+// Set initial value of __FLT_EVAL_METHOD__ from the command line.
+setCurrentFPEvalMethod(SourceLocation(), getLangOpts().getFPEvalMethod());
+  // When `-ffast-math` option is enabled, it triggers several driver math
+  // options to be enabled. Among those, only one the following two modes
+  // affect the eval-method:  reciprocal or reassociate.
+  if (getLangOpts().AllowFPReassoc || getLangOpts().AllowRecip)
+setCurrentFPEvalMethod(SourceLocation(), LangOptions::FEM_Indeterminable);
 }
 
 void Preprocessor::InitializeForModelFile() {


Index: clang/test/Preprocessor/flt_eval_macro.cpp
===
--- clang/test/Preprocessor/flt_eval_macro.cpp
+++ clang/test/Preprocessor/flt_eval_macro.cpp
@@ -16,6 +16,9 @@
 // RUN: %clang_cc1 -E -dM -triple=arm64_32-apple-ios -target-feature -sse \
 // RUN:   %s -o - | FileCheck %s  -strict-whitespace
 
+// RUN: %clang_cc1 -E -dM -triple=x86_64-apple-macos13.0 -ffast-math \
+// RUN:   %s -o 

[PATCH] D127408: [clang][driver] Introduce new -fdriver-only flag

2022-06-10 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan accepted this revision.
egorzhdan added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127408

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


[PATCH] D126289: [Clang][Driver] Fix include paths for `--sysroot /` on Linux

2022-05-27 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe917801eddbe: [Clang][Driver] Fix include paths for 
`--sysroot /` on Linux (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126289

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/Inputs/basic_linux_libstdcxx_tree/usr/bin/.keep
  
clang/test/Driver/Inputs/basic_linux_libstdcxx_tree/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/crtbegin.o
  clang/test/Driver/linux-header-search.cpp

Index: clang/test/Driver/linux-header-search.cpp
===
--- clang/test/Driver/linux-header-search.cpp
+++ clang/test/Driver/linux-header-search.cpp
@@ -16,6 +16,22 @@
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/x86_64-unknown-linux-gnu/c++/v1"
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+
+// Test include paths when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/x86_64-unknown-linux-gnu/c++/v1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/local/include"
+
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
 // RUN: -stdlib=libc++ \
@@ -56,7 +72,20 @@
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/x86_64-unknown-linux-gnu/c++/v2"
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v2"
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
-//
+
+// Test Linux with libstdc++ when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libstdc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libstdcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/../../../../x86_64-unknown-linux-gnu/include"
+
 // Test Linux with both libc++ and libstdc++ installed.
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -97,9 +97,9 @@
   case llvm::Triple::mips64: {
 std::string MT = std::string(IsMipsR6 ? "mipsisa64r6" : "mips64") +
  "-linux-" + (IsMipsN32Abi ? "gnuabin32" : "gnuabi64");
-if (D.getVFS().exists(SysRoot + "/lib/" + MT))
+if (D.getVFS().exists(concat(SysRoot, "/lib", MT)))
   return MT;
-if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu"))
+if (D.getVFS().exists(concat(SysRoot, "/lib/mips64-linux-gnu")))
   return "mips64-linux-gnu";
 break;
   }
@@ -108,14 +108,14 @@
   return "mips64el-linux-android";
 std::string MT = std::string(IsMipsR6 ? "mipsisa64r6el" : "mips64el") +
  "-linux-" + (IsMipsN32Abi ? "gnuabin32" : "gnuabi64");
-if (D.getVFS().exists(SysRoot + "/lib/" + MT))
+if (D.getVFS().exists(concat(SysRoot, "/lib", MT)))
   return MT;
-if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu"))
+if (D.getVFS().exists(concat(SysRoot, "/lib/mips64el-linux-gnu")))
   return "mips64el-linux-gnu";
 break;
   }
   case llvm::Triple::ppc:
-if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe"))
+if (D.getVFS().exists(concat(SysRoot, "/lib/powerpc-linux-gnuspe")))
   return "powerpc-linux-gnuspe";
 return "powerpc-linux-gnu";
   case 

[PATCH] D126289: [Clang][Driver] Fix include paths for `--sysroot /` on Linux

2022-05-27 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 432568.
egorzhdan marked an inline comment as done.
egorzhdan added a comment.

Rebase & fix formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126289

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/Inputs/basic_linux_libstdcxx_tree/usr/bin/.keep
  
clang/test/Driver/Inputs/basic_linux_libstdcxx_tree/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/crtbegin.o
  clang/test/Driver/linux-header-search.cpp

Index: clang/test/Driver/linux-header-search.cpp
===
--- clang/test/Driver/linux-header-search.cpp
+++ clang/test/Driver/linux-header-search.cpp
@@ -16,6 +16,22 @@
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/x86_64-unknown-linux-gnu/c++/v1"
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+
+// Test include paths when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/x86_64-unknown-linux-gnu/c++/v1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/local/include"
+
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
 // RUN: -stdlib=libc++ \
@@ -56,7 +72,20 @@
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/x86_64-unknown-linux-gnu/c++/v2"
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v2"
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
-//
+
+// Test Linux with libstdc++ when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libstdc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libstdcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/../../../../x86_64-unknown-linux-gnu/include"
+
 // Test Linux with both libc++ and libstdc++ installed.
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -97,9 +97,9 @@
   case llvm::Triple::mips64: {
 std::string MT = std::string(IsMipsR6 ? "mipsisa64r6" : "mips64") +
  "-linux-" + (IsMipsN32Abi ? "gnuabin32" : "gnuabi64");
-if (D.getVFS().exists(SysRoot + "/lib/" + MT))
+if (D.getVFS().exists(concat(SysRoot, "/lib", MT)))
   return MT;
-if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu"))
+if (D.getVFS().exists(concat(SysRoot, "/lib/mips64-linux-gnu")))
   return "mips64-linux-gnu";
 break;
   }
@@ -108,14 +108,14 @@
   return "mips64el-linux-android";
 std::string MT = std::string(IsMipsR6 ? "mipsisa64r6el" : "mips64el") +
  "-linux-" + (IsMipsN32Abi ? "gnuabin32" : "gnuabi64");
-if (D.getVFS().exists(SysRoot + "/lib/" + MT))
+if (D.getVFS().exists(concat(SysRoot, "/lib", MT)))
   return MT;
-if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu"))
+if (D.getVFS().exists(concat(SysRoot, "/lib/mips64el-linux-gnu")))
   return "mips64el-linux-gnu";
 break;
   }
   case llvm::Triple::ppc:
-if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe"))
+if (D.getVFS().exists(concat(SysRoot, "/lib/powerpc-linux-gnuspe")))
   return "powerpc-linux-gnuspe";
 return "powerpc-linux-gnu";
   case llvm::Triple::ppcle:
@@ -269,13 +269,13 @@
   // 

[PATCH] D126289: [Clang][Driver] Fix include paths for `--sysroot /` on Linux

2022-05-27 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan marked 2 inline comments as done.
egorzhdan added inline comments.



Comment at: clang/lib/Driver/ToolChain.cpp:917
 
+/*static*/ std::string ToolChain::concat(const std::string ,
+ const Twine , const Twine ,

MaskRay wrote:
> I think the first argument of `concat` should be `StringRef`, then we can 
> avoid changing the signature of `getMultiarchTriple`
You're right, thanks!



Comment at: clang/test/Driver/linux-header-search.cpp:76
+
+// Test Linux with libstdc++.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \

MaskRay wrote:
> I suspect this test does not add more coverage than linux-cross.cpp.
> 
> To test --sysroot with a trailing `/`, just modify the previous 
> `CHECK-BASIC-LIBCXXV2` by appending a `/`
`CHECK-BASIC-LIBCXXV2 ` is not quite the same: I'd like to test the libstdc++ 
detection logic (e.g. `GCCInstallationDetector`) which doesn't get invoked for 
libc++.

I removed the unnecessary test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126289

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


[PATCH] D126289: [Clang][Driver] Fix include paths for `--sysroot /` on Linux

2022-05-27 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 432539.
egorzhdan added a comment.

- Change arg type from `std::string` to `StringRef`
- Remove unnecessary `//`

• Remove unneeded test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126289

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/Inputs/basic_linux_libstdcxx_tree/usr/bin/.keep
  
clang/test/Driver/Inputs/basic_linux_libstdcxx_tree/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/crtbegin.o
  clang/test/Driver/linux-header-search.cpp

Index: clang/test/Driver/linux-header-search.cpp
===
--- clang/test/Driver/linux-header-search.cpp
+++ clang/test/Driver/linux-header-search.cpp
@@ -16,6 +16,22 @@
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/x86_64-unknown-linux-gnu/c++/v1"
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+
+// Test include paths when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/x86_64-unknown-linux-gnu/c++/v1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/local/include"
+
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
 // RUN: -stdlib=libc++ \
@@ -56,7 +72,20 @@
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/x86_64-unknown-linux-gnu/c++/v2"
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v2"
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
-//
+
+// Test Linux with libstdc++ when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libstdc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libstdcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/../../../../x86_64-unknown-linux-gnu/include"
+
 // Test Linux with both libc++ and libstdc++ installed.
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -97,9 +97,9 @@
   case llvm::Triple::mips64: {
 std::string MT = std::string(IsMipsR6 ? "mipsisa64r6" : "mips64") +
  "-linux-" + (IsMipsN32Abi ? "gnuabin32" : "gnuabi64");
-if (D.getVFS().exists(SysRoot + "/lib/" + MT))
+if (D.getVFS().exists(concat(SysRoot, "/lib", MT)))
   return MT;
-if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu"))
+if (D.getVFS().exists(concat(SysRoot, "/lib/mips64-linux-gnu")))
   return "mips64-linux-gnu";
 break;
   }
@@ -108,14 +108,14 @@
   return "mips64el-linux-android";
 std::string MT = std::string(IsMipsR6 ? "mipsisa64r6el" : "mips64el") +
  "-linux-" + (IsMipsN32Abi ? "gnuabin32" : "gnuabi64");
-if (D.getVFS().exists(SysRoot + "/lib/" + MT))
+if (D.getVFS().exists(concat(SysRoot, "/lib", MT)))
   return MT;
-if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu"))
+if (D.getVFS().exists(concat(SysRoot, "/lib/mips64el-linux-gnu")))
   return "mips64el-linux-gnu";
 break;
   }
   case llvm::Triple::ppc:
-if (D.getVFS().exists(SysRoot + "/lib/powerpc-linux-gnuspe"))
+if (D.getVFS().exists(concat(SysRoot, "/lib/powerpc-linux-gnuspe")))
   return "powerpc-linux-gnuspe";
 return "powerpc-linux-gnu";
   case 

[PATCH] D126289: [Clang][Driver] Fix include paths for `--sysroot /` on Linux

2022-05-26 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 432256.
egorzhdan added a comment.

- Remove unnecessary trailing `/`
- Add `-SAME` in tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126289

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Hurd.cpp
  clang/lib/Driver/ToolChains/Hurd.h
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/lib/Driver/ToolChains/WebAssembly.h
  clang/test/Driver/Inputs/basic_linux_libstdcxx_tree/usr/bin/.keep
  
clang/test/Driver/Inputs/basic_linux_libstdcxx_tree/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/crtbegin.o
  clang/test/Driver/linux-header-search.cpp

Index: clang/test/Driver/linux-header-search.cpp
===
--- clang/test/Driver/linux-header-search.cpp
+++ clang/test/Driver/linux-header-search.cpp
@@ -16,6 +16,22 @@
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/x86_64-unknown-linux-gnu/c++/v1"
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+//
+// Test include paths when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/x86_64-unknown-linux-gnu/c++/v1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/local/include"
+//
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
 // RUN: -stdlib=libc++ \
@@ -56,6 +72,32 @@
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/x86_64-unknown-linux-gnu/c++/v2"
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v2"
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+
+// Test Linux with libstdc++.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libstdc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libstdcxx_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBSTDCXX-SYSROOT %s
+// CHECK-BASIC-LIBSTDCXX-SYSROOT: "-cc1"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SAME: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SAME: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/../../../../x86_64-unknown-linux-gnu/include"
+//
+// Test Linux with libstdc++ when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libstdc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libstdcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH-SAME: "-internal-isystem" "[[SYSROOT]]usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/../../../../x86_64-unknown-linux-gnu/include"
 //
 // Test Linux with both libc++ and libstdc++ installed.
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
Index: clang/lib/Driver/ToolChains/WebAssembly.h
===
--- clang/lib/Driver/ToolChains/WebAssembly.h
+++ clang/lib/Driver/ToolChains/WebAssembly.h
@@ -78,7 +78,7 @@
 
   std::string getMultiarchTriple(const Driver ,
  const llvm::Triple ,
- StringRef SysRoot) const override;
+ const std::string ) const override;
 
   void addLibCxxIncludePaths(const llvm::opt::ArgList ,
  llvm::opt::ArgStringList ) const;
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp

[PATCH] D126289: [Clang][Driver] Fix include paths for `--sysroot /` on Linux

2022-05-25 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added inline comments.



Comment at: clang/include/clang/Driver/ToolChain.h:219
+
+  static std::string concat(const std::string , const Twine ,
+const Twine  = "", const Twine  = "",

MaskRay wrote:
> This can use `llvm::sys::path::append`
The implementation of this already uses `llvm::sys::path::append`, do you mean 
replacing the usages of `concat` with `llvm::sys::path::append`?
That would produce quite a lot of boilerplate I think, since 
`llvm::sys::path::append` modifies the path in-place, so every call to `concat` 
would expand into 3 lines of code. Also it would be very easy to forget to pass 
`Style::posix` and cause incorrect behavior on Windows (something I've stumbled 
upon while making this patch).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126289

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


[PATCH] D126031: [libclang] add supporting for indexing/visiting C++ concepts

2022-05-24 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan accepted this revision.
egorzhdan added a comment.
This revision is now accepted and ready to land.

I'm not super familiar with concepts but this LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126031

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


[PATCH] D126289: [Clang][Driver] Fix include paths for `--sysroot /` on Linux

2022-05-24 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
Herald added subscribers: pmatos, asb, jgravelle-google, sbc100, dschuff.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, aheejin.
Herald added a project: clang.

Currently if `--sysroot /` is passed to the Clang driver, the include paths 
generated by the Clang driver will start with a double slash: 
`//usr/include/...`.
 If VFS is used to inject files into the include paths (for example, the Swift 
compiler does this), VFS will get confused and the injected files won't be 
visible.

This change makes sure that the include paths start with a single slash.

Fixes #28283.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126289

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Hurd.cpp
  clang/lib/Driver/ToolChains/Hurd.h
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/lib/Driver/ToolChains/WebAssembly.h
  clang/test/Driver/Inputs/basic_linux_libstdcxx_tree/usr/bin/.keep
  
clang/test/Driver/Inputs/basic_linux_libstdcxx_tree/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/crtbegin.o
  clang/test/Driver/linux-header-search.cpp

Index: clang/test/Driver/linux-header-search.cpp
===
--- clang/test/Driver/linux-header-search.cpp
+++ clang/test/Driver/linux-header-search.cpp
@@ -16,6 +16,22 @@
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/x86_64-unknown-linux-gnu/c++/v1"
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
 // CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+//
+// Test include paths when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH: "-internal-isystem" "[[SYSROOT]]usr/include/x86_64-unknown-linux-gnu/c++/v1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH: "-internal-isystem" "[[SYSROOT]]usr/include/c++/v1"
+// CHECK-BASIC-LIBCXX-SYSROOT-SLASH: "-internal-isystem" "[[SYSROOT]]usr/local/include"
+//
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
 // RUN: --target=x86_64-unknown-linux-gnu \
 // RUN: -stdlib=libc++ \
@@ -56,6 +72,32 @@
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/x86_64-unknown-linux-gnu/c++/v2"
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v2"
 // CHECK-BASIC-LIBCXXV2-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+
+// Test Linux with libstdc++.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libstdc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libstdcxx_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBSTDCXX-SYSROOT %s
+// CHECK-BASIC-LIBSTDCXX-SYSROOT: "-cc1"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/../../../../x86_64-unknown-linux-gnu/include"
+//
+// Test Linux with libstdc++ when the sysroot path ends with `/`.
+// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -stdlib=libstdc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_libstdcxx_tree/ \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH %s
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH: "-cc1"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH: "-isysroot" "[[SYSROOT:[^"]+/]]"
+// CHECK-BASIC-LIBSTDCXX-SYSROOT-SLASH: "-internal-isystem" "[[SYSROOT]]usr/lib/gcc/x86_64-unknown-linux-gnu/4.8/../../../../x86_64-unknown-linux-gnu/include"
 //
 // Test Linux with both libc++ and libstdc++ installed.
 // RUN: %clang -### %s -fsyntax-only 2>&1 \
Index: clang/lib/Driver/ToolChains/WebAssembly.h
===
--- clang/lib/Driver/ToolChains/WebAssembly.h
+++ clang/lib/Driver/ToolChains/WebAssembly.h
@@ -78,7 +78,7 @@
 

[PATCH] D126031: [libclang] add supporting for indexing/visiting C++ concepts

2022-05-20 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

Looks like `index-concepts.cpp` is failing on Windows, @arphaman could you 
please take a look?


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

https://reviews.llvm.org/D126031

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


[PATCH] D121911: [Clang] Add DriverKit support

2022-05-13 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2f04e703bff3: [Clang] Add DriverKit support (authored by 
egorzhdan).

Changed prior to commit:
  https://reviews.llvm.org/D121911?vs=429025=429328#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121911

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/LangStandards.cpp
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/test/CodeGen/availability-check-driverkit.c
  clang/test/Driver/Inputs/DriverKit19.0.sdk/SDKSettings.plist
  clang/test/Driver/Inputs/DriverKit19.0.sdk/System/DriverKit/usr/include/.keep
  
clang/test/Driver/Inputs/basic_darwin_driverkit_sdk_usr_cxx_v1/System/DriverKit/usr/include/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_darwin_driverkit_sdk_usr_cxx_v1/System/DriverKit/usr/lib/.keep
  clang/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.driverkit.a
  clang/test/Driver/darwin-ld-platform-version-driverkit.c
  clang/test/Driver/darwin-ld.c
  clang/test/Driver/darwin-version.c
  clang/test/Driver/debug-options.c
  clang/test/Driver/driverkit-arm64.c
  clang/test/Driver/driverkit-arm64e.c
  clang/test/Driver/driverkit-armv7k.s
  clang/test/Driver/driverkit-cplusplus.cpp
  clang/test/Driver/driverkit-exceptions.cpp
  clang/test/Driver/driverkit-framework.c
  clang/test/Driver/driverkit-rtti.cpp
  clang/test/Driver/driverkit-target-cpu.c
  clang/test/Driver/driverkit-version-min.c
  clang/test/Driver/incompatible_sysroot.c
  clang/test/Driver/instrprof-ld.c
  clang/test/Driver/pic.c
  clang/test/Driver/stack-protector.c
  clang/test/Frontend/darwin-version.c
  clang/test/Preprocessor/arm-target-features.c
  clang/test/Sema/attr-availability-driverkit.c

Index: clang/test/Sema/attr-availability-driverkit.c
===
--- /dev/null
+++ clang/test/Sema/attr-availability-driverkit.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 "-triple" "x86_64-apple-driverkit20.0" -fsyntax-only -verify %s
+
+void f0(int) __attribute__((availability(driverkit,introduced=19.0,deprecated=20.0))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(driverkit,introduced=20.0)));
+void f2(int) __attribute__((availability(driverkit,introduced=19.0,deprecated=20.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(driverkit,introduced=20.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(driverkit,introduced=19.0,deprecated=19.5,obsoleted=20.0))); // expected-note{{explicitly marked unavailable}}
+
+void f5(int) __attribute__((availability(driverkit,introduced=19.0))) __attribute__((availability(driverkit,deprecated=20.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(driverkit,deprecated=20.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f7(int) __attribute__((availability(driverkit,introduced=19.0)));
+
+void test() {
+  f0(0); // expected-warning{{'f0' is deprecated: first deprecated in DriverKit 20.0}}
+  f1(0);
+  f2(0); // expected-warning{{'f2' is deprecated: first deprecated in DriverKit 20.0}}
+  f3(0);
+  f4(0); // expected-error{{f4' is unavailable: obsoleted in DriverKit 20.0}}
+  f5(0); // expected-warning{{'f5' is deprecated: first deprecated in DriverKit 20.0}}
+  f6(0); // expected-warning{{'f6' is deprecated: first deprecated in DriverKit 20.0}}
+  f7(0);
+}
Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -834,6 +834,9 @@
 // CHECK-V82A: #define __ARM_FEATURE_QRDMX 1
 // CHECK-V82A: #define __ARM_FP 0xe
 
+// RUN: %clang -target armv7-apple-driverkit21.0 -x c %s -dM -E -o - | FileCheck -match-full-lines --check-prefix=CHECK-DRIVERKIT %s
+// CHECK-DRIVERKIT-NOT: #define __ARM_PCS_VFP 1
+
 // RUN: %clang -target armv8.3a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V83A %s
 // CHECK-V83A: #define __ARM_ARCH 8
 // CHECK-V83A: #define __ARM_ARCH_8_3A__ 1
Index: clang/test/Frontend/darwin-version.c

[PATCH] D121911: [Clang] Add DriverKit support

2022-05-12 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 429025.
egorzhdan added a comment.

Remove static analyzer changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121911

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/availability-check-driverkit.c
  clang/test/Driver/Inputs/DriverKit19.0.sdk/SDKSettings.plist
  clang/test/Driver/Inputs/DriverKit19.0.sdk/System/DriverKit/usr/include/.keep
  
clang/test/Driver/Inputs/basic_darwin_driverkit_sdk_usr_cxx_v1/System/DriverKit/usr/include/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_darwin_driverkit_sdk_usr_cxx_v1/System/DriverKit/usr/lib/.keep
  clang/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.driverkit.a
  clang/test/Driver/darwin-ld-platform-version-driverkit.c
  clang/test/Driver/darwin-ld.c
  clang/test/Driver/darwin-version.c
  clang/test/Driver/debug-options.c
  clang/test/Driver/driverkit-arm64.c
  clang/test/Driver/driverkit-arm64e.c
  clang/test/Driver/driverkit-armv7k.s
  clang/test/Driver/driverkit-cplusplus.cpp
  clang/test/Driver/driverkit-exceptions.cpp
  clang/test/Driver/driverkit-framework.c
  clang/test/Driver/driverkit-rtti.cpp
  clang/test/Driver/driverkit-target-cpu.c
  clang/test/Driver/driverkit-version-min.c
  clang/test/Driver/incompatible_sysroot.c
  clang/test/Driver/instrprof-ld.c
  clang/test/Driver/pic.c
  clang/test/Driver/stack-protector.c
  clang/test/Frontend/darwin-version.c
  clang/test/Preprocessor/arm-target-features.c
  clang/test/Sema/attr-availability-driverkit.c

Index: clang/test/Sema/attr-availability-driverkit.c
===
--- /dev/null
+++ clang/test/Sema/attr-availability-driverkit.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 "-triple" "x86_64-apple-driverkit20.0" -fsyntax-only -verify %s
+
+void f0(int) __attribute__((availability(driverkit,introduced=19.0,deprecated=20.0))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(driverkit,introduced=20.0)));
+void f2(int) __attribute__((availability(driverkit,introduced=19.0,deprecated=20.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(driverkit,introduced=20.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(driverkit,introduced=19.0,deprecated=19.5,obsoleted=20.0))); // expected-note{{explicitly marked unavailable}}
+
+void f5(int) __attribute__((availability(driverkit,introduced=19.0))) __attribute__((availability(driverkit,deprecated=20.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(driverkit,deprecated=20.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f7(int) __attribute__((availability(driverkit,introduced=19.0)));
+
+void test() {
+  f0(0); // expected-warning{{'f0' is deprecated: first deprecated in DriverKit 20.0}}
+  f1(0);
+  f2(0); // expected-warning{{'f2' is deprecated: first deprecated in DriverKit 20.0}}
+  f3(0);
+  f4(0); // expected-error{{f4' is unavailable: obsoleted in DriverKit 20.0}}
+  f5(0); // expected-warning{{'f5' is deprecated: first deprecated in DriverKit 20.0}}
+  f6(0); // expected-warning{{'f6' is deprecated: first deprecated in DriverKit 20.0}}
+  f7(0);
+}
Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -834,6 +834,9 @@
 // CHECK-V82A: #define __ARM_FEATURE_QRDMX 1
 // CHECK-V82A: #define __ARM_FP 0xe
 
+// RUN: %clang -target armv7-apple-driverkit21.0 -x c %s -dM -E -o - | FileCheck -match-full-lines --check-prefix=CHECK-DRIVERKIT %s
+// CHECK-DRIVERKIT-NOT: #define __ARM_PCS_VFP 1
+
 // RUN: %clang -target armv8.3a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V83A %s
 // CHECK-V83A: #define __ARM_ARCH 8
 // CHECK-V83A: #define __ARM_ARCH_8_3A__ 1
Index: clang/test/Frontend/darwin-version.c
===
--- clang/test/Frontend/darwin-version.c
+++ clang/test/Frontend/darwin-version.c
@@ -51,3 +51,8 @@
 // RUN: grep 

[PATCH] D122232: [clang][NFC] Refactor logic for picking standard library on Apple

2022-03-22 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan accepted this revision.
egorzhdan added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122232

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


[PATCH] D121911: [Clang] Add DriverKit support

2022-03-21 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 416920.
egorzhdan added a comment.

Fix clang-format warnings


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121911

Files:
  clang/include/clang/Analysis/RetainSummaryManager.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Driver/Options.td
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Analysis/driverkit_base.h
  clang/test/Analysis/retain-release-driverkit.cpp
  clang/test/CodeGen/availability-check-driverkit.c
  clang/test/Driver/Inputs/DriverKit19.0.sdk/SDKSettings.plist
  clang/test/Driver/Inputs/DriverKit19.0.sdk/System/DriverKit/usr/include/.keep
  
clang/test/Driver/Inputs/basic_darwin_driverkit_sdk_usr_cxx_v1/System/DriverKit/usr/include/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_darwin_driverkit_sdk_usr_cxx_v1/System/DriverKit/usr/lib/.keep
  clang/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.driverkit.a
  clang/test/Driver/darwin-ld-platform-version-driverkit.c
  clang/test/Driver/darwin-ld.c
  clang/test/Driver/darwin-version.c
  clang/test/Driver/debug-options.c
  clang/test/Driver/driverkit-arm64.c
  clang/test/Driver/driverkit-arm64e.c
  clang/test/Driver/driverkit-armv7k.s
  clang/test/Driver/driverkit-cplusplus.cpp
  clang/test/Driver/driverkit-exceptions.cpp
  clang/test/Driver/driverkit-framework.c
  clang/test/Driver/driverkit-rtti.cpp
  clang/test/Driver/driverkit-target-cpu.c
  clang/test/Driver/driverkit-version-min.c
  clang/test/Driver/incompatible_sysroot.c
  clang/test/Driver/instrprof-ld.c
  clang/test/Driver/pic.c
  clang/test/Driver/stack-protector.c
  clang/test/Frontend/darwin-version.c
  clang/test/Preprocessor/arm-target-features.c
  clang/test/Sema/attr-availability-driverkit.c

Index: clang/test/Sema/attr-availability-driverkit.c
===
--- /dev/null
+++ clang/test/Sema/attr-availability-driverkit.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 "-triple" "x86_64-apple-driverkit20.0" -fsyntax-only -verify %s
+
+void f0(int) __attribute__((availability(driverkit,introduced=19.0,deprecated=20.0))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(driverkit,introduced=20.0)));
+void f2(int) __attribute__((availability(driverkit,introduced=19.0,deprecated=20.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(driverkit,introduced=20.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(driverkit,introduced=19.0,deprecated=19.5,obsoleted=20.0))); // expected-note{{explicitly marked unavailable}}
+
+void f5(int) __attribute__((availability(driverkit,introduced=19.0))) __attribute__((availability(driverkit,deprecated=20.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(driverkit,deprecated=20.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f7(int) __attribute__((availability(driverkit,introduced=19.0)));
+
+void test() {
+  f0(0); // expected-warning{{'f0' is deprecated: first deprecated in DriverKit 20.0}}
+  f1(0);
+  f2(0); // expected-warning{{'f2' is deprecated: first deprecated in DriverKit 20.0}}
+  f3(0);
+  f4(0); // expected-error{{f4' is unavailable: obsoleted in DriverKit 20.0}}
+  f5(0); // expected-warning{{'f5' is deprecated: first deprecated in DriverKit 20.0}}
+  f6(0); // expected-warning{{'f6' is deprecated: first deprecated in DriverKit 20.0}}
+  f7(0);
+}
Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -834,6 +834,9 @@
 // CHECK-V82A: #define __ARM_FEATURE_QRDMX 1
 // CHECK-V82A: #define __ARM_FP 0xe
 
+// RUN: %clang -target armv7-apple-driverkit21.0 -x c %s -dM -E -o - | FileCheck -match-full-lines --check-prefix=CHECK-DRIVERKIT %s
+// CHECK-DRIVERKIT-NOT: #define __ARM_PCS_VFP 1
+
 // RUN: %clang -target armv8.3a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V83A %s
 // CHECK-V83A: #define __ARM_ARCH 8
 // CHECK-V83A: #define __ARM_ARCH_8_3A__ 1
Index: clang/test/Frontend/darwin-version.c

[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-18 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

In D121283#3392137 , @thakis wrote:

> The commit message got a bit mutilated: 
> 33a9eac6aaa495fce6fd9b17cd48aa57a95461e6 
> 
>
> Just FYI in case you didn't notice. In that case, update your commit workflow 
> to make sure this doesn't happen next time :)

That's strange, I didn't notice this, thanks for the heads up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121283

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


[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-18 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33a9eac6aaa4: [Clang] Support multiple attributes in a 
single pragma (authored by egorzhdan).

Changed prior to commit:
  https://reviews.llvm.org/D121283?vs=416279=416469#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121283

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/AttrSubjectMatchRules.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/test/AST/pragma-multiple-attributes-declspec.cpp
  clang/test/AST/pragma-multiple-attributes.cpp
  clang/test/FixIt/fixit-pragma-attribute.c
  clang/test/FixIt/fixit-pragma-attribute.cpp
  clang/test/Parser/pragma-attribute-declspec.cpp
  clang/test/Parser/pragma-attribute.cpp

Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -154,9 +154,6 @@
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=any(function))
 #pragma clang attribute pop
 
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=namespace)
 #pragma clang attribute pop
 
@@ -210,3 +207,13 @@
 #pragma clang attribute push([[clang::uninitialized]], apply_to=any) // expected-error {{expected '('}}
 #pragma clang attribute push([[clang::uninitialized]], apply_to = any()) // expected-error {{expected an identifier that corresponds to an attribute subject rule}}
 // NB: neither of these need to be popped; they were never successfully pushed.
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls, annotate("test"))), apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls,)), apply_to = function) // expected-error {{expected identifier that represents an attribute name}}
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{expected ','}}
Index: clang/test/Parser/pragma-attribute-declspec.cpp
===
--- clang/test/Parser/pragma-attribute-declspec.cpp
+++ clang/test/Parser/pragma-attribute-declspec.cpp
@@ -6,7 +6,8 @@
 
 #pragma clang attribute pop
 
-#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
+#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function)
+#pragma clang attribute pop
 
 #pragma clang attribute push(__declspec(align), apply_to = variable) // expected-error {{attribute 'align' is not supported by '#pragma clang attribute'}}
 
Index: clang/test/FixIt/fixit-pragma-attribute.cpp
===
--- clang/test/FixIt/fixit-pragma-attribute.cpp
+++ clang/test/FixIt/fixit-pragma-attribute.cpp
@@ -39,7 +39,7 @@
 #pragma clang attribute pop
 
 #pragma clang attribute push (__attribute__((abi_tag("a"
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) apply_to=function)
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", "
 #pragma clang attribute push (__attribute__((abi_tag("a"))) = function)
@@ -48,36 +48,39 @@
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = "
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))) 22)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) function)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:69}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:69}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute 

[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-17 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 416279.
egorzhdan added a comment.

- Fix off-by-one error in fix-it generation logic: the last SubjectMatchRule

(`SubjectMatchRule_variable_not_is_parameter`) was not handled properly

- Add a test for this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121283

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/AttrSubjectMatchRules.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/test/AST/pragma-multiple-attributes-declspec.cpp
  clang/test/AST/pragma-multiple-attributes.cpp
  clang/test/FixIt/fixit-pragma-attribute.c
  clang/test/FixIt/fixit-pragma-attribute.cpp
  clang/test/Parser/pragma-attribute-declspec.cpp
  clang/test/Parser/pragma-attribute.cpp

Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -154,9 +154,6 @@
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=any(function))
 #pragma clang attribute pop
 
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=namespace)
 #pragma clang attribute pop
 
@@ -210,3 +207,13 @@
 #pragma clang attribute push([[clang::uninitialized]], apply_to=any) // expected-error {{expected '('}}
 #pragma clang attribute push([[clang::uninitialized]], apply_to = any()) // expected-error {{expected an identifier that corresponds to an attribute subject rule}}
 // NB: neither of these need to be popped; they were never successfully pushed.
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls, annotate("test"))), apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls,)), apply_to = function) // expected-error {{expected identifier that represents an attribute name}}
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{expected ','}}
Index: clang/test/Parser/pragma-attribute-declspec.cpp
===
--- clang/test/Parser/pragma-attribute-declspec.cpp
+++ clang/test/Parser/pragma-attribute-declspec.cpp
@@ -6,7 +6,8 @@
 
 #pragma clang attribute pop
 
-#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
+#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function)
+#pragma clang attribute pop
 
 #pragma clang attribute push(__declspec(align), apply_to = variable) // expected-error {{attribute 'align' is not supported by '#pragma clang attribute'}}
 
Index: clang/test/FixIt/fixit-pragma-attribute.cpp
===
--- clang/test/FixIt/fixit-pragma-attribute.cpp
+++ clang/test/FixIt/fixit-pragma-attribute.cpp
@@ -39,7 +39,7 @@
 #pragma clang attribute pop
 
 #pragma clang attribute push (__attribute__((abi_tag("a"
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) apply_to=function)
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", "
 #pragma clang attribute push (__attribute__((abi_tag("a"))) = function)
@@ -48,36 +48,39 @@
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = "
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))) 22)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) function)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:69}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:69}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) (function))
-// CHECK: 

[PATCH] D121911: [Clang] Add DriverKit support

2022-03-17 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
egorzhdan added a reviewer: arphaman.
Herald added a reviewer: aaron.ballman.
Herald added subscribers: dexonsmith, zzheng.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is the second patch that upstreams the support for Apple's DriverKit.

The first patch: https://reviews.llvm.org/D118046.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121911

Files:
  clang/include/clang/Analysis/RetainSummaryManager.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Driver/Options.td
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Analysis/driverkit_base.h
  clang/test/Analysis/retain-release-driverkit.cpp
  clang/test/CodeGen/availability-check-driverkit.c
  clang/test/Driver/Inputs/DriverKit19.0.sdk/SDKSettings.plist
  clang/test/Driver/Inputs/DriverKit19.0.sdk/System/DriverKit/usr/include/.keep
  
clang/test/Driver/Inputs/basic_darwin_driverkit_sdk_usr_cxx_v1/System/DriverKit/usr/include/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_darwin_driverkit_sdk_usr_cxx_v1/System/DriverKit/usr/lib/.keep
  clang/test/Driver/Inputs/resource_dir/lib/darwin/libclang_rt.driverkit.a
  clang/test/Driver/darwin-ld-platform-version-driverkit.c
  clang/test/Driver/darwin-ld.c
  clang/test/Driver/darwin-version.c
  clang/test/Driver/debug-options.c
  clang/test/Driver/driverkit-arm64.c
  clang/test/Driver/driverkit-arm64e.c
  clang/test/Driver/driverkit-armv7k.s
  clang/test/Driver/driverkit-cplusplus.cpp
  clang/test/Driver/driverkit-exceptions.cpp
  clang/test/Driver/driverkit-framework.c
  clang/test/Driver/driverkit-rtti.cpp
  clang/test/Driver/driverkit-target-cpu.c
  clang/test/Driver/driverkit-version-min.c
  clang/test/Driver/incompatible_sysroot.c
  clang/test/Driver/instrprof-ld.c
  clang/test/Driver/pic.c
  clang/test/Driver/stack-protector.c
  clang/test/Frontend/darwin-version.c
  clang/test/Preprocessor/arm-target-features.c
  clang/test/Sema/attr-availability-driverkit.c

Index: clang/test/Sema/attr-availability-driverkit.c
===
--- /dev/null
+++ clang/test/Sema/attr-availability-driverkit.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 "-triple" "x86_64-apple-driverkit20.0" -fsyntax-only -verify %s
+
+void f0(int) __attribute__((availability(driverkit,introduced=19.0,deprecated=20.0))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(driverkit,introduced=20.0)));
+void f2(int) __attribute__((availability(driverkit,introduced=19.0,deprecated=20.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(driverkit,introduced=20.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(driverkit,introduced=19.0,deprecated=19.5,obsoleted=20.0))); // expected-note{{explicitly marked unavailable}}
+
+void f5(int) __attribute__((availability(driverkit,introduced=19.0))) __attribute__((availability(driverkit,deprecated=20.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(driverkit,deprecated=20.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f7(int) __attribute__((availability(driverkit,introduced=19.0)));
+
+void test() {
+  f0(0); // expected-warning{{'f0' is deprecated: first deprecated in DriverKit 20.0}}
+  f1(0);
+  f2(0); // expected-warning{{'f2' is deprecated: first deprecated in DriverKit 20.0}}
+  f3(0);
+  f4(0); // expected-error{{f4' is unavailable: obsoleted in DriverKit 20.0}}
+  f5(0); // expected-warning{{'f5' is deprecated: first deprecated in DriverKit 20.0}}
+  f6(0); // expected-warning{{'f6' is deprecated: first deprecated in DriverKit 20.0}}
+  f7(0);
+}
Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -834,6 +834,9 @@
 // CHECK-V82A: #define __ARM_FEATURE_QRDMX 1
 // CHECK-V82A: #define __ARM_FP 0xe
 
+// RUN: %clang -target armv7-apple-driverkit21.0 -x c %s -dM -E -o - | FileCheck -match-full-lines --check-prefix=CHECK-DRIVERKIT %s
+// CHECK-DRIVERKIT-NOT: #define __ARM_PCS_VFP 1
+
 // RUN: 

[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-15 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

Thanks for the review @aaron.ballman!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121283

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


[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-15 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 415527.
egorzhdan added a comment.

Merge two test files into one to speed up testing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121283

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/AttrSubjectMatchRules.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/test/AST/pragma-multiple-attributes-declspec.cpp
  clang/test/AST/pragma-multiple-attributes.cpp
  clang/test/FixIt/fixit-pragma-attribute.c
  clang/test/FixIt/fixit-pragma-attribute.cpp
  clang/test/Parser/pragma-attribute-declspec.cpp
  clang/test/Parser/pragma-attribute.cpp

Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -154,9 +154,6 @@
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=any(function))
 #pragma clang attribute pop
 
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=namespace)
 #pragma clang attribute pop
 
@@ -210,3 +207,13 @@
 #pragma clang attribute push([[clang::uninitialized]], apply_to=any) // expected-error {{expected '('}}
 #pragma clang attribute push([[clang::uninitialized]], apply_to = any()) // expected-error {{expected an identifier that corresponds to an attribute subject rule}}
 // NB: neither of these need to be popped; they were never successfully pushed.
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls, annotate("test"))), apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls,)), apply_to = function) // expected-error {{expected identifier that represents an attribute name}}
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{expected ','}}
Index: clang/test/Parser/pragma-attribute-declspec.cpp
===
--- clang/test/Parser/pragma-attribute-declspec.cpp
+++ clang/test/Parser/pragma-attribute-declspec.cpp
@@ -6,7 +6,8 @@
 
 #pragma clang attribute pop
 
-#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
+#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function)
+#pragma clang attribute pop
 
 #pragma clang attribute push(__declspec(align), apply_to = variable) // expected-error {{attribute 'align' is not supported by '#pragma clang attribute'}}
 
Index: clang/test/FixIt/fixit-pragma-attribute.cpp
===
--- clang/test/FixIt/fixit-pragma-attribute.cpp
+++ clang/test/FixIt/fixit-pragma-attribute.cpp
@@ -39,7 +39,7 @@
 #pragma clang attribute pop
 
 #pragma clang attribute push (__attribute__((abi_tag("a"
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) apply_to=function)
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", "
 #pragma clang attribute push (__attribute__((abi_tag("a"))) = function)
@@ -48,35 +48,35 @@
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = "
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))) 22)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) function)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:69}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:69}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) (function))
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:71}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: 

[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-14 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 415199.
egorzhdan added a comment.

- Only allow one attribute syntax style per directive
- Adjust documentation
- Add a release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121283

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/AttrSubjectMatchRules.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/test/AST/pragma-multiple-attributes-declspec.cpp
  clang/test/AST/pragma-multiple-attributes.cpp
  clang/test/FixIt/fixit-pragma-attribute.c
  clang/test/FixIt/fixit-pragma-attribute.cpp
  clang/test/Parser/pragma-attribute-declspec.cpp
  clang/test/Parser/pragma-attribute.cpp
  clang/test/Parser/pragma-multiple-attributes.cpp

Index: clang/test/Parser/pragma-multiple-attributes.cpp
===
--- /dev/null
+++ clang/test/Parser/pragma-multiple-attributes.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -Wno-pragma-clang-attribute -verify %s
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls, annotate("test"))), apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls,)), apply_to = function) // expected-error {{expected identifier that represents an attribute name}}
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{expected ','}}
Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -154,9 +154,6 @@
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=any(function))
 #pragma clang attribute pop
 
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=namespace)
 #pragma clang attribute pop
 
Index: clang/test/Parser/pragma-attribute-declspec.cpp
===
--- clang/test/Parser/pragma-attribute-declspec.cpp
+++ clang/test/Parser/pragma-attribute-declspec.cpp
@@ -6,7 +6,8 @@
 
 #pragma clang attribute pop
 
-#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
+#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function)
+#pragma clang attribute pop
 
 #pragma clang attribute push(__declspec(align), apply_to = variable) // expected-error {{attribute 'align' is not supported by '#pragma clang attribute'}}
 
Index: clang/test/FixIt/fixit-pragma-attribute.cpp
===
--- clang/test/FixIt/fixit-pragma-attribute.cpp
+++ clang/test/FixIt/fixit-pragma-attribute.cpp
@@ -39,7 +39,7 @@
 #pragma clang attribute pop
 
 #pragma clang attribute push (__attribute__((abi_tag("a"
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) apply_to=function)
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", "
 #pragma clang attribute push (__attribute__((abi_tag("a"))) = function)
@@ -48,35 +48,35 @@
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = "
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))) 22)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) function)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:69}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:69}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) (function))
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:71}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: 

[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-14 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

In D121283#3379225 , @aaron.ballman 
wrote:

> As a thought experiment, would it make sense to lift the restriction on the 
> number of attributes allowed in a pragma, but not allow multiple attribute 
> specifiers?

I think this is reasonable, and as you've mentioned, it also leaves the 
opportunity to extend this syntax later should the need arise.
I will adjust this patch shortly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121283

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


[PATCH] D121475: [Clang][Sema] Avoid crashing for `__builtin_memcpy_inline` with an array argument

2022-03-14 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6ca2f1938f96: [Clang][Sema] Avoid crashing for 
`__builtin_memcpy_inline` with an array… (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121475

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/builtins-memcpy-inline.cpp


Index: clang/test/Sema/builtins-memcpy-inline.cpp
===
--- clang/test/Sema/builtins-memcpy-inline.cpp
+++ clang/test/Sema/builtins-memcpy-inline.cpp
@@ -36,3 +36,9 @@
   // we do not try to evaluate size in non intantiated templates.
   __builtin_memcpy_inline(dst, src, size);
 }
+
+void test_memcpy_inline_implicit_conversion(void *ptr) {
+  char a[5];
+  __builtin_memcpy_inline(ptr, a, 5);
+  __builtin_memcpy_inline(a, ptr, 5);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1943,6 +1943,17 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
+auto ArgArrayConversionFailed = [&](unsigned Arg) {
+  ExprResult ArgExpr =
+  DefaultFunctionArrayLvalueConversion(TheCall->getArg(Arg));
+  if (ArgExpr.isInvalid())
+return true;
+  TheCall->setArg(Arg, ArgExpr.get());
+  return false;
+};
+
+if (ArgArrayConversionFailed(0) || ArgArrayConversionFailed(1))
+  return true;
 clang::Expr *SizeOp = TheCall->getArg(2);
 // We warn about copying to or from `nullptr` pointers when `size` is
 // greater than 0. When `size` is value dependent we cannot evaluate its


Index: clang/test/Sema/builtins-memcpy-inline.cpp
===
--- clang/test/Sema/builtins-memcpy-inline.cpp
+++ clang/test/Sema/builtins-memcpy-inline.cpp
@@ -36,3 +36,9 @@
   // we do not try to evaluate size in non intantiated templates.
   __builtin_memcpy_inline(dst, src, size);
 }
+
+void test_memcpy_inline_implicit_conversion(void *ptr) {
+  char a[5];
+  __builtin_memcpy_inline(ptr, a, 5);
+  __builtin_memcpy_inline(a, ptr, 5);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1943,6 +1943,17 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
+auto ArgArrayConversionFailed = [&](unsigned Arg) {
+  ExprResult ArgExpr =
+  DefaultFunctionArrayLvalueConversion(TheCall->getArg(Arg));
+  if (ArgExpr.isInvalid())
+return true;
+  TheCall->setArg(Arg, ArgExpr.get());
+  return false;
+};
+
+if (ArgArrayConversionFailed(0) || ArgArrayConversionFailed(1))
+  return true;
 clang::Expr *SizeOp = TheCall->getArg(2);
 // We warn about copying to or from `nullptr` pointers when `size` is
 // greater than 0. When `size` is value dependent we cannot evaluate its
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121475: [Clang][Sema] Avoid crashing for `__builtin_memcpy_inline` with an array argument

2022-03-14 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 415069.
egorzhdan added a comment.

Rename a lambda to improve readability


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121475

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/builtins-memcpy-inline.cpp


Index: clang/test/Sema/builtins-memcpy-inline.cpp
===
--- clang/test/Sema/builtins-memcpy-inline.cpp
+++ clang/test/Sema/builtins-memcpy-inline.cpp
@@ -36,3 +36,9 @@
   // we do not try to evaluate size in non intantiated templates.
   __builtin_memcpy_inline(dst, src, size);
 }
+
+void test_memcpy_inline_implicit_conversion(void *ptr) {
+  char a[5];
+  __builtin_memcpy_inline(ptr, a, 5);
+  __builtin_memcpy_inline(a, ptr, 5);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1943,6 +1943,17 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
+auto ArgArrayConversionFailed = [&](unsigned Arg) {
+  ExprResult ArgExpr =
+  DefaultFunctionArrayLvalueConversion(TheCall->getArg(Arg));
+  if (ArgExpr.isInvalid())
+return true;
+  TheCall->setArg(Arg, ArgExpr.get());
+  return false;
+};
+
+if (ArgArrayConversionFailed(0) || ArgArrayConversionFailed(1))
+  return true;
 clang::Expr *SizeOp = TheCall->getArg(2);
 // We warn about copying to or from `nullptr` pointers when `size` is
 // greater than 0. When `size` is value dependent we cannot evaluate its


Index: clang/test/Sema/builtins-memcpy-inline.cpp
===
--- clang/test/Sema/builtins-memcpy-inline.cpp
+++ clang/test/Sema/builtins-memcpy-inline.cpp
@@ -36,3 +36,9 @@
   // we do not try to evaluate size in non intantiated templates.
   __builtin_memcpy_inline(dst, src, size);
 }
+
+void test_memcpy_inline_implicit_conversion(void *ptr) {
+  char a[5];
+  __builtin_memcpy_inline(ptr, a, 5);
+  __builtin_memcpy_inline(a, ptr, 5);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1943,6 +1943,17 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
+auto ArgArrayConversionFailed = [&](unsigned Arg) {
+  ExprResult ArgExpr =
+  DefaultFunctionArrayLvalueConversion(TheCall->getArg(Arg));
+  if (ArgExpr.isInvalid())
+return true;
+  TheCall->setArg(Arg, ArgExpr.get());
+  return false;
+};
+
+if (ArgArrayConversionFailed(0) || ArgArrayConversionFailed(1))
+  return true;
 clang::Expr *SizeOp = TheCall->getArg(2);
 // We warn about copying to or from `nullptr` pointers when `size` is
 // greater than 0. When `size` is value dependent we cannot evaluate its
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-11 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

In D121283#3373560 , @aaron.ballman 
wrote:

> why do we support multiple attribute *specifiers* in the same pragma? I would 
> not expect to be able to mix attribute styles in the same pragma given that 
> all of the individual styles allow you to specify multiple attributes within 
> a single specifier

I don't think I have a strong use case for this. It seemed consistent with the 
way multiple attributes can be added for individual declarations, e.g. 
`__attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f()`. But we 
can prohibit multiple specifiers within a single pragma if you think that this 
is not a good construct to support.

In D121283#3373560 , @aaron.ballman 
wrote:

> why is whitespace the correct separator as opposed to a comma-delimited list?

My motivation for this was also consistency with the syntax for attributes in 
individual declarations. Given that attribute specifiers are delimited by space 
for individual declarations (`__attribute__((cdecl)) __attribute__((noreturn)) 
void f()`), I think it would be unintuitive to require commas for attribute 
specifiers in pragmas when we could instead reuse the existing syntax of 
space-delimited attribute specifiers.

In D121283#3373560 , @aaron.ballman 
wrote:

> Also, I'd expect there to be some documentation changes along with this patch 
> and a release note.

Good point, thanks, I will add those to this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121283

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


[PATCH] D121475: [Clang][Sema] Avoid crashing for `__builtin_memcpy_inline` with an array argument

2022-03-11 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
egorzhdan added a reviewer: gchatelet.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change teaches the Sema logic for `__builtin_memcpy_inline` to implicitly 
convert arrays passed as arguments to pointers, similarly to regular `memcpy`.

This code will no longer cause a compiler crash:

  void f(char *p) {
  char s[1] = {0};
  __builtin_memcpy_inline(p, s, 1);
  }

rdar://88147527


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121475

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/builtins-memcpy-inline.cpp


Index: clang/test/Sema/builtins-memcpy-inline.cpp
===
--- clang/test/Sema/builtins-memcpy-inline.cpp
+++ clang/test/Sema/builtins-memcpy-inline.cpp
@@ -36,3 +36,9 @@
   // we do not try to evaluate size in non intantiated templates.
   __builtin_memcpy_inline(dst, src, size);
 }
+
+void test_memcpy_inline_implicit_conversion(void *ptr) {
+  char a[5];
+  __builtin_memcpy_inline(ptr, a, 5);
+  __builtin_memcpy_inline(a, ptr, 5);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1943,6 +1943,17 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
+auto ArgArrayConversion = [&](unsigned Arg) {
+  ExprResult ArgExpr =
+  DefaultFunctionArrayLvalueConversion(TheCall->getArg(Arg));
+  if (ArgExpr.isInvalid())
+return true;
+  TheCall->setArg(Arg, ArgExpr.get());
+  return false;
+};
+
+if (ArgArrayConversion(0) || ArgArrayConversion(1))
+  return true;
 clang::Expr *SizeOp = TheCall->getArg(2);
 // We warn about copying to or from `nullptr` pointers when `size` is
 // greater than 0. When `size` is value dependent we cannot evaluate its


Index: clang/test/Sema/builtins-memcpy-inline.cpp
===
--- clang/test/Sema/builtins-memcpy-inline.cpp
+++ clang/test/Sema/builtins-memcpy-inline.cpp
@@ -36,3 +36,9 @@
   // we do not try to evaluate size in non intantiated templates.
   __builtin_memcpy_inline(dst, src, size);
 }
+
+void test_memcpy_inline_implicit_conversion(void *ptr) {
+  char a[5];
+  __builtin_memcpy_inline(ptr, a, 5);
+  __builtin_memcpy_inline(a, ptr, 5);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1943,6 +1943,17 @@
   case Builtin::BI__builtin_nontemporal_store:
 return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
+auto ArgArrayConversion = [&](unsigned Arg) {
+  ExprResult ArgExpr =
+  DefaultFunctionArrayLvalueConversion(TheCall->getArg(Arg));
+  if (ArgExpr.isInvalid())
+return true;
+  TheCall->setArg(Arg, ArgExpr.get());
+  return false;
+};
+
+if (ArgArrayConversion(0) || ArgArrayConversion(1))
+  return true;
 clang::Expr *SizeOp = TheCall->getArg(2);
 // We warn about copying to or from `nullptr` pointers when `size` is
 // greater than 0. When `size` is value dependent we cannot evaluate its
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-09 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 414068.
egorzhdan added a comment.

Remove unused include


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121283

Files:
  clang/include/clang/Basic/AttrSubjectMatchRules.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/test/AST/pragma-multiple-attributes-declspec.cpp
  clang/test/AST/pragma-multiple-attributes.cpp
  clang/test/FixIt/fixit-pragma-attribute.c
  clang/test/FixIt/fixit-pragma-attribute.cpp
  clang/test/Parser/pragma-attribute-declspec.cpp
  clang/test/Parser/pragma-attribute.cpp
  clang/test/Parser/pragma-multiple-attributes.cpp

Index: clang/test/Parser/pragma-multiple-attributes.cpp
===
--- /dev/null
+++ clang/test/Parser/pragma-multiple-attributes.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -Wno-pragma-clang-attribute -verify %s
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push ([[clang::disable_tail_calls]] __attribute__((annotate("test"))), apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls)) __attribute__((annotate("test"))), apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{expected ','}}
+
+#pragma clang attribute push (test [[noreturn]]) // expected-error {{expected an attribute that is specified using the GNU, C++11 or '__declspec' syntax}}
+
+#pragma clang attribute push ([[noreturn]] test) // expected-error {{expected ',' or an attribute that is specified using the GNU, C++11 or '__declspec' syntax}}
Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -154,9 +154,6 @@
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=any(function))
 #pragma clang attribute pop
 
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=namespace)
 #pragma clang attribute pop
 
Index: clang/test/Parser/pragma-attribute-declspec.cpp
===
--- clang/test/Parser/pragma-attribute-declspec.cpp
+++ clang/test/Parser/pragma-attribute-declspec.cpp
@@ -6,7 +6,8 @@
 
 #pragma clang attribute pop
 
-#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
+#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function)
+#pragma clang attribute pop
 
 #pragma clang attribute push(__declspec(align), apply_to = variable) // expected-error {{attribute 'align' is not supported by '#pragma clang attribute'}}
 
Index: clang/test/FixIt/fixit-pragma-attribute.cpp
===
--- clang/test/FixIt/fixit-pragma-attribute.cpp
+++ clang/test/FixIt/fixit-pragma-attribute.cpp
@@ -39,7 +39,7 @@
 #pragma clang attribute pop
 
 #pragma clang attribute push (__attribute__((abi_tag("a"
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) apply_to=function)
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", "
 #pragma clang attribute push (__attribute__((abi_tag("a"))) = function)
@@ -48,35 +48,33 @@
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = "
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))) 22)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
-#pragma clang attribute push (__attribute__((abi_tag("a"))) function)
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:69}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:63}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) (function))
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:71}:", apply_to = any(record(unless(is_union)), variable, 

[PATCH] D121283: [Clang] Support multiple attributes in a single pragma

2022-03-09 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
egorzhdan added a reviewer: arphaman.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This adds support for multiple attributes in `#pragma clang attribute push`, 
for example:

  #pragma clang attribute push 
(__attribute__((disable_sanitizer_instrumentation)) 
__attribute__((section("S"))), apply_to=variable(is_global))

or

  #pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], 
apply_to = function)

Related attributes can now be applied with a single pragma, which makes it 
harder for developers to make an accidental error later when editing the code.

rdar://78269653


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121283

Files:
  clang/include/clang/Basic/AttrSubjectMatchRules.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/test/AST/pragma-multiple-attributes-declspec.cpp
  clang/test/AST/pragma-multiple-attributes.cpp
  clang/test/FixIt/fixit-pragma-attribute.c
  clang/test/FixIt/fixit-pragma-attribute.cpp
  clang/test/Parser/pragma-attribute-declspec.cpp
  clang/test/Parser/pragma-attribute.cpp
  clang/test/Parser/pragma-multiple-attributes.cpp

Index: clang/test/Parser/pragma-multiple-attributes.cpp
===
--- /dev/null
+++ clang/test/Parser/pragma-multiple-attributes.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -Wno-pragma-clang-attribute -verify %s
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push ([[clang::disable_tail_calls]] __attribute__((annotate("test"))), apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((disable_tail_calls)) __attribute__((annotate("test"))), apply_to = function)
+#pragma clang attribute pop
+
+#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{expected ','}}
+
+#pragma clang attribute push (test [[noreturn]]) // expected-error {{expected an attribute that is specified using the GNU, C++11 or '__declspec' syntax}}
+
+#pragma clang attribute push ([[noreturn]] test) // expected-error {{expected ',' or an attribute that is specified using the GNU, C++11 or '__declspec' syntax}}
Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -154,9 +154,6 @@
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=any(function))
 #pragma clang attribute pop
 
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-#pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
-
 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=namespace)
 #pragma clang attribute pop
 
Index: clang/test/Parser/pragma-attribute-declspec.cpp
===
--- clang/test/Parser/pragma-attribute-declspec.cpp
+++ clang/test/Parser/pragma-attribute-declspec.cpp
@@ -6,7 +6,8 @@
 
 #pragma clang attribute pop
 
-#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function) // expected-error {{more than one attribute specified in '#pragma clang attribute push'}}
+#pragma clang attribute push(__declspec(dllexport, dllimport), apply_to = function)
+#pragma clang attribute pop
 
 #pragma clang attribute push(__declspec(align), apply_to = variable) // expected-error {{attribute 'align' is not supported by '#pragma clang attribute'}}
 
Index: clang/test/FixIt/fixit-pragma-attribute.cpp
===
--- clang/test/FixIt/fixit-pragma-attribute.cpp
+++ clang/test/FixIt/fixit-pragma-attribute.cpp
@@ -39,7 +39,7 @@
 #pragma clang attribute pop
 
 #pragma clang attribute push (__attribute__((abi_tag("a"
-// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(record(unless(is_union)), variable, function, namespace)"
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = any(function, namespace, record(unless(is_union)), variable)"
 #pragma clang attribute push (__attribute__((abi_tag("a"))) apply_to=function)
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", "
 #pragma clang attribute push (__attribute__((abi_tag("a"))) = function)
@@ -48,35 +48,33 @@
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:60-[[@LINE-1]]:60}:", apply_to = "
 
 #pragma clang attribute push (__attribute__((abi_tag("a"))) 22)
-// CHECK: 

[PATCH] D120160: [Clang] Add `-funstable` flag to enable unstable and experimental features

2022-03-07 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.
Herald added a project: All.

Apologies for landing this too quickly! I'll adjust this logic in a separate 
patch: https://reviews.llvm.org/D121141

In D120160#3352399 , @Mordante wrote:

> `-funstable` is an option that controls multiple flags therefore I think it 
> would be good to have a separate flag to opt-in for unstable/incomplete 
> libc++ features. That makes it easier to _only_ opt-in to these features.

@Mordante could you please elaborate a little bit, are you proposing a separate 
flag that would be equivalent to `-Xcc -funstable` (essentially to enable 
`LangOpts.Unstable` but not the rest of the flags) and have a different 
spelling to indicate that it is specific to libc++?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120160

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


[PATCH] D121141: [Clang] Add `-funstable` flag to enable unstable and experimental features: follow-up fixes

2022-03-07 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
Herald added a subscriber: dang.
Herald added a project: All.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a follow-up for https://reviews.llvm.org/D120160 that addresses some of 
the post-merge feedback.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121141

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/unstable-flag.cpp


Index: clang/test/Driver/unstable-flag.cpp
===
--- clang/test/Driver/unstable-flag.cpp
+++ clang/test/Driver/unstable-flag.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang -funstable -### %s 2>&1 | FileCheck %s
 
 // CHECK: -funstable
-// CHECK: -fcoroutines-ts
 // CHECK: -fmodules-ts
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5766,8 +5766,6 @@
 
   if (Args.hasArg(options::OPT_funstable)) {
 CmdArgs.push_back("-funstable");
-if (!Args.hasArg(options::OPT_fno_coroutines_ts))
-  CmdArgs.push_back("-fcoroutines-ts");
 CmdArgs.push_back("-fmodules-ts");
   }
 
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -966,6 +966,8 @@
   switch (Type) {
   case ToolChain::CST_Libcxx:
 CmdArgs.push_back("-lc++");
+if (Args.hasArg(options::OPT_funstable))
+  CmdArgs.push_back("-lc++experimental");
 break;
 
   case ToolChain::CST_Libstdcxx:
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1162,7 +1162,10 @@
 
 defm unstable : BoolFOption<"unstable",
   LangOpts<"Unstable">, DefaultFalse,
-  PosFlag,
+  PosFlag,
   NegFlag>;
 
 def fembed_offload_object_EQ : Joined<["-"], "fembed-offload-object=">,
Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -271,6 +271,12 @@
 
 Build this module as a system module. Only used with -emit-module
 
+.. option:: -funstable
+
+Enable unstable and experimental language and library features.
+
+This option enables various language and library features that are either 
experimental (also known as TSes), or have been standardized but are not stable 
yet. This option should not be used in production code, since neither ABI nor 
API stability are guaranteed.
+
 .. option:: -fuse-cuid=
 
 Method to generate ID's for compilation units for single source offloading 
languages CUDA and HIP: 'hash' (ID's generated by hashing file path and command 
line options) \| 'random' (ID's generated as random numbers) \| 'none' 
(disabled). Default is 'hash'. This option will be overridden by option 
'-cuid=\[ID\]' if it is specified.


Index: clang/test/Driver/unstable-flag.cpp
===
--- clang/test/Driver/unstable-flag.cpp
+++ clang/test/Driver/unstable-flag.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang -funstable -### %s 2>&1 | FileCheck %s
 
 // CHECK: -funstable
-// CHECK: -fcoroutines-ts
 // CHECK: -fmodules-ts
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5766,8 +5766,6 @@
 
   if (Args.hasArg(options::OPT_funstable)) {
 CmdArgs.push_back("-funstable");
-if (!Args.hasArg(options::OPT_fno_coroutines_ts))
-  CmdArgs.push_back("-fcoroutines-ts");
 CmdArgs.push_back("-fmodules-ts");
   }
 
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -966,6 +966,8 @@
   switch (Type) {
   case ToolChain::CST_Libcxx:
 CmdArgs.push_back("-lc++");
+if (Args.hasArg(options::OPT_funstable))
+  CmdArgs.push_back("-lc++experimental");
 break;
 
   case ToolChain::CST_Libstdcxx:
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1162,7 +1162,10 @@
 
 defm unstable : BoolFOption<"unstable",
   LangOpts<"Unstable">, DefaultFalse,
-  PosFlag,
+  PosFlag,
   NegFlag>;
 
 def fembed_offload_object_EQ : Joined<["-"], "fembed-offload-object=">,
Index: clang/docs/ClangCommandLineReference.rst
===
--- 

[PATCH] D120160: [Clang] Add `-funstable` flag to enable unstable and experimental features

2022-03-01 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3cdc1c155b40: [Clang] Add `-funstable` flag to enable 
unstable and experimental features (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120160

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/unstable-flag.cpp
  clang/test/Lexer/has_feature_cxx_unstable.cpp


Index: clang/test/Lexer/has_feature_cxx_unstable.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_cxx_unstable.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -funstable -E %s -o - | FileCheck 
--check-prefix=CHECK-UNSTABLE %s
+// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-UNSTABLE %s
+
+#if __has_feature(cxx_unstable)
+int has_cxx_unstable();
+#else
+int has_no_cxx_unstable();
+#endif
+// CHECK-UNSTABLE: int has_cxx_unstable();
+// CHECK-NO-UNSTABLE: int has_no_cxx_unstable();
Index: clang/test/Driver/unstable-flag.cpp
===
--- /dev/null
+++ clang/test/Driver/unstable-flag.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -funstable -### %s 2>&1 | FileCheck %s
+
+// CHECK: -funstable
+// CHECK: -fcoroutines-ts
+// CHECK: -fmodules-ts
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5764,6 +5764,13 @@
 CmdArgs.push_back(A->getValue());
   }
 
+  if (Args.hasArg(options::OPT_funstable)) {
+CmdArgs.push_back("-funstable");
+if (!Args.hasArg(options::OPT_fno_coroutines_ts))
+  CmdArgs.push_back("-fcoroutines-ts");
+CmdArgs.push_back("-fmodules-ts");
+  }
+
   if (Args.hasArg(options::OPT_fexperimental_new_constant_interpreter))
 CmdArgs.push_back("-fexperimental-new-constant-interpreter");
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1160,6 +1160,11 @@
   PosFlag,
   NegFlag>;
 
+defm unstable : BoolFOption<"unstable",
+  LangOpts<"Unstable">, DefaultFalse,
+  PosFlag,
+  NegFlag>;
+
 def fembed_offload_object_EQ : Joined<["-"], "fembed-offload-object=">,
   Group, Flags<[NoXarchOption, CC1Option]>,
   HelpText<"Embed Offloading device-side binary into host object file as a 
section.">,
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -150,6 +150,7 @@
 LANGOPT(Coroutines, 1, 0, "C++20 coroutines")
 LANGOPT(DllExportInlines  , 1, 1, "dllexported classes dllexport inline 
methods")
 LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed matching of template 
template arguments")
+LANGOPT(Unstable  , 1, 0, "Enable unstable and experimental features")
 
 LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for 
all language standard modes")
 
Index: clang/include/clang/Basic/Features.def
===
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -173,6 +173,7 @@
 FEATURE(cxx_trailing_return, LangOpts.CPlusPlus11)
 FEATURE(cxx_unicode_literals, LangOpts.CPlusPlus11)
 FEATURE(cxx_unrestricted_unions, LangOpts.CPlusPlus11)
+FEATURE(cxx_unstable, LangOpts.Unstable)
 FEATURE(cxx_user_literals, LangOpts.CPlusPlus11)
 FEATURE(cxx_variadic_templates, LangOpts.CPlusPlus11)
 // C++14 features


Index: clang/test/Lexer/has_feature_cxx_unstable.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_cxx_unstable.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -funstable -E %s -o - | FileCheck --check-prefix=CHECK-UNSTABLE %s
+// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-UNSTABLE %s
+
+#if __has_feature(cxx_unstable)
+int has_cxx_unstable();
+#else
+int has_no_cxx_unstable();
+#endif
+// CHECK-UNSTABLE: int has_cxx_unstable();
+// CHECK-NO-UNSTABLE: int has_no_cxx_unstable();
Index: clang/test/Driver/unstable-flag.cpp
===
--- /dev/null
+++ clang/test/Driver/unstable-flag.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -funstable -### %s 2>&1 | FileCheck %s
+
+// CHECK: -funstable
+// CHECK: -fcoroutines-ts
+// CHECK: -fmodules-ts
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ 

[PATCH] D120160: [Clang] Add `-funstable` flag to enable unstable and experimental features

2022-02-18 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
Herald added subscribers: dexonsmith, dang.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This new flag enables `__has_feature(cxx_unstable)` that would replace libc++ 
macros for individual unstable/experimental features, e.g. 
`_LIBCPP_HAS_NO_INCOMPLETE_RANGES` or `_LIBCPP_HAS_NO_INCOMPLETE_FORMAT`.

This would make it easier and more convenient to opt-in into all libc++ 
unstable features at once.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120160

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/unstable-flag.cpp
  clang/test/Lexer/has_feature_cxx_unstable.cpp


Index: clang/test/Lexer/has_feature_cxx_unstable.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_cxx_unstable.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -funstable -E %s -o - | FileCheck 
--check-prefix=CHECK-UNSTABLE %s
+// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-UNSTABLE %s
+
+#if __has_feature(cxx_unstable)
+int has_cxx_unstable();
+#else
+int has_no_cxx_unstable();
+#endif
+// CHECK-UNSTABLE: int has_cxx_unstable();
+// CHECK-NO-UNSTABLE: int has_no_cxx_unstable();
Index: clang/test/Driver/unstable-flag.cpp
===
--- /dev/null
+++ clang/test/Driver/unstable-flag.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -funstable -### %s 2>&1 | FileCheck %s
+
+// CHECK: -funstable
+// CHECK: -fcoroutines-ts
+// CHECK: -fmodules-ts
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5721,6 +5721,13 @@
 CmdArgs.push_back(A->getValue());
   }
 
+  if (Args.hasArg(options::OPT_funstable)) {
+CmdArgs.push_back("-funstable");
+if (!Args.hasArg(options::OPT_fno_coroutines_ts))
+  CmdArgs.push_back("-fcoroutines-ts");
+CmdArgs.push_back("-fmodules-ts");
+  }
+
   if (Args.hasArg(options::OPT_fexperimental_new_constant_interpreter))
 CmdArgs.push_back("-fexperimental-new-constant-interpreter");
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1151,6 +1151,11 @@
   PosFlag,
   NegFlag>;
 
+defm unstable : BoolFOption<"unstable",
+  LangOpts<"Unstable">, DefaultFalse,
+  PosFlag,
+  NegFlag>;
+
 def fembed_offload_object_EQ : Joined<["-"], "fembed-offload-object=">,
   Group, Flags<[NoXarchOption, CC1Option]>,
   HelpText<"Embed Offloading device-side binary into host object file as a 
section.">,
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -150,6 +150,7 @@
 LANGOPT(Coroutines, 1, 0, "C++20 coroutines")
 LANGOPT(DllExportInlines  , 1, 1, "dllexported classes dllexport inline 
methods")
 LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed matching of template 
template arguments")
+LANGOPT(Unstable  , 1, 0, "Enable unstable and experimental features")
 
 LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for 
all language standard modes")
 
Index: clang/include/clang/Basic/Features.def
===
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -173,6 +173,7 @@
 FEATURE(cxx_trailing_return, LangOpts.CPlusPlus11)
 FEATURE(cxx_unicode_literals, LangOpts.CPlusPlus11)
 FEATURE(cxx_unrestricted_unions, LangOpts.CPlusPlus11)
+FEATURE(cxx_unstable, LangOpts.Unstable)
 FEATURE(cxx_user_literals, LangOpts.CPlusPlus11)
 FEATURE(cxx_variadic_templates, LangOpts.CPlusPlus11)
 // C++14 features


Index: clang/test/Lexer/has_feature_cxx_unstable.cpp
===
--- /dev/null
+++ clang/test/Lexer/has_feature_cxx_unstable.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -funstable -E %s -o - | FileCheck --check-prefix=CHECK-UNSTABLE %s
+// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-UNSTABLE %s
+
+#if __has_feature(cxx_unstable)
+int has_cxx_unstable();
+#else
+int has_no_cxx_unstable();
+#endif
+// CHECK-UNSTABLE: int has_cxx_unstable();
+// CHECK-NO-UNSTABLE: int has_no_cxx_unstable();
Index: clang/test/Driver/unstable-flag.cpp
===
--- /dev/null
+++ clang/test/Driver/unstable-flag.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -funstable -### %s 2>&1 | FileCheck %s
+
+// CHECK: -funstable
+// CHECK: -fcoroutines-ts
+// CHECK: 

[PATCH] D119363: [clang] Add `ObjCProtocolLoc` to represent protocol references

2022-02-15 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

Thank you @dgoldman, this approach looks good to me.
I don't have anything to add other than what @sammccall has already commented.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119363

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


[PATCH] D116052: [clang] fix out of bounds access in an empty string when lexing a _Pragma with missing string token

2022-02-02 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan accepted this revision.
egorzhdan added a comment.
This revision is now accepted and ready to land.

LGTM!


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

https://reviews.llvm.org/D116052

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


[PATCH] D117931: [Clang] Support `address_space` attribute in `#pragma clang attribute

2022-02-01 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan abandoned this revision.
egorzhdan added a comment.

Thanks @aaron.ballman for your feedback. I will probably abandon this change 
until we have a more compelling reason to apply attributes to types via pragmas.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117931

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


[PATCH] D117931: [Clang] Support `address_space` attribute in `#pragma clang attribute

2022-01-21 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
Herald added a reviewer: aaron.ballman.
Herald added a subscriber: jdoerfert.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change adds support for type attributes (for example, `address_space`) in 
pragmas, so that the following code now compiles correctly:

  #pragma clang attribute push (__attribute__ ((address_space(1))), 
apply_to=variable(is_global))
  
  int var;
  
  #pragma clang attribute pop

Since the attribute matching logic (`attr::SubjectMatchRule`) applies to an 
already constructed `Decl`, we first determine the declaration's type ignoring 
pragma attributes, then construct the `Decl`, and then recalculate its type if 
any type attribute was applied.

rdar://78269223


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117931

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/address_space_attribute.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Parser/pragma-attribute.cpp

Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -142,8 +142,6 @@
 
 _Pragma("clang attribute pop");
 
-#pragma clang attribute push (__attribute__((address_space(0))), apply_to=variable) // expected-error {{attribute 'address_space' is not supported by '#pragma clang attribute'}}
-
 // Check support for CXX11 style attributes
 #pragma clang attribute push ([[noreturn]], apply_to = any(function))
 #pragma clang attribute pop
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -10,6 +10,7 @@
 // CHECK-NEXT: AVRSignal (SubjectMatchRule_function)
 // CHECK-NEXT: AbiTag (SubjectMatchRule_record_not_is_union, SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_namespace)
 // CHECK-NEXT: AcquireHandle (SubjectMatchRule_function, SubjectMatchRule_type_alias, SubjectMatchRule_variable_is_parameter)
+// CHECK-NEXT: AddressSpace ()
 // CHECK-NEXT: Alias (SubjectMatchRule_function, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: AlignValue (SubjectMatchRule_variable, SubjectMatchRule_type_alias)
 // CHECK-NEXT: AlwaysDestroy (SubjectMatchRule_variable)
Index: clang/test/AST/address_space_attribute.cpp
===
--- clang/test/AST/address_space_attribute.cpp
+++ clang/test/AST/address_space_attribute.cpp
@@ -28,3 +28,19 @@
 void func2() {
   func<2>();
 }
+
+#pragma clang attribute push (__attribute__((address_space(4))), apply_to=variable(is_global))
+volatile int f;
+// CHECK: VarDecl {{.*}} 'volatile __attribute__((address_space(4))) int'
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((address_space(5))), apply_to=variable(is_parameter))
+void func3(volatile int g) {}
+// CHECK: ParmVarDecl {{.*}} 'volatile __attribute__((address_space(5))) int'
+#pragma clang attribute pop
+
+#pragma clang attribute push (__attribute__((address_space(6))), apply_to=field)
+volatile int g;
+// Verify that the attribute is not applied to a declaration that does not match the filter.
+// CHECK: VarDecl {{.*}} 'volatile int'
+#pragma clang attribute pop
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -9017,7 +9017,7 @@
 /// ProcessDeclAttributes - Given a declarator (PD) with attributes indicated in
 /// it, apply them to D.  This is a bit tricky because PD can have attributes
 /// specified in many different places, and we need to find and apply them all.
-void Sema::ProcessDeclAttributes(Scope *S, Decl *D, const Declarator ) {
+void Sema::ProcessDeclAttributes(Scope *S, Decl *D, Declarator ) {
   // Apply decl attributes from the DeclSpec if present.
   if (!PD.getDeclSpec().getAttributes().empty())
 ProcessDeclAttributeList(S, D, PD.getDeclSpec().getAttributes());
@@ -9035,6 +9035,8 @@
 
   // Apply additional attributes specified by '#pragma clang attribute'.
   AddPragmaAttributes(S, D);
+  if (auto *VD = dyn_cast(D))
+AddPragmaTypeAttributes(S, VD, PD);
 }
 
 /// Is the given declaration allowed to use a forbidden type?
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -972,10 +972,12 @@
 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
 }
 
-void Sema::AddPragmaAttributes(Scope *S, Decl *D) {
-  if 

[PATCH] D117348: [Preprocessor] Reduce the memory overhead of `#define` directives

2022-01-17 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan accepted this revision.
egorzhdan added a comment.

LGTM!


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

https://reviews.llvm.org/D117348

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


[PATCH] D116822: [Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and watchOS availability

2022-01-12 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3a32d2e74e5c: [Clang][Sema] Use VersionMap from SDKSettings 
for remapping tvOS and watchOS… (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116822

Files:
  clang/include/clang/Basic/DarwinSDKInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/Inputs/AppleTVOS15.0.sdk/SDKSettings.json
  clang/test/Sema/Inputs/WatchOS7.0.sdk/SDKSettings.json
  clang/test/Sema/attr-availability-tvos.c
  clang/test/Sema/attr-availability-watchos.c

Index: clang/test/Sema/attr-availability-watchos.c
===
--- clang/test/Sema/attr-availability-watchos.c
+++ clang/test/Sema/attr-availability-watchos.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 "-triple" "arm64-apple-watchos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/WatchOS7.0.sdk -fsyntax-only -verify %s
 
 void f0(int) __attribute__((availability(ios,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
 void f1(int) __attribute__((availability(ios,introduced=2.1)));
@@ -58,3 +59,19 @@
 void test_ios_correctly_map_to_watchos() {
   deprecatedAfterIntroduced(); // expected-warning {{'deprecatedAfterIntroduced' is deprecated: first deprecated in watchOS 3}}
 }
+
+#ifdef USE_VERSION_MAP
+// iOS 10.3.1 corresponds to watchOS 3.2, as indicated in 'SDKSettings.json'.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.2}}
+}
+#else
+// Without VersionMap, watchOS version is inferred incorrectly as 3.3.1.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithoutVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.3.1}}
+}
+#endif
Index: clang/test/Sema/attr-availability-tvos.c
===
--- clang/test/Sema/attr-availability-tvos.c
+++ clang/test/Sema/attr-availability-tvos.c
@@ -1,63 +1,80 @@
-// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/AppleTVOS15.0.sdk -fsyntax-only -verify %s
 
-void f0(int) __attribute__((availability(tvos,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
-void f1(int) __attribute__((availability(tvos,introduced=2.1)));
-void f2(int) __attribute__((availability(tvos,introduced=2.0,deprecated=3.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
-void f3(int) __attribute__((availability(tvos,introduced=3.0)));
-void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}}
+void f0(int) __attribute__((availability(tvos,introduced=12.0,deprecated=12.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(tvos,introduced=12.1)));
+void f2(int) __attribute__((availability(tvos,introduced=12.0,deprecated=13.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(tvos,introduced=13.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=12.0,deprecated=12.1,obsoleted=13.0))); // expected-note{{explicitly marked unavailable}}
 
-void f5(int) __attribute__((availability(tvos,introduced=2.0))) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,introduced=2.0)));
+void f5(int) __attribute__((availability(tvos,introduced=12.0))) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,introduced=12.0)));
 
 void test() {
-  f0(0); // 

[PATCH] D116822: [Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and watchOS availability

2022-01-12 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 399327.
egorzhdan added a comment.

Add a test for a diagnostic without VersionMap & fix clang-format warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116822

Files:
  clang/include/clang/Basic/DarwinSDKInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/Inputs/AppleTVOS15.0.sdk/SDKSettings.json
  clang/test/Sema/Inputs/WatchOS7.0.sdk/SDKSettings.json
  clang/test/Sema/attr-availability-tvos.c
  clang/test/Sema/attr-availability-watchos.c

Index: clang/test/Sema/attr-availability-watchos.c
===
--- clang/test/Sema/attr-availability-watchos.c
+++ clang/test/Sema/attr-availability-watchos.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 "-triple" "arm64-apple-watchos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/WatchOS7.0.sdk -fsyntax-only -verify %s
 
 void f0(int) __attribute__((availability(ios,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
 void f1(int) __attribute__((availability(ios,introduced=2.1)));
@@ -58,3 +59,19 @@
 void test_ios_correctly_map_to_watchos() {
   deprecatedAfterIntroduced(); // expected-warning {{'deprecatedAfterIntroduced' is deprecated: first deprecated in watchOS 3}}
 }
+
+#ifdef USE_VERSION_MAP
+// iOS 10.3.1 corresponds to watchOS 3.2, as indicated in 'SDKSettings.json'.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.2}}
+}
+#else
+// Without VersionMap, watchOS version is inferred incorrectly as 3.3.1.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithoutVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.3.1}}
+}
+#endif
Index: clang/test/Sema/attr-availability-tvos.c
===
--- clang/test/Sema/attr-availability-tvos.c
+++ clang/test/Sema/attr-availability-tvos.c
@@ -1,63 +1,80 @@
-// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/AppleTVOS15.0.sdk -fsyntax-only -verify %s
 
-void f0(int) __attribute__((availability(tvos,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
-void f1(int) __attribute__((availability(tvos,introduced=2.1)));
-void f2(int) __attribute__((availability(tvos,introduced=2.0,deprecated=3.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
-void f3(int) __attribute__((availability(tvos,introduced=3.0)));
-void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}}
+void f0(int) __attribute__((availability(tvos,introduced=12.0,deprecated=12.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(tvos,introduced=12.1)));
+void f2(int) __attribute__((availability(tvos,introduced=12.0,deprecated=13.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(tvos,introduced=13.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=12.0,deprecated=12.1,obsoleted=13.0))); // expected-note{{explicitly marked unavailable}}
 
-void f5(int) __attribute__((availability(tvos,introduced=2.0))) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,introduced=2.0)));
+void f5(int) __attribute__((availability(tvos,introduced=12.0))) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,introduced=12.0)));
 
 void test() {
-  f0(0); // expected-warning{{'f0' is deprecated: first deprecated in tvOS 2.1}}
+  

[PATCH] D116412: [Clang][Sema] Fix attribute mismatch warning for ObjC class properties

2022-01-11 Thread Egor Zhdan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfda47db8ee1d: [Clang][Sema] Fix attribute mismatch warning 
for ObjC class properties (authored by egorzhdan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116412

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/test/SemaObjC/class-property-inheritance.m

Index: clang/test/SemaObjC/class-property-inheritance.m
===
--- /dev/null
+++ clang/test/SemaObjC/class-property-inheritance.m
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@class MyObject;
+
+
+@interface TopClassWithClassProperty0
+@property(nullable, readonly, strong, class) MyObject *foo;
+@end
+
+@interface SubClassWithClassProperty0 : TopClassWithClassProperty0
+@property(nonnull, readonly, copy, class) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithClassProperty0'}}
+@end
+
+
+
+@interface TopClassWithInstanceProperty1
+@property(nullable, readonly, strong) MyObject *foo;
+@end
+
+@interface ClassWithClassProperty1 : TopClassWithInstanceProperty1
+@property(nonnull, readonly, copy, class) MyObject *foo; // no-warning
+@end
+
+@interface SubClassWithInstanceProperty1 : ClassWithClassProperty1
+@property(nullable, readonly, copy) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithInstanceProperty1'}}
+@end
+
+
+@interface TopClassWithClassProperty2
+@property(nullable, readonly, strong, class) MyObject *foo;
+@end
+
+@interface ClassWithInstanceProperty2 : TopClassWithClassProperty2
+@property(nonnull, readonly, copy) MyObject *foo; // no-warning
+@end
+
+@interface SubClassWithClassProperty2 : ClassWithInstanceProperty2
+@property(nonnull, readonly, copy, class) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithClassProperty2'}}
+@end
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -112,8 +112,8 @@
 return;
 
   // Look for a property with the same name.
-  if (ObjCPropertyDecl *ProtoProp =
-  Proto->lookup(Prop->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *ProtoProp = Proto->getProperty(
+  Prop->getIdentifier(), Prop->isInstanceProperty())) {
 S.DiagnosePropertyMismatch(Prop, ProtoProp, Proto->getIdentifier(), true);
 return;
   }
@@ -231,8 +231,8 @@
 bool FoundInSuper = false;
 ObjCInterfaceDecl *CurrentInterfaceDecl = IFace;
 while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
-  if (ObjCPropertyDecl *SuperProp =
-  Super->lookup(Res->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *SuperProp = Super->getProperty(
+  Res->getIdentifier(), Res->isInstanceProperty())) {
 DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(), false);
 FoundInSuper = true;
 break;
Index: clang/lib/AST/DeclObjC.cpp
===
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -232,6 +232,18 @@
   return (ivarName.str());
 }
 
+ObjCPropertyDecl *ObjCContainerDecl::getProperty(const IdentifierInfo *Id,
+ bool IsInstance) const {
+  for (auto *LookupResult : lookup(Id)) {
+if (auto *Prop = dyn_cast(LookupResult)) {
+  if (Prop->isInstanceProperty() == IsInstance) {
+return Prop;
+  }
+}
+  }
+  return nullptr;
+}
+
 /// FindPropertyDeclaration - Finds declaration of the property given its name
 /// in 'PropertyId' and returns it. It returns 0, if not found.
 ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(
Index: clang/include/clang/AST/DeclObjC.h
===
--- clang/include/clang/AST/DeclObjC.h
+++ clang/include/clang/AST/DeclObjC.h
@@ -1071,6 +1071,9 @@
   bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
   ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
 
+  ObjCPropertyDecl *getProperty(const IdentifierInfo *Id,
+bool IsInstance) const;
+
   ObjCPropertyDecl *
   FindPropertyDeclaration(const IdentifierInfo *PropertyId,
   ObjCPropertyQueryKind QueryKind) const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116412: [Clang][Sema] Fix attribute mismatch warning for ObjC class properties

2022-01-10 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 398753.
egorzhdan added a comment.

Fix clang-format warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116412

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/test/SemaObjC/class-property-inheritance.m

Index: clang/test/SemaObjC/class-property-inheritance.m
===
--- /dev/null
+++ clang/test/SemaObjC/class-property-inheritance.m
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@class MyObject;
+
+
+@interface TopClassWithClassProperty0
+@property(nullable, readonly, strong, class) MyObject *foo;
+@end
+
+@interface SubClassWithClassProperty0 : TopClassWithClassProperty0
+@property(nonnull, readonly, copy, class) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithClassProperty0'}}
+@end
+
+
+
+@interface TopClassWithInstanceProperty1
+@property(nullable, readonly, strong) MyObject *foo;
+@end
+
+@interface ClassWithClassProperty1 : TopClassWithInstanceProperty1
+@property(nonnull, readonly, copy, class) MyObject *foo; // no-warning
+@end
+
+@interface SubClassWithInstanceProperty1 : ClassWithClassProperty1
+@property(nullable, readonly, copy) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithInstanceProperty1'}}
+@end
+
+
+@interface TopClassWithClassProperty2
+@property(nullable, readonly, strong, class) MyObject *foo;
+@end
+
+@interface ClassWithInstanceProperty2 : TopClassWithClassProperty2
+@property(nonnull, readonly, copy) MyObject *foo; // no-warning
+@end
+
+@interface SubClassWithClassProperty2 : ClassWithInstanceProperty2
+@property(nonnull, readonly, copy, class) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithClassProperty2'}}
+@end
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -112,8 +112,8 @@
 return;
 
   // Look for a property with the same name.
-  if (ObjCPropertyDecl *ProtoProp =
-  Proto->lookup(Prop->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *ProtoProp = Proto->getProperty(
+  Prop->getIdentifier(), Prop->isInstanceProperty())) {
 S.DiagnosePropertyMismatch(Prop, ProtoProp, Proto->getIdentifier(), true);
 return;
   }
@@ -231,8 +231,8 @@
 bool FoundInSuper = false;
 ObjCInterfaceDecl *CurrentInterfaceDecl = IFace;
 while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
-  if (ObjCPropertyDecl *SuperProp =
-  Super->lookup(Res->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *SuperProp = Super->getProperty(
+  Res->getIdentifier(), Res->isInstanceProperty())) {
 DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(), false);
 FoundInSuper = true;
 break;
Index: clang/lib/AST/DeclObjC.cpp
===
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -232,6 +232,18 @@
   return (ivarName.str());
 }
 
+ObjCPropertyDecl *ObjCContainerDecl::getProperty(const IdentifierInfo *Id,
+ bool IsInstance) const {
+  for (auto *LookupResult : lookup(Id)) {
+if (auto *Prop = dyn_cast(LookupResult)) {
+  if (Prop->isInstanceProperty() == IsInstance) {
+return Prop;
+  }
+}
+  }
+  return nullptr;
+}
+
 /// FindPropertyDeclaration - Finds declaration of the property given its name
 /// in 'PropertyId' and returns it. It returns 0, if not found.
 ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(
Index: clang/include/clang/AST/DeclObjC.h
===
--- clang/include/clang/AST/DeclObjC.h
+++ clang/include/clang/AST/DeclObjC.h
@@ -1071,6 +1071,9 @@
   bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
   ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
 
+  ObjCPropertyDecl *getProperty(const IdentifierInfo *Id,
+bool IsInstance) const;
+
   ObjCPropertyDecl *
   FindPropertyDeclaration(const IdentifierInfo *PropertyId,
   ObjCPropertyQueryKind QueryKind) const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116412: [Clang][Sema] Fix attribute mismatch warning for ObjC class properties

2022-01-10 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 398601.
egorzhdan added a comment.

Diagnose mismatches between class property of a class and a class property of 
its superclass.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116412

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/test/SemaObjC/class-property-inheritance.m

Index: clang/test/SemaObjC/class-property-inheritance.m
===
--- /dev/null
+++ clang/test/SemaObjC/class-property-inheritance.m
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@class MyObject;
+
+
+@interface TopClassWithClassProperty0
+@property(nullable, readonly, strong, class) MyObject *foo;
+@end
+
+@interface SubClassWithClassProperty0 : TopClassWithClassProperty0
+@property(nonnull, readonly, copy, class) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithClassProperty0'}}
+@end
+
+
+
+@interface TopClassWithInstanceProperty1
+@property(nullable, readonly, strong) MyObject *foo;
+@end
+
+@interface ClassWithClassProperty1 : TopClassWithInstanceProperty1
+@property(nonnull, readonly, copy, class) MyObject *foo; // no-warning
+@end
+
+@interface SubClassWithInstanceProperty1 : ClassWithClassProperty1
+@property(nullable, readonly, copy) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithInstanceProperty1'}}
+@end
+
+
+@interface TopClassWithClassProperty2
+@property(nullable, readonly, strong, class) MyObject *foo;
+@end
+
+@interface ClassWithInstanceProperty2 : TopClassWithClassProperty2
+@property(nonnull, readonly, copy) MyObject *foo; // no-warning
+@end
+
+@interface SubClassWithClassProperty2 : ClassWithInstanceProperty2
+@property(nonnull, readonly, copy, class) MyObject *foo; // expected-warning {{'copy' attribute on property 'foo' does not match the property inherited from 'TopClassWithClassProperty2'}}
+@end
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -112,8 +112,8 @@
 return;
 
   // Look for a property with the same name.
-  if (ObjCPropertyDecl *ProtoProp =
-  Proto->lookup(Prop->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *ProtoProp = Proto->getProperty(
+  Prop->getIdentifier(), Prop->isInstanceProperty())) {
 S.DiagnosePropertyMismatch(Prop, ProtoProp, Proto->getIdentifier(), true);
 return;
   }
@@ -231,8 +231,8 @@
 bool FoundInSuper = false;
 ObjCInterfaceDecl *CurrentInterfaceDecl = IFace;
 while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
-  if (ObjCPropertyDecl *SuperProp =
-  Super->lookup(Res->getDeclName()).find_first()) {
+  if (ObjCPropertyDecl *SuperProp = Super->getProperty(
+  Res->getIdentifier(), Res->isInstanceProperty())) {
 DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(), false);
 FoundInSuper = true;
 break;
Index: clang/lib/AST/DeclObjC.cpp
===
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -232,6 +232,19 @@
   return (ivarName.str());
 }
 
+ObjCPropertyDecl *
+ObjCContainerDecl::getProperty(const IdentifierInfo *Id,
+   bool IsInstance) const {
+  for (auto *LookupResult : lookup(Id)) {
+if (auto *Prop = dyn_cast(LookupResult)) {
+  if (Prop->isInstanceProperty() == IsInstance) {
+return Prop;
+  }
+}
+  }
+  return nullptr;
+}
+
 /// FindPropertyDeclaration - Finds declaration of the property given its name
 /// in 'PropertyId' and returns it. It returns 0, if not found.
 ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(
Index: clang/include/clang/AST/DeclObjC.h
===
--- clang/include/clang/AST/DeclObjC.h
+++ clang/include/clang/AST/DeclObjC.h
@@ -1071,6 +1071,9 @@
   bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
   ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
 
+  ObjCPropertyDecl *getProperty(const IdentifierInfo *Id,
+bool IsInstance) const;
+
   ObjCPropertyDecl *
   FindPropertyDeclaration(const IdentifierInfo *PropertyId,
   ObjCPropertyQueryKind QueryKind) const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116272: [Clang][Sema] Avoid crashing for va_arg expressions with bool argument

2022-01-07 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

In D116272#3228427 , @tstellar wrote:

> We may have time to fit it in to the release, but no guarantees.  Can you 
> file an issue for this?

That would be great. I filed an issue: 
https://github.com/llvm/llvm-project/issues/53078.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116272

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


[PATCH] D116272: [Clang][Sema] Avoid crashing for va_arg expressions with bool argument

2022-01-07 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan added a comment.

Thank you @aaron.ballman, I will try to get this patch into the next 13.0.x 
release.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116272

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


[PATCH] D116822: [Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and watchOS availability

2022-01-07 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 398192.
egorzhdan added a comment.

Remove accidental change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116822

Files:
  clang/include/clang/Basic/DarwinSDKInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/Inputs/AppleTVOS15.0.sdk/SDKSettings.json
  clang/test/Sema/Inputs/WatchOS7.0.sdk/SDKSettings.json
  clang/test/Sema/attr-availability-tvos.c
  clang/test/Sema/attr-availability-watchos.c

Index: clang/test/Sema/attr-availability-watchos.c
===
--- clang/test/Sema/attr-availability-watchos.c
+++ clang/test/Sema/attr-availability-watchos.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 "-triple" "arm64-apple-watchos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/WatchOS7.0.sdk -fsyntax-only -verify %s
 
 void f0(int) __attribute__((availability(ios,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
 void f1(int) __attribute__((availability(ios,introduced=2.1)));
@@ -58,3 +59,12 @@
 void test_ios_correctly_map_to_watchos() {
   deprecatedAfterIntroduced(); // expected-warning {{'deprecatedAfterIntroduced' is deprecated: first deprecated in watchOS 3}}
 }
+
+#ifdef USE_VERSION_MAP
+// iOS 10.3.1 corresponds to watchOS 3.2, as indicated in 'SDKSettings.json'.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.2}}
+}
+#endif
Index: clang/test/Sema/attr-availability-tvos.c
===
--- clang/test/Sema/attr-availability-tvos.c
+++ clang/test/Sema/attr-availability-tvos.c
@@ -1,63 +1,73 @@
-// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/AppleTVOS15.0.sdk -fsyntax-only -verify %s
 
-void f0(int) __attribute__((availability(tvos,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
-void f1(int) __attribute__((availability(tvos,introduced=2.1)));
-void f2(int) __attribute__((availability(tvos,introduced=2.0,deprecated=3.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
-void f3(int) __attribute__((availability(tvos,introduced=3.0)));
-void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}}
+void f0(int) __attribute__((availability(tvos,introduced=12.0,deprecated=12.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(tvos,introduced=12.1)));
+void f2(int) __attribute__((availability(tvos,introduced=12.0,deprecated=13.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(tvos,introduced=13.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=12.0,deprecated=12.1,obsoleted=13.0))); // expected-note{{explicitly marked unavailable}}
 
-void f5(int) __attribute__((availability(tvos,introduced=2.0))) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,introduced=2.0)));
+void f5(int) __attribute__((availability(tvos,introduced=12.0))) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,introduced=12.0)));
 
 void test() {
-  f0(0); // expected-warning{{'f0' is deprecated: first deprecated in tvOS 2.1}}
+  f0(0); // expected-warning{{'f0' is deprecated: first deprecated in tvOS 12.1}}
   f1(0);
-  f2(0); // expected-warning{{'f2' is deprecated: first deprecated in tvOS 3.0}}
+  f2(0); // expected-warning{{'f2' is deprecated: first deprecated in tvOS 13.0}}
   f3(0);
-  f4(0); // expected-error{{f4' is unavailable: obsoleted in tvOS 3.0}}
-  f5(0); // expected-warning{{'f5' is deprecated: first deprecated in tvOS 3.0}}
-  f6(0); // expected-warning{{'f6' is deprecated: first 

[PATCH] D116822: [Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and watchOS availability

2022-01-07 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
Herald added a reviewer: aaron.ballman.
Herald added a subscriber: dexonsmith.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This makes the mapping between iOS & tvOS/watchOS versions more accurate. For 
example, iOS 9.3 now gets correctly mapped into tvOS 9.2 and not tvOS 9.3.

Before this change, the incorrect mapping could cause excessive or missing 
warnings for code that specifies availability for iOS, but not for tvOS/watchOS.

rdar://81491680


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116822

Files:
  clang/include/clang/Basic/DarwinSDKInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/Inputs/AppleTVOS15.0.sdk/SDKSettings.json
  clang/test/Sema/Inputs/WatchOS7.0.sdk/SDKSettings.json
  clang/test/Sema/attr-availability-tvos.c
  clang/test/Sema/attr-availability-watchos-infer-from-ios.c
  clang/test/Sema/attr-availability-watchos.c

Index: clang/test/Sema/attr-availability-watchos-infer-from-ios.c
===
--- clang/test/Sema/attr-availability-watchos-infer-from-ios.c
+++ clang/test/Sema/attr-availability-watchos-infer-from-ios.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 "-triple" "arm64-apple-watchos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "arm64-apple-watchos4.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/WatchOS7.0.sdk -fsyntax-only -verify %s
 
 void f0(int) __attribute__((availability(ios,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
 void f1(int) __attribute__((availability(ios,introduced=2.1)));
@@ -58,3 +59,12 @@
 void test_ios_correctly_map_to_watchos() {
   deprecatedAfterIntroduced(); // expected-warning {{'deprecatedAfterIntroduced' is deprecated: first deprecated in watchOS 3}}
 }
+
+#ifdef USE_VERSION_MAP
+// iOS 10.3.1 corresponds to watchOS 3.2, as indicated in 'SDKSettings.json'.
+void f9(int) __attribute__((availability(ios,deprecated=10.3.1))); // expected-note {{'f9' has been explicitly marked deprecated here}}
+
+void testWithVersionMap() {
+  f9(0); // expected-warning {{'f9' is deprecated: first deprecated in watchOS 3.2}}
+}
+#endif
Index: clang/test/Sema/attr-availability-tvos.c
===
--- clang/test/Sema/attr-availability-tvos.c
+++ clang/test/Sema/attr-availability-tvos.c
@@ -1,63 +1,73 @@
-// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos3.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -fsyntax-only -verify %s
+// RUN: %clang_cc1 "-triple" "x86_64-apple-tvos13.0" -DUSE_VERSION_MAP -isysroot %S/Inputs/AppleTVOS15.0.sdk -fsyntax-only -verify %s
 
-void f0(int) __attribute__((availability(tvos,introduced=2.0,deprecated=2.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
-void f1(int) __attribute__((availability(tvos,introduced=2.1)));
-void f2(int) __attribute__((availability(tvos,introduced=2.0,deprecated=3.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
-void f3(int) __attribute__((availability(tvos,introduced=3.0)));
-void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}}
+void f0(int) __attribute__((availability(tvos,introduced=12.0,deprecated=12.1))); // expected-note {{'f0' has been explicitly marked deprecated here}}
+void f1(int) __attribute__((availability(tvos,introduced=12.1)));
+void f2(int) __attribute__((availability(tvos,introduced=12.0,deprecated=13.0))); // expected-note {{'f2' has been explicitly marked deprecated here}}
+void f3(int) __attribute__((availability(tvos,introduced=13.0)));
+void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(tvos,introduced=12.0,deprecated=12.1,obsoleted=13.0))); // expected-note{{explicitly marked unavailable}}
 
-void f5(int) __attribute__((availability(tvos,introduced=2.0))) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,deprecated=3.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(tvos,introduced=2.0)));
+void f5(int) __attribute__((availability(tvos,introduced=12.0))) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f5' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,deprecated=13.0))); // expected-note {{'f6' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(tvos,introduced=12.0)));
 
 void test() {
-  f0(0); // expected-warning{{'f0' is deprecated: first 

[PATCH] D116615: [Clang] Extract availability mapping from VersionMap for watchOS/tvOS

2022-01-05 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 397565.
egorzhdan added a comment.

Fix lint warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116615

Files:
  clang/lib/Basic/DarwinSDKInfo.cpp
  clang/unittests/Basic/DarwinSDKInfoTest.cpp

Index: clang/unittests/Basic/DarwinSDKInfoTest.cpp
===
--- clang/unittests/Basic/DarwinSDKInfoTest.cpp
+++ clang/unittests/Basic/DarwinSDKInfoTest.cpp
@@ -13,7 +13,68 @@
 using namespace llvm;
 using namespace clang;
 
-TEST(DarwinSDKInfoTest, ParseAndTestMapping) {
+// Check the version mapping logic in DarwinSDKInfo.
+TEST(DarwinSDKInfo, VersionMapping) {
+  llvm::json::Object Obj({{"3.0", "1.0"}, {"3.1", "1.2"}});
+  Optional Mapping =
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj,
+VersionTuple());
+  EXPECT_TRUE(Mapping.hasValue());
+  EXPECT_EQ(Mapping->getMinimumValue(), VersionTuple(1));
+
+  // Exact mapping.
+  EXPECT_EQ(Mapping->map(VersionTuple(3), VersionTuple(0, 1), None),
+VersionTuple(1));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 0), VersionTuple(0, 1), None),
+VersionTuple(1));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 0, 0), VersionTuple(0, 1), None),
+VersionTuple(1));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 1), VersionTuple(0, 1), None),
+VersionTuple(1, 2));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 1, 0), VersionTuple(0, 1), None),
+VersionTuple(1, 2));
+
+  // Missing mapping - fallback to major.
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 0, 1), VersionTuple(0, 1), None),
+VersionTuple(1));
+
+  // Minimum
+  EXPECT_EQ(Mapping->map(VersionTuple(2), VersionTuple(0, 1), None),
+VersionTuple(0, 1));
+
+  // Maximum
+  EXPECT_EQ(
+  Mapping->map(VersionTuple(4), VersionTuple(0, 1), VersionTuple(100)),
+  VersionTuple(100));
+}
+
+// Check the version mapping logic in DarwinSDKInfo.
+TEST(DarwinSDKInfo, VersionMappingMissingKey) {
+  llvm::json::Object Obj({{"3.0", "1.0"}, {"5.0", "1.2"}});
+  Optional Mapping =
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj,
+VersionTuple());
+  EXPECT_TRUE(Mapping.hasValue());
+  EXPECT_EQ(
+  Mapping->map(VersionTuple(4), VersionTuple(0, 1), VersionTuple(100)),
+  None);
+}
+
+TEST(DarwinSDKInfo, VersionMappingParseEmpty) {
+  llvm::json::Object Obj({});
+  EXPECT_FALSE(
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj, VersionTuple())
+  .hasValue());
+}
+
+TEST(DarwinSDKInfo, VersionMappingParseError) {
+  llvm::json::Object Obj({{"test", "1.2"}});
+  EXPECT_FALSE(
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj, VersionTuple())
+  .hasValue());
+}
+
+TEST(DarwinSDKInfoTest, ParseAndTestMappingMacCatalyst) {
   llvm::json::Object Obj;
   Obj["Version"] = "11.0";
   Obj["MaximumDeploymentTarget"] = "11.99";
@@ -58,6 +119,51 @@
 VersionTuple(99, 99));
 }
 
+TEST(DarwinSDKInfoTest, ParseAndTestMappingIOSDerived) {
+  llvm::json::Object Obj;
+  Obj["Version"] = "15.0";
+  Obj["MaximumDeploymentTarget"] = "15.0.99";
+  llvm::json::Object VersionMap;
+  VersionMap["10.0"] = "10.0";
+  VersionMap["10.3.1"] = "10.2";
+  VersionMap["11.0"] = "11.0";
+  llvm::json::Object IOSToTvOS;
+  IOSToTvOS["iOS_tvOS"] = std::move(VersionMap);
+  Obj["VersionMap"] = std::move(IOSToTvOS);
+
+  auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON();
+  ASSERT_TRUE(SDKInfo);
+  EXPECT_EQ(SDKInfo->getVersion(), VersionTuple(15, 0));
+
+  // Verify that mapping is present for platforms that derive from iOS.
+  const auto *Mapping = SDKInfo->getVersionMapping(DarwinSDKInfo::OSEnvPair(
+  llvm::Triple::IOS, llvm::Triple::UnknownEnvironment, llvm::Triple::TvOS,
+  llvm::Triple::UnknownEnvironment));
+  ASSERT_TRUE(Mapping);
+
+  // Verify that the iOS versions that are present in the map are translated
+  // directly to their corresponding tvOS versions.
+  EXPECT_EQ(*Mapping->map(VersionTuple(10, 0), VersionTuple(), None),
+VersionTuple(10, 0));
+  EXPECT_EQ(*Mapping->map(VersionTuple(10, 3, 1), VersionTuple(), None),
+VersionTuple(10, 2));
+  EXPECT_EQ(*Mapping->map(VersionTuple(11, 0), VersionTuple(), None),
+VersionTuple(11, 0));
+
+  // Verify that an iOS version that's not present in the map is translated
+  // like the nearest major OS version.
+  EXPECT_EQ(*Mapping->map(VersionTuple(10, 1), VersionTuple(), None),
+VersionTuple(10, 0));
+
+  // Verify that the iOS versions that are outside of the mapped version
+  // range map to the min/max values passed to the `map` call.
+  EXPECT_EQ(*Mapping->map(VersionTuple(9, 0), VersionTuple(99, 99), None),
+VersionTuple(99, 99));
+  EXPECT_EQ(
+  

[PATCH] D116615: [Clang] Extract availability mapping from VersionMap for watchOS/tvOS

2022-01-05 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan updated this revision to Diff 397541.
egorzhdan added a comment.

Add a test to verify that `iOS_tvOS` mapping is parsed correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116615

Files:
  clang/lib/Basic/DarwinSDKInfo.cpp
  clang/unittests/Basic/DarwinSDKInfoTest.cpp

Index: clang/unittests/Basic/DarwinSDKInfoTest.cpp
===
--- clang/unittests/Basic/DarwinSDKInfoTest.cpp
+++ clang/unittests/Basic/DarwinSDKInfoTest.cpp
@@ -13,7 +13,68 @@
 using namespace llvm;
 using namespace clang;
 
-TEST(DarwinSDKInfoTest, ParseAndTestMapping) {
+// Check the version mapping logic in DarwinSDKInfo.
+TEST(DarwinSDKInfo, VersionMapping) {
+  llvm::json::Object Obj({{"3.0", "1.0"}, {"3.1", "1.2"}});
+  Optional Mapping =
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj,
+VersionTuple());
+  EXPECT_TRUE(Mapping.hasValue());
+  EXPECT_EQ(Mapping->getMinimumValue(), VersionTuple(1));
+
+  // Exact mapping.
+  EXPECT_EQ(Mapping->map(VersionTuple(3), VersionTuple(0, 1), None),
+VersionTuple(1));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 0), VersionTuple(0, 1), None),
+VersionTuple(1));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 0, 0), VersionTuple(0, 1), None),
+VersionTuple(1));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 1), VersionTuple(0, 1), None),
+VersionTuple(1, 2));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 1, 0), VersionTuple(0, 1), None),
+VersionTuple(1, 2));
+
+  // Missing mapping - fallback to major.
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 0, 1), VersionTuple(0, 1), None),
+VersionTuple(1));
+
+  // Minimum
+  EXPECT_EQ(Mapping->map(VersionTuple(2), VersionTuple(0, 1), None),
+VersionTuple(0, 1));
+
+  // Maximum
+  EXPECT_EQ(
+  Mapping->map(VersionTuple(4), VersionTuple(0, 1), VersionTuple(100)),
+  VersionTuple(100));
+}
+
+// Check the version mapping logic in DarwinSDKInfo.
+TEST(DarwinSDKInfo, VersionMappingMissingKey) {
+  llvm::json::Object Obj({{"3.0", "1.0"}, {"5.0", "1.2"}});
+  Optional Mapping =
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj,
+VersionTuple());
+  EXPECT_TRUE(Mapping.hasValue());
+  EXPECT_EQ(
+  Mapping->map(VersionTuple(4), VersionTuple(0, 1), VersionTuple(100)),
+  None);
+}
+
+TEST(DarwinSDKInfo, VersionMappingParseEmpty) {
+  llvm::json::Object Obj({});
+  EXPECT_FALSE(
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj, VersionTuple())
+  .hasValue());
+}
+
+TEST(DarwinSDKInfo, VersionMappingParseError) {
+  llvm::json::Object Obj({{"test", "1.2"}});
+  EXPECT_FALSE(
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj, VersionTuple())
+  .hasValue());
+}
+
+TEST(DarwinSDKInfoTest, ParseAndTestMappingMacCatalyst) {
   llvm::json::Object Obj;
   Obj["Version"] = "11.0";
   Obj["MaximumDeploymentTarget"] = "11.99";
@@ -58,6 +119,53 @@
 VersionTuple(99, 99));
 }
 
+TEST(DarwinSDKInfoTest, ParseAndTestMappingIOSDerived) {
+  llvm::json::Object Obj;
+  Obj["Version"] = "15.0";
+  Obj["MaximumDeploymentTarget"] = "15.0.99";
+  llvm::json::Object VersionMap;
+  VersionMap["10.0"] = "10.0";
+  VersionMap["10.3.1"] = "10.2";
+  VersionMap["11.0"] = "11.0";
+  llvm::json::Object IOSToTvOS;
+  IOSToTvOS["iOS_tvOS"] = std::move(VersionMap);
+  Obj["VersionMap"] = std::move(IOSToTvOS);
+
+  auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON();
+  ASSERT_TRUE(SDKInfo);
+  EXPECT_EQ(SDKInfo->getVersion(), VersionTuple(15, 0));
+
+  // Verify that mapping is present for platforms that derive from iOS.
+  const auto *Mapping = SDKInfo->getVersionMapping(DarwinSDKInfo::OSEnvPair(
+  llvm::Triple::IOS,
+  llvm::Triple::UnknownEnvironment,
+  llvm::Triple::TvOS,
+  llvm::Triple::UnknownEnvironment));
+  ASSERT_TRUE(Mapping);
+
+  // Verify that the iOS versions that are present in the map are translated
+  // directly to their corresponding tvOS versions.
+  EXPECT_EQ(*Mapping->map(VersionTuple(10, 0), VersionTuple(), None),
+VersionTuple(10, 0));
+  EXPECT_EQ(*Mapping->map(VersionTuple(10, 3, 1), VersionTuple(), None),
+VersionTuple(10, 2));
+  EXPECT_EQ(*Mapping->map(VersionTuple(11, 0), VersionTuple(), None),
+VersionTuple(11, 0));
+
+  // Verify that an iOS version that's not present in the map is translated
+  // like the nearest major OS version.
+  EXPECT_EQ(*Mapping->map(VersionTuple(10, 1), VersionTuple(), None),
+VersionTuple(10, 0));
+
+  // Verify that the iOS versions that are outside of the mapped version
+  // range map to the min/max values passed to the `map` call.
+  EXPECT_EQ(*Mapping->map(VersionTuple(9, 0), VersionTuple(99, 99), None),
+   

[PATCH] D116615: [Clang] Extract availability mapping from VersionMap for watchOS/tvOS

2022-01-04 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
Herald added a subscriber: dexonsmith.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change makes it possible to extract iOS-to-another-platform version 
mappings from `VersionMap` in the `SDKSettings.json` file in Darwin SDKs, for 
example, `iOS_watchOS` and `iOS_tvOS`.

This code was originally authored by Alex Lorenz.

rdar://81491680


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116615

Files:
  clang/lib/Basic/DarwinSDKInfo.cpp
  clang/unittests/Basic/DarwinSDKInfoTest.cpp

Index: clang/unittests/Basic/DarwinSDKInfoTest.cpp
===
--- clang/unittests/Basic/DarwinSDKInfoTest.cpp
+++ clang/unittests/Basic/DarwinSDKInfoTest.cpp
@@ -13,6 +13,67 @@
 using namespace llvm;
 using namespace clang;
 
+// Check the version mapping logic in DarwinSDKInfo.
+TEST(DarwinSDKInfo, VersionMapping) {
+  llvm::json::Object Obj({{"3.0", "1.0"}, {"3.1", "1.2"}});
+  Optional Mapping =
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj,
+VersionTuple());
+  EXPECT_TRUE(Mapping.hasValue());
+  EXPECT_EQ(Mapping->getMinimumValue(), VersionTuple(1));
+
+  // Exact mapping.
+  EXPECT_EQ(Mapping->map(VersionTuple(3), VersionTuple(0, 1), None),
+VersionTuple(1));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 0), VersionTuple(0, 1), None),
+VersionTuple(1));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 0, 0), VersionTuple(0, 1), None),
+VersionTuple(1));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 1), VersionTuple(0, 1), None),
+VersionTuple(1, 2));
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 1, 0), VersionTuple(0, 1), None),
+VersionTuple(1, 2));
+
+  // Missing mapping - fallback to major.
+  EXPECT_EQ(Mapping->map(VersionTuple(3, 0, 1), VersionTuple(0, 1), None),
+VersionTuple(1));
+
+  // Minimum
+  EXPECT_EQ(Mapping->map(VersionTuple(2), VersionTuple(0, 1), None),
+VersionTuple(0, 1));
+
+  // Maximum
+  EXPECT_EQ(
+  Mapping->map(VersionTuple(4), VersionTuple(0, 1), VersionTuple(100)),
+  VersionTuple(100));
+}
+
+// Check the version mapping logic in DarwinSDKInfo.
+TEST(DarwinSDKInfo, VersionMappingMissingKey) {
+  llvm::json::Object Obj({{"3.0", "1.0"}, {"5.0", "1.2"}});
+  Optional Mapping =
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj,
+VersionTuple());
+  EXPECT_TRUE(Mapping.hasValue());
+  EXPECT_EQ(
+  Mapping->map(VersionTuple(4), VersionTuple(0, 1), VersionTuple(100)),
+  None);
+}
+
+TEST(DarwinSDKInfo, VersionMappingParseEmpty) {
+  llvm::json::Object Obj({});
+  EXPECT_FALSE(
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj, VersionTuple())
+  .hasValue());
+}
+
+TEST(DarwinSDKInfo, VersionMappingParseError) {
+  llvm::json::Object Obj({{"test", "1.2"}});
+  EXPECT_FALSE(
+  DarwinSDKInfo::RelatedTargetVersionMapping::parseJSON(Obj, VersionTuple())
+  .hasValue());
+}
+
 TEST(DarwinSDKInfoTest, ParseAndTestMapping) {
   llvm::json::Object Obj;
   Obj["Version"] = "11.0";
Index: clang/lib/Basic/DarwinSDKInfo.cpp
===
--- clang/lib/Basic/DarwinSDKInfo.cpp
+++ clang/lib/Basic/DarwinSDKInfo.cpp
@@ -84,6 +84,25 @@
   llvm::DenseMap>
   VersionMappings;
   if (const auto *VM = Obj->getObject("VersionMap")) {
+// FIXME: Generalize this out beyond iOS-deriving targets.
+// Look for ios_ version mapping for targets that derive from ios.
+for (const auto  : *VM) {
+  auto Pair = StringRef(KV.getFirst()).split("_");
+  if (Pair.first.compare_insensitive("ios") == 0) {
+llvm::Triple TT(llvm::Twine("--") + Pair.second.lower());
+if (TT.getOS() != llvm::Triple::UnknownOS) {
+  auto Mapping = RelatedTargetVersionMapping::parseJSON(
+  *KV.getSecond().getAsObject(), *MaximumDeploymentVersion);
+  if (Mapping)
+VersionMappings[OSEnvPair(llvm::Triple::IOS,
+  llvm::Triple::UnknownEnvironment,
+  TT.getOS(),
+  llvm::Triple::UnknownEnvironment)
+.Value] = std::move(Mapping);
+}
+  }
+}
+
 if (const auto *Mapping = VM->getObject("macOS_iOSMac")) {
   auto VersionMap = RelatedTargetVersionMapping::parseJSON(
   *Mapping, *MaximumDeploymentVersion);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116459: [Clang][Sema] Adjust formatting (NFC)

2021-12-31 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
Herald added a reviewer: aaron.ballman.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a preparation for another change in the watchOS/tvOS availability 
logic. It is extracted into a separate commit to simplify reviewing and to keep 
the linter happy at the same time.

rdar://81491680


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116459

Files:
  clang/lib/Sema/SemaDeclAttr.cpp


Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2625,37 +2625,37 @@
   NewII = ("watchos_app_extension");
 
 if (NewII) {
-auto adjustWatchOSVersion = [](VersionTuple Version) -> VersionTuple {
-  if (Version.empty())
-return Version;
-  auto Major = Version.getMajor();
-  auto NewMajor = Major >= 9 ? Major - 7 : 0;
-  if (NewMajor >= 2) {
-if (Version.getMinor().hasValue()) {
-  if (Version.getSubminor().hasValue())
-return VersionTuple(NewMajor, Version.getMinor().getValue(),
-Version.getSubminor().getValue());
-  else
-return VersionTuple(NewMajor, Version.getMinor().getValue());
-}
-return VersionTuple(NewMajor);
+  auto adjustWatchOSVersion = [](VersionTuple Version) -> VersionTuple {
+if (Version.empty())
+  return Version;
+auto Major = Version.getMajor();
+auto NewMajor = Major >= 9 ? Major - 7 : 0;
+if (NewMajor >= 2) {
+  if (Version.getMinor().hasValue()) {
+if (Version.getSubminor().hasValue())
+  return VersionTuple(NewMajor, Version.getMinor().getValue(),
+  Version.getSubminor().getValue());
+else
+  return VersionTuple(NewMajor, Version.getMinor().getValue());
   }
+  return VersionTuple(NewMajor);
+}
 
-  return VersionTuple(2, 0);
-};
+return VersionTuple(2, 0);
+  };
 
-auto NewIntroduced = adjustWatchOSVersion(Introduced.Version);
-auto NewDeprecated = adjustWatchOSVersion(Deprecated.Version);
-auto NewObsoleted = adjustWatchOSVersion(Obsoleted.Version);
-
-AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
-ND, AL, NewII, true /*Implicit*/, NewIntroduced, NewDeprecated,
-NewObsoleted, IsUnavailable, Str, IsStrict, Replacement,
-Sema::AMK_None,
-PriorityModifier + Sema::AP_InferredFromOtherPlatform);
-if (NewAttr)
-  D->addAttr(NewAttr);
-  }
+  auto NewIntroduced = adjustWatchOSVersion(Introduced.Version);
+  auto NewDeprecated = adjustWatchOSVersion(Deprecated.Version);
+  auto NewObsoleted = adjustWatchOSVersion(Obsoleted.Version);
+
+  AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
+  ND, AL, NewII, true /*Implicit*/, NewIntroduced, NewDeprecated,
+  NewObsoleted, IsUnavailable, Str, IsStrict, Replacement,
+  Sema::AMK_None,
+  PriorityModifier + Sema::AP_InferredFromOtherPlatform);
+  if (NewAttr)
+D->addAttr(NewAttr);
+}
   } else if (S.Context.getTargetInfo().getTriple().isTvOS()) {
 // Transcribe "ios" to "tvos" (and add a new attribute) if the versioning
 // matches before the start of the tvOS platform.
@@ -2673,7 +2673,7 @@
   PriorityModifier + Sema::AP_InferredFromOtherPlatform);
   if (NewAttr)
 D->addAttr(NewAttr);
-  }
+}
   } else if (S.Context.getTargetInfo().getTriple().getOS() ==
  llvm::Triple::IOS &&
  S.Context.getTargetInfo().getTriple().isMacCatalystEnvironment()) 
{


Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2625,37 +2625,37 @@
   NewII = ("watchos_app_extension");
 
 if (NewII) {
-auto adjustWatchOSVersion = [](VersionTuple Version) -> VersionTuple {
-  if (Version.empty())
-return Version;
-  auto Major = Version.getMajor();
-  auto NewMajor = Major >= 9 ? Major - 7 : 0;
-  if (NewMajor >= 2) {
-if (Version.getMinor().hasValue()) {
-  if (Version.getSubminor().hasValue())
-return VersionTuple(NewMajor, Version.getMinor().getValue(),
-Version.getSubminor().getValue());
-  else
-return VersionTuple(NewMajor, Version.getMinor().getValue());
-}
-return VersionTuple(NewMajor);
+  auto adjustWatchOSVersion = [](VersionTuple Version) -> VersionTuple {
+if (Version.empty())
+  return 

[PATCH] D116412: [Clang][Sema] Fix attribute mismatch warning for ObjC class properties

2021-12-30 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If a class declares an instance property, and an inheritor class declares a 
class property with the same name, Clang Sema currently treats the latter as an 
overridden property, and compares the attributes of the two properties to check 
for a mismatch. The resulting diagnostics might be misleading, since neither of 
the properties actually overrides the another one.

rdar://86018435


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116412

Files:
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/test/SemaObjC/class-property-inheritance.m

Index: clang/test/SemaObjC/class-property-inheritance.m
===
--- /dev/null
+++ clang/test/SemaObjC/class-property-inheritance.m
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+@class MyObject;
+
+@interface TopClassWithInstanceProperty
+@property(nullable, readonly, strong) MyObject *foo;
+@end
+
+@interface SubClassWithClassProperty : TopClassWithInstanceProperty
+@property(nonnull, readonly, copy, class) MyObject *foo;
+@end
+
+@interface TopClassWithClassProperty
+@property(nullable, readonly, class) MyObject *foo;
+@end
+
+@interface SubClassWithInstanceProperty : TopClassWithClassProperty
+@property(nonnull, readonly, copy) MyObject *foo;
+@end
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -225,43 +225,56 @@
   if (Res->getType().getObjCLifetime())
 checkPropertyDeclWithOwnership(*this, Res);
 
-  llvm::SmallPtrSet KnownProtos;
-  if (ObjCInterfaceDecl *IFace = dyn_cast(ClassDecl)) {
-// For a class, compare the property against a property in our superclass.
-bool FoundInSuper = false;
-ObjCInterfaceDecl *CurrentInterfaceDecl = IFace;
-while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
-  if (ObjCPropertyDecl *SuperProp =
-  Super->lookup(Res->getDeclName()).find_first()) {
-DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(), false);
-FoundInSuper = true;
-break;
+  // For an instance property, check consistency with the properties of
+  // superclasses.
+  if (Res->isInstanceProperty()) {
+llvm::SmallPtrSet KnownProtos;
+if (ObjCInterfaceDecl *IFace = dyn_cast(ClassDecl)) {
+  // For a class, compare the property against a property in our superclass.
+  bool FoundInSuper = false;
+  ObjCInterfaceDecl *CurrentInterfaceDecl = IFace;
+  while (ObjCInterfaceDecl *Super = CurrentInterfaceDecl->getSuperClass()) {
+ObjCPropertyDecl *SuperProp = nullptr;
+for (auto *LookupResult : Super->lookup(Res->getDeclName())) {
+  if (auto *Prop = dyn_cast(LookupResult)) {
+if (Prop->isInstanceProperty()) {
+  SuperProp = Prop;
+  break;
+}
+  }
+}
+if (SuperProp) {
+  DiagnosePropertyMismatch(Res, SuperProp, Super->getIdentifier(),
+   false);
+  FoundInSuper = true;
+  break;
+}
+CurrentInterfaceDecl = Super;
   }
-  CurrentInterfaceDecl = Super;
-}
 
-if (FoundInSuper) {
-  // Also compare the property against a property in our protocols.
-  for (auto *P : CurrentInterfaceDecl->protocols()) {
-CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
+  if (FoundInSuper) {
+// Also compare the property against a property in our protocols.
+for (auto *P : CurrentInterfaceDecl->protocols()) {
+  CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
+}
+  } else {
+// Slower path: look in all protocols we referenced.
+for (auto *P : IFace->all_referenced_protocols()) {
+  CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
+}
   }
+} else if (ObjCCategoryDecl *Cat = dyn_cast(ClassDecl)) {
+  // We don't check if class extension. Because properties in class
+  // extension are meant to override some of the attributes and checking has
+  // already done when property in class extension is constructed.
+  if (!Cat->IsClassExtension())
+for (auto *P : Cat->protocols())
+  CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
 } else {
-  // Slower path: look in all protocols we referenced.
-  for (auto *P : IFace->all_referenced_protocols()) {
+  ObjCProtocolDecl *Proto = cast(ClassDecl);
+  for (auto *P : Proto->protocols())
 CheckPropertyAgainstProtocol(*this, Res, P, KnownProtos);
-  }
 }
-  } else if (ObjCCategoryDecl *Cat = dyn_cast(ClassDecl)) {
-// We don't check if class extension. Because 

[PATCH] D116272: [Clang][Sema] Avoid crashing for va_arg expressions with bool argument

2021-12-24 Thread Egor Zhdan via Phabricator via cfe-commits
egorzhdan created this revision.
egorzhdan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change fixes a compiler crash that was introduced in 
https://reviews.llvm.org/D103611: `Sema::BuildVAArgExpr` attempted to retrieve 
a corresponding signed type for `bool` by calling 
`ASTContext::getCorrespondingSignedType`.

rdar://86580370


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116272

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/varargs.cpp


Index: clang/test/SemaCXX/varargs.cpp
===
--- clang/test/SemaCXX/varargs.cpp
+++ clang/test/SemaCXX/varargs.cpp
@@ -53,6 +53,8 @@
 
   // Ensure that signed vs unsigned doesn't matter either.
   (void)__builtin_va_arg(ap, unsigned int);
+
+  (void)__builtin_va_arg(ap, bool); // expected-warning {{second argument to 
'va_arg' is of promotable type 'bool'; this va_arg has undefined behavior 
because arguments will be promoted to 'int'}}
 }
 
 #if __cplusplus >= 201103L
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15913,7 +15913,7 @@
   // promoted type and the underlying type are the same except for
   // signedness. Ask the AST for the correctly corresponding type and see
   // if that's compatible.
-  if (!PromoteType.isNull() &&
+  if (!PromoteType.isNull() && !UnderlyingType->isBooleanType() &&
   PromoteType->isUnsignedIntegerType() !=
   UnderlyingType->isUnsignedIntegerType()) {
 UnderlyingType =


Index: clang/test/SemaCXX/varargs.cpp
===
--- clang/test/SemaCXX/varargs.cpp
+++ clang/test/SemaCXX/varargs.cpp
@@ -53,6 +53,8 @@
 
   // Ensure that signed vs unsigned doesn't matter either.
   (void)__builtin_va_arg(ap, unsigned int);
+
+  (void)__builtin_va_arg(ap, bool); // expected-warning {{second argument to 'va_arg' is of promotable type 'bool'; this va_arg has undefined behavior because arguments will be promoted to 'int'}}
 }
 
 #if __cplusplus >= 201103L
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15913,7 +15913,7 @@
   // promoted type and the underlying type are the same except for
   // signedness. Ask the AST for the correctly corresponding type and see
   // if that's compatible.
-  if (!PromoteType.isNull() &&
+  if (!PromoteType.isNull() && !UnderlyingType->isBooleanType() &&
   PromoteType->isUnsignedIntegerType() !=
   UnderlyingType->isUnsignedIntegerType()) {
 UnderlyingType =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits