[PATCH] D137885: [modules] Support zstd in .pcm file

2022-11-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: aaron.ballman, jansvoboda11, rsmith.
Herald added a subscriber: StephenFan.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Extend SM_SLOC_BUFFER_BLOB_COMPRESSED to allow zstd, which is much faster
(compression/decompression) than zlib and has better compression ratio.

An alternative is to add a value beside SM_SLOC_BUFFER_BLOB_COMPRESSED, but
reusing SM_SLOC_BUFFER_BLOB_COMPRESSED slightly simplifies the implementation
and leads to better diagnostics when a slightly older Clang consumes zstd
compressed blob.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137885

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/embed-files-compressed.cpp


Index: clang/test/Modules/embed-files-compressed.cpp
===
--- clang/test/Modules/embed-files-compressed.cpp
+++ clang/test/Modules/embed-files-compressed.cpp
@@ -1,4 +1,4 @@
-// REQUIRES: zlib
+// REQUIRES: zlib || zstd
 // REQUIRES: shell
 //
 // RUN: rm -rf %t
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1980,6 +1980,14 @@
   // Compress the buffer if possible. We expect that almost all PCM
   // consumers will not want its contents.
   SmallVector CompressedBuffer;
+  if (llvm::compression::zstd::isAvailable()) {
+llvm::compression::zstd::compress(
+llvm::arrayRefFromStringRef(Blob.drop_back(1)), CompressedBuffer);
+RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, Blob.size() - 
1};
+Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
+  llvm::toStringRef(CompressedBuffer));
+return;
+  }
   if (llvm::compression::zlib::isAvailable()) {
 llvm::compression::zlib::compress(
 llvm::arrayRefFromStringRef(Blob.drop_back(1)), CompressedBuffer);
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1452,19 +1452,23 @@
 unsigned RecCode = MaybeRecCode.get();
 
 if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) {
-  if (!llvm::compression::zlib::isAvailable()) {
-Error("zlib is not available");
+  const llvm::compression::Format F =
+  Blob.size() >= 2 && memcmp(Blob.data(), "\x1f\x8b", 2) == 0
+  ? llvm::compression::Format::Zlib
+  : llvm::compression::Format::Zstd;
+  if (const char *Reason = llvm::compression::getReasonIfUnsupported(F)) {
+Error(Reason);
 return nullptr;
   }
-  SmallVector Uncompressed;
-  if (llvm::Error E = llvm::compression::zlib::decompress(
-  llvm::arrayRefFromStringRef(Blob), Uncompressed, Record[0])) {
+  SmallVector Decompressed;
+  if (llvm::Error E = llvm::compression::decompress(
+  F, llvm::arrayRefFromStringRef(Blob), Decompressed, Record[0])) {
 Error("could not decompress embedded file contents: " +
   llvm::toString(std::move(E)));
 return nullptr;
   }
   return llvm::MemoryBuffer::getMemBufferCopy(
-  llvm::toStringRef(Uncompressed), Name);
+  llvm::toStringRef(Decompressed), Name);
 } else if (RecCode == SM_SLOC_BUFFER_BLOB) {
   return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true);
 } else {


Index: clang/test/Modules/embed-files-compressed.cpp
===
--- clang/test/Modules/embed-files-compressed.cpp
+++ clang/test/Modules/embed-files-compressed.cpp
@@ -1,4 +1,4 @@
-// REQUIRES: zlib
+// REQUIRES: zlib || zstd
 // REQUIRES: shell
 //
 // RUN: rm -rf %t
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1980,6 +1980,14 @@
   // Compress the buffer if possible. We expect that almost all PCM
   // consumers will not want its contents.
   SmallVector CompressedBuffer;
+  if (llvm::compression::zstd::isAvailable()) {
+llvm::compression::zstd::compress(
+llvm::arrayRefFromStringRef(Blob.drop_back(1)), CompressedBuffer);
+RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, Blob.size() - 1};
+Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
+  llvm::toStringRef(CompressedBuffer));
+return;
+  }
   if (llvm::compression::zlib::isAvailable()) {
 llvm::compression::zlib::compress(
 llvm::arrayRefFromStringRef(Blob.drop_back(1)), CompressedBuffer);
Index: clang/lib/Serialization/ASTRead

[clang] 96e2390 - [clang-format] Correctly annotate function names before attributes

2022-11-12 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2022-11-12T00:40:46-08:00
New Revision: 96e23906b5e80dc86b5d2431d30c9afc38ae4d20

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

LOG: [clang-format] Correctly annotate function names before attributes

Fixes #58827.

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

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 f489b2c2ddb3c..e63818cfcd9ab 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -71,6 +71,38 @@ static bool isKeywordWithCondition(const FormatToken &Tok) {
  tok::kw_constexpr, tok::kw_catch);
 }
 
+/// Returns \c true if the token starts a C++ attribute, \c false otherwise.
+static bool isCppAttribute(bool IsCpp, const FormatToken &Tok) {
+  if (!IsCpp || !Tok.startsSequence(tok::l_square, tok::l_square))
+return false;
+  // The first square bracket is part of an ObjC array literal
+  if (Tok.Previous && Tok.Previous->is(tok::at))
+return false;
+  const FormatToken *AttrTok = Tok.Next->Next;
+  if (!AttrTok)
+return false;
+  // C++17 '[[using ns: foo, bar(baz, blech)]]'
+  // We assume nobody will name an ObjC variable 'using'.
+  if (AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon))
+return true;
+  if (AttrTok->isNot(tok::identifier))
+return false;
+  while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
+// ObjC message send. We assume nobody will use : in a C++11 attribute
+// specifier parameter, although this is technically valid:
+// [[foo(:)]].
+if (AttrTok->is(tok::colon) ||
+AttrTok->startsSequence(tok::identifier, tok::identifier) ||
+AttrTok->startsSequence(tok::r_paren, tok::identifier)) {
+  return false;
+}
+if (AttrTok->is(tok::ellipsis))
+  return true;
+AttrTok = AttrTok->Next;
+  }
+  return AttrTok && AttrTok->startsSequence(tok::r_square, tok::r_square);
+}
+
 /// A parser that gathers additional information about tokens.
 ///
 /// The \c TokenAnnotator tries to match parenthesis and square brakets and
@@ -538,34 +570,7 @@ class AnnotatingParser {
   }
 
   bool isCpp11AttributeSpecifier(const FormatToken &Tok) {
-if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
-  return false;
-// The first square bracket is part of an ObjC array literal
-if (Tok.Previous && Tok.Previous->is(tok::at))
-  return false;
-const FormatToken *AttrTok = Tok.Next->Next;
-if (!AttrTok)
-  return false;
-// C++17 '[[using ns: foo, bar(baz, blech)]]'
-// We assume nobody will name an ObjC variable 'using'.
-if (AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon))
-  return true;
-if (AttrTok->isNot(tok::identifier))
-  return false;
-while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
-  // ObjC message send. We assume nobody will use : in a C++11 attribute
-  // specifier parameter, although this is technically valid:
-  // [[foo(:)]].
-  if (AttrTok->is(tok::colon) ||
-  AttrTok->startsSequence(tok::identifier, tok::identifier) ||
-  AttrTok->startsSequence(tok::r_paren, tok::identifier)) {
-return false;
-  }
-  if (AttrTok->is(tok::ellipsis))
-return true;
-  AttrTok = AttrTok->Next;
-}
-return AttrTok && AttrTok->startsSequence(tok::r_square, tok::r_square);
+return isCppAttribute(Style.isCpp(), Tok);
   }
 
   bool parseSquare() {
@@ -2844,6 +2849,8 @@ static bool isFunctionDeclarationName(bool IsCpp, const 
FormatToken &Current,
 }
 if (!Next->is(tok::identifier))
   return false;
+  } else if (isCppAttribute(IsCpp, *Next)) {
+Next = Next->MatchingParen;
   } else if (Next->is(tok::l_paren)) {
 break;
   } else {

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 65ecb12c46cd7..477e78c9c19e8 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1047,6 +1047,16 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsFunctionAnnotations) {
   EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {
+  auto Tokens = annotate("void f [[noreturn]] ();");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("void f [[noreturn]] () {}");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOK

[PATCH] D137486: [clang-format] Correctly annotate function names before attributes

2022-11-12 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG96e23906b5e8: [clang-format] Correctly annotate function 
names before attributes (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137486

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

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1047,6 +1047,16 @@
   EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {
+  auto Tokens = annotate("void f [[noreturn]] ();");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("void f [[noreturn]] () {}");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   auto Annotate = [this](llvm::StringRef Code) {
 return annotate(Code, getLLVMStyle(FormatStyle::LK_Verilog));
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -71,6 +71,38 @@
  tok::kw_constexpr, tok::kw_catch);
 }
 
+/// Returns \c true if the token starts a C++ attribute, \c false otherwise.
+static bool isCppAttribute(bool IsCpp, const FormatToken &Tok) {
+  if (!IsCpp || !Tok.startsSequence(tok::l_square, tok::l_square))
+return false;
+  // The first square bracket is part of an ObjC array literal
+  if (Tok.Previous && Tok.Previous->is(tok::at))
+return false;
+  const FormatToken *AttrTok = Tok.Next->Next;
+  if (!AttrTok)
+return false;
+  // C++17 '[[using ns: foo, bar(baz, blech)]]'
+  // We assume nobody will name an ObjC variable 'using'.
+  if (AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon))
+return true;
+  if (AttrTok->isNot(tok::identifier))
+return false;
+  while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
+// ObjC message send. We assume nobody will use : in a C++11 attribute
+// specifier parameter, although this is technically valid:
+// [[foo(:)]].
+if (AttrTok->is(tok::colon) ||
+AttrTok->startsSequence(tok::identifier, tok::identifier) ||
+AttrTok->startsSequence(tok::r_paren, tok::identifier)) {
+  return false;
+}
+if (AttrTok->is(tok::ellipsis))
+  return true;
+AttrTok = AttrTok->Next;
+  }
+  return AttrTok && AttrTok->startsSequence(tok::r_square, tok::r_square);
+}
+
 /// A parser that gathers additional information about tokens.
 ///
 /// The \c TokenAnnotator tries to match parenthesis and square brakets and
@@ -538,34 +570,7 @@
   }
 
   bool isCpp11AttributeSpecifier(const FormatToken &Tok) {
-if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
-  return false;
-// The first square bracket is part of an ObjC array literal
-if (Tok.Previous && Tok.Previous->is(tok::at))
-  return false;
-const FormatToken *AttrTok = Tok.Next->Next;
-if (!AttrTok)
-  return false;
-// C++17 '[[using ns: foo, bar(baz, blech)]]'
-// We assume nobody will name an ObjC variable 'using'.
-if (AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon))
-  return true;
-if (AttrTok->isNot(tok::identifier))
-  return false;
-while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
-  // ObjC message send. We assume nobody will use : in a C++11 attribute
-  // specifier parameter, although this is technically valid:
-  // [[foo(:)]].
-  if (AttrTok->is(tok::colon) ||
-  AttrTok->startsSequence(tok::identifier, tok::identifier) ||
-  AttrTok->startsSequence(tok::r_paren, tok::identifier)) {
-return false;
-  }
-  if (AttrTok->is(tok::ellipsis))
-return true;
-  AttrTok = AttrTok->Next;
-}
-return AttrTok && AttrTok->startsSequence(tok::r_square, tok::r_square);
+return isCppAttribute(Style.isCpp(), Tok);
   }
 
   bool parseSquare() {
@@ -2844,6 +2849,8 @@
 }
 if (!Next->is(tok::identifier))
   return false;
+  } else if (isCppAttribute(IsCpp, *Next)) {
+Next = Next->MatchingParen;
   } else if (Next->is(tok::l_paren)) {
 break;
   } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137755: [clang-format] Treats &/&& as reference when followed by ',' or ')'.

2022-11-12 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe864ac694540: [clang-format] Treats &/&& as 
reference when followed by ',' or ')' (authored by 
red1bluelost, committed by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137755

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -157,6 +157,24 @@
   Tokens = annotate("if (Foo* Bar = getObj())");
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
+
+  Tokens = annotate("int f3() { return sizeof(Foo&); }");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("int f4() { return sizeof(Foo&&); }");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("void f5() { int f6(Foo&, Bar&); }");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[12], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("void f7() { int f8(Foo&&, Bar&&); }");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2132,6 +2132,10 @@
   verifyFormat("int *a = f1();", Style);
   verifyFormat("int &b = f2();", Style);
   verifyFormat("int &&c = f3();", Style);
+  verifyFormat("int f3() { return sizeof(Foo &); }", Style);
+  verifyFormat("int f4() { return sizeof(Foo &&); }", Style);
+  verifyFormat("void f5() { int f6(Foo &, Bar &); }", Style);
+  verifyFormat("void f5() { int f6(Foo &&, Bar &&); }", Style);
   verifyFormat("for (auto a = 0, b = 0; const auto &c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const int &c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const Foo &c : {1, 2, 3})", Style);
@@ -2171,6 +2175,10 @@
   verifyFormat("int* a = f1();", Style);
   verifyFormat("int& b = f2();", Style);
   verifyFormat("int&& c = f3();", Style);
+  verifyFormat("int f3() { return sizeof(Foo&); }", Style);
+  verifyFormat("int f4() { return sizeof(Foo&&); }", Style);
+  verifyFormat("void f5() { int f6(Foo&, Bar&); }", Style);
+  verifyFormat("void f5() { int f6(Foo&&, Bar&&); }", Style);
   verifyFormat("for (auto a = 0, b = 0; const auto& c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const int& c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const Foo& c : {1, 2, 3})", Style);
@@ -2211,6 +2219,10 @@
   verifyFormat("int *a = f1();", Style);
   verifyFormat("int& b = f2();", Style);
   verifyFormat("int&& c = f3();", Style);
+  verifyFormat("int f3() { return sizeof(Foo&); }", Style);
+  verifyFormat("int f4() { return sizeof(Foo&&); }", Style);
+  verifyFormat("void f5() { int f6(Foo&, Bar&); }", Style);
+  verifyFormat("void f5() { int f6(Foo&&, Bar&&); }", Style);
   verifyFormat("for (auto a = 0, b = 0; const Foo *c : {1, 2, 3})", Style);
   verifyFormat("for (int a = 0, b = 0; const Foo *c : {1, 2, 3})", Style);
   verifyFormat("for (int a = 0, b++; const Foo *c : {1, 2, 3})", Style);
@@ -2232,6 +2244,10 @@
   verifyFormat("int* a = f1();", Style);
   verifyFormat("int & b = f2();", Style);
   verifyFormat("int && c = f3();", Style);
+  verifyFormat("int f3() { return sizeof(Foo &); }", Style);
+  verifyFormat("int f4() { return sizeof(Foo &&); }", Style);
+  verifyFormat("void f5() { int f6(Foo &, Bar &); }", Style);
+  verifyFormat("void f5() { int f6(Foo &&, Bar &&); }", Style);
   verifyFormat("for (auto a = 0, b = 0; const auto & c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const int & c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const Foo & c : {1, 2, 3})", Style);
@@ -2268,6 +2284,10 @@
   verifyFormat("int * a = f1();", Style);
   verifyFormat("int &b = f2();", Style);
   verifyFormat("int &&c = f3();", Style);
+  verifyFormat("int f3() { return sizeof(Foo &); }", Style);
+  verifyFormat("int f4() { return sizeof(Foo &&); }", Style);
+  verifyFormat("void f5() { int f6(Foo &, Bar &); }", Style);
+  verifyFormat("void f5() { int f6(Foo &&, Bar &&); }", Style);
   verifyFormat("for (auto a = 0, b = 0; const F

[clang] e864ac6 - [clang-format] Treats &/&& as reference when followed by ',' or ')'

2022-11-12 Thread Owen Pan via cfe-commits

Author: Micah Weston
Date: 2022-11-12T00:58:58-08:00
New Revision: e864ac694540342d5e59f59c525c5082f2594fb8

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

LOG: [clang-format] Treats &/&& as reference when followed by ',' or ')'

Ran into an issue where function declarations inside function
scopes or uses of sizeof inside a function would treat the && in
'sizeof(Type &&)' as a binary operator.

Attempt to fix this by assuming reference when followed by ',' or
')'. Also adds tests for these.

Also hit an edge case in another test that treated "and" the same
as "&&" since it parses as C++. Changed the "and" to "also" so it
is no longer a keyword.

Fixes #58923.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index e63818cfcd9a..75570552146c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2356,7 +2356,8 @@ class AnnotatingParser {
   return TT_BinaryOperator;
 
 if (!NextToken ||
-NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_noexcept) ||
+NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_noexcept, 
tok::comma,
+   tok::r_paren) ||
 NextToken->canBePointerOrReferenceQualifier() ||
 (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment())) {
   return TT_PointerOrReference;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b6c3bda79358..0ff08d4d446d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2132,6 +2132,10 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
   verifyFormat("int *a = f1();", Style);
   verifyFormat("int &b = f2();", Style);
   verifyFormat("int &&c = f3();", Style);
+  verifyFormat("int f3() { return sizeof(Foo &); }", Style);
+  verifyFormat("int f4() { return sizeof(Foo &&); }", Style);
+  verifyFormat("void f5() { int f6(Foo &, Bar &); }", Style);
+  verifyFormat("void f5() { int f6(Foo &&, Bar &&); }", Style);
   verifyFormat("for (auto a = 0, b = 0; const auto &c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const int &c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const Foo &c : {1, 2, 3})", Style);
@@ -2171,6 +2175,10 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
   verifyFormat("int* a = f1();", Style);
   verifyFormat("int& b = f2();", Style);
   verifyFormat("int&& c = f3();", Style);
+  verifyFormat("int f3() { return sizeof(Foo&); }", Style);
+  verifyFormat("int f4() { return sizeof(Foo&&); }", Style);
+  verifyFormat("void f5() { int f6(Foo&, Bar&); }", Style);
+  verifyFormat("void f5() { int f6(Foo&&, Bar&&); }", Style);
   verifyFormat("for (auto a = 0, b = 0; const auto& c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const int& c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const Foo& c : {1, 2, 3})", Style);
@@ -2211,6 +2219,10 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
   verifyFormat("int *a = f1();", Style);
   verifyFormat("int& b = f2();", Style);
   verifyFormat("int&& c = f3();", Style);
+  verifyFormat("int f3() { return sizeof(Foo&); }", Style);
+  verifyFormat("int f4() { return sizeof(Foo&&); }", Style);
+  verifyFormat("void f5() { int f6(Foo&, Bar&); }", Style);
+  verifyFormat("void f5() { int f6(Foo&&, Bar&&); }", Style);
   verifyFormat("for (auto a = 0, b = 0; const Foo *c : {1, 2, 3})", Style);
   verifyFormat("for (int a = 0, b = 0; const Foo *c : {1, 2, 3})", Style);
   verifyFormat("for (int a = 0, b++; const Foo *c : {1, 2, 3})", Style);
@@ -2232,6 +2244,10 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
   verifyFormat("int* a = f1();", Style);
   verifyFormat("int & b = f2();", Style);
   verifyFormat("int && c = f3();", Style);
+  verifyFormat("int f3() { return sizeof(Foo &); }", Style);
+  verifyFormat("int f4() { return sizeof(Foo &&); }", Style);
+  verifyFormat("void f5() { int f6(Foo &, Bar &); }", Style);
+  verifyFormat("void f5() { int f6(Foo &&, Bar &&); }", Style);
   verifyFormat("for (auto a = 0, b = 0; const auto & c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const int & c : {1, 2, 3})", Style);
   verifyFormat("for (auto a = 0, b = 0; const Foo & c : {1, 2, 3})", Style);
@@ -2268,6 +2284,10 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
   verifyFormat("int * a = f1();", Style);
   verifyFormat("int &b = f2();", Style);
   verifyFormat("int &&c = f3();", Style);
+ 

[PATCH] D137706: [clang][Interp] Implement IntegralToPointer casts

2022-11-12 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 474929.

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

https://reviews.llvm.org/D137706

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/builtins.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/constant-expression-cxx14.cpp


Index: clang/test/SemaCXX/constant-expression-cxx14.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx14.cpp
+++ clang/test/SemaCXX/constant-expression-cxx14.cpp
@@ -1274,3 +1274,12 @@
 (dbt2.wp = nullptr, 0)
   };
 }
+
+
+constexpr auto name1() { return "name1"; }
+constexpr auto name2() { return "name2"; }
+
+constexpr auto b3 = name1() == name1();
+static_assert(b3, "");
+constexpr auto b4 = name1() == name2();
+static_assert(!b4, "");
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -358,12 +358,29 @@
 
 extern char externalvar[];
 constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL; // 
expected-error {{must be initialized by a constant expression}} expected-note 
{{reinterpret_cast}}
-constexpr bool litaddress = "foo" == "foo"; // expected-error {{must be 
initialized by a constant expression}}
-// cxx20_2b-warning@-1 {{comparison between two arrays is deprecated}}
+constexpr bool litaddress = "foo" == "foo"; // cxx20_2b-warning {{comparison 
between two arrays is deprecated}}
 static_assert(0 != "foo", "");
 
 }
 
+constexpr const char *foo(const char *p) { return p; }
+constexpr const char *p1 = "test1";
+constexpr const char *p2 = "test2";
+
+constexpr bool b1 = foo(p1) == foo(p1);
+static_assert(b1, "");
+
+constexpr bool b2 = foo(p1) == foo(p2);
+static_assert(!b2, "");
+
+constexpr const char *name1() { return "name1"; }
+constexpr const char *name2() { return "name2"; }
+
+constexpr auto b3 = name1() == name1();
+static_assert(b3, "");
+constexpr auto b4 = name1() == name2();
+static_assert(!b4, "");
+
 namespace MaterializeTemporary {
 
 constexpr int f(const int &r) { return r; }
Index: clang/test/SemaCXX/builtins.cpp
===
--- clang/test/SemaCXX/builtins.cpp
+++ clang/test/SemaCXX/builtins.cpp
@@ -47,7 +47,7 @@
 void a(void) {}
 int n;
 void *p = __builtin_function_start(n);   // expected-error 
{{argument must be a function}}
-static_assert(__builtin_function_start(a) == a, ""); // expected-error 
{{static assertion expression is not an integral constant expression}}
+static_assert(__builtin_function_start(a) == a, ""); // expected-error 
{{static assertion failed}}
 } // namespace function_start
 
 void no_ms_builtins() {
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -12947,13 +12947,12 @@
   if ((!LHSValue.Base && !LHSValue.Offset.isZero()) ||
   (!RHSValue.Base && !RHSValue.Offset.isZero()))
 return Error(E);
-  // It's implementation-defined whether distinct literals will have
-  // distinct addresses. In clang, the result of such a comparison is
-  // unspecified, so it is not a constant expression. However, we do know
-  // that the address of a literal will be non-null.
-  if ((IsLiteralLValue(LHSValue) || IsLiteralLValue(RHSValue)) &&
-  LHSValue.Base && RHSValue.Base)
+
+  // ObjC's @encode()
+  if (isa(E->getLHS()->IgnoreParenImpCasts()) ||
+  isa(E->getRHS()->IgnoreParenImpCasts()))
 return Error(E);
+
   // We can't tell whether weak symbols will end up pointing to the same
   // object.
   if (IsWeakLValue(LHSValue) || IsWeakLValue(RHSValue))


Index: clang/test/SemaCXX/constant-expression-cxx14.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx14.cpp
+++ clang/test/SemaCXX/constant-expression-cxx14.cpp
@@ -1274,3 +1274,12 @@
 (dbt2.wp = nullptr, 0)
   };
 }
+
+
+constexpr auto name1() { return "name1"; }
+constexpr auto name2() { return "name2"; }
+
+constexpr auto b3 = name1() == name1();
+static_assert(b3, "");
+constexpr auto b4 = name1() == name2();
+static_assert(!b4, "");
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -358,12 +358,29 @@
 
 extern char externalvar[];
 constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL; // expected-error {{must be initialized by a constant expression}} expected-note {{reinterpret_cast}}
-constexpr bool litaddress = "foo" == "foo"; // expected-error {{must be initialized by a constant expressio

[PATCH] D137706: [clang][Interp] Implement IntegralToPointer casts

2022-11-12 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 474930.

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

https://reviews.llvm.org/D137706

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/test/Sema/const-eval-64.c

Index: clang/test/Sema/const-eval-64.c
===
--- clang/test/Sema/const-eval-64.c
+++ clang/test/Sema/const-eval-64.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux -fexperimental-new-constant-interpreter %s
 
 #define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
 
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -67,6 +67,7 @@
   Pointer() {}
   Pointer(Block *B);
   Pointer(Block *B, unsigned BaseAndOffset);
+  Pointer(unsigned Offset);
   Pointer(const Pointer &P);
   Pointer(Pointer &&P);
   ~Pointer();
@@ -79,6 +80,8 @@
 
   /// Offsets a pointer inside an array.
   Pointer atIndex(unsigned Idx) const {
+if (!Pointee)
+  return Pointer(nullptr, 0, Offset + Idx);
 if (Base == RootPtrMark)
   return Pointer(Pointee, RootPtrMark, getDeclDesc()->getSize());
 unsigned Off = Idx * elemSize();
@@ -160,14 +163,17 @@
   }
 
   /// Checks if the pointer is null.
-  bool isZero() const { return Pointee == nullptr; }
+  bool isZero() const { return Pointee == nullptr && Offset == 0; }
   /// Checks if the pointer is live.
   bool isLive() const { return Pointee && !Pointee->IsDead; }
   /// Checks if the item is a field in an object.
   bool isField() const { return Base != 0 && Base != RootPtrMark; }
 
   /// Accessor for information about the declaration site.
-  Descriptor *getDeclDesc() const { return Pointee->Desc; }
+  Descriptor *getDeclDesc() const {
+assert(Pointee);
+return Pointee->Desc;
+  }
   SourceLocation getDeclLoc() const { return getDeclDesc()->getLocation(); }
 
   /// Returns a pointer to the object of which this pointer is a field.
@@ -232,12 +238,12 @@
   }
 
   /// Checks if the innermost field is an array.
-  bool inArray() const { return getFieldDesc()->IsArray; }
+  bool inArray() const { return Pointee ? getFieldDesc()->IsArray : false; }
   /// Checks if the structure is a primitive array.
   bool inPrimitiveArray() const { return getFieldDesc()->isPrimitiveArray(); }
   /// Checks if the structure is an array of unknown size.
   bool isUnknownSizeArray() const {
-return getFieldDesc()->isUnknownSizeArray();
+return Pointee ? getFieldDesc()->isUnknownSizeArray() : false;
   }
   /// Checks if the pointer points to an array.
   bool isArrayElement() const { return Base != Offset; }
@@ -288,12 +294,20 @@
   }
 
   /// Returns the number of elements.
-  unsigned getNumElems() const { return getSize() / elemSize(); }
+  unsigned getNumElems() const {
+if (Pointee)
+  return getSize() / elemSize();
+
+return std::numeric_limits::max();
+  }
 
   Block *block() const { return Pointee; }
 
   /// Returns the index into an array.
   int64_t getIndex() const {
+if (!Pointee)
+  return 0;
+
 if (isElementPastEnd())
   return 1;
 if (auto ElemSize = elemSize())
@@ -307,7 +321,7 @@
   }
 
   /// Checks if the pointer is an out-of-bounds element pointer.
-  bool isElementPastEnd() const { return Offset == PastEndMark; }
+  bool isElementPastEnd() const { return Pointee && Offset == PastEndMark; }
 
   /// Dereferences the pointer, if it's live.
   template  T &deref() const {
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -19,6 +19,8 @@
 Pointer::Pointer(Block *Pointee, unsigned BaseAndOffset)
 : Pointer(Pointee, BaseAndOffset, BaseAndOffset) {}
 
+Pointer::Pointer(unsigned Offset) : Pointer(nullptr, 0, Offset) {}
+
 Pointer::Pointer(const Pointer &P) : Pointer(P.Pointee, P.Base, P.Offset) {}
 
 Pointer::Pointer(Pointer &&P)
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -522,6 +522,11 @@
   let HasGroup = 1;
 }
 
+def CastIntegralPointer : Opcode {
+  let Types = [AluTypeClass];
+  let HasGroup = 1;
+}
+
 //===--===//
 // Comparison opcodes.
 //===--===//
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1250,6 +1250,13 @@
   r

[PATCH] D137883: [clang-format][NFC] Improve documentation of FixNamespaceComments

2022-11-12 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/include/clang/Format/Format.h:2124-2126
+  /// namespaces and fixes invalid existing ones. This is omitted for short
+  /// namespaces, what a short namespace is, is controlled by
+  /// "ShortNamespaceLines".

Or something like that?



Comment at: clang/include/clang/Format/Format.h:2133
   ///} // namespace a   }
+  ///namespace short {  namespace short {
+  ///void baz();void baz();

`short` is a C++ keyword.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137883

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


[PATCH] D102107: [OpenMP] Codegen aggregate for outlined function captures

2022-11-12 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D102107#3922842 , @dhruvachak 
wrote:

> In D102107#3921948 , @jhuber6 wrote:
>
>> @dhruvachak Do you still need help updating the LLVM tests?
>
> If you go a few messages back, there are some llvm tests that @jdoerfert said 
> were not updated properly. Can someone help update those tests properly?

The patch does not apply cleanly currently, please rebase it and I'll try to 
get it working locally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102107

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


Re: How can Autoconf help with the transition to stricter compilation defaults?

2022-11-12 Thread Zack Weinberg via cfe-commits
Sam James  writes:

>> On 12 Nov 2022, at 03:40, Zack Weinberg  wrote:
>> This is definitely more work than I can see myself doing on a volunteer
>> basis, but a 2.69.1 patch release — nothing that’s not already on trunk,
>> cherry pick the changes needed to support the newer compilers (and
>> also newer Perl and Bash and M4) is a thing that could happen.
>
> I didn't want to ask you to do this because I felt fortunate enough
> you were volunteering to handle 2.72, but this would indeed be a help,
> because then I won't have to try persuade people they should totally upgrade,
> and it should happen naturally enough with distro upgrades.

To be clear, I am *not* volunteering to do this.  It would be
significantly more work than I can carve out the time for.

Whoever does this will need to go through the *entire* list of changes
since the original 2.69 release, to find all of the changes that improve
compatibility with newer versions of tools, disentangle each from any
other changes applied in the same commit, and then do a whole lot of
testing.  It’s tedious, and whoever does it should get paid to do it.
I’m guessing at least one full 40-hour week of work, and you should
budget for three times that, going by how much more work the 2.70
release was than we anticipated.

I can *advise* anyone who takes on the job, and review their changes,
but that’s it.

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


[PATCH] D137768: [opt][clang] Enable using -module-summary with -S / -emit-llvm

2022-11-12 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:1016
   case Backend_EmitLL:
-MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists));
+if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
+  if (!TheModule->getModuleFlag("EnableSplitLTOUnit"))

Thanks for adding this too! I'm wondering if the code should be restructured 
slightly to reduce the code duplication. The simplest way might be to handle 
both cases (EmitBC and EmitLL) together, and then check the Action type to 
guard whether calling a *BitcodeWriter pass (optionally setting up the 
additional output file in the ThinLTO BC case) vs PrintModulePass.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137768

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


Re: How can Autoconf help with the transition to stricter compilation defaults?

2022-11-12 Thread Zack Weinberg via cfe-commits
Wookey  writes:
> On 2022-11-10 19:08 +0100, Florian Weimer wrote:
>> based on a limited attempt to get this fixed about three years
>> ago, I expect that many of the problematic packages have not had their
>> configure scripts regenerated using autoconf for a decade or more.  This
>> means that as an autoconf maintainer, you unfortunately won't be able to
>> help us much.
>
> We changed the default in debian to re-autoconf on build a few years
> ago precisely so that changes in the tools (particularly new arch
> support) were picked up even by code that was not being re-released or
> released without autofoo updates.  This has worked remarkably well.
>
> So changes in the tools will get used, at least in that context, which
> includes a fairly hefty pile of crufty old code. I have no feeling for
> how many packages are actually affected by this. Is there a quick way to test?

In the run-up to Autoconf 2.70 I got Lucas to do a Debian archive
rebuild and mass bug filing, so, look through Debian packages for
patches being carried for configure.ac and/or bundled .m4 files?

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


Re: How can Autoconf help with the transition to stricter compilation defaults?

2022-11-12 Thread Sam James via cfe-commits


> On 12 Nov 2022, at 03:40, Zack Weinberg  wrote:
> 
> Florian Weimer  writes:
>> based on a limited attempt to get this fixed about three years
>> ago, I expect that many of the problematic packages have not had their
>> configure scripts regenerated using autoconf for a decade or more.  This
>> means that as an autoconf maintainer, you unfortunately won't be able to
>> help us much.
> 
> I’m sadly not surprised.
> 
> This is definitely more work than I can see myself doing on a volunteer
> basis, but a 2.69.1 patch release — nothing that’s not already on trunk,
> cherry pick the changes needed to support the newer compilers (and
> also newer Perl and Bash and M4) is a thing that could happen.

I didn't want to ask you to do this because I felt fortunate enough
you were volunteering to handle 2.72, but this would indeed be a help,
because then I won't have to try persuade people they should totally upgrade,
and it should happen naturally enough with distro upgrades.

If you are willing, that would be welcome.

Of course, we'll have to go lobby them, but that is what it is :)



signature.asc
Description: Message signed with OpenPGP
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: How can Autoconf help with the transition to stricter compilation defaults?

2022-11-12 Thread Wookey via cfe-commits
On 2022-11-10 19:08 +0100, Florian Weimer wrote:
> * Zack Weinberg via Gcc:
> 
> > It’s come to my attention (via https://lwn.net/Articles/913505/ and
> > https://fedoraproject.org/wiki/Changes/PortingToModernC) that GCC and
> > Clang both plan to disable several “legacy” C language features by
> > default in a near-future release (GCC 14, Clang 16) (see the Fedora
> > wiki link for a list).

> based on a limited attempt to get this fixed about three years
> ago, I expect that many of the problematic packages have not had their
> configure scripts regenerated using autoconf for a decade or more.  This
> means that as an autoconf maintainer, you unfortunately won't be able to
> help us much.

We changed the default in debian to re-autoconf on build a few years
ago precisely so that changes in the tools (particularly new arch
support) were picked up even by code that was not being re-released or
released without autofoo updates.  This has worked remarkably well.

So changes in the tools will get used, at least in that context, which
includes a fairly hefty pile of crufty old code. I have no feeling for
how many packages are actually affected by this. Is there a quick way to test?

Wookey
-- 
Principal hats:  Debian, Wookware, ARM
http://wookware.org/


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


Re: How can Autoconf help with the transition to stricter compilation defaults?

2022-11-12 Thread Joseph Myers via cfe-commits
On Fri, 11 Nov 2022, Zack Weinberg via Gcc wrote:

> These are also a trip hazard for novices, and the only way to turn them
> off is with -std=cXX, which also turns another trip hazard (trigraphs)
> *on*… so yeah, anything you can do to help speed up their removal, I
> think it’d be worthwhile.

As of GCC 13, -std=c2x will disable trigraphs, since they've been removed 
from C2x.

-- 
Joseph S. Myers
jos...@codesourcery.com___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133036: [InstCombine] Treat passing undef to noundef params as UB

2022-11-12 Thread Tim Neumann via Phabricator via cfe-commits
TimNN added a comment.

I'm still trying to properly minimize this, but this definitely interacts badly 
with other optimizations (which triggers the Rust CI failure I mentioned above):

- We start with two functions, `outer` and `inner`. `outer` calls `inner`. 
`outer` has a `noundef` argument that it forwards to `inner` (where the 
argument is also `noundef`).
- `PostOrderFunctionAttrsPass` decides, for both functions, that the argument 
is `readnone`. The `readnone` attribute is //only// added to the function 
definitions. The `readnone` attribute is //not// added at the `call` to `inner` 
from `outer`.
- The `DeadArgumentEliminationPass` decides that when `outer` calls `inner` the 
argument should be `poison`.
- This patch sees the `poison` being passed to a `noundef` argument and kills 
the call.

I don't know which component should be considered "at fault" here (or if the 
`readnone` bit is even relevant).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133036

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


[PATCH] D133036: [InstCombine] Treat passing undef to noundef params as UB

2022-11-12 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

@TimNN Do you have an IR sample for this? DAE is supposed to strip UB-implying 
attributes when converting arguments to poison here: 
https://github.com/llvm/llvm-project/blob/cbe5b2dd914b7ee47bb4d0f67af154a40be4d208/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp#LL291C17-L291C37


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133036

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


[PATCH] D133036: [InstCombine] Treat passing undef to noundef params as UB

2022-11-12 Thread Tim Neumann via Phabricator via cfe-commits
TimNN added a comment.

I've included excerpts from the IR below. It will take me a bit to provide 
something compilable. Though you are right, the `noundef` did indeed get 
removed from the `call`.

  *** IR Dump Before DeadArgumentEliminationPass on [module] ***
  ; Function Attrs: nonlazybind uwtable
  define void 
@_RNvXs2_NtNtCs840rfDNPFol_10proc_macro6bridge3rpcbINtB5_6EncodeuE6encodeB9_(i1 
noundef zeroext %0, ptr noalias noundef align 8 dereferenceable(40) %1, ptr 
noalias nocapture noundef nonnull readnone align 1 %2) unnamed_addr #0 !dbg 
!18135 {
%4 = zext i1 %0 to i8, !dbg !18137
call void 
@_RNvXs0_NtNtCs840rfDNPFol_10proc_macro6bridge3rpchINtB5_6EncodeuE6encodeB9_(i8 
%4, ptr noalias noundef nonnull align 8 dereferenceable(40) %1, ptr noalias 
noundef nonnull align 1 %2), !dbg !18137
ret void, !dbg !18138
  }
  *** IR Dump After DeadArgumentEliminationPass on [module] ***
  ; Function Attrs: nonlazybind uwtable
  define void 
@_RNvXs2_NtNtCs840rfDNPFol_10proc_macro6bridge3rpcbINtB5_6EncodeuE6encodeB9_(i1 
noundef zeroext %0, ptr noalias noundef align 8 dereferenceable(40) %1, ptr 
noalias nocapture noundef nonnull readnone align 1 %2) unnamed_addr #0 !dbg 
!18136 {
%4 = zext i1 %0 to i8, !dbg !18138
call void 
@_RNvXs0_NtNtCs840rfDNPFol_10proc_macro6bridge3rpchINtB5_6EncodeuE6encodeB9_(i8 
%4, ptr noalias noundef nonnull align 8 dereferenceable(40) %1, ptr noalias 
nonnull align 1 poison), !dbg !18138
ret void, !dbg !18139
  }
  *** IR Dump Before InstCombinePass on 
_RNvXs2_NtNtCs840rfDNPFol_10proc_macro6bridge3rpcbINtB5_6EncodeuE6encodeB9_ ***
  ; Function Attrs: nonlazybind uwtable
  define available_externally void 
@_RNvXs2_NtNtCs840rfDNPFol_10proc_macro6bridge3rpcbINtB5_6EncodeuE6encodeB9_(i1 
noundef zeroext %0, ptr noalias noundef align 8 dereferenceable(40) %1, ptr 
noalias nocapture noundef nonnull readnone align 1 %2) unnamed_addr #2 !dbg 
!20759 {
%4 = zext i1 %0 to i8, !dbg !20762
call void 
@_RNvXs0_NtNtCs840rfDNPFol_10proc_macro6bridge3rpchINtB5_6EncodeuE6encodeB9_(i8 
%4, ptr noalias noundef nonnull align 8 dereferenceable(40) %1, ptr noalias 
nonnull align 1 poison), !dbg !20762
ret void, !dbg !20763
  }
  *** IR Dump After InstCombinePass on 
_RNvXs2_NtNtCs840rfDNPFol_10proc_macro6bridge3rpcbINtB5_6EncodeuE6encodeB9_ ***
  ; Function Attrs: nonlazybind uwtable
  define available_externally void 
@_RNvXs2_NtNtCs840rfDNPFol_10proc_macro6bridge3rpcbINtB5_6EncodeuE6encodeB9_(i1 
noundef zeroext %0, ptr noalias noundef align 8 dereferenceable(40) %1, ptr 
noalias nocapture noundef nonnull readnone align 1 %2) unnamed_addr #2 !dbg 
!20759 {
store i1 true, ptr poison, align 1
ret void, !dbg !20762
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133036

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


[PATCH] D137885: [modules] Support zstd in .pcm file

2022-11-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 474953.
MaskRay edited the summary of this revision.
MaskRay added a comment.

use level 9


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137885

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/embed-files-compressed.cpp


Index: clang/test/Modules/embed-files-compressed.cpp
===
--- clang/test/Modules/embed-files-compressed.cpp
+++ clang/test/Modules/embed-files-compressed.cpp
@@ -1,4 +1,4 @@
-// REQUIRES: zlib
+// REQUIRES: zlib || zstd
 // REQUIRES: shell
 //
 // RUN: rm -rf %t
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1980,6 +1980,14 @@
   // Compress the buffer if possible. We expect that almost all PCM
   // consumers will not want its contents.
   SmallVector CompressedBuffer;
+  if (llvm::compression::zstd::isAvailable()) {
+llvm::compression::zstd::compress(
+llvm::arrayRefFromStringRef(Blob.drop_back(1)), CompressedBuffer, 9);
+RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, Blob.size() - 
1};
+Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
+  llvm::toStringRef(CompressedBuffer));
+return;
+  }
   if (llvm::compression::zlib::isAvailable()) {
 llvm::compression::zlib::compress(
 llvm::arrayRefFromStringRef(Blob.drop_back(1)), CompressedBuffer);
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1452,19 +1452,23 @@
 unsigned RecCode = MaybeRecCode.get();
 
 if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) {
-  if (!llvm::compression::zlib::isAvailable()) {
-Error("zlib is not available");
+  const llvm::compression::Format F =
+  Blob.size() >= 2 && memcmp(Blob.data(), "\x1f\x8b", 2) == 0
+  ? llvm::compression::Format::Zlib
+  : llvm::compression::Format::Zstd;
+  if (const char *Reason = llvm::compression::getReasonIfUnsupported(F)) {
+Error(Reason);
 return nullptr;
   }
-  SmallVector Uncompressed;
-  if (llvm::Error E = llvm::compression::zlib::decompress(
-  llvm::arrayRefFromStringRef(Blob), Uncompressed, Record[0])) {
+  SmallVector Decompressed;
+  if (llvm::Error E = llvm::compression::decompress(
+  F, llvm::arrayRefFromStringRef(Blob), Decompressed, Record[0])) {
 Error("could not decompress embedded file contents: " +
   llvm::toString(std::move(E)));
 return nullptr;
   }
   return llvm::MemoryBuffer::getMemBufferCopy(
-  llvm::toStringRef(Uncompressed), Name);
+  llvm::toStringRef(Decompressed), Name);
 } else if (RecCode == SM_SLOC_BUFFER_BLOB) {
   return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true);
 } else {


Index: clang/test/Modules/embed-files-compressed.cpp
===
--- clang/test/Modules/embed-files-compressed.cpp
+++ clang/test/Modules/embed-files-compressed.cpp
@@ -1,4 +1,4 @@
-// REQUIRES: zlib
+// REQUIRES: zlib || zstd
 // REQUIRES: shell
 //
 // RUN: rm -rf %t
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1980,6 +1980,14 @@
   // Compress the buffer if possible. We expect that almost all PCM
   // consumers will not want its contents.
   SmallVector CompressedBuffer;
+  if (llvm::compression::zstd::isAvailable()) {
+llvm::compression::zstd::compress(
+llvm::arrayRefFromStringRef(Blob.drop_back(1)), CompressedBuffer, 9);
+RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, Blob.size() - 1};
+Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
+  llvm::toStringRef(CompressedBuffer));
+return;
+  }
   if (llvm::compression::zlib::isAvailable()) {
 llvm::compression::zlib::compress(
 llvm::arrayRefFromStringRef(Blob.drop_back(1)), CompressedBuffer);
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1452,19 +1452,23 @@
 unsigned RecCode = MaybeRecCode.get();
 
 if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) {
-  if (!llvm::compression::zlib::isAvailable()) {
-Error("zlib is not available");
+  const llvm::compression::Format F =
+  Blob.size() >= 2 && memcmp(Blob.da

[PATCH] D137897: Extend the number of case Sema::CheckForIntOverflow covers

2022-11-12 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik created this revision.
shafik added reviewers: aaron.ballman, erichkeane.
Herald added a project: All.
shafik requested review of this revision.

Currently `Sema::CheckForIntOverflow` misses several case that other compilers 
diagnose for overflow in integral constant expressions. This includes the 
arguments of a `CXXConstructExpr` as well as the expressions used in an 
`ArraySubscriptExpr`, `CXXNewExpr` and `CompoundLiteralExpr`.

This fixes https://github.com/llvm/llvm-project/issues/58944


https://reviews.llvm.org/D137897

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/integer-overflow.cpp


Index: clang/test/Sema/integer-overflow.cpp
===
--- /dev/null
+++ clang/test/Sema/integer-overflow.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -Wno-unused-value -verify -fsyntax-only
+
+namespace GH58944 {
+struct A {
+  A(unsigned long) ;
+};
+
+A a(1024 * 1024 * 1024 * 1024* 1024ull); // expected-warning {{overflow in 
expression; result is 0 with type 'int'}}
+
+void f() {
+  new int[1024 * 1024 * 1024 * 1024* 1024ull]; // expected-warning {{overflow 
in expression; result is 0 with type 'int'}}
+
+  int arr[]{1,2,3};
+  arr[1024 * 1024 * 1024 * 1024* 1024ull]; // expected-warning {{overflow in 
expression; result is 0 with type 'int'}}
+
+  (int){1024 * 1024 * 1024 * 1024* 1024}; // expected-warning {{overflow in 
expression; result is 0 with type 'int'}}
+}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14660,6 +14660,17 @@
   Exprs.append(Call->arg_begin(), Call->arg_end());
 else if (auto Message = dyn_cast(E))
   Exprs.append(Message->arg_begin(), Message->arg_end());
+else if (auto Construct = dyn_cast(E))
+  Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Array = dyn_cast(E))
+  Exprs.push_back(Array->getIdx());
+else if (auto Compound = dyn_cast(E))
+  Exprs.push_back(Compound->getInitializer());
+else if (auto New = dyn_cast(E)) {
+  if (New->isArray())
+if (auto ArraySize = New->getArraySize())
+  Exprs.push_back(ArraySize.value());
+}
   } while (!Exprs.empty());
 }
 


Index: clang/test/Sema/integer-overflow.cpp
===
--- /dev/null
+++ clang/test/Sema/integer-overflow.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -Wno-unused-value -verify -fsyntax-only
+
+namespace GH58944 {
+struct A {
+  A(unsigned long) ;
+};
+
+A a(1024 * 1024 * 1024 * 1024* 1024ull); // expected-warning {{overflow in expression; result is 0 with type 'int'}}
+
+void f() {
+  new int[1024 * 1024 * 1024 * 1024* 1024ull]; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
+
+  int arr[]{1,2,3};
+  arr[1024 * 1024 * 1024 * 1024* 1024ull]; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
+
+  (int){1024 * 1024 * 1024 * 1024* 1024}; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
+}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14660,6 +14660,17 @@
   Exprs.append(Call->arg_begin(), Call->arg_end());
 else if (auto Message = dyn_cast(E))
   Exprs.append(Message->arg_begin(), Message->arg_end());
+else if (auto Construct = dyn_cast(E))
+  Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Array = dyn_cast(E))
+  Exprs.push_back(Array->getIdx());
+else if (auto Compound = dyn_cast(E))
+  Exprs.push_back(Compound->getInitializer());
+else if (auto New = dyn_cast(E)) {
+  if (New->isArray())
+if (auto ArraySize = New->getArraySize())
+  Exprs.push_back(ArraySize.value());
+}
   } while (!Exprs.empty());
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6daa005 - [NFC][Clang] Add some codegen tests for https://github.com/llvm/llvm-project/issues/58798

2022-11-12 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2022-11-13T02:39:52+03:00
New Revision: 6daa005b90c8122751d04c6eba0fa1259e912cfe

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

LOG: [NFC][Clang] Add some codegen tests for 
https://github.com/llvm/llvm-project/issues/58798

Added: 
clang/test/CodeGenCXX/pr58798.cpp

Modified: 


Removed: 




diff  --git a/clang/test/CodeGenCXX/pr58798.cpp 
b/clang/test/CodeGenCXX/pr58798.cpp
new file mode 100644
index 0..607b36aa7f69a
--- /dev/null
+++ b/clang/test/CodeGenCXX/pr58798.cpp
@@ -0,0 +1,186 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-attributes
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-linux-gnu -fexceptions 
-fcxx-exceptions | FileCheck %s
+
+// CHECK: Function Attrs: mustprogress noinline nounwind optnone willreturn 
memory(read)
+// CHECK-LABEL: define 
{{[^@]+}}@_Z54early_caller_of_callee_with_clang_attr_with_clang_attri
+// CHECK-SAME: (i32 noundef [[A:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[CALL:%.*]] = call noundef i32 
@_Z22callee_with_clang_attri(i32 noundef [[TMP0]]) #[[ATTR3:[0-9]+]]
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+
+// CHECK: Function Attrs: mustprogress noinline nounwind optnone willreturn 
memory(read)
+// CHECK-LABEL: define {{[^@]+}}@_Z22callee_with_clang_attri
+// CHECK-SAME: (i32 noundef [[A:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TOBOOL:%.*]] = icmp ne i32 [[TMP0]], 0
+// CHECK-NEXT:br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+// CHECK:   if.then:
+// CHECK-NEXT:[[EXCEPTION:%.*]] = call ptr @__cxa_allocate_exception(i64 
4) #[[ATTR4:[0-9]+]]
+// CHECK-NEXT:store i32 42, ptr [[EXCEPTION]], align 16
+// CHECK-NEXT:call void @__cxa_throw(ptr [[EXCEPTION]], ptr @_ZTIi, ptr 
null) #[[ATTR5:[0-9]+]]
+// CHECK-NEXT:unreachable
+// CHECK:   if.end:
+// CHECK-NEXT:ret i32 24
+//
+
+// CHECK: Function Attrs: mustprogress noinline nounwind optnone
+// CHECK-LABEL: define 
{{[^@]+}}@_Z52early_caller_of_callee_with_clang_attr_with_cxx_attri
+// CHECK-SAME: (i32 noundef [[A:%.*]]) #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[CALL:%.*]] = call noundef i32 
@_Z22callee_with_clang_attri(i32 noundef [[TMP0]]) #[[ATTR3]]
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+
+// CHECK: Function Attrs: mustprogress noinline nounwind optnone willreturn 
memory(read)
+// CHECK-LABEL: define 
{{[^@]+}}@_Z52early_caller_of_callee_with_cxx_attr_with_clang_attri
+// CHECK-SAME: (i32 noundef [[A:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[CALL:%.*]] = call noundef i32 
@_Z20callee_with_cxx_attri(i32 noundef [[TMP0]]) #[[ATTR4]]
+// CHECK-NEXT:ret i32 [[CALL]]
+//
+
+// CHECK: Function Attrs: mustprogress noinline nounwind optnone
+// CHECK-LABEL: define {{[^@]+}}@_Z20callee_with_cxx_attri
+// CHECK-SAME: (i32 noundef [[A:%.*]]) #[[ATTR1]] personality ptr 
@__gxx_personality_v0 {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A]], ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// CHECK-NEXT:[[TOBOOL:%.*]] = icmp ne i32 [[TMP0]], 0
+// CHECK-NEXT:br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+// CHECK:   if.then:
+// CHECK-NEXT:[[EXCEPTION:%.*]] = call ptr @__cxa_allocate_exception(i64 
4) #[[ATTR4]]
+// CHECK-NEXT:store i32 42, ptr [[EXCEPTION]], align 16
+// CHECK-NEXT:invoke void @__cxa_throw(ptr [[EXCEPTION]], ptr @_ZTIi, ptr 
null) #[[ATTR5]]
+// CHECK-NEXT:to label [[UNREACHABLE:%.*]] unwind label 
[[TERMINATE_LPAD:%.*]]
+// CHECK:   if.end:
+// CHECK-NEXT:ret i32 24
+// CHECK:   terminate.lpad:
+// CHECK-NEXT:[[TMP1:%.*]] = landingpad { ptr, i32 }
+// CHECK-NEXT:catch ptr null
+// CHECK-NEXT:[[TMP2:%.*]] = extractvalue { ptr, i32 } [[TMP1]], 0
+// CHECK-NEXT:call void @__clang_call_terminate(ptr [[TMP2]]) 
#

[PATCH] D133036: [InstCombine] Treat passing undef to noundef params as UB

2022-11-12 Thread Tim Neumann via Phabricator via cfe-commits
TimNN added a comment.

I didn't manage to repro with `opt`, so still no compilable IR. I did some more 
debugging, though:

- Inside `removeDeadArgumentsFromCallers`, `CB->getCalledFunction()->dump()` 
(after the modification) is `define void 
@_RNvXs0_NtNtCs840rfDNPFol_10proc_macro6bridge3rpchINtB5_6EncodeuE6encodeB9_(i8 
%0, ptr noalias noundef align 8 dereferenceable(40) %1, ptr noalias nocapture 
nonnull readnone align 1 %2) unnamed_addr #0 personality ptr 
@rust_eh_personality !dbg !18034 { ... }`. **Definition, no `noundef`.**
- Inside `callPassesUndefToPassingUndefUBParam`, 
`Call.getCalledFunction()->dump()` is `declare void 
@_RNvXs0_NtNtCs840rfDNPFol_10proc_macro6bridge3rpchINtB5_6EncodeuE6encodeB9_(i8 
%0, ptr noalias noundef align 8 dereferenceable(40) %1, ptr noalias noundef 
nonnull align 1 %2) unnamed_addr #2`. **Declaration, `noundef` is back.**


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133036

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


[PATCH] D137901: [Clang] `nothrow`-implying attributes should actually manifest `nothrow` attribute (PR58798)

2022-11-12 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri created this revision.
lebedev.ri added reviewers: aaron.ballman, erichkeane, rjmccall.
lebedev.ri added a project: LLVM.
Herald added a project: All.
lebedev.ri requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.
Herald added a project: clang.

This is part of https://reviews.llvm.org/D137381,
i've stumbled into this in 
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52989&q=label%3AProj-librawspeed

Look at the `callee_with_clang_attr()`.
`pure` attribute implies `nounwind`, and we successfully manifest that at IRgen,
and calls from nounwind functions treat it as non-unwinding,
except that when generating function definition,
we'd suddenly forget that it is nounwind...

Here, everything that could go wrong, goes wrong.

`CodeGenFunction::EmitStartEHSpec()` looks at the AST function exception 
specification,
and not IR attributes, so

You'd think we can inferr the attribute in AST after the fact,
in `Sema::ActOnFunctionDeclarator()`, and while that is sufficient to get the 
diagnostics,
the function exception specification has already been computed from parsed 
attributes.

So we also need to adjust `handleFunctionTypeAttr()` (called by 
`processTypeAttrs()`)
so it considers just-parsed `pure` as if it's `nothrow`...

It would somewhat less ugly if we could just infer `nothrow` attribute
during *attribute parsing* from `pure`/etc. Is that possible?

Also, OpenMP declare variant tests are showing an unexpected error,
looks like i'm missing some attribute propagation?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137901

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCXX/pr58798.cpp
  clang/test/OpenMP/declare_variant_messages.cpp
  clang/test/SemaCXX/attr-print.cpp
  clang/test/SemaCXX/cxx11-attr-print.cpp
  clang/test/SemaCXX/warn-throw-out-noexcept-func.cpp

Index: clang/test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- clang/test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ clang/test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -23,6 +23,9 @@
   void __declspec(nothrow) SomeDeclspecThrow() {// expected-note {{function declared non-throwing here}}
throw 1; // expected-warning {{has a non-throwing exception specification but}}
   }
+  void __attribute__((pure)) SomeAnotherThrow() {// expected-note {{function declared non-throwing here}}
+   throw 1; // expected-warning {{has a non-throwing exception specification but}}
+  }
 };
 
 struct M_ShouldNotDiag {
@@ -240,7 +243,7 @@
   }
 }
 // As seen in p34973, this should not throw the warning.  If there is an active
-// exception, catch(...) catches everything. 
+// exception, catch(...) catches everything.
 void o_ShouldNotDiag() noexcept {
   try {
 throw;
Index: clang/test/SemaCXX/cxx11-attr-print.cpp
===
--- clang/test/SemaCXX/cxx11-attr-print.cpp
+++ clang/test/SemaCXX/cxx11-attr-print.cpp
@@ -31,10 +31,10 @@
 // CHECK: int c11_alignas _Alignas(alignof(int));
 _Alignas(int) int c11_alignas;
 
-// CHECK: void foo() __attribute__((const));
+// CHECK: void foo() noexcept __attribute__((const));
 void foo() __attribute__((const));
 
-// CHECK: void bar() __attribute__((__const));
+// CHECK: void bar() noexcept __attribute__((__const));
 void bar() __attribute__((__const));
 
 // FIXME: It's unfortunate that the string literal prints with the below three
@@ -65,8 +65,8 @@
 
 // CHECK: int m __attribute__((aligned(4
 // CHECK: int n alignas(4
-// CHECK: static int f() __attribute__((pure))
-// CHECK: static int g() {{\[}}[gnu::pure]]
+// CHECK: static int f() noexcept __attribute__((pure))
+// CHECK: static int g() noexcept {{\[}}[gnu::pure]]
 template  struct S {
   __attribute__((aligned(4))) int m;
   alignas(4) int n;
@@ -80,8 +80,8 @@
 
 // CHECK: int m __attribute__((aligned(4
 // CHECK: int n alignas(4
-// CHECK: static int f() __attribute__((pure))
-// CHECK: static int g() {{\[}}[gnu::pure]]
+// CHECK: static int f() noexcept __attribute__((pure))
+// CHECK: static int g() noexcept {{\[}}[gnu::pure]]
 template struct S;
 
 // CHECK: using Small2 {{\[}}[gnu::mode(byte)]] = int;
Index: clang/test/SemaCXX/attr-print.cpp
===
--- clang/test/SemaCXX/attr-print.cpp
+++ clang/test/SemaCXX/attr-print.cpp
@@ -7,14 +7,14 @@
 // CHECK: int y __declspec(align(4));
 __declspec(align(4)) int y;
 
-// CHECK: void foo() __attribute__((const));
+// CHECK: void foo() noexcept __attribute__((const));
 void foo() __attribute__((const));
 
-// CHECK: void bar() __attribute__((__const));
+// CHECK: void bar() noexcept __attribute__((__const));
 void bar() __attribute__((__const));
 
 // FIXME: Print this with correct format.
-// CHECK: void foo1() __attribute__((noinline)) __attribute__((pure));
+// CHECK: 

[PATCH] D137040: [clangd] Add heuristic for dropping snippet when completing member function pointer

2022-11-12 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks!

In D137040#3918118 , @tom-anders 
wrote:

> now we kinda have the same test case duplicated in sema and clangd tests - I 
> guess for clangd we now actually only have to test that the SnippetSuffix is 
> cleared when FunctionCanBeCall is true, but I don't see an easy way to 
> somehow inject fake Sema results into CodeComplete.cpp

I don't mind the duplication too much; I like that the clangd test is an "end 
to end" test directly expressing the user-visible behaviour that "in these 
situations we should get these completions".




Comment at: clang/unittests/Sema/CodeCompleteTest.cpp:123
+  CodeCompleteAction(ParsedSourceLocation P, CompletionContext &ResultCtx,
+ CodeCompleteConsumer *Consumer = nullptr)
+  : CompletePosition(std::move(P)), ResultCtx(ResultCtx),

Since the constructor has only one other caller (`runCompletion()`), I'd rather 
remove the default arg and put the `new VisitedContextFinder(...)` in that 
caller.

As a bonus, we would no longer need to pass the `CompletionContext` to the 
`CodeCompleteAction` constructor, and don't need to use a "dummy context" in 
`CollectCompletedFunctions()`.



Comment at: clang/unittests/Sema/CodeCompleteTest.cpp:231
+Contains(AllOf(
+Field("Name", &CompletedFunctionDecl::Name, "method"),
+Field("IsStatic", &CompletedFunctionDecl::IsStatic, false),

Consider using [this 
style](https://searchfox.org/llvm/rev/3182ea4a8fcb163c6e5cb01f474f84f30d101dd9/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp#35-37)
 of matcher ([example 
use](https://searchfox.org/llvm/rev/3182ea4a8fcb163c6e5cb01f474f84f30d101dd9/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp#378)).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137040

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


[PATCH] D137897: Extend the number of case Sema::CheckForIntOverflow covers

2022-11-12 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 474981.
shafik added a comment.

Fix formatting of test


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

https://reviews.llvm.org/D137897

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/integer-overflow.cpp


Index: clang/test/Sema/integer-overflow.cpp
===
--- /dev/null
+++ clang/test/Sema/integer-overflow.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -Wno-unused-value -verify -fsyntax-only
+
+namespace GH58944 {
+struct A {
+  A(unsigned long) ;
+};
+
+A a(1024 * 1024 * 1024 * 1024 * 1024ull); // expected-warning {{overflow in 
expression; result is 0 with type 'int'}}
+
+void f() {
+  new int[1024 * 1024 * 1024 * 1024 * 1024ull]; // expected-warning {{overflow 
in expression; result is 0 with type 'int'}}
+
+  int arr[]{1,2,3};
+  arr[1024 * 1024 * 1024 * 1024 * 1024ull]; // expected-warning {{overflow in 
expression; result is 0 with type 'int'}}
+
+  (int){1024 * 1024 * 1024 * 1024 * 1024}; // expected-warning {{overflow in 
expression; result is 0 with type 'int'}}
+}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14660,6 +14660,17 @@
   Exprs.append(Call->arg_begin(), Call->arg_end());
 else if (auto Message = dyn_cast(E))
   Exprs.append(Message->arg_begin(), Message->arg_end());
+else if (auto Construct = dyn_cast(E))
+  Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Array = dyn_cast(E))
+  Exprs.push_back(Array->getIdx());
+else if (auto Compound = dyn_cast(E))
+  Exprs.push_back(Compound->getInitializer());
+else if (auto New = dyn_cast(E)) {
+  if (New->isArray())
+if (auto ArraySize = New->getArraySize())
+  Exprs.push_back(ArraySize.value());
+}
   } while (!Exprs.empty());
 }
 


Index: clang/test/Sema/integer-overflow.cpp
===
--- /dev/null
+++ clang/test/Sema/integer-overflow.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -Wno-unused-value -verify -fsyntax-only
+
+namespace GH58944 {
+struct A {
+  A(unsigned long) ;
+};
+
+A a(1024 * 1024 * 1024 * 1024 * 1024ull); // expected-warning {{overflow in expression; result is 0 with type 'int'}}
+
+void f() {
+  new int[1024 * 1024 * 1024 * 1024 * 1024ull]; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
+
+  int arr[]{1,2,3};
+  arr[1024 * 1024 * 1024 * 1024 * 1024ull]; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
+
+  (int){1024 * 1024 * 1024 * 1024 * 1024}; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
+}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14660,6 +14660,17 @@
   Exprs.append(Call->arg_begin(), Call->arg_end());
 else if (auto Message = dyn_cast(E))
   Exprs.append(Message->arg_begin(), Message->arg_end());
+else if (auto Construct = dyn_cast(E))
+  Exprs.append(Construct->arg_begin(), Construct->arg_end());
+else if (auto Array = dyn_cast(E))
+  Exprs.push_back(Array->getIdx());
+else if (auto Compound = dyn_cast(E))
+  Exprs.push_back(Compound->getInitializer());
+else if (auto New = dyn_cast(E)) {
+  if (New->isArray())
+if (auto ArraySize = New->getArraySize())
+  Exprs.push_back(ArraySize.value());
+}
   } while (!Exprs.empty());
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137823: [clang-format][NFC] Moved configuration parsing tests in own file

2022-11-12 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/unittests/Format/ConfigParseTest.cpp:14
+
+#define DEBUG_TYPE "parse-test"
+

You can delete it.



Comment at: clang/unittests/Format/ConfigParseTest.cpp:1006
+
+TEST(FormatStyle, GetStyleWithEmptyFileName) {
+  llvm::vfs::InMemoryFileSystem FS;

Otherwise, the test will be skipped.



Comment at: clang/unittests/Format/ConfigParseTest.cpp:1013
+
+TEST(FormatStyle, GetStyleOfFile) {
+  llvm::vfs::InMemoryFileSystem FS;

Change `FormatStyle` to `ParseTest` here and on line 1220 below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137823

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


[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

2022-11-12 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D137181#3918715 , @goldstein.w.n 
wrote:

> In D137181#3918673 , @owenpan wrote:
>
>> Below is how I defined `PPLevel`:
>>
>>   $ git diff UnwrappedLineParser.h
>>   diff --git a/clang/lib/Format/UnwrappedLineParser.h 
>> b/clang/lib/Format/UnwrappedLineParser.h
>>   index b9b106bcc89a..a234f6852e0c 100644
>>   --- a/clang/lib/Format/UnwrappedLineParser.h
>>   +++ b/clang/lib/Format/UnwrappedLineParser.h
>>   @@ -43,6 +43,9 @@ struct UnwrappedLine {
>>
>>  /// The indent level of the \c UnwrappedLine.
>>  unsigned Level;
>>   +  /// The \c PPBranchLevel (adjusted for header guards) of the macro 
>> definition
>>   +  /// this line belongs to.
>>   +  unsigned PPLevel;
>>
>>  /// Whether this \c UnwrappedLine is part of a preprocessor directive.
>>  bool InPPDirective;
>>   @@ -358,7 +361,7 @@ struct UnwrappedLineNode {
>>};
>>
>>inline UnwrappedLine::UnwrappedLine()
>>   -: Level(0), InPPDirective(false), InPragmaDirective(false),
>>   +: Level(0), PPLevel(0), InPPDirective(false), 
>> InPragmaDirective(false),
>>  InMacroBody(false), MustBeDeclaration(false),
>>  MatchingOpeningBlockLineIndex(kInvalidIndex) {}
>>
>>
>> Conceptually, I think it's more accurate to make `PPLevel` to mean the PP 
>> branching level of the `#define` line, not the first line of the macro body. 
>> IMO it may simplify the changes you made to the formatter.
>
> Hmm? Not sure what you mean.

Does the comments above `unsigned PPLevel;` in the above `git diff` output 
help? Anyway, you already addressed my comment by decreasing `PPLevel` by 1, so 
it's ok now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137181

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