[PATCH] D149119: [CMake] Use LLVM own tools in extract_symbols.py

2023-05-10 Thread James Henderson via Phabricator via cfe-commits
jhenderson added a comment.

In D149119#4331207 , @ikudrin wrote:

> In D149119#4329274 , @tmatheson 
> wrote:
>
>> LGTM, thank you for doing this. Please give it a couple of days in case 
>> others have comments.
>
> Thanks!
>
> In D149119#4329285 , @jhenderson 
> wrote:
>
>> I've not really looked into this patch significantly, so this may well be 
>> addressed in the patch, given I see you have modified stuff to do with the 
>> NATIVE build, but in the past I have seen LLVM using its own tools to build 
>> other parts of its system. I believe it was using llvm-nm to extract the 
>> list of symbols needed for export, possibly to do with part of the clang 
>> build, possibly even using this script, I don't remember. The problem was 
>> that it was using the just-built version of llvm-nm, rather than 
>> specifically one from a release build. On a debug build this caused 
>> particularly slow builds for me, so much so that I stopped building the 
>> relevant parts of LLVM. Please don't introduce a similar situation/make the 
>> situation worse (it's quite possible this was fixed some time ago, but I 
>> haven't tried recently, nor do I remember the exact thing causing the 
>> issue): much like tablegen, any parts of the LLVM build that use just-built 
>> tools should make use of release builds, even in debug configuration, at 
>> least if an appropriate cmake option is specified.
>
> Your concerns are legit, but the tools in this patch follow the same 
> principle as `TableGen`, i.e. if `LLVM_OPTIMIZED_TABLEGEN` is `ON` then the 
> tools are forced to be built with optimization.

Thanks - that's fine with me (though raises the question as to whether we 
should be renaming that variable at some point...).


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

https://reviews.llvm.org/D149119

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


[clang] 99f933b - [test] Clean up Driver/check-time-trace*

2023-05-10 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-05-10T00:19:46-07:00
New Revision: 99f933b6346b0afcafa3c1ea0972136d7b441a86

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

LOG: [test] Clean up Driver/check-time-trace*

Rename check-time-trace* to ftime-trace*.
Avoid deprecated %T.

Added: 
clang/test/Driver/ftime-trace-sections.cpp
clang/test/Driver/ftime-trace-sections.py
clang/test/Driver/ftime-trace.cpp

Modified: 


Removed: 
clang/test/Driver/check-time-trace-sections.cpp
clang/test/Driver/check-time-trace-sections.py
clang/test/Driver/check-time-trace.cpp



diff  --git a/clang/test/Driver/check-time-trace-sections.cpp 
b/clang/test/Driver/check-time-trace-sections.cpp
deleted file mode 100644
index 2dbe2037550a5..0
--- a/clang/test/Driver/check-time-trace-sections.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o 
%T/check-time-trace-sections %s
-// RUN: cat %T/check-time-trace-sections.json | %python 
%S/check-time-trace-sections.py
-
-template 
-void foo(T) {}
-void bar() { foo(0); }

diff  --git a/clang/test/Driver/ftime-trace-sections.cpp 
b/clang/test/Driver/ftime-trace-sections.cpp
new file mode 100644
index 0..0c16052bc0c3a
--- /dev/null
+++ b/clang/test/Driver/ftime-trace-sections.cpp
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t && mkdir %t && cd %t
+// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o out %s
+// RUN: %python %S/ftime-trace-sections.py < out.json
+
+template 
+void foo(T) {}
+void bar() { foo(0); }

diff  --git a/clang/test/Driver/check-time-trace-sections.py 
b/clang/test/Driver/ftime-trace-sections.py
similarity index 100%
rename from clang/test/Driver/check-time-trace-sections.py
rename to clang/test/Driver/ftime-trace-sections.py

diff  --git a/clang/test/Driver/check-time-trace.cpp 
b/clang/test/Driver/ftime-trace.cpp
similarity index 62%
rename from clang/test/Driver/check-time-trace.cpp
rename to clang/test/Driver/ftime-trace.cpp
index 32940500db1bc..42a969059101f 100644
--- a/clang/test/Driver/check-time-trace.cpp
+++ b/clang/test/Driver/ftime-trace.cpp
@@ -1,19 +1,19 @@
-// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o 
%T/check-time-trace %s
-// RUN: cat %T/check-time-trace.json \
+// RUN: rm -rf %t && mkdir -p %t && cd %t
+// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o out %s
+// RUN: cat out.json \
 // RUN:   | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
-// RUN: %clangxx -S -ftime-trace=%T/new-name.json -ftime-trace-granularity=0 
-o %T/check-time-trace %s
-// RUN: cat %T/new-name.json \
+// RUN: %clangxx -S -ftime-trace=new-name.json -ftime-trace-granularity=0 -o 
out %s
+// RUN: cat new-name.json \
 // RUN:   | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
-// RUN: rm -rf %T/output1 && mkdir %T/output1
-// RUN: %clangxx -S -ftime-trace=%T/output1 -ftime-trace-granularity=0 -o 
%T/check-time-trace %s
-// RUN: cat %T/output1/check-time-trace.json \
+// RUN: mkdir dir1 dir2
+// RUN: %clangxx -S -ftime-trace=dir1 -ftime-trace-granularity=0 -o out %s
+// RUN: cat dir1/out.json \
 // RUN:   | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
-// RUN: rm -rf %T/output2 && mkdir %T/output2
-// RUN: %clangxx -S -ftime-trace=%T/output2/ -ftime-trace-granularity=0 -o 
%T/check-time-trace %s
-// RUN: cat %T/output2/check-time-trace.json \
+// RUN: %clangxx -S -ftime-trace=dir2/ -ftime-trace-granularity=0 -o out %s
+// RUN: cat dir2/out.json \
 // RUN:   | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
 



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


[PATCH] D150253: [RISCV] Add Zvfhmin extension.

2023-05-10 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan created this revision.
jacquesguan added reviewers: craig.topper, asb, luismarques, frasercrmck.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, evandro, apazos, 
sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, 
kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, 
arichardson.
Herald added a project: All.
jacquesguan requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, eopXD, 
MaskRay.
Herald added projects: clang, LLVM.

This patch adds the Zvfhmin extension for clang and llvm RISCV target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150253

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin-error.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
  clang/utils/TableGen/RISCVVEmitter.cpp
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td

Index: llvm/lib/Target/RISCV/RISCVFeatures.td
===
--- llvm/lib/Target/RISCV/RISCVFeatures.td
+++ llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -446,6 +446,11 @@
   "'V' (Vector Extension for Application Processors), 'Zve32f', "
   "'Zve64f' or 'Zve64d' (Vector Extensions for Embedded Processors)">;
 
+def FeatureStdExtZvfhmin
+: SubtargetFeature<"experimental-zvfhmin", "HasStdExtZvfhmin", "true",
+   "'Zvfhmin' (Vector Half-Precision Floating-Point Minimal)",
+   [FeatureStdExtZve32f]>;
+
 def FeatureStdExtZvfh
 : SubtargetFeature<"experimental-zvfh", "HasStdExtZvfh", "true",
"'Zvfh' (Vector Half-Precision Floating-Point)",
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -148,6 +148,7 @@
 {"zcmt", RISCVExtensionVersion{1, 0}},
 {"zfa", RISCVExtensionVersion{0, 2}},
 {"zicond", RISCVExtensionVersion{1, 0}},
+{"zvfhmin", RISCVExtensionVersion{0, 1}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
 {"ztso", RISCVExtensionVersion{0, 1}},
 
@@ -936,6 +937,7 @@
 static const char *ImpliedExtsZve64d[] = {"zve64f", "d"};
 static const char *ImpliedExtsZve64f[] = {"zve64x", "zve32f"};
 static const char *ImpliedExtsZve64x[] = {"zve32x", "zvl64b"};
+static const char *ImpliedExtsZvfhmin[] = {"zve32f"};
 static const char *ImpliedExtsZvfh[] = {"zve32f", "zfhmin"};
 static const char *ImpliedExtsZvkn[] = {"zvbb", "zvbc", "zvkned", "zvknhb",
 "zvkt"};
@@ -994,6 +996,7 @@
 {{"zve64d"}, {ImpliedExtsZve64d}},
 {{"zve64f"}, {ImpliedExtsZve64f}},
 {{"zve64x"}, {ImpliedExtsZve64x}},
+{{"zvfhmin"}, {ImpliedExtsZvfhmin}},
 {{"zvfh"}, {ImpliedExtsZvfh}},
 {{"zvkn"}, {ImpliedExtsZvkn}},
 {{"zvkng"}, {ImpliedExtsZvkng}},
Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -633,6 +633,7 @@
   RVVRequire RequireExt = StringSwitch(RequiredFeature)
   .Case("RV64", RVV_REQ_RV64)
   .Case("FullMultiply", RVV_REQ_FullMultiply)
+  .Case("ZvfhminOrZvfh", RVV_REQ_ZvfhminOrZvfh)
   .Case("Xsfvcp", RVV_REQ_Xsfvcp)
   .Default(RVV_REQ_None);
   assert(RequireExt != RVV_REQ_None && "Unrecognized required feature?");
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
@@ -0,0 +1,28 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v \
+// RUN:   -target-feature +experimental-zvfhmin -disable-O0-optnone  \
+// RUN:   -emit-llvm %s -o - | opt -S -passes=mem2reg | \
+// RUN:   FileCheck --check-prefix=CHECK-ZVFHMIN %s
+
+#include 
+
+
+// CHECK-ZVFHMIN-LABEL: @test_vfncvt_f_f_w_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vfncvt.f.f.w.nxv4f16.nxv4f32.i64( poison,  [[SRC:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t test_vfncvt_f_f_w_f16m1(vfloat32m2_t src, size_t vl) {
+  return __riscv_vfncvt_f(src, vl);
+}
+
+
+// CHECK-ZVFHMIN-LABEL: @test_vfwcvt_f_f_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]

[PATCH] D150254: [tidy] Fix possible use-after-free in IdentifierNamingCheck

2023-05-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: hokein, PiotrZSL.
Herald added a subscriber: carlosgalvezp.
Herald added a reviewer: njames93.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

CheckName retrieived during construction is a reference to keys stored
inside ClangTidyCheckFactories, which isn't guranteed to outlive the check.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150254

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h


Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
@@ -11,6 +11,7 @@
 
 #include "../utils/RenamerClangTidyCheck.h"
 #include 
+#include 
 namespace clang::tidy {
 namespace readability {
 
@@ -202,7 +203,7 @@
   mutable llvm::StringMap NamingStylesCache;
   FileStyle *MainFileStyle;
   ClangTidyContext *Context;
-  const StringRef CheckName;
+  const std::string CheckName;
   const bool GetConfigPerFile;
   const bool IgnoreFailedSplit;
   HungarianNotation HungarianNotation;


Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
@@ -11,6 +11,7 @@
 
 #include "../utils/RenamerClangTidyCheck.h"
 #include 
+#include 
 namespace clang::tidy {
 namespace readability {
 
@@ -202,7 +203,7 @@
   mutable llvm::StringMap NamingStylesCache;
   FileStyle *MainFileStyle;
   ClangTidyContext *Context;
-  const StringRef CheckName;
+  const std::string CheckName;
   const bool GetConfigPerFile;
   const bool IgnoreFailedSplit;
   HungarianNotation HungarianNotation;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150254: [tidy] Fix possible use-after-free in IdentifierNamingCheck

2023-05-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

see 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/ClangTidy.cpp#L638
 for such a pattern, clangd also initializes checks with a similar approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150254

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


[PATCH] D149986: AMDGPU: Force sc0 and sc1 on stores for gfx940 and gfx941

2023-05-10 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp:524
+ SIAtomicAddrSpace::NONE)
+  return enableSC0Bit(MI) | enableSC1Bit(MI);
+return false;

NIT: Is the use of the bitwise or " | " intended? I'd use the logical or " || " 
instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149986

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


[PATCH] D148505: Allow `__attribute__((warn_unused))` on individual constructors

2023-05-10 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

In D148505#4302702 , @aaron.ballman 
wrote:

> Thank you for poking on this! FWIW, I don't know that there's a way to 
> cross-post to Discourse (but if I'm wrong and there is, I'd love to know 
> how!).

Ping, any further input from anybody?

(The cross-posting didn't work, but there was also almost no response on the 
GCC side, https://gcc.gnu.org/pipermail/gcc/2023-April/241220.html "Re: 
GCC/Clang attributes guiding warnings about unused entities".)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148505

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


[PATCH] D140275: [clangd] Tweak to add doxygen comment to the function declaration

2023-05-10 Thread Oleg Skoromnik via Phabricator via cfe-commits
tupos added a comment.

Hi,

could you please provide a code review again?

Thanks.

With best regards,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140275

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


[clang] f109b10 - [NFC] [C++20] [Modules] Refactor Sema::isModuleUnitOfCurrentTU into

2023-05-10 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-05-10T16:01:27+08:00
New Revision: f109b1016801e2b0dbee278f3c517057c0b1d441

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

LOG: [NFC] [C++20] [Modules] Refactor Sema::isModuleUnitOfCurrentTU into
Decl::isInCurrentModuleUnit

Refactor `Sema::isModuleUnitOfCurrentTU` to `Decl::isInCurrentModuleUnit`
to make code simpler a little bit. Note that although this patch
introduces a FIXME, this is an existing issue and this patch just tries
to describe it explicitly.

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/DeclBase.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaModule.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index b08eb525602b6..c2e4847d1d1e8 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -447,9 +447,8 @@ class ASTContext : public RefCountedBase {
   };
   llvm::DenseMap ModuleInitializers;
 
-  /// For module code-gen cases, this is the top-level (C++20) Named module
-  /// we are building.
-  Module *TopLevelCXXNamedModule = nullptr;
+  /// This is the top-level (C++20) Named module we are building.
+  Module *CurrentCXXNamedModule = nullptr;
 
   static constexpr unsigned ConstantArrayTypesLog2InitSize = 8;
   static constexpr unsigned GeneralTypesLog2InitSize = 9;
@@ -1052,10 +1051,10 @@ class ASTContext : public RefCountedBase {
   ArrayRef getModuleInitializers(Module *M);
 
   /// Set the (C++20) module we are building.
-  void setNamedModuleForCodeGen(Module *M) { TopLevelCXXNamedModule = M; }
+  void setCurrentNamedModule(Module *M);
 
   /// Get module under construction, nullptr if this is not a C++20 module.
-  Module *getNamedModuleForCodeGen() const { return TopLevelCXXNamedModule; }
+  Module *getCurrentNamedModule() const { return CurrentCXXNamedModule; }
 
   TranslationUnitDecl *getTranslationUnitDecl() const {
 return TUDecl->getMostRecentDecl();

diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index be76d1648b9ac..571f1f10387bf 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -644,6 +644,9 @@ class alignas(8) Decl {
 return getModuleOwnershipKind() > ModuleOwnershipKind::VisibleWhenImported;
   }
 
+  /// Whether this declaration comes from another module unit.
+  bool isInCurrentModuleUnit() const;
+
   /// FIXME: Implement discarding declarations actually in global module
   /// fragment. See [module.global.frag]p3,4 for details.
   bool isDiscardedInGlobalModuleFragment() const { return false; }

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5296d7000b5cc..4d68462e43e3e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2358,9 +2358,6 @@ class Sema final {
 return Entity->getOwningModule();
   }
 
-  // Determine whether the module M belongs to the  current TU.
-  bool isModuleUnitOfCurrentTU(const Module *M) const;
-
   /// Make a merged definition of an existing hidden definition \p ND
   /// visible at the specified location.
   void makeMergedDefinitionVisible(NamedDecl *ND);

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index de65c3cc47b9b..3441c069b4b83 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1153,6 +1153,13 @@ ArrayRef 
ASTContext::getModuleInitializers(Module *M) {
   return Inits->Initializers;
 }
 
+void ASTContext::setCurrentNamedModule(Module *M) {
+  assert(M->isModulePurview());
+  assert(!CurrentCXXNamedModule &&
+ "We should set named module for ASTContext for only once");
+  CurrentCXXNamedModule = M;
+}
+
 ExternCContextDecl *ASTContext::getExternCContextDecl() const {
   if (!ExternCContext)
 ExternCContext = ExternCContextDecl::Create(*this, 
getTranslationUnitDecl());

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index f49945f434193..fe458b67dcab0 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -30,6 +30,7 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/Module.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceLocation.h"
@@ -1022,6 +1023,26 @@ bool Decl::isInExportDeclContext() const {
   return DC && isa(DC);

[PATCH] D150253: [RISCV] Add Zvfhmin extension.

2023-05-10 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Don’t you need to make f16 vectors legal types in the backend?

And you need to disable intrinsics for instructions that aren’t supported by 
Zfhmin. Like f16 vector fadd

And you also need to make the backend only allow f16 vector operations that are 
supported with Zfhmin.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150253

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


[PATCH] D149495: [RISCV] Add support for V extension in SiFive7

2023-05-10 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead accepted this revision.
pcwang-thead added a comment.

LGTM.
Though I don't like the way that we need to loop `MxList` again when defining 
scheduling model, I think this can be a good practice to define RVV scheduling 
model in current TableGen's grammar.




Comment at: llvm/lib/Target/RISCV/RISCVSchedSiFive7.td:15
+class SiFive7IsWorstCaseMX MxList> {
+  string LLMUL = LargestLMUL.r;
+  bit c = !eq(mx, LLMUL);

michaelmaitland wrote:
> pcwang-thead wrote:
> > I think I have fixed the issue that `defar` can't refer to template 
> > arguments in D148197. So `LMUL`, `SSEW` and other fields can be replaced 
> > with `defvar`s.
> A `defvar` statement defines a global variable. `SiFive7IsWorstCaseMX SchedMxList>.c` becomes invalid syntax since `c` is not a member of 
> `SiFive7IsWorstCaseMX` now that `c` is global. If we did use `defvar` here 
> and gave `c` a more unique name so that it could fit in the global space, 
> then we would also need to complicate it by adding a `MXxxx_MxListxxx` suffix 
> for all `mx` and `SchedMxList` pairs. 
> 
> I think we'd like to keep these as `Type Iden = Value;`. What do you think?
I mean:
```
class SiFive7IsWorstCaseMX MxList> {
  defvar LLMUL = LargestLMUL.r;
  bit c = !eq(mx, LLMUL);
}
```
`LLMUL` can be a local variable so that there is only one field `c`(which is 
the result of this class-based subroutine). We can keep only one field as 
result and change other fields to local variables. In this way, we know that 
`SiFive7IsWorstCaseMX` is a subroutine conventionally and can be replace with 
`function` in the future(if my patches is merged).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149495

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


[PATCH] D148700: [clang] Add support for “regular” keyword attributes

2023-05-10 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm added a subscriber: sdesmalen.
rsandifo-arm added a comment.

Thanks for the review.




Comment at: clang/include/clang/Basic/Attr.td:2427-2430
+def ArmStreaming : TypeAttr, TargetSpecificAttr {
+  let Spellings = [RegularKeyword<"__arm_streaming">];
+  let Documentation = [Undocumented];
+}

aaron.ballman wrote:
> I'd feel more comfortable switching an existing attribute over to use this 
> new functionality instead of introducing a new attribute at the same time. 
> (Also, we ask that there be no new undocumented attributes unless there's a 
> Very Good Reason to leave it undocumented.)
Could you suggest an attribute that would be suitable?  The problem is that, as 
far as I know, no existing keyword has parse rules that exactly match the rules 
for standard attributes.  (That, and the fact that different keywords have 
different rules, was one of the main motivations for the patch).  So I don't 
think it would be possible to adopt the new scheme for existing attributes 
without breaking compatiblity (both ways: some things would become valid that 
weren't before, and some things that were valid before would become invalid).

E.g.:

 __declspec

I don't think anyone was suggesting we try to convert this :-) but for 
completeness:

```
int __declspec(align(16)) a1; // OK, but standard attribute rules would say 
this appertains to the type
int a2 __declspec();  // Not valid, unlike for standard decl attributes
```

 __forceinline

```
int __forceinline a1() { return 1; } // OK, but standard attribute rules would 
say this appertains to the type
int a2 __forceinline() { return 1; } // Not valid, but would be for standard 
decl attributes
```

 Calling convention keywords

These are generally DeclOrType attributes, with attributes sliding from the 
decl to the type where necessary.

```
__stdcall int a1();   // OK, but appertains to the decl and relies on sliding 
behaviour
int a2 __stdcall();   // Not valid, but is another place to put standard decl 
attributes
int a3() __stdcall;   // Not valid, but is another place to put standard type 
attributes
int (__stdcall a4)(); // OK, but standard attributes aren't allowed in this 
position
extern int (*const __stdcall volatile a5) (); // OK, but standard attributes 
wouldn't be allowed here
```

 Nullability keywords

Like the calling-convention keywords, the nullability keywords appertain to 
types but are allowed in some (but not all) positions that would normally 
appertain to decls:

```
using ptr = int *;
_Nullable ptr a1; // OK, but appertains to the decl and relies on sliding 
behaviour
ptr a2 _Nullable; // Not valid, but is another place to put standard decl 
attributes
extern int *const _Nullable volatile a3; // OK, but a standard attribute 
wouldn't be allowed here
```

The same distinction applies to Microsoft pointer attributes.

On the documentation side: I admit this is one of the awkward things about 
using a new keyword to prove the system.  The series doesn't actually implement 
`__arm_streaming` (@sdesmalen has patches for that, and other SME stuff).  So 
it didn't seem appropriate to document the attribute until it was actually 
implemented.  But the implementation, when it comes, will/should have 
documentation.



Comment at: clang/lib/AST/TypePrinter.cpp:1724-1727
+  if (T->getAttrKind() == attr::ArmStreaming) {
+OS << "__arm_streaming";
+return;
+  }

aaron.ballman wrote:
> This seems like something that tablegen should automatically handle more 
> generally for these attributes.
I wondered about trying to use tablegen for TypePrinter::printAttributedAfter, 
but decided against it. 
 RegularKeyword is really a spelling-level classification rather than an 
attribute-level classification, and in general, an attribute could have both 
GNU and RegularKeyword spellings. In contrast, printAttributedAfter is only 
given the attribute kind and the type that results from applying the attribute. 
AFAIK, it doesn't have access to the original attribute spelling. This means 
that some attribute-specific or type-specific knowledge might be needed to 
print the attribute in the best way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148700

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


[PATCH] D150254: [tidy] Fix possible use-after-free in IdentifierNamingCheck

2023-05-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

The fix looks good.

We also have a `CheckName` field in the base class `ClangTidyCheck`, however 
that's field is private, we can't not access, we could consider make it 
protected (I think that's probably out of the scope of this patch).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150254

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


[PATCH] D150254: [tidy] Fix possible use-after-free in IdentifierNamingCheck

2023-05-10 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D150254#4331640 , @kadircet wrote:

> see 
> https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/ClangTidy.cpp#L638
>  for such a pattern, clangd also initializes checks with a similar approach.

In this example the factory outlives the check so there is no possible use 
after free.

In regard to this change, I think that this member can actually be removed 
entirely as we can get the name of the check using the `getID` virtual function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150254

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


[PATCH] D150254: [tidy] Fix possible use-after-free in IdentifierNamingCheck

2023-05-10 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D150254#4331734 , @hokein wrote:

> The fix looks good.
>
> We also have a `CheckName` field in the base class `ClangTidyCheck`, however 
> that's field is private, we can't not access, we could consider make it 
> protected (I think that's probably out of the scope of this patch).

See previous comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150254

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


[PATCH] D150257: [clangd] Initialize clang-tidy modules only once

2023-05-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: carlosgalvezp, arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This is showing up on our profiles with ~100ms contribution @95th% for
buildAST latencies.
The patch is unlikely to address it all, but should help with some low-hanging
fruit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150257

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/TidyProvider.cpp


Index: clang-tools-extra/clangd/TidyProvider.cpp
===
--- clang-tools-extra/clangd/TidyProvider.cpp
+++ clang-tools-extra/clangd/TidyProvider.cpp
@@ -8,6 +8,7 @@
 
 #include "TidyProvider.h"
 #include "../clang-tidy/ClangTidyModuleRegistry.h"
+#include "../clang-tidy/ClangTidyOptions.h"
 #include "Config.h"
 #include "support/FileCache.h"
 #include "support/Logger.h"
@@ -283,11 +284,18 @@
 
 tidy::ClangTidyOptions getTidyOptionsForFile(TidyProviderRef Provider,
  llvm::StringRef Filename) {
-  tidy::ClangTidyOptions Opts = tidy::ClangTidyOptions::getDefaults();
-  Opts.Checks->clear();
-  if (Provider)
-Provider(Opts, Filename);
-  return Opts;
+  // getDefaults instantiates all check factories, which are registered at link
+  // time. So cache the results once.
+  static const auto Opts = [] {
+auto Opts = tidy::ClangTidyOptions::getDefaults();
+Opts.Checks->clear();
+return Opts;
+  }();
+  if (!Provider)
+return Opts;
+  auto NewOpts = Opts;
+  Provider(NewOpts, Filename);
+  return NewOpts;
 }
 
 bool isRegisteredTidyCheck(llvm::StringRef Check) {
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -9,6 +9,7 @@
 #include "ParsedAST.h"
 #include "../clang-tidy/ClangTidyCheck.h"
 #include "../clang-tidy/ClangTidyDiagnosticConsumer.h"
+#include "../clang-tidy/ClangTidyModule.h"
 #include "../clang-tidy/ClangTidyModuleRegistry.h"
 #include "AST.h"
 #include "Compiler.h"
@@ -25,7 +26,6 @@
 #include "TidyProvider.h"
 #include "clang-include-cleaner/Record.h"
 #include "index/CanonicalIncludes.h"
-#include "index/Index.h"
 #include "index/Symbol.h"
 #include "support/Logger.h"
 #include "support/Trace.h"
@@ -50,7 +50,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include 
 #include 
 #include 
 #include 
@@ -476,9 +475,12 @@
   // diagnostics.
   if (PreserveDiags) {
 trace::Span Tracer("ClangTidyInit");
-tidy::ClangTidyCheckFactories CTFactories;
-for (const auto &E : tidy::ClangTidyModuleRegistry::entries())
-  E.instantiate()->addCheckFactories(CTFactories);
+static const tidy::ClangTidyCheckFactories CTFactories = [] {
+  tidy::ClangTidyCheckFactories CTFactories;
+  for (const auto &E : tidy::ClangTidyModuleRegistry::entries())
+E.instantiate()->addCheckFactories(CTFactories);
+  return CTFactories;
+}();
 CTContext.emplace(std::make_unique(
 tidy::ClangTidyGlobalOptions(), ClangTidyOpts));
 CTContext->setDiagnosticsEngine(&Clang->getDiagnostics());
@@ -610,10 +612,8 @@
 Macros = Patch->mainFileMacros();
 Marks = Patch->marks();
   }
-  auto& PP = Clang->getPreprocessor();
-  PP.addPPCallbacks(
-  std::make_unique(
-  PP, Macros));
+  auto &PP = Clang->getPreprocessor();
+  PP.addPPCallbacks(std::make_unique(PP, Macros));
 
   PP.addPPCallbacks(
   collectPragmaMarksCallback(Clang->getSourceManager(), Marks));


Index: clang-tools-extra/clangd/TidyProvider.cpp
===
--- clang-tools-extra/clangd/TidyProvider.cpp
+++ clang-tools-extra/clangd/TidyProvider.cpp
@@ -8,6 +8,7 @@
 
 #include "TidyProvider.h"
 #include "../clang-tidy/ClangTidyModuleRegistry.h"
+#include "../clang-tidy/ClangTidyOptions.h"
 #include "Config.h"
 #include "support/FileCache.h"
 #include "support/Logger.h"
@@ -283,11 +284,18 @@
 
 tidy::ClangTidyOptions getTidyOptionsForFile(TidyProviderRef Provider,
  llvm::StringRef Filename) {
-  tidy::ClangTidyOptions Opts = tidy::ClangTidyOptions::getDefaults();
-  Opts.Checks->clear();
-  if (Provider)
-Provider(Opts, Filename);
-  return Opts;
+  // getDefaults instantiates all check factories, which are registered at link
+  // time. So cache the results once.
+  static const auto Opts = [] {
+auto Opts = tidy::ClangTidyOptions::getDefaults();
+Opts.Checks->clear();
+return Opts;
+  }();
+  if (!Provider)
+return Opts;
+  auto NewOpts = Opts;
+  Provider(NewOpts, Filename);
+  return NewOpts;
 }
 
 bool isRegisteredTidyC

[PATCH] D150126: [clang-tidy][WIP] Set traversal scope to prevent analysis in headers

2023-05-10 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: carlosgalvezp, PiotrZSL.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
njames93 updated this revision to Diff 520620.
njames93 added a comment.
njames93 updated this revision to Diff 520918.
njames93 retitled this revision from "[clang-tidy] Set traversal scope to 
prevent analysis in headers" to "[clang-tidy][WIP] Set traversal scope to 
prevent analysis in headers".
njames93 published this revision for review.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Fix failing unittests


njames93 added a comment.

Fix infrastructure test failures




Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:511
+
+Consumers.push_back(std::make_unique(
+!Context.getOptions().SystemHeaders.value_or(false),

Here comes a stupid question :) If I understand correctly we are adding one 
more ASTConsumer to the list of Consumers, i.e. we are not replacing the 
"normal" consumer with the "optimized" consumer. So I fail to understand how 
adding this new consumer fixes the problems of the other consumer? I'd be happy 
to read more about the implementation if there are resources you could point me 
to.



Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:511
+
+Consumers.push_back(std::make_unique(
+!Context.getOptions().SystemHeaders.value_or(false),

carlosgalvezp wrote:
> Here comes a stupid question :) If I understand correctly we are adding one 
> more ASTConsumer to the list of Consumers, i.e. we are not replacing the 
> "normal" consumer with the "optimized" consumer. So I fail to understand how 
> adding this new consumer fixes the problems of the other consumer? I'd be 
> happy to read more about the implementation if there are resources you could 
> point me to.
The `MultiplexConsumer` runs each consumers callbacks in the order they are 
added.  So this consumers `HandleTranslationUnit` callback will be executed 
before the `FinderASTConsumer `runs its `HandleTranslationUnit` callback(The 
function that actually does the AST matching. So by modifying the `ASTContext` 
traversal scope in this `HandleTranslationUnit` callback, the results are 
visible when the Finder comes to do its matching.

Also part of this implementation was taken from clangd which uses a somewhat 
similar approach to only run tidy checks that originate in the main file 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/ParsedAST.cpp#L73


See 
https://discourse.llvm.org/t/rfc-exclude-issues-from-system-headers-as-early-as-posible/68483


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150126

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp
  clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
  clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/file-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/line-filter.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/system-headers.cpp

Index: clang-tools-extra/test/clang-tidy/infrastructure/system-headers.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/system-headers.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/system-headers.cpp
@@ -11,9 +11,9 @@
 // RUN: clang-tidy -help | FileCheck -check-prefix=CHECK-OPT-PRESENT %s
 
 // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers=true %s -- -isystem %S/Inputs/system-headers 2>&1 | FileCheck -check-prefix=CHECK-SYSTEM-HEADERS %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers=false %s -- -isystem %S/Inputs/system-headers 2>&1 | FileCheck -check-prefix=CHECK-NO-SYSTEM-HEADERS %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers=false %s -- -isystem %S/Inputs/system-headers 2>&1 | FileCheck -check-prefix=CHECK-NO-SYSTEM-HEADERS %s --allow-empty
 // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -config='SystemHeaders: true' %s -- -isystem %S/Inputs/system-headers 2>&1 | FileCheck -check-prefix=CHECK-SYSTEM-HEADERS %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -config='SystemHeaders: false' %s -- -isystem %S/Inputs/system-headers 2>&1 | FileCheck -check-prefix=CHECK-NO-SYSTEM-HEADERS %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -config='SystemHeaders: false' %s -- -isystem %S/Inputs/system-headers 2>&1 | FileCheck -check-prefix=CHECK-NO-SYSTEM-HEADERS %s --allow-empty
 
 #include 
 // CHECK-SYSTEM-HEADERS: system_header.h:1:13: warning: sing

[PATCH] D150257: [clangd] Initialize clang-tidy modules only once

2023-05-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/ParsedAST.cpp:478
 trace::Span Tracer("ClangTidyInit");
-tidy::ClangTidyCheckFactories CTFactories;
-for (const auto &E : tidy::ClangTidyModuleRegistry::entries())
-  E.instantiate()->addCheckFactories(CTFactories);
+static const tidy::ClangTidyCheckFactories CTFactories = [] {
+  tidy::ClangTidyCheckFactories CTFactories;

as written this creates a global destructor

instead, prefer heap-allocating and never freeing (the static variable should 
be a pointer or non-lifetime-extending reference)



Comment at: clang-tools-extra/clangd/TidyProvider.cpp:289
+  // time. So cache the results once.
+  static const auto Opts = [] {
+auto Opts = tidy::ClangTidyOptions::getDefaults();

same here, avoid the destructor



Comment at: clang-tools-extra/clangd/TidyProvider.cpp:289
+  // time. So cache the results once.
+  static const auto Opts = [] {
+auto Opts = tidy::ClangTidyOptions::getDefaults();

sammccall wrote:
> same here, avoid the destructor
nit: call this DefaultOpts, as it's in general not the opts we're calculating



Comment at: clang-tools-extra/clangd/TidyProvider.cpp:294
+  }();
+  if (!Provider)
+return Opts;

Inverting the if(Provider) check isn't clearer IMO, and it's also not an 
optimization (`return Opts` is a copy, vs `NewOpts = Opts` is a copy + `return 
NewOpts` is a NVRO no-op).

Up to you, but I prefer the previous formulation (with the extra copy of 
defaultopts added at the top)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150257

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


[PATCH] D150254: [tidy] Fix possible use-after-free in IdentifierNamingCheck

2023-05-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 520936.
kadircet added a comment.

- Expose getID to tidy-checks and use it instead of storing checkname


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150254

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h


Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
@@ -11,6 +11,7 @@
 
 #include "../utils/RenamerClangTidyCheck.h"
 #include 
+#include 
 namespace clang::tidy {
 namespace readability {
 
@@ -202,7 +203,6 @@
   mutable llvm::StringMap NamingStylesCache;
   FileStyle *MainFileStyle;
   ClangTidyContext *Context;
-  const StringRef CheckName;
   const bool GetConfigPerFile;
   const bool IgnoreFailedSplit;
   HungarianNotation HungarianNotation;
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -14,6 +14,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -396,7 +397,7 @@
 
 IdentifierNamingCheck::IdentifierNamingCheck(StringRef Name,
  ClangTidyContext *Context)
-: RenamerClangTidyCheck(Name, Context), Context(Context), CheckName(Name),
+: RenamerClangTidyCheck(Name, Context), Context(Context),
   GetConfigPerFile(Options.get("GetConfigPerFile", true)),
   IgnoreFailedSplit(Options.get("IgnoreFailedSplit", false)) {
 
@@ -1461,6 +1462,7 @@
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
+  llvm::StringRef CheckName = getID();
   ClangTidyOptions Options = Context->getOptionsForFile(FileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
Index: clang-tools-extra/clang-tidy/ClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -407,7 +407,6 @@
 
 private:
   void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  StringRef getID() const override { return CheckName; }
   std::string CheckName;
   ClangTidyContext *Context;
 
@@ -422,6 +421,7 @@
   bool areDiagsSelfContained() const {
 return Context->areDiagsSelfContained();
   }
+  StringRef getID() const override { return CheckName; }
 };
 
 /// Read a named option from the ``Context`` and parse it as a bool.


Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
@@ -11,6 +11,7 @@
 
 #include "../utils/RenamerClangTidyCheck.h"
 #include 
+#include 
 namespace clang::tidy {
 namespace readability {
 
@@ -202,7 +203,6 @@
   mutable llvm::StringMap NamingStylesCache;
   FileStyle *MainFileStyle;
   ClangTidyContext *Context;
-  const StringRef CheckName;
   const bool GetConfigPerFile;
   const bool IgnoreFailedSplit;
   HungarianNotation HungarianNotation;
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -14,6 +14,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -396,7 +397,7 @@
 
 IdentifierNamingCheck::IdentifierNamingCheck(StringRef Name,
  ClangTidyContext *Context)
-: RenamerClangTidyCheck(Name, Context), Context(Context), CheckName(Name),
+: RenamerClangTidyCheck(Name, Context), Context(Context),
   GetConfigPerFile(Options.get("GetConfigPerFile", true)),
   IgnoreFailedSplit(Options.get("IgnoreFailedSplit", false)) {
 
@@ -1461,6 +1462,7 @@
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
+  llvm::StringRef CheckName = getID();
   ClangTidyOptions Options = Context->getOptionsForFi

[PATCH] D150258: [clang][parser] Fix namespace dropping after malformed declarations

2023-05-10 Thread Alejandro Álvarez Ayllón via Phabricator via cfe-commits
alejandro-alvarez-sonarsource created this revision.
alejandro-alvarez-sonarsource added a reviewer: aaron.ballman.
alejandro-alvarez-sonarsource added a project: clang.
Herald added a subscriber: kadircet.
Herald added a project: All.
alejandro-alvarez-sonarsource requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.

- After a malformed top-level declaration
- After a malformed templated class method declaration

In both cases, when there is a malformed declaration, any following namespace 
is dropped from the AST.
This can trigger a cascade of confusing diagnostics that may hide the original 
error. An example:

  // Start #include "SomeFile.h"
  template 
  void Foo::Bar(void* aRawPtr) {
  (void)(aRawPtr);
  }
  // End #include "SomeFile.h"
  
  #include 
  
  int main() {}

We get the original error, plus 19 others from the standard library. 
With this patch, we only get the original error.

  clangd
  ``` can also benefit from this patch, as namespaces following the malformed 
declaration is now preserved. i.e.

#pragma once

MACRO_FROM_MISSING_INCLUDE("X")

namespace my_namespace {

  //...

}

  Before this patch, `my_namespace` is not visible for auto-completion.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150258

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Parser/cxx-namespace-after-missing-semicolon.cpp
  clang/test/Parser/cxx-template-recovery.cpp


Index: clang/test/Parser/cxx-template-recovery.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx-template-recovery.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify %s
+
+template 
+void Foo::Bar(void* aRawPtr) { // expected-error {{no template named 'Foo'}}
+(void)(aRawPtr);
+}
+
+namespace baz {
+  class klass {};
+}
+
+int *variable = 0; // ok
+const baz::klass object; // ok
Index: clang/test/Parser/cxx-namespace-after-missing-semicolon.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx-namespace-after-missing-semicolon.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -verify %s
+
+UNKNOWN_MACRO_1("z", 1) // expected-error {{a type specifier is required for 
all declarations}}
+// expected-error@-1 {{expected ';' after top level declarator}}
+
+namespace foo {
+  class bar {};
+}
+
+int variable = 0; // ok
+foo::bar something; // ok
+
+UNKNOWN_MACRO_2(void) // expected-error {{a type specifier is required for all 
declarations}}
+// expected-error@-1 {{expected ';' after top level declarator}}
+
+namespace baz {
+  using Bool = bool;
+}
+
+int variable2 = 2; // ok
+const baz::Bool flag = false;  // ok
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -275,10 +275,7 @@
 
   // Error parsing the declarator?
   if (!DeclaratorInfo.hasName()) {
-// If so, skip until the semi-colon or a }.
-SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
-if (Tok.is(tok::semi))
-  ConsumeToken();
+SkipMalformedDecl();
 return nullptr;
   }
 
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2176,7 +2176,8 @@
   return Actions.ConvertDeclToDeclGroup(TheDecl);
 }
 
-if (isDeclarationSpecifier(ImplicitTypenameContext::No)) {
+if (isDeclarationSpecifier(ImplicitTypenameContext::No) ||
+Tok.is(tok::kw_namespace)) {
   // If there is an invalid declaration specifier right after the
   // function prototype, then we must be in a missing semicolon case
   // where this isn't actually a body.  Just fall through into the code
@@ -2304,8 +2305,7 @@
 // declaration specifier, just assume it was missing and continue parsing.
 // Otherwise things are very confused and we skip to recover.
 if (!isDeclarationSpecifier(ImplicitTypenameContext::No)) {
-  SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
-  TryConsumeToken(tok::semi);
+  SkipMalformedDecl();
 }
   }
 


Index: clang/test/Parser/cxx-template-recovery.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx-template-recovery.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify %s
+
+template 
+void Foo::Bar(void* aRawPtr) { // expected-error {{no template named 'Foo'}}
+(void)(aRawPtr);
+}
+
+namespace baz {
+  class klass {};
+}
+
+int *variable = 0; // ok
+const baz::klass object; // ok
Index: clang/test/Parser/cxx-namespace-after-missing-semicolon.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx-namespace-after-missing-semicolon.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -verify %s
+
+UNKNOWN_MAC

[clang] b6c7177 - [C++20] [Modules] Don't generate unused variables in other module units

2023-05-10 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-05-10T17:41:58+08:00
New Revision: b6c7177145bc439c712208bfbe041db212c5262d

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

LOG: [C++20] [Modules] Don't generate unused variables in other module units
even if its initializer has side effects

Close https://github.com/llvm/llvm-project/issues/61892

The variables whose initializer has side effects will be emitted even if
it is not used. But it shouldn't be true after we introduced modules.
The variables in other modules shouldn't be emitted if it is not used
even if its initializer has size effects.

Also this patch rename `Decl::isInCurrentModuleUnit` to
`Decl::isInAnotherModuleUnit` to make it closer to the semantics.

Added: 
clang/test/Modules/pr61892.cppm

Modified: 
clang/include/clang/AST/DeclBase.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 571f1f10387bf..65215dbf70551 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -645,7 +645,7 @@ class alignas(8) Decl {
   }
 
   /// Whether this declaration comes from another module unit.
-  bool isInCurrentModuleUnit() const;
+  bool isInAnotherModuleUnit() const;
 
   /// FIXME: Implement discarding declarations actually in global module
   /// fragment. See [module.global.frag]p3,4 for details.

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 3441c069b4b83..b9919073e8267 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -11926,6 +11926,10 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
   !isMSStaticDataMemberInlineDefinition(VD))
 return false;
 
+  // Variables in other module units shouldn't be forced to be emitted.
+  if (VD->isInAnotherModuleUnit())
+return false;
+
   // Variables that can be needed in other TUs are required.
   auto Linkage = GetGVALinkageForVariable(VD);
   if (!isDiscardableGVALinkage(Linkage))

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index fe458b67dcab0..834beef49a444 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1023,24 +1023,26 @@ bool Decl::isInExportDeclContext() const {
   return DC && isa(DC);
 }
 
-bool Decl::isInCurrentModuleUnit() const {
+bool Decl::isInAnotherModuleUnit() const {
   auto *M = getOwningModule();
 
   if (!M)
-return true;
+return false;
 
   M = M->getTopLevelModule();
   // FIXME: It is problematic if the header module lives in another module
   // unit. Consider to fix this by techniques like
   // ExternalASTSource::hasExternalDefinitions.
   if (M->isHeaderLikeModule())
-return true;
+return false;
 
+  // A global module without parent implies that we're parsing the global
+  // module. So it can't be in another module unit.
   if (M->isGlobalModule())
-return true;
+return false;
 
   assert(M->isModulePurview() && "New module kind?");
-  return M == getASTContext().getCurrentNamedModule();
+  return M != getASTContext().getCurrentNamedModule();
 }
 
 static Decl::Kind getKind(const Decl *D) { return D->getKind(); }

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index b59ee727d267b..6621ebddf58d0 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1909,7 +1909,7 @@ bool LookupResult::isReachableSlow(Sema &SemaRef, 
NamedDecl *D) {
   if (DeclModule->isHeaderLikeModule())
 return false;
 
-  if (D->isInCurrentModuleUnit())
+  if (!D->isInAnotherModuleUnit())
 return true;
 
   // [module.reach]/p3:
@@ -3889,7 +3889,7 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, 
SourceLocation Loc,
"bad export context");
 // .. are attached to a named module M, do not appear in the
 // translation unit containing the point of the lookup..
-if (!D->isInCurrentModuleUnit() &&
+if (D->isInAnotherModuleUnit() &&
 llvm::any_of(AssociatedClasses, [&](auto *E) {
   // ... and have the same innermost enclosing non-inline
   // namespace scope as a declaration of an associated entity

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 419adff028c28..7f3e78c89f57a 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6543,7 +6543,7 @@ void Sema::AddOverloadCandidate(
   }
 
   // Functions with internal linkage are only viable in the same module unit.
-  if (getLangOpts().CPlusPlusModules && !Function->isInCurrentModul

[clang] 48bbc64 - [NFC] [C++20] [Modules] Code cleanups when checking modules in ADL

2023-05-10 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-05-10T17:53:47+08:00
New Revision: 48bbc64a8ff5e3777a76a02cffd94b3786b93203

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

LOG: [NFC] [C++20] [Modules] Code cleanups when checking modules in ADL

The original code uses getTopLevelModuleName to compare if the module
matches. This is an overkill. Since in one program there will only be at
most one module name. So it is good enough to compare the module
directly. So that we can save some string comparisons.

Added: 


Modified: 
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 6621ebddf58d..537c09723919 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -3894,9 +3894,7 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, 
SourceLocation Loc,
   // ... and have the same innermost enclosing non-inline
   // namespace scope as a declaration of an associated entity
   // attached to M
-  if (!E->hasOwningModule() ||
-  E->getOwningModule()->getTopLevelModuleName() !=
-  FM->getTopLevelModuleName())
+  if (E->getOwningModule() != FM)
 return false;
   // TODO: maybe this could be cached when generating the
   // associated namespaces / entities.



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


[PATCH] D150257: [clangd] Initialize clang-tidy modules only once

2023-05-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 520948.
kadircet marked 4 inline comments as done.
kadircet added a comment.

- Move ReplayPreambleTests to its own file and move registry to global scope.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150257

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp

Index: clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp
@@ -0,0 +1,166 @@
+//===-- ReplayPreambleTests.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
+//
+//===--===//
+//
+// These tests cover clangd's logic to replay PP events from preamble to
+// clang-tidy checks.
+//
+//===--===//
+
+#include "../../clang-tidy/ClangTidyCheck.h"
+#include "../../clang-tidy/ClangTidyModule.h"
+#include "../../clang-tidy/ClangTidyModuleRegistry.h"
+#include "AST.h"
+#include "Diagnostics.h"
+#include "ParsedAST.h"
+#include "SourceCode.h"
+#include "TestTU.h"
+#include "TidyProvider.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/Basic/FileEntry.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/Module.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Syntax/Tokens.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Registry.h"
+#include "llvm/Testing/Annotations/Annotations.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+namespace clang::clangd {
+namespace {
+struct Inclusion {
+  Inclusion(const SourceManager &SM, SourceLocation HashLoc,
+const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled,
+CharSourceRange FilenameRange)
+  : HashOffset(SM.getDecomposedLoc(HashLoc).second), IncTok(IncludeTok),
+IncDirective(IncludeTok.getIdentifierInfo()->getName()),
+FileNameOffset(SM.getDecomposedLoc(FilenameRange.getBegin()).second),
+FileName(FileName), IsAngled(IsAngled) {
+EXPECT_EQ(
+toSourceCode(SM, FilenameRange.getAsRange()).drop_back().drop_front(),
+FileName);
+  }
+  size_t HashOffset;
+  syntax::Token IncTok;
+  llvm::StringRef IncDirective;
+  size_t FileNameOffset;
+  llvm::StringRef FileName;
+  bool IsAngled;
+};
+static std::vector Includes;
+static std::vector SkippedFiles;
+struct ReplayPreamblePPCallback : public PPCallbacks {
+  const SourceManager &SM;
+  explicit ReplayPreamblePPCallback(const SourceManager &SM) : SM(SM) {}
+
+  void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
+  StringRef FileName, bool IsAngled,
+  CharSourceRange FilenameRange, OptionalFileEntryRef,
+  StringRef, StringRef, const clang::Module *,
+  SrcMgr::CharacteristicKind) override {
+Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled,
+  FilenameRange);
+  }
+
+  void FileSkipped(const FileEntryRef &, const Token &FilenameTok,
+   SrcMgr::CharacteristicKind) override {
+SkippedFiles.emplace_back(FilenameTok);
+  }
+};
+struct ReplayPreambleCheck : public tidy::ClangTidyCheck {
+  ReplayPreambleCheck(StringRef Name, tidy::ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override {
+PP->addPPCallbacks(::std::make_unique(SM));
+  }
+};
+llvm::StringLiteral CheckName = "replay-preamble-check";
+struct ReplayPreambleModule : public tidy::ClangTidyModule {
+  void
+  addCheckFactories(tidy::ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(CheckName);
+  }
+};
+static tidy::ClangTidyModuleRegistry::Add
+X("replay-preamble-module", "");
+
+MATCHER_P(rangeIs, R, "") {
+  return arg.beginOffset() == R.Begin && arg.endOffset() == R.End;
+}
+
+TEST(ReplayPreambleTest, IncludesAndSkippedFiles) {
+  TestTU TU;
+  // This check records inclusion directives replayed by clangd.
+  TU.ClangTidyProvider = addTidyChecks(CheckName);
+  llvm::Annotations Test(R"cp

[PATCH] D150254: [tidy] Fix possible use-after-free in IdentifierNamingCheck

2023-05-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D150254#4331738 , @njames93 wrote:

> In D150254#4331640 , @kadircet 
> wrote:
>
>> see 
>> https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/ClangTidy.cpp#L638
>>  for such a pattern, clangd also initializes checks with a similar approach.
>
> In this example the factory outlives the check so there is no possible use 
> after free.

Sorry you're right, I thought checks created in 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/ClangTidy.cpp#L660
 would become part of the return value, but instead they're dropped on the 
floor.
but nevertheless, clangd has this pattern in 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/ParsedAST.cpp#L479.
 I am happy to change the pattern in clangd as well, but I don't think there's 
anything requiring users to keep the "factory" around in the contract.

> In regard to this change, I think that this member can actually be removed 
> entirely as we can get the name of the check using the `getID` virtual 
> function.

made it protected and used it instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150254

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


[clang-tools-extra] 62a090f - [clangd] Initialize clang-tidy modules only once

2023-05-10 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-05-10T12:32:33+02:00
New Revision: 62a090f958ce02a8035e3c9424a05dbfe25859e1

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

LOG: [clangd] Initialize clang-tidy modules only once

This is showing up on our profiles with ~100ms contribution @95th% for
buildAST latencies.
The patch is unlikely to address it all, but should help with some low-hanging
fruit.

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

Added: 
clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp

Modified: 
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/TidyProvider.cpp
clang-tools-extra/clangd/unittests/CMakeLists.txt
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index 1501a5c5f3c3b..e5a391a775389 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -9,6 +9,7 @@
 #include "ParsedAST.h"
 #include "../clang-tidy/ClangTidyCheck.h"
 #include "../clang-tidy/ClangTidyDiagnosticConsumer.h"
+#include "../clang-tidy/ClangTidyModule.h"
 #include "../clang-tidy/ClangTidyModuleRegistry.h"
 #include "AST.h"
 #include "Compiler.h"
@@ -25,7 +26,6 @@
 #include "TidyProvider.h"
 #include "clang-include-cleaner/Record.h"
 #include "index/CanonicalIncludes.h"
-#include "index/Index.h"
 #include "index/Symbol.h"
 #include "support/Logger.h"
 #include "support/Trace.h"
@@ -50,7 +50,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include 
 #include 
 #include 
 #include 
@@ -476,16 +475,19 @@ ParsedAST::build(llvm::StringRef Filename, const 
ParseInputs &Inputs,
   // diagnostics.
   if (PreserveDiags) {
 trace::Span Tracer("ClangTidyInit");
-tidy::ClangTidyCheckFactories CTFactories;
-for (const auto &E : tidy::ClangTidyModuleRegistry::entries())
-  E.instantiate()->addCheckFactories(CTFactories);
+static const auto *CTFactories = [] {
+  auto *CTFactories = new tidy::ClangTidyCheckFactories;
+  for (const auto &E : tidy::ClangTidyModuleRegistry::entries())
+E.instantiate()->addCheckFactories(*CTFactories);
+  return CTFactories;
+}();
 CTContext.emplace(std::make_unique(
 tidy::ClangTidyGlobalOptions(), ClangTidyOpts));
 CTContext->setDiagnosticsEngine(&Clang->getDiagnostics());
 CTContext->setASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(Filename);
 CTContext->setSelfContainedDiags(true);
-CTChecks = CTFactories.createChecksForLanguage(&*CTContext);
+CTChecks = CTFactories->createChecksForLanguage(&*CTContext);
 Preprocessor *PP = &Clang->getPreprocessor();
 for (const auto &Check : CTChecks) {
   Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
@@ -610,10 +612,8 @@ ParsedAST::build(llvm::StringRef Filename, const 
ParseInputs &Inputs,
 Macros = Patch->mainFileMacros();
 Marks = Patch->marks();
   }
-  auto& PP = Clang->getPreprocessor();
-  PP.addPPCallbacks(
-  std::make_unique(
-  PP, Macros));
+  auto &PP = Clang->getPreprocessor();
+  PP.addPPCallbacks(std::make_unique(PP, Macros));
 
   PP.addPPCallbacks(
   collectPragmaMarksCallback(Clang->getSourceManager(), Marks));

diff  --git a/clang-tools-extra/clangd/TidyProvider.cpp 
b/clang-tools-extra/clangd/TidyProvider.cpp
index f3ed6f08a9acb..e3a6d5af20ae2 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -8,6 +8,7 @@
 
 #include "TidyProvider.h"
 #include "../clang-tidy/ClangTidyModuleRegistry.h"
+#include "../clang-tidy/ClangTidyOptions.h"
 #include "Config.h"
 #include "support/FileCache.h"
 #include "support/Logger.h"
@@ -283,8 +284,15 @@ TidyProvider combine(std::vector Providers) {
 
 tidy::ClangTidyOptions getTidyOptionsForFile(TidyProviderRef Provider,
  llvm::StringRef Filename) {
-  tidy::ClangTidyOptions Opts = tidy::ClangTidyOptions::getDefaults();
-  Opts.Checks->clear();
+  // getDefaults instantiates all check factories, which are registered at link
+  // time. So cache the results once.
+  static const auto *DefaultOpts = [] {
+auto *Opts = new tidy::ClangTidyOptions;
+*Opts = tidy::ClangTidyOptions::getDefaults();
+Opts->Checks->clear();
+return Opts;
+  }();
+  auto Opts = *DefaultOpts;
   if (Provider)
 Provider(Opts, Filename);
   return Opts;

diff  --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt 
b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index 6d7bb59be3ab1..8d02b91fdd716 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittest

[PATCH] D150257: [clangd] Initialize clang-tidy modules only once

2023-05-10 Thread Kadir Cetinkaya 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 rG62a090f958ce: [clangd] Initialize clang-tidy modules only 
once (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150257

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp

Index: clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp
@@ -0,0 +1,166 @@
+//===-- ReplayPreambleTests.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
+//
+//===--===//
+//
+// These tests cover clangd's logic to replay PP events from preamble to
+// clang-tidy checks.
+//
+//===--===//
+
+#include "../../clang-tidy/ClangTidyCheck.h"
+#include "../../clang-tidy/ClangTidyModule.h"
+#include "../../clang-tidy/ClangTidyModuleRegistry.h"
+#include "AST.h"
+#include "Diagnostics.h"
+#include "ParsedAST.h"
+#include "SourceCode.h"
+#include "TestTU.h"
+#include "TidyProvider.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/Basic/FileEntry.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/Module.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Syntax/Tokens.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Registry.h"
+#include "llvm/Testing/Annotations/Annotations.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+namespace clang::clangd {
+namespace {
+struct Inclusion {
+  Inclusion(const SourceManager &SM, SourceLocation HashLoc,
+const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled,
+CharSourceRange FilenameRange)
+  : HashOffset(SM.getDecomposedLoc(HashLoc).second), IncTok(IncludeTok),
+IncDirective(IncludeTok.getIdentifierInfo()->getName()),
+FileNameOffset(SM.getDecomposedLoc(FilenameRange.getBegin()).second),
+FileName(FileName), IsAngled(IsAngled) {
+EXPECT_EQ(
+toSourceCode(SM, FilenameRange.getAsRange()).drop_back().drop_front(),
+FileName);
+  }
+  size_t HashOffset;
+  syntax::Token IncTok;
+  llvm::StringRef IncDirective;
+  size_t FileNameOffset;
+  llvm::StringRef FileName;
+  bool IsAngled;
+};
+static std::vector Includes;
+static std::vector SkippedFiles;
+struct ReplayPreamblePPCallback : public PPCallbacks {
+  const SourceManager &SM;
+  explicit ReplayPreamblePPCallback(const SourceManager &SM) : SM(SM) {}
+
+  void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
+  StringRef FileName, bool IsAngled,
+  CharSourceRange FilenameRange, OptionalFileEntryRef,
+  StringRef, StringRef, const clang::Module *,
+  SrcMgr::CharacteristicKind) override {
+Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled,
+  FilenameRange);
+  }
+
+  void FileSkipped(const FileEntryRef &, const Token &FilenameTok,
+   SrcMgr::CharacteristicKind) override {
+SkippedFiles.emplace_back(FilenameTok);
+  }
+};
+struct ReplayPreambleCheck : public tidy::ClangTidyCheck {
+  ReplayPreambleCheck(StringRef Name, tidy::ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override {
+PP->addPPCallbacks(::std::make_unique(SM));
+  }
+};
+llvm::StringLiteral CheckName = "replay-preamble-check";
+struct ReplayPreambleModule : public tidy::ClangTidyModule {
+  void
+  addCheckFactories(tidy::ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(CheckName);
+  }
+};
+static tidy::ClangTidyModuleRegistry::Add
+X("replay-preamble-module", "");
+
+MATCHER_P(rangeIs, R, "") {
+  return arg.beginOffset() == R.Begin && arg.endOffset() == R.End;
+}
+
+TEST(ReplayPreambleTest, IncludesAndSkippedFiles) {
+  TestTU TU;
+  // This check records inclusion directives replayed by clangd.
+  TU.ClangTidyProvider = addTidyChecks(C

[PATCH] D150192: Allow clang to emit inrange metadata when generating code for array subscripts

2023-05-10 Thread Shiva Chen via Phabricator via cfe-commits
shiva0217 added a comment.

In D150192#4330199 , @efriedma wrote:

> From what I recall, "inrange" is actually more restrictive than the normal 
> C/C++ array indexing rules.  Specifically, the bits regarding comparisons. 
> "inrange" was designed to allow splitting globals indexed using inrange.
>
> That isn't to say that functionality like this isn't useful, but we probably 
> need to call it something different.  And I'm not sure an attribute on a GEP 
> is actually the best way to represent the semantics. It might make sense to 
> use a separate intrinsic to represent this, especially given the direction of 
> https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699 .

Hi Eli,

Very appreciate your inputs. ^^
Is there any idea how the intrinsic should look like and how it associated with 
GEP before ptradd arrive?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150192

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


[clang-tools-extra] 2b240cc - [tidy] Expose getID to tidy checks

2023-05-10 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-05-10T12:50:25+02:00
New Revision: 2b240cc377b5e4f41c05d68c9a513f7d08ab69c8

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

LOG: [tidy] Expose getID to tidy checks

This also fixes a possible use-after-free in the IdentifierNamingCheck.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyCheck.h
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
index 9381b6e8becb2..17e9df96c39be 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -407,7 +407,6 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 
 private:
   void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  StringRef getID() const override { return CheckName; }
   std::string CheckName;
   ClangTidyContext *Context;
 
@@ -422,6 +421,7 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
   bool areDiagsSelfContained() const {
 return Context->areDiagsSelfContained();
   }
+  StringRef getID() const override { return CheckName; }
 };
 
 /// Read a named option from the ``Context`` and parse it as a bool.

diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 9561b2b00904f..0e16edc10a953 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -14,6 +14,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -396,7 +397,7 @@ std::string 
IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
 
 IdentifierNamingCheck::IdentifierNamingCheck(StringRef Name,
  ClangTidyContext *Context)
-: RenamerClangTidyCheck(Name, Context), Context(Context), CheckName(Name),
+: RenamerClangTidyCheck(Name, Context), Context(Context),
   GetConfigPerFile(Options.get("GetConfigPerFile", true)),
   IgnoreFailedSplit(Options.get("IgnoreFailedSplit", false)) {
 
@@ -1461,6 +1462,7 @@ IdentifierNamingCheck::getStyleForFile(StringRef 
FileName) const {
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
+  llvm::StringRef CheckName = getID();
   ClangTidyOptions Options = Context->getOptionsForFile(FileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(

diff  --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
index 3df15ad780180..2e3d4ea8c39c8 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
@@ -11,6 +11,7 @@
 
 #include "../utils/RenamerClangTidyCheck.h"
 #include 
+#include 
 namespace clang::tidy {
 namespace readability {
 
@@ -202,7 +203,6 @@ class IdentifierNamingCheck final : public 
RenamerClangTidyCheck {
   mutable llvm::StringMap NamingStylesCache;
   FileStyle *MainFileStyle;
   ClangTidyContext *Context;
-  const StringRef CheckName;
   const bool GetConfigPerFile;
   const bool IgnoreFailedSplit;
   HungarianNotation HungarianNotation;



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


[PATCH] D150254: [tidy] Fix possible use-after-free in IdentifierNamingCheck

2023-05-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2b240cc377b5: [tidy] Expose getID to tidy checks (authored 
by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150254

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h


Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
@@ -11,6 +11,7 @@
 
 #include "../utils/RenamerClangTidyCheck.h"
 #include 
+#include 
 namespace clang::tidy {
 namespace readability {
 
@@ -202,7 +203,6 @@
   mutable llvm::StringMap NamingStylesCache;
   FileStyle *MainFileStyle;
   ClangTidyContext *Context;
-  const StringRef CheckName;
   const bool GetConfigPerFile;
   const bool IgnoreFailedSplit;
   HungarianNotation HungarianNotation;
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -14,6 +14,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -396,7 +397,7 @@
 
 IdentifierNamingCheck::IdentifierNamingCheck(StringRef Name,
  ClangTidyContext *Context)
-: RenamerClangTidyCheck(Name, Context), Context(Context), CheckName(Name),
+: RenamerClangTidyCheck(Name, Context), Context(Context),
   GetConfigPerFile(Options.get("GetConfigPerFile", true)),
   IgnoreFailedSplit(Options.get("IgnoreFailedSplit", false)) {
 
@@ -1461,6 +1462,7 @@
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
+  llvm::StringRef CheckName = getID();
   ClangTidyOptions Options = Context->getOptionsForFile(FileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
Index: clang-tools-extra/clang-tidy/ClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -407,7 +407,6 @@
 
 private:
   void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  StringRef getID() const override { return CheckName; }
   std::string CheckName;
   ClangTidyContext *Context;
 
@@ -422,6 +421,7 @@
   bool areDiagsSelfContained() const {
 return Context->areDiagsSelfContained();
   }
+  StringRef getID() const override { return CheckName; }
 };
 
 /// Read a named option from the ``Context`` and parse it as a bool.


Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
@@ -11,6 +11,7 @@
 
 #include "../utils/RenamerClangTidyCheck.h"
 #include 
+#include 
 namespace clang::tidy {
 namespace readability {
 
@@ -202,7 +203,6 @@
   mutable llvm::StringMap NamingStylesCache;
   FileStyle *MainFileStyle;
   ClangTidyContext *Context;
-  const StringRef CheckName;
   const bool GetConfigPerFile;
   const bool IgnoreFailedSplit;
   HungarianNotation HungarianNotation;
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -14,6 +14,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -396,7 +397,7 @@
 
 IdentifierNamingCheck::IdentifierNamingCheck(StringRef Name,
  ClangTidyContext *Context)
-: RenamerClangTidyCheck(Name, Context), Context(Context), CheckName(Name),
+: RenamerClangTidyCheck(Name, Context), Context(Context),
   GetConfigPerFile(Options.get("GetConfigPerFile", true)),
   IgnoreFailedSplit(Options.get("IgnoreFailedSplit", false)) {
 
@@ -1461,6 +1462,7 @@
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
+  llvm::StringRef CheckName = getID();
   ClangTidyOptions Options = Co

[PATCH] D150209: [clang][Interp] Add more shift error checking

2023-05-10 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 520954.

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

https://reviews.llvm.org/D150209

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/shifts.cpp


Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -152,4 +152,14 @@
   constexpr signed int R = (sizeof(unsigned) * 8) + 1;
   constexpr decltype(L) M  = (R > 32 && R < 64) ?  L << R : 0;
   constexpr decltype(L) M2 = (R > 32 && R < 64) ?  L >> R : 0;
+
+
+  constexpr int signedShift() { // cxx17-error {{never produces a constant 
expression}} \
+// ref-cxx17-error {{never produces a constant 
expression}}
+return 1024 << 31; // cxx17-warning {{signed shift result}} \
+   // ref-cxx17-warning {{signed shift result}} \
+   // cxx17-note {{signed left shift discards bits}} \
+   // ref-cxx17-note {{signed left shift discards bits}}
+  }
+
 };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -109,8 +109,9 @@
 bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
 
 /// Checks if the shift operation is legal.
-template 
-bool CheckShift(InterpState &S, CodePtr OpPC, const RT &RHS, unsigned Bits) {
+template 
+bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
+unsigned Bits) {
   if (RHS.isNegative()) {
 const SourceInfo &Loc = S.Current->getSource(OpPC);
 S.CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
@@ -125,6 +126,16 @@
 QualType Ty = E->getType();
 S.CCEDiag(E, diag::note_constexpr_large_shift) << Val << Ty << Bits;
 return false;
+  } else if (LHS.isSigned() && !S.getLangOpts().CPlusPlus20) {
+const Expr *E = S.Current->getExpr(OpPC);
+// C++11 [expr.shift]p2: A signed left shift must have a non-negative
+// operand, and must not overflow the corresponding unsigned type.
+// C++2a [expr.shift]p2: E1 << E2 is the unique value congruent to
+// E1 x 2^E2 module 2^N.
+if (LHS.isNegative())
+  S.CCEDiag(E, diag::note_constexpr_lshift_of_negative) << LHS.toAPSInt();
+else if (LHS.toUnsigned().countLeadingZeros() < static_cast(RHS))
+  S.CCEDiag(E, diag::note_constexpr_lshift_discards);
   }
   return true;
 }
@@ -1612,7 +1623,7 @@
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;
@@ -1629,7 +1640,7 @@
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -127,7 +127,11 @@
 return Compare(V, RHS.V);
   }
 
-  unsigned countLeadingZeros() const { return llvm::countl_zero(V); }
+  unsigned countLeadingZeros() const {
+if constexpr (!Signed)
+  return llvm::countl_zero(V);
+llvm_unreachable("Don't call countLeadingZeros() on signed types.");
+  }
 
   Integral truncate(unsigned TruncBits) const {
 if (TruncBits >= Bits)


Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -152,4 +152,14 @@
   constexpr signed int R = (sizeof(unsigned) * 8) + 1;
   constexpr decltype(L) M  = (R > 32 && R < 64) ?  L << R : 0;
   constexpr decltype(L) M2 = (R > 32 && R < 64) ?  L >> R : 0;
+
+
+  constexpr int signedShift() { // cxx17-error {{never produces a constant expression}} \
+// ref-cxx17-error {{never produces a constant expression}}
+return 1024 << 31; // cxx17-warning {{signed shift result}} \
+   // ref-cxx17-warning {{signed shift result}} \
+   // cxx17-note {{signed left shift discards bits}} \
+   // ref-cxx17-note {{signed left shift discards bits}}
+  }
+
 };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -109,8 +109,9 @@
 bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
 
 /// Checks if the shift operation is legal.
-template 
-bool CheckShift(InterpState &S, CodePtr OpPC, const RT &RHS, unsigned Bits) {
+template 
+bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
+unsigned Bi

[clang] d526e2e - Add -no-canonical-prefixes to test that matches the binary name

2023-05-10 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2023-05-10T13:17:35+02:00
New Revision: d526e2ec957fc7bc31d7be3670cd1673c2b4389b

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

LOG: Add -no-canonical-prefixes to test that matches the binary name

Added: 


Modified: 
clang/test/Driver/ftime-trace.cpp

Removed: 




diff  --git a/clang/test/Driver/ftime-trace.cpp 
b/clang/test/Driver/ftime-trace.cpp
index 42a969059101..16c7ad53c69e 100644
--- a/clang/test/Driver/ftime-trace.cpp
+++ b/clang/test/Driver/ftime-trace.cpp
@@ -1,18 +1,18 @@
 // RUN: rm -rf %t && mkdir -p %t && cd %t
-// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o out %s
+// RUN: %clangxx -S -no-canonical-prefixes -ftime-trace 
-ftime-trace-granularity=0 -o out %s
 // RUN: cat out.json \
 // RUN:   | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
-// RUN: %clangxx -S -ftime-trace=new-name.json -ftime-trace-granularity=0 -o 
out %s
+// RUN: %clangxx -S -no-canonical-prefixes -ftime-trace=new-name.json 
-ftime-trace-granularity=0 -o out %s
 // RUN: cat new-name.json \
 // RUN:   | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
 // RUN: mkdir dir1 dir2
-// RUN: %clangxx -S -ftime-trace=dir1 -ftime-trace-granularity=0 -o out %s
+// RUN: %clangxx -S -no-canonical-prefixes -ftime-trace=dir1 
-ftime-trace-granularity=0 -o out %s
 // RUN: cat dir1/out.json \
 // RUN:   | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
-// RUN: %clangxx -S -ftime-trace=dir2/ -ftime-trace-granularity=0 -o out %s
+// RUN: %clangxx -S -no-canonical-prefixes -ftime-trace=dir2/ 
-ftime-trace-granularity=0 -o out %s
 // RUN: cat dir2/out.json \
 // RUN:   | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s



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


[PATCH] D149997: [clang] [test] Narrow down MSVC specific behaviours from "any windows" to only MSVC/clang-cl

2023-05-10 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This broke check-clang on windows: http://45.33.8.238/win/78359/step_7.txt

(The Driver/split-debug.c failure is something else and since fixed, but the 
other two tests are due to this change.)

Please take a look and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149997

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


[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

2023-05-10 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

One of the buildbot failures is the test you modified (\dr1xx.c), so I suspect 
it is related.

I THINK this needs a notice on the 'breaking changes' mailing list as well.

For release notes, I'd put it in the 'Potentially Breaking Changes' section.


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

https://reviews.llvm.org/D150226

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


[clang] 34b422b - clang-format: [JS] support import/export type

2023-05-10 Thread Krasimir Georgiev via cfe-commits

Author: Jan Kuhle
Date: 2023-05-10T15:27:03+02:00
New Revision: 34b422bafbd934ee3c644fd7a8f0b6803976c818

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

LOG: clang-format: [JS] support import/export type

Contributed by @jankuehle!

Users can choose to only import/export the type of the symbol (not value nor 
namespace) by adding a `type` keyword, e.g.:

```
import type {x} from 'y';
import {type x} from 'y';
export type {x};
export {type x};
```

Previously, this was not handled and would:
- Terminate import sorting
- Remove the space before the curly bracket in `export type {`

With this change, both formatting and import sorting work as expected.

Reviewed By: MyDeveloperDay, krasimir

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

Added: 


Modified: 
clang/lib/Format/SortJavaScriptImports.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestJS.cpp
clang/unittests/Format/SortImportsTestJS.cpp

Removed: 




diff  --git a/clang/lib/Format/SortJavaScriptImports.cpp 
b/clang/lib/Format/SortJavaScriptImports.cpp
index ce83ddea3e076..af2d3400c970d 100644
--- a/clang/lib/Format/SortJavaScriptImports.cpp
+++ b/clang/lib/Format/SortJavaScriptImports.cpp
@@ -72,6 +72,7 @@ struct JsImportedSymbol {
 struct JsModuleReference {
   bool FormattingOff = false;
   bool IsExport = false;
+  bool IsTypeOnly = false;
   // Module references are sorted into these categories, in order.
   enum ReferenceCategory {
 SIDE_EFFECT, // "import 'something';"
@@ -306,6 +307,7 @@ class JavaScriptImportSorter : public TokenAnalyzer {
   if (Reference->Category == JsModuleReference::SIDE_EFFECT ||
   PreviousReference->Category == JsModuleReference::SIDE_EFFECT ||
   Reference->IsExport != PreviousReference->IsExport ||
+  Reference->IsTypeOnly != PreviousReference->IsTypeOnly ||
   !PreviousReference->Prefix.empty() || !Reference->Prefix.empty() ||
   !PreviousReference->DefaultImport.empty() ||
   !Reference->DefaultImport.empty() || Reference->Symbols.empty() ||
@@ -488,6 +490,11 @@ class JavaScriptImportSorter : public TokenAnalyzer {
   bool parseStarBinding(const AdditionalKeywords &Keywords,
 JsModuleReference &Reference) {
 // * as prefix from '...';
+if (Current->is(Keywords.kw_type) && Current->Next &&
+Current->Next->is(tok::star)) {
+  Reference.IsTypeOnly = true;
+  nextToken();
+}
 if (Current->isNot(tok::star))
   return false;
 nextToken();
@@ -503,6 +510,12 @@ class JavaScriptImportSorter : public TokenAnalyzer {
 
   bool parseNamedBindings(const AdditionalKeywords &Keywords,
   JsModuleReference &Reference) {
+if (Current->is(Keywords.kw_type) && Current->Next &&
+Current->Next->isOneOf(tok::identifier, tok::l_brace)) {
+  Reference.IsTypeOnly = true;
+  nextToken();
+}
+
 // eat a potential "import X, " prefix.
 if (Current->is(tok::identifier)) {
   Reference.DefaultImport = Current->TokenText;
@@ -535,14 +548,19 @@ class JavaScriptImportSorter : public TokenAnalyzer {
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  if (!Current->isOneOf(tok::identifier, tok::kw_default))
+  bool isTypeOnly =
+  Current->is(Keywords.kw_type) && Current->Next &&
+  Current->Next->isOneOf(tok::identifier, tok::kw_default);
+  if (!isTypeOnly && !Current->isOneOf(tok::identifier, tok::kw_default))
 return false;
 
   JsImportedSymbol Symbol;
-  Symbol.Symbol = Current->TokenText;
   // Make sure to include any preceding comments.
   Symbol.Range.setBegin(
   Current->getPreviousNonComment()->Next->WhitespaceRange.getBegin());
+  if (isTypeOnly)
+nextToken();
+  Symbol.Symbol = Current->TokenText;
   nextToken();
 
   if (Current->is(Keywords.kw_as)) {

diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 2e5bdf96deb88..64035b0976f55 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4068,7 +4068,9 @@ void 
UnwrappedLineParser::parseJavaScriptEs6ImportExport() {
   // parsing the structural element, i.e. the declaration or expression for
   // `export default`.
   if (!IsImport && !FormatTok->isOneOf(tok::l_brace, tok::star) &&
-  !FormatTok->isStringLiteral()) {
+  !FormatTok->isStringLiteral() &&
+  !(FormatTok->is(Keywords.kw_type) &&
+Tokens->peekNextToken()->isOneOf(tok::l_brace, tok::star))) {
 return;
   }
 

diff  --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 6f07d8b084f56..ce81b

[PATCH] D150116: clang-format: [JS] support import/export type

2023-05-10 Thread Krasimir Georgiev 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 rG34b422bafbd9: clang-format: [JS] support import/export type 
(authored by jankuehle, committed by krasimir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150116

Files:
  clang/lib/Format/SortJavaScriptImports.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestJS.cpp
  clang/unittests/Format/SortImportsTestJS.cpp

Index: clang/unittests/Format/SortImportsTestJS.cpp
===
--- clang/unittests/Format/SortImportsTestJS.cpp
+++ clang/unittests/Format/SortImportsTestJS.cpp
@@ -465,6 +465,46 @@
  "console.log(Z);\n");
 }
 
+TEST_F(SortImportsTestJS, ImportExportType) {
+  verifySort("import type {sym} from 'a';\n"
+ "import {type sym} from 'b';\n"
+ "import {sym} from 'c';\n"
+ "import type sym from 'd';\n"
+ "import type * as sym from 'e';\n"
+ "\n"
+ "let x = 1;",
+ "import {sym} from 'c';\n"
+ "import type {sym} from 'a';\n"
+ "import type * as sym from 'e';\n"
+ "import type sym from 'd';\n"
+ "import {type sym} from 'b';\n"
+ "let x = 1;");
+
+  // Symbols within import statement
+  verifySort("import {type sym1, type sym2 as a, sym3} from 'b';\n",
+ "import {type sym2 as a, type sym1, sym3} from 'b';\n");
+
+  // Merging
+  verifySort("import {X, type Z} from 'a';\n"
+ "import type {Y} from 'a';\n"
+ "\n"
+ "X + Y + Z;\n",
+ "import {X} from 'a';\n"
+ "import {type Z} from 'a';\n"
+ "import type {Y} from 'a';\n"
+ "\n"
+ "X + Y + Z;\n");
+
+  // Merging: empty imports
+  verifySort("import type {A} from 'foo';\n", "import type {} from 'foo';\n"
+  "import type {A} from 'foo';");
+
+  // Merging: exports
+  verifySort("export {A, type B} from 'foo';\n",
+ "export {A} from 'foo';\n"
+ "export   {type B} from 'foo';");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -1476,6 +1476,17 @@
" export class Y {}");
 }
 
+TEST_F(FormatTestJS, ImportExportType) {
+  verifyFormat("import type {x, y} from 'y';\n"
+   "import type * as x from 'y';\n"
+   "import type x from 'y';\n"
+   "import {x, type yu, z} from 'y';\n");
+  verifyFormat("export type {x, y} from 'y';\n"
+   "export {x, type yu, z} from 'y';\n"
+   "export type {x, y};\n"
+   "export {x, type yu, z};\n");
+}
+
 TEST_F(FormatTestJS, ClosureStyleCasts) {
   verifyFormat("var x = /** @type {foo} */ (bar);");
 }
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -4068,7 +4068,9 @@
   // parsing the structural element, i.e. the declaration or expression for
   // `export default`.
   if (!IsImport && !FormatTok->isOneOf(tok::l_brace, tok::star) &&
-  !FormatTok->isStringLiteral()) {
+  !FormatTok->isStringLiteral() &&
+  !(FormatTok->is(Keywords.kw_type) &&
+Tokens->peekNextToken()->isOneOf(tok::l_brace, tok::star))) {
 return;
   }
 
Index: clang/lib/Format/SortJavaScriptImports.cpp
===
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -72,6 +72,7 @@
 struct JsModuleReference {
   bool FormattingOff = false;
   bool IsExport = false;
+  bool IsTypeOnly = false;
   // Module references are sorted into these categories, in order.
   enum ReferenceCategory {
 SIDE_EFFECT, // "import 'something';"
@@ -306,6 +307,7 @@
   if (Reference->Category == JsModuleReference::SIDE_EFFECT ||
   PreviousReference->Category == JsModuleReference::SIDE_EFFECT ||
   Reference->IsExport != PreviousReference->IsExport ||
+  Reference->IsTypeOnly != PreviousReference->IsTypeOnly ||
   !PreviousReference->Prefix.empty() || !Reference->Prefix.empty() ||
   !PreviousReference->DefaultImport.empty() ||
   !Reference->DefaultImport.empty() || Reference->Symbols.empty() ||
@@ -488,6 +490,11 @@
   bool parseStarBinding(const AdditionalKeywords &Keywords,
 JsModuleReference &Reference) {
 // * as prefix from '...';
+if (Current->is(Keywords.kw_t

[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

2023-05-10 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D150226#4332024 , @erichkeane 
wrote:

> One of the buildbot failures is the test you modified (\dr1xx.c), so I 
> suspect it is related.
>
> I THINK this needs a notice on the 'breaking changes' mailing list as well.
>
> For release notes, I'd put it in the 'Potentially Breaking Changes' section.

Interestingly, my downstream noticed both of those same two tests failing, so I 
think you're right.  I have no idea why I thought you'd modified dr1xx.c?  No 
idea what I was thinking, so disregard.  So just the 'breaking changes' mailing 
list, and the release notes for me are needed.


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

https://reviews.llvm.org/D150226

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


[PATCH] D150221: Add option -fkeep-static-variables to emit all static variables

2023-05-10 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a subscriber: aaron.ballman.
erichkeane added a comment.

In D150221#4330534 , 
@hubert.reinterpretcast wrote:

> In D150221#4330504 , @MaskRay wrote:
>
>> Can you give a more compelling reason that this option is needed?
>
> This is intended to prevent "excessive transformation" to enable migration of 
> existing applications (using a non-Clang compiler) where users further 
> manipulate the object or assembly after compilation.

I don't get what you mean by this?  I don't currently see motivation for this?  
@aaron.ballman would have to make a decision here eventually, but I don't think 
he'd be compelled by this either.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150221

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


[PATCH] D149612: [Sema] avoid merge error type

2023-05-10 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

@aaron.ballman : Can you comment, particularly on the 'x2' and 'x3' examples 
here?  I think our hackery here to get the AST back in a reasonable position 
here is unfortunate, and leads to some pretty awkward errors.  I'm not sure 
what else we could do?

We can't make it a dependent type, as it can then not be merged correctly.
We can't really make it a variable array type, since we would then have those 
types in places where it isn't 'legal'.
We would have a perhaps similar problem with the incomplete array type as the 
VLA, but at least we would diagnose `char[]`, right?

My original thoughts were to make this still be a constant-array-type, keeping 
the 'error' size expression, but with a '1' for the extent, but I'm second 
guessing here based on those errors.




Comment at: clang/test/Sema/merge-decls.c:101
+char x3[sizeof(d.data) == 8]; // expected-error {{member reference base type 
'char' is not a structure or union}}
+char x3[1];

Newline at end of file still needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149612

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


[PATCH] D149562: [clang-format] Stop comment disrupting indentation of Verilog ports

2023-05-10 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

> IMO a trailing comment (empty or not) belongs to the code before it.

There is only a parenthesis before it.  It doesn't usually need a comment.  It 
is like in 5a61139.  One doesn't tend to comment a single brace.

> A comment about the code below it should start on a new line.

In this special case, the comment would be indented to the same column as the 
next line, so it should be clear it is for the next line.  Like the case 
forbraced initializer lists, the first field will be on the same line as the 
brace if there isn't a comment, so the first comment is also on the same line 
as the brace when there is one.

  foo foo{// first field
  a,
  // second field
  b};


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149562

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


[clang] ddfb974 - Add support of the next Ubuntu (Ubuntu 23.10 - Mantic Minotaur)

2023-05-10 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2023-05-10T16:31:53+02:00
New Revision: ddfb974d0fca62e3eaeb98b79b5e29738c9082d2

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

LOG: Add support of the next Ubuntu (Ubuntu 23.10 - Mantic Minotaur)

Added: 


Modified: 
clang/include/clang/Driver/Distro.h
clang/lib/Driver/Distro.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Distro.h 
b/clang/include/clang/Driver/Distro.h
index 0c858b3d716f1..8291f6575a711 100644
--- a/clang/include/clang/Driver/Distro.h
+++ b/clang/include/clang/Driver/Distro.h
@@ -77,6 +77,7 @@ class Distro {
 UbuntuJammy,
 UbuntuKinetic,
 UbuntuLunar,
+UbuntuMantic,
 UnknownDistro
   };
 
@@ -128,7 +129,7 @@ class Distro {
   }
 
   bool IsUbuntu() const {
-return DistroVal >= UbuntuHardy && DistroVal <= UbuntuLunar;
+return DistroVal >= UbuntuHardy && DistroVal <= UbuntuMantic;
   }
 
   bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }

diff  --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp
index 85d82180a805c..e86b589a1cfb5 100644
--- a/clang/lib/Driver/Distro.cpp
+++ b/clang/lib/Driver/Distro.cpp
@@ -93,6 +93,7 @@ static Distro::DistroType 
DetectLsbRelease(llvm::vfs::FileSystem &VFS) {
 .Case("jammy", Distro::UbuntuJammy)
 .Case("kinetic", Distro::UbuntuKinetic)
 .Case("lunar", Distro::UbuntuLunar)
+.Case("mantic", Distro::UbuntuMantic)
 .Default(Distro::UnknownDistro);
   return Version;
 }



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


[clang] 56bac6c - Revert "[clang] [test] Narrow down MSVC specific behaviours from "any windows" to only MSVC/clang-cl"

2023-05-10 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2023-05-10T16:49:18+02:00
New Revision: 56bac6c87a2d9046dbac36aae4910b4b90edf643

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

LOG: Revert "[clang] [test] Narrow down MSVC specific behaviours from "any 
windows" to only MSVC/clang-cl"

This reverts commit 7f037e5645bd62fca6fc7c3e77962aafe2bc8b27.
Breaks tests, see https://reviews.llvm.org/D149997#4331937

Added: 


Modified: 
clang/test/C/drs/dr1xx.c
clang/test/Driver/experimental-library-flag.cpp
clang/test/SemaCXX/attr-trivial-abi.cpp

Removed: 




diff  --git a/clang/test/C/drs/dr1xx.c b/clang/test/C/drs/dr1xx.c
index 6bbeb02408c7a..400807ed5da84 100644
--- a/clang/test/C/drs/dr1xx.c
+++ b/clang/test/C/drs/dr1xx.c
@@ -235,7 +235,7 @@ void dr118(void) {
 * type at this point.
 */
 Val = sizeof(enum E)
-#ifndef _MSC_VER
+#ifndef _WIN32
 /* expected-error@-2 {{invalid application of 'sizeof' to an incomplete 
type 'enum E'}} */
 /* expected-note@-12 {{definition of 'enum E' is not complete until the 
closing '}'}} */
 #endif

diff  --git a/clang/test/Driver/experimental-library-flag.cpp 
b/clang/test/Driver/experimental-library-flag.cpp
index db6a90b50f255..148cb7ed2adb0 100644
--- a/clang/test/Driver/experimental-library-flag.cpp
+++ b/clang/test/Driver/experimental-library-flag.cpp
@@ -1,6 +1,6 @@
 // On some platforms, -stdlib=libc++ is currently ignored, so 
-lc++experimental is not added.
 // Once -stdlib=libc++ works on those, this XFAIL can be removed.
-// XFAIL: target={{.*-windows-msvc.*}}, target={{.*-(ps4|ps5)}}
+// XFAIL: target={{.*-windows.*}}, target={{.*-(ps4|ps5)}}
 
 // For some reason, this fails with a core dump on AIX. This needs to be 
investigated.
 // UNSUPPORTED: target={{.*}}-aix{{.*}}

diff  --git a/clang/test/SemaCXX/attr-trivial-abi.cpp 
b/clang/test/SemaCXX/attr-trivial-abi.cpp
index 2cee3bd5dd215..deae99f7d0890 100644
--- a/clang/test/SemaCXX/attr-trivial-abi.cpp
+++ b/clang/test/SemaCXX/attr-trivial-abi.cpp
@@ -5,11 +5,11 @@ void __attribute__((trivial_abi)) foo(); // expected-warning 
{{'trivial_abi' att
 // Should not crash.
 template 
 class __attribute__((trivial_abi)) a { a(a &&); };
-#if defined(_WIN64) && defined(_MSC_VER)
-// On Windows/MSVC, to be trivial-for-calls, an object must be trivially 
copyable.
+#ifdef _WIN64
+// On Windows, to be trivial-for-calls, an object must be trivially copyable.
 // (And it is only trivially relocatable, currently, if it is trivial for 
calls.)
 // In this case, it is suppressed by an explicitly defined move constructor.
-// Similar concerns apply to later tests that have #if defined(_WIN64) && 
defined(_MSC_VER).
+// Similar concerns apply to later tests that have #ifdef _WIN64.
 static_assert(!__is_trivially_relocatable(a), "");
 #else
 static_assert(__is_trivially_relocatable(a), "");
@@ -137,7 +137,7 @@ struct __attribute__((trivial_abi)) CopyDeleted {
   CopyDeleted(const CopyDeleted &) = delete;
   CopyDeleted(CopyDeleted &&) = default;
 };
-#if defined(_WIN64) && defined(_MSC_VER)
+#ifdef _WIN64
 static_assert(!__is_trivially_relocatable(CopyDeleted), "");
 #else
 static_assert(__is_trivially_relocatable(CopyDeleted), "");
@@ -163,7 +163,7 @@ static_assert(!__is_trivially_relocatable(S19), "");
 struct __attribute__((trivial_abi)) S20 {
   int &&a; // a member of rvalue reference type deletes the copy constructor.
 };
-#if defined(_WIN64) && defined(_MSC_VER)
+#ifdef _WIN64
 static_assert(!__is_trivially_relocatable(S20), "");
 #else
 static_assert(__is_trivially_relocatable(S20), "");



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


[PATCH] D149997: [clang] [test] Narrow down MSVC specific behaviours from "any windows" to only MSVC/clang-cl

2023-05-10 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Fails with cmake too: 
https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket/8781510258907322449/+/u/package_clang/stdout?format=raw
 Reverted in 56bac6c87a2d9046dbac36aae4910b4b90edf643 
 for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149997

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


[PATCH] D127910: [Clang][AArch64][SME] Add vector load/store (ld1/st1) intrinsics

2023-05-10 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:726
 
-if (Feature == "+sme") {
-  HasSME = true;

Why did you remove this?



Comment at: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ld1.c:16
+//
+__attribute__((arm_streaming)) void test_svld1_hor_za8(uint32_t slice_base, 
svbool_t pg, const void *ptr) {
+  svld1_hor_za8(0, slice_base, 0, pg, ptr);

Hi @bryanpkc, would you be happy to remove the dependence on the attributes 
patch for now, so that we can move forward to review/land this patch series?

I'm thinking of doing something like:

  // RUN: %clang_cc1 -DDISABLE_SME_ATTRIBUTES 
  ...
  
  #ifdef DISABLE_SME_ATTRIBUTES
  #define ARM_STREAMING_ATTR
  #else
  #define ARM_STREAMING_ATTR __attribute__((arm_streaming))
  #endif
  
  ...
  
  ARM_STREAMING_ATTR void test_svld1_hor_za16(uint32_t slice_base, svbool_t pg, 
const void *ptr) {
svld1_hor_za16(0, slice_base, 0, pg, ptr);
svld1_hor_za16(1, slice_base, 7, pg, ptr);
  }

With that the tests all pass, and when the attribute patches have landed we can 
just remove the `-DDISABLE_SME_ATTRIBUTES` from the RUN lines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127910

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


[PATCH] D150221: Add option -fkeep-static-variables to emit all static variables

2023-05-10 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D150221#4332142 , @erichkeane 
wrote:

>> This is intended to prevent "excessive transformation" to enable migration 
>> of existing applications (using a non-Clang compiler) where users further 
>> manipulate the object or assembly after compilation.
>
> I don't get what you mean by this?  I don't currently see motivation for this?

The intent is to apply the `__attribute__((__used__))` semantic to static 
variables (since the front-end is likely to discard them). Additional reasons 
for using `__attribute__((__used__))` applies: The compiler cannot optimize 
with the assumption that it sees all direct accesses to the variable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150221

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


[PATCH] D146809: [clang-repl] Implement Value pretty printing

2023-05-10 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 520998.
junaire added a comment.

Export symbols in Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146809

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_interpreter_runtime_printvalue.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Interpreter/ValuePrinter.cpp
  clang/test/Interpreter/pretty-print.cpp
  clang/tools/clang-repl/CMakeLists.txt

Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -11,6 +11,65 @@
   ClangRepl.cpp
   )
 
+if(MSVC)
+  set_target_properties(clang-repl PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)
+
+  # RTTI/C++ symbols
+  set(clang_repl_exports ${clang_repl_exports} ??_7type_info@@6B@
+?__type_info_root_node@@3U__type_info_node@@A
+?nothrow@std@@3Unothrow_t@1@B
+  )
+
+  # Compiler added symbols for static variables. NOT for VStudio < 2015
+  set(clang_repl_exports ${clang_repl_exports} _Init_thread_abort _Init_thread_epoch
+_Init_thread_footer _Init_thread_header _tls_index
+  )
+
+  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+# new/delete variants needed when linking to static msvc runtime (esp. Debug)
+set(clang_repl_exports ${clang_repl_exports}
+  ??2@YAPEAX_K@Z
+  ??3@YAXPEAX@Z
+  ??_U@YAPEAX_K@Z
+  ??_V@YAXPEAX@Z
+  ??3@YAXPEAX_K@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@H@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@M@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@N@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@PEBX@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@P6AAEAV01@AEAV01@@Z@Z
+  ??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@D@Z
+  ??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z
+  ?_Facet_Register@std@@YAXPEAV_Facet_base@1@@Z
+)
+  else()
+set(clang_repl_exports ${clang_repl_exports}
+  ??2@YAPAXI@Z
+  ??3@YAXPAX@Z
+  ??3@YAXPAXI@Z
+  ??_U@YAPAXI@Z
+  ??_V@YAXPAX@Z
+  ??_V@YAXPAXI@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@M@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@N@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@PBX@Z
+  ??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z
+  ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@D@Z
+  ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z
+  ?_Facet_Register@std@@YAXPAV_Facet_base@1@@Z
+)
+  endif()
+
+  # List to '/EXPORT:sym0 /EXPORT:sym1 /EXPORT:sym2 ...'
+  foreach(sym ${clang_repl_exports})
+set(clang_repl_link_str "${clang_repl_link_str} /EXPORT:${sym}")
+  endforeach(sym ${clang_repl_exports})
+
+  set_property(TARGET clang-repl APPEND_STRING PROPERTY LINK_FLAGS ${clang_repl_link_str})
+
+endif(MSVC)
+
 clang_target_link_libraries(clang-repl PRIVATE
   clangAST
   clangBasic
Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,180 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+extern "C" int printf(const char*,...);
+
+char c = 'a';
+c
+// CHECK: (char) 'a'
+
+const char* c_str = "Goodbye, world!";
+c_str
+// CHECK-NEXT: (const char *) "Goodbye, world!"
+
+const char* c_null_str = 0;
+c_null_str
+// CHECK-NEXT: (const char *) nullptr
+
+"Hello, world"
+// CHECK-NEXT: (const char[13]) "Hello, world"
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+&x
+// CHECK-NEXT: (int *) [[Addr:@0x.*]]
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2f
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.210
+
+struct S1{};
+S1 s1;
+s1
+// CHECK-NEXT: (S1 &) [[Addr:@0x.*]]
+
+S1{}
+// CHECK-NEXT: (S1) [[Addr:@0x.*]]
+
+struct S2 {int d;} E = {22};
+E
+// CHECK-NEXT: (struct S2 &) [[Addr:@0x.*]]
+E.d
+// CHECK-NEXT: (int) 22
+
+

[PATCH] D149158: [clang][analyzer] Cleanup tests of StdCLibraryFunctionsChecker (NFC)

2023-05-10 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/test/Analysis/Inputs/std-c-library-functions.h:1-2
+typedef typeof(sizeof(int)) size_t;
+typedef signed long ssize_t;
+typedef struct {

steakhal wrote:
> balazske wrote:
> > steakhal wrote:
> > > `ssize_t`'s size should match the size of `size_t`. In this 
> > > implementation, it would be true only if `size_t` is `long`.
> > > 
> > I could not find a working way of defining the type in that way (there is 
> > no `__sizte_t`). The current definition should work well in the test code, 
> > the property of being the same size is supposedly not used in the tests. 
> > The previous definition was not better than this (and different in 
> > different places).
> I think [[ 
> https://github.com/llvm/llvm-project/blob/main/clang/test/Sema/format-strings-scanf.c#L7-L15
>  | clang/test/Sema/format-strings-scanf.c ]] uses something like this: 
> ```lang=C++
> typedef __SIZE_TYPE__ size_t;
> #define __SSIZE_TYPE__
>  \
>   __typeof__(_Generic((__SIZE_TYPE__)0,   
>  \
>   unsigned long long int : (long long int)0,  
>  \
>   unsigned long int : (long int)0,
>  \
>   unsigned int : (int)0,  
>  \
>   unsigned short : (short)0,  
>  \
>   unsigned char : (signed char)0))
> typedef __SSIZE_TYPE__ ssize_t;
> ```
This may work (probably not on all platforms) but still I think in this context 
it is only important that we have a type called `ssize_t` and it is signed, it 
is less important that it is exactly the correct type. Other types in the same 
header are not exact, and `ssize_t` in other test code (in Analysis tests) is 
defined not in this way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149158

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


[clang] 1fc7021 - AMDGPU: Add basic gfx941 target

2023-05-10 Thread Konstantin Zhuravlyov via cfe-commits

Author: Konstantin Zhuravlyov
Date: 2023-05-10T11:51:06-04:00
New Revision: 1fc70210a6a585bad941f64bd3fca7909eeafdda

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

LOG: AMDGPU: Add basic gfx941 target

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

Added: 


Modified: 
clang/include/clang/Basic/Cuda.h
clang/lib/Basic/Cuda.cpp
clang/lib/Basic/Targets/NVPTX.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/test/CodeGenOpenCL/amdgpu-features.cl
clang/test/Driver/amdgpu-macros.cl
clang/test/Driver/amdgpu-mcpu.cl
clang/test/Misc/target-invalid-cpu-note.c
llvm/docs/AMDGPUUsage.rst
llvm/include/llvm/BinaryFormat/ELF.h
llvm/include/llvm/TargetParser/TargetParser.h
llvm/lib/Object/ELFObjectFile.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/lib/Target/AMDGPU/AMDGPU.td
llvm/lib/Target/AMDGPU/GCNProcessors.td
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
llvm/lib/TargetParser/TargetParser.cpp
llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll
llvm/test/CodeGen/AMDGPU/elf-header-flags-mach.ll
llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Cuda.h 
b/clang/include/clang/Basic/Cuda.h
index 8ff28944f23d5..dddbd651054da 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -92,6 +92,7 @@ enum class CudaArch {
   GFX90a,
   GFX90c,
   GFX940,
+  GFX941,
   GFX1010,
   GFX1011,
   GFX1012,

diff  --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index b4cf6cbe95f8b..baca1106b263b 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -114,6 +114,7 @@ static const CudaArchToStringMap arch_names[] = {
 GFX(90a),  // gfx90a
 GFX(90c),  // gfx90c
 GFX(940),  // gfx940
+GFX(941),  // gfx941
 GFX(1010), // gfx1010
 GFX(1011), // gfx1011
 GFX(1012), // gfx1012

diff  --git a/clang/lib/Basic/Targets/NVPTX.cpp 
b/clang/lib/Basic/Targets/NVPTX.cpp
index 5eaa21e1a8f6a..17e38a4f1d299 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -195,6 +195,7 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   case CudaArch::GFX90a:
   case CudaArch::GFX90c:
   case CudaArch::GFX940:
+  case CudaArch::GFX941:
   case CudaArch::GFX1010:
   case CudaArch::GFX1011:
   case CudaArch::GFX1012:

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 68c4fc872e3b8..dd0ed791588a9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3580,6 +3580,7 @@ void CGOpenMPRuntimeGPU::processRequiresDirective(
   case CudaArch::GFX90a:
   case CudaArch::GFX90c:
   case CudaArch::GFX940:
+  case CudaArch::GFX941:
   case CudaArch::GFX1010:
   case CudaArch::GFX1011:
   case CudaArch::GFX1012:

diff  --git a/clang/test/CodeGenOpenCL/amdgpu-features.cl 
b/clang/test/CodeGenOpenCL/amdgpu-features.cl
index e000239cd03fe..5f452ae63925f 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features.cl
@@ -30,6 +30,7 @@
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx90a -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX90A %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx90c -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX90C %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx940 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX940 %s
+// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx941 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX941 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1010 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1010 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1011 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1011 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1012 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1012 %s
@@ -75,6 +76,7 @@
 // GFX90A: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 // GFX90C: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 // GFX940: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atom

[clang] 9d05727 - AMDGPU: Add basic gfx942 target

2023-05-10 Thread Konstantin Zhuravlyov via cfe-commits

Author: Konstantin Zhuravlyov
Date: 2023-05-10T11:51:06-04:00
New Revision: 9d0572797233857397f3fdc35fffcfb490354f56

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

LOG: AMDGPU: Add basic gfx942 target

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

Added: 


Modified: 
clang/include/clang/Basic/Cuda.h
clang/lib/Basic/Cuda.cpp
clang/lib/Basic/Targets/NVPTX.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/test/CodeGenOpenCL/amdgpu-features.cl
clang/test/Driver/amdgpu-macros.cl
clang/test/Driver/amdgpu-mcpu.cl
clang/test/Misc/target-invalid-cpu-note.c
llvm/docs/AMDGPUUsage.rst
llvm/include/llvm/BinaryFormat/ELF.h
llvm/include/llvm/TargetParser/TargetParser.h
llvm/lib/Object/ELFObjectFile.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/lib/Target/AMDGPU/AMDGPU.td
llvm/lib/Target/AMDGPU/GCNProcessors.td
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
llvm/lib/TargetParser/TargetParser.cpp
llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll
llvm/test/CodeGen/AMDGPU/elf-header-flags-mach.ll
llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Cuda.h 
b/clang/include/clang/Basic/Cuda.h
index dddbd651054da..2b8fc2a0bb1c3 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -93,6 +93,7 @@ enum class CudaArch {
   GFX90c,
   GFX940,
   GFX941,
+  GFX942,
   GFX1010,
   GFX1011,
   GFX1012,

diff  --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index baca1106b263b..db30142ad866d 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -115,6 +115,7 @@ static const CudaArchToStringMap arch_names[] = {
 GFX(90c),  // gfx90c
 GFX(940),  // gfx940
 GFX(941),  // gfx941
+GFX(942),  // gfx942
 GFX(1010), // gfx1010
 GFX(1011), // gfx1011
 GFX(1012), // gfx1012

diff  --git a/clang/lib/Basic/Targets/NVPTX.cpp 
b/clang/lib/Basic/Targets/NVPTX.cpp
index 17e38a4f1d299..cfcf4ca36f285 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -196,6 +196,7 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   case CudaArch::GFX90c:
   case CudaArch::GFX940:
   case CudaArch::GFX941:
+  case CudaArch::GFX942:
   case CudaArch::GFX1010:
   case CudaArch::GFX1011:
   case CudaArch::GFX1012:

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index dd0ed791588a9..74f8c19e1bc7e 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3581,6 +3581,7 @@ void CGOpenMPRuntimeGPU::processRequiresDirective(
   case CudaArch::GFX90c:
   case CudaArch::GFX940:
   case CudaArch::GFX941:
+  case CudaArch::GFX942:
   case CudaArch::GFX1010:
   case CudaArch::GFX1011:
   case CudaArch::GFX1012:

diff  --git a/clang/test/CodeGenOpenCL/amdgpu-features.cl 
b/clang/test/CodeGenOpenCL/amdgpu-features.cl
index 5f452ae63925f..efa5759558cc5 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features.cl
@@ -31,6 +31,7 @@
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx90c -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX90C %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx940 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX940 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx941 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX941 %s
+// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx942 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX942 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1010 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1010 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1011 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1011 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1012 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1012 %s
@@ -77,6 +78,7 @@
 // GFX90C: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 // GFX940: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+fp8-insts,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gfx940-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 // 

[PATCH] D149982: AMDGPU: Add basic gfx941 target

2023-05-10 Thread Konstantin Zhuravlyov 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 rG1fc70210a6a5: AMDGPU: Add basic gfx941 target (authored by 
kzhuravl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149982

Files:
  clang/include/clang/Basic/Cuda.h
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/CodeGenOpenCL/amdgpu-features.cl
  clang/test/Driver/amdgpu-macros.cl
  clang/test/Driver/amdgpu-mcpu.cl
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/docs/AMDGPUUsage.rst
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/Object/ELFObjectFile.cpp
  llvm/lib/ObjectYAML/ELFYAML.cpp
  llvm/lib/Target/AMDGPU/AMDGPU.td
  llvm/lib/Target/AMDGPU/GCNProcessors.td
  llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll
  llvm/test/CodeGen/AMDGPU/elf-header-flags-mach.ll
  llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
  llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
  llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
  llvm/tools/llvm-readobj/ELFDumper.cpp

Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1588,6 +1588,7 @@
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX90A),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX90C),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX940),
+  LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX941),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1010),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1011),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1012),
@@ -1648,6 +1649,7 @@
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX90A),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX90C),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX940),
+  LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX941),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1010),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1011),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1012),
Index: llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
===
--- llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
+++ llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
@@ -205,6 +205,15 @@
 # RUN: yaml2obj %s -o %t -DABI_VERSION=2 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX940
 # RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=2 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX940 -DFLAG_VALUE=0x40
 
+# RUN: yaml2obj %s -o %t -DABI_VERSION=0 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX941
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=0 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX941 -DFLAG_VALUE=0x4B
+
+# RUN: yaml2obj %s -o %t -DABI_VERSION=1 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX941
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=1 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX941 -DFLAG_VALUE=0x4B
+
+# RUN: yaml2obj %s -o %t -DABI_VERSION=2 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX941
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=2 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX941 -DFLAG_VALUE=0x4B
+
 # RUN: yaml2obj %s -o %t -DABI_VERSION=0 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX1010
 # RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=0 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX1010 -DFLAG_VALUE=0x33
 
Index: llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
===
--- llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
+++ llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
@@ -85,6 +85,11 @@
 
 ; --GFX9---
 ;
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx941 -filetype=obj -O0 -o %t.o %s
+; RUN: llvm-objdump -D --arch-name=amdgcn --mcpu=gfx941 %t.o > %t-specify.txt
+; RUN: llvm-objdump -D %t.o > %t-detect.txt
+; RUN: diff %t-specify.txt %t-detect.txt
+
 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -filetype=obj -O0 -o %t.o %s
 ; RUN: llvm-objdump -D --arch-name=amdgcn --mcpu=gfx940 %t.o > %t-specify.txt
 ; RUN: llvm-objdump -D %t.o > %t-detect.txt
Index: llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
=

[PATCH] D149983: AMDGPU: Add basic gfx942 target

2023-05-10 Thread Konstantin Zhuravlyov 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 rG9d0572797233: AMDGPU: Add basic gfx942 target (authored by 
kzhuravl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149983

Files:
  clang/include/clang/Basic/Cuda.h
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/CodeGenOpenCL/amdgpu-features.cl
  clang/test/Driver/amdgpu-macros.cl
  clang/test/Driver/amdgpu-mcpu.cl
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/docs/AMDGPUUsage.rst
  llvm/include/llvm/BinaryFormat/ELF.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/Object/ELFObjectFile.cpp
  llvm/lib/ObjectYAML/ELFYAML.cpp
  llvm/lib/Target/AMDGPU/AMDGPU.td
  llvm/lib/Target/AMDGPU/GCNProcessors.td
  llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/test/CodeGen/AMDGPU/directive-amdgcn-target.ll
  llvm/test/CodeGen/AMDGPU/elf-header-flags-mach.ll
  llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
  llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
  llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
  llvm/tools/llvm-readobj/ELFDumper.cpp

Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1589,6 +1589,7 @@
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX90C),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX940),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX941),
+  LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX942),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1010),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1011),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1012),
@@ -1650,6 +1651,7 @@
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX90C),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX940),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX941),
+  LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX942),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1010),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1011),
   LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_MACH_AMDGCN_GFX1012),
Index: llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
===
--- llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
+++ llvm/test/tools/llvm-readobj/ELF/amdgpu-elf-headers.test
@@ -214,6 +214,15 @@
 # RUN: yaml2obj %s -o %t -DABI_VERSION=2 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX941
 # RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=2 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX941 -DFLAG_VALUE=0x4B
 
+# RUN: yaml2obj %s -o %t -DABI_VERSION=0 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX942
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=0 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX942 -DFLAG_VALUE=0x4C
+
+# RUN: yaml2obj %s -o %t -DABI_VERSION=1 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX942
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=1 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX942 -DFLAG_VALUE=0x4C
+
+# RUN: yaml2obj %s -o %t -DABI_VERSION=2 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX942
+# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=2 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX942 -DFLAG_VALUE=0x4C
+
 # RUN: yaml2obj %s -o %t -DABI_VERSION=0 -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX1010
 # RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=ALL,KNOWN-ABI-VERSION,SINGLE-FLAG --match-full-lines -DABI_VERSION=0 -DFILE=%t -DFLAG_NAME=EF_AMDGPU_MACH_AMDGCN_GFX1010 -DFLAG_VALUE=0x33
 
Index: llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
===
--- llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
+++ llvm/test/tools/llvm-objdump/ELF/AMDGPU/subtarget.ll
@@ -85,6 +85,11 @@
 
 ; --GFX9---
 ;
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 -filetype=obj -O0 -o %t.o %s
+; RUN: llvm-objdump -D --arch-name=amdgcn --mcpu=gfx942 %t.o > %t-specify.txt
+; RUN: llvm-objdump -D %t.o > %t-detect.txt
+; RUN: diff %t-specify.txt %t-detect.txt
+
 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx941 -filetype=obj -O0 -o %t.o %s
 ; RUN: llvm-objdump -D --arch-name=amdgcn --mcpu=gfx941 %t.o > %t-specify.txt
 ; RUN: llvm-objdump -D %t.o > %t-detect.txt
Index: llvm/test/Object/AMDGPU/elf-header-flags-mach.yaml
=

[PATCH] D146418: Support for OpenMP 5.0 sec 2.12.7 - Declare Target initializer expressions

2023-05-10 Thread Ritanya via Phabricator via cfe-commits
RitanyaB updated this revision to Diff 521014.

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

https://reviews.llvm.org/D146418

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_target_messages.cpp
  clang/test/OpenMP/declare_target_variables_ast_print.cpp
  clang/test/OpenMP/nvptx_target_exceptions_messages.cpp

Index: clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
===
--- clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
+++ clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
@@ -95,7 +95,7 @@
 int (*D)() = C; // expected-note {{used here}}
 // host-note@-1 {{used here}}
 #pragma omp end declare target
-int foobar3() { throw 1; }
+int foobar3() { throw 1; } // expected-error {{cannot use 'throw' with exceptions disabled}}
 
 // Check no infinite recursion in deferred diagnostic emitter.
 long E = (long)&E;
Index: clang/test/OpenMP/declare_target_variables_ast_print.cpp
===
--- /dev/null
+++ clang/test/OpenMP/declare_target_variables_ast_print.cpp
@@ -0,0 +1,111 @@
+// RUN: %clang_cc1 -w -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK
+// expected-no-diagnostics
+
+static int variable = 100; 
+static float variable1 = 200;
+static float variable2 = variable1; 
+
+static int var = 1;
+
+static int var1 = 10;
+static int *var2 = &var1;
+static int **ptr1 = &var2;
+
+int arr[2] = {1,2};
+int (*arrptr)[2] = &arr;
+
+class declare{
+  public: int x;
+  void print();
+};
+declare obj1;
+declare *obj2 = &obj1;
+
+struct target{
+  int x;
+  void print();
+};
+static target S;
+
+#pragma omp declare target
+int target_var = variable;
+float target_var1 = variable2;
+int *ptr = &var;
+int ***ptr2 = &ptr1;
+int (**ptr3)[2] = &arrptr;
+declare **obj3 = &obj2;
+target *S1 = &S;
+#pragma omp end declare target
+// CHECK: #pragma omp declare target
+// CHECK-NEXT: static int variable = 100;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static float variable1 = 200;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static float variable2 = variable1;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK: #pragma omp declare target
+// CHECK-NEXT: static int var = 1;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int var1 = 10;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int *var2 = &var1;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int **ptr1 = &var2;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int arr[2] = {1, 2};
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int (*arrptr)[2] = &arr;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: class declare {
+// CHECK-NEXT: public: 
+// CHECK-NEXT:  int x;
+// CHECK-NEXT:  void print();
+// CHECK-NEXT: };
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: declare obj1;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: declare *obj2 = &obj1;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: struct target {
+// CHECK-NEXT:  int x;
+// CHECK-NEXT:  void print();
+// CHECK-NEXT: };
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static target S;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int target_var = variable;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: float target_var1 = variable2;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int *ptr = &var;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int ***ptr2 = &ptr1;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int (**ptr3)[2] = &arrptr;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: declare **obj3 = &obj2; 
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: target *S1 = &S;
+// CHECK-NEXT: #pragma omp end declare target
Index: clang/test/OpenMP/declare_target_messages.cpp
===
--- clang/test/OpenMP/declare_target_messages.cpp
+++ clang/test/OpenMP/declare_target_messages.cpp
@@ -233,6 +233,42 @@
 #pragma omp declar

[PATCH] D146418: Support for OpenMP 5.0 sec 2.12.7 - Declare Target initializer expressions

2023-05-10 Thread Ritanya via Phabricator via cfe-commits
RitanyaB added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:23094-23095
+public:
+  SmallVector DeclVector;
+  Decl *TargetDecl;
+  void VisitDeclRefExpr(const DeclRefExpr *Node) {

ABataev wrote:
> Why public?
As the data members are accessed from outside the class (in 
ActOnOpenMPImplicitDeclareTarget function), I have made them public.  



Comment at: clang/lib/Sema/SemaOpenMP.cpp:23107-23110
+  if (isa(*it))
+VisitExpr(dyn_cast(*it));
+  if (isa(*it))
+Visit(*it);

ABataev wrote:
> Just Visit(*it)?
Or I can call VisitDeclRefExpr directly. Would that be more suitable?


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

https://reviews.llvm.org/D146418

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


[PATCH] D149986: AMDGPU: Force sc0 and sc1 on stores for gfx940 and gfx941

2023-05-10 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl marked an inline comment as done.
kzhuravl added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp:524
+ SIAtomicAddrSpace::NONE)
+  return enableSC0Bit(MI) | enableSC1Bit(MI);
+return false;

jmmartinez wrote:
> NIT: Is the use of the bitwise or " | " intended? I'd use the logical or " || 
> " instead.
It is intentional, we need both SC0 and SC1 bits set. If I switch this to || it 
will short circuit and not invoke enableSC1Bit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149986

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


[PATCH] D146418: Support for OpenMP 5.0 sec 2.12.7 - Declare Target initializer expressions

2023-05-10 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:23106-23107
+ it != Ex->child_end(); ++it) {
+  if (isa(*it))
+VisitExpr(dyn_cast(*it));
+  if (isa(*it))

Why just a regular Visit does not work here? Plus, isa + dyn_cast is weird.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:23094-23095
+public:
+  SmallVector DeclVector;
+  Decl *TargetDecl;
+  void VisitDeclRefExpr(const DeclRefExpr *Node) {

RitanyaB wrote:
> ABataev wrote:
> > Why public?
> As the data members are accessed from outside the class (in 
> ActOnOpenMPImplicitDeclareTarget function), I have made them public.  
If you need them, implement getters for them and make them private.


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

https://reviews.llvm.org/D146418

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


[PATCH] D149997: [clang] [test] Narrow down MSVC specific behaviours from "any windows" to only MSVC/clang-cl

2023-05-10 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D149997#4331937 , @thakis wrote:

> This broke check-clang on windows: http://45.33.8.238/win/78359/step_7.txt
>
> (The Driver/split-debug.c failure is something else and since fixed, but the 
> other two tests are due to this change.)
>
> Please take a look and revert for now if it takes a while to fix.

Sorry about this, and thanks for reverting. I’ll have a closer look at the 
issue later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149997

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


[PATCH] D150192: Allow clang to emit inrange metadata when generating code for array subscripts

2023-05-10 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

See D115274 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150192

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


[clang] ce5ad23 - libclang: declare blocks interfaces always

2023-05-10 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2023-05-10T10:00:25-07:00
New Revision: ce5ad23ac29bb70427dd22d9ee480d22e0aa6cf1

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

LOG: libclang: declare blocks interfaces always

The implementation of these methods is not reliant on the availability
of the Blocks extension in the compiler.  However, when building on
Windows, the interface declaration is important for the attribution of
the DLL storage.  Without the attribution, the method implementation is
built but not made available as part of the ABI.  Use a check for the
blocks extension to determine how method signature is viewed rather than
controlling whether it is part of the interface.

Added: 


Modified: 
clang/include/clang-c/Index.h

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index c7d32e6a152ae..2c1bc02003ba3 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -48,6 +48,10 @@
 #define CINDEX_VERSION_STRING  
\
   CINDEX_VERSION_STRINGIZE(CINDEX_VERSION_MAJOR, CINDEX_VERSION_MINOR)
 
+#ifndef __has_feature
+#define __has_feature(feature) 0
+#endif
+
 LLVM_CLANG_C_EXTERN_C_BEGIN
 
 /** \defgroup CINDEX libclang: C Interface to Clang
@@ -3856,8 +3860,6 @@ typedef enum CXChildVisitResult 
(*CXCursorVisitor)(CXCursor cursor,
 CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
 CXCursorVisitor visitor,
 CXClientData client_data);
-#ifdef __has_feature
-#if __has_feature(blocks)
 /**
  * Visitor invoked for each cursor found by a traversal.
  *
@@ -3868,8 +3870,12 @@ CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor 
parent,
  * The visitor should return one of the \c CXChildVisitResult values
  * to direct clang_visitChildrenWithBlock().
  */
+#if __has_feature(blocks)
 typedef enum CXChildVisitResult (^CXCursorVisitorBlock)(CXCursor cursor,
 CXCursor parent);
+#else
+typedef _CXChildVisitResult *CXCursorVisitorBlock;
+#endif
 
 /**
  * Visits the children of a cursor using the specified block.  Behaves
@@ -3877,8 +3883,6 @@ typedef enum CXChildVisitResult 
(^CXCursorVisitorBlock)(CXCursor cursor,
  */
 CINDEX_LINKAGE unsigned
 clang_visitChildrenWithBlock(CXCursor parent, CXCursorVisitorBlock block);
-#endif
-#endif
 
 /**
  * @}
@@ -5879,11 +5883,12 @@ CINDEX_LINKAGE CXResult clang_findReferencesInFile(
 CINDEX_LINKAGE CXResult clang_findIncludesInFile(
 CXTranslationUnit TU, CXFile file, CXCursorAndRangeVisitor visitor);
 
-#ifdef __has_feature
 #if __has_feature(blocks)
-
 typedef enum CXVisitorResult (^CXCursorAndRangeVisitorBlock)(CXCursor,
  CXSourceRange);
+#else
+typedef struct _CXCursorAndRangeVisitorBlock *CXCursorAndRangeVisitorBlock;
+#endif
 
 CINDEX_LINKAGE
 CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
@@ -5893,9 +5898,6 @@ CINDEX_LINKAGE
 CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
CXCursorAndRangeVisitorBlock);
 
-#endif
-#endif
-
 /**
  * The client's data object that is associated with a CXFile.
  */



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


[PATCH] D149495: [RISCV] Add support for V extension in SiFive7

2023-05-10 Thread Michael Maitland via Phabricator via cfe-commits
michaelmaitland updated this revision to Diff 521024.
michaelmaitland marked 2 inline comments as done.
michaelmaitland added a comment.

Use defvar in subroutines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149495

Files:
  llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
  llvm/lib/Target/RISCV/RISCVScheduleV.td

Index: llvm/lib/Target/RISCV/RISCVScheduleV.td
===
--- llvm/lib/Target/RISCV/RISCVScheduleV.td
+++ llvm/lib/Target/RISCV/RISCVScheduleV.td
@@ -9,7 +9,7 @@
 //===--===//
 /// Define scheduler resources associated with def operands.
 
-defvar SchedMxList = ["M1", "M2", "M4", "M8", "MF2", "MF4", "MF8"];
+defvar SchedMxList = ["MF8", "MF4", "MF2", "M1", "M2", "M4", "M8"];
 // Used for widening and narrowing instructions as it doesn't contain M8.
 defvar SchedMxListW = !listremove(SchedMxList, ["M8"]);
 defvar SchedMxListFW = !listremove(SchedMxList, ["M8", "MF8"]);
@@ -38,6 +38,32 @@
 !eq(mx, "MF4"): [16]);
 }
 
+// Helper function to get the largest LMUL from MxList
+// Precondition: MxList is sorted in ascending LMUL order.
+class LargestLMUL MxList> {
+  // MX list is sorted from smallest to largest
+  string r = !foldl(!head(MxList), MxList, last, curr, curr);
+}
+// Helper function to get the smallest SEW that can be used with LMUL mx
+// Precondition: MxList is sorted in ascending LMUL order and SchedSEWSet
+class SmallestSEW {
+  int r = !head(!if(isF, SchedSEWSetF.val, SchedSEWSet.val));
+}
+
+// Creates WriteRes for (name, mx, resources) tuple
+multiclass LMULWriteResMX resources,
+  string mx, bit IsWorstCase> {
+  def : WriteRes(name # "_" # mx), resources>;
+  if IsWorstCase then
+def : WriteRes(name # "_WorstCase"), resources>;
+}
+multiclass LMULSEWWriteResMXSEW resources,
+ string mx, int sew,  bit IsWorstCase> {
+  def : WriteRes(name # "_" # mx # "_E" # sew), resources>;
+  if IsWorstCase then
+def : WriteRes(name # "_WorstCase"), resources>;
+}
+
 // Define multiclasses to define SchedWrite, SchedRead,  WriteRes, and
 // ReadAdvance for each (name, LMUL) pair and for each LMUL in each of the
 // SchedMxList variants above. Each multiclass is responsible for defining
Index: llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
===
--- llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
+++ llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
@@ -8,6 +8,131 @@
 
 //===--===//
 
+/// c is true if mx has the worst case behavior compared to LMULs in MxList.
+/// On the SiFive7, the worst case LMUL is the Largest LMUL
+/// and the worst case sew is the smallest SEW for that LMUL.
+class SiFive7IsWorstCaseMX MxList> {
+  defvar LLMUL = LargestLMUL.r;
+  bit c = !eq(mx, LLMUL);
+}
+
+/// c is true if mx and sew have the worst case behavior compared to LMULs in
+/// MxList. On the SiFive7, the worst case LMUL is the Largest LMUL
+/// and the worst case sew is the smallest SEW for that LMUL.
+class SiFive7IsWorstCaseMXSEW MxList,
+   bit isF = 0> {
+  defvar LLMUL = LargestLMUL.r;
+  defvar SSEW = SmallestSEW.r;
+  bit c = !and(!eq(mx, LLMUL), !eq(sew, SSEW));
+}
+
+class SiFive7GetCyclesDefault {
+  int c = !cond(
+!eq(mx, "M1") : 2,
+!eq(mx, "M2") : 4,
+!eq(mx, "M4") : 8,
+!eq(mx, "M8") : 16,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesWidening {
+  int c = !cond(
+!eq(mx, "M1") : 2,
+!eq(mx, "M2") : 4,
+!eq(mx, "M4") : 8,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesNarrowing {
+  int c = !cond(
+!eq(mx, "M1") : 4,
+!eq(mx, "M2") : 8,
+!eq(mx, "M4") : 16,
+!eq(mx, "MF2") : 2,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesOutputLMUL {
+  int c = !cond(
+!eq(mx, "M1") : 1,
+!eq(mx, "M2") : 2,
+!eq(mx, "M4") : 4,
+!eq(mx, "M8") : 8,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesVMask {
+  int c = !cond(
+!eq(mx, "M1") : 1,
+!eq(mx, "M2") : 1,
+!eq(mx, "M4") : 1,
+!eq(mx, "M8") : 2,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+// Cycles for segmented loads and stores are calculated using the
+// formula ceil(2 * nf * lmul).
+class SiFive7GetCyclesSegmented {
+  int c = !cond(
+!eq(mx, "M1") : !mul(!mul(2, nf), 1),
+!eq(mx, "M2") : !mul(!mul(2, nf), 2),
+!eq(mx, "M4") : !mul(!mul(2, nf), 4),
+!eq(mx, "M8") : !mul(!mul(2, nf), 8),
+// We can calculate ceil(a/b) using (a + b - 1) / b.
+// Since the multiplication

[PATCH] D149495: [RISCV] Add support for V extension in SiFive7

2023-05-10 Thread Michael Maitland via Phabricator via cfe-commits
michaelmaitland added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVScheduleV.td:41
 
+// Helper function to get the largest LMUL from MxList
+// Precondition: MxList is sorted in ascending LMUL order.

pcwang-thead wrote:
> So, are we going to discard `LMULXXXImpl` below?
I will use `LMULXXXImpl` in a follow up NFC patch. This code below comes from 
before `LMULXXXImpl` was introduced.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149495

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


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names and introduce Bfloat16 arithmetic type.

2023-05-10 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann requested changes to this revision.
tahonermann added a comment.
This revision now requires changes to proceed.

I reviewed about a third of this, but then stopped due to the `__bf16` vs 
`std::bfloat16_t` naming issues. I think the existing names that use "bfloat16" 
to support the `__bf16` type should be renamed, in a separate patch, and this 
patch rebased on top of it. We are sure to make mistakes if this confusing 
situation is not resolved.




Comment at: clang/include/clang/AST/ASTContext.h:1113-1114
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
   CanQualType BFloat16Ty;
+  CanQualType BF16Ty;// [C++23 6.8.3p5], ISO/IEC/IEEE 60559.
   CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3

This seems wrong. C++23 introduces `std​::​bfloat16_t` and Clang already 
supports `__bf16`. It seems to me that the `BFloat16Ty` name should be used for 
the former and `BF16Ty` used for the latter. I get that the inconsistency is 
preexisting, but I think we should fix that (in another patch before landing 
this one; there aren't very many references).



Comment at: clang/include/clang/AST/BuiltinTypes.def:215-219
+// 'Bfloat16' arithmetic type to represent std::bfloat16_t.
+FLOATING_TYPE(BF16, BFloat16Ty)
+
 // '__bf16'
 FLOATING_TYPE(BFloat16, BFloat16Ty)

Here again, the type names are the exact opposite of what one would intuitively 
expect (I do appreciate that the comment makes the intent clear, but it still 
looks like a copy/paste error or similar).



Comment at: clang/include/clang/AST/Type.h:2152-2162
+  bool isCXX23FloatingPointType()
+  const; // C++23 6.8.2p12 [basic.fundamental] (standard floating point +
+ // extended floating point)
+  bool isCXX23StandardFloatingPointType()
+  const; // C++23 6.8.2p12 [basic.fundamental] (standard floating point)
+  bool isCXX23ExtendedFloatingPointType()
+  const; // C++23 6.8.2p12 [basic.fundamental] (extended floating point)

Precedent elsewhere in this file is to place multi-line comments ahead of the 
function they appertain to.



Comment at: clang/include/clang/AST/Type.h:7259-7265
 inline bool Type::isBFloat16Type() const {
   return isSpecificBuiltinType(BuiltinType::BFloat16);
 }
 
+inline bool Type::isBF16Type() const {
+  return isSpecificBuiltinType(BuiltinType::BF16);
+}

This is a great example of `BFloat16` vs `BF16` confusion; here the names are 
*not* reversed. It is really hard to know if this code is wrong or for callers 
to know which one they should use.



Comment at: clang/include/clang/Driver/Options.td:6418-6420
+def fnative_bfloat16_type: Flag<["-"], "fnative-bfloat16-type">,
+  HelpText<"Enable bfloat16 arithmetic type in C++23 for targets with native 
support.">,
+  MarshallingInfoFlag>;

Since this message is specific to C++ for now (pending the addition of a 
`_BFloat16` type in some future C standard, I think the message should 
reference `std::bfloat16_t` and skip explicit mention of C++23. I know it is 
kind of awkward to refer to the standard library name for the type, but since 
WG21 decided not to provide a keyword name (I wish they would just use the C 
names for these and get over it; they can still provide pretty library names!), 
there isn't another more explicit name to use. Alternatively, we could say 
something like "Enable the underlying type of std::bfloat16_t in C++ ...".



Comment at: clang/include/clang/Lex/LiteralSupport.h:75
   bool isBitInt : 1;// 1wb, 1uwb (C2x)
+  bool isBF16 : 1;  // 1.0bf
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.

Is this for `__bf16` or for `std::bfloat16_t`?


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

https://reviews.llvm.org/D149573

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


[PATCH] D103930: [clang][HeaderSearch] Fix implicit module when using header maps

2023-05-10 Thread Ian Anderson via Phabricator via cfe-commits
iana added inline comments.



Comment at: clang/test/Modules/implicit-module-header-maps.cpp:52
+//header and trip a `#error`, or
+// 2) header maps aren't usesd, as the header name doesn't exist and relies on
+//the header map to remap it to the real header.

usesd -> used


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103930

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


[PATCH] D103930: [clang][HeaderSearch] Fix implicit module when using header maps

2023-05-10 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

I wonder if clang should have better module interaction with the header maps 
produced by Xcode, or if Xcode should produce better header maps to work with 
clang. Or are you having problems with header maps outside of Xcode?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103930

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


[clang] d747f82 - libclang: add missing `struct` in the declaration

2023-05-10 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2023-05-10T10:31:53-07:00
New Revision: d747f8277b386059a74dee062295aa8d864398fc

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

LOG: libclang: add missing `struct` in the declaration

When building with compilers that do not support the Blocks extension,
we would fail to compile due to the missing type specifier on the
`typedef`.  This should repair those builds.

Fixes: #62640

Added: 


Modified: 
clang/include/clang-c/Index.h

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 2c1bc02003ba..29c53c0382ab 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3874,7 +3874,7 @@ CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor 
parent,
 typedef enum CXChildVisitResult (^CXCursorVisitorBlock)(CXCursor cursor,
 CXCursor parent);
 #else
-typedef _CXChildVisitResult *CXCursorVisitorBlock;
+typedef struct _CXChildVisitResult *CXCursorVisitorBlock;
 #endif
 
 /**



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


[PATCH] D149495: [RISCV] Add support for V extension in SiFive7

2023-05-10 Thread Michael Maitland 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 rG1a855819a87f: [RISCV] Add support for V extenstion in 
SiFive7 (authored by michaelmaitland).

Changed prior to commit:
  https://reviews.llvm.org/D149495?vs=521024&id=521031#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149495

Files:
  llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
  llvm/lib/Target/RISCV/RISCVScheduleV.td

Index: llvm/lib/Target/RISCV/RISCVScheduleV.td
===
--- llvm/lib/Target/RISCV/RISCVScheduleV.td
+++ llvm/lib/Target/RISCV/RISCVScheduleV.td
@@ -9,7 +9,7 @@
 //===--===//
 /// Define scheduler resources associated with def operands.
 
-defvar SchedMxList = ["M1", "M2", "M4", "M8", "MF2", "MF4", "MF8"];
+defvar SchedMxList = ["MF8", "MF4", "MF2", "M1", "M2", "M4", "M8"];
 // Used for widening and narrowing instructions as it doesn't contain M8.
 defvar SchedMxListW = !listremove(SchedMxList, ["M8"]);
 defvar SchedMxListFW = !listremove(SchedMxList, ["M8", "MF8"]);
@@ -38,6 +38,32 @@
 !eq(mx, "MF4"): [16]);
 }
 
+// Helper function to get the largest LMUL from MxList
+// Precondition: MxList is sorted in ascending LMUL order.
+class LargestLMUL MxList> {
+  // MX list is sorted from smallest to largest
+  string r = !foldl(!head(MxList), MxList, last, curr, curr);
+}
+// Helper function to get the smallest SEW that can be used with LMUL mx
+// Precondition: MxList is sorted in ascending LMUL order and SchedSEWSet
+class SmallestSEW {
+  int r = !head(!if(isF, SchedSEWSetF.val, SchedSEWSet.val));
+}
+
+// Creates WriteRes for (name, mx, resources) tuple
+multiclass LMULWriteResMX resources,
+  string mx, bit IsWorstCase> {
+  def : WriteRes(name # "_" # mx), resources>;
+  if IsWorstCase then
+def : WriteRes(name # "_WorstCase"), resources>;
+}
+multiclass LMULSEWWriteResMXSEW resources,
+ string mx, int sew,  bit IsWorstCase> {
+  def : WriteRes(name # "_" # mx # "_E" # sew), resources>;
+  if IsWorstCase then
+def : WriteRes(name # "_WorstCase"), resources>;
+}
+
 // Define multiclasses to define SchedWrite, SchedRead,  WriteRes, and
 // ReadAdvance for each (name, LMUL) pair and for each LMUL in each of the
 // SchedMxList variants above. Each multiclass is responsible for defining
Index: llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
===
--- llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
+++ llvm/lib/Target/RISCV/RISCVSchedSiFive7.td
@@ -8,6 +8,131 @@
 
 //===--===//
 
+/// c is true if mx has the worst case behavior compared to LMULs in MxList.
+/// On the SiFive7, the worst case LMUL is the Largest LMUL
+/// and the worst case sew is the smallest SEW for that LMUL.
+class SiFive7IsWorstCaseMX MxList> {
+  defvar LLMUL = LargestLMUL.r;
+  bit c = !eq(mx, LLMUL);
+}
+
+/// c is true if mx and sew have the worst case behavior compared to LMULs in
+/// MxList. On the SiFive7, the worst case LMUL is the Largest LMUL
+/// and the worst case sew is the smallest SEW for that LMUL.
+class SiFive7IsWorstCaseMXSEW MxList,
+   bit isF = 0> {
+  defvar LLMUL = LargestLMUL.r;
+  defvar SSEW = SmallestSEW.r;
+  bit c = !and(!eq(mx, LLMUL), !eq(sew, SSEW));
+}
+
+class SiFive7GetCyclesDefault {
+  int c = !cond(
+!eq(mx, "M1") : 2,
+!eq(mx, "M2") : 4,
+!eq(mx, "M4") : 8,
+!eq(mx, "M8") : 16,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesWidening {
+  int c = !cond(
+!eq(mx, "M1") : 2,
+!eq(mx, "M2") : 4,
+!eq(mx, "M4") : 8,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesNarrowing {
+  int c = !cond(
+!eq(mx, "M1") : 4,
+!eq(mx, "M2") : 8,
+!eq(mx, "M4") : 16,
+!eq(mx, "MF2") : 2,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesOutputLMUL {
+  int c = !cond(
+!eq(mx, "M1") : 1,
+!eq(mx, "M2") : 2,
+!eq(mx, "M4") : 4,
+!eq(mx, "M8") : 8,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+class SiFive7GetCyclesVMask {
+  int c = !cond(
+!eq(mx, "M1") : 1,
+!eq(mx, "M2") : 1,
+!eq(mx, "M4") : 1,
+!eq(mx, "M8") : 2,
+!eq(mx, "MF2") : 1,
+!eq(mx, "MF4") : 1,
+!eq(mx, "MF8") : 1
+  );
+}
+
+// Cycles for segmented loads and stores are calculated using the
+// formula ceil(2 * nf * lmul).
+class SiFive7GetCyclesSegmented {
+  int c = !cond(
+!eq(mx, "M1") : !mul(!mul(2, nf), 1),
+!eq(mx, "M2") : !mul(!mul(2, nf), 2),
+!eq(mx, "

[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names and introduce Bfloat16 arithmetic type.

2023-05-10 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs marked an inline comment as done.
codemzs added a comment.

In D149573#4332549 , @tahonermann 
wrote:

> I reviewed about a third of this, but then stopped due to the `__bf16` vs 
> `std::bfloat16_t` naming issues. I think the existing names that use 
> "bfloat16" to support the `__bf16` type should be renamed, in a separate 
> patch, and this patch rebased on top of it. We are sure to make mistakes if 
> this confusing situation is not resolved.

@tahonermann, thank you for your review and highlighting the naming issues with 
`__bf16` and `std::bfloat16_t`. I agree that reversing the type names will 
improve readability and maintainability. I considered this while working on the 
code and appreciate your suggestion to address it in a separate patch before 
rebasing this one.




Comment at: clang/include/clang/Lex/LiteralSupport.h:75
   bool isBitInt : 1;// 1wb, 1uwb (C2x)
+  bool isBF16 : 1;  // 1.0bf
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.

tahonermann wrote:
> Is this for `__bf16` or for `std::bfloat16_t`?
Its for `std::bfloat16_t`, I don't believe `__bf16` has a literal suffix. 


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

https://reviews.llvm.org/D149573

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


[PATCH] D150278: [Headers][doc] Add "shift" intrinsic descriptions to avx2intrin.h

2023-05-10 Thread Paul Robinson via Phabricator via cfe-commits
probinson created this revision.
probinson added reviewers: pengfei, RKSimon, goldstein.w.n, craig.topper.
Herald added a project: All.
probinson requested review of this revision.

https://reviews.llvm.org/D150278

Files:
  clang/lib/Headers/avx2intrin.h

Index: clang/lib/Headers/avx2intrin.h
===
--- clang/lib/Headers/avx2intrin.h
+++ clang/lib/Headers/avx2intrin.h
@@ -493,108 +493,404 @@
 return (__m256i)__builtin_ia32_psignd256((__v8si)__a, (__v8si)__b);
 }
 
+/// Shifts each 128-bit half of the 256-bit integer vector \a a left by
+///\a imm bytes, shifting in zero bytes, and returns the result. If \a imm
+///is greater than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// \code
+/// __m256i _mm256_slli_si256(__m256i a, const int imm);
+/// \endcode
+///
+/// This intrinsic corresponds to the \c VPSLLDQ instruction.
+///
+/// \param a
+///A 256-bit integer vector to be shifted.
+/// \param imm
+/// An unsigned immediate value specifying the shift count (in bytes).
+/// \returns A 256-bit integer vector containing the result.
 #define _mm256_slli_si256(a, imm) \
   ((__m256i)__builtin_ia32_pslldqi256_byteshift((__v4di)(__m256i)(a), (int)(imm)))
 
+/// Shifts each 128-bit half of the 256-bit integer vector \a a left by
+///\a imm bytes, shifting in zero bytes, and returns the result. If \a imm
+///is greater than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// \code
+/// __m256i _mm256_bslli_epi128(__m256i a, const int imm);
+/// \endcode
+///
+/// This intrinsic corresponds to the \c VPSLLDQ instruction.
+///
+/// \param a
+///A 256-bit integer vector to be shifted.
+/// \param imm
+///An unsigned immediate value specifying the shift count (in bytes).
+/// \returns A 256-bit integer vector containing the result.
 #define _mm256_bslli_epi128(a, imm) \
   ((__m256i)__builtin_ia32_pslldqi256_byteshift((__v4di)(__m256i)(a), (int)(imm)))
 
+/// Shifts each 16-bit element of the 256-bit vector of [16 x i16] in \a __a
+///left by \a __count bits, shifting in zero bits, and returns the result.
+///If \a __count is greater than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPSLLW instruction.
+///
+/// \param __a
+///A 256-bit vector of [16 x i16] to be shifted.
+/// \param __count
+///An unsigned integer value specifying the shift count (in bits).
+/// \returns A 256-bit vector of [16 x i16] containing the result.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_slli_epi16(__m256i __a, int __count)
 {
   return (__m256i)__builtin_ia32_psllwi256((__v16hi)__a, __count);
 }
 
+/// Shifts each 16-bit element of the 256-bit vector of [16 x i16] in \a __a
+///left by the number of bits specified by the lower 64 bits of \a __count,
+///shifting in zero bits, and returns the result. If \a __count is greater
+///than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPSLLW instruction.
+///
+/// \param __a
+///A 256-bit vector of [16 x i16] to be shifted.
+/// \param __count
+///A 128-bit vector of [2 x i64] whose lower element gives the unsigned
+///shift count (in bits). The upper element is ignored.
+/// \returns A 256-bit vector of [16 x i16] containing the result.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_sll_epi16(__m256i __a, __m128i __count)
 {
   return (__m256i)__builtin_ia32_psllw256((__v16hi)__a, (__v8hi)__count);
 }
 
+/// Shifts each 32-bit element of the 256-bit vector of [8 x i32] in \a __a
+///left by \a __count bits, shifting in zero bits, and returns the result.
+///If \a __count is greater than 31, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPSLLD instruction.
+///
+/// \param __a
+///A 256-bit vector of [8 x i32] to be shifted.
+/// \param __count
+///An unsigned integer value specifying the shift count (in bits).
+/// \returns A 256-bit vector of [8 x i32] containing the result.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_slli_epi32(__m256i __a, int __count)
 {
   return (__m256i)__builtin_ia32_pslldi256((__v8si)__a, __count);
 }
 
+/// Shifts each 32-bit element of the 256-bit vector of [8 x i32] in \a __a
+///left by the number of bits given in the lower 64 bits of \a __count,
+///shifting in zero bits, and returns the result. If \a __count is greater
+///than 31, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPSLLD instruction.
+///
+/// \param __a
+///A 256-bit vector of [8 x i32] to be shifted.
+/// \param __count
+///A 128-bit vector of [2 x i64] whose lower element gives the unsigned
+///shift count (in bits). The upper element is ignored.
+/// \returns A 256-bit vector of [8 x i32] containing th

[clang] 63eb04a - [clang][modules] Avoid unnecessary writes of .timestamp files

2023-05-10 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2023-05-10T10:41:33-07:00
New Revision: 63eb04a3683996db26dbf1534682c5696d93b080

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

LOG: [clang][modules] Avoid unnecessary writes of .timestamp files

Clang currently updates the mtime of .timestamp files on each load of the 
corresponding .pcm file. This is not necessary. In a given build session, Clang 
only needs to write the .timestamp file once, when we first validate the input 
files. This patch makes it so that we only touch the .timestamp file when it's 
older than the build session, alleviating some filesystem contention in 
clang-scan-deps.

Reviewed By: benlangmuir

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

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 9c31f9db14679..bdf476cf128a3 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4507,18 +4507,16 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef 
FileName,
 }
   }
 
-  if (PP.getHeaderSearchInfo()
-  .getHeaderSearchOpts()
-  .ModulesValidateOncePerBuildSession) {
+  HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();
+  if (HSOpts.ModulesValidateOncePerBuildSession) {
 // Now we are certain that the module and all modules it depends on are
-// up to date.  Create or update timestamp files for modules that are
-// located in the module cache (not for PCH files that could be anywhere
-// in the filesystem).
+// up-to-date. For implicitly-built module files, ensure the corresponding
+// timestamp files are up-to-date in this build session.
 for (unsigned I = 0, N = Loaded.size(); I != N; ++I) {
   ImportedModule &M = Loaded[I];
-  if (M.Mod->Kind == MK_ImplicitModule) {
+  if (M.Mod->Kind == MK_ImplicitModule &&
+  M.Mod->InputFilesValidationTimestamp < HSOpts.BuildSessionTimestamp)
 updateModuleTimestamp(*M.Mod);
-  }
 }
   }
 



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


[PATCH] D149802: [clang][modules] Avoid unnecessary writes of .timestamp files

2023-05-10 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG63eb04a36839: [clang][modules] Avoid unnecessary writes of 
.timestamp files (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149802

Files:
  clang/lib/Serialization/ASTReader.cpp


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4507,18 +4507,16 @@
 }
   }
 
-  if (PP.getHeaderSearchInfo()
-  .getHeaderSearchOpts()
-  .ModulesValidateOncePerBuildSession) {
+  HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();
+  if (HSOpts.ModulesValidateOncePerBuildSession) {
 // Now we are certain that the module and all modules it depends on are
-// up to date.  Create or update timestamp files for modules that are
-// located in the module cache (not for PCH files that could be anywhere
-// in the filesystem).
+// up-to-date. For implicitly-built module files, ensure the corresponding
+// timestamp files are up-to-date in this build session.
 for (unsigned I = 0, N = Loaded.size(); I != N; ++I) {
   ImportedModule &M = Loaded[I];
-  if (M.Mod->Kind == MK_ImplicitModule) {
+  if (M.Mod->Kind == MK_ImplicitModule &&
+  M.Mod->InputFilesValidationTimestamp < HSOpts.BuildSessionTimestamp)
 updateModuleTimestamp(*M.Mod);
-  }
 }
   }
 


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4507,18 +4507,16 @@
 }
   }
 
-  if (PP.getHeaderSearchInfo()
-  .getHeaderSearchOpts()
-  .ModulesValidateOncePerBuildSession) {
+  HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();
+  if (HSOpts.ModulesValidateOncePerBuildSession) {
 // Now we are certain that the module and all modules it depends on are
-// up to date.  Create or update timestamp files for modules that are
-// located in the module cache (not for PCH files that could be anywhere
-// in the filesystem).
+// up-to-date. For implicitly-built module files, ensure the corresponding
+// timestamp files are up-to-date in this build session.
 for (unsigned I = 0, N = Loaded.size(); I != N; ++I) {
   ImportedModule &M = Loaded[I];
-  if (M.Mod->Kind == MK_ImplicitModule) {
+  if (M.Mod->Kind == MK_ImplicitModule &&
+  M.Mod->InputFilesValidationTimestamp < HSOpts.BuildSessionTimestamp)
 updateModuleTimestamp(*M.Mod);
-  }
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150278: [Headers][doc] Add "shift" intrinsic descriptions to avx2intrin.h

2023-05-10 Thread Noah Goldstein via Phabricator via cfe-commits
goldstein.w.n accepted this revision.
goldstein.w.n added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D150278

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


[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-10 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl added a comment.

In D143675#4310903 , @eugenis wrote:

> I'm fine with it in general. Is asan_abi.cpp meant as a temporary stub? It's 
> not even link anywhere in the current version.

Right, we should be using it... We will add a test that compiles and links to 
it as affirmation that we have covered all of the entrypoints that ASan 
generates. It's also the case that asan_abi_shim.h is redundant since 
asan_abi_shim.cpp now gets its declarations from 
../asan/asan_interface_internal.h which is of course the source of truth for 
what the shim should be implementing. We will remove that as well and update. 
Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

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


[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-05-10 Thread Roy Sundahl via Phabricator via cfe-commits
rsundahl added a comment.

In D143675#4330599 , @thetruestblue 
wrote:

> Small insignificant note from me: When this lands, please be sure to add me 
> as co-author.
> https://github.blog/2018-01-29-commit-together-with-co-authors/

I've not seen this before @thetruestblue! I certainly will do so!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

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


[PATCH] D140275: [clangd] Tweak to add doxygen comment to the function declaration

2023-05-10 Thread David Goldman via Phabricator via cfe-commits
dgoldman added a comment.

In D140275#4203456 , @tupos wrote:

> Could you please also advice me what else need to be done for the ObjC, since 
> there were many years since I wrote ObjC last time I'm not sure what else 
> need to be done there.
>
> Thanks.

I think this is fine for a v1 - I think the main improvement would be changing 
the style/format, Xcode itself uses the following format instead where 
<#Placeholder Name#> denotes a placeholder:

  /// <#Description#>
  /// - Parameters:
  ///   - arg1: <#model description#>
  ///   - arg2: <#user description#>
  /// - Returns: <#description#>


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140275

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


[clang] 878e590 - Reland [clang] Make predefined expressions string literals under -fms-extensions

2023-05-10 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2023-05-10T10:54:58-07:00
New Revision: 878e590503dff0d9097e91c2bec4409f14503b82

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

LOG: Reland [clang] Make predefined expressions string literals under 
-fms-extensions

MSVC makes these string literals [1][2].

[1] https://godbolt.org/z/6vnTzbExx
[2] 
https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170

Fixes #114

Initial commit didn't check if there was a function name when stepping through 
expressions ignoring parens.

Reviewed By: aaron.ballman

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

Added: 
clang/test/Modules/predefined.cpp
clang/test/Sema/ms_predefined_expr.cpp
clang/test/SemaCXX/predefined-expr-msvc.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Expr.h
clang/include/clang/AST/IgnoreExpr.h
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c0820bd01fd5f..8b6232a6b9e6f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -438,6 +438,9 @@ Bug Fixes to C++ Support
 - Fix a crash when expanding a pack as the index of a subscript expression.
 - Fix handling of constexpr dynamic memory allocations in template
   arguments. (`#62462 `_)
+- Some predefined expressions are now treated as string literals in MSVC
+  compatibility mode.
+  (`#114 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 0ab778e5d8cd3..db4316d8faf1f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1992,7 +1992,7 @@ class PredefinedExpr final
 
 private:
   PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
- StringLiteral *SL);
+ bool IsTransparent, StringLiteral *SL);
 
   explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName);
 
@@ -2007,8 +2007,12 @@ class PredefinedExpr final
 
 public:
   /// Create a PredefinedExpr.
+  ///
+  /// If IsTransparent, the PredefinedExpr is transparently handled as a
+  /// StringLiteral.
   static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L,
-QualType FNTy, IdentKind IK, StringLiteral 
*SL);
+QualType FNTy, IdentKind IK, bool 
IsTransparent,
+StringLiteral *SL);
 
   /// Create an empty PredefinedExpr.
   static PredefinedExpr *CreateEmpty(const ASTContext &Ctx,
@@ -2018,6 +2022,8 @@ class PredefinedExpr final
 return static_cast(PredefinedExprBits.Kind);
   }
 
+  bool isTransparent() const { return PredefinedExprBits.IsTransparent; }
+
   SourceLocation getLocation() const { return PredefinedExprBits.Loc; }
   void setLocation(SourceLocation L) { PredefinedExprBits.Loc = L; }
 

diff  --git a/clang/include/clang/AST/IgnoreExpr.h 
b/clang/include/clang/AST/IgnoreExpr.h
index f8d2d6c7d00c0..917bada61fa6f 100644
--- a/clang/include/clang/AST/IgnoreExpr.h
+++ b/clang/include/clang/AST/IgnoreExpr.h
@@ -166,6 +166,11 @@ inline Expr *IgnoreParensSingleStep(Expr *E) {
   return CE->getChosenSubExpr();
   }
 
+  else if (auto *PE = dyn_cast(E)) {
+if (PE->isTransparent() && PE->getFunctionName())
+  return PE->getFunctionName();
+  }
+
   return E;
 }
 

diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index ea979d791ce7b..e466aa1755daf 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -364,6 +364,10 @@ class alignas(void *) Stmt {
 /// for the predefined identifier.
 unsigned HasFunctionName : 1;
 
+/// True if this PredefinedExpr should be treated as a StringLiteral (for
+/// MSVC compatibility).
+unsigned IsTransparent : 1;
+
 /// The location of this PredefinedExpr.
 SourceLocation Loc;
   };

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 87e72f000d494..2ba42f9b73763 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1190,6 +1190,7 @@ def MicrosoftCommentPaste : 
DiagGroup<"microsoft-comment-paste">;
 def MicrosoftEndOfFile : DiagGroup<"microsoft-end-of-file">;
 def Microsof

[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-05-10 Thread Arthur Eubanks via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG878e590503df: Reland [clang] Make predefined expressions 
string literals under -fms-extensions (authored by aeubanks).

Changed prior to commit:
  https://reviews.llvm.org/D146764?vs=520204&id=521039#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/IgnoreExpr.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/Modules/predefined.cpp
  clang/test/Sema/ms_predefined_expr.cpp
  clang/test/SemaCXX/predefined-expr-msvc.cpp

Index: clang/test/SemaCXX/predefined-expr-msvc.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/predefined-expr-msvc.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -std=c++17 -fsyntax-only -verify
+// RUN: %clang_cc1 %s -std=c++17 -fsyntax-only -verify -fms-extensions
+
+// expected-no-diagnostics
+
+struct StringRef {
+  StringRef(const char *);
+};
+template 
+StringRef getTypeName() {
+  StringRef s = __func__;
+}
+
Index: clang/test/Sema/ms_predefined_expr.cpp
===
--- /dev/null
+++ clang/test/Sema/ms_predefined_expr.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
+
+void f() {
+ const char a[] = __FUNCTION__; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
+ const char b[] = __FUNCDNAME__; // expected-warning{{initializing an array from a '__FUNCDNAME__' predefined identifier is a Microsoft extension}}
+ const char c[] = __FUNCSIG__; // expected-warning{{initializing an array from a '__FUNCSIG__' predefined identifier is a Microsoft extension}}
+ const char d[] = __func__; // expected-warning{{initializing an array from a '__func__' predefined identifier is a Microsoft extension}}
+ const char e[] = __PRETTY_FUNCTION__; // expected-warning{{initializing an array from a '__PRETTY_FUNCTION__' predefined identifier is a Microsoft extension}}
+}
Index: clang/test/Modules/predefined.cpp
===
--- /dev/null
+++ clang/test/Modules/predefined.cpp
@@ -0,0 +1,27 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -x c++ -std=c++20 -emit-module-interface a.h -o a.pcm -fms-extensions -verify
+// RUN: %clang_cc1 -std=c++20 a.cpp -fmodule-file=A=a.pcm -fms-extensions -fsyntax-only -verify
+
+//--- a.h
+
+// expected-no-diagnostics
+
+export module A;
+
+export template 
+void f() {
+char a[] = __func__;
+}
+
+//--- a.cpp
+
+// expected-warning@a.h:8 {{initializing an array from a '__func__' predefined identifier is a Microsoft extension}}
+
+import A;
+
+void g() {
+f(); // expected-note {{in instantiation of function template specialization 'f' requested here}}
+}
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -593,6 +593,7 @@
   bool HasFunctionName = E->getFunctionName() != nullptr;
   Record.push_back(HasFunctionName);
   Record.push_back(E->getIdentKind()); // FIXME: stable encoding
+  Record.push_back(E->isTransparent());
   Record.AddSourceLocation(E->getLocation());
   if (HasFunctionName)
 Record.AddStmt(E->getFunctionName());
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -582,6 +582,7 @@
   bool HasFunctionName = Record.readInt();
   E->PredefinedExprBits.HasFunctionName = HasFunctionName;
   E->PredefinedExprBits.Kind = Record.readInt();
+  E->PredefinedExprBits.IsTransparent = Record.readInt();
   E->setLocation(readSourceLocation());
   if (HasFunctionName)
 E->setFunctionName(cast(Record.readSubExpr()));
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -174,6 +174,8 @@
   E = GSE->getResultExpr();
 } else if (ChooseExpr *CE = dyn_cast(E)) {
   E = CE->getChosenSubExpr();
+} else if (PredefinedExpr *PE = dyn_cast(E)) {
+  E = PE->getFunctionName();
 } else {
   llvm_unreachable("unexpected expr in string literal init");
 }
@@ -8508,6 +8510,15 @@
 << Init->getSourceRange();
   }
 
+  if (S.getLan

[PATCH] D147266: [AArch64] Add IR intrinsics for vbsl* C intrinsics

2023-05-10 Thread Pranav Kant via Phabricator via cfe-commits
pranavk updated this revision to Diff 521040.
pranavk edited the summary of this revision.
pranavk added a comment.

Change shouldSinkOperand to allow backend to generate bitselect instructions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147266

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp


Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -14332,6 +14332,61 @@
 
 return true;
   }
+  case Instruction::And: {
+// If Or(And(A, maskValue), And(B, ~maskValue)), sink ~maskValue
+// where ~maskValue = xor maskValue, -1
+// This is to select more performant bitselect instruction with NEON.
+
+// We start checking for this code sequence from AND instruction containing
+// ~maskValue because operands are sunk just before the Instruction* I
+// passed to this function. Starting pattern matching with any other
+// instruction (such as Or) would lead to malformed IR
+
+// Check if this AND instruction is part of bigger tree rooted at Or.
+if (Subtarget->hasNEON() && I->getNumUses() == 1) {
+  Use &U = *(I->use_begin());
+  Instruction *OI = cast(U.getUser());
+  Value *And0_Op0 = nullptr, *And0_Op1 = nullptr, *And1_Op0 = nullptr,
+*And1_Op1 = nullptr;
+  if (!OI ||
+  !match(OI, m_Or(m_And(m_Value(And0_Op0), m_Value(And0_Op1)),
+  m_And(m_Value(And1_Op0), m_Value(And1_Op1 ||
+  !all_of(OI->operands(), [](Value *V) { return V->hasOneUser(); }))
+return false;
+
+  ArrayRef> Ands = {{And0_Op0, And0_Op1},
+  {And1_Op0, And1_Op1}};
+  for (unsigned AndIndex = 0; AndIndex < Ands.size(); ++AndIndex) {
+const unsigned OtherAndIndex = (AndIndex + 1) % 2;
+
+// Iterate operands of selected And
+for (unsigned AndOpIndex = 0; AndOpIndex < 2; ++AndOpIndex) {
+  if (const Instruction *XI =
+  dyn_cast(Ands[AndIndex][AndOpIndex]);
+  XI && XI->getOpcode() == Instruction::Xor) {
+Constant *MaskConst;
+Value *MaskValue;
+if (!match(XI, m_Xor(m_Value(MaskValue), m_Constant(MaskConst))) &&
+!match(XI, m_Xor(m_Constant(MaskConst), m_Value(MaskValue
+  return false;
+
+if (!MaskConst->isAllOnesValue())
+  return false;
+
+// one of the operands of other AND should be MaskValue
+if (!any_of(Ands[OtherAndIndex],
+[&MaskValue](Value *V) { return V == MaskValue; }))
+  return false;
+
+auto TI = cast(OI->getOperand(AndIndex));
+Ops.push_back(&TI->getOperandUse(AndOpIndex));
+return true;
+  }
+}
+  }
+}
+return false;
+  }
   case Instruction::Mul: {
 int NumZExts = 0, NumSExts = 0;
 for (auto &Op : I->operands()) {


Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -14332,6 +14332,61 @@
 
 return true;
   }
+  case Instruction::And: {
+// If Or(And(A, maskValue), And(B, ~maskValue)), sink ~maskValue
+// where ~maskValue = xor maskValue, -1
+// This is to select more performant bitselect instruction with NEON.
+
+// We start checking for this code sequence from AND instruction containing
+// ~maskValue because operands are sunk just before the Instruction* I
+// passed to this function. Starting pattern matching with any other
+// instruction (such as Or) would lead to malformed IR
+
+// Check if this AND instruction is part of bigger tree rooted at Or.
+if (Subtarget->hasNEON() && I->getNumUses() == 1) {
+  Use &U = *(I->use_begin());
+  Instruction *OI = cast(U.getUser());
+  Value *And0_Op0 = nullptr, *And0_Op1 = nullptr, *And1_Op0 = nullptr,
+*And1_Op1 = nullptr;
+  if (!OI ||
+  !match(OI, m_Or(m_And(m_Value(And0_Op0), m_Value(And0_Op1)),
+  m_And(m_Value(And1_Op0), m_Value(And1_Op1 ||
+  !all_of(OI->operands(), [](Value *V) { return V->hasOneUser(); }))
+return false;
+
+  ArrayRef> Ands = {{And0_Op0, And0_Op1},
+  {And1_Op0, And1_Op1}};
+  for (unsigned AndIndex = 0; AndIndex < Ands.size(); ++AndIndex) {
+const unsigned OtherAndIndex = (AndIndex + 1) % 2;
+
+// Iterate operands of selected And
+for (unsigned AndOpIndex = 0; AndOpIndex < 2; ++AndOpIndex) {
+  if (const Instruction *XI =
+  dyn_cast(Ands[AndIndex][AndOpIndex]

[PATCH] D147266: [AArch64] Add IR intrinsics for vbsl* C intrinsics

2023-05-10 Thread Pranav Kant via Phabricator via cfe-commits
pranavk planned changes to this revision.
pranavk added a comment.

I agree. I changed the implementation to not introduce the intrinsic. I will 
need another change in InstCombine to handle case #1 mentioned on github bug 
report. I will have separate patch for it changing InstCombine. Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147266

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


[PATCH] D150282: [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

2023-05-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: clang, jamieschmeiser, Whitney, Maetveis, dblaikie, 
scott.linder.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Inspired by D133662 .
Close https://github.com/llvm/llvm-project/issues/57285

When -ftime-trace is specified and the driver performs both compilation and
linking phases, the trace files are currently placed in the temporary directory
(/tmp by default on *NIX). A more sensible behavior would be to derive the trace
file names from the -o option, similar to how GCC derives auxiliary and dump
file names. Use -dumpdir (D149193 ) to 
implement the -gsplit-dwarf like behavior.

The following script demonstrates the time trace filenames.

  #!/bin/sh -e
  PATH=/tmp/Rel/bin:$PATH# adapt according to your build 
directory
  mkdir -p d e f
  echo 'int main() {}' > d/a.c
  echo > d/b.c
  
  a() { rm $1 || exit 1; }
  
  clang -ftime-trace d/a.c d/b.c # previously /tmp/[ab]-*.json
  a a-a.json; a a-b.json
  clang -ftime-trace d/a.c d/b.c -o e/x  # previously /tmp/[ab]-*.json
  a e/x-a.json; a e/x-b.json
  clang -ftime-trace d/a.c d/b.c -o e/x -dumpdir f/
  a f/a.json; a f/b.json
  clang -ftime-trace=f d/a.c d/b.c -o e/x
  a f/a-*.json; a f/b-*.json
  
  clang -c -ftime-trace d/a.c d/b.c
  a a.json b.json
  clang -c -ftime-trace=f d/a.c d/b.c
  a f/a.json f/b.json
  
  clang -c -ftime-trace d/a.c -o e/xa.o
  a e/xa.json
  clang -c -ftime-trace d/a.c -o e/xa.o -dumpdir f/
  a f/a.json

The driver checks `-ftime-trace` and `-ftime-trace=`, infers the trace file
name, and passes `-ftime-trace=` to cc1. The `-ftime-trace` cc1 option is
removed.

This patch doesn't attempt to change offloading behavior (D133662 
).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150282

Files:
  clang/include/clang/Driver/Compilation.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ftime-trace.cpp
  clang/tools/driver/cc1_main.cpp

Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -213,9 +213,7 @@
   bool Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(),
 Argv, Diags, Argv0);
 
-  if (Clang->getFrontendOpts().TimeTrace ||
-  !Clang->getFrontendOpts().TimeTracePath.empty()) {
-Clang->getFrontendOpts().TimeTrace = 1;
+  if (!Clang->getFrontendOpts().TimeTracePath.empty()) {
 llvm::timeTraceProfilerInitialize(
 Clang->getFrontendOpts().TimeTraceGranularity, Argv0);
   }
@@ -257,16 +255,6 @@
   llvm::TimerGroup::clearAll();
 
   if (llvm::timeTraceProfilerEnabled()) {
-SmallString<128> Path(Clang->getFrontendOpts().OutputFile);
-llvm::sys::path::replace_extension(Path, "json");
-if (!Clang->getFrontendOpts().TimeTracePath.empty()) {
-  // replace the suffix to '.json' directly
-  SmallString<128> TracePath(Clang->getFrontendOpts().TimeTracePath);
-  if (llvm::sys::fs::is_directory(TracePath))
-llvm::sys::path::append(TracePath, llvm::sys::path::filename(Path));
-  Path.assign(TracePath);
-}
-
 // It is possible that the compiler instance doesn't own a file manager here
 // if we're compiling a module unit. Since the file manager are owned by AST
 // when we're compiling a module unit. So the file manager may be invalid
@@ -280,7 +268,8 @@
   Clang->getInvocation(), Clang->getDiagnostics()));
 
 if (auto profilerOutput = Clang->createOutputFile(
-Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
+Clang->getFrontendOpts().TimeTracePath, /*Binary=*/false,
+/*RemoveFileOnSignal=*/false,
 /*useTemporary=*/false)) {
   llvm::timeTraceProfilerWrite(*profilerOutput);
   profilerOutput.reset();
Index: clang/test/Driver/ftime-trace.cpp
===
--- clang/test/Driver/ftime-trace.cpp
+++ clang/test/Driver/ftime-trace.cpp
@@ -31,6 +31,27 @@
 // CHECK:  "name": "process_name"
 // CHECK:  "name": "thread_name"
 
+// RUN: mkdir d e f && cp %s d/a.cpp && touch d/b.c
+
+// RUN: %clang -### -c -ftime-trace -ftime-trace-granularity=0 d/a.cpp -o e/a.o 2>&1 | FileCheck %s --check-prefix=COMPILE1
+// COMPILE1: -cc1{{.*}} "-ftime-trace=e/a.json"
+
+// RUN: %clang -### -c -ftime-trace -ftime-trace-granularity=0 d/a.cpp d/b.c -dumpdir f/ 2>&1 | FileCheck %s --check-prefix=COMPILE2
+// COMPILE2: -cc1{{.*}} "-ftime-trace=f/a.json"
+// COMPILE2: -cc1{{.*}} "-ftime-trace=f/b.json"
+
+// RUN: %clang -### -ftime-trace -ftime-trace

[PATCH] D150285: Fix CRTP partial specialization instantiation crash.

2023-05-10 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: alexander-shaposhnikov, clang-language-wg.
Herald added a project: All.
erichkeane requested review of this revision.

Fixes #60778.

When instantiating the body of a class template specialization that was
instantiated from a partial specialization, we were incorrectly
collecting template arguments from the primary template, which resulted
in the template arguments list being inaccurate.  In the example from
the issue, we were trying to substitute the boolean 'false' into the
type on Nested, which caused an assertion.


https://reviews.llvm.org/D150285

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaTemplate/partial-spec-instantiate.cpp


Index: clang/test/SemaTemplate/partial-spec-instantiate.cpp
===
--- clang/test/SemaTemplate/partial-spec-instantiate.cpp
+++ clang/test/SemaTemplate/partial-spec-instantiate.cpp
@@ -134,3 +134,23 @@
 
   _Static_assert(S::value, "");
 }
+
+namespace GH60778 {
+  template  class ClassTemplate {
+  public:
+  template  class Nested {};
+  };
+
+  template  class Base {};
+
+  template <>
+  template 
+  class ClassTemplate<>::Nested : public Base::Nested> 
{};
+
+  void use() {
+// This should instantiate the body of Nested with the template arguments
+// from the Partial Specialization. This would previously get confused and 
+// get the template arguments from the primary template instead.
+ClassTemplate<>::Nested instantiation;
+  }
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -163,6 +163,14 @@
 assert(ClassTemplSpec->getSpecializedTemplate() && "No class template?");
 if (ClassTemplSpec->getSpecializedTemplate()->isMemberSpecialization())
   return Response::Done();
+
+// If this was instantiated from a partial template specialization, we need
+// to get the next level of declaration context from the partial
+// specialization, as the ClassTemplateSpecializationDecl's
+// DeclContext/LexicalDeclContext will be for the primary template.
+if (auto *InstFromPartialTempl = 
ClassTemplSpec->getSpecializedTemplateOrPartial()
+  .dyn_cast())
+  return 
Response::ChangeDecl(InstFromPartialTempl->getLexicalDeclContext());
   }
   return Response::UseNextDecl(ClassTemplSpec);
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -391,6 +391,10 @@
   at the point where it is required. This fixes:
   (`#62224 `_) and
   (`#62596 `_)
+- Fix an assertion when instantiating the body of a Class Template 
Specialization
+  when it had been instantiated from a partial template specialization with 
different
+  template arguments on the containing class. This fixes:
+  (`#60778 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaTemplate/partial-spec-instantiate.cpp
===
--- clang/test/SemaTemplate/partial-spec-instantiate.cpp
+++ clang/test/SemaTemplate/partial-spec-instantiate.cpp
@@ -134,3 +134,23 @@
 
   _Static_assert(S::value, "");
 }
+
+namespace GH60778 {
+  template  class ClassTemplate {
+  public:
+  template  class Nested {};
+  };
+
+  template  class Base {};
+
+  template <>
+  template 
+  class ClassTemplate<>::Nested : public Base::Nested> {};
+
+  void use() {
+// This should instantiate the body of Nested with the template arguments
+// from the Partial Specialization. This would previously get confused and 
+// get the template arguments from the primary template instead.
+ClassTemplate<>::Nested instantiation;
+  }
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -163,6 +163,14 @@
 assert(ClassTemplSpec->getSpecializedTemplate() && "No class template?");
 if (ClassTemplSpec->getSpecializedTemplate()->isMemberSpecialization())
   return Response::Done();
+
+// If this was instantiated from a partial template specialization, we need
+// to get the next level of declaration context from the partial
+// specialization, as the ClassTemplateSpecializationDecl's
+// DeclContext/LexicalDeclContext will be for the primary template.
+if (auto *InstFromPartialTempl = ClassTemplSpec->getSpecializedTemplateOrPartial()
+  .dyn_cast())
+  return Respon

[PATCH] D150285: Fix CRTP partial specialization instantiation crash.

2023-05-10 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov accepted this revision.
alexander-shaposhnikov added a comment.
This revision is now accepted and ready to land.

LG


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

https://reviews.llvm.org/D150285

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


[PATCH] D144999: [Clang][MC][MachO]Only emits compact-unwind format for "canonical" personality symbols. For the rest, use DWARFs.

2023-05-10 Thread Vy Nguyen via Phabricator via cfe-commits
oontvoo added a comment.

@int3 @thakis, et al - friendly 🔔  :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144999

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


[PATCH] D149718: [NFC][Clang] Fix Coverity issues of copy without assign

2023-05-10 Thread Soumi Manna via Phabricator via cfe-commits
Manna updated this revision to Diff 521073.
Manna marked 2 inline comments as done.
Manna added a comment.

I have updated patch


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

https://reviews.llvm.org/D149718

Files:
  clang/include/clang/Analysis/BodyFarm.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp


Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -42,6 +42,7 @@
   Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
 
 ASTStmtWriter(const ASTStmtWriter&) = delete;
+ASTStmtWriter &operator=(const ASTStmtWriter &) = delete;
 
 uint64_t Emit() {
   assert(Code != serialization::STMT_NULL_PTR &&
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -762,7 +762,9 @@
 public:
   Strategy() = default;
   Strategy(const Strategy &) = delete; // Let's avoid copies.
+  Strategy &operator=(const Strategy &) = delete;
   Strategy(Strategy &&) = default;
+  Strategy &operator=(Strategy &&) = default;
 
   void set(const VarDecl *VD, Kind K) { Map[VD] = K; }
 
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -696,11 +696,13 @@
   AttributePool(AttributeFactory &factory) : Factory(factory) {}
 
   AttributePool(const AttributePool &) = delete;
+  AttributePool &operator=(const AttributePool &) = delete;
 
   ~AttributePool() { Factory.reclaimPool(*this); }
 
   /// Move the given pool's allocations to this pool.
   AttributePool(AttributePool &&pool) = default;
+  AttributePool &operator=(AttributePool &&pool) = default;
 
   AttributeFactory &getFactory() const { return Factory; }
 
@@ -912,6 +914,7 @@
 public:
   ParsedAttributes(AttributeFactory &factory) : pool(factory) {}
   ParsedAttributes(const ParsedAttributes &) = delete;
+  ParsedAttributes &operator=(const ParsedAttributes &) = delete;
 
   AttributePool &getPool() const { return pool; }
 
Index: clang/include/clang/Analysis/BodyFarm.h
===
--- clang/include/clang/Analysis/BodyFarm.h
+++ clang/include/clang/Analysis/BodyFarm.h
@@ -40,6 +40,9 @@
   /// Remove copy constructor to avoid accidental copying.
   BodyFarm(const BodyFarm &other) = delete;
 
+  /// Delete copy assignment operator.
+  BodyFarm &operator=(const BodyFarm &other) = delete;
+
 private:
   typedef llvm::DenseMap> BodyMap;
 


Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -42,6 +42,7 @@
   Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
 
 ASTStmtWriter(const ASTStmtWriter&) = delete;
+ASTStmtWriter &operator=(const ASTStmtWriter &) = delete;
 
 uint64_t Emit() {
   assert(Code != serialization::STMT_NULL_PTR &&
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -762,7 +762,9 @@
 public:
   Strategy() = default;
   Strategy(const Strategy &) = delete; // Let's avoid copies.
+  Strategy &operator=(const Strategy &) = delete;
   Strategy(Strategy &&) = default;
+  Strategy &operator=(Strategy &&) = default;
 
   void set(const VarDecl *VD, Kind K) { Map[VD] = K; }
 
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -696,11 +696,13 @@
   AttributePool(AttributeFactory &factory) : Factory(factory) {}
 
   AttributePool(const AttributePool &) = delete;
+  AttributePool &operator=(const AttributePool &) = delete;
 
   ~AttributePool() { Factory.reclaimPool(*this); }
 
   /// Move the given pool's allocations to this pool.
   AttributePool(AttributePool &&pool) = default;
+  AttributePool &operator=(AttributePool &&pool) = default;
 
   AttributeFactory &getFactory() const { return Factory; }
 
@@ -912,6 +914,7 @@
 public:
   ParsedAttributes(AttributeFactory &factory) : pool(factory) {}
   ParsedAttributes(const ParsedAttributes &) = delete;
+  ParsedAttributes &operator=(const ParsedAttributes &) = delete;
 
   AttributePool &getPool() const { return pool; }
 
Index: clang/include/clang/Analysis/BodyFarm.h
===
--- clang/include/clang/Analysis/BodyFarm.h
+++ clang/include/clang/Analysis

[PATCH] D146520: [clang-tidy] Fix checks filter with warnings-as-errors

2023-05-10 Thread kiwixz via Phabricator via cfe-commits
kiwixz added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146520

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


[PATCH] D149718: [NFC][Clang] Fix Coverity issues of copy without assign

2023-05-10 Thread Soumi Manna via Phabricator via cfe-commits
Manna added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:1786
 SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D);
+SemaDiagnosticBuilder &operator=(SemaDiagnosticBuilder &&D);
 SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default;

tahonermann wrote:
> Manna wrote:
> > tahonermann wrote:
> > > Since this class declares a move constructor, the declaration of the 
> > > implicit move assignment operator is inhibited and the implicitly 
> > > declared assignment operator is defined as deleted. This change declares 
> > > a move assignment operator but doesn't define it (perhaps `= delete` was 
> > > intended?). If support for assignment is not desired, then I think a 
> > > declaration of a deleted copy assignment operator is all that is needed 
> > > (matching the change made for `Strategy` below). Otherwise, I think a 
> > > defaulted copy assignment operator should be declared and a move 
> > > assignment operator should be defined that implements the same behavior 
> > > as the move constructor.
> > Thanks @tahonermann for the comments. 
> > 
> > >> think a defaulted copy assignment operator should be declared and a move 
> > >> assignment operator should be defined that implements the same behavior 
> > >> as the move constructor.
> > 
> > I have updated patch based on further analysis and my understanding. This 
> > seems reasonable to me.
> This change still declares a move assignment operator, but doesn't provide a 
> definition. The move constructor is implemented in `clang/lib/Sema/Sema.cpp`, 
> so I would expect to see the move assignment operator definition provided 
> there as well.
Thanks @tahonermann for the comments. I have removed `Sema.h`  change from the 
current patch. I will address it in a separate review pull request. Need to 
look into this more.  


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

https://reviews.llvm.org/D149718

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


[PATCH] D150291: [Clang] Rename internal type identifier(s) for `__bf16` to `BF16Ty`

2023-05-10 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs created this revision.
codemzs added reviewers: tahonermann, erichkeane, stuij.
Herald added subscribers: mattd, gchakrabarti, asavonic, ctetreau, kerbowa, 
arphaman, kristof.beyls, jvesely.
Herald added a project: All.
codemzs requested review of this revision.
Herald added subscribers: lldb-commits, cfe-commits, jholewinski.
Herald added projects: clang, LLDB.

  This change updates internal type identifiers for `__bf16` from
  `BFloat16Ty` to `BF16Ty` and renames any associated variables and
  function names accordingly. The rationale for this change comes from
  the review feedback on https://reviews.llvm.org/D149573, which pointed
  out the confusing naming issues between `__bf16` and the upcoming
  `std::bfloat16_t`. This modification only affects LLVM/Clang specific
  code and does not interfere with target-specific code, such as
  NeonEmitters, SVE Type, AArch64, etc. The existing names are being
  updated to avoid potential mistakes and enhance clarity in the codebase.
  The change is made in a separate patch, as suggested in the review, to
  ensure a smooth integration of std::bfloat16_t support.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150291

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/BuiltinTypes.def
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Basic/arm_neon_incl.td
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/tools/libclang/CXType.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -4909,7 +4909,7 @@
 case clang::BuiltinType::Float128:
 case clang::BuiltinType::Double:
 case clang::BuiltinType::LongDouble:
-case clang::BuiltinType::BFloat16:
+case clang::BuiltinType::BF16:
 case clang::BuiltinType::Ibm128:
   return lldb::eEncodingIEEE754;
 
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -618,7 +618,7 @@
 TKIND(Pipe);
 TKIND(Attributed);
 TKIND(BTFTagAttributed);
-TKIND(BFloat16);
+TKIND(BF16);
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) TKIND(Id);
 #include "clang/Basic/OpenCLImageTypes.def"
 #undef IMAGE_TYPE
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -7026,8 +7026,8 @@
 case PREDEF_TYPE_INT128_ID:
   T = Context.Int128Ty;
   break;
-case PREDEF_TYPE_BFLOAT16_ID:
-  T = Context.BFloat16Ty;
+case PREDEF_TYPE_BF16_ID:
+  T = Context.BF16Ty;
   break;
 case PREDEF_TYPE_HALF_ID:
   T = Context.HalfTy;
Index: clang/lib/Serialization/ASTCommon.cpp
===
--- clang/lib/Serialization/ASTCommon.cpp
+++ clang/lib/Serialization/ASTCommon.cpp
@@ -270,8 +270,8 @@
   case BuiltinType::OMPIterator:
 ID = PREDEF_TYPE_OMP_ITERATOR;
 break;
-  case BuiltinType::BFloat16:
-ID = PREDEF_TYPE_BFLOAT16_ID;
+  case BuiltinType::BF16:
+ID = PREDEF_TYPE_BF16_ID;
 break;
   }
 
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaTy

[PATCH] D150292: [clang][modules] Serialize `Module::DefinitionLoc`

2023-05-10 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, Bigcheese.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a prep patch for avoiding the quadratic number of calls to 
`HeaderSearch::lookupModule()` in `ASTReader` for each (transitively) loaded 
PCM file. (Specifically in the context of `clang-scan-deps`).

This patch explicitly serializes `Module::DefinitionLoc` so that we can stop 
relying on it being filled by the module map parser. This change also required 
change to the module map parser, where we used the absence of `DefinitionLoc` 
to determine whether a file came from a PCM file. We also need to make sure we 
consider the "containing" module map affecting when writing a PCM, so that it's 
not stripped during serialization, which ensures `DefinitionLoc` still ends up 
pointing to the correct offset. This is intended to be a NFC change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150292

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -201,7 +201,9 @@
 CB(F);
 FileID FID = SourceMgr.translateFile(F);
 SourceLocation Loc = SourceMgr.getIncludeLoc(FID);
-while (Loc.isValid()) {
+// The include location of inferred module maps can point into the header
+// file that triggered the inferring. Cut off the walk if that's the case.
+while (Loc.isValid() && isModuleMap(SourceMgr.getFileCharacteristic(Loc))) {
   FID = SourceMgr.getFileID(Loc);
   CB(*SourceMgr.getFileEntryRefForID(FID));
   Loc = SourceMgr.getIncludeLoc(FID);
@@ -210,11 +212,18 @@
 
   auto ProcessModuleOnce = [&](const Module *M) {
 for (const Module *Mod = M; Mod; Mod = Mod->Parent)
-  if (ProcessedModules.insert(Mod).second)
+  if (ProcessedModules.insert(Mod).second) {
+auto Insert = [&](FileEntryRef F) { ModuleMaps.insert(F); };
+// The containing module map is affecting, because it's being pointed
+// into by Module::DefinitionLoc.
+if (auto ModuleMapFile = MM.getContainingModuleMapFile(Mod))
+  ForIncludeChain(*ModuleMapFile, Insert);
+// For inferred modules, the module map that allowed inferring is not in
+// the include chain of the virtual containing module map file. It did
+// affect the compilation, though.
 if (auto ModuleMapFile = MM.getModuleMapFileForUniquing(Mod))
-  ForIncludeChain(*ModuleMapFile, [&](FileEntryRef F) {
-ModuleMaps.insert(F);
-  });
+  ForIncludeChain(*ModuleMapFile, Insert);
+  }
   };
 
   for (const Module *CurrentModule : ModulesToProcess) {
@@ -2720,6 +2729,7 @@
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // Kind
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Definition location
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem
@@ -2820,12 +2830,16 @@
   ParentID = SubmoduleIDs[Mod->Parent];
 }
 
+uint64_t DefinitionLoc =
+SourceLocationEncoding::encode(getAdjustedLocation(Mod->DefinitionLoc));
+
 // Emit the definition of the block.
 {
   RecordData::value_type Record[] = {SUBMODULE_DEFINITION,
  ID,
  ParentID,
  (RecordData::value_type)Mod->Kind,
+ DefinitionLoc,
  Mod->IsFramework,
  Mod->IsExplicit,
  Mod->IsSystem,
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -5599,7 +5599,7 @@
   break;
 
 case SUBMODULE_DEFINITION: {
-  if (Record.size() < 12)
+  if (Record.size() < 13)
 return llvm::createStringError(std::errc::illegal_byte_sequence,
"malformed module definition");
 
@@ -5608,6 +5608,7 @@
   SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]);
   SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]);
   Module::ModuleKind Kind = (Module::ModuleKind)

[PATCH] D150209: [clang][Interp] Add more shift error checking

2023-05-10 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 521078.

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

https://reviews.llvm.org/D150209

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/shifts.cpp


Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -152,4 +152,21 @@
   constexpr signed int R = (sizeof(unsigned) * 8) + 1;
   constexpr decltype(L) M  = (R > 32 && R < 64) ?  L << R : 0;
   constexpr decltype(L) M2 = (R > 32 && R < 64) ?  L >> R : 0;
+
+
+  constexpr int signedShift() { // cxx17-error {{never produces a constant 
expression}} \
+// ref-cxx17-error {{never produces a constant 
expression}}
+return 1024 << 31; // cxx17-warning {{signed shift result}} \
+   // ref-cxx17-warning {{signed shift result}} \
+   // cxx17-note {{signed left shift discards bits}} \
+   // ref-cxx17-note {{signed left shift discards bits}}
+  }
+
+  constexpr int negativeShift() { // cxx17-error {{never produces a constant 
expression}} \
+  // ref-cxx17-error {{never produces a 
constant expression}}
+return -1 << 2; // cxx17-warning {{shifting a negative signed value is 
undefined}} \
+// ref-cxx17-warning {{shifting a negative signed value is 
undefined}} \
+// cxx17-note {{left shift of negative value -1}} \
+// ref-cxx17-note {{left shift of negative value -1}}
+  }
 };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -109,8 +109,9 @@
 bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
 
 /// Checks if the shift operation is legal.
-template 
-bool CheckShift(InterpState &S, CodePtr OpPC, const RT &RHS, unsigned Bits) {
+template 
+bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
+unsigned Bits) {
   if (RHS.isNegative()) {
 const SourceInfo &Loc = S.Current->getSource(OpPC);
 S.CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
@@ -125,6 +126,16 @@
 QualType Ty = E->getType();
 S.CCEDiag(E, diag::note_constexpr_large_shift) << Val << Ty << Bits;
 return false;
+  } else if (LHS.isSigned() && !S.getLangOpts().CPlusPlus20) {
+const Expr *E = S.Current->getExpr(OpPC);
+// C++11 [expr.shift]p2: A signed left shift must have a non-negative
+// operand, and must not overflow the corresponding unsigned type.
+// C++2a [expr.shift]p2: E1 << E2 is the unique value congruent to
+// E1 x 2^E2 module 2^N.
+if (LHS.isNegative())
+  S.CCEDiag(E, diag::note_constexpr_lshift_of_negative) << LHS.toAPSInt();
+else if (LHS.toUnsigned().countLeadingZeros() < static_cast(RHS))
+  S.CCEDiag(E, diag::note_constexpr_lshift_discards);
   }
   return true;
 }
@@ -1612,7 +1623,7 @@
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;
@@ -1629,7 +1640,7 @@
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -127,7 +127,11 @@
 return Compare(V, RHS.V);
   }
 
-  unsigned countLeadingZeros() const { return llvm::countl_zero(V); }
+  unsigned countLeadingZeros() const {
+if constexpr (!Signed)
+  return llvm::countl_zero(V);
+llvm_unreachable("Don't call countLeadingZeros() on signed types.");
+  }
 
   Integral truncate(unsigned TruncBits) const {
 if (TruncBits >= Bits)


Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -152,4 +152,21 @@
   constexpr signed int R = (sizeof(unsigned) * 8) + 1;
   constexpr decltype(L) M  = (R > 32 && R < 64) ?  L << R : 0;
   constexpr decltype(L) M2 = (R > 32 && R < 64) ?  L >> R : 0;
+
+
+  constexpr int signedShift() { // cxx17-error {{never produces a constant expression}} \
+// ref-cxx17-error {{never produces a constant expression}}
+return 1024 << 31; // cxx17-warning {{signed shift result}} \
+   // ref-cxx17-warning {{signed shift result}} \
+   // cxx17-note {{signed left shift discards bits}} \
+   // ref-cxx17-note {{signed left shift discards bits}}

[PATCH] D150209: [clang][Interp] Add more shift error checking

2023-05-10 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 521082.

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

https://reviews.llvm.org/D150209

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/shifts.cpp


Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -152,4 +152,21 @@
   constexpr signed int R = (sizeof(unsigned) * 8) + 1;
   constexpr decltype(L) M  = (R > 32 && R < 64) ?  L << R : 0;
   constexpr decltype(L) M2 = (R > 32 && R < 64) ?  L >> R : 0;
+
+
+  constexpr int signedShift() { // cxx17-error {{never produces a constant 
expression}} \
+// ref-cxx17-error {{never produces a constant 
expression}}
+return 1024 << 31; // cxx17-warning {{signed shift result}} \
+   // ref-cxx17-warning {{signed shift result}} \
+   // cxx17-note {{signed left shift discards bits}} \
+   // ref-cxx17-note {{signed left shift discards bits}}
+  }
+
+  constexpr int negativeShift() { // cxx17-error {{never produces a constant 
expression}} \
+  // ref-cxx17-error {{never produces a 
constant expression}}
+return -1 << 2; // cxx17-warning {{shifting a negative signed value is 
undefined}} \
+// ref-cxx17-warning {{shifting a negative signed value is 
undefined}} \
+// cxx17-note {{left shift of negative value -1}} \
+// ref-cxx17-note {{left shift of negative value -1}}
+  }
 };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -109,8 +109,9 @@
 bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
 
 /// Checks if the shift operation is legal.
-template 
-bool CheckShift(InterpState &S, CodePtr OpPC, const RT &RHS, unsigned Bits) {
+template 
+bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
+unsigned Bits) {
   if (RHS.isNegative()) {
 const SourceInfo &Loc = S.Current->getSource(OpPC);
 S.CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
@@ -126,6 +127,20 @@
 S.CCEDiag(E, diag::note_constexpr_large_shift) << Val << Ty << Bits;
 return false;
   }
+
+  if (LHS.isSigned() && !S.getLangOpts().CPlusPlus20) {
+const Expr *E = S.Current->getExpr(OpPC);
+// C++11 [expr.shift]p2: A signed left shift must have a non-negative
+// operand, and must not overflow the corresponding unsigned type.
+if (LHS.isNegative())
+  S.CCEDiag(E, diag::note_constexpr_lshift_of_negative) << LHS.toAPSInt();
+else if (LHS.toUnsigned().countLeadingZeros() < static_cast(RHS))
+  S.CCEDiag(E, diag::note_constexpr_lshift_discards);
+  }
+
+  // C++2a [expr.shift]p2: E1 << E2 is the unique value congruent to
+  // E1 x 2^E2 module 2^N.
+
   return true;
 }
 
@@ -1612,7 +1627,7 @@
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;
@@ -1629,7 +1644,7 @@
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -127,7 +127,11 @@
 return Compare(V, RHS.V);
   }
 
-  unsigned countLeadingZeros() const { return llvm::countl_zero(V); }
+  unsigned countLeadingZeros() const {
+if constexpr (!Signed)
+  return llvm::countl_zero(V);
+llvm_unreachable("Don't call countLeadingZeros() on signed types.");
+  }
 
   Integral truncate(unsigned TruncBits) const {
 if (TruncBits >= Bits)


Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -152,4 +152,21 @@
   constexpr signed int R = (sizeof(unsigned) * 8) + 1;
   constexpr decltype(L) M  = (R > 32 && R < 64) ?  L << R : 0;
   constexpr decltype(L) M2 = (R > 32 && R < 64) ?  L >> R : 0;
+
+
+  constexpr int signedShift() { // cxx17-error {{never produces a constant expression}} \
+// ref-cxx17-error {{never produces a constant expression}}
+return 1024 << 31; // cxx17-warning {{signed shift result}} \
+   // ref-cxx17-warning {{signed shift result}} \
+   // cxx17-note {{signed left shift discards bits}} \
+   // ref-cxx17-note {{signed left shift discards bits}}
+  }
+
+  constexpr int negativ

[PATCH] D150278: [Headers][doc] Add "shift" intrinsic descriptions to avx2intrin.h

2023-05-10 Thread Paul Robinson 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 rG642bd1123d05: [Headers][doc] Add "shift" intrinsic 
descriptions to avx2intrin.h (authored by probinson).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150278

Files:
  clang/lib/Headers/avx2intrin.h

Index: clang/lib/Headers/avx2intrin.h
===
--- clang/lib/Headers/avx2intrin.h
+++ clang/lib/Headers/avx2intrin.h
@@ -493,108 +493,404 @@
 return (__m256i)__builtin_ia32_psignd256((__v8si)__a, (__v8si)__b);
 }
 
+/// Shifts each 128-bit half of the 256-bit integer vector \a a left by
+///\a imm bytes, shifting in zero bytes, and returns the result. If \a imm
+///is greater than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// \code
+/// __m256i _mm256_slli_si256(__m256i a, const int imm);
+/// \endcode
+///
+/// This intrinsic corresponds to the \c VPSLLDQ instruction.
+///
+/// \param a
+///A 256-bit integer vector to be shifted.
+/// \param imm
+/// An unsigned immediate value specifying the shift count (in bytes).
+/// \returns A 256-bit integer vector containing the result.
 #define _mm256_slli_si256(a, imm) \
   ((__m256i)__builtin_ia32_pslldqi256_byteshift((__v4di)(__m256i)(a), (int)(imm)))
 
+/// Shifts each 128-bit half of the 256-bit integer vector \a a left by
+///\a imm bytes, shifting in zero bytes, and returns the result. If \a imm
+///is greater than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// \code
+/// __m256i _mm256_bslli_epi128(__m256i a, const int imm);
+/// \endcode
+///
+/// This intrinsic corresponds to the \c VPSLLDQ instruction.
+///
+/// \param a
+///A 256-bit integer vector to be shifted.
+/// \param imm
+///An unsigned immediate value specifying the shift count (in bytes).
+/// \returns A 256-bit integer vector containing the result.
 #define _mm256_bslli_epi128(a, imm) \
   ((__m256i)__builtin_ia32_pslldqi256_byteshift((__v4di)(__m256i)(a), (int)(imm)))
 
+/// Shifts each 16-bit element of the 256-bit vector of [16 x i16] in \a __a
+///left by \a __count bits, shifting in zero bits, and returns the result.
+///If \a __count is greater than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPSLLW instruction.
+///
+/// \param __a
+///A 256-bit vector of [16 x i16] to be shifted.
+/// \param __count
+///An unsigned integer value specifying the shift count (in bits).
+/// \returns A 256-bit vector of [16 x i16] containing the result.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_slli_epi16(__m256i __a, int __count)
 {
   return (__m256i)__builtin_ia32_psllwi256((__v16hi)__a, __count);
 }
 
+/// Shifts each 16-bit element of the 256-bit vector of [16 x i16] in \a __a
+///left by the number of bits specified by the lower 64 bits of \a __count,
+///shifting in zero bits, and returns the result. If \a __count is greater
+///than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPSLLW instruction.
+///
+/// \param __a
+///A 256-bit vector of [16 x i16] to be shifted.
+/// \param __count
+///A 128-bit vector of [2 x i64] whose lower element gives the unsigned
+///shift count (in bits). The upper element is ignored.
+/// \returns A 256-bit vector of [16 x i16] containing the result.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_sll_epi16(__m256i __a, __m128i __count)
 {
   return (__m256i)__builtin_ia32_psllw256((__v16hi)__a, (__v8hi)__count);
 }
 
+/// Shifts each 32-bit element of the 256-bit vector of [8 x i32] in \a __a
+///left by \a __count bits, shifting in zero bits, and returns the result.
+///If \a __count is greater than 31, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPSLLD instruction.
+///
+/// \param __a
+///A 256-bit vector of [8 x i32] to be shifted.
+/// \param __count
+///An unsigned integer value specifying the shift count (in bits).
+/// \returns A 256-bit vector of [8 x i32] containing the result.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_slli_epi32(__m256i __a, int __count)
 {
   return (__m256i)__builtin_ia32_pslldi256((__v8si)__a, __count);
 }
 
+/// Shifts each 32-bit element of the 256-bit vector of [8 x i32] in \a __a
+///left by the number of bits given in the lower 64 bits of \a __count,
+///shifting in zero bits, and returns the result. If \a __count is greater
+///than 31, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPSLLD instruction.
+///
+/// \param __a
+///A 256-bit vector of [8 x i32] to be shifted.
+///

[clang] 642bd11 - [Headers][doc] Add "shift" intrinsic descriptions to avx2intrin.h

2023-05-10 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2023-05-10T13:14:41-07:00
New Revision: 642bd1123d05e594cd0ef1527516f421ac07c5a6

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

LOG: [Headers][doc] Add "shift" intrinsic descriptions to avx2intrin.h

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

Added: 


Modified: 
clang/lib/Headers/avx2intrin.h

Removed: 




diff  --git a/clang/lib/Headers/avx2intrin.h b/clang/lib/Headers/avx2intrin.h
index 33f24f2443b3a..1fbc4edafbd7f 100644
--- a/clang/lib/Headers/avx2intrin.h
+++ b/clang/lib/Headers/avx2intrin.h
@@ -493,108 +493,404 @@ _mm256_sign_epi32(__m256i __a, __m256i __b)
 return (__m256i)__builtin_ia32_psignd256((__v8si)__a, (__v8si)__b);
 }
 
+/// Shifts each 128-bit half of the 256-bit integer vector \a a left by
+///\a imm bytes, shifting in zero bytes, and returns the result. If \a imm
+///is greater than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// \code
+/// __m256i _mm256_slli_si256(__m256i a, const int imm);
+/// \endcode
+///
+/// This intrinsic corresponds to the \c VPSLLDQ instruction.
+///
+/// \param a
+///A 256-bit integer vector to be shifted.
+/// \param imm
+/// An unsigned immediate value specifying the shift count (in bytes).
+/// \returns A 256-bit integer vector containing the result.
 #define _mm256_slli_si256(a, imm) \
   ((__m256i)__builtin_ia32_pslldqi256_byteshift((__v4di)(__m256i)(a), 
(int)(imm)))
 
+/// Shifts each 128-bit half of the 256-bit integer vector \a a left by
+///\a imm bytes, shifting in zero bytes, and returns the result. If \a imm
+///is greater than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// \code
+/// __m256i _mm256_bslli_epi128(__m256i a, const int imm);
+/// \endcode
+///
+/// This intrinsic corresponds to the \c VPSLLDQ instruction.
+///
+/// \param a
+///A 256-bit integer vector to be shifted.
+/// \param imm
+///An unsigned immediate value specifying the shift count (in bytes).
+/// \returns A 256-bit integer vector containing the result.
 #define _mm256_bslli_epi128(a, imm) \
   ((__m256i)__builtin_ia32_pslldqi256_byteshift((__v4di)(__m256i)(a), 
(int)(imm)))
 
+/// Shifts each 16-bit element of the 256-bit vector of [16 x i16] in \a __a
+///left by \a __count bits, shifting in zero bits, and returns the result.
+///If \a __count is greater than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPSLLW instruction.
+///
+/// \param __a
+///A 256-bit vector of [16 x i16] to be shifted.
+/// \param __count
+///An unsigned integer value specifying the shift count (in bits).
+/// \returns A 256-bit vector of [16 x i16] containing the result.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_slli_epi16(__m256i __a, int __count)
 {
   return (__m256i)__builtin_ia32_psllwi256((__v16hi)__a, __count);
 }
 
+/// Shifts each 16-bit element of the 256-bit vector of [16 x i16] in \a __a
+///left by the number of bits specified by the lower 64 bits of \a __count,
+///shifting in zero bits, and returns the result. If \a __count is greater
+///than 15, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPSLLW instruction.
+///
+/// \param __a
+///A 256-bit vector of [16 x i16] to be shifted.
+/// \param __count
+///A 128-bit vector of [2 x i64] whose lower element gives the unsigned
+///shift count (in bits). The upper element is ignored.
+/// \returns A 256-bit vector of [16 x i16] containing the result.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_sll_epi16(__m256i __a, __m128i __count)
 {
   return (__m256i)__builtin_ia32_psllw256((__v16hi)__a, (__v8hi)__count);
 }
 
+/// Shifts each 32-bit element of the 256-bit vector of [8 x i32] in \a __a
+///left by \a __count bits, shifting in zero bits, and returns the result.
+///If \a __count is greater than 31, the returned result is all zeroes.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPSLLD instruction.
+///
+/// \param __a
+///A 256-bit vector of [8 x i32] to be shifted.
+/// \param __count
+///An unsigned integer value specifying the shift count (in bits).
+/// \returns A 256-bit vector of [8 x i32] containing the result.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_slli_epi32(__m256i __a, int __count)
 {
   return (__m256i)__builtin_ia32_pslldi256((__v8si)__a, __count);
 }
 
+/// Shifts each 32-bit element of the 256-bit vector of [8 x i32] in \a __a
+///left by the number of bits given in the lower 64 bits of \a __count,
+///shifting in zero bits, and returns the result. If \a __count is greater
+///than 31, the returned result

[PATCH] D150295: [MemProf] Update hot/cold information after importing

2023-05-10 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added a reviewer: davidxl.
Herald added subscribers: ormris, steven_wu, hiraditya.
Herald added a project: All.
tejohnson requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

The support added by D149215  to remove 
memprof metadata and attributes
if we don't link with an allocator supporting hot/cold operator new
interfaces did not update imported code. Move the update handling later
in the ThinLTO backend to just after importing, and update the test to
check this case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150295

Files:
  clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll
  llvm/lib/LTO/LTOBackend.cpp
  llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll

Index: llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll
===
--- llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll
+++ llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll
@@ -3,37 +3,53 @@
 ;; from being removed from the LTO backend, and vice versa without passing
 ;; -supports-hot-cold-new.
 
+; RUN: split-file %s %t
+
 ;; First check with -supports-hot-cold-new.
-; RUN: opt -thinlto-bc %s >%t.o
-; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
+; RUN: opt -thinlto-bc %t/main.ll >%t/main.o
+; RUN: opt -thinlto-bc %t/foo.ll >%t/foo.o
+; RUN: llvm-lto2 run %t/main.o %t/foo.o -enable-memprof-context-disambiguation \
 ; RUN:	-supports-hot-cold-new \
-; RUN:	-r=%t.o,main,plx \
-; RUN:	-r=%t.o,_Znam, \
+; RUN:	-r=%t/main.o,main,plx \
+; RUN:	-r=%t/main.o,bar,plx \
+; RUN:	-r=%t/main.o,foo, \
+; RUN:	-r=%t/main.o,_Znam, \
+; RUN:	-r=%t/foo.o,foo,plx \
+; RUN:	-r=%t/foo.o,_Znam, \
 ; RUN:	-memprof-dump-ccg \
 ; RUN:	 -save-temps \
 ; RUN:	-o %t.out 2>&1 | FileCheck %s --check-prefix=DUMP
 ; DUMP: Callsite Context Graph:
 
-; RUN: llvm-dis %t.out.1.0.preopt.bc -o - | FileCheck %s --check-prefix=IR
+; RUN: llvm-dis %t.out.1.3.import.bc -o - | FileCheck %s --check-prefix=IR
+; IR: @main()
+; IR: !memprof {{.*}} !callsite
+; IR: @_Znam(i64 0) #[[ATTR:[0-9]+]]
+; IR: @bar()
 ; IR: !memprof {{.*}} !callsite
-; IR: "memprof"="cold"
+; IR: @_Znam(i64 0) #[[ATTR:[0-9]+]]
+; IR: attributes #[[ATTR]] = { "memprof"="cold" }
 
 ;; Next check without -supports-hot-cold-new, we should not perform
 ;; context disambiguation, and we should strip memprof metadata and
 ;; attributes before optimization.
-; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
-; RUN:	-r=%t.o,main,plx \
-; RUN:	-r=%t.o,_Znam, \
+; RUN: llvm-lto2 run %t/main.o %t/foo.o -enable-memprof-context-disambiguation \
+; RUN:	-r=%t/main.o,main,plx \
+; RUN:	-r=%t/main.o,bar,plx \
+; RUN:	-r=%t/main.o,foo, \
+; RUN:	-r=%t/main.o,_Znam, \
+; RUN:	-r=%t/foo.o,foo,plx \
+; RUN:	-r=%t/foo.o,_Znam, \
 ; RUN:	-memprof-dump-ccg \
 ; RUN:	 -save-temps \
 ; RUN:	-o %t.out 2>&1 | FileCheck %s --allow-empty \
 ; RUN:  --implicit-check-not "Callsite Context Graph:"
 
-; RUN: llvm-dis %t.out.1.0.preopt.bc -o - | FileCheck %s \
+; RUN: llvm-dis %t.out.1.3.import.bc -o - | FileCheck %s \
 ; RUN: --implicit-check-not "!memprof" --implicit-check-not "!callsite" \
 ; RUN: --implicit-check-not "memprof"="cold"
 
-source_filename = "memprof-supports-hot-cold-new.ll"
+;--- main.ll
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 
@@ -44,6 +60,13 @@
   ret i32 0
 }
 
+define void @bar() {
+  call void @foo()
+  ret void
+}
+
+declare void @foo()
+
 declare ptr @_Znam(i64)
 
 attributes #0 = { noinline optnone }
@@ -55,3 +78,25 @@
 !3 = !{!4, !"cold"}
 !4 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
 !5 = !{i64 9086428284934609951}
+
+;--- foo.ll
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @foo() {
+entry:
+  %call = call ptr @_Znam(i64 0), !memprof !0, !callsite !5
+  %call2 = call ptr @_Znam(i64 0) #1
+  ret i32 0
+}
+
+declare ptr @_Znam(i64)
+
+attributes #1 = { "memprof"="cold" }
+
+!0 = !{!1, !3}
+!1 = !{!2, !"notcold"}
+!2 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414}
+!3 = !{!4, !"cold"}
+!4 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
+!5 = !{i64 9086428284934609951}
Index: llvm/lib/LTO/LTOBackend.cpp
===
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -565,8 +565,6 @@
   // the module, if applicable.
   Mod.setPartialSampleProfileRatio(CombinedIndex);
 
-  updateMemProfAttributes(Mod, CombinedIndex);
-
   updatePublicTypeTestCalls(Mod, CombinedIndex.withWholeProgramVisibility());
 
  

[PATCH] D150140: [NFC][CLANG] Fix Static Code Analysis Concerns

2023-05-10 Thread Soumi Manna via Phabricator via cfe-commits
Manna updated this revision to Diff 521089.
Manna added a comment.

Fix Coverity complain about shift overflow issue


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

https://reviews.llvm.org/D150140

Files:
  clang/utils/TableGen/SveEmitter.cpp


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -299,6 +299,7 @@
 if (It != FlagTypes.end()) {
   uint64_t Mask = It->getValue();
   unsigned Shift = llvm::countr_zero(Mask);
+  assert(Shift < 64 && "Mask value produced an invalid shift value");
   return (V << Shift) & Mask;
 }
 llvm_unreachable("Unsupported flag");


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -299,6 +299,7 @@
 if (It != FlagTypes.end()) {
   uint64_t Mask = It->getValue();
   unsigned Shift = llvm::countr_zero(Mask);
+  assert(Shift < 64 && "Mask value produced an invalid shift value");
   return (V << Shift) & Mask;
 }
 llvm_unreachable("Unsupported flag");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150140: [NFC][CLANG] Fix Static Code Analysis Concerns

2023-05-10 Thread Soumi Manna via Phabricator via cfe-commits
Manna marked an inline comment as done.
Manna added inline comments.



Comment at: clang/utils/TableGen/SveEmitter.cpp:302
   unsigned Shift = llvm::countr_zero(Mask);
+  assert(Shift >= 64 && "Shift is out of encodable range");
   return (V << Shift) & Mask;

tahonermann wrote:
> Manna wrote:
> > sdesmalen wrote:
> > > erichkeane wrote:
> > > > sdesmalen wrote:
> > > > > erichkeane wrote:
> > > > > > Shouldn't this be: `assert(Shift < 64 &&"...")`?
> > > > > > 
> > > > > > `expr.shift` (https://eel.is/c++draft/expr.shift) says:
> > > > > > ```
> > > > > > The operands shall be of integral or unscoped enumeration type and 
> > > > > > integral promotions are performed.
> > > > > > The type of the result is that of the promoted left operand.
> > > > > > The behavior is undefined if the right operand is negative, or 
> > > > > > greater than or equal to the width of the promoted left operand.```
> > > > > > 
> > > > > > uint64 stays as an `unsigned long`, so it is still 64 bits, so the 
> > > > > > only invalid value for `Shift` is 64 (though >64 is 'nonsense', but 
> > > > > > only impossible because of `llvm::countr_zero`).
> > > > > > 
> > > > > > One thing to consider: I wonder if we should instead be changing 
> > > > > > the 'shift' to be:
> > > > > > 
> > > > > > `(V << (Shift % 64)) && Mask` ?  It looks like `arm_sve.td` has the 
> > > > > > `NoFlags` value as zero, which I think will end up going through 
> > > > > > here possibly (or at least, inserted into `FlagTypes`.
> > > > > > 
> > > > > > So I suspect an assert might not be sufficient, since a 64 bit 
> > > > > > shift is possible in that case (since a zero 'Mask' is the only 
> > > > > > case where `countr_zero` will end up being 64).
> > > > > > 
> > > > > > 
> > > > > > So I suspect an assert might not be sufficient, since a 64 bit 
> > > > > > shift is possible in that case (since a zero 'Mask' is the only 
> > > > > > case where countr_zero will end up being 64).
> > > > > It should be fine to assert that `Mask != 0`, since that would be an 
> > > > > invalid mask.
> > > > Thanks for the comment @sdesmalen!  Is there something that prevents 
> > > > the `NoFlags` from being passed as the `MaskName` here?  
> > > There's nothing that actively prevents it, but `encodeFlag` is a utility 
> > > function that has no uses outside this file and has only 4 uses. Adding 
> > > an assert should be sufficient.
> > Thank you for the explanation!
> I'm not sure if asserting `Mask != 0` will suffice to silence Coverity. While 
> Coverity can specifically observe that `countr_zero` might return 0 (because 
> `TrailingZerosCounter::count()` has a `return 64` statement), I don't 
> think Coverity can determine that the function can't return 65 or higher. I 
> think Erich's initial intuition is correct; the concern that Coverity is 
> reporting is that the shift might overflow, so that is what should be guarded.
>   assert(Shift < 64 && "Mask value produced an invalid shift value");
Thanks @tahonermann for comments. I have updated my patch to guard the shift 
overflow issue with Mask value.


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

https://reviews.llvm.org/D150140

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


[PATCH] D150209: [clang][Interp] Add more shift error checking

2023-05-10 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/AST/Interp/Interp.h:141-142
+
+  // C++2a [expr.shift]p2: E1 << E2 is the unique value congruent to
+  // E1 x 2^E2 module 2^N.
+

Just adding a reference to 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0907r4.html since 
that is the paper that changed this behavior


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

https://reviews.llvm.org/D150209

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


[PATCH] D150295: [MemProf] Update hot/cold information after importing

2023-05-10 Thread David Li via Phabricator via cfe-commits
davidxl accepted this revision.
davidxl 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/D150295/new/

https://reviews.llvm.org/D150295

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


[PATCH] D146148: Float_t and double_t types shouldn't be modified by #pragma clang fp eval_method

2023-05-10 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D146148#4330971 , @rjmccall wrote:

> In D146148#4330611 , @zahiraam 
> wrote:
>
>> In D146148#4221651 , @rjmccall 
>> wrote:
>>
>>> In D146148#4220591 , @zahiraam 
>>> wrote:
>>>
 In D146148#4220495 , 
 @aaron.ballman wrote:

> In D146148#4220433 , @zahiraam 
> wrote:
>
>> In D146148#4220268 , @rjmccall 
>> wrote:
>>
>>> Okay, so modifying `math.h` to use this attribute is acceptable?  
>>> That's great, that's definitely the best outcome for the compiler.
>>>
>>> Just a minor request about the diagnostic name, but otherwise LGTM.
>>
>> Yes. Added the attribute inside the included math.h header file.
>
> How does this work for, say, glibc, musl, or MSVC CRT? Won't those math.h 
> headers lack the attribute and thus run into problems when used with 
> Clang?

 Good point! @rjmccall are you thinking of something in particular with the 
 attribute?
>>>
>>> Zahira, this is what I was asking you when I asked whether modifying the 
>>> math.h header was acceptable: whether you were prepared to accept that the 
>>> warning would only fire on system math.h headers that we'd modified, or 
>>> whether you cared about making it work with non-cooperative headers.  I 
>>> wasn't asking if you were willing to change the test code.
>>>
 If not I guess we will have to rely on string comparison for all the 
 typedef in the TU. Aaron pointed out the compile time overhead.
>>>
>>> Well, the compile-time overhead of doing this on every typedef 
>>> *declaration* is way better than the overhead of doing this on every type 
>>> lookup, at least.
>>>
>>> Anyway, there are three possibilities I can see:
>>>
>>> - We accept that this needs cooperative system headers.
>>> - We add a math.h compiler header that `#include_next`s the system math.h 
>>> and then adds the attribute.  I believe you can just add an attribute to a 
>>> typedef retroactively with something like `typedef float_t float_t 
>>> __attribute__((whatever))`.
>>> - We do checks on every typedef declaration.  There's a builtin-identifier 
>>> trick that we do with library functions that we should be able to 
>>> generalize to typedefs, so you wouldn't need to actually do string 
>>> comparisons, you'd just check whether the `IdentifierInfo*` was storing a 
>>> special ID.  We'd set that up in `initializeBuiltins` at the start of the 
>>> translation unit, so the overhead would just be that we'd create two extra 
>>> `IdentifierInfo*`s in every TU.
>>>
>>> The builtin ID logic is currently specific to builtin *functions*, and I 
>>> don't think we'd want to hack typedef names into that.  But the same 
>>> storage in `IdentifierInfo*` is also used for identifying the ObjC 
>>> context-sensitive keywords, by just offsetting the builtin IDs by the 
>>> NUM_OBJC_KEYWORD.  You should be able to generalize that by also 
>>> introducing a concept of a builtin *type* name, so that e.g. IDs in 
>>> [0,NUM_OBJC_KEYWORDS) are ObjCKeywordKinds, IDs in [NUM_OBJC_KEYWORDS, 
>>> NUM_OBJC_KEYWORDS+NUM_BUILTIN_TYPES) are BuiltinTypeKinds (when you 
>>> subtract NUM_OBJC_KEYWORDS), and IDs in 
>>> [NUM_OBJC_KEYWORDS+NUM_BUILTIN_TYPES,∞) are builtin function IDs (when you 
>>> subtract NUM_OBJC_KEYWORDS+NUM_BUILTIN_TYPES).
>>
>> Reading this more carefully... Does that mean that we initialize the 
>> float_t, double_t in initializeBuiltins  even if they are not used in the 
>> source code?
>
> Yes.  If we decide this is an overhead worth eliminating, we'll find a way to 
> do it lazily to the builtins, and then we'll be able to take advantage of it 
> here, too.  The builtins are a much larger contributor to overhead.
>
>> Also not sure how to define the NUM_BUILTIN_TYPES since I don't need to add 
>> it to TokenKinds.h? I was proposing to do something like this:
>> enum InterestingIdentifierKind {
>> #define Interesting_Identifier(X) X,
>> #include "clang/Basic/TokenKinds.def"
>>
>>   NUM_INTERESTING_IDENTIFIERS
>>
>> };
>> But I guess I don't need since we don't want to add additional storage. Do I 
>> understand things correctly?
>
> We should have an enum like this, yes.  And this is what we do in 
> `IdentifierTable.h` for all the other kinds.  Alternatively, you can just 
> hard-code the number and then static_assert that it's correct in some .cpp 
> file.
>
> FWIW, I think I like NUM_INTERESTING_IDENTIFIERS as a name rather than 
> NUM_BUILTIN_TYPES.

Okay, so I did add that in TokenKinds.h. Isn't that the right place for it? The 
same way it's done for the other builtins? And in TokenKinds.def I added the 
lines for the interesting identifiers?

In D146148#4330971 

[PATCH] D146148: Float_t and double_t types shouldn't be modified by #pragma clang fp eval_method

2023-05-10 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

> Okay, so I did add that in TokenKinds.h. Isn't that the right place for it? 
> The same way it's done for the other builtins? And in TokenKinds.def I added 
> the lines for the interesting identifiers?

What you're doing in `TokenKinds.{def,h}` seems fine.  What I'm objecting to is 
adding another field to `IdentifierInfo` to store it instead of fitting it into 
`ObjCOrBuiltinID`.  Currently an given identifier is either normal, an ObjC 
keyword, or a builtin ID, and it determines this by checking what range of 
values ObjCOrBuiltinID fits into.  You can use the same idea to allow an 
identifier to be either normal, an ObjC keyword, a builtin ID, or an 
interesting.




Comment at: clang/include/clang/Basic/TokenKinds.def:89
+#ifndef Interesting_Identifier
+#define Interesting_Identifier(X)
+#endif

Please follow the existing pattern by spelling this INTERESTING_IDENTIFIER.


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

https://reviews.llvm.org/D146148

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


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-05-10 Thread Louis Dionne via Phabricator via cfe-commits
ldionne accepted this revision as: libc++abi.
ldionne added a comment.
This revision is now accepted and ready to land.

Code changes in libc++ and libc++abi LGTM. I am neutral on whether the 
diagnostic is worth adding, but don't consider libc++ and libc++abi as blockers 
for this patch.




Comment at: libcxxabi/src/cxa_personality.cpp:721
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = ((actions & _UA_SEARCH_PHASE) ? 
_URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND);
 return;

Double-parens are not required.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

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


[clang] 9e280c4 - [MemProf] Update hot/cold information after importing

2023-05-10 Thread Teresa Johnson via cfe-commits

Author: Teresa Johnson
Date: 2023-05-10T14:58:35-07:00
New Revision: 9e280c47588bfaf008a5fb091cd47df92b9c4264

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

LOG: [MemProf] Update hot/cold information after importing

The support added by D149215 to remove memprof metadata and attributes
if we don't link with an allocator supporting hot/cold operator new
interfaces did not update imported code. Move the update handling later
in the ThinLTO backend to just after importing, and update the test to
check this case.

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

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll
llvm/lib/LTO/LTOBackend.cpp
llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll 
b/clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll
index e213fbaf3fa14..08c1a2946971c 100644
--- a/clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll
+++ b/clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll
@@ -22,7 +22,7 @@
 
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t1.o -x ir %t.o -c 
-fthinlto-index=%t.o.thinlto.bc -save-temps=obj
 
-; RUN: llvm-dis %t.s.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
+; RUN: llvm-dis %t.s.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 ; CHECK-IR: !memprof {{.*}} !callsite
 ; CHECK-IR: "memprof"="cold"
 
@@ -42,7 +42,7 @@
 
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t1.o -x ir %t.o -c 
-fthinlto-index=%t.o.thinlto.bc -save-temps=obj
 
-; RUN: llvm-dis %t.s.0.preopt.bc -o - | FileCheck %s \
+; RUN: llvm-dis %t.s.3.import.bc -o - | FileCheck %s \
 ; RUN: --implicit-check-not "!memprof" --implicit-check-not "!callsite" \
 ; RUN: --implicit-check-not "memprof"="cold"
 

diff  --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index a18963fcaf85d..a089cbe63963e 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -565,8 +565,6 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, 
AddStreamFn AddStream,
   // the module, if applicable.
   Mod.setPartialSampleProfileRatio(CombinedIndex);
 
-  updateMemProfAttributes(Mod, CombinedIndex);
-
   updatePublicTypeTestCalls(Mod, CombinedIndex.withWholeProgramVisibility());
 
   if (Conf.CodeGenOnly) {
@@ -653,6 +651,9 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, 
AddStreamFn AddStream,
   if (Error Err = Importer.importFunctions(Mod, ImportList).takeError())
 return Err;
 
+  // Do this after any importing so that imported code is updated.
+  updateMemProfAttributes(Mod, CombinedIndex);
+
   if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod))
 return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
 

diff  --git a/llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll 
b/llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll
index 9e69377d14443..7a4d860d8d0d9 100644
--- a/llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll
+++ b/llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll
@@ -3,37 +3,53 @@
 ;; from being removed from the LTO backend, and vice versa without passing
 ;; -supports-hot-cold-new.
 
+; RUN: split-file %s %t
+
 ;; First check with -supports-hot-cold-new.
-; RUN: opt -thinlto-bc %s >%t.o
-; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
+; RUN: opt -thinlto-bc %t/main.ll >%t/main.o
+; RUN: opt -thinlto-bc %t/foo.ll >%t/foo.o
+; RUN: llvm-lto2 run %t/main.o %t/foo.o -enable-memprof-context-disambiguation 
\
 ; RUN: -supports-hot-cold-new \
-; RUN: -r=%t.o,main,plx \
-; RUN: -r=%t.o,_Znam, \
+; RUN: -r=%t/main.o,main,plx \
+; RUN: -r=%t/main.o,bar,plx \
+; RUN: -r=%t/main.o,foo, \
+; RUN: -r=%t/main.o,_Znam, \
+; RUN: -r=%t/foo.o,foo,plx \
+; RUN: -r=%t/foo.o,_Znam, \
 ; RUN: -memprof-dump-ccg \
 ; RUN:  -save-temps \
 ; RUN: -o %t.out 2>&1 | FileCheck %s --check-prefix=DUMP
 ; DUMP: Callsite Context Graph:
 
-; RUN: llvm-dis %t.out.1.0.preopt.bc -o - | FileCheck %s --check-prefix=IR
+; RUN: llvm-dis %t.out.1.3.import.bc -o - | FileCheck %s --check-prefix=IR
+; IR: @main()
+; IR: !memprof {{.*}} !callsite
+; IR: @_Znam(i64 0) #[[ATTR:[0-9]+]]
+; IR: @bar()
 ; IR: !memprof {{.*}} !callsite
-; IR: "memprof"="cold"
+; IR: @_Znam(i64 0) #[[ATTR:[0-9]+]]
+; IR: attributes #[[ATTR]] = { "memprof"="cold" }
 
 ;; Next check without -supports-hot-cold-new, we should not perform
 ;; context disambiguation, and we should strip memprof metadata and
 ;; attributes before optimization.
-; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
-; RUN: -r=%t.o,main,plx \
-; RUN: -r=%t.o,_Znam, \
+; RUN: llvm-lto2 run %t/main.o %t/foo.o -enable-memprof-c

[PATCH] D150295: [MemProf] Update hot/cold information after importing

2023-05-10 Thread Teresa Johnson 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 rG9e280c47588b: [MemProf] Update hot/cold information after 
importing (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150295

Files:
  clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll
  llvm/lib/LTO/LTOBackend.cpp
  llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll

Index: llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll
===
--- llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll
+++ llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll
@@ -3,37 +3,53 @@
 ;; from being removed from the LTO backend, and vice versa without passing
 ;; -supports-hot-cold-new.
 
+; RUN: split-file %s %t
+
 ;; First check with -supports-hot-cold-new.
-; RUN: opt -thinlto-bc %s >%t.o
-; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
+; RUN: opt -thinlto-bc %t/main.ll >%t/main.o
+; RUN: opt -thinlto-bc %t/foo.ll >%t/foo.o
+; RUN: llvm-lto2 run %t/main.o %t/foo.o -enable-memprof-context-disambiguation \
 ; RUN:	-supports-hot-cold-new \
-; RUN:	-r=%t.o,main,plx \
-; RUN:	-r=%t.o,_Znam, \
+; RUN:	-r=%t/main.o,main,plx \
+; RUN:	-r=%t/main.o,bar,plx \
+; RUN:	-r=%t/main.o,foo, \
+; RUN:	-r=%t/main.o,_Znam, \
+; RUN:	-r=%t/foo.o,foo,plx \
+; RUN:	-r=%t/foo.o,_Znam, \
 ; RUN:	-memprof-dump-ccg \
 ; RUN:	 -save-temps \
 ; RUN:	-o %t.out 2>&1 | FileCheck %s --check-prefix=DUMP
 ; DUMP: Callsite Context Graph:
 
-; RUN: llvm-dis %t.out.1.0.preopt.bc -o - | FileCheck %s --check-prefix=IR
+; RUN: llvm-dis %t.out.1.3.import.bc -o - | FileCheck %s --check-prefix=IR
+; IR: @main()
+; IR: !memprof {{.*}} !callsite
+; IR: @_Znam(i64 0) #[[ATTR:[0-9]+]]
+; IR: @bar()
 ; IR: !memprof {{.*}} !callsite
-; IR: "memprof"="cold"
+; IR: @_Znam(i64 0) #[[ATTR:[0-9]+]]
+; IR: attributes #[[ATTR]] = { "memprof"="cold" }
 
 ;; Next check without -supports-hot-cold-new, we should not perform
 ;; context disambiguation, and we should strip memprof metadata and
 ;; attributes before optimization.
-; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
-; RUN:	-r=%t.o,main,plx \
-; RUN:	-r=%t.o,_Znam, \
+; RUN: llvm-lto2 run %t/main.o %t/foo.o -enable-memprof-context-disambiguation \
+; RUN:	-r=%t/main.o,main,plx \
+; RUN:	-r=%t/main.o,bar,plx \
+; RUN:	-r=%t/main.o,foo, \
+; RUN:	-r=%t/main.o,_Znam, \
+; RUN:	-r=%t/foo.o,foo,plx \
+; RUN:	-r=%t/foo.o,_Znam, \
 ; RUN:	-memprof-dump-ccg \
 ; RUN:	 -save-temps \
 ; RUN:	-o %t.out 2>&1 | FileCheck %s --allow-empty \
 ; RUN:  --implicit-check-not "Callsite Context Graph:"
 
-; RUN: llvm-dis %t.out.1.0.preopt.bc -o - | FileCheck %s \
+; RUN: llvm-dis %t.out.1.3.import.bc -o - | FileCheck %s \
 ; RUN: --implicit-check-not "!memprof" --implicit-check-not "!callsite" \
 ; RUN: --implicit-check-not "memprof"="cold"
 
-source_filename = "memprof-supports-hot-cold-new.ll"
+;--- main.ll
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 
@@ -44,6 +60,13 @@
   ret i32 0
 }
 
+define void @bar() {
+  call void @foo()
+  ret void
+}
+
+declare void @foo()
+
 declare ptr @_Znam(i64)
 
 attributes #0 = { noinline optnone }
@@ -55,3 +78,25 @@
 !3 = !{!4, !"cold"}
 !4 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
 !5 = !{i64 9086428284934609951}
+
+;--- foo.ll
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @foo() {
+entry:
+  %call = call ptr @_Znam(i64 0), !memprof !0, !callsite !5
+  %call2 = call ptr @_Znam(i64 0) #1
+  ret i32 0
+}
+
+declare ptr @_Znam(i64)
+
+attributes #1 = { "memprof"="cold" }
+
+!0 = !{!1, !3}
+!1 = !{!2, !"notcold"}
+!2 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414}
+!3 = !{!4, !"cold"}
+!4 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
+!5 = !{i64 9086428284934609951}
Index: llvm/lib/LTO/LTOBackend.cpp
===
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -565,8 +565,6 @@
   // the module, if applicable.
   Mod.setPartialSampleProfileRatio(CombinedIndex);
 
-  updateMemProfAttributes(Mod, CombinedIndex);
-
   updatePublicTypeTestCalls(Mod, CombinedIndex.withWholeProgramVisibility());
 
   if (Conf.CodeGenOnly) {
@@ -653,6 +651,9 @@
   if (Error Err = Importer.importFunctions(Mod, ImportList).takeError())
 return Err;
 
+  // Do this after any importing so that imported code is updated.
+  updateMemProfAttributes(Mod, CombinedIndex);
+
   if (Conf.PostImportModuleHook && !Conf.PostI

[PATCH] D147266: [AArch64] Add IR intrinsics for vbsl* C intrinsics

2023-05-10 Thread Pranav Kant via Phabricator via cfe-commits
pranavk updated this revision to Diff 521114.
pranavk added a comment.

[AArch64][InstCombine] Bail out for bitselect instructions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147266

Files:
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -56,6 +56,29 @@
 ///
 /// FIXME: It's possible to create more instructions than previously existed.
 static bool cheapToScalarize(Value *V, Value *EI) {
+  // Pattern: or(and(a, mask), and(b, ~mask)) can be efficiently folded to 
bitselect instructions
+  // where ~mask = xor mask, -1
+  if (isa(V)) {
+Instruction *TI = cast(V);
+if (TI->getOpcode() == Instruction::Or) {
+  Value *LHS = TI->getOperand(0);
+  Value *RHS = TI->getOperand(1);
+  Value *MaskValue = nullptr;
+  Value *MaskConst = nullptr;
+
+  if (match(LHS, m_And(m_Value(), m_Value(MaskValue))) &&
+  match(RHS, m_And(m_Value(), m_Xor(m_Specific(MaskValue), 
m_Value(MaskConst) {
+if (auto *CI = dyn_cast(MaskConst)) {
+  Constant *C = CI->getSplatValue();
+  if (C->isAllOnesValue()) {
+llvm::outs() << "return false from cheap\n";
+return false;
+  }
+}
+  }
+}
+  }
+
   ConstantInt *CEI = dyn_cast(EI);
 
   // If we can pick a scalar constant value out of a vector, that is free.


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -56,6 +56,29 @@
 ///
 /// FIXME: It's possible to create more instructions than previously existed.
 static bool cheapToScalarize(Value *V, Value *EI) {
+  // Pattern: or(and(a, mask), and(b, ~mask)) can be efficiently folded to bitselect instructions
+  // where ~mask = xor mask, -1
+  if (isa(V)) {
+Instruction *TI = cast(V);
+if (TI->getOpcode() == Instruction::Or) {
+  Value *LHS = TI->getOperand(0);
+  Value *RHS = TI->getOperand(1);
+  Value *MaskValue = nullptr;
+  Value *MaskConst = nullptr;
+
+  if (match(LHS, m_And(m_Value(), m_Value(MaskValue))) &&
+  match(RHS, m_And(m_Value(), m_Xor(m_Specific(MaskValue), m_Value(MaskConst) {
+if (auto *CI = dyn_cast(MaskConst)) {
+  Constant *C = CI->getSplatValue();
+  if (C->isAllOnesValue()) {
+llvm::outs() << "return false from cheap\n";
+return false;
+  }
+}
+  }
+}
+  }
+
   ConstantInt *CEI = dyn_cast(EI);
 
   // If we can pick a scalar constant value out of a vector, that is free.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >