[PATCH] D109751: [Clang] Support conversion between PPC double-double and IEEE float128

2021-10-14 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/CodeGen/ibm128-cast.c:59
+  // IEEE: %{{.+}} = fadd ppc_fp128 %{{.+}}, %{{.+}}
+  w + q;
+  // CHECK: %{{.+}} = fadd ppc_fp128 %{{.+}}, %{{.+}}

It's controversial enough to consider, as well-formed, a case requiring 
application of the usual arithmetic conversions to a pair of operands with 
floating types that each have distinct values not representable by the type of 
the other operand; it is even more controversial to consider the type with the 
narrower finite range to be the common real type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109751

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


[PATCH] D110257: [CFE][Codegen] Make sure to maintain the contiguity of all the static allocas

2021-10-14 Thread Mahesha S via Phabricator via cfe-commits
hsmhsm updated this revision to Diff 379918.
hsmhsm marked 2 inline comments as done.
hsmhsm added a comment.

Rebase + minor clean-up to patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110257

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGenCUDA/builtins-amdgcn.cu
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
  clang/test/CodeGenCXX/vla.cpp
  clang/test/CodeGenSYCL/address-space-deduction.cpp
  clang/test/OpenMP/amdgcn_target_init_temp_alloca.cpp

Index: clang/test/OpenMP/amdgcn_target_init_temp_alloca.cpp
===
--- clang/test/OpenMP/amdgcn_target_init_temp_alloca.cpp
+++ clang/test/OpenMP/amdgcn_target_init_temp_alloca.cpp
@@ -12,7 +12,9 @@
   int arr[N];
 
   // CHECK:  [[VAR_ADDR:%.+]] = alloca [100 x i32]*, align 8, addrspace(5)
+  // CHECK-NEXT: [[VAR2_ADDR:%.+]] = alloca i32, align 4, addrspace(5)
   // CHECK-NEXT: [[VAR_ADDR_CAST:%.+]] = addrspacecast [100 x i32]* addrspace(5)* [[VAR_ADDR]] to [100 x i32]**
+  // CHECK-NEXT: [[VAR2_ADDR_CAST:%.+]] = addrspacecast i32 addrspace(5)* [[VAR2_ADDR]] to i32*
   // CHECK:  store [100 x i32]* [[VAR:%.+]], [100 x i32]** [[VAR_ADDR_CAST]], align 8
 
 #pragma omp target
Index: clang/test/CodeGenSYCL/address-space-deduction.cpp
===
--- clang/test/CodeGenSYCL/address-space-deduction.cpp
+++ clang/test/CodeGenSYCL/address-space-deduction.cpp
@@ -1,34 +1,33 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple spir64 -fsycl-is-device -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
 
-
 // CHECK-LABEL: @_Z4testv(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[I:%.*]] = alloca i32, align 4
-// CHECK-NEXT:[[I_ASCAST:%.*]] = addrspacecast i32* [[I]] to i32 addrspace(4)*
 // CHECK-NEXT:[[PPTR:%.*]] = alloca i32 addrspace(4)*, align 8
-// CHECK-NEXT:[[PPTR_ASCAST:%.*]] = addrspacecast i32 addrspace(4)** [[PPTR]] to i32 addrspace(4)* addrspace(4)*
 // CHECK-NEXT:[[IS_I_PTR:%.*]] = alloca i8, align 1
-// CHECK-NEXT:[[IS_I_PTR_ASCAST:%.*]] = addrspacecast i8* [[IS_I_PTR]] to i8 addrspace(4)*
 // CHECK-NEXT:[[VAR23:%.*]] = alloca i32, align 4
-// CHECK-NEXT:[[VAR23_ASCAST:%.*]] = addrspacecast i32* [[VAR23]] to i32 addrspace(4)*
 // CHECK-NEXT:[[CP:%.*]] = alloca i8 addrspace(4)*, align 8
-// CHECK-NEXT:[[CP_ASCAST:%.*]] = addrspacecast i8 addrspace(4)** [[CP]] to i8 addrspace(4)* addrspace(4)*
 // CHECK-NEXT:[[ARR:%.*]] = alloca [42 x i32], align 4
-// CHECK-NEXT:[[ARR_ASCAST:%.*]] = addrspacecast [42 x i32]* [[ARR]] to [42 x i32] addrspace(4)*
 // CHECK-NEXT:[[CPP:%.*]] = alloca i8 addrspace(4)*, align 8
-// CHECK-NEXT:[[CPP_ASCAST:%.*]] = addrspacecast i8 addrspace(4)** [[CPP]] to i8 addrspace(4)* addrspace(4)*
 // CHECK-NEXT:[[APTR:%.*]] = alloca i32 addrspace(4)*, align 8
-// CHECK-NEXT:[[APTR_ASCAST:%.*]] = addrspacecast i32 addrspace(4)** [[APTR]] to i32 addrspace(4)* addrspace(4)*
 // CHECK-NEXT:[[STR:%.*]] = alloca i8 addrspace(4)*, align 8
-// CHECK-NEXT:[[STR_ASCAST:%.*]] = addrspacecast i8 addrspace(4)** [[STR]] to i8 addrspace(4)* addrspace(4)*
 // CHECK-NEXT:[[PHI_STR:%.*]] = alloca i8 addrspace(4)*, align 8
-// CHECK-NEXT:[[PHI_STR_ASCAST:%.*]] = addrspacecast i8 addrspace(4)** [[PHI_STR]] to i8 addrspace(4)* addrspace(4)*
 // CHECK-NEXT:[[SELECT_NULL:%.*]] = alloca i8 addrspace(4)*, align 8
-// CHECK-NEXT:[[SELECT_NULL_ASCAST:%.*]] = addrspacecast i8 addrspace(4)** [[SELECT_NULL]] to i8 addrspace(4)* addrspace(4)*
 // CHECK-NEXT:[[SELECT_STR_TRIVIAL1:%.*]] = alloca i8 addrspace(4)*, align 8
-// CHECK-NEXT:[[SELECT_STR_TRIVIAL1_ASCAST:%.*]] = addrspacecast i8 addrspace(4)** [[SELECT_STR_TRIVIAL1]] to i8 addrspace(4)* addrspace(4)*
 // CHECK-NEXT:[[SELECT_STR_TRIVIAL2:%.*]] = alloca i8 addrspace(4)*, align 8
+// CHECK-NEXT:[[I_ASCAST:%.*]] = addrspacecast i32* [[I]] to i32 addrspace(4)*
+// CHECK-NEXT:[[PPTR_ASCAST:%.*]] = addrspacecast i32 addrspace(4)** [[PPTR]] to i32 addrspace(4)* addrspace(4)*
+// CHECK-NEXT:[[IS_I_PTR_ASCAST:%.*]] = addrspacecast i8* [[IS_I_PTR]] to i8 addrspace(4)*
+// CHECK-NEXT:[[VAR23_ASCAST:%.*]] = addrspacecast i32* [[VAR23]] to i32 addrspace(4)*
+// CHECK-NEXT:[[CP_ASCAST:%.*]] = addrspacecast i8 addrspace(4)** [[CP]] to i8 addrspace(4)* addrspace(4)*
+// CHECK-NEXT:[[ARR_ASCAST:%.*]] = addrspacecast [42 x i32]* [[ARR]] to [42 x i32] addrspace(4)*
+// CHECK-NEXT:[[CPP_ASCAST:%.*]] = addrspacecast i8 addrspace(4)** [[CPP]] to i8 addrspace(4)* addrspace(4)*
+// CHECK-NEXT:[[APTR_ASCAST:%.*]] = addrspacecast i32 addrspace(4)** 

[PATCH] D111863: [libunwind] Add an interface for dynamic .eh_frame registration

2021-10-14 Thread Peter S. Housel via Phabricator via cfe-commits
housel added a comment.

In D111863#3065992 , @MaskRay wrote:

> I looked at the libgcc mechanism at one time. I remember that in most cases 
> it just uses `PT_GNU_EH_FRAME` and these eh_frame boundary registry functions 
> are not needed.
> Can ORC just use `PT_GNU_EH_FRAME`?

ORC doesn't go through the system dynamic loader, so there's no program header 
(JITLink doesn't generate one). None of the dynamic loaders I've looked at have 
any way to dynamically register program headers so that they'll be returned by 
`dl_iterate_phdr`. With ORC, code and data segments, including `.eh_frame` 
segments, get allocated in the target execution space and initialized by the 
JITLink memory manager, and the ORC runtime calling these registration 
functions is the only way libunwind will know about these tables.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111863

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


[PATCH] D111154: [WebAssembly] Implementation of table.get/set for reftypes in LLVM IR

2021-10-14 Thread Paulo Matos via Phabricator via cfe-commits
pmatos marked 4 inline comments as done.
pmatos added inline comments.



Comment at: llvm/test/CodeGen/WebAssembly/externref-tableget.ll:8
+
+define %externref @get_externref_from_table(i32 %i) {
+  %p = getelementptr [0 x %externref], [0 x %externref] addrspace (1)* 
@externref_table, i32 0, i32 %i

tlively wrote:
> pmatos wrote:
> > tlively wrote:
> > > It would be good to add tests with different access patterns as well like 
> > > constant indices, base + offset indices, etc.
> > This is a good point and I am looking at this at the moment. Adding a few 
> > tests, reveals a couple of issues with hardcoding how a table shows up in 
> > the DAG. For example, an access with an offset reveals that the DAG is way 
> > more complicated than it needs to be. For example, for:
> > 
> > ```
> > define %externref @get_externref_from_table_with_offset(i32 %i) {
> >   %off = add nsw i32 %i, 2
> >   %p = getelementptr [0 x %externref], [0 x %externref] addrspace (1)* 
> > @externref_table, i32 0, i32 %off
> >   %ref = load %externref, %externref addrspace(1)* %p
> >   ret %externref %ref
> > }
> > ```
> > 
> > So, an access with a 2 offset from the argument index causes this dag to be 
> > generated for the access:
> > 
> > ```
> > t2: i32 = WebAssemblyISD::ARGUMENT TargetConstant:i32<0>
> >   t12: i32 = shl t2, Constant:i32<2>
> > t15: i32 = add t12, GlobalAddress:i32<[0 x %extern addrspace(10)*] 
> > addrspace(1)* @externref_table> 0
> >   t16: i32 = add t15, Constant:i32<8>
> > t10: externref,ch = load<(load (s0) from %ir.p, addrspace 1)> t0, t16, 
> > undef:i32
> > ```
> > 
> > Which looks like: `(add (add (shl arg 2) table) 8)`.
> > I need to transform this back into a table load from `(add arg 2)` which 
> > seems suboptimal. I am trying to understand if it's possible to tell LLVM 
> > not to generate these address offsets for these types of accesses. It 
> > certainly seems cleaner than to reverse the computation to find the correct 
> > index to access.
> I wonder if there is a way to tell LLVM that the width of an element in the 
> table is just 1. That looks like it would simplify this a lot, if not 
> completely.
I managed to get that sorted in the last patch - which was to add to the 
datalayout string p10:8:8 and p20:8:8



Comment at: llvm/test/CodeGen/WebAssembly/funcref-table_call.ll:25-27
+; CHECK-NEXT: i32.const   0
+; CHECK-NEXT: ref.nullfunc
+; CHECK-NEXT: table.set   __funcref_call_table

tlively wrote:
> Do you think it would be a good idea to skip setting this table slot back to 
> null? I know we discussed this before, but I don't remember what the pros and 
> cons were.
So the reason to do this was that if we leave the funcref in the slot, this 
could create hidden GC roots. Comes from this comment by @wingo : 
https://reviews.llvm.org/D95425#inline-929792


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54

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


[PATCH] D111154: [WebAssembly] Implementation of table.get/set for reftypes in LLVM IR

2021-10-14 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 379917.
pmatos added a comment.
Herald added subscribers: cfe-commits, ormris, jdoerfert, steven_wu.
Herald added a project: clang.

Simplified a lot of code that required some further fixes and de-duplication.

Most importantly, I added many more testcases to ensure different addressing 
modes are supported.
The way to tell LLVM that externref and funcref pointers should not have 
complex addressing DAGS with shift/add/muls, 
was to add that information to the DataLayout string (p10:8:8-p20:8:8). This 
forced changes in many testfiles.

This looks now ready for another round of reviewing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54

Files:
  clang/lib/Basic/Targets/WebAssembly.h
  clang/test/CodeGen/target-data.c
  lld/test/wasm/lto/Inputs/archive.ll
  lld/test/wasm/lto/Inputs/cache.ll
  lld/test/wasm/lto/Inputs/libcall-archive.ll
  lld/test/wasm/lto/Inputs/libcall-truncsfhf2.ll
  lld/test/wasm/lto/Inputs/save-temps.ll
  lld/test/wasm/lto/Inputs/thinlto.ll
  lld/test/wasm/lto/Inputs/used.ll
  lld/test/wasm/lto/archive.ll
  lld/test/wasm/lto/atomics.ll
  lld/test/wasm/lto/cache.ll
  lld/test/wasm/lto/comdat.ll
  lld/test/wasm/lto/diagnostics.ll
  lld/test/wasm/lto/export.ll
  lld/test/wasm/lto/import-attributes.ll
  lld/test/wasm/lto/internalize-basic.ll
  lld/test/wasm/lto/libcall-archive.ll
  lld/test/wasm/lto/libcall-truncsfhf2.ll
  lld/test/wasm/lto/lto-start.ll
  lld/test/wasm/lto/new-pass-manager.ll
  lld/test/wasm/lto/opt-level.ll
  lld/test/wasm/lto/parallel.ll
  lld/test/wasm/lto/relocatable-undefined.ll
  lld/test/wasm/lto/relocatable.ll
  lld/test/wasm/lto/save-temps.ll
  lld/test/wasm/lto/thinlto.ll
  lld/test/wasm/lto/tls.ll
  lld/test/wasm/lto/undef.ll
  lld/test/wasm/lto/used.ll
  lld/test/wasm/lto/verify-invalid.ll
  lld/test/wasm/lto/weak-undefined.ll
  lld/test/wasm/lto/weak.ll
  llvm/lib/Target/WebAssembly/WebAssemblyISD.def
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.h
  llvm/lib/Target/WebAssembly/WebAssemblyInstrTable.td
  llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/test/CodeGen/WebAssembly/externref-tableget.ll
  llvm/test/CodeGen/WebAssembly/externref-tableset.ll
  llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
  llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
  llvm/test/CodeGen/WebAssembly/funcref-tableset.ll

Index: llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
@@ -0,0 +1,82 @@
+; RUN: llc --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types < %s | FileCheck %s
+
+%func = type void ()
+%funcref = type %func addrspace(20)* ;; addrspace 20 is nonintegral
+
+@funcref_table = local_unnamed_addr addrspace(1) global [0 x %funcref] undef
+
+define void @set_funcref_table(%funcref %g, i32 %i) {
+; CHECK-LABEL: set_funcref_table:
+; CHECK-NEXT: .functype   set_funcref_table (funcref, i32) -> ()
+; CHECK-NEXT: local.get  1
+; CHECK-NEXT: local.get  0
+; CHECK-NEXT: table.set funcref_table
+; CHECK-NEXT: end_function
+
+;; this generates a table.set of @funcref_table
+  %p = getelementptr [0 x %funcref], [0 x %funcref] addrspace (1)* @funcref_table, i32 0, i32 %i
+  store %funcref %g, %funcref addrspace(1)* %p
+  ret void
+}
+
+define void @set_funcref_table_const(%funcref %g) {
+; CHECK-LABEL: set_funcref_table_const:
+; CHECK-NEXT:  .functype  set_funcref_table_const (funcref) -> ()
+; CHECK-NEXT:  i32.const  0
+; CHECK-NEXT:  local.get  0
+; CHECK-NEXT:  table.set  funcref_table
+; CHECK-NEXT:  end_function
+  %p = getelementptr [0 x %funcref], [0 x %funcref] addrspace (1)* @funcref_table, i32 0, i32 0
+  store %funcref %g, %funcref addrspace(1)* %p
+  ret void
+}
+
+define void @set_funcref_table_with_offset(%funcref %g, i32 %i) {
+; CHECK-LABEL: set_funcref_table_with_offset:
+; CHECK-NEXT:  .functype   set_funcref_table_with_offset (funcref, i32) -> ()
+; CHECK-NEXT:  local.get   1
+; CHECK-NEXT:  i32.const   2
+; CHECK-NEXT:  i32.add
+; CHECK-NEXT:  local.get   0
+; CHECK-NEXT:  table.set   funcref_table
+; CHECK-NEXT:  end_function
+  %off = add nsw i32 %i, 2
+  %p = getelementptr [0 x %funcref], [0 x %funcref] addrspace (1)* @funcref_table, i32 0, i32 %off
+  store %funcref %g, %funcref addrspace(1)* %p
+  ret void
+}
+
+define void @set_funcref_table_with_var_offset(%funcref %g, i32 %i, i32 %j) {
+; CHECK-LABEL: set_funcref_table_with_var_offset:
+; CHECK-NEXT:  .functype   set_funcref_table_with_var_offset (funcref, i32, i32) -> ()
+; CHECK-NEXT:  local.get   1
+; CHECK-NEXT:  local.get   2
+; CHECK-NEXT:  i32.add
+; 

[clang] 12cbc8c - [analyzer] Fix property access kind detection inside parentheses.

2021-10-14 Thread Artem Dergachev via cfe-commits

Author: Artem Dergachev
Date: 2021-10-14T21:07:19-07:00
New Revision: 12cbc8cbf071901686b36e192a6d4da19deb6ec6

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

LOG: [analyzer] Fix property access kind detection inside parentheses.

'(self.prop)' produces a surprising AST where ParenExpr
resides inside `PseudoObjectExpr.

This breaks ObjCMethodCall::getMessageKind() which in turn causes us
to perform unnecessary dynamic dispatch bifurcation when evaluating
body-farmed property accessors, which in turn causes us
to explore infeasible paths.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/CallEvent.cpp
clang/test/Analysis/ObjCProperties.m

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp 
b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
index e035db8ef35a7..9a95921b64c3b 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -1039,12 +1039,12 @@ const PseudoObjectExpr 
*ObjCMethodCall::getContainingPseudoObjectExpr() const {
 
 static const Expr *
 getSyntacticFromForPseudoObjectExpr(const PseudoObjectExpr *POE) {
-  const Expr *Syntactic = POE->getSyntacticForm();
+  const Expr *Syntactic = POE->getSyntacticForm()->IgnoreParens();
 
   // This handles the funny case of assigning to the result of a getter.
   // This can happen if the getter returns a non-const reference.
   if (const auto *BO = dyn_cast(Syntactic))
-Syntactic = BO->getLHS();
+Syntactic = BO->getLHS()->IgnoreParens();
 
   return Syntactic;
 }

diff  --git a/clang/test/Analysis/ObjCProperties.m 
b/clang/test/Analysis/ObjCProperties.m
index 1a112ec2b1289..c4d264471fd16 100644
--- a/clang/test/Analysis/ObjCProperties.m
+++ b/clang/test/Analysis/ObjCProperties.m
@@ -1,5 +1,35 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core 
-analyzer-store=region -Wno-objc-root-class %s -verify
-// expected-no-diagnostics
+// RUN: %clang_analyze_cc1 -w %s -verify \
+// RUN: -analyzer-checker=core,alpha.core,debug.ExprInspection
+
+#ifdef HEADER // A clever trick to avoid splitting up the test.
+
+@interface NSObject
+@end
+
+@interface HeaderClass : NSObject
+@property NSObject *prop;
+@end
+
+#else
+#define HEADER
+#include "ObjCProperties.m"
+
+@implementation HeaderClass
+- (void)foo {
+  if ((self.prop)) {
+  }
+
+  // This test tests that no dynamic bifurcation is performed on the property.
+  // The TRUE/FALSE dilemma correctly arises from eagerly-assume behavior
+  // inside the if-statement. The dynamic bifurcation at (self.prop) inside
+  // the if-statement was causing an UNKNOWN to show up as well due to
+  // extra parentheses being caught inside PseudoObjectExpr.
+  // This should not be UNKNOWN.
+  clang_analyzer_eval(self.prop); // expected-warning{{TRUE}}
+  // expected-warning@-1{{FALSE}}
+}
+@end
+
 
 // The point of this test cases is to exercise properties in the static
 // analyzer
@@ -19,3 +49,4 @@ - (id)initWithY:(id)Y {
   return self;
 }
 @end
+#endif



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


[PATCH] D111863: [libunwind] Add an interface for dynamic .eh_frame registration

2021-10-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I looked at the libgcc mechanism at one time. I remember that most cases just 
use `PT_GNU_EH_FRAME` and these eh_frame boundary registry functions are not 
needed.
Can ORC just use `PT_GNU_EH_FRAME`?

Clang passes `--eh-frame-hdr` to ld even in `-static` mode, unlike GCC. I 
assume ORC doesn't need to support `gcc -static` (or: requires 
`-Wl,--eh-frame-hdr`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111863

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


[PATCH] D111371: [Support][ThinLTO] Move ThinLTO caching to LLVM Support library.

2021-10-14 Thread Noah Shutty via Phabricator via cfe-commits
noajshu marked an inline comment as done.
noajshu added inline comments.



Comment at: llvm/include/llvm/Support/Caching.h:1
+//===- Caching.h - LLVM File Cache Handling Configuration 
-===//
+//

MaskRay wrote:
> There needs to be a `*- C++ -*-`.
> Can you check whether the header has 80 characters?
Thank you, nice catch @MaskRay . I just added this indicator and can confirm 
that the header has 80 characters.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111371

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


[PATCH] D111371: [Support][ThinLTO] Move ThinLTO caching to LLVM Support library.

2021-10-14 Thread Noah Shutty via Phabricator via cfe-commits
noajshu updated this revision to Diff 379912.
noajshu added a comment.

Add *- C++ -*- header indicator to Caching.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111371

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  lld/COFF/LTO.cpp
  lld/ELF/LTO.cpp
  lld/MachO/LTO.cpp
  lld/wasm/LTO.cpp
  llvm/include/llvm/LTO/Caching.h
  llvm/include/llvm/LTO/LTO.h
  llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
  llvm/include/llvm/Support/Caching.h
  llvm/lib/LTO/CMakeLists.txt
  llvm/lib/LTO/Caching.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/Caching.cpp
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -19,10 +19,10 @@
 #include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/IR/DiagnosticPrinter.h"
-#include "llvm/LTO/Caching.h"
 #include "llvm/LTO/LTO.h"
 #include "llvm/Passes/PassPlugin.h"
 #include "llvm/Remarks/HotnessThresholdParser.h"
+#include "llvm/Support/Caching.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/InitLLVM.h"
@@ -362,14 +362,13 @@
   if (HasErrors)
 return 1;
 
-  auto AddStream =
-  [&](size_t Task) -> std::unique_ptr {
+  auto AddStream = [&](size_t Task) -> std::unique_ptr {
 std::string Path = OutputFilename + "." + utostr(Task);
 
 std::error_code EC;
 auto S = std::make_unique(Path, EC, sys::fs::OF_None);
 check(EC, Path);
-return std::make_unique(std::move(S));
+return std::make_unique(std::move(S));
   };
 
   auto AddBuffer = [&](size_t Task, std::unique_ptr MB) {
@@ -378,7 +377,8 @@
 
   NativeObjectCache Cache;
   if (!CacheDir.empty())
-Cache = check(localCache(CacheDir, AddBuffer), "failed to create cache");
+Cache = check(localCache("ThinLTO", "Thin", CacheDir, AddBuffer),
+  "failed to create cache");
 
   check(Lto.run(AddStream, Cache), "LTO::run failed");
   return 0;
Index: llvm/tools/llvm-lto/llvm-lto.cpp
===
--- llvm/tools/llvm-lto/llvm-lto.cpp
+++ llvm/tools/llvm-lto/llvm-lto.cpp
@@ -1097,8 +1097,7 @@
 error("writing merged module failed.");
 }
 
-auto AddStream =
-[&](size_t Task) -> std::unique_ptr {
+auto AddStream = [&](size_t Task) -> std::unique_ptr {
   std::string PartFilename = OutputFilename;
   if (Parallelism != 1)
 PartFilename += "." + utostr(Task);
@@ -1108,7 +1107,7 @@
   std::make_unique(PartFilename, EC, sys::fs::OF_None);
   if (EC)
 error("error opening the file '" + PartFilename + "': " + EC.message());
-  return std::make_unique(std::move(S));
+  return std::make_unique(std::move(S));
 };
 
 if (!CodeGen.compileOptimized(AddStream, Parallelism))
Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -1081,12 +1081,11 @@
   size_t MaxTasks = Lto->getMaxTasks();
   std::vector, bool>> Files(MaxTasks);
 
-  auto AddStream =
-  [&](size_t Task) -> std::unique_ptr {
+  auto AddStream = [&](size_t Task) -> std::unique_ptr {
 Files[Task].second = !SaveTemps;
 int FD = getOutputFileName(Filename, /* TempOutFile */ !SaveTemps,
Files[Task].first, Task);
-return std::make_unique(
+return std::make_unique(
 std::make_unique(FD, true));
   };
 
@@ -1096,7 +1095,7 @@
 
   NativeObjectCache Cache;
   if (!options::cache_dir.empty())
-Cache = check(localCache(options::cache_dir, AddBuffer));
+Cache = check(localCache("ThinLTO", "Thin", options::cache_dir, AddBuffer));
 
   check(Lto->run(AddStream, Cache));
 
Index: llvm/lib/Support/Caching.cpp
===
--- llvm/lib/Support/Caching.cpp
+++ llvm/lib/Support/Caching.cpp
@@ -1,4 +1,4 @@
-//===-Caching.cpp - LLVM Link Time Optimizer Cache Handling ---===//
+//===-Caching.cpp - LLVM File Cache Handling --===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,11 +6,11 @@
 //
 //===--===//
 //
-// This file implements the Caching for ThinLTO.
+// This file implements the Caching used by ThinLTO.
 //
 //===--===//
 
-#include "llvm/LTO/Caching.h"
+#include "llvm/Support/Caching.h"
 #include "llvm/ADT/StringExtras.h"
 #include 

[PATCH] D111863: [libunwind] Add an interface for dynamic .eh_frame registration

2021-10-14 Thread Peter S. Housel via Phabricator via cfe-commits
housel created this revision.
housel added a reviewer: cfe-commits.
Herald added a project: libunwind.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libunwind.
housel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The libgcc runtime library provides __register_frame and __deregister_frame 
functions, which can be used by dynamic code generators to register an 
.eh_frame section, which contains one or more Call Frame Information records, 
each consisting of a Common Information Entry record followed by one or more 
Frame Description Entry records. This libunwind library also provides 
__register_frame
and __deregister_frame functions, but they are effectively aliases for 
__unw_add_dynamic_fde and __unw_remove_dynamic_fde and thus can only take a 
single FDE.

This patch adds __unw_add_dynamic_eh_frame_section and 
__unw_remove_dynamic_eh_frame_section functions which explicitly use the 
.eh_frame format. Clients such as the ORCv2 platform and runtime can check for 
these functions and use them if unwinding is being
provided by libunwind, or fall back to __register_frame and __deregister_frame 
if unwinding is provided by libgcc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111863

Files:
  libunwind/src/DwarfParser.hpp
  libunwind/src/libunwind.cpp
  libunwind/src/libunwind_ext.h


Index: libunwind/src/libunwind_ext.h
===
--- libunwind/src/libunwind_ext.h
+++ libunwind/src/libunwind_ext.h
@@ -51,6 +51,9 @@
 extern void __unw_add_dynamic_fde(unw_word_t fde);
 extern void __unw_remove_dynamic_fde(unw_word_t fde);
 
+extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start);
+extern void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start);
+
 #if defined(_LIBUNWIND_ARM_EHABI)
 extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*);
 extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context,
Index: libunwind/src/libunwind.cpp
===
--- libunwind/src/libunwind.cpp
+++ libunwind/src/libunwind.cpp
@@ -292,6 +292,35 @@
   // fde is own mh_group
   
DwarfFDECache::removeAllIn((LocalAddressSpace::pint_t)fde);
 }
+
+void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
+  // The eh_frame section start serves as the mh_group
+  unw_word_t mh_group = eh_frame_start;
+  CFI_Parser::CIE_Info cieInfo;
+  CFI_Parser::FDE_Info fdeInfo;
+  auto p = (LocalAddressSpace::pint_t)eh_frame_start;
+  while (true) {
+if (CFI_Parser::decodeFDE(
+LocalAddressSpace::sThisAddressSpace, p, , ,
+true) == NULL) {
+  
DwarfFDECache::add((LocalAddressSpace::pint_t)mh_group,
+fdeInfo.pcStart, fdeInfo.pcEnd,
+fdeInfo.fdeStart);
+  p += fdeInfo.fdeLength;
+} else if (CFI_Parser::parseCIE(
+   LocalAddressSpace::sThisAddressSpace, p, ) == NULL) 
{
+  p += cieInfo.cieLength;
+} else
+  return;
+  }
+}
+
+void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
+  // The eh_frame section start serves as the mh_group
+  DwarfFDECache::removeAllIn(
+  (LocalAddressSpace::pint_t)eh_frame_start);
+}
+
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 #endif // !defined(__USING_SJLJ_EXCEPTIONS__)
 
Index: libunwind/src/DwarfParser.hpp
===
--- libunwind/src/DwarfParser.hpp
+++ libunwind/src/DwarfParser.hpp
@@ -154,7 +154,8 @@
   uintptr_t sectionLength, pint_t fdeHint, FDE_Info 
*fdeInfo,
   CIE_Info *cieInfo);
   static const char *decodeFDE(A , pint_t fdeStart,
-   FDE_Info *fdeInfo, CIE_Info *cieInfo);
+   FDE_Info *fdeInfo, CIE_Info *cieInfo,
+   bool useCIEInfo = false);
   static bool parseFDEInstructions(A , const FDE_Info ,
const CIE_Info , pint_t upToPC,
int arch, PrologInfo *results);
@@ -165,7 +166,8 @@
 /// Parse a FDE into a CIE_Info and an FDE_Info
 template 
 const char *CFI_Parser::decodeFDE(A , pint_t fdeStart,
- FDE_Info *fdeInfo, CIE_Info *cieInfo) {
+ FDE_Info *fdeInfo, CIE_Info *cieInfo,
+ bool useCIEInfo) {
   pint_t p = fdeStart;
   pint_t cfiLength = (pint_t)addressSpace.get32(p);
   p += 4;
@@ -181,9 +183,14 @@
 return "FDE is really a CIE"; // this is a CIE not an FDE
   pint_t nextCFI = p + cfiLength;
   pint_t cieStart = p - ciePointer;
-  const char *err = parseCIE(addressSpace, cieStart, cieInfo);
-  if (err != NULL)
-return err;
+  if (useCIEInfo) {
+if 

[clang] effbf0b - PR52183: Don't emit code for a void-typed constant expression.

2021-10-14 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2021-10-14T20:55:51-07:00
New Revision: effbf0bdd039237542ac5e9afe1f23c9386010e2

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

LOG: PR52183: Don't emit code for a void-typed constant expression.

This is unnecessary in general, and wrong when the expression invokes a
consteval function.

Added: 


Modified: 
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGenCXX/cxx2a-consteval.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index d9ecf57a9ab5..ff900ed077e6 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1714,6 +1714,8 @@ llvm::Constant 
*ConstantEmitter::emitForMemory(CodeGenModule ,
 
 llvm::Constant *ConstantEmitter::tryEmitPrivate(const Expr *E,
 QualType destType) {
+  assert(!destType->isVoidType() && "can't emit a void constant");
+
   Expr::EvalResult Result;
 
   bool Success = false;

diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 866da292819f..ae9434f96529 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -419,6 +419,11 @@ class ScalarExprEmitter
   Value *VisitExpr(Expr *S);
 
   Value *VisitConstantExpr(ConstantExpr *E) {
+// A constant expression of type 'void' generates no code and produces no
+// value.
+if (E->getType()->isVoidType())
+  return nullptr;
+
 if (Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
   if (E->isGLValue())
 return CGF.Builder.CreateLoad(Address(

diff  --git a/clang/test/CodeGenCXX/cxx2a-consteval.cpp 
b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
index 7ee693ca..b10ac8fa6825 100644
--- a/clang/test/CodeGenCXX/cxx2a-consteval.cpp
+++ b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
@@ -2,7 +2,8 @@
 // RUN: %clang_cc1 -emit-llvm %s -std=c++2a -triple x86_64-unknown-linux-gnu 
-o %t.ll
 // RUN: FileCheck -check-prefix=EVAL -input-file=%t.ll %s
 // RUN: FileCheck -check-prefix=EVAL-STATIC -input-file=%t.ll %s
-// RUN: %clang_cc1 -emit-llvm %s -std=c++2a -triple x86_64-unknown-linux-gnu 
-o - | FileCheck -check-prefix=EVAL-FN %s
+// RUN: FileCheck -check-prefix=EVAL-FN -input-file=%t.ll %s
+//
 // RUN: %clang_cc1 -emit-llvm %s -Dconsteval="" -std=c++2a -triple 
x86_64-unknown-linux-gnu -o %t.ll
 // RUN: FileCheck -check-prefix=EXPR -input-file=%t.ll %s
 
@@ -243,3 +244,10 @@ consteval int test_UserConvOverload_helper_ceval(int a) { 
return a; }
 int test_UserConvOverload_ceval() {
   return test_UserConvOverload_helper_ceval(UserConv());
 }
+
+consteval void void_test() {}
+void void_call() { // EVAL-FN-LABEL: define {{.*}} @_Z9void_call
+  // EVAL-FN-NOT: call
+  void_test();
+  // EVAL-FN: {{^}}}
+}



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


[PATCH] D110215: [C++2a] [Module] Support extern C/C++ semantics

2021-10-14 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 379907.
ChuanqiXu added a comment.
Herald added a subscriber: dexonsmith.

Address the comments from @rsmith. It looks much better now.


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

https://reviews.llvm.org/D110215

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/CXX/module/module.linkage_specification/Inputs/h1.h
  clang/test/CXX/module/module.linkage_specification/Inputs/h2.h
  clang/test/CXX/module/module.linkage_specification/Inputs/h4.h
  clang/test/CXX/module/module.linkage_specification/Inputs/h5.h
  clang/test/CXX/module/module.linkage_specification/p1.cpp
  clang/test/CXX/module/module.linkage_specification/p2.cpp
  clang/test/CXX/module/module.linkage_specification/p3.cpp
  clang/test/CXX/module/module.linkage_specification/p4.cpp
  clang/test/CXX/module/module.linkage_specification/p5.cpp
  clang/test/CodeGenCXX/Inputs/module-extern-C.h
  clang/test/CodeGenCXX/module-extern-C.cpp

Index: clang/test/CodeGenCXX/module-extern-C.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/module-extern-C.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++2a -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
+
+module;
+
+#include "Inputs/module-extern-C.h"
+
+export module x;
+
+// CHECK: define dso_local void @foo()
+extern "C" void foo() {
+  return;
+}
+
+extern "C" {
+// CHECK: define dso_local void @bar()
+void bar() {
+  return;
+}
+// CHECK: define dso_local i32 @baz()
+int baz() {
+  return 3;
+}
+// CHECK: define dso_local double @double_func()
+double double_func() {
+  return 5.0;
+}
+}
Index: clang/test/CodeGenCXX/Inputs/module-extern-C.h
===
--- /dev/null
+++ clang/test/CodeGenCXX/Inputs/module-extern-C.h
@@ -0,0 +1,7 @@
+extern "C" void foo();
+extern "C" {
+void bar();
+int baz();
+double double_func();
+}
+extern "C++" class CPP;
Index: clang/test/CXX/module/module.linkage_specification/p5.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.linkage_specification/p5.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++2a %s -verify
+// expected-no-diagnostics
+module;
+
+#include "Inputs/h4.h"
+
+export module x;
+
+extern "C++" int a = 5;
Index: clang/test/CXX/module/module.linkage_specification/p4.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.linkage_specification/p4.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++2a %s -verify
+// expected-no-diagnostics
+module;
+
+#include "Inputs/h4.h"
+
+export module x;
+
+extern "C" struct C {
+  int a;
+  int b;
+  double d;
+};
Index: clang/test/CXX/module/module.linkage_specification/p3.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.linkage_specification/p3.cpp
@@ -0,0 +1,7 @@
+// This tests whether the global module would be created when the program don't declare it explicitly.
+// RUN: %clang_cc1 -std=c++2a %s -verify
+// expected-no-diagnostics
+export module x;
+
+extern "C" void foo();
+extern "C++" class CPP {};
Index: clang/test/CXX/module/module.linkage_specification/p2.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.linkage_specification/p2.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++2a %s -verify
+// expected-no-diagnostics
+module;
+
+#include "Inputs/h2.h"
+
+export module x;
+
+extern "C++" class CPP {};
Index: clang/test/CXX/module/module.linkage_specification/p1.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.linkage_specification/p1.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -std=c++2a %s -verify
+// expected-no-diagnostics
+module;
+
+#include "Inputs/h1.h"
+
+export module x;
+
+extern "C" void foo() {
+  return;
+}
+
+extern "C" {
+void bar() {
+  return;
+}
+int baz() {
+  return 3;
+}
+double double_func() {
+  return 5.0;
+}
+}
+
+extern "C++" {
+void bar_cpp() {
+  return;
+}
+int baz_cpp() {
+  return 3;
+}
+double double_func_cpp() {
+  return 5.0;
+}
+}
Index: clang/test/CXX/module/module.linkage_specification/Inputs/h5.h
===
--- /dev/null
+++ clang/test/CXX/module/module.linkage_specification/Inputs/h5.h
@@ -0,0 +1 @@
+extern "C++" int a;
Index: clang/test/CXX/module/module.linkage_specification/Inputs/h4.h
===
--- /dev/null
+++ clang/test/CXX/module/module.linkage_specification/Inputs/h4.h
@@ -0,0 +1 @@
+extern "C" struct C;
Index: clang/test/CXX/module/module.linkage_specification/Inputs/h2.h

[PATCH] D107882: BPF: Enable frontend constant folding for VLA size

2021-10-14 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@pchaigno as @efriedma suggested, we can add some transformation in BPF target 
IR passes to ignore @llvm.stacksave() and @llvm.stackrestore(). I should have a 
patch ready soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107882

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


[PATCH] D111860: [modules] Update visibility for merged ObjCProtocolDecl definitions.

2021-10-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: Bigcheese, bnbarham.
Herald added a subscriber: ributzka.
vsapsai requested review of this revision.
Herald added a project: clang.

Add a test that shows a warning is emitted when we cannot find a visible
protocol and merge definition visibility the same way we do for other
decls.

rdar://83600696


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111860

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/merge-objc-protocol-visibility.m


Index: clang/test/Modules/merge-objc-protocol-visibility.m
===
--- /dev/null
+++ clang/test/Modules/merge-objc-protocol-visibility.m
@@ -0,0 +1,76 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%t/Frameworks %t/test.m 
-Werror=objc-method-access -DHIDDEN_FIRST=1 \
+// RUN:-fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/modules.cache
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%t/Frameworks %t/test.m 
-Werror=objc-method-access -DHIDDEN_FIRST=0 \
+// RUN:-fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/modules.cache
+
+// Test a case when Objective-C protocol is imported both as hidden and as 
visible.
+
+//--- Frameworks/Foundation.framework/Headers/Foundation.h
+@interface NSObject
+@end
+
+//--- Frameworks/Foundation.framework/Modules/module.modulemap
+framework module Foundation {
+  header "Foundation.h"
+  export *
+}
+
+//--- Frameworks/Common.framework/Headers/Common.h
+#import 
+@protocol Testing;
+@interface Common : NSObject
+- (id)getProtocolObj;
+@end
+
+//--- Frameworks/Common.framework/Modules/module.modulemap
+framework module Common {
+  header "Common.h"
+  export *
+}
+
+//--- Frameworks/Regular.framework/Headers/Regular.h
+@protocol Testing
+- (void)protocolMethod;
+@end
+
+//--- Frameworks/Regular.framework/Modules/module.modulemap
+framework module Regular {
+  header "Regular.h"
+  export *
+}
+
+//--- Frameworks/RegularHider.framework/Headers/Visible.h
+// Empty, file required to create a module.
+
+//--- Frameworks/RegularHider.framework/Headers/Hidden.h
+@protocol Testing
+- (void)protocolMethod;
+@end
+
+//--- Frameworks/RegularHider.framework/Modules/module.modulemap
+framework module RegularHider {
+  header "Visible.h"
+  export *
+
+  explicit module Hidden {
+header "Hidden.h"
+export *
+  }
+}
+
+//--- test.m
+#import 
+
+#if HIDDEN_FIRST
+#import 
+#import 
+#else
+#import 
+#import 
+#endif
+
+void test(Common *obj) {
+  [[obj getProtocolObj] protocolMethod];
+}
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1243,6 +1243,13 @@
 
 void ASTDeclReader::MergeDefinitionData(ObjCProtocolDecl *D,
  struct ObjCProtocolDecl::DefinitionData &) {
+  struct ObjCProtocolDecl::DefinitionData  = D->data();
+  if (DD.Definition != NewDD.Definition) {
+Reader.MergedDeclContexts.insert(
+std::make_pair(NewDD.Definition, DD.Definition));
+Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition);
+  }
+
   // FIXME: odr checking?
 }
 


Index: clang/test/Modules/merge-objc-protocol-visibility.m
===
--- /dev/null
+++ clang/test/Modules/merge-objc-protocol-visibility.m
@@ -0,0 +1,76 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%t/Frameworks %t/test.m -Werror=objc-method-access -DHIDDEN_FIRST=1 \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%t/Frameworks %t/test.m -Werror=objc-method-access -DHIDDEN_FIRST=0 \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+
+// Test a case when Objective-C protocol is imported both as hidden and as visible.
+
+//--- Frameworks/Foundation.framework/Headers/Foundation.h
+@interface NSObject
+@end
+
+//--- Frameworks/Foundation.framework/Modules/module.modulemap
+framework module Foundation {
+  header "Foundation.h"
+  export *
+}
+
+//--- Frameworks/Common.framework/Headers/Common.h
+#import 
+@protocol Testing;
+@interface Common : NSObject
+- (id)getProtocolObj;
+@end
+
+//--- Frameworks/Common.framework/Modules/module.modulemap
+framework module Common {
+  header "Common.h"
+  export *
+}
+
+//--- Frameworks/Regular.framework/Headers/Regular.h
+@protocol Testing
+- (void)protocolMethod;
+@end
+
+//--- Frameworks/Regular.framework/Modules/module.modulemap
+framework module Regular {
+  header "Regular.h"
+  export *
+}
+
+//--- Frameworks/RegularHider.framework/Headers/Visible.h
+// Empty, file required to create a module.
+
+//--- Frameworks/RegularHider.framework/Headers/Hidden.h
+@protocol Testing
+- (void)protocolMethod;

LLVM build master will be restarted soon

2021-10-14 Thread Galina Kistanova via cfe-commits
 Hello,

LLVM build master will be restarted at 6 PM PST today.

Thanks

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


[PATCH] D84375: [git-clang-format] Add --diffstat parameter

2021-10-14 Thread Roland via Phabricator via cfe-commits
roligugus added a comment.

@MyDeveloperDay Thanks for the follow-up! I've rebased on latest main.

Out of curiosity, as I am trying to wrap my head around the llvm workflow: 
Could I `arc land ...` myself once you sign off with "ready to land" even if I 
don't have llvm commit rights? If so, please let me know and I'll do that.

Otherwise, I've set the author on my commit, but if you need to set it: `git 
commit --amend --author="Roland Fischer "`

Thanks a lot!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84375

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


[PATCH] D84375: [git-clang-format] Add --diffstat parameter

2021-10-14 Thread Roland via Phabricator via cfe-commits
roligugus updated this revision to Diff 379892.
roligugus added a comment.

[git-clang-format] Rebase D84375  on latest 
main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84375

Files:
  clang/tools/clang-format/git-clang-format


Index: clang/tools/clang-format/git-clang-format
===
--- clang/tools/clang-format/git-clang-format
+++ clang/tools/clang-format/git-clang-format
@@ -99,6 +99,8 @@
  help='default commit to use if none is specified'),
   p.add_argument('--diff', action='store_true',
  help='print a diff instead of applying the changes')
+  p.add_argument('--diffstat', action='store_true',
+ help='print a diffstat instead of applying the changes')
   p.add_argument('--extensions',
  default=config.get('clangformat.extensions',
 default_extensions),
@@ -176,6 +178,8 @@
   print('clang-format did not modify any files')
   elif opts.diff:
 print_diff(old_tree, new_tree)
+  elif opts.diffstat:
+print_diffstat(old_tree, new_tree)
   else:
 changed_files = apply_changes(old_tree, new_tree, force=opts.force,
   patch_mode=opts.patch)
@@ -506,6 +510,17 @@
   subprocess.check_call(['git', 'diff', '--diff-filter=M', old_tree, new_tree,
  '--'])
 
+def print_diffstat(old_tree, new_tree):
+  """Print the diffstat between the two trees to stdout."""
+  # We use the porcelain 'diff' and not plumbing 'diff-tree' because the output
+  # is expected to be viewed by the user, and only the former does nice things
+  # like color and pagination.
+  #
+  # We also only print modified files since `new_tree` only contains the files
+  # that were modified, so unmodified files would show as deleted without the
+  # filter.
+  subprocess.check_call(['git', 'diff', '--diff-filter=M', '--stat', old_tree, 
new_tree,
+ '--'])
 
 def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
   """Apply the changes in `new_tree` to the working directory.


Index: clang/tools/clang-format/git-clang-format
===
--- clang/tools/clang-format/git-clang-format
+++ clang/tools/clang-format/git-clang-format
@@ -99,6 +99,8 @@
  help='default commit to use if none is specified'),
   p.add_argument('--diff', action='store_true',
  help='print a diff instead of applying the changes')
+  p.add_argument('--diffstat', action='store_true',
+ help='print a diffstat instead of applying the changes')
   p.add_argument('--extensions',
  default=config.get('clangformat.extensions',
 default_extensions),
@@ -176,6 +178,8 @@
   print('clang-format did not modify any files')
   elif opts.diff:
 print_diff(old_tree, new_tree)
+  elif opts.diffstat:
+print_diffstat(old_tree, new_tree)
   else:
 changed_files = apply_changes(old_tree, new_tree, force=opts.force,
   patch_mode=opts.patch)
@@ -506,6 +510,17 @@
   subprocess.check_call(['git', 'diff', '--diff-filter=M', old_tree, new_tree,
  '--'])
 
+def print_diffstat(old_tree, new_tree):
+  """Print the diffstat between the two trees to stdout."""
+  # We use the porcelain 'diff' and not plumbing 'diff-tree' because the output
+  # is expected to be viewed by the user, and only the former does nice things
+  # like color and pagination.
+  #
+  # We also only print modified files since `new_tree` only contains the files
+  # that were modified, so unmodified files would show as deleted without the
+  # filter.
+  subprocess.check_call(['git', 'diff', '--diff-filter=M', '--stat', old_tree, new_tree,
+ '--'])
 
 def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
   """Apply the changes in `new_tree` to the working directory.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111778: [WIP][X86] Update CPU_SPECIFIC list.

2021-10-14 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D111778#3064555 , @erichkeane 
wrote:

> In D111778#3064439 , @craig.topper 
> wrote:
>
>> In D111778#3064287 , @FreddyYe 
>> wrote:
>>
>>> In D111778#3063891 , @erichkeane 
>>> wrote:
>>>
 Supporting these types requires changes to the library so that we can 
 check these, right?  Do you have the library changes for these as well?  
 The constants used to check for these features/etc needs to be present in 
 the glibc library.
>>>
>>> Yes. It's highly related to the `ProcessorFeatures` I mentioned above. Does 
>>> the `library changes` refer to the compiler-rt/cpu_model.c? I think that 
>>> change depends on libgcc. For now libgcc has no strong will to update that 
>>> table.
>>
>> Every feature gcc knows about should be in libgcc. The unfortunate problem 
>> now is that cpu_features2 in libgcc is an array thats size may be different 
>> with every version of gcc. Clang can’t know how big that array is without 
>> reading the libgcc.a symbol table at compile time. Without knowing the size 
>> we can’t access any bits past the first 32 bits of cpu_features2.
>
> libgcc entries are the ones I was concerned about.  We need to make sure this 
> list matches that one (and we don't generate checks that it does not have).  
> @craig.topper can better clarify what needs to happen with the library 
> lookup, but I THINK we keep a version of this in compiler-rt instead of using 
> libgcc?

I don't know what needs to be done for the library lookup. I'm not sure if the 
compiler knows whether we are linking with compiler-rt or libgcc. That 
information is on the linker command line not necessarily the compiler command 
line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111778

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


[PATCH] D109128: [VFS] Use original path when falling back to external FS

2021-10-14 Thread Keith Smiley via Phabricator via cfe-commits
keith updated this revision to Diff 379882.
keith added a comment.

Fix format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109128

Files:
  clang/test/VFS/relative-path-errors.c
  llvm/include/llvm/Support/VirtualFileSystem.h
  llvm/lib/Support/VirtualFileSystem.cpp
  llvm/unittests/Support/VirtualFileSystemTest.cpp

Index: llvm/unittests/Support/VirtualFileSystemTest.cpp
===
--- llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -1627,6 +1627,114 @@
   EXPECT_EQ(0, NumDiagnostics);
 }
 
+TEST_F(VFSFromYAMLTest, ReturnsRequestedPathVFSMiss) {
+  IntrusiveRefCntPtr BaseFS(
+  new vfs::InMemoryFileSystem);
+  BaseFS->addFile("//root/foo/a", 0,
+  MemoryBuffer::getMemBuffer("contents of a"));
+  ASSERT_FALSE(BaseFS->setCurrentWorkingDirectory("//root/foo"));
+  auto RemappedFS = vfs::RedirectingFileSystem::create(
+  {}, /*UseExternalNames=*/false, *BaseFS);
+
+  auto OpenedF = RemappedFS->openFileForRead("a");
+  ASSERT_FALSE(OpenedF.getError());
+  llvm::ErrorOr Name = (*OpenedF)->getName();
+  ASSERT_FALSE(Name.getError());
+  EXPECT_EQ("a", Name.get());
+
+  auto OpenedS = (*OpenedF)->status();
+  ASSERT_FALSE(OpenedS.getError());
+  EXPECT_EQ("a", OpenedS->getName());
+  EXPECT_FALSE(OpenedS->IsVFSMapped);
+
+  auto DirectS = RemappedFS->status("a");
+  ASSERT_FALSE(DirectS.getError());
+  EXPECT_EQ("a", DirectS->getName());
+  EXPECT_FALSE(DirectS->IsVFSMapped);
+
+  EXPECT_EQ(0, NumDiagnostics);
+}
+
+TEST_F(VFSFromYAMLTest, ReturnsExternalPathVFSHit) {
+  IntrusiveRefCntPtr BaseFS(
+  new vfs::InMemoryFileSystem);
+  BaseFS->addFile("//root/foo/realname", 0,
+  MemoryBuffer::getMemBuffer("contents of a"));
+  auto FS =
+  getFromYAMLString("{ 'use-external-names': true,\n"
+"  'roots': [\n"
+"{\n"
+"  'type': 'directory',\n"
+"  'name': '//root/foo',\n"
+"  'contents': [ {\n"
+"  'type': 'file',\n"
+"  'name': 'vfsname',\n"
+"  'external-contents': 'realname'\n"
+"}\n"
+"  ]\n"
+"}]}",
+BaseFS);
+  ASSERT_FALSE(FS->setCurrentWorkingDirectory("//root/foo"));
+
+  auto OpenedF = FS->openFileForRead("vfsname");
+  ASSERT_FALSE(OpenedF.getError());
+  llvm::ErrorOr Name = (*OpenedF)->getName();
+  ASSERT_FALSE(Name.getError());
+  EXPECT_EQ("realname", Name.get());
+
+  auto OpenedS = (*OpenedF)->status();
+  ASSERT_FALSE(OpenedS.getError());
+  EXPECT_EQ("realname", OpenedS->getName());
+  EXPECT_TRUE(OpenedS->IsVFSMapped);
+
+  auto DirectS = FS->status("vfsname");
+  ASSERT_FALSE(DirectS.getError());
+  EXPECT_EQ("realname", DirectS->getName());
+  EXPECT_TRUE(DirectS->IsVFSMapped);
+
+  EXPECT_EQ(0, NumDiagnostics);
+}
+
+TEST_F(VFSFromYAMLTest, ReturnsInternalPathVFSHit) {
+  IntrusiveRefCntPtr BaseFS(
+  new vfs::InMemoryFileSystem);
+  BaseFS->addFile("//root/foo/realname", 0,
+  MemoryBuffer::getMemBuffer("contents of a"));
+  auto FS =
+  getFromYAMLString("{ 'use-external-names': false,\n"
+"  'roots': [\n"
+"{\n"
+"  'type': 'directory',\n"
+"  'name': '//root/foo',\n"
+"  'contents': [ {\n"
+"  'type': 'file',\n"
+"  'name': 'vfsname',\n"
+"  'external-contents': 'realname'\n"
+"}\n"
+"  ]\n"
+"}]}",
+BaseFS);
+  ASSERT_FALSE(FS->setCurrentWorkingDirectory("//root/foo"));
+
+  auto OpenedF = FS->openFileForRead("vfsname");
+  ASSERT_FALSE(OpenedF.getError());
+  llvm::ErrorOr Name = (*OpenedF)->getName();
+  ASSERT_FALSE(Name.getError());
+  EXPECT_EQ("vfsname", Name.get());
+
+  auto OpenedS = (*OpenedF)->status();
+  ASSERT_FALSE(OpenedS.getError());
+  EXPECT_EQ("vfsname", OpenedS->getName());
+  EXPECT_TRUE(OpenedS->IsVFSMapped);
+
+  auto DirectS = FS->status("vfsname");
+  ASSERT_FALSE(DirectS.getError());
+  EXPECT_EQ("vfsname", DirectS->getName());
+  EXPECT_TRUE(DirectS->IsVFSMapped);
+
+  EXPECT_EQ(0, NumDiagnostics);
+}
+
 TEST_F(VFSFromYAMLTest, CaseInsensitive) {
   IntrusiveRefCntPtr Lower(new DummyFileSystem());
   Lower->addRegularFile("//root/foo/bar/a");
Index: llvm/lib/Support/VirtualFileSystem.cpp
===
--- 

[PATCH] D109128: [VFS] Use original path when falling back to external FS

2021-10-14 Thread Keith Smiley via Phabricator via cfe-commits
keith updated this revision to Diff 379881.
keith marked an inline comment as done.
keith added a comment.

Extract fallback status logic to another function


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109128

Files:
  clang/test/VFS/relative-path-errors.c
  llvm/include/llvm/Support/VirtualFileSystem.h
  llvm/lib/Support/VirtualFileSystem.cpp
  llvm/unittests/Support/VirtualFileSystemTest.cpp

Index: llvm/unittests/Support/VirtualFileSystemTest.cpp
===
--- llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -1627,6 +1627,114 @@
   EXPECT_EQ(0, NumDiagnostics);
 }
 
+TEST_F(VFSFromYAMLTest, ReturnsRequestedPathVFSMiss) {
+  IntrusiveRefCntPtr BaseFS(
+  new vfs::InMemoryFileSystem);
+  BaseFS->addFile("//root/foo/a", 0,
+  MemoryBuffer::getMemBuffer("contents of a"));
+  ASSERT_FALSE(BaseFS->setCurrentWorkingDirectory("//root/foo"));
+  auto RemappedFS = vfs::RedirectingFileSystem::create(
+  {}, /*UseExternalNames=*/false, *BaseFS);
+
+  auto OpenedF = RemappedFS->openFileForRead("a");
+  ASSERT_FALSE(OpenedF.getError());
+  llvm::ErrorOr Name = (*OpenedF)->getName();
+  ASSERT_FALSE(Name.getError());
+  EXPECT_EQ("a", Name.get());
+
+  auto OpenedS = (*OpenedF)->status();
+  ASSERT_FALSE(OpenedS.getError());
+  EXPECT_EQ("a", OpenedS->getName());
+  EXPECT_FALSE(OpenedS->IsVFSMapped);
+
+  auto DirectS = RemappedFS->status("a");
+  ASSERT_FALSE(DirectS.getError());
+  EXPECT_EQ("a", DirectS->getName());
+  EXPECT_FALSE(DirectS->IsVFSMapped);
+
+  EXPECT_EQ(0, NumDiagnostics);
+}
+
+TEST_F(VFSFromYAMLTest, ReturnsExternalPathVFSHit) {
+  IntrusiveRefCntPtr BaseFS(
+  new vfs::InMemoryFileSystem);
+  BaseFS->addFile("//root/foo/realname", 0,
+  MemoryBuffer::getMemBuffer("contents of a"));
+  auto FS =
+  getFromYAMLString("{ 'use-external-names': true,\n"
+"  'roots': [\n"
+"{\n"
+"  'type': 'directory',\n"
+"  'name': '//root/foo',\n"
+"  'contents': [ {\n"
+"  'type': 'file',\n"
+"  'name': 'vfsname',\n"
+"  'external-contents': 'realname'\n"
+"}\n"
+"  ]\n"
+"}]}",
+BaseFS);
+  ASSERT_FALSE(FS->setCurrentWorkingDirectory("//root/foo"));
+
+  auto OpenedF = FS->openFileForRead("vfsname");
+  ASSERT_FALSE(OpenedF.getError());
+  llvm::ErrorOr Name = (*OpenedF)->getName();
+  ASSERT_FALSE(Name.getError());
+  EXPECT_EQ("realname", Name.get());
+
+  auto OpenedS = (*OpenedF)->status();
+  ASSERT_FALSE(OpenedS.getError());
+  EXPECT_EQ("realname", OpenedS->getName());
+  EXPECT_TRUE(OpenedS->IsVFSMapped);
+
+  auto DirectS = FS->status("vfsname");
+  ASSERT_FALSE(DirectS.getError());
+  EXPECT_EQ("realname", DirectS->getName());
+  EXPECT_TRUE(DirectS->IsVFSMapped);
+
+  EXPECT_EQ(0, NumDiagnostics);
+}
+
+TEST_F(VFSFromYAMLTest, ReturnsInternalPathVFSHit) {
+  IntrusiveRefCntPtr BaseFS(
+  new vfs::InMemoryFileSystem);
+  BaseFS->addFile("//root/foo/realname", 0,
+  MemoryBuffer::getMemBuffer("contents of a"));
+  auto FS =
+  getFromYAMLString("{ 'use-external-names': false,\n"
+"  'roots': [\n"
+"{\n"
+"  'type': 'directory',\n"
+"  'name': '//root/foo',\n"
+"  'contents': [ {\n"
+"  'type': 'file',\n"
+"  'name': 'vfsname',\n"
+"  'external-contents': 'realname'\n"
+"}\n"
+"  ]\n"
+"}]}",
+BaseFS);
+  ASSERT_FALSE(FS->setCurrentWorkingDirectory("//root/foo"));
+
+  auto OpenedF = FS->openFileForRead("vfsname");
+  ASSERT_FALSE(OpenedF.getError());
+  llvm::ErrorOr Name = (*OpenedF)->getName();
+  ASSERT_FALSE(Name.getError());
+  EXPECT_EQ("vfsname", Name.get());
+
+  auto OpenedS = (*OpenedF)->status();
+  ASSERT_FALSE(OpenedS.getError());
+  EXPECT_EQ("vfsname", OpenedS->getName());
+  EXPECT_TRUE(OpenedS->IsVFSMapped);
+
+  auto DirectS = FS->status("vfsname");
+  ASSERT_FALSE(DirectS.getError());
+  EXPECT_EQ("vfsname", DirectS->getName());
+  EXPECT_TRUE(DirectS->IsVFSMapped);
+
+  EXPECT_EQ(0, NumDiagnostics);
+}
+
 TEST_F(VFSFromYAMLTest, CaseInsensitive) {
   IntrusiveRefCntPtr Lower(new DummyFileSystem());
   Lower->addRegularFile("//root/foo/bar/a");
Index: llvm/lib/Support/VirtualFileSystem.cpp

[PATCH] D109128: [VFS] Use original path when falling back to external FS

2021-10-14 Thread Keith Smiley via Phabricator via cfe-commits
keith added inline comments.



Comment at: llvm/lib/Support/VirtualFileSystem.cpp:1179-1180
 
+  if (ExternalFS)
+ExternalFS->setCurrentWorkingDirectory(Path);
+

JDevlieghere wrote:
> I'm pretty sure there was a reason we stopped doing this. There should be 
> some discussion about that in my original patch. 
So it sounds like it was related to this:

> [fallthrough] ... but not for relative paths that would get resolved 
> incorrectly at the lower layer (for example, in case of the RealFileSystem, 
> because the strictly virtual path does not exist).

But if I remove that 2 of my new tests `ReturnsInternalPathVFSHit` and 
`ReturnsExternalPathVFSHit` do not pass. I think the behavior of them is what 
we want, what do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109128

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


[PATCH] D111853: [NFC][Interpreter] Remove unused CompilerInvocation

2021-10-14 Thread Roland via Phabricator via cfe-commits
roligugus created this revision.
roligugus requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111853

Files:
  clang/lib/Interpreter/Interpreter.cpp


Index: clang/lib/Interpreter/Interpreter.cpp
===
--- clang/lib/Interpreter/Interpreter.cpp
+++ clang/lib/Interpreter/Interpreter.cpp
@@ -144,7 +144,6 @@
   // driver to construct.
   ClangArgv.push_back("<<< inputs >>>");
 
-  CompilerInvocation Invocation;
   // Buffer diagnostics from argument parsing so that we can output them using 
a
   // well formed diagnostic object.
   IntrusiveRefCntPtr DiagID(new DiagnosticIDs());


Index: clang/lib/Interpreter/Interpreter.cpp
===
--- clang/lib/Interpreter/Interpreter.cpp
+++ clang/lib/Interpreter/Interpreter.cpp
@@ -144,7 +144,6 @@
   // driver to construct.
   ClangArgv.push_back("<<< inputs >>>");
 
-  CompilerInvocation Invocation;
   // Buffer diagnostics from argument parsing so that we can output them using a
   // well formed diagnostic object.
   IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111371: [Support][ThinLTO] Move ThinLTO caching to LLVM Support library.

2021-10-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.



Comment at: llvm/include/llvm/Support/Caching.h:1
+//===- Caching.h - LLVM File Cache Handling Configuration 
-===//
+//

There needs to be a `*- C++ -*-`.
Can you check whether the header has 80 characters?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111371

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


[PATCH] D111471: [NVPTX] Add a late SROA pass which allows optimizing away more allocas.

2021-10-14 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 379872.
tra edited the summary of this revision.
tra added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Added a test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111471

Files:
  clang/test/CodeGenCUDA/b52037.ll
  llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp

Index: llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
===
--- llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -328,6 +328,7 @@
 addEarlyCSEOrGVNPass();
 if (!DisableLoadStoreVectorizer)
   addPass(createLoadStoreVectorizerPass());
+addPass(createSROAPass());
   }
 }
 
Index: clang/test/CodeGenCUDA/b52037.ll
===
--- /dev/null
+++ clang/test/CodeGenCUDA/b52037.ll
@@ -0,0 +1,259 @@
+; Reproducer for a bad performance regression triggered by switch to the new PM.
+; `barney` ended up with the local variables not being optimized away and that
+; had rather dramatic effect on some GPU code. See
+; https://bugs.llvm.org/show_bug.cgi?id=52037 for the gory details.
+;
+; Even though the fix for it is in LLVM, the issue is hard to reproduce with
+; opt+llc. The pipeline created by LLVM tools is somewhat different compared to
+; the one created by clang and that's enough to affect the reproducer.
+;
+; RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -aux-triple x86_64-pc-linux-gnu -S -aux-target-cpu x86-64 \
+; RUN:  -fcuda-is-device -target-cpu sm_70 -Wno-override-module -O3 -x ir %s -flegacy-pass-manager -o - \
+; RUN: | FileCheck  %s
+; RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -aux-triple x86_64-pc-linux-gnu -S -aux-target-cpu x86-64 \
+; RUN:  -fcuda-is-device -target-cpu sm_70 -Wno-override-module -O3 -x ir %s -o - \
+; RUN: | FileCheck  %s
+
+; CHECK-LABEL: .visible .entry barney(
+; CHECK-NOT:  .local{{.*}}__local_depot
+; CHECK: ret;
+
+source_filename = "reduced.1.ll"
+
+%char3 = type { i8, i8, i8 }
+%float4 = type { float, float, float, float }
+%float3 = type { float, float, float }
+%int3 = type { i32, i32, i32 }
+%struct.w = type { i32 (...)**, [8 x i8], i32, [12 x i8] }
+%struct.blam = type <{ i32*, i16*, %float4, %int3, i32, %float3, [4 x i8], i64, i32, i8, [3 x i8], i32, [12 x i8] }>
+%struct.spam.2 = type { %struct.foo.3, i16*, float, float, i32, float }
+%struct.foo.3 = type <{ %float4*, %float4*, %float4*, i32*, i32*, i32, i32, float }>
+%struct.zot = type { %struct.bar, [8 x i8], %struct.foo, [12 x i8] }
+%struct.bar = type { i32 (...)** }
+%struct.foo = type <{ i16*, %float4, %int3, i32, %float3, [4 x i8], i64, i32, i8, [3 x i8], i32 }>
+
+@global = external addrspace(4) externally_initialized global [27 x %char3], align 1
+@global.1 = linkonce_odr unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* inttoptr (i64 16 to i8*), i8* null, i8* null] }, align 8
+
+; Function Attrs: argmemonly nofree nounwind willreturn
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) #0
+
+declare %float4 @snork(float)
+
+declare %float3 @bar.2(float, float)
+
+declare %float3 @zot()
+
+declare %int3 @hoge(i32, i32, i32)
+
+define internal i1 @pluto(%struct.w* %arg) {
+bb:
+  %tmp = call i64 @foo()
+  %tmp1 = bitcast %struct.w* %arg to i8**
+  %tmp2 = load i8*, i8** %tmp1, align 8, !tbaa !1
+  %tmp3 = getelementptr i8, i8* %tmp2, i64 -24
+  %tmp4 = bitcast i8* %tmp3 to i64*
+  %tmp5 = load i64, i64* %tmp4, align 8
+  %tmp6 = bitcast %struct.w* %arg to i8*
+  %tmp7 = getelementptr inbounds i8, i8* %tmp6, i64 %tmp5
+  %tmp8 = bitcast i8* %tmp7 to %struct.blam*
+  %tmp9 = getelementptr inbounds %struct.blam, %struct.blam* %tmp8, i32 undef, i32 7
+  %tmp10 = load i64, i64* %tmp9, align 16
+  %tmp11 = add i64 %tmp10, %tmp
+  store i64 %tmp11, i64* %tmp9, align 16, !tbaa !4
+  %tmp12 = bitcast %struct.w* %arg to i8**
+  %tmp13 = load i8*, i8** %tmp12, align 8, !tbaa !1
+  %tmp14 = getelementptr i8, i8* %tmp13, i64 -24
+  %tmp15 = bitcast i8* %tmp14 to i64*
+  %tmp16 = load i64, i64* %tmp15, align 8
+  %tmp17 = bitcast %struct.w* %arg to i8*
+  %tmp18 = getelementptr inbounds i8, i8* %tmp17, i64 %tmp16
+  %tmp19 = bitcast i8* %tmp18 to %struct.blam*
+  %tmp20 = getelementptr inbounds %struct.blam, %struct.blam* %tmp19, i32 undef, i32 1
+  %tmp21 = load i16*, i16** %tmp20, align 8
+  %tmp22 = bitcast %struct.w* %arg to i8**
+  %tmp23 = load i8*, i8** %tmp22, align 8
+  %tmp24 = getelementptr i8, i8* %tmp23, i64 -24
+  %tmp25 = bitcast i8* %tmp24 to i64*
+  %tmp26 = load i64, i64* %tmp25, align 8
+  %tmp27 = bitcast %struct.w* %arg to i8*
+  %tmp28 = getelementptr inbounds i8, i8* %tmp27, i64 %tmp26
+  %tmp29 = bitcast i8* %tmp28 to %struct.blam*
+  %tmp30 = getelementptr inbounds %struct.blam, %struct.blam* %tmp29, 

[PATCH] D58751: Order File Instrumentation: add clang support for -forder-file-instrumentation

2021-10-14 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.
Herald added a subscriber: dang.

In D58751#1417467 , @manmanren wrote:

> r355333

Hello, thanks for this nice feature. Are there any docs on how to use it?


Repository:
  rC Clang

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

https://reviews.llvm.org/D58751

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


[PATCH] D111270: [clang] Pass -clear-ast-before-backend in Clang::ConstructJob()

2021-10-14 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 379866.
aeubanks added a comment.

force off for the clang interpreter
I thought I ran check-clang, apparently I didn't


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111270

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Interpreter/Interpreter.cpp


Index: clang/lib/Interpreter/Interpreter.cpp
===
--- clang/lib/Interpreter/Interpreter.cpp
+++ clang/lib/Interpreter/Interpreter.cpp
@@ -113,6 +113,10 @@
 
   Clang->getTarget().adjust(Clang->getDiagnostics(), Clang->getLangOpts());
 
+  // Don't clear the AST before backend codegen since we do codegen multiple
+  // times, reusing the same AST.
+  Clang->getCodeGenOpts().ClearASTBeforeBackend = false;
+
   return std::move(Clang);
 }
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4660,6 +4660,7 @@
   // cleanup.
   if (!C.isForDiagnostics())
 CmdArgs.push_back("-disable-free");
+  CmdArgs.push_back("-clear-ast-before-backend");
 
 #ifdef NDEBUG
   const bool IsAssertBuild = false;


Index: clang/lib/Interpreter/Interpreter.cpp
===
--- clang/lib/Interpreter/Interpreter.cpp
+++ clang/lib/Interpreter/Interpreter.cpp
@@ -113,6 +113,10 @@
 
   Clang->getTarget().adjust(Clang->getDiagnostics(), Clang->getLangOpts());
 
+  // Don't clear the AST before backend codegen since we do codegen multiple
+  // times, reusing the same AST.
+  Clang->getCodeGenOpts().ClearASTBeforeBackend = false;
+
   return std::move(Clang);
 }
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4660,6 +4660,7 @@
   // cleanup.
   if (!C.isForDiagnostics())
 CmdArgs.push_back("-disable-free");
+  CmdArgs.push_back("-clear-ast-before-backend");
 
 #ifdef NDEBUG
   const bool IsAssertBuild = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111078: [AIX] Enable int128 in 64 bit mode

2021-10-14 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D111078#3063245 , @lkail wrote:

> This LGTM as the start point to support int128 on AIX. We might need more 
> patches involving libraries in the LLVM monorepo, we can do that 
> progressively.

Agreed (although I find it slightly odd that the testing doesn't check the edge 
case where the argument value is split between r10 and the stack).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111078

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


[clang] 675ed4c - [NFC][Interpreter] Remove unused CompilerInvocation

2021-10-14 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2021-10-14T15:17:49-07:00
New Revision: 675ed4c82df6bb53536270d900843a985ef9036e

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

LOG: [NFC][Interpreter] Remove unused CompilerInvocation

Added: 


Modified: 
clang/lib/Interpreter/Interpreter.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 28c6c4f4e80f8..02b3025297b67 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -144,7 +144,6 @@ IncrementalCompilerBuilder::create(std::vector ) {
   // driver to construct.
   ClangArgv.push_back("<<< inputs >>>");
 
-  CompilerInvocation Invocation;
   // Buffer diagnostics from argument parsing so that we can output them using 
a
   // well formed diagnostic object.
   IntrusiveRefCntPtr DiagID(new DiagnosticIDs());



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


[PATCH] D111833: [clang] Fortify warning for scanf calls with field width too big.

2021-10-14 Thread Elliott Hughes via Phabricator via cfe-commits
enh added a comment.

"shut up and take my money!" :-)




Comment at: clang/lib/Sema/SemaChecking.cpp:662
+if (Index < FD->getNumParams()) {
+  if (const auto *POS =
+  FD->getParamDecl(Index)->getAttr())

(stray tabs?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111833

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


Re: [clang] 2bd8493 - Improve type printing of const arrays to normalize array-of-const and const-array

2021-10-14 Thread David Blaikie via cfe-commits
On Tue, Oct 12, 2021 at 7:35 PM David Blaikie  wrote:

> On Mon, Oct 11, 2021 at 2:46 PM Richard Smith 
> wrote:
>
>> On Wed, 15 Sept 2021 at 13:52, David Blaikie  wrote:
>>
>>> On Tue, Sep 14, 2021 at 10:04 AM Richard Smith 
>>> wrote:
>>>
 On Mon, 13 Sept 2021 at 19:24, David Blaikie via cfe-commits <
 cfe-commits@lists.llvm.org> wrote:

>
> Author: David Blaikie
> Date: 2021-09-13T19:17:05-07:00
> New Revision: 2bd84938470bf2e337801faafb8a67710f46429d
>
> URL:
> https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d
> DIFF:
> https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d.diff
>
> LOG: Improve type printing of const arrays to normalize array-of-const
> and const-array
>
> Since these map to the same effective type - render them the same/in
> the
> more legible way (const x[n]).
>

 Nice!


> Added:
>
>
> Modified:
> clang/lib/AST/TypePrinter.cpp
> clang/test/ARCMT/cxx-checking.mm
> clang/test/AST/ast-dump-APValue-arithmetic.cpp
> clang/test/AST/ast-dump-APValue-array.cpp
> clang/test/CXX/basic/basic.types/p10.cpp
> clang/test/Sema/assign.c
> clang/test/Sema/typedef-retain.c
> clang/test/SemaCXX/reinterpret-cast.cpp
> clang/test/SemaCXX/static-assert-cxx17.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/lib/AST/TypePrinter.cpp
> b/clang/lib/AST/TypePrinter.cpp
> index aef1e4f3f4953..251db97c7db08 100644
> --- a/clang/lib/AST/TypePrinter.cpp
> +++ b/clang/lib/AST/TypePrinter.cpp
> @@ -200,11 +200,12 @@ bool TypePrinter::canPrefixQualifiers(const Type
> *T,
>// type expands to a simple string.
>bool CanPrefixQualifiers = false;
>NeedARCStrongQualifier = false;
> -  Type::TypeClass TC = T->getTypeClass();
> +  const Type *UnderlyingType = T;
>if (const auto *AT = dyn_cast(T))
> -TC = AT->desugar()->getTypeClass();
> +UnderlyingType = AT->desugar().getTypePtr();
>if (const auto *Subst = dyn_cast(T))
> -TC = Subst->getReplacementType()->getTypeClass();
> +UnderlyingType = Subst->getReplacementType().getTypePtr();
> +  Type::TypeClass TC = UnderlyingType->getTypeClass();
>
>switch (TC) {
>  case Type::Auto:
> @@ -243,6 +244,9 @@ bool TypePrinter::canPrefixQualifiers(const Type
> *T,
>
>  case Type::ConstantArray:
>  case Type::IncompleteArray:
> +  return canPrefixQualifiers(
> +
> cast(UnderlyingType)->getElementType().getTypePtr(),
> +  NeedARCStrongQualifier);
>  case Type::VariableArray:
>  case Type::DependentSizedArray:
>

 Can we give these two cases the same treatment?

>>>
>>> Handled the DependentSizedArray in
>>> https://github.com/llvm/llvm-project/commit/40acc0adad59ac39e9a7a02fcd93161298500c00
>>>
>>> But per the comment in that commit I wasn't able to reproduce the
>>> problem with a variable array - though we could include it in the handling
>>> on principle/for consistency, even without a test/etc. Perhaps there's a
>>> way to test/provoke the behavior you might know that I couldn't figure out?
>>>
>>> Details from the commit:
>>>
>>> The VariableArray case I couldn't figure out how to test/provoke -
>>> you
>>>
>>> can't write/form a variable array in any context other than a local
>>>
>>> variable that I know of, and in that case `const int x[n]` is the
>>>
>>> normalized form already (array-of-const) and you can't use typedefs
>>>
>>> (since you can't typedef int[n] with variable 'n') to force the
>>>
>>> const-array AST that would produce the undesirable type printing
>>> "int
>>>
>>> const [n]".
>>>
>>
>> C has a fairly surprising rule here -- you actually can define a VLA type
>> in a local typedef. For example,
>>
>> void f(int n) {
>> typedef int arr[n];
>> const arr x;
>> }
>>
>> ... is valid in C. In C++ mode, this produces:
>>
>> :3:15: error: default initialization of an object of const type
>> 'const arr' (aka 'int const[n]')
>>
>> (note, 'int const[n]' not 'const int[n]').
>>
>
> Oh, right, good to understand! Yep, fixed and tested with this:
> 39093279f2ede4af9048b89d048d7fe9182a50f8
>
> Huh, funny diagnostic experience aside here:
> https://godbolt.org/z/W46b3qc49
> void f(int i) {
> typedef int x[i];
> const x y = {};
> }
> :2:19: error: variable-sized object may not be initialized
> typedef int x[i];
>   ^
>
> With no pointer/note/etc to the 'y' variable - the typedef and variable
> could be quite far apart. The diagnostic would be hard to read/understand.
>
>
>> Oh, also - another quirk of array type printing that I'd be up for
>>> 

[PATCH] D111476: [modules] Make a module map referenced by a system map a system one too.

2021-10-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111476

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


[PATCH] D111205: [driver] Explicitly specify `-fbuild-session-timestamp` in seconds.

2021-10-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Ping. Failed tests seem to be unrelated (don't know how this change would cause 
"flangOmpReport.so: cannot open shared object file: No such file or 
directory"). If you think it would be better, can rebase and trigger new builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111205

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


[PATCH] D110357: [Analyzer] Extend ConstraintAssignor to handle remainder op

2021-10-14 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 379830.
martong added a comment.

- Fix signedness mismatch assertaion and add a test case for that


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110357

Files:
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constraint-assignor.c

Index: clang/test/Analysis/constraint-assignor.c
===
--- /dev/null
+++ clang/test/Analysis/constraint-assignor.c
@@ -0,0 +1,103 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify
+
+// expected-no-diagnostics
+
+void clang_analyzer_warnIfReached();
+
+void rem_constant_rhs_eq_zero(int x, int y) {
+  if (x % 3 != 0) // x % 3 == 0 -> x == 0
+return;
+  if (x * y == 0) // x * y != 0 -> contradiction
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)x; // keep the constraints alive.
+}
+
+void rem_symbolic_rhs_eq_zero(int x, int y, int z) {
+  if (x % z != 0) // x % z == 0 -> x == 0
+return;
+  if (x * y == 0) // x * y != 0 -> contradiction
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)x; // keep the constraints alive.
+}
+
+void rem_constant_rhs_ne_zero(int x, int y) {
+  if (x % 3 == 0) // x % 3 != 0 -> x != 0
+return;
+  if (x * y != 0) // x * y == 0
+return;
+  if (y != 1) // y == 1 -> x == 0
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)x; // keep the constraints alive.
+}
+
+void rem_symbolic_rhs_ne_zero(int x, int y, int z) {
+  if (x % z == 0) // x % z != 0 -> x != 0
+return;
+  if (x * y != 0) // x * y == 0
+return;
+  if (y != 1) // y == 1 -> x == 0
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)x; // keep the constraints alive.
+}
+
+void rem_symbolic_rhs_eq_zero_nested(int w, int x, int y, int z) {
+  if (w % x % z != 0) // w % x % z == 0 -> w % x == 0
+return;
+  if (w % x * y == 0) // w % x * y != 0 -> contradiction
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)(w * x); // keep the constraints alive.
+}
+
+void rem_constant_rhs_eq_zero_early_contradiction(int x, int y) {
+  if (x == 0) // x != 0
+return;
+  if (x % 3 != 0) // x % 3 == 0 -> x == 0 -> contradiction
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)x; // keep the constraints alive.
+}
+
+void rem_symbolic_rhs_eq_zero_early_contradiction(int x, int y, int z) {
+  if (x == 0) // x != 0
+return;
+  if (x % z != 0) // x % z == 0 -> x == 0 -> contradiction
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)x; // keep the constraints alive.
+}
+
+void rem_constant_rhs_ne_zero_early_contradiction(int x, int y) {
+  if ((x + y) != 0) // (x + y) == 0
+return;
+  if ((x + y) % 3 == 0) // (x + y) % 3 != 0 -> (x + y) != 0 -> contradiction
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)x; // keep the constraints alive.
+}
+
+void rem_symbolic_rhs_ne_zero_early_contradiction(int x, int y, int z) {
+  if ((x + y) != 0) // (x + y) == 0
+return;
+  if ((x + y) % z == 0) // (x + y) % z != 0 -> (x + y) != 0 -> contradiction
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)x; // keep the constraints alive.
+}
+
+void internal_unsigned_signed_mismatch(unsigned a) {
+  int d = a;
+  // Implicit casts are not handled, thus the analyzer models `d % 2` as
+  // `(reg_$0) % 2`
+  // However, this should not result in internal signedness mismatch error when
+  // we assign new constraints below.
+  if (d % 2 != 0)
+return;
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1610,7 +1610,35 @@
 return Assignor.assign(CoS, NewConstraint);
   }
 
+  /// Handle expressions like: a % b == 0.
+  template 
+  bool handleRemainderOp(const SymT *Sym, RangeSet Constraint) {
+if (Sym->getOpcode() != BO_Rem)
+  return true;
+const SymbolRef LHS = Sym->getLHS();
+const llvm::APSInt  =
+Builder.getBasicValueFactory().getValue(0, Sym->getType());
+const llvm::APSInt *ConcreteValue = Constraint.getConcreteValue();
+// a % b == 0 implies that a == 0.
+if (ConcreteValue && *ConcreteValue == Zero) {
+  State = RCM.assumeSymEQ(State, LHS, Zero, Zero);
+  if (!State)
+return false;
+}
+// a % b != 0 implies that a != 0.
+if (!Constraint.containsZero()) {
+  State = RCM.assumeSymNE(State, LHS, Zero, Zero);
+  if (!State)
+return false;
+}
+return true;
+  }
+
   inline bool 

[PATCH] D111767: [clang] Support -clear-ast-before-backend without -disable-free

2021-10-14 Thread Arthur Eubanks via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd0a5f61c4f6f: [clang] Support -clear-ast-before-backend 
without -disable-free (authored by aeubanks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111767

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/CodeGen/CodeGenAction.cpp

Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -351,10 +351,16 @@
 }
   }
 
-  // FIXME: Fix cleanup issues with clearing the AST when we properly free
-  // things.
-  if (CodeGenOpts.DisableFree && CodeGenOpts.ClearASTBeforeBackend)
+  if (CodeGenOpts.ClearASTBeforeBackend) {
+// Access to the AST is no longer available after this.
+// Other things that the ASTContext manages are still available, e.g.
+// the SourceManager. It'd be nice if we could separate out all the
+// things in ASTContext used after this point and null out the
+// ASTContext, but too many various parts of the ASTContext are still
+// used in various parts.
+C.cleanup();
 C.getAllocator().Reset();
+  }
 
   EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
 
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1962,6 +1962,7 @@
   // pointer because the subclass doesn't add anything that needs to
   // be deleted.
   StoredDeclsMap::DestroyAll(LastSDM.getPointer(), LastSDM.getInt());
+  LastSDM.setPointer(nullptr);
 }
 
 void StoredDeclsMap::DestroyAll(StoredDeclsMap *Map, bool Dependent) {
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -990,7 +990,7 @@
   addTranslationUnitDecl();
 }
 
-ASTContext::~ASTContext() {
+void ASTContext::cleanup() {
   // Release the DenseMaps associated with DeclContext objects.
   // FIXME: Is this the ideal solution?
   ReleaseDeclContextMaps();
@@ -998,6 +998,7 @@
   // Call all of the deallocation functions on all of their targets.
   for (auto  : Deallocations)
 (Pair.first)(Pair.second);
+  Deallocations.clear();
 
   // ASTRecordLayout objects in ASTRecordLayouts must always be destroyed
   // because they can contain DenseMaps.
@@ -1007,6 +1008,7 @@
 // Increment in loop to prevent using deallocated memory.
 if (auto *R = const_cast((I++)->second))
   R->Destroy(*this);
+  ObjCLayouts.clear();
 
   for (llvm::DenseMap::iterator
I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) {
@@ -1014,16 +1016,21 @@
 if (auto *R = const_cast((I++)->second))
   R->Destroy(*this);
   }
+  ASTRecordLayouts.clear();
 
   for (llvm::DenseMap::iterator A = DeclAttrs.begin(),
 AEnd = DeclAttrs.end();
A != AEnd; ++A)
 A->second->~AttrVec();
+  DeclAttrs.clear();
 
   for (const auto  : ModuleInitializers)
 Value.second->~PerModuleInitializers();
+  ModuleInitializers.clear();
 }
 
+ASTContext::~ASTContext() { cleanup(); }
+
 void ASTContext::setTraversalScope(const std::vector ) {
   TraversalScope = TopLevelDecls;
   getParentMapContext().clear();
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -695,6 +695,12 @@
   SourceManager& getSourceManager() { return SourceMgr; }
   const SourceManager& getSourceManager() const { return SourceMgr; }
 
+  // Cleans up some of the data structures. This allows us to do cleanup
+  // normally done in the destructor earlier. Renders much of the ASTContext
+  // unusable, mostly the actual AST nodes, so should be called when we no
+  // longer need access to the AST.
+  void cleanup();
+
   llvm::BumpPtrAllocator () const {
 return BumpAlloc;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d0a5f61 - [clang] Support -clear-ast-before-backend without -disable-free

2021-10-14 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2021-10-14T13:43:53-07:00
New Revision: d0a5f61c4f6fccec87fd5207e3fcd9502dd59854

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

LOG: [clang] Support -clear-ast-before-backend without -disable-free

Previously without -disable-free, -clear-ast-before-backend would crash in 
~ASTContext() due to various reasons.
This works around that by doing a lot of the cleanup ahead of the destructor so 
that the destructor doesn't actually do any manual cleanup if we've already 
cleaned up beforehand.

This actually does save a measurable amount of memory with 
-clear-ast-before-backend, although at an almost unnoticeable runtime cost:
https://llvm-compile-time-tracker.com/compare.php?from=5d755b32f2775b9219f6d6e2feda5e1417dc993b=58ef1c7ad7e2ad45f9c97597905a8cf05a26258c=max-rss

Previously we weren't doing any cleanup with -disable-free, so I tried 
measuring the impact of always doing the cleanup and didn't measure anything 
noticeable on llvm-compile-time-tracker.

Reviewed By: dblaikie

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/CodeGen/CodeGenAction.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index b21f9b83b9d86..b9aa2d2cfadb5 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -695,6 +695,12 @@ class ASTContext : public RefCountedBase {
   SourceManager& getSourceManager() { return SourceMgr; }
   const SourceManager& getSourceManager() const { return SourceMgr; }
 
+  // Cleans up some of the data structures. This allows us to do cleanup
+  // normally done in the destructor earlier. Renders much of the ASTContext
+  // unusable, mostly the actual AST nodes, so should be called when we no
+  // longer need access to the AST.
+  void cleanup();
+
   llvm::BumpPtrAllocator () const {
 return BumpAlloc;
   }

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a6b11465d4bcd..d9017b347d812 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -990,7 +990,7 @@ ASTContext::ASTContext(LangOptions , SourceManager 
,
   addTranslationUnitDecl();
 }
 
-ASTContext::~ASTContext() {
+void ASTContext::cleanup() {
   // Release the DenseMaps associated with DeclContext objects.
   // FIXME: Is this the ideal solution?
   ReleaseDeclContextMaps();
@@ -998,6 +998,7 @@ ASTContext::~ASTContext() {
   // Call all of the deallocation functions on all of their targets.
   for (auto  : Deallocations)
 (Pair.first)(Pair.second);
+  Deallocations.clear();
 
   // ASTRecordLayout objects in ASTRecordLayouts must always be destroyed
   // because they can contain DenseMaps.
@@ -1007,6 +1008,7 @@ ASTContext::~ASTContext() {
 // Increment in loop to prevent using deallocated memory.
 if (auto *R = const_cast((I++)->second))
   R->Destroy(*this);
+  ObjCLayouts.clear();
 
   for (llvm::DenseMap::iterator
I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) {
@@ -1014,16 +1016,21 @@ ASTContext::~ASTContext() {
 if (auto *R = const_cast((I++)->second))
   R->Destroy(*this);
   }
+  ASTRecordLayouts.clear();
 
   for (llvm::DenseMap::iterator A = DeclAttrs.begin(),
 AEnd = DeclAttrs.end();
A != AEnd; ++A)
 A->second->~AttrVec();
+  DeclAttrs.clear();
 
   for (const auto  : ModuleInitializers)
 Value.second->~PerModuleInitializers();
+  ModuleInitializers.clear();
 }
 
+ASTContext::~ASTContext() { cleanup(); }
+
 void ASTContext::setTraversalScope(const std::vector ) {
   TraversalScope = TopLevelDecls;
   getParentMapContext().clear();

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index e042ae8dae4ae..4044404f74ef2 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1962,6 +1962,7 @@ void ASTContext::ReleaseDeclContextMaps() {
   // pointer because the subclass doesn't add anything that needs to
   // be deleted.
   StoredDeclsMap::DestroyAll(LastSDM.getPointer(), LastSDM.getInt());
+  LastSDM.setPointer(nullptr);
 }
 
 void StoredDeclsMap::DestroyAll(StoredDeclsMap *Map, bool Dependent) {

diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 4ca34db06ced4..881e30a4c8444 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -351,10 +351,16 @@ namespace clang {
 }
   }
 
-  // FIXME: Fix cleanup issues with clearing the AST when we properly free
-  // things.
-  if (CodeGenOpts.DisableFree && 

[PATCH] D111639: [Sema] check PseudoObject when rebuilding CXXOperatorCallExpr in template instantiation

2021-10-14 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

There are some invariants about what family of APIs TreeTransform methods 
should call, and I've forgotten what they are, so I'm hesitant to approve this. 
Test case looks good, though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111639

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


[PATCH] D111767: [clang] Support -clear-ast-before-backend without -disable-free

2021-10-14 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 379827.
aeubanks added a comment.

add more comments about the cleanup


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111767

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/CodeGen/CodeGenAction.cpp

Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -351,10 +351,16 @@
 }
   }
 
-  // FIXME: Fix cleanup issues with clearing the AST when we properly free
-  // things.
-  if (CodeGenOpts.DisableFree && CodeGenOpts.ClearASTBeforeBackend)
+  if (CodeGenOpts.ClearASTBeforeBackend) {
+// Access to the AST is no longer available after this.
+// Other things that the ASTContext manages are still available, e.g.
+// the SourceManager. It'd be nice if we could separate out all the
+// things in ASTContext used after this point and null out the
+// ASTContext, but too many various parts of the ASTContext are still
+// used in various parts.
+C.cleanup();
 C.getAllocator().Reset();
+  }
 
   EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
 
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1962,6 +1962,7 @@
   // pointer because the subclass doesn't add anything that needs to
   // be deleted.
   StoredDeclsMap::DestroyAll(LastSDM.getPointer(), LastSDM.getInt());
+  LastSDM.setPointer(nullptr);
 }
 
 void StoredDeclsMap::DestroyAll(StoredDeclsMap *Map, bool Dependent) {
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -990,7 +990,7 @@
   addTranslationUnitDecl();
 }
 
-ASTContext::~ASTContext() {
+void ASTContext::cleanup() {
   // Release the DenseMaps associated with DeclContext objects.
   // FIXME: Is this the ideal solution?
   ReleaseDeclContextMaps();
@@ -998,6 +998,7 @@
   // Call all of the deallocation functions on all of their targets.
   for (auto  : Deallocations)
 (Pair.first)(Pair.second);
+  Deallocations.clear();
 
   // ASTRecordLayout objects in ASTRecordLayouts must always be destroyed
   // because they can contain DenseMaps.
@@ -1007,6 +1008,7 @@
 // Increment in loop to prevent using deallocated memory.
 if (auto *R = const_cast((I++)->second))
   R->Destroy(*this);
+  ObjCLayouts.clear();
 
   for (llvm::DenseMap::iterator
I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) {
@@ -1014,16 +1016,21 @@
 if (auto *R = const_cast((I++)->second))
   R->Destroy(*this);
   }
+  ASTRecordLayouts.clear();
 
   for (llvm::DenseMap::iterator A = DeclAttrs.begin(),
 AEnd = DeclAttrs.end();
A != AEnd; ++A)
 A->second->~AttrVec();
+  DeclAttrs.clear();
 
   for (const auto  : ModuleInitializers)
 Value.second->~PerModuleInitializers();
+  ModuleInitializers.clear();
 }
 
+ASTContext::~ASTContext() { cleanup(); }
+
 void ASTContext::setTraversalScope(const std::vector ) {
   TraversalScope = TopLevelDecls;
   getParentMapContext().clear();
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -695,6 +695,12 @@
   SourceManager& getSourceManager() { return SourceMgr; }
   const SourceManager& getSourceManager() const { return SourceMgr; }
 
+  // Cleans up some of the data structures. This allows us to do cleanup
+  // normally done in the destructor earlier. Renders much of the ASTContext
+  // unusable, mostly the actual AST nodes, so should be called when we no
+  // longer need access to the AST.
+  void cleanup();
+
   llvm::BumpPtrAllocator () const {
 return BumpAlloc;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111371: [Support][ThinLTO] Move ThinLTO caching to LLVM Support library.

2021-10-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111371

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


[PATCH] D111833: [clang] Fortify warning for scanf calls with field width too big.

2021-10-14 Thread Michael Benfield via Phabricator via cfe-commits
mbenfield created this revision.
mbenfield added reviewers: enh, gbiv.
Herald added a reviewer: george.burgess.iv.
mbenfield requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111833

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/warn-fortify-scanf.c

Index: clang/test/Sema/warn-fortify-scanf.c
===
--- /dev/null
+++ clang/test/Sema/warn-fortify-scanf.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify
+
+typedef struct _FILE FILE;
+extern int scanf(const char *format, ...);
+extern int fscanf(FILE *f, const char *format, ...);
+extern int sscanf(const char *input, const char *format, ...);
+
+void call_scanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  scanf("%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 4 has size 10, but the corresponding field width plus null byte is 11}}
+  scanf("%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 4 has size 10, but the corresponding field width plus null byte is 12}}
+  scanf("%4s %5s %9s", buf20, buf30, buf10);
+  scanf("%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 2 has size 20, but the corresponding field width plus null byte is 21}}
+  scanf("%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'scanf' may overflow; destination buffer in argument 2 has size 20, but the corresponding field width plus null byte is 22}}
+  scanf("%19s %5s %9s", buf20, buf30, buf10);
+  scanf("%19s %29s %9s", buf20, buf30, buf10);
+}
+
+void call_sscanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  sscanf("a b c", "%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus null byte is 11}}
+  sscanf("a b c", "%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus null byte is 12}}
+  sscanf("a b c", "%4s %5s %9s", buf20, buf30, buf10);
+  sscanf("a b c", "%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus null byte is 21}}
+  sscanf("a b c", "%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'sscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus null byte is 22}}
+  sscanf("a b c", "%19s %5s %9s", buf20, buf30, buf10);
+  sscanf("a b c", "%19s %29s %9s", buf20, buf30, buf10);
+}
+
+void call_fscanf() {
+  char buf10[10];
+  char buf20[20];
+  char buf30[30];
+  fscanf(0, "%4s %5s %10s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus null byte is 11}}
+  fscanf(0, "%4s %5s %11s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 5 has size 10, but the corresponding field width plus null byte is 12}}
+  fscanf(0, "%4s %5s %9s", buf20, buf30, buf10);
+  fscanf(0, "%20s %5s %9s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus null byte is 21}}
+  fscanf(0, "%21s %5s %9s", buf20, buf30, buf10); // expected-warning {{'fscanf' may overflow; destination buffer in argument 3 has size 20, but the corresponding field width plus null byte is 22}}
+  fscanf(0, "%19s %5s %9s", buf20, buf30, buf10);
+  fscanf(0, "%19s %29s %9s", buf20, buf30, buf10);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -408,6 +408,48 @@
 
 namespace {
 
+class ScanfDiagnosticFormatHandler
+: public analyze_format_string::FormatStringHandler {
+  // Accepts the argument index (relative to the first destination index) of the
+  // argument whose size we want.
+  using ComputeSizeFunction = std::function(unsigned)>;
+
+  // Accepts the argument index (relative to the first destination index), the
+  // destination size, and the source size).
+  using DiagnoseFunction = std::function;
+
+  ComputeSizeFunction ComputeSizeArgument;
+  DiagnoseFunction Diagnose;
+
+public:
+  ScanfDiagnosticFormatHandler(ComputeSizeFunction ComputeSizeArgument,
+   DiagnoseFunction Diagnose)
+  : ComputeSizeArgument(ComputeSizeArgument), Diagnose(Diagnose) {}
+
+  bool HandleScanfSpecifier(const 

[PATCH] D111100: enable plugins for clang-tidy

2021-10-14 Thread Jameson Nash via Phabricator via cfe-commits
vtjnash added a comment.

bump?


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] D111830: [clang] fix typo correction not looking for candidates in base classes.

2021-10-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 379810.
mizvekov added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111830

Files:
  clang/lib/Sema/SemaExprMember.cpp
  clang/test/CXX/drs/dr1xx.cpp


Index: clang/test/CXX/drs/dr1xx.cpp
===
--- clang/test/CXX/drs/dr1xx.cpp
+++ clang/test/CXX/drs/dr1xx.cpp
@@ -477,7 +477,7 @@
 
 namespace dr141 { // dr141: yes
   template void f();
-  template struct S { int n; };
+  template struct S { int n; }; // expected-note 
{{'::dr141::S::n' declared here}}
   struct A : S {
 template void f();
 template struct S {};
@@ -485,7 +485,7 @@
   struct B : S {} b;
   void g() {
 a.f();
-(void)a.S::n; // expected-error {{no member named 'n'}}
+(void)a.S::n; // expected-error {{no member named 'n' in 
'dr141::A::S'; did you mean '::dr141::S::n'?}}
 #if __cplusplus < 201103L
 // expected-error@-2 {{ambiguous}}
 // expected-note@-11 {{lookup from the current scope}}
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -611,11 +611,10 @@
 if (Record->containsDecl(ND))
   return true;
 
-if (const CXXRecordDecl *RD = dyn_cast(Record)) {
+if (const auto *RD = dyn_cast(Record)) {
   // Accept candidates that occur in any of the current class' base 
classes.
   for (const auto  : RD->bases()) {
-if (const RecordType *BSTy =
-dyn_cast_or_null(BS.getType().getTypePtrOrNull())) 
{
+if (const auto *BSTy = BS.getType()->getAs()) {
   if (BSTy->getDecl()->containsDecl(ND))
 return true;
 }


Index: clang/test/CXX/drs/dr1xx.cpp
===
--- clang/test/CXX/drs/dr1xx.cpp
+++ clang/test/CXX/drs/dr1xx.cpp
@@ -477,7 +477,7 @@
 
 namespace dr141 { // dr141: yes
   template void f();
-  template struct S { int n; };
+  template struct S { int n; }; // expected-note {{'::dr141::S::n' declared here}}
   struct A : S {
 template void f();
 template struct S {};
@@ -485,7 +485,7 @@
   struct B : S {} b;
   void g() {
 a.f();
-(void)a.S::n; // expected-error {{no member named 'n'}}
+(void)a.S::n; // expected-error {{no member named 'n' in 'dr141::A::S'; did you mean '::dr141::S::n'?}}
 #if __cplusplus < 201103L
 // expected-error@-2 {{ambiguous}}
 // expected-note@-11 {{lookup from the current scope}}
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -611,11 +611,10 @@
 if (Record->containsDecl(ND))
   return true;
 
-if (const CXXRecordDecl *RD = dyn_cast(Record)) {
+if (const auto *RD = dyn_cast(Record)) {
   // Accept candidates that occur in any of the current class' base classes.
   for (const auto  : RD->bases()) {
-if (const RecordType *BSTy =
-dyn_cast_or_null(BS.getType().getTypePtrOrNull())) {
+if (const auto *BSTy = BS.getType()->getAs()) {
   if (BSTy->getDecl()->containsDecl(ND))
 return true;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111443: [Driver] Fix ToolChain::getSanitizerArgs

2021-10-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 379806.
yaxunl edited the summary of this revision.
yaxunl added a comment.

diagnose sanitizer args only once.


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

https://reviews.llvm.org/D111443

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AIX.h
  clang/lib/Driver/ToolChains/AMDGPU.h
  clang/lib/Driver/ToolChains/BareMetal.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CloudABI.cpp
  clang/lib/Driver/ToolChains/CloudABI.h
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CrossWindows.cpp
  clang/lib/Driver/ToolChains/CrossWindows.h
  clang/lib/Driver/ToolChains/Cuda.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/FreeBSD.h
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Fuchsia.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/lib/Driver/ToolChains/Haiku.h
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  clang/lib/Driver/ToolChains/MSP430.h
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MSVC.h
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/lib/Driver/ToolChains/MinGW.h
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/lib/Driver/ToolChains/OpenBSD.h
  clang/lib/Driver/ToolChains/PS4CPU.cpp
  clang/lib/Driver/ToolChains/PS4CPU.h
  clang/lib/Driver/ToolChains/TCE.cpp
  clang/lib/Driver/ToolChains/TCE.h
  clang/lib/Driver/ToolChains/VEToolchain.cpp
  clang/lib/Driver/ToolChains/VEToolchain.h
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/lib/Driver/ToolChains/WebAssembly.h
  clang/lib/Driver/ToolChains/XCore.cpp
  clang/lib/Driver/ToolChains/XCore.h
  clang/lib/Driver/ToolChains/ZOS.h
  clang/test/Driver/hip-sanitize-options.hip

Index: clang/test/Driver/hip-sanitize-options.hip
===
--- clang/test/Driver/hip-sanitize-options.hip
+++ clang/test/Driver/hip-sanitize-options.hip
@@ -1,47 +1,67 @@
 // REQUIRES: clang-driver, x86-registered-target, amdgpu-registered-target
 
-// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900 \
+// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack+ \
 // RUN:   -fsanitize=address \
 // RUN:   -nogpuinc --rocm-path=%S/Inputs/rocm \
-// RUN:   %s 2>&1 | FileCheck %s
+// RUN:   %s 2>&1 | FileCheck -check-prefixes=NORDC %s
 
-// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900 \
+// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack+ \
 // RUN:   -fsanitize=address -fno-gpu-sanitize \
 // RUN:   -nogpuinc --rocm-path=%S/Inputs/rocm \
 // RUN:   %s 2>&1 | FileCheck %s
 
-// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900 \
+// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack+ \
 // RUN:   -fsanitize=address -fgpu-sanitize \
 // RUN:   -nogpuinc --rocm-path=%S/Inputs/rocm \
 // RUN:   %s 2>&1 | FileCheck -check-prefixes=NORDC %s
 
-// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900 \
+// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack+ \
 // RUN:   -fsanitize=address -fgpu-sanitize -fgpu-rdc \
 // RUN:   -nogpuinc --rocm-path=%S/Inputs/rocm \
 // RUN:   %s 2>&1 | FileCheck -check-prefixes=RDC %s
 
-// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900 \
+// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack+ \
 // RUN:   -fsanitize=address -fgpu-sanitize \
 // RUN:   -nogpuinc --rocm-path=%S/Inputs/rocm-invalid \
 // RUN:   %s 2>&1 | FileCheck -check-prefixes=FAIL %s
 
 // RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack- \
-// RUN:   -fsanitize=address -fgpu-sanitize \
-// RUN:   -nogpuinc --rocm-path=%S/Inputs/rocm \
-// RUN:   %s 2>&1 | FileCheck -check-prefix=XNACK %s
+// RUN:   --offload-arch=gfx900:xnack+ --offload-arch=gfx906 -fsanitize=address -fgpu-sanitize \
+// RUN:   -fsanitize=leak -nogpuinc --rocm-path=%S/Inputs/rocm \
+// RUN:   %s 2>&1 | FileCheck -check-prefixes=XNACK %s
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack- \
+// RUN:   --offload-arch=gfx900:xnack+ --offload-arch=gfx906 -fsanitize=address -fgpu-sanitize \
+// RUN:   -fsanitize=leak -nogpuinc --rocm-path=%S/Inputs/rocm \
+// RUN:   %s 2>&1 | FileCheck -check-prefixes=XNACKNEG %s
 
 // CHECK-NOT: {{"[^"]*clang[^"]*".* "-fcuda-is-device".* "-fsanitize=address"}}
+// CHECK-NOT: {{"[^"]*clang[^"]*".* "-fcuda-is-device".* "-mlink-bitcode-file" 

[PATCH] D111830: [clang] fix typo correction not looking for candidates in base classes.

2021-10-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

RecordMemberExprValidator was not looking through ElaboratedType
nodes when looking for candidates which occur in base classes.

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111830

Files:
  clang/lib/Sema/SemaExprMember.cpp
  clang/test/CXX/drs/dr1xx.cpp


Index: clang/test/CXX/drs/dr1xx.cpp
===
--- clang/test/CXX/drs/dr1xx.cpp
+++ clang/test/CXX/drs/dr1xx.cpp
@@ -477,7 +477,7 @@
 
 namespace dr141 { // dr141: yes
   template void f();
-  template struct S { int n; };
+  template struct S { int n; }; // expected-note 
{{'::dr141::S::n' declared here}}
   struct A : S {
 template void f();
 template struct S {};
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -611,11 +611,10 @@
 if (Record->containsDecl(ND))
   return true;
 
-if (const CXXRecordDecl *RD = dyn_cast(Record)) {
+if (const auto *RD = dyn_cast(Record)) {
   // Accept candidates that occur in any of the current class' base 
classes.
   for (const auto  : RD->bases()) {
-if (const RecordType *BSTy =
-dyn_cast_or_null(BS.getType().getTypePtrOrNull())) 
{
+if (const auto *BSTy = BS.getType()->getAs()) {
   if (BSTy->getDecl()->containsDecl(ND))
 return true;
 }


Index: clang/test/CXX/drs/dr1xx.cpp
===
--- clang/test/CXX/drs/dr1xx.cpp
+++ clang/test/CXX/drs/dr1xx.cpp
@@ -477,7 +477,7 @@
 
 namespace dr141 { // dr141: yes
   template void f();
-  template struct S { int n; };
+  template struct S { int n; }; // expected-note {{'::dr141::S::n' declared here}}
   struct A : S {
 template void f();
 template struct S {};
Index: clang/lib/Sema/SemaExprMember.cpp
===
--- clang/lib/Sema/SemaExprMember.cpp
+++ clang/lib/Sema/SemaExprMember.cpp
@@ -611,11 +611,10 @@
 if (Record->containsDecl(ND))
   return true;
 
-if (const CXXRecordDecl *RD = dyn_cast(Record)) {
+if (const auto *RD = dyn_cast(Record)) {
   // Accept candidates that occur in any of the current class' base classes.
   for (const auto  : RD->bases()) {
-if (const RecordType *BSTy =
-dyn_cast_or_null(BS.getType().getTypePtrOrNull())) {
+if (const auto *BSTy = BS.getType()->getAs()) {
   if (BSTy->getDecl()->containsDecl(ND))
 return true;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-14 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 379807.
yonghong-song added a comment.

- fix clang-format issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeLoc.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/TypeNodes.td
  clang/include/clang/Serialization/ASTRecordWriter.h
  clang/include/clang/Serialization/TypeBitCodes.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGen/attr-btf_type_tag-conv-var.c
  clang/test/CodeGen/attr-btf_type_tag-typedef-field.c
  clang/test/Sema/attr-btf_type_tag.c
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/DebugInfo/attr-btf_type_tag.ll

Index: llvm/test/DebugInfo/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/attr-btf_type_tag.ll
@@ -0,0 +1,62 @@
+; REQUIRES: x86-registered-target
+; RUN: llc -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   #define __tag2 __attribute__((btf_type_tag("tag2")))
+;
+;   int * __tag1 * __tag2 *g;
+; Compilation flag:
+;   clang -target x86_64 -g -S -emit-llvm t.c
+
+@g = dso_local global i32*** null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!13, !14, !15, !16, !17}
+!llvm.ident = !{!18}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !11)
+!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, annotations: !9)
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{!10}
+!10 = !{!"btf_type_tag", !"tag1"}
+!11 = !{!12}
+!12 = !{!"btf_type_tag", !"tag2"}
+
+; CHECK:  DW_TAG_variable
+; CHECK-NEXT:   DW_AT_name  ("g")
+; CHECK-NEXT:   DW_AT_type  (0x[[T1:[0-9]+]] "int ***")
+
+; CHECK:  0x[[T1]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T2:[0-9]+]] "int **")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag2")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T2]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T3:[0-9]+]] "int *")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag1")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T3]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[#]] "int")
+
+!13 = !{i32 7, !"Dwarf Version", i32 4}
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 1, !"wchar_size", i32 4}
+!16 = !{i32 7, !"uwtable", i32 1}
+!17 = !{i32 7, !"frame-pointer", i32 2}
+!18 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)"}
Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -292,12 +292,13 @@
 uint64_t SizeInBits,
 uint32_t AlignInBits,
 Optional DWARFAddressSpace,
-StringRef Name) {
+StringRef Name,
+DINodeArray Annotations) {
   // FIXME: Why is there a name here?
   return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
 nullptr, 0, nullptr, PointeeTy, SizeInBits,
 AlignInBits, 0, DWARFAddressSpace,
-DINode::FlagZero);
+DINode::FlagZero, nullptr, Annotations);
 }
 
 DIDerivedType 

[clang] 68157fe - Fix a crash on valid consteval code.

2021-10-14 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-10-14T15:48:10-04:00
New Revision: 68157fe15b238428d0fdbeb38c14afd5bda574da

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

LOG: Fix a crash on valid consteval code.

Not all constants are emitted within the context of a function, so use
the module's ASTContext instead because 1) that's the same as the
current function ASTContext, and 2) the module can never be null.

Fixes PR50787.

Added: 
clang/test/CodeGenCXX/cxx20-consteval-crash.cpp

Modified: 
clang/lib/CodeGen/CGExprConstant.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 734024149bbbe..d9ecf57a9ab52 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1369,7 +1369,7 @@ llvm::Constant 
*ConstantEmitter::tryEmitConstantExpr(const ConstantExpr *CE) {
   const Expr *Inner = CE->getSubExpr()->IgnoreImplicit();
   QualType RetType;
   if (auto *Call = dyn_cast(Inner))
-RetType = Call->getCallReturnType(CGF->getContext());
+RetType = Call->getCallReturnType(CGM.getContext());
   else if (auto *Ctor = dyn_cast(Inner))
 RetType = Ctor->getType();
   llvm::Constant *Res =

diff  --git a/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp 
b/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
new file mode 100644
index 0..ef868fa85749f
--- /dev/null
+++ b/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 %s -emit-llvm 
-o - | FileCheck %s
+
+namespace PR50787 {
+// This code would previously cause a crash.
+extern int x_;
+consteval auto& X() { return x_; }
+constexpr auto& x1 = X();
+auto x2 = X();
+
+// CHECK: @_ZN7PR507872x_E = external global i32, align 4
+// CHECK-NEXT: @_ZN7PR507872x1E = constant i32* @_ZN7PR507872x_E, align 8
+// CHECK-NEXT: @_ZN7PR507872x2E = global i32* @_ZN7PR507872x_E, align 4
+}
+



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


[PATCH] D90121: clang-format: Add a consumer to diagnostics engine

2021-10-14 Thread Kirill Dmitrenko via Phabricator via cfe-commits
dmikis added a comment.

> I took a look and in its simplest form moving TextDiagnosticPrinter.cpp to 
> lib/Basic but also requires DiagnosticRender.cpp and TextDiagnostic.cpp to 
> also move to lib/Basic too,
>
> But DiagnosticRender.cpp has a dependency on lib/Edit so clang-format now 
> needs that as a dependency, is that better/worse than having a dependency on 
> lib/FrontEnd? (not sure why I don't have to provide "Edit" as a dependency 
> when including FrontEnd!)

I did make an attempt to move those classes to lib/Basic but ultimately 
dependency tree turned out to be too complex for me to tackle (IIRC, it 
basically ended up depending upon Lexer or something similar, that wasn't 
appropriate to move to lib/Basic). Since we used heavily patched version of 
clang-format (including this patch) that problem didn't bugged us and I kinda 
moved on to other things :/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90121

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


[PATCH] D111270: [clang] Pass -clear-ast-before-backend in Clang::ConstructJob()

2021-10-14 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

In D111270#3062802 , @aeubanks wrote:

> In D111270#3060484 , @dblaikie 
> wrote:
>
>> Plan is still to address the "this only works with disable free" issue? 
>> (I've some preference that be addressed before this feature is turned on by 
>> default)
>
> https://reviews.llvm.org/D111767. Thanks for pushing back, this actually does 
> help a bit more with memory savings. I was worried that we'd be doing a bunch 
> of pointer chasing if we supported -clear-ast-before-backend without 
> -disable-free but couldn't measure any runtime regressions aside from some 
> nullifying tiny wins gained by this patch.

Great, thanks for that!

>> & is there a flag to pass to turn this off if someone had trouble with it? 
>> (doesn't necessarily have to be, but just checking)
>
> Just like `-disable-free` doesn't have a flag, I don't want one for this at 
> least for now. I'd rather just revert this change and fix any issues. If we 
> come across weird issues then we may have to add a flag.

Yep, sounds good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111270

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


[PATCH] D109128: [VFS] Use original path when falling back to external FS

2021-10-14 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added inline comments.



Comment at: llvm/lib/Support/VirtualFileSystem.cpp:1179-1180
 
+  if (ExternalFS)
+ExternalFS->setCurrentWorkingDirectory(Path);
+

I'm pretty sure there was a reason we stopped doing this. There should be some 
discussion about that in my original patch. 



Comment at: llvm/lib/Support/VirtualFileSystem.cpp:2012
+  if (auto Result = ExternalFS->status(CanonicalPath)) {
+return Result.get().copyWithNewName(Result.get(), OriginalPath);
+  } else {

Can we abstract this in a function similar to `getRedirectedFileStatus`, 
something like `getOrginialFileStatus` or `getNonCanonicalizedFileStatus` and 
have a comment explaining what it does and why? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109128

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


[PATCH] D111793: [Driver][Darwin] Use T reference instead of getToolChain().getTriple().

2021-10-14 Thread Frederic Cambus via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8ecbcd058fbd: [Driver][Darwin] Use T reference instead of 
getToolChain().getTriple(). (authored by fcambus).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111793

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp


Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -94,6 +94,8 @@
  const InputInfoList ,
  const ArgList ,
  const char *LinkingOutput) const {
+  const llvm::Triple (getToolChain().getTriple());
+
   ArgStringList CmdArgs;
 
   assert(Inputs.size() == 1 && "Unexpected number of inputs.");
@@ -112,7 +114,6 @@
   // FIXME: at run-time detect assembler capabilities or rely on version
   // information forwarded by -target-assembler-version.
   if (Args.hasArg(options::OPT_fno_integrated_as)) {
-const llvm::Triple (getToolChain().getTriple());
 if (!(T.isMacOSX() && T.isMacOSXVersionLT(10, 7)))
   CmdArgs.push_back("-Q");
   }
@@ -130,8 +131,7 @@
   AddMachOArch(Args, CmdArgs);
 
   // Use -force_cpusubtype_ALL on x86 by default.
-  if (getToolChain().getTriple().isX86() ||
-  Args.hasArg(options::OPT_force__cpusubtype__ALL))
+  if (T.isX86() || Args.hasArg(options::OPT_force__cpusubtype__ALL))
 CmdArgs.push_back("-force_cpusubtype_ALL");
 
   if (getToolChain().getArch() != llvm::Triple::x86_64 &&


Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -94,6 +94,8 @@
  const InputInfoList ,
  const ArgList ,
  const char *LinkingOutput) const {
+  const llvm::Triple (getToolChain().getTriple());
+
   ArgStringList CmdArgs;
 
   assert(Inputs.size() == 1 && "Unexpected number of inputs.");
@@ -112,7 +114,6 @@
   // FIXME: at run-time detect assembler capabilities or rely on version
   // information forwarded by -target-assembler-version.
   if (Args.hasArg(options::OPT_fno_integrated_as)) {
-const llvm::Triple (getToolChain().getTriple());
 if (!(T.isMacOSX() && T.isMacOSXVersionLT(10, 7)))
   CmdArgs.push_back("-Q");
   }
@@ -130,8 +131,7 @@
   AddMachOArch(Args, CmdArgs);
 
   // Use -force_cpusubtype_ALL on x86 by default.
-  if (getToolChain().getTriple().isX86() ||
-  Args.hasArg(options::OPT_force__cpusubtype__ALL))
+  if (T.isX86() || Args.hasArg(options::OPT_force__cpusubtype__ALL))
 CmdArgs.push_back("-force_cpusubtype_ALL");
 
   if (getToolChain().getArch() != llvm::Triple::x86_64 &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8ecbcd0 - [Driver][Darwin] Use T reference instead of getToolChain().getTriple().

2021-10-14 Thread Frederic Cambus via cfe-commits

Author: Frederic Cambus
Date: 2021-10-14T21:30:39+02:00
New Revision: 8ecbcd058fbd552375fda614f36a1e01755c2620

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

LOG: [Driver][Darwin] Use T reference instead of getToolChain().getTriple().

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 8f3b6336d59d..5062c33bb096 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -94,6 +94,8 @@ void darwin::Assembler::ConstructJob(Compilation , const 
JobAction ,
  const InputInfoList ,
  const ArgList ,
  const char *LinkingOutput) const {
+  const llvm::Triple (getToolChain().getTriple());
+
   ArgStringList CmdArgs;
 
   assert(Inputs.size() == 1 && "Unexpected number of inputs.");
@@ -112,7 +114,6 @@ void darwin::Assembler::ConstructJob(Compilation , const 
JobAction ,
   // FIXME: at run-time detect assembler capabilities or rely on version
   // information forwarded by -target-assembler-version.
   if (Args.hasArg(options::OPT_fno_integrated_as)) {
-const llvm::Triple (getToolChain().getTriple());
 if (!(T.isMacOSX() && T.isMacOSXVersionLT(10, 7)))
   CmdArgs.push_back("-Q");
   }
@@ -130,8 +131,7 @@ void darwin::Assembler::ConstructJob(Compilation , const 
JobAction ,
   AddMachOArch(Args, CmdArgs);
 
   // Use -force_cpusubtype_ALL on x86 by default.
-  if (getToolChain().getTriple().isX86() ||
-  Args.hasArg(options::OPT_force__cpusubtype__ALL))
+  if (T.isX86() || Args.hasArg(options::OPT_force__cpusubtype__ALL))
 CmdArgs.push_back("-force_cpusubtype_ALL");
 
   if (getToolChain().getArch() != llvm::Triple::x86_64 &&



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


[PATCH] D111720: [clang][deps] Ensure reported context hash is strict

2021-10-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp:56-58
+  // Ensure the reported context hash is strict.
+  CI.getHeaderSearchOpts().ModulesStrictContextHash = true;
+

dexonsmith wrote:
> IIUC, explicit modules don't really have/need a context hash. Can related 
> options be stripped out when serializing to `-cc1` when `ImplicitModules` is 
> false?
> 
> Basically, I'm asking if `ModulesStrictContextHash` is a no-op when 
> `ImplicitModules` is false. If not, can we make it a no-op?
> (If we can, then maybe rename the field to `ImplicitModulesStrictContextHash` 
> and audit that no one reads it when `ImplicitModules` is off...)
Let me clarify this a bit. You're right that when building explicit modules, we 
don't care about context hash.

We do care about using **strict** context hash during the scan though - it's an 
implementation detail through which we prevent mixing incompatible modules/TUs. 
(This strict context hash is enabled elsewhere in the dependency scanner.)

At the end of the scan, we take discovered modules and modify/prune their 
`CompilerInvocation` (in this function). This can essentially "merge" multiple 
versions of the same module into one, which is very desirable. But we still 
want to do it according to the **strict** context hash. We don't want to merge 
versions with different search paths for example (non-strict context hash). 
That's what this change ensures.

Note that we don't **need** to report context hashes to scanner clients. Any 
other identifier derived from a strict context hash would work.



Comment at: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp:56-58
+  // Ensure the reported context hash is strict.
+  CI.getHeaderSearchOpts().ModulesStrictContextHash = true;
+

jansvoboda11 wrote:
> dexonsmith wrote:
> > IIUC, explicit modules don't really have/need a context hash. Can related 
> > options be stripped out when serializing to `-cc1` when `ImplicitModules` 
> > is false?
> > 
> > Basically, I'm asking if `ModulesStrictContextHash` is a no-op when 
> > `ImplicitModules` is false. If not, can we make it a no-op?
> > (If we can, then maybe rename the field to 
> > `ImplicitModulesStrictContextHash` and audit that no one reads it when 
> > `ImplicitModules` is off...)
> Let me clarify this a bit. You're right that when building explicit modules, 
> we don't care about context hash.
> 
> We do care about using **strict** context hash during the scan though - it's 
> an implementation detail through which we prevent mixing incompatible 
> modules/TUs. (This strict context hash is enabled elsewhere in the dependency 
> scanner.)
> 
> At the end of the scan, we take discovered modules and modify/prune their 
> `CompilerInvocation` (in this function). This can essentially "merge" 
> multiple versions of the same module into one, which is very desirable. But 
> we still want to do it according to the **strict** context hash. We don't 
> want to merge versions with different search paths for example (non-strict 
> context hash). That's what this change ensures.
> 
> Note that we don't **need** to report context hashes to scanner clients. Any 
> other identifier derived from a strict context hash would work.
I think the rename you're suggesting is valid.

We //could// strip the `ModulesStrictContextHash` in the scanner: after we 
generate the strict context hash and before we generate the command-line. I 
think that can be done in a NFC follow-up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111720

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


[PATCH] D111817: Fix a rejects-valid with consteval on overloaded operators

2021-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I landed the non-pmf changes in b9941de0bfac4bad93e11dff26396e34a53e3891 



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

https://reviews.llvm.org/D111817

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


[clang] b9941de - Fix a rejects-valid with consteval on overloaded operators

2021-10-14 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-10-14T14:47:29-04:00
New Revision: b9941de0bfac4bad93e11dff26396e34a53e3891

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

LOG: Fix a rejects-valid with consteval on overloaded operators

It seems that Clang 11 regressed functionality that was working in
Clang 10 regarding calling a few overloaded operators in an immediate
context. Specifically, we were not checking for immediate invocations
of array subscripting and the arrow operators, but we properly handle
the other overloaded operators.

This fixes the two problematic operators and adds some test coverage to
show they're equivalent to calling the operator directly.

This addresses PR50779.

Added: 


Modified: 
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 044e3c4b254ad..d93fd9df0093e 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -14161,7 +14161,8 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation 
LLoc,
   Method->getType()->castAs()))
   return ExprError();
 
-return MaybeBindToTemporary(TheCall);
+return CheckForImmediateInvocation(MaybeBindToTemporary(TheCall),
+   FnDecl);
   } else {
 // We matched a built-in operator. Convert the arguments, then
 // break out so that we will build the appropriate built-in
@@ -14916,7 +14917,7 @@ Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, 
SourceLocation OpLoc,
 Method->getType()->castAs()))
 return ExprError();
 
-  return MaybeBindToTemporary(TheCall);
+  return CheckForImmediateInvocation(MaybeBindToTemporary(TheCall), Method);
 }
 
 /// BuildLiteralOperatorCall - Build a UserDefinedLiteral by creating a call to

diff  --git a/clang/test/SemaCXX/cxx2a-consteval.cpp 
b/clang/test/SemaCXX/cxx2a-consteval.cpp
index 04c8898aa5bad..c1e713a5b6b79 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -612,3 +612,34 @@ using T = decltype(g(f()));
 static_assert(is_same::value);
 
 } // namespace unevaluated
+
+namespace PR50779 {
+struct derp {
+  int b = 0;
+};
+
+constexpr derp d;
+
+struct test {
+  consteval int operator[](int i) const { return {}; }
+  consteval const derp * operator->() const { return  }
+  consteval int f() const { return 12; } // expected-note 2{{declared here}}
+};
+
+constexpr test a;
+
+// We previously rejected both of these overloaded operators as taking the
+// address of a consteval function outside of an immediate context, but we
+// accepted direct calls to the overloaded operator. Now we show that we accept
+// both forms.
+constexpr int s = a.operator[](1);
+constexpr int t = a[1];
+constexpr int u = a.operator->()->b;
+constexpr int v = a->b;
+// FIXME: I believe this case should work, but we currently reject.
+constexpr int w = (a.*::f)(); // expected-error {{cannot take address of 
consteval function 'f' outside of an immediate invocation}}
+constexpr int x = a.f();
+
+// Show that we reject when not in an immediate context.
+int w2 = (a.*::f)(); // expected-error {{cannot take address of consteval 
function 'f' outside of an immediate invocation}}
+}



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


[PATCH] D111817: Fix a rejects-valid with consteval on overloaded operators

2021-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 379795.
aaron.ballman added a comment.

Updated the patch to add new test cases.


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

https://reviews.llvm.org/D111817

Files:
  clang/lib/Sema/SemaOverload.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
@@ -612,3 +612,34 @@
 static_assert(is_same::value);
 
 } // namespace unevaluated
+
+namespace PR50779 {
+struct derp {
+  int b = 0;
+};
+
+constexpr derp d;
+
+struct test {
+  consteval int operator[](int i) const { return {}; }
+  consteval const derp * operator->() const { return  }
+  consteval int f() const { return 12; } // expected-note 2{{declared here}}
+};
+
+constexpr test a;
+
+// We previously rejected both of these overloaded operators as taking the
+// address of a consteval function outside of an immediate context, but we
+// accepted direct calls to the overloaded operator. Now we show that we accept
+// both forms.
+constexpr int s = a.operator[](1);
+constexpr int t = a[1];
+constexpr int u = a.operator->()->b;
+constexpr int v = a->b;
+// FIXME: I believe this case should work, but we currently reject.
+constexpr int w = (a.*::f)(); // expected-error {{cannot take address of 
consteval function 'f' outside of an immediate invocation}}
+constexpr int x = a.f();
+
+// Show that we reject when not in an immediate context.
+int w2 = (a.*::f)(); // expected-error {{cannot take address of consteval 
function 'f' outside of an immediate invocation}}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -14161,7 +14161,8 @@
   Method->getType()->castAs()))
   return ExprError();
 
-return MaybeBindToTemporary(TheCall);
+return CheckForImmediateInvocation(MaybeBindToTemporary(TheCall),
+   FnDecl);
   } else {
 // We matched a built-in operator. Convert the arguments, then
 // break out so that we will build the appropriate built-in
@@ -14916,7 +14917,7 @@
 Method->getType()->castAs()))
 return ExprError();
 
-  return MaybeBindToTemporary(TheCall);
+  return CheckForImmediateInvocation(MaybeBindToTemporary(TheCall), Method);
 }
 
 /// BuildLiteralOperatorCall - Build a UserDefinedLiteral by creating a call to


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -612,3 +612,34 @@
 static_assert(is_same::value);
 
 } // namespace unevaluated
+
+namespace PR50779 {
+struct derp {
+  int b = 0;
+};
+
+constexpr derp d;
+
+struct test {
+  consteval int operator[](int i) const { return {}; }
+  consteval const derp * operator->() const { return  }
+  consteval int f() const { return 12; } // expected-note 2{{declared here}}
+};
+
+constexpr test a;
+
+// We previously rejected both of these overloaded operators as taking the
+// address of a consteval function outside of an immediate context, but we
+// accepted direct calls to the overloaded operator. Now we show that we accept
+// both forms.
+constexpr int s = a.operator[](1);
+constexpr int t = a[1];
+constexpr int u = a.operator->()->b;
+constexpr int v = a->b;
+// FIXME: I believe this case should work, but we currently reject.
+constexpr int w = (a.*::f)(); // expected-error {{cannot take address of consteval function 'f' outside of an immediate invocation}}
+constexpr int x = a.f();
+
+// Show that we reject when not in an immediate context.
+int w2 = (a.*::f)(); // expected-error {{cannot take address of consteval function 'f' outside of an immediate invocation}}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -14161,7 +14161,8 @@
   Method->getType()->castAs()))
   return ExprError();
 
-return MaybeBindToTemporary(TheCall);
+return CheckForImmediateInvocation(MaybeBindToTemporary(TheCall),
+   FnDecl);
   } else {
 // We matched a built-in operator. Convert the arguments, then
 // break out so that we will build the appropriate built-in
@@ -14916,7 +14917,7 @@
 Method->getType()->castAs()))
 return ExprError();
 
-  return MaybeBindToTemporary(TheCall);
+  return CheckForImmediateInvocation(MaybeBindToTemporary(TheCall), Method);
 }
 
 /// BuildLiteralOperatorCall - Build a UserDefinedLiteral by creating a call to

[PATCH] D111817: Fix a rejects-valid with consteval on overloaded operators

2021-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:14290
 
 return MaybeBindToTemporary(call);
   }

aaron.ballman wrote:
> erichkeane wrote:
> > rsmith wrote:
> > > aaron.ballman wrote:
> > > > erichkeane wrote:
> > > > > Was this one missed too?
> > > > I couldn't devise a test case that was failing with member function 
> > > > call expressions, so I left this one alone. We have a bunch of existing 
> > > > test coverage for calling a consteval member function, so I'm assuming 
> > > > this is correct, but if someone finds a test case that fails here, it's 
> > > > easy enough to fix.
> > > This code is only reachable for a call through a pointer-to-member. We 
> > > don't need to worry about `consteval` member function pointers because 
> > > they can't escape constant-evaluated contexts anyway. Eg, 
> > > `(p->*::consteval_fn)()` is ill-formed outside of a 
> > > constant-evaluated context -- we should make sure we have a test for that.
> > I can't come up with one either, I think we're fine for now.
> ```
> struct test {
>   consteval int f() const { return 12; }
> };
> 
> constexpr test t;
> int main() {
>   constexpr int i = (t.*::f)();
> }
> ```
> @rsmith -- would you expect us to accept or reject this? GCC accepts, MSVC 
> rejects, Clang currently rejects. This is different from your test case 
> (because this is in a constant evaluated context), which we do already reject 
> with a decent message: https://godbolt.org/z/3nv4bco9M
Thinking about this a bit more, I think that code should be accepted.
```
struct test {
  consteval int f() const { return 12; }
};

constexpr test t;
int main() {
  constexpr int i = t.f(); // If this works
  constexpr int j = (t.*::f)(); // This should also work
}
```
However, when I make the obvious changes in this patch to support it, we stop 
getting the diagnostic outside of a constant evaluated context. So my plan is 
to land the small fixes we know are correct and are happy with, and we can 
debate this case more later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111817

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


[PATCH] D111767: [clang] Support -clear-ast-before-backend without -disable-free

2021-10-14 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added subscribers: aaron.ballman, rsmith.
dblaikie added a comment.
This revision is now accepted and ready to land.

Sounds OK, thanks!




Comment at: clang/lib/CodeGen/CodeGenAction.cpp:355-356
+  if (CodeGenOpts.ClearASTBeforeBackend) {
+// The ASTContext may be unusable after this.
+C.cleanup();
 C.getAllocator().Reset();

aeubanks wrote:
> dblaikie wrote:
> > Any chance of refactoring such that the ASTContext is scoped such that it 
> > is destroyed here, rather than rendered unusable - to reduce the chance 
> > that it'd be accidentally used after this point?
> > 
> > Like what happens if CompilerInstance::setASTContext(nullptr) is called? It 
> > wouldn't null out everyone's ASTContext pointers, but would mean there's no 
> > object there - perhaps crash harder/faster than a "cleaned up" ASTContext 
> > being used?
> I had tried this in the past and gave up for some reason. So I tried again 
> (ASan was very helpful here) and ran into a couple of issues.
> 
> First, Sema depends on ASTContext, so we have to `setSema(nullptr)` before 
> `setASTContext(nullptr)`, but Sema has to finalize some things after codegen, 
> so we can't `CI->setSema(nullptr)` until much later.
> 
> Another unrelated thing is that the diagnostics end up calling into 
> ASTContext. This might be fixable by moving some data structures out of 
> ASTContext?
> 
> Another unrelated thing is a weird crash in 
> `DiagStorageAllocator::~DiagStorageAllocator()` when calling 
> `setASTContext(nullptr)` early.
> 
> These individually might be solvable, but it seems like a lot of unrelated 
> issues.
> Basically, we depend a lot on various parts of ASTContext that aren't the 
> actual AST nodes themselves.
Fair enough - not sure, but might be worth noting this info somewhere in the 
source in case someone else comes along to do this refactoring in the future if 
they have another reason to weigh into the choice to address it.

@rsmith @aaron.ballman - wouldn't mind at least a quick thought on this stuff 
if you've both got a moment - for long term direction/broad design of this 
stuff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111767

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


[PATCH] D111371: [Support][ThinLTO] Move ThinLTO caching to LLVM Support library.

2021-10-14 Thread Noah Shutty via Phabricator via cfe-commits
noajshu updated this revision to Diff 379787.
noajshu added a comment.

rebase against main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111371

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  lld/COFF/LTO.cpp
  lld/ELF/LTO.cpp
  lld/MachO/LTO.cpp
  lld/wasm/LTO.cpp
  llvm/include/llvm/LTO/Caching.h
  llvm/include/llvm/LTO/LTO.h
  llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
  llvm/include/llvm/Support/Caching.h
  llvm/lib/LTO/CMakeLists.txt
  llvm/lib/LTO/Caching.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/Caching.cpp
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -19,10 +19,10 @@
 #include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/IR/DiagnosticPrinter.h"
-#include "llvm/LTO/Caching.h"
 #include "llvm/LTO/LTO.h"
 #include "llvm/Passes/PassPlugin.h"
 #include "llvm/Remarks/HotnessThresholdParser.h"
+#include "llvm/Support/Caching.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/InitLLVM.h"
@@ -362,14 +362,13 @@
   if (HasErrors)
 return 1;
 
-  auto AddStream =
-  [&](size_t Task) -> std::unique_ptr {
+  auto AddStream = [&](size_t Task) -> std::unique_ptr {
 std::string Path = OutputFilename + "." + utostr(Task);
 
 std::error_code EC;
 auto S = std::make_unique(Path, EC, sys::fs::OF_None);
 check(EC, Path);
-return std::make_unique(std::move(S));
+return std::make_unique(std::move(S));
   };
 
   auto AddBuffer = [&](size_t Task, std::unique_ptr MB) {
@@ -378,7 +377,8 @@
 
   NativeObjectCache Cache;
   if (!CacheDir.empty())
-Cache = check(localCache(CacheDir, AddBuffer), "failed to create cache");
+Cache = check(localCache("ThinLTO", "Thin", CacheDir, AddBuffer),
+  "failed to create cache");
 
   check(Lto.run(AddStream, Cache), "LTO::run failed");
   return 0;
Index: llvm/tools/llvm-lto/llvm-lto.cpp
===
--- llvm/tools/llvm-lto/llvm-lto.cpp
+++ llvm/tools/llvm-lto/llvm-lto.cpp
@@ -1097,8 +1097,7 @@
 error("writing merged module failed.");
 }
 
-auto AddStream =
-[&](size_t Task) -> std::unique_ptr {
+auto AddStream = [&](size_t Task) -> std::unique_ptr {
   std::string PartFilename = OutputFilename;
   if (Parallelism != 1)
 PartFilename += "." + utostr(Task);
@@ -1108,7 +1107,7 @@
   std::make_unique(PartFilename, EC, sys::fs::OF_None);
   if (EC)
 error("error opening the file '" + PartFilename + "': " + EC.message());
-  return std::make_unique(std::move(S));
+  return std::make_unique(std::move(S));
 };
 
 if (!CodeGen.compileOptimized(AddStream, Parallelism))
Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -1081,12 +1081,11 @@
   size_t MaxTasks = Lto->getMaxTasks();
   std::vector, bool>> Files(MaxTasks);
 
-  auto AddStream =
-  [&](size_t Task) -> std::unique_ptr {
+  auto AddStream = [&](size_t Task) -> std::unique_ptr {
 Files[Task].second = !SaveTemps;
 int FD = getOutputFileName(Filename, /* TempOutFile */ !SaveTemps,
Files[Task].first, Task);
-return std::make_unique(
+return std::make_unique(
 std::make_unique(FD, true));
   };
 
@@ -1096,7 +1095,7 @@
 
   NativeObjectCache Cache;
   if (!options::cache_dir.empty())
-Cache = check(localCache(options::cache_dir, AddBuffer));
+Cache = check(localCache("ThinLTO", "Thin", options::cache_dir, AddBuffer));
 
   check(Lto->run(AddStream, Cache));
 
Index: llvm/lib/Support/Caching.cpp
===
--- llvm/lib/Support/Caching.cpp
+++ llvm/lib/Support/Caching.cpp
@@ -1,4 +1,4 @@
-//===-Caching.cpp - LLVM Link Time Optimizer Cache Handling ---===//
+//===-Caching.cpp - LLVM File Cache Handling --===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,11 +6,11 @@
 //
 //===--===//
 //
-// This file implements the Caching for ThinLTO.
+// This file implements the Caching used by ThinLTO.
 //
 //===--===//
 
-#include "llvm/LTO/Caching.h"
+#include "llvm/Support/Caching.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Errc.h"
 #include 

[PATCH] D111767: [clang] Support -clear-ast-before-backend without -disable-free

2021-10-14 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:355-356
+  if (CodeGenOpts.ClearASTBeforeBackend) {
+// The ASTContext may be unusable after this.
+C.cleanup();
 C.getAllocator().Reset();

dblaikie wrote:
> Any chance of refactoring such that the ASTContext is scoped such that it is 
> destroyed here, rather than rendered unusable - to reduce the chance that 
> it'd be accidentally used after this point?
> 
> Like what happens if CompilerInstance::setASTContext(nullptr) is called? It 
> wouldn't null out everyone's ASTContext pointers, but would mean there's no 
> object there - perhaps crash harder/faster than a "cleaned up" ASTContext 
> being used?
I had tried this in the past and gave up for some reason. So I tried again 
(ASan was very helpful here) and ran into a couple of issues.

First, Sema depends on ASTContext, so we have to `setSema(nullptr)` before 
`setASTContext(nullptr)`, but Sema has to finalize some things after codegen, 
so we can't `CI->setSema(nullptr)` until much later.

Another unrelated thing is that the diagnostics end up calling into ASTContext. 
This might be fixable by moving some data structures out of ASTContext?

Another unrelated thing is a weird crash in 
`DiagStorageAllocator::~DiagStorageAllocator()` when calling 
`setASTContext(nullptr)` early.

These individually might be solvable, but it seems like a lot of unrelated 
issues.
Basically, we depend a lot on various parts of ASTContext that aren't the 
actual AST nodes themselves.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111767

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


[PATCH] D110898: Pass template parameters when printing template argument lists for function templates

2021-10-14 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110898

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


[PATCH] D107882: BPF: Enable frontend constant folding for VLA size

2021-10-14 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I don't think my opinion has changed here.  I'm against the solution proposed 
in this patch.  The other solutions discussed in the review seem fine.  (The 
simplest is just to make the bpf backend ignore stacksave/stackrestore calls.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107882

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


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-14 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 379772.
yonghong-song retitled this revision from "[POC][BTF] support btf_type_tag 
attribute" to "[Clang][LLVM][Attr] support btf_type_tag attribute".
yonghong-song edited the summary of this revision.
yonghong-song added a comment.
Herald added subscribers: arphaman, martong.

- remove POC tag and now the implementation is complete
- in this patch, AttributedBTFType is created as a subclass of AttributedType. 
This makes quite some changes in the codebase for processing or handling 
AttributedBTFType. Alternatively, we could amend existing AttributedType to 
have a StringRef to store btf_tag. We can discuss which way is better.
- I may have missed some testing. Let me know what I have missed and I can add 
them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeLoc.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/TypeNodes.td
  clang/include/clang/Serialization/ASTRecordWriter.h
  clang/include/clang/Serialization/TypeBitCodes.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGen/attr-btf_type_tag-conv-var.c
  clang/test/CodeGen/attr-btf_type_tag-typedef-field.c
  clang/test/Sema/attr-btf_type_tag.c
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/DebugInfo/attr-btf_type_tag.ll

Index: llvm/test/DebugInfo/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/attr-btf_type_tag.ll
@@ -0,0 +1,62 @@
+; REQUIRES: x86-registered-target
+; RUN: llc -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   #define __tag2 __attribute__((btf_type_tag("tag2")))
+;
+;   int * __tag1 * __tag2 *g;
+; Compilation flag:
+;   clang -target x86_64 -g -S -emit-llvm t.c
+
+@g = dso_local global i32*** null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!13, !14, !15, !16, !17}
+!llvm.ident = !{!18}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !11)
+!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, annotations: !9)
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{!10}
+!10 = !{!"btf_type_tag", !"tag1"}
+!11 = !{!12}
+!12 = !{!"btf_type_tag", !"tag2"}
+
+; CHECK:  DW_TAG_variable
+; CHECK-NEXT:   DW_AT_name  ("g")
+; CHECK-NEXT:   DW_AT_type  (0x[[T1:[0-9]+]] "int ***")
+
+; CHECK:  0x[[T1]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T2:[0-9]+]] "int **")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag2")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T2]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T3:[0-9]+]] "int *")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag1")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T3]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[#]] "int")
+
+!13 = !{i32 7, !"Dwarf Version", i32 4}
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 1, !"wchar_size", i32 4}
+!16 = !{i32 7, !"uwtable", i32 1}
+!17 = !{i32 7, !"frame-pointer", i32 2}
+!18 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)"}
Index: llvm/lib/IR/DIBuilder.cpp
===
--- 

[clang] f7a3214 - [Driver][WebAssembly] Use ToolChain reference instead of getToolChain().

2021-10-14 Thread Frederic Cambus via cfe-commits

Author: Frederic Cambus
Date: 2021-10-14T19:43:59+02:00
New Revision: f7a3214306cb83c350a89e2247f67983dbd792ea

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

LOG: [Driver][WebAssembly] Use ToolChain reference instead of getToolChain().

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

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 6ce4f4454487..b1a5e58d2980 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -63,7 +63,7 @@ void wasm::Linker::ConstructJob(Compilation , const 
JobAction ,
   ArgStringList CmdArgs;
 
   CmdArgs.push_back("-m");
-  if (getToolChain().getTriple().isArch64Bit())
+  if (ToolChain.getTriple().isArch64Bit())
 CmdArgs.push_back("wasm64");
   else
 CmdArgs.push_back("wasm32");
@@ -130,7 +130,7 @@ void wasm::Linker::ConstructJob(Compilation , const 
JobAction ,
 
   // When optimizing, if wasm-opt is available, run it.
   if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
-auto WasmOptPath = getToolChain().GetProgramPath("wasm-opt");
+auto WasmOptPath = ToolChain.GetProgramPath("wasm-opt");
 if (WasmOptPath != "wasm-opt") {
   StringRef OOpt = "s";
   if (A->getOption().matches(options::OPT_O4) ||



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


[PATCH] D111786: [Driver][WebAssembly] Use ToolChain reference instead of getToolChain().

2021-10-14 Thread Frederic Cambus via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf7a3214306cb: [Driver][WebAssembly] Use ToolChain reference 
instead of getToolChain(). (authored by fcambus).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111786

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


Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -63,7 +63,7 @@
   ArgStringList CmdArgs;
 
   CmdArgs.push_back("-m");
-  if (getToolChain().getTriple().isArch64Bit())
+  if (ToolChain.getTriple().isArch64Bit())
 CmdArgs.push_back("wasm64");
   else
 CmdArgs.push_back("wasm32");
@@ -130,7 +130,7 @@
 
   // When optimizing, if wasm-opt is available, run it.
   if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
-auto WasmOptPath = getToolChain().GetProgramPath("wasm-opt");
+auto WasmOptPath = ToolChain.GetProgramPath("wasm-opt");
 if (WasmOptPath != "wasm-opt") {
   StringRef OOpt = "s";
   if (A->getOption().matches(options::OPT_O4) ||


Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -63,7 +63,7 @@
   ArgStringList CmdArgs;
 
   CmdArgs.push_back("-m");
-  if (getToolChain().getTriple().isArch64Bit())
+  if (ToolChain.getTriple().isArch64Bit())
 CmdArgs.push_back("wasm64");
   else
 CmdArgs.push_back("wasm32");
@@ -130,7 +130,7 @@
 
   // When optimizing, if wasm-opt is available, run it.
   if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
-auto WasmOptPath = getToolChain().GetProgramPath("wasm-opt");
+auto WasmOptPath = ToolChain.GetProgramPath("wasm-opt");
 if (WasmOptPath != "wasm-opt") {
   StringRef OOpt = "s";
   if (A->getOption().matches(options::OPT_O4) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111793: [Driver][Darwin] Use T reference instead of getToolChain().getTriple().

2021-10-14 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.
This revision is now accepted and ready to land.

Thanks, lgtm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111793

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


[PATCH] D111817: Fix a rejects-valid with consteval on overloaded operators

2021-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:14290
 
 return MaybeBindToTemporary(call);
   }

erichkeane wrote:
> rsmith wrote:
> > aaron.ballman wrote:
> > > erichkeane wrote:
> > > > Was this one missed too?
> > > I couldn't devise a test case that was failing with member function call 
> > > expressions, so I left this one alone. We have a bunch of existing test 
> > > coverage for calling a consteval member function, so I'm assuming this is 
> > > correct, but if someone finds a test case that fails here, it's easy 
> > > enough to fix.
> > This code is only reachable for a call through a pointer-to-member. We 
> > don't need to worry about `consteval` member function pointers because they 
> > can't escape constant-evaluated contexts anyway. Eg, 
> > `(p->*::consteval_fn)()` is ill-formed outside of a 
> > constant-evaluated context -- we should make sure we have a test for that.
> I can't come up with one either, I think we're fine for now.
```
struct test {
  consteval int f() const { return 12; }
};

constexpr test t;
int main() {
  constexpr int i = (t.*::f)();
}
```
@rsmith -- would you expect us to accept or reject this? GCC accepts, MSVC 
rejects, Clang currently rejects. This is different from your test case 
(because this is in a constant evaluated context), which we do already reject 
with a decent message: https://godbolt.org/z/3nv4bco9M


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111817

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


[PATCH] D111817: Fix a rejects-valid with consteval on overloaded operators

2021-10-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:14290
 
 return MaybeBindToTemporary(call);
   }

rsmith wrote:
> aaron.ballman wrote:
> > erichkeane wrote:
> > > Was this one missed too?
> > I couldn't devise a test case that was failing with member function call 
> > expressions, so I left this one alone. We have a bunch of existing test 
> > coverage for calling a consteval member function, so I'm assuming this is 
> > correct, but if someone finds a test case that fails here, it's easy enough 
> > to fix.
> This code is only reachable for a call through a pointer-to-member. We don't 
> need to worry about `consteval` member function pointers because they can't 
> escape constant-evaluated contexts anyway. Eg, `(p->*::consteval_fn)()` 
> is ill-formed outside of a constant-evaluated context -- we should make sure 
> we have a test for that.
I can't come up with one either, I think we're fine for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111817

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


[PATCH] D111817: Fix a rejects-valid with consteval on overloaded operators

2021-10-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Looks good to me.




Comment at: clang/lib/Sema/SemaOverload.cpp:14290
 
 return MaybeBindToTemporary(call);
   }

aaron.ballman wrote:
> erichkeane wrote:
> > Was this one missed too?
> I couldn't devise a test case that was failing with member function call 
> expressions, so I left this one alone. We have a bunch of existing test 
> coverage for calling a consteval member function, so I'm assuming this is 
> correct, but if someone finds a test case that fails here, it's easy enough 
> to fix.
This code is only reachable for a call through a pointer-to-member. We don't 
need to worry about `consteval` member function pointers because they can't 
escape constant-evaluated contexts anyway. Eg, `(p->*::consteval_fn)()` 
is ill-formed outside of a constant-evaluated context -- we should make sure we 
have a test for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111817

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


[PATCH] D111817: Fix a rejects-valid with consteval on overloaded operators

2021-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:13800
 
 ExprResult R = MaybeBindToTemporary(TheCall);
 if (R.isInvalid())

erichkeane wrote:
> Wonder if as a 'while we're here' we should make this the same as the others? 
> Does `CheckForImmediateInvocation` handle an invalid result without the extra 
> check like we have here?
`CheckForImmediateInvocation` handles invalid results (I checked), so we could 
remove the isInvalid() lines below if we wanted (that's really an NFC cleanup).



Comment at: clang/lib/Sema/SemaOverload.cpp:14290
 
 return MaybeBindToTemporary(call);
   }

erichkeane wrote:
> Was this one missed too?
I couldn't devise a test case that was failing with member function call 
expressions, so I left this one alone. We have a bunch of existing test 
coverage for calling a consteval member function, so I'm assuming this is 
correct, but if someone finds a test case that fails here, it's easy enough to 
fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111817

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


[PATCH] D111817: Fix a rejects-valid with consteval on overloaded operators

2021-10-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

This seems like two places this was missed in: https://reviews.llvm.org/D63960 
however I see a another place grepping around we might have missed too?  Can 
you find a way to write tests for that?

Also, perhaps 1 more cleanup?




Comment at: clang/lib/Sema/SemaOverload.cpp:13800
 
 ExprResult R = MaybeBindToTemporary(TheCall);
 if (R.isInvalid())

Wonder if as a 'while we're here' we should make this the same as the others? 
Does `CheckForImmediateInvocation` handle an invalid result without the extra 
check like we have here?



Comment at: clang/lib/Sema/SemaOverload.cpp:14290
 
 return MaybeBindToTemporary(call);
   }

Was this one missed too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111817

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


[PATCH] D109632: [clang] de-duplicate methods from AST files

2021-10-14 Thread Richard Howell via Phabricator via cfe-commits
rmaz added a comment.

In D109632#3062608 , @vsapsai wrote:

> I can be wrong but I like writing less data as it can result in savings for 
> more projects. For example, if compile time is dominated by method 
> deserialization and not by `Sema::addMethodToGlobalList`, we still should see 
> an improvement. I can try to experiment on a bunch of other projects and 
> their heavy .m files and report the results, if you'd like.

I think that would be a useful comparison, yes. For our code I consistently 
measure this approach as 10-20% slower on average, with very few outliers where 
the set deduplication approach is slower.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109632

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


[PATCH] D111814: Fix consteval crash when transforming 'this' expressions

2021-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:14839
 
   if (!IsInstantiation)
 PopDeclContext();

erichkeane wrote:
> so the only real change here is that `ExitFunctionBodyRAII` ends here, 
> instead of the end of the function?  
> 
> I guess this SEEMS pretty innocuous, I don't know particularly what 
> `PopFunctionScopeInfo` does well enough to know if this is going to cause 
> problems, but I DO know at least the 14850+ doesn't need to have the function 
> body in scope (and PopDeclContext seems like it doesn't do much?)...
> 
> I would think that anything after `PopDeclContext` would have a problem being 
> in the function body anyway (that is, being in a 'function body' with a 
> mismatched DeclContext seems wrong), so I'm reasonably convinced this is at 
> least non-breaking.
> 
> so the only real change here is that ExitFunctionBodyRAII ends here, instead 
> of the end of the function?

That's correct. I added the opening curly brace before the comments on the 
declaration of `ExitRAII`, and the close curly brace is on the line with the 
new comments added to it. Git decided this was the best diff it could come up 
with for all that re-indentation. :-/

> I would think that anything after PopDeclContext would have a problem being 
> in the function body anyway (that is, being in a 'function body' with a 
> mismatched DeclContext seems wrong), so I'm reasonably convinced this is at 
> least non-breaking.

This matches my thinking -- just before we go to pop the declaration context or 
scope, *that* is when the function body has ended.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111814

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


[PATCH] D111778: [WIP][X86] Update CPU_SPECIFIC list.

2021-10-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D111778#3064439 , @craig.topper 
wrote:

> In D111778#3064287 , @FreddyYe 
> wrote:
>
>> In D111778#3063891 , @erichkeane 
>> wrote:
>>
>>> Supporting these types requires changes to the library so that we can check 
>>> these, right?  Do you have the library changes for these as well?  The 
>>> constants used to check for these features/etc needs to be present in the 
>>> glibc library.
>>
>> Yes. It's highly related to the `ProcessorFeatures` I mentioned above. Does 
>> the `library changes` refer to the compiler-rt/cpu_model.c? I think that 
>> change depends on libgcc. For now libgcc has no strong will to update that 
>> table.
>
> Every feature gcc knows about should be in libgcc. The unfortunate problem 
> now is that cpu_features2 in libgcc is an array thats size may be different 
> with every version of gcc. Clang can’t know how big that array is without 
> reading the libgcc.a symbol table at compile time. Without knowing the size 
> we can’t access any bits past the first 32 bits of cpu_features2.

libgcc entries are the ones I was concerned about.  We need to make sure this 
list matches that one (and we don't generate checks that it does not have).  
@craig.topper can better clarify what needs to happen with the library lookup, 
but I THINK we keep a version of this in compiler-rt instead of using libgcc?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111778

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


[PATCH] D111708: [libTooling] Add "switch"-like Stencil combinator

2021-10-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb6c218d4fdb7: [libTooling] Add switch-like 
Stencil combinator (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111708

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

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -201,6 +201,58 @@
   testExpr(Id, "3;", ifBound("other", cat("5"), cat("7")), "7");
 }
 
+static auto selectMatcher() {
+  // The `anything` matcher is not bound, to test for none of the cases
+  // matching.
+  return expr(anyOf(integerLiteral().bind("int"), cxxBoolLiteral().bind("bool"),
+floatLiteral().bind("float"), anything()));
+}
+
+static auto selectStencil() {
+  return selectBound({
+  {"int", cat("I")},
+  {"bool", cat("B")},
+  {"bool", cat("redundant")},
+  {"float", cat("F")},
+  });
+}
+
+TEST_F(StencilTest, SelectBoundChooseDetectedMatch) {
+  std::string Input = "3;";
+  auto StmtMatch = matchStmt(Input, selectMatcher());
+  ASSERT_TRUE(StmtMatch);
+  EXPECT_THAT_EXPECTED(selectStencil()->eval(StmtMatch->Result),
+   HasValue(std::string("I")));
+}
+
+TEST_F(StencilTest, SelectBoundChooseFirst) {
+  std::string Input = "true;";
+  auto StmtMatch = matchStmt(Input, selectMatcher());
+  ASSERT_TRUE(StmtMatch);
+  EXPECT_THAT_EXPECTED(selectStencil()->eval(StmtMatch->Result),
+   HasValue(std::string("B")));
+}
+
+TEST_F(StencilTest, SelectBoundDiesOnExhaustedCases) {
+  std::string Input = "\"string\";";
+  auto StmtMatch = matchStmt(Input, selectMatcher());
+  ASSERT_TRUE(StmtMatch);
+  EXPECT_THAT_EXPECTED(
+  selectStencil()->eval(StmtMatch->Result),
+  Failed(testing::Property(
+  ::getMessage,
+  AllOf(HasSubstr("selectBound failed"), HasSubstr("no default");
+}
+
+TEST_F(StencilTest, SelectBoundSucceedsWithDefault) {
+  std::string Input = "\"string\";";
+  auto StmtMatch = matchStmt(Input, selectMatcher());
+  ASSERT_TRUE(StmtMatch);
+  auto Stencil = selectBound({{"int", cat("I")}}, cat("D"));
+  EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result),
+   HasValue(std::string("D")));
+}
+
 TEST_F(StencilTest, ExpressionOpNoParens) {
   StringRef Id = "id";
   testExpr(Id, "3;", expression(Id), "3");
@@ -674,6 +726,28 @@
   EXPECT_EQ(S->toString(), Expected);
 }
 
+TEST(StencilToStringTest, SelectBoundOp) {
+  auto S = selectBound({
+  {"int", cat("I")},
+  {"float", cat("F")},
+  });
+  StringRef Expected = R"repr(selectBound({{"int", "I"}, {"float", "F"}}))repr";
+  EXPECT_EQ(S->toString(), Expected);
+}
+
+TEST(StencilToStringTest, SelectBoundOpWithOneCase) {
+  auto S = selectBound({{"int", cat("I")}});
+  StringRef Expected = R"repr(selectBound({{"int", "I"}}))repr";
+  EXPECT_EQ(S->toString(), Expected);
+}
+
+TEST(StencilToStringTest, SelectBoundOpWithDefault) {
+  auto S = selectBound({{"int", cat("I")}, {"float", cat("F")}}, cat("D"));
+  StringRef Expected =
+  R"cc(selectBound({{"int", "I"}, {"float", "F"}}, "D"))cc";
+  EXPECT_EQ(S->toString(), Expected);
+}
+
 TEST(StencilToStringTest, RunOp) {
   auto F1 = [](const MatchResult ) { return "foo"; };
   auto S1 = run(F1);
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -27,14 +27,15 @@
 using namespace clang;
 using namespace transformer;
 
+using ast_matchers::BoundNodes;
 using ast_matchers::MatchFinder;
 using llvm::errc;
 using llvm::Error;
 using llvm::Expected;
 using llvm::StringError;
 
-static llvm::Expected
-getNode(const ast_matchers::BoundNodes , StringRef Id) {
+static llvm::Expected getNode(const BoundNodes ,
+StringRef Id) {
   auto  = Nodes.getMap();
   auto It = NodesMap.find(Id);
   if (It == NodesMap.end())
@@ -366,6 +367,73 @@
   }
 };
 
+class SelectBoundStencil : public clang::transformer::StencilInterface {
+  static bool containsNoNullStencils(
+  const std::vector> ) {
+for (const auto  : Cases)
+  if (S.second == nullptr)
+return false;
+return true;
+  }
+
+public:
+  SelectBoundStencil(std::vector> Cases,
+ Stencil Default)
+  : CaseStencils(std::move(Cases)), DefaultStencil(std::move(Default)) {
+assert(containsNoNullStencils(CaseStencils) &&
+   "cases of selectBound may not be null");
+  }
+  ~SelectBoundStencil() override{};
+
+  llvm::Error eval(const MatchFinder::MatchResult ,
+   

[clang] b6c218d - [libTooling] Add "switch"-like Stencil combinator

2021-10-14 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2021-10-14T16:45:37Z
New Revision: b6c218d4fdb74c0ee467e078721438c3396dc599

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

LOG: [libTooling] Add "switch"-like Stencil combinator

Adds `selectBound`, a `Stencil` combinator that allows the user to supply 
multiple alternative cases, discriminated by bound node IDs.

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

Added: 


Modified: 
clang/include/clang/Tooling/Transformer/Stencil.h
clang/lib/Tooling/Transformer/Stencil.cpp
clang/unittests/Tooling/StencilTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Transformer/Stencil.h 
b/clang/include/clang/Tooling/Transformer/Stencil.h
index 1b7495eb02622..249f95b7391df 100644
--- a/clang/include/clang/Tooling/Transformer/Stencil.h
+++ b/clang/include/clang/Tooling/Transformer/Stencil.h
@@ -117,6 +117,38 @@ inline Stencil ifBound(llvm::StringRef Id, llvm::StringRef 
TrueText,
  detail::makeStencil(FalseText));
 }
 
+/// Chooses between multiple stencils, based on the presence of bound nodes. \p
+/// CaseStencils takes a vector of (ID, \c Stencil) pairs and checks each ID in
+/// order to see if it's bound to a node.  If so, the associated \c Stencil is
+/// run and all other cases are ignored.  An optional \p DefaultStencil can be
+/// provided to be run if all cases are exhausted beacause none of the provided
+/// IDs are bound.  If no default case is provided and all cases are exhausted,
+/// the stencil will fail with error `llvm::errc::result_out_of_range`.
+///
+/// For example, say one matches a statement's type with:
+/// anyOf(
+///   qualType(isInteger()).bind("int"),
+///   qualType(realFloatingPointType()).bind("float"),
+///   qualType(isAnyCharacter()).bind("char"),
+///   booleanType().bind("bool"))
+///
+/// Then, one can decide in a stencil how to construct a literal.
+/// cat("a = ",
+/// selectBound(
+/// {{"int", cat("0")},
+///  {"float", cat("0.0")},
+///  {"char", cat("'\\0'")},
+///  {"bool", cat("false")}}))
+///
+/// In addition, one could supply a default case for all other types:
+/// selectBound(
+/// {{"int", cat("0")},
+///  ...
+///  {"bool", cat("false")}},
+/// cat("{}"))
+Stencil selectBound(std::vector> CaseStencils,
+Stencil DefaultStencil = nullptr);
+
 /// Wraps a \c MatchConsumer in a \c Stencil, so that it can be used in a \c
 /// Stencil.  This supports user-defined extensions to the \c Stencil language.
 Stencil run(MatchConsumer C);

diff  --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index 4dc3544bb06db..8b20ef34c3ff2 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -27,14 +27,15 @@
 using namespace clang;
 using namespace transformer;
 
+using ast_matchers::BoundNodes;
 using ast_matchers::MatchFinder;
 using llvm::errc;
 using llvm::Error;
 using llvm::Expected;
 using llvm::StringError;
 
-static llvm::Expected
-getNode(const ast_matchers::BoundNodes , StringRef Id) {
+static llvm::Expected getNode(const BoundNodes ,
+StringRef Id) {
   auto  = Nodes.getMap();
   auto It = NodesMap.find(Id);
   if (It == NodesMap.end())
@@ -366,6 +367,73 @@ class IfBoundStencil : public StencilInterface {
   }
 };
 
+class SelectBoundStencil : public clang::transformer::StencilInterface {
+  static bool containsNoNullStencils(
+  const std::vector> ) {
+for (const auto  : Cases)
+  if (S.second == nullptr)
+return false;
+return true;
+  }
+
+public:
+  SelectBoundStencil(std::vector> Cases,
+ Stencil Default)
+  : CaseStencils(std::move(Cases)), DefaultStencil(std::move(Default)) {
+assert(containsNoNullStencils(CaseStencils) &&
+   "cases of selectBound may not be null");
+  }
+  ~SelectBoundStencil() override{};
+
+  llvm::Error eval(const MatchFinder::MatchResult ,
+   std::string *result) const override {
+const BoundNodes::IDToNodeMap  = match.Nodes.getMap();
+for (const auto  : CaseStencils) {
+  if (NodeMap.count(S.first) > 0) {
+return S.second->eval(match, result);
+  }
+}
+
+if (DefaultStencil != nullptr) {
+  return DefaultStencil->eval(match, result);
+}
+
+llvm::SmallVector CaseIDs;
+CaseIDs.reserve(CaseStencils.size());
+for (const auto  : CaseStencils)
+  CaseIDs.emplace_back(S.first);
+
+return llvm::createStringError(
+errc::result_out_of_range,
+llvm::Twine("selectBound failed: no cases bound and no default: {") +
+

[PATCH] D111817: Fix a rejects-valid with consteval on overloaded operators

2021-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, rjmccall, erichkeane.
aaron.ballman requested review of this revision.
Herald added a project: clang.

It seems that Clang 11 regressed functionality that was working in Clang 10 
regarding calling a few overloaded operators in an immediate context. 
Specifically, we were not checking for immediate invocations of array 
subscripting and the arrow operators, but we properly handle the other 
overloaded operators.

This fixes the two problematic operators and adds some test coverage to show 
they're equivalent to calling the operator directly. This addresses PR50779.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111817

Files:
  clang/lib/Sema/SemaOverload.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
@@ -612,3 +612,27 @@
 static_assert(is_same::value);
 
 } // namespace unevaluated
+
+namespace PR50779 {
+struct derp {
+  int b = 0;
+};
+
+constexpr derp d;
+
+struct test {
+  consteval int operator[](int i) const { return {}; }
+  consteval const derp * operator->() const { return  }
+};
+
+constexpr test a;
+
+// We previously rejected both of these overloaded operators as taking the
+// address of a consteval function outside of an immediate context, but we
+// accepted direct calls to the overloaded operator. Now we show that we accept
+// both forms.
+constexpr int s = a.operator[](1);
+constexpr int t = a[1];
+constexpr int u = a.operator->()->b;
+constexpr int v = a->b;
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -14161,7 +14161,8 @@
   Method->getType()->castAs()))
   return ExprError();
 
-return MaybeBindToTemporary(TheCall);
+return CheckForImmediateInvocation(MaybeBindToTemporary(TheCall),
+   FnDecl);
   } else {
 // We matched a built-in operator. Convert the arguments, then
 // break out so that we will build the appropriate built-in
@@ -14916,7 +14917,7 @@
 Method->getType()->castAs()))
 return ExprError();
 
-  return MaybeBindToTemporary(TheCall);
+  return CheckForImmediateInvocation(MaybeBindToTemporary(TheCall), Method);
 }
 
 /// BuildLiteralOperatorCall - Build a UserDefinedLiteral by creating a call to


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -612,3 +612,27 @@
 static_assert(is_same::value);
 
 } // namespace unevaluated
+
+namespace PR50779 {
+struct derp {
+  int b = 0;
+};
+
+constexpr derp d;
+
+struct test {
+  consteval int operator[](int i) const { return {}; }
+  consteval const derp * operator->() const { return  }
+};
+
+constexpr test a;
+
+// We previously rejected both of these overloaded operators as taking the
+// address of a consteval function outside of an immediate context, but we
+// accepted direct calls to the overloaded operator. Now we show that we accept
+// both forms.
+constexpr int s = a.operator[](1);
+constexpr int t = a[1];
+constexpr int u = a.operator->()->b;
+constexpr int v = a->b;
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -14161,7 +14161,8 @@
   Method->getType()->castAs()))
   return ExprError();
 
-return MaybeBindToTemporary(TheCall);
+return CheckForImmediateInvocation(MaybeBindToTemporary(TheCall),
+   FnDecl);
   } else {
 // We matched a built-in operator. Convert the arguments, then
 // break out so that we will build the appropriate built-in
@@ -14916,7 +14917,7 @@
 Method->getType()->castAs()))
 return ExprError();
 
-  return MaybeBindToTemporary(TheCall);
+  return CheckForImmediateInvocation(MaybeBindToTemporary(TheCall), Method);
 }
 
 /// BuildLiteralOperatorCall - Build a UserDefinedLiteral by creating a call to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110663: [Driver] Support Debian multiarch style lib/clang/14.0.0/x86_64-linux-gnu runtime path and include/x86_64-linux-gnu/c++/v1 libc++ path

2021-10-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110663

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


[clang] f7ba572 - [RISCV] Update Zba, Zbb, Zbc, and Zbs version from 0.93 to 1.0.

2021-10-14 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2021-10-14T09:25:03-07:00
New Revision: f7ba572483dd424c6235901d1c6cb3650c46b477

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

LOG: [RISCV] Update Zba, Zbb, Zbc, and Zbs version from 0.93 to 1.0.

I've removed the Zbs W instructions that are not part of the frozen spec.

References to B as an extension name have been removed. Tests are updated or 
split accordingly.

Reviewed By: luismarques

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

Added: 


Modified: 
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/test/Driver/riscv-arch.c
clang/test/Preprocessor/riscv-target-features.c
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index fa56cddca2a2f..00da8cdaef0b5 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -182,13 +182,13 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
,
   }
 
   if (HasZba)
-Builder.defineMacro("__riscv_zba", "93000");
+Builder.defineMacro("__riscv_zba", "100");
 
   if (HasZbb)
-Builder.defineMacro("__riscv_zbb", "93000");
+Builder.defineMacro("__riscv_zbb", "100");
 
   if (HasZbc)
-Builder.defineMacro("__riscv_zbc", "93000");
+Builder.defineMacro("__riscv_zbc", "100");
 
   if (HasZbe)
 Builder.defineMacro("__riscv_zbe", "93000");
@@ -206,7 +206,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__riscv_zbr", "93000");
 
   if (HasZbs)
-Builder.defineMacro("__riscv_zbs", "93000");
+Builder.defineMacro("__riscv_zbs", "100");
 
   if (HasZbt)
 Builder.defineMacro("__riscv_zbt", "93000");

diff  --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index aff96d80f765e..a05b8a93a37b0 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -58,9 +58,10 @@ static StringRef getExtensionType(StringRef Ext) {
 // extension that the compiler currently supports.
 static Optional
 isExperimentalExtension(StringRef Ext) {
-  if (Ext == "zba" || Ext == "zbb" || Ext == "zbc" || Ext == "zbe" ||
-  Ext == "zbf" || Ext == "zbm" || Ext == "zbp" || Ext == "zbr" ||
-  Ext == "zbs" || Ext == "zbt")
+  if (Ext == "zba" || Ext == "zbb" || Ext == "zbc" || Ext == "zbs")
+return RISCVExtensionVersion{"1", "0"};
+  if (Ext == "zbe" || Ext == "zbf" || Ext == "zbm" || Ext == "zbp" ||
+  Ext == "zbr" || Ext == "zbt")
 return RISCVExtensionVersion{"0", "93"};
   if (Ext == "v" || Ext == "zvamo" || Ext == "zvlsseg")
 return RISCVExtensionVersion{"0", "10"};

diff  --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 269df87c2603f..e0afaa9e5351e 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -387,20 +387,20 @@
 // RV32-EXPERIMENTAL-ZBB-NOFLAG: error: invalid arch name 'rv32izbb'
 // RV32-EXPERIMENTAL-ZBB-NOFLAG: requires '-menable-experimental-extensions'
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p93 
-menable-experimental-extensions -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb1p0 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB %s
 // RV32-EXPERIMENTAL-ZBB: "-target-feature" "+experimental-zbb"
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p93_zbp0p93 
-menable-experimental-extensions -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb1p0_zbp0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP 
%s
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbb"
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbp"
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p93zbp0p93 
-menable-experimental-extensions -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb1p0zbp0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE %s
-// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb0p93zbp0p93', multi-character extensions must be separated by 
underscores
+// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb1p0zbp0p93', multi-character extensions must be separated by 
underscores
 
-// RUN: 

[PATCH] D110669: [RISCV] Update Zba, Zbb, Zbc, and Zbs version from 0.93 to 1.0.

2021-10-14 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf7ba572483dd: [RISCV] Update Zba, Zbb, Zbc, and Zbs version 
from 0.93 to 1.0. (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110669

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -40,13 +40,13 @@
 # CHECK: attribute  5, "rv32i2p0_v0p10"
 
 .attribute arch, "rv32izba"
-# CHECK: attribute  5, "rv32i2p0_zba0p93"
+# CHECK: attribute  5, "rv32i2p0_zba1p0"
 
 .attribute arch, "rv32izbb"
-# CHECK: attribute  5, "rv32i2p0_zbb0p93"
+# CHECK: attribute  5, "rv32i2p0_zbb1p0"
 
 .attribute arch, "rv32izbc"
-# CHECK: attribute  5, "rv32i2p0_zbc0p93"
+# CHECK: attribute  5, "rv32i2p0_zbc1p0"
 
 .attribute arch, "rv32izbe"
 # CHECK: attribute  5, "rv32i2p0_zbe0p93"
@@ -64,7 +64,7 @@
 # CHECK: attribute  5, "rv32i2p0_zbr0p93"
 
 .attribute arch, "rv32izbs"
-# CHECK: attribute  5, "rv32i2p0_zbs0p93"
+# CHECK: attribute  5, "rv32i2p0_zbs1p0"
 
 .attribute arch, "rv32izbt"
 # CHECK: attribute  5, "rv32i2p0_zbt0p93"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -44,17 +44,17 @@
 ; RV32C: .attribute 5, "rv32i2p0_c2p0"
 ; RV32V: .attribute 5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
 ; RV32ZFH: .attribute 5, "rv32i2p0_f2p0_zfh0p1"
-; RV32ZBA: .attribute 5, "rv32i2p0_zba0p93"
-; RV32ZBB: .attribute 5, "rv32i2p0_zbb0p93"
-; RV32ZBC: .attribute 5, "rv32i2p0_zbc0p93"
+; RV32ZBA: .attribute 5, "rv32i2p0_zba1p0"
+; RV32ZBB: .attribute 5, "rv32i2p0_zbb1p0"
+; RV32ZBC: .attribute 5, "rv32i2p0_zbc1p0"
 ; RV32ZBE: .attribute 5, "rv32i2p0_zbe0p93"
 ; RV32ZBF: .attribute 5, "rv32i2p0_zbf0p93"
 ; RV32ZBM: .attribute 5, "rv32i2p0_zbm0p93"
 ; RV32ZBP: .attribute 5, "rv32i2p0_zbp0p93"
 ; RV32ZBR: .attribute 5, "rv32i2p0_zbr0p93"
-; RV32ZBS: .attribute 5, "rv32i2p0_zbs0p93"
+; RV32ZBS: .attribute 5, "rv32i2p0_zbs1p0"
 ; RV32ZBT: .attribute 5, "rv32i2p0_zbt0p93"
-; RV32COMBINED: .attribute 5, "rv32i2p0_f2p0_v0p10_zfh0p1_zbb0p93_zvamo0p10_zvlsseg0p10"
+; RV32COMBINED: .attribute 5, "rv32i2p0_f2p0_v0p10_zfh0p1_zbb1p0_zvamo0p10_zvlsseg0p10"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64A: .attribute 5, "rv64i2p0_a2p0"
@@ -62,18 +62,18 @@
 ; RV64D: .attribute 5, "rv64i2p0_f2p0_d2p0"
 ; RV64C: .attribute 5, "rv64i2p0_c2p0"
 ; RV64ZFH: .attribute 5, "rv64i2p0_f2p0_zfh0p1"
-; RV64ZBA: .attribute 5, "rv64i2p0_zba0p93"
-; RV64ZBB: .attribute 5, "rv64i2p0_zbb0p93"
-; RV64ZBC: .attribute 5, "rv64i2p0_zbc0p93"
+; RV64ZBA: .attribute 5, "rv64i2p0_zba1p0"
+; RV64ZBB: .attribute 5, "rv64i2p0_zbb1p0"
+; RV64ZBC: .attribute 5, "rv64i2p0_zbc1p0"
 ; RV64ZBE: .attribute 5, "rv64i2p0_zbe0p93"
 ; RV64ZBF: .attribute 5, "rv64i2p0_zbf0p93"
 ; RV64ZBM: .attribute 5, "rv64i2p0_zbm0p93"
 ; RV64ZBP: .attribute 5, "rv64i2p0_zbp0p93"
 ; RV64ZBR: .attribute 5, "rv64i2p0_zbr0p93"
-; RV64ZBS: .attribute 5, "rv64i2p0_zbs0p93"
+; RV64ZBS: .attribute 5, "rv64i2p0_zbs1p0"
 ; RV64ZBT: .attribute 5, "rv64i2p0_zbt0p93"
 ; RV64V: .attribute 5, "rv64i2p0_v0p10_zvamo0p10_zvlsseg0p10"
-; RV64COMBINED: .attribute 5, "rv64i2p0_f2p0_v0p10_zfh0p1_zbb0p93_zvamo0p10_zvlsseg0p10"
+; RV64COMBINED: .attribute 5, "rv64i2p0_f2p0_v0p10_zfh0p1_zbb1p0_zvamo0p10_zvlsseg0p10"
 
 
 define i32 @addi(i32 %a) {
Index: llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
@@ -7,7 +7,17 @@
 //===--===//
 //
 // This file describes the RISC-V instructions from the standard Bitmanip
-// extensions, version 0.93.
+// extensions, versions:
+//   Zba - 1.0
+//   Zbb - 1.0
+//   Zbc - 1.0
+//   Zbs - 1.0
+//   Zbe - 0.93
+//   Zbf - 0.93
+//   Zbm - 0.93
+//   Zbp - 0.93
+//   Zbr - 0.93
+//   Zbt - 0.93
 // This version is still experimental as the Bitmanip extensions haven't been
 // ratified yet.
 //
@@ -485,15 +495,6 @@
 Sched<[WriteRotateReg32, ReadRotateReg32, ReadRotateReg32]>;
 } // Predicates = [HasStdExtZbbOrZbp, IsRV64]
 
-let Predicates = [HasStdExtZbs, IsRV64] in {
-// NOTE: These instructions have been removed from the 0.94 spec. 

[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-10-14 Thread Zakk Chen via Phabricator via cfe-commits
khchen added inline comments.



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2089
 else
   return Error(ValueExprLoc, "bad arch string " + Arch);
   }

maybe we could have a NFC patch later to add 
```
// Emit the arch string if needed.
if (!IsIntegerValue)
  getTargetStreamer().emitTextAttribute(Tag, ISAInfo->toString());
```
here to reuse `ISAInfo`, and remove 2098~2117 code.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

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


[PATCH] D111805: [Driver][NetBSD] Use T reference instead of getToolChain().getTriple().

2021-10-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: clang/lib/Driver/ToolChains/NetBSD.cpp:35
   const Driver  = ToolChain.getDriver();
+  const llvm::Triple  = ToolChain.getTriple();
 

Is there a specific reason to choose the name `T`? FWICS different drivers use 
different names but I think `Triple` is both more popular and more readable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111805

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


[PATCH] D111814: Fix consteval crash when transforming 'this' expressions

2021-10-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:14839
 
   if (!IsInstantiation)
 PopDeclContext();

so the only real change here is that `ExitFunctionBodyRAII` ends here, instead 
of the end of the function?  

I guess this SEEMS pretty innocuous, I don't know particularly what 
`PopFunctionScopeInfo` does well enough to know if this is going to cause 
problems, but I DO know at least the 14850+ doesn't need to have the function 
body in scope (and PopDeclContext seems like it doesn't do much?)...

I would think that anything after `PopDeclContext` would have a problem being 
in the function body anyway (that is, being in a 'function body' with a 
mismatched DeclContext seems wrong), so I'm reasonably convinced this is at 
least non-breaking.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111814

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


[PATCH] D111778: [WIP][X86] Update CPU_SPECIFIC list.

2021-10-14 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D111778#3064287 , @FreddyYe wrote:

> In D111778#3063891 , @erichkeane 
> wrote:
>
>> Supporting these types requires changes to the library so that we can check 
>> these, right?  Do you have the library changes for these as well?  The 
>> constants used to check for these features/etc needs to be present in the 
>> glibc library.
>
> Yes. It's highly related to the `ProcessorFeatures` I mentioned above. Does 
> the `library changes` refer to the compiler-rt/cpu_model.c? I think that 
> change depends on libgcc. For now libgcc has no strong will to update that 
> table.

Every feature gcc knows about should be in libgcc. The unfortunate problem now 
is that cpu_features2 in libgcc is an array thats size may be different with 
every version of gcc. Clang can’t know how big that array is without reading 
the libgcc.a symbol table at compile time. Without knowing the size we can’t 
access any bits past the first 32 bits of cpu_features2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111778

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


[PATCH] D110913: [analyzer][solver] Handle simplification to ConcreteInt

2021-10-14 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGac3edc5af099: [analyzer][solver] Handle simplification to 
ConcreteInt (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110913

Files:
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/solver-sym-simplification-concreteint.c

Index: clang/test/Analysis/solver-sym-simplification-concreteint.c
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-concreteint.c
@@ -0,0 +1,40 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -verify
+
+void clang_analyzer_warnIfReached();
+void clang_analyzer_eval();
+
+void test_simplification_to_concrete_int_infeasible(int b, int c) {
+  if (c + b != 0) // c + b == 0
+return;
+  if (b != 1) // b == 1  --> c + 1 == 0
+return;
+  if (c != 1) // c == 1  --> 1 + 1 == 0 contradiction
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+
+  // Keep the symbols and the constraints! alive.
+  (void)(b * c);
+  return;
+}
+
+void test_simplification_to_concrete_int_feasible(int b, int c) {
+  if (c + b != 0)
+return;
+  // c + b == 0
+  if (b != 1)
+return;
+  // b == 1   -->  c + 1 == 0
+  if (c != -1)
+return;
+  // c == -1  --> -1 + 1 == 0 OK
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_eval(c == -1);   // expected-warning{{TRUE}}
+
+  // Keep the symbols and the constraints! alive.
+  (void)(b * c);
+  return;
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -226,9 +226,13 @@
   }
 }
 
-SymbolRef simplify(ProgramStateRef State, SymbolRef Sym) {
+SVal simplifyToSVal(ProgramStateRef State, SymbolRef Sym) {
   SValBuilder  = State->getStateManager().getSValBuilder();
-  SVal SimplifiedVal = SVB.simplifySVal(State, SVB.makeSymbolVal(Sym));
+  return SVB.simplifySVal(State, SVB.makeSymbolVal(Sym));
+}
+
+SymbolRef simplify(ProgramStateRef State, SymbolRef Sym) {
+  SVal SimplifiedVal = simplifyToSVal(State, Sym);
   if (SymbolRef SimplifiedSym = SimplifiedVal.getAsSymbol())
 return SimplifiedSym;
   return Sym;
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2106,7 +2106,20 @@
ProgramStateRef State, EquivalenceClass Class) {
   SymbolSet ClassMembers = Class.getClassMembers(State);
   for (const SymbolRef  : ClassMembers) {
-SymbolRef SimplifiedMemberSym = ento::simplify(State, MemberSym);
+
+const SVal SimplifiedMemberVal = simplifyToSVal(State, MemberSym);
+const SymbolRef SimplifiedMemberSym = SimplifiedMemberVal.getAsSymbol();
+
+// The symbol is collapsed to a constant, check if the current State is
+// still feasible.
+if (const auto CI = SimplifiedMemberVal.getAs()) {
+  const llvm::APSInt  = CI->getValue();
+  const RangeSet *ClassConstraint = getConstraint(State, Class);
+  // We have found a contradiction.
+  if (ClassConstraint && !ClassConstraint->contains(SV))
+return nullptr;
+}
+
 if (SimplifiedMemberSym && MemberSym != SimplifiedMemberSym) {
   // The simplified symbol should be the member of the original Class,
   // however, it might be in another existing class at the moment. We
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
@@ -389,11 +389,22 @@
   static void computeAdjustment(SymbolRef , llvm::APSInt );
 };
 
-/// Try to simplify a given symbolic expression's associated value based on the
-/// constraints in State. This is needed because the Environment bindings are
-/// not getting updated when a new constraint is added to the State.
+/// Try to simplify a given symbolic expression based on the constraints in
+/// State. This is needed because the Environment bindings are not getting
+/// updated when a new constraint is added to the State. If the symbol 

[clang] ac3edc5 - [analyzer][solver] Handle simplification to ConcreteInt

2021-10-14 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2021-10-14T17:53:29+02:00
New Revision: ac3edc5af09947210d8f8d25ddd7e42379ef6454

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

LOG: [analyzer][solver] Handle simplification to ConcreteInt

The solver's symbol simplification mechanism was not able to handle cases
when a symbol is simplified to a concrete integer. This patch adds the
capability.

E.g., in the attached lit test case, the original symbol is `c + 1` and
it has a `[0, 0]` range associated with it. Then, a new condition `c == 0`
is assumed, so a new range constraint `[0, 0]` comes in for `c` and
simplification kicks in. `c + 1` becomes `0 + 1`, but the associated
range is `[0, 0]`, so now we are able to realize the contradiction.

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

Added: 
clang/test/Analysis/solver-sym-simplification-concreteint.c

Modified: 

clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
index c1d2b4665f1d3..599e4ec812a1b 100644
--- 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
+++ 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
@@ -389,11 +389,22 @@ class RangedConstraintManager : public 
SimpleConstraintManager {
   static void computeAdjustment(SymbolRef , llvm::APSInt );
 };
 
-/// Try to simplify a given symbolic expression's associated value based on the
-/// constraints in State. This is needed because the Environment bindings are
-/// not getting updated when a new constraint is added to the State.
+/// Try to simplify a given symbolic expression based on the constraints in
+/// State. This is needed because the Environment bindings are not getting
+/// updated when a new constraint is added to the State. If the symbol is
+/// simplified to a non-symbol (e.g. to a constant) then the original symbol
+/// is returned. We use this function in the family of assumeSymNE/EQ/LT/../GE
+/// functions where we can work only with symbols. Use the other function
+/// (simplifyToSVal) if you are interested in a simplification that may yield
+/// a concrete constant value.
 SymbolRef simplify(ProgramStateRef State, SymbolRef Sym);
 
+/// Try to simplify a given symbolic expression's associated `SVal` based on 
the
+/// constraints in State. This is very similar to `simplify`, but this function
+/// always returns the simplified SVal. The simplified SVal might be a single
+/// constant (i.e. `ConcreteInt`).
+SVal simplifyToSVal(ProgramStateRef State, SymbolRef Sym);
+
 } // namespace ento
 } // namespace clang
 

diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 8299486938850..d1113569c59db 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2106,7 +2106,20 @@ EquivalenceClass::simplify(SValBuilder , 
RangeSet::Factory ,
ProgramStateRef State, EquivalenceClass Class) {
   SymbolSet ClassMembers = Class.getClassMembers(State);
   for (const SymbolRef  : ClassMembers) {
-SymbolRef SimplifiedMemberSym = ento::simplify(State, MemberSym);
+
+const SVal SimplifiedMemberVal = simplifyToSVal(State, MemberSym);
+const SymbolRef SimplifiedMemberSym = SimplifiedMemberVal.getAsSymbol();
+
+// The symbol is collapsed to a constant, check if the current State is
+// still feasible.
+if (const auto CI = SimplifiedMemberVal.getAs()) {
+  const llvm::APSInt  = CI->getValue();
+  const RangeSet *ClassConstraint = getConstraint(State, Class);
+  // We have found a contradiction.
+  if (ClassConstraint && !ClassConstraint->contains(SV))
+return nullptr;
+}
+
 if (SimplifiedMemberSym && MemberSym != SimplifiedMemberSym) {
   // The simplified symbol should be the member of the original Class,
   // however, it might be in another existing class at the moment. We

diff  --git a/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
index d227c025fb203..80f3054a5a37f 100644
--- a/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -226,9 +226,13 @@ void RangedConstraintManager::computeAdjustment(SymbolRef 
,
   }
 }
 
-SymbolRef simplify(ProgramStateRef State, SymbolRef Sym) {
+SVal 

[PATCH] D111815: [clang-format] [PR42014,PR52021] don't let clang-format assert/crash when file being formatted is read-only/locked

2021-10-14 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: thakis, curdeius, HazardyKnusperkeks.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay requested review of this revision.

This is a bug which gets reported from time to time and we've had multiple 
attempts to fix it, but don't want to fix it by adding frontEnd to the mix.

D68554: [clang-format] Proposal for clang-format to give compiler style 
warnings 
D90121: clang-format: Add a consumer to diagnostics engine 

D69854: [clang-format] [RELAND] Remove the dependency on frontend 


This patch aim to find a trivial, but not that sophisticated way of emitting 
the error without the additional impact of adding libFrontEnd to clang-format.

See D90121: clang-format: Add a consumer to diagnostics engine 
 for analysis of why we don't want those 
previous attempts

We can now see this:

  $ clang-format -i test1.cpp
  clang-format error:unable to rename temporary 'test1.cpp-4e5b1ac5' to output 
file 'test1.cpp': 'permission denied'

Rather than

  Assertion failed: getClient() && "DiagnosticClient not set!", file 
C:\llvm-project\clang\lib\Basic\Diagnostic.cpp, line 522
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace.
  Stack dump:
  0.  Program arguments: C:\\build_ninja\\bin\\clang-format.exe -i test1.cpp
   #0 0x7ff63cd7244c (C:\build_ninja\bin\clang-format.exe+0x12244c)
   #1 0x7fff3db28e05 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xa8e05)
  ...
   #6 0x7fff3db3158f (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xb158f)
   #7 0x7ff63ce6d4ff (C:\build_ninja\bin\clang-format.exe+0x21d4ff)
   #8 0x7ff63ce7dcf6 (C:\build_ninja\bin\clang-format.exe+0x22dcf6)
  
  #17 0x7ff63d16457e (C:\build_ninja\bin\clang-format.exe+0x51457e)
  #18 0x7fff9b7f7034 (C:\WINDOWS\System32\KERNEL32.DLL+0x17034)
  #19 0x7fff9ce02651 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x52651)

Not sure how I can easily unit test this, as I had to use Excel to lock the 
file!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111815

Files:
  clang/tools/clang-format/ClangFormat.cpp


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -366,6 +366,18 @@
   outs() << "\n";
 }
 
+class ClangFormatDiagConsumer : public DiagnosticConsumer {
+  virtual void anchor() {}
+
+  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const Diagnostic ) override {
+
+SmallVector vec;
+Info.FormatDiagnostic(vec);
+errs() << "clang-format error:" << vec << "\n";
+  }
+};
+
 // Returns true on error.
 static bool format(StringRef FileName) {
   if (!OutputXML && Inplace && FileName == "-") {
@@ -477,9 +489,12 @@
 IntrusiveRefCntPtr InMemoryFileSystem(
 new llvm::vfs::InMemoryFileSystem);
 FileManager Files(FileSystemOptions(), InMemoryFileSystem);
+
+IntrusiveRefCntPtr DiagOpts(new DiagnosticOptions());
+ClangFormatDiagConsumer IgnoreDiagnostics;
 DiagnosticsEngine Diagnostics(
-IntrusiveRefCntPtr(new DiagnosticIDs),
-new DiagnosticOptions);
+IntrusiveRefCntPtr(new DiagnosticIDs), &*DiagOpts,
+, false);
 SourceManager Sources(Diagnostics, Files);
 FileID ID = createInMemoryFile(AssumedFileName, *Code, Sources, Files,
InMemoryFileSystem.get());


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -366,6 +366,18 @@
   outs() << "\n";
 }
 
+class ClangFormatDiagConsumer : public DiagnosticConsumer {
+  virtual void anchor() {}
+
+  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const Diagnostic ) override {
+
+SmallVector vec;
+Info.FormatDiagnostic(vec);
+errs() << "clang-format error:" << vec << "\n";
+  }
+};
+
 // Returns true on error.
 static bool format(StringRef FileName) {
   if (!OutputXML && Inplace && FileName == "-") {
@@ -477,9 +489,12 @@
 IntrusiveRefCntPtr InMemoryFileSystem(
 new llvm::vfs::InMemoryFileSystem);
 FileManager Files(FileSystemOptions(), InMemoryFileSystem);
+
+IntrusiveRefCntPtr DiagOpts(new DiagnosticOptions());
+ClangFormatDiagConsumer IgnoreDiagnostics;
 DiagnosticsEngine Diagnostics(
-IntrusiveRefCntPtr(new DiagnosticIDs),
-new DiagnosticOptions);
+IntrusiveRefCntPtr(new DiagnosticIDs), &*DiagOpts,
+, false);
 SourceManager Sources(Diagnostics, Files);
 FileID ID = createInMemoryFile(AssumedFileName, *Code, Sources, Files,

[PATCH] D111814: Fix consteval crash when transforming 'this' expressions

2021-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, rjmccall, erichkeane.
aaron.ballman requested review of this revision.
Herald added a project: clang.

When reaching the end of a function body, we need to ensure that the 
`ExitFunctionBodyRAII` object is destroyed before we pop the declaration 
context for the function. Exiting the function body causes us to handle 
immediate invocations, which involves template transformations that need to 
know the correct type for `this`.

This addresses PR48235.

(Note, the diff in Phrabricator looks more awful than it is in reality -- the 
only change to the code was to add a new compound scope, but indenting the 
contents of that new scope seems to make for confusing-looking diffs.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111814

Files:
  clang/lib/Sema/SemaDecl.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
@@ -612,3 +612,23 @@
 static_assert(is_same::value);
 
 } // namespace unevaluated
+
+namespace PR48235 {
+consteval int d() {
+  return 1;
+}
+
+struct A {
+  consteval int a() const { return 1; }
+
+  void b() {
+this->a() + d(); // expected-error {{call to consteval function 'PR48235::A::a' is not a constant expression}} \
+ // expected-note {{use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function}}
+  }
+
+  void c() {
+a() + d(); // expected-error {{call to consteval function 'PR48235::A::a' is not a constant expression}} \
+   // expected-note {{use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function}}
+  }
+};
+} // PR48235
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -14501,333 +14501,340 @@
   if (getLangOpts().Coroutines && FSI->isCoroutine())
 CheckCompletedCoroutineBody(FD, Body);
 
-  // Do not call PopExpressionEvaluationContext() if it is a lambda because one
-  // is already popped when finishing the lambda in BuildLambdaExpr(). This is
-  // meant to pop the context added in ActOnStartOfFunctionDef().
-  ExitFunctionBodyRAII ExitRAII(*this, isLambdaCallOperator(FD));
-
-  if (FD) {
-FD->setBody(Body);
-FD->setWillHaveBody(false);
-
-if (getLangOpts().CPlusPlus14) {
-  if (!FD->isInvalidDecl() && Body && !FD->isDependentContext() &&
-  FD->getReturnType()->isUndeducedType()) {
-// If the function has a deduced result type but contains no 'return'
-// statements, the result type as written must be exactly 'auto', and
-// the deduced result type is 'void'.
-if (!FD->getReturnType()->getAs()) {
-  Diag(dcl->getLocation(), diag::err_auto_fn_no_return_but_not_auto)
-  << FD->getReturnType();
-  FD->setInvalidDecl();
-} else {
-  // Substitute 'void' for the 'auto' in the type.
-  TypeLoc ResultType = getReturnTypeLoc(FD);
-  Context.adjustDeducedFunctionResultType(
-  FD, SubstAutoType(ResultType.getType(), Context.VoidTy));
+  {
+// Do not call PopExpressionEvaluationContext() if it is a lambda because
+// one is already popped when finishing the lambda in BuildLambdaExpr().
+// This is meant to pop the context added in ActOnStartOfFunctionDef().
+ExitFunctionBodyRAII ExitRAII(*this, isLambdaCallOperator(FD));
+
+if (FD) {
+  FD->setBody(Body);
+  FD->setWillHaveBody(false);
+
+  if (getLangOpts().CPlusPlus14) {
+if (!FD->isInvalidDecl() && Body && !FD->isDependentContext() &&
+FD->getReturnType()->isUndeducedType()) {
+  // If the function has a deduced result type but contains no 'return'
+  // statements, the result type as written must be exactly 'auto', and
+  // the deduced result type is 'void'.
+  if (!FD->getReturnType()->getAs()) {
+Diag(dcl->getLocation(), diag::err_auto_fn_no_return_but_not_auto)
+<< FD->getReturnType();
+FD->setInvalidDecl();
+  } else {
+// Substitute 'void' for the 'auto' in the type.
+TypeLoc ResultType = getReturnTypeLoc(FD);
+Context.adjustDeducedFunctionResultType(
+FD, SubstAutoType(ResultType.getType(), Context.VoidTy));
+  }
+}
+  } else if (getLangOpts().CPlusPlus11 && isLambdaCallOperator(FD)) {
+// In C++11, we don't use 'auto' deduction rules for lambda call
+// operators because we don't support return type deduction.
+auto *LSI = getCurLambda();
+if (LSI->HasImplicitReturnType) {
+  deduceClosureReturnType(*LSI);
+
+  // C++11 

[PATCH] D111778: [WIP][X86] Update CPU_SPECIFIC list.

2021-10-14 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

In D111778#3063891 , @erichkeane 
wrote:

> Supporting these types requires changes to the library so that we can check 
> these, right?  Do you have the library changes for these as well?  The 
> constants used to check for these features/etc needs to be present in the 
> glibc library.

Yes. It's highly related to the `ProcessorFeatures` I mentioned above. Does the 
`library changes` refer to the compiler-rt/cpu_model.c? I think that change 
depends on libgcc. For now libgcc has no strong will to update that table.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111778

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


[PATCH] D111734: [HIP] Relax conditions for address space cast in builtin args

2021-10-14 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 added a comment.

Passed internal CI, still working on a Sema test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111734

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


[PATCH] D111468: [clang] Capture Framework when HeaderSearch is resolved via headermap

2021-10-14 Thread Cyndy Ishida via Phabricator via cfe-commits
cishida updated this revision to Diff 379721.
cishida added a comment.

Fix windows build.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111468

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/unittests/Lex/HeaderSearchTest.cpp

Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -18,6 +18,7 @@
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Serialization/InMemoryModuleCache.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -47,7 +48,8 @@
   }
 
   void addHeaderMap(llvm::StringRef Filename,
-std::unique_ptr Buf) {
+std::unique_ptr Buf,
+bool isAngled = false) {
 VFS->addFile(Filename, 0, std::move(Buf), /*User=*/None, /*Group=*/None,
  llvm::sys::fs::file_type::regular_file);
 auto FE = FileMgr.getFile(Filename, true);
@@ -58,7 +60,7 @@
 HMap = HeaderMap::Create(*FE, FileMgr);
 auto DL =
 DirectoryLookup(HMap.get(), SrcMgr::C_User, /*isFramework=*/false);
-Search.AddSearchPath(DL, /*isAngled=*/false);
+Search.AddSearchPath(DL, isAngled);
   }
 
   IntrusiveRefCntPtr VFS;
@@ -179,5 +181,48 @@
 "d.h");
 }
 
+TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) {
+  typedef NullTerminatedFile, char> FileTy;
+  FileTy File;
+  File.init();
+
+  std::string HeaderDirName = "/tmp/Sources/Foo/Headers/";
+  std::string HeaderName = "Foo.h";
+#ifdef _WIN32
+  // Force header path to be absolute on windows.
+  // As headermap content should represent absolute locations.
+  HeaderDirName = "C:" + HeaderDirName;
+#endif /*_WIN32*/
+
+  test::HMapFileMockMaker Maker(File);
+  auto a = Maker.addString("Foo/Foo.h");
+  auto b = Maker.addString(HeaderDirName);
+  auto c = Maker.addString(HeaderName);
+  Maker.addBucket("Foo/Foo.h", a, b, c);
+  addHeaderMap("product-headers.hmap", File.getBuffer(), /*isAngled=*/true);
+
+  VFS->addFile(
+  HeaderDirName + HeaderName, 0,
+  llvm::MemoryBuffer::getMemBufferCopy("", HeaderDirName + HeaderName),
+  /*User=*/None, /*Group=*/None, llvm::sys::fs::file_type::regular_file);
+
+  bool IsMapped = false;
+  const DirectoryLookup *CurDir = nullptr;
+  auto FoundFile = Search.LookupFile(
+  "Foo/Foo.h", SourceLocation(), /*isAngled=*/true, /*FromDir=*/nullptr,
+  CurDir, /*Includers=*/{}, /*SearchPath=*/nullptr,
+  /*RelativePath=*/nullptr, /*RequestingModule=*/nullptr,
+  /*SuggestedModule=*/nullptr, ,
+  /*IsFrameworkFound=*/nullptr);
+
+  EXPECT_TRUE(FoundFile.hasValue());
+  EXPECT_TRUE(IsMapped);
+  auto  = FoundFile.getValue();
+  auto FI = Search.getExistingFileInfo(FE);
+  EXPECT_TRUE(FI);
+  EXPECT_TRUE(FI->IsValid);
+  EXPECT_EQ(FI->Framework.str(), "Foo");
+}
+
 } // namespace
 } // namespace clang
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1005,13 +1005,13 @@
 
 // If this file is found in a header map and uses the framework style of
 // includes, then this header is part of a framework we're building.
-if (CurDir->isIndexHeaderMap()) {
+if (CurDir->isHeaderMap() && isAngled) {
   size_t SlashPos = Filename.find('/');
-  if (SlashPos != StringRef::npos) {
+  if (SlashPos != StringRef::npos)
+HFI.Framework =
+getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos));
+  if (CurDir->isIndexHeaderMap())
 HFI.IndexHeaderMapHeader = 1;
-HFI.Framework = getUniqueFrameworkName(StringRef(Filename.begin(),
- SlashPos));
-  }
 }
 
 if (checkMSVCHeaderSearch(Diags, MSFE ? >getFileEntry() : nullptr,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90121: clang-format: Add a consumer to diagnostics engine

2021-10-14 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

@thakis , At the back of my mind is those people who always say "Measure, 
Measure, Measure"...

This issue still plagues us, we constantly get bugs reported that come back to 
this.  
(https://bugs.llvm.org/show_bug.cgi?id=52021,https://bugs.llvm.org/show_bug.cgi?id=42014)

So I decided I should look into the concerns with us fixing this issue.

I decided to do 3 tests:

- a) Build current tip of main
- b) Apply this FrontEnd fix
- c) Move TextDiagnosticPrinter (and dependencies) into lib/Basic

I took a look and in its simplest form moving TextDiagnosticPrinter.cpp to 
lib/Basic but also requires DiagnosticRender.cpp and TextDiagnostic.cpp to also 
move to lib/Basic too,

But DiagnosticRender.cpp has a dependency on lib/Edit so clang-format now needs 
that as a dependency, is that better/worse than having a dependency on 
lib/FrontEnd? (not sure why I don't have to provide "Edit" as a dependency when 
including FrontEnd!)

For each test, I want to check

- a) size of the executable produced (debug/release)
- b) number of build dependencies (from ninja after ninja clean)

The size of the executable I assume is a concern as this impacts the runtime of 
clang-format as the system loads the module,
The number of build dependencies comes down to how quickly developers working 
on clang-format can rebuild.

I'm not concerning myself with the final "link" time of clang-format, as its 
relatively trivial on a modern machine, and nothing in comparison to building 
from clean.

Firstly I think we should recognize that this "crash" against a read-only file 
IS a problem that most of us will see from time to time and at best
its annoying. So I think there is enough momentum for us to have a solution of 
one sort of another.

**Build speeds**

Build speeds are important if you are a LLVM developer as you don't really want 
to have to keep rebuilding, I personally use ninja on Windows
having given up using vs projects generated by cmake years ago as being way too 
slow in the first place.

Ninja will give me the number of "targets" needed to compile, rather than 
timing it, I'll simply work on the assumption that "less is best"

  $ ninja clang-format
  [698/1298] Building CXX object 
lib\Object\CMakeFiles\LLVMObject.dir\SymbolicFile.cpp.obj

Before building each of the targets I perform a "ninja clean" so that hopefully 
the build that follows shows me how many targets I needed

1. Using the current tip of master, the number of targets to build clang-format 
sits at 608
2. If I apply this FrontEnd patch D90121: clang-format: Add a consumer to 
diagnostics engine  it rises to `1352`

3 )If I apply a patch that moves just 
`TextDiagnosticPrinter/TextDiagnostic/DiagnosticRender` into `lib/Basic` then 
the number is `1298`

**Executable Size**

For Completeness I built both Debug and Release (mainly because I live in Debug 
as I work on clang-format, but the releases are Release (i assume))

**Debug (clang-format)**

For Debug there seems no benefit for moving the code out of FrontEnd into Basic

  -rwxr-xr-x 1  17425920 Oct 14 14:48 clang-format-frontend.exe   (Debug)
  -rwxr-xr-x 1  17425920 Oct 14 14:40 clang-format.basic.exe (Debug)
  -rwxr-xr-x 1  17171968 Oct 14 14:44 clang-format.original.exe (Debug)

The modified debug binaries are only 1.5% larger.

**Release (clang-format)**

For Release the Basic version was actually larger.

  -rwxr-xr-x 1   2601472 Oct 14 15:17 clang-format-release.basic.exe   (Release)
  -rwxr-xr-x 1   2600960 Oct 14 15:12 clang-format-release-frontend.exe 
(Release)
  -rwxr-xr-x 1   2041344 Oct 14 15:14 clang-format-release.orginal.exe (Release)

With both Basic and FrontEnd release binaries being `~27%` larger.

**Conclusion**

This bug is annoying.

1. I just don't think an approach that moves the files into Basic is the 
solution.



- a) It requires multiple CMakeFile changes
- b) We have to leave header stubs lying around (or fix all the other tools 
that might include them and that is ugly)
- c) The binary is actually larger (go figure!)
- d) The number of files to be build is 213% as many as not having this fix, 
even if its ~10% less than the frontend fix (thats not worth the difference)



2. Frontend fix is the simplest solution (and has been sent for review at least 
3 times that I can find)



- a) Its slightly annoying because I keep having to defend why we don't want to 
fix it!
- b) Its 222% more files during the build cycle (however we don't build clean 
every time when building clang-format) so for a clang-format developer the 
impact is likely minimal
- c) The binaries are larger, less than the basic but still ~27% larger (which 
one could see as causing a slowdown on startup, although I have not measured 
that)

I'm kind of the opinion that we should resolve the crash before worrying about 
binary size aspect. Like I said I primarily use debug builds of clang-format
even during my working day so that I am 

[PATCH] D109825: [AArch64]Enabling Cortex-A510 Support

2021-10-14 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.
This revision is now accepted and ready to land.

Thanks for the changes. Nice working pulling this into shape.

LGTM




Comment at: llvm/include/llvm/Support/AArch64TargetParser.def:149
+ (AArch64::AEK_BF16 | AArch64::AEK_I8MM | 
AArch64::AEK_SVE2BITPERM |
+  AArch64::AEK_PAUTH | AArch64::AEK_PAUTH | AArch64::AEK_MTE |
+  AArch64::AEK_SSBS | AArch64::AEK_SB | AArch64::AEK_FP16FML))

dmgreen wrote:
> AEK_PAUTH is twice here.
Can you make sure you remove the second PAUTH here before committing.


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

https://reviews.llvm.org/D109825

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


[PATCH] D109825: [AArch64]Enabling Cortex-A510 Support

2021-10-14 Thread Mubashar Ahmad via Phabricator via cfe-commits
mubashar_ marked an inline comment as done.
mubashar_ added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:86
 
+- Support has been added for the following processors (command-line 
identifiers in parentheses):
+  - Arm Cortex-A510 (cortex-a510)

dmgreen wrote:
> dmgreen wrote:
> > Can you add an Arm section below and move this to it.
> This still needs doing. Also please add a line to the arm section saying 
> "Added support for the Armv9-A, Armv9.1-A and Armv9.2-A architectures."
> 
> It looks like there are some llvm release notes in llvm/docs/ReleaseNotes.rst 
> too, that could have a line added.
I didn't add support for these architectures. This may already be in its own 
commit.


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

https://reviews.llvm.org/D109825

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


[PATCH] D109825: [AArch64]Enabling Cortex-A510 Support

2021-10-14 Thread Mubashar Ahmad via Phabricator via cfe-commits
mubashar_ updated this revision to Diff 379717.
mubashar_ marked an inline comment as done.
mubashar_ added a comment.

Corrected PAUTH duplication mistake.


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

https://reviews.llvm.org/D109825

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Driver/aarch64-cpus.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -898,6 +898,17 @@
  AArch64::AEK_RDM | AArch64::AEK_FP16 |
  AArch64::AEK_DOTPROD | AArch64::AEK_RCPC,
  "8.2-A"),
+ARMCPUTestParams("cortex-a510", "armv9-a", "neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_FP |
+ AArch64::AEK_SIMD | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | AArch64::AEK_RDM |
+ AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+ AArch64::AEK_SVE2 | AArch64::AEK_BF16 |
+ AArch64::AEK_I8MM | AArch64::AEK_SVE2BITPERM |
+ AArch64::AEK_PAUTH | AArch64::AEK_MTE |
+ AArch64::AEK_SSBS | AArch64::AEK_FP16FML |
+ AArch64::AEK_SB,
+ "9-A"),
 ARMCPUTestParams("cortex-a57", "armv8-a", "crypto-neon-fp-armv8",
  AArch64::AEK_CRC | AArch64::AEK_CRYPTO |
  AArch64::AEK_FP | AArch64::AEK_SIMD,
@@ -1178,7 +1189,7 @@
  AArch64::AEK_LSE | AArch64::AEK_RDM,
  "8.2-A")));
 
-static constexpr unsigned NumAArch64CPUArchs = 48;
+static constexpr unsigned NumAArch64CPUArchs = 49;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/AArch64/AArch64Subtarget.h
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -50,6 +50,7 @@
 CortexA35,
 CortexA53,
 CortexA55,
+CortexA510,
 CortexA57,
 CortexA65,
 CortexA72,
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -78,6 +78,7 @@
 break;
   case CortexA53:
   case CortexA55:
+  case CortexA510:
 PrefFunctionLogAlignment = 4;
 break;
   case CortexA57:
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -630,6 +630,22 @@
FeatureFuseAddress,
]>;
 
+def ProcA510: SubtargetFeature<"a510", "ARMProcFamily", "CortexA510",
+   "Cortex-A510 ARM processors", [
+   HasV9_0aOps,
+   FeatureNEON,
+   FeaturePerfMon,
+   FeatureMatMulInt8,
+   FeatureBF16,
+   FeatureAM,
+   FeatureMTE,
+   FeatureETE,
+   FeatureSVE2BitPerm,
+   FeatureFP16FML,
+   FeatureFuseAES,
+   FeaturePostRAScheduler
+   ]>;
+
 def ProcA57 : SubtargetFeature<"a57", "ARMProcFamily", "CortexA57",
"Cortex-A57 ARM processors", [
FeatureBalanceFPOps,
@@ -1186,6 +1202,7 @@
 def : ProcessorModel<"cortex-a34", CortexA53Model, [ProcA35]>;
 def : ProcessorModel<"cortex-a53", CortexA53Model, [ProcA53]>;
 def : ProcessorModel<"cortex-a55", CortexA55Model, [ProcA55]>;
+def : ProcessorModel<"cortex-a510", CortexA55Model, [ProcA510]>;
 def : ProcessorModel<"cortex-a57", CortexA57Model, [ProcA57]>;
 def : ProcessorModel<"cortex-a65", CortexA53Model, [ProcA65]>;
 def : ProcessorModel<"cortex-a65ae", CortexA53Model, [ProcA65]>;
Index: llvm/include/llvm/Support/AArch64TargetParser.def
===
--- llvm/include/llvm/Support/AArch64TargetParser.def
+++ llvm/include/llvm/Support/AArch64TargetParser.def
@@ -144,6 +144,10 @@
  (AArch64::AEK_CRC))
 

[PATCH] D110641: Implement P0857R0 -Part B: requires clause for template-template params

2021-10-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Ping!  Does anyone have any feedback on this?  I'd really like to start getting 
us caught up on standards implementation, and this seems like it might be an 
easy win (unless someone on the list knows why it is just plain wrong/more 
complicated than I think!).


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

https://reviews.llvm.org/D110641

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


[PATCH] D109825: [AArch64]Enabling Cortex-A510 Support

2021-10-14 Thread Mubashar Ahmad via Phabricator via cfe-commits
mubashar_ updated this revision to Diff 379713.
mubashar_ marked 2 inline comments as done.
mubashar_ added a comment.

Added crypto and no-crypto tests for -mcpu and added new section for Arm and 
AArch64 support in release notes.


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

https://reviews.llvm.org/D109825

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Driver/aarch64-cpus.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -898,6 +898,17 @@
  AArch64::AEK_RDM | AArch64::AEK_FP16 |
  AArch64::AEK_DOTPROD | AArch64::AEK_RCPC,
  "8.2-A"),
+ARMCPUTestParams("cortex-a510", "armv9-a", "neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_FP |
+ AArch64::AEK_SIMD | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | AArch64::AEK_RDM |
+ AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+ AArch64::AEK_SVE2 | AArch64::AEK_BF16 |
+ AArch64::AEK_I8MM | AArch64::AEK_SVE2BITPERM |
+ AArch64::AEK_PAUTH | AArch64::AEK_MTE |
+ AArch64::AEK_SSBS | AArch64::AEK_FP16FML |
+ AArch64::AEK_SB,
+ "9-A"),
 ARMCPUTestParams("cortex-a57", "armv8-a", "crypto-neon-fp-armv8",
  AArch64::AEK_CRC | AArch64::AEK_CRYPTO |
  AArch64::AEK_FP | AArch64::AEK_SIMD,
@@ -1178,7 +1189,7 @@
  AArch64::AEK_LSE | AArch64::AEK_RDM,
  "8.2-A")));
 
-static constexpr unsigned NumAArch64CPUArchs = 48;
+static constexpr unsigned NumAArch64CPUArchs = 49;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/AArch64/AArch64Subtarget.h
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -50,6 +50,7 @@
 CortexA35,
 CortexA53,
 CortexA55,
+CortexA510,
 CortexA57,
 CortexA65,
 CortexA72,
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -78,6 +78,7 @@
 break;
   case CortexA53:
   case CortexA55:
+  case CortexA510:
 PrefFunctionLogAlignment = 4;
 break;
   case CortexA57:
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -630,6 +630,22 @@
FeatureFuseAddress,
]>;
 
+def ProcA510: SubtargetFeature<"a510", "ARMProcFamily", "CortexA510",
+   "Cortex-A510 ARM processors", [
+   HasV9_0aOps,
+   FeatureNEON,
+   FeaturePerfMon,
+   FeatureMatMulInt8,
+   FeatureBF16,
+   FeatureAM,
+   FeatureMTE,
+   FeatureETE,
+   FeatureSVE2BitPerm,
+   FeatureFP16FML,
+   FeatureFuseAES,
+   FeaturePostRAScheduler
+   ]>;
+
 def ProcA57 : SubtargetFeature<"a57", "ARMProcFamily", "CortexA57",
"Cortex-A57 ARM processors", [
FeatureBalanceFPOps,
@@ -1186,6 +1202,7 @@
 def : ProcessorModel<"cortex-a34", CortexA53Model, [ProcA35]>;
 def : ProcessorModel<"cortex-a53", CortexA53Model, [ProcA53]>;
 def : ProcessorModel<"cortex-a55", CortexA55Model, [ProcA55]>;
+def : ProcessorModel<"cortex-a510", CortexA55Model, [ProcA510]>;
 def : ProcessorModel<"cortex-a57", CortexA57Model, [ProcA57]>;
 def : ProcessorModel<"cortex-a65", CortexA53Model, [ProcA65]>;
 def : ProcessorModel<"cortex-a65ae", CortexA53Model, [ProcA65]>;
Index: llvm/include/llvm/Support/AArch64TargetParser.def
===
--- llvm/include/llvm/Support/AArch64TargetParser.def
+++ 

[PATCH] D107769: [OpenCL] Make generic addrspace optional for -fdeclare-opencl-builtins

2021-10-14 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

In D107769#2967565 , @Anastasia wrote:

> In D107769#2960441 , @svenvh wrote:
>
>> I have done an alternative spin of this patch: instead of introducing 
>> `RequireDisabledExtension`, simply always make the `private`, `global`, and 
>> `local` overloads available.  This makes tablegen diverge from `opencl-c.h` 
>> though.  Perhaps we should also always add make the `private`, `global`, and 
>> `local` overloads available in `opencl-c.h`?
>
> Yes, we could do this indeed as a clang extension. I don't think this will 
> impact the user code. However, this means vendors will have to add 
> definitions for extra overloads in OpenCL 2.0 mode?

I wonder if making the `private`, `global`, and `local` overloads always 
available would even be considered an extension.  Unless I overlooked 
something, I cannot find anything in the spec saying that the `private`, 
`global`, and `local` overloads should **not** be available when a `generic` 
overload is available (even though this is what Clang has always done)?

Making all overloads always available in e.g. CL2.0 mode will indeed affect the 
generated calls, which means the definitions should be available when consuming 
the generated IR.


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

https://reviews.llvm.org/D107769

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


[PATCH] D111443: [Driver] Fix ToolChain::getSanitizerArgs

2021-10-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D111443#3062139 , @eugenis wrote:

> Right, but a cache for SanitizerArgs is not enough to avoid repeated 
> diagnostics, is it? Ex. if I request a non-existing sanitizer, I think I 
> would get errors from host arg parsing, as well as from each of device1 and 
> device2, because each device will have a unique ArgList.
>
> Is it even possible for the driver to introduce new diagnostics in offload 
> SanitizerArgs parsing? Is it possible to catch those cases ahead of time, 
> when parsing SanitizerArgs for the first time, by looking at a target triple 
> or something? That would be the most user friendly approach.

I think it makes sense to assume offloading toolchain will not introduce extra 
diagnostics inside SanitizerArgs than the default toolchain, therefore it 
should be OK to let the default toolchain check sanitizer args for once. I will 
try make that change.


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

https://reviews.llvm.org/D111443

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


[PATCH] D111805: [Driver][NetBSD] Use T reference instead of getToolChain().getTriple().

2021-10-14 Thread Frederic Cambus via Phabricator via cfe-commits
fcambus created this revision.
fcambus added reviewers: krytarowski, mgorny.
Herald added a subscriber: fedor.sergeev.
fcambus requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111805

Files:
  clang/lib/Driver/ToolChains/NetBSD.cpp


Index: clang/lib/Driver/ToolChains/NetBSD.cpp
===
--- clang/lib/Driver/ToolChains/NetBSD.cpp
+++ clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -32,6 +32,7 @@
   const toolchains::NetBSD  =
 static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
+  const llvm::Triple  = ToolChain.getTriple();
 
   claimNoWarnArgs(Args);
   ArgStringList CmdArgs;
@@ -49,7 +50,7 @@
 StringRef MArch, MCPU;
 arm::getARMArchCPUFromArgs(Args, MArch, MCPU, /*FromAs*/ true);
 std::string Arch =
-arm::getARMTargetCPU(MCPU, MArch, ToolChain.getTriple());
+arm::getARMTargetCPU(MCPU, MArch, T);
 CmdArgs.push_back(Args.MakeArgString("-mcpu=" + Arch));
 break;
   }
@@ -60,7 +61,7 @@
   case llvm::Triple::mips64el: {
 StringRef CPUName;
 StringRef ABIName;
-mips::getMipsCPUAndABI(Args, ToolChain.getTriple(), CPUName, ABIName);
+mips::getMipsCPUAndABI(Args, T, CPUName, ABIName);
 
 CmdArgs.push_back("-march");
 CmdArgs.push_back(CPUName.data());
@@ -68,7 +69,7 @@
 CmdArgs.push_back("-mabi");
 CmdArgs.push_back(mips::getGnuCompatibleMipsABIName(ABIName).data());
 
-if (ToolChain.getTriple().isLittleEndian())
+if (T.isLittleEndian())
   CmdArgs.push_back("-EL");
 else
   CmdArgs.push_back("-EB");
@@ -80,18 +81,16 @@
   case llvm::Triple::sparc:
   case llvm::Triple::sparcel: {
 CmdArgs.push_back("-32");
-std::string CPU = getCPUName(D, Args, ToolChain.getTriple());
-CmdArgs.push_back(
-sparc::getSparcAsmModeForCPU(CPU, ToolChain.getTriple()));
+std::string CPU = getCPUName(D, Args, T);
+CmdArgs.push_back(sparc::getSparcAsmModeForCPU(CPU, T));
 AddAssemblerKPIC(ToolChain, Args, CmdArgs);
 break;
   }
 
   case llvm::Triple::sparcv9: {
 CmdArgs.push_back("-64");
-std::string CPU = getCPUName(D, Args, ToolChain.getTriple());
-CmdArgs.push_back(
-sparc::getSparcAsmModeForCPU(CPU, ToolChain.getTriple()));
+std::string CPU = getCPUName(D, Args, T);
+CmdArgs.push_back(sparc::getSparcAsmModeForCPU(CPU, T));
 AddAssemblerKPIC(ToolChain, Args, CmdArgs);
 break;
   }
@@ -122,6 +121,8 @@
   const toolchains::NetBSD  =
 static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
+  const llvm::Triple  = ToolChain.getTriple();
+
   ArgStringList CmdArgs;
 
   if (!D.SysRoot.empty())
@@ -156,7 +157,7 @@
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
 CmdArgs.push_back("-m");
-switch (ToolChain.getTriple().getEnvironment()) {
+switch (T.getEnvironment()) {
 case llvm::Triple::EABI:
 case llvm::Triple::GNUEABI:
   CmdArgs.push_back("armelf_nbsd_eabi");
@@ -174,7 +175,7 @@
   case llvm::Triple::thumbeb:
 arm::appendBE8LinkFlag(Args, CmdArgs, ToolChain.getEffectiveTriple());
 CmdArgs.push_back("-m");
-switch (ToolChain.getTriple().getEnvironment()) {
+switch (T.getEnvironment()) {
 case llvm::Triple::EABI:
 case llvm::Triple::GNUEABI:
   CmdArgs.push_back("armelfb_nbsd_eabi");
@@ -271,7 +272,7 @@
   }
 
   unsigned Major, Minor, Micro;
-  ToolChain.getTriple().getOSVersion(Major, Minor, Micro);
+  T.getOSVersion(Major, Minor, Micro);
   bool useLibgcc = true;
   if (Major >= 7 || Major == 0) {
 switch (ToolChain.getArch()) {


Index: clang/lib/Driver/ToolChains/NetBSD.cpp
===
--- clang/lib/Driver/ToolChains/NetBSD.cpp
+++ clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -32,6 +32,7 @@
   const toolchains::NetBSD  =
 static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
+  const llvm::Triple  = ToolChain.getTriple();
 
   claimNoWarnArgs(Args);
   ArgStringList CmdArgs;
@@ -49,7 +50,7 @@
 StringRef MArch, MCPU;
 arm::getARMArchCPUFromArgs(Args, MArch, MCPU, /*FromAs*/ true);
 std::string Arch =
-arm::getARMTargetCPU(MCPU, MArch, ToolChain.getTriple());
+arm::getARMTargetCPU(MCPU, MArch, T);
 CmdArgs.push_back(Args.MakeArgString("-mcpu=" + Arch));
 break;
   }
@@ -60,7 +61,7 @@
   case llvm::Triple::mips64el: {
 StringRef CPUName;
 StringRef ABIName;
-mips::getMipsCPUAndABI(Args, ToolChain.getTriple(), CPUName, ABIName);
+mips::getMipsCPUAndABI(Args, T, CPUName, ABIName);
 
 CmdArgs.push_back("-march");
 CmdArgs.push_back(CPUName.data());
@@ -68,7 +69,7 @@
 CmdArgs.push_back("-mabi");
 CmdArgs.push_back(mips::getGnuCompatibleMipsABIName(ABIName).data());
 
-if (ToolChain.getTriple().isLittleEndian())
+if (T.isLittleEndian())
   

[PATCH] D111790: [AArch64][Driver][SVE] Allow -msve-vector-bits=+ syntax to mean no maximum vscale

2021-10-14 Thread Bradley Smith via Phabricator via cfe-commits
bsmith updated this revision to Diff 379701.
bsmith added a comment.

- Remove mention of 128-bit chunks from help texts
- Allow any positive integer value for -mvscale-{min,max}, not just powers of 2


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111790

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp
  clang/test/CodeGen/aarch64-sve-vector-bits-codegen.c
  clang/test/CodeGen/arm-sve-vector-bits-vscale-range.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-call.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
  clang/test/CodeGenCXX/aarch64-mangle-sve-fixed-vectors.cpp
  clang/test/CodeGenCXX/aarch64-sve-fixedtypeinfo.cpp
  clang/test/Driver/aarch64-sve-vector-bits.c
  clang/test/Sema/aarch64-sve-explicit-casts-fixed-size.c
  clang/test/Sema/aarch64-sve-lax-vector-conversions.c
  clang/test/Sema/attr-arm-sve-vector-bits.c
  clang/test/SemaCXX/aarch64-sve-explicit-casts-fixed-size.cpp
  clang/test/SemaCXX/aarch64-sve-lax-vector-conversions.cpp
  clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp

Index: clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
===
--- clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
+++ clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns -Wconversion %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 -mvscale-min=4 -mvscale-max=4 -fallow-half-arguments-and-returns -Wconversion %s
 // expected-no-diagnostics
 
 #include 
Index: clang/test/SemaCXX/aarch64-sve-lax-vector-conversions.cpp
===
--- clang/test/SemaCXX/aarch64-sve-lax-vector-conversions.cpp
+++ clang/test/SemaCXX/aarch64-sve-lax-vector-conversions.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=none -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-none %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=integer -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-integer %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=all -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-all %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -mvscale-min=4 -mvscale-max=4 -flax-vector-conversions=none -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-none %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -mvscale-min=4 -mvscale-max=4 -flax-vector-conversions=integer -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-integer %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -mvscale-min=4 -mvscale-max=4 -flax-vector-conversions=all -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify=lax-vector-all %s
 
 #include 
 
Index: clang/test/SemaCXX/aarch64-sve-explicit-casts-fixed-size.cpp
===
--- clang/test/SemaCXX/aarch64-sve-explicit-casts-fixed-size.cpp
+++ clang/test/SemaCXX/aarch64-sve-explicit-casts-fixed-size.cpp
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=128 -flax-vector-conversions=none -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=256 -flax-vector-conversions=none -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=512 -flax-vector-conversions=none -fallow-half-arguments-and-returns -ffreestanding -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -msve-vector-bits=1024 -flax-vector-conversions=none 

[PATCH] D111642: [Analyzer][solver] Simplification: reorganize equalities with adjustment

2021-10-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:2126-2130
+  // Initiate the reorganization of the equality information. E.g., if we
+  // have `c + 1 == 0` then we'd like to express that `c == -1`. It makes
+  // sense to do this only with `SymIntExpr`s.
+  // TODO Handle `IntSymExpr` as well, once computeAdjustment can handle
+  // them.

Can the simplification of a `SymSymExpr` result in `IntSymExpr`? If it can 
happen, then we could see such instances and we should do the right thing with 
them as well.
WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111642

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


  1   2   >