[PATCH] D134629: [clang][Interp] Fix Pointer::toAPValue() LValuePath order

2022-09-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 462823.

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

https://reviews.llvm.org/D134629

Files:
  clang/lib/AST/Interp/Pointer.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -153,11 +153,7 @@
 constexpr FourBoolPairs LT;
 // Copy ctor
 constexpr FourBoolPairs LT2 = LT;
-// FIXME: The copy constructor call above
-//   works, but APValue we generate for it is
-//   not sufficiently correct, so the lvalue-to-rvalue
-//   conversion in ExprConstant.c runs into an assertion.
-//static_assert(LT2.v[0].first == false, "");
-//static_assert(LT2.v[0].second == false, "");
-//static_assert(LT2.v[2].first == true, "");
-//static_assert(LT2.v[2].second == false, "");
+static_assert(LT2.v[0].first == false, "");
+static_assert(LT2.v[0].second == false, "");
+static_assert(LT2.v[2].first == true, "");
+static_assert(LT2.v[2].second == false, "");
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -148,6 +148,12 @@
 }
   }
 
+  // We assemble the LValuePath starting from the innermost pointer to the
+  // outermost one. SO in a.b.c, the first element in Path will refer to
+  // the field 'c', while later code expects it to refer to 'a'.
+  // Just invert the order of the elements.
+  std::reverse(Path.begin(), Path.end());
+
   return APValue(Base, Offset, Path, IsOnePastEnd, IsNullPtr);
 }
 


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -153,11 +153,7 @@
 constexpr FourBoolPairs LT;
 // Copy ctor
 constexpr FourBoolPairs LT2 = LT;
-// FIXME: The copy constructor call above
-//   works, but APValue we generate for it is
-//   not sufficiently correct, so the lvalue-to-rvalue
-//   conversion in ExprConstant.c runs into an assertion.
-//static_assert(LT2.v[0].first == false, "");
-//static_assert(LT2.v[0].second == false, "");
-//static_assert(LT2.v[2].first == true, "");
-//static_assert(LT2.v[2].second == false, "");
+static_assert(LT2.v[0].first == false, "");
+static_assert(LT2.v[0].second == false, "");
+static_assert(LT2.v[2].first == true, "");
+static_assert(LT2.v[2].second == false, "");
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -148,6 +148,12 @@
 }
   }
 
+  // We assemble the LValuePath starting from the innermost pointer to the
+  // outermost one. SO in a.b.c, the first element in Path will refer to
+  // the field 'c', while later code expects it to refer to 'a'.
+  // Just invert the order of the elements.
+  std::reverse(Path.begin(), Path.end());
+
   return APValue(Base, Offset, Path, IsOnePastEnd, IsNullPtr);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134523: [clang][Interp] Fix copy constructors with record array members

2022-09-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/records.cpp:160-163
+//static_assert(LT2.v[0].first == false, "");
+//static_assert(LT2.v[0].second == false, "");
+//static_assert(LT2.v[2].first == true, "");
+//static_assert(LT2.v[2].second == false, "");

These are fixed via https://reviews.llvm.org/D134629


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134523

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


[PATCH] D134629: [clang][Interp] Fix Pointer::toAPValue() LValuePath order

2022-09-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

See the comment I added for an explanation. This fixes the commented-out 
testcases I added in https://reviews.llvm.org/D134523.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134629

Files:
  clang/lib/AST/Interp/Pointer.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -153,11 +153,7 @@
 constexpr FourBoolPairs LT;
 // Copy ctor
 constexpr FourBoolPairs LT2 = LT;
-// FIXME: The copy constructor call above
-//   works, but APValue we generate for it is
-//   not sufficiently correct, so the lvalue-to-rvalue
-//   conversion in ExprConstant.c runs into an assertion.
-//static_assert(LT2.v[0].first == false, "");
-//static_assert(LT2.v[0].second == false, "");
-//static_assert(LT2.v[2].first == true, "");
-//static_assert(LT2.v[2].second == false, "");
+static_assert(LT2.v[0].first == false, "");
+static_assert(LT2.v[0].second == false, "");
+static_assert(LT2.v[2].first == true, "");
+static_assert(LT2.v[2].second == false, "");
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -148,7 +148,16 @@
 }
   }
 
-  return APValue(Base, Offset, Path, IsOnePastEnd, IsNullPtr);
+  // We assemble the LValuePath starting from the innermost pointer to the
+  // outermost one. SO in a.b.c, the first element in Path will refer to
+  // the field 'c', while later code expects it to refer to 'a'.
+  // Just invert the order of the elements.
+  decltype(Path) RealPath;
+  RealPath.resize(Path.size());
+  for (unsigned I = 0, N = Path.size(); I != N; ++I)
+RealPath[N - 1 - I] = Path[I];
+
+  return APValue(Base, Offset, RealPath, IsOnePastEnd, IsNullPtr);
 }
 
 bool Pointer::isInitialized() const {


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -153,11 +153,7 @@
 constexpr FourBoolPairs LT;
 // Copy ctor
 constexpr FourBoolPairs LT2 = LT;
-// FIXME: The copy constructor call above
-//   works, but APValue we generate for it is
-//   not sufficiently correct, so the lvalue-to-rvalue
-//   conversion in ExprConstant.c runs into an assertion.
-//static_assert(LT2.v[0].first == false, "");
-//static_assert(LT2.v[0].second == false, "");
-//static_assert(LT2.v[2].first == true, "");
-//static_assert(LT2.v[2].second == false, "");
+static_assert(LT2.v[0].first == false, "");
+static_assert(LT2.v[0].second == false, "");
+static_assert(LT2.v[2].first == true, "");
+static_assert(LT2.v[2].second == false, "");
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -148,7 +148,16 @@
 }
   }
 
-  return APValue(Base, Offset, Path, IsOnePastEnd, IsNullPtr);
+  // We assemble the LValuePath starting from the innermost pointer to the
+  // outermost one. SO in a.b.c, the first element in Path will refer to
+  // the field 'c', while later code expects it to refer to 'a'.
+  // Just invert the order of the elements.
+  decltype(Path) RealPath;
+  RealPath.resize(Path.size());
+  for (unsigned I = 0, N = Path.size(); I != N; ++I)
+RealPath[N - 1 - I] = Path[I];
+
+  return APValue(Base, Offset, RealPath, IsOnePastEnd, IsNullPtr);
 }
 
 bool Pointer::isInitialized() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134617: [HLSL] Support register binding attribute on global variable

2022-09-25 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 462819.
python3kgae added a comment.

Remove empty line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134617

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/test/AST/HLSL/resource_binding_attr.hlsl
  clang/test/SemaHLSL/resource_binding_attr_error.hlsl

Index: clang/test/SemaHLSL/resource_binding_attr_error.hlsl
===
--- clang/test/SemaHLSL/resource_binding_attr_error.hlsl
+++ clang/test/SemaHLSL/resource_binding_attr_error.hlsl
@@ -1,10 +1,6 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
 
-// expected-error@+5 {{expected ';' after top level declarator}}
-// expected-error@+4 {{expected ')'}}
-// expected-note@+3 {{to match this '('}}
-// expected-error@+2 {{a type specifier is required for all declarations}}
-// expected-error@+1 {{illegal storage class on file-scoped variable}}
+// expected-error@+1 {{invalid resource class specifier 'c' used; expected 'b', 's', 't', or 'u'}}
 float a : register(c0, space1);
 
 // expected-error@+1 {{invalid resource class specifier 'i' used; expected 'b', 's', 't', or 'u'}}
@@ -36,3 +32,26 @@
 // expected-error@+2 {{wrong argument format for hlsl attribute, use b2 instead}}
 // expected-error@+1 {{wrong argument format for hlsl attribute, use space3 instead}}
 cbuffer D : register(b 2, space 3) {}
+
+// expected-warning@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
+static RWBuffer U : register(u5);
+
+void foo() {
+  // expected-warning@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
+  RWBuffer U : register(u3);
+}
+
+// FIXEME: expect-error once fix https://github.com/llvm/llvm-project/issues/57886.
+float b : register(u0, space1);
+
+// expected-warning@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
+void bar(RWBuffer U : register(u3)) {
+
+}
+
+struct S {
+  // FIXME: generate better error when support semantic on struct field.
+  // See https://github.com/llvm/llvm-project/issues/57889.
+  // expected-error@+1 {{expected expression}}
+  RWBuffer U : register(u3);
+};
Index: clang/test/AST/HLSL/resource_binding_attr.hlsl
===
--- clang/test/AST/HLSL/resource_binding_attr.hlsl
+++ clang/test/AST/HLSL/resource_binding_attr.hlsl
@@ -22,3 +22,16 @@
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}}  'float' lvalue Var 0x[[B]] 'b' 'float'
   return a + b;
 }
+
+// CHECK: VarDecl 0x{{[0-9a-f]+}} <{{.*}}> col:17 UAV 'RWBuffer':'hlsl::RWBuffer<>' callinit
+// CHECK-NEXT:-CXXConstructExpr 0x{{[0-9a-f]+}}  'RWBuffer':'hlsl::RWBuffer<>' 'void ()'
+// CHECK-NEXT:-HLSLResourceBindingAttr 0x{{[0-9a-f]+}}  "u3" "space0"
+RWBuffer UAV : register(u3);
+
+// CHECK: -VarDecl 0x{{[0-9a-f]+}} <{{.*}}> col:17 UAV1 'RWBuffer':'hlsl::RWBuffer<>' callinit
+// CHECK-NEXT:-CXXConstructExpr 0x{{[0-9a-f]+}}  'RWBuffer':'hlsl::RWBuffer<>' 'void ()'
+// CHECK-NEXT:-HLSLResourceBindingAttr 0x{{[0-9a-f]+}}  "u2" "space0"
+// CHECK-NEXT:-VarDecl 0x{{[0-9a-f]+}}  col:38 UAV2 'RWBuffer':'hlsl::RWBuffer<>' callinit
+// CHECK-NEXT:-CXXConstructExpr 0x{{[0-9a-f]+}}  'RWBuffer':'hlsl::RWBuffer<>' 'void ()'
+// CHECK-NEXT:-HLSLResourceBindingAttr 0x{{[0-9a-f]+}}  "u4" "space0"
+RWBuffer UAV1 : register(u2), UAV2 : register(u4);
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2054,6 +2054,9 @@
 return nullptr;
   }
 
+  if (getLangOpts().HLSL)
+MaybeParseHLSLSemantics(D);
+
   if (Tok.is(tok::kw_requires))
 ParseTrailingRequiresClause(D);
 
@@ -2223,6 +2226,10 @@
   DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
 
 ParseDeclarator(D);
+
+if (getLangOpts().HLSL)
+  MaybeParseHLSLSemantics(D);
+
 if (!D.isInvalidType()) {
   // C++2a [dcl.decl]p1
   //init-declarator:
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2814,6 +2814,15 @@
   Sema::AttributeCompletion Completion = Sema::AttributeCompletion::None,
   const IdentifierInfo *EnclosingScope = nullptr);
 
+  void MaybeParseHLSLSemantics(Declarator &D,
+   SourceLocation *EndLoc = nullptr) {
+if (Tok.is(tok::colon)) {
+  ParsedAttributes Attrs(AttrFactory);
+  ParseHLSLSemantics(Attrs, EndLoc);
+  D.takeAttributes(Attrs);
+}
+  }
+
   void MaybeParseHLSLSemantics(ParsedAttributes &Attrs,
SourceLocation *EndLoc = nullptr) {
 if (getLangOpts().HLSL && Tok.

[PATCH] D134626: [clang-format] Correctly indent closing brace of compound requires

2022-09-25 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

Note: I don't have the historical insight to know why the code order was as it 
was. I simply tried yoinking the place where the level was being set to occur 
earlier, and it surprisingly seemed to work, and also seemed to not break any 
other tests; I hope it doesn't break something in some subtle way


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134626

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


[PATCH] D134626: [clang-format] Correctly indent closing brace of compound requires

2022-09-25 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel created this revision.
rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay, curdeius.
Herald added a project: All.
rymiel requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When a compound requirement is too long to fit onto a single line, the
braces are split apart onto separate lines, and the contained expression
is indented. However, this indentation would also apply to the closing
brace and the trailing return type requirement thereof.
This was because the indentation level was being restored after all
trailing things were already read

With this change, the initial level of the opening brace is set before
attempting to read any trailing return type requirements

Fixes https://github.com/llvm/llvm-project/issues/57108


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134626

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
@@ -24418,6 +24418,16 @@
   "  { x * 1 } -> std::convertible_to;\n"
   "};");
 
+  verifyFormat("template \n"
+   "concept C = requires(T x) {\n"
+   "  {\n"
+   "long_long_long_function_call(1, 2, 3, 4, 5)\n"
+   "  } -> long_long_concept_name;\n"
+   "  {\n"
+   "long_long_long_function_call(1, 2, 3, 4, 5)\n"
+   "  } noexcept -> long_long_concept_name;\n"
+   "};");
+
   verifyFormat(
   "template \n"
   "concept Swappable = requires(T &&t, U &&u) {\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -964,6 +964,8 @@
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
 
+  Line->Level = InitialLevel;
+
   if (FormatTok->is(tok::kw_noexcept)) {
 // A noexcept in a requires expression.
 nextToken();
@@ -979,8 +981,6 @@
   if (MunchSemi && FormatTok->is(tok::semi))
 nextToken();
 
-  Line->Level = InitialLevel;
-
   if (PPStartHash == PPEndHash) {
 Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
 if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24418,6 +24418,16 @@
   "  { x * 1 } -> std::convertible_to;\n"
   "};");
 
+  verifyFormat("template \n"
+   "concept C = requires(T x) {\n"
+   "  {\n"
+   "long_long_long_function_call(1, 2, 3, 4, 5)\n"
+   "  } -> long_long_concept_name;\n"
+   "  {\n"
+   "long_long_long_function_call(1, 2, 3, 4, 5)\n"
+   "  } noexcept -> long_long_concept_name;\n"
+   "};");
+
   verifyFormat(
   "template \n"
   "concept Swappable = requires(T &&t, U &&u) {\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -964,6 +964,8 @@
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
 
+  Line->Level = InitialLevel;
+
   if (FormatTok->is(tok::kw_noexcept)) {
 // A noexcept in a requires expression.
 nextToken();
@@ -979,8 +981,6 @@
   if (MunchSemi && FormatTok->is(tok::semi))
 nextToken();
 
-  Line->Level = InitialLevel;
-
   if (PPStartHash == PPEndHash) {
 Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
 if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129926: [clang-format] Handle constructor invocations after new operator in C# correct

2022-09-25 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG258d7b86eeab: [clang-format] Handle constructor invocations 
after new operator in C# correct (authored by eoanermine, committed by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D129926?vs=452513&id=462802#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129926

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


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -617,6 +617,24 @@
   EXPECT_EQ(Code, format(Code, Style));
 }
 
+TEST_F(FormatTestCSharp, CSharpNewOperator) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_CSharp);
+
+  verifyFormat("public void F() {\n"
+   "  var v = new C(() => { var t = 5; });\n"
+   "}",
+   Style);
+  verifyFormat("public void F() {\n"
+   "  var v = new C(() => {\n"
+   "try {\n"
+   "} catch {\n"
+   "  var t = 5;\n"
+   "}\n"
+   "  });\n"
+   "}",
+   Style);
+}
+
 TEST_F(FormatTestCSharp, CSharpLambdas) {
   FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_CSharp);
   FormatStyle MicrosoftStyle = getMicrosoftStyle(FormatStyle::LK_CSharp);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2975,6 +2975,11 @@
 
   if (Style.isCSharp()) {
 do {
+  // Handle constructor invocation, e.g. `new(field: value)`.
+  if (FormatTok->is(tok::l_paren))
+parseParens();
+
+  // Handle array initialization syntax, e.g. `new[] {10, 20, 30}`.
   if (FormatTok->is(tok::l_brace))
 parseBracedList();
 


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -617,6 +617,24 @@
   EXPECT_EQ(Code, format(Code, Style));
 }
 
+TEST_F(FormatTestCSharp, CSharpNewOperator) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_CSharp);
+
+  verifyFormat("public void F() {\n"
+   "  var v = new C(() => { var t = 5; });\n"
+   "}",
+   Style);
+  verifyFormat("public void F() {\n"
+   "  var v = new C(() => {\n"
+   "try {\n"
+   "} catch {\n"
+   "  var t = 5;\n"
+   "}\n"
+   "  });\n"
+   "}",
+   Style);
+}
+
 TEST_F(FormatTestCSharp, CSharpLambdas) {
   FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_CSharp);
   FormatStyle MicrosoftStyle = getMicrosoftStyle(FormatStyle::LK_CSharp);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2975,6 +2975,11 @@
 
   if (Style.isCSharp()) {
 do {
+  // Handle constructor invocation, e.g. `new(field: value)`.
+  if (FormatTok->is(tok::l_paren))
+parseParens();
+
+  // Handle array initialization syntax, e.g. `new[] {10, 20, 30}`.
   if (FormatTok->is(tok::l_brace))
 parseBracedList();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 258d7b8 - [clang-format] Handle constructor invocations after new operator in C# correct

2022-09-25 Thread Owen Pan via cfe-commits

Author: Danil Sidoruk
Date: 2022-09-25T21:10:26-07:00
New Revision: 258d7b86eeab4222c783c1a19acd8e18cd7745aa

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

LOG: [clang-format] Handle constructor invocations after new operator in C# 
correct

Fixes #56549.

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestCSharp.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 3919bc0ef0b35..a5dbd43cdf264 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2975,6 +2975,11 @@ void UnwrappedLineParser::parseNew() {
 
   if (Style.isCSharp()) {
 do {
+  // Handle constructor invocation, e.g. `new(field: value)`.
+  if (FormatTok->is(tok::l_paren))
+parseParens();
+
+  // Handle array initialization syntax, e.g. `new[] {10, 20, 30}`.
   if (FormatTok->is(tok::l_brace))
 parseBracedList();
 

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index 680a9576cf5a3..47ad779d632a9 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -617,6 +617,24 @@ var x = foo(className, $@"some code:
   EXPECT_EQ(Code, format(Code, Style));
 }
 
+TEST_F(FormatTestCSharp, CSharpNewOperator) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_CSharp);
+
+  verifyFormat("public void F() {\n"
+   "  var v = new C(() => { var t = 5; });\n"
+   "}",
+   Style);
+  verifyFormat("public void F() {\n"
+   "  var v = new C(() => {\n"
+   "try {\n"
+   "} catch {\n"
+   "  var t = 5;\n"
+   "}\n"
+   "  });\n"
+   "}",
+   Style);
+}
+
 TEST_F(FormatTestCSharp, CSharpLambdas) {
   FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_CSharp);
   FormatStyle MicrosoftStyle = getMicrosoftStyle(FormatStyle::LK_CSharp);



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


[PATCH] D134243: Don't crash when code completing `using enum ^Foo`.

2022-09-25 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rG30b676ac5f30: Don't crash when code completing `using 
enum ^Foo`. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D134243?vs=461416&id=462794#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134243

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/test/CodeCompletion/using-enum.cpp


Index: clang/test/CodeCompletion/using-enum.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/using-enum.cpp
@@ -0,0 +1,7 @@
+enum class AAA { X, Y, Z };
+
+namespace N2 {
+  using enum AAA;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:14 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: AAA
+};
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -4593,6 +4593,7 @@
 // Code completion for an enum name.
 cutOffParsing();
 Actions.CodeCompleteTag(getCurScope(), DeclSpec::TST_enum);
+DS.SetTypeSpecError(); // Needed by ActOnUsingDeclaration.
 return;
   }
 


Index: clang/test/CodeCompletion/using-enum.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/using-enum.cpp
@@ -0,0 +1,7 @@
+enum class AAA { X, Y, Z };
+
+namespace N2 {
+  using enum AAA;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:14 %s | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: AAA
+};
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -4593,6 +4593,7 @@
 // Code completion for an enum name.
 cutOffParsing();
 Actions.CodeCompleteTag(getCurScope(), DeclSpec::TST_enum);
+DS.SetTypeSpecError(); // Needed by ActOnUsingDeclaration.
 return;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 30b676a - Don't crash when code completing `using enum ^Foo`.

2022-09-25 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-09-26T04:52:19+02:00
New Revision: 30b676ac5f3041a5494b1eb9c9a3322cfc56d480

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

LOG: Don't crash when code completing `using enum ^Foo`.

Fixes https://github.com/clangd/clangd/issues/1281

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

Added: 
clang/test/CodeCompletion/using-enum.cpp

Modified: 
clang/lib/Parse/ParseDecl.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index d6a2a08bf28b7..4d25b22c9cd33 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4593,6 +4593,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, 
DeclSpec &DS,
 // Code completion for an enum name.
 cutOffParsing();
 Actions.CodeCompleteTag(getCurScope(), DeclSpec::TST_enum);
+DS.SetTypeSpecError(); // Needed by ActOnUsingDeclaration.
 return;
   }
 

diff  --git a/clang/test/CodeCompletion/using-enum.cpp 
b/clang/test/CodeCompletion/using-enum.cpp
new file mode 100644
index 0..1619e36c18f61
--- /dev/null
+++ b/clang/test/CodeCompletion/using-enum.cpp
@@ -0,0 +1,7 @@
+enum class AAA { X, Y, Z };
+
+namespace N2 {
+  using enum AAA;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:14 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: AAA
+};



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


[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2022-09-25 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

In D86049#3812412 , @plotfi wrote:

> In D86049#3812068 , @ahatanak wrote:
>
>> In D86049#3806898 , @plotfi wrote:
>>
>>> 1. Do we change the existing visibility behavior of objc methods? Yes / No
>>
>> I don't think we want to change the existing visibility behavior of 
>> non-direct objc methods. Is there a use reason or use case for making them 
>> visible outside the linkage unit?
>>
>>> 2. If we leave hidden as the default do we change the behavior for 
>>> objc_direct? Yes / No
>>
>> I think direct methods shouldn't be hidden by default (i.e., they should get 
>> the default visibility). But it's not clear to me whether we should make 
>> that change right away as I've heard concerns from people internally. I 
>> think I need more time to understand what exactly their concerns are.
>>
>>> 3. If we leave objc_direct as hidden by default do we expand the existing 
>>> objc_direct attr to have the enum as you said so 
>>> `__attribute__((objc_direct("visible")))` or do we add a new attr as I have 
>>> done so far?
>>
>> I wasn't sure why it wasn't possible to use the existing 
>> `__attribute__((visibility("default")))` attribute. Is it not possible to 
>> make only the direct methods get the default visibility?
>
> This is not possible because default visibility is implicit (as far as I 
> understand). It can not be checked if  
> `__attribute__((visibility("default")))` is set because it is always set 
> unless -fvisibility=hidden is passed on the command line. So either we treat 
> direct methods like everything else, and hide them when  
> `__attribute__((visibility("hidden")))` or the command line to hide 
> everything by default is used, or we need a new attr or a new enum on the 
> existing objc_direct attr.
>
> Does this make sense or am I missing some details?

But there are ways to check whether the user explicitly added a visibility 
attribute (e.g., `__attribute__((visibility("default")))`), right?  For 
example, `NamedDecl::getExplicitVisibility`.

I'm just not sure whether we want to add support for a new attribute like 
`__attribute__((objc_direct("default")))` since it seems equivalent to 
`__attribute__((objc_direct, visibility("default")))`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86049

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


[clang-tools-extra] 283b6de - [clangd] Make go-to-type work on member function calls

2022-09-25 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-09-26T04:18:43+02:00
New Revision: 283b6dec8d08520f73ebd4563966f491b49d47b2

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

LOG: [clangd] Make go-to-type work on member function calls

Added: 


Modified: 
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index 020f83b1a8fb..17be646c7d7c 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -454,6 +454,10 @@ struct TargetFinder {
 Outer.add(TD->getTemplatedDecl(), Flags | Rel::TemplatePattern);
 }
   }
+  void
+  VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *STTPT) {
+Outer.add(STTPT->getReplacementType(), Flags);
+  }
   void VisitTemplateTypeParmType(const TemplateTypeParmType *TTPT) {
 Outer.add(TTPT->getDecl(), Flags);
   }

diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index 25ddcbdbd739..10fb14b2ba8c 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1834,6 +1834,12 @@ static QualType typeForNode(const SelectionTree::Node 
*N) {
   QualType VisitExpr(const Expr *S) {
 return S->IgnoreImplicitAsWritten()->getType();
   }
+  QualType VisitMemberExpr(const MemberExpr *S) {
+// The `foo` in `s.foo()` pretends not to have a real type!
+if (S->getType()->isSpecificBuiltinType(BuiltinType::BoundMember))
+  return Expr::findBoundMemberType(S);
+return VisitExpr(S);
+  }
   // Exceptions for void expressions that operate on a type in some way.
   QualType VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
 return S->getDestroyedType();

diff  --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index e9e6b6f79a2d..dba7f4f85b40 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1829,8 +1829,9 @@ TEST(FindType, All) {
 struct $Target[[Target]] { operator int() const; };
 struct Aggregate { Target a, b; };
 Target t;
+Target make();
 
-template  class $smart_ptr[[smart_ptr]] {
+template  struct $smart_ptr[[smart_ptr]] {
   T& operator*();
   T* operator->();
   T* get();
@@ -1858,6 +1859,8 @@ TEST(FindType, All) {
"void x() { ^if (t) {} }",
"void x() { ^while (t) {} }",
"void x() { ^do { } while (t); }",
+   "void x() { ^make(); }",
+   "void x(smart_ptr &t) { t.^get(); }",
"^auto x = []() { return t; };",
"Target* ^tptr = &t;",
"Target ^tarray[3];",



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


[PATCH] D134618: [Syntax] Fix macro-arg handling in TokenBuffer::spelledForExpanded

2022-09-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

A few cases were not handled correctly. Notably:

  #define ID(X) X
  #define HIDE a ID(b)
  HIDE

spelledForExpanded() would claim HIDE is an equivalent range of the 'b' it
contains, despite the fact that HIDE also covers 'a'.

While trying to fix this bug, I found findCommonRangeForMacroArgs hard
to understand (both the implementation and how it's used in spelledForExpanded).
It relies on details of the SourceLocation graph that are IMO fairly obscure.
So I've added/revised quite a lot of comments and made some naming tweaks.

Fixes https://github.com/clangd/clangd/issues/1289


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134618

Files:
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp

Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -743,6 +743,54 @@
   ValueIs(SameRange(findSpelled("ID2 ( a4 , a5 a6 a7 )";
   // Should fail, spans multiple invocations.
   EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a1 a2 a3 a4")), llvm::None);
+
+  // https://github.com/clangd/clangd/issues/1289
+  recordTokens(R"cpp(
+#define FOO(X) foo(X)
+#define INDIRECT FOO(y)
+INDIRECT // expands to foo(y)
+  )cpp");
+  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("y")), llvm::None);
+
+  recordTokens(R"cpp(
+#define FOO(X) a X b
+FOO(y)
+  )cpp");
+  EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("y")),
+  ValueIs(SameRange(findSpelled("( y").drop_front(;
+
+  // Critical cases for mapping of Prev/Next in spelledForExpandedSlow.
+  recordTokens(R"cpp(
+#define ID(X) X
+ID(prev ID(good))
+#define LARGE ID(prev ID(bad))
+LARGE
+  )cpp");
+  EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("good")),
+  ValueIs(SameRange(findSpelled("good";
+  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("bad")), llvm::None);
+
+  recordTokens(R"cpp(
+#define PREV prev
+#define ID(X) X
+PREV ID(good)
+#define LARGE PREV ID(bad)
+LARGE
+  )cpp");
+  EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("good")),
+ValueIs(SameRange(findSpelled("good";
+  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("bad")), llvm::None);
+
+  recordTokens(R"cpp(
+#define ID(X) X
+#define ID2(X, Y) X Y
+ID2(prev, ID(good))
+#define LARGE ID2(prev, bad)
+LARGE
+  )cpp");
+  EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("good")),
+ValueIs(SameRange(findSpelled("good";
+  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("bad")), llvm::None);
 }
 
 TEST_F(TokenBufferTest, ExpandedTokensForRange) {
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -55,45 +55,140 @@
   return {Begin, End};
 }
 
-// Finds the smallest expansion range that contains expanded tokens First and
-// Last, e.g.:
+// Finds the range within FID corresponding to expanded tokens [First, Last].
+// Prev precedes First and Next follows Last, these must *not* be included.
+// If no range satisfies the criteria, returns an invalid range.
+//
 // #define ID(x) x
 // ID(ID(ID(a1) a2))
 //  ~~   -> a1
 //  ~~   -> a2
 //   ~   -> a1 a2
-SourceRange findCommonRangeForMacroArgs(const syntax::Token &First,
-const syntax::Token &Last,
-const SourceManager &SM) {
-  SourceRange Res;
-  auto FirstLoc = First.location(), LastLoc = Last.location();
-  // Keep traversing up the spelling chain as longs as tokens are part of the
-  // same expansion.
-  while (!FirstLoc.isFileID() && !LastLoc.isFileID()) {
-auto ExpInfoFirst = SM.getSLocEntry(SM.getFileID(FirstLoc)).getExpansion();
-auto ExpInfoLast = SM.getSLocEntry(SM.getFileID(LastLoc)).getExpansion();
-// Stop if expansions have diverged.
-if (ExpInfoFirst.getExpansionLocStart() !=
-ExpInfoLast.getExpansionLocStart())
+SourceRange spelledForExpandedSlow(SourceLocation First, SourceLocation Last,
+   SourceLocation Prev, SourceLocation Next,
+   FileID FID, const SourceManager &SM) {
+  // There are two main parts to this algorithm:
+  //  - identifying which spelled range covers the expanded tokens
+  //  - validating that this range doesn't cover any extra tokens (First/Last)
+  //
+  // We do these in order. However as we transform the expanded range into the
+  // spelled one, we adjust Fir

[PATCH] D134157: [Clang][LoongArch] Add inline asm support for constraints f/l/I/K

2022-09-25 Thread Lu Weining via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG394f30919a02: [Clang][LoongArch] Add inline asm support for 
constraints f/l/I/K (authored by SixWeining).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134157

Files:
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/test/CodeGen/LoongArch/inline-asm-constraints-error.c
  clang/test/CodeGen/LoongArch/inline-asm-constraints.c
  clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c
  clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/test/CodeGen/LoongArch/inline-asm-clobbers.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-error.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-f.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll
  llvm/test/CodeGen/LoongArch/inline-asm-reg-names-error.ll
  llvm/test/CodeGen/LoongArch/inline-asm-reg-names-f-error.ll
  llvm/test/CodeGen/LoongArch/inline-asm-reg-names-f.ll
  llvm/test/CodeGen/LoongArch/inline-asm-reg-names.ll

Index: llvm/test/CodeGen/LoongArch/inline-asm-reg-names.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/inline-asm-reg-names.ll
@@ -0,0 +1,109 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 --verify-machineinstrs < %s \
+; RUN:   | FileCheck --check-prefix=LA32 %s
+; RUN: llc --mtriple=loongarch64 --verify-machineinstrs < %s \
+; RUN:   | FileCheck --check-prefix=LA64 %s
+
+;; These test that we can use architectural names ($r*) refer to registers in
+;; inline asm constraint lists. In each case, the named register should be used
+;; for the source register of the `addi.w`. It is very likely that `$a0` will
+;; be chosen as the designation register, but this is left to the compiler to
+;; choose.
+;;
+;; Parenthesised registers in comments are the other aliases for this register.
+
+;; NOTE: This test has to pass in 0 to the inline asm, because that's the only
+;; value `$r0` (`$zero`) can take.
+define i32 @register_r0() nounwind {
+; LA32-LABEL: register_r0:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:addi.w $a0, $zero, 0
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: register_r0:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:addi.w $a0, $zero, 0
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = tail call i32 asm "addi.w $0, $1, 0", "=r,{$r0}"(i32 0)
+  ret i32 %1
+}
+
+define i32 @register_r4(i32 %a) nounwind {
+; LA32-LABEL: register_r4:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:addi.w $a0, $a0, 1
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: register_r4:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:addi.w $a0, $a0, 1
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = tail call i32 asm "addi.w $0, $1, 1", "=r,{$r4}"(i32 %a)
+  ret i32 %1
+}
+
+;; NOTE: This test uses `$r22` (`$s9`, `$fp`) as an input, so it should be saved.
+define i32 @register_r22(i32 %a) nounwind {
+; LA32-LABEL: register_r22:
+; LA32:   # %bb.0:
+; LA32-NEXT:addi.w $sp, $sp, -16
+; LA32-NEXT:st.w $fp, $sp, 12 # 4-byte Folded Spill
+; LA32-NEXT:move $fp, $a0
+; LA32-NEXT:#APP
+; LA32-NEXT:addi.w $a0, $fp, 1
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ld.w $fp, $sp, 12 # 4-byte Folded Reload
+; LA32-NEXT:addi.w $sp, $sp, 16
+; LA32-NEXT:ret
+;
+; LA64-LABEL: register_r22:
+; LA64:   # %bb.0:
+; LA64-NEXT:addi.d $sp, $sp, -16
+; LA64-NEXT:st.d $fp, $sp, 8 # 8-byte Folded Spill
+; LA64-NEXT:move $fp, $a0
+; LA64-NEXT:#APP
+; LA64-NEXT:addi.w $a0, $fp, 1
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ld.d $fp, $sp, 8 # 8-byte Folded Reload
+; LA64-NEXT:addi.d $sp, $sp, 16
+; LA64-NEXT:ret
+  %1 = tail call i32 asm "addi.w $0, $1, 1", "=r,{$r22}"(i32 %a)
+  ret i32 %1
+}
+
+;; NOTE: This test uses `$r31` (`$s8`) as an input, so it should be saved.
+define i32 @register_r31(i32 %a) nounwind {
+; LA32-LABEL: register_r31:
+; LA32:   # %bb.0:
+; LA32-NEXT:addi.w $sp, $sp, -16
+; LA32-NEXT:st.w $s8, $sp, 12 # 4-byte Folded Spill
+; LA32-NEXT:move $s8, $a0
+; LA32-NEXT:#APP
+; LA32-NEXT:addi.w $a0, $s8, 1
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ld.w $s8, $sp, 12 # 4-byte Folded Reload
+; LA32-NEXT:addi.w $sp, $sp, 16
+; LA32-NEXT:ret
+;
+; LA64-LABEL: register_r31:
+; LA64:   # %bb.0:
+; LA64-NEXT:addi.d $sp, $sp, -16
+; LA64-NEXT:st.d $s8, $sp, 8 # 8-byte Folded Spill
+; LA64-NEXT:move $s8, $a0
+; LA64-NEXT:#APP
+; LA64-NEXT:addi.w $a0, $s8, 1
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ld.d $s8, $sp, 8 # 8-byte Folded R

[clang] 394f309 - [Clang][LoongArch] Add inline asm support for constraints f/l/I/K

2022-09-25 Thread Weining Lu via cfe-commits

Author: Weining Lu
Date: 2022-09-26T08:49:58+08:00
New Revision: 394f30919a029331ebdfe02c180bd1586c0d9ace

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

LOG: [Clang][LoongArch] Add inline asm support for constraints f/l/I/K

This patch adds support for constraints `f`, `l`, `I`, `K` according
to [1]. The remain constraints (`k`, `m`, `ZB`, `ZC`) will be added
later as they are a little more complex than the others.
f: A floating-point register (if available).
l: A signed 16-bit constant.
I: A signed 12-bit constant (for arithmetic instructions).
K: An unsigned 12-bit constant (for logic instructions).

For now, no need to support register alias (e.g. `$a0`) in llvm as
clang will correctly decode the usage of register name aliases into
their official names. And AFAIK, the not yet upstreamed `rustc` for
LoongArch will always use official register names (e.g. `$r4`).

[1] https://gcc.gnu.org/onlinedocs/gccint/Machine-Constraints.html

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

Added: 
clang/test/CodeGen/LoongArch/inline-asm-constraints-error.c
clang/test/CodeGen/LoongArch/inline-asm-constraints.c
clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c
clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c
llvm/test/CodeGen/LoongArch/inline-asm-clobbers.ll
llvm/test/CodeGen/LoongArch/inline-asm-constraint-error.ll
llvm/test/CodeGen/LoongArch/inline-asm-constraint-f.ll
llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll
llvm/test/CodeGen/LoongArch/inline-asm-reg-names-error.ll
llvm/test/CodeGen/LoongArch/inline-asm-reg-names-f-error.ll
llvm/test/CodeGen/LoongArch/inline-asm-reg-names-f.ll
llvm/test/CodeGen/LoongArch/inline-asm-reg-names.ll

Modified: 
clang/lib/Basic/Targets/LoongArch.cpp
llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
llvm/lib/Target/LoongArch/LoongArchISelLowering.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index d87d8e841c4b..cc93206dad68 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -21,20 +21,73 @@ using namespace clang;
 using namespace clang::targets;
 
 ArrayRef LoongArchTargetInfo::getGCCRegNames() const {
-  // TODO: To be implemented in future.
-  return {};
+  static const char *const GCCRegNames[] = {
+  // General purpose registers.
+  "$r0", "$r1", "$r2", "$r3", "$r4", "$r5", "$r6", "$r7", "$r8", "$r9",
+  "$r10", "$r11", "$r12", "$r13", "$r14", "$r15", "$r16", "$r17", "$r18",
+  "$r19", "$r20", "$r21", "$r22", "$r23", "$r24", "$r25", "$r26", "$r27",
+  "$r28", "$r29", "$r30", "$r31",
+  // Floating point registers.
+  "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", "$f8", "$f9",
+  "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", "$f16", "$f17", "$f18",
+  "$f19", "$f20", "$f21", "$f22", "$f23", "$f24", "$f25", "$f26", "$f27",
+  "$f28", "$f29", "$f30", "$f31"};
+  return llvm::makeArrayRef(GCCRegNames);
 }
 
 ArrayRef
 LoongArchTargetInfo::getGCCRegAliases() const {
-  // TODO: To be implemented in future.
-  return {};
+  static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
+  {{"$zero"}, "$r0"},   {{"$ra"}, "$r1"},{{"$tp"}, "$r2"},
+  {{"$sp"}, "$r3"}, {{"$a0"}, "$r4"},{{"$a1"}, "$r5"},
+  {{"$a2"}, "$r6"}, {{"$a3"}, "$r7"},{{"$a4"}, "$r8"},
+  {{"$a5"}, "$r9"}, {{"$a6"}, "$r10"},   {{"$a7"}, "$r11"},
+  {{"$t0"}, "$r12"},{{"$t1"}, "$r13"},   {{"$t2"}, "$r14"},
+  {{"$t3"}, "$r15"},{{"$t4"}, "$r16"},   {{"$t5"}, "$r17"},
+  {{"$t6"}, "$r18"},{{"$t7"}, "$r19"},   {{"$t8"}, "$r20"},
+  {{"$fp", "$s9"}, "$r22"}, {{"$s0"}, "$r23"},   {{"$s1"}, "$r24"},
+  {{"$s2"}, "$r25"},{{"$s3"}, "$r26"},   {{"$s4"}, "$r27"},
+  {{"$s5"}, "$r28"},{{"$s6"}, "$r29"},   {{"$s7"}, "$r30"},
+  {{"$s8"}, "$r31"},{{"$fa0"}, "$f0"},   {{"$fa1"}, "$f1"},
+  {{"$fa2"}, "$f2"},{{"$fa3"}, "$f3"},   {{"$fa4"}, "$f4"},
+  {{"$fa5"}, "$f5"},{{"$fa6"}, "$f6"},   {{"$fa7"}, "$f7"},
+  {{"$ft0"}, "$f8"},{{"$ft1"}, "$f9"},   {{"$ft2"}, "$f10"},
+  {{"$ft3"}, "$f11"},   {{"$ft4"}, "$f12"},  {{"$ft5"}, "$f13"},
+  {{"$ft6"}, "$f14"},   {{"$ft7"}, "$f15"},  {{"$ft8"}, "$f16"},
+  {{"$ft9"}, "$f17"},   {{"$ft10"}, "$f18"}, {{"$ft11"}, "$f19"},
+  {{"$ft12"}, "$f20"},  {{"$ft13"}, "$f21"}, {{"$ft14"}, "$f22"},
+  {{"$ft15"}, "$f23"},  {{"$fs0"}, "$f24"},  {{"$fs1"}, "$f25"},
+  {{"$fs2"}, "$f26"},   {{"$fs3"}, "$f27"},  {{"$fs4"}, "$f28"

[PATCH] D134617: [HLSL] Support register binding attribute on global variable

2022-09-25 Thread Xiang Li via Phabricator via cfe-commits
python3kgae created this revision.
python3kgae added reviewers: beanz, pow2clk, bogner.
Herald added a reviewer: aaron.ballman.
Herald added a subscriber: Anastasia.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Allow register binding attribute on variables.

Report warning when register binding attribute applies to local variable or 
static variable.
It will be ignored in this case.

Type check for register binding is tracked with 
https://github.com/llvm/llvm-project/issues/57886.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134617

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/test/AST/HLSL/resource_binding_attr.hlsl
  clang/test/SemaHLSL/resource_binding_attr_error.hlsl

Index: clang/test/SemaHLSL/resource_binding_attr_error.hlsl
===
--- clang/test/SemaHLSL/resource_binding_attr_error.hlsl
+++ clang/test/SemaHLSL/resource_binding_attr_error.hlsl
@@ -1,10 +1,6 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
 
-// expected-error@+5 {{expected ';' after top level declarator}}
-// expected-error@+4 {{expected ')'}}
-// expected-note@+3 {{to match this '('}}
-// expected-error@+2 {{a type specifier is required for all declarations}}
-// expected-error@+1 {{illegal storage class on file-scoped variable}}
+// expected-error@+1 {{invalid resource class specifier 'c' used; expected 'b', 's', 't', or 'u'}}
 float a : register(c0, space1);
 
 // expected-error@+1 {{invalid resource class specifier 'i' used; expected 'b', 's', 't', or 'u'}}
@@ -36,3 +32,26 @@
 // expected-error@+2 {{wrong argument format for hlsl attribute, use b2 instead}}
 // expected-error@+1 {{wrong argument format for hlsl attribute, use space3 instead}}
 cbuffer D : register(b 2, space 3) {}
+
+// expected-warning@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
+static RWBuffer U : register(u5);
+
+void foo() {
+  // expected-warning@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
+  RWBuffer U : register(u3);
+}
+
+// FIXEME: expect-error once fix https://github.com/llvm/llvm-project/issues/57886.
+float b : register(u0, space1);
+
+// expected-warning@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
+void bar(RWBuffer U : register(u3)) {
+
+}
+
+struct S {
+  // FIXME: generate better error when support semantic on struct field.
+  // See https://github.com/llvm/llvm-project/issues/57889.
+  // expected-error@+1 {{expected expression}}
+  RWBuffer U : register(u3);
+};
Index: clang/test/AST/HLSL/resource_binding_attr.hlsl
===
--- clang/test/AST/HLSL/resource_binding_attr.hlsl
+++ clang/test/AST/HLSL/resource_binding_attr.hlsl
@@ -22,3 +22,16 @@
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}}  'float' lvalue Var 0x[[B]] 'b' 'float'
   return a + b;
 }
+
+// CHECK: VarDecl 0x{{[0-9a-f]+}} <{{.*}}> col:17 UAV 'RWBuffer':'hlsl::RWBuffer<>' callinit
+// CHECK-NEXT:-CXXConstructExpr 0x{{[0-9a-f]+}}  'RWBuffer':'hlsl::RWBuffer<>' 'void ()'
+// CHECK-NEXT:-HLSLResourceBindingAttr 0x{{[0-9a-f]+}}  "u3" "space0"
+RWBuffer UAV : register(u3);
+
+// CHECK: -VarDecl 0x{{[0-9a-f]+}} <{{.*}}> col:17 UAV1 'RWBuffer':'hlsl::RWBuffer<>' callinit
+// CHECK-NEXT:-CXXConstructExpr 0x{{[0-9a-f]+}}  'RWBuffer':'hlsl::RWBuffer<>' 'void ()'
+// CHECK-NEXT:-HLSLResourceBindingAttr 0x{{[0-9a-f]+}}  "u2" "space0"
+// CHECK-NEXT:-VarDecl 0x{{[0-9a-f]+}}  col:38 UAV2 'RWBuffer':'hlsl::RWBuffer<>' callinit
+// CHECK-NEXT:-CXXConstructExpr 0x{{[0-9a-f]+}}  'RWBuffer':'hlsl::RWBuffer<>' 'void ()'
+// CHECK-NEXT:-HLSLResourceBindingAttr 0x{{[0-9a-f]+}}  "u4" "space0"
+RWBuffer UAV1 : register(u2), UAV2 : register(u4);
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2054,6 +2054,9 @@
 return nullptr;
   }
 
+  if (getLangOpts().HLSL)
+MaybeParseHLSLSemantics(D);
+
   if (Tok.is(tok::kw_requires))
 ParseTrailingRequiresClause(D);
 
@@ -2223,6 +2226,10 @@
   DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
 
 ParseDeclarator(D);
+
+if (getLangOpts().HLSL)
+  MaybeParseHLSLSemantics(D);
+
 if (!D.isInvalidType()) {
   // C++2a [dcl.decl]p1
   //init-declarator:
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2814,6 +2814,16 @@
   Sema::AttributeCompletion Completion = Sema::AttributeCompletion::None,
   const IdentifierInfo *EnclosingScope = nullptr);
 
+
+  void Mayb

[PATCH] D134542: [Concepts] Recover properly from a RecoveryExpr in a concept

2022-09-25 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

In D134542#3814029 , @erichkeane 
wrote:

> Thanks for the quick review!  Yeah, that case is a tough one, we don't really 
> have a good way of determining whether that was supposed to fail, or be the 
> best match.  GCC does the option of just treating it as failed, so it'll have 
> the problem that I mentioned above.  No idea what MSVC is doing though 
> thats frightening.

This paper 
(https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2429r0.pdf) makes me 
like the current approach more. Basically, we better strive for intuitive 
diagnostics instead of diagnosing as many errors as possible but run the risk 
of lower-quality diagnostic messages.


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

https://reviews.llvm.org/D134542

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


[PATCH] D134542: [Concepts] Recover properly from a RecoveryExpr in a concept

2022-09-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D134542#3812711 , @ychen wrote:

> In D134542#3812292 , @erichkeane 
> wrote:
>
>> In D134542#3812211 , @ychen wrote:
>>
>>> The patch looks good. Two high-level questions:
>>>
>>> - Does the similar thing happen for class templates? Like a constraint expr 
>>> of a partial specialization has an error. Maybe we don't assert in this 
>>> case?
>>
>> WE currently crash in that case as well: https://godbolt.org/z/MGMqz1x59 .  
>> This patch still crashes in that case, and we should fix that in a similar 
>> way.  I'll put it on my list of things to do soon!  I don't want to do it in 
>> the same patch, simply because the type resolution parts are going to be 
>> completely different, and would likely just double the size of this patch.
>>
>>> - I suppose the constraint error does not always affect the overload 
>>> resolution results. When it does not, an alternative would be to assume the 
>>> constraint is a satisfaction failure and the compilation continues. Do you 
>>> see any value in this approach? Personally, I could go either way. 
>>> Basically a trade-off between pessimistic and optimistic.
>>
>> In cases where the constraint error does not affect overload resolution 
>> (like with short-circuiting), this patch makes no changes, and will continue 
>> without it.  ONLY when a constraint that references a RecoveryExpr in some 
>> way is used will we 'quit' overload resolution.
>> I ALSO considered just marking as a failure, and continuing, but 
>> @tahonermann made a point in a private chat that the result is that we'll 
>> end up getting wacky follow-up errors.  Consider something like:
>>
>>   template concept HasFoo = /*Test for has foo*/;
>>  template concept HasBarAlternative = /*test for has bar, 
>> but with a typo!*/;
>>   
>>  template requires HasFoo
>>  void do_thing(T &t) {
>>t.Foo();
>>t.Bar();
>>  }
>>  template requires HasFoo && HasBarAlternative
>>  void do_thing(T&t) {
>>t.Foo();
>>t.BarAlternative();
>>  }
>>
>> The result of just marking `HasBarAlternative' as not satisfied, is the 1st 
>> `do_thing` will be called.  THEN you'd get an error on instantiating because 
>> of the lack of `Bar`.  This seems like a worse behavior to me, and results 
>> in just nonsense-errors/not useful errors most of the time.
>
> Agreed that short-circuiting cases would not hit this issue. I actually meant 
> cases where a supposedly failed constraint has errors 
> (https://clang.godbolt.org/z/5P7fYYvao). But that could be reconsidered in 
> the future if use cases arise. With this patch, we already handle this better 
> than GCC/MSVC.
>
>   constexpr bool True = true;
>   constexpr bool False = b;
>   template  concept C = True;
>   template  concept D = False;
>   
>   template
>   void foo(T) = delete;
>   template
>   void foo(T);
>   
>   void g() {
>   foo(1);
>   }

Thanks for the quick review!  Yeah, that case is a tough one, we don't really 
have a good way of determining whether that was supposed to fail, or be the 
best match.  GCC does the option of just treating it as failed, so it'll have 
the problem that I mentioned above.  No idea what MSVC is doing though 
thats frightening.


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

https://reviews.llvm.org/D134542

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


[PATCH] D131789: [clang-format][NFC] Rewrite prints in python3 compatible way

2022-09-25 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG015ce15ea27b: [clang-format][NFC] Rewrite prints in python3 
compatible way (authored by eoanermine, committed by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131789

Files:
  
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py


Index: 
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
===
--- 
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
+++ 
clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
@@ -39,7 +39,7 @@
   result = './'
   while not os.path.isfile(os.path.join(result, path)):
 if os.path.realpath(result) == '/':
-  print 'Error: could not find compilation database.'
+  print('Error: could not find compilation database.')
   sys.exit(1)
 result += '../'
   return os.path.realpath(result)
@@ -49,7 +49,7 @@
   """Merge all symbol files (yaml) in a given directory into a single file."""
   invocation = [args.binary, '-merge-dir='+directory, args.saving_path]
   subprocess.call(invocation)
-  print 'Merge is finished. Saving results in ' + args.saving_path
+  print('Merge is finished. Saving results in ' + args.saving_path)
 
 
 def run_find_all_symbols(args, tmpdir, build_path, queue):
@@ -118,7 +118,7 @@
   except KeyboardInterrupt:
 # This is a sad hack. Unfortunately subprocess goes
 # bonkers with ctrl-c and we start forking merrily.
-print '\nCtrl-C detected, goodbye.'
+print('\nCtrl-C detected, goodbye.')
 os.kill(0, 9)
 
 


Index: clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
===
--- clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
+++ clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
@@ -39,7 +39,7 @@
   result = './'
   while not os.path.isfile(os.path.join(result, path)):
 if os.path.realpath(result) == '/':
-  print 'Error: could not find compilation database.'
+  print('Error: could not find compilation database.')
   sys.exit(1)
 result += '../'
   return os.path.realpath(result)
@@ -49,7 +49,7 @@
   """Merge all symbol files (yaml) in a given directory into a single file."""
   invocation = [args.binary, '-merge-dir='+directory, args.saving_path]
   subprocess.call(invocation)
-  print 'Merge is finished. Saving results in ' + args.saving_path
+  print('Merge is finished. Saving results in ' + args.saving_path)
 
 
 def run_find_all_symbols(args, tmpdir, build_path, queue):
@@ -118,7 +118,7 @@
   except KeyboardInterrupt:
 # This is a sad hack. Unfortunately subprocess goes
 # bonkers with ctrl-c and we start forking merrily.
-print '\nCtrl-C detected, goodbye.'
+print('\nCtrl-C detected, goodbye.')
 os.kill(0, 9)
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 015ce15 - [clang-format][NFC] Rewrite prints in python3 compatible way

2022-09-25 Thread Owen Pan via cfe-commits

Author: Danil Sidoruk
Date: 2022-09-25T13:27:42-07:00
New Revision: 015ce15ea27bcd88447d84c4b277d775fede29f7

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

LOG: [clang-format][NFC] Rewrite prints in python3 compatible way

Closes #55996.

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

Added: 


Modified: 

clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py

Removed: 




diff  --git 
a/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
 
b/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
index 8655af137bb27..a0fa64592e62b 100755
--- 
a/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
+++ 
b/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/run-find-all-symbols.py
@@ -39,7 +39,7 @@ def find_compilation_database(path):
   result = './'
   while not os.path.isfile(os.path.join(result, path)):
 if os.path.realpath(result) == '/':
-  print 'Error: could not find compilation database.'
+  print('Error: could not find compilation database.')
   sys.exit(1)
 result += '../'
   return os.path.realpath(result)
@@ -49,7 +49,7 @@ def MergeSymbols(directory, args):
   """Merge all symbol files (yaml) in a given directory into a single file."""
   invocation = [args.binary, '-merge-dir='+directory, args.saving_path]
   subprocess.call(invocation)
-  print 'Merge is finished. Saving results in ' + args.saving_path
+  print('Merge is finished. Saving results in ' + args.saving_path)
 
 
 def run_find_all_symbols(args, tmpdir, build_path, queue):
@@ -118,7 +118,7 @@ def main():
   except KeyboardInterrupt:
 # This is a sad hack. Unfortunately subprocess goes
 # bonkers with ctrl-c and we start forking merrily.
-print '\nCtrl-C detected, goodbye.'
+print('\nCtrl-C detected, goodbye.')
 os.kill(0, 9)
 
 



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


[PATCH] D133092: [clang] fix generation of .debug_aranges with LTO

2022-09-25 Thread Azat Khuzhin via Phabricator via cfe-commits
azat added a comment.

> If the two patches are basically identical with just some fixes for the 
> problem, the convention is to reuse the original Differential.

I've updated this revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133092

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


[PATCH] D133092: [clang] fix generation of .debug_aranges with LTO

2022-09-25 Thread Azat Khuzhin via Phabricator via cfe-commits
azat updated this revision to Diff 462756.
azat added a comment.

Resubmit with fixed tests and using --plugin-opt


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133092

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,7 @@
+// REQUIRES: lld
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g -target x86_64-linux -flto  -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s
+// CHECK: --plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,14 @@
 CmdArgs.push_back(Args.MakeArgString(Plugin));
   }
 
+  // Note, this solution is far from perfect, better to encode it into IR
+  // metadata, but this may not be worth it, since it looks like aranges is on
+  // the way out.
+  if (Args.hasArg(options::OPT_gdwarf_aranges)) {
+CmdArgs.push_back(
+Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,7 @@
+// REQUIRES: lld
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g -target x86_64-linux -flto  -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck %s
+// CHECK: --plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,14 @@
 CmdArgs.push_back(Args.MakeArgString(Plugin));
   }
 
+  // Note, this solution is far from perfect, better to encode it into IR
+  // metadata, but this may not be worth it, since it looks like aranges is on
+  // the way out.
+  if (Args.hasArg(options::OPT_gdwarf_aranges)) {
+CmdArgs.push_back(
+Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-25 Thread Azat Khuzhin via Phabricator via cfe-commits
azat abandoned this revision.
azat added a comment.

Closing in favor of https://reviews.llvm.org/D133092


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133875

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


[clang] ea83712 - [clang-cl] Implement /ZH: flag

2022-09-25 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-09-25T14:43:14-04:00
New Revision: ea8371247f6339c32a696e9ea2f84080f91f808d

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

LOG: [clang-cl] Implement /ZH: flag

Based on a patch by Arlo Siemsen (D98438)!

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

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/debug-info-file-checksum.c
clang/test/Driver/cl-options.c

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index c3b6b289fcff8..ddeabfc9d5451 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -341,6 +341,9 @@ CODEGENOPT(DebugExplicitImport, 1, 0)  ///< Whether or not 
debug info should
///< contain explicit imports for
///< anonymous namespaces
 
+/// Set debug info source file hashing algorithm.
+ENUM_CODEGENOPT(DebugSrcHash, DebugSrcHashKind, 2, DSH_MD5)
+
 CODEGENOPT(SplitDwarfInlining, 1, 1) ///< Whether to include inlining info in 
the
  ///< skeleton CU to allow for 
symbolication
  ///< of inline stack frames without .dwo 
files.

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 98f537e62b608..f0fc630c46a6e 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -102,6 +102,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
 IAD_Intel,
   };
 
+  enum DebugSrcHashKind {
+DSH_MD5,
+DSH_SHA1,
+DSH_SHA256,
+  };
+
   // This field stores one of the allowed values for the option
   // -fbasic-block-sections=.  The allowed values with this option are:
   // {"labels", "all", "list=", "none"}.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index cfdee32913b75..429ab38fe4afd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3217,6 +3217,12 @@ def gsimple_template_names_EQ
   HelpText<"Use simple template names in DWARF, or include the full "
"template name with a modified prefix for validation">,
   Values<"simple,mangled">, Flags<[CC1Option, NoDriverOption]>;
+def gsrc_hash_EQ : Joined<["-"], "gsrc-hash=">,
+  Group, Flags<[CC1Option, NoDriverOption]>,
+  Values<"md5,sha1,sha256">,
+  NormalizedValues<["DSH_MD5", "DSH_SHA1", "DSH_SHA256"]>,
+  NormalizedValuesScope<"CodeGenOptions">,
+  MarshallingInfoEnum, "DSH_MD5">;
 def gno_simple_template_names : Flag<["-"], "gno-simple-template-names">,
 Group;
 def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group, 
Flags<[CC1Option]>;
@@ -6657,6 +6663,15 @@ def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
   HelpText<"Disable C++ builtin type wchar_t">;
 def _SLASH_Z7 : CLFlag<"Z7">,
   HelpText<"Enable CodeView debug information in object files">;
+def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
+  HelpText<"Use MD5 for file checksums in debug info (default)">,
+  Alias, AliasArgs<["md5"]>;
+def _SLASH_ZH_SHA1 : CLFlag<"ZH:SHA1">,
+  HelpText<"Use SHA1 for file checksums in debug info">,
+  Alias, AliasArgs<["sha1"]>;
+def _SLASH_ZH_SHA_256 : CLFlag<"ZH:SHA_256">,
+  HelpText<"Use SHA256 for file checksums in debug info">,
+  Alias, AliasArgs<["sha256"]>;
 def _SLASH_Zi : CLFlag<"Zi">, Alias<_SLASH_Z7>,
   HelpText<"Like /Z7">;
 def _SLASH_Zp : CLJoined<"Zp">,
@@ -6842,9 +6857,6 @@ def _SLASH_Zc_forScope : CLIgnoredFlag<"Zc:forScope">;
 def _SLASH_Zc_inline : CLIgnoredFlag<"Zc:inline">;
 def _SLASH_Zc_rvalueCast : CLIgnoredFlag<"Zc:rvalueCast">;
 def _SLASH_Zc_ternary : CLIgnoredFlag<"Zc:ternary">;
-def _SLASH_ZH_MD5 : CLIgnoredFlag<"ZH:MD5">;
-def _SLASH_ZH_SHA1 : CLIgnoredFlag<"ZH:SHA1">;
-def _SLASH_ZH_SHA_256 : CLIgnoredFlag<"ZH:SHA_256">;
 def _SLASH_Zm : CLIgnoredJoined<"Zm">;
 def _SLASH_Zo : CLIgnoredFlag<"Zo">;
 def _SLASH_Zo_ : CLIgnoredFlag<"Zo-">;

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index a5cc5930728aa..6f6bad1052a15 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -48,6 +48,8 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/SHA1.h"
+#include "llvm/Support/SHA256.h"
 #include "llvm/Support/TimeProfiler.h"
 using namespace 

[PATCH] D134544: [clang-cl] Implement /ZH: flag

2022-09-25 Thread Nico Weber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGea8371247f63: [clang-cl] Implement /ZH: flag (authored by 
thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134544

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/debug-info-file-checksum.c
  clang/test/Driver/cl-options.c

Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -395,9 +395,6 @@
 // RUN:/wd1234 \
 // RUN:/Wv \
 // RUN:/Wv:17 \
-// RUN:/ZH:MD5 \
-// RUN:/ZH:SHA1 \
-// RUN:/ZH:SHA_256 \
 // RUN:/Zm \
 // RUN:/Zo \
 // RUN:/Zo- \
@@ -578,6 +575,17 @@
 // Z7_gdwarf: "-debug-info-kind=constructor"
 // Z7_gdwarf: "-dwarf-version=
 
+// RUN: %clang_cl /ZH:MD5 /c -### -- %s 2>&1 | FileCheck -check-prefix=ZH_MD5 %s
+// ZH_MD5: "-gsrc-hash=md5"
+
+// RUN: %clang_cl /ZH:SHA1 /c -### -- %s 2>&1 \
+// RUN: | FileCheck -check-prefix=ZH_SHA1 %s
+// ZH_SHA1: "-gsrc-hash=sha1"
+
+// RUN: %clang_cl /ZH:SHA_256 /c -### -- %s 2>&1 \
+// RUN: | FileCheck -check-prefix=ZH_SHA256 %s
+// ZH_SHA256: "-gsrc-hash=sha256"
+
 // RUN: %clang_cl -fmsc-version=1800 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX11 %s
 // CXX11: -std=c++11
 
Index: clang/test/CodeGen/debug-info-file-checksum.c
===
--- clang/test/CodeGen/debug-info-file-checksum.c
+++ clang/test/CodeGen/debug-info-file-checksum.c
@@ -1,9 +1,21 @@
+// RUN: %clang -emit-llvm -S -g -gcodeview -x c \
+// RUN: %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -g -gcodeview -Xclang -gsrc-hash=md5 \
+// RUN: -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -g -gcodeview -Xclang -gsrc-hash=sha1 \
+// RUN: -x c %S/Inputs/debug-info-file-checksum.c -o - \
+// RUN: | FileCheck --check-prefix=SHA1 %s
+// RUN: %clang -emit-llvm -S -g -gcodeview -Xclang -gsrc-hash=sha256 \
+// RUN: -x c %S/Inputs/debug-info-file-checksum.c -o - \
+// RUN: | FileCheck --check-prefix=SHA256 %s
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 // RUN: %clang -emit-llvm -S -gdwarf-5 -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 
 // Check that "checksum" is created correctly for the compiled file.
 
 // CHECK: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_MD5, checksum: "a3b7d27af071accdeccaa933fc603608")
+// SHA1: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_SHA1, checksum: "6f6eeaba705ad6db6fbb05c2cbcf3cbb3e374bcd")
+// SHA256: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_SHA256, checksum: "2d49b53859e57898a0f8c16ff1fa4d99306b8ec28d65cf7577109761f0d56197")
 
 // Ensure #line directives (in already pre-processed files) do not emit checksums
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum-pre.cpp -o - | FileCheck %s --check-prefix NOCHECKSUM
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4389,6 +4389,11 @@
 }
   }
 
+  if (const Arg *A = Args.getLastArg(options::OPT_gsrc_hash_EQ)) {
+StringRef v = A->getValue();
+CmdArgs.push_back(Args.MakeArgString("-gsrc-hash=" + v));
+  }
+
   if (Args.hasFlag(options::OPT_fdebug_ranges_base_address,
options::OPT_fno_debug_ranges_base_address, false)) {
 CmdArgs.push_back("-fdebug-ranges-base-address");
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -631,7 +631,7 @@
 
   /// Compute the file checksum debug info for input file ID.
   Optional
-  computeChecksum(FileID FID, SmallString<32> &Checksum) const;
+  computeChecksum(FileID FID, SmallString<64> &Checksum) const;
 
   /// Get the source of the given file ID.
   Optional getSource(const SourceManager &SM, FileID FID);
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -48,6 +48,8 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/SHA1.h"
+#include "llvm/Support/SHA256.h"
 #include "llvm/Support/TimeProfiler.h"
 using namespace clang;
 using namespace clan

[clang] 7847225 - [clang-format] Correctly annotate static and consteval lambdas

2022-09-25 Thread Emilia Dreamer via cfe-commits

Author: Emilia Dreamer
Date: 2022-09-25T20:29:55+03:00
New Revision: 7847225576d571fb7101463de56330e1f0e84856

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

LOG: [clang-format] Correctly annotate static and consteval lambdas

`P1169` "static operator()" (https://wg21.link/P1169) is accepted to
C++23 and while clang itself doesn't exactly support it yet,
clang-format could quite easily.

This simply allows the keyword `static` to be a part of lambdas as
specified by the addition to [expr.prim.lambda.general]

While adding this, I noticed `consteval` lambdas also aren't handled,
so that keyword is now allowed to be a part of lambdas as well

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 4fd4fd4f7c27c..87a0e43f8730e 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2230,6 +2230,7 @@ bool UnwrappedLineParser::tryToParseLambda() {
 case tok::star:
 case tok::kw_const:
 case tok::kw_constexpr:
+case tok::kw_consteval:
 case tok::comma:
 case tok::greater:
 case tok::identifier:
@@ -2237,6 +2238,7 @@ bool UnwrappedLineParser::tryToParseLambda() {
 case tok::coloncolon:
 case tok::kw_mutable:
 case tok::kw_noexcept:
+case tok::kw_static:
   nextToken();
   break;
 // Specialization of a template with an integer parameter can contain

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index d27c176415c83..6bc295c41798c 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -837,6 +837,21 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
 
+  Tokens = annotate("[]() consteval {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() mutable {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() static {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
   Tokens = annotate("[]() -> auto {}");
   ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);



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


[PATCH] D134325: [clang-format] Look ahead before consuming `bool` in requires clause.

2022-09-25 Thread Emilia Dreamer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG39e6077d9723: [clang-format] Look ahead before consuming 
`bool` in requires clause. (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134325

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


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -449,6 +449,14 @@
   EXPECT_TRUE(Tokens[14]->ClosesRequiresClause);
   EXPECT_TOKEN(Tokens[20], tok::arrow, TT_TrailingReturnArrow);
 
+  Tokens = annotate("template \n"
+"requires Bar\n"
+"bool foo(T) { return false; }");
+  ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[9]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName);
+
   Tokens = annotate("template \n"
 "struct S {\n"
 "  void foo() const requires Bar;\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3530,9 +3530,9 @@
   // concept C = bool(...);
   // and bool is the only type, all other types as cast must be inside a
   // cast to bool an thus are handled by the other cases.
-  nextToken();
-  if (FormatTok->isNot(tok::l_paren))
+  if (Tokens->peekNextToken()->isNot(tok::l_paren))
 return;
+  nextToken();
   parseParens();
   break;
 


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -449,6 +449,14 @@
   EXPECT_TRUE(Tokens[14]->ClosesRequiresClause);
   EXPECT_TOKEN(Tokens[20], tok::arrow, TT_TrailingReturnArrow);
 
+  Tokens = annotate("template \n"
+"requires Bar\n"
+"bool foo(T) { return false; }");
+  ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[9]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName);
+
   Tokens = annotate("template \n"
 "struct S {\n"
 "  void foo() const requires Bar;\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3530,9 +3530,9 @@
   // concept C = bool(...);
   // and bool is the only type, all other types as cast must be inside a
   // cast to bool an thus are handled by the other cases.
-  nextToken();
-  if (FormatTok->isNot(tok::l_paren))
+  if (Tokens->peekNextToken()->isNot(tok::l_paren))
 return;
+  nextToken();
   parseParens();
   break;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 39e6077 - [clang-format] Look ahead before consuming `bool` in requires clause.

2022-09-25 Thread Emilia Dreamer via cfe-commits

Author: Emilia Dreamer
Date: 2022-09-25T20:30:21+03:00
New Revision: 39e6077d97238ec13c9ed1b9dbae1e6408e5aba3

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

LOG: [clang-format] Look ahead before consuming `bool` in requires clause.

The comment handling the bool case says:
"bool is only allowed if it is directly followed by a paren for a cast"

This change more closely follows this directive by looking ahead for
the paren before consuming the bool keyword itself. Without a following
paren, the bool would be part of something else, such as a return type
for a function declaration

Fixes https://github.com/llvm/llvm-project/issues/57538

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 87a0e43f8730e..3919bc0ef0b35 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3530,9 +3530,9 @@ void UnwrappedLineParser::parseConstraintExpression() {
   // concept C = bool(...);
   // and bool is the only type, all other types as cast must be inside a
   // cast to bool an thus are handled by the other cases.
-  nextToken();
-  if (FormatTok->isNot(tok::l_paren))
+  if (Tokens->peekNextToken()->isNot(tok::l_paren))
 return;
+  nextToken();
   parseParens();
   break;
 

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 6bc295c41798c..c8de8a2a2abe4 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -449,6 +449,14 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   EXPECT_TRUE(Tokens[14]->ClosesRequiresClause);
   EXPECT_TOKEN(Tokens[20], tok::arrow, TT_TrailingReturnArrow);
 
+  Tokens = annotate("template \n"
+"requires Bar\n"
+"bool foo(T) { return false; }");
+  ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[9]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName);
+
   Tokens = annotate("template \n"
 "struct S {\n"
 "  void foo() const requires Bar;\n"



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


[PATCH] D134587: [clang-format] Correctly annotate static and consteval lambdas

2022-09-25 Thread Emilia Dreamer via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7847225576d5: [clang-format] Correctly annotate static and 
consteval lambdas (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134587

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


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -837,6 +837,21 @@
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
 
+  Tokens = annotate("[]() consteval {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() mutable {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() static {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
   Tokens = annotate("[]() -> auto {}");
   ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2230,6 +2230,7 @@
 case tok::star:
 case tok::kw_const:
 case tok::kw_constexpr:
+case tok::kw_consteval:
 case tok::comma:
 case tok::greater:
 case tok::identifier:
@@ -2237,6 +2238,7 @@
 case tok::coloncolon:
 case tok::kw_mutable:
 case tok::kw_noexcept:
+case tok::kw_static:
   nextToken();
   break;
 // Specialization of a template with an integer parameter can contain


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -837,6 +837,21 @@
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
 
+  Tokens = annotate("[]() consteval {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() mutable {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() static {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
   Tokens = annotate("[]() -> auto {}");
   ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2230,6 +2230,7 @@
 case tok::star:
 case tok::kw_const:
 case tok::kw_constexpr:
+case tok::kw_consteval:
 case tok::comma:
 case tok::greater:
 case tok::identifier:
@@ -2237,6 +2238,7 @@
 case tok::coloncolon:
 case tok::kw_mutable:
 case tok::kw_noexcept:
+case tok::kw_static:
   nextToken();
   break;
 // Specialization of a template with an integer parameter can contain
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134337: [clang] [Driver] More flexible rules for loading default configs (WIP)

2022-09-25 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

In D134337#3813779 , @sepavloff wrote:

> First clang tries to find `x86_64-pc-linux-gnu-clang.cfg`. Just tool name 
> with added suffix `cfg`. No target override, no attempt to split tool name 
> into components. It provides possibility to have a separate configuration for 
> any tool. The existing mechanism does not search for such file, so 
> compatibility cannot be broken. This variant makes it possible to use 
> configuration file even if tool name is arbitrary and does not follow usual 
> pattern.

That's incorrect. The existing algorithm uses precisely this file if that's how 
clang is named:

  $ ./bin/x86_64-pc-linux-gnu-clang --version
  clang version 16.0.0 (g...@github.com:llvm/llvm-project.git 
17779984ca4441657071ea5abe6ef2bb32306dce)
  Target: x86_64-pc-linux-gnu
  Thread model: posix
  InstalledDir: /home/mgorny/git/llvm-project/build/./bin
  Configuration file: /tmp/clang-config/x86_64-pc-linux-gnu-clang.cfg

Also note that it performs the arch substitution on this path:

  $ ./bin/x86_64-pc-linux-gnu-clang --version -m32
  clang version 16.0.0 (g...@github.com:llvm/llvm-project.git 
17779984ca4441657071ea5abe6ef2bb32306dce)
  Target: i386-pc-linux-gnu
  Thread model: posix
  InstalledDir: /home/mgorny/git/llvm-project/build/./bin
  Configuration file: /tmp/clang-config/i386-pc-linux-gnu-clang.cfg

So your proposal breaks backwards compatibility.

> If `x86_64-pc-linux-gnu-clang.cfg` is found, it is loaded as configuration 
> file and that's all. Otherwise the middle components are dropped and only 
> target prefix and driver mode suffix are used for the search. It is similar 
> to the search made by existing implementation, the following files that are 
> looked for :
>
> - `i386-clang.cfg`
> - `i386.cfg`
> - `x86_64-clang.cfg`
> - `x86_64.cfg`
>
> If the file found has form `target.cfg` or none of the files was found, clang 
> tries to load driver-mode configuration file. The files are the same as in 
> your algorithm:
>
> - `clang++.cfg`
> - `clang.cfg`
>
> The driver-mode configuration is loaded prior to the target config, - as it 
> may contain default settings that target config may override. In the current 
> implementation such files are not, risk of breaking compatibility is minimal.
>
> What do you think about this variant? Does it fit your use case?

Well, my immediate use case only needs per-driver mode configuration files, so 
it would work — presuming we're using the real driver mode and not the 
executable suffix.

However, I definitely do see potential use cases for per-target configuration 
files — for example, providing target-specific paths instead of hardcoding them 
in the driver. Please note that architecture part alone is insufficient here — 
there are ABIs (such as n32 ABI on mips or x32 ABI on x86_64) that can only be 
distinguished by `-gnuabin32` or `-gnux32` suffix rather than the architecture 
part. This is also relevant to hardfloat/softfloat targets, and the larger part 
of the triple is definitely needed for cross-toolchains that may target 
different operating systems.

Perhaps it would be easier if you described your use case to me — I presume you 
have one as author of the original patch.


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

https://reviews.llvm.org/D134337

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


[PATCH] D131963: [libc++] Add custom clang-tidy checks

2022-09-25 Thread Jonathan Wakely via Phabricator via cfe-commits
jwakely added inline comments.



Comment at: libcxx/test/tools/clang_tidy_checks/robust_against_adl.cpp:22
+AST_MATCHER(clang::UnresolvedLookupExpr, isCustomizationPoint) {
+  // TODO: Are make_error_code and make_error_condition actually customization 
points?
+  return std::ranges::any_of(

Mordante wrote:
> ldionne wrote:
> > This is funny, I actually saw a LWG issue about that go by a few weeks ago. 
> > I'll try to get more details.
> @ldionne @jwakely posted this bug report about it 
> https://github.com/llvm/llvm-project/issues/57614
They're definitely customization points. If they weren't, specializing 
`is_error_code_enum` and `is_error_condition_enum` would be completely useless 
and serve no purpose.

LWG confirmed that and [LWG 3629](https://wg21.link/lwg3629) is Tentatively 
Ready now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131963

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


[PATCH] D134604: [clang] Instiantiate early substituted entities with sugared template arguments

2022-09-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 462738.
Herald added subscribers: kadircet, arphaman.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134604

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.const/p3-0x.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
  clang/test/CXX/temp/temp.deduct.guide/p3.cpp
  clang/test/CXX/temp/temp.param/p10-2a.cpp
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/SemaCXX/sizeless-1.cpp
  clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
  clang/test/SemaTemplate/instantiate-requires-expr.cpp
  clang/test/SemaTemplate/instantiation-default-1.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/pr52970.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1 +1,2 @@
 D131858
+D134604
Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -437,7 +437,7 @@
 
   template class X> struct A {
 template N> struct B; // expected-note 2{{here}}
-template struct B {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y' (aka 'type-parameter-0-0 *')}}
+template  struct B {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y' (aka 'T *')}}
   };
   A::B ax;
   A::B ay; // expected-error {{undefined}} expected-note {{instantiation of}}
Index: clang/test/SemaTemplate/pr52970.cpp
===
--- clang/test/SemaTemplate/pr52970.cpp
+++ clang/test/SemaTemplate/pr52970.cpp
@@ -53,7 +53,7 @@
 #if __cplusplus >= 202002L
 template 
 concept C = requires(T t) { t.begin(); };
-  // cxx20-note@-1 {{because 't.begin()' would be invalid: member reference type 'Holder *' is a pointer}}
+  // cxx20-note@-1 {{because 't.begin()' would be invalid: member reference type 'Bad' (aka 'Holder *') is a pointer}}
 
 static_assert(C);
 static_assert(!C);
Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_integer_seq.cpp
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -46,9 +46,9 @@
 // CHECK-NEXT:   |-TemplateArgument expr
 // CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT:   |   |-value: Int 1
-// CHECK-NEXT:   |   `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT:   |   `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}}  'int':'int'
 // CHECK-NEXT:   | |-NonTypeTemplateParmDecl 0x{{[0-9A-Fa-f]+}}  col:24 referenced 'B1' depth 0 index 1 B2
-// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
+// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int':'int' 1
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A' sugar A
 // CHECK-NEXT: |-TemplateArgument type 'int':'int'
 // CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar typename depth 0 index 1
@@ -73,14 +73,14 @@
 // CHECK-NEXT:   | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'T' dependent depth 0 index 1
 // CHECK-NEXT:   |   `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'T'
 // CHECK-NEXT:   |-TemplateArgument expr
-// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T':'T' 
 // CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' dependent __make_integer_seq
 // CHECK-NEXT: |-TemplateArgument template
 // CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NEXT: | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent depth 0 index 1
 // CHECK-NEXT: `-TemplateArgument expr
-// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T

[PATCH] D134337: [clang] [Driver] More flexible rules for loading default configs (WIP)

2022-09-25 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

I would propose to slightly modify the config file search algorithm.

For the tool named as `x86_64-pc-linux-gnu-clang`, the existing algorithm would 
search for the files:

- `i386-clang.cfg`
- `i386.cfg`
- `x86_64-clang.cfg`
- `x86_64.cfg`

We could modify this algorithm to obtain more flexible one and still preserve 
backward compatibility as much as possible. Let's use  the invocation 
`x86_64-pc-linux-gnu-clang --driver-mode=g++ -target i386` as example and see 
what files the tool would search for in the modified algorithm.

First clang tries to find `x86_64-pc-linux-gnu-clang.cfg`. Just tool name with 
added suffix `cfg`. No target override, no attempt to split tool name into 
components. It provides possibility to have a separate configuration for any 
tool. The existing mechanism does not search for such file, so compatibility 
cannot be broken. This variant makes it possible to use configuration file even 
if tool name is arbitrary and does not follow usual pattern.

If `x86_64-pc-linux-gnu-clang.cfg` is found, it is loaded as configuration file 
and that's all. Otherwise the middle components are dropped and only target 
prefix and driver mode suffix are used for the search. It is similar to the 
search made by existing implementation, the following files that are looked for 
:

- `i386-clang.cfg`
- `i386.cfg`
- `x86_64-clang.cfg`
- `x86_64.cfg`

If the file found has form `target.cfg` or none of the files was found, clang 
tries to load driver-mode configuration file. The files are the same as in your 
algorithm:

- `clang++.cfg`
- `clang.cfg`

The driver-mode configuration is loaded prior to the target config, - as it may 
contain default settings that target config may override. In the current 
implementation such files are not, risk of breaking compatibility is minimal.

What do you think about this variant? Does it fit your use case?


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

https://reviews.llvm.org/D134337

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


[PATCH] D134604: [clang] Instiantiate early substituted entities with sugared template arguments

2022-09-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 462735.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134604

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.const/p3-0x.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
  clang/test/CXX/temp/temp.deduct.guide/p3.cpp
  clang/test/CXX/temp/temp.param/p10-2a.cpp
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/SemaCXX/sizeless-1.cpp
  clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
  clang/test/SemaTemplate/instantiate-requires-expr.cpp
  clang/test/SemaTemplate/instantiation-default-1.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/pr52970.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1 +1,2 @@
 D131858
+D134604
Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -437,7 +437,7 @@
 
   template class X> struct A {
 template N> struct B; // expected-note 2{{here}}
-template struct B {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y' (aka 'type-parameter-0-0 *')}}
+template  struct B {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y' (aka 'T *')}}
   };
   A::B ax;
   A::B ay; // expected-error {{undefined}} expected-note {{instantiation of}}
Index: clang/test/SemaTemplate/pr52970.cpp
===
--- clang/test/SemaTemplate/pr52970.cpp
+++ clang/test/SemaTemplate/pr52970.cpp
@@ -53,7 +53,7 @@
 #if __cplusplus >= 202002L
 template 
 concept C = requires(T t) { t.begin(); };
-  // cxx20-note@-1 {{because 't.begin()' would be invalid: member reference type 'Holder *' is a pointer}}
+  // cxx20-note@-1 {{because 't.begin()' would be invalid: member reference type 'Bad' (aka 'Holder *') is a pointer}}
 
 static_assert(C);
 static_assert(!C);
Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_integer_seq.cpp
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -46,9 +46,9 @@
 // CHECK-NEXT:   |-TemplateArgument expr
 // CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT:   |   |-value: Int 1
-// CHECK-NEXT:   |   `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT:   |   `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}}  'int':'int'
 // CHECK-NEXT:   | |-NonTypeTemplateParmDecl 0x{{[0-9A-Fa-f]+}}  col:24 referenced 'B1' depth 0 index 1 B2
-// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
+// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int':'int' 1
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A' sugar A
 // CHECK-NEXT: |-TemplateArgument type 'int':'int'
 // CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar typename depth 0 index 1
@@ -73,14 +73,14 @@
 // CHECK-NEXT:   | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'T' dependent depth 0 index 1
 // CHECK-NEXT:   |   `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'T'
 // CHECK-NEXT:   |-TemplateArgument expr
-// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T':'T' 
 // CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' dependent __make_integer_seq
 // CHECK-NEXT: |-TemplateArgument template
 // CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NEXT: | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent depth 0 index 1
 // CHECK-NEXT: `-TemplateArgument expr
-// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A

[PATCH] D134453: Introduce the `AlwaysIncludeTypeForNonTypeTemplateArgument` into printing policy

2022-09-25 Thread Nenad Mikša via Phabricator via cfe-commits
DoDoENT added inline comments.



Comment at: clang/include/clang/AST/PrettyPrinter.h:307
+  /// decltype(s) will be printed as "S" if enabled and as 
"S<{1,2}>" if disabled,
+  /// regardless if PrintCanonicalTypes is enabled.
+  unsigned AlwaysIncludeTypeForNonTypeTemplateArgument : 1;

dblaikie wrote:
> DoDoENT wrote:
> > DoDoENT wrote:
> > > dblaikie wrote:
> > > > aaron.ballman wrote:
> > > > > DoDoENT wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > dblaikie wrote:
> > > > > > > > DoDoENT wrote:
> > > > > > > > > dblaikie wrote:
> > > > > > > > > > What does `PrintCanonicalTypes` have to do with this? Does 
> > > > > > > > > > it overlap with this functionality in some way, but doesn't 
> > > > > > > > > > provide the functionality you want in particular?
> > > > > > > > > Thank you for the question. If you set the 
> > > > > > > > > `PrintCanonicalTypes` to `false`, the `S` would 
> > > > > > > > > be printed as `S` even without this patch. 
> > > > > > > > > However, if you set it to `true`, it will be printed as 
> > > > > > > > > `S<{1, 2}>`.
> > > > > > > > > 
> > > > > > > > > I don't fully understand why it does that, but it's quite 
> > > > > > > > > annoying.
> > > > > > > > > 
> > > > > > > > > For a better example, please take a look at the 
> > > > > > > > > `TemplateIdWithComplexFullTypeNTTP` unit tests that I've 
> > > > > > > > > added: if `PrintCanonicalTypes` is set to `true`, the 
> > > > > > > > > original print output of type is `NDArray > > > > > > > > {{{0}}}, {{{0}}}>`, and if set to `false` (which is default), 
> > > > > > > > > the output is `NDArray > > > > > > > > Channels{{{0}}}>` - so the NTTP type is neither fully written 
> > > > > > > > > nor fully omitted, which is weird.
> > > > > > > > > 
> > > > > > > > > As I said, I don't really understand the idea behind 
> > > > > > > > > `PrintCanonicalTypes`, but when my new 
> > > > > > > > > `AlwaysIncludeTypeForNonTypeTemplateArgument` is enabled, you 
> > > > > > > > > will get the full type printed, regardless of value of 
> > > > > > > > > `PrintCanonicalTypes` setting.
> > > > > > > > > 
> > > > > > > > Perhaps this might be more of a bug in PrintCanonicalTypes than 
> > > > > > > > something to add a separate flag for.
> > > > > > > > 
> > > > > > > > @aaron.ballman D2 for context here... 
> > > > > > > > 
> > > > > > > > Hmm, actually, just adding the top level `Height{{0}}, 
> > > > > > > > Width{{0}}, Channels{{0}}` is sufficient to make this code 
> > > > > > > > compile (whereas with the `{{{0}}}` it doesn't form a valid 
> > > > > > > > identifier.
> > > > > > > > 
> > > > > > > > So what's your use case for needing more explicitness than that 
> > > > > > > > top level? 
> > > > > > > > Perhaps this might be more of a bug in PrintCanonicalTypes than 
> > > > > > > > something to add a separate flag for.
> > > > > > > >
> > > > > > > > @aaron.ballman D2 for context here...
> > > > > > > 
> > > > > > > I looked over D2 again and haven't spotted anything with it 
> > > > > > > that seems amiss; the change there is to grab the canonical type 
> > > > > > > before trying to print it which is all the more I'd expect 
> > > > > > > `PrintCanonicalTypes` to impact.
> > > > > > > 
> > > > > > > This looks like the behavior you'd get when you desugar the type. 
> > > > > > > Check out the AST dump for `s`: https://godbolt.org/z/vxh5j6qWr
> > > > > > > ```
> > > > > > > `-VarDecl  col:20 s 'S':'S<{1, 
> > > > > > > 2}>' callinit
> > > > > > > ```
> > > > > > > We generate that type information at 
> > > > > > > https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/TextNodeDumper.cpp#L663
> > > > > > >  for doing the AST dump, note how the second type printed is the 
> > > > > > > desugared type and that matches what we're seeing from the pretty 
> > > > > > > printer.
> > > > > > > So what's your use case for needing more explicitness than that 
> > > > > > > top level?
> > > > > > 
> > > > > > As I described in the [github 
> > > > > > issue](https://github.com/llvm/llvm-project/issues/57562), I'm 
> > > > > > trying to write a clang-based tool that will have different 
> > > > > > behavior if the printed `{{{0}}}` is actually `Width` than if its 
> > > > > > `Height` or anything else.
> > > > > > 
> > > > > > You can see the the issue in the AST dump for `bla`: 
> > > > > > https://godbolt.org/z/fMr4f13o3
> > > > > > 
> > > > > > The type is
> > > > > > ```
> > > > > > `-VarDecl  col:21 bla 'NDArray > > > > > W>':'NDArray' callinit
> > > > > >   `-CXXConstructExpr  'NDArray':'NDArray > > > > > {{{0}}}>' 'void () noexcept'
> > > > > > ```
> > > > > > 
> > > > > > so it's unknown whether `{{{0}}}` represent the `Width` or 
> > > > > > `Height`. My patch makes it work exactly like GCC (see the 
> > > > > > comparison of error message between [clang 15 and GCC 
> > > > > > 12.1](https://godbolt.org/z/WenWe8caf).
> > > > > > 
> > > > > > > Perhaps this might be more of 

[PATCH] D134604: [clang] Instiantiate early substituted entities with sugared template arguments

2022-09-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

WIP - Not ready for review

Signed-off-by: Matheus Izvekov 

Depends on D133874 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134604

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/expr/expr.const/p3-0x.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
  clang/test/CXX/temp/temp.deduct.guide/p3.cpp
  clang/test/CXX/temp/temp.param/p10-2a.cpp
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/SemaCXX/sizeless-1.cpp
  clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
  clang/test/SemaTemplate/instantiate-requires-expr.cpp
  clang/test/SemaTemplate/instantiation-default-1.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/pr52970.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp

Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -437,7 +437,7 @@
 
   template class X> struct A {
 template N> struct B; // expected-note 2{{here}}
-template struct B {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y' (aka 'type-parameter-0-0 *')}}
+template  struct B {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y' (aka 'T *')}}
   };
   A::B ax;
   A::B ay; // expected-error {{undefined}} expected-note {{instantiation of}}
Index: clang/test/SemaTemplate/pr52970.cpp
===
--- clang/test/SemaTemplate/pr52970.cpp
+++ clang/test/SemaTemplate/pr52970.cpp
@@ -53,7 +53,7 @@
 #if __cplusplus >= 202002L
 template 
 concept C = requires(T t) { t.begin(); };
-  // cxx20-note@-1 {{because 't.begin()' would be invalid: member reference type 'Holder *' is a pointer}}
+  // cxx20-note@-1 {{because 't.begin()' would be invalid: member reference type 'Bad' (aka 'Holder *') is a pointer}}
 
 static_assert(C);
 static_assert(!C);
Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_integer_seq.cpp
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -46,9 +46,9 @@
 // CHECK-NEXT:   |-TemplateArgument expr
 // CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT:   |   |-value: Int 1
-// CHECK-NEXT:   |   `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT:   |   `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}}  'int':'int'
 // CHECK-NEXT:   | |-NonTypeTemplateParmDecl 0x{{[0-9A-Fa-f]+}}  col:24 referenced 'B1' depth 0 index 1 B2
-// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
+// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int':'int' 1
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A' sugar A
 // CHECK-NEXT: |-TemplateArgument type 'int':'int'
 // CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar typename depth 0 index 1
@@ -73,14 +73,14 @@
 // CHECK-NEXT:   | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'T' dependent depth 0 index 1
 // CHECK-NEXT:   |   `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'T'
 // CHECK-NEXT:   |-TemplateArgument expr
-// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T':'T' 
 // CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
 // CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' dependent __make_integer_seq
 // CHECK-NEXT: |-TemplateArgument template
 // CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NEXT: | `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent depth 0 index 1
 // CHECK-NEXT: `-TemplateArgument expr
-// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'type-parameter-0-1':'type-parameter-0-1' 
+// CHECK-NEXT:   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'T':'T' 
 // CHECK-NEXT: `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
 
   using test4 = __ma

[PATCH] D134544: [clang-cl] Implement /ZH: flag

2022-09-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.h:106
+  enum SrcHashAlgorithm {
+CSK_MD5,
+CSK_SHA1,

hans wrote:
> thakis wrote:
> > hans wrote:
> > > what does CSK stand for here?
> > I'm guessing "check sum kind", but I don't know :)
> > 
> > `SHA_` looks a bit funny as prefix too...
> > 
> > I also don't love the cc1 flag name, but I figured it's a bit bikesheddy 
> > and it's internal only so i kept it as is.
> > 
> > If you have a preference for flag name, enum name, and enum prefix, let me 
> > know.
> How about
> 
> `enum DebugSrcHashKind { DSH_MD5, ...`
> 
> ("kind" seems a common suffix for these, "debug" is a nice hint about what 
> area this applies to.)
DebugSourceHash it is.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:377
+  }
+  return CSKind;
 }

hans wrote:
> Perhaps it would be simpler to drop the CSKind variable and fold the return 
> into the individual cases?
Oh, that's much nicer, thanks.


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

https://reviews.llvm.org/D134544

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


[PATCH] D134544: [clang-cl] Implement /ZH: flag

2022-09-25 Thread Nico Weber via Phabricator via cfe-commits
thakis updated this revision to Diff 462731.
thakis added a comment.

final tweaks


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

https://reviews.llvm.org/D134544

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/debug-info-file-checksum.c
  clang/test/Driver/cl-options.c

Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -395,9 +395,6 @@
 // RUN:/wd1234 \
 // RUN:/Wv \
 // RUN:/Wv:17 \
-// RUN:/ZH:MD5 \
-// RUN:/ZH:SHA1 \
-// RUN:/ZH:SHA_256 \
 // RUN:/Zm \
 // RUN:/Zo \
 // RUN:/Zo- \
@@ -578,6 +575,17 @@
 // Z7_gdwarf: "-debug-info-kind=constructor"
 // Z7_gdwarf: "-dwarf-version=
 
+// RUN: %clang_cl /ZH:MD5 /c -### -- %s 2>&1 | FileCheck -check-prefix=ZH_MD5 %s
+// ZH_MD5: "-gsrc-hash=md5"
+
+// RUN: %clang_cl /ZH:SHA1 /c -### -- %s 2>&1 \
+// RUN: | FileCheck -check-prefix=ZH_SHA1 %s
+// ZH_SHA1: "-gsrc-hash=sha1"
+
+// RUN: %clang_cl /ZH:SHA_256 /c -### -- %s 2>&1 \
+// RUN: | FileCheck -check-prefix=ZH_SHA256 %s
+// ZH_SHA256: "-gsrc-hash=sha256"
+
 // RUN: %clang_cl -fmsc-version=1800 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX11 %s
 // CXX11: -std=c++11
 
Index: clang/test/CodeGen/debug-info-file-checksum.c
===
--- clang/test/CodeGen/debug-info-file-checksum.c
+++ clang/test/CodeGen/debug-info-file-checksum.c
@@ -1,9 +1,21 @@
+// RUN: %clang -emit-llvm -S -g -gcodeview -x c \
+// RUN: %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -g -gcodeview -Xclang -gsrc-hash=md5 \
+// RUN: -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -g -gcodeview -Xclang -gsrc-hash=sha1 \
+// RUN: -x c %S/Inputs/debug-info-file-checksum.c -o - \
+// RUN: | FileCheck --check-prefix=SHA1 %s
+// RUN: %clang -emit-llvm -S -g -gcodeview -Xclang -gsrc-hash=sha256 \
+// RUN: -x c %S/Inputs/debug-info-file-checksum.c -o - \
+// RUN: | FileCheck --check-prefix=SHA256 %s
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 // RUN: %clang -emit-llvm -S -gdwarf-5 -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 
 // Check that "checksum" is created correctly for the compiled file.
 
 // CHECK: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_MD5, checksum: "a3b7d27af071accdeccaa933fc603608")
+// SHA1: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_SHA1, checksum: "6f6eeaba705ad6db6fbb05c2cbcf3cbb3e374bcd")
+// SHA256: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_SHA256, checksum: "2d49b53859e57898a0f8c16ff1fa4d99306b8ec28d65cf7577109761f0d56197")
 
 // Ensure #line directives (in already pre-processed files) do not emit checksums
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum-pre.cpp -o - | FileCheck %s --check-prefix NOCHECKSUM
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4389,6 +4389,11 @@
 }
   }
 
+  if (const Arg *A = Args.getLastArg(options::OPT_gsrc_hash_EQ)) {
+StringRef v = A->getValue();
+CmdArgs.push_back(Args.MakeArgString("-gsrc-hash=" + v));
+  }
+
   if (Args.hasFlag(options::OPT_fdebug_ranges_base_address,
options::OPT_fno_debug_ranges_base_address, false)) {
 CmdArgs.push_back("-fdebug-ranges-base-address");
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -631,7 +631,7 @@
 
   /// Compute the file checksum debug info for input file ID.
   Optional
-  computeChecksum(FileID FID, SmallString<32> &Checksum) const;
+  computeChecksum(FileID FID, SmallString<64> &Checksum) const;
 
   /// Get the source of the given file ID.
   Optional getSource(const SourceManager &SM, FileID FID);
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -48,6 +48,8 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/SHA1.h"
+#include "llvm/Support/SHA256.h"
 #include "llvm/Support/TimeProfiler.h"
 using namespace clang;
 using namespace clang::CodeGen;
@@ -344,7 +346,7 @@
 }
 
 Optional
-CGDebugInfo::computeChecksum(FileID FID, SmallString<32> &Checksum) const {
+CGDebugInfo::computeCh

[PATCH] D134592: [clang-tidy] Add option to control floating point binary operators in readability-simplify-boolean-expr

2022-09-25 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:155
+
+  Added an option SafeFloatComparisons to control negating binary operators 
+  with floating point operands.

Eugene.Zelenko wrote:
> Please enclose `SafeFloatComparisons` into single back-ticks.
It would be nice if it were possible to link to the actual option 
documentation, but I dont think rst supports those kinds of links.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134592

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


[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-09-25 Thread Liming Liu via Phabricator via cfe-commits
lime added a comment.

Well, Something happened after rebasing this patch on D126907 
. `s41` below was rejected as the constrain 
generated from `template ` was no longer considered to subsume the constrain 
generated from `template  requires C` in the template template 
argument, which is not the case  in both GCC 
and MSVC. However, GCC and MSVC also accept the redeclaration for `S`, which 
might be ill-formed because of this rule 
. If this kind of 
redeclaration happens on `X`, GCC and MSVC will reject it. Rebasing this patch 
on D126907  will also not make the both 
redeclaration valid.

Personally, I decided to make `s41` valid for Clang, a clue might be making the 
`QualType`s the same in the parameters of two generated constrains.

  template  concept C = T::f();
  
  template  concept C1 = T::f();
  
  template  struct X {};
  
  template  requires C struct X; // ill-formed for sure
  
  template  struct Y {};
  
  template  requires C class> struct S {};
  
  template  class> struct S; // GCC and MSVC accept this
  
  S sx; // my target
  S sy; // ill-formed for sure


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

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


[PATCH] D134177: Add MC support of RISCV Zcd Extension

2022-09-25 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu updated this revision to Diff 462727.
VincentWu added a comment.

fix testcase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134177

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoC.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/MC/RISCV/rv32dc-valid.s
  llvm/test/MC/RISCV/rv64dc-valid.s

Index: llvm/test/MC/RISCV/rv64dc-valid.s
===
--- llvm/test/MC/RISCV/rv64dc-valid.s
+++ llvm/test/MC/RISCV/rv64dc-valid.s
@@ -3,31 +3,39 @@
 # RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+c,+d < %s \
 # RUN: | llvm-objdump --mattr=+c,+d -M no-aliases -d -r - \
 # RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zcd,+d -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zcd,+d < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zcd,+d -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
 #
 # RUN: not llvm-mc -triple riscv64 -mattr=+c \
 # RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
 # RUN: | FileCheck -check-prefixes=CHECK-NO-EXT-D %s
+# RUN: not llvm-mc -triple riscv64 -mattr=+experimental-zcd \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT-D %s
 # RUN: not llvm-mc -triple riscv64 -riscv-no-aliases -show-encoding < %s 2>&1 \
 # RUN: | FileCheck -check-prefixes=CHECK-NO-EXT-DC %s
 
 # CHECK-ASM-AND-OBJ: c.fldsp  fs0, 504(sp)
 # CHECK-ASM: encoding: [0x7e,0x34]
 # CHECK-NO-EXT-D:  error: instruction requires the following: 'D' (Double-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions), 'D' (Double-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcd' (Compressed Double-Precision Floating-Point Instructions), 'D' (Double-Precision Floating-Point){{$}}
 c.fldsp  fs0, 504(sp)
 # CHECK-ASM-AND-OBJ: c.fsdsp  fa7, 504(sp)
 # CHECK-ASM: encoding: [0xc6,0xbf]
 # CHECK-NO-EXT-D:  error: instruction requires the following: 'D' (Double-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions), 'D' (Double-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcd' (Compressed Double-Precision Floating-Point Instructions), 'D' (Double-Precision Floating-Point){{$}}
 c.fsdsp  fa7, 504(sp)
 
 # CHECK-ASM-AND-OBJ: c.fld  fa3, 248(a5)
 # CHECK-ASM: encoding: [0xf4,0x3f]
 # CHECK-NO-EXT-D:  error: instruction requires the following: 'D' (Double-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions), 'D' (Double-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcd' (Compressed Double-Precision Floating-Point Instructions), 'D' (Double-Precision Floating-Point){{$}}
 c.fld  fa3, 248(a5)
 # CHECK-ASM-AND-OBJ: c.fsd  fa2, 248(a1)
 # CHECK-ASM: encoding: [0xf0,0xbd]
 # CHECK-NO-EXT-D:  error: instruction requires the following: 'D' (Double-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions), 'D' (Double-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcd' (Compressed Double-Precision Floating-Point Instructions), 'D' (Double-Precision Floating-Point){{$}}
 c.fsd  fa2, 248(a1)
Index: llvm/test/MC/RISCV/rv32dc-valid.s
===
--- llvm/test/MC/RISCV/rv32dc-valid.s
+++ llvm/test/MC/RISCV/rv32dc-valid.s
@@ -3,31 +3,39 @@
 # RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+c,+d < %s \
 # RUN: | llvm-objdump --mattr=+c,+d -M no-aliases -d -r - \
 # RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zcd,+d -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zcd,+d < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zcd,+d -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
 #
 # RUN: not llvm-mc -triple riscv32 -mattr=+c \
 # RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
 # RUN: | FileCheck -check-prefixes=CHECK-NO-EXT-D %s
+# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-zcd \

[PATCH] D134588: [clang-tidy] Fix bugprone-exception-escape warn on noexcept calls

2022-09-25 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

It'll be good idea to mention change in Release Notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134588

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


[PATCH] D134592: [clang-tidy] Add option to control floating point binary operators in readability-simplify-boolean-expr

2022-09-25 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:155
+
+  Added an option SafeFloatComparisons to control negating binary operators 
+  with floating point operands.

Please enclose `SafeFloatComparisons` into single back-ticks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134592

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


[PATCH] D131963: [libc++] Add custom clang-tidy checks

2022-09-25 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a subscriber: jwakely.
Mordante added inline comments.



Comment at: libcxx/test/tools/clang_tidy_checks/robust_against_adl.cpp:22
+AST_MATCHER(clang::UnresolvedLookupExpr, isCustomizationPoint) {
+  // TODO: Are make_error_code and make_error_condition actually customization 
points?
+  return std::ranges::any_of(

ldionne wrote:
> This is funny, I actually saw a LWG issue about that go by a few weeks ago. 
> I'll try to get more details.
@ldionne @jwakely posted this bug report about it 
https://github.com/llvm/llvm-project/issues/57614


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131963

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


[PATCH] D134177: Add MC support of RISCV Zcd Extension

2022-09-25 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu updated this revision to Diff 462721.
VincentWu marked 3 inline comments as done.
VincentWu added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134177

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoC.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/MC/RISCV/rv32dc-valid.s
  llvm/test/MC/RISCV/rv64dc-valid.s

Index: llvm/test/MC/RISCV/rv64dc-valid.s
===
--- llvm/test/MC/RISCV/rv64dc-valid.s
+++ llvm/test/MC/RISCV/rv64dc-valid.s
@@ -3,31 +3,39 @@
 # RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+c,+d < %s \
 # RUN: | llvm-objdump --mattr=+c,+d -M no-aliases -d -r - \
 # RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zcd,+d -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zcd,+d < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zcd,+d -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
 #
 # RUN: not llvm-mc -triple riscv64 -mattr=+c \
 # RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
 # RUN: | FileCheck -check-prefixes=CHECK-NO-EXT-D %s
+# RUN: not llvm-mc -triple riscv64 -mattr=+experimental-zcd \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT-D %s
 # RUN: not llvm-mc -triple riscv64 -riscv-no-aliases -show-encoding < %s 2>&1 \
 # RUN: | FileCheck -check-prefixes=CHECK-NO-EXT-DC %s
 
 # CHECK-ASM-AND-OBJ: c.fldsp  fs0, 504(sp)
 # CHECK-ASM: encoding: [0x7e,0x34]
 # CHECK-NO-EXT-D:  error: instruction requires the following: 'D' (Double-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions), 'D' (Double-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcd' (Compressed Double-Precision Floating-Point Instructions), 'D' (Double-Precision Floating-Point){{$}}
 c.fldsp  fs0, 504(sp)
 # CHECK-ASM-AND-OBJ: c.fsdsp  fa7, 504(sp)
 # CHECK-ASM: encoding: [0xc6,0xbf]
 # CHECK-NO-EXT-D:  error: instruction requires the following: 'D' (Double-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions), 'D' (Double-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcd' (Compressed Double-Precision Floating-Point Instructions), 'D' (Double-Precision Floating-Point){{$}}
 c.fsdsp  fa7, 504(sp)
 
 # CHECK-ASM-AND-OBJ: c.fld  fa3, 248(a5)
 # CHECK-ASM: encoding: [0xf4,0x3f]
 # CHECK-NO-EXT-D:  error: instruction requires the following: 'D' (Double-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions), 'D' (Double-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcd' (Compressed Double-Precision Floating-Point Instructions), 'D' (Double-Precision Floating-Point){{$}}
 c.fld  fa3, 248(a5)
 # CHECK-ASM-AND-OBJ: c.fsd  fa2, 248(a1)
 # CHECK-ASM: encoding: [0xf0,0xbd]
 # CHECK-NO-EXT-D:  error: instruction requires the following: 'D' (Double-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions), 'D' (Double-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-DC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcd' (Compressed Double-Precision Floating-Point Instructions), 'D' (Double-Precision Floating-Point){{$}}
 c.fsd  fa2, 248(a1)
Index: llvm/test/MC/RISCV/rv32dc-valid.s
===
--- llvm/test/MC/RISCV/rv32dc-valid.s
+++ llvm/test/MC/RISCV/rv32dc-valid.s
@@ -3,31 +3,39 @@
 # RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+c,+d < %s \
 # RUN: | llvm-objdump --mattr=+c,+d -M no-aliases -d -r - \
 # RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zcd,+d -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zcd,+d < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zcd,+d -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
 #
 # RUN: not llvm-mc -triple riscv32 -mattr=+c \
 # RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
 # RUN: | FileCheck -check-prefixes=CHECK-NO-EXT-D %s
+# RUN: not llv

[PATCH] D134176: Add MC support of RISCV Zcf Extension

2022-09-25 Thread Xinlong Wu via Phabricator via cfe-commits
VincentWu updated this revision to Diff 462720.
VincentWu marked 2 inline comments as done.
VincentWu added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134176

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoC.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/MC/RISCV/rv32fc-valid.s

Index: llvm/test/MC/RISCV/rv32fc-valid.s
===
--- llvm/test/MC/RISCV/rv32fc-valid.s
+++ llvm/test/MC/RISCV/rv32fc-valid.s
@@ -3,41 +3,52 @@
 # RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+c,+f < %s \
 # RUN: | llvm-objdump --mattr=+c,+f -M no-aliases -d -r - \
 # RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zcf,+f -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zcf,+f < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zcf,+f -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
 #
 # RUN: not llvm-mc -triple riscv32 -mattr=+c \
 # RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
 # RUN: | FileCheck -check-prefixes=CHECK-NO-EXT-F %s
+# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-zcf \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT-F %s
 # RUN: not llvm-mc -triple riscv32 \
 # RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
 # RUN: | FileCheck -check-prefixes=CHECK-NO-EXT-FC %s
 # RUN: not llvm-mc -triple riscv64 -mattr=+c,+f \
 # RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
 # RUN: | FileCheck -check-prefixes=CHECK-NO-RV32 %s
+# RUN: not llvm-mc -triple riscv64 -mattr=+experimental-zcf,+f \
+# RUN: -riscv-no-aliases -show-encoding < %s 2>&1 \
+# RUN: | FileCheck -check-prefixes=CHECK-NO-RV32 %s
 
 # FIXME: error messages for rv64fc are misleading
 
 # CHECK-ASM-AND-OBJ: c.flwsp  fs0, 252(sp)
 # CHECK-ASM: encoding: [0x7e,0x74]
 # CHECK-NO-EXT-F:  error: instruction requires the following: 'F' (Single-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-FC:  error: instruction requires the following: 'C' (Compressed Instructions), 'F' (Single-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-FC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcf' (Compressed Single-Precision Floating-Point Instructions), 'F' (Single-Precision Floating-Point){{$}}
 # CHECK-NO-RV32:  error: instruction requires the following: RV32I Base Instruction Set{{$}}
 c.flwsp  fs0, 252(sp)
 # CHECK-ASM-AND-OBJ: c.fswsp  fa7, 252(sp)
 # CHECK-ASM: encoding: [0xc6,0xff]
 # CHECK-NO-EXT-F:  error: instruction requires the following: 'F' (Single-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-FC:  error: instruction requires the following: 'C' (Compressed Instructions), 'F' (Single-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-FC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcf' (Compressed Single-Precision Floating-Point Instructions), 'F' (Single-Precision Floating-Point){{$}}
 # CHECK-NO-RV32:  error: instruction requires the following: RV32I Base Instruction Set{{$}}
 c.fswsp  fa7, 252(sp)
 
 # CHECK-ASM-AND-OBJ: c.flw  fa3, 124(a5)
 # CHECK-ASM: encoding: [0xf4,0x7f]
 # CHECK-NO-EXT-F:  error: instruction requires the following: 'F' (Single-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-FC:  error: instruction requires the following: 'C' (Compressed Instructions), 'F' (Single-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-FC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcf' (Compressed Single-Precision Floating-Point Instructions), 'F' (Single-Precision Floating-Point){{$}}
 # CHECK-NO-RV32:  error: instruction requires the following: RV32I Base Instruction Set{{$}}
 c.flw  fa3, 124(a5)
 # CHECK-ASM-AND-OBJ: c.fsw  fa2, 124(a1)
 # CHECK-ASM: encoding: [0xf0,0xfd]
 # CHECK-NO-EXT-F:  error: instruction requires the following: 'F' (Single-Precision Floating-Point){{$}}
-# CHECK-NO-EXT-FC:  error: instruction requires the following: 'C' (Compressed Instructions), 'F' (Single-Precision Floating-Point){{$}}
+# CHECK-NO-EXT-FC:  error: instruction requires the following: 'C' (Compressed Instructions) or 'Zcf' (Compressed Single-Precision Floating-Point Instructions), 'F' (Single-Precision Floating-Point){{$}}
 # CHECK-NO-RV32:  error: instruction requires the following: RV32I Base Instruction Set{{$}}
 c.fsw  fa2, 124(a1)
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -62,6 +62,

[clang] dcc756d - [AMDGPU] Pattern for flat atomic fadd f64 intrinsic with local addr

2022-09-25 Thread Petar Avramovic via cfe-commits

Author: Petar Avramovic
Date: 2022-09-25T13:25:41+02:00
New Revision: dcc756d03e597d6a405493a630f66ce4fcb7d656

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

LOG: [AMDGPU] Pattern for flat atomic fadd f64 intrinsic with local addr

Fix regression from clang opencl test in builtins-fp-atomics-gfx90a.cl
test_flat_add_local_f64 caused by D130579
Revert a3becb333d7faae695e18728e9b8fa3a3579a240.

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

Added: 


Modified: 
clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
llvm/lib/Target/AMDGPU/DSInstructions.td
llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl 
b/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
index 467745948215d..f078f4e93bb3d 100644
--- a/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
+++ b/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -no-opaque-pointers -O0 -cl-std=CL2.0 -triple 
amdgcn-amd-amdhsa -target-cpu gfx90a \
 // RUN:   %s -S -emit-llvm -o - | FileCheck %s -check-prefix=CHECK
 
+// RUN: %clang_cc1 -no-opaque-pointers -O0 -cl-std=CL2.0 -triple 
amdgcn-amd-amdhsa -target-cpu gfx90a \
+// RUN:   -S -o - %s | FileCheck -check-prefix=GFX90A %s
+
 // REQUIRES: amdgpu-registered-target
 
 typedef half __attribute__((ext_vector_type(2))) half2;

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td 
b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
index 047583077687d..52551c80526b8 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
@@ -580,6 +580,22 @@ multiclass flat_addr_space_atomic_op {
 }
 }
 
+multiclass local_addr_space_atomic_op {
+  def "_noret_local_addrspace" :
+PatFrag<(ops node:$ptr, node:$data),
+(!cast(NAME) node:$ptr, node:$data)>{
+  let HasNoUse = true;
+  let AddressSpaces = LoadAddress_local.AddrSpaces;
+  let IsAtomic = 1;
+}
+def "_local_addrspace" :
+PatFrag<(ops node:$ptr, node:$data),
+(!cast(NAME) node:$ptr, node:$data)>{
+  let AddressSpaces = LoadAddress_local.AddrSpaces;
+  let IsAtomic = 1;
+}
+}
+
 defm int_amdgcn_flat_atomic_fadd : flat_addr_space_atomic_op;
 defm int_amdgcn_flat_atomic_fadd_v2bf16 : noret_op;
 defm int_amdgcn_flat_atomic_fmin : noret_op;
@@ -589,6 +605,7 @@ defm int_amdgcn_flat_atomic_fadd : 
global_addr_space_atomic_op;
 defm int_amdgcn_global_atomic_fadd_v2bf16 : noret_op;
 defm int_amdgcn_global_atomic_fmin : noret_op;
 defm int_amdgcn_global_atomic_fmax : noret_op;
+defm int_amdgcn_flat_atomic_fadd : local_addr_space_atomic_op;
 defm int_amdgcn_ds_fadd_v2bf16 : noret_op;
 
 multiclass noret_binary_atomic_op {

diff  --git a/llvm/lib/Target/AMDGPU/DSInstructions.td 
b/llvm/lib/Target/AMDGPU/DSInstructions.td
index 292e85f9b11a5..9ff9c8ab110b7 100644
--- a/llvm/lib/Target/AMDGPU/DSInstructions.td
+++ b/llvm/lib/Target/AMDGPU/DSInstructions.td
@@ -1121,6 +1121,16 @@ let SubtargetPredicate = isGFX90APlus in {
 def : DSAtomicRetPat;
 let AddedComplexity = 1 in
 def : DSAtomicRetPat;
+
+class DSAtomicRetPatIntrinsic : GCNPat <
+  (vt (frag (DS1Addr1Offset i32:$ptr, i16:$offset), vt:$value)),
+  (inst $ptr, getVregSrcForVT.ret:$value, offset:$offset, (i1 gds))> {
+}
+
+def : DSAtomicRetPatIntrinsic;
+let AddedComplexity = 1 in
+def : DSAtomicRetPatIntrinsic;
 }
 
 let SubtargetPredicate = isGFX940Plus in {

diff  --git a/llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll 
b/llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
index 5dd73ebedf969..f5104eba35ec2 100644
--- a/llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
+++ b/llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
@@ -12,6 +12,7 @@ declare double 
@llvm.amdgcn.global.atomic.fadd.f64.p1f64.f64(double addrspace(1)
 declare double @llvm.amdgcn.global.atomic.fmin.f64.p1f64.f64(double 
addrspace(1)* %ptr, double %data)
 declare double @llvm.amdgcn.global.atomic.fmax.f64.p1f64.f64(double 
addrspace(1)* %ptr, double %data)
 declare double @llvm.amdgcn.flat.atomic.fadd.f64.p0f64.f64(double* %ptr, 
double %data)
+declare double @llvm.amdgcn.flat.atomic.fadd.f64.p3f64.f64(double 
addrspace(3)* %ptr, double %data)
 declare double @llvm.amdgcn.flat.atomic.fmin.f64.p0f64.f64(double* %ptr, 
double %data)
 declare double @llvm.amdgcn.flat.atomic.fmax.f64.p0f64.f64(double* %ptr, 
double %data)
 declare double @llvm.amdgcn.ds.fadd.f64(double addrspace(3)* nocapture, 
double, i32, i32, i1)
@@ -952,6 +953,35 @@ main_body:
   ret double %ret
 }
 
+define amdgpu_kernel void 
@local_atomic_fadd_f64_noret_from_flat_intrinsic(double addrspace(3)* %ptr, 
double %data) {
+; GFX90A-LABEL: local_atomic_fadd_f64

[PATCH] D134568: [AMDGPU] Add pattern for flat fadd f64 intrinsic with local address

2022-09-25 Thread Petar Avramovic via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdcc756d03e59: [AMDGPU] Pattern for flat atomic fadd f64 
intrinsic with local addr (authored by Petar.Avramovic).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D134568?vs=462593&id=462719#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134568

Files:
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
  llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
  llvm/lib/Target/AMDGPU/DSInstructions.td
  llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll

Index: llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
===
--- llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
+++ llvm/test/CodeGen/AMDGPU/fp64-atomics-gfx90a.ll
@@ -12,6 +12,7 @@
 declare double @llvm.amdgcn.global.atomic.fmin.f64.p1f64.f64(double addrspace(1)* %ptr, double %data)
 declare double @llvm.amdgcn.global.atomic.fmax.f64.p1f64.f64(double addrspace(1)* %ptr, double %data)
 declare double @llvm.amdgcn.flat.atomic.fadd.f64.p0f64.f64(double* %ptr, double %data)
+declare double @llvm.amdgcn.flat.atomic.fadd.f64.p3f64.f64(double addrspace(3)* %ptr, double %data)
 declare double @llvm.amdgcn.flat.atomic.fmin.f64.p0f64.f64(double* %ptr, double %data)
 declare double @llvm.amdgcn.flat.atomic.fmax.f64.p0f64.f64(double* %ptr, double %data)
 declare double @llvm.amdgcn.ds.fadd.f64(double addrspace(3)* nocapture, double, i32, i32, i1)
@@ -952,6 +953,35 @@
   ret double %ret
 }
 
+define amdgpu_kernel void @local_atomic_fadd_f64_noret_from_flat_intrinsic(double addrspace(3)* %ptr, double %data) {
+; GFX90A-LABEL: local_atomic_fadd_f64_noret_from_flat_intrinsic:
+; GFX90A:   ; %bb.0: ; %main_body
+; GFX90A-NEXT:s_load_dword s4, s[0:1], 0x24
+; GFX90A-NEXT:s_load_dwordx2 s[2:3], s[0:1], 0x2c
+; GFX90A-NEXT:s_waitcnt lgkmcnt(0)
+; GFX90A-NEXT:v_mov_b32_e32 v2, s4
+; GFX90A-NEXT:v_pk_mov_b32 v[0:1], s[2:3], s[2:3] op_sel:[0,1]
+; GFX90A-NEXT:ds_add_f64 v2, v[0:1]
+; GFX90A-NEXT:s_endpgm
+main_body:
+  %ret = call double @llvm.amdgcn.flat.atomic.fadd.f64.p3f64.f64(double addrspace(3)* %ptr, double %data)
+  ret void
+}
+
+define double @local_atomic_fadd_f64_rtn_from_flat_intrinsic(double addrspace(3)* %ptr, double %data) {
+; GFX90A-LABEL: local_atomic_fadd_f64_rtn_from_flat_intrinsic:
+; GFX90A:   ; %bb.0: ; %main_body
+; GFX90A-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX90A-NEXT:v_mov_b32_e32 v3, v2
+; GFX90A-NEXT:v_mov_b32_e32 v2, v1
+; GFX90A-NEXT:ds_add_rtn_f64 v[0:1], v0, v[2:3]
+; GFX90A-NEXT:s_waitcnt lgkmcnt(0)
+; GFX90A-NEXT:s_setpc_b64 s[30:31]
+main_body:
+  %ret = call double @llvm.amdgcn.flat.atomic.fadd.f64.p3f64.f64(double addrspace(3)* %ptr, double %data)
+  ret double %ret
+}
+
 define amdgpu_kernel void @local_atomic_fadd_f64_noret_pat(double addrspace(3)* %ptr) #1 {
 ; GFX90A-LABEL: local_atomic_fadd_f64_noret_pat:
 ; GFX90A:   ; %bb.0: ; %main_body
@@ -994,7 +1024,7 @@
 ; GFX90A-NEXT:s_waitcnt lgkmcnt(0)
 ; GFX90A-NEXT:v_mov_b32_e32 v0, s2
 ; GFX90A-NEXT:ds_read_b64 v[0:1], v0
-; GFX90A-NEXT:  .LBB52_1: ; %atomicrmw.start
+; GFX90A-NEXT:  .LBB54_1: ; %atomicrmw.start
 ; GFX90A-NEXT:; =>This Inner Loop Header: Depth=1
 ; GFX90A-NEXT:s_waitcnt lgkmcnt(0)
 ; GFX90A-NEXT:v_add_f64 v[2:3], v[0:1], 4.0
@@ -1006,7 +1036,7 @@
 ; GFX90A-NEXT:s_or_b64 s[0:1], vcc, s[0:1]
 ; GFX90A-NEXT:v_pk_mov_b32 v[0:1], v[2:3], v[2:3] op_sel:[0,1]
 ; GFX90A-NEXT:s_andn2_b64 exec, exec, s[0:1]
-; GFX90A-NEXT:s_cbranch_execnz .LBB52_1
+; GFX90A-NEXT:s_cbranch_execnz .LBB54_1
 ; GFX90A-NEXT:  ; %bb.2: ; %atomicrmw.end
 ; GFX90A-NEXT:s_endpgm
 main_body:
Index: llvm/lib/Target/AMDGPU/DSInstructions.td
===
--- llvm/lib/Target/AMDGPU/DSInstructions.td
+++ llvm/lib/Target/AMDGPU/DSInstructions.td
@@ -1121,6 +1121,16 @@
 def : DSAtomicRetPat;
 let AddedComplexity = 1 in
 def : DSAtomicRetPat;
+
+class DSAtomicRetPatIntrinsic : GCNPat <
+  (vt (frag (DS1Addr1Offset i32:$ptr, i16:$offset), vt:$value)),
+  (inst $ptr, getVregSrcForVT.ret:$value, offset:$offset, (i1 gds))> {
+}
+
+def : DSAtomicRetPatIntrinsic;
+let AddedComplexity = 1 in
+def : DSAtomicRetPatIntrinsic;
 }
 
 let SubtargetPredicate = isGFX940Plus in {
Index: llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
===
--- llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
+++ llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
@@ -580,6 +580,22 @@
 }
 }
 
+multiclass local_addr_space_atomic_op {
+  def "_noret_local_addrspace" :
+PatFrag<(ops node:$ptr, node:$data),
+(!cast(NAME) node:$ptr, node:$data)>{
+  

[PATCH] D133648: Clang, increase upper bound of partially initialized array sizes

2022-09-25 Thread Ofek Shochat via Phabricator via cfe-commits
OfekShochat marked an inline comment as done.
OfekShochat added a comment.

@efriedma would you be able to commit this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133648

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


[PATCH] D134269: [docs] Document the one-phase style compilation to c++ standard modules

2022-09-25 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

Thanks for doing this! The traditional Clang Header modules call this implicit 
and explicit modules.

Feel free to ignore, but I found this awesome article about implicit and 
explicit modules in Swift. They have same nomenclature and issues.

https://forums.swift.org/t/explicit-module-builds-the-new-swift-driver-and-swiftpm/36990


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

https://reviews.llvm.org/D134269

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


[PATCH] D134597: [CMake] install clang resource headers into `CLANG_RESOURCE_DIR/include` if `CLANG_RESOURCE_DIR` is not empty

2022-09-25 Thread LJC via Phabricator via cfe-commits
paperchalice created this revision.
paperchalice added a reviewer: phosek.
paperchalice added a project: clang.
Herald added a project: All.
paperchalice requested review of this revision.
Herald added a subscriber: cfe-commits.

When `CLANG_RESOURCE_DIR` is not empty, clang will look up builtin headers in 
`CLANG_RESOURCE_DIR/include`, this patch makes sure resource headers are 
installed into the correct location.
Resolve issue #57708.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134597

Files:
  clang/lib/Headers/CMakeLists.txt


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -421,6 +421,9 @@
 add_header_target("utility-resource-headers" ${utility_files})
 
 set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include)
+if(NOT CLANG_RESOURCE_DIR STREQUAL "")
+  set(header_install_dir ${CMAKE_INSTALL_BINDIR}/${CLANG_RESOURCE_DIR}/include)
+endif()
 
 #
 # Install rules for the catch-all clang-resource-headers target


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -421,6 +421,9 @@
 add_header_target("utility-resource-headers" ${utility_files})
 
 set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include)
+if(NOT CLANG_RESOURCE_DIR STREQUAL "")
+  set(header_install_dir ${CMAKE_INSTALL_BINDIR}/${CLANG_RESOURCE_DIR}/include)
+endif()
 
 #
 # Install rules for the catch-all clang-resource-headers target
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133757: [clangd] Turn QueryDriverDatabase into a CompileCommandsAdjuster

2022-09-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 462704.
nridge marked 2 inline comments as done.
nridge added a comment.

This is mostly just a rebase on top of the update to D133756 
 to turn
CompileCommandsAdjuster into a unique_function, and addressing a few
minor comments.

I still need to re-formulate the test to use lit tests, I will work
on that next.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133757

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/QueryDriverDatabase.cpp
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp

Index: clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -71,6 +71,7 @@
   MockFS FS;
   ClangdLSPServer::Options Opts;
   FeatureModuleSet FeatureModules;
+  llvm::Optional Server;
 
 private:
   class Logger : public clang::clangd::Logger {
@@ -97,7 +98,6 @@
 
   Logger L;
   LoggingSession LogSession;
-  llvm::Optional Server;
   llvm::Optional ServerThread;
   LSPClient Client;
 };
@@ -229,6 +229,33 @@
   diagMessage("Use of undeclared identifier 'BAR'";
 }
 
+// Tests that clangd can run --query-driver on a compiler specified
+// via the Compiler key in the config file.
+TEST_F(LSPTest, QueryCompilerFromConfig) {
+  auto CfgProvider =
+  config::Provider::fromAncestorRelativeYAMLFiles(".clangd", FS);
+  Opts.ConfigProvider = CfgProvider.get();
+  Opts.QueryDriverGlobs = {"/**/*"};
+
+  FS.Files[".clangd"] = R"yaml(
+CompileFlags:
+  Compiler: gcc
+  )yaml";
+  // Just to ensure there's a CDB entry
+  FS.Files["compile_flags.txt"] = "-DSOME_FLAG";
+
+  auto &Client = start();
+  Client.sync(); // wait for onInitialize() to run
+
+  auto CompileCommand = Server->getCompileCommand(testPath("foo.cpp"));
+  ASSERT_TRUE(bool(CompileCommand));
+  EXPECT_GE(llvm::count_if(CompileCommand->CommandLine,
+   [](const std::string &Arg) {
+ return StringRef(Arg).contains("isystem");
+   }),
+1);
+}
+
 TEST_F(LSPTest, ModulesTest) {
   class MathModule final : public FeatureModule {
 OutgoingNotification Changed;
Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -100,9 +100,9 @@
 Config::current().CompileFlags.CDBSearch.FixedCDBPath;
 std::unique_ptr BaseCDB =
 std::make_unique(CDBOpts);
-BaseCDB = getQueryDriverDatabase(llvm::makeArrayRef(Opts.QueryDriverGlobs),
- std::move(BaseCDB));
 auto Mangler = CommandMangler::detect();
+Mangler.SystemIncludeExtractor =
+getSystemIncludeExtractor(llvm::makeArrayRef(Opts.QueryDriverGlobs));
 if (Opts.ResourceDir)
   Mangler.ResourceDir = *Opts.ResourceDir;
 auto CDB = std::make_unique(
Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -315,24 +315,20 @@
 /// Extracts system includes from a trusted driver by parsing the output of
 /// include search path and appends them to the commands coming from underlying
 /// compilation database.
-class QueryDriverDatabase : public DelegatingCDB {
+class SystemIncludeExtractor {
 public:
-  QueryDriverDatabase(llvm::ArrayRef QueryDriverGlobs,
-  std::unique_ptr Base)
-  : DelegatingCDB(std::move(Base)),
-QueryDriverRegex(convertGlobsToRegex(QueryDriverGlobs)) {}
+  SystemIncludeExtractor(llvm::ArrayRef QueryDriverGlobs)
+  : QueryDriverRegex(convertGlobsToRegex(QueryDriverGlobs)) {}
 
-  llvm::Optional
-  getCompileCommand(PathRef File) const override {
-auto Cmd = DelegatingCDB::getCompileCommand(File);
-if (!Cmd || Cmd->CommandLine.empty())
-  return Cmd;
+  void operator()(tooling::CompileCommand &Cmd, llvm::StringRef File) const {
+if (Cmd.CommandLine.empty())
+  return;
 
 llvm::StringRef Lang;
-for (size_t I = 0, E = Cmd->CommandLine.size(); I < E; ++I) {
-  llvm::StringRef Arg = Cmd->CommandLine[I];
+for (size_t I = 0, E = Cmd.CommandLine.size(); I < E; ++I) {
+  llvm::StringRef Arg = Cmd.CommandLine[I];
   if (Arg == "-x" && I + 1 < E)
-Lang = Cmd->CommandLine[I + 1];
+Lang = Cmd.CommandLi

[PATCH] D133756: [clangd] Introduce CompileCommandsAdjuster

2022-09-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 462702.
nridge added a comment.

Updated to use unique_function rather than inheritance


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133756

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/indexer/IndexerMain.cpp
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp

Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -59,7 +59,7 @@
   Argv.push_back(FullFilename);
 
   auto Mangler = CommandMangler::forTests();
-  Mangler.adjust(Inputs.CompileCommand.CommandLine, FullFilename);
+  Mangler(Inputs.CompileCommand, FullFilename);
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.Directory = testRoot();
   Inputs.Contents = Code;
Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
===
--- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -138,11 +138,9 @@
 
 TEST_F(OverlayCDBTest, Adjustments) {
   OverlayCDB CDB(Base.get(), {"-DFallback"},
- [](const std::vector &Cmd, llvm::StringRef File) {
-   auto Ret = Cmd;
-   Ret.push_back(
+ [](tooling::CompileCommand &Cmd, llvm::StringRef File) {
+   Cmd.CommandLine.push_back(
("-DAdjust_" + llvm::sys::path::filename(File)).str());
-   return Ret;
  });
   // Command from underlying gets adjusted.
   auto Cmd = *CDB.getCompileCommand(testPath("foo.cc"));
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -45,41 +45,47 @@
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "--", "foo.cc", "bar.cc"};
-  Mangler.adjust(Cmd, "foo.cc");
-  EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
-   "-resource-dir=" + testPath("fake/resources"),
-   "-isysroot", testPath("fake/sysroot"), "--",
-   "foo.cc"));
+  tooling::CompileCommand Cmd;
+  Cmd.CommandLine = {"clang++", "--", "foo.cc", "bar.cc"};
+  Mangler(Cmd, "foo.cc");
+  EXPECT_THAT(Cmd.CommandLine,
+  ElementsAre(testPath("fake/clang++"),
+  "-resource-dir=" + testPath("fake/resources"),
+  "-isysroot", testPath("fake/sysroot"), "--",
+  "foo.cc"));
 }
 
 TEST(CommandMangler, FilenameMismatch) {
   auto Mangler = CommandMangler::forTests();
   Mangler.ClangPath = testPath("clang");
   // Our compile flags refer to foo.cc...
-  std::vector Cmd = {"clang", "foo.cc"};
+  tooling::CompileCommand Cmd;
+  Cmd.CommandLine = {"clang", "foo.cc"};
   // but we're applying it to foo.h...
-  Mangler.adjust(Cmd, "foo.h");
+  Mangler(Cmd, "foo.h");
   // so transferCompileCommand should add -x c++-header to preserve semantics.
-  EXPECT_THAT(
-  Cmd, ElementsAre(testPath("clang"), "-x", "c++-header", "--", "foo.h"));
+  EXPECT_THAT(Cmd.CommandLine, ElementsAre(testPath("clang"), "-x",
+   "c++-header", "--", "foo.h"));
 }
 
 TEST(CommandMangler, ResourceDir) {
   auto Mangler = CommandMangler::forTests();
   Mangler.ResourceDir = testPath("fake/resources");
-  std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd, "foo.cc");
-  EXPECT_THAT(Cmd, Contains("-resource-dir=" + testPath("fake/resources")));
+  tooling::CompileCommand Cmd;
+  Cmd.CommandLine = {"clang++", "foo.cc"};
+  Mangler(Cmd, "foo.cc");
+  EXPECT_THAT(Cmd.CommandLine,
+  Contains("-resource-dir=" + testPath("fake/resources")));
 }
 
 TEST(CommandMangler, Sysroot) {
   auto Mangler = CommandMangler::forTests();
   Mangler.Sysroot = testPath("fake/sysroot");
 
-  std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd, "foo.cc");
-  EXPECT_THAT(llvm:

[PATCH] D133756: [clangd] Introduce CompileCommandsAdjuster

2022-09-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/GlobalCompilationDatabase.h:165
+// process a file (possibly different from the one in the command).
+class CompileCommandsAdjuster {
+public:

nridge wrote:
> sammccall wrote:
> > I have a couple of concerns with this interface:
> >  - we seem to be stretching to cover {mangler, querydriver} with one 
> > interface, but there's no particular reason to - we never use it 
> > polymorphically.
> >  - the contract is very vague. If it's just "mutate flags" then some sort 
> > of generic `function` seems sufficient
> >  - `File` feels out-of-place - it's purely an input for the mangler. If 
> > query-driver needs an extra input, will we add that too?
> >  - either `CompileCommand` or filename+argv seems reasonable, providing 
> > CompileCommand+argv is confusing. 
> >  - the name is hard to distinguish from tooling::ArgumentsAdjuster (which 
> > is a bad interface)
> > 
> > The immediate problem being solved is the type of 
> > CommandMangler::SystemIncludeExtractor, right?
> > Can that just be `unique_function&, StringRef)>` or so? 
> > Possibly behind `using SystemIncludeExtractor = ...`.
> It's more that `QueryDriverDatabase` 
> [uses](https://searchfox.org/llvm/rev/f213128b292da85f68eeebbb68cba1541e1c39e2/clang-tools-extra/clangd/QueryDriverDatabase.cpp#354)
>  the `Directory` field of `tooling::CompileCommand` in addition to the 
> arguments.
> 
> We could add the directory as another argument to the function, but at that 
> point why not group the arguments into `tooling::CompileCommand` which is 
> more semantically meaningful?
> 
> As for polymorphism vs. `unique_function`, I don't feel strongly about that, 
> happy to change that up. (I do find `function` more annoying to debug because 
> `step into` at a call site in the debugger steps into some hard-to-read 
> library code, but that's probably better solved at the debugger tooling 
> level.)
Forgot to mention one other subtlety here: because `QueryDriverDatabase` needs 
to operate on a `tooling::CompileCommand`, the interface between 
`CommandMangler` and `OverlayCDB` needs to be widened to accommodate passing a 
`tooling::CompileCommand`, i.e. it can't be `ArgumentsAdjuster` any more.

This is why I reused `CompileCommandsAdjuster` as the type used to pass 
`CommandMangler` to `OverlayCDB`, and the type used to pass 
`SystemIncludeExtractor` to `CommandMangler`. It's not used 
//polymorphically//, we just need an interface that can accept a 
`CompileCommand` in both places; they could be two different types if we prefer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133756

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


[PATCH] D134269: [docs] Document the one-phase style compilation to c++ standard modules

2022-09-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 462701.
ChuanqiXu added a comment.

Refine the behavior about partitions.


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

https://reviews.llvm.org/D134269

Files:
  clang/docs/StandardCPlusPlusModules.rst

Index: clang/docs/StandardCPlusPlusModules.rst
===
--- clang/docs/StandardCPlusPlusModules.rst
+++ clang/docs/StandardCPlusPlusModules.rst
@@ -142,8 +142,7 @@
 
 .. code-block:: console
 
-  $ clang++ -std=c++20 Hello.cppm --precompile -o Hello.pcm
-  $ clang++ -std=c++20 use.cpp -fprebuilt-module-path=. Hello.pcm -o Hello.out
+  $ clang++ -std=c++20 Hello.cppm use.cpp -o Hello.out
   $ ./Hello.out
   Hello World!
 
@@ -223,7 +222,22 @@
 How to produce a BMI
 
 
-It is possible to generate a BMI for an importable module unit by specifying the ``--precompile`` option.
+It is possible to generate a BMI explicitly for an importable
+module unit by specifying the ``--precompile`` option.
+
+Also if when we compile an importable module unit to an object file,
+the compiler will generate the corresponding BMI implicitly in the module cache path.
+See :ref:`Module Cache Path`.
+
+The file name for the implicitly generated BMI will be:
+
+* (1) If the module name is specified by `-fmodule-name={module-name}` option,
+  the file name of the BMI will be `{module-name}.pcm` or `{primary-module-name}-{partition-name}.pcm`
+  if the `module-name` specifies a partition name.
+* (2) If `-fmodule-name` is not specified, the file name of the BMI will be
+  the same with the name with source file except with the different suffix `.pcm`.
+  For example, if the source file is `M.cppm`, then the name of the implicitly
+  generated BMI in this manner will be `M.pcm`.
 
 File name requirement
 ~
@@ -309,6 +323,27 @@
 ``-fprebuilt-module-path`` is more convenient and ``-fmodule-file`` is faster since
 it saves time for file lookup.
 
+Module Cache Path
+~
+
+When we compile an importable module unit to an object file directly, the BMI
+will be generated in the module cache path.
+Users can specifiy the module cache path by ``-fmodules-cache-path=/path/`` option.
+If the module cache path is not specified explicitly, the compiler will choose
+the default module cache path.
+
+If we set the environment variable ``CLANG_MODULE_CACHE_PATH``, its value will
+be the default module cache path.
+Otherwise, the default module path is system specified. In Unix systems, its value
+will be ``~/.cache/clang/ModuleCache/``.
+
+If the directory specified by module cache path doesn't exist,
+the compiler will try to create the directory.
+The compiler will emit an error if it fails to create the directory.
+
+The module cache path will be passed to ``-fprebuilt-module-path`` so that
+the translation unit are able to lookup these implicitly generated BMI implicitly.
+
 Remember that module units still have an object counterpart to the BMI
 ~~
 
@@ -874,3 +909,52 @@
 this means the build speedup at higher optimization levels may be lower than expected given ``O0`` experience, 
 but does provide by more optimization opportunities.
 
+Why two-phase compilation?
+--
+
+The readers may notice that the document generates the BMI explicitly.
+We call this manner as two-phase compilation
+(sources to BMIs and BMIs to object files) to disambiguate the traditional
+compilation process (sources to object files directly),
+which we call one-phase compilation.
+
+The two-phase compilation will have higher parallelism than the one-phase compilation.
+Image the following example:
+
+.. code-block:: c++
+
+  // A.cppm
+  export module A;
+  // ...
+
+  // B.cppm
+  export module B;
+  import A;
+
+  // C.cpp
+  import B;
+
+In this example, `C.cpp` depends on Module B and `B.cppm` depends on Module A.
+So the compilation process in one-phase style will be:
+
+.. code-block:: text
+
+  A.cppm --- A.pcm ---> A.o ->
+   B.cppm --- B.pcm ---> B.o ->
+C.cppm --- C.pcm ---> C.o
+
+But if it is compiled by the two-phase compilation, the process will be:
+
+.. code-block:: text
+
+  A.cppm --- A.pcm ---> A.o
+   B.cppm --- B.pcm ---> B.o
+C.cppm --- C.pcm ---> C.o
+
+From the example, we can find the two-phase compilation can bring more parallelism and
+the higher compilation speed.
+Especially, the middle end and the backend usually take much much more time than the frontend.
+So the gap will be larger in larger projects.
+
+So we highly recommend to use two-phase compilation in real workloads
+while the one-phase compilation model are more suitable for quick POC and demo examples.
___
cfe-commits mailing list
cfe-comm

[PATCH] D134267: [C++] [Modules] Support one phase compilation model for named modules

2022-09-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 462700.
ChuanqiXu added a comment.

- Add ReleaseNotes.
- Refine the behavior about partitions.


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

https://reviews.llvm.org/D134267

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/create_module_cache.cpp
  clang/test/Modules/one-phase-compilation-named-modules.cppm

Index: clang/test/Modules/one-phase-compilation-named-modules.cppm
===
--- /dev/null
+++ clang/test/Modules/one-phase-compilation-named-modules.cppm
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/M.cppm -c -o - -fmodules-cache-path=%t/pcm.cache
+// RUN: %clang -std=c++20 %t/Use.cpp -fsyntax-only  -fprebuilt-module-path=%t/pcm.cache -Xclang -verify
+//
+// RUN: rm -f %t/M.pcm
+// Tests that the Sema will detect the incorrect module name.
+// RUN: %clang -std=c++20 %t/MismatchedName.cppm -o - -fmodules-cache-path=%t/pcm.cache \
+// RUN: -fmodule-name=WRONG_MODULE_NAME -fsyntax-only -Xclang -verify
+//
+// RUN: %clang -std=c++20 %t/MismatchedName.cppm -c -o - -fmodules-cache-path=%t/pcm.cache -fmodule-name=M
+// RUN: %clang -std=c++20 %t/Use.cpp -fsyntax-only  -fprebuilt-module-path=%t/pcm.cache -Xclang -verify
+
+//--- M.cppm
+export module M;
+export int getValue();
+
+//--- MismatchedName.cppm
+export module M;   // expected-error {{module name 'WRONG_MODULE_NAME' specified on command line does not match name of module}}
+export int getValue(); // expected-error {{export declaration can only be used within a module interface unit after the module declaration}}
+
+//--- Use.cpp
+// expected-no-diagnostics
+import M;
+int Use() {
+return getValue();
+}
Index: clang/test/Driver/create_module_cache.cpp
===
--- /dev/null
+++ clang/test/Driver/create_module_cache.cpp
@@ -0,0 +1,28 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: not %clang -std=c++20 %t/M.cppm -fmodules-cache-path= -c -o %t/M.tmp.o 2>&1 | FileCheck %t/M.cppm --check-prefix=ERROR
+// RUN: %clang -std=c++20 %t/M.cppm -fmodules-cache-path=%t/abc -c -o -
+// RUN: ls %t | FileCheck %t/M.cppm --check-prefix=CHECK-AVAILABLE
+//
+// RUN: %clang -std=c++20 %t/Use.cpp -fmodules-cache-path=abc -### 2>&1 | FileCheck %t/Use.cpp
+//
+// Check that the compiler will generate M-Part.pcm correctly.
+// RUN: %clang -std=c++20 %t/Part.cppm -fmodules-cache-path=%t/abc -fmodule-name=M:Part -c -o -
+// RUN: ls %t/abc | FileCheck %t/Part.cppm --check-prefix=CHECK-AVAILABLE
+
+//--- M.cppm
+export module M;
+
+// ERROR: unable to create default module cache path "": No such file or directory
+// CHECK-AVAILABLE: abc
+
+//--- Use.cpp
+import M;
+
+// CHECK: -fprebuilt-module-path=abc
+
+//--- Part.cppm
+export module M:Part;
+// CHECK-AVAILABLE: M-Part.pcm
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3658,6 +3658,7 @@
  const ArgList &Args, const InputInfo &Input,
  const InputInfo &Output,
  ArgStringList &CmdArgs, bool &HaveModules) {
+  bool HasCXXModules = HaveModules;
   // -fmodules enables the use of precompiled modules (off by default).
   // Users can pass -fno-cxx-modules to turn off modules support for
   // C++/Objective-C++ programs.
@@ -3699,33 +3700,34 @@
 options::OPT_fno_implicit_modules, HaveClangModules)) {
 if (HaveModules)
   CmdArgs.push_back("-fno-implicit-modules");
-  } else if (HaveModules) {
+  } else if (HaveModules)
 ImplicitModules = true;
-// -fmodule-cache-path specifies where our implicitly-built module files
-// should be written.
-SmallString<128> Path;
-if (Arg *A = Args.getLastArg(options::OPT_fmodules_cache_path))
-  Path = A->getValue();
 
-bool HasPath = true;
-if (C.isForDiagnostics()) {
-  // When generating crash reports, we want to emit the modules along with
-  // the reproduction sources, so we ignore any provided module path.
-  Path = Output.getFilename();
-  llvm::sys::path::replace_extension(Path, ".cache");
-  llvm::sys::path::append(Path, "modules");
-} else if (Path.empty()) {
-  // No module path was provided: use the default.
-  HasPath = Driver::getDefaultModuleCachePath(Path);
-}
-
-// `HasPath` will only be false if getDefaultModuleCachePath() fails.
-// That being said, that failure is unlikely and not caching is harmless.
-if (HasPath) {
-  const char Arg[] = "-fmodules-cache-path=";
-  Path.insert(Path.begin(), Arg, Arg