[clang] Diagnose problematic uses of constructor/destructor attribute (PR #67360)

2023-09-26 Thread Alexander Richardson via cfe-commits

arichardson wrote:

With regard to arguments: I know that the [FreeBSD runtime 
linker](https://github.com/freebsd/freebsd-src/blob/d06328c37bbcf3d3d3c7601372d29237996a6f6a/libexec/rtld-elf/aarch64/rtld_machdep.h#L59)
 (and according to https://stackoverflow.com/a/46331112 also glibc) passes 
argc, argv, envv to the constructor functions, so maybe that specific signature 
should be permitted?

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


[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-09-26 Thread via cfe-commits


@@ -0,0 +1,17 @@
+.. title:: clang-tidy - bugprone-move-shared-pointer-contents
+
+bugprone-move-shared-pointer-contents
+=
+
+Detects calls to move the contents out of a ``std::shared_ptr`` rather than
+moving the pointer itself. In other words, calling ``std::move(*p)``. Other
+reference holders may not be expecting the move and suddenly getting empty or
+otherwise indeterminate states can cause issues.
+
+Options
+---
+
+.. option :: SharedPointerClasses
+
+   A semicolon-separated list of class names that should be treated as shared
+   pointers. By default only `std::shared_ptr` is included.

EugeneZelenko wrote:

I think , `Default is `std::shared_ptr`.` would be better.

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


[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-09-26 Thread via cfe-commits


@@ -0,0 +1,37 @@
+//===--- MoveSharedPointerContentsCheck.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_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+
+#include 
+

EugeneZelenko wrote:

Excessive newline.

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


[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-09-26 Thread via cfe-commits


@@ -0,0 +1,37 @@
+//===--- MoveSharedPointerContentsCheck.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_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+
+#include 
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// FIXME: Write a short description.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/move-shared-pointer-contents.html
+class MoveSharedPointerContentsCheck : public ClangTidyCheck {
+public:
+  MoveSharedPointerContentsCheck(StringRef Name, ClangTidyContext *Context);
+  ~MoveSharedPointerContentsCheck() override;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  bool
+  isLanguageVersionSupported(const LangOptions ) const override;
+
+private:
+  const std::vector SharedPointerClasses;

EugeneZelenko wrote:

Please include `llvm/StringRef.h`.

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-26 Thread Kai Luo via cfe-commits

bzEq wrote:

> Also, is it intentional that we combined the patch to enable local-dynamic in 
> clang within this patch?

Yes. For github's nature, we are unable to set parent PR in llvm-project repo, 
so clang part is included in this PR.

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


[clang] [clang-format] Handle __attribute/__declspec/AttributeMacro consistently (PR #67518)

2023-09-26 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/67518

None

>From 44165f4df433a668e4f4c2db730a66ce2acbc64b Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 26 Sep 2023 20:43:55 -0700
Subject: [PATCH] [clang-format] Handle __attribute/__declspec/AttributeMacro
 consistently

---
 clang/lib/Format/FormatToken.h| 36 +--
 .../lib/Format/NamespaceEndCommentsFixer.cpp  |  2 +-
 clang/lib/Format/TokenAnnotator.cpp   | 23 ++--
 clang/lib/Format/UnwrappedLineParser.cpp  |  6 ++--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 13 +++
 5 files changed, 46 insertions(+), 34 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 986849abd8f9206..dbd3a6e70f037ef 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -618,6 +618,10 @@ struct FormatToken {
 
   bool isStringLiteral() const { return tok::isStringLiteral(Tok.getKind()); }
 
+  bool isAttribute() const {
+return isOneOf(tok::kw___attribute, tok::kw___declspec, TT_AttributeMacro);
+  }
+
   bool isObjCAtKeyword(tok::ObjCKeywordKind Kind) const {
 return Tok.isObjCAtKeyword(Kind);
   }
@@ -633,9 +637,10 @@ struct FormatToken {
 
   bool canBePointerOrReferenceQualifier() const {
 return isOneOf(tok::kw_const, tok::kw_restrict, tok::kw_volatile,
-   tok::kw___attribute, tok::kw__Nonnull, tok::kw__Nullable,
+   tok::kw__Nonnull, tok::kw__Nullable,
tok::kw__Null_unspecified, tok::kw___ptr32, tok::kw___ptr64,
-   tok::kw___funcref, TT_AttributeMacro);
+   tok::kw___funcref) ||
+   isAttribute();
   }
 
   /// Determine whether the token is a simple-type-specifier.
@@ -708,25 +713,16 @@ struct FormatToken {
   /// Returns \c true if this is a keyword that can be used
   /// like a function call (e.g. sizeof, typeid, ...).
   bool isFunctionLikeKeyword() const {
-switch (Tok.getKind()) {
-case tok::kw_throw:
-case tok::kw_typeid:
-case tok::kw_return:
-case tok::kw_sizeof:
-case tok::kw_alignof:
-case tok::kw_alignas:
-case tok::kw_decltype:
-case tok::kw_noexcept:
-case tok::kw_static_assert:
-case tok::kw__Atomic:
-case tok::kw___attribute:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-case tok::kw_requires:
+if (isAttribute())
   return true;
-default:
-  return false;
-}
+
+return isOneOf(tok::kw_throw, tok::kw_typeid, tok::kw_return,
+   tok::kw_sizeof, tok::kw_alignof, tok::kw_alignas,
+   tok::kw_decltype, tok::kw_noexcept, tok::kw_static_assert,
+   tok::kw__Atomic,
+#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) tok::kw___##Trait,
+#include "clang/Basic/TransformTypeTraits.def"
+   tok::kw_requires);
   }
 
   /// Returns \c true if this is a string literal that's like a label,
diff --git a/clang/lib/Format/NamespaceEndCommentsFixer.cpp 
b/clang/lib/Format/NamespaceEndCommentsFixer.cpp
index aed31db87495406..08f8d6840fe00a8 100644
--- a/clang/lib/Format/NamespaceEndCommentsFixer.cpp
+++ b/clang/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -48,7 +48,7 @@ processTokens(const FormatToken *Tok, tok::TokenKind StartTok,
 const FormatToken *skipAttribute(const FormatToken *Tok) {
   if (!Tok)
 return nullptr;
-  if (Tok->is(tok::kw___attribute)) {
+  if (Tok->isAttribute()) {
 Tok = Tok->getNextNonComment();
 Tok = processTokens(Tok, tok::l_paren, tok::r_paren, nullptr);
   } else if (Tok->is(tok::l_square)) {
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 95d039b459b43e8..ba90e0184917344 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -376,7 +376,7 @@ class AnnotatingParser {
 // Infer the role of the l_paren based on the previous token if we haven't
 // detected one yet.
 if (PrevNonComment && OpeningParen.is(TT_Unknown)) {
-  if (PrevNonComment->is(tok::kw___attribute)) {
+  if (PrevNonComment->isAttribute()) {
 OpeningParen.setType(TT_AttributeLParen);
   } else if (PrevNonComment->isOneOf(TT_TypenameMacro, tok::kw_decltype,
  tok::kw_typeof,
@@ -1207,11 +1207,13 @@ class AnnotatingParser {
 return false;
   if (Line.MustBeDeclaration && Contexts.size() == 1 &&
   !Contexts.back().IsExpression && !Line.startsWith(TT_ObjCProperty) &&
-  !Tok->isOneOf(TT_TypeDeclarationParen, TT_RequiresExpressionLParen) 
&&
-  (!Tok->Previous ||
-   !Tok->Previous->isOneOf(tok::kw___attribute, TT_RequiresClause,
-   TT_LeadingJavaAnnotation))) {
-Line.MightBeFunctionDecl = true;
+  !Tok->isOneOf(TT_TypeDeclarationParen, 

[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-26 Thread Amy Kwan via cfe-commits

amy-kwan wrote:

Also, is it intentional that we combined the patch to enable local-dynamic in 
clang within this patch?
Just wondering since I thought I saw a separate patch for the clang portion 
before (unless I am mistaken).

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-26 Thread Amy Kwan via cfe-commits


@@ -3412,13 +3414,28 @@ SDValue 
PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op,
 return DAG.getNode(PPCISD::ADD_TLS, dl, PtrVT, TLSReg, VariableOffset);
   }
 
-  // Only Local-Exec, Initial-Exec and General-Dynamic TLS models are currently
-  // supported models. If Local- or Initial-exec are not possible or specified,
-  // all GlobalTLSAddress nodes are lowered using the general-dynamic model.
-  // We need to generate two TOC entries, one for the variable offset, one for
-  // the region handle. The global address for the TOC entry of the region
-  // handle is created with the MO_TLSGDM_FLAG flag and the global address
-  // for the TOC entry of the variable offset is created with MO_TLSGD_FLAG.
+  if (Model == TLSModel::LocalDynamic) {
+// For local-dynamic on AIX, we need to generate one TOC entry for each
+// variable offset, and single module-handle TOC entry for the entire file.
+
+// We are not (1) create GV node (2) call getTOCEntry for the module-handle

amy-kwan wrote:

```suggestion
// We are not able to (1) create a GV node, and (2) call getTOCEntry for 
the module-handle
```

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-26 Thread Amy Kwan via cfe-commits


@@ -145,9 +160,92 @@ namespace {
   .addImm(0);
 
 if (IsAIX) {
-  // The variable offset and region handle are copied in r4 and r3. The
-  // copies are followed by GETtlsADDR32AIX/GETtlsADDR64AIX.
-  if (!IsTLSTPRelMI) {
+  if (MI.getOpcode() == PPC::TLSLDAIX8 ||
+  MI.getOpcode() == PPC::TLSLDAIX) {
+// It is better to put TLSLDAIX node before LoadOffsetToc node,
+// because LoadOffsetToc node can use clobbers r4/r5. Search for 
the
+// first paired LoadOffsetToc node within the same BB.
+const PPCSubtarget  =
+MBB.getParent()->getSubtarget();
+bool IsLargeModel =
+Subtarget.getTargetMachine().getCodeModel() == 
CodeModel::Large;
+unsigned LDTocOp =
+Is64Bit ? (IsLargeModel ? PPC::LDtocL : PPC::LDtoc)
+: (IsLargeModel ? PPC::LWZtocL : PPC::LWZtoc);
+MachineBasicBlock::iterator Anchor = I;
+if (!RegInfo.use_empty(OutReg)) {
+  std::set Uses;
+  // Collect all instructions that use OutReg
+  for (MachineOperand  : RegInfo.use_operands(OutReg)) {
+if (Uses.count(MO.getParent()))
+  continue;
+Uses.insert(MO.getParent());
+  }
+  // Find the first Add within current BB.
+  MachineBasicBlock::iterator UseIter = MBB.begin();
+  for (MachineBasicBlock::iterator AE = MBB.end(); UseIter != AE;
+   ++UseIter)
+if (Uses.count(&*UseIter))
+  break;
+
+  if (UseIter != MBB.end()) {
+// Get the instruction that defines the other used register
+// operand of UseIter. The match pattern is that: UseIter has
+// exactly one used-operand defined by LDTocOp
+// (LDtocL/LDtoc/LWZtocL/LWZtoc).
+MachineInstr *LoadOffsetToc = nullptr;
+int MatchCount = 0;
+for (MachineOperand  : UseIter->operands()) {
+  if (MO.isReg() && MO.isUse()) {
+if (RegInfo.hasOneDef(MO.getReg())) {

amy-kwan wrote:

Pull out `MO.getReg()` calls into a separate variable after the `isReg()` check.

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-26 Thread Amy Kwan via cfe-commits


@@ -231,12 +231,18 @@ class PPCTargetAsmStreamer : public PPCTargetStreamer {
   MCSymbolXCOFF *TCSym =
   cast(Streamer.getCurrentSectionOnly())
   ->getQualNameSymbol();
-  // On AIX, we have a region handle (symbol@m) and the variable offset
-  // (symbol@{gd|ie|le}) for TLS variables, depending on the TLS model.
+  // On AIX, we have TLS variable offsets (symbol@({gd|ie|le|ld}) depending
+  // on the TLS access method (or model). For the general-dynamic access
+  // method, we also have region handle (symbol@m) for each variable. For
+  // local-dynamic, a module handle (__TLSML[TC]@ml) for all variables. For

amy-kwan wrote:

```suggestion
  // local-dynamic, there is a module handle (__TLSML[TC]@ml) for all 
variables. Finally, for
```

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-26 Thread Amy Kwan via cfe-commits


@@ -370,11 +370,23 @@ namespace llvm {
 /// G8RC = TLSGD_AIX, TOC_ENTRY, TOC_ENTRY
 /// Op that combines two register copies of TOC entries
 /// (region handle into R3 and variable offset into R4) followed by a
-/// GET_TLS_ADDR node which will be expanded to a call to __get_tls_addr.
+/// GET_TLS_ADDR node which will be expanded to a call to .__tls_get_addr.
 /// This node is used in 64-bit mode as well (in which case the result is
 /// G8RC and inputs are X3/X4).
 TLSGD_AIX,
 
+/// %x3 = GET_TLS_MOD_AIX _$TLSML - For the AIX local-dynamic TLS model,
+/// produces a call to .__tls_get_mod(_$TLSML\@ml).
+GET_TLS_MOD_AIX,
+
+/// [GP|G8]RC = TLSLD_AIX, TOC_ENTRY(variable offset)
+/// Op that internally creates TOC entry for the "_$TLSML" symbol, 
generates

amy-kwan wrote:

```suggestion
/// Op that internally creates a TOC entry for the "_$TLSML" symbol, and 
generates
```

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-26 Thread Amy Kwan via cfe-commits


@@ -3281,6 +3288,9 @@ def TLSGDAIX : PPCEmitTimePseudo<(outs gprc:$rD), (ins 
gprc:$offset, gprc:$handl
   "#TLSGDAIX",
   [(set i32:$rD,
 (PPCTlsgdAIX i32:$offset, i32:$handle))]>;
+// This pseudo is expanded to load module-handle in R3, and the call to 
GETtlsMOD32AIX.

amy-kwan wrote:

```suggestion
// This pseudo is expanded to load the module-handle in R3, and the call to 
GETtlsMOD32AIX.
```

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-26 Thread Amy Kwan via cfe-commits


@@ -2710,6 +2758,15 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module ) {
   MCSymbol *S = OutContext.getOrCreateSymbol(Name);
   TCEntry = cast(
   getObjFileLowering().getSectionForTOCEntry(S, TM));
+} else if (I.first.second ==
+   MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSML) {
+  // AIX assembler expects TC storage-mapping class for the "_$TLSML"

amy-kwan wrote:

```suggestion
  // AIX assembler expects the TC storage-mapping class for the "_$TLSML"
```

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-26 Thread Amy Kwan via cfe-commits


@@ -145,9 +160,92 @@ namespace {
   .addImm(0);
 
 if (IsAIX) {
-  // The variable offset and region handle are copied in r4 and r3. The
-  // copies are followed by GETtlsADDR32AIX/GETtlsADDR64AIX.
-  if (!IsTLSTPRelMI) {
+  if (MI.getOpcode() == PPC::TLSLDAIX8 ||

amy-kwan wrote:

We're checking is the opcode is `PPC::TLSLDAIX`/`PPC::TLSLDAIX8` quite a bit. 
Maybe we should save this check into a boolean, similar to `IsTLSTPRelMI`.

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-26 Thread Amy Kwan via cfe-commits


@@ -3412,13 +3414,28 @@ SDValue 
PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op,
 return DAG.getNode(PPCISD::ADD_TLS, dl, PtrVT, TLSReg, VariableOffset);
   }
 
-  // Only Local-Exec, Initial-Exec and General-Dynamic TLS models are currently
-  // supported models. If Local- or Initial-exec are not possible or specified,
-  // all GlobalTLSAddress nodes are lowered using the general-dynamic model.
-  // We need to generate two TOC entries, one for the variable offset, one for
-  // the region handle. The global address for the TOC entry of the region
-  // handle is created with the MO_TLSGDM_FLAG flag and the global address
-  // for the TOC entry of the variable offset is created with MO_TLSGD_FLAG.
+  if (Model == TLSModel::LocalDynamic) {
+// For local-dynamic on AIX, we need to generate one TOC entry for each
+// variable offset, and single module-handle TOC entry for the entire file.

amy-kwan wrote:

```suggestion
// variable offset, and a single module-handle TOC entry for the entire 
file.
```

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-26 Thread Amy Kwan via cfe-commits


@@ -846,6 +872,17 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr 
*MI) {
   return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSGDM;
 if (MO.getTargetFlags() & PPCII::MO_TLSGD_FLAG)
   return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSGD;
+if (MO.getTargetFlags() & PPCII::MO_TLSLD_FLAG) {
+  if (isSpecialAIXSymbolTLSML(MO, IsAIX))
+// FIXME: Due to the size limit of MachineOperand::SubReg_TargetFlags,
+// hacked this flag which should have been named MO_TLSLDM_FLAG: on AIX
+// the ML relocation type is only valid for a reference to a TOC symbol
+// from the symbol itself, and right now its only user is the symbol
+// "_$TLSML". Use symbol name to decide that R_TLSML is expected.

amy-kwan wrote:

```suggestion
// "_$TLSML". The symbol name is used to decide that R_TLSML is 
expected.
```

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


[clang] [clang][Interp] Three-way comparisons (PR #65901)

2023-09-26 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/65901

>From 5dc457a45bdf8366a5f8e5d7df7bcf3383120ecd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 10 Sep 2023 17:02:22 +0200
Subject: [PATCH] [clang][Interp] Three-way comparisons

---
 clang/lib/AST/Interp/Boolean.h   |  6 +++
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 23 ++
 clang/lib/AST/Interp/Floating.h  |  6 +++
 clang/lib/AST/Interp/Integral.h  |  7 +++
 clang/lib/AST/Interp/Interp.h| 29 +
 clang/lib/AST/Interp/InterpBuiltin.cpp   | 17 
 clang/lib/AST/Interp/Opcodes.td  |  5 +++
 clang/lib/AST/Interp/Pointer.h   | 13 ++
 clang/test/AST/Interp/cxx20.cpp  | 54 
 9 files changed, 160 insertions(+)

diff --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index 6f0fe26ace68807..c3ed3d61f76ca1c 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -84,6 +84,12 @@ class Boolean final {
   Boolean truncate(unsigned TruncBits) const { return *this; }
 
   void print(llvm::raw_ostream ) const { OS << (V ? "true" : "false"); }
+  std::string toDiagnosticString(const ASTContext ) const {
+std::string NameStr;
+llvm::raw_string_ostream OS(NameStr);
+print(OS);
+return NameStr;
+  }
 
   static Boolean min(unsigned NumBits) { return Boolean(false); }
   static Boolean max(unsigned NumBits) { return Boolean(true); }
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e813d4fa651ceaf..a09e2a007b912c9 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -253,6 +253,29 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
 return this->delegate(RHS);
   }
 
+  // Special case for C++'s three-way/spaceship operator <=>, which
+  // returns a std::{strong,weak,partial}_ordering (which is a class, so 
doesn't
+  // have a PrimType).
+  if (!T) {
+if (DiscardResult)
+  return true;
+const ComparisonCategoryInfo *CmpInfo =
+Ctx.getASTContext().CompCategories.lookupInfoForType(BO->getType());
+assert(CmpInfo);
+
+// We need a temporary variable holding our return value.
+if (!Initializing) {
+  std::optional ResultIndex = this->allocateLocal(BO, false);
+  if (!this->emitGetPtrLocal(*ResultIndex, BO))
+return false;
+}
+
+if (!visit(LHS) || !visit(RHS))
+  return false;
+
+return this->emitCMP3(*LT, CmpInfo, BO);
+  }
+
   if (!LT || !RT || !T)
 return this->bail(BO);
 
diff --git a/clang/lib/AST/Interp/Floating.h b/clang/lib/AST/Interp/Floating.h
index 9a8fd34ec934893..a22b3fa79f3992f 100644
--- a/clang/lib/AST/Interp/Floating.h
+++ b/clang/lib/AST/Interp/Floating.h
@@ -76,6 +76,12 @@ class Floating final {
 F.toString(Buffer);
 OS << Buffer;
   }
+  std::string toDiagnosticString(const ASTContext ) const {
+std::string NameStr;
+llvm::raw_string_ostream OS(NameStr);
+print(OS);
+return NameStr;
+  }
 
   unsigned bitWidth() const { return F.semanticsSizeInBits(F.getSemantics()); }
 
diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 72285cabcbbf8ce..0295a9c3b5c898c 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -128,6 +128,13 @@ template  class Integral final 
{
 return Compare(V, RHS.V);
   }
 
+  std::string toDiagnosticString(const ASTContext ) const {
+std::string NameStr;
+llvm::raw_string_ostream OS(NameStr);
+OS << V;
+return NameStr;
+  }
+
   unsigned countLeadingZeros() const {
 if constexpr (!Signed)
   return llvm::countl_zero(V);
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 8453856e526a6b2..dd37150b63f6db0 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -112,6 +112,11 @@ bool CheckCtorCall(InterpState , CodePtr OpPC, const 
Pointer );
 bool CheckPotentialReinterpretCast(InterpState , CodePtr OpPC,
const Pointer );
 
+/// Sets the given integral value to the pointer, which is of
+/// a std::{weak,partial,strong}_ordering type.
+bool SetThreeWayComparisonField(InterpState , CodePtr OpPC,
+const Pointer , const APSInt );
+
 /// Checks if the shift operation is legal.
 template 
 bool CheckShift(InterpState , CodePtr OpPC, const LT , const RT ,
@@ -781,6 +786,30 @@ bool EQ(InterpState , CodePtr OpPC) {
   });
 }
 
+template ::T>
+bool CMP3(InterpState , CodePtr OpPC, const ComparisonCategoryInfo *CmpInfo) 
{
+  const T  = S.Stk.pop();
+  const T  = S.Stk.pop();
+  const Pointer  = S.Stk.peek();
+
+  ComparisonCategoryResult CmpResult = LHS.compare(RHS);
+  if (CmpResult == ComparisonCategoryResult::Unordered) {
+// This should only happen with pointers.
+const 

[clang] [clang] Avoid evaluating the BitWidth expression over and over again (PR #66203)

2023-09-26 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Emit dummy values for unknown C variables (PR #66749)

2023-09-26 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Three-way comparisons (PR #65901)

2023-09-26 Thread Timm Baeder via cfe-commits

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


[clang] [clang][Interp] Three-way comparisons (PR #65901)

2023-09-26 Thread Timm Baeder via cfe-commits


@@ -253,6 +253,29 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
 return this->delegate(RHS);
   }
 
+  // Special case for C++'s three-way/spaceship operator <=>, which
+  // returns a std::strong_ordering (which is class, so doesn't have a

tbaederr wrote:

Right, I wrote that comment for the first test case I had. Updated it, thanks.

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


[clang] [clang][Interp] Three-way comparisons (PR #65901)

2023-09-26 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/65901

>From 0c61a3cd0d02e70bc1cedf048e73af50caf65bd5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 10 Sep 2023 17:02:22 +0200
Subject: [PATCH] [clang][Interp] Three-way comparisons

---
 clang/lib/AST/Interp/Boolean.h   |  6 +++
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 23 ++
 clang/lib/AST/Interp/Floating.h  |  6 +++
 clang/lib/AST/Interp/Integral.h  |  7 +++
 clang/lib/AST/Interp/Interp.h| 29 +
 clang/lib/AST/Interp/InterpBuiltin.cpp   | 17 
 clang/lib/AST/Interp/Opcodes.td  |  5 +++
 clang/lib/AST/Interp/Pointer.h   | 13 ++
 clang/test/AST/Interp/cxx20.cpp  | 54 
 9 files changed, 160 insertions(+)

diff --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index 6f0fe26ace68807..c3ed3d61f76ca1c 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -84,6 +84,12 @@ class Boolean final {
   Boolean truncate(unsigned TruncBits) const { return *this; }
 
   void print(llvm::raw_ostream ) const { OS << (V ? "true" : "false"); }
+  std::string toDiagnosticString(const ASTContext ) const {
+std::string NameStr;
+llvm::raw_string_ostream OS(NameStr);
+print(OS);
+return NameStr;
+  }
 
   static Boolean min(unsigned NumBits) { return Boolean(false); }
   static Boolean max(unsigned NumBits) { return Boolean(true); }
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e813d4fa651ceaf..f18b969805b373e 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -253,6 +253,29 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
 return this->delegate(RHS);
   }
 
+  // Special case for C++'s three-way/spaceship operator <=>, which
+  // returns a std::{strong,weak,partial}_ordering (which is class, so doesn't
+  // have a PrimType).
+  if (!T) {
+if (DiscardResult)
+  return true;
+const ComparisonCategoryInfo *CmpInfo =
+Ctx.getASTContext().CompCategories.lookupInfoForType(BO->getType());
+assert(CmpInfo);
+
+// We need a temporary variable holding our return value.
+if (!Initializing) {
+  std::optional ResultIndex = this->allocateLocal(BO, false);
+  if (!this->emitGetPtrLocal(*ResultIndex, BO))
+return false;
+}
+
+if (!visit(LHS) || !visit(RHS))
+  return false;
+
+return this->emitCMP3(*LT, CmpInfo, BO);
+  }
+
   if (!LT || !RT || !T)
 return this->bail(BO);
 
diff --git a/clang/lib/AST/Interp/Floating.h b/clang/lib/AST/Interp/Floating.h
index 9a8fd34ec934893..a22b3fa79f3992f 100644
--- a/clang/lib/AST/Interp/Floating.h
+++ b/clang/lib/AST/Interp/Floating.h
@@ -76,6 +76,12 @@ class Floating final {
 F.toString(Buffer);
 OS << Buffer;
   }
+  std::string toDiagnosticString(const ASTContext ) const {
+std::string NameStr;
+llvm::raw_string_ostream OS(NameStr);
+print(OS);
+return NameStr;
+  }
 
   unsigned bitWidth() const { return F.semanticsSizeInBits(F.getSemantics()); }
 
diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 72285cabcbbf8ce..0295a9c3b5c898c 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -128,6 +128,13 @@ template  class Integral final 
{
 return Compare(V, RHS.V);
   }
 
+  std::string toDiagnosticString(const ASTContext ) const {
+std::string NameStr;
+llvm::raw_string_ostream OS(NameStr);
+OS << V;
+return NameStr;
+  }
+
   unsigned countLeadingZeros() const {
 if constexpr (!Signed)
   return llvm::countl_zero(V);
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 8453856e526a6b2..dd37150b63f6db0 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -112,6 +112,11 @@ bool CheckCtorCall(InterpState , CodePtr OpPC, const 
Pointer );
 bool CheckPotentialReinterpretCast(InterpState , CodePtr OpPC,
const Pointer );
 
+/// Sets the given integral value to the pointer, which is of
+/// a std::{weak,partial,strong}_ordering type.
+bool SetThreeWayComparisonField(InterpState , CodePtr OpPC,
+const Pointer , const APSInt );
+
 /// Checks if the shift operation is legal.
 template 
 bool CheckShift(InterpState , CodePtr OpPC, const LT , const RT ,
@@ -781,6 +786,30 @@ bool EQ(InterpState , CodePtr OpPC) {
   });
 }
 
+template ::T>
+bool CMP3(InterpState , CodePtr OpPC, const ComparisonCategoryInfo *CmpInfo) 
{
+  const T  = S.Stk.pop();
+  const T  = S.Stk.pop();
+  const Pointer  = S.Stk.peek();
+
+  ComparisonCategoryResult CmpResult = LHS.compare(RHS);
+  if (CmpResult == ComparisonCategoryResult::Unordered) {
+// This should only happen with pointers.
+const 

[libunwind] [libc++][lit] Allow overriding the executor for tests (PR #66545)

2023-09-26 Thread Alexander Richardson via cfe-commits

arichardson wrote:

> @arichardson
> 
> here is a problem with your changes when building the libraries on the 
> windows cross toolchain builders
> 
> * https://lab.llvm.org/buildbot/#/builders/60/builds/14086
> * https://lab.llvm.org/buildbot/#/builders/119/builds/15283
> 
> https://lab.llvm.org/buildbot/#/builders/60/builds/14086/steps/12/logs/stdio
> 
> ```
> llvm-lit.py: 
> C:\buildbot\as-builder-1\x-armv7l\llvm-project\llvm\utils\lit\lit\TestingConfig.py:151:
>  fatal: unable to parse config file 
> 'C:/buildbot/as-builder-1/x-armv7l/build/runtimes/runtimes-armv7-unknown-linux-gnueabihf-bins/libunwind/test/cmake-bridge.cfg',
>  traceback: Traceback (most recent call last):
>   File 
> "C:\buildbot\as-builder-1\x-armv7l\llvm-project\llvm\utils\lit\lit\TestingConfig.py",
>  line 139, in load_from_path
> exec(compile(data, path, "exec"), cfg_globals, None)
>   File 
> "C:/buildbot/as-builder-1/x-armv7l/build/runtimes/runtimes-armv7-unknown-linux-gnueabihf-bins/libunwind/test/cmake-bridge.cfg",
>  line 7
> config. 'executor="C:/Python310/python.exe" 
> "C:/buildbot/as-builder-1/x-armv7l/llvm-project/libcxx/utils/ssh.py" --host = 
> "ubu...@jetson6.lab.llvm.org'"
>   
>  ^
> SyntaxError: unterminated string literal (detected at line 7)
> ```
> 
> would you take care of it?
> 
> UPDATE: Just let me know if you will need to check you changes before commit. 
> I will test them on the builder locally.

Sorry about that! It looks like the cmake file quoting needs to be updated. 
Alternatively I could revert the part of this change that deprecates the 
executor variable. I will take a look at this first thing tomorrow morning. If 
it's more urgent, feel free to revert the change.

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


[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)

2023-09-26 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/65844

>From 41ea723998954938a00a0de482ef000f1f3af980 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 9 Sep 2023 10:34:26 +0200
Subject: [PATCH 1/5] [clang][Interp] Add IntegralAP for arbitrary-precision
 integers

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp |  11 +-
 clang/lib/AST/Interp/Context.cpp |   6 +-
 clang/lib/AST/Interp/Descriptor.cpp  |   9 +
 clang/lib/AST/Interp/EvalEmitter.cpp |   1 +
 clang/lib/AST/Interp/Integral.h  |   4 +
 clang/lib/AST/Interp/IntegralAP.h| 253 +++
 clang/lib/AST/Interp/Interp.h|  21 +-
 clang/lib/AST/Interp/InterpStack.h   |   5 +
 clang/lib/AST/Interp/Opcodes.td  |   8 +-
 clang/lib/AST/Interp/PrimType.cpp|   1 +
 clang/lib/AST/Interp/PrimType.h  |  13 ++
 clang/test/AST/Interp/literals.cpp   |  24 +++
 12 files changed, 343 insertions(+), 13 deletions(-)
 create mode 100644 clang/lib/AST/Interp/IntegralAP.h

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e813d4fa651ceaf..ca762e795ec6f4b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   return this->discard(SubExpr);
 std::optional FromT = classify(SubExpr->getType());
 std::optional ToT = classify(CE->getType());
+
 if (!FromT || !ToT)
   return false;
 
 if (!this->visit(SubExpr))
   return false;
 
-if (FromT == ToT)
+if (FromT == ToT) {
+  assert(ToT != PT_IntAP && ToT != PT_IntAPS);
   return true;
+}
 
 return this->emitCast(*FromT, *ToT, CE);
   }
@@ -1598,6 +1601,9 @@ bool 
ByteCodeExprGen::visitZeroInitializer(QualType QT,
 return this->emitZeroSint64(E);
   case PT_Uint64:
 return this->emitZeroUint64(E);
+  case PT_IntAP:
+  case PT_IntAPS:
+assert(false);
   case PT_Ptr:
 return this->emitNullPtr(E);
   case PT_FnPtr:
@@ -1837,6 +1843,9 @@ bool ByteCodeExprGen::emitConst(T Value, 
PrimType Ty, const Expr *E) {
 return this->emitConstSint64(Value, E);
   case PT_Uint64:
 return this->emitConstUint64(Value, E);
+  case PT_IntAP:
+  case PT_IntAPS:
+assert(false);
   case PT_Bool:
 return this->emitConstBool(Value, E);
   case PT_Ptr:
diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp
index 1c1aacbc8bb9e7d..e51c45329b9ead6 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -103,7 +103,8 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Sint8;
 default:
-  return std::nullopt;
+  return PT_IntAPS;
+  // return std::nullopt;
 }
   }
 
@@ -118,7 +119,8 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Uint8;
 default:
-  return std::nullopt;
+  return PT_IntAP;
+  // return std::nullopt;
 }
   }
 
diff --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index db49a569eff33ea..4ecb7466998e705 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -10,6 +10,7 @@
 #include "Boolean.h"
 #include "Floating.h"
 #include "FunctionPointer.h"
+#include "IntegralAP.h"
 #include "Pointer.h"
 #include "PrimType.h"
 #include "Record.h"
@@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) {
   // constructor called.
   if (Type == PT_Float)
 return ctorTy::T>;
+  if (Type == PT_IntAP)
+return ctorTy::T>;
+  if (Type == PT_IntAPS)
+return ctorTy::T>;
 
   COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr);
 }
@@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) {
   // destructor called, since they might allocate memory.
   if (Type == PT_Float)
 return dtorTy::T>;
+  if (Type == PT_IntAP)
+return dtorTy::T>;
+  if (Type == PT_IntAPS)
+return dtorTy::T>;
 
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }
diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index bdf800c60f1723f..f46ef1067cf52a0 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -9,6 +9,7 @@
 #include "EvalEmitter.h"
 #include "ByteCodeGenError.h"
 #include "Context.h"
+#include "IntegralAP.h"
 #include "Interp.h"
 #include "Opcode.h"
 #include "clang/AST/DeclCXX.h"
diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 72285cabcbbf8ce..f8e529aa3392696 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -29,6 +29,8 @@ namespace interp {
 using APInt = llvm::APInt;
 using APSInt = llvm::APSInt;
 
+template 

[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)

2023-09-26 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang] Preserve UDL nodes in RemoveNestedImmediateInvocation (PR #66641)

2023-09-26 Thread via cfe-commits

zyn0217 wrote:

Invite @shafik and @cor3ntin to have a look at this.

My apologies if I'm churning anyone's review backlog. Honestly, I have no idea 
who the appropriate reviewer/code owner is. :(

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


[clang] [clang][NFC] Preprocessor only needs const LangOptions (PR #66874)

2023-09-26 Thread Timm Baeder via cfe-commits

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


[clang] 17a1cc6 - [clang][NFC] Preprocessor only needs const LangOptions (#66874)

2023-09-26 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-09-27T06:36:18+02:00
New Revision: 17a1cc69a575a40428491b1c454d88c49ac07569

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

LOG: [clang][NFC] Preprocessor only needs const LangOptions (#66874)

Added: 


Modified: 
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/Preprocessor.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 575d08b83fd3a02..2b10ea91bde7794 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -132,7 +132,7 @@ class Preprocessor {
   llvm::unique_function OnToken;
   std::shared_ptr PPOpts;
   DiagnosticsEngine*Diags;
-  LangOptions   
+  const LangOptions 
   const TargetInfo *Target = nullptr;
   const TargetInfo *AuxTarget = nullptr;
   FileManager   
@@ -1161,8 +1161,9 @@ class Preprocessor {
 
 public:
   Preprocessor(std::shared_ptr PPOpts,
-   DiagnosticsEngine , LangOptions , SourceManager ,
-   HeaderSearch , ModuleLoader ,
+   DiagnosticsEngine , const LangOptions ,
+   SourceManager , HeaderSearch ,
+   ModuleLoader ,
IdentifierInfoLookup *IILookup = nullptr,
bool OwnsHeaderSearch = false,
TranslationUnitKind TUKind = TU_Complete);

diff  --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index f0381c18a8b6f77..6dfe7c0ccc50b33 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -77,7 +77,7 @@ LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry)
 ExternalPreprocessorSource::~ExternalPreprocessorSource() = default;
 
 Preprocessor::Preprocessor(std::shared_ptr PPOpts,
-   DiagnosticsEngine , LangOptions ,
+   DiagnosticsEngine , const LangOptions ,
SourceManager , HeaderSearch ,
ModuleLoader ,
IdentifierInfoLookup *IILookup, bool OwnsHeaders,



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


[clang] [clang][Diagnostics] Make 'note' color CYAN (PR #66997)

2023-09-26 Thread Timm Baeder via cfe-commits

tbaederr wrote:

I keep forgetting to add release notes and @AaronBallman hasn't reminded me in 
a while - is this work a release note?

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


[clang] [clang-format] Split TT_AttributeParen (PR #67396)

2023-09-26 Thread Owen Pan via cfe-commits

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


[clang] cef9f40 - [clang-format] Split TT_AttributeParen (#67396)

2023-09-26 Thread via cfe-commits

Author: Owen Pan
Date: 2023-09-26T20:27:15-07:00
New Revision: cef9f40cd4feb395e1993f086619abd9ed016a17

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

LOG: [clang-format] Split TT_AttributeParen (#67396)

Replaced TT_AttributeParen with TT_AttributeLParen and
TT_AttributeRParen.

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 68103c45b0b9463..bd7a2020589b88f 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1336,7 +1336,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
(PreviousNonComment->ClosesTemplateDeclaration ||
 PreviousNonComment->ClosesRequiresClause ||
 PreviousNonComment->isOneOf(
-TT_AttributeParen, TT_AttributeSquare, TT_FunctionAnnotationRParen,
+TT_AttributeRParen, TT_AttributeSquare, 
TT_FunctionAnnotationRParen,
 TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||
   (!Style.IndentWrappedFunctionNames &&
NextNonComment->isOneOf(tok::kw_operator, TT_FunctionDeclarationName))) 
{

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 0605ac9da7219f2..986849abd8f9206 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -30,8 +30,9 @@ namespace format {
   TYPE(ArrayInitializerLSquare)
\
   TYPE(ArraySubscriptLSquare)  
\
   TYPE(AttributeColon) 
\
+  TYPE(AttributeLParen)
\
   TYPE(AttributeMacro) 
\
-  TYPE(AttributeParen) 
\
+  TYPE(AttributeRParen)
\
   TYPE(AttributeSquare)
\
   TYPE(BinaryOperator) 
\
   TYPE(BitFieldColon)  
\

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 8162d6ddb8c16e4..95d039b459b43e8 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -377,7 +377,7 @@ class AnnotatingParser {
 // detected one yet.
 if (PrevNonComment && OpeningParen.is(TT_Unknown)) {
   if (PrevNonComment->is(tok::kw___attribute)) {
-OpeningParen.setType(TT_AttributeParen);
+OpeningParen.setType(TT_AttributeLParen);
   } else if (PrevNonComment->isOneOf(TT_TypenameMacro, tok::kw_decltype,
  tok::kw_typeof,
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) tok::kw___##Trait,
@@ -475,8 +475,8 @@ class AnnotatingParser {
   }
 }
 
-if (OpeningParen.is(TT_AttributeParen))
-  CurrentToken->setType(TT_AttributeParen);
+if (OpeningParen.is(TT_AttributeLParen))
+  CurrentToken->setType(TT_AttributeRParen);
 if (OpeningParen.is(TT_TypeDeclarationParen))
   CurrentToken->setType(TT_TypeDeclarationParen);
 if (OpeningParen.Previous &&
@@ -2382,11 +2382,15 @@ class AnnotatingParser {
   // Strip trailing qualifiers such as const or volatile when checking
   // whether the parens could be a cast to a pointer/reference type.
   while (T) {
-if (T->is(TT_AttributeParen)) {
+if (T->is(TT_AttributeRParen)) {
   // Handle `x = (foo *__attribute__((foo)))`:
-  if (T->MatchingParen && T->MatchingParen->Previous &&
-  T->MatchingParen->Previous->is(tok::kw___attribute)) {
-T = T->MatchingParen->Previous->Previous;
+  assert(T->is(tok::r_paren));
+  assert(T->MatchingParen);
+  assert(T->MatchingParen->is(tok::l_paren));
+  assert(T->MatchingParen->is(TT_AttributeLParen));
+  if (const auto *Tok = T->MatchingParen->Previous;
+  Tok && Tok->is(tok::kw___attribute)) {
+T = Tok->Previous;
 continue;
   }
 } else if (T->is(TT_AttributeSquare)) {
@@ -3993,7 +3997,7 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine ,
 // after pointer qualifiers.
 if ((Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_After ||
  Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Both) &&

[clang-tools-extra] Adding Separate OpenMP Offloading Backend to `libcxx/include/__algorithm/pstl_backends` (PR #66968)

2023-09-26 Thread Anton Rydahl via cfe-commits

https://github.com/AntonRydahl updated 
https://github.com/llvm/llvm-project/pull/66968

>From b35340e47de896c9933c54ce617538c46cf01488 Mon Sep 17 00:00:00 2001
From: AntonRydahl 
Date: Wed, 20 Sep 2023 17:06:10 -0700
Subject: [PATCH 1/8] Adding OpenMP Offloading Backend for C++ Parallel
 Algorithms

---
 libcxx/CMakeLists.txt | 14 +++
 libcxx/include/CMakeLists.txt |  5 +
 libcxx/include/__algorithm/pstl_backend.h |  8 ++
 .../__algorithm/pstl_backends/gpu_backend.h   | 21 +
 .../pstl_backends/gpu_backends/backend.h  | 33 +++
 .../pstl_backends/gpu_backends/fill.h | 59 
 .../pstl_backends/gpu_backends/for_each.h | 59 
 .../pstl_backends/gpu_backends/omp_offload.h  | 91 +++
 libcxx/include/__config_site.in   |  1 +
 9 files changed, 291 insertions(+)
 create mode 100644 libcxx/include/__algorithm/pstl_backends/gpu_backend.h
 create mode 100644 
libcxx/include/__algorithm/pstl_backends/gpu_backends/backend.h
 create mode 100644 libcxx/include/__algorithm/pstl_backends/gpu_backends/fill.h
 create mode 100644 
libcxx/include/__algorithm/pstl_backends/gpu_backends/for_each.h
 create mode 100644 
libcxx/include/__algorithm/pstl_backends/gpu_backends/omp_offload.h

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index bb2898b799bcef9..43d2a448de79584 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -290,6 +290,8 @@ option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection 
and force use of win32
 option(LIBCXX_HAS_EXTERNAL_THREAD_API
   "Build libc++ with an externalized threading API.
This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
+option(LIBCXX_ENABLE_GPU_OFFLOAD 
+  "Build libc++ with support for GPU offload" OFF)
 
 if (LIBCXX_ENABLE_THREADS)
   set(LIBCXX_PSTL_CPU_BACKEND "std_thread" CACHE STRING "Which PSTL CPU 
backend to use")
@@ -297,6 +299,14 @@ else()
   set(LIBCXX_PSTL_CPU_BACKEND "serial" CACHE STRING "Which PSTL CPU backend to 
use")
 endif()
 
+if (NOT DEFINED LIBCXX_PSTL_GPU_BACKEND)
+  if (${LIBCXX_ENABLE_GPU_OFFLOAD})
+set(LIBCXX_PSTL_GPU_BACKEND "omp_offload" CACHE STRING "Which PSTL GPU 
backend to use")
+  else()
+set(LIBCXX_PSTL_GPU_BACKEND "none" CACHE STRING "Which PSTL GPU backend to 
use")
+  endif()
+endif()
+
 # Misc options 
 # FIXME: Turn -pedantic back ON. It is currently off because it warns
 # about #include_next which is used everywhere.
@@ -809,6 +819,10 @@ else()
Valid backends are: serial, std_thread and libdispatch")
 endif()
 
+if (LIBCXX_PSTL_GPU_BACKEND STREQUAL "omp_offload")
+  config_define(1 _LIBCPP_PSTL_GPU_BACKEND_OMP_OFFLOAD)
+endif()
+
 if (LIBCXX_ABI_DEFINES)
   set(abi_defines)
   foreach (abi_define ${LIBCXX_ABI_DEFINES})
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..a3d72df61a86dde 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -85,6 +85,11 @@ set(files
   __algorithm/pstl_backends/cpu_backends/thread.h
   __algorithm/pstl_backends/cpu_backends/transform.h
   __algorithm/pstl_backends/cpu_backends/transform_reduce.h
+  __algorithm/pstl_backends/gpu_backend.h
+  __algorithm/pstl_backends/gpu_backends/backend.h
+  __algorithm/pstl_backends/gpu_backends/fill.h
+  __algorithm/pstl_backends/gpu_backends/for_each.h
+  __algorithm/pstl_backends/gpu_backends/omp_offload.h
   __algorithm/pstl_copy.h
   __algorithm/pstl_count.h
   __algorithm/pstl_fill.h
diff --git a/libcxx/include/__algorithm/pstl_backend.h 
b/libcxx/include/__algorithm/pstl_backend.h
index 93372f019031b63..f051e0ce9be13c3 100644
--- a/libcxx/include/__algorithm/pstl_backend.h
+++ b/libcxx/include/__algorithm/pstl_backend.h
@@ -10,6 +10,7 @@
 #define _LIBCPP___ALGORITHM_PSTL_BACKEND_H
 
 #include <__algorithm/pstl_backends/cpu_backend.h>
+#include <__algorithm/pstl_backends/gpu_backend.h>
 #include <__config>
 #include 
 
@@ -179,10 +180,17 @@ struct __select_backend {
   using type = __cpu_backend_tag;
 };
 
+#   if defined(_LIBCPP_PSTL_GPU_BACKEND_OMP_OFFLOAD)
+template <>
+struct __select_backend {
+  using type = __gpu_backend_tag;
+};
+#   else
 template <>
 struct __select_backend {
   using type = __cpu_backend_tag;
 };
+#   endif
 
 #  else
 
diff --git a/libcxx/include/__algorithm/pstl_backends/gpu_backend.h 
b/libcxx/include/__algorithm/pstl_backends/gpu_backend.h
new file mode 100644
index 000..46a85f77b5deb99
--- /dev/null
+++ b/libcxx/include/__algorithm/pstl_backends/gpu_backend.h
@@ -0,0 +1,21 @@
+//===--===//
+//
+// 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
+//

[clang] [clang][hexagon] Add support for -nolibc (PR #67515)

2023-09-26 Thread via cfe-commits

https://github.com/androm3da created 
https://github.com/llvm/llvm-project/pull/67515

None

>From 41a8826e647917042e8e5eaf0922f60e16d98839 Mon Sep 17 00:00:00 2001
From: Brian Cain 
Date: Tue, 26 Sep 2023 19:57:47 -0700
Subject: [PATCH] [clang][hexagon] Add support for -nolibc

---
 clang/lib/Driver/ToolChains/Hexagon.cpp |  6 +++--
 clang/test/Driver/hexagon-toolchain-elf.c   | 26 -
 clang/test/Driver/hexagon-toolchain-linux.c | 12 ++
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index e7dca1053dc8d8a..d81e022708932f7 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -377,7 +377,8 @@ constructHexagonLinkArgs(Compilation , const JobAction 
,
 linkXRayRuntimeDeps(HTC, Args, CmdArgs);
 
   CmdArgs.push_back("-lclang_rt.builtins-hexagon");
-  CmdArgs.push_back("-lc");
+  if (!Args.hasArg(options::OPT_nolibc))
+CmdArgs.push_back("-lc");
 }
 if (D.CCCIsCXX()) {
   if (HTC.ShouldLinkCXXStdlib(Args))
@@ -470,7 +471,8 @@ constructHexagonLinkArgs(Compilation , const JobAction 
,
 if (!IsShared) {
   for (StringRef Lib : OsLibs)
 CmdArgs.push_back(Args.MakeArgString("-l" + Lib));
-  CmdArgs.push_back("-lc");
+  if (!Args.hasArg(options::OPT_nolibc))
+CmdArgs.push_back("-lc");
 }
 CmdArgs.push_back("-lgcc");
 
diff --git a/clang/test/Driver/hexagon-toolchain-elf.c 
b/clang/test/Driver/hexagon-toolchain-elf.c
index 039b87347436d51..48b9aa2c22bffaa 100644
--- a/clang/test/Driver/hexagon-toolchain-elf.c
+++ b/clang/test/Driver/hexagon-toolchain-elf.c
@@ -330,7 +330,7 @@
 // CHECK335: 
"{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/G0/fini.o"
 
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
-
-// -nostdlib, -nostartfiles, -nodefaultlibs
+// -nostdlib, -nostartfiles, -nodefaultlibs, -nolibc
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
-
 // RUN: %clangxx -### -target hexagon-unknown-elf \
 // RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
@@ -401,6 +401,30 @@
 // CHECK338-NOT: "--end-group"
 // CHECK338: 
"{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/fini.o"
 
+// RUN: %clangxx -### -target hexagon-unknown-elf \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   -nolibc \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-NOLIBC %s
+// CHECK-NOLIBC: "-cc1"
+// CHECK-NOLIBC: {{hexagon-link|ld}}
+// CHECK-NOLIBC: 
"{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/crt0_standalone.o"
+// CHECK-NOLIBC: 
"{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/crt0.o"
+// CHECK-NOLIBC: 
"{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/init.o"
+// CHECK-NOLIBC: 
"-L{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60"
+// CHECK-NOLIBC: "-L{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib"
+// CHECK-NOLIBC: "{{[^"]+}}.o"
+// CHECK-NOLIBC: "-lstdc++"
+// CHECK-NOLIBC: "-lm"
+// CHECK-NOLIBC: "--start-group"
+// CHECK-NOLIBC: "-lstandalone"
+// CHECK-NOLIBC-NOT: "-lc"
+// CHECK-NOLIBC: "-lgcc"
+// CHECK-NOLIBC: "--end-group"
+// CHECK-NOLIBC: 
"{{.*}}/Inputs/hexagon_tree/Tools/bin/../target/hexagon/lib/v60/fini.o"
+
+
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
-
 // -moslib
 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
-
diff --git a/clang/test/Driver/hexagon-toolchain-linux.c 
b/clang/test/Driver/hexagon-toolchain-linux.c
index 423306affdce3ac..90a92900020fcda 100644
--- a/clang/test/Driver/hexagon-toolchain-linux.c
+++ b/clang/test/Driver/hexagon-toolchain-linux.c
@@ -68,6 +68,18 @@
 // CHECK004-NOT:   "-lclang_rt.builtins-hexagon"
 // CHECK004-NOT:   "-lc"
 // 
-
+// Passing --musl -nolibc
+// 
-
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -nolibc \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-NOLIBC %s
+// CHECK-NOLIBC:   
"-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK-NOLIBC:   
"{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o"
+// CHECK-NOLIBC-NOT:   "-lc"
+// 
-
 // Not Passing -fno-use-init-array when musl is selected
 // 
-
 // RUN: %clang -### -target hexagon-unknown-linux-musl \


[clang-tools-extra] Adding Separate OpenMP Offloading Backend to `libcxx/include/__algorithm/pstl_backends` (PR #66968)

2023-09-26 Thread Anton Rydahl via cfe-commits

https://github.com/AntonRydahl updated 
https://github.com/llvm/llvm-project/pull/66968

>From b35340e47de896c9933c54ce617538c46cf01488 Mon Sep 17 00:00:00 2001
From: AntonRydahl 
Date: Wed, 20 Sep 2023 17:06:10 -0700
Subject: [PATCH 1/7] Adding OpenMP Offloading Backend for C++ Parallel
 Algorithms

---
 libcxx/CMakeLists.txt | 14 +++
 libcxx/include/CMakeLists.txt |  5 +
 libcxx/include/__algorithm/pstl_backend.h |  8 ++
 .../__algorithm/pstl_backends/gpu_backend.h   | 21 +
 .../pstl_backends/gpu_backends/backend.h  | 33 +++
 .../pstl_backends/gpu_backends/fill.h | 59 
 .../pstl_backends/gpu_backends/for_each.h | 59 
 .../pstl_backends/gpu_backends/omp_offload.h  | 91 +++
 libcxx/include/__config_site.in   |  1 +
 9 files changed, 291 insertions(+)
 create mode 100644 libcxx/include/__algorithm/pstl_backends/gpu_backend.h
 create mode 100644 
libcxx/include/__algorithm/pstl_backends/gpu_backends/backend.h
 create mode 100644 libcxx/include/__algorithm/pstl_backends/gpu_backends/fill.h
 create mode 100644 
libcxx/include/__algorithm/pstl_backends/gpu_backends/for_each.h
 create mode 100644 
libcxx/include/__algorithm/pstl_backends/gpu_backends/omp_offload.h

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index bb2898b799bcef9..43d2a448de79584 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -290,6 +290,8 @@ option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection 
and force use of win32
 option(LIBCXX_HAS_EXTERNAL_THREAD_API
   "Build libc++ with an externalized threading API.
This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
+option(LIBCXX_ENABLE_GPU_OFFLOAD 
+  "Build libc++ with support for GPU offload" OFF)
 
 if (LIBCXX_ENABLE_THREADS)
   set(LIBCXX_PSTL_CPU_BACKEND "std_thread" CACHE STRING "Which PSTL CPU 
backend to use")
@@ -297,6 +299,14 @@ else()
   set(LIBCXX_PSTL_CPU_BACKEND "serial" CACHE STRING "Which PSTL CPU backend to 
use")
 endif()
 
+if (NOT DEFINED LIBCXX_PSTL_GPU_BACKEND)
+  if (${LIBCXX_ENABLE_GPU_OFFLOAD})
+set(LIBCXX_PSTL_GPU_BACKEND "omp_offload" CACHE STRING "Which PSTL GPU 
backend to use")
+  else()
+set(LIBCXX_PSTL_GPU_BACKEND "none" CACHE STRING "Which PSTL GPU backend to 
use")
+  endif()
+endif()
+
 # Misc options 
 # FIXME: Turn -pedantic back ON. It is currently off because it warns
 # about #include_next which is used everywhere.
@@ -809,6 +819,10 @@ else()
Valid backends are: serial, std_thread and libdispatch")
 endif()
 
+if (LIBCXX_PSTL_GPU_BACKEND STREQUAL "omp_offload")
+  config_define(1 _LIBCPP_PSTL_GPU_BACKEND_OMP_OFFLOAD)
+endif()
+
 if (LIBCXX_ABI_DEFINES)
   set(abi_defines)
   foreach (abi_define ${LIBCXX_ABI_DEFINES})
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..a3d72df61a86dde 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -85,6 +85,11 @@ set(files
   __algorithm/pstl_backends/cpu_backends/thread.h
   __algorithm/pstl_backends/cpu_backends/transform.h
   __algorithm/pstl_backends/cpu_backends/transform_reduce.h
+  __algorithm/pstl_backends/gpu_backend.h
+  __algorithm/pstl_backends/gpu_backends/backend.h
+  __algorithm/pstl_backends/gpu_backends/fill.h
+  __algorithm/pstl_backends/gpu_backends/for_each.h
+  __algorithm/pstl_backends/gpu_backends/omp_offload.h
   __algorithm/pstl_copy.h
   __algorithm/pstl_count.h
   __algorithm/pstl_fill.h
diff --git a/libcxx/include/__algorithm/pstl_backend.h 
b/libcxx/include/__algorithm/pstl_backend.h
index 93372f019031b63..f051e0ce9be13c3 100644
--- a/libcxx/include/__algorithm/pstl_backend.h
+++ b/libcxx/include/__algorithm/pstl_backend.h
@@ -10,6 +10,7 @@
 #define _LIBCPP___ALGORITHM_PSTL_BACKEND_H
 
 #include <__algorithm/pstl_backends/cpu_backend.h>
+#include <__algorithm/pstl_backends/gpu_backend.h>
 #include <__config>
 #include 
 
@@ -179,10 +180,17 @@ struct __select_backend {
   using type = __cpu_backend_tag;
 };
 
+#   if defined(_LIBCPP_PSTL_GPU_BACKEND_OMP_OFFLOAD)
+template <>
+struct __select_backend {
+  using type = __gpu_backend_tag;
+};
+#   else
 template <>
 struct __select_backend {
   using type = __cpu_backend_tag;
 };
+#   endif
 
 #  else
 
diff --git a/libcxx/include/__algorithm/pstl_backends/gpu_backend.h 
b/libcxx/include/__algorithm/pstl_backends/gpu_backend.h
new file mode 100644
index 000..46a85f77b5deb99
--- /dev/null
+++ b/libcxx/include/__algorithm/pstl_backends/gpu_backend.h
@@ -0,0 +1,21 @@
+//===--===//
+//
+// 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
+//

[clang] [mlir][affine] Check the input vector sizes to be greater than 0 (PR #65293)

2023-09-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-affine


Changes

In the process of vectorization of the affine loop, the 0 vector size causes 
the crash with building the invalid AffineForOp. We can catch the case 
beforehand propagating to the assertion.

See: https://github.com/llvm/llvm-project/issues/64262

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


3 Files Affected:

- (modified) mlir/include/mlir/Dialect/Affine/Passes.td (+2-1) 
- (modified) mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp (+5) 
- (added) mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir (+9) 


``diff
diff --git a/mlir/include/mlir/Dialect/Affine/Passes.td 
b/mlir/include/mlir/Dialect/Affine/Passes.td
index 891a6661ca87be7..1036e93a0392409 100644
--- a/mlir/include/mlir/Dialect/Affine/Passes.td
+++ b/mlir/include/mlir/Dialect/Affine/Passes.td
@@ -349,7 +349,8 @@ def AffineVectorize : Pass<"affine-super-vectorize", 
"func::FuncOp"> {
   let dependentDialects = ["vector::VectorDialect"];
   let options = [
 ListOption<"vectorSizes", "virtual-vector-size", "int64_t",
-   "Specify an n-D virtual vector size for vectorization">,
+   "Specify an n-D virtual vector size for vectorization. "
+   "This must be greater than zero.">,
 // Optionally, the fixed mapping from loop to fastest varying MemRef
 // dimension for all the MemRefs within a loop pattern:
 //   the index represents the loop depth, the value represents the k^th
diff --git a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp 
b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
index 85c2602aa266d67..a1d9c7b56c4e154 100644
--- a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
@@ -1732,6 +1732,11 @@ void Vectorize::runOnOperation() {
 return signalPassFailure();
   }
 
+  if (llvm::any_of(vectorSizes, [](int64_t size) { return size <= 0; })) {
+f.emitError("Vectorization factor must be greater than zero.");
+return signalPassFailure();
+  }
+
   DenseSet parallelLoops;
   ReductionLoopMap reductionLoops;
 
diff --git a/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir 
b/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir
new file mode 100644
index 000..396cc933e25bcf4
--- /dev/null
+++ b/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir
@@ -0,0 +1,9 @@
+// RUN: mlir-opt %s -verify-diagnostics 
--affine-super-vectorize=virtual-vector-size=0
+
+// expected-error@+1 {{Vectorization factor must be greater than zero}} 
+func.func @with_zero_vector_size(%arg0: memref<21x12x12xi1>) {
+  affine.for %arg1 = 0 to 84 step 4294967295 {
+  }
+  return
+}
+

``




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


[clang-tools-extra] [mlir][affine] Check the input vector sizes to be greater than 0 (PR #65293)

2023-09-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-affine


Changes

In the process of vectorization of the affine loop, the 0 vector size causes 
the crash with building the invalid AffineForOp. We can catch the case 
beforehand propagating to the assertion.

See: https://github.com/llvm/llvm-project/issues/64262

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


3 Files Affected:

- (modified) mlir/include/mlir/Dialect/Affine/Passes.td (+2-1) 
- (modified) mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp (+5) 
- (added) mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir (+9) 


``diff
diff --git a/mlir/include/mlir/Dialect/Affine/Passes.td 
b/mlir/include/mlir/Dialect/Affine/Passes.td
index 891a6661ca87be7..1036e93a0392409 100644
--- a/mlir/include/mlir/Dialect/Affine/Passes.td
+++ b/mlir/include/mlir/Dialect/Affine/Passes.td
@@ -349,7 +349,8 @@ def AffineVectorize : Pass<"affine-super-vectorize", 
"func::FuncOp"> {
   let dependentDialects = ["vector::VectorDialect"];
   let options = [
 ListOption<"vectorSizes", "virtual-vector-size", "int64_t",
-   "Specify an n-D virtual vector size for vectorization">,
+   "Specify an n-D virtual vector size for vectorization. "
+   "This must be greater than zero.">,
 // Optionally, the fixed mapping from loop to fastest varying MemRef
 // dimension for all the MemRefs within a loop pattern:
 //   the index represents the loop depth, the value represents the k^th
diff --git a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp 
b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
index 85c2602aa266d67..a1d9c7b56c4e154 100644
--- a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
@@ -1732,6 +1732,11 @@ void Vectorize::runOnOperation() {
 return signalPassFailure();
   }
 
+  if (llvm::any_of(vectorSizes, [](int64_t size) { return size <= 0; })) {
+f.emitError("Vectorization factor must be greater than zero.");
+return signalPassFailure();
+  }
+
   DenseSet parallelLoops;
   ReductionLoopMap reductionLoops;
 
diff --git a/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir 
b/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir
new file mode 100644
index 000..396cc933e25bcf4
--- /dev/null
+++ b/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir
@@ -0,0 +1,9 @@
+// RUN: mlir-opt %s -verify-diagnostics 
--affine-super-vectorize=virtual-vector-size=0
+
+// expected-error@+1 {{Vectorization factor must be greater than zero}} 
+func.func @with_zero_vector_size(%arg0: memref<21x12x12xi1>) {
+  affine.for %arg1 = 0 to 84 step 4294967295 {
+  }
+  return
+}
+

``




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


[clang] [mlir][affine] Check the input vector sizes to be greater than 0 (PR #65293)

2023-09-26 Thread Kai Sasaki via cfe-commits

https://github.com/Lewuathe updated 
https://github.com/llvm/llvm-project/pull/65293

>From cd1a19a5b12cbdba2654b08b04e54c8313dda696 Mon Sep 17 00:00:00 2001
From: Kai Sasaki 
Date: Tue, 5 Sep 2023 14:40:44 +0900
Subject: [PATCH 1/2] [mlir][affine] Check the input vector sizes to be greater
 than 0

---
 mlir/include/mlir/Dialect/Affine/Passes.td| 3 ++-
 mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp | 5 +
 mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir  | 9 +
 3 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir

diff --git a/mlir/include/mlir/Dialect/Affine/Passes.td 
b/mlir/include/mlir/Dialect/Affine/Passes.td
index 891a6661ca87be7..1036e93a0392409 100644
--- a/mlir/include/mlir/Dialect/Affine/Passes.td
+++ b/mlir/include/mlir/Dialect/Affine/Passes.td
@@ -349,7 +349,8 @@ def AffineVectorize : Pass<"affine-super-vectorize", 
"func::FuncOp"> {
   let dependentDialects = ["vector::VectorDialect"];
   let options = [
 ListOption<"vectorSizes", "virtual-vector-size", "int64_t",
-   "Specify an n-D virtual vector size for vectorization">,
+   "Specify an n-D virtual vector size for vectorization. "
+   "This must be greater than zero.">,
 // Optionally, the fixed mapping from loop to fastest varying MemRef
 // dimension for all the MemRefs within a loop pattern:
 //   the index represents the loop depth, the value represents the k^th
diff --git a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp 
b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
index 072e858220feae3..327616d45c90189 100644
--- a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
@@ -1732,6 +1732,11 @@ void Vectorize::runOnOperation() {
 return signalPassFailure();
   }
 
+  if (llvm::any_of(vectorSizes, [](int64_t size) { return size == 0; })) {
+f.emitError("Vectorization factor must be greater than zero.");
+return signalPassFailure();
+  }
+
   DenseSet parallelLoops;
   ReductionLoopMap reductionLoops;
 
diff --git a/mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir 
b/mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir
new file mode 100644
index 000..396cc933e25bcf4
--- /dev/null
+++ b/mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir
@@ -0,0 +1,9 @@
+// RUN: mlir-opt %s -verify-diagnostics 
--affine-super-vectorize=virtual-vector-size=0
+
+// expected-error@+1 {{Vectorization factor must be greater than zero}} 
+func.func @with_zero_vector_size(%arg0: memref<21x12x12xi1>) {
+  affine.for %arg1 = 0 to 84 step 4294967295 {
+  }
+  return
+}
+

>From c0cc18d4d5631ec586d719eb21c37d0610f5ee31 Mon Sep 17 00:00:00 2001
From: Kai Sasaki 
Date: Tue, 26 Sep 2023 15:25:05 +0900
Subject: [PATCH 2/2] Post review follow-up

---
 mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp   | 2 +-
 .../SuperVectorize/{invalid.mlir => invalid-zero-size.mlir} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename mlir/test/Dialect/Affine/SuperVectorize/{invalid.mlir => 
invalid-zero-size.mlir} (100%)

diff --git a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp 
b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
index 327616d45c90189..82623126e49006b 100644
--- a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
@@ -1732,7 +1732,7 @@ void Vectorize::runOnOperation() {
 return signalPassFailure();
   }
 
-  if (llvm::any_of(vectorSizes, [](int64_t size) { return size == 0; })) {
+  if (llvm::any_of(vectorSizes, [](int64_t size) { return size <= 0; })) {
 f.emitError("Vectorization factor must be greater than zero.");
 return signalPassFailure();
   }
diff --git a/mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir 
b/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir
similarity index 100%
rename from mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir
rename to mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir

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


[clang-tools-extra] [mlir][affine] Check the input vector sizes to be greater than 0 (PR #65293)

2023-09-26 Thread Kai Sasaki via cfe-commits

https://github.com/Lewuathe updated 
https://github.com/llvm/llvm-project/pull/65293

>From cd1a19a5b12cbdba2654b08b04e54c8313dda696 Mon Sep 17 00:00:00 2001
From: Kai Sasaki 
Date: Tue, 5 Sep 2023 14:40:44 +0900
Subject: [PATCH 1/2] [mlir][affine] Check the input vector sizes to be greater
 than 0

---
 mlir/include/mlir/Dialect/Affine/Passes.td| 3 ++-
 mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp | 5 +
 mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir  | 9 +
 3 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir

diff --git a/mlir/include/mlir/Dialect/Affine/Passes.td 
b/mlir/include/mlir/Dialect/Affine/Passes.td
index 891a6661ca87be7..1036e93a0392409 100644
--- a/mlir/include/mlir/Dialect/Affine/Passes.td
+++ b/mlir/include/mlir/Dialect/Affine/Passes.td
@@ -349,7 +349,8 @@ def AffineVectorize : Pass<"affine-super-vectorize", 
"func::FuncOp"> {
   let dependentDialects = ["vector::VectorDialect"];
   let options = [
 ListOption<"vectorSizes", "virtual-vector-size", "int64_t",
-   "Specify an n-D virtual vector size for vectorization">,
+   "Specify an n-D virtual vector size for vectorization. "
+   "This must be greater than zero.">,
 // Optionally, the fixed mapping from loop to fastest varying MemRef
 // dimension for all the MemRefs within a loop pattern:
 //   the index represents the loop depth, the value represents the k^th
diff --git a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp 
b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
index 072e858220feae3..327616d45c90189 100644
--- a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
@@ -1732,6 +1732,11 @@ void Vectorize::runOnOperation() {
 return signalPassFailure();
   }
 
+  if (llvm::any_of(vectorSizes, [](int64_t size) { return size == 0; })) {
+f.emitError("Vectorization factor must be greater than zero.");
+return signalPassFailure();
+  }
+
   DenseSet parallelLoops;
   ReductionLoopMap reductionLoops;
 
diff --git a/mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir 
b/mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir
new file mode 100644
index 000..396cc933e25bcf4
--- /dev/null
+++ b/mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir
@@ -0,0 +1,9 @@
+// RUN: mlir-opt %s -verify-diagnostics 
--affine-super-vectorize=virtual-vector-size=0
+
+// expected-error@+1 {{Vectorization factor must be greater than zero}} 
+func.func @with_zero_vector_size(%arg0: memref<21x12x12xi1>) {
+  affine.for %arg1 = 0 to 84 step 4294967295 {
+  }
+  return
+}
+

>From c0cc18d4d5631ec586d719eb21c37d0610f5ee31 Mon Sep 17 00:00:00 2001
From: Kai Sasaki 
Date: Tue, 26 Sep 2023 15:25:05 +0900
Subject: [PATCH 2/2] Post review follow-up

---
 mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp   | 2 +-
 .../SuperVectorize/{invalid.mlir => invalid-zero-size.mlir} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename mlir/test/Dialect/Affine/SuperVectorize/{invalid.mlir => 
invalid-zero-size.mlir} (100%)

diff --git a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp 
b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
index 327616d45c90189..82623126e49006b 100644
--- a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
@@ -1732,7 +1732,7 @@ void Vectorize::runOnOperation() {
 return signalPassFailure();
   }
 
-  if (llvm::any_of(vectorSizes, [](int64_t size) { return size == 0; })) {
+  if (llvm::any_of(vectorSizes, [](int64_t size) { return size <= 0; })) {
 f.emitError("Vectorization factor must be greater than zero.");
 return signalPassFailure();
   }
diff --git a/mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir 
b/mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir
similarity index 100%
rename from mlir/test/Dialect/Affine/SuperVectorize/invalid.mlir
rename to mlir/test/Dialect/Affine/SuperVectorize/invalid-zero-size.mlir

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


[PATCH] D144136: Add a "remark" to report on array accesses

2023-09-26 Thread Kees Cook via Phabricator via cfe-commits
kees added a comment.

In D144136#4651030 , @void wrote:

> or can it be simplified into something like this:
>
>   array-bounds.c:341:2: remark: accessing flexible array, counted by 'count', 
> with 'index - 1' [-Rarray-bounds]
>  341 | TEST_ACCESS(p, array, index, SHOULD_TRAP);
>  | ^

Yeah, this is totally enough. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144136

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


[clang] [Clang] Fix crash when visting a fold expression in a default argument (PR #67514)

2023-09-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

CheckDefaultArgumentVisitor::Visit(...) assumes that the children of Expr will 
not be NULL. This is not a valid assumption and when we have a CXXFoldExpr the 
children can be NULL and this causes a crash.

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

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+2-1) 
- (modified) clang/test/SemaTemplate/cxx1z-fold-expressions.cpp (+8) 


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0091e0ecf6f3986..302e944d5d74f1c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -86,7 +86,8 @@ class CheckDefaultArgumentVisitor
 bool CheckDefaultArgumentVisitor::VisitExpr(const Expr *Node) {
   bool IsInvalid = false;
   for (const Stmt *SubStmt : Node->children())
-IsInvalid |= Visit(SubStmt);
+if (SubStmt)
+  IsInvalid |= Visit(SubStmt);
   return IsInvalid;
 }
 
diff --git a/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp 
b/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
index 518eaf0e05239e0..47a252eb335f6e5 100644
--- a/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
+++ b/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
@@ -124,3 +124,11 @@ namespace PR30738 {
   int test_h3 = h(1, 2, 3);
   N::S test_h4 = h(N::S(), N::S(), N::S()); // expected-note 
{{instantiation of}}
 }
+
+namespace GH67395 {
+template 
+bool f();
+
+template 
+void g(bool = (f() || ...));
+}

``




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


[clang] [Clang] Fix crash when visting a fold expression in a default argument (PR #67514)

2023-09-26 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik created 
https://github.com/llvm/llvm-project/pull/67514

CheckDefaultArgumentVisitor::Visit(...) assumes that the children of Expr will 
not be NULL. This is not a valid assumption and when we have a CXXFoldExpr the 
children can be NULL and this causes a crash.

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

>From 2c8147f4f781ad8eaef188b294ce3588069f1c01 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Tue, 26 Sep 2023 18:55:44 -0700
Subject: [PATCH] [Clang] Fix crash when visting a fold expression in a default
 argument

CheckDefaultArgumentVisitor::Visit(...) assumes that the children of Expr will
not be NULL. This is not a valid assumption and when we have a CXXFoldExpr
the children can be NULL and this causes a crash.

Fixes: https://github.com/llvm/llvm-project/issues/67395
---
 clang/lib/Sema/SemaDeclCXX.cpp | 3 ++-
 clang/test/SemaTemplate/cxx1z-fold-expressions.cpp | 8 
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0091e0ecf6f3986..302e944d5d74f1c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -86,7 +86,8 @@ class CheckDefaultArgumentVisitor
 bool CheckDefaultArgumentVisitor::VisitExpr(const Expr *Node) {
   bool IsInvalid = false;
   for (const Stmt *SubStmt : Node->children())
-IsInvalid |= Visit(SubStmt);
+if (SubStmt)
+  IsInvalid |= Visit(SubStmt);
   return IsInvalid;
 }
 
diff --git a/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp 
b/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
index 518eaf0e05239e0..47a252eb335f6e5 100644
--- a/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
+++ b/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
@@ -124,3 +124,11 @@ namespace PR30738 {
   int test_h3 = h(1, 2, 3);
   N::S test_h4 = h(N::S(), N::S(), N::S()); // expected-note 
{{instantiation of}}
 }
+
+namespace GH67395 {
+template 
+bool f();
+
+template 
+void g(bool = (f() || ...));
+}

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


[clang-tools-extra] [libcxx] Allow string to use SSO in constant evaluation. (PR #66576)

2023-09-26 Thread Shafik Yaghmour via cfe-commits


@@ -0,0 +1,22 @@
+//===--===//
+//
+// 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
+
+// Ensure that strings which fit within the SSO size can be 
constant-initialized

shafik wrote:

I think I would also like to see some Sema tests as well, do we expect 
something like this to work: https://godbolt.org/z/x8EvdGfoq

Currently it does not for libstdc++ but does on MSVC.

```cpp
#include 

constexpr std::string f() {
std::string s = "hello world";

return s;
}

void g() {
constexpr auto s = f();
}
```

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


[clang] [libcxx] Allow string to use SSO in constant evaluation. (PR #66576)

2023-09-26 Thread Shafik Yaghmour via cfe-commits

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


[clang-tools-extra] [libcxx] Allow string to use SSO in constant evaluation. (PR #66576)

2023-09-26 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

I think this is fine but I agree we should have a compat warning for this and I 
would like to see more testing as well.

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


[clang-tools-extra] [libcxx] Allow string to use SSO in constant evaluation. (PR #66576)

2023-09-26 Thread Shafik Yaghmour via cfe-commits

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


[clang] 4d5d9a5 - Revert "[Coverage] Allow Clang coverage to be used with debug info correlation."

2023-09-26 Thread Zequan Wu via cfe-commits

Author: Zequan Wu
Date: 2023-09-26T20:57:09-04:00
New Revision: 4d5d9a539058c87b42b472daedfb95377f5e1612

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

LOG: Revert "[Coverage] Allow Clang coverage to be used with debug info 
correlation."

This reverts commit 32db121b29f78e4c41116b2a8f1c730f9522b202 and subsequent 
commits.

This causes time regression on llvm-cov even with debug info correlation off.

Added: 
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll

Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp
llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
llvm/include/llvm/ProfileData/InstrProfCorrelator.h
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/lib/ProfileData/InstrProfCorrelator.cpp
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Removed: 
clang/test/CodeGen/coverage-profile-raw-version.c
compiler-rt/test/profile/Linux/coverage-debug-info-correlate.cpp

llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-byte-coverage.ll

llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll



diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 32c67739915380c..76ed10091b025be 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -31,10 +31,6 @@
 // is textually included.
 #define COVMAP_V3
 
-namespace llvm {
-extern cl::opt DebugInfoCorrelate;
-} // namespace llvm
-
 static llvm::cl::opt EmptyLineCommentCoverage(
 "emptyline-comment-coverage",
 llvm::cl::desc("Emit emptylines and comment lines as skipped regions (only 
"
@@ -1835,22 +1831,6 @@ void CoverageMappingModuleGen::emit() {
  llvm::GlobalValue::InternalLinkage, NamesArrVal,
  llvm::getCoverageUnusedNamesVarName());
   }
-  const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
-  llvm::Type *IntTy64 = llvm::Type::getInt64Ty(Ctx);
-  uint64_t ProfileVersion = INSTR_PROF_RAW_VERSION;
-  if (llvm::DebugInfoCorrelate)
-ProfileVersion |= VARIANT_MASK_DBG_CORRELATE;
-  auto *VersionVariable = new llvm::GlobalVariable(
-  CGM.getModule(), llvm::Type::getInt64Ty(Ctx), true,
-  llvm::GlobalValue::WeakAnyLinkage,
-  llvm::Constant::getIntegerValue(IntTy64, llvm::APInt(64, 
ProfileVersion)),
-  VarName);
-  VersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility);
-  llvm::Triple TT(CGM.getModule().getTargetTriple());
-  if (TT.supportsCOMDAT()) {
-VersionVariable->setLinkage(llvm::GlobalValue::ExternalLinkage);
-VersionVariable->setComdat(CGM.getModule().getOrInsertComdat(VarName));
-  }
 }
 
 unsigned CoverageMappingModuleGen::getFileID(FileEntryRef File) {

diff  --git a/clang/test/CodeGen/coverage-profile-raw-version.c 
b/clang/test/CodeGen/coverage-profile-raw-version.c
deleted file mode 100644
index 749dce50298f025..000
--- a/clang/test/CodeGen/coverage-profile-raw-version.c
+++ /dev/null
@@ -1,9 +0,0 @@
-// RUN: %clang_cc1 -debug-info-kind=standalone -fprofile-instrument=clang 
-fcoverage-mapping -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -debug-info-kind=standalone -mllvm -debug-info-correlate 
-fprofile-instrument=clang -fcoverage-mapping -emit-llvm -o - %s | FileCheck %s 
--check-prefix=DEBUG_INFO
-
-// CHECK: @__llvm_profile_raw_version = {{.*}}constant i64 8
-// DEBUG_INFO: @__llvm_profile_raw_version = {{.*}}constant i64 
576460752303423496
-
-int main() {
-return 0;
-}

diff  --git a/compiler-rt/test/profile/Linux/coverage-debug-info-correlate.cpp 
b/compiler-rt/test/profile/Linux/coverage-debug-info-correlate.cpp
deleted file mode 100644
index 06901de4a24291a..000
--- a/compiler-rt/test/profile/Linux/coverage-debug-info-correlate.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-// Test debug info correlate with clang coverage.
-
-// Test the case when there is no __llvm_prf_names in the binary.
-// RUN: %clang_profgen -o %t.normal -fcoverage-mapping 
%S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%S/../Inputs/instrprof-debug-info-correlate-foo.cpp
-// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.normal
-// RUN: llvm-profdata merge -o %t.normal.profdata %t.profraw
-
-// RUN: %clang_profgen -o %t -g -mllvm --debug-info-correlate 
-fcoverage-mapping %S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%S/../Inputs/instrprof-debug-info-correlate-foo.cpp
-// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t
-// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t %t.proflite
-
-// RUN: 
diff  <(llvm-profdata show --all-functions --counts %t.normal.profdata) 
<(llvm-profdata show 

[libunwind] [libunwind][nfc] Avoid type warning of debug printf (PR #67390)

2023-09-26 Thread Alexander Richardson via cfe-commits

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

Change LGTM assuming CI is also happy.

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


[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits


@@ -0,0 +1,320 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+
+namespace llvm {
+/// A vector that allocates memory in pages.
+///
+/// Order is kept, but memory is allocated only when one element of the page is
+/// accessed. This introduces a level of indirection, but it is useful when you
+/// have a sparsely initialised vector where the full size is allocated 
upfront.
+///
+/// As a side effect the elements are initialised later than in a normal 
vector.
+/// On the first access to one of the elements of a given page all, the 
elements
+/// of the page are initialised. This also means that the elements of the page
+/// are initialised beyond the size of the vector.
+///
+/// Similarly on destruction the elements are destroyed only when the page is
+/// not needed anymore, delaying invoking the destructor of the elements.
+///
+/// Notice that this does not have iterators, because if you have iterators it
+/// probably means you are going to touch all the memory in any case, so better
+/// use a std::vector in the first place.
+template  class PagedVector {
+  static_assert(PageSize > 1, "PageSize must be greater than 0. Most likely "
+  "you want it to be greater than 16.");
+  /// The actual number of element in the vector which can be accessed.
+  size_t Size = 0;
+
+  /// The position of the initial element of the page in the Data vector.
+  /// Pages are allocated contiguously in the Data vector.
+  mutable SmallVector PageToDataPtrs;
+  /// Actual page data. All the page elements are added to this vector on the
+  /// first access of any of the elements of the page. Elements default
+  /// constructed and elements of the page are stored contiguously. The order 
of
+  /// the elements however depends on the order of access of the pages.
+  PointerIntPair Allocator;
+
+  constexpr static T *InvalidPage = nullptr;
+
+public:
+  using value_type = T;
+
+  /// Default constructor. We build our own allocator and mark it as such with
+  /// `true` in the second pair element.
+  PagedVector() : Allocator(new BumpPtrAllocator, true) {}
+  PagedVector(BumpPtrAllocator *A) : Allocator(A, false) {
+assert(A != nullptr && "Allocator cannot be null");
+  }
+
+  ~PagedVector() {
+clear();
+// If we own the allocator, delete it.
+if (Allocator.getInt())
+  delete Allocator.getPointer();
+  }
+
+  /// Look up an element at position `Index`.
+  /// If the associated page is not filled, it will be filled with default
+  /// constructed elements. If the associated page is filled, return the
+  /// element.
+  T [](size_t Index) const {
+assert(Index < Size);
+assert(Index / PageSize < PageToDataPtrs.size());
+T * = PageToDataPtrs[Index / PageSize];
+// If the page was not yet allocated, allocate it.
+if (PagePtr == InvalidPage) {
+  T *NewPagePtr = Allocator.getPointer()->template Allocate(PageSize);
+  // We need to invoke the default constructor on all the elements of the
+  // page.
+  std::uninitialized_value_construct_n(NewPagePtr, PageSize);
+
+  PagePtr = NewPagePtr;
+}
+// Dereference the element in the page.
+return PagePtr[Index % PageSize];
+  }
+
+  /// Return the capacity of the vector. I.e. the maximum size it can be
+  /// expanded to with the resize method without allocating more pages.
+  [[nodiscard]] size_t capacity() const {
+return PageToDataPtrs.size() * PageSize;
+  }
+
+  /// Return the size of the vector. I.e. the maximum index that can be
+  /// accessed, i.e. the maximum value which was used as argument of the
+  /// resize method.
+  [[nodiscard]] size_t size() const { return Size; }
+
+  /// Resize the vector. Notice that the constructor of the elements will not
+  /// be invoked until an element of a given page is accessed, at which point
+  /// all the elements of the page will be constructed.
+  ///
+  /// If the new size is smaller than the current size, the elements of the
+  /// pages that are not needed anymore will be destroyed, however, elements of
+  /// the last page will not be destroyed.
+  ///
+  /// For these reason the usage of this vector is discouraged if you rely
+  /// on the construction / destructor of the elements to be invoked.
+  void 

[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits


@@ -0,0 +1,322 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+#include 
+
+namespace llvm {
+// A vector that allocates memory in pages.
+// Order is kept, but memory is allocated only when one element of the page is
+// accessed. This introduces a level of indirection, but it is useful when you
+// have a sparsely initialised vector where the full size is allocated upfront
+// with the default constructor and elements are initialised later, on first
+// access.
+//
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+//
+// Pages are allocated in SLAB_SIZE chunks, using the BumpPtrAllocator.
+template 
+class PagedVector {
+  static_assert(PAGE_SIZE > 0, "PAGE_SIZE must be greater than 0. Most likely "
+   "you want it to be greater than 16.");
+  // The actual number of element in the vector which can be accessed.
+  std::size_t Size = 0;
+
+  // The position of the initial element of the page in the Data vector.
+  // Pages are allocated contiguously in the Data vector.
+  mutable std::vector PageToDataIdx;
+  // Actual page data. All the page elements are added to this vector on the
+  // first access of any of the elements of the page. Elements default
+  // constructed and elements of the page are stored contiguously. The order of
+  // the elements however depends on the order of access of the pages.
+  PointerIntPair Allocator;
+
+  constexpr static uintptr_t InvalidPage = SIZE_MAX;
+
+public:
+  using value_type = T;
+
+  // Default constructor. We build our own allocator.
+  PagedVector() : Allocator(new BumpPtrAllocator, true) {}
+  PagedVector(BumpPtrAllocator *A) : Allocator(A, false) {}
+
+  ~PagedVector() {
+// If we own the allocator, delete it.
+if (Allocator.getInt() == true)
+  delete Allocator.getPointer();
+  }
+
+  // Lookup an element at position i.
+  // If the associated page is not filled, it will be filled with default
+  // constructed elements. If the associated page is filled, return the 
element.
+  T [](std::size_t Index) const {
+assert(Index < Size);
+assert(Index / PAGE_SIZE < PageToDataIdx.size());
+uintptr_t  = PageToDataIdx[Index / PAGE_SIZE];
+// If the page was not yet allocated, allocate it.
+if (PagePtr == InvalidPage) {
+  T *NewPagePtr = Allocator.getPointer()->template Allocate(PAGE_SIZE);
+  // We need to invoke the default constructor on all the elements of the
+  // page.
+  for (std::size_t I = 0; I < PAGE_SIZE; ++I)
+new (NewPagePtr + I) T();
+
+  PagePtr = reinterpret_cast(NewPagePtr);
+}
+// Dereference the element in the page.
+return *((Index % PAGE_SIZE) + reinterpret_cast(PagePtr));
+  }
+
+  // Return the capacity of the vector. I.e. the maximum size it can be 
expanded
+  // to with the resize method without allocating more pages.
+  [[nodiscard]] std::size_t capacity() const {
+return PageToDataIdx.size() * PAGE_SIZE;
+  }
+
+  // Return the size of the vector. I.e. the maximum index that can be
+  // accessed, i.e. the maximum value which was used as argument of the
+  // resize method.
+  [[nodiscard]] std::size_t size() const { return Size; }
+
+  // Expands the vector to the given NewSize number of elements.
+  // If the vector was smaller, allocates new pages as needed.
+  // It should be called only with NewSize >= Size.
+  void resize(std::size_t NewSize) {
+// Handle shrink case: delete the pages and update the size.
+if (NewSize < Size) {
+  std::size_t NewLastPage = (NewSize - 1) / PAGE_SIZE;
+  for (std::size_t I = NewLastPage + 1; I < PageToDataIdx.size(); ++I) {
+uintptr_t PagePtr = PageToDataIdx[I];
+if (PagePtr == InvalidPage)
+  continue;
+T *Page = reinterpret_cast(PagePtr);
+// We need to invoke the destructor on all the elements of the page.
+for (std::size_t J = 0; J < PAGE_SIZE; ++J)
+  Page[J].~T();
+Allocator.getPointer()->Deallocate(Page);
+  }
+  // Delete the extra ones in the new last page.
+  uintptr_t PagePtr = PageToDataIdx[NewLastPage];
+  if (PagePtr != InvalidPage) {
+T *Page = reinterpret_cast(PagePtr);
+// If 

[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits


@@ -0,0 +1,320 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+
+namespace llvm {
+/// A vector that allocates memory in pages.
+///
+/// Order is kept, but memory is allocated only when one element of the page is
+/// accessed. This introduces a level of indirection, but it is useful when you
+/// have a sparsely initialised vector where the full size is allocated 
upfront.
+///
+/// As a side effect the elements are initialised later than in a normal 
vector.
+/// On the first access to one of the elements of a given page all, the 
elements
+/// of the page are initialised. This also means that the elements of the page
+/// are initialised beyond the size of the vector.
+///
+/// Similarly on destruction the elements are destroyed only when the page is
+/// not needed anymore, delaying invoking the destructor of the elements.
+///
+/// Notice that this does not have iterators, because if you have iterators it
+/// probably means you are going to touch all the memory in any case, so better
+/// use a std::vector in the first place.
+template  class PagedVector {
+  static_assert(PageSize > 1, "PageSize must be greater than 0. Most likely "
+  "you want it to be greater than 16.");
+  /// The actual number of element in the vector which can be accessed.
+  size_t Size = 0;
+
+  /// The position of the initial element of the page in the Data vector.
+  /// Pages are allocated contiguously in the Data vector.
+  mutable SmallVector PageToDataPtrs;
+  /// Actual page data. All the page elements are added to this vector on the
+  /// first access of any of the elements of the page. Elements default
+  /// constructed and elements of the page are stored contiguously. The order 
of
+  /// the elements however depends on the order of access of the pages.
+  PointerIntPair Allocator;
+
+  constexpr static T *InvalidPage = nullptr;
+
+public:
+  using value_type = T;
+
+  /// Default constructor. We build our own allocator and mark it as such with
+  /// `true` in the second pair element.
+  PagedVector() : Allocator(new BumpPtrAllocator, true) {}
+  PagedVector(BumpPtrAllocator *A) : Allocator(A, false) {
+assert(A != nullptr && "Allocator cannot be null");
+  }
+
+  ~PagedVector() {
+clear();
+// If we own the allocator, delete it.
+if (Allocator.getInt())
+  delete Allocator.getPointer();
+  }
+
+  /// Look up an element at position `Index`.
+  /// If the associated page is not filled, it will be filled with default
+  /// constructed elements. If the associated page is filled, return the
+  /// element.
+  T [](size_t Index) const {
+assert(Index < Size);
+assert(Index / PageSize < PageToDataPtrs.size());
+T * = PageToDataPtrs[Index / PageSize];
+// If the page was not yet allocated, allocate it.
+if (PagePtr == InvalidPage) {
+  T *NewPagePtr = Allocator.getPointer()->template Allocate(PageSize);
+  // We need to invoke the default constructor on all the elements of the
+  // page.
+  std::uninitialized_value_construct_n(NewPagePtr, PageSize);
+
+  PagePtr = NewPagePtr;
+}
+// Dereference the element in the page.
+return PagePtr[Index % PageSize];
+  }
+
+  /// Return the capacity of the vector. I.e. the maximum size it can be
+  /// expanded to with the resize method without allocating more pages.
+  [[nodiscard]] size_t capacity() const {
+return PageToDataPtrs.size() * PageSize;
+  }
+
+  /// Return the size of the vector. I.e. the maximum index that can be
+  /// accessed, i.e. the maximum value which was used as argument of the
+  /// resize method.
+  [[nodiscard]] size_t size() const { return Size; }
+
+  /// Resize the vector. Notice that the constructor of the elements will not
+  /// be invoked until an element of a given page is accessed, at which point
+  /// all the elements of the page will be constructed.
+  ///
+  /// If the new size is smaller than the current size, the elements of the
+  /// pages that are not needed anymore will be destroyed, however, elements of
+  /// the last page will not be destroyed.
+  ///
+  /// For these reason the usage of this vector is discouraged if you rely
+  /// on the construction / destructor of the elements to be invoked.
+  void 

[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits


@@ -0,0 +1,322 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+#include 
+
+namespace llvm {
+// A vector that allocates memory in pages.
+// Order is kept, but memory is allocated only when one element of the page is
+// accessed. This introduces a level of indirection, but it is useful when you
+// have a sparsely initialised vector where the full size is allocated upfront
+// with the default constructor and elements are initialised later, on first
+// access.
+//
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+//
+// Pages are allocated in SLAB_SIZE chunks, using the BumpPtrAllocator.
+template 
+class PagedVector {
+  static_assert(PAGE_SIZE > 0, "PAGE_SIZE must be greater than 0. Most likely "
+   "you want it to be greater than 16.");
+  // The actual number of element in the vector which can be accessed.
+  std::size_t Size = 0;
+
+  // The position of the initial element of the page in the Data vector.
+  // Pages are allocated contiguously in the Data vector.
+  mutable std::vector PageToDataIdx;
+  // Actual page data. All the page elements are added to this vector on the
+  // first access of any of the elements of the page. Elements default
+  // constructed and elements of the page are stored contiguously. The order of
+  // the elements however depends on the order of access of the pages.
+  PointerIntPair Allocator;
+
+  constexpr static uintptr_t InvalidPage = SIZE_MAX;
+
+public:
+  using value_type = T;
+
+  // Default constructor. We build our own allocator.
+  PagedVector() : Allocator(new BumpPtrAllocator, true) {}
+  PagedVector(BumpPtrAllocator *A) : Allocator(A, false) {}
+
+  ~PagedVector() {

zygoloid wrote:

For now, please explicitly delete the copy operations -- right now they exist 
but don't work (and will double-free the allocator if it's owned, and will 
double-destroy the page elements, etc).

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


[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits


@@ -0,0 +1,320 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+
+namespace llvm {
+/// A vector that allocates memory in pages.
+///
+/// Order is kept, but memory is allocated only when one element of the page is
+/// accessed. This introduces a level of indirection, but it is useful when you
+/// have a sparsely initialised vector where the full size is allocated 
upfront.
+///
+/// As a side effect the elements are initialised later than in a normal 
vector.
+/// On the first access to one of the elements of a given page all, the 
elements
+/// of the page are initialised. This also means that the elements of the page
+/// are initialised beyond the size of the vector.
+///
+/// Similarly on destruction the elements are destroyed only when the page is
+/// not needed anymore, delaying invoking the destructor of the elements.
+///
+/// Notice that this does not have iterators, because if you have iterators it
+/// probably means you are going to touch all the memory in any case, so better
+/// use a std::vector in the first place.
+template  class PagedVector {
+  static_assert(PageSize > 1, "PageSize must be greater than 0. Most likely "
+  "you want it to be greater than 16.");
+  /// The actual number of element in the vector which can be accessed.
+  size_t Size = 0;
+
+  /// The position of the initial element of the page in the Data vector.
+  /// Pages are allocated contiguously in the Data vector.
+  mutable SmallVector PageToDataPtrs;
+  /// Actual page data. All the page elements are added to this vector on the
+  /// first access of any of the elements of the page. Elements default
+  /// constructed and elements of the page are stored contiguously. The order 
of
+  /// the elements however depends on the order of access of the pages.
+  PointerIntPair Allocator;
+
+  constexpr static T *InvalidPage = nullptr;
+
+public:
+  using value_type = T;
+
+  /// Default constructor. We build our own allocator and mark it as such with
+  /// `true` in the second pair element.
+  PagedVector() : Allocator(new BumpPtrAllocator, true) {}
+  PagedVector(BumpPtrAllocator *A) : Allocator(A, false) {
+assert(A != nullptr && "Allocator cannot be null");
+  }
+
+  ~PagedVector() {
+clear();
+// If we own the allocator, delete it.
+if (Allocator.getInt())
+  delete Allocator.getPointer();
+  }
+
+  /// Look up an element at position `Index`.
+  /// If the associated page is not filled, it will be filled with default
+  /// constructed elements. If the associated page is filled, return the
+  /// element.
+  T [](size_t Index) const {
+assert(Index < Size);
+assert(Index / PageSize < PageToDataPtrs.size());
+T * = PageToDataPtrs[Index / PageSize];
+// If the page was not yet allocated, allocate it.
+if (PagePtr == InvalidPage) {
+  T *NewPagePtr = Allocator.getPointer()->template Allocate(PageSize);
+  // We need to invoke the default constructor on all the elements of the
+  // page.
+  std::uninitialized_value_construct_n(NewPagePtr, PageSize);
+
+  PagePtr = NewPagePtr;
+}
+// Dereference the element in the page.
+return PagePtr[Index % PageSize];
+  }
+
+  /// Return the capacity of the vector. I.e. the maximum size it can be
+  /// expanded to with the resize method without allocating more pages.
+  [[nodiscard]] size_t capacity() const {
+return PageToDataPtrs.size() * PageSize;
+  }
+
+  /// Return the size of the vector. I.e. the maximum index that can be
+  /// accessed, i.e. the maximum value which was used as argument of the
+  /// resize method.
+  [[nodiscard]] size_t size() const { return Size; }
+
+  /// Resize the vector. Notice that the constructor of the elements will not
+  /// be invoked until an element of a given page is accessed, at which point
+  /// all the elements of the page will be constructed.
+  ///
+  /// If the new size is smaller than the current size, the elements of the
+  /// pages that are not needed anymore will be destroyed, however, elements of
+  /// the last page will not be destroyed.
+  ///
+  /// For these reason the usage of this vector is discouraged if you rely
+  /// on the construction / destructor of the elements to be invoked.
+  void 

[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits


@@ -0,0 +1,320 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+
+namespace llvm {
+/// A vector that allocates memory in pages.
+///
+/// Order is kept, but memory is allocated only when one element of the page is
+/// accessed. This introduces a level of indirection, but it is useful when you
+/// have a sparsely initialised vector where the full size is allocated 
upfront.
+///
+/// As a side effect the elements are initialised later than in a normal 
vector.
+/// On the first access to one of the elements of a given page all, the 
elements
+/// of the page are initialised. This also means that the elements of the page
+/// are initialised beyond the size of the vector.
+///
+/// Similarly on destruction the elements are destroyed only when the page is
+/// not needed anymore, delaying invoking the destructor of the elements.
+///
+/// Notice that this does not have iterators, because if you have iterators it
+/// probably means you are going to touch all the memory in any case, so better
+/// use a std::vector in the first place.

zygoloid wrote:

I think it'd be better to say that this only has iterators over the 
materialized elements, rather than that it has none at all.

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


[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits


@@ -0,0 +1,320 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+
+namespace llvm {
+/// A vector that allocates memory in pages.
+///
+/// Order is kept, but memory is allocated only when one element of the page is
+/// accessed. This introduces a level of indirection, but it is useful when you
+/// have a sparsely initialised vector where the full size is allocated 
upfront.
+///
+/// As a side effect the elements are initialised later than in a normal 
vector.
+/// On the first access to one of the elements of a given page all, the 
elements
+/// of the page are initialised. This also means that the elements of the page
+/// are initialised beyond the size of the vector.
+///
+/// Similarly on destruction the elements are destroyed only when the page is
+/// not needed anymore, delaying invoking the destructor of the elements.
+///
+/// Notice that this does not have iterators, because if you have iterators it
+/// probably means you are going to touch all the memory in any case, so better
+/// use a std::vector in the first place.
+template  class PagedVector {
+  static_assert(PageSize > 1, "PageSize must be greater than 0. Most likely "
+  "you want it to be greater than 16.");
+  /// The actual number of element in the vector which can be accessed.
+  size_t Size = 0;
+
+  /// The position of the initial element of the page in the Data vector.
+  /// Pages are allocated contiguously in the Data vector.
+  mutable SmallVector PageToDataPtrs;
+  /// Actual page data. All the page elements are added to this vector on the
+  /// first access of any of the elements of the page. Elements default
+  /// constructed and elements of the page are stored contiguously. The order 
of
+  /// the elements however depends on the order of access of the pages.
+  PointerIntPair Allocator;
+
+  constexpr static T *InvalidPage = nullptr;
+
+public:
+  using value_type = T;
+
+  /// Default constructor. We build our own allocator and mark it as such with
+  /// `true` in the second pair element.
+  PagedVector() : Allocator(new BumpPtrAllocator, true) {}
+  PagedVector(BumpPtrAllocator *A) : Allocator(A, false) {
+assert(A != nullptr && "Allocator cannot be null");
+  }
+
+  ~PagedVector() {
+clear();
+// If we own the allocator, delete it.
+if (Allocator.getInt())
+  delete Allocator.getPointer();
+  }
+
+  /// Look up an element at position `Index`.
+  /// If the associated page is not filled, it will be filled with default
+  /// constructed elements. If the associated page is filled, return the
+  /// element.
+  T [](size_t Index) const {
+assert(Index < Size);
+assert(Index / PageSize < PageToDataPtrs.size());
+T * = PageToDataPtrs[Index / PageSize];
+// If the page was not yet allocated, allocate it.
+if (PagePtr == InvalidPage) {
+  T *NewPagePtr = Allocator.getPointer()->template Allocate(PageSize);
+  // We need to invoke the default constructor on all the elements of the
+  // page.
+  std::uninitialized_value_construct_n(NewPagePtr, PageSize);
+
+  PagePtr = NewPagePtr;
+}
+// Dereference the element in the page.
+return PagePtr[Index % PageSize];
+  }
+
+  /// Return the capacity of the vector. I.e. the maximum size it can be
+  /// expanded to with the resize method without allocating more pages.
+  [[nodiscard]] size_t capacity() const {
+return PageToDataPtrs.size() * PageSize;
+  }
+
+  /// Return the size of the vector. I.e. the maximum index that can be
+  /// accessed, i.e. the maximum value which was used as argument of the
+  /// resize method.
+  [[nodiscard]] size_t size() const { return Size; }
+
+  /// Resize the vector. Notice that the constructor of the elements will not
+  /// be invoked until an element of a given page is accessed, at which point
+  /// all the elements of the page will be constructed.
+  ///
+  /// If the new size is smaller than the current size, the elements of the
+  /// pages that are not needed anymore will be destroyed, however, elements of
+  /// the last page will not be destroyed.
+  ///
+  /// For these reason the usage of this vector is discouraged if you rely
+  /// on the construction / destructor of the elements to be invoked.
+  void 

[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits


@@ -0,0 +1,322 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+#include 
+
+namespace llvm {
+// A vector that allocates memory in pages.
+// Order is kept, but memory is allocated only when one element of the page is
+// accessed. This introduces a level of indirection, but it is useful when you
+// have a sparsely initialised vector where the full size is allocated upfront
+// with the default constructor and elements are initialised later, on first
+// access.
+//
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+//
+// Pages are allocated in SLAB_SIZE chunks, using the BumpPtrAllocator.
+template 
+class PagedVector {
+  static_assert(PAGE_SIZE > 0, "PAGE_SIZE must be greater than 0. Most likely "
+   "you want it to be greater than 16.");
+  // The actual number of element in the vector which can be accessed.
+  std::size_t Size = 0;
+
+  // The position of the initial element of the page in the Data vector.
+  // Pages are allocated contiguously in the Data vector.
+  mutable std::vector PageToDataIdx;
+  // Actual page data. All the page elements are added to this vector on the
+  // first access of any of the elements of the page. Elements default
+  // constructed and elements of the page are stored contiguously. The order of
+  // the elements however depends on the order of access of the pages.
+  PointerIntPair Allocator;
+
+  constexpr static uintptr_t InvalidPage = SIZE_MAX;
+
+public:
+  using value_type = T;
+
+  // Default constructor. We build our own allocator.
+  PagedVector() : Allocator(new BumpPtrAllocator, true) {}
+  PagedVector(BumpPtrAllocator *A) : Allocator(A, false) {}
+
+  ~PagedVector() {
+// If we own the allocator, delete it.
+if (Allocator.getInt() == true)
+  delete Allocator.getPointer();
+  }
+
+  // Lookup an element at position i.
+  // If the associated page is not filled, it will be filled with default
+  // constructed elements. If the associated page is filled, return the 
element.
+  T [](std::size_t Index) const {
+assert(Index < Size);
+assert(Index / PAGE_SIZE < PageToDataIdx.size());
+uintptr_t  = PageToDataIdx[Index / PAGE_SIZE];
+// If the page was not yet allocated, allocate it.
+if (PagePtr == InvalidPage) {
+  T *NewPagePtr = Allocator.getPointer()->template Allocate(PAGE_SIZE);
+  // We need to invoke the default constructor on all the elements of the
+  // page.
+  for (std::size_t I = 0; I < PAGE_SIZE; ++I)
+new (NewPagePtr + I) T();
+
+  PagePtr = reinterpret_cast(NewPagePtr);
+}
+// Dereference the element in the page.
+return *((Index % PAGE_SIZE) + reinterpret_cast(PagePtr));
+  }
+
+  // Return the capacity of the vector. I.e. the maximum size it can be 
expanded
+  // to with the resize method without allocating more pages.
+  [[nodiscard]] std::size_t capacity() const {
+return PageToDataIdx.size() * PAGE_SIZE;
+  }
+
+  // Return the size of the vector. I.e. the maximum index that can be
+  // accessed, i.e. the maximum value which was used as argument of the
+  // resize method.
+  [[nodiscard]] std::size_t size() const { return Size; }
+
+  // Expands the vector to the given NewSize number of elements.
+  // If the vector was smaller, allocates new pages as needed.
+  // It should be called only with NewSize >= Size.
+  void resize(std::size_t NewSize) {
+// Handle shrink case: delete the pages and update the size.
+if (NewSize < Size) {
+  std::size_t NewLastPage = (NewSize - 1) / PAGE_SIZE;
+  for (std::size_t I = NewLastPage + 1; I < PageToDataIdx.size(); ++I) {
+uintptr_t PagePtr = PageToDataIdx[I];
+if (PagePtr == InvalidPage)
+  continue;
+T *Page = reinterpret_cast(PagePtr);
+// We need to invoke the destructor on all the elements of the page.
+for (std::size_t J = 0; J < PAGE_SIZE; ++J)
+  Page[J].~T();
+Allocator.getPointer()->Deallocate(Page);
+  }
+  // Delete the extra ones in the new last page.
+  uintptr_t PagePtr = PageToDataIdx[NewLastPage];
+  if (PagePtr != InvalidPage) {
+T *Page = reinterpret_cast(PagePtr);
+// If 

[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits


@@ -0,0 +1,320 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+
+namespace llvm {
+/// A vector that allocates memory in pages.
+///
+/// Order is kept, but memory is allocated only when one element of the page is
+/// accessed. This introduces a level of indirection, but it is useful when you
+/// have a sparsely initialised vector where the full size is allocated 
upfront.
+///
+/// As a side effect the elements are initialised later than in a normal 
vector.
+/// On the first access to one of the elements of a given page all, the 
elements
+/// of the page are initialised. This also means that the elements of the page
+/// are initialised beyond the size of the vector.
+///
+/// Similarly on destruction the elements are destroyed only when the page is
+/// not needed anymore, delaying invoking the destructor of the elements.
+///
+/// Notice that this does not have iterators, because if you have iterators it
+/// probably means you are going to touch all the memory in any case, so better
+/// use a std::vector in the first place.
+template  class PagedVector {
+  static_assert(PageSize > 1, "PageSize must be greater than 0. Most likely "
+  "you want it to be greater than 16.");
+  /// The actual number of element in the vector which can be accessed.

zygoloid wrote:

```suggestion
  /// The actual number of elements in the vector which can be accessed.
```

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


[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits


@@ -0,0 +1,320 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- 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
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+
+namespace llvm {
+/// A vector that allocates memory in pages.
+///
+/// Order is kept, but memory is allocated only when one element of the page is
+/// accessed. This introduces a level of indirection, but it is useful when you
+/// have a sparsely initialised vector where the full size is allocated 
upfront.
+///
+/// As a side effect the elements are initialised later than in a normal 
vector.
+/// On the first access to one of the elements of a given page all, the 
elements

zygoloid wrote:

```suggestion
/// On the first access to one of the elements of a given page, all the elements
```

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


[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

2023-09-26 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese accepted this revision.
Bigcheese added a comment.
This revision is now accepted and ready to land.

The implementation of this change looks good. I share the concern that changing 
the default may break other users, but that's easily remedied and this is the 
correct default. It would be good to hear from at least the Google folks before 
landing though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159483

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


[libunwind] [libunwind][nfc] Avoid type warning of debug printf (PR #67390)

2023-09-26 Thread Kazushi Marukawa via cfe-commits

kaz7 wrote:

Update the top comment to describe what I modify.

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


[libunwind] [libunwind][nfc] Avoid type warning of debug printf (PR #67390)

2023-09-26 Thread Kazushi Marukawa via cfe-commits

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


[libunwind] [libunwind][nfc] Avoid type warning of debug printf (PR #67390)

2023-09-26 Thread Kazushi Marukawa via cfe-commits

https://github.com/kaz7 updated https://github.com/llvm/llvm-project/pull/67390

>From 18e3568db4a3a11c794f077e9effd0a713dbd2dc Mon Sep 17 00:00:00 2001
From: "Kazushi (Jam) Marukawa" 
Date: Sun, 24 Sep 2023 08:08:24 +0200
Subject: [PATCH 1/2] [libunwind][nfc] Avoid type warning of debug printf

Avoid type warning of debug printf since VE uses 64 bits SjLj.
---
 libunwind/src/Unwind-sjlj.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/libunwind/src/Unwind-sjlj.c b/libunwind/src/Unwind-sjlj.c
index 4d9a02699cddd78..f24088a0e98ae99 100644
--- a/libunwind/src/Unwind-sjlj.c
+++ b/libunwind/src/Unwind-sjlj.c
@@ -42,12 +42,18 @@ struct _Unwind_FunctionContext {
 
   // set by personality handler to be parameters passed to landing pad function
   uint64_tresumeParameters[4];
+
+  // specify format for debug dump of resumeLocation and resumeParameters[]
+#define SJLJ_PRI_PTR PRIxPTR
 #else
   // set by calling function before registering to be the landing pad
   uint32_tresumeLocation;
 
   // set by personality handler to be parameters passed to landing pad function
   uint32_tresumeParameters[4];
+
+  // specify format for debug dump of resumeLocation and resumeParameters[]
+#define SJLJ_PRI_PTR PRIuPTR
 #endif
 
   // set by calling function before registering
@@ -427,9 +433,9 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetGR(struct 
_Unwind_Context *context,
 /// Called by personality handler during phase 2 to alter register values.
 _LIBUNWIND_EXPORT void _Unwind_SetGR(struct _Unwind_Context *context, int 
index,
  uintptr_t new_value) {
-  _LIBUNWIND_TRACE_API("_Unwind_SetGR(context=%p, reg=%d, value=0x%" PRIuPTR
-   ")",
-   (void *)context, index, new_value);
+  _LIBUNWIND_TRACE_API(
+  "_Unwind_SetGR(context=%p, reg=%d, value=0x%" SJLJ_PRI_PTR ")",
+  (void *)context, index, new_value);
   _Unwind_FunctionContext_t ufc = (_Unwind_FunctionContext_t) context;
   ufc->resumeParameters[index] = new_value;
 }
@@ -438,7 +444,7 @@ _LIBUNWIND_EXPORT void _Unwind_SetGR(struct _Unwind_Context 
*context, int index,
 /// Called by personality handler during phase 2 to get instruction pointer.
 _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {
   _Unwind_FunctionContext_t ufc = (_Unwind_FunctionContext_t) context;
-  _LIBUNWIND_TRACE_API("_Unwind_GetIP(context=%p) => 0x%" PRIu32,
+  _LIBUNWIND_TRACE_API("_Unwind_GetIP(context=%p) => 0x%" SJLJ_PRI_PTR,
(void *)context, ufc->resumeLocation + 1);
   return ufc->resumeLocation + 1;
 }
@@ -451,7 +457,7 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIPInfo(struct 
_Unwind_Context *context,
   int *ipBefore) {
   _Unwind_FunctionContext_t ufc = (_Unwind_FunctionContext_t) context;
   *ipBefore = 0;
-  _LIBUNWIND_TRACE_API("_Unwind_GetIPInfo(context=%p, %p) => 0x%" PRIu32,
+  _LIBUNWIND_TRACE_API("_Unwind_GetIPInfo(context=%p, %p) => 0x%" SJLJ_PRI_PTR,
(void *)context, (void *)ipBefore,
ufc->resumeLocation + 1);
   return ufc->resumeLocation + 1;
@@ -461,7 +467,7 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIPInfo(struct 
_Unwind_Context *context,
 /// Called by personality handler during phase 2 to alter instruction pointer.
 _LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *context,
  uintptr_t new_value) {
-  _LIBUNWIND_TRACE_API("_Unwind_SetIP(context=%p, value=0x%" PRIuPTR ")",
+  _LIBUNWIND_TRACE_API("_Unwind_SetIP(context=%p, value=0x%" SJLJ_PRI_PTR ")",
(void *)context, new_value);
   _Unwind_FunctionContext_t ufc = (_Unwind_FunctionContext_t) context;
   ufc->resumeLocation = new_value - 1;

>From 0da56a015da4158c067c692fcaf6549752534419 Mon Sep 17 00:00:00 2001
From: "Kazushi (Jam) Marukawa" 
Date: Wed, 27 Sep 2023 02:23:40 +0200
Subject: [PATCH 2/2] Change to use PRIxPTR in order to follow suggestions.

---
 libunwind/src/Unwind-sjlj.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/libunwind/src/Unwind-sjlj.c b/libunwind/src/Unwind-sjlj.c
index f24088a0e98ae99..7e8faf098fe14b1 100644
--- a/libunwind/src/Unwind-sjlj.c
+++ b/libunwind/src/Unwind-sjlj.c
@@ -42,18 +42,12 @@ struct _Unwind_FunctionContext {
 
   // set by personality handler to be parameters passed to landing pad function
   uint64_tresumeParameters[4];
-
-  // specify format for debug dump of resumeLocation and resumeParameters[]
-#define SJLJ_PRI_PTR PRIxPTR
 #else
   // set by calling function before registering to be the landing pad
   uint32_tresumeLocation;
 
   // set by personality handler to be parameters passed to landing pad function
   uint32_tresumeParameters[4];
-
-  // specify format 

[libunwind] [libunwind][nfc] Avoid type warning of debug printf (PR #67390)

2023-09-26 Thread Kazushi Marukawa via cfe-commits

kaz7 wrote:

@arichardson Thank for your kind comment.  I confused them already.  I update 
my patch following your 2nd suggestion.

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


[PATCH] D155064: [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated

2023-09-26 Thread Takuya Shimizu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG491b2810fb7f: [clang][SemaCXX] Diagnose tautological uses of 
consteval if and… (authored by hazohelet).

Changed prior to commit:
  https://reviews.llvm.org/D155064?vs=556946=557380#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155064

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/AST/Interp/builtins.cpp
  clang/test/AST/Interp/if.cpp
  clang/test/AST/Interp/literals.cpp
  clang/test/CXX/expr/expr.const/p2-0x.cpp
  clang/test/CXX/expr/expr.const/p6-2a.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p4.cpp
  clang/test/Parser/pragma-fenv_access.c
  clang/test/SemaCXX/constant-conversion.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/test/SemaCXX/cxx2b-consteval-if.cpp
  clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
  clang/test/SemaCXX/fixit-tautological-meta-constant.cpp
  clang/test/SemaCXX/vartemplate-lambda.cpp
  clang/test/SemaCXX/warn-constant-evaluated-constexpr.cpp
  clang/test/SemaCXX/warn-tautological-meta-constant.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/unittests/Support/TimeProfilerTest.cpp
  libcxx/include/__type_traits/is_constant_evaluated.h
  
libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.segmented.pass.cpp
  
libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.verify.cpp

Index: libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.verify.cpp
===
--- libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.verify.cpp
+++ libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.verify.cpp
@@ -24,7 +24,7 @@
 #else
   // expected-error-re@+1 (static_assert|static assertion)}} failed}}
   static_assert(!std::is_constant_evaluated(), "");
-  // expected-warning@-1 0-1 {{'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression}}
+  // expected-warning-re@-1 0-1 {{'std::is_constant_evaluated' will always evaluate to {{('true' in a manifestly constant-evaluated expression|true in this context)
 #endif
   return 0;
 }
Index: libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.segmented.pass.cpp
===
--- libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.segmented.pass.cpp
+++ libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.segmented.pass.cpp
@@ -93,12 +93,10 @@
 }
 
 int main(int, char**) {
-  if (!std::is_constant_evaluated()) {
-test_containers, std::deque>();
-test_containers, std::vector>();
-test_containers, std::deque>();
-test_containers, std::vector>();
-  }
+  test_containers, std::deque>();
+  test_containers, std::vector>();
+  test_containers, std::deque>();
+  test_containers, std::vector>();
 
   types::for_each(types::forward_iterator_list{}, [] {
 test_join_view();
Index: libcxx/include/__type_traits/is_constant_evaluated.h
===
--- libcxx/include/__type_traits/is_constant_evaluated.h
+++ libcxx/include/__type_traits/is_constant_evaluated.h
@@ -24,7 +24,14 @@
 #endif
 
 _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR bool __libcpp_is_constant_evaluated() _NOEXCEPT {
+// __builtin_is_constant_evaluated() in this function always evaluates to false in pre-C++11 mode
+// because this function is not constexpr-qualified.
+// The following macro use clarifies this and avoids warnings from compilers.
+#ifndef _LIBCPP_CXX03_LANG
   return __builtin_is_constant_evaluated();
+#else
+  return false;
+#endif
 }
 
 _LIBCPP_END_NAMESPACE_STD
Index: clang/unittests/Support/TimeProfilerTest.cpp
===
--- clang/unittests/Support/TimeProfilerTest.cpp
+++ clang/unittests/Support/TimeProfilerTest.cpp
@@ -188,7 +188,6 @@
 | EvaluateAsBooleanCondition ()
 | | EvaluateAsRValue ()
 | EvaluateAsInitializer (slow_value)
-| EvaluateAsConstantExpr ()
 | EvaluateAsConstantExpr 

[clang] 491b281 - [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated

2023-09-26 Thread Takuya Shimizu via cfe-commits

Author: Takuya Shimizu
Date: 2023-09-27T09:26:06+09:00
New Revision: 491b2810fb7fe5f080fa9c4f5945ed0a6909dc92

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

LOG: [clang][SemaCXX] Diagnose tautological uses of consteval if and 
is_constant_evaluated

This patch makes clang diagnose extensive cases of consteval if and 
is_constant_evaluated usage that are tautologically true or false.
This introduces a new IsRuntimeEvaluated boolean flag to 
Sema::ExpressionEvaluationContextRecord that means the immediate appearance of 
if consteval or is_constant_evaluated are tautologically false(e.g. inside if 
!consteval {} block or non-constexpr-qualified function definition body)
This patch also pushes new expression evaluation context when parsing the 
condition of if constexpr and initializer of constexpr variables so that Sema 
can be aware that the use of consteval if and is_consteval are tautologically 
true in if constexpr condition and constexpr variable initializers.
BEFORE this patch, the warning for is_constant_evaluated was emitted from 
constant evaluator. This patch moves the warning logic to Sema in order to 
diagnose tautological use of is_constant_evaluated in the same way as consteval 
if.

This patch separates initializer evaluation context from InitializerScopeRAII.
This fixes a bug that was happening when user takes address of function address 
in initializers of non-local variables.

Fixes https://github.com/llvm/llvm-project/issues/43760
Fixes https://github.com/llvm/llvm-project/issues/51567

Reviewed By: cor3ntin, ldionne
Differential Revision: https://reviews.llvm.org/D155064

Added: 
clang/test/SemaCXX/fixit-tautological-meta-constant.cpp
clang/test/SemaCXX/warn-tautological-meta-constant.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ExprConstant.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Parse/ParseStmt.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/AST/Interp/builtins.cpp
clang/test/AST/Interp/if.cpp
clang/test/AST/Interp/literals.cpp
clang/test/CXX/expr/expr.const/p2-0x.cpp
clang/test/CXX/expr/expr.const/p6-2a.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p4.cpp
clang/test/Parser/pragma-fenv_access.c
clang/test/SemaCXX/constant-conversion.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
clang/test/SemaCXX/cxx2b-consteval-if.cpp
clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
clang/test/SemaCXX/vartemplate-lambda.cpp
clang/test/SemaCXX/warn-constant-evaluated-constexpr.cpp
clang/test/SemaTemplate/concepts.cpp
clang/unittests/Support/TimeProfilerTest.cpp
libcxx/include/__type_traits/is_constant_evaluated.h

libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.segmented.pass.cpp

libcxx/test/std/utilities/meta/meta.const.eval/is_constant_evaluated.verify.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8a136aae5489a8c..a17efab57bcdfa3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,12 @@ Improvements to Clang's diagnostics
 - Clang no longer emits irrelevant notes about unsatisfied constraint 
expressions
   on the left-hand side of ``||`` when the right-hand side constraint is 
satisfied.
   (`#54678: `_).
+- Clang now diagnoses wider cases of tautological use of consteval if or
+  ``std::is_constant_evaluated``. This also suppresses some false positives.
+  (`#43760: `_)
+  (`#51567: `_)
+- Clang now diagnoses narrowing implicit conversions on variable initializers 
in immediate
+  function context and on constexpr variable template initializers.
 
 Bug Fixes in This Version
 -

diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..1abb0b89af9f1c1 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -413,10 +413,6 @@ def 

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-09-26 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav added a comment.

Bootstrapping build failed due to -werror flag 
(https://buildkite.com/llvm-project/libcxx-ci/builds/30031)

   | 
/home/libcxx-builder/.buildkite-agent/builds/google-libcxx-builder-4613821dc47f-1/llvm-project/libcxx-ci/libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp:43:18:
 error: operator '?:' has lower precedence than '&'; '&' will be evaluated 
first [-Werror,-Wbitwise-conditional-parentheses]
  # |43 |   return val & 1 ? 1 : 0;
  # |   |  ~~~ ^
  
  
  # | 
/home/libcxx-builder/.buildkite-agent/builds/google-libcxx-builder-4613821dc47f-1/llvm-project/libcxx-ci/libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp:64:19:
 error: operator '?:' has lower precedence than '&'; '&' will be evaluated 
first [-Werror,-Wbitwise-conditional-parentheses]
  # |64 |   return *val & 1 ? 1 : 0;
  # |   |   ^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147844

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


[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits

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


[clang] Introduce paged vector (PR #66430)

2023-09-26 Thread Richard Smith via cfe-commits

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


[clang] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-09-26 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 2f2319cf2406d9830a331cbf015881c55ae78806 
5f33fa63e76b5d0c066773113447749c3428aa99 -- 
libcxx/include/__algorithm/ranges_contains_subrange.h 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
index fd4d858b255d..e9c300e5bb20 100644
--- 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
+++ 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
@@ -51,7 +51,8 @@ static_assert(HasContainsSubrangeSubrangeIt);
 
 template >
 concept HasContainsSubrangeR = requires(Range1&& range1, Range2&& range2) {
-std::ranges::contains_subrange(std::forward(range1), 
std::forward(range2)); };
+  std::ranges::contains_subrange(std::forward(range1), 
std::forward(range2));
+};
 
 static_assert(HasContainsSubrangeR>);
 static_assert(HasContainsSubrangeR);
@@ -68,27 +69,26 @@ static std::vector comparable_data;
 
 template 
 constexpr void test_iterators() {
-  {  // simple tests
-int a[] = {1, 2, 3, 4, 5, 6};
-int p[] = {3, 4, 5};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+  { // simple tests
+int a[]   = {1, 2, 3, 4, 5, 6};
+int p[]   = {3, 4, 5};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   [[maybe_unused]] std::same_as decltype(auto) ret =
-std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
+  std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
   assert(ret);
 }
 {
-  [[maybe_unused]] std::same_as decltype(auto) ret =
-std::ranges::contains_subrange(whole, subrange);
+  [[maybe_unused]] std::same_as decltype(auto) ret = 
std::ranges::contains_subrange(whole, subrange);
   assert(ret);
 }
   }
 
   { // no match
-int a[] = {1, 2, 3, 4, 5, 6};
-int p[] = {3, 4, 2};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+int a[]   = {1, 2, 3, 4, 5, 6};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -101,9 +101,9 @@ constexpr void test_iterators() {
   }
 
   { // range consists of just one element
-int a[] = {3};
-int p[] = {3, 4, 2};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 1)));
+int a[]   = {3};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 1)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -116,9 +116,9 @@ constexpr void test_iterators() {
   }
 
   { // subrange consists of just one element
-int a[] = {23, 1, 20, 3, 54, 2};
-int p[] = {3};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+int a[]   = {23, 1, 20, 3, 54, 2};
+int p[]   = {3};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 1)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -131,9 +131,9 @@ constexpr void test_iterators() {
   }
 
   { // range has zero length
-int a[] = {};
-int p[] = {3, 4, 2};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
+int a[]   = {};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -146,9 +146,9 @@ constexpr void test_iterators() {
   }
 
   { // subrange has zero length
-int a[] = {3, 4, 2};
-int p[] = {};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
+int a[]   = {3, 4, 2};
+int p[]   = {};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p)));
 {
 

[clang-tools-extra] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-09-26 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 2f2319cf2406d9830a331cbf015881c55ae78806 
5f33fa63e76b5d0c066773113447749c3428aa99 -- 
libcxx/include/__algorithm/ranges_contains_subrange.h 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
index fd4d858b255d..e9c300e5bb20 100644
--- 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
+++ 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
@@ -51,7 +51,8 @@ static_assert(HasContainsSubrangeSubrangeIt);
 
 template >
 concept HasContainsSubrangeR = requires(Range1&& range1, Range2&& range2) {
-std::ranges::contains_subrange(std::forward(range1), 
std::forward(range2)); };
+  std::ranges::contains_subrange(std::forward(range1), 
std::forward(range2));
+};
 
 static_assert(HasContainsSubrangeR>);
 static_assert(HasContainsSubrangeR);
@@ -68,27 +69,26 @@ static std::vector comparable_data;
 
 template 
 constexpr void test_iterators() {
-  {  // simple tests
-int a[] = {1, 2, 3, 4, 5, 6};
-int p[] = {3, 4, 5};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+  { // simple tests
+int a[]   = {1, 2, 3, 4, 5, 6};
+int p[]   = {3, 4, 5};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   [[maybe_unused]] std::same_as decltype(auto) ret =
-std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
+  std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
   assert(ret);
 }
 {
-  [[maybe_unused]] std::same_as decltype(auto) ret =
-std::ranges::contains_subrange(whole, subrange);
+  [[maybe_unused]] std::same_as decltype(auto) ret = 
std::ranges::contains_subrange(whole, subrange);
   assert(ret);
 }
   }
 
   { // no match
-int a[] = {1, 2, 3, 4, 5, 6};
-int p[] = {3, 4, 2};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+int a[]   = {1, 2, 3, 4, 5, 6};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -101,9 +101,9 @@ constexpr void test_iterators() {
   }
 
   { // range consists of just one element
-int a[] = {3};
-int p[] = {3, 4, 2};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 1)));
+int a[]   = {3};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 1)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -116,9 +116,9 @@ constexpr void test_iterators() {
   }
 
   { // subrange consists of just one element
-int a[] = {23, 1, 20, 3, 54, 2};
-int p[] = {3};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+int a[]   = {23, 1, 20, 3, 54, 2};
+int p[]   = {3};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 1)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -131,9 +131,9 @@ constexpr void test_iterators() {
   }
 
   { // range has zero length
-int a[] = {};
-int p[] = {3, 4, 2};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
+int a[]   = {};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -146,9 +146,9 @@ constexpr void test_iterators() {
   }
 
   { // subrange has zero length
-int a[] = {3, 4, 2};
-int p[] = {};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
+int a[]   = {3, 4, 2};
+int p[]   = {};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p)));
 {
 

[clang] [clang] Default x86_64's medium code model -mlarge-data-threshold to 65535 (PR #67506)

2023-09-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

This matches gcc.

See 
https://discourse.llvm.org/t/rfc-matching-gccs-mlarge-data-threshold-for-x86-64s-medium-code-model/73727.


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


2 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (modified) clang/test/CodeGen/large-data-threshold.c (+1-1) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f573f5a06ceb501..5030a709f14a1f3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4250,7 +4250,7 @@ def mcmodel_EQ : Joined<["-"], "mcmodel=">, 
Group,
   MarshallingInfoString, [{"default"}]>;
 def mlarge_data_threshold_EQ : Joined<["-"], "mlarge-data-threshold=">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
-  MarshallingInfoInt>;
+  MarshallingInfoInt, "65535">;
 def mtls_size_EQ : Joined<["-"], "mtls-size=">, Group,
   Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
   HelpText<"Specify bit size of immediate TLS offsets (AArch64 ELF only): "
diff --git a/clang/test/CodeGen/large-data-threshold.c 
b/clang/test/CodeGen/large-data-threshold.c
index 650a7fbb0094e66..29ae19e9b718994 100644
--- a/clang/test/CodeGen/large-data-threshold.c
+++ b/clang/test/CodeGen/large-data-threshold.c
@@ -5,7 +5,7 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -S %s -o - -mcmodel=medium 
-mlarge-data-threshold=200 | FileCheck %s --check-prefix=ASM-SMALL
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -S %s -o - -mcmodel=medium 
-mlarge-data-threshold=2 | FileCheck %s --check-prefix=ASM-LARGE
 
-// IR-DEFAULT: !{i32 1, !"Large Data Threshold", i64 0}
+// IR-DEFAULT: !{i32 1, !"Large Data Threshold", i64 65535}
 // IR-CUSTOM: !{i32 1, !"Large Data Threshold", i64 200}
 
 // ASM-SMALL-NOT: movabsq

``




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


[clang] [clang] Default x86_64's medium code model -mlarge-data-threshold to 65535 (PR #67506)

2023-09-26 Thread Arthur Eubanks via cfe-commits

https://github.com/aeubanks created 
https://github.com/llvm/llvm-project/pull/67506

This matches gcc.

See 
https://discourse.llvm.org/t/rfc-matching-gccs-mlarge-data-threshold-for-x86-64s-medium-code-model/73727.


>From b406b086709a1f5012aa444bc7774962c82c4f30 Mon Sep 17 00:00:00 2001
From: Arthur Eubanks 
Date: Tue, 26 Sep 2023 17:02:34 -0700
Subject: [PATCH] [clang] Default x86_64's medium code model
 -mlarge-data-threshold to 65535

This matches gcc.

See 
https://discourse.llvm.org/t/rfc-matching-gccs-mlarge-data-threshold-for-x86-64s-medium-code-model/73727.
---
 clang/include/clang/Driver/Options.td | 2 +-
 clang/test/CodeGen/large-data-threshold.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f573f5a06ceb501..5030a709f14a1f3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4250,7 +4250,7 @@ def mcmodel_EQ : Joined<["-"], "mcmodel=">, 
Group,
   MarshallingInfoString, [{"default"}]>;
 def mlarge_data_threshold_EQ : Joined<["-"], "mlarge-data-threshold=">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
-  MarshallingInfoInt>;
+  MarshallingInfoInt, "65535">;
 def mtls_size_EQ : Joined<["-"], "mtls-size=">, Group,
   Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
   HelpText<"Specify bit size of immediate TLS offsets (AArch64 ELF only): "
diff --git a/clang/test/CodeGen/large-data-threshold.c 
b/clang/test/CodeGen/large-data-threshold.c
index 650a7fbb0094e66..29ae19e9b718994 100644
--- a/clang/test/CodeGen/large-data-threshold.c
+++ b/clang/test/CodeGen/large-data-threshold.c
@@ -5,7 +5,7 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -S %s -o - -mcmodel=medium 
-mlarge-data-threshold=200 | FileCheck %s --check-prefix=ASM-SMALL
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -S %s -o - -mcmodel=medium 
-mlarge-data-threshold=2 | FileCheck %s --check-prefix=ASM-LARGE
 
-// IR-DEFAULT: !{i32 1, !"Large Data Threshold", i64 0}
+// IR-DEFAULT: !{i32 1, !"Large Data Threshold", i64 65535}
 // IR-CUSTOM: !{i32 1, !"Large Data Threshold", i64 200}
 
 // ASM-SMALL-NOT: movabsq

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


[clang] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-09-26 Thread via cfe-commits

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


[clang-tools-extra] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-09-26 Thread via cfe-commits

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


[clang] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-09-26 Thread via cfe-commits

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


[clang-tools-extra] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-09-26 Thread via cfe-commits

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

>From 5a2c930770cf548c5e3f3451e76b48cb067e6762 Mon Sep 17 00:00:00 2001
From: Zijun Zhao 
Date: Wed, 13 Sep 2023 14:26:01 -0700
Subject: [PATCH 1/4] [libc++] Implement ranges::contains_subrange

---
 libcxx/include/CMakeLists.txt |   1 +
 .../__algorithm/ranges_contains_subrange.h| 145 +
 libcxx/include/algorithm  |  14 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../ranges.contains_subrange.pass.cpp | 293 ++
 .../niebloid.compile.pass.cpp |   3 +
 6 files changed, 460 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains_subrange.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..b096259f85f6ac8 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains_subrange.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains_subrange.h 
b/libcxx/include/__algorithm/ranges_contains_subrange.h
new file mode 100644
index 000..16de6c29cb2a1a4
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains_subrange.h
@@ -0,0 +1,145 @@
+//===--===//
+//
+// 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___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  for (; __offset >= 0; __offset--, __first1++) {
+auto result = ranges::starts_with(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+std::ref(__pred),
+std::ref(__proj1),
+std::ref(__proj2));
+if (result)
+  return true;
+  }
+  return false;
+}
+  }
+
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+auto __n1 = ranges::distance(__first1, __last1);
+auto __n2 = ranges::distance(__first2, __last2);
+auto __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+auto __n1 = 0;
+auto __n2 = 0;
+
+if 

[clang] Change all CHECK lines in test to include DAG to work when the compiler emits debug info in a different order. (PR #67503)

2023-09-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

When the changes in f8aab28 were merged into our downstream compiler, it 
started failing because the compiler with our downstream patches applied was 
emitting the debug information in a different order than originally expected. 
The debug info was still correct, just in a different order. This changes the 
test to be more flexible in the search so that it works more generally.

Sample debug output generated by our downstream compiler for this test:
```
!5 = distinct !DISubprogram(name: "main", scope: !6, file: !6, line: 4, type: 
!7, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: 
!0, retainedNodes: !13)
!6 = !DIFile(filename: 
"/mnt/sources/git/dev/clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp", 
directory: "")
!7 = !DISubroutineType(types: !8)
!8 = !{!9, !9, !10, !10}
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
!12 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
!13 = !{!14, !15, !16, !17, !23, !24, !27, !28, !30, !35, !36, !44}
!14 = !DILocalVariable(name: "argc", arg: 1, scope: !5, file: !6, line: 4, 
type: !9)
!15 = !DILocalVariable(name: "argv", arg: 2, scope: !5, file: !6, line: 4, 
type: !10)
!16 = !DILocalVariable(name: "arge", arg: 3, scope: !5, file: !6, line: 4, 
type: !10)
!17 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !5, file: 
!6, line: 64, size: 8, flags: DIFlagTypePassByValue, elements: !18)
!18 = !{!19}
!19 = !DISubprogram(name: "bar", scope: !17, file: !6, line: 64, type: !20, 
scopeLine: 64, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit)
!20 = !DISubroutineType(types: !21)
!21 = !{null, !22}
!22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 64, flags: 
DIFlagArtificial | DIFlagObjectPointer)
!23 = !DILocalVariable(name: "one", scope: !5, file: !6, line: 64, type: !17)
!24 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !5, file: 
!6, line: 79, size: 32, flags: DIFlagTypePassByValue, elements: !25)
!25 = !{!26}
!26 = !DIDerivedType(tag: DW_TAG_member, name: "bar", scope: !24, file: !6, 
line: 79, baseType: !9, size: 32)
!27 = !DILocalVariable(name: "two", scope: !5, file: !6, line: 79, type: !24)
!28 = !DILocalVariable(name: "ptr2unnamed", scope: !5, file: !6, line: 80, 
type: !29)
!29 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !9, size: 64, 
extraData: !24)
!30 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "named", 
scope: !5, file: !6, line: 95, size: 128, flags: DIFlagTypePassByValue, 
elements: !31)
!31 = !{!32, !33}
!32 = !DIDerivedType(tag: DW_TAG_member, name: "bar", scope: !30, file: !6, 
line: 95, baseType: !9, size: 32)
!33 = !DIDerivedType(tag: DW_TAG_member, name: "p2mem", scope: !30, file: !6, 
line: 95, baseType: !34, size: 64, offset: 64)
!34 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !9, size: 64, 
extraData: !30)
!35 = !DILocalVariable(name: "three", scope: !5, file: !6, line: 95, type: !30)
!36 = distinct !DICompositeType(tag: DW_TAG_class_type, scope: !5, file: !6, 
line: 111, size: 32, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: 
!37)
!37 = !{!38, !39}
!38 = !DIDerivedType(tag: DW_TAG_member, name: "argc", scope: !36, file: !6, 
line: 111, baseType: !9, size: 32)
!39 = !DISubprogram(name: "operator()", scope: !36, file: !6, line: 111, type: 
!40, scopeLine: 111, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 
DISPFlagLocalToUnit)
!40 = !DISubroutineType(types: !41)
!41 = !{!9, !42, !9}
!42 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !43, size: 64, flags: 
DIFlagArtificial | DIFlagObjectPointer)
!43 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !36)
!44 = !DILocalVariable(name: "four", scope: !5, file: !6, line: 111, type: !36)
```
The match of the CHECK line on line 47 capturing a value for `TYPE_OF_FOUR` was 
matched on line `!36` of the debug output. When it next tried to find the 
variable definition for "one" the check failed because it had already passed it 
(it was previously emitted as `!23`).

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


1 Files Affected:

- (modified) clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp (+68-68) 


``diff
diff --git a/clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp 
b/clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
index 9602ac1b0249730..ed33a1934ee9e8f 100644
--- a/clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
+++ b/clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
@@ -3,58 +3,58 @@
 
 int main(int argc, char* argv[], char* arge[]) {
   //
-  // LINUX:  [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
-  // LINUX-SAME: tag: DW_TAG_structure_type
-  // LINUX-NOT:  name:
-  // LINUX-NOT:  identifier:
-  // LINUX-SAME: )
-  //
-  // 

[clang] Change all CHECK lines in test to include DAG to work when the compiler emits debug info in a different order. (PR #67503)

2023-09-26 Thread via cfe-commits

https://github.com/dyung created https://github.com/llvm/llvm-project/pull/67503

When the changes in f8aab28 were merged into our downstream compiler, it 
started failing because the compiler with our downstream patches applied was 
emitting the debug information in a different order than originally expected. 
The debug info was still correct, just in a different order. This changes the 
test to be more flexible in the search so that it works more generally.

Sample debug output generated by our downstream compiler for this test:
```
!5 = distinct !DISubprogram(name: "main", scope: !6, file: !6, line: 4, type: 
!7, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: 
!0, retainedNodes: !13)
!6 = !DIFile(filename: 
"/mnt/sources/git/dev/clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp", 
directory: "")
!7 = !DISubroutineType(types: !8)
!8 = !{!9, !9, !10, !10}
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
!12 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
!13 = !{!14, !15, !16, !17, !23, !24, !27, !28, !30, !35, !36, !44}
!14 = !DILocalVariable(name: "argc", arg: 1, scope: !5, file: !6, line: 4, 
type: !9)
!15 = !DILocalVariable(name: "argv", arg: 2, scope: !5, file: !6, line: 4, 
type: !10)
!16 = !DILocalVariable(name: "arge", arg: 3, scope: !5, file: !6, line: 4, 
type: !10)
!17 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !5, file: 
!6, line: 64, size: 8, flags: DIFlagTypePassByValue, elements: !18)
!18 = !{!19}
!19 = !DISubprogram(name: "bar", scope: !17, file: !6, line: 64, type: !20, 
scopeLine: 64, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit)
!20 = !DISubroutineType(types: !21)
!21 = !{null, !22}
!22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 64, flags: 
DIFlagArtificial | DIFlagObjectPointer)
!23 = !DILocalVariable(name: "one", scope: !5, file: !6, line: 64, type: !17)
!24 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !5, file: 
!6, line: 79, size: 32, flags: DIFlagTypePassByValue, elements: !25)
!25 = !{!26}
!26 = !DIDerivedType(tag: DW_TAG_member, name: "bar", scope: !24, file: !6, 
line: 79, baseType: !9, size: 32)
!27 = !DILocalVariable(name: "two", scope: !5, file: !6, line: 79, type: !24)
!28 = !DILocalVariable(name: "ptr2unnamed", scope: !5, file: !6, line: 80, 
type: !29)
!29 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !9, size: 64, 
extraData: !24)
!30 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "named", 
scope: !5, file: !6, line: 95, size: 128, flags: DIFlagTypePassByValue, 
elements: !31)
!31 = !{!32, !33}
!32 = !DIDerivedType(tag: DW_TAG_member, name: "bar", scope: !30, file: !6, 
line: 95, baseType: !9, size: 32)
!33 = !DIDerivedType(tag: DW_TAG_member, name: "p2mem", scope: !30, file: !6, 
line: 95, baseType: !34, size: 64, offset: 64)
!34 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !9, size: 64, 
extraData: !30)
!35 = !DILocalVariable(name: "three", scope: !5, file: !6, line: 95, type: !30)
!36 = distinct !DICompositeType(tag: DW_TAG_class_type, scope: !5, file: !6, 
line: 111, size: 32, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: 
!37)
!37 = !{!38, !39}
!38 = !DIDerivedType(tag: DW_TAG_member, name: "argc", scope: !36, file: !6, 
line: 111, baseType: !9, size: 32)
!39 = !DISubprogram(name: "operator()", scope: !36, file: !6, line: 111, type: 
!40, scopeLine: 111, flags: DIFlagPublic | DIFlagPrototyped, spFlags: 
DISPFlagLocalToUnit)
!40 = !DISubroutineType(types: !41)
!41 = !{!9, !42, !9}
!42 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !43, size: 64, flags: 
DIFlagArtificial | DIFlagObjectPointer)
!43 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !36)
!44 = !DILocalVariable(name: "four", scope: !5, file: !6, line: 111, type: !36)
```
The match of the CHECK line on line 47 capturing a value for `TYPE_OF_FOUR` was 
matched on line `!36` of the debug output. When it next tried to find the 
variable definition for "one" the check failed because it had already passed it 
(it was previously emitted as `!23`).

>From 38ceaa71d3a34e7f0bdec648eafd351699dd49f7 Mon Sep 17 00:00:00 2001
From: Douglas Yung 
Date: Tue, 26 Sep 2023 16:43:39 -0700
Subject: [PATCH] Change all CHECK lines in test to include DAG to work when
 the compiler emits debug info in a different order.

---
 .../debug-info-codeview-unnamed.cpp   | 136 +-
 1 file changed, 68 insertions(+), 68 deletions(-)

diff --git a/clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp 
b/clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
index 9602ac1b0249730..ed33a1934ee9e8f 100644
--- a/clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
+++ b/clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
@@ -3,58 +3,58 @@
 
 int main(int argc, char* argv[], char* 

[clang] [X86] Change target of __builtin_ia32_cmp[p|s][s|d] from avx into sse/sse2 (PR #67410)

2023-09-26 Thread Freddy Ye via cfe-commits


@@ -4742,6 +4742,125 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS 
_mm_castsi128_pd(__m128i __a) {
   return (__m128d)__a;
 }
 
+/// Compares each of the corresponding double-precision values of two
+///128-bit vectors of [2 x double], using the operation specified by the
+///immediate integer operand.
+///
+///Returns a [2 x double] vector consisting of two doubles corresponding to
+///the two comparison results: zero if the comparison is false, and all 1's
+///if the comparison is true.
+///
+/// \headerfile 
+///
+/// \code
+/// __m128d _mm_cmp_pd(__m128d a, __m128d b, const int c);
+/// \endcode
+///
+/// This intrinsic corresponds to the  VCMPPD  instruction.
+///
+/// \param a
+///A 128-bit vector of [2 x double].
+/// \param b
+///A 128-bit vector of [2 x double].
+/// \param c
+///An immediate integer operand, with bits [4:0] specifying which 
comparison

FreddyLeaf wrote:

```
$ echo "cmpsd   \$8, %xmm1, %xmm0" | llvm-mc --show-encoding
cmpsd   $8, %xmm1, %xmm0# encoding: 
[0xf2,0x0f,0xc2,0xc1,0x08]
$ echo "cmpsd   \$0, %xmm1, %xmm0" | llvm-mc --show-encoding
cmpeqsd %xmm1, %xmm0# encoding: 
[0xf2,0x0f,0xc2,0xc1,0x00]
```
encoding won't omit higher bits for cmpsd, but maybe hardware will?

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


[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-09-26 Thread via cfe-commits


@@ -0,0 +1,60 @@
+//===--- MoveSharedPointerContentsCheck.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 "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))) {}
+
+MoveSharedPointerContentsCheck::~MoveSharedPointerContentsCheck() = default;
+
+bool MoveSharedPointerContentsCheck::isLanguageVersionSupported(
+const LangOptions ) const {
+  return LangOptions.CPlusPlus11;
+}
+
+void MoveSharedPointerContentsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("std::move"))),
+  hasArgument(0, cxxOperatorCallExpr(hasOverloadedOperatorName("*"),
+ callee(cxxMethodDecl(ofClass(
+ 
matchers::matchesAnyListedName(
+ SharedPointerClasses)
+ .bind("op")))
+  .bind("call"),
+  this);
+}
+
+void MoveSharedPointerContentsCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *Call = Result.Nodes.getNodeAs("call");
+  const auto *Op = Result.Nodes.getNodeAs("op");
+
+  if (Op) {

5chmidti wrote:

With the way your match works, there is no need to check if `Op` is a 
`nullptr`. Your matcher either matches and all matchers specified with `bind` 
are bound, or it is not a match result and `check` is not called.
Although that might change when you match templated cases (main conversation 
comment).

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


[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-09-26 Thread via cfe-commits


@@ -0,0 +1,60 @@
+//===--- MoveSharedPointerContentsCheck.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 "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))) {}
+
+MoveSharedPointerContentsCheck::~MoveSharedPointerContentsCheck() = default;

5chmidti wrote:

You don't need to declare and define the destructor if it is defaulted.

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


[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-09-26 Thread via cfe-commits


@@ -0,0 +1,60 @@
+//===--- MoveSharedPointerContentsCheck.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 "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))) {}
+
+MoveSharedPointerContentsCheck::~MoveSharedPointerContentsCheck() = default;
+
+bool MoveSharedPointerContentsCheck::isLanguageVersionSupported(

5chmidti wrote:

`isLanguageVersionSupported` is usually defined in the header instead of here.

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


[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-09-26 Thread via cfe-commits


@@ -0,0 +1,37 @@
+//===--- MoveSharedPointerContentsCheck.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_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+
+#include 
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// FIXME: Write a short description.

5chmidti wrote:

Missing class description, you can use the sentence from the release notes here.

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


[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-09-26 Thread via cfe-commits

https://github.com/5chmidti commented:

I noticed a problem with your matcher, so I reviewed the rest of it while I was 
at it.

The problem is that you do not consider a type-dependent `std::shared_ptr` 
and the following test case fails:

```c++
template 
void dependentType() {
  std::shared_ptr p;
  T y = std::move(*p);
  // CHECK-FIXES: *std::move(p)
}
// CHECK-MESSAGES: :[[@LINE-3]]:11: warning: don't move the contents out of a 
shared pointer, as other accessors expect them to remain in a determinate state 
[bugprone-move-shared-pointer-contents]
```

In this case, your `callee` is no longer a `functionDecl` but an 
`unresolvedLookupExpr` and the `*` operator is a `UnaryOperator` instead of a 
`cxxOperatorCallExpr`.

Otherwise, looks like a good check to have.

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


[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-09-26 Thread via cfe-commits

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


[clang] [clang][modules] Adopt `FileEntryRef` in the `HeaderFileInfo` block in PCM files (PR #67383)

2023-09-26 Thread Jan Svoboda via cfe-commits

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


[PATCH] D148654: Modify BoundsSan to improve debuggability

2023-09-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka resigned from this revision.
vitalybuka added a comment.

I assume we moved to https://github.com/llvm/llvm-project/pull/65972


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148654

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-26 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

We've been investigating a serious performance regression in our latest Clang 
roll that is affecting coverage. Whereas previously, we could process all 
coverage data in under an hour, now the job times out after 6 hours. After 
investigation, I found out that this change is the culprit. Specifically, it 
seems like `llvm-cov` has gotten significantly slower.

Before this change:

  $ time llvm-cov show -instr-profile merged.profdata -summary-only 
e91b5a1a324aa156
  llvm-cov     0.92s user 0.12s system 99% cpu 1.038 total

After this change:

  $ time llvm-cov show -instr-profile merged.profdata -summary-only 
e91b5a1a324aa156
  llvm-cov     5.61s user 0.89s system 99% cpu 6.495 total

I did some investigation and it seems like the time increase is related to 
`InstrProfSymtab` that used in the `CoverageReader`. I saw that subsequent 
changes fix some issues trying to avoid unnecessary copies, but that still 
hasn't addressed the slowdown since the tip-of-tree is still exhibiting this 
issue.

It's also possible that there isn't any issue that was introduced here, the 
problem is that the implementation simply doesn't scale. For example, the 
binary `e91b5a1a324aa156` I used here has 95527 symbol entries, most of them 
are the `__covrec_*` symbols, and that's one of the smaller binaries we have in 
our build.

Regardless, this is still a serious regression and I'm wondering if there's 
anything we can do short of reverting this change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157913

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


[PATCH] D145214: [TSAN] add support for riscv64

2023-09-26 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.

Other than -Wframe-larger-than=656 and `const uptr indicator = 
0x0f00ull;` changes, others looks good to me.
I agree that this should be reviewed by @dvyukov :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145214

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


[clang-tools-extra] [CodeGen] Avoid potential sideeffects from XOR (PR #67193)

2023-09-26 Thread Nick Desaulniers via cfe-commits

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


[clang] [CodeGen] Avoid potential sideeffects from XOR (PR #67193)

2023-09-26 Thread Nick Desaulniers via cfe-commits

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


[clang-tools-extra] [CodeGen] Avoid potential sideeffects from XOR (PR #67193)

2023-09-26 Thread Nick Desaulniers via cfe-commits

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


[clang] [CodeGen] Avoid potential sideeffects from XOR (PR #67193)

2023-09-26 Thread Nick Desaulniers via cfe-commits

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


[clang-tools-extra] [CodeGen] Avoid potential sideeffects from XOR (PR #67193)

2023-09-26 Thread Nick Desaulniers via cfe-commits


@@ -574,8 +574,8 @@ class X86InstrInfo final : public X86GenInstrInfo {
  outliner::Candidate ) const override;
 
   void buildClearRegister(Register Reg, MachineBasicBlock ,
-  MachineBasicBlock::iterator Iter,
-  DebugLoc ) const override;
+  MachineBasicBlock::iterator Iter, DebugLoc ,
+  bool NoSideEffects = false) const override;

nickdesaulniers wrote:

Yeah, that SGTM

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


[clang] [CodeGen] Avoid potential sideeffects from XOR (PR #67193)

2023-09-26 Thread Nick Desaulniers via cfe-commits


@@ -574,8 +574,8 @@ class X86InstrInfo final : public X86GenInstrInfo {
  outliner::Candidate ) const override;
 
   void buildClearRegister(Register Reg, MachineBasicBlock ,
-  MachineBasicBlock::iterator Iter,
-  DebugLoc ) const override;
+  MachineBasicBlock::iterator Iter, DebugLoc ,
+  bool NoSideEffects = false) const override;

nickdesaulniers wrote:

Yeah, that SGTM

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


[clang] Diagnose problematic uses of constructor/destructor attribute (PR #67360)

2023-09-26 Thread Nick Desaulniers via cfe-commits

nickdesaulniers wrote:

ah, yeah I was curious about what precisely `reserved for the implementation` 
meant. System libraries? That means they should be able to opt out via 
`-Wno-whatever`.

For anything thats */test/*, I assume they can be adjusted to just not use a 
reserved priority?

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


[PATCH] D145214: [TSAN] add support for riscv64

2023-09-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.



Comment at: compiler-rt/lib/tsan/rtl/CMakeLists.txt:5
 append_list_if(COMPILER_RT_HAS_MSSE4_2_FLAG -msse4.2 TSAN_RTL_CFLAGS)
-append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=530
+append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=656
TSAN_RTL_CFLAGS)

Maybe this one is not needed after b31bd6d8046d01a66aa92993bacb56b115a67fc5


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145214

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


[clang] Diagnose problematic uses of constructor/destructor attribute (PR #67360)

2023-09-26 Thread Nick Desaulniers via cfe-commits


@@ -3176,6 +3178,11 @@ def err_alignas_underaligned : Error<
   "requested alignment is less than minimum alignment of %1 for type %0">;
 def warn_aligned_attr_underaligned : Warning,
   InGroup;
+def err_ctor_dtor_attr_on_non_void_func : Error<
+  "%0 attribute can only be applied to a function which accepts no arguments "
+  "and has a 'void' or 'int' return type">;

nickdesaulniers wrote:

ah, perhaps what I'm thinking of is that we aught to emit a similar diagnostic 
for the return type of those functions.

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


[clang] [clang][modules] Adopt `FileEntryRef` in the `HeaderFileInfo` block in PCM files (PR #67383)

2023-09-26 Thread Ben Langmuir via cfe-commits


@@ -612,24 +612,21 @@ FileManager::getNoncachedStatValue(StringRef Path,
 }
 
 void FileManager::GetUniqueIDMapping(
-SmallVectorImpl ) const {
+SmallVectorImpl ) const {
   UIDToFiles.clear();
   UIDToFiles.resize(NextFileUID);
 
-  // Map file entries
-  for (llvm::StringMap,
-   llvm::BumpPtrAllocator>::const_iterator
-   FE = SeenFileEntries.begin(),
-   FEEnd = SeenFileEntries.end();
-   FE != FEEnd; ++FE)
-if (llvm::ErrorOr Entry = FE->getValue()) {
-  if (const auto *FE = Entry->V.dyn_cast())
-UIDToFiles[FE->getUID()] = FE;
-}
-
-  // Map virtual file entries
-  for (const auto  : VirtualFileEntries)
-UIDToFiles[VFE->getUID()] = VFE;
+  for (const auto  : SeenFileEntries) {
+// Only return existing non-virtual files.

benlangmuir wrote:

"virtual" is an overloaded term here; maybe "VFS-mapped"?

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


[clang] [clang][modules] Adopt `FileEntryRef` in the `HeaderFileInfo` block in PCM files (PR #67383)

2023-09-26 Thread Ben Langmuir via cfe-commits

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


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


[clang] [clang][modules] Adopt `FileEntryRef` in the `HeaderFileInfo` block in PCM files (PR #67383)

2023-09-26 Thread Ben Langmuir via cfe-commits

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


  1   2   3   4   5   >