[PATCH] D91025: [clangd] Fix locateMacroAt() for macro definition outside preamble

2020-11-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman.
Herald added a project: clang.
nridge requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Fixes https://github.com/clangd/clangd/issues/577


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91025

Files:
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1563,6 +1563,14 @@
 }
   )cpp",
 
+  R"cpp(// Macro outside preamble
+int breakPreamble;
+#define [[MA^CRO]](X) (X+1)
+void test() {
+  int x = [[MACRO]]([[MACRO]](1));
+}
+  )cpp",
+
   R"cpp(
 int [[v^ar]] = 0;
 void foo(int s = [[var]]);
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -975,17 +975,31 @@
   if (!IdentifierInfo || !IdentifierInfo->hadMacroDefinition())
 return None;
 
-  // Get the definition just before the searched location so that a macro
-  // referenced in a '#undef MACRO' can still be found. Note that we only do
-  // that if Loc is not pointing at start of file.
-  if (SM.getLocForStartOfFile(SM.getFileID(Loc)) != Loc)
-Loc = Loc.getLocWithOffset(-1);
-  MacroDefinition MacroDef = PP.getMacroDefinitionAtLoc(IdentifierInfo, Loc);
-  if (auto *MI = MacroDef.getMacroInfo())
-return DefinedMacro{
-IdentifierInfo->getName(), MI,
-translatePreamblePatchLocation(MI->getDefinitionLoc(), SM)};
-  return None;
+  // We need to take special case to handle #define and #undef.
+  // Preprocessor::getMacroDefinitionAtLoc() only considers a macro
+  // definition to be in scope *after* the location of the macro name in a
+  // #define that introduces it, and *before* the location of the macro name
+  // in an #undef that undefines it. To handle these cases, we check for
+  // the macro being in scope either just after or just before the location
+  // of the token. In getting the locations before and after, we also take
+  // care to check for start-of-file and end-of-file.
+  FileID FID = SM.getFileID(Loc);
+  auto JustAfterToken =
+  SM.getLocForEndOfFile(FID) == Loc ? Loc : Loc.getLocWithOffset(1);
+  auto *MI =
+  PP.getMacroDefinitionAtLoc(IdentifierInfo, 
JustAfterToken).getMacroInfo();
+  if (!MI) {
+auto JustBeforeToken =
+SM.getLocForStartOfFile(FID) == Loc ? Loc : Loc.getLocWithOffset(-1);
+MI = PP.getMacroDefinitionAtLoc(IdentifierInfo, JustBeforeToken)
+ .getMacroInfo();
+  }
+  if (!MI) {
+return None;
+  }
+  return DefinedMacro{
+  IdentifierInfo->getName(), MI,
+  translatePreamblePatchLocation(MI->getDefinitionLoc(), SM)};
 }
 
 llvm::Expected Edit::apply() const {


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1563,6 +1563,14 @@
 }
   )cpp",
 
+  R"cpp(// Macro outside preamble
+int breakPreamble;
+#define [[MA^CRO]](X) (X+1)
+void test() {
+  int x = [[MACRO]]([[MACRO]](1));
+}
+  )cpp",
+
   R"cpp(
 int [[v^ar]] = 0;
 void foo(int s = [[var]]);
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -975,17 +975,31 @@
   if (!IdentifierInfo || !IdentifierInfo->hadMacroDefinition())
 return None;
 
-  // Get the definition just before the searched location so that a macro
-  // referenced in a '#undef MACRO' can still be found. Note that we only do
-  // that if Loc is not pointing at start of file.
-  if (SM.getLocForStartOfFile(SM.getFileID(Loc)) != Loc)
-Loc = Loc.getLocWithOffset(-1);
-  MacroDefinition MacroDef = PP.getMacroDefinitionAtLoc(IdentifierInfo, Loc);
-  if (auto *MI = MacroDef.getMacroInfo())
-return DefinedMacro{
-IdentifierInfo->getName(), MI,
-translatePreamblePatchLocation(MI->getDefinitionLoc(), SM)};
-  return None;
+  // We need to take special case to handle #define and #undef.
+  // Preprocessor::getMacroDefinitionAtLoc() only considers a macro
+  // definition to be in scope *after* the location of the macro name in a
+  // #define that introduces it, and *before* the location of the macro name
+  // in an #undef that undefines it. To handle these cases, we check for
+  // the macro being in scope either just after or just 

[PATCH] D89158: [NewPM] Provide method to run all pipeline callbacks, used for -O0

2020-11-07 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

Sorry about that, https://reviews.llvm.org/D91019 should fix it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89158

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


[PATCH] D90982: Ignore implicit nodes in IgnoreUnlessSpelledInSource mode

2020-11-07 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 303682.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90982

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -132,6 +132,13 @@
 compareSnippets(Expected, rewrite(Input));
   }
 
+  template  void testRuleFailure(R Rule, StringRef Input) {
+Transformers.push_back(
+std::make_unique(std::move(Rule), consumer()));
+Transformers.back()->registerMatchers();
+ASSERT_FALSE(rewrite(Input)) << "Expected failure to rewrite code";
+  }
+
   // Transformers are referenced by MatchFinder.
   std::vector> Transformers;
   clang::ast_matchers::MatchFinder MatchFinder;
@@ -1067,6 +1074,179 @@
   EXPECT_EQ(ErrorCount, 0);
 }
 
+TEST_F(TransformerTest, ImplicitNodes_ConstructorDecl) {
+
+  std::string OtherStructPrefix = R"cpp(
+struct Other {
+)cpp";
+  std::string OtherStructSuffix = "};";
+
+  std::string CopyableStructName = "struct Copyable";
+  std::string BrokenStructName = "struct explicit Copyable";
+
+  std::string CodeSuffix = R"cpp(
+{
+Other m_i;
+Copyable();
+};
+)cpp";
+
+  std::string CopyCtor = "Other(const Other&) = default;";
+  std::string ExplicitCopyCtor = "explicit Other(const Other&) = default;";
+  std::string BrokenExplicitCopyCtor =
+  "explicit explicit explicit Other(const Other&) = default;";
+
+  std::string RewriteInput = OtherStructPrefix + CopyCtor + OtherStructSuffix +
+ CopyableStructName + CodeSuffix;
+  std::string ExpectedRewriteOutput = OtherStructPrefix + ExplicitCopyCtor +
+  OtherStructSuffix + CopyableStructName +
+  CodeSuffix;
+  std::string BrokenRewriteOutput = OtherStructPrefix + BrokenExplicitCopyCtor +
+OtherStructSuffix + BrokenStructName +
+CodeSuffix;
+
+  auto MatchedRecord =
+  cxxConstructorDecl(isCopyConstructor()).bind("copyConstructor");
+
+  auto RewriteRule =
+  changeTo(before(node("copyConstructor")), cat("explicit "));
+
+  testRule(makeRule(traverse(TK_IgnoreUnlessSpelledInSource, MatchedRecord),
+RewriteRule),
+   RewriteInput, ExpectedRewriteOutput);
+
+  testRule(makeRule(traverse(TK_AsIs, MatchedRecord), RewriteRule),
+   RewriteInput, BrokenRewriteOutput);
+}
+
+TEST_F(TransformerTest, ImplicitNodes_RangeFor) {
+
+  std::string CodePrefix = R"cpp(
+struct Container
+{
+int* begin() const;
+int* end() const;
+int* cbegin() const;
+int* cend() const;
+};
+
+void foo()
+{
+  const Container c;
+)cpp";
+
+  std::string BeginCallBefore = "  c.begin();";
+  std::string BeginCallAfter = "  c.cbegin();";
+
+  std::string ForLoop = "for (auto i : c)";
+  std::string BrokenForLoop = "for (auto i :.cbegin() c)";
+
+  std::string CodeSuffix = R"cpp(
+  {
+  }
+}
+)cpp";
+
+  std::string RewriteInput =
+  CodePrefix + BeginCallBefore + ForLoop + CodeSuffix;
+  std::string ExpectedRewriteOutput =
+  CodePrefix + BeginCallAfter + ForLoop + CodeSuffix;
+  std::string BrokenRewriteOutput =
+  CodePrefix + BeginCallAfter + BrokenForLoop + CodeSuffix;
+
+  auto MatchedRecord =
+  cxxMemberCallExpr(on(expr(hasType(qualType(isConstQualified(),
+ hasDeclaration(cxxRecordDecl(
+ hasName("Container"))
+   .bind("callTarget")),
+callee(cxxMethodDecl(hasName("begin"
+  .bind("constBeginCall");
+
+  auto RewriteRule =
+  changeTo(node("constBeginCall"), cat(name("callTarget"), ".cbegin()"));
+
+  testRule(makeRule(traverse(TK_IgnoreUnlessSpelledInSource, MatchedRecord),
+RewriteRule),
+   RewriteInput, ExpectedRewriteOutput);
+
+  testRule(makeRule(traverse(TK_AsIs, MatchedRecord), RewriteRule),
+   RewriteInput, BrokenRewriteOutput);
+}
+
+TEST_F(TransformerTest, ImplicitNodes_ForStmt) {
+
+  std::string CodePrefix = R"cpp(
+struct NonTrivial {
+NonTrivial() {}
+NonTrivial(NonTrivial&) {}
+NonTrivial& operator=(NonTrivial const&) { return *this; }
+
+~NonTrivial() {}
+};
+
+struct ContainsArray {
+NonTrivial arr[2];
+ContainsArray& operator=(ContainsArray const&) = default;
+};
+
+void testIt()
+{
+

[PATCH] D72218: [clang-tidy] new altera kernel name restriction check

2020-11-07 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies updated this revision to Diff 303680.
ffrankies added a comment.

Moved test files `KERNEL.cl`, `VHDL.cl` and `vERILOG.cl` to the `uppercase` 
subdirectory to prevent filename clashes in some environments.

This is in response to the buildbot failure where `Verilog.cl`, `KERNEL.cl`, 
and `VHDL.cl` were not present in the buildbot output despite being showing up 
as present in Differential.

@aaron.ballman Can you please try committing this again?


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

https://reviews.llvm.org/D72218

Files:
  clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp
  clang-tools-extra/clang-tidy/altera/CMakeLists.txt
  clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
  clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/altera-kernel-name-restriction.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/Verilog.cl
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/kernel.cl
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/kernel.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/other_Verilog.cl
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/otherdir/vhdl.cl
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/otherthing.cl
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/some/dir/kernel.cl
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/some/kernel.cl/foo.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/some/verilog.cl/foo.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/some/vhdl.cl/foo.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/some_kernel.cl
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/somedir/verilog.cl
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/thing.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/uppercase/KERNEL.cl
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/uppercase/VHDL.cl
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/uppercase/vERILOG.cl
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/verilog.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/vhdl.CL
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/vhdl.h
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/altera-kernel-name-restriction/vhdl_number_two.cl
  clang-tools-extra/test/clang-tidy/checkers/altera-kernel-name-restriction.cpp
  llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/altera/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/altera/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/altera/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/altera/BUILD.gn
@@ -13,6 +13,7 @@
   ]
   sources = [
 "AlteraTidyModule.cpp",
+"KernelNameRestrictionCheck.cpp",
 "StructPackAlignCheck.cpp",
   ]
 }
Index: clang-tools-extra/test/clang-tidy/checkers/altera-kernel-name-restriction.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/altera-kernel-name-restriction.cpp
@@ -0,0 +1,55 @@
+// RUN: %check_clang_tidy %s altera-kernel-name-restriction %t -- -- -I%S/Inputs/altera-kernel-name-restriction
+// RUN: %check_clang_tidy -check-suffix=UPPERCASE %s altera-kernel-name-restriction %t -- -- -I%S/Inputs/altera-kernel-name-restriction/uppercase -DUPPERCASE
+
+#ifdef UPPERCASE
+// The warning should be triggered regardless of capitalization
+#include "KERNEL.cl"
+// CHECK-MESSAGES-UPPERCASE: :[[@LINE-1]]:1: warning: including 'KERNEL.cl' may cause additional compilation errors due to the name of the kernel source file; consider renaming the included kernel source file [altera-kernel-name-restriction]
+#include "vERILOG.cl"
+// CHECK-MESSAGES-UPPERCASE: :[[@LINE-1]]:1: warning: including 'vERILOG.cl' may cause additional compilation errors due to the name of the kernel source file; consider renaming the included kernel source file [altera-kernel-name-restriction]
+#include "VHDL.cl"
+// CHECK-MESSAGES-UPPERCASE: :[[@LINE-1]]:1: warning: including 'VHDL.cl' may cause additional compilation errors due to the name of the kernel source file; consider renaming the included kernel source file [altera-kernel-name-restriction]
+#else 
+// These 

[PATCH] D90982: Ignore implicit nodes in IgnoreUnlessSpelledInSource mode

2020-11-07 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 303679.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90982

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -132,6 +132,13 @@
 compareSnippets(Expected, rewrite(Input));
   }
 
+  template  void testRuleFailure(R Rule, StringRef Input) {
+Transformers.push_back(
+std::make_unique(std::move(Rule), consumer()));
+Transformers.back()->registerMatchers();
+ASSERT_FALSE(rewrite(Input)) << "Expected failure to rewrite code";
+  }
+
   // Transformers are referenced by MatchFinder.
   std::vector> Transformers;
   clang::ast_matchers::MatchFinder MatchFinder;
@@ -1067,6 +1074,134 @@
   EXPECT_EQ(ErrorCount, 0);
 }
 
+TEST_F(TransformerTest, ImplicitNodes_RangeFor) {
+
+  std::string CodePrefix = R"cpp(
+struct Container
+{
+int* begin() const;
+int* end() const;
+int* cbegin() const;
+int* cend() const;
+};
+
+void foo()
+{
+  const Container c;
+)cpp";
+
+  std::string BeginCallBefore = "  c.begin();";
+  std::string BeginCallAfter = "  c.cbegin();";
+
+  std::string ForLoop = "for (auto i : c)";
+  std::string BrokenForLoop = "for (auto i :.cbegin() c)";
+
+  std::string CodeSuffix = R"cpp(
+  {
+  }
+}
+)cpp";
+
+  std::string RewriteInput =
+  CodePrefix + BeginCallBefore + ForLoop + CodeSuffix;
+  std::string ExpectedRewriteOutput =
+  CodePrefix + BeginCallAfter + ForLoop + CodeSuffix;
+  std::string BrokenRewriteOutput =
+  CodePrefix + BeginCallAfter + BrokenForLoop + CodeSuffix;
+
+  auto MatchedRecord =
+  cxxMemberCallExpr(on(expr(hasType(qualType(isConstQualified(),
+ hasDeclaration(cxxRecordDecl(
+ hasName("Container"))
+   .bind("callTarget")),
+callee(cxxMethodDecl(hasName("begin"
+  .bind("constBeginCall");
+
+  auto RewriteRule =
+  changeTo(node("constBeginCall"), cat(name("callTarget"), ".cbegin()"));
+
+  testRule(makeRule(traverse(TK_IgnoreUnlessSpelledInSource, MatchedRecord),
+RewriteRule),
+   RewriteInput, ExpectedRewriteOutput);
+
+  testRule(makeRule(traverse(TK_AsIs, MatchedRecord), RewriteRule),
+   RewriteInput, BrokenRewriteOutput);
+}
+
+TEST_F(TransformerTest, ImplicitNodes_ForStmt) {
+
+  std::string CodePrefix = R"cpp(
+struct NonTrivial {
+NonTrivial() {}
+NonTrivial(NonTrivial&) {}
+NonTrivial& operator=(NonTrivial const&) { return *this; }
+
+~NonTrivial() {}
+};
+
+struct ContainsArray {
+NonTrivial arr[2];
+ContainsArray& operator=(ContainsArray const&) = default;
+};
+
+void testIt()
+{
+ContainsArray ca1;
+ContainsArray ca2;
+ca2 = ca1;
+)cpp";
+
+  auto CodeSuffix = "}";
+
+  auto LoopBody = R"cpp(
+{
+
+}
+)cpp";
+
+  auto RawLoop = "for (auto i = 0; i != 5; ++i)";
+
+  auto RangeLoop = "for (auto i : boost::irange(5))";
+
+  // Expect to rewrite the raw loop to the ranged loop.
+  // This works in TK_IgnoreUnlessSpelledInSource mode, but TK_AsIs
+  // mode also matches the hidden for loop generated in the copy assignment
+  // operator of ContainsArray. Transformer then fails to transform the code at
+  // all.
+
+  auto RewriteInput =
+  CodePrefix + RawLoop + LoopBody + RawLoop + LoopBody + CodeSuffix;
+
+  auto RewriteOutput =
+  CodePrefix + RangeLoop + LoopBody + RangeLoop + LoopBody + CodeSuffix;
+  {
+auto MatchedLoop = forStmt(
+has(declStmt(
+hasSingleDecl(varDecl(hasInitializer(integerLiteral(equals(0
+  .bind("loopVar",
+has(binaryOperator(hasOperatorName("!="),
+   hasLHS(ignoringImplicit(declRefExpr(
+   to(varDecl(equalsBoundNode("loopVar")),
+   hasRHS(expr().bind("upperBoundExpr",
+has(unaryOperator(hasOperatorName("++"),
+  hasUnaryOperand(declRefExpr(
+  to(varDecl(equalsBoundNode("loopVar"))
+.bind("incrementOp")));
+
+auto RewriteRule =
+changeTo(transformer::enclose(node("loopVar"), node("incrementOp")),
+ cat("auto ", name("loopVar"), " : boost::irange(",
+ node("upperBoundExpr"), ")"));
+
+

[clang] 4eb8804 - Fix dumping of explicit template specializations

2020-11-07 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2020-11-07T22:34:16Z
New Revision: 4eb880439a7ec4a0310b630ff89125e00cf200a3

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

LOG: Fix dumping of explicit template specializations

This was missing from commit 7efe07a1 (Traverse-ignore explicit template
instantiations, 2020-11-06).

Added: 


Modified: 
clang/include/clang/AST/ASTNodeTraverser.h
clang/unittests/AST/ASTTraverserTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index c3c06bf37f3d..78b2ec5a3dc7 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -101,8 +101,14 @@ class ASTNodeTraverser
 
   // Decls within functions are visited by the body.
   if (!isa(*D) && !isa(*D)) {
-if (isa(*D) && Traversal != TK_AsIs)
-  return;
+if (Traversal != TK_AsIs) {
+  if (const auto *CTSD = dyn_cast(D)) 
{
+auto SK = CTSD->getSpecializationKind();
+if (SK == TSK_ExplicitInstantiationDeclaration ||
+SK == TSK_ExplicitInstantiationDefinition)
+  return;
+  }
+}
 if (const auto *DC = dyn_cast(D))
   dumpDeclContext(DC);
   }

diff  --git a/clang/unittests/AST/ASTTraverserTest.cpp 
b/clang/unittests/AST/ASTTraverserTest.cpp
index 727a1ffa8395..5e167e4d30b7 100644
--- a/clang/unittests/AST/ASTTraverserTest.cpp
+++ b/clang/unittests/AST/ASTTraverserTest.cpp
@@ -1183,6 +1183,48 @@ ClassTemplateDecl 'TemplStruct'
   | `-CompoundStmt
   |-AccessSpecDecl
   `-FieldDecl 'm_t'
+)cpp");
+  }
+  {
+auto BN = ast_matchers::match(
+classTemplateSpecializationDecl(
+hasTemplateArgument(
+0, templateArgument(refersToType(asString("_Bool")
+.bind("templSpec"),
+AST->getASTContext());
+EXPECT_EQ(BN.size(), 1u);
+
+EXPECT_EQ(dumpASTString(TK_AsIs, BN[0].getNodeAs("templSpec")),
+  R"cpp(
+ClassTemplateSpecializationDecl 'TemplStruct'
+|-TemplateArgument type _Bool
+| `-BuiltinType
+|-CXXRecordDecl 'TemplStruct'
+|-CXXConstructorDecl 'TemplStruct'
+| `-CompoundStmt
+|-CXXDestructorDecl '~TemplStruct'
+| `-CompoundStmt
+|-CXXMethodDecl 'foo'
+| `-CompoundStmt
+|-AccessSpecDecl
+`-FieldDecl 'm_t'
+)cpp");
+
+EXPECT_EQ(dumpASTString(TK_IgnoreUnlessSpelledInSource,
+BN[0].getNodeAs("templSpec")),
+  R"cpp(
+ClassTemplateSpecializationDecl 'TemplStruct'
+|-TemplateArgument type _Bool
+| `-BuiltinType
+|-CXXRecordDecl 'TemplStruct'
+|-CXXConstructorDecl 'TemplStruct'
+| `-CompoundStmt
+|-CXXDestructorDecl '~TemplStruct'
+| `-CompoundStmt
+|-CXXMethodDecl 'foo'
+| `-CompoundStmt
+|-AccessSpecDecl
+`-FieldDecl 'm_t'
 )cpp");
   }
   {



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


[PATCH] D90392: [clang-tidy] Omit std::make_unique/make_shared for default initialization.

2020-11-07 Thread Chris Kennelly via Phabricator via cfe-commits
ckennelly added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-make-shared.cpp:51
   // CHECK-FIXES: std::shared_ptr P1 = std::make_shared();
+  std::shared_ptr P2 = std::shared_ptr(new int);
 

steveire wrote:
> I'm a bit confused. Why don't we want to transform this?
`std::make_shared()` is equivalent to `std::shared_ptr(new int())`.  
This value initializes (read: zeroes out the value).

The statement here is only default initializing (read: leaves the value 
uninitialized).  For this use case, we should use 
`std::make_shared_for_overwrite` when it is available.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90392

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


[PATCH] D90392: [clang-tidy] Omit std::make_unique/make_shared for default initialization.

2020-11-07 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-make-shared.cpp:51
   // CHECK-FIXES: std::shared_ptr P1 = std::make_shared();
+  std::shared_ptr P2 = std::shared_ptr(new int);
 

I'm a bit confused. Why don't we want to transform this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90392

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


[PATCH] D91015: Extend bugprone-string-constructor-check to std::string_view.

2020-11-07 Thread Chris Kennelly via Phabricator via cfe-commits
ckennelly created this revision.
ckennelly added reviewers: EricWF, ymandel.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
ckennelly requested review of this revision.

This allows for matching the constructors std::string has in common with
std::string_view.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91015

Files:
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
  clang-tools-extra/docs/clang-tidy/checks/bugprone-string-constructor.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-string-constructor.cpp
@@ -14,6 +14,15 @@
 };
 typedef basic_string string;
 typedef basic_string wstring;
+
+template >
+struct basic_string_view {
+  basic_string_view();
+  basic_string_view(const C *, unsigned int size);
+  basic_string_view(const C *);
+};
+typedef basic_string_view string_view;
+typedef basic_string_view wstring_view;
 }
 
 const char* kText = "";
@@ -52,11 +61,35 @@
   // CHECK-MESSAGES: [[@LINE-1]]:20: warning: constructing string from nullptr is undefined behaviour
 }
 
+void TestView() {
+  std::string_view q0("test", 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: constructor creating an empty string
+  std::string_view q1(kText, -4);
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: negative value used as length parameter
+  std::string_view q2("test", 200);
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: length is bigger than string literal size
+  std::string_view q3(kText, 200);
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: length is bigger than string literal size
+  std::string_view q4(kText2, 200);
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: length is bigger than string literal size
+  std::string_view q5(kText3, 0x100);
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: suspicious large length parameter
+  std::string_view q6(nullptr);
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: constructing string from nullptr is undefined behaviour
+  std::string_view q7 = 0;
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: constructing string from nullptr is undefined behaviour
+}
+
 std::string StringFromZero() {
   return 0;
   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: constructing string from nullptr is undefined behaviour
 }
 
+std::string_view StringViewFromZero() {
+  return 0;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: constructing string from nullptr is undefined behaviour
+}
+
 void Valid() {
   std::string empty();
   std::string str(4, 'x');
@@ -64,6 +97,11 @@
   std::string s1("test", 4);
   std::string s2("test", 3);
   std::string s3("test");
+
+  std::string_view emptyv();
+  std::string_view sv1("test", 4);
+  std::string_view sv2("test", 3);
+  std::string_view sv3("test");
 }
 
 namespace instantiation_dependent_exprs {
@@ -71,5 +109,6 @@
 struct S {
   bool x;
   std::string f() { return x ? "a" : "b"; }
+  std::string_view g() { return x ? "a" : "b"; }
 };
 }
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-string-constructor.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone-string-constructor.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-string-constructor.rst
@@ -21,6 +21,7 @@
 .. code-block:: c++
 
   std::string("test", 200);   // Will include random characters after "test".
+  std::string_view("test", 200);
 
 Creating an empty string from constructors with parameters is considered
 suspicious. The programmer should use the empty constructor instead.
@@ -30,6 +31,7 @@
 .. code-block:: c++
 
   std::string("test", 0);   // Creation of an empty string.
+  std::string_view("test", 0);
 
 Options
 ---
@@ -42,3 +44,12 @@
 .. option::  LargeLengthThreshold
 
An integer specifying the large length threshold. Default is `0x80`.
+
+.. option:: StringNames
+
+Default is `::std::basic_string;::std::basic_string_view`.
+
+Semicolon-delimited list of class names to apply this check to.
+By default `::std::basic_string` applies to ``std::string`` and
+``std::wstring``. Set to e.g. `::std::basic_string;llvm::StringRef;QString`
+to perform this check on custom classes.
Index: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.h
@@ -32,6 +32,7 @@
 private:
   const bool WarnOnLargeLength;
   const unsigned int LargeLengthThreshold;
+  std::vector StringNames;
 };
 
 } // namespace bugprone
Index: 

[PATCH] D91011: [NFC, Refactor] Rename the (scoped) enum DeclaratorContext enumerator's to avoid redundancy

2020-11-07 Thread Faisal Vali via Phabricator via cfe-commits
faisalv created this revision.
faisalv added reviewers: aaron.ballman, bruno.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
faisalv requested review of this revision.

Since these are scoped enumerators, they have to be prefixed by 
DeclaratorContext, so lets remove Context from the name, and return some 
characters to the multiverse.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91011

Files:
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp

Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -50,7 +50,7 @@
 /// isOmittedBlockReturnType - Return true if this declarator is missing a
 /// return type because this is a omitted return type on a block literal.
 static bool isOmittedBlockReturnType(const Declarator ) {
-  if (D.getContext() != DeclaratorContext::BlockLiteralContext ||
+  if (D.getContext() != DeclaratorContext::BlockLiteral ||
   D.getDeclSpec().hasTypeSpecifier())
 return false;
 
@@ -1348,12 +1348,12 @@
 // The declspec is always missing in a lambda expr context; it is either
 // specified with a trailing return type or inferred.
 if (S.getLangOpts().CPlusPlus14 &&
-declarator.getContext() == DeclaratorContext::LambdaExprContext) {
+declarator.getContext() == DeclaratorContext::LambdaExpr) {
   // In C++1y, a lambda's implicit return type is 'auto'.
   Result = Context.getAutoDeductType();
   break;
 } else if (declarator.getContext() ==
-   DeclaratorContext::LambdaExprContext ||
+   DeclaratorContext::LambdaExpr ||
checkOmittedBlockReturnType(S, declarator,
Context.DependentTy)) {
   Result = Context.DependentTy;
@@ -1741,7 +1741,7 @@
 
   // Before we process any type attributes, synthesize a block literal
   // function declarator if necessary.
-  if (declarator.getContext() == DeclaratorContext::BlockLiteralContext)
+  if (declarator.getContext() == DeclaratorContext::BlockLiteral)
 maybeSynthesizeBlockSignature(state, Result);
 
   // Apply any type attributes from the decl spec.  This may cause the
@@ -3306,21 +3306,21 @@
 bool IsDeducedReturnType = false;
 
 switch (D.getContext()) {
-case DeclaratorContext::LambdaExprContext:
+case DeclaratorContext::LambdaExpr:
   // Declared return type of a lambda-declarator is implicit and is always
   // 'auto'.
   break;
-case DeclaratorContext::ObjCParameterContext:
-case DeclaratorContext::ObjCResultContext:
+case DeclaratorContext::ObjCParameter:
+case DeclaratorContext::ObjCResult:
   Error = 0;
   break;
-case DeclaratorContext::RequiresExprContext:
+case DeclaratorContext::RequiresExpr:
   Error = 22;
   break;
-case DeclaratorContext::PrototypeContext:
-case DeclaratorContext::LambdaExprParameterContext: {
+case DeclaratorContext::Prototype:
+case DeclaratorContext::LambdaExprParameter: {
   InventedTemplateParameterInfo *Info = nullptr;
-  if (D.getContext() == DeclaratorContext::PrototypeContext) {
+  if (D.getContext() == DeclaratorContext::Prototype) {
 // With concepts we allow 'auto' in function parameters.
 if (!SemaRef.getLangOpts().CPlusPlus20 || !Auto ||
 Auto->getKeyword() != AutoTypeKeyword::Auto) {
@@ -3350,7 +3350,7 @@
 T = InventTemplateParameter(state, T, nullptr, Auto, *Info).first;
   break;
 }
-case DeclaratorContext::MemberContext: {
+case DeclaratorContext::Member: {
   if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
   D.isFunctionDeclarator())
 break;
@@ -3370,21 +3370,21 @@
 Error = 20; // Friend type
   break;
 }
-case DeclaratorContext::CXXCatchContext:
-case DeclaratorContext::ObjCCatchContext:
+case DeclaratorContext::CXXCatch:
+case DeclaratorContext::ObjCCatch:
   Error = 7; // Exception declaration
   break;
-case DeclaratorContext::TemplateParamContext:
+case DeclaratorContext::TemplateParam:
   if (isa(Deduced) &&
   !SemaRef.getLangOpts().CPlusPlus20)
 Error = 19; // Template parameter (until C++20)
   else if (!SemaRef.getLangOpts().CPlusPlus17)
 Error = 8; // Template parameter (until 

[PATCH] D91009: Include std::basic_string_view in readability-redundant-string-init.

2020-11-07 Thread Chris Kennelly via Phabricator via cfe-commits
ckennelly created this revision.
ckennelly added reviewers: EricWF, ymandel.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
ckennelly requested review of this revision.

std::string_view("") produces a string_view instance that compares
equal to std::string_view(), but requires more complex initialization
(storing the address of the string literal, rather than zeroing).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91009

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
@@ -1,7 +1,7 @@
 // RUN: %check_clang_tidy -std=c++11,c++14 %s readability-redundant-string-init %t \
 // RUN:   -config="{CheckOptions: \
 // RUN: [{key: readability-redundant-string-init.StringNames, \
-// RUN:   value: '::std::basic_string;our::TestString'}] \
+// RUN:   value: '::std::basic_string;::std::basic_string_view;our::TestString'}] \
 // RUN: }"
 // FIXME: Fix the checker to work in C++17 mode.
 
@@ -19,6 +19,20 @@
 };
 typedef basic_string string;
 typedef basic_string wstring;
+
+template , typename A = std::allocator>
+struct basic_string_view {
+  using size_type = unsigned;
+
+  basic_string_view();
+  basic_string_view(const basic_string_view &);
+  basic_string_view(const C *, size_type);
+  basic_string_view(const C *, const A  = A());
+  template 
+  basic_string_view(It, End);
+};
+typedef basic_string_view string_view;
+typedef basic_string_view wstring_view;
 }
 
 void f() {
@@ -48,6 +62,33 @@
   std::string z;
 }
 
+void fview() {
+  std::string_view a = "";
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization [readability-redundant-string-init]
+  // CHECK-FIXES: std::string_view a;
+  std::string_view b("");
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization
+  // CHECK-FIXES: std::string_view b;
+  std::string_view c = R"()";
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization
+  // CHECK-FIXES: std::string_view c;
+  std::string_view d(R"()");
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization
+  // CHECK-FIXES: std::string_view d;
+  std::string_view e{""};
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization
+  // CHECK-FIXES: std::string_view e;
+  std::string_view f = {""};
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: redundant string initialization
+  // CHECK-FIXES: std::string_view f;
+
+  std::string_view u = "u";
+  std::string_view w("w");
+  std::string_view x = R"(x)";
+  std::string_view y(R"(y)");
+  std::string_view z;
+}
+
 void g() {
   std::wstring a = L"";
   // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
@@ -69,6 +110,27 @@
   std::wstring z;
 }
 
+void gview() {
+  std::wstring_view a = L"";
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization
+  // CHECK-FIXES: std::wstring_view a;
+  std::wstring_view b(L"");
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization
+  // CHECK-FIXES: std::wstring_view b;
+  std::wstring_view c = LR"()";
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization
+  // CHECK-FIXES: std::wstring_view c;
+  std::wstring_view d(LR"()");
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization
+  // CHECK-FIXES: std::wstring_view d;
+
+  std::wstring_view u = L"u";
+  std::wstring_view w(L"w");
+  std::wstring_view x = LR"(x)";
+  std::wstring_view y(LR"(y)");
+  std::wstring_view z;
+}
+
 template 
 void templ() {
   std::string s = "";
@@ -121,6 +183,35 @@
   DECL_STRING(h, "u");
 }
 
+typedef std::string_view MyStringView;
+#define STRINGVIEW MyStringView
+#define DECL_STRINGVIEW(name, val) STRINGVIEW name = val
+
+void iview() {
+  MyStringView a = "";
+  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+  // CHECK-FIXES: MyStringView a;
+  STRINGVIEW b = "";
+  // CHECK-MESSAGES: [[@LINE-1]]:14: warning: redundant string initialization
+  // CHECK-FIXES: STRINGVIEW b;
+  MyStringView c = ""
+   ""
+   "";
+  // CHECK-MESSAGES: [[@LINE-3]]:16: warning: redundant string initialization
+  // CHECK-FIXES: MyStringView c;
+  STRINGVIEW d = ""
+ ""
+ "";
+  // CHECK-MESSAGES: [[@LINE-3]]:14: warning: redundant string initialization
+  // CHECK-FIXES: STRINGVIEW d;
+  DECL_STRINGVIEW(e, "");
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: redundant string initialization
+
+  MyStringView f = "u";
+  

[PATCH] D90992: [clang-tidy] Use vfs::FileSystem when getting config

2020-11-07 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd725f1ce5318: [clang-tidy] Use vfs::FileSystem when getting 
config (authored by njames93).

Changed prior to commit:
  https://reviews.llvm.org/D90992?vs=303630=303658#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90992

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp
@@ -0,0 +1,67 @@
+//=== ObjCModuleTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyOptions.h"
+#include "clang/Basic/LLVM.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+TEST(ClangTidyOptionsProvider, InMemoryFileSystems) {
+  llvm::IntrusiveRefCntPtr FileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  StringRef BaseClangTidy = R"(
+Checks: -*,clang-diagnostic-*
+  )";
+  StringRef Sub1ClangTidy = R"(
+Checks: readability-*
+InheritParentConfig: true
+  )";
+  StringRef Sub2ClangTidy = R"(
+Checks: bugprone-*,misc-*,clang-diagnostic-*
+InheritParentConfig: false
+)";
+  FileSystem->addFile("ProjectRoot/.clang-tidy", 0,
+  llvm::MemoryBuffer::getMemBuffer(BaseClangTidy));
+  FileSystem->addFile("ProjectRoot/SubDir1/.clang-tidy", 0,
+  llvm::MemoryBuffer::getMemBuffer(Sub1ClangTidy));
+  FileSystem->addFile("ProjectRoot/SubDir1/File.cpp", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+  FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/.clang-tidy", 0,
+  llvm::MemoryBuffer::getMemBuffer(Sub2ClangTidy));
+  FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/File.cpp", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+  FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/SubDir3/File.cpp", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+
+  FileOptionsProvider FileOpt({}, {}, {}, FileSystem);
+
+  ClangTidyOptions File1Options =
+  FileOpt.getOptions("ProjectRoot/SubDir1/File.cpp");
+  ClangTidyOptions File2Options =
+  FileOpt.getOptions("ProjectRoot/SubDir1/SubDir2/File.cpp");
+  ClangTidyOptions File3Options =
+  FileOpt.getOptions("ProjectRoot/SubDir1/SubDir2/SubDir3/File.cpp");
+
+  ASSERT_TRUE(File1Options.Checks.hasValue());
+  EXPECT_EQ(*File1Options.Checks, "-*,clang-diagnostic-*,readability-*");
+  ASSERT_TRUE(File2Options.Checks.hasValue());
+  EXPECT_EQ(*File2Options.Checks, "bugprone-*,misc-*,clang-diagnostic-*");
+
+  // 2 and 3 should use the same config so these should also be the same.
+  EXPECT_EQ(File2Options.Checks, File3Options.Checks);
+}
+
+} // namespace test
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
===
--- clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
+++ clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
@@ -17,6 +17,7 @@
   LLVMModuleTest.cpp
   NamespaceAliaserTest.cpp
   ObjCModuleTest.cpp
+  OptionsProviderTest.cpp
   OverlappingReplacementsTest.cpp
   UsingInserterTest.cpp
   ReadabilityModuleTest.cpp
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -325,7 +325,9 @@
 FileOptionsBaseProvider::tryReadConfigFile(StringRef Directory) {
   assert(!Directory.empty());
 
-  if (!llvm::sys::fs::is_directory(Directory)) {
+  llvm::ErrorOr DirectoryStatus = FS->status(Directory);
+
+  if (!DirectoryStatus || !DirectoryStatus->isDirectory()) {
 llvm::errs() << "Error reading configuration from " << Directory
  << ": directory doesn't exist.\n";
 return llvm::None;
@@ -336,15 +338,13 @@
 llvm::sys::path::append(ConfigFile, ConfigHandler.first);
 LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");
 
-bool IsFile = false;
-// Ignore errors from is_regular_file: we only need to know if we can read
-// the file or not.
-llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile);
-if (!IsFile)
+llvm::ErrorOr FileStatus = 

[clang-tools-extra] d725f1c - [clang-tidy] Use vfs::FileSystem when getting config

2020-11-07 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-11-07T19:18:02Z
New Revision: d725f1ce5318f8aca12632d3b7cfb3a5968e5d37

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

LOG: [clang-tidy] Use vfs::FileSystem when getting config

The config providers that look for configuration files currently take a pointer 
to a FileSystem in the constructor.
For some reason this isn't actually used when trying to read those 
configuration files, Essentially it just follows the behaviour of the real 
filesystem.
Using clang-tidy standalone this doesn't cause any issue.
But if its used as a library and the user wishes to use say an 
`InMemoryFileSystem` it will try to read the files from the disc instead.

Reviewed By: aaron.ballman

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

Added: 
clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp

Modified: 
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/unittests/clang-tidy/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 8ff22041d725..2ac4bbbf36b3 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -325,7 +325,9 @@ llvm::Optional
 FileOptionsBaseProvider::tryReadConfigFile(StringRef Directory) {
   assert(!Directory.empty());
 
-  if (!llvm::sys::fs::is_directory(Directory)) {
+  llvm::ErrorOr DirectoryStatus = FS->status(Directory);
+
+  if (!DirectoryStatus || !DirectoryStatus->isDirectory()) {
 llvm::errs() << "Error reading configuration from " << Directory
  << ": directory doesn't exist.\n";
 return llvm::None;
@@ -336,15 +338,13 @@ FileOptionsBaseProvider::tryReadConfigFile(StringRef 
Directory) {
 llvm::sys::path::append(ConfigFile, ConfigHandler.first);
 LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");
 
-bool IsFile = false;
-// Ignore errors from is_regular_file: we only need to know if we can read
-// the file or not.
-llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile);
-if (!IsFile)
+llvm::ErrorOr FileStatus = FS->status(ConfigFile);
+
+if (!FileStatus || !FileStatus->isRegularFile())
   continue;
 
 llvm::ErrorOr> Text =
-llvm::MemoryBuffer::getFile(ConfigFile.c_str());
+FS->getBufferForFile(ConfigFile);
 if (std::error_code EC = Text.getError()) {
   llvm::errs() << "Can't read " << ConfigFile << ": " << EC.message()
<< "\n";
@@ -363,7 +363,7 @@ FileOptionsBaseProvider::tryReadConfigFile(StringRef 
Directory) {
  << ParsedOptions.getError().message() << "\n";
   continue;
 }
-return OptionsSource(*ParsedOptions, ConfigFile.c_str());
+return OptionsSource(*ParsedOptions, ConfigFile.str());
   }
   return llvm::None;
 }

diff  --git a/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt 
b/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
index 016cb9d0c244..5b0cbac3a61e 100644
--- a/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
@@ -17,6 +17,7 @@ add_extra_unittest(ClangTidyTests
   LLVMModuleTest.cpp
   NamespaceAliaserTest.cpp
   ObjCModuleTest.cpp
+  OptionsProviderTest.cpp
   OverlappingReplacementsTest.cpp
   UsingInserterTest.cpp
   ReadabilityModuleTest.cpp

diff  --git a/clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp
new file mode 100644
index ..b99d0781e3f7
--- /dev/null
+++ b/clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp
@@ -0,0 +1,67 @@
+//=== ObjCModuleTest.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyOptions.h"
+#include "clang/Basic/LLVM.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+TEST(ClangTidyOptionsProvider, InMemoryFileSystems) {
+  llvm::IntrusiveRefCntPtr FileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  StringRef BaseClangTidy = R"(
+Checks: -*,clang-diagnostic-*
+  )";
+  StringRef Sub1ClangTidy = R"(
+Checks: readability-*
+InheritParentConfig: true
+  )";
+  StringRef Sub2ClangTidy = R"(
+Checks: bugprone-*,misc-*,clang-diagnostic-*
+InheritParentConfig: false
+)";
+  

[PATCH] D90944: [clang-tidy] implement misc-mt-unsafe

2020-11-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

While i share concern about false-positives, it is literally impossible to 
avoid them here,
and this should be viewed more as an enforcement tool (don't use thread-unsafe 
fns),
not bug-detection check.

What i would however like to be improved, is better docs.
I'm guessing `mt-unsafe` is MT-Unsafe from 
https://www.gnu.org/software/libc/manual/html_node/POSIX-Safety-Concepts.html ?
Does this fully cover all glibc functions? POSIX? Etc?


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

https://reviews.llvm.org/D90944

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


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-11-07 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson added inline comments.



Comment at: clang/test/CodeGenCXX/this-nonnull.cpp:1-2
+// RUN: %clang_cc1 -S -emit-llvm -o - -triple %itanium_abi_triple %s | 
FileCheck %s -check-prefix=CHECK-YES
+// RUN: %clang_cc1 -S -emit-llvm -o - -fno-delete-null-pointer-checks -triple 
%itanium_abi_triple %s | FileCheck %s -check-prefix=CHECK-NO
+

rsmith wrote:
> Please use a specific triple here (eg `x86_64-linux-gnu`); right now this 
> test would fail on Itanium targets where `sizeof(Struct)` is not exactly 12 
> (which is not guaranteed -- `int` might not be 32 bits wide on all Itanium 
> targets).
This has now been switched to `-triple=x86_64-linux-gnu` :)


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

https://reviews.llvm.org/D17993

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


[PATCH] D17993: [CodeGen] Apply 'nonnull' to 'this' pointer arguments.

2020-11-07 Thread CJ Johnson via Phabricator via cfe-commits
CJ-Johnson updated this revision to Diff 303648.

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

https://reviews.llvm.org/D17993

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CXX/except/except.spec/p14-ir.cpp
  clang/test/CodeGen/arm64-microsoft-arguments.cpp
  clang/test/CodeGen/attr-nomerge.cpp
  clang/test/CodeGen/no-builtin.cpp
  clang/test/CodeGen/temporary-lifetime.cpp
  clang/test/CodeGenCUDA/device-var-init.cu
  clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
  
clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-and-child-in-comdats.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/pass-byval-attributes.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/vbase-offset.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/virtual-function-call.cpp
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
  clang/test/CodeGenCXX/aix-static-init.cpp
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp
  clang/test/CodeGenCXX/apple-kext.cpp
  clang/test/CodeGenCXX/arm.cpp
  clang/test/CodeGenCXX/arm64-constructor-return.cpp
  clang/test/CodeGenCXX/array-default-argument.cpp
  clang/test/CodeGenCXX/atomicinit.cpp
  clang/test/CodeGenCXX/attr-disable-tail-calls.cpp
  clang/test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  clang/test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  clang/test/CodeGenCXX/attr.cpp
  clang/test/CodeGenCXX/auto-variable-template.cpp
  clang/test/CodeGenCXX/blocks-cxx11.cpp
  clang/test/CodeGenCXX/blocks.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/builtin_LINE.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/cfi-cross-dso.cpp
  clang/test/CodeGenCXX/conditional-gnu-ext.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
  clang/test/CodeGenCXX/constructor-direct-call.cpp
  clang/test/CodeGenCXX/constructor-init.cpp
  clang/test/CodeGenCXX/constructors.cpp
  clang/test/CodeGenCXX/copy-constructor-elim-2.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis.cpp
  clang/test/CodeGenCXX/cxx0x-delegating-ctors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx11-initializer-array-new.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp
  clang/test/CodeGenCXX/cxx1y-init-captures.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-copy-omission.cpp
  clang/test/CodeGenCXX/cxx1z-decomposition.cpp
  clang/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
  clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
  clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
  clang/test/CodeGenCXX/debug-info-class.cpp
  clang/test/CodeGenCXX/debug-info-ms-dtor-thunks.cpp
  clang/test/CodeGenCXX/default-arg-temps.cpp
  clang/test/CodeGenCXX/default-arguments.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/derived-to-base-conv.cpp
  clang/test/CodeGenCXX/destructors.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
  clang/test/CodeGenCXX/dllexport-ctor-closure.cpp
  clang/test/CodeGenCXX/dllexport-members.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport-dtor-thunks.cpp
  clang/test/CodeGenCXX/dllimport-members.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/duplicate-mangled-name.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/empty-nontrivially-copyable.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
  clang/test/CodeGenCXX/exceptions-seh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/CodeGenCXX/float128-declarations.cpp
  clang/test/CodeGenCXX/float16-declarations.cpp
  clang/test/CodeGenCXX/global-dtor-no-atexit.cpp
  clang/test/CodeGenCXX/global-init.cpp
  clang/test/CodeGenCXX/goto.cpp
  clang/test/CodeGenCXX/hidden-dllimport.cpp
  

[PATCH] D89651: [clang-tidy] Add bugprone-suspicious-memory-comparison check

2020-11-07 Thread Gabor Bencze via Phabricator via cfe-commits
gbencze marked an inline comment as done.
gbencze added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp:45
+
+  for (unsigned int i = 0; i < 2; ++i) {
+const Expr *ArgExpr = CE->getArg(i);

aaron.ballman wrote:
> The lint warning here is actually correct, which is a lovely change of pace.
Changed to `ArgIndex`



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp:70
+  if (ComparedBits.hasValue() && *ComparedBits >= PointeeSize &&
+  !Ctx.hasUniqueObjectRepresentations(PointeeQualifiedType)) {
+diag(CE->getBeginLoc(),

aaron.ballman wrote:
> Note that this may produce false positives as the list of objects with unique 
> representations is not complete. For instance, it doesn't handle _Complex or 
> _Atomic types, etc.
Yes, this could definitely cause some false positives. I'm not sure how we 
could easily fix it thought, especially if they are in some nested record.
Do you think this is a serious issue?



Comment at: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp:73
+ "comparing object representation of type %0 which does not have "
+ "unique object representations; consider comparing the values "
+ "manually")

aaron.ballman wrote:
> unique object representations -> a unique object representation
> 
> WDYT about:
> consider comparing the values manually -> consider comparing %select{the 
> values|the members of the object}0 manually
> 
> to make it more clear that these cases are different:
> ```
> memcmp(_float, _other_float, sizeof(float));
> memcmp(_struct, _other_struct, sizeof(some_struct));
> ```
> The use of "values" make it sound a bit like the user should be able to do 
> `if (some_struct == some_other_struct)` to me.
I wasn't entirely happy with the wording either; changed it according to your 
suggestions. 



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison-32bits.cpp:2
+// RUN: %check_clang_tidy %s bugprone-suspicious-memory-comparison %t \
+// RUN: -- -- -target x86_64-unknown-unknown -m32
+

aaron.ballman wrote:
> Wouldn't picking a 32-bit target suffice instead of `-m32`? e.g., `-target 
> i386-unknown-unknown`
To be fully honest, I have no idea, I saw some other tests using `-m32` so I 
decided to copy that. 



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.c:121
+  memcmp(, , sizeof(int)); // no-warning: not comparing entire object
+  memcmp(, , 2 * sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation 
of

aaron.ballman wrote:
> Just to make it obvious, I think a test like this would also be handy:
> ```
> struct Whatever {
>   int i[2];
>   char c;
> };
> 
> struct Whatever one, two;
> memcmp(, , 2 * sizeof(int)); // Shouldn't warn either
> ```
> which brings up a pathological case that I have no idea how it should behave:
> ```
> struct Whatever {
>   int i[2];
>   int : 0; // What now?!
> };
> 
> struct Whatever one, two;
> memcmp(, , 2 * sizeof(int)); // Warn? Don't Warn? Cry?
> ```
Added two new test cases for these: `Test_TrailingPadding2` and 
`Bitfield_TrailingUnnamed`. 
Purely empirically the latter one seems to have a size of `2*sizeof(int)`, so I 
assume there is no need to warn there. 



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp:229
+  // consider comparing the values manually
+}
+} // namespace alignment

aaron.ballman wrote:
> Another case we should be careful of is template instantiations:
> ```
> template 
> void func(const Ty *o1, const Ty *o2) {
>   memcmp(o1, o2, sizeof(Ty));
> }
> ```
> We don't want to diagnose that unless it's been instantiated with types that 
> are a problem.
Thanks, I added two new tests for these. I also made a minor fix in 
`registerMatchers` to make sure I don't try to evaluate a dependant expression. 


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

https://reviews.llvm.org/D89651

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


[PATCH] D89651: [clang-tidy] Add bugprone-suspicious-memory-comparison check

2020-11-07 Thread Gabor Bencze via Phabricator via cfe-commits
gbencze updated this revision to Diff 303643.
gbencze added a comment.

- Added some new test cases
- Fixed assertion in templates
- Changed loop variable name from `i` to `ArgIndex`
- Changed wording of warnings
- Changed CHECK-MESSAGES to be in a single line: turns out that only the first 
line is checked as a prefix if clang-tidy breaks it into multiple lines


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

https://reviews.llvm.org/D89651

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.h
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-suspicious-memory-comparison.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-exp42-c.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-flp37-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison-32bits.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.c
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp
@@ -0,0 +1,231 @@
+// RUN: %check_clang_tidy %s bugprone-suspicious-memory-comparison %t \
+// RUN: -- -- -target x86_64-unknown-unknown
+
+namespace std {
+typedef __SIZE_TYPE__ size_t;
+int memcmp(const void *lhs, const void *rhs, size_t count);
+} // namespace std
+
+namespace sei_cert_example_oop57_cpp {
+class C {
+  int i;
+
+public:
+  virtual void f();
+};
+
+void f(C , C ) {
+  if (!std::memcmp(, , sizeof(C))) {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: comparing object representation of non-standard-layout type 'sei_cert_example_oop57_cpp::C'; consider using a comparison operator instead
+  }
+}
+} // namespace sei_cert_example_oop57_cpp
+
+namespace inner_padding_64bit_only {
+struct S {
+  int x;
+  int *y;
+};
+
+void test() {
+  S a, b;
+  std::memcmp(, , sizeof(S));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of type 'inner_padding_64bit_only::S' which does not have a unique object representation; consider comparing the members of the object manually
+}
+} // namespace inner_padding_64bit_only
+
+namespace padding_in_base {
+class Base {
+  char c;
+  int i;
+};
+
+class Derived : public Base {};
+
+class Derived2 : public Derived {};
+
+void testDerived() {
+  Derived a, b;
+  std::memcmp(, , sizeof(Base));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of type 'padding_in_base::Derived' which does not have a unique object representation; consider comparing the members of the object manually
+  std::memcmp(, , sizeof(Derived));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of type 'padding_in_base::Derived' which does not have a unique object representation; consider comparing the members of the object manually
+}
+
+void testDerived2() {
+  Derived2 a, b;
+  std::memcmp(, , sizeof(Base));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of type 'padding_in_base::Derived2' which does not have a unique object representation; consider comparing the members of the object manually
+  std::memcmp(, , sizeof(Derived2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of type 'padding_in_base::Derived2' which does not have a unique object representation; consider comparing the members of the object manually
+}
+
+} // namespace padding_in_base
+
+namespace no_padding_in_base {
+class Base {
+  int a, b;
+};
+
+class Derived : public Base {};
+
+class Derived2 : public Derived {};
+
+void testDerived() {
+  Derived a, b;
+  std::memcmp(, , sizeof(Base));
+  std::memcmp(, , sizeof(Derived));
+}
+
+void testDerived2() {
+  Derived2 a, b;
+  std::memcmp(, , sizeof(char));
+  std::memcmp(, , sizeof(Base));
+  std::memcmp(, , sizeof(Derived2));
+}
+} // namespace no_padding_in_base
+
+namespace non_standard_layout {
+class C {
+private:
+  int x;
+
+public:
+  int y;
+};
+
+void test() {
+  C a, b;
+  std::memcmp(, , sizeof(C));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of non-standard-layout type 'non_standard_layout::C'; consider using a comparison operator instead
+}
+
+} // namespace non_standard_layout
+
+namespace static_ignored {
+struct S {
+  static char c;
+  int i;
+};
+
+void test() {
+  S a, b;
+  std::memcmp(, , sizeof(S));
+}
+} // namespace static_ignored
+
+namespace operator_void_ptr {

[PATCH] D90972: [clang-tidy] Install run-clang-tidy.py in bin/ as run-clang-tidy

2020-11-07 Thread Florian Schmaus via Phabricator via cfe-commits
Flow updated this revision to Diff 303642.
Flow added a comment.

Use backticks in ReleaseNotes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90972

Files:
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/docs/ReleaseNotes.rst


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -73,6 +73,9 @@
   ` and
   :doc:`modernize-make-unique `.
 
+- The `run-clang-tidy.py` helper script is now installed in `bin/` as
+  `run-clang-tidy`. It was previously installed in `share/clang/`.
+
 New modules
 ^^^
 
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -55,5 +55,6 @@
   DESTINATION share/clang
   COMPONENT clang-tidy)
 install(PROGRAMS run-clang-tidy.py
-  DESTINATION share/clang
-  COMPONENT clang-tidy)
+  DESTINATION bin
+  COMPONENT clang-tidy
+  RENAME run-clang-tidy)


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -73,6 +73,9 @@
   ` and
   :doc:`modernize-make-unique `.
 
+- The `run-clang-tidy.py` helper script is now installed in `bin/` as
+  `run-clang-tidy`. It was previously installed in `share/clang/`.
+
 New modules
 ^^^
 
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -55,5 +55,6 @@
   DESTINATION share/clang
   COMPONENT clang-tidy)
 install(PROGRAMS run-clang-tidy.py
-  DESTINATION share/clang
-  COMPONENT clang-tidy)
+  DESTINATION bin
+  COMPONENT clang-tidy
+  RENAME run-clang-tidy)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90714: [clang]Fix length threshold for MicrosoftMangle md5 hash

2020-11-07 Thread Melanie Blower 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 rGc511963d5adb: [clang] Fix length threshold for 
MicrosoftMangle md5 hash (authored by mibintc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90714

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  clang/test/CodeGenCXX/mangle-ms-md5.cpp


Index: clang/test/CodeGenCXX/mangle-ms-md5.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-md5.cpp
+++ clang/test/CodeGenCXX/mangle-ms-md5.cpp
@@ -49,3 +49,25 @@
 // HAVECTOR: 
"_CT??@c14087f0ec22b387aea7c59083f4f546@??@4ef4f8979c81f9d2224b32bf327e6bdf@4"
 }
 #endif
+
+// Verify the threshold where md5 mangling kicks in
+// Test an ident with 4088 characters, pre-hash, MangleName.size() is 4095
+#define X4088(X)\
+C2(C2(  \
+  C4(X,   X4(X),   X4(X),X8(X)),\
+  C4(X8(X),   X32(X),  X64(X),   X128(X))), \
+  C4(X256(X), X512(X), X1024(X), X2048(X)))
+#define Z4088 X4088(z)
+// Use initialization to verify mangled name association in the il
+int X4088(z) = 1515;
+// CHECK-DAG: @"?{{z+}}@@3HA" = dso_local global i32 1515, align 4
+
+// Test an ident with 4089 characters, pre-hash, MangleName.size() is 4096
+#define X4089(X)\
+C2(C2(  \
+  C4(X2(X),   X4(X),   X4(X),X8(X)),\
+  C4(X8(X),   X32(X),  X64(X),   X128(X))), \
+  C4(X256(X), X512(X), X1024(X), X2048(X)))
+// Use initialization to verify mangled name association in the il
+int X4089(z) = 1717;
+// CHECK-DAG: @"??@0269945400a3474730d6880df0967d8f@" = dso_local global i32 
1717, align 4
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -50,7 +50,7 @@
 bool StartsWithEscape = MangledName.startswith("\01");
 if (StartsWithEscape)
   MangledName = MangledName.drop_front(1);
-if (MangledName.size() <= 4096) {
+if (MangledName.size() < 4096) {
   OS << str();
   return;
 }


Index: clang/test/CodeGenCXX/mangle-ms-md5.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-md5.cpp
+++ clang/test/CodeGenCXX/mangle-ms-md5.cpp
@@ -49,3 +49,25 @@
 // HAVECTOR: "_CT??@c14087f0ec22b387aea7c59083f4f546@??@4ef4f8979c81f9d2224b32bf327e6bdf@4"
 }
 #endif
+
+// Verify the threshold where md5 mangling kicks in
+// Test an ident with 4088 characters, pre-hash, MangleName.size() is 4095
+#define X4088(X)\
+C2(C2(  \
+  C4(X,   X4(X),   X4(X),X8(X)),\
+  C4(X8(X),   X32(X),  X64(X),   X128(X))), \
+  C4(X256(X), X512(X), X1024(X), X2048(X)))
+#define Z4088 X4088(z)
+// Use initialization to verify mangled name association in the il
+int X4088(z) = 1515;
+// CHECK-DAG: @"?{{z+}}@@3HA" = dso_local global i32 1515, align 4
+
+// Test an ident with 4089 characters, pre-hash, MangleName.size() is 4096
+#define X4089(X)\
+C2(C2(  \
+  C4(X2(X),   X4(X),   X4(X),X8(X)),\
+  C4(X8(X),   X32(X),  X64(X),   X128(X))), \
+  C4(X256(X), X512(X), X1024(X), X2048(X)))
+// Use initialization to verify mangled name association in the il
+int X4089(z) = 1717;
+// CHECK-DAG: @"??@0269945400a3474730d6880df0967d8f@" = dso_local global i32 1717, align 4
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -50,7 +50,7 @@
 bool StartsWithEscape = MangledName.startswith("\01");
 if (StartsWithEscape)
   MangledName = MangledName.drop_front(1);
-if (MangledName.size() <= 4096) {
+if (MangledName.size() < 4096) {
   OS << str();
   return;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c511963 - [clang] Fix length threshold for MicrosoftMangle md5 hash

2020-11-07 Thread Melanie Blower via cfe-commits

Author: Melanie Blower
Date: 2020-11-07T07:40:24-08:00
New Revision: c511963d5adb1a8ca16adabf4b49f8d013a66785

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

LOG: [clang] Fix length threshold for MicrosoftMangle md5 hash

Reviewers: rnk, dblaikie

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

Added: 


Modified: 
clang/lib/AST/MicrosoftMangle.cpp
clang/test/CodeGenCXX/mangle-ms-md5.cpp

Removed: 




diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 3a263d487b75..de03a88d7612 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -50,7 +50,7 @@ struct msvc_hashing_ostream : public 
llvm::raw_svector_ostream {
 bool StartsWithEscape = MangledName.startswith("\01");
 if (StartsWithEscape)
   MangledName = MangledName.drop_front(1);
-if (MangledName.size() <= 4096) {
+if (MangledName.size() < 4096) {
   OS << str();
   return;
 }

diff  --git a/clang/test/CodeGenCXX/mangle-ms-md5.cpp 
b/clang/test/CodeGenCXX/mangle-ms-md5.cpp
index 52a29324af05..bd7cef2f099b 100644
--- a/clang/test/CodeGenCXX/mangle-ms-md5.cpp
+++ b/clang/test/CodeGenCXX/mangle-ms-md5.cpp
@@ -49,3 +49,25 @@ void g() {
 // HAVECTOR: 
"_CT??@c14087f0ec22b387aea7c59083f4f546@??@4ef4f8979c81f9d2224b32bf327e6bdf@4"
 }
 #endif
+
+// Verify the threshold where md5 mangling kicks in
+// Test an ident with 4088 characters, pre-hash, MangleName.size() is 4095
+#define X4088(X)\
+C2(C2(  \
+  C4(X,   X4(X),   X4(X),X8(X)),\
+  C4(X8(X),   X32(X),  X64(X),   X128(X))), \
+  C4(X256(X), X512(X), X1024(X), X2048(X)))
+#define Z4088 X4088(z)
+// Use initialization to verify mangled name association in the il
+int X4088(z) = 1515;
+// CHECK-DAG: @"?{{z+}}@@3HA" = dso_local global i32 1515, align 4
+
+// Test an ident with 4089 characters, pre-hash, MangleName.size() is 4096
+#define X4089(X)\
+C2(C2(  \
+  C4(X2(X),   X4(X),   X4(X),X8(X)),\
+  C4(X8(X),   X32(X),  X64(X),   X128(X))), \
+  C4(X256(X), X512(X), X1024(X), X2048(X)))
+// Use initialization to verify mangled name association in the il
+int X4089(z) = 1717;
+// CHECK-DAG: @"??@0269945400a3474730d6880df0967d8f@" = dso_local global i32 
1717, align 4



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


[PATCH] D90714: [clang]Fix length threshold for MicrosoftMangle md5 hash

2020-11-07 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 303640.
mibintc added a comment.

I submitted the test improvements separately, i'm going to push this version, 
thanks all


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90714

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  clang/test/CodeGenCXX/mangle-ms-md5.cpp


Index: clang/test/CodeGenCXX/mangle-ms-md5.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-md5.cpp
+++ clang/test/CodeGenCXX/mangle-ms-md5.cpp
@@ -49,3 +49,25 @@
 // HAVECTOR: 
"_CT??@c14087f0ec22b387aea7c59083f4f546@??@4ef4f8979c81f9d2224b32bf327e6bdf@4"
 }
 #endif
+
+// Verify the threshold where md5 mangling kicks in
+// Test an ident with 4088 characters, pre-hash, MangleName.size() is 4095
+#define X4088(X)\
+C2(C2(  \
+  C4(X,   X4(X),   X4(X),X8(X)),\
+  C4(X8(X),   X32(X),  X64(X),   X128(X))), \
+  C4(X256(X), X512(X), X1024(X), X2048(X)))
+#define Z4088 X4088(z)
+// Use initialization to verify mangled name association in the il
+int X4088(z) = 1515;
+// CHECK-DAG: @"?{{z+}}@@3HA" = dso_local global i32 1515, align 4
+
+// Test an ident with 4089 characters, pre-hash, MangleName.size() is 4096
+#define X4089(X)\
+C2(C2(  \
+  C4(X2(X),   X4(X),   X4(X),X8(X)),\
+  C4(X8(X),   X32(X),  X64(X),   X128(X))), \
+  C4(X256(X), X512(X), X1024(X), X2048(X)))
+// Use initialization to verify mangled name association in the il
+int X4089(z) = 1717;
+// CHECK-DAG: @"??@0269945400a3474730d6880df0967d8f@" = dso_local global i32 
1717, align 4
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -50,7 +50,7 @@
 bool StartsWithEscape = MangledName.startswith("\01");
 if (StartsWithEscape)
   MangledName = MangledName.drop_front(1);
-if (MangledName.size() <= 4096) {
+if (MangledName.size() < 4096) {
   OS << str();
   return;
 }


Index: clang/test/CodeGenCXX/mangle-ms-md5.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-md5.cpp
+++ clang/test/CodeGenCXX/mangle-ms-md5.cpp
@@ -49,3 +49,25 @@
 // HAVECTOR: "_CT??@c14087f0ec22b387aea7c59083f4f546@??@4ef4f8979c81f9d2224b32bf327e6bdf@4"
 }
 #endif
+
+// Verify the threshold where md5 mangling kicks in
+// Test an ident with 4088 characters, pre-hash, MangleName.size() is 4095
+#define X4088(X)\
+C2(C2(  \
+  C4(X,   X4(X),   X4(X),X8(X)),\
+  C4(X8(X),   X32(X),  X64(X),   X128(X))), \
+  C4(X256(X), X512(X), X1024(X), X2048(X)))
+#define Z4088 X4088(z)
+// Use initialization to verify mangled name association in the il
+int X4088(z) = 1515;
+// CHECK-DAG: @"?{{z+}}@@3HA" = dso_local global i32 1515, align 4
+
+// Test an ident with 4089 characters, pre-hash, MangleName.size() is 4096
+#define X4089(X)\
+C2(C2(  \
+  C4(X2(X),   X4(X),   X4(X),X8(X)),\
+  C4(X8(X),   X32(X),  X64(X),   X128(X))), \
+  C4(X256(X), X512(X), X1024(X), X2048(X)))
+// Use initialization to verify mangled name association in the il
+int X4089(z) = 1717;
+// CHECK-DAG: @"??@0269945400a3474730d6880df0967d8f@" = dso_local global i32 1717, align 4
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -50,7 +50,7 @@
 bool StartsWithEscape = MangledName.startswith("\01");
 if (StartsWithEscape)
   MangledName = MangledName.drop_front(1);
-if (MangledName.size() <= 4096) {
+if (MangledName.size() < 4096) {
   OS << str();
   return;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b0de3f6 - [clang] Improve Microsoft mangling lit test with dblaikie's suggestions

2020-11-07 Thread Melanie Blower via cfe-commits

Author: Melanie Blower
Date: 2020-11-07T07:32:34-08:00
New Revision: b0de3f67874ac3eff465cb2ef8ab6081292625c3

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

LOG: [clang] Improve Microsoft mangling lit test with dblaikie's suggestions

Added: 


Modified: 
clang/test/CodeGenCXX/mangle-ms-md5.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/mangle-ms-md5.cpp 
b/clang/test/CodeGenCXX/mangle-ms-md5.cpp
index 1492984d3fed..52a29324af05 100644
--- a/clang/test/CodeGenCXX/mangle-ms-md5.cpp
+++ b/clang/test/CodeGenCXX/mangle-ms-md5.cpp
@@ -1,12 +1,37 @@
 // RUN: %clang_cc1 -emit-llvm -o - -triple i686-pc-win32 %s | FileCheck %s
-int 
xxx;
+// Define macros, using 

[PATCH] D91000: [clang-tidy] CERT MSC24-C Obsolescent Functions check

2020-11-07 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:19
+namespace {
+static Preprocessor *PP;
+}

Why this could not be member of check class?



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:52
+  bool AnnexKIsWanted;
+  if (!PP->isMacroDefined("__STDC_LIB_EXT1__")) {
+AnnexKIsAvailable = false;

Why not to use plain assignment? See `readability-simplify-boolean-expr`.



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:59
+  AnnexKIsWanted = false;
+  if (!Id) {
+AnnexKIsWanted = false;

Early return will be better.



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:69
+AreSafeFunctionsWanted = IntValue.getZExtValue();
+if (AreSafeFunctionsWanted.hasValue()) {
+  AnnexKIsWanted = AreSafeFunctionsWanted.getValue();

Please elide braces.



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:80
+  bool AnnexKIsWanted = std::get<1>(AnnexKUsage);
+  if (!AnnexKIsWanted || !AnnexKIsAvailable) {
+return;

Please elide braces.



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:84
+  if (const auto *Function = Result.Nodes.getNodeAs("callexpr")) {
+const FunctionDecl *FD = Result.Nodes.getNodeAs("fn");
+const NamedDecl *NFD = dyn_cast(FD);

Could be `const auto *`, because type is spelled in same statement.



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:85
+const FunctionDecl *FD = Result.Nodes.getNodeAs("fn");
+const NamedDecl *NFD = dyn_cast(FD);
+std::string FunctionName = NFD->getNameAsString();

Could be `const auto *`, because type is spelled in same statement.



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:92
+  if (const auto *FunctionPointer = Result.Nodes.getNodeAs("fp")) {
+if (const FunctionDecl *FD = Result.Nodes.getNodeAs("fnp")) {
+  const NamedDecl *NFD = dyn_cast(FD);

Could be `const auto *`, because type is spelled in same statement.



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:93
+if (const FunctionDecl *FD = Result.Nodes.getNodeAs("fnp")) {
+  const NamedDecl *NFD = dyn_cast(FD);
+  std::string FunctionName = NFD->getNameAsString();

Could be `const auto *`, because type is spelled in same statement.



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.h:12
+
+#include "../ClangTidyCheck.h"
+namespace clang {

Please separate include statement and namespaces with empty line.



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.h:13
+#include "../ClangTidyCheck.h"
+namespace clang {
+namespace tidy {

Please separate with empty line.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cert-obsolescent-functions.rst:6
+
+Guards against using some unsafe function calls and function pointers which 
initialized with unsafe functions if __STDC_LIB_EXT1__ macro is defined and the 
value of __STDC_WANT_LIB_EXT1__ is 1. The usage of following functions are 
checked : bsearch,
+fprintf, fscanf, fwprintf, fwscanf, getenv, gmtime, localtime, mbsrtowcs,

Please make first statement same as in Release Notes. Please enclose all 
preprocessor variables and function names in double back-ticks.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cert-obsolescent-functions.rst:15
+
+This is a CERT security rule:
+https://wiki.sei.cmu.edu/confluence/display/c/MSC24-C.+Do+not+use+deprecated+or+obsolescent+functions

Link to original rule should be at the end. See other documentation as example. 



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cert-obsolescent-functions.rst:17
+https://wiki.sei.cmu.edu/confluence/display/c/MSC24-C.+Do+not+use+deprecated+or+obsolescent+functions
+  Example :
+  .code-block::

Please remove space before colon and separate code with empty line.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cert-obsolescent-functions.rst:18
+  Example :
+  .code-block::
+#define __STDC_WANT_LIB_EXT1__ 1

Should be `.. code-block:: c++`. See other documentation as formatting example.



Comment at: clang-tools-extra/test/clang-tidy/cert-obsolescent-functions.cpp:5
+#define __STDC_WANT_LIB_EXT1__ 1
+void * memmove(void *, void *, unsigned int);
+void f1(const char *in) {

Please separate with empty line.


CHANGES SINCE LAST ACTION
  

[PATCH] D90972: [clang-tidy] Install run-clang-tidy.py in bin/ as run-clang-tidy

2020-11-07 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:76
 
+- The run-clang-tidy.py helper script is now installed in bin/ as
+  run-clang-tidy. It was previously installed in share/clang/.

Please enclose run-clang-tidy.py, bin/, run-clang-tidy and share/clang/ in 
single back-ticks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90972

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


[PATCH] D90972: [clang-tidy] Install run-clang-tidy.py in bin/ as run-clang-tidy

2020-11-07 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru accepted this revision.
sylvestre.ledru added a comment.
This revision is now accepted and ready to land.

Sounds great. You might want to ask feedback to other reviews too!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90972

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


[PATCH] D90975: [clangd] Don't run clang-tidy AST traversal if there are no checks.

2020-11-07 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90975

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


[PATCH] D91001: [clang-tidy] Install run-clang-tidy.py as run-clang-tidy

2020-11-07 Thread Florian Schmaus via Phabricator via cfe-commits
Flow abandoned this revision.
Flow added a comment.

All changes introduced by this are now done in https://reviews.llvm.org/D90972


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91001

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


[PATCH] D90972: [clang-tidy] Install run-clang-tidy.py in bin/ as run-clang-tidy

2020-11-07 Thread Florian Schmaus via Phabricator via cfe-commits
Flow updated this revision to Diff 303638.
Flow retitled this revision from "[clang-tidy] Install run-clang-tidy.py in 
bin/ not in share/clang/" to "[clang-tidy] Install run-clang-tidy.py in bin/ as 
run-clang-tidy".

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90972

Files:
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/docs/ReleaseNotes.rst


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -73,6 +73,9 @@
   ` and
   :doc:`modernize-make-unique `.
 
+- The run-clang-tidy.py helper script is now installed in bin/ as
+  run-clang-tidy. It was previously installed in share/clang/.
+
 New modules
 ^^^
 
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -55,5 +55,6 @@
   DESTINATION share/clang
   COMPONENT clang-tidy)
 install(PROGRAMS run-clang-tidy.py
-  DESTINATION share/clang
-  COMPONENT clang-tidy)
+  DESTINATION bin
+  COMPONENT clang-tidy
+  RENAME run-clang-tidy)


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -73,6 +73,9 @@
   ` and
   :doc:`modernize-make-unique `.
 
+- The run-clang-tidy.py helper script is now installed in bin/ as
+  run-clang-tidy. It was previously installed in share/clang/.
+
 New modules
 ^^^
 
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -55,5 +55,6 @@
   DESTINATION share/clang
   COMPONENT clang-tidy)
 install(PROGRAMS run-clang-tidy.py
-  DESTINATION share/clang
-  COMPONENT clang-tidy)
+  DESTINATION bin
+  COMPONENT clang-tidy
+  RENAME run-clang-tidy)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90992: [clang-tidy] Use vfs::FileSystem when getting config

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

LGTM aside from a nit with the test.




Comment at: clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp:68
+} // namespace clang
\ No newline at end of file


Can you add the newline to the end of the file?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90992

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


[PATCH] D90180: [clang-tidy] find/fix unneeded semicolon after switch

2020-11-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D90180#2379803 , @nickdesaulniers 
wrote:

> In D90180#2375878 , @aaron.ballman 
> wrote:
>
>> In D90180#2374839 , 
>> @nickdesaulniers wrote:
>>
>>> In D90180#2357247 , @aaron.ballman 
>>> wrote:
>>>
 This will reduce the amount of compilation overhead for the clang-tidy 
 project over time by not needing to introduce a new check (with new 
 boilerplate) for each scenario but should hopefully still allow you to do 
 what you need (with config files perhaps) in your CI. WDYT?
>>>
>>> I don't see how renaming the check changes "compilation overhead" or why we 
>>> think "compilation overhead" of clang tidy is a concern in this case?
>>
>> I meant that if we had distinct checks `linuxkernel-switch-semi`, 
>> `linuxkernel-for-loop-semi`, `linuxkernel-middle-of-nowhere-semi`, etc that 
>> each one of those checks would require their own header file, source file, 
>> test files, documentation, etc. whereas if we had a single check, we'd 
>> reduce that overhead by only having one header, one source, one 
>> documentation, etc using config options, which makes fetching or building 
>> clang-tidy go ever-so-slightly faster.
>
> Ah, so you're recommending that future checks related to 
> additional/extraneous semicolons also be placed in this check, rather than 
> their own?  I don't have a problem with that.

Yup!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90180

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


[PATCH] D90972: [clang-tidy] Install run-clang-tidy.py in bin/ not in share/clang/

2020-11-07 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru requested changes to this revision.
sylvestre.ledru added a comment.
This revision now requires changes to proceed.

Thanks.
Could you please also update the release notes for 12?

And if you are motivated, this script should be documented (or at least 
mentioned in the doc a bit more)
I only found two references in:
clang-tools-extra/docs/clang-tidy/Contributing.rst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90972

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


[PATCH] D90972: [clang-tidy] Install run-clang-tidy.py in bin/ not in share/clang/

2020-11-07 Thread Florian Schmaus via Phabricator via cfe-commits
Flow added a comment.

In D90972#2380640 , @sylvestre.ledru 
wrote:

> By the way, while you are working on it, why not removing the python 
> extension when installing? We don't need to know that it is Python code.

Thanks for the feedback. Please see https://reviews.llvm.org/D91001


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90972

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


[PATCH] D91001: [clang-tidy] Install run-clang-tidy.py as run-clang-tidy

2020-11-07 Thread Florian Schmaus via Phabricator via cfe-commits
Flow created this revision.
Flow added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun, mgorny.
Herald added a project: clang.
Flow requested review of this revision.

Installed scripts in PATH usually do not carry a filename extension,
since there is no need to know that this is a Python script. For
example Debian and Ubuntu already install this script as
'run-clang-tidy' [1] and hence build systems like Meson also look for
this name first [2].

This changes was suggested by Sylvestre Ledru [3].

1: 
https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/-/blob/60aefb14171ab5c3867a0081844b507fc9f6e015/debian/clang-tidy-X.Y.links.in#L2
2: 
https://github.com/mesonbuild/meson/blob/b6dc4d5e5c6e838de0b52e62d982ba2547eb366d/mesonbuild/scripts/clangtidy.py#L44
3: https://reviews.llvm.org/D90972#2380640


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91001

Files:
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt


Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -56,4 +56,5 @@
   COMPONENT clang-tidy)
 install(PROGRAMS run-clang-tidy.py
   DESTINATION bin
-  COMPONENT clang-tidy)
+  COMPONENT clang-tidy
+  RENAME run-clang-tidy)


Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -56,4 +56,5 @@
   COMPONENT clang-tidy)
 install(PROGRAMS run-clang-tidy.py
   DESTINATION bin
-  COMPONENT clang-tidy)
+  COMPONENT clang-tidy
+  RENAME run-clang-tidy)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D91000: MSC24-C Obsolescent Functions check

2020-11-07 Thread Koller Tamás via Phabricator via cfe-commits
ktomi996 updated this revision to Diff 303633.

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

https://reviews.llvm.org/D91000

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp
  clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-obsolescent-functions.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/cert-obsolescent-functions.cpp

Index: clang-tools-extra/test/clang-tidy/cert-obsolescent-functions.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/cert-obsolescent-functions.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s cert-obsolescent-functions %t --
+
+#define __STDC_LIB_EXT1__
+#define __STDC_WANT_LIB_EXT1__ 1
+void * memmove(void *, void *, unsigned int);
+void f1(const char *in) {
+  int i = 1;
+  int j = 2;
+  memmove(, , sizeof(int));
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unsafe function memmove used. Safe memmove_s can be used instead. [cert-obsolescent-functions]
+}
+
+
+void f2(const char *in) {
+void * (*func_ptr)(void *, void *, unsigned int) = memmove;
+// CHECK-MESSAGES: :[[@LINE-1]]:56: warning: Unsafe function memmove used. Safe memmove_s can be used instead. [cert-obsolescent-functions]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -100,6 +100,7 @@
cert-msc32-c (redirects to cert-msc51-cpp) 
cert-msc50-cpp
cert-msc51-cpp
+   cert-obsolescent-functions
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cert-oop54-cpp (redirects to bugprone-unhandled-self-assignment) 
cppcoreguidelines-avoid-c-arrays (redirects to modernize-avoid-c-arrays) 
Index: clang-tools-extra/docs/clang-tidy/checks/cert-obsolescent-functions.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cert-obsolescent-functions.rst
@@ -0,0 +1,23 @@
+..title::clang-tidy-cert-obsolescent-functions
+
+cert-obsolescent-functions
+==
+
+Guards against using some unsafe function calls and function pointers which initialized with unsafe functions if __STDC_LIB_EXT1__ macro is defined and the value of __STDC_WANT_LIB_EXT1__ is 1. The usage of following functions are checked : bsearch,
+fprintf, fscanf, fwprintf, fwscanf, getenv, gmtime, localtime, mbsrtowcs,
+mbstowcs, memcpy, memmove, printf, qsort, setbuf, snprintf, sprintf, sscanf,
+strcat, strcpy, strerror, strncat, strncpy, strtok, swprintf, swscanf,
+vfprintf, vfscanf, vfwprintf, vfwscanf, vprintf, vscanf vsnprintf, vspr,
+wcscpy, wcsncat, wcsncpy wcsrtombs, wcstok, wcstombs, wctomb, wmemcpy,
+wmemmove, wprintf, wscanf,
+strlen
+
+This is a CERT security rule:
+https://wiki.sei.cmu.edu/confluence/display/c/MSC24-C.+Do+not+use+deprecated+or+obsolescent+functions
+  Example :
+  .code-block::
+#define __STDC_WANT_LIB_EXT1__ 1
+int i = 2;
+int j = 3;
+memmove(, , sizeof(int)); // diagnosed if __STDC_LIB_EXT1__ is defined in a
+// header, memmove_s usage is suggested instead.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -194,6 +194,13 @@
   against self-assignment either by checking self-assignment explicitly or
   using the copy-and-swap or the copy-and-move method.
 
+- New :doc:`cert-obsolescent-functions
+  ` check.
+
+  Guards against using some unsafe function calls and function pointers which
+  initialized with unsafe functions if some macros defined.
+
+
 - New :doc:`fuchsia-default-arguments-calls
   ` check.
 
Index: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.h
@@ -0,0 +1,36 @@
+//===--- ObsolescentFunctionsCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_OBSOLESCENTFUNCTIONSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_OBSOLESCENTFUNCTIONSCHECK_H
+
+#include "../ClangTidyCheck.h"

[PATCH] D91000: MSC24-C Obsolescent Functions check

2020-11-07 Thread Koller Tamás via Phabricator via cfe-commits
ktomi996 created this revision.
ktomi996 added reviewers: aaron.ballman, alexfh, hokein, njames93.
ktomi996 added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.
ktomi996 requested review of this revision.

This checker guards against using some vulnerable C functions which are 
mentioned in MSC24-C in obsolescent functions table.
The checker warns only if __STDC_LIB_EXT1__ macro is defined and the value of 
__STDC_WANT_LIB_EXT1__ macro is 1 in this case it suggests the corresponding 
functions from Annex K instead the vulnerable function.
https://wiki.sei.cmu.edu/confluence/display/c/MSC24-C.+Do+not+use+deprecated+or+obsolescent+functions


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91000

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp
  clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.h
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/CountFunctionsCheck.cpp
  clang-tools-extra/clang-tidy/misc/CountFunctionsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-obsolescent-functions.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/cert-obsolescent-functions.cpp

Index: clang-tools-extra/test/clang-tidy/cert-obsolescent-functions.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/cert-obsolescent-functions.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s cert-obsolescent-functions %t --
+
+#define __STDC_LIB_EXT1__
+#define __STDC_WANT_LIB_EXT1__ 1
+void * memmove(void *, void *, unsigned int);
+void f1(const char *in) {
+  int i = 1;
+  int j = 2;
+  memmove(, , sizeof(int));
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Unsafe function memmove used. Safe memmove_s can be used instead. [cert-obsolescent-functions]
+}
+
+
+void f2(const char *in) {
+void * (*func_ptr)(void *, void *, unsigned int) = memmove;
+// CHECK-MESSAGES: :[[@LINE-1]]:56: warning: Unsafe function memmove used. Safe memmove_s can be used instead. [cert-obsolescent-functions]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -100,6 +100,7 @@
cert-msc32-c (redirects to cert-msc51-cpp) 
cert-msc50-cpp
cert-msc51-cpp
+   cert-obsolescent-functions
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cert-oop54-cpp (redirects to bugprone-unhandled-self-assignment) 
cppcoreguidelines-avoid-c-arrays (redirects to modernize-avoid-c-arrays) 
Index: clang-tools-extra/docs/clang-tidy/checks/cert-obsolescent-functions.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cert-obsolescent-functions.rst
@@ -0,0 +1,23 @@
+..title::clang-tidy-cert-obsolescent-functions
+
+cert-obsolescent-functions
+==
+
+Guards against using some unsafe function calls and function pointers which initialized with unsafe functions if __STDC_LIB_EXT1__ macro is defined and the value of __STDC_WANT_LIB_EXT1__ is 1. The usage of following functions are checked : bsearch,
+fprintf, fscanf, fwprintf, fwscanf, getenv, gmtime, localtime, mbsrtowcs,
+mbstowcs, memcpy, memmove, printf, qsort, setbuf, snprintf, sprintf, sscanf,
+strcat, strcpy, strerror, strncat, strncpy, strtok, swprintf, swscanf,
+vfprintf, vfscanf, vfwprintf, vfwscanf, vprintf, vscanf vsnprintf, vspr,
+wcscpy, wcsncat, wcsncpy wcsrtombs, wcstok, wcstombs, wctomb, wmemcpy,
+wmemmove, wprintf, wscanf,
+strlen
+
+This is a CERT security rule:
+https://wiki.sei.cmu.edu/confluence/display/c/MSC24-C.+Do+not+use+deprecated+or+obsolescent+functions
+  Example :
+  .code-block::
+#define __STDC_WANT_LIB_EXT1__ 1
+int i = 2;
+int j = 3;
+memmove(, , sizeof(int)); // diagnosed if __STDC_LIB_EXT1__ is defined in a
+// header, memmove_s usage is suggested instead.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -194,6 +194,13 @@
   against self-assignment either by checking self-assignment explicitly or
   using the copy-and-swap or the copy-and-move method.
 
+- New :doc:`cert-obsolescent-functions
+  ` check.
+
+  Guards against using some unsafe function calls and function pointers which
+  initialized with unsafe functions if some macros defined.
+
+
 - New :doc:`fuchsia-default-arguments-calls
   ` check.
 

[PATCH] D90992: [clang-tidy] Use vfs::FileSystem when getting config

2020-11-07 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 303630.
njames93 added a comment.

Small tweak to the tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90992

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp
@@ -0,0 +1,67 @@
+//=== ObjCModuleTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyOptions.h"
+#include "clang/Basic/LLVM.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+TEST(ClangTidyOptionsProvider, InMemoryFileSystems) {
+  llvm::IntrusiveRefCntPtr FileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  StringRef BaseClangTidy = R"(
+Checks: -*,clang-diagnostic-*
+  )";
+  StringRef Sub1ClangTidy = R"(
+Checks: readability-*
+InheritParentConfig: true
+  )";
+  StringRef Sub2ClangTidy = R"(
+Checks: bugprone-*,misc-*,clang-diagnostic-*
+InheritParentConfig: false
+)";
+  FileSystem->addFile("ProjectRoot/.clang-tidy", 0,
+  llvm::MemoryBuffer::getMemBuffer(BaseClangTidy));
+  FileSystem->addFile("ProjectRoot/SubDir1/.clang-tidy", 0,
+  llvm::MemoryBuffer::getMemBuffer(Sub1ClangTidy));
+  FileSystem->addFile("ProjectRoot/SubDir1/File.cpp", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+  FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/.clang-tidy", 0,
+  llvm::MemoryBuffer::getMemBuffer(Sub2ClangTidy));
+  FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/File.cpp", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+  FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/SubDir3/File.cpp", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+
+  FileOptionsProvider FileOpt({}, {}, {}, FileSystem);
+
+  ClangTidyOptions File1Options =
+  FileOpt.getOptions("ProjectRoot/SubDir1/File.cpp");
+  ClangTidyOptions File2Options =
+  FileOpt.getOptions("ProjectRoot/SubDir1/SubDir2/File.cpp");
+  ClangTidyOptions File3Options =
+  FileOpt.getOptions("ProjectRoot/SubDir1/SubDir2/SubDir3/File.cpp");
+
+  ASSERT_TRUE(File1Options.Checks.hasValue());
+  EXPECT_EQ(*File1Options.Checks, "-*,clang-diagnostic-*,readability-*");
+  ASSERT_TRUE(File2Options.Checks.hasValue());
+  EXPECT_EQ(*File2Options.Checks, "bugprone-*,misc-*,clang-diagnostic-*");
+
+  // 2 and 3 should use the same config so these should also be the same.
+  EXPECT_EQ(File2Options.Checks, File3Options.Checks);
+}
+
+} // namespace test
+} // namespace tidy
+} // namespace clang
\ No newline at end of file
Index: clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
===
--- clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
+++ clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
@@ -17,6 +17,7 @@
   LLVMModuleTest.cpp
   NamespaceAliaserTest.cpp
   ObjCModuleTest.cpp
+  OptionsProviderTest.cpp
   OverlappingReplacementsTest.cpp
   UsingInserterTest.cpp
   ReadabilityModuleTest.cpp
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -325,7 +325,9 @@
 FileOptionsBaseProvider::tryReadConfigFile(StringRef Directory) {
   assert(!Directory.empty());
 
-  if (!llvm::sys::fs::is_directory(Directory)) {
+  llvm::ErrorOr DirectoryStatus = FS->status(Directory);
+
+  if (!DirectoryStatus || !DirectoryStatus->isDirectory()) {
 llvm::errs() << "Error reading configuration from " << Directory
  << ": directory doesn't exist.\n";
 return llvm::None;
@@ -336,15 +338,13 @@
 llvm::sys::path::append(ConfigFile, ConfigHandler.first);
 LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");
 
-bool IsFile = false;
-// Ignore errors from is_regular_file: we only need to know if we can read
-// the file or not.
-llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile);
-if (!IsFile)
+llvm::ErrorOr FileStatus = FS->status(ConfigFile);
+
+if (!FileStatus || !FileStatus->isRegularFile())
   continue;
 
 llvm::ErrorOr> Text =
-

[PATCH] D90992: [clang-tidy] Use vfs::FileSystem when getting config

2020-11-07 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 303629.
njames93 added a comment.
Herald added a subscriber: mgorny.

Added unittest for loading configs from an InMemoryFileSystem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90992

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp
@@ -0,0 +1,67 @@
+//=== ObjCModuleTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyOptions.h"
+#include "clang/Basic/LLVM.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+TEST(ClangTidyOptionsProvider, InMemoryFileSystems) {
+  llvm::IntrusiveRefCntPtr FileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  StringRef BaseClangTidy = R"(
+Checks: -*,clang-diagnostic-*
+  )";
+  StringRef Sub1ClangTidy = R"(
+Checks: readability-*
+InheritParentConfig: true
+  )";
+  StringRef Sub2ClangTidy = R"(
+Checks: bugprone-*,misc-*,clang-diagnostic-*
+InheritParentConfig: false
+)";
+  FileSystem->addFile("ProjectRoot/.clang-tidy", 0,
+  llvm::MemoryBuffer::getMemBuffer(BaseClangTidy));
+  FileSystem->addFile("ProjectRoot/SubDir1/.clang-tidy", 0,
+  llvm::MemoryBuffer::getMemBuffer(Sub1ClangTidy));
+  FileSystem->addFile("ProjectRoot/SubDir1/File1.cpp", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+  FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/.clang-tidy", 0,
+  llvm::MemoryBuffer::getMemBuffer(Sub2ClangTidy));
+  FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/File2.cpp", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+  FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/SubDir3/File3.cpp", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+
+  FileOptionsProvider FileOpt({}, {}, {}, FileSystem);
+
+  ClangTidyOptions File1Options =
+  FileOpt.getOptions("ProjectRoot/SubDir1/File1.cpp");
+  ClangTidyOptions File2Options =
+  FileOpt.getOptions("ProjectRoot/SubDir1/SubDir2/File1.cpp");
+  ClangTidyOptions File3Options =
+  FileOpt.getOptions("ProjectRoot/SubDir1/SubDir2/SubDir3/File3.cpp");
+
+  ASSERT_TRUE(File1Options.Checks.hasValue());
+  EXPECT_EQ(*File1Options.Checks, "-*,clang-diagnostic-*,readability-*");
+  ASSERT_TRUE(File2Options.Checks.hasValue());
+  EXPECT_EQ(*File2Options.Checks, "bugprone-*,misc-*,clang-diagnostic-*");
+
+  // 2 and 3 should use the same config so these should also be the same.
+  EXPECT_EQ(File2Options.Checks, File3Options.Checks);
+}
+
+} // namespace test
+} // namespace tidy
+} // namespace clang
\ No newline at end of file
Index: clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
===
--- clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
+++ clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
@@ -17,6 +17,7 @@
   LLVMModuleTest.cpp
   NamespaceAliaserTest.cpp
   ObjCModuleTest.cpp
+  OptionsProviderTest.cpp
   OverlappingReplacementsTest.cpp
   UsingInserterTest.cpp
   ReadabilityModuleTest.cpp
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -325,7 +325,9 @@
 FileOptionsBaseProvider::tryReadConfigFile(StringRef Directory) {
   assert(!Directory.empty());
 
-  if (!llvm::sys::fs::is_directory(Directory)) {
+  llvm::ErrorOr DirectoryStatus = FS->status(Directory);
+
+  if (!DirectoryStatus || !DirectoryStatus->isDirectory()) {
 llvm::errs() << "Error reading configuration from " << Directory
  << ": directory doesn't exist.\n";
 return llvm::None;
@@ -336,15 +338,13 @@
 llvm::sys::path::append(ConfigFile, ConfigHandler.first);
 LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");
 
-bool IsFile = false;
-// Ignore errors from is_regular_file: we only need to know if we can read
-// the file or not.
-llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile);
-if (!IsFile)
+llvm::ErrorOr FileStatus = FS->status(ConfigFile);
+
+if (!FileStatus || 

[PATCH] D90599: Fix a leak in `ASTUnit::LoadFromCommandLine()` wehn compiler invocation fails

2020-11-07 Thread Boris Staletic via Phabricator via cfe-commits
bstaletic updated this revision to Diff 303624.
bstaletic added a comment.

Fixed the code formatting error.


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

https://reviews.llvm.org/D90599

Files:
  clang/lib/Frontend/ASTUnit.cpp


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -1757,8 +1757,11 @@
 
 CI = createInvocationFromCommandLine(
 llvm::makeArrayRef(ArgBegin, ArgEnd), Diags, VFS);
-if (!CI)
+if (!CI) {
+  for (const auto  : RemappedFiles)
+delete RF.second;
   return nullptr;
+}
   }
 
   // Override any files that need remapping


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -1757,8 +1757,11 @@
 
 CI = createInvocationFromCommandLine(
 llvm::makeArrayRef(ArgBegin, ArgEnd), Diags, VFS);
-if (!CI)
+if (!CI) {
+  for (const auto  : RemappedFiles)
+delete RF.second;
   return nullptr;
+}
   }
 
   // Override any files that need remapping
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90972: [clang-tidy] Install run-clang-tidy.py in bin/ not in share/clang/

2020-11-07 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

FWIW, I am doing this change already in Debian & Ubuntu ( 
https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/-/blob/10/debian/clang-tidy-X.Y.links.in#L2
 )

By the way, while you are working on it, why not removing the python extension 
when installing? We don't need to know that it is Python code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90972

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


[PATCH] D90972: [clang-tidy] Install run-clang-tidy.py in bin/ not in share/clang/

2020-11-07 Thread Florian Schmaus via Phabricator via cfe-commits
Flow added reviewers: alexfh, sylvestre.ledru, Eugene.Zelenko.
Flow added a comment.

Adding involved persons from https://reviews.llvm.org/D12700 as reviewers, 
which was the change introducing `share/clang/` as install location.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90972

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


[PATCH] D89158: [NewPM] Provide method to run all pipeline callbacks, used for -O0

2020-11-07 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

  $ cmake \
  -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_C_COMPILER=$(command -v clang) \
  -DCMAKE_CXX_COMPILER=$(command -v clang++) \
  -DLLVM_CCACHE_BUILD=ON \
  -DLLVM_ENABLE_PROJECTS="clang;polly" \
  -DLLVM_TARGETS_TO_BUILD=X86 \
  -DLLVM_USE_LINKER=$(command -v ld.lld) \
  ../llvm
  
  $ ninja check-clang
  ...
  [0/1] Running the Clang regression tests
  -- Testing: 26861 tests, 64 workers --
  Testing: llvm-lit: /tmp/llvm-project/llvm/utils/lit/lit/llvm/config.py:347: 
note: using clang: /tmp/llvm-project/build/bin/clang
   0.. 10
  FAIL: Clang :: CodeGen/lto-newpm-pipeline.c (3731 of 26861)
   TEST 'Clang :: CodeGen/lto-newpm-pipeline.c' FAILED 

  Script:
  --
  : 'RUN: at line 3';   /tmp/llvm-project/build/bin/clang -cc1 
-internal-isystem /tmp/llvm-project/build/lib/clang/12.0.0/include 
-nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-fexperimental-new-pass-manager -fdebug-pass-manager -flto=full -O0 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c 2>&1 | 
/tmp/llvm-project/build/bin/FileCheck 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c
-check-prefix=CHECK-FULL-O0
  : 'RUN: at line 5';   /tmp/llvm-project/build/bin/clang -cc1 
-internal-isystem /tmp/llvm-project/build/lib/clang/12.0.0/include 
-nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-fexperimental-new-pass-manager -fdebug-pass-manager -flto=thin -O0 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c 2>&1 | 
/tmp/llvm-project/build/bin/FileCheck 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c
-check-prefix=CHECK-THIN-O0
  : 'RUN: at line 7';   /tmp/llvm-project/build/bin/clang -cc1 
-internal-isystem /tmp/llvm-project/build/lib/clang/12.0.0/include 
-nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-fexperimental-new-pass-manager -fdebug-pass-manager -flto=full -O1 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c 2>&1 | 
/tmp/llvm-project/build/bin/FileCheck 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c
-check-prefix=CHECK-FULL-OPTIMIZED
  : 'RUN: at line 9';   /tmp/llvm-project/build/bin/clang -cc1 
-internal-isystem /tmp/llvm-project/build/lib/clang/12.0.0/include 
-nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-fexperimental-new-pass-manager -fdebug-pass-manager -flto=thin -O1 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c 2>&1 | 
/tmp/llvm-project/build/bin/FileCheck 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c
-check-prefix=CHECK-THIN-OPTIMIZED
  : 'RUN: at line 11';   /tmp/llvm-project/build/bin/clang -cc1 
-internal-isystem /tmp/llvm-project/build/lib/clang/12.0.0/include 
-nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-fexperimental-new-pass-manager -fdebug-pass-manager -flto=full -O2 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c 2>&1 | 
/tmp/llvm-project/build/bin/FileCheck 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c
-check-prefix=CHECK-FULL-OPTIMIZED
  : 'RUN: at line 13';   /tmp/llvm-project/build/bin/clang -cc1 
-internal-isystem /tmp/llvm-project/build/lib/clang/12.0.0/include 
-nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-fexperimental-new-pass-manager -fdebug-pass-manager -flto=thin -O2 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c 2>&1 | 
/tmp/llvm-project/build/bin/FileCheck 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c
-check-prefix=CHECK-THIN-OPTIMIZED
  : 'RUN: at line 15';   /tmp/llvm-project/build/bin/clang -cc1 
-internal-isystem /tmp/llvm-project/build/lib/clang/12.0.0/include 
-nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-fexperimental-new-pass-manager -fdebug-pass-manager -flto=full -O3 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c 2>&1 | 
/tmp/llvm-project/build/bin/FileCheck 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c
-check-prefix=CHECK-FULL-OPTIMIZED
  : 'RUN: at line 17';   /tmp/llvm-project/build/bin/clang -cc1 
-internal-isystem /tmp/llvm-project/build/lib/clang/12.0.0/include 
-nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-fexperimental-new-pass-manager -fdebug-pass-manager -flto=thin -O3 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c 2>&1 | 
/tmp/llvm-project/build/bin/FileCheck 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c
-check-prefix=CHECK-THIN-OPTIMIZED
  : 'RUN: at line 19';   /tmp/llvm-project/build/bin/clang -cc1 
-internal-isystem /tmp/llvm-project/build/lib/clang/12.0.0/include 
-nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null 
-fexperimental-new-pass-manager -fdebug-pass-manager -flto=full -Os 
/tmp/llvm-project/clang/test/CodeGen/lto-newpm-pipeline.c 2>&1 | 
/tmp/llvm-project/build/bin/FileCheck