[PATCH] D117647: [RISCV] Add passthru operand for RVV nomask load intrinsics.

2022-01-25 Thread Zakk Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 402776.
khchen added a comment.
Herald added a subscriber: pcwang-thead.

rebase and ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117647

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vloxei.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vluxei.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vle.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vleff.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vloxei.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlse.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vluxei.c
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
  llvm/lib/Target/RISCV/RISCVISelDAGToDAG.h
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
  llvm/test/CodeGen/RISCV/rvv/rv32-vsetvli-intrinsics.ll
  llvm/test/CodeGen/RISCV/rvv/rv64-vsetvli-intrinsics.ll
  llvm/test/CodeGen/RISCV/rvv/rvv-out-arguments.ll
  llvm/test/CodeGen/RISCV/rvv/unmasked-tu.ll
  llvm/test/CodeGen/RISCV/rvv/vle-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vle-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vleff-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vleff-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vloxei-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vloxei-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vlse-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vlse-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vluxei-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vluxei-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
  llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir
  llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.ll
  llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.mir

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


[PATCH] D117416: [clang-format] Handle C variables with name that matches c++ access specifier

2022-01-25 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius requested changes to this revision.
curdeius added a comment.
This revision now requires changes to proceed.

Last nits, apart from this clean up, I'm OK.




Comment at: clang/lib/Format/FormatToken.h:125
+/// Operators that can follow a C variable.
+static const std::set C_OperatorsFollowingVar = {
+tok::l_square, tok::r_square,

HazardyKnusperkeks wrote:
> And maybe choose a different container: 
> https://llvm.org/docs/ProgrammersManual.html#set-like-containers-std-set-smallset-setvector-etc
Not done it seems.
Please rename and use a different type. Maybe `ImmutableSet`? Or just a sorted 
`std::vector`?



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:109
+return true;
+  // Handle Qt signals
+  else if ((RootToken.isOneOf(Keywords.kw_signals, Keywords.kw_qsignals) &&

Nit here and elsewhere: full stop at the end of comments.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:113
+return true;
+  // Handle malformed access specifier i.e. 'private' without trailing ':'
+  else if ((RootToken.isAccessSpecifier(false) &&





Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:116
+(!RootToken.Next ||
+ (!C_OperatorsFollowingVar.count(
+  RootToken.Next->Tok.getKind()) &&

Please use `contains` instead of `count` if using `ImmutableSet`.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2497
 void UnwrappedLineParser::parseAccessSpecifier() {
+  auto *AccessSpecifierCandidate = FormatTok;
   nextToken();





Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2506-2512
+// is not a variable name or namespacename
+  } else if (!C_OperatorsFollowingVar.count(FormatTok->Tok.getKind()) &&
+ !FormatTok->Tok.is(tok::coloncolon))
+addUnwrappedLine();
+  // consider the accessSpecifier to be a C identifier
+  else if (AccessSpecifierCandidate)
+AccessSpecifierCandidate->Tok.setKind(tok::identifier);





Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2507
+// is not a variable name or namespacename
+  } else if (!C_OperatorsFollowingVar.count(FormatTok->Tok.getKind()) &&
+ !FormatTok->Tok.is(tok::coloncolon))

Ditto. Use `contains`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117416

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


[PATCH] D116085: [clang-tidy] Performance improvements for NOLINTBEGIN/END blocks

2022-01-25 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz updated this revision to Diff 402774.
salman-javed-nz added a comment.

`ClangTidyContext::shouldSuppressDiagnostic()`:

- Hook up `AllowIO` and `EnableNoLintBlocks` to 
`NoLintDirectiveHandler::shouldSuppress()`

`NoLintToken`:
-Remove copy ctor and assignment operator. Class is now move-only.

`getNoLints()`:

- Use `llvm::StringLiteral` for string literal
- Break out of the loop once there are no more NOLINT strings
- Determine NOLINT checks string inline instead of in a lamda
- Remove the `NoLintToken()` in the call to `emplace_back()`

`NoLintDirectiveHandler`:

- `std::make_unique` --> `std::make_unique`
- Remove default values for `AllowIO` and `EnableNoLintBlocks` parameters


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116085

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
  clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/1st-translation-unit.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/2nd-translation-unit.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-glob.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-specific.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-all.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-specific.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-global-end-specific.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-all.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-glob.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-global.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-multiple-TUs.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp

Index: clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
@@ -58,30 +58,24 @@
 // NOLINTEND(some-other-check)
 // NOLINTEND(google-explicit-constructor)
 
-// NOLINTBEGIN(google-explicit-constructor)
-// NOLINTBEGIN(some-other-check)
-class C7 { C7(int i); };
-// NOLINTEND(google-explicit-constructor)
-// NOLINTEND(some-other-check)
-
 // NOLINTBEGIN(google-explicit-constructor)
 // NOLINTBEGIN
-class C8 { C8(int i); };
+class C7 { C7(int i); };
 // NOLINTEND
 // NOLINTEND(google-explicit-constructor)
 
 // NOLINTBEGIN
 // NOLINTBEGIN(google-explicit-constructor)
-class C9 { C9(int i); };
+class C8 { C8(int i); };
 // NOLINTEND(google-explicit-constructor)
 // NOLINTEND
 
 // NOLINTBEGIN(not-closed-bracket-is-treated-as-skip-all
-class C10 { C10(int i); };
+class C9 { C9(int i); };
 // NOLINTEND(not-closed-bracket-is-treated-as-skip-all
 
 // NOLINTBEGIN without-brackets-skip-all, another-check
-class C11 { C11(int i); };
+class C10 { C10(int i); };
 // NOLINTEND without-brackets-skip-all, another-check
 
 #define MACRO(X) class X { X(int i); };
@@ -114,28 +108,28 @@
 MACRO_NO_LINT_INSIDE_MACRO
 
 // NOLINTBEGIN(google*)
-class C12 { C12(int i); };
+class C11 { C11(int i); };
 // NOLINTEND(google*)
 
 // NOLINTBEGIN(*explicit-constructor)
-class C15 { C15(int i); };
+class C12 { C12(int i); };
 // NOLINTEND(*explicit-constructor)
 
 // NOLINTBEGIN(*explicit*)
-class C16 { C16(int i); };
+class C13 { C13(int i); };
 // NOLINTEND(*explicit*)
 
 // NOLINTBEGIN(-explicit-constructor)
-class C17 { C17(int x); };
+class C14 { C14(int x); };
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: single-argument constructors must be marked explicit
 // NOLINTEND(-explicit-constructor)
 
 // NOLINTBEGIN(google*,-google*)
-class C18 { C18(int x); };
+class C15 { C15(int x); };
 // NOLINTEND(google*,-google*)
 
 // NOLINTBEGIN(*,-google*)
-class C19 { C19(int x); };

[PATCH] D117994: [Clang] Implement multidimentional subscript operator

2022-01-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 402780.
cor3ntin added a comment.

Address Erich's feedback: A source range was only constructed from the
first element


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117994

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaAccess.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/OpenMP/target_update_messages.cpp
  clang/test/Parser/cxx2b-subscript.cpp
  clang/test/SemaCXX/cxx2b-overloaded-operator.cpp
  clang/test/SemaTemplate/instantiate-subscript.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1353,7 +1353,7 @@
 
   Multidimensional subscript operator
   https://wg21.link/P2128R6";>P2128R6
-  No
+  Clang 14
 
 
   Non-literal variables (and labels and gotos) in constexpr functions
Index: clang/test/SemaTemplate/instantiate-subscript.cpp
===
--- clang/test/SemaTemplate/instantiate-subscript.cpp
+++ clang/test/SemaTemplate/instantiate-subscript.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2b %s
 
 struct Sub0 {
   int &operator[](int);
Index: clang/test/SemaCXX/cxx2b-overloaded-operator.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2b-overloaded-operator.cpp
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -verify -std=c++2b %s
+
+namespace N {
+
+void empty() {
+  struct S {
+int operator[](); // expected-note{{not viable: requires 0 arguments, but 1 was provided}}
+  };
+
+  S{}[];
+  S{}[1]; // expected-error {{no viable overloaded operator[] for type 'S'}}
+}
+
+void default_var() {
+  struct S {
+constexpr int operator[](int i = 42) { return i; } // expected-note {{not viable: allows at most single argument 'i'}}
+  };
+  static_assert(S{}[] == 42);
+  static_assert(S{}[1] == 1);
+  static_assert(S{}[1, 2] == 1); // expected-error {{no viable overloaded operator[] for type 'S'}}
+}
+
+struct Variadic {
+  constexpr int operator[](auto... i) { return (42 + ... + i); }
+};
+
+void variadic() {
+
+  static_assert(Variadic{}[] == 42);
+  static_assert(Variadic{}[1] == 43);
+  static_assert(Variadic{}[1, 2] == 45);
+}
+
+void multiple() {
+  struct S {
+constexpr int operator[]() { return 0; }
+constexpr int operator[](int) { return 1; };
+constexpr int operator[](int, int) { return 2; };
+  };
+  static_assert(S{}[] == 0);
+  static_assert(S{}[1] == 1);
+  static_assert(S{}[1, 1] == 2);
+}
+
+void ambiguous() {
+  struct S {
+constexpr int operator[]() { return 0; } // expected-note{{candidate function}}
+constexpr int operator[](int = 0) { return 1; }; // expected-note{{candidate function}}
+  };
+
+  static_assert(S{}[] == 0); // expected-error{{call to subscript operator of type 'S' is ambiguous}}
+}
+} // namespace N
+
+template 
+struct T1 {
+  constexpr auto operator[](T... arg) { // expected-note {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+return (1 + ... + arg);
+  }
+};
+
+static_assert(T1<>{}[] == 1);
+static_assert(T1{}[1] == 2);
+static_assert(T1{}[1, 1] == 3);
+static_assert(T1{}[1] == 3); // expected-error {{no viable overloaded operator[] for type 'T1'}}
+
+struct T2 {
+  constexpr auto operator[](auto... arg) {
+return (1 + ... + arg);
+  }
+};
+
+static_assert(T2{}[] == 1);
+static_assert(T2{}[1] == 2);
+static_assert(T2{}[1, 1] == 3);
Index: clang/test/Parser/cxx2b-subscript.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx2b-subscript.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx2b -std=c++2b %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
+
+//cxx2b-no-diagnostics
+
+struct S {
+  constexpr int operator[](int i) {
+return i;
+  }
+  constexpr int operator[](int a, int b) { // cxx20-error {{overloaded 'operator[]' cannot have more than one parameter before C++2b}}
+return a + b;
+  }
+  constexpr int operator[]() { // cxx20-error {{overloaded 'operator[]' cannot have no parameter before C++2b}}
+return 42;
+  }
+};
+
+struct Defaults {
+  constexpr int operator[](int i = 0) { // cxx20-error {{overloaded 'operator[]' cannot have a defaulted parameter before C++2b}}
+return 0;
+  }
+  constexpr int operator[](int a, int b, int c = 0) { // c

[PATCH] D117994: [Clang] Implement multidimentional subscript operator

2022-01-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 402781.
cor3ntin marked an inline comment as done.
cor3ntin added a comment.

Address Erich's feedback: A source range was only constructed from the
first element


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117994

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaAccess.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/OpenMP/target_update_messages.cpp
  clang/test/Parser/cxx2b-subscript.cpp
  clang/test/SemaCXX/cxx2b-overloaded-operator.cpp
  clang/test/SemaTemplate/instantiate-subscript.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1353,7 +1353,7 @@
 
   Multidimensional subscript operator
   https://wg21.link/P2128R6";>P2128R6
-  No
+  Clang 14
 
 
   Non-literal variables (and labels and gotos) in constexpr functions
Index: clang/test/SemaTemplate/instantiate-subscript.cpp
===
--- clang/test/SemaTemplate/instantiate-subscript.cpp
+++ clang/test/SemaTemplate/instantiate-subscript.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2b %s
 
 struct Sub0 {
   int &operator[](int);
Index: clang/test/SemaCXX/cxx2b-overloaded-operator.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2b-overloaded-operator.cpp
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -verify -std=c++2b %s
+
+namespace N {
+
+void empty() {
+  struct S {
+int operator[](); // expected-note{{not viable: requires 0 arguments, but 1 was provided}}
+  };
+
+  S{}[];
+  S{}[1]; // expected-error {{no viable overloaded operator[] for type 'S'}}
+}
+
+void default_var() {
+  struct S {
+constexpr int operator[](int i = 42) { return i; } // expected-note {{not viable: allows at most single argument 'i'}}
+  };
+  static_assert(S{}[] == 42);
+  static_assert(S{}[1] == 1);
+  static_assert(S{}[1, 2] == 1); // expected-error {{no viable overloaded operator[] for type 'S'}}
+}
+
+struct Variadic {
+  constexpr int operator[](auto... i) { return (42 + ... + i); }
+};
+
+void variadic() {
+
+  static_assert(Variadic{}[] == 42);
+  static_assert(Variadic{}[1] == 43);
+  static_assert(Variadic{}[1, 2] == 45);
+}
+
+void multiple() {
+  struct S {
+constexpr int operator[]() { return 0; }
+constexpr int operator[](int) { return 1; };
+constexpr int operator[](int, int) { return 2; };
+  };
+  static_assert(S{}[] == 0);
+  static_assert(S{}[1] == 1);
+  static_assert(S{}[1, 1] == 2);
+}
+
+void ambiguous() {
+  struct S {
+constexpr int operator[]() { return 0; } // expected-note{{candidate function}}
+constexpr int operator[](int = 0) { return 1; }; // expected-note{{candidate function}}
+  };
+
+  static_assert(S{}[] == 0); // expected-error{{call to subscript operator of type 'S' is ambiguous}}
+}
+} // namespace N
+
+template 
+struct T1 {
+  constexpr auto operator[](T... arg) { // expected-note {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+return (1 + ... + arg);
+  }
+};
+
+static_assert(T1<>{}[] == 1);
+static_assert(T1{}[1] == 2);
+static_assert(T1{}[1, 1] == 3);
+static_assert(T1{}[1] == 3); // expected-error {{no viable overloaded operator[] for type 'T1'}}
+
+struct T2 {
+  constexpr auto operator[](auto... arg) {
+return (1 + ... + arg);
+  }
+};
+
+static_assert(T2{}[] == 1);
+static_assert(T2{}[1] == 2);
+static_assert(T2{}[1, 1] == 3);
Index: clang/test/Parser/cxx2b-subscript.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx2b-subscript.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx2b -std=c++2b %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
+
+//cxx2b-no-diagnostics
+
+struct S {
+  constexpr int operator[](int i) {
+return i;
+  }
+  constexpr int operator[](int a, int b) { // cxx20-error {{overloaded 'operator[]' cannot have more than one parameter before C++2b}}
+return a + b;
+  }
+  constexpr int operator[]() { // cxx20-error {{overloaded 'operator[]' cannot have no parameter before C++2b}}
+return 42;
+  }
+};
+
+struct Defaults {
+  constexpr int operator[](int i = 0) { // cxx20-error {{overloaded 'operator[]' cannot have a defaulted parameter before C++2b}}
+return 0;
+  }
+  constexpr int

[PATCH] D117994: [Clang] Implement multidimentional subscript operator

2022-01-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaAccess.cpp:1799
+R = SourceRange(ArgExprs.front()->getBeginLoc(),
+ArgExprs.front()->getEndLoc());
+  }

erichkeane wrote:
> So should the 'end' be `ArgExprs.back()->getEndLoc()`?
It should, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117994

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


[PATCH] D117929: [XRay] Add support for RISCV

2022-01-25 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris requested changes to this revision.
dberris added a comment.
This revision now requires changes to proceed.

It looks like you'll need to address the lint issues (using clang-format).

I'm not an expert on RISCV assembly so you might need to get someone familiar 
with the ISA reviewing this too.

For tests, I recommend also adding some for the tooling that consumes the 
sections of the binary where we expect metadata that XRay expects to be 
present. You should be able to re-use/extend some of the tests we already have 
for those to see the end-to-end result (compiling and linking a binary which 
has Xray instrumentation sleds and associated maps).


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

https://reviews.llvm.org/D117929

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


[PATCH] D118095: [AVR][clang] Reject non assembly source files for the avr1 family

2022-01-25 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

There is an old solution in https://reviews.llvm.org/D117423. The concern over 
there is that AVR specific checks should be implemented in AVR toolchain 
specific files. And this patch obeys that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118095

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


[PATCH] D118106: [clang-format] Fix regression in parsing pointers to arrays.

2022-01-25 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius created this revision.
curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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

After commit 5c2e7c9 
, the code:

  template <> struct S : Template {};

was misformatted as:

  template <> struct S : Template{};


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118106

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
@@ -23483,6 +23483,8 @@
 TEST_F(FormatTest, ShortTemplatedArgumentLists) {
   auto Style = getLLVMStyle();
 
+  verifyFormat("template <> struct S : Template {};\n", Style);
+  verifyFormat("template <> struct S : Template {};\n", Style);
   verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
   verifyFormat("struct Y<[] { return 0; }> {};", Style);
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3081,8 +3081,15 @@
 if (!tryToParseBracedList())
   break;
   }
-  if (FormatTok->is(tok::l_square) && !tryToParseLambda())
-break;
+  if (FormatTok->is(tok::l_square)) {
+FormatToken *Previous = FormatTok->Previous;
+if (!Previous || Previous->isNot(tok::r_paren)) {
+  // Don't try parsing a lambda if we had a closing parenthesis before,
+  // it was probably a pointer to an array: int (*)[].
+  if (!tryToParseLambda())
+break;
+}
+  }
   if (FormatTok->Tok.is(tok::semi))
 return;
   if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23483,6 +23483,8 @@
 TEST_F(FormatTest, ShortTemplatedArgumentLists) {
   auto Style = getLLVMStyle();
 
+  verifyFormat("template <> struct S : Template {};\n", Style);
+  verifyFormat("template <> struct S : Template {};\n", Style);
   verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
   verifyFormat("struct Y<[] { return 0; }> {};", Style);
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3081,8 +3081,15 @@
 if (!tryToParseBracedList())
   break;
   }
-  if (FormatTok->is(tok::l_square) && !tryToParseLambda())
-break;
+  if (FormatTok->is(tok::l_square)) {
+FormatToken *Previous = FormatTok->Previous;
+if (!Previous || Previous->isNot(tok::r_paren)) {
+  // Don't try parsing a lambda if we had a closing parenthesis before,
+  // it was probably a pointer to an array: int (*)[].
+  if (!tryToParseLambda())
+break;
+}
+  }
   if (FormatTok->Tok.is(tok::semi))
 return;
   if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2a14bc5 - [NFC] [C++20] [Modules] Update comments for handling friend

2022-01-25 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2022-01-25T16:39:47+08:00
New Revision: 2a14bc55c547f0fc7285b783b5320338c3ffdc42

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

LOG: [NFC] [C++20] [Modules] Update comments for handling friend

There is a comment contains a FIXME for the Module TS. And now the
Module TS is merged so we should update the comment. I've checked the
implementation.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a29409461f575..e014500f2114f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1586,10 +1586,13 @@ void Sema::FilterLookupForScope(LookupResult &R, 
DeclContext *Ctx, Scope *S,
 /// We've determined that \p New is a redeclaration of \p Old. Check that they
 /// have compatible owning modules.
 bool Sema::CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old) {
-  // FIXME: The Modules TS is not clear about how friend declarations are
-  // to be treated. It's not meaningful to have 
diff erent owning modules for
-  // linkage in redeclarations of the same entity, so for now allow the
-  // redeclaration and change the owning modules to match.
+  // [module.interface]p7:
+  // A declaration is attached to a module as follows:
+  // - If the declaration is a non-dependent friend declaration that nominates 
a
+  // function with a declarator-id that is a qualified-id or template-id or 
that
+  // nominates a class other than with an elaborated-type-specifier with 
neither
+  // a nested-name-specifier nor a simple-template-id, it is attached to the
+  // module to which the friend is attached ([basic.link]).
   if (New->getFriendObjectKind() &&
   Old->getOwningModuleForLinkage() != New->getOwningModuleForLinkage()) {
 New->setLocalOwningModule(Old->getOwningModule());



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


[PATCH] D118023: Corrected fragment size for tf32 LD B matrix.

2022-01-25 Thread Jack Kirk via Phabricator via cfe-commits
JackAKirk added a comment.

In D118023#3267271 , @tra wrote:

> The patch uses a `@gmail.com` email. Should I change it to `JackAKirk 
> ` to match the sign-off email?

Ah yes thanks for catching that.  Please use `JackAKirk 
`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118023

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


[clang] aa97bc1 - [NFC] Remove uses of PointerType::getElementType()

2022-01-25 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-01-25T09:44:52+01:00
New Revision: aa97bc116d343f7b6f222d7229668de5d361b312

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

LOG: [NFC] Remove uses of PointerType::getElementType()

Instead use either Type::getPointerElementType() or
Type::getNonOpaquePointerElementType().

This is part of D117885, in preparation for deprecating the API.

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGClass.cpp
clang/lib/CodeGen/CGObjCGNU.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/TargetInfo.cpp
llvm/include/llvm/FuzzMutate/OpDescriptor.h
llvm/include/llvm/IR/MatrixBuilder.h
llvm/include/llvm/IR/Statepoint.h
llvm/lib/Analysis/AliasAnalysisEvaluator.cpp
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/Analysis/IVDescriptors.cpp
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
llvm/lib/FuzzMutate/Operations.cpp
llvm/lib/FuzzMutate/RandomIRBuilder.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/ConstantFold.cpp
llvm/lib/IR/Core.cpp
llvm/lib/IR/Function.cpp
llvm/lib/IR/IRBuilder.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/lib/Target/BPF/BTFDebug.cpp
llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/lib/Target/Sparc/SparcISelLowering.cpp
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/lib/Transforms/Scalar/Scalarizer.cpp
llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
llvm/tools/llvm-stress/llvm-stress.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index ccb394283c4ed..a37ff8844e885 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3880,9 +3880,8 @@ static void emitWritebackArg(CodeGenFunction &CGF, 
CallArgList &args,
   }
 
   // Create the temporary.
-  Address temp = CGF.CreateTempAlloca(destType->getElementType(),
-  CGF.getPointerAlign(),
-  "icr.temp");
+  Address temp = CGF.CreateTempAlloca(destType->getPointerElementType(),
+  CGF.getPointerAlign(), "icr.temp");
   // Loading an l-value can introduce a cleanup if the l-value is __weak,
   // and that cleanup will be conditional if we can't prove that the l-value
   // isn't null, so we need to register a dominating point so that the cleanups
@@ -3892,9 +3891,8 @@ static void emitWritebackArg(CodeGenFunction &CGF, 
CallArgList &args,
   // Zero-initialize it if we're not doing a copy-initialization.
   bool shouldCopy = CRE->shouldCopy();
   if (!shouldCopy) {
-llvm::Value *null =
-  llvm::ConstantPointerNull::get(
-cast(destType->getElementType()));
+llvm::Value *null = llvm::ConstantPointerNull::get(
+cast(destType->getPointerElementType()));
 CGF.Builder.CreateStore(null, temp);
   }
 
@@ -3936,7 +3934,7 @@ static void emitWritebackArg(CodeGenFunction &CGF, 
CallArgList &args,
 assert(srcRV.isScalar());
 
 llvm::Value *src = srcRV.getScalarVal();
-src = CGF.Builder.CreateBitCast(src, destType->getElementType(),
+src = CGF.Builder.CreateBitCast(src, destType->getPointerElementType(),
 "icr.cast");
 
 // Use an ordinary store, not a store-to-lvalue.
@@ -5075,8 +5073,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 #ifndef NDEBUG
 // Assert that these

[PATCH] D117137: [Driver] Add CUDA support for --offload param

2022-01-25 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

SPIR-V target requires that the OS and the environment type is unknown (see 
TargetInfo::AllocateTarget and BaseSPIRTargetInfo). The clang would fail to 
create a SPIR-V target if there is an OS or environment component in the target 
string known by the Triple. This could lead to a misleading error message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117137

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


[PATCH] D118109: [clang] Replace `std::vector` use in Syntax

2022-01-25 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: dexonsmith.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

LLVM Programmer’s Manual strongly discourages the use of `std::vector` 
and suggests `llvm::BitVector` as a possible replacement.

This patch replaces `std::vector` with `llvm::BitVector` in the Format 
library and replaces range-based for loop with regular for loop. This is 
necessary due to `llvm::BitVector` not having `begin()` and `end()` (D117116 
).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118109

Files:
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
@@ -202,7 +203,7 @@
 }
 
 static void dumpNode(raw_ostream &OS, const syntax::Node *N,
- const SourceManager &SM, std::vector IndentMask) {
+ const SourceManager &SM, llvm::BitVector IndentMask) {
   auto DumpExtraInfo = [&OS](const syntax::Node *N) {
 if (N->getRole() != syntax::NodeRole::Unknown)
   OS << " " << N->getRole();
@@ -228,8 +229,8 @@
   OS << "\n";
 
   for (const syntax::Node &It : T->getChildren()) {
-for (bool Filled : IndentMask) {
-  if (Filled)
+for (unsigned Idx = 0; Idx < IndentMask.size(); ++Idx) {
+  if (IndentMask[Idx])
 OS << "| ";
   else
 OS << "  ";


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -9,6 +9,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Nodes.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
@@ -202,7 +203,7 @@
 }
 
 static void dumpNode(raw_ostream &OS, const syntax::Node *N,
- const SourceManager &SM, std::vector IndentMask) {
+ const SourceManager &SM, llvm::BitVector IndentMask) {
   auto DumpExtraInfo = [&OS](const syntax::Node *N) {
 if (N->getRole() != syntax::NodeRole::Unknown)
   OS << " " << N->getRole();
@@ -228,8 +229,8 @@
   OS << "\n";
 
   for (const syntax::Node &It : T->getChildren()) {
-for (bool Filled : IndentMask) {
-  if (Filled)
+for (unsigned Idx = 0; Idx < IndentMask.size(); ++Idx) {
+  if (IndentMask[Idx])
 OS << "| ";
   else
 OS << "  ";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118110: [CMake] [Clang] Add CMake build option to specify long double format on PowerPC

2022-01-25 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf created this revision.
qiucf added reviewers: jsji, nemanjai, shchenz, PowerPC.
Herald added subscribers: steven.zhang, kbarton, mgorny.
qiucf requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This method introduces new CMake variable `ENABLE_PPC_IEEELONGDOUBLE` (false by 
default) to enable `fp128` as default long double format.

We need to make some tests explicitly set long double type, otherwise they fail 
in either config.

There's one thing uncertain: whether this config only applies to `ppc64le`? 
Currently `-mabi=ieeelongdouble` also works on ppc64 linux, GCC also does under 
big endian, however we may be not interested in doing the transition other than 
ppc64le 
(https://gcc.gnu.org/wiki/Ieee128PowerPC#A7.0_Transition_to_IEEE_128-bit_floating_point_as_the_default_for_long_double
 ).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118110

Files:
  clang/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Analysis/builtin_signbit.cpp
  clang/test/Driver/ppc-abi.c

Index: clang/test/Driver/ppc-abi.c
===
--- clang/test/Driver/ppc-abi.c
+++ clang/test/Driver/ppc-abi.c
@@ -63,9 +63,6 @@
 // CHECK-ELFv1-IEEE: "-mabi=ieeelongdouble"
 // CHECK-ELFv1-IEEE: "-target-abi" "elfv1"
 
-// Check -mabi=ibmlongdouble is the default.
-// RUN: %clang -target powerpc64le-linux-gnu %s -### 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s
 // RUN: %clang -target powerpc64le-linux-gnu %s -mabi=ibmlongdouble -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s
 
Index: clang/test/Analysis/builtin_signbit.cpp
===
--- clang/test/Analysis/builtin_signbit.cpp
+++ clang/test/Analysis/builtin_signbit.cpp
@@ -1,6 +1,9 @@
-// RUN: %clang -target powerpc-linux-gnu -emit-llvm -S -O0 %s -o - | FileCheck %s --check-prefix=CHECK-BE --check-prefix=CHECK
-// RUN: %clang -target powerpc64-linux-gnu   -emit-llvm -S -O0 %s -o - | FileCheck %s --check-prefix=CHECK-BE --check-prefix=CHECK
-// RUN: %clang -target powerpc64le-linux-gnu -emit-llvm -S -O0 %s -o - | FileCheck %s --check-prefix=CHECK-LE --check-prefix=CHECK
+// RUN: %clang -target powerpc-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \
+// RUN:   -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -target powerpc64-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \
+// RUN:   -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -target powerpc64le-linux-gnu -emit-llvm -S -mabi=ibmlongdouble \
+// RUN:   -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-LE
 
 bool b;
 double d = -1.0;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2061,7 +2061,7 @@
 }
   }
 
-  bool IEEELongDouble = false;
+  bool IEEELongDouble = getToolChain().useIEEELongDouble();
   for (const Arg *A : Args.filtered(options::OPT_mabi_EQ)) {
 StringRef V = A->getValue();
 if (V == "ieeelongdouble")
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -109,6 +109,10 @@
   return ENABLE_X86_RELAX_RELOCATIONS;
 }
 
+bool ToolChain::useIEEELongDouble() const {
+  return ENABLE_PPC_IEEELONGDOUBLE;
+}
+
 SanitizerArgs
 ToolChain::getSanitizerArgs(const llvm::opt::ArgList &JobArgs) const {
   SanitizerArgs SanArgs(*this, JobArgs, !SanitizerArgsChecked);
Index: clang/include/clang/Driver/ToolChain.h
===
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -409,6 +409,9 @@
   /// Check whether to enable x86 relax relocations by default.
   virtual bool useRelaxRelocations() const;
 
+  /// Check whether use IEEE binary128 as long double format by default.
+  bool useIEEELongDouble() const;
+
   /// GetDefaultStackProtectorLevel - Get the default stack protector level for
   /// this tool chain.
   virtual LangOptions::StackProtectorMode
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -78,6 +78,9 @@
 /* enable x86 relax relocations by default */
 #cmakedefine01 ENABLE_X86_RELAX_RELOCATIONS
 
+/* Enable IEEE binary128 as default long double format on PowerPC. */
+#cmakedefine01 ENABLE_PPC_IEEELONGDOUBLE
+
 /* Enable each functionality of modules */
 #cmakedefine01 CLANG_ENABLE_ARCMT
 #cmakedefine01 CLANG_ENABLE_OBJC_REWRITER
Index: clang/CMakeLists.txt
==

[PATCH] D116085: [clang-tidy] Performance improvements for NOLINTBEGIN/END blocks

2022-01-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!




Comment at: clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp:187
+static SmallVector
+formNoLintBlocks(SmallVector &NoLints,
+ SmallVectorImpl &UnmatchedTokens) {

let's drop the `&` here to make sure caller does an explicit `std::move`. since 
the helper is actually consuming the tokens inside the vector and in theory it 
shouldn't be used afterwards.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116085

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


[PATCH] D118050: [analyzer] Different address spaces cannot overlap

2022-01-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a subscriber: NoQ.
steakhal added a comment.

I'm wondering if we should have an assertion within the 
`SValBuilder::evalBinOpLL()` asserting that the pointers should have the same 
bitwidths.
That's better than having nothing, waiting for a bugreport containing such a 
constraint on the bugpath to get a crash with Z3 refutation.

That way we could have a chance to fix these issues for once and all.
WDYT @NoQ @martong?




Comment at: clang/test/Analysis/cstring-checker-addressspace.c:14
+// Copy from host to device memory.
+DEVICE void *memcpy(DEVICE void *dst, const void *src, unsigned long len);
+

Please try to trigger the test using some suffix for the `memcpy`.
E.g.: `memcpy_host2device` or something similar.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118050

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


[PATCH] D118044: [ARM] Undeprecate complex IT blocks

2022-01-25 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

I may have missed this in the many test changes but are we left with a test 
that demonstrates that the codegen restriction still works? I see some that set 
one or the other, any with both that would catch us breaking this feature later?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118044

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


[PATCH] D118044: [ARM] Undeprecate complex IT blocks

2022-01-25 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added inline comments.



Comment at: llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp:10977
-Warning(IDLoc, "deprecated instruction in IT block");
-  }
 }

MarkMurrayARM wrote:
> DavidSpickett wrote:
> > Is this warning something you'd still want if you opted into restricting IT 
> > blocks? Or can we say that because there has/will not be any core produced 
> > that follows the deprecation, you would never need the warning.
> No - in effect, deprecation is gone entirely. There is nothing to warn about. 
> You can ask the compiler not to do it, but if you craft complex IT blocks by 
> hand, that is up to you.
Got it, agreed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118044

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


[PATCH] D107290: [RISCV] Add support for the vscale_range attribute

2022-01-25 Thread Fraser Cormack via Phabricator via cfe-commits
frasercrmck added inline comments.



Comment at: llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vscale-range.ll:162
+
+attributes #0 = { vscale_range(2,1024) }
+attributes #1 = { vscale_range(4,1024) }

khchen wrote:
> I'm thinking do we need to test zvl and vscale_range in the same attribute?
> ex. `attributes #0 = { vscale_range(2,1024) "target-features"="+zvl512b" }`
Perhaps yeah. Just to check - what exactly for? Because we need `zvl` in the 
attributes for correctness, or in order to test the combination of `zvl` 
architecture and `vscale_range` to test what happens when they disagree?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107290

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


[PATCH] D117753: [AArch64] Support for memset tagged intrinsic

2022-01-25 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added inline comments.



Comment at: clang/test/CodeGen/aarch64-mops.c:3
+
+// RUN: %clang_cc1 -triple aarch64-arm-unknown-eabi -target-feature +mops -S 
-emit-llvm -o - %s  | FileCheck %s
+

I forgot if we add negative tests for these things, i.e. check if we error if 
we don't have `+mops` or `__ARM_FEATURE_MOPS` set? I guess so?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117753

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


[PATCH] D117295: [clang][sema] Allow unnamed decls in C++20 module export{} blocks

2022-01-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 402813.
tbaeder added a comment.

Limited the change to c++2b


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

https://reviews.llvm.org/D117295

Files:
  clang/lib/Sema/SemaModule.cpp
  clang/test/CXX/module/module.interface/p3.cpp
  clang/test/Modules/cxx20-export.cpp


Index: clang/test/Modules/cxx20-export.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-export.cpp
@@ -0,0 +1,23 @@
+
+// RUN: %clang_cc1 -std=c++2b -verify %s
+export module testmodule;
+
+export static_assert(true); // expected-error {{static_assert declaration 
cannot be exported}}
+export; // expected-error {{empty declaration cannot be 
exported}}
+
+namespace A {};
+
+export {
+#define STR(x) constexpr char x[] = #x;
+  STR(foo);
+#undef STR
+
+  static_assert(true);
+
+  template  struct X { T t; };
+  template  X(T) -> X;
+
+  ; // Empty declaration
+
+  using namespace A;
+}
Index: clang/test/CXX/module/module.interface/p3.cpp
===
--- clang/test/CXX/module/module.interface/p3.cpp
+++ clang/test/CXX/module/module.interface/p3.cpp
@@ -9,12 +9,6 @@
 export static_assert(true); // expected-error {{static_assert declaration 
cannot be exported}}
 export using namespace A; // expected-error {{ISO C++20 does not permit using 
directive to be exported}}
 
-export { // expected-note 3{{export block begins here}}
-  ; // expected-error {{ISO C++20 does not permit an empty declaration to 
appear in an export block}}
-  static_assert(true); // expected-error {{ISO C++20 does not permit a 
static_assert declaration to appear in an export block}}
-  using namespace A; // expected-error {{ISO C++20 does not permit using 
directive to be exported}}
-}
-
 export struct {}; // expected-error {{must be class member}} expected-error 
{{GNU extension}} expected-error {{does not declare anything}}
 export struct {} struct_;
 export union {}; // expected-error {{must be declared 'static'}} 
expected-error {{does not declare anything}}
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -615,12 +615,10 @@
   return llvm::None;
 }
 
-unsigned getUnnamedDeclDiag(UnnamedDeclKind UDK, bool InBlock) {
+static unsigned getUnnamedDeclDiag(UnnamedDeclKind UDK, bool InBlock) {
   switch (UDK) {
   case UnnamedDeclKind::Empty:
   case UnnamedDeclKind::StaticAssert:
-// Allow empty-declarations and static_asserts in an export block as an
-// extension.
 return InBlock ? diag::ext_export_no_name_block : diag::err_export_no_name;
 
   case UnnamedDeclKind::UsingDirective:
@@ -648,10 +646,16 @@
 
 /// Check that it's valid to export \p D.
 static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
-  // C++2a [module.interface]p3:
-  //   An exported declaration shall declare at least one name
-  if (auto UDK = getUnnamedDeclKind(D))
-diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+  if (auto UDK = getUnnamedDeclKind(D)) {
+if (S.getLangOpts().CPlusPlus2b) {
+  if (BlockStart.isInvalid())
+diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+} else {
+  // C++2a [module.interface]p3:
+  //   An exported declaration shall declare at least one name
+  diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+}
+  }
 
   //   [...] shall not declare a name with internal linkage.
   if (auto *ND = dyn_cast(D)) {


Index: clang/test/Modules/cxx20-export.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-export.cpp
@@ -0,0 +1,23 @@
+
+// RUN: %clang_cc1 -std=c++2b -verify %s
+export module testmodule;
+
+export static_assert(true); // expected-error {{static_assert declaration cannot be exported}}
+export; // expected-error {{empty declaration cannot be exported}}
+
+namespace A {};
+
+export {
+#define STR(x) constexpr char x[] = #x;
+  STR(foo);
+#undef STR
+
+  static_assert(true);
+
+  template  struct X { T t; };
+  template  X(T) -> X;
+
+  ; // Empty declaration
+
+  using namespace A;
+}
Index: clang/test/CXX/module/module.interface/p3.cpp
===
--- clang/test/CXX/module/module.interface/p3.cpp
+++ clang/test/CXX/module/module.interface/p3.cpp
@@ -9,12 +9,6 @@
 export static_assert(true); // expected-error {{static_assert declaration cannot be exported}}
 export using namespace A; // expected-error {{ISO C++20 does not permit using directive to be exported}}
 
-export { // expected-note 3{{export block begins here}}
-  ; // expected-error {{ISO C++20 does not permit an empty declaration to appear in an export block}}
-  static_assert(true); // expected-error {{ISO C++20 does not permit a static_assert declaration to appear in an export b

[PATCH] D118050: [analyzer] Different address spaces cannot overlap

2022-01-25 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Good thoughts, I will try those things and get back to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118050

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


[PATCH] D117295: [clang][sema] Allow unnamed decls in C++20 module export{} blocks

2022-01-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:650-652
+if (S.getLangOpts().CPlusPlus2b) {
+  if (BlockStart.isInvalid())
+diagExportedUnnamedDecl(S, *UDK, D, BlockStart);

Should we add a cite to P1766R1 here?



Comment at: clang/test/CXX/module/module.interface/p3.cpp:12-16
-export { // expected-note 3{{export block begins here}}
-  ; // expected-error {{ISO C++20 does not permit an empty declaration to 
appear in an export block}}
-  static_assert(true); // expected-error {{ISO C++20 does not permit a 
static_assert declaration to appear in an export block}}
-  using namespace A; // expected-error {{ISO C++20 does not permit using 
directive to be exported}}
-}

This one should be deleted unintentionally.


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

https://reviews.llvm.org/D117295

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


[clang] 99adacb - [clang] Remove some getPointerElementType() uses

2022-01-25 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-01-25T12:09:06+01:00
New Revision: 99adacbcb7895114a62266c8a15e794bacd2380c

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

LOG: [clang] Remove some getPointerElementType() uses

Same cases where the call can be removed in a straightforward way.

Added: 


Modified: 
clang/lib/CodeGen/CGAtomic.cpp
clang/lib/CodeGen/CGCall.h
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 6532f0287961..10569ae2c3f9 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -351,12 +351,12 @@ bool AtomicInfo::requiresMemSetZero(llvm::Type *type) 
const {
 
 bool AtomicInfo::emitMemSetZeroIfNecessary() const {
   assert(LVal.isSimple());
-  llvm::Value *addr = LVal.getPointer(CGF);
-  if (!requiresMemSetZero(addr->getType()->getPointerElementType()))
+  Address addr = LVal.getAddress(CGF);
+  if (!requiresMemSetZero(addr.getElementType()))
 return false;
 
   CGF.Builder.CreateMemSet(
-  addr, llvm::ConstantInt::get(CGF.Int8Ty, 0),
+  addr.getPointer(), llvm::ConstantInt::get(CGF.Int8Ty, 0),
   CGF.getContext().toCharUnitsFromBits(AtomicSizeInBits).getQuantity(),
   LVal.getAlignment().getAsAlign());
   return true;
@@ -1522,7 +1522,7 @@ RValue AtomicInfo::ConvertIntToValueOrAtomic(llvm::Value 
*IntVal,
!AsValue)) {
 auto *ValTy = AsValue
   ? CGF.ConvertTypeForMem(ValueTy)
-  : getAtomicAddress().getType()->getPointerElementType();
+  : getAtomicAddress().getElementType();
 if (ValTy->isIntegerTy()) {
   assert(IntVal->getType() == ValTy && "Different integer types.");
   return RValue::get(CGF.EmitFromMemory(IntVal, ValueTy));

diff  --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index d2bb104a3f9d..af63e1bddd2d 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -112,7 +112,8 @@ class CGCallee {
 assert(functionPtr && "configuring callee without function pointer");
 assert(functionPtr->getType()->isPointerTy());
 assert(functionPtr->getType()->isOpaquePointerTy() ||
-   functionPtr->getType()->getPointerElementType()->isFunctionTy());
+   functionPtr->getType()->getNonOpaquePointerElementType()
+   ->isFunctionTy());
   }
 
   static CGCallee forBuiltin(unsigned builtinID,

diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index e32462eb635c..4e8933fffe03 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1613,8 +1613,9 @@ 
ScalarExprEmitter::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) {
   if (GlobalConstStr->getType()->getPointerAddressSpace() == ExprAS)
 return GlobalConstStr;
 
-  llvm::Type *EltTy = GlobalConstStr->getType()->getPointerElementType();
-  llvm::PointerType *NewPtrTy = llvm::PointerType::get(EltTy, ExprAS);
+  llvm::PointerType *PtrTy = 
cast(GlobalConstStr->getType());
+  llvm::PointerType *NewPtrTy =
+  llvm::PointerType::getWithSamePointeeType(PtrTy, ExprAS);
   return Builder.CreateAddrSpaceCast(GlobalConstStr, NewPtrTy, 
"usn_addr_cast");
 }
 

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index fd956aabc717..c8c08060e729 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -837,10 +837,7 @@ void ReductionCodeGen::emitAggregateType(CodeGenFunction 
&CGF, unsigned N) {
   }
   llvm::Value *Size;
   llvm::Value *SizeInChars;
-  auto *ElemType = OrigAddresses[N]
-   .first.getPointer(CGF)
-   ->getType()
-   ->getPointerElementType();
+  auto *ElemType = OrigAddresses[N].first.getAddress(CGF).getElementType();
   auto *ElemSizeOf = llvm::ConstantExpr::getSizeOf(ElemType);
   if (AsArraySection) {
 Size = CGF.Builder.CreatePtrDiff(OrigAddresses[N].second.getPointer(CGF),

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 594c7fef36a7..7c8e4e6b52a0 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3401,12 +3401,13 @@ CGOpenMPRuntimeGPU::getParameterAddress(CodeGenFunction 
&CGF,
   LocalAddr, /*Volatile=*/false, TargetTy, SourceLocation());
   // First cast to generic.
   TargetAddr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
-  TargetAddr, TargetAddr->getType()->getPointerElementType()->getPointerTo(
-  /*AddrSpace=*/0));
+   

[PATCH] D116085: [clang-tidy] Performance improvements for NOLINTBEGIN/END blocks

2022-01-25 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz updated this revision to Diff 402818.
salman-javed-nz added a comment.

Review comment: 
`formNoLintBlocks()` - drop the `&` so the vector must be std::moved in


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116085

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
  clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/1st-translation-unit.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/2nd-translation-unit.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-glob.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-all-end-specific.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-all.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-glob-end-specific.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-global-end-specific.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-all.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-glob.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-specific-end-global.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-multiple-TUs.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp

Index: clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
@@ -58,30 +58,24 @@
 // NOLINTEND(some-other-check)
 // NOLINTEND(google-explicit-constructor)
 
-// NOLINTBEGIN(google-explicit-constructor)
-// NOLINTBEGIN(some-other-check)
-class C7 { C7(int i); };
-// NOLINTEND(google-explicit-constructor)
-// NOLINTEND(some-other-check)
-
 // NOLINTBEGIN(google-explicit-constructor)
 // NOLINTBEGIN
-class C8 { C8(int i); };
+class C7 { C7(int i); };
 // NOLINTEND
 // NOLINTEND(google-explicit-constructor)
 
 // NOLINTBEGIN
 // NOLINTBEGIN(google-explicit-constructor)
-class C9 { C9(int i); };
+class C8 { C8(int i); };
 // NOLINTEND(google-explicit-constructor)
 // NOLINTEND
 
 // NOLINTBEGIN(not-closed-bracket-is-treated-as-skip-all
-class C10 { C10(int i); };
+class C9 { C9(int i); };
 // NOLINTEND(not-closed-bracket-is-treated-as-skip-all
 
 // NOLINTBEGIN without-brackets-skip-all, another-check
-class C11 { C11(int i); };
+class C10 { C10(int i); };
 // NOLINTEND without-brackets-skip-all, another-check
 
 #define MACRO(X) class X { X(int i); };
@@ -114,28 +108,28 @@
 MACRO_NO_LINT_INSIDE_MACRO
 
 // NOLINTBEGIN(google*)
-class C12 { C12(int i); };
+class C11 { C11(int i); };
 // NOLINTEND(google*)
 
 // NOLINTBEGIN(*explicit-constructor)
-class C15 { C15(int i); };
+class C12 { C12(int i); };
 // NOLINTEND(*explicit-constructor)
 
 // NOLINTBEGIN(*explicit*)
-class C16 { C16(int i); };
+class C13 { C13(int i); };
 // NOLINTEND(*explicit*)
 
 // NOLINTBEGIN(-explicit-constructor)
-class C17 { C17(int x); };
+class C14 { C14(int x); };
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: single-argument constructors must be marked explicit
 // NOLINTEND(-explicit-constructor)
 
 // NOLINTBEGIN(google*,-google*)
-class C18 { C18(int x); };
+class C15 { C15(int x); };
 // NOLINTEND(google*,-google*)
 
 // NOLINTBEGIN(*,-google*)
-class C19 { C19(int x); };
+class C16 { C16(int x); };
 // NOLINTEND(*,-google*)
 
 int array1[10];
@@ -154,4 +148,4 @@
 int array4[10];
 // NOLINTEND(*-avoid-c-arrays)
 
-// CHECK-MESSAGES: Suppressed 27 warnings (27 NOLINT).
+// CHECK-MESSAGES: Suppressed 26 warnings (26 NOLINT).
Index: clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-typo-in-check-name.cpp
+++ clang-tools-extra/

[PATCH] D118119: [clang][dataflow] Add a transfer function for InitListExpr

2022-01-25 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev created this revision.
sgatev added reviewers: ymandel, xazax.hun, gribozavr2.
Herald added subscribers: tschuett, steakhal, rnkovacs.
sgatev requested review of this revision.
Herald added a project: clang.

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118119

Files:
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1865,4 +1865,91 @@
   });
 }
 
+TEST_F(TransferTest, AggregateInitialization) {
+  std::string BracesCode = R"(
+struct A {
+  int Foo;
+};
+
+struct B {
+  int Bar;
+  A Baz;
+  int Qux;
+};
+
+void target(int BarArg, int FooArg, int QuxArg) {
+  B Quux{BarArg, {FooArg}, QuxArg};
+  /*[[p]]*/
+}
+  )";
+  std::string BraceEllisionCode = R"(
+struct A {
+  int Foo;
+};
+
+struct B {
+  int Bar;
+  A Baz;
+  int Qux;
+};
+
+void target(int BarArg, int FooArg, int QuxArg) {
+  B Quux = {BarArg, FooArg, QuxArg};
+  /*[[p]]*/
+}
+  )";
+  for (const std::string &Code : {BracesCode, BraceEllisionCode}) {
+runDataflow(
+Code, [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+  ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+  const Environment &Env = Results[0].second.Env;
+
+  const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+  ASSERT_THAT(FooDecl, NotNull());
+
+  const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+  ASSERT_THAT(BarDecl, NotNull());
+
+  const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+  ASSERT_THAT(BazDecl, NotNull());
+
+  const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+  ASSERT_THAT(QuxDecl, NotNull());
+
+  const ValueDecl *FooArgDecl = findValueDecl(ASTCtx, "FooArg");
+  ASSERT_THAT(FooArgDecl, NotNull());
+
+  const ValueDecl *BarArgDecl = findValueDecl(ASTCtx, "BarArg");
+  ASSERT_THAT(BarArgDecl, NotNull());
+
+  const ValueDecl *QuxArgDecl = findValueDecl(ASTCtx, "QuxArg");
+  ASSERT_THAT(QuxArgDecl, NotNull());
+
+  const ValueDecl *QuuxDecl = findValueDecl(ASTCtx, "Quux");
+  ASSERT_THAT(QuuxDecl, NotNull());
+
+  const auto *FooArgVal =
+  cast(Env.getValue(*FooArgDecl, SkipPast::None));
+  const auto *BarArgVal =
+  cast(Env.getValue(*BarArgDecl, SkipPast::None));
+  const auto *QuxArgVal =
+  cast(Env.getValue(*QuxArgDecl, SkipPast::None));
+
+  const auto *QuuxVal =
+  cast(Env.getValue(*QuuxDecl, SkipPast::None));
+  ASSERT_THAT(QuuxVal, NotNull());
+
+  const auto *BazVal = cast(&QuuxVal->getChild(*BazDecl));
+  ASSERT_THAT(BazVal, NotNull());
+
+  EXPECT_EQ(&QuuxVal->getChild(*BarDecl), BarArgVal);
+  EXPECT_EQ(&BazVal->getChild(*FooDecl), FooArgVal);
+  EXPECT_EQ(&QuuxVal->getChild(*QuxDecl), QuxArgVal);
+});
+  }
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -22,9 +22,11 @@
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Basic/OperatorKinds.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace dataflow {
@@ -414,6 +416,28 @@
   Env.setValue(Loc, *Val);
   }
 
+  void VisitInitListExpr(const InitListExpr *S) {
+QualType Type = S->getType();
+assert(Type->isStructureOrClassType());
+
+auto &Loc = Env.createStorageLocation(*S);
+Env.setStorageLocation(*S, Loc);
+
+auto *Val = cast(Env.createValue(Type));
+Env.setValue(Loc, *Val);
+
+for (auto IT : llvm::zip(Type->getAsRecordDecl()->fields(), S->inits())) {
+  const FieldDecl *Field = std::get<0>(IT);
+  assert(Field != nullptr);
+
+  const Expr *Init = std::get<1>(IT);
+  assert(Init != nullptr);
+
+  if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
+Val->setChild(*Field, *InitVal);
+}
+  }
+
   // FIXME: Add support for:
   // - CXXBoolLiteralExpr
 
Index: clang/include/clang/Analysis/FlowSensitive/Value.h
===
---

[PATCH] D118120: [C++20] [Modules] Only check decls under namespace scope in CheckRedeclarationExported

2022-01-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu created this revision.
ChuanqiXu added reviewers: rsmith, aaron.ballman, urnathan, erichkeane, tbaeder.
ChuanqiXu added a project: clang.
ChuanqiXu requested review of this revision.
Herald added a subscriber: cfe-commits.

Since only the decls inhabit in a namespace scope could be exported, it is not 
meaningful to check it in CheckRedeclarationExported, which implements 
[module.interface]/p6: http://eel.is/c++draft/module.interface#6.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118120

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/module/module.interface/p6.cpp


Index: clang/test/CXX/module/module.interface/p6.cpp
===
--- clang/test/CXX/module/module.interface/p6.cpp
+++ clang/test/CXX/module/module.interface/p6.cpp
@@ -91,3 +91,24 @@
 T TemplVar; // expected-note {{previous declaration is here}}
 export template 
 T TemplVar; // expected-error {{cannot export redeclaration 'TemplVar' here 
since the previous declaration is not exported}}
+
+// Test the compiler wouldn't complain about the redeclaration of friend in 
exported class.
+namespace Friend {
+template 
+class bar;
+class gua;
+template 
+void hello();
+void hi();
+export class foo;
+bool operator<(const foo &a, const foo &b);
+export class foo {
+  template 
+  friend class bar;
+  friend class gua;
+  template 
+  friend void hello();
+  friend void hi();
+  friend bool operator<(const foo &a, const foo &b);
+};
+} // namespace Friend
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1635,6 +1635,19 @@
 // A redeclaration of an entity X is implicitly exported if X was introduced by
 // an exported declaration; otherwise it shall not be exported.
 bool Sema::CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old) {
+  // [module.interface]p1:
+  // An export-declaration shall inhabit a namespace scope.
+  //
+  // So it is meaningless to talk about redeclaration which is not at namespace
+  // scope.
+  if (!New->getLexicalDeclContext()
+   ->getNonTransparentContext()
+   ->isFileContext() ||
+  !Old->getLexicalDeclContext()
+   ->getNonTransparentContext()
+   ->isFileContext())
+return false;
+
   bool IsNewExported = New->isInExportDeclContext();
   bool IsOldExported = Old->isInExportDeclContext();
 


Index: clang/test/CXX/module/module.interface/p6.cpp
===
--- clang/test/CXX/module/module.interface/p6.cpp
+++ clang/test/CXX/module/module.interface/p6.cpp
@@ -91,3 +91,24 @@
 T TemplVar; // expected-note {{previous declaration is here}}
 export template 
 T TemplVar; // expected-error {{cannot export redeclaration 'TemplVar' here since the previous declaration is not exported}}
+
+// Test the compiler wouldn't complain about the redeclaration of friend in exported class.
+namespace Friend {
+template 
+class bar;
+class gua;
+template 
+void hello();
+void hi();
+export class foo;
+bool operator<(const foo &a, const foo &b);
+export class foo {
+  template 
+  friend class bar;
+  friend class gua;
+  template 
+  friend void hello();
+  friend void hi();
+  friend bool operator<(const foo &a, const foo &b);
+};
+} // namespace Friend
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1635,6 +1635,19 @@
 // A redeclaration of an entity X is implicitly exported if X was introduced by
 // an exported declaration; otherwise it shall not be exported.
 bool Sema::CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old) {
+  // [module.interface]p1:
+  // An export-declaration shall inhabit a namespace scope.
+  //
+  // So it is meaningless to talk about redeclaration which is not at namespace
+  // scope.
+  if (!New->getLexicalDeclContext()
+   ->getNonTransparentContext()
+   ->isFileContext() ||
+  !Old->getLexicalDeclContext()
+   ->getNonTransparentContext()
+   ->isFileContext())
+return false;
+
   bool IsNewExported = New->isInExportDeclContext();
   bool IsOldExported = Old->isInExportDeclContext();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118120: [C++20] [Modules] Only check decls under namespace scope in CheckRedeclarationExported

2022-01-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:1643-1648
+  if (!New->getLexicalDeclContext()
+   ->getNonTransparentContext()
+   ->isFileContext() ||
+  !Old->getLexicalDeclContext()
+   ->getNonTransparentContext()
+   ->isFileContext())

This is formatted by clang-format, the original may be too long:
```
if (!New->getLexicalDeclContext()->getNonTransparentContext()->isFileContext() 
||
...
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118120

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


[PATCH] D117295: [clang][sema] Allow unnamed decls in C++20 module export{} blocks

2022-01-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:650-652
+if (S.getLangOpts().CPlusPlus2b) {
+  if (BlockStart.isInvalid())
+diagExportedUnnamedDecl(S, *UDK, D, BlockStart);

ChuanqiXu wrote:
> Should we add a cite to P1766R1 here?
I wanted to do that, but I'm not 100% sure how. P1766R1 doesn't seem to change 
any wording for this change. What exactly do I cite?



Comment at: clang/test/CXX/module/module.interface/p3.cpp:12-16
-export { // expected-note 3{{export block begins here}}
-  ; // expected-error {{ISO C++20 does not permit an empty declaration to 
appear in an export block}}
-  static_assert(true); // expected-error {{ISO C++20 does not permit a 
static_assert declaration to appear in an export block}}
-  using namespace A; // expected-error {{ISO C++20 does not permit using 
directive to be exported}}
-}

ChuanqiXu wrote:
> This one should be deleted unintentionally.
Right, I forgot about that. Added it back, thanks.


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

https://reviews.llvm.org/D117295

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


[clang] caff859 - [OpenMP] Simplify pointer comparison

2022-01-25 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-01-25T12:38:37+01:00
New Revision: caff8591eff211c41d8de8505f89754d09ca6fa7

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

LOG: [OpenMP] Simplify pointer comparison

Rather than checking ptrdiff(a, b) != 0, directly check a != b.

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/declare_mapper_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index c8c08060e729e..233656b90095b 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -10217,8 +10217,7 @@ void CGOpenMPRuntime::emitUDMapperArrayInitOrDel(
   llvm::Value *Cond;
   if (IsInit) {
 // base != begin?
-llvm::Value *BaseIsBegin = MapperCGF.Builder.CreateIsNotNull(
-MapperCGF.Builder.CreatePtrDiff(Base, Begin));
+llvm::Value *BaseIsBegin = MapperCGF.Builder.CreateICmpNE(Base, Begin);
 // IsPtrAndObj?
 llvm::Value *PtrAndObjBit = MapperCGF.Builder.CreateAnd(
 MapType,

diff  --git a/clang/test/OpenMP/declare_mapper_codegen.cpp 
b/clang/test/OpenMP/declare_mapper_codegen.cpp
index 053aa9d2cc6df..e114a1315c79f 100644
--- a/clang/test/OpenMP/declare_mapper_codegen.cpp
+++ b/clang/test/OpenMP/declare_mapper_codegen.cpp
@@ -102,11 +102,7 @@ class C {
 // CK0-DAG: [[ISARRAY:%.+]] = icmp sgt i64 [[SIZE]], 1
 // CK0-DAG: [[PTRBEGIN:%.+]] = bitcast i8* [[BEGIN]] to %class.C*
 // CK0-DAG: [[PTREND:%.+]] = getelementptr %class.C, %class.C* [[PTRBEGIN]], 
i64 [[SIZE]]
-// CK0-DAG: [[BPTRI:%.+]] = ptrtoint i8* [[BPTR]] to i64
-// CK0-DAG: [[PTRI:%.+]] = ptrtoint i8* [[BEGIN]] to i64
-// CK0-DAG: [[DIF:%.+]] = sub i64 [[BPTRI]], [[PTRI]]
-// CK0-DAG: [[NORM:%.+]] = sdiv exact i64 [[DIF]], ptrtoint (i8* getelementptr 
(i8, i8* null, i32 1) to i64)
-// CK0-DAG: [[PTRSNE:%.+]] = icmp ne i64 [[NORM]], 0
+// CK0-DAG: [[PTRSNE:%.+]] = icmp ne i8* [[BPTR]], [[BEGIN]]
 // CK0-DAG: [[PTRANDOBJ:%.+]] = and i64 [[TYPE]], 16
 // CK0-DAG: [[ISPTRANDOBJ:%.+]] = icmp ne i64 [[PTRANDOBJ]], 0
 // CK0-DAG: [[CMPA:%.+]] = and i1 [[PTRSNE]], [[ISPTRANDOBJ]]
@@ -662,11 +658,7 @@ class C {
 // CK1-DAG: [[PTRBEGIN:%.+]] = bitcast i8* [[BEGIN]] to %class.C*
 // CK1-DAG: [[PTREND:%.+]] = getelementptr %class.C, %class.C* [[PTRBEGIN]], 
i64 [[SIZE]]
 // CK1-DAG: [[ISARRAY:%.+]] = icmp sgt i64 [[SIZE]], 1
-// CK1-DAG: [[BPTRI:%.+]] = ptrtoint i8* [[BPTR]] to i64
-// CK1-DAG: [[PTRI:%.+]] = ptrtoint i8* [[BEGIN]] to i64
-// CK1-DAG: [[DIF:%.+]] = sub i64 [[BPTRI]], [[PTRI]]
-// CK1-DAG: [[NORM:%.+]] = sdiv exact i64 [[DIF]], ptrtoint (i8* getelementptr 
(i8, i8* null, i32 1) to i64)
-// CK1-DAG: [[PTRSNE:%.+]] = icmp ne i64 [[NORM]], 0
+// CK1-DAG: [[PTRSNE:%.+]] = icmp ne i8* [[BPTR]], [[BEGIN]]
 // CK1-DAG: [[PTRANDOBJ:%.+]] = and i64 [[TYPE]], 16
 // CK1-DAG: [[ISPTRANDOBJ:%.+]] = icmp ne i64 [[PTRANDOBJ]], 0
 // CK1-DAG: [[CMPA:%.+]] = and i1 [[PTRSNE]], [[ISPTRANDOBJ]]
@@ -789,11 +781,7 @@ class C {
 // CK2-DAG: [[PTRBEGIN:%.+]] = bitcast i8* [[BEGIN]] to %class.C*
 // CK2-DAG: [[PTREND:%.+]] = getelementptr %class.C, %class.C* [[PTRBEGIN]], 
i64 [[SIZE]]
 // CK2-DAG: [[ISARRAY:%.+]] = icmp sgt i64 [[SIZE]], 1
-// CK2-DAG: [[BPTRI:%.+]] = ptrtoint i8* [[BPTR]] to i64
-// CK2-DAG: [[PTRI:%.+]] = ptrtoint i8* [[BEGIN]] to i64
-// CK2-DAG: [[DIF:%.+]] = sub i64 [[BPTRI]], [[PTRI]]
-// CK2-DAG: [[NORM:%.+]] = sdiv exact i64 [[DIF]], ptrtoint (i8* getelementptr 
(i8, i8* null, i32 1) to i64)
-// CK2-DAG: [[PTRSNE:%.+]] = icmp ne i64 [[NORM]], 0
+// CK2-DAG: [[PTRSNE:%.+]] = icmp ne i8* [[BPTR]], [[BEGIN]]
 // CK2-DAG: [[PTRANDOBJ:%.+]] = and i64 [[TYPE]], 16
 // CK2-DAG: [[ISPTRANDOBJ:%.+]] = icmp ne i64 [[PTRANDOBJ]], 0
 // CK2-DAG: [[CMPA:%.+]] = and i1 [[PTRSNE]], [[ISPTRANDOBJ]]
@@ -999,11 +987,7 @@ class C {
 // CK4-DAG: [[PTRBEGIN:%.+]] = bitcast i8* [[BEGIN]] to %class.C*
 // CK4-DAG: [[PTREND:%.+]] = getelementptr %class.C, %class.C* [[PTRBEGIN]], 
i64 [[SIZE]]
 // CK4-DAG: [[ISARRAY:%.+]] = icmp sgt i64 [[SIZE]], 1
-// CK4-DAG: [[BPTRI:%.+]] = ptrtoint i8* [[BPTR]] to i64
-// CK4-DAG: [[PTRI:%.+]] = ptrtoint i8* [[BEGIN]] to i64
-// CK4-DAG: [[DIF:%.+]] = sub i64 [[BPTRI]], [[PTRI]]
-// CK4-DAG: [[NORM:%.+]] = sdiv exact i64 [[DIF]], ptrtoint (i8* getelementptr 
(i8, i8* null, i32 1) to i64)
-// CK4-DAG: [[PTRSNE:%.+]] = icmp ne i64 [[NORM]], 0
+// CK4-DAG: [[PTRSNE:%.+]] = icmp ne i8* [[BPTR]], [[BEGIN]]
 // CK4-DAG: [[PTRANDOBJ:%.+]] = and i64 [[TYPE]], 16
 // CK4-DAG: [[ISPTRANDOBJ:%.+]] = icmp ne i64 [[PTRANDOBJ]], 0
 // CK4-DAG: [[CMPA:%.+]] = and i1 [[PTRSNE]], [[ISPTRANDOBJ]]



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

[PATCH] D118016: [clang-tidy] Change code of SignalHandlerCheck (NFC).

2022-01-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 402832.
balazske added a comment.

Added tests to check more specific behavior.
Removed AST matcher of TU.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118016

Files:
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
@@ -51,6 +51,37 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
+void test_false_condition(int) {
+  if (0)
+printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+}
+
+void test_multiple_calls(int) {
+  f_extern();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  f_extern();
+  // first 'f_extern' call found only
+}
+
+void f_recursive();
+
+void test_recursive(int) {
+  f_recursive();
+  printf("");
+  // first 'printf' call (in other function) found only
+}
+
+void f_recursive() {
+  f_extern();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  printf("");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  f_recursive(2);
+}
+
 void test() {
   signal(SIGINT, handler_abort);
   signal(SIGINT, handler_signal);
@@ -66,4 +97,8 @@
 
   signal(SIGINT, SIG_IGN);
   signal(SIGINT, SIG_DFL);
+
+  signal(SIGINT, test_false_condition);
+  signal(SIGINT, test_multiple_calls);
+  signal(SIGINT, test_recursive);
 }
Index: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNALHANDLERCHECK_H
 
 #include "../ClangTidyCheck.h"
+#include "clang/Analysis/CallGraph.h"
 #include "llvm/ADT/StringSet.h"
 
 namespace clang {
@@ -31,9 +32,12 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  bool isFunctionAsyncSafe(const FunctionDecl *FD) const;
+  bool isSystemCallAsyncSafe(const FunctionDecl *FD) const;
   void reportBug(const FunctionDecl *CalledFunction, const Expr *CallOrRef,
  const CallExpr *SignalCall, const FunctionDecl *HandlerDecl);
-  bool isSystemCallAllowed(const FunctionDecl *FD) const;
+
+  CallGraph CG;
 
   AsyncSafeFunctionSetType AsyncSafeFunctionSet;
   llvm::StringSet<> &ConformingFunctions;
Index: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
@@ -7,15 +7,9 @@
 //===--===//
 
 #include "SignalHandlerCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Analysis/CallGraph.h"
-#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/DepthFirstIterator.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
-#include 
-#include 
 
 using namespace clang::ast_matchers;
 
@@ -42,7 +36,9 @@
 
 namespace bugprone {
 
-static bool isSystemCall(const FunctionDecl *FD) {
+namespace {
+
+bool isSystemCall(const FunctionDecl *FD) {
   // Find a possible redeclaration in system header.
   // FIXME: Looking at the canonical declaration is not the most exact way
   // to do this.
@@ -73,6 +69,22 @@
   FD->getCanonicalDecl()->getLocation());
 }
 
+/// Given a call graph node of a function and another one that is called from
+/// this function, get a CallExpr of the corresponding function call.
+/// It is unspecified which call is found if multiple calls exist, but the order
+/// should be deterministic (depend only on the AST).
+Expr *findCallExpr(const CallGraphNode *Caller

[clang] 91a0b46 - [OpenCL] Make read_write images optional for -fdeclare-opencl-builtins

2022-01-25 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-01-25T11:40:31Z
New Revision: 91a0b464a853821734db8b1c521df03f8e2e56e7

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

LOG: [OpenCL] Make read_write images optional for -fdeclare-opencl-builtins

Ensure any use of a `read_write` image is guarded behind the
`__opencl_c_read_write_images` feature macro.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Sema/OpenCLBuiltins.td
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 7485386c82346..4f63e7bbdcbba 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -68,6 +68,7 @@
 // For the SPIR and SPIR-V target all features are supported.
 #if defined(__SPIR__) || defined(__SPIRV__)
 #define __opencl_c_atomic_scope_all_devices 1
+#define __opencl_c_read_write_images 1
 #endif // defined(__SPIR__)
 #endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
 

diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 38debc5aa9fc5..df2f206041c10 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -80,11 +80,14 @@ def FuncExtKhrLocalInt32ExtendedAtomics  : 
FunctionExtension<"cl_khr_local_int32
 def FuncExtKhrInt64BaseAtomics   : 
FunctionExtension<"cl_khr_int64_base_atomics">;
 def FuncExtKhrInt64ExtendedAtomics   : 
FunctionExtension<"cl_khr_int64_extended_atomics">;
 def FuncExtKhrMipmapImage: 
FunctionExtension<"cl_khr_mipmap_image">;
+def FuncExtKhrMipmapImageReadWrite   : 
FunctionExtension<"cl_khr_mipmap_image __opencl_c_read_write_images">;
 def FuncExtKhrMipmapImageWrites  : 
FunctionExtension<"cl_khr_mipmap_image_writes">;
 def FuncExtKhrGlMsaaSharing  : 
FunctionExtension<"cl_khr_gl_msaa_sharing">;
+def FuncExtKhrGlMsaaSharingReadWrite : 
FunctionExtension<"cl_khr_gl_msaa_sharing __opencl_c_read_write_images">;
 
 def FuncExtOpenCLCPipes  : 
FunctionExtension<"__opencl_c_pipes">;
 def FuncExtOpenCLCWGCollectiveFunctions  : 
FunctionExtension<"__opencl_c_work_group_collective_functions">;
+def FuncExtOpenCLCReadWriteImages: 
FunctionExtension<"__opencl_c_read_write_images">;
 def FuncExtFloatAtomicsFp16GlobalLoadStore  : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_global_atomic_load_store">;
 def FuncExtFloatAtomicsFp16LocalLoadStore   : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_local_atomic_load_store">;
 def FuncExtFloatAtomicsFp16GenericLoadStore : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_global_atomic_load_store 
__opencl_c_ext_fp16_local_atomic_load_store">;
@@ -1390,30 +1393,35 @@ foreach coordTy = [Int, Float] in {
 }
 
 // --- Table 23: Sampler-less Read Functions ---
+multiclass ImageReadSamplerless {
+  foreach imgTy = [Image2d, Image1dArray] in {
+def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
+def : Builtin<"read_imagei", [VectorType, ImageType, 
VectorType], Attr.Pure>;
+def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
+  }
+  foreach imgTy = [Image3d, Image2dArray] in {
+def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
+def : Builtin<"read_imagei", [VectorType, ImageType, 
VectorType], Attr.Pure>;
+def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
+  }
+  foreach imgTy = [Image1d, Image1dBuffer] in {
+def : Builtin<"read_imagef", [VectorType, ImageType, Int], Attr.Pure>;
+def : Builtin<"read_imagei", [VectorType, ImageType, 
Int], Attr.Pure>;
+def : Builtin<"read_imageui", [VectorType, ImageType, Int], Attr.Pure>;
+  }
+  def : Builtin<"read_imagef", [Float, ImageType, 
VectorType], Attr.Pure>;
+  def : Builtin<"read_imagef", [Float, ImageType, 
VectorType], Attr.Pure>;
+}
+
 let MinVersion = CL12 in {
-  foreach aQual = ["RO", "RW"] in {
-foreach imgTy = [Image2d, Image1dArray] in {
-  def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
-}
-foreach imgTy = [Image3d, Image2dArray] in {
-  def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
-}
-foreach imgTy = [Image1d, Imag

[PATCH] D117899: [OpenCL] Make read_write images optional for -fdeclare-opencl-builtins

2022-01-25 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG91a0b464a853: [OpenCL] Make read_write images optional for 
-fdeclare-opencl-builtins (authored by svenvh).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117899

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Sema/OpenCLBuiltins.td
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -74,6 +74,7 @@
 #define cl_khr_subgroup_ballot 1
 #define cl_khr_subgroup_non_uniform_arithmetic 1
 #define cl_khr_subgroup_clustered_reduce 1
+#define __opencl_c_read_write_images 1
 #endif
 #endif
 
Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -80,11 +80,14 @@
 def FuncExtKhrInt64BaseAtomics   : FunctionExtension<"cl_khr_int64_base_atomics">;
 def FuncExtKhrInt64ExtendedAtomics   : FunctionExtension<"cl_khr_int64_extended_atomics">;
 def FuncExtKhrMipmapImage: FunctionExtension<"cl_khr_mipmap_image">;
+def FuncExtKhrMipmapImageReadWrite   : FunctionExtension<"cl_khr_mipmap_image __opencl_c_read_write_images">;
 def FuncExtKhrMipmapImageWrites  : FunctionExtension<"cl_khr_mipmap_image_writes">;
 def FuncExtKhrGlMsaaSharing  : FunctionExtension<"cl_khr_gl_msaa_sharing">;
+def FuncExtKhrGlMsaaSharingReadWrite : FunctionExtension<"cl_khr_gl_msaa_sharing __opencl_c_read_write_images">;
 
 def FuncExtOpenCLCPipes  : FunctionExtension<"__opencl_c_pipes">;
 def FuncExtOpenCLCWGCollectiveFunctions  : FunctionExtension<"__opencl_c_work_group_collective_functions">;
+def FuncExtOpenCLCReadWriteImages: FunctionExtension<"__opencl_c_read_write_images">;
 def FuncExtFloatAtomicsFp16GlobalLoadStore  : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_load_store">;
 def FuncExtFloatAtomicsFp16LocalLoadStore   : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_load_store">;
 def FuncExtFloatAtomicsFp16GenericLoadStore : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_load_store __opencl_c_ext_fp16_local_atomic_load_store">;
@@ -1390,30 +1393,35 @@
 }
 
 // --- Table 23: Sampler-less Read Functions ---
+multiclass ImageReadSamplerless {
+  foreach imgTy = [Image2d, Image1dArray] in {
+def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
+def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>;
+def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
+  }
+  foreach imgTy = [Image3d, Image2dArray] in {
+def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
+def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>;
+def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
+  }
+  foreach imgTy = [Image1d, Image1dBuffer] in {
+def : Builtin<"read_imagef", [VectorType, ImageType, Int], Attr.Pure>;
+def : Builtin<"read_imagei", [VectorType, ImageType, Int], Attr.Pure>;
+def : Builtin<"read_imageui", [VectorType, ImageType, Int], Attr.Pure>;
+  }
+  def : Builtin<"read_imagef", [Float, ImageType, VectorType], Attr.Pure>;
+  def : Builtin<"read_imagef", [Float, ImageType, VectorType], Attr.Pure>;
+}
+
 let MinVersion = CL12 in {
-  foreach aQual = ["RO", "RW"] in {
-foreach imgTy = [Image2d, Image1dArray] in {
-  def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
-}
-foreach imgTy = [Image3d, Image2dArray] in {
-  def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
-}
-foreach imgTy = [Image1d, Image1dBuffer] in {
-  def : Builtin<"read_imagef", [VectorType, ImageType, Int], Attr.Pure>;
-  def : Builtin<"read_imagei", [VectorType, ImageType, Int], Attr.Pure>;
-  def : Builtin<"read_imageui", [VectorType, ImageType, Int], Attr.Pure>;
-}
-def : Builtin<"read_imagef", [Float, ImageType, VectorType], Attr.Pure>;
-def : Builtin<"read_imagef", [Float, ImageType, VectorType], Attr.Pure>;
+  defm : ImageReadSamplerless<"RO">;
+  let Extension = FuncExtOpenCLCReadWriteImages in {
+defm : ImageReadSamplerless<"RW">;
   }
 }
 
 // --- Table 24: I

[PATCH] D107290: [RISCV] Add support for the vscale_range attribute

2022-01-25 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm added a comment.

Does this mean `RISCVTTIImpl::getMaxVScale()` can be removed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107290

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


[clang] 30d4a7e - [IRBuilder] Require explicit element type in CreatePtrDiff()

2022-01-25 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-01-25T12:43:57+01:00
New Revision: 30d4a7e2955356c69ae412bfe2de46b92a2202c1

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

LOG: [IRBuilder] Require explicit element type in CreatePtrDiff()

For opaque pointer compatibility, we cannot derive the element
type from the pointer type.

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/IR/Core.cpp
llvm/lib/IR/IRBuilder.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 233656b90095b..db1c3ca191ca2 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -840,7 +840,8 @@ void ReductionCodeGen::emitAggregateType(CodeGenFunction 
&CGF, unsigned N) {
   auto *ElemType = OrigAddresses[N].first.getAddress(CGF).getElementType();
   auto *ElemSizeOf = llvm::ConstantExpr::getSizeOf(ElemType);
   if (AsArraySection) {
-Size = CGF.Builder.CreatePtrDiff(OrigAddresses[N].second.getPointer(CGF),
+Size = CGF.Builder.CreatePtrDiff(ElemType,
+ OrigAddresses[N].second.getPointer(CGF),
  OrigAddresses[N].first.getPointer(CGF));
 Size = CGF.Builder.CreateNUWAdd(
 Size, llvm::ConstantInt::get(Size->getType(), /*V=*/1));
@@ -1006,7 +1007,8 @@ Address 
ReductionCodeGen::adjustPrivateAddress(CodeGenFunction &CGF, unsigned N,
 OriginalBaseLValue);
 Address SharedAddr = SharedAddresses[N].first.getAddress(CGF);
 llvm::Value *Adjustment = CGF.Builder.CreatePtrDiff(
-BaseLValue.getPointer(CGF), SharedAddr.getPointer());
+SharedAddr.getElementType(), BaseLValue.getPointer(CGF),
+SharedAddr.getPointer());
 llvm::Value *PrivatePointer =
 CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
 PrivateAddr.getPointer(), SharedAddr.getType());
@@ -8119,7 +8121,7 @@ class MappableExprsHandler {
   .getAddress(CGF);
 }
 Size = CGF.Builder.CreatePtrDiff(
-CGF.EmitCastToVoidPtr(ComponentLB.getPointer()),
+CGF.Int8Ty, 
CGF.EmitCastToVoidPtr(ComponentLB.getPointer()),
 CGF.EmitCastToVoidPtr(LB.getPointer()));
 break;
   }
@@ -8140,7 +8142,7 @@ class MappableExprsHandler {
   CombinedInfo.BasePointers.push_back(BP.getPointer());
   CombinedInfo.Pointers.push_back(LB.getPointer());
   Size = CGF.Builder.CreatePtrDiff(
-  CGF.Builder.CreateConstGEP(HB, 1).getPointer(),
+  CGF.Int8Ty, CGF.Builder.CreateConstGEP(HB, 1).getPointer(),
   CGF.EmitCastToVoidPtr(LB.getPointer()));
   CombinedInfo.Sizes.push_back(
   CGF.Builder.CreateIntCast(Size, CGF.Int64Ty, /*isSigned=*/true));
@@ -8966,7 +8968,7 @@ class MappableExprsHandler {
 CGF.Builder.CreateConstGEP1_32(HBAddr.getElementType(), HB, 
/*Idx0=*/1);
 llvm::Value *CLAddr = CGF.Builder.CreatePointerCast(LB, CGF.VoidPtrTy);
 llvm::Value *CHAddr = CGF.Builder.CreatePointerCast(HAddr, CGF.VoidPtrTy);
-llvm::Value *Diff = CGF.Builder.CreatePtrDiff(CHAddr, CLAddr);
+llvm::Value *Diff = CGF.Builder.CreatePtrDiff(CGF.Int8Ty, CHAddr, CLAddr);
 llvm::Value *Size = CGF.Builder.CreateIntCast(Diff, CGF.Int64Ty,
   /*isSigned=*/false);
 CombinedInfo.Sizes.push_back(Size);

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 7c8e4e6b52a08..e09ea5e01b1a9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1798,8 +1798,9 @@ static void shuffleAndStore(CodeGenFunction &CGF, Address 
SrcAddr,
   Ptr = Address(PhiSrc, Ptr.getAlignment());
   ElemPtr = Address(PhiDest, ElemPtr.getAlignment());
   llvm::Value *PtrDiff = Bld.CreatePtrDiff(
-  PtrEnd.getPointer(), Bld.CreatePointerBitCastOrAddrSpaceCast(
-   Ptr.getPointer(), CGF.VoidPtrTy));
+  CGF.Int8Ty, PtrEnd.getPointer(),
+  Bld.CreatePointerBitCastOrAddrSpaceCast(Ptr.getPointer(),
+  CGF.VoidPtrTy));
   Bld.CreateCondBr(Bld.CreateICmpSGT(PtrDiff, Bld.getInt64(IntSize - 1)),
ThenBB, ExitBB);
   CGF.EmitBlock(ThenBB);

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index 32c978f02a4d2..53f517480ca1c 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/incl

[PATCH] D118016: [clang-tidy] Change code of SignalHandlerCheck (NFC).

2022-01-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 2 inline comments as done.
balazske added a comment.

The `CallGraph` just scans for `FunctionDecl` and `CallExpr`, no check for 
unreachable code is there.




Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:131
+  if (const auto *TU = Result.Nodes.getNodeAs("TU")) {
+// Call graph must be populated with the entire TU at the begin.
+// (It is possible to add a single function but the functions called from 
it

njames93 wrote:
> aaron.ballman wrote:
> > Should we also assert that this matcher is triggered before any other 
> > matcher is matched?
> > 
> > Alternatively, instead of matching on the TU decl itself, would it make 
> > sense to walk the decl contexts up to the TU level on the first match?
> The nicest solution would be to change the OnStartOfTranslationUnit callback 
> to pass the ASTContext. That way checks which require setup code like this 
> don't need to register matchers.
> However this would be a breaking change.
Call graph is now populated at the first normal match, no need for the 
additional AST matcher.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118016

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


[PATCH] D117295: [clang][sema] Allow unnamed decls in C++20 module export{} blocks

2022-01-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:650-652
+if (S.getLangOpts().CPlusPlus2b) {
+  if (BlockStart.isInvalid())
+diagExportedUnnamedDecl(S, *UDK, D, BlockStart);

tbaeder wrote:
> ChuanqiXu wrote:
> > Should we add a cite to P1766R1 here?
> I wanted to do that, but I'm not 100% sure how. P1766R1 doesn't seem to 
> change any wording for this change. What exactly do I cite?
I am not sure about the standard method. But I guess it might not be bad to 
write something like:
```
// P1766R1 removed the rule that a declaration in an export block introduces at 
least one name. The rule for the single-declaration form of export is retained.
// FIXME: Cite for labels when it shows in the draft.
```

BTW, you could send a pull request or an issue at: 
https://github.com/cplusplus/draft to do the change. Since P1766R1 is adopted, 
so this change should be editorial.


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

https://reviews.llvm.org/D117295

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


[PATCH] D118119: [clang][dataflow] Add a transfer function for InitListExpr

2022-01-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:421
+QualType Type = S->getType();
+assert(Type->isStructureOrClassType());
+

Why do we expect this assertion to be true? Aren't `InitListExpr`s also used to 
initialize arrays?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118119

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


[PATCH] D118119: [clang][dataflow] Add a transfer function for InitListExpr

2022-01-25 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 402840.
sgatev marked an inline comment as done.
sgatev added a comment.

Address reviewers' comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118119

Files:
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1865,4 +1865,91 @@
   });
 }
 
+TEST_F(TransferTest, AggregateInitialization) {
+  std::string BracesCode = R"(
+struct A {
+  int Foo;
+};
+
+struct B {
+  int Bar;
+  A Baz;
+  int Qux;
+};
+
+void target(int BarArg, int FooArg, int QuxArg) {
+  B Quux{BarArg, {FooArg}, QuxArg};
+  /*[[p]]*/
+}
+  )";
+  std::string BraceEllisionCode = R"(
+struct A {
+  int Foo;
+};
+
+struct B {
+  int Bar;
+  A Baz;
+  int Qux;
+};
+
+void target(int BarArg, int FooArg, int QuxArg) {
+  B Quux = {BarArg, FooArg, QuxArg};
+  /*[[p]]*/
+}
+  )";
+  for (const std::string &Code : {BracesCode, BraceEllisionCode}) {
+runDataflow(
+Code, [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+  ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+  const Environment &Env = Results[0].second.Env;
+
+  const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+  ASSERT_THAT(FooDecl, NotNull());
+
+  const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+  ASSERT_THAT(BarDecl, NotNull());
+
+  const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+  ASSERT_THAT(BazDecl, NotNull());
+
+  const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+  ASSERT_THAT(QuxDecl, NotNull());
+
+  const ValueDecl *FooArgDecl = findValueDecl(ASTCtx, "FooArg");
+  ASSERT_THAT(FooArgDecl, NotNull());
+
+  const ValueDecl *BarArgDecl = findValueDecl(ASTCtx, "BarArg");
+  ASSERT_THAT(BarArgDecl, NotNull());
+
+  const ValueDecl *QuxArgDecl = findValueDecl(ASTCtx, "QuxArg");
+  ASSERT_THAT(QuxArgDecl, NotNull());
+
+  const ValueDecl *QuuxDecl = findValueDecl(ASTCtx, "Quux");
+  ASSERT_THAT(QuuxDecl, NotNull());
+
+  const auto *FooArgVal =
+  cast(Env.getValue(*FooArgDecl, SkipPast::None));
+  const auto *BarArgVal =
+  cast(Env.getValue(*BarArgDecl, SkipPast::None));
+  const auto *QuxArgVal =
+  cast(Env.getValue(*QuxArgDecl, SkipPast::None));
+
+  const auto *QuuxVal =
+  cast(Env.getValue(*QuuxDecl, SkipPast::None));
+  ASSERT_THAT(QuuxVal, NotNull());
+
+  const auto *BazVal = cast(&QuuxVal->getChild(*BazDecl));
+  ASSERT_THAT(BazVal, NotNull());
+
+  EXPECT_EQ(&QuuxVal->getChild(*BarDecl), BarArgVal);
+  EXPECT_EQ(&BazVal->getChild(*FooDecl), FooArgVal);
+  EXPECT_EQ(&QuuxVal->getChild(*QuxDecl), QuxArgVal);
+});
+  }
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -22,9 +22,11 @@
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Basic/OperatorKinds.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace dataflow {
@@ -414,6 +416,33 @@
   Env.setValue(Loc, *Val);
   }
 
+  void VisitInitListExpr(const InitListExpr *S) {
+QualType Type = S->getType();
+
+auto &Loc = Env.createStorageLocation(*S);
+Env.setStorageLocation(*S, Loc);
+
+auto *Val = Env.createValue(Type);
+if (Val == nullptr)
+  return;
+
+Env.setValue(Loc, *Val);
+
+if (Type->isStructureOrClassType()) {
+  for (auto IT : llvm::zip(Type->getAsRecordDecl()->fields(), S->inits())) {
+const FieldDecl *Field = std::get<0>(IT);
+assert(Field != nullptr);
+
+const Expr *Init = std::get<1>(IT);
+assert(Init != nullptr);
+
+if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
+  cast(Val)->setChild(*Field, *InitVal);
+  }
+}
+// FIXME: Implement array initialization.
+  }
+
   // FIXME: Add support for:
   // - CXXBoolLiteralExpr
 
Index: clang/include/clang/Analysis/FlowSensitive/Value.h
===
--- clang/include/clang/Analysis/FlowSens

[PATCH] D118119: [clang][dataflow] Add a transfer function for InitListExpr

2022-01-25 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:421
+QualType Type = S->getType();
+assert(Type->isStructureOrClassType());
+

xazax.hun wrote:
> Why do we expect this assertion to be true? Aren't `InitListExpr`s also used 
> to initialize arrays?
Yes, but I don't plan to add support for array initialization in this patch so 
let me restructure the code and add a FIXME.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118119

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


[PATCH] D114483: [SYCL] Add support for sycl_special_class attribute

2022-01-25 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 402850.
zahiraam marked an inline comment as done.

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

https://reviews.llvm.org/D114483

Files:
  clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaSYCL/special-class-attribute-on-non-sycl.cpp
  clang/test/SemaSYCL/special-class-attribute.cpp

Index: clang/test/SemaSYCL/special-class-attribute.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/special-class-attribute.cpp
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
+
+// No diagnostics
+class [[clang::sycl_special_class]] class1 {
+  void __init(){};
+};
+class __attribute__((sycl_special_class)) class2 {
+  void __init(){};
+};
+
+class class3;
+class [[clang::sycl_special_class]] class3 {
+  void __init(){};
+};
+
+class class4;
+class __attribute__((sycl_special_class)) class4 {
+  void __init(){};
+};
+
+struct [[clang::sycl_special_class]] struct1 {
+  void __init(){};
+};
+struct __attribute__((sycl_special_class)) struct2 {
+  void __init(){};
+};
+
+class __attribute__((sycl_special_class)) class5;
+class class5 {
+  void __init(){};
+};
+
+// Must have one and only one __init method defined
+class __attribute__((sycl_special_class)) class6 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  class6() {}
+};
+class [[clang::sycl_special_class]] class7 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+};
+
+class [[clang::sycl_special_class]] class8 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+  int func() {};
+  void __init(int a){};
+};
+
+struct __attribute__((sycl_special_class)) struct3;
+struct struct3 {}; // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+
+// Only classes
+[[clang::sycl_special_class]] int var1 = 0;   // expected-warning {{'sycl_special_class' attribute only applies to classes}}
+__attribute__((sycl_special_class)) int var2 = 0; // expected-warning {{'sycl_special_class' attribute only applies to classes}}
+
+[[clang::sycl_special_class]] void foo1();   // expected-warning {{'sycl_special_class' attribute only applies to classes}}
+__attribute__((sycl_special_class)) void foo2(); // expected-warning {{'sycl_special_class' attribute only applies to classes}}
+
+// Attribute takes no arguments
+class [[clang::sycl_special_class(1)]] class9{}; // expected-error {{'sycl_special_class' attribute takes no arguments}}
+class __attribute__((sycl_special_class(1))) class10 {}; // expected-error {{'sycl_special_class' attribute takes no arguments}}
+
+// __init method must be defined inside the CXXRecordDecl.
+class [[clang::sycl_special_class]] class11 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+};
+void class11::__init(){};
+
+class __attribute__((sycl_special_class)) class12 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+};
+void class12::__init(){};
+
+struct [[clang::sycl_special_class]] struct4 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+};
+void struct4::__init(){};
+
+struct __attribute__((sycl_special_class)) struct5 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+};
+void struct5::__init(){};
Index: clang/test/SemaSYCL/special-class-attribute-on-non-sycl.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/special-class-attribute-on-non-sycl.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -x c++ %s
+
+#ifndef __SYCL_DEVICE_ONLY__
+// expected-warning@+5 {{'sycl_special_class' attribute ignored}}
+#else
+// expected-no-diagnostics
+#endif
+
+class __attribute__((sycl_special_class)) special_class {
+  void __init(){};
+};
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribut

[PATCH] D116085: [clang-tidy] Performance improvements for NOLINTBEGIN/END blocks

2022-01-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.

Looks great!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116085

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


[clang-tools-extra] c0e3c89 - [NFC][clangd] cleaning up llvm-qualified-auto

2022-01-25 Thread Christian Kühnel via cfe-commits

Author: Christian Kühnel
Date: 2022-01-25T13:26:33Z
New Revision: c0e3c893aa095c78156900ef11f68042aff83839

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

LOG: [NFC][clangd] cleaning up llvm-qualified-auto

This is a cleanup of all llvm-qualified-auto findings.
This patch was created by automatically applying the fixes from
clang-tidy.

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

Added: 


Modified: 
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/ExpectedTypes.cpp
clang-tools-extra/clangd/FindSymbols.cpp
clang-tools-extra/clangd/HeaderSourceSwitch.cpp
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/index/IndexAction.cpp
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/clangd/index/dex/Iterator.cpp
clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp
clang-tools-extra/clangd/unittests/ClangdTests.cpp
clang-tools-extra/clangd/unittests/FileIndexTests.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/AST.cpp 
b/clang-tools-extra/clangd/AST.cpp
index 53b55e1579ec4..b970325098c65 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -456,7 +456,7 @@ class DeducedTypeVisitor : public 
RecursiveASTVisitor {
 const AutoType *AT = D->getReturnType()->getContainedAutoType();
 if (AT && !AT->getDeducedType().isNull()) {
   DeducedType = AT->getDeducedType();
-} else if (auto DT = dyn_cast(D->getReturnType())) {
+} else if (auto *DT = dyn_cast(D->getReturnType())) {
   // auto in a trailing return type just points to a DecltypeType and
   // getContainedAutoType does not unwrap it.
   if (!DT->getUnderlyingType().isNull())

diff  --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index d9165599fb9ab..43f35232270a3 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -453,7 +453,7 @@ struct CodeCompletionBuilder {
   template 
   const std::string *onlyValue() const {
 auto B = Bundled.begin(), E = Bundled.end();
-for (auto I = B + 1; I != E; ++I)
+for (auto *I = B + 1; I != E; ++I)
   if (I->*Member != B->*Member)
 return nullptr;
 return &(B->*Member);
@@ -461,7 +461,7 @@ struct CodeCompletionBuilder {
 
   template  const bool *onlyValue() const {
 auto B = Bundled.begin(), E = Bundled.end();
-for (auto I = B + 1; I != E; ++I)
+for (auto *I = B + 1; I != E; ++I)
   if (I->*Member != B->*Member)
 return nullptr;
 return &(B->*Member);

diff  --git a/clang-tools-extra/clangd/ExpectedTypes.cpp 
b/clang-tools-extra/clangd/ExpectedTypes.cpp
index e0a4e472f3496..01a08c8589c18 100644
--- a/clang-tools-extra/clangd/ExpectedTypes.cpp
+++ b/clang-tools-extra/clangd/ExpectedTypes.cpp
@@ -53,7 +53,7 @@ typeOfCompletion(const CodeCompletionResult &R) {
   auto T = VD->getType();
   if (T.isNull())
 return llvm::None;
-  if (auto FuncT = T->getAs()) {
+  if (auto *FuncT = T->getAs()) {
 // Functions are a special case. They are completed as 'foo()' and we want
 // to match their return type rather than the function type itself.
 // FIXME(ibiryukov): in some cases, we might want to avoid completing `()`

diff  --git a/clang-tools-extra/clangd/FindSymbols.cpp 
b/clang-tools-extra/clangd/FindSymbols.cpp
index edbeeed9e2ca6..75961d3a6ea17 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -483,7 +483,7 @@ class DocumentOutline {
 if (!llvm::isa(D))
   return VisitKind::No;
 
-if (auto Func = llvm::dyn_cast(D)) {
+if (auto *Func = llvm::dyn_cast(D)) {
   // Some functions are implicit template instantiations, those should be
   // ignored.
   if (auto *Info = Func->getTemplateSpecializationInfo()) {

diff  --git a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp 
b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
index e3e2ab3ea8694..ed86c2eb0d12d 100644
--- a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
+++ b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
@@ -25,13 +25,13 @@ llvm::Optional getCorrespondingHeaderOrSource(
   llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile);
 
   // Lookup in a list of known extensi

[PATCH] D113898: [NFC][clangd] cleaning up llvm-qualified-auto

2022-01-25 Thread Christian Kühnel via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0e3c893aa09: [NFC][clangd] cleaning up llvm-qualified-auto 
(authored by kuhnel).

Changed prior to commit:
  https://reviews.llvm.org/D113898?vs=393894&id=402869#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113898

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/ExpectedTypes.cpp
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/HeaderSourceSwitch.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/dex/Iterator.cpp
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
  clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp
@@ -192,7 +192,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformNestedNamespaces) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -220,7 +220,7 @@
   b::c::aux();
   a::b::c::aux();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   void bar();
   namespace b {
@@ -252,7 +252,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformUsings) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo();
@@ -263,7 +263,7 @@
   using c::aux;
   namespace d = c;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a { namespace b { namespace c { void aux(); } } }
 
 void foo(){
@@ -278,7 +278,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDecls) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 void foo();
 void f^oo() {
   class Foo {
@@ -293,7 +293,7 @@
   enum class EnClass { Zero, One };
   EnClass y = EnClass::Zero;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 void foo(){
   class Foo {
   public:
@@ -312,7 +312,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTemplDecls) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -329,7 +329,7 @@
   bar>.bar();
   aux>();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -350,7 +350,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformMembers) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 class Foo {
   void foo();
 };
@@ -358,7 +358,7 @@
 void Foo::f^oo() {
   return;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 class Foo {
   void foo(){
   return;
@@ -395,7 +395,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDependentTypes) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -409,7 +409,7 @@
   Bar B;
   Bar> q;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {};
 }
@@ -511,7 +511,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformTypeLocs) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -528,7 +528,7 @@
   Foo foo;
   a::Bar>::Baz> q;
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -549,7 +549,7 @@
 }
 
 TEST_F(DefineInlineTest, TransformDeclRefs) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -575,7 +575,7 @@
   bar();
   a::test();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace a {
   template  class Bar {
   public:
@@ -605,12 +605,12 @@
 }
 
 TEST_F(DefineInlineTest, StaticMembers) {
-  auto Test = R"cpp(
+  auto *Test = R"cpp(
 namespace ns { class X { static void foo(); void bar(); }; }
 void ns::X::b^ar() {
   foo();
 })cpp";
-  auto Expected = R"cpp(
+  auto *Expected = R"cpp(
 namespace ns

[PATCH] D115640: [OpenCL] Add support of __opencl_c_device_enqueue feature macro.

2022-01-25 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 402873.
azabaznov added a comment.

Add expected-no-diagnostics, fix misprint in test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115640

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenCLOptions.h
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Headers/opencl-c.h
  clang/lib/Sema/Sema.cpp
  clang/test/CodeGenOpenCL/address-spaces-mangling.cl
  clang/test/CodeGenOpenCL/address-spaces.cl
  clang/test/CodeGenOpenCL/blocks.cl
  clang/test/CodeGenOpenCL/pipe_types.cl
  clang/test/CodeGenOpenCL/pipe_types_mangling.cl
  clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
  clang/test/Frontend/opencl.cl
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/invalid-block.cl
  clang/test/SemaOpenCL/invalid-device-enqueue-types-cl3.0.cl
  clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl
  clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
  clang/test/SemaOpenCL/storageclass.cl
  clang/test/SemaOpenCLCXX/remove-address-space.clcpp

Index: clang/test/SemaOpenCLCXX/remove-address-space.clcpp
===
--- clang/test/SemaOpenCLCXX/remove-address-space.clcpp
+++ clang/test/SemaOpenCLCXX/remove-address-space.clcpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -cl-std=clc++1.0 -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify
 // RUN: %clang_cc1 %s -cl-std=clc++2021 -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify
-// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify
+// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=-__opencl_c_device_enqueue,-__opencl_c_generic_address_space,-__opencl_c_pipes -triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify
 
 // expected-no-diagnostics
 
Index: clang/test/SemaOpenCL/storageclass.cl
===
--- clang/test/SemaOpenCL/storageclass.cl
+++ clang/test/SemaOpenCL/storageclass.cl
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-all
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-all,+__opencl_c_program_scope_global_variables
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-all,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 -cl-ext=-all,+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-all
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-all,+__opencl_c_program_scope_global_variables
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-all,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++2021 -cl-ext=-all,+__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
 static constant int G1 = 0;
 constant int G2 = 0;
 
Index: clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl

[PATCH] D118016: [clang-tidy] Change code of SignalHandlerCheck (NFC).

2022-01-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from a commenting nit. Thanks!




Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:136
+  if (CG.size() <= 1) {
+// Call graph must be populated with the entire TU at the begin.
+// (It is possible to add a single function but the functions called from 
it




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118016

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


[PATCH] D115640: [OpenCL] Add support of __opencl_c_device_enqueue feature macro.

2022-01-25 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov marked an inline comment as done.
azabaznov added inline comments.



Comment at: clang/test/SemaOpenCL/storageclass.cl:2
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 
-cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 
-cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 
-cl-ext=-__opencl_c_program_scope_global_variables,+__opencl_c_generic_address_space
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 
-cl-ext=-__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes,-__opencl_c_device_enqueue
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0 
-cl-ext=+__opencl_c_program_scope_global_variables,-__opencl_c_generic_address_space,-__opencl_c_pipes,-__opencl_c_device_enqueue

Anastasia wrote:
> azabaznov wrote:
> > Anastasia wrote:
> > > Anastasia wrote:
> > > > These lines are getting a bit longer. Do we actually need to set 
> > > > `-__opencl_c_device_enqueue` for this test? Same for some other tests...
> > > ping
> > Yeah, we need that here because we are turning off generic AS and PSV in 
> > this test. Note that `__opencl_c_device_enqueue` is turned off with 
> > `-cl-ext=-all`.
> since this test doesn't check anything for `__opencl_c_device_enqueue` why do 
> we need to switch this off explicitly?
In this test PSV and generic address space features are alternately turned off. 
Since they are required to by device enqueue, it's required to turn device 
enqueue as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115640

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


[PATCH] D118034: [C++20] [Modules] Don't complain about duplicated default template argument across modules

2022-01-25 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:2681-2697
+// Variable used to not diagnose redundant default arguments
+// from modules.
+//
+// [basic.def.odr]/13:
+// There can be more than one definition of a
+// ...
+// default template argument

while I do approve of good commenting, this is a little wordy and I think 
misleading.  It is only from global module fragments that you can get duplicate 
declarations and those must match default parameters (I think).  so perhaps 
'IsGlobalModule'?  or somehting like that.

Perhaps all of this comment shoould be at the point of checking?  After all the 
preceding comment mentions 'variables used to ...'?




Comment at: clang/lib/Sema/SemaTemplate.cpp:2852
 
-if (RedundantDefaultArg) {
+if (RedundantDefaultArg && !IsOldParamFromModule) {
   // C++ [temp.param]p12:

Yes, I think this is a better place for the comment.  If there are duplicates 
we need to check they are the same -- pedantically the same tokens, but at 
least AST equivalence?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118034

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


[PATCH] D115610: [C++20] [Modules] Don't create multiple global module fragment

2022-01-25 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added a comment.

Seems good to me, @iains you've been looking at this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115610

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


[PATCH] D117295: [clang][sema] Allow unnamed decls in C++20 module export{} blocks

2022-01-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 402874.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D117295

Files:
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/cxx20-export.cpp


Index: clang/test/Modules/cxx20-export.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-export.cpp
@@ -0,0 +1,23 @@
+
+// RUN: %clang_cc1 -std=c++2b -verify %s
+export module testmodule;
+
+export static_assert(true); // expected-error {{static_assert declaration 
cannot be exported}}
+export; // expected-error {{empty declaration cannot be 
exported}}
+
+namespace A {};
+
+export {
+#define STR(x) constexpr char x[] = #x;
+  STR(foo);
+#undef STR
+
+  static_assert(true);
+
+  template  struct X { T t; };
+  template  X(T) -> X;
+
+  ; // Empty declaration
+
+  using namespace A;
+}
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -615,12 +615,10 @@
   return llvm::None;
 }
 
-unsigned getUnnamedDeclDiag(UnnamedDeclKind UDK, bool InBlock) {
+static unsigned getUnnamedDeclDiag(UnnamedDeclKind UDK, bool InBlock) {
   switch (UDK) {
   case UnnamedDeclKind::Empty:
   case UnnamedDeclKind::StaticAssert:
-// Allow empty-declarations and static_asserts in an export block as an
-// extension.
 return InBlock ? diag::ext_export_no_name_block : diag::err_export_no_name;
 
   case UnnamedDeclKind::UsingDirective:
@@ -648,10 +646,19 @@
 
 /// Check that it's valid to export \p D.
 static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
-  // C++2a [module.interface]p3:
-  //   An exported declaration shall declare at least one name
-  if (auto UDK = getUnnamedDeclKind(D))
-diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+  if (auto UDK = getUnnamedDeclKind(D)) {
+if (S.getLangOpts().CPlusPlus2b) {
+  // P1766R1 allows unnamed declarations in export{} blocks, but not in
+  // the single-declaration form of export.
+  // FIXME: Cite the standard once P1766R1 is reflected in the wording
+  if (BlockStart.isInvalid())
+diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+} else {
+  // C++2a [module.interface]p3:
+  //   An exported declaration shall declare at least one name
+  diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+}
+  }
 
   //   [...] shall not declare a name with internal linkage.
   if (auto *ND = dyn_cast(D)) {


Index: clang/test/Modules/cxx20-export.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-export.cpp
@@ -0,0 +1,23 @@
+
+// RUN: %clang_cc1 -std=c++2b -verify %s
+export module testmodule;
+
+export static_assert(true); // expected-error {{static_assert declaration cannot be exported}}
+export; // expected-error {{empty declaration cannot be exported}}
+
+namespace A {};
+
+export {
+#define STR(x) constexpr char x[] = #x;
+  STR(foo);
+#undef STR
+
+  static_assert(true);
+
+  template  struct X { T t; };
+  template  X(T) -> X;
+
+  ; // Empty declaration
+
+  using namespace A;
+}
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -615,12 +615,10 @@
   return llvm::None;
 }
 
-unsigned getUnnamedDeclDiag(UnnamedDeclKind UDK, bool InBlock) {
+static unsigned getUnnamedDeclDiag(UnnamedDeclKind UDK, bool InBlock) {
   switch (UDK) {
   case UnnamedDeclKind::Empty:
   case UnnamedDeclKind::StaticAssert:
-// Allow empty-declarations and static_asserts in an export block as an
-// extension.
 return InBlock ? diag::ext_export_no_name_block : diag::err_export_no_name;
 
   case UnnamedDeclKind::UsingDirective:
@@ -648,10 +646,19 @@
 
 /// Check that it's valid to export \p D.
 static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
-  // C++2a [module.interface]p3:
-  //   An exported declaration shall declare at least one name
-  if (auto UDK = getUnnamedDeclKind(D))
-diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+  if (auto UDK = getUnnamedDeclKind(D)) {
+if (S.getLangOpts().CPlusPlus2b) {
+  // P1766R1 allows unnamed declarations in export{} blocks, but not in
+  // the single-declaration form of export.
+  // FIXME: Cite the standard once P1766R1 is reflected in the wording
+  if (BlockStart.isInvalid())
+diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+} else {
+  // C++2a [module.interface]p3:
+  //   An exported declaration shall declare at least one name
+  diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+}
+  }
 
   //   [...] shall not declare a name with internal linkage.
   if (auto *ND = dyn_cast(D)) {
__

[PATCH] D117295: [clang][sema] Allow unnamed decls in C++20 module export{} blocks

2022-01-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 2 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:650-652
+if (S.getLangOpts().CPlusPlus2b) {
+  if (BlockStart.isInvalid())
+diagExportedUnnamedDecl(S, *UDK, D, BlockStart);

ChuanqiXu wrote:
> tbaeder wrote:
> > ChuanqiXu wrote:
> > > Should we add a cite to P1766R1 here?
> > I wanted to do that, but I'm not 100% sure how. P1766R1 doesn't seem to 
> > change any wording for this change. What exactly do I cite?
> I am not sure about the standard method. But I guess it might not be bad to 
> write something like:
> ```
> // P1766R1 removed the rule that a declaration in an export block introduces 
> at least one name. The rule for the single-declaration form of export is 
> retained.
> // FIXME: Cite for labels when it shows in the draft.
> ```
> 
> BTW, you could send a pull request or an issue at: 
> https://github.com/cplusplus/draft to do the change. Since P1766R1 is 
> adopted, so this change should be editorial.
Thanks, I added a comment and opened 
https://github.com/cplusplus/draft/issues/5237


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

https://reviews.llvm.org/D117295

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


[PATCH] D118120: [C++20] [Modules] Only check decls under namespace scope in CheckRedeclarationExported

2022-01-25 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan accepted this revision.
urnathan added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/SemaDecl.cpp:1643-1648
+  if (!New->getLexicalDeclContext()
+   ->getNonTransparentContext()
+   ->isFileContext() ||
+  !Old->getLexicalDeclContext()
+   ->getNonTransparentContext()
+   ->isFileContext())

ChuanqiXu wrote:
> This is formatted by clang-format, the original may be too long:
> ```
> if 
> (!New->getLexicalDeclContext()->getNonTransparentContext()->isFileContext() ||
> ...
> ```
I like continuation lines where the operator is on the start of the new line 
rather than the end of the old one :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118120

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


[PATCH] D115610: [C++20] [Modules] Don't create multiple global module fragment

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



Comment at: clang/include/clang/Sema/Sema.h:2217
+  /// The gloabl module fragment of the current tranlation unit.
+  clang::Module *GlobalModuleFragmentCache = nullptr;
 

Typos in "gloabl" and "tranlation" in the comment. Any reason to call this a 
"cache"? This was confusing to me at first.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115610

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


[PATCH] D118016: [clang-tidy] Change code of SignalHandlerCheck (NFC).

2022-01-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 402881.
balazske marked an inline comment as done.
balazske added a comment.

Corrected a comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118016

Files:
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
@@ -51,6 +51,37 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
+void test_false_condition(int) {
+  if (0)
+printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+}
+
+void test_multiple_calls(int) {
+  f_extern();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  f_extern();
+  // first 'f_extern' call found only
+}
+
+void f_recursive();
+
+void test_recursive(int) {
+  f_recursive();
+  printf("");
+  // first 'printf' call (in other function) found only
+}
+
+void f_recursive() {
+  f_extern();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  printf("");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  f_recursive(2);
+}
+
 void test() {
   signal(SIGINT, handler_abort);
   signal(SIGINT, handler_signal);
@@ -66,4 +97,8 @@
 
   signal(SIGINT, SIG_IGN);
   signal(SIGINT, SIG_DFL);
+
+  signal(SIGINT, test_false_condition);
+  signal(SIGINT, test_multiple_calls);
+  signal(SIGINT, test_recursive);
 }
Index: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNALHANDLERCHECK_H
 
 #include "../ClangTidyCheck.h"
+#include "clang/Analysis/CallGraph.h"
 #include "llvm/ADT/StringSet.h"
 
 namespace clang {
@@ -31,9 +32,12 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  bool isFunctionAsyncSafe(const FunctionDecl *FD) const;
+  bool isSystemCallAsyncSafe(const FunctionDecl *FD) const;
   void reportBug(const FunctionDecl *CalledFunction, const Expr *CallOrRef,
  const CallExpr *SignalCall, const FunctionDecl *HandlerDecl);
-  bool isSystemCallAllowed(const FunctionDecl *FD) const;
+
+  CallGraph CG;
 
   AsyncSafeFunctionSetType AsyncSafeFunctionSet;
   llvm::StringSet<> &ConformingFunctions;
Index: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
@@ -7,15 +7,9 @@
 //===--===//
 
 #include "SignalHandlerCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Analysis/CallGraph.h"
-#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/DepthFirstIterator.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
-#include 
-#include 
 
 using namespace clang::ast_matchers;
 
@@ -42,7 +36,9 @@
 
 namespace bugprone {
 
-static bool isSystemCall(const FunctionDecl *FD) {
+namespace {
+
+bool isSystemCall(const FunctionDecl *FD) {
   // Find a possible redeclaration in system header.
   // FIXME: Looking at the canonical declaration is not the most exact way
   // to do this.
@@ -73,6 +69,22 @@
   FD->getCanonicalDecl()->getLocation());
 }
 
+/// Given a call graph node of a function and another one that is called from
+/// this function, get a CallExpr of the corresponding function call.
+/// It is unspecified which call is found if multiple calls exist, but the order
+/// should be deterministic (depend only on the AST).
+Expr *findCallExpr(const CallGraphNode *Caller, const 

[PATCH] D118044: [ARM] Undeprecate complex IT blocks

2022-01-25 Thread Mark Murray via Phabricator via cfe-commits
MarkMurrayARM added a comment.

In D118044#3266521 , @DavidSpickett 
wrote:

> Please define what "complex" is, in the commit message and (if it doesn't 
> make the description a whole paragraph) the command line help.
>
> Given that we're flipping a default for v8 thumb targets does this warrant a 
> release note?

I've updated the commit message.

I'll look at the release notes next.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118044

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


[PATCH] D117753: [AArch64] Support for memset tagged intrinsic

2022-01-25 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 marked an inline comment as done.
tyb0807 added inline comments.



Comment at: clang/test/CodeGen/aarch64-mops.c:3
+
+// RUN: %clang_cc1 -triple aarch64-arm-unknown-eabi -target-feature +mops -S 
-emit-llvm -o - %s  | FileCheck %s
+

SjoerdMeijer wrote:
> I forgot if we add negative tests for these things, i.e. check if we error if 
> we don't have `+mops` or `__ARM_FEATURE_MOPS` set? I guess so?
Currently this only tests if the support for memset tagged intrinsic is in 
clang, how to enable the memset tagged intrinsic is implemented (and tested) in 
a separate patch (https://reviews.llvm.org/D116160). Note how we set 
`__ARM_FEATURE_MOPS` manually in line 5.

This test will thus be updated with negative tests in 
https://reviews.llvm.org/D116160


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117753

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


[PATCH] D117137: [Driver] Add CUDA support for --offload param

2022-01-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D117137#3268548 , @linjamaki wrote:

> SPIR-V target requires that the OS and the environment type is unknown (see 
> TargetInfo::AllocateTarget and BaseSPIRTargetInfo). The clang would fail to 
> create a SPIR-V target if there is an OS or environment component in the 
> target string known by the Triple. This could lead to a misleading error 
> message.

Does that mean only "spirv{64}-unkown-unkown" is acceptable, or 
"spirv{64}-amd-unkown-unknown" is also acceptable?

One usage of vendor component in spirv triple is that it may be used to choose 
toolchain if there are multiple toolchains supporting spirv.

@mkuper What are intended use of OS and environment components of spirv triple?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117137

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


[PATCH] D114483: [SYCL] Add support for sycl_special_class attribute

2022-01-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM aside from some small nits.




Comment at: clang/include/clang/Basic/AttrDocs.td:415
+  let Content = [{
+SYCL defines some special classes (accessor, sampler and stream) which require
+specific handling during the generation of the SPIR entry point.

I love the Oxford comma and am not afraid to admit it in public. :-D



Comment at: clang/include/clang/Basic/AttrDocs.td:422
+``__finalize`` method (the ``__finalize`` method is used only with the
+``stream`` type). Kernel parameters types are extract from the ``__init`` 
method
+parameters. The kernel function arguments list is derived from the





Comment at: clang/test/SemaSYCL/special-class-attribute-on-non-sycl.cpp:11
+class __attribute__((sycl_special_class)) special_class {
+  void __init(){};
+};





Comment at: clang/test/SemaSYCL/special-class-attribute.cpp:5
+class [[clang::sycl_special_class]] class1 {
+  void __init(){};
+};

Can you correct this entire file not to have the trailing semicolons?


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

https://reviews.llvm.org/D114483

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


[PATCH] D107290: [RISCV] Add support for the vscale_range attribute

2022-01-25 Thread Zakk Chen via Phabricator via cfe-commits
khchen added inline comments.



Comment at: llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vscale-range.ll:162
+
+attributes #0 = { vscale_range(2,1024) }
+attributes #1 = { vscale_range(4,1024) }

frasercrmck wrote:
> khchen wrote:
> > I'm thinking do we need to test zvl and vscale_range in the same attribute?
> > ex. `attributes #0 = { vscale_range(2,1024) "target-features"="+zvl512b" }`
> Perhaps yeah. Just to check - what exactly for? Because we need `zvl` in the 
> attributes for correctness, or in order to test the combination of `zvl` 
> architecture and `vscale_range` to test what happens when they disagree?
Just test for they disagree.
Do you know what's expected value for different `vscale_range` value in two 
function after function inlining? If they are always have the same minimum 
value for VLEN, I think we don't need a check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107290

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


[PATCH] D114483: [SYCL] Add support for sycl_special_class attribute

2022-01-25 Thread Victor Lomuller via Phabricator via cfe-commits
Naghasan accepted this revision.
Naghasan added a comment.

LGTM, thanks for the work


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

https://reviews.llvm.org/D114483

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


[clang-tools-extra] f3314e3 - [clang-tidy] Pop Files only if FileChangeReason is ExitFile

2022-01-25 Thread Jim Lin via cfe-commits

Author: Jim Lin
Date: 2022-01-25T22:46:12+08:00
New Revision: f3314e3747873fdf026a28742a30f372503baf32

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

LOG: [clang-tidy] Pop Files only if FileChangeReason is ExitFile

enum FileChangeReason has four possible type EnterFile, ExitFile,
SystemHeaderPragma and RenameFile,
It should pop the back element of Files only if FileChangeReason is ExitFile.

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
index 681b8399154a7..a6e49439c8434 100644
--- a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
@@ -71,7 +71,7 @@ void DuplicateIncludeCallbacks::FileChanged(SourceLocation 
Loc,
 FileID PrevFID) {
   if (Reason == EnterFile)
 Files.emplace_back();
-  else
+  else if (Reason == ExitFile)
 Files.pop_back();
 }
 



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


[PATCH] D116478: [clang-tidy] A semicolon-separated list of the names of functions or methods to be considered as not having side-effects

2022-01-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from a nit in the documentation.




Comment at: clang-tools-extra/docs/ReleaseNotes.rst:161
+  check now supports an ``IgnoredFunctions`` option to explicitly consider
+  the specified semicolon-separated functions list as not any having
+  side-effects. Regular expressions for the list items are also accepted.




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

https://reviews.llvm.org/D116478

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


[PATCH] D118110: [CMake] [Clang] Add CMake build option to specify long double format on PowerPC

2022-01-25 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

It is probably not worth the effort since there won't be that many test cases 
that test the front end's IR generation for `long double`, but there should be 
a way to set up lit to know the default through its configuration files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118110

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


[PATCH] D118110: [CMake] [Clang] Add CMake build option to specify long double format on PowerPC

2022-01-25 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added inline comments.



Comment at: clang/CMakeLists.txt:240
 
+set(ENABLE_PPC_IEEELONGDOUBLE OFF CACHE BOOL
+"Enable IEEE binary128 as default long double format on PowerPC.")

Do we need any error checking here? What happens if someone erroneously sets 
this on an AIX build (or big endian Linux, FreeBSD, etc.)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118110

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


[clang-tools-extra] 9d8c3ad - [clang-tidy] Change code of SignalHandlerCheck (NFC).

2022-01-25 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2022-01-25T15:52:38+01:00
New Revision: 9d8c3ad94fad5dd5fb511af89c9e7c3679922ce0

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

LOG: [clang-tidy] Change code of SignalHandlerCheck (NFC).

Using clang::CallGraph to get the called functions.
This makes a better foundation to improve support for
C++ and print the call chain.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
index 63478a954058..1fc19a8652e3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
@@ -7,15 +7,9 @@
 
//===--===//
 
 #include "SignalHandlerCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Analysis/CallGraph.h"
-#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/DepthFirstIterator.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
-#include 
-#include 
 
 using namespace clang::ast_matchers;
 
@@ -42,7 +36,9 @@ struct OptionEnumMapping<
 
 namespace bugprone {
 
-static bool isSystemCall(const FunctionDecl *FD) {
+namespace {
+
+bool isSystemCall(const FunctionDecl *FD) {
   // Find a possible redeclaration in system header.
   // FIXME: Looking at the canonical declaration is not the most exact way
   // to do this.
@@ -73,6 +69,22 @@ static bool isSystemCall(const FunctionDecl *FD) {
   FD->getCanonicalDecl()->getLocation());
 }
 
+/// Given a call graph node of a function and another one that is called from
+/// this function, get a CallExpr of the corresponding function call.
+/// It is unspecified which call is found if multiple calls exist, but the 
order
+/// should be deterministic (depend only on the AST).
+Expr *findCallExpr(const CallGraphNode *Caller, const CallGraphNode *Callee) {
+  auto FoundCallee = llvm::find_if(
+  Caller->callees(), [Callee](const CallGraphNode::CallRecord &Call) {
+return Call.Callee == Callee;
+  });
+  assert(FoundCallee != Caller->end() &&
+ "Callee should be called from the caller function here.");
+  return FoundCallee->CallExpr;
+}
+
+} // namespace
+
 AST_MATCHER(FunctionDecl, isSystemCall) { return isSystemCall(&Node); }
 
 SignalHandlerCheck::SignalHandlerCheck(StringRef Name,
@@ -117,68 +129,50 @@ void SignalHandlerCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *HandlerDecl =
   Result.Nodes.getNodeAs("handler_decl");
   const auto *HandlerExpr = 
Result.Nodes.getNodeAs("handler_expr");
+  assert(SignalCall && HandlerDecl && HandlerExpr &&
+ "All of these should exist in a match here.");
+
+  if (CG.size() <= 1) {
+// Call graph must be populated with the entire TU at the beginning.
+// (It is possible to add a single function but the functions called from 
it
+// are not analysed in this case.)
+CG.addToCallGraph(const_cast(
+HandlerDecl->getTranslationUnitDecl()));
+assert(CG.size() > 1 &&
+   "There should be at least one function added to call graph.");
+  }
 
-  // Visit each function encountered in the callgraph only once.
-  llvm::DenseSet SeenFunctions;
-
-  // The worklist of the callgraph visitation algorithm.
-  std::deque CalledFunctions;
-
-  auto ProcessFunction = [&](const FunctionDecl *F, const Expr *CallOrRef) {
-// Ensure that canonical declaration is used.
-F = F->getCanonicalDecl();
-
-// Do not visit function if already encountered.
-if (!SeenFunctions.insert(F).second)
-  return true;
-
-// Check if the call is allowed.
-// Non-system calls are not considered.
-if (isSystemCall(F)) {
-  if (isSystemCallAllowed(F))
-return true;
-
-  reportBug(F, CallOrRef, SignalCall, HandlerDecl);
-
-  return false;
-}
-
-// Get the body of the encountered non-system call function.
-const FunctionDecl *FBody;
-if (!F->hasBody(FBody)) {
-  reportBug(F, CallOrRef, SignalCall, HandlerDecl);
-  return false;
-}
-
-// Collect all called functions.
-auto Matches = match(decl(forEachDescendant(callExpr().bind("call"))),
- *FBody, FBody->getASTContext());
-for (const auto &Match : Matches) {
-  const auto *CE = Match.getNodeAs("call");
-  if 

[PATCH] D118016: [clang-tidy] Change code of SignalHandlerCheck (NFC).

2022-01-25 Thread Balázs Kéri 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 rG9d8c3ad94fad: [clang-tidy] Change code of SignalHandlerCheck 
(NFC). (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118016

Files:
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
@@ -51,6 +51,37 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
+void test_false_condition(int) {
+  if (0)
+printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+}
+
+void test_multiple_calls(int) {
+  f_extern();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  f_extern();
+  // first 'f_extern' call found only
+}
+
+void f_recursive();
+
+void test_recursive(int) {
+  f_recursive();
+  printf("");
+  // first 'printf' call (in other function) found only
+}
+
+void f_recursive() {
+  f_extern();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  printf("");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  f_recursive(2);
+}
+
 void test() {
   signal(SIGINT, handler_abort);
   signal(SIGINT, handler_signal);
@@ -66,4 +97,8 @@
 
   signal(SIGINT, SIG_IGN);
   signal(SIGINT, SIG_DFL);
+
+  signal(SIGINT, test_false_condition);
+  signal(SIGINT, test_multiple_calls);
+  signal(SIGINT, test_recursive);
 }
Index: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SIGNALHANDLERCHECK_H
 
 #include "../ClangTidyCheck.h"
+#include "clang/Analysis/CallGraph.h"
 #include "llvm/ADT/StringSet.h"
 
 namespace clang {
@@ -31,9 +32,12 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
 private:
+  bool isFunctionAsyncSafe(const FunctionDecl *FD) const;
+  bool isSystemCallAsyncSafe(const FunctionDecl *FD) const;
   void reportBug(const FunctionDecl *CalledFunction, const Expr *CallOrRef,
  const CallExpr *SignalCall, const FunctionDecl *HandlerDecl);
-  bool isSystemCallAllowed(const FunctionDecl *FD) const;
+
+  CallGraph CG;
 
   AsyncSafeFunctionSetType AsyncSafeFunctionSet;
   llvm::StringSet<> &ConformingFunctions;
Index: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
@@ -7,15 +7,9 @@
 //===--===//
 
 #include "SignalHandlerCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Analysis/CallGraph.h"
-#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/DepthFirstIterator.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
-#include 
-#include 
 
 using namespace clang::ast_matchers;
 
@@ -42,7 +36,9 @@
 
 namespace bugprone {
 
-static bool isSystemCall(const FunctionDecl *FD) {
+namespace {
+
+bool isSystemCall(const FunctionDecl *FD) {
   // Find a possible redeclaration in system header.
   // FIXME: Looking at the canonical declaration is not the most exact way
   // to do this.
@@ -73,6 +69,22 @@
   FD->getCanonicalDecl()->getLocation());
 }
 
+/// Given a call graph node of a function and another one that is called from
+/// this function, get a CallExpr of the corresponding function call.
+/// It is unspecified which call is found if multiple calls exist, but the order
+/// sh

[PATCH] D117355: [PowerPC] Fix the undef virtual register reading failure for PPC backend trap optimization

2022-01-25 Thread Amy Kwan via Phabricator via cfe-commits
amyk added inline comments.



Comment at: llvm/lib/Target/PowerPC/PPCMIPeephole.cpp:432
   if (EnableTrapOptimization && TrapOpt) {
+bool IsVReg =
+(MI.getNumOperands() && MI.getOperand(0).isReg())

Might be good to pull out `MI.getOperand(0).isReg()` into a separate variable 
since you're using it three times here. 



Comment at: llvm/test/CodeGen/PowerPC/mi-peephole-trap-opt-dominated-block.mir:1
+# RUN: llc -mtriple powerpc64le-unknown-linux-gnu -mcpu=pwr8 -x mir < %s \
+# RUN:   -verify-machineinstrs -start-before=ppc-mi-peepholes \

Question: are AIX run lines necessary, too? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117355

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


[PATCH] D114483: [SYCL] Add support for sycl_special_class attribute

2022-01-25 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 402900.
zahiraam marked 3 inline comments as done.

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

https://reviews.llvm.org/D114483

Files:
  clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaSYCL/special-class-attribute-on-non-sycl.cpp
  clang/test/SemaSYCL/special-class-attribute.cpp

Index: clang/test/SemaSYCL/special-class-attribute.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/special-class-attribute.cpp
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
+
+// No diagnostics
+class [[clang::sycl_special_class]] class1 {
+  void __init(){}
+};
+class __attribute__((sycl_special_class)) class2 {
+  void __init(){}
+};
+
+class class3;
+class [[clang::sycl_special_class]] class3 {
+  void __init(){}
+};
+
+class class4;
+class __attribute__((sycl_special_class)) class4 {
+  void __init(){}
+};
+
+struct [[clang::sycl_special_class]] struct1 {
+  void __init(){}
+};
+struct __attribute__((sycl_special_class)) struct2 {
+  void __init(){}
+};
+
+class __attribute__((sycl_special_class)) class5;
+class class5 {
+  void __init(){}
+};
+
+// Must have one and only one __init method defined
+class __attribute__((sycl_special_class)) class6 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  class6() {}
+};
+class [[clang::sycl_special_class]] class7 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+};
+
+class [[clang::sycl_special_class]] class8 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+  int func() {}
+  void __init(int a){}
+};
+
+struct __attribute__((sycl_special_class)) struct3;
+struct struct3 {}; // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+
+// Only classes
+[[clang::sycl_special_class]] int var1 = 0;   // expected-warning {{'sycl_special_class' attribute only applies to classes}}
+__attribute__((sycl_special_class)) int var2 = 0; // expected-warning {{'sycl_special_class' attribute only applies to classes}}
+
+[[clang::sycl_special_class]] void foo1();   // expected-warning {{'sycl_special_class' attribute only applies to classes}}
+__attribute__((sycl_special_class)) void foo2(); // expected-warning {{'sycl_special_class' attribute only applies to classes}}
+
+// Attribute takes no arguments
+class [[clang::sycl_special_class(1)]] class9{}; // expected-error {{'sycl_special_class' attribute takes no arguments}}
+class __attribute__((sycl_special_class(1))) class10 {}; // expected-error {{'sycl_special_class' attribute takes no arguments}}
+
+// __init method must be defined inside the CXXRecordDecl.
+class [[clang::sycl_special_class]] class11 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+};
+void class11::__init(){}
+
+class __attribute__((sycl_special_class)) class12 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+};
+void class12::__init(){}
+
+struct [[clang::sycl_special_class]] struct4 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+};
+void struct4::__init(){}
+
+struct __attribute__((sycl_special_class)) struct5 { // expected-error {{types with 'sycl_special_class' attribute must have one and only one '__init' method defined}}
+  void __init();
+};
+void struct5::__init(){}
Index: clang/test/SemaSYCL/special-class-attribute-on-non-sycl.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/special-class-attribute-on-non-sycl.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -x c++ %s
+
+#ifndef __SYCL_DEVICE_ONLY__
+// expected-warning@+5 {{'sycl_special_class' attribute ignored}}
+#else
+// expected-no-diagnostics
+#endif
+
+class __attribute__((sycl_special_class)) special_class {
+  void __init(){}
+};
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-at

[PATCH] D114483: [SYCL] Add support for sycl_special_class attribute

2022-01-25 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

Thanks for the reviews.


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

https://reviews.llvm.org/D114483

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


[PATCH] D103048: [IR] make -stack-alignment= into a module attr

2022-01-25 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

One test `FAILs` on Solaris/sparcv9:

  LLVM :: CodeGen/Generic/ForceStackAlign.ll

with

  LLVM ERROR: Function "g" required stack re-alignment, but LLVM couldn't 
handle it (probably because it has a dynamic alloca).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103048

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


[PATCH] D116377: [libTooling] Adds more support for constructing object access expressions.

2022-01-25 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 402910.
ymandel added a comment.

extended list of pointer-like types


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116377

Files:
  clang/include/clang/Tooling/Transformer/SourceCodeBuilders.h
  clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp
  clang/lib/Tooling/Transformer/Stencil.cpp
  clang/unittests/Tooling/SourceCodeBuildersTest.cpp

Index: clang/unittests/Tooling/SourceCodeBuildersTest.cpp
===
--- clang/unittests/Tooling/SourceCodeBuildersTest.cpp
+++ clang/unittests/Tooling/SourceCodeBuildersTest.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Tooling/Transformer/SourceCodeBuilders.h"
+#include "clang/AST/Type.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/Tooling.h"
@@ -24,8 +25,23 @@
 
 // Create a valid translation unit from a statement.
 static std::string wrapSnippet(StringRef StatementCode) {
-  return ("struct S { S(); S(int); int field; };\n"
+  return ("namespace std {\n"
+  "template  struct unique_ptr {\n"
+  "  T* operator->() const;\n"
+  "  T& operator*() const;\n"
+  "};\n"
+  "template  struct shared_ptr {\n"
+  "  T* operator->() const;\n"
+  "  T& operator*() const;\n"
+  "};\n"
+  "}\n"
+  "struct A { void super(); };\n"
+  "struct S : public A { S(); S(int); int Field; };\n"
   "S operator+(const S &a, const S &b);\n"
+  "struct Smart {\n"
+  "  S* operator->() const;\n"
+  "  S& operator*() const;\n"
+  "};\n"
   "auto test_snippet = []{" +
   StatementCode + "};")
   .str();
@@ -51,7 +67,8 @@
 // `StatementCode` may contain other statements not described by `Matcher`.
 static llvm::Optional matchStmt(StringRef StatementCode,
StatementMatcher Matcher) {
-  auto AstUnit = buildASTFromCode(wrapSnippet(StatementCode));
+  auto AstUnit = buildASTFromCodeWithArgs(wrapSnippet(StatementCode),
+  {"-Wno-unused-value"});
   if (AstUnit == nullptr) {
 ADD_FAILURE() << "AST construction failed";
 return llvm::None;
@@ -95,7 +112,7 @@
   testPredicate(needParensAfterUnaryOperator, "int(3.0);", false);
   testPredicate(needParensAfterUnaryOperator, "void f(); f();", false);
   testPredicate(needParensAfterUnaryOperator, "int a[3]; a[0];", false);
-  testPredicate(needParensAfterUnaryOperator, "S x; x.field;", false);
+  testPredicate(needParensAfterUnaryOperator, "S x; x.Field;", false);
   testPredicate(needParensAfterUnaryOperator, "int x = 1; --x;", false);
   testPredicate(needParensAfterUnaryOperator, "int x = 1; -x;", false);
 }
@@ -117,7 +134,7 @@
   testPredicate(mayEverNeedParens, "int(3.0);", false);
   testPredicate(mayEverNeedParens, "void f(); f();", false);
   testPredicate(mayEverNeedParens, "int a[3]; a[0];", false);
-  testPredicate(mayEverNeedParens, "S x; x.field;", false);
+  testPredicate(mayEverNeedParens, "S x; x.Field;", false);
 }
 
 TEST(SourceCodeBuildersTest, mayEverNeedParensInImplictConversion) {
@@ -126,6 +143,50 @@
   testPredicateOnArg(mayEverNeedParens, "void f(S); f(3 + 5);", true);
 }
 
+TEST(SourceCodeBuildersTest, isKnownPointerLikeTypeUniquePtr) {
+  std::string Snippet = "std::unique_ptr P; P;";
+  auto StmtMatch =
+  matchStmt(Snippet, declRefExpr(hasType(qualType().bind("ty";
+  ASSERT_TRUE(StmtMatch) << "Snippet: " << Snippet;
+  EXPECT_TRUE(
+  isKnownPointerLikeType(*StmtMatch->Result.Nodes.getNodeAs("ty"),
+ *StmtMatch->Result.Context))
+  << "Snippet: " << Snippet;
+}
+
+TEST(SourceCodeBuildersTest, isKnownPointerLikeTypeSharedPtr) {
+  std::string Snippet = "std::shared_ptr P; P;";
+  auto StmtMatch =
+  matchStmt(Snippet, declRefExpr(hasType(qualType().bind("ty";
+  ASSERT_TRUE(StmtMatch) << "Snippet: " << Snippet;
+  EXPECT_TRUE(
+  isKnownPointerLikeType(*StmtMatch->Result.Nodes.getNodeAs("ty"),
+ *StmtMatch->Result.Context))
+  << "Snippet: " << Snippet;
+}
+
+TEST(SourceCodeBuildersTest, isKnownPointerLikeTypeUnknownTypeFalse) {
+  std::string Snippet = "Smart P; P;";
+  auto StmtMatch =
+  matchStmt(Snippet, declRefExpr(hasType(qualType().bind("ty";
+  ASSERT_TRUE(StmtMatch) << "Snippet: " << Snippet;
+  EXPECT_FALSE(
+  isKnownPointerLikeType(*StmtMatch->Result.Nodes.getNodeAs("ty"),
+ *StmtMatch->Result.Context))
+  << "Snippet: " << Snippet;
+}
+
+TEST(SourceCodeBuildersTest, isKnownPointerLikeTypeNormalTypeFalse) {
+  std::string Snippet = "int *P; P;";
+  auto StmtMatch =
+  matchStmt(Snippet, declRefExpr(hasType(qualType().bind("

[PATCH] D118150: [clang] Fix serialized diagnostics edge-cases

2022-01-25 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The Clang frontend sometimes fails on the following assertion when launched 
with `-serialize-diagnostic-file `:

  Assertion failed: (BlockScope.empty() && CurAbbrevs.empty() && "Block 
imbalance"), function ~BitstreamWriter, file BitstreamWriter.h, line 125.

This was first noticed when passing an unknown command-line argument to `-cc1`.

It turns out the `DiagnosticConsumer::finish()` function should be called as 
soon as processing of all source files ends, but there are some code paths 
where that doesn't happen:

1. when command line parsing fails in `main_cc1()`,
2. when `!Act.PrepareToExecute(*this)` or `!createTarget()` evaluate to `true` 
in `CompilerInstance::ExecuteAction` and the function returns early.

This patch ensures `finish()` is called in all those code paths.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118150

Files:
  clang/lib/Frontend/CompilerInstance.cpp
  clang/test/Misc/serialized-diags-emit-header-module-misconfig.c
  clang/test/Misc/serialized-diags-unknown-argument.c
  clang/test/Misc/serialized-diags-unknown-target.c
  clang/tools/driver/cc1_main.cpp


Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -237,8 +237,10 @@
   
static_cast(&Clang->getDiagnostics()));
 
   DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
-  if (!Success)
+  if (!Success) {
+Clang->getDiagnosticClient().finish();
 return 1;
+  }
 
   // Execute the frontend actions.
   {
Index: clang/test/Misc/serialized-diags-unknown-target.c
===
--- /dev/null
+++ clang/test/Misc/serialized-diags-unknown-target.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 %s -triple blah-unknown-unknown 
-serialize-diagnostic-file %t/diag -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: unknown target triple 'blah-unknown-unknown', please use 
-triple or -arch
Index: clang/test/Misc/serialized-diags-unknown-argument.c
===
--- /dev/null
+++ clang/test/Misc/serialized-diags-unknown-argument.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 %s -unknown-argument -serialize-diagnostic-file %t/diag 
-o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: unknown argument: '-unknown-argument'
Index: clang/test/Misc/serialized-diags-emit-header-module-misconfig.c
===
--- /dev/null
+++ clang/test/Misc/serialized-diags-emit-header-module-misconfig.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 -emit-header-module %s -o %t/out.pcm 
-serialize-diagnostic-file %t/diag 2>&1 | FileCheck %s
+
+// CHECK: error: header module compilation requires '-fmodules', '-std=c++20', 
or '-fmodules-ts'
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -37,6 +37,7 @@
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CrashRecoveryContext.h"
@@ -996,6 +997,11 @@
   // DesiredStackSpace available.
   noteBottomOfStack();
 
+  auto FinishDiagnosticClient = llvm::make_scope_exit([&]() {
+// Notify the diagnostic client that all files were processed.
+getDiagnosticClient().finish();
+  });
+
   raw_ostream &OS = getVerboseOutputStream();
 
   if (!Act.PrepareToExecute(*this))
@@ -1034,9 +1040,6 @@
 }
   }
 
-  // Notify the diagnostic client that all files were processed.
-  getDiagnostics().getClient()->finish();
-
   if (getDiagnosticOpts().ShowCarets) {
 // We can have multiple diagnostics sharing one diagnostic client.
 // Get the total number of warnings/errors from the client.


Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -237,8 +237,10 @@
   static_cast(&Clang->getDiagnostics()));
 
   DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
-  if (!Success)
+  if (!Success) {
+Clang->getDiagnosticClient().finish();
 return 1;
+  }
 
   // Execute the frontend actions.
   {
Index: clang/test/Misc/serialized-diags-unknown-target.c
===
--- /dev/null

[PATCH] D117965: [AlwaysInliner] Enable call site inlining to make flatten attribute working again (PR53360)

2022-01-25 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Aiming this fix for LLVM 14.0.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117965

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


[PATCH] D118150: [clang] Fix serialized diagnostics edge-cases

2022-01-25 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/test/Misc/serialized-diags-emit-header-module-misconfig.c:2
+// RUN: rm -rf %t && mkdir %t
+// RUN: not %clang_cc1 -emit-header-module %s -o %t/out.pcm 
-serialize-diagnostic-file %t/diag 2>&1 | FileCheck %s
+

This combination of command-line arguments causes 
`GenerateHeaderModuleAction::PrepareToExecuteAction` to return `false` and 
`!Act.PrepareToExecute(*this) == true`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118150

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


[PATCH] D118104: Make run-clang-tidy.py print the configured checks correctly

2022-01-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py:257-265
 invocation = [args.clang_tidy_binary, '-list-checks']
 if args.allow_enabling_alpha_checkers:
   invocation.append('-allow-enabling-analyzer-alpha-checkers')
 invocation.append('-p=' + build_path)
 if args.checks:
   invocation.append('-checks=' + args.checks)
+if args.config:

Would it make sense to re-use `get_tidy_invocation` with the proper arguments 
here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118104

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


[PATCH] D118152: [clang][deps] Adapt test to be compatible when the assembler is called by default

2022-01-25 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan created this revision.
Jake-Egan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118152

Files:
  clang/test/ClangScanDeps/headerwithdirname.cpp
  clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp


Index: clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
===
--- clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
+++ clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
@@ -17,7 +17,7 @@
 #include 
 #include "foodir/foodirheader.h"
 
-// CHECK: headerwithdirname_input.o
+// CHECK: headerwithdirname_input{{.*}}{{.o|.s}}
 // CHECK-NEXT: headerwithdirname_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}foodir
 
Index: clang/test/ClangScanDeps/headerwithdirname.cpp
===
--- clang/test/ClangScanDeps/headerwithdirname.cpp
+++ clang/test/ClangScanDeps/headerwithdirname.cpp
@@ -13,7 +13,7 @@
 
 #include 
 
-// CHECK: headerwithdirname_input.o
+// CHECK: headerwithdirname_input{{.*}}{{.o|.s}}
 // CHECK-NEXT: headerwithdirname_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}foodir
 


Index: clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
===
--- clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
+++ clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
@@ -17,7 +17,7 @@
 #include 
 #include "foodir/foodirheader.h"
 
-// CHECK: headerwithdirname_input.o
+// CHECK: headerwithdirname_input{{.*}}{{.o|.s}}
 // CHECK-NEXT: headerwithdirname_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}foodir
 
Index: clang/test/ClangScanDeps/headerwithdirname.cpp
===
--- clang/test/ClangScanDeps/headerwithdirname.cpp
+++ clang/test/ClangScanDeps/headerwithdirname.cpp
@@ -13,7 +13,7 @@
 
 #include 
 
-// CHECK: headerwithdirname_input.o
+// CHECK: headerwithdirname_input{{.*}}{{.o|.s}}
 // CHECK-NEXT: headerwithdirname_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}foodir
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118153: [CUDA][HIP] Do not treat host var address as constant in device compilation

2022-01-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
yaxunl requested review of this revision.

Currently clang treats host var address as constant in device compilation,
which causes const vars initialized with host var address promoted to
device variables incorrectly and results in undefined symbols.

This patch fixes that.


https://reviews.llvm.org/D118153

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/CodeGenCUDA/const-var.cu
  clang/test/SemaCUDA/const-var.cu

Index: clang/test/SemaCUDA/const-var.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/const-var.cu
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -fsyntax-only -verify
+
+#include "Inputs/cuda.h"
+
+// Test const var initialized with address of a const var.
+// Both are promoted to device side.
+
+namespace Test1 {
+const int a = 1;
+
+struct B { 
+static const int *const p; 
+__device__ static const int *const p2; 
+};
+const int *const B::p = &a;
+__device__ const int *const B::p2 = &a;
+
+__device__ void f() {
+  int y = a;
+  const int *x = B::p;
+  const int *z = B::p2;
+}
+}
+
+// Test const var initialized with address of a non-cost var.
+// Neither is promoted to device side.
+
+namespace Test2 {
+int a = 1;
+// expected-note@-1{{host variable declared here}}
+
+struct B { 
+static int *const p; 
+};
+int *const B::p = &a;
+// expected-note@-1{{const variable cannot be emitted on device side due to dynamic initialization}}
+
+__device__ void f() {
+  int y = a; 
+  // expected-error@-1{{reference to __host__ variable 'a' in __device__ function}}
+  const int *x = B::p;
+  // expected-error@-1{{reference to __host__ variable 'p' in __device__ function}}
+}
+}
+
+// Test device var initialized with address of a non-const host var.
+
+namespace Test3 {
+int a = 1;
+
+struct B { 
+__device__ static int *const p; 
+};
+__device__ int *const B::p = &a;
+// expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+}
Index: clang/test/CodeGenCUDA/const-var.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/const-var.cu
@@ -0,0 +1,46 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -emit-llvm -o - | FileCheck -check-prefix=DEV %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -x hip %s \
+// RUN:   -emit-llvm -o - | FileCheck -check-prefix=HOST %s
+
+// Negative tests.
+
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -emit-llvm -o - | FileCheck -check-prefix=DEV-NEG %s
+
+#include "Inputs/cuda.h"
+
+// Test const var initialized with address of a const var.
+// Both are promoted to device side.
+
+// DEV-DAG: @_ZN5Test1L1aE = internal addrspace(4) constant i32 1
+// DEV-DAG: @_ZN5Test11B1pE = addrspace(4) externally_initialized constant i32* addrspacecast (i32 addrspace(4)* @_ZN5Test1L1aE to i32*)
+// HOST-DAG: @_ZN5Test1L1aE = internal constant i32 1
+// HOST-DAG: @_ZN5Test11B1pE = constant i32* @_ZN5Test1L1aE
+namespace Test1 {
+const int a = 1;
+
+struct B { 
+static const int *const p; 
+};
+const int *const B::p = &a;
+}
+
+// Test const var initialized with address of a non-cost var.
+// Neither is promoted to device side.
+
+// DEV-NEG-NOT: @_ZN5Test2L1aE
+// DEV-NEG-NOT: @_ZN5Test21B1pE
+// HOST-DAG: @_ZN5Test21aE = global i32 1
+// HOST-DAG: @_ZN5Test21B1pE = constant i32* @_ZN5Test21aE
+
+namespace Test2 {
+int a = 1;
+
+struct B { 
+static int *const p; 
+};
+int *const B::p = &a;
+__constant__ int *const x = &a;
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -983,6 +983,8 @@
   discardCleanups();
 }
 
+ASTContext &getCtx() const override { return Ctx; }
+
 void setEvaluatingDecl(APValue::LValueBase Base, APValue &Value,
EvaluatingDeclKind EDK = EvaluatingDeclKind::Ctor) {
   EvaluatingDecl = Base;
@@ -1116,8 +1118,6 @@
 
 Expr::EvalStatus &getEvalStatus() const override { return EvalStatus; }
 
-ASTContext &getCtx() const override { return Ctx; }
-
 // If we have a prior diagnostic, it will be noting that the expression
 // isn't a constant expression. This diagnostic is more important,
 // unless we require this evaluation to produce a constant expression.
@@ -2216,6 +2216,19 @@
   if (!isForManglingOnly(Kind) && Var->hasAttr())
 // FIXME: Diagnostic!
 return false;
+
+  // In CUDA/HIP device compilation, only device side variables have
+  // constant addresses.
+  if (Info.getCtx().getLangOpts().CUDA &&
+  Info.getCtx().getLangOpts().CUDAIsDevice) {
+if (!Var->hasAttr() &&
+

[PATCH] D117048: [OpenMP] Link the bitcode library late for device LTO

2022-01-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 402925.
jhuber6 added a comment.

Squash other uncommitted changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117048

Files:
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -68,9 +68,14 @@
 
 static cl::opt OptLevel("opt-level",
  cl::desc("Optimization level for LTO"),
- cl::init("O0"),
+ cl::init("O2"),
  cl::cat(ClangLinkerWrapperCategory));
 
+static cl::opt
+BitcodeLibrary("target-library",
+   cl::desc("Path for the target bitcode library"),
+   cl::cat(ClangLinkerWrapperCategory));
+
 // Do not parse linker options.
 static cl::list
 HostLinkerArgs(cl::Sink, cl::desc("..."));
@@ -201,7 +206,7 @@
   std::unique_ptr Output = std::move(*OutputOrErr);
   std::copy(Contents->begin(), Contents->end(), Output->getBufferStart());
   if (Error E = Output->commit())
-return E;
+return std::move(E);
 
   DeviceFiles.emplace_back(DeviceTriple, Arch, TempFile);
   ToBeStripped.push_back(*Name);
@@ -229,7 +234,7 @@
 std::unique_ptr Output = std::move(*OutputOrErr);
 std::copy(Contents.begin(), Contents.end(), Output->getBufferStart());
 if (Error E = Output->commit())
-  return E;
+  return std::move(E);
 StripFile = TempFile;
   }
 
@@ -318,7 +323,7 @@
 std::unique_ptr Output = std::move(*OutputOrErr);
 std::copy(Contents.begin(), Contents.end(), Output->getBufferStart());
 if (Error E = Output->commit())
-  return E;
+  return std::move(E);
 
 DeviceFiles.emplace_back(DeviceTriple, Arch, TempFile);
 ToBeDeleted.push_back(&GV);
@@ -329,7 +334,7 @@
 
   // We need to materialize the lazy module before we make any changes.
   if (Error Err = M->materializeAll())
-return Err;
+return std::move(Err);
 
   // Remove the global from the module and write it to a new file.
   for (GlobalVariable *GV : ToBeDeleted) {
@@ -403,7 +408,7 @@
   }
 
   if (Err)
-return Err;
+return std::move(Err);
 
   if (!NewMembers)
 return None;
@@ -417,9 +422,9 @@
 
   std::unique_ptr Buffer =
   MemoryBuffer::getMemBuffer(Library.getMemoryBufferRef(), false);
-  if (Error WriteErr = writeArchive(TempFile, Members, true, Library.kind(),
+  if (Error Err = writeArchive(TempFile, Members, true, Library.kind(),
 true, Library.isThin(), std::move(Buffer)))
-return WriteErr;
+return std::move(Err);
 
   return static_cast(TempFile);
 }
@@ -740,7 +745,7 @@
 
 // Add the bitcode file with its resolved symbols to the LTO job.
 if (Error Err = LTOBackend->add(std::move(BitcodeFile), Resolutions))
-  return Err;
+  return std::move(Err);
   }
 
   // Run the LTO job to compile the bitcode.
@@ -758,7 +763,7 @@
 std::make_unique(FD, true));
   };
   if (Error Err = LTOBackend->run(AddStream))
-return Err;
+return std::move(Err);
 
   for (auto &File : Files) {
 if (!TheTriple.isNVPTX())
@@ -976,6 +981,17 @@
 }
   }
 
+  // Add the device bitcode library to the device files if it was passed in.
+  if (!BitcodeLibrary.empty()) {
+// FIXME: Hacky workaround to avoid a backend crash at O0.
+if (OptLevel[1] - '0' == 0)
+  OptLevel[1] = '1';
+auto DeviceAndPath = StringRef(BitcodeLibrary).split('=');
+auto TripleAndArch = DeviceAndPath.first.rsplit('-');
+DeviceFiles.emplace_back(TripleAndArch.first, TripleAndArch.second,
+ DeviceAndPath.second);
+  }
+
   // Link the device images extracted from the linker input.
   SmallVector LinkedImages;
   if (Error Err = linkDeviceFiles(DeviceFiles, LinkerArgs, LinkedImages))
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -744,6 +744,10 @@
   return;
 }
 
+// Link the bitcode library late if we're using device LTO.
+if (getDriver().isUsingLTO(/* IsOffload */ true))
+  return;
+
 std::string BitcodeSuffix;
 if (DriverArgs.hasFlag(options::OPT_fopenmp_target_new_runtime,
options::OPT_fno_openmp_target_new_runtime, true))
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clan

[PATCH] D118153: [CUDA][HIP] Do not treat host var address as constant in device compilation

2022-01-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 402924.
yaxunl added a comment.

fix test


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

https://reviews.llvm.org/D118153

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/CodeGenCUDA/const-var.cu
  clang/test/SemaCUDA/const-var.cu

Index: clang/test/SemaCUDA/const-var.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/const-var.cu
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -fsyntax-only -verify
+
+#include "Inputs/cuda.h"
+
+// Test const var initialized with address of a const var.
+// Both are promoted to device side.
+
+namespace Test1 {
+const int a = 1;
+
+struct B { 
+static const int *const p; 
+__device__ static const int *const p2; 
+};
+const int *const B::p = &a;
+__device__ const int *const B::p2 = &a;
+
+__device__ void f() {
+  int y = a;
+  const int *x = B::p;
+  const int *z = B::p2;
+}
+}
+
+// Test const var initialized with address of a non-cost var.
+// Neither is promoted to device side.
+
+namespace Test2 {
+int a = 1;
+// expected-note@-1{{host variable declared here}}
+
+struct B { 
+static int *const p; 
+};
+int *const B::p = &a;
+// expected-note@-1{{const variable cannot be emitted on device side due to dynamic initialization}}
+
+__device__ void f() {
+  int y = a; 
+  // expected-error@-1{{reference to __host__ variable 'a' in __device__ function}}
+  const int *x = B::p;
+  // expected-error@-1{{reference to __host__ variable 'p' in __device__ function}}
+}
+}
+
+// Test device var initialized with address of a non-const host var.
+
+namespace Test3 {
+int a = 1;
+
+struct B { 
+__device__ static int *const p; 
+};
+__device__ int *const B::p = &a;
+// expected-error@-1{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+}
Index: clang/test/CodeGenCUDA/const-var.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/const-var.cu
@@ -0,0 +1,45 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -emit-llvm -o - | FileCheck -check-prefix=DEV %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -x hip %s \
+// RUN:   -emit-llvm -o - | FileCheck -check-prefix=HOST %s
+
+// Negative tests.
+
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -emit-llvm -o - | FileCheck -check-prefix=DEV-NEG %s
+
+#include "Inputs/cuda.h"
+
+// Test const var initialized with address of a const var.
+// Both are promoted to device side.
+
+// DEV-DAG: @_ZN5Test1L1aE = internal addrspace(4) constant i32 1
+// DEV-DAG: @_ZN5Test11B1pE = addrspace(4) externally_initialized constant i32* addrspacecast (i32 addrspace(4)* @_ZN5Test1L1aE to i32*)
+// HOST-DAG: @_ZN5Test1L1aE = internal constant i32 1
+// HOST-DAG: @_ZN5Test11B1pE = constant i32* @_ZN5Test1L1aE
+namespace Test1 {
+const int a = 1;
+
+struct B { 
+static const int *const p; 
+};
+const int *const B::p = &a;
+}
+
+// Test const var initialized with address of a non-cost var.
+// Neither is promoted to device side.
+
+// DEV-NEG-NOT: @_ZN5Test2L1aE
+// DEV-NEG-NOT: @_ZN5Test21B1pE
+// HOST-DAG: @_ZN5Test21aE = global i32 1
+// HOST-DAG: @_ZN5Test21B1pE = constant i32* @_ZN5Test21aE
+
+namespace Test2 {
+int a = 1;
+
+struct B { 
+static int *const p; 
+};
+int *const B::p = &a;
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -983,6 +983,8 @@
   discardCleanups();
 }
 
+ASTContext &getCtx() const override { return Ctx; }
+
 void setEvaluatingDecl(APValue::LValueBase Base, APValue &Value,
EvaluatingDeclKind EDK = EvaluatingDeclKind::Ctor) {
   EvaluatingDecl = Base;
@@ -1116,8 +1118,6 @@
 
 Expr::EvalStatus &getEvalStatus() const override { return EvalStatus; }
 
-ASTContext &getCtx() const override { return Ctx; }
-
 // If we have a prior diagnostic, it will be noting that the expression
 // isn't a constant expression. This diagnostic is more important,
 // unless we require this evaluation to produce a constant expression.
@@ -2216,6 +2216,19 @@
   if (!isForManglingOnly(Kind) && Var->hasAttr())
 // FIXME: Diagnostic!
 return false;
+
+  // In CUDA/HIP device compilation, only device side variables have
+  // constant addresses.
+  if (Info.getCtx().getLangOpts().CUDA &&
+  Info.getCtx().getLangOpts().CUDAIsDevice) {
+if (!Var->hasAttr() &&
+!Var->hasAttr() &&
+!Var->hasAttr() &&
+!Var->hasAttr() &&
+!Var->getType()->isCUDADeviceBuiltinSurfaceType() &&
+!Var->getType()->isCUDADeviceBuiltinTextureType())
+

[PATCH] D117049: [OpenMP] Add support for embedding bitcode images in wrapper tool

2022-01-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 402926.
jhuber6 added a comment.

Rework commits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117049

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -76,12 +76,18 @@
cl::desc("Path for the target bitcode library"),
cl::cat(ClangLinkerWrapperCategory));
 
+static cl::opt EmbedBC(
+"target-embed-bc", cl::ZeroOrMore,
+cl::desc("Embed linked bitcode instead of an executable device image."),
+cl::init(false), cl::cat(ClangLinkerWrapperCategory));
+
 // Do not parse linker options.
 static cl::list
-HostLinkerArgs(cl::Sink, cl::desc("..."));
+HostLinkerArgs(cl::Positional,
+   cl::desc("..."));
 
 /// Path of the current binary.
-static std::string LinkerExecutable;
+static const char *LinkerExecutable;
 
 /// Temporary files created by the linker wrapper.
 static SmallVector TempFiles;
@@ -422,8 +428,8 @@
 
   std::unique_ptr Buffer =
   MemoryBuffer::getMemBuffer(Library.getMemoryBufferRef(), false);
-  if (Error Err = writeArchive(TempFile, Members, true, Library.kind(),
-true, Library.isThin(), std::move(Buffer)))
+  if (Error Err = writeArchive(TempFile, Members, true, Library.kind(), true,
+   Library.isThin(), std::move(Buffer)))
 return std::move(Err);
 
   return static_cast(TempFile);
@@ -500,7 +506,7 @@
   return static_cast(TempFile);
 }
 
-Expected link(ArrayRef InputFiles,
+Expected link(ArrayRef InputFiles,
ArrayRef LinkerArgs, Triple TheTriple,
StringRef Arch) {
   // NVPTX uses the nvlink binary to link device object files.
@@ -534,7 +540,7 @@
   CmdArgs.push_back(Arg);
 
   // Add extracted input files.
-  for (auto Input : InputFiles)
+  for (StringRef Input : InputFiles)
 CmdArgs.push_back(Input);
 
   if (sys::ExecuteAndWait(*NvlinkPath, CmdArgs))
@@ -544,7 +550,7 @@
 }
 } // namespace nvptx
 
-Expected linkDevice(ArrayRef InputFiles,
+Expected linkDevice(ArrayRef InputFiles,
  ArrayRef LinkerArgs,
  Triple TheTriple, StringRef Arch) {
   switch (TheTriple.getArch()) {
@@ -611,8 +617,10 @@
   llvm_unreachable("Invalid optimization level");
 }
 
-std::unique_ptr createLTO(const Triple &TheTriple, StringRef Arch,
-bool WholeProgram) {
+template >
+std::unique_ptr createLTO(
+const Triple &TheTriple, StringRef Arch, bool WholeProgram,
+ModuleHook Hook = [](size_t, const Module &) { return true; }) {
   lto::Config Conf;
   lto::ThinBackend Backend;
   // TODO: Handle index-only thin-LTO
@@ -631,7 +639,7 @@
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
   Conf.PTO.SLPVectorization = Conf.OptLevel > 1;
 
-  // TODO: Handle outputting bitcode using a module hook.
+  Conf.PostInternalizeModuleHook = Hook;
   if (TheTriple.isNVPTX())
 Conf.CGFileType = CGFT_AssemblyFile;
   else
@@ -651,11 +659,11 @@
  [](char C) { return C == '_' || isAlnum(C); });
 }
 
-Expected> linkBitcodeFiles(ArrayRef InputFiles,
- const Triple &TheTriple,
- StringRef Arch) {
+Error linkBitcodeFiles(SmallVectorImpl &InputFiles,
+   const Triple &TheTriple, StringRef Arch) {
   SmallVector, 4> SavedBuffers;
   SmallVector, 4> BitcodeFiles;
+  SmallVector NewInputFiles;
   StringMap UsedInRegularObj;
 
   // Search for bitcode files in the input and create an LTO input file. If it
@@ -674,6 +682,7 @@
   if (!ObjFile)
 return ObjFile.takeError();
 
+  NewInputFiles.push_back(File.str());
   for (auto &Sym : (*ObjFile)->symbols()) {
 Expected Name = Sym.getName();
 if (!Name)
@@ -693,12 +702,36 @@
   }
 
   if (BitcodeFiles.empty())
-return None;
+return Error::success();
+
+  auto HandleError = [&](std::error_code EC) {
+logAllUnhandledErrors(errorCodeToError(EC),
+  WithColor::error(errs(), LinkerExecutable));
+exit(1);
+  };
+
+  // LTO Module hook to output bitcode without running the backend.
+  auto LinkOnly = [&](size_t Task, const Module &M) {
+SmallString<128> TempFile;
+if (std::error_code EC = sys::fs::createTemporaryFile(
+"jit-" + TheTriple.getTriple(), "bc", TempFile))
+  HandleError(EC);
+std::error_code EC;
+raw_fd_ostream Linked

[PATCH] D117156: [OpenMP] Add extra flag handling to linker wrapper

2022-01-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 402928.
jhuber6 added a comment.

Rework commits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117156

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -48,6 +48,12 @@
 
 static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
 
+enum DebugKind {
+  NoDebugInfo,
+  DirectivesOnly,
+  FullDebugInfo,
+};
+
 // Mark all our options with this category, everything else (except for -help)
 // will be hidden.
 static cl::OptionCategory
@@ -58,29 +64,53 @@
 cl::desc("Strip offloading sections from the host object file."),
 cl::init(true), cl::cat(ClangLinkerWrapperCategory));
 
-static cl::opt LinkerUserPath("linker-path",
+static cl::opt LinkerUserPath("linker-path", cl::Required,
cl::desc("Path of linker binary"),
cl::cat(ClangLinkerWrapperCategory));
 
 static cl::opt
-TargetFeatures("target-feature", cl::desc("Target features for triple"),
+TargetFeatures("target-feature", cl::ZeroOrMore,
+   cl::desc("Target features for triple"),
cl::cat(ClangLinkerWrapperCategory));
 
-static cl::opt OptLevel("opt-level",
+static cl::opt OptLevel("opt-level", cl::ZeroOrMore,
  cl::desc("Optimization level for LTO"),
  cl::init("O2"),
  cl::cat(ClangLinkerWrapperCategory));
 
 static cl::opt
-BitcodeLibrary("target-library",
+BitcodeLibrary("target-library", cl::ZeroOrMore,
cl::desc("Path for the target bitcode library"),
cl::cat(ClangLinkerWrapperCategory));
 
 static cl::opt EmbedBC(
 "target-embed-bc", cl::ZeroOrMore,
-cl::desc("Embed linked bitcode instead of an executable device image."),
+cl::desc("Embed linked bitcode instead of an executable device image"),
 cl::init(false), cl::cat(ClangLinkerWrapperCategory));
 
+static cl::opt
+HostTriple("host-triple", cl::ZeroOrMore,
+   cl::desc("Triple to use for the host compilation"),
+   cl::init(sys::getDefaultTargetTriple()),
+   cl::cat(ClangLinkerWrapperCategory));
+
+static cl::opt
+PtxasOption("ptxas-option", cl::ZeroOrMore,
+cl::desc("Argument to pass to the ptxas invocation"),
+cl::cat(ClangLinkerWrapperCategory));
+
+static cl::opt Verbose("v", cl::ZeroOrMore,
+ cl::desc("Verbose output from tools"),
+ cl::init(false),
+ cl::cat(ClangLinkerWrapperCategory));
+
+static cl::opt DebugInfo(
+cl::desc("Choose debugging level:"), cl::init(NoDebugInfo),
+cl::values(clEnumValN(NoDebugInfo, "g0", "No debug information"),
+   clEnumValN(DirectivesOnly, "gline-directives-only",
+  "Direction information"),
+   clEnumValN(FullDebugInfo, "g", "Full debugging support")));
+
 // Do not parse linker options.
 static cl::list
 HostLinkerArgs(cl::Positional,
@@ -491,6 +521,14 @@
   std::string Opt = "-" + OptLevel;
   CmdArgs.push_back(*PtxasPath);
   CmdArgs.push_back(TheTriple.isArch64Bit() ? "-m64" : "-m32");
+  if (Verbose)
+CmdArgs.push_back("-v");
+  if (DebugInfo == DirectivesOnly && OptLevel[1] == '0')
+CmdArgs.push_back("-lineinfo");
+  else if (DebugInfo == FullDebugInfo && OptLevel[1] == '0')
+CmdArgs.push_back("-g");
+  if (!PtxasOption.empty())
+CmdArgs.push_back(PtxasOption);
   CmdArgs.push_back("-o");
   CmdArgs.push_back(TempFile);
   CmdArgs.push_back(Opt);
@@ -525,10 +563,13 @@
 return createFileError(TempFile, EC);
   TempFiles.push_back(static_cast(TempFile));
 
-  // TODO: Pass in arguments like `-g` and `-v` from the driver.
   SmallVector CmdArgs;
   CmdArgs.push_back(*NvlinkPath);
   CmdArgs.push_back(TheTriple.isArch64Bit() ? "-m64" : "-m32");
+  if (Verbose)
+CmdArgs.push_back("-v");
+  if (DebugInfo != NoDebugInfo)
+CmdArgs.push_back("-g");
   CmdArgs.push_back("-o");
   CmdArgs.push_back(TempFile);
   CmdArgs.push_back("-arch");
@@ -577,16 +618,16 @@
 
   switch (DI.getSeverity()) {
   case DS_Error:
-WithColor::error(errs(), LinkerExecutable) << ErrStorage;
+WithColor::error(errs(), LinkerExecutable) << ErrStorage << "\n";
 break;
   case DS_Warning:
-WithColor::warning(errs(), LinkerExecutable) << ErrStorage;
+WithColor::warning(errs(), LinkerExecutable) << ErrStorage << "\n";
 break;
   case DS_Note:
-WithColor::note(errs(), LinkerExec

[PATCH] D117246: [OpenMP] Add support for linking AMDGPU images

2022-01-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 402929.
jhuber6 added a comment.

Update commits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117246

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -512,7 +512,7 @@
   // Create a new file to write the linked device image to.
   SmallString<128> TempFile;
   if (std::error_code EC = sys::fs::createTemporaryFile(
-  TheTriple.getArchName() + "-" + Arch, "cubin", TempFile))
+  "lto-" + TheTriple.getArchName() + "-" + Arch, "cubin", TempFile))
 return createFileError(TempFile, EC);
   TempFiles.push_back(static_cast(TempFile));
 
@@ -590,6 +590,50 @@
   return static_cast(TempFile);
 }
 } // namespace nvptx
+namespace amdgcn {
+Expected link(ArrayRef InputFiles,
+   ArrayRef LinkerArgs, Triple TheTriple,
+   StringRef Arch) {
+  // AMDGPU uses the lld binary to link device object files.
+  ErrorOr LLDPath =
+  sys::findProgramByName("lld", sys::path::parent_path(LinkerExecutable));
+  if (!LLDPath)
+LLDPath = sys::findProgramByName("lld");
+  if (!LLDPath)
+return createStringError(LLDPath.getError(),
+ "Unable to find 'lld' in path");
+
+  // Create a new file to write the linked device image to.
+  SmallString<128> TempFile;
+  if (std::error_code EC = sys::fs::createTemporaryFile(
+  TheTriple.getArchName() + "-" + Arch + "-image", "out", TempFile))
+return createFileError(TempFile, EC);
+  TempFiles.push_back(static_cast(TempFile));
+
+  SmallVector CmdArgs;
+  CmdArgs.push_back(*LLDPath);
+  CmdArgs.push_back("-flavor");
+  CmdArgs.push_back("gnu");
+  CmdArgs.push_back("--no-undefined");
+  CmdArgs.push_back("-shared");
+  CmdArgs.push_back("-o");
+  CmdArgs.push_back(TempFile);
+
+  // Copy system library paths used by the host linker.
+  for (StringRef Arg : LinkerArgs)
+if (Arg.startswith("-L"))
+  CmdArgs.push_back(Arg);
+
+  // Add extracted input files.
+  for (StringRef Input : InputFiles)
+CmdArgs.push_back(Input);
+
+  if (sys::ExecuteAndWait(*LLDPath, CmdArgs))
+return createStringError(inconvertibleErrorCode(), "'lld' failed");
+
+  return static_cast(TempFile);
+}
+} // namespace amdgcn
 
 Expected linkDevice(ArrayRef InputFiles,
  ArrayRef LinkerArgs,
@@ -599,7 +643,7 @@
   case Triple::nvptx64:
 return nvptx::link(InputFiles, LinkerArgs, TheTriple, Arch);
   case Triple::amdgcn:
-// TODO: AMDGCN linking support.
+return amdgcn::link(InputFiles, LinkerArgs, TheTriple, Arch);
   case Triple::x86:
   case Triple::x86_64:
 // TODO: x86 linking support.


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -512,7 +512,7 @@
   // Create a new file to write the linked device image to.
   SmallString<128> TempFile;
   if (std::error_code EC = sys::fs::createTemporaryFile(
-  TheTriple.getArchName() + "-" + Arch, "cubin", TempFile))
+  "lto-" + TheTriple.getArchName() + "-" + Arch, "cubin", TempFile))
 return createFileError(TempFile, EC);
   TempFiles.push_back(static_cast(TempFile));
 
@@ -590,6 +590,50 @@
   return static_cast(TempFile);
 }
 } // namespace nvptx
+namespace amdgcn {
+Expected link(ArrayRef InputFiles,
+   ArrayRef LinkerArgs, Triple TheTriple,
+   StringRef Arch) {
+  // AMDGPU uses the lld binary to link device object files.
+  ErrorOr LLDPath =
+  sys::findProgramByName("lld", sys::path::parent_path(LinkerExecutable));
+  if (!LLDPath)
+LLDPath = sys::findProgramByName("lld");
+  if (!LLDPath)
+return createStringError(LLDPath.getError(),
+ "Unable to find 'lld' in path");
+
+  // Create a new file to write the linked device image to.
+  SmallString<128> TempFile;
+  if (std::error_code EC = sys::fs::createTemporaryFile(
+  TheTriple.getArchName() + "-" + Arch + "-image", "out", TempFile))
+return createFileError(TempFile, EC);
+  TempFiles.push_back(static_cast(TempFile));
+
+  SmallVector CmdArgs;
+  CmdArgs.push_back(*LLDPath);
+  CmdArgs.push_back("-flavor");
+  CmdArgs.push_back("gnu");
+  CmdArgs.push_back("--no-undefined");
+  CmdArgs.push_back("-shared");
+  CmdArgs.push_back("-o");
+  CmdArgs.push_back(TempFile);
+
+  // Copy system library paths used by the host linker.
+  for (StringRef Arg : LinkerArgs)
+if (Arg.startswith("-L"))
+  CmdArgs.push_back(Arg);
+
+  // Ad

[clang] 0e5ea40 - Fix running orc-rt tests with LLVM_BUILD_EXTERNAL_COMPILER_RT

2022-01-25 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2022-01-25T08:27:40-08:00
New Revision: 0e5ea403e8deeb5374a9072aaa12292b9c0bed30

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

LOG: Fix running orc-rt tests with LLVM_BUILD_EXTERNAL_COMPILER_RT

Add missing dependency on llvm-jitlink when building compiler-rt with
LLVM_BUILD_EXTERNAL_COMPILER_RT. Previously we would
non-deterministically fail the tests due to the missing binary.

rdar://87247681

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

Added: 


Modified: 
clang/runtime/CMakeLists.txt

Removed: 




diff  --git a/clang/runtime/CMakeLists.txt b/clang/runtime/CMakeLists.txt
index 0388008792511..ca7e17927ee1f 100644
--- a/clang/runtime/CMakeLists.txt
+++ b/clang/runtime/CMakeLists.txt
@@ -132,7 +132,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS 
${COMPILER_RT_SRC_ROOT}/)
   if(LLVM_INCLUDE_TESTS)
 # Add binaries that compiler-rt tests depend on.
 set(COMPILER_RT_TEST_DEPENDENCIES
-  FileCheck count not llvm-nm llvm-objdump llvm-symbolizer)
+  FileCheck count not llvm-nm llvm-objdump llvm-symbolizer llvm-jitlink)
 
 # Add top-level targets for various compiler-rt test suites.
 set(COMPILER_RT_TEST_SUITES check-fuzzer check-asan check-hwasan 
check-asan-dynamic check-dfsan



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


[PATCH] D118087: Fix running orc-rt tests with LLVM_BUILD_EXTERNAL_COMPILER_RT

2022-01-25 Thread Ben Langmuir 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 rG0e5ea403e8de: Fix running orc-rt tests with 
LLVM_BUILD_EXTERNAL_COMPILER_RT (authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118087

Files:
  clang/runtime/CMakeLists.txt


Index: clang/runtime/CMakeLists.txt
===
--- clang/runtime/CMakeLists.txt
+++ clang/runtime/CMakeLists.txt
@@ -132,7 +132,7 @@
   if(LLVM_INCLUDE_TESTS)
 # Add binaries that compiler-rt tests depend on.
 set(COMPILER_RT_TEST_DEPENDENCIES
-  FileCheck count not llvm-nm llvm-objdump llvm-symbolizer)
+  FileCheck count not llvm-nm llvm-objdump llvm-symbolizer llvm-jitlink)
 
 # Add top-level targets for various compiler-rt test suites.
 set(COMPILER_RT_TEST_SUITES check-fuzzer check-asan check-hwasan 
check-asan-dynamic check-dfsan


Index: clang/runtime/CMakeLists.txt
===
--- clang/runtime/CMakeLists.txt
+++ clang/runtime/CMakeLists.txt
@@ -132,7 +132,7 @@
   if(LLVM_INCLUDE_TESTS)
 # Add binaries that compiler-rt tests depend on.
 set(COMPILER_RT_TEST_DEPENDENCIES
-  FileCheck count not llvm-nm llvm-objdump llvm-symbolizer)
+  FileCheck count not llvm-nm llvm-objdump llvm-symbolizer llvm-jitlink)
 
 # Add top-level targets for various compiler-rt test suites.
 set(COMPILER_RT_TEST_SUITES check-fuzzer check-asan check-hwasan check-asan-dynamic check-dfsan
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118155: [OpenMP] Improve symbol resolution for OpenMP Offloading LTO

2022-01-25 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield, ronlieb, saiislam.
Herald added subscribers: guansong, inglorion, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch improves the symbol resolution done for LTO with offloading
applications. The symbol resolution done here allows the LTO backend to
internalize more functions. The symbol resoltion done is a simplified
view that does not take into account various options like `--wrap` or
`--dyanimic-list` and always assumes we are creating a shared object.
The actual target may be an executable, but semantically it is used as a
shared object because certain objects need to be visible outside of the
executable when they are read by the OpenMP plugin.

Depends on D117246 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118155

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -750,6 +750,7 @@
   SmallVector, 4> BitcodeFiles;
   SmallVector NewInputFiles;
   StringMap UsedInRegularObj;
+  StringMap UsedInSharedLib;
 
   // Search for bitcode files in the input and create an LTO input file. If it
   // is not a bitcode file, scan its symbol table for symbols we need to
@@ -773,7 +774,11 @@
 if (!Name)
   return Name.takeError();
 
-UsedInRegularObj[*Name] = true;
+// Record if we've seen these symbols in any object or shared libraries.
+if ((*ObjFile)->isRelocatableObject()) {
+  UsedInRegularObj[*Name] = true;
+} else
+  UsedInSharedLib[*Name] = true;
   }
 } else {
   Expected> InputFileOrErr =
@@ -781,6 +786,7 @@
   if (!InputFileOrErr)
 return InputFileOrErr.takeError();
 
+  // Save the input file and the buffer associated with its memory.
   BitcodeFiles.push_back(std::move(*InputFileOrErr));
   SavedBuffers.push_back(std::move(*BufferOrErr));
 }
@@ -811,22 +817,16 @@
 return false;
   };
 
-  // We have visibility of the whole program if every input is bitcode, all
-  // inputs are statically linked so there should be no external references.
+  // We assume visibility of the whole program if every input file was bitcode.
   bool WholeProgram = BitcodeFiles.size() == InputFiles.size();
   auto LTOBackend = (EmbedBC)
 ? createLTO(TheTriple, Arch, WholeProgram, LinkOnly)
 : createLTO(TheTriple, Arch, WholeProgram);
 
-  // TODO: Run more tests to verify that this is correct.
-  // Create the LTO instance with the necessary config and add the bitcode files
-  // to it after resolving symbols. We make a few assumptions about symbol
-  // resolution.
-  // 1. The target is going to be a stand-alone executable file.
-  // 2. We do not support relocatable object files.
-  // 3. All inputs are relocatable object files extracted from host binaries, so
-  //there is no resolution to a dynamic library.
-  StringMap PrevailingSymbols;
+  // We need to resolve the symbols so the LTO backend knows which symbols need
+  // to be kept or can be internalized. This is a simplified symbol resolution
+  // scheme to approximate the full resolution a linker would do.
+  DenseSet PrevailingSymbols;
   for (auto &BitcodeFile : BitcodeFiles) {
 const auto Symbols = BitcodeFile->symbols();
 SmallVector Resolutions(Symbols.size());
@@ -835,35 +835,43 @@
   lto::SymbolResolution &Res = Resolutions[Idx++];
 
   // We will use this as the prevailing symbol definition in LTO unless
-  // it is undefined in the module or another symbol has already been used.
-  Res.Prevailing = !Sym.isUndefined() && !PrevailingSymbols[Sym.getName()];
-
-  // We need LTO to preserve symbols referenced in other object files, or
-  // are needed by the rest of the toolchain.
+  // it is undefined or another definition has already been used.
+  Res.Prevailing =
+  !Sym.isUndefined() && PrevailingSymbols.insert(Sym.getName()).second;
+
+  // We need LTO to preseve the following global symbols:
+  // 1) Symbols used in regular objects.
+  // 2) Sections that will be given a __start/__stop symbol.
+  // 3) Prevailing symbols that are needed visibile to external libraries.
   Res.VisibleToRegularObj =
   UsedInRegularObj[Sym.getName()] ||
   isValidCIdentifier(Sym.getSectionName()) ||
-  (Res.Prevailing && Sym.getName().startswith("__omp"));
-
-  // We do not currently support shared libraries, so no symbols will be
-  // referenced externally by shared libraries.
-  Res.ExportDynamic = false;
-
-  // The res

[PATCH] D45438: [CodeView] Enable debugging of captured variables within C++ lambdas

2022-01-25 Thread Brock Wyma via Phabricator via cfe-commits
bwyma added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:812-814
+  // CodeView types with C++ mangling need a type identifier.
+  if (CGM.getCodeGenOpts().EmitCodeView)
+return true;

dblaikie wrote:
> rnk wrote:
> > rnk wrote:
> > > dblaikie wrote:
> > > > Just came across this code today - it's /probably/ a problem for LTO. 
> > > > LLVM IR linking depends on the identifier to determine if two structs 
> > > > are the same for linkage purposes - so if an identifier is added for a 
> > > > non-linkage (local/not externally visible) type, LLVM will consider 
> > > > them to be the same even though they're unrelated:
> > > > ```
> > > > namespace { struct t1 { int i; int j; }; }
> > > > t1 v1;
> > > > void *v3 = &v1;
> > > > ```
> > > > ```
> > > > namespace { struct t1 { int i; }; }
> > > > t1 v1;
> > > > void *v2 = &v1;
> > > > ```
> > > > ```
> > > > $ clang++-tot -emit-llvm -S a.cpp b.cpp -g -gcodeview  && 
> > > > ~/dev/llvm/build/default/bin/llvm-link -o ab.bc a.ll b.ll && 
> > > > ~/dev/llvm/build/default/bin/llvm-dis ab.bc && cat ab.ll | grep "\"t1\""
> > > > !8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", 
> > > > scope: !9, file: !3, line: 1, size: 64, flags: DIFlagTypePassByValue, 
> > > > elements: !10, identifier: "_ZTSN12_GLOBAL__N_12t1E")
> > > > $ clang++-tot -emit-llvm -S a.cpp b.cpp -g && 
> > > > ~/dev/llvm/build/default/bin/llvm-link -o ab.bc a.ll b.ll && 
> > > > ~/dev/llvm/build/default/bin/llvm-dis ab.bc && cat ab.ll | grep "\"t1\""
> > > > !8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", 
> > > > scope: !9, file: !3, line: 1, size: 64, flags: DIFlagTypePassByValue, 
> > > > elements: !10)
> > > > !21 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", 
> > > > scope: !9, file: !17, line: 1, size: 32, flags: DIFlagTypePassByValue, 
> > > > elements: !22)
> > > > ```
> > > > 
> > > > So in linking, now both `a.cpp` and `b.cpp` refer to a single `t1` type 
> > > > (in this case, it looks like the first one - the 64 bit wide one).
> > > > 
> > > > If CodeView actually can't represent these two distinct types with the 
> > > > same name in the same object file, so be it? But this looks like it's 
> > > > likely to cause problems for consumers/users.
> > > If you use the MSVC ABI, we will assign unique identifiers to these two 
> > > structs:
> > > ```
> > > !9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", 
> > > scope: !10, file: !7, line: 1, size: 64, flags: DIFlagTypePassByValue, 
> > > elements: !11, identifier: ".?AUt1@?A0xF964240C@@")
> > > ```
> > > 
> > > The `A0xF964240C` is set up here, and it is based on the source file path 
> > > (the hash will only be unique when source file paths are unique across 
> > > the build):
> > > https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/MicrosoftMangle.cpp#L464
> > > ```
> > >   // It's important to make the mangled names unique because, when 
> > > CodeView
> > >   // debug info is in use, the debugger uses mangled type names to 
> > > distinguish
> > >   // between otherwise identically named types in anonymous namespaces.
> > > ```
> > > 
> > > Maybe this should use a "is MSVC ABI" check instead, since that is what 
> > > controls whether the identifier will be unique, and the unique-ness is 
> > > what matters for LTO and PDBs.
> > After thinking about it some more, see the comment I added here: 
> > rG59320fc9d78237a5f9fdd6a5030d6554bb6976ce
> > 
> > ```
> > // If the type is not externally visible, it should be unique to the 
> > current TU,
> > // and should not need an identifier to participate in type deduplication.
> > // However, when emitting CodeView, the format internally uses these
> > // unique type name identifers for references between debug info. For 
> > example,
> > // the method of a class in an anonymous namespace uses the identifer to 
> > refer
> > // to its parent class. The Microsoft C++ ABI attempts to provide unique 
> > names
> > // for such types, so when emitting CodeView, always use identifiers for C++
> > // types. This may create problems when attempting to emit CodeView when 
> > the MS
> > // C++ ABI is not in use.
> > ```
> > 
> > I think type identifiers are pretty crucial for CodeView functionality. The 
> > debugger won't be able to link a method to its class without them. 
> > Therefore, I think it's better to leave this as it is. The bad experience 
> > of duplicate type identifiers is better than the lack of functionality from 
> > not emitting identifiers at all for non-externally visible types.
> Yeah, thanks for explaining/adding the comment - that about covers it.
> 
> 
> Hmm, do these identifiers just need to only be unique within a single object 
> file to provide the name referencing mechanics? Perhaps we could generate 
> them later to ensure they're unique - rather than risk collapsing them while 
> linking?
> 
> (at least here's an obscure case

[clang] 64ba462 - [clang][dataflow] Add a transfer function for InitListExpr

2022-01-25 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2022-01-25T16:28:15Z
New Revision: 64ba462b6e398bdb33464963f7d6274320f84370

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

LOG: [clang][dataflow] Add a transfer function for InitListExpr

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

Reviewed-by: xazax.hun

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/Value.h
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/Value.h 
b/clang/include/clang/Analysis/FlowSensitive/Value.h
index d1de2b64fd95a..47e4d31c832bb 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Value.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Value.h
@@ -100,15 +100,18 @@ class StructValue final : public Value {
 return Val->getKind() == Kind::Struct;
   }
 
-  /// Returns the child value for `D`.
+  /// Returns the child value that is assigned for `D`.
   Value &getChild(const ValueDecl &D) const {
 auto It = Children.find(&D);
 assert(It != Children.end());
 return *It->second;
   }
 
+  /// Assigns `Val` as the child value for `D`.
+  void setChild(const ValueDecl &D, Value &Val) { Children[&D] = &Val; }
+
 private:
-  const llvm::DenseMap Children;
+  llvm::DenseMap Children;
 };
 
 } // namespace dataflow

diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 32a05333923f5..7c5e063278d78 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -22,9 +22,11 @@
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Basic/OperatorKinds.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace dataflow {
@@ -414,6 +416,33 @@ class TransferVisitor : public 
ConstStmtVisitor {
   Env.setValue(Loc, *Val);
   }
 
+  void VisitInitListExpr(const InitListExpr *S) {
+QualType Type = S->getType();
+
+auto &Loc = Env.createStorageLocation(*S);
+Env.setStorageLocation(*S, Loc);
+
+auto *Val = Env.createValue(Type);
+if (Val == nullptr)
+  return;
+
+Env.setValue(Loc, *Val);
+
+if (Type->isStructureOrClassType()) {
+  for (auto IT : llvm::zip(Type->getAsRecordDecl()->fields(), S->inits())) 
{
+const FieldDecl *Field = std::get<0>(IT);
+assert(Field != nullptr);
+
+const Expr *Init = std::get<1>(IT);
+assert(Init != nullptr);
+
+if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
+  cast(Val)->setChild(*Field, *InitVal);
+  }
+}
+// FIXME: Implement array initialization.
+  }
+
   // FIXME: Add support for:
   // - CXXBoolLiteralExpr
 

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index c1eaf281ddc49..cd3e58207680a 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1865,4 +1865,91 @@ TEST_F(TransferTest, VarDeclInDoWhile) {
   });
 }
 
+TEST_F(TransferTest, AggregateInitialization) {
+  std::string BracesCode = R"(
+struct A {
+  int Foo;
+};
+
+struct B {
+  int Bar;
+  A Baz;
+  int Qux;
+};
+
+void target(int BarArg, int FooArg, int QuxArg) {
+  B Quux{BarArg, {FooArg}, QuxArg};
+  /*[[p]]*/
+}
+  )";
+  std::string BraceEllisionCode = R"(
+struct A {
+  int Foo;
+};
+
+struct B {
+  int Bar;
+  A Baz;
+  int Qux;
+};
+
+void target(int BarArg, int FooArg, int QuxArg) {
+  B Quux = {BarArg, FooArg, QuxArg};
+  /*[[p]]*/
+}
+  )";
+  for (const std::string &Code : {BracesCode, BraceEllisionCode}) {
+runDataflow(
+Code, [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+  ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+  const Environment &Env = Results[0].second.Env;
+
+  const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+  ASSERT_THAT(FooDecl, NotNull());
+
+  const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+  ASSERT_THAT(BarDecl, NotNull());
+
+  const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+  ASSERT_THAT(BazDecl, NotNull());
+
+  const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+  ASSERT_THA

[PATCH] D118119: [clang][dataflow] Add a transfer function for InitListExpr

2022-01-25 Thread Stanislav Gatev 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 rG64ba462b6e39: [clang][dataflow] Add a transfer function for 
InitListExpr (authored by sgatev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118119

Files:
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1865,4 +1865,91 @@
   });
 }
 
+TEST_F(TransferTest, AggregateInitialization) {
+  std::string BracesCode = R"(
+struct A {
+  int Foo;
+};
+
+struct B {
+  int Bar;
+  A Baz;
+  int Qux;
+};
+
+void target(int BarArg, int FooArg, int QuxArg) {
+  B Quux{BarArg, {FooArg}, QuxArg};
+  /*[[p]]*/
+}
+  )";
+  std::string BraceEllisionCode = R"(
+struct A {
+  int Foo;
+};
+
+struct B {
+  int Bar;
+  A Baz;
+  int Qux;
+};
+
+void target(int BarArg, int FooArg, int QuxArg) {
+  B Quux = {BarArg, FooArg, QuxArg};
+  /*[[p]]*/
+}
+  )";
+  for (const std::string &Code : {BracesCode, BraceEllisionCode}) {
+runDataflow(
+Code, [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+  ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+  const Environment &Env = Results[0].second.Env;
+
+  const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+  ASSERT_THAT(FooDecl, NotNull());
+
+  const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+  ASSERT_THAT(BarDecl, NotNull());
+
+  const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
+  ASSERT_THAT(BazDecl, NotNull());
+
+  const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+  ASSERT_THAT(QuxDecl, NotNull());
+
+  const ValueDecl *FooArgDecl = findValueDecl(ASTCtx, "FooArg");
+  ASSERT_THAT(FooArgDecl, NotNull());
+
+  const ValueDecl *BarArgDecl = findValueDecl(ASTCtx, "BarArg");
+  ASSERT_THAT(BarArgDecl, NotNull());
+
+  const ValueDecl *QuxArgDecl = findValueDecl(ASTCtx, "QuxArg");
+  ASSERT_THAT(QuxArgDecl, NotNull());
+
+  const ValueDecl *QuuxDecl = findValueDecl(ASTCtx, "Quux");
+  ASSERT_THAT(QuuxDecl, NotNull());
+
+  const auto *FooArgVal =
+  cast(Env.getValue(*FooArgDecl, SkipPast::None));
+  const auto *BarArgVal =
+  cast(Env.getValue(*BarArgDecl, SkipPast::None));
+  const auto *QuxArgVal =
+  cast(Env.getValue(*QuxArgDecl, SkipPast::None));
+
+  const auto *QuuxVal =
+  cast(Env.getValue(*QuuxDecl, SkipPast::None));
+  ASSERT_THAT(QuuxVal, NotNull());
+
+  const auto *BazVal = cast(&QuuxVal->getChild(*BazDecl));
+  ASSERT_THAT(BazVal, NotNull());
+
+  EXPECT_EQ(&QuuxVal->getChild(*BarDecl), BarArgVal);
+  EXPECT_EQ(&BazVal->getChild(*FooDecl), FooArgVal);
+  EXPECT_EQ(&QuuxVal->getChild(*QuxDecl), QuxArgVal);
+});
+  }
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -22,9 +22,11 @@
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Basic/OperatorKinds.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace dataflow {
@@ -414,6 +416,33 @@
   Env.setValue(Loc, *Val);
   }
 
+  void VisitInitListExpr(const InitListExpr *S) {
+QualType Type = S->getType();
+
+auto &Loc = Env.createStorageLocation(*S);
+Env.setStorageLocation(*S, Loc);
+
+auto *Val = Env.createValue(Type);
+if (Val == nullptr)
+  return;
+
+Env.setValue(Loc, *Val);
+
+if (Type->isStructureOrClassType()) {
+  for (auto IT : llvm::zip(Type->getAsRecordDecl()->fields(), S->inits())) {
+const FieldDecl *Field = std::get<0>(IT);
+assert(Field != nullptr);
+
+const Expr *Init = std::get<1>(IT);
+assert(Init != nullptr);
+
+if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
+  cast(Val)->setChild(*Field, *InitVal);
+  }
+}
+// FIXME: Implement array initialization.
+  }
+
   // FIXME: Add support for:
   // - CXXBoolLiteralExpr
 
Index: clang/include/clang/Analysis/FlowSensitive/Value.h
=

[PATCH] D118110: [CMake] [Clang] Add CMake build option to specify long double format on PowerPC

2022-01-25 Thread Jinsong Ji via Phabricator via cfe-commits
jsji added a comment.

In D118110#3269450 , @nemanjai wrote:

> It is probably not worth the effort since there won't be that many test cases 
> that test the front end's IR generation for `long double`, but there should 
> be a way to set up lit to know the default through its configuration files.

Yes, that is not a must for now, but we should try to do it .

> There's one thing uncertain: whether this config only applies to ppc64le?

Let us apply it to ppc64le only for now.




Comment at: clang/CMakeLists.txt:240
 
+set(ENABLE_PPC_IEEELONGDOUBLE OFF CACHE BOOL
+"Enable IEEE binary128 as default long double format on PowerPC.")

nemanjai wrote:
> Do we need any error checking here? What happens if someone erroneously sets 
> this on an AIX build (or big endian Linux, FreeBSD, etc.)?
How about `CLANG_DEFAULT_IEEELONGDOUBLE_ON_PPC_LINUX` similar to 
`CLANG_DEFAULT_PIE_ON_LINUX`?



Comment at: clang/include/clang/Driver/ToolChain.h:413
+  /// Check whether use IEEE binary128 as long double format by default.
+  bool useIEEELongDouble() const;
+

defaultToIEEELongDouble?



Comment at: clang/lib/Driver/ToolChain.cpp:113
+bool ToolChain::useIEEELongDouble() const {
+  return ENABLE_PPC_IEEELONGDOUBLE;
+}

Check OS here ?

eg: CLANG_DEFAULT_IEEELONGDOUBLE_ON_PPC_LINUX && OS.Linux() 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118110

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


[PATCH] D117647: [RISCV] Add passthru operand for RVV nomask load intrinsics.

2022-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117647

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


[PATCH] D118152: [clang][deps] Adapt test to be compatible when the assembler is called by default

2022-01-25 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/test/ClangScanDeps/headerwithdirname.cpp:16
 
-// CHECK: headerwithdirname_input.o
+// CHECK: headerwithdirname_input{{.*}}{{.o|.s}}
 // CHECK-NEXT: headerwithdirname_input.cpp

Why is `{{.*}}` necessary?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118152

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


[PATCH] D117681: [RISCV] Add the policy operand for some masked RVV ternary IR intrinsics.

2022-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.
Herald added a subscriber: pcwang-thead.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td:2342
 defm _VS : VPseudoTernary,
-   Sched<[WriteVIRedV, ReadVIRedV, ReadVIRedV, ReadVIRedV, 
ReadVMask]>;
+   Sched<[WriteVIWRedV, ReadVIWRedV, ReadVIWRedV, ReadVIWRedV, 
ReadVMask]>;
   }

This change doesn't look right. Or it's unrelated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117681

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


[PATCH] D118158: [OpenCL] opencl-c.h: refactor named addrspace builtins

2022-01-25 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: clang.
Herald added subscribers: Naghasan, ldrumm, Anastasia, yaxunl.
svenvh requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The named address space overloads of builtins that take a pointer
argument are conditionalized on the `__opencl_c_generic_address_space`
feature macro (in a `#else` body).  Introduce an internal feature
macro instead, such that their availability can be controlled in a
single place and independently of the generic address space feature
macro.

This commit does not change the available builtins.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118158

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Headers/opencl-c.h

Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -7285,7 +7285,9 @@
 half8 __ovld fract(half8 x, half8 *iptr);
 half16 __ovld fract(half16 x, half16 *iptr);
 #endif //cl_khr_fp16
-#else
+#endif //defined(__opencl_c_generic_address_space)
+
+#if defined(__opencl_c_named_addrsp_builtins)
 float __ovld fract(float x, __global float *iptr);
 float2 __ovld fract(float2 x, __global float2 *iptr);
 float3 __ovld fract(float3 x, __global float3 *iptr);
@@ -7344,7 +7346,7 @@
 half8 __ovld fract(half8 x, __private half8 *iptr);
 half16 __ovld fract(half16 x, __private half16 *iptr);
 #endif //cl_khr_fp16
-#endif //defined(__opencl_c_generic_address_space)
+#endif //defined(__opencl_c_named_addrsp_builtins)
 
 /**
  * Extract mantissa and exponent from x. For each
@@ -7375,7 +7377,9 @@
 half8 __ovld frexp(half8 x, int8 *exp);
 half16 __ovld frexp(half16 x, int16 *exp);
 #endif //cl_khr_fp16
-#else
+#endif //defined(__opencl_c_generic_address_space)
+
+#if defined(__opencl_c_named_addrsp_builtins)
 float __ovld frexp(float x, __global int *exp);
 float2 __ovld frexp(float2 x, __global int2 *exp);
 float3 __ovld frexp(float3 x, __global int3 *exp);
@@ -7434,7 +7438,7 @@
 half8 __ovld frexp(half8 x, __private int8 *exp);
 half16 __ovld frexp(half16 x, __private int16 *exp);
 #endif //cl_khr_fp16
-#endif //defined(__opencl_c_generic_address_space)
+#endif //defined(__opencl_c_named_addrsp_builtins)
 
 /**
  * Compute the value of the square root of x^2 + y^2
@@ -7582,7 +7586,9 @@
 half8 __ovld lgamma_r(half8 x, int8 *signp);
 half16 __ovld lgamma_r(half16 x, int16 *signp);
 #endif //cl_khr_fp16
-#else
+#endif //defined(__opencl_c_generic_address_space)
+
+#if defined(__opencl_c_named_addrsp_builtins)
 float __ovld lgamma_r(float x, __global int *signp);
 float2 __ovld lgamma_r(float2 x, __global int2 *signp);
 float3 __ovld lgamma_r(float3 x, __global int3 *signp);
@@ -7641,7 +7647,7 @@
 half8 __ovld lgamma_r(half8 x, __private int8 *signp);
 half16 __ovld lgamma_r(half16 x, __private int16 *signp);
 #endif //cl_khr_fp16
-#endif //defined(__opencl_c_generic_address_space)
+#endif //defined(__opencl_c_named_addrsp_builtins)
 
 /**
  * Compute natural logarithm.
@@ -7888,7 +7894,9 @@
 half8 __ovld modf(half8 x, half8 *iptr);
 half16 __ovld modf(half16 x, half16 *iptr);
 #endif //cl_khr_fp16
-#else
+#endif //defined(__opencl_c_generic_address_space)
+
+#if defined(__opencl_c_named_addrsp_builtins)
 float __ovld modf(float x, __global float *iptr);
 float2 __ovld modf(float2 x, __global float2 *iptr);
 float3 __ovld modf(float3 x, __global float3 *iptr);
@@ -7947,7 +7955,7 @@
 half8 __ovld modf(half8 x, __private half8 *iptr);
 half16 __ovld modf(half16 x, __private half16 *iptr);
 #endif //cl_khr_fp16
-#endif //defined(__opencl_c_generic_address_space)
+#endif //defined(__opencl_c_named_addrsp_builtins)
 
 /**
  * Returns a quiet NaN. The nancode may be placed
@@ -8147,9 +8155,10 @@
 half4 __ovld remquo(half4 x, half4 y, int4 *quo);
 half8 __ovld remquo(half8 x, half8 y, int8 *quo);
 half16 __ovld remquo(half16 x, half16 y, int16 *quo);
-
 #endif //cl_khr_fp16
-#else
+#endif //defined(__opencl_c_generic_address_space)
+
+#if defined(__opencl_c_named_addrsp_builtins)
 float __ovld remquo(float x, float y, __global int *quo);
 float2 __ovld remquo(float2 x, float2 y, __global int2 *quo);
 float3 __ovld remquo(float3 x, float3 y, __global int3 *quo);
@@ -8208,7 +8217,7 @@
 half8 __ovld remquo(half8 x, half8 y, __private int8 *quo);
 half16 __ovld remquo(half16 x, half16 y, __private int16 *quo);
 #endif //cl_khr_fp16
-#endif //defined(__opencl_c_generic_address_space)
+#endif //defined(__opencl_c_named_addrsp_builtins)
 /**
  * Round to integral value (using round to nearest
  * even rounding mode) in floating-point format.
@@ -8372,7 +8381,9 @@
 half8 __ovld sincos(half8 x, half8 *cosval);
 half16 __ovld sincos(half16 x, half16 *cosval);
 #endif //cl_khr_fp16
-#else
+#endif //defined(__opencl_c_generic_address_space)
+
+#if defined(__opencl_c_named_addrsp_builtins)
 float __ovld sincos(float x, __global float *cosval);
 float2 __ovl

[PATCH] D117913: [Clang][RISCV] Guard vmulh, vsmul correctly

2022-01-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117913

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


[PATCH] D118109: [clang] Replace `std::vector` use in Syntax

2022-01-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118109

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


[PATCH] D45438: [CodeView] Enable debugging of captured variables within C++ lambdas

2022-01-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:812-814
+  // CodeView types with C++ mangling need a type identifier.
+  if (CGM.getCodeGenOpts().EmitCodeView)
+return true;

bwyma wrote:
> dblaikie wrote:
> > rnk wrote:
> > > rnk wrote:
> > > > dblaikie wrote:
> > > > > Just came across this code today - it's /probably/ a problem for LTO. 
> > > > > LLVM IR linking depends on the identifier to determine if two structs 
> > > > > are the same for linkage purposes - so if an identifier is added for 
> > > > > a non-linkage (local/not externally visible) type, LLVM will consider 
> > > > > them to be the same even though they're unrelated:
> > > > > ```
> > > > > namespace { struct t1 { int i; int j; }; }
> > > > > t1 v1;
> > > > > void *v3 = &v1;
> > > > > ```
> > > > > ```
> > > > > namespace { struct t1 { int i; }; }
> > > > > t1 v1;
> > > > > void *v2 = &v1;
> > > > > ```
> > > > > ```
> > > > > $ clang++-tot -emit-llvm -S a.cpp b.cpp -g -gcodeview  && 
> > > > > ~/dev/llvm/build/default/bin/llvm-link -o ab.bc a.ll b.ll && 
> > > > > ~/dev/llvm/build/default/bin/llvm-dis ab.bc && cat ab.ll | grep 
> > > > > "\"t1\""
> > > > > !8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: 
> > > > > "t1", scope: !9, file: !3, line: 1, size: 64, flags: 
> > > > > DIFlagTypePassByValue, elements: !10, identifier: 
> > > > > "_ZTSN12_GLOBAL__N_12t1E")
> > > > > $ clang++-tot -emit-llvm -S a.cpp b.cpp -g && 
> > > > > ~/dev/llvm/build/default/bin/llvm-link -o ab.bc a.ll b.ll && 
> > > > > ~/dev/llvm/build/default/bin/llvm-dis ab.bc && cat ab.ll | grep 
> > > > > "\"t1\""
> > > > > !8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: 
> > > > > "t1", scope: !9, file: !3, line: 1, size: 64, flags: 
> > > > > DIFlagTypePassByValue, elements: !10)
> > > > > !21 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: 
> > > > > "t1", scope: !9, file: !17, line: 1, size: 32, flags: 
> > > > > DIFlagTypePassByValue, elements: !22)
> > > > > ```
> > > > > 
> > > > > So in linking, now both `a.cpp` and `b.cpp` refer to a single `t1` 
> > > > > type (in this case, it looks like the first one - the 64 bit wide 
> > > > > one).
> > > > > 
> > > > > If CodeView actually can't represent these two distinct types with 
> > > > > the same name in the same object file, so be it? But this looks like 
> > > > > it's likely to cause problems for consumers/users.
> > > > If you use the MSVC ABI, we will assign unique identifiers to these two 
> > > > structs:
> > > > ```
> > > > !9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", 
> > > > scope: !10, file: !7, line: 1, size: 64, flags: DIFlagTypePassByValue, 
> > > > elements: !11, identifier: ".?AUt1@?A0xF964240C@@")
> > > > ```
> > > > 
> > > > The `A0xF964240C` is set up here, and it is based on the source file 
> > > > path (the hash will only be unique when source file paths are unique 
> > > > across the build):
> > > > https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/MicrosoftMangle.cpp#L464
> > > > ```
> > > >   // It's important to make the mangled names unique because, when 
> > > > CodeView
> > > >   // debug info is in use, the debugger uses mangled type names to 
> > > > distinguish
> > > >   // between otherwise identically named types in anonymous namespaces.
> > > > ```
> > > > 
> > > > Maybe this should use a "is MSVC ABI" check instead, since that is what 
> > > > controls whether the identifier will be unique, and the unique-ness is 
> > > > what matters for LTO and PDBs.
> > > After thinking about it some more, see the comment I added here: 
> > > rG59320fc9d78237a5f9fdd6a5030d6554bb6976ce
> > > 
> > > ```
> > > // If the type is not externally visible, it should be unique to the 
> > > current TU,
> > > // and should not need an identifier to participate in type deduplication.
> > > // However, when emitting CodeView, the format internally uses these
> > > // unique type name identifers for references between debug info. For 
> > > example,
> > > // the method of a class in an anonymous namespace uses the identifer to 
> > > refer
> > > // to its parent class. The Microsoft C++ ABI attempts to provide unique 
> > > names
> > > // for such types, so when emitting CodeView, always use identifiers for 
> > > C++
> > > // types. This may create problems when attempting to emit CodeView when 
> > > the MS
> > > // C++ ABI is not in use.
> > > ```
> > > 
> > > I think type identifiers are pretty crucial for CodeView functionality. 
> > > The debugger won't be able to link a method to its class without them. 
> > > Therefore, I think it's better to leave this as it is. The bad experience 
> > > of duplicate type identifiers is better than the lack of functionality 
> > > from not emitting identifiers at all for non-externally visible types.
> > Yeah, thanks for explaining/adding the comment - that about covers it.
> > 
> > 
> > Hmm, do these identifiers 

[clang] bd1fac2 - Add assert on End iteration distance to Rewriter::getRewrittenText.

2022-01-25 Thread Yitzhak Mandelbaum via cfe-commits

Author: Ashley Hedberg
Date: 2022-01-25T17:26:13Z
New Revision: bd1fac2fafd7a1afacce05cd53a3741a2214f5f1

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

LOG: Add assert on End iteration distance to Rewriter::getRewrittenText.

I currently have code that is crashing in the second std::advance call,
and it was not straightforward to identify the problem, as the first line
of the stacktrace is in RopePieceBTreeIterator::operator++:

```

*** SIGILL; stack trace: ***
PC: clang/include/clang/Rewrite/Core/RewriteRope.h:119 
clang::RopePieceBTreeIterator::operator++()
../include/c++/v1/__iterator/advance.h:35 std::__u::__advance<>()
../include/c++/v1/__iterator/advance.h:65 std::__u::advance<>()
clang/lib/Rewrite/Rewriter.cpp:228 clang::Rewriter::getRewrittenText()
clang/include/clang/Rewrite/Core/Rewriter.h:106 
clang::Rewriter::getRewrittenText()
```

Adding an assertion produces a friendlier error message for the caller.

Reviewed By: gribozavr2

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

Added: 


Modified: 
clang/lib/Rewrite/Rewriter.cpp

Removed: 




diff  --git a/clang/lib/Rewrite/Rewriter.cpp b/clang/lib/Rewrite/Rewriter.cpp
index 3b06afc76e16e..8950bfb7c4dcc 100644
--- a/clang/lib/Rewrite/Rewriter.cpp
+++ b/clang/lib/Rewrite/Rewriter.cpp
@@ -223,6 +223,7 @@ std::string Rewriter::getRewrittenText(CharSourceRange 
Range) const {
   RewriteBuffer::iterator Start = RB.begin();
   std::advance(Start, StartOff);
   RewriteBuffer::iterator End = Start;
+  assert(EndOff >= StartOff && "Invalid iteration distance");
   std::advance(End, EndOff-StartOff);
 
   return std::string(Start, End);



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


[PATCH] D117579: Add assert on End iteration distance to Rewriter::getRewrittenText.

2022-01-25 Thread Yitzhak Mandelbaum 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 rGbd1fac2fafd7: Add assert on End iteration distance to 
Rewriter::getRewrittenText. (authored by ahedberg, committed by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117579

Files:
  clang/lib/Rewrite/Rewriter.cpp


Index: clang/lib/Rewrite/Rewriter.cpp
===
--- clang/lib/Rewrite/Rewriter.cpp
+++ clang/lib/Rewrite/Rewriter.cpp
@@ -223,6 +223,7 @@
   RewriteBuffer::iterator Start = RB.begin();
   std::advance(Start, StartOff);
   RewriteBuffer::iterator End = Start;
+  assert(EndOff >= StartOff && "Invalid iteration distance");
   std::advance(End, EndOff-StartOff);
 
   return std::string(Start, End);


Index: clang/lib/Rewrite/Rewriter.cpp
===
--- clang/lib/Rewrite/Rewriter.cpp
+++ clang/lib/Rewrite/Rewriter.cpp
@@ -223,6 +223,7 @@
   RewriteBuffer::iterator Start = RB.begin();
   std::advance(Start, StartOff);
   RewriteBuffer::iterator End = Start;
+  assert(EndOff >= StartOff && "Invalid iteration distance");
   std::advance(End, EndOff-StartOff);
 
   return std::string(Start, End);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118161: [CMake] Set sanitizer test C++ library on Linux

2022-01-25 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: leonardchan, haowei.
Herald added subscribers: abrachet, mgorny.
phosek requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We always want to use the in-tree libc++ for tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118161

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -134,6 +134,8 @@
 set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
 set(RUNTIMES_${target}_SANITIZER_CXX_ABI "libc++" CACHE STRING "")
 set(RUNTIMES_${target}_SANITIZER_CXX_ABI_INTREE ON CACHE BOOL "")
+set(RUNTIMES_${target}_SANITIZER_TEST_CXX "libc++" CACHE STRING "")
+set(RUNTIMES_${target}_SANITIZER_TEST_CXX_INTREE ON CACHE BOOL "")
 set(RUNTIMES_${target}_COMPILER_RT_TEST_COMPILER_CFLAGS 
"--unwindlib=libunwind -static-libgcc" CACHE STRING "")
 set(RUNTIMES_${target}_SANITIZER_COMMON_TEST_TARGET_CFLAGS 
"--unwindlib=libunwind -static-libgcc" CACHE STRING "")
 set(RUNTIMES_${target}_TSAN_TEST_TARGET_CFLAGS "--unwindlib=libunwind 
-static-libgcc" CACHE STRING "")


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -134,6 +134,8 @@
 set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
 set(RUNTIMES_${target}_SANITIZER_CXX_ABI "libc++" CACHE STRING "")
 set(RUNTIMES_${target}_SANITIZER_CXX_ABI_INTREE ON CACHE BOOL "")
+set(RUNTIMES_${target}_SANITIZER_TEST_CXX "libc++" CACHE STRING "")
+set(RUNTIMES_${target}_SANITIZER_TEST_CXX_INTREE ON CACHE BOOL "")
 set(RUNTIMES_${target}_COMPILER_RT_TEST_COMPILER_CFLAGS "--unwindlib=libunwind -static-libgcc" CACHE STRING "")
 set(RUNTIMES_${target}_SANITIZER_COMMON_TEST_TARGET_CFLAGS "--unwindlib=libunwind -static-libgcc" CACHE STRING "")
 set(RUNTIMES_${target}_TSAN_TEST_TARGET_CFLAGS "--unwindlib=libunwind -static-libgcc" CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >