[PATCH] D136554: Implement CWG2631

2022-12-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D136554#4019135 , @rupprecht wrote:

> [...]
> The undefined symbols before are all provided by libc++, so those are fine. 
> After, the new undefined symbol for the lambda cannot be resolved. Depending 
> on how the linker is invoked, this may or may not be fine -- IIUC the linker 
> can sometimes recognize that it doesn't actually need the undefined symbol, 
> so it doesn't matter if it can't find it.
>
> Here is the build script I'm using, although you will likely need to tweak it 
> for your own environment:

The behavior is expected.

For `/tmp/main.o -Wl,--start-lib /tmp/b.o -Wl,--end-lib`, `b.o` is a lazy 
object file (with archive semantics) which is not extracted.
The result is as if the linker discards the input file, so its undefined 
references do not cause a linker error ([[ 
https://maskray.me/blog/2021-06-13-dependency-related-linker-options#z-defs | 
`-z defs` ]]: unresolved undefined non-weak symbol from a relocatable object 
file; an unextracted lazy file is not considered a relocatable object file ).

For `/tmp/main.o /tmp/b.o`, `b.o` is parsed as a relocatable object file. Its 
undefined reference causes by this patch (experiment locally with `git revert 
-n 339a7687e1c036a5f91c9d5391523b93e2e76cd3`) leads to a `-z defs` linker error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[PATCH] D140695: [M68k] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros

2022-12-29 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

In D140695#4019189 , @brad wrote:

> How come the Clang M68k backend defaults to 68000? GCC defaults to 68020 for 
> all targets.

The Clang M68k is a complete rewrite from scratch, independent of GCC, so it's 
not surprising you may see differences between Clang and GCC.

I'm open to raising the default baseline to 68020 though once the backend has 
matured enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140695

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


[clang] f3c9342 - Fix build of nvptx-arch with CLANG_LINK_CLANG_DYLIB

2022-12-29 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2022-12-29T09:48:05+01:00
New Revision: f3c9342a3d56e1782e3b6db081401af334648492

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

LOG: Fix build of nvptx-arch with CLANG_LINK_CLANG_DYLIB

The function clang_target_link_libraries must only be used with real
Clang libraries; with CLANG_LINK_CLANG_DYLIB, it will instead link in
clang-cpp. We must use the standard CMake target_link_libraries for
the CUDA library.

Added: 


Modified: 
clang/tools/nvptx-arch/CMakeLists.txt

Removed: 




diff  --git a/clang/tools/nvptx-arch/CMakeLists.txt 
b/clang/tools/nvptx-arch/CMakeLists.txt
index 94ef206a3bd75..94f544a01f0e6 100644
--- a/clang/tools/nvptx-arch/CMakeLists.txt
+++ b/clang/tools/nvptx-arch/CMakeLists.txt
@@ -25,4 +25,4 @@ add_clang_tool(nvptx-arch NVPTXArch.cpp)
 set_target_properties(nvptx-arch PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON)
 target_include_directories(nvptx-arch PRIVATE ${CUDA_INCLUDE_DIRS})
 
-clang_target_link_libraries(nvptx-arch PRIVATE ${cuda-library})
+target_link_libraries(nvptx-arch PRIVATE ${cuda-library})



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


[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-29 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: clang/tools/nvptx-arch/CMakeLists.txt:28
+
+clang_target_link_libraries(nvptx-arch PRIVATE ${cuda-library})

This broke my build with `CLANG_LINK_CLANG_DYLIB`; we must use the standard 
CMake `target_link_libraries` for the CUDA libraries. I fixed this in commit 
rGf3c9342a3d56e1782e3b6db081401af334648492.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140433

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


[PATCH] D140695: [M68k] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros

2022-12-29 Thread Sheng via Phabricator via cfe-commits
0x59616e accepted this revision.
0x59616e added a comment.

The CI seems OK. My first LGTM is given to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140695

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


[PATCH] D140662: [NFC][Clang][RISCV] Reduce boilerplate when determining prototype for segment loads

2022-12-29 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 485589.
eopXD added a comment.

Update code based on landing of D140678 .

The motivation of this NFC patch comes from the struggle while I was tracing 
through them. I think the scattered comments of boilerplates with only 
something slightly different makes the code hard to read, that is why I am 
gathering the comments together into a sole paragraph. The multi-level 
if-statement has duplicated actions and gets me confused from time-to-time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140662

Files:
  clang/include/clang/Basic/riscv_vector.td

Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -812,6 +812,47 @@
 }
 
 defvar NFList = [2, 3, 4, 5, 6, 7, 8];
+/*
+Segment load builtin has different variants.
+
+Segment unit-stride load builtin,
+(Address0, ..., Address{NF - 1}, mask, Ptr, VL)
+(Address0, ..., Address{NF - 1}, mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, VL)
+Segment unit-stride fault-only-first load builtin,
+(Address0, ..., Address{NF - 1}, mask, Ptr, NewVL, VL)
+(Address0, ..., Address{NF - 1}, mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, NewVL, VL)
+Segment strided load builtin,
+(Address0, ..., Address{NF - 1}, mask, Ptr, Stride, VL)
+(Address0, ..., Address{NF - 1}, mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, Stride, VL)
+Segment indexed load builtin,
+(Address0, ..., Address{NF - 1}, mask, Ptr, Idx, VL)
+(Address0, ..., Address{NF - 1}, mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, Idx, VL)
+
+The Maskedoff parameter(s) exist when at least one of the policy behaviors
+(vta or vma) implies undisturbed.
+
+Segment load intrinsics has different variants similar to their builtins.
+
+Segment unit-stride load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, VL)
+Segment unit-stride fault-only-first load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, VL)
+Segment strided load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Stride, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, Stride, VL)
+Segment indexed load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Index, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, Index, VL)
+
+The Vector(s) is poison when the policy behavior allows us to not care
+about any masked-off elements.
+*/
 
 class PVString {
   string S =
@@ -842,36 +883,30 @@
 {
   ResultType = ConvertType(E->getArg(0)->getType()->getPointeeType());
   IntrinsicTypes = {ResultType, Ops.back()->getType()};
-  SmallVector Operands;
-  if (IsMasked) {
-// TAMA builtin: (val0 address, ..., mask, ptr, vl)
-// builtin: (val0 address, ..., mask, maskedoff0, ..., ptr, vl)
-// intrinsic: (maskedoff0, ..., ptr, mask, vl)
-if (PolicyAttrs == TAIL_AGNOSTIC_MASK_AGNOSTIC) {
-  Operands.append(NF, llvm::PoisonValue::get(ResultType));
-  Operands.push_back(Ops[NF + 1]);
-  Operands.push_back(Ops[NF]);
-  Operands.push_back(Ops[NF + 2]);
-} else {
+  SmallVector Operands;
+
+  // Please refer to comment under 'defvar NFList' in this file
+  if ((IsMasked && PolicyAttrs == TAIL_AGNOSTIC_MASK_AGNOSTIC) ||
+  (!IsMasked && PolicyAttrs == TAIL_AGNOSTIC))
+Operands.append(NF, llvm::PoisonValue::get(ResultType));
+  else {
+if (IsMasked)
   Operands.append(Ops.begin() + NF + 1, Ops.begin() + 2 * NF + 1);
-  Operands.push_back(Ops[2 * NF + 1]);
-  Operands.push_back(Ops[NF]);
-  Operands.push_back(Ops[2 * NF + 2]);
-}
-Operands.push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
-assert(Operands.size() == NF + 4);
-  } else {
-// TA builtin: (val0 address, val1 address, ..., ptr, vl)
-// TU builtin: (val0 address, ..., passthru0, ..., ptr, vl)
-// intrinsic: (passthru0, passthru1, ..., ptr, vl)
-if (PolicyAttrs == TAIL_AGNOSTIC) {
-  Operands.append(NF, llvm::PoisonValue::get(ResultType));
-  Operands.push_back(Ops[NF]);
-  Operands.push_back(Ops[NF + 1]);
-} else {
-  Operands.append(Ops.begin() + NF, Ops.begin() + 2 * NF + 2);
-}
+else // Unmasked
+  Operands.append(Ops.begin() + NF, Ops.begin() + 2 * NF);
   }
+  unsigned PtrOperandIdx = IsMasked ?
+(PolicyAttrs == TAIL_AGNOSTIC_MASK_AGNOSTIC) ? NF + 1 : 2 * NF + 1 :
+(PolicyAttrs == TAIL_AGNOSTIC) ? NF : 2 * NF;
+  Value *PtrOperand = Ops[PtrOperandIdx];
+  Value *VLOperand = Ops[

[PATCH] D140753: [clang][dataflow] Check both operand's type in mergeDistinctValues

2022-12-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Previously we assume RHS is a BoolValue if LHS is a BoolValue. However,
if RHS represents a bitfield in a struct/class, this could lead to bad
casting.

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

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140753

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp


Index: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2970,6 +2970,23 @@
   cxxConstructorDecl(ofClass(hasName("Target";
 }
 
+// This is regression test, it shouldn't crash.
+TEST_P(UncheckedOptionalAccessTest, Bitfield) {
+  using namespace ast_matchers;
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+struct Dst {
+  unsigned int n : 1;
+};
+void target() {
+  $ns::$optional v;
+  Dst d;
+  if (v.has_value())
+d.n = v.value();
+}
+  )");
+}
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -94,14 +94,15 @@
   // Join distinct boolean values preserving information about the constraints
   // in the respective path conditions.
   if (auto *Expr1 = dyn_cast(&Val1)) {
-auto *Expr2 = cast(&Val2);
-auto &MergedVal = MergedEnv.makeAtomicBoolValue();
-MergedEnv.addToFlowCondition(MergedEnv.makeOr(
-MergedEnv.makeAnd(Env1.getFlowConditionToken(),
-  MergedEnv.makeIff(MergedVal, *Expr1)),
-MergedEnv.makeAnd(Env2.getFlowConditionToken(),
-  MergedEnv.makeIff(MergedVal, *Expr2;
-return &MergedVal;
+if (auto *Expr2 = dyn_cast(&Val2)) {
+  auto &MergedVal = MergedEnv.makeAtomicBoolValue();
+  MergedEnv.addToFlowCondition(MergedEnv.makeOr(
+  MergedEnv.makeAnd(Env1.getFlowConditionToken(),
+MergedEnv.makeIff(MergedVal, *Expr1)),
+  MergedEnv.makeAnd(Env2.getFlowConditionToken(),
+MergedEnv.makeIff(MergedVal, *Expr2;
+  return &MergedVal;
+}
   }
 
   // FIXME: Consider destroying `MergedValue` immediately if 
`ValueModel::merge`


Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2970,6 +2970,23 @@
   cxxConstructorDecl(ofClass(hasName("Target";
 }
 
+// This is regression test, it shouldn't crash.
+TEST_P(UncheckedOptionalAccessTest, Bitfield) {
+  using namespace ast_matchers;
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+struct Dst {
+  unsigned int n : 1;
+};
+void target() {
+  $ns::$optional v;
+  Dst d;
+  if (v.has_value())
+d.n = v.value();
+}
+  )");
+}
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -94,14 +94,15 @@
   // Join distinct boolean values preserving information about the constraints
   // in the respective path conditions.
   if (auto *Expr1 = dyn_cast(&Val1)) {
-auto *Expr2 = cast(&Val2);
-auto &MergedVal = MergedEnv.makeAtomicBoolValue();
-MergedEnv.addToFlowCondition(MergedEnv.makeOr(
-MergedEnv.makeAnd(Env1.getFlowConditionToken(),
-  MergedEnv.makeIff(MergedVal, *Expr1)),
-MergedEnv.makeAnd(Env2.getFlowConditionToken(),
-  MergedEnv.makeIff(MergedVal, *Expr2;
-return &MergedVal;
+if (auto *Expr2 = dyn_cast(&Val2)) {
+  auto &MergedVal = MergedEnv.makeAtomicBoolValue();
+  MergedEnv.addToFlowCondition(MergedEnv.makeOr(
+  MergedEnv.makeAnd(Env1.getFlowConditionToken(),
+MergedEnv.ma

[PATCH] D140685: [LoongArch] Add intrinsics for MOVFCSR2GR and MOVGR2FCSR instructions

2022-12-29 Thread Xiaodong Liu via Phabricator via cfe-commits
XiaodongLoong updated this revision to Diff 485593.
XiaodongLoong marked an inline comment as done.
XiaodongLoong added a comment.

rebase code and change code for @xen0n's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140685

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-la32-error.c
  clang/test/CodeGen/LoongArch/intrinsic-la32.c
  clang/test/CodeGen/LoongArch/intrinsic-la64-error.c
  clang/test/CodeGen/LoongArch/intrinsic-la64.c
  llvm/include/llvm/IR/IntrinsicsLoongArch.td
  llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.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-not-constant-error.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
@@ -1,10 +1,12 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s
-; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s
+; RUN: llc --mtriple=loongarch32 --mattr=+f < %s | FileCheck %s
+; RUN: llc --mtriple=loongarch64 --mattr=+f < %s | FileCheck %s
 
 declare void @llvm.loongarch.dbar(i32)
 declare void @llvm.loongarch.ibar(i32)
 declare void @llvm.loongarch.break(i32)
+declare void @llvm.loongarch.movgr2fcsr(i32, i32)
+declare i32 @llvm.loongarch.movfcsr2gr(i32)
 declare void @llvm.loongarch.syscall(i32)
 declare i32 @llvm.loongarch.csrrd.w(i32 immarg)
 declare i32 @llvm.loongarch.csrwr.w(i32, i32 immarg)
@@ -47,6 +49,26 @@
   ret void
 }
 
+define void @movgr2fcsr(i32 %a) nounwind {
+; CHECK-LABEL: movgr2fcsr:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:movgr2fcsr $fcsr1, $a0
+; CHECK-NEXT:ret
+entry:
+  call void @llvm.loongarch.movgr2fcsr(i32 1, i32 %a)
+  ret void
+}
+
+define i32 @movfcsr2gr() nounwind {
+; CHECK-LABEL: movfcsr2gr:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:movfcsr2gr $a0, $fcsr1
+; CHECK-NEXT:ret
+entry:
+  %res = call i32 @llvm.loongarch.movfcsr2gr(i32 1)
+  ret i32 %res
+}
+
 define void @syscall() nounwind {
 ; CHECK-LABEL: syscall:
 ; CHECK:   # %bb.0: # %entry
Index: llvm/test/CodeGen/LoongArch/intrinsic-not-constant-error.ll
===
--- llvm/test/CodeGen/LoongArch/intrinsic-not-constant-error.ll
+++ llvm/test/CodeGen/LoongArch/intrinsic-not-constant-error.ll
@@ -4,6 +4,8 @@
 declare void @llvm.loongarch.dbar(i32)
 declare void @llvm.loongarch.ibar(i32)
 declare void @llvm.loongarch.break(i32)
+declare void @llvm.loongarch.movgr2fcsr(i32, i32)
+declare i32 @llvm.loongarch.movfcsr2gr(i32)
 declare void @llvm.loongarch.syscall(i32)
 
 define void @dbar_not_constant(i32 %x) nounwind {
@@ -27,6 +29,20 @@
   ret void
 }
 
+define void @movgr2fcsr(i32 %a) nounwind {
+; CHECK: immarg operand has non-immediate parameter
+entry:
+  call void @llvm.loongarch.movgr2fcsr(i32 %a, i32 %a)
+  ret void
+}
+
+define i32 @movfcsr2gr(i32 %a) nounwind {
+; CHECK: immarg operand has non-immediate parameter
+entry:
+  %res = call i32 @llvm.loongarch.movfcsr2gr(i32 %a)
+  ret i32 %res
+}
+
 define void @syscall(i32 %x) nounwind {
 ; CHECK: immarg operand has non-immediate parameter
 entry:
Index: llvm/test/CodeGen/LoongArch/intrinsic-error.ll
===
--- llvm/test/CodeGen/LoongArch/intrinsic-error.ll
+++ llvm/test/CodeGen/LoongArch/intrinsic-error.ll
@@ -5,105 +5,151 @@
 declare void @llvm.loongarch.dbar(i32)
 declare void @llvm.loongarch.ibar(i32)
 declare void @llvm.loongarch.break(i32)
+declare void @llvm.loongarch.movgr2fcsr(i32, i32)
+declare i32 @llvm.loongarch.movfcsr2gr(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 @dbar_imm_out_of_hi_range() nounwind {
+define void @dbar_imm_out_of_hi_range() #0 {
 ; CHECK: argument to 'llvm.loongarch.dbar' out of range
 entry:
   call void @llvm.loongarch.dbar(i32 32769)
   ret void
 }
 
-define void @dbar_imm_out_of_lo_range() nounwind {
+define void @dbar_imm_out_of_lo_range() #0 {
 ; CHECK: argument to 'llvm.loongarch.dbar' out of range
 entry:
   call void @llvm.loongarch.dbar(i32 -1)
   ret void
 }
 
-define void @ibar_imm_out_of_hi_range() nounwind {
+define void @ibar_imm_out_of_hi_range() #0 {
 ; CHECK: argument to 'llvm.loongarch.ibar' out of range
 entry:
 

[PATCH] D140685: [LoongArch] Add intrinsics for MOVFCSR2GR and MOVGR2FCSR instructions

2022-12-29 Thread Xiaodong Liu via Phabricator via cfe-commits
XiaodongLoong added a comment.

@xen0n Thanks for your suggestion.




Comment at: llvm/lib/Target/LoongArch/LoongArchInstrInfo.td:53
+SDTCisVT<1, GRLenVT>]>;
+def SDT_LoongArchFCSR2GR : SDTypeProfile<1, 1, [SDTCisVT<0, GRLenVT>,
+SDTCisVT<1, i32>]>;

xen0n wrote:
> Be consistent with the surrounding code and spell out the instruction 
> mnemonic fully? Like `SDT_LoongArchMovfcsr2gr`?
Thanks, I changed that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140685

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


[clang] 2784b24 - [M68k] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros

2022-12-29 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2022-12-29T05:07:35-05:00
New Revision: 2784b243e38f7d526a40838a854554b53ebeb41e

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

LOG: [M68k] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros

Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros

Fixes #58974

Reviewed By: myhsu, glaubitz, 0x59616e

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

Added: 


Modified: 
clang/lib/Basic/Targets/M68k.cpp
clang/test/Preprocessor/predefined-arch-macros.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/M68k.cpp 
b/clang/lib/Basic/Targets/M68k.cpp
index 48627a8ceff9a..e3215b24a3a5a 100644
--- a/clang/lib/Basic/Targets/M68k.cpp
+++ b/clang/lib/Basic/Targets/M68k.cpp
@@ -113,6 +113,12 @@ void M68kTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   default:
 break;
   }
+
+  if (CPU >= CK_68020) {
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+  }
 }
 
 ArrayRef M68kTargetInfo::getTargetBuiltins() const {

diff  --git a/clang/test/Preprocessor/predefined-arch-macros.c 
b/clang/test/Preprocessor/predefined-arch-macros.c
index 3d9c14e13eba8..5abcdab7da037 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -4313,3 +4313,20 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_R600_FP64
 // CHECK_R600_FP64-DAG: #define __R600__ 1
 // CHECK_R600_FP64-DAG: #define __HAS_FMAF__ 1
+
+// Begin M68k tests 
+
+// RUN: %clang -mcpu=68000 -E -dM %s -o - 2>&1 \
+// RUN: -target m68k-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s 
-check-prefix=CHECK_M68K_68000_ATOMICS
+// RUN: %clang -mcpu=68010 -E -dM %s -o - 2>&1 \
+// RUN: -target m68k-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s 
-check-prefix=CHECK_M68K_68000_ATOMICS
+// RUN: %clang -mcpu=68020 -E -dM %s -o - 2>&1 \
+// RUN: -target m68k-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s 
-check-prefix=CHECK_M68K_68020_ATOMICS
+
+// CHECK_M68K_68000_ATOMICS-NOT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP
+// CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1



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


[PATCH] D140695: [M68k] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros

2022-12-29 Thread Brad Smith via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2784b243e38f: [M68k] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP 
macros (authored by brad).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140695

Files:
  clang/lib/Basic/Targets/M68k.cpp
  clang/test/Preprocessor/predefined-arch-macros.c


Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -4313,3 +4313,20 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_R600_FP64
 // CHECK_R600_FP64-DAG: #define __R600__ 1
 // CHECK_R600_FP64-DAG: #define __HAS_FMAF__ 1
+
+// Begin M68k tests 
+
+// RUN: %clang -mcpu=68000 -E -dM %s -o - 2>&1 \
+// RUN: -target m68k-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s 
-check-prefix=CHECK_M68K_68000_ATOMICS
+// RUN: %clang -mcpu=68010 -E -dM %s -o - 2>&1 \
+// RUN: -target m68k-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s 
-check-prefix=CHECK_M68K_68000_ATOMICS
+// RUN: %clang -mcpu=68020 -E -dM %s -o - 2>&1 \
+// RUN: -target m68k-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s 
-check-prefix=CHECK_M68K_68020_ATOMICS
+
+// CHECK_M68K_68000_ATOMICS-NOT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP
+// CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
Index: clang/lib/Basic/Targets/M68k.cpp
===
--- clang/lib/Basic/Targets/M68k.cpp
+++ clang/lib/Basic/Targets/M68k.cpp
@@ -113,6 +113,12 @@
   default:
 break;
   }
+
+  if (CPU >= CK_68020) {
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+  }
 }
 
 ArrayRef M68kTargetInfo::getTargetBuiltins() const {


Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -4313,3 +4313,20 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_R600_FP64
 // CHECK_R600_FP64-DAG: #define __R600__ 1
 // CHECK_R600_FP64-DAG: #define __HAS_FMAF__ 1
+
+// Begin M68k tests 
+
+// RUN: %clang -mcpu=68000 -E -dM %s -o - 2>&1 \
+// RUN: -target m68k-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_M68K_68000_ATOMICS
+// RUN: %clang -mcpu=68010 -E -dM %s -o - 2>&1 \
+// RUN: -target m68k-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_M68K_68000_ATOMICS
+// RUN: %clang -mcpu=68020 -E -dM %s -o - 2>&1 \
+// RUN: -target m68k-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_M68K_68020_ATOMICS
+
+// CHECK_M68K_68000_ATOMICS-NOT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP
+// CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
Index: clang/lib/Basic/Targets/M68k.cpp
===
--- clang/lib/Basic/Targets/M68k.cpp
+++ clang/lib/Basic/Targets/M68k.cpp
@@ -113,6 +113,12 @@
   default:
 break;
   }
+
+  if (CPU >= CK_68020) {
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+  }
 }
 
 ArrayRef M68kTargetInfo::getTargetBuiltins() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140753: [clang][dataflow] Check both operand's type in mergeDistinctValues

2022-12-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 requested changes to this revision.
gribozavr2 added a comment.
This revision now requires changes to proceed.

Thank you for your contribution!

While adding a conditional check fixes the crash, the problem's root cause must 
be deeper. Mismatched types indicate that one code path in dataflow analysis 
computes a bool type for a storage location, while a different code path 
computes an integer type. That's the actual root cause. Could you try to 
investigate the reasons for that, and try to fix it? The dataflow analysis 
should be computing values of the same type no matter through which path we 
arrived at a program point.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140753

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


[PATCH] D140662: [NFC][Clang][RISCV] Reduce boilerplate when determining prototype for segment loads

2022-12-29 Thread Zakk Chen via Phabricator via cfe-commits
khchen added a comment.

LGTM. Thanks for clean up code!




Comment at: clang/include/clang/Basic/riscv_vector.td:820
+(Address0, ..., Address{NF - 1}, mask, Ptr, VL)
+(Address0, ..., Address{NF - 1}, mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, VL)

nit: there is no unmasked builtin comment here.



Comment at: clang/include/clang/Basic/riscv_vector.td:1035
+  Value *StrideOperand = Ops[PtrOperandIdx + 1];
+  Value *VLOperand = Ops[PtrOperandIdx + 2];
+  Operands.push_back(PtrOperand);

In fact, VLOperand is always coming from `Ops.back()`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140662

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


[PATCH] D140756: Add clang_CXXMethod_isExplicit to libclang

2022-12-29 Thread Luca Di sera via Phabricator via cfe-commits
diseraluca created this revision.
diseraluca added a reviewer: aaron.ballman.
Herald added a subscriber: arphaman.
Herald added a project: All.
diseraluca requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The new method is a wrapper of `CXXConstructorDecl::isExplicit` and
`CXXConversionDecl::isExplicit`, allowing the user to recognize whether
the declaration pointed to by a cursor was marked with the explicit
specifier.

An export for the function, together with its documentation, was added
to "clang/include/clang-c/Index.h" with an implementation provided in
"clang/tools/libclang/CIndex.cpp".

The implementation is based on similar `clang_CXXMethod`
implementations, returning a falsy unsigned value when the cursor is not
a declaration, is not a declaration for a constructor or conversion
function or is not a relevant declaration that was marked with the
`explicit` specifier.

The new symbol was added to "clang/tools/libclang/libclang.map" to be
exported, under the LLVM16 tag.

"clang/tools/c-index-test/c-index-test.c" was modified to print a
specific tag, "(explicit)", for cursors that are recognized by
`clang_CXXMethod_isExplicit`.

Two new regression files, "explicit-constructor.cpp" and
"explicit-conversion-function.cpp", were added to "clang/test/Index", to
ensure that the behavior of the new function is correct for constructors
and conversion functions, respectively.

The "get-cursor.cpp", "index-file.cpp" and
"recursive-cxx-member-calls.cpp" regression files in "clang/test/Index"
were updated as they were affected by the new "(explicit)" tag.

A binding for the new function was added to libclang's python's
bindings, in "clang/bindings/python/clang/cindex.py", as the
"is_explicit_method" method under `Cursor`.

An accompanying test was added to
"clang/bindings/python/tests/cindex/test_cursor.py", mimicking the
regression tests for the C side.

The current release note for Clang, "clang/docs/ReleaseNotes.rst" was
modified to report the new addition under the "libclang" section.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140756

Files:
  clang/bindings/python/clang/cindex.py
  clang/bindings/python/tests/cindex/test_cursor.py
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/test/Index/explicit-constructor.cpp
  clang/test/Index/explicit-conversion-function.cpp
  clang/test/Index/get-cursor.cpp
  clang/test/Index/index-file.cpp
  clang/test/Index/recursive-cxx-member-calls.cpp
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/libclang.map

Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -416,6 +416,7 @@
 clang_disposeAPISet;
 clang_getSymbolGraphForCursor;
 clang_getSymbolGraphForUSR;
+clang_CXXMethod_isExplicit;
 };
 
 # Example of how to add a new symbol version entry.  If you do add a new symbol
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -8943,6 +8943,20 @@
   return (Method && Method->isMoveAssignmentOperator()) ? 1 : 0;
 }
 
+unsigned clang_CXXMethod_isExplicit(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+return 0;
+
+  const Decl *D = cxcursor::getCursorDecl(C);
+  const CXXConstructorDecl *Constructor =
+  D ? dyn_cast_or_null(D->getAsFunction()) : nullptr;
+  const CXXConversionDecl *ConversionFunction =
+  D ? dyn_cast_or_null(D->getAsFunction()) : nullptr;
+
+  return ((Constructor && Constructor->isExplicit()) ||
+  (ConversionFunction && ConversionFunction->isExplicit()));
+}
+
 unsigned clang_CXXRecord_isAbstract(CXCursor C) {
   if (!clang_isDeclaration(C.kind))
 return 0;
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -916,6 +916,8 @@
   printf(" (copy-assignment operator)");
 if (clang_CXXMethod_isMoveAssignmentOperator(Cursor))
   printf(" (move-assignment operator)");
+if (clang_CXXMethod_isExplicit(Cursor))
+  printf(" (explicit)");
 if (clang_CXXRecord_isAbstract(Cursor))
   printf(" (abstract)");
 if (clang_EnumDecl_isScoped(Cursor))
Index: clang/test/Index/recursive-cxx-member-calls.cpp
===
--- clang/test/Index/recursive-cxx-member-calls.cpp
+++ clang/test/Index/recursive-cxx-member-calls.cpp
@@ -824,7 +824,7 @@
 // CHECK-tokens: Keyword: "public" [86:1 - 86:7] CXXAccessSpecifier=:86:1 (Definition)
 // CHECK-tokens: Punctuation: ":" [86:7 - 86:8] CXXAccessSpecifier=:86:1 (Definition)
 // CHECK-tokens: Keyword: "explicit" [87:3 - 87:11] CXXConstructor=StringSwitch:

[PATCH] D140753: [clang][dataflow] Check both operand's type in mergeDistinctValues

2022-12-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D140753#4019322 , @gribozavr2 
wrote:

> Thank you for your contribution!
>
> While adding a conditional check fixes the crash, the problem's root cause 
> must be deeper. Mismatched types indicate that one code path in dataflow 
> analysis computes a bool type for a storage location, while a different code 
> path computes an integer type. That's the actual root cause. Could you try to 
> investigate the reasons for that, and try to fix it? The dataflow analysis 
> should be computing values of the same type no matter through which path we 
> arrived at a program point.

Thanks for your thoughts about the bug. Sure I'd love to try to investigate and 
will let you know what I finally got :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140753

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


[PATCH] D140757: [Hexagon][VE][WebAssembly] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros

2022-12-29 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added reviewers: kparzysz, kaz7, simoll, aheejin, luke.
brad added a project: clang.
Herald added subscribers: pmatos, asb, ecnelises, sunfish, jgravelle-google, 
sbc100, dschuff.
Herald added a project: All.
brad requested review of this revision.

Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140757

Files:
  clang/lib/Basic/Targets/Hexagon.cpp
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/test/Preprocessor/predefined-arch-macros.c


Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -4330,3 +4330,39 @@
 // CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
 // CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
 // CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+
+// Begin Hexagon tests 
+
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target hexagon-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_HEXAGON_ATOMICS
+
+// CHECK_HEXAGON_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_HEXAGON_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_HEXAGON_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+// CHECK_HEXAGON_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+
+// Begin VE tests 
+
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target ve-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_VE_ATOMICS
+
+// CHECK_VE_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_VE_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_VE_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+// CHECK_VE_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+
+// Begin WebAssembly tests 
+
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_WASM_ATOMICS
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_WASM_ATOMICS
+
+// CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+// CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
Index: clang/lib/Basic/Targets/WebAssembly.cpp
===
--- clang/lib/Basic/Targets/WebAssembly.cpp
+++ clang/lib/Basic/Targets/WebAssembly.cpp
@@ -96,6 +96,11 @@
 Builder.defineMacro("__wasm_reference_types__");
   if (HasExtendedConst)
 Builder.defineMacro("__wasm_extended_const__");
+
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
 }
 
 void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap &Features,
Index: clang/lib/Basic/Targets/VE.cpp
===
--- clang/lib/Basic/Targets/VE.cpp
+++ clang/lib/Basic/Targets/VE.cpp
@@ -38,6 +38,11 @@
   // FIXME: define __FAST_MATH__ 1 if -ffast-math is enabled
   // FIXME: define __OPTIMIZE__ n if -On is enabled
   // FIXME: define __VECTOR__ n 1 if automatic vectorization is enabled
+
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
 }
 
 ArrayRef VETargetInfo::getTargetBuiltins() const {
Index: clang/lib/Basic/Targets/Hexagon.cpp
===
--- clang/lib/Basic/Targets/Hexagon.cpp
+++ clang/lib/Basic/Targets/Hexagon.cpp
@@ -102,6 +102,11 @@
 
   std::string NumPhySlots = isTinyCore() ? "3" : "4";
   Builder.defineMacro("__HEXAGON_PHYSICAL_SLOTS__", NumPhySlots);
+
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
 }
 
 bool HexagonTargetInfo::initFeatureMap(


Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -4330,3 +4330,39 @@
 // CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
 //

[PATCH] D140543: [clang-format] Add an option to format integer literal separators

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

Fix a memory bug, which doesn't surface in Debug build.


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

https://reviews.llvm.org/D140543

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
  clang/lib/Format/IntegerLiteralSeparatorFixer.h
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/IntegerLiteralSeparatorTest.cpp

Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -0,0 +1,228 @@
+//===- unittest/Format/IntegerLiteralSeparatorTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "../Tooling/ReplacementTest.h"
+#include "FormatTestUtils.h"
+
+#define DEBUG_TYPE "integer-literal-separator-test"
+
+namespace clang {
+namespace format {
+namespace {
+
+// TODO:
+// Refactor the class declaration, which is copied from BracesInserterTest.cpp.
+class IntegerLiteralSeparatorTest : public ::testing::Test {
+protected:
+  std::string format(llvm::StringRef Code, const FormatStyle &Style,
+ const std::vector &Ranges) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+auto NonEmptyRanges = Ranges;
+if (Ranges.empty())
+  NonEmptyRanges = {1, tooling::Range(0, Code.size())};
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, NonEmptyRanges, "", &Status);
+EXPECT_EQ(true, Status.FormatComplete) << Code << "\n\n";
+ReplacementCount = Replaces.size();
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ const std::vector &Ranges = {}) {
+testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style, Ranges))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style, Ranges));
+if (Style.Language == FormatStyle::LK_Cpp && Ranges.empty()) {
+  // Objective-C++ is a superset of C++, so everything checked for C++
+  // needs to be checked for Objective-C++ as well.
+  FormatStyle ObjCStyle = Style;
+  ObjCStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle, Ranges));
+}
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ const std::vector &Ranges = {}) {
+_verifyFormat(File, Line, Code, Code, Style, Ranges);
+  }
+
+  int ReplacementCount;
+};
+
+#define verifyFormat(...) _verifyFormat(__FILE__, __LINE__, __VA_ARGS__)
+
+TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(Style.Language, FormatStyle::LK_Cpp);
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Binary, 0);
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Decimal, 0);
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Hex, 0);
+
+  const StringRef Binary("b = 0b10011'11'0110'1u;");
+  verifyFormat(Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = -1;
+  verifyFormat("b = 0b10001101u;", Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = 1;
+  verifyFormat("b = 0b1'0'0'1'1'1'1'0'1'1'0'1u;", Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = 4;
+  verifyFormat("b = 0b1001'1110'1101u;", Binary, Style);
+
+  const StringRef Decimal("d = 184467'440737'0'95505'92Ull;");
+  verifyFormat(Decimal, Style);
+  Style.IntegerLiteralSeparator.Decimal = -1;
+  verifyFormat("d = 18446744073709550592Ull;", Decimal, Style);
+  Style.IntegerLiteralSeparator.Decimal = 3;
+  verifyFormat("d = 18'446'744'073'709'550'592Ull;", Decimal, Style);
+
+  const StringRef Hex("h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;");
+  verifyFormat(Hex, Style);
+  Style.IntegerLiteralSeparator.Hex = -1;
+  verifyFormat("h = 0xDEADBEEFDEADBEEFuz;", Hex, Style);
+  Style.IntegerLiteralSeparator.Hex = 2;
+  verifyFormat("h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;", Hex, Style);
+
+  verifyFormat("o0 = 0;\n"
+   "o1 = 07;\n"
+   

[PATCH] D140543: [clang-format] Add an option to format integer literal separators

2022-12-29 Thread Owen Pan via Phabricator via cfe-commits
owenpan requested review of this revision.
owenpan added a comment.

In D140543#4016184 , @thakis wrote:

> In D140543#4016181 , @owenpan wrote:
>
>> In D140543#4016156 , @thakis wrote:
>>
>>> This seems to break tests everywhere, eg 
>>> http://45.33.8.238/linux/95289/step_7.txt
>>>
>>> Please take a look and revert for now if it takes a while to fix.
>>
>> I had run FormatTests on Windows and macOS without any problems and don't 
>> understand why the build bots failed. I will disable the `FixRanges` test as 
>> a workaround.
>
> FWIW it also fails on Windows and macOS on my bots: 
> http://45.33.8.238/macm1/51645/step_7.txt 
> http://45.33.8.238/win/72399/step_7.txt
>
> If the test is failing, why not revert the commit for now instead of 
> disabling the test? That's what we usually do.

I couldn't reproduce the failure until I ran the unit tests in the //Release// 
build. You are right though that I should have just reverted the commit.




Comment at: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp:81-82
+
+  llvm::SpecificBumpPtrAllocator Allocator;
+  auto Tok = new (Allocator.Allocate()) Token;
+  Lex->LexFromRawLexer(*Tok);

I should allocate memory for the `Token` object as shown but instead had `Token 
Tok;` before.


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

https://reviews.llvm.org/D140543

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


[PATCH] D140662: [NFC][Clang][RISCV] Reduce boilerplate when determining prototype for segment loads

2022-12-29 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 485604.
eopXD marked 2 inline comments as done.
eopXD edited the summary of this revision.
eopXD added a comment.

Update comment section for segment load.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140662

Files:
  clang/include/clang/Basic/riscv_vector.td

Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -812,6 +812,80 @@
 }
 
 defvar NFList = [2, 3, 4, 5, 6, 7, 8];
+/*
+A segment load builtin has different variants.
+
+Therefore a segment unit-stride load builtin can have 4 variants,
+1. When unmasked and the policies are all specified as agnostic:
+  (Address0, ..., Address{NF - 1}, Ptr, VL)
+2. When masked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Mask, Ptr, VL)
+3. When unmasked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, VL)
+4. When masked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, VL)
+
+Other variants of segment load builtin share the same structure, but they
+have their own extra parameter.
+
+The segment unit-stride fault-only-first load builtin has a 'NewVL'
+operand after the 'Ptr' operand.
+1. When unmasked and the policies are all specified as agnostic:
+  (Address0, ..., Address{NF - 1}, Ptr, NewVL, VL)
+2. When masked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Mask, Ptr, NewVL, VL)
+3. When unmasked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, NewVL, VL)
+4. When masked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, NewVL, VL)
+
+The segment strided load builtin has a 'Stride' operand after the 'Ptr'
+operand.
+1. When unmasked and the policies are all specified as agnostic:
+  (Address0, ..., Address{NF - 1}, Ptr, Stride, VL)
+2. When masked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Mask, Ptr, Stride, VL)
+3. When unmasked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, Stride, VL)
+4. When masked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, Stride, VL)
+
+The segment indexed load builtin has a 'Idx' operand after the 'Ptr' operand.
+1. When unmasked and the policies are all specified as agnostic:
+  (Address0, ..., Address{NF - 1}, Ptr, Idx, VL)
+2. When masked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Mask, Ptr, Idx, VL)
+3. When unmasked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, Idx, VL)
+4. When masked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, Idx, VL)
+
+Segment load intrinsics has different variants similar to their builtins.
+
+Segment unit-stride load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, VL)
+Segment unit-stride fault-only-first load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, VL)
+Segment strided load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Stride, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, Stride, VL)
+Segment indexed load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Index, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, Index, VL)
+
+The Vector(s) is poison when the policy behavior allows us to not care
+about any masked-off elements.
+*/
 
 class PVString {
   string S =
@@ -842,36 +916,30 @@
 {
   ResultType = ConvertType(E->getArg(0)->getType()->getPointeeType());
   IntrinsicTypes = {ResultType, Ops.back()->getType()};
-  SmallVector Operands;
-  if (IsMasked) {
-// TAMA builtin: (val0 address, ..., mask, ptr, vl)
-// builtin: (val0 address, ..., mask, maskedoff0, ..., ptr, vl)
-// intrinsic: (maskedoff0, ..., ptr, mask, vl)
-if (PolicyAttrs == TAIL_AGNOSTIC_MASK_AGNOSTIC) {
-  Operands.append(NF, llvm::PoisonValue::get(ResultType));
-  Operands.push_back(Ops[NF + 1]);
-  Operands.push_back(Ops[NF]);
-  Operands.push_back(Ops[NF + 2]);
-} else {
+  SmallVector Operands;
+
+  // Please refer to 

[PATCH] D136554: Implement CWG2631

2022-12-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 485605.
cor3ntin added a comment.

Another fun one.
I really apreciate your help on this.

The constructor of `Wrapper` causes
the constructor of `Option` to be defined, but not yet used
(as default parameters are not odr used) - 
so none of the default member initializers where marked ODR used.

When `Option::Option()` is called by `Func`, it is marked
as referenced and ODR used, but its default member initializers
are not.

When marking a constructor as referenced, we therefore must make sure
to reference its default member initializers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/UsedDeclVisitor.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/AST/ast-dump-records.cpp
  clang/test/CXX/class/class.local/p1-0x.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
  clang/test/CodeGenCXX/meminit-initializers-odr.cpp
  clang/test/PCH/default-argument-with-immediate-calls.cpp
  clang/test/SemaCXX/cxx11-default-member-initializers.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/source_location.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
@@ -15593,7 +15593,7 @@
 https://wg21.link/cwg2631";>2631
 DR
 Immediate function evaluations in default arguments
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg2632";>2632
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
 
 #define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
@@ -8,15 +9,22 @@
 template 
 struct Printer;
 
+#ifdef USE_CONSTEVAL
+#define SOURCE_LOC_EVAL_KIND consteval
+#else
+#define SOURCE_LOC_EVAL_KIND constexpr
+#endif
+
 namespace std {
 class source_location {
   struct __impl;
 
 public:
-  static constexpr source_location current(const __impl *__p = __builtin_source_location()) noexcept {
-source_location __loc;
-__loc.__m_impl = __p;
-return __loc;
+  static SOURCE_LOC_EVAL_KIND source_location
+current(const __impl *__p = __builtin_source_location()) noexcept {
+  source_location __loc;
+  __loc.__m_impl = __p;
+  return __loc;
   }
   constexpr source_location() = default;
   constexpr source_location(source_location const &) = default;
@@ -593,3 +601,73 @@
   }
   static_assert(test());
 }
+
+namespace Lambda {
+#line 8000 "TestLambda.cpp"
+constexpr int nested_lambda(int l = []{
+  return SL::current().line();
+}()) {
+  return l;
+}
+static_assert(nested_lambda() == __LINE__ - 4);
+
+constexpr int lambda_param(int l = [](int l = SL::current().line()) {
+  return l;
+}()) {
+  return l;
+}
+static_assert(lambda_param() == __LINE__);
+
+
+}
+
+constexpr int compound_literal_fun(int a =
+  (int){ SL::current().line() }
+) { return a ;}
+static_assert(compound_literal_fun() == __LINE__);
+
+struct CompoundLiteral {
+  int a = (int){ SL::current().line() };
+};
+static_assert(CompoundLiteral{}.a == __LINE__);
+
+
+// FIXME
+// Init captures are subexpressions of the lambda expression
+// so according to the standard immediate invocations in init captures
+// should be evaluated at the call site.
+// However Clang does not yet implement this as it would introduce
+// a fair bit of complexity.
+// We intend to implement that functionality once we find real world
+// use cases that require it.
+constexpr int test_init_capture(int a =
+[b = SL::current().line()] { return b; }()) {
+  return a;
+}
+#ifdef USE_CONSTEVAL
+static_assert(test_init_capture() == __LINE__ - 4);
+#else
+static_assert(test_init_capture() == __LINE__ );
+#endif
+
+namespace check_immediate_invocations_in_templates {
+
+template 
+struct G {
+T line = __builtin_LINE();
+};
+template 
+struct S {
+int i = G{}.line;
+};
+static_assert(S{}.i != // intentional new li

[PATCH] D140662: [NFC][Clang][RISCV] Reduce boilerplate when determining prototype for segment loads

2022-12-29 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 485606.
eopXD added a comment.

Update comment section: remove mis-indented indents.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140662

Files:
  clang/include/clang/Basic/riscv_vector.td

Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -812,6 +812,80 @@
 }
 
 defvar NFList = [2, 3, 4, 5, 6, 7, 8];
+/*
+A segment load builtin has different variants.
+
+Therefore a segment unit-stride load builtin can have 4 variants,
+1. When unmasked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Ptr, VL)
+2. When masked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Mask, Ptr, VL)
+3. When unmasked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, VL)
+4. When masked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, VL)
+
+Other variants of segment load builtin share the same structure, but they
+have their own extra parameter.
+
+The segment unit-stride fault-only-first load builtin has a 'NewVL'
+operand after the 'Ptr' operand.
+1. When unmasked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Ptr, NewVL, VL)
+2. When masked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Mask, Ptr, NewVL, VL)
+3. When unmasked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, NewVL, VL)
+4. When masked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, NewVL, VL)
+
+The segment strided load builtin has a 'Stride' operand after the 'Ptr'
+operand.
+1. When unmasked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Ptr, Stride, VL)
+2. When masked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Mask, Ptr, Stride, VL)
+3. When unmasked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, Stride, VL)
+4. When masked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, Stride, VL)
+
+The segment indexed load builtin has a 'Idx' operand after the 'Ptr' operand.
+1. When unmasked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Ptr, Idx, VL)
+2. When masked and the policies are all specified as agnostic:
+(Address0, ..., Address{NF - 1}, Mask, Ptr, Idx, VL)
+3. When unmasked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, Idx, VL)
+4. When masked and one of the policies is specified as undisturbed:
+(Address0, ..., Address{NF - 1}, Mask, Maskedoff0, ..., Maskedoff{NF - 1},
+  Ptr, Idx, VL)
+
+Segment load intrinsics has different variants similar to their builtins.
+
+Segment unit-stride load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, VL)
+Segment unit-stride fault-only-first load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, VL)
+Segment strided load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Stride, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, Stride, VL)
+Segment indexed load intrinsic,
+  Masked: (Vector0, ..., Vector{NF - 1}, Ptr, Index, Mask, VL, Policy)
+  Unmasked: (Vector0, ..., Vector{NF - 1}, Ptr, Index, VL)
+
+The Vector(s) is poison when the policy behavior allows us to not care
+about any masked-off elements.
+*/
 
 class PVString {
   string S =
@@ -842,36 +916,30 @@
 {
   ResultType = ConvertType(E->getArg(0)->getType()->getPointeeType());
   IntrinsicTypes = {ResultType, Ops.back()->getType()};
-  SmallVector Operands;
-  if (IsMasked) {
-// TAMA builtin: (val0 address, ..., mask, ptr, vl)
-// builtin: (val0 address, ..., mask, maskedoff0, ..., ptr, vl)
-// intrinsic: (maskedoff0, ..., ptr, mask, vl)
-if (PolicyAttrs == TAIL_AGNOSTIC_MASK_AGNOSTIC) {
-  Operands.append(NF, llvm::PoisonValue::get(ResultType));
-  Operands.push_back(Ops[NF + 1]);
-  Operands.push_back(Ops[NF]);
-  Operands.push_back(Ops[NF + 2]);
-} else {
+  SmallVector Operands;
+
+  // Please refer to comment under 'defvar NFList' in this file
+  if ((IsMasked && PolicyAttrs 

[PATCH] D140757: [Hexagon][VE][WebAssembly] Define __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros

2022-12-29 Thread Brad Smith via Phabricator via cfe-commits
brad updated this revision to Diff 485607.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140757

Files:
  clang/lib/Basic/Targets/Hexagon.cpp
  clang/lib/Basic/Targets/VE.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/test/Preprocessor/init.c
  clang/test/Preprocessor/predefined-arch-macros.c

Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -4330,3 +4330,39 @@
 // CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
 // CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
 // CHECK_M68K_68020_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+
+// Begin Hexagon tests 
+
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target hexagon-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_HEXAGON_ATOMICS
+
+// CHECK_HEXAGON_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_HEXAGON_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_HEXAGON_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+// CHECK_HEXAGON_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+
+// Begin VE tests 
+
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target ve-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_VE_ATOMICS
+
+// CHECK_VE_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_VE_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_VE_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+// CHECK_VE_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+
+// Begin WebAssembly tests 
+
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_WASM_ATOMICS
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_WASM_ATOMICS
+
+// CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+// CHECK_WASM_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -1597,6 +1597,10 @@
 // WEBASSEMBLY-NEXT:#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
 // WEBASSEMBLY-NEXT:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
 // WEBASSEMBLY-NEXT:#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
+// WEBASSEMBLY-NEXT:#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 
+// WEBASSEMBLY-NEXT:#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 
+// WEBASSEMBLY-NEXT:#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 
+// WEBASSEMBLY-NEXT:#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
 // WEBASSEMBLY-NEXT:#define __GNUC_MINOR__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __GNUC_PATCHLEVEL__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __GNUC_STDC_INLINE__ 1
Index: clang/lib/Basic/Targets/WebAssembly.cpp
===
--- clang/lib/Basic/Targets/WebAssembly.cpp
+++ clang/lib/Basic/Targets/WebAssembly.cpp
@@ -96,6 +96,11 @@
 Builder.defineMacro("__wasm_reference_types__");
   if (HasExtendedConst)
 Builder.defineMacro("__wasm_extended_const__");
+
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
 }
 
 void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap &Features,
Index: clang/lib/Basic/Targets/VE.cpp
===
--- clang/lib/Basic/Targets/VE.cpp
+++ clang/lib/Basic/Targets/VE.cpp
@@ -38,6 +38,11 @@
   // FIXME: define __FAST_MATH__ 1 if -ffast-math is enabled
   // FIXME: define __OPTIMIZE__ n if -On is enabled
   // FIXME: define __VECTOR__ n 1 if automatic vectorization is enabled
+
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
 }
 
 ArrayRef VETargetInfo::getTargetBuiltins() const {
Index: clang/lib/Basic/Targets/Hexagon.cpp
===
--- clang/lib/Basic/Targets/Hexagon.cpp
+++ clang/lib/Basic/Targets/Hexagon.cpp
@@ -102,6 +102,11 @@
 
   std::string NumPhySlots = isTinyCore() ? "3" : "4";
   Builder.defineMacro("__HEXAGON_PHYSICAL_SLOTS__", NumPhySlots);
+
+  B

[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2022-12-29 Thread Chris Cotter via Phabricator via cfe-commits
ccotter created this revision.
ccotter added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
ccotter requested review of this revision.
Herald added a subscriber: cfe-commits.

The modernize-loop-convert check will now match iterator based loops
that call the free functions 'begin'/'end', as well as matching the
free function 'size' on containers.

Test plan: Added unit test cases matching free function calls on
containers, and a single negative test case for length() which is not
supported.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140760

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -445,6 +445,34 @@
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & I : Dpp)
   // CHECK-FIXES-NEXT: printf("%d\n", I->X);
+
+  for (S::iterator It = begin(Ss), E = end(Ss); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : Ss)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::iterator It = begin(*Ps), E = end(*Ps); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : *Ps)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::iterator It = begin(*Ps); It != end(*Ps); ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : *Ps)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::const_iterator It = cbegin(Ss), E = cend(Ss); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto It : Ss)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
 }
 
 // Tests to verify the proper use of auto where the init variable type and the
@@ -653,6 +681,28 @@
   // CHECK-FIXES: for (int I : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = size(V); E != I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & I : V)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = size(V); E != I; ++I) {
+V[I] = 0;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int& I : V)
+  // CHECK-FIXES-NEXT: I = 0;
+
+  // Although 'length' might be a valid free function, only std::size() is standardized
+  for (int I = 0, E = length(V); E != I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
 }
 
 // Ensure that 'const auto &' is used with containers of non-trivial types.
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
@@ -39,6 +39,14 @@
   iterator end();
 };
 
+S::const_iterator begin(const S& s);
+S::const_iterator end(const S& s);
+S::const_iterator cbegin(const S& s);
+S::const_iterator cend(const S& s);
+S::iterator begin(S& s);
+S::iterator end(S& s);
+unsigned size(const S& s);
+
 struct T {
   typedef int value_type;
   struct iterator {
@@ -126,6 +134,11 @@
   void constFoo() const;
 };
 
+template
+unsigned size(const dependent&);
+template
+unsigned length(const dependent&);
+
 template
 class doublyDependent{
  public:
Index: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#include 
 #include 
 
 using namespace clang::ast_matchers;
@@ -129,6 +130,8 @@
 ///e = createIterator(); 

[PATCH] D140543: [clang-format] Add an option to format integer literal separators

2022-12-29 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp:81-82
+
+  llvm::SpecificBumpPtrAllocator Allocator;
+  auto Tok = new (Allocator.Allocate()) Token;
+  Lex->LexFromRawLexer(*Tok);

owenpan wrote:
> I should allocate memory for the `Token` object as shown but instead had 
> `Token Tok;` before.
But why? What is different?


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

https://reviews.llvm.org/D140543

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


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2022-12-29 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

It'll be good idea to mention change in Release Notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140760

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


[PATCH] D140696: [clang][dataflow] Treat unions as structs.

2022-12-29 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
merrymeerkat updated this revision to Diff 485626.
merrymeerkat added a comment.

Resolving review comment. Add createValue functionality for unions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140696

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1518,6 +1518,50 @@
   });
 }
 
+TEST(TransferTest, UnionThisMember) {
+  std::string Code = R"(
+union A {
+  int Foo;
+  int Bar;
+
+  void target() {
+(void)0; // [[p]]
+  }
+};
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+const auto *ThisLoc = dyn_cast(
+Env.getThisPointeeStorageLocation());
+ASSERT_THAT(ThisLoc, NotNull());
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const auto *FooLoc =
+cast(&ThisLoc->getChild(*FooDecl));
+ASSERT_TRUE(isa_and_nonnull(FooLoc));
+
+const Value *FooVal = Env.getValue(*FooLoc);
+ASSERT_TRUE(isa_and_nonnull(FooVal));
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *BarLoc =
+cast(&ThisLoc->getChild(*BarDecl));
+ASSERT_TRUE(isa_and_nonnull(BarLoc));
+
+const Value *BarVal = Env.getValue(*BarLoc);
+ASSERT_TRUE(isa_and_nonnull(BarVal));
+  });
+}
+
 TEST(TransferTest, StructThisInLambda) {
   std::string ThisCaptureCode = R"(
 struct A {
@@ -2537,12 +2581,34 @@
 ASSERT_THAT(BazDecl, NotNull());
 ASSERT_TRUE(BazDecl->getType()->isUnionType());
 
+auto BazFields = BazDecl->getType()->getAsRecordDecl()->fields();
+FieldDecl *FooDecl = nullptr;
+for (FieldDecl *Field : BazFields) {
+  if (Field->getNameAsString() == "Foo") {
+FooDecl = Field;
+  } else {
+FAIL() << "Unexpected field: " << Field->getNameAsString();
+  }
+}
+ASSERT_THAT(FooDecl, NotNull());
+
 const auto *BazLoc = dyn_cast_or_null(
 Env.getStorageLocation(*BazDecl, SkipPast::None));
 ASSERT_THAT(BazLoc, NotNull());
+ASSERT_THAT(Env.getValue(*BazLoc), NotNull());
+
+const auto *BazVal = cast(Env.getValue(*BazLoc));
+const auto *FooValFromBazVal = cast(BazVal->getChild(*FooDecl));
+const auto *FooValFromBazLoc = cast(Env.getValue(BazLoc->getChild(*FooDecl)));
+EXPECT_EQ(FooValFromBazLoc, FooValFromBazVal);
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+const auto *BarLoc = Env.getStorageLocation(*BarDecl, SkipPast::None);
+ASSERT_TRUE(isa_and_nonnull(BarLoc));
 
-// FIXME: Add support for union types.
-EXPECT_THAT(Env.getValue(*BazLoc), IsNull());
+EXPECT_EQ(Env.getValue(*BarLoc), FooValFromBazVal);
+EXPECT_EQ(Env.getValue(*BarLoc), FooValFromBazLoc);
   });
 }
 
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -480,10 +480,6 @@
 if (BaseLoc == nullptr)
   return;
 
-// FIXME: Add support for union types.
-if (BaseLoc->getType()->isUnionType())
-  return;
-
 auto &MemberLoc = BaseLoc->getChild(*Member);
 if (MemberLoc.getType()->isReferenceType()) {
   Env.setStorageLocation(*S, MemberLoc);
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -223,14 +223,12 @@
 if (Parent->isLambda())
   MethodDecl = dyn_cast(Parent->getDeclContext());
 
+// FIXME: Initialize the ThisPointeeLoc of lambdas too.
 if (MethodDecl && !MethodDecl->isStatic()) {
   QualType ThisPointeeType = MethodDecl->getThisObjectType();
-  // FIXME: Add support for union types.
-  if (!ThisPointeeType->isUnionType()) {
-ThisPointeeLoc = &createStorageLocation(ThisPointeeType);
-if (Value *ThisPointeeVal = createValue(ThisPointeeType))
-  setValue(*ThisPointeeLoc, *ThisPointeeVal);
-  }
+  ThisPoi

[PATCH] D140696: [clang][dataflow] Treat unions as structs.

2022-12-29 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
merrymeerkat added a comment.

> another thought: please verify that `createStorageLoction` and `createValue` 
> can correctly handle union types. Otherwise, you'll likely end up with other 
> (surprising) crashes in the system. E.g. 
> https://github.com/llvm/llvm-project/blob/781eabeb40b8e47e3a46b0b927784e63f0aad9ab/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L457
> assumes that the base of a member expression is an 
> `AggregateStorageLocation`, which means that in the case that `this` is such 
> a base and it's a union type, you need to be sure that 
> `createStorageLocation` has allocated an `AggregateStorageLocation`.
>
> Unfortunately, we don't have written down anywhere (aside from the code 
> itself) the invariants we require.

Good point!

Based on the assertions in TransferTest.UnionThisMember, we are creating 
storage locations for unions. So, the code you linked to should not crash (at 
least on unions as simple as that in the test).

We weren't creating values yet though. Turns out that was because `createValue` 
calls `createValueUnlessSelfReferential`, which creates values only for certain 
types, returning a nullptr otherwise: 
https://github.com/llvm/llvm-project/blob/8eb3698b940c4064b772f3ff5848d45f28523753/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp#L618-L699
 . I've just changed this function's if-statement on structs and classes to 
accept union types too, and now we are creating values for unions. So, values 
should hopefully not be a problem either.

There was already another unit test relating to unions 
(TransferTest.AssignToUnionMember), but it was only partly implemented. Now 
that we initialize locations and values for union types, I implemented the rest 
of the test. (thank you @gribozavr2 for the help debugging!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140696

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


[PATCH] D104931: [AArch64] Wire up ILP32 ABI support in Clang

2022-12-29 Thread Amanieu d'Antras via Phabricator via cfe-commits
Amanieu added a comment.

The situation around -mabi for AArch64 is a bit awkward: Clang uses it to 
select the ARM64 calling convention (`-mabi=aapcs` vs `-mabi=darwinpcs`) while 
GCC uses it to select between LP64 and ILP32. I'm not sure how we should be 
handling this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104931

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


[PATCH] D140696: [clang][dataflow] Treat unions as structs.

2022-12-29 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D140696#4019589 , @merrymeerkat 
wrote:

>> another thought: please verify that `createStorageLoction` and `createValue` 
>> can correctly handle union types. Otherwise, you'll likely end up with other 
>> (surprising) crashes in the system. E.g. 
>> https://github.com/llvm/llvm-project/blob/781eabeb40b8e47e3a46b0b927784e63f0aad9ab/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L457
>> assumes that the base of a member expression is an 
>> `AggregateStorageLocation`, which means that in the case that `this` is such 
>> a base and it's a union type, you need to be sure that 
>> `createStorageLocation` has allocated an `AggregateStorageLocation`.
>>
>> Unfortunately, we don't have written down anywhere (aside from the code 
>> itself) the invariants we require.
>
> Good point!
>
> Based on the assertions in TransferTest.UnionThisMember, we are creating 
> storage locations for unions. So, the code you linked to should not crash (at 
> least on unions as simple as that in the test).
>
> We weren't creating values yet though. Turns out that was because 
> `createValue` calls `createValueUnlessSelfReferential`, which creates values 
> only for certain types, returning a nullptr otherwise: 
> https://github.com/llvm/llvm-project/blob/8eb3698b940c4064b772f3ff5848d45f28523753/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp#L618-L699
>  . I've just changed this function's if-statement on structs and classes to 
> accept union types too, and now we are creating values for unions. So, values 
> should hopefully not be a problem either.
>
> There was already another unit test relating to unions 
> (TransferTest.AssignToUnionMember), but it was only partly implemented. Now 
> that we initialize locations and values for union types, I implemented the 
> rest of the test. (thank you @gribozavr2 for the help debugging!)

Sorry to go back-and-forth here, but I'm afraid this might be overly ambitious. 
With this change, unions are modeled exactly as structs (as far as I can tell), 
which is unsound.  I think we need to think carefully before doing this (it 
might be fine, but it's a non trivial step) and we'd need to test thoroughly.  
Moreover, this goes well beyond simply fixing the bug you set out to fix.

I realize that I'm the one who raised the concern with these functions, so I 
should explain: I had in mind just that you verify they work correctly with the 
fix (while retaining existing behavior of not modeling unions), rather than go 
the extra step of allowing unions altogether. I think that it would be enough 
to modify `createStorageLocation` as you have (so that unions are guaranteed to 
map from an `AggregateStorageLocation`), but then leave `createValue` as is. 
The result will be that all union-typed expressions will map to 
`AggregateStorageLocation`, so member expressions will work correctly, but the 
fields will always map to nullptr, so the modeling will be sound.

However, this all just begs the question of why go down this path to begin 
with. If we can't properly model union fields, does it make sense to model a 
union-typed `this` pointer?  Going back to your original argument, I think I 
missed a crucial point (and apologies that I didn't catch this sooner!):

> I thought more about this and I think I'd actually prefer to add support for 
> unions and skip the null check. The support could be useful for users. Now, 
> as for why I think we should skip the null check: in l. 226 of 
> Analysis/FlowSensitive/DataflowEnvironment.cpp, we check for methods that are 
> not static. These are the prerequisites for something having a "this" 
> pointer*. So, since we initialise the ThisPointeeLoc there, any intializer 
> we're processing in TypeErasedDataflowAnalysis::builtinTransferInitializer 
> should already have a not-null "this" pointer, making the check unnecessary. 
> What do you think?

You're making the case here for why we should avoid the null check, given that 
we support unions.  And you're logic is sound! But, it jumps over the hard 
question: when `this` is a union, do we want to initialise it all? Or, like 
other expressions we can't model, should we leave this `null` and then update 
the downstream code to avoid assuming that that `this` is non-null? (Or, a 
twist on that: should we avoid analysing the method at all when the object type 
is a union, since we're severely limited in what we can do. That would give us 
both benefits: we can still assume that the `ThisPointeeLoc` is never null, and 
avoid the bug.)  I think we need to dig into this question first, and then the 
answer about the fix follows. I would assert that to fix the bug you're 
encountering, you're fastest solution is to add the null check. Then, if you 
want to come back later and extend the framework to support unions, we can do 
that (and correspondingly remove the null check), but its a longer and more 
difficult process.

Again, sorry for the

[PATCH] D138868: AMDGPU/clang: Remove target features from address space test builtins

2022-12-29 Thread Joe Nash via Phabricator via cfe-commits
Joe_Nash added inline comments.



Comment at: clang/test/CodeGenOpenCL/builtins-amdgcn-flat-address-space.cl:8
+// be initialized to something useful. The proper way to diagnose invalid flat
+// usage is to forbid flat pointers on unsupported targets.
+

What part of the toolchain is responsible for forbiding flat pointers on 
unsupported targets?


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

https://reviews.llvm.org/D138868

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


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2022-12-29 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 485634.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140760

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -445,6 +445,34 @@
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & I : Dpp)
   // CHECK-FIXES-NEXT: printf("%d\n", I->X);
+
+  for (S::iterator It = begin(Ss), E = end(Ss); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : Ss)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::iterator It = begin(*Ps), E = end(*Ps); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : *Ps)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::iterator It = begin(*Ps); It != end(*Ps); ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : *Ps)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::const_iterator It = cbegin(Ss), E = cend(Ss); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto It : Ss)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
 }
 
 // Tests to verify the proper use of auto where the init variable type and the
@@ -653,6 +681,28 @@
   // CHECK-FIXES: for (int I : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = size(V); E != I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & I : V)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = size(V); E != I; ++I) {
+V[I] = 0;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int& I : V)
+  // CHECK-FIXES-NEXT: I = 0;
+
+  // Although 'length' might be a valid free function, only std::size() is standardized
+  for (int I = 0, E = length(V); E != I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
 }
 
 // Ensure that 'const auto &' is used with containers of non-trivial types.
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
@@ -39,6 +39,14 @@
   iterator end();
 };
 
+S::const_iterator begin(const S& s);
+S::const_iterator end(const S& s);
+S::const_iterator cbegin(const S& s);
+S::const_iterator cend(const S& s);
+S::iterator begin(S& s);
+S::iterator end(S& s);
+unsigned size(const S& s);
+
 struct T {
   typedef int value_type;
   struct iterator {
@@ -126,6 +134,11 @@
   void constFoo() const;
 };
 
+template
+unsigned size(const dependent&);
+template
+unsigned length(const dependent&);
+
 template
 class doublyDependent{
  public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -204,6 +204,10 @@
   The check now skips concept definitions since redundant expressions still make sense
   inside them.
 
+- Improved :doc:`modernize-loop-convert ` to
+  refactor container based for loops that initialize iterators with free function calls
+  to ``begin``, ``end``, or ``size``.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#include 
 #incl

[PATCH] D138868: AMDGPU/clang: Remove target features from address space test builtins

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



Comment at: clang/test/CodeGenOpenCL/builtins-amdgcn-flat-address-space.cl:8
+// be initialized to something useful. The proper way to diagnose invalid flat
+// usage is to forbid flat pointers on unsupported targets.
+

Joe_Nash wrote:
> What part of the toolchain is responsible for forbiding flat pointers on 
> unsupported targets?
The frontend should just error on languages with flat pointers. Really we 
should just implement software flat pointers, it wouldn’t be difficult and 
might only require minimal driver cooperation if any 


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

https://reviews.llvm.org/D138868

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


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2022-12-29 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

I just look into check documentation, new feature should be described with 
example there too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140760

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


[PATCH] D138868: AMDGPU/clang: Remove target features from address space test builtins

2022-12-29 Thread Joe Nash via Phabricator via cfe-commits
Joe_Nash accepted this revision.
Joe_Nash added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/CodeGenOpenCL/builtins-amdgcn-flat-address-space.cl:8
+// be initialized to something useful. The proper way to diagnose invalid flat
+// usage is to forbid flat pointers on unsupported targets.
+

arsenm wrote:
> Joe_Nash wrote:
> > What part of the toolchain is responsible for forbiding flat pointers on 
> > unsupported targets?
> The frontend should just error on languages with flat pointers. Really we 
> should just implement software flat pointers, it wouldn’t be difficult and 
> might only require minimal driver cooperation if any 
Ok, I just want to ask if that is in place or should be in place before this 
patch lands. So we don't accidentally convert a compile time error into a 
runtime error. Otherwise LGTM.


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

https://reviews.llvm.org/D138868

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


[PATCH] D140307: [clang-tidy] Match derived types in in modernize-loop-convert

2022-12-29 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 485637.
ccotter added a comment.

Add release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140307

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -575,6 +575,7 @@
 const dependent *Pconstv;
 
 transparent> Cv;
+dependent_derived VD;
 
 void f() {
   int Sum = 0;
@@ -653,6 +654,15 @@
   // CHECK-FIXES: for (int I : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = VD.size(); E != I; ++I) {
+printf("Fibonacci number is %d\n", VD[I]);
+Sum += VD[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int I : VD)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
 }
 
 // Ensure that 'const auto &' is used with containers of non-trivial types.
Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
@@ -126,6 +126,10 @@
   void constFoo() const;
 };
 
+template
+class dependent_derived : public dependent {
+};
+
 template
 class doublyDependent{
  public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -204,6 +204,10 @@
   The check now skips concept definitions since redundant expressions still 
make sense
   inside them.
 
+- Improved :doc:`misc-redundant-expression 
`
+  to check for container functions ``begin``/``end`` etc on base classes of 
the container
+  type, instead of only as direct members of the container type itself.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -251,17 +251,18 @@
   // functions called begin() and end() taking the container as an argument
   // are also allowed.
   TypeMatcher RecordWithBeginEnd = qualType(anyOf(
-  qualType(
-  isConstQualified(),
-  hasUnqualifiedDesugaredType(recordType(hasDeclaration(cxxRecordDecl(
-  hasMethod(cxxMethodDecl(hasName("begin"), isConst())),
-  hasMethod(cxxMethodDecl(hasName("end"),
-  isConst()   // hasDeclaration
- ))), // qualType
+  qualType(isConstQualified(),
+   hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+   cxxRecordDecl(isSameOrDerivedFrom(cxxRecordDecl(
+   hasMethod(cxxMethodDecl(hasName("begin"), isConst())),
+   hasMethod(cxxMethodDecl(hasName("end"),
+   isConst())) // 
hasDeclaration
+  ))), // qualType
   qualType(unless(isConstQualified()),
hasUnqualifiedDesugaredType(recordType(hasDeclaration(
-   cxxRecordDecl(hasMethod(hasName("begin")),
- hasMethod(hasName("end"))) // qualType
+   cxxRecordDecl(isSameOrDerivedFrom(cxxRecordDecl(
+   hasMethod(hasName("begin")),
+   hasMethod(hasName("end") // qualType
   ));
 
   StatementMatcher SizeCallMatcher = cxxMemberCallExpr(


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -575,6 +575,7 @@
 const dependent *Pconstv;
 
 transparent> Cv;
+dependent_derived VD;
 
 void f() {
   int Sum = 0;
@@ -653,6 +654,15 @@
   // CHECK-FIXES: for (int I : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FI

[clang] eb20499 - [clang] Use try_emplace instead of insert when getting new identifier

2022-12-29 Thread via cfe-commits

Author: serge-sans-paille
Date: 2022-12-29T21:40:21+01:00
New Revision: eb20499dab29e2180dd0ff106edb3233ab243323

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

LOG: [clang] Use try_emplace instead of insert when getting new identifier

This is both less verbose and slightly faster, according to:

https://llvm-compile-time-tracker.com/compare.php?from=d9ab3e82f30d646deff054230b0c742704a1cf26&to=73405077ad913f634797ffc7a7bbb110ac9cae99&stat=instructions:u

No functional change intended :-)

Added: 


Modified: 
clang/include/clang/Basic/IdentifierTable.h

Removed: 




diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index f98ea48f952fb..1886b1d7ba620 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -595,7 +595,7 @@ class IdentifierTable {
   /// Return the identifier token info for the specified named
   /// identifier.
   IdentifierInfo &get(StringRef Name) {
-auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
+auto &Entry = *HashTable.try_emplace(Name, nullptr).first;
 
 IdentifierInfo *&II = Entry.second;
 if (II) return *II;



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


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2022-12-29 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

In D140760#4019680 , @Eugene.Zelenko 
wrote:

> I just look into check documentation, new feature should be described with 
> example there too.

Would you mind clarifying where I should add documentation to? In the release 
notes, or within LoopConvertCheck.cpp itself?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140760

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


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2022-12-29 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In D140760#4019708 , @ccotter wrote:

> In D140760#4019680 , 
> @Eugene.Zelenko wrote:
>
>> I just look into check documentation, new feature should be described with 
>> example there too.
>
> Would you mind clarifying where I should add documentation to? In the release 
> notes, or within LoopConvertCheck.cpp itself?

Sorry, if I was not clear. I meant 
`clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140760

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


[PATCH] D138868: AMDGPU/clang: Remove target features from address space test builtins

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



Comment at: clang/test/CodeGenOpenCL/builtins-amdgcn-flat-address-space.cl:8
+// be initialized to something useful. The proper way to diagnose invalid flat
+// usage is to forbid flat pointers on unsupported targets.
+

Joe_Nash wrote:
> arsenm wrote:
> > Joe_Nash wrote:
> > > What part of the toolchain is responsible for forbiding flat pointers on 
> > > unsupported targets?
> > The frontend should just error on languages with flat pointers. Really we 
> > should just implement software flat pointers, it wouldn’t be difficult and 
> > might only require minimal driver cooperation if any 
> Ok, I just want to ask if that is in place or should be in place before this 
> patch lands. So we don't accidentally convert a compile time error into a 
> runtime error. Otherwise LGTM.
In practice you’ll be failing to select all over on regular code long before 
you see this predicate 


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

https://reviews.llvm.org/D138868

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


[PATCH] D140767: [clang-format] Require space before noexcept qualifier

2022-12-29 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.

This brings the noexcept qualifier more visually in line with the other
keyword qualifiers, such as "final" and "override".

Originally reported as https://github.com/llvm/llvm-project/issues/44542,
it was closed as "working by design" and reinforcing tests were added
as part of a218706cba90248be0c60bd6a8f10dbcf0270955 
. The 
exact spacing
depended on the `PointerAlignment` option, where the default value of
`Right` would leave no space.

This patch seeks to change this behaviour, regardless of the configured
`PointerAlignment` option (matching the previous behaviour of the `Left`
option).

Closes https://github.com/llvm/llvm-project/issues/59729


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140767

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
@@ -10566,10 +10566,10 @@
 
 TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
   verifyFormat("void A::b() && {}");
-  verifyFormat("void A::b() &&noexcept {}");
+  verifyFormat("void A::b() && noexcept {}");
   verifyFormat("Deleted &operator=(const Deleted &) & = default;");
   verifyFormat("Deleted &operator=(const Deleted &) && = delete;");
-  verifyFormat("Deleted &operator=(const Deleted &) &noexcept = default;");
+  verifyFormat("Deleted &operator=(const Deleted &) & noexcept = default;");
   verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;");
   verifyFormat("SomeType MemberFunction(const Deleted &) && = delete;");
   verifyFormat("Deleted &operator=(const Deleted &) &;");
@@ -10579,16 +10579,16 @@
   verifyFormat("SomeType MemberFunction(const Deleted &) && {}");
   verifyFormat("SomeType MemberFunction(const Deleted &) && final {}");
   verifyFormat("SomeType MemberFunction(const Deleted &) && override {}");
-  verifyFormat("SomeType MemberFunction(const Deleted &) &&noexcept {}");
+  verifyFormat("SomeType MemberFunction(const Deleted &) && noexcept {}");
   verifyFormat("void Fn(T const &) const &;");
   verifyFormat("void Fn(T const volatile &&) const volatile &&;");
-  verifyFormat("void Fn(T const volatile &&) const volatile &&noexcept;");
+  verifyFormat("void Fn(T const volatile &&) const volatile && noexcept;");
   verifyFormat("template \n"
"void F(T) && = delete;",
getGoogleStyle());
   verifyFormat("template  void operator=(T) &;");
   verifyFormat("template  void operator=(T) const &;");
-  verifyFormat("template  void operator=(T) &noexcept;");
+  verifyFormat("template  void operator=(T) & noexcept;");
   verifyFormat("template  void operator=(T) & = default;");
   verifyFormat("template  void operator=(T) &&;");
   verifyFormat("template  void operator=(T) && = delete;");
@@ -10678,31 +10678,31 @@
 
   verifyFormat("struct f {\n"
"  template \n"
-   "  int &foo(const std::string &str) &noexcept {}\n"
+   "  int &foo(const std::string &str) & noexcept {}\n"
"};",
BreakTemplate);
 
   verifyFormat("struct f {\n"
"  template \n"
-   "  int &foo(const std::string &str) &&noexcept {}\n"
+   "  int &foo(const std::string &str) && noexcept {}\n"
"};",
BreakTemplate);
 
   verifyFormat("struct f {\n"
"  template \n"
-   "  int &foo(const std::string &str) const &noexcept {}\n"
+   "  int &foo(const std::string &str) const & noexcept {}\n"
"};",
BreakTemplate);
 
   verifyFormat("struct f {\n"
"  template \n"
-   "  int &foo(const std::string &str) const &noexcept {}\n"
+   "  int &foo(const std::string &str) const & noexcept {}\n"
"};",
BreakTemplate);
 
   verifyFormat("struct f {\n"
"  template \n"
-   "  auto foo(const std::string &str) &&noexcept -> int & {}\n"
+   "  auto foo(const std::string &str) && noexcept -> int & {}\n"
"};",
BreakTemplate);
 
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3495,7 +3495,8 @@
 if (Right.is(TT_BlockComment))
   return true;
 // foo() -> const Bar * override/final
-if (Right.isOneOf(Keywords.kw_override, Keywords.kw_final) &&
+if (Right.isOneOf(Keywords.kw_override, Keyword

[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2022-12-29 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 485643.
ccotter added a comment.

Update docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140760

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -445,6 +445,34 @@
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & I : Dpp)
   // CHECK-FIXES-NEXT: printf("%d\n", I->X);
+
+  for (S::iterator It = begin(Ss), E = end(Ss); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : Ss)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::iterator It = begin(*Ps), E = end(*Ps); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : *Ps)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::iterator It = begin(*Ps); It != end(*Ps); ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : *Ps)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::const_iterator It = cbegin(Ss), E = cend(Ss); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto It : Ss)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
 }
 
 // Tests to verify the proper use of auto where the init variable type and the
@@ -653,6 +681,28 @@
   // CHECK-FIXES: for (int I : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = size(V); E != I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & I : V)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = size(V); E != I; ++I) {
+V[I] = 0;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int& I : V)
+  // CHECK-FIXES-NEXT: I = 0;
+
+  // Although 'length' might be a valid free function, only std::size() is standardized
+  for (int I = 0, E = length(V); E != I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
 }
 
 // Ensure that 'const auto &' is used with containers of non-trivial types.
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
@@ -39,6 +39,14 @@
   iterator end();
 };
 
+S::const_iterator begin(const S& s);
+S::const_iterator end(const S& s);
+S::const_iterator cbegin(const S& s);
+S::const_iterator cend(const S& s);
+S::iterator begin(S& s);
+S::iterator end(S& s);
+unsigned size(const S& s);
+
 struct T {
   typedef int value_type;
   struct iterator {
@@ -126,6 +134,11 @@
   void constFoo() const;
 };
 
+template
+unsigned size(const dependent&);
+template
+unsigned length(const dependent&);
+
 template
 class doublyDependent{
  public:
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
@@ -91,10 +91,18 @@
   for (vector::iterator it = v.begin(); it != v.end(); ++it)
 cout << *it;
 
+  // reasonable conversion
+  for (vector::iterator it = begin(v); it != end(v); ++it)
+cout << *it;
+
   // reasonable conversion
   for (int i = 0; i < v.size(); ++i)
 cout << v[i];
 
+  // reasonable conversion
+  for (int i = 0; i < size(v); ++i)
+cout << v[i];
+
 After applying the check with minimum confidence level set to `reasonable` (default):
 
 .. code-block:: c++
Index: cla

[PATCH] D140743: [DFSan] Fix overuse of REQUIRES: in tests.

2022-12-29 Thread Andrew via Phabricator via cfe-commits
browneee abandoned this revision.
browneee added a comment.

Abandon due to D140744  being submitted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140743

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


[PATCH] D140696: [clang][dataflow] Treat unions as structs.

2022-12-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

> With this change, unions are modeled exactly as structs (as far as I can 
> tell), which is unsound.

Modeling just the storage of the union (but not the value) is sound. The first 
revision of the patch was a targeted fix that allowed us to continue 
maintaining the invariant that `this` is always modeled with a non-null 
`StorageLocation`.

About modeling values of unions as structs (and members of unions as struct 
members), I can think of some unsoundness but nothing that affects what we are 
modeling now (e.g., pointers to two struct members should compare unequal, but 
pointers to two union members should compare equal). If the code writes to one 
union member, but reads from the other, code has UB. So it generally shouldn't 
be a problem, for the purpose of modeling, to model more storage in the union 
that a program free of union-related UB should never use. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140696

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


[clang] f4bcd7f - AMDGPU/clang: Add builtins for llvm.amdgcn.ballot

2022-12-29 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2022-12-29T17:58:55-05:00
New Revision: f4bcd7f598331457cfe74e459b489d4098369511

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

LOG: AMDGPU/clang: Add builtins for llvm.amdgcn.ballot

Use explicit _w32/_w64 suffixes for the wave size to be consistent
with the existing other wave dependent intrinsics. Also start
diagnosing trying to use both wave32 and wave64.

I would have preferred to avoid the +wavefrontsize64 spam on targets
where that's the only option, but avoiding this seems to be more work
than I expected.

Added: 
clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl
clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl
clang/test/SemaOpenCL/builtins-amdgcn-error-wave64.cl

Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGenOpenCL/amdgpu-features.cl
clang/test/CodeGenOpenCL/builtins-amdgcn-gfx10.cl
clang/test/OpenMP/amdgcn-attributes.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 5e64f830fb850..9e717099f 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -120,12 +120,6 @@ BUILTIN(__builtin_amdgcn_s_sleep, "vIi", "n")
 BUILTIN(__builtin_amdgcn_s_incperflevel, "vIi", "n")
 BUILTIN(__builtin_amdgcn_s_decperflevel, "vIi", "n")
 BUILTIN(__builtin_amdgcn_s_setprio, "vIs", "n")
-BUILTIN(__builtin_amdgcn_uicmp, "WUiUiUiIi", "nc")
-BUILTIN(__builtin_amdgcn_uicmpl, "WUiWUiWUiIi", "nc")
-BUILTIN(__builtin_amdgcn_sicmp, "WUiiiIi", "nc")
-BUILTIN(__builtin_amdgcn_sicmpl, "WUiWiWiIi", "nc")
-BUILTIN(__builtin_amdgcn_fcmp, "WUiddIi", "nc")
-BUILTIN(__builtin_amdgcn_fcmpf, "WUiffIi", "nc")
 BUILTIN(__builtin_amdgcn_ds_swizzle, "iiIi", "nc")
 BUILTIN(__builtin_amdgcn_ds_permute, "iii", "nc")
 BUILTIN(__builtin_amdgcn_ds_bpermute, "iii", "nc")
@@ -155,6 +149,21 @@ BUILTIN(__builtin_amdgcn_qsad_pk_u16_u8, "WUiWUiUiWUi", 
"nc")
 BUILTIN(__builtin_amdgcn_mqsad_pk_u16_u8, "WUiWUiUiWUi", "nc")
 BUILTIN(__builtin_amdgcn_mqsad_u32_u8, "V4UiWUiUiV4Ui", "nc")
 
+//===--===//
+// Ballot builtins.
+//===--===//
+
+TARGET_BUILTIN(__builtin_amdgcn_ballot_w32, "Uib", "nc", "wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_ballot_w64, "LUib", "nc", "wavefrontsize64")
+
+// Deprecated intrinsics in favor of __builtin_amdgn_ballot_{w32|w64}
+BUILTIN(__builtin_amdgcn_uicmp, "WUiUiUiIi", "nc")
+BUILTIN(__builtin_amdgcn_uicmpl, "WUiWUiWUiIi", "nc")
+BUILTIN(__builtin_amdgcn_sicmp, "WUiiiIi", "nc")
+BUILTIN(__builtin_amdgcn_sicmpl, "WUiWiWiIi", "nc")
+BUILTIN(__builtin_amdgcn_fcmp, "WUiddIi", "nc")
+BUILTIN(__builtin_amdgcn_fcmpf, "WUiffIi", "nc")
+
 
//===--===//
 // CI+ only builtins.
 
//===--===//

diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index cd9a7e8d93f2e..ecb786482c9a3 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -13,6 +13,7 @@
 #include "AMDGPU.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
@@ -178,6 +179,8 @@ ArrayRef AMDGPUTargetInfo::getGCCRegNames() 
const {
 bool AMDGPUTargetInfo::initFeatureMap(
 llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU,
 const std::vector &FeatureVec) const {
+  const bool IsNullCPU = CPU.empty();
+  bool IsWave32Capable = false;
 
   using namespace llvm::AMDGPU;
 
@@ -188,6 +191,7 @@ bool AMDGPUTargetInfo::initFeatureMap(
 case GK_GFX1102:
 case GK_GFX1101:
 case GK_GFX1100:
+  IsWave32Capable = true;
   Features["ci-insts"] = true;
   Features["dot1-insts"] = true;
   Features["dot5-insts"] = true;
@@ -211,6 +215,7 @@ bool AMDGPUTargetInfo::initFeatureMap(
 case GK_GFX1032:
 case GK_GFX1031:
 case GK_GFX1030:
+  IsWave32Capable = true;
   Features["ci-insts"] = true;
   Features["dot1-insts"] = true;
   Features["dot2-insts"] = true;
@@ -238,6 +243,7 @@ bool AMDGPUTargetInfo::initFeatureMap(
   [[fallthrough]];
 case GK_GFX1013:
 case GK_GFX1010:
+  IsWave32Capable = true;
   Features["dl-insts"] = true;
   Features["

[PATCH] D82087: AMDGPU/clang: Add builtins for llvm.amdgcn.ballot

2022-12-29 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

f4bcd7f598331457cfe74e459b489d4098369511


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

https://reviews.llvm.org/D82087

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


[PATCH] D140743: [DFSan] Fix overuse of REQUIRES: in tests.

2022-12-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:766
   Res |= SanitizerKind::SafeStack;
-  if (IsX86_64 || IsMIPS64 || IsAArch64)
+  if (IsX86_64)
 Res |= SanitizerKind::DataFlow;

This change is still useful and worth submitting :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140743

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


[libclc] 4ddba3a - libclc: Add parentheses to silence warning

2022-12-29 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2022-12-29T18:19:55-05:00
New Revision: 4ddba3a7061fef81faed2f0fbaba25f4b78f6014

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

LOG: libclc: Add parentheses to silence warning

Fixes #59209

Added: 


Modified: 
libclc/generic/lib/math/acosh.cl

Removed: 




diff  --git a/libclc/generic/lib/math/acosh.cl 
b/libclc/generic/lib/math/acosh.cl
index cc10dd48fadb5..59da511627744 100644
--- a/libclc/generic/lib/math/acosh.cl
+++ b/libclc/generic/lib/math/acosh.cl
@@ -117,7 +117,7 @@ _CLC_OVERLOAD _CLC_DEF double acosh(double x) {
 
 ret = ux >= 0x7FF0 ? x : ret;
 ret = x == 1.0 ? 0.0 : ret;
-ret = (ux & SIGNBIT_DP64) != 0UL | x < 1.0 ? as_double(QNANBITPATT_DP64) : 
ret;
+ret = ((ux & SIGNBIT_DP64) != 0UL | x < 1.0) ? as_double(QNANBITPATT_DP64) 
: ret;
 
 return ret;
 }



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


[clang] e630d9b - AMDGPU/clang: Remove target features from address space test builtins

2022-12-29 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2022-12-29T18:46:41-05:00
New Revision: e630d9b299822810bba8f3d0457004d1b4c39bef

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

LOG: AMDGPU/clang: Remove target features from address space test builtins

It turns out we can codegen these on targets without flat addressing,
although the runtime probably didn't put anything useful there. The
proper diagnostic would be to disallow flat pointer uses or languages
with them, not this one edge case. Allows removing one of the special
cases requiring subtarget support in the device libraries.

Added: 
clang/test/CodeGenOpenCL/builtins-amdgcn-flat-address-space.cl

Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/test/CodeGenOpenCL/builtins-amdgcn.cl
clang/test/SemaOpenCL/builtins-amdgcn-error-flat-address-space.cl
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.is.private.ll
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.is.shared.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 9e717099f..5c39bae0d5d46 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -164,14 +164,18 @@ BUILTIN(__builtin_amdgcn_sicmpl, "WUiWiWiIi", "nc")
 BUILTIN(__builtin_amdgcn_fcmp, "WUiddIi", "nc")
 BUILTIN(__builtin_amdgcn_fcmpf, "WUiffIi", "nc")
 
+//===--===//
+// Flat addressing builtins.
+//===--===//
+BUILTIN(__builtin_amdgcn_is_shared, "bvC*0", "nc")
+BUILTIN(__builtin_amdgcn_is_private, "bvC*0", "nc")
+
 
//===--===//
 // CI+ only builtins.
 
//===--===//
 TARGET_BUILTIN(__builtin_amdgcn_s_dcache_inv_vol, "v", "n", "ci-insts")
 TARGET_BUILTIN(__builtin_amdgcn_buffer_wbinvl1_vol, "v", "n", "ci-insts")
 TARGET_BUILTIN(__builtin_amdgcn_ds_gws_sema_release_all, "vUi", "n", 
"ci-insts")
-TARGET_BUILTIN(__builtin_amdgcn_is_shared, "bvC*0", "nc", "flat-address-space")
-TARGET_BUILTIN(__builtin_amdgcn_is_private, "bvC*0", "nc", 
"flat-address-space")
 
 
//===--===//
 // Interpolation builtins.

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-flat-address-space.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-flat-address-space.cl
new file mode 100644
index 0..57ee1c1a64711
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-flat-address-space.cl
@@ -0,0 +1,22 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-unknown-unknown -target-cpu 
tahiti -S -emit-llvm -disable-llvm-passes -o - %s | FileCheck -enable-var-scope 
%s
+
+// SI did not actually support flat addressing, but we can codegen the address
+// space test builtins. The target specfic part is a load from the implicit
+// argument buffer to use for the high pointer bits. It's just that buffer 
won't
+// be initialized to something useful. The proper way to diagnose invalid flat
+// usage is to forbid flat pointers on unsupported targets.
+
+// CHECK-LABEL: @test_is_shared_global(
+// CHECK: [[CAST:%[0-9]+]] = addrspacecast ptr addrspace(1) %{{[0-9]+}} to ptr
+// CHECK: call i1 @llvm.amdgcn.is.shared(ptr [[CAST]]
+int test_is_shared_global(const global int* ptr) {
+  return __builtin_amdgcn_is_shared(ptr);
+}
+
+// CHECK-LABEL: @test_is_private_global(
+// CHECK: [[CAST:%[0-9]+]] = addrspacecast ptr addrspace(1) %{{[0-9]+}} to ptr
+// CHECK: call i1 @llvm.amdgcn.is.private(ptr [[CAST]]
+int test_is_private_global(const global int* ptr) {
+  return __builtin_amdgcn_is_private(ptr);
+}

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
index eb1fa22e7fac2..9a20dba7490b4 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -1,5 +1,5 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -no-opaque-pointers -cl-std=CL2.0 -triple 
amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck -enable-var-scope %s
+// RUN: %clang_cc1 -no-opaque-pointers -cl-std=CL2.0 -triple 
amdgcn-unknown-unknown -target-cpu tahiti -S -emit-llvm -o - %s | FileCheck 
-enable-var-scope %s
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 

diff  --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-flat-address-space.cl 
b/clang/test/SemaOpenCL/builtins-amdgcn-error-flat-address-space.cl
index 0d759bac74a72..86ee55a646de8 100644
--- a/clang/test/SemaOpenCL/builtins-amdgcn-error-flat-address-space.cl
+++ b/clang/test/SemaOpenCL/builtins-a

[PATCH] D138868: AMDGPU/clang: Remove target features from address space test builtins

2022-12-29 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

e630d9b299822810bba8f3d0457004d1b4c39bef 



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

https://reviews.llvm.org/D138868

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


[PATCH] D138870: clang/AMDGPU: Remove flat-address-space from feature map

2022-12-29 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 485650.
arsenm added a comment.

Rebase


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

https://reviews.llvm.org/D138870

Files:
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/test/CodeGenOpenCL/amdgpu-features.cl
  clang/test/OpenMP/amdgcn-attributes.cpp
  clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp

Index: clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp
===
--- clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp
+++ clang/test/OpenMP/metadirective_device_isa_codegen_amdgcn.cpp
@@ -14,7 +14,7 @@
: threadCount)
   {
 #pragma omp metadirective \
-when(device = {isa("flat-address-space")} \
+when(device = {isa("dpp")} \
  : parallel) default(single)
 threadCount++;
   }
Index: clang/test/OpenMP/amdgcn-attributes.cpp
===
--- clang/test/OpenMP/amdgcn-attributes.cpp
+++ clang/test/OpenMP/amdgcn-attributes.cpp
@@ -33,11 +33,11 @@
 }
 
 // DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="none" "kernel" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
-// CPU: attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="none" "kernel" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" "uniform-work-group-size"="true" }
+// CPU: attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="none" "kernel" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" "uniform-work-group-size"="true" }
 // NOIEEE: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-ieee"="false" "frame-pointer"="none" "kernel" "no-nans-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
 // UNSAFEATOMIC: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "kernel" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
 
 // DEFAULT: attributes #1 = { convergent mustprogress noinline nounwind optnone "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
-// CPU: attributes #1 = { convergent mustprogress noinline nounwind optnone "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" }
+// CPU: attributes #1 = { convergent mustprogress noinline nounwind optnone "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" }
 // NOIEEE: attributes #1 = { convergent mustprogress noinline nounwind optnone "amdgpu-ieee"="false" "frame-pointer"="none" "no-nans-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
 // UNSAFEATOMIC: attributes #1 = { convergent mustprogress noinline nounwind optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
Index: clang/test/CodeGenOpenCL/amdgpu-features.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-features.cl
+++ clang/test/CodeGenOpenCL/amdgpu-features.cl
@@ -55,41 +55,41 @@
 // GFX600: "target-features"="+s-memtime-inst,+wavefrontsize64"
 // GFX601: "target-features"="+s-memtime-inst,+wavefrontsize64"
 // GFX602: "target-features"="+s-memtime-inst,+wavefrontsize64"
-// GFX700: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst,+wavefrontsize64"
-// GFX701: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst,+wavefrontsize64"
-// GFX702: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst,+wavefrontsize64"
-// GFX703: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst,+wavefrontsize64"
-// GFX704: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst,+wavefrontsize64"
-// GFX705: "target-features"="+ci-insts,+flat-address-space,+s-memtime-inst,+wavefrontsize64"
-// GFX801: "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
-// GFX802: "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+s-memrealti

[PATCH] D140696: [clang][dataflow] Treat unions as structs.

2022-12-29 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D140696#4019810 , @gribozavr2 
wrote:

>> With this change, unions are modeled exactly as structs (as far as I can 
>> tell), which is unsound.
>
> Modeling just the storage of the union (but not the value) is sound. The 
> first revision of the patch was a targeted fix that allowed us to continue 
> maintaining the invariant that `this` is always modeled with a non-null 
> `StorageLocation`.
>
> About modeling values of unions as structs (and members of unions as struct 
> members), I can think of some unsoundness but nothing that affects what we 
> are modeling now (e.g., pointers to two struct members should compare 
> unequal, but pointers to two union members should compare equal). If the code 
> writes to one union member, but reads from the other, code has UB. So it 
> generally shouldn't be a problem, for the purpose of modeling, to model more 
> storage in the union that a program free of union-related UB should never 
> use. WDYT?

Good point about UB! So, we can drop the soundness concern. That leaves the 
"this is a big change" concern. I'm ok with it, but I'd prefer it wait for a 
thorough test (running over a large variety of TUs). That said, you two can 
decide how best to proceed -- I don't want to block your progress.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140696

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


[PATCH] D140753: [clang][dataflow] Check both operand's type in mergeDistinctValues

2022-12-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 485654.
junaire added a comment.

Update patch according to @ymandel 's suggestion. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140753

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp


Index: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2970,6 +2970,23 @@
   cxxConstructorDecl(ofClass(hasName("Target";
 }
 
+// This is regression test, it shouldn't crash.
+TEST_P(UncheckedOptionalAccessTest, Bitfield) {
+  using namespace ast_matchers;
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+struct Dst {
+  unsigned int n : 1;
+};
+void target() {
+  $ns::$optional v;
+  Dst d;
+  if (v.has_value())
+d.n = v.value();
+}
+  )");
+}
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -93,7 +93,18 @@
   Environment::ValueModel &Model) {
   // Join distinct boolean values preserving information about the constraints
   // in the respective path conditions.
-  if (auto *Expr1 = dyn_cast(&Val1)) {
+  if (Type->isBooleanType()) {
+// FIXME: This is sort of workaound. Since now we just ignore all 
(implicit)
+// integral casts, treating the resulting value as same as the underling
+// value, it could cause inconsistency between values after `Join` if in
+// some paths the type doesn't strictly match.
+// Eg:
+// std::optional o;
+// int x;
+// if (o.has_value()) {
+//   x = o.value();
+// }
+auto *Expr1 = cast(&Val1);
 auto *Expr2 = cast(&Val2);
 auto &MergedVal = MergedEnv.makeAtomicBoolValue();
 MergedEnv.addToFlowCondition(MergedEnv.makeOr(


Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2970,6 +2970,23 @@
   cxxConstructorDecl(ofClass(hasName("Target";
 }
 
+// This is regression test, it shouldn't crash.
+TEST_P(UncheckedOptionalAccessTest, Bitfield) {
+  using namespace ast_matchers;
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+struct Dst {
+  unsigned int n : 1;
+};
+void target() {
+  $ns::$optional v;
+  Dst d;
+  if (v.has_value())
+d.n = v.value();
+}
+  )");
+}
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -93,7 +93,18 @@
   Environment::ValueModel &Model) {
   // Join distinct boolean values preserving information about the constraints
   // in the respective path conditions.
-  if (auto *Expr1 = dyn_cast(&Val1)) {
+  if (Type->isBooleanType()) {
+// FIXME: This is sort of workaound. Since now we just ignore all (implicit)
+// integral casts, treating the resulting value as same as the underling
+// value, it could cause inconsistency between values after `Join` if in
+// some paths the type doesn't strictly match.
+// Eg:
+// std::optional o;
+// int x;
+// if (o.has_value()) {
+//   x = o.value();
+// }
+auto *Expr1 = cast(&Val1);
 auto *Expr2 = cast(&Val2);
 auto &MergedVal = MergedEnv.makeAtomicBoolValue();
 MergedEnv.addToFlowCondition(MergedEnv.makeOr(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2022-12-29 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 485655.
ccotter added a comment.

Update tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140760

Files:
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -687,7 +687,7 @@
 Sum += V[I] + 2;
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & I : V)
+  // CHECK-FIXES: for (int I : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FIXES-NEXT: Sum += I + 2;
 
@@ -695,7 +695,7 @@
 V[I] = 0;
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int& I : V)
+  // CHECK-FIXES: for (int & I : V)
   // CHECK-FIXES-NEXT: I = 0;
 
   // Although 'length' might be a valid free function, only std::size() is 
standardized
@@ -703,6 +703,14 @@
 printf("Fibonacci number is %d\n", V[I]);
 Sum += V[I] + 2;
   }
+
+  dependent Vals;
+  for (int I = 0, E = size(Vals); E != I; ++I) {
+Sum += Vals[I].X;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & Val : Vals)
+  // CHECK-FIXES-NEXT: Sum += Val.X;
 }
 
 // Ensure that 'const auto &' is used with containers of non-trivial types.


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -687,7 +687,7 @@
 Sum += V[I] + 2;
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int & I : V)
+  // CHECK-FIXES: for (int I : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FIXES-NEXT: Sum += I + 2;
 
@@ -695,7 +695,7 @@
 V[I] = 0;
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (int& I : V)
+  // CHECK-FIXES: for (int & I : V)
   // CHECK-FIXES-NEXT: I = 0;
 
   // Although 'length' might be a valid free function, only std::size() is standardized
@@ -703,6 +703,14 @@
 printf("Fibonacci number is %d\n", V[I]);
 Sum += V[I] + 2;
   }
+
+  dependent Vals;
+  for (int I = 0, E = size(Vals); E != I; ++I) {
+Sum += Vals[I].X;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & Val : Vals)
+  // CHECK-FIXES-NEXT: Sum += Val.X;
 }
 
 // Ensure that 'const auto &' is used with containers of non-trivial types.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2022-12-29 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 485656.
ccotter added a comment.

oops, redo diff with correct arc diff command


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140760

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -445,6 +445,34 @@
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & I : Dpp)
   // CHECK-FIXES-NEXT: printf("%d\n", I->X);
+
+  for (S::iterator It = begin(Ss), E = end(Ss); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : Ss)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::iterator It = begin(*Ps), E = end(*Ps); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : *Ps)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::iterator It = begin(*Ps); It != end(*Ps); ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : *Ps)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::const_iterator It = cbegin(Ss), E = cend(Ss); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto It : Ss)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
 }
 
 // Tests to verify the proper use of auto where the init variable type and the
@@ -653,6 +681,36 @@
   // CHECK-FIXES: for (int I : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = size(V); E != I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int I : V)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = size(V); E != I; ++I) {
+V[I] = 0;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & I : V)
+  // CHECK-FIXES-NEXT: I = 0;
+
+  // Although 'length' might be a valid free function, only std::size() is standardized
+  for (int I = 0, E = length(V); E != I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
+
+  dependent Vals;
+  for (int I = 0, E = size(Vals); E != I; ++I) {
+Sum += Vals[I].X;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & Val : Vals)
+  // CHECK-FIXES-NEXT: Sum += Val.X;
 }
 
 // Ensure that 'const auto &' is used with containers of non-trivial types.
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
@@ -39,6 +39,14 @@
   iterator end();
 };
 
+S::const_iterator begin(const S& s);
+S::const_iterator end(const S& s);
+S::const_iterator cbegin(const S& s);
+S::const_iterator cend(const S& s);
+S::iterator begin(S& s);
+S::iterator end(S& s);
+unsigned size(const S& s);
+
 struct T {
   typedef int value_type;
   struct iterator {
@@ -126,6 +134,11 @@
   void constFoo() const;
 };
 
+template
+unsigned size(const dependent&);
+template
+unsigned length(const dependent&);
+
 template
 class doublyDependent{
  public:
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
@@ -91,10 +91,18 @@
   for (vector::iterator it = v.begin(); it != v.end(); ++it)
 cout << *it;
 
+  // reasonable conversion
+  for (vector::iterator it = begin(v); it != end(v); ++it)
+cout << *it;
+

[PATCH] D140753: [clang][dataflow] Fix crash when having boolean-to-integral casts.

2022-12-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 485657.
junaire added a comment.

Fix typos


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140753

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp


Index: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2970,6 +2970,23 @@
   cxxConstructorDecl(ofClass(hasName("Target";
 }
 
+// This is regression test, it shouldn't crash.
+TEST_P(UncheckedOptionalAccessTest, Bitfield) {
+  using namespace ast_matchers;
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+struct Dst {
+  unsigned int n : 1;
+};
+void target() {
+  $ns::$optional v;
+  Dst d;
+  if (v.has_value())
+d.n = v.value();
+}
+  )");
+}
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -93,7 +93,18 @@
   Environment::ValueModel &Model) {
   // Join distinct boolean values preserving information about the constraints
   // in the respective path conditions.
-  if (auto *Expr1 = dyn_cast(&Val1)) {
+  if (Type->isBooleanType()) {
+// FIXME: This is sort of workaround. Since now we just ignore all 
(implicit)
+// integral casts, treating the resulting value as the same as the 
underlying
+// value, it could cause inconsistency between values after `Join` if in
+// some paths the type doesn't strictly match:
+//
+// std::optional o;
+// int x;
+// if (o.has_value()) {
+//   x = o.value();
+// }
+auto *Expr1 = cast(&Val1);
 auto *Expr2 = cast(&Val2);
 auto &MergedVal = MergedEnv.makeAtomicBoolValue();
 MergedEnv.addToFlowCondition(MergedEnv.makeOr(


Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2970,6 +2970,23 @@
   cxxConstructorDecl(ofClass(hasName("Target";
 }
 
+// This is regression test, it shouldn't crash.
+TEST_P(UncheckedOptionalAccessTest, Bitfield) {
+  using namespace ast_matchers;
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+struct Dst {
+  unsigned int n : 1;
+};
+void target() {
+  $ns::$optional v;
+  Dst d;
+  if (v.has_value())
+d.n = v.value();
+}
+  )");
+}
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -93,7 +93,18 @@
   Environment::ValueModel &Model) {
   // Join distinct boolean values preserving information about the constraints
   // in the respective path conditions.
-  if (auto *Expr1 = dyn_cast(&Val1)) {
+  if (Type->isBooleanType()) {
+// FIXME: This is sort of workaround. Since now we just ignore all (implicit)
+// integral casts, treating the resulting value as the same as the underlying
+// value, it could cause inconsistency between values after `Join` if in
+// some paths the type doesn't strictly match:
+//
+// std::optional o;
+// int x;
+// if (o.has_value()) {
+//   x = o.value();
+// }
+auto *Expr1 = cast(&Val1);
 auto *Expr2 = cast(&Val2);
 auto &MergedVal = MergedEnv.makeAtomicBoolValue();
 MergedEnv.addToFlowCondition(MergedEnv.makeOr(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140543: [clang-format] Add an option to format integer literal separators

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

It turns out that the memory bug had nothing to do with whether to use the 
stack or heap memory for the `Token` object. The culprit was passing 
`getFormattingLangOpts(Style)` directly to the `Lexer` constructor. I suppose 
in the Release build the copying of the returned `LangOptions` object is 
optimized out.


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

https://reviews.llvm.org/D140543

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
  clang/lib/Format/IntegerLiteralSeparatorFixer.h
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/IntegerLiteralSeparatorTest.cpp

Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -0,0 +1,228 @@
+//===- unittest/Format/IntegerLiteralSeparatorTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "../Tooling/ReplacementTest.h"
+#include "FormatTestUtils.h"
+
+#define DEBUG_TYPE "integer-literal-separator-test"
+
+namespace clang {
+namespace format {
+namespace {
+
+// TODO:
+// Refactor the class declaration, which is copied from BracesInserterTest.cpp.
+class IntegerLiteralSeparatorTest : public ::testing::Test {
+protected:
+  std::string format(llvm::StringRef Code, const FormatStyle &Style,
+ const std::vector &Ranges) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+auto NonEmptyRanges = Ranges;
+if (Ranges.empty())
+  NonEmptyRanges = {1, tooling::Range(0, Code.size())};
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, NonEmptyRanges, "", &Status);
+EXPECT_EQ(true, Status.FormatComplete) << Code << "\n\n";
+ReplacementCount = Replaces.size();
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ const std::vector &Ranges = {}) {
+testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style, Ranges))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style, Ranges));
+if (Style.Language == FormatStyle::LK_Cpp && Ranges.empty()) {
+  // Objective-C++ is a superset of C++, so everything checked for C++
+  // needs to be checked for Objective-C++ as well.
+  FormatStyle ObjCStyle = Style;
+  ObjCStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle, Ranges));
+}
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ const std::vector &Ranges = {}) {
+_verifyFormat(File, Line, Code, Code, Style, Ranges);
+  }
+
+  int ReplacementCount;
+};
+
+#define verifyFormat(...) _verifyFormat(__FILE__, __LINE__, __VA_ARGS__)
+
+TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(Style.Language, FormatStyle::LK_Cpp);
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Binary, 0);
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Decimal, 0);
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Hex, 0);
+
+  const StringRef Binary("b = 0b10011'11'0110'1u;");
+  verifyFormat(Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = -1;
+  verifyFormat("b = 0b10001101u;", Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = 1;
+  verifyFormat("b = 0b1'0'0'1'1'1'1'0'1'1'0'1u;", Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = 4;
+  verifyFormat("b = 0b1001'1110'1101u;", Binary, Style);
+
+  const StringRef Decimal("d = 184467'440737'0'95505'92Ull;");
+  verifyFormat(Decimal, Style);
+  Style.IntegerLiteralSeparator.Decimal = -1;
+  verifyFormat("d = 18446744073709550592Ull;", Decimal, Style);
+  Style.IntegerLiteralSeparator.Decimal = 3;
+  verifyFormat("d = 18'446'744'073'709'550'592Ull;", Decimal, Style);
+
+  const StringRef Hex("h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;");
+  verifyFormat(Hex, Style);
+  Style.IntegerL

[PATCH] D140543: [clang-format] Add an option to format integer literal separators

2022-12-29 Thread Owen Pan via Phabricator via cfe-commits
owenpan requested review of this revision.
owenpan added inline comments.



Comment at: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp:81-82
+
+  llvm::SpecificBumpPtrAllocator Allocator;
+  auto Tok = new (Allocator.Allocate()) Token;
+  Lex->LexFromRawLexer(*Tok);

HazardyKnusperkeks wrote:
> owenpan wrote:
> > I should allocate memory for the `Token` object as shown but instead had 
> > `Token Tok;` before.
> But why? What is different?
Thanks for asking! It made me find the real cause.


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

https://reviews.llvm.org/D140543

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


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2022-12-29 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 485665.
ccotter added a comment.

- Remove unused variable


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140760

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
@@ -445,6 +445,34 @@
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
   // CHECK-FIXES: for (auto & I : Dpp)
   // CHECK-FIXES-NEXT: printf("%d\n", I->X);
+
+  for (S::iterator It = begin(Ss), E = end(Ss); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : Ss)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::iterator It = begin(*Ps), E = end(*Ps); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : *Ps)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::iterator It = begin(*Ps); It != end(*Ps); ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & It : *Ps)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
+
+  for (S::const_iterator It = cbegin(Ss), E = cend(Ss); It != E; ++It) {
+printf("s has value %d\n", (*It).X);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto It : Ss)
+  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
 }
 
 // Tests to verify the proper use of auto where the init variable type and the
@@ -653,6 +681,36 @@
   // CHECK-FIXES: for (int I : V)
   // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
   // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = size(V); E != I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
+  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int I : V)
+  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
+  // CHECK-FIXES-NEXT: Sum += I + 2;
+
+  for (int I = 0, E = size(V); E != I; ++I) {
+V[I] = 0;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & I : V)
+  // CHECK-FIXES-NEXT: I = 0;
+
+  // Although 'length' might be a valid free function, only std::size() is standardized
+  for (int I = 0, E = length(V); E != I; ++I) {
+printf("Fibonacci number is %d\n", V[I]);
+Sum += V[I] + 2;
+  }
+
+  dependent Vals;
+  for (int I = 0, E = size(Vals); E != I; ++I) {
+Sum += Vals[I].X;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & Val : Vals)
+  // CHECK-FIXES-NEXT: Sum += Val.X;
 }
 
 // Ensure that 'const auto &' is used with containers of non-trivial types.
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
@@ -39,6 +39,14 @@
   iterator end();
 };
 
+S::const_iterator begin(const S& s);
+S::const_iterator end(const S& s);
+S::const_iterator cbegin(const S& s);
+S::const_iterator cend(const S& s);
+S::iterator begin(S& s);
+S::iterator end(S& s);
+unsigned size(const S& s);
+
 struct T {
   typedef int value_type;
   struct iterator {
@@ -126,6 +134,11 @@
   void constFoo() const;
 };
 
+template
+unsigned size(const dependent&);
+template
+unsigned length(const dependent&);
+
 template
 class doublyDependent{
  public:
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
@@ -91,10 +91,18 @@
   for (vector::iterator it = v.begin(); it != v.end(); ++it)
 cout << *it;
 
+  // reasonable conversion
+  for (vector::iterator it = begin(v); it != end(v); ++it)
+cout << *it;
+
   // reasonable conv

[PATCH] D140753: [clang][dataflow] Fix crash when having boolean-to-integral casts.

2022-12-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:97-106
+// FIXME: This is sort of workaround. Since now we just ignore all 
(implicit)
+// integral casts, treating the resulting value as the same as the 
underlying
+// value, it could cause inconsistency between values after `Join` if in
+// some paths the type doesn't strictly match:
+//
+// std::optional o;
+// int x;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140753

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


[PATCH] D140772: Fix minor bug in add_new_check.py

2022-12-29 Thread Chris Cotter via Phabricator via cfe-commits
ccotter created this revision.
Herald added a subscriber: carlosgalvezp.
Herald added a reviewer: njames93.
Herald added a project: All.
ccotter requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

While rebuilding the list of checks in add_new_check.py,
check is a file is a subdirectory before traversing it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140772

Files:
  clang-tools-extra/clang-tidy/add_new_check.py
  clang-tools-extra/docs/ReleaseNotes.rst


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -99,6 +99,9 @@
 - Change to Python 3 in the shebang of `add_new_check.py` and 
`rename_check.py`,
   as the existing code is not compatible with Python 2.
 
+- Fix a minor bug in `add_new_check.py` to only traverse subdirectories
+  when updating the list of checks in the documentation.
+
 New checks
 ^^
 
Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -322,8 +322,7 @@
 lines = f.readlines()
   # Get all existing docs
   doc_files = []
-  for subdir in list(filter(lambda s: not s.endswith('.rst') and not 
s.endswith('.py'),
- os.listdir(docs_dir))):
+  for subdir in list(filter(os.path.isdir, os.listdir(docs_dir))):
 for file in filter(lambda s: s.endswith('.rst'), 
os.listdir(os.path.join(docs_dir, subdir))):
   doc_files.append([subdir, file])
   doc_files.sort()


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -99,6 +99,9 @@
 - Change to Python 3 in the shebang of `add_new_check.py` and `rename_check.py`,
   as the existing code is not compatible with Python 2.
 
+- Fix a minor bug in `add_new_check.py` to only traverse subdirectories
+  when updating the list of checks in the documentation.
+
 New checks
 ^^
 
Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -322,8 +322,7 @@
 lines = f.readlines()
   # Get all existing docs
   doc_files = []
-  for subdir in list(filter(lambda s: not s.endswith('.rst') and not s.endswith('.py'),
- os.listdir(docs_dir))):
+  for subdir in list(filter(os.path.isdir, os.listdir(docs_dir))):
 for file in filter(lambda s: s.endswith('.rst'), os.listdir(os.path.join(docs_dir, subdir))):
   doc_files.append([subdir, file])
   doc_files.sort()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136554: Implement CWG2631

2022-12-29 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht added a comment.

I threw this at the "test everything" test (some millions of targets) and it 
found only one breakage, so this is very very close. Without further ado, here 
is this silly looking thing:

File `blah.h`:

  #include 
  #include 
  
  template 
  struct Base {
virtual ~Base() = default;
  };
  
  class Impl : public Base {};
  
  struct ImplHolder {
std::unique_ptr> impl = std::make_unique();
  };
  
  struct GetImplCreators {
std::function impl_creator = []() { return ImplHolder{}; };
  };
  
  void UseImpl(GetImplCreators impl_creators = GetImplCreators{});

And `blah.cc`:

  #include "blah.h"
  
  void UseImpl(GetImplCreators impl_creators) {}

And lastly, `blah_main.cc`:

  #include "blah.h"
  
  void Func1() { UseImpl(); }
  // Note: it also fails when we explicitly specify the default arg, in case 
that is interesting.
  // void Func2() { UseImpl(GetImplCreators()); }
  
  int main(int argc, char* argv[]) { return 0; }

And here's the LLD output:

  ld: error: undefined hidden symbol: 
std::__u::__unique_if::__unique_single std::__u::make_unique()
  >>> referenced by blah_main.cc
  >>>   blah_main.o:(ImplHolder 
std::__u::__function::__policy_invoker::__call_impl>(std::__u::__function::__policy_storage const*))
  
  ld: error: undefined hidden symbol: std::__u::unique_ptr>::~unique_ptr()
  >>> referenced by blah_main.cc
  >>>   blah_main.o:(ImplHolder 
std::__u::__function::__policy_invoker::__call_impl>(std::__u::__function::__policy_storage const*))

I'm out of time today so I don't have a repro script to offer, but I can dig 
into that when I get back next year if the source-only example is insufficient.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[clang] eda2eaa - [clang][dataflow] Fix crash when having boolean-to-integral casts.

2022-12-29 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-12-30T13:14:44+08:00
New Revision: eda2eaabf2949c08ba94c92b9aad6fccb3c8eaa2

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

LOG: [clang][dataflow] Fix crash when having boolean-to-integral casts.

Since now we just ignore all (implicit) integral casts, treating the
resulting value as the same as the underlying value, it could cause
inconsistency between values after `Join` if in some paths the type
doesn't strictly match. This could cause intermittent crashes.

std::optional o;
int x;
if (o.has_value()) {
  x = o.value();
}

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

Signed-off-by: Jun Zhang 

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index c883f90f5554b..b8e3e93390602 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -93,7 +93,19 @@ static Value *mergeDistinctValues(QualType Type, Value &Val1,
   Environment::ValueModel &Model) {
   // Join distinct boolean values preserving information about the constraints
   // in the respective path conditions.
-  if (auto *Expr1 = dyn_cast(&Val1)) {
+  if (Type->isBooleanType()) {
+// FIXME: The type check above is a workaround and should be unnecessary.
+// However, right now we can end up with BoolValue's in integer-typed
+// variables due to our incorrect handling of boolean-to-integer casts (we
+// just propagate the BoolValue to the result of the cast). For example:
+// std::optional o;
+//
+//
+// int x;
+// if (o.has_value()) {
+//   x = o.value();
+// }
+auto *Expr1 = cast(&Val1);
 auto *Expr2 = cast(&Val2);
 auto &MergedVal = MergedEnv.makeAtomicBoolValue();
 MergedEnv.addToFlowCondition(MergedEnv.makeOr(

diff  --git 
a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
index 4d9c57f0dacd5..1fcede5d62865 100644
--- 
a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ 
b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2970,6 +2970,23 @@ TEST_P(UncheckedOptionalAccessTest, 
CtorInitializerValue) {
   cxxConstructorDecl(ofClass(hasName("Target";
 }
 
+// This is regression test, it shouldn't crash.
+TEST_P(UncheckedOptionalAccessTest, Bitfield) {
+  using namespace ast_matchers;
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+struct Dst {
+  unsigned int n : 1;
+};
+void target() {
+  $ns::$optional v;
+  Dst d;
+  if (v.has_value())
+d.n = v.value();
+}
+  )");
+}
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)



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


[PATCH] D140753: [clang][dataflow] Fix crash when having boolean-to-integral casts.

2022-12-29 Thread Jun Zhang 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 rGeda2eaabf294: [clang][dataflow] Fix crash when having 
boolean-to-integral casts. (authored by junaire).

Changed prior to commit:
  https://reviews.llvm.org/D140753?vs=485657&id=485669#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140753

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp


Index: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2970,6 +2970,23 @@
   cxxConstructorDecl(ofClass(hasName("Target";
 }
 
+// This is regression test, it shouldn't crash.
+TEST_P(UncheckedOptionalAccessTest, Bitfield) {
+  using namespace ast_matchers;
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+struct Dst {
+  unsigned int n : 1;
+};
+void target() {
+  $ns::$optional v;
+  Dst d;
+  if (v.has_value())
+d.n = v.value();
+}
+  )");
+}
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -93,7 +93,19 @@
   Environment::ValueModel &Model) {
   // Join distinct boolean values preserving information about the constraints
   // in the respective path conditions.
-  if (auto *Expr1 = dyn_cast(&Val1)) {
+  if (Type->isBooleanType()) {
+// FIXME: The type check above is a workaround and should be unnecessary.
+// However, right now we can end up with BoolValue's in integer-typed
+// variables due to our incorrect handling of boolean-to-integer casts (we
+// just propagate the BoolValue to the result of the cast). For example:
+// std::optional o;
+//
+//
+// int x;
+// if (o.has_value()) {
+//   x = o.value();
+// }
+auto *Expr1 = cast(&Val1);
 auto *Expr2 = cast(&Val2);
 auto &MergedVal = MergedEnv.makeAtomicBoolValue();
 MergedEnv.addToFlowCondition(MergedEnv.makeOr(


Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2970,6 +2970,23 @@
   cxxConstructorDecl(ofClass(hasName("Target";
 }
 
+// This is regression test, it shouldn't crash.
+TEST_P(UncheckedOptionalAccessTest, Bitfield) {
+  using namespace ast_matchers;
+  ExpectDiagnosticsFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+struct Dst {
+  unsigned int n : 1;
+};
+void target() {
+  $ns::$optional v;
+  Dst d;
+  if (v.has_value())
+d.n = v.value();
+}
+  )");
+}
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -93,7 +93,19 @@
   Environment::ValueModel &Model) {
   // Join distinct boolean values preserving information about the constraints
   // in the respective path conditions.
-  if (auto *Expr1 = dyn_cast(&Val1)) {
+  if (Type->isBooleanType()) {
+// FIXME: The type check above is a workaround and should be unnecessary.
+// However, right now we can end up with BoolValue's in integer-typed
+// variables due to our incorrect handling of boolean-to-integer casts (we
+// just propagate the BoolValue to the result of the cast). For example:
+// std::optional o;
+//
+//
+// int x;
+// if (o.has_value()) {
+//   x = o.value();
+// }
+auto *Expr1 = cast(&Val1);
 auto *Expr2 = cast(&Val2);
 auto &MergedVal = MergedEnv.makeAtomicBoolValue();
 MergedEnv.addToFlowCondition(MergedEnv.makeOr(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140527: [LoongArch] Add intrinsics for CACOP instruction

2022-12-29 Thread Xiaodong Liu via Phabricator via cfe-commits
XiaodongLoong added a comment.

ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140527

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


[PATCH] D140662: [NFC][Clang][RISCV] Reduce boilerplate when determining prototype for segment loads

2022-12-29 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng accepted this revision.
kito-cheng added a comment.
This revision is now accepted and ready to land.

Go ahead, thanks for clean up!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140662

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


[PATCH] D140693: [Driver][RISCV] Adjust the priority between -mcpu, -mtune and -march

2022-12-29 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

> So if I read this correctly, the effect of this is that we never pass 
> -target-cpu to the backend after this patch and will only pass 
> -target-feature and -tune-cpu?

Yes, that's prevent us taking any extensions from `-target-cpu`, so always pass 
`-target-feature` and `-tune-cpu` only.

> The code in riscv::getRISCVArch prioritizes -march over -mcpu for 
> architecture extensions for setting -target-features.
>
> But the backend still applies extensions from -target-cpu via the tablegen 
> features from RISCV.td.
>
> So its not even a "priority", we end up with a union.

Damm, you are right, that...even worth than I thought before, let me update the 
summary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140693

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


[PATCH] D140693: [Driver][RISCV] Adjust the priority between -mcpu, -mtune and -march

2022-12-29 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:5457
+  // RISC-V will handle -mcpu option in Clang::AddRISCVTargetArgs.
+  if (!Triple.isRISCV()) {
+// Add the target cpu

craig.topper wrote:
> I wonder if we should stop getCPUName from calling `getRISCVTargetCPU` 
> instead? Have you audited all callers of getCPUName?
That sounds a better way, that prevent us to auditing every caller of 
`getCPUName`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140693

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


[PATCH] D140773: [WebAssembly] Use `shufflevector` for shuffle

2022-12-29 Thread Petr Penzin via Phabricator via cfe-commits
penzn created this revision.
penzn added a reviewer: tlively.
Herald added subscribers: pmatos, asb, ecnelises, sunfish, hiraditya, 
jgravelle-google, sbc100, dschuff.
Herald added a project: All.
penzn requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, aheejin.
Herald added projects: clang, LLVM.

Back out D66983 , "[WebAssembly] Add 
wasm-specific vector shuffle builtin and
intrinsic".

  

Fix shuffle intrinsic tests. Since they are compiled with -O2 masks need to be
updated as well, otherwise optimizer would replace second operand with
`poison`.

  

Fix shuffle codegen tests. They require some mask updates to avoid invalid
`shufflevector` use and to make sure both operands get picked up.

  

This reverts commit 8e3e56f2a36701480eeb65e426701d5a9025cc59 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140773

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/wasm_simd128.h
  clang/test/CodeGen/builtins-wasm.c
  clang/test/Headers/wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -154,15 +154,10 @@
 ; NO-CHECK-NOT: i8x16
 ; CHECK-NEXT: .functype shuffle_v16i8 (v128, v128) -> (v128){{$}}
 ; CHECK-NEXT: i8x16.shuffle $push[[R:[0-9]+]]=, $0, $1,
-; CHECK-SAME: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0{{$}}
+; CHECK-SAME: 0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23{{$}}
 ; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <16 x i8> @llvm.wasm.shuffle(
-  <16 x i8>, <16 x i8>, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
-  i32, i32, i32, i32, i32)
 define <16 x i8> @shuffle_v16i8(<16 x i8> %x, <16 x i8> %y) {
-  %res = call <16 x i8> @llvm.wasm.shuffle(<16 x i8> %x, <16 x i8> %y,
-  i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7,
-  i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 35)
+  %res = shufflevector <16 x i8> %x, <16 x i8> %y, <16 x i32> 
   ret <16 x i8> %res
 }
 
@@ -170,13 +165,13 @@
 ; NO-CHECK-NOT: i8x16
 ; CHECK-NEXT: .functype shuffle_undef_v16i8 (v128, v128) -> (v128){{$}}
 ; CHECK-NEXT: i8x16.shuffle $push[[R:[0-9]+]]=, $0, $1,
-; CHECK-SAME: 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2{{$}}
+; CHECK-SAME: 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25{{$}}
 ; CHECK-NEXT: return $pop[[R]]{{$}}
 define <16 x i8> @shuffle_undef_v16i8(<16 x i8> %x, <16 x i8> %y) {
-  %res = call <16 x i8> @llvm.wasm.shuffle(<16 x i8> %x, <16 x i8> %y,
+  %res = shufflevector <16 x i8> %x, <16 x i8> %y, <16 x i32> <
   i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef,
   i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef,
-  i32 undef, i32 undef, i32 undef, i32 2)
+  i32 undef, i32 undef, i32 undef, i32 25>
   ret <16 x i8> %res
 }
 
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1806,24 +1806,6 @@
 SDValue Node = DAG.getTargetExternalSymbol(SymName, PtrVT);
 return DAG.getNode(WebAssemblyISD::Wrapper, DL, PtrVT, Node);
   }
-
-  case Intrinsic::wasm_shuffle: {
-// Drop in-chain and replace undefs, but otherwise pass through unchanged
-SDValue Ops[18];
-size_t OpIdx = 0;
-Ops[OpIdx++] = Op.getOperand(1);
-Ops[OpIdx++] = Op.getOperand(2);
-while (OpIdx < 18) {
-  const SDValue &MaskIdx = Op.getOperand(OpIdx + 1);
-  if (MaskIdx.isUndef() ||
-  cast(MaskIdx.getNode())->getZExtValue() >= 32) {
-Ops[OpIdx++] = DAG.getConstant(0, DL, MVT::i32);
-  } else {
-Ops[OpIdx++] = MaskIdx;
-  }
-}
-return DAG.getNode(WebAssemblyISD::SHUFFLE, DL, Op.getValueType(), Ops);
-  }
   }
 }
 
Index: llvm/include/llvm/IR/IntrinsicsWebAssembly.td
===
--- llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -168,14 +168,6 @@
   DefaultAttrsIntrinsic<[llvm_v16i8_ty],
 [llvm_v16i8_ty, llvm_v16i8_ty],
 [IntrNoMem, IntrSpeculatable]>;
-def int_wasm_shuffle :
-  DefaultAttrsIntrinsic<[llvm_v16i8_ty],
-[llvm_v16i8_ty, llvm_v16i8_ty, llvm_i32_ty,
- llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty,
- llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty,
- llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm

[PATCH] D140773: [WebAssembly] Use `shufflevector` for shuffle

2022-12-29 Thread Petr Penzin via Phabricator via cfe-commits
penzn added a comment.

I still need to run a few external tests, like the ones mentioned in

https://github.com/emscripten-core/emscripten/issues/9340
https://github.com/WebAssembly/simd/issues/196


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140773

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