[clang] [clang-format] Fix a bug in RemoveParentheses: ReturnStatement (PR #67911)

2023-10-02 Thread Tobias Hieta via cfe-commits

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


[clang] 75441a6 - [clang-format] Fix a bug in RemoveParentheses: ReturnStatement (#67911)

2023-10-02 Thread via cfe-commits

Author: Owen Pan
Date: 2023-10-02T09:15:49+02:00
New Revision: 75441a684273268ce91036aa2c770e669d39f501

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

LOG: [clang-format] Fix a bug in RemoveParentheses: ReturnStatement (#67911)

Don't remove the outermost parentheses surrounding a return statement
expression when inside a function/lambda that has the decltype(auto)
return type.

Fixed #67892.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index bf38ed73c4a0b4e..dda5fd077e590e5 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -173,10 +173,12 @@ void UnwrappedLineParser::reset() {
   CommentsBeforeNextToken.clear();
   FormatTok = nullptr;
   MustBreakBeforeNextToken = false;
+  IsDecltypeAutoFunction = false;
   PreprocessorDirectives.clear();
   CurrentLines = &Lines;
   DeclarationScopeStack.clear();
   NestedTooDeep.clear();
+  NestedLambdas.clear();
   PPStack.clear();
   Line->FirstStartColumn = FirstStartColumn;
 
@@ -1766,6 +1768,17 @@ void UnwrappedLineParser::parseStructuralElement(
   if (parseStructLike())
 return;
   break;
+case tok::kw_decltype:
+  nextToken();
+  if (FormatTok->is(tok::l_paren)) {
+parseParens();
+assert(FormatTok->Previous);
+if (FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
+  tok::l_paren)) {
+  Line->SeenDecltypeAuto = true;
+}
+  }
+  break;
 case tok::period:
   nextToken();
   // In Java, classes have an implicit static member "class".
@@ -1827,6 +1840,7 @@ void UnwrappedLineParser::parseStructuralElement(
   if (InRequiresExpression)
 FormatTok->setFinalizedType(TT_BracedListLBrace);
   if (!tryToParsePropertyAccessor() && !tryToParseBracedList()) {
+IsDecltypeAutoFunction = Line->SeenDecltypeAuto;
 // A block outside of parentheses must be the last part of a
 // structural element.
 // FIXME: Figure out cases where this is not true, and add projections
@@ -1844,6 +1858,7 @@ void UnwrappedLineParser::parseStructuralElement(
 }
 FormatTok->setFinalizedType(TT_FunctionLBrace);
 parseBlock();
+IsDecltypeAutoFunction = false;
 addUnwrappedLine();
 return;
   }
@@ -2249,9 +2264,15 @@ bool UnwrappedLineParser::tryToParseLambda() {
   return true;
 }
   }
+
   FormatTok->setFinalizedType(TT_LambdaLBrace);
   LSquare.setFinalizedType(TT_LambdaLSquare);
+
+  NestedLambdas.push_back(Line->SeenDecltypeAuto);
   parseChildBlock();
+  assert(!NestedLambdas.empty());
+  NestedLambdas.pop_back();
+
   return true;
 }
 
@@ -2469,6 +2490,8 @@ bool UnwrappedLineParser::parseParens(TokenType 
AmpAmpTokenType) {
PrevPrev->endsSequence(tok::kw_constexpr, tok::kw_if;
 const bool ReturnParens =
 Style.RemoveParentheses == FormatStyle::RPS_ReturnStatement &&
+((NestedLambdas.empty() && !IsDecltypeAutoFunction) ||
+ (!NestedLambdas.empty() && !NestedLambdas.back())) &&
 Prev && Prev->isOneOf(tok::kw_return, tok::kw_co_return) && Next &&
 Next->is(tok::semi);
 if ((DoubleParens && !Blacklisted) || ReturnParens) {
@@ -4379,6 +4402,7 @@ void UnwrappedLineParser::addUnwrappedLine(LineLevel 
AdjustLevel) {
   Line->MatchingOpeningBlockLineIndex = UnwrappedLine::kInvalidIndex;
   Line->FirstStartColumn = 0;
   Line->IsContinuation = false;
+  Line->SeenDecltypeAuto = false;
 
   if (ClosesWhitesmithsBlock && AdjustLevel == LineLevel::Remove)
 --Line->Level;

diff  --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index 4138baaabe2693d..a4f150d19571266 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -61,6 +61,9 @@ struct UnwrappedLine {
 
   bool MustBeDeclaration = false;
 
+  /// Whether the parser has seen \c decltype(auto) in this line.
+  bool SeenDecltypeAuto = false;
+
   /// \c True if this line should be indented by ContinuationIndent in
   /// addition to the normal indention level.
   bool IsContinuation = false;
@@ -335,6 +338,14 @@ class UnwrappedLineParser {
   // statement contains more than some predefined number of nested statements).
   SmallVector NestedTooDeep;
 
+  // Keeps a stack of the states of nested lambdas (true if the return type of
+  // the lambda is `decltype(auto)`).
+  SmallVector NestedLambdas;
+
+  // Whether the parser is parsin

[clang] [clang-format] Fix a bug in RemoveParentheses: ReturnStatement (PR #67911)

2023-10-02 Thread Tobias Hieta via cfe-commits

tru wrote:

oh sorry for merging this @owenca - it was tagged for the 17.x release and I 
thought it was a PR towards the backport branch so ti wasn't my intention to 
merge it into main for you. 

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


[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-10-02 Thread via cfe-commits

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

LGTM from the libc++ side of things.

https://github.com/llvm/llvm-project/pull/65246
___
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 RemoveParentheses: ReturnStatement (PR #67911)

2023-10-02 Thread Owen Pan via cfe-commits

owenca wrote:

@tru np! That was my intention anyways.

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


[clang] c83d64f - [clang-format] Fix a bug in mis-annotating arrows (#67780)

2023-10-02 Thread via cfe-commits

Author: Owen Pan
Date: 2023-10-02T00:38:26-07:00
New Revision: c83d64f17a6e38f39fde611f06479e6f2a62b70f

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

LOG: [clang-format] Fix a bug in mis-annotating arrows (#67780)

Fixed #66923.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index ae2cbbdce934618..3ea65707da90369 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2016,8 +2016,7 @@ class AnnotatingParser {
Style.Language == FormatStyle::LK_Java) {
   Current.setType(TT_LambdaArrow);
 } else if (Current.is(tok::arrow) && AutoFound &&
-   (Line.MightBeFunctionDecl || Line.InPPDirective) &&
-   Current.NestingLevel == 0 &&
+   Line.MightBeFunctionDecl && Current.NestingLevel == 0 &&
!Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) {
   // not auto operator->() -> xxx;
   Current.setType(TT_TrailingReturnArrow);
@@ -3252,7 +3251,8 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
 // This function heuristically determines whether 'Current' starts the name of 
a
 // function declaration.
 static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
-  const AnnotatedLine &Line) {
+  const AnnotatedLine &Line,
+  FormatToken *&ClosingParen) {
   assert(Current.Previous);
 
   if (Current.is(TT_FunctionDeclarationName))
@@ -3344,16 +3344,16 @@ static bool isFunctionDeclarationName(bool IsCpp, const 
FormatToken &Current,
   // Check whether parameter list can belong to a function declaration.
   if (!Next || Next->isNot(tok::l_paren) || !Next->MatchingParen)
 return false;
+  ClosingParen = Next->MatchingParen;
+  assert(ClosingParen->is(tok::r_paren));
   // If the lines ends with "{", this is likely a function definition.
   if (Line.Last->is(tok::l_brace))
 return true;
-  if (Next->Next == Next->MatchingParen)
+  if (Next->Next == ClosingParen)
 return true; // Empty parentheses.
   // If there is an &/&& after the r_paren, this is likely a function.
-  if (Next->MatchingParen->Next &&
-  Next->MatchingParen->Next->is(TT_PointerOrReference)) {
+  if (ClosingParen->Next && ClosingParen->Next->is(TT_PointerOrReference))
 return true;
-  }
 
   // Check for K&R C function definitions (and C++ function definitions with
   // unnamed parameters), e.g.:
@@ -3370,7 +3370,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const 
FormatToken &Current,
 return true;
   }
 
-  for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
+  for (const FormatToken *Tok = Next->Next; Tok && Tok != ClosingParen;
Tok = Tok->Next) {
 if (Tok->is(TT_TypeDeclarationParen))
   return true;
@@ -3442,11 +3442,12 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
 calculateArrayInitializerColumnList(Line);
 
   bool LineIsFunctionDeclaration = false;
+  FormatToken *ClosingParen = nullptr;
   for (FormatToken *Tok = Current, *AfterLastAttribute = nullptr; Tok;
Tok = Tok->Next) {
 if (Tok->Previous->EndsCppAttributeGroup)
   AfterLastAttribute = Tok;
-if (isFunctionDeclarationName(Style.isCpp(), *Tok, Line)) {
+if (isFunctionDeclarationName(Style.isCpp(), *Tok, Line, ClosingParen)) {
   LineIsFunctionDeclaration = true;
   Tok->setFinalizedType(TT_FunctionDeclarationName);
   if (AfterLastAttribute &&
@@ -3458,29 +3459,38 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
 }
   }
 
-  if (Style.isCpp() && !LineIsFunctionDeclaration) {
-// Annotate */&/&& in `operator` function calls as binary operators.
-for (const auto *Tok = Line.First; Tok; Tok = Tok->Next) {
-  if (Tok->isNot(tok::kw_operator))
-continue;
-  do {
-Tok = Tok->Next;
-  } while (Tok && Tok->isNot(TT_OverloadedOperatorLParen));
-  if (!Tok)
-break;
-  const auto *LeftParen = Tok;
-  for (Tok = Tok->Next; Tok && Tok != LeftParen->MatchingParen;
-   Tok = Tok->Next) {
-if (Tok->isNot(tok::identifier))
-  continue;
-auto *Next = Tok->Next;
-const bool NextIsBinaryOperator =
-Next && Next->isOneOf(tok::star, tok::amp, tok::ampamp) &&
-Next->Next && Next->Next->is(tok::identifier);
-if (!NextIsBinaryOperator)
+  if (Style.isCpp()) {
+if (!LineIsFunctionDeclaration) {
+  // Annotate */&/&& in `operator` funct

[clang] [clang-format] Fix a bug in mis-annotating arrows (PR #67780)

2023-10-02 Thread Owen Pan via cfe-commits

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


[clang] 8245ca9 - [clang][Interp] Don't disable int128 tests everywhere.

2023-10-02 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-02T09:55:35+02:00
New Revision: 8245ca994bc524ef7a047526c128dbe0cb14d104

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

LOG: [clang][Interp] Don't disable int128 tests everywhere.

Added: 


Modified: 
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index b57a0e64c5fac32..eca0e4c2cbd26f1 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -27,7 +27,7 @@ static_assert(number != 10, ""); // expected-error{{failed}} \
  // ref-note{{evaluates to}}
 
 
-#ifdef __SIZEOF__INT128__
+#ifdef __SIZEOF_INT128__
 namespace i128 {
   typedef __int128 int128_t;
   typedef unsigned __int128 uint128_t;



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


[clang-tools-extra] [Clang] Fix crash when ill-formed code is treated as a deduction guide (PR #67373)

2023-10-02 Thread Mariya Podchishchaeva via cfe-commits

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


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


[clang] [Clang] Fix crash when ill-formed code is treated as a deduction guide (PR #67373)

2023-10-02 Thread Mariya Podchishchaeva via cfe-commits

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


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


[clang] 5317912 - [clang] Add missing canonicalization in int literal profile (#67822)

2023-10-02 Thread via cfe-commits

Author: Henrik G. Olsson
Date: 2023-10-02T10:03:32+02:00
New Revision: 53179129edbff13644b7c46336773fb8740899c9

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

LOG: [clang] Add missing canonicalization in int literal profile (#67822)

The addition of the type kind to the profile ID of IntegerLiterals
results in e.g. size_t and unsigned long literals mismatch even on
platforms where they are canonically the same type. This patch checks
the Canonical field to determine whether to canonicalize the type first.

rdar://116063468

Added: 


Modified: 
clang/lib/AST/StmtProfile.cpp

Removed: 




diff  --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 2e4f15f83ac26ef..763d3d612698095 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -1335,6 +1335,8 @@ void StmtProfiler::VisitIntegerLiteral(const 
IntegerLiteral *S) {
   S->getValue().Profile(ID);
 
   QualType T = S->getType();
+  if (Canonical)
+T = T.getCanonicalType();
   ID.AddInteger(T->getTypeClass());
   if (auto BitIntT = T->getAs())
 BitIntT->Profile(ID);



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


[clang] [clang] Add missing canonicalization in int literal profile (PR #67822)

2023-10-02 Thread Henrik G. Olsson via cfe-commits

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


[PATCH] D93829: [clangd] Support outgoing calls in call hierarchy

2023-10-02 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 557525.
nridge added a comment.

Rebased to apply to recent trunk


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93829

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/index/Index.cpp
  clang-tools-extra/clangd/index/Index.h
  clang-tools-extra/clangd/index/MemIndex.cpp
  clang-tools-extra/clangd/index/MemIndex.h
  clang-tools-extra/clangd/index/Merge.cpp
  clang-tools-extra/clangd/index/Merge.h
  clang-tools-extra/clangd/index/ProjectAware.cpp
  clang-tools-extra/clangd/index/dex/Dex.cpp
  clang-tools-extra/clangd/index/dex/Dex.h
  clang-tools-extra/clangd/test/type-hierarchy-ext.test
  clang-tools-extra/clangd/test/type-hierarchy.test
  clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1417,6 +1417,12 @@
   return true; // has more references
 }
 
+bool refersTo(const RefsRequest &Req,
+  llvm::function_ref Callback)
+const override {
+  return false;
+}
+
 bool fuzzyFind(
 const FuzzyFindRequest &Req,
 llvm::function_ref Callback) const override {
@@ -1468,6 +1474,12 @@
   return false;
 }
 
+bool refersTo(const RefsRequest &Req,
+  llvm::function_ref Callback)
+const override {
+  return false;
+}
+
 bool fuzzyFind(const FuzzyFindRequest &,
llvm::function_ref) const override {
   return false;
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1644,6 +1644,12 @@
 return false;
   }
 
+  bool
+  refersTo(const RefsRequest &,
+   llvm::function_ref) const override {
+return false;
+  }
+
   void relations(const RelationsRequest &,
  llvm::function_ref)
   const override {}
Index: clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
===
--- clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
+++ clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
@@ -44,17 +44,27 @@
 
 // Helpers for matching call hierarchy data structures.
 MATCHER_P(withName, N, "") { return arg.name == N; }
+MATCHER_P(withDetail, N, "") { return arg.detail == N; }
 MATCHER_P(withSelectionRange, R, "") { return arg.selectionRange == R; }
 
 template 
 ::testing::Matcher from(ItemMatcher M) {
   return Field(&CallHierarchyIncomingCall::from, M);
 }
+template 
+::testing::Matcher to(ItemMatcher M) {
+  return Field(&CallHierarchyOutgoingCall::to, M);
+}
 template 
-::testing::Matcher fromRanges(RangeMatchers... M) {
+::testing::Matcher iFromRanges(RangeMatchers... M) {
   return Field(&CallHierarchyIncomingCall::fromRanges,
UnorderedElementsAre(M...));
 }
+template 
+::testing::Matcher oFromRanges(RangeMatchers... M) {
+  return Field(&CallHierarchyOutgoingCall::fromRanges,
+   UnorderedElementsAre(M...));
+}
 
 TEST(CallHierarchy, IncomingOneFileCpp) {
   Annotations Source(R"cpp(
@@ -79,21 +89,24 @@
   prepareCallHierarchy(AST, Source.point(), testPath(TU.Filename));
   ASSERT_THAT(Items, ElementsAre(withName("callee")));
   auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
-  ASSERT_THAT(IncomingLevel1,
-  ElementsAre(AllOf(from(withName("caller1")),
-fromRanges(Source.range("Callee");
+  ASSERT_THAT(
+  IncomingLevel1,
+  ElementsAre(AllOf(from(AllOf(withName("caller1"), withDetail("caller1"))),
+iFromRanges(Source.range("Callee");
   auto IncomingLevel2 = incomingCalls(IncomingLevel1[0].from, Index.get());
-  ASSERT_THAT(IncomingLevel2,
-  ElementsAre(AllOf(from(withName("caller2")),
-fromRanges(Source.range("Caller1A"),
-   Source.range("Caller1B"))),
-  AllOf(from(withName("caller3")),
-fromRanges(Source.range("Caller1C");
+  ASSERT_THAT(
+  IncomingLevel2,
+  ElementsAre(AllOf(from(AllOf(withName("caller2"), withDetail("caller2"))),
+iFromRanges(Source.range("Caller1A"),
+ 

[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-10-02 Thread via cfe-commits

kasuga-fj wrote:

Thanks! (The upstream build process seems to be broken now, so I'll wait until 
it's fixed)

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


[clang] [clang] [MinGW] Tolerate mingw specific linker options during compilation (PR #67891)

2023-10-02 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> Did you plan to backport this as well @mstorsjo ?

Yes, I did - in #64464, with 
https://github.com/llvm/llvm-project-release-prs/pull/716 (where tests failed 
after cherrypicking; looking into that test issue right now).

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


[clang] [clang][Interp] Implement IntegralAP::comp (PR #67954)

2023-10-02 Thread Timm Baeder via cfe-commits

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

>From 80bd890c332654458014c4acc20709b9cbb6eb90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 1 Oct 2023 19:57:03 +0200
Subject: [PATCH] [clang][Interp] Implement IntegralAP::comp

---
 clang/lib/AST/Interp/IntegralAP.h  | 1 -
 clang/test/AST/Interp/literals.cpp | 3 +++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index b2b367f30c238fe..b29aac2a73e3243 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -210,7 +210,6 @@ template  class IntegralAP final {
   }
 
   static bool comp(IntegralAP A, IntegralAP *R) {
-assert(false);
 *R = IntegralAP(~A.V);
 return false;
   }
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index eca0e4c2cbd26f1..00182ba4ab1d918 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -52,6 +52,9 @@ namespace i128 {
   constexpr int128_t Two = (int128_t)1 << 1ul;
   static_assert(Two == 2, "");
 
+  constexpr uint128_t AllOnes = ~static_cast(0);
+  static_assert(AllOnes == static_cast(-1), "");
+
 #if __cplusplus >= 201402L
   template 
   constexpr T CastFrom(__int128_t A) {

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


[clang] [clang] [MinGW] Tolerate mingw specific linker options during compilation (PR #67891)

2023-10-02 Thread Tobias Hieta via cfe-commits

tru wrote:

Yeah i noticed when I got further down in my notification stack :)

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


[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-02 Thread Endre Fülöp via cfe-commits

https://github.com/gamesh411 updated 
https://github.com/llvm/llvm-project/pull/67663

From 9f7f577c95d7e9fb7e2f929215ff217ca2d7ed53 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= 
Date: Fri, 8 Sep 2023 14:20:00 +0200
Subject: [PATCH 1/8] [analyzer][clangsa] Add new option to
 alpha.security.cert.InvalidPtrChecker

The invalidation of pointer pointers returned by subsequent calls to genenv is
suggested by the POSIX standard, but is too strict from a practical point of
view. A new checker option 'InvalidatingGetEnv' is introduced, and is set to a
more lax default value, which does not consider consecutive getenv calls
invalidating.
The handling of the main function's possible specification where an environment
pointer is also pecified as a third parameter is also considered now.

Differential Revision: https://reviews.llvm.org/D154603
---
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  9 ++
 .../Checkers/cert/InvalidPtrChecker.cpp   | 86 ++-
 clang/test/Analysis/analyzer-config.c |  1 +
 .../Analysis/cert/env34-c-cert-examples.c | 40 -
 clang/test/Analysis/cert/env34-c.c|  1 +
 clang/test/Analysis/invalid-ptr-checker.c | 50 +++
 6 files changed, 163 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/Analysis/invalid-ptr-checker.c

diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 65c1595eb6245dd..b4f65c934bf483b 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -997,6 +997,15 @@ let ParentPackage = ENV in {
 
   def InvalidPtrChecker : Checker<"InvalidPtr">,
   HelpText<"Finds usages of possibly invalidated pointers">,
+  CheckerOptions<[
+CmdLineOption,
+  ]>,
   Documentation;
 
 } // end "alpha.cert.env"
diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index aae1a17bc0ae53e..8849eb1148564b7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -38,6 +38,15 @@ class InvalidPtrChecker
 CheckerContext &C) const;
 
   // SEI CERT ENV31-C
+
+  // If set to true, consider getenv calls as invalidating operations on the
+  // environment variable buffer. This is implied in the standard, but in
+  // practice does not cause problems (in the commonly used environments).
+  bool InvalidatingGetEnv = false;
+
+  // GetEnv can be treated invalidating and non-invalidating as well.
+  const CallDescription GetEnvCall{{"getenv"}, 1};
+
   const CallDescriptionMap EnvpInvalidatingFunctions = {
   {{{"setenv"}, 3}, &InvalidPtrChecker::EnvpInvalidatingCall},
   {{{"unsetenv"}, 1}, &InvalidPtrChecker::EnvpInvalidatingCall},
@@ -51,7 +60,6 @@ class InvalidPtrChecker
 
   // SEI CERT ENV34-C
   const CallDescriptionMap PreviousCallInvalidatingFunctions = {
-  {{{"getenv"}, 1}, 
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{{"setlocale"}, 2},
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{{"strerror"}, 1},
@@ -62,6 +70,10 @@ class InvalidPtrChecker
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   };
 
+  // The private members of this checker corresponding to commandline options
+  // are set in this function.
+  friend void ento::registerInvalidPtrChecker(CheckerManager &);
+
 public:
   // Obtain the environment pointer from 'main()' (if present).
   void checkBeginFunction(CheckerContext &C) const;
@@ -84,7 +96,10 @@ class InvalidPtrChecker
 REGISTER_SET_WITH_PROGRAMSTATE(InvalidMemoryRegions, const MemRegion *)
 
 // Stores the region of the environment pointer of 'main' (if present).
-REGISTER_TRAIT_WITH_PROGRAMSTATE(EnvPtrRegion, const MemRegion *)
+REGISTER_TRAIT_WITH_PROGRAMSTATE(MainEnvPtrRegion, const MemRegion *)
+
+// Stores the regions of environments returned by getenv calls.
+REGISTER_SET_WITH_PROGRAMSTATE(GetenvEnvPtrRegions, const MemRegion *)
 
 // Stores key-value pairs, where key is function declaration and value is
 // pointer to memory region returned by previous call of this function
@@ -95,22 +110,35 @@ void InvalidPtrChecker::EnvpInvalidatingCall(const 
CallEvent &Call,
  CheckerContext &C) const {
   StringRef FunctionName = Call.getCalleeIdentifier()->getName();
   ProgramStateRef State = C.getState();
-  const MemRegion *SymbolicEnvPtrRegion = State->get();
-  if (!SymbolicEnvPtrRegion)
-return;
 
-  State = State->add(SymbolicEnvPtrRegion);
+  auto PlaceInvalidationNote = [&C, FunctionName,
+&State](const MemRegion *Region,
+StringRef Message, ExplodedNode *Pred) 
{
+State = State->add(Region);
+
+// Make cop

[clang] Avoid need for SLocEntryLoaded BitVector (PR #67960)

2023-10-02 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf created https://github.com/llvm/llvm-project/pull/67960

The BitVector is currently used to keep track of which entries of 
LoadedSLocEntryTable have been loaded. Such information can be stored in the 
SLocEntry itself. Moreover, thanks to the fact that LoadedSLocEntryTable is now 
a PagedVector, we can simply consider elements of unmaterialised pages as not 
loaded.

This trades reducing the number of OffsetBits by one for reducing memory usage 
of the SourceManager by LoadedSLocEntryTable.size()/8 bytes.

>From 9fde224de6baa5b1fb3713d810ce835d4456b457 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Fri, 29 Sep 2023 08:37:57 +0200
Subject: [PATCH] Avoid need for SLocEntryLoaded BitVector

The BitVector is currently used to keep track of which entries of
LoadedSLocEntryTable have been loaded. Such information can be stored in
the SLocEntry itself. Moreover, thanks to the fact that
LoadedSLocEntryTable is now a PagedVector, we can simply consider
elements of unmaterialised pages as not loaded.

This trades reducing the number of OffsetBits by one for reducing memory
usage of the SourceManager by LoadedSLocEntryTable.size()/8 bytes.
---
 clang/include/clang/Basic/SourceManager.h | 16 ++
 clang/lib/Basic/SourceManager.cpp | 27 ++-
 llvm/include/llvm/ADT/PagedVector.h   |  6 +
 3 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index c1b24eec2759c71..d450280303d6785 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -474,9 +474,10 @@ static_assert(sizeof(FileInfo) <= sizeof(ExpansionInfo),
 /// SourceManager keeps an array of these objects, and they are uniquely
 /// identified by the FileID datatype.
 class SLocEntry {
-  static constexpr int OffsetBits = 8 * sizeof(SourceLocation::UIntTy) - 1;
+  static constexpr int OffsetBits = 8 * sizeof(SourceLocation::UIntTy) - 2;
   SourceLocation::UIntTy Offset : OffsetBits;
   SourceLocation::UIntTy IsExpansion : 1;
+  SourceLocation::UIntTy Loaded : 1;
   union {
 FileInfo File;
 ExpansionInfo Expansion;
@@ -489,6 +490,8 @@ class SLocEntry {
 
   bool isExpansion() const { return IsExpansion; }
   bool isFile() const { return !isExpansion(); }
+  [[nodiscard]] bool isLoaded() const { return Loaded; }
+  void setLoaded(bool Value) { Loaded = Value; }
 
   const FileInfo &getFile() const {
 assert(isFile() && "Not a file SLocEntry!");
@@ -716,13 +719,7 @@ class SourceManager : public RefCountedBase 
{
   /// The highest possible offset is 2^31-1 (2^63-1 for 64-bit source
   /// locations), so CurrentLoadedOffset starts at 2^31 (2^63 resp.).
   static const SourceLocation::UIntTy MaxLoadedOffset =
-  1ULL << (8 * sizeof(SourceLocation::UIntTy) - 1);
-
-  /// A bitmap that indicates whether the entries of LoadedSLocEntryTable
-  /// have already been loaded from the external source.
-  ///
-  /// Same indexing as LoadedSLocEntryTable.
-  llvm::BitVector SLocEntryLoaded;
+  1ULL << (8 * sizeof(SourceLocation::UIntTy) - 2);
 
   /// An external source for source location entries.
   ExternalSLocEntrySource *ExternalSLocEntries = nullptr;
@@ -1710,7 +1707,8 @@ class SourceManager : public 
RefCountedBase {
   const SrcMgr::SLocEntry &getLoadedSLocEntry(unsigned Index,
   bool *Invalid = nullptr) const {
 assert(Index < LoadedSLocEntryTable.size() && "Invalid index");
-if (SLocEntryLoaded[Index])
+if (LoadedSLocEntryTable.isMaterialized(Index) &&
+LoadedSLocEntryTable[Index].isLoaded())
   return LoadedSLocEntryTable[Index];
 return loadSLocEntry(Index, Invalid);
   }
diff --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 3066cc53dbfd878..20e3f1252ddf077 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -336,7 +336,6 @@ void SourceManager::clearIDTables() {
   MainFileID = FileID();
   LocalSLocEntryTable.clear();
   LoadedSLocEntryTable.clear();
-  SLocEntryLoaded.clear();
   LastLineNoFileIDQuery = FileID();
   LastLineNoContentCache = nullptr;
   LastFileIDLookup = FileID();
@@ -373,7 +372,8 @@ void SourceManager::initializeForReplay(const SourceManager 
&Old) {
 
   // Ensure all SLocEntries are loaded from the external source.
   for (unsigned I = 0, N = Old.LoadedSLocEntryTable.size(); I != N; ++I)
-if (!Old.SLocEntryLoaded[I])
+if (!Old.LoadedSLocEntryTable.isMaterialized(I) ||
+!Old.LoadedSLocEntryTable[I].isLoaded())
   Old.loadSLocEntry(I, nullptr);
 
   // Inherit any content cache data from the old source manager.
@@ -430,12 +430,14 @@ ContentCache &SourceManager::createMemBufferContentCache(
 
 const SrcMgr::SLocEntry &SourceManager::loadSLocEntry(unsigned Index,
   

[clang] Avoid need for SLocEntryLoaded BitVector (PR #67960)

2023-10-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

The BitVector is currently used to keep track of which entries of 
LoadedSLocEntryTable have been loaded. Such information can be stored in the 
SLocEntry itself. Moreover, thanks to the fact that LoadedSLocEntryTable is now 
a PagedVector, we can simply consider elements of unmaterialised pages as not 
loaded.

This trades reducing the number of OffsetBits by one for reducing memory usage 
of the SourceManager by LoadedSLocEntryTable.size()/8 bytes.

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


3 Files Affected:

- (modified) clang/include/clang/Basic/SourceManager.h (+7-9) 
- (modified) clang/lib/Basic/SourceManager.cpp (+16-11) 
- (modified) llvm/include/llvm/ADT/PagedVector.h (+6) 


``diff
diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index c1b24eec2759c71..d450280303d6785 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -474,9 +474,10 @@ static_assert(sizeof(FileInfo) <= sizeof(ExpansionInfo),
 /// SourceManager keeps an array of these objects, and they are uniquely
 /// identified by the FileID datatype.
 class SLocEntry {
-  static constexpr int OffsetBits = 8 * sizeof(SourceLocation::UIntTy) - 1;
+  static constexpr int OffsetBits = 8 * sizeof(SourceLocation::UIntTy) - 2;
   SourceLocation::UIntTy Offset : OffsetBits;
   SourceLocation::UIntTy IsExpansion : 1;
+  SourceLocation::UIntTy Loaded : 1;
   union {
 FileInfo File;
 ExpansionInfo Expansion;
@@ -489,6 +490,8 @@ class SLocEntry {
 
   bool isExpansion() const { return IsExpansion; }
   bool isFile() const { return !isExpansion(); }
+  [[nodiscard]] bool isLoaded() const { return Loaded; }
+  void setLoaded(bool Value) { Loaded = Value; }
 
   const FileInfo &getFile() const {
 assert(isFile() && "Not a file SLocEntry!");
@@ -716,13 +719,7 @@ class SourceManager : public RefCountedBase 
{
   /// The highest possible offset is 2^31-1 (2^63-1 for 64-bit source
   /// locations), so CurrentLoadedOffset starts at 2^31 (2^63 resp.).
   static const SourceLocation::UIntTy MaxLoadedOffset =
-  1ULL << (8 * sizeof(SourceLocation::UIntTy) - 1);
-
-  /// A bitmap that indicates whether the entries of LoadedSLocEntryTable
-  /// have already been loaded from the external source.
-  ///
-  /// Same indexing as LoadedSLocEntryTable.
-  llvm::BitVector SLocEntryLoaded;
+  1ULL << (8 * sizeof(SourceLocation::UIntTy) - 2);
 
   /// An external source for source location entries.
   ExternalSLocEntrySource *ExternalSLocEntries = nullptr;
@@ -1710,7 +1707,8 @@ class SourceManager : public 
RefCountedBase {
   const SrcMgr::SLocEntry &getLoadedSLocEntry(unsigned Index,
   bool *Invalid = nullptr) const {
 assert(Index < LoadedSLocEntryTable.size() && "Invalid index");
-if (SLocEntryLoaded[Index])
+if (LoadedSLocEntryTable.isMaterialized(Index) &&
+LoadedSLocEntryTable[Index].isLoaded())
   return LoadedSLocEntryTable[Index];
 return loadSLocEntry(Index, Invalid);
   }
diff --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 3066cc53dbfd878..20e3f1252ddf077 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -336,7 +336,6 @@ void SourceManager::clearIDTables() {
   MainFileID = FileID();
   LocalSLocEntryTable.clear();
   LoadedSLocEntryTable.clear();
-  SLocEntryLoaded.clear();
   LastLineNoFileIDQuery = FileID();
   LastLineNoContentCache = nullptr;
   LastFileIDLookup = FileID();
@@ -373,7 +372,8 @@ void SourceManager::initializeForReplay(const SourceManager 
&Old) {
 
   // Ensure all SLocEntries are loaded from the external source.
   for (unsigned I = 0, N = Old.LoadedSLocEntryTable.size(); I != N; ++I)
-if (!Old.SLocEntryLoaded[I])
+if (!Old.LoadedSLocEntryTable.isMaterialized(I) ||
+!Old.LoadedSLocEntryTable[I].isLoaded())
   Old.loadSLocEntry(I, nullptr);
 
   // Inherit any content cache data from the old source manager.
@@ -430,12 +430,14 @@ ContentCache &SourceManager::createMemBufferContentCache(
 
 const SrcMgr::SLocEntry &SourceManager::loadSLocEntry(unsigned Index,
   bool *Invalid) const {
-  assert(!SLocEntryLoaded[Index]);
+  assert(!LoadedSLocEntryTable.isMaterialized(Index) ||
+ !LoadedSLocEntryTable[Index].isLoaded());
   if (ExternalSLocEntries->ReadSLocEntry(-(static_cast(Index) + 2))) {
 if (Invalid)
   *Invalid = true;
 // If the file of the SLocEntry changed we could still have loaded it.
-if (!SLocEntryLoaded[Index]) {
+if (!LoadedSLocEntryTable.isMaterialized(Index) ||
+!LoadedSLocEntryTable[Index].isLoaded()) {
   // Try to recover; create a SLocEntry so the rest of clang can handle it.
   if (!FakeSLocEntryForRecovery)
 FakeSLocEntryForRecovery = std:

[clang] Avoid need for SLocEntryLoaded BitVector (PR #67960)

2023-10-02 Thread Giulio Eulisse via cfe-commits

ktf wrote:

@vgvassilev IIUC, this is what you were proposing in some comment in 
https://github.com/llvm/llvm-project/pull/66430.

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


[clang] [clang][Interp] Fix value truncation when casting int128 to smaller size (PR #67961)

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


https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/67961

Before this patch, we would run into an assertion in 
`APInt::get{S,Z}ExtValue()` because the `AllOnes` value had more than 64 active 
bits.

>From 80bd890c332654458014c4acc20709b9cbb6eb90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 1 Oct 2023 19:57:03 +0200
Subject: [PATCH 1/2] [clang][Interp] Implement IntegralAP::comp

---
 clang/lib/AST/Interp/IntegralAP.h  | 1 -
 clang/test/AST/Interp/literals.cpp | 3 +++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index b2b367f30c238fe..b29aac2a73e3243 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -210,7 +210,6 @@ template  class IntegralAP final {
   }
 
   static bool comp(IntegralAP A, IntegralAP *R) {
-assert(false);
 *R = IntegralAP(~A.V);
 return false;
   }
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index eca0e4c2cbd26f1..00182ba4ab1d918 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -52,6 +52,9 @@ namespace i128 {
   constexpr int128_t Two = (int128_t)1 << 1ul;
   static_assert(Two == 2, "");
 
+  constexpr uint128_t AllOnes = ~static_cast(0);
+  static_assert(AllOnes == static_cast(-1), "");
+
 #if __cplusplus >= 201402L
   template 
   constexpr T CastFrom(__int128_t A) {

>From 31ed85d44562ed1e5fe4714a5b659e5da8720f02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 2 Oct 2023 10:46:22 +0200
Subject: [PATCH 2/2] [clang][Interp] Fix value truncation when casting int128
 to smaller size

---
 clang/lib/AST/Interp/IntegralAP.h  | 21 +
 clang/test/AST/Interp/literals.cpp |  8 +++-
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index b29aac2a73e3243..f67b15dbc9b31ac 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -55,14 +55,14 @@ template  class IntegralAP final {
   bool operator<=(IntegralAP RHS) const { return V <= RHS.V; }
 
   explicit operator bool() const { return !V.isZero(); }
-  explicit operator int8_t() const { return V.getSExtValue(); }
-  explicit operator uint8_t() const { return V.getZExtValue(); }
-  explicit operator int16_t() const { return V.getSExtValue(); }
-  explicit operator uint16_t() const { return V.getZExtValue(); }
-  explicit operator int32_t() const { return V.getSExtValue(); }
-  explicit operator uint32_t() const { return V.getZExtValue(); }
-  explicit operator int64_t() const { return V.getSExtValue(); }
-  explicit operator uint64_t() const { return V.getZExtValue(); }
+  explicit operator int8_t() const { return truncateCast(V); }
+  explicit operator uint8_t() const { return truncateCast(V); }
+  explicit operator int16_t() const { return truncateCast(V); }
+  explicit operator uint16_t() const { return truncateCast(V); }
+  explicit operator int32_t() const { return truncateCast(V); }
+  explicit operator uint32_t() const { return truncateCast(V); }
+  explicit operator int64_t() const { return truncateCast(V); }
+  explicit operator uint64_t() const { return truncateCast(V); }
 
   template  static IntegralAP from(T Value, unsigned NumBits = 0) {
 assert(NumBits > 0);
@@ -248,6 +248,11 @@ template  class IntegralAP final {
 R->V = A.V - B.V;
 return false; // Success!
   }
+
+  template  static T truncateCast(const APSInt &V) {
+return std::is_signed_v ? V.trunc(sizeof(T) * 8).getSExtValue()
+   : V.trunc(sizeof(T) * 8).getZExtValue();
+  }
 };
 
 template 
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 00182ba4ab1d918..65d211422ddac92 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -53,7 +53,7 @@ namespace i128 {
   static_assert(Two == 2, "");
 
   constexpr uint128_t AllOnes = ~static_cast(0);
-  static_assert(AllOnes == static_cast(-1), "");
+  static_assert(AllOnes == UINT128_MAX, "");
 
 #if __cplusplus >= 201402L
   template 
@@ -70,6 +70,12 @@ namespace i128 {
   static_assert(CastFrom(12) == 12, "");
   static_assert(CastFrom(12) == 12, "");
 
+  static_assert(CastFrom(AllOnes) == -1, "");
+  static_assert(CastFrom(AllOnes) == 0xFF, "");
+  static_assert(CastFrom(AllOnes) == -1, "");
+  static_assert(CastFrom(AllOnes) == 0x, "");
+  static_assert(CastFrom(AllOnes) == -1, "");
+
   template 
   constexpr __int128 CastTo(T A) {
 int128_t B = (int128_t)A;

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


[clang] [clang][Interp] Fix value truncation when casting int128 to smaller size (PR #67961)

2023-10-02 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

Before this patch, we would run into an assertion in 
`APInt::get{S,Z}ExtValue()` because the `AllOnes` value had more than 64 active 
bits.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/IntegralAP.h (+13-9) 
- (modified) clang/test/AST/Interp/literals.cpp (+9) 


``diff
diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index b2b367f30c238fe..f67b15dbc9b31ac 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -55,14 +55,14 @@ template  class IntegralAP final {
   bool operator<=(IntegralAP RHS) const { return V <= RHS.V; }
 
   explicit operator bool() const { return !V.isZero(); }
-  explicit operator int8_t() const { return V.getSExtValue(); }
-  explicit operator uint8_t() const { return V.getZExtValue(); }
-  explicit operator int16_t() const { return V.getSExtValue(); }
-  explicit operator uint16_t() const { return V.getZExtValue(); }
-  explicit operator int32_t() const { return V.getSExtValue(); }
-  explicit operator uint32_t() const { return V.getZExtValue(); }
-  explicit operator int64_t() const { return V.getSExtValue(); }
-  explicit operator uint64_t() const { return V.getZExtValue(); }
+  explicit operator int8_t() const { return truncateCast(V); }
+  explicit operator uint8_t() const { return truncateCast(V); }
+  explicit operator int16_t() const { return truncateCast(V); }
+  explicit operator uint16_t() const { return truncateCast(V); }
+  explicit operator int32_t() const { return truncateCast(V); }
+  explicit operator uint32_t() const { return truncateCast(V); }
+  explicit operator int64_t() const { return truncateCast(V); }
+  explicit operator uint64_t() const { return truncateCast(V); }
 
   template  static IntegralAP from(T Value, unsigned NumBits = 0) {
 assert(NumBits > 0);
@@ -210,7 +210,6 @@ template  class IntegralAP final {
   }
 
   static bool comp(IntegralAP A, IntegralAP *R) {
-assert(false);
 *R = IntegralAP(~A.V);
 return false;
   }
@@ -249,6 +248,11 @@ template  class IntegralAP final {
 R->V = A.V - B.V;
 return false; // Success!
   }
+
+  template  static T truncateCast(const APSInt &V) {
+return std::is_signed_v ? V.trunc(sizeof(T) * 8).getSExtValue()
+   : V.trunc(sizeof(T) * 8).getZExtValue();
+  }
 };
 
 template 
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index eca0e4c2cbd26f1..65d211422ddac92 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -52,6 +52,9 @@ namespace i128 {
   constexpr int128_t Two = (int128_t)1 << 1ul;
   static_assert(Two == 2, "");
 
+  constexpr uint128_t AllOnes = ~static_cast(0);
+  static_assert(AllOnes == UINT128_MAX, "");
+
 #if __cplusplus >= 201402L
   template 
   constexpr T CastFrom(__int128_t A) {
@@ -67,6 +70,12 @@ namespace i128 {
   static_assert(CastFrom(12) == 12, "");
   static_assert(CastFrom(12) == 12, "");
 
+  static_assert(CastFrom(AllOnes) == -1, "");
+  static_assert(CastFrom(AllOnes) == 0xFF, "");
+  static_assert(CastFrom(AllOnes) == -1, "");
+  static_assert(CastFrom(AllOnes) == 0x, "");
+  static_assert(CastFrom(AllOnes) == -1, "");
+
   template 
   constexpr __int128 CastTo(T A) {
 int128_t B = (int128_t)A;

``




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


[PATCH] D154869: [Flang] [FlangRT] Introduce FlangRT project as solution to Flang's runtime LLVM integration

2023-10-02 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

I've reverted this 
https://github.com/llvm/llvm-project/commit/ffc67bb3602a6a9a4f886af362e1f2d7c9821570
 as Linaro's flang and clang bots are red all over and we're also in an upgrade 
period for the build server 
(https://discourse.llvm.org/t/llvm-zorg-migration-to-the-buildbot-v3-9/73749) 
so getting a fix into zorg isn't going to happen for a few days at least.

Whoever decided to land this change please look at the remedies suggested by 
@pscoro and submit PRs to address those and eventually reland this. Happy to 
help on review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154869

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


[PATCH] D154869: [Flang] [FlangRT] Introduce FlangRT project as solution to Flang's runtime LLVM integration

2023-10-02 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

Thanks for the revert!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154869

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


[clang] [clang][Interp] Fix value truncation when casting int128 to smaller size (PR #67961)

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


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

>From 80bd890c332654458014c4acc20709b9cbb6eb90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 1 Oct 2023 19:57:03 +0200
Subject: [PATCH 1/2] [clang][Interp] Implement IntegralAP::comp

---
 clang/lib/AST/Interp/IntegralAP.h  | 1 -
 clang/test/AST/Interp/literals.cpp | 3 +++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index b2b367f30c238fe..b29aac2a73e3243 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -210,7 +210,6 @@ template  class IntegralAP final {
   }
 
   static bool comp(IntegralAP A, IntegralAP *R) {
-assert(false);
 *R = IntegralAP(~A.V);
 return false;
   }
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index eca0e4c2cbd26f1..00182ba4ab1d918 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -52,6 +52,9 @@ namespace i128 {
   constexpr int128_t Two = (int128_t)1 << 1ul;
   static_assert(Two == 2, "");
 
+  constexpr uint128_t AllOnes = ~static_cast(0);
+  static_assert(AllOnes == static_cast(-1), "");
+
 #if __cplusplus >= 201402L
   template 
   constexpr T CastFrom(__int128_t A) {

>From c39f0d9b69d00c08be93e5843efeb185fc292741 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 2 Oct 2023 10:46:22 +0200
Subject: [PATCH 2/2] [clang][Interp] Fix value truncation when casting int128
 to smaller size

---
 clang/lib/AST/Interp/IntegralAP.h  | 21 +
 clang/test/AST/Interp/literals.cpp | 10 +-
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index b29aac2a73e3243..f67b15dbc9b31ac 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -55,14 +55,14 @@ template  class IntegralAP final {
   bool operator<=(IntegralAP RHS) const { return V <= RHS.V; }
 
   explicit operator bool() const { return !V.isZero(); }
-  explicit operator int8_t() const { return V.getSExtValue(); }
-  explicit operator uint8_t() const { return V.getZExtValue(); }
-  explicit operator int16_t() const { return V.getSExtValue(); }
-  explicit operator uint16_t() const { return V.getZExtValue(); }
-  explicit operator int32_t() const { return V.getSExtValue(); }
-  explicit operator uint32_t() const { return V.getZExtValue(); }
-  explicit operator int64_t() const { return V.getSExtValue(); }
-  explicit operator uint64_t() const { return V.getZExtValue(); }
+  explicit operator int8_t() const { return truncateCast(V); }
+  explicit operator uint8_t() const { return truncateCast(V); }
+  explicit operator int16_t() const { return truncateCast(V); }
+  explicit operator uint16_t() const { return truncateCast(V); }
+  explicit operator int32_t() const { return truncateCast(V); }
+  explicit operator uint32_t() const { return truncateCast(V); }
+  explicit operator int64_t() const { return truncateCast(V); }
+  explicit operator uint64_t() const { return truncateCast(V); }
 
   template  static IntegralAP from(T Value, unsigned NumBits = 0) {
 assert(NumBits > 0);
@@ -248,6 +248,11 @@ template  class IntegralAP final {
 R->V = A.V - B.V;
 return false; // Success!
   }
+
+  template  static T truncateCast(const APSInt &V) {
+return std::is_signed_v ? V.trunc(sizeof(T) * 8).getSExtValue()
+   : V.trunc(sizeof(T) * 8).getZExtValue();
+  }
 };
 
 template 
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 00182ba4ab1d918..00875bcf44dc8e6 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -53,7 +53,7 @@ namespace i128 {
   static_assert(Two == 2, "");
 
   constexpr uint128_t AllOnes = ~static_cast(0);
-  static_assert(AllOnes == static_cast(-1), "");
+  static_assert(AllOnes == UINT128_MAX, "");
 
 #if __cplusplus >= 201402L
   template 
@@ -70,6 +70,14 @@ namespace i128 {
   static_assert(CastFrom(12) == 12, "");
   static_assert(CastFrom(12) == 12, "");
 
+  static_assert(CastFrom(AllOnes) == -1, "");
+  static_assert(CastFrom(AllOnes) == 0xFF, "");
+  static_assert(CastFrom(AllOnes) == -1, "");
+  static_assert(CastFrom(AllOnes) == 0x, "");
+  static_assert(CastFrom(AllOnes) == -1, "");
+  static_assert(CastFrom(AllOnes) == -1, "");
+  static_assert(CastFrom(AllOnes) == AllOnes, "");
+
   template 
   constexpr __int128 CastTo(T A) {
 int128_t B = (int128_t)A;

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


[PATCH] D155688: [PATCH] [llvm] [InstCombine] Canonicalise ADD+GEP

2023-10-02 Thread Dmitriy Smirnov via Phabricator via cfe-commits
d-smirnov added a comment.

@nikic Updated. Please review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155688

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


[clang] [flang]Add vscale argument parsing (PR #67676)

2023-10-02 Thread Tom Eccles via cfe-commits

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


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


[clang] [clang] Add test for CWG472 (PR #67948)

2023-10-02 Thread via cfe-commits

cor3ntin wrote:

CC @zygoloid 
In the proposed resolution, i do not understand why `B* bp = n2p;` should be 
ill-formed by virtue of being declared in `P2`

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


[clang] [clang][Interp] Implement compound assign operators on bitfields (PR #67306)

2023-10-02 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[clang] [clang][Interp] Diagnose uninitialized bases (PR #67131)

2023-10-02 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[PATCH] D155610: [Clang][Sema] Fix display of characters on static assertion failure

2023-10-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


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

https://reviews.llvm.org/D155610

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


[clang] [clang][Modules] `checkModuleIsAvailable` should use a const & parameter instead of pointer (PR #67902)

2023-10-02 Thread Chuanqi Xu via cfe-commits

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

LGTM. Thanks.

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


[clang] [clang][Modules] Make `Module::Requirement` a struct (PR #67900)

2023-10-02 Thread Chuanqi Xu via cfe-commits

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

LGTM. Thanks.

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


[clang] remove duplicate ModuleId alias (PR #67899)

2023-10-02 Thread Chuanqi Xu via cfe-commits

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

LGTM. Thanks.

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


[clang] [flang]Add vscale argument parsing (PR #67676)

2023-10-02 Thread Andrzej Warzyński via cfe-commits

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


[clang] [flang]Add vscale argument parsing (PR #67676)

2023-10-02 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,55 @@
+! -
+! Tests for the -msve-vector-bits flag (taken from the clang test)
+! -
+
+! RUN: %flang -c %s -### --target=aarch64-none-linux-gnu -march=armv8-a+sve \
+! RUN:  -msve-vector-bits=128 2>&1 | FileCheck --check-prefix=CHECK-128 %s
+! RUN: %flang -c %s -### --target=aarch64-none-linux-gnu -march=armv8-a+sve \
+! RUN:  -msve-vector-bits=256 2>&1 | FileCheck --check-prefix=CHECK-256 %s
+! RUN: %flang -c %s -### --target=aarch64-none-linux-gnu -march=armv8-a+sve \
+! RUN:  -msve-vector-bits=512 2>&1 | FileCheck --check-prefix=CHECK-512 %s
+! RUN: %flang -c %s -### --target=aarch64-none-linux-gnu -march=armv8-a+sve \
+! RUN:  -msve-vector-bits=1024 2>&1 | FileCheck --check-prefix=CHECK-1024 %s
+! RUN: %flang -c %s -### --target=aarch64-none-linux-gnu -march=armv8-a+sve \
+! RUN:  -msve-vector-bits=2048 2>&1 | FileCheck --check-prefix=CHECK-2048 %s
+! RUN: %flang -c %s -### --target=aarch64-none-linux-gnu -march=armv8-a+sve \
+! RUN:  -msve-vector-bits=128+ 2>&1 | FileCheck --check-prefix=CHECK-128P %s
+! RUN: %flang -c %s -### --target=aarch64-none-linux-gnu -march=armv8-a+sve \
+! RUN:  -msve-vector-bits=256+ 2>&1 | FileCheck --check-prefix=CHECK-256P %s
+! RUN: %flang -c %s -### --target=aarch64-none-linux-gnu -march=armv8-a+sve \
+! RUN:  -msve-vector-bits=512+ 2>&1 | FileCheck --check-prefix=CHECK-512P %s
+! RUN: %flang -c %s -### --target=aarch64-none-linux-gnu -march=armv8-a+sve \
+! RUN:  -msve-vector-bits=1024+ 2>&1 | FileCheck --check-prefix=CHECK-1024P %s
+! RUN: %flang -c %s -### --target=aarch64-none-linux-gnu -march=armv8-a+sve \
+! RUN:  -msve-vector-bits=2048+ 2>&1 | FileCheck --check-prefix=CHECK-2048P %s
+! RUN: %flang -c %s -### --target=aarch64-none-linux-gnu -march=armv8-a+sve \
+! RUN:  -msve-vector-bits=scalable 2>&1 | FileCheck 
--check-prefix=CHECK-SCALABLE %s
+
+! CHECK-128: "-mvscale-max=1" "-mvscale-min=1"

banach-space wrote:

> So you're saying we should check that it's not catching some other - 
> preprocessor, linker or something else that may have got hold of the "right" 
> command-line argument?

Indeed. Also, as a documentation for our future selves. It won't hurt, but 
could make our lives easier when re-visiting this in e.g. 6 months time :) 

This is a nit, feel free to land as is 👍🏻 Thank you :)

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


[clang] [RISCV] Update Zfa extension version to 1.0 (PR #67964)

2023-10-02 Thread Alex Bradbury via cfe-commits

https://github.com/asb created https://github.com/llvm/llvm-project/pull/67964

The Zfa specification was recently ratified
. This commit 
bumps the version to 1.0, but leaves it as an experimental extension (to be 
done in a follow-on patch), so reviews can focus on confirming there haven't 
been spec changes we have missed (which as noted below, is more difficult than 
usual).

Because the development of the Zfa spec overlapped with the transition of 
riscv-isa-manual from LaTeX to AsciiDoc, it's more difficult than usual to 
confirm version changes. The linked PDF in RISCVUsage is for some reason a 404. 
Key commit histories to review are:
* Changes to zfa.adoc on the main branch 

* Changes to zfa.tex on the now defunct latex branch 


>From reviewing these, I believe there have been no changes to the spec since 
>version 0.1/0.2 (sadly the AsciiDoc and LaTeX versions of the spec are 
>inconsistent about version numbering).

There hasn't been a GitHub release of the spec since Zfa was ratified (though 
I've requested one
), so RISCVUsage is 
updated to link to the current Zfa.adoc. I don't think we need to block on 
this, as we expect to shortly move Zfa to non-experimental, at which point we 
don't link to individual spec documents in RISCVUsage.

>From 79ab61e07a01e503f22e717c4b0e64b7741c59a0 Mon Sep 17 00:00:00 2001
From: Alex Bradbury 
Date: Mon, 2 Oct 2023 11:06:44 +0100
Subject: [PATCH] [RISCV] Update Zfa extension version to 1.0

The Zfa specification was recently ratified
. This
commit bumps the version to 1.0, but leaves it as an experimental
extension (to be done in a follow-on patch), so reviews can focus on
confirming there haven't been spec changes we have missed (which as
noted below, is more difficult than usual).

Because the development of the Zfa spec overlapped with the transition
of riscv-isa-manual from LaTeX to AsciiDoc, it's more difficult than
usual to confirm version changes. The linked PDF in RISCVUsage is for
some reason a 404. Key commit histories to review are:
* Changes to zfa.adoc on the main branch
  
* Changes to zfa.tex on the now defunct latex branch
  

>From reviewing these, I believe there have been no changes to the spec
since version 0.1/0.2 (sadly the AsciiDoc and LaTeX versions of the spec
are inconsistent about version numbering).

There hasn't been a GitHub release of the spec since Zfa was ratified
(though I've requested one
), so RISCVUsage
is updated to link to the current Zfa.adoc. I don't think we need to
block on this, as we expect to shortly move Zfa to non-experimental, at
which point we don't link to individual spec documents in RISCVUsage.
---
 clang/test/Driver/riscv-arch.c  | 4 ++--
 clang/test/Preprocessor/riscv-target-features.c | 6 +++---
 llvm/docs/RISCVUsage.rst| 2 +-
 llvm/docs/ReleaseNotes.rst  | 1 +
 llvm/lib/Support/RISCVISAInfo.cpp   | 2 +-
 llvm/test/CodeGen/RISCV/attributes.ll   | 4 ++--
 llvm/test/MC/RISCV/attribute-arch.s | 4 ++--
 7 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 92a6a59cba2317c..4896c0184507dd4 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -385,9 +385,9 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32izfa0p1 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-BADVERS 
%s
 // RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32izfa0p1'
-// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental 
extension 'zfa' (this compiler supports 0.2)
+// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental 
extension 'zfa' (this compiler supports 1.0)
 
-// RUN: %clang --target=riscv32-unknown-elf -march=rv32izfa0p2 
-menable-experimental-extensions -### %s \
+// RUN: %clang --target=riscv32-unknown-elf -march=rv32izfa1p0 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-GOODVERS %s
 // RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-zfa"
 
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 4dd83cfa0620b90..4b9ec423200017f 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -

[clang] [RISCV] Update Zfa extension version to 1.0 (PR #67964)

2023-10-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

The Zfa specification was recently ratified
;. This 
commit bumps the version to 1.0, but leaves it as an experimental extension (to 
be done in a follow-on patch), so reviews can focus on confirming there haven't 
been spec changes we have missed (which as noted below, is more difficult than 
usual).

Because the development of the Zfa spec overlapped with the transition of 
riscv-isa-manual from LaTeX to AsciiDoc, it's more difficult than usual to 
confirm version changes. The linked PDF in RISCVUsage is for some reason a 404. 
Key commit histories to review are:
* Changes to zfa.adoc on the main branch 
;
* Changes to zfa.tex on the now defunct latex branch 
;

>From reviewing these, I believe there have been no changes to the spec since 
>version 0.1/0.2 (sadly the AsciiDoc and LaTeX versions of the spec are 
>inconsistent about version numbering).

There hasn't been a GitHub release of the spec since Zfa was ratified (though 
I've requested one
;), so RISCVUsage 
is updated to link to the current Zfa.adoc. I don't think we need to block on 
this, as we expect to shortly move Zfa to non-experimental, at which point we 
don't link to individual spec documents in RISCVUsage.

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


7 Files Affected:

- (modified) clang/test/Driver/riscv-arch.c (+2-2) 
- (modified) clang/test/Preprocessor/riscv-target-features.c (+3-3) 
- (modified) llvm/docs/RISCVUsage.rst (+1-1) 
- (modified) llvm/docs/ReleaseNotes.rst (+1) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+1-1) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+2-2) 
- (modified) llvm/test/MC/RISCV/attribute-arch.s (+2-2) 


``diff
diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 92a6a59cba2317c..4896c0184507dd4 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -385,9 +385,9 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32izfa0p1 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-BADVERS 
%s
 // RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32izfa0p1'
-// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental 
extension 'zfa' (this compiler supports 0.2)
+// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental 
extension 'zfa' (this compiler supports 1.0)
 
-// RUN: %clang --target=riscv32-unknown-elf -march=rv32izfa0p2 
-menable-experimental-extensions -### %s \
+// RUN: %clang --target=riscv32-unknown-elf -march=rv32izfa1p0 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-GOODVERS %s
 // RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-zfa"
 
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 4dd83cfa0620b90..4b9ec423200017f 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -1002,12 +1002,12 @@
 // CHECK-ZACAS-EXT: __riscv_zacas 100{{$}}
 
 // RUN: %clang --target=riscv32-unknown-linux-gnu 
-menable-experimental-extensions \
-// RUN: -march=rv32izfa0p2 -x c -E -dM %s \
+// RUN: -march=rv32izfa1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
 // RUN: %clang --target=riscv64-unknown-linux-gnu 
-menable-experimental-extensions \
-// RUN: -march=rv64izfa0p2 -x c -E -dM %s \
+// RUN: -march=rv64izfa1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
-// CHECK-ZFA-EXT: __riscv_zfa 2000{{$}}
+// CHECK-ZFA-EXT: __riscv_zfa 100{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN: -march=rv32izfbfmin0p8 -x c -E -dM %s \
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 8d12d58738c609a..647c4c49500c161 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -197,7 +197,7 @@ The primary goal of experimental support is to assist in 
the process of ratifica
   LLVM implements the `1.0-rc1 draft specification 
`_.
 
 ``experimental-zfa``
-  LLVM implements the `0.2 draft specification 
`__.
+  LLVM implements the `1.0 specification 
`__.
 
 ``experimental-zfbfmin``, ``experimental-zvfbfmin``, ``experimental-zvfbfwma``
   LLVM implements assembler support for the `0.8.0 draft specificatio

[clang] [clang] Add test for CWG1341 (PR #67965)

2023-10-02 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/67965

https://cplusplus.github.io/CWG/issues/1341.html
https://wg21.link/p0683r1

>From 92fec6fe49de0392596e7f7d4a1c5524dd436747 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 2 Oct 2023 13:17:40 +0300
Subject: [PATCH] [clang] Add test for CWG1341

---
 clang/test/CXX/drs/dr13xx.cpp | 17 +
 clang/www/cxx_dr_status.html  |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index feaf523c44fc27c..3510695954e27c1 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -254,6 +254,23 @@ namespace dr1330 { // dr1330: 4 c++11
 #endif
 }
 
+namespace dr1341 { // dr1341: sup P0683R1
+#if __cplusplus >= 202002L
+int a;
+const int b = 0; // #dr1341-b-decl
+struct S {
+  int x1 : 8 = 42;
+  int x2 : 8 { 42 };
+  int y1 : true ? 8 : a = 42;
+  int y2 : true ? 8 : b = 42;
+  // expected-error@-1{{cannot assign to variable 'b' with 
const-qualified type 'const int'}}
+  // expected-note@#dr1341-b-decl {{variable 'b' declared const here}}
+  int y3 : (true ? 8 : b) = 42;
+  int z : 1 || new int { 0 };
+};
+#endif
+}
+
 namespace dr1346 { // dr1346: 3.5
   auto a(1); // expected-error 0-1{{extension}}
   auto b(1, 2); // expected-error {{multiple expressions}} expected-error 
0-1{{extension}}
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index ee9712e9bab9949..6b351a3eb72f3d1 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -7853,7 +7853,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1341.html";>1341
 NAD
 Bit-field initializers
-Unknown
+Superseded by https://wg21.link/P0683R1";>P0683R1
   
   
 https://cplusplus.github.io/CWG/issues/1342.html";>1342

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


[clang] [clang] Add test for CWG1341 (PR #67965)

2023-10-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

https://cplusplus.github.io/CWG/issues/1341.html
https://wg21.link/p0683r1

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


2 Files Affected:

- (modified) clang/test/CXX/drs/dr13xx.cpp (+17) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 


``diff
diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index feaf523c44fc27c..3510695954e27c1 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -254,6 +254,23 @@ namespace dr1330 { // dr1330: 4 c++11
 #endif
 }
 
+namespace dr1341 { // dr1341: sup P0683R1
+#if __cplusplus >= 202002L
+int a;
+const int b = 0; // #dr1341-b-decl
+struct S {
+  int x1 : 8 = 42;
+  int x2 : 8 { 42 };
+  int y1 : true ? 8 : a = 42;
+  int y2 : true ? 8 : b = 42;
+  // expected-error@-1{{cannot assign to variable 'b' with 
const-qualified type 'const int'}}
+  // expected-note@#dr1341-b-decl {{variable 'b' declared const here}}
+  int y3 : (true ? 8 : b) = 42;
+  int z : 1 || new int { 0 };
+};
+#endif
+}
+
 namespace dr1346 { // dr1346: 3.5
   auto a(1); // expected-error 0-1{{extension}}
   auto b(1, 2); // expected-error {{multiple expressions}} expected-error 
0-1{{extension}}
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index ee9712e9bab9949..6b351a3eb72f3d1 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -7853,7 +7853,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1341.html";>1341
 NAD
 Bit-field initializers
-Unknown
+Superseded by https://wg21.link/P0683R1";>P0683R1
   
   
 https://cplusplus.github.io/CWG/issues/1342.html";>1342

``




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


[clang] [clang] Add test for CWG2267 (PR #67931)

2023-10-02 Thread Vlad Serebrennikov via cfe-commits

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


[clang] -fsanitize=function: fix MSVC hashing to sugared type (PR #66816)

2023-10-02 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@rnk Since @efriedma-quic seems to be unavailable, any objections we move 
forward and merge this, as is?

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


[clang] [MLIR][NVGPU] Introduce `nvgpu.wargroup.mma.store` Op for Hopper GPUs (PR #65441)

2023-10-02 Thread Guray Ozen via cfe-commits

https://github.com/grypp updated https://github.com/llvm/llvm-project/pull/65441

>From 7b71da55fca8fe2a7dbe4982b1959be6a6175fa1 Mon Sep 17 00:00:00 2001
From: Guray Ozen 
Date: Thu, 7 Sep 2023 11:52:38 +0200
Subject: [PATCH 1/6] [MLIR][NVGPU] Introduce `nvgpu.warpgroup.mma.store` Op
 for Hopper GPUs

This work introduces a new operation called `warpgroup.mma.store` to the NVGPU 
dialect of MLIR. The purpose of this operation is to facilitate storing 
fragmanted results of WGMMA to the given memref.

An example of fragmentation is given here :
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#wgmma-64n16-d

The `warpgroup.mma.store` does followings:
1) Takes one or more fragmented results matrix.
2) Calculates indexes per thread in warp group and stores the data into give 
memref.

Here's an example usage of the `nvgpu.warpgroup.mma` operation:
```
// Performs matmul, results are fragmented and in registers
%res, %res2 = nvgpu.warpgroup.mma ...

// Stores the fragmented result to the give memory
nvgpu.warpgroup.mma.store [%res1, %res2], %matrixD :
!nvgpu.warpgroup.result>,
!nvgpu.warpgroup.result>
to memref<128x128xf32,3>
```

Depends on #65440
---
 mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td   | 19 +
 .../Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp| 83 ++-
 mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp| 29 +++
 3 files changed, 129 insertions(+), 2 deletions(-)

diff --git a/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td 
b/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td
index 90381648dac6acc..e102ae0dc581013 100644
--- a/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td
+++ b/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td
@@ -721,4 +721,23 @@ def NVGPU_WarpgroupMmaOp : NVGPU_Op<"warpgroup.mma"> {
   let hasVerifier = 1;
 }
 
+def NVGPU_WarpgroupMmaStoreOp : NVGPU_Op<"warpgroup.mma.store"> {
+  let description = [{
+The `nvgpu.warpgroup.mma.store` op performs the store of fragmented result 
+in $matrixD to give memref. 
+
+[See the details of register fragment layout for accumulator matrix 
D](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#wgmma-64n16-d)
 
+
+Note that, the op must be run with warp group.
+  }];
+
+  let arguments = (ins Variadic:$matrixD,
+   Arg:$dstMemref);
+  
+  let assemblyFormat = [{
+`[` $matrixD `]` `,` $dstMemref attr-dict `:` type($matrixD) `to` 
type($dstMemref)
+  }];
+  let hasVerifier = 1;
+}
+
 #endif // NVGPU
diff --git a/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp 
b/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
index f74aa05c0c4c4ff..4f1a0bc651e81b7 100644
--- a/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
+++ b/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
@@ -11,6 +11,7 @@
 #include "mlir/Conversion/GPUCommon/GPUCommonPass.h"
 #include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
 #include "mlir/Conversion/LLVMCommon/Pattern.h"
+#include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
@@ -409,8 +410,8 @@ struct ConvertNVGPUToNVVMPass
   using Base::Base;
 
   void getDependentDialects(DialectRegistry ®istry) const override {
-registry
-.insert();
+registry.insert();
   }
 
   void runOnOperation() override {
@@ -451,6 +452,7 @@ struct ConvertNVGPUToNVVMPass
 populateNVGPUToNVVMConversionPatterns(converter, patterns);
 LLVMConversionTarget target(getContext());
 target.addLegalDialect<::mlir::LLVM::LLVMDialect>();
+target.addLegalDialect<::mlir::arith::ArithDialect>();
 target.addLegalDialect<::mlir::memref::MemRefDialect>();
 target.addLegalDialect<::mlir::NVVM::NVVMDialect>();
 mlir::scf::populateSCFStructuralTypeConversionsAndLegality(
@@ -1299,11 +1301,88 @@ struct NVGPUWarpgroupMmaOpLowering
   }
 };
 
+struct NVGPUWarpgroupMmaStoreOpLowering
+: public ConvertOpToLLVMPattern {
+  using ConvertOpToLLVMPattern<
+  nvgpu::WarpgroupMmaStoreOp>::ConvertOpToLLVMPattern;
+
+  void storeFragmentedMatrix(Value wgmmaResult, nvgpu::WarpgroupMmaStoreOp op,
+ OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter,
+ int offset) const {
+Location loc = op->getLoc();
+Type i32 = rewriter.getI32Type();
+
+auto makeConst = [&](int32_t index) -> Value {
+  return rewriter.create(
+  loc, i32, rewriter.getI32IntegerAttr(index));
+};
+Value c4 = makeConst(4);
+Value c32 = makeConst(kWarpSize);
+Value c8 = makeConst(8);
+Value c2 = makeConst(2);
+Value c1 = makeConst(1);
+Value c16 = makeConst(16);
+
+auto makeMul = [&](Value lhs, Value rhs) -> Value {
+  return rewriter.create(loc, lhs.getType(), lhs, rhs);
+};
+auto makeAdd = [&](Value lhs, Value rhs) -> Value {
+  return rewriter.create(loc, lhs.getType(), lhs, rhs)

[clang] 3f09273 - [C++20] [Modules] Fix crash when emitting module inits for duplicated modules

2023-10-02 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-10-02T18:31:54+08:00
New Revision: 3f0927368285505ead516ba7572baaa7f52b01a9

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

LOG: [C++20] [Modules] Fix crash when emitting module inits for duplicated 
modules

Close https://github.com/llvm/llvm-project/issues/67893

The root cause of the crash is an oversight that we missed the point
that the same module can be imported multiple times. And we should use
`SmallSetVector` instead of `SmallVector` to filter the case.

Added: 
clang/test/Modules/module-init-duplicated-import.cppm
clang/test/Modules/pr67893.cppm

Modified: 
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 8a05e4893196ad2..30683ad474cd2c0 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -666,13 +666,13 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module 
*Primary) {
   // Module initializers for imported modules are emitted first.
 
   // Collect all the modules that we import
-  SmallVector AllImports;
+  llvm::SmallSetVector AllImports;
   // Ones that we export
   for (auto I : Primary->Exports)
-AllImports.push_back(I.getPointer());
+AllImports.insert(I.getPointer());
   // Ones that we only import.
   for (Module *M : Primary->Imports)
-AllImports.push_back(M);
+AllImports.insert(M);
   // Ones that we import in the global module fragment or the private module
   // fragment.
   llvm::for_each(Primary->submodules(), [&AllImports](Module *SubM) {
@@ -683,7 +683,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
"The global mdoule fragments and the private module fragments are "
"not allowed to export import modules.");
 for (Module *M : SubM->Imports)
-  AllImports.push_back(M);
+  AllImports.insert(M);
   });
 
   SmallVector ModuleInits;

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index c96523c52562582..925f5114e9108e0 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2938,6 +2938,9 @@ void CodeGenModule::EmitModuleInitializers(clang::Module 
*Primary) {
   // Third any associated with the Privat eMOdule Fragment, if present.
   if (auto PMF = Primary->getPrivateModuleFragment()) {
 for (Decl *D : getContext().getModuleInitializers(PMF)) {
+  // Skip import decls, the inits for those are called explicitly.
+  if (isa(D))
+continue;
   assert(isa(D) && "PMF initializer decl is not a var?");
   EmitTopLevelDecl(D);
 }

diff  --git a/clang/test/Modules/module-init-duplicated-import.cppm 
b/clang/test/Modules/module-init-duplicated-import.cppm
new file mode 100644
index 000..de0ce1962f10082
--- /dev/null
+++ b/clang/test/Modules/module-init-duplicated-import.cppm
@@ -0,0 +1,27 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/a.cppm \
+// RUN:  -emit-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/m.cppm \
+// RUN:  -emit-module-interface -fmodule-file=a=%t/a.pcm -o %t/m.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/m.pcm  \
+// RUN: -S -emit-llvm -o - | FileCheck %t/m.cppm
+
+//--- a.cppm
+export module a;
+export struct A {
+  A(){};
+};
+export A __dynamic_inited_a;
+
+//--- m.cppm
+export module m;
+import a;
+export import a;
+
+
+// CHECK: define void @_ZGIW1m
+// CHECK: store i8 1, ptr @_ZGIW1m__in_chrg
+// CHECK: call{{.*}}@_ZGIW1a

diff  --git a/clang/test/Modules/pr67893.cppm b/clang/test/Modules/pr67893.cppm
new file mode 100644
index 000..7d4e4c1dc5d843c
--- /dev/null
+++ b/clang/test/Modules/pr67893.cppm
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/a.cppm \
+// RUN:  -emit-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/m.cppm \
+// RUN:  -emit-module-interface -fmodule-file=a=%t/a.pcm -o %t/m.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/m.pcm  \
+// RUN: -S -emit-llvm -o - | FileCheck %t/m.cppm
+
+//--- a.cppm
+export module a;
+export struct A {
+  A(){};
+};
+export A __dynamic_inited_a;
+
+//--- m.cppm
+module;
+import a;
+export module m;
+import a;
+module :private;
+import a;
+
+// CHECK: define void @_ZGIW1m
+// CHECK: store i8 1, ptr @_ZGIW1m__in_chrg
+// CHECK: call{{.*}}@_ZGIW1a



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

[clang] [MLIR][NVGPU] Introduce `nvgpu.wargroup.mma.store` Op for Hopper GPUs (PR #65441)

2023-10-02 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 7bc09a471fbc274d8632d1379d4134bec63fecc4 
2cc84d3d83320fc31a2434055939a4ed6569c077 -- 
mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp 
mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp
``





View the diff from clang-format here.


``diff
diff --git a/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp 
b/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
index 9027bfa4efdb..c77ba1f9ada3 100644
--- a/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
+++ b/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
@@ -19,8 +19,8 @@
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/NVGPU/IR/NVGPUDialect.h"
 #include "mlir/Dialect/SCF/Transforms/Patterns.h"
-#include "mlir/IR/ImplicitLocOpBuilder.h"
 #include "mlir/IR/BuiltinTypes.h"
+#include "mlir/IR/ImplicitLocOpBuilder.h"
 #include "mlir/IR/PatternMatch.h"
 #include "mlir/IR/TypeUtilities.h"
 #include "mlir/IR/Value.h"

``




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


[PATCH] D158266: [OpenMP] Patch for Support to loop bind clause : Checking Parent Region

2023-10-02 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:6230
 BindKind = BC->getBindKind();
+
   // First check CancelRegion which is then used in checkNestingOfRegions.

Remove this new line



Comment at: clang/lib/Sema/SemaOpenMP.cpp:6245-6248
+  UseClausesWithoutBind = mapLoopConstruct(
+  ClausesWithoutBind, Clauses, BindKind, Kind, PrevMappedDirective,
+  StartLoc, EndLoc, DirName, CancelRegion);
 

Can we do this before checks in lines 6232-6235 so we can avoid double call of 
checkNestingOfRegions for bind?


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

https://reviews.llvm.org/D158266

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


[clang] 3b25407 - [IR] Mark zext/sext constant expressions as undesirable

2023-10-02 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-10-02T12:40:20+02:00
New Revision: 3b25407d977d9ed3dbcaccd4f8850b65e95d70fd

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

LOG: [IR] Mark zext/sext constant expressions as undesirable

Introduce isDesirableCastOp() which determines whether IR builder
and constant folding should produce constant expressions for a
given cast type. This mirrors what we do for binary operators.

Mark zext/sext as undesirable, which prevents most creations of such
constant expressions. This is still somewhat incomplete and there
are a few more places that can create zext/sext expressions.

This is part of the work for
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.

The reason for the odd result in the constantexpr-fneg.c test is
that initially the "a[]" global is created with an [0 x i32] type,
at which point the icmp expression cannot be folded. Later it is
replaced with an [1 x i32] global and the icmp gets folded away.
But at that point we no longer fold the zext.

Added: 


Modified: 
clang/test/CodeGen/constantexpr-fneg.c
clang/test/CodeGenCXX/weak-external.cpp
clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
llvm/include/llvm/Analysis/TargetFolder.h
llvm/include/llvm/IR/ConstantFolder.h
llvm/include/llvm/IR/Constants.h
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/IR/Constants.cpp
llvm/lib/Transforms/Utils/SCCPSolver.cpp
llvm/test/Transforms/InstCombine/constant-fold-shifts.ll
llvm/test/Transforms/InstCombine/gep-custom-dl.ll
llvm/test/Transforms/InstCombine/hoist-xor-by-constant-from-xor-by-value.ll
llvm/test/Transforms/LowerTypeTests/import.ll
llvm/test/Transforms/LowerTypeTests/simplify.ll

Removed: 




diff  --git a/clang/test/CodeGen/constantexpr-fneg.c 
b/clang/test/CodeGen/constantexpr-fneg.c
index f82b3ff726578bb..3cd4db34f61acb7 100644
--- a/clang/test/CodeGen/constantexpr-fneg.c
+++ b/clang/test/CodeGen/constantexpr-fneg.c
@@ -8,9 +8,11 @@
 // CHECK:  entry:
 // CHECK-NEXT:   %retval = alloca i32
 // CHECK-NEXT:   store i32 0, ptr %retval
+// CHECK-NEXT:   [[ZEXT:%.*]] = zext i1 true to i32
+// CHECK-NEXT:   [[SITOFP:%.*]] = sitofp i32 [[ZEXT]] to float
 // CHECK-NEXT:   [[LV:%.*]] = load ptr, ptr @c
-// CHECK-NEXT:   store float 1.00e+00, ptr [[LV]], align 4
-// CHECK-NEXT:   [[FNEG:%.*]] = fneg float 1.00e+00
+// CHECK-NEXT:   store float [[SITOFP]], ptr [[LV]], align 4
+// CHECK-NEXT:   [[FNEG:%.*]] = fneg float [[SITOFP]]
 // CHECK-NEXT:   [[CONV:%.*]] = fptosi float [[FNEG]] to i32
 // CHECK-NEXT:   ret i32 [[CONV]]
 

diff  --git a/clang/test/CodeGenCXX/weak-external.cpp 
b/clang/test/CodeGenCXX/weak-external.cpp
index af636ccb4a3aef2..5fc37f73bb46974 100644
--- a/clang/test/CodeGenCXX/weak-external.cpp
+++ b/clang/test/CodeGenCXX/weak-external.cpp
@@ -80,19 +80,23 @@ namespace not_weak_on_first {
 namespace constant_eval {
   [[gnu::weak]] extern int a;
   // CHECK-LABEL: define {{.*}} @__cxx_global_var_init
-  // CHECK: store i8 zext (i1 icmp ne (ptr @_ZN13constant_eval1aE, ptr 
null) to i8), ptr @_ZN13constant_eval6has_a1E,
+  // CHECK: [[ZEXT:%.*]] = zext i1 icmp ne (ptr @_ZN13constant_eval1aE, 
ptr null) to i8
+  // CHECK: store i8 [[ZEXT]], ptr @_ZN13constant_eval6has_a1E,
   bool has_a1 = &a;
   // CHECK-LABEL: define {{.*}} @__cxx_global_var_init
-  // CHECK: store i8 zext (i1 icmp ne (ptr @_ZN13constant_eval1aE, ptr 
null) to i8), ptr @_ZN13constant_eval6has_a2E,
+  // CHECK: [[ZEXT:%.*]] = zext i1 icmp ne (ptr @_ZN13constant_eval1aE, 
ptr null) to i8
+  // CHECK: store i8 [[ZEXT]], ptr @_ZN13constant_eval6has_a2E,
   bool has_a2 = &a != nullptr;
 
   struct X {
 [[gnu::weak]] void f();
   };
   // CHECK-LABEL: define {{.*}} @__cxx_global_var_init
-  // CHECK: store i8 zext (i1 icmp ne (i{{32|64}} ptrtoint (ptr 
@_ZN13constant_eval1X1fEv to i{{32|64}}), i{{32|64}} 0) to i8), ptr 
@_ZN13constant_eval6has_f1E,
+  // CHECK: [[ZEXT:%.*]] = zext i1 icmp ne (i{{32|64}} ptrtoint (ptr 
@_ZN13constant_eval1X1fEv to i{{32|64}}), i{{32|64}} 0) to i8
+  // CHECK: store i8 [[ZEXT]], ptr @_ZN13constant_eval6has_f1E,
   bool has_f1 = &X::f;
   // CHECK-LABEL: define {{.*}} @__cxx_global_var_init
-  // CHECK: store i8 zext (i1 icmp ne (i{{32|64}} ptrtoint (ptr 
@_ZN13constant_eval1X1fEv to i{{32|64}}), i{{32|64}} 0) to i8), ptr 
@_ZN13constant_eval6has_f2E,
+  // CHECK: [[ZEXT:%.*]] = zext i1 icmp ne (i{{32|64}} ptrtoint (ptr 
@_ZN13constant_eval1X1fEv to i{{32|64}}), i{{32|64}} 0) to i8
+  // CHECK: store i8 [[ZEXT]], ptr @_ZN13constant_eval6has_f2E,
   bool has_f2 = &X::f != nullptr;
 }

diff  --git a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl 
b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
index cb3ca514c584fb1..8

[clang] Introduce paged vector (PR #66430)

2023-10-02 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> > Looks like this causes a compile-time regression: 
> > https://llvm-compile-time-tracker.com/compare.php?from=abcaebfe3aacb13d46be5e949fd6ed9b4321e2f6&to=4ae51570806ba5c5fcabe6d6dcbe52e3a5d5453b&stat=instructions%3Au
> >  About 0.5% at `O0`.
> 
> It is probably the change in the `SourceManager.cpp` in non-modules mode that 
> caused it. IIUC, this is a ~memory regression and probably comes by the 
> larger page/slab that we allocate~. Looks like the instruction count 
> increased and the branching increased. Could it be the indexing operation:
> 
> https://github.com/llvm/llvm-project/blob/f99bd296108756e9824b179761fb5a40807af66f/llvm/include/llvm/ADT/PagedVector.h#L82-L95
> 
> Would adding an `LLVM_UNLIKELY` in the if-stmt condition help us?

@ktf could you take a look at this?

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][ASTImporter] Fix of possible crash "Did not find base!". (PR #67680)

2023-10-02 Thread via cfe-commits

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

Looks reasonable, thanks!

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


[clang] [clang][ASTImporter] Fix of possible crash "Did not find base!". (PR #67680)

2023-10-02 Thread via cfe-commits

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


[clang] 11e68c7 - [flang]Add vscale argument parsing (#67676)

2023-10-02 Thread via cfe-commits

Author: Mats Petersson
Date: 2023-10-02T12:01:12+01:00
New Revision: 11e68c7e7ffb430f17a02c5ca28f6884b5de563a

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

LOG: [flang]Add vscale argument parsing (#67676)

Support for vector scale range arguments, for AArch64 scalable vector
extension (SVE) support.

Adds -msve-vector-bits to the flang frontend, and for flang fc1 the
options are -mvscale-min and -mvscale-max (optional). These match the
clang and clang cc1 options for the same purposes.

A further patch will actually USE these arguments.

Added: 
flang/test/Driver/aarch64-sve-vector-bits.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/ToolChains/Flang.h
flang/include/flang/Frontend/LangOptions.def
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index efd90942948af27..ee4e23f335e7875 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4557,18 +4557,19 @@ foreach i = {8-15,18} in
 HelpText<"Make the x"#i#" register call-saved (AArch64 only)">;
 
 def msve_vector_bits_EQ : Joined<["-"], "msve-vector-bits=">, 
Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Specify the size in bits of an SVE vector register. Defaults to 
the"
" vector length agnostic value of \"scalable\". (AArch64 only)">;
 } // let Flags = [TargetSpecific]
 
 def mvscale_min_EQ : Joined<["-"], "mvscale-min=">,
   Group, Flags<[NoXarchOption]>,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FC1Option]>,
   HelpText<"Specify the vscale minimum. Defaults to \"1\". (AArch64/RISC-V 
only)">,
   MarshallingInfoInt>;
 def mvscale_max_EQ : Joined<["-"], "mvscale-max=">,
   Group, Flags<[NoXarchOption]>,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FC1Option]>,
   HelpText<"Specify the vscale maximum. Defaults to the"
" vector length agnostic value of \"0\". (AArch64/RISC-V only)">,
   MarshallingInfoInt>;

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 10f785ce7ab9075..fe44939741d8ddb 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -6,7 +6,6 @@
 //
 
//===--===//
 
-
 #include "Flang.h"
 #include "CommonArgs.h"
 
@@ -170,6 +169,38 @@ void Flang::addPicOptions(const ArgList &Args, 
ArgStringList &CmdArgs) const {
   }
 }
 
+void Flang::AddAArch64TargetArgs(const ArgList &Args,
+ ArgStringList &CmdArgs) const {
+  // Handle -msve_vector_bits=
+  if (Arg *A = Args.getLastArg(options::OPT_msve_vector_bits_EQ)) {
+StringRef Val = A->getValue();
+const Driver &D = getToolChain().getDriver();
+if (Val.equals("128") || Val.equals("256") || Val.equals("512") ||
+Val.equals("1024") || Val.equals("2048") || Val.equals("128+") ||
+Val.equals("256+") || Val.equals("512+") || Val.equals("1024+") ||
+Val.equals("2048+")) {
+  unsigned Bits = 0;
+  if (Val.endswith("+"))
+Val = Val.substr(0, Val.size() - 1);
+  else {
+[[maybe_unused]] bool Invalid = Val.getAsInteger(10, Bits);
+assert(!Invalid && "Failed to parse value");
+CmdArgs.push_back(
+Args.MakeArgString("-mvscale-max=" + llvm::Twine(Bits / 128)));
+  }
+
+  [[maybe_unused]] bool Invalid = Val.getAsInteger(10, Bits);
+  assert(!Invalid && "Failed to parse value");
+  CmdArgs.push_back(
+  Args.MakeArgString("-mvscale-min=" + llvm::Twine(Bits / 128)));
+  // Silently drop requests for vector-length agnostic code as it's 
implied.
+} else if (!Val.equals("scalable"))
+  // Handle the unsupported values passed to msve-vector-bits.
+  D.Diag(diag::err_drv_unsupported_option_argument)
+  << A->getSpelling() << Val;
+  }
+}
+
 void Flang::addTargetOptions(const ArgList &Args,
  ArgStringList &CmdArgs) const {
   const ToolChain &TC = getToolChain();
@@ -186,9 +217,13 @@ void Flang::addTargetOptions(const ArgList &Args,
   switch (TC.getArch()) {
   default:
 break;
+  case llvm::Triple::aarch64:
+getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
+AddAArch64TargetArgs(Args, CmdArgs);
+break;
+
   case llvm::Triple::r600:
   case llvm::Triple::amdgcn:
-  case llvm::Triple::aarch64:
   case llvm::Triple::riscv64:
   case llvm::Triple::x86_64:
 getTargetFeatures(D, Triple, Args, 

[clang] [flang]Add vscale argument parsing (PR #67676)

2023-10-02 Thread Mats Petersson via cfe-commits

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


[clang] [clang] Add check for duplicates to make_cxx_dr_status script (PR #67969)

2023-10-02 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/67969

While working on #67965, I stumbled upon the fact that `make_cxx_dr_status` 
script doesn't check for duplicated comment (last comment wins), so I added 
this check.

It even found another instance of duplicated comment: CWG1223 was marked as 
CWG1227. I fixed status of the former.

>From 6b488467b6e6b40027e6ba1f5abbeeecbfeeef5b Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 2 Oct 2023 14:02:16 +0300
Subject: [PATCH] [clang] Add check for duplicates to make_cxx_dr_status script

---
 clang/test/CXX/drs/dr12xx.cpp | 2 +-
 clang/www/cxx_dr_status.html  | 2 +-
 clang/www/make_cxx_dr_status  | 6 +-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/test/CXX/drs/dr12xx.cpp b/clang/test/CXX/drs/dr12xx.cpp
index a941366050e1ab5..c23a515ba56cb99 100644
--- a/clang/test/CXX/drs/dr12xx.cpp
+++ b/clang/test/CXX/drs/dr12xx.cpp
@@ -32,7 +32,7 @@ namespace dr1213 { // dr1213: 7
 }
 
 #if __cplusplus >= 201103L
-namespace dr1223 { // dr1227: yes open
+namespace dr1223 { // dr1223: 17 drafting
 struct M;
 template 
 struct V;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index ee9712e9bab9949..80a80d9940df254 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -7145,7 +7145,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1223.html";>1223
 drafting
 Syntactic disambiguation and trailing-return-types
-Not resolved
+Clang 17
   
   
 https://cplusplus.github.io/CWG/issues/1224.html";>1224
diff --git a/clang/www/make_cxx_dr_status b/clang/www/make_cxx_dr_status
index afb7189c0ececc5..c44a5910d53daeb 100755
--- a/clang/www/make_cxx_dr_status
+++ b/clang/www/make_cxx_dr_status
@@ -39,7 +39,11 @@ def collect_tests():
 test_cpp = os.path.join(dr_test_dir, test_cpp)
 found_any = False;
 for match in re.finditer(status_re, open(test_cpp, 'r').read()):
-  status_map[int(match.group(1))] = match.group(2)
+  dr_number = int(match.group(1))
+  if dr_number in status_map:
+print("error: Comment for dr{} encountered more than once. Duplicate 
found in {}".format(dr_number, test_cpp))
+sys.exit(1)
+  status_map[dr_number] = match.group(2)
   found_any = True
 if not found_any:
   print("warning:%s: no '// dr123: foo' comments in this file" % test_cpp, 
file=sys.stderr)

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


[clang] [clang] Add check for duplicates to make_cxx_dr_status script (PR #67969)

2023-10-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

While working on #67965, I stumbled upon the fact that 
`make_cxx_dr_status` script doesn't check for duplicated comment (last comment 
wins), so I added this check.

It even found another instance of duplicated comment: CWG1223 was marked as 
CWG1227. I fixed status of the former.

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


3 Files Affected:

- (modified) clang/test/CXX/drs/dr12xx.cpp (+1-1) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 
- (modified) clang/www/make_cxx_dr_status (+5-1) 


``diff
diff --git a/clang/test/CXX/drs/dr12xx.cpp b/clang/test/CXX/drs/dr12xx.cpp
index a941366050e1ab5..c23a515ba56cb99 100644
--- a/clang/test/CXX/drs/dr12xx.cpp
+++ b/clang/test/CXX/drs/dr12xx.cpp
@@ -32,7 +32,7 @@ namespace dr1213 { // dr1213: 7
 }
 
 #if __cplusplus >= 201103L
-namespace dr1223 { // dr1227: yes open
+namespace dr1223 { // dr1223: 17 drafting
 struct M;
 template 
 struct V;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index ee9712e9bab9949..80a80d9940df254 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -7145,7 +7145,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1223.html";>1223
 drafting
 Syntactic disambiguation and trailing-return-types
-Not resolved
+Clang 17
   
   
 https://cplusplus.github.io/CWG/issues/1224.html";>1224
diff --git a/clang/www/make_cxx_dr_status b/clang/www/make_cxx_dr_status
index afb7189c0ececc5..c44a5910d53daeb 100755
--- a/clang/www/make_cxx_dr_status
+++ b/clang/www/make_cxx_dr_status
@@ -39,7 +39,11 @@ def collect_tests():
 test_cpp = os.path.join(dr_test_dir, test_cpp)
 found_any = False;
 for match in re.finditer(status_re, open(test_cpp, 'r').read()):
-  status_map[int(match.group(1))] = match.group(2)
+  dr_number = int(match.group(1))
+  if dr_number in status_map:
+print("error: Comment for dr{} encountered more than once. Duplicate 
found in {}".format(dr_number, test_cpp))
+sys.exit(1)
+  status_map[dr_number] = match.group(2)
   found_any = True
 if not found_any:
   print("warning:%s: no '// dr123: foo' comments in this file" % test_cpp, 
file=sys.stderr)

``




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

ktf wrote:

> @ktf could you take a look at this?

Sure, I did https://github.com/llvm/llvm-project/pull/67972 with your 
suggestion, however I am not sure how I can run the benchmark myself.

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] Add check for duplicates to make_cxx_dr_status script (PR #67969)

2023-10-02 Thread Vlad Serebrennikov via cfe-commits


@@ -7145,7 +7145,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1223.html";>1223
 drafting
 Syntactic disambiguation and trailing-return-types
-Not resolved
+Clang 17

Endilll wrote:

`make_cxx_dr_status` is not yet updated to know that 17 has been released. I'll 
address it in a separate PR.

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


[PATCH] D140828: [C++] Implement "Deducing this" (P0847R7)

2023-10-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Accepting as-is; we'll keep our eyes peeled for any post-commit feedback.

Thank you for all the hard work on this one, it was a big, involved patch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140828

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


[clang] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers (PR #67212)

2023-10-02 Thread via cfe-commits

vabridgers wrote:

Hey guys, is it ok to merge this fix? Thanks

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


[clang] [MLIR][NVGPU] Introduce `nvgpu.wargroup.mma.store` Op for Hopper GPUs (PR #65441)

2023-10-02 Thread Guray Ozen via cfe-commits

https://github.com/grypp updated https://github.com/llvm/llvm-project/pull/65441

>From 7b71da55fca8fe2a7dbe4982b1959be6a6175fa1 Mon Sep 17 00:00:00 2001
From: Guray Ozen 
Date: Thu, 7 Sep 2023 11:52:38 +0200
Subject: [PATCH 1/7] [MLIR][NVGPU] Introduce `nvgpu.warpgroup.mma.store` Op
 for Hopper GPUs

This work introduces a new operation called `warpgroup.mma.store` to the NVGPU 
dialect of MLIR. The purpose of this operation is to facilitate storing 
fragmanted results of WGMMA to the given memref.

An example of fragmentation is given here :
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#wgmma-64n16-d

The `warpgroup.mma.store` does followings:
1) Takes one or more fragmented results matrix.
2) Calculates indexes per thread in warp group and stores the data into give 
memref.

Here's an example usage of the `nvgpu.warpgroup.mma` operation:
```
// Performs matmul, results are fragmented and in registers
%res, %res2 = nvgpu.warpgroup.mma ...

// Stores the fragmented result to the give memory
nvgpu.warpgroup.mma.store [%res1, %res2], %matrixD :
!nvgpu.warpgroup.result>,
!nvgpu.warpgroup.result>
to memref<128x128xf32,3>
```

Depends on #65440
---
 mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td   | 19 +
 .../Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp| 83 ++-
 mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp| 29 +++
 3 files changed, 129 insertions(+), 2 deletions(-)

diff --git a/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td 
b/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td
index 90381648dac6acc..e102ae0dc581013 100644
--- a/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td
+++ b/mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td
@@ -721,4 +721,23 @@ def NVGPU_WarpgroupMmaOp : NVGPU_Op<"warpgroup.mma"> {
   let hasVerifier = 1;
 }
 
+def NVGPU_WarpgroupMmaStoreOp : NVGPU_Op<"warpgroup.mma.store"> {
+  let description = [{
+The `nvgpu.warpgroup.mma.store` op performs the store of fragmented result 
+in $matrixD to give memref. 
+
+[See the details of register fragment layout for accumulator matrix 
D](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#wgmma-64n16-d)
 
+
+Note that, the op must be run with warp group.
+  }];
+
+  let arguments = (ins Variadic:$matrixD,
+   Arg:$dstMemref);
+  
+  let assemblyFormat = [{
+`[` $matrixD `]` `,` $dstMemref attr-dict `:` type($matrixD) `to` 
type($dstMemref)
+  }];
+  let hasVerifier = 1;
+}
+
 #endif // NVGPU
diff --git a/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp 
b/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
index f74aa05c0c4c4ff..4f1a0bc651e81b7 100644
--- a/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
+++ b/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
@@ -11,6 +11,7 @@
 #include "mlir/Conversion/GPUCommon/GPUCommonPass.h"
 #include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
 #include "mlir/Conversion/LLVMCommon/Pattern.h"
+#include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
@@ -409,8 +410,8 @@ struct ConvertNVGPUToNVVMPass
   using Base::Base;
 
   void getDependentDialects(DialectRegistry ®istry) const override {
-registry
-.insert();
+registry.insert();
   }
 
   void runOnOperation() override {
@@ -451,6 +452,7 @@ struct ConvertNVGPUToNVVMPass
 populateNVGPUToNVVMConversionPatterns(converter, patterns);
 LLVMConversionTarget target(getContext());
 target.addLegalDialect<::mlir::LLVM::LLVMDialect>();
+target.addLegalDialect<::mlir::arith::ArithDialect>();
 target.addLegalDialect<::mlir::memref::MemRefDialect>();
 target.addLegalDialect<::mlir::NVVM::NVVMDialect>();
 mlir::scf::populateSCFStructuralTypeConversionsAndLegality(
@@ -1299,11 +1301,88 @@ struct NVGPUWarpgroupMmaOpLowering
   }
 };
 
+struct NVGPUWarpgroupMmaStoreOpLowering
+: public ConvertOpToLLVMPattern {
+  using ConvertOpToLLVMPattern<
+  nvgpu::WarpgroupMmaStoreOp>::ConvertOpToLLVMPattern;
+
+  void storeFragmentedMatrix(Value wgmmaResult, nvgpu::WarpgroupMmaStoreOp op,
+ OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter,
+ int offset) const {
+Location loc = op->getLoc();
+Type i32 = rewriter.getI32Type();
+
+auto makeConst = [&](int32_t index) -> Value {
+  return rewriter.create(
+  loc, i32, rewriter.getI32IntegerAttr(index));
+};
+Value c4 = makeConst(4);
+Value c32 = makeConst(kWarpSize);
+Value c8 = makeConst(8);
+Value c2 = makeConst(2);
+Value c1 = makeConst(1);
+Value c16 = makeConst(16);
+
+auto makeMul = [&](Value lhs, Value rhs) -> Value {
+  return rewriter.create(loc, lhs.getType(), lhs, rhs);
+};
+auto makeAdd = [&](Value lhs, Value rhs) -> Value {
+  return rewriter.create(loc, lhs.getType(), lhs, rhs)

[clang] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers (PR #67212)

2023-10-02 Thread via cfe-commits

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

It's simple and clean, let's just merge it :)

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

ktf wrote:

I also noticed that LoadedSLocEntryTable uses 42 elements tables, which 
probably introduces some extra divisions to do the indexing. I can try 
switching to 32 elements.

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


[clang] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers (PR #67212)

2023-10-02 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Please be sure to add a release note about the fix, too!

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


[clang] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers (PR #67212)

2023-10-02 Thread Aaron Ballman via cfe-commits

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


[clang] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers (PR #67212)

2023-10-02 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.portability.UnixAPI \
+// RUN:-triple x86_64-pc-linux-gnu -x c %s
+
+// Don't crash!
+// expected-no-diagnostics
+const __int128_t a = ( (__int128_t)1 << 64 );

AaronBallman wrote:

It'd be good to add a test case using `_BitInt(72)` or something along those 
lines to ensure we handle that properly as well.

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


[clang] [analyzer] Remove inaccurate legacy handling of bad bitwise shifts (PR #66647)

2023-10-02 Thread via cfe-commits

DonatNagyE wrote:

This commit accidentally left behind two unused functions; thanks 
@kazutakahirata for quickly fixing my mistake!

https://github.com/llvm/llvm-project/pull/66647
___
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-10-02 Thread via cfe-commits

mikaelholmen wrote:

Hi @vgvassilev !
Compiling this with gcc we see lots of warnings like
`
../include/llvm/ADT/PagedVector.h:213:59: warning: friend declaration 'bool 
llvm::operator==(const llvm::PagedVector::MaterializedIterator&, 
const llvm::PagedVector::MaterializedIterator&)' declares a 
non-template function [-Wnon-template-friend]
  213 |MaterializedIterator const &RHS);
  |   ^
../include/llvm/ADT/PagedVector.h:213:59: note: (if this is not what you 
intended, make sure the function template has already been declared and add <> 
after the function name here) 
../include/llvm/ADT/PagedVector.h:215:59: warning: friend declaration 'bool 
llvm::operator!=(const llvm::PagedVector::MaterializedIterator&, 
const llvm::PagedVector::MaterializedIterator&)' declares a 
non-template function [-Wnon-template-friend]
  215 |MaterializedIterator const &RHS);
  |
`
Anything that could/should be fixed even if clang seems to not bother?

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] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-02 Thread Endre Fülöp via cfe-commits

https://github.com/gamesh411 updated 
https://github.com/llvm/llvm-project/pull/67663

From 9f7f577c95d7e9fb7e2f929215ff217ca2d7ed53 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= 
Date: Fri, 8 Sep 2023 14:20:00 +0200
Subject: [PATCH 1/7] [analyzer][clangsa] Add new option to
 alpha.security.cert.InvalidPtrChecker

The invalidation of pointer pointers returned by subsequent calls to genenv is
suggested by the POSIX standard, but is too strict from a practical point of
view. A new checker option 'InvalidatingGetEnv' is introduced, and is set to a
more lax default value, which does not consider consecutive getenv calls
invalidating.
The handling of the main function's possible specification where an environment
pointer is also pecified as a third parameter is also considered now.

Differential Revision: https://reviews.llvm.org/D154603
---
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  9 ++
 .../Checkers/cert/InvalidPtrChecker.cpp   | 86 ++-
 clang/test/Analysis/analyzer-config.c |  1 +
 .../Analysis/cert/env34-c-cert-examples.c | 40 -
 clang/test/Analysis/cert/env34-c.c|  1 +
 clang/test/Analysis/invalid-ptr-checker.c | 50 +++
 6 files changed, 163 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/Analysis/invalid-ptr-checker.c

diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 65c1595eb6245dd..b4f65c934bf483b 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -997,6 +997,15 @@ let ParentPackage = ENV in {
 
   def InvalidPtrChecker : Checker<"InvalidPtr">,
   HelpText<"Finds usages of possibly invalidated pointers">,
+  CheckerOptions<[
+CmdLineOption,
+  ]>,
   Documentation;
 
 } // end "alpha.cert.env"
diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index aae1a17bc0ae53e..8849eb1148564b7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -38,6 +38,15 @@ class InvalidPtrChecker
 CheckerContext &C) const;
 
   // SEI CERT ENV31-C
+
+  // If set to true, consider getenv calls as invalidating operations on the
+  // environment variable buffer. This is implied in the standard, but in
+  // practice does not cause problems (in the commonly used environments).
+  bool InvalidatingGetEnv = false;
+
+  // GetEnv can be treated invalidating and non-invalidating as well.
+  const CallDescription GetEnvCall{{"getenv"}, 1};
+
   const CallDescriptionMap EnvpInvalidatingFunctions = {
   {{{"setenv"}, 3}, &InvalidPtrChecker::EnvpInvalidatingCall},
   {{{"unsetenv"}, 1}, &InvalidPtrChecker::EnvpInvalidatingCall},
@@ -51,7 +60,6 @@ class InvalidPtrChecker
 
   // SEI CERT ENV34-C
   const CallDescriptionMap PreviousCallInvalidatingFunctions = {
-  {{{"getenv"}, 1}, 
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{{"setlocale"}, 2},
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{{"strerror"}, 1},
@@ -62,6 +70,10 @@ class InvalidPtrChecker
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   };
 
+  // The private members of this checker corresponding to commandline options
+  // are set in this function.
+  friend void ento::registerInvalidPtrChecker(CheckerManager &);
+
 public:
   // Obtain the environment pointer from 'main()' (if present).
   void checkBeginFunction(CheckerContext &C) const;
@@ -84,7 +96,10 @@ class InvalidPtrChecker
 REGISTER_SET_WITH_PROGRAMSTATE(InvalidMemoryRegions, const MemRegion *)
 
 // Stores the region of the environment pointer of 'main' (if present).
-REGISTER_TRAIT_WITH_PROGRAMSTATE(EnvPtrRegion, const MemRegion *)
+REGISTER_TRAIT_WITH_PROGRAMSTATE(MainEnvPtrRegion, const MemRegion *)
+
+// Stores the regions of environments returned by getenv calls.
+REGISTER_SET_WITH_PROGRAMSTATE(GetenvEnvPtrRegions, const MemRegion *)
 
 // Stores key-value pairs, where key is function declaration and value is
 // pointer to memory region returned by previous call of this function
@@ -95,22 +110,35 @@ void InvalidPtrChecker::EnvpInvalidatingCall(const 
CallEvent &Call,
  CheckerContext &C) const {
   StringRef FunctionName = Call.getCalleeIdentifier()->getName();
   ProgramStateRef State = C.getState();
-  const MemRegion *SymbolicEnvPtrRegion = State->get();
-  if (!SymbolicEnvPtrRegion)
-return;
 
-  State = State->add(SymbolicEnvPtrRegion);
+  auto PlaceInvalidationNote = [&C, FunctionName,
+&State](const MemRegion *Region,
+StringRef Message, ExplodedNode *Pred) 
{
+State = State->add(Region);
+
+// Make cop

[clang] [clang] remove ClassScopeFunctionSpecializationDecl (PR #66636)

2023-10-02 Thread Aaron Ballman via cfe-commits


@@ -9354,13 +9353,14 @@ 
Sema::CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
   }
   F.done();
 
+  bool isFriend = FD->getFriendObjectKind() != Decl::FOK_None;

AaronBallman wrote:

```suggestion
  bool IsFriend = FD->getFriendObjectKind() != Decl::FOK_None;
```
nit for naming style.

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


[clang-tools-extra] [clang] remove ClassScopeFunctionSpecializationDecl (PR #66636)

2023-10-02 Thread Aaron Ballman via cfe-commits


@@ -1481,10 +1481,6 @@ enum DeclCode {
   /// template template parameter pack.
   DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK,
 
-  /// A ClassScopeFunctionSpecializationDecl record a class scope
-  /// function specialization. (Microsoft extension).
-  DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION,

AaronBallman wrote:

I verify that we already bumped the AST serialization version number, so older 
serialized code should no longer expect to deserialize.

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


[clang] [clang] remove ClassScopeFunctionSpecializationDecl (PR #66636)

2023-10-02 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

The changes should definitely have a release note so that downstreams can be 
aware of the changes. This isn't really a potentially breaking change, but we 
should alert clang-vendors in case a downstream actually cares.

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


[clang] [clang] remove ClassScopeFunctionSpecializationDecl (PR #66636)

2023-10-02 Thread Aaron Ballman via cfe-commits


@@ -752,8 +745,6 @@ class CollectExtraHighlightings
 }
 if (auto *Args = D->getTemplateSpecializationArgsAsWritten())
   H.addAngleBracketTokens(Args->getLAngleLoc(), Args->getRAngleLoc());
-if (auto *I = D->getDependentSpecializationInfo())
-  H.addAngleBracketTokens(I->getLAngleLoc(), I->getRAngleLoc());

AaronBallman wrote:

Can you explain why this was removed?

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


[clang-tools-extra] [clang] remove ClassScopeFunctionSpecializationDecl (PR #66636)

2023-10-02 Thread Aaron Ballman via cfe-commits


@@ -2154,6 +2144,15 @@ bool 
RecursiveASTVisitor::TraverseFunctionHelper(FunctionDecl *D) {
   TALI->NumTemplateArgs));
   }
 }
+// FIXME: Do we want to traverse the explicit template arguments for

AaronBallman wrote:

Agreed, I think we should remove the FIXME and do the traversal.

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


[clang] [clang] remove ClassScopeFunctionSpecializationDecl (PR #66636)

2023-10-02 Thread Aaron Ballman via cfe-commits


@@ -10442,32 +10441,54 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator 
&D, DeclContext *DC,
 if (getLangOpts().CUDA && !isFunctionTemplateSpecialization)
   maybeAddCUDAHostDeviceAttrs(NewFD, Previous);
 
-// If it's a friend (and only if it's a friend), it's possible
-// that either the specialized function type or the specialized
-// template is dependent, and therefore matching will fail.  In
-// this case, don't check the specialization yet.
-if (isFunctionTemplateSpecialization && isFriend &&
-(NewFD->getType()->isDependentType() || DC->isDependentContext() ||
- 
TemplateSpecializationType::anyInstantiationDependentTemplateArguments(
- TemplateArgs.arguments( {
-  assert(HasExplicitTemplateArgs &&
- "friend function specialization without template args");
-  if (CheckDependentFunctionTemplateSpecialization(NewFD, TemplateArgs,
-   Previous))
-NewFD->setInvalidDecl();
-} else if (isFunctionTemplateSpecialization) {
-  if (CurContext->isDependentContext() && CurContext->isRecord()
-  && !isFriend) {
-isDependentClassScopeExplicitSpecialization = true;
-  } else if (!NewFD->isInvalidDecl() &&
- CheckFunctionTemplateSpecialization(
- NewFD, (HasExplicitTemplateArgs ? &TemplateArgs : 
nullptr),
- Previous))
-NewFD->setInvalidDecl();
+// Handle explict specializations of function templates
+// and friend function declarations with an explicit
+// template argument list.
+if (isFunctionTemplateSpecialization) {
+  bool isDependentSpecialization = false;
+  if (isFriend) {
+// For friend function specializations, this is a dependent
+// specialization if its semantic context is dependent, its
+// type is dependent, or if its template-id is dependent.
+isDependentSpecialization =
+DC->isDependentContext() || NewFD->getType()->isDependentType() ||
+(HasExplicitTemplateArgs &&
+ TemplateSpecializationType::
+ anyInstantiationDependentTemplateArguments(
+ TemplateArgs.arguments()));
+assert(!isDependentSpecialization ||
+   (HasExplicitTemplateArgs == isDependentSpecialization) &&
+   "dependent friend function specialization without template "
+   "args");
+  } else {
+// For class-scope explicit specializations of function templates,
+// if the lexical context is dependent, then the specialization
+// is dependent.
+isDependentSpecialization =
+CurContext->isRecord() && CurContext->isDependentContext();
+  }
+
+  TemplateArgumentListInfo *ExplicitTemplateArgs =
+  HasExplicitTemplateArgs ? &TemplateArgs : nullptr;
+  if (isDependentSpecialization) {
+// If it's a dependent specialization, it may not be possible
+// to determine the primary template (for explicit specializations)
+// or befriended declaration (for friends) until the enclosing
+// template is instantiated. In such cases, we store the declarations
+// found by name lookup and defer resolution until instantiation.
+if (CheckDependentFunctionTemplateSpecialization(
+NewFD, ExplicitTemplateArgs, Previous))
+  NewFD->setInvalidDecl();
+  } else if (!NewFD->isInvalidDecl()) {
+if (CheckFunctionTemplateSpecialization(NewFD, ExplicitTemplateArgs,
+Previous))
+  NewFD->setInvalidDecl();
+  }
 
   // C++ [dcl.stc]p1:
   //   A storage-class-specifier shall not be specified in an explicit
   //   specialization (14.7.3)
+  // FIXME: We should be checking this for dependent specializations.

AaronBallman wrote:

Can you be sure to file an issue or add a test case + FIXME comment so we don't 
lose track of the needed follow-up work, or are you planning to do that work 
immediately after this lands?

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


[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-02 Thread Endre Fülöp via cfe-commits


@@ -2399,13 +2399,34 @@ pointer. These functions include: getenv, localeconv, 
asctime, setlocale, strerr
 char *p, *pp;
 
 p = getenv("VAR");
-pp = getenv("VAR2");
-// subsequent call to 'getenv' invalidated previous one
+setenv("SOMEVAR", "VALUE", /*overwrite*/1);

gamesh411 wrote:

fixed in 5e2d77aa0c14ee8695bcde55b68daa22ccb84a1b

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


[clang-tools-extra] [clang] remove ClassScopeFunctionSpecializationDecl (PR #66636)

2023-10-02 Thread Aaron Ballman via cfe-commits

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


[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-02 Thread Endre Fülöp via cfe-commits


@@ -2399,13 +2399,34 @@ pointer. These functions include: getenv, localeconv, 
asctime, setlocale, strerr
 char *p, *pp;
 
 p = getenv("VAR");
-pp = getenv("VAR2");
-// subsequent call to 'getenv' invalidated previous one
+setenv("SOMEVAR", "VALUE", /*overwrite*/1);
+// call to 'setenv' may invalidate p
 
 *p;
 // dereferencing invalid pointer
   }
 
+
+The ``InvalidatingGetEnv`` option is available for treating getenv calls as
+invalidating. When enabled, the checker issues a warning if getenv is called
+multiple times and their results are used without first creating a copy.
+This level of strictness might be considered overly pedantic for a standard
+getenv implementation.

gamesh411 wrote:

fixed as well (5e2d77aa0c14ee8695bcde55b68daa22ccb84a1b)

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


[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-02 Thread Endre Fülöp via cfe-commits


@@ -25,19 +25,36 @@
 using namespace clang;
 using namespace ento;
 
+
 namespace {
 
+
 class InvalidPtrChecker
 : public Checker {
 private:
-  BugType BT{this, "Use of invalidated pointer", categories::MemoryError};
+  static const BugType *InvalidPtrBugType;
+  // For accurate emission of NoteTags, the BugType of this checker should have
+  // a unique address.
+  void InitInvalidPtrBugType() {
+InvalidPtrBugType = new BugType(this, "Use of invalidated pointer",
+categories::MemoryError);
+  }

gamesh411 wrote:

incorporated this in 190d2409b89147b8c2c9c2e8d0f96ec07df9e3fc

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


[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-02 Thread Endre Fülöp via cfe-commits


@@ -146,16 +188,15 @@ void 
InvalidPtrChecker::postPreviousReturnInvalidatingCall(
 
   // Remember to this region.
   const auto *SymRegOfRetVal = cast(RetVal.getAsRegion());
-  const MemRegion *MR =
-  const_cast(SymRegOfRetVal->getBaseRegion());
+  const MemRegion *MR = SymRegOfRetVal->getBaseRegion();
   State = State->set(FD, MR);
 
   ExplodedNode *Node = C.addTransition(State, Note);
   const NoteTag *PreviousCallNote =
   C.getNoteTag([MR](PathSensitiveBugReport &BR, llvm::raw_ostream &Out) {
-if (!BR.isInteresting(MR))
+if (!BR.isInteresting(MR) || &BR.getBugType() != InvalidPtrBugType)
   return;
-Out << '\'' << "'previous function call was here" << '\'';
+Out << "'previous function call was here" << '\'';

gamesh411 wrote:

fixed in fd4dab0a486c95642905582e94e50f0743d2a6a2

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


[PATCH] D156565: Diagnose use of VLAs in C++ by default

2023-10-02 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

Overall looks good, just a few nits from looking things over.




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:143
+def ext_vla_cxx : ExtWarn<
+  "variable length arrays are a Clang extension">, InGroup;
+def ext_vla_cxx_in_gnu_mode : Extension,

Clarify text: "variable length arrays in C++ are a Clang extension" and same 
below.

I also think we should be (consistently) using the term "variable-length array" 
with a dash instead of "variable length array", but if you change that, it 
should be in a follow-on which changes it in all the messages.



Comment at: clang/lib/Sema/SemaType.cpp:2617
+  } else if (getLangOpts().CPlusPlus) {
+if (getLangOpts().CPlusPlus11 && IsStaticAssertLike(ArraySize, Context))
+  VLADiag = getLangOpts().GNUMode

Not sure whether to actually care, since C++98 is so old now, but, having 
`-Wno-vla-extension-static-assert` work in C++98 mode seems like it'd be quite 
useful, exactly because the usage cannot trivially be replaced by a 
static_assert. So it's a bit unfortunate that we don't distinguish it there.

Perhaps we should emit the same diagnostics in both 98/11, but with slightly 
different text in 98?



Comment at: clang/test/CXX/dcl.dcl/dcl.spec/dcl.typedef/p2-0x.cpp:39
+  using T = int[n]; // expected-error {{variable length array declaration not 
allowed at file scope}} \
+   expected-warning {{variable length arrays are a Clang 
extension}} \
+   expected-note {{read of non-const variable 'n' is not 
allowed in a constant expression}}

That we get a warning _and_ an error for this using statement now is non-ideal. 
I see that we are doing this in two different places, though...first in 
CheckType for the VLA, then diagnosing if it's used at file scope in CheckDecl. 
So maybe not worth fixing.




Comment at: clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp:124
+  typedef int arr[strcmp("bar", "foo") + 4 * strncmp("foo", "bar", 4)]; // 
expected-warning {{variable length array folded to constant array as an 
extension}} \
+   
expected-warning {{variable length arrays are a Clang extension}} \
+   
expected-note {{non-constexpr function 'strcmp' cannot be used in a constant 
expression}}

Another unfortunate case, similar to the error case earlier, of BOTH warning 
about about it being a variable-length but then also warning about it actually 
being constant array as an extension.



Comment at: clang/test/SemaCXX/offsetof.cpp:31
+  int array1[__builtin_offsetof(HasArray, array[i])]; // expected-warning 
{{variable length arrays are a Clang extension}} \
+ new-interp-note 
{{function parameter 'i' with unknown value cannot be used in a constant 
expression}}
 }

Weird that new-interp adds the diagnostic for C++98 mode. I wonder if that 
indicates a bug (e.g. if in new-interp we accidentally use C++11 rules for 
C++98)?



Comment at: clang/test/SemaCXX/vla-ext-diag.cpp:13
+
+// FIXME: it's not clear why C++98 mode does not emit the extra notes in the
+// same way that C++11 mode does.

I think this is "expected" due to the divergence between the use of the 
constant-expression evaluation in C++11-and-later and "ICE" code in previous.


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

https://reviews.llvm.org/D156565

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

ktf wrote:

@mikaelholmen see also https://github.com/llvm/llvm-project/pull/67958. I can't 
seem to create a version that avoids triggering the warning and is also 
compatible across both macOS and Windows. Some good idea would be appreciated, 
especially because I do not have a windows setup and godbolt does not seem to 
like LLVM as an external package.

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][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)

2023-10-02 Thread Nico Weber via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


nico wrote:

Still broken: http://45.33.8.238/win/84419/step_4.txt

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


[clang] [clang] remove ClassScopeFunctionSpecializationDecl (PR #66636)

2023-10-02 Thread Krystian Stasiowski via cfe-commits


@@ -752,8 +745,6 @@ class CollectExtraHighlightings
 }
 if (auto *Args = D->getTemplateSpecializationArgsAsWritten())
   H.addAngleBracketTokens(Args->getLAngleLoc(), Args->getRAngleLoc());
-if (auto *I = D->getDependentSpecializationInfo())
-  H.addAngleBracketTokens(I->getLAngleLoc(), I->getRAngleLoc());

sdkrystian wrote:

@AaronBallman With this patch we store the template arguments as written in 
`DependentFunctionTemplateSpecializationInfo::TemplateArgsAsWritten`, and 
`FunctionDecl::getTemplateSpecializationArgsAsWritten` is updated to return the 
stored `ASTTemplateArgumentListInfo`. Therefore, the two lines above handle the 
arguments list for dependent function template specializations.

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


[clang] [clang] remove ClassScopeFunctionSpecializationDecl (PR #66636)

2023-10-02 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

@AaronBallman 
> Can you be sure to file an issue or add a test case + FIXME comment so we 
> don't lose track of the needed follow-up work, or are you planning to do that 
> work immediately after this lands?

I will address that once this gets merged

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


[PATCH] D159497: [RFC][clangd] Check if SelectionTree is complete

2023-10-02 Thread Kugan Vivekanandarajah via Phabricator via cfe-commits
kuganv added a comment.

ping? Any thoughts. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159497

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


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

2023-10-02 Thread antoine moynault via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


antmox wrote:

Hello,
Looks like this also broke lldb-aarch64-windows bot:
https://lab.llvm.org/buildbot/#/builders/219/builds/6012 ... 
https://lab.llvm.org/buildbot/#/builders/219/builds/6041


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


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

2023-10-02 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Sigh, will push a fix as soon as my local build is done.

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


[clang] [clang] remove ClassScopeFunctionSpecializationDecl (PR #66636)

2023-10-02 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

CC @llvm/clang-vendors for awareness of the AST changing to remove a node.

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


[clang-tools-extra] [MLIR][Presburger] Fix reduction of Fractions and add tests (PR #67382)

2023-10-02 Thread via cfe-commits

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


[clang] [MLIR][Presburger] Fix reduction of Fractions and add tests (PR #67382)

2023-10-02 Thread via cfe-commits

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


[clang-tools-extra] [MLIR][Presburger] Fix reduction of Fractions and add tests (PR #67382)

2023-10-02 Thread via cfe-commits

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


[clang] [MLIR][Presburger] Fix reduction of Fractions and add tests (PR #67382)

2023-10-02 Thread via cfe-commits

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


[clang] [Clang] Fix HIP wrapper inclusion of 'algorithm' when using libc++ (PR #67981)

2023-10-02 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/67981

Summary:
The `algorithm` header included here sometimes caused issues when using
`libc++` over `libstdc++`. This was primarily because  of the order they
were included in. This patch just gets rid of this dependency as it was
only used for min and max which are trivial to reimplement.


>From 9a74030bdec5cade2a13ba5e260a22e61ebae5f8 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Mon, 2 Oct 2023 07:25:03 -0500
Subject: [PATCH] [Clang] Fix HIP wrapper inclusion of 'algorithm' when using
 libc++

Summary:
The `algorithm` header included here sometimes caused issues when using
`libc++` over `libstdc++`. This was primarily because  of the order they
were included in. This patch just gets rid of this dependency as it was
only used for min and max which are trivial to reimplement.
---
 clang/lib/Headers/__clang_hip_math.h | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index 58aa55d74769031..11e1e7d032586f8 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -14,9 +14,6 @@
 #endif
 
 #if !defined(__HIPCC_RTC__)
-#if defined(__cplusplus)
-#include 
-#endif
 #include 
 #include 
 #ifdef __OPENMP_AMDGCN__
@@ -1311,11 +1308,11 @@ double min(double __x, double __y) { return 
__builtin_fmin(__x, __y); }
 
 #if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
 __host__ inline static int min(int __arg1, int __arg2) {
-  return std::min(__arg1, __arg2);
+  return __arg1 < __arg2 ? __arg1 : __arg2;
 }
 
 __host__ inline static int max(int __arg1, int __arg2) {
-  return std::max(__arg1, __arg2);
+  return __arg1 > __arg2 ? __arg1 : __arg2;
 }
 #endif // !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
 #endif

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


[clang] [Clang] Fix HIP wrapper inclusion of 'algorithm' when using libc++ (PR #67981)

2023-10-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

Summary:
The `algorithm` header included here sometimes caused issues when using
`libc++` over `libstdc++`. This was primarily because  of the order they
were included in. This patch just gets rid of this dependency as it was
only used for min and max which are trivial to reimplement.


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


1 Files Affected:

- (modified) clang/lib/Headers/__clang_hip_math.h (+2-5) 


``diff
diff --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index 58aa55d74769031..11e1e7d032586f8 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -14,9 +14,6 @@
 #endif
 
 #if !defined(__HIPCC_RTC__)
-#if defined(__cplusplus)
-#include 
-#endif
 #include 
 #include 
 #ifdef __OPENMP_AMDGCN__
@@ -1311,11 +1308,11 @@ double min(double __x, double __y) { return 
__builtin_fmin(__x, __y); }
 
 #if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
 __host__ inline static int min(int __arg1, int __arg2) {
-  return std::min(__arg1, __arg2);
+  return __arg1 < __arg2 ? __arg1 : __arg2;
 }
 
 __host__ inline static int max(int __arg1, int __arg2) {
-  return std::max(__arg1, __arg2);
+  return __arg1 > __arg2 ? __arg1 : __arg2;
 }
 #endif // !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
 #endif

``




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


[clang] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers (PR #67212)

2023-10-02 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/67212

>From ccf65544918f48800799dea2993168a5a29e11ba Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Sat, 23 Sep 2023 01:26:14 +0200
Subject: [PATCH] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t
 integers

This change avoids a crash in BasicValueFactory by checking the bit
width of an APSInt to avoid calling getZExtValue if greater than
64-bits.

Clang invocation
clang -cc1 -analyzer-checker=optin.portability.UnixAPI case.c

/llvm/include/llvm/ADT/APInt.h:1488:
uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64
  && "Too many bits for uint64_t"' failed.
...

 #9  llvm::APInt::getZExtValue() const
 /llvm/include/llvm/ADT/APInt.h:1488:5
 clang::BinaryOperatorKind, llvm::APSInt const&, llvm::APSInt const&)
 /clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:307:37
 llvm::IntrusiveRefCntPtr,
 clang::BinaryOperatorKind, clang::ento::NonLoc, clang::ento::NonLoc,
 clang::QualType)
 /clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:531:31
 llvm::IntrusiveRefCntPtr,
 clang::BinaryOperatorKind, clang::ento::SVal, clang::ento::SVal,
 clang::QualType)
 /clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:532:26
...
---
 .../lib/StaticAnalyzer/Core/BasicValueFactory.cpp |  4 ++--
 clang/test/Analysis/int128-nocrash.c  | 15 +++
 llvm/docs/ReleaseNotes.rst|  8 
 3 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Analysis/int128-nocrash.c

diff --git a/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp 
b/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
index e8d74b40c6fd846..5c10e757244d7fb 100644
--- a/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
@@ -272,7 +272,7 @@ BasicValueFactory::evalAPSInt(BinaryOperator::Opcode Op,
   // FIXME: This logic should probably go higher up, where we can
   // test these conditions symbolically.
 
-  if (V2.isSigned() && V2.isNegative())
+  if (V2.isNegative() || V2.getBitWidth() > 64)
 return nullptr;
 
   uint64_t Amt = V2.getZExtValue();
@@ -287,7 +287,7 @@ BasicValueFactory::evalAPSInt(BinaryOperator::Opcode Op,
   // FIXME: This logic should probably go higher up, where we can
   // test these conditions symbolically.
 
-  if (V2.isSigned() && V2.isNegative())
+  if (V2.isNegative() || V2.getBitWidth() > 64)
 return nullptr;
 
   uint64_t Amt = V2.getZExtValue();
diff --git a/clang/test/Analysis/int128-nocrash.c 
b/clang/test/Analysis/int128-nocrash.c
new file mode 100644
index 000..457254ce50caf03
--- /dev/null
+++ b/clang/test/Analysis/int128-nocrash.c
@@ -0,0 +1,15 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.portability.UnixAPI \
+// RUN:-triple x86_64-pc-linux-gnu -x c %s
+
+// Don't crash!
+// expected-no-diagnostics
+const __int128_t a = ( (__int128_t)1 << 64 );
+const _BitInt(72) b = ( 1 << 72 );
+
+void int128() {
+  2 >> a;
+}
+
+void withbitint() {
+  2 >> b;
+}
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 660bb4e70a5a707..203eb62191c281d 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -208,6 +208,14 @@ Other Changes
   fully stripped); :doc:`llvm-symbolizer ` can
   symbolize the markup afterwards using ``debuginfod``.
 
+* A few crashes have been found and fixed using randomized testing related
+  to the use of _BitInt() in tidy checks and in clang analysis. See
+  https://github.com/llvm/llvm-project/pull/67212,
+  https://github.com/llvm/llvm-project/pull/66782,
+  https://github.com/llvm/llvm-project/pull/65889,
+  https://github.com/llvm/llvm-project/pull/65888, and
+  https://github.com/llvm/llvm-project/pull/65887
+
 External Open Source Projects Using LLVM 15
 ===
 

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


[clang] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers (PR #67212)

2023-10-02 Thread via cfe-commits


@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.portability.UnixAPI \
+// RUN:-triple x86_64-pc-linux-gnu -x c %s
+
+// Don't crash!
+// expected-no-diagnostics
+const __int128_t a = ( (__int128_t)1 << 64 );

vabridgers wrote:

I added a test case. Let me know if you're ok with this. Thanks!

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


[clang] [Clang] Fix HIP wrapper inclusion of 'algorithm' when using libc++ (PR #67981)

2023-10-02 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/67981

>From 3ce25920eb83ed2e859050fd24dada7b232e0431 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Mon, 2 Oct 2023 07:25:03 -0500
Subject: [PATCH] [Clang] Fix HIP wrapper inclusion of 'algorithm' when using
 libc++

Summary:
The `algorithm` header included here sometimes caused issues when using
`libc++` over `libstdc++`. This was primarily because  of the order they
were included in. This patch just gets rid of this dependency as it was
only used for min and max which are trivial to reimplement.

Fixes: https://github.com/llvm/llvm-project/issues/67938
---
 clang/lib/Headers/__clang_hip_math.h | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index 58aa55d74769031..11e1e7d032586f8 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -14,9 +14,6 @@
 #endif
 
 #if !defined(__HIPCC_RTC__)
-#if defined(__cplusplus)
-#include 
-#endif
 #include 
 #include 
 #ifdef __OPENMP_AMDGCN__
@@ -1311,11 +1308,11 @@ double min(double __x, double __y) { return 
__builtin_fmin(__x, __y); }
 
 #if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
 __host__ inline static int min(int __arg1, int __arg2) {
-  return std::min(__arg1, __arg2);
+  return __arg1 < __arg2 ? __arg1 : __arg2;
 }
 
 __host__ inline static int max(int __arg1, int __arg2) {
-  return std::max(__arg1, __arg2);
+  return __arg1 > __arg2 ? __arg1 : __arg2;
 }
 #endif // !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
 #endif

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


[clang] [Clang] Fix HIP wrapper inclusion of 'algorithm' when using libc++ (PR #67981)

2023-10-02 Thread Joseph Huber via cfe-commits

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


[clang] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers (PR #67212)

2023-10-02 Thread via cfe-commits

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


[clang] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers (PR #67212)

2023-10-02 Thread via cfe-commits

vabridgers wrote:

I'll wait for an ok from @AaronBallman before merging. Thank you! 

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


  1   2   3   4   5   >