[PATCH] D119098: [clang-tidy] Ignore variable template partial specializations in `misc-definitions-in-headers`

2022-02-06 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.

thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119098

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


[PATCH] D119067: [clang-format] Fix DefinitionBlockSeparator extra empty lines

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

LGTM.




Comment at: clang/unittests/Format/DefinitionBlockSeparatorTest.cpp:305
   "  int r = j / k;\n"
+  "  if (struct S = getS()) {\n"
+  "// if condition\n"

curdeius wrote:
> I'd rather see this added in another function e.g. bar3, because otherwise 
> you don't test what was tested before.
When I wrote this comment I thought that bar3 didn't exist... But well, I think 
I'll create a patch to clean up these tests a bit anyway.


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

https://reviews.llvm.org/D119067

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


[PATCH] D119103: [NFC][Analyzer] Use range based for loop.

2022-02-06 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D119103#3300037 , @steakhal wrote:

> Hmm, I guess you must take it by mutable reference since you push it to 
> `LocalTUDecls`.
> Thanks for the patch. Do you have push permissions? Otherwise, send me your 
> `name ` to let me commit this on your behalf.

Thanks for the feedback! I have commit access so I can push it on my own. :^)

> Do you plan to clean up other loops as well?

I'm a student and I'm learning clang static analyzer so I may send more 
patches. (of course including cleaning up work like this one)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119103

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


[PATCH] D119103: [NFC][Analyzer] Use range based for loop.

2022-02-06 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

Hmm, I guess you must take it by mutable reference since you push it to 
`LocalTUDecls`.
Thanks for the patch. Do you have push permissions? Otherwise, send me your 
`name ` to let me commit this on your behalf.

Do you plan to clean up other loops as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119103

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


[PATCH] D118225: [RISCV] Decouple Zve* extensions.

2022-02-06 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

Discussion on riscv-v-spec : 
https://github.com/riscv/riscv-v-spec/issues/723#issuecomment-922153867, 
although v-spec and isa-spec still not clearly describe that, but seems ISA 
folks prefer having those implication relationship between those zve* and v 
extensions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118225

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


[PATCH] D118977: [NVPTX] Add more FMA intriniscs/builtins

2022-02-06 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda added a comment.

In D118977#3297465 , @tra wrote:

>> They all require PTX 7.0, SM_80.
>
> According to 
> https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#half-precision-floating-point-instructions-fma
>  only `fma.relu` and `bf16*` variants require ptx70/sm80:
>
>   PTX ISA Notes
>   Introduced in PTX ISA version 4.2.
>   
>   fma.relu.{f16, f16x2} and fma{.relu}.{bf16, bf16x2} introduced in PTX ISA 
> version 7.0.
>   
>   Target ISA Notes
>   Requires sm_53 or higher.
>   
>   fma.relu.{f16, f16x2} and fma{.relu}.{bf16, bf16x2} require sm_80 or higher.

My bad, sorry. Fixed now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118977

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


[PATCH] D118977: [NVPTX] Add more FMA intriniscs/builtins

2022-02-06 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda updated this revision to Diff 406322.
jchlanda added a comment.

Set correct SM and PTX version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118977

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/test/CodeGen/builtins-nvptx-native-half-type.c
  clang/test/CodeGen/builtins-nvptx.c
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp
  llvm/test/CodeGen/NVPTX/math-intrins-sm80-ptx70-instcombine.ll
  llvm/test/CodeGen/NVPTX/math-intrins-sm80-ptx70.ll
  llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll
  llvm/test/CodeGen/NVPTX/math-intrins.ll

Index: llvm/test/CodeGen/NVPTX/math-intrins.ll
===
--- llvm/test/CodeGen/NVPTX/math-intrins.ll
+++ llvm/test/CodeGen/NVPTX/math-intrins.ll
@@ -30,6 +30,15 @@
 declare float @llvm.fma.f32(float, float, float) #0
 declare double @llvm.fma.f64(double, double, double) #0
 
+declare half @llvm.nvvm.fma.rn.f16(half, half, half)
+declare half @llvm.nvvm.fma.rn.ftz.f16(half, half, half)
+declare half @llvm.nvvm.fma.rn.sat.f16(half, half, half)
+declare half @llvm.nvvm.fma.rn.ftz.sat.f16(half, half, half)
+declare <2 x half> @llvm.nvvm.fma.rn.f16x2(<2 x half>, <2 x half>, <2 x half>)
+declare <2 x half> @llvm.nvvm.fma.rn.ftz.f16x2(<2 x half>, <2 x half>, <2 x half>)
+declare <2 x half> @llvm.nvvm.fma.rn.sat.f16x2(<2 x half>, <2 x half>, <2 x half>)
+declare <2 x half> @llvm.nvvm.fma.rn.ftz.sat.f16x2(<2 x half>, <2 x half>, <2 x half>)
+
 ;  ceil 
 
 ; CHECK-LABEL: ceil_float
@@ -328,5 +337,69 @@
   ret double %x
 }
 
+; CHECK-LABEL: fma_rn_f16
+define half @fma_rn_f16(half %0, half %1, half %2) {
+  ; CHECK-NOT: call
+  ; CHECK: fma.rn.f16
+  %res = call half @llvm.nvvm.fma.rn.f16(half %0, half %1, half %2)
+  ret half %res
+}
+
+; CHECK-LABEL: fma_rn_ftz_f16
+define half @fma_rn_ftz_f16(half %0, half %1, half %2) {
+  ; CHECK-NOT: call
+  ; CHECK: fma.rn.ftz.f16
+  %res = call half @llvm.nvvm.fma.rn.ftz.f16(half %0, half %1, half %2)
+  ret half %res
+}
+
+; CHECK-LABEL: fma_rn_sat_f16
+define half @fma_rn_sat_f16(half %0, half %1, half %2) {
+  ; CHECK-NOT: call
+  ; CHECK: fma.rn.sat.f16
+  %res = call half @llvm.nvvm.fma.rn.sat.f16(half %0, half %1, half %2)
+  ret half %res
+}
+
+; CHECK-LABEL: fma_rn_ftz_sat_f16
+define half @fma_rn_ftz_sat_f16(half %0, half %1, half %2) {
+  ; CHECK-NOT: call
+  ; CHECK: fma.rn.ftz.sat.f16
+  %res = call half @llvm.nvvm.fma.rn.ftz.sat.f16(half %0, half %1, half %2)
+  ret half %res
+}
+
+; CHECK-LABEL: fma_rn_f16x2
+define <2 x half> @fma_rn_f16x2(<2 x half> %0, <2 x half> %1, <2 x half> %2) {
+  ; CHECK-NOT: call
+  ; CHECK: fma.rn.f16x2
+  %res = call <2 x half> @llvm.nvvm.fma.rn.f16x2(<2 x half> %0, <2 x half> %1, <2 x half> %2)
+  ret <2 x half> %res
+}
+
+; CHECK-LABEL: fma_rn_ftz_f16x2
+define <2 x half> @fma_rn_ftz_f16x2(<2 x half> %0, <2 x half> %1, <2 x half> %2) {
+  ; CHECK-NOT: call
+  ; CHECK: fma.rn.ftz.f16x2
+  %res = call <2 x half> @llvm.nvvm.fma.rn.ftz.f16x2(<2 x half> %0, <2 x half> %1, <2 x half> %2)
+  ret <2 x half> %res
+}
+
+; CHECK-LABEL: fma_rn_sat_f16x2
+define <2 x half> @fma_rn_sat_f16x2(<2 x half> %0, <2 x half> %1, <2 x half> %2) {
+  ; CHECK-NOT: call
+  ; CHECK: fma.rn.sat.f16x2
+  %res = call <2 x half> @llvm.nvvm.fma.rn.sat.f16x2(<2 x half> %0, <2 x half> %1, <2 x half> %2)
+  ret <2 x half> %res
+}
+
+; CHECK-LABEL: fma_rn_ftz_sat_f16x2
+define <2 x half> @fma_rn_ftz_sat_f16x2(<2 x half> %0, <2 x half> %1, <2 x half> %2) {
+  ; CHECK-NOT: call
+  ; CHECK: fma.rn.ftz.sat.f16x2
+  %res = call <2 x half> @llvm.nvvm.fma.rn.ftz.sat.f16x2(<2 x half> %0, <2 x half> %1, <2 x half> %2)
+  ret <2 x half> %res
+}
+
 attributes #0 = { nounwind readnone }
 attributes #1 = { "denormal-fp-math-f32" = "preserve-sign" }
Index: llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll
===
--- llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll
+++ llvm/test/CodeGen/NVPTX/math-intrins-sm86-ptx72.ll
@@ -36,6 +36,7 @@
 
 ; CHECK-LABEL: fmin_xorsign_abs_f16
 define half @fmin_xorsign_abs_f16(half %0, half %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.xorsign.abs.f16
   %res = call half @llvm.nvvm.fmin.xorsign.abs.f16(half %0, half %1)
   ret half %res
@@ -43,6 +44,7 @@
 
 ; CHECK-LABEL: fmin_ftz_xorsign_abs_f16
 define half @fmin_ftz_xorsign_abs_f16(half %0, half %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.ftz.xorsign.abs.f16
   %res = call half @llvm.nvvm.fmin.ftz.xorsign.abs.f16(half %0, half %1)
   ret half %res
@@ -50,6 +52,7 @@
 
 ; CHECK-LABEL: fmin_nan_xorsign_abs_f16
 define half @fmin_nan_xorsign_abs_f16(half %0, half %1) {
+  ; CHECK-NOT: call
   ; CHECK: min.NaN.xorsign.abs.f16
   %res = call half @llvm.nvvm.fmin.nan.xorsign.abs.f16(half %0, half %1)
   

[PATCH] D119004: [NFC][analyzer] Allow CallDescriptions to be matched with CallExprs

2022-02-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

The original `lookup()` isn't exactly precise either, it's just slightly more 
precise as it has better access to path-sensitive information such as current 
values of function pointers, but this doesn't necessarily help given that these 
pointers can still be unknown. And when the information is not available the 
lookup silently fails in both cases.

But I can certainly get behind demotivating callers from calling the new 
function unless they know what they're doing. Maybe `lookupAsWritten()` to 
indicate that the function intentionally ignores the runtime state of the 
program and looks at the syntax only?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119004

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


[PATCH] D117989: [RISCV] Add the passthru operand for RVV nomask binary intrinsics.

2022-02-06 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:4503
   case Intrinsic::riscv_vslide1down_mask: {
 // We need to special case these when the scalar is larger than XLen.
 unsigned NumOps = Op.getNumOperands();

Are we dropping the policy operand for masked intrinsics here?



Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:4539
+if (!IsMasked) {
+  SDValue passthru = DAG.getBitcast(I32VT, Op.getOperand(1));
+  if (IntNo == Intrinsic::riscv_vslide1up) {

Capitalize variable name


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117989

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


[PATCH] D119103: [NFC][Analyzer] Use range based for loop.

2022-02-06 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: zaks.anna, dcoughlin.
Herald added subscribers: manas, steakhal, ASDenysPetrov, martong, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Use range base loop loop to improve code readability.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119103

Files:
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp


Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -383,14 +383,14 @@
 }
 
 void AnalysisConsumer::storeTopLevelDecls(DeclGroupRef DG) {
-  for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) {
+  for (auto  : DG) {
 
 // Skip ObjCMethodDecl, wait for the objc container to avoid
 // analyzing twice.
-if (isa(*I))
+if (isa(I))
   continue;
 
-LocalTUDecls.push_back(*I);
+LocalTUDecls.push_back(I);
   }
 }
 
@@ -462,11 +462,9 @@
   SetOfConstDecls Visited;
   SetOfConstDecls VisitedAsTopLevel;
   llvm::ReversePostOrderTraversal RPOT();
-  for (llvm::ReversePostOrderTraversal::rpo_iterator
- I = RPOT.begin(), E = RPOT.end(); I != E; ++I) {
+  for (auto  : RPOT) {
 NumFunctionTopLevel++;
 
-CallGraphNode *N = *I;
 Decl *D = N->getDecl();
 
 // Skip the abstract root node.


Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -383,14 +383,14 @@
 }
 
 void AnalysisConsumer::storeTopLevelDecls(DeclGroupRef DG) {
-  for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) {
+  for (auto  : DG) {
 
 // Skip ObjCMethodDecl, wait for the objc container to avoid
 // analyzing twice.
-if (isa(*I))
+if (isa(I))
   continue;
 
-LocalTUDecls.push_back(*I);
+LocalTUDecls.push_back(I);
   }
 }
 
@@ -462,11 +462,9 @@
   SetOfConstDecls Visited;
   SetOfConstDecls VisitedAsTopLevel;
   llvm::ReversePostOrderTraversal RPOT();
-  for (llvm::ReversePostOrderTraversal::rpo_iterator
- I = RPOT.begin(), E = RPOT.end(); I != E; ++I) {
+  for (auto  : RPOT) {
 NumFunctionTopLevel++;
 
-CallGraphNode *N = *I;
 Decl *D = N->getDecl();
 
 // Skip the abstract root node.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118437: [NFC] [Modules] Refactor ODR checking for default template argument in ASTReader

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

gentle ping~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118437

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


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

2022-02-06 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 406315.
ChuanqiXu added a comment.

Address comments.


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

https://reviews.llvm.org/D115610

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaModule.cpp
  clang/test/CXX/module/module.unit/p7/Inputs/h8.h
  clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
  clang/test/CXX/module/module.unit/p7/t8.cpp


Index: clang/test/CXX/module/module.unit/p7/t8.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/t8.cpp
@@ -0,0 +1,7 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %S/Inputs/m8.cppm 
-I%S/Inputs -o %t/m8.pcm
+// RUN: %clang_cc1 -std=c++20 -I%S/Inputs/ -fprebuilt-module-path=%t %s 
-verify -fsyntax-only
+// expected-no-diagnostics
+export module t8;
+import m8;
Index: clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
===
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
@@ -0,0 +1,7 @@
+module;
+#include "h8.h"
+export module m8;
+
+extern "C++" {
+void bar();
+}
Index: clang/test/CXX/module/module.unit/p7/Inputs/h8.h
===
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/Inputs/h8.h
@@ -0,0 +1,4 @@
+#ifndef H8
+#define H8
+void foo();
+#endif
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -720,19 +720,24 @@
 
 Module *Sema::PushGlobalModuleFragment(SourceLocation BeginLoc,
bool IsImplicit) {
-  ModuleMap  = PP.getHeaderSearchInfo().getModuleMap();
-  Module *GlobalModule =
-  Map.createGlobalModuleFragmentForModuleUnit(BeginLoc, 
getCurrentModule());
-  assert(GlobalModule && "module creation should not fail");
+  // We shouldn't create new global module fragment if there is already
+  // one.
+  if (!GlobalModuleFragment) {
+ModuleMap  = PP.getHeaderSearchInfo().getModuleMap();
+GlobalModuleFragment = Map.createGlobalModuleFragmentForModuleUnit(
+BeginLoc, getCurrentModule());
+  }
+
+  assert(GlobalModuleFragment && "module creation should not fail");
 
   // Enter the scope of the global module.
-  ModuleScopes.push_back({BeginLoc, GlobalModule,
+  ModuleScopes.push_back({BeginLoc, GlobalModuleFragment,
   /*ModuleInterface=*/false,
   /*ImplicitGlobalModuleFragment=*/IsImplicit,
-  /*VisibleModuleSet*/{}});
-  VisibleModules.setVisible(GlobalModule, BeginLoc);
+  /*VisibleModuleSet*/ {}});
+  VisibleModules.setVisible(GlobalModuleFragment, BeginLoc);
 
-  return GlobalModule;
+  return GlobalModuleFragment;
 }
 
 void Sema::PopGlobalModuleFragment() {
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -2218,6 +2218,8 @@
   };
   /// The modules we're currently parsing.
   llvm::SmallVector ModuleScopes;
+  /// The global module fragment of the current translation unit.
+  clang::Module *GlobalModuleFragment = nullptr;
 
   /// Namespace definitions that we will export when they finish.
   llvm::SmallPtrSet DeferredExportedNamespaces;


Index: clang/test/CXX/module/module.unit/p7/t8.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/t8.cpp
@@ -0,0 +1,7 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %S/Inputs/m8.cppm -I%S/Inputs -o %t/m8.pcm
+// RUN: %clang_cc1 -std=c++20 -I%S/Inputs/ -fprebuilt-module-path=%t %s -verify -fsyntax-only
+// expected-no-diagnostics
+export module t8;
+import m8;
Index: clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
===
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
@@ -0,0 +1,7 @@
+module;
+#include "h8.h"
+export module m8;
+
+extern "C++" {
+void bar();
+}
Index: clang/test/CXX/module/module.unit/p7/Inputs/h8.h
===
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/Inputs/h8.h
@@ -0,0 +1,4 @@
+#ifndef H8
+#define H8
+void foo();
+#endif
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -720,19 +720,24 @@
 
 Module *Sema::PushGlobalModuleFragment(SourceLocation BeginLoc,
bool IsImplicit) {
-  ModuleMap  = PP.getHeaderSearchInfo().getModuleMap();
-  Module *GlobalModule =
-  Map.createGlobalModuleFragmentForModuleUnit(BeginLoc, 

[PATCH] D117087: [C++20] [Coroutines] Implement return value optimization for get_return_object

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

gentle ping~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117087

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


[PATCH] D115867: [C++20] [Coroutines] Warning for always_inline coroutine

2022-02-06 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 406314.
ChuanqiXu added a comment.

Apply Aaron's opinion in: 
https://github.com/llvm/llvm-project/issues/53413#issuecomment-1024910619.


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

https://reviews.llvm.org/D115867

Files:
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaCoroutine.cpp
  clang/test/SemaCXX/coroutines.cpp


Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1460,3 +1460,13 @@
   co_await missing_await_suspend{}; // expected-error {{no member named 
'await_suspend' in 'missing_await_suspend'}}
   co_await missing_await_resume{}; // expected-error {{no member named 
'await_resume' in 'missing_await_resume'}}
 }
+
+__attribute__((__always_inline__))
+void warn_always_inline() { // expected-warning {{this coroutine may be split 
into pieces; not every piece is guaranteed to be inlined}}
+  co_await suspend_always{};
+}
+
+[[gnu::always_inline]]
+void warn_gnu_always_inline() { // expected-warning {{this coroutine may be 
split into pieces; not every piece is guaranteed to be inlined}}
+  co_await suspend_always{};
+}
Index: clang/lib/Sema/SemaCoroutine.cpp
===
--- clang/lib/Sema/SemaCoroutine.cpp
+++ clang/lib/Sema/SemaCoroutine.cpp
@@ -1081,6 +1081,14 @@
 return;
   }
 
+  // The always_inline attribute doesn't reliably apply to a coroutine,
+  // because the coroutine will be split into pieces and some pieces
+  // might be called indirectly, as in a virtual call. Even the ramp
+  // function cannot be inlined at -O0, due to pipeline ordering
+  // problems (see https://llvm.org/PR53413). Tell the user about it.
+  if (FD->hasAttr())
+Diag(FD->getLocation(), diag::warn_always_inline_coroutine);
+
   // [stmt.return.coroutine]p1:
   //   A coroutine shall not enclose a return statement ([stmt.return]).
   if (Fn->FirstReturnLoc.isValid()) {
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9,6 +9,10 @@
 def note_coroutine_function_declare_noexcept : Note<
   "must be declared with 'noexcept'"
 >;
+def warn_always_inline_coroutine : Warning<
+  "this coroutine may be split into pieces; not every piece is guaranteed to 
be inlined"
+  >,
+  InGroup;
 } // end of coroutines issue category
 
 let CategoryName = "Documentation Issue" in {
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -58,7 +58,9 @@
   DiagGroup<"deprecated-experimental-coroutine">;
 def DeprecatedCoroutine :
   DiagGroup<"deprecated-coroutine", [DeprecatedExperimentalCoroutine]>;
-def Coroutine : DiagGroup<"coroutine", [CoroutineMissingUnhandledException, 
DeprecatedCoroutine]>;
+def AlwaysInlineCoroutine :
+  DiagGroup<"always-inline-coroutine">;
+def Coroutine : DiagGroup<"coroutine", [CoroutineMissingUnhandledException, 
DeprecatedCoroutine, AlwaysInlineCoroutine]>;
 def ObjCBoolConstantConversion : DiagGroup<"objc-bool-constant-conversion">;
 def ConstantConversion : DiagGroup<"constant-conversion",
[BitFieldConstantConversion,
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -6203,7 +6203,11 @@
 Inlining heuristics are disabled and inlining is always attempted regardless of
 optimization level.
 
-Does not guarantee that inline substitution actually occurs.
+Does not guarantee that inline substitution actually occurs. 
+
+Note: applying this attribute to a coroutine at the `-O0` optimization 
level
+has no effect; other optimization levels may only partially inline and result 
in a
+diagnostic.
 
 See also `the Microsoft Docs on Inline Functions`_, `the GCC Common Function
 Attribute docs`_, and `the GCC Inline docs`_.


Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1460,3 +1460,13 @@
   co_await missing_await_suspend{}; // expected-error {{no member named 'await_suspend' in 'missing_await_suspend'}}
   co_await missing_await_resume{}; // expected-error {{no member named 'await_resume' in 'missing_await_resume'}}
 }
+
+__attribute__((__always_inline__))
+void warn_always_inline() { // expected-warning {{this coroutine may be split into pieces; not every piece is 

[PATCH] D118632: [WIP][Clang]OpenMP] Add the codegen support for `atomic compare`

2022-02-06 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:1
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 
-fopenmp -fopenmp-version=51 -x c -emit-llvm %s -o - | FileCheck %s

The test case itself was generated from a Python script.



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:3
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 
-fopenmp -fopenmp-version=51 -x c -emit-llvm %s -o - | FileCheck %s
+// %clang_cc1 -fopenmp -fopenmp-version=51 -x c -triple x86_64-apple-darwin10 
-target-cpu core2 -emit-pch -o %t %s
+// %clang_cc1 -fopenmp -fopenmp-version=51 -x c -triple x86_64-apple-darwin10 
-target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s

This test cannot be done because clang crashed. I filed a bug 
https://github.com/llvm/llvm-project/issues/53601.



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:6
+
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 
-fopenmp-simd -fopenmp-version=51 -x c -emit-llvm %s -o - | FileCheck 
--check-prefix SIMD-ONLY0 %s
+// %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c -triple 
x86_64-apple-darwin10 -target-cpu core2 -emit-pch -o %t %s

CodeGen for `-fopen-simd` is wrong. It doesn't emit corresponding atomic 
operations. I'll fix it.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:3496
 : Builder.CreateBitCast(X.Var, IntCastTy->getPointerTo(Addrspace));
+Value *NewE = E->getType()->isFloatingPointTy()
+  ? Builder.CreateFPToSI(E, IntCastTy)

This change will be separated.

Actually I got a question about whether we want support equality comparison for 
floating point values. In the patch, we don't support '<' or '>' for floating 
point values because we don't have corresponding atomic instruction for them. 
For '==', we cast them to integers and then compare the two integers. However, 
We all know it doesn't make too much sense to compare two floating point 
variables, such as `x == d`. The comparison of floating point variables should 
always do like `x - d < epsilon`. However, like we said before, that comparison 
cannot be done because of lack of instruction. So I'm not sure if we want to 
support floating point variables at all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D118632: [WIP][Clang]OpenMP] Add the codegen support for `atomic compare`

2022-02-06 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 406310.
tianshilei1992 added a comment.

add tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/atomic_compare_codegen.cpp
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

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


[PATCH] D119067: [clang-format] Fix DefinitionBlockSeparator extra empty lines

2022-02-06 Thread ksyx via Phabricator via cfe-commits
ksyx updated this revision to Diff 406309.
ksyx added a comment.

Use for loop to go through tokens in a line.


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

https://reviews.llvm.org/D119067

Files:
  clang/lib/Format/DefinitionBlockSeparator.cpp
  clang/unittests/Format/DefinitionBlockSeparatorTest.cpp

Index: clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
===
--- clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -109,6 +109,15 @@
"};",
Style);
 
+  verifyFormat("union foo {\n"
+   "  int i, j;\n"
+   "};\n"
+   "\n"
+   "union bar {\n"
+   "  int j, k;\n"
+   "};",
+   Style);
+
   verifyFormat("class foo {\n"
"  int i, j;\n"
"};\n"
@@ -311,6 +320,9 @@
   "int bar3(int j, int k, const enum Bar b) {\n"
   "  // A comment\n"
   "  int r = j % k;\n"
+  "  if (struct S = getS()) {\n"
+  "// if condition\n"
+  "  }\n"
   "  return r;\n"
   "}\n";
   std::string Postfix = "\n"
@@ -364,6 +376,9 @@
 "int bar3(int j, int k, const enum Bar b) {\n"
 "  // A comment\n"
 "  int r = j % k;\n"
+"  if (struct S = getS()) {\n"
+"// if condition\n"
+"  }\n"
 "  return r;\n"
 "}\n"
 "} // namespace";
@@ -425,6 +440,10 @@
"{\n"
"  // A comment\n"
"  int r = j % k;\n"
+   "  if (struct S = getS())\n"
+   "  {\n"
+   "// if condition\n"
+   "  }\n"
"  return r;\n"
"}\n"
"} // namespace NS",
@@ -473,6 +492,9 @@
 "int bar3(int j, int k, const enum Bar b) {\n"
 "  // A comment\n"
 "  int r = j % k;\n"
+"  if (struct S = getS()) {\n"
+"// if condition\n"
+"  }\n"
 "  return r;\n"
 "}\n"
 "} // namespace";
Index: clang/lib/Format/DefinitionBlockSeparator.cpp
===
--- clang/lib/Format/DefinitionBlockSeparator.cpp
+++ clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -35,19 +35,31 @@
   const bool IsNeverStyle =
   Style.SeparateDefinitionBlocks == FormatStyle::SDS_Never;
   const AdditionalKeywords  = Tokens.getKeywords();
-  auto LikelyDefinition = [this, ExtraKeywords](const AnnotatedLine *Line,
-bool ExcludeEnum = false) {
+  auto GetBracketLevelChange = [](const FormatToken *Tok) {
+if (Tok->isOneOf(tok::l_brace, tok::l_paren, tok::l_square))
+  return 1;
+if (Tok->isOneOf(tok::r_brace, tok::r_paren, tok::r_square))
+  return -1;
+return 0;
+  };
+  auto LikelyDefinition = [&](const AnnotatedLine *Line,
+  bool ExcludeEnum = false) {
 if ((Line->MightBeFunctionDecl && Line->mightBeFunctionDefinition()) ||
 Line->startsWithNamespace())
   return true;
-FormatToken *CurrentToken = Line->First;
-while (CurrentToken) {
-  if (CurrentToken->isOneOf(tok::kw_class, tok::kw_struct) ||
-  (Style.isJavaScript() && CurrentToken->is(ExtraKeywords.kw_function)))
-return true;
-  if (!ExcludeEnum && CurrentToken->is(tok::kw_enum))
-return true;
-  CurrentToken = CurrentToken->Next;
+int BracketLevel = 0;
+for (const FormatToken *CurrentToken = Line->First; CurrentToken;
+ CurrentToken = CurrentToken->Next) {
+  if (BracketLevel == 0) {
+if ((CurrentToken->isOneOf(tok::kw_class, tok::kw_struct,
+   tok::kw_union) ||
+ (Style.isJavaScript() &&
+  CurrentToken->is(ExtraKeywords.kw_function
+  return true;
+if (!ExcludeEnum && CurrentToken->is(tok::kw_enum))
+  return true;
+  }
+  BracketLevel += GetBracketLevelChange(CurrentToken);
 }
 return false;
   };
@@ -102,14 +114,17 @@
  IsPPConditional(OpeningLineIndex - 1);
 };
 const auto HasEnumOnLine = [&]() {
-  FormatToken *CurrentToken = CurrentLine->First;
   bool FoundEnumKeyword = false;
-  while (CurrentToken) {
-if (CurrentToken->is(tok::kw_enum))
-  FoundEnumKeyword = true;
-else if (FoundEnumKeyword && CurrentToken->is(tok::l_brace))
-  

[PATCH] D119067: [clang-format] Fix DefinitionBlockSeparator extra empty lines

2022-02-06 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/DefinitionBlockSeparator.cpp:50-64
 FormatToken *CurrentToken = Line->First;
+int BracketLevel = 0;
 while (CurrentToken) {
-  if (CurrentToken->isOneOf(tok::kw_class, tok::kw_struct) ||
-  (Style.isJavaScript() && 
CurrentToken->is(ExtraKeywords.kw_function)))
-return true;
-  if (!ExcludeEnum && CurrentToken->is(tok::kw_enum))
-return true;
+  if (BracketLevel == 0) {
+if ((CurrentToken->isOneOf(tok::kw_class, tok::kw_struct,
+   tok::kw_union) ||
+ (Style.isJavaScript() &&

Please use a `for` loop instead:

```
for (const FormatToken *CurrentToken = Line->First; CurrentToken;
 CurrentToken = CurrentToken->Next) {
  ...;
}
```



Comment at: clang/lib/Format/DefinitionBlockSeparator.cpp:121-130
   while (CurrentToken) {
-if (CurrentToken->is(tok::kw_enum))
-  FoundEnumKeyword = true;
-else if (FoundEnumKeyword && CurrentToken->is(tok::l_brace))
-  return true;
+if (BracketLevel == 0) {
+  if (CurrentToken->is(tok::kw_enum))
+FoundEnumKeyword = true;
+  else if (FoundEnumKeyword && CurrentToken->is(tok::l_brace))
+return true;
+}

Use a `for` loop with the `const FormatToken *CurrentToken` loop variable 
similar to the above.


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

https://reviews.llvm.org/D119067

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


[PATCH] D119098: [clang-tidy] Ignore variable template partial specializations in `misc-definitions-in-headers`

2022-02-06 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

A copy-pasted message below, as usual =)

//If this review is eventually approved, kindly please merge the commit on my 
behalf =) As I don't have merge access. My name is `Evgeny Shulgin` and email 
is `izaronpl...@gmail.com`. Sorry for inconvenience!//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119098

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


[PATCH] D119098: [clang-tidy] Ignore variable template partial specializations in `misc-definitions-in-headers`

2022-02-06 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron created this revision.
Izaron added reviewers: njames93, hokein, LegalizeAdulthood.
Herald added subscribers: carlosgalvezp, xazax.hun.
Izaron requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Variable template partial specializations are inline and can't lead
to ODR-violations. The checker now ignores them.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119098

Files:
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp
@@ -193,6 +193,16 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: full function template 
specialization 'f12' defined in a header file;
 // CHECK-FIXES: inline const int f12() { return 0; }
 
+template 
+constexpr bool f13 = false;
+
+template 
+constexpr bool f13 = true; // OK: template partial specialization
+
+template <>
+constexpr bool f13 = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: variable 'f13' defined 
in a header file;
+
 int main() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'main' defined in a 
header file;
 // CHECK-FIXES: {{^}}int main() {
Index: clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -149,6 +149,9 @@
 // Ignore inline variables.
 if (VD->isInline())
   return;
+// Ignore partial specializations.
+if (isa(VD))
+  return;
 
 diag(VD->getLocation(),
  "variable %0 defined in a header file; "


Index: clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-definitions-in-headers.hpp
@@ -193,6 +193,16 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: full function template specialization 'f12' defined in a header file;
 // CHECK-FIXES: inline const int f12() { return 0; }
 
+template 
+constexpr bool f13 = false;
+
+template 
+constexpr bool f13 = true; // OK: template partial specialization
+
+template <>
+constexpr bool f13 = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: variable 'f13' defined in a header file;
+
 int main() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'main' defined in a header file;
 // CHECK-FIXES: {{^}}int main() {
Index: clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -149,6 +149,9 @@
 // Ignore inline variables.
 if (VD->isInline())
   return;
+// Ignore partial specializations.
+if (isa(VD))
+  return;
 
 diag(VD->getLocation(),
  "variable %0 defined in a header file; "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-02-06 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris added a comment.

In D117929#3276843 , @ashwin98 wrote:

> Fixed another lint issue, they should all be done for now hopefully.
>
> @dberris Sorry, I'm a little confused, do you mean I need to update some of 
> the clang tests for XRay instrumentation to test compilation and linking, or 
> add new ones for the llvm-xray tool under llvm/test/tools?

Yes to both. :)

There are already some tests that ensure the supported triples build with XRay 
instrumentation and that we can get the instrumentation map with the tooling on 
binaries generated with clang+lld. Extending those to support risc64 and ensure 
we're able to find the instrumentation with the tooling gives us higher 
confidence that this will work when the patch is accepted.


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

https://reviews.llvm.org/D117929

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


[PATCH] D119095: [clang] Fix redundant functional cast in ConstantExpr

2022-02-06 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

There are some godbolt links in the github issues.

Expression `A{}.f();` generates the call of the move constructor from nowhere 
as well - https://godbolt.org/z/MceYedKzj

With the patch this node (that lives inside an another `ConstantExpr` node):

  MemberExpr 0x5e48b3d8 '' .f 0x5e48aa98
  `-MaterializeTemporaryExpr 0x5e48b3c0 'struct A' xvalue
`-CXXFunctionalCastExpr 0x5e48b398 'struct A' functional cast to struct 
A 
  `-ConstantExpr 0x5e48b200 'struct A'
`-CXXTemporaryObjectExpr 0x5e48b1d0 'struct A' 'void (void)' list

transforms to this:

  MemberExpr 0x5e48b3d8 '' .f 0x5e48aa98
  `-MaterializeTemporaryExpr 0x5e48b3c0 'struct A' xvalue
`-CXXTemporaryObjectExpr 0x5e48b1d0 'struct A' 'void (void)' list

I reviewed other github issues about consteval. This patch doesn't fix other 
known issues as I checked.

//P.S. If this review is eventually approved, kindly please merge the commit on 
my behalf =) As I don't have merge access. My name is `Evgeny Shulgin` and 
email is `izaronpl...@gmail.com`. Sorry for inconvenience!//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119095

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


[PATCH] D119095: [clang] Fix redundant functional cast in ConstantExpr

2022-02-06 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron created this revision.
Izaron added reviewers: aaron.ballman, cor3ntin.
Izaron requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When removing nested ConstantExprs, the tree transformer
doesn't remove redundant CXXFunctionalCasts that were created
"above" consteval constructors. After a while it generates a call
to a constructor, therefore violating the C++17 mandatory copy
elision rule.

Fixes https://github.com/llvm/llvm-project/issues/53244
and https://github.com/llvm/llvm-project/issues/53245


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119095

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -613,6 +613,45 @@
 
 } // namespace unevaluated
 
+namespace mandatory_copy_elision {
+
+struct A {
+  consteval A() {}
+  consteval A(const A &);
+  consteval A(A &&);
+  consteval void f() {}
+};
+
+struct B {
+  consteval B() {}
+  consteval B(const B &) = delete;
+  consteval B(B &&) = delete;
+  consteval void f() {}
+};
+
+struct C {
+  consteval C() {}
+  consteval void f() {}
+
+private:
+  consteval C(const C &){};
+  consteval C(C &&){};
+};
+
+void test() {
+  { A{}.f(); }
+  { A{A{}}.f(); }
+  { A{A{A{A{A{A{A{A{.f(); }
+  { B{}.f(); }
+  { B{B{}}.f(); }
+  { B{B{B{B{B{B{B{B{.f(); }
+  { C{}.f(); }
+  { C{C{}}.f(); }
+  { C{C{C{C{C{C{C{C{.f(); }
+}
+
+} // namespace mandatory_copy_elision
+
 namespace PR50779 {
 struct derp {
   int b = 0;
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16796,6 +16796,14 @@
   DRSet.erase(cast(E->getCallee()->IgnoreImplicit()));
   return Base::TransformCXXOperatorCallExpr(E);
 }
+/// Delete extra no-op functional casts to avoid calling a constructor
+ExprResult TransformCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
+  auto *CE = dyn_cast(E->getSubExpr());
+  if (E->getCastKind() != CK_NoOp || !CE || !CE->isImmediateInvocation())
+return Base::TransformCXXFunctionalCastExpr(E);
+  RemoveImmediateInvocation(CE);
+  return Base::TransformExpr(CE->getSubExpr());
+}
 /// Base::TransformInitializer skip ConstantExpr so we need to visit them
 /// here.
 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit) {


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -613,6 +613,45 @@
 
 } // namespace unevaluated
 
+namespace mandatory_copy_elision {
+
+struct A {
+  consteval A() {}
+  consteval A(const A &);
+  consteval A(A &&);
+  consteval void f() {}
+};
+
+struct B {
+  consteval B() {}
+  consteval B(const B &) = delete;
+  consteval B(B &&) = delete;
+  consteval void f() {}
+};
+
+struct C {
+  consteval C() {}
+  consteval void f() {}
+
+private:
+  consteval C(const C &){};
+  consteval C(C &&){};
+};
+
+void test() {
+  { A{}.f(); }
+  { A{A{}}.f(); }
+  { A{A{A{A{A{A{A{A{.f(); }
+  { B{}.f(); }
+  { B{B{}}.f(); }
+  { B{B{B{B{B{B{B{B{.f(); }
+  { C{}.f(); }
+  { C{C{}}.f(); }
+  { C{C{C{C{C{C{C{C{.f(); }
+}
+
+} // namespace mandatory_copy_elision
+
 namespace PR50779 {
 struct derp {
   int b = 0;
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16796,6 +16796,14 @@
   DRSet.erase(cast(E->getCallee()->IgnoreImplicit()));
   return Base::TransformCXXOperatorCallExpr(E);
 }
+/// Delete extra no-op functional casts to avoid calling a constructor
+ExprResult TransformCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
+  auto *CE = dyn_cast(E->getSubExpr());
+  if (E->getCastKind() != CK_NoOp || !CE || !CE->isImmediateInvocation())
+return Base::TransformCXXFunctionalCastExpr(E);
+  RemoveImmediateInvocation(CE);
+  return Base::TransformExpr(CE->getSubExpr());
+}
 /// Base::TransformInitializer skip ConstantExpr so we need to visit them
 /// here.
 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119094: [clang] Don't emit redundant warnings for 'return;'

2022-02-06 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone created this revision.
Quuxplusone added reviewers: rsmith, sammccall, mizvekov, majnemer, riccibruno, 
clang.
Quuxplusone added a project: clang.
Quuxplusone requested review of this revision.
Herald added a subscriber: cfe-commits.

...when the function declaration's return type is already invalid for
some reason. This is relevant to 
https://github.com/llvm/llvm-project/issues/49188
because another way that the declaration's return type could become
invalid is that it might be `C auto` where `C` is false.

(This doesn't actually fix 49188, but it eliminates a surprising redundant 
warning in the fix I tried, and also eliminates redundant warnings in the test 
cases depicted here.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119094

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/deduced-return-void.cpp


Index: clang/test/SemaCXX/deduced-return-void.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/deduced-return-void.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Check that we don't get any extra warning for "return" without an
+// expression, in a function that might have been intended to return
+// void all along.
+auto f1() {
+  return 1;
+  return; // expected-error {{deduced as 'void' here but deduced as 'int' in 
earlier return statement}}
+}
+
+decltype(auto) f2() {
+  return 1;
+  return; // expected-error {{deduced as 'void' here but deduced as 'int' in 
earlier return statement}}
+}
+
+auto *g() {
+  return; // expected-error {{cannot deduce return type 'auto *' from omitted 
return expression}}
+}
+
+decltype(h1) h1() { // expected-error {{use of undeclared identifier 'h1'}}
+  return;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -4098,7 +4098,9 @@
   } else if (!RetValExp && !HasDependentReturnType) {
 FunctionDecl *FD = getCurFunctionDecl();
 
-if (getLangOpts().CPlusPlus11 && FD && FD->isConstexpr()) {
+if (FD->isInvalidDecl()) {
+  // Don't redundantly warn about "return;" if the return type is invalid.
+} else if (getLangOpts().CPlusPlus11 && FD && FD->isConstexpr()) {
   // C++11 [stmt.return]p2
   Diag(ReturnLoc, diag::err_constexpr_return_missing_expr)
   << FD << FD->isConsteval();


Index: clang/test/SemaCXX/deduced-return-void.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/deduced-return-void.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Check that we don't get any extra warning for "return" without an
+// expression, in a function that might have been intended to return
+// void all along.
+auto f1() {
+  return 1;
+  return; // expected-error {{deduced as 'void' here but deduced as 'int' in earlier return statement}}
+}
+
+decltype(auto) f2() {
+  return 1;
+  return; // expected-error {{deduced as 'void' here but deduced as 'int' in earlier return statement}}
+}
+
+auto *g() {
+  return; // expected-error {{cannot deduce return type 'auto *' from omitted return expression}}
+}
+
+decltype(h1) h1() { // expected-error {{use of undeclared identifier 'h1'}}
+  return;
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -4098,7 +4098,9 @@
   } else if (!RetValExp && !HasDependentReturnType) {
 FunctionDecl *FD = getCurFunctionDecl();
 
-if (getLangOpts().CPlusPlus11 && FD && FD->isConstexpr()) {
+if (FD->isInvalidDecl()) {
+  // Don't redundantly warn about "return;" if the return type is invalid.
+} else if (getLangOpts().CPlusPlus11 && FD && FD->isConstexpr()) {
   // C++11 [stmt.return]p2
   Diag(ReturnLoc, diag::err_constexpr_return_missing_expr)
   << FD << FD->isConsteval();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119067: [clang-format] Fix DefinitionBlockSeparator extra empty lines

2022-02-06 Thread ksyx via Phabricator via cfe-commits
ksyx updated this revision to Diff 406271.
ksyx added a comment.

- Remove return after else


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

https://reviews.llvm.org/D119067

Files:
  clang/lib/Format/DefinitionBlockSeparator.cpp
  clang/unittests/Format/DefinitionBlockSeparatorTest.cpp

Index: clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
===
--- clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -109,6 +109,15 @@
"};",
Style);
 
+  verifyFormat("union foo {\n"
+   "  int i, j;\n"
+   "};\n"
+   "\n"
+   "union bar {\n"
+   "  int j, k;\n"
+   "};",
+   Style);
+
   verifyFormat("class foo {\n"
"  int i, j;\n"
"};\n"
@@ -311,6 +320,9 @@
   "int bar3(int j, int k, const enum Bar b) {\n"
   "  // A comment\n"
   "  int r = j % k;\n"
+  "  if (struct S = getS()) {\n"
+  "// if condition\n"
+  "  }\n"
   "  return r;\n"
   "}\n";
   std::string Postfix = "\n"
@@ -364,6 +376,9 @@
 "int bar3(int j, int k, const enum Bar b) {\n"
 "  // A comment\n"
 "  int r = j % k;\n"
+"  if (struct S = getS()) {\n"
+"// if condition\n"
+"  }\n"
 "  return r;\n"
 "}\n"
 "} // namespace";
@@ -425,6 +440,10 @@
"{\n"
"  // A comment\n"
"  int r = j % k;\n"
+   "  if (struct S = getS())\n"
+   "  {\n"
+   "// if condition\n"
+   "  }\n"
"  return r;\n"
"}\n"
"} // namespace NS",
@@ -473,6 +492,9 @@
 "int bar3(int j, int k, const enum Bar b) {\n"
 "  // A comment\n"
 "  int r = j % k;\n"
+"  if (struct S = getS()) {\n"
+"// if condition\n"
+"  }\n"
 "  return r;\n"
 "}\n"
 "} // namespace";
Index: clang/lib/Format/DefinitionBlockSeparator.cpp
===
--- clang/lib/Format/DefinitionBlockSeparator.cpp
+++ clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -35,18 +35,31 @@
   const bool IsNeverStyle =
   Style.SeparateDefinitionBlocks == FormatStyle::SDS_Never;
   const AdditionalKeywords  = Tokens.getKeywords();
-  auto LikelyDefinition = [this, ExtraKeywords](const AnnotatedLine *Line,
-bool ExcludeEnum = false) {
+  auto GetBracketLevelChange = [](const FormatToken *Tok) {
+if (Tok->isOneOf(tok::l_brace, tok::l_paren, tok::l_square))
+  return 1;
+if (Tok->isOneOf(tok::r_brace, tok::r_paren, tok::r_square))
+  return -1;
+return 0;
+  };
+  auto LikelyDefinition = [&](const AnnotatedLine *Line,
+  bool ExcludeEnum = false) {
 if ((Line->MightBeFunctionDecl && Line->mightBeFunctionDefinition()) ||
 Line->startsWithNamespace())
   return true;
 FormatToken *CurrentToken = Line->First;
+int BracketLevel = 0;
 while (CurrentToken) {
-  if (CurrentToken->isOneOf(tok::kw_class, tok::kw_struct) ||
-  (Style.isJavaScript() && CurrentToken->is(ExtraKeywords.kw_function)))
-return true;
-  if (!ExcludeEnum && CurrentToken->is(tok::kw_enum))
-return true;
+  if (BracketLevel == 0) {
+if ((CurrentToken->isOneOf(tok::kw_class, tok::kw_struct,
+   tok::kw_union) ||
+ (Style.isJavaScript() &&
+  CurrentToken->is(ExtraKeywords.kw_function
+  return true;
+if (!ExcludeEnum && CurrentToken->is(tok::kw_enum))
+  return true;
+  }
+  BracketLevel += GetBracketLevelChange(CurrentToken);
   CurrentToken = CurrentToken->Next;
 }
 return false;
@@ -104,11 +117,15 @@
 const auto HasEnumOnLine = [&]() {
   FormatToken *CurrentToken = CurrentLine->First;
   bool FoundEnumKeyword = false;
+  int BracketLevel = 0;
   while (CurrentToken) {
-if (CurrentToken->is(tok::kw_enum))
-  FoundEnumKeyword = true;
-else if (FoundEnumKeyword && CurrentToken->is(tok::l_brace))
-  return true;
+if (BracketLevel == 0) {
+  if (CurrentToken->is(tok::kw_enum))
+FoundEnumKeyword = true;
+  else if (FoundEnumKeyword && 

[PATCH] D119067: [clang-format] Fix DefinitionBlockSeparator extra empty lines

2022-02-06 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/DefinitionBlockSeparator.cpp:41
+  return 1;
+else if (Tok->isOneOf(tok::r_brace, tok::r_paren, tok::r_square))
+  return -1;

This is also an else after return. ;)


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

https://reviews.llvm.org/D119067

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


[PATCH] D117391: [AST] Ignore implicit nodes in CastExpr::getConversionFunction

2022-02-06 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

I have now convinced myself that including `FullExpr` in 
`skipImplicitTemporary` gives an improvement in `consteval` diagnostics. But 
I'm still not sure why. Motivating example, derived from cxx2a-consteval.cpp:

  struct A {
int *p = new int(42);
consteval A ret_a() const {
return A{};
}
  };
  
  consteval const A _lvalue_ref(const A &) {
return a;
  }
  
  void test() {
constexpr A a{nullptr};
  
// error: call to consteval function 'A::ret_a' is not a constant expression
// { (void)a.ret_a(); }
  
// error: call to consteval function 'to_lvalue_ref' is not a constant 
expression
// { (void)to_lvalue_ref(A{}); }
  
// error: call to consteval function 'to_lvalue_ref' is not a constant 
expression
// but should probably also raise
// error: call to consteval function 'A::ret_a' is not a constant expression
{ (void)to_lvalue_ref(a.ret_a()); }
  }

It's interesting to experiment with these one by one

- `A::ret_a` returns a new A, whose constructor does heap allocation; no 
consteval possible
- `to_lvalue_ref` attempts to return a reference to a temporary; no consteval 
possible

Composing the two as in the last example, it seems to me, should print both 
diagnostics. Mainline Clang doesn't, but changing `skipImplicitTemporary` to 
also skip `FullExpr`s does (also allowing removal of all `IgnoreImplicit` from 
`getSubExprAsWritten` and `getConversionFunction`).

It seems intuitively right to me. I'm just a little peeved that I can't figure 
out the connection between the diagnostic emission and `skipImplicitTemporary`.




Comment at: clang/lib/AST/Expr.cpp:1946-1947
   for (const CastExpr *E = this; E; E = dyn_cast(SubExpr)) {
 SubExpr = skipImplicitTemporary(E->getSubExpr());
+SubExpr = SubExpr->IgnoreImplicit();
 

davrec wrote:
> aaron.ballman wrote:
> > `IgnoreImplicit()` calls `IgnoreImplicitSingleStep()` eventually, and that 
> > call does the same work as `skipImplicitTemporary()`, so I think the end 
> > result here should be the same.
> As I look at this a second time, I just realized...calling IgnoreImplicit 
> here mean that the loop only ever runs one iteration, since IgnoreImplicit 
> presumably skips over ImplicitCastExprs.  While I liked how Kim did revision 
> initially because it seemed to handle the constructor conversions similarly 
> to their handling of getSubExprAsWritten() above, now I think something 
> different is needed here.
> 
> Proposed alternative:
> Right now skipIimplicitTemporary does what IgnoreImplicit does *except* skip 
> over a) ImplicitCastExprs and b) FullExprs (= ConstantExprs or 
> ExprWithCleanups).
> 
> Kim has identified that we need to skip over at least ConstantExprs at least 
> in this case (i.e. the most conservative possible fix would be to skip over 
> ConstantExprs just before the cast in line 1950).
> 
> But perhaps the better solution, to forestall future bugs, is to skip over 
> FullExprs in skipImplicitTemporary, so that it skips over everything 
> IgnoreImplicit does except ImplicitCastExprs.  (And, some documentation 
> should be added to `skipImplicitTemporary` to that effect, to aid future 
> maintenance.)
> 
> I can't see offhand how the other uses of skipImplicitTemporary would be 
> negatively affected by additionally skipping over FullExprs.
> 
> Aaron what do you think?  Kim can you verify this alternative would also 
> solve the problem without breaking any tests?
> 
@aaron.ballman Just removing the `skipImplicitTemporary` line is probably not 
going to work, since that's the first time `SubExpr` is assigned a 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117391

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


[clang] 631b94c - [Driver] Remove redundant string initialization (NFC)

2022-02-06 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-02-06T10:54:42-08:00
New Revision: 631b94cc22a83205c1d26baadb579b9c5576c8eb

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

LOG: [Driver] Remove redundant string initialization (NFC)

Identified with readability-redundant-string-init.

Added: 


Modified: 
clang/lib/Driver/ToolChains/WebAssembly.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp 
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index 4fdfb7e1762e0..292cf4d66971f 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -503,7 +503,7 @@ void WebAssembly::addLibStdCXXIncludePaths(
   bool IsKnownOs = (getTriple().getOS() != llvm::Triple::UnknownOS);
 
   // This is similar to detectLibcxxVersion()
-  std::string Version = "";
+  std::string Version;
   {
 std::error_code EC;
 Generic_GCC::GCCVersion MaxVersion =



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


[PATCH] D117898: [Clang] Add elementwise saturated add/sub builtins

2022-02-06 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon updated this revision to Diff 406264.
RKSimon added a comment.

rebase, simplify description in documentation and add _BitInt test coverage


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117898

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -21,6 +21,22 @@
   static_assert(!is_const::value);
 }
 
+void test_builtin_elementwise_add_sat() {
+  const int a = 2;
+  int b = 1;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
+
+void test_builtin_elementwise_sub_sat() {
+  const int a = 2;
+  int b = 1;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
+
 void test_builtin_elementwise_max() {
   const int a = 2;
   int b = 1;
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -33,6 +33,122 @@
   // expected-error@-1 {{1st argument must be a signed integer or floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_add_sat(int i, short s, double d, float4 v, int3 iv, unsigned3 uv, int *p) {
+  i = __builtin_elementwise_add_sat(p, d);
+  // expected-error@-1 {{arguments are of different types ('int *' vs 'double')}}
+
+  struct Foo foo = __builtin_elementwise_add_sat(i, i);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'int'}}
+
+  i = __builtin_elementwise_add_sat(i);
+  // expected-error@-1 {{too few arguments to function call, expected 2, have 1}}
+
+  i = __builtin_elementwise_add_sat();
+  // expected-error@-1 {{too few arguments to function call, expected 2, have 0}}
+
+  i = __builtin_elementwise_add_sat(i, i, i);
+  // expected-error@-1 {{too many arguments to function call, expected 2, have 3}}
+
+  i = __builtin_elementwise_add_sat(v, iv);
+  // expected-error@-1 {{arguments are of different types ('float4' (vector of 4 'float' values) vs 'int3' (vector of 3 'int' values))}}
+
+  i = __builtin_elementwise_add_sat(uv, iv);
+  // expected-error@-1 {{arguments are of different types ('unsigned3' (vector of 3 'unsigned int' values) vs 'int3' (vector of 3 'int' values))}}
+
+  v = __builtin_elementwise_add_sat(v, v);
+  // expected-error@-1 {{1st argument must be a vector of integers (was 'float4' (vector of 4 'float' values))}}
+
+  s = __builtin_elementwise_add_sat(i, s);
+
+  enum e { one,
+   two };
+  i = __builtin_elementwise_add_sat(one, two);
+
+  enum f { three };
+  enum f x = __builtin_elementwise_add_sat(one, three);
+
+  _BitInt(32) ext; // expected-warning {{'_BitInt' in C17 and earlier is a Clang extension}}
+  ext = __builtin_elementwise_add_sat(ext, ext);
+
+  const int ci;
+  i = __builtin_elementwise_add_sat(ci, i);
+  i = __builtin_elementwise_add_sat(i, ci);
+  i = __builtin_elementwise_add_sat(ci, ci);
+
+  i = __builtin_elementwise_add_sat(i, int_as_one); // ok (attributes don't match)?
+  i = __builtin_elementwise_add_sat(i, b);  // ok (sugar doesn't match)?
+
+  int A[10];
+  A = __builtin_elementwise_add_sat(A, A);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was 'int *')}}
+
+  int(ii);
+  int j;
+  j = __builtin_elementwise_add_sat(i, j);
+
+  _Complex float c1, c2;
+  c1 = __builtin_elementwise_add_sat(c1, c2);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
+}
+
+void test_builtin_elementwise_sub_sat(int i, short s, double d, float4 v, int3 iv, unsigned3 uv, int *p) {
+  i = __builtin_elementwise_sub_sat(p, d);
+  // expected-error@-1 {{arguments are of different types ('int *' vs 'double')}}
+
+  struct Foo foo = __builtin_elementwise_sub_sat(i, i);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'int'}}
+
+  i = __builtin_elementwise_sub_sat(i);
+  // expected-error@-1 {{too few arguments to function call, expected 2, have 1}}
+
+  i = __builtin_elementwise_sub_sat();
+  // expected-error@-1 {{too few arguments to function call, expected 2, have 0}}
+
+  i = __builtin_elementwise_sub_sat(i, i, i);
+  // expected-error@-1 {{too many arguments to function call, expected 2, have 3}}
+
+  i = __builtin_elementwise_sub_sat(v, iv);
+  // expected-error@-1 

[clang] 1ab7d43 - [clang][CodeGen] Add _BitInt test coverage to builtins-elementwise-math.c

2022-02-06 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2022-02-06T17:17:28Z
New Revision: 1ab7d43bf9e0e77b38ae558907451a8295531986

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

LOG: [clang][CodeGen] Add _BitInt test coverage to builtins-elementwise-math.c

As suggested on D117898, we should be testing irregular _BitInt types with the 
__builtin_elementwise_* intrinsics

Added: 


Modified: 
clang/test/CodeGen/builtins-elementwise-math.c

Removed: 




diff  --git a/clang/test/CodeGen/builtins-elementwise-math.c 
b/clang/test/CodeGen/builtins-elementwise-math.c
index a4785b8f28f22..6a786432aed8c 100644
--- a/clang/test/CodeGen/builtins-elementwise-math.c
+++ b/clang/test/CodeGen/builtins-elementwise-math.c
@@ -10,7 +10,8 @@ bar b;
 
 void test_builtin_elementwise_abs(float f1, float f2, double d1, double d2,
   float4 vf1, float4 vf2, si8 vi1, si8 vi2,
-  long long int i1, long long int i2, short 
si) {
+  long long int i1, long long int i2, short si,
+  _BitInt(31) bi1, _BitInt(31) bi2) {
   // CHECK-LABEL: define void @test_builtin_elementwise_abs(
   // CHECK:  [[F1:%.+]] = load float, float* %f1.addr, align 4
   // CHECK-NEXT:  call float @llvm.fabs.f32(float [[F1]])
@@ -37,6 +38,10 @@ void test_builtin_elementwise_abs(float f1, float f2, double 
d1, double d2,
   const si8 cvi2 = vi2;
   vi2 = __builtin_elementwise_abs(cvi2);
 
+  // CHECK:  [[BI1:%.+]] = load i31, i31* %bi1.addr, align 4
+  // CHECK-NEXT: call i31 @llvm.abs.i31(i31 [[BI1]], i1 false)
+  bi2 = __builtin_elementwise_abs(bi1);
+
   // CHECK:  [[IA1:%.+]] = load i32, i32 addrspace(1)* @int_as_one, align 4
   // CHECK-NEXT: call i32 @llvm.abs.i32(i32 [[IA1]], i1 false)
   b = __builtin_elementwise_abs(int_as_one);
@@ -54,7 +59,9 @@ void test_builtin_elementwise_abs(float f1, float f2, double 
d1, double d2,
 void test_builtin_elementwise_max(float f1, float f2, double d1, double d2,
   float4 vf1, float4 vf2, long long int i1,
   long long int i2, si8 vi1, si8 vi2,
-  unsigned u1, unsigned u2, u4 vu1, u4 vu2) {
+  unsigned u1, unsigned u2, u4 vu1, u4 vu2,
+  _BitInt(31) bi1, _BitInt(31) bi2,
+  unsigned _BitInt(55) bu1, unsigned 
_BitInt(55) bu2) {
   // CHECK-LABEL: define void @test_builtin_elementwise_max(
   // CHECK:  [[F1:%.+]] = load float, float* %f1.addr, align 4
   // CHECK-NEXT: [[F2:%.+]] = load float, float* %f2.addr, align 4
@@ -99,6 +106,16 @@ void test_builtin_elementwise_max(float f1, float f2, 
double d1, double d2,
   // CHECK-NEXT: call <4 x i32> @llvm.umax.v4i32(<4 x i32> [[VU1]], <4 x i32> 
[[VU2]])
   vu1 = __builtin_elementwise_max(vu1, vu2);
 
+  // CHECK:  [[BI1:%.+]] = load i31, i31* %bi1.addr, align 4
+  // CHECK-NEXT: [[BI2:%.+]] = load i31, i31* %bi2.addr, align 4
+  // CHECK-NEXT: call i31 @llvm.smax.i31(i31 [[BI1]], i31 [[BI2]])
+  bi1 = __builtin_elementwise_max(bi1, bi2);
+
+  // CHECK:  [[BU1:%.+]] = load i55, i55* %bu1.addr, align 8
+  // CHECK-NEXT: [[BU2:%.+]] = load i55, i55* %bu2.addr, align 8
+  // CHECK-NEXT: call i55 @llvm.umax.i55(i55 [[BU1]], i55 [[BU2]])
+  bu1 = __builtin_elementwise_max(bu1, bu2);
+
   // CHECK:  [[CVF1:%.+]] = load <4 x float>, <4 x float>* %cvf1, align 16
   // CHECK-NEXT: [[VF2:%.+]] = load <4 x float>, <4 x float>* %vf2.addr, align 
16
   // CHECK-NEXT: call <4 x float> @llvm.maxnum.v4f32(<4 x float> [[CVF1]], <4 
x float> [[VF2]])
@@ -122,7 +139,9 @@ void test_builtin_elementwise_max(float f1, float f2, 
double d1, double d2,
 void test_builtin_elementwise_min(float f1, float f2, double d1, double d2,
   float4 vf1, float4 vf2, long long int i1,
   long long int i2, si8 vi1, si8 vi2,
-  unsigned u1, unsigned u2, u4 vu1, u4 vu2) {
+  unsigned u1, unsigned u2, u4 vu1, u4 vu2,
+  _BitInt(31) bi1, _BitInt(31) bi2,
+  unsigned _BitInt(55) bu1, unsigned 
_BitInt(55) bu2) {
   // CHECK-LABEL: define void @test_builtin_elementwise_min(
   // CHECK:  [[F1:%.+]] = load float, float* %f1.addr, align 4
   // CHECK-NEXT: [[F2:%.+]] = load float, float* %f2.addr, align 4
@@ -173,6 +192,16 @@ void test_builtin_elementwise_min(float f1, float f2, 
double d1, double d2,
   // CHECK-NEXT: call <4 x i32> @llvm.umin.v4i32(<4 x i32> [[VU1]], <4 x i32> 
[[VU2]])
   vu1 = __builtin_elementwise_min(vu1, vu2);
 
+  // CHECK:  [[BI1:%.+]] = load i31, 

[PATCH] D117522: [clang-tidy] Add modernize-macro-to-enum check

2022-02-06 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Ok, thanks for the explanation! I'm mostly interested on the warning message, 
we've had situations before where the warning describes the problem **and** the 
solution, which can easily lead to confusion. From the tests I can see the 
message is quite generic "use an enum", so it won't push users to prefer one 
variant over the other.

I'd like to play a bit with the patch and see what pops in our codebase but 
somehow I get an error when downloading, do you happen to know what could be 
wrong? Alternatively if there's any other easy way to checkout the patch and 
test it :)

  $ arc patch D117522
   Exception 
  preg_match(): Passing null to parameter #2 ($subject) of type string is 
deprecated
  (Run with `--trace` for a full exception trace.)



> This check is more about implementing Enum.1 Prefer enumerations over macros.

Should a `cppcoreguidelines` alias be added in that case?


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

https://reviews.llvm.org/D117522

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


[PATCH] D119067: [clang-format] Fix DefinitionBlockSeparator extra empty lines

2022-02-06 Thread ksyx via Phabricator via cfe-commits
ksyx updated this revision to Diff 406245.
ksyx marked 3 inline comments as done.
ksyx edited the summary of this revision.
ksyx added a comment.

- Add or remove empty lines surrounding `union`s.
- Move new test location.
- Remove else immediately above return.


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

https://reviews.llvm.org/D119067

Files:
  clang/lib/Format/DefinitionBlockSeparator.cpp
  clang/unittests/Format/DefinitionBlockSeparatorTest.cpp

Index: clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
===
--- clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -109,6 +109,15 @@
"};",
Style);
 
+  verifyFormat("union foo {\n"
+   "  int i, j;\n"
+   "};\n"
+   "\n"
+   "union bar {\n"
+   "  int j, k;\n"
+   "};",
+   Style);
+
   verifyFormat("class foo {\n"
"  int i, j;\n"
"};\n"
@@ -311,6 +320,9 @@
   "int bar3(int j, int k, const enum Bar b) {\n"
   "  // A comment\n"
   "  int r = j % k;\n"
+  "  if (struct S = getS()) {\n"
+  "// if condition\n"
+  "  }\n"
   "  return r;\n"
   "}\n";
   std::string Postfix = "\n"
@@ -364,6 +376,9 @@
 "int bar3(int j, int k, const enum Bar b) {\n"
 "  // A comment\n"
 "  int r = j % k;\n"
+"  if (struct S = getS()) {\n"
+"// if condition\n"
+"  }\n"
 "  return r;\n"
 "}\n"
 "} // namespace";
@@ -425,6 +440,10 @@
"{\n"
"  // A comment\n"
"  int r = j % k;\n"
+   "  if (struct S = getS())\n"
+   "  {\n"
+   "// if condition\n"
+   "  }\n"
"  return r;\n"
"}\n"
"} // namespace NS",
@@ -473,6 +492,9 @@
 "int bar3(int j, int k, const enum Bar b) {\n"
 "  // A comment\n"
 "  int r = j % k;\n"
+"  if (struct S = getS()) {\n"
+"// if condition\n"
+"  }\n"
 "  return r;\n"
 "}\n"
 "} // namespace";
Index: clang/lib/Format/DefinitionBlockSeparator.cpp
===
--- clang/lib/Format/DefinitionBlockSeparator.cpp
+++ clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -35,18 +35,31 @@
   const bool IsNeverStyle =
   Style.SeparateDefinitionBlocks == FormatStyle::SDS_Never;
   const AdditionalKeywords  = Tokens.getKeywords();
-  auto LikelyDefinition = [this, ExtraKeywords](const AnnotatedLine *Line,
-bool ExcludeEnum = false) {
+  auto GetBracketLevelChange = [](const FormatToken *Tok) {
+if (Tok->isOneOf(tok::l_brace, tok::l_paren, tok::l_square))
+  return 1;
+else if (Tok->isOneOf(tok::r_brace, tok::r_paren, tok::r_square))
+  return -1;
+return 0;
+  };
+  auto LikelyDefinition = [&](const AnnotatedLine *Line,
+  bool ExcludeEnum = false) {
 if ((Line->MightBeFunctionDecl && Line->mightBeFunctionDefinition()) ||
 Line->startsWithNamespace())
   return true;
 FormatToken *CurrentToken = Line->First;
+int BracketLevel = 0;
 while (CurrentToken) {
-  if (CurrentToken->isOneOf(tok::kw_class, tok::kw_struct) ||
-  (Style.isJavaScript() && CurrentToken->is(ExtraKeywords.kw_function)))
-return true;
-  if (!ExcludeEnum && CurrentToken->is(tok::kw_enum))
-return true;
+  if (BracketLevel == 0) {
+if ((CurrentToken->isOneOf(tok::kw_class, tok::kw_struct,
+   tok::kw_union) ||
+ (Style.isJavaScript() &&
+  CurrentToken->is(ExtraKeywords.kw_function
+  return true;
+if (!ExcludeEnum && CurrentToken->is(tok::kw_enum))
+  return true;
+  }
+  BracketLevel += GetBracketLevelChange(CurrentToken);
   CurrentToken = CurrentToken->Next;
 }
 return false;
@@ -104,11 +117,15 @@
 const auto HasEnumOnLine = [&]() {
   FormatToken *CurrentToken = CurrentLine->First;
   bool FoundEnumKeyword = false;
+  int BracketLevel = 0;
   while (CurrentToken) {
-if (CurrentToken->is(tok::kw_enum))
-  FoundEnumKeyword = true;
-else if (FoundEnumKeyword && CurrentToken->is(tok::l_brace))
-  

[PATCH] D119077: clangd SemanticHighlighting: added support for highlighting overloaded operators

2022-02-06 Thread Iannis de Zwart via Phabricator via cfe-commits
iannisdezwart updated this revision to Diff 406244.
iannisdezwart added a comment.

Fixed a bug I introduced by removing a null-check. I added the null-check back 
in again.


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

https://reviews.llvm.org/D119077

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp

Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
@@ -26,6 +27,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
@@ -449,6 +451,8 @@
   }
 
   const HeuristicResolver *getResolver() const { return Resolver; }
+  const SourceManager () const { return SourceMgr; }
+  const syntax::TokenBuffer () const { return TB; }
 
 private:
   llvm::Optional getRangeForSourceLocation(SourceLocation Loc) {
@@ -527,13 +531,135 @@
 return true;
   }
 
+  // Returns the token immediately after a given location.
+  // FIXME: Is this really the best way to do this?
+  const syntax::Token *nextToken(SourceLocation Loc) {
+if (Loc.isInvalid())
+  return nullptr;
+
+return llvm::partition_point(
+H.getTB().spelledTokens(H.getSourceMgr().getFileID(Loc)),
+[&](const syntax::Token ) { return T.location() <= Loc; });
+  }
+
+  // Expands a HighlightingToken to another SourceLocation. The token at the
+  // given location will be highlighted exactly the same way.
+  void expandToken(HighlightingToken , SourceLocation Loc) {
+if (Loc.isInvalid())
+  return;
+
+auto  = H.addToken(Loc, OldTok.Kind);
+NewTok.Modifiers = OldTok.Modifiers;
+  }
+
+  // For an overloaded operator `operator<<(...)`, we want to the highlighting
+  // to also include the `<<` part. If we don't do this, only the `operator`
+  // part will be correctly highlighted.
+  void expandOverloadedOperator(SourceLocation Loc,
+HighlightingToken ) {
+if (Loc.isInvalid())
+  return;
+
+const auto *NextTok = nextToken(Loc);
+if (!NextTok)
+  return;
+
+expandToken(OpKeywTok, NextTok->location());
+
+// If this operator is `[` or `(`, we also want to highlight the matching
+// `]` or `)`.
+if (NextTok->kind() == tok::l_paren || NextTok->kind() == tok::l_square) {
+  const auto *ParenEndTok = nextToken(NextTok->location());
+  if (ParenEndTok)
+expandToken(OpKeywTok, ParenEndTok->location()); // `]` or `)`.
+}
+
+// If this operator is `new[]` or `delete[]`,
+// we also want to highlight the `[]` part.
+else if (NextTok->kind() == tok::kw_new ||
+ NextTok->kind() == tok::kw_delete) {
+  NextTok = nextToken(NextTok->location());
+  if (!NextTok || NextTok->kind() != tok::l_square)
+return;
+  expandToken(OpKeywTok, NextTok->location()); // `[`.
+  const auto *ParenEndTok = nextToken(NextTok->location());
+  if (ParenEndTok)
+expandToken(OpKeywTok, ParenEndTok->location()); // `]`.
+}
+  }
+
+  void highlightOperatorCallExpr(SourceLocation Loc, FunctionDecl *FD) {
+auto HighlightingKind = kindForDecl(FD, H.getResolver());
+if (!HighlightingKind)
+  return;
+
+auto  = H.addToken(Loc, *HighlightingKind);
+if (auto Mod = scopeModifier(FD))
+  Tok.addModifier(*Mod);
+if (isConst(FD))
+  Tok.addModifier(HighlightingModifier::Readonly);
+if (isStatic(FD))
+  Tok.addModifier(HighlightingModifier::Static);
+if (isAbstract(FD))
+  Tok.addModifier(HighlightingModifier::Abstract);
+if (isVirtual(FD))
+  Tok.addModifier(HighlightingModifier::Virtual);
+if (isDependent(FD))
+  Tok.addModifier(HighlightingModifier::DependentName);
+if (isDefaultLibrary(FD))
+  Tok.addModifier(HighlightingModifier::DefaultLibrary);
+if (FD->isDeprecated())
+  Tok.addModifier(HighlightingModifier::Deprecated);
+  }
+
+  // Highlight called overloaded operators.
+  // E.g. `<<` in `std::cout << "foo"`.
+  bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *O) {
+// Highlight calls to overloaded operators as function-like types.
+auto *FD = dyn_cast_or_null(O->getCalleeDecl());
+if (!FD)
+  return true;
+
+auto HighlightingKind = kindForDecl(FD, H.getResolver());
+if (!HighlightingKind)
+  return true;
+
+auto Loc = O->getOperatorLoc();
+if (Loc.isMacroID())
+  return true;
+
+highlightOperatorCallExpr(Loc, FD);
+

[PATCH] D119077: clangd SemanticHighlighting: added support for highlighting overloaded operators

2022-02-06 Thread Iannis de Zwart via Phabricator via cfe-commits
iannisdezwart created this revision.
iannisdezwart added a reviewer: nridge.
iannisdezwart added a project: clang-tools-extra.
Herald added subscribers: usaxena95, kadircet, arphaman.
iannisdezwart requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

Recently I switched from the default vscode Microsoft C/C++ extension to clangd 
because of performance reasons.
I found out clangd lacks one of my most liked features from the Microsoft 
extension: overloaded operators are not highlighted as functions.
This is a very essential semantic indicator, because overloaded operators can 
have very different functionality.
This patch adds syntax highlighting for the following patterns:

1. operator calls to overloaded operators, e.g.

  std::cout << 42; // `<<` is highlighted as if it were a function.
  std::string s;
  s = "Hello, World!"; // `=` ditto
  some_map["key"] = "value"; // `[` and `]`
  some_functor(1, 2, 3); // `(` and `)`



2. function calls to overloaded operators in function notation, e.g.

  operator<<(std::cout, 42); // `operator<<`
  some_ptr->some_field.operator++(); // `operator++`
  operator delete[](ptr) // `operator delete[]`



3. any reference to an overloaded operator function, e.g.

  const auto  = some_struct.operator<<; // `operator<<`

Before:
F22005275: Screenshot 2022-02-06 at 14.33.20.png 


After:
F22005248: Screenshot 2022-02-06 at 14.31.03.png 



Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119077

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp

Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
@@ -26,6 +27,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
@@ -449,6 +451,8 @@
   }
 
   const HeuristicResolver *getResolver() const { return Resolver; }
+  const SourceManager () const { return SourceMgr; }
+  const syntax::TokenBuffer () const { return TB; }
 
 private:
   llvm::Optional getRangeForSourceLocation(SourceLocation Loc) {
@@ -527,13 +531,135 @@
 return true;
   }
 
+  // Returns the token immediately after a given location.
+  // FIXME: Is this really the best way to do this?
+  const syntax::Token *nextToken(SourceLocation Loc) {
+if (Loc.isInvalid())
+  return nullptr;
+
+return llvm::partition_point(
+H.getTB().spelledTokens(H.getSourceMgr().getFileID(Loc)),
+[&](const syntax::Token ) { return T.location() <= Loc; });
+  }
+
+  // Expands a HighlightingToken to another SourceLocation. The token at the
+  // given location will be highlighted exactly the same way.
+  void expandToken(HighlightingToken , SourceLocation Loc) {
+if (Loc.isInvalid())
+  return;
+
+auto  = H.addToken(Loc, OldTok.Kind);
+NewTok.Modifiers = OldTok.Modifiers;
+  }
+
+  // For an overloaded operator `operator<<(...)`, we want to the highlighting
+  // to also include the `<<` part. If we don't do this, only the `operator`
+  // part will be correctly highlighted.
+  void expandOverloadedOperator(SourceLocation Loc,
+HighlightingToken ) {
+if (Loc.isInvalid())
+  return;
+
+const auto *NextTok = nextToken(Loc);
+if (!NextTok)
+  return;
+
+expandToken(OpKeywTok, NextTok->location());
+
+// If this operator is `[` or `(`, we also want to highlight the matching
+// `]` or `)`.
+if (NextTok->kind() == tok::l_paren || NextTok->kind() == tok::l_square) {
+  const auto *ParenEndTok = nextToken(NextTok->location());
+  if (ParenEndTok)
+expandToken(OpKeywTok, ParenEndTok->location()); // `]` or `)`.
+}
+
+// If this operator is `new[]` or `delete[]`,
+// we also want to highlight the `[]` part.
+else if (NextTok->kind() == tok::kw_new ||
+ NextTok->kind() == tok::kw_delete) {
+  NextTok = nextToken(NextTok->location());
+  if (!NextTok || NextTok->kind() != tok::l_square)
+return;
+  expandToken(OpKeywTok, NextTok->location()); // `[`.
+  const auto *ParenEndTok = nextToken(NextTok->location());
+  if (ParenEndTok)
+expandToken(OpKeywTok, ParenEndTok->location()); // `]`.
+}
+  }
+
+  void highlightOperatorCallExpr(SourceLocation Loc, FunctionDecl *FD) {
+auto HighlightingKind = kindForDecl(FD, 

[PATCH] D119067: [clang-format] Fix DefinitionBlockSeparator extra empty lines

2022-02-06 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/DefinitionBlockSeparator.cpp:39
+  auto GetBracketLevelChange = [](const FormatToken *Tok) {
+if (Tok->isOneOf(tok::l_brace, tok::l_paren, tok::l_square))
+  return 1;

I would prefer a switch over the tokens.

But definitely no else after return.



Comment at: clang/lib/Format/DefinitionBlockSeparator.cpp:55
+  if (BracketLevel == 0) {
+if ((CurrentToken->isOneOf(tok::kw_class, tok::kw_struct) ||
+ (Style.isJavaScript() &&

What about union?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119067

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


[PATCH] D111100: enable plugins for clang-tidy

2022-02-06 Thread Michał Górny via Phabricator via cfe-commits
mgorny reopened this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

This breaks build of clang against system-installed LLVM:

  CMake Error at /usr/lib/llvm/14/lib64/cmake/llvm/AddLLVM.cmake:1821 
(add_dependencies):
The dependency target "LLVMHello" of target "check-all" does not exist.
  Call Stack (most recent call first):
CMakeLists.txt:574 (add_lit_target)

`LLVMHello` isn't installed, so you can't rely on it being available. The 
customary way to resolve this kind of issue would be to check whether the 
target is present, and build it via `add_subdirectory()` against the respective 
LLVM directory (see how LLVMTestingSupport is handled in unittests). That said, 
you will also probably need to account for different build path (it will land 
in clang's shlibdir).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D00

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


[PATCH] D117500: [clang] Mention MS on-demand TLS initialization in release notes

2022-02-06 Thread Maurice Heumann via Phabricator via cfe-commits
momo5502 added a comment.

Seems like this can be merged, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117500

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


[PATCH] D59254: [RFC] Implementation of Clang randstruct

2022-02-06 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D59254#3299150 , @Dan wrote:

> Hi @void, @connorkuehl
>
> Reminding that I also participated in working on this, and back then in 2019 
> I did manage to compile and boot a working Linux kernel with this feature 
> enabled in Clang. It was a fully built Fedora Linux 5.3 kernel. I remember 
> though that @connorkuehl made various cleanups and refactoring following from 
> my branch, but work stopped at some point and I don't remember at what state 
> we left it it exactly.. :(
>
> This is the Fedora Copr repo with the kernel RPM and all the LLVM/Clang 
> package sources that used to build it: 
> https://copr.fedorainfracloud.org/coprs/alonid/llvm-experimental
>
> As for LLVM source, the git branch which was used back then is 
> `randstruct-demo-fc30` in my Github fork - 
> https://github.com/da-x/llvm-project/

Thanks, @Dan and @connorkuehl!

I cherry-picked Connor's changes to top-of-tree LLVM. It wasn't too bad. I'll 
see how it works with the current Linux kernel. @jfb mentioned some really good 
issues having to do with C++. Because of how horrible it would be to support 
C++, I propose restricting this feature to C (probably a decision that's 
already been made).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59254

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


[PATCH] D119067: [clang-format] Fix DefinitionBlockSeparator extra empty lines

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

Looks ok but please rework the tests to keep previous cases untouched.




Comment at: clang/unittests/Format/DefinitionBlockSeparatorTest.cpp:305
   "  int r = j / k;\n"
+  "  if (struct S = getS()) {\n"
+  "// if condition\n"

I'd rather see this added in another function e.g. bar3, because otherwise you 
don't test what was tested before.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119067

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


[PATCH] D119071: [Driver][OpenBSD] -r: imply -nostdlib like GCC

2022-02-06 Thread Brad Smith via Phabricator via cfe-commits
brad updated this revision to Diff 406236.
brad added a comment.

formating.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119071

Files:
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/test/Driver/openbsd.c


Index: clang/test/Driver/openbsd.c
===
--- clang/test/Driver/openbsd.c
+++ clang/test/Driver/openbsd.c
@@ -40,8 +40,9 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64-LD %s
 // RUN: %clang -no-canonical-prefixes -target mips64el-unknown-openbsd %s -### 
2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s
-// CHECK-LD-R: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
-// CHECK-LD-R: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" 
"-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" 
"-L{{.*}}" "-r" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" 
"{{.*}}crtend.o"
+// CHECK-LD-R: "-r"
+// CHECK-LD-R-NOT: "-l
+// CHECK-LD-R-NOT: crt{{[^.]+}}.o
 // CHECK-LD-S: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
 // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" 
"-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" 
"-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" 
"{{.*}}crtend.o"
 // CHECK-LD-T: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -160,7 +160,8 @@
 assert(Output.isNothing() && "Invalid output.");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 const char *crt0 = nullptr;
 const char *crtbegin = nullptr;
 if (!Args.hasArg(options::OPT_shared)) {
@@ -191,7 +192,8 @@
   bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
+   options::OPT_r)) {
 // Use the static OpenMP runtime with -static-openmp
 bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
 !Args.hasArg(options::OPT_static);
@@ -234,7 +236,8 @@
 CmdArgs.push_back("-lcompiler_rt");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 const char *crtend = nullptr;
 if (!Args.hasArg(options::OPT_shared))
   crtend = "crtend.o";


Index: clang/test/Driver/openbsd.c
===
--- clang/test/Driver/openbsd.c
+++ clang/test/Driver/openbsd.c
@@ -40,8 +40,9 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64-LD %s
 // RUN: %clang -no-canonical-prefixes -target mips64el-unknown-openbsd %s -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s
-// CHECK-LD-R: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
-// CHECK-LD-R: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-r" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
+// CHECK-LD-R: "-r"
+// CHECK-LD-R-NOT: "-l
+// CHECK-LD-R-NOT: crt{{[^.]+}}.o
 // CHECK-LD-S: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
 // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
 // CHECK-LD-T: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -160,7 +160,8 @@
 assert(Output.isNothing() && "Invalid output.");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 const char *crt0 = nullptr;
 const char *crtbegin = nullptr;
 if (!Args.hasArg(options::OPT_shared)) {
@@ -191,7 +192,8 @@
   bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
+   options::OPT_r)) {
 // Use the static OpenMP runtime with -static-openmp
 bool 

[PATCH] D119071: [Driver][OpenBSD] -r: imply -nostdlib like GCC

2022-02-06 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added a reviewer: MaskRay.
brad added a project: clang.
brad requested review of this revision.

Similar to D116843 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119071

Files:
  clang/lib/Driver/ToolChains/OpenBSD.cpp
  clang/test/Driver/openbsd.c


Index: clang/test/Driver/openbsd.c
===
--- clang/test/Driver/openbsd.c
+++ clang/test/Driver/openbsd.c
@@ -40,8 +40,9 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64-LD %s
 // RUN: %clang -no-canonical-prefixes -target mips64el-unknown-openbsd %s -### 
2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s
-// CHECK-LD-R: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
-// CHECK-LD-R: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" 
"-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" 
"-L{{.*}}" "-r" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" 
"{{.*}}crtend.o"
+// CHECK-LD-R: "-r"
+// CHECK-LD-R-NOT: "-l
+// CHECK-LD-R-NOT: crt{{[^.]+}}.o
 // CHECK-LD-S: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
 // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" 
"-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" 
"-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" 
"{{.*}}crtend.o"
 // CHECK-LD-T: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -160,7 +160,8 @@
 assert(Output.isNothing() && "Invalid output.");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+  options::OPT_r)) {
 const char *crt0 = nullptr;
 const char *crtbegin = nullptr;
 if (!Args.hasArg(options::OPT_shared)) {
@@ -191,7 +192,8 @@
   bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
+  options::OPT_r)) {
 // Use the static OpenMP runtime with -static-openmp
 bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
 !Args.hasArg(options::OPT_static);
@@ -234,7 +236,8 @@
 CmdArgs.push_back("-lcompiler_rt");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+  options::OPT_r)) {
 const char *crtend = nullptr;
 if (!Args.hasArg(options::OPT_shared))
   crtend = "crtend.o";


Index: clang/test/Driver/openbsd.c
===
--- clang/test/Driver/openbsd.c
+++ clang/test/Driver/openbsd.c
@@ -40,8 +40,9 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64-LD %s
 // RUN: %clang -no-canonical-prefixes -target mips64el-unknown-openbsd %s -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s
-// CHECK-LD-R: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
-// CHECK-LD-R: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-r" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
+// CHECK-LD-R: "-r"
+// CHECK-LD-R-NOT: "-l
+// CHECK-LD-R-NOT: crt{{[^.]+}}.o
 // CHECK-LD-S: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
 // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
 // CHECK-LD-T: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
===
--- clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -160,7 +160,8 @@
 assert(Output.isNothing() && "Invalid output.");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+  options::OPT_r)) {
 const char *crt0 = nullptr;
 const char *crtbegin = nullptr;
 if (!Args.hasArg(options::OPT_shared)) {
@@ -191,7 +192,8 @@
   bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
+  options::OPT_r)) {
 // Use the static OpenMP runtime with -static-openmp
 bool StaticOpenMP = 

[PATCH] D59254: [RFC] Implementation of Clang randstruct

2022-02-06 Thread Dan Aloni via Phabricator via cfe-commits
Dan added a comment.

Hi @void, @connorkuehl

Reminding that I also participated in working on this, and back then in 2019 I 
did manage to compile and boot a working Linux kernel with this feature enabled 
in Clang. It was a fully built Fedora Linux 5.3 kernel. I remember though that 
@connorkuehl made various cleanups and refactoring following from my branch, 
but work stopped at some point and I don't remember at what state we left it it 
exactly.. :(

This is the Fedora Copr repo with the kernel RPM and all the LLVM/Clang package 
sources that used to build it: 
https://copr.fedorainfracloud.org/coprs/alonid/llvm-experimental

As for LLVM source, the git branch which was used back then is 
`randstruct-demo-fc30` in my Github fork - https://github.com/da-x/llvm-project/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59254

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