[PATCH] D104790: [x86] fix mm*_undefined* intrinsics to use arbitrary frozen bit pattern

2021-06-27 Thread Juneyoung Lee via Phabricator via cfe-commits
aqjune added a comment.

In D104790#2842523 , @nikic wrote:

> Is this actually better in any meaningful way? InstCombine will turn `freeze 
> poison` into `zeroinitializer`, and until then this is just a completely 
> opaque value.

I think to correctly emit IR for intrinsics like mm256_castsi128_si256 (D103874 
 has more context) efficient handling of this 
kind of pattern is necessary:

  %v = freeze  poison
  %w = shufflevector %a, %v, mask

The zeroinitializer folding is done by InstCombine's visitFreeze, which should 
be fixed maybe.
I'll play with some patterns and create patches for this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104790

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


[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-06-27 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh updated this revision to Diff 354737.
chh marked 7 inline comments as done.
chh added a comment.

update some comments and sync again with the latest clang/llvm source


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

https://reviews.llvm.org/D98710

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header1.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/skip-headers/my_header2.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-forward-declaration-namespace.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-interfaces-global-init.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-namespaces.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-objc-function-naming.m
  clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvm-prefer-register-over-unsigned.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-no-recursion.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx03.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-cxx11.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-pass-by-value-header.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-chained-conditional-return.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-members.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
  clang-tools-extra/test/clang-tidy/checkers/skip-headers.cpp
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp

Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1306,12 +1306,25 @@
MatchFinder::ParsingDoneTestCallback *ParsingDone)
   : Finder(Finder), ParsingDone(ParsingDone) {}
 
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+Finder->HandleTopLevelDecl(DG);
+return true;
+  }
+
 private:
   void HandleTranslationUnit(ASTContext &Context) override {
 if (ParsingDone != nullptr) {
   ParsingDone->run();
 }
-Finder->matchAST(Context);
+if (Finder->hasFilter()) {
+  auto SavedScope = Context.getTraversalScope();
+  auto &MyTopDecls = Finder->getTraversalScope();
+  Context.setTraversalScope(MyTopDecls);
+  Finder->matchAST(Context);
+  Context.setTraversalScope(SavedScope);
+} else {
+  Finder->matchAST(Context);
+}
   }
 
   MatchFinder *Finder;
@@ -1454,5 +1467,44 @@
   return llvm::None;
 }
 
+// Out of line key method.
+MatchFinder::MatchFinderOptions::DeclFilter::~DeclFilter() = default;
+
+template 
+bool isTemplateSpecializationKind(const NamedDecl *D,
+  TemplateSpecializationKind Kind) {
+  if (const auto *TD = dyn_cast(D))
+return TD->getTemplateSpecializationKind() == Kind;
+  return false;
+}
+
+bool isTemplateSpecializationKind(const NamedDecl *D,
+  TemplateSpecializationKind Kind) {
+  return isTemplateSpecializationKind(D, Kind) ||
+ isTemplateSpecializationKind(D, Kind) ||
+ isTemplateSpecializationKind(D, Kind);
+}
+
+bool isImplicitTemplateInstantiation(const NamedDecl *D) {
+  return isTemplateSpecializationKind(D, TSK_ImplicitInstantiation);
+}
+
+void MatchFinder::HandleTopLevelDecl(DeclGroupRef DG) {
+  if (hasFilter()) {
+for (Decl *D : DG) {
+  if (const NamedDecl *ND = dyn_cast(D))
+if (isImplicitTemplateInstantiation(ND))
+  continue;
+
+  // ObjCMethodDecl are not actually top-level decls.
+  if (isa(D))
+continue;
+
+  if (!Options.Filter->skipDecl(D))
+TopLevelDecls.push_back(D);
+}
+  }
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===
--- clang/include/clang

[PATCH] D98710: [clang-tidy] Add --skip-headers, part 1 (use setTraversalScope)

2021-06-27 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:431
+bool DeclFilter::skipLocation(SourceLocation Location) {
+  // do not skip non-file locations
+  if (!Location.isValid())

sammccall wrote:
> this comment didn't match the next line.
> Did you intend to check Location.isFile() instead?
I just wanted to make sure that we can get valid FileID.
Updated the comment.





Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:434
+return false;
+  auto FID = Sources.getDecomposedExpansionLoc(Location).first;
+  // Quick check against last checked results.

sammccall wrote:
> sammccall wrote:
> > maybe add a comment explaning why the expansion loc is chosen?
> note that this means we're going to traverse up the macro expansion edges 
> even if we're hitting the cache. You may want to cache under the original 
> file ID instead?
This is to match the ClangTidyDiagnosticConsumer::checkFilters.
Do you think some other get*Location method should be used in both places?




Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:434
+return false;
+  auto FID = Sources.getDecomposedExpansionLoc(Location).first;
+  // Quick check against last checked results.

chh wrote:
> sammccall wrote:
> > sammccall wrote:
> > > maybe add a comment explaning why the expansion loc is chosen?
> > note that this means we're going to traverse up the macro expansion edges 
> > even if we're hitting the cache. You may want to cache under the original 
> > file ID instead?
> This is to match the ClangTidyDiagnosticConsumer::checkFilters.
> Do you think some other get*Location method should be used in both places?
> 
I would rather explore various cache performance improvements in follow up CLs.
In my performance tests, current simple check of LastAcceptedFileID and 
LastSkippedFileID already has very high hit rate due to sequential check of 
Decls in the included header files. More caching improvements should produce 
relatively smaller difference, which will be shown/visible easier in their own 
small change CLs.




Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:436
+  // Quick check against last checked results.
+  if (FID == LastSkippedFileID)
+return true;

sammccall wrote:
> caching all results in a DenseMap seems likely to perform 
> better, no?
I am sure most calls hit the last FileID. For the missed calls, I was planning 
to add other caching mechanism in skipFileID function. That could be in follow 
up CLs with more accurate measurements to compare the overhead vs hit rate.




Comment at: clang/include/clang/ASTMatchers/ASTMatchFinder.h:148
+/// Check if a Decl should be skipped.
+std::shared_ptr Filter;
   };

sammccall wrote:
> hokein wrote:
> > chh wrote:
> > > sammccall wrote:
> > > > I don't think the filter belongs here.
> > > > The design of traversal scope is that it's a property of the AST that 
> > > > affects all traversals, so it shouldn't be a configuration property of 
> > > > particular traversals like ASTMatchFinder.
> > > > 
> > > > There's a question of what to do about `MatchFinder::newASTConsumer()`, 
> > > > which runs the finder immediately after an AST is created, and so 
> > > > covers the point at which we might set a scope. There are several good 
> > > > options, e.g.:
> > > >  - Don't provide any facility for setting traversal scope when 
> > > > newASTConsumer() is used - it's not commonly needed, and the 
> > > > ASTConsumer is trivial to reimplement where that's actually needed
> > > >  - Accept an optional `function` which should run 
> > > > just before matching starts
> > > > 
> > > > This seems a bit subtle, but the difference between having this in 
> > > > MatchFinder proper vs just in newASTConsumer() is important I think, 
> > > > precisely because it's common to run the matchers directly on an 
> > > > existing AST.
> > > > 
> > > I have some similar concerns too.
> > > 
> > > clangd calls MatchFinder::matchAST explicitly after setTraversalScope,
> > > but clang-tidy uses MultiplexConsumer and MatchFinder::newASTConsumer
> > > is just one of the two consumers.
> > > (1) I am not sure if it would be safe or even work to make big changes in
> > > ClangTidy.cpp's CreateASTConsumer to call MatchFinder::matchAST 
> > > explicitly.
> > > (2) Similarly, I wonder if setTraversalScope will work for both 
> > > MatchFinder
> > > and other consumers in the same MultiplexConsumer.
> > > 
> > > Could you check if my current change to MatchFinder::HandleTranslationUnit
> > > is right, especially in the saving/restoring of traversal scope?
> > > 
> > > I am assuming that each consumer in a MultiplexConsumer will have its own
> > > chance to HandleTranslationUnit and HandleTopLevelDecl.
> > > If that's correct, it seems to me that changing those two handlers in
> > > MatchFinder is 

[PATCH] D104900: [clang-format] PR50525 doesn't handle AlignConsecutiveAssignments correctly in some situations

2021-06-27 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D104900#2842540 , @darwin wrote:

> Sorry I haven't had a chance to look at this bug before it has closed. But I 
> do have a question:
>
> I observed that this code are formatted incorrectly by the same config:
>
>   llvm::Optional CurrentCode = None;
>   autoEnv = std::make_unique(Code,
>FileName,
>Ranges,
>FirstStartColumn,
>NextStartColumn,
>LastStartColumn);
>
> Can this solution solve this issue? I am afraid not.
>
> If no, should I open a new bug for it?

If this is indeed a bug  you need to log its, I think it highly unlikey that 
its related, make sure you include your .clang-format file (and remove non 
impacting options)

I tested this example and it looked to work correctly (but it depends on your 
options I suspect):

  Language: Cpp
  BasedOnStyle: LLVM
  AlignConsecutiveDeclarations: true
  AlignConsecutiveAssignments: true
  ColumnLimit: 80



  llvm::Optional CurrentCode = None;
  autoEnv = std::make_unique(
  Code, FileName, Ranges, FirstStartColumn, NextStartColumn, 
LastStartColumn);


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104900

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


[PATCH] D104388: [clang-format] PR50727 C# Invoke Lamda Expression indentation incorrect

2021-06-27 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

ping


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

https://reviews.llvm.org/D104388

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


[PATCH] D104044: [clang-format] Fix the issue that empty lines being removed at the beginning of namespace

2021-06-27 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:1270
   !startsExternCBlock(*PreviousLine))
 Newlines = 1;
 

Nit:I do think at some point we need to have some sort of option for 
controlling these empty lines, 


EmptyLine:
 AfterNamespace: 1
 BeforeAccessModifier: 1
 AfterAccessModifier: 1
 BetweenFunctions: 1
 ...



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

https://reviews.llvm.org/D104044

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


[PATCH] D104981: [clang-tidy] Add -line-filter to run-clang-tidy.py

2021-06-27 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added reviewers: njames93, kbobyrev.
xgupta added a comment.

Assuming this is your first patch, I add two reviewers for this patch who touch 
this file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104981

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


[clang] e5a8f23 - [clang-format] Fix the issue that empty lines being removed at the beginning of namespace

2021-06-27 Thread via cfe-commits

Author: Darwin Xu
Date: 2021-06-27T15:59:21+01:00
New Revision: e5a8f230c765aebff34221cb3e084316496fc08e

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

LOG: [clang-format] Fix the issue that empty lines being removed at the 
beginning of namespace

This is a bug fix of https://bugs.llvm.org/show_bug.cgi?id=50116

Reviewed By: MyDeveloperDay

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 3255c71d3407..cca85c1074de 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1134,6 +1134,7 @@ unsigned UnwrappedLineFormatter::format(
   unsigned Penalty = 0;
   LevelIndentTracker IndentTracker(Style, Keywords, Lines[0]->Level,
AdditionalIndent);
+  const AnnotatedLine *PrevPrevLine = nullptr;
   const AnnotatedLine *PreviousLine = nullptr;
   const AnnotatedLine *NextLine = nullptr;
 
@@ -1172,7 +1173,7 @@ unsigned UnwrappedLineFormatter::format(
 if (ShouldFormat && TheLine.Type != LT_Invalid) {
   if (!DryRun) {
 bool LastLine = Line->First->is(tok::eof);
-formatFirstToken(TheLine, PreviousLine, Lines, Indent,
+formatFirstToken(TheLine, PreviousLine, PrevPrevLine, Lines, Indent,
  LastLine ? LastStartColumn : NextStartColumn + 
Indent);
   }
 
@@ -1218,7 +1219,7 @@ unsigned UnwrappedLineFormatter::format(
   TheLine.LeadingEmptyLinesAffected);
 // Format the first token.
 if (ReformatLeadingWhitespace)
-  formatFirstToken(TheLine, PreviousLine, Lines,
+  formatFirstToken(TheLine, PreviousLine, PrevPrevLine, Lines,
TheLine.First->OriginalColumn,
TheLine.First->OriginalColumn);
 else
@@ -1234,6 +1235,7 @@ unsigned UnwrappedLineFormatter::format(
 }
 if (!DryRun)
   markFinalized(TheLine.First);
+PrevPrevLine = PreviousLine;
 PreviousLine = &TheLine;
   }
   PenaltyCache[CacheKey] = Penalty;
@@ -1242,6 +1244,7 @@ unsigned UnwrappedLineFormatter::format(
 
 void UnwrappedLineFormatter::formatFirstToken(
 const AnnotatedLine &Line, const AnnotatedLine *PreviousLine,
+const AnnotatedLine *PrevPrevLine,
 const SmallVectorImpl &Lines, unsigned Indent,
 unsigned NewlineIndent) {
   FormatToken &RootToken = *Line.First;
@@ -1273,6 +1276,8 @@ void UnwrappedLineFormatter::formatFirstToken(
   if (!Style.KeepEmptyLinesAtTheStartOfBlocks && PreviousLine &&
   PreviousLine->Last->is(tok::l_brace) &&
   !PreviousLine->startsWithNamespace() &&
+  !(PrevPrevLine && PrevPrevLine->startsWithNamespace() &&
+PreviousLine->startsWith(tok::l_brace)) &&
   !startsExternCBlock(*PreviousLine))
 Newlines = 1;
 

diff  --git a/clang/lib/Format/UnwrappedLineFormatter.h 
b/clang/lib/Format/UnwrappedLineFormatter.h
index a1ff16999589..3e33de07fa12 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.h
+++ b/clang/lib/Format/UnwrappedLineFormatter.h
@@ -47,6 +47,7 @@ class UnwrappedLineFormatter {
   /// of the \c UnwrappedLine if there was no structural parsing error.
   void formatFirstToken(const AnnotatedLine &Line,
 const AnnotatedLine *PreviousLine,
+const AnnotatedLine *PrevPrevLine,
 const SmallVectorImpl &Lines,
 unsigned Indent, unsigned NewlineIndent);
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index e5fa17270cdf..6747fe749a2f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -262,6 +262,128 @@ TEST_F(FormatTest, RemovesEmptyLines) {
"}",
getGoogleStyle()));
 
+  auto CustomStyle = clang::format::getLLVMStyle();
+  CustomStyle.BreakBeforeBraces = clang::format::FormatStyle::BS_Custom;
+  CustomStyle.BraceWrapping.AfterNamespace = true;
+  CustomStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
+  EXPECT_EQ("namespace N\n"
+"{\n"
+"\n"
+"int i;\n"
+"}",
+format("namespace N\n"
+   "{\n"
+   "\n"
+   "\n"
+   "inti;\n"
+   "}",
+   CustomStyle));
+  EXPECT_EQ("/* something */ namespace N\n"
+"{\n"
+"\n"
+"int i;\n"
+"}",
+format("/* somethin

[PATCH] D104044: [clang-format] Fix the issue that empty lines being removed at the beginning of namespace

2021-06-27 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe5a8f230c765: [clang-format] Fix the issue that empty lines 
being removed at the beginning of… (authored by darwin, committed by 
MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104044

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineFormatter.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -262,6 +262,128 @@
"}",
getGoogleStyle()));
 
+  auto CustomStyle = clang::format::getLLVMStyle();
+  CustomStyle.BreakBeforeBraces = clang::format::FormatStyle::BS_Custom;
+  CustomStyle.BraceWrapping.AfterNamespace = true;
+  CustomStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
+  EXPECT_EQ("namespace N\n"
+"{\n"
+"\n"
+"int i;\n"
+"}",
+format("namespace N\n"
+   "{\n"
+   "\n"
+   "\n"
+   "inti;\n"
+   "}",
+   CustomStyle));
+  EXPECT_EQ("/* something */ namespace N\n"
+"{\n"
+"\n"
+"int i;\n"
+"}",
+format("/* something */ namespace N {\n"
+   "\n"
+   "\n"
+   "inti;\n"
+   "}",
+   CustomStyle));
+  EXPECT_EQ("inline namespace N\n"
+"{\n"
+"\n"
+"int i;\n"
+"}",
+format("inline namespace N\n"
+   "{\n"
+   "\n"
+   "\n"
+   "inti;\n"
+   "}",
+   CustomStyle));
+  EXPECT_EQ("/* something */ inline namespace N\n"
+"{\n"
+"\n"
+"int i;\n"
+"}",
+format("/* something */ inline namespace N\n"
+   "{\n"
+   "\n"
+   "inti;\n"
+   "}",
+   CustomStyle));
+  EXPECT_EQ("export namespace N\n"
+"{\n"
+"\n"
+"int i;\n"
+"}",
+format("export namespace N\n"
+   "{\n"
+   "\n"
+   "inti;\n"
+   "}",
+   CustomStyle));
+  EXPECT_EQ("namespace a\n"
+"{\n"
+"namespace b\n"
+"{\n"
+"\n"
+"class AA {};\n"
+"\n"
+"} // namespace b\n"
+"} // namespace a\n",
+format("namespace a\n"
+   "{\n"
+   "namespace b\n"
+   "{\n"
+   "\n"
+   "\n"
+   "class AA {};\n"
+   "\n"
+   "\n"
+   "}\n"
+   "}\n",
+   CustomStyle));
+  EXPECT_EQ("namespace A /* comment */\n"
+"{\n"
+"class B {}\n"
+"} // namespace A",
+format("namespace A /* comment */ { class B {} }", CustomStyle));
+  EXPECT_EQ("namespace A\n"
+"{ /* comment */\n"
+"class B {}\n"
+"} // namespace A",
+format("namespace A {/* comment */ class B {} }", CustomStyle));
+  EXPECT_EQ("namespace A\n"
+"{ /* comment */\n"
+"\n"
+"class B {}\n"
+"\n"
+""
+"} // namespace A",
+format("namespace A { /* comment */\n"
+   "\n"
+   "\n"
+   "class B {}\n"
+   "\n"
+   "\n"
+   "}",
+   CustomStyle));
+  EXPECT_EQ("namespace A /* comment */\n"
+"{\n"
+"\n"
+"class B {}\n"
+"\n"
+"} // namespace A",
+format("namespace A/* comment */ {\n"
+   "\n"
+   "\n"
+   "class B {}\n"
+   "\n"
+   "\n"
+   "}",
+   CustomStyle));
+
   // ...but do keep inlining and removing empty lines for non-block extern "C"
   // functions.
   verifyFormat("extern \"C\" int f() { return 42; }", getGoogleStyle());
Index: clang/lib/Format/UnwrappedLineFormatter.h
===
--- clang/lib/Format/UnwrappedLineFormatter.h
+++ clang/lib/Format/UnwrappedLineFormatter.h
@@ -47,6 +47,7 @@
   /// of the \c UnwrappedLine if there was no structural parsing error.
   void formatFirstToken(const AnnotatedLine &Line,

[PATCH] D90238: [clang-format] Added ReferenceAlignmentStyle option - (Update to D31635)

2021-06-27 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

@catskul  can we now Abandon this revision seeing as D104096: [Clang-Format] 
Add ReferenceAlignment directive  is landed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90238

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


[PATCH] D104991: [PowerPC] Add XL Compat fetch builtins

2021-06-27 Thread Jinsong Ji via Phabricator via cfe-commits
jsji created this revision.
jsji added reviewers: PowerPC, w2yehia, lkail, shchenz, Whitney.
Herald added subscribers: jfb, kbarton, nemanjai.
jsji requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Prototype
unsigned int __fetch_and_add (volatile unsigned int* addr, unsigned int
val);
unsigned long __fetch_and_addlp (volatile unsigned long* addr, unsigned
long val);

Ref:
https://www.ibm.com/docs/en/xl-c-and-cpp-linux/16.1.1?topic=functions-fetch


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104991

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-fetch-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-fetch.c

Index: clang/test/CodeGen/builtins-ppc-xlcompat-fetch.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-fetch.c
@@ -0,0 +1,120 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown \
+// RUN:-emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown \
+// RUN:   -emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s
+
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_add(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A:%.*]], i32* [[A_ADDR]], align 4
+// CHECK-NEXT:store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw add i32* [[A_ADDR]], i32 [[TMP1]] monotonic, align 4
+// CHECK-NEXT:ret void
+//
+void test_builtin_ppc_fetch_and_add(unsigned int a, unsigned int b) {
+  __fetch_and_add(&a, b);
+}
+
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_addlp(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
+// CHECK-NEXT:store i64 [[B:%.*]], i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i64, i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw add i64* [[A_ADDR]], i64 [[TMP1]] monotonic, align 8
+// CHECK-NEXT:ret void
+//
+void test_builtin_ppc_fetch_and_addlp(unsigned long a, unsigned long b) {
+  __fetch_and_addlp(&a, b);
+}
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_and(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A:%.*]], i32* [[A_ADDR]], align 4
+// CHECK-NEXT:store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw and i32* [[A_ADDR]], i32 [[TMP1]] monotonic, align 4
+// CHECK-NEXT:ret void
+//
+void test_builtin_ppc_fetch_and_and(unsigned int a, unsigned int b) {
+  __fetch_and_and(&a, b);
+}
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_andlp(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
+// CHECK-NEXT:store i64 [[B:%.*]], i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i64, i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw and i64* [[A_ADDR]], i64 [[TMP1]] monotonic, align 8
+// CHECK-NEXT:ret void
+//
+void test_builtin_ppc_fetch_and_andlp(unsigned long a, unsigned long b) {
+  __fetch_and_andlp(&a, b);
+}
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_or(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A:%.*]], i32* [[A_ADDR]], align 4
+// CHECK-NEXT:store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw or i32* [[A_ADDR]], i32 [[TMP1]] monotonic, align 4
+// CHECK-NEXT:ret void
+//
+void test_builtin_ppc_fetch_and_or(unsigned int a, unsigned int b) {
+  __fetch_and_or(&a, b);
+}
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_orlp(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i64, alig

[PATCH] D104952: [hexagon] Add {hvx,}hexagon_{protos,circ_brev...}

2021-06-27 Thread Brian Cain via Phabricator via cfe-commits
bcain updated this revision to Diff 354758.
bcain added a comment.

Add hexagon_types.h and additional test cases.  Updated existing test case to 
use types defined in hexagon_types.h.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104952

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/hexagon_circ_brev_intrinsics.h
  clang/lib/Headers/hexagon_protos.h
  clang/lib/Headers/hexagon_types.h
  clang/lib/Headers/hvx_hexagon_protos.h
  clang/test/Headers/hexagon-audio-headers.c
  clang/test/Headers/hexagon-headers.c
  clang/test/Headers/hexagon-hvx-headers.c

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


[PATCH] D104981: [clang-tidy] Add -line-filter to run-clang-tidy.py

2021-06-27 Thread Vincent LE GARREC via Phabricator via cfe-commits
bansan added a comment.

Right, this is my first patch. I based this one on 
https://reviews.llvm.org/D28334


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104981

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


[PATCH] D104500: [clang] Apply P1825 as Defect Report from C++11 up to C++20.

2021-06-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 354773.
mizvekov added a comment.

This introduces two new test cases that cover the bug fixed by the previous 
diff:

- The one suggested by rsmith in the comments above.
- Another one that shows that when both const and non-const lvref conversion 
operators where available, we would not pick the const one on the first 
overload resolution, and end up picking the non-const one on the second.

Trying to think of explanations of how we got this bug in the first place,
I think it boils down to the fact that the first overload resolution was
jerry-rigged into (trying to, unsuccessfully) bailing out in cases where it
would have succceeded without the xvalueness of the expression mattering, and
so the second overload would have hopefully done the same operation, without
affecting the meaning of the program.

The reason for this was diagnostics, it was necessary to get information on 
whether
casting the expression to rvref would have helped in order to implement the 
std-move
suggestions. As specified in the standard, the first overload resolution would 
often
just succeed where it would not have made a difference if the cast was there or 
not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104500

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/conversion-function.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/test/SemaObjCXX/block-capture.mm

Index: clang/test/SemaObjCXX/block-capture.mm
===
--- clang/test/SemaObjCXX/block-capture.mm
+++ clang/test/SemaObjCXX/block-capture.mm
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b,cxx2b %s
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b   %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx98_11   %s
-// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b,cxx98_11   %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx11_2b,cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx11_2b   %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx11_2b   %s
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b,cxx98  %s
 
 #define TEST(T) void test_##T() { \
   __block T x;\
@@ -14,54 +14,68 @@
 };
 TEST(CopyOnly); // cxx2b-error {{no matching constructor}}
 
+struct ConstCopyOnly {
+  ConstCopyOnly();
+  ConstCopyOnly(ConstCopyOnly &) = delete; // cxx98-note {{marked deleted here}}
+  ConstCopyOnly(const ConstCopyOnly &);
+};
+TEST(ConstCopyOnly); // cxx98-error {{call to deleted constructor}}
+
+struct NonConstCopyOnly {
+  NonConstCopyOnly();
+  NonConstCopyOnly(NonConstCopyOnly &);
+  NonConstCopyOnly(const NonConstCopyOnly &) = delete; // cxx11_2b-note {{marked deleted here}}
+};
+TEST(NonConstCopyOnly); // cxx11_2b-error {{call to deleted constructor}}
+
 struct CopyNoMove {
   CopyNoMove();
   CopyNoMove(CopyNoMove &);
-  CopyNoMove(CopyNoMove &&) = delete; // cxx98_2b-note {{marked deleted here}}
+  CopyNoMove(CopyNoMove &&) = delete; // cxx11_2b-note {{marked deleted here}}
 };
-TEST(CopyNoMove); // cxx98_2b-error {{call to deleted constructor}}
+TEST(CopyNoMove); // cxx11_2b-error {{call to deleted constructor}}
 
 struct MoveOnly {
   MoveOnly();
-  MoveOnly(MoveOnly &) = delete;
+  MoveOnly(MoveOnly &) = delete; // cxx98-note {{marked deleted here}}
   MoveOnly(MoveOnly &&);
 };
-TEST(MoveOnly);
+TEST(MoveOnly); // cxx98-error {{call to deleted constructor}}
 
 struct NoCopyNoMove {
   NoCopyNoMove();
-  NoCopyNoMove(NoCopyNoMove &) = delete;
-  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx98_2b-note {{marked deleted here}}
+  NoCopyNoMove(NoCopyNoMove &) = delete;  // cxx98-note {{marked deleted here}}
+  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx11_2b-note {{marked deleted here}}
 };
 TEST(NoCopyNoMove); // cxx98_2b-error {{call to deleted constructor}}
 
 struct ConvertingRVRef {
   ConvertingRVRef();
-  ConvertingRVRef(ConvertingRVRef &) = delete; // cxx98_11-note {{marked deleted here}}
+  ConvertingRVRef(ConvertingRVRef &) = delete; // cxx98-note {{marked deleted here}}
 
   struct X {};
   ConvertingRVRef(X &&);
   operator X() const & = delete;
   operator X() &&;
 };
-TEST(ConvertingRVRef); // cxx98_11-error {{call to deleted constructor}}
+TEST(Converting

[PATCH] D104500: [clang] Apply P1825 as Defect Report from C++11 up to C++20.

2021-06-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov marked 2 inline comments as done.
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaStmt.cpp:3544
-// taking an rvalue reference.
-if (cast(FD)->getRefQualifier() != RQ_RValue)
-  break;

If there was a `IsDiagnosticsCheck &&` check here just as there is above for 
the constructor case, this bug could have been confined to a diagnostic issue 
only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104500

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


[PATCH] D104500: [clang] Apply P1825 as Defect Report from C++11 up to C++20.

2021-06-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 354776.
mizvekov added a comment.

format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104500

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/conversion-function.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/test/SemaObjCXX/block-capture.mm

Index: clang/test/SemaObjCXX/block-capture.mm
===
--- clang/test/SemaObjCXX/block-capture.mm
+++ clang/test/SemaObjCXX/block-capture.mm
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b,cxx2b %s
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx20_2b   %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx98_11   %s
-// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b,cxx98_11   %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx11_2b,cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx11_2b   %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_2b,cxx11_2b   %s
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_2b,cxx98  %s
 
 #define TEST(T) void test_##T() { \
   __block T x;\
@@ -14,54 +14,68 @@
 };
 TEST(CopyOnly); // cxx2b-error {{no matching constructor}}
 
+struct ConstCopyOnly {
+  ConstCopyOnly();
+  ConstCopyOnly(ConstCopyOnly &) = delete; // cxx98-note {{marked deleted here}}
+  ConstCopyOnly(const ConstCopyOnly &);
+};
+TEST(ConstCopyOnly); // cxx98-error {{call to deleted constructor}}
+
+struct NonConstCopyOnly {
+  NonConstCopyOnly();
+  NonConstCopyOnly(NonConstCopyOnly &);
+  NonConstCopyOnly(const NonConstCopyOnly &) = delete; // cxx11_2b-note {{marked deleted here}}
+};
+TEST(NonConstCopyOnly); // cxx11_2b-error {{call to deleted constructor}}
+
 struct CopyNoMove {
   CopyNoMove();
   CopyNoMove(CopyNoMove &);
-  CopyNoMove(CopyNoMove &&) = delete; // cxx98_2b-note {{marked deleted here}}
+  CopyNoMove(CopyNoMove &&) = delete; // cxx11_2b-note {{marked deleted here}}
 };
-TEST(CopyNoMove); // cxx98_2b-error {{call to deleted constructor}}
+TEST(CopyNoMove); // cxx11_2b-error {{call to deleted constructor}}
 
 struct MoveOnly {
   MoveOnly();
-  MoveOnly(MoveOnly &) = delete;
+  MoveOnly(MoveOnly &) = delete; // cxx98-note {{marked deleted here}}
   MoveOnly(MoveOnly &&);
 };
-TEST(MoveOnly);
+TEST(MoveOnly); // cxx98-error {{call to deleted constructor}}
 
 struct NoCopyNoMove {
   NoCopyNoMove();
-  NoCopyNoMove(NoCopyNoMove &) = delete;
-  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx98_2b-note {{marked deleted here}}
+  NoCopyNoMove(NoCopyNoMove &) = delete;  // cxx98-note {{marked deleted here}}
+  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx11_2b-note {{marked deleted here}}
 };
 TEST(NoCopyNoMove); // cxx98_2b-error {{call to deleted constructor}}
 
 struct ConvertingRVRef {
   ConvertingRVRef();
-  ConvertingRVRef(ConvertingRVRef &) = delete; // cxx98_11-note {{marked deleted here}}
+  ConvertingRVRef(ConvertingRVRef &) = delete; // cxx98-note {{marked deleted here}}
 
   struct X {};
   ConvertingRVRef(X &&);
   operator X() const & = delete;
   operator X() &&;
 };
-TEST(ConvertingRVRef); // cxx98_11-error {{call to deleted constructor}}
+TEST(ConvertingRVRef); // cxx98-error {{call to deleted constructor}}
 
 struct ConvertingCLVRef {
   ConvertingCLVRef();
   ConvertingCLVRef(ConvertingCLVRef &);
 
   struct X {};
-  ConvertingCLVRef(X &&); // cxx20_2b-note {{passing argument to parameter here}}
+  ConvertingCLVRef(X &&); // cxx11_2b-note {{passing argument to parameter here}}
   operator X() const &;
-  operator X() && = delete; // cxx20_2b-note {{marked deleted here}}
+  operator X() && = delete; // cxx11_2b-note {{marked deleted here}}
 };
-TEST(ConvertingCLVRef); // cxx20_2b-error {{invokes a deleted function}}
+TEST(ConvertingCLVRef); // cxx11_2b-error {{invokes a deleted function}}
 
 struct SubSubMove {};
 struct SubMove : SubSubMove {
   SubMove();
-  SubMove(SubMove &) = delete; // cxx98_11-note {{marked deleted here}}
+  SubMove(SubMove &) = delete; // cxx98-note {{marked deleted here}}
 
   SubMove(SubSubMove &&);
 };
-TEST(SubMove); // cxx98_11-error {{call to deleted constructor}}
+TEST(SubMove); // cxx98-error {{call to deleted constructor}}
Index: clang/test/SemaCXX/warn-return-std-move.cpp
=

[PATCH] D99005: [clang] Implement P2266 Simpler implicit move

2021-06-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

Thank you again @sberg.

I have talked to the MSVC STL maintainers. They would be open to a pull request 
for fixing this.
The repo can be found at https://github.com/microsoft/STL
Be my guest if you want to submit that fix yourself.
If not, I can probably do it in the near future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

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


[clang] 3a6599b - Remove XFAIL flag from sanitize-coverage-old-pm.c

2021-06-27 Thread Muhammad Omair Javaid via cfe-commits

Author: Muhammad Omair Javaid
Date: 2021-06-28T03:38:08+05:00
New Revision: 3a6599b7bd0fe4fe579e0abd9bd882ea964dd627

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

LOG: Remove XFAIL flag from sanitize-coverage-old-pm.c

This test has started passing consistently on 32bit arm where underlying
core is reported as Armv7 or Thumbv7.
However it still fails intermittently on 32bit AArch32 reported as Armv8l.

https://lab.llvm.org/buildbot/#/builders/190/builds/20
https://lab.llvm.org/buildbot/#/builders/170/builds/41

Added: 


Modified: 
clang/test/CodeGen/sanitize-coverage-old-pm.c

Removed: 




diff  --git a/clang/test/CodeGen/sanitize-coverage-old-pm.c 
b/clang/test/CodeGen/sanitize-coverage-old-pm.c
index cbed401b1e02..ec84de1c024c 100644
--- a/clang/test/CodeGen/sanitize-coverage-old-pm.c
+++ b/clang/test/CodeGen/sanitize-coverage-old-pm.c
@@ -6,8 +6,7 @@
 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S 
-fsanitize=undefined  -fsanitize-coverage=trace-pc,trace-cmp -o - 
-flegacy-pass-manager | FileCheck %s --check-prefixes=CHECK,UBSAN
 //
 // Host armv7 is currently unsupported: 
https://bugs.llvm.org/show_bug.cgi?id=46117
-// UNSUPPORTED: armv8l
-// XFAIL: armv7, thumbv7
+// XFAIL: armv8l
 // The same issue also occurs on a riscv32 host.
 // XFAIL: riscv32
 



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


[PATCH] D104852: [AArch64][SVEIntrinsicOpts] Convect cntb/h/w/d to vscale intrinsic or constant.

2021-06-27 Thread JunMa via Phabricator via cfe-commits
junparser added a comment.

@sdesmalen @david-arm @paulwalker-arm kindly ping~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104852

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


[PATCH] D104991: [PowerPC] Add XL Compat fetch builtins

2021-06-27 Thread Kai Luo via Phabricator via cfe-commits
lkail accepted this revision.
lkail added a comment.

LGTM, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104991

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


[clang] 2ddca68 - Tag sanitize-coverage-old-pm.c unsupported on arm 32 bit

2021-06-27 Thread Muhammad Omair Javaid via cfe-commits

Author: Muhammad Omair Javaid
Date: 2021-06-28T07:19:11+05:00
New Revision: 2ddca686ee8fd73d4b6630b60794be82caa4c311

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

LOG: Tag sanitize-coverage-old-pm.c unsupported on arm 32 bit

This test is again failing across multiple bots and passing on others
there is no reliable way to enable it for some of the bots while
disabling for the unsupported ones. Tagging it as unsupported across all
types of Arm 32 bit cores.

Added: 


Modified: 
clang/test/CodeGen/sanitize-coverage-old-pm.c

Removed: 




diff  --git a/clang/test/CodeGen/sanitize-coverage-old-pm.c 
b/clang/test/CodeGen/sanitize-coverage-old-pm.c
index ec84de1c024c..ff37eda464a8 100644
--- a/clang/test/CodeGen/sanitize-coverage-old-pm.c
+++ b/clang/test/CodeGen/sanitize-coverage-old-pm.c
@@ -6,7 +6,7 @@
 // RUN: %clang %s -target x86_64-unknown-linux-gnu -emit-llvm -S 
-fsanitize=undefined  -fsanitize-coverage=trace-pc,trace-cmp -o - 
-flegacy-pass-manager | FileCheck %s --check-prefixes=CHECK,UBSAN
 //
 // Host armv7 is currently unsupported: 
https://bugs.llvm.org/show_bug.cgi?id=46117
-// XFAIL: armv8l
+// UNSUPPORTED: armv7, thumbv7, armv8l
 // The same issue also occurs on a riscv32 host.
 // XFAIL: riscv32
 



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


[clang] eb237ff - [PowerPC] Add XL Compat fetch builtins

2021-06-27 Thread Jinsong Ji via cfe-commits

Author: Jinsong Ji
Date: 2021-06-28T02:52:32Z
New Revision: eb237ffca821839374574b2195c865765ebf5d09

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

LOG: [PowerPC] Add XL Compat fetch builtins

Prototype
```
unsigned int __fetch_and_add (volatile unsigned int* addr, unsigned int
val);
unsigned long __fetch_and_addlp (volatile unsigned long* addr, unsigned
long val);
```
Ref:
https://www.ibm.com/docs/en/xl-c-and-cpp-linux/16.1.1?topic=functions-fetch

Reviewed By: #powerpc, w2yehia, lkail

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

Added: 
clang/test/CodeGen/builtins-ppc-xlcompat-fetch-error.c
clang/test/CodeGen/builtins-ppc-xlcompat-fetch.c

Modified: 
clang/include/clang/Basic/BuiltinsPPC.def
clang/lib/Basic/Targets/PPC.cpp
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index 47b485473342b..e07632d415109 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -47,6 +47,14 @@ BUILTIN(__builtin_ppc_dcbz, "vv*", "")
 BUILTIN(__builtin_ppc_icbt, "vv*", "")
 BUILTIN(__builtin_ppc_compare_and_swap, "iiD*i*i", "")
 BUILTIN(__builtin_ppc_compare_and_swaplp, "iLiD*Li*Li", "")
+BUILTIN(__builtin_ppc_fetch_and_add, "UiUiD*Ui", "")
+BUILTIN(__builtin_ppc_fetch_and_addlp, "ULiULiD*ULi", "")
+BUILTIN(__builtin_ppc_fetch_and_and, "UiUiD*Ui", "")
+BUILTIN(__builtin_ppc_fetch_and_andlp, "ULiULiD*ULi", "")
+BUILTIN(__builtin_ppc_fetch_and_or, "UiUiD*Ui", "")
+BUILTIN(__builtin_ppc_fetch_and_orlp, "ULiULiD*ULi", "")
+BUILTIN(__builtin_ppc_fetch_and_swap, "UiUiD*Ui", "")
+BUILTIN(__builtin_ppc_fetch_and_swaplp, "ULiULiD*ULi", "")
 
 BUILTIN(__builtin_ppc_get_timebase, "ULLi", "n")
 

diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index e051826c52168..6860b5e5d02fa 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -100,6 +100,14 @@ static void defineXLCompatMacros(MacroBuilder &Builder) {
   Builder.defineMacro("__compare_and_swap", "__builtin_ppc_compare_and_swap");
   Builder.defineMacro("__compare_and_swaplp",
   "__builtin_ppc_compare_and_swaplp");
+  Builder.defineMacro("__fetch_and_add", "__builtin_ppc_fetch_and_add");
+  Builder.defineMacro("__fetch_and_addlp", "__builtin_ppc_fetch_and_addlp");
+  Builder.defineMacro("__fetch_and_and", "__builtin_ppc_fetch_and_and");
+  Builder.defineMacro("__fetch_and_andlp", "__builtin_ppc_fetch_and_andlp");
+  Builder.defineMacro("__fetch_and_or", "__builtin_ppc_fetch_and_or");
+  Builder.defineMacro("__fetch_and_orlp", "__builtin_ppc_fetch_and_orlp");
+  Builder.defineMacro("__fetch_and_swap", "__builtin_ppc_fetch_and_swap");
+  Builder.defineMacro("__fetch_and_swaplp", "__builtin_ppc_fetch_and_swaplp");
 }
 
 /// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 97f2db9bec2c8..2e9454921ffa8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -15440,6 +15440,27 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Monotonic, 
true);
 return Pair.second;
   }
+  case PPC::BI__builtin_ppc_fetch_and_add:
+  case PPC::BI__builtin_ppc_fetch_and_addlp: {
+return MakeBinaryAtomicValue(*this, AtomicRMWInst::Add, E,
+ llvm::AtomicOrdering::Monotonic);
+  }
+  case PPC::BI__builtin_ppc_fetch_and_and:
+  case PPC::BI__builtin_ppc_fetch_and_andlp: {
+return MakeBinaryAtomicValue(*this, AtomicRMWInst::And, E,
+ llvm::AtomicOrdering::Monotonic);
+  }
+
+  case PPC::BI__builtin_ppc_fetch_and_or:
+  case PPC::BI__builtin_ppc_fetch_and_orlp: {
+return MakeBinaryAtomicValue(*this, AtomicRMWInst::Or, E,
+ llvm::AtomicOrdering::Monotonic);
+  }
+  case PPC::BI__builtin_ppc_fetch_and_swap:
+  case PPC::BI__builtin_ppc_fetch_and_swaplp: {
+return MakeBinaryAtomicValue(*this, AtomicRMWInst::Xchg, E,
+ llvm::AtomicOrdering::Monotonic);
+  }
   }
 }
 

diff  --git a/clang/test/CodeGen/builtins-ppc-xlcompat-fetch-error.c 
b/clang/test/CodeGen/builtins-ppc-xlcompat-fetch-error.c
new file mode 100644
index 0..a5124e3c10e93
--- /dev/null
+++ b/clang/test/CodeGen/builtins-ppc-xlcompat-fetch-error.c
@@ -0,0 +1,17 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -target-cpu pwr8 \
+// RUN:  -verify %s
+
+void test_builtin_ppc_fetch_and_add2() {
+  volatile int a = 0;
+  unsigned int b = 0;
+
+  __fetch_and_

[PATCH] D104991: [PowerPC] Add XL Compat fetch builtins

2021-06-27 Thread Jinsong Ji via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb237ffca821: [PowerPC] Add XL Compat fetch builtins 
(authored by jsji).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104991

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-fetch-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-fetch.c

Index: clang/test/CodeGen/builtins-ppc-xlcompat-fetch.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-fetch.c
@@ -0,0 +1,120 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown \
+// RUN:-emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown \
+// RUN:   -emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s
+
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_add(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A:%.*]], i32* [[A_ADDR]], align 4
+// CHECK-NEXT:store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw add i32* [[A_ADDR]], i32 [[TMP1]] monotonic, align 4
+// CHECK-NEXT:ret void
+//
+void test_builtin_ppc_fetch_and_add(unsigned int a, unsigned int b) {
+  __fetch_and_add(&a, b);
+}
+
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_addlp(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
+// CHECK-NEXT:store i64 [[B:%.*]], i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i64, i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw add i64* [[A_ADDR]], i64 [[TMP1]] monotonic, align 8
+// CHECK-NEXT:ret void
+//
+void test_builtin_ppc_fetch_and_addlp(unsigned long a, unsigned long b) {
+  __fetch_and_addlp(&a, b);
+}
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_and(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A:%.*]], i32* [[A_ADDR]], align 4
+// CHECK-NEXT:store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw and i32* [[A_ADDR]], i32 [[TMP1]] monotonic, align 4
+// CHECK-NEXT:ret void
+//
+void test_builtin_ppc_fetch_and_and(unsigned int a, unsigned int b) {
+  __fetch_and_and(&a, b);
+}
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_andlp(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
+// CHECK-NEXT:store i64 [[B:%.*]], i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i64, i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw and i64* [[A_ADDR]], i64 [[TMP1]] monotonic, align 8
+// CHECK-NEXT:ret void
+//
+void test_builtin_ppc_fetch_and_andlp(unsigned long a, unsigned long b) {
+  __fetch_and_andlp(&a, b);
+}
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_or(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 [[A:%.*]], i32* [[A_ADDR]], align 4
+// CHECK-NEXT:store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw or i32* [[A_ADDR]], i32 [[TMP1]] monotonic, align 4
+// CHECK-NEXT:ret void
+//
+void test_builtin_ppc_fetch_and_or(unsigned int a, unsigned int b) {
+  __fetch_and_or(&a, b);
+}
+// CHECK-LABEL: @test_builtin_ppc_fetch_and_orlp(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
+// CHECK-NEXT:store i64 [[B:%.*]], i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, i64* [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i64, i64* [[B_ADDR]], align 8
+//

[PATCH] D104952: [hexagon] Add {hvx,}hexagon_{protos,circ_brev...}

2021-06-27 Thread Brian Cain via Phabricator via cfe-commits
bcain added a comment.

Should I clang format the headers?  I prefer keeping the historical formatting 
intact. But if the submission should conform then I suppose I'll just accept 
the wrapped text suggested by clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104952

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


[PATCH] D102756: [clang-repl] Tell the LLJIT the exact target triple we use.

2021-06-27 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev closed this revision.
v.g.vassilev added a comment.

Landed in 49f9532165f0cc0485a7da84662ebf63d155652c 



Repository:
  rC Clang

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

https://reviews.llvm.org/D102756

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


[PATCH] D104601: [Preprocessor] Implement -fnormalize-whitespace.

2021-06-27 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

In D104601#2842686 , @dblaikie wrote:

> One other thing: This wouldn't be usable when using debug info, presumably, 
> because it'd refer to the wrong lines, etc.

This is considered in the ccache patch 
. By default (unless a corresponding 
"sloppiness" option is used), only direct hits (by binary file comparison) are 
used if: There is compiler output, debug info is generated, or `.incbin` 
assembly instruction is used.

However, the is orthogonal to `-fnormalize-whitespace`. It is a mitigation of 
using `-E -P` as preprocessor intermediate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104601

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


[PATCH] D104616: [analyzer][WIP] Model comparision methods of std::unique_ptr

2021-06-27 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:351-352
+  case OO_##Name:  
\
+BinOpIt = BinOps.find(Spelling);   
\
+UnOpIt = UnOps.find(Spelling); 
\
+if (BinOpIt != BinOps.end())   
\

Optimization: if one of the lookups succeeds, the other is unnecessary. A bit 
premature but I think we shouldn't lose too much elegance over this.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:388-389
+
+  auto retrieveOrConjureInnerPtrVal = [&C, &State](const Expr *E,
+   SVal S) -> SVal {
+if (S.isZeroConstant()) {

This sounds like a super common functionality. Doesn't `.get()` do the same as 
well? I think it should be de-duplicated into a top-level method.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:443-446
+  auto RetVal = C.getSValBuilder().evalBinOp(
+  State, BOK, FirstPtrVal, SecondPtrVal, Call.getResultType());
+  State = State->BindExpr(Call.getOriginExpr(), C.getLocationContext(), 
RetVal);
+  C.addTransition(State);

Because these operators are pure boolean functions, a state split would be 
justified. It's pointless to call the operator unless both return values are 
feasible. I think you should do an `assume()` and transition into both states.

It might also make sense to consult `-analyzer-config eagerly-assume=` before 
doing it but it sounds like this option will stays true forever and we might as 
well remove it.

The spaceship operator is obviously an exceptional case. Invocation of the 
spaceship operator isn't a good indication that all three return values are 
feasible, might be only two.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104616

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


[PATCH] D104925: [Analyzer] Improve report of file read at end-of-file condition.

2021-06-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 354791.
balazske added a comment.

Add checker name to commit message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104925

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream-note.c

Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -88,3 +88,60 @@
   fclose(F); // expected-warning {{Stream pointer might be NULL}}
   // expected-note@-1 {{Stream pointer might be NULL}}
 }
+
+void check_eof_notes_1() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  }
+  fread(Buf, 1, 1, F);
+  if (feof(F)) { // expected-note {{Taking true branch}}
+clearerr(F);
+fread(Buf, 1, 1, F);   // expected-note {{Assuming that stream reaches end-of-file here}}
+if (feof(F)) { // expected-note {{End-of-file status is discovered here}} expected-note {{Taking true branch}}
+  fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+  // expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+}
+  }
+  fclose(F);
+}
+
+void check_eof_notes_2() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  }
+  fread(Buf, 1, 1, F);
+  if (feof(F)) { // expected-note {{Taking false branch}}
+fclose(F);
+return;
+  } else if (ferror(F)) { // expected-note {{Taking false branch}}
+fclose(F);
+return;
+  }
+  fread(Buf, 1, 1, F);   // expected-note {{Assuming that stream reaches end-of-file here}}
+  if (feof(F)) { // expected-note {{End-of-file status is discovered here}} expected-note {{Taking true branch}}
+fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+// expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+  }
+  fclose(F);
+}
+
+void check_eof_notes_3() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  int RRet = fread(Buf, 1, 1, F); // expected-note {{Assuming that stream reaches end-of-file here}}
+  if (ferror(F)) {// expected-note {{End-of-file status is discovered here}} expected-note {{Taking false branch}}
+  } else {
+fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+// expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+  }
+  fclose(F);
+}
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -25,6 +25,10 @@
 using namespace ento;
 using namespace std::placeholders;
 
+//===--===//
+// Definition of state data structures.
+//===--===//
+
 namespace {
 
 struct FnDescription;
@@ -146,6 +150,14 @@
   }
 };
 
+} // namespace
+
+//===--===//
+// StreamChecker class and utility functions.
+//===--===//
+
+namespace {
+
 class StreamChecker;
 using FnCheck = std::function;
@@ -337,7 +349,8 @@
   /// There will be always a state transition into the passed State,
   /// by the new non-fatal error node or (if failed) a normal transition,
   /// to ensure uniform handling.
-  void reportFEofWarning(CheckerContext &C, ProgramStateRef State) const;
+  void reportFEofWarning(SymbolRef StreamSym, CheckerContext &C,
+ ProgramStateRef State) const;
 
   /// Emit resource leak warnings for the given symbols.
   /// Createn a non-fatal error node for these, and returns it (if any warnings
@@ -389,10 +402,62 @@
 CheckerContext &C);
 };
 
+class StreamBugVisitor final : public BugReporterVisitor {
+public:
+  // FIXME: Use mode FOpen to find place of opening a file, instead of NoteTag.
+  enum NotificationMode { FOpen, FEof };
+
+  StreamBugVisitor(SymbolRef S, NotificationMode M, unsigned int BugSeq = 0)
+  : StreamSym{S}, Mode{M}, BugSeq{BugSeq} {}
+
+  static void *getTag() {
+static int Tag = 0;
+return &Tag;
+  }
+
+  void Profile(ll

[PATCH] D105003: [Analyzer] Improve report of "indeterminate file position" condition (alpha.unix.Stream).

2021-06-27 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: manas, steakhal, ASDenysPetrov, martong, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun, whisperity.
Herald added a reviewer: Szelethus.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The checker warns if specific stream operation is called in a failed state
(that is called "indeterminate file position condition").
The commit adds indication of location of the previously failed operation
that causes the failed state.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105003

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream-note.c

Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -145,3 +145,62 @@
   }
   fclose(F);
 }
+
+void check_indeterminate_notes_1() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (!F) // expected-note {{Taking false branch}} expected-note {{'F' is non-null}}
+return;
+  fread(Buf, 1, 1, F);
+  if (ferror(F)) { // expected-note {{Taking true branch}}
+F = freopen(0, "w", F);
+if (!F) // expected-note {{Taking false branch}} expected-note {{'F' is non-null}}
+  return;
+fread(Buf, 1, 1, F);   // expected-note {{Assuming that this stream operation fails}}
+if (ferror(F)) {   // expected-note {{Taking true branch}}
+  fread(Buf, 1, 1, F); // expected-warning {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}}
+  // expected-note@-1 {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}}
+}
+  }
+  fclose(F);
+}
+
+void check_indeterminate_notes_2() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (!F) // expected-note {{Taking false branch}} expected-note {{'F' is non-null}}
+return;
+  fseek(F, 1, SEEK_SET); // expected-note {{Assuming that this stream operation fails}}
+  if (!feof(F))  // expected-note {{Taking true branch}}
+fread(Buf, 1, 1, F); // expected-warning {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}}
+  // expected-note@-1 {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}}
+  fclose(F);
+}
+
+void check_indeterminate_notes_3() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (!F) // expected-note {{Taking false branch}} expected-note {{'F' is non-null}}
+return;
+  fwrite(Buf, 1, 1, F);  // expected-note {{Assuming that this stream operation fails}}
+  if (ferror(F)) // expected-note {{Taking true branch}}
+fread(Buf, 1, 1, F); // expected-warning {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}}
+  // expected-note@-1 {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}}
+  fclose(F);
+}
+
+void check_indeterminate_notes_4() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (!F) // expected-note {{Taking false branch}} expected-note {{'F' is non-null}}
+return;
+  fseek(F, 1, SEEK_SET);  // expected-note {{Assuming that this stream operation fails}}
+  if (!ferror(F) && !feof(F)) // expected-note {{Taking true branch}} // expected-note {{Left side of '&&' is true}}
+fread(Buf, 1, 1, F);  // expected-warning {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}}
+  // expected-note@-1 {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}}
+  fclose(F);
+}
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -405,7 +405,7 @@
 class StreamBugVisitor final : public BugReporterVisitor {
 public:
   // FIXME: Use mode FOpen to find place of opening a file, instead of NoteTag.
-  enum NotificationMode { FOpen, FEof };
+  enum NotificationMode { FOpen, FEof, Indeterminate };
 
   StreamBugVisitor(SymbolRef S, NotificationMode M, unsigned int BugSeq = 0)
   : StreamSym{S}, Mode{M}, BugSeq{BugSeq} {}
@@ -447,17 +447,27 @@
 // FEOF flag from false to true. This way it is possible to find the last
 // place where the stream becomes into EOF state.
 REGISTER_MAP_WITH_PROGRAMSTATE(EofSeqMap, SymbolRef, unsigned int)
+// Simillar for the "FilePositionIndeterminate" value.
+REGISTER_MAP_WITH_PROGRAMSTATE(IndeterminateSeqMap, SymbolRef, unsigned int)
 
-ProgramStateRef initEofSeq(SymbolRef StreamSym,