[PATCH] D120456: bump __cpp_concepts and __cpp_constexpr in accordance with P2493R0

2022-02-24 Thread Marcus Boay via Phabricator via cfe-commits
MarcusBoay created this revision.
MarcusBoay 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/D120456

Files:
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Lexer/cxx-features.cpp


Index: clang/test/Lexer/cxx-features.cpp
===
--- clang/test/Lexer/cxx-features.cpp
+++ clang/test/Lexer/cxx-features.cpp
@@ -52,7 +52,7 @@
 #error "wrong value for __cpp_char8_t"
 #endif
 
-#if check(concepts, 0, 0, 0, 0, 201907, 201907)
+#if check(concepts, 0, 0, 0, 0, 202002L, 202002L)
 #error "wrong value for __cpp_concepts"
 #endif
 
@@ -277,7 +277,7 @@
 #error "wrong value for __cpp_lambdas"
 #endif
 
-#if check(constexpr, 0, 200704, 201304, 201603, 201907, 201907)
+#if check(constexpr, 0, 200704, 201304, 201603, 202110L, 202110L)
 #error "wrong value for __cpp_constexpr"
 #endif
 
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -562,7 +562,7 @@
 Builder.defineMacro("__cpp_user_defined_literals", "200809L");
 Builder.defineMacro("__cpp_lambdas", "200907L");
 Builder.defineMacro("__cpp_constexpr",
-LangOpts.CPlusPlus20 ? "201907L" :
+LangOpts.CPlusPlus20 ? "202110L" :
 LangOpts.CPlusPlus17 ? "201603L" :
 LangOpts.CPlusPlus14 ? "201304L" : "200704");
 Builder.defineMacro("__cpp_constexpr_in_decltype", "201711L");
@@ -629,7 +629,7 @@
   // C++20 features.
   if (LangOpts.CPlusPlus20) {
 //Builder.defineMacro("__cpp_aggregate_paren_init", "201902L");
-Builder.defineMacro("__cpp_concepts", "201907L");
+Builder.defineMacro("__cpp_concepts", "202002L");
 Builder.defineMacro("__cpp_conditional_explicit", "201806L");
 //Builder.defineMacro("__cpp_consteval", "201811L");
 Builder.defineMacro("__cpp_constexpr_dynamic_alloc", "201907L");


Index: clang/test/Lexer/cxx-features.cpp
===
--- clang/test/Lexer/cxx-features.cpp
+++ clang/test/Lexer/cxx-features.cpp
@@ -52,7 +52,7 @@
 #error "wrong value for __cpp_char8_t"
 #endif
 
-#if check(concepts, 0, 0, 0, 0, 201907, 201907)
+#if check(concepts, 0, 0, 0, 0, 202002L, 202002L)
 #error "wrong value for __cpp_concepts"
 #endif
 
@@ -277,7 +277,7 @@
 #error "wrong value for __cpp_lambdas"
 #endif
 
-#if check(constexpr, 0, 200704, 201304, 201603, 201907, 201907)
+#if check(constexpr, 0, 200704, 201304, 201603, 202110L, 202110L)
 #error "wrong value for __cpp_constexpr"
 #endif
 
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -562,7 +562,7 @@
 Builder.defineMacro("__cpp_user_defined_literals", "200809L");
 Builder.defineMacro("__cpp_lambdas", "200907L");
 Builder.defineMacro("__cpp_constexpr",
-LangOpts.CPlusPlus20 ? "201907L" :
+LangOpts.CPlusPlus20 ? "202110L" :
 LangOpts.CPlusPlus17 ? "201603L" :
 LangOpts.CPlusPlus14 ? "201304L" : "200704");
 Builder.defineMacro("__cpp_constexpr_in_decltype", "201711L");
@@ -629,7 +629,7 @@
   // C++20 features.
   if (LangOpts.CPlusPlus20) {
 //Builder.defineMacro("__cpp_aggregate_paren_init", "201902L");
-Builder.defineMacro("__cpp_concepts", "201907L");
+Builder.defineMacro("__cpp_concepts", "202002L");
 Builder.defineMacro("__cpp_conditional_explicit", "201806L");
 //Builder.defineMacro("__cpp_consteval", "201811L");
 Builder.defineMacro("__cpp_constexpr_dynamic_alloc", "201907L");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120334: [NFC][Lexer] Make Lexer::LangOpts const reference

2022-02-24 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

Looks reasonable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120334

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


[clang] 7fd60ee - [analyzer] Fix -Wunused-lambda-capture in -DLLVM_ENABLE_ASSERTIONS=off builds

2022-02-24 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-02-24T00:13:13-08:00
New Revision: 7fd60ee6e0a87957a718297a4a42d9881fc561e3

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

LOG: [analyzer] Fix -Wunused-lambda-capture in -DLLVM_ENABLE_ASSERTIONS=off 
builds

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
index d15a4659a96e6..d31e05076998a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -793,6 +793,7 @@ void GenericTaintRule::process(const GenericTaintChecker 
&Checker,
   LLVM_DEBUG(llvm::dbgs() << "PreCall<"; Call.dump(llvm::dbgs());
  llvm::dbgs()
  << "> prepares tainting arg index: " << I << '\n';);
+  (void)Call;
   Result = F.add(Result, I);
 }
 



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


[PATCH] D118987: [analyzer] Add failing test case demonstrating buggy taint propagation

2022-02-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:782
+if (PropDstArgs.contains(I)) {
+  LLVM_DEBUG(llvm::dbgs() << "PreCall<"; Call.dump(llvm::dbgs());
+ llvm::dbgs()

There was a -Wunused-lambda-capture in `-DLLVM_ENABLE_ASSERTIONS=off` builds. 
Fixed by 7fd60ee6e0a87957a718297a4a42d9881fc561e3


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118987

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


[PATCH] D120227: [RISCV] Add policy operand for masked vid and viota IR intrinsics.

2022-02-24 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 accepted this revision.
rogfer01 added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks @khchen !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120227

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


[PATCH] D120228: [RISCV] Add policy operand for masked compare and vmsbf/vmsif/vmsof IR intrinsics.

2022-02-24 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 accepted this revision.
rogfer01 added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks @khchen !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120228

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


[PATCH] D120334: [NFC][Lexer] Make Lexer::LangOpts const reference

2022-02-24 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.

LGTM too if the performance remains the same as with the original revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120334

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


[PATCH] D120445: [clang-format] Treat && followed by noexcept operator as a binary operator inside template arguments

2022-02-24 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

LGTM, but please rebase so that CI runs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120445

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


[clang] 69350e5 - [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-24 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-02-24T09:01:09Z
New Revision: 69350e569dc47f871590243b5e46a68520640dcd

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

LOG: [C++20][Modules][3/8] Initial handling for module partitions.

This implements the parsing and recognition of module partition CMIs
and removes the FIXMEs in the parser.

Module partitions are recognised in the base computation of visibility,
however additional amendments to visibility follow in subsequent patches.

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

Added: 
clang/test/Modules/cxx20-multiple-partitions.cpp
clang/test/Modules/cxx20-partition-diagnostics-a.cpp

Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaModule.cpp
clang/test/CXX/module/module.unit/p3.cpp
clang/test/CXX/module/module.unit/p8.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7611bac83419d..926426b5470d2 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4467,6 +4467,16 @@ class CapturedDecl final
 ///   @import std.vector;
 /// \endcode
 ///
+/// A C++20 module import declaration imports the named module or partition.
+/// Periods are permitted in C++20 module names, but have no semantic meaning.
+/// For example:
+/// \code
+///   import NamedModule;
+///   import :SomePartition; // Must be a partition of the current module.
+///   import Names.Like.this; // Allowed.
+///   import :and.Also.Partition.names;
+/// \endcode
+///
 /// Import declarations can also be implicitly generated from
 /// \#include/\#import directives.
 class ImportDecl final : public Decl,

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index f7d9a685e8b92..92ae27d6212a0 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1541,9 +1541,11 @@ def err_private_module_fragment_expected_semi : Error<
   "expected ';' after private module fragment declaration">;
 def err_missing_before_module_end : Error<"expected %0 at end of module">;
 def err_unsupported_module_partition : Error<
-  "sorry, module partitions are not yet supported">;
+  "module partitions are only supported for C++20 onwards">;
 def err_import_not_allowed_here : Error<
   "imports must immediately follow the module declaration">;
+def err_partition_import_outside_module : Error<
+  "module partition imports must be within a module purview">;
 def err_import_in_wrong_fragment : Error<
   "module%select{| partition}0 imports cannot be in the 
%select{global|private}1 module fragment">;
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 94283e2412a98..436718a54640e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2210,6 +2210,7 @@ class Sema final {
 SourceLocation BeginLoc;
 clang::Module *Module = nullptr;
 bool ModuleInterface = false;
+bool IsPartition = false;
 bool ImplicitGlobalModuleFragment = false;
 VisibleModuleSet OuterVisibleModules;
   };
@@ -2962,7 +2963,7 @@ class Sema final {
   /// of a module interface or implementation.
   DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc,
  SourceLocation ModuleLoc, ModuleDeclKind MDK,
- ModuleIdPath Path,
+ ModuleIdPath Path, ModuleIdPath Partition,
  ModuleImportState &ImportState);
 
   /// The parser has processed a global-module-fragment declaration that begins
@@ -2983,10 +2984,12 @@ class Sema final {
   ///could be the location of an '@', 'export', or 'import'.
   /// \param ExportLoc The location of the 'export' keyword, if any.
   /// \param ImportLoc The location of the 'import' keyword.
-  /// \param Path The module access path.
+  /// \param Path The module toplevel name as an access path.
+  /// \param Partition The module partition name as an access path.
   DeclResult ActOnModuleImport(SourceLocation StartLoc,
SourceLocation ExportLoc,
-   SourceLocation ImportLoc, ModuleIdPath Path);
+   SourceLocation ImportLoc, ModuleIdPath Path,
+   ModuleIdPath Partition = {});
   DeclResult ActOnModuleImport(SourceLocation StartLoc,
SourceLocation ExportLoc,
SourceLocation ImportLoc, Module *M,


[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-24 Thread Iain Sandoe via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
iains marked an inline comment as done.
Closed by commit rG69350e569dc4: [C++20][Modules][3/8] Initial handling for 
module partitions. (authored by iains).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/CXX/module/module.unit/p3.cpp
  clang/test/CXX/module/module.unit/p8.cpp
  clang/test/Modules/cxx20-multiple-partitions.cpp
  clang/test/Modules/cxx20-partition-diagnostics-a.cpp

Index: clang/test/Modules/cxx20-partition-diagnostics-a.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-partition-diagnostics-a.cpp
@@ -0,0 +1,19 @@
+// Module Partition diagnostics
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only %t/bad-import.cpp -verify
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only %t/bad-partition.cpp -verify
+
+//--- bad-import.cpp
+
+import :B; // expected-error {{module partition imports must be within a module purview}}
+
+//--- bad-partition.cpp
+
+module; // expected-error {{missing 'module' declaration at end of global module fragment introduced here}}
+
+import :Part; // expected-error {{module partition imports cannot be in the global module fragment}}
Index: clang/test/Modules/cxx20-multiple-partitions.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-multiple-partitions.cpp
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/partition1.cpp \
+// RUN:  -o %t/A_part1.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/partition2.cpp \
+// RUN:  -o %t/A_part2.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/partition3.cpp \
+// RUN:  -o %t/A_part3.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/moduleA.cpp \
+// RUN:  -fmodule-file=%t/A_part1.pcm -fmodule-file=%t/A_part2.pcm \
+// RUN:  -fmodule-file=%t/A_part3.pcm -o %t/A.pcm
+
+// expected-no-diagnostics
+
+//--- partition1.cpp
+
+export module A:Part1;
+
+int part1();
+
+//--- partition2.cpp
+
+export module A:Part2;
+
+int part2();
+
+//--- partition3.cpp
+
+export module A:Part3;
+
+int part3();
+
+//--- moduleA.cpp
+
+export module A;
+
+import :Part1;
+export import :Part2;
+import :Part3;
+
+int foo();
Index: clang/test/CXX/module/module.unit/p8.cpp
===
--- clang/test/CXX/module/module.unit/p8.cpp
+++ clang/test/CXX/module/module.unit/p8.cpp
@@ -12,7 +12,7 @@
 
 #elif MODE == 1
 // expected-no-diagnostics
-module foo;
+module foo; // Implementation, implicitly imports foo.
 #define IMPORTED
 
 #elif MODE == 2
@@ -21,15 +21,15 @@
 #define IMPORTED
 
 #elif MODE == 3
-export module bar;
+export module bar; // A different module
 
 #elif MODE == 4
-module foo:bar; // expected-error {{not yet supported}}
-#define IMPORTED // FIXME
+module foo:bar; // Partition implementation
+//#define IMPORTED (we don't import foo here)
 
 #elif MODE == 5
-export module foo:bar; // expected-error {{not yet supported}} expected-error {{redefinition}} expected-note@* {{loaded from}}
-#define IMPORTED // FIXME
+export module foo:bar; // Partition interface
+//#define IMPORTED  (we don't import foo here)
 
 #endif
 
Index: clang/test/CXX/module/module.unit/p3.cpp
===
--- clang/test/CXX/module/module.unit/p3.cpp
+++ clang/test/CXX/module/module.unit/p3.cpp
@@ -1,4 +1,4 @@
 // RUN: %clang_cc1 -std=c++2a -verify %s
 
-export module foo:bar; // expected-error {{sorry, module partitions are not yet supported}}
-import :baz; // expected-error {{sorry, module partitions are not yet supported}}
+export module foo:bar;
+import :baz; // expected-error {{module 'foo:baz' not found}}
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -54,6 +54,23 @@
   }
 }
 
+// We represent the primary and partition names as 'Paths' which are sections
+// of the hierarchical access path for a clang module.  However for C++20
+// the periods in a name are just another character, and we will need to
+// flatten them into a string.
+static std::string stringFromPath(ModuleIdPath Path) {
+  std::string Name;
+  if (Path.empty())
+return Name;
+
+  for (auto &Piece : Path) {
+if (!Name.empty())
+  Name += ".";
+Name += Piece.first->get

[PATCH] D118352: [clang][ABI] New c++20 modules mangling scheme

2022-02-24 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@urnathan FWIW, D114714  is landed~


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

https://reviews.llvm.org/D118352

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


[clang] dbc4d28 - [clang-format] Do not insert space after new/delete keywords in C function declarations

2022-02-24 Thread Marek Kurdej via cfe-commits

Author: Luis Penagos
Date: 2022-02-24T10:06:40+01:00
New Revision: dbc4d281bd6954362ccfc0747893ceaae842671b

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

LOG: [clang-format] Do not insert space after new/delete keywords in C function 
declarations

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

Reviewed By: curdeius, HazardyKnusperkeks

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 42c271f35be44..01c215f6ad9da 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3299,11 +3299,15 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   if (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch))
 return Style.SpaceBeforeParensOptions.AfterControlStatements ||
spaceRequiredBeforeParens(Right);
-  if (Left.isOneOf(tok::kw_new, tok::kw_delete) ||
-  (Left.is(tok::r_square) && Left.MatchingParen &&
-   Left.MatchingParen->Previous &&
-   Left.MatchingParen->Previous->is(tok::kw_delete)))
-return Style.SpaceBeforeParens != FormatStyle::SBPO_Never ||
+  if (Left.isOneOf(tok::kw_new, tok::kw_delete))
+return ((!Line.MightBeFunctionDecl || !Left.Previous) &&
+Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
+   spaceRequiredBeforeParens(Right);
+
+  if (Left.is(tok::r_square) && Left.MatchingParen &&
+  Left.MatchingParen->Previous &&
+  Left.MatchingParen->Previous->is(tok::kw_delete))
+return (Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
spaceRequiredBeforeParens(Right);
 }
 if (Line.Type != LT_PreprocessorDirective &&

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 98a0111d1ea40..6cd6c4ab9a602 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9919,6 +9919,11 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) {
   verifyFormat("void operator new(void *foo) ATTRIB;");
   verifyFormat("void operator delete[](void *foo) ATTRIB;");
   verifyFormat("void operator delete(void *ptr) noexcept;");
+
+  EXPECT_EQ("void new(link p);\n"
+"void delete(link p);\n",
+format("void new (link p);\n"
+   "void delete (link p);\n"));
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {



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


[PATCH] D120374: [clang-format] Do not insert space after new/delete keywords in C function declarations

2022-02-24 Thread Marek Kurdej 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 rGdbc4d281bd69: [clang-format] Do not insert space after 
new/delete keywords in C function… (authored by penagos, committed by curdeius).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120374

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9919,6 +9919,11 @@
   verifyFormat("void operator new(void *foo) ATTRIB;");
   verifyFormat("void operator delete[](void *foo) ATTRIB;");
   verifyFormat("void operator delete(void *ptr) noexcept;");
+
+  EXPECT_EQ("void new(link p);\n"
+"void delete(link p);\n",
+format("void new (link p);\n"
+   "void delete (link p);\n"));
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3299,11 +3299,15 @@
   if (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch))
 return Style.SpaceBeforeParensOptions.AfterControlStatements ||
spaceRequiredBeforeParens(Right);
-  if (Left.isOneOf(tok::kw_new, tok::kw_delete) ||
-  (Left.is(tok::r_square) && Left.MatchingParen &&
-   Left.MatchingParen->Previous &&
-   Left.MatchingParen->Previous->is(tok::kw_delete)))
-return Style.SpaceBeforeParens != FormatStyle::SBPO_Never ||
+  if (Left.isOneOf(tok::kw_new, tok::kw_delete))
+return ((!Line.MightBeFunctionDecl || !Left.Previous) &&
+Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
+   spaceRequiredBeforeParens(Right);
+
+  if (Left.is(tok::r_square) && Left.MatchingParen &&
+  Left.MatchingParen->Previous &&
+  Left.MatchingParen->Previous->is(tok::kw_delete))
+return (Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
spaceRequiredBeforeParens(Right);
 }
 if (Line.Type != LT_PreprocessorDirective &&


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9919,6 +9919,11 @@
   verifyFormat("void operator new(void *foo) ATTRIB;");
   verifyFormat("void operator delete[](void *foo) ATTRIB;");
   verifyFormat("void operator delete(void *ptr) noexcept;");
+
+  EXPECT_EQ("void new(link p);\n"
+"void delete(link p);\n",
+format("void new (link p);\n"
+   "void delete (link p);\n"));
 }
 
 TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3299,11 +3299,15 @@
   if (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch))
 return Style.SpaceBeforeParensOptions.AfterControlStatements ||
spaceRequiredBeforeParens(Right);
-  if (Left.isOneOf(tok::kw_new, tok::kw_delete) ||
-  (Left.is(tok::r_square) && Left.MatchingParen &&
-   Left.MatchingParen->Previous &&
-   Left.MatchingParen->Previous->is(tok::kw_delete)))
-return Style.SpaceBeforeParens != FormatStyle::SBPO_Never ||
+  if (Left.isOneOf(tok::kw_new, tok::kw_delete))
+return ((!Line.MightBeFunctionDecl || !Left.Previous) &&
+Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
+   spaceRequiredBeforeParens(Right);
+
+  if (Left.is(tok::r_square) && Left.MatchingParen &&
+  Left.MatchingParen->Previous &&
+  Left.MatchingParen->Previous->is(tok::kw_delete))
+return (Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
spaceRequiredBeforeParens(Right);
 }
 if (Line.Type != LT_PreprocessorDirective &&
___
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-02-24 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:726-727
+  LhsLoc.getType(Ctx).isNull() ? 0 : Ctx.getTypeSize(LhsLoc.getType(Ctx));
+  if (RhsBitwidth && LhsBitwidth &&
+  (LhsLoc.getSubKind() == RhsLoc.getSubKind())) {
+assert(RhsBitwidth == LhsBitwidth &&

steakhal wrote:
> You should probably ignore references.
> Ah, but we already lost that information. Well, that's bad.
> Anyway. You probably don't need to check the subkinds. Do you?
There was a case I hit in my testing where the subkinds were different and a 
crash occurred. I cannot recall the details at the moment, but it made sense at 
the time to also check subkkinds. I'll check this again so I can describe the 
rationale for this.



Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:745
+  // See LIT case clang/test/Analysis/cstring-checker-addressspace.c
+  assertEqualBitWidths(state, rhs, lhs);
+

steakhal wrote:
> You don't use the return value of this call.
> Can we have a `void` return type instead?
Yes, will do.


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


[clang] 46f6c83 - [clang-format] Fix QualifierOrder breaking the code with requires clause.

2022-02-24 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-02-24T10:16:10+01:00
New Revision: 46f6c834d9f95d99e0a85aa0c6dc07419aa6dee2

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

LOG: [clang-format] Fix QualifierOrder breaking the code with requires clause.

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

Given the config:
```
BasedOnStyle: LLVM
QualifierAlignment: Custom
QualifierOrder: ['constexpr', 'type']
```

The code:
```
template 
  requires std::invocable
constexpr constructor();
```
was incorrectly formatted to:
```
template 
  requires
constexpr std::invocable constructor();
```
because we considered `std::invocable constexpr` as a type, not recognising 
the requires clause.

This patch avoids moving the qualifier across the boundary of the requires 
clause (checking `ClosesRequiresClause`).

Reviewed By: HazardyKnusperkeks, owenpan

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

Added: 


Modified: 
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 233b081a95f6d..aff5562dd9721 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -328,14 +328,17 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeLeft(
   if (Next->is(tok::comment) && Next->getNextNonComment())
 Next = Next->getNextNonComment();
   assert(Next->MatchingParen && "Missing template closer");
-  Next = Next->MatchingParen->Next;
+  Next = Next->MatchingParen;
+  if (Next->ClosesRequiresClause)
+return Next;
+  Next = Next->Next;
 
   // Move to the end of any template class members e.g.
   // `Foo::iterator`.
   if (Next && Next->startsSequence(tok::coloncolon, tok::identifier))
 Next = Next->Next->Next;
   if (Next && Next->is(QualifierType)) {
-// Remove the const.
+// Move the qualifier.
 insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier);
 removeToken(SourceMgr, Fixes, Next);
 return Next;
@@ -344,7 +347,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeLeft(
 if (Next && Next->Next &&
 Next->Next->isOneOf(tok::amp, tok::ampamp, tok::star)) {
   if (Next->is(QualifierType)) {
-// Remove the qualifier.
+// Move the qualifier.
 insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier);
 removeToken(SourceMgr, Fixes, Next);
 return Next;

diff  --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 14f09d875e6be..0c81c831e1f18 100755
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -858,6 +858,21 @@ TEST_F(QualifierFixerTest, QualifierTemplates) {
Style);
 }
 
+TEST_F(QualifierFixerTest, WithConstraints) {
+  FormatStyle Style = getLLVMStyle();
+  Style.QualifierAlignment = FormatStyle::QAS_Custom;
+  Style.QualifierOrder = {"constexpr", "type"};
+
+  verifyFormat("template \n"
+   "  requires Concept\n"
+   "constexpr constructor();",
+   Style);
+  verifyFormat("template \n"
+   "  requires Concept1 && Concept2\n"
+   "constexpr constructor();",
+   Style);
+}
+
 TEST_F(QualifierFixerTest, DisableRegions) {
   FormatStyle Style = getLLVMStyle();
   Style.QualifierAlignment = FormatStyle::QAS_Custom;



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


[PATCH] D120309: [clang-format] Fix QualifierOrder breaking the code with requires clause.

2022-02-24 Thread Marek Kurdej 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 rG46f6c834d9f9: [clang-format] Fix QualifierOrder breaking the 
code with requires clause. (authored by curdeius).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120309

Files:
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/unittests/Format/QualifierFixerTest.cpp


Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -858,6 +858,21 @@
Style);
 }
 
+TEST_F(QualifierFixerTest, WithConstraints) {
+  FormatStyle Style = getLLVMStyle();
+  Style.QualifierAlignment = FormatStyle::QAS_Custom;
+  Style.QualifierOrder = {"constexpr", "type"};
+
+  verifyFormat("template \n"
+   "  requires Concept\n"
+   "constexpr constructor();",
+   Style);
+  verifyFormat("template \n"
+   "  requires Concept1 && Concept2\n"
+   "constexpr constructor();",
+   Style);
+}
+
 TEST_F(QualifierFixerTest, DisableRegions) {
   FormatStyle Style = getLLVMStyle();
   Style.QualifierAlignment = FormatStyle::QAS_Custom;
Index: clang/lib/Format/QualifierAlignmentFixer.cpp
===
--- clang/lib/Format/QualifierAlignmentFixer.cpp
+++ clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -328,14 +328,17 @@
   if (Next->is(tok::comment) && Next->getNextNonComment())
 Next = Next->getNextNonComment();
   assert(Next->MatchingParen && "Missing template closer");
-  Next = Next->MatchingParen->Next;
+  Next = Next->MatchingParen;
+  if (Next->ClosesRequiresClause)
+return Next;
+  Next = Next->Next;
 
   // Move to the end of any template class members e.g.
   // `Foo::iterator`.
   if (Next && Next->startsSequence(tok::coloncolon, tok::identifier))
 Next = Next->Next->Next;
   if (Next && Next->is(QualifierType)) {
-// Remove the const.
+// Move the qualifier.
 insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier);
 removeToken(SourceMgr, Fixes, Next);
 return Next;
@@ -344,7 +347,7 @@
 if (Next && Next->Next &&
 Next->Next->isOneOf(tok::amp, tok::ampamp, tok::star)) {
   if (Next->is(QualifierType)) {
-// Remove the qualifier.
+// Move the qualifier.
 insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier);
 removeToken(SourceMgr, Fixes, Next);
 return Next;


Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -858,6 +858,21 @@
Style);
 }
 
+TEST_F(QualifierFixerTest, WithConstraints) {
+  FormatStyle Style = getLLVMStyle();
+  Style.QualifierAlignment = FormatStyle::QAS_Custom;
+  Style.QualifierOrder = {"constexpr", "type"};
+
+  verifyFormat("template \n"
+   "  requires Concept\n"
+   "constexpr constructor();",
+   Style);
+  verifyFormat("template \n"
+   "  requires Concept1 && Concept2\n"
+   "constexpr constructor();",
+   Style);
+}
+
 TEST_F(QualifierFixerTest, DisableRegions) {
   FormatStyle Style = getLLVMStyle();
   Style.QualifierAlignment = FormatStyle::QAS_Custom;
Index: clang/lib/Format/QualifierAlignmentFixer.cpp
===
--- clang/lib/Format/QualifierAlignmentFixer.cpp
+++ clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -328,14 +328,17 @@
   if (Next->is(tok::comment) && Next->getNextNonComment())
 Next = Next->getNextNonComment();
   assert(Next->MatchingParen && "Missing template closer");
-  Next = Next->MatchingParen->Next;
+  Next = Next->MatchingParen;
+  if (Next->ClosesRequiresClause)
+return Next;
+  Next = Next->Next;
 
   // Move to the end of any template class members e.g.
   // `Foo::iterator`.
   if (Next && Next->startsSequence(tok::coloncolon, tok::identifier))
 Next = Next->Next->Next;
   if (Next && Next->is(QualifierType)) {
-// Remove the const.
+// Move the qualifier.
 insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier);
 removeToken(SourceMgr, Fixes, Next);
 return Next;
@@ -344,7 +347,7 @@
 if (Next && Next->Next &&
 Next->Next->isOneOf(tok::amp, tok::ampamp, tok::star)) {
   if (Next->is(QualifierType)) {
-// Remove the qualifier.
+// Move the qualifier.
 insertQualifierBefore(SourceMgr, Fixes, Tok, Qualifier);
 removeToken(Sourc

[PATCH] D120140: [clang-format] Avoid inserting space after C++ casts.

2022-02-24 Thread Marek Kurdej 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 rGbfb4afee74c8: [clang-format] Avoid inserting space after C++ 
casts. (authored by curdeius).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120140

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10570,6 +10570,19 @@
 
 TEST_F(FormatTest, FormatsCasts) {
   verifyFormat("Type *A = static_cast(P);");
+  verifyFormat("static_cast(P);");
+  verifyFormat("static_cast(Fun)(Args);");
+  verifyFormat("static_cast(*Fun)(Args);");
+  verifyFormat("if (static_cast(A) + B >= 0)\n  ;");
+  // Check that static_cast<...>(...) does not require the next token to be on
+  // the same line.
+  verifyFormat("some_lng_output << something_something__ << "
+   "static_cast(R)\n"
+   "<< something;");
+  verifyFormat("a = static_cast(*Fun)(Args);");
+  verifyFormat("const_cast(*Fun)(Args);");
+  verifyFormat("dynamic_cast(*Fun)(Args);");
+  verifyFormat("reinterpret_cast(*Fun)(Args);");
   verifyFormat("Type *A = (Type *)P;");
   verifyFormat("Type *A = (vector)P;");
   verifyFormat("int a = (int)(2.0f);");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -358,7 +358,8 @@
   if (CurrentToken->Previous->is(TT_BinaryOperator))
 Contexts.back().IsExpression = true;
   if (CurrentToken->is(tok::r_paren)) {
-if (MightBeFunctionType && ProbablyFunctionType && CurrentToken->Next 
&&
+if (Left->isNot(TT_CppCastLParen) && MightBeFunctionType &&
+ProbablyFunctionType && CurrentToken->Next &&
 (CurrentToken->Next->is(tok::l_paren) ||
  (CurrentToken->Next->is(tok::l_square) && 
Line.MustBeDeclaration)))
   Left->setType(Left->Next->is(tok::caret) ? TT_ObjCBlockLParen
@@ -1733,6 +1734,9 @@
   Current.Tok.setKind(tok::unknown);
   else
 Current.setType(TT_LineComment);
+} else if (Current.is(tok::l_paren)) {
+  if (lParenStartsCppCast(Current))
+Current.setType(TT_CppCastLParen);
 } else if (Current.is(tok::r_paren)) {
   if (rParenEndsCast(Current))
 Current.setType(TT_CastRParen);
@@ -1880,6 +1884,25 @@
 return Style.isJavaScript() && PreviousNotConst->is(tok::kw_const);
   }
 
+  /// Determine whether '(' is starting a C++ cast.
+  bool lParenStartsCppCast(const FormatToken &Tok) {
+// C-style casts are only used in C++.
+if (!Style.isCpp())
+  return false;
+
+FormatToken *LeftOfParens = Tok.getPreviousNonComment();
+if (LeftOfParens && LeftOfParens->is(TT_TemplateCloser) &&
+LeftOfParens->MatchingParen) {
+  auto *Prev = LeftOfParens->MatchingParen->getPreviousNonComment();
+  if (Prev && Prev->isOneOf(tok::kw_const_cast, tok::kw_dynamic_cast,
+tok::kw_reinterpret_cast, tok::kw_static_cast))
+// FIXME: Maybe we should handle identifiers ending with "_cast",
+// e.g. any_cast?
+return true;
+}
+return false;
+  }
+
   /// Determine whether ')' is ending a cast.
   bool rParenEndsCast(const FormatToken &Tok) {
 // C-style casts are only used in C++, C# and Java.
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -43,6 +43,7 @@
   TYPE(ConflictAlternative)
\
   TYPE(ConflictEnd)
\
   TYPE(ConflictStart)  
\
+  TYPE(CppCastLParen)  
\
   TYPE(CtorInitializerColon)   
\
   TYPE(CtorInitializerComma)   
\
   TYPE(DesignatedInitializerLSquare)   
\


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10570,6 +10570,19 @@
 
 TEST_F(FormatTest, FormatsCasts) {
   verifyFormat("Type *A = static_cast(P);");
+  verifyFormat("static_cast(P);");
+  verifyFormat("static_cast(Fun)(Args);");
+  verifyFormat("static_cast(*Fun)(Args);");
+  verifyFormat("if (static_cast(A) + B >= 0)\n  ;");
+  // Check that st

[clang] bfb4afe - [clang-format] Avoid inserting space after C++ casts.

2022-02-24 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-02-24T10:21:02+01:00
New Revision: bfb4afee74c8d6e3b1d020564bfe163073f07a04

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

LOG: [clang-format] Avoid inserting space after C++ casts.

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

This is a solution for standard C++ casts: const_cast, dynamic_cast, 
reinterpret_cast, static_cast.

A general approach handling all possible casts is not possible without semantic 
information.
Consider the code:
```
static_cast(*function_pointer_variable)(arguments);
```
vs.
```
some_return_type (*function_pointer_variable)(parameters);
// Later used as:
function_pointer_variable = &some_function;
return function_pointer_variable(args);
```
In the latter case, it's not a cast but a variable declaration of a pointer to 
function.
Without knowing what `some_return_type` is (and clang-format does not know 
it), it's hard to distinguish between the two cases. Theoretically, one could 
check whether "parameters" are types (not a cast) and "arguments" are 
value/expressions (a cast), but that might be inefficient (needs lots of 
lookahead).

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan

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

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index bd1d447328a0..d1dc3ffb129d 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -43,6 +43,7 @@ namespace format {
   TYPE(ConflictAlternative)
\
   TYPE(ConflictEnd)
\
   TYPE(ConflictStart)  
\
+  TYPE(CppCastLParen)  
\
   TYPE(CtorInitializerColon)   
\
   TYPE(CtorInitializerComma)   
\
   TYPE(DesignatedInitializerLSquare)   
\

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 01c215f6ad9d..36ff757922a9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -358,7 +358,8 @@ class AnnotatingParser {
   if (CurrentToken->Previous->is(TT_BinaryOperator))
 Contexts.back().IsExpression = true;
   if (CurrentToken->is(tok::r_paren)) {
-if (MightBeFunctionType && ProbablyFunctionType && CurrentToken->Next 
&&
+if (Left->isNot(TT_CppCastLParen) && MightBeFunctionType &&
+ProbablyFunctionType && CurrentToken->Next &&
 (CurrentToken->Next->is(tok::l_paren) ||
  (CurrentToken->Next->is(tok::l_square) && 
Line.MustBeDeclaration)))
   Left->setType(Left->Next->is(tok::caret) ? TT_ObjCBlockLParen
@@ -1733,6 +1734,9 @@ class AnnotatingParser {
   Current.Tok.setKind(tok::unknown);
   else
 Current.setType(TT_LineComment);
+} else if (Current.is(tok::l_paren)) {
+  if (lParenStartsCppCast(Current))
+Current.setType(TT_CppCastLParen);
 } else if (Current.is(tok::r_paren)) {
   if (rParenEndsCast(Current))
 Current.setType(TT_CastRParen);
@@ -1880,6 +1884,25 @@ class AnnotatingParser {
 return Style.isJavaScript() && PreviousNotConst->is(tok::kw_const);
   }
 
+  /// Determine whether '(' is starting a C++ cast.
+  bool lParenStartsCppCast(const FormatToken &Tok) {
+// C-style casts are only used in C++.
+if (!Style.isCpp())
+  return false;
+
+FormatToken *LeftOfParens = Tok.getPreviousNonComment();
+if (LeftOfParens && LeftOfParens->is(TT_TemplateCloser) &&
+LeftOfParens->MatchingParen) {
+  auto *Prev = LeftOfParens->MatchingParen->getPreviousNonComment();
+  if (Prev && Prev->isOneOf(tok::kw_const_cast, tok::kw_dynamic_cast,
+tok::kw_reinterpret_cast, tok::kw_static_cast))
+// FIXME: Maybe we should handle identifiers ending with "_cast",
+// e.g. any_cast?
+return true;
+}
+return false;
+  }
+
   /// Determine whether ')' is ending a cast.
   bool rParenEndsCast(const FormatToken &Tok) {
 // C-style casts are only used in C++, C# and Java.

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 6cd6c4ab9a60..624f3a78755f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10570,6 +10570,19 @@ TEST_F(FormatTest, 
FormatsBinaryOperatorsPrecedingEquals) 

[PATCH] D119816: Fix not working attribute no_sanitize bounds that affects linux kernel

2022-02-24 Thread Tong Zhang via Phabricator via cfe-commits
ztong0001 updated this revision to Diff 411040.
ztong0001 edited the summary of this revision.
ztong0001 added a comment.

update patch and description as suggested by Marco


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119816

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/sanitize-coverage.c
  llvm/bindings/go/llvm/ir_test.go
  llvm/docs/BitCodeFormat.rst
  llvm/docs/LangRef.rst
  llvm/include/llvm/AsmParser/LLToken.h
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Bitcode/attributes.ll
  llvm/test/Bitcode/compatibility.ll
  llvm/utils/emacs/llvm-mode.el
  llvm/utils/llvm.grm
  llvm/utils/vim/syntax/llvm.vim
  llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml

Index: llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
===
--- llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
+++ llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
@@ -238,6 +238,7 @@
 \\bnosync\\b|\
 \\bnoundef\\b|\
 \\bnounwind\\b|\
+\\bnosanitize_bounds\\b|\
 \\bnosanitize_coverage\\b|\
 \\bnull_pointer_is_valid\\b|\
 \\boptforfuzzing\\b|\
Index: llvm/utils/vim/syntax/llvm.vim
===
--- llvm/utils/vim/syntax/llvm.vim
+++ llvm/utils/vim/syntax/llvm.vim
@@ -139,6 +139,7 @@
   \ nosync
   \ noundef
   \ nounwind
+  \ nosanitize_bounds
   \ nosanitize_coverage
   \ null_pointer_is_valid
   \ optforfuzzing
Index: llvm/utils/llvm.grm
===
--- llvm/utils/llvm.grm
+++ llvm/utils/llvm.grm
@@ -176,6 +176,7 @@
  | sanitize_thread
  | sanitize_memory
  | mustprogress
+ | nosanitize_bounds
  | nosanitize_coverage
  ;

Index: llvm/utils/emacs/llvm-mode.el
===
--- llvm/utils/emacs/llvm-mode.el
+++ llvm/utils/emacs/llvm-mode.el
@@ -25,7 +25,7 @@
'("alwaysinline" "argmemonly" "allocsize" "builtin" "cold" "convergent" "dereferenceable" "dereferenceable_or_null" "hot" "inaccessiblememonly"
  "inaccessiblemem_or_argmemonly" "inalloca" "inlinehint" "jumptable" "minsize" "mustprogress" "naked" "nobuiltin" "nonnull"
  "nocallback" "nocf_check" "noduplicate" "nofree" "noimplicitfloat" "noinline" "nomerge" "nonlazybind" "noprofile" "noredzone" "noreturn"
- "norecurse" "nosync" "noundef" "nounwind" "nosanitize_coverage" "null_pointer_is_valid" "optforfuzzing" "optnone" "optsize" "preallocated" "readnone" "readonly" "returned" "returns_twice"
+ "norecurse" "nosync" "noundef" "nounwind" "nosanitize_bounds" "nosanitize_coverage" "null_pointer_is_valid" "optforfuzzing" "optnone" "optsize" "preallocated" "readnone" "readonly" "returned" "returns_twice"
  "shadowcallstack" "speculatable" "speculative_load_hardening" "ssp" "sspreq" "sspstrong" "safestack" "sanitize_address" "sanitize_hwaddress" "sanitize_memtag"
  "sanitize_thread" "sanitize_memory" "strictfp" "swifterror" "uwtable" "vscale_range" "willreturn" "writeonly" "immarg") 'symbols) . font-lock-constant-face)
;; Variables
Index: llvm/test/Bitcode/compatibility.ll
===
--- llvm/test/Bitcode/compatibility.ll
+++ llvm/test/Bitcode/compatibility.ll
@@ -1510,7 +1510,7 @@
   ; CHECK: select <2 x i1> , <2 x i8> , <2 x i8> 

   call void @f.nobuiltin() builtin
-  ; CHECK: call void @f.nobuiltin() #48
+  ; CHECK: call void @f.nobuiltin() #49

   call fastcc noalias i32* @f.noalias() noinline
   ; CHECK: call fastcc noalias i32* @f.noalias() #12
@@ -1930,6 +1930,9 @@
 ; CHECK: Function Attrs: allocsize(1,0)
 ; CHECK: declare void @f.allocsize_two(i32, i32)

+declare void @f.nosanitize_bounds() nosanitize_bounds
+; CHECK: declare void @f.nosanitize_bounds() #48
+
 ; CHECK: attributes #0 = { alignstack=4 }
 ; CHECK: attributes #1 = { alignstack=8 }
 ; CHECK: attributes #2 = { alwaysinline }
@@ -1978,7 +1981,8 @@
 ; CHECK: attributes #45 = { disable_sanitizer_instrumentation }
 ; CHECK: attributes #46 = { allocsize(0) }
 ; CHECK: attributes #47 = { allocsize(1,0) }
-; CHECK: attributes #48 = { builtin }
+; CHECK: attributes #48 = { nosanitize_bounds }
+; CHECK: attributes #49 = { builtin }

 ;; Metadata

Index: llvm/test/Bitcode/attributes.ll
===
--- llvm/test/Bitcode/attributes.ll
+++ llvm/test/Bitcode/attributes.ll
@@ -526,6 +526,12 @@
 ret void;
 }

+; CHECK: define void @f86() #52
+define void @f86()

[PATCH] D120361: [clang-format] Extract doc for entire configuration structs

2022-02-24 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius 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/D120361/new/

https://reviews.llvm.org/D120361

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


[PATCH] D117090: [clang-tidy] Fix `readability-non-const-parameter` for parameter referenced by an lvalue

2022-02-24 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Before landing make sure this is rebased against trunk, just so the pre-merge 
bot can run and verify there are no issues. It looks like this patch is based 
off a few commits that don't appear on trunk.


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

https://reviews.llvm.org/D117090

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


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2022-02-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

@achieveartificialintelligence any progress with the problematic IR? Have you 
been able to reproduce using nikic's reduced example?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

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


[PATCH] D120463: [clang][modules] NFC: Simplify and clarify test

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

This patch simplifies a test that checks only used module map files are 
reported as input files in PCM files.

Instead of using opaque `diff`, this patch uses `clang -module-file-info` and 
`FileCheck` to verify this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120463

Files:
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
  clang/test/Modules/add-remove-irrelevant-module-map.m


Index: clang/test/Modules/add-remove-irrelevant-module-map.m
===
--- clang/test/Modules/add-remove-irrelevant-module-map.m
+++ clang/test/Modules/add-remove-irrelevant-module-map.m
@@ -1,16 +1,30 @@
-// RUN: rm -rf %t
-// RUN: rm -rf %t.mcp
-// RUN: mkdir -p %t
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
 
-// Build without b.modulemap
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t.mcp -fdisable-module-hash 
-fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
-// RUN: cp %t.mcp/a.pcm %t/a.pcm
+//--- a.modulemap
+module a {}
 
-// Build with b.modulemap
-// RUN: rm -rf %t.mcp
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t.mcp -fdisable-module-hash 
-fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap 
-fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
-// RUN: not diff %t.mcp/a.pcm %t/a.pcm
+//--- b.modulemap
+module b {}
 
+//--- test-simple.m
 // expected-no-diagnostics
-
 @import a;
+
+// Build without b.modulemap:
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/a.modulemap %t/test-simple.m -verify
+// RUN: mv %t/cache %t/cache-without-b
+
+// Build with b.modulemap:
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap 
%t/test-simple.m -verify
+// RUN: mv %t/cache %t/cache-with-b
+
+// Neither PCM file considers 'b.modulemap' an input:
+//
+// RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s
+// RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s
+// CHECK-NOT: Input file: {{.*}}/b.modulemap
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
===
--- clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
+++ /dev/null
@@ -1 +0,0 @@
-module b { }
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
===
--- clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
+++ /dev/null
@@ -1 +0,0 @@
-module a { }


Index: clang/test/Modules/add-remove-irrelevant-module-map.m
===
--- clang/test/Modules/add-remove-irrelevant-module-map.m
+++ clang/test/Modules/add-remove-irrelevant-module-map.m
@@ -1,16 +1,30 @@
-// RUN: rm -rf %t
-// RUN: rm -rf %t.mcp
-// RUN: mkdir -p %t
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
 
-// Build without b.modulemap
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
-// RUN: cp %t.mcp/a.pcm %t/a.pcm
+//--- a.modulemap
+module a {}
 
-// Build with b.modulemap
-// RUN: rm -rf %t.mcp
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
-// RUN: not diff %t.mcp/a.pcm %t/a.pcm
+//--- b.modulemap
+module b {}
 
+//--- test-simple.m
 // expected-no-diagnostics
-
 @import a;
+
+// Build without b.modulemap:
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/a.modulemap %t/test-simple.m -verify
+// RUN: mv %t/cache %t/cache-without-b
+
+// Build with b.modulemap:
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap %t/test-simple.m -verify
+// RUN: mv %t/cache %t/cache-with-b
+
+// Neither PCM file considers 'b.modulemap' an input:
+//
+// RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s
+// RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s
+// CHECK-N

[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2022-02-24 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence added a comment.

In D93298#3342452 , @krasimir wrote:

> @achieveartificialintelligence any progress with the problematic IR? Have you 
> been able to reproduce using nikic's reduced example?

Sorry, I don't have a solution right now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

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


[PATCH] D120464: [clang][modules] Report module maps affecting `no_undeclared_includes` modules

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

Since D106876 , PCM files don't report module 
maps as input files unless they contributed to the compilation.

Reporting only module maps of (transitively) imported modules is not enough, 
though. For modules marked with `[no_undeclared_includes]`, other module maps 
affect the compilation by introducing anti-dependencies.

This patch makes sure such module maps are being reported as input files.

Depends on D120463 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120464

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/Basic/Module.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/add-remove-irrelevant-module-map.m

Index: clang/test/Modules/add-remove-irrelevant-module-map.m
===
--- clang/test/Modules/add-remove-irrelevant-module-map.m
+++ clang/test/Modules/add-remove-irrelevant-module-map.m
@@ -25,6 +25,34 @@
 
 // Neither PCM file considers 'b.modulemap' an input:
 //
-// RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s
-// RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s
-// CHECK-NOT: Input file: {{.*}}/b.modulemap
+// RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s --check-prefix=CHECK-B
+// RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s --check-prefix=CHECK-B
+// CHECK-B-NOT: Input file: {{.*}}/b.modulemap
+
+//--- c.modulemap
+module c [no_undeclared_includes] { header "c.h" }
+
+//--- c.h
+#if __has_include("d.h") // This should use 'd.modulemap' in order to determine that 'd.h'
+ // doesn't exist for 'c' because of its '[no_undeclared_includes]'.
+#endif
+
+//--- d.modulemap
+module d { header "d.h" }
+
+//--- d.h
+// empty
+
+//--- test-no-undeclared-includes.m
+// expected-no-diagnostics
+@import c;
+
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/c.modulemap -fmodule-map-file=%t/d.modulemap \
+// RUN:   %t/test-no-undeclared-includes.m -verify
+
+// The PCM file considers 'd.modulemap' an input because it affects the compilation,
+// although it doesn't describe the built module or its imports.
+//
+// RUN: %clang_cc1 -module-file-info %t/cache/c.pcm | FileCheck %s --check-prefix=CHECK-D -DDIR=%t
+// CHECK-D: Input file: [[DIR]]/d.modulemap
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -164,8 +164,8 @@
 std::set GetAllModuleMaps(const HeaderSearch &HS,
  Module *RootModule) {
   std::set ModuleMaps{};
-  std::set ProcessedModules;
-  SmallVector ModulesToProcess{RootModule};
+  std::set ProcessedModules;
+  SmallVector ModulesToProcess{RootModule};
 
   SmallVector FilesByUID;
   HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
@@ -209,6 +209,11 @@
   }
   ModulesToProcess.push_back(ImportedModule);
 }
+
+for (const Module *UndeclaredModule : CurrentModule->UndeclaredUses)
+  if (UndeclaredModule &&
+  ProcessedModules.find(UndeclaredModule) == ProcessedModules.end())
+ModulesToProcess.push_back(UndeclaredModule);
   }
 
   return ModuleMaps;
@@ -2861,6 +2866,8 @@
 // Might be unnecessary as use declarations are only used to build the
 // module itself.
 
+// TODO: Consider serializing undeclared uses of modules.
+
 // Emit the link libraries.
 for (const auto &LL : Mod->LinkLibraries) {
   RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY,
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -267,7 +267,7 @@
   return llvm::makeArrayRef(TopHeaders.begin(), TopHeaders.end());
 }
 
-bool Module::directlyUses(const Module *Requested) const {
+bool Module::directlyUses(const Module *Requested) {
   auto *Top = getTopLevelModule();
 
   // A top-level module implicitly uses itself.
@@ -282,6 +282,9 @@
   if (!Requested->Parent && Requested->Name == "_Builtin_stddef_max_align_t")
 return true;
 
+  if (NoUndeclaredIncludes)
+UndeclaredUses.insert(Requested);
+
   return false;
 }
 
Index: clang/include/clang/Basic/Module.h
===
--- clang/include/clang/Basic/Module.h
+++ clang/include/clang/Basic/Module.h
@@ -371,6 +371,10 @@
   /// The set of use declarations that have yet to be resolved.
   SmallVector UnresolvedDirectUses;
 
+  /// When \c NoUndeclaredIncludes is true, the set o

[PATCH] D120465: [clang][deps] Generate necessary "-fmodule-map-file=" arguments, disable implicit module maps

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

Since D113473 , we don't report any module 
map files via `-fmodule-map-file=` in explicit builds. The ultimate goal here 
is to make sure Clang doesn't open/read/parse/evaluate unnecessary module maps.

However, implicit module maps still end up reading all reachable module maps. 
This patch disables implicit module maps in explicit builds.

Unfortunately, we still need to report some module map files that aren't 
encoded in PCM files of dependencies: module maps that are necessary to 
correctly evaluate includes in modules marked as `[no_undeclared_includes]`.

Depends on D120464 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120465

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred.m
  clang/test/ClangScanDeps/modules-no-undeclared-includes.c
  clang/test/ClangScanDeps/modules-pch.c

Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -26,6 +26,7 @@
 // CHECK-PCH-NEXT: "-cc1"
 // CHECK-PCH:  "-emit-module"
 // CHECK-PCH:  "-fmodules"
+// CHECK-PCH-NOT:  "-fimplicit-module-maps"
 // CHECK-PCH:  "-fmodule-name=ModCommon1"
 // CHECK-PCH:  "-fno-implicit-modules"
 // CHECK-PCH:],
@@ -43,6 +44,7 @@
 // CHECK-PCH-NEXT: "-cc1"
 // CHECK-PCH:  "-emit-module"
 // CHECK-PCH:  "-fmodules"
+// CHECK-PCH-NOT:  "-fimplicit-module-maps"
 // CHECK-PCH:  "-fmodule-name=ModCommon2"
 // CHECK-PCH:  "-fno-implicit-modules"
 // CHECK-PCH:],
@@ -66,6 +68,7 @@
 // CHECK-PCH:  "-emit-module"
 // CHECK-PCH:  "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_2]]/ModCommon2-{{.*}}.pcm"
 // CHECK-PCH:  "-fmodules"
+// CHECK-PCH-NOT:  "-fimplicit-module-maps"
 // CHECK-PCH:  "-fmodule-name=ModPCH"
 // CHECK-PCH:  "-fno-implicit-modules"
 // CHECK-PCH:],
@@ -139,6 +142,7 @@
 // CHECK-TU-NEXT:   "command-line": [
 // CHECK-TU-NEXT: "-cc1",
 // CHECK-TU:  "-emit-module",
+// CHECK-TU-NOT:  "-fimplicit-module-maps",
 // CHECK-TU:  "-fmodule-name=ModTU",
 // CHECK-TU:  "-fno-implicit-modules",
 // CHECK-TU:],
@@ -202,6 +206,7 @@
 // CHECK-TU-WITH-COMMON-NEXT: "-cc1",
 // CHECK-TU-WITH-COMMON:  "-emit-module",
 // CHECK-TU-WITH-COMMON:  "-fmodule-file=[[PREFIX]]/build/{{.*}}/ModCommon1-{{.*}}.pcm",
+// CHECK-TU-WITH-COMMON-NOT:  "-fimplicit-module-maps",
 // CHECK-TU-WITH-COMMON:  "-fmodule-name=ModTUWithCommon",
 // CHECK-TU-WITH-COMMON:  "-fno-implicit-modules",
 // CHECK-TU-WITH-COMMON:],
Index: clang/test/ClangScanDeps/modules-no-undeclared-includes.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-no-undeclared-includes.c
@@ -0,0 +1,72 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
+
+//--- undeclared/module.modulemap
+module Undeclared { header "undeclared.h" }
+
+//--- undeclared/undeclared.h
+
+//--- module.modulemap
+module User [no_undeclared_includes] { header "user.h" }
+
+//--- user.h
+#if __has_include("undeclared.h")
+#error Unreachable. Undeclared comes from a module that's not 'use'd, meaning the compiler should pretend it doesn't exist.
+#endif
+
+//--- test.c
+#include "user.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -IDIR/undeclared -c DIR/test.c -o DIR/test.o",
+  "file": "DIR/test.c"
+}]
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
+// RUN:   -generate-modules-path-args -module-files-dir %t/build > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%t
+
+// CHECK:{
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:  "-fmodule-map-file=[[PREFIX]]/undeclared/module.modulemap"
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",

[PATCH] D118915: [clang][deps] Generate '-fmodule-file=' only for direct dependencies

2022-02-24 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 411044.
jansvoboda11 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118915

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-pch.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -298,10 +298,7 @@
 
 ID.CommandLine = GenerateModulesPathArgs
  ? FD.getCommandLine(
-   [&](ModuleID MID) { return lookupPCMPath(MID); },
-   [&](ModuleID MID) -> const ModuleDeps & {
- return lookupModuleDeps(MID);
-   })
+   [&](ModuleID MID) { return lookupPCMPath(MID); })
  : FD.getCommandLineWithoutModulePaths();
 
 Inputs.push_back(std::move(ID));
@@ -336,10 +333,7 @@
   {"command-line",
GenerateModulesPathArgs
? MD.getCanonicalCommandLine(
- [&](ModuleID MID) { return lookupPCMPath(MID); },
- [&](ModuleID MID) -> const ModuleDeps & {
-   return lookupModuleDeps(MID);
- })
+ [&](ModuleID MID) { return lookupPCMPath(MID); })
: MD.getCanonicalCommandLineWithoutModulePaths()},
   };
   OutModules.push_back(std::move(O));
@@ -369,12 +363,16 @@
   StringRef lookupPCMPath(ModuleID MID) {
 auto PCMPath = PCMPaths.insert({MID, ""});
 if (PCMPath.second)
-  PCMPath.first->second = constructPCMPath(lookupModuleDeps(MID));
+  PCMPath.first->second = constructPCMPath(MID);
 return PCMPath.first->second;
   }
 
   /// Construct a path for the explicitly built PCM.
-  std::string constructPCMPath(const ModuleDeps &MD) const {
+  std::string constructPCMPath(ModuleID MID) const {
+auto MDIt = Modules.find(IndexedModuleID{MID, 0});
+assert(MDIt != Modules.end());
+const ModuleDeps &MD = MDIt->second;
+
 StringRef Filename = llvm::sys::path::filename(MD.ImplicitModulePCMPath);
 
 SmallString<256> ExplicitPCMPath(
@@ -385,12 +383,6 @@
 return std::string(ExplicitPCMPath);
   }
 
-  const ModuleDeps &lookupModuleDeps(ModuleID MID) {
-auto I = Modules.find(IndexedModuleID{MID, 0});
-assert(I != Modules.end());
-return I->second;
-  };
-
   struct IndexedModuleID {
 ModuleID ID;
 mutable size_t InputIndex;
Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -97,7 +97,6 @@
 // CHECK-PCH:  "-fno-implicit-modules",
 // CHECK-PCH-NEXT: "-fno-implicit-module-maps",
 // CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_1]]/ModCommon1-{{.*}}.pcm",
-// CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_2]]/ModCommon2-{{.*}}.pcm",
 // CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_PCH]]/ModPCH-{{.*}}.pcm"
 // CHECK-PCH-NEXT:   ],
 // CHECK-PCH-NEXT:   "file-deps": [
Index: clang/test/ClangScanDeps/modules-full.cpp
===
--- clang/test/ClangScanDeps/modules-full.cpp
+++ clang/test/ClangScanDeps/modules-full.cpp
@@ -169,9 +169,7 @@
 // CHECK:  "-fno-implicit-modules"
 // CHECK-NEXT: "-fno-implicit-module-maps"
 // CHECK-NO-ABS-NOT:   "-fmodule-file={{.*}}"
-// CHECK-ABS-NEXT: "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[HASH_H2_DINCLUDE]]/header2-{{[A-Z0-9]+}}.pcm"
 // CHECK-ABS-NEXT: "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[HASH_H1_DINCLUDE]]/header1-{{[A-Z0-9]+}}.pcm"
-// CHECK-CUSTOM-NEXT:  "-fmodule-file=[[PREFIX]]/custom/[[HASH_H2_DINCLUDE]]/header2-{{[A-Z0-9]+}}.pcm"
 // CHECK-CUSTOM-NEXT:  "-fmodule-file=[[PREFIX]]/custom/[[HASH_H1_DINCLUDE]]/header1-{{[A-Z0-9]+}}.pcm"
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "file-deps": [
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -87,8 +87,7 @@
 }
 
 std::vector ModuleDeps::getCanonicalCommandLine(
-std::function LookupPCMPath,
-std:

[PATCH] D116015: [PowerPC] Add generic fnmsub intrinsic

2022-02-24 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf updated this revision to Diff 411046.
qiucf marked an inline comment as done.
qiucf edited the summary of this revision.
qiucf added a comment.

Replace existing `ppc.fnmsub` and `ppc.fnmsubs`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116015

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/PowerPC/builtins-ppc-fma.c
  clang/test/CodeGen/PowerPC/builtins-ppc-fpconstrained.c
  clang/test/CodeGen/PowerPC/builtins-ppc-vsx.c
  clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-math.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCInstrVSX.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-math.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-math.ll
===
--- llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-math.ll
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-math.ll
@@ -98,49 +98,104 @@
 
 declare float @llvm.ppc.fnmadds(float, float, float)
 
-define dso_local double @fnmsub_t0(double %d, double %d2, double %d3) {
-; CHECK-PWR8-LABEL: fnmsub_t0:
+define dso_local float @fnmsub_f32(float %f, float %f2, float %f3) {
+; CHECK-PWR8-LABEL: fnmsub_f32:
 ; CHECK-PWR8:   # %bb.0: # %entry
-; CHECK-PWR8-NEXT:xsnmsubmdp 1, 2, 3
+; CHECK-PWR8-NEXT:xsnmsubasp 3, 1, 2
+; CHECK-PWR8-NEXT:fmr 1, 3
 ; CHECK-PWR8-NEXT:blr
 ;
-; CHECK-NOVSX-LABEL: fnmsub_t0:
+; CHECK-NOVSX-LABEL: fnmsub_f32:
+; CHECK-NOVSX:   # %bb.0: # %entry
+; CHECK-NOVSX-NEXT:fnmsubs 1, 1, 2, 3
+; CHECK-NOVSX-NEXT:blr
+;
+; CHECK-PWR7-LABEL: fnmsub_f32:
+; CHECK-PWR7:   # %bb.0: # %entry
+; CHECK-PWR7-NEXT:fnmsubs 1, 1, 2, 3
+; CHECK-PWR7-NEXT:blr
+entry:
+  %0 = tail call float @llvm.ppc.fnmsub.f32(float %f, float %f2, float %f3)
+  ret float %0
+}
+
+declare float @llvm.ppc.fnmsub.f32(float, float, float)
+
+define dso_local double @fnmsub_f64(double %f, double %f2, double %f3) {
+; CHECK-PWR8-LABEL: fnmsub_f64:
+; CHECK-PWR8:   # %bb.0: # %entry
+; CHECK-PWR8-NEXT:xsnmsubadp 3, 1, 2
+; CHECK-PWR8-NEXT:fmr 1, 3
+; CHECK-PWR8-NEXT:blr
+;
+; CHECK-NOVSX-LABEL: fnmsub_f64:
 ; CHECK-NOVSX:   # %bb.0: # %entry
 ; CHECK-NOVSX-NEXT:fnmsub 1, 1, 2, 3
 ; CHECK-NOVSX-NEXT:blr
 ;
-; CHECK-PWR7-LABEL: fnmsub_t0:
+; CHECK-PWR7-LABEL: fnmsub_f64:
 ; CHECK-PWR7:   # %bb.0: # %entry
-; CHECK-PWR7-NEXT:xsnmsubmdp 1, 2, 3
+; CHECK-PWR7-NEXT:xsnmsubadp 3, 1, 2
+; CHECK-PWR7-NEXT:fmr 1, 3
 ; CHECK-PWR7-NEXT:blr
 entry:
-  %0 = tail call double @llvm.ppc.fnmsub(double %d, double %d2, double %d3)
+  %0 = tail call double @llvm.ppc.fnmsub.f64(double %f, double %f2, double %f3)
   ret double %0
 }
 
-declare double @llvm.ppc.fnmsub(double, double, double)
+declare double @llvm.ppc.fnmsub.f64(double, double, double)
 
-define dso_local float @fnmsubs_t0(float %f, float %f2, float %f3) {
-; CHECK-PWR8-LABEL: fnmsubs_t0:
+define dso_local <4 x float> @fnmsub_v4f32(<4 x float> %f, <4 x float> %f2, <4 x float> %f3) {
+; CHECK-PWR8-LABEL: fnmsub_v4f32:
 ; CHECK-PWR8:   # %bb.0: # %entry
-; CHECK-PWR8-NEXT:xsnmsubmsp 1, 2, 3
+; CHECK-PWR8-NEXT:xvnmsubasp 36, 34, 35
+; CHECK-PWR8-NEXT:vmr 2, 4
 ; CHECK-PWR8-NEXT:blr
 ;
-; CHECK-NOVSX-LABEL: fnmsubs_t0:
+; CHECK-NOVSX-LABEL: fnmsub_v4f32:
 ; CHECK-NOVSX:   # %bb.0: # %entry
-; CHECK-NOVSX-NEXT:fnmsubs 1, 1, 2, 3
+; CHECK-NOVSX-NEXT:fnmsubs 1, 1, 5, 9
+; CHECK-NOVSX-NEXT:fnmsubs 2, 2, 6, 10
+; CHECK-NOVSX-NEXT:fnmsubs 3, 3, 7, 11
+; CHECK-NOVSX-NEXT:fnmsubs 4, 4, 8, 12
 ; CHECK-NOVSX-NEXT:blr
 ;
-; CHECK-PWR7-LABEL: fnmsubs_t0:
+; CHECK-PWR7-LABEL: fnmsub_v4f32:
 ; CHECK-PWR7:   # %bb.0: # %entry
-; CHECK-PWR7-NEXT:fnmsubs 1, 1, 2, 3
+; CHECK-PWR7-NEXT:xvnmsubasp 36, 34, 35
+; CHECK-PWR7-NEXT:vmr 2, 4
 ; CHECK-PWR7-NEXT:blr
 entry:
-  %0 = tail call float @llvm.ppc.fnmsubs(float %f, float %f2, float %f3)
-  ret float %0
+  %0 = tail call <4 x float> @llvm.ppc.fnmsub.v4f32(<4 x float> %f, <4 x float> %f2, <4 x float> %f3)
+  ret <4 x float> %0
+}
+
+declare <4 x float> @llvm.ppc.fnmsub.v4f32(<4 x float>, <4 x float>, <4 x float>)
+
+define dso_local <2 x double> @fnmsub_v2f64(<2 x double> %f, <2 x double> %f2, <2 x double> %f3) {
+; CHECK-PWR8-LABEL: fnmsub_v2f64:
+; CHECK-PWR8:   # %bb.0: # %entry
+; CHECK-PWR8-NEXT:xvnmsubadp 36, 34, 35
+; CHECK-PWR8-NEXT:vmr 2, 4
+; CHECK-PWR8-NEXT:blr
+;
+; CHECK-NOVSX-LABEL: fnmsub_v2f64:
+; CHECK-NOVSX:   # %bb.0: # %entry
+; CHECK-NOVSX-NEXT:fnmsub 1, 1, 3, 5
+; CHECK-NOVSX-NEXT:fnmsub 2, 2, 4, 6
+; CHECK-NOVSX-NEXT:blr
+;
+; CHECK-PWR7-LABEL: fnmsub_v2f64:
+; CHECK-PWR7:   # %bb.0: # %entry
+; CHECK-PWR7-NEXT:xvnmsubadp 36, 34, 35
+; CHECK-PWR7-NEXT:vmr 2, 4
+; CHECK-PWR7-NEXT:blr
+entry:
+  %0

[PATCH] D118370: [clang-tidy] bugprone-signal-handler: Message improvement and code refactoring.

2022-02-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 411047.
balazske added a comment.

Applied review comments, fixed the failing tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118370

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-minimal.c
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
  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
@@ -17,7 +17,7 @@
 
 void handler_printf(int) {
   printf("1234");
-  // CHECK-NOTES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: system call 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
   // CHECK-NOTES: :[[@LINE-2]]:3: note: function 'printf' called here from 'handler_printf'
   // CHECK-NOTES: :[[@LINE+4]]:18: note: function 'handler_printf' registered here as signal handler
 }
@@ -28,7 +28,7 @@
 
 void handler_extern(int) {
   f_extern();
-  // CHECK-NOTES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: cannot verify if external function 'f_extern' is asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
   // CHECK-NOTES: :[[@LINE-2]]:3: note: function 'f_extern' called here from 'handler_extern'
   // CHECK-NOTES: :[[@LINE+4]]:18: note: function 'handler_extern' registered here as signal handler
 }
@@ -51,7 +51,7 @@
 
 void f_bad() {
   printf("1234");
-  // CHECK-NOTES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: system call 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
   // CHECK-NOTES: :[[@LINE-2]]:3: note: function 'printf' called here from 'f_bad'
   // CHECK-NOTES: :[[@LINE+5]]:3: note: function 'f_bad' called here from 'handler_bad'
   // CHECK-NOTES: :[[@LINE+8]]:18: note: function 'handler_bad' registered here as signal handler
@@ -67,7 +67,7 @@
 
 void f_bad1() {
   printf("1234");
-  // CHECK-NOTES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: system call 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
   // CHECK-NOTES: :[[@LINE-2]]:3: note: function 'printf' called here from 'f_bad1'
   // CHECK-NOTES: :[[@LINE+6]]:3: note: function 'f_bad1' called here from 'f_bad2'
   // CHECK-NOTES: :[[@LINE+9]]:3: note: function 'f_bad2' called here from 'handler_bad1'
@@ -99,7 +99,7 @@
 void handler_false_condition(int) {
   if (0)
 printf("1234");
-  // CHECK-NOTES: :[[@LINE-1]]:5: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-1]]:5: warning: system call 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
   // CHECK-NOTES: :[[@LINE-2]]:5: note: function 'printf' called here from 'handler_false_condition'
   // CHECK-NOTES: :[[@LINE+4]]:18: note: function 'handler_false_condition' registered here as signal handler
 }
@@ -110,11 +110,11 @@
 
 void handler_multiple_calls(int) {
   f_extern();
-  // CHECK-NOTES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: cannot verify if external function 'f_extern' is asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
   // CHECK-NOTES: :[[@LINE-2]]:3: note: function 'f_extern' called here from 'handler_multiple_calls'
   // CHECK-NOTES: :[[@LINE+10]]:18: note: function 'handler_multiple_calls' registered here as signal handler
   printf("1234");
-  // CHECK-NOTES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+  // CHECK-NOTES: :[[@LINE-1]]:3: warning: system call 'printf' may not be asynchronous-safe; calling it from a signal handl

[clang] fb3a2d4 - [Sema] Silence unused variable warning in Release builds. NFC.

2022-02-24 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2022-02-24T11:00:52+01:00
New Revision: fb3a2d45cd79d3573dafcb7d26df355266b0228c

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

LOG: [Sema] Silence unused variable warning in Release builds. NFC.

Added: 


Modified: 
clang/lib/Sema/SemaModule.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 125dbefd9dd07..a797644754b59 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -484,6 +484,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
   } else if (getLangOpts().isCompilingModule()) {
 Module *ThisModule = PP.getHeaderSearchInfo().lookupModule(
 getLangOpts().CurrentModule, ExportLoc, false, false);
+(void)ThisModule;
 assert(ThisModule && "was expecting a module if building one");
   }
 
@@ -526,6 +527,7 @@ void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, 
Module *Mod) {
   if (getLangOpts().isCompilingModule()) {
 Module *ThisModule = PP.getHeaderSearchInfo().lookupModule(
 getLangOpts().CurrentModule, DirectiveLoc, false, false);
+(void)ThisModule;
 assert(ThisModule && "was expecting a module if building one");
   }
 }



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


[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-24 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

Hi, our internal release build bots are showing failures in two clang-tidy 
tests that I bisected back to your commit, 
clang-tidy/checkers/altera-id-dependent-backward-branch.cpp and 
clang-tidy/checkers/altera-single-work-item-barrier.cpp. After this change, 
both are exhibiting this error:

  Error while processing 
/home/dyung/src/upstream/aa9c2d19d9b73589d72114d6e0a4fb4ce42b922b-linux/tools/clang/tools/extra/test/clang-tidy/checkers/Output/altera-single-work-item-barrier.cpp.tmp.cpp.
  error: enum type memory_scope not found; include the base header with 
-finclude-default-header [clang-diagnostic-error]

Oddly, this only fails in a release configuration. Can you take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120254

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


[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

In D120254#3342551 , @dyung wrote:

> Hi, our internal release build bots are showing failures in two clang-tidy 
> tests that I bisected back to your commit, 
> clang-tidy/checkers/altera-id-dependent-backward-branch.cpp and 
> clang-tidy/checkers/altera-single-work-item-barrier.cpp. After this change, 
> both are exhibiting this error:
>
>   Error while processing 
> /home/dyung/src/upstream/aa9c2d19d9b73589d72114d6e0a4fb4ce42b922b-linux/tools/clang/tools/extra/test/clang-tidy/checkers/Output/altera-single-work-item-barrier.cpp.tmp.cpp.
>   error: enum type memory_scope not found; include the base header with 
> -finclude-default-header [clang-diagnostic-error]
>
> Oddly, this only fails in a release configuration. Can you take a look?

I'll try to reproduce the failure locally, but until I've done so perhaps you 
could try whether the following fixes one of the tests?  If so, then the other 
test will likely need a similar fix.

  diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
  index a6dbab7b72fc..9bc1bbf173cc 100644
  --- 
a/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
  +++ 
b/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
  @@ -1,4 +1,4 @@
  -// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h
  +// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h --include 
opencl-c-base.h
   
   typedef struct ExampleStruct {
 int IDDepField;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120254

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


[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-24 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

In D120254#3342570 , @svenvh wrote:

> In D120254#3342551 , @dyung wrote:
>
>> Hi, our internal release build bots are showing failures in two clang-tidy 
>> tests that I bisected back to your commit, 
>> clang-tidy/checkers/altera-id-dependent-backward-branch.cpp and 
>> clang-tidy/checkers/altera-single-work-item-barrier.cpp. After this change, 
>> both are exhibiting this error:
>>
>>   Error while processing 
>> /home/dyung/src/upstream/aa9c2d19d9b73589d72114d6e0a4fb4ce42b922b-linux/tools/clang/tools/extra/test/clang-tidy/checkers/Output/altera-single-work-item-barrier.cpp.tmp.cpp.
>>   error: enum type memory_scope not found; include the base header with 
>> -finclude-default-header [clang-diagnostic-error]
>>
>> Oddly, this only fails in a release configuration. Can you take a look?
>
> I'll try to reproduce the failure locally, but until I've done so perhaps you 
> could try whether the following fixes one of the tests?  If so, then the 
> other test will likely need a similar fix.
>
>   diff --git 
> a/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
>  
> b/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
>   index a6dbab7b72fc..9bc1bbf173cc 100644
>   --- 
> a/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
>   +++ 
> b/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
>   @@ -1,4 +1,4 @@
>   -// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
> -header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h
>   +// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
> -header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h --include 
> opencl-c-base.h
>
>typedef struct ExampleStruct {
>  int IDDepField;

I just tried that patch and it doesn't seem to fix it unfortunately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120254

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


[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-24 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

If it helps, this is the cmake command I am using to build using gcc on linux:

  CMake command: -G Ninja -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_VERSION_SUFFIX= 
-DLLVM_BUILD_RUNTIME=ON -DLLVM_TOOL_LLD_BUILD=OFF "-DLLVM_LIT_ARGS=--verbose 
-j80 --no-progress-bar --max-tests 10" -DCMAKE_BUILD_TYPE=Release 
-DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_TARGETS_TO_BUILD=all 
-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra

Some of the stuff there probably isn't needed (it's taken from a general script 
that I make small changes to when trying to reproduce stuff), but is there for 
completeness.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120254

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


[PATCH] D120246: [flang][driver] Add support for `--target`/`--triple`

2022-02-24 Thread Mats Petersson via Phabricator via cfe-commits
MatsPetersson added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120246

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


[PATCH] D118987: [analyzer] Add failing test case demonstrating buggy taint propagation

2022-02-24 Thread Balázs Benics via Phabricator via cfe-commits
steakhal marked an inline comment as done.
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:782
+if (PropDstArgs.contains(I)) {
+  LLVM_DEBUG(llvm::dbgs() << "PreCall<"; Call.dump(llvm::dbgs());
+ llvm::dbgs()

MaskRay wrote:
> There was a -Wunused-lambda-capture in `-DLLVM_ENABLE_ASSERTIONS=off` builds. 
> Fixed by 7fd60ee6e0a87957a718297a4a42d9881fc561e3
Ah, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118987

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


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2022-02-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

In D93298#3342480 , 
@achieveartificialintelligence wrote:

> In D93298#3342452 , @krasimir wrote:
>
>> @achieveartificialintelligence any progress with the problematic IR? Have 
>> you been able to reproduce using nikic's reduced example?
>
> Sorry, I don't have a solution right now.

Could we revert this until then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

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


[clang] a8b4b91 - [NFC][clang] Simplify `isOneOf` function

2022-02-24 Thread Shao-Ce SUN via cfe-commits

Author: Shao-Ce SUN
Date: 2022-02-24T19:12:34+08:00
New Revision: a8b4b9104c8f7ab5edb8651a900e61279e8bf931

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

LOG: [NFC][clang] Simplify `isOneOf` function

Reviewed By: tmatheson

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

Added: 


Modified: 
clang/include/clang/Lex/Token.h

Removed: 




diff  --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h
index 00fbe6d18f721..7115d68f0f269 100644
--- a/clang/include/clang/Lex/Token.h
+++ b/clang/include/clang/Lex/Token.h
@@ -99,9 +99,8 @@ class Token {
   bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const {
 return is(K1) || is(K2);
   }
-  template 
-  bool isOneOf(tok::TokenKind K1, tok::TokenKind K2, Ts... Ks) const {
-return is(K1) || isOneOf(K2, Ks...);
+  template  bool isOneOf(tok::TokenKind K1, Ts... Ks) const {
+return is(K1) || isOneOf(Ks...);
   }
 
   /// Return true if this is a raw identifier (when lexing



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


[PATCH] D117740: [NFC][clang] Simplify `isOneOf` function

2022-02-24 Thread Shao-Ce SUN via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa8b4b9104c8f: [NFC][clang] Simplify `isOneOf` function 
(authored by achieveartificialintelligence).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117740

Files:
  clang/include/clang/Lex/Token.h


Index: clang/include/clang/Lex/Token.h
===
--- clang/include/clang/Lex/Token.h
+++ clang/include/clang/Lex/Token.h
@@ -99,9 +99,8 @@
   bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const {
 return is(K1) || is(K2);
   }
-  template 
-  bool isOneOf(tok::TokenKind K1, tok::TokenKind K2, Ts... Ks) const {
-return is(K1) || isOneOf(K2, Ks...);
+  template  bool isOneOf(tok::TokenKind K1, Ts... Ks) const {
+return is(K1) || isOneOf(Ks...);
   }
 
   /// Return true if this is a raw identifier (when lexing


Index: clang/include/clang/Lex/Token.h
===
--- clang/include/clang/Lex/Token.h
+++ clang/include/clang/Lex/Token.h
@@ -99,9 +99,8 @@
   bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const {
 return is(K1) || is(K2);
   }
-  template 
-  bool isOneOf(tok::TokenKind K1, tok::TokenKind K2, Ts... Ks) const {
-return is(K1) || isOneOf(K2, Ks...);
+  template  bool isOneOf(tok::TokenKind K1, Ts... Ks) const {
+return is(K1) || isOneOf(Ks...);
   }
 
   /// Return true if this is a raw identifier (when lexing
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120468: [clang][NFC] Move all avr CodeGen tests to avr specific directory

2022-02-24 Thread Ben Shi via Phabricator via cfe-commits
benshi001 created this revision.
benshi001 added reviewers: MaskRay, dylanmckay, aykevl.
Herald added a subscriber: Jim.
benshi001 requested review of this revision.
Herald added subscribers: cfe-commits, jacquesguan.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120468

Files:
  clang/test/CodeGen/address-space-avr.c
  clang/test/CodeGen/alias-avr.c
  clang/test/CodeGen/avr-builtins.c
  clang/test/CodeGen/avr-flash.c
  clang/test/CodeGen/avr-inline-asm-constraints.c
  clang/test/CodeGen/avr-unsupported-inline-asm-constraints.c
  clang/test/CodeGen/avr/address-space-avr.c
  clang/test/CodeGen/avr/alias-avr.c
  clang/test/CodeGen/avr/avr-builtins.c
  clang/test/CodeGen/avr/avr-flash.c
  clang/test/CodeGen/avr/avr-inline-asm-constraints.c
  clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c




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


[PATCH] D120468: [clang][NFC] Move all avr CodeGen tests to avr specific directory

2022-02-24 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

There are also other AVR tests in the folder clang/test/CodeGen/avr, so it 
would be better to put them together.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120468

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


[PATCH] D118333: [RISCV] Use computeTargetABI from llc as well as clang

2022-02-24 Thread Alex Bradbury via Phabricator via cfe-commits
asb accepted this revision.
asb added a comment.
This revision is now accepted and ready to land.

In D118333#3329422 , @asb wrote:

> Thanks, I've put this on the agenda for the RISC-V LLVM sync call today. I 
> think this is more attractive than the previous proposal due to unifying 
> logic between llc and Clang. I could see a counter-argument about llc being a 
> low-level tool that should be controlled very explicitly.

I forgot to update on this. Nobody had particularly strong feelings either way, 
but I think the overall consensus was that this change seemed sensible. Landing 
this after the LLVM 14 branch also feels like a good time for it. LGTM - thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118333

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


[PATCH] D120470: [clang-tidy] Update tests to include opencl-c-base.h

2022-02-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: dyung.
Herald added subscribers: Naghasan, ldrumm, xazax.hun, Anastasia, yaxunl.
svenvh requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

After D120254  some clang-tidy tests started 
failing on release builds.
clang-tidy appears to be using the `-fdeclare-opencl-builtins`
functionality, so there is no need to include the full `opencl-c.h`
header.  Instead, only include the base header, which contains
definitions required by `-fdeclare-opencl-builtins`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120470

Files:
  
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
  clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
@@ -1,7 +1,7 @@
-// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c 
--include opencl-c.h -DOLDCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c 
--include opencl-c.h -DNEWCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL1.2 -c --include opencl-c.h -DOLDCLNEWAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL2.0 -c --include opencl-c.h -DNEWCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c 
--include opencl-c-base.h -DOLDCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c 
--include opencl-c-base.h -DNEWCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL1.2 -c --include opencl-c-base.h -DOLDCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL2.0 -c --include opencl-c-base.h -DNEWCLNEWAOC
 
 #ifdef OLDCLOLDAOC  // OpenCL 1.2 Altera Offline Compiler < 17.1
 void __kernel error_barrier_no_id(__global int * foo, int size) {
Index: 
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h
+// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c-base.h
 
 typedef struct ExampleStruct {
   int IDDepField;


Index: clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
@@ -1,7 +1,7 @@
-// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h -DOLDCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c --include opencl-c.h -DNEWCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h -DOLDCLNEWAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* "--" -cl-std=CL2.0 -c --include opencl-c.h -DNEWCLNEWAOC
+// RUN: %check_clang_tidy -c

[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

Thanks, I could reproduce the problem with your cmake line.  I have uploaded a 
fix for review in https://reviews.llvm.org/D120470


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120254

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


[clang] 88182e2 - [OpenCL] opencl-c.h: remove arg names for image builtins

2022-02-24 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-24T11:52:32Z
New Revision: 88182e2dfde295a8f6adc9e6148410e86c71680d

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

LOG: [OpenCL] opencl-c.h: remove arg names for image builtins

This simplifies completeness comparisons against OpenCLBuiltins.td and
also makes the header no longer "claim" the identifiers "image",
"image_array", "coord", "sampler", "sample", "gradientX", "gradientY",
"lod", and "color".

Continues the direction set out in D119560.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 172b2c192709..0adf07cc7e3d 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -15200,123 +15200,123 @@ half16 __ovld __cnfn shuffle2(half16 x, half16 y, 
ushort16 mask);
  * in the description above are undefined.
  */
 
-float4 __ovld __purefn read_imagef(read_only image2d_t image, sampler_t 
sampler, int2 coord);
-float4 __ovld __purefn read_imagef(read_only image2d_t image, sampler_t 
sampler, float2 coord);
+float4 __ovld __purefn read_imagef(read_only image2d_t, sampler_t, int2);
+float4 __ovld __purefn read_imagef(read_only image2d_t, sampler_t, float2);
 
-int4 __ovld __purefn read_imagei(read_only image2d_t image, sampler_t sampler, 
int2 coord);
-int4 __ovld __purefn read_imagei(read_only image2d_t image, sampler_t sampler, 
float2 coord);
-uint4 __ovld __purefn read_imageui(read_only image2d_t image, sampler_t 
sampler, int2 coord);
-uint4 __ovld __purefn read_imageui(read_only image2d_t image, sampler_t 
sampler, float2 coord);
+int4 __ovld __purefn read_imagei(read_only image2d_t, sampler_t, int2);
+int4 __ovld __purefn read_imagei(read_only image2d_t, sampler_t, float2);
+uint4 __ovld __purefn read_imageui(read_only image2d_t, sampler_t, int2);
+uint4 __ovld __purefn read_imageui(read_only image2d_t, sampler_t, float2);
 
-float4 __ovld __purefn read_imagef(read_only image3d_t image, sampler_t 
sampler, int4 coord);
-float4 __ovld __purefn read_imagef(read_only image3d_t image, sampler_t 
sampler, float4 coord);
+float4 __ovld __purefn read_imagef(read_only image3d_t, sampler_t, int4);
+float4 __ovld __purefn read_imagef(read_only image3d_t, sampler_t, float4);
 
-int4 __ovld __purefn read_imagei(read_only image3d_t image, sampler_t sampler, 
int4 coord);
-int4 __ovld __purefn read_imagei(read_only image3d_t image, sampler_t sampler, 
float4 coord);
-uint4 __ovld __purefn read_imageui(read_only image3d_t image, sampler_t 
sampler, int4 coord);
-uint4 __ovld __purefn read_imageui(read_only image3d_t image, sampler_t 
sampler, float4 coord);
+int4 __ovld __purefn read_imagei(read_only image3d_t, sampler_t, int4);
+int4 __ovld __purefn read_imagei(read_only image3d_t, sampler_t, float4);
+uint4 __ovld __purefn read_imageui(read_only image3d_t, sampler_t, int4);
+uint4 __ovld __purefn read_imageui(read_only image3d_t, sampler_t, float4);
 
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
-float4 __ovld __purefn read_imagef(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
-float4 __ovld __purefn read_imagef(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
+float4 __ovld __purefn read_imagef(read_only image2d_array_t, sampler_t, int4);
+float4 __ovld __purefn read_imagef(read_only image2d_array_t, sampler_t, 
float4);
 
-int4 __ovld __purefn read_imagei(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
-int4 __ovld __purefn read_imagei(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
-uint4 __ovld __purefn read_imageui(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
-uint4 __ovld __purefn read_imageui(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
+int4 __ovld __purefn read_imagei(read_only image2d_array_t, sampler_t, int4);
+int4 __ovld __purefn read_imagei(read_only image2d_array_t, sampler_t, float4);
+uint4 __ovld __purefn read_imageui(read_only image2d_array_t, sampler_t, int4);
+uint4 __ovld __purefn read_imageui(read_only image2d_array_t, sampler_t, 
float4);
 #endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_1_2)
 
-float4 __ovld __purefn read_imagef(read_only image1d_t image, sampler_t 
sampler, int coord);
-float4 __ovld __purefn read_imagef(read_only image1d_t image, sampler_t 
sampler, float coord);
+float4 __ovld __purefn read_imagef(read_only image1d_t, sampler_t, int);
+float4 __ovld __purefn read_imagef(read_only image1d_t, sampler_t, float);
 
-int4 __ovld __purefn read_imagei(read_only image1d_t image, sampler_t sampler, 
int coord);
-int4 __ovld __purefn read_imagei(read_only image1d_t imag

[PATCH] D109239: Add support for floating-option `-ffp-eval-method` and for new `pragma clang fp eval-method`

2022-02-24 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D109239#3341696 , @thakis wrote:

> Actually, I did it myself in 34285bcd5ac260246c9d59708a63ea3d5972f75c 
> 

@thakis Thanks!


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

https://reviews.llvm.org/D109239

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


[PATCH] D120474: [clang][deps] Remove '-fmodules-cache-path=' arguments

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

With explicit modules build, the '-fmodules-cache-path=' argument is unused.

This patch removes the argument to avoid warnings or errors (with '-Werror') 
stemming from that.

Depends on D118915 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120474

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-inferred-explicit-build.m
  clang/tools/clang-scan-deps/ClangScanDeps.cpp


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -374,11 +374,11 @@
 const ModuleDeps &MD = MDIt->second;
 
 StringRef Filename = llvm::sys::path::filename(MD.ImplicitModulePCMPath);
+StringRef ModuleCachePath = llvm::sys::path::parent_path(
+llvm::sys::path::parent_path(MD.ImplicitModulePCMPath));
 
-SmallString<256> ExplicitPCMPath(
-!ModuleFilesDir.empty()
-? ModuleFilesDir
-: MD.BuildInvocation.getHeaderSearchOpts().ModuleCachePath);
+SmallString<256> ExplicitPCMPath(!ModuleFilesDir.empty() ? ModuleFilesDir
+ : 
ModuleCachePath);
 llvm::sys::path::append(ExplicitPCMPath, MD.ID.ContextHash, Filename);
 return std::string(ExplicitPCMPath);
   }
Index: clang/test/ClangScanDeps/modules-inferred-explicit-build.m
===
--- clang/test/ClangScanDeps/modules-inferred-explicit-build.m
+++ clang/test/ClangScanDeps/modules-inferred-explicit-build.m
@@ -12,7 +12,7 @@
 // RUN: %python %S/../../utils/module-deps-to-rsp.py %t.db --tu-index=0 > 
%t.tu.rsp
 // RUN: %clang @%t.inferred.cc1.rsp -pedantic -Werror
 // RUN: %clang @%t.system.cc1.rsp -pedantic -Werror
-// RUN: %clang @%t.tu.rsp -pedantic -Werror -Wno-unused-command-line-argument
+// RUN: %clang @%t.tu.rsp -pedantic -Werror
 
 #include 
 #include 
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -51,6 +51,7 @@
 
   CI.getLangOpts()->ImplicitModules = false;
   CI.getHeaderSearchOpts().ImplicitModuleMaps = false;
+  CI.getHeaderSearchOpts().ModuleCachePath.clear();
 
   // Report the prebuilt modules this module uses.
   for (const auto &PrebuiltModule : Deps.PrebuiltModuleDeps)
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -31,7 +31,10 @@
   getAdditionalArgsWithoutModulePaths();
   Args.insert(Args.end(), AdditionalArgs.begin(), AdditionalArgs.end());
 
-  // TODO: Filter out implicit modules leftovers (e.g. 
"-fmodules-cache-path=").
+  // This argument is unused in explicit compiles.
+  llvm::erase_if(Args, [](const std::string &Arg) {
+return Arg.find("-fmodules-cache-path=") == 0;
+  });
 
   return Args;
 }


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -374,11 +374,11 @@
 const ModuleDeps &MD = MDIt->second;
 
 StringRef Filename = llvm::sys::path::filename(MD.ImplicitModulePCMPath);
+StringRef ModuleCachePath = llvm::sys::path::parent_path(
+llvm::sys::path::parent_path(MD.ImplicitModulePCMPath));
 
-SmallString<256> ExplicitPCMPath(
-!ModuleFilesDir.empty()
-? ModuleFilesDir
-: MD.BuildInvocation.getHeaderSearchOpts().ModuleCachePath);
+SmallString<256> ExplicitPCMPath(!ModuleFilesDir.empty() ? ModuleFilesDir
+ : ModuleCachePath);
 llvm::sys::path::append(ExplicitPCMPath, MD.ID.ContextHash, Filename);
 return std::string(ExplicitPCMPath);
   }
Index: clang/test/ClangScanDeps/modules-inferred-explicit-build.m
===
--- clang/test/ClangScanDeps/modules-inferred-explicit-build.m
+++ clang/test/ClangScanDeps/modules-inferred-explicit-build.m
@@ -12,7 +12,7 @@
 // RUN: %python %S/../../utils/module-deps-to-rsp.py %t.db --tu-index=0 > %t.tu.rsp
 // RUN: %clang @%t.inferred.cc1.rsp -pedantic -Werror
 // RUN: %clang @%t.system.cc1.rsp -pedantic

[PATCH] D120475: [clang][AVR] Implement standard calling convention for AVR and AVRTiny

2022-02-24 Thread Ben Shi via Phabricator via cfe-commits
benshi001 created this revision.
benshi001 added reviewers: aykevl, dylanmckay.
Herald added a subscriber: Jim.
benshi001 requested review of this revision.
Herald added subscribers: cfe-commits, jacquesguan.
Herald added a project: clang.

The standard calling convention of AVR is documented at
https://gcc.gnu.org/wiki/avr-gcc#Calling_Convention


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120475

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/AVR.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/avr/argument.c

Index: clang/test/CodeGen/avr/argument.c
===
--- /dev/null
+++ clang/test/CodeGen/avr/argument.c
@@ -0,0 +1,87 @@
+// RUN: %clang_cc1 -triple avr -target-cpu atmega328 -emit-llvm %s -o - \
+// RUN: | FileCheck %s --check-prefix AVR
+// RUN: %clang_cc1 -triple avr -target-cpu attiny40 -emit-llvm %s -o - \
+// RUN: | FileCheck %s --check-prefix TINY
+
+// NOTE: All arguments are passed in memory for functions with variable arguments.
+// AVR:  define {{.*}} i16 @foo_varargs(i16* {{.*}} %0, i16* {{.*}} %1, ...)
+// TINY: define {{.*}} i16 @foo_varargs(i16* {{.*}} %0, i16* {{.*}} %1, ...)
+int foo_varargs(int a, int b, ...) {
+  return a + b;
+}
+
+// NOTE: A 10-byte argument is passed in registers on avr but in memory on avrtiny.
+// AVR:  define {{.*}} i16 @foo0([10 x i8]{{.*}})
+// TINY: define {{.*}} i16 @foo0(%struct.s10* {{.*}})
+struct s10 {
+  char arr[10];
+};
+int foo0(struct s10 v) {
+  return v.arr[0] + v.arr[1];
+}
+
+// NOTE: The 8-byte argument is always passed in registers. The other arguments are passed
+// NOTE: in registers on avr but in memory on avrtiny.
+// AVR:  define {{.*}} i16 @foo1([8 x i8] {{.*}}, i16  {{.*}}, i32  {{.*}})
+// TINY: define {{.*}} i16 @foo1([8 x i8] {{.*}}, i16* {{.*}}, i32* {{.*}})
+struct s8 {
+  char arr[8];
+};
+int foo1(struct s8 a, int b, long c) {
+  return a.arr[b + c];
+}
+
+// NOTE: All arguments are passed in registers.
+// AVR:  define {{.*}} i32 @foo2(i32 {{.*}}, i16 {{.*}}, i16 {{.*}})
+// TINY: define {{.*}} i32 @foo2(i32 {{.*}}, i16 {{.*}}, i16 {{.*}})
+long foo2(long a, int b, int c) {
+  return a + b + c;
+}
+
+// NOTE: The arguments a&b are passed in registers. The argument c is passed
+// NOTE: in register on avr but in memory on avrtiny.
+// AVR:  define {{.*}} i32 @foo3(i32 {{.*}}, i16 {{.*}}, i32  {{.*}})
+// TINY: define {{.*}} i32 @foo3(i32 {{.*}}, i16 {{.*}}, i32* {{.*}})
+long foo3(long a, int b, long c) {
+  return a + b + c;
+}
+
+// NOTE: An int8 arguments will be extended to i16 if passed in registers.
+// AVR:  define {{.*}} i16 @foo4(i8 {{.*}} signext {{.*}}, i8 {{.*}} zeroext {{.*}})
+// TINY: define {{.*}} i16 @foo4(i8 {{.*}} signext {{.*}}, i8 {{.*}} zeroext {{.*}})
+int foo4(char a, unsigned char b) {
+  return (int)a + (int)b;
+}
+
+// NOTE: On avrtiny, although the first argument only costs 7 registers, the second
+// NOTE: argument (with i8 type) is passed in memory.
+// TINY: define {{.*}} i16 @foo5([7 x i8] {{.*}}, i8* {{.*}})
+struct s7 {
+  char arr[7];
+};
+int foo5(struct s7 a, char b) {
+  return a.arr[b];
+}
+
+// NOTE: On avr, although the first argument only costs 17 registers, the second
+// NOTE: argument (with i8 type) is passed in memory.
+// AVR: define {{.*}} i16 @foo6([17 x i8] {{.*}}, i8* {{.*}})
+struct s17 {
+  char arr[17];
+};
+int foo6(struct s17 a, char b) {
+  return a.arr[b];
+}
+
+// NOTE: On avr, all arguments are passed in registers.
+// AVR: define {{.*}} i32 @foo7(i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i16 {{.*}})
+long foo7(long a, long b, long c, long d, int e) {
+  return a + b + c + d + e;
+}
+
+// NOTE: On avr, the arguments a&b&c&d are passed in registers, but e is
+// NOTE: passed in memory.
+// AVR: define {{.*}} i32 @foo8(i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32* {{.*}})
+long foo8(long a, long b, long c, long d, long e) {
+  return a + b + c + d + e;
+}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -33,6 +33,7 @@
 #include "llvm/IR/IntrinsicsNVPTX.h"
 #include "llvm/IR/IntrinsicsS390.h"
 #include "llvm/IR/Type.h"
+#include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
 #include  // std::sort
 
@@ -8273,8 +8274,14 @@
 
 namespace {
 class AVRABIInfo : public DefaultABIInfo {
+private:
+  // The total amount of registers can be used to pass parameters. It is 18 on
+  // AVR, or 8 on AVRTiny.
+  unsigned ParamRegs;
+
 public:
-  AVRABIInfo(CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
+  AVRABIInfo(CodeGenTypes &CGT, unsigned N)
+  : DefaultABIInfo(CGT), ParamRegs(N) {}
 
   ABIArgInfo classifyReturnType(QualType Ty) const {
 // A return struct with size less than or equal to 8 bytes is returned
@@ -8285,20 +8292,55 @@
   return DefaultABIInfo::classifyReturnType(Ty);
   

[PATCH] D120475: [clang][AVR] Implement standard calling convention for AVR and AVRTiny

2022-02-24 Thread Ben Shi via Phabricator via cfe-commits
benshi001 updated this revision to Diff 411090.

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

https://reviews.llvm.org/D120475

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/AVR.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/avr/argument.c

Index: clang/test/CodeGen/avr/argument.c
===
--- /dev/null
+++ clang/test/CodeGen/avr/argument.c
@@ -0,0 +1,87 @@
+// RUN: %clang_cc1 -triple avr -target-cpu atmega328 -emit-llvm %s -o - \
+// RUN: | FileCheck %s --check-prefix AVR
+// RUN: %clang_cc1 -triple avr -target-cpu attiny40 -emit-llvm %s -o - \
+// RUN: | FileCheck %s --check-prefix TINY
+
+// NOTE: All arguments are passed in memory for functions with variable arguments.
+// AVR:  define {{.*}} i16 @foo_varargs(i16* {{.*}} %0, i16* {{.*}} %1, ...)
+// TINY: define {{.*}} i16 @foo_varargs(i16* {{.*}} %0, i16* {{.*}} %1, ...)
+int foo_varargs(int a, int b, ...) {
+  return a + b;
+}
+
+// NOTE: A 10-byte argument is passed in registers on avr but in memory on avrtiny.
+// AVR:  define {{.*}} i16 @foo0([10 x i8]{{.*}})
+// TINY: define {{.*}} i16 @foo0(%struct.s10* {{.*}})
+struct s10 {
+  char arr[10];
+};
+int foo0(struct s10 v) {
+  return v.arr[0] + v.arr[1];
+}
+
+// NOTE: The 8-byte argument is always passed in registers. The other arguments are passed
+// NOTE: in registers on avr but in memory on avrtiny.
+// AVR:  define {{.*}} i16 @foo1([8 x i8] {{.*}}, i16  {{.*}}, i32  {{.*}})
+// TINY: define {{.*}} i16 @foo1([8 x i8] {{.*}}, i16* {{.*}}, i32* {{.*}})
+struct s8 {
+  char arr[8];
+};
+int foo1(struct s8 a, int b, long c) {
+  return a.arr[b + c];
+}
+
+// NOTE: All arguments are passed in registers.
+// AVR:  define {{.*}} i32 @foo2(i32 {{.*}}, i16 {{.*}}, i16 {{.*}})
+// TINY: define {{.*}} i32 @foo2(i32 {{.*}}, i16 {{.*}}, i16 {{.*}})
+long foo2(long a, int b, int c) {
+  return a + b + c;
+}
+
+// NOTE: The arguments a&b are passed in registers. The argument c is passed
+// NOTE: in register on avr but in memory on avrtiny.
+// AVR:  define {{.*}} i32 @foo3(i32 {{.*}}, i16 {{.*}}, i32  {{.*}})
+// TINY: define {{.*}} i32 @foo3(i32 {{.*}}, i16 {{.*}}, i32* {{.*}})
+long foo3(long a, int b, long c) {
+  return a + b + c;
+}
+
+// NOTE: An int8 arguments will be extended to i16 if passed in registers.
+// AVR:  define {{.*}} i16 @foo4(i8 {{.*}} signext {{.*}}, i8 {{.*}} zeroext {{.*}})
+// TINY: define {{.*}} i16 @foo4(i8 {{.*}} signext {{.*}}, i8 {{.*}} zeroext {{.*}})
+int foo4(char a, unsigned char b) {
+  return (int)a + (int)b;
+}
+
+// NOTE: On avrtiny, although the first argument only costs 7 registers, the second
+// NOTE: argument (with i8 type) is passed in memory.
+// TINY: define {{.*}} i16 @foo5([7 x i8] {{.*}}, i8* {{.*}})
+struct s7 {
+  char arr[7];
+};
+int foo5(struct s7 a, char b) {
+  return a.arr[b];
+}
+
+// NOTE: On avr, although the first argument only costs 17 registers, the second
+// NOTE: argument (with i8 type) is passed in memory.
+// AVR: define {{.*}} i16 @foo6([17 x i8] {{.*}}, i8* {{.*}})
+struct s17 {
+  char arr[17];
+};
+int foo6(struct s17 a, char b) {
+  return a.arr[b];
+}
+
+// NOTE: On avr, all arguments are passed in registers.
+// AVR: define {{.*}} i32 @foo7(i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i16 {{.*}})
+long foo7(long a, long b, long c, long d, int e) {
+  return a + b + c + d + e;
+}
+
+// NOTE: On avr, the arguments a&b&c&d are passed in registers, but e is
+// NOTE: passed in memory.
+// AVR: define {{.*}} i32 @foo8(i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32* {{.*}})
+long foo8(long a, long b, long c, long d, long e) {
+  return a + b + c + d + e;
+}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -33,6 +33,7 @@
 #include "llvm/IR/IntrinsicsNVPTX.h"
 #include "llvm/IR/IntrinsicsS390.h"
 #include "llvm/IR/Type.h"
+#include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
 #include  // std::sort
 
@@ -8273,8 +8274,14 @@
 
 namespace {
 class AVRABIInfo : public DefaultABIInfo {
+private:
+  // The total amount of registers can be used to pass parameters. It is 18 on
+  // AVR, or 8 on AVRTiny.
+  unsigned ParamRegs;
+
 public:
-  AVRABIInfo(CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
+  AVRABIInfo(CodeGenTypes &CGT, unsigned N)
+  : DefaultABIInfo(CGT), ParamRegs(N) {}
 
   ABIArgInfo classifyReturnType(QualType Ty) const {
 // A return struct with size less than or equal to 8 bytes is returned
@@ -8285,20 +8292,55 @@
   return DefaultABIInfo::classifyReturnType(Ty);
   }
 
-  // Just copy the original implementation of DefaultABIInfo::computeInfo(),
-  // since DefaultABIInfo::classify{Return,Argument}Type() are not virtual.
+  ABIArgInfo classifyArgumentType(QualType Ty, unsigned &NumRegs) const {
+unsigned TySize = getContext().getT

[PATCH] D120475: [clang][AVR] Implement standard calling convention for AVR and AVRTiny

2022-02-24 Thread Ben Shi via Phabricator via cfe-commits
benshi001 updated this revision to Diff 411094.

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

https://reviews.llvm.org/D120475

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/AVR.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/avr/argument.c

Index: clang/test/CodeGen/avr/argument.c
===
--- /dev/null
+++ clang/test/CodeGen/avr/argument.c
@@ -0,0 +1,90 @@
+// RUN: %clang_cc1 -triple avr -target-cpu atmega328 -emit-llvm %s -o - \
+// RUN: | FileCheck %s --check-prefix AVR
+// RUN: %clang_cc1 -triple avr -target-cpu attiny40 -emit-llvm %s -o - \
+// RUN: | FileCheck %s --check-prefix TINY
+
+// NOTE: All arguments are passed in memory for functions with variable arguments.
+// AVR:  define {{.*}} i16 @foo_varargs(i16* {{.*}} %0, i16* {{.*}} %1, ...)
+// TINY: define {{.*}} i16 @foo_varargs(i16* {{.*}} %0, i16* {{.*}} %1, ...)
+int foo_varargs(int a, int b, ...) {
+  return a + b;
+}
+
+// NOTE: A 10-byte argument is passed in registers on avr but in memory on avrtiny.
+// AVR:  define {{.*}} i16 @foo0([10 x i8]{{.*}})
+// TINY: define {{.*}} i16 @foo0(%struct.s10* {{.*}})
+struct s10 {
+  char arr[10];
+};
+int foo0(struct s10 v) {
+  return v.arr[0] + v.arr[1];
+}
+
+// NOTE: The 8-byte argument is always passed in registers. The other arguments are passed
+// NOTE: in registers on avr but in memory on avrtiny.
+// AVR:  define {{.*}} i16 @foo1([8 x i8] {{.*}}, i16  {{.*}}, i32  {{.*}})
+// TINY: define {{.*}} i16 @foo1([8 x i8] {{.*}}, i16* {{.*}}, i32* {{.*}})
+struct s8 {
+  char arr[8];
+};
+int foo1(struct s8 a, int b, long c) {
+  return a.arr[b + c];
+}
+
+// NOTE: All arguments are passed in registers.
+// AVR:  define {{.*}} i32 @foo2(i32 {{.*}}, i16 {{.*}}, i16 {{.*}})
+// TINY: define {{.*}} i32 @foo2(i32 {{.*}}, i16 {{.*}}, i16 {{.*}})
+long foo2(long a, int b, int c) {
+  return a + b + c;
+}
+
+// NOTE: The arguments a&b are passed in registers. The argument c is passed
+// NOTE: in register on avr but in memory on avrtiny.
+// AVR:  define {{.*}} i32 @foo3(i32 {{.*}}, i16 {{.*}}, i32  {{.*}})
+// TINY: define {{.*}} i32 @foo3(i32 {{.*}}, i16 {{.*}}, i32* {{.*}})
+long foo3(long a, int b, long c) {
+  return a + b + c;
+}
+
+// NOTE: An int8 arguments will be extended to i16 if passed in registers.
+// AVR:  define {{.*}} i16 @foo4(i8 {{.*}} signext {{.*}}, i8 {{.*}} zeroext {{.*}})
+// TINY: define {{.*}} i16 @foo4(i8 {{.*}} signext {{.*}}, i8 {{.*}} zeroext {{.*}})
+int foo4(char a, unsigned char b) {
+  return (int)a + (int)b;
+}
+
+// NOTE: On avrtiny, although the first argument only costs 7 registers, the second
+// NOTE: argument (with i8 type) is passed in memory. So there is one register
+// NOTE: that is vacant.
+// TINY: define {{.*}} i16 @foo5([7 x i8] {{.*}}, i8* {{.*}})
+struct s7 {
+  char arr[7];
+};
+int foo5(struct s7 a, char b) {
+  return a.arr[b];
+}
+
+// NOTE: On avr, although the first argument only costs 17 registers, the second
+// NOTE: argument (with i8 type) is passed in memory. So there is one register
+// NOTE: that is vacant.
+// AVR: define {{.*}} i16 @foo6([17 x i8] {{.*}}, i8* {{.*}})
+struct s17 {
+  char arr[17];
+};
+int foo6(struct s17 a, char b) {
+  return a.arr[b];
+}
+
+// NOTE: On avr, all arguments are passed in registers.
+// AVR: define {{.*}} i32 @foo7(i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i16 {{.*}})
+long foo7(long a, long b, long c, long d, int e) {
+  return a + b + c + d + e;
+}
+
+// NOTE: On avr, the arguments a&b&c&d are passed in registers, but e is
+// NOTE: passed in memory. Actually 16 registers are used, while 2 ones
+// NOTE: are vacant.
+// AVR: define {{.*}} i32 @foo8(i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32* {{.*}})
+long foo8(long a, long b, long c, long d, long e) {
+  return a + b + c + d + e;
+}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -33,6 +33,7 @@
 #include "llvm/IR/IntrinsicsNVPTX.h"
 #include "llvm/IR/IntrinsicsS390.h"
 #include "llvm/IR/Type.h"
+#include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
 #include  // std::sort
 
@@ -8273,8 +8274,14 @@
 
 namespace {
 class AVRABIInfo : public DefaultABIInfo {
+private:
+  // The total amount of registers can be used to pass parameters. It is 18 on
+  // AVR, or 8 on AVRTiny.
+  unsigned ParamRegs;
+
 public:
-  AVRABIInfo(CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
+  AVRABIInfo(CodeGenTypes &CGT, unsigned N)
+  : DefaultABIInfo(CGT), ParamRegs(N) {}
 
   ABIArgInfo classifyReturnType(QualType Ty) const {
 // A return struct with size less than or equal to 8 bytes is returned
@@ -8285,20 +8292,55 @@
   return DefaultABIInfo::classifyReturnType(Ty);
   }
 
-  // Just copy the original implementation of DefaultABIInfo::computeInfo(),
-  // since DefaultABII

[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

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

- Adds more tests for calls inside std, inline namespaces and adl lookup
- use llvm::find
- rename the warning flag to unqualified-std-cast-call to leave room for future 
extensions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/unqualified-std-call-fixits.cpp
  clang/test/SemaCXX/unqualified-std-call.cpp
  clang/test/SemaCXX/warn-self-move.cpp

Index: clang/test/SemaCXX/warn-self-move.cpp
===
--- clang/test/SemaCXX/warn-self-move.cpp
+++ clang/test/SemaCXX/warn-self-move.cpp
@@ -17,7 +17,8 @@
   (x) = std::move(x);  // expected-warning{{explicitly moving}}
 
   using std::move;
-  x = move(x);  // expected-warning{{explicitly moving}}
+  x = move(x); // expected-warning{{explicitly moving}} \
+   expected-warning {{unqualified call to std::move}}
 }
 
 int global;
@@ -26,7 +27,8 @@
   (global) = std::move(global);  // expected-warning{{explicitly moving}}
 
   using std::move;
-  global = move(global);  // expected-warning{{explicitly moving}}
+  global = move(global); // expected-warning{{explicitly moving}} \
+ expected-warning {{unqualified call to std::move}}
 }
 
 class field_test {
Index: clang/test/SemaCXX/unqualified-std-call.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/unqualified-std-call.cpp
@@ -0,0 +1,118 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall -std=c++11 %s
+
+namespace std {
+
+template 
+void dummy(T &&) {}
+template 
+void move(T &&) {}
+template 
+void move(T &&, U &&) {}
+
+inline namespace __1 {
+template 
+void forward(T &) {}
+} // namespace __1
+
+struct foo {};
+
+} // namespace std
+
+namespace global {
+
+using namespace std;
+
+void f() {
+  int i = 0;
+  std::move(i);
+  move(i);   // expected-warning{{unqualified call to std::move}}
+  (move)(i); // expected-warning{{unqualified call to std::move}}
+  std::dummy(1);
+  dummy(1);
+  std::move(1, 2);
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+  std::forward(i);
+}
+
+template 
+void g(T &&foo) {
+  std::move(foo);
+  move(foo); // expected-warning{{unqualified call to std::move}}
+
+  std::forward(foo);
+  forward(foo); // expected-warning{{unqualified call to std::forward}}
+  move(1, 2);
+  dummy(foo);
+}
+
+void call() {
+  g(0); //expected-note {{here}}
+}
+
+} // namespace global
+
+namespace named {
+
+using std::forward;
+using std::move;
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+template 
+void g(T &&foo) {
+  move(foo); // expected-warning{{unqualified call to std::move}}
+  forward(foo);   // expected-warning{{unqualified call to std::forward}}
+  (forward)(foo); // expected-warning{{unqualified call to std::forward}}
+  move(1, 2);
+}
+
+void call() {
+  g(0); //expected-note {{here}}
+}
+
+} // namespace named
+
+namespace overload {
+using namespace std;
+template 
+int move(T &&);
+void f() {
+  int i = 0;
+  move(i);
+}
+} // namespace overload
+
+namespace adl {
+void f() {
+  move(std::foo{}); // expected-warning{{unqualified call to std::move}}
+}
+
+} // namespace adl
+
+namespace std {
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+} // namespace std
+
+namespace test_alias {
+namespace alias = std;
+using namespace alias;
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+} // namespace test_alias
Index: clang/test/SemaCXX/unqualified-std-call-fixits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/unqualified-std-call-fixits.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -verify -std=c++20 -Wall %s
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -std=c++20 -fixit %t
+// RUN: %clang_cc1 -Wall -Werror -x c++ -std=c++20 %t
+// RUN: cat %t | FileCheck %s
+
+namespace std {
+
+void move(auto &&a) {}
+
+void forward(auto &a) {}
+
+} // namespace std
+
+using namespace std;
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning {{unqualified call to std::move}}
+  // CHECK: {{^}}  std::
+  forward(i); // expected-warning {{unqualified call to std::forward}}
+  // CHECK: {{^}}  std::
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- cl

[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 411101.
cor3ntin added a comment.

Fix comment to address Christopher's feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/unqualified-std-call-fixits.cpp
  clang/test/SemaCXX/unqualified-std-call.cpp
  clang/test/SemaCXX/warn-self-move.cpp

Index: clang/test/SemaCXX/warn-self-move.cpp
===
--- clang/test/SemaCXX/warn-self-move.cpp
+++ clang/test/SemaCXX/warn-self-move.cpp
@@ -17,7 +17,8 @@
   (x) = std::move(x);  // expected-warning{{explicitly moving}}
 
   using std::move;
-  x = move(x);  // expected-warning{{explicitly moving}}
+  x = move(x); // expected-warning{{explicitly moving}} \
+   expected-warning {{unqualified call to std::move}}
 }
 
 int global;
@@ -26,7 +27,8 @@
   (global) = std::move(global);  // expected-warning{{explicitly moving}}
 
   using std::move;
-  global = move(global);  // expected-warning{{explicitly moving}}
+  global = move(global); // expected-warning{{explicitly moving}} \
+ expected-warning {{unqualified call to std::move}}
 }
 
 class field_test {
Index: clang/test/SemaCXX/unqualified-std-call.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/unqualified-std-call.cpp
@@ -0,0 +1,118 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall -std=c++11 %s
+
+namespace std {
+
+template 
+void dummy(T &&) {}
+template 
+void move(T &&) {}
+template 
+void move(T &&, U &&) {}
+
+inline namespace __1 {
+template 
+void forward(T &) {}
+} // namespace __1
+
+struct foo {};
+
+} // namespace std
+
+namespace global {
+
+using namespace std;
+
+void f() {
+  int i = 0;
+  std::move(i);
+  move(i);   // expected-warning{{unqualified call to std::move}}
+  (move)(i); // expected-warning{{unqualified call to std::move}}
+  std::dummy(1);
+  dummy(1);
+  std::move(1, 2);
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+  std::forward(i);
+}
+
+template 
+void g(T &&foo) {
+  std::move(foo);
+  move(foo); // expected-warning{{unqualified call to std::move}}
+
+  std::forward(foo);
+  forward(foo); // expected-warning{{unqualified call to std::forward}}
+  move(1, 2);
+  dummy(foo);
+}
+
+void call() {
+  g(0); //expected-note {{here}}
+}
+
+} // namespace global
+
+namespace named {
+
+using std::forward;
+using std::move;
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+template 
+void g(T &&foo) {
+  move(foo); // expected-warning{{unqualified call to std::move}}
+  forward(foo);   // expected-warning{{unqualified call to std::forward}}
+  (forward)(foo); // expected-warning{{unqualified call to std::forward}}
+  move(1, 2);
+}
+
+void call() {
+  g(0); //expected-note {{here}}
+}
+
+} // namespace named
+
+namespace overload {
+using namespace std;
+template 
+int move(T &&);
+void f() {
+  int i = 0;
+  move(i);
+}
+} // namespace overload
+
+namespace adl {
+void f() {
+  move(std::foo{}); // expected-warning{{unqualified call to std::move}}
+}
+
+} // namespace adl
+
+namespace std {
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+} // namespace std
+
+namespace test_alias {
+namespace alias = std;
+using namespace alias;
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+} // namespace test_alias
Index: clang/test/SemaCXX/unqualified-std-call-fixits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/unqualified-std-call-fixits.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -verify -std=c++20 -Wall %s
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -std=c++20 -fixit %t
+// RUN: %clang_cc1 -Wall -Werror -x c++ -std=c++20 %t
+// RUN: cat %t | FileCheck %s
+
+namespace std {
+
+void move(auto &&a) {}
+
+void forward(auto &a) {}
+
+} // namespace std
+
+using namespace std;
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning {{unqualified call to std::move}}
+  // CHECK: {{^}}  std::
+  forward(i); // expected-warning {{unqualified call to std::forward}}
+  // CHECK: {{^}}  std::
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6416,6 +6416,38 @@
   }
 }
 
+// Once a call is fully resolved, warn for unqualified calls to specific
+// C++ standa

[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/SemaCXX/warn-self-move.cpp:20-21
   using std::move;
-  x = move(x);  // expected-warning{{explicitly moving}}
+  x = move(x); // expected-warning{{explicitly moving}} \
+   expected-warning {{unqualified call to std::move}}
 }

cjdb wrote:
> Rationale: there's less mental gymnastics when backslashes aren't involved.
I think this is unusual so I'd like @aaron.ballman 's opinion - I think to 
recall he asked me to make the exact opposite change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

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


[PATCH] D120398: [format] follow up: Use unsigned char as the base of all enums in FormatStyle

2022-02-24 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 411105.
kwk added a comment.

Rebased on upstream/main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120398

Files:
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : unsigned char {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -140,7 +140,7 @@
   /// ``AlignConsecutiveBitFields``), names in declarations (see
   /// ``AlignConsecutiveDeclarations``) or macro definitions (see
   /// ``AlignConsecutiveMacros``).
-  enum AlignConsecutiveStyle {
+  enum AlignConsecutiveStyle : unsigned char {
 ACS_None,
 ACS_Consecutive,
 ACS_AcrossEmptyLines,
@@ -1771,7 +1771,7 @@
   BraceWrappingFlags BraceWrapping;
 
   /// Different ways to break before concept declarations.
-  enum BreakBeforeConceptDeclarationsStyle {
+  enum BreakBeforeConceptDeclarationsStyle : unsigned char {
 /// Keep the template declaration line together with ``concept``.
 /// \code
 ///   template  concept C = ...;
@@ -1882,7 +1882,7 @@
   std::string CommentPragmas;
 
   /// Different specifiers and qualifiers alignment styles.
-  enum QualifierAlignmentStyle {
+  enum QualifierAlignmentStyle : unsigned char {
 /// Don't change specifiers/qualifiers to either Left or Right alignment
 /// (default).
 /// \code
@@ -3067,7 +3067,7 @@
   std::vector RawStringFormats;
 
   /// \brief The ``&`` and ``&&`` alignment style.
-  enum ReferenceAlignmentStyle {
+  enum ReferenceAlignmentStyle : unsigned char {
 /// Align reference like ``PointerAlignment``.
 RAS_Pointer,
 /// Align reference to the left.
@@ -3166,7 +3166,7 @@
   /// \brief The possible positions for the requires clause. The
   /// ``IndentRequires`` option is only used if the ``requires`` is put on the
   /// start of a line.
-  enum RequiresClausePositionStyle {
+  enum RequiresClausePositionStyle : unsigned char {
 /// Always put the ``requires`` clause on its own line.
 /// \code
 ///   template 
@@ -3245,7 +3245,7 @@
   RequiresClausePositionStyle RequiresClausePosition;
 
   /// \brief The style if definition blocks should be separated.
-  enum SeparateDefinitionStyle {
+  enum SeparateDefinitionStyle : unsigned char {
 /// Leave definition blocks as they are.
 SDS_Leave,
 /// Insert an empty line between definition blocks.


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : unsigned char {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -140,7 +140,7 @@
   /// ``AlignConsecutiveBitFields``), names in declarations (see
   /// ``AlignConsecutiveDeclarations``) or macro definitions (see
   /// ``AlignConsecutiveMacros``).
-  enum AlignConsecutiveStyle {
+  enum AlignConsecutiveStyle : unsigned char {
 ACS_None,
 ACS_Consecutive,
 ACS_AcrossEmptyLines,
@@ -1771,7 +1771,7 @@
   BraceWrappingFlags BraceWrapping;
 
   /// Different ways to break before concept declarations.
-  enum BreakBeforeConceptDeclarationsStyle {
+  enum BreakBeforeConceptDeclarationsStyle : unsigned char {
 /// Keep the template declaration line together with ``concept``.
 /// \code
 ///   template  concept C = ...;
@@ -1882,7 +1882,7 @@
   std::string CommentPragmas;
 
   /// Different specifiers and qualifiers alignment styles.
-  enum QualifierAlignmentStyle {
+  enum QualifierAlignmentStyle : unsigned char {
 /// Don't change specifiers/qualifiers to either Left or Right alignment
 /// (default).
 /// \code
@@ -3067,7 +3067,7 @@
   std::vector RawStringFormats;
 
   /// \brief The ``&`` and ``&&`` alignment style.
-  enum ReferenceAlignmentStyle {
+  enum ReferenceAlignmentStyle : unsigned char {
 /// Align reference like ``PointerAlignment``.
 RAS_Pointer,
 /// Align reference to the left.
@@ -3166,7 +3166,7 @@
   /// \brief The possible positions for the requires clause. The
   /// ``IndentRequires`` option is only used if the ``requires`` is put on the
   /// start of a line.
-  enum RequiresClausePositionStyle {
+  enum RequiresClausePositionStyle : unsigned char {
 /// Always put the ``requires`` clause on its own l

[PATCH] D120470: [clang-tidy] Update tests to include opencl-c-base.h

2022-02-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 411106.
svenvh edited the summary of this revision.
svenvh added reviewers: Anastasia, ffrankies.
svenvh added a comment.

After a bit of digging I realized we don't need the explicit include at all 
anymore.


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

https://reviews.llvm.org/D120470

Files:
  
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
  clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
@@ -1,7 +1,7 @@
-// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c 
--include opencl-c.h -DOLDCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c 
--include opencl-c.h -DNEWCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL1.2 -c --include opencl-c.h -DOLDCLNEWAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL2.0 -c --include opencl-c.h -DNEWCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c 
-DOLDCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c 
-DNEWCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL1.2 -c -DOLDCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL2.0 -c -DNEWCLNEWAOC
 
 #ifdef OLDCLOLDAOC  // OpenCL 1.2 Altera Offline Compiler < 17.1
 void __kernel error_barrier_no_id(__global int * foo, int size) {
Index: 
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h
+// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c
 
 typedef struct ExampleStruct {
   int IDDepField;


Index: clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
@@ -1,7 +1,7 @@
-// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h -DOLDCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c --include opencl-c.h -DNEWCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h -DOLDCLNEWAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* "--" -cl-std=CL2.0 -c --include opencl-c.h -DNEWCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c -DOLDCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c -DNEWCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* "-

[PATCH] D120468: [clang][NFC] Move all avr CodeGen tests to avr specific directory

2022-02-24 Thread Ben Shi via Phabricator via cfe-commits
benshi001 updated this revision to Diff 411107.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120468

Files:
  clang/test/CodeGen/address-space-avr.c
  clang/test/CodeGen/alias-avr.c
  clang/test/CodeGen/avr-builtins.c
  clang/test/CodeGen/avr-flash.c
  clang/test/CodeGen/avr-inline-asm-constraints.c
  clang/test/CodeGen/avr-unsupported-inline-asm-constraints.c
  clang/test/CodeGen/avr/address-space-avr.c
  clang/test/CodeGen/avr/alias-avr.c
  clang/test/CodeGen/avr/avr-builtins.c
  clang/test/CodeGen/avr/avr-flash.c
  clang/test/CodeGen/avr/avr-inline-asm-constraints.c
  clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c




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


[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

See the suggestions, our comments are supposed to be full sentences terminated 
with a full-stop. Otherwise nothing actionable.




Comment at: clang/lib/Sema/SemaExpr.cpp:6420
+// Once a call is fully resolved, warn for unqualified calls to specific
+// C++ standard functions, like move and forward
+static void DiagnosedUnqualifiedCallsToStdFunctions(Sema &S, CallExpr *Call) {





Comment at: clang/lib/Sema/SemaExpr.cpp:6422
+static void DiagnosedUnqualifiedCallsToStdFunctions(Sema &S, CallExpr *Call) {
+  // We are only checking unary move and forward so exit early here
+  if (Call->getNumArgs() != 1)





Comment at: clang/lib/Sema/SemaExpr.cpp:6441
+  // Only warn for some functions deemed more frequent or problematic
+  static constexpr llvm::StringRef SpecialFunctions[] = {"move", "forward"};
+  auto it = llvm::find(SpecialFunctions, D->getName());

I find myself a touch grumpy that this is used to keep this expandable to other 
std functions, but still sticks itself to unary functions (particularly when 
the function name `DiagnosedUnqualifiedCallsToStdFunctions` isn't 
unary-specific).

I'm not sure how actionable this comment is, but I felt the need to share.  I 
guess I could suggest moving this to the top and making this hold a 'pair' of 
args + name (plus presumably a "don't check arg count" for some sort of 
variadic function check).

But, 'eh', think about it perhaps?  Maybe this comment can just exist to help 
out the next person who wants to add something to this function.



Comment at: clang/lib/Sema/SemaExpr.cpp:6437
+  NamedDecl *D = dyn_cast_or_null(Call->getCalleeDecl());
+  if (!D || !D->isInStdNamespace())
+return;

cor3ntin wrote:
> Quuxplusone wrote:
> > cor3ntin wrote:
> > > erichkeane wrote:
> > > > Quuxplusone wrote:
> > > > > erichkeane wrote:
> > > > > > Do we really want this?  I guess I would think doing:
> > > > > > 
> > > > > > 
> > > > > > ```
> > > > > > void MyFunc(auto whatever) {
> > > > > >   auto X = move(whatever);
> > > > > > ```
> > > > > > 
> > > > > > when I MEAN std::move, just for it to pick up a non-std::move the 
> > > > > > 1st time is likely the same problem?  Or should it get a separate 
> > > > > > warning?
> > > > > That's a good point (IMHO). Perhaps instead of making this a specific 
> > > > > case of "warn for unqualified call to things in `std` (namely `move` 
> > > > > and `forward`)," we should make it a specific case of "warn for any 
> > > > > unqualified use of //this identifier// (namely `move` and 
> > > > > `forward`)." That's closer in spirit to Nico Josuttis's comment that 
> > > > > `move` is almost like a keyword in modern C++, and therefore 
> > > > > shouldn't be thrown around willy-nilly. Either you mean `std::move` 
> > > > > (in which case qualify it), or you mean some other `my::move` (in 
> > > > > which case qualify it), but using the bare word `move` is 
> > > > > inappropriate in modern C++ no matter whether it //currently// finds 
> > > > > something out of `std` or not.
> > > > > I'm ambivalent between these two ways of looking at the issue. Maybe 
> > > > > someone can think up a reason to prefer one or the other?
> > > > > 
> > > > > libc++'s tests do include several recently-added instances of `move` 
> > > > > as a //variable name//, e.g. `auto copy(x); auto 
> > > > > move(std::move(x));`. This confuses grep but would not confuse Clang, 
> > > > > for better and worse. I don't expect that real code would ever do 
> > > > > this, either.
> > > > > 
> > > > > @erichkeane's specific example is a //template//, which means it's 
> > > > > going to be picked up by D72282 `clang-tidy bugprone-unintended-adl` 
> > > > > also. Using ADL inside templates triggers multiple red flags 
> > > > > simultaneously. Whereas this D119670 is the only thing that's going 
> > > > > to catch unqualified `move` in //non-template// code.
> > > > > That's a good point (IMHO). Perhaps instead of making this a specific 
> > > > > case of "warn for unqualified call to things in `std` (namely `move` 
> > > > > and `forward`)," we should make it a specific case of "warn for any 
> > > > > unqualified use of //this identifier// (namely `move` and 
> > > > > `forward`)." That's closer in spirit to Nico Josuttis's comment that 
> > > > > `move` is almost like a keyword in modern C++, and therefore 
> > > > > shouldn't be thrown around willy-nilly. Either you mean `std::move` 
> > > > > (in which case qualify it), or you mean some other `my::move` (in 
> > > > > which case qualify it), but using the bare word `move` is 
> > > > > inappropriate in modern C++ no matter whether it //currently// finds 
> > > > > something out of `std` or not.
> > > > 
> > > > Ah! I guess that was just my interpretation of how this p

[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 41.
cor3ntin added a comment.

Fix comments punctuation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/unqualified-std-call-fixits.cpp
  clang/test/SemaCXX/unqualified-std-call.cpp
  clang/test/SemaCXX/warn-self-move.cpp

Index: clang/test/SemaCXX/warn-self-move.cpp
===
--- clang/test/SemaCXX/warn-self-move.cpp
+++ clang/test/SemaCXX/warn-self-move.cpp
@@ -17,7 +17,8 @@
   (x) = std::move(x);  // expected-warning{{explicitly moving}}
 
   using std::move;
-  x = move(x);  // expected-warning{{explicitly moving}}
+  x = move(x); // expected-warning{{explicitly moving}} \
+   expected-warning {{unqualified call to std::move}}
 }
 
 int global;
@@ -26,7 +27,8 @@
   (global) = std::move(global);  // expected-warning{{explicitly moving}}
 
   using std::move;
-  global = move(global);  // expected-warning{{explicitly moving}}
+  global = move(global); // expected-warning{{explicitly moving}} \
+ expected-warning {{unqualified call to std::move}}
 }
 
 class field_test {
Index: clang/test/SemaCXX/unqualified-std-call.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/unqualified-std-call.cpp
@@ -0,0 +1,118 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall -std=c++11 %s
+
+namespace std {
+
+template 
+void dummy(T &&) {}
+template 
+void move(T &&) {}
+template 
+void move(T &&, U &&) {}
+
+inline namespace __1 {
+template 
+void forward(T &) {}
+} // namespace __1
+
+struct foo {};
+
+} // namespace std
+
+namespace global {
+
+using namespace std;
+
+void f() {
+  int i = 0;
+  std::move(i);
+  move(i);   // expected-warning{{unqualified call to std::move}}
+  (move)(i); // expected-warning{{unqualified call to std::move}}
+  std::dummy(1);
+  dummy(1);
+  std::move(1, 2);
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+  std::forward(i);
+}
+
+template 
+void g(T &&foo) {
+  std::move(foo);
+  move(foo); // expected-warning{{unqualified call to std::move}}
+
+  std::forward(foo);
+  forward(foo); // expected-warning{{unqualified call to std::forward}}
+  move(1, 2);
+  dummy(foo);
+}
+
+void call() {
+  g(0); //expected-note {{here}}
+}
+
+} // namespace global
+
+namespace named {
+
+using std::forward;
+using std::move;
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+template 
+void g(T &&foo) {
+  move(foo); // expected-warning{{unqualified call to std::move}}
+  forward(foo);   // expected-warning{{unqualified call to std::forward}}
+  (forward)(foo); // expected-warning{{unqualified call to std::forward}}
+  move(1, 2);
+}
+
+void call() {
+  g(0); //expected-note {{here}}
+}
+
+} // namespace named
+
+namespace overload {
+using namespace std;
+template 
+int move(T &&);
+void f() {
+  int i = 0;
+  move(i);
+}
+} // namespace overload
+
+namespace adl {
+void f() {
+  move(std::foo{}); // expected-warning{{unqualified call to std::move}}
+}
+
+} // namespace adl
+
+namespace std {
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+} // namespace std
+
+namespace test_alias {
+namespace alias = std;
+using namespace alias;
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+} // namespace test_alias
Index: clang/test/SemaCXX/unqualified-std-call-fixits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/unqualified-std-call-fixits.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -verify -std=c++20 -Wall %s
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -std=c++20 -fixit %t
+// RUN: %clang_cc1 -Wall -Werror -x c++ -std=c++20 %t
+// RUN: cat %t | FileCheck %s
+
+namespace std {
+
+void move(auto &&a) {}
+
+void forward(auto &a) {}
+
+} // namespace std
+
+using namespace std;
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning {{unqualified call to std::move}}
+  // CHECK: {{^}}  std::
+  forward(i); // expected-warning {{unqualified call to std::forward}}
+  // CHECK: {{^}}  std::
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6416,6 +6416,38 @@
   }
 }
 
+// Once a call is fully resolved, warn for unqualified calls to specific
+// C++ standard functions, like m

[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:6441
+  // Only warn for some functions deemed more frequent or problematic
+  static constexpr llvm::StringRef SpecialFunctions[] = {"move", "forward"};
+  auto it = llvm::find(SpecialFunctions, D->getName());

erichkeane wrote:
> I find myself a touch grumpy that this is used to keep this expandable to 
> other std functions, but still sticks itself to unary functions (particularly 
> when the function name `DiagnosedUnqualifiedCallsToStdFunctions` isn't 
> unary-specific).
> 
> I'm not sure how actionable this comment is, but I felt the need to share.  I 
> guess I could suggest moving this to the top and making this hold a 'pair' of 
> args + name (plus presumably a "don't check arg count" for some sort of 
> variadic function check).
> 
> But, 'eh', think about it perhaps?  Maybe this comment can just exist to help 
> out the next person who wants to add something to this function.
To be honest, this is something I've considered, and I'll go in that direction 
if you ask me to.
My thinking is that we do not have the need to do that right now, we can expand 
on it when we want to, and in the meantime, bailing out early on arity avoid 
wasting cpu cycles.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

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


[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I understand you still don't have commit-rights.  If you'd like, I can push 
this in a little bit.  Just let me know the name/email you'd like me to use.




Comment at: clang/lib/Sema/SemaExpr.cpp:6441
+  // Only warn for some functions deemed more frequent or problematic
+  static constexpr llvm::StringRef SpecialFunctions[] = {"move", "forward"};
+  auto it = llvm::find(SpecialFunctions, D->getName());

cor3ntin wrote:
> erichkeane wrote:
> > I find myself a touch grumpy that this is used to keep this expandable to 
> > other std functions, but still sticks itself to unary functions 
> > (particularly when the function name 
> > `DiagnosedUnqualifiedCallsToStdFunctions` isn't unary-specific).
> > 
> > I'm not sure how actionable this comment is, but I felt the need to share.  
> > I guess I could suggest moving this to the top and making this hold a 
> > 'pair' of args + name (plus presumably a "don't check arg count" for some 
> > sort of variadic function check).
> > 
> > But, 'eh', think about it perhaps?  Maybe this comment can just exist to 
> > help out the next person who wants to add something to this function.
> To be honest, this is something I've considered, and I'll go in that 
> direction if you ask me to.
> My thinking is that we do not have the need to do that right now, we can 
> expand on it when we want to, and in the meantime, bailing out early on arity 
> avoid wasting cpu cycles.
Right, its the inconsistency between the two (being extra future-proof here, 
and being much-less future-proof above) that bugs me.

Not enough to make you do anything here though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

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


[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D119670#3343076 , @erichkeane 
wrote:

> I understand you still don't have commit-rights.  If you'd like, I can push 
> this in a little bit.  Just let me know the name/email you'd like me to use.

I guess i should ask for those at some point, I feed bad asking you or Aaron 
every time...

"Corentin Jabot "


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

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


[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:6441
+  // Only warn for some functions deemed more frequent or problematic
+  static constexpr llvm::StringRef SpecialFunctions[] = {"move", "forward"};
+  auto it = llvm::find(SpecialFunctions, D->getName());

erichkeane wrote:
> cor3ntin wrote:
> > erichkeane wrote:
> > > I find myself a touch grumpy that this is used to keep this expandable to 
> > > other std functions, but still sticks itself to unary functions 
> > > (particularly when the function name 
> > > `DiagnosedUnqualifiedCallsToStdFunctions` isn't unary-specific).
> > > 
> > > I'm not sure how actionable this comment is, but I felt the need to 
> > > share.  I guess I could suggest moving this to the top and making this 
> > > hold a 'pair' of args + name (plus presumably a "don't check arg count" 
> > > for some sort of variadic function check).
> > > 
> > > But, 'eh', think about it perhaps?  Maybe this comment can just exist to 
> > > help out the next person who wants to add something to this function.
> > To be honest, this is something I've considered, and I'll go in that 
> > direction if you ask me to.
> > My thinking is that we do not have the need to do that right now, we can 
> > expand on it when we want to, and in the meantime, bailing out early on 
> > arity avoid wasting cpu cycles.
> Right, its the inconsistency between the two (being extra future-proof here, 
> and being much-less future-proof above) that bugs me.
> 
> Not enough to make you do anything here though.
Oh, i see.. I guess we could not have an array but that seemed cleaner. Or we 
could find a less generic name for the function, if you want.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

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


[PATCH] D120454: clang/www: Add links to tracking issues for C++20 features

2022-02-24 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/www/cxx_status.html:106
+automatically fetch status information from the issue in the tracker. For 
Example:
+No
+

HTML nit: these attributes should use `"` instead of `'` (ooh, and ditto in the 
actual HTML on lines 961 etc.)



Comment at: clang/www/cxx_status.html:1308-1313

 https://wg21.link/p2082r1";>P2082R1
+  
+No
+  
   

Have you eyeballed the new rendering of this table here? (I haven't.) The 
indentation on these HTML lines is wonky now; looks like lines 1308, 1309, and 
1313 are overindented by 2 spaces?



Comment at: clang/www/cxx_status.html:1652
+ * in the link text field. e.g.
+ * No
+ *

`s/'/"/g`



Comment at: clang/www/cxx_status.html:1660-1664
+Array.from(document.getElementsByClassName("autoupdate")).forEach(element => {
+  if (element.innerHTML != "No")
+return;
+  updateIssueCell(element);
+})

Does this need to be in a `document.onload` or `

[PATCH] D120484: More explicit message when failing to find a mandatory cfi ressource file

2022-02-24 Thread serge via Phabricator via cfe-commits
serge-sans-paille created this revision.
serge-sans-paille added a reviewer: thakis.
serge-sans-paille requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Compiler-rt doesn't provide support file for cfi on s390x ad ppc64le (at 
least). When trying to use the flag, we get a file error.
This is an attempt at making the error more explicit, maybe we should also 
suggest passing `-fno-sanitize-ignorelist`?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120484

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/SanitizerArgs.cpp


Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -168,7 +168,7 @@
 else if (BL.Mask == SanitizerKind::CFI && DiagnoseErrors)
   // If cfi_ignorelist.txt cannot be found in the resource dir, driver
   // should fail.
-  D.Diag(clang::diag::err_drv_no_such_file) << Path;
+  D.Diag(clang::diag::err_drv_missing_sanitizer_ignorelist) << Path;
   }
   validateSpecialCaseListFormat(
   D, IgnorelistFiles, clang::diag::err_drv_malformed_sanitizer_ignorelist,
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -205,6 +205,8 @@
   "invalid deployment target for -stdlib=libc++ (requires %0 or later)">;
 def err_drv_invalid_argument_to_option : Error<
   "invalid argument '%0' to -%1">;
+def err_drv_missing_sanitizer_ignorelist : Error<
+  "missing required sanitizer ignorelist: '%0'">;
 def err_drv_malformed_sanitizer_ignorelist : Error<
   "malformed sanitizer ignorelist: '%0'">;
 def err_drv_malformed_sanitizer_coverage_allowlist : Error<


Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -168,7 +168,7 @@
 else if (BL.Mask == SanitizerKind::CFI && DiagnoseErrors)
   // If cfi_ignorelist.txt cannot be found in the resource dir, driver
   // should fail.
-  D.Diag(clang::diag::err_drv_no_such_file) << Path;
+  D.Diag(clang::diag::err_drv_missing_sanitizer_ignorelist) << Path;
   }
   validateSpecialCaseListFormat(
   D, IgnorelistFiles, clang::diag::err_drv_malformed_sanitizer_ignorelist,
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -205,6 +205,8 @@
   "invalid deployment target for -stdlib=libc++ (requires %0 or later)">;
 def err_drv_invalid_argument_to_option : Error<
   "invalid argument '%0' to -%1">;
+def err_drv_missing_sanitizer_ignorelist : Error<
+  "missing required sanitizer ignorelist: '%0'">;
 def err_drv_malformed_sanitizer_ignorelist : Error<
   "malformed sanitizer ignorelist: '%0'">;
 def err_drv_malformed_sanitizer_coverage_allowlist : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114235: [clang] Extend ParsedAttr to allow custom handling for type attributes

2022-02-24 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

In D114235#3340412 , @erichkeane 
wrote:

> In D114235#3340369 , @mboehme wrote:
>
>> In D114235#3244054 , 
>> @aaron.ballman wrote:
>>
>>> so there could likely be places that need updating to look "through" the 
>>> attributed type. But unlike with arbitrary plugins, the number of places is 
>>> hopefully more reasonable.
>>
>> IIUC, this already happens to some extent for other type attributes -- 
>> correct? For example, the nullability attributes (`_Nonnull` and the like). 
>> However, these can only be applied to pointer types (e.g. `int * _Nonnull 
>> ptr`), while an `annotate_type` attribute could also be applied to other 
>> types (e.g. `int [[clang::annotate_type("foo")]] i`). Is this an example of 
>> the places you're thinking of that would need to be touched?
>
> _Nonnull has exactly the problems we are talking about; it is put on the 
> attributed-type, which end up getting lost in canonicalization just about 
> immediately.

For my purposes, it would be fine, and maybe even desirable, for the proposed 
`annotate_type` to have the same limitations as `_Nonnull`.

Are you saying that a) this would not be acceptable for a more general-purpose 
attribute such as a putative `annotate_type`, or even that b) the behavior of 
`_Nonnull` itself is seen as undesirable and should be changed if possible?

> This is going to be an incredibly heavy lift, I just don't see how you can 
> make it 'last' through the type system.  For example:
>
>   template
>   struct S {
> using my_type = T;
>   };
>   
>   using my_attr_type = int [[annotated_type("asdf")]];
>   
>   S::my_type;
>   S::my_type; <-- will have lost the attribute already, since 
> you want them to behave as the same type.
>   std::is_same::value; // Do you want this to be true?

Yes.

>   std::is_same, S::value; // What about this one?

Yes.

Both of these are what the `_Nullable` attribute does today (godbolt 
), and I would be happy for the proposed 
`annotate_type` attribute to have the same semantics.

> This problem ends up being generally intractable as far as I can imagine.  
> The C++ language doesn't have the idea of strong-typedefs, a type is just the 
> type.  You can't have 1 instance of the type have an attribute, and others 
> not without them being DIFFERENT types.  So you'd have to have some level of 
> AnnotatedType in the type system that does its best to ACT like its 
> underlying type (at great development cost to make sure it doesn't get lost, 
> basically everywhere), but actually isn't.  For example, it would have to end 
> up failing the 2nd `is_same` above, which, IMO, would be language breaking 
> unless the 1st `is_same` ALSO stopped being true.

As noted above, this isn't actually what I'm trying to achieve.

Some colleagues and I are currently preparing an RFC for the specific use case 
we'd like to use the proposed `annotate_type` attribute for. That use case 
might give more context to the discussion. If you think it would help to put 
this discussion on hold until we've written up and posted the RFC, I'd be happy 
to do that. If you have any additional comments right now, I'd be happy to hear 
those too of course!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114235

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


[clang] 28cdcf8 - [OpenCL] Handle TypeExtensions in OpenCLBuiltinFileEmitter

2022-02-24 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-24T15:17:24Z
New Revision: 28cdcf8e3c8e6c51d42051b54f67c6920b5d8cf3

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

LOG: [OpenCL] Handle TypeExtensions in OpenCLBuiltinFileEmitter

Until now, any types that had TypeExtensions attached to them were not
guarded with those extensions.  Extend the OpenCLBuiltinFileEmitter
such that all required extensions are emitted for the types of a
builtin function.

The `clang-tblgen -gen-clang-opencl-builtin-tests` emitter will now
produce e.g.:

  #if defined(cl_khr_fp16) && defined(cl_khr_fp64)
  half8 test11802_convert_half8_rtp(double8 arg1) {
return convert_half8_rtp(arg1);
  }
  #endif // TypeExtension

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

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 34ca6cb36738c..a2d0cfb0b6ca9 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -17,6 +17,7 @@
 #include "TableGenBackends.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -293,6 +294,15 @@ class OpenCLBuiltinFileEmitterBase {
   // was emitted.
   std::string emitVersionGuard(const Record *Builtin);
 
+  // Emit an #if guard for all type extensions required for the given type
+  // strings.  Return the corresponding closing #endif, or an empty string
+  // if no extension #if guard was emitted.
+  StringRef
+  emitTypeExtensionGuards(const SmallVectorImpl &Signature);
+
+  // Map type strings to type extensions (e.g. "half2" -> "cl_khr_fp16").
+  StringMap TypeExtMap;
+
   // Contains OpenCL builtin functions and related information, stored as
   // Record instances. They are coming from the associated TableGen file.
   RecordKeeper &Records;
@@ -1057,7 +1067,16 @@ void 
OpenCLBuiltinFileEmitterBase::expandTypesInSignature(
 // Insert the Cartesian product of the types and vector sizes.
 for (const auto &Vector : VectorList) {
   for (const auto &Type : TypeList) {
-ExpandedArg.push_back(getTypeString(Type, Flags, Vector));
+std::string FullType = getTypeString(Type, Flags, Vector);
+ExpandedArg.push_back(FullType);
+
+// If the type requires an extension, add a TypeExtMap entry mapping
+// the full type name to the extension.
+StringRef Ext =
+Arg->getValueAsDef("Extension")->getValueAsString("ExtName");
+if (!Ext.empty() && TypeExtMap.find(FullType) == TypeExtMap.end()) {
+  TypeExtMap.insert({FullType, Ext});
+}
   }
 }
 NumSignatures = std::max(NumSignatures, ExpandedArg.size());
@@ -1141,6 +1160,39 @@ OpenCLBuiltinFileEmitterBase::emitVersionGuard(const 
Record *Builtin) {
   return OptionalEndif;
 }
 
+StringRef OpenCLBuiltinFileEmitterBase::emitTypeExtensionGuards(
+const SmallVectorImpl &Signature) {
+  SmallSet ExtSet;
+
+  // Iterate over all types to gather the set of required TypeExtensions.
+  for (const auto &Ty : Signature) {
+StringRef TypeExt = TypeExtMap.lookup(Ty);
+if (!TypeExt.empty()) {
+  // The TypeExtensions are space-separated in the .td file.
+  SmallVector ExtVec;
+  TypeExt.split(ExtVec, " ");
+  for (const auto Ext : ExtVec) {
+ExtSet.insert(Ext);
+  }
+}
+  }
+
+  // Emit the #if only when at least one extension is required.
+  if (ExtSet.empty())
+return "";
+
+  OS << "#if ";
+  bool isFirst = true;
+  for (const auto Ext : ExtSet) {
+if (!isFirst)
+  OS << " && ";
+OS << "defined(" << Ext << ")";
+isFirst = false;
+  }
+  OS << "\n";
+  return "#endif // TypeExtension\n";
+}
+
 void OpenCLBuiltinTestEmitter::emit() {
   emitSourceFileHeader("OpenCL Builtin exhaustive testing", OS);
 
@@ -1163,6 +1215,8 @@ void OpenCLBuiltinTestEmitter::emit() {
 std::string OptionalVersionEndif = emitVersionGuard(B);
 
 for (const auto &Signature : FTypes) {
+  StringRef OptionalTypeExtEndif = emitTypeExtensionGuards(Signature);
+
   // Emit function declaration.
   OS << Signature[0] << " test" << TestID++ << "_" << Name << "(";
   if (Signature.size() > 1) {
@@ -1189,6 +1243,7 @@ void OpenCLBuiltinTestEmitter::emit() {
 
   // End of function body.
   OS << "}\n";
+  OS << OptionalTypeExtEndif;
 }
 
 OS << OptionalVersionEndif;



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

[PATCH] D120262: [OpenCL] Handle TypeExtensions in OpenCLBuiltinFileEmitter

2022-02-24 Thread Sven van Haastregt 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 rG28cdcf8e3c8e: [OpenCL] Handle TypeExtensions in 
OpenCLBuiltinFileEmitter (authored by svenvh).

Changed prior to commit:
  https://reviews.llvm.org/D120262?vs=410822&id=411121#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120262

Files:
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -17,6 +17,7 @@
 #include "TableGenBackends.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -293,6 +294,15 @@
   // was emitted.
   std::string emitVersionGuard(const Record *Builtin);
 
+  // Emit an #if guard for all type extensions required for the given type
+  // strings.  Return the corresponding closing #endif, or an empty string
+  // if no extension #if guard was emitted.
+  StringRef
+  emitTypeExtensionGuards(const SmallVectorImpl &Signature);
+
+  // Map type strings to type extensions (e.g. "half2" -> "cl_khr_fp16").
+  StringMap TypeExtMap;
+
   // Contains OpenCL builtin functions and related information, stored as
   // Record instances. They are coming from the associated TableGen file.
   RecordKeeper &Records;
@@ -1057,7 +1067,16 @@
 // Insert the Cartesian product of the types and vector sizes.
 for (const auto &Vector : VectorList) {
   for (const auto &Type : TypeList) {
-ExpandedArg.push_back(getTypeString(Type, Flags, Vector));
+std::string FullType = getTypeString(Type, Flags, Vector);
+ExpandedArg.push_back(FullType);
+
+// If the type requires an extension, add a TypeExtMap entry mapping
+// the full type name to the extension.
+StringRef Ext =
+Arg->getValueAsDef("Extension")->getValueAsString("ExtName");
+if (!Ext.empty() && TypeExtMap.find(FullType) == TypeExtMap.end()) {
+  TypeExtMap.insert({FullType, Ext});
+}
   }
 }
 NumSignatures = std::max(NumSignatures, ExpandedArg.size());
@@ -1141,6 +1160,39 @@
   return OptionalEndif;
 }
 
+StringRef OpenCLBuiltinFileEmitterBase::emitTypeExtensionGuards(
+const SmallVectorImpl &Signature) {
+  SmallSet ExtSet;
+
+  // Iterate over all types to gather the set of required TypeExtensions.
+  for (const auto &Ty : Signature) {
+StringRef TypeExt = TypeExtMap.lookup(Ty);
+if (!TypeExt.empty()) {
+  // The TypeExtensions are space-separated in the .td file.
+  SmallVector ExtVec;
+  TypeExt.split(ExtVec, " ");
+  for (const auto Ext : ExtVec) {
+ExtSet.insert(Ext);
+  }
+}
+  }
+
+  // Emit the #if only when at least one extension is required.
+  if (ExtSet.empty())
+return "";
+
+  OS << "#if ";
+  bool isFirst = true;
+  for (const auto Ext : ExtSet) {
+if (!isFirst)
+  OS << " && ";
+OS << "defined(" << Ext << ")";
+isFirst = false;
+  }
+  OS << "\n";
+  return "#endif // TypeExtension\n";
+}
+
 void OpenCLBuiltinTestEmitter::emit() {
   emitSourceFileHeader("OpenCL Builtin exhaustive testing", OS);
 
@@ -1163,6 +1215,8 @@
 std::string OptionalVersionEndif = emitVersionGuard(B);
 
 for (const auto &Signature : FTypes) {
+  StringRef OptionalTypeExtEndif = emitTypeExtensionGuards(Signature);
+
   // Emit function declaration.
   OS << Signature[0] << " test" << TestID++ << "_" << Name << "(";
   if (Signature.size() > 1) {
@@ -1189,6 +1243,7 @@
 
   // End of function body.
   OS << "}\n";
+  OS << OptionalTypeExtEndif;
 }
 
 OS << OptionalVersionEndif;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114235: [clang] Extend ParsedAttr to allow custom handling for type attributes

2022-02-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

> For my purposes, it would be fine, and maybe even desirable, for the proposed 
> annotate_type to have the same limitations as _Nonnull.
>
> Are you saying that a) this would not be acceptable for a more 
> general-purpose attribute such as a putative annotate_type, or even that b) 
> the behavior of _Nonnull itself is seen as undesirable and should be changed 
> if possible?

Yes and Maybe?  The non-type-modifying type attributes we have are here for 
compatibility with GCC/MSVC, but are, IMO, a complete mistake otherwise.  The 
strange/obnoxious behavior of them disappearing off of something as soon as 
they are looked at funny makes them so non-intuitive that I see them as harmful.

Something as general as an 'annotate_type' would, IMO, need to be held to an 
even higher standard than our normal type attributes due to its nature.  And I 
don't see how a type attribute with the behaviors you require as being both 
intuitive and working in the C++ type system.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114235

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


[clang] 70b1f6d - [clang] Warn on unqualified calls to std::move and std::forward

2022-02-24 Thread Erich Keane via cfe-commits

Author: Corentin Jabot
Date: 2022-02-24T07:23:39-08:00
New Revision: 70b1f6de539867353940d3dcb8b25786d5082d63

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

LOG: [clang] Warn on unqualified calls to std::move and std::forward

This adds a diagnostic when an unqualified call is resolved
to std::move or std::forward.

This follows some C++ committee discussions where some
people where concerns that this might be an usual anti pattern
particularly britle worth warning about - both because move
is a common name and because these functions accept any values.

This warns inconditionnally of whether the current context is in
std:: or not, as implementations probably want to always qualify
these calls too, to avoid triggering adl accidentally.

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

Added: 
clang/test/SemaCXX/unqualified-std-call-fixits.cpp
clang/test/SemaCXX/unqualified-std-call.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/warn-self-move.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 11fcd5ff5a323..15487260eb732 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4804,6 +4804,9 @@ def ext_adl_only_template_id : ExtWarn<
   "use of function template name with no prior declaration in function call "
   "with explicit template arguments is a C++20 extension">, InGroup;
 
+def warn_unqualified_call_to_std_cast_function : Warning<
+  "unqualified call to %0">, InGroup>;
+
 // C++ Template Argument Lists
 def err_template_missing_args : Error<
   "use of "

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 88fc89bec629a..454e21ecfa2d9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6450,6 +6450,38 @@ 
tryImplicitlyCaptureThisIfImplicitMemberFunctionAccessWithDependentArgs(
   }
 }
 
+// Once a call is fully resolved, warn for unqualified calls to specific
+// C++ standard functions, like move and forward.
+static void DiagnosedUnqualifiedCallsToStdFunctions(Sema &S, CallExpr *Call) {
+  // We are only checking unary move and forward so exit early here.
+  if (Call->getNumArgs() != 1)
+return;
+
+  Expr *E = Call->getCallee()->IgnoreParenImpCasts();
+  if (!E || isa(E))
+return;
+  DeclRefExpr *DRE = dyn_cast_or_null(E);
+  if (!DRE || !DRE->getLocation().isValid())
+return;
+
+  if (DRE->getQualifier())
+return;
+
+  NamedDecl *D = dyn_cast_or_null(Call->getCalleeDecl());
+  if (!D || !D->isInStdNamespace())
+return;
+
+  // Only warn for some functions deemed more frequent or problematic.
+  static constexpr llvm::StringRef SpecialFunctions[] = {"move", "forward"};
+  auto it = llvm::find(SpecialFunctions, D->getName());
+  if (it == std::end(SpecialFunctions))
+return;
+
+  S.Diag(DRE->getLocation(), diag::warn_unqualified_call_to_std_cast_function)
+  << D->getQualifiedNameAsString()
+  << FixItHint::CreateInsertion(DRE->getLocation(), "std::");
+}
+
 ExprResult Sema::ActOnCallExpr(Scope *Scope, Expr *Fn, SourceLocation 
LParenLoc,
MultiExprArg ArgExprs, SourceLocation RParenLoc,
Expr *ExecConfig) {
@@ -6474,7 +6506,11 @@ ExprResult Sema::ActOnCallExpr(Scope *Scope, Expr *Fn, 
SourceLocation LParenLoc,
   if (LangOpts.OpenMP)
 Call = ActOnOpenMPCall(Call, Scope, LParenLoc, ArgExprs, RParenLoc,
ExecConfig);
-
+  if (LangOpts.CPlusPlus) {
+CallExpr *CE = dyn_cast(Call.get());
+if (CE)
+  DiagnosedUnqualifiedCallsToStdFunctions(*this, CE);
+  }
   return Call;
 }
 

diff  --git a/clang/test/SemaCXX/unqualified-std-call-fixits.cpp 
b/clang/test/SemaCXX/unqualified-std-call-fixits.cpp
new file mode 100644
index 0..0b2d70c0360a3
--- /dev/null
+++ b/clang/test/SemaCXX/unqualified-std-call-fixits.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -verify -std=c++20 -Wall %s
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -std=c++20 -fixit %t
+// RUN: %clang_cc1 -Wall -Werror -x c++ -std=c++20 %t
+// RUN: cat %t | FileCheck %s
+
+namespace std {
+
+void move(auto &&a) {}
+
+void forward(auto &a) {}
+
+} // namespace std
+
+using namespace std;
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning {{unqualified call to std::move}}
+  // CHECK: {{^}}  std::
+  forward(i); // expected-warning {{unqualified call to std::forward}}
+  // CHECK: {{^}}  std::
+}

diff  --git a/clang/test/SemaCXX/unqualified-std-call.cpp 
b/clang/test/SemaCXX/unqualified-std-call.cpp
new file mode 100644
index 0..fa66ae9f8e321
--- /dev/null

[PATCH] D119670: [clang] Warn on unqualified calls to std::move and std::forward

2022-02-24 Thread Erich Keane 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 rG70b1f6de5398: [clang] Warn on unqualified calls to std::move 
and std::forward (authored by cor3ntin, committed by erichkeane).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119670

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/unqualified-std-call-fixits.cpp
  clang/test/SemaCXX/unqualified-std-call.cpp
  clang/test/SemaCXX/warn-self-move.cpp

Index: clang/test/SemaCXX/warn-self-move.cpp
===
--- clang/test/SemaCXX/warn-self-move.cpp
+++ clang/test/SemaCXX/warn-self-move.cpp
@@ -17,7 +17,8 @@
   (x) = std::move(x);  // expected-warning{{explicitly moving}}
 
   using std::move;
-  x = move(x);  // expected-warning{{explicitly moving}}
+  x = move(x); // expected-warning{{explicitly moving}} \
+   expected-warning {{unqualified call to std::move}}
 }
 
 int global;
@@ -26,7 +27,8 @@
   (global) = std::move(global);  // expected-warning{{explicitly moving}}
 
   using std::move;
-  global = move(global);  // expected-warning{{explicitly moving}}
+  global = move(global); // expected-warning{{explicitly moving}} \
+ expected-warning {{unqualified call to std::move}}
 }
 
 class field_test {
Index: clang/test/SemaCXX/unqualified-std-call.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/unqualified-std-call.cpp
@@ -0,0 +1,118 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall -std=c++11 %s
+
+namespace std {
+
+template 
+void dummy(T &&) {}
+template 
+void move(T &&) {}
+template 
+void move(T &&, U &&) {}
+
+inline namespace __1 {
+template 
+void forward(T &) {}
+} // namespace __1
+
+struct foo {};
+
+} // namespace std
+
+namespace global {
+
+using namespace std;
+
+void f() {
+  int i = 0;
+  std::move(i);
+  move(i);   // expected-warning{{unqualified call to std::move}}
+  (move)(i); // expected-warning{{unqualified call to std::move}}
+  std::dummy(1);
+  dummy(1);
+  std::move(1, 2);
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+  std::forward(i);
+}
+
+template 
+void g(T &&foo) {
+  std::move(foo);
+  move(foo); // expected-warning{{unqualified call to std::move}}
+
+  std::forward(foo);
+  forward(foo); // expected-warning{{unqualified call to std::forward}}
+  move(1, 2);
+  dummy(foo);
+}
+
+void call() {
+  g(0); //expected-note {{here}}
+}
+
+} // namespace global
+
+namespace named {
+
+using std::forward;
+using std::move;
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+template 
+void g(T &&foo) {
+  move(foo); // expected-warning{{unqualified call to std::move}}
+  forward(foo);   // expected-warning{{unqualified call to std::forward}}
+  (forward)(foo); // expected-warning{{unqualified call to std::forward}}
+  move(1, 2);
+}
+
+void call() {
+  g(0); //expected-note {{here}}
+}
+
+} // namespace named
+
+namespace overload {
+using namespace std;
+template 
+int move(T &&);
+void f() {
+  int i = 0;
+  move(i);
+}
+} // namespace overload
+
+namespace adl {
+void f() {
+  move(std::foo{}); // expected-warning{{unqualified call to std::move}}
+}
+
+} // namespace adl
+
+namespace std {
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+} // namespace std
+
+namespace test_alias {
+namespace alias = std;
+using namespace alias;
+void f() {
+  int i = 0;
+  move(i); // expected-warning{{unqualified call to std::move}}
+  move(1, 2);
+  forward(i); // expected-warning{{unqualified call to std::forward}}
+}
+
+} // namespace test_alias
Index: clang/test/SemaCXX/unqualified-std-call-fixits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/unqualified-std-call-fixits.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -verify -std=c++20 -Wall %s
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -std=c++20 -fixit %t
+// RUN: %clang_cc1 -Wall -Werror -x c++ -std=c++20 %t
+// RUN: cat %t | FileCheck %s
+
+namespace std {
+
+void move(auto &&a) {}
+
+void forward(auto &a) {}
+
+} // namespace std
+
+using namespace std;
+
+void f() {
+  int i = 0;
+  move(i); // expected-warning {{unqualified call to std::move}}
+  // CHECK: {{^}}  std::
+  forward(i); // expected-warning {{unqualified call to std::forward}}
+  // CHECK: {{^}}  std::
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.c

[PATCH] D120310: [clang][analyzer] Add modeling of 'errno' (work-in-progress).

2022-02-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 411131.
balazske added a comment.

Improved the tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/Errno.h
  clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/Inputs/errno_func.h
  clang/test/Analysis/Inputs/errno_var.h
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/errno.c
  clang/test/Analysis/global-region-invalidation.c
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c

Index: clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
===
--- clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
+++ clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
@@ -21,6 +21,7 @@
 // CHECK-NEXT: alpha.unix.Stream
 // CHECK-NEXT: apiModeling.StdCLibraryFunctions
 // CHECK-NEXT: alpha.unix.StdCLibraryFunctionArgs
+// CHECK-NEXT: apiModeling.Errno
 // CHECK-NEXT: apiModeling.TrustNonnull
 // CHECK-NEXT: apiModeling.TrustReturnsNonnull
 // CHECK-NEXT: apiModeling.llvm.CastValue
Index: clang/test/Analysis/global-region-invalidation.c
===
--- clang/test/Analysis/global-region-invalidation.c
+++ clang/test/Analysis/global-region-invalidation.c
@@ -1,8 +1,15 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\" %s
+
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
 
 void clang_analyzer_eval(int);
 
 // Note, we do need to include headers here, since the analyzer checks if the function declaration is located in a system header.
+#include ERRNO_HEADER
 #include "Inputs/system-header-simulator.h"
 
 // Test that system header does not invalidate the internal global.
Index: clang/test/Analysis/errno.c
===
--- /dev/null
+++ clang/test/Analysis/errno.c
@@ -0,0 +1,56 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\"
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
+
+#include ERRNO_HEADER
+
+void clang_analyzer_eval(int);
+void ErrnoTesterChecker_setErrno(int);
+int ErrnoTesterChecker_setErrnoIfError();
+int ErrnoTesterChecker_setErrnoIfErrorRange();
+
+void something();
+
+void test() {
+  // Test if errno is initialized.
+  clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
+
+  ErrnoTesterChecker_setErrno(1);
+
+  // Test if errno was recognized and changed.
+  clang_analyzer_eval(errno == 1); // expected-warning{{TRUE}}
+
+  something();
+
+  // Test if errno was invalidated.
+  clang_analyzer_eval(errno); // expected-warning{{UNKNOWN}}
+}
+
+void testRange(int X) {
+  if (X > 0) {
+ErrnoTesterChecker_setErrno(X);
+clang_analyzer_eval(errno > 0); // expected-warning{{TRUE}}
+  }
+}
+
+void testIfError() {
+  if (ErrnoTesterChecker_setErrnoIfError())
+clang_analyzer_eval(errno == 11); // expected-warning{{TRUE}}
+}
+
+void testIfErrorRange() {
+  if (ErrnoTesterChecker_setErrnoIfErrorRange()) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+clang_analyzer_eval(errno == 1); // expected-warning{{FALSE}} expected-warning{{TRUE}}
+  }
+}
Index: clang/test/Analysis/analyzer-enabled-checkers.c
===
--- clang/test/Analysis/analyzer-enabled-checkers.c
+++ clang/test/Analysis/analyzer-enabled-checkers.c
@@ -7,6 +7,7 @@
 // CHECK:  OVERVIEW: Clang Static Analyzer Enabled Checkers List
 // CHECK-EMPTY:
 // CHECK-NEXT: core.CallAndMessageModeling

[PATCH] D120489: [analyzer][NFCi] Does some changes to detect Uninitialized read by the char array manipulation functions

2022-02-24 Thread Shivam Rajput via Phabricator via cfe-commits
phyBrackets created this revision.
Herald added subscribers: ASDenysPetrov, martong, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
phyBrackets requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Few weeks back I was experimenting with reading the uninitialized values from 
src , which is actually a bug but the CSA seems to give up at that point . I 
was curious about that and I pinged @steakhal on the discord and according to 
him this seems to be a genuine issue and needs to be fix. So I goes with fixing 
this bug and thanks to @steakhal who help me creating this patch. This feature 
seems to break some tests but this was the genuine problem and the broken tests 
also needs to fix in certain manner. I add a test but yeah we need more 
tests,I'll try to add more tests.Thanks


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120489

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/bstring.c

Index: clang/test/Analysis/bstring.c
===
--- clang/test/Analysis/bstring.c
+++ clang/test/Analysis/bstring.c
@@ -70,6 +70,11 @@
 
 #endif /* VARIANT */
 
+void top(char *dst) {
+  char buf[10];
+  memcpy(dst, buf, 10); // expected-warning{{Bytes string function accesses uninitialized/garbage values}}
+  (void)buf;
+}
 
 void memcpy0 () {
   char src[] = {1, 2, 3, 4};
@@ -297,9 +302,12 @@
   int dst[5] = {0};
   int *p;
 
-  p = mempcpy(dst, src, 4 * sizeof(int));
+  p = mempcpy(dst, src, 4 * sizeof(int)); // expected-warning{{Bytes string function accesses uninitialized/garbage values}}
+  // FIXME: This behaviour is actually Unexpected and needs to be fix, 
+  // mempcpy seems to consider the src buffered byte as uninitialized
+  // and returning undef which is actually not the case It should return something like Unknown .
 
-  clang_analyzer_eval(p == &dst[4]); // expected-warning{{TRUE}}
+  clang_analyzer_eval(p == &dst[4]); // no-warning (above is fatal)
 }
 
 struct st {
@@ -314,9 +322,10 @@
   struct st *p2;
 
   p1 = (&s2) + 1;
-  p2 = mempcpy(&s2, &s1, sizeof(struct st));
-
-  clang_analyzer_eval(p1 == p2); // expected-warning{{TRUE}}
+  p2 = mempcpy(&s2, &s1, sizeof(struct st)); // expected-warning{{Bytes string function accesses uninitialized/garbage values}}
+  // FIXME: It seems same as mempcpy14() case.
+  
+  clang_analyzer_eval(p1 == p2); // no-warning (above is fatal)
 }
 
 void mempcpy16() {
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -80,7 +80,7 @@
  check::RegionChanges
  > {
   mutable std::unique_ptr BT_Null, BT_Bounds, BT_Overlap,
-  BT_NotCString, BT_AdditionOverflow;
+  BT_NotCString, BT_AdditionOverflow, BT_UninitRead;
 
   mutable const char *CurrentFunctionDescription;
 
@@ -92,11 +92,13 @@
 DefaultBool CheckCStringOutOfBounds;
 DefaultBool CheckCStringBufferOverlap;
 DefaultBool CheckCStringNotNullTerm;
+DefaultBool CheckCStringUninitializedRead;
 
 CheckerNameRef CheckNameCStringNullArg;
 CheckerNameRef CheckNameCStringOutOfBounds;
 CheckerNameRef CheckNameCStringBufferOverlap;
 CheckerNameRef CheckNameCStringNotNullTerm;
+CheckerNameRef CheckNameCStringUninitializedRead;
   };
 
   CStringChecksFilter Filter;
@@ -257,6 +259,8 @@
   void emitNotCStringBug(CheckerContext &C, ProgramStateRef State,
  const Stmt *S, StringRef WarningMsg) const;
   void emitAdditionOverflowBug(CheckerContext &C, ProgramStateRef State) const;
+  void emitUninitializedRead(CheckerContext &C, ProgramStateRef State,
+ const Expr *E) const;
 
   ProgramStateRef checkAdditionOverflow(CheckerContext &C,
 ProgramStateRef state,
@@ -368,6 +372,15 @@
 return nullptr;
   }
 
+  // Ensure that we wouldn't read uninitialized value.
+  if (Access == AccessKind::read) {
+if (StInBound->getSVal(ER).isUndef()) {
+  llvm::errs() << "Reading from " << ER << "\n";
+  emitUninitializedRead(C, StInBound, Buffer.Expression);
+  return nullptr;
+}
+  }
+
   // Array bound check succeeded.  From this point forward the array bound
   // should always succeed.
   return StInBound;
@@ -421,6 +434,7 @@
 SVal BufEnd =
 svalBuilder.evalBinOpLN(State, BO_Add, *BufLoc, LastOffset, PtrTy);
 
+State = CheckLocation(C, State, Buffer, BufStart, Access);
 State = CheckLocation(C, State, Buffer, BufEnd, Access);
 
 // If the buffer isn't large enough, abort.
@@ -580,6 +594,27 @@
   }
 }
 
+void CStringChecker::em

[PATCH] D120310: [clang][analyzer] Add modeling of 'errno' (work-in-progress).

2022-02-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 4 inline comments as done.
balazske added inline comments.



Comment at: clang/test/Analysis/global-region-invalidation.c:6
 // Note, we do need to include headers here, since the analyzer checks if the 
function declaration is located in a system header.
+#include "Inputs/errno_var.h"
 #include "Inputs/system-header-simulator.h"

steakhal wrote:
> If you were `eval::Calling` the `errno_location` functions, and used the 
> corresponding header, would the tests pass?
It is now executed wit both versions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

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


[clang] 7aef8b3 - [OpenMP] Make section variable external to prevent collisions

2022-02-24 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-02-24T10:57:09-05:00
New Revision: 7aef8b3754a28e0856a8300980786a45bf7b4cd4

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

LOG: [OpenMP] Make section variable external to prevent collisions

Summary:
We use a section to embed offloading code into the host for later
linking. This is normally unique to the translation unit as it is thrown
away during linking. However, if the user performs a relocatable link
the sections will be merged and we won't be able to access the files
stored inside. This patch changes the section variables to have external
linkage and a name defined by the section name, so if two sections are
combined during linking we get an error.

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/test/Frontend/embed-object.ll
llvm/lib/Transforms/Utils/ModuleUtils.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ebfbe991881c6..490f5b3de1ff3 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1759,24 +1759,22 @@ void clang::EmbedObject(llvm::Module *M, const 
CodeGenOptions &CGOpts,
 return;
 
   for (StringRef OffloadObject : CGOpts.OffloadObjects) {
-if (OffloadObject.count(',') != 1) {
+if (OffloadObject.count(',') != 1)
   Diags.Report(Diags.getCustomDiagID(
   DiagnosticsEngine::Error, "Invalid string pair for embedding '%0'"))
   << OffloadObject;
-  return;
-}
 auto FilenameAndSection = OffloadObject.split(',');
 llvm::ErrorOr> ObjectOrErr =
-llvm::MemoryBuffer::getFileOrSTDIN(std::get<0>(FilenameAndSection));
+llvm::MemoryBuffer::getFileOrSTDIN(FilenameAndSection.first);
 if (std::error_code EC = ObjectOrErr.getError()) {
   auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
   "could not open '%0' for embedding");
-  Diags.Report(DiagID) << std::get<0>(FilenameAndSection);
+  Diags.Report(DiagID) << FilenameAndSection.first;
   return;
 }
 
 SmallString<128> SectionName(
-{".llvm.offloading.", std::get<1>(FilenameAndSection)});
+{".llvm.offloading.", FilenameAndSection.second});
 llvm::embedBufferInModule(*M, **ObjectOrErr, SectionName);
   }
 }

diff  --git a/clang/test/Frontend/embed-object.ll 
b/clang/test/Frontend/embed-object.ll
index 49b477d4a7be0..3270a7806210b 100644
--- a/clang/test/Frontend/embed-object.ll
+++ b/clang/test/Frontend/embed-object.ll
@@ -3,8 +3,8 @@
 ; RUN:-fembed-offload-object=%S/Inputs/empty.h,section2 -x ir %s -o - \
 ; RUN:| FileCheck %s -check-prefix=CHECK
 
-; CHECK: @[[OBJECT1:.+]] = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading.section1"
-; CHECK: @[[OBJECT2:.+]] = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading.section2"
+; CHECK: @[[OBJECT1:.+]] = hidden constant [0 x i8] zeroinitializer, section 
".llvm.offloading.section1"
+; CHECK: @[[OBJECT2:.+]] = hidden constant [0 x i8] zeroinitializer, section 
".llvm.offloading.section2"
 ; CHECK: @llvm.compiler.used = appending global [3 x i8*] [i8* @x, i8* 
getelementptr inbounds ([0 x i8], [0 x i8]* @[[OBJECT1]], i32 0, i32 0), i8* 
getelementptr inbounds ([0 x i8], [0 x i8]* @[[OBJECT2]], i32 0, i32 0)], 
section "llvm.metadata"
 
 @x = private constant i8 1

diff  --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp 
b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
index 61cf42db4a755..032ea80397977 100644
--- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -271,9 +271,10 @@ void llvm::embedBufferInModule(Module &M, MemoryBufferRef 
Buf,
   Constant *ModuleConstant = ConstantDataArray::get(
   M.getContext(), makeArrayRef(Buf.getBufferStart(), Buf.getBufferSize()));
   GlobalVariable *GV = new GlobalVariable(
-  M, ModuleConstant->getType(), true, GlobalValue::PrivateLinkage,
-  ModuleConstant, "llvm.embedded.object");
+  M, ModuleConstant->getType(), true, GlobalValue::ExternalLinkage,
+  ModuleConstant, SectionName.drop_front());
   GV->setSection(SectionName);
+  GV->setVisibility(GlobalValue::HiddenVisibility);
 
   appendToCompilerUsed(M, GV);
 }



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


[clang] 0039249 - Remove useless RUN lines in the middle of the file and pipe to FileCheck; NFC

2022-02-24 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-02-24T11:01:33-05:00
New Revision: 003924963f95c746ab72cc8ea0201c855f5264fb

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

LOG: Remove useless RUN lines in the middle of the file and pipe to FileCheck; 
NFC

Added: 


Modified: 
clang/test/CodeGen/attributes.c

Removed: 




diff  --git a/clang/test/CodeGen/attributes.c b/clang/test/CodeGen/attributes.c
index 7ee6fb903fa7a..ec42ff2f2c50f 100644
--- a/clang/test/CodeGen/attributes.c
+++ b/clang/test/CodeGen/attributes.c
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -fcf-protection=branch -triple i386-linux-gnu -o 
%t %s
-// RUN: FileCheck --input-file=%t %s
+// RUN: %clang_cc1 -emit-llvm -fcf-protection=branch -triple i386-linux-gnu %s 
-o - | FileCheck %s
 
 // CHECK: @t5 = weak{{.*}} global i32 2
 int t5 __attribute__((weak)) = 2;
@@ -79,9 +78,6 @@ void __attribute__((section("xSECT"))) t11(void) {}
 // CHECK: define{{.*}} i32 @t19() [[NUW]] {
 extern int t19(void) __attribute__((weak_import));
 int t19(void) {
-// RUN: %clang_cc1 -emit-llvm -fcf-protection=branch -triple i386-linux-gnu -o 
%t %s
-// RUN: %clang_cc1 -emit-llvm -fcf-protection=branch -triple i386-linux-gnu -o 
%t %s
-// RUN: %clang_cc1 -emit-llvm -fcf-protection=branch -triple i386-linux-gnu -o 
%t %s
   return 10;
 }
 



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


[PATCH] D120489: [analyzer][NFCi] Done some changes to detect Uninitialized read by the char array manipulation functions

2022-02-24 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I'm looking forward to this check.




Comment at: clang/test/Analysis/bstring.c:300-311
 void mempcpy14() {
   int src[] = {1, 2, 3, 4};
   int dst[5] = {0};
   int *p;
 
-  p = mempcpy(dst, src, 4 * sizeof(int));
+  p = mempcpy(dst, src, 4 * sizeof(int)); // expected-warning{{Bytes string 
function accesses uninitialized/garbage values}}
+  // FIXME: This behaviour is actually Unexpected and needs to be fix, 

Basically, the store has 4 direct bindings for the `src` cluster.
At bit offset 0, 32, 64, 96, the values `1`, `2`, `3`, `4` (ints) respectively.
However, in the `memcopy` modeling, we calculate the byte offset of the very 
last touched **byte**, which is `byte 15`.
Consequently, we will do a lookup in the store for acquiring a binding starting 
at bit offset `15*8, aka. 120`.
However, there is no binding for that offset. What we have instead, is a 
binding starting at offset 96, associating an integer, which is 4 bytes long, 
thus this entry actually refers to the bits [96-128], so it overlaps with the 
byte at [120-128].
From this, we should be able to prove that the given bits must have been 
initialized to //some value//.

What I cannot remember off the top of my head, what was the type of the `ER`. I 
hope it was `char`, but I cannot recall.
If that was `char`, then we have a bug in the `store`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120489

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


[PATCH] D113743: [RFC][clang][DebugInfo] Allow function-local statics and types to be scoped within a lexical block

2022-02-24 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 411137.
krisb added a comment.

Rebase on top of 'main'.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113743

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/debug-info-lexcial-block.cpp

Index: clang/test/CodeGenCXX/debug-info-lexcial-block.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-lexcial-block.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+void foo() {
+  static int bar = 1;
+  {
+struct X {};
+typedef char Y;
+static int bar = 0;
+// The following basic block is intended, in order to check the case where
+// types "X", "Y" are defined in a different scope than where they are used.
+// They should have the scope they are defined at as their parent scope.
+{
+  X a;
+  Y b;
+}
+  }
+}
+
+// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[FSCOPE:![0-9]+]]
+// CHECK: [[FSCOPE]] = distinct !DISubprogram(name: "foo"
+// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[LBSCOPE:![0-9]+]]
+// CHECK: [[LBSCOPE]] = distinct !DILexicalBlock(scope: [[FSCOPE]]
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "a", scope: [[LBSCOPE2:![0-9]+]], {{.*}} type: [[STRUCT:![0-9]+]]
+// CHECK: [[LBSCOPE2]] = distinct !DILexicalBlock(scope: [[LBSCOPE]]
+// CHECK: [[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[LBSCOPE]]
+// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "b", scope: [[LBSCOPE2]], {{.*}} type: [[TYPEDEF:![0-9]+]]
+// CHECK: [[TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Y", scope: [[LBSCOPE]]
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -103,17 +103,21 @@
 llvm_unreachable("Declaration should not be in declstmts!");
   case Decl::Record:// struct/union/class X;
   case Decl::CXXRecord: // struct/union/class X; [C++]
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   if (cast(D).getDefinition())
 DI->EmitAndRetainType(getContext().getRecordType(cast(&D)));
+}
 return;
   case Decl::Enum:  // enum X;
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   if (cast(D).getDefinition())
 DI->EmitAndRetainType(getContext().getEnumType(cast(&D)));
+}
 return;
-  case Decl::Function: // void X();
   case Decl::EnumConstant: // enum ? { X = ? }
+  case Decl::Function: // void X();
   case Decl::StaticAssert: // static_assert(X, ""); [C++0x]
   case Decl::Label:// __label__ x;
   case Decl::Import:
@@ -132,11 +136,11 @@
 
   case Decl::NamespaceAlias:
 if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitNamespaceAlias(cast(D));
+  DI->EmitNamespaceAlias(cast(D));
 return;
   case Decl::Using:  // using X; [C++]
 if (CGDebugInfo *DI = getDebugInfo())
-DI->EmitUsingDecl(cast(D));
+  DI->EmitUsingDecl(cast(D));
 return;
   case Decl::UsingEnum: // using enum X; [C++]
 if (CGDebugInfo *DI = getDebugInfo())
@@ -172,8 +176,10 @@
   case Decl::Typedef:  // typedef int X;
   case Decl::TypeAlias: {  // using X = int; [C++0x]
 QualType Ty = cast(D).getUnderlyingType();
-if (CGDebugInfo *DI = getDebugInfo())
+if (CGDebugInfo *DI = getDebugInfo()) {
+  DI->recordDeclarationLexicalScope(D);
   DI->EmitAndRetainType(Ty);
+}
 if (Ty->isVariablyModifiedType())
   EmitVariablyModifiedType(Ty);
 return;
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -138,6 +138,11 @@
 
   /// Keep track of our current nested lexical block.
   std::vector> LexicalBlockStack;
+
+  /// Map of AST declaration to its lexical block scope.
+  llvm::DenseMap>
+  LexicalBlockMap;
+
   llvm::DenseMap RegionMap;
   /// Keep track of LexicalBlockStack counter at the beginning of a
   /// function. This is used to pop unbalanced regions at the end of a
@@ -542,6 +547,12 @@
   /// Emit an Objective-C interface type standalone debug info.
   llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
 
+  /// Map AST declaration to its lexical block scope if available.
+  void recordDeclarationLexicalScope(const Decl &D);
+
+  /// Get lexical scope of AST declaration.
+  llvm::DIScope *getDeclarationLexicalScope(const Decl *D);
+
   /// Emit standalone debug info for a type.
   llvm::DIT

[PATCH] D120470: [clang-tidy] Update tests to include opencl-c-base.h

2022-02-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

Since this is a simple test update I'll commit this now (before code review), 
to get affected CI back to green. Please let me know if there are any 
post-commit concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120470

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


[clang-tools-extra] ba18c36 - [clang-tidy] Remove opencl-c.h inclusion from tests

2022-02-24 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-24T16:28:52Z
New Revision: ba18c360b2f3c25fe9091c7a7931eded374b3cf6

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

LOG: [clang-tidy] Remove opencl-c.h inclusion from tests

After D120254 some clang-tidy tests started failing on release builds.

clang-tidy has been using the `-fdeclare-opencl-builtins` functionality
since this became the default in clang, so there is no need to include
`opencl-c.h`.

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

Added: 


Modified: 

clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp

clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
index a6dbab7b72fce..68f4658a7dc9b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h
+// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c
 
 typedef struct ExampleStruct {
   int IDDepField;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
index 1b6045144cea5..a6b31875e7c72 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
@@ -1,7 +1,7 @@
-// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c 
--include opencl-c.h -DOLDCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c 
--include opencl-c.h -DNEWCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL1.2 -c --include opencl-c.h -DOLDCLNEWAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL2.0 -c --include opencl-c.h -DNEWCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c 
-DOLDCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c 
-DNEWCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL1.2 -c -DOLDCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL2.0 -c -DNEWCLNEWAOC
 
 #ifdef OLDCLOLDAOC  // OpenCL 1.2 Altera Offline Compiler < 17.1
 void __kernel error_barrier_no_id(__global int * foo, int size) {



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


[PATCH] D120470: [clang-tidy] Update tests to include opencl-c-base.h

2022-02-24 Thread Sven van Haastregt 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 rGba18c360b2f3: [clang-tidy] Remove opencl-c.h inclusion from 
tests (authored by svenvh).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120470

Files:
  
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
  clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
@@ -1,7 +1,7 @@
-// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c 
--include opencl-c.h -DOLDCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c 
--include opencl-c.h -DNEWCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL1.2 -c --include opencl-c.h -DOLDCLNEWAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL2.0 -c --include opencl-c.h -DNEWCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c 
-DOLDCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c 
-DNEWCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL1.2 -c -DOLDCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL2.0 -c -DNEWCLNEWAOC
 
 #ifdef OLDCLOLDAOC  // OpenCL 1.2 Altera Offline Compiler < 17.1
 void __kernel error_barrier_no_id(__global int * foo, int size) {
Index: 
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h
+// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c
 
 typedef struct ExampleStruct {
   int IDDepField;


Index: clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
@@ -1,7 +1,7 @@
-// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h -DOLDCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c --include opencl-c.h -DNEWCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h -DOLDCLNEWAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* "--" -cl-std=CL2.0 -c --include opencl-c.h -DNEWCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c -DOLDCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c -DNEWCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: altera-single-work-item

[clang] baa0f22 - [clang][dataflow] Update StructValue child when assigning a value

2022-02-24 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2022-02-24T16:41:48Z
New Revision: baa0f221d6df2fcce10c54751cc42284e2656c31

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

LOG: [clang][dataflow] Update StructValue child when assigning a value

When assigning a value to a storage location of a struct member we
need to also update the value in the corresponding `StructValue`.

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: ymandel, xazax.hun

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

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index bab20418a016a..2fb32053a11b5 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -265,6 +265,12 @@ class Environment {
 
   llvm::DenseMap LocToVal;
 
+  // Maps locations of struct members to symbolic values of the structs that 
own
+  // them and the decls of the struct members.
+  llvm::DenseMap>
+  MemberLocToStruct;
+
   // FIXME: Add flow condition constraints.
 };
 

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 0fb341fd0bb05..fc6f9aa2167b0 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -138,6 +138,9 @@ bool Environment::equivalentTo(const Environment &Other,
   if (ExprToLoc != Other.ExprToLoc)
 return false;
 
+  if (MemberLocToStruct != Other.MemberLocToStruct)
+return false;
+
   if (LocToVal.size() != Other.LocToVal.size())
 return false;
 
@@ -176,6 +179,12 @@ LatticeJoinEffect Environment::join(const Environment 
&Other,
   if (ExprToLocSizeBefore != ExprToLoc.size())
 Effect = LatticeJoinEffect::Changed;
 
+  const unsigned MemberLocToStructSizeBefore = MemberLocToStruct.size();
+  MemberLocToStruct =
+  intersectDenseMaps(MemberLocToStruct, Other.MemberLocToStruct);
+  if (MemberLocToStructSizeBefore != MemberLocToStruct.size())
+Effect = LatticeJoinEffect::Changed;
+
   // Move `LocToVal` so that `Environment::ValueModel::merge` can safely assign
   // values to storage locations while this code iterates over the current
   // assignments.
@@ -285,9 +294,25 @@ void Environment::setValue(const StorageLocation &Loc, 
Value &Val) {
 
 for (const FieldDecl *Field : Type->getAsRecordDecl()->fields()) {
   assert(Field != nullptr);
-  setValue(AggregateLoc.getChild(*Field), StructVal->getChild(*Field));
+  StorageLocation &FieldLoc = AggregateLoc.getChild(*Field);
+  MemberLocToStruct[&FieldLoc] = std::make_pair(StructVal, Field);
+  setValue(FieldLoc, StructVal->getChild(*Field));
 }
   }
+
+  auto IT = MemberLocToStruct.find(&Loc);
+  if (IT != MemberLocToStruct.end()) {
+// `Loc` is the location of a struct member so we need to also update the
+// value of the member in the corresponding `StructValue`.
+
+assert(IT->second.first != nullptr);
+StructValue &StructVal = *IT->second.first;
+
+assert(IT->second.second != nullptr);
+const ValueDecl &Member = *IT->second.second;
+
+StructVal.setChild(Member, Val);
+  }
 }
 
 Value *Environment::getValue(const StorageLocation &Loc) const {

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index fda4af435c4a7..4da24e0e1f75c 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2320,4 +2320,48 @@ TEST_F(TransferTest, StaticMemberRefVarDecl) {
   });
 }
 
+TEST_F(TransferTest, AssignMemberBeforeCopy) {
+  std::string Code = R"(
+struct A {
+  int Foo;
+};
+
+void target() {
+  A A1;
+  A A2;
+  int Bar;
+  A1.Foo = Bar;
+  A2 = A1;
+  // [[p]]
+}
+  )";
+  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 =

[PATCH] D120414: [clang][dataflow] Update StructValue child when assigning a value

2022-02-24 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 rGbaa0f221d6df: [clang][dataflow] Update StructValue child 
when assigning a value (authored by sgatev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120414

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.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
@@ -2320,4 +2320,48 @@
   });
 }
 
+TEST_F(TransferTest, AssignMemberBeforeCopy) {
+  std::string Code = R"(
+struct A {
+  int Foo;
+};
+
+void target() {
+  A A1;
+  A A2;
+  int Bar;
+  A1.Foo = Bar;
+  A2 = A1;
+  // [[p]]
+}
+  )";
+  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 *A1Decl = findValueDecl(ASTCtx, "A1");
+ASSERT_THAT(A1Decl, NotNull());
+
+const ValueDecl *A2Decl = findValueDecl(ASTCtx, "A2");
+ASSERT_THAT(A2Decl, NotNull());
+
+const auto *BarVal =
+cast(Env.getValue(*BarDecl, SkipPast::None));
+
+const auto *A2Val =
+cast(Env.getValue(*A2Decl, SkipPast::None));
+EXPECT_EQ(&A2Val->getChild(*FooDecl), BarVal);
+  });
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -138,6 +138,9 @@
   if (ExprToLoc != Other.ExprToLoc)
 return false;
 
+  if (MemberLocToStruct != Other.MemberLocToStruct)
+return false;
+
   if (LocToVal.size() != Other.LocToVal.size())
 return false;
 
@@ -176,6 +179,12 @@
   if (ExprToLocSizeBefore != ExprToLoc.size())
 Effect = LatticeJoinEffect::Changed;
 
+  const unsigned MemberLocToStructSizeBefore = MemberLocToStruct.size();
+  MemberLocToStruct =
+  intersectDenseMaps(MemberLocToStruct, Other.MemberLocToStruct);
+  if (MemberLocToStructSizeBefore != MemberLocToStruct.size())
+Effect = LatticeJoinEffect::Changed;
+
   // Move `LocToVal` so that `Environment::ValueModel::merge` can safely assign
   // values to storage locations while this code iterates over the current
   // assignments.
@@ -285,9 +294,25 @@
 
 for (const FieldDecl *Field : Type->getAsRecordDecl()->fields()) {
   assert(Field != nullptr);
-  setValue(AggregateLoc.getChild(*Field), StructVal->getChild(*Field));
+  StorageLocation &FieldLoc = AggregateLoc.getChild(*Field);
+  MemberLocToStruct[&FieldLoc] = std::make_pair(StructVal, Field);
+  setValue(FieldLoc, StructVal->getChild(*Field));
 }
   }
+
+  auto IT = MemberLocToStruct.find(&Loc);
+  if (IT != MemberLocToStruct.end()) {
+// `Loc` is the location of a struct member so we need to also update the
+// value of the member in the corresponding `StructValue`.
+
+assert(IT->second.first != nullptr);
+StructValue &StructVal = *IT->second.first;
+
+assert(IT->second.second != nullptr);
+const ValueDecl &Member = *IT->second.second;
+
+StructVal.setChild(Member, Val);
+  }
 }
 
 Value *Environment::getValue(const StorageLocation &Loc) const {
Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -265,6 +265,12 @@
 
   llvm::DenseMap LocToVal;
 
+  // Maps locations of struct members to symbolic values of the structs that own
+  // them and the decls of the struct members.
+  llvm::DenseMap>
+  MemberLocToStruct;
+
   // FIXME: Add flow condition constraints.
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120426: [Sema] Mark the referenced destructor during transformation of a `CXXBindTemporaryExpr`

2022-02-24 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 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/D120426/new/

https://reviews.llvm.org/D120426

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


[PATCH] D120456: [clang] Bump __cpp_concepts and __cpp_constexpr in accordance with P2493R0

2022-02-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Thanks for the patch. However,  wg21.link/P0848 need to be fully implemented 
before we can update `__cpp_concepts`. Could you only modify `__cpp_constexpr` 
? Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120456

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


[PATCH] D120310: [clang][analyzer] Add modeling of 'errno'.

2022-02-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 411149.
balazske marked 3 inline comments as done.
balazske edited the summary of this revision.
balazske added a comment.

Changed name of the checker to `ErrnoModeling`, other small cleanup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120310

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/Errno.h
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/Inputs/errno_func.h
  clang/test/Analysis/Inputs/errno_var.h
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/errno.c
  clang/test/Analysis/global-region-invalidation.c
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c

Index: clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
===
--- clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
+++ clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
@@ -21,6 +21,7 @@
 // CHECK-NEXT: alpha.unix.Stream
 // CHECK-NEXT: apiModeling.StdCLibraryFunctions
 // CHECK-NEXT: alpha.unix.StdCLibraryFunctionArgs
+// CHECK-NEXT: apiModeling.Errno
 // CHECK-NEXT: apiModeling.TrustNonnull
 // CHECK-NEXT: apiModeling.TrustReturnsNonnull
 // CHECK-NEXT: apiModeling.llvm.CastValue
Index: clang/test/Analysis/global-region-invalidation.c
===
--- clang/test/Analysis/global-region-invalidation.c
+++ clang/test/Analysis/global-region-invalidation.c
@@ -1,8 +1,15 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\" %s
+
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
+// RUN:   -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
 
 void clang_analyzer_eval(int);
 
 // Note, we do need to include headers here, since the analyzer checks if the function declaration is located in a system header.
+#include ERRNO_HEADER
 #include "Inputs/system-header-simulator.h"
 
 // Test that system header does not invalidate the internal global.
Index: clang/test/Analysis/errno.c
===
--- /dev/null
+++ clang/test/Analysis/errno.c
@@ -0,0 +1,56 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_var.h\"
+
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.Errno \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-checker=debug.ErrnoTest \
+// RUN:   -DERRNO_HEADER=\"Inputs/errno_func.h\"
+
+#include ERRNO_HEADER
+
+void clang_analyzer_eval(int);
+void ErrnoTesterChecker_setErrno(int);
+int ErrnoTesterChecker_setErrnoIfError();
+int ErrnoTesterChecker_setErrnoIfErrorRange();
+
+void something();
+
+void test() {
+  // Test if errno is initialized.
+  clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
+
+  ErrnoTesterChecker_setErrno(1);
+
+  // Test if errno was recognized and changed.
+  clang_analyzer_eval(errno == 1); // expected-warning{{TRUE}}
+
+  something();
+
+  // Test if errno was invalidated.
+  clang_analyzer_eval(errno); // expected-warning{{UNKNOWN}}
+}
+
+void testRange(int X) {
+  if (X > 0) {
+ErrnoTesterChecker_setErrno(X);
+clang_analyzer_eval(errno > 0); // expected-warning{{TRUE}}
+  }
+}
+
+void testIfError() {
+  if (ErrnoTesterChecker_setErrnoIfError())
+clang_analyzer_eval(errno == 11); // expected-warning{{TRUE}}
+}
+
+void testIfErrorRange() {
+  if (ErrnoTesterChecker_setErrnoIfErrorRange()) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+clang_analyzer_eval(errno == 1); // expected-warning{{FALSE}} expected-warning{{TRUE}}
+  }
+}
Index: clang/test/Analysis/analyzer-enabled-checkers.c
===
--- clang/test/Analysis/analyzer-enabled-checkers.c
+++ clang/test/Analysis/analyzer-enabled-checkers.c
@@ -7,6

[PATCH] D120132: [HIP] Fix HIP include path

2022-02-24 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 411150.
yaxunl edited the summary of this revision.
yaxunl added a reviewer: linjamaki.
yaxunl added a comment.
Herald added subscribers: mstorsjo, emaste.

add HIP include path after adding other system include paths


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

https://reviews.llvm.org/D120132

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/FreeBSD.h
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/lib/Driver/ToolChains/HIPAMD.h
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MSVC.h
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/lib/Driver/ToolChains/MinGW.h
  clang/lib/Driver/ToolChains/ROCm.h
  clang/test/Driver/hip-include-path.hip
  clang/test/Driver/hipspv-toolchain.hip

Index: clang/test/Driver/hipspv-toolchain.hip
===
--- clang/test/Driver/hipspv-toolchain.hip
+++ clang/test/Driver/hipspv-toolchain.hip
@@ -11,7 +11,7 @@
 // CHECK-SAME: "-fcuda-is-device"
 // CHECK-SAME: "-fcuda-allow-variadic-functions"
 // CHECK-SAME: "-mlink-builtin-bitcode" {{".*/hipspv/lib/hip-device-lib/hipspv-spirv64.bc"}}
-// CHECK-SAME: "-isystem" {{".*/hipspv/include"}}
+// CHECK-SAME: "-internal-isystem" {{".*/hipspv/include"}}
 // CHECK-SAME: "-fhip-new-launch-api"
 // CHECK-SAME: "-o" [[DEV_BC:".*bc"]]
 // CHECK-SAME: "-x" "hip"
Index: clang/test/Driver/hip-include-path.hip
===
--- clang/test/Driver/hip-include-path.hip
+++ clang/test/Driver/hip-include-path.hip
@@ -19,24 +19,24 @@
 // COMMON-LABEL: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
 // CLANG-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
 // NOCLANG-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
-// HIP-SAME: "-internal-isystem" "{{[^"]*}}Inputs/rocm/include"
-// NOHIP-NOT: "{{.*}}Inputs/rocm/include"
 // HIP-SAME: "-include" "__clang_hip_runtime_wrapper.h"
 // NOHIP-NOT: "-include" "__clang_hip_runtime_wrapper.h"
 // skip check of standard C++ include path
 // CLANG-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include"
 // NOCLANG-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include"
+// HIP-SAME: "-internal-isystem" "{{[^"]*}}Inputs/rocm/include"
+// NOHIP-NOT: "{{.*}}Inputs/rocm/include"
 
 // COMMON-LABEL: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
 // CLANG-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
 // NOCLANG-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
-// HIP-SAME: "-internal-isystem" "{{[^"]*}}Inputs/rocm/include"
-// NOHIP-NOT: "{{.*}}Inputs/rocm/include"
 // HIP-SAME: "-include" "__clang_hip_runtime_wrapper.h"
 // NOHIP-NOT: "-include" "__clang_hip_runtime_wrapper.h"
 // skip check of standard C++ include path
 // CLANG-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include"
 // NOCLANG-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include"
+// HIP-SAME: "-internal-isystem" "{{[^"]*}}Inputs/rocm/include"
+// NOHIP-NOT: "{{.*}}Inputs/rocm/include"
 
 // RUN: %clang -c -### -target x86_64-unknown-linux-gnu --cuda-gpu-arch=gfx900 \
 // RUN:   -std=c++11 --rocm-path=%S/Inputs/rocm -nogpulib %s 2>&1 \
@@ -45,7 +45,7 @@
 // ROCM35-LABEL: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
 // ROCM35-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
 // ROCM35-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}"
-// ROCM35-SAME: "-internal-isystem" "{{[^"]*}}Inputs/rocm/include"
 // ROCM35-NOT: "-include" "__clang_hip_runtime_wrapper.h"
 // skip check of standard C++ include path
 // ROCM35-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include"
+// ROCM35-SAME: "-internal-isystem" "{{[^"]*}}Inputs/rocm/include"
Index: clang/lib/Driver/ToolChains/ROCm.h
===
--- clang/lib/Driver/ToolChains/ROCm.h
+++ clang/lib/Driver/ToolChains/ROCm.h
@@ -255,8 +255,9 @@
 return LibDeviceMap.lookup(Gpu);
   }
 
-  void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
- llvm::opt::ArgStringList &CC1Args) const;
+  std::string
+  AddHIPWrapperArgsAndGetIncludePath(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const;
 
   void detectDeviceLibrary();
   void detectHIPRuntime();
Index: clang/lib/Driver/ToolChains/MinGW.h
===
--- clang/lib/Driver/ToolC

[PATCH] D119816: [SanitizerBounds] Add support for NoSanitizeBounds function

2022-02-24 Thread Marco Elver via Phabricator via cfe-commits
melver requested changes to this revision.
melver added a comment.
This revision now requires changes to proceed.

Thanks - this looks good so far.




Comment at: clang/test/CodeGen/sanitize-coverage.c:56
   // BOUNDS-NOT: call void @__ubsan_handle_out_of_bounds
+  // BOUNDS-NOT: call void @llvm.trap()
   // TSAN-NOT: call void @__tsan_func_entry

This test by itself is not sufficient, it's technically only for 
fsanitize-coverage.

2 places with more tests would be good:

1. extend clang/test/CodeGen/bounds-checking.c
2. add a pure IR test in llvm/test/Instrumentation/BoundsChecking

With that, it'll also be very clear what was broken before, and what is being 
fixed now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119816

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


[PATCH] D120495: [clang][dataflow] Add transfer functions for structured bindings

2022-02-24 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/D120495

Files:
  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
@@ -2364,4 +2364,192 @@
   });
 }
 
+TEST_F(TransferTest, StructuredBindingAssignFromStructIntMembersToRefs) {
+  std::string Code = R"(
+struct A {
+  int Foo;
+  int Bar;
+};
+
+void target() {
+  int Qux;
+  A Baz;
+  Baz.Foo = Qux;
+  auto &FooRef = Baz.Foo;
+  auto &BarRef = Baz.Bar;
+  auto &[BoundFooRef, BoundBarRef] = Baz;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooRefDecl = findValueDecl(ASTCtx, "FooRef");
+ASSERT_THAT(FooRefDecl, NotNull());
+
+const ValueDecl *BarRefDecl = findValueDecl(ASTCtx, "BarRef");
+ASSERT_THAT(BarRefDecl, NotNull());
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+
+const ValueDecl *BoundFooRefDecl = findValueDecl(ASTCtx, "BoundFooRef");
+ASSERT_THAT(BoundFooRefDecl, NotNull());
+
+const ValueDecl *BoundBarRefDecl = findValueDecl(ASTCtx, "BoundBarRef");
+ASSERT_THAT(BoundBarRefDecl, NotNull());
+
+const StorageLocation *FooRefLoc =
+Env.getStorageLocation(*FooRefDecl, SkipPast::Reference);
+ASSERT_THAT(FooRefLoc, NotNull());
+
+const StorageLocation *BarRefLoc =
+Env.getStorageLocation(*BarRefDecl, SkipPast::Reference);
+ASSERT_THAT(BarRefLoc, NotNull());
+
+const Value *QuxVal = Env.getValue(*QuxDecl, SkipPast::None);
+ASSERT_THAT(QuxVal, NotNull());
+
+const StorageLocation *BoundFooRefLoc =
+Env.getStorageLocation(*BoundFooRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundFooRefLoc, FooRefLoc);
+
+const StorageLocation *BoundBarRefLoc =
+Env.getStorageLocation(*BoundBarRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundBarRefLoc, BarRefLoc);
+
+EXPECT_EQ(Env.getValue(*BoundFooRefDecl, SkipPast::Reference), QuxVal);
+  });
+}
+
+TEST_F(TransferTest, StructuredBindingAssignFromStructRefMembersToRefs) {
+  std::string Code = R"(
+struct A {
+  int &Foo;
+  int &Bar;
+};
+
+void target(A Baz) {
+  int Qux;
+  Baz.Foo = Qux;
+  auto &FooRef = Baz.Foo;
+  auto &BarRef = Baz.Bar;
+  auto &[BoundFooRef, BoundBarRef] = Baz;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooRefDecl = findValueDecl(ASTCtx, "FooRef");
+ASSERT_THAT(FooRefDecl, NotNull());
+
+const ValueDecl *BarRefDecl = findValueDecl(ASTCtx, "BarRef");
+ASSERT_THAT(BarRefDecl, NotNull());
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+
+const ValueDecl *BoundFooRefDecl = findValueDecl(ASTCtx, "BoundFooRef");
+ASSERT_THAT(BoundFooRefDecl, NotNull());
+
+const ValueDecl *BoundBarRefDecl = findValueDecl(ASTCtx, "BoundBarRef");
+ASSERT_THAT(BoundBarRefDecl, NotNull());
+
+const StorageLocation *FooRefLoc =
+Env.getStorageLocation(*FooRefDecl, SkipPast::Reference);
+ASSERT_THAT(FooRefLoc, NotNull());
+
+const StorageLocation *BarRefLoc =
+Env.getStorageLocation(*BarRefDecl, SkipPast::Reference);
+ASSERT_THAT(BarRefLoc, NotNull());
+
+const Value *QuxVal = Env.getValue(*QuxDecl, SkipPast::None);
+ASSERT_THAT(QuxVal, NotNull());
+
+const StorageLocation *BoundFooRefLoc =
+Env.getStorageLocation(*BoundFooRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundFooRefLoc, FooRefLoc);
+
+const StorageLocation *BoundBarRefLoc =
+Env.getStorageLocation(*BoundBarRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundBarRefLoc, BarRefLoc)

[PATCH] D113743: [RFC][clang][DebugInfo] Allow function-local statics and types to be scoped within a lexical block

2022-02-24 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a subscriber: shafik.
dblaikie added a comment.

In D113743#3177437 , @krisb wrote:

> In D113743#3175301 , @dblaikie 
> wrote:
>
>> Not super surprising that lldb might not be able to deal with DWARF in this 
>> shape - is LLDB support important to you/something you plan to work on for 
>> this DWARF? Otherwise we might need to opt-out of this functionality when 
>> tuning for LLDB, for instance. Unless LLDB-invested folks are interested in 
>> doing the integration work (& even then, maybe disabling it for LLDB tuning 
>> until that's fixed). @aprantl @JDevlieghere
>
> Thank you for the suggestion!
> I implemented a small workaround that makes lldb behaves like if the types 
> have subprogram scope (see https://reviews.llvm.org/D115277), not sure I'll 
> be able to do something better any time soon.
> So, if D115277  isn't acceptable, and 
> nobody volunteers to implement this properly, the only way to proceed is to 
> turn this functionality off for lldb.

Thanks for having a go at a fix/workaround here.

I think we'll still need to hear from Apple folks (@aprantl @JDevlieghere 
@shafik ) - I'm not sure what their backwards compatibility (new clang-produced 
binaries being debugged with an old lldb) requirements are. If they need some 
backcompat there, then I guess they/we/you would still need to disable this 
DWARF fidelity improvement when tuning for lldb. Hopefully that can be avoided, 
but I don't know.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113743

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


[PATCH] D120498: [AST] Test RecursiveASTVisitor's current traversal of templates.

2022-02-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: hokein, nridge.
Herald added subscribers: usaxena95, kadircet, mgorny.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

There are several logical inconsistencies and traps in the current traversal.

This doesn't fix any of them, but

- describes the general expectations of how templates should be traversed
- (mostly) exhaustively records current behavior as a baseline for changes
- lists the apparent bugs in current behavior

See https://github.com/clangd/clangd/issues/1034 for an example of reasonable
code that falls into one of the traps, and some discussion.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120498

Files:
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp
  clang/unittests/Tooling/TestVisitor.h

Index: clang/unittests/Tooling/TestVisitor.h
===
--- clang/unittests/Tooling/TestVisitor.h
+++ clang/unittests/Tooling/TestVisitor.h
@@ -95,7 +95,7 @@
 
 void HandleTranslationUnit(clang::ASTContext &Context) override {
   Visitor->Context = &Context;
-  Visitor->TraverseDecl(Context.getTranslationUnitDecl());
+  Visitor->getDerived().TraverseAST(Context);
 }
 
   private:
Index: clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp
@@ -0,0 +1,423 @@
+//===- Templates.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tests exactly which template-related declarations are traversed by
+// RecursiveASTVisitor in various configurations.
+//
+// shouldVisitTemplateInstantiations() controls traversal of AST nodes that
+// were created by instantiation, rather than by written code. This means:
+//   - Primary template bodies are always traversed: they are written code
+//   - User-defined specializations (partial or complete) are traversed too.
+//   - Implicit instantiations are only traversed if shouldVisit() is true.
+//   - Explicit instantiations are a tricky case:
+// - the "declaration part" (template args, function params etc) was written
+//   and should always be traversed.
+// - the "definition part" (function body, class members, var initializer)
+//   was instantiated and should only be traversed if shouldVisit() is true.
+// - the node itself (FunctionDecl, {Class,Var}TemplateSpecializationDecl)
+//   must be visited. Overriders of VisitFunctionDecl() etc may need to
+//   check getTemplateSpecializationKind() to know whether to use the body.
+//
+// Because RecursiveASTVisitor should also be able to traverse arbitrary
+// subtrees, the nodes representing explicit instantiations should behave in
+// a similar way when traversed directly. This is also tested.
+// (The historical behavior for functions with shouldVisit() off was:
+// explicit function instantiations were not visited at all, but if explicitly
+// passed to TraverseDecl() then the whole body was traversed).
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include "clang/Basic/Specifiers.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+
+// This RecursiveASTVisitor logs the traversal of template-related declarations,
+// as well as a few leaf nodes (so we can tell whether bodies are traversed).
+class TemplateVisitor : public TestVisitor {
+  using Base = TestVisitor;
+
+public:
+  bool Instantiations = false;
+  std::function ChooseTraversalRoot =
+  [](ASTContext &Ctx) { return Ctx.getTranslationUnitDecl(); };
+
+  bool shouldVisitTemplateInstantiations() { return Instantiations; }
+  bool shouldVisitImplicitCode() { return false; }
+
+  bool TraverseAST(ASTContext &Ctx) {
+return TraverseDecl(ChooseTraversalRoot(Ctx));
+  }
+
+#define LOG_VISIT(NodeTy)  \
+  bool Visit##NodeTy(NodeTy *N) {  \
+addLog("Visit" #NodeTy);   \
+addNodeDetail(N);  \
+return Base::Visit##NodeTy(N); \
+  }
+#define LOG_TRAVERSE(NodeTy)   \
+  LOG_VISIT(NodeTy)\
+  bool Traverse##No

[PATCH] D120499: [NVPTX] Fix nvvm.match.sync*.i64 intrinsics return type (i64 -> i32)

2022-02-24 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb created this revision.
krisb added a reviewer: tra.
Herald added subscribers: asavonic, hiraditya.
krisb requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jdoerfert.
Herald added projects: clang, LLVM.

NVVM IR specification defines them with i32 return type [0]:

  The following intrinsics synchronize a subset of threads in a warp and then
  broadcast and compare a value across threads in the subset.
  
  declare i32 @llvm.nvvm.match.any.sync.i64(i32 %membermask, i64 %value)
  declare {i32, i1} @llvm.nvvm.match.all.sync.i64(i32 %membermask, i64 %value)
  ...
  The i32 return value is a 32-bit mask where bit position in mask corresponds
  to thread’s laneid.

as well as PTX ISA spec [1]:

  9.7.12.8. Parallel Synchronization and Communication Instructions: match.sync
  ...
  Syntax
  match.any.sync.type  d, a, membermask;
  match.all.sync.type  d[|p], a, membermask;
  
  Description
  ...
  Destination d is a 32-bit mask where bit position in mask corresponds
  to thread’s laneid.

So it doesn't make sense to define them with any other return type.

Additionally, ptxas doesn't accept intructions, produced by NVPTX
backend. Here is the ptxas output for `llvm/test/CodeGen/NVPTX/match.ll`:

  ptxas match.ptx, line 44; error   : Arguments mismatch for instruction 'match'
  ptxas match.ptx, line 45; error   : Arguments mismatch for instruction 'match'
  ptxas match.ptx, line 46; error   : Arguments mismatch for instruction 'match'
  ptxas match.ptx, line 47; error   : Arguments mismatch for instruction 'match'
  ptxas match.ptx, line 98; error   : Arguments mismatch for instruction 'match'

After this patch, it compiles with no issues.

[0] https://docs.nvidia.com/cuda/nvvm-ir-spec/index.html#unique_341827171
[1] 
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-match-sync


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120499

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/Headers/__clang_cuda_intrinsics.h
  clang/test/CodeGen/builtins-nvptx-ptx60.cu
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/match.ll

Index: llvm/test/CodeGen/NVPTX/match.ll
===
--- llvm/test/CodeGen/NVPTX/match.ll
+++ llvm/test/CodeGen/NVPTX/match.ll
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_70 -mattr=+ptx60 | FileCheck %s
 
 declare i32 @llvm.nvvm.match.any.sync.i32(i32, i32)
-declare i64 @llvm.nvvm.match.any.sync.i64(i32, i64)
+declare i32 @llvm.nvvm.match.any.sync.i64(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i32
 define i32 @match.any.sync.i32(i32 %mask, i32 %value) {
@@ -23,26 +23,26 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.any.sync.i64
-define i64 @match.any.sync.i64(i32 %mask, i64 %value) {
+define i32 @match.any.sync.i64(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.any.sync.i64_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0-9]+]], [match.any.sync.i64_param_1];
 
-  ; CHECK:  match.any.sync.b64  [[V0:%rd[0-9]+]], [[VALUE]], [[MASK]];
-  %v0 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V1:%rd[0-9]+]], [[VALUE]], 1;
-  %v1 = call i64 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
-  ; CHECK:  match.any.sync.b64  [[V2:%rd[0-9]+]], 2, [[MASK]];
-  %v2 = call i64 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
-  ; CHECK:  match.any.sync.b64  [[V3:%rd[0-9]+]], 4, 3;
-  %v3 = call i64 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
-  %sum1 = add i64 %v0, %v1
-  %sum2 = add i64 %v2, %v3
-  %sum3 = add i64 %sum1, %sum2
-  ret i64 %sum3;
+  ; CHECK:  match.any.sync.b64  [[V0:%r[0-9]+]], [[VALUE]], [[MASK]];
+  %v0 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V1:%r[0-9]+]], [[VALUE]], 1;
+  %v1 = call i32 @llvm.nvvm.match.any.sync.i64(i32 1, i64 %value)
+  ; CHECK:  match.any.sync.b64  [[V2:%r[0-9]+]], 2, [[MASK]];
+  %v2 = call i32 @llvm.nvvm.match.any.sync.i64(i32 %mask, i64 2)
+  ; CHECK:  match.any.sync.b64  [[V3:%r[0-9]+]], 4, 3;
+  %v3 = call i32 @llvm.nvvm.match.any.sync.i64(i32 3, i64 4)
+  %sum1 = add i32 %v0, %v1
+  %sum2 = add i32 %v2, %v3
+  %sum3 = add i32 %sum1, %sum2
+  ret i32 %sum3;
 }
 
 declare {i32, i1} @llvm.nvvm.match.all.sync.i32p(i32, i32)
-declare {i64, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
+declare {i32, i1} @llvm.nvvm.match.all.sync.i64p(i32, i64)
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i32p(
 define {i32,i1} @match.all.sync.i32p(i32 %mask, i32 %value) {
@@ -81,37 +81,37 @@
 }
 
 ; CHECK-LABEL: .func{{.*}}match.all.sync.i64p(
-define {i64,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
+define {i32,i1} @match.all.sync.i64p(i32 %mask, i64 %value) {
   ; CHECK: ld.param.u32 	[[MASK:%r[0-9]+]], [match.all.sync.i64p_param_0];
   ; CHECK: ld.param.u64 	[[VALUE:%rd[0

[PATCH] D118259: [AArch64] Adjust aarch64-neon-intrinsics-constrained test and un-XFAIL

2022-02-24 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

In D118259#3275297 , @fhahn wrote:

> Does this clang test actually need to check the generated assembly? Shouldn't 
> it be enough to check that the correct intrinsics are generated?

I could remove the CHECK-ASM checks, but the other xyz-constrained.c tests 
(including non-aarch64 ones) all do this and it feels a bit weird to just do 
that to this test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118259

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


[PATCH] D119147: [AIX][clang][driver] Check the command string to the linker for exportlist opts

2022-02-24 Thread Digger Lin via Phabricator via cfe-commits
DiggerLin marked 6 inline comments as done.
DiggerLin added inline comments.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:80
+static bool hasExportListLinkerOpts(const ArgStringList &CmdArgs) {
+  for (size_t i = 0; i < CmdArgs.size(); ++i) {
+llvm::StringRef ArgString(CmdArgs[i]);

MaskRay wrote:
> https://llvm.org/docs/CodingStandards.html#don-t-evaluate-end-every-time-through-a-loop
> 
> Prefer `!=`
thanks



Comment at: clang/test/Driver/aix-ld.c:609
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. -shared (with exp option strings in 
other opt).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:-resource-dir=%S/Inputs/resource_dir \

MaskRay wrote:
> If you don't test `clang` in CHECK lines, you can omit 
> `-no-canonical-prefixes`
> 
> Consider switching to `.cpp` if you always use `-x c++`.
all the test in the aix-ld.c using "-no-canonical-prefixes", in order to keep 
the same style. I am prefer to keep as it now. and create a NFC patch  to clean 
the ""-no-canonical-prefixes" later.  And keep the file name as aix-ld.c , it 
maybe better to have another NFC to change the file name.



Comment at: clang/test/Driver/aix-ld.c:615
+// RUN:-ccc-install-dir 
%T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:-unwindlib=libunwind \
+// RUN:-Wl,-Z/expall/expfull/a-bE:/a-bexport:/ \

MaskRay wrote:
> `-u` prefixed long option form is not recommended. `-u` is a short option 
> taking a value, therefore an option name typo cannot be detected.
same comment as above, I am prefer for another NFC patch for it. thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119147

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


[clang] ecff9b6 - [analyzer] Just use default capture after 7fd60ee6e0a87957a718297a4a42d9881fc561e3

2022-02-24 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-02-24T10:06:11-08:00
New Revision: ecff9b65b54c7a4bd79ca2af157c81595678f0ee

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

LOG: [analyzer] Just use default capture after 
7fd60ee6e0a87957a718297a4a42d9881fc561e3

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
index d31e05076998a..5a9bebc411dc6 100644
--- a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -787,13 +787,11 @@ void GenericTaintRule::process(const GenericTaintChecker 
&Checker,
   auto &F = State->getStateManager().get_context();
   ImmutableSet Result = F.getEmptySet();
   ForEachCallArg(
-  [this, WouldEscape, &Call, &Result, &F](ArgIdxTy I, const Expr *E,
-  SVal V) {
+  [&](ArgIdxTy I, const Expr *E, SVal V) {
 if (PropDstArgs.contains(I)) {
   LLVM_DEBUG(llvm::dbgs() << "PreCall<"; Call.dump(llvm::dbgs());
  llvm::dbgs()
  << "> prepares tainting arg index: " << I << '\n';);
-  (void)Call;
   Result = F.add(Result, I);
 }
 



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


[PATCH] D119147: [AIX][clang][driver] Check the command string to the linker for exportlist opts

2022-02-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/aix-ld.c:609
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. -shared (with exp option strings in 
other opt).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:-resource-dir=%S/Inputs/resource_dir \

DiggerLin wrote:
> MaskRay wrote:
> > If you don't test `clang` in CHECK lines, you can omit 
> > `-no-canonical-prefixes`
> > 
> > Consider switching to `.cpp` if you always use `-x c++`.
> all the test in the aix-ld.c using "-no-canonical-prefixes", in order to keep 
> the same style. I am prefer to keep as it now. and create a NFC patch  to 
> clean the ""-no-canonical-prefixes" later.  And keep the file name as 
> aix-ld.c , it maybe better to have another NFC to change the file name.
See D119309


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119147

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


[PATCH] D120468: [clang][NFC] Move all avr CodeGen tests to avr specific directory

2022-02-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay 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/D120468/new/

https://reviews.llvm.org/D120468

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


[PATCH] D119147: [AIX][clang][driver] Check the command string to the linker for exportlist opts

2022-02-24 Thread Digger Lin via Phabricator via cfe-commits
DiggerLin updated this revision to Diff 411172.
DiggerLin marked 3 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119147

Files:
  clang/include/clang/Driver/Job.h
  clang/lib/Driver/Job.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/test/Driver/aix-ld.c

Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -619,10 +619,9 @@
 // CHECK-LD32-SHARED: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
 // CHECK-LD32-SHARED: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-LD32-SHARED: "-isysroot" "[[SYSROOT:[^"]+]]"
-// CHECK-LD32-SHARED: "{{.*}}CreateExportList"
-// CHECK-LD32-SHARED: "[[EXPORTLIST:[^"]+]]"
-// CHECK-LD32-SHARED: "-X"
-// CHECK-LD32-SHARED: "32"
+// CHECK-LD32-SHARED: "{{.*}}llvm-nm"
+// CHECK-LD32-SHARED: "--export-symbols"
+// CHECK-LD32-SHARED: "-X" "32"
 // CHECK-LD32-SHARED: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD32-SHARED: "-bM:SRE"
 // CHECK-LD32-SHARED: "-bnoentry"
@@ -630,7 +629,6 @@
 // CHECK-LD32-SHARED: "-bpT:0x1000" "-bpD:0x2000"
 // CHECK-LD32-SHARED-NOT: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
 // CHECK-LD32-SHARED-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti.o"
-// CHECK-LD32-SHARED: "-bE:[[EXPORTLIST]]"
 // CHECK-LD32-SHARED: "-lc++"
 // CHECK-LD32-SHARED: "-lc++abi"
 // CHECK-LD32-SHARED: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc.a"
@@ -648,7 +646,7 @@
 // RUN:--sysroot %S/Inputs/aix_ppc_tree \
 // RUN:-ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
 // RUN:-Wl,-bE:input.exp \
-// RUN:   | FileCheck -DMASS_VRM=%mass_vrm -DOPEN_XL_VRM=%open_xl_vrm --check-prefix=CHECK-LD32-SHARED-EXPORTS %s
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-SHARED-EXPORTS %s
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. -shared with export list (no -Wl, variant).
 // RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
@@ -658,7 +656,7 @@
 // RUN:--sysroot %S/Inputs/aix_ppc_tree \
 // RUN:-ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
 // RUN:-bE:input.exp \
-// RUN:   | FileCheck -DMASS_VRM=%mass_vrm -DOPEN_XL_VRM=%open_xl_vrm --check-prefix=CHECK-LD32-SHARED-EXPORTS %s
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-SHARED-EXPORTS %s
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. -shared with export list (-Xlinker variant).
 // RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
@@ -673,7 +671,7 @@
 // CHECK-LD32-SHARED-EXPORTS: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
 // CHECK-LD32-SHARED-EXPORTS: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-LD32-SHARED-EXPORTS: "-isysroot" "[[SYSROOT:[^"]+]]"
-// CHECK-LD32-SHARED-EXPORTS-NOT: "{{.*}}CreateExportList"
+// CHECK-LD32-SHARED-EXPORTS-NOT: "{{.*}}llvm-nm"
 // CHECK-LD32-SHARED-EXPORTS-NOT: "-X"
 // CHECK-LD32-SHARED-EXPORTS-NOT: "32"
 // CHECK-LD32-SHARED-EXPORTS: "{{.*}}ld{{(.exe)?}}"
@@ -701,10 +699,9 @@
 // CHECK-LD64-SHARED: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
 // CHECK-LD64-SHARED: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-LD64-SHARED: "-isysroot" "[[SYSROOT:[^"]+]]"
-// CHECK-LD64-SHARED: "{{.*}}CreateExportList"
-// CHECK-LD64-SHARED: "[[EXPORTLIST:[^"]+]]"
-// CHECK-LD64-SHARED: "-X"
-// CHECK-LD64-SHARED: "64"
+/ /CHECK-LD64-SHARED: "{{.*}}llvm-nm"
+// CHECK-LD64-SHARED: "--export-symbols"
+// CHECK-LD64-SHARED: "-X" "64"
 // CHECK-LD64-SHARED: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD64-SHARED: "-bM:SRE"
 // CHECK-LD64-SHARED: "-bnoentry"
@@ -712,7 +709,6 @@
 // CHECK-LD64-SHARED: "-bpT:0x1" "-bpD:0x11000"
 // CHECK-LD64-SHARED-NOT: "[[SYSROOT]]/usr/lib{{/|}}crt0_64.o"
 // CHECK-LD64-SHARED-NOT: "[[SYSROOT]]/usr/lib{{/|}}crti_64.o"
-// CHECK-LD64-SHARED: "-bE:[[EXPORTLIST]]"
 // CHECK-LD64-SHARED: "-lc++"
 // CHECK-LD64-SHARED: "-lc++abi"
 // CHECK-LD64-SHARED: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}aix{{/|}}libclang_rt.builtins-powerpc64.a"
@@ -751,7 +747,7 @@
 // RUN:--sysroot %S/Inputs/aix_ppc_tree \
 // RUN:-ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
 // RUN:-Wl,-bE:input.exp \
-// RUN:   | FileCheck -DMASS_VRM=%mass_vrm -DOPEN_XL_VRM=%open_xl_vrm --check-prefix=CHECK-LD64-SHARED-EXPORTS %s
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPORTS %s
 
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with export list (no -Wl, variant).
 // RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
@@ -761,7 +757,7 @@
 // RUN:--sysroot %S/Inputs/aix_ppc_tree \
 // RUN:-ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/

[PATCH] D120503: [clang-format] Handle trailing comment for InsertBraces

2022-02-24 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: curdeius, HazardyKnusperkeks, MyDeveloperDay.
owenpan added a project: clang-format.
owenpan 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/D120503

Files:
  clang/lib/Format/Format.cpp
  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
@@ -24481,6 +24481,13 @@
"  f();",
Style);
 
+  verifyFormat("if (a) {\n"
+   "  f(); // comment\n"
+   "}",
+   "if (a)"
+   "  f(); // comment",
+   Style);
+
   verifyFormat("if (a) {\n"
"  f();\n"
"}\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2338,8 +2338,10 @@
 for (const auto &L : llvm::reverse(*CurrentLines)) {
   if (!L.InPPDirective) {
 Tok = getLastNonComment(L);
-if (Tok)
+if (Tok) {
+  Tok = L.Tokens.back().Tok;
   break;
+}
   }
 }
 assert(Tok);
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1855,7 +1855,7 @@
   assert(Token->BraceCount == -1);
   Brace = '{';
 } else {
-  Brace = std::string(Token->BraceCount, '}');
+  Brace = '\n' + std::string(Token->BraceCount, '}');
 }
 Token->BraceCount = 0;
 const auto Start = Token->Tok.getEndLoc();


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24481,6 +24481,13 @@
"  f();",
Style);
 
+  verifyFormat("if (a) {\n"
+   "  f(); // comment\n"
+   "}",
+   "if (a)"
+   "  f(); // comment",
+   Style);
+
   verifyFormat("if (a) {\n"
"  f();\n"
"}\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2338,8 +2338,10 @@
 for (const auto &L : llvm::reverse(*CurrentLines)) {
   if (!L.InPPDirective) {
 Tok = getLastNonComment(L);
-if (Tok)
+if (Tok) {
+  Tok = L.Tokens.back().Tok;
   break;
+}
   }
 }
 assert(Tok);
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1855,7 +1855,7 @@
   assert(Token->BraceCount == -1);
   Brace = '{';
 } else {
-  Brace = std::string(Token->BraceCount, '}');
+  Brace = '\n' + std::string(Token->BraceCount, '}');
 }
 Token->BraceCount = 0;
 const auto Start = Token->Tok.getEndLoc();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113107: Support of expression granularity for _Float16.

2022-02-24 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 411177.
zahiraam set the repository for this revision to rG LLVM Github Monorepo.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113107

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/X86/Float16-arithmetic.c
  clang/test/CodeGen/X86/avx512fp16-abi.c
  clang/test/CodeGen/X86/avx512fp16-complex-abi.c
  clang/test/CodeGen/X86/avx512fp16-complex.c
  clang/test/CodeGen/X86/fp16-abi.c
  clang/test/CodeGen/X86/fp16-complex-abi.c
  clang/test/CodeGen/X86/fp16-complex.c
  clang/test/Sema/Float16.c
  clang/test/Sema/conversion-target-dep.c
  clang/test/SemaCXX/Float16.cpp

Index: clang/test/SemaCXX/Float16.cpp
===
--- clang/test/SemaCXX/Float16.cpp
+++ clang/test/SemaCXX/Float16.cpp
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-pc-linux-gnu %s
 
 #ifdef HAVE
 // expected-no-diagnostics
Index: clang/test/Sema/conversion-target-dep.c
===
--- clang/test/Sema/conversion-target-dep.c
+++ clang/test/Sema/conversion-target-dep.c
@@ -6,7 +6,7 @@
 
 long double ld;
 double d;
-_Float16 f16; // x86-error {{_Float16 is not supported on this target}}
+_Float16 f16;
 
 int main(void) {
   ld = d; // x86-warning {{implicit conversion increases floating-point precision: 'double' to 'long double'}}
Index: clang/test/Sema/Float16.c
===
--- clang/test/Sema/Float16.c
+++ clang/test/Sema/Float16.c
@@ -1,8 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s  -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc -target-feature +avx512fp16 %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-pc-linux-gnu %s
 
 #ifndef HAVE
 // expected-error@+2{{_Float16 is not supported on this target}}
Index: clang/test/CodeGen/X86/fp16-complex.c
===
--- clang/test/CodeGen/X86/fp16-complex.c
+++ clang/test/CodeGen/X86/fp16-complex.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown -target-feature +avx512fp16 -o - | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown -o - | FileCheck %s --check-prefixes=X86
 
 _Float16 _Complex add_half_rr(_Float16 a, _Float16 b) {
   // X86-LABEL: @add_half_rr(
Index: clang/test/CodeGen/X86/fp16-abi.c
===
--- clang/test/CodeGen/X86/fp16-abi.c
+++ clang/test/CodeGen/X86/fp16-abi.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-feature +avx512fp16 < %s | FileCheck %s --check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  < %s | FileCheck %s --check-prefixes=CHECK,CHECK-C
 // RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-feature +avx512fp16 -x c++ -std=c++11 < %s | FileCheck %s --check-prefixes=CHECK,CHECK-CPP
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -x c++ -std=c++11 < %s | FileCheck %s --check-prefixes=CHECK,CHECK-CPP
 
 struct half1 {
   _Float16 a;
@@ -150,7 +152,8 @@
 }
 
 struct float2 {
-  struct {} s;
+  struct {
+  } s;
   float a;
   float b;
 };
@@ -163,7 +166,8 @@
 
 struct float3 {
   float a;
-  struct {} s;
+  struct {
+  } s;
   float b;
 };
 
@@ -174,7 +178,8 @@
 }
 
 struct shalf2 {
-  struct {} s;
+  struct {
+  } s;
   _Float16 a;
   _Float16 b;
 };
@@ -187,9 +192,11 @@
 
 struct halfs2 {
   _Float16 a;
-  struct {} s1;
+  struct {
+  } s1;
   _Float16 b;
-  struct {} s2;
+  struct {
+  } s2;
 };
 
 _Float16 fs2(struct shalf2 s) {
Index: clang/test/CodeGen/X86/Float16-arithmetic.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/Float16-arithmetic.c
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -triple  x86_64-unknown-unknown \
+// RUN: -emit-llvm -o - %s  | FileCheck %s --check-prefixes=CHECK
+
+_Float16 add1(_Float16 a, _Float16 b) {
+  // CHECK-LABEL: define {{.*}} half @add1
+  // CHECK:

[PATCH] D120504: [AST] RAV doesn't traverse explicitly instantiated function bodies by default

2022-02-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: hokein, davidxl.
Herald added subscribers: wenlei, usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

This is consistent with the idea of shouldVisitTemplateInstantiations():
when false, we should traverse the code the user wrote but not the code
clang synthesized. Therefore we should be able to traverse the
signature of the function without traversing its body.
This is also consistent with how class and variable templates behave.

Note that currently RAV does not traverse *any* part of the these when
shouldVisitTemplateInstantiations() is false (which is another bug).
So currently this change is only observable when the user passes the
instantiated FunctionDecl to TraverseDecl themselves.

This is what the caller in CodeGenPGO does, and it wants to traverse the
instantiated body. I believe not traversing instantiations in general in
this context is an oversight.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120504

Files:
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp

Index: clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp
===
--- clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/Templates.cpp
@@ -218,11 +218,9 @@
 ADD_FAILURE() << "Could not find an explicit instantiation!";
 return Ctx.getTranslationUnitDecl();
   };
-  // FIXME: we should not visit the body, as instantiation traversals are off.
   checkLog("Explicitly traversing an explicit instantiation", Visitor, Code, R"(
 TraverseFunctionDecl
   VisitFunctionDecl foo ExplicitInstantiationDefinition
-  VisitCompoundStmt
 )");
 }
 
Index: clang/lib/CodeGen/CodeGenPGO.cpp
===
--- clang/lib/CodeGen/CodeGenPGO.cpp
+++ clang/lib/CodeGen/CodeGenPGO.cpp
@@ -154,6 +154,8 @@
 struct MapRegionCounters : public RecursiveASTVisitor {
   using Base = RecursiveASTVisitor;
 
+  bool shouldVisitTemplateInstantiations() { return true; }
+
   /// The next counter value to assign.
   unsigned NextCounter;
   /// The function hash.
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2064,6 +2064,7 @@
   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
 
+  bool BodyWasInstantiated = false;
   // If we're an explicit template specialization, iterate over the
   // template args that were explicitly specified.  If we were doing
   // this in typing order, we'd do it between the return type and
@@ -2071,8 +2072,7 @@
   // above, so we have to choose one side.  I've decided to do before.
   if (const FunctionTemplateSpecializationInfo *FTSI =
   D->getTemplateSpecializationInfo()) {
-if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
-FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
+if (FTSI->isExplicitInstantiationOrSpecialization()) {
   // A specialization might not have explicit template arguments if it has
   // a templated return type and concrete arguments.
   if (const ASTTemplateArgumentListInfo *TALI =
@@ -2081,6 +2081,8 @@
   TALI->NumTemplateArgs));
   }
 }
+BodyWasInstantiated =
+isTemplateInstantiation(FTSI->getTemplateSpecializationKind());
   }
 
   // Visit the function type itself, which can be either
@@ -2104,16 +2106,11 @@
 TRY_TO(TraverseStmt(TrailingRequiresClause));
   }
 
-  if (CXXConstructorDecl *Ctor = dyn_cast(D)) {
-// Constructor initializers.
-for (auto *I : Ctor->inits()) {
-  if (I->isWritten() || getDerived().shouldVisitImplicitCode())
-TRY_TO(TraverseConstructorInitializer(I));
-}
-  }
-
   bool VisitBody =
   D->isThisDeclarationADefinition() &&
+  // Don't visit the function body if it was instantiated, not written.
+  (!BodyWasInstantiated ||
+   getDerived().shouldVisitTemplateInstantiations()) &&
   // Don't visit the function body if the function definition is generated
   // by clang.
   (!D->isDefaulted() || getDerived().shouldVisitImplicitCode());
@@ -2128,6 +2125,14 @@
   }
 
   if (VisitBody) {
+if (CXXConstructorDecl *Ctor = dyn_cast(D)) {
+  // Constructor initializers.
+  for (auto *I : Ctor->inits()) {
+if (I->isWritten() || getDerived().shouldVisitImplicitCode())
+  TRY_TO(TraverseConstructorInitializer(I))

  1   2   >