[PATCH] D139302: [RISCV] Add Syntacore SCR1 CPU model

2022-12-06 Thread Dmitrii Petrov via Phabricator via cfe-commits
dnpetrov-sc updated this revision to Diff 480352.
dnpetrov-sc edited the summary of this revision.
dnpetrov-sc added a comment.

- fixed new line at end-of-file in RISCVSchedSCR1.td;
- dropped scr1-min (RV32E unsupported).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139302

Files:
  clang/test/Driver/riscv-cpus.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/include/llvm/Support/RISCVTargetParser.def
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSchedSCR1.td

Index: llvm/lib/Target/RISCV/RISCVSchedSCR1.td
===
--- /dev/null
+++ llvm/lib/Target/RISCV/RISCVSchedSCR1.td
@@ -0,0 +1,207 @@
+//==- RISCVSchedSCR1.td - SCR1 Scheduling Definitions *- tablegen -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+
+// SCR1: https://github.com/syntacore/scr1
+
+// This model covers SCR1_CFG_RV32IMC_MAX configuration (scr1-max).
+// SCR1_CFG_RV32EC_MIN (scr1-min) and SCR1_CFG_RV32IC_BASE (scr1-base)
+// configurations have essentially same scheduling characteristics.
+
+// SCR1 is single-issue in-order processor
+def SCR1Model : SchedMachineModel {
+  let MicroOpBufferSize = 0;
+  let IssueWidth = 1;
+  let LoadLatency = 2;
+  let MispredictPenalty = 3;
+  let CompleteModel = 0;
+  let UnsupportedFeatures = [HasStdExtZbkb, HasStdExtZbkc, HasStdExtZbkx,
+ HasStdExtZknd, HasStdExtZkne, HasStdExtZknh,
+ HasStdExtZksed, HasStdExtZksh, HasStdExtZkr,
+ HasVInstructions];
+}
+
+let SchedModel = SCR1Model in {
+
+let BufferSize = 0 in {
+def SCR1_ALU : ProcResource<1>;
+def SCR1_LSU : ProcResource<1>;
+def SCR1_MUL : ProcResource<1>;
+def SCR1_DIV : ProcResource<1>;
+def SCR1_CFU : ProcResource<1>;
+}
+
+// Branching
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+
+// Integer arithmetic and logic
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+
+// Integer multiplication: single-cycle multiplier in SCR1_CFG_RV32IMC_MAX
+def : WriteRes;
+def : WriteRes;
+
+// Integer division: latency 33, inverse throughput 33
+let Latency = 33, ResourceCycles = [33] in {
+def : WriteRes;
+def : WriteRes;
+}
+
+// Load/store instructions on SCR1 have latency 2 and inverse throughput 2
+// (SCR1_CFG_RV32IMC_MAX includes TCM)
+let Latency = 2, ResourceCycles=[2] in {
+// Memory
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+}
+
+let Unsupported = true in {
+// Atomic memory
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+
+// FP load/store
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+
+// FP instructions
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+def : WriteRes;
+
+def : WriteRes;
+}
+
+// Others
+def : WriteRes;
+def : WriteRes;
+
+def : InstRW<[WriteIALU], (instrs COPY)>;
+
+//===--===//
+// Bypasses (none)
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def : ReadAdvance;
+def 

[PATCH] D139397: [LoongArch] Add testcases for privileged intrinsic macros

2022-12-06 Thread Gong LingQin via Phabricator via cfe-commits
gonglingqin created this revision.
gonglingqin added reviewers: xen0n, xry111, SixWeining, wangleiat, MaskRay, 
XiaodongLoong.
Herald added a subscriber: StephenFan.
Herald added a project: All.
gonglingqin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add testcases calling macros to the implemented privileged intrinsics
as discussed in D139288 . The intrinsics 
involved include ibar, dbar,
break, syscall, and CRC check intrinsics.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139397

Files:
  clang/test/CodeGen/LoongArch/intrinsic-la64.c
  clang/test/CodeGen/LoongArch/intrinsic.c

Index: clang/test/CodeGen/LoongArch/intrinsic.c
===
--- clang/test/CodeGen/LoongArch/intrinsic.c
+++ clang/test/CodeGen/LoongArch/intrinsic.c
@@ -9,55 +9,67 @@
 // LA32-LABEL: @dbar(
 // LA32-NEXT:  entry:
 // LA32-NEXT:call void @llvm.loongarch.dbar(i32 0)
+// LA32-NEXT:call void @llvm.loongarch.dbar(i32 0)
 // LA32-NEXT:ret void
 //
 // LA64-LABEL: @dbar(
 // LA64-NEXT:  entry:
 // LA64-NEXT:call void @llvm.loongarch.dbar(i32 0)
+// LA64-NEXT:call void @llvm.loongarch.dbar(i32 0)
 // LA64-NEXT:ret void
 //
 void dbar() {
-  return __builtin_loongarch_dbar(0);
+  __dbar(0);
+  __builtin_loongarch_dbar(0);
 }
 
 // LA32-LABEL: @ibar(
 // LA32-NEXT:  entry:
 // LA32-NEXT:call void @llvm.loongarch.ibar(i32 0)
+// LA32-NEXT:call void @llvm.loongarch.ibar(i32 0)
 // LA32-NEXT:ret void
 //
 // LA64-LABEL: @ibar(
 // LA64-NEXT:  entry:
 // LA64-NEXT:call void @llvm.loongarch.ibar(i32 0)
+// LA64-NEXT:call void @llvm.loongarch.ibar(i32 0)
 // LA64-NEXT:ret void
 //
 void ibar() {
-  return __builtin_loongarch_ibar(0);
+  __ibar(0);
+  __builtin_loongarch_ibar(0);
 }
 
 // LA32-LABEL: @loongarch_break(
 // LA32-NEXT:  entry:
 // LA32-NEXT:call void @llvm.loongarch.break(i32 1)
+// LA32-NEXT:call void @llvm.loongarch.break(i32 1)
 // LA32-NEXT:ret void
 //
 // LA64-LABEL: @loongarch_break(
 // LA64-NEXT:  entry:
 // LA64-NEXT:call void @llvm.loongarch.break(i32 1)
+// LA64-NEXT:call void @llvm.loongarch.break(i32 1)
 // LA64-NEXT:ret void
 //
 void loongarch_break() {
+  __break(1);
   __builtin_loongarch_break(1);
 }
 
 // LA32-LABEL: @syscall(
 // LA32-NEXT:  entry:
 // LA32-NEXT:call void @llvm.loongarch.syscall(i32 1)
+// LA32-NEXT:call void @llvm.loongarch.syscall(i32 1)
 // LA32-NEXT:ret void
 //
 // LA64-LABEL: @syscall(
 // LA64-NEXT:  entry:
 // LA64-NEXT:call void @llvm.loongarch.syscall(i32 1)
+// LA64-NEXT:call void @llvm.loongarch.syscall(i32 1)
 // LA64-NEXT:ret void
 //
 void syscall() {
+  __syscall(1);
   __builtin_loongarch_syscall(1);
 }
Index: clang/test/CodeGen/LoongArch/intrinsic-la64.c
===
--- clang/test/CodeGen/LoongArch/intrinsic-la64.c
+++ clang/test/CodeGen/LoongArch/intrinsic-la64.c
@@ -5,72 +5,104 @@
 
 // CHECK-LABEL: @crc_w_b_w(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.loongarch.crc.w.b.w(i32 [[A:%.*]], i32 [[B:%.*]])
-// CHECK-NEXT:ret i32 [[TMP0]]
+// CHECK-NEXT:[[TMP0:%.*]] = shl i32 [[A:%.*]], 24
+// CHECK-NEXT:[[CONV_I:%.*]] = ashr exact i32 [[TMP0]], 24
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.loongarch.crc.w.b.w(i32 [[CONV_I]], i32 [[B:%.*]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call i32 @llvm.loongarch.crc.w.b.w(i32 [[A]], i32 [[B]])
+// CHECK-NEXT:ret i32 0
 //
 int crc_w_b_w(int a, int b) {
-  return __builtin_loongarch_crc_w_b_w(a, b);
+  int c = __crc_w_b_w(a, b);
+  int d = __builtin_loongarch_crc_w_b_w(a, b);
+  return 0;
 }
 
 // CHECK-LABEL: @crc_w_h_w(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.loongarch.crc.w.h.w(i32 [[A:%.*]], i32 [[B:%.*]])
-// CHECK-NEXT:ret i32 [[TMP0]]
+// CHECK-NEXT:[[TMP0:%.*]] = shl i32 [[A:%.*]], 16
+// CHECK-NEXT:[[CONV_I:%.*]] = ashr exact i32 [[TMP0]], 16
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.loongarch.crc.w.h.w(i32 [[CONV_I]], i32 [[B:%.*]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call i32 @llvm.loongarch.crc.w.h.w(i32 [[A]], i32 [[B]])
+// CHECK-NEXT:ret i32 0
 //
 int crc_w_h_w(int a, int b) {
-  return __builtin_loongarch_crc_w_h_w(a, b);
+  int c = __crc_w_h_w(a, b);
+  int d = __builtin_loongarch_crc_w_h_w(a, b);
+  return 0;
 }
 
 // CHECK-LABEL: @crc_w_w_w(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.loongarch.crc.w.w.w(i32 [[A:%.*]], i32 [[B:%.*]])
-// CHECK-NEXT:ret i32 [[TMP0]]
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.loongarch.crc.w.w.w(i32 [[A]], i32 [[B]])
+// CHECK-NEXT:ret i32 0
 //
 int crc_w_w_w(int a, int b) {
-  return __builtin_loongarch_crc_w_w_w(a, b);
+  int c = __crc_w_w_w(a, b);
+  int d = __builtin_loongarch_crc_w_w

[PATCH] D135750: [clang][Interp] Track initialization state of local variables

2022-12-06 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 9 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:835
 IsTemporary = true;
 Ty = E->getType();
   }

shafik wrote:
> Do we really want to the type of the expression? If we have a `ValueDecl` 
> don't we want that type? I think they should be the same, do you have any 
> examples where the expression is the type we want? I am looking at the AST 
> from ` int x = 1+1L;` 
> 
> https://godbolt.org/z/q3Tr7Kxoq
I don't have a counter example but I didn't write that line either. The Expr 
case is for temporary values created for AST expressions, not sure what other 
type to use.



Comment at: clang/lib/AST/Interp/InterpBlock.h:97
   void invokeCtor() {
-std::memset(data(), 0, getSize());
+std::memset(rawData(), 0, Desc->getAllocSize());
 if (Desc->CtorFn)

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > tbaeder wrote:
> > > > aaron.ballman wrote:
> > > > > Why do we want to overwrite the metadata here?
> > > > This is only called after creating an new block, so nothing is being 
> > > > overwritten, the metadata hasn't been filled-in yet.
> > > Sounds like a good reason not to memset over that block then; it's 
> > > useless work that will be thrown away anyway (I worry we may come to rely 
> > > on this zero init accidentally)?
> > FWIW I looked into this and I think zeroing everything is what we want, so 
> > the initmap is null initially 
> Hmmm, would it make more sense to have the init map setting that itself (in 
> `allocate()`) rather than relying on `invokeCtor()` to do it?
It's a bit blurry to me regarding the layering with Pointer/Descriptor. 
Descriptors don't know anything about the metadata, but pointers know that 
primitive arrays have an initmap. So to keep that consistent, we'd have to 
create a pointer to create the initmap.

But I don't think it's unreasonable to expect zero-initialization for types 
used in the interpreter.



Comment at: clang/test/AST/Interp/cxx20.cpp:93
+  // ref-note {{read of uninitialized object is not allowed in a 
constant expression}}
+}
+static_assert(initializedLocal3() == 20); // expected-error {{not an integral 
constant expression}} \

It might be interesting to know that the output for this test changes with 
https://reviews.llvm.org/D135750. After that patch, we only note that the 


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

https://reviews.llvm.org/D135750

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


[PATCH] D139398: [AMDGPU] Add bf16 storage support

2022-12-06 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh created this revision.
Pierre-vh added reviewers: arsenm, foad, yaxunl.
Herald added subscribers: kosarev, kerbowa, hiraditya, tpr, dstuttard, jvesely, 
kzhuravl.
Herald added a project: All.
Pierre-vh requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, wdng.
Herald added projects: clang, LLVM.

- [Clang] Declare AMDGPU target as supporting BF16 for storage-only purposes.
  - Add Sema & CodeGen tests cases.
  - Also add cases that D138651  would have 
covered as this patch replaces it.
- [AMDGPU] Add BF16 storage-only support
  - CC: Add bf16/v2bf16 arguments support by converting them to i16/i32.
  - Add BF16 to various register classes & fix issues it causes with type 
inference.
  - DAG: Add BF16 legalization/codegen support for GCN targets.
  - GISel: Not supported as the framework doesn't support bfloat16 properly yet.
  - Added test cases for supported BF16 ops + unsupported ones.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139398

Files:
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/test/CodeGenCUDA/amdgpu-bf16.cu
  clang/test/SemaCUDA/amdgpu-bf16.cu
  llvm/lib/Target/AMDGPU/AMDGPUCallingConv.td
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIInstructions.td
  llvm/lib/Target/AMDGPU/SIRegisterInfo.td
  llvm/lib/Target/AMDGPU/VOP3PInstructions.td
  llvm/test/CodeGen/AMDGPU/bf16-ops.ll
  llvm/test/CodeGen/AMDGPU/bf16.ll

Index: llvm/test/CodeGen/AMDGPU/bf16.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/bf16.ll
@@ -0,0 +1,956 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -march=amdgcn -verify-machineinstrs | FileCheck %s -check-prefixes=GCN
+; RUN: llc < %s -march=amdgcn -mcpu=hawaii  -verify-machineinstrs | FileCheck %s -check-prefixes=GFX7
+; RUN: llc < %s -march=amdgcn -mcpu=tonga  -verify-machineinstrs | FileCheck %s -check-prefixes=GFX8
+; RUN: llc < %s -march=amdgcn -mcpu=gfx900 -verify-machineinstrs | FileCheck %s -check-prefixes=GFX9
+; RUN: llc < %s -march=amdgcn -mcpu=gfx1010 -verify-machineinstrs | FileCheck %s -check-prefixes=GFX10
+
+; We only have storage-only BF16 support. We can load/store those values as we treat them as u16, but
+; we don't support operations on them. As such, codegen is expected to fail for any operation other
+; than simple load/stores.
+
+define void @test_load_store(bfloat addrspace(1)* %in, bfloat addrspace(1)* %out) {
+; GCN-LABEL: test_load_store:
+; GCN:   ; %bb.0:
+; GCN-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GCN-NEXT:s_mov_b32 s6, 0
+; GCN-NEXT:s_mov_b32 s7, 0xf000
+; GCN-NEXT:s_mov_b32 s4, s6
+; GCN-NEXT:s_mov_b32 s5, s6
+; GCN-NEXT:buffer_load_ushort v0, v[0:1], s[4:7], 0 addr64
+; GCN-NEXT:s_waitcnt vmcnt(0)
+; GCN-NEXT:buffer_store_short v0, v[2:3], s[4:7], 0 addr64
+; GCN-NEXT:s_waitcnt vmcnt(0) expcnt(0)
+; GCN-NEXT:s_setpc_b64 s[30:31]
+;
+; GFX7-LABEL: test_load_store:
+; GFX7:   ; %bb.0:
+; GFX7-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX7-NEXT:s_mov_b32 s6, 0
+; GFX7-NEXT:s_mov_b32 s7, 0xf000
+; GFX7-NEXT:s_mov_b32 s4, s6
+; GFX7-NEXT:s_mov_b32 s5, s6
+; GFX7-NEXT:buffer_load_ushort v0, v[0:1], s[4:7], 0 addr64
+; GFX7-NEXT:s_waitcnt vmcnt(0)
+; GFX7-NEXT:buffer_store_short v0, v[2:3], s[4:7], 0 addr64
+; GFX7-NEXT:s_waitcnt vmcnt(0)
+; GFX7-NEXT:s_setpc_b64 s[30:31]
+;
+; GFX8-LABEL: test_load_store:
+; GFX8:   ; %bb.0:
+; GFX8-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX8-NEXT:flat_load_ushort v0, v[0:1]
+; GFX8-NEXT:s_waitcnt vmcnt(0)
+; GFX8-NEXT:flat_store_short v[2:3], v0
+; GFX8-NEXT:s_waitcnt vmcnt(0)
+; GFX8-NEXT:s_setpc_b64 s[30:31]
+;
+; GFX9-LABEL: test_load_store:
+; GFX9:   ; %bb.0:
+; GFX9-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT:global_load_ushort v0, v[0:1], off
+; GFX9-NEXT:s_waitcnt vmcnt(0)
+; GFX9-NEXT:global_store_short v[2:3], v0, off
+; GFX9-NEXT:s_waitcnt vmcnt(0)
+; GFX9-NEXT:s_setpc_b64 s[30:31]
+;
+; GFX10-LABEL: test_load_store:
+; GFX10:   ; %bb.0:
+; GFX10-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX10-NEXT:s_waitcnt_vscnt null, 0x0
+; GFX10-NEXT:global_load_ushort v0, v[0:1], off
+; GFX10-NEXT:s_waitcnt vmcnt(0)
+; GFX10-NEXT:global_store_short v[2:3], v0, off
+; GFX10-NEXT:s_waitcnt_vscnt null, 0x0
+; GFX10-NEXT:s_setpc_b64 s[30:31]
+  %val = load bfloat, bfloat addrspace(1)* %in
+  store bfloat %val, bfloat addrspace(1) * %out
+  ret void
+}
+
+define void @test_load_store_v2bf16(<2 x bfloat> addrspace(1)* %in, <2 x bfloat> addrspace(1)* %out) {
+; GCN-LABEL: test_load_store_v2bf16:
+; GCN:   ; %bb.0:
+; GCN-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GCN-NEXT:

[PATCH] D138651: [CUDA][HIP] Don't diagnose use for __bf16

2022-12-06 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh abandoned this revision.
Pierre-vh added a comment.

Added bf16 storage support instead: D139398 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138651

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


[PATCH] D128457: [clangd] Add new IncludeType to IncludeHeaderWithReferences

2022-12-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

it feels like rebasing went wrong. changes from 2 unrelated patches seem to be 
part of this one now. can you make sure this patch only contains the delta for 
symbolcollector/clangd pieces?




Comment at: clang-tools-extra/clangd/Headers.h:50
+  /// The header to include.
+  llvm::StringRef Header;
+  /// The include directive to use, e.g. #import or #include.

let's mention that this is either a URI or verbatim include in the comments



Comment at: clang-tools-extra/clangd/Headers.h:54
 
+struct HeaderInclude {
+  /// The header to include.

let's rename this to `SymbolInclude` as it looks too similar to `HeaderFile` 
right now.

also adding a comment like: `A header and directives as stored in a Symbol.`



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:869
+  Directives |= Symbol::Include;
+if ((CollectDirectives & Symbol::Import) != 0) {
+  auto [It, Inserted] = FileToContainsImportsOrObjC.try_emplace(FID);

can we add a comment like `Only allow #import for symbols from objc-like files.`



Comment at: clang/lib/Tooling/Inclusions/HeaderAnalysis.cpp:76
+  // need to check for anything but the main-file.
+  (!const_cast(SM).isMainFile(*FE) ||
+   !codeContainsImports(getFileContents(FE, SM

`SM.getFileEntryForID(SM.getMainFileID()) == FE`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128457

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


[PATCH] D139302: [RISCV] Add Syntacore SCR1 CPU model

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



Comment at: llvm/lib/Target/RISCV/RISCV.td:637
+def : ProcessorModel<"scr1-min", SCR1Model,
+ [FeatureRV32E, FeatureStdExtC],
+ [TuneNoDefaultUnroll]>;

dnpetrov-sc wrote:
> craig.topper wrote:
> > Shouldn't this also need Feature32Bit?
> Now, that's somewhat funny. Indeed, RISCVSubtarget has `HasRV32` field, but 
> it is never queried. `IsRV32` predicate in RISCV.td is mapped to 
> `!Subtarget->is64Bit()` in C++ code.
> 
> Code generation for RV32E is not implemented yet, though (and would error out 
> in `RISCVTargetLowering`). I'll drop scr1-min for now.
> 
It is queried from the MC layer using something like 
FeatureBits[RISCV::Feature32Bit].

It’s only there to distinquish mtune CPU names from real CPU names. The mtune 
CPU names don’t have 32Bit or 64Bit and generate an error if they are used with 
-mcpu


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139302

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


[PATCH] D139274: Store OptTable::Info::Name as a StringRef

2022-12-06 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 480363.
serge-sans-paille added a comment.

fix test / compile errors


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

https://reviews.llvm.org/D139274

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/Option/OptTable.cpp
  llvm/unittests/Option/OptionMarshallingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -54,9 +54,9 @@
 
 static void emitNameUsingSpelling(raw_ostream &OS, const Record &R) {
   size_t PrefixLength;
-  OS << "&";
+  OS << "llvm::StringRef(";
   write_cstring(OS, StringRef(getOptionSpelling(R, PrefixLength)));
-  OS << "[" << PrefixLength << "]";
+  OS << ").substr(" << PrefixLength << ")";
 }
 
 class MarshallingInfo {
Index: llvm/unittests/Option/OptionMarshallingTest.cpp
===
--- llvm/unittests/Option/OptionMarshallingTest.cpp
+++ llvm/unittests/Option/OptionMarshallingTest.cpp
@@ -6,10 +6,11 @@
 //
 //===--===//
 
+#include "llvm/ADT/StringRef.h"
 #include "gtest/gtest.h"
 
 struct OptionWithMarshallingInfo {
-  const char *Name;
+  llvm::StringRef Name;
   const char *KeyPath;
   const char *ImpliedCheck;
   const char *ImpliedValue;
@@ -27,10 +28,10 @@
 };
 
 TEST(OptionMarshalling, EmittedOrderSameAsDefinitionOrder) {
-  ASSERT_STREQ(MarshallingTable[0].Name, "marshalled-flag-d");
-  ASSERT_STREQ(MarshallingTable[1].Name, "marshalled-flag-c");
-  ASSERT_STREQ(MarshallingTable[2].Name, "marshalled-flag-b");
-  ASSERT_STREQ(MarshallingTable[3].Name, "marshalled-flag-a");
+  ASSERT_STREQ(MarshallingTable[0].Name.data(), "marshalled-flag-d");
+  ASSERT_STREQ(MarshallingTable[1].Name.data(), "marshalled-flag-c");
+  ASSERT_STREQ(MarshallingTable[2].Name.data(), "marshalled-flag-b");
+  ASSERT_STREQ(MarshallingTable[3].Name.data(), "marshalled-flag-a");
 }
 
 TEST(OptionMarshalling, EmittedSpecifiedKeyPath) {
Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -67,7 +67,7 @@
   if (&A == &B)
 return false;
 
-  if (int N = StrCmpOptionName(A.Name, B.Name))
+  if (int N = StrCmpOptionName(A.Name.data(), B.Name.data()))
 return N < 0;
 
   for (const char * const *APre = A.Prefixes,
@@ -87,7 +87,7 @@
 
 // Support lower_bound between info and an option name.
 static inline bool operator<(const OptTable::Info &I, const char *Name) {
-  return StrCmpOptionNameIgnoreCase(I.Name, Name) < 0;
+  return StrCmpOptionNameIgnoreCase(I.Name.data(), Name) < 0;
 }
 
 } // end namespace opt
@@ -321,7 +321,7 @@
   return BestDistance;
 }
 
-bool OptTable::addValues(const char *Option, const char *Values) {
+bool OptTable::addValues(StringRef Option, const char *Values) {
   for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
 Info &In = OptionInfos[I];
 if (optionMatches(In, Option)) {
Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -44,7 +44,7 @@
 /// A null terminated array of prefix strings to apply to name while
 /// matching.
 const char *const *Prefixes;
-const char *Name;
+StringRef Name;
 const char *HelpText;
 const char *MetaVar;
 unsigned ID;
@@ -102,9 +102,7 @@
   const Option getOption(OptSpecifier Opt) const;
 
   /// Lookup the name of the given option.
-  const char *getOptionName(OptSpecifier id) const {
-return getInfo(id).Name;
-  }
+  StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
 
   /// Get the kind of the given option.
   unsigned getOptionKind(OptSpecifier id) const {
@@ -184,7 +182,7 @@
   ///  takes
   ///
   /// \return true in success, and false in fail.
-  bool addValues(const char *Option, const char *Values);
+  bool addValues(StringRef Option, const char *Values);
 
   /// Parse a single argument; returning the new argument and
   /// updating Index.
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -331,8 +331,8 @@
   if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
 const Driver &D = TC.getDriver();
 const llvm::opt::OptTable &Opts = D.getOpts();
-const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
-const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
+StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
+StringRef NoPIEName = Opts.get

[PATCH] D139277: [clangd] Use all query-driver arguments in cache key

2022-12-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks a lot for taking a look at this!




Comment at: clang-tools-extra/clangd/SystemIncludeExtractor.cpp:301
 llvm::StringRef Lang;
+llvm::SmallVector AdditionalDriverArgs;
+

can we introduce a struct instead?
```
struct DriverArgs {
  std::string Driver;
  bool StandardIncludes = true;
  bool StandardCXXIncludes = true;
  bool BuiltinIncludes = true;
  llvm::StringRef Lang;
  llvm::StringRef Sysroot;

  DriverArgs(const tooling::CompileCommand &Cmd); // Traverses the Cmd and 
infers the bits.
  llvm::SmallVector render() const; // we can use canonical 
versions.
};
```

we can also implement hashing based on the struct now and also pass it around.



Comment at: clang-tools-extra/clangd/SystemIncludeExtractor.cpp:304
+// These flags will be preserved
+const llvm::StringRef FlagsToPreserve[] = {
+"-nostdinc", "--no-standard-includes", "-nostdinc++", "-nobuiltininc"};

i don't think we gain much by having these 3 different types now, especially 
considering an arg might need to be placed in multiple categories (`-isysroot` 
in both TwoPartArgs and ArgPrefixes).

let's rather have a check for each related bit of struct inside the for loop, 
e.g. something like:

```
for(...) {
  // Infer Lang
  if(Arg.startswith("-x")) {
if (Arg == "-x" && I + 1 < E) Lang = Args[++I];
else Lang = Arg.drop_front(2).trim();
continue;
  }

  // Infer Sysroot
  ...
}
```



Comment at: clang-tools-extra/clangd/SystemIncludeExtractor.cpp:310
+const llvm::StringRef ArgPrefixesToPreserve[] = {
+"-isysroot", "--sysroot=", "-specs=", "--specs="};
+

can we add `--specs` related changes in a follow up patch instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139277

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


[libunwind] ca0b4d5 - [libunwind][RISCV] Support reading of VLENB CSR register

2022-12-06 Thread Sergey Kachkov via cfe-commits

Author: Sergey Kachkov
Date: 2022-12-06T11:48:54+03:00
New Revision: ca0b4d58eaad405ea74b4db82ecb14b3cfdeccb7

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

LOG: [libunwind][RISCV] Support reading of VLENB CSR register

Support reading of VLENB (vector byte length) control register, that can be
required for correct unwinding of RVV objects on stack.

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

Added: 
libunwind/test/unwind_scalable_vectors.pass.cpp

Modified: 
libunwind/include/libunwind.h
libunwind/src/Registers.hpp

Removed: 




diff  --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index 8c8cf8f533384..d2ad5ab871227 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -1023,6 +1023,16 @@ enum {
   UNW_RISCV_F29 = 61,
   UNW_RISCV_F30 = 62,
   UNW_RISCV_F31 = 63,
+  // 65-95 -- Reserved for future standard extensions
+  // 96-127 -- v0-v31 (Vector registers)
+  // 128-3071 -- Reserved for future standard extensions
+  // 3072-4095 -- Reserved for custom extensions
+  // 4096-8191 -- CSRs
+  //
+  // VLENB CSR number: 0xC22 -- defined by section 3 of v-spec:
+  // 
https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#3-vector-extension-programmers-model
+  // VLENB DWARF number: 0x1000 + 0xC22
+  UNW_RISCV_VLENB = 0x1C22,
 };
 
 // VE register numbers

diff  --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index ff736ca9e8b37..c7b875d74ae3c 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -4085,6 +4085,8 @@ inline bool Registers_riscv::validRegister(int regNum) 
const {
 return true;
   if (regNum < 0)
 return false;
+  if (regNum == UNW_RISCV_VLENB)
+return true;
   if (regNum > UNW_RISCV_F31)
 return false;
   return true;
@@ -4099,6 +4101,11 @@ inline reg_t Registers_riscv::getRegister(int regNum) 
const {
 return 0;
   if ((regNum > 0) && (regNum < 32))
 return _registers[regNum];
+  if (regNum == UNW_RISCV_VLENB) {
+reg_t vlenb;
+__asm__("csrr %0, 0xC22" : "=r"(vlenb));
+return vlenb;
+  }
   _LIBUNWIND_ABORT("unsupported riscv register");
 }
 
@@ -4250,6 +4257,8 @@ inline const char *Registers_riscv::getRegisterName(int 
regNum) {
 return "ft10";
   case UNW_RISCV_F31:
 return "ft11";
+  case UNW_RISCV_VLENB:
+return "vlenb";
   default:
 return "unknown register";
   }

diff  --git a/libunwind/test/unwind_scalable_vectors.pass.cpp 
b/libunwind/test/unwind_scalable_vectors.pass.cpp
new file mode 100644
index 0..250e2c8fc7b1e
--- /dev/null
+++ b/libunwind/test/unwind_scalable_vectors.pass.cpp
@@ -0,0 +1,50 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// REQUIRES: linux && target={{riscv64-.+}}
+
+#undef NDEBUG
+#include 
+#include 
+
+// Check correct unwinding of frame with VLENB-sized objects (vector 
registers):
+// 1. Save return address (ra) in temporary register.
+// 2. Load VLENB (vector length in bytes) and substract it from current stack
+//pointer (sp) - equivalent to one vector register on stack frame.
+// 3. Set DWARF cannonical frame address (CFA) to "sp + vlenb" expresssion so 
it
+//can be correctly unwinded.
+// 4. Call stepper() function and check that 2 unwind steps are successful -
+//from stepper() into foo() and from foo() into main().
+// 5. Restore stack pointer and return address.
+__attribute__((naked)) static void foo() {
+  __asm__(".cfi_startproc\n"
+  "mv s0, ra\n"
+  "csrr  s1, vlenb\n"
+  "sub sp, sp, s1\n"
+  "# .cfi_def_cfa_expression sp + vlenb\n"
+  ".cfi_escape 0x0f, 0x07, 0x72, 0x00, 0x92, 0xa2, 0x38, 0x00, 0x22\n"
+  "call stepper\n"
+  "add sp, sp, s1\n"
+  "mv ra, s0\n"
+  "ret\n"
+  ".cfi_endproc\n");
+}
+
+extern "C" void stepper() {
+  unw_cursor_t cursor;
+  unw_context_t uc;
+  unw_getcontext(&uc);
+  unw_init_local(&cursor, &uc);
+  // Stepping into foo() should succeed.
+  assert(unw_step(&cursor) > 0);
+  // Stepping past foo() should succeed, too.
+  assert(unw_step(&cursor) > 0);
+}
+
+int main() { foo(); }



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


[PATCH] D139281: [clang-format] Fix an assertion failure in block parsing

2022-12-06 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 480364.
owenpan added a comment.

Moved `isBlockBegin()` to `UnwrappedLineParser`.


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

https://reviews.llvm.org/D139281

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6602,6 +6602,13 @@
"  x = 1;\n"
"FOO_END(Baz)",
Style);
+
+  Style.RemoveBracesLLVM = true;
+  verifyNoCrash("for (;;)\n"
+"  FOO_BEGIN\n"
+"foo();\n"
+"  FOO_END",
+Style);
 }
 
 
//===--===//
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -143,6 +143,7 @@
   void parseUnbracedBody(bool CheckEOF = false);
   void handleAttributes();
   bool handleCppAttributes();
+  bool isBlockBegin(const FormatToken &Tok) const;
   FormatToken *parseIfThenElse(IfStmtKind *IfKind, bool KeepBraces = false);
   void parseTryCatch();
   void parseLoopBody(bool KeepBraces, bool WrapRightBrace);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2739,6 +2739,14 @@
   return false;
 }
 
+/// Returns whether \c Tok begins a block.
+bool UnwrappedLineParser::isBlockBegin(const FormatToken &Tok) const {
+  // FIXME: rename the function or make
+  // Tok.isOneOf(tok::l_brace, TT_MacroBlockBegin) work.
+  return Style.isVerilog() ? Keywords.isVerilogBegin(Tok)
+   : Tok.is(tok::l_brace);
+}
+
 FormatToken *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
   bool KeepBraces) {
   assert(FormatTok->is(tok::kw_if) && "'if' expected");
@@ -2764,7 +2772,7 @@
   FormatToken *IfLeftBrace = nullptr;
   IfStmtKind IfBlockKind = IfStmtKind::NotIf;
 
-  if (Keywords.isBlockBegin(*FormatTok, Style)) {
+  if (isBlockBegin(*FormatTok)) {
 FormatTok->setFinalizedType(TT_ControlStatementLBrace);
 IfLeftBrace = FormatTok;
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
@@ -2796,7 +2804,7 @@
 }
 nextToken();
 handleAttributes();
-if (Keywords.isBlockBegin(*FormatTok, Style)) {
+if (isBlockBegin(*FormatTok)) {
   const bool FollowedByIf = Tokens->peekNextToken()->is(tok::kw_if);
   FormatTok->setFinalizedType(TT_ElseLBrace);
   ElseLeftBrace = FormatTok;
@@ -3063,7 +3071,7 @@
 void UnwrappedLineParser::parseLoopBody(bool KeepBraces, bool WrapRightBrace) {
   keepAncestorBraces();
 
-  if (Keywords.isBlockBegin(*FormatTok, Style)) {
+  if (isBlockBegin(*FormatTok)) {
 if (!KeepBraces)
   FormatTok->setFinalizedType(TT_ControlStatementLBrace);
 FormatToken *LeftBrace = FormatTok;
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -1785,12 +1785,6 @@
 kw_input, kw_output, kw_sequence)));
   }
 
-  /// Whether the token begins a block.
-  bool isBlockBegin(const FormatToken &Tok, const FormatStyle &Style) const {
-return Tok.is(TT_MacroBlockBegin) ||
-   (Style.isVerilog() ? isVerilogBegin(Tok) : Tok.is(tok::l_brace));
-  }
-
 private:
   /// The JavaScript keywords beyond the C++ keyword set.
   std::unordered_set JsExtraKeywords;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6602,6 +6602,13 @@
"  x = 1;\n"
"FOO_END(Baz)",
Style);
+
+  Style.RemoveBracesLLVM = true;
+  verifyNoCrash("for (;;)\n"
+"  FOO_BEGIN\n"
+"foo();\n"
+"  FOO_END",
+Style);
 }
 
 //===--===//
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -143,6 +143,7 @@
   void parseUnbracedBody(bool CheckEOF = false);
   void handleAttributes();
   bool handleCppAttributes();
+  bool isBlockBegin(const FormatToken &Tok) const;
   FormatToken *parseIfThenElse(IfStmtKind *IfKind, bool KeepBraces = false);
   void parseT

[PATCH] D139274: Store OptTable::Info::Name as a StringRef

2022-12-06 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: llvm/lib/Option/OptTable.cpp:44
 if (a == '\0')
   return 0;
 

The code in this function (and also StrCmpOptionName) depends on the 
terminating null byte, while a StringRef is not guaranteed to by directly 
followed by one. I think these two functions would have to be adjusted to 
operate on StringRef rather than pointers as well.


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

https://reviews.llvm.org/D139274

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


[PATCH] D139400: [clang] Show error when a local variables is passed as default template parameter

2022-12-06 Thread Jens Massberg via Phabricator via cfe-commits
massberg created this revision.
massberg added a reviewer: ilya-biryukov.
Herald added a project: All.
massberg requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I haven't found an existing error message for this in
clang/include/clang/Basic/DiagnosticSemaKinds.td so I have added a new
one. I'm not sure if it in the right place and the formulation might be
improved.

Fixes #48755


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139400

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/default-template-arguments.cpp


Index: clang/test/SemaTemplate/default-template-arguments.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/default-template-arguments.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+namespace GH48755 {
+constexpr auto z = 2;
+
+auto f() {
+  const auto x = 1;
+
+  auto lambda1 = []  {}; // expected-error {{local variables may 
not be used as default parameters}}
+  auto lambda2 = []  {};
+  auto lambda3 = []  {};
+  auto lambda4 = []  {};
+}
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1587,6 +1587,15 @@
 
   // Check the well-formedness of the default template argument, if provided.
   if (Default) {
+// Local variables may not be used as default template arguments.
+if (auto *DRE = dyn_cast(Default)) {
+  if (VarDecl *VD = dyn_cast(DRE->getDecl())) {
+if(VD->hasLocalStorage()) {
+  Diag(DRE->getLocation(), 
diag::err_local_variable_as_default_in_template) << VD->getNameAsString();
+}
+  }
+}
+
 // Check for unexpanded parameter packs.
 if (DiagnoseUnexpandedParameterPack(Default, UPPC_DefaultArgument))
   return Param;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7896,6 +7896,9 @@
   def warn_cxx17_compat_lambda_def_ctor_assign : Warning<
 "%select{default construction|assignment}0 of lambda is incompatible with "
 "C++ standards before C++20">, InGroup, DefaultIgnore;
+
+  def err_local_variable_as_default_in_template : Error<
+  "local variable '%0' may not be used as default parameter">;
 }
 
 def err_return_in_captured_stmt : Error<


Index: clang/test/SemaTemplate/default-template-arguments.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/default-template-arguments.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+namespace GH48755 {
+constexpr auto z = 2;
+
+auto f() {
+  const auto x = 1;
+
+  auto lambda1 = []  {}; // expected-error {{local variables may not be used as default parameters}}
+  auto lambda2 = []  {};
+  auto lambda3 = []  {};
+  auto lambda4 = []  {};
+}
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1587,6 +1587,15 @@
 
   // Check the well-formedness of the default template argument, if provided.
   if (Default) {
+// Local variables may not be used as default template arguments.
+if (auto *DRE = dyn_cast(Default)) {
+  if (VarDecl *VD = dyn_cast(DRE->getDecl())) {
+if(VD->hasLocalStorage()) {
+  Diag(DRE->getLocation(), diag::err_local_variable_as_default_in_template) << VD->getNameAsString();
+}
+  }
+}
+
 // Check for unexpanded parameter packs.
 if (DiagnoseUnexpandedParameterPack(Default, UPPC_DefaultArgument))
   return Param;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7896,6 +7896,9 @@
   def warn_cxx17_compat_lambda_def_ctor_assign : Warning<
 "%select{default construction|assignment}0 of lambda is incompatible with "
 "C++ standards before C++20">, InGroup, DefaultIgnore;
+
+  def err_local_variable_as_default_in_template : Error<
+  "local variable '%0' may not be used as default parameter">;
 }
 
 def err_return_in_captured_stmt : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138779: [include-cleaner] Filter out references that not spelled in the main file.

2022-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 480367.
hokein added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138779

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -19,14 +19,17 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 
 namespace clang::include_cleaner {
 namespace {
 using testing::ElementsAre;
+using testing::AllOf;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
@@ -214,5 +217,127 @@
 )cpp");
 }
 
+MATCHER_P3(expandedAt, FileID, Offset, SM, "") {
+  auto [ExpanedFileID, ExpandedOffset] = SM->getDecomposedExpansionLoc(arg);
+  return ExpanedFileID == FileID && ExpandedOffset == Offset;
+}
+MATCHER_P3(spelledAt, FileID, Offset, SM, "") {
+  auto [SpelledFileID, SpelledOffset] = SM->getDecomposedSpellingLoc(arg);
+  return SpelledFileID == FileID && SpelledOffset == Offset;
+}
+TEST(WalkUsed, FilterRefsNotSpelledInMainFile) {
+  // Each test is expected to have a single expected ref of `target` symbol
+  // (or have none).
+  // The location in the reported ref is a macro location. $expand points to
+  // the macro location, and $spell points to the spelled location.
+  struct {
+llvm::StringRef Header;
+llvm::StringRef Main;
+  } TestCases[] = {
+  // Tests for decl references.
+  {
+  /*Header=*/"",
+  R"cpp(
+int target();
+#define CALL_FUNC $spell^target()
+
+int b = $expand^CALL_FUNC;
+  )cpp",
+  },
+  {/*Header=*/R"cpp(
+int target();
+#define CALL_FUNC target()
+)cpp",
+   // No ref of `target` being reported, as it is not spelled in main file.
+   "int a = CALL_FUNC;"},
+  {
+  /*Header=*/"",
+  R"cpp(
+int target;
+#define PLUS_ONE(X) X + 1
+int a = $expand^PLUS_ONE($spell^target);
+  )cpp",
+  },
+  {
+  /*Header*/ R"cpp(
+int target;
+#define PLUS_ONE(X) X + 1
+  )cpp",
+  R"cpp(
+int a = $expand^PLUS_ONE($spell^target);
+  )cpp",
+  },
+  {
+  /*Header=*/"#define PLUS_ONE(X) X + 1",
+  R"cpp(
+int target;
+int a = $expand^PLUS_ONE($spell^target);
+  )cpp",
+  },
+  // Tests for macro references,
+  {/*Header=*/"",
+   R"cpp(
+  #define target 1
+  #define USE_target $spell^target
+  int b = $expand^USE_target;
+)cpp"},
+  {/*Header=*/R"cpp(
+  #define target 1
+  #define USE_target target
+)cpp",
+   // No ref of `target` being reported, it is not spelled in main file.
+   R"cpp(
+  int a = USE_target;
+)cpp"},
+  };
+
+  for (const auto &T : TestCases) {
+llvm::Annotations Main(T.Main);
+TestInputs Inputs(Main.code());
+Inputs.ExtraFiles["header.h"] = guard(T.Header);
+RecordedPP Recorded;
+Inputs.MakeAction = [&]() {
+  struct RecordAction : public SyntaxOnlyAction {
+RecordedPP &Out;
+RecordAction(RecordedPP &Out) : Out(Out) {}
+bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+  auto &PP = CI.getPreprocessor();
+  PP.addPPCallbacks(Out.record(PP));
+  return true;
+}
+  };
+  return std::make_unique(Recorded);
+};
+Inputs.ExtraArgs.push_back("-include");
+Inputs.ExtraArgs.push_back("header.h");
+TestAST AST(Inputs);
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls())
+  TopLevelDecls.emplace_back(D);
+auto &SM = AST.sourceManager();
+
+std::optional RefLoc;
+walkUsed(TopLevelDecls, Recorded.MacroReferences,
+ /*PragmaIncludes=*/nullptr, SM,
+ [&](const SymbolReference &Ref, llvm::ArrayRef) {
+   if (!Ref.RefLocation.isMacroID())
+ return;
+   if (llvm::to_string(Ref.Target) == "target") {
+ ASSERT_FALSE(RefLoc)
+ << "Expected only one 'target' ref loc per testcase";
+ RefLoc = Ref.RefLocation;
+   }
+ });
+FileID MainFID = SM.getMainFileID();
+

[PATCH] D138779: [include-cleaner] Filter out references that not spelled in the main file.

2022-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

this patch is ready for another review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138779

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


[PATCH] D139400: [clang] Show error when a local variables is passed as default template parameter

2022-12-06 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 480369.
massberg added a comment.

Fix test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139400

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/default-template-arguments.cpp


Index: clang/test/SemaTemplate/default-template-arguments.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/default-template-arguments.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+namespace GH48755 {
+constexpr auto z = 2;
+
+auto f() {
+  const auto x = 1;
+
+  auto lambda1 = []  {}; // expected-error {{local variable 'x' 
may not be used as default parameter}}
+  auto lambda2 = []  {};
+  auto lambda3 = []  {};
+  auto lambda4 = []  {};
+}
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1587,6 +1587,15 @@
 
   // Check the well-formedness of the default template argument, if provided.
   if (Default) {
+// Local variables may not be used as default template arguments.
+if (auto *DRE = dyn_cast(Default)) {
+  if (VarDecl *VD = dyn_cast(DRE->getDecl())) {
+if(VD->hasLocalStorage()) {
+  Diag(DRE->getLocation(), 
diag::err_local_variable_as_default_in_template) << VD->getNameAsString();
+}
+  }
+}
+
 // Check for unexpanded parameter packs.
 if (DiagnoseUnexpandedParameterPack(Default, UPPC_DefaultArgument))
   return Param;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7896,6 +7896,9 @@
   def warn_cxx17_compat_lambda_def_ctor_assign : Warning<
 "%select{default construction|assignment}0 of lambda is incompatible with "
 "C++ standards before C++20">, InGroup, DefaultIgnore;
+
+  def err_local_variable_as_default_in_template : Error<
+  "local variable '%0' may not be used as default parameter">;
 }
 
 def err_return_in_captured_stmt : Error<


Index: clang/test/SemaTemplate/default-template-arguments.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/default-template-arguments.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+namespace GH48755 {
+constexpr auto z = 2;
+
+auto f() {
+  const auto x = 1;
+
+  auto lambda1 = []  {}; // expected-error {{local variable 'x' may not be used as default parameter}}
+  auto lambda2 = []  {};
+  auto lambda3 = []  {};
+  auto lambda4 = []  {};
+}
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1587,6 +1587,15 @@
 
   // Check the well-formedness of the default template argument, if provided.
   if (Default) {
+// Local variables may not be used as default template arguments.
+if (auto *DRE = dyn_cast(Default)) {
+  if (VarDecl *VD = dyn_cast(DRE->getDecl())) {
+if(VD->hasLocalStorage()) {
+  Diag(DRE->getLocation(), diag::err_local_variable_as_default_in_template) << VD->getNameAsString();
+}
+  }
+}
+
 // Check for unexpanded parameter packs.
 if (DiagnoseUnexpandedParameterPack(Default, UPPC_DefaultArgument))
   return Param;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7896,6 +7896,9 @@
   def warn_cxx17_compat_lambda_def_ctor_assign : Warning<
 "%select{default construction|assignment}0 of lambda is incompatible with "
 "C++ standards before C++20">, InGroup, DefaultIgnore;
+
+  def err_local_variable_as_default_in_template : Error<
+  "local variable '%0' may not be used as default parameter">;
 }
 
 def err_return_in_captured_stmt : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139288: [Clang][LoongArch] Add intrinsic for csrrd, csrwr and csrxchg

2022-12-06 Thread Gong LingQin via Phabricator via cfe-commits
gonglingqin updated this revision to Diff 480371.
gonglingqin added a comment.

Add testcases for macros.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139288

Files:
  clang/include/clang/Basic/BuiltinsLoongArch.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/larchintrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/LoongArch/intrinsic-error-la64.c
  clang/test/CodeGen/LoongArch/intrinsic-error.c
  clang/test/CodeGen/LoongArch/intrinsic-la64.c
  clang/test/CodeGen/LoongArch/intrinsic.c
  llvm/include/llvm/IR/IntrinsicsLoongArch.td
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.td
  llvm/test/CodeGen/LoongArch/intrinsic-error.ll
  llvm/test/CodeGen/LoongArch/intrinsic-la32-error.ll
  llvm/test/CodeGen/LoongArch/intrinsic-la64-error.ll
  llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
  llvm/test/CodeGen/LoongArch/intrinsic.ll

Index: llvm/test/CodeGen/LoongArch/intrinsic.ll
===
--- llvm/test/CodeGen/LoongArch/intrinsic.ll
+++ llvm/test/CodeGen/LoongArch/intrinsic.ll
@@ -6,6 +6,9 @@
 declare void @llvm.loongarch.ibar(i32)
 declare void @llvm.loongarch.break(i32)
 declare void @llvm.loongarch.syscall(i32)
+declare i32 @llvm.loongarch.csrrd.w(i32 immarg)
+declare i32 @llvm.loongarch.csrwr.w(i32, i32 immarg)
+declare i32 @llvm.loongarch.csrxchg.w(i32, i32, i32 immarg)
 
 define void @foo() nounwind {
 ; CHECK-LABEL: foo:
@@ -46,3 +49,33 @@
   call void @llvm.loongarch.syscall(i32 1)
   ret void
 }
+
+define i32 @csrrd_w() {
+; CHECK-LABEL: csrrd_w:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:csrrd $a0, 1
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call i32 @llvm.loongarch.csrrd.w(i32 1)
+  ret i32 %0
+}
+
+define i32 @csrwr_w(i32 signext %a) {
+; CHECK-LABEL: csrwr_w:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:csrwr $a0, 1
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call i32 @llvm.loongarch.csrwr.w(i32 %a, i32 1)
+  ret i32 %0
+}
+
+define i32 @csrxchg_w(i32 signext %a, i32 signext %b) {
+; CHECK-LABEL: csrxchg_w:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:csrxchg $a0, $a1, 1
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call i32 @llvm.loongarch.csrxchg.w(i32 %a, i32 %b, i32 1)
+  ret i32 %0
+}
Index: llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
===
--- llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
+++ llvm/test/CodeGen/LoongArch/intrinsic-la64.ll
@@ -9,6 +9,9 @@
 declare i32 @llvm.loongarch.crcc.w.h.w(i32, i32)
 declare i32 @llvm.loongarch.crcc.w.w.w(i32, i32)
 declare i32 @llvm.loongarch.crcc.w.d.w(i64, i32)
+declare i64 @llvm.loongarch.csrrd.d(i32 immarg)
+declare i64 @llvm.loongarch.csrwr.d(i64, i32 immarg)
+declare i64 @llvm.loongarch.csrxchg.d(i64, i64, i32 immarg)
 
 define i32 @crc_w_b_w(i32 %a, i32 %b) nounwind {
 ; CHECK-LABEL: crc_w_b_w:
@@ -81,3 +84,33 @@
   %res = call i32 @llvm.loongarch.crcc.w.d.w(i64 %a, i32 %b)
   ret i32 %res
 }
+
+define i64 @csrrd_d() {
+; CHECK-LABEL: csrrd_d:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:csrrd $a0, 1
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call i64 @llvm.loongarch.csrrd.d(i32 1)
+  ret i64 %0
+}
+
+define i64 @csrwr_d(i64 %a) {
+; CHECK-LABEL: csrwr_d:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:csrwr $a0, 1
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call i64 @llvm.loongarch.csrwr.d(i64 %a, i32 1)
+  ret i64 %0
+}
+
+define i64 @csrxchg_d(i64 %a, i64 %b) {
+; CHECK-LABEL: csrxchg_d:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:csrxchg $a0, $a1, 1
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call i64 @llvm.loongarch.csrxchg.d(i64 %a, i64 %b, i32 1)
+  ret i64 %0
+}
Index: llvm/test/CodeGen/LoongArch/intrinsic-la64-error.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/intrinsic-la64-error.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: not llc --mtriple=loongarch64 < %s 2>&1 | FileCheck %s
+
+declare i64 @llvm.loongarch.csrrd.d(i32 immarg)
+declare i64 @llvm.loongarch.csrwr.d(i64, i32 immarg)
+declare i64 @llvm.loongarch.csrxchg.d(i64, i64, i32 immarg)
+
+define i64 @csrrd_d_imm_out_of_hi_range() nounwind {
+; CHECK: argument to 'llvm.loongarch.csrrd.d' out of range
+entry:
+  %0 = call i64 @llvm.loongarch.csrrd.d(i32 16384)
+  ret i64 %0
+}
+
+define i64 @csrrd_d_imm_out_of_lo_range() nounwind {
+; CHECK: argument to 'llvm.loongarch.csrrd.d' out of range
+entry:
+  %0 = call i64 @llvm.loongarch.csrrd.d(i32 -1)
+  ret i64 %0
+}
+
+define i64 @csrwr_d_imm_out_of_hi_range(i64 %a) nounwind {
+; CHECK: argument to 'llvm.loongarch.csrwr.d' out of range
+entry:
+  %0 = call i64 @llvm.loongarch.csrwr.d(i64 %a, i32 16384)
+  ret i64 %0
+}
+
+define i64 @csrwr_d_

[clang] b40e9dc - [clang-format] Avoid breaking )( with BlockIndent

2022-12-06 Thread Owen Pan via cfe-commits

Author: Gedare Bloom
Date: 2022-12-06T01:04:51-08:00
New Revision: b40e9dce0a67beab352f7b7be43f13190f69b69c

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

LOG: [clang-format] Avoid breaking )( with BlockIndent

The BracketAlignmentStyle BAS_BlockIndent was forcing breaks before a
closing right parenthesis yielding strange-looking results in case of
code structures that have a left parens immediately following a right
parens ")(" such as is seen with indirect function calls via function
pointers and with type casting.

Fixes 57250.
Fixes 58496.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 4e5672f244bf8..6c8f7eb6e2902 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -720,8 +720,9 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
(Previous.is(tok::l_brace) && Previous.isNot(BK_Block) &&
 Style.Cpp11BracedListStyle)) &&
   State.Column > getNewLineColumn(State) &&
-  (!Previous.Previous || !Previous.Previous->isOneOf(
- tok::kw_for, tok::kw_while, tok::kw_switch)) 
&&
+  (!Previous.Previous ||
+   !Previous.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
+   tok::kw_switch)) &&
   // Don't do this for simple (no expressions) one-argument function calls
   // as that feels like needlessly wasting whitespace, e.g.:
   //

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 889dfa5fd7a63..cc0b7719b9e52 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5016,6 +5016,11 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine 
&Line,
 !Right.MatchingParen) {
   return false;
 }
+auto Next = Right.Next;
+if (Next && Next->is(tok::r_paren))
+  Next = Next->Next;
+if (Next && Next->is(tok::l_paren))
+  return false;
 const FormatToken *Previous = Right.MatchingParen->Previous;
 return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf()));
   }

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 1db8ee94369b7..f895eb4f8df89 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7451,7 +7451,7 @@ TEST_F(FormatTest, AllowAllArgumentsOnNextLineDontAlign) {
   "void functionDecl(int A, int B,\n"
   "  int C);"),
 format(Input, Style));
-  // However, BAS_AlwaysBreak should take precedence over
+  // However, BAS_AlwaysBreak and BAS_BlockIndent should take precedence over
   // AllowAllArgumentsOnNextLine.
   Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
   EXPECT_EQ(StringRef("functionCall(\n"
@@ -7459,6 +7459,14 @@ TEST_F(FormatTest, AllowAllArgumentsOnNextLineDontAlign) 
{
   "void functionDecl(\n"
   "int A, int B, int C);"),
 format(Input, Style));
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
+  verifyFormat("functionCall(\n"
+   "paramA, paramB, paramC\n"
+   ");\n"
+   "void functionDecl(\n"
+   "int A, int B, int C\n"
+   ");",
+   Input, Style);
 
   // When AllowAllArgumentsOnNextLine is set, we prefer breaking before the
   // first argument.
@@ -8661,6 +8669,52 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
   "(a, )) &&\n"
   ");",
   Style);
+
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
+  Style.BinPackArguments = false;
+  Style.BinPackParameters = false;
+  verifyFormat("void aa(\n"
+   "aaa ,\n"
+   "a aaa,\n"
+   "a\n"
+   ") {}",
+   Style);
+  verifyFormat("SomeLongVariableName->someVeryLongFunctionName(\n"
+   "aaa a,\n"
+   "aaa a,\n"
+   "a\n"
+   ");",
+   Style);
+  verifyFormat("SomeLongVariableName->someFunction(f(\n"
+   "aaa,\n"
+   "

[PATCH] D137762: [clang-format] avoid breaking )( with BlockIndent

2022-12-06 Thread Owen Pan 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 rGb40e9dce0a67: [clang-format] Avoid breaking )( with 
BlockIndent (authored by gedare, committed by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137762

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7451,7 +7451,7 @@
   "void functionDecl(int A, int B,\n"
   "  int C);"),
 format(Input, Style));
-  // However, BAS_AlwaysBreak should take precedence over
+  // However, BAS_AlwaysBreak and BAS_BlockIndent should take precedence over
   // AllowAllArgumentsOnNextLine.
   Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
   EXPECT_EQ(StringRef("functionCall(\n"
@@ -7459,6 +7459,14 @@
   "void functionDecl(\n"
   "int A, int B, int C);"),
 format(Input, Style));
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
+  verifyFormat("functionCall(\n"
+   "paramA, paramB, paramC\n"
+   ");\n"
+   "void functionDecl(\n"
+   "int A, int B, int C\n"
+   ");",
+   Input, Style);
 
   // When AllowAllArgumentsOnNextLine is set, we prefer breaking before the
   // first argument.
@@ -8661,6 +8669,52 @@
   "(a, )) &&\n"
   ");",
   Style);
+
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
+  Style.BinPackArguments = false;
+  Style.BinPackParameters = false;
+  verifyFormat("void aa(\n"
+   "aaa ,\n"
+   "a aaa,\n"
+   "a\n"
+   ") {}",
+   Style);
+  verifyFormat("SomeLongVariableName->someVeryLongFunctionName(\n"
+   "aaa a,\n"
+   "aaa a,\n"
+   "a\n"
+   ");",
+   Style);
+  verifyFormat("SomeLongVariableName->someFunction(f(\n"
+   "aaa,\n"
+   "a,\n"
+   "a\n"
+   "));",
+   Style);
+  verifyFormat("(a(\n"
+   "(a, )\n"
+   "));",
+   Style);
+  verifyFormat("(aa.aa(\n"
+   "(a, )\n"
+   "));",
+   Style);
+  verifyFormat(
+  "(\n"
+  "a(\n"
+  "(a, )\n"
+  "),\n"
+  "\n"
+  ");",
+  Style);
+  verifyFormat(
+  "(\n"
+  "a(\n"
+  "(a, )\n"
+  ") &&\n"
+  "\n"
+  ");",
+  Style);
 }
 
 TEST_F(FormatTest, ParenthesesAndOperandAlignment) {
@@ -14580,6 +14634,13 @@
 "\"long\",\n"
 "a);",
 format("someFunction(\"long long long long\", a);", Style));
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
+  verifyFormat("someFunction(\n"
+   "\"long long long \"\n"
+   "\"long\",\n"
+   "a\n"
+   ");",
+   Style);
 }
 
 TEST_F(FormatTest, DontSplitStringLiteralsWithEscapedNewlines) {
@@ -16303,6 +16364,23 @@
"FoLong);\n"
"}",
Spaces);
+
+  Spaces.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
+  verifyFormat("void foo( ) {\n"
+   "size_t foo = (*(function))(\n"
+   "F, Bar, F, Ba, FoLong, "
+   "BaLong,\n"
+   "FoLong\n"
+   ");\n"
+   "}",
+   Spaces);
+  verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
+  verifyFormat("size_t idx = (size_t)a;", Spaces);
+  verifyFormat("size_t idx = (size_t)(a - 1);", Spaces);
+  verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
+ 

[PATCH] D138779: [include-cleaner] Filter out references that not spelled in the main file.

2022-12-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h:36
 /// Find and report all references to symbols in a region of code.
+/// It will filter out references that are not spelled in the main file.
 ///

maybe rather say `Only reports references from main file` ?



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:161
+  R"cpp(
+int target();
+#define CALL_FUNC $spell^target()

i think it's better to make declarations for `target` always part of the 
header. otherwise there are changes to both `target` and extra step in between 
(e.g. CALL_FUNC) between tests (so multiple things could go wrong and cancel 
each other).



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:177
+int target;
+#define PLUS_ONE(X) X + 1
+int a = $expand^PLUS_ONE($spell^target);

nit: i think you can still have `int target()` and convert `PLUS_ONE` to `X() + 
1` (same for other examples). (or you can do it the other way around, always 
have an `static int target = 0;`)



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:239
+
+std::optional RefLoc;
+walkUsed(TopLevelDecls, Recorded.MacroReferences,

nit: no need for `optional` SourceLocation will be invalid by default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138779

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


[PATCH] D138821: [include-cleaner] Remove filtering from UsingDecl visit.

2022-12-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 480375.
VitaNuo added a comment.

Re-introduce the isUsed check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138821

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -26,7 +26,6 @@
 namespace {
 
 // Specifies a test of which symbols are referenced by a piece of code.
-// If `// c++-header` is present, treats referencing code as a header file.
 // Target should contain points annotated with the reference kind.
 // Example:
 //   Target:  int $explicit^foo();
@@ -41,8 +40,6 @@
   Inputs.ExtraArgs.push_back("-include");
   Inputs.ExtraArgs.push_back("target.h");
   Inputs.ExtraArgs.push_back("-std=c++17");
-  if (Referencing.code().contains("// c++-header\n"))
-Inputs.ExtraArgs.push_back("-xc++-header");
   TestAST AST(Inputs);
   const auto &SM = AST.sourceManager();
 
@@ -88,12 +85,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -129,19 +124,27 @@
 }
 
 TEST(WalkAST, Using) {
-  // Make sure we ignore unused overloads.
+  // We should report unused overloads as explicit.
   testWalk(R"cpp(
 namespace ns {
-  void $explicit^x(); void x(int); void x(char);
+  void $explicit^x(); void $ambiguous^x(int); void $ambiguous^x(char);
 })cpp",
"using ns::^x; void foo() { x(); }");
-  // We should report unused overloads if main file is a header.
   testWalk(R"cpp(
 namespace ns {
   void $ambiguous^x(); void $ambiguous^x(int); void $ambiguous^x(char);
 })cpp",
-   "// c++-header\n using ns::^x;");
+   "using ns::^x;");
   testWalk("namespace ns { struct S; } using ns::$explicit^S;", "^S *s;");
+
+  // We should report references to templates as explicit.
+  testWalk(R"cpp(
+namespace ns {
+  template
+  class $ambiguous^Y {};
+}
+)cpp",
+   "using ns::^Y;");
 }
 
 TEST(WalkAST, Namespaces) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -16,7 +16,6 @@
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 
@@ -27,10 +26,6 @@
 
 class ASTWalker : public RecursiveASTVisitor {
   DeclCallback Callback;
-  // Whether we're traversing declarations coming from a header file.
-  // This helps figure out whether certain symbols can be assumed as unused
-  // (e.g. overloads brought into an implementation file, but not used).
-  bool IsHeader = false;
 
   bool handleTemplateName(SourceLocation Loc, TemplateName TN) {
 // For using-templates, only mark the alias.
@@ -50,8 +45,7 @@
   }
 
 public:
-  ASTWalker(DeclCallback Callback, bool IsHeader)
-  : Callback(Callback), IsHeader(IsHeader) {}
+  ASTWalker(DeclCallback Callback) : Callback(Callback) {}
 
   bool VisitDeclRefExpr(DeclRefExpr *DRE) {
 report(DRE->getLocation(), DRE->getFoundDecl());
@@ -82,10 +76,6 @@
 for (const auto *Shadow : UD->shadows()) {
   auto *TD = Shadow->getTargetDecl();
   auto IsUsed = TD->isUsed() || TD->isReferenced();
-  // We ignore unused overloads inside implementation files, as the ones in
-  // headers might still be used by the dependents of the header.
-  if (!IsUsed && !IsHeader)
-continue;
   report(UD->getLocation(), TD,
  IsUsed ? RefType::Explicit : RefType::Ambiguous);
 }
@@ -151,14 +141,7 @@
 } // namespace
 
 void walkAST(Decl &Root, DeclCallback Callback) {
-  auto &AST = Root.getASTContext();
-  auto &SM = AST.getSourceManager();
-  // If decl isn't written in main file, assume it's coming from an include,
-  // hence written in a header.
-  bool IsRootedAtHeader =
-  AST.getLangOpts().IsHeaderFile ||
- 

[PATCH] D138821: [include-cleaner] Remove filtering from UsingDecl visit.

2022-12-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:86
   report(UD->getLocation(), TD,
  IsUsed ? RefType::Explicit : RefType::Ambiguous);
 }

hokein wrote:
> VitaNuo wrote:
> > kadircet wrote:
> > > hokein wrote:
> > > > we should report all references as explicit.
> > > i think having `Ambiguous` here for unused symbols is fine. we'd like to 
> > > consider such symbols for the purposes of saying "yeah this include is 
> > > probably used" but we shouldn't be inserting headers for the unused ones.
> > > 
> > > do we have an example for the contrary?
> > @hokein so what would be the final conclusion then? Should I re-introduce 
> > the "isUsed" check?
> oh, right. `Ambiguous` is better, this is similar to OverloadExpr, we can't 
> prove that the symbol is used. (sorry, I somewhat had an impression this 
> should be explicit).
Ok, thank you. I have re-introduced the isUsed check now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138821

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


[PATCH] D127844: [clangd] Pull suppression logic into common path, apply for driver diagnostics

2022-12-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127844

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


[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.

2022-12-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 480378.
VitaNuo added a comment.

Address review comments, mostly style issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139087

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -172,10 +170,16 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); 
}");
+  testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); 
}");
   testWalk(
-  "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };",
+  "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };",
   "void foo() { X{}.^foo(); }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived d) { d.^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived* d) { d->^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived& d) { d.^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -49,6 +49,12 @@
 Callback(Loc, *cast(ND->getCanonicalDecl()), RT);
   }
 
+  NamedDecl *resolveType(QualType Type) {
+if (Type->isPointerType())
+  Type = Type->getPointeeType();
+return Type->getAsRecordDecl();
+  }
+
 public:
   ASTWalker(DeclCallback Callback, bool IsHeader)
   : Callback(Callback), IsHeader(IsHeader) {}
@@ -59,7 +65,13 @@
   }
 
   bool VisitMemberExpr(MemberExpr *E) {
-report(E->getMemberLoc(), E->getFoundDecl().getDecl());
+// Instead of the FieldDecl for MemberExpr, we report the Decl of
+// the corresponding record. This is done in order to report
+// the usage of most specific type (e.g., derived class, when
+// using members from the base).
+// FIXME: support dependent types, e.g., "std::vector().size()".
+QualType Type = E->getBase()->IgnoreImpCasts()->getType();
+report(E->getMemberLoc(), resolveType(Type));
 return true;
   }
 


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -172,10 +170,16 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); }");
+  testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); }");
   testWalk(
-  "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };",
+  "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };",
   "void foo() { X{}.^foo(); }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base {};",
+   "void fun(Derived d) { d.^a; }");
+  testWalk("struct Base { int a; };

[clang] 5b22c51 - [clang] Add test for CWG952

2022-12-06 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2022-12-06T12:27:22+03:00
New Revision: 5b22c5129c11f5c762c5092d7c52e1ac3d536903

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

LOG: [clang] Add test for CWG952

P1787: // [[ https://wg21.link/cwg952 | CWG952 ]] is resolved by refining the 
definition of “naming class” per Richard’s suggestion in [[ 
https://lists.isocpp.org/core/2020/09/9963.php | “CWG1621 and 
[class.static/2”]].//
Wording:
- [class.static]/2 removed;
- [class.access.base]/5 rephrased.

Currently behavior is the following: unqualified names undergo //unqualified 
name lookup// [1], which perform //unqualified search// in immediate scope [2]. 
This scope is the scope the definition of //naming class// [3] refers to. 
`A::I` is not //accessible// when named in classes `C` and `D` per [3]. In 
particular, the last item regarding base class ([class.access.base]/5.4) is not 
applicable, because class `A` is not //accessible// in both classes `C` and `D` 
per [4].

References:
1. [[ https://eel.is/c++draft/basic.lookup#unqual-4.sentence-2 | 
basic.lookup.unqual/4 ]]
2. [[ https://eel.is/c++draft/basic.lookup#unqual-3 | basic.lookup.unqual/3 ]]
3. [[ https://eel.is/c++draft/class.access#base-5.sentence-4 | 
class.access.base/5 ]]
4. [[ https://eel.is/c++draft/class.access#base-4 | class.access.base/4 ]]

Reviewed By: #clang-language-wg, erichkeane, aaron.ballman

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

Added: 


Modified: 
clang/test/CXX/drs/dr9xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr9xx.cpp b/clang/test/CXX/drs/dr9xx.cpp
index db40c8a01a8d3..039ba431e4a1f 100644
--- a/clang/test/CXX/drs/dr9xx.cpp
+++ b/clang/test/CXX/drs/dr9xx.cpp
@@ -1,11 +1,9 @@
 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
-// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
-
-#if __cplusplus < 201103L
-// expected-no-diagnostics
-#endif
+// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 
 namespace std {
   __extension__ typedef __SIZE_TYPE__ size_t;
@@ -74,6 +72,34 @@ namespace dr948 { // dr948: 3.7
 #endif
 }
 
+namespace dr952 { // dr952: yes
+struct A {
+  typedef int I; // #dr952-typedef-decl
+};
+struct B : private A { // #dr952-inheritance
+};
+struct C : B {
+  void f() {
+I i1; // expected-error {{private member}}
+// expected-note@#dr952-inheritance {{constrained by private inheritance}}
+// expected-note@#dr952-typedef-decl {{declared here}}
+  }
+  I i2; // expected-error {{private member}}
+  // expected-note@#dr952-inheritance {{constrained by private inheritance}}
+  // expected-note@#dr952-typedef-decl {{declared here}}
+  struct D {
+I i3; // expected-error {{private member}}
+// expected-note@#dr952-inheritance {{constrained by private inheritance}}
+// expected-note@#dr952-typedef-decl {{declared here}}
+void g() {
+  I i4; // expected-error {{private member}}
+  // expected-note@#dr952-inheritance {{constrained by private 
inheritance}}
+  // expected-note@#dr952-typedef-decl {{declared here}}
+}
+  };
+};
+} // namespace dr952
+
 namespace dr974 { // dr974: yes
 #if __cplusplus >= 201103L
   void test() {

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 6fa7ead4138d5..73d238354bd5b 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -5520,7 +5520,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg952";>952
 CD6
 Insufficient description of “naming class”
-Unknown
+Yes
   
   
 https://wg21.link/cwg953";>953



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


[PATCH] D139326: [clang] Add test for CWG952

2022-12-06 Thread Vlad Serebrennikov 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 rG5b22c5129c11: [clang] Add test for CWG952 (authored by 
Endill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139326

Files:
  clang/test/CXX/drs/dr9xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -5520,7 +5520,7 @@
 https://wg21.link/cwg952";>952
 CD6
 Insufficient description of “naming class”
-Unknown
+Yes
   
   
 https://wg21.link/cwg953";>953
Index: clang/test/CXX/drs/dr9xx.cpp
===
--- clang/test/CXX/drs/dr9xx.cpp
+++ clang/test/CXX/drs/dr9xx.cpp
@@ -1,11 +1,9 @@
 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
-// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
-
-#if __cplusplus < 201103L
-// expected-no-diagnostics
-#endif
+// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 
 namespace std {
   __extension__ typedef __SIZE_TYPE__ size_t;
@@ -74,6 +72,34 @@
 #endif
 }
 
+namespace dr952 { // dr952: yes
+struct A {
+  typedef int I; // #dr952-typedef-decl
+};
+struct B : private A { // #dr952-inheritance
+};
+struct C : B {
+  void f() {
+I i1; // expected-error {{private member}}
+// expected-note@#dr952-inheritance {{constrained by private inheritance}}
+// expected-note@#dr952-typedef-decl {{declared here}}
+  }
+  I i2; // expected-error {{private member}}
+  // expected-note@#dr952-inheritance {{constrained by private inheritance}}
+  // expected-note@#dr952-typedef-decl {{declared here}}
+  struct D {
+I i3; // expected-error {{private member}}
+// expected-note@#dr952-inheritance {{constrained by private inheritance}}
+// expected-note@#dr952-typedef-decl {{declared here}}
+void g() {
+  I i4; // expected-error {{private member}}
+  // expected-note@#dr952-inheritance {{constrained by private 
inheritance}}
+  // expected-note@#dr952-typedef-decl {{declared here}}
+}
+  };
+};
+} // namespace dr952
+
 namespace dr974 { // dr974: yes
 #if __cplusplus >= 201103L
   void test() {


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -5520,7 +5520,7 @@
 https://wg21.link/cwg952";>952
 CD6
 Insufficient description of “naming class”
-Unknown
+Yes
   
   
 https://wg21.link/cwg953";>953
Index: clang/test/CXX/drs/dr9xx.cpp
===
--- clang/test/CXX/drs/dr9xx.cpp
+++ clang/test/CXX/drs/dr9xx.cpp
@@ -1,11 +1,9 @@
 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
-
-#if __cplusplus < 201103L
-// expected-no-diagnostics
-#endif
+// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 
 namespace std {
   __extension__ typedef __SIZE_TYPE__ size_t;
@@ -74,6 +72,34 @@
 #endif
 }
 
+namespace dr952 { // dr952: yes
+struct A {
+  typedef int I; // #dr952-typedef-decl
+};
+struct B : private A { // #dr952-inheritance
+};
+struct C : B {
+  void f() {
+I i1; // expected-error {{private member}}
+// expected-note@#dr952-inheritance {{constrained by private inheritance}}
+// expected-note@#dr952-typedef-decl {{declared here}}
+  }
+  I i2; // expected-error {{private member}}
+  // expected-note@#dr952-inheritance {{constrained by private inheritance}}
+  // expected-note@#dr952-typedef-decl {{declared here}}
+  struct D {
+I i3; // expected-error {{private member}}
+// expected-note@#dr952-inheritance {{constrained by private inheritance}}
+// expected-note@#dr952-typedef-decl {{declared here}}
+void g() {
+  I i4; // expected-error {{private member}}
+  // expected-note@#d

[PATCH] D138788: [SVE] Change some bfloat lane intrinsics to use i32 immediates

2022-12-06 Thread David Sherwood via Phabricator via cfe-commits
david-arm marked an inline comment as done.
david-arm added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsAArch64.td:2527
 
-def int_aarch64_sve_bfdot_lane   : SVE_4Vec_BF16_Indexed;
-def int_aarch64_sve_bfmlalb_lane : SVE_4Vec_BF16_Indexed;
-def int_aarch64_sve_bfmlalt_lane : SVE_4Vec_BF16_Indexed;
+def int_aarch64_sve_bfdot_lane   : SVE_4Vec_BF16_Indexed;
+def int_aarch64_sve_bfdot_lane_i32   : SVE_4Vec_BF16_Indexed_I32;

paulwalker-arm wrote:
> david-arm wrote:
> > sdesmalen wrote:
> > > do you also want to remove the old intrinsics?
> > Good spot! Turns out that not only had I done this wrong, but I'd also 
> > missed out upgrades for bfmlalb/t too. :)
> Having `_i32` in the name is confusing because it'll come out as `.i32` when 
> printed in IR, which looks like a type suffix but in this case it's actually 
> part of the name.
> 
> With that said, do you have to change the name?  That seems unfortunate given 
> this is a bug fix.
> 
> If it's absolutely necessary then I suggestion using `_v2` to signify this is 
> the second version of this intrinsic.
Sadly @paulwalker-arm the auto-upgrade mechanism forbids you from upgrading to 
an intrinsic of the same name. I don't really know why we have that restriction 
though, since in theory I could decide to upgrade only when the index is a i64 
type. I'll use _v2 then!


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

https://reviews.llvm.org/D138788

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


[clang] 80bae9a - [clang] Add test for CWG405

2022-12-06 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2022-12-06T12:35:21+03:00
New Revision: 80bae9aacc1452d18bfb1fe7437f5dcd160614d3

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

LOG: [clang] Add test for CWG405

P1787: //CWG405 is resolved by stating that argument-dependent lookup 
(sometimes) occurs after an ordinary unqualified lookup (making statements like 
“finding a variable prevents argument-dependent lookup” formally correct).//
Wording: see changes to [basic.lookup.argdep] p1 and p3

This issue seems a duplicate of CWG218, even though it is not officially 
recognized. A part of a test for CWG218 is reused here, adding cross-references.

Reviewed By: #clang-language-wg, aaron.ballman

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

Added: 


Modified: 
clang/test/CXX/drs/dr2xx.cpp
clang/test/CXX/drs/dr4xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr2xx.cpp b/clang/test/CXX/drs/dr2xx.cpp
index c76b65ddeef56..31ac31b088105 100644
--- a/clang/test/CXX/drs/dr2xx.cpp
+++ b/clang/test/CXX/drs/dr2xx.cpp
@@ -141,6 +141,7 @@ namespace dr217 { // dr217: yes
 }
 
 namespace dr218 { // dr218: yes
+  // NB: also dup 405
   namespace A {
 struct S {};
 void f(S);

diff  --git a/clang/test/CXX/drs/dr4xx.cpp b/clang/test/CXX/drs/dr4xx.cpp
index 4e437b272087b..1814f5ac32185 100644
--- a/clang/test/CXX/drs/dr4xx.cpp
+++ b/clang/test/CXX/drs/dr4xx.cpp
@@ -3,6 +3,7 @@
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++14 
%s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++17 
%s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++20 
%s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++2b 
%s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 
 // FIXME: __SIZE_TYPE__ expands to 'long long' on some targets.
 __extension__ typedef __SIZE_TYPE__ size_t;
@@ -79,6 +80,40 @@ namespace dr403 { // dr403: yes
 // dr404: na
 // (NB: also sup 594)
 
+namespace dr405 { // dr405: yes
+  // NB: also dup 218
+  namespace A {
+struct S {};
+void f(S);
+  }
+  namespace B {
+struct S {};
+void f(S);
+  }
+
+  struct C {
+int f;
+void test1(A::S as) { f(as); } // expected-error {{called object type 
'int'}}
+void test2(A::S as) { void f(); f(as); } // expected-error {{too many 
arguments}} expected-note {{}}
+void test3(A::S as) { using A::f; f(as); } // ok
+void test4(A::S as) { using B::f; f(as); } // ok
+void test5(A::S as) { int f; f(as); } // expected-error {{called object 
type 'int'}}
+void test6(A::S as) { struct f {}; (void) f(as); } // expected-error {{no 
matching conversion}} expected-note +{{}}
+  };
+
+  namespace D {
+struct S {};
+struct X { void operator()(S); } f;
+  }
+  void testD(D::S ds) { f(ds); } // expected-error {{undeclared identifier}}
+
+  namespace E {
+struct S {};
+struct f { f(S); };
+  }
+  void testE(E::S es) { f(es); } // expected-error {{undeclared identifier}}
+}
+
 namespace dr406 { // dr406: yes
   typedef struct {
 static int n; // expected-error {{static data member 'n' not allowed in 
anonymous struct}}

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 73d238354bd5b..befe27262850c 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -2470,7 +2470,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg405";>405
 CD6
 Unqualified function name lookup
-Unknown
+Yes
   
   
 https://wg21.link/cwg406";>406



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


[PATCH] D139095: [clang] Add test for CWG405

2022-12-06 Thread Vlad Serebrennikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG80bae9aacc14: [clang] Add test for CWG405 (authored by 
Endill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139095

Files:
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/drs/dr4xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -2470,7 +2470,7 @@
 https://wg21.link/cwg405";>405
 CD6
 Unqualified function name lookup
-Unknown
+Yes
   
   
 https://wg21.link/cwg406";>406
Index: clang/test/CXX/drs/dr4xx.cpp
===
--- clang/test/CXX/drs/dr4xx.cpp
+++ clang/test/CXX/drs/dr4xx.cpp
@@ -3,6 +3,7 @@
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++14 
%s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++17 
%s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++20 
%s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++2b 
%s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 
 // FIXME: __SIZE_TYPE__ expands to 'long long' on some targets.
 __extension__ typedef __SIZE_TYPE__ size_t;
@@ -79,6 +80,40 @@
 // dr404: na
 // (NB: also sup 594)
 
+namespace dr405 { // dr405: yes
+  // NB: also dup 218
+  namespace A {
+struct S {};
+void f(S);
+  }
+  namespace B {
+struct S {};
+void f(S);
+  }
+
+  struct C {
+int f;
+void test1(A::S as) { f(as); } // expected-error {{called object type 
'int'}}
+void test2(A::S as) { void f(); f(as); } // expected-error {{too many 
arguments}} expected-note {{}}
+void test3(A::S as) { using A::f; f(as); } // ok
+void test4(A::S as) { using B::f; f(as); } // ok
+void test5(A::S as) { int f; f(as); } // expected-error {{called object 
type 'int'}}
+void test6(A::S as) { struct f {}; (void) f(as); } // expected-error {{no 
matching conversion}} expected-note +{{}}
+  };
+
+  namespace D {
+struct S {};
+struct X { void operator()(S); } f;
+  }
+  void testD(D::S ds) { f(ds); } // expected-error {{undeclared identifier}}
+
+  namespace E {
+struct S {};
+struct f { f(S); };
+  }
+  void testE(E::S es) { f(es); } // expected-error {{undeclared identifier}}
+}
+
 namespace dr406 { // dr406: yes
   typedef struct {
 static int n; // expected-error {{static data member 'n' not allowed in 
anonymous struct}}
Index: clang/test/CXX/drs/dr2xx.cpp
===
--- clang/test/CXX/drs/dr2xx.cpp
+++ clang/test/CXX/drs/dr2xx.cpp
@@ -141,6 +141,7 @@
 }
 
 namespace dr218 { // dr218: yes
+  // NB: also dup 405
   namespace A {
 struct S {};
 void f(S);


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -2470,7 +2470,7 @@
 https://wg21.link/cwg405";>405
 CD6
 Unqualified function name lookup
-Unknown
+Yes
   
   
 https://wg21.link/cwg406";>406
Index: clang/test/CXX/drs/dr4xx.cpp
===
--- clang/test/CXX/drs/dr4xx.cpp
+++ clang/test/CXX/drs/dr4xx.cpp
@@ -3,6 +3,7 @@
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 
 // FIXME: __SIZE_TYPE__ expands to 'long long' on some targets.
 __extension__ typedef __SIZE_TYPE__ size_t;
@@ -79,6 +80,40 @@
 // dr404: na
 // (NB: also sup 594)
 
+namespace dr405 { // dr405: yes
+  // NB: also dup 218
+  namespace A {
+struct S {};
+void f(S);
+  }
+  namespace B {
+struct S {};
+void f(S);
+  }
+
+  struct C {
+int f;
+void test1(A::S as) { f(as); } // expected-error {{called object type 'int'}}
+void test2(A::S as) { void f(); f(as); } // expected-error {{too many arguments}} expected-note {{}}
+void test3(A::S as) { using A::f; f(as); } // ok
+void test4(A::S as) { using B::f; f(as); } // ok
+void test5(A::S as) { int f; f(as); } // expected-error {{called object

[clang] 6d971cb - [clang] Mark CWG554 as N/A

2022-12-06 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2022-12-06T12:39:19+03:00
New Revision: 6d971cb840dbb3f05689469bf11e49046ce2fae1

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

LOG: [clang] Mark CWG554 as N/A

P1787: //CWG554 is resolved by using the word “scope” instead of “declarative 
region”, consistent with its very common use in phrases like “namespace 
scope”.//

Reviewed By: #clang-language-wg, cor3ntin, aaron.ballman, shafik

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

Added: 


Modified: 
clang/test/CXX/drs/dr5xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr5xx.cpp b/clang/test/CXX/drs/dr5xx.cpp
index c48987853115..b5b7be179248 100644
--- a/clang/test/CXX/drs/dr5xx.cpp
+++ b/clang/test/CXX/drs/dr5xx.cpp
@@ -602,6 +602,7 @@ namespace dr553 {
   };
 }
 
+// dr554: na
 // dr556: na
 
 namespace dr557 { // dr557: yes

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index befe27262850..06783c0ff41b 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -3366,7 +3366,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg554";>554
 CD6
 Definition of “declarative region” and 
“scope”
-Unknown
+N/A
   
   
 https://wg21.link/cwg555";>555



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


[PATCH] D139172: [clang] Mark CWG554 as N/A

2022-12-06 Thread Vlad Serebrennikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6d971cb840db: [clang] Mark CWG554 as N/A (authored by 
Endill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139172

Files:
  clang/test/CXX/drs/dr5xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -3366,7 +3366,7 @@
 https://wg21.link/cwg554";>554
 CD6
 Definition of “declarative region” and 
“scope”
-Unknown
+N/A
   
   
 https://wg21.link/cwg555";>555
Index: clang/test/CXX/drs/dr5xx.cpp
===
--- clang/test/CXX/drs/dr5xx.cpp
+++ clang/test/CXX/drs/dr5xx.cpp
@@ -602,6 +602,7 @@
   };
 }
 
+// dr554: na
 // dr556: na
 
 namespace dr557 { // dr557: yes


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -3366,7 +3366,7 @@
 https://wg21.link/cwg554";>554
 CD6
 Definition of “declarative region” and “scope”
-Unknown
+N/A
   
   
 https://wg21.link/cwg555";>555
Index: clang/test/CXX/drs/dr5xx.cpp
===
--- clang/test/CXX/drs/dr5xx.cpp
+++ clang/test/CXX/drs/dr5xx.cpp
@@ -602,6 +602,7 @@
   };
 }
 
+// dr554: na
 // dr556: na
 
 namespace dr557 { // dr557: yes
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2fbe3f9 - [Clang] make_cxx_dr_status download the issue list automatically

2022-12-06 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-12-06T10:40:06+01:00
New Revision: 2fbe3f9e7941858e9c856474737b5a1420448eb8

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

LOG: [Clang] make_cxx_dr_status download the issue list automatically

if none is provided

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/www/cxx_dr_status.html
clang/www/make_cxx_dr_status

Removed: 




diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 06783c0ff41b..d5f52b3bc9d6 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1,9 +1,8 @@
-http://www.w3.org/TR/html4/strict.dtd";>
+
 
 
 
-  
+  
   Clang - C++ Defect Report Status
   
   

diff  --git a/clang/www/make_cxx_dr_status b/clang/www/make_cxx_dr_status
index 922a3810ec9a..1b4fdb6c6184 100755
--- a/clang/www/make_cxx_dr_status
+++ b/clang/www/make_cxx_dr_status
@@ -1,18 +1,12 @@
 #! /usr/bin/env python3
-import sys, os, re
+import sys, os, re, urllib.request
 
-index = 'cwg_index.html'
+
+default_issue_list_path = 'cwg_index.html'
+issue_list_url = "https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_index.html";
 output = 'cxx_dr_status.html'
 dr_test_dir = '../test/CXX/drs'
 
-if len(sys.argv) == 1:
-  pass
-elif len(sys.argv) == 2:
-  index = sys.argv[1]
-else:
-  print('Usage: make_drs []', file=sys.stderr)
-  sys.exit(1)
-
 class DR:
   def __init__(self, section, issue, url, status, title):
 self.section, self.issue, self.url, self.status, self.title = \
@@ -31,29 +25,61 @@ def parse(dr):
   title = title.replace('', '').replace('', 
'').replace('\r\n', '\n').strip()
   return DR(section, issue, url, status, title)
 
-status_re = re.compile(r'\bdr([0-9]+): (.*)')
-status_map = {}
-for test_cpp in os.listdir(dr_test_dir):
-  if not test_cpp.endswith('.cpp'):
-continue
-  test_cpp = os.path.join(dr_test_dir, test_cpp)
-  found_any = False;
-  for match in re.finditer(status_re, open(test_cpp, 'r').read()):
-status_map[int(match.group(1))] = match.group(2)
-found_any = True
-  if not found_any:
-print("warning:%s: no '// dr123: foo' comments in this file" % test_cpp, 
file=sys.stderr)
-
-drs = sorted((parse(dr) for dr in open(index, 'r').read().split('')[2:]),
- key = lambda dr: dr.issue)
+def collect_tests():
+  status_re = re.compile(r'\bdr([0-9]+): (.*)')
+  status_map = {}
+  for test_cpp in os.listdir(dr_test_dir):
+if not test_cpp.endswith('.cpp'):
+  continue
+test_cpp = os.path.join(dr_test_dir, test_cpp)
+found_any = False;
+for match in re.finditer(status_re, open(test_cpp, 'r').read()):
+  status_map[int(match.group(1))] = match.group(2)
+  found_any = True
+if not found_any:
+  print("warning:%s: no '// dr123: foo' comments in this file" % test_cpp, 
file=sys.stderr)
+  return status_map
+
+def get_issues(path):
+  buffer = None
+  if not path and os.path.exists(default_issue_list_path):
+path = default_issue_list_path
+  try:
+if path is None:
+  print('Fetching issue list from {}'.format(issue_list_url))
+  with urllib.request.urlopen(issue_list_url) as f:
+buffer = f.read().decode('utf-8')
+else:
+  print('Opening issue list from file {}'.format(path))
+  with open(path, 'r') as f:
+buffer = f.read()
+  except Exception as ex:
+ print('Unable to read the core issue list', file=sys.stderr)
+ print(ex, file=sys.stderr)
+ sys.exit(1)
+
+  return sorted((parse(dr) for dr in buffer.split('')[2:]),
+key = lambda dr: dr.issue)
+
+
+issue_list_path  = None
+if len(sys.argv) == 1:
+  pass
+elif len(sys.argv) == 2:
+  issue_list_path = sys.argv[1]
+else:
+  print('Usage: {} []'.format(sys.argv[0]), 
file=sys.stderr)
+  sys.exit(1)
+
+status_map = collect_tests()
+drs = get_issues(issue_list_path)
 out_file = open(output, 'w')
 out_file.write('''\
-http://www.w3.org/TR/html4/strict.dtd";>
+
 
 
 
-  
+  
   Clang - C++ Defect Report Status
   
   
@@ -95,7 +121,7 @@ latest_release = 15
 
 def availability(issue):
   status = status_map.get(issue, 'unknown')
-  
+
   unresolved_status = ''
   if status.endswith(' open'):
 status = status[:-5]
@@ -173,10 +199,12 @@ for dr in drs:
 # This refers to the old ("C++0x") concepts feature, which was not part
 # of any C++ International Standard or Technical Specification.
 continue
+
   elif dr.status == 'extension':
 row_style = ' class="open"'
 avail = 'Extension'
 avail_style = ''
+
   elif dr.status in ('open', 'drafting', 'review'):
 row_style = ' class="open"'
 avail, avail_style, unresolved_status = availability(dr.issue)
@@ -187,16 +215,15 @@ for dr in drs:
   assert unresolved_status == dr.status, \

[PATCH] D139212: [Clang] make_cxx_dr_status download the issue list automatically

2022-12-06 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2fbe3f9e7941: [Clang] make_cxx_dr_status download the issue 
list automatically (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139212

Files:
  clang/www/cxx_dr_status.html
  clang/www/make_cxx_dr_status

Index: clang/www/make_cxx_dr_status
===
--- clang/www/make_cxx_dr_status
+++ clang/www/make_cxx_dr_status
@@ -1,18 +1,12 @@
 #! /usr/bin/env python3
-import sys, os, re
+import sys, os, re, urllib.request
 
-index = 'cwg_index.html'
+
+default_issue_list_path = 'cwg_index.html'
+issue_list_url = "https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_index.html";
 output = 'cxx_dr_status.html'
 dr_test_dir = '../test/CXX/drs'
 
-if len(sys.argv) == 1:
-  pass
-elif len(sys.argv) == 2:
-  index = sys.argv[1]
-else:
-  print('Usage: make_drs []', file=sys.stderr)
-  sys.exit(1)
-
 class DR:
   def __init__(self, section, issue, url, status, title):
 self.section, self.issue, self.url, self.status, self.title = \
@@ -31,29 +25,61 @@
   title = title.replace('', '').replace('', '').replace('\r\n', '\n').strip()
   return DR(section, issue, url, status, title)
 
-status_re = re.compile(r'\bdr([0-9]+): (.*)')
-status_map = {}
-for test_cpp in os.listdir(dr_test_dir):
-  if not test_cpp.endswith('.cpp'):
-continue
-  test_cpp = os.path.join(dr_test_dir, test_cpp)
-  found_any = False;
-  for match in re.finditer(status_re, open(test_cpp, 'r').read()):
-status_map[int(match.group(1))] = match.group(2)
-found_any = True
-  if not found_any:
-print("warning:%s: no '// dr123: foo' comments in this file" % test_cpp, file=sys.stderr)
-
-drs = sorted((parse(dr) for dr in open(index, 'r').read().split('')[2:]),
- key = lambda dr: dr.issue)
+def collect_tests():
+  status_re = re.compile(r'\bdr([0-9]+): (.*)')
+  status_map = {}
+  for test_cpp in os.listdir(dr_test_dir):
+if not test_cpp.endswith('.cpp'):
+  continue
+test_cpp = os.path.join(dr_test_dir, test_cpp)
+found_any = False;
+for match in re.finditer(status_re, open(test_cpp, 'r').read()):
+  status_map[int(match.group(1))] = match.group(2)
+  found_any = True
+if not found_any:
+  print("warning:%s: no '// dr123: foo' comments in this file" % test_cpp, file=sys.stderr)
+  return status_map
+
+def get_issues(path):
+  buffer = None
+  if not path and os.path.exists(default_issue_list_path):
+path = default_issue_list_path
+  try:
+if path is None:
+  print('Fetching issue list from {}'.format(issue_list_url))
+  with urllib.request.urlopen(issue_list_url) as f:
+buffer = f.read().decode('utf-8')
+else:
+  print('Opening issue list from file {}'.format(path))
+  with open(path, 'r') as f:
+buffer = f.read()
+  except Exception as ex:
+ print('Unable to read the core issue list', file=sys.stderr)
+ print(ex, file=sys.stderr)
+ sys.exit(1)
+
+  return sorted((parse(dr) for dr in buffer.split('')[2:]),
+key = lambda dr: dr.issue)
+
+
+issue_list_path  = None
+if len(sys.argv) == 1:
+  pass
+elif len(sys.argv) == 2:
+  issue_list_path = sys.argv[1]
+else:
+  print('Usage: {} []'.format(sys.argv[0]), file=sys.stderr)
+  sys.exit(1)
+
+status_map = collect_tests()
+drs = get_issues(issue_list_path)
 out_file = open(output, 'w')
 out_file.write('''\
-http://www.w3.org/TR/html4/strict.dtd";>
+
 
 
 
-  
+  
   Clang - C++ Defect Report Status
   
   
@@ -95,7 +121,7 @@
 
 def availability(issue):
   status = status_map.get(issue, 'unknown')
-  
+
   unresolved_status = ''
   if status.endswith(' open'):
 status = status[:-5]
@@ -173,10 +199,12 @@
 # This refers to the old ("C++0x") concepts feature, which was not part
 # of any C++ International Standard or Technical Specification.
 continue
+
   elif dr.status == 'extension':
 row_style = ' class="open"'
 avail = 'Extension'
 avail_style = ''
+
   elif dr.status in ('open', 'drafting', 'review'):
 row_style = ' class="open"'
 avail, avail_style, unresolved_status = availability(dr.issue)
@@ -187,16 +215,15 @@
   assert unresolved_status == dr.status, \
  "Issue %s is marked '%s', which differs from CWG index status '%s'" \
  % (dr.issue, unresolved_status, dr.status)
-if not avail.startswith('Sup') and not avail.startswith('Dup'):
-  count[avail] = count.get(avail, 0) + 1
   else:
 row_style = ''
 avail, avail_style, unresolved_status = availability(dr.issue)
 assert not unresolved_status, \
"Issue %s is marked '%s', even though it is resolved in CWG index" \
% (dr.issue, unresolved_status)
-if not avail.startswith('Sup') and not avail.startswith('Dup'):
-  count[avail] = count.get(avail, 0) + 1
+
+  if not avai

[clang] 7e31d07 - [clang] Add test for CWG600

2022-12-06 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2022-12-06T12:42:35+03:00
New Revision: 7e31d0723dbf8ab9355cb58cfc6309be51be3e25

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

LOG: [clang] Add test for CWG600

P1787: //CWG600 is resolved by explaining that accessibility affects naming a 
member in the sense of the ODR.//
Wording: see changes to [class.access] p1 and p4.
Additional references: [[ http://eel.is/c++draft/basic.def.odr#8.sentence-2 | 
basic.def.odr/8 ]]: //A function is odr-used if it is named by a 
potentially-evaluated expression or conversion.//

Reviewed By: #clang-language-wg, aaron.ballman

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

Added: 


Modified: 
clang/test/CXX/drs/dr6xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr6xx.cpp b/clang/test/CXX/drs/dr6xx.cpp
index 494d857e829a..f9925e22085b 100644
--- a/clang/test/CXX/drs/dr6xx.cpp
+++ b/clang/test/CXX/drs/dr6xx.cpp
@@ -3,6 +3,22 @@
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
+// RUN: %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
+
+namespace dr600 { // dr600: yes
+struct S {
+  void f(int);
+
+private:
+  void f(double); // expected-note {{declared private here}}
+};
+
+void g(S *sp) {
+  sp->f(2);
+  // access control is applied after overload resolution
+  sp->f(2.2); // expected-error {{is a private member}}
+}
+} // namespace dr600
 
 namespace std {
   struct type_info {};

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index d5f52b3bc9d6..33ab66fcbeb6 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -3641,7 +3641,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg600";>600
 CD6
 Does access control apply to members or to names?
-Unknown
+Yes
   
   
 https://wg21.link/cwg601";>601



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


[PATCH] D139173: [clang] Add test for CWG600

2022-12-06 Thread Vlad Serebrennikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7e31d0723dbf: [clang] Add test for CWG600 (authored by 
Endill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139173

Files:
  clang/test/CXX/drs/dr6xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -3641,7 +3641,7 @@
 https://wg21.link/cwg600";>600
 CD6
 Does access control apply to members or to names?
-Unknown
+Yes
   
   
 https://wg21.link/cwg601";>601
Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -3,6 +3,22 @@
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
+// RUN: %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors -fno-spell-checking
+
+namespace dr600 { // dr600: yes
+struct S {
+  void f(int);
+
+private:
+  void f(double); // expected-note {{declared private here}}
+};
+
+void g(S *sp) {
+  sp->f(2);
+  // access control is applied after overload resolution
+  sp->f(2.2); // expected-error {{is a private member}}
+}
+} // namespace dr600
 
 namespace std {
   struct type_info {};


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -3641,7 +3641,7 @@
 https://wg21.link/cwg600";>600
 CD6
 Does access control apply to members or to names?
-Unknown
+Yes
   
   
 https://wg21.link/cwg601";>601
Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -3,6 +3,22 @@
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
+// RUN: %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
+
+namespace dr600 { // dr600: yes
+struct S {
+  void f(int);
+
+private:
+  void f(double); // expected-note {{declared private here}}
+};
+
+void g(S *sp) {
+  sp->f(2);
+  // access control is applied after overload resolution
+  sp->f(2.2); // expected-error {{is a private member}}
+}
+} // namespace dr600
 
 namespace std {
   struct type_info {};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3f65691 - [NFC] Remove const from return value of function

2022-12-06 Thread Juan Manuel MARTINEZ CAAMAÑO via cfe-commits

Author: Juan Manuel MARTINEZ CAAMAÑO
Date: 2022-12-06T04:46:33-05:00
New Revision: 3f65691737641c3b46bee11c9cf0e52046af3a49

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

LOG: [NFC] Remove const from return value of function

Added: 


Modified: 
clang/lib/Driver/ToolChains/ROCm.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/ROCm.h 
b/clang/lib/Driver/ToolChains/ROCm.h
index 600c8b39f4b31..5c1431f3270cf 100644
--- a/clang/lib/Driver/ToolChains/ROCm.h
+++ b/clang/lib/Driver/ToolChains/ROCm.h
@@ -266,7 +266,7 @@ class RocmInstallationDetector {
   void detectHIPRuntime();
 
   /// Get the values for --rocm-device-lib-path arguments
-  const ArrayRef getRocmDeviceLibPathArg() const {
+  ArrayRef getRocmDeviceLibPathArg() const {
 return RocmDeviceLibPathArg;
   }
 



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


[PATCH] D138200: [include-cleaner] Make use of locateSymbol in WalkUsed

2022-12-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:44
+
+  // Cache for decl to header mappings, as the same decl might be referenced in
+  // multiple locations and finding providers for each location is expensive.

kadircet wrote:
> hokein wrote:
> > I agree the place here might be on a performance-critical path, but I think 
> > the idea of using cache probably needs some bits of design, the current 
> > implementation seems half baked (there is also a FIXME in the 
> > findAllHeaders saying we should implement another cache for it, so it is 
> > unclear to me what's the whole picture).
> > 
> > Can we just leave out all cache in this patch with a FIXME? And having a 
> > follow-up patch for that?
> i agree that the cache for `findHeaders` is a bit more nuanced, as it'll need 
> to have assumptions about a given `SymbolLocation`, no matter how/where it 
> was acquired will return the same results.
> but i am not sure what's complicated/unclear about the cache for decl to 
> headers. The benefit is clear as explained in the comment around saving 
> computations every time a `foo` is referenced inside the file.
> Since both the benefit is clear and the assumption around "a `decl` having 
> the same set of providers" sounds simple and sane enough, i'd actually keep 
> this one in.
I also think this needs a bit more examination. It seems cheap, but there are 
several overlapping concerns and addressing the first is always cheap but makes 
the others more expensive.

e.g. here, it's not obvious which of these is most desirable and therefore 
should probably be done first:
 - caching symbol => header
 - caching (part of) location => header
 - caching/optimizing location => fileid
 - propagating signals across these steps
 - exposing location from the API
 - keeping the implementation simple

I don't personally have a strong intuition of which of these steps should be 
cached for performance, if any of them will really matter, and whether we're 
better off caching end-to-end (cache a longer computation, lower hit-rate) vs 
individual steps (small computation, higher hit-rate).

To me this seems premature without *at least* measuring that it improves 
performance, but ideally showing that it's better than caching at a different 
level.



Comment at: clang-tools-extra/include-cleaner/test/html.cpp:7
 int n = foo();
+// CHECK: Symbol{{.*}}foo
+// CHECK-NEXT: int foo()

I'd like to keep a very simple smoke test of the HTML report.

If you're aiming to test something specific here about the HTML report, I'd 
suggest creating a new test describing what it is. (Though generally speaking, 
the HTML test has poor test coverage of its details, which I think is 
unfortunately the right tradeoff)

If you're aiming to provide an integration test (these locations are taken into 
account in making overall decisions), I think this should be a test using 
`-print=changes` rather than -html.



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:61
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls())
+  TopLevelDecls.emplace_back(D);

shouldn't we have a location filter for the decls, to simulate RecordAST?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138200

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


[PATCH] D138253: [-Wunsafe-buffer-usage] NFC: Implement fix-strategies and variable-use-claiming.

2022-12-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 480394.
NoQ marked 9 inline comments as done.
NoQ added a comment.

A cleaner way to implement the debug facility.


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

https://reviews.llvm.org/D138253

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
  clang/lib/Analysis/UnsafeBufferUsage.cpp

Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -13,11 +13,123 @@
 using namespace clang;
 using namespace ast_matchers;
 
-namespace {
-// TODO: Better abstractions over gadgets.
-using GadgetList = std::vector;
+// Because we're dealing with raw pointers, let's define what we mean by that.
+static auto hasPointerType() {
+  return anyOf(hasType(pointerType()),
+   hasType(autoType(hasDeducedType(
+   hasUnqualifiedDesugaredType(pointerType());
 }
 
+namespace {
+/// Gadget is an individual operation in the code that may be of interest to
+/// this analysis. Each (non-abstract) subclass corresponds to a specific
+/// rigid AST structure that constitutes an operation on a pointer-type object.
+/// Discovery of a gadget in the code corresponds to claiming that we understand
+/// what this part of code is doing well enough to potentially improve it.
+/// Gadgets can be unsafe (immediately deserving a warning) or safe (not
+/// deserving a warning per se, but affecting our decision-making process
+/// nonetheless).
+class Gadget {
+public:
+  enum class Kind {
+#define GADGET(x) x,
+#include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def"
+  };
+
+  /// Common type of ASTMatchers used for discovering gadgets.
+  /// Useful for implementing the static matcher() methods
+  /// that are expected from all non-abstract subclasses.
+  using Matcher = decltype(stmt());
+
+  Gadget(Kind K) : K(K) {}
+
+  Kind getKind() const { return K; }
+
+  virtual bool isSafe() const = 0;
+  virtual const Stmt *getBaseStmt() const = 0;
+
+  virtual ~Gadget() = default;
+
+private:
+  Kind K;
+};
+
+using GadgetList = std::vector>;
+
+/// Unsafe gadgets correspond to unsafe code patterns that warrants
+/// an immediate warning.
+class UnsafeGadget : public Gadget {
+public:
+  UnsafeGadget(Kind K) : Gadget(K) {}
+
+  static bool classof(const Gadget *G) { return G->isSafe(); }
+  bool isSafe() const final { return false; }
+};
+
+/// Safe gadgets correspond to code patterns that aren't unsafe but need to be
+/// properly recognized in order to emit correct warnings and fixes over unsafe
+/// gadgets. For example, if a raw pointer-type variable is replaced by
+/// a safe C++ container, every use of such variable may need to be
+/// carefully considered and possibly updated.
+class SafeGadget : public Gadget {
+public:
+  SafeGadget(Kind K) : Gadget(K) {}
+
+  static bool classof(const Gadget *G) { return !G->isSafe(); }
+  bool isSafe() const final { return true; }
+};
+
+/// An increment of a pointer-type value is unsafe as it may run the pointer
+/// out of bounds.
+class IncrementGadget : public UnsafeGadget {
+  static constexpr const char *const OpTag = "op";
+  const UnaryOperator *Op;
+
+public:
+  IncrementGadget(const MatchFinder::MatchResult &Result)
+  : UnsafeGadget(Kind::Increment),
+Op(Result.Nodes.getNodeAs(OpTag)) {}
+
+  static bool classof(const Gadget *G) {
+return G->getKind() == Kind::Increment;
+  }
+
+  static Matcher matcher() {
+return stmt(unaryOperator(
+  hasOperatorName("++"),
+  hasUnaryOperand(ignoringParenImpCasts(hasPointerType()))
+).bind(OpTag));
+  }
+
+  const UnaryOperator *getBaseStmt() const override { return Op; }
+};
+
+/// A decrement of a pointer-type value is unsafe as it may run the pointer
+/// out of bounds.
+class DecrementGadget : public UnsafeGadget {
+  static constexpr const char *const OpTag = "op";
+  const UnaryOperator *Op;
+
+public:
+  DecrementGadget(const MatchFinder::MatchResult &Result)
+  : UnsafeGadget(Kind::Decrement),
+Op(Result.Nodes.getNodeAs(OpTag)) {}
+
+  static bool classof(const Gadget *G) {
+return G->getKind() == Kind::Decrement;
+  }
+
+  static Matcher matcher() {
+return stmt(unaryOperator(
+  hasOperatorName("--"),
+  hasUnaryOperand(ignoringParenImpCasts(hasPointerType()))
+).bind(OpTag));
+  }
+
+  const UnaryOperator *getBaseStmt() const override { return Op; }
+};
+} // namespace
+
 // Scan the function and return a list of gadgets found with provided kits.
 static GadgetList findGadgets(const Decl *D) {
 
@@ -28,40 +140,56 @@
 GadgetFinderCallback(GadgetList &Output) : Output(Output) {}
 
 void run(const MatchFinder::MatchResult &Result) override {
-  Output.push_back(Result.Nodes.getNodeAs("root_node"));
+  // In debug mode, assert that we've found exactly one gadget.
+  // This helps us avoid conflicts 

[PATCH] D137348: [-Wunsafe-buffer-usage] Introduce an abstraction for fixable code patterns.

2022-12-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 480396.
NoQ added a comment.

A cleaner way to implement the debug facility.


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

https://reviews.llvm.org/D137348

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
  clang/lib/Analysis/UnsafeBufferUsage.cpp

Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -13,11 +13,123 @@
 using namespace clang;
 using namespace ast_matchers;
 
-namespace {
-// TODO: Better abstractions over gadgets.
-using GadgetList = std::vector;
+// Because we're dealing with raw pointers, let's define what we mean by that.
+static auto hasPointerType() {
+  return anyOf(hasType(pointerType()),
+   hasType(autoType(hasDeducedType(
+   hasUnqualifiedDesugaredType(pointerType());
 }
 
+namespace {
+/// Gadget is an individual operation in the code that may be of interest to
+/// this analysis. Each (non-abstract) subclass corresponds to a specific
+/// rigid AST structure that constitutes an operation on a pointer-type object.
+/// Discovery of a gadget in the code corresponds to claiming that we understand
+/// what this part of code is doing well enough to potentially improve it.
+/// Gadgets can be unsafe (immediately deserving a warning) or safe (not
+/// deserving a warning per se, but affecting our decision-making process
+/// nonetheless).
+class Gadget {
+public:
+  enum class Kind {
+#define GADGET(x) x,
+#include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def"
+  };
+
+  /// Common type of ASTMatchers used for discovering gadgets.
+  /// Useful for implementing the static matcher() methods
+  /// that are expected from all non-abstract subclasses.
+  using Matcher = decltype(stmt());
+
+  Gadget(Kind K) : K(K) {}
+
+  Kind getKind() const { return K; }
+
+  virtual bool isSafe() const = 0;
+  virtual const Stmt *getBaseStmt() const = 0;
+
+  virtual ~Gadget() = default;
+
+private:
+  Kind K;
+};
+
+using GadgetList = std::vector>;
+
+/// Unsafe gadgets correspond to unsafe code patterns that warrants
+/// an immediate warning.
+class UnsafeGadget : public Gadget {
+public:
+  UnsafeGadget(Kind K) : Gadget(K) {}
+
+  static bool classof(const Gadget *G) { return G->isSafe(); }
+  bool isSafe() const final { return false; }
+};
+
+/// Safe gadgets correspond to code patterns that aren't unsafe but need to be
+/// properly recognized in order to emit correct warnings and fixes over unsafe
+/// gadgets. For example, if a raw pointer-type variable is replaced by
+/// a safe C++ container, every use of such variable may need to be
+/// carefully considered and possibly updated.
+class SafeGadget : public Gadget {
+public:
+  SafeGadget(Kind K) : Gadget(K) {}
+
+  static bool classof(const Gadget *G) { return !G->isSafe(); }
+  bool isSafe() const final { return true; }
+};
+
+/// An increment of a pointer-type value is unsafe as it may run the pointer
+/// out of bounds.
+class IncrementGadget : public UnsafeGadget {
+  static constexpr const char *const OpTag = "op";
+  const UnaryOperator *Op;
+
+public:
+  IncrementGadget(const MatchFinder::MatchResult &Result)
+  : UnsafeGadget(Kind::Increment),
+Op(Result.Nodes.getNodeAs(OpTag)) {}
+
+  static bool classof(const Gadget *G) {
+return G->getKind() == Kind::Increment;
+  }
+
+  static Matcher matcher() {
+return stmt(unaryOperator(
+  hasOperatorName("++"),
+  hasUnaryOperand(ignoringParenImpCasts(hasPointerType()))
+).bind(OpTag));
+  }
+
+  const UnaryOperator *getBaseStmt() const override { return Op; }
+};
+
+/// A decrement of a pointer-type value is unsafe as it may run the pointer
+/// out of bounds.
+class DecrementGadget : public UnsafeGadget {
+  static constexpr const char *const OpTag = "op";
+  const UnaryOperator *Op;
+
+public:
+  DecrementGadget(const MatchFinder::MatchResult &Result)
+  : UnsafeGadget(Kind::Decrement),
+Op(Result.Nodes.getNodeAs(OpTag)) {}
+
+  static bool classof(const Gadget *G) {
+return G->getKind() == Kind::Decrement;
+  }
+
+  static Matcher matcher() {
+return stmt(unaryOperator(
+  hasOperatorName("--"),
+  hasUnaryOperand(ignoringParenImpCasts(hasPointerType()))
+).bind(OpTag));
+  }
+
+  const UnaryOperator *getBaseStmt() const override { return Op; }
+};
+} // namespace
+
 // Scan the function and return a list of gadgets found with provided kits.
 static GadgetList findGadgets(const Decl *D) {
 
@@ -28,40 +140,56 @@
 GadgetFinderCallback(GadgetList &Output) : Output(Output) {}
 
 void run(const MatchFinder::MatchResult &Result) override {
-  Output.push_back(Result.Nodes.getNodeAs("root_node"));
+  // In debug mode, assert that we've found exactly one gadget.
+  // This helps us avoid conflicts in .bind() tags.
+#if NDEBUG
+#define 

[PATCH] D138253: [-Wunsafe-buffer-usage] NFC: Implement fix-strategies and variable-use-claiming.

2022-12-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 480397.
NoQ added a comment.

Whoops, sorry, wrong patch. I was trying to say, "Address review comments".


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

https://reviews.llvm.org/D138253

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp

Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2150,9 +2150,18 @@
   UnsafeBufferUsageReporter(Sema &S) : S(S) {}
 
   void handleUnsafeOperation(const Stmt *Operation) override {
-S.Diag(Operation->getBeginLoc(), diag::warn_unsafe_buffer_usage)
+S.Diag(Operation->getBeginLoc(), diag::warn_unsafe_buffer_expression)
 << Operation->getSourceRange();
   }
+
+  void handleFixableVariable(const VarDecl *Variable,
+ FixItList &&Fixes) override {
+const auto &D =
+S.Diag(Variable->getBeginLoc(), diag::warn_unsafe_buffer_variable);
+D << Variable << Variable->getSourceRange();
+for (const auto &F: Fixes)
+  D << F;
+  }
 };
 
 
@@ -2449,7 +2458,8 @@
 checkThrowInNonThrowingFunc(S, FD, AC);
 
   // Emit unsafe buffer usage warnings and fixits.
-  if (!Diags.isIgnored(diag::warn_unsafe_buffer_usage, D->getBeginLoc())) {
+  if (!Diags.isIgnored(diag::warn_unsafe_buffer_expression, D->getBeginLoc()) ||
+  !Diags.isIgnored(diag::warn_unsafe_buffer_variable, D->getBeginLoc())) {
 UnsafeBufferUsageReporter R(S);
 checkUnsafeBufferUsage(D, R);
   }
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -13,6 +13,18 @@
 using namespace clang;
 using namespace ast_matchers;
 
+namespace {
+// Because the analysis revolves around variables and their types, we'll need to
+// track uses of variables (aka DeclRefExprs).
+using DeclUseList = SmallVector;
+
+// Convenience typedef.
+using FixItList = SmallVector;
+
+// Defined below.
+class Strategy;
+} // namespace
+
 // Because we're dealing with raw pointers, let's define what we mean by that.
 static auto hasPointerType() {
   return anyOf(hasType(pointerType()),
@@ -48,6 +60,18 @@
   virtual bool isSafe() const = 0;
   virtual const Stmt *getBaseStmt() const = 0;
 
+  /// Returns the list of pointer-type variables on which this gadget performs
+  /// its operation. Typically, there's only one variable. This isn't a list
+  /// of all DeclRefExprs in the gadget's AST!
+  virtual DeclUseList getClaimedVarUseSites() const = 0;
+
+  /// Returns a fixit that would fix the current gadget according to
+  /// the current strategy. Returns None if the fix cannot be produced;
+  /// returns an empty list if no fixes are necessary.
+  virtual std::optional getFixits(const Strategy &) const {
+return std::nullopt;
+  }
+
   virtual ~Gadget() = default;
 
 private:
@@ -102,6 +126,16 @@
   }
 
   const UnaryOperator *getBaseStmt() const override { return Op; }
+
+  DeclUseList getClaimedVarUseSites() const override {
+SmallVector Uses;
+if (const auto *DRE =
+dyn_cast(Op->getSubExpr()->IgnoreParenImpCasts())) {
+  Uses.push_back(DRE);
+}
+
+return std::move(Uses);
+  }
 };
 
 /// A decrement of a pointer-type value is unsafe as it may run the pointer
@@ -127,6 +161,15 @@
   }
 
   const UnaryOperator *getBaseStmt() const override { return Op; }
+
+  DeclUseList getClaimedVarUseSites() const override {
+if (const auto *DRE =
+dyn_cast(Op->getSubExpr()->IgnoreParenImpCasts())) {
+  return {DRE};
+}
+
+return {};
+  }
 };
 
 /// Array subscript expressions on raw pointers as if they're arrays. Unsafe as
@@ -152,17 +195,115 @@
   }
 
   const Stmt *getBaseStmt() const override { return ASE; }
+
+  DeclUseList getClaimedVarUseSites() const override {
+if (const auto *DRE =
+dyn_cast(ASE->getBase()->IgnoreParenImpCasts())) {
+  return {DRE};
+}
+
+return {};
+  }
 };
 } // namespace
 
-// Scan the function and return a list of gadgets found with provided kits.
-static GadgetList findGadgets(const Decl *D) {
+namespace {
+// An auxiliary tracking facility for the fixit analysis. It helps connect
+// declarations to its and make sure we've covered all uses with our analysis
+// before we try to fix the declaration.
+class DeclUseTracker {
+  using UseSetTy = SmallSet;
+  using DefMapTy = DenseMap;
+
+  // Allocate on the heap for easier move.
+  std::unique_ptr Uses{std::make_unique()};
+  DefMapTy Defs{};
 
-  class GadgetFinderCallback : public MatchFinder::MatchCallback {
-GadgetList &Output;
+public:
+  DeclUseTrac

[PATCH] D138253: [-Wunsafe-buffer-usage] NFC: Implement fix-strategies and variable-use-claiming.

2022-12-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:17-19
+// Because the analysis revolves around variables and their types, we'll need 
to
+// track uses of variables (aka DeclRefExprs).
+using DeclUseList = SmallVector;

aaron.ballman wrote:
> Do we have to care about data member accesses (which would be a `MemberExpr` 
> and not a `DeclRefExpr`)?
> 
> Also, because this shows up in interfaces, it should probably be a 
> `SmallVectorImpl` so the size doesn't matter.
> Do we have to care about data member accesses (which would be a `MemberExpr` 
> and not a `DeclRefExpr`)?

Unlikely. Auto-fixing member variables without breaking source or binary 
compatibility is next to impossible.

> Also, because this shows up in interfaces, it should probably be a 
> SmallVectorImpl so the size doesn't matter.

This doesn't seem to work on return types, which is where these classes show up 
in my case (`SmallVectorImpl` has deleted copy-move constructors so it's only 
suitable for passing by reference).



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:266-271
+for (const Decl *D: DS->decls()) {
+  if (const auto *VD = dyn_cast(D)) {
+assert(Defs.count(VD) == 0 && "Definition already discovered!");
+Defs[VD] = DS;
+  }
+}

aaron.ballman wrote:
> Use a `specific_decl_iterator` instead?
Hmm `DeclStmt` doesn't seem to provide a neat accessor, would you like me to 
add it?


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

https://reviews.llvm.org/D138253

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


[PATCH] D138807: [RISCV] Support vector crypto extension ISA string and assembly

2022-12-06 Thread Eric Gouriou via Phabricator via cfe-commits
ego added a comment.

I have been working on a patch set to support Zvk. It will take me a few more 
days to prepare my patches to post them publicly.
Your patches are in a very good shape and a lot of files end up looking pretty 
similar.

I have a few comments, most minor.
This is my first review on Phabricator, don't hesitate to provide 
feedback/suggestions on my feedback.




Comment at: clang/test/Preprocessor/riscv-target-features.c:486
+// RUN: -march=rv32izvkb0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKB-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \

Minor: please keep the Zvk sub-extensions in alphabetical order (zvkb, zvkg, 
zvknha, zvknhb, zvkns, zvksed, zvksh).



Comment at: llvm/docs/RISCVUsage.rst:147
 
+``experimental-zvkns``, ``experimental-zvknha``, ``experimental-zvknhb``, 
``experimental-zvkb``, ``experimental-zvkg``, ``experimental-zvksed``, 
``experimental-zvksh``
+  LLVM implements the `0.1 draft specification 
`_.
 Note that current vector crypto extension version can be found in: 
.

Minor: please keep the Zvk sub-extensions in alphabetical order (zvkb, zvkg, 
zvknha, zvknhb, zvkns, zvksed, zvksh).



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:125
+{"zvknhb", RISCVExtensionVersion{0, 1}},
+{"zvkb", RISCVExtensionVersion{0, 1}},
+{"zvkg", RISCVExtensionVersion{0, 1}},

Minor: please keep the Zvk sub-extensions in alphabetical order (zvkb, zvkg, 
zvknha, zvknhb, zvkns, zvksed, zvksh).



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:826
 {{"zvfh"}, {ImpliedExtsZvfh}},
+{{"zvkb"}, {ImpliedExtsZve64x}},
+{{"zvkg"}, {ImpliedExtsZve32x}},

Can you please point me to where the specification(s) state those implications?

Are those the semantics we want? I know the spec reviewers are keen to ensure 
that the spec works on vector units with a VLEN smaller than the element group. 
Is there a requirement that VLEN is at least as large as the element?

So far I asked all my uses of zvk extensions to also declare v (or Zve) 
explicitly. I believe there is a precedent for another extension relying on 
vector but will need to double-check.

Along the same lines, we'll want to figure what declaring "Zvk" means.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:827
+{{"zvkb"}, {ImpliedExtsZve64x}},
+{{"zvkg"}, {ImpliedExtsZve32x}},
+{{"zvknha"}, {ImpliedExtsZve32x}},

What is the reasoning between 32 vs 64 for those sub-extensions?
I do not think that extensions using 64bxN element groups are restricted to 
rv64.

No matter what the end result is, I would welcome some comments explaining the 
encoded semantics.



Comment at: llvm/lib/Target/RISCV/RISCV.td:473
+AssemblerPredicate<(any_of 
FeatureStdExtZvknha, FeatureStdExtZvknhb),
+"'Zvknha' (Vector SHA-2. (SHA-256 only)) "
+"'Zvknhb' (Vector SHA-2. (SHA-256 and 
SHA-512))">;

Please consider adding an "or" in the string.



Comment at: llvm/lib/Target/RISCV/RISCV.td:476
+
+def FeatureStdExtZvkb
+: SubtargetFeature<"experimental-zvkb", "HasStdExtZvkb", "true",

Minor: please keep the Zvk sub-extensions in alphabetical order (zvkb, zvkg, 
zvknha, zvknhb, zvkns, zvksed, zvksh).

Note: I just realized the spec lists them in the order used here. So feel free 
to ignore those suggestions if you'd rather follow the spec ordering (although 
I may try to nudge Ken towards an alphabetical ordering in the spec).



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td:63
+  let Opcode = OPC_OP_P.Value;
+  let Inst{14-12} = 0b010;
+}

Suggestion: OMPVV.Value;



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td:78
+
+class PALUVI_CUSTOM funct6, string opcodestr, Operand optype>
+: VALUVINoVm {

This deserves a comment about intended usage.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td:85
+
+def rnum_0_7 : Operand, ImmLeaf {

Note: there is a way to avoid code duplication using classes, and to also cover 
the similar use in the scalar crypto instructions.
I will post Zvk patches, but the code looks like this:

In RISCVIntrInfo.td:

// Parser match class for Round Number operands
// with defined min/max inclusive bounds.
class RnumParserOperand : AsmOperandClass {
  let Name = "Rnum" # min # "_" # max # "Operand";
  let RenderMethod = "addImmOperands";
  let DiagnosticType = "InvalidRnum" # min # "_" # max # "Operand";
}

// Oerand class representing cryptographic Round Number operands
// with d

[PATCH] D136594: [clangd] Add support for semantic token type "operator"

2022-12-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

For my part, I still need to understand why we want the 
`builtin`/`UserModified` modifier. (The `operator` highlight kind seems obvious 
to me).

From earlier comments:

>> Can you give some background here or on the bug tracker about what kind of 
>> distinction you're trying to draw here and why it's important?
>> (Most clients are never going to benefit from nonstandard modifiers so they 
>> should be pretty compelling)
>
> This was one of the biggest questions I had about this patch - just hoping it 
> doesn't get missed.






Comment at: clang-tools-extra/clangd/SemanticHighlighting.h:76
   ConstructorOrDestructor,
+  UserProvided,
 

ckandeler wrote:
> sammccall wrote:
> > ckandeler wrote:
> > > sammccall wrote:
> > > > sammccall wrote:
> > > > > nridge wrote:
> > > > > > ckandeler wrote:
> > > > > > > ckandeler wrote:
> > > > > > > > sammccall wrote:
> > > > > > > > > sammccall wrote:
> > > > > > > > > > sammccall wrote:
> > > > > > > > > > > Can you give some background here or on the bug tracker 
> > > > > > > > > > > about what kind of distinction you're trying to draw here 
> > > > > > > > > > > and why it's important?
> > > > > > > > > > > (Most clients are never going to benefit from nonstandard 
> > > > > > > > > > > modifiers so they should be pretty compelling)
> > > > > > > > > > as well as being jargony, "user-provided" has a specific 
> > > > > > > > > > technical meaning that I don't think you intend here. For 
> > > > > > > > > > example, `auto operator<=>(const S&) const = default` is 
> > > > > > > > > > not user-provided (defaulted on first declaration). 
> > > > > > > > > > https://eel.is/c++draft/dcl.fct.def.default#5
> > > > > > > > > > 
> > > > > > > > > > If we need this and can't get away with reusing 
> > > > > > > > > > `defaultLibrary` (which would include `std::`) then maybe 
> > > > > > > > > > we should add something like `builtin` which seems quite 
> > > > > > > > > > reusable.
> > > > > > > > > Since we often can't say whether an operator is user-provided 
> > > > > > > > > or not (in templates), we should consider what we want the 
> > > > > > > > > highlighting to be in these cases.
> > > > > > > > > (If templates should be highlighted as built-in, we should 
> > > > > > > > > prefer a modifier like `UserProvided`, if they should be 
> > > > > > > > > highlighted as user-provided, we should prefer a modifier 
> > > > > > > > > like `Builtin`)
> > > > > > > > > as well as being jargony, "user-provided" has a specific 
> > > > > > > > > technical meaning that I don't think you intend here. For 
> > > > > > > > > example, `auto operator<=>(const S&) const = default` is not 
> > > > > > > > > user-provided (defaulted on first declaration). 
> > > > > > > > > https://eel.is/c++draft/dcl.fct.def.default#5
> > > > > > > > > 
> > > > > > > > > If we need this and can't get away with reusing 
> > > > > > > > > `defaultLibrary` (which would include `std::`) then maybe we 
> > > > > > > > > should add something like `builtin` which seems quite 
> > > > > > > > > reusable.
> > > > > > > > 
> > > > > > > > I use "userProvided" here in the sense of "not built-in" or 
> > > > > > > > "overloaded". I do not cling to the term, and have also 
> > > > > > > > suggested the opposite default of using "builtin" in another 
> > > > > > > > comment.
> > > > > > > > Since we often can't say whether an operator is user-provided 
> > > > > > > > or not (in templates), we should consider what we want the 
> > > > > > > > highlighting to be in these cases.
> > > > > > > 
> > > > > > > True, I have not considered this.
> > > > > > > 
> > > > > > > > (If templates should be highlighted as built-in, we should 
> > > > > > > > prefer a modifier like `UserProvided`, if they should be 
> > > > > > > > highlighted as user-provided, we should prefer a modifier like 
> > > > > > > > `Builtin`)
> > > > > > > 
> > > > > > > Intuitively, it seems we should be conservative and not claim the 
> > > > > > > operator is overloaded unless we know it is. So "built-in" might 
> > > > > > > then mean "we can't prove it's not a built-in". It's probably not 
> > > > > > > worth to introduce a modifier CouldBeEitherWay just to explicitly 
> > > > > > > express ambiguity ;)
> > > > > > > Since we often can't say whether an operator is user-provided or 
> > > > > > > not (in templates), we should consider what we want the 
> > > > > > > highlighting to be in these cases.
> > > > > > > (If templates should be highlighted as built-in, we should prefer 
> > > > > > > a modifier like `UserProvided`, if they should be highlighted as 
> > > > > > > user-provided, we should prefer a modifier like `Builtin`)
> > > > > > 
> > > > > > In my mind, "go-to-definition on this operator symbol will take me 
> > > > > > to a function declaration/definition" is a good match for "I want 
> > > > > > this colored differently". (Which would imply treating dependent 
> > > > > > 

[PATCH] D138821: [include-cleaner] Remove filtering from UsingDecl visit.

2022-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:130
 TEST(WalkAST, Using) {
-  // Make sure we ignore unused overloads.
+  // We should report unused overloads as ambiguous.
   testWalk(R"cpp(

hokein wrote:
> nit: update the comment.
this comment is stale, and the below one as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138821

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


[PATCH] D138722: Overload all llvm.annotation intrinsics for globals argument

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

LGTM




Comment at: llvm/test/Bitcode/upgrade-annotation.ll:14
+
+declare i32 @llvm.annotation.i32(i32, i8*, i8*, i32)
+; CHECK: declare i32 @llvm.annotation.i32.p0i8(i32, i8*, i8*, i32)

arsenm wrote:
> New tests should use opaque pointers. For autoupgrade we may want and need 
> both test copies
I think this is fine for now. We'll deal with this when we remove the typed 
pointer auto-detection from the bitcode reader, at which point all existing 
typed pointer bitcode will get upgraded to opaque pointer bitcode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138722

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


[PATCH] D139409: [include-cleaner] Handle dependent type members in AST

2022-12-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added a subscriber: kadircet.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Handles dependent type members in AST.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139409

Files:
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -178,6 +178,11 @@
   "void foo() { X{}.^foo(); }");
 }
 
+TEST(WalkAST, CXXDependentScopeMemberExprs) {
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base t) { t.^method(); }");
+}
+
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct S { $implicit^S(); };", "S ^t;");


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -178,6 +178,11 @@
   "void foo() { X{}.^foo(); }");
 }
 
+TEST(WalkAST, CXXDependentScopeMemberExprs) {
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base t) { t.^method(); }");
+}
+
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct S { $implicit^S(); };", "S ^t;");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138821: [include-cleaner] Remove filtering from UsingDecl visit.

2022-12-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 480418.
VitaNuo added a comment.

Change/remove stale comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138821

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -26,7 +26,6 @@
 namespace {
 
 // Specifies a test of which symbols are referenced by a piece of code.
-// If `// c++-header` is present, treats referencing code as a header file.
 // Target should contain points annotated with the reference kind.
 // Example:
 //   Target:  int $explicit^foo();
@@ -41,8 +40,6 @@
   Inputs.ExtraArgs.push_back("-include");
   Inputs.ExtraArgs.push_back("target.h");
   Inputs.ExtraArgs.push_back("-std=c++17");
-  if (Referencing.code().contains("// c++-header\n"))
-Inputs.ExtraArgs.push_back("-xc++-header");
   TestAST AST(Inputs);
   const auto &SM = AST.sourceManager();
 
@@ -88,12 +85,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -129,19 +124,34 @@
 }
 
 TEST(WalkAST, Using) {
-  // Make sure we ignore unused overloads.
+  // We should report unused overloads as ambiguous.
   testWalk(R"cpp(
 namespace ns {
-  void $explicit^x(); void x(int); void x(char);
+  void $explicit^x(); void $ambiguous^x(int); void $ambiguous^x(char);
 })cpp",
"using ns::^x; void foo() { x(); }");
-  // We should report unused overloads if main file is a header.
   testWalk(R"cpp(
 namespace ns {
   void $ambiguous^x(); void $ambiguous^x(int); void $ambiguous^x(char);
 })cpp",
-   "// c++-header\n using ns::^x;");
+   "using ns::^x;");
   testWalk("namespace ns { struct S; } using ns::$explicit^S;", "^S *s;");
+
+  testWalk(R"cpp(
+namespace ns {
+  template
+  class $ambiguous^Y {};
+}
+)cpp",
+   "using ns::^Y;");
+  testWalk(R"cpp(
+namespace ns {
+  template
+  class Y {};
+}
+   using ns::$explicit^Y; 
+)cpp",
+   "^Y x;");
 }
 
 TEST(WalkAST, Namespaces) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -16,7 +16,6 @@
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 
@@ -27,10 +26,6 @@
 
 class ASTWalker : public RecursiveASTVisitor {
   DeclCallback Callback;
-  // Whether we're traversing declarations coming from a header file.
-  // This helps figure out whether certain symbols can be assumed as unused
-  // (e.g. overloads brought into an implementation file, but not used).
-  bool IsHeader = false;
 
   bool handleTemplateName(SourceLocation Loc, TemplateName TN) {
 // For using-templates, only mark the alias.
@@ -50,8 +45,7 @@
   }
 
 public:
-  ASTWalker(DeclCallback Callback, bool IsHeader)
-  : Callback(Callback), IsHeader(IsHeader) {}
+  ASTWalker(DeclCallback Callback) : Callback(Callback) {}
 
   bool VisitDeclRefExpr(DeclRefExpr *DRE) {
 report(DRE->getLocation(), DRE->getFoundDecl());
@@ -82,10 +76,6 @@
 for (const auto *Shadow : UD->shadows()) {
   auto *TD = Shadow->getTargetDecl();
   auto IsUsed = TD->isUsed() || TD->isReferenced();
-  // We ignore unused overloads inside implementation files, as the ones in
-  // headers might still be used by the dependents of the header.
-  if (!IsUsed && !IsHeader)
-continue;
   report(UD->getLocation(), TD,
  IsUsed ? RefType::Explicit : RefType::Ambiguous);
 }
@@ -151,14 +141,7 @@
 } // namespace
 
 void walkAST(Decl &Root, DeclCallback Callback) {
-  auto &AST = Root.getASTContext();
-  auto &SM = AST.getSourceManager();
-  // If decl isn't written in main file, assume it's coming from an include,
-  // hence written in a

[PATCH] D138200: [include-cleaner] Make use of locateSymbol in WalkUsed

2022-12-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 5 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/include-cleaner/test/html.cpp:7
 int n = foo();
+// CHECK: Symbol{{.*}}foo
+// CHECK-NEXT: int foo()

sammccall wrote:
> I'd like to keep a very simple smoke test of the HTML report.
> 
> If you're aiming to test something specific here about the HTML report, I'd 
> suggest creating a new test describing what it is. (Though generally 
> speaking, the HTML test has poor test coverage of its details, which I think 
> is unfortunately the right tradeoff)
> 
> If you're aiming to provide an integration test (these locations are taken 
> into account in making overall decisions), I think this should be a test 
> using `-print=changes` rather than -html.
thanks makes sense. `print-changes` didn't exist back in the day when i was 
putting together this patch and i forgot to update this piece.

i wasn't trying to test HTMLReport behaviour specifically, and it's probably 
not worth adding that anyways.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138200

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


[PATCH] D138200: [include-cleaner] Make use of locateSymbol in WalkUsed

2022-12-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 480419.
kadircet marked an inline comment as done.
kadircet added a comment.

- Drop the cache
- Use `-print=changes` in lit test
- Update unittest helper to limit decls to main file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138200

Files:
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/test/Inputs/foo2.h
  clang-tools-extra/include-cleaner/test/multiple-providers.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -18,7 +18,6 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -26,6 +25,7 @@
 
 namespace clang::include_cleaner {
 namespace {
+using testing::Contains;
 using testing::ElementsAre;
 using testing::Pair;
 using testing::UnorderedElementsAre;
@@ -34,8 +34,48 @@
   return "#pragma once\n" + Code.str();
 }
 
-TEST(WalkUsed, Basic) {
-  // FIXME: Have a fixture for setting up tests.
+class WalkUsedTest : public testing::Test {
+protected:
+  TestInputs Inputs;
+  PragmaIncludes PI;
+  WalkUsedTest() {
+Inputs.MakeAction = [this] {
+  struct Hook : public SyntaxOnlyAction {
+  public:
+Hook(PragmaIncludes *Out) : Out(Out) {}
+bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+  Out->record(CI);
+  return true;
+}
+
+PragmaIncludes *Out;
+  };
+  return std::make_unique(&PI);
+};
+  }
+
+  llvm::DenseMap>
+  offsetToProviders(TestAST &AST, SourceManager &SM,
+llvm::ArrayRef MacroRefs = {}) {
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
+  if (!SM.isWrittenInMainFile(SM.getExpansionLoc(D->getLocation(
+continue;
+  TopLevelDecls.emplace_back(D);
+}
+llvm::DenseMap> OffsetToProviders;
+walkUsed(TopLevelDecls, MacroRefs, &PI, SM,
+ [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
+   auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
+   if (FID != SM.getMainFileID())
+ ADD_FAILURE() << "Reference outside of the main file!";
+   OffsetToProviders.try_emplace(Offset, Providers.vec());
+ });
+return OffsetToProviders;
+  }
+};
+
+TEST_F(WalkUsedTest, Basic) {
   llvm::Annotations Code(R"cpp(
   #include "header.h"
   #include "private.h"
@@ -45,7 +85,7 @@
 std::$vector^vector $vconstructor^v;
   }
   )cpp");
-  TestInputs Inputs(Code.code());
+  Inputs.Code = Code.code();
   Inputs.ExtraFiles["header.h"] = guard(R"cpp(
   void foo();
   namespace std { class vector {}; }
@@ -55,85 +95,75 @@
 class Private {};
   )cpp");
 
-  PragmaIncludes PI;
-  Inputs.MakeAction = [&PI] {
-struct Hook : public SyntaxOnlyAction {
-public:
-  Hook(PragmaIncludes *Out) : Out(Out) {}
-  bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
-Out->record(CI);
-return true;
-  }
-
-  PragmaIncludes *Out;
-};
-return std::make_unique(&PI);
-  };
   TestAST AST(Inputs);
-
-  llvm::SmallVector TopLevelDecls;
-  for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
-TopLevelDecls.emplace_back(D);
-  }
-
   auto &SM = AST.sourceManager();
-  llvm::DenseMap> OffsetToProviders;
-  walkUsed(TopLevelDecls, /*MacroRefs=*/{}, &PI, SM,
-   [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
- auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
- EXPECT_EQ(FID, SM.getMainFileID());
- OffsetToProviders.try_emplace(Offset, Providers.vec());
-   });
-  auto &FM = AST.fileManager();
-  auto HeaderFile = Header(FM.getFile("header.h").get());
+  auto HeaderFile = Header(AST.fileManager().getFile("header.h").get());
+  auto PrivateFile = Header(AST.fileManager().getFile("private.h").get());
+  auto PublicFile = Header("\"path/public.h\"");
   auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
   auto VectorSTL = Header(tooling::stdlib::Header::named("").value());
   EXPECT_THAT(
-  OffsetToProviders,
+  offsetToProviders(AST, SM),
   UnorderedElementsAre(
   Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
   Pair(Code.point("private"),
-   UnorderedElementsAre(Header("\"path/public.h\""),
-

[PATCH] D138821: [include-cleaner] Remove filtering from UsingDecl visit.

2022-12-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked 2 inline comments as done.
VitaNuo added inline comments.



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:130
 TEST(WalkAST, Using) {
-  // Make sure we ignore unused overloads.
+  // We should report unused overloads as ambiguous.
   testWalk(R"cpp(

hokein wrote:
> hokein wrote:
> > nit: update the comment.
> this comment is stale, and the below one as well.
oops, sorry.



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:149
+  // We should report references to templates as ambiguous.
+  testWalk(R"cpp(
+namespace ns {

VitaNuo wrote:
> kadircet wrote:
> > sorry if i am being dense but what's the difference we're trying to grasp 
> > between this and the next test case exactly?
> > i guess it's meant to test the difference between used and non-used 
> > template patterns?
> Yes, you're right. It probably only made sense before I removed the "isUsed" 
> check.
I have re-introduced this test case now, since there's a differentiation 
between used and unused again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138821

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


[PATCH] D138200: [include-cleaner] Make use of locateSymbol in WalkUsed

2022-12-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 480420.
kadircet added a comment.

- Fix RUN: line in lit test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138200

Files:
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/test/Inputs/foo2.h
  clang-tools-extra/include-cleaner/test/multiple-providers.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -18,7 +18,6 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -26,6 +25,7 @@
 
 namespace clang::include_cleaner {
 namespace {
+using testing::Contains;
 using testing::ElementsAre;
 using testing::Pair;
 using testing::UnorderedElementsAre;
@@ -34,8 +34,48 @@
   return "#pragma once\n" + Code.str();
 }
 
-TEST(WalkUsed, Basic) {
-  // FIXME: Have a fixture for setting up tests.
+class WalkUsedTest : public testing::Test {
+protected:
+  TestInputs Inputs;
+  PragmaIncludes PI;
+  WalkUsedTest() {
+Inputs.MakeAction = [this] {
+  struct Hook : public SyntaxOnlyAction {
+  public:
+Hook(PragmaIncludes *Out) : Out(Out) {}
+bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+  Out->record(CI);
+  return true;
+}
+
+PragmaIncludes *Out;
+  };
+  return std::make_unique(&PI);
+};
+  }
+
+  llvm::DenseMap>
+  offsetToProviders(TestAST &AST, SourceManager &SM,
+llvm::ArrayRef MacroRefs = {}) {
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
+  if (!SM.isWrittenInMainFile(SM.getExpansionLoc(D->getLocation(
+continue;
+  TopLevelDecls.emplace_back(D);
+}
+llvm::DenseMap> OffsetToProviders;
+walkUsed(TopLevelDecls, MacroRefs, &PI, SM,
+ [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
+   auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
+   if (FID != SM.getMainFileID())
+ ADD_FAILURE() << "Reference outside of the main file!";
+   OffsetToProviders.try_emplace(Offset, Providers.vec());
+ });
+return OffsetToProviders;
+  }
+};
+
+TEST_F(WalkUsedTest, Basic) {
   llvm::Annotations Code(R"cpp(
   #include "header.h"
   #include "private.h"
@@ -45,7 +85,7 @@
 std::$vector^vector $vconstructor^v;
   }
   )cpp");
-  TestInputs Inputs(Code.code());
+  Inputs.Code = Code.code();
   Inputs.ExtraFiles["header.h"] = guard(R"cpp(
   void foo();
   namespace std { class vector {}; }
@@ -55,85 +95,75 @@
 class Private {};
   )cpp");
 
-  PragmaIncludes PI;
-  Inputs.MakeAction = [&PI] {
-struct Hook : public SyntaxOnlyAction {
-public:
-  Hook(PragmaIncludes *Out) : Out(Out) {}
-  bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
-Out->record(CI);
-return true;
-  }
-
-  PragmaIncludes *Out;
-};
-return std::make_unique(&PI);
-  };
   TestAST AST(Inputs);
-
-  llvm::SmallVector TopLevelDecls;
-  for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
-TopLevelDecls.emplace_back(D);
-  }
-
   auto &SM = AST.sourceManager();
-  llvm::DenseMap> OffsetToProviders;
-  walkUsed(TopLevelDecls, /*MacroRefs=*/{}, &PI, SM,
-   [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
- auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
- EXPECT_EQ(FID, SM.getMainFileID());
- OffsetToProviders.try_emplace(Offset, Providers.vec());
-   });
-  auto &FM = AST.fileManager();
-  auto HeaderFile = Header(FM.getFile("header.h").get());
+  auto HeaderFile = Header(AST.fileManager().getFile("header.h").get());
+  auto PrivateFile = Header(AST.fileManager().getFile("private.h").get());
+  auto PublicFile = Header("\"path/public.h\"");
   auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
   auto VectorSTL = Header(tooling::stdlib::Header::named("").value());
   EXPECT_THAT(
-  OffsetToProviders,
+  offsetToProviders(AST, SM),
   UnorderedElementsAre(
   Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
   Pair(Code.point("private"),
-   UnorderedElementsAre(Header("\"path/public.h\""),
-Header(FM.getFile("private.h").get(,
+   UnorderedElementsAre(PublicFile, PrivateFile)),
   

[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.

2022-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:68
   bool VisitMemberExpr(MemberExpr *E) {
-report(E->getMemberLoc(), E->getFoundDecl().getDecl());
+// Instead of the FieldDecl for MemberExpr, we report the Decl of
+// the corresponding record. This is done in order to report

I'd rephrase something like -- A member expr implies a usage of the class type 
(e.g. to prevent inserting a header of base class when using base members from 
a derived object).



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:182
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived& d) { d.^a; }");
 }

can you add more  test cases (the AST node is a bit different among the 
following cases) to make sure our code handle all of them? 

- `Derived foo();  foo().^a;`
- `Derived& foo(); foo().^a;`
- `Derived().^a;`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139087

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


[PATCH] D139125: [clang] Correctly handle by-reference capture with an initializer that is a pack expansion in lambdas.

2022-12-06 Thread Jens Massberg via Phabricator via cfe-commits
massberg added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:13156
   getSema().buildLambdaInitCaptureInitialization(
-  C->getLocation(), OldVD->getType()->isReferenceType(),
+  C->getLocation(), isReferenceType,
   EllipsisLoc, NumExpansions, OldVD->getIdentifier(),

massberg wrote:
> ilya-biryukov wrote:
> > Could we use `C->getCaptureKind() == LCK_ByRef` instead?
> > 
> > It seems like that was the intention of the function in the first place 
> > (that's was the other callsite from the parser is doing): pass what was 
> > written by the user and let the function figure out how to actually build 
> > the types.
> > Normally we want to unify the code that parser uses for non-dependent code 
> > and the tree-transforms where possible.
> `C-getCaptureKind` is equal to `LCK_ByCopy`, even if the expansion pack is 
> passed by refernece.
I will check if this is by error and if it should be set to `LCK_ByRef` in case 
of references to pack expansions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139125

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


[PATCH] D139274: Store OptTable::Info::Name as a StringRef

2022-12-06 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 480421.
serge-sans-paille added a comment.

Also simplify `StrCmpOptionNameIgnoreCase` implementation thanks to the move to 
StringRef


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

https://reviews.llvm.org/D139274

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/Option/OptTable.cpp
  llvm/unittests/Option/OptionMarshallingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -54,9 +54,9 @@
 
 static void emitNameUsingSpelling(raw_ostream &OS, const Record &R) {
   size_t PrefixLength;
-  OS << "&";
+  OS << "llvm::StringRef(";
   write_cstring(OS, StringRef(getOptionSpelling(R, PrefixLength)));
-  OS << "[" << PrefixLength << "]";
+  OS << ").substr(" << PrefixLength << ")";
 }
 
 class MarshallingInfo {
Index: llvm/unittests/Option/OptionMarshallingTest.cpp
===
--- llvm/unittests/Option/OptionMarshallingTest.cpp
+++ llvm/unittests/Option/OptionMarshallingTest.cpp
@@ -6,10 +6,11 @@
 //
 //===--===//
 
+#include "llvm/ADT/StringRef.h"
 #include "gtest/gtest.h"
 
 struct OptionWithMarshallingInfo {
-  const char *Name;
+  llvm::StringRef Name;
   const char *KeyPath;
   const char *ImpliedCheck;
   const char *ImpliedValue;
@@ -27,10 +28,10 @@
 };
 
 TEST(OptionMarshalling, EmittedOrderSameAsDefinitionOrder) {
-  ASSERT_STREQ(MarshallingTable[0].Name, "marshalled-flag-d");
-  ASSERT_STREQ(MarshallingTable[1].Name, "marshalled-flag-c");
-  ASSERT_STREQ(MarshallingTable[2].Name, "marshalled-flag-b");
-  ASSERT_STREQ(MarshallingTable[3].Name, "marshalled-flag-a");
+  ASSERT_STREQ(MarshallingTable[0].Name.data(), "marshalled-flag-d");
+  ASSERT_STREQ(MarshallingTable[1].Name.data(), "marshalled-flag-c");
+  ASSERT_STREQ(MarshallingTable[2].Name.data(), "marshalled-flag-b");
+  ASSERT_STREQ(MarshallingTable[3].Name.data(), "marshalled-flag-a");
 }
 
 TEST(OptionMarshalling, EmittedSpecifiedKeyPath) {
Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -36,31 +36,23 @@
 // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
 // with an exception. '\0' comes at the end of the alphabet instead of the
 // beginning (thus options precede any other options which prefix them).
-static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
-  const char *X = A, *Y = B;
-  char a = tolower(*A), b = tolower(*B);
-  while (a == b) {
-if (a == '\0')
-  return 0;
-
-a = tolower(*++X);
-b = tolower(*++Y);
-  }
+static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
+  size_t MinSize = std::min(A.size(), B.size());
+  if (int res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize)))
+return res;
 
-  if (a == '\0') // A is a prefix of B.
-return 1;
-  if (b == '\0') // B is a prefix of A.
-return -1;
+  if (A.size() == B.size())
+return 0;
 
-  // Otherwise lexicographic.
-  return (a < b) ? -1 : 1;
+  return (A.size() == MinSize) ? 1 /* A is a prefix of B. */
+   : -1 /* B is a prefix of A */;
 }
 
 #ifndef NDEBUG
-static int StrCmpOptionName(const char *A, const char *B) {
+static int StrCmpOptionName(StringRef A, StringRef B) {
   if (int N = StrCmpOptionNameIgnoreCase(A, B))
 return N;
-  return strcmp(A, B);
+  return A.compare(B);
 }
 
 static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) {
@@ -86,7 +78,7 @@
 #endif
 
 // Support lower_bound between info and an option name.
-static inline bool operator<(const OptTable::Info &I, const char *Name) {
+static inline bool operator<(const OptTable::Info &I, StringRef Name) {
   return StrCmpOptionNameIgnoreCase(I.Name, Name) < 0;
 }
 
@@ -321,7 +313,7 @@
   return BestDistance;
 }
 
-bool OptTable::addValues(const char *Option, const char *Values) {
+bool OptTable::addValues(StringRef Option, const char *Values) {
   for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
 Info &In = OptionInfos[I];
 if (optionMatches(In, Option)) {
@@ -347,8 +339,8 @@
 
   const Info *End = OptionInfos.data() + OptionInfos.size();
   StringRef Name = Str.ltrim(PrefixChars);
-  const Info *Start = std::lower_bound(
-  OptionInfos.data() + FirstSearchableIndex, End, Name.data());
+  const Info *Start =
+  std::lower_bound(OptionInfos.data() + FirstSearchableIndex, End, Name);
   const Info *Fallback = nullptr;
   unsigned Prev = Index;
 
@@ -415,7 +407,7 @@
   StringRef Name = StringRef(Str).ltrim(PrefixChars);
 
   // Search for the first next option 

[PATCH] D138200: [include-cleaner] Make use of locateSymbol in WalkUsed

2022-12-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

looks good from my side.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138200

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


[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.

2022-12-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 480422.
VitaNuo marked an inline comment as done.
VitaNuo added a comment.

Address review comments: change comment, add more test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139087

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -172,10 +170,22 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); 
}");
+  testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); 
}");
   testWalk(
-  "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };",
+  "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };",
   "void foo() { X{}.^foo(); }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived d) { d.^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived* d) { d->^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived& d) { d.^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun() { Derived().^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "Derived foo(); void fun() { foo().^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "Derived& foo(); void fun() { foo().^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -49,6 +49,12 @@
 Callback(Loc, *cast(ND->getCanonicalDecl()), RT);
   }
 
+  NamedDecl *resolveType(QualType Type) {
+if (Type->isPointerType())
+  Type = Type->getPointeeType();
+return Type->getAsRecordDecl();
+  }
+
 public:
   ASTWalker(DeclCallback Callback, bool IsHeader)
   : Callback(Callback), IsHeader(IsHeader) {}
@@ -59,7 +65,12 @@
   }
 
   bool VisitMemberExpr(MemberExpr *E) {
-report(E->getMemberLoc(), E->getFoundDecl().getDecl());
+// A member expr implies a usage of the class type
+// (e.g., to prevent inserting a header of base class when using base
+// members from a derived object).
+// FIXME: support dependent types, e.g., "std::vector().size()".
+QualType Type = E->getBase()->IgnoreImpCasts()->getType();
+report(E->getMemberLoc(), resolveType(Type));
 return true;
   }
 


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -172,10 +170,22 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); }");
+  testWalk("struct $explicit^S { void foo(); };", "void fo

[PATCH] D136594: [clangd] Add support for semantic token type "operator"

2022-12-06 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

In D136594#3973812 , @sammccall wrote:

> For my part, I still need to understand why we want the 
> `builtin`/`UserModified` modifier. (The `operator` highlight kind seems 
> obvious to me).

We make this distinction in our client. The reasoning is explained here: 
https://codereview.qt-project.org/c/qt-creator/qt-creator/+/220587
I think Nathan made the same point earlier, i.e. it's helpful to see that an 
operator is (potentially) overloaded and you could follow the symbol.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136594

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


[PATCH] D139274: Store OptTable::Info::Name as a StringRef

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

LG




Comment at: llvm/lib/Option/OptTable.cpp:41
+  size_t MinSize = std::min(A.size(), B.size());
+  if (int res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize)))
+return res;

res -> Res


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

https://reviews.llvm.org/D139274

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


[PATCH] D138755: [Clang][CodeGen] Use poison instead of undef for extra argument in __builtin_amdgcn_mov_dpp [NFC]

2022-12-06 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito edited reviewers, added: arsenm; removed: yaxunl.
ManuelJBrito added a comment.
Herald added a subscriber: wdng.

Is this change OK? It seems to me that here undef is just a placeholder. Was 
hoping that some AMDGPU folks could review it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138755

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


[clang] 83b3304 - [AArch64] Implement __arm_rsr128/__arm_wsr128

2022-12-06 Thread Archibald Elliott via cfe-commits

Author: Archibald Elliott
Date: 2022-12-06T11:39:05Z
New Revision: 83b3304dd2a3bee8b6b4f76282adb734a5d1c8ff

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

LOG: [AArch64] Implement __arm_rsr128/__arm_wsr128

This only contains the SelectionDAG implementation. GlobalISel to
follow.

The broad approach is:
- Introduce new builtins for 128-bit wide instructions.
- Lower these to @llvm.read_register.i128/@llvm.write_register.i128
- Introduce target-specific ISD nodes which have legal operands (two
  i64s rather than an i128). These are named AArch64::{MRRS, MSRR} to
  match the instructions they are for. These are a little complex as
  they need to match the "shape" of what they're replacing or the
  legaliser complains.
- Select these using the existing tryReadRegister/tryWriteRegister to
  share the MDString parsing code, and introduce additional code to
  ensure these are selected into the right MRRS/MSRR instructions. What
  makes this hard is ensuring that the two i64s end up in an XSeqPair
  register pair, because SelectionDAG doesn't care that much about
  register classes if it can avoid doing so.

The main change to existing code is the reorganisation of
tryReadRegister and tryWriteRegister to try to keep the string parsing
code separate from the instruction creating code.

This also includes the changes to clang to define and use the ACLE
feature macro named `__ARM_FEATURE_SYSREG128`.

Contributors:
  Sam Elliott
  Lucas Prates

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

Added: 
llvm/test/CodeGen/AArch64/aarch64-sysreg128.ll

Modified: 
clang/include/clang/Basic/BuiltinsAArch64.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/arm_acle.h
clang/test/CodeGen/arm_acle.c
clang/test/Preprocessor/aarch64-target-features.c
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.h

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index bc8ab4eade91a..c9b3272e74bc8 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -82,9 +82,11 @@ BUILTIN(__builtin_arm_prefetch, "vvC*UiUiUiUi", "nc")
 // System Registers
 BUILTIN(__builtin_arm_rsr, "UicC*", "nc")
 BUILTIN(__builtin_arm_rsr64, "WUicC*", "nc")
+BUILTIN(__builtin_arm_rsr128, "LLLUicC*", "nc")
 BUILTIN(__builtin_arm_rsrp, "v*cC*", "nc")
 BUILTIN(__builtin_arm_wsr, "vcC*Ui", "nc")
 BUILTIN(__builtin_arm_wsr64, "vcC*WUi", "nc")
+BUILTIN(__builtin_arm_wsr128, "vcC*LLLUi", "nc")
 BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc")
 
 // MSVC

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2b717208313f2..0138111758657 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7605,9 +7605,10 @@ static Value *EmitSpecialRegisterBuiltin(CodeGenFunction 
&CGF,
  llvm::Type *ValueType,
  SpecialRegisterAccessKind AccessKind,
  StringRef SysReg = "") {
-  // write and register intrinsics only support 32 and 64 bit operations.
-  assert((RegisterType->isIntegerTy(32) || RegisterType->isIntegerTy(64))
-  && "Unsupported size for register.");
+  // write and register intrinsics only support 32, 64 and 128 bit operations.
+  assert((RegisterType->isIntegerTy(32) || RegisterType->isIntegerTy(64) ||
+  RegisterType->isIntegerTy(128)) &&
+ "Unsupported size for register.");
 
   CodeGen::CGBuilderTy &Builder = CGF.Builder;
   CodeGen::CodeGenModule &CGM = CGF.CGM;
@@ -10173,32 +10174,43 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 
   if (BuiltinID == clang::AArch64::BI__builtin_arm_rsr ||
   BuiltinID == clang::AArch64::BI__builtin_arm_rsr64 ||
+  BuiltinID == clang::AArch64::BI__builtin_arm_rsr128 ||
   BuiltinID == clang::AArch64::BI__builtin_arm_rsrp ||
   BuiltinID == clang::AArch64::BI__builtin_arm_wsr ||
   BuiltinID == clang::AArch64::BI__builtin_arm_wsr64 ||
+  BuiltinID == clang::AArch64::BI__builtin_arm_wsr128 ||
   BuiltinID == clang::AArch64::BI__builtin_arm_wsrp) {
 
 SpecialRegisterAccessKind AccessKind = Write;
 if (BuiltinID == clang::AArch64::BI__builtin_arm_rsr ||
 BuiltinID == clang::AArch64::BI__builtin_arm_rsr64 ||
+BuiltinID == clang::AArch64::BI__builtin_arm_rsr128 ||
 BuiltinID == clang::AArch64::BI__builtin_arm_rsrp)
   AccessKind = VolatileRead;
 
 bool IsPointerBuiltin = BuiltinID == clang::AArch64::BI__builtin_arm_rsrp 
||
 BuiltinID == c

[PATCH] D139086: [AArch64] Implement __arm_rsr128/__arm_wsr128

2022-12-06 Thread Sam Elliott 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 rG83b3304dd2a3: [AArch64] Implement __arm_rsr128/__arm_wsr128 
(authored by lenary).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139086

Files:
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/arm_acle.h
  clang/test/CodeGen/arm_acle.c
  clang/test/Preprocessor/aarch64-target-features.c
  llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/test/CodeGen/AArch64/aarch64-sysreg128.ll

Index: llvm/test/CodeGen/AArch64/aarch64-sysreg128.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/aarch64-sysreg128.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple aarch64-mattr=+d128 | FileCheck %s --check-prefixes=CHECK-LE
+; RUN: llc < %s -mtriple aarch64_be -mattr=+d128 | FileCheck %s --check-prefixes=CHECK-BE
+
+define i128 @test_rsr128() #0 {
+; CHECK-LE-LABEL: test_rsr128:
+; CHECK-LE:   // %bb.0: // %entry
+; CHECK-LE-NEXT:mrrs x0, x1, S1_2_C3_C4_5
+; CHECK-LE-NEXT:ret
+;
+; CHECK-BE-LABEL: test_rsr128:
+; CHECK-BE:   // %bb.0: // %entry
+; CHECK-BE-NEXT:mrrs x2, x3, S1_2_C3_C4_5
+; CHECK-BE-NEXT:mov x0, x3
+; CHECK-BE-NEXT:mov x1, x2
+; CHECK-BE-NEXT:ret
+entry:
+  %0 = call i128 @llvm.read_volatile_register.i128(metadata !1)
+  ret i128 %0
+}
+
+declare i128 @llvm.read_volatile_register.i128(metadata) #1
+
+define void @test_wsr128(i128 noundef %v) #0 {
+; CHECK-LE-LABEL: test_wsr128:
+; CHECK-LE:   // %bb.0: // %entry
+; CHECK-LE-NEXT:// kill: def $x1 killed $x1 killed $x0_x1 def $x0_x1
+; CHECK-LE-NEXT:// kill: def $x0 killed $x0 killed $x0_x1 def $x0_x1
+; CHECK-LE-NEXT:msrr S1_2_C3_C4_5, x0, x1
+; CHECK-LE-NEXT:ret
+;
+; CHECK-BE-LABEL: test_wsr128:
+; CHECK-BE:   // %bb.0: // %entry
+; CHECK-BE-NEXT:mov x2, x1
+; CHECK-BE-NEXT:mov x3, x0
+; CHECK-BE-NEXT:msrr S1_2_C3_C4_5, x2, x3
+; CHECK-BE-NEXT:ret
+entry:
+  call void @llvm.write_register.i128(metadata !1, i128 %v)
+  ret void
+}
+
+declare void @llvm.write_register.i128(metadata, i128) #1
+
+attributes #0 = { noinline nounwind }
+attributes #1 = { nounwind }
+
+!1 = !{!"1:2:3:4:5"}
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.h
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.h
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.h
@@ -430,6 +430,12 @@
   // the caller
   ASSERT_ZEXT_BOOL,
 
+  // 128-bit system register accesses
+  // lo64, hi64, chain = MRRS(chain, sysregname)
+  MRRS,
+  // chain = MSRR(chain, sysregname, lo64, hi64)
+  MSRR,
+
   // Strict (exception-raising) floating point comparison
   STRICT_FCMP = ISD::FIRST_TARGET_STRICTFP_OPCODE,
   STRICT_FCMPE,
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -1627,6 +1627,11 @@
   setIndexedStoreAction(im, VT, Legal);
 }
   }
+
+  if (Subtarget->hasD128()) {
+setOperationAction(ISD::READ_REGISTER, MVT::i128, Custom);
+setOperationAction(ISD::WRITE_REGISTER, MVT::i128, Custom);
+  }
 }
 
 bool AArch64TargetLowering::shouldExpandGetActiveLaneMask(EVT ResVT,
@@ -2491,6 +2496,8 @@
 MAKE_CASE(AArch64ISD::MOPS_MEMCOPY)
 MAKE_CASE(AArch64ISD::MOPS_MEMMOVE)
 MAKE_CASE(AArch64ISD::CALL_BTI)
+MAKE_CASE(AArch64ISD::MRRS)
+MAKE_CASE(AArch64ISD::MSRR)
   }
 #undef MAKE_CASE
   return nullptr;
@@ -5943,6 +5950,26 @@
 return DAG.getNode(Op.getOpcode(), DL, {Op.getValueType(), MVT::Other},
{Ext.getValue(1), Ext.getValue(0)});
   }
+  case ISD::WRITE_REGISTER: {
+assert(Op.getOperand(2).getValueType() == MVT::i128 &&
+   "WRITE_REGISTER custom lowering is only for 128-bit sysregs");
+SDLoc DL(Op);
+
+SDValue Chain = Op.getOperand(0);
+SDValue SysRegName = Op.getOperand(1);
+SDValue Pair = Op.getOperand(2);
+
+SDValue PairLo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i64, Pair,
+ DAG.getConstant(0, DL, MVT::i32));
+SDValue PairHi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i64, Pair,
+ DAG.getConstant(1, DL, MVT::i32));
+
+// chain = MSRR(chain, sysregname, lo, hi)
+SDValue Result = DAG.getNode(AArch64ISD::MSRR, DL, MVT::Other, Chain,
+ SysRegName, PairLo, PairHi);
+
+return Result;
+  }
   }
 }
 
@@ -21734,6 +21761,26 @@
 }
 }
   }
+  case ISD::READ_REGIST

[PATCH] D138200: [include-cleaner] Make use of locateSymbol in WalkUsed

2022-12-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

LG, thanks!




Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:33
+  for (auto &Loc : locateSymbol(S))
+// FIXME: findHeaders in theory returns the same result for all source
+// locations in the same FileID. Have a cache for that, since we can have

nit: I think this would be better as a vaguer comment at a higher level (in 
walkUsed) like "it might be useful to cache some parts of this computation to 
save repeated work"



Comment at: clang-tools-extra/include-cleaner/test/multiple-providers.cpp:1
+// RUN: clang-include-cleaner --print=changes %s -- -I %S/Inputs | FileCheck \
+// RUN: --allow-empty %s

nit: splitting RUN lines over lines makes copy/pasting/debugging lit tests 
harder and ends up being net-negative IMO. I've added a `.clang-format` file so 
that >80 col lines won't get split


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138200

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


[PATCH] D138755: [Clang][CodeGen] Use poison instead of undef for extra argument in __builtin_amdgcn_mov_dpp [NFC]

2022-12-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm accepted this revision.
arsenm added a comment.
This revision is now accepted and ready to land.

I think this is OK. It’s use of uninitialized value, those uninitialized values 
just happen to come from inactive lanes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138755

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


[PATCH] D139395: Add support for integer types normalization

2022-12-06 Thread Miguel Ojeda via Phabricator via cfe-commits
ojeda added subscribers: nathanchance, nickdesaulniers.
ojeda added a comment.

Cc @nickdesaulniers @nathanchance


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139395

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


[PATCH] D139398: [AMDGPU] Add bf16 storage support

2022-12-06 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh updated this revision to Diff 480431.
Pierre-vh added a comment.

- Only accept bf16 on AMDGCN; r600 doesn't support it (we could but it's not 
worth the effort I think; I'll look at it if we find out it's needed)
- Remove bf16 types from a few register classes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139398

Files:
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/test/CodeGenCUDA/amdgpu-bf16.cu
  clang/test/SemaCUDA/amdgpu-bf16.cu
  llvm/lib/Target/AMDGPU/AMDGPUCallingConv.td
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIInstructions.td
  llvm/lib/Target/AMDGPU/SIRegisterInfo.td
  llvm/lib/Target/AMDGPU/VOP3PInstructions.td
  llvm/test/CodeGen/AMDGPU/bf16-ops.ll
  llvm/test/CodeGen/AMDGPU/bf16.ll

Index: llvm/test/CodeGen/AMDGPU/bf16.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/bf16.ll
@@ -0,0 +1,956 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -march=amdgcn -verify-machineinstrs | FileCheck %s -check-prefixes=GCN
+; RUN: llc < %s -march=amdgcn -mcpu=hawaii  -verify-machineinstrs | FileCheck %s -check-prefixes=GFX7
+; RUN: llc < %s -march=amdgcn -mcpu=tonga  -verify-machineinstrs | FileCheck %s -check-prefixes=GFX8
+; RUN: llc < %s -march=amdgcn -mcpu=gfx900 -verify-machineinstrs | FileCheck %s -check-prefixes=GFX9
+; RUN: llc < %s -march=amdgcn -mcpu=gfx1010 -verify-machineinstrs | FileCheck %s -check-prefixes=GFX10
+
+; We only have storage-only BF16 support. We can load/store those values as we treat them as u16, but
+; we don't support operations on them. As such, codegen is expected to fail for any operation other
+; than simple load/stores.
+
+define void @test_load_store(bfloat addrspace(1)* %in, bfloat addrspace(1)* %out) {
+; GCN-LABEL: test_load_store:
+; GCN:   ; %bb.0:
+; GCN-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GCN-NEXT:s_mov_b32 s6, 0
+; GCN-NEXT:s_mov_b32 s7, 0xf000
+; GCN-NEXT:s_mov_b32 s4, s6
+; GCN-NEXT:s_mov_b32 s5, s6
+; GCN-NEXT:buffer_load_ushort v0, v[0:1], s[4:7], 0 addr64
+; GCN-NEXT:s_waitcnt vmcnt(0)
+; GCN-NEXT:buffer_store_short v0, v[2:3], s[4:7], 0 addr64
+; GCN-NEXT:s_waitcnt vmcnt(0) expcnt(0)
+; GCN-NEXT:s_setpc_b64 s[30:31]
+;
+; GFX7-LABEL: test_load_store:
+; GFX7:   ; %bb.0:
+; GFX7-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX7-NEXT:s_mov_b32 s6, 0
+; GFX7-NEXT:s_mov_b32 s7, 0xf000
+; GFX7-NEXT:s_mov_b32 s4, s6
+; GFX7-NEXT:s_mov_b32 s5, s6
+; GFX7-NEXT:buffer_load_ushort v0, v[0:1], s[4:7], 0 addr64
+; GFX7-NEXT:s_waitcnt vmcnt(0)
+; GFX7-NEXT:buffer_store_short v0, v[2:3], s[4:7], 0 addr64
+; GFX7-NEXT:s_waitcnt vmcnt(0)
+; GFX7-NEXT:s_setpc_b64 s[30:31]
+;
+; GFX8-LABEL: test_load_store:
+; GFX8:   ; %bb.0:
+; GFX8-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX8-NEXT:flat_load_ushort v0, v[0:1]
+; GFX8-NEXT:s_waitcnt vmcnt(0)
+; GFX8-NEXT:flat_store_short v[2:3], v0
+; GFX8-NEXT:s_waitcnt vmcnt(0)
+; GFX8-NEXT:s_setpc_b64 s[30:31]
+;
+; GFX9-LABEL: test_load_store:
+; GFX9:   ; %bb.0:
+; GFX9-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT:global_load_ushort v0, v[0:1], off
+; GFX9-NEXT:s_waitcnt vmcnt(0)
+; GFX9-NEXT:global_store_short v[2:3], v0, off
+; GFX9-NEXT:s_waitcnt vmcnt(0)
+; GFX9-NEXT:s_setpc_b64 s[30:31]
+;
+; GFX10-LABEL: test_load_store:
+; GFX10:   ; %bb.0:
+; GFX10-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX10-NEXT:s_waitcnt_vscnt null, 0x0
+; GFX10-NEXT:global_load_ushort v0, v[0:1], off
+; GFX10-NEXT:s_waitcnt vmcnt(0)
+; GFX10-NEXT:global_store_short v[2:3], v0, off
+; GFX10-NEXT:s_waitcnt_vscnt null, 0x0
+; GFX10-NEXT:s_setpc_b64 s[30:31]
+  %val = load bfloat, bfloat addrspace(1)* %in
+  store bfloat %val, bfloat addrspace(1) * %out
+  ret void
+}
+
+define void @test_load_store_v2bf16(<2 x bfloat> addrspace(1)* %in, <2 x bfloat> addrspace(1)* %out) {
+; GCN-LABEL: test_load_store_v2bf16:
+; GCN:   ; %bb.0:
+; GCN-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GCN-NEXT:s_mov_b32 s6, 0
+; GCN-NEXT:s_mov_b32 s7, 0xf000
+; GCN-NEXT:s_mov_b32 s4, s6
+; GCN-NEXT:s_mov_b32 s5, s6
+; GCN-NEXT:buffer_load_dword v0, v[0:1], s[4:7], 0 addr64
+; GCN-NEXT:s_waitcnt vmcnt(0)
+; GCN-NEXT:buffer_store_dword v0, v[2:3], s[4:7], 0 addr64
+; GCN-NEXT:s_waitcnt vmcnt(0) expcnt(0)
+; GCN-NEXT:s_setpc_b64 s[30:31]
+;
+; GFX7-LABEL: test_load_store_v2bf16:
+; GFX7:   ; %bb.0:
+; GFX7-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX7-NEXT:s_mov_b32 s6, 0
+; GFX7-NEXT:s_mov_b32 s7, 0xf000
+; GFX7-NEXT:s_mov_b32 s4, s6
+; GFX7-NEXT:s_mov_b32 s5, s6
+; GFX7-NEXT

[clang] 481170c - [Clang][CodeGen] Use poison instead of undef for extra argument in __builtin_amdgcn_mov_dpp [NFC]

2022-12-06 Thread Nuno Lopes via cfe-commits

Author: Manuel Brito
Date: 2022-12-06T12:40:33Z
New Revision: 481170cb551124ed89353dd55a89b1d9971e9a6d

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

LOG: [Clang][CodeGen] Use poison instead of undef for extra argument in 
__builtin_amdgcn_mov_dpp [NFC]

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 0138111758657..d40910b76b599 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -16905,7 +16905,7 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   Args.push_back(EmitScalarExpr(E->getArg(I)));
 assert(Args.size() == 5 || Args.size() == 6);
 if (Args.size() == 5)
-  Args.insert(Args.begin(), llvm::UndefValue::get(Args[0]->getType()));
+  Args.insert(Args.begin(), llvm::PoisonValue::get(Args[0]->getType()));
 Function *F =
 CGM.getIntrinsic(Intrinsic::amdgcn_update_dpp, Args[0]->getType());
 return Builder.CreateCall(F, Args);

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl
index daba1b972787e..c7437d7c1e881 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl
@@ -101,7 +101,7 @@ void test_s_dcache_wb()
 }
 
 // CHECK-LABEL: @test_mov_dpp
-// CHECK: call i32 @llvm.amdgcn.update.dpp.i32(i32 undef, i32 %src, i32 0, i32 
0, i32 0, i1 false)
+// CHECK: call i32 @llvm.amdgcn.update.dpp.i32(i32 poison, i32 %src, i32 0, 
i32 0, i32 0, i1 false)
 void test_mov_dpp(global int* out, int src)
 {
   *out = __builtin_amdgcn_mov_dpp(src, 0, 0, 0, false);



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


[PATCH] D138755: [Clang][CodeGen] Use poison instead of undef for extra argument in __builtin_amdgcn_mov_dpp [NFC]

2022-12-06 Thread Nuno Lopes 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 rG481170cb5511: [Clang][CodeGen] Use poison instead of undef 
for extra argument in… (authored by ManuelJBrito, committed by nlopes).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138755

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl


Index: clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl
@@ -101,7 +101,7 @@
 }
 
 // CHECK-LABEL: @test_mov_dpp
-// CHECK: call i32 @llvm.amdgcn.update.dpp.i32(i32 undef, i32 %src, i32 0, i32 
0, i32 0, i1 false)
+// CHECK: call i32 @llvm.amdgcn.update.dpp.i32(i32 poison, i32 %src, i32 0, 
i32 0, i32 0, i1 false)
 void test_mov_dpp(global int* out, int src)
 {
   *out = __builtin_amdgcn_mov_dpp(src, 0, 0, 0, false);
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -16905,7 +16905,7 @@
   Args.push_back(EmitScalarExpr(E->getArg(I)));
 assert(Args.size() == 5 || Args.size() == 6);
 if (Args.size() == 5)
-  Args.insert(Args.begin(), llvm::UndefValue::get(Args[0]->getType()));
+  Args.insert(Args.begin(), llvm::PoisonValue::get(Args[0]->getType()));
 Function *F =
 CGM.getIntrinsic(Intrinsic::amdgcn_update_dpp, Args[0]->getType());
 return Builder.CreateCall(F, Args);


Index: clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl
@@ -101,7 +101,7 @@
 }
 
 // CHECK-LABEL: @test_mov_dpp
-// CHECK: call i32 @llvm.amdgcn.update.dpp.i32(i32 undef, i32 %src, i32 0, i32 0, i32 0, i1 false)
+// CHECK: call i32 @llvm.amdgcn.update.dpp.i32(i32 poison, i32 %src, i32 0, i32 0, i32 0, i1 false)
 void test_mov_dpp(global int* out, int src)
 {
   *out = __builtin_amdgcn_mov_dpp(src, 0, 0, 0, false);
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -16905,7 +16905,7 @@
   Args.push_back(EmitScalarExpr(E->getArg(I)));
 assert(Args.size() == 5 || Args.size() == 6);
 if (Args.size() == 5)
-  Args.insert(Args.begin(), llvm::UndefValue::get(Args[0]->getType()));
+  Args.insert(Args.begin(), llvm::PoisonValue::get(Args[0]->getType()));
 Function *F =
 CGM.getIntrinsic(Intrinsic::amdgcn_update_dpp, Args[0]->getType());
 return Builder.CreateCall(F, Args);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139288: [Clang][LoongArch] Add intrinsic for csrrd, csrwr and csrxchg

2022-12-06 Thread Lu Weining via Phabricator via cfe-commits
SixWeining accepted this revision.
SixWeining 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/D139288/new/

https://reviews.llvm.org/D139288

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


[PATCH] D139398: [AMDGPU] Add bf16 storage support

2022-12-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm requested changes to this revision.
arsenm added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/Basic/Targets/AMDGPU.h:119
+  bool hasBFloat16Type() const override { return isAMDGCN(getTriple()); }
+  const char *getBFloat16Mangling() const override { return "u6__bf16"; };
+

Don't understand this mangling. What is u6?



Comment at: clang/test/CodeGenCUDA/amdgpu-bf16.cu:30
+  *out = bf16;
+}
+

should also test a load



Comment at: clang/test/SemaCUDA/amdgpu-bf16.cu:43
+  *out = bf16;
+}
+

check casts to different int and float types? Is construction of bf16 vectors 
allowed?



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:4819-4831
+// When we don't have 16 bit instructions, bf16 is illegal and gets
+// softened to i16 for storage, with float being used for arithmetic.
+//
+// After softening, some i16 -> fp32 bf16_to_fp operations can be left 
over.
+// Lower those to (f32 (fp_extend (f16 (bitconvert x
+if (!Op->getValueType(0).isFloatingPoint() ||
+Op->getOperand(0).getValueType() != MVT::i16)

The generic legalizer should have handled this?



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:5185-5198
+// When we don't have 16 bit instructions, bf16 is illegal and gets
+// softened to i16 for storage, with float being used for arithmetic.
+//
+// After softening, fp_to_bf16 can be emitted, but with a i16 VT instead.
+// Of course those won't work, so we handle them here by lowering them
+// to (i16 (bitconvert (f32 (fptrunc x
+if (N->getValueType(0) != MVT::i16)

Ditto



Comment at: llvm/test/CodeGen/AMDGPU/bf16-ops.ll:1-4
+; RUN: not llc < %s -march=amdgcn -mcpu=hawaii  -verify-machineinstrs
+; RUN: not llc < %s -march=amdgcn -mcpu=tonga  -verify-machineinstrs
+; RUN: not llc < %s -march=amdgcn -mcpu=gfx900 -verify-machineinstrs
+; RUN: not llc < %s -march=amdgcn -mcpu=gfx1010 -verify-machineinstrs

Drop -verify-machineinstrs



Comment at: llvm/test/CodeGen/AMDGPU/bf16-ops.ll:22
+
+define void @test_add(bfloat %a, bfloat %b, bfloat addrspace(1)* %out) {
+  %result = fadd bfloat %a, %b

Use opaque pointers



Comment at: llvm/test/CodeGen/AMDGPU/bf16.ll:432
+}
+
+define void @test_arg_store_v4bf16(<4 x bfloat> %in, <4 x bfloat> 
addrspace(1)* %out) {

Missing v3 test



Comment at: llvm/test/CodeGen/AMDGPU/bf16.ll:899
+}
+
+define bfloat @test_alloca_load_store_ret(bfloat %in) {

Ret of vectors



Comment at: llvm/test/CodeGen/AMDGPU/bf16.ll:953
+  store volatile bfloat %in, bfloat addrspace(5)* %in.addr, align 2
+  %0 = load volatile bfloat, bfloat addrspace(5)* %in.addr, align 2
+  ret bfloat %0

Don't use anonymous values. Also use opaque pointers



Comment at: llvm/test/CodeGen/AMDGPU/bf16.ll:956
+}
+

Should also test call argument, call return, passed in byval, sret, implicit 
sret, and passed in argument in overflow stack area


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139398

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


[PATCH] D139398: [AMDGPU] Add bf16 storage support

2022-12-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:147
 addRegisterClass(MVT::f16, &AMDGPU::SReg_32RegClass);
+addRegisterClass(MVT::bf16, &AMDGPU::SReg_32RegClass);
 

Do you really need to add this to a register class? The only thing this would 
be useful for is for the calling convention contexts, which should promote to 
i16. If you do that you don't need most of the rest of this patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139398

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


[clang] 8ae1830 - Store OptTable::Info::Name as a StringRef

2022-12-06 Thread via cfe-commits

Author: serge-sans-paille
Date: 2022-12-06T14:10:07+01:00
New Revision: 8ae18303f97d5dcfaecc90b4d87effb2011ed82e

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

LOG: Store OptTable::Info::Name as a StringRef

This avoids implicit conversion to StringRef at several points, which in
turns avoid redundant calls to strlen.

As a side effect, this greatly simplifies the implementation of
StrCmpOptionNameIgnoreCase.

It also eventually gives a consistent, humble speedup in compilation
time.

https://llvm-compile-time-tracker.com/compare.php?from=5f5b942823474e98e43a27d515a87ce140396c53&to=60e13b778119fc32d50dc38ff1a564a87146e9c6&stat=instructions:u

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
llvm/include/llvm/Option/OptTable.h
llvm/lib/Option/OptTable.cpp
llvm/unittests/Option/OptionMarshallingTest.cpp
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 4621850f13772..60d62e2b9c5c1 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -331,8 +331,8 @@ static bool getStaticPIE(const ArgList &Args, const 
ToolChain &TC) {
   if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
 const Driver &D = TC.getDriver();
 const llvm::opt::OptTable &Opts = D.getOpts();
-const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
-const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
+StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
+StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
 D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
   }
   return HasStaticPIE;

diff  --git a/llvm/include/llvm/Option/OptTable.h 
b/llvm/include/llvm/Option/OptTable.h
index 07d9870f71b33..e884ebeb788c4 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -44,7 +44,7 @@ class OptTable {
 /// A null terminated array of prefix strings to apply to name while
 /// matching.
 const char *const *Prefixes;
-const char *Name;
+StringRef Name;
 const char *HelpText;
 const char *MetaVar;
 unsigned ID;
@@ -102,9 +102,7 @@ class OptTable {
   const Option getOption(OptSpecifier Opt) const;
 
   /// Lookup the name of the given option.
-  const char *getOptionName(OptSpecifier id) const {
-return getInfo(id).Name;
-  }
+  StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
 
   /// Get the kind of the given option.
   unsigned getOptionKind(OptSpecifier id) const {
@@ -184,7 +182,7 @@ class OptTable {
   ///  takes
   ///
   /// \return true in success, and false in fail.
-  bool addValues(const char *Option, const char *Values);
+  bool addValues(StringRef Option, const char *Values);
 
   /// Parse a single argument; returning the new argument and
   /// updating Index.

diff  --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index ef4873eb7f9c4..f23561b5d078d 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -36,31 +36,23 @@ namespace opt {
 // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
 // with an exception. '\0' comes at the end of the alphabet instead of the
 // beginning (thus options precede any other options which prefix them).
-static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
-  const char *X = A, *Y = B;
-  char a = tolower(*A), b = tolower(*B);
-  while (a == b) {
-if (a == '\0')
-  return 0;
-
-a = tolower(*++X);
-b = tolower(*++Y);
-  }
+static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
+  size_t MinSize = std::min(A.size(), B.size());
+  if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize)))
+return Res;
 
-  if (a == '\0') // A is a prefix of B.
-return 1;
-  if (b == '\0') // B is a prefix of A.
-return -1;
+  if (A.size() == B.size())
+return 0;
 
-  // Otherwise lexicographic.
-  return (a < b) ? -1 : 1;
+  return (A.size() == MinSize) ? 1 /* A is a prefix of B. */
+   : -1 /* B is a prefix of A */;
 }
 
 #ifndef NDEBUG
-static int StrCmpOptionName(const char *A, const char *B) {
+static int StrCmpOptionName(StringRef A, StringRef B) {
   if (int N = StrCmpOptionNameIgnoreCase(A, B))
 return N;
-  return strcmp(A, B);
+  return A.compare(B);
 }
 
 static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) 
{
@@ -86,7 +78,7 @@ static inline bool operator<(const OptTable::Info &A, const 
OptTable::Info &B) {
 #endif
 
 // Support lower_bound between info and an o

[PATCH] D139274: Store OptTable::Info::Name as a StringRef

2022-12-06 Thread serge 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 rG8ae18303f97d: Store OptTable::Info::Name as a StringRef 
(authored by serge-sans-paille).

Changed prior to commit:
  https://reviews.llvm.org/D139274?vs=480421&id=480440#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139274

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/Option/OptTable.cpp
  llvm/unittests/Option/OptionMarshallingTest.cpp
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -54,9 +54,9 @@
 
 static void emitNameUsingSpelling(raw_ostream &OS, const Record &R) {
   size_t PrefixLength;
-  OS << "&";
+  OS << "llvm::StringRef(";
   write_cstring(OS, StringRef(getOptionSpelling(R, PrefixLength)));
-  OS << "[" << PrefixLength << "]";
+  OS << ").substr(" << PrefixLength << ")";
 }
 
 class MarshallingInfo {
Index: llvm/unittests/Option/OptionMarshallingTest.cpp
===
--- llvm/unittests/Option/OptionMarshallingTest.cpp
+++ llvm/unittests/Option/OptionMarshallingTest.cpp
@@ -6,10 +6,11 @@
 //
 //===--===//
 
+#include "llvm/ADT/StringRef.h"
 #include "gtest/gtest.h"
 
 struct OptionWithMarshallingInfo {
-  const char *Name;
+  llvm::StringRef Name;
   const char *KeyPath;
   const char *ImpliedCheck;
   const char *ImpliedValue;
@@ -27,10 +28,10 @@
 };
 
 TEST(OptionMarshalling, EmittedOrderSameAsDefinitionOrder) {
-  ASSERT_STREQ(MarshallingTable[0].Name, "marshalled-flag-d");
-  ASSERT_STREQ(MarshallingTable[1].Name, "marshalled-flag-c");
-  ASSERT_STREQ(MarshallingTable[2].Name, "marshalled-flag-b");
-  ASSERT_STREQ(MarshallingTable[3].Name, "marshalled-flag-a");
+  ASSERT_STREQ(MarshallingTable[0].Name.data(), "marshalled-flag-d");
+  ASSERT_STREQ(MarshallingTable[1].Name.data(), "marshalled-flag-c");
+  ASSERT_STREQ(MarshallingTable[2].Name.data(), "marshalled-flag-b");
+  ASSERT_STREQ(MarshallingTable[3].Name.data(), "marshalled-flag-a");
 }
 
 TEST(OptionMarshalling, EmittedSpecifiedKeyPath) {
Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -36,31 +36,23 @@
 // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
 // with an exception. '\0' comes at the end of the alphabet instead of the
 // beginning (thus options precede any other options which prefix them).
-static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
-  const char *X = A, *Y = B;
-  char a = tolower(*A), b = tolower(*B);
-  while (a == b) {
-if (a == '\0')
-  return 0;
-
-a = tolower(*++X);
-b = tolower(*++Y);
-  }
+static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
+  size_t MinSize = std::min(A.size(), B.size());
+  if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize)))
+return Res;
 
-  if (a == '\0') // A is a prefix of B.
-return 1;
-  if (b == '\0') // B is a prefix of A.
-return -1;
+  if (A.size() == B.size())
+return 0;
 
-  // Otherwise lexicographic.
-  return (a < b) ? -1 : 1;
+  return (A.size() == MinSize) ? 1 /* A is a prefix of B. */
+   : -1 /* B is a prefix of A */;
 }
 
 #ifndef NDEBUG
-static int StrCmpOptionName(const char *A, const char *B) {
+static int StrCmpOptionName(StringRef A, StringRef B) {
   if (int N = StrCmpOptionNameIgnoreCase(A, B))
 return N;
-  return strcmp(A, B);
+  return A.compare(B);
 }
 
 static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) {
@@ -86,7 +78,7 @@
 #endif
 
 // Support lower_bound between info and an option name.
-static inline bool operator<(const OptTable::Info &I, const char *Name) {
+static inline bool operator<(const OptTable::Info &I, StringRef Name) {
   return StrCmpOptionNameIgnoreCase(I.Name, Name) < 0;
 }
 
@@ -321,7 +313,7 @@
   return BestDistance;
 }
 
-bool OptTable::addValues(const char *Option, const char *Values) {
+bool OptTable::addValues(StringRef Option, const char *Values) {
   for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
 Info &In = OptionInfos[I];
 if (optionMatches(In, Option)) {
@@ -347,8 +339,8 @@
 
   const Info *End = OptionInfos.data() + OptionInfos.size();
   StringRef Name = Str.ltrim(PrefixChars);
-  const Info *Start = std::lower_bound(
-  OptionInfos.data() + FirstSearchableIndex, End, Name.data());
+  const Info *Start =
+  std::lower_bound(OptionInfos.data() + FirstSearchableIndex, End, Name);

[PATCH] D139416: [clang-format] Don't require deduction guides to be templates

2022-12-06 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel created this revision.
rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay.
Herald added a project: All.
rymiel requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The C++ standard doesn't require that class template deduction guides
be templates themselves, but previously `isDeductionGuide` would assert
for the existence of a template closer or requires clause closer before
the deduction guide declaration.

This patch simply removes that check. Because of this, a test which
asserted that `x()->x<1>;` *isn't* a deduction guide failed, as it is
now formatted as a deduction guide. However, as @JohelEGP demonstrated,
it is [possible to make that a viable deduction guide][1].

Thus, that test has been removed, but other tests related to
non-template class template deduction guides have been added.

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

[1]: https://compiler-explorer.com/z/Wx3K6d5K9


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139416

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8001,12 +8001,14 @@
   verifyFormat("template  x() -> x<1>;");
   verifyFormat("template  explicit x(T &) -> x<1>;");
 
+  verifyFormat("A(const char *) -> A;");
+  verifyFormat("A() -> A;");
+
   // Ensure not deduction guides.
   verifyFormat("c()->f();");
   verifyFormat("x()->foo<1>;");
   verifyFormat("x = p->foo<3>();");
   verifyFormat("x()->x<1>();");
-  verifyFormat("x()->x<1>;");
 }
 
 TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1804,21 +1804,8 @@
 FormatToken *LeadingIdentifier =
 Current.Previous->MatchingParen->Previous;
 
-// Differentiate a deduction guide by seeing the
-// > of the template prior to the leading identifier.
-if (LeadingIdentifier) {
-  FormatToken *PriorLeadingIdentifier = LeadingIdentifier->Previous;
-  // Skip back past explicit decoration
-  if (PriorLeadingIdentifier &&
-  PriorLeadingIdentifier->is(tok::kw_explicit)) {
-PriorLeadingIdentifier = PriorLeadingIdentifier->Previous;
-  }
-
-  return PriorLeadingIdentifier &&
- (PriorLeadingIdentifier->is(TT_TemplateCloser) ||
-  PriorLeadingIdentifier->ClosesRequiresClause) &&
- LeadingIdentifier->TokenText == Current.Next->TokenText;
-}
+return LeadingIdentifier &&
+   LeadingIdentifier->TokenText == Current.Next->TokenText;
   }
 }
 return false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8001,12 +8001,14 @@
   verifyFormat("template  x() -> x<1>;");
   verifyFormat("template  explicit x(T &) -> x<1>;");
 
+  verifyFormat("A(const char *) -> A;");
+  verifyFormat("A() -> A;");
+
   // Ensure not deduction guides.
   verifyFormat("c()->f();");
   verifyFormat("x()->foo<1>;");
   verifyFormat("x = p->foo<3>();");
   verifyFormat("x()->x<1>();");
-  verifyFormat("x()->x<1>;");
 }
 
 TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1804,21 +1804,8 @@
 FormatToken *LeadingIdentifier =
 Current.Previous->MatchingParen->Previous;
 
-// Differentiate a deduction guide by seeing the
-// > of the template prior to the leading identifier.
-if (LeadingIdentifier) {
-  FormatToken *PriorLeadingIdentifier = LeadingIdentifier->Previous;
-  // Skip back past explicit decoration
-  if (PriorLeadingIdentifier &&
-  PriorLeadingIdentifier->is(tok::kw_explicit)) {
-PriorLeadingIdentifier = PriorLeadingIdentifier->Previous;
-  }
-
-  return PriorLeadingIdentifier &&
- (PriorLeadingIdentifier->is(TT_TemplateCloser) ||
-  PriorLeadingIdentifier->ClosesRequiresClause) &&
- LeadingIdentifier->TokenText == Current.Next->TokenText;
-}
+return LeadingIdentifier &&
+   LeadingIdentifier->TokenText == Current.Next->TokenText;
   }
 }
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llv

[PATCH] D139274: Store OptTable::Info::Name as a StringRef

2022-12-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This breaks building lldb: http://45.33.8.238/linux/93366/step_4.txt


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139274

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


[clang] de4b6a1 - Revert "Store OptTable::Info::Name as a StringRef"

2022-12-06 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-12-06T08:43:48-05:00
New Revision: de4b6a1bc64db33643f001ad45fae7b92b4a4688

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

LOG: Revert "Store OptTable::Info::Name as a StringRef"

This reverts commit 8ae18303f97d5dcfaecc90b4d87effb2011ed82e.
Breaks buildling lldb, see https://reviews.llvm.org/D139274#3974171

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
llvm/include/llvm/Option/OptTable.h
llvm/lib/Option/OptTable.cpp
llvm/unittests/Option/OptionMarshallingTest.cpp
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 60d62e2b9c5c1..4621850f13772 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -331,8 +331,8 @@ static bool getStaticPIE(const ArgList &Args, const 
ToolChain &TC) {
   if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
 const Driver &D = TC.getDriver();
 const llvm::opt::OptTable &Opts = D.getOpts();
-StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
-StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
+const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
+const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
 D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
   }
   return HasStaticPIE;

diff  --git a/llvm/include/llvm/Option/OptTable.h 
b/llvm/include/llvm/Option/OptTable.h
index e884ebeb788c4..07d9870f71b33 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -44,7 +44,7 @@ class OptTable {
 /// A null terminated array of prefix strings to apply to name while
 /// matching.
 const char *const *Prefixes;
-StringRef Name;
+const char *Name;
 const char *HelpText;
 const char *MetaVar;
 unsigned ID;
@@ -102,7 +102,9 @@ class OptTable {
   const Option getOption(OptSpecifier Opt) const;
 
   /// Lookup the name of the given option.
-  StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
+  const char *getOptionName(OptSpecifier id) const {
+return getInfo(id).Name;
+  }
 
   /// Get the kind of the given option.
   unsigned getOptionKind(OptSpecifier id) const {
@@ -182,7 +184,7 @@ class OptTable {
   ///  takes
   ///
   /// \return true in success, and false in fail.
-  bool addValues(StringRef Option, const char *Values);
+  bool addValues(const char *Option, const char *Values);
 
   /// Parse a single argument; returning the new argument and
   /// updating Index.

diff  --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index f23561b5d078d..ef4873eb7f9c4 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -36,23 +36,31 @@ namespace opt {
 // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
 // with an exception. '\0' comes at the end of the alphabet instead of the
 // beginning (thus options precede any other options which prefix them).
-static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
-  size_t MinSize = std::min(A.size(), B.size());
-  if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize)))
-return Res;
+static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
+  const char *X = A, *Y = B;
+  char a = tolower(*A), b = tolower(*B);
+  while (a == b) {
+if (a == '\0')
+  return 0;
+
+a = tolower(*++X);
+b = tolower(*++Y);
+  }
 
-  if (A.size() == B.size())
-return 0;
+  if (a == '\0') // A is a prefix of B.
+return 1;
+  if (b == '\0') // B is a prefix of A.
+return -1;
 
-  return (A.size() == MinSize) ? 1 /* A is a prefix of B. */
-   : -1 /* B is a prefix of A */;
+  // Otherwise lexicographic.
+  return (a < b) ? -1 : 1;
 }
 
 #ifndef NDEBUG
-static int StrCmpOptionName(StringRef A, StringRef B) {
+static int StrCmpOptionName(const char *A, const char *B) {
   if (int N = StrCmpOptionNameIgnoreCase(A, B))
 return N;
-  return A.compare(B);
+  return strcmp(A, B);
 }
 
 static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) 
{
@@ -78,7 +86,7 @@ static inline bool operator<(const OptTable::Info &A, const 
OptTable::Info &B) {
 #endif
 
 // Support lower_bound between info and an option name.
-static inline bool operator<(const OptTable::Info &I, StringRef Name) {
+static inline bool operator<(const OptTable::Info &I, const char *Name) {
   return StrCmpOptionNameIgnoreCase(I.Name, Name) < 0;
 }
 
@@ -313,7 +321,7 @@ unsigned OptTable::findNearest(StringRef Option, 
std::string &NearestString,
   return BestDistance;
 }
 
-bool OptTable::add

[PATCH] D139274: Store OptTable::Info::Name as a StringRef

2022-12-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Reverted in de4b6a1bc64db33643f001ad45fae7b92b4a4688 
 for now. 
(Note that there was a follow-up fix in 
e50a60d7349de151bd2b06d85a79201ebc372d8a 
 that I 
reverted in 13e061e73e1b067589d3bd680fc29297d7e4ec8d 
. When you 
reland, you'll likely want to cherry-pick that into your reland.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139274

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


[PATCH] D139274: Store OptTable::Info::Name as a StringRef

2022-12-06 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

In D139274#3974176 , @thakis wrote:

> Reverted in de4b6a1bc64db33643f001ad45fae7b92b4a4688 
>  for 
> now. (Note that there was a follow-up fix in 
> e50a60d7349de151bd2b06d85a79201ebc372d8a 
>  that I 
> reverted in 13e061e73e1b067589d3bd680fc29297d7e4ec8d 
> . When 
> you reland, you'll likely want to cherry-pick that into your reland.)

You've been quicker than I am. Thanks for the revert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139274

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


[clang] af95441 - [clang] Tweak test to tolerate clang being called "clang" instead of "clang-15"

2022-12-06 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-12-06T08:50:37-05:00
New Revision: af95441ba7f3ca61c925409e58ee7e5486d84033

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

LOG: [clang] Tweak test to tolerate clang being called "clang" instead of 
"clang-15"

Added: 


Modified: 
clang/test/Driver/hip-link-bc-to-bc.hip

Removed: 




diff  --git a/clang/test/Driver/hip-link-bc-to-bc.hip 
b/clang/test/Driver/hip-link-bc-to-bc.hip
index ac6dcf494224b..f759ee4cc2ce8 100644
--- a/clang/test/Driver/hip-link-bc-to-bc.hip
+++ b/clang/test/Driver/hip-link-bc-to-bc.hip
@@ -11,10 +11,10 @@
 // RUN:   2>&1 | FileCheck -check-prefix=BITCODE %s
 
 // BITCODE: "{{.*}}clang-offload-bundler" "-type=bc" 
"-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx906" 
"-input={{.*}}bundle1.bc" "-output=[[B1HOST:.*\.bc]]" 
"-output=[[B1DEV1:.*\.bc]]" "-unbundle" "-allow-missing-bundles"
-// BITCODE: "{{.*}}clang-{{.*}}" "-o" "[[B1DEV2:.*bundle1-gfx906.bc]]" "-x" 
"ir" "[[B1DEV1]]"
+// BITCODE: "{{.*}}clang{{.*}}" "-o" "[[B1DEV2:.*bundle1-gfx906.bc]]" "-x" 
"ir" "[[B1DEV1]]"
 
 // BITCODE: "{{.*}}clang-offload-bundler" "-type=bc" 
"-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx906" 
"-input={{.*}}bundle2.bc" "-output=[[B2HOST:.*\.bc]]" 
"-output=[[B2DEV1:.*\.bc]]" "-unbundle" "-allow-missing-bundles"
-// BITCODE: "{{.*}}clang-{{.*}}" "-o" "[[B2DEV2:.*bundle2-gfx906.bc]]" "-x" 
"ir" "[[B2DEV1]]"
+// BITCODE: "{{.*}}clang{{.*}}" "-o" "[[B2DEV2:.*bundle2-gfx906.bc]]" "-x" 
"ir" "[[B2DEV1]]"
 
 // BITCODE: "{{.*}}llvm-link" "-o" "bundle1-hip-amdgcn-amd-amdhsa-gfx906.bc" 
"[[B1DEV2]]" "[[B2DEV2]]"
 
@@ -28,7 +28,7 @@
 // RUN:   2>&1 | FileCheck -check-prefix=ARCHIVE %s
 
 // ARCHIVE: "{{.*}}clang-offload-bundler" "-type=bc" 
"-targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa-gfx906" 
"-input={{.*}}bundle.bc" "-output=[[HOST:.*\.bc]]" "-output=[[DEV1:.*\.bc]]" 
"-unbundle" "-allow-missing-bundles"
-// ARCHIVE: "{{.*}}clang-{{.*}}" "-o" "[[DEV2:.*\.bc]]" "-x" "ir" "[[DEV1]]"
+// ARCHIVE: "{{.*}}clang{{.*}}" "-o" "[[DEV2:.*\.bc]]" "-x" "ir" "[[DEV1]]"
 
 // ARCHIVE: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" 
"-input={{.*}}libhipbundle.a" "-targets=hip-amdgcn-amd-amdhsa-gfx906" 
"-output=[[AR:.*\.a]]" "-allow-missing-bundles" "-hip-openmp-compatible"
 



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


[PATCH] D137275: [Driver][test] Fix test by creating empty archive instead of empty file

2022-12-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In D137275#3972773 , @thakis wrote:

> This breaks check-clang: http://45.33.8.238/linux/93300/step_7.txt
>
> Please take a look and revert for now if it takes a while to fix.

This ended up being a local config thing that I fixed in 
af95441ba7f3ca61c925409e58ee7e5486d84033 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137275

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


[PATCH] D138200: [include-cleaner] Make use of locateSymbol in WalkUsed

2022-12-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 2 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/include-cleaner/test/multiple-providers.cpp:1
+// RUN: clang-include-cleaner --print=changes %s -- -I %S/Inputs | FileCheck \
+// RUN: --allow-empty %s

sammccall wrote:
> nit: splitting RUN lines over lines makes copy/pasting/debugging lit tests 
> harder and ends up being net-negative IMO. I've added a `.clang-format` file 
> so that >80 col lines won't get split
i also have some extra enforcement by my editor for line breaks :P. i didn't 
know copy pasting run lines were a workflow (because they usually have place 
holders one needs to change afterwards), i've always used the command line 
printed with the failing test. makes sense to keep it in a single line for 
people with such a workflow though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138200

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


[PATCH] D138200: [include-cleaner] Make use of locateSymbol in WalkUsed

2022-12-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 480454.
kadircet marked an inline comment as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138200

Files:
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/test/Inputs/foo2.h
  clang-tools-extra/include-cleaner/test/multiple-providers.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -18,7 +18,6 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -26,6 +25,7 @@
 
 namespace clang::include_cleaner {
 namespace {
+using testing::Contains;
 using testing::ElementsAre;
 using testing::Pair;
 using testing::UnorderedElementsAre;
@@ -34,8 +34,48 @@
   return "#pragma once\n" + Code.str();
 }
 
-TEST(WalkUsed, Basic) {
-  // FIXME: Have a fixture for setting up tests.
+class WalkUsedTest : public testing::Test {
+protected:
+  TestInputs Inputs;
+  PragmaIncludes PI;
+  WalkUsedTest() {
+Inputs.MakeAction = [this] {
+  struct Hook : public SyntaxOnlyAction {
+  public:
+Hook(PragmaIncludes *Out) : Out(Out) {}
+bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+  Out->record(CI);
+  return true;
+}
+
+PragmaIncludes *Out;
+  };
+  return std::make_unique(&PI);
+};
+  }
+
+  llvm::DenseMap>
+  offsetToProviders(TestAST &AST, SourceManager &SM,
+llvm::ArrayRef MacroRefs = {}) {
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
+  if (!SM.isWrittenInMainFile(SM.getExpansionLoc(D->getLocation(
+continue;
+  TopLevelDecls.emplace_back(D);
+}
+llvm::DenseMap> OffsetToProviders;
+walkUsed(TopLevelDecls, MacroRefs, &PI, SM,
+ [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
+   auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
+   if (FID != SM.getMainFileID())
+ ADD_FAILURE() << "Reference outside of the main file!";
+   OffsetToProviders.try_emplace(Offset, Providers.vec());
+ });
+return OffsetToProviders;
+  }
+};
+
+TEST_F(WalkUsedTest, Basic) {
   llvm::Annotations Code(R"cpp(
   #include "header.h"
   #include "private.h"
@@ -45,7 +85,7 @@
 std::$vector^vector $vconstructor^v;
   }
   )cpp");
-  TestInputs Inputs(Code.code());
+  Inputs.Code = Code.code();
   Inputs.ExtraFiles["header.h"] = guard(R"cpp(
   void foo();
   namespace std { class vector {}; }
@@ -55,85 +95,75 @@
 class Private {};
   )cpp");
 
-  PragmaIncludes PI;
-  Inputs.MakeAction = [&PI] {
-struct Hook : public SyntaxOnlyAction {
-public:
-  Hook(PragmaIncludes *Out) : Out(Out) {}
-  bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
-Out->record(CI);
-return true;
-  }
-
-  PragmaIncludes *Out;
-};
-return std::make_unique(&PI);
-  };
   TestAST AST(Inputs);
-
-  llvm::SmallVector TopLevelDecls;
-  for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
-TopLevelDecls.emplace_back(D);
-  }
-
   auto &SM = AST.sourceManager();
-  llvm::DenseMap> OffsetToProviders;
-  walkUsed(TopLevelDecls, /*MacroRefs=*/{}, &PI, SM,
-   [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
- auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
- EXPECT_EQ(FID, SM.getMainFileID());
- OffsetToProviders.try_emplace(Offset, Providers.vec());
-   });
-  auto &FM = AST.fileManager();
-  auto HeaderFile = Header(FM.getFile("header.h").get());
+  auto HeaderFile = Header(AST.fileManager().getFile("header.h").get());
+  auto PrivateFile = Header(AST.fileManager().getFile("private.h").get());
+  auto PublicFile = Header("\"path/public.h\"");
   auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
   auto VectorSTL = Header(tooling::stdlib::Header::named("").value());
   EXPECT_THAT(
-  OffsetToProviders,
+  offsetToProviders(AST, SM),
   UnorderedElementsAre(
   Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
   Pair(Code.point("private"),
-   UnorderedElementsAre(Header("\"path/public.h\""),
-Header(FM.getFile("private.h").get(,
+   UnorderedElementsAre(Publ

[PATCH] D138200: [include-cleaner] Make use of locateSymbol in WalkUsed

2022-12-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG29a8eec1f9eb: [include-cleaner] Make use of locateSymbol in 
WalkUsed and HTMLReport (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138200

Files:
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/test/Inputs/foo2.h
  clang-tools-extra/include-cleaner/test/multiple-providers.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -18,7 +18,6 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -26,6 +25,7 @@
 
 namespace clang::include_cleaner {
 namespace {
+using testing::Contains;
 using testing::ElementsAre;
 using testing::Pair;
 using testing::UnorderedElementsAre;
@@ -34,8 +34,48 @@
   return "#pragma once\n" + Code.str();
 }
 
-TEST(WalkUsed, Basic) {
-  // FIXME: Have a fixture for setting up tests.
+class WalkUsedTest : public testing::Test {
+protected:
+  TestInputs Inputs;
+  PragmaIncludes PI;
+  WalkUsedTest() {
+Inputs.MakeAction = [this] {
+  struct Hook : public SyntaxOnlyAction {
+  public:
+Hook(PragmaIncludes *Out) : Out(Out) {}
+bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
+  Out->record(CI);
+  return true;
+}
+
+PragmaIncludes *Out;
+  };
+  return std::make_unique(&PI);
+};
+  }
+
+  llvm::DenseMap>
+  offsetToProviders(TestAST &AST, SourceManager &SM,
+llvm::ArrayRef MacroRefs = {}) {
+llvm::SmallVector TopLevelDecls;
+for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
+  if (!SM.isWrittenInMainFile(SM.getExpansionLoc(D->getLocation(
+continue;
+  TopLevelDecls.emplace_back(D);
+}
+llvm::DenseMap> OffsetToProviders;
+walkUsed(TopLevelDecls, MacroRefs, &PI, SM,
+ [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
+   auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
+   if (FID != SM.getMainFileID())
+ ADD_FAILURE() << "Reference outside of the main file!";
+   OffsetToProviders.try_emplace(Offset, Providers.vec());
+ });
+return OffsetToProviders;
+  }
+};
+
+TEST_F(WalkUsedTest, Basic) {
   llvm::Annotations Code(R"cpp(
   #include "header.h"
   #include "private.h"
@@ -45,7 +85,7 @@
 std::$vector^vector $vconstructor^v;
   }
   )cpp");
-  TestInputs Inputs(Code.code());
+  Inputs.Code = Code.code();
   Inputs.ExtraFiles["header.h"] = guard(R"cpp(
   void foo();
   namespace std { class vector {}; }
@@ -55,85 +95,75 @@
 class Private {};
   )cpp");
 
-  PragmaIncludes PI;
-  Inputs.MakeAction = [&PI] {
-struct Hook : public SyntaxOnlyAction {
-public:
-  Hook(PragmaIncludes *Out) : Out(Out) {}
-  bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
-Out->record(CI);
-return true;
-  }
-
-  PragmaIncludes *Out;
-};
-return std::make_unique(&PI);
-  };
   TestAST AST(Inputs);
-
-  llvm::SmallVector TopLevelDecls;
-  for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
-TopLevelDecls.emplace_back(D);
-  }
-
   auto &SM = AST.sourceManager();
-  llvm::DenseMap> OffsetToProviders;
-  walkUsed(TopLevelDecls, /*MacroRefs=*/{}, &PI, SM,
-   [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
- auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
- EXPECT_EQ(FID, SM.getMainFileID());
- OffsetToProviders.try_emplace(Offset, Providers.vec());
-   });
-  auto &FM = AST.fileManager();
-  auto HeaderFile = Header(FM.getFile("header.h").get());
+  auto HeaderFile = Header(AST.fileManager().getFile("header.h").get());
+  auto PrivateFile = Header(AST.fileManager().getFile("private.h").get());
+  auto PublicFile = Header("\"path/public.h\"");
   auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
   auto VectorSTL = Header(tooling::stdlib::Header::named("").value());
   EXPECT_THAT(
-  OffsetToProviders,
+  offsetToProviders(AST, SM),
   UnorderedElementsAre(
   Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
   Pair(Code.point("private"),
-   UnorderedElementsAre(Header("\"path/public.h\"")

[clang-tools-extra] 29a8eec - [include-cleaner] Make use of locateSymbol in WalkUsed and HTMLReport

2022-12-06 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-12-06T15:03:11+01:00
New Revision: 29a8eec1f9eb6df8d52d8621415754989595fb6a

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

LOG: [include-cleaner] Make use of locateSymbol in WalkUsed and HTMLReport

Depens on D135953

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

Added: 
clang-tools-extra/include-cleaner/test/Inputs/foo2.h
clang-tools-extra/include-cleaner/test/multiple-providers.cpp

Modified: 
clang-tools-extra/include-cleaner/lib/Analysis.cpp
clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index c83b4d5a25be0..95cf8ab7550a5 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -8,8 +8,10 @@
 
 #include "clang-include-cleaner/Analysis.h"
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Format/Format.h"
 #include "clang/Lex/HeaderSearch.h"
@@ -21,6 +23,18 @@
 
 namespace clang::include_cleaner {
 
+namespace {
+// Gets all the providers for a symbol by tarversing each location.
+llvm::SmallVector headersForSymbol(const Symbol &S,
+   const SourceManager &SM,
+   const PragmaIncludes *PI) {
+  llvm::SmallVector Headers;
+  for (auto &Loc : locateSymbol(S))
+Headers.append(findHeaders(Loc, SM, PI));
+  return Headers;
+}
+} // namespace
+
 void walkUsed(llvm::ArrayRef ASTRoots,
   llvm::ArrayRef MacroRefs,
   const PragmaIncludes *PI, const SourceManager &SM,
@@ -30,19 +44,15 @@ void walkUsed(llvm::ArrayRef ASTRoots,
   for (auto *Root : ASTRoots) {
 auto &SM = Root->getASTContext().getSourceManager();
 walkAST(*Root, [&](SourceLocation Loc, NamedDecl &ND, RefType RT) {
+  // FIXME: Most of the work done here is repetative. It might be useful to
+  // have a cache/batching.
   SymbolReference SymRef{Loc, ND, RT};
-  if (auto SS = Recognizer(&ND)) {
-// FIXME: Also report forward decls from main-file, so that the caller
-// can decide to insert/ignore a header.
-return CB(SymRef, findHeaders(*SS, SM, PI));
-  }
-  // FIXME: Extract locations from redecls.
-  return CB(SymRef, findHeaders(ND.getLocation(), SM, PI));
+  return CB(SymRef, headersForSymbol(ND, SM, PI));
 });
   }
   for (const SymbolReference &MacroRef : MacroRefs) {
 assert(MacroRef.Target.kind() == Symbol::Macro);
-CB(MacroRef, findHeaders(MacroRef.Target.macro().Definition, SM, PI));
+return CB(MacroRef, headersForSymbol(MacroRef.Target, SM, PI));
   }
 }
 

diff  --git a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp 
b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
index 4d109d5f6d206..6d165b5d22ded 100644
--- a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -154,7 +154,7 @@ class Reporter {
   };
   std::vector Refs;
   llvm::DenseMap> IncludeRefs;
-  llvm::StringMap> Insertion;
+  llvm::StringMap> Insertion;
 
   llvm::StringRef includeType(const Include *I) {
 auto &List = IncludeRefs[I];
@@ -185,17 +185,8 @@ class Reporter {
 
   void fillTarget(Ref &R) {
 // Duplicates logic from walkUsed(), which doesn't expose SymbolLocations.
-// FIXME: use locateDecl and friends once implemented.
-// This doesn't use stdlib::Recognizer, but locateDecl will soon do that.
-switch (R.Sym.kind()) {
-case Symbol::Declaration:
-  R.Locations.push_back(R.Sym.declaration().getLocation());
-  break;
-case Symbol::Macro:
-  R.Locations.push_back(R.Sym.macro().Definition);
-  break;
-}
-
+for (auto &Loc : locateSymbol(R.Sym))
+  R.Locations.push_back(Loc);
 for (const auto &Loc : R.Locations)
   R.Headers.append(findHeaders(Loc, SM, PI));
 
@@ -220,8 +211,8 @@ class Reporter {
 
 public:
   Reporter(llvm::raw_ostream &OS, ASTContext &Ctx, HeaderSearch &HS,
-   const include_cleaner::Includes &Includes,
-   const PragmaIncludes *PI, FileID MainFile)
+   const include_cleaner::Includes &Includes, const PragmaIncludes *PI,
+   FileID MainFile)
   : OS(OS), Ctx(Ctx), SM(Ctx.getSourceManager()), HS(HS),
 Includes(Includes), PI(PI), MainFile(MainFile),
 MainFE(SM.getFileEntryForID(MainFile)) {}
@@ -321,7 +312,7 @@ class Reporter {
 printFilename(S

[PATCH] D138788: [SVE] Change some bfloat lane intrinsics to use i32 immediates

2022-12-06 Thread David Sherwood via Phabricator via cfe-commits
david-arm updated this revision to Diff 480451.
david-arm added a comment.

I did try to avoid having to create an intrinsic with a different name, but I 
was thwarted at every turn! It is with great regret that I report these two 
problems:

1. When you write an IR test file containing a declaration of the same 
intrinsic with a different type and try to use the upgrade mechanism the 
compiler crashes in `llvm::Intrinsic::getDeclaration`. This is presumably 
because we've declared an intrinsic in the module with a different signature to 
that in IntrinsicsAArch64.td and it seems deeply unhappy about it.
2. Secondly, in `llvm::UpgradeIntrinsicFunction` we would also hit the assert 
`assert(F != NewFn && "Intrinsic function upgraded to the same function");`

Let us bemoan the evil that befalls us @paulwalker-arm!


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

https://reviews.llvm.org/D138788

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfdot.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalt.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
  llvm/lib/Target/AArch64/SVEInstrFormats.td
  llvm/test/Bitcode/upgrade-aarch64-sve-intrinsics.ll
  llvm/test/CodeGen/AArch64/sve-intrinsics-bfloat.ll

Index: llvm/test/CodeGen/AArch64/sve-intrinsics-bfloat.ll
===
--- llvm/test/CodeGen/AArch64/sve-intrinsics-bfloat.ll
+++ llvm/test/CodeGen/AArch64/sve-intrinsics-bfloat.ll
@@ -19,7 +19,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfdot z0.s, z1.h, z2.h[0]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfdot.lane( %a,  %b,  %c, i64 0)
+  %out = call  @llvm.aarch64.sve.bfdot.lane.v2( %a,  %b,  %c, i32 0)
   ret  %out
 }
 
@@ -28,7 +28,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfdot z0.s, z1.h, z2.h[1]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfdot.lane( %a,  %b,  %c, i64 1)
+  %out = call  @llvm.aarch64.sve.bfdot.lane.v2( %a,  %b,  %c, i32 1)
   ret  %out
 }
 
@@ -37,7 +37,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfdot z0.s, z1.h, z2.h[2]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfdot.lane( %a,  %b,  %c, i64 2)
+  %out = call  @llvm.aarch64.sve.bfdot.lane.v2( %a,  %b,  %c, i32 2)
   ret  %out
 }
 
@@ -46,7 +46,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfdot z0.s, z1.h, z2.h[3]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfdot.lane( %a,  %b,  %c, i64 3)
+  %out = call  @llvm.aarch64.sve.bfdot.lane.v2( %a,  %b,  %c, i32 3)
   ret  %out
 }
 
@@ -68,7 +68,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[0]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 0)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.v2( %a,  %b,  %c, i32 0)
   ret  %out
 }
 
@@ -77,7 +77,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[1]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 1)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.v2( %a,  %b,  %c, i32 1)
   ret  %out
 }
 
@@ -86,7 +86,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[2]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 2)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.v2( %a,  %b,  %c, i32 2)
   ret  %out
 }
 
@@ -95,7 +95,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[3]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 3)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.v2( %a,  %b,  %c, i32 3)
   ret  %out
 }
 
@@ -104,7 +104,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[4]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 4)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.v2( %a,  %b,  %c, i32 4)
   ret  %out
 }
 
@@ -113,7 +113,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[5]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 5)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.v2( %a,  %b,  %c, i32 5)
   ret  %out
 }
 
@@ -122,7 +122,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[6]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 6)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.v2( %a,  %b,  %c, i32 6)
   ret  %out
 }
 
@@ -131,7 +131,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalb z0.s, z1.h, z2.h[7]
 ; CHECK-NEXT:ret
-  %out = call  @llvm.aarch64.sve.bfmlalb.lane( %a,  %b,  %c, i64 7)
+  %out = call  @llvm.aarch64.sve.bfmlalb.lane.v2( %a,  %b,  %c, i32 7)
   ret  %out
 }
 
@@ -153,7 +153,7 @@
 ; CHECK:   // %bb.0:
 ; CHECK-NEXT:bfmlalt z0.s, z1.h, z2.h[0]

[PATCH] D139428: Handle char{8,16,32} and wchar_t in ASTContext::getIntegerRank()

2022-12-06 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.
hans added a reviewer: aaron.ballman.
Herald added a project: All.
hans requested review of this revision.
Herald added a project: clang.

They were previously not handled, causing the llvm_unreachable with 
"getIntegerRank(): not a built-in integer" message to be hit.

The test case is derived from how we hit it in Chromium (crbug.com/1396142). I 
tried to come up with something more direct, but this is the best I could find.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139428

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/vector-bool.cpp


Index: clang/test/SemaCXX/vector-bool.cpp
===
--- clang/test/SemaCXX/vector-bool.cpp
+++ clang/test/SemaCXX/vector-bool.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -fexceptions 
-fcxx-exceptions %s -std=c++17
+// RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -fexceptions 
-fcxx-exceptions %s -std=c++20
 // Note that this test depends on the size of long-long to be different from
 // int, so it specifies a triple.
 
@@ -90,3 +90,15 @@
   foo(eight_bools.w);// expected-error@90 {{illegal vector component name 
''w''}}
   foo(eight_bools.wyx);  // expected-error@91 {{illegal vector component name 
''wyx''}}
 }
+
+// Don't crash due to missing integer ranks.
+char8_t v1 __attribute__((vector_size(16)));
+char16_t v2 __attribute__((vector_size(16)));
+char32_t v3 __attribute__((vector_size(16)));
+wchar_t v4 __attribute__((vector_size(16)));
+void triggerIntegerRankCheck() {
+  auto b1 = (v1 >= 0x12);
+  auto b2 = (v2 >= 0x12);
+  auto b3 = (v3 >= 0x12);
+  auto b4 = (v4 >= 0x12);
+}
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -7102,6 +7102,21 @@
   case BuiltinType::Int128:
   case BuiltinType::UInt128:
 return 7 + (getIntWidth(Int128Ty) << 3);
+
+  // "The ranks of char8_t, char16_t, char32_t, and wchar_t equal the ranks of
+  // their underlying types" [c++20 conv.rank]
+  case BuiltinType::Char8:
+return getIntegerRank(CharTy.getTypePtr());
+  case BuiltinType::Char16:
+return getIntegerRank(
+getFromTargetType(Target->getChar16Type()).getTypePtr());
+  case BuiltinType::Char32:
+return getIntegerRank(
+getFromTargetType(Target->getChar32Type()).getTypePtr());
+  case BuiltinType::WChar_S:
+  case BuiltinType::WChar_U:
+return getIntegerRank(
+getFromTargetType(Target->getWCharType()).getTypePtr());
   }
 }
 


Index: clang/test/SemaCXX/vector-bool.cpp
===
--- clang/test/SemaCXX/vector-bool.cpp
+++ clang/test/SemaCXX/vector-bool.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++17
+// RUN: %clang_cc1 -triple x86_64-linux-pc -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++20
 // Note that this test depends on the size of long-long to be different from
 // int, so it specifies a triple.
 
@@ -90,3 +90,15 @@
   foo(eight_bools.w);// expected-error@90 {{illegal vector component name ''w''}}
   foo(eight_bools.wyx);  // expected-error@91 {{illegal vector component name ''wyx''}}
 }
+
+// Don't crash due to missing integer ranks.
+char8_t v1 __attribute__((vector_size(16)));
+char16_t v2 __attribute__((vector_size(16)));
+char32_t v3 __attribute__((vector_size(16)));
+wchar_t v4 __attribute__((vector_size(16)));
+void triggerIntegerRankCheck() {
+  auto b1 = (v1 >= 0x12);
+  auto b2 = (v2 >= 0x12);
+  auto b3 = (v3 >= 0x12);
+  auto b4 = (v4 >= 0x12);
+}
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -7102,6 +7102,21 @@
   case BuiltinType::Int128:
   case BuiltinType::UInt128:
 return 7 + (getIntWidth(Int128Ty) << 3);
+
+  // "The ranks of char8_t, char16_t, char32_t, and wchar_t equal the ranks of
+  // their underlying types" [c++20 conv.rank]
+  case BuiltinType::Char8:
+return getIntegerRank(CharTy.getTypePtr());
+  case BuiltinType::Char16:
+return getIntegerRank(
+getFromTargetType(Target->getChar16Type()).getTypePtr());
+  case BuiltinType::Char32:
+return getIntegerRank(
+getFromTargetType(Target->getChar32Type()).getTypePtr());
+  case BuiltinType::WChar_S:
+  case BuiltinType::WChar_U:
+return getIntegerRank(
+getFromTargetType(Target->getWCharType()).getTypePtr());
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128457: [clangd] Add new IncludeType to IncludeHeaderWithReferences

2022-12-06 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 480465.
dgoldman marked 4 inline comments as done.
dgoldman added a comment.

Fixes + hopefully proper diffbase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128457

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/index/Merge.cpp
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/index/Symbol.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/index/YAMLSerialization.cpp
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/test/index-serialization/Inputs/sample.idx
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IndexTests.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang/include/clang/Tooling/Inclusions/HeaderAnalysis.h
  clang/lib/Tooling/Inclusions/HeaderAnalysis.cpp
  clang/unittests/Tooling/HeaderAnalysisTest.cpp

Index: clang/unittests/Tooling/HeaderAnalysisTest.cpp
===
--- clang/unittests/Tooling/HeaderAnalysisTest.cpp
+++ clang/unittests/Tooling/HeaderAnalysisTest.cpp
@@ -56,11 +56,32 @@
   EXPECT_TRUE(isSelfContainedHeader(FM.getFile("headerguard.h").get(), SM, HI));
   EXPECT_TRUE(isSelfContainedHeader(FM.getFile("pragmaonce.h").get(), SM, HI));
   EXPECT_TRUE(isSelfContainedHeader(FM.getFile("imported.h").get(), SM, HI));
+  EXPECT_TRUE(
+  isSelfContainedHeader(SM.getFileEntryForID(SM.getMainFileID()), SM, HI));
 
   EXPECT_FALSE(isSelfContainedHeader(FM.getFile("unguarded.h").get(), SM, HI));
   EXPECT_FALSE(isSelfContainedHeader(FM.getFile("bad.h").get(), SM, HI));
 }
 
+TEST(HeaderAnalysisTest, CodeContainsImports) {
+  EXPECT_TRUE(codeContainsImports(R"cpp(
+  #include "foo.h"
+#import "NSFoo.h"
+
+  int main() {
+foo();
+  }
+  )cpp"));
+
+  EXPECT_FALSE(codeContainsImports(R"cpp(
+  #include "foo.h"
+
+  int main() {
+foo();
+  }
+  )cpp"));
+}
+
 TEST(HeaderAnalysisTest, ParseIWYUPragma) {
   EXPECT_THAT(parseIWYUPragma("// IWYU pragma: keep"), ValueIs(Eq("keep")));
   EXPECT_THAT(parseIWYUPragma("// IWYU pragma:   keep  me\netc"),
Index: clang/lib/Tooling/Inclusions/HeaderAnalysis.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderAnalysis.cpp
+++ clang/lib/Tooling/Inclusions/HeaderAnalysis.cpp
@@ -37,8 +37,7 @@
 }
 
 // Heuristically headers that only want to be included via an umbrella.
-bool isDontIncludeMeHeader(llvm::MemoryBufferRef Buffer) {
-  StringRef Content = Buffer.getBuffer();
+bool isDontIncludeMeHeader(StringRef Content) {
   llvm::StringRef Line;
   // Only sniff up to 100 lines or 10KB.
   Content = Content.take_front(100 * 100);
@@ -50,19 +49,48 @@
   return false;
 }
 
+bool isImportLine(llvm::StringRef Line) {
+  Line = Line.ltrim();
+  if (!Line.consume_front("#"))
+return false;
+  Line = Line.ltrim();
+  return Line.startswith("import");
+}
+
+llvm::StringRef getFileContents(const FileEntry *FE, const SourceManager &SM) {
+  return const_cast(SM)
+  .getMemoryBufferForFileOrNone(FE)
+  .value_or(llvm::MemoryBufferRef())
+  .getBuffer();
+}
+
 } // namespace
 
 bool isSelfContainedHeader(const FileEntry *FE, const SourceManager &SM,
HeaderSearch &HeaderInfo) {
   assert(FE);
   if (!HeaderInfo.isFileMultipleIncludeGuarded(FE) &&
-  !HeaderInfo.hasFileBeenImported(FE))
+  !HeaderInfo.hasFileBeenImported(FE) &&
+  // Any header that contains #imports is supposed to be #import'd so no
+  // need to check for anything but the main-file.
+  (SM.getFileEntryForID(SM.getMainFileID()) != FE ||
+   !codeContainsImports(getFileContents(FE, SM
 return false;
   // This pattern indicates that a header can't be used without
   // particular preprocessor state, usually set up by another header.
-  return !isDontIncludeMeHeader(
-  const_cast(SM).getMemoryBufferForFileOrNone(FE).value_or(
-  llvm::MemoryBufferRef()));
+  return !isDontIncludeMeHeader(getFileContents(FE, SM));
+}
+
+bool codeContainsImports(llvm::StringRef Code) {
+  // Only sniff up to 100 lines or 10KB.
+  Code = Code.take_front(100 * 100);
+  llvm::StringRef Line;
+  for (unsigned I = 0; I < 100 && !Code.empty(); ++I) {
+std::tie(Line, Code) = Code.split('\n');
+if (isImportLine(Line))
+  return true;
+  }
+  return false;
 }
 
 llvm::Optional parseIWYUPragma(const char *Text) {
Index: clang/include/clang/Tooling/Inclusions/HeaderAnalysis.h

[PATCH] D139409: [include-cleaner] Handle dependent type members in AST

2022-12-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 480466.
VitaNuo added a comment.

Implement dependent type handling for template specialization types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139409

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -178,6 +178,11 @@
   "void foo() { X{}.^foo(); }");
 }
 
+TEST(WalkAST, CXXDependentScopeMemberExprs) {
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base t) { t.^method(); }");
+}
+
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct S { $implicit^S(); };", "S ^t;");
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
+#include 
 
 namespace clang::include_cleaner {
 namespace {
@@ -63,6 +64,17 @@
 return true;
   }
 
+  bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+QualType Type = E->getBaseType().getCanonicalType();
+if (isa(Type)) {
+  const TemplateSpecializationType *TST =
+  cast(Type);
+  TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl();
+  report(E->getMemberLoc(), TD);
+}
+return true;
+  }
+
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
 report(E->getLocation(), E->getConstructor(),
E->getParenOrBraceRange().isValid() ? RefType::Explicit


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -178,6 +178,11 @@
   "void foo() { X{}.^foo(); }");
 }
 
+TEST(WalkAST, CXXDependentScopeMemberExprs) {
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base t) { t.^method(); }");
+}
+
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct S { $implicit^S(); };", "S ^t;");
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
+#include 
 
 namespace clang::include_cleaner {
 namespace {
@@ -63,6 +64,17 @@
 return true;
   }
 
+  bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+QualType Type = E->getBaseType().getCanonicalType();
+if (isa(Type)) {
+  const TemplateSpecializationType *TST =
+  cast(Type);
+  TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl();
+  report(E->getMemberLoc(), TD);
+}
+return true;
+  }
+
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
 report(E->getLocation(), E->getConstructor(),
E->getParenOrBraceRange().isValid() ? RefType::Explicit
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139409: [include-cleaner] Handle dependent type members in AST

2022-12-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 480467.
VitaNuo added a comment.

Remove extra import.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139409

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -178,6 +178,11 @@
   "void foo() { X{}.^foo(); }");
 }
 
+TEST(WalkAST, CXXDependentScopeMemberExprs) {
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base t) { t.^method(); }");
+}
+
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct S { $implicit^S(); };", "S ^t;");
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -63,6 +63,17 @@
 return true;
   }
 
+  bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+QualType Type = E->getBaseType().getCanonicalType();
+if (isa(Type)) {
+  const TemplateSpecializationType *TST =
+  cast(Type);
+  TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl();
+  report(E->getMemberLoc(), TD);
+}
+return true;
+  }
+
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
 report(E->getLocation(), E->getConstructor(),
E->getParenOrBraceRange().isValid() ? RefType::Explicit


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -178,6 +178,11 @@
   "void foo() { X{}.^foo(); }");
 }
 
+TEST(WalkAST, CXXDependentScopeMemberExprs) {
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base t) { t.^method(); }");
+}
+
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct S { $implicit^S(); };", "S ^t;");
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -63,6 +63,17 @@
 return true;
   }
 
+  bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+QualType Type = E->getBaseType().getCanonicalType();
+if (isa(Type)) {
+  const TemplateSpecializationType *TST =
+  cast(Type);
+  TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl();
+  report(E->getMemberLoc(), TD);
+}
+return true;
+  }
+
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
 report(E->getLocation(), E->getConstructor(),
E->getParenOrBraceRange().isValid() ? RefType::Explicit
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138788: [SVE] Change some bfloat lane intrinsics to use i32 immediates

2022-12-06 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm accepted this revision.
paulwalker-arm added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/include/llvm/IR/IntrinsicsAArch64.td:1517
 
-class SVE_4Vec_BF16_Indexed
+class SVE_4Vec_BF16_Indexed_V2
 : DefaultAttrsIntrinsic<[llvm_nxv4f32_ty],

I suppose you don't actually need to change the name of this class.



Comment at: llvm/lib/IR/AutoUpgrade.cpp:3977
+LLVMContext &Ctx = F->getParent()->getContext();
+SmallVector Args(CI->args());
+Args[3] = ConstantInt::get(Type::getInt32Ty(Ctx),

This may as well be 4 given we know the exact number of arguments.


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

https://reviews.llvm.org/D138788

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


[PATCH] D139409: [include-cleaner] Handle dependent type members in AST

2022-12-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 480469.
VitaNuo added a comment.

Adjust implementation to handle pointer types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139409

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -178,6 +176,15 @@
   "void foo() { X{}.^foo(); }");
 }
 
+TEST(WalkAST, CXXDependentScopeMemberExprs) {
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base t) { t.^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base& t) { t.^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base* t) { t->^method(); }");
+}
+
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct S { $implicit^S(); };", "S ^t;");
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -63,6 +63,21 @@
 return true;
   }
 
+  bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+QualType Type = E->getBaseType().getCanonicalType();
+if (Type->isPointerType()) {
+  Type = Type->getPointeeType();
+}
+
+if (isa(Type)) {
+  const TemplateSpecializationType *TST =
+  cast(Type);
+  TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl();
+  report(E->getMemberLoc(), TD);
+}
+return true;
+  }
+
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
 report(E->getLocation(), E->getConstructor(),
E->getParenOrBraceRange().isValid() ? RefType::Explicit


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -178,6 +176,15 @@
   "void foo() { X{}.^foo(); }");
 }
 
+TEST(WalkAST, CXXDependentScopeMemberExprs) {
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base t) { t.^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base& t) { t.^method(); }");
+  testWalk("template struct $explicit^Base { void method(); };",
+   "template void k(Base* t) { t->^method(); }");
+}
+
 TEST(WalkAST, ConstructExprs) {
   testWalk("struct $implicit^S {};", "S ^t;");
   testWalk("struct S { $implicit^S(); };", "S ^t;");
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -63,6 +63,21 @@
 return true;
   }
 
+  bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
+QualType Type = E->getBaseType().getCanonicalType();
+if (Type->isPointerType()) {
+  Type = Type->getPoi

[PATCH] D128457: [clangd] Add new IncludeType to IncludeHeaderWithReferences

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

thanks, lgtm!




Comment at: clang/unittests/Tooling/HeaderAnalysisTest.cpp:69
+  #include "foo.h"
+#import "NSFoo.h"
+

indentation



Comment at: clang/unittests/Tooling/HeaderAnalysisTest.cpp:69
+  #include "foo.h"
+#import "NSFoo.h"
+

kadircet wrote:
> indentation
i think another important positive test case is, having it after some non PP 
code blocks (e.g. put it after main)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128457

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


[clang] 26e50c4 - [ARM/Darwin] Convert tests to check 'target='

2022-12-06 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-12-06T06:58:39-08:00
New Revision: 26e50c4c4df10de7bd8fcad520bf11ab94331eac

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

LOG: [ARM/Darwin] Convert tests to check 'target='

Part of the project to eliminate special handling for triples in lit
expressions.

Added: 


Modified: 
clang/test/CodeGen/2004-02-13-IllegalVararg.c
clang/test/Driver/clang-offload-bundler-asserts-on.c
clang/test/Driver/clang-offload-bundler.c
clang/test/Index/pch-from-libclang.c
clang/test/Interpreter/simple-exception.cpp
llvm/test/DebugInfo/Generic/empty.ll
llvm/test/DebugInfo/Generic/gmlt.test
llvm/test/ExecutionEngine/MCJIT/test-global-ctors.ll

Removed: 




diff  --git a/clang/test/CodeGen/2004-02-13-IllegalVararg.c 
b/clang/test/CodeGen/2004-02-13-IllegalVararg.c
index b3acda1f9e72f..9a2d286b77766 100644
--- a/clang/test/CodeGen/2004-02-13-IllegalVararg.c
+++ b/clang/test/CodeGen/2004-02-13-IllegalVararg.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1  %s -w -emit-llvm -o -
 
 // https://bugs.llvm.org/show_bug.cgi?id=46644#c6
-// XFAIL: arm64-apple
+// XFAIL: target=arm64-apple-{{.*}}
 
 float test(int X, ...) {
   __builtin_va_list ap;

diff  --git a/clang/test/Driver/clang-offload-bundler-asserts-on.c 
b/clang/test/Driver/clang-offload-bundler-asserts-on.c
index e92ecdf0107aa..aceda09f7bfa1 100644
--- a/clang/test/Driver/clang-offload-bundler-asserts-on.c
+++ b/clang/test/Driver/clang-offload-bundler-asserts-on.c
@@ -1,6 +1,6 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: asserts
-// UNSUPPORTED: darwin, target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
 
 // Generate the file we can bundle.
 // RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.o

diff  --git a/clang/test/Driver/clang-offload-bundler.c 
b/clang/test/Driver/clang-offload-bundler.c
index 9c4b7cd2cc996..b803db5f90ca8 100644
--- a/clang/test/Driver/clang-offload-bundler.c
+++ b/clang/test/Driver/clang-offload-bundler.c
@@ -1,6 +1,6 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: powerpc-registered-target
-// UNSUPPORTED: darwin, target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
 
 //
 // Generate all the types of files we can bundle.

diff  --git a/clang/test/Index/pch-from-libclang.c 
b/clang/test/Index/pch-from-libclang.c
index 5ad5ecb9157a0..52722b629982c 100644
--- a/clang/test/Index/pch-from-libclang.c
+++ b/clang/test/Index/pch-from-libclang.c
@@ -1,7 +1,7 @@
 // Check that clang can use a PCH created from libclang.
 
 // https://PR46644
-// XFAIL: arm64-apple
+// XFAIL: target=arm64-apple-{{.*}}
 
 // This test doesn't use -fdisable-module-hash and hence requires that
 // CompilerInvocation::getModuleHash() computes exactly the same hash

diff  --git a/clang/test/Interpreter/simple-exception.cpp 
b/clang/test/Interpreter/simple-exception.cpp
index 5af656396d4a3..57e14e47a30a1 100644
--- a/clang/test/Interpreter/simple-exception.cpp
+++ b/clang/test/Interpreter/simple-exception.cpp
@@ -1,6 +1,7 @@
 // clang-format off
 // UNSUPPORTED: system-aix
-// XFAIL: arm, arm64-apple, system-windows
+// XFAIL for arm and arm64, or running on Windows.
+// XFAIL: target=arm{{.*}}, system-windows
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
 

diff  --git a/llvm/test/DebugInfo/Generic/empty.ll 
b/llvm/test/DebugInfo/Generic/empty.ll
index 83b2e40b4328a..8de50ff23bb5b 100644
--- a/llvm/test/DebugInfo/Generic/empty.ll
+++ b/llvm/test/DebugInfo/Generic/empty.ll
@@ -3,7 +3,7 @@
 ; RUN: %llc_dwarf -split-dwarf-file=foo.dwo < %s -filetype=obj | 
llvm-dwarfdump -v - | FileCheck --check-prefix=FISSION %s
 
 ; darwin has a workaround for a linker bug so it always emits one line table 
entry
-; XFAIL: darwin
+; XFAIL: target={{.*}}-darwin{{.*}}
 
 ; Expect no line table entry since there are no functions and file references 
in this compile unit
 ; CHECK: .debug_line contents:

diff  --git a/llvm/test/DebugInfo/Generic/gmlt.test 
b/llvm/test/DebugInfo/Generic/gmlt.test
index 2b82cef8cb052..3cb3d9c14761c 100644
--- a/llvm/test/DebugInfo/Generic/gmlt.test
+++ b/llvm/test/DebugInfo/Generic/gmlt.test
@@ -1,4 +1,4 @@
 ; RUN: %llc_dwarf -O0 -filetype=obj < %S/../Inputs/gmlt.ll | llvm-dwarfdump -v 
- | FileCheck %S/../Inputs/gmlt.ll
 
 ; There's a darwin specific test in X86/gmlt, so it's okay to XFAIL this here.
-; XFAIL: darwin
+; XFAIL: target={{.*}}-darwin{{.*}}

diff  --git a/llvm/test/ExecutionEngine/MCJIT/test-global-ctors.ll 
b/llvm/test/ExecutionEngine/MCJIT/test-global-ctors.ll
index 1dbe9398065d0..2e95e7eda588a 100644
--- a/llvm/test/ExecutionEngine/MCJIT/test-global-ctors.ll
+++ b/llvm/test/ExecutionEngine/MCJIT/test-global-ctors.ll
@@ -1,6 +1,6 @@
 ;

[PATCH] D139429: [clang] Add test for CWG418

2022-12-06 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill created this revision.
Endill added a reviewer: clang-language-wg.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

P1787 : //CWG418 
 is resolved by trivial 
rephrasing along with that necessary for the new using-declaration 
interpretation.//
Wording: see changes to [dcl.fct.default]/9 and [over.match.best]/4.

Here's a caveat: [over.match.best]/4 includes an example 
 that is not 
properly diagnosed by Clang. While it is very relevant for the paragraph in 
question, I don't believe it is relevant for the issue itself, so I decided not 
to include it in the test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139429

Files:
  clang/test/CXX/drs/dr4xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -2547,7 +2547,7 @@
 https://wg21.link/cwg418";>418
 CD6
 Imperfect wording on error on multiple default arguments on a called 
function
-Unknown
+Yes
   
   
 https://wg21.link/cwg419";>419
Index: clang/test/CXX/drs/dr4xx.cpp
===
--- clang/test/CXX/drs/dr4xx.cpp
+++ clang/test/CXX/drs/dr4xx.cpp
@@ -315,6 +315,32 @@
   }
 }
 
+namespace dr418 { // dr418: yes
+namespace example1 {
+void f1(int, int = 0);
+void f1(int = 0, int);
+
+void g() { f1(); }
+} // namespace example1
+
+namespace example2 {
+namespace A {
+void f2(int); // #dr418-f3-decl
+}
+namespace B {
+using A::f2;
+}
+namespace A {
+void f2(int = 3);
+}
+void g2() {
+  using B::f2;
+  f2(); // expected-error {{no matching function}}
+  // expected-note@#dr418-f3-decl {{requires 1 argument}}
+}
+} // namespace example2
+} // namespace dr418
+
 namespace dr420 { // dr420: yes
   template struct ptr {
 T *operator->() const;


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -2547,7 +2547,7 @@
 https://wg21.link/cwg418";>418
 CD6
 Imperfect wording on error on multiple default arguments on a called function
-Unknown
+Yes
   
   
 https://wg21.link/cwg419";>419
Index: clang/test/CXX/drs/dr4xx.cpp
===
--- clang/test/CXX/drs/dr4xx.cpp
+++ clang/test/CXX/drs/dr4xx.cpp
@@ -315,6 +315,32 @@
   }
 }
 
+namespace dr418 { // dr418: yes
+namespace example1 {
+void f1(int, int = 0);
+void f1(int = 0, int);
+
+void g() { f1(); }
+} // namespace example1
+
+namespace example2 {
+namespace A {
+void f2(int); // #dr418-f3-decl
+}
+namespace B {
+using A::f2;
+}
+namespace A {
+void f2(int = 3);
+}
+void g2() {
+  using B::f2;
+  f2(); // expected-error {{no matching function}}
+  // expected-note@#dr418-f3-decl {{requires 1 argument}}
+}
+} // namespace example2
+} // namespace dr418
+
 namespace dr420 { // dr420: yes
   template struct ptr {
 T *operator->() const;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139125: [clang] Correctly handle by-reference capture with an initializer that is a pack expansion in lambdas.

2022-12-06 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 480475.
massberg added a comment.

Moved check if we have a pack expansion with reference type to 
Sema::BuildLambdaExpr.

I'm still not sure if this is the right place, or if `From.isCopyCapture()` 
should be `false` for pack expansions with refernece types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139125

Files:
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/lambda-pack-expansion.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2306,6 +2306,30 @@
   hasName("cc"), hasInitializer(integerLiteral(equals(1));
 }
 
+TEST_P(ASTMatchersTest, LambdaCaptureTest_BindsToCaptureOfReferenceType) {
+  if (!GetParam().isCXX20OrLater()) {
+return;
+  }
+  auto matcher = lambdaExpr(hasAnyCapture(
+  lambdaCapture(capturesVar(varDecl(hasType(referenceType()));
+  EXPECT_TRUE(matches("template  void f(T &...args) {"
+  "  [&...args = args] () mutable {"
+  "  }();"
+  "}"
+  "int main() {"
+  "  int a;"
+  "  f(a);"
+  "}", matcher));
+  EXPECT_FALSE(matches("template  void f(T &...args) {"
+   "  [...args = args] () mutable {"
+   "  }();"
+   "}"
+   "int main() {"
+   "  int a;"
+   "  f(a);"
+   "}", matcher));
+}
+
 TEST(ASTMatchersTestObjC, ObjCMessageCalees) {
   StatementMatcher MessagingFoo =
   objcMessageExpr(callee(objcMethodDecl(hasName("foo";
Index: clang/test/SemaCXX/lambda-pack-expansion.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/lambda-pack-expansion.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s
+
+namespace GH49266 {
+struct X {
+  X() = default;
+  X(X const&) = delete; // expected-note {{'X' has been explicitly marked 
deleted here}}
+};
+
+void take_by_copy(auto &...args) {
+  [...args = args] {}(); // expected-error {{call to deleted constructor}}
+}
+
+void take_by_ref(auto &...args) {
+  [&...args = args] {}(); // args is passed by reference and not copied.
+}
+
+void foo() {
+  X x;
+  take_by_copy(x); // expected-note {{in instantiation of function template 
specialization}}
+  take_by_ref(x);
+}
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -13147,9 +13147,10 @@
   }
   Expr *NewExprInit = NewExprInitResult.get();
 
+  bool isReferenceType = (C->getCaptureKind() == LCK_ByRef);
   QualType NewInitCaptureType =
   getSema().buildLambdaInitCaptureInitialization(
-  C->getLocation(), OldVD->getType()->isReferenceType(),
+  C->getLocation(), isReferenceType,
   EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
   cast(C->getCapturedVar())->getInitStyle() !=
   VarDecl::CInit,
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1900,6 +1900,12 @@
   ValueDecl *Var = From.getVariable();
   LambdaCaptureKind Kind =
   From.isCopyCapture() ? LCK_ByCopy : LCK_ByRef;
+  if (isa(Var->getType()) &&
+  cast(Var->getType())
+->getPattern()
+  ->isReferenceType()) {
+Kind = LCK_ByRef;
+  }
   return LambdaCapture(From.getLocation(), IsImplicit, Kind, Var,
From.getEllipsisLoc());
 }


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2306,6 +2306,30 @@
   hasName("cc"), hasInitializer(integerLiteral(equals(1));
 }
 
+TEST_P(ASTMatchersTest, LambdaCaptureTest_BindsToCaptureOfReferenceType) {
+  if (!GetParam().isCXX20OrLater()) {
+return;
+  }
+  auto matcher = lambdaExpr(hasAnyCapture(
+  lambdaCapture(capturesVar(varDecl(hasType(referenceType()));
+  EXPECT_TRUE(matches("template  void f(T &...args) {"
+  "  [&...args = args] () mutable {"
+  "  }();"
+  "}"
+  "int ma

[PATCH] D139398: [AMDGPU] Add bf16 storage support

2022-12-06 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh added inline comments.



Comment at: clang/lib/Basic/Targets/AMDGPU.h:119
+  bool hasBFloat16Type() const override { return isAMDGCN(getTriple()); }
+  const char *getBFloat16Mangling() const override { return "u6__bf16"; };
+

arsenm wrote:
> Don't understand this mangling. What is u6?
Not sure; for that one I just copy-pasted the implementation of other targets. 
All other targets use that mangling scheme



Comment at: clang/test/SemaCUDA/amdgpu-bf16.cu:43
+  *out = bf16;
+}
+

arsenm wrote:
> check casts to different int and float types? Is construction of bf16 vectors 
> allowed?
Added cast + vec sema test and vec assign codegen test too

No conversions are allowed apparently but I don't think it matters for the 
initial patch; if needed we can always add it later I think



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:4819-4831
+// When we don't have 16 bit instructions, bf16 is illegal and gets
+// softened to i16 for storage, with float being used for arithmetic.
+//
+// After softening, some i16 -> fp32 bf16_to_fp operations can be left 
over.
+// Lower those to (f32 (fp_extend (f16 (bitconvert x
+if (!Op->getValueType(0).isFloatingPoint() ||
+Op->getOperand(0).getValueType() != MVT::i16)

arsenm wrote:
> The generic legalizer should have handled this?
It looks like those operations are not implemented in the generic legalizer, 
e.g. I get 
``` 
Do not know how to promote this operator's operand!
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139398

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


[PATCH] D135247: [clang][analyzer] Add stream functions to StdLibraryFunctionsChecker.

2022-12-06 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:786
   /// constraints (and different return value constraints).
-  const NoErrnoConstraint ErrnoIrrelevant{};
+  const NoErrnoConstraint ErrnoUnchanged{};
+  const ResetErrnoConstraint ErrnoIrrelevant{};

Szelethus wrote:
> Hmm, do we need to specify this? Can't this be the default?
This is only used in cases where `errno` should not change (previous value 
remains, no invalidation happens). This works if another checker has `evalCall` 
for the function and does not change `errno` (otherwise a default evaluation 
occurs that invalidates the system region of `errno`).
The `StreamChecker` is an example with some functions added in the next patch. 
This class is really not used in this patch, could be moved to the next.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135247

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


[PATCH] D128677: [clang][Tooling] Add support for generating #import edits

2022-12-06 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 480482.
dgoldman marked 9 inline comments as done.
dgoldman added a comment.

Fixes for review + fix diffbase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128677

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/IncludeFixer.h
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Tooling/HeaderIncludesTest.cpp

Index: clang/unittests/Tooling/HeaderIncludesTest.cpp
===
--- clang/unittests/Tooling/HeaderIncludesTest.cpp
+++ clang/unittests/Tooling/HeaderIncludesTest.cpp
@@ -20,10 +20,12 @@
 
 class HeaderIncludesTest : public ::testing::Test {
 protected:
-  std::string insert(llvm::StringRef Code, llvm::StringRef Header) {
+  std::string insert(llvm::StringRef Code, llvm::StringRef Header,
+ IncludeDirective Directive = IncludeDirective::Include) {
 HeaderIncludes Includes(FileName, Code, Style);
 assert(Header.startswith("\"") || Header.startswith("<"));
-auto R = Includes.insert(Header.trim("\"<>"), Header.startswith("<"));
+auto R =
+Includes.insert(Header.trim("\"<>"), Header.startswith("<"), Directive);
 if (!R)
   return std::string(Code);
 auto Result = applyAllReplacements(Code, Replacements(*R));
@@ -60,6 +62,25 @@
   EXPECT_EQ(Expected, insert(Code, "\"a2.h\""));
 }
 
+TEST_F(HeaderIncludesTest, InsertImportWithSameInclude) {
+  std::string Code = "#include \"a.h\"\n";
+  std::string Expected = Code + "#import \"a.h\"\n";
+  EXPECT_EQ(Expected, insert(Code, "\"a.h\"", IncludeDirective::Import));
+}
+
+TEST_F(HeaderIncludesTest, DontInsertAlreadyImported) {
+  std::string Code = "#import \"a.h\"\n";
+  EXPECT_EQ(Code, insert(Code, "\"a.h\"", IncludeDirective::Import));
+}
+
+TEST_F(HeaderIncludesTest, DeleteImportAndSameInclude) {
+  std::string Code = "#include \"abc.h\"\n"
+ "#import \"abc.h\"\n"
+ "int x;\n";
+  std::string Expected = "int x;\n";
+  EXPECT_EQ(Expected, remove(Code, "\"abc.h\""));
+}
+
 TEST_F(HeaderIncludesTest, NoExistingIncludeWithDefine) {
   std::string Code = "#ifndef A_H\n"
  "#define A_H\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -296,7 +296,9 @@
   addExistingInclude(
   Include(Matches[2],
   tooling::Range(
-  Offset, std::min(Line.size() + 1, Code.size() - Offset))),
+  Offset, std::min(Line.size() + 1, Code.size() - Offset)),
+  Matches[1] == "import" ? tooling::IncludeDirective::Import
+ : tooling::IncludeDirective::Include),
   NextLineOffset);
 }
 Offset = NextLineOffset;
@@ -342,17 +344,20 @@
 }
 
 llvm::Optional
-HeaderIncludes::insert(llvm::StringRef IncludeName, bool IsAngled) const {
+HeaderIncludes::insert(llvm::StringRef IncludeName, bool IsAngled,
+   IncludeDirective Directive) const {
   assert(IncludeName == trimInclude(IncludeName));
   // If a  ("header") already exists in code, "header" () with
-  // different quotation will still be inserted.
+  // different quotation and/or directive will still be inserted.
   // FIXME: figure out if this is the best behavior.
   auto It = ExistingIncludes.find(IncludeName);
-  if (It != ExistingIncludes.end())
+  if (It != ExistingIncludes.end()) {
 for (const auto &Inc : It->second)
-  if ((IsAngled && StringRef(Inc.Name).startswith("<")) ||
-  (!IsAngled && StringRef(Inc.Name).startswith("\"")))
+  if (Inc.Directive == Directive &&
+  ((IsAngled && StringRef(Inc.Name).startswith("<")) ||
+   (!IsAngled && StringRef(Inc.Name).startswith("\""
 return llvm::None;
+  }
   std::string Quoted =
   std::string(llvm::formatv(IsAngled ? "<{0}>" : "\"{0}\"", IncludeName));
   StringRef QuotedName = Quoted;
@@ -371,8 +376,10 @@
 }
   }
   assert(InsertOffset <= Code.size());
+  llvm::StringRef DirectiveSpelling =
+  Directive == IncludeDirective::Include ? "include" : "import";
   std::string NewInclude =
-  std::string(llvm::formatv("#include {0}\n", QuotedName));
+  llvm::formatv("#{0} {1}\n", DirectiveSpelling, QuotedName);
   // When inserting headers at end of the code, also append '\n' to the code
   // if it does not end with '\n'.
   // FIXME: when inserting multiple #includes at the end of code, only on

[PATCH] D128677: [clang][Tooling] Add support for generating #import edits

2022-12-06 Thread David Goldman via Phabricator via cfe-commits
dgoldman added inline comments.



Comment at: clang/unittests/Tooling/HeaderIncludesTest.cpp:65
 
+TEST_F(HeaderIncludesTest, InsertImportWithSameInclude) {
+  std::string Code = "#include \"a.h\"\n";

kadircet wrote:
> can you also add a removal test?
> 
> i know we didn't change the implementation, but today there's nothing 
> checking the behaviour. so explicitly encoding the expectation here, 
> especially for the case where we have both #include and #import with same 
> spelling is useful. btw is it likely that `#include "foo.h"` and `#import 
> "foo.h"` can refer to different physical headers (e.g. due to framework 
> handling and whatnot)?
> 
> we're not changing the behaviour today, but if there's a difference, this is 
> likely a bug (that already exists), so we should leave a fixme (or address it 
> here if you got time, by introducing a IncludeDirective parameter into 
> remove. updating users is likely harder in this case, as everyone needs to 
> propagate/store the directive during their analysis).
No, I don't think #import and #include can refer to different headers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128677

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


[PATCH] D137275: [Driver][test] Fix test by creating empty archive instead of empty file

2022-12-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

…but even after that, things are still broken on macOS: 
http://45.33.8.238/macm1/50243/step_7.txt

  ar: no archive members specified
  usage:  ar -d [-TLsv] archive file ...
ar -m [-TLsv] archive file ...
ar -m [-abiTLsv] position archive file ...
ar -p [-TLsv] archive [file ...]
ar -q [-cTLsv] archive file ...
ar -r [-cuTLsv] archive file ...
ar -r [-abciuTLsv] position archive file ...
ar -t [-TLsv] archive [file ...]
ar -x [-ouTLsv] archive [file ...]


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137275

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


[PATCH] D139429: [clang] Add test for CWG418

2022-12-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

I'm not sure how I feel about this.
Clang does not, implement correctly that paragraph at all, so I think the best 
course here is to create an issue on the llvm github and mark the dr resolved 
as part of fixing the bug in clang.
The fact the previous wording was unclear may be related to clamg 
non-conformance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139429

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


  1   2   3   >