[PATCH] D123907: [HLSL] Add shader attribute

2022-04-16 Thread Xiang Li via Phabricator via cfe-commits
python3kgae created this revision.
python3kgae added reviewers: aaron.ballman, rnk, jdoerfert, MaskRay, rsmith.
Herald added a subscriber: StephenFan.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Shader attribute is for shader library identify entry functions.
Here's an example,

[shader("pixel")]
float ps_main() : SV_Target {

  return 1;

}

When compile this shader to library target like -E lib_6_3, compiler needs to 
know ps_main is an entry function for pixel shader. Shader attribute is to 
offer the information.

A new attribute HLSLShader is added to support shader attribute. It has an 
EnumArgument which included all possible shader stages.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123907

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaHLSL/shader_attr.hlsl

Index: clang/test/SemaHLSL/shader_attr.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/shader_attr.hlsl
@@ -0,0 +1,76 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s -DFAIL -verify
+
+
+#ifdef FAIL
+
+// expected-warning@+1 {{'shader' attribute only applies to global functions}}
+[shader("compute")]
+struct Fido {
+  // expected-warning@+1 {{'shader' attribute only applies to global functions}}
+  [shader("pixel")]
+  void wag() {}
+
+  // expected-warning@+1 {{'shader' attribute only applies to global functions}}
+  [shader("vertex")]
+  static void oops() {}
+};
+
+// expected-warning@+1 {{'shader' attribute only applies to global functions}}
+  [shader("vertex")]
+static void oops() {}
+
+namespace spec {
+// expected-warning@+1 {{'shader' attribute only applies to global functions}}
+  [shader("vertex")]
+static void oops() {}
+}
+
+// expected-error@+1 {{'shader' attribute parameters do not match the previous declaration}}
+[shader("compute")]
+// expected-note@+1 {{conflicting attribute is here}}
+[shader("vertex")]
+int doubledUp() {
+  return 1;
+}
+
+// expected-note@+1 {{conflicting attribute is here}}
+[shader("vertex")]
+int forwardDecl();
+
+// expected-error@+1 {{'shader' attribute parameters do not match the previous declaration}}
+[shader("compute")]
+int forwardDecl() {
+  return 1;
+}
+
+
+// expected-error@+1 {{'shader' attribute takes one argument}}
+[shader()]
+// expected-error@+1 {{'shader' attribute takes one argument}}
+[shader(1,2)]
+// expected-error@+1 {{'shader' attribute requires a string}}
+[shader(1)]
+// expected-error@+1 {{'shader' attribute argument not supported: 'cs'}}
+[shader("cs")]
+
+#endif  // END of FAIL
+
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+[shader("compute")]
+int entry() {
+ return 1;
+}
+
+// Because these two attributes match, they should both appear in the AST
+[shader("compute")]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+int secondFn();
+
+[shader("compute")]
+// CHECK:HLSLShaderAttr 0x{{[0-9a-fA-F]+}}  Compute
+int secondFn() {
+  return 1;
+}
+
+
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6940,6 +6940,44 @@
   D->addAttr(::new (S.Context) HLSLSV_GroupIndexAttr(S.Context, AL));
 }
 
+static void handleHLSLShaderAttr(Sema , Decl *D, const ParsedAttr ) {
+  if (AL.getNumArgs() != 1) {
+S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
+return;
+  }
+
+  StringRef Str;
+  SourceLocation ArgLoc;
+  if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, ))
+return;
+
+  HLSLShaderAttr::ShaderStage Stage;
+  if (!HLSLShaderAttr::ConvertStrToShaderStage(Str, Stage)) {
+S.Diag(AL.getLoc(), diag::err_hlsl_invalid_attribute_argument)
+<< AL << "'" + std::string(Str) + "'";
+return;
+  }
+
+  // TODO: check function match the shader stage.
+
+  HLSLShaderAttr *NewAttr = S.mergeHLSLShaderAttr(D, AL, Stage);
+  if (NewAttr)
+D->addAttr(NewAttr);
+}
+
+HLSLShaderAttr *Sema::mergeHLSLShaderAttr(Decl *D,
+  const AttributeCommonInfo ,
+  HLSLShaderAttr::ShaderStage Stage) {
+  if (HLSLShaderAttr *NT = D->getAttr()) {
+if (NT->getStage() != Stage) {
+  Diag(NT->getLocation(), diag::err_hlsl_attribute_param_mismatch) << AL;
+  Diag(AL.getLoc(), diag::note_conflicting_attribute);
+}
+return nullptr;
+  }
+  return HLSLShaderAttr::Create(Context, Stage, AL);
+}
+
 static void handleMSInheritanceAttr(Sema , Decl *D, const ParsedAttr ) {
   if (!S.LangOpts.CPlusPlus) {
 

[PATCH] D123898: Fix crash in ObjC codegen introduced with 5ab6ee75994d645725264e757d67bbb1c96fb2b6

2022-04-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

LGTM.  Could you add a test case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123898

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


[PATCH] D123889: [clang-tidy] Improve macro handling in modernize-macro-to-enum

2022-04-16 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood updated this revision to Diff 423265.
LegalizeAdulthood added a comment.

Internal methods are private


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

https://reviews.llvm.org/D123889

Files:
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
@@ -181,6 +181,12 @@
 #define USE_IFDEF 1
 #define USE_IFNDEF 1
 
+// Undef'ing first and then defining later should still exclude this macro
+#undef USE_UINT64
+#define USE_UINT64 0
+#undef USE_INT64
+#define USE_INT64 0
+
 #if defined(USE_FOO) && USE_FOO
 extern void foo();
 #else
@@ -243,6 +249,27 @@
 #define IFNDEF3 3
 #endif
 
+// Macros used in conditions are invalidated, even if they look
+// like enums after they are used in conditions.
+#if DEFINED_LATER1
+#endif
+#ifdef DEFINED_LATER2
+#endif
+#ifndef DEFINED_LATER3
+#endif
+#undef DEFINED_LATER4
+#if ((defined(DEFINED_LATER5) || DEFINED_LATER6) && DEFINED_LATER7) || (DEFINED_LATER8 > 10)
+#endif
+
+#define DEFINED_LATER1 1
+#define DEFINED_LATER2 2
+#define DEFINED_LATER3 3
+#define DEFINED_LATER4 4
+#define DEFINED_LATER5 5
+#define DEFINED_LATER6 6
+#define DEFINED_LATER7 7
+#define DEFINED_LATER8 8
+
 // Sometimes an argument to ifdef can be classified as a keyword token.
 #ifdef __restrict
 #endif
Index: clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
@@ -222,6 +222,8 @@
   void conditionStart(const SourceLocation );
   void checkCondition(SourceRange ConditionRange);
   void checkName(const Token );
+  void rememberExpressionName(const Token );
+  void invalidateExpressionNames();
   void warnMacroEnum(const EnumMacro ) const;
   void fixEnumMacro(const MacroList ) const;
 
@@ -230,6 +232,7 @@
   const SourceManager 
   SmallVector Enums;
   SmallVector Files;
+  std::vector ExpressionNames;
   FileState *CurrentFile = nullptr;
 };
 
@@ -284,8 +287,9 @@
 }
 
 void MacroToEnumCallbacks::checkName(const Token ) {
-  StringRef Id = getTokenName(MacroNameTok);
+  rememberExpressionName(MacroNameTok);
 
+  StringRef Id = getTokenName(MacroNameTok);
   llvm::erase_if(Enums, [](const MacroList ) {
 return llvm::any_of(MacroList, [](const EnumMacro ) {
   return getTokenName(Macro.Name) == Id;
@@ -293,6 +297,14 @@
   });
 }
 
+void MacroToEnumCallbacks::rememberExpressionName(const Token ) {
+  std::string Id = getTokenName(MacroNameTok).str();
+  auto Pos = llvm::lower_bound(ExpressionNames, Id);
+  if (Pos == ExpressionNames.end() || *Pos != Id) {
+ExpressionNames.insert(Pos, Id);
+  }
+}
+
 void MacroToEnumCallbacks::FileChanged(SourceLocation Loc,
FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -384,6 +396,8 @@
 void MacroToEnumCallbacks::MacroUndefined(const Token ,
   const MacroDefinition ,
   const MacroDirective *Undef) {
+  rememberExpressionName(MacroNameTok);
+
   auto MatchesToken = [](const EnumMacro ) {
 return getTokenName(Macro.Name) == getTokenName(MacroNameTok);
   };
@@ -447,7 +461,19 @@
 CurrentFile->GuardScanner = IncludeGuard::IfGuard;
 }
 
+void MacroToEnumCallbacks::invalidateExpressionNames() {
+  for (const std::string  : ExpressionNames) {
+llvm::erase_if(Enums, [Id](const MacroList ) {
+  return llvm::any_of(MacroList, [](const EnumMacro ) {
+return getTokenName(Macro.Name) == Id;
+  });
+});
+  }
+}
+
 void MacroToEnumCallbacks::EndOfMainFile() {
+  invalidateExpressionNames();
+
   for (const MacroList  : Enums) {
 if (MacroList.empty())
   continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123889: [clang-tidy] Improve macro handling in modernize-macro-to-enum

2022-04-16 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood updated this revision to Diff 423259.
LegalizeAdulthood added a comment.

Make method names symmetric


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

https://reviews.llvm.org/D123889

Files:
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
@@ -181,6 +181,12 @@
 #define USE_IFDEF 1
 #define USE_IFNDEF 1
 
+// Undef'ing first and then defining later should still exclude this macro
+#undef USE_UINT64
+#define USE_UINT64 0
+#undef USE_INT64
+#define USE_INT64 0
+
 #if defined(USE_FOO) && USE_FOO
 extern void foo();
 #else
@@ -243,6 +249,27 @@
 #define IFNDEF3 3
 #endif
 
+// Macros used in conditions are invalidated, even if they look
+// like enums after they are used in conditions.
+#if DEFINED_LATER1
+#endif
+#ifdef DEFINED_LATER2
+#endif
+#ifndef DEFINED_LATER3
+#endif
+#undef DEFINED_LATER4
+#if ((defined(DEFINED_LATER5) || DEFINED_LATER6) && DEFINED_LATER7) || (DEFINED_LATER8 > 10)
+#endif
+
+#define DEFINED_LATER1 1
+#define DEFINED_LATER2 2
+#define DEFINED_LATER3 3
+#define DEFINED_LATER4 4
+#define DEFINED_LATER5 5
+#define DEFINED_LATER6 6
+#define DEFINED_LATER7 7
+#define DEFINED_LATER8 8
+
 // Sometimes an argument to ifdef can be classified as a keyword token.
 #ifdef __restrict
 #endif
Index: clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
@@ -193,6 +193,7 @@
   void Endif(SourceLocation Loc, SourceLocation IfLoc) override;
   void PragmaDirective(SourceLocation Loc,
PragmaIntroducerKind Introducer) override;
+  void invalidateExpressionNames();
 
   // After we've seen everything, issue warnings and fix-its.
   void EndOfMainFile() override;
@@ -222,6 +223,7 @@
   void conditionStart(const SourceLocation );
   void checkCondition(SourceRange ConditionRange);
   void checkName(const Token );
+  void rememberExpressionName(const Token );
   void warnMacroEnum(const EnumMacro ) const;
   void fixEnumMacro(const MacroList ) const;
 
@@ -230,6 +232,7 @@
   const SourceManager 
   SmallVector Enums;
   SmallVector Files;
+  std::vector ExpressionNames;
   FileState *CurrentFile = nullptr;
 };
 
@@ -284,8 +287,9 @@
 }
 
 void MacroToEnumCallbacks::checkName(const Token ) {
-  StringRef Id = getTokenName(MacroNameTok);
+  rememberExpressionName(MacroNameTok);
 
+  StringRef Id = getTokenName(MacroNameTok);
   llvm::erase_if(Enums, [](const MacroList ) {
 return llvm::any_of(MacroList, [](const EnumMacro ) {
   return getTokenName(Macro.Name) == Id;
@@ -293,6 +297,14 @@
   });
 }
 
+void MacroToEnumCallbacks::rememberExpressionName(const Token ) {
+  std::string Id = getTokenName(MacroNameTok).str();
+  auto Pos = llvm::lower_bound(ExpressionNames, Id);
+  if (Pos == ExpressionNames.end() || *Pos != Id) {
+ExpressionNames.insert(Pos, Id);
+  }
+}
+
 void MacroToEnumCallbacks::FileChanged(SourceLocation Loc,
FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -384,6 +396,8 @@
 void MacroToEnumCallbacks::MacroUndefined(const Token ,
   const MacroDefinition ,
   const MacroDirective *Undef) {
+  rememberExpressionName(MacroNameTok);
+
   auto MatchesToken = [](const EnumMacro ) {
 return getTokenName(Macro.Name) == getTokenName(MacroNameTok);
   };
@@ -447,7 +461,19 @@
 CurrentFile->GuardScanner = IncludeGuard::IfGuard;
 }
 
+void MacroToEnumCallbacks::invalidateExpressionNames() {
+  for (const std::string  : ExpressionNames) {
+llvm::erase_if(Enums, [Id](const MacroList ) {
+  return llvm::any_of(MacroList, [](const EnumMacro ) {
+return getTokenName(Macro.Name) == Id;
+  });
+});
+  }
+}
+
 void MacroToEnumCallbacks::EndOfMainFile() {
+  invalidateExpressionNames();
+
   for (const MacroList  : Enums) {
 if (MacroList.empty())
   continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123889: [clang-tidy] Improve macro handling in modernize-macro-to-enum

2022-04-16 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood updated this revision to Diff 423258.
LegalizeAdulthood added a comment.

Add more test cases


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

https://reviews.llvm.org/D123889

Files:
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
@@ -181,6 +181,12 @@
 #define USE_IFDEF 1
 #define USE_IFNDEF 1
 
+// Undef'ing first and then defining later should still exclude this macro
+#undef USE_UINT64
+#define USE_UINT64 0
+#undef USE_INT64
+#define USE_INT64 0
+
 #if defined(USE_FOO) && USE_FOO
 extern void foo();
 #else
@@ -243,6 +249,27 @@
 #define IFNDEF3 3
 #endif
 
+// Macros used in conditions are invalidated, even if they look
+// like enums after they are used in conditions.
+#if DEFINED_LATER1
+#endif
+#ifdef DEFINED_LATER2
+#endif
+#ifndef DEFINED_LATER3
+#endif
+#undef DEFINED_LATER4
+#if ((defined(DEFINED_LATER5) || DEFINED_LATER6) && DEFINED_LATER7) || (DEFINED_LATER8 > 10)
+#endif
+
+#define DEFINED_LATER1 1
+#define DEFINED_LATER2 2
+#define DEFINED_LATER3 3
+#define DEFINED_LATER4 4
+#define DEFINED_LATER5 5
+#define DEFINED_LATER6 6
+#define DEFINED_LATER7 7
+#define DEFINED_LATER8 8
+
 // Sometimes an argument to ifdef can be classified as a keyword token.
 #ifdef __restrict
 #endif
Index: clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
@@ -193,6 +193,7 @@
   void Endif(SourceLocation Loc, SourceLocation IfLoc) override;
   void PragmaDirective(SourceLocation Loc,
PragmaIntroducerKind Introducer) override;
+  void invalidateExpressionNames();
 
   // After we've seen everything, issue warnings and fix-its.
   void EndOfMainFile() override;
@@ -222,6 +223,7 @@
   void conditionStart(const SourceLocation );
   void checkCondition(SourceRange ConditionRange);
   void checkName(const Token );
+  void rememberExpressionToken(const Token );
   void warnMacroEnum(const EnumMacro ) const;
   void fixEnumMacro(const MacroList ) const;
 
@@ -230,6 +232,7 @@
   const SourceManager 
   SmallVector Enums;
   SmallVector Files;
+  std::vector ExpressionNames;
   FileState *CurrentFile = nullptr;
 };
 
@@ -284,8 +287,9 @@
 }
 
 void MacroToEnumCallbacks::checkName(const Token ) {
-  StringRef Id = getTokenName(MacroNameTok);
+  rememberExpressionToken(MacroNameTok);
 
+  StringRef Id = getTokenName(MacroNameTok);
   llvm::erase_if(Enums, [](const MacroList ) {
 return llvm::any_of(MacroList, [](const EnumMacro ) {
   return getTokenName(Macro.Name) == Id;
@@ -293,6 +297,14 @@
   });
 }
 
+void MacroToEnumCallbacks::rememberExpressionToken(const Token ) {
+  std::string Id = getTokenName(MacroNameTok).str();
+  auto Pos = llvm::lower_bound(ExpressionNames, Id);
+  if (Pos == ExpressionNames.end() || *Pos != Id) {
+ExpressionNames.insert(Pos, Id);
+  }
+}
+
 void MacroToEnumCallbacks::FileChanged(SourceLocation Loc,
FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -384,6 +396,8 @@
 void MacroToEnumCallbacks::MacroUndefined(const Token ,
   const MacroDefinition ,
   const MacroDirective *Undef) {
+  rememberExpressionToken(MacroNameTok);
+
   auto MatchesToken = [](const EnumMacro ) {
 return getTokenName(Macro.Name) == getTokenName(MacroNameTok);
   };
@@ -447,7 +461,19 @@
 CurrentFile->GuardScanner = IncludeGuard::IfGuard;
 }
 
+void MacroToEnumCallbacks::invalidateExpressionNames() {
+  for (const std::string  : ExpressionNames) {
+llvm::erase_if(Enums, [Id](const MacroList ) {
+  return llvm::any_of(MacroList, [](const EnumMacro ) {
+return getTokenName(Macro.Name) == Id;
+  });
+});
+  }
+}
+
 void MacroToEnumCallbacks::EndOfMainFile() {
+  invalidateExpressionNames();
+
   for (const MacroList  : Enums) {
 if (MacroList.empty())
   continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked 3 inline comments as done.
kwk added inline comments.



Comment at: clang/lib/Format/Format.cpp:2692-2695
+  for (int i = Matches.size() - 1; i > 0; i--) {
+if (!Matches[i].empty())
+  return Matches[i];
+  }

owenpan wrote:
> I think you missed `Matches[0]`.
I did miss it and fixed it but it doesn't make much sense to use the first 
match because that's always the overall string that's being matched. 
Nevertheless, I've used your porposed reverse loop and the logic is better if 
it includes even the first match.



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:176-188
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ 
]*([^;]+;)))";
+
+// Returns the last match group in the above regex (IncludeRegexPattern) that
+// is not empty.
+StringRef getIncludeNameFromMatches(const SmallVectorImpl ) 
{
+  for (int i = Matches.size() - 1; i > 0; i--) {

owenpan wrote:
> owenpan wrote:
> > If these are the same as in `Format.cpp` above, we should move the 
> > definitions to `HeaderIncludes.h`.
> > If these are the same as in `Format.cpp` above, we should move the 
> > definitions to `HeaderIncludes.h`.
> 
> I meant we should remove the definitions from `Format.cpp` and add the 
> declarations to `HeaderIncludes.h`.
I think I've done what you intended me to do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

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


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 423257.
kwk marked an inline comment as done.
kwk added a comment.

- Make function static


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -274,8 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 423256.
kwk added a comment.

- Use proposed reverse loop


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -274,8 +267,7 @@
   

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 423255.
kwk added a comment.

- Added llvm:: namespace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -274,8 +267,7 @@
   

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 423254.
kwk added a comment.

- Put shared code for finding include names HeaderIncludes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -274,8 +267,7 

[PATCH] D116203: [clang] adds unary type transformations as compiler built-ins

2022-04-16 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb marked an inline comment as done.
cjdb added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:9113
+  BaseType.isReferenceable() || BaseType->isVoidType()
+  ? BuildPointerType(BaseType.getNonReferenceType(), Loc, EntityName)
+  : BaseType;

cjdb wrote:
> erichkeane wrote:
> > Do we at any point want this builtin to be address-space aware?  
> I'm not against this functionality, but there isn't (currently) motivation 
> for it. WDYT about `__add_pointer(T, address_space)`? Do we want this to be a 
> separate builtin (e.g. `__add_pointer_with_address_space(T, address_space)`)?
I don't think handling address spaces is worth the trouble: we can always do 
`__add_pointer(int __attribute__((address_space(1` if desired (I added two 
tests to confirm this). I did need to fix `__remove_pointer` so that it also 
removes address spaces, so thank you for flagging this :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116203

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


[PATCH] D119136: [clang] Implement Change scope of lambda trailing-return-type

2022-04-16 Thread Noel Grandin via Phabricator via cfe-commits
grandinj added a comment.

I note that building on Ubuntu, I am now seeing failures like:

env/gbuildtojson/gbuildtojson.cxx:10:
In file included from 
/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/algorithm:74:
In file included from 
/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/pstl/glue_algorithm_defs.h:13:
In file included from 
/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/functional:61:
In file included from 
/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/unordered_map:52:
In file included from 
/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/debug/unordered_map:49:
/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/debug/safe_unordered_container.h:71:28:
 error: captured variable '__local_end' cannot appear here

  [__local_end](__decltype(__local_end) __it)
   ^

/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/debug/safe_unordered_container.h:71:4:
 note: variable '__local_end' is explicitly captured here

  [__local_end](__decltype(__local_end) __it)
   ^

/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/debug/safe_unordered_container.h:69:2:
 note: '__local_end' declared here

  auto __local_end = _M_cont()._M_base().cend(0);
  ^

/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/debug/safe_unordered_container.h:79:44:
 error: captured variable '__end' cannot appear here

  this->_M_invalidate_if([__end](__decltype(__end) __it)
^

/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/debug/safe_unordered_container.h:79:26:
 note: variable '__end' is explicitly captured here

  this->_M_invalidate_if([__end](__decltype(__end) __it)
  ^

/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/debug/safe_unordered_container.h:78:2:
 note: '__end' declared here

  auto __end = _M_cont()._M_base().cend();
  ^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119136

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


[PATCH] D122865: [HLSL][clang][Driver] Support target profile command line option.

2022-04-16 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

Seems to be fine now. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122865

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


[PATCH] D123898: Fix crash in ObjC codegen introduced with 5ab6ee75994d645725264e757d67bbb1c96fb2b6

2022-04-16 Thread David Chisnall via Phabricator via cfe-commits
theraven created this revision.
theraven added reviewers: rjmccall, triplef.
Herald added a project: All.
theraven requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

5ab6ee75994d645725264e757d67bbb1c96fb2b6 
 assumed 
that if `RValue::isScalar()` returns true then `RValue::getScalarVal` will 
return a valid value.  This is not the case when the return value is `void` and 
so void message returns would crash if they hit this path.  This is triggered 
only for cases where the nil-handling path needs to do something non-trivial 
(destroy arguments that should be consumed by the callee).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123898

Files:
  clang/lib/CodeGen/CGObjCGNU.cpp


Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -2837,11 +2837,13 @@
 // Enter the continuation block and emit a phi if required.
 CGF.EmitBlock(continueBB);
 if (msgRet.isScalar()) {
-  llvm::Value *v = msgRet.getScalarVal();
-  llvm::PHINode *phi = Builder.CreatePHI(v->getType(), 2);
-  phi->addIncoming(v, nonNilPathBB);
-  phi->addIncoming(CGM.EmitNullConstant(ResultType), nilPathBB);
-  msgRet = RValue::get(phi);
+  // If the return type is void, do nothing
+  if (llvm::Value *v = msgRet.getScalarVal()) {
+llvm::PHINode *phi = Builder.CreatePHI(v->getType(), 2);
+phi->addIncoming(v, nonNilPathBB);
+phi->addIncoming(CGM.EmitNullConstant(ResultType), nilPathBB);
+msgRet = RValue::get(phi);
+  }
 } else if (msgRet.isAggregate()) {
   // Aggregate zeroing is handled in nilCleanupBB when it's required.
 } else /* isComplex() */ {


Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -2837,11 +2837,13 @@
 // Enter the continuation block and emit a phi if required.
 CGF.EmitBlock(continueBB);
 if (msgRet.isScalar()) {
-  llvm::Value *v = msgRet.getScalarVal();
-  llvm::PHINode *phi = Builder.CreatePHI(v->getType(), 2);
-  phi->addIncoming(v, nonNilPathBB);
-  phi->addIncoming(CGM.EmitNullConstant(ResultType), nilPathBB);
-  msgRet = RValue::get(phi);
+  // If the return type is void, do nothing
+  if (llvm::Value *v = msgRet.getScalarVal()) {
+llvm::PHINode *phi = Builder.CreatePHI(v->getType(), 2);
+phi->addIncoming(v, nonNilPathBB);
+phi->addIncoming(CGM.EmitNullConstant(ResultType), nilPathBB);
+msgRet = RValue::get(phi);
+  }
 } else if (msgRet.isAggregate()) {
   // Aggregate zeroing is handled in nilCleanupBB when it's required.
 } else /* isComplex() */ {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7692fc8 - Revert "[randstruct] Enforce using a designated init for a randomized struct"

2022-04-16 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-04-16T11:11:32-04:00
New Revision: 7692fc81e016a5674464fa77732bd1c7a3903f17

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

LOG: Revert "[randstruct] Enforce using a designated init for a randomized 
struct"

This reverts commit aed923b1246ac38335b222b89594516fcf0d6385.

It causes some buildbot test failures.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaInit.cpp

Removed: 
clang/test/Sema/init-randomized-struct.c



diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e79a40d62381f..a14194d271a71 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11602,9 +11602,7 @@ def err_hlsl_pointers_unsupported : Error<
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
 
-// Layout randomization diagnostics.
-def err_non_designated_init_used : Error<
-  "a randomized struct can only be initialized with a designated initializer">;
+// Layout randomization warning.
 def err_cast_from_randomized_struct : Error<
   "casting from randomized structure pointer type %0 to %1">;
 } // end of sema component.

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 233be547bf118..c3bbefbaaed1b 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -2123,7 +2123,6 @@ void InitListChecker::CheckStructUnionTypes(
   // worthwhile to skip over the rest of the initializer, though.
   RecordDecl *RD = DeclType->castAs()->getDecl();
   RecordDecl::field_iterator FieldEnd = RD->field_end();
-  size_t NumRecordFields = std::distance(RD->field_begin(), RD->field_end());
   bool CheckForMissingFields =
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
@@ -2173,35 +2172,6 @@ void InitListChecker::CheckStructUnionTypes(
   break;
 }
 
-// Check if this is an initializer of forms:
-//
-//   struct foo f = {};
-//   struct foo g = {0};
-//
-// These are okay for randomized structures. [C99 6.7.8p19]
-//
-// Also, if there is only one element in the structure, we allow something
-// like this, because it's really not randomized in the tranditional sense.
-//
-//   struct foo h = {bar};
-auto IsZeroInitializer = [&](const Expr *I) {
-  if (IList->getNumInits() == 1) {
-if (NumRecordFields == 1)
-  return true;
-if (const auto *IL = dyn_cast(I))
-  return IL->getValue().isZero();
-  }
-  return false;
-};
-
-// Don't allow non-designated initializers on randomized structures.
-if (RD->isRandomized() && !IsZeroInitializer(Init)) {
-  if (!VerifyOnly)
-SemaRef.Diag(InitLoc, diag::err_non_designated_init_used);
-  hadError = true;
-  break;
-}
-
 // We've already initialized a member of a union. We're done.
 if (InitializedSomething && DeclType->isUnionType())
   break;

diff  --git a/clang/test/Sema/init-randomized-struct.c 
b/clang/test/Sema/init-randomized-struct.c
deleted file mode 100644
index 87842e1f19e80..0
--- a/clang/test/Sema/init-randomized-struct.c
+++ /dev/null
@@ -1,56 +0,0 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only 
-frandomize-layout-seed=1234567890abcdef
-
-// Initializing a randomized structure requires a designated initializer,
-// otherwise the element ordering will be off. The only exceptions to this rule
-// are:
-//
-//- A structure with only one element, and
-//- A structure initialized with "{0}".
-//
-// These are well-defined situations where the field ordering doesn't affect
-// the result.
-
-typedef void (*func_ptr)();
-
-void foo(void);
-void bar(void);
-void baz(void);
-void gaz(void);
-
-struct test {
-  func_ptr a;
-  func_ptr b;
-  func_ptr c;
-  func_ptr d;
-  func_ptr e;
-  func_ptr f;
-  func_ptr g;
-} __attribute__((randomize_layout));
-
-struct test t1 = {}; // This should be fine per WG14 N2900 (in C23) + our 
extension handling of it in earlier modes
-struct test t2 = { 0 }; // This should also be fine per C99 6.7.8p19
-struct test t3 = { .f = baz, .b = bar, .g = gaz, .a = foo }; // Okay
-struct test t4 = { .a = foo, bar, baz }; // expected-error {{a randomized 
struct can only be initialized with a designated initializer}}
-
-struct other_test {
-  func_ptr a;
-  func_ptr b[3];
-  func_ptr c;
-} __attribute__((randomize_layout));
-
-struct other_test t5 = { .a = foo, .b[0] = foo }; // Okay
-struct other_test t6 = { .a = foo, .b[0] = foo, bar, baz }; // Okay
-struct other_test t7 = { .a = foo, .b = { foo, bar, baz } }; // Okay
-struct 

[clang] 5a4980c - Revert "[randstruct] Force errors for all platforms"

2022-04-16 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-04-16T11:10:57-04:00
New Revision: 5a4980cc954faa6e39538bfcf62fe7c449d468d3

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

LOG: Revert "[randstruct] Force errors for all platforms"

This reverts commit 2a404cdfd8bc75de593ce0e15fff0a7a0a18ec1c.

It didn't address the built bot failures.

https://lab.llvm.org/buildbot/#/builders/171/builds/13231
https://lab.llvm.org/buildbot/#/builders/186/builds/5520

Added: 


Modified: 
clang/test/Sema/init-randomized-struct.c

Removed: 




diff  --git a/clang/test/Sema/init-randomized-struct.c 
b/clang/test/Sema/init-randomized-struct.c
index 7ce19165921e3..87842e1f19e80 100644
--- a/clang/test/Sema/init-randomized-struct.c
+++ b/clang/test/Sema/init-randomized-struct.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only -Werror 
-frandomize-layout-seed=1234567890abcdef
+// RUN: %clang_cc1 %s -verify -fsyntax-only 
-frandomize-layout-seed=1234567890abcdef
 
 // Initializing a randomized structure requires a designated initializer,
 // otherwise the element ordering will be off. The only exceptions to this rule



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


[PATCH] D123896: [clang-format] fix nested angle brackets parse inside concept definition

2022-04-16 Thread Sergey Semushin via Phabricator via cfe-commits
predelnik updated this revision to Diff 423234.
predelnik edited the summary of this revision.
predelnik added a comment.

Added issue links to commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123896

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -294,6 +294,18 @@
   EXPECT_TOKEN(Tokens[21], tok::r_brace, TT_Unknown);
   EXPECT_EQ(Tokens[21]->MatchingParen, Tokens[15]);
   EXPECT_TRUE(Tokens[21]->ClosesRequiresClause);
+
+  Tokens =
+  annotate("template  concept C ="
+   "std::same_as, std::iter_value_t>;");
+  ASSERT_EQ(Tokens.size(), 31u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::kw_concept, TT_Unknown);
+  EXPECT_TOKEN(Tokens[14], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[18], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[20], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[25], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[27], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[28], tok::greater, TT_TemplateCloser);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24040,6 +24040,12 @@
   verifyFormat("template \n"
"concept Same = __is_same_as;");
 
+  verifyFormat(
+  "template \n"
+  "concept _Can_reread_dest =\n"
+  "std::forward_iterator<_OutIt> &&\n"
+  "std::same_as, 
std::iter_value_t<_OutIt>>;");
+
   auto Style = getLLVMStyle();
   Style.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Allowed;
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2174,7 +2174,8 @@
   parseBracedList();
   break;
 case tok::less:
-  if (Style.Language == FormatStyle::LK_Proto) {
+  if (Style.Language == FormatStyle::LK_Proto ||
+  ClosingBraceKind == tok::greater) {
 nextToken();
 parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
 /*ClosingBraceKind=*/tok::greater);
@@ -3218,6 +3219,7 @@
   if (!FormatTok->is(tok::less))
 return;
 
+  nextToken();
   parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
   /*ClosingBraceKind=*/tok::greater);
   break;
@@ -3258,9 +3260,11 @@
 
   // Read identifier with optional template declaration.
   nextToken();
-  if (FormatTok->is(tok::less))
+  if (FormatTok->is(tok::less)) {
+nextToken();
 parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
 /*ClosingBraceKind=*/tok::greater);
+  }
   break;
 }
   } while (!eof());


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -294,6 +294,18 @@
   EXPECT_TOKEN(Tokens[21], tok::r_brace, TT_Unknown);
   EXPECT_EQ(Tokens[21]->MatchingParen, Tokens[15]);
   EXPECT_TRUE(Tokens[21]->ClosesRequiresClause);
+
+  Tokens =
+  annotate("template  concept C ="
+   "std::same_as, std::iter_value_t>;");
+  ASSERT_EQ(Tokens.size(), 31u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::kw_concept, TT_Unknown);
+  EXPECT_TOKEN(Tokens[14], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[18], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[20], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[25], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[27], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[28], tok::greater, TT_TemplateCloser);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24040,6 +24040,12 @@
   verifyFormat("template \n"
"concept Same = __is_same_as;");
 
+  verifyFormat(
+  "template \n"
+  "concept _Can_reread_dest =\n"
+  "std::forward_iterator<_OutIt> &&\n"
+  "std::same_as, std::iter_value_t<_OutIt>>;");
+
   auto Style = getLLVMStyle();
   Style.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Allowed;
 
Index: clang/lib/Format/UnwrappedLineParser.cpp

[clang-tools-extra] b859c39 - [clang-tidy] Add a Standalone diagnostics mode to clang-tidy

2022-04-16 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2022-04-16T09:53:35+01:00
New Revision: b859c39c40a79ff74033f67d807a18130b9afe30

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

LOG: [clang-tidy] Add a Standalone diagnostics mode to clang-tidy

Adds a flag to `ClangTidyContext` that is used to indicate to checks that fixes 
will only be applied one at a time.
This is to indicate to checks that each fix emitted should not depend on any 
other fixes emitted across the translation unit.
I've currently implemented the `IncludeInserter`, `LoopConvertCheck` and 
`PreferMemberInitializerCheck` to use these support these modes.

Reasoning behind this is in use cases like `clangd` it's only possible to apply 
one fix at a time.
For include inserter checks, the include is only added once for the first 
diagnostic that requires it, this will result in subsequent fixes not having 
the included needed.

A similar issue is seen in the `PreferMemberInitializerCheck` where the `:` 
will only be added for the first member that needs fixing.

Fixes emitted in `StandaloneDiagsMode` will likely result in malformed code if 
they are applied all together, conversely fixes currently emitted may result in 
malformed code if they are applied one at a time.
For this reason invoking `clang-tidy` from the binary will always with 
`StandaloneDiagsMode` disabled, However using it as a library its possible to 
select the mode you wish to use, `clangd` always selects `StandaloneDiagsMode`.

This is an example of the current behaviour failing
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E) {
A = D;
B = E; // Fix Here
  }
};
```
Incorrectly transformed to:
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E), B(E) {
A = D;
 // Fix Here
  }
};
```
In `StandaloneDiagsMode`, it gets transformed to:
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E) : B(E) {
A = D;
 // Fix Here
  }
};
```

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyCheck.h
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp

clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
clang-tools-extra/clang-tidy/utils/IncludeInserter.h
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
index 9b41e5836de73..33f84a15b8441 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -417,6 +417,11 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
   StringRef getCurrentMainFile() const { return Context->getCurrentFile(); }
   /// Returns the language options from the context.
   const LangOptions () const { return Context->getLangOpts(); }
+  /// Returns true when the check is run in a use case when only 1 fix will be
+  /// applied at a time.
+  bool areDiagsSelfContained() const {
+return Context->areDiagsSelfContained();
+  }
 };
 
 /// Read a named option from the ``Context`` and parse it as a bool.

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 04721a2d3a020..d455473673b09 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -162,7 +162,8 @@ ClangTidyContext::ClangTidyContext(
 bool 

[PATCH] D97121: [clang-tidy] Add a Standalone diagnostics mode to clang-tidy

2022-04-16 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb859c39c40a7: [clang-tidy] Add a Standalone diagnostics mode 
to clang-tidy (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97121

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
  
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.h
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -30,8 +30,10 @@
 public:
   IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context,
utils::IncludeSorter::IncludeStyle Style =
-   utils::IncludeSorter::IS_Google)
-  : ClangTidyCheck(CheckName, Context), Inserter(Style) {}
+   utils::IncludeSorter::IS_Google,
+   bool SelfContainedDiags = false)
+  : ClangTidyCheck(CheckName, Context),
+Inserter(Style, SelfContainedDiags) {}
 
   void registerPPCallbacks(const SourceManager , Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
@@ -85,6 +87,19 @@
   }
 };
 
+class MultipleHeaderSingleInserterCheck : public IncludeInserterCheckBase {
+public:
+  MultipleHeaderSingleInserterCheck(StringRef CheckName,
+ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google,
+ /*SelfContainedDiags=*/true) {}
+
+  std::vector headersToInclude() const override {
+return {"path/to/header.h", "path/to/header2.h", "path/to/header.h"};
+  }
+};
+
 class CSystemIncludeInserterCheck : public IncludeInserterCheckBase {
 public:
   CSystemIncludeInserterCheck(StringRef CheckName, ClangTidyContext *Context)
@@ -246,6 +261,41 @@
 PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
 }
 
+TEST(IncludeInserterTest, InsertMultipleIncludesNoDeduplicate) {
+  const char *PreCode = R"(
+#include "clang_tidy/tests/insert_includes_test_header.h"
+
+#include 
+#include 
+
+#include "path/to/a/header.h"
+
+void foo() {
+  int a = 0;
+})";
+  // FIXME: ClangFormat bug - https://bugs.llvm.org/show_bug.cgi?id=49298
+  // clang-format off
+  const char *PostCode = R"(
+#include "clang_tidy/tests/insert_includes_test_header.h"
+
+#include 
+#include 
+
+#include "path/to/a/header.h"
+#include "path/to/header.h"
+#include "path/to/header2.h"
+#include "path/to/header.h"
+
+void foo() {
+  int a = 0;
+})";
+  // clang-format on
+
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
+}
+
 TEST(IncludeInserterTest, InsertBeforeFirstNonSystemInclude) {
   const char *PreCode = R"(
 #include "clang_tidy/tests/insert_includes_test_header.h"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -53,6 +53,7 @@
 
 Diagnostics
 ^^^
+- Improved Fix-its of some clang-tidy checks when applied with clangd.
 
 Semantic Highlighting
 ^
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

[PATCH] D123896: [clang-format] fix nested angle brackets parse inside concept definition

2022-04-16 Thread Sergey Semushin via Phabricator via cfe-commits
predelnik added a comment.

I've created the issue here:
https://github.com/llvm/llvm-project/issues/54943
It also seems to fix the other issue I reported which was partially fixed 
before this change in master:
https://github.com/llvm/llvm-project/issues/54837


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123896

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


[PATCH] D123896: [clang-format] fix nested angle brackets parse inside concept definition

2022-04-16 Thread Sergey Semushin via Phabricator via cfe-commits
predelnik updated this revision to Diff 423231.
predelnik added a comment.

Added annotator test, checked that it fails without a patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123896

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -294,6 +294,18 @@
   EXPECT_TOKEN(Tokens[21], tok::r_brace, TT_Unknown);
   EXPECT_EQ(Tokens[21]->MatchingParen, Tokens[15]);
   EXPECT_TRUE(Tokens[21]->ClosesRequiresClause);
+
+  Tokens =
+  annotate("template  concept C ="
+   "std::same_as, std::iter_value_t>;");
+  ASSERT_EQ(Tokens.size(), 31u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::kw_concept, TT_Unknown);
+  EXPECT_TOKEN(Tokens[14], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[18], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[20], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[25], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[27], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[28], tok::greater, TT_TemplateCloser);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24040,6 +24040,12 @@
   verifyFormat("template \n"
"concept Same = __is_same_as;");
 
+  verifyFormat(
+  "template \n"
+  "concept _Can_reread_dest =\n"
+  "std::forward_iterator<_OutIt> &&\n"
+  "std::same_as, 
std::iter_value_t<_OutIt>>;");
+
   auto Style = getLLVMStyle();
   Style.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Allowed;
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2174,7 +2174,8 @@
   parseBracedList();
   break;
 case tok::less:
-  if (Style.Language == FormatStyle::LK_Proto) {
+  if (Style.Language == FormatStyle::LK_Proto ||
+  ClosingBraceKind == tok::greater) {
 nextToken();
 parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
 /*ClosingBraceKind=*/tok::greater);
@@ -3218,6 +3219,7 @@
   if (!FormatTok->is(tok::less))
 return;
 
+  nextToken();
   parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
   /*ClosingBraceKind=*/tok::greater);
   break;
@@ -3258,9 +3260,11 @@
 
   // Read identifier with optional template declaration.
   nextToken();
-  if (FormatTok->is(tok::less))
+  if (FormatTok->is(tok::less)) {
+nextToken();
 parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
 /*ClosingBraceKind=*/tok::greater);
+  }
   break;
 }
   } while (!eof());


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -294,6 +294,18 @@
   EXPECT_TOKEN(Tokens[21], tok::r_brace, TT_Unknown);
   EXPECT_EQ(Tokens[21]->MatchingParen, Tokens[15]);
   EXPECT_TRUE(Tokens[21]->ClosesRequiresClause);
+
+  Tokens =
+  annotate("template  concept C ="
+   "std::same_as, std::iter_value_t>;");
+  ASSERT_EQ(Tokens.size(), 31u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::kw_concept, TT_Unknown);
+  EXPECT_TOKEN(Tokens[14], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[18], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[20], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[25], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[27], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[28], tok::greater, TT_TemplateCloser);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24040,6 +24040,12 @@
   verifyFormat("template \n"
"concept Same = __is_same_as;");
 
+  verifyFormat(
+  "template \n"
+  "concept _Can_reread_dest =\n"
+  "std::forward_iterator<_OutIt> &&\n"
+  "std::same_as, std::iter_value_t<_OutIt>>;");
+
   auto Style = getLLVMStyle();
   Style.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Allowed;
 
Index: clang/lib/Format/UnwrappedLineParser.cpp

[PATCH] D123182: [Concepts] Fix overload resolution bug with constrained candidates

2022-04-16 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

Thanks @erichkeane! I will land this on Monday if there are no further comments 
and the CI looks good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123182

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


[PATCH] D97121: [clang-tidy] Add a Standalone diagnostics mode to clang-tidy

2022-04-16 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 423230.
njames93 added a comment.

Added clangd release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97121

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
  
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.h
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -30,8 +30,10 @@
 public:
   IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context,
utils::IncludeSorter::IncludeStyle Style =
-   utils::IncludeSorter::IS_Google)
-  : ClangTidyCheck(CheckName, Context), Inserter(Style) {}
+   utils::IncludeSorter::IS_Google,
+   bool SelfContainedDiags = false)
+  : ClangTidyCheck(CheckName, Context),
+Inserter(Style, SelfContainedDiags) {}
 
   void registerPPCallbacks(const SourceManager , Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
@@ -85,6 +87,19 @@
   }
 };
 
+class MultipleHeaderSingleInserterCheck : public IncludeInserterCheckBase {
+public:
+  MultipleHeaderSingleInserterCheck(StringRef CheckName,
+ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google,
+ /*SelfContainedDiags=*/true) {}
+
+  std::vector headersToInclude() const override {
+return {"path/to/header.h", "path/to/header2.h", "path/to/header.h"};
+  }
+};
+
 class CSystemIncludeInserterCheck : public IncludeInserterCheckBase {
 public:
   CSystemIncludeInserterCheck(StringRef CheckName, ClangTidyContext *Context)
@@ -246,6 +261,41 @@
 PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
 }
 
+TEST(IncludeInserterTest, InsertMultipleIncludesNoDeduplicate) {
+  const char *PreCode = R"(
+#include "clang_tidy/tests/insert_includes_test_header.h"
+
+#include 
+#include 
+
+#include "path/to/a/header.h"
+
+void foo() {
+  int a = 0;
+})";
+  // FIXME: ClangFormat bug - https://bugs.llvm.org/show_bug.cgi?id=49298
+  // clang-format off
+  const char *PostCode = R"(
+#include "clang_tidy/tests/insert_includes_test_header.h"
+
+#include 
+#include 
+
+#include "path/to/a/header.h"
+#include "path/to/header.h"
+#include "path/to/header2.h"
+#include "path/to/header.h"
+
+void foo() {
+  int a = 0;
+})";
+  // clang-format on
+
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
+}
+
 TEST(IncludeInserterTest, InsertBeforeFirstNonSystemInclude) {
   const char *PreCode = R"(
 #include "clang_tidy/tests/insert_includes_test_header.h"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -53,6 +53,7 @@
 
 Diagnostics
 ^^^
+- Improved Fix-its of some clang-tidy checks when applied with clangd.
 
 Semantic Highlighting
 ^
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ 

[PATCH] D123896: [clang-format] fix nested angle brackets parse inside concept definition

2022-04-16 Thread Sergey Semushin via Phabricator via cfe-commits
predelnik added a comment.

In D123896#3455299 , @curdeius wrote:

> Is there an issue report for this bug already?

I could create an issue if that is required.

In D123896#3455301 , @curdeius wrote:

> Could you please add an annotator test as well?

Will look into that, thank you for reviewing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123896

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


[PATCH] D123182: [Concepts] Fix overload resolution bug with constrained candidates

2022-04-16 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 423229.
royjacobson added a comment.

Rebase again (HEAD CI was broken)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123182

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Index: clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
===
--- /dev/null
+++ clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+struct A;
+struct B;
+
+template  constexpr bool True = true;
+template  concept C = True;
+
+void f(C auto &, auto &) = delete;
+template  void f(Q &, C auto &);
+
+void g(struct A *ap, struct B *bp) {
+  f(*ap, *bp);
+}
+
+template  struct X {};
+
+template  bool operator==(X, V) = delete;
+templatebool operator==(T, X);
+
+bool h() {
+  return X{} == 0;
+}
+
+namespace PR53640 {
+
+template 
+concept C = true;
+
+template 
+void f(T t) {} // expected-note {{candidate function [with T = int]}}
+
+template 
+void f(const T ) {} // expected-note {{candidate function [with T = int]}}
+
+int g() {
+  f(0); // expected-error {{call to 'f' is ambiguous}}
+}
+
+struct S {
+  template  explicit S(T) noexcept requires C {} // expected-note {{candidate constructor}}
+  template  explicit S(const T &) noexcept {}   // expected-note {{candidate constructor}}
+};
+
+int h() {
+  S s(4); // expected-error-re {{call to constructor of {{.*}} is ambiguous}}
+}
+
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5143,18 +5143,20 @@
 /// candidate with a reversed parameter order. In this case, the corresponding
 /// P/A pairs between FT1 and FT2 are reversed.
 ///
+/// \param AllowOrderingByConstraints If \c is false, don't check whether one
+/// of the templates is more constrained than the other. Default is true.
+///
 /// \returns the more specialized function template. If neither
 /// template is more specialized, returns NULL.
-FunctionTemplateDecl *
-Sema::getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
- FunctionTemplateDecl *FT2,
- SourceLocation Loc,
- TemplatePartialOrderingContext TPOC,
- unsigned NumCallArguments1,
- unsigned NumCallArguments2,
- bool Reversed) {
-
-  auto JudgeByConstraints = [&] () -> FunctionTemplateDecl * {
+FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
+FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
+TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
+unsigned NumCallArguments2, bool Reversed,
+bool AllowOrderingByConstraints) {
+
+  auto JudgeByConstraints = [&]() -> FunctionTemplateDecl * {
+if (!AllowOrderingByConstraints)
+  return nullptr;
 llvm::SmallVector AC1, AC2;
 FT1->getAssociatedConstraints(AC1);
 FT2->getAssociatedConstraints(AC2);
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -2952,24 +2952,30 @@
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are different,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are different,
 /// ArgPos will have the parameter index of the first different parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *ArgPos, bool Reversed) {
+  assert(OldType->getNumParams() == NewType->getNumParams() &&
+ "Can't compare parameters of functions with 

[PATCH] D123896: [clang-format] fix nested angle brackets parse inside concept definition

2022-04-16 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

Could you please add an annotator test as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123896

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


[PATCH] D123896: [clang-format] fix nested angle brackets parse inside concept definition

2022-04-16 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

Is there an issue report for this bug already?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123896

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


[PATCH] D122768: [Clang][C++20] Support capturing structured bindings in lambdas

2022-04-16 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 423228.
cor3ntin added a comment.

Fix several conflicrs with the recently committed change to lambda captures
(D119136 ).

Also add to rewrite the code gen test. I'm not sure what, if anything
changed there, and the generated IR *seems* fine?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122768

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/LambdaCapture.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Analysis/AnalysisDeclContext.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/ScopeInfo.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
  clang/test/CodeGenCXX/cxx20-decomposition.cpp
  clang/test/SemaCXX/cxx1z-decomposition.cpp
  clang/test/SemaCXX/cxx20-decomposition.cpp
  clang/test/SemaCXX/decomposition-blocks.cpp
  clang/test/SemaCXX/decomposition-openmp.cpp
  clang/tools/libclang/CIndex.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1144,7 +1144,7 @@
 
   Structured binding extensions
   https://wg21.link/p1091r3;>P1091R3
-  Partial
+  Clang 15
 
   
 https://wg21.link/p1381r1;>P1381R1
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -3355,9 +3355,11 @@
C != CEnd; ++C) {
 if (!C->capturesVariable())
   continue;
-
-if (Visit(MakeCursorVariableRef(C->getCapturedVar(), C->getLocation(),
-TU)))
+// TODO: hamdle structured bindings here ?
+if (!isa(C->getCapturedVar()))
+  continue;
+if (Visit(MakeCursorVariableRef(cast(C->getCapturedVar()),
+C->getLocation(), TU)))
   return true;
   }
   // Visit init captures
Index: clang/test/SemaCXX/decomposition-openmp.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/decomposition-openmp.cpp
@@ -0,0 +1,13 @@
+
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -fopenmp %s
+
+// FIXME: OpenMP should support capturing structured bindings
+auto f() {
+  int i[2] = {};
+  auto [a, b] = i; // expected-note 2{{declared here}}
+  return [=, ] {
+// expected-error@-1 {{capturing a structured binding is not yet supported in OpenMP}}
+return a + b;
+// expected-error@-1 {{capturing a structured binding is not yet supported in OpenMP}}
+  };
+}
Index: clang/test/SemaCXX/decomposition-blocks.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/decomposition-blocks.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s -fblocks
+
+struct S {
+  int i : 1;
+  int j;
+};
+
+void run(void (^)());
+void test() {
+  auto [i, j] = S{1, 42}; // expected-note {{'i' declared here}}
+  run(^{
+(void)i; // expected-error {{reference to local binding 'i' declared in enclosing function 'test'}}
+  });
+}
Index: clang/test/SemaCXX/cxx20-decomposition.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-decomposition.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template 
+constexpr bool is_same = false;
+template 
+constexpr bool is_same = true;
+
+struct S {
+  int i;
+  int 
+};
+
+void check_category() {
+  int a = 42;
+  {
+auto [v, r] = S{1, a};
+(void)[ v, r ] {
+  static_assert(is_same);
+  static_assert(is_same);
+};
+  }
+  {
+auto [v, r] = S{1, a};
+(void)[,  ] {
+  static_assert(is_same);
+  static_assert(is_same);

[PATCH] D123896: [clang-format] fix nested angle brackets parse inside concept definition

2022-04-16 Thread Sergey Semushin via Phabricator via cfe-commits
predelnik created this revision.
Herald added a project: All.
predelnik requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Due to how parseBracedList always stopped on the first closing angle
bracket and was used in parsing angle bracketed expression inside concept
definition, nested brackets inside concepts were parsed incorrectly.

nextToken() call before calling parseBracedList is required because
we were processing opening angle bracket inside parseBracedList second
time leading to incorrect logic after my fix.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123896

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24040,6 +24040,12 @@
   verifyFormat("template \n"
"concept Same = __is_same_as;");
 
+  verifyFormat(
+  "template \n"
+  "concept _Can_reread_dest =\n"
+  "std::forward_iterator<_OutIt> &&\n"
+  "std::same_as, 
std::iter_value_t<_OutIt>>;");
+
   auto Style = getLLVMStyle();
   Style.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Allowed;
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2174,7 +2174,8 @@
   parseBracedList();
   break;
 case tok::less:
-  if (Style.Language == FormatStyle::LK_Proto) {
+  if (Style.Language == FormatStyle::LK_Proto ||
+  ClosingBraceKind == tok::greater) {
 nextToken();
 parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
 /*ClosingBraceKind=*/tok::greater);
@@ -3218,6 +3219,7 @@
   if (!FormatTok->is(tok::less))
 return;
 
+  nextToken();
   parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
   /*ClosingBraceKind=*/tok::greater);
   break;
@@ -3258,9 +3260,11 @@
 
   // Read identifier with optional template declaration.
   nextToken();
-  if (FormatTok->is(tok::less))
+  if (FormatTok->is(tok::less)) {
+nextToken();
 parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
 /*ClosingBraceKind=*/tok::greater);
+  }
   break;
 }
   } while (!eof());


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24040,6 +24040,12 @@
   verifyFormat("template \n"
"concept Same = __is_same_as;");
 
+  verifyFormat(
+  "template \n"
+  "concept _Can_reread_dest =\n"
+  "std::forward_iterator<_OutIt> &&\n"
+  "std::same_as, std::iter_value_t<_OutIt>>;");
+
   auto Style = getLLVMStyle();
   Style.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Allowed;
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2174,7 +2174,8 @@
   parseBracedList();
   break;
 case tok::less:
-  if (Style.Language == FormatStyle::LK_Proto) {
+  if (Style.Language == FormatStyle::LK_Proto ||
+  ClosingBraceKind == tok::greater) {
 nextToken();
 parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
 /*ClosingBraceKind=*/tok::greater);
@@ -3218,6 +3219,7 @@
   if (!FormatTok->is(tok::less))
 return;
 
+  nextToken();
   parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
   /*ClosingBraceKind=*/tok::greater);
   break;
@@ -3258,9 +3260,11 @@
 
   // Read identifier with optional template declaration.
   nextToken();
-  if (FormatTok->is(tok::less))
+  if (FormatTok->is(tok::less)) {
+nextToken();
 parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
 /*ClosingBraceKind=*/tok::greater);
+  }
   break;
 }
   } while (!eof());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123345: Treat `std::move`, `forward`, and `move_if_noexcept` as builtins.

2022-04-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka reopened this revision.
vitalybuka added a comment.
This revision is now accepted and ready to land.

Reverted with e75d8b70370435b0ad10388afba0df45fcf9bfcc 
 to 
recover bots


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123345

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


[clang] e75d8b7 - Revert "Treat `std::move`, `forward`, and `move_if_noexcept` as builtins."

2022-04-16 Thread Vitaly Buka via cfe-commits

Author: Vitaly Buka
Date: 2022-04-16T00:27:51-07:00
New Revision: e75d8b70370435b0ad10388afba0df45fcf9bfcc

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

LOG: Revert "Treat `std::move`, `forward`, and `move_if_noexcept` as builtins."
Revert "Extend support for std::move etc to also cover std::as_const and"
Revert "Update test to handle opaque pointers flag flip."

It crashes on libcxx tests 
https://lab.llvm.org/buildbot/#/builders/85/builds/8174

This reverts commit fc3090109643af8d2da9822d0f99c84742b9c877.
This reverts commit a571f82a50416b767fd3cce0fb5027bb5dfec58c.
This reverts commit 64c045e25b8471bbb572bd29159c294a82a86a25.

Added: 


Modified: 
clang/docs/CommandGuide/clang.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.def
clang/include/clang/Basic/Builtins.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/ExprConstant.cpp
clang/lib/Analysis/BodyFarm.cpp
clang/lib/Basic/Builtins.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/Analysis/inner-pointer.cpp
clang/test/Analysis/use-after-move.cpp
clang/test/CodeGenCXX/builtins.cpp
clang/test/CodeGenCXX/microsoft-abi-throw.cpp
clang/test/SemaCXX/unqualified-std-call-fixits.cpp
clang/test/SemaCXX/unqualified-std-call.cpp
clang/test/SemaCXX/warn-consumed-analysis.cpp
clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Removed: 
clang/test/CodeGenCXX/builtin-std-move.cpp
clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
clang/test/SemaCXX/builtin-std-move.cpp



diff  --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index 658a30458043e..aec62789a43e6 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -252,24 +252,8 @@ Language Selection and Mode Options
 
 .. option:: -fno-builtin
 
- Disable special handling and optimizations of well-known library functions,
- like :c:func:`strlen` and :c:func:`malloc`.
-
-.. option:: -fno-builtin-
-
- Disable special handling and optimizations for the specific library function.
- For example, ``-fno-builtin-strlen`` removes any special handling for the
- :c:func:`strlen` library function.
-
-.. option:: -fno-builtin-std-
-
- Disable special handling and optimizations for the specific C++ standard
- library function in namespace ``std``. For example,
- ``-fno-builtin-std-move_if_noexcept`` removes any special handling for the
- :cpp:func:`std::move_if_noexcept` library function.
-
- For C standard library functions that the C++ standard library also provides
- in namespace ``std``, use :option:`-fno-builtin-\` instead.
+ Disable special handling and optimizations of builtin functions like
+ :c:func:`strlen` and :c:func:`malloc`.
 
 .. option:: -fmath-errno
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b2a5f6c366dd5..c72028c718586 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -230,10 +230,7 @@ C2x Feature Support
 C++ Language Changes in Clang
 -
 
-- Improved ``-O0`` code generation for calls to ``std::move``, 
``std::forward``,
-  and ``std::move_if_noexcept``. These are now treated as compiler builtins and
-  implemented directly, rather than instantiating the definition from the
-  standard library.
+- ...
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index c22957e14de7d..62e82cd36321d 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -81,9 +81,7 @@
 //   builtin even if type doesn't match signature, and don't warn if we
 //   can't be sure the type is right
 //  F -> this is a libc/libm function with a '__builtin_' prefix added.
-//  f -> this is a libc/libm function without a '__builtin_' prefix, or with
-//   'z', a C++ standard library function in namespace std::. This builtin
-//   is disableable by '-fno-builtin-foo' / '-fno-builtin-std-foo'.
+//  f -> this is a libc/libm function without the '__builtin_' prefix.
 //  h -> this function requires a specific header or an explicit declaration.
 //  i -> this is a runtime library implemented function without the
 //   '__builtin_' prefix. It will be implemented in compiler-rt or libgcc.
@@ -103,7 +101,6 @@
 //  V:N: -> requires vectors of at least N bits to be legal
 //  C -> callback behavior: argument N is called with