[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #72607)

2024-01-02 Thread Yuanfang Chen via cfe-commits

https://github.com/yuanfang-chen updated 
https://github.com/llvm/llvm-project/pull/72607

>From 471f87e727d71e3984d533eeb9db9ebab40e63ff Mon Sep 17 00:00:00 2001
From: Yuanfang Chen 
Date: Fri, 17 Nov 2023 03:16:38 +
Subject: [PATCH] [clang][ExprConst] allow single element access of vector
 object to be constant expression

Supports both v[0] and v.x/v.r/v.s0 syntax.
Selecting multiple elements is left as a future work.
---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/lib/AST/ExprConstant.cpp| 103 +-
 clang/lib/AST/Interp/State.h  |   3 +-
 clang/test/CodeGenCXX/temporaries.cpp |  43 
 .../constexpr-vectors-access-elements.cpp |  29 +
 5 files changed, 155 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-vectors-access-elements.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8fec691bf3c9..070f0109501863 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -144,6 +144,9 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Allow single element access of vector object to be constant expression.
+  Supports the `V.xyzw` syntax and other tidbits as seen in OpenCL.
+  Selecting multiple elements is left as a future work.
 
 C++20 Feature Support
 ^
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f6aeee1a4e935d..9e2fc9b1af2ad1 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -221,6 +221,11 @@ namespace {
 ArraySize = 2;
 MostDerivedLength = I + 1;
 IsArray = true;
+  } else if (const auto *VT = Type->getAs()) {
+Type = VT->getElementType();
+ArraySize = VT->getNumElements();
+MostDerivedLength = I + 1;
+IsArray = true;
   } else if (const FieldDecl *FD = getAsField(Path[I])) {
 Type = FD->getType();
 ArraySize = 0;
@@ -437,6 +442,16 @@ namespace {
   MostDerivedArraySize = 2;
   MostDerivedPathLength = Entries.size();
 }
+void addVectorUnchecked(QualType EltTy, uint64_t Size, uint64_t Idx) {
+  Entries.push_back(PathEntry::ArrayIndex(Idx));
+
+  // This is technically a most-derived object, though in practice this
+  // is unlikely to matter.
+  MostDerivedType = EltTy;
+  MostDerivedIsArrayElement = true;
+  MostDerivedArraySize = Size;
+  MostDerivedPathLength = Entries.size();
+}
 void diagnoseUnsizedArrayPointerArithmetic(EvalInfo &Info, const Expr *E);
 void diagnosePointerArithmetic(EvalInfo &Info, const Expr *E,
const APSInt &N);
@@ -1732,6 +1747,11 @@ namespace {
   if (checkSubobject(Info, E, Imag ? CSK_Imag : CSK_Real))
 Designator.addComplexUnchecked(EltTy, Imag);
 }
+void addVectorElement(EvalInfo &Info, const Expr *E, QualType EltTy,
+  uint64_t Size, uint64_t Idx) {
+  if (checkSubobject(Info, E, CSK_VectorElement))
+Designator.addVectorUnchecked(EltTy, Size, Idx);
+}
 void clearIsNullPointer() {
   IsNullPtr = false;
 }
@@ -3278,6 +3298,19 @@ static bool HandleLValueComplexElement(EvalInfo &Info, 
const Expr *E,
   return true;
 }
 
+static bool HandleLValueVectorElement(EvalInfo &Info, const Expr *E,
+  LValue &LVal, QualType EltTy,
+  uint64_t Size, uint64_t Idx) {
+  if (Idx) {
+CharUnits SizeOfElement;
+if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfElement))
+  return false;
+LVal.Offset += SizeOfElement * Idx;
+  }
+  LVal.addVectorElement(Info, E, EltTy, Size, Idx);
+  return true;
+}
+
 /// Try to evaluate the initializer for a variable declaration.
 ///
 /// \param Info   Information about the ongoing evaluation.
@@ -3823,6 +3856,21 @@ findSubobject(EvalInfo &Info, const Expr *E, const 
CompleteObject &Obj,
 return handler.found(Index ? O->getComplexFloatImag()
: O->getComplexFloatReal(), ObjType);
   }
+} else if (const auto *VT = ObjType->getAs()) {
+  uint64_t Index = Sub.Entries[I].getAsArrayIndex();
+  if (Index >= VT->getNumElements()) {
+if (Info.getLangOpts().CPlusPlus11)
+  Info.FFDiag(E, diag::note_constexpr_access_past_end)
+<< handler.AccessKind;
+else
+  Info.FFDiag(E);
+return handler.failed();
+  }
+
+  ObjType = VT->getElementType();
+
+  assert(I == N - 1 && "extracting subobject of scalar?");
+  return handler.found(O->getVectorElt(Index), ObjType);
 } else if (const FieldDecl *Field = getAsField(Sub.Entries[I])) {
   if (Field->isMutable() &&
   !Obj.mayAccessMutableMembers(Info, handler.AccessKind)) {
@@ -8432,6 +8480,7 @@ class LValueExprEvaluator
   bool Vi

[clang] [clang-format] unexpected break after binOp '<<' (PR #69859)

2024-01-02 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

@s1Sharp are there any conclusions here? our code also incidentally relied on 
having new lines between string literals, mostly for the sake of having a line 
break after string literals that end with `\n`.

what do people think about restoring the functionality to break after string 
literals that end with `\n`?
https://github.com/search?q=%2F%5C%5Cn%5C%22%5Cn%5Cs*%3C%3C%5C+%5C%22%2F+language%3AC%2B%2B+&type=code&ref=advsearch
 shows a lot of examples of such pattern, so i feel like having that without an 
option initially easy relatively easy and likely to preserve clang-format's 
behavior for a lot of existing code for the next release. afterwards we can 
discuss introducing more options again.

https://github.com/llvm/llvm-project/pull/69859
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [X86] Emit Warnings for frontend options to enable knl/knm. (PR #75580)

2024-01-02 Thread Freddy Ye via cfe-commits

FreddyLeaf wrote:

Keeping `-march` supports for knl/knm meanwhile removing the specific ISA's 
intrinsic supports doesn't sound quite good to me. And thanks @phoebewang 
mentioned, removing the KNL/KNM supports could make all other targets always 
support AVX512F and AVX512VL meanwhile. This can simplify large amounts of 
logic codes in backend, which is very beneficial.

https://github.com/llvm/llvm-project/pull/75580
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix more bugs in isStartOfName() (PR #72336)

2024-01-02 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

hi @owenca looks like this is still regressing certain patterns, e.g:

```cpp
int foo BAR;
```

annotations before your modifications to `isStartOfName`:
```
AnnotatedTokens(L=0):
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=int L=3 PPK=2 FakeLParens= 
FakeRParens=0 II=0x216ebe0 Text='int'
 M=0 C=1 T=StartOfName S=1 F=0 B=0 BK=0 P=220 Name=identifier L=7 PPK=2 
FakeLParens= FakeRParens=0 II=0x21a3268 Text='foo'
 M=0 C=1 T=StartOfName S=1 F=0 B=0 BK=0 P=130 Name=identifier L=11 PPK=2 
FakeLParens= FakeRParens=0 II=0x21a3298 Text='BAR'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=semi L=12 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text=';'
```

new annotations:
```
AnnotatedTokens(L=0, P=0, T=5, C=0):
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=int L=3 PPK=2 FakeLParens= 
FakeRParens=0 II=0x558b37655290 Text='int'
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=23 Name=identifier L=7 PPK=2 FakeLParens= 
FakeRParens=0 II=0x558b3769d410 Text='foo'
 M=0 C=1 T=StartOfName S=1 F=0 B=0 BK=0 P=220 Name=identifier L=11 PPK=2 
FakeLParens= FakeRParens=0 II=0x558b3769d440 Text='BAR'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=semi L=12 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text=';'
```


as you can see `foo` is no longer recognized as `StartOfName`, resulting in 
drastically different penalties for breaking around the token and changing 
formatting for a lot of existing code. 

clang-format previously recognized these type of trailing attribute macros 
without any extra user configuration. it's quite obvious in 
https://github.com/llvm/llvm-project/commit/199fc973ced20016b04ba540cf63a1d4914fa513#diff-3f6f57cda9809a57c5b79e22b4181b3f3aaac7216262d0ef44108f39b0443e9bR8484,
 you're explicitly adding an attribute macro that wasn't explicitly told before 
(google style didn't have any pre-configured macros up until 
efeb546865c233dfa7706ee0316c676de9f69897).

not sure if this was deliberate, but it's resulting in a lot of changes for our 
codebase and even independent of that not recognizing identifier `foo` as 
`StartOfName` seem clearly wrong to me. since we're close to release cut can 
you quickly remedy this regression that has started with 
efeb546865c233dfa7706ee0316c676de9f69897 and accumulated more commits on top?

https://github.com/llvm/llvm-project/pull/72336
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-02 Thread Craig Topper via cfe-commits


@@ -109,6 +115,11 @@ BitVector RISCVRegisterInfo::getReservedRegs(const 
MachineFunction &MF) const {
   // beginning with 'x0' for instructions that take register pairs.
   markSuperRegs(Reserved, RISCV::DUMMY_REG_PAIR_WITH_X0);
 
+  // There are only 16 GPRs for RVE.
+  if (STI.isRVE())
+for (size_t Reg = RISCV::X16; Reg <= RISCV::X31; Reg++)

topperc wrote:

`MCPhysReg`.  Registers aren't size_t.

https://github.com/llvm/llvm-project/pull/76777
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-02 Thread Craig Topper via cfe-commits


@@ -285,13 +286,16 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList 
&Args,
   // 3. Choose a default based on `-mabi=`
   //
   // ilp32e -> rv32e
+  // lp64e -> rv64e
   // ilp32 | ilp32f | ilp32d -> rv32imafdc
   // lp64 | lp64f | lp64d -> rv64imafdc
   if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
 StringRef MABI = A->getValue();
 
 if (MABI.equals_insensitive("ilp32e"))
   return "rv32e";
+else if (MABI.starts_with_insensitive("lp64e"))

topperc wrote:

`equals_insensitive` like lip32e?

https://github.com/llvm/llvm-project/pull/76777
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-02 Thread Craig Topper via cfe-commits


@@ -68,6 +68,11 @@ ABI computeTargetABI(const Triple &TT, const FeatureBitset 
&FeatureBits,
 TargetABI = ABI_Unknown;
   }
 
+  if ((TargetABI == RISCVABI::ABI::ABI_ILP32E ||
+   (TargetABI == ABI_Unknown && IsRVE && !IsRV64)) &&
+  FeatureBits[RISCV::FeatureStdExtD])
+report_fatal_error("ILP32E must not be used with the D ISA extension");

topperc wrote:

"must not" -> "cannot"

https://github.com/llvm/llvm-project/pull/76777
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-02 Thread Craig Topper via cfe-commits


@@ -17134,30 +17133,64 @@ static const MCPhysReg ArgVRM4s[] = {RISCV::V8M4, 
RISCV::V12M4, RISCV::V16M4,
  RISCV::V20M4};
 static const MCPhysReg ArgVRM8s[] = {RISCV::V8M8, RISCV::V16M8};
 
-ArrayRef RISCV::getArgGPRs() {
-  static const MCPhysReg ArgGPRs[] = {RISCV::X10, RISCV::X11, RISCV::X12,
-  RISCV::X13, RISCV::X14, RISCV::X15,
-  RISCV::X16, RISCV::X17};
+ArrayRef RISCV::getArgGPRs(const RISCVABI::ABI ABI) {
+  // The GPRs used for passing arguments in the ILP32* and LP64* ABIs, except
+  // the ILP32E ABI.
+  static const MCPhysReg ArgIGPRs[] = {RISCV::X10, RISCV::X11, RISCV::X12,
+   RISCV::X13, RISCV::X14, RISCV::X15,
+   RISCV::X16, RISCV::X17};
+  // The GPRs used for passing arguments in the ILP32E/ILP64E ABI.
+  static const MCPhysReg ArgEGPRs[] = {RISCV::X10, RISCV::X11, RISCV::X12,
+   RISCV::X13, RISCV::X14, RISCV::X15};
+
+  if (ABI == RISCVABI::ABI_ILP32E || ABI == RISCVABI::ABI_LP64E)
+return ArrayRef(ArgEGPRs);
+
+  return ArrayRef(ArgIGPRs);
+}
+
+static ArrayRef getFastCCArgGPRs(const RISCVABI::ABI ABI) {
+  // The GPRs used for passing arguments in the FastCC, X5 and X6 might be used
+  // for save-restore libcall, so we don't use them.
+  static const MCPhysReg FastCCIGPRs[] = {
+  RISCV::X10, RISCV::X11, RISCV::X12, RISCV::X13, RISCV::X14,
+  RISCV::X15, RISCV::X16, RISCV::X17, RISCV::X7,  RISCV::X28,
+  RISCV::X29, RISCV::X30, RISCV::X31};
+
+  // The GPRs used for passing arguments in the FastCC when using 
ILP32E/ILP64E.
+  static const MCPhysReg FastCCEGPRs[] = {RISCV::X10, RISCV::X11, RISCV::X12,
+  RISCV::X13, RISCV::X14, RISCV::X15,
+  RISCV::X7};
 
-  return ArrayRef(ArgGPRs);
+  if (ABI == RISCVABI::ABI_ILP32E || ABI == RISCVABI::ABI_LP64E)
+return ArrayRef(FastCCEGPRs);
+
+  return ArrayRef(FastCCIGPRs);
 }
 
 // Pass a 2*XLEN argument that has been split into two XLEN values through
 // registers or the stack as necessary.
 static bool CC_RISCVAssign2XLen(unsigned XLen, CCState &State, CCValAssign VA1,
 ISD::ArgFlagsTy ArgFlags1, unsigned ValNo2,
 MVT ValVT2, MVT LocVT2,
-ISD::ArgFlagsTy ArgFlags2) {
+ISD::ArgFlagsTy ArgFlags2, bool EABI) {
   unsigned XLenInBytes = XLen / 8;
-  ArrayRef ArgGPRs = RISCV::getArgGPRs();
+  const RISCVSubtarget &STI =
+  State.getMachineFunction().getSubtarget();
+  ArrayRef ArgGPRs = RISCV::getArgGPRs(STI.getTargetABI());
+
   if (Register Reg = State.AllocateReg(ArgGPRs)) {
 // At least one half can be passed via register.
 State.addLoc(CCValAssign::getReg(VA1.getValNo(), VA1.getValVT(), Reg,
  VA1.getLocVT(), CCValAssign::Full));
   } else {
 // Both halves must be passed on the stack, with proper alignment.
+// TODO: To be compatible with GCC's behaviors, we force them to have 
4-byte
+// alignment. This behavior may be changed when RV32E/ILP32E is ratified.
 Align StackAlign =
-std::max(Align(XLenInBytes), ArgFlags1.getNonZeroOrigAlign());
+EABI && XLen == 32

topperc wrote:

```
Align StackAlign(XLenInBytes);
if (!EABI || XLen != 32)
  StackAlign = std::max(StackAlign, ArgFlags1.getNonZeroOrigAlign());
```

https://github.com/llvm/llvm-project/pull/76777
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-02 Thread Craig Topper via cfe-commits


@@ -0,0 +1,2556 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv32 -target-abi ilp32e -verify-machineinstrs < %s \
+; RUN:   | FileCheck -check-prefix=ILP32E-FPELIM %s
+; RUN: llc -mtriple=riscv32 -target-abi ilp32e -frame-pointer=all \
+; RUN:   -verify-machineinstrs < %s \
+; RUN:   | FileCheck -check-prefix=ILP32E-WITHFP %s
+; RUN: llc -mtriple=riscv32 -target-abi ilp32e -mattr=+save-restore 
-verify-machineinstrs < %s \
+; RUN:   | FileCheck -check-prefix=ILP32E-FPELIM-SAVE-RESTORE %s
+; RUN: llc -mtriple=riscv32 -target-abi ilp32e -mattr=+save-restore 
-frame-pointer=all \
+; RUN:   -verify-machineinstrs < %s \
+; RUN:   | FileCheck -check-prefix=ILP32E-WITHFP-SAVE-RESTORE %s
+
+; As well as calling convention details, we check that ra and fp are
+; consistently stored to fp-4 and fp-8.
+
+; Any tests that would have identical output for some combination of the ilp32*

topperc wrote:

This comment isn't accurate for this test.

https://github.com/llvm/llvm-project/pull/76777
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-02 Thread Craig Topper via cfe-commits


@@ -499,7 +514,8 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
   if (int LibCallRegs = getLibCallID(MF, MFI.getCalleeSavedInfo()) + 1) {
 // Calculate the size of the frame managed by the libcall. The libcalls are
 // implemented such that the stack will always be 16 byte aligned.

topperc wrote:

Does this comment about 16 byte aligned need to be updated?

https://github.com/llvm/llvm-project/pull/76777
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-02 Thread Craig Topper via cfe-commits


@@ -0,0 +1,221 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv64 -target-abi lp64e -verify-machineinstrs < %s \
+; RUN:   | FileCheck -check-prefix=RV64I-LP64E-FPELIM %s
+; RUN: llc -mtriple=riscv64 -target-abi lp64e -verify-machineinstrs 
-frame-pointer=all < %s \
+; RUN:   | FileCheck -check-prefix=RV64I-LP64E-WITHFP %s
+
+; As well as calling convention details, we check that ra and fp are
+; consistently stored to fp-8 and fp-16.
+
+; Any tests that would have identical output for some combination of the lp64*

topperc wrote:

This comment isn't accurate for this test.

https://github.com/llvm/llvm-project/pull/76777
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [polly] [libc] [flang] [openmp] [compiler-rt] [clang] [libcxxabi] [llvm] [mlir] [libcxx] [lldb] [mlir][vector] Fix invalid `LoadOp` indices being created (PR #76292)

2024-01-02 Thread Rik Huijzer via cfe-commits


@@ -897,7 +921,8 @@ struct TransferOpConversion : public 
VectorToSCFPattern {
   } else {
 // It's safe to assume the mask buffer can be unpacked if the data
 // buffer was unpacked.
-auto castedMaskType = *unpackOneDim(maskBufferType);
+auto maskBufferType = dyn_cast(maskBuffer.getType());

rikhuijzer wrote:

Ah yes. You're right. Done in 
[ec9d8d7](https://github.com/llvm/llvm-project/pull/76292/commits/ec9d8d75077b26c2efa92063ec659ba2dd89d8b7).

https://github.com/llvm/llvm-project/pull/76292
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [polly] [libc] [flang] [openmp] [compiler-rt] [clang] [libcxxabi] [llvm] [mlir] [libcxx] [lldb] [mlir][vector] Fix invalid `LoadOp` indices being created (PR #76292)

2024-01-02 Thread Rik Huijzer via cfe-commits

https://github.com/rikhuijzer updated 
https://github.com/llvm/llvm-project/pull/76292

>From 0ff5a0ec09f7c26824bd90e6c7656222ee2448ae Mon Sep 17 00:00:00 2001
From: Rik Huijzer 
Date: Sat, 23 Dec 2023 16:32:27 +0100
Subject: [PATCH 1/3] [mlir][vector] Fix invalid `LoadOp` indices being created

---
 .../Conversion/VectorToSCF/VectorToSCF.cpp| 48 +--
 .../Conversion/VectorToSCF/vector-to-scf.mlir | 37 ++
 2 files changed, 71 insertions(+), 14 deletions(-)

diff --git a/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp 
b/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
index 2ee314e9fedfe3..13d2513a88804c 100644
--- a/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
+++ b/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
@@ -866,6 +866,31 @@ struct TransferOpConversion : public 
VectorToSCFPattern {
 this->setHasBoundedRewriteRecursion();
   }
 
+  static void getMaskBufferLoadIndices(OpTy xferOp, Value castedMaskBuffer,
+   SmallVector &loadIndices,
+   Value iv) {
+assert(xferOp.getMask() && "Expected transfer op to have mask");
+
+// Add load indices from the previous iteration.
+// The mask buffer depends on the permutation map, which makes determining
+// the indices quite complex, so this is why we need to "look back" to the
+// previous iteration to find the right indices.
+Value maskBuffer = getMaskBuffer(xferOp);
+for (OpOperand &use : maskBuffer.getUses()) {
+  // If there is no previous load op, then the indices are empty.
+  if (auto loadOp = dyn_cast(use.getOwner())) {
+Operation::operand_range prevIndices = loadOp.getIndices();
+loadIndices.append(prevIndices.begin(), prevIndices.end());
+break;
+  }
+}
+
+// In case of broadcast: Use same indices to load from memref
+// as before.
+if (!xferOp.isBroadcastDim(0))
+  loadIndices.push_back(iv);
+  }
+
   LogicalResult matchAndRewrite(OpTy xferOp,
 PatternRewriter &rewriter) const override {
 if (!xferOp->hasAttr(kPassLabel))
@@ -873,9 +898,9 @@ struct TransferOpConversion : public 
VectorToSCFPattern {
 
 // Find and cast data buffer. How the buffer can be found depends on OpTy.
 ImplicitLocOpBuilder locB(xferOp.getLoc(), rewriter);
-auto dataBuffer = Strategy::getBuffer(xferOp);
+Value dataBuffer = Strategy::getBuffer(xferOp);
 auto dataBufferType = dyn_cast(dataBuffer.getType());
-auto castedDataType = unpackOneDim(dataBufferType);
+FailureOr castedDataType = unpackOneDim(dataBufferType);
 if (failed(castedDataType))
   return failure();
 
@@ -885,8 +910,7 @@ struct TransferOpConversion : public 
VectorToSCFPattern {
 // If the xferOp has a mask: Find and cast mask buffer.
 Value castedMaskBuffer;
 if (xferOp.getMask()) {
-  auto maskBuffer = getMaskBuffer(xferOp);
-  auto maskBufferType = dyn_cast(maskBuffer.getType());
+  Value maskBuffer = getMaskBuffer(xferOp);
   if (xferOp.isBroadcastDim(0) || xferOp.getMaskType().getRank() == 1) {
 // Do not unpack a dimension of the mask, if:
 // * To-be-unpacked transfer op dimension is a broadcast.
@@ -897,7 +921,8 @@ struct TransferOpConversion : public 
VectorToSCFPattern {
   } else {
 // It's safe to assume the mask buffer can be unpacked if the data
 // buffer was unpacked.
-auto castedMaskType = *unpackOneDim(maskBufferType);
+auto maskBufferType = dyn_cast(maskBuffer.getType());
+MemRefType castedMaskType = *unpackOneDim(maskBufferType);
 castedMaskBuffer =
 locB.create(castedMaskType, maskBuffer);
   }
@@ -929,21 +954,16 @@ struct TransferOpConversion : public 
VectorToSCFPattern {
 
 // If old transfer op has a mask: Set mask on new transfer op.
 // Special case: If the mask of the old transfer op is 1D and
-// the
-//   unpacked dim is not a broadcast, no mask is
-//   needed on the new transfer op.
+// the unpacked dim is not a broadcast, no mask is needed on
+// the new transfer op.
 if (xferOp.getMask() && (xferOp.isBroadcastDim(0) ||
  xferOp.getMaskType().getRank() > 1)) {
   OpBuilder::InsertionGuard guard(b);
   b.setInsertionPoint(newXfer); // Insert load before newXfer.
 
   SmallVector loadIndices;
-  Strategy::getBufferIndices(xferOp, loadIndices);
-  // In case of broadcast: Use same indices to load from memref
-  // as before.
-  if (!xferOp.isBroadcastDim(0))
-loadIndices.push_back(iv);
-
+  getMaskBufferLoadIndices(xferOp, castedMaskBuffer,
+

[llvm] [clang] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-02 Thread Craig Topper via cfe-commits

topperc wrote:

What was the last bit of discussion on the phabricator review? I can no longer 
access it.

https://github.com/llvm/llvm-project/pull/76777
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [flang] [clang] [compiler-rt] [llvm] [lldb] [clang-tools-extra] [libc] [lld] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2024-01-02 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja edited 
https://github.com/llvm/llvm-project/pull/76447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [flang] [clang] [compiler-rt] [llvm] [lldb] [clang-tools-extra] [libc] [lld] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2024-01-02 Thread A. Jiang via cfe-commits


@@ -1273,6 +1293,22 @@ public:
 __impl_.__swap(__that.__impl_);
   }
 
+#  if _LIBCPP_STD_VER >= 26
+  // [variant.visit], visitation
+
+  template 

frederick-vs-ja wrote:

Would it be better to use a special tag type like this
```C++
struct __variant_visit_barrier_tag { // unnamable when using standard library 
modules
  explicit __variant_visit_barrier_tag() = default;
};
// ...
template <__variant_visit_barrier_tag = __variant_visit_barrier_tag{}, class 
_Self, class _Visitor>
// ...
```
to avoid accepting `v.visit<0, T, F>(f)`?

https://github.com/llvm/llvm-project/pull/76447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

2024-01-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Wang Pengcheng (wangpc-pp)


Changes

This commit includes the necessary changes to clang and LLVM to support
codegen of `RVE` and the `ilp32e`/`lp64e` ABIs.

The differences between `RVE` and `RVI` are:
* `RVE` reduces the integer register count to 16(x0-x16).
* The ABI should be `ilp32e` for 32 bits and `lp64e` for 64 bits.

`RVE` can be combined with all current standard extensions.

The central changes in ilp32e/lp64e ABI, compared to ilp32/lp64 are:
* Only 6 integer argument registers (rather than 8).
* Only 2 callee-saved registers (rather than 12).
* A Stack Alignment of 32bits (rather than 128bits).
* ilp32e isn't compatible with D ISA extension.

If `ilp32e` or `lp64` is used with an ISA that has any of the registers
x16-x31 and f0-f31, then these registers are considered temporaries.

To be compatible with the implementation of ilp32e in GCC, we don't use
aligned registers to pass variadic arguments and set stack alignment\
to 4-bytes for types with length of 2*XLEN.

FastCC is also supported on RVE, while GHC isn't since there is only one
avaiable register.

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


---

Patch is 422.14 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/76777.diff


45 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Basic/Targets/RISCV.cpp (+13-1) 
- (modified) clang/lib/Basic/Targets/RISCV.h (+12) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2-1) 
- (modified) clang/lib/CodeGen/TargetInfo.h (+2-1) 
- (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+25-10) 
- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+4) 
- (modified) clang/test/CodeGen/RISCV/riscv32-abi.c (+3) 
- (added) clang/test/CodeGen/RISCV/riscv32-ilp32e-error.c (+4) 
- (modified) clang/test/CodeGen/RISCV/riscv32-vararg.c (+421-141) 
- (modified) clang/test/CodeGen/RISCV/riscv64-abi.c (+4) 
- (modified) clang/test/CodeGen/RISCV/riscv64-vararg.c (+2) 
- (modified) clang/test/Preprocessor/riscv-target-features.c (+22) 
- (modified) llvm/docs/RISCVUsage.rst (+6) 
- (modified) llvm/docs/ReleaseNotes.rst (+2) 
- (modified) llvm/include/llvm/Support/RISCVAttributes.h (+1-1) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+4-4) 
- (modified) llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp (+5) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp (+8-5) 
- (modified) llvm/lib/Target/RISCV/RISCVCallingConv.td (+14-1) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+7) 
- (modified) llvm/lib/Target/RISCV/RISCVFrameLowering.cpp (+21-3) 
- (modified) llvm/lib/Target/RISCV/RISCVFrameLowering.h (+1-6) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+65-28) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.h (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp (+17-3) 
- (modified) llvm/lib/Target/RISCV/RISCVTargetMachine.cpp (+13-3) 
- (modified) llvm/test/CodeGen/RISCV/callee-saved-fpr32s.ll (+432-2) 
- (modified) llvm/test/CodeGen/RISCV/callee-saved-fpr64s.ll (+216-1) 
- (modified) llvm/test/CodeGen/RISCV/callee-saved-gprs.ll (+530) 
- (added) llvm/test/CodeGen/RISCV/calling-conv-ilp32e.ll (+2556) 
- (added) llvm/test/CodeGen/RISCV/calling-conv-lp64e.ll (+221) 
- (added) llvm/test/CodeGen/RISCV/calling-conv-rv32f-ilp32e.ll (+83) 
- (modified) llvm/test/CodeGen/RISCV/interrupt-attr.ll (+745) 
- (added) llvm/test/CodeGen/RISCV/rv32e.ll (+25) 
- (added) llvm/test/CodeGen/RISCV/rv64e.ll (+25) 
- (removed) llvm/test/CodeGen/RISCV/rve.ll (-8) 
- (modified) 
llvm/test/CodeGen/RISCV/stack-realignment-with-variable-sized-objects.ll (+60) 
- (modified) llvm/test/CodeGen/RISCV/stack-realignment.ll (+652) 
- (modified) llvm/test/CodeGen/RISCV/target-abi-valid.ll (+4-5) 
- (added) llvm/test/CodeGen/RISCV/vararg-ilp32e.ll (+148) 
- (modified) llvm/test/CodeGen/RISCV/vararg.ll (+1261) 
- (modified) llvm/test/MC/RISCV/option-invalid.s (-3) 
- (modified) llvm/test/MC/RISCV/target-abi-invalid.s (+6-3) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8fec691bf3c9..aa8d27f5c17551 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -971,6 +971,8 @@ RISC-V Support
 ^^
 - Unaligned memory accesses can be toggled by ``-m[no-]unaligned-access`` or 
the
   aliases ``-m[no-]strict-align``.
+- CodeGen of RV32E/RV64E are supported experimentally.
+- CodeGen of ilp32e/lp64e are supported experimentally.
 
 - Default ABI with F but without D was changed to ilp32f for RV32 and to lp64f
   for RV64.
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 6bc57a83a2d5ae..8db989df04c87b 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -154,7 +154,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
&Opts,

[clang-tools-extra] [llvm] create new clang-tidy check to add namespaces to symbol references (PR #70621)

2024-01-02 Thread via cfe-commits

https://github.com/daltairwalter updated 
https://github.com/llvm/llvm-project/pull/70621

>From f44d7746a990a3bd8e53de047a30baee4da2c790 Mon Sep 17 00:00:00 2001
From: Daniel Walter 
Date: Mon, 30 Oct 2023 00:08:56 -0500
Subject: [PATCH 1/5] Initial commit of add new check before changes

---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/ReadabilityTidyModule.cpp |  3 ++
 .../UseExplicitNamespacesCheck.cpp| 33 +++
 .../readability/UseExplicitNamespacesCheck.h  | 30 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../readability/use-explicit-namespaces.rst   |  6 
 .../readability/use-explicit-namespaces.cpp   | 14 
 8 files changed, 93 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/use-explicit-namespaces.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/use-explicit-namespaces.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a4617..6bcc9ca3e646ce 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -51,6 +51,7 @@ add_clang_library(clangTidyReadabilityModule
   UniqueptrDeleteReleaseCheck.cpp
   UppercaseLiteralSuffixCheck.cpp
   UseAnyOfAllOfCheck.cpp
+  UseExplicitNamespacesCheck.cpp
 
   LINK_LIBS
   clangTidy
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e641432060..bdb253f90cebc2 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -54,6 +54,7 @@
 #include "UniqueptrDeleteReleaseCheck.h"
 #include "UppercaseLiteralSuffixCheck.h"
 #include "UseAnyOfAllOfCheck.h"
+#include "UseExplicitNamespacesCheck.h"
 
 namespace clang::tidy {
 namespace readability {
@@ -151,6 +152,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-uppercase-literal-suffix");
 CheckFactories.registerCheck(
 "readability-use-anyofallof");
+CheckFactories.registerCheck(
+"readability-use-explicit-namespaces");
   }
 };
 
diff --git 
a/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
new file mode 100644
index 00..a803179b822bd2
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.cpp
@@ -0,0 +1,33 @@
+//===--- UseExplicitNamespacesCheck.cpp - clang-tidy 
--===//
+//
+// 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 "UseExplicitNamespacesCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void UseExplicitNamespacesCheck::registerMatchers(MatchFinder *Finder) {
+  // FIXME: Add matchers.
+  Finder->addMatcher(functionDecl().bind("x"), this);
+}
+
+void UseExplicitNamespacesCheck::check(const MatchFinder::MatchResult &Result) 
{
+  // FIXME: Add callback implementation.
+  const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
+  if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().startswith("awesome_"))
+return;
+  diag(MatchedDecl->getLocation(), "function %0 is insufficiently awesome")
+  << MatchedDecl
+  << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
+  diag(MatchedDecl->getLocation(), "insert 'awesome'", DiagnosticIDs::Note);
+}
+
+} // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h 
b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h
new file mode 100644
index 00..846e47930d0566
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/UseExplicitNamespacesCheck.h
@@ -0,0 +1,30 @@
+//===--- UseExplicitNamespacesCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USEEX

[clang-tools-extra] [clangd] Add container field to remote index Refs grpc method (PR #71605)

2024-01-02 Thread via cfe-commits

https://github.com/tdupes edited https://github.com/llvm/llvm-project/pull/71605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PseudoProbe] Mix and reorder block and call probe ID in lexical order (PR #75092)

2024-01-02 Thread via cfe-commits

WenleiHe wrote:

We will need some protection against accidentally consuming old profile with 
new toolchain and vice versa. The cost of investigating mysterious perf 
regression can be high and we'd rather simply error out in those cases. Maybe 
consider some flag for `SecProfSummaryFlags` (also wondering if this needs to 
be per-function flag since technically some function/module can be compiled 
with old order while others with new order).

Can we gauge perf benefit of mixed order encoding? i.e. profile an old source 
rev (several weeks ago?) with both probe order, and build with new source rev 
using that old profile, then see how old vs new order compare in terms of perf 
and efficacy with incremental PGO. 

https://github.com/llvm/llvm-project/pull/75092
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-02 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/76774

>From 79cefc9f0f006acd788b6ac4e240c17d9deadf13 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 3 Jan 2024 11:33:17 +0800
Subject: [PATCH] Load Specializations Lazily

---
 clang/include/clang/AST/DeclTemplate.h|  35 ++--
 clang/include/clang/AST/ExternalASTSource.h   |   5 +
 clang/include/clang/AST/ODRHash.h |   3 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |  19 +++
 clang/include/clang/Serialization/ASTWriter.h |   6 +
 clang/lib/AST/DeclTemplate.cpp|  66 +---
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 clang/lib/AST/ODRHash.cpp |   2 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |   6 +
 clang/lib/Serialization/ASTReader.cpp | 109 +++-
 clang/lib/Serialization/ASTReaderDecl.cpp |  34 +++-
 clang/lib/Serialization/ASTReaderInternals.h  |  80 +
 clang/lib/Serialization/ASTWriter.cpp | 149 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  75 ++---
 clang/test/Modules/odr_hash.cpp   |   4 +-
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazily.cpp  | 159 ++
 19 files changed, 702 insertions(+), 65 deletions(-)
 create mode 100644 clang/unittests/Serialization/LoadSpecLazily.cpp

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 832ad2de6b08a8..4699dd17bc182c 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -525,8 +525,11 @@ class FunctionTemplateSpecializationInfo final
 return Function.getInt();
   }
 
+  void loadExternalRedecls();
+
 public:
   friend TrailingObjects;
+  friend class ASTReader;
 
   static FunctionTemplateSpecializationInfo *
   Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
@@ -789,13 +792,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
-  void loadLazySpecializationsImpl() const;
+  void loadExternalSpecializations() const;
 
   template 
   typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
  void *&InsertPos, ProfileArguments &&...ProfileArgs);
 
+  void loadLazySpecializationsWithArgs(ArrayRef 
TemplateArgs);
+
   template 
   void addSpecializationImpl(llvm::FoldingSetVector &Specs,
  EntryType *Entry, void *InsertPos);
@@ -814,9 +819,13 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 /// If non-null, points to an array of specializations (including
 /// partial specializations) known only by their external declaration IDs.
 ///
+/// These specializations needs to be loaded at once in
+/// loadExternalSpecializations to complete the redecl chain or be 
preparing
+/// for template resolution.
+///
 /// The first value in the array is the number of specializations/partial
 /// specializations that follow.
-uint32_t *LazySpecializations = nullptr;
+uint32_t *ExternalSpecializations = nullptr;
 
 /// The set of "injected" template arguments used within this
 /// template.
@@ -850,6 +859,8 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   friend class ASTDeclWriter;
   friend class ASTReader;
   template  friend class RedeclarableTemplate;
+  friend class ClassTemplateSpecializationDecl;
+  friend class VarTemplateSpecializationDecl;
 
   /// Retrieves the canonical declaration of this template.
   RedeclarableTemplateDecl *getCanonicalDecl() override {
@@ -977,6 +988,7 @@ SpecEntryTraits {
 class FunctionTemplateDecl : public RedeclarableTemplateDecl {
 protected:
   friend class FunctionDecl;
+  friend class FunctionTemplateSpecializationInfo;
 
   /// Data that is common to all of the declarations of a given
   /// function template.
@@ -1012,13 +1024,13 @@ class FunctionTemplateDecl : public 
RedeclarableTemplateDecl {
   void addSpecialization(FunctionTemplateSpecializationInfo* Info,
  void *InsertPos);
 
+  /// Load any lazily-loaded specializations from the external source.
+  void LoadLazySpecializations() const;
+
 public:
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
 
-  /// Load any lazily-loaded specializations from the external source.
-  void LoadLazySpecializations() const;
-
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
 return static_cast(TemplatedDecl);
@@ -1839,6 +1851,8 @@ class ClassTemplateSpecializationDecl
   LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
   unsigned SpecializationKind : 3;
 
+  void loadExternalRedecls();
+
 protected:
   ClassTemplateSpecializationDecl(ASTCont

[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-02 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 7a3b0cbb143d02b70b2bfae5cd40e9867c124748 
af6f8ca9b739c532a489881245fac1413ec84a07 -- 
clang/unittests/Serialization/LoadSpecLazily.cpp 
clang/include/clang/AST/DeclTemplate.h 
clang/include/clang/AST/ExternalASTSource.h clang/include/clang/AST/ODRHash.h 
clang/include/clang/Sema/MultiplexExternalSemaSource.h 
clang/include/clang/Serialization/ASTBitCodes.h 
clang/include/clang/Serialization/ASTReader.h 
clang/include/clang/Serialization/ASTWriter.h clang/lib/AST/DeclTemplate.cpp 
clang/lib/AST/ExternalASTSource.cpp clang/lib/AST/ODRHash.cpp 
clang/lib/Sema/MultiplexExternalSemaSource.cpp 
clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTReaderDecl.cpp 
clang/lib/Serialization/ASTReaderInternals.h 
clang/lib/Serialization/ASTWriter.cpp clang/lib/Serialization/ASTWriterDecl.cpp 
clang/test/Modules/odr_hash.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 3e0a89a92b..4699dd17bc 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -2253,7 +2253,6 @@ public:
 /// Declaration of a class template.
 class ClassTemplateDecl : public RedeclarableTemplateDecl {
 protected:
-
   /// Data that is common to all of the declarations of a given
   /// class template.
   struct Common : CommonBase {
@@ -3035,7 +3034,6 @@ public:
 /// Declaration of a variable template.
 class VarTemplateDecl : public RedeclarableTemplateDecl {
 protected:
-
   /// Data that is common to all of the declarations of a given
   /// variable template.
   struct Common : CommonBase {

``




https://github.com/llvm/llvm-project/pull/76774
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-02 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/76774

>From af6f8ca9b739c532a489881245fac1413ec84a07 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 3 Jan 2024 11:33:17 +0800
Subject: [PATCH] Load Specializations Lazily

---
 clang/include/clang/AST/DeclTemplate.h|  37 ++--
 clang/include/clang/AST/ExternalASTSource.h   |   5 +
 clang/include/clang/AST/ODRHash.h |   3 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |  19 +++
 clang/include/clang/Serialization/ASTWriter.h |   6 +
 clang/lib/AST/DeclTemplate.cpp|  66 +---
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 clang/lib/AST/ODRHash.cpp |   2 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |   6 +
 clang/lib/Serialization/ASTReader.cpp | 109 +++-
 clang/lib/Serialization/ASTReaderDecl.cpp |  34 +++-
 clang/lib/Serialization/ASTReaderInternals.h  |  80 +
 clang/lib/Serialization/ASTWriter.cpp | 149 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  75 ++---
 clang/test/Modules/odr_hash.cpp   |   4 +-
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazily.cpp  | 159 ++
 19 files changed, 704 insertions(+), 65 deletions(-)
 create mode 100644 clang/unittests/Serialization/LoadSpecLazily.cpp

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 832ad2de6b08a8..3e0a89a92b020d 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -525,8 +525,11 @@ class FunctionTemplateSpecializationInfo final
 return Function.getInt();
   }
 
+  void loadExternalRedecls();
+
 public:
   friend TrailingObjects;
+  friend class ASTReader;
 
   static FunctionTemplateSpecializationInfo *
   Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
@@ -789,13 +792,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
-  void loadLazySpecializationsImpl() const;
+  void loadExternalSpecializations() const;
 
   template 
   typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
  void *&InsertPos, ProfileArguments &&...ProfileArgs);
 
+  void loadLazySpecializationsWithArgs(ArrayRef 
TemplateArgs);
+
   template 
   void addSpecializationImpl(llvm::FoldingSetVector &Specs,
  EntryType *Entry, void *InsertPos);
@@ -814,9 +819,13 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 /// If non-null, points to an array of specializations (including
 /// partial specializations) known only by their external declaration IDs.
 ///
+/// These specializations needs to be loaded at once in
+/// loadExternalSpecializations to complete the redecl chain or be 
preparing
+/// for template resolution.
+///
 /// The first value in the array is the number of specializations/partial
 /// specializations that follow.
-uint32_t *LazySpecializations = nullptr;
+uint32_t *ExternalSpecializations = nullptr;
 
 /// The set of "injected" template arguments used within this
 /// template.
@@ -850,6 +859,8 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   friend class ASTDeclWriter;
   friend class ASTReader;
   template  friend class RedeclarableTemplate;
+  friend class ClassTemplateSpecializationDecl;
+  friend class VarTemplateSpecializationDecl;
 
   /// Retrieves the canonical declaration of this template.
   RedeclarableTemplateDecl *getCanonicalDecl() override {
@@ -977,6 +988,7 @@ SpecEntryTraits {
 class FunctionTemplateDecl : public RedeclarableTemplateDecl {
 protected:
   friend class FunctionDecl;
+  friend class FunctionTemplateSpecializationInfo;
 
   /// Data that is common to all of the declarations of a given
   /// function template.
@@ -1012,13 +1024,13 @@ class FunctionTemplateDecl : public 
RedeclarableTemplateDecl {
   void addSpecialization(FunctionTemplateSpecializationInfo* Info,
  void *InsertPos);
 
+  /// Load any lazily-loaded specializations from the external source.
+  void LoadLazySpecializations() const;
+
 public:
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
 
-  /// Load any lazily-loaded specializations from the external source.
-  void LoadLazySpecializations() const;
-
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
 return static_cast(TemplatedDecl);
@@ -1839,6 +1851,8 @@ class ClassTemplateSpecializationDecl
   LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
   unsigned SpecializationKind : 3;
 
+  void loadExternalRedecls();
+
 protected:
   ClassTemplateSpecializationDecl(ASTCont

[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-02 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 edited 
https://github.com/llvm/llvm-project/pull/76774
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Support 'fdopen' in the StreamChecker (PR #76776)

2024-01-02 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/76776

>From 19122ac9df0e621ffb25fcb64bfad2336476b94b Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 3 Jan 2024 11:30:57 +0800
Subject: [PATCH] [clang][analyzer] Support 'fdopen' in the StreamChecker

---
 clang/docs/ReleaseNotes.rst |  5 +++--
 clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp |  1 +
 .../test/Analysis/Inputs/system-header-simulator.h  |  1 +
 clang/test/Analysis/stream-error.c  | 13 +++--
 clang/test/Analysis/stream-non-posix-function.c |  7 ++-
 clang/test/Analysis/stream-note.c   | 10 ++
 clang/test/Analysis/stream-stdlibraryfunctionargs.c |  8 
 clang/test/Analysis/stream.c|  7 +++
 8 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8fec691bf3c9..5aaa4436d21104 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1158,8 +1158,9 @@ Improvements
   `0954dc3fb921 
`_)
 
 - Improved the ``alpha.unix.Stream`` checker by modeling more functions like,
-  ``fflush``, ``fputs``, ``fgetc``, ``fputc``, ``fopen``, ``fopen``, ``fgets``.
-  (`#74296 `_,
+  ``fflush``, ``fputs``, ``fgetc``, ``fputc``, ``fopen``, ``fdopen``, 
``fgets``, ``tmpfile``.
+  (`#76776 `_,
+  `#74296 `_,
   `#73335 `_,
   `#72627 `_,
   `#71518 `_,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 254b36ed03968d..25da3c18e8519f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -239,6 +239,7 @@ class StreamChecker : public Checker FnDescriptions = {
   {{{"fopen"}, 2}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
+  {{{"fdopen"}, 2}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
   {{{"freopen"}, 3},
{&StreamChecker::preFreopen, &StreamChecker::evalFreopen, 2}},
   {{{"tmpfile"}, 0}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index 409a969a0d4cce..8c43c48c6a3e45 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -43,6 +43,7 @@ FILE *funopen(const void *,
   int (*)(void *));
 
 FILE *fopen(const char *restrict path, const char *restrict mode);
+FILE *fdopen(int fd, const char *mode);
 FILE *tmpfile(void);
 FILE *freopen(const char *restrict pathname, const char *restrict mode, FILE 
*restrict stream);
 int fclose(FILE *fp);
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 37e1e54dfc89d5..13c6684b5840af 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -21,6 +21,15 @@ void error_fopen(void) {
   fclose(F);
 }
 
+void error_fdopen(int fd) {
+  FILE *F = fdopen(fd, "r");
+  if (!F)
+return;
+  clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  fclose(F);
+}
+
 void error_freopen(void) {
   FILE *F = fopen("file", "r");
   if (!F)
@@ -146,8 +155,8 @@ void error_fgets(void) {
   fgets(Buf, sizeof(Buf), F); // expected-warning {{Stream might be 
already closed}}
 }
 
-void error_fputc(void) {
-  FILE *F = tmpfile();
+void error_fputc(int fd) {
+  FILE *F = fdopen(fd, "w");
   if (!F)
 return;
   int Ret = fputc('X', F);
diff --git a/clang/test/Analysis/stream-non-posix-function.c 
b/clang/test/Analysis/stream-non-posix-function.c
index c6dc65afe788bb..091d95a573ddf9 100644
--- a/clang/test/Analysis/stream-non-posix-function.c
+++ b/clang/test/Analysis/stream-non-posix-function.c
@@ -8,11 +8,16 @@ typedef struct _FILE FILE;
 // These functions are not standard C library functions.
 FILE *tmpfile(const char *restrict path); // Real 'tmpfile' should have 
exactly 0 formal parameters.
 FILE *fopen(const char *restrict path);   // Real 'fopen' should have exactly 
2 formal parameters.
+FILE *fdopen(int fd); // Real 'fdopen' should have exactly 
2 formal parameters.
 
 void test_fopen_non_posix(void) {
   FILE *fp = fopen("file"); // no-leak: This isn't the standard POSIX `fopen`, 
we don't know the semantics of this call.
 }
 
 void test_tmpfile_non_posix(void) {
-  FILE *fp = tmpfile("file"); // // no-leak: This isn't the standard POSIX 
`tmpfile`, we don't know the semantics

[clang] [clang][analyzer] Support 'fdopen' in the StreamChecker (PR #76776)

2024-01-02 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/76776.diff


8 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+1) 
- (modified) clang/test/Analysis/Inputs/system-header-simulator.h (+1) 
- (modified) clang/test/Analysis/stream-error.c (+11-2) 
- (modified) clang/test/Analysis/stream-non-posix-function.c (+6-1) 
- (modified) clang/test/Analysis/stream-note.c (+10) 
- (modified) clang/test/Analysis/stream-stdlibraryfunctionargs.c (+8) 
- (modified) clang/test/Analysis/stream.c (+7) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8fec691bf3c9..2be7f66c2e8081 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1158,7 +1158,7 @@ Improvements
   `0954dc3fb921 
`_)
 
 - Improved the ``alpha.unix.Stream`` checker by modeling more functions like,
-  ``fflush``, ``fputs``, ``fgetc``, ``fputc``, ``fopen``, ``fopen``, ``fgets``.
+  ``fflush``, ``fputs``, ``fgetc``, ``fputc``, ``fopen``, ``fdopen``, 
``fgets``, ``tmpfile``.
   (`#74296 `_,
   `#73335 `_,
   `#72627 `_,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 254b36ed03968d..25da3c18e8519f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -239,6 +239,7 @@ class StreamChecker : public Checker FnDescriptions = {
   {{{"fopen"}, 2}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
+  {{{"fdopen"}, 2}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
   {{{"freopen"}, 3},
{&StreamChecker::preFreopen, &StreamChecker::evalFreopen, 2}},
   {{{"tmpfile"}, 0}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index 409a969a0d4cce..8c43c48c6a3e45 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -43,6 +43,7 @@ FILE *funopen(const void *,
   int (*)(void *));
 
 FILE *fopen(const char *restrict path, const char *restrict mode);
+FILE *fdopen(int fd, const char *mode);
 FILE *tmpfile(void);
 FILE *freopen(const char *restrict pathname, const char *restrict mode, FILE 
*restrict stream);
 int fclose(FILE *fp);
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 37e1e54dfc89d5..13c6684b5840af 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -21,6 +21,15 @@ void error_fopen(void) {
   fclose(F);
 }
 
+void error_fdopen(int fd) {
+  FILE *F = fdopen(fd, "r");
+  if (!F)
+return;
+  clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  fclose(F);
+}
+
 void error_freopen(void) {
   FILE *F = fopen("file", "r");
   if (!F)
@@ -146,8 +155,8 @@ void error_fgets(void) {
   fgets(Buf, sizeof(Buf), F); // expected-warning {{Stream might be 
already closed}}
 }
 
-void error_fputc(void) {
-  FILE *F = tmpfile();
+void error_fputc(int fd) {
+  FILE *F = fdopen(fd, "w");
   if (!F)
 return;
   int Ret = fputc('X', F);
diff --git a/clang/test/Analysis/stream-non-posix-function.c 
b/clang/test/Analysis/stream-non-posix-function.c
index c6dc65afe788bb..091d95a573ddf9 100644
--- a/clang/test/Analysis/stream-non-posix-function.c
+++ b/clang/test/Analysis/stream-non-posix-function.c
@@ -8,11 +8,16 @@ typedef struct _FILE FILE;
 // These functions are not standard C library functions.
 FILE *tmpfile(const char *restrict path); // Real 'tmpfile' should have 
exactly 0 formal parameters.
 FILE *fopen(const char *restrict path);   // Real 'fopen' should have exactly 
2 formal parameters.
+FILE *fdopen(int fd); // Real 'fdopen' should have exactly 
2 formal parameters.
 
 void test_fopen_non_posix(void) {
   FILE *fp = fopen("file"); // no-leak: This isn't the standard POSIX `fopen`, 
we don't know the semantics of this call.
 }
 
 void test_tmpfile_non_posix(void) {
-  FILE *fp = tmpfile("file"); // // no-leak: This isn't the standard POSIX 
`tmpfile`, we don't know the semantics of this call.
+  FILE *fp = tmpfile("file"); // no-leak: This isn't the standard POSIX 
`tmpfile`, we don't know the semantics of this call.
+}
+
+void test_fdopen_non_posix(int fd) {
+  FILE *fp = fdopen(fd); // no-leak: This isn't the standard POSIX `fdopen`, 
we don't know the semantics of this call.
 }
diff --git a/clang/

[clang] [clang][analyzer] Support 'fdopen' in the StreamChecker (PR #76776)

2024-01-02 Thread Ben Shi via cfe-commits

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/76776

None

>From 8a7caba467e121290d36ad75626ea95ea47b41f2 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 3 Jan 2024 11:30:57 +0800
Subject: [PATCH] [clang][analyzer] Support 'fdopen' in the StreamChecker

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp |  1 +
 .../test/Analysis/Inputs/system-header-simulator.h  |  1 +
 clang/test/Analysis/stream-error.c  | 13 +++--
 clang/test/Analysis/stream-non-posix-function.c |  7 ++-
 clang/test/Analysis/stream-note.c   | 10 ++
 clang/test/Analysis/stream-stdlibraryfunctionargs.c |  8 
 clang/test/Analysis/stream.c|  7 +++
 8 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8fec691bf3c9..2be7f66c2e8081 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1158,7 +1158,7 @@ Improvements
   `0954dc3fb921 
`_)
 
 - Improved the ``alpha.unix.Stream`` checker by modeling more functions like,
-  ``fflush``, ``fputs``, ``fgetc``, ``fputc``, ``fopen``, ``fopen``, ``fgets``.
+  ``fflush``, ``fputs``, ``fgetc``, ``fputc``, ``fopen``, ``fdopen``, 
``fgets``, ``tmpfile``.
   (`#74296 `_,
   `#73335 `_,
   `#72627 `_,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 254b36ed03968d..25da3c18e8519f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -239,6 +239,7 @@ class StreamChecker : public Checker FnDescriptions = {
   {{{"fopen"}, 2}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
+  {{{"fdopen"}, 2}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
   {{{"freopen"}, 3},
{&StreamChecker::preFreopen, &StreamChecker::evalFreopen, 2}},
   {{{"tmpfile"}, 0}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index 409a969a0d4cce..8c43c48c6a3e45 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -43,6 +43,7 @@ FILE *funopen(const void *,
   int (*)(void *));
 
 FILE *fopen(const char *restrict path, const char *restrict mode);
+FILE *fdopen(int fd, const char *mode);
 FILE *tmpfile(void);
 FILE *freopen(const char *restrict pathname, const char *restrict mode, FILE 
*restrict stream);
 int fclose(FILE *fp);
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 37e1e54dfc89d5..13c6684b5840af 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -21,6 +21,15 @@ void error_fopen(void) {
   fclose(F);
 }
 
+void error_fdopen(int fd) {
+  FILE *F = fdopen(fd, "r");
+  if (!F)
+return;
+  clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  fclose(F);
+}
+
 void error_freopen(void) {
   FILE *F = fopen("file", "r");
   if (!F)
@@ -146,8 +155,8 @@ void error_fgets(void) {
   fgets(Buf, sizeof(Buf), F); // expected-warning {{Stream might be 
already closed}}
 }
 
-void error_fputc(void) {
-  FILE *F = tmpfile();
+void error_fputc(int fd) {
+  FILE *F = fdopen(fd, "w");
   if (!F)
 return;
   int Ret = fputc('X', F);
diff --git a/clang/test/Analysis/stream-non-posix-function.c 
b/clang/test/Analysis/stream-non-posix-function.c
index c6dc65afe788bb..091d95a573ddf9 100644
--- a/clang/test/Analysis/stream-non-posix-function.c
+++ b/clang/test/Analysis/stream-non-posix-function.c
@@ -8,11 +8,16 @@ typedef struct _FILE FILE;
 // These functions are not standard C library functions.
 FILE *tmpfile(const char *restrict path); // Real 'tmpfile' should have 
exactly 0 formal parameters.
 FILE *fopen(const char *restrict path);   // Real 'fopen' should have exactly 
2 formal parameters.
+FILE *fdopen(int fd); // Real 'fdopen' should have exactly 
2 formal parameters.
 
 void test_fopen_non_posix(void) {
   FILE *fp = fopen("file"); // no-leak: This isn't the standard POSIX `fopen`, 
we don't know the semantics of this call.
 }
 
 void test_tmpfile_non_posix(void) {
-  FILE *fp = tmpfile("file"); // // no-leak: This isn't the standard POSIX 
`tmpfile`, we don't know the semantics of this call.
+  FILE *fp = tmpfile("file"); // no-leak: This isn't the standard POSIX 
`tmpfile`, we don't know the semantics of this call.
+}
+
+void test_fdopen_non_posix(int fd) {
+  FI

[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)


Changes

The idea comes from @vgvassilev and @vgvassilev had patch for 
it on phab. Unfortunately phab is closed and I forgot the Dxxx number of that 
patch. But I remember the last comment from @vgvassilev is that we 
should use MultiOnDiskHashTable for it. So I followed that and rewrite the 
whole from the scratch in the new year.

### Background

Currently all the specializations of a template (including instantiation, 
specialization and partial specializations)  will be loaded at once if we want 
to instantiate another instance for the template, or find instantiation for the 
template, or just want to complete the redecl chain. 

This means basically we need to load every specializations for the template 
once the template declaration got loaded. This is bad since when we load a 
specialization, we need to load all of its template arguments. Then we have to 
deserialize a lot of unnecessary declarations.

For example,

```
// M.cppm
export module M;
export template 
class A {};

export class ShouldNotBeLoaded {};

export class Temp {
   A AS;
};

// use.cpp
import M;
A a;
```

We should a specialization ` A` in `M.cppm` and we 
instantiate the template `A` in `use.cpp`. Then we will deserialize 
`ShouldNotBeLoaded` surprisingly when compiling `use.cpp`. And this patch tries 
to avoid that.

 Given that the templates are heavily used in C++, this is a pain point for the 
performance.

### What this patch did

This patch adds MultiOnDiskHashTable for specializations in the ASTReader. Then 
we will only deserialize the specializations with the same template arguments. 
We made that by using ODRHash for the template arguments as the key of the hash 
table.

The partial specializations are not added to the MultiOnDiskHashTable. Since we 
can't know if a partial specialization is needed before deciding the template 
declaration for a instantiation request. There may be space for further 
optimizations, but let's do that in the future.

To review this patch, I think `ASTReaderDecl::AddLazySpecializations` may be a 
good entry point. 

### What this patch not did

This patch doesn't solve the problem completely. Since we will add `update` 
specializations if there are new specializations in a different module:
https://github.com/llvm/llvm-project/blob/8ae73fea3a2cbb072bf3e577dc49deb25b56e760/clang/lib/Serialization/ASTWriterDecl.cpp#L251-L269

That said, we can't handle this case now:

```
// M.cppm
export module M;
export template 
class A {};

// N.cppm
export module N;
export import A;
export class ShouldNotBeLoaded {};

export class Temp {
   A AS;
};

// use.cpp
import N;
A a;
```

Now `ShouldNotBeLoaded` will still be loaded.

But the current patch is already relatively big. So I want to split it in the 
next patch. I think the current patch is already self contained.

---

Patch is 53.18 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/76774.diff


20 Files Affected:

- (modified) clang/include/clang/AST/DeclTemplate.h (+41-10) 
- (modified) clang/include/clang/AST/ExternalASTSource.h (+5) 
- (modified) clang/include/clang/AST/ODRHash.h (+3) 
- (modified) clang/include/clang/Sema/MultiplexExternalSemaSource.h (+6) 
- (modified) clang/include/clang/Serialization/ASTBitCodes.h (+3) 
- (modified) clang/include/clang/Serialization/ASTReader.h (+19) 
- (modified) clang/include/clang/Serialization/ASTWriter.h (+6) 
- (modified) clang/lib/AST/DeclTemplate.cpp (+45-21) 
- (modified) clang/lib/AST/ExternalASTSource.cpp (+5) 
- (modified) clang/lib/AST/ODRHash.cpp (+2) 
- (modified) clang/lib/Sema/MultiplexExternalSemaSource.cpp (+6) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+103-6) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+28-5) 
- (modified) clang/lib/Serialization/ASTReaderInternals.h (+80) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+148-1) 
- (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+55-20) 
- (modified) clang/test/Modules/odr_hash.cpp (+2-2) 
- (added) clang/test/Modules/static-member-in-templates.cppm (+52) 
- (modified) clang/unittests/Serialization/CMakeLists.txt (+1) 
- (added) clang/unittests/Serialization/LoadSpecLazily.cpp (+159) 


``diff
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 832ad2de6b08a8..ab380f55c038ee 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -30,6 +30,7 @@
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/iterator.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Casting.h"
@@ -525,8 +526,11 @@ class FunctionTemplateSpecializationInfo final
 return Function.getInt();
   }
 
+

[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-02 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/76774

The idea comes from @vgvassilev and @vgvassilev had patch for it on phab. 
Unfortunately phab is closed and I forgot the Dxxx number of that patch. But I 
remember the last comment from @vgvassilev is that we should use 
MultiOnDiskHashTable for it. So I followed that and rewrite the whole from the 
scratch in the new year.

### Background

Currently all the specializations of a template (including instantiation, 
specialization and partial specializations)  will be loaded at once if we want 
to instantiate another instance for the template, or find instantiation for the 
template, or just want to complete the redecl chain. 

This means basically we need to load every specializations for the template 
once the template declaration got loaded. This is bad since when we load a 
specialization, we need to load all of its template arguments. Then we have to 
deserialize a lot of unnecessary declarations.

For example,

```
// M.cppm
export module M;
export template 
class A {};

export class ShouldNotBeLoaded {};

export class Temp {
   A AS;
};

// use.cpp
import M;
A a;
```

We should a specialization ` A` in `M.cppm` and we 
instantiate the template `A` in `use.cpp`. Then we will deserialize 
`ShouldNotBeLoaded` surprisingly when compiling `use.cpp`. And this patch tries 
to avoid that.

 Given that the templates are heavily used in C++, this is a pain point for the 
performance.

### What this patch did

This patch adds MultiOnDiskHashTable for specializations in the ASTReader. Then 
we will only deserialize the specializations with the same template arguments. 
We made that by using ODRHash for the template arguments as the key of the hash 
table.

The partial specializations are not added to the MultiOnDiskHashTable. Since we 
can't know if a partial specialization is needed before deciding the template 
declaration for a instantiation request. There may be space for further 
optimizations, but let's do that in the future.

To review this patch, I think `ASTReaderDecl::AddLazySpecializations` may be a 
good entry point. 

### What this patch not did

This patch doesn't solve the problem completely. Since we will add `update` 
specializations if there are new specializations in a different module:
https://github.com/llvm/llvm-project/blob/8ae73fea3a2cbb072bf3e577dc49deb25b56e760/clang/lib/Serialization/ASTWriterDecl.cpp#L251-L269

That said, we can't handle this case now:

```
// M.cppm
export module M;
export template 
class A {};

// N.cppm
export module N;
export import A;
export class ShouldNotBeLoaded {};

export class Temp {
   A AS;
};

// use.cpp
import N;
A a;
```

Now `ShouldNotBeLoaded` will still be loaded.

But the current patch is already relatively big. So I want to split it in the 
next patch. I think the current patch is already self contained.

>From f4191661961428a0f534f527774ac3d5159c5103 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Tue, 2 Jan 2024 10:43:03 +0800
Subject: [PATCH] Load Specializations Lazily

---
 clang/include/clang/AST/DeclTemplate.h|  51 --
 clang/include/clang/AST/ExternalASTSource.h   |   5 +
 clang/include/clang/AST/ODRHash.h |   3 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |  19 +++
 clang/include/clang/Serialization/ASTWriter.h |   6 +
 clang/lib/AST/DeclTemplate.cpp|  66 +---
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 clang/lib/AST/ODRHash.cpp |   2 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |   6 +
 clang/lib/Serialization/ASTReader.cpp | 109 +++-
 clang/lib/Serialization/ASTReaderDecl.cpp |  33 +++-
 clang/lib/Serialization/ASTReaderInternals.h  |  80 +
 clang/lib/Serialization/ASTWriter.cpp | 149 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  75 ++---
 clang/test/Modules/odr_hash.cpp   |   4 +-
 .../Modules/static-member-in-templates.cppm   |  52 ++
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazily.cpp  | 159 ++
 20 files changed, 769 insertions(+), 65 deletions(-)
 create mode 100644 clang/test/Modules/static-member-in-templates.cppm
 create mode 100644 clang/unittests/Serialization/LoadSpecLazily.cpp

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 832ad2de6b08a8..ab380f55c038ee 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -30,6 +30,7 @@
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/iterator.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Casting.h"
@@ -525,8 +526,11 @@ class FunctionTemplateSpeci

[clang] [polly] [llvm] [polly][ScheduleOptimizer] Fix long compile time(hang) reported in polly (PR #75141)

2024-01-02 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Pushed revert.

@kartcq please fix the test so it either doesn't depend on DEBUG output, or 
uses `REQUIRES: asserts`.

https://github.com/llvm/llvm-project/pull/75141
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)

2024-01-02 Thread Qizhi Hu via cfe-commits


@@ -1491,6 +1492,12 @@ static bool 
IsRecordContextStructurallyEquivalent(RecordDecl *D1,
 return false;
 }
 
+if (auto *D1Spec = dyn_cast(DC1)) {
+  auto *D2Spec = dyn_cast(DC2);

jcsxky wrote:

Done.

https://github.com/llvm/llvm-project/pull/76226
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [llvm] [clang] [Propeller] Add new flag option '-basic-block-sections=listwithlabels=' to support to use Propeller iteratively. (PR #76497)

2024-01-02 Thread via cfe-commits

lifengxiang1025 wrote:

> Thanks for looking into this. I didn't know you're still working on it. I 
> have a complete PR (including changes to llvm-objdump, llvm-readobj, etc.) 
> ready here : https://github.com/rlavaee/llvm-project/tree/bb-addr-map

@rlavaee  It's ok. This PR doesn't take me long time. As a propeller user, I 
just want to use propeller iteratively as soon as possible. 
So when do you plan to merge your PR?
BTW, there is another question about profiling tool 
https://github.com/google/autofdo/issues/182.


https://github.com/llvm/llvm-project/pull/76497
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2024-01-02 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@iains @dwblaikie ping~

https://github.com/llvm/llvm-project/pull/75894
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-01-02 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@dwblaikie @rjmccall ping~

https://github.com/llvm/llvm-project/pull/75912
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[polly] [llvm] [clang] [polly][ScheduleOptimizer] Fix long compile time(hang) reported in polly (PR #75141)

2024-01-02 Thread Andres Villegas via cfe-commits

avillega wrote:

I think this change might be breaking some of our builds, please revert if 
possible. 
This is the error I am getting:
```
 TEST 'Polly :: ScheduleOptimizer/schedule_computeout.ll' 
FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /b/s/w/ir/x/w/llvm_build/tools/clang/stage2-bins/bin/opt -S 
-polly-optree -polly-delicm  -polly-opt-isl -polly-schedule-computeout=10 
-debug-only="polly-opt-isl" < 
/b/s/w/ir/x/w/llvm-llvm-project/polly/test/ScheduleOptimizer/schedule_computeout.ll
 2>&1 | /b/s/w/ir/x/w/llvm_build/tools/clang/stage2-bins/bin/FileCheck 
/b/s/w/ir/x/w/llvm-llvm-project/polly/test/ScheduleOptimizer/schedule_computeout.ll
+ /b/s/w/ir/x/w/llvm_build/tools/clang/stage2-bins/bin/opt -S -polly-optree 
-polly-delicm -polly-opt-isl -polly-schedule-computeout=10 
-debug-only=polly-opt-isl
+ /b/s/w/ir/x/w/llvm_build/tools/clang/stage2-bins/bin/FileCheck 
/b/s/w/ir/x/w/llvm-llvm-project/polly/test/ScheduleOptimizer/schedule_computeout.ll
/b/s/w/ir/x/w/llvm-llvm-project/polly/test/ScheduleOptimizer/schedule_computeout.ll:94:10:
 error: CHECK: expected string not found in input
; CHECK: Schedule optimizer calculation exceeds ISL quota
 ^
:1:1: note: scanning from here
opt: Unknown command line argument '-debug-only=polly-opt-isl'. Try: 
'/b/s/w/ir/x/w/llvm_build/tools/clang/stage2-bins/bin/opt --help'
^
:2:20: note: possible intended match here
opt: Did you mean '--debug-pass=polly-opt-isl'?
   ^

Input file: 
Check file: 
/b/s/w/ir/x/w/llvm-llvm-project/polly/test/ScheduleOptimizer/schedule_computeout.ll

-dump-input=help explains the following input dump.

Input was:
<<
1: opt: Unknown command line argument '-debug-only=polly-opt-isl'. 
Try: '/b/s/w/ir/x/w/llvm_build/tools/clang/stage2-bins/bin/opt --help' 
check:94'0 
X~~
 error: no match found
2: opt: Did you mean '--debug-pass=polly-opt-isl'? 
check:94'0 
check:94'1? possible 
intended match
>>

--


```

https://github.com/llvm/llvm-project/pull/75141
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][lex] Fix non-portability diagnostics with absolute path (PR #74782)

2024-01-02 Thread Jan Svoboda via cfe-commits

jansvoboda11 wrote:

Thanks for reporting @jrmwng, I'll look into it.

https://github.com/llvm/llvm-project/pull/74782
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)

2024-01-02 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/76226

>From ab1ace9573588153f1e8caf992a6abda3322c6a7 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 22 Dec 2023 17:56:32 +0800
Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve
 StructuralEquivalence on recordType

---
 clang/lib/AST/ASTStructuralEquivalence.cpp| 13 ---
 .../AST/StructuralEquivalenceTest.cpp | 23 +++
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 6bb4bf14b873d7..73b3b2a9524a7b 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1463,8 +1463,9 @@ 
IsStructurallyEquivalentLambdas(StructuralEquivalenceContext &Context,
 }
 
 /// Determine if context of a class is equivalent.
-static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1,
-  RecordDecl *D2) {
+static bool
+IsRecordContextStructurallyEquivalent(StructuralEquivalenceContext &Context,
+  RecordDecl *D1, RecordDecl *D2) {
   // The context should be completely equal, including anonymous and inline
   // namespaces.
   // We compare objects as part of full translation units, not subtrees of
@@ -1491,6 +1492,12 @@ static bool 
IsRecordContextStructurallyEquivalent(RecordDecl *D1,
 return false;
 }
 
+auto *D1Spec = dyn_cast(DC1);
+auto *D2Spec = dyn_cast(DC2);
+if (nullptr != D1Spec && nullptr != D2Spec &&
+!IsStructurallyEquivalent(Context, D1Spec, D2Spec))
+  return false;
+
 DC1 = DC1->getParent()->getNonTransparentContext();
 DC2 = DC2->getParent()->getNonTransparentContext();
   }
@@ -1544,7 +1551,7 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   // If the records occur in different context (namespace), these should be
   // different. This is specially important if the definition of one or both
   // records is missing.
-  if (!IsRecordContextStructurallyEquivalent(D1, D2))
+  if (!IsRecordContextStructurallyEquivalent(Context, D1, D2))
 return false;
 
   // If both declarations are class template specializations, we know
diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 44d950cfe758f1..22c7b82460f0a0 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1024,6 +1024,29 @@ TEST_F(StructuralEquivalenceRecordContextTest, 
TransparentContextInNamespace) {
   EXPECT_TRUE(testStructuralMatch(Decls));
 }
 
+TEST_F(StructuralEquivalenceRecordContextTest,
+   ClassTemplateSpecializationContext) {
+  std::string Code =
+  R"(
+  template  struct O {
+struct M {};
+  };
+  )";
+  auto t = makeDecls(Code + R"(
+  typedef O::M MT1;
+  MT1 A;
+  )",
+  Code + R"(
+  namespace {
+struct I {};
+  } // namespace
+  typedef O::M MT2;
+  MT2 A;
+  )",
+  Lang_CXX11, varDecl(hasName("A")));
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) {
   auto Decls = makeNamedDecls(
   R"(

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


[clang] [clang][lex] Fix non-portability diagnostics with absolute path (PR #74782)

2024-01-02 Thread Jeremy Wong via cfe-commits

jrmwng wrote:

492>Failed Tests (1):
492>  Clang :: Lexer/case-insensitive-include-absolute.c

I built with "clang", "X86" and "AArch64" under Windows 11 and VS2022 community 
edition

```
492>-- Build started: Project: check-all, Configuration: Release x64 --
492>Running all regression tests
492>llvm-lit.py: C:\GitHub\llvm-project\llvm\utils\lit\lit\llvm\config.py:46: 
note: using lit tools: C:\Program Files\Git\usr\bin
492>llvm-lit.py: C:\GitHub\llvm-project\llvm\utils\lit\lit\llvm\config.py:488: 
note: using clang: c:\github\llvm-project\build\release\bin\clang.exe
492>-- Testing: 70944 tests, 32 workers --
492>FAIL: Clang :: Lexer/case-insensitive-include-absolute.c (1 of 70944)
492> TEST 'Clang :: 
Lexer/case-insensitive-include-absolute.c' FAILED 
492>Exit Code: 2
492>
492>Command Output (stdout):
492>--
492># RUN: at line 3
492>rm -rf 
C:\GitHub\llvm-project\build\tools\clang\test\Lexer\Output\case-insensitive-include-absolute.c.tmp
 && split-file 
C:\GitHub\llvm-project\clang\test\Lexer\case-insensitive-include-absolute.c 
C:\GitHub\llvm-project\build\tools\clang\test\Lexer\Output\case-insensitive-include-absolute.c.tmp
492># executed command: rm -rf 
'C:\GitHub\llvm-project\build\tools\clang\test\Lexer\Output\case-insensitive-include-absolute.c.tmp'
492># executed command: split-file 
'C:\GitHub\llvm-project\clang\test\Lexer\case-insensitive-include-absolute.c' 
'C:\GitHub\llvm-project\build\tools\clang\test\Lexer\Output\case-insensitive-include-absolute.c.tmp'
492># RUN: at line 4
492>sed 
"s|DIR|C:/GitHub/llvm-project/build/tools/clang/test/Lexer/Output/case-insensitive-include-absolute.c.tmp|g"
 
C:\GitHub\llvm-project\build\tools\clang\test\Lexer\Output\case-insensitive-include-absolute.c.tmp/tu.c.in
 > 
C:\GitHub\llvm-project\build\tools\clang\test\Lexer\Output\case-insensitive-include-absolute.c.tmp/tu.c
492># executed command: sed 
's|DIR|C:/GitHub/llvm-project/build/tools/clang/test/Lexer/Output/case-insensitive-include-absolute.c.tmp|g'
 
'C:\GitHub\llvm-project\build\tools\clang\test\Lexer\Output\case-insensitive-include-absolute.c.tmp/tu.c.in'
492># RUN: at line 5
492>c:\github\llvm-project\build\release\bin\clang.exe -cc1 -internal-isystem 
F:\GitHub\llvm-project\build\Release\lib\clang\18\include -nostdsysteminc 
-fsyntax-only 
C:\GitHub\llvm-project\build\tools\clang\test\Lexer\Output\case-insensitive-include-absolute.c.tmp/tu.c
 2>&1 | c:\github\llvm-project\build\release\bin\filecheck.exe 
C:\GitHub\llvm-project\clang\test\Lexer\case-insensitive-include-absolute.c 
--DDIR=C:/GitHub/llvm-project/build/tools/clang/test/Lexer/Output/case-insensitive-include-absolute.c.tmp
492># executed command: 'c:\github\llvm-project\build\release\bin\clang.exe' 
-cc1 -internal-isystem 
'F:\GitHub\llvm-project\build\Release\lib\clang\18\include' -nostdsysteminc 
-fsyntax-only 
'C:\GitHub\llvm-project\build\tools\clang\test\Lexer\Output\case-insensitive-include-absolute.c.tmp/tu.c'
492># executed command: 
'c:\github\llvm-project\build\release\bin\filecheck.exe' 
'C:\GitHub\llvm-project\clang\test\Lexer\case-insensitive-include-absolute.c' 
--DDIR=C:/GitHub/llvm-project/build/tools/clang/test/Lexer/Output/case-insensitive-include-absolute.c.tmp
492># .---command stderr
492>CUSTOMBUILD : # | FileCheck error : '' is empty.
492># | FileCheck command line:  
c:\github\llvm-project\build\release\bin\filecheck.exe 
C:\GitHub\llvm-project\clang\test\Lexer\case-insensitive-include-absolute.c 
--DDIR=C:/GitHub/llvm-project/build/tools/clang/test/Lexer/Output/case-insensitive-include-absolute.c.tmp
492># `-
492>CUSTOMBUILD : # error : command failed with exit status: 2
492>
492>--
492>
492>
492>
492>Failed Tests (1):
492>  Clang :: Lexer/case-insensitive-include-absolute.c
492>
492>
492>Testing Time: 434.26s
492>
492>Total Discovered Tests: 92696
492>  Skipped  :90 (0.10%)
492>  Unsupported  : 24219 (26.13%)
492>  Passed   : 68283 (73.66%)
492>  Expectedly Failed:   103 (0.11%)
492>  Failed   : 1 (0.00%)
492>C:\Program Files\Microsoft Visual 
Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5):
 error MSB8066: Custom build for 
'C:\GitHub\llvm-project\build\CMakeFiles\5344a242bf0d5667ee3e0d3564612537\check-all.rule;C:\GitHub\llvm-project\llvm\CMakeLists.txt'
 exited with code 1.
492>Done building project "check-all.vcxproj" -- FAILED.
== Build: 491 succeeded, 1 failed, 55 up-to-date, 0 skipped ==
```

https://github.com/llvm/llvm-project/pull/74782
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [X86] Emit Warnings for frontend options to enable knl/knm. (PR #75580)

2024-01-02 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> I also think we need a policy regarding what test coverage we need for 
> various avx512 features (when should we assume avx512vl etc.)

Considering the new evolution in AVX10, we should switch testing model from 
`avx512xxx ± avx512vl` to `avx512xxx + avx512vl ± 
 evex512`.
I also imagine we can turn any avx512 feature, e.g., `bool hasBWI() {return 
HasBWI;}` into `bool hasBWI() {return HasBWI & HasVLX;}`, then remove all 
`hasVLX` checks in the code, e.g., `Subtarget.hasVLX() && Subtarget.hasBWI()` 
to `Subtarget.hasBWI()`.

> I think if we have an approach that allows people to emulate a very basic 
> KNL/KNM implementation with the equivalent of "-march=x86-64-v3 -mavx512f 
> -mavx512cd" then that would be sufficient.

This will require compiler and tests continue to handle cases avx512f/avx512cd 
without avx512vl. It conflicts with my expectation for `hasVLX` clean up. But 
maybe we can preserve these handling for few features for a short period.

> We should keep asm handling for avx512er/avx512pf/etc but no need for 
> attributes/intrinsics handling for them - if somebody needs to write assembly 
> for them we shouldn't prevent it.

+1

https://github.com/llvm/llvm-project/pull/75580
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu updated 
https://github.com/llvm/llvm-project/pull/76471

>From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 27 Dec 2023 13:05:01 -0500
Subject: [PATCH 01/12] Initial commit

---
 .../ExpandModularHeadersPPCallbacks.cpp   |  2 +-
 clang/include/clang/Frontend/Utils.h  |  4 +-
 clang/lib/Frontend/CompilerInstance.cpp   |  2 +-
 clang/lib/Frontend/InitPreprocessor.cpp   | 12 ++--
 compiler-rt/include/CMakeLists.txt|  1 +
 .../include/profile/instr_prof_interface.h| 66 +++
 compiler-rt/lib/profile/InstrProfiling.h  | 32 +
 7 files changed, 83 insertions(+), 36 deletions(-)
 create mode 100644 compiler-rt/include/profile/instr_prof_interface.h

diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index e414ac8c770508..5ecd4fb19131e4 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -100,7 +100,7 @@ 
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
   /*OwnsHeaderSearch=*/false);
   PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
   InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
- Compiler.getFrontendOpts());
+ Compiler.getFrontendOpts(), 
Compiler.getCodeGenOpts());
   ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts,
Compiler.getTarget().getTriple());
 }
diff --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 143cf4359f00b5..604e42067a3f1e 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -43,12 +43,14 @@ class PCHContainerReader;
 class Preprocessor;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
+class CodeGenOptions;
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
 void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions 
&PPOpts,
 const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts);
+const FrontendOptions &FEOpts,
+const CodeGenOptions &CodeGenOpts);
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 56bbef9697b650..ea44a26b6db7da 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -470,7 +470,7 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Predefine macros and configure the preprocessor.
   InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
- getFrontendOpts());
+ getFrontendOpts(), getCodeGenOpts());
 
   // Initialize the header search object.  In CUDA compilations, we use the aux
   // triple (the host triple) to initialize our header search, since we need to
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index d83128adb511ef..009a67eea1eb52 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
-void clang::InitializePreprocessor(
-Preprocessor &PP, const PreprocessorOptions &InitOpts,
-const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts) {
+void clang::InitializePreprocessor(Preprocessor &PP,
+   const PreprocessorOptions &InitOpts,
+   const PCHContainerReader &PCHContainerRdr,
+   const FrontendOptions &FEOpts,
+   const CodeGenOptions &CodeGenOpts) {
   const LangOptions &LangOpts = PP.getLangOpts();
   std::string PredefineBuffer;
   PredefineBuffer.reserve(4080);
@@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor(
   InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(),
  FEOpts, Builder);
 
+  if (CodeGenOpts.hasProfileIRInstr())
+Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE");
+
   // Add on the predefines from the driver.  Wrap in a #line directive to 
report
   // that they come from the command line.
   Builder.append("# 1 \"\" 1");
diff --git a/compiler-rt/include/CMakeLists.txt 
b/compiler-rt/include/CMakeLists.txt
ind

[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Qiongsi Wu via cfe-commits


@@ -0,0 +1,38 @@
+// RUN: %clang_profgen %s --target=ppc64le-unknown-linux-gnu -S \
+// RUN:-emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN
+// RUN: %clang_profgen -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t

qiongsiwu wrote:

Ah thanks for the proposal! 

We still want to keep this test working for both BE and LE because we want this 
test to run on AIX as well. In its current shape, the test passes on AIX. If it 
is fine, given [this 
comment](https://github.com/llvm/llvm-project/pull/76471#issuecomment-1874671580),
 I can be a bit speculative and let the buildbot alert me if this test is 
failing on Linux ppc BE. 

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Qiongsi Wu via cfe-commits


@@ -0,0 +1,16 @@
+// Test the linker feature that treats undefined weak symbols as null values.
+
+// RUN: %clang_pgogen -o %t %s

qiongsiwu wrote:

Ah no worries! I actually tried running this on AIX and the test is 
unsupported. I think compiler-rt 
[checks](https://github.com/llvm/llvm-project/blob/d933b88b71b00461815667d7cd0bb2fecd8606db/compiler-rt/test/profile/Linux/lit.local.cfg.py#L45)
 to see if the host is Linux before running the tests in the `Linux` folder. 

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [TargetParser] Define AEK_FCMA and AEK_JSCVT for tsv110 (PR #75516)

2024-01-02 Thread Qi Hu via cfe-commits

https://github.com/Qi-Hu updated https://github.com/llvm/llvm-project/pull/75516

>From c7334de4f54ebd7755827c35a09c8a63743027ec Mon Sep 17 00:00:00 2001
From: Qi Hu 
Date: Thu, 14 Dec 2023 13:35:52 -0500
Subject: [PATCH] [TargetParser] Define AEK_FCMA and AEK_JSCVT for tsv110

We define AEK_JSCVT and AEK_FCMA for CPU features FEAT_JSCVT and FEAT_FCMA
respectively, and add them to the CpuInfo of tsv110.
---
 clang/test/CodeGen/aarch64-targetattr.c   |  12 +-
 .../Preprocessor/aarch64-target-features.c|  10 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |  11 +-
 llvm/lib/Target/AArch64/AArch64.td|   3 +-
 .../TargetParser/TargetParserTest.cpp | 105 ++
 5 files changed, 81 insertions(+), 60 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-targetattr.c 
b/clang/test/CodeGen/aarch64-targetattr.c
index 9664b723a2b2cd..1693b6ff3b853c 100644
--- a/clang/test/CodeGen/aarch64-targetattr.c
+++ b/clang/test/CodeGen/aarch64-targetattr.c
@@ -97,19 +97,19 @@ void minusarch() {}
 // CHECK: attributes #0 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" }
 // CHECK: attributes #1 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a"
 }
 // CHECK: attributes #2 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a"
 }
-// CHECK: attributes #3 = { {{.*}} 
"target-features"="+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
-// CHECK: attributes #4 = { {{.*}} "target-cpu"="cortex-a710" 
"target-features"="+bf16,+crc,+dotprod,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+mte,+neon,+pauth,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm"
 }
+// CHECK: attributes #3 = { {{.*}} 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+jsconv,+lse,+neon,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
+// CHECK: attributes #4 = { {{.*}} "target-cpu"="cortex-a710" 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+mte,+neon,+pauth,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm"
 }
 // CHECK: attributes #5 = { {{.*}} "tune-cpu"="cortex-a710" }
 // CHECK: attributes #6 = { {{.*}} "target-cpu"="generic" }
 // CHECK: attributes #7 = { {{.*}} "tune-cpu"="generic" }
 // CHECK: attributes #8 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+crc,+dotprod,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs"
 "tune-cpu"="cortex-a710" }
 // CHECK: attributes #9 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve" "tune-cpu"="cortex-a710" }
-// CHECK: attributes #10 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2"
 }
-// CHECK: attributes #11 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,-sve"
 }
+// CHECK: attributes #10 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2"
 }
+// CHECK: attributes #11 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,-sve"
 }
 // CHECK: attributes #12 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve" }
 // CHECK: attributes #13 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve,-sve2" }
 // CHECK: attributes #14 = { {{.*}} "target-features"="+fullfp16" }
-// CHECK: attributes #15 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
-// CHECK: attributes #16 = { {{.*}} "branch-target-enforcement"="true" {{.*}} 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
+// CHECK: attributes #15 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+jsconv,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
+// CHECK: attributes #16 = { {{.*}} "branch-target-enforcement"="true" {{.*}} 
"target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+jsconv,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a

[clang] [-Wunsafe-buffer-usage] Warning for unsafe invocation of span::data (PR #75650)

2024-01-02 Thread Malavika Samak via cfe-commits

https://github.com/malavikasamak closed 
https://github.com/llvm/llvm-project/pull/75650
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7122f55 - [-Wunsafe-buffer-usage] Warning for unsafe invocation of span::data (#75650)

2024-01-02 Thread via cfe-commits

Author: Malavika Samak
Date: 2024-01-02T15:41:00-08:00
New Revision: 7122f55c639a00e719b6088249f4fca1810cf04c

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

LOG: [-Wunsafe-buffer-usage] Warning for unsafe invocation of span::data 
(#75650)

…-Wunsafe-buffer-usage,

there maybe accidental re-introduction of new OutOfBound accesses into
the code bases. One such case is invoking span::data() method on a span
variable to retrieve a pointer, which is then cast to a larger type and
dereferenced. Such dereferences can introduce OutOfBound accesses.

To address this, a new WarningGadget is being introduced to warn against
such invocations.

-

Co-authored-by: MalavikaSamak 

Added: 
clang/test/SemaCXX/warn-unsafe-buffer-usage-warning-data-invocation.cpp

Modified: 
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index 8a2d56668e32f9..b28f2c6b99c50e 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -66,7 +66,7 @@ class UnsafeBufferUsageHandler {
 
   /// Invoked when an unsafe operation over raw pointers is found.
   virtual void handleUnsafeOperation(const Stmt *Operation,
- bool IsRelatedToDecl) = 0;
+ bool IsRelatedToDecl, ASTContext &Ctx) = 
0;
 
   /// Invoked when a fix is suggested against a variable. This function groups
   /// all variables that must be fixed together (i.e their types must be 
changed

diff  --git 
a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index 757ee452ced748..c9766168836510 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -30,6 +30,7 @@ WARNING_GADGET(Decrement)
 WARNING_GADGET(ArraySubscript)
 WARNING_GADGET(PointerArithmetic)
 WARNING_GADGET(UnsafeBufferUsageAttr)
+WARNING_GADGET(DataInvocation)
 FIXABLE_GADGET(ULCArraySubscript)  // `DRE[any]` in an Unspecified 
Lvalue Context
 FIXABLE_GADGET(DerefSimplePtrArithFixable)
 FIXABLE_GADGET(PointerDereference)

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index aebb7d9b945c33..e54f969c19039d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12064,7 +12064,7 @@ def warn_unsafe_buffer_variable : Warning<
   InGroup, DefaultIgnore;
 def warn_unsafe_buffer_operation : Warning<
   "%select{unsafe pointer operation|unsafe pointer arithmetic|"
-  "unsafe buffer access|function introduces unsafe buffer manipulation}0">,
+  "unsafe buffer access|function introduces unsafe buffer manipulation|unsafe 
invocation of span::data}0">,
   InGroup, DefaultIgnore;
 def note_unsafe_buffer_operation : Note<
   "used%select{| in pointer arithmetic| in buffer access}0 here">;

diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 70eec1cee57f8e..724c4304a07242 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -721,6 +721,34 @@ class UnsafeBufferUsageAttrGadget : public WarningGadget {
   DeclUseList getClaimedVarUseSites() const override { return {}; }
 };
 
+// Warning gadget for unsafe invocation of span::data method.
+// Triggers when the pointer returned by the invocation is immediately
+// cast to a larger type.
+
+class DataInvocationGadget : public WarningGadget {
+  constexpr static const char *const OpTag = "data_invocation_expr";
+  const ExplicitCastExpr *Op;
+
+public:
+  DataInvocationGadget(const MatchFinder::MatchResult &Result)
+  : WarningGadget(Kind::DataInvocation),
+Op(Result.Nodes.getNodeAs(OpTag)) {}
+
+  static bool classof(const Gadget *G) {
+return G->getKind() == Kind::DataInvocation;
+  }
+
+  static Matcher matcher() {
+return stmt(
+explicitCastExpr(has(cxxMemberCallExpr(callee(cxxMethodDecl(
+ hasName("data"), 
ofClass(hasName("std::span")))
+.bind(OpTag));
+  }
+  const Stmt *getBaseStmt() const override { return Op; }
+
+  DeclUseList getClaimedVarUseSites() const override { return {}; }
+};
+
 // Represents expressions of the form `DRE[*]` in the U

[clang] [-Wunsafe-buffer-usage] Warning for unsafe invocation of span::data (PR #75650)

2024-01-02 Thread Malavika Samak via cfe-commits

https://github.com/malavikasamak edited 
https://github.com/llvm/llvm-project/pull/75650
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

2024-01-02 Thread Jordan R AW via cfe-commits

ajordanr-google wrote:

All CI runs are failing on unrelated tests... can we re-run the CI again in a 
week or so?

https://github.com/llvm/llvm-project/pull/74791
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang-tools-extra] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Mingming Liu via cfe-commits

minglotus-6 wrote:

> > thanks! Mostly lg with a pending discussion on whether we want to have test 
> > coverage for `clang_pgogen` in `compiler-rt/test/profile/instrprof-api.c`, 
> > and the open-ended discussion about the observed build failure in another 
> > compiler-rt test.
> 
> Thanks for the feedback! The latest commit aims at resolving all comments but 
> the one related to the BE failure case. I will look into the BE related 
> failure next.

Actually most compiler-rt test doesn't encounter the build failure as the 
specific test (`instrprof-thinlto-indirect-call-promotion.cpp`) does. I now 
begin to wonder if it has something to do with the fact that that affected test 
is C++ (intentionally not pure C to have mangled names)..

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [TargetParser] Define AEK_FCMA and AEK_JSCVT for tsv110 (PR #75516)

2024-01-02 Thread Qi Hu via cfe-commits


@@ -81,6 +81,15 @@ static bool DecodeAArch64Features(const Driver &D, StringRef 
text,
 else
   return false;
 
+// +jsconv and +complxnum implies +neon and +fp-armv8

Qi-Hu wrote:

I have made some changes and included AEK_JSCVT and AEK_FCMA in Armv8.3-A. 
Could you please review it again? @davemgreen @momchil-velikov Thanks!

https://github.com/llvm/llvm-project/pull/75516
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Mingming Liu via cfe-commits


@@ -0,0 +1,16 @@
+// Test the linker feature that treats undefined weak symbols as null values.
+
+// RUN: %clang_pgogen -o %t %s

minglotus-6 wrote:

Please discard this comment. 

@snehasish pointed out build-bots doesn't really have coverage of AIX linker, 
and the executable returns 1 if weak symbol is not null.

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang-tools-extra] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Mingming Liu via cfe-commits


@@ -0,0 +1,38 @@
+// RUN: %clang_profgen %s --target=ppc64le-unknown-linux-gnu -S \
+// RUN:-emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN
+// RUN: %clang_profgen -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t

minglotus-6 wrote:

> I don't have access to a BE machine at the moment to reproduce but I will go 
> find one and take a look.

Or maybe just add `REQUIRES: host-byteorder-little-endian` if this test passes 
on little-endian systems. 

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang-tools-extra] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 commented:

thanks for making the changes!

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Mingming Liu via cfe-commits


@@ -0,0 +1,16 @@
+// Test the linker feature that treats undefined weak symbols as null values.
+
+// RUN: %clang_pgogen -o %t %s

minglotus-6 wrote:

This just occurred to me, if the tested feature relies on linker 
implementation, does it need `REQUIRES: ` so that `not %t` passes? 

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Mingming Liu via cfe-commits

https://github.com/minglotus-6 edited 
https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Qiongsi Wu via cfe-commits

qiongsiwu wrote:

> thanks! Mostly lg with a pending discussion on whether we want to have test 
> coverage for `clang_pgogen` in `compiler-rt/test/profile/instrprof-api.c`, 
> and the open-ended discussion about the observed build failure in another 
> compiler-rt test.

Thanks for the feedback! The latest commit aims at resolving most of the 
comments. I will look into the BE related failure. 

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Qiongsi Wu via cfe-commits


@@ -0,0 +1,38 @@
+// RUN: %clang_profgen %s --target=ppc64le-unknown-linux-gnu -S \
+// RUN:-emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN
+// RUN: %clang_profgen -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t

qiongsiwu wrote:

> Relatedly, I do get compilation errors on ppc big-endian systems for 
> clang_pgogen in another compiler-rt test 
> ([commit](https://github.com/llvm/llvm-project/commit/5136c167a2573fbd05179849cb41b198c4862b12)
>  and [buildbot 
> link](https://lab.llvm.org/buildbot/#/builders/18/builds/13228))

> From the error message, I think lack of ABI implementation should manifest 
> whether it's clang_pgogen or clang_profgen.

Hmmm thanks for pointing this out! I don't have access to a BE machine at the 
moment to reproduce but I will go find one and take a look. 

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Qiongsi Wu via cfe-commits


@@ -0,0 +1,38 @@
+// RUN: %clang_profgen %s --target=ppc64le-unknown-linux-gnu -S \
+// RUN:-emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN
+// RUN: %clang_profgen -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t

qiongsiwu wrote:

> Nevertheless, I wonder test coverage for %clang_pgogen should be added here 
> as well.

Ah good catch! Thanks! I had missed that. The `%clang_pgogen` tests are added.

> Good point, can we drop the `--target=ppc64le-unknown-linux-gnu` flag? It 
> shouldn't make a difference to what we want to test here.

Sounds good! The test is revised to avoid any target specific flags.

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [lldb] [polly] [compiler-rt] [libc] [clang] [libcxx] [mlir] [llvm] [libcxxabi] [clang-tools-extra] [flang] Make clang report invalid target versions. (PR #75373)

2024-01-02 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/75373

>From 74f256d8a77ee2ba8e0d5bbb6519aa2729cf94d5 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 01/11] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 llvm/lib/TargetParser/Triple.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index c5e9ad43d22588..335253194d1cf8 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/ARMTargetParser.h"
@@ -1199,7 +1200,11 @@ StringRef Triple::getOSAndEnvironmentName() const {
 
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
-  Version.tryParse(Name);
+  if (Version.tryParse(Name)) {
+errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
+"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+exit(1);
+  }
   return Version.withoutBuild();
 }
 

>From 0d159b2a9b76e233e020ac0aef15b49b03f4d86c Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:23:54 +
Subject: [PATCH 02/11] rephrase

---
 llvm/lib/TargetParser/Triple.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 335253194d1cf8..713ca447403d50 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1201,8 +1201,7 @@ StringRef Triple::getOSAndEnvironmentName() const {
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
   if (Version.tryParse(Name)) {
-errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
-"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+errs() << "version "<< Name << " is invalid\n";
 exit(1);
   }
   return Version.withoutBuild();

>From b2dda9ce95804783c59aa1ca4e81a7941aae805d Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 03/11] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 clang/lib/Basic/Targets/OSTargets.h | 5 +
 llvm/include/llvm/TargetParser/Triple.h | 4 
 llvm/lib/TargetParser/Triple.cpp| 8 
 3 files changed, 17 insertions(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 342af4bbc42b7b..bc28066019971c 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -323,6 +323,11 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
 // This historical but ambiguous name for the minSdkVersion macro. Keep
 // defined for compatibility.
 Builder.defineMacro("__ANDROID_API__", "__ANDROID_MIN_SDK_VERSION__");
+  } else {
+llvm::errs() << "version "<< Triple.getVersionName() <<
+" in triple " << Triple.getArchName() << "-" << Triple.getVendorName()
+<< "-" << Triple.getOSAndEnvironmentName() << " is invalid\n";
+exit(1);
   }
 } else {
 Builder.defineMacro("__gnu_linux__");
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 47904621c0967f..05df1c489ad06e 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -434,6 +434,10 @@ class Triple {
   /// string (separated by a '-' if the environment component is present).
   StringRef getOSAndEnvironmentName() const;
 
+  /// Get the version component of the environment component as a single
+  /// string (the version after the environment).
+  StringRef getVersionName() const;
+
   /// @}
   /// @name Convenience Predicates
   /// @{
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 49bc24ffbfae6c..db4ba7100781bc 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1199,6 +1199,14 @@ StringRef Triple::getOSAndEnvironmentName() const {
   return Tmp.split('-').second;  // Strip second component
 }
 
+StringRef Triple::getVersionName() const {
+  StringRef VersionName = getEnvironmentName();
+  StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
+  if (VersionName.startswith(EnvironmentTypeName))
+return VersionName.substr(EnvironmentTypeName.size());
+  return VersionName;
+}
+
 static 

[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Qiongsi Wu via cfe-commits




qiongsiwu wrote:

Comments added.

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Qiongsi Wu via cfe-commits


@@ -0,0 +1,92 @@
+/*=== instr_prof_interface.h - Instrumentation PGO User Program API ===
+ *
+ * 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
+ *
+ *===---===
+ *
+ * This header provides a public interface for fine-grained control of counter
+ * reset and profile dumping. These interface functions can be directly called
+ * in user programs.
+ *
+\*===-===*/
+
+#ifndef COMPILER_RT_INSTR_PROFILING
+#define COMPILER_RT_INSTR_PROFILING
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __LLVM_INSTR_PROFILE_GENERATE
+// Profile file reset and dump interfaces.
+// When `-fprofile[-instr]-generate`/`-fcs-profile-generate` is in effect,
+// clang defines __LLVM_INSTR_PROFILE_GENERATE to pick up the API calls.
+
+/*!
+ * \brief Set the filename for writing instrumentation data.
+ *
+ * Sets the filename to be used for subsequent calls to
+ * \a __llvm_profile_write_file().
+ *
+ * \c Name is not copied, so it must remain valid.  Passing NULL resets the
+ * filename logic to the default behaviour.
+ *
+ * Note: There may be multiple copies of the profile runtime (one for each
+ * instrumented image/DSO). This API only modifies the filename within the
+ * copy of the runtime available to the calling image.
+ *
+ * Warning: This is a no-op if continuous mode (\ref
+ * __llvm_profile_is_continuous_mode_enabled) is on. The reason for this is
+ * that in continuous mode, profile counters are mmap()'d to the profile at
+ * program initialization time. Support for transferring the mmap'd profile
+ * counts to a new file has not been implemented.
+ */
+void __llvm_profile_set_filename(const char *Name);
+
+/*!
+ * \brief Interface to set all PGO counters to zero for the current process.
+ *
+ */
+void __llvm_profile_reset_counters(void);
+
+/*!
+ * \brief this is a wrapper interface to \c __llvm_profile_write_file.
+ * After this interface is invoked, an already dumped flag will be set
+ * so that profile won't be dumped again during program exit.
+ * Invocation of interface __llvm_profile_reset_counters will clear
+ * the flag. This interface is designed to be used to collect profile
+ * data from user selected hot regions. The use model is
+ *  __llvm_profile_reset_counters();
+ *  ... hot region 1
+ *  __llvm_profile_dump();
+ *  .. some other code
+ *  __llvm_profile_reset_counters();
+ *  ... hot region 2
+ *  __llvm_profile_dump();
+ *
+ *  It is expected that on-line profile merging is on with \c %m specifier
+ *  used in profile filename . If merging is  not turned on, user is expected
+ *  to invoke __llvm_profile_set_filename  to specify different profile names

qiongsiwu wrote:

Ah thanks for pointing them out! Fixed.

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu updated 
https://github.com/llvm/llvm-project/pull/76471

>From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 27 Dec 2023 13:05:01 -0500
Subject: [PATCH 01/11] Initial commit

---
 .../ExpandModularHeadersPPCallbacks.cpp   |  2 +-
 clang/include/clang/Frontend/Utils.h  |  4 +-
 clang/lib/Frontend/CompilerInstance.cpp   |  2 +-
 clang/lib/Frontend/InitPreprocessor.cpp   | 12 ++--
 compiler-rt/include/CMakeLists.txt|  1 +
 .../include/profile/instr_prof_interface.h| 66 +++
 compiler-rt/lib/profile/InstrProfiling.h  | 32 +
 7 files changed, 83 insertions(+), 36 deletions(-)
 create mode 100644 compiler-rt/include/profile/instr_prof_interface.h

diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index e414ac8c770508..5ecd4fb19131e4 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -100,7 +100,7 @@ 
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
   /*OwnsHeaderSearch=*/false);
   PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
   InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
- Compiler.getFrontendOpts());
+ Compiler.getFrontendOpts(), 
Compiler.getCodeGenOpts());
   ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts,
Compiler.getTarget().getTriple());
 }
diff --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 143cf4359f00b5..604e42067a3f1e 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -43,12 +43,14 @@ class PCHContainerReader;
 class Preprocessor;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
+class CodeGenOptions;
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
 void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions 
&PPOpts,
 const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts);
+const FrontendOptions &FEOpts,
+const CodeGenOptions &CodeGenOpts);
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 56bbef9697b650..ea44a26b6db7da 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -470,7 +470,7 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Predefine macros and configure the preprocessor.
   InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
- getFrontendOpts());
+ getFrontendOpts(), getCodeGenOpts());
 
   // Initialize the header search object.  In CUDA compilations, we use the aux
   // triple (the host triple) to initialize our header search, since we need to
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index d83128adb511ef..009a67eea1eb52 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
-void clang::InitializePreprocessor(
-Preprocessor &PP, const PreprocessorOptions &InitOpts,
-const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts) {
+void clang::InitializePreprocessor(Preprocessor &PP,
+   const PreprocessorOptions &InitOpts,
+   const PCHContainerReader &PCHContainerRdr,
+   const FrontendOptions &FEOpts,
+   const CodeGenOptions &CodeGenOpts) {
   const LangOptions &LangOpts = PP.getLangOpts();
   std::string PredefineBuffer;
   PredefineBuffer.reserve(4080);
@@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor(
   InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(),
  FEOpts, Builder);
 
+  if (CodeGenOpts.hasProfileIRInstr())
+Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE");
+
   // Add on the predefines from the driver.  Wrap in a #line directive to 
report
   // that they come from the command line.
   Builder.append("# 1 \"\" 1");
diff --git a/compiler-rt/include/CMakeLists.txt 
b/compiler-rt/include/CMakeLists.txt
ind

[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

2024-01-02 Thread David Goldman via cfe-commits

https://github.com/DavidGoldman updated 
https://github.com/llvm/llvm-project/pull/76466

>From 4caf5b3c779bf18236b4b0be5bc7147d10339f2b Mon Sep 17 00:00:00 2001
From: David Goldman 
Date: Tue, 26 Dec 2023 15:59:01 -0500
Subject: [PATCH 1/7] [clangd][SymbolCollector] Treat ObjC methods as spelled

We'll treat multi-arg methods as spelled once we have full rename
support for them.
---
 .../clangd/index/SymbolCollector.cpp  |  6 ++-
 .../clangd/unittests/SymbolCollectorTests.cpp | 42 +++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 7ef4b15febad22..336bc3506bb360 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -174,7 +174,9 @@ bool isSpelled(SourceLocation Loc, const NamedDecl &ND) {
   auto Name = ND.getDeclName();
   const auto NameKind = Name.getNameKind();
   if (NameKind != DeclarationName::Identifier &&
-  NameKind != DeclarationName::CXXConstructorName)
+  NameKind != DeclarationName::CXXConstructorName &&
+  NameKind != DeclarationName::ObjCZeroArgSelector &&
+  NameKind != DeclarationName::ObjCOneArgSelector)
 return false;
   const auto &AST = ND.getASTContext();
   const auto &SM = AST.getSourceManager();
@@ -183,6 +185,8 @@ bool isSpelled(SourceLocation Loc, const NamedDecl &ND) {
   if (clang::Lexer::getRawToken(Loc, Tok, SM, LO))
 return false;
   auto StrName = Name.getAsString();
+  if (const auto *MD = dyn_cast(&ND))
+StrName = MD->getSelector().getNameForSlot(0).str();
   return clang::Lexer::getSpelling(Tok, SM, LO) == StrName;
 }
 } // namespace
diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 9cdc57ec01f327..1d4e1c1d75ea23 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -105,6 +105,9 @@ MATCHER(refRange, "") {
 MATCHER_P2(OverriddenBy, Subject, Object, "") {
   return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID};
 }
+MATCHER(isSpelled, "") {
+  return static_cast(arg.Kind & RefKind::Spelled);
+}
 ::testing::Matcher &>
 haveRanges(const std::vector Ranges) {
   return ::testing::UnorderedPointwise(refRange(), Ranges);
@@ -524,6 +527,45 @@ TEST_F(SymbolCollectorTest, templateArgs) {
  forCodeCompletion(false);
 }
 
+TEST_F(SymbolCollectorTest, ObjCRefs) {
+  Annotations Header(R"(
+  @interface Person
+  - (void)$talk[[talk]];
+  - (void)$say[[say]]:(id)something;
+  @end
+  @interface Person (Category)
+  - (void)categoryMethod;
+  - (void)multiArg:(id)a method:(id)b;
+  @end
+  )");
+  Annotations Main(R"(
+  @implementation Person
+  - (void)$talk[[talk]] {}
+  - (void)$say[[say]]:(id)something {}
+  @end
+
+  void fff(Person *p) {
+[p $talk[[talk]]];
+[p $say[[say]]:0];
+[p categoryMethod];
+[p multiArg:0 method:0];
+  }
+  )");
+  CollectorOpts.RefFilter = RefKind::All;
+  CollectorOpts.CollectMainFileRefs = true;
+  TestFileName = testPath("test.m");
+  runSymbolCollector(Header.code(), Main.code(),
+ {"-fblocks", "-xobjective-c++", "-Wno-objc-root-class"});
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::talk").ID,
+  haveRanges(Main.ranges("talk");
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
+  haveRanges(Main.ranges("say");
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::categoryMethod").ID,
+  ElementsAre(isSpelled();
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::multiArg:method:").ID,
+  ElementsAre(Not(isSpelled());
+}
+
 TEST_F(SymbolCollectorTest, ObjCSymbols) {
   const std::string Header = R"(
 @interface Person

>From 1b6a09464ff5c7b1988fcb479d0a4ff876f696e6 Mon Sep 17 00:00:00 2001
From: David Goldman 
Date: Tue, 26 Dec 2023 16:12:03 -0500
Subject: [PATCH 2/7] Run clang-format

---
 .../clangd/unittests/SymbolCollectorTests.cpp  | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 1d4e1c1d75ea23..5c20b950e4eac0 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -560,10 +560,12 @@ TEST_F(SymbolCollectorTest, ObjCRefs) {
   haveRanges(Main.ranges("talk");
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
   haveRanges(Main.ranges("say");
-  EXPECT_THAT(Refs, Contains(Pair(findSymbol

[libcxx] [compiler-rt] [llvm] [flang] [lld] [clang-tools-extra] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,104 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// std::enumerate_viewdifference_type;
+// std::enumerate_viewvalue_type;
+// std::enumerate_viewiterator_category;
+// std::enumerate_viewiterator_concept;
+
+#include 
+
+#include 
+#include "test_iterators.h"
+#include "../types.h"
+
+template 
+concept HasIteratorCategory = requires { typename T::iterator_category; };
+
+template 
+using EnumerateViewFor = std::ranges::enumerate_view< MinimalView>>;
+
+template 
+using EnumerateIteratorFor = 
std::ranges::iterator_t>;
+
+struct ForwardIteratorWithInputCategory {
+  using difference_type   = int;
+  using value_type= int;
+  using iterator_category = std::input_iterator_tag;
+  using iterator_concept  = std::forward_iterator_tag;
+  ForwardIteratorWithInputCategory();
+  ForwardIteratorWithInputCategory& operator++();
+  ForwardIteratorWithInputCategory operator++(int);
+  int& operator*() const;
+  friend bool operator==(ForwardIteratorWithInputCategory, 
ForwardIteratorWithInputCategory);
+};
+static_assert(std::forward_iterator);
+
+constexpr void test() {
+  // Check that value_type is range_value_t and difference_type is 
range_difference_t
+  {
+auto test = [] {
+  using EnumerateView = EnumerateViewFor;
+  using EnumerateIterator = EnumerateIteratorFor;
+  static_assert(std::is_same_v>);
+  static_assert(
+  std::is_same_v>);
+};
+test.operator()>();
+test.operator()>();
+test.operator()>();
+test.operator()>();
+test.operator()>();
+test.operator()>();
+test.operator()();

cjdb wrote:

Please turn `test` into a function template instead of a lambda template. It 
lends itself to a nicer syntax.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [libcxx] [clang-tools-extra] [compiler-rt] [lld] [flang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,77 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// constexpr auto operator[](difference_type n) const
+//   requires random_access_range;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+
+template 
+concept HasSubscriptOperator = requires(T t, U u) { t[u]; };
+
+template 
+using EnumerateIterator = 
std::ranges::iterator_t>;
+
+using RandomAccessRange = std::ranges::subrange;
+static_assert(std::ranges::random_access_range);
+
+static_assert(HasSubscriptOperator, int>);
+
+using BidirectionalRange = std::ranges::subrange>;
+static_assert(!std::ranges::random_access_range);
+
+static_assert(!HasSubscriptOperator, 
int>);
+
+constexpr bool test() {
+  // Reference
+  {
+std::array ts = {0, 1, 2, 3, 84};
+auto view = ts | std::views::enumerate;
+auto it   = view.begin();
+
+for (std::size_t index = 0; index != ts.size(); ++index) {
+  assert(it[index] == *(it + index));
+}
+
+static_assert(std::is_same_v>);
+  }
+
+  // Value
+  {
+auto view = std::views::iota(0, 5) | std::views::enumerate;
+auto it   = view.begin();
+
+for (std::size_t index = 0; index != 5; ++index) {
+  assert(it[index] == *(it + index));
+}
+
+static_assert(std::is_same_v>);

cjdb wrote:

Consider using `std::iter_difference_t`.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [clang-tools-extra] [flang] [compiler-rt] [llvm] [clang] [lld] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,95 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// constexpr difference_type index() const noexcept;
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "test_macros.h"
+#include "../types.h"
+
+template >
+constexpr void test() {
+  using View  = MinimalView;
+  using EnumerateView = std::ranges::enumerate_view;
+
+  std::array array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+
+  View view{Iterator(array.begin()), Sentinel(Iterator(array.end()))};
+  EnumerateView ev(std::move(view));
+
+  {
+auto it = ev.begin();
+ASSERT_NOEXCEPT(it.index());
+
+static_assert(std::same_as);
+for (std::size_t index = 0; index < array.size(); ++index) {
+  assert(std::cmp_equal(index, it.index()));
+
+  ++it;
+}

cjdb wrote:

Please hand-roll.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [compiler-rt] [clang] [flang] [lld] [llvm] [libcxx] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,75 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// friend constexpr auto iter_move(const iterator& i)
+//   noexcept(noexcept(ranges::iter_move(i.current_)) &&
+// 
is_nothrow_move_constructible_v>);
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "../types.h"
+
+template 
+constexpr void test() {
+  using Sentinel  = sentinel_wrapper;
+  using View  = MinimalView;
+  using EnumerateView = std::ranges::enumerate_view;
+  using EnumerateIterator = std::ranges::iterator_t;
+
+  std::array array{0, 1, 2, 3, 4};
+
+  View view{Iterator(array.begin()), Sentinel(Iterator(array.end()))};
+  EnumerateView ev{std::move(view)};
+  EnumerateIterator const it = ev.begin();
+
+  auto&& result = iter_move(it);
+
+  static_assert(std::is_same_v::difference_type, int&&>&&>);

cjdb wrote:

Consider using `ranges::range_difference_t`.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [compiler-rt] [clang] [libcxx] [llvm] [clang-tools-extra] [flang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,107 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// friend constexpr strong_ordering operator<=>(const iterator& x, const 
iterator& y) noexcept;
+
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "../types.h"
+
+constexpr void compareOperatorTest(const auto& iter1, const auto& iter2) {
+  assert(!(iter1 < iter1));
+  assert(iter1 < iter2);
+  assert(!(iter2 < iter1));
+
+  assert(iter1 <= iter1);
+  assert(iter1 <= iter2);
+  assert(!(iter2 <= iter1));
+
+  assert(!(iter1 > iter1));
+  assert(!(iter1 > iter2));
+  assert(iter2 > iter1);
+
+  assert(iter1 >= iter1);
+  assert(!(iter1 >= iter2));
+  assert(iter2 >= iter1);
+
+  assert(iter1 == iter1);
+  assert(!(iter1 == iter2));
+  assert(iter2 == iter2);
+
+  assert(!(iter1 != iter1));
+  assert(iter1 != iter2);
+  assert(!(iter2 != iter2));
+}
+
+constexpr bool test() {
+  int buff[] = {0, 1, 2, 3};

cjdb wrote:

Same as before: we should have multiple categories of range being tested.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [lld] [libcxx] [compiler-rt] [clang-tools-extra] [clang] [flang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[libcxx] [llvm] [lld] [flang] [clang-tools-extra] [clang] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,107 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// friend constexpr strong_ordering operator<=>(const iterator& x, const 
iterator& y) noexcept;
+
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "../types.h"
+
+constexpr void compareOperatorTest(const auto& iter1, const auto& iter2) {
+  assert(!(iter1 < iter1));
+  assert(iter1 < iter2);
+  assert(!(iter2 < iter1));
+
+  assert(iter1 <= iter1);
+  assert(iter1 <= iter2);
+  assert(!(iter2 <= iter1));
+
+  assert(!(iter1 > iter1));
+  assert(!(iter1 > iter2));
+  assert(iter2 > iter1);
+
+  assert(iter1 >= iter1);
+  assert(!(iter1 >= iter2));
+  assert(iter2 >= iter1);
+
+  assert(iter1 == iter1);
+  assert(!(iter1 == iter2));
+  assert(iter2 == iter2);
+
+  assert(!(iter1 != iter1));
+  assert(iter1 != iter2);
+  assert(!(iter2 != iter2));
+}
+
+constexpr bool test() {
+  int buff[] = {0, 1, 2, 3};
+  {
+using View = std::ranges::enumerate_view;
+
+using Iterator = std::ranges::iterator_t;
+static_assert(std::three_way_comparable);
+using Subrange = std::ranges::subrange;
+
static_assert(std::three_way_comparable>);
+using EnumerateView = std::ranges::enumerate_view;
+
static_assert(std::three_way_comparable>);
+
+RangeView const range(buff, buff + 4);
+
+std::same_as decltype(auto) ev = std::views::enumerate(range);
+
+auto it1 = ev.begin();
+auto it2 = it1 + 1;

cjdb wrote:

Please const-qualify (I'm specifically calling these out because the interface 
requires them to be `const`-qualified).

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [libcxx] [compiler-rt] [flang] [clang] [clang-tools-extra] [lld] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,129 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// constexpr auto begin() requires (!simple-view);
+// constexpr auto begin() const requires range-with-movable-references;
+
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "types.h"
+
+// Helpers
+
+template 
+concept HasConstBegin = requires(const T ct) { ct.begin(); };
+
+template 
+concept HasBegin = requires(T t) { t.begin(); };
+
+template 
+concept HasConstAndNonConstBegin =
+HasConstBegin &&
+// Because const begin() and non-const begin() returns different types: 
iterator vs. iterator
+requires(T t, const T ct) { requires !std::same_as; };
+
+template 
+concept HasOnlyNonConstBegin = HasBegin && !HasConstBegin;
+
+template 
+concept HasOnlyConstBegin = HasConstBegin && !HasConstAndNonConstBegin;
+
+// Types
+
+template 
+struct CommonView : std::ranges::view_base {
+  constexpr std::tuple* begin()
+requires(!Simple)
+  {
+return nullptr;
+  }
+  constexpr const std::tuple* begin() const { return 
nullptr; }
+  constexpr std::tuple* end()
+requires(!Simple)
+  {
+return nullptr;
+  }
+  constexpr const std::tuple* end() const { return 
nullptr; }
+};
+using SimpleCommonView= CommonView;
+using NonSimpleCommonView = CommonView;
+
+struct NoConstBeginView : std::ranges::view_base {
+  constexpr std::tuple* begin() { return nullptr; }
+  constexpr std::tuple* end() { return nullptr; }
+};
+
+// SFINAE
+
+// simple-view
+static_assert(HasOnlyConstBegin>);
+
+// !simple-view && range
+static_assert(HasConstAndNonConstBegin>);
+
+// !range
+static_assert(HasOnlyNonConstBegin>);
+
+constexpr bool test() {
+  int buff[] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+  // Check the return type of begin()
+  {
+RangeView range(buff, buff + 1);
+
+std::ranges::enumerate_view view(range);
+using Iterator = std::ranges::iterator_t;
+static_assert(std::same_as);
+  }

cjdb wrote:

This feels like it's testing `ranges::iterator_t` more than `view.begin()`.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [libcxx] [llvm] [clang-tools-extra] [clang] [flang] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)

cjdb wrote:

```suggestion
requires default_initializable<_View>
```

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [llvm] [lld] [flang] [clang-tools-extra] [libcxx] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,114 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// constexpr auto end() requires (!simple-view);
+// constexpr auto end() const requires range-with-movable-references;
+
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "types.h"
+
+constexpr bool test() {
+  int buff[] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+  // Check the return type of .end()
+  {
+RangeView range(buff, buff + 1);
+
+std::ranges::enumerate_view view(range);
+using Iterator = std::ranges::iterator_t;
+static_assert(std::same_as);
+using Sentinel = std::ranges::sentinel_t;
+static_assert(std::same_as);
+  }
+
+  // Check the return type of .end() const
+  {
+RangeView range(buff, buff + 1);
+
+const std::ranges::enumerate_view view(range);
+using Iterator = std::ranges::iterator_t;
+static_assert(std::same_as);
+using Sentinel = std::ranges::sentinel_t;
+static_assert(std::same_as);
+  }

cjdb wrote:

This feels like it's testing `ranges::iterator_t` and `ranges::sentinel_t` more 
than anything in `enumerate_view`. I think we can remove it, or at least 
condense it to checking that we have a common range in both cases.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [llvm] [clang-tools-extra] [lld] [libcxx] [compiler-rt] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,101 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// constexpr auto operator*() const;
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "test_macros.h"
+#include "../types.h"
+
+template >
+constexpr void test() {
+  using View  = MinimalView;
+  using EnumerateView = std::ranges::enumerate_view;
+  using EnumerateIterator = std::ranges::iterator_t;
+
+  using Result = std::tuple>>;
+
+  std::array array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+
+  View view{Iterator(array.begin()), Sentinel(Iterator(array.end()))};
+  EnumerateView ev{std::move(view)};
+
+  {
+auto it = ev.begin();
+for (std::size_t index = 0; index < array.size(); ++index) {
+  std::same_as decltype(auto) result = *it;
+
+  auto [resultIndex, resultValue] = result;
+  assert(std::cmp_equal(index, resultIndex));
+  assert(array[index] == resultValue);
+
+  ++it;
+}
+
+assert(it == ev.end());
+  }
+
+  // const
+  {
+auto constIt = std::as_const(ev).begin();
+for (std::size_t index = 0; index < array.size(); ++index) {
+  std::same_as decltype(auto) result = *constIt;
+
+  auto [resultIndex, resultValue] = result;
+  assert(std::cmp_equal(index, resultIndex));
+  assert(array[index] == resultValue);
+
+  ++constIt;
+}

cjdb wrote:

Please hand-roll.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [flang] [libcxx] [llvm] [clang-tools-extra] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }

cjdb wrote:

I'm not sure this function is necessary.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [flang] [libcxx] [lld] [compiler-rt] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)

cjdb wrote:

```suggestion
requires default_initializable>
```

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-co

[clang-tools-extra] [compiler-rt] [flang] [libcxx] [clang] [lld] [llvm] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,96 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// friend constexpr bool operator==(const iterator& x, const iterator& y) 
noexcept;
+
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "../types.h"
+// #include "../types_iterators.h"
+
+// template 
+// struct Iterator {
+//   using value_type   = int
+//   using difference_type  = std::std::ptrdiff_t;
+//   using iterator_concept = std::input_iterator_tag;
+
+//   constexpr decltype(auto) operator*() const { return *it_; }
+//   constexpr Iterator& operator++() {
+// ++it_;
+
+// return *this;
+//   }
+//   constexpr void operator++(int) { ++it_; }
+
+//   std::tuple* it_;
+// };
+
+// template 
+// struct Sentinel {
+//   constexpr bool operator==(const Iterator& i) const { return i.it_ 
== end_; }
+
+//   std::tuple* end_;
+// };
+
+// template 
+// struct CrossComparableSentinel {
+//   template 
+//   constexpr bool operator==(const Iterator& i) const {
+// return i.it_ == end_;
+//   }
+
+//   std::tuple* end_;
+// };
+
+constexpr bool test() {
+  int buff[] = {0, 1, 2, 3, 5};
+  {
+using View = std::ranges::enumerate_view;
+RangeView const range(buff, buff + 5);
+
+std::same_as decltype(auto) ev = std::views::enumerate(range);
+
+auto it1 = ev.begin();
+auto it2 = it1 + 5;
+
+assert(it1 == it1);
+ASSERT_NOEXCEPT(it1 == it1);
+assert(it1 != it2);
+ASSERT_NOEXCEPT(it1 != it2);
+assert(it2 != it1);
+ASSERT_NOEXCEPT(it2 != it1);
+assert(it2 == ev.end());
+assert(ev.end() == it2);
+
+for (std::size_t index = 0; index != 5; ++index) {
+  ++it1;
+}

cjdb wrote:

Please hand-roll.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [libcxx] [clang-tools-extra] [flang] [clang] [llvm] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[libcxx] [compiler-rt] [clang] [llvm] [clang-tools-extra] [flang] [lld] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,138 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// constexpr const iterator_t& base() const & noexcept;
+// constexpr iterator_t base() &&;
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "../types.h"
+
+// template 
+// class MovableIterator {
+//   using Traits = std::iterator_traits;
+//   It it_;
+
+//   template 
+//   friend class MovableIterator;
+
+// public:
+//   using iterator_category = std::input_iterator_tag;
+//   using value_type= typename Traits::value_type;
+//   using difference_type   = typename Traits::difference_type;
+//   using pointer   = It;
+//   using reference = typename Traits::reference;
+
+//   TEST_CONSTEXPR explicit MovableIterator(It it) : it_(it), 
justInitialized{true} { static_assert(false); }
+
+//   template 
+//   TEST_CONSTEXPR MovableIterator(const MovableIterator& u) : 
it_(u.it_), wasCopyInitialized{true} {
+// static_assert(false);
+//   }
+
+//   template ::value>::type>
+//   TEST_CONSTEXPR_CXX14 MovableIterator(MovableIterator&& u) : 
it_(u.it_), wasMoveInitialized{true} {
+// static_assert(false);
+// u.it_ = U();
+//   }
+
+//   TEST_CONSTEXPR reference operator*() const { return *it_; }
+
+//   TEST_CONSTEXPR_CXX14 MovableIterator& operator++() {
+// ++it_;
+// return *this;
+//   }
+//   TEST_CONSTEXPR_CXX14 MovableIterator operator++(int) { return 
MovableIterator(it_++); }
+
+//   friend TEST_CONSTEXPR bool operator==(const MovableIterator& x, const 
MovableIterator& y) { return x.it_ == y.it_; }
+//   friend TEST_CONSTEXPR bool operator!=(const MovableIterator& x, const 
MovableIterator& y) { return x.it_ != y.it_; }
+
+//   friend TEST_CONSTEXPR It base(const MovableIterator& i) { return i.it_; }
+
+//   template 
+//   void operator,(T const&) = delete;
+
+//   bool justInitialized= false;
+//   bool wasCopyInitialized = false;
+//   bool wasMoveInitialized = false;
+// };

cjdb wrote:

```suggestion
```
Please delete this if it's not being used.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [clang] [lld] [llvm] [clang-tools-extra] [flang] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[clang] [libcxx] [llvm] [lld] [flang] [clang-tools-extra] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[clang] [lld] [clang-tools-extra] [llvm] [flang] [compiler-rt] [libcxx] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits

https://github.com/cjdb edited https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libcxx] [flang] [compiler-rt] [clang] [lld] [llvm] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;

cjdb wrote:

```suggestion
template 
concept __range_with_movable_references =
   input_range<_Rp> && move_constructible> &&
   move_constructible>;
```
We don't need to qualify these names in their native namespace.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang-tools-extra] [lld] [libcxx] [llvm] [flang] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,129 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// constexpr auto begin() requires (!simple-view);
+// constexpr auto begin() const requires range-with-movable-references;
+
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "types.h"
+
+// Helpers
+
+template 

cjdb wrote:

I would prefer it if these were declared at their point of use, rather than at 
the top of the file (and same for other tests).

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [libcxx] [lld] [flang] [compiler-rt] [clang-tools-extra] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits

https://github.com/cjdb requested changes to this pull request.

Thanks for working on this! There's a fair bit that I've provided comments for, 
but I think you're off to a great start, and I would like to see this merged in 
January, if at all possible.

Some comments are short and repetitive: those are usually coupled with a 
starter comment that explains my perspective, and then I just flag the others 
as I see them in a (hopefully) non-intrusive way.

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [libcxx] [lld] [flang] [compiler-rt] [libc] [clang-tools-extra] [clang] [hwasan] Workaround unsupported AssignmentTrackingPass (PR #76547)

2024-01-02 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka closed 
https://github.com/llvm/llvm-project/pull/76547
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [libcxx] [lld] [flang] [compiler-rt] [libc] [clang-tools-extra] [clang] [hwasan] Workaround unsupported AssignmentTrackingPass (PR #76547)

2024-01-02 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/76547
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [libcxx] [lld] [flang] [compiler-rt] [libc] [clang-tools-extra] [clang] [hwasan] Workaround unsupported AssignmentTrackingPass (PR #76547)

2024-01-02 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/76547
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [libcxx] [lld] [flang] [compiler-rt] [libc] [clang-tools-extra] [clang] [hwasan] Workaround unsupported AssignmentTrackingPass (PR #76547)

2024-01-02 Thread Florian Mayer via cfe-commits

https://github.com/fmayer approved this pull request.

LGTM, but maybe be more explicit in the commit message how we work around this.

https://github.com/llvm/llvm-project/pull/76547
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [llvm] [clang-tools-extra] [clang] [emacs] Fix Emacs library formatting (PR #76110)

2024-01-02 Thread via cfe-commits

darkfeline wrote:

Friendly ping, this is a comment change that will make it easier to package 
these Emacs configs for developers.

https://github.com/llvm/llvm-project/pull/76110
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Fix bug in `Value` comparison. (PR #76746)

2024-01-02 Thread Gábor Horváth via cfe-commits


@@ -27,9 +27,13 @@ static bool areEquivalentIndirectionValues(const Value &Val1,
 }
 
 bool areEquivalentValues(const Value &Val1, const Value &Val2) {
-  return &Val1 == &Val2 || (Val1.getKind() == Val2.getKind() &&
-(isa(&Val1) ||
- areEquivalentIndirectionValues(Val1, Val2)));
+  // If values are distinct and have properties, we don't consider them equal,
+  // leaving equality up to the user model.
+  return &Val1 == &Val2 ||
+ (Val1.getKind() == Val2.getKind() &&
+  (Val1.properties().empty() && Val2.properties().empty()) &&

Xazax-hun wrote:

Do we want to consider them different when only one of them has properties?

https://github.com/llvm/llvm-project/pull/76746
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-01-02 Thread Axel Lundberg via cfe-commits

Zonotora wrote:

> Please add test coverage for compound assignment and increment/decrement.
> 
> This seems like a reasonable extension of the existing integer truncation 
> checks, but we might want to consider giving it a unique name. Otherwise, 
> people using integer truncation checks will have trouble upgrading their 
> compiler.

Sure 👍 Fair enough, what name do you suggest? Replace "integer" with "bitfield" 
as in `implicit-unsigned-bitfield-truncation`, 
`implicit-signed-bitfield-truncation` and `implicit-bitfield-sign-change`? Or 
just have a single flag `implicit-bitfield-conversion` for now?

https://github.com/llvm/llvm-project/pull/75481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-01-02 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Please add test coverage for compound assignment and increment/decrement.

This seems like a reasonable extension of the existing integer truncation 
checks, but we might want to consider giving it a unique name.  Otherwise, 
people using integer truncation checks will have trouble upgrading their 
compiler.

https://github.com/llvm/llvm-project/pull/75481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [lld] [mlir] [libcxx] [lldb] [compiler-rt] [libc] [flang] [llvm] [libcxxabi] [clang] [polly] Make clang report invalid target versions. (PR #75373)

2024-01-02 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/75373

>From 74f256d8a77ee2ba8e0d5bbb6519aa2729cf94d5 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 01/11] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 llvm/lib/TargetParser/Triple.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index c5e9ad43d22588..335253194d1cf8 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/ARMTargetParser.h"
@@ -1199,7 +1200,11 @@ StringRef Triple::getOSAndEnvironmentName() const {
 
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
-  Version.tryParse(Name);
+  if (Version.tryParse(Name)) {
+errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
+"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+exit(1);
+  }
   return Version.withoutBuild();
 }
 

>From 0d159b2a9b76e233e020ac0aef15b49b03f4d86c Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:23:54 +
Subject: [PATCH 02/11] rephrase

---
 llvm/lib/TargetParser/Triple.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 335253194d1cf8..713ca447403d50 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1201,8 +1201,7 @@ StringRef Triple::getOSAndEnvironmentName() const {
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
   if (Version.tryParse(Name)) {
-errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
-"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+errs() << "version "<< Name << " is invalid\n";
 exit(1);
   }
   return Version.withoutBuild();

>From b2dda9ce95804783c59aa1ca4e81a7941aae805d Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 03/11] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 clang/lib/Basic/Targets/OSTargets.h | 5 +
 llvm/include/llvm/TargetParser/Triple.h | 4 
 llvm/lib/TargetParser/Triple.cpp| 8 
 3 files changed, 17 insertions(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 342af4bbc42b7b..bc28066019971c 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -323,6 +323,11 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
 // This historical but ambiguous name for the minSdkVersion macro. Keep
 // defined for compatibility.
 Builder.defineMacro("__ANDROID_API__", "__ANDROID_MIN_SDK_VERSION__");
+  } else {
+llvm::errs() << "version "<< Triple.getVersionName() <<
+" in triple " << Triple.getArchName() << "-" << Triple.getVendorName()
+<< "-" << Triple.getOSAndEnvironmentName() << " is invalid\n";
+exit(1);
   }
 } else {
 Builder.defineMacro("__gnu_linux__");
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 47904621c0967f..05df1c489ad06e 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -434,6 +434,10 @@ class Triple {
   /// string (separated by a '-' if the environment component is present).
   StringRef getOSAndEnvironmentName() const;
 
+  /// Get the version component of the environment component as a single
+  /// string (the version after the environment).
+  StringRef getVersionName() const;
+
   /// @}
   /// @name Convenience Predicates
   /// @{
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 49bc24ffbfae6c..db4ba7100781bc 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1199,6 +1199,14 @@ StringRef Triple::getOSAndEnvironmentName() const {
   return Tmp.split('-').second;  // Strip second component
 }
 
+StringRef Triple::getVersionName() const {
+  StringRef VersionName = getEnvironmentName();
+  StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
+  if (VersionName.startswith(EnvironmentTypeName))
+return VersionName.substr(EnvironmentTypeName.size());
+  return VersionName;
+}
+
 static 

[clang] [llvm] [TargetParser] Define AEK_FCMA and AEK_JSCVT for tsv110 (PR #75516)

2024-01-02 Thread Qi Hu via cfe-commits

https://github.com/Qi-Hu updated https://github.com/llvm/llvm-project/pull/75516

>From 9b1022c10acf491f5dcb0487d3fccf7ee3fee2f8 Mon Sep 17 00:00:00 2001
From: Qi Hu 
Date: Thu, 14 Dec 2023 13:35:52 -0500
Subject: [PATCH] [TargetParser] Define AEK_FCMA and AEK_JSCVT for tsv110

We define AEK_JSCVT and AEK_FCMA for CPU features FEAT_JSCVT and FEAT_FCMA
respectively, and add them to the CpuInfo of tsv110.
---
 clang/test/CodeGen/aarch64-targetattr.c   | 12 +--
 .../Preprocessor/aarch64-target-features.c| 10 +--
 .../llvm/TargetParser/AArch64TargetParser.h   | 11 ++-
 llvm/lib/Target/AArch64/AArch64.td|  3 +-
 .../TargetParser/TargetParserTest.cpp | 77 +++
 5 files changed, 67 insertions(+), 46 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-targetattr.c 
b/clang/test/CodeGen/aarch64-targetattr.c
index 9664b723a2b2cd..1693b6ff3b853c 100644
--- a/clang/test/CodeGen/aarch64-targetattr.c
+++ b/clang/test/CodeGen/aarch64-targetattr.c
@@ -97,19 +97,19 @@ void minusarch() {}
 // CHECK: attributes #0 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" }
 // CHECK: attributes #1 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a"
 }
 // CHECK: attributes #2 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a"
 }
-// CHECK: attributes #3 = { {{.*}} 
"target-features"="+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
-// CHECK: attributes #4 = { {{.*}} "target-cpu"="cortex-a710" 
"target-features"="+bf16,+crc,+dotprod,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+mte,+neon,+pauth,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm"
 }
+// CHECK: attributes #3 = { {{.*}} 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+jsconv,+lse,+neon,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
+// CHECK: attributes #4 = { {{.*}} "target-cpu"="cortex-a710" 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+mte,+neon,+pauth,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm"
 }
 // CHECK: attributes #5 = { {{.*}} "tune-cpu"="cortex-a710" }
 // CHECK: attributes #6 = { {{.*}} "target-cpu"="generic" }
 // CHECK: attributes #7 = { {{.*}} "tune-cpu"="generic" }
 // CHECK: attributes #8 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+crc,+dotprod,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs"
 "tune-cpu"="cortex-a710" }
 // CHECK: attributes #9 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve" "tune-cpu"="cortex-a710" }
-// CHECK: attributes #10 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2"
 }
-// CHECK: attributes #11 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,-sve"
 }
+// CHECK: attributes #10 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2"
 }
+// CHECK: attributes #11 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,-sve"
 }
 // CHECK: attributes #12 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve" }
 // CHECK: attributes #13 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve,-sve2" }
 // CHECK: attributes #14 = { {{.*}} "target-features"="+fullfp16" }
-// CHECK: attributes #15 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
-// CHECK: attributes #16 = { {{.*}} "branch-target-enforcement"="true" {{.*}} 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
+// CHECK: attributes #15 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+jsconv,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
+// CHECK: attributes #16 = { {{.*}} "branch-target-enforcement"="true" {{.*}} 
"target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+jsconv,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,

[llvm] [libcxxabi] [lldb] [libcxx] [polly] [openmp] [compiler-rt] [flang] [libc] [mlir] [clang-tools-extra] [clang] [mlir][vector] Fix invalid `LoadOp` indices being created (PR #76292)

2024-01-02 Thread Mehdi Amini via cfe-commits


@@ -897,7 +921,8 @@ struct TransferOpConversion : public 
VectorToSCFPattern {
   } else {
 // It's safe to assume the mask buffer can be unpacked if the data
 // buffer was unpacked.
-auto castedMaskType = *unpackOneDim(maskBufferType);
+auto maskBufferType = dyn_cast(maskBuffer.getType());

joker-eph wrote:

OK, but we're not checking the result: if this can't fail here by construction 
it should be a cast instead.

https://github.com/llvm/llvm-project/pull/76292
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

2024-01-02 Thread Axel Lundberg via cfe-commits

Zonotora wrote:

Feedback @vitalybuka @AaronBallman @LebedevRI? :smiley:

https://github.com/llvm/llvm-project/pull/75481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [clang-tools-extra] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-02 Thread Snehasish Kumar via cfe-commits


@@ -0,0 +1,38 @@
+// RUN: %clang_profgen %s --target=ppc64le-unknown-linux-gnu -S \
+// RUN:-emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN
+// RUN: %clang_profgen -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t

snehasish wrote:

Good point, can we drop the `--target=ppc64le-unknown-linux-gnu` flag? It 
shouldn't make a difference to what we want to test here.

https://github.com/llvm/llvm-project/pull/76471
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >