[clang-tools-extra] [clang-tidy] Fix handling --driver-mode= (PR #66553)

2023-09-15 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix handling --driver-mode= (PR #66553)

2023-09-15 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] ff8b4c8 - [clang-tidy][NFC] Minor cleanup in ClangTidyMain.cpp

2023-09-15 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-09-16T06:17:57Z
New Revision: ff8b4c8b2c9cce0e70e6e05ca9f0d4399d670236

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

LOG: [clang-tidy][NFC] Minor cleanup in ClangTidyMain.cpp

Extracted some code from a clangTidyMain function into
separate functions.

Added: 


Modified: 
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index dd7f8141a694e2a..0d2593e74f052b9 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -525,6 +525,31 @@ static bool verifyFileExtensions(
   return AnyInvalid;
 }
 
+static SmallString<256> makeAbsolute(llvm::StringRef Input) {
+  if (Input.empty())
+return {};
+  SmallString<256> AbsolutePath(Input);
+  if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
+llvm::errs() << "Can't make absolute path from " << Input << ": "
+ << EC.message() << "\n";
+  }
+  return AbsolutePath;
+}
+
+static llvm::IntrusiveRefCntPtr createBaseFS() {
+  llvm::IntrusiveRefCntPtr BaseFS(
+  new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
+
+  if (!VfsOverlay.empty()) {
+IntrusiveRefCntPtr VfsFromFile =
+getVfsFromFile(VfsOverlay, BaseFS);
+if (!VfsFromFile)
+  return nullptr;
+BaseFS->pushOverlay(std::move(VfsFromFile));
+  }
+  return BaseFS;
+}
+
 int clangTidyMain(int argc, const char **argv) {
   llvm::InitLLVM X(argc, argv);
 
@@ -540,34 +565,16 @@ int clangTidyMain(int argc, const char **argv) {
 return 1;
   }
 
-  llvm::IntrusiveRefCntPtr BaseFS(
-  new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
-
-  if (!VfsOverlay.empty()) {
-IntrusiveRefCntPtr VfsFromFile =
-getVfsFromFile(VfsOverlay, BaseFS);
-if (!VfsFromFile)
-  return 1;
-BaseFS->pushOverlay(std::move(VfsFromFile));
-  }
+  llvm::IntrusiveRefCntPtr BaseFS = createBaseFS();
+  if (!BaseFS)
+return 1;
 
   auto OwningOptionsProvider = createOptionsProvider(BaseFS);
   auto *OptionsProvider = OwningOptionsProvider.get();
   if (!OptionsProvider)
 return 1;
 
-  auto MakeAbsolute = [](const std::string &Input) -> SmallString<256> {
-if (Input.empty())
-  return {};
-SmallString<256> AbsolutePath(Input);
-if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
-  llvm::errs() << "Can't make absolute path from " << Input << ": "
-   << EC.message() << "\n";
-}
-return AbsolutePath;
-  };
-
-  SmallString<256> ProfilePrefix = MakeAbsolute(StoreCheckProfile);
+  SmallString<256> ProfilePrefix = makeAbsolute(StoreCheckProfile);
 
   StringRef FileName("dummy");
   auto PathList = OptionsParser->getSourcePathList();
@@ -575,9 +582,9 @@ int clangTidyMain(int argc, const char **argv) {
 FileName = PathList.front();
   }
 
-  SmallString<256> FilePath = MakeAbsolute(std::string(FileName));
-
+  SmallString<256> FilePath = makeAbsolute(FileName);
   ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
+
   std::vector EnabledChecks =
   getCheckNames(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers);
 



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


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-15 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> Any objections to this @vgvassilev?

I have no objections to this if that makes your workflow work. However I think 
this cures the symptom and not the real cause. It might be worth investigating 
how to adapt lldb to the incremental processing change more deeply. 

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


[clang] [clang][docs] Pass full path of source TD file to gen_rst_from_td. [NFC] (PR #66497)

2023-09-15 Thread Tom Stellard via cfe-commits

https://github.com/tstellar commented:

Where else will the .td files be?  In the build directory?

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


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-15 Thread Ben Barham via cfe-commits

bnbarham wrote:

Any objections to this @vgvassilev?

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


[PATCH] D157615: [ExtendLifetimes][1/4] Add "disable-post-ra" function attribute to disable the post-regalloc scheduler

2023-09-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Might be worth rewording the commit, or  splitting it - I'd say the 
introduction of `optdebug` should be the noteworthier part of this patch (or 
whichever patch introduces it) - so either "this patch adds optdebug, and a 
first/exemplar use of it in postra scheduler" or split it into a patch that 
just adds the attribute and no uses, and one that adds the use. (I'd lean 
towards splitting it up, personally & I guess maybe moving to github pull 
requests in the process, perhaps)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157615

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


[PATCH] D158223: [clang] Add clang::unnamed_addr attribute that marks globals' address as not significant

2023-09-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:14524
+  VD->hasAttr() &&
+  (!VD->getType().isPODType(getASTContext()) ||
+   !VD->getType().isConstQualified())) {

aeubanks wrote:
> rnk wrote:
> > I don't think `isPODType` really describes what we want. I think we want 
> > `isConstantStorage` which @dblaikie just added, which means essentially, 
> > can this global be placed in a readonly section.
> @dblaikie is 
> [this](https://github.com/llvm/llvm-project/blob/08d7377b67358496a409080fac22f3f7c077fb63/clang/lib/AST/Type.cpp#L124)
>  missing a check for a trivial constructor? using `isConstantStorage` the 
> test is failing on `const Foo` by warning there when it shouldn't be
(I realize this patch has been abandoned for now (probably worth actually 
marking it abandoned - I'm guessing folks are going to be wanting to look at 
outstanding phab reviews to try to get them cleaned out as we transition to 
github pull requests), just leaving some comments for the sake of it)

I think the `isConstantStorage` made some assumptions that the construction 
issues were already handled externally to the call... or you could pass in a 
bool to the second argument `ExcludeCtor` - but it's overly coarse/simplistic 
and I think just says "if you're not excluding the ctor, and the type is a 
CXXRecordDecl, then it's non-trivial" (so you'd pass in `false` for 
`ExcludeCtor` if you know the ctor you're using is non-trivial, otherwise pass 
in `true`). Because the function doesn't know which ctor you're using, so it's 
up to the caller to check. The dtor is checked, however (if `ExcludeDtor` is 
false).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158223

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


[clang] [clang-format][NFC] Clean up signatures of some parser functions (PR #66569)

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

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

None

>From d570d3bb4d0bf9a49b51c25857958988329d398f Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 15 Sep 2023 21:59:47 -0700
Subject: [PATCH] [clang-format][NFC] Clean up signatures of some parser
 functions

---
 clang/lib/Format/FormatToken.h   |  1 -
 clang/lib/Format/TokenAnnotator.cpp  |  2 +-
 clang/lib/Format/UnwrappedLineParser.cpp | 49 +++-
 clang/lib/Format/UnwrappedLineParser.h   | 11 ++
 4 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 1ea7ce6a564d8fa..0605ac9da7219f2 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -41,7 +41,6 @@ namespace format {
   TYPE(CaseLabelColon) 
\
   TYPE(CastRParen) 
\
   TYPE(ClassLBrace)
\
-  TYPE(CompoundRequirementLBrace)  
\
   /* ternary ?: expression */  
\
   TYPE(ConditionalExpr)
\
   /* the condition in an if statement */   
\
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 142168e074bbc27..138f7e8562dcc39 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1698,7 +1698,7 @@ class AnnotatingParser {
 TT_RecordLBrace, TT_StructLBrace, TT_UnionLBrace, 
TT_RequiresClause,
 TT_RequiresClauseInARequiresExpression, TT_RequiresExpression,
 TT_RequiresExpressionLParen, TT_RequiresExpressionLBrace,
-TT_CompoundRequirementLBrace, TT_BracedListLBrace)) {
+TT_BracedListLBrace)) {
   CurrentToken->setType(TT_Unknown);
 }
 CurrentToken->Role.reset();
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 0ff0656a92d7222..70b47279a89bb18 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -338,19 +338,16 @@ bool 
UnwrappedLineParser::precededByCommentOrPPDirective() const {
 /// \param OpeningBrace Opening brace (\p nullptr if absent) of that level
 /// \param CanContainBracedList If the content can contain (at any level) a
 /// braced list.
-/// \param NextLBracesType The type for left brace found in this level.
 /// \param IfKind The \p if statement kind in the level.
 /// \param IfLeftBrace The left brace of the \p if block in the level.
 /// \returns true if a simple block of if/else/for/while, or false otherwise.
 /// (A simple block has a single statement.)
 bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
  bool CanContainBracedList,
- TokenType NextLBracesType,
  IfStmtKind *IfKind,
  FormatToken **IfLeftBrace) {
-  auto NextLevelLBracesType = NextLBracesType == TT_CompoundRequirementLBrace
-  ? TT_BracedListLBrace
-  : TT_Unknown;
+  const bool InRequiresExpression =
+  OpeningBrace && OpeningBrace->is(TT_RequiresExpressionLBrace);
   const bool IsPrecededByCommentOrPPDirective =
   !Style.RemoveBracesLLVM || precededByCommentOrPPDirective();
   FormatToken *IfLBrace = nullptr;
@@ -370,9 +367,9 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
 else if (FormatTok->getType() == TT_MacroBlockEnd)
   kind = tok::r_brace;
 
-auto ParseDefault = [this, OpeningBrace, NextLevelLBracesType, IfKind,
+auto ParseDefault = [this, OpeningBrace, InRequiresExpression, IfKind,
  &IfLBrace, &HasDoWhile, &HasLabel, &StatementCount] {
-  parseStructuralElement(!OpeningBrace, NextLevelLBracesType, IfKind,
+  parseStructuralElement(OpeningBrace, InRequiresExpression, IfKind,
  &IfLBrace, HasDoWhile ? nullptr : &HasDoWhile,
  HasLabel ? nullptr : &HasLabel);
   ++StatementCount;
@@ -385,8 +382,8 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
   addUnwrappedLine();
   break;
 case tok::l_brace:
-  if (NextLBracesType != TT_Unknown) {
-FormatTok->setFinalizedType(NextLBracesType);
+  if (InRequiresExpression) {
+FormatTok->setFinalizedType(TT_RequiresExpressionLBrace);
   } else if (FormatTok->Previous &&
  FormatTok->Previous->ClosesRequiresClause) {
 // We need the 'default' case here to correctly parse a function
@@ -400,8 +397,7 @@ bool UnwrappedLineParser::parseLevel(const F

[clang] [clang][Sema] Fix a bug when instantiating a lambda with requires clause (PR #65193)

2023-09-15 Thread via cfe-commits


@@ -567,6 +567,58 @@ bool Sema::addInstantiatedCapturesToScope(
   return false;
 }
 
+static void addDeclsFromParentScope(Sema &S, FunctionDecl *FD,
+LocalInstantiationScope &Scope) {
+  assert(isLambdaCallOperator(FD) && "FD must be a lambda call operator");
+
+  LambdaScopeInfo *LSI = cast(S.getFunctionScopes().back());
+
+  auto captureVar = [&](VarDecl *VD) {
+LSI->addCapture(VD, /*isBlock=*/false, /*isByref=*/false,
+/*isNested=*/false, VD->getBeginLoc(), SourceLocation(),
+VD->getType(), /*Invalid=*/false);
+  };
+
+  FD = dyn_cast(FD->getParent()->getParent());
+
+  if (!FD || !FD->isTemplateInstantiation())
+return;
+
+  FunctionDecl *Pattern = FD->getPrimaryTemplate()->getTemplatedDecl();
+
+  for (unsigned I = 0; I < Pattern->getNumParams(); ++I) {
+ParmVarDecl *PVD = Pattern->getParamDecl(I);
+if (!PVD->isParameterPack()) {
+  Scope.InstantiatedLocal(PVD, FD->getParamDecl(I));
+  captureVar(FD->getParamDecl(I));
+  continue;
+}
+
+Scope.MakeInstantiatedLocalArgPack(PVD);
+
+for (ParmVarDecl *Inst : FD->parameters().drop_front(I)) {
+  Scope.InstantiatedLocalPackArg(PVD, Inst);
+  captureVar(Inst);
+}
+  }
+
+  for (auto *decl : Pattern->decls()) {
+if (!isa(decl) || isa(decl))
+  continue;
+
+IdentifierInfo *II = cast(decl)->getIdentifier();
+auto it = llvm::find_if(FD->decls(), [&](Decl *inst) {
+  VarDecl *VD = dyn_cast(inst);
+  return VD && VD->isLocalVarDecl() && VD->getIdentifier() == II;
+});
+
+assert(it != FD->decls().end() && "Cannot find the instantiated 
variable.");
+
+Scope.InstantiatedLocal(decl, *it);

0x59616e wrote:

I'm having difficulty understanding the problem. Is there anything incorrect 
here ? It would be great if more context could be provided. Thanks.

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


[PATCH] D158238: Implement __builtin_fmaximum/fminimum*

2023-09-15 Thread Kunwar Shaanjeet Singh Grover via Phabricator via cfe-commits
Groverkss added a comment.

LGTM, the fmaximum/fminimum fallback support backends has been blocking us for 
a while in IREE. This patch is a welcome addition to start the support for 
this. I will let @fhahn accept the patch, since I'm not an expert in this part 
of code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158238

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


[clang] Support target names with dots in more utilities (PR #65812)

2023-09-15 Thread Fangrui Song via cfe-commits


@@ -390,6 +390,21 @@ StringRef stem(StringRef path, Style style = 
Style::native);
 /// @result The extension of \a path.
 StringRef extension(StringRef path, Style style = Style::native);
 
+/// Get the program's name
+///
+/// If the path ends with the string .exe, returns the stem of

MaskRay wrote:

.exe => ".exe"

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


[clang] Support target names with dots in more utilities (PR #65812)

2023-09-15 Thread Fangrui Song via cfe-commits

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

LGTM, but @jh7370 usually wants to have an eye on such changes.

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


[clang] Support target names with dots in more utilities (PR #65812)

2023-09-15 Thread Fangrui Song via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix handling --driver-mode= (PR #66553)

2023-09-15 Thread via cfe-commits


@@ -525,8 +527,95 @@ static bool verifyFileExtensions(
   return AnyInvalid;
 }
 
+static SmallString<256> makeAbsolute(llvm::StringRef Input) {
+  if (Input.empty())
+return {};
+  SmallString<256> AbsolutePath(Input);
+  if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
+llvm::errs() << "Can't make absolute path from " << Input << ": "
+ << EC.message() << "\n";
+  }
+  return AbsolutePath;
+}
+
+static llvm::IntrusiveRefCntPtr createBaseFS() {
+  llvm::IntrusiveRefCntPtr BaseFS(
+  new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
+
+  if (!VfsOverlay.empty()) {
+IntrusiveRefCntPtr VfsFromFile =
+getVfsFromFile(VfsOverlay, BaseFS);
+if (!VfsFromFile)
+  return nullptr;
+BaseFS->pushOverlay(std::move(VfsFromFile));
+  }
+  return BaseFS;
+}
+
+static llvm::Expected
+recreateOptionsParserIfNeeded(llvm::ArrayRef Args,
+  llvm::Expected 
OptionsParser,
+  const ClangTidyOptions &EffectiveOptions) {
+
+  auto DoubleDashIt = std::find(Args.begin(), Args.end(), StringRef("--"));
+  if (DoubleDashIt == Args.end() || Args.empty() ||
+  Args.back() == StringRef("--"))
+return OptionsParser;
+
+  auto IsDriverMode = [](StringRef Argument) {
+return Argument.startswith("--driver-mode=");
+  };
+
+  if (Args.end() !=
+  std::find_if(std::next(DoubleDashIt), Args.end(), IsDriverMode))
+return OptionsParser;
+
+  std::vector CommandArguments(std::next(DoubleDashIt),

EugeneZelenko wrote:

Please include `iterator`, `string` and `vector`.

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

https://github.com/pandaninjas updated 
https://github.com/llvm/llvm-project/pull/66315

>From ead65bfcb70be46788bc9e88c891e7ae7f91b8d7 Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 17:38:17 -0700
Subject: [PATCH 01/15] [libc++] Prevent calling the projection more than three
 times

---
 libcxx/include/__algorithm/ranges_clamp.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 9613f7f37720a6c..ca46675eb4b3041 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto &projection = std::invoke(__proj, __value);
+if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), 
std::invoke(__proj, __value)))
+else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
   return __high;
 else
   return __value;

>From c18d60870ac342a95a5528396a8e0c7b91717cbb Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 18:56:44 -0700
Subject: [PATCH 02/15] [libc++] Run clang-format on file

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index ca46675eb4b3041..3469a6419b2270f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto &projection = std::invoke(__proj, __value);
+auto& projection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From b40e791f0e9fedbb19936851e1e71decf00331fa Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:20 -0700
Subject: [PATCH 03/15] [libcxx] CamelCase projection and make variable name
 more descriptive

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3469a6419b2270f..3adb5fa828e1ee5 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto& projection = std::invoke(__proj, __value);
+auto& ValueProjection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From a8907624defa4cc4f47520a2d93a8bd042816aa2 Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:47 -0700
Subject: [PATCH 04/15] [libcxx] properly change variable name

---
 libcxx/include/__algorithm/ranges_clamp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3adb5fa828e1ee5..3d7a224b3649a3f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -38,9 +38,9 @@ struct __fn {
  "Bad bounds passed to std::ranges::clamp");
 
 auto& ValueProjection = std::invoke(__proj, __value);
-if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
+if (std::invoke(__comp, ValueProjection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
+else if (std::invoke(__comp, std::invoke(__proj, __high), ValueProjection))
   return __high;
 else
   return __value;

>From 15d3b2b79fbd61f97b0312e0913cede36b5b202d Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Thu, 14 Sep 2023 10:37:34 -0700
Subject: [PATCH 05/15] Apply suggestions from code review

---
 libcxx/include/__algorithm/ranges_clamp.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3d7a224b3649a3f..

[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

https://github.com/pandaninjas updated 
https://github.com/llvm/llvm-project/pull/66315

>From ead65bfcb70be46788bc9e88c891e7ae7f91b8d7 Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 17:38:17 -0700
Subject: [PATCH 01/15] [libc++] Prevent calling the projection more than three
 times

---
 libcxx/include/__algorithm/ranges_clamp.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 9613f7f37720a6c..ca46675eb4b3041 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto &projection = std::invoke(__proj, __value);
+if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), 
std::invoke(__proj, __value)))
+else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
   return __high;
 else
   return __value;

>From c18d60870ac342a95a5528396a8e0c7b91717cbb Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 18:56:44 -0700
Subject: [PATCH 02/15] [libc++] Run clang-format on file

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index ca46675eb4b3041..3469a6419b2270f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto &projection = std::invoke(__proj, __value);
+auto& projection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From b40e791f0e9fedbb19936851e1e71decf00331fa Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:20 -0700
Subject: [PATCH 03/15] [libcxx] CamelCase projection and make variable name
 more descriptive

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3469a6419b2270f..3adb5fa828e1ee5 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto& projection = std::invoke(__proj, __value);
+auto& ValueProjection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From a8907624defa4cc4f47520a2d93a8bd042816aa2 Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:47 -0700
Subject: [PATCH 04/15] [libcxx] properly change variable name

---
 libcxx/include/__algorithm/ranges_clamp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3adb5fa828e1ee5..3d7a224b3649a3f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -38,9 +38,9 @@ struct __fn {
  "Bad bounds passed to std::ranges::clamp");
 
 auto& ValueProjection = std::invoke(__proj, __value);
-if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
+if (std::invoke(__comp, ValueProjection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
+else if (std::invoke(__comp, std::invoke(__proj, __high), ValueProjection))
   return __high;
 else
   return __value;

>From 15d3b2b79fbd61f97b0312e0913cede36b5b202d Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Thu, 14 Sep 2023 10:37:34 -0700
Subject: [PATCH 05/15] Apply suggestions from code review

---
 libcxx/include/__algorithm/ranges_clamp.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3d7a224b3649a3f..

[clang] [clang][Sema] Fix a bug when instantiating a lambda with requires clause (PR #65193)

2023-09-15 Thread via cfe-commits

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


[clang] [clang][Sema] Fix a bug when instantiating a lambda with requires clause (PR #65193)

2023-09-15 Thread via cfe-commits

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


[clang] [clang][Sema] Fix a bug when instantiating a lambda with requires clause (PR #65193)

2023-09-15 Thread via cfe-commits

https://github.com/0x59616e updated 
https://github.com/llvm/llvm-project/pull/65193

>From 3eafb85ff74271456cba24ea5892dd5660c1d332 Mon Sep 17 00:00:00 2001
From: Sheng 
Date: Wed, 30 Aug 2023 11:44:23 +0800
Subject: [PATCH 1/3] [clang][Sema] Fix a bug when instantiating a lambda with
 requires clause

Instantiating a lambda at a scope different from its definition
scope will paralyze clang if the trailing require clause
refers to local variables of that definition scope.

This patch fixes this by re-adding the local variables to
`LocalInstantiationScope`.

Fixes #64462
---
 clang/lib/Sema/SemaConcept.cpp | 59 ++
 clang/test/SemaCXX/pr64462.cpp | 20 
 2 files changed, 79 insertions(+)
 create mode 100644 clang/test/SemaCXX/pr64462.cpp

diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index d1fa8e7831225b7..e48e0f743927a17 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -567,6 +567,58 @@ bool Sema::addInstantiatedCapturesToScope(
   return false;
 }
 
+static void addDeclsFromParentScope(Sema &S, FunctionDecl *FD,
+LocalInstantiationScope &Scope) {
+  assert(isLambdaCallOperator(FD) && "FD must be a lambda call operator");
+
+  LambdaScopeInfo *LSI = cast(S.getFunctionScopes().back());
+
+  auto captureVar = [&](VarDecl *VD) {
+LSI->addCapture(VD, /*isBlock=*/false, /*isByref=*/false,
+/*isNested=*/false, VD->getBeginLoc(), SourceLocation(),
+VD->getType(), /*Invalid=*/false);
+  };
+
+  FD = dyn_cast(FD->getParent()->getParent());
+
+  if (!FD || !FD->isTemplateInstantiation())
+return;
+
+  FunctionDecl *Pattern = FD->getPrimaryTemplate()->getTemplatedDecl();
+
+  for (unsigned I = 0; I < Pattern->getNumParams(); ++I) {
+ParmVarDecl *PVD = Pattern->getParamDecl(I);
+if (!PVD->isParameterPack()) {
+  Scope.InstantiatedLocal(PVD, FD->getParamDecl(I));
+  captureVar(FD->getParamDecl(I));
+  continue;
+}
+
+Scope.MakeInstantiatedLocalArgPack(PVD);
+
+for (ParmVarDecl *Inst : FD->parameters().drop_front(I)) {
+  Scope.InstantiatedLocalPackArg(PVD, Inst);
+  captureVar(Inst);
+}
+  }
+
+  for (auto *decl : Pattern->decls()) {
+if (!isa(decl) || isa(decl))
+  continue;
+
+IdentifierInfo *II = cast(decl)->getIdentifier();
+auto it = llvm::find_if(FD->decls(), [&](Decl *inst) {
+  VarDecl *VD = dyn_cast(inst);
+  return VD && VD->isLocalVarDecl() && VD->getIdentifier() == II;
+});
+
+assert(it != FD->decls().end() && "Cannot find the instantiated 
variable.");
+
+Scope.InstantiatedLocal(decl, *it);
+captureVar(cast(*it));
+  }
+}
+
 bool Sema::SetupConstraintScope(
 FunctionDecl *FD, std::optional> TemplateArgs,
 MultiLevelTemplateArgumentList MLTAL, LocalInstantiationScope &Scope) {
@@ -684,6 +736,7 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
   CtxToSave = CtxToSave->getNonTransparentContext();
   }
 
+  const bool shouldAddDeclsFromParentScope = !CtxToSave->Encloses(CurContext);
   ContextRAII SavedContext{*this, CtxToSave};
   LocalInstantiationScope Scope(*this, !ForOverloadResolution ||
isLambdaCallOperator(FD));
@@ -705,6 +758,9 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
   LambdaScopeForCallOperatorInstantiationRAII LambdaScope(
   *this, const_cast(FD), *MLTAL, Scope);
 
+  if (isLambdaCallOperator(FD) && shouldAddDeclsFromParentScope)
+addDeclsFromParentScope(*this, const_cast(FD), Scope);
+
   return CheckConstraintSatisfaction(
   FD, {FD->getTrailingRequiresClause()}, *MLTAL,
   SourceRange(UsageLoc.isValid() ? UsageLoc : FD->getLocation()),
@@ -896,6 +952,9 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
   LambdaScopeForCallOperatorInstantiationRAII LambdaScope(
   *this, const_cast(Decl), *MLTAL, Scope);
 
+  if (isLambdaCallOperator(Decl))
+addDeclsFromParentScope(*this, Decl, Scope);
+
   llvm::SmallVector Converted;
   return CheckConstraintSatisfaction(Template, TemplateAC, Converted, *MLTAL,
  PointOfInstantiation, Satisfaction);
diff --git a/clang/test/SemaCXX/pr64462.cpp b/clang/test/SemaCXX/pr64462.cpp
new file mode 100644
index 000..cc8b5510d1a823a
--- /dev/null
+++ b/clang/test/SemaCXX/pr64462.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+
+auto c1(auto f, auto ...fs) {
+  constexpr bool a = true;
+  // expected-note@+2{{because substituted constraint expression is 
ill-formed: no matching function for call to 'c1'}}
+  // expected-note@+1{{candidate template ignored: constraints not satisfied 
[with auto:1 = bool}}
+  return [](auto) requires a && (c1(fs...)) {};
+}
+
+auto c2(auto f, auto ...fs) {
+  constexpr bool a = true;
+  // expected-note@+2{{because substituted constraint expression is 
ill-formed: n

[PATCH] D148381: [Clang] Implement the 'counted_by' attribute

2023-09-15 Thread FĂ©lix Cloutier via Phabricator via cfe-commits
fcloutier added a comment.

In D148381#4646833 , @rapidsna wrote:

> `-fbounds-safety` doesn't allow this. In our internal adoption experience, we 
> haven't encountered such use cases yet. So, I think it's best to make the 
> model restrictive to avoid surprises. If we were to support it, I think it 
> should at least be limited to cases where the array subscript expression is 
> known to be in bounds at compile time, to avoid an OOB access when the 
> counted_by argument is evaluated.

Additionally: it is probably safe from an aliasing perspective (or at least not 
worse than using any other field) to use an array subscript in a count 
expression, provided the array's storage exists within the struct. However, we 
certainly wouldn't want people to go towards `array[variable]`, 
`pointer[anything]`, or (worse!) `FAM[anything]`, and constant array subscripts 
are confusingly adjacent to the boundary we need to close. If we're just 
entertaining the possibility without motivating use cases at this time, I'd 
advise to leave it be.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

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


[clang] [clang][dataflow] Model the fields that are accessed via inline accessors (PR #66368)

2023-09-15 Thread Kinuko Yasuda via cfe-commits

kinu wrote:

Thanks! Addressed comments.

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


[clang] [clang][dataflow] Model the fields that are accessed via inline accessors (PR #66368)

2023-09-15 Thread Kinuko Yasuda via cfe-commits

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


[clang] [clang][dataflow] Model the fields that are accessed via inline accessors (PR #66368)

2023-09-15 Thread Kinuko Yasuda via cfe-commits


@@ -288,6 +288,18 @@ static void insertIfFunction(const Decl &D,
 Funcs.insert(FD);
 }
 
+static Expr *getRetValueFromSingleReturnStmtMethod(const CXXMemberCallExpr &C) 
{
+  auto *D = cast_or_null(C.getMethodDecl()->getDefinition());
+  if (!D)
+return nullptr;
+  auto *S = cast(D->getBody());
+  if (S->size() != 1)
+return nullptr;
+  if (auto *RS = dyn_cast(*S->body_begin()))
+return RS->getRetValue()->IgnoreParenImpCasts();
+  return nullptr;

kinu wrote:

Applied with slight modifications

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


[clang] [MSVC, ARM64] Add _Copy* and _Count* intrinsics (PR #66554)

2023-09-15 Thread Eli Friedman via cfe-commits


@@ -10752,6 +10752,68 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 return Load;
   }
 
+  if (BuiltinID == AArch64::BI_CopyDoubleFromInt64 ||
+  BuiltinID == AArch64::BI_CopyFloatFromInt32 ||
+  BuiltinID == AArch64::BI_CopyInt32FromFloat ||
+  BuiltinID == AArch64::BI_CopyInt64FromDouble) {
+return EmitScalarExpr(E->getArg(0));

efriedma-quic wrote:

I suspect this won't actually work correctly in general (for example, if you 
try to do arithmetic on the returned value); the returned value has the wrong 
type.

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


[clang] [clang][dataflow] Model the fields that are accessed via inline accessors (PR #66368)

2023-09-15 Thread Kinuko Yasuda via cfe-commits

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


[clang] [clang][dataflow] Model the fields that are accessed via inline accessors (PR #66368)

2023-09-15 Thread Kinuko Yasuda via cfe-commits

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


[clang] [clang][dataflow] Model the fields that are accessed via inline accessors (PR #66368)

2023-09-15 Thread Kinuko Yasuda via cfe-commits


@@ -324,6 +336,12 @@ getFieldsGlobalsAndFuncs(const Stmt &S, FieldSet &Fields,
   } else if (auto *E = dyn_cast(&S)) {
 insertIfGlobal(*E->getDecl(), Vars);
 insertIfFunction(*E->getDecl(), Funcs);
+  } else if (const auto *C = dyn_cast(&S)) {
+// If this is a method that returns a member variable but does nothing 
else,
+// model the field of the return value.
+if (MemberExpr *E = dyn_cast_or_null(
+getRetValueFromSingleReturnStmtMethod(*C)))
+  getFieldsGlobalsAndFuncs(*E, Fields, Vars, Funcs);

kinu wrote:

Totally, done.

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


[clang] [clang][dataflow] Model the fields that are accessed via inline accessors (PR #66368)

2023-09-15 Thread Kinuko Yasuda via cfe-commits

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


[clang] [clang][dataflow] Model the fields that are accessed via inline accessors (PR #66368)

2023-09-15 Thread Kinuko Yasuda via cfe-commits

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


[clang] [clang][dataflow] Model the fields that are accessed via inline accessors (PR #66368)

2023-09-15 Thread Kinuko Yasuda via cfe-commits


@@ -1446,6 +1446,51 @@ TEST(TransferTest, BaseClassInitializer) {
   llvm::Succeeded());
 }
 
+TEST(TransferTest, StructModeledFieldsWithAccessor) {
+  std::string Code = R"(
+class S {
+  int *P;
+  int *Q;
+  int X;
+  int Y;
+  int Z;
+public:
+  int *getPtr() const { return P; }
+  int *getPtrNonConst() { return Q; }
+  int getInt(int i) const { return X; }

kinu wrote:

Done.

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


[clang] [clang][dataflow] Model the fields that are accessed via inline accessors (PR #66368)

2023-09-15 Thread Kinuko Yasuda via cfe-commits

https://github.com/kinu updated https://github.com/llvm/llvm-project/pull/66368

>From d311f12fe3ca0d30a40e659236ba7eaccda24a8b Mon Sep 17 00:00:00 2001
From: Kinuko Yasuda 
Date: Thu, 14 Sep 2023 12:45:04 +
Subject: [PATCH 1/4] [clang][dataflow] Model the fields that are accessed via
 inline accessors

So that the values that are accessed via such accessors can be analyzed
as a limited version of context-sensitive analysis.
We can potentially do this only when some option is set, but doing
additional modeling like this won't be expensive and intrusive, so
we do it by default for now.
---
 .../FlowSensitive/DataflowEnvironment.cpp | 18 
 .../Analysis/FlowSensitive/TransferTest.cpp   | 44 +++
 2 files changed, 62 insertions(+)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index e13f880896fc071..713df62e5009336 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -288,6 +288,18 @@ static void insertIfFunction(const Decl &D,
 Funcs.insert(FD);
 }
 
+static Expr *getRetValueFromSingleReturnStmtMethod(const CXXMemberCallExpr &C) 
{
+  auto *D = cast_or_null(C.getMethodDecl()->getDefinition());
+  if (!D)
+return nullptr;
+  auto *S = cast(D->getBody());
+  if (S->size() != 1)
+return nullptr;
+  if (auto *RS = dyn_cast(*S->body_begin()))
+return RS->getRetValue()->IgnoreParenImpCasts();
+  return nullptr;
+}
+
 static void
 getFieldsGlobalsAndFuncs(const Decl &D, FieldSet &Fields,
  llvm::DenseSet &Vars,
@@ -324,6 +336,12 @@ getFieldsGlobalsAndFuncs(const Stmt &S, FieldSet &Fields,
   } else if (auto *E = dyn_cast(&S)) {
 insertIfGlobal(*E->getDecl(), Vars);
 insertIfFunction(*E->getDecl(), Funcs);
+  } else if (const auto *C = dyn_cast(&S)) {
+// If this is a method that returns a member variable but does nothing 
else,
+// model the field of the return value.
+if (MemberExpr *E = dyn_cast_or_null(
+getRetValueFromSingleReturnStmtMethod(*C)))
+  getFieldsGlobalsAndFuncs(*E, Fields, Vars, Funcs);
   } else if (auto *E = dyn_cast(&S)) {
 // FIXME: should we be using `E->getFoundDecl()`?
 const ValueDecl *VD = E->getMemberDecl();
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index cdb1bc3cd16ac7b..355d18bc1fe55a6 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1446,6 +1446,50 @@ TEST(TransferTest, BaseClassInitializer) {
   llvm::Succeeded());
 }
 
+TEST(TransferTest, StructModeledFieldsWithConstAccessor) {
+  std::string Code = R"(
+class S {
+  int *P;
+  int *Q;
+  int X;
+  int Y;
+  int Z;
+public:
+  int *getPtr() const { return P; }
+  int *getPtrNonConst() { return Q; }
+  int getInt() const { return X; }
+  int getInt(int i) const { return Y; }
+  int getIntNonConst() { return Z; }
+  int getIntNoDefinition() const;
+};
+
+void target() {
+  S s;
+  int *p = s.getPtr();
+  int *q = s.getPtrNonConst();
+  int x = s.getInt();
+  int y = s.getIntNonConst();
+  int z = s.getIntNoDefinition();
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env =
+  getEnvironmentAtAnnotation(Results, "p");
+auto &SLoc = getLocForDecl(ASTCtx, Env, "s");
+std::vector Fields;
+for (auto [Field, _] : SLoc.children())
+  Fields.push_back(Field);
+// Only the fields that have corresponding const accessor methods
+// should be modeled.
+ASSERT_THAT(Fields, UnorderedElementsAre(
+findValueDecl(ASTCtx, "P"), findValueDecl(ASTCtx, "X")));
+  });
+}
+
 TEST(TransferTest, StructModeledFieldsWithComplicatedInheritance) {
   std::string Code = R"(
 struct Base1 {

>From ec7e051b7b0901b5776fe0c0fe751b3a1d2f995d Mon Sep 17 00:00:00 2001
From: Kinuko Yasuda 
Date: Thu, 14 Sep 2023 15:09:29 +
Subject: [PATCH 2/4] Update the broken test

---
 .../Analysis/FlowSensitive/TransferTest.cpp   | 25 +++
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 355d18bc1fe55a6..bf3d002567cc06a 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1446,7 +1446,7 @@ TEST(TransferTest, BaseClassInitializer) {
   llvm::Succeeded());
 }
 
-TEST(TransferTest, StructModeledFieldsWithConstAccessor) {
+TEST(TransferTest, StructModeledFieldsWithAccessor) {
   std::string Code = R"(
 class S {
   int

[PATCH] D148381: [Clang] Implement the 'counted_by' attribute

2023-09-15 Thread Yeoul Na via Phabricator via cfe-commits
rapidsna added a comment.

  struct V {
int Sizes[2];
int FAM[] __counted_by(Sizes[0]); // Thoughts?
  };

`-fbounds-safety` doesn't allow this. In our internal adoption experience, we 
haven't encountered such use cases yet. So, I think it's best to make the model 
restrictive to avoid surprises. If we were to support it, I think it should at 
least be limited to cases where the array subscript expression is known to be 
in bounds at compile time, to avoid an OOB access when the counted_by argument 
is evaluated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

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


[clang] [clang][CodeGen] Use byval for SystemZ indirect arguments (PR #66404)

2023-09-15 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

byval generally results in worse code. It has two problems:

- The copy is invisible.  Having the copy explicitly visible means we can 
optimize the code involved in the copy (sometimes we can eliminate it, or parts 
of it).
- Gluing the allocation to the call means stack layout is less flexible: the 
memory has to be allocated at a specific location on the stack.

x86-64 uses it because it was the simplest way to implement the ABI 
requirements; llvm.call.preallocated.setup theoretically solves the same 
problem, but it's a lot more complicated.

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


[clang] [clang][CodeGen] Use byval for SystemZ indirect arguments (PR #66404)

2023-09-15 Thread Ilya Leoshkevich via cfe-commits

iii-i wrote:

Sorry, I my wording was not precise enough, it is indeed important that we 
create a copy, and not pass a pointer to the original. Still, what you 
described matches the s390x ABI:

```
1.2.2.3. Parameter Area

The parameter area shall be allocated by a calling function if some parameters 
cannot
be passed in registers, but must be passed on the stack instead (see section 
1.2.3).

[...]

1.2.3. Parameter Passing

[...]
A struct or union of any other size, a complex type, an __int128, a long
double, a _Decimal128, or a vector whose size exceeds 16 bytes. Replace
such an argument by a pointer to the object, or to a copy where necessary
to enforce call-by-value semantics. Only if the caller can ascertain that the
object is “constant” can it pass a pointer to the object itself.
```

---

Ah, that's the source of my confusion. I didn't realize the call instruction 
had to make a copy, I thought it just had to be done somewhere. "The attribute 
implies that a hidden copy of the pointee is made between the caller and the 
callee" actually does mean the former, but one has to squint to see that. The 
way you phrased it is much clearer.

So in the following example:

```
struct foo { char x[800]; };
void bar(struct foo);
void baz(void) { struct foo f = {}; bar(f); };
```

x84_64 generates:

```
define dso_local void @baz() #0 {
  %1 = alloca %struct.foo, align 8
  call void @llvm.memset.p0.i64(ptr align 1 %1, i8 0, i64 800, i1 false)
  call void @bar(ptr noundef byval(%struct.foo) align 8 %1)
  ret void
}
```

and relies on the backend to expand `call void @bar` into roughly 
`REP_MOVSQ_64` and `CALL64pcrel32`. Whereas on s390x we get:

```
define dso_local void @baz() #0 {
  %1 = alloca %struct.foo, align 1
  %2 = alloca %struct.foo, align 1
  call void @llvm.memset.p0.i64(ptr align 1 %1, i8 0, i64 800, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %2, ptr align 1 %1, i64 800, i1 
false)
  call void @bar(ptr noundef %2)
  ret void
}
```

so the creation of the copy is explicit in the LLVM IR. Even though the ABIs 
are saying roughly the same thing, it's implemented differently.

I wonder if it would still be beneficial to switch s390x to byval? I think it 
can be done in a way that correctly implements the ABI, even though it would of 
course be more complex than this PR. An obvious benefit is that s390x would 
become more similar to x86_64, but maybe there are some drawbacks that I'm not 
seeing.

---

I revisited MSan's `param_tls_limit.cpp`, and the XFAIL is actually fine. The 
instrumentation does indeed put the shadow of the synthetic pointer into the 
parameters' TLS area on s390x, but this is not a problem, since the shadow of 
the actual value is still preserved and checked. This prevents the overflow, 
which the test expects, from happening, so the conclusion that the test is not 
applicable is correct. Sorry for the noise.

I will check if there is a different solution for DFSan. It currently passes 
the label of the pointer to the copy, which is always 0, instead of the label 
of the actual value, to vararg functions on s390x. Even though this is similar 
to what MSan does, the difference is that the DFSan runtime (e.g., 
`format_buffer`) expects the label of the actual value, regardless of the ABI.

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


[PATCH] D150075: Fix PR#62594 : static lambda call operator is not convertible to function pointer on win32

2023-09-15 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D150075#4646487 , @royjacobson 
wrote:

> @shafik @aaron.ballman does any of you want to commandeer this diff? seems 
> simple enough of a change

I think Aaron might be better since he is more familiar with Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150075

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread via cfe-commits


@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto&& __projected = std::invoke(__proj, __value);

timsong-cpp wrote:

The `invoke(__proj, __value)` call itself creates no temporaries; it just binds 
two references. Any temporaries are created inside `invoke` and are destroyed 
before `invoke` returns, so `invoke(identity_proj, "")` is always dangling 
regardless of what you do with the result.

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread via cfe-commits


@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto&& __projected = std::invoke(__proj, __value);
+if (std::invoke(__comp, std::forward(__projected), 
std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), 
std::invoke(__proj, __value)))
+else if (std::invoke(__comp, std::invoke(__proj, __high), 
std::forward(__projected))

timsong-cpp wrote:

https://github.com/microsoft/STL/issues/3970#issuecomment-1685120958

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


[PATCH] D159292: [driver] Conditionally include installed libc++ headers for Android

2023-09-15 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In D159292#4646811 , @rprichard wrote:

> In D159292#4646096 , @smeenai wrote:
>
>> Ping.
>
> I asked a couple of other people at Google to take a look at the patches. 
> Someone should get to it next week I think?

Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159292

___
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-15 Thread Jakub Kuderski via cfe-commits

https://github.com/kuhar 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-15 Thread Jakub Kuderski via cfe-commits

https://github.com/kuhar 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-15 Thread Jakub Kuderski via cfe-commits

https://github.com/kuhar 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-15 Thread Jakub Kuderski via cfe-commits

https://github.com/kuhar 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] [Driver] Change default PCH extension name from .gch to .pch (PR #66165)

2023-09-15 Thread Brad Smith via cfe-commits

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


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


[clang] [MSVC, ARM64] Add _Copy* and _Count* intrinsics (PR #66554)

2023-09-15 Thread Amy Huang via cfe-commits

https://github.com/amykhuang updated 
https://github.com/llvm/llvm-project/pull/66554

>From 2f18bc9802942e5fa08181026212ea711f9f16a9 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Thu, 7 Sep 2023 11:32:17 -0700
Subject: [PATCH] [MSVC, ARM64] Add _Copy* and _Count* intrinsics

---
 clang/include/clang/Basic/BuiltinsAArch64.def |  15 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |  62 
 clang/lib/Headers/intrin.h|  14 ++
 .../test/CodeGen/arm64-microsoft-intrinsics.c | 138 ++
 4 files changed, 228 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index eaae6c9ad846868..c4d34f8e15e8b8d 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -259,7 +259,6 @@ TARGET_HEADER_BUILTIN(__umulh, "ULLiULLiULLi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES,
 
 TARGET_HEADER_BUILTIN(__break, "vi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
 
-
 TARGET_HEADER_BUILTIN(__writex18byte,  "vUNiUc", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__writex18word,  "vUNiUs", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__writex18dword, "vUNiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
@@ -270,6 +269,20 @@ TARGET_HEADER_BUILTIN(__readx18word,  "UsUNi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES,
 TARGET_HEADER_BUILTIN(__readx18dword, "UNiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__readx18qword, "ULLiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 
+TARGET_HEADER_BUILTIN(_CopyDoubleFromInt64, "dSLLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CopyFloatFromInt32, "fSi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CopyInt32FromFloat, "Sif", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CopyInt64FromDouble, "SLLid", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+
+TARGET_HEADER_BUILTIN(_CountLeadingOnes, "UiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingOnes64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingSigns, "UiSLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingSigns64, "UiSLLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingZeros, "UiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingZeros64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountOneBits, "UiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountOneBits64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+
 #undef BUILTIN
 #undef LANGBUILTIN
 #undef TARGET_BUILTIN
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 037a2f9f7b15322..08d09c1c3d8e9de 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10752,6 +10752,68 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 return Load;
   }
 
+  if (BuiltinID == AArch64::BI_CopyDoubleFromInt64 ||
+  BuiltinID == AArch64::BI_CopyFloatFromInt32 ||
+  BuiltinID == AArch64::BI_CopyInt32FromFloat ||
+  BuiltinID == AArch64::BI_CopyInt64FromDouble) {
+return EmitScalarExpr(E->getArg(0));
+  }
+
+  if (BuiltinID == AArch64::BI_CountLeadingOnes ||
+  BuiltinID == AArch64::BI_CountLeadingOnes64 ||
+  BuiltinID == AArch64::BI_CountLeadingZeros ||
+  BuiltinID == AArch64::BI_CountLeadingZeros64) {
+Value *Arg = EmitScalarExpr(E->getArg(0));
+llvm::Type *ArgType = Arg->getType();
+
+if (BuiltinID == AArch64::BI_CountLeadingOnes ||
+BuiltinID == AArch64::BI_CountLeadingOnes64)
+  Arg = Builder.CreateXor(Arg, Constant::getAllOnesValue(ArgType));
+
+Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType);
+Value *Result = Builder.CreateCall(F, {Arg, Builder.getInt1(false)});
+
+if (BuiltinID == AArch64::BI_CountLeadingOnes64 ||
+BuiltinID == AArch64::BI_CountLeadingZeros64)
+  Result = Builder.CreateTrunc(Result, Builder.getInt32Ty());
+return Result;
+  }
+
+  if (BuiltinID == AArch64::BI_CountLeadingSigns ||
+  BuiltinID == AArch64::BI_CountLeadingSigns64) {
+Value *Arg = EmitScalarExpr(E->getArg(0));
+llvm::Type *ArgType = Arg->getType();
+
+Function *F;
+if (BuiltinID == AArch64::BI_CountLeadingSigns) {
+  F = CGM.getIntrinsic(Intrinsic::aarch64_cls);
+  if (ArgType != Builder.getInt32Ty())
+Arg =
+Builder.CreateIntCast(Arg, Builder.getInt32Ty(), /*isSigned*/ 
true);
+} else {
+  F = CGM.getIntrinsic(Intrinsic::aarch64_cls64);
+  if (ArgType != Builder.getInt64Ty())
+Arg =
+Builder.CreateIntCast(Arg, Builder.getInt64Ty(), /*isSigned*/ 
true);
+}
+Value *Result = Builder.CreateCall(F, Arg, "cls");
+if (BuiltinID == AArch64::BI_CountLeadingSigns64)
+  Result = Builder.CreateTrunc(Result, Build

[PATCH] D159292: [driver] Conditionally include installed libc++ headers for Android

2023-09-15 Thread Ryan Prichard via Phabricator via cfe-commits
rprichard added a comment.

In D159292#4646096 , @smeenai wrote:

> Ping.

I asked a couple of other people at Google to take a look at the patches. 
Someone should get to it next week I think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159292

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


[PATCH] D148381: [Clang] Implement the 'counted_by' attribute

2023-09-15 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D148381#4646780 , @kees wrote:

> In D148381#4645600 , @void wrote:
>
>> Added more error messages. Changed some code around to align with coding 
>> practices. Added some more test cases.
>
> Doing a full "allmodconfig" Linux kernel build with my 200ish __counted_by 
> annotations is building cleanly. Yay! :)

Great! That means I did something wrong.

;-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

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


[PATCH] D155688: [PATCH] [llvm] [InstCombine] Reassociate loop invariant GEP index calculations.

2023-09-15 Thread Dmitriy Smirnov via Phabricator via cfe-commits
d-smirnov updated this revision to Diff 556884.
d-smirnov added a comment.

updated


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155688

Files:
  clang/test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/align-addr.ll
  llvm/test/Transforms/InstCombine/gep-combine-loop-invariant.ll
  llvm/test/Transforms/InstCombine/lshr-phi.ll
  llvm/test/Transforms/InstCombine/mem-par-metadata-memcpy.ll
  llvm/test/Transforms/InstCombine/memrchr-4.ll
  llvm/test/Transforms/InstCombine/shift.ll
  llvm/test/Transforms/LoopUnroll/runtime-unroll-remainder.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-interleaved-accesses.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-vector-reverse.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
  llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse-mask4.ll
  llvm/test/Transforms/LoopVectorize/if-conversion-nest.ll
  llvm/test/Transforms/LoopVectorize/induction.ll
  llvm/test/Transforms/LoopVectorize/interleaved-accesses.ll
  llvm/test/Transforms/LoopVectorize/invariant-store-vectorization.ll
  llvm/test/Transforms/LoopVectorize/runtime-check.ll
  llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll

Index: llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll
===
--- llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll
+++ llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll
@@ -27,14 +27,14 @@
 ; CHECK-NEXT:br label [[INNER_BODY:%.*]]
 ; CHECK:   inner.body:
 ; CHECK-NEXT:[[TMP0:%.*]] = shl i64 [[INNER_IV]], 2
-; CHECK-NEXT:[[TMP1:%.*]] = add i64 [[TMP0]], [[ROWS_IV]]
-; CHECK-NEXT:[[TMP2:%.*]] = getelementptr double, ptr [[A:%.*]], i64 [[TMP1]]
+; CHECK-NEXT:[[TMP1:%.*]] = getelementptr double, ptr [[A:%.*]], i64 [[TMP0]]
+; CHECK-NEXT:[[TMP2:%.*]] = getelementptr double, ptr [[TMP1]], i64 [[ROWS_IV]]
 ; CHECK-NEXT:[[COL_LOAD:%.*]] = load <2 x double>, ptr [[TMP2]], align 8
 ; CHECK-NEXT:[[VEC_GEP:%.*]] = getelementptr double, ptr [[TMP2]], i64 4
 ; CHECK-NEXT:[[COL_LOAD1:%.*]] = load <2 x double>, ptr [[VEC_GEP]], align 8
 ; CHECK-NEXT:[[TMP3:%.*]] = shl i64 [[COLS_IV]], 2
-; CHECK-NEXT:[[TMP4:%.*]] = add i64 [[TMP3]], [[INNER_IV]]
-; CHECK-NEXT:[[TMP5:%.*]] = getelementptr double, ptr [[B:%.*]], i64 [[TMP4]]
+; CHECK-NEXT:[[TMP4:%.*]] = getelementptr double, ptr [[B:%.*]], i64 [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = getelementptr double, ptr [[TMP4]], i64 [[INNER_IV]]
 ; CHECK-NEXT:[[COL_LOAD2:%.*]] = load <2 x double>, ptr [[TMP5]], align 8
 ; CHECK-NEXT:[[VEC_GEP3:%.*]] = getelementptr double, ptr [[TMP5]], i64 4
 ; CHECK-NEXT:[[COL_LOAD4:%.*]] = load <2 x double>, ptr [[VEC_GEP3]], align 8
@@ -55,8 +55,8 @@
 ; CHECK-NEXT:[[ROWS_STEP]] = add i64 [[ROWS_IV]], 2
 ; CHECK-NEXT:[[ROWS_COND_NOT:%.*]] = icmp eq i64 [[ROWS_STEP]], 4
 ; CHECK-NEXT:[[TMP10:%.*]] = shl i64 [[COLS_IV]], 2
-; CHECK-NEXT:[[TMP11:%.*]] = add i64 [[TMP10]], [[ROWS_IV]]
-; CHECK-NEXT:[[TMP12:%.*]] = getelementptr double, ptr [[C:%.*]], i64 [[TMP11]]
+; CHECK-NEXT:[[TMP11:%.*]] = getelementptr double, ptr [[C:%.*]], i64 [[TMP10]]
+; CHECK-NEXT:[[TMP12:%.*]] = getelementptr double, ptr [[TMP11]], i64 [[ROWS_IV]]
 ; CHECK-NEXT:store <2 x double> [[TMP7]], ptr [[TMP12]], align 8
 ; CHECK-NEXT:[[VEC_GEP16:%.*]] = getelementptr double, ptr [[TMP12]], i64 4
 ; CHECK-NEXT:store <2 x double> [[TMP9]], ptr [[VEC_GEP16]], align 8
@@ -103,14 +103,14 @@
 ; CHECK-NEXT:br label [[INNER_BODY:%.*]]
 ; CHECK:   inner.body:
 ; CHECK-NEXT:[[TMP0:%.*]] = shl i64 [[INNER_IV]], 1
-; CHECK-NEXT:[[TMP1:%.*]] = add i64 [[TMP0]], [[ROWS_IV]]
-; CHECK-NEXT:[[TMP2:%.*]] = getelementptr i64, ptr [[A:%.*]], i64 [[TMP1]]
+; CHECK-NEXT:[[TMP1:%.*]] = getelementptr i64, ptr [[A:%.*]], i64 [[TMP0]]
+; CHECK-NEXT:[[TMP2:%.*]] = getelementptr i64, ptr [[TMP1]], i64 [[ROWS_IV]]
 ; CHECK-NEXT:[[COL_LOAD:%.*]] = load <2 x i64>, ptr [[TMP2]], align 8
 ; CHECK-NEXT:[[VEC_GEP:%.*]] = getelementptr i64, ptr [[TMP2]], i64 2
 ; CHECK-NEXT:[[COL_LOAD1:%.*]] = load <2 x i64>, ptr [[VEC_GEP]], align 8
 ; CHECK-NEXT:[[TMP3:%.*]] = shl i64 [[COLS_IV]], 2
-; CHECK-NEXT:[[TMP4:%.*]] = add i64 [[TMP3]], [[INNER_IV]]
-; CHECK-NEXT:[[TMP5:%.*]] = getelementptr i64, ptr [[B:%.*]], i64 [[TMP4]]
+; CHECK-NEXT:[[TMP4:%.*]] = getelementptr i64, ptr [[B:%.*]], i64 [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = getelementptr i64, ptr [[TMP4]], i64 [[INNER_IV]]
 ; CHECK-NEXT:[[COL_LOAD2:%.*]] = load <2 x i64>, ptr [[TMP5]], align 8
 ; CHECK-NEXT:[[VEC_GEP3:%.*]] = getelementptr i64, ptr [[TMP5]], i64 4
 ; CHECK-NEXT:[[COL_LOAD4:%.*]] = load <2 x i64>, ptr [[VEC_GEP3]], align 8
@@ -135,

[clang] [MSVC, ARM64] Add _Copy* and _Count* intrinsics (PR #66554)

2023-09-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-platform-windows


Changes

Implement the _Count* and _Copy* Windows ARM intrinsics:

```
double _CopyDoubleFromInt64(__int64)
float _CopyFloatFromInt32(__int32)
__int32 _CopyInt32FromFloat(float)
__int64 _CopyInt64FromDouble(double)
unsigned int _CountLeadingOnes(unsigned long)
unsigned int _CountLeadingOnes64(unsigned __int64)
unsigned int _CountLeadingSigns(long)
unsigned int _CountLeadingSigns64(__int64)
unsigned int _CountLeadingZeros(unsigned long)
unsigned int _CountLeadingZeros64(unsigned __int64)
unsigned int _CountOneBits(unsigned long)
unsigned int _CountOneBits64(unsigned __int64)
```

Full list of intrinsics here: 
[https://learn.microsoft.com/en-us/cpp/intrinsics/arm64-intrinsics](https://learn.microsoft.com/en-us/cpp/intrinsics/arm64-intrinsics)

Bug: [65405](https://github.com/llvm/llvm-project/issues/65405)
---
Full diff: https://github.com/llvm/llvm-project/pull/66554.diff


4 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsAArch64.def (+14-1) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+62) 
- (modified) clang/lib/Headers/intrin.h (+14) 
- (modified) clang/test/CodeGen/arm64-microsoft-intrinsics.c (+140) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index eaae6c9ad846868..c4d34f8e15e8b8d 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -259,7 +259,6 @@ TARGET_HEADER_BUILTIN(__umulh, "ULLiULLiULLi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES,
 
 TARGET_HEADER_BUILTIN(__break, "vi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
 
-
 TARGET_HEADER_BUILTIN(__writex18byte,  "vUNiUc", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__writex18word,  "vUNiUs", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__writex18dword, "vUNiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
@@ -270,6 +269,20 @@ TARGET_HEADER_BUILTIN(__readx18word,  "UsUNi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES,
 TARGET_HEADER_BUILTIN(__readx18dword, "UNiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__readx18qword, "ULLiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 
+TARGET_HEADER_BUILTIN(_CopyDoubleFromInt64, "dSLLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CopyFloatFromInt32, "fSi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CopyInt32FromFloat, "Sif", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CopyInt64FromDouble, "SLLid", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+
+TARGET_HEADER_BUILTIN(_CountLeadingOnes, "UiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingOnes64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingSigns, "UiSLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingSigns64, "UiSLLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingZeros, "UiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingZeros64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountOneBits, "UiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountOneBits64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+
 #undef BUILTIN
 #undef LANGBUILTIN
 #undef TARGET_BUILTIN
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 037a2f9f7b15322..08d09c1c3d8e9de 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10752,6 +10752,68 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 return Load;
   }
 
+  if (BuiltinID == AArch64::BI_CopyDoubleFromInt64 ||
+  BuiltinID == AArch64::BI_CopyFloatFromInt32 ||
+  BuiltinID == AArch64::BI_CopyInt32FromFloat ||
+  BuiltinID == AArch64::BI_CopyInt64FromDouble) {
+return EmitScalarExpr(E->getArg(0));
+  }
+
+  if (BuiltinID == AArch64::BI_CountLeadingOnes ||
+  BuiltinID == AArch64::BI_CountLeadingOnes64 ||
+  BuiltinID == AArch64::BI_CountLeadingZeros ||
+  BuiltinID == AArch64::BI_CountLeadingZeros64) {
+Value *Arg = EmitScalarExpr(E->getArg(0));
+llvm::Type *ArgType = Arg->getType();
+
+if (BuiltinID == AArch64::BI_CountLeadingOnes ||
+BuiltinID == AArch64::BI_CountLeadingOnes64)
+  Arg = Builder.CreateXor(Arg, Constant::getAllOnesValue(ArgType));
+
+Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType);
+Value *Result = Builder.CreateCall(F, {Arg, Builder.getInt1(false)});
+
+if (BuiltinID == AArch64::BI_CountLeadingOnes64 ||
+BuiltinID == AArch64::BI_CountLeadingZeros64)
+  Result = Builder.CreateTrunc(Result, Builder.getInt32Ty());
+return Result;
+  }
+
+  if (BuiltinID == AArch64::BI_CountLeadingSigns ||
+  BuiltinID == AArch64::BI_CountLeadingSigns64) {
+Value *Arg = EmitScalarExpr(E->getArg(0));
+llvm::Type *ArgType = Arg->getType();
+
+Func

[clang] [MSVC, ARM64] Add _Copy* and _Count* intrinsics (PR #66554)

2023-09-15 Thread Amy Huang via cfe-commits

https://github.com/amykhuang created 
https://github.com/llvm/llvm-project/pull/66554

Implement the _Count* and _Copy* Windows ARM intrinsics:

```
double _CopyDoubleFromInt64(__int64)
float _CopyFloatFromInt32(__int32)
__int32 _CopyInt32FromFloat(float)
__int64 _CopyInt64FromDouble(double)
unsigned int _CountLeadingOnes(unsigned long)
unsigned int _CountLeadingOnes64(unsigned __int64)
unsigned int _CountLeadingSigns(long)
unsigned int _CountLeadingSigns64(__int64)
unsigned int _CountLeadingZeros(unsigned long)
unsigned int _CountLeadingZeros64(unsigned __int64)
unsigned int _CountOneBits(unsigned long)
unsigned int _CountOneBits64(unsigned __int64)
```

Full list of intrinsics here: 
[https://learn.microsoft.com/en-us/cpp/intrinsics/arm64-intrinsics](https://learn.microsoft.com/en-us/cpp/intrinsics/arm64-intrinsics)

Bug: [65405](https://github.com/llvm/llvm-project/issues/65405)

>From bbd538659e363e7e7e57fd5e585bc90c2bc0d88b Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Thu, 7 Sep 2023 11:32:17 -0700
Subject: [PATCH] [MSVC, ARM64] Add _Copy* and _Count* intrinsics

---
 clang/include/clang/Basic/BuiltinsAArch64.def |  15 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |  62 
 clang/lib/Headers/intrin.h|  14 ++
 .../test/CodeGen/arm64-microsoft-intrinsics.c | 140 ++
 4 files changed, 230 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index eaae6c9ad846868..c4d34f8e15e8b8d 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -259,7 +259,6 @@ TARGET_HEADER_BUILTIN(__umulh, "ULLiULLiULLi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES,
 
 TARGET_HEADER_BUILTIN(__break, "vi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
 
-
 TARGET_HEADER_BUILTIN(__writex18byte,  "vUNiUc", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__writex18word,  "vUNiUs", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__writex18dword, "vUNiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
@@ -270,6 +269,20 @@ TARGET_HEADER_BUILTIN(__readx18word,  "UsUNi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES,
 TARGET_HEADER_BUILTIN(__readx18dword, "UNiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__readx18qword, "ULLiUNi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 
+TARGET_HEADER_BUILTIN(_CopyDoubleFromInt64, "dSLLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CopyFloatFromInt32, "fSi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CopyInt32FromFloat, "Sif", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CopyInt64FromDouble, "SLLid", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+
+TARGET_HEADER_BUILTIN(_CountLeadingOnes, "UiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingOnes64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingSigns, "UiSLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingSigns64, "UiSLLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingZeros, "UiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountLeadingZeros64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountOneBits, "UiULi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_CountOneBits64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
+
 #undef BUILTIN
 #undef LANGBUILTIN
 #undef TARGET_BUILTIN
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 037a2f9f7b15322..08d09c1c3d8e9de 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10752,6 +10752,68 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 return Load;
   }
 
+  if (BuiltinID == AArch64::BI_CopyDoubleFromInt64 ||
+  BuiltinID == AArch64::BI_CopyFloatFromInt32 ||
+  BuiltinID == AArch64::BI_CopyInt32FromFloat ||
+  BuiltinID == AArch64::BI_CopyInt64FromDouble) {
+return EmitScalarExpr(E->getArg(0));
+  }
+
+  if (BuiltinID == AArch64::BI_CountLeadingOnes ||
+  BuiltinID == AArch64::BI_CountLeadingOnes64 ||
+  BuiltinID == AArch64::BI_CountLeadingZeros ||
+  BuiltinID == AArch64::BI_CountLeadingZeros64) {
+Value *Arg = EmitScalarExpr(E->getArg(0));
+llvm::Type *ArgType = Arg->getType();
+
+if (BuiltinID == AArch64::BI_CountLeadingOnes ||
+BuiltinID == AArch64::BI_CountLeadingOnes64)
+  Arg = Builder.CreateXor(Arg, Constant::getAllOnesValue(ArgType));
+
+Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType);
+Value *Result = Builder.CreateCall(F, {Arg, Builder.getInt1(false)});
+
+if (BuiltinID == AArch64::BI_CountLeadingOnes64 ||
+BuiltinID == AArch64::BI_CountLeadingZeros64)
+  Result = Builder.CreateTrunc(Result, Builder.getInt32Ty());
+return Result;
+  }
+
+  if (BuiltinID == AArch64::BI_CountL

[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread via cfe-commits


@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto&& __projected = std::invoke(__proj, __value);

EricWF wrote:

That's not quite true. It will lifetime extend any _value_ returned from that 
function. However if the function returns a reference to a temporary created in 
the call to the projection, then that reference will dangle once at the 
semicolon.

For example, consider the identity projection that tries to prevent copies:

```
std::string const& identity_proj(std::string const& x) { return x; }
```
No matter what,  the return value ends its lifetime when the argument does. If 
you pass something other than `std::string` to that function, you're in 
trouble. 

Now, it may be the case that any such code is buggy. I'm not 100% convinced it 
is. I haven't found standardese that clarifies the situation. But it would work 
today, and we could continue to make it work my forwarding the projected values 
down to another function which uses them.




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


[PATCH] D155688: [PATCH] [llvm] [InstCombine] Reassociate loop invariant GEP index calculations.

2023-09-15 Thread Dmitriy Smirnov via Phabricator via cfe-commits
d-smirnov updated this revision to Diff 556881.
d-smirnov added a comment.
Herald added subscribers: cfe-commits, wangpc, zzheng.
Herald added a project: clang.

Relaxed checks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155688

Files:
  clang/test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/gep-combine-loop-invariant.ll
  llvm/test/Transforms/LoopUnroll/runtime-unroll-remainder.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-interleaved-accesses.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-vector-reverse.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
  llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse-mask4.ll
  llvm/test/Transforms/LoopVectorize/if-conversion-nest.ll
  llvm/test/Transforms/LoopVectorize/induction.ll
  llvm/test/Transforms/LoopVectorize/interleaved-accesses.ll
  llvm/test/Transforms/LoopVectorize/invariant-store-vectorization.ll
  llvm/test/Transforms/LoopVectorize/runtime-check.ll
  llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll

Index: llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll
===
--- llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll
+++ llvm/test/Transforms/LowerMatrixIntrinsics/multiply-fused-loops.ll
@@ -27,14 +27,14 @@
 ; CHECK-NEXT:br label [[INNER_BODY:%.*]]
 ; CHECK:   inner.body:
 ; CHECK-NEXT:[[TMP0:%.*]] = shl i64 [[INNER_IV]], 2
-; CHECK-NEXT:[[TMP1:%.*]] = add i64 [[TMP0]], [[ROWS_IV]]
-; CHECK-NEXT:[[TMP2:%.*]] = getelementptr double, ptr [[A:%.*]], i64 [[TMP1]]
+; CHECK-NEXT:[[TMP1:%.*]] = getelementptr double, ptr [[A:%.*]], i64 [[TMP0]]
+; CHECK-NEXT:[[TMP2:%.*]] = getelementptr double, ptr [[TMP1]], i64 [[ROWS_IV]]
 ; CHECK-NEXT:[[COL_LOAD:%.*]] = load <2 x double>, ptr [[TMP2]], align 8
 ; CHECK-NEXT:[[VEC_GEP:%.*]] = getelementptr double, ptr [[TMP2]], i64 4
 ; CHECK-NEXT:[[COL_LOAD1:%.*]] = load <2 x double>, ptr [[VEC_GEP]], align 8
 ; CHECK-NEXT:[[TMP3:%.*]] = shl i64 [[COLS_IV]], 2
-; CHECK-NEXT:[[TMP4:%.*]] = add i64 [[TMP3]], [[INNER_IV]]
-; CHECK-NEXT:[[TMP5:%.*]] = getelementptr double, ptr [[B:%.*]], i64 [[TMP4]]
+; CHECK-NEXT:[[TMP4:%.*]] = getelementptr double, ptr [[B:%.*]], i64 [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = getelementptr double, ptr [[TMP4]], i64 [[INNER_IV]]
 ; CHECK-NEXT:[[COL_LOAD2:%.*]] = load <2 x double>, ptr [[TMP5]], align 8
 ; CHECK-NEXT:[[VEC_GEP3:%.*]] = getelementptr double, ptr [[TMP5]], i64 4
 ; CHECK-NEXT:[[COL_LOAD4:%.*]] = load <2 x double>, ptr [[VEC_GEP3]], align 8
@@ -55,8 +55,8 @@
 ; CHECK-NEXT:[[ROWS_STEP]] = add i64 [[ROWS_IV]], 2
 ; CHECK-NEXT:[[ROWS_COND_NOT:%.*]] = icmp eq i64 [[ROWS_STEP]], 4
 ; CHECK-NEXT:[[TMP10:%.*]] = shl i64 [[COLS_IV]], 2
-; CHECK-NEXT:[[TMP11:%.*]] = add i64 [[TMP10]], [[ROWS_IV]]
-; CHECK-NEXT:[[TMP12:%.*]] = getelementptr double, ptr [[C:%.*]], i64 [[TMP11]]
+; CHECK-NEXT:[[TMP11:%.*]] = getelementptr double, ptr [[C:%.*]], i64 [[TMP10]]
+; CHECK-NEXT:[[TMP12:%.*]] = getelementptr double, ptr [[TMP11]], i64 [[ROWS_IV]]
 ; CHECK-NEXT:store <2 x double> [[TMP7]], ptr [[TMP12]], align 8
 ; CHECK-NEXT:[[VEC_GEP16:%.*]] = getelementptr double, ptr [[TMP12]], i64 4
 ; CHECK-NEXT:store <2 x double> [[TMP9]], ptr [[VEC_GEP16]], align 8
@@ -103,14 +103,14 @@
 ; CHECK-NEXT:br label [[INNER_BODY:%.*]]
 ; CHECK:   inner.body:
 ; CHECK-NEXT:[[TMP0:%.*]] = shl i64 [[INNER_IV]], 1
-; CHECK-NEXT:[[TMP1:%.*]] = add i64 [[TMP0]], [[ROWS_IV]]
-; CHECK-NEXT:[[TMP2:%.*]] = getelementptr i64, ptr [[A:%.*]], i64 [[TMP1]]
+; CHECK-NEXT:[[TMP1:%.*]] = getelementptr i64, ptr [[A:%.*]], i64 [[TMP0]]
+; CHECK-NEXT:[[TMP2:%.*]] = getelementptr i64, ptr [[TMP1]], i64 [[ROWS_IV]]
 ; CHECK-NEXT:[[COL_LOAD:%.*]] = load <2 x i64>, ptr [[TMP2]], align 8
 ; CHECK-NEXT:[[VEC_GEP:%.*]] = getelementptr i64, ptr [[TMP2]], i64 2
 ; CHECK-NEXT:[[COL_LOAD1:%.*]] = load <2 x i64>, ptr [[VEC_GEP]], align 8
 ; CHECK-NEXT:[[TMP3:%.*]] = shl i64 [[COLS_IV]], 2
-; CHECK-NEXT:[[TMP4:%.*]] = add i64 [[TMP3]], [[INNER_IV]]
-; CHECK-NEXT:[[TMP5:%.*]] = getelementptr i64, ptr [[B:%.*]], i64 [[TMP4]]
+; CHECK-NEXT:[[TMP4:%.*]] = getelementptr i64, ptr [[B:%.*]], i64 [[TMP3]]
+; CHECK-NEXT:[[TMP5:%.*]] = getelementptr i64, ptr [[TMP4]], i64 [[INNER_IV]]
 ; CHECK-NEXT:[[COL_LOAD2:%.*]] = load <2 x i64>, ptr [[TMP5]], align 8
 ; CHECK-NEXT:[[VEC_GEP3:%.*]] = getelementptr i64, ptr [[TMP5]], i64 4
 ; CHECK-NEXT:[[COL_LOAD4:%.*]] = load <2 x i64>, ptr [[VEC_GEP3]], align 8
@@ -135,8 +135,8 @@
 ; CHECK-NEXT:[[ROWS_STEP]] = add i64 [[ROWS_IV]], 2
 ; CHECK-NEXT:[[ROWS_COND_NOT:%.*]] = icmp eq i64 [[ROWS_IV]], 0
 ; CHECK-NEXT:[

[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)

2023-09-15 Thread Reid Kleckner via cfe-commits

https://github.com/rnk commented:

This seems fine to me, but it's hard to understand if this is redundant with 
some other "ParseFunction" scope from the tests. WDYT @MaskRay ?

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


[clang-tools-extra] [clang-tidy] Fix handling --driver-mode= (PR #66553)

2023-09-15 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

If anyone see any other alternative implementations or see some potential 
issues, then any comments are welcome.

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


[clang-tools-extra] [clang-tidy] Fix handling --driver-mode= (PR #66553)

2023-09-15 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix handling --driver-mode= (PR #66553)

2023-09-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy


Changes

Driver mode passed as an extra argument (command line or config) were not 
utilized for removing invalid arguments in stripPositionalArgs function, and 
even if passed as config driver mode were not used for dependency file striping 
leading to invalid handling of -MD. Additionally driver mode were needed even 
if user already added cl.exe after --.

Fixes: #65108, #53674, #52687, #44701
---
Full diff: https://github.com/llvm/llvm-project/pull/66553.diff


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp (+102-25) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5) 
- (added) clang-tools-extra/test/clang-tidy/infrastructure/driver-mode.cpp 
(+57) 


``diff
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index dd7f8141a694e2a..152bfbf6bc61f99 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -19,6 +19,7 @@
 #include "../ClangTidyForceLinker.h"
 #include "../GlobList.h"
 #include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/PluginLoader.h"
@@ -26,6 +27,7 @@
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/WithColor.h"
+#include 
 #include 
 
 using namespace clang::tooling;
@@ -450,7 +452,7 @@ static StringRef closest(StringRef Value, const StringSet<> 
&Allowed) {
   return Closest;
 }
 
-static constexpr StringLiteral VerifyConfigWarningEnd = " [-verify-config]\n";
+static constexpr StringRef VerifyConfigWarningEnd = " [-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> &AllChecks, StringRef CheckGlob,
  StringRef Source) {
@@ -525,8 +527,95 @@ static bool verifyFileExtensions(
   return AnyInvalid;
 }
 
+static SmallString<256> makeAbsolute(llvm::StringRef Input) {
+  if (Input.empty())
+return {};
+  SmallString<256> AbsolutePath(Input);
+  if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
+llvm::errs() << "Can't make absolute path from " << Input << ": "
+ << EC.message() << "\n";
+  }
+  return AbsolutePath;
+}
+
+static llvm::IntrusiveRefCntPtr createBaseFS() {
+  llvm::IntrusiveRefCntPtr BaseFS(
+  new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
+
+  if (!VfsOverlay.empty()) {
+IntrusiveRefCntPtr VfsFromFile =
+getVfsFromFile(VfsOverlay, BaseFS);
+if (!VfsFromFile)
+  return nullptr;
+BaseFS->pushOverlay(std::move(VfsFromFile));
+  }
+  return BaseFS;
+}
+
+static llvm::Expected
+recreateOptionsParserIfNeeded(llvm::ArrayRef Args,
+  llvm::Expected 
OptionsParser,
+  const ClangTidyOptions &EffectiveOptions) {
+
+  auto DoubleDashIt = std::find(Args.begin(), Args.end(), StringRef("--"));
+  if (DoubleDashIt == Args.end() || Args.empty() ||
+  Args.back() == StringRef("--"))
+return OptionsParser;
+
+  auto IsDriverMode = [](StringRef Argument) {
+return Argument.startswith("--driver-mode=");
+  };
+
+  if (Args.end() !=
+  std::find_if(std::next(DoubleDashIt), Args.end(), IsDriverMode))
+return OptionsParser;
+
+  std::vector CommandArguments(std::next(DoubleDashIt),
+Args.end());
+  if (CommandArguments.empty() ||
+  llvm::StringRef(CommandArguments.front()).startswith("-"))
+CommandArguments.insert(CommandArguments.begin(), "clang-tool");
+
+  CommandArguments =
+  OptionsParser->getArgumentsAdjuster()(CommandArguments, "");
+  if (EffectiveOptions.ExtraArgsBefore)
+CommandArguments = tooling::getInsertArgumentAdjuster(
+*EffectiveOptions.ExtraArgsBefore,
+tooling::ArgumentInsertPosition::BEGIN)(CommandArguments, "");
+
+  if (EffectiveOptions.ExtraArgs)
+CommandArguments = tooling::getInsertArgumentAdjuster(
+*EffectiveOptions.ExtraArgs,
+tooling::ArgumentInsertPosition::END)(CommandArguments, "");
+
+  auto DriverModeIt = std::find_if(CommandArguments.begin(),
+   CommandArguments.end(), IsDriverMode);
+  if (DriverModeIt == CommandArguments.end()) {
+std::string ExeName = CommandArguments.front();
+tooling::addTargetAndModeForProgramName(CommandArguments, ExeName);
+DriverModeIt = std::find_if(CommandArguments.begin(),
+CommandArguments.end(), IsDriverMode);
+  }
+
+  if (DriverModeIt == CommandArguments.end())
+return OptionsParser;
+
+  std::vector NewArgs(Args.begin(), Args.end());
+  auto InsertIt =
+  NewArgs.begin() + std::distance(Args.begin(), DoubleDashIt) + 1U;
+  if (!StringRef(*InsertIt).startswith("-"))
+++InsertIt;
+  NewArgs.insert(InsertIt, DriverModeIt->c_str());
+
+  int ArgC = NewA

[clang-tools-extra] [clang-tidy] Fix handling --driver-mode= (PR #66553)

2023-09-15 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/66553

Driver mode passed as an extra argument (command line or config) were not 
utilized for removing invalid arguments in stripPositionalArgs function, and 
even if passed as config driver mode were not used for dependency file striping 
leading to invalid handling of -MD. Additionally driver mode were needed even 
if user already added cl.exe after --.

Fixes: #65108, #53674, #52687, #44701

>From 3bc42b19b245e3497aadfc7642957cd349712723 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Fri, 15 Sep 2023 21:39:17 +
Subject: [PATCH] [clang-tidy] Fix handling --driver-mode=

Driver mode passed as an extra argument (command line or config)
were not utilized for removing invalid arguments in
stripPositionalArgs function, and even if passed as config
driver mode were not used for dependency file striping
leading to invalid handling of -MD. Additionally driver mode
were needed even if user already added cl.exe after --.
---
 .../clang-tidy/tool/ClangTidyMain.cpp | 127 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../clang-tidy/infrastructure/driver-mode.cpp |  57 
 3 files changed, 164 insertions(+), 25 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/driver-mode.cpp

diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index dd7f8141a694e2a..152bfbf6bc61f99 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -19,6 +19,7 @@
 #include "../ClangTidyForceLinker.h"
 #include "../GlobList.h"
 #include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/PluginLoader.h"
@@ -26,6 +27,7 @@
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/WithColor.h"
+#include 
 #include 
 
 using namespace clang::tooling;
@@ -450,7 +452,7 @@ static StringRef closest(StringRef Value, const StringSet<> 
&Allowed) {
   return Closest;
 }
 
-static constexpr StringLiteral VerifyConfigWarningEnd = " [-verify-config]\n";
+static constexpr StringRef VerifyConfigWarningEnd = " [-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> &AllChecks, StringRef CheckGlob,
  StringRef Source) {
@@ -525,8 +527,95 @@ static bool verifyFileExtensions(
   return AnyInvalid;
 }
 
+static SmallString<256> makeAbsolute(llvm::StringRef Input) {
+  if (Input.empty())
+return {};
+  SmallString<256> AbsolutePath(Input);
+  if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
+llvm::errs() << "Can't make absolute path from " << Input << ": "
+ << EC.message() << "\n";
+  }
+  return AbsolutePath;
+}
+
+static llvm::IntrusiveRefCntPtr createBaseFS() {
+  llvm::IntrusiveRefCntPtr BaseFS(
+  new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
+
+  if (!VfsOverlay.empty()) {
+IntrusiveRefCntPtr VfsFromFile =
+getVfsFromFile(VfsOverlay, BaseFS);
+if (!VfsFromFile)
+  return nullptr;
+BaseFS->pushOverlay(std::move(VfsFromFile));
+  }
+  return BaseFS;
+}
+
+static llvm::Expected
+recreateOptionsParserIfNeeded(llvm::ArrayRef Args,
+  llvm::Expected 
OptionsParser,
+  const ClangTidyOptions &EffectiveOptions) {
+
+  auto DoubleDashIt = std::find(Args.begin(), Args.end(), StringRef("--"));
+  if (DoubleDashIt == Args.end() || Args.empty() ||
+  Args.back() == StringRef("--"))
+return OptionsParser;
+
+  auto IsDriverMode = [](StringRef Argument) {
+return Argument.startswith("--driver-mode=");
+  };
+
+  if (Args.end() !=
+  std::find_if(std::next(DoubleDashIt), Args.end(), IsDriverMode))
+return OptionsParser;
+
+  std::vector CommandArguments(std::next(DoubleDashIt),
+Args.end());
+  if (CommandArguments.empty() ||
+  llvm::StringRef(CommandArguments.front()).startswith("-"))
+CommandArguments.insert(CommandArguments.begin(), "clang-tool");
+
+  CommandArguments =
+  OptionsParser->getArgumentsAdjuster()(CommandArguments, "");
+  if (EffectiveOptions.ExtraArgsBefore)
+CommandArguments = tooling::getInsertArgumentAdjuster(
+*EffectiveOptions.ExtraArgsBefore,
+tooling::ArgumentInsertPosition::BEGIN)(CommandArguments, "");
+
+  if (EffectiveOptions.ExtraArgs)
+CommandArguments = tooling::getInsertArgumentAdjuster(
+*EffectiveOptions.ExtraArgs,
+tooling::ArgumentInsertPosition::END)(CommandArguments, "");
+
+  auto DriverModeIt = std::find_if(CommandArguments.begin(),
+   CommandArguments.end(), IsDriverMode);
+  if (DriverModeIt == CommandArguments.end()) {
+std::string ExeName = CommandArguments.fro

[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

https://github.com/pandaninjas updated 
https://github.com/llvm/llvm-project/pull/66315

>From ead65bfcb70be46788bc9e88c891e7ae7f91b8d7 Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 17:38:17 -0700
Subject: [PATCH 01/14] [libc++] Prevent calling the projection more than three
 times

---
 libcxx/include/__algorithm/ranges_clamp.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 9613f7f37720a6c..ca46675eb4b3041 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto &projection = std::invoke(__proj, __value);
+if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), 
std::invoke(__proj, __value)))
+else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
   return __high;
 else
   return __value;

>From c18d60870ac342a95a5528396a8e0c7b91717cbb Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 18:56:44 -0700
Subject: [PATCH 02/14] [libc++] Run clang-format on file

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index ca46675eb4b3041..3469a6419b2270f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto &projection = std::invoke(__proj, __value);
+auto& projection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From b40e791f0e9fedbb19936851e1e71decf00331fa Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:20 -0700
Subject: [PATCH 03/14] [libcxx] CamelCase projection and make variable name
 more descriptive

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3469a6419b2270f..3adb5fa828e1ee5 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto& projection = std::invoke(__proj, __value);
+auto& ValueProjection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From a8907624defa4cc4f47520a2d93a8bd042816aa2 Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:47 -0700
Subject: [PATCH 04/14] [libcxx] properly change variable name

---
 libcxx/include/__algorithm/ranges_clamp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3adb5fa828e1ee5..3d7a224b3649a3f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -38,9 +38,9 @@ struct __fn {
  "Bad bounds passed to std::ranges::clamp");
 
 auto& ValueProjection = std::invoke(__proj, __value);
-if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
+if (std::invoke(__comp, ValueProjection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
+else if (std::invoke(__comp, std::invoke(__proj, __high), ValueProjection))
   return __high;
 else
   return __value;

>From 15d3b2b79fbd61f97b0312e0913cede36b5b202d Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Thu, 14 Sep 2023 10:37:34 -0700
Subject: [PATCH 05/14] Apply suggestions from code review

---
 libcxx/include/__algorithm/ranges_clamp.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3d7a224b3649a3f..

[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

https://github.com/pandaninjas updated 
https://github.com/llvm/llvm-project/pull/66315

>From ead65bfcb70be46788bc9e88c891e7ae7f91b8d7 Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 17:38:17 -0700
Subject: [PATCH 01/14] [libc++] Prevent calling the projection more than three
 times

---
 libcxx/include/__algorithm/ranges_clamp.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 9613f7f37720a6c..ca46675eb4b3041 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto &projection = std::invoke(__proj, __value);
+if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), 
std::invoke(__proj, __value)))
+else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
   return __high;
 else
   return __value;

>From c18d60870ac342a95a5528396a8e0c7b91717cbb Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 18:56:44 -0700
Subject: [PATCH 02/14] [libc++] Run clang-format on file

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index ca46675eb4b3041..3469a6419b2270f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto &projection = std::invoke(__proj, __value);
+auto& projection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From b40e791f0e9fedbb19936851e1e71decf00331fa Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:20 -0700
Subject: [PATCH 03/14] [libcxx] CamelCase projection and make variable name
 more descriptive

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3469a6419b2270f..3adb5fa828e1ee5 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto& projection = std::invoke(__proj, __value);
+auto& ValueProjection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From a8907624defa4cc4f47520a2d93a8bd042816aa2 Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:47 -0700
Subject: [PATCH 04/14] [libcxx] properly change variable name

---
 libcxx/include/__algorithm/ranges_clamp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3adb5fa828e1ee5..3d7a224b3649a3f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -38,9 +38,9 @@ struct __fn {
  "Bad bounds passed to std::ranges::clamp");
 
 auto& ValueProjection = std::invoke(__proj, __value);
-if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
+if (std::invoke(__comp, ValueProjection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
+else if (std::invoke(__comp, std::invoke(__proj, __high), ValueProjection))
   return __high;
 else
   return __value;

>From 15d3b2b79fbd61f97b0312e0913cede36b5b202d Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Thu, 14 Sep 2023 10:37:34 -0700
Subject: [PATCH 05/14] Apply suggestions from code review

---
 libcxx/include/__algorithm/ranges_clamp.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3d7a224b3649a3f..

[clang] Honor -fno-sanitize-link-runtime for libclang_rt.asan_static (PR #66414)

2023-09-15 Thread via cfe-commits

colincross wrote:

> Which branch exactly changed?

https://github.com/llvm/llvm-project/pull/66414/commits/311cdea702b2d6c7264cbc3a3bd07ae0708ad4cd#diff-c89ebf1fc950679f63c19739a35aa966a12674f7d61af6fb382ab1fa0ee21dd7L1110
 is the branch added by https://reviews.llvm.org/D122407 that wasn't checking 
`SanArgs.linkRuntimes()`, but now does.

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


[PATCH] D148381: [Clang] Implement the 'counted_by' attribute

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

In D148381#4645600 , @void wrote:

> Added more error messages. Changed some code around to align with coding 
> practices. Added some more test cases.

Doing a full "allmodconfig" Linux kernel build with my 200ish __counted_by 
annotations is building cleanly. Yay! :)




Comment at: clang/test/Sema/attr-counted-by.c:21
+  struct bar *fam[] __counted_by(non_integer); // expected-note {{counted_by 
field 'non_integer' declared here}}
+};

void wrote:
> aaron.ballman wrote:
> > Please add test with the other strange FAM-like members, as well as one 
> > that is just a trailing constant array of size 2.
> > 
> > Some more tests or situations to consider:
> > ```
> > struct S {
> >   struct {
> > int NotInThisStruct;
> >   };
> >   int FAM[] __counted_by(NotInThisStruct); // Should this work?
> > };
> > 
> > int Global;
> > struct T {
> >   int FAM[] __counted_by(Global); // Should fail per your design but is 
> > that the behavior you want?
> > };
> > 
> > struct U {
> >   struct {
> > int Count;
> >   } data;
> >   int FAM[] __counted_by(data.Count); // Thoughts?
> > };
> > 
> > struct V {
> >   int Sizes[2];
> >   int FAM[] __counted_by(Sizes[0]); // Thoughts?
> > };
> > ```
> > (I'm not suggesting any of this needs to be accepted in order to land the 
> > patch.)
> > 
> > You should also have tests showing the attribute is diagnosed when applied 
> > to something other than a field, given something other than an identifier, 
> > is given zero arguments, and is given two arguments.
> I added a "this isn't a flexible array member" error message.
> 
> ```
> struct S {
>   struct {
> int NotInThisStruct;
>   };
>   int FAM[] __counted_by(NotInThisStruct); // Should this work?
> };
> ```
> 
> Yes, I believe it should. Kees had a similar example:
> 
> ```
> struct S {
>   int x;
>   struct {
> int count;
> int FAM[] __counted_by(count);
>   };
> };
> ```
> 
> I made changes to support this. It may be controversial, so please let me 
> know if you or anyone has an issue with it.
> 
> ```
> int Global;
> struct T {
>   int FAM[] __counted_by(Global); // Should fail per your design but is that 
> the behavior you want?
> };
> ```
> 
> Yes, it should fail. I'll add a test case.
> 
> ```
> struct U {
>   struct {
> int Count;
>   } data;
>   int FAM[] __counted_by(data.Count); // Thoughts?
> };
> ```
> 
> I don't think we should support that at the moment. Referencing arbitrary 
> fields in a nested structure is very complicated and the syntax for it is not 
> at all settled on.
> 
> ```
> struct V {
>   int Sizes[2];
>   int FAM[] __counted_by(Sizes[0]); // Thoughts?
> };
> ```
> 
> Hmm...Not sure. I'll ask the GCC person who's implementing this on her side 
> about this.
> Yes, I believe it should. Kees had a similar example:
> 
> ```
> struct S {
>   int x;
>   struct {
> int count;
> int FAM[] __counted_by(count);
>   };
> };
> ```
> 
> I made changes to support this. It may be controversial, so please let me 
> know if you or anyone has an issue with it.

FWIW, the Linux kernel has a LOT of this style (in an anonymous struct), which 
is why I wanted to make sure it was supported in this first version of the 
feature.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

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


[clang] [clang][CodeGen] Use byval for SystemZ indirect arguments (PR #66404)

2023-09-15 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

> Both s390x and x86_64 ABIs require passing large structs via a pointer

Wrong.  x86_64 passes structs by value (copying the data into the argument 
list).  It just looks like a pointer in the IR because LLVM can't really handle 
large values in registers.

---

The semantics of byval are "the call instruction allocates memory, and copies 
the argument into that memory".  That generally means copying the memory into 
the argument list, although LangRef doesn't actually mandate that.

If byval were actually implemented correctly for SystemZ, adding would 
completely change the generated code in a way that's not actually compatible 
with the SystemZ C ABI.

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


[libunwind] [libunwind][AIX] Fix up TOC register if unw_getcontext is called from a different module (PR #66549)

2023-09-15 Thread via cfe-commits


@@ -305,9 +305,22 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
   mflr  0
   std   0, PPC64_OFFS_SRR0(3) // store lr as ssr0
   PPC64_STR(1)
+  PPC64_STR(4)  // Save r4 first since it will be used for fixing r2.
+#if defined(_AIX)
+  // The TOC register (r2) was changed by the glue code if unw_getcontext
+  // is called from a different module. Save the original TOC register
+  // in the context if this is the case.
+  mflr  4
+  lwz   4, 0(4) // Get the first instruction at the return address.
+  lis   0, 0xe841   // Is it reloading the TOC register "ld 2,40(1)"?

stephenpeckham wrote:

Why is the 32- and 64-bit code different?  Can't you use the same comparison 
technique?

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


[libunwind] [libunwind][AIX] Fix up TOC register if unw_getcontext is called from a different module (PR #66549)

2023-09-15 Thread via cfe-commits


@@ -305,9 +305,22 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
   mflr  0
   std   0, PPC64_OFFS_SRR0(3) // store lr as ssr0
   PPC64_STR(1)
+  PPC64_STR(4)  // Save r4 first since it will be used for fixing r2.
+#if defined(_AIX)
+  // The TOC register (r2) was changed by the glue code if unw_getcontext
+  // is called from a different module. Save the original TOC register
+  // in the context if this is the case.
+  mflr  4

stephenpeckham wrote:

Not a bit deal, but LR is already in r0.  Do you need mflr twice? You could use 
mr r4,r0.

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


[clang] a52560c - [clang] Remove spurious trailing whitespace

2023-09-15 Thread Louis Dionne via cfe-commits

Author: Louis Dionne
Date: 2023-09-15T17:26:16-04:00
New Revision: a52560c8dd804104041e3cde4d9b9b89bf22f81e

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

LOG: [clang] Remove spurious trailing whitespace

Added: 


Modified: 
clang/lib/CodeGen/CGCoroutine.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 0e63ef91415ee13..448943084acedf3 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -833,7 +833,7 @@ RValue CodeGenFunction::EmitCoroutineIntrinsic(const 
CallExpr *E,
   // argument.
   if (IID == llvm::Intrinsic::coro_end)
 Args.push_back(llvm::ConstantTokenNone::get(getLLVMContext()));
-  
+
   llvm::Function *F = CGM.getIntrinsic(IID);
   llvm::CallInst *Call = Builder.CreateCall(F, Args);
 



___
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-15 Thread Giulio Eulisse via cfe-commits


@@ -0,0 +1,133 @@
+//===- 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 
+#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.
+template  class PagedVector {

ktf wrote:

Done in the last commit.

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] [clang-format] Fix a bug in ContinuationIndenter (PR #66354)

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

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


[clang] 5ed94c6 - [clang-format] Fix a bug in ContinuationIndenter (#66354)

2023-09-15 Thread via cfe-commits

Author: Owen Pan
Date: 2023-09-15T14:20:41-07:00
New Revision: 5ed94c6e3d30d342b7bc74facbcd0740d080c156

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

LOG: [clang-format] Fix a bug in ContinuationIndenter (#66354)

See https://reviews.llvm.org/D136154#3890747 for context.

Fixes part of #58592.

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 17567572f030542..8ce7e5b8a2a2055 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -876,15 +876,15 @@ void 
ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
  FormatStyle::BCIS_AfterColon) {
 CurrentState.Indent = State.Column;
 CurrentState.LastSpace = State.Column;
-  } else if ((Previous.isOneOf(TT_BinaryOperator, TT_ConditionalExpr,
-   TT_CtorInitializerColon)) &&
+  } else if (Previous.isOneOf(TT_ConditionalExpr, TT_CtorInitializerColon)) {
+CurrentState.LastSpace = State.Column;
+  } else if (Previous.is(TT_BinaryOperator) &&
  ((Previous.getPrecedence() != prec::Assignment &&
(Previous.isNot(tok::lessless) || Previous.OperatorIndex != 0 ||
 Previous.NextOperator)) ||
   Current.StartsBinaryExpression)) {
 // Indent relative to the RHS of the expression unless this is a simple
-// assignment without binary expression on the RHS. Also indent relative to
-// unary operators and the colons of constructor initializers.
+// assignment without binary expression on the RHS.
 if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None)
   CurrentState.LastSpace = State.Column;
   } else if (Previous.is(TT_InheritanceColon)) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 4f72166bdce2d73..0d0fbdb84e3271b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7108,6 +7108,29 @@ TEST_F(FormatTest, 
ExpressionIndentationBreakingBeforeOperators) {
"(someOtherLongishConditionPart1 || "
"someOtherEvenLongerNestedConditionPart2);",
Style);
+
+  Style = getLLVMStyleWithColumns(20);
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  Style.BinPackParameters = false;
+  Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
+  Style.ContinuationIndentWidth = 2;
+  verifyFormat("struct Foo {\n"
+   "  Foo(\n"
+   "int arg1,\n"
+   "int arg2)\n"
+   "  : Base(\n"
+   "  arg1,\n"
+   "  arg2) {}\n"
+   "};",
+   Style);
+  verifyFormat("return abc\n"
+   " ? foo(\n"
+   " a,\n"
+   " b,\n"
+   " bar(\n"
+   "   abc))\n"
+   " : g(abc);",
+   Style);
 }
 
 TEST_F(FormatTest, ExpressionIndentationStrictAlign) {



___
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-15 Thread Giulio Eulisse via cfe-commits


@@ -0,0 +1,133 @@
+//===- 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 
+#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.
+template  class PagedVector {
+  // 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 Lookup;
+  // 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 oder of
+  // the elements however depends on the order of access of the pages.
+  mutable std::vector Data;
+
+public:
+  // Lookup an element at position Index.
+  T &operator[](std::size_t Index) const { return at(Index); }
+
+  // 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 &at(std::size_t Index) const {
+assert(Index < Size);
+assert(Index / PAGE_SIZE < Lookup.size());
+auto &PageId = Lookup[Index / PAGE_SIZE];
+// If the range is not filled, fill it
+if (PageId == -1) {
+  int OldSize = Data.size();
+  PageId = OldSize / PAGE_SIZE;
+  // Allocate the memory
+  Data.resize(OldSize + PAGE_SIZE);
+  // Fill the whole capacity with empty elements
+  for (int I = 0; I < PAGE_SIZE; ++I) {
+Data[I + OldSize] = T();
+  }

ktf wrote:

Done in the last commit.

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-15 Thread Giulio Eulisse via cfe-commits


@@ -0,0 +1,133 @@
+//===- 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 
+#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.
+template  class PagedVector {
+  // 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 Lookup;

ktf wrote:

Done in the last commit.

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-15 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf updated https://github.com/llvm/llvm-project/pull/66430

>From b952f0577dfe8112f394bd5392212f843c0cc86e Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 21:58:21 +0200
Subject: [PATCH 01/14] Introduce PagedVector class

The goal of the class is to be an (almost) drop in replacement for
SmallVector and std::vector when those are presized and filled later,
as it happens in SourceManager and ASTReader.

By splitting the actual vector in pages of the same size and allocating
the pages only when they are needed, using this containers reduces the
memory usage by a factor 4 for the cases relevant to the ALICE
experiment ROOT / cling usage.
---
 llvm/include/llvm/ADT/PagedVector.h | 96 +
 1 file changed, 96 insertions(+)
 create mode 100644 llvm/include/llvm/ADT/PagedVector.h

diff --git a/llvm/include/llvm/ADT/PagedVector.h 
b/llvm/include/llvm/ADT/PagedVector.h
new file mode 100644
index 000..dab0d249aa706e4
--- /dev/null
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -0,0 +1,96 @@
+//===- 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 
+
+// 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 {
+  size_t Size = 0;
+  // Index of where to find a given page in the data
+  mutable std::vector Lookup;
+  // Actual data
+  mutable std::vector Data;
+
+public:
+  // Add a range to the vector.
+  // When vector is accessed, it will call the callback to fill the range
+  // with data.
+
+  // Lookup an element at position i.
+  // If the given range is not filled, it will be filled.
+  // If the given range is filled, return the element.
+  T &operator[](int Index) const { return at(Index); }
+
+  T &at(int Index) const {
+auto &PageId = Lookup[Index / PAGE_SIZE];
+// If the range is not filled, fill it
+if (PageId == -1) {
+  int OldSize = Data.size();
+  PageId = OldSize / PAGE_SIZE;
+  // Allocate the memory
+  Data.resize(OldSize + PAGE_SIZE);
+  // Fill the whole capacity with empty elements
+  for (int I = 0; I < PAGE_SIZE; ++I) {
+Data[I + OldSize] = T();
+  }
+}
+// Return the element
+return Data[Index % PAGE_SIZE + PAGE_SIZE * PageId];
+  }
+
+  // Return the size of the vector
+  size_t capacity() const { return Lookup.size() * PAGE_SIZE; }
+
+  size_t size() const { return Size; }
+
+  // Expands the vector to the given size.
+  // If the vector is already bigger, does nothing.
+  void expand(size_t NewSize) {
+// You cannot shrink the vector, otherwise
+// you would have to invalidate
+assert(NewSize >= Size);
+if (NewSize <= Size) {
+  return;
+}
+if (NewSize <= capacity()) {
+  Size = NewSize;
+  return;
+}
+auto Pages = NewSize / PAGE_SIZE;
+auto Remainder = NewSize % PAGE_SIZE;
+if (Remainder) {
+  Pages += 1;
+}
+assert(Pages > Lookup.size());
+Lookup.resize(Pages, -1);
+Size = NewSize;
+  }
+
+  // Return true if the vector is empty
+  bool empty() const { return Size == 0; }
+  /// Clear the vector
+  void clear() {
+Size = 0;
+Lookup.clear();
+Data.clear();
+  }
+
+  std::vector const &materialised() const { return Data; }
+};
+
+#endif // LLVM_ADT_PAGEDVECTOR_H

>From f0c75c8af0fea27b5b758e2e5775787f33595de3 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 22:20:29 +0200
Subject: [PATCH 02/14] Use PagedVector to reduce memory usage of sparsely
 populated vectors

---
 clang/include/clang/Basic/SourceManager.h |  3 ++-
 clang/include/clang/Serialization/ASTReader.h |  5 +++--
 clang/lib/Basic/SourceManager.cpp | 12 ++--
 clang/lib/Serialization/ASTReader.cpp |  9 +
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 2f846502d6f3327..b1942a3d86afc37 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -43,6 +43,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/PointerIntPai

[libunwind] [libunwind][AIX] Fix up TOC register if unw_getcontext is called from a different module (PR #66549)

2023-09-15 Thread via cfe-commits

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


[clang] [Coverage] Add coverage for constructor member initializers. (PR #66441)

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

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


[clang] 0b8df84 - [Coverage] Add coverage for constructor member initializers. (#66441)

2023-09-15 Thread via cfe-commits

Author: Zequan Wu
Date: 2023-09-15T17:06:04-04:00
New Revision: 0b8df841f951beb5690cd74c91bd54a8de31df14

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

LOG: [Coverage] Add coverage for constructor member initializers. (#66441)

Before, constructor member initializers are shown as not covered. This
adds coverage info for them.

Added: 
clang/test/CoverageMapping/ctor.cpp

Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 7cc2e0630f65cd7..bb814dfbfd580f1 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1036,11 +1036,20 @@ struct CounterCoverageMappingBuilder
 // lexer may not be able to report back precise token end locations for
 // these children nodes (llvm.org/PR39822), and moreover users will not be
 // able to see coverage for them.
+Counter BodyCounter = getRegionCounter(Body);
 bool Defaulted = false;
 if (auto *Method = dyn_cast(D))
   Defaulted = Method->isDefaulted();
+if (auto *Ctor = dyn_cast(D)) {
+  for (auto *Initializer : Ctor->inits()) {
+if (Initializer->isWritten()) {
+  auto *Init = Initializer->getInit();
+  propagateCounts(BodyCounter, Init);
+}
+  }
+}
 
-propagateCounts(getRegionCounter(Body), Body,
+propagateCounts(BodyCounter, Body,
 /*VisitChildren=*/!Defaulted);
 assert(RegionStack.empty() && "Regions entered but never exited");
   }

diff  --git a/clang/test/CoverageMapping/ctor.cpp 
b/clang/test/CoverageMapping/ctor.cpp
new file mode 100644
index 000..1cf12cd738c2ccd
--- /dev/null
+++ b/clang/test/CoverageMapping/ctor.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name continue.c %s | FileCheck %s
+
+class A {
+public:
+int a;
+A(int a): a(a) {}
+};
+class B: public A {
+public:
+int b;
+int c;
+B(int x, int y)
+: A(x), // CHECK:  File 0, [[@LINE]]:7 -> [[@LINE]]:11 
= #0
+// CHECK-NEXT: File 0, [[@LINE+1]]:7 -> 
[[@LINE+1]]:13 = #0
+b(x == 0? 1: 2),// CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:19 
= #0
+// CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> 
[[@LINE-1]]:13 = #1, (#0 - #1)
+// CHECK-NEXT: Gap,File 0, [[@LINE-2]]:14 -> 
[[@LINE-2]]:15 = #1
+// CHECK-NEXT: File 0, [[@LINE-3]]:15 -> 
[[@LINE-3]]:16 = #1
+// CHECK-NEXT: File 0, [[@LINE-4]]:18 -> 
[[@LINE-4]]:19 = (#0 - #1)
+// CHECK-NEXT: File 0, [[@LINE+2]]:7 -> 
[[@LINE+8]]:8 = #0
+// CHECK-NEXT: File 0, [[@LINE+7]]:10 -> 
[[@LINE+7]]:12 = #0
+c([&]() {
+// CHECK:  File 0, [[@LINE-1]]:13 -> 
[[@LINE+5]]:6 = #0
+// CHECK-NEXT: File 0, [[@LINE+1]]:13 -> 
[[@LINE+1]]:19 = #0
+if (y == 0) // CHECK-NEXT: Branch,File 0, [[@LINE]]:13 -> 
[[@LINE]]:19 = #1, (#0 - #1)
+return 1;   // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:20 -> 
[[@LINE]]:13 = #1
+return 2;   // CHECK-NEXT: File 0, [[@LINE-1]]:13 -> 
[[@LINE-1]]:21 = #1
+}()) {} // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:22 -> 
[[@LINE-1]]:9 = (#0 - #1)
+};  // CHECK-NEXT: File 0, [[@LINE-2]]:9 -> 
[[@LINE-2]]:17 = (#0 - #1)
+
+int main() {
+B b(1,2);
+return 0;
+}



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


[libunwind] [libunwind][AIX] Fix up TOC register if unw_getcontext is called from a different module (PR #66549)

2023-09-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind


Changes

`unw_getcontext` saves the caller's registers in the context. However, if the 
caller of `unw_getcontext` is in a different module, the glue code of 
`unw_getcontext` sets the TOC register (r2) with the new TOC base and saves the 
original TOC register value in the stack frame. This causes the incorrect TOC 
value is used when the caller steps up frames, which fails libunwind LIT test 
case `unw_resume.pass.cpp'. This PR fixes the problem by using the original TOC 
register value saved in the stack if the caller is in a different module and 
enables `unw_resume.pass.cpp' on AIX.
---
Full diff: https://github.com/llvm/llvm-project/pull/66549.diff


2 Files Affected:

- (modified) libunwind/src/UnwindRegistersSave.S (+27-2) 
- (modified) libunwind/test/unw_resume.pass.cpp (-3) 


``diff
diff --git a/libunwind/src/UnwindRegistersSave.S 
b/libunwind/src/UnwindRegistersSave.S
index 58ffd1b9e1fb35a..f47b38ff848f729 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -305,9 +305,22 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
   mflr  0
   std   0, PPC64_OFFS_SRR0(3) // store lr as ssr0
   PPC64_STR(1)
+  PPC64_STR(4)  // Save r4 first since it will be used for fixing r2.
+#if defined(_AIX)
+  // The TOC register (r2) was changed by the glue code if unw_getcontext
+  // is called from a different module. Save the original TOC register
+  // in the context if this is the case.
+  mflr  4
+  lwz   4, 0(4) // Get the first instruction at the return address.
+  lis   0, 0xe841   // Is it reloading the TOC register "ld 2,40(1)"?
+  ori   0, 0, 0x28
+  cmpw  0, 0, 4
+  bne   0, LnoR2Fix // No need to fix up r2 if it is not.
+  ld2, 40(1)// Use the saved TOC register in the stack.
+LnoR2Fix:
+#endif
   PPC64_STR(2)
   PPC64_STR(3)
-  PPC64_STR(4)
   PPC64_STR(5)
   PPC64_STR(6)
   PPC64_STR(7)
@@ -547,9 +560,21 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
   mflr0
   stw 0,   0(3) // store lr as ssr0
   stw 1,  12(3)
+  stw 4,  24(3) // Save r4 first since it will be used for fixing r2.
+#if defined(_AIX)
+  // The TOC register (r2) was changed by the glue code if unw_getcontext
+  // is called from a different module. Save the original TOC register
+  // in the context if this is the case.
+  mflr4
+  lwz 4,  0(4)  // Get the instruction at the return address.
+  xoris   4,  4, 0x8041 // Is it reloading the TOC register "lwz r2,20(r1)"?
+  cmplwi  4,  0x14
+  bne 0,  LnoR2Fix  // No need to fix up r2 if it is not.
+  lwz 2,  20(1) // Use the saved TOC register in the stack.
+LnoR2Fix:
+#endif
   stw 2,  16(3)
   stw 3,  20(3)
-  stw 4,  24(3)
   stw 5,  28(3)
   stw 6,  32(3)
   stw 7,  36(3)
diff --git a/libunwind/test/unw_resume.pass.cpp 
b/libunwind/test/unw_resume.pass.cpp
index 76273e4a8ef0a71..08e8d4edeaf2927 100644
--- a/libunwind/test/unw_resume.pass.cpp
+++ b/libunwind/test/unw_resume.pass.cpp
@@ -10,9 +10,6 @@
 // Ensure that unw_resume() resumes execution at the stack frame identified by
 // cursor.
 
-// TODO: Investigate this failure on AIX system.
-// XFAIL: target={{.*}}-aix{{.*}}
-
 // TODO: Figure out why this fails with Memory Sanitizer.
 // XFAIL: msan
 

``




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


[libunwind] [libunwind][AIX] Fix up TOC register if unw_getcontext is called from a different module (PR #66549)

2023-09-15 Thread via cfe-commits

https://github.com/xingxue-ibm created 
https://github.com/llvm/llvm-project/pull/66549

`unw_getcontext` saves the caller's registers in the context. However, if the 
caller of `unw_getcontext` is in a different module, the glue code of 
`unw_getcontext` sets the TOC register (r2) with the new TOC base and saves the 
original TOC register value in the stack frame. This causes the incorrect TOC 
value is used when the caller steps up frames, which fails libunwind LIT test 
case `unw_resume.pass.cpp'. This PR fixes the problem by using the original TOC 
register value saved in the stack if the caller is in a different module and 
enables `unw_resume.pass.cpp' on AIX.

>From d42f6f35b8a4f3750b151f29951b215889d2c3e4 Mon Sep 17 00:00:00 2001
From: Xing Xue 
Date: Fri, 15 Sep 2023 16:09:43 -0400
Subject: [PATCH] The TOC register (r2) was changed by the glue code if
 unw_getcontext is called from a different module. Fix it up by using the
 original TOC register saved in the stack frame.

---
 libunwind/src/UnwindRegistersSave.S | 29 +++--
 libunwind/test/unw_resume.pass.cpp  |  3 ---
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/libunwind/src/UnwindRegistersSave.S 
b/libunwind/src/UnwindRegistersSave.S
index 58ffd1b9e1fb35a..f47b38ff848f729 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -305,9 +305,22 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
   mflr  0
   std   0, PPC64_OFFS_SRR0(3) // store lr as ssr0
   PPC64_STR(1)
+  PPC64_STR(4)  // Save r4 first since it will be used for fixing r2.
+#if defined(_AIX)
+  // The TOC register (r2) was changed by the glue code if unw_getcontext
+  // is called from a different module. Save the original TOC register
+  // in the context if this is the case.
+  mflr  4
+  lwz   4, 0(4) // Get the first instruction at the return address.
+  lis   0, 0xe841   // Is it reloading the TOC register "ld 2,40(1)"?
+  ori   0, 0, 0x28
+  cmpw  0, 0, 4
+  bne   0, LnoR2Fix // No need to fix up r2 if it is not.
+  ld2, 40(1)// Use the saved TOC register in the stack.
+LnoR2Fix:
+#endif
   PPC64_STR(2)
   PPC64_STR(3)
-  PPC64_STR(4)
   PPC64_STR(5)
   PPC64_STR(6)
   PPC64_STR(7)
@@ -547,9 +560,21 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
   mflr0
   stw 0,   0(3) // store lr as ssr0
   stw 1,  12(3)
+  stw 4,  24(3) // Save r4 first since it will be used for fixing r2.
+#if defined(_AIX)
+  // The TOC register (r2) was changed by the glue code if unw_getcontext
+  // is called from a different module. Save the original TOC register
+  // in the context if this is the case.
+  mflr4
+  lwz 4,  0(4)  // Get the instruction at the return address.
+  xoris   4,  4, 0x8041 // Is it reloading the TOC register "lwz r2,20(r1)"?
+  cmplwi  4,  0x14
+  bne 0,  LnoR2Fix  // No need to fix up r2 if it is not.
+  lwz 2,  20(1) // Use the saved TOC register in the stack.
+LnoR2Fix:
+#endif
   stw 2,  16(3)
   stw 3,  20(3)
-  stw 4,  24(3)
   stw 5,  28(3)
   stw 6,  32(3)
   stw 7,  36(3)
diff --git a/libunwind/test/unw_resume.pass.cpp 
b/libunwind/test/unw_resume.pass.cpp
index 76273e4a8ef0a71..08e8d4edeaf2927 100644
--- a/libunwind/test/unw_resume.pass.cpp
+++ b/libunwind/test/unw_resume.pass.cpp
@@ -10,9 +10,6 @@
 // Ensure that unw_resume() resumes execution at the stack frame identified by
 // cursor.
 
-// TODO: Investigate this failure on AIX system.
-// XFAIL: target={{.*}}-aix{{.*}}
-
 // TODO: Figure out why this fails with Memory Sanitizer.
 // XFAIL: msan
 

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


[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Louis Dionne via cfe-commits


@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto&& __projected = std::invoke(__proj, __value);

ldionne wrote:

I don't see how it could dangle. Do you mean that it will dangle if 
`std::invoke(__proj, __value)` returns a temporary? Rvalue references extend 
the lifetime of temporaries so whatever this references will live until the end 
of the function.

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Louis Dionne via cfe-commits


@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto&& __projected = std::invoke(__proj, __value);

ldionne wrote:

I don't see how it could dangle. Do you mean that it will dangle if 
`std::invoke(__proj, __value)` returns a temporary? Rvalue references extend 
the lifetime of temporaries so whatever this references will live until the end 
of the function.

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


[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Louis Dionne via cfe-commits


@@ -108,7 +108,33 @@ constexpr bool test() {
 auto prvalue_proj = [](const CheckDoubleMove& x) -> CheckDoubleMove { 
return x; };
 assert(&std::ranges::clamp(val, low, high, moving_comp, prvalue_proj) == 
&val);
   }
+  { // Make sure we don't call the projection more than three times per 
[alg.clamp], see #64717
+int counter = 0;
+auto projection_function = [counter](const int value) -> int {
+  assert(counter++ != 3);

ldionne wrote:

I think you missed this comment!

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Louis Dionne via cfe-commits


@@ -108,7 +108,33 @@ constexpr bool test() {
 auto prvalue_proj = [](const CheckDoubleMove& x) -> CheckDoubleMove { 
return x; };
 assert(&std::ranges::clamp(val, low, high, moving_comp, prvalue_proj) == 
&val);
   }
+  { // Make sure we don't call the projection more than three times per 
[alg.clamp], see #64717
+int counter = 0;
+auto projection_function = [counter](const int value) -> int {
+  assert(counter++ != 3);

ldionne wrote:

I think you missed this comment!

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


[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread via cfe-commits

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread via cfe-commits

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


[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread via cfe-commits


@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto&& __projected = std::invoke(__proj, __value);

EricWF wrote:

This could dangle. 

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread via cfe-commits

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


[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread via cfe-commits

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


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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread via cfe-commits


@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto&& __projected = std::invoke(__proj, __value);

EricWF wrote:

This could dangle. 

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread via cfe-commits

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


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


[clang] Fix math-errno issue (PR #66381)

2023-09-15 Thread Joshua Cranmer via cfe-commits


@@ -2313,14 +2313,20 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
   FD->hasAttr() ? 0 : BuiltinID;
 
   bool ErrnoOverriden = false;
-  // True if math-errno is overriden via the
+  bool ErrnoOverrideValue = false;

jcranmer-intel wrote:

This might be easier to understand if you replaced these two variables with a 
single `std::optional ErrnoOverride`.

https://github.com/llvm/llvm-project/pull/66381
___
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-15 Thread Giulio Eulisse via cfe-commits


@@ -0,0 +1,133 @@
+//===- 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 
+#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.
+template  class PagedVector {
+  // 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 Lookup;
+  // 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 oder of
+  // the elements however depends on the order of access of the pages.
+  mutable std::vector Data;

ktf wrote:

At the moment the largest vector I found is 1.5M entries. Thinking about it, 
one could however in principle use this to allocate very sparsely placed pages 
(e.g. where the index is some 64bit spatial hash and elements tend to be 
clustered together). However, I do not have any (llvm) use case for that at the 
moment. I guess the real motivation was due to the fact I am not familiar with 
SmallVector and I preferred to keep it simple.

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-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

https://github.com/pandaninjas updated 
https://github.com/llvm/llvm-project/pull/66315

>From ead65bfcb70be46788bc9e88c891e7ae7f91b8d7 Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 17:38:17 -0700
Subject: [PATCH 01/13] [libc++] Prevent calling the projection more than three
 times

---
 libcxx/include/__algorithm/ranges_clamp.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 9613f7f37720a6c..ca46675eb4b3041 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto &projection = std::invoke(__proj, __value);
+if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), 
std::invoke(__proj, __value)))
+else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
   return __high;
 else
   return __value;

>From c18d60870ac342a95a5528396a8e0c7b91717cbb Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 18:56:44 -0700
Subject: [PATCH 02/13] [libc++] Run clang-format on file

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index ca46675eb4b3041..3469a6419b2270f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto &projection = std::invoke(__proj, __value);
+auto& projection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From b40e791f0e9fedbb19936851e1e71decf00331fa Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:20 -0700
Subject: [PATCH 03/13] [libcxx] CamelCase projection and make variable name
 more descriptive

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3469a6419b2270f..3adb5fa828e1ee5 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto& projection = std::invoke(__proj, __value);
+auto& ValueProjection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From a8907624defa4cc4f47520a2d93a8bd042816aa2 Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:47 -0700
Subject: [PATCH 04/13] [libcxx] properly change variable name

---
 libcxx/include/__algorithm/ranges_clamp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3adb5fa828e1ee5..3d7a224b3649a3f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -38,9 +38,9 @@ struct __fn {
  "Bad bounds passed to std::ranges::clamp");
 
 auto& ValueProjection = std::invoke(__proj, __value);
-if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
+if (std::invoke(__comp, ValueProjection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
+else if (std::invoke(__comp, std::invoke(__proj, __high), ValueProjection))
   return __high;
 else
   return __value;

>From 15d3b2b79fbd61f97b0312e0913cede36b5b202d Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Thu, 14 Sep 2023 10:37:34 -0700
Subject: [PATCH 05/13] Apply suggestions from code review

---
 libcxx/include/__algorithm/ranges_clamp.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3d7a224b3649a3f..

[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

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


[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

https://github.com/pandaninjas updated 
https://github.com/llvm/llvm-project/pull/66315

>From ead65bfcb70be46788bc9e88c891e7ae7f91b8d7 Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 17:38:17 -0700
Subject: [PATCH 01/13] [libc++] Prevent calling the projection more than three
 times

---
 libcxx/include/__algorithm/ranges_clamp.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 9613f7f37720a6c..ca46675eb4b3041 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,9 +37,10 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, 
__low)))
+auto &projection = std::invoke(__proj, __value);
+if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), 
std::invoke(__proj, __value)))
+else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
   return __high;
 else
   return __value;

>From c18d60870ac342a95a5528396a8e0c7b91717cbb Mon Sep 17 00:00:00 2001
From: PandaNinjas 
Date: Wed, 13 Sep 2023 18:56:44 -0700
Subject: [PATCH 02/13] [libc++] Run clang-format on file

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index ca46675eb4b3041..3469a6419b2270f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto &projection = std::invoke(__proj, __value);
+auto& projection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From b40e791f0e9fedbb19936851e1e71decf00331fa Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:20 -0700
Subject: [PATCH 03/13] [libcxx] CamelCase projection and make variable name
 more descriptive

---
 libcxx/include/__algorithm/ranges_clamp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3469a6419b2270f..3adb5fa828e1ee5 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -37,7 +37,7 @@ struct __fn {
 _LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, 
__high), std::invoke(__proj, __low))),
  "Bad bounds passed to std::ranges::clamp");
 
-auto& projection = std::invoke(__proj, __value);
+auto& ValueProjection = std::invoke(__proj, __value);
 if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
   return __low;
 else if (std::invoke(__comp, std::invoke(__proj, __high), projection))

>From a8907624defa4cc4f47520a2d93a8bd042816aa2 Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Wed, 13 Sep 2023 19:11:47 -0700
Subject: [PATCH 04/13] [libcxx] properly change variable name

---
 libcxx/include/__algorithm/ranges_clamp.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3adb5fa828e1ee5..3d7a224b3649a3f 100644
--- a/libcxx/include/__algorithm/ranges_clamp.h
+++ b/libcxx/include/__algorithm/ranges_clamp.h
@@ -38,9 +38,9 @@ struct __fn {
  "Bad bounds passed to std::ranges::clamp");
 
 auto& ValueProjection = std::invoke(__proj, __value);
-if (std::invoke(__comp, projection, std::invoke(__proj, __low)))
+if (std::invoke(__comp, ValueProjection, std::invoke(__proj, __low)))
   return __low;
-else if (std::invoke(__comp, std::invoke(__proj, __high), projection))
+else if (std::invoke(__comp, std::invoke(__proj, __high), ValueProjection))
   return __high;
 else
   return __value;

>From 15d3b2b79fbd61f97b0312e0913cede36b5b202d Mon Sep 17 00:00:00 2001
From: Jocelyn Castellano 
Date: Thu, 14 Sep 2023 10:37:34 -0700
Subject: [PATCH 05/13] Apply suggestions from code review

---
 libcxx/include/__algorithm/ranges_clamp.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__algorithm/ranges_clamp.h 
b/libcxx/include/__algorithm/ranges_clamp.h
index 3d7a224b3649a3f..

[clang-tools-extra] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

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


[clang] [libc++] Prevent calling the projection more than three times (PR #66315)

2023-09-15 Thread Jocelyn Castellano via cfe-commits

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


[clang] [clang][deps] Load module map file from PCM (PR #66389)

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


@@ -1307,6 +1307,9 @@ void ModuleMap::setInferredModuleAllowedBy(Module *M,
 
 std::error_code
 ModuleMap::canonicalizeModuleMapPath(SmallVectorImpl &Path) {
+  FileManager &FM = SourceMgr.getFileManager();
+  FM.makeAbsolutePath(Path);

benlangmuir wrote:

> This function (and therefore the scanner) used to return absolute paths even 
> before this patch because it always uses FileManager::getCanonicalName().

Heh, my bad. As the person who wrote that code I should've realized this was 
already absolute.

> Should we call FileManager::makeAbsolutePath() in 
> ModuleMap::canonicalizeModuleMapPath() or in FileManager::getCanonicalName()?

I think the correct behaviour would be that `FileManager::getCanonicalName` 
would use `FixupRelativePath` to apply `-working-directory`, but not use 
`makeAbsolutePath` since that would be inconsistent with how it handles paths 
in other APIs.  The VFS itself is responsible for resolving CWD in 
`getRealPath`.

That being said, if this causes other issues I'm fine with your current 
approach in the meantime.

> Is using ASTWriter::AddPath() with the real path problematic? It only 
> performs textual prefix match with a directory path that's not necessarily 
> the real path.

I don't know how we avoid that without the same issues that motivated 
canonicalizing in the first place. We don't want to be compiling separate 
modules for /a/Foo, /a/foo, /a/b/../foo, /symlink/foo, etc.

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


[clang] [clang][CodeGen] Use byval for SystemZ indirect arguments (PR #66404)

2023-09-15 Thread Ilya Leoshkevich via cfe-commits

iii-i wrote:

I don't quite get why can't we use byval here. How is this different from 
x86_64? Both s390x and x86_64 ABIs require passing large structs via a pointer, 
why can x86_64 implement this using byval in LLVM and s390x can't? I agree that 
currently s390x backend does not handle it properly and the current version of 
this PR is not suitable for inclusion, but what is the conceptual problem here?

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


  1   2   3   4   5   >