[clang] 2a42c75 - [clang-format] [PR19056] Add support for access modifiers indentation

2021-02-26 Thread Marek Kurdej via cfe-commits

Author: Jakub Budiský
Date: 2021-02-26T09:17:07+01:00
New Revision: 2a42c759ae7bb09dd448d188138f310d014fcab6

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

LOG: [clang-format] [PR19056] Add support for access modifiers indentation

Adds support for coding styles that make a separate indentation level for 
access modifiers, such as Code::Blocks or QtCreator.

The new option, `IndentAccessModifiers`, if enabled, forces the content inside 
classes, structs and unions (“records”) to be indented twice while removing a 
level for access modifiers. The value of `AccessModifierOffset` is disregarded 
in this case, aiming towards an ease of use.

==
The PR (https://bugs.llvm.org/show_bug.cgi?id=19056) had an implementation 
attempt by @MyDeveloperDay already (https://reviews.llvm.org/D60225) but I've 
decided to start from scratch. They differ in functionality, chosen approaches, 
and even the option name. The code tries to re-use the existing functionality 
to achieve this behavior, limiting possibility of breaking something else.

Reviewed By: MyDeveloperDay, curdeius, HazardyKnusperkeks

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 7ae8ea913099..1dbf11987cd8 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2360,6 +2360,33 @@ the configuration (without a prefix: ``Auto``).
   ``ClassImpl.hpp`` would not have the main include file put on top
   before any other include.
 
+**IndentAccessModifiers** (``bool``)
+  Specify whether access modifiers should have their own indentation level.
+
+  When ``false``, access modifiers are indented (or outdented) relative to
+  the record members, respecting the ``AccessModifierOffset``. Record
+  members are indented one level below the record.
+  When ``true``, access modifiers get their own indentation level. As a
+  consequence, record members are indented 2 levels below the record,
+  regardless of the access modifier presence. Value of the
+  ``AccessModifierOffset`` is ignored.
+
+  .. code-block:: c++
+
+ false: true:
+ class C {  vs. class C {
+   class D {class D {
+ void bar();void bar();
+   protected: protected:
+ D();   D();
+   };   };
+ public:  public:
+   C(); C();
+ }; };
+ void foo() {   void foo() {
+   return 1;  return 1;
+ }  }
+
 **IndentCaseBlocks** (``bool``)
   Indent case label blocks one level from the case label.
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 26b380407c0b..6a0ebd9ab3ee 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -196,6 +196,9 @@ clang-format
 - ``BasedOnStyle: InheritParentConfig`` allows to use the ``.clang-format`` of
   the parent directories to overwrite only parts of it.
 
+- Option ``IndentAccessModifiers`` has been added to be able to give access
+  modifiers their own indentation level inside records.
+
 libclang
 
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 1a669ebf07f5..d60c56058a85 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2047,6 +2047,32 @@ struct FormatStyle {
 
   tooling::IncludeStyle IncludeStyle;
 
+  /// Specify whether access modifiers should have their own indentation level.
+  ///
+  /// When ``false``, access modifiers are indented (or outdented) relative to
+  /// the record members, respecting the ``AccessModifierOffset``. Record
+  /// members are indented one level below the record.
+  /// When ``true``, access modifiers get their own indentation level. As a
+  /// consequence, record members are always indented 2 levels below the 
record,
+  /// regardless of the access modifier presence. Value of the
+  /// ``AccessModifierOffset`` is ignored.
+  /// \code
+  ///false: true:

[PATCH] D94661: [clang-format] [PR19056] Add support for access modifiers indentation

2021-02-26 Thread Marek Kurdej via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2a42c759ae7b: [clang-format] [PR19056] Add support for 
access modifiers indentation (authored by Budovi, committed by curdeius).

Changed prior to commit:
  https://reviews.llvm.org/D94661?vs=322645&id=326618#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94661

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -15453,6 +15453,7 @@
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
   CHECK_PARSE_BOOL(DisableFormat);
+  CHECK_PARSE_BOOL(IndentAccessModifiers);
   CHECK_PARSE_BOOL(IndentCaseLabels);
   CHECK_PARSE_BOOL(IndentCaseBlocks);
   CHECK_PARSE_BOOL(IndentGotoLabels);
@@ -19155,6 +19156,57 @@
 "}",
 format(Source, Style));
 }
+
+TEST_F(FormatTest, IndentAccessModifiers) {
+  FormatStyle Style = getLLVMStyle();
+  Style.IndentAccessModifiers = true;
+  // Members are *two* levels below the record;
+  // Style.IndentWidth == 2, thus yielding a 4 spaces wide indentation.
+  verifyFormat("class C {\n"
+   "int i;\n"
+   "};\n",
+   Style);
+  verifyFormat("union C {\n"
+   "int i;\n"
+   "unsigned u;\n"
+   "};\n",
+   Style);
+  // Access modifiers should be indented one level below the record.
+  verifyFormat("class C {\n"
+   "  public:\n"
+   "int i;\n"
+   "};\n",
+   Style);
+  verifyFormat("struct S {\n"
+   "  private:\n"
+   "class C {\n"
+   "int j;\n"
+   "\n"
+   "  public:\n"
+   "C();\n"
+   "};\n"
+   "\n"
+   "  public:\n"
+   "int i;\n"
+   "};\n",
+   Style);
+  // Enumerations are not records and should be unaffected.
+  Style.AllowShortEnumsOnASingleLine = false;
+  verifyFormat("enum class E\n"
+   "{\n"
+   "  A,\n"
+   "  B\n"
+   "};\n",
+   Style);
+  // Test with a different indentation width;
+  // also proves that the result is Style.AccessModifierOffset agnostic.
+  Style.IndentWidth = 3;
+  verifyFormat("class C {\n"
+   "   public:\n"
+   "  int i;\n"
+   "};\n",
+   Style);
+}
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -85,7 +85,7 @@
   void reset();
   void parseFile();
   void parseLevel(bool HasOpeningBrace);
-  void parseBlock(bool MustBeDeclaration, bool AddLevel = true,
+  void parseBlock(bool MustBeDeclaration, unsigned AddLevels = 1u,
   bool MunchSemi = true);
   void parseChildBlock();
   void parsePPDirective();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -579,7 +579,7 @@
   return h;
 }
 
-void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
+void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, unsigned AddLevels,
  bool MunchSemi) {
   assert(FormatTok->isOneOf(tok::l_brace, TT_MacroBlockBegin) &&
  "'{' or macro block token expected");
@@ -589,7 +589,7 @@
   size_t PPStartHash = computePPHash();
 
   unsigned InitialLevel = Line->Level;
-  nextToken(/*LevelDifference=*/AddLevel ? 1 : 0);
+  nextToken(/*LevelDifference=*/AddLevels);
 
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
@@ -604,8 +604,7 @@
 
   ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
   MustBeDeclaration);
-  if (AddLevel)
-++Line->Level;
+  Line->Level += AddLevels;
   parseLevel(/*HasOpeningBrace=*/true);
 
   if (eof())
@@ -621,7 +620,7 @@
   size_t PPEndHash = computePPHash();
 
   // Munch the closing brace.
-  nextToken(/*LevelDifference=*/AddLevel ? -1 : 0);
+  nextToken(/*LevelDifference=*/-AddLevels);
 
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens()

[clang] d412dbe - [clang][NFC] Extract Target and AuxTarget creation in CompilerInstance to new function

2021-02-26 Thread Sam McCall via cfe-commits

Author: Yu-Hsun Chiang
Date: 2021-02-26T09:29:11+01:00
New Revision: d412dbe388819dd68bbe4a3967783fdf80400860

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

LOG: [clang][NFC] Extract Target and AuxTarget creation in CompilerInstance to 
new function

As @sammccall mentioned in [[ https://reviews.llvm.org/D97109 | D97109 ]], I've 
extract the logic of creating Target and AuxTarget into a new function called 
`createTargetAndAuxTarget`.

Since there are many similar code in clang or other related tools, 
consolidating them into a single function may help others to maintain the logic 
handling target related things.

Reviewed By: sammccall

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

Added: 


Modified: 
clang/include/clang/Frontend/CompilerInstance.h
clang/lib/Frontend/CompilerInstance.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 57632f8770f0..e5d0790f9e10 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -382,6 +382,9 @@ class CompilerInstance : public ModuleLoader {
   /// Replace the current AuxTarget.
   void setAuxTarget(TargetInfo *Value);
 
+  // Create Target and AuxTarget based on current options
+  bool createTarget();
+
   /// }
   /// @name Virtual File System
   /// {

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 7c2b2bf57917..d40240b5b527 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -97,6 +97,54 @@ void 
CompilerInstance::setVerboseOutputStream(std::unique_ptr Value
 void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; }
 void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
 
+bool CompilerInstance::createTarget() {
+  // Create the target instance.
+  setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
+ getInvocation().TargetOpts));
+  if (!hasTarget())
+return false;
+
+  // Create TargetInfo for the other side of CUDA/OpenMP/SYCL compilation.
+  if ((getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
+   getLangOpts().SYCLIsDevice) &&
+  !getFrontendOpts().AuxTriple.empty()) {
+auto TO = std::make_shared();
+TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple);
+if (getFrontendOpts().AuxTargetCPU)
+  TO->CPU = getFrontendOpts().AuxTargetCPU.getValue();
+if (getFrontendOpts().AuxTargetFeatures)
+  TO->FeaturesAsWritten = getFrontendOpts().AuxTargetFeatures.getValue();
+TO->HostTriple = getTarget().getTriple().str();
+setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), TO));
+  }
+
+  if (!getTarget().hasStrictFP() && !getLangOpts().ExpStrictFP) {
+if (getLangOpts().getFPRoundingMode() !=
+llvm::RoundingMode::NearestTiesToEven) {
+  getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_rounding);
+  getLangOpts().setFPRoundingMode(llvm::RoundingMode::NearestTiesToEven);
+}
+if (getLangOpts().getFPExceptionMode() != LangOptions::FPE_Ignore) {
+  getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_exceptions);
+  getLangOpts().setFPExceptionMode(LangOptions::FPE_Ignore);
+}
+// FIXME: can we disable FEnvAccess?
+  }
+
+  // Inform the target of the language options.
+  // FIXME: We shouldn't need to do this, the target should be immutable once
+  // created. This complexity should be lifted elsewhere.
+  getTarget().adjust(getLangOpts());
+
+  // Adjust target options based on codegen options.
+  getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts());
+
+  if (auto *Aux = getAuxTarget())
+getTarget().setAuxTarget(Aux);
+
+  return true;
+}
+
 llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem() const {
   return getFileManager().getVirtualFileSystem();
 }
@@ -878,51 +926,9 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) {
   if (!Act.PrepareToExecute(*this))
 return false;
 
-  // Create the target instance.
-  setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
- getInvocation().TargetOpts));
-  if (!hasTarget())
+  if (!createTarget())
 return false;
 
-  // Create TargetInfo for the other side of CUDA/OpenMP/SYCL compilation.
-  if ((getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
-   getLangOpts().SYCLIsDevice) &&
-  !getFrontendOpts().AuxTriple.empty()) {
-auto TO = std::make_shared();
-TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple);
-if (getFrontendOpts().AuxTargetCPU)
-  TO->CPU = getFrontendOpts().AuxTargetCPU.getValue

[PATCH] D97493: [clang][NFC] Extract Target and AuxTarget creation in CompilerInstance to new function

2021-02-26 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd412dbe38881: [clang][NFC] Extract Target and AuxTarget 
creation in CompilerInstance to new… (authored by oToToT, committed by 
sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97493

Files:
  clang/include/clang/Frontend/CompilerInstance.h
  clang/lib/Frontend/CompilerInstance.cpp

Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -97,6 +97,54 @@
 void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; }
 void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
 
+bool CompilerInstance::createTarget() {
+  // Create the target instance.
+  setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
+ getInvocation().TargetOpts));
+  if (!hasTarget())
+return false;
+
+  // Create TargetInfo for the other side of CUDA/OpenMP/SYCL compilation.
+  if ((getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
+   getLangOpts().SYCLIsDevice) &&
+  !getFrontendOpts().AuxTriple.empty()) {
+auto TO = std::make_shared();
+TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple);
+if (getFrontendOpts().AuxTargetCPU)
+  TO->CPU = getFrontendOpts().AuxTargetCPU.getValue();
+if (getFrontendOpts().AuxTargetFeatures)
+  TO->FeaturesAsWritten = getFrontendOpts().AuxTargetFeatures.getValue();
+TO->HostTriple = getTarget().getTriple().str();
+setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), TO));
+  }
+
+  if (!getTarget().hasStrictFP() && !getLangOpts().ExpStrictFP) {
+if (getLangOpts().getFPRoundingMode() !=
+llvm::RoundingMode::NearestTiesToEven) {
+  getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_rounding);
+  getLangOpts().setFPRoundingMode(llvm::RoundingMode::NearestTiesToEven);
+}
+if (getLangOpts().getFPExceptionMode() != LangOptions::FPE_Ignore) {
+  getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_exceptions);
+  getLangOpts().setFPExceptionMode(LangOptions::FPE_Ignore);
+}
+// FIXME: can we disable FEnvAccess?
+  }
+
+  // Inform the target of the language options.
+  // FIXME: We shouldn't need to do this, the target should be immutable once
+  // created. This complexity should be lifted elsewhere.
+  getTarget().adjust(getLangOpts());
+
+  // Adjust target options based on codegen options.
+  getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts());
+
+  if (auto *Aux = getAuxTarget())
+getTarget().setAuxTarget(Aux);
+
+  return true;
+}
+
 llvm::vfs::FileSystem &CompilerInstance::getVirtualFileSystem() const {
   return getFileManager().getVirtualFileSystem();
 }
@@ -878,51 +926,9 @@
   if (!Act.PrepareToExecute(*this))
 return false;
 
-  // Create the target instance.
-  setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
- getInvocation().TargetOpts));
-  if (!hasTarget())
+  if (!createTarget())
 return false;
 
-  // Create TargetInfo for the other side of CUDA/OpenMP/SYCL compilation.
-  if ((getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
-   getLangOpts().SYCLIsDevice) &&
-  !getFrontendOpts().AuxTriple.empty()) {
-auto TO = std::make_shared();
-TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple);
-if (getFrontendOpts().AuxTargetCPU)
-  TO->CPU = getFrontendOpts().AuxTargetCPU.getValue();
-if (getFrontendOpts().AuxTargetFeatures)
-  TO->FeaturesAsWritten = getFrontendOpts().AuxTargetFeatures.getValue();
-TO->HostTriple = getTarget().getTriple().str();
-setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), TO));
-  }
-
-  if (!getTarget().hasStrictFP() && !getLangOpts().ExpStrictFP) {
-if (getLangOpts().getFPRoundingMode() !=
-llvm::RoundingMode::NearestTiesToEven) {
-  getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_rounding);
-  getLangOpts().setFPRoundingMode(llvm::RoundingMode::NearestTiesToEven);
-}
-if (getLangOpts().getFPExceptionMode() != LangOptions::FPE_Ignore) {
-  getDiagnostics().Report(diag::warn_fe_backend_unsupported_fp_exceptions);
-  getLangOpts().setFPExceptionMode(LangOptions::FPE_Ignore);
-}
-// FIXME: can we disable FEnvAccess?
-  }
-
-  // Inform the target of the language options.
-  //
-  // FIXME: We shouldn't need to do this, the target should be immutable once
-  // created. This complexity should be lifted elsewhere.
-  getTarget().adjust(getLangOpts());
-
-  // Adjust target options based on codegen options.
-  getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts());
-
-  if (auto *Aux = getAuxTarget())
-getTarget().setAuxTarget(Aux)

[PATCH] D97361: [clang-tidy] Add readability-redundant-using check

2021-02-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

You can look into **misc/UnusedUsingDeclsCheck.cpp** (if not done yet), that 
check handles `using` too. And that check is related to this check, the module 
should be the same too (`misc`)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97361

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


[PATCH] D97361: [clang-tidy] Add readability-redundant-using check

2021-02-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

There should be already a name lookup implemented somewhere in clang 
(`DeclContext`? or Sema) that maybe usable here (check if the name of the 
"used" entity is visible in the declaration context of the `using` statement). 
Probably it is not as simple to do because the `using` is already there and it 
may depend on the order.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97361

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


[PATCH] D97534: SEH: capture 'this'

2021-02-26 Thread Olivier Goffart via Phabricator via cfe-commits
ogoffart created this revision.
ogoffart added reviewers: rnk, asl, cfe-commits.
ogoffart requested review of this revision.
Herald added a project: clang.

Simply make sure that the CodeGenFunction::CXXThisValue and CXXABIThisValue
are correctly initialized to the recovered value.
For lambda capture, we also need to make sure to fill the LambdaCaptureFields


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97534

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp

Index: clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
===
--- clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
+++ clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
@@ -39,13 +39,13 @@
   int l1 = 13;
   __try {
 might_crash();
-  } __except(basic_filter(l1)) {
-// FIXME: Test capturing 'this' and 'm1'.
+  } __except(basic_filter(l1, m1)) {
   }
 }
 
 // CHECK-LABEL: define dso_local void @"?test_method@S@@QEAAXXZ"(%struct.S* {{[^,]*}} %this)
-// CHECK: @llvm.localescape(i32* %[[l1_addr:[^, ]*]])
+// CHECK: @llvm.localescape(i32* %[[l1_addr:[^, ]*]], %struct.S** %[[this_addr:[^, ]*]])
+// CHECK: store %struct.S* %this, %struct.S** %[[this_addr]], align 8
 // CHECK: store i32 13, i32* %[[l1_addr]], align 4
 // CHECK: invoke void @might_crash()
 
@@ -53,8 +53,46 @@
 // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.eh.recoverfp(i8* bitcast (void (%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %frame_pointer)
 // CHECK: %[[l1_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %[[fp]], i32 0)
 // CHECK: %[[l1_ptr:[^ ]*]] = bitcast i8* %[[l1_i8]] to i32*
+// CHECK: %[[this_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %[[fp]], i32 1)
+// CHECK: %[[this_ptr:[^ ]*]] = bitcast i8* %[[this_i8]] to %struct.S**
+// CHECK: %[[this:[^ ]*]] = load %struct.S*, %struct.S** %[[this_ptr]], align 8
+// CHECK: %[[m1_ptr:[^ ]*]] = getelementptr inbounds %struct.S, %struct.S* %[[this]], i32 0, i32 0
+// CHECK: %[[m1:[^ ]*]] = load i32, i32* %[[m1_ptr]]
 // CHECK: %[[l1:[^ ]*]] = load i32, i32* %[[l1_ptr]]
-// CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l1]])
+// CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l1]], i32 %[[m1]])
+
+
+struct V {
+  void test_virtual(int p1);
+  virtual void virt(int p1);
+};
+
+void V::test_virtual(int p1) {
+  __try {
+might_crash();
+  } __finally {
+virt(p1);
+  }
+}
+
+// CHECK-LABEL: define dso_local void @"?test_virtual@V@@QEAAXH@Z"(%struct.V* {{[^,]*}} %this, i32 %p1)
+// CHECK: @llvm.localescape(%struct.V** %[[this_addr:[^, ]*]], i32* %[[p1_addr:[^, ]*]])
+// CHECK: store i32 %p1, i32* %[[p1_addr]], align 4
+// CHECK: store %struct.V* %this, %struct.V** %[[this_addr]], align 8
+// CHECK: invoke void @might_crash()
+
+// CHECK-LABEL: define internal void @"?fin$0@0@test_virtual@V@@"(i8 %abnormal_termination, i8* %frame_pointer)
+// CHECK: %[[this_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.V*, i32)* @"?test_virtual@V@@QEAAXH@Z" to i8*), i8* %frame_pointer, i32 0)
+// CHECK: %[[this_ptr:[^ ]*]] = bitcast i8* %[[this_i8]] to %struct.V**
+// CHECK: %[[this:[^ ]*]] = load %struct.V*, %struct.V** %[[this_ptr]], align 8
+// CHECK: %[[p1_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.V*, i32)* @"?test_virtual@V@@QEAAXH@Z" to i8*), i8* %frame_pointer, i32 1)
+// CHECK: %[[p1_ptr:[^ ]*]] = bitcast i8* %[[p1_i8]] to i32*
+// CHECK: %[[p1:[^ ]*]] = load i32, i32* %[[p1_ptr]]
+// CHECK: %[[this_2:[^ ]*]] = bitcast %struct.V* %[[this]] to void (%struct.V*, i32)***
+// CHECK: %[[vtable:[^ ]*]] = load void (%struct.V*, i32)**, void (%struct.V*, i32)*** %[[this_2]], align 8
+// CHECK: %[[vfn:[^ ]*]] = getelementptr inbounds void (%struct.V*, i32)*, void (%struct.V*, i32)** %[[vtable]], i64 0
+// CHECK: %[[virt:[^ ]*]] = load void (%struct.V*, i32)*, void (%struct.V*, i32)** %[[vfn]], align 8
+// CHECK: call void %[[virt]](%struct.V* {{[^,]*}} %[[this]], i32 %[[p1]])
 
 void test_lambda() {
   int l1 = 13;
@@ -62,21 +100,28 @@
 int l2 = 42;
 __try {
   might_crash();
-} __except(basic_filter(l2)) {
-  // FIXME: Test 'l1' when we can capture the lambda's 'this' decl.
+} __except(basic_filter(l1, l2)) {
 }
   };
   lambda();
 }
 
 // CHECK-LABEL: define internal void @"??R@?0??test_lambda@@YAXXZ@QEBA@XZ"(%class.anon* {{[^,]*}} %this)
-// CHECK: @llvm.localescape(i32* %[[l2_addr:[^, ]*]])
+// CHECK: @llvm.localescape(%class.anon** %[[this_addr:[^, ]*]], i32* %[[l2_addr:[^, ]*]])
+// CHECK: store %class.anon* %this, %class.anon** %[[this_addr]], align 8
 // CHECK: store i32 42, i32* %[[l2_addr]], align 4
 // CHECK: invoke void @might_crash()
 
 // CHECK-LABEL: define internal i32 @"?filt$0@0@?R@?0??test_lambda@@YAXXZ@"(i8* %exception_pointers, i8* %frame_pointer)
 // CHECK: %[[fp:

[PATCH] D97535: [clangd] Use URIs instead of paths in the index file list

2021-02-26 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
ArcsinX requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Without this patch the file list of the index is derived from the keys, but 
initial `FileSymbols` design was that the keys are arbitrary, so we can not 
assume that the keys are always paths/URIs (e.g. the preamble index uses URIs 
for the keys and other indexes use file paths).
This patch introduces the file list extraction from the index data, thus it 
makes `FileSymbols` usage more flexible (we do not need to think about the 
keys) and helps to avoid a lot of URI <=> path conversions, but from the other 
hand the index file list could be empty if there are no symbols/references 
(empty files seems to be a very rare case).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97535

Files:
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/MemIndex.cpp
  clang-tools-extra/clangd/index/dex/Dex.cpp
  clang-tools-extra/clangd/unittests/DexTests.cpp
  clang-tools-extra/clangd/unittests/IndexTests.cpp

Index: clang-tools-extra/clangd/unittests/IndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/clangd/unittests/IndexTests.cpp
@@ -229,7 +229,7 @@
   RefSlab Refs;
   auto Size = Symbols.bytes() + Refs.bytes();
   auto Data = std::make_pair(std::move(Symbols), std::move(Refs));
-  llvm::StringSet<> Files = {testPath("foo.cc"), testPath("bar.cc")};
+  llvm::StringSet<> Files = {"unittest:///foo.cc", "unittest:///bar.cc"};
   MemIndex I(std::move(Data.first), std::move(Data.second), RelationSlab(),
  std::move(Files), IndexContents::All, std::move(Data), Size);
   auto ContainsFile = I.indexedFiles();
@@ -339,21 +339,21 @@
   FileIndex DynamicIndex, StaticIndex;
   MergedIndex Merge(&DynamicIndex, &StaticIndex);
 
-  const char *HeaderCode = "class Foo;";
+  const char *HeaderCode = "class Foo; class Bar;";
   auto HeaderSymbols = TestTU::withHeaderCode(HeaderCode).headerSymbols();
   auto Foo = findSymbol(HeaderSymbols, "Foo");
 
-  // Build static index for test.cc with Foo symbol
+  // Build static index for test.cc with Foo and Bar symbols
   TestTU Test;
   Test.HeaderCode = HeaderCode;
-  Test.Code = "class Foo {};";
+  Test.Code = "class Foo {}; class Bar {};";
   Test.Filename = "test.cc";
   auto AST = Test.build();
   StaticIndex.updateMain(testPath(Test.Filename), AST);
 
-  // Remove Foo symbol, i.e. build dynamic index for test.cc, which is empty.
-  Test.HeaderCode = "";
-  Test.Code = "";
+  // Remove Foo symbol.
+  Test.HeaderCode = "class Bar;";
+  Test.Code = "class Bar {};";
   AST = Test.build();
   DynamicIndex.updateMain(testPath(Test.Filename), AST);
 
@@ -487,7 +487,7 @@
 
   // Remove all refs for test.cc from dynamic index,
   // merged index should not return results from static index for test.cc.
-  Test.Code = "";
+  Test.Code = "int I;"; // test.cc should not be empty
   AST = Test.build();
   Dyn.updateMain(testPath(Test.Filename), AST);
 
@@ -506,7 +506,7 @@
   RefSlab DynRefs;
   auto DynSize = DynSymbols.bytes() + DynRefs.bytes();
   auto DynData = std::make_pair(std::move(DynSymbols), std::move(DynRefs));
-  llvm::StringSet<> DynFiles = {testPath("foo.cc")};
+  llvm::StringSet<> DynFiles = {"unittest:///foo.cc"};
   MemIndex DynIndex(std::move(DynData.first), std::move(DynData.second),
 RelationSlab(), std::move(DynFiles), IndexContents::Symbols,
 std::move(DynData), DynSize);
@@ -514,7 +514,7 @@
   RefSlab StaticRefs;
   auto StaticData =
   std::make_pair(std::move(StaticSymbols), std::move(StaticRefs));
-  llvm::StringSet<> StaticFiles = {testPath("foo.cc"), testPath("bar.cc")};
+  llvm::StringSet<> StaticFiles = {"unittest:///foo.cc", "unittest:///bar.cc"};
   MemIndex StaticIndex(
   std::move(StaticData.first), std::move(StaticData.second), RelationSlab(),
   std::move(StaticFiles), IndexContents::References, std::move(StaticData),
Index: clang-tools-extra/clangd/unittests/DexTests.cpp
===
--- clang-tools-extra/clangd/unittests/DexTests.cpp
+++ clang-tools-extra/clangd/unittests/DexTests.cpp
@@ -737,7 +737,7 @@
   RefSlab Refs;
   auto Size = Symbols.bytes() + Refs.bytes();
   auto Data = std::make_pair(std::move(Symbols), std::move(Refs));
-  llvm::StringSet<> Files = {testPath("foo.cc"), testPath("bar.cc")};
+  llvm::StringSet<> Files = {"unittest:///foo.cc", "unittest:///bar.cc"};
   Dex I(std::move(Data.first), std::move(Data.second), RelationSlab(),
 std::move(Files), IndexContents::All, std::move(Data), Size);
   auto ContainsFile = I.indexedFiles();
Index: clang-tools-extra/clangd/index/dex/Dex.cpp
===

[PATCH] D97536: [clangd][remote] Add flag to set idletimeout

2021-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

By default gRPC has no idletimeout and some firewalls might drop idle
connections after a certain period. This results in idle clients
shouting into void until server resets the connection.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97536

Files:
  clang-tools-extra/clangd/index/remote/server/Server.cpp


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -80,6 +80,11 @@
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 
0.0.0.0:50051"));
 
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(10),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "
+   "the connection, in seconds. Defaults to 10."));
+
 static Key CurrentRequest;
 
 class RemoteIndexServer final : public v1::SymbolIndex::Service {
@@ -311,6 +316,8 @@
   grpc::ServerBuilder Builder;
   Builder.AddListeningPort(ServerAddress.str(),
grpc::InsecureServerCredentials());
+  Builder.AddChannelArgument(GRPC_ARG_MAX_CONNECTION_IDLE_MS,
+ IdleTimeoutSeconds * 1000);
   Builder.RegisterService(&Service);
   std::unique_ptr Server(Builder.BuildAndStart());
   log("Server listening on {0}", ServerAddress);


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -80,6 +80,11 @@
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 0.0.0.0:50051"));
 
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(10),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "
+   "the connection, in seconds. Defaults to 10."));
+
 static Key CurrentRequest;
 
 class RemoteIndexServer final : public v1::SymbolIndex::Service {
@@ -311,6 +316,8 @@
   grpc::ServerBuilder Builder;
   Builder.AddListeningPort(ServerAddress.str(),
grpc::InsecureServerCredentials());
+  Builder.AddChannelArgument(GRPC_ARG_MAX_CONNECTION_IDLE_MS,
+ IdleTimeoutSeconds * 1000);
   Builder.RegisterService(&Service);
   std::unique_ptr Server(Builder.BuildAndStart());
   log("Server listening on {0}", ServerAddress);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97535: [clangd] Use URIs instead of paths in the index file list

2021-02-26 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added reviewers: sammccall, kadircet, hokein.
ArcsinX added a comment.

Initial discussion D94952#inline-892421 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97535

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


[clang] d5e0868 - [Basic] Fix Wreturn-type gcc warning (NFC)

2021-02-26 Thread Yang Fan via cfe-commits

Author: Yang Fan
Date: 2021-02-26T17:14:13+08:00
New Revision: d5e0868e5e321e2a2f3bf73599ae9239c5aaa0c9

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

LOG: [Basic] Fix Wreturn-type gcc warning (NFC)

Added: 


Modified: 
clang/include/clang/Basic/Diagnostic.h

Removed: 




diff  --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index 8f94d271aaa4..3b915fb15a89 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -731,6 +731,7 @@ class DiagnosticsEngine : public 
RefCountedBase {
 case Ovl_Best:
   return NumOverloadsToShow;
 }
+llvm_unreachable("invalid OverloadsShown kind");
   }
 
   /// Call this after showing N overload candidates.  This influences the value



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


[PATCH] D97536: [clangd][remote] Add flag to set idletimeout

2021-02-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:84
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(10),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "

10 seems much too low, maybe set this to 5 min or so?
Going idle for a minute or so seems common, and the only real reason we have to 
time connections out is to beat the gcp firewall. So I don't see the need to be 
really aggressive here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97536

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


[clang] e9475a2 - [Sema] Fix MSVC "attribute is not recognized" warning (NFC)

2021-02-26 Thread Yang Fan via cfe-commits

Author: Yang Fan
Date: 2021-02-26T17:28:24+08:00
New Revision: e9475a276267f1bc74d9624fc797c7a754b5b90b

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

LOG: [Sema] Fix MSVC "attribute is not recognized" warning (NFC)

MSVC warning:
```
\llvm-project\clang\lib\Sema\SemaChecking.cpp(10323): warning C5030: attribute 
'clang::fallthrough' is not recognized
```

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f69bdf97aa8d..f67cba189344 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10320,7 +10320,7 @@ void CheckFreeArgumentsCast(Sema &S, const std::string 
&CalleeName,
   case clang::CK_BitCast:
 if (!Cast->getSubExpr()->getType()->isFunctionPointerType())
   return;
-[[clang::fallthrough]];
+LLVM_FALLTHROUGH;
   case clang::CK_IntegralToPointer:
   case clang::CK_FunctionToPointerDecay:
 OS << '\'';



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


[PATCH] D97536: [clangd][remote] Add flag to set idletimeout

2021-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 326632.
kadircet marked an inline comment as done.
kadircet added a comment.

Change 10 seconds to 600 seconds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97536

Files:
  clang-tools-extra/clangd/index/remote/server/Server.cpp


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -80,6 +80,11 @@
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 
0.0.0.0:50051"));
 
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(10 * 60),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "
+   "the connection, in seconds. Defaults to 600."));
+
 static Key CurrentRequest;
 
 class RemoteIndexServer final : public v1::SymbolIndex::Service {
@@ -311,6 +316,8 @@
   grpc::ServerBuilder Builder;
   Builder.AddListeningPort(ServerAddress.str(),
grpc::InsecureServerCredentials());
+  Builder.AddChannelArgument(GRPC_ARG_MAX_CONNECTION_IDLE_MS,
+ IdleTimeoutSeconds * 1000);
   Builder.RegisterService(&Service);
   std::unique_ptr Server(Builder.BuildAndStart());
   log("Server listening on {0}", ServerAddress);


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -80,6 +80,11 @@
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 0.0.0.0:50051"));
 
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(10 * 60),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "
+   "the connection, in seconds. Defaults to 600."));
+
 static Key CurrentRequest;
 
 class RemoteIndexServer final : public v1::SymbolIndex::Service {
@@ -311,6 +316,8 @@
   grpc::ServerBuilder Builder;
   Builder.AddListeningPort(ServerAddress.str(),
grpc::InsecureServerCredentials());
+  Builder.AddChannelArgument(GRPC_ARG_MAX_CONNECTION_IDLE_MS,
+ IdleTimeoutSeconds * 1000);
   Builder.RegisterService(&Service);
   std::unique_ptr Server(Builder.BuildAndStart());
   log("Server listening on {0}", ServerAddress);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97536: [clangd][remote] Add flag to set idletimeout

2021-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:84
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(10),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "

sammccall wrote:
> 10 seems much too low, maybe set this to 5 min or so?
> Going idle for a minute or so seems common, and the only real reason we have 
> to time connections out is to beat the gcp firewall. So I don't see the need 
> to be really aggressive here.
oops this was meant to be 10 minutes, not seconds :D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97536

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


[PATCH] D97196: [clang-tidy] Add new check 'bugprone-unhandled-exception-at-new'.

2021-02-26 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 326642.
balazske added a comment.

Rebase, fixes according to review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97196

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp
@@ -0,0 +1,143 @@
+// RUN: %check_clang_tidy -std=c++14 %s bugprone-unhandled-exception-at-new %t
+
+namespace std {
+typedef __typeof__(sizeof(0)) size_t;
+enum class align_val_t : std::size_t {};
+class exception {};
+class bad_alloc : public exception {};
+struct nothrow_t {};
+extern const nothrow_t nothrow;
+} // namespace std
+
+void *operator new(std::size_t, const std::nothrow_t &);
+void *operator new(std::size_t, std::align_val_t, const std::nothrow_t &);
+
+class A {};
+typedef std::bad_alloc badalloc1;
+using badalloc2 = std::bad_alloc;
+using badalloc3 = std::bad_alloc &;
+
+void f1() noexcept {
+  int *I1 = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: missing exception handler for allocation failure at 'new'
+  try {
+int *I2 = new int;
+try {
+  int *I3 = new int;
+} catch (A) {
+}
+  } catch (std::bad_alloc) {
+  }
+
+  try {
+int *I = new int;
+  } catch (std::bad_alloc &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const std::bad_alloc &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc1) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc1 &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const badalloc1 &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc2) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc3) {
+  }
+
+  try {
+int *I = new int;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: missing exception handler for allocation failure at 'new'
+  } catch (std::bad_alloc *) {
+  }
+
+  try {
+int *I = new int;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: missing exception handler for allocation failure at 'new'
+  } catch (A) {
+  }
+}
+
+void f2() noexcept {
+  try {
+int *I = new int;
+  } catch (A) {
+  } catch (std::bad_alloc) {
+  }
+
+  try {
+int *I = new int;
+  } catch (...) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const std::exception &) {
+  }
+}
+
+void f3() noexcept {
+  int *I1 = new (std::nothrow) int;
+  int *I2 = new (static_cast(1), std::nothrow) int;
+}
+
+void f_est_none() {
+  int *I = new int;
+}
+
+void f_est_noexcept_false() noexcept(false) {
+  int *I = new int;
+}
+
+void f_est_noexcept_true() noexcept(true) {
+  int *I = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: missing exception handler for allocation failure at 'new'
+}
+
+void f_est_dynamic_none() throw() {
+  int *I = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: missing exception handler for allocation failure at 'new'
+}
+
+void f_est_dynamic_1() throw(std::bad_alloc) {
+  int *I = new int;
+}
+
+void f_est_dynamic_2() throw(A) {
+  // the exception specification list is not checked
+  int *I = new int;
+}
+
+template 
+void f_est_noexcept_dependent_unused() noexcept(P) {
+  int *I = new int;
+}
+
+template 
+void f_est_noexcept_dependent_used() noexcept(P) {
+  int *I = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: missing exception handler for allocation failure at 'new'
+}
+
+void f_1() {
+  f_est_noexcept_dependent_used();
+}
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
@@ -99,6 +99,7 @@
`bugprone-too-small-loop-variable `_,
`bugprone-undefined-memory-manipulation `_,
`bugprone-undelegated-constructor `_,
+   `bugprone-unhandled-exception-at-new `_,
`bugprone-unhandled-self-assignment `_,
`bugprone-unused-raii `_, "Yes"
`bugprone-unused-return-value `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - bugprone-unhandled-exception-at-new
+
+bugprone

[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-02-26 Thread Zakk Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 326585.
khchen marked 10 inline comments as done.
khchen added a comment.

1. address Craig's comments.
2. use ListSeparator in some code snippet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/include/clang/Basic/CMakeLists.txt
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/test/CodeGen/RISCV/rvv-intrinsics-generic/vadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-generic/vfadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfadd.c
  clang/test/CodeGen/RISCV/vadd.c
  clang/test/Headers/riscv-vector-header.c
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/RISCVVEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h
  llvm/docs/CommandGuide/tblgen.rst

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


[clang] 04c3071 - [Driver] Flush file in locked area

2021-02-26 Thread Serge Pavlov via cfe-commits

Author: Serge Pavlov
Date: 2021-02-26T19:02:54+07:00
New Revision: 04c3071c16d799a4406c1742f239e8381c00b2b8

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

LOG: [Driver] Flush file in locked area

When writing report file by option -proc-stat-report some part of output
can be written to unlocked file because destructor of raw_fd_ostream
calls `flush()`. In high thread contention environment it can result in
file operation failure. With this change `flush` is called explicitly when
file is locked, so call of `flush()` in the destructor does not cause
write to file.

Added: 


Modified: 
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5aa0011d80ef..84bee2ae9d07 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4069,6 +4069,7 @@ void Driver::BuildJobs(Compilation &C) const {
   return;
 }
 OS << Buffer;
+OS.flush();
   }
 });
   }



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


[PATCH] D97388: [analyzer] Replace StoreManager::evalIntegralCast with SValBuilder::evalCast

2021-02-26 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 326651.
ASDenysPetrov added a comment.

A bit improved.


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

https://reviews.llvm.org/D97388

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp

Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -493,44 +493,6 @@
   return true;
 }
 
-// Handles casts of type CK_IntegralCast.
-// At the moment, this function will redirect to evalCast, except when the range
-// of the original value is known to be greater than the max of the target type.
-SVal SValBuilder::evalIntegralCast(ProgramStateRef state, SVal val,
-   QualType castTy, QualType originalTy) {
-  // No truncations if target type is big enough.
-  if (getContext().getTypeSize(castTy) >= getContext().getTypeSize(originalTy))
-return evalCast(state, val, castTy, originalTy);
-
-  SymbolRef se = val.getAsSymbol();
-  if (!se) // Let evalCast handle non symbolic expressions.
-return evalCast(state, val, castTy, originalTy);
-
-  // Find the maximum value of the target type.
-  APSIntType ToType(getContext().getTypeSize(castTy),
-castTy->isUnsignedIntegerType());
-  llvm::APSInt ToTypeMax = ToType.getMaxValue();
-  NonLoc ToTypeMaxVal =
-  makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue()
-: ToTypeMax.getSExtValue(),
- castTy)
-  .castAs();
-  // Check the range of the symbol being casted against the maximum value of the
-  // target type.
-  NonLoc FromVal = val.castAs();
-  QualType CmpTy = getConditionType();
-  NonLoc CompVal =
-  evalBinOpNN(state, BO_LE, FromVal, ToTypeMaxVal, CmpTy).castAs();
-  ProgramStateRef IsNotTruncated, IsTruncated;
-  std::tie(IsNotTruncated, IsTruncated) = state->assume(CompVal);
-  if (!IsNotTruncated && IsTruncated) {
-// Symbol is truncated so we evaluate it as a cast.
-NonLoc CastVal = makeNonLoc(se, originalTy, castTy);
-return CastVal;
-  }
-  return evalCast(state, val, castTy, originalTy);
-}
-
 //===--===//
 // Cast methods.
 // `evalCast` is the main method
@@ -915,6 +877,37 @@
   return makeNonLoc(SE, BO_NE, BVF.getValue(0, SE->getType()), CastTy);
 }
   } else {
+// Symbol to integer.
+if (!OriginalTy.isNull() && CastTy->isIntegralOrEnumerationType()) {
+  // Symbolic integer to integer.
+  if (OriginalTy->isIntegralOrEnumerationType()) {
+// Truncation.
+if (getContext().getTypeSize(CastTy) <
+getContext().getTypeSize(OriginalTy)) {
+  // Find the maximum value of the target type.
+  llvm::APSInt ToTypeMax =
+  llvm::APSInt::getMaxValue(getContext().getTypeSize(CastTy),
+CastTy->isUnsignedIntegerType());
+  NonLoc ToTypeMaxVal =
+  makeIntVal(ToTypeMax.getExtValue(), CastTy).castAs();
+  // Check the range of the symbol being casted against the maximum
+  // value of the target type.
+  NonLoc FromVal = V.castAs();
+  QualType CmpTy = getConditionType();
+  NonLoc CompVal =
+  evalBinOpNN(State, BO_LE, FromVal, ToTypeMaxVal, CmpTy)
+  .castAs();
+  ProgramStateRef IsNotTruncated, IsTruncated;
+  std::tie(IsNotTruncated, IsTruncated) = State->assume(CompVal);
+  if (!IsNotTruncated && IsTruncated) {
+// Symbol is truncated so we evaluate it as a cast.
+NonLoc CastVal = makeNonLoc(SE, OriginalTy, CastTy);
+return CastVal;
+  }
+}
+  }
+}
+
 // Symbol to integer, float.
 QualType T = Context.getCanonicalType(SE->getType());
 // If types are the same or both are integers, ignore the cast.
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -431,7 +431,7 @@
   case CK_IntegralCast: {
 // Delegate to SValBuilder to process.
 SVal V = state->getSVal(Ex, LCtx);
-V = svalBuilder.evalIntegralCast(state, V, T, ExTy);
+V = svalBuilder.evalCast(state, V, T, ExTy);
 state = state->BindExpr(CastE, LCtx, V);
 Bldr.generateNode(CastE, Pred, state);
 continue;
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ clang/include/c

[clang] 8dc70bd - [clang][cli] Fix build failure in CompilerInvocation

2021-02-26 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-02-26T13:14:23+01:00
New Revision: 8dc70bdcd0fe4efb65876dce0144d9c3386a2f07

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

LOG: [clang][cli] Fix build failure in CompilerInvocation

There is a report that https://reviews.llvm.org/D96280 causes a build failure 
with error: too few template arguments for class template 'SmallVector'. This 
patch attempts to fix that by explicitly specifying N for SmallVector.

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 4d4b942995d7..dac64183306a 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -663,7 +663,7 @@ static bool RoundTrip(ParseFn Parse, GenerateFn Generate,
   // Generate arguments from the dummy invocation. If Generate is the
   // inverse of Parse, the newly generated arguments must have the same
   // semantics as the original.
-  SmallVector GeneratedArgs1;
+  SmallVector GeneratedArgs1;
   Generate(DummyInvocation, GeneratedArgs1, SA);
 
   // Run the second parse, now on the generated arguments, and with the real
@@ -683,7 +683,7 @@ static bool RoundTrip(ParseFn Parse, GenerateFn Generate,
 
   // Generate arguments again, this time from the options we will end up using
   // for the rest of the compilation.
-  SmallVector GeneratedArgs2;
+  SmallVector GeneratedArgs2;
   Generate(RealInvocation, GeneratedArgs2, SA);
 
   // Compares two lists of generated arguments.



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


[PATCH] D97536: [clangd][remote] Add flag to set idletimeout

2021-02-26 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:84
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(10),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "

kadircet wrote:
> sammccall wrote:
> > 10 seems much too low, maybe set this to 5 min or so?
> > Going idle for a minute or so seems common, and the only real reason we 
> > have to time connections out is to beat the gcp firewall. So I don't see 
> > the need to be really aggressive here.
> oops this was meant to be 10 minutes, not seconds :D
Haha, makes more sense :-)

Setting this to exactly the gcp timeout seems tempting fate with hard to debug 
races. Maybe 8 min?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97536

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


[PATCH] D96280: [clang][cli] Round-trip the whole CompilerInvocation

2021-02-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:666
+  // semantics as the original.
+  SmallVector GeneratedArgs1;
+  Generate(DummyInvocation, GeneratedArgs1, SA);

scui wrote:
> This is failing our build, This line and line 686. The msg is:
> 
> llvm-project/clang/lib/Frontend/CompilerInvocation.cpp:666:3: error: too few 
> template arguments for class template 'SmallVector'
>   SmallVector GeneratedArgs1;
>   ^
> llvm-project/clang/include/clang/Basic/LLVM.h:35:42: note: template is 
> declared here
>   template class SmallVector;
>      ^
> llvm-project/clang/lib/Frontend/CompilerInvocation.cpp:686:3: error: too few 
> template arguments for class template 'SmallVector'
>   SmallVector GeneratedArgs2;
>   ^
> llvm-project/clang/include/clang/Basic/LLVM.h:35:42: note: template is 
> declared here
>   template class SmallVector;
>      ^
> 2 errors generated.
> 
That's interesting, the definition of `SmallVector` defaults `N` to a sensible 
number. Out of interest: what compiler are you using?

Should be fixed in 8dc70bdcd0fe4efb65876dce0144d9c3386a2f07.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96280

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


[clang] cb81135 - [clang][cli] Implement '-cuid=' marshalling

2021-02-26 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2021-02-26T13:17:51+01:00
New Revision: cb81135f94e58ce0a0e91d764841acee90eeb59f

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

LOG: [clang][cli] Implement '-cuid=' marshalling

This patch adds marshalling to the `-cuid=` option introduced in D95007.

Reviewed By: Bigcheese

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ec0e84fbd771..c34c371197c3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -934,7 +934,8 @@ def cuid_EQ : Joined<["-"], "cuid=">, Flags<[CC1Option]>,
"compilation unit but 
diff erent for 
diff erent compilation units. "
"It is used to externalize device-side static variables for single "
"source offloading languages CUDA and HIP so that they can be "
-   "accessed by the host code of the same compilation unit.">;
+   "accessed by the host code of the same compilation unit.">,
+  MarshallingInfoString>;
 def fuse_cuid_EQ : Joined<["-"], "fuse-cuid=">,
   HelpText<"Method to generate ID's for compilation units for single source "
"offloading languages CUDA and HIP: 'hash' (ID's generated by 
hashing "

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index dac64183306a..a3b4855ab54f 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3585,11 +3585,6 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
 }
   }
 
-
-  if (auto *A = Args.getLastArg(OPT_cuid_EQ)) {
-Opts.CUID = std::string(A->getValue());
-  }
-
   if (Opts.ObjC) {
 if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
   StringRef value = arg->getValue();



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


[PATCH] D97461: [clang][cli] Implement '-cuid=' marshalling

2021-02-26 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcb81135f94e5: [clang][cli] Implement '-cuid=' 
marshalling (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97461

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3585,11 +3585,6 @@
 }
   }
 
-
-  if (auto *A = Args.getLastArg(OPT_cuid_EQ)) {
-Opts.CUID = std::string(A->getValue());
-  }
-
   if (Opts.ObjC) {
 if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
   StringRef value = arg->getValue();
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -934,7 +934,8 @@
"compilation unit but different for different compilation units. "
"It is used to externalize device-side static variables for single "
"source offloading languages CUDA and HIP so that they can be "
-   "accessed by the host code of the same compilation unit.">;
+   "accessed by the host code of the same compilation unit.">,
+  MarshallingInfoString>;
 def fuse_cuid_EQ : Joined<["-"], "fuse-cuid=">,
   HelpText<"Method to generate ID's for compilation units for single source "
"offloading languages CUDA and HIP: 'hash' (ID's generated by 
hashing "


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3585,11 +3585,6 @@
 }
   }
 
-
-  if (auto *A = Args.getLastArg(OPT_cuid_EQ)) {
-Opts.CUID = std::string(A->getValue());
-  }
-
   if (Opts.ObjC) {
 if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
   StringRef value = arg->getValue();
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -934,7 +934,8 @@
"compilation unit but different for different compilation units. "
"It is used to externalize device-side static variables for single "
"source offloading languages CUDA and HIP so that they can be "
-   "accessed by the host code of the same compilation unit.">;
+   "accessed by the host code of the same compilation unit.">,
+  MarshallingInfoString>;
 def fuse_cuid_EQ : Joined<["-"], "fuse-cuid=">,
   HelpText<"Method to generate ID's for compilation units for single source "
"offloading languages CUDA and HIP: 'hash' (ID's generated by hashing "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96976: [analyzer] Fix reinterpret_cast handling for pointer-to-member

2021-02-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D96976#2587513 , @RedDocMD wrote:

> Many thanks for you comments, @steakhal!
> I will address the issues you have pointed out in this comment. To clean 
> things up I should perhaps add some more clarification to the summary.
>
>> Could you elaborate on what approach did you choose and more importantly, 
>> why that approach?
>> Why do we need a graph search here?
>
> Pointer-to-members contain two things - a pointer to a NamedDecl to store the 
> field/method being pointed to and a list of CXXBaseSpeciifier. This list is 
> used to determine which sub-object the member lies in. This path needs to be 
> determined and unfortunately with `reinterpret_cast`, the AST provides no 
> structural assistance (unlike `static_cast`). Hence, it needs to be searched 
> by searching through the BaseSpecifiers of the `CXXRecordDecl`.

So here you are implying that for reinterpret casts, the 
`CastE->path_begin()-end()` range is empty? And that is why you need to 
manually come up with a //possible// CXXBaseSpecifier list?

I strongly encourage you to find a better alternative to this manual graph 
search.
This information must be available somewhere.

Have you looked at `CXXRecordDecl::isDerivedFrom()`? Or any other member 
functions of that class?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96976

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


[PATCH] D97534: SEH: capture 'this'

2021-02-26 Thread Olivier Goffart via Phabricator via cfe-commits
ogoffart updated this revision to Diff 326656.
ogoffart added a comment.

(git-clang-format)


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

https://reviews.llvm.org/D97534

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp

Index: clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
===
--- clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
+++ clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
@@ -39,13 +39,13 @@
   int l1 = 13;
   __try {
 might_crash();
-  } __except(basic_filter(l1)) {
-// FIXME: Test capturing 'this' and 'm1'.
+  } __except (basic_filter(l1, m1)) {
   }
 }
 
 // CHECK-LABEL: define dso_local void @"?test_method@S@@QEAAXXZ"(%struct.S* {{[^,]*}} %this)
-// CHECK: @llvm.localescape(i32* %[[l1_addr:[^, ]*]])
+// CHECK: @llvm.localescape(i32* %[[l1_addr:[^, ]*]], %struct.S** %[[this_addr:[^, ]*]])
+// CHECK: store %struct.S* %this, %struct.S** %[[this_addr]], align 8
 // CHECK: store i32 13, i32* %[[l1_addr]], align 4
 // CHECK: invoke void @might_crash()
 
@@ -53,8 +53,45 @@
 // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.eh.recoverfp(i8* bitcast (void (%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %frame_pointer)
 // CHECK: %[[l1_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %[[fp]], i32 0)
 // CHECK: %[[l1_ptr:[^ ]*]] = bitcast i8* %[[l1_i8]] to i32*
+// CHECK: %[[this_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %[[fp]], i32 1)
+// CHECK: %[[this_ptr:[^ ]*]] = bitcast i8* %[[this_i8]] to %struct.S**
+// CHECK: %[[this:[^ ]*]] = load %struct.S*, %struct.S** %[[this_ptr]], align 8
+// CHECK: %[[m1_ptr:[^ ]*]] = getelementptr inbounds %struct.S, %struct.S* %[[this]], i32 0, i32 0
+// CHECK: %[[m1:[^ ]*]] = load i32, i32* %[[m1_ptr]]
 // CHECK: %[[l1:[^ ]*]] = load i32, i32* %[[l1_ptr]]
-// CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l1]])
+// CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l1]], i32 %[[m1]])
+
+struct V {
+  void test_virtual(int p1);
+  virtual void virt(int p1);
+};
+
+void V::test_virtual(int p1) {
+  __try {
+might_crash();
+  } __finally {
+virt(p1);
+  }
+}
+
+// CHECK-LABEL: define dso_local void @"?test_virtual@V@@QEAAXH@Z"(%struct.V* {{[^,]*}} %this, i32 %p1)
+// CHECK: @llvm.localescape(%struct.V** %[[this_addr:[^, ]*]], i32* %[[p1_addr:[^, ]*]])
+// CHECK: store i32 %p1, i32* %[[p1_addr]], align 4
+// CHECK: store %struct.V* %this, %struct.V** %[[this_addr]], align 8
+// CHECK: invoke void @might_crash()
+
+// CHECK-LABEL: define internal void @"?fin$0@0@test_virtual@V@@"(i8 %abnormal_termination, i8* %frame_pointer)
+// CHECK: %[[this_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.V*, i32)* @"?test_virtual@V@@QEAAXH@Z" to i8*), i8* %frame_pointer, i32 0)
+// CHECK: %[[this_ptr:[^ ]*]] = bitcast i8* %[[this_i8]] to %struct.V**
+// CHECK: %[[this:[^ ]*]] = load %struct.V*, %struct.V** %[[this_ptr]], align 8
+// CHECK: %[[p1_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.V*, i32)* @"?test_virtual@V@@QEAAXH@Z" to i8*), i8* %frame_pointer, i32 1)
+// CHECK: %[[p1_ptr:[^ ]*]] = bitcast i8* %[[p1_i8]] to i32*
+// CHECK: %[[p1:[^ ]*]] = load i32, i32* %[[p1_ptr]]
+// CHECK: %[[this_2:[^ ]*]] = bitcast %struct.V* %[[this]] to void (%struct.V*, i32)***
+// CHECK: %[[vtable:[^ ]*]] = load void (%struct.V*, i32)**, void (%struct.V*, i32)*** %[[this_2]], align 8
+// CHECK: %[[vfn:[^ ]*]] = getelementptr inbounds void (%struct.V*, i32)*, void (%struct.V*, i32)** %[[vtable]], i64 0
+// CHECK: %[[virt:[^ ]*]] = load void (%struct.V*, i32)*, void (%struct.V*, i32)** %[[vfn]], align 8
+// CHECK: call void %[[virt]](%struct.V* {{[^,]*}} %[[this]], i32 %[[p1]])
 
 void test_lambda() {
   int l1 = 13;
@@ -62,21 +99,27 @@
 int l2 = 42;
 __try {
   might_crash();
-} __except(basic_filter(l2)) {
-  // FIXME: Test 'l1' when we can capture the lambda's 'this' decl.
+} __except (basic_filter(l1, l2)) {
 }
   };
   lambda();
 }
 
 // CHECK-LABEL: define internal void @"??R@?0??test_lambda@@YAXXZ@QEBA@XZ"(%class.anon* {{[^,]*}} %this)
-// CHECK: @llvm.localescape(i32* %[[l2_addr:[^, ]*]])
+// CHECK: @llvm.localescape(%class.anon** %[[this_addr:[^, ]*]], i32* %[[l2_addr:[^, ]*]])
+// CHECK: store %class.anon* %this, %class.anon** %[[this_addr]], align 8
 // CHECK: store i32 42, i32* %[[l2_addr]], align 4
 // CHECK: invoke void @might_crash()
 
 // CHECK-LABEL: define internal i32 @"?filt$0@0@?R@?0??test_lambda@@YAXXZ@"(i8* %exception_pointers, i8* %frame_pointer)
 // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.eh.recoverfp(i8* bitcast (void (%class.anon*)* @"??R@?0??test_lambda@@YAXXZ@QEBA@XZ" to i8*), i8* %frame_pointer)
-// CHECK: %[[l2_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%class.anon*)* @"??R@?0??t

[PATCH] D97544: [clang-tidy] Remove some test c++ mode restrictions.

2021-02-26 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh.
Herald added subscribers: kbarton, xazax.hun, nemanjai.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Some comments are redundant, others just simple fixes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97544

Files:
  
clang-tools-extra/test/clang-tidy/checkers/abseil-faster-strsplit-delimiter.cpp
  clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
  clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
  clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
@@ -2,7 +2,10 @@
 // RUN:  -config='{CheckOptions: [ \
 // RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64
-// FIXME: Fix the checker to work in C++20 mode.
+// RUN: %check_clang_tidy -std=c++20-or-later %s portability-simd-intrinsics 
-check-suffix=CXX20 %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target x86_64
 
 typedef long long __m128i __attribute__((vector_size(16)));
 typedef double __m256 __attribute__((vector_size(32)));
@@ -18,7 +21,8 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by 
operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced 
by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+  // CHECK-MESSAGES-CXX20: :[[@LINE-2]]:3: warning: '_mm_add_epi32' can be 
replaced by operator+ on std::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
@@ -2,7 +2,10 @@
 // RUN:  -config='{CheckOptions: [ \
 // RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec
-// FIXME: Fix the checker to work in C++20 mode.
+// RUN: %check_clang_tidy -std=c++20-or-later %s portability-simd-intrinsics 
-check-suffix=CXX20 %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec
 
 vector int vec_add(vector int, vector int);
 
@@ -10,5 +13,6 @@
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by 
operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by 
operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+  // CHECK-MESSAGES-CXX20: :[[@LINE-2]]:3: warning: 'vec_add' can be replaced 
by operator+ on std::simd objects [portability-simd-intrinsics]
 }
Index: clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
@@ -1,5 +1,4 @@
 // RUN: %check_clang_tidy -std=c++11-or-later %s google-readability-casting %t
-// FIXME: Fix the checker to work in C++17 mode.
 
 bool g() { return false; }
 
Index: 
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
@@ -1,5 +1,4 @@
 // RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
-// FIXME: Fix the checker to work in C++17 mode.
 
 using int64_t = long long;
 
Index: clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-time-

[PATCH] D97388: [analyzer] Replace StoreManager::evalIntegralCast with SValBuilder::evalCast

2021-02-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Please make sure that you specify the parent revision or the patch can be 
applied on top of the tree.
Your lines clearly not match the top of the tree state.
https://github.com/llvm/llvm-project/blob/13f4448ae7db1a477ec2d48776e46415a3401314/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h#L129-L131

I really want to help you by finding regressions and stuff. But these mistakes 
hinder me a lot in applying your patches.


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

https://reviews.llvm.org/D97388

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


[PATCH] D97510: [AArch64][Docs] Release notes 12.x on outline atomics

2021-02-26 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover accepted this revision.
t.p.northover added a comment.
This revision is now accepted and ready to land.

I think this is fine.




Comment at: clang/docs/ReleaseNotes.rst:82
+  if compilation target supports LSE. Atomic instructions are used directly in
+  that case. The options behaviour mirrors GCC, the helpers are implemented
+  both in compiler-rt and libgcc.

Feel free to ignore since they're so minor, but if you're looking for more 
typos to fix:

  * The comma after "do not apply" is unnecessary.
  * "the compilation target" would be a bit more natural.
  * Missing apostrophe in "option's behaviour".

No need to reupload to Phab as far as I'm concerned either way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97510

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


[PATCH] D97094: [Driver] Print process statistics report on CC_PRINT_PROC_STAT env variable.

2021-02-26 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea accepted this revision.
aganea added a comment.
This revision is now accepted and ready to land.

LGTM, just a few minor things:




Comment at: clang/docs/UsersManual.rst:798
+  Setting ``CC_PRINT_PROC_STAT`` to ``1`` enables the feature, the report goes 
to
+  the stdout in the human readable format.
+  Setting ``CC_PRINT_PROC_STAT_FILE`` to a fully qualified file path makes it 
report

"enables the feature, the report goes to ~~the~~ stdout in ~~the~~ human 
readable format."



Comment at: clang/docs/UsersManual.rst:800
+  Setting ``CC_PRINT_PROC_STAT_FILE`` to a fully qualified file path makes it 
report
+  the process statistics to the given file in the CSV format. Specifying a 
relative
+  path will likely lead to multiple files with the same name created in 
different

"~~the~~ process statistics to the given file in the CSV format"



Comment at: clang/docs/UsersManual.rst:804
+
+  These environment variables are handy when you need to request the statistics
+  report without changing your build scripts or alter the existing set of 
compiler

Would you be able to merge this paragraph with the following one please? It 
could be something like:

"These environment variables are handy when you need to request the statistics 
report without changing your build scripts or alter the existing set of 
compiler options. Note that `-fproc-stat-report` take precedence over 
`CC_PRINT_PROC_STAT` and `CC_PRINT_PROC_STAT_FILE`."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97094

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


[PATCH] D97548: [clangd] Introduce client state invalidation

2021-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Clangd can invalidate client state of features like semantic higlighting
without client explicitly triggering, for example after a preamble build
caused by an onSave notification on a different file.

This patch introduces a mechanism to let client know of such actions,
and also calls the workspace/semanticTokens/refresh request to
demonstrate the situation after each preamble build.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97548

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/test/semantic-tokens-refresh.test

Index: clang-tools-extra/clangd/test/semantic-tokens-refresh.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/semantic-tokens-refresh.test
@@ -0,0 +1,42 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"capabilities":{
+  "workspace":{"semanticTokens":{"refreshSupport":true}}
+}}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{
+  "uri": "test:///foo.cpp",
+  "languageId": "cpp",
+  "text": "int x = 2;"
+}}}
+# Expect a request after initial preamble build.
+# CHECK:"method": "workspace/semanticTokens/refresh",
+# CHECK-NEXT:   "params": null
+# CHECK-NEXT:  }
+---
+# Reply with success.
+{"jsonrpc":"2.0","id":0}
+---
+# Preamble stays the same, no refresh requests.
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{
+  "textDocument": {"uri":"test:///foo.cpp","version":2},
+  "contentChanges":[{"text":"int x = 2;\nint y = 3;"}]
+}}
+# CHECK-NOT:  "method": "workspace/semanticTokens/refresh"
+---
+# Preamble changes
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{
+  "textDocument": {"uri":"test:///foo.cpp","version":2},
+  "contentChanges":[{"text":"#define FOO"}]
+}}
+# Expect a request after initial preamble build.
+# CHECK:"method": "workspace/semanticTokens/refresh",
+# CHECK-NEXT:   "params": null
+# CHECK-NEXT:  }
+---
+# Reply with error, to make sure there are no crashes.
+{"jsonrpc":"2.0","id":1,"error":{"code": 0, "message": "msg"}}
+---
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
+
Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -261,6 +261,7 @@
 bool fromJSON(const llvm::json::Value &E, TraceLevel &Out, llvm::json::Path);
 
 struct NoParams {};
+inline llvm::json::Value toJSON(const NoParams &) { return nullptr; }
 inline bool fromJSON(const llvm::json::Value &, NoParams &, llvm::json::Path) {
   return true;
 }
@@ -473,6 +474,10 @@
   /// This is a clangd extension.
   /// window.implicitWorkDoneProgressCreate
   bool ImplicitProgressCreation = false;
+
+  /// Whether the client implementation supports a refresh request sent from the
+  /// server to the client.
+  bool SemanticTokenRefreshSupport = false;
 };
 bool fromJSON(const llvm::json::Value &, ClientCapabilities &,
   llvm::json::Path);
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -403,6 +403,10 @@
 }
   }
 }
+if (auto *SemanticTokens = Workspace->getObject("semanticTokens")) {
+  if (auto RefreshSupport = SemanticTokens->getBoolean("refreshSupport"))
+R.SemanticTokenRefreshSupport = *RefreshSupport;
+}
   }
   if (auto *Window = O->getObject("window")) {
 if (auto WorkDoneProgress = Window->getBoolean("workDoneProgress"))
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -27,6 +27,7 @@
 #include "support/Cancellation.h"
 #include "support/Function.h"
 #include "support/MemoryTree.h"
+#include "support/Path.h"
 #include "support/ThreadsafeFS.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Replacement.h"
@@ -73,6 +74,12 @@
 /// Not called concurrently.
 virtual void
 onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats) {}
+
+/// Called when server triggers a state change without client requesting it.
+/// For example a preamble build, which might happen on its own,
+/// invalidating informa

[PATCH] D97548: [clangd] Introduce client state invalidation

2021-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/test/semantic-tokens-refresh.test:13
+# CHECK:"method": "workspace/semanticTokens/refresh",
+# CHECK-NEXT:   "params": null
+# CHECK-NEXT:  }

lsp spec says `params: none` for this request. i am not sure if this is 
acceptable or if we should really change our transport layer to accommodate 
optional parameters. can't really test it on vscode atm unfortunately :/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97548

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


[PATCH] D96586: [analyzer][CTU][NFC] Add an extra regression test

2021-02-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96586

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


[PATCH] D97536: [clangd][remote] Add flag to set idletimeout

2021-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 326667.
kadircet marked an inline comment as done.
kadircet added a comment.

- change default from 10 to 8 minutes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97536

Files:
  clang-tools-extra/clangd/index/remote/server/Server.cpp


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -80,6 +80,11 @@
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 
0.0.0.0:50051"));
 
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(8 * 60),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "
+   "the connection, in seconds. Defaults to 480."));
+
 static Key CurrentRequest;
 
 class RemoteIndexServer final : public v1::SymbolIndex::Service {
@@ -311,6 +316,8 @@
   grpc::ServerBuilder Builder;
   Builder.AddListeningPort(ServerAddress.str(),
grpc::InsecureServerCredentials());
+  Builder.AddChannelArgument(GRPC_ARG_MAX_CONNECTION_IDLE_MS,
+ IdleTimeoutSeconds * 1000);
   Builder.RegisterService(&Service);
   std::unique_ptr Server(Builder.BuildAndStart());
   log("Server listening on {0}", ServerAddress);


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -80,6 +80,11 @@
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 0.0.0.0:50051"));
 
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(8 * 60),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "
+   "the connection, in seconds. Defaults to 480."));
+
 static Key CurrentRequest;
 
 class RemoteIndexServer final : public v1::SymbolIndex::Service {
@@ -311,6 +316,8 @@
   grpc::ServerBuilder Builder;
   Builder.AddListeningPort(ServerAddress.str(),
grpc::InsecureServerCredentials());
+  Builder.AddChannelArgument(GRPC_ARG_MAX_CONNECTION_IDLE_MS,
+ IdleTimeoutSeconds * 1000);
   Builder.RegisterService(&Service);
   std::unique_ptr Server(Builder.BuildAndStart());
   log("Server listening on {0}", ServerAddress);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96280: [clang][cli] Round-trip the whole CompilerInvocation

2021-02-26 Thread Shimin Cui via Phabricator via cfe-commits
scui added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:666
+  // semantics as the original.
+  SmallVector GeneratedArgs1;
+  Generate(DummyInvocation, GeneratedArgs1, SA);

jansvoboda11 wrote:
> scui wrote:
> > This is failing our build, This line and line 686. The msg is:
> > 
> > llvm-project/clang/lib/Frontend/CompilerInvocation.cpp:666:3: error: too 
> > few template arguments for class template 'SmallVector'
> >   SmallVector GeneratedArgs1;
> >   ^
> > llvm-project/clang/include/clang/Basic/LLVM.h:35:42: note: template is 
> > declared here
> >   template class SmallVector;
> >      ^
> > llvm-project/clang/lib/Frontend/CompilerInvocation.cpp:686:3: error: too 
> > few template arguments for class template 'SmallVector'
> >   SmallVector GeneratedArgs2;
> >   ^
> > llvm-project/clang/include/clang/Basic/LLVM.h:35:42: note: template is 
> > declared here
> >   template class SmallVector;
> >      ^
> > 2 errors generated.
> > 
> That's interesting, the definition of `SmallVector` defaults `N` to a 
> sensible number. Out of interest: what compiler are you using?
> 
> Should be fixed in 8dc70bdcd0fe4efb65876dce0144d9c3386a2f07.
Thanks for the quick fix. We are using the IBM XL compilers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96280

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


[clang-tools-extra] 1a5dfb7 - [clangd][remote] Add flag to set idletimeout

2021-02-26 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-02-26T15:04:44+01:00
New Revision: 1a5dfb7db23e3c0aec0b4356a60b9d6b7c8f9683

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

LOG: [clangd][remote] Add flag to set idletimeout

By default gRPC has no idletimeout and some firewalls might drop idle
connections after a certain period. This results in idle clients
shouting into void until server resets the connection.

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

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/server/Server.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp 
b/clang-tools-extra/clangd/index/remote/server/Server.cpp
index 20b140e00787..3de2c38f7c08 100644
--- a/clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -80,6 +80,11 @@ llvm::cl::opt ServerAddress(
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 
0.0.0.0:50051"));
 
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(8 * 60),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "
+   "the connection, in seconds. Defaults to 480."));
+
 static Key CurrentRequest;
 
 class RemoteIndexServer final : public v1::SymbolIndex::Service {
@@ -311,6 +316,8 @@ void runServerAndWait(clangd::SymbolIndex &Index, 
llvm::StringRef ServerAddress,
   grpc::ServerBuilder Builder;
   Builder.AddListeningPort(ServerAddress.str(),
grpc::InsecureServerCredentials());
+  Builder.AddChannelArgument(GRPC_ARG_MAX_CONNECTION_IDLE_MS,
+ IdleTimeoutSeconds * 1000);
   Builder.RegisterService(&Service);
   std::unique_ptr Server(Builder.BuildAndStart());
   log("Server listening on {0}", ServerAddress);



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


[PATCH] D97536: [clangd][remote] Add flag to set idletimeout

2021-02-26 Thread Kadir Cetinkaya 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 rG1a5dfb7db23e: [clangd][remote] Add flag to set idletimeout 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97536

Files:
  clang-tools-extra/clangd/index/remote/server/Server.cpp


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -80,6 +80,11 @@
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 
0.0.0.0:50051"));
 
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(8 * 60),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "
+   "the connection, in seconds. Defaults to 480."));
+
 static Key CurrentRequest;
 
 class RemoteIndexServer final : public v1::SymbolIndex::Service {
@@ -311,6 +316,8 @@
   grpc::ServerBuilder Builder;
   Builder.AddListeningPort(ServerAddress.str(),
grpc::InsecureServerCredentials());
+  Builder.AddChannelArgument(GRPC_ARG_MAX_CONNECTION_IDLE_MS,
+ IdleTimeoutSeconds * 1000);
   Builder.RegisterService(&Service);
   std::unique_ptr Server(Builder.BuildAndStart());
   log("Server listening on {0}", ServerAddress);


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -80,6 +80,11 @@
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 0.0.0.0:50051"));
 
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(8 * 60),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "
+   "the connection, in seconds. Defaults to 480."));
+
 static Key CurrentRequest;
 
 class RemoteIndexServer final : public v1::SymbolIndex::Service {
@@ -311,6 +316,8 @@
   grpc::ServerBuilder Builder;
   Builder.AddListeningPort(ServerAddress.str(),
grpc::InsecureServerCredentials());
+  Builder.AddChannelArgument(GRPC_ARG_MAX_CONNECTION_IDLE_MS,
+ IdleTimeoutSeconds * 1000);
   Builder.RegisterService(&Service);
   std::unique_ptr Server(Builder.BuildAndStart());
   log("Server listening on {0}", ServerAddress);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97536: [clangd][remote] Add flag to set idletimeout

2021-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:84
+llvm::cl::opt IdleTimeoutSeconds(
+"idle-timeout", llvm::cl::init(10),
+llvm::cl::desc("Maximum time a channel may stay idle until server closes "

sammccall wrote:
> kadircet wrote:
> > sammccall wrote:
> > > 10 seems much too low, maybe set this to 5 min or so?
> > > Going idle for a minute or so seems common, and the only real reason we 
> > > have to time connections out is to beat the gcp firewall. So I don't see 
> > > the need to be really aggressive here.
> > oops this was meant to be 10 minutes, not seconds :D
> Haha, makes more sense :-)
> 
> Setting this to exactly the gcp timeout seems tempting fate with hard to 
> debug races. Maybe 8 min?
fair point, done!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97536

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


[PATCH] D97552: [clang][cli] Fix generation of '-fvisibility' with regards to '-mignore-xcoff-visibility'

2021-02-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, DiggerLin.
Herald added a subscriber: dang.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch fixes failure of the `CodeGen/aix-ignore-xcoff-visibility.cpp` test 
with command line round-trip.

The absence of '-fvisibility' implies '-mignore-xcoff-visibility'.

The problem was that '-fvisibility default' passed to -cc1 wasn't being 
generated. (This adheres to the principle that generation doesn't produce 
arguments with default values.)

However, that caused '-mignore-xcoff-visibility' to be implied in the generated 
command line (without '-fvisibility'), while it wasn't implied in the original 
command line (with '-fvisibility').

This patch fixes that by always generating '-fvisibility' and explains the 
situation in comment.

(The '-mginore-xcoff-visibility' option was added in D87451 
).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97552

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1838,6 +1838,23 @@
 }
   }
 
+  // This is the reason why '-fvisibility' needs to be always generated:
+  // its absence implies '-mignore-xcoff-visibility'.
+  //
+  // Suppose the original cc1 command line does contain '-fvisibility default':
+  // '-mignore-xcoff-visibility' should not be implied.
+  // * If '-fvisibility' is not generated (as most options with default values
+  //   don't), its absence would imply '-mignore-xcoff-visibility'. This 
changes
+  //   the command line semantics.
+  // * If '-fvisibility' is generated regardless of its presence and value,
+  //   '-mignore-xcoff-visibility' won't be implied and the command line
+  //   semantics are kept intact.
+  //
+  // When the original cc1 command line does **not** contain '-fvisibility',
+  // '-mignore-xcoff-visibility' is implied. The generated command line will
+  // contain both '-fvisibility default' and '-mignore-xcoff-visibility' and
+  // subsequent calls to `CreateFromArgs`/`generateCC1CommandLine` will always
+  // produce the same arguments.
   if (T.isOSAIX() && (Args.hasArg(OPT_mignore_xcoff_visibility) ||
   !Args.hasArg(OPT_fvisibility)))
 Opts.IgnoreXCOFFVisibility = 1;
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5302,7 +5302,9 @@
   MarshallingInfoStringInt, "8">;
 def fvisibility : Separate<["-"], "fvisibility">,
   HelpText<"Default type and symbol visibility">,
-  MarshallingInfoVisibility, 
"DefaultVisibility">;
+  MarshallingInfoVisibility, 
"DefaultVisibility">,
+  // Always emitting because of the relation to `-mignore-xcoff-visibility`.
+  AlwaysEmit;
 def ftype_visibility : Separate<["-"], "ftype-visibility">,
   HelpText<"Default type visibility">,
   MarshallingInfoVisibility, 
fvisibility.KeyPath>;


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1838,6 +1838,23 @@
 }
   }
 
+  // This is the reason why '-fvisibility' needs to be always generated:
+  // its absence implies '-mignore-xcoff-visibility'.
+  //
+  // Suppose the original cc1 command line does contain '-fvisibility default':
+  // '-mignore-xcoff-visibility' should not be implied.
+  // * If '-fvisibility' is not generated (as most options with default values
+  //   don't), its absence would imply '-mignore-xcoff-visibility'. This changes
+  //   the command line semantics.
+  // * If '-fvisibility' is generated regardless of its presence and value,
+  //   '-mignore-xcoff-visibility' won't be implied and the command line
+  //   semantics are kept intact.
+  //
+  // When the original cc1 command line does **not** contain '-fvisibility',
+  // '-mignore-xcoff-visibility' is implied. The generated command line will
+  // contain both '-fvisibility default' and '-mignore-xcoff-visibility' and
+  // subsequent calls to `CreateFromArgs`/`generateCC1CommandLine` will always
+  // produce the same arguments.
   if (T.isOSAIX() && (Args.hasArg(OPT_mignore_xcoff_visibility) ||
   !Args.hasArg(OPT_fvisibility)))
 Opts.IgnoreXCOFFVisibility = 1;
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5302,7 +5302,9 @@
   MarshallingInfoStringInt, "8">;
 def fvisibility : Separa

[PATCH] D97462: [clang][cli] Round-trip cc1 arguments in assert builds

2021-02-26 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 326677.
jansvoboda11 added a comment.

Rebase on top of D97552 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97462

Files:
  clang/CMakeLists.txt


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -465,7 +465,8 @@
 
 option(CLANG_ENABLE_PROTO_FUZZER "Build Clang protobuf fuzzer." OFF)
 
-option(CLANG_ROUND_TRIP_CC1_ARGS "Round-trip command line arguments in -cc1." 
OFF)
+option(CLANG_ROUND_TRIP_CC1_ARGS
+  "Round-trip command line arguments in -cc1." ${LLVM_ENABLE_ASSERTIONS})
 
 if(NOT CLANG_ENABLE_STATIC_ANALYZER AND CLANG_ENABLE_ARCMT)
   message(FATAL_ERROR "Cannot disable static analyzer while enabling ARCMT or 
Z3")


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -465,7 +465,8 @@
 
 option(CLANG_ENABLE_PROTO_FUZZER "Build Clang protobuf fuzzer." OFF)
 
-option(CLANG_ROUND_TRIP_CC1_ARGS "Round-trip command line arguments in -cc1." OFF)
+option(CLANG_ROUND_TRIP_CC1_ARGS
+  "Round-trip command line arguments in -cc1." ${LLVM_ENABLE_ASSERTIONS})
 
 if(NOT CLANG_ENABLE_STATIC_ANALYZER AND CLANG_ENABLE_ARCMT)
   message(FATAL_ERROR "Cannot disable static analyzer while enabling ARCMT or Z3")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97553: [clang][NFC] pack StaticDiagInfoRec

2021-02-26 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: rsmith, aaron.ballman.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Exchanging types, reordering fields and borrowing a bit from OptionGroupIndex 
shrinks this from 12 bytes to 8.
This knocks ~20k from the binary size.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97553

Files:
  clang/lib/Basic/DiagnosticIDs.cpp


Index: clang/lib/Basic/DiagnosticIDs.cpp
===
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -109,15 +109,15 @@
 
 struct StaticDiagInfoRec {
   uint16_t DiagID;
-  unsigned DefaultSeverity : 3;
-  unsigned Class : 3;
-  unsigned SFINAE : 2;
-  unsigned WarnNoWerror : 1;
-  unsigned WarnShowInSystemHeader : 1;
-  unsigned Deferrable : 1;
-  unsigned Category : 6;
+  uint8_t DefaultSeverity : 3;
+  uint8_t Class : 3;
+  uint8_t SFINAE : 2;
+  uint8_t Category : 6;
+  uint8_t WarnNoWerror : 1;
+  uint8_t WarnShowInSystemHeader : 1;
 
-  uint16_t OptionGroupIndex;
+  uint16_t OptionGroupIndex : 15;
+  uint16_t Deferrable : 1;
 
   uint16_t DescriptionLen;
 
@@ -168,20 +168,20 @@
 #undef STRINGIFY_NAME
 
 const StaticDiagInfoRec StaticDiagInfo[] = {
+// clang-format off
 #define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, 
\
- SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
+ SHOWINSYSHEADER, DEFERRABLE, CATEGORY)
\
   {
\
   diag::ENUM,  
\
   DEFAULT_SEVERITY,
\
   CLASS,   
\
   DiagnosticIDs::SFINAE,   
\
+  CATEGORY,
\
   NOWERROR,
\
   SHOWINSYSHEADER, 
\
- DEFERRABLE,  \
-  CATEGORY,
\
   GROUP,   
\
+   DEFERRABLE, 
 \
   STR_SIZE(DESC, uint16_t)},
-// clang-format off
 #include "clang/Basic/DiagnosticCommonKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
 #include "clang/Basic/DiagnosticFrontendKinds.inc"
@@ -194,7 +194,7 @@
 #include "clang/Basic/DiagnosticSemaKinds.inc"
 #include "clang/Basic/DiagnosticAnalysisKinds.inc"
 #include "clang/Basic/DiagnosticRefactoringKinds.inc"
-  // clang-format on
+// clang-format on
 #undef DIAG
 };
 


Index: clang/lib/Basic/DiagnosticIDs.cpp
===
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -109,15 +109,15 @@
 
 struct StaticDiagInfoRec {
   uint16_t DiagID;
-  unsigned DefaultSeverity : 3;
-  unsigned Class : 3;
-  unsigned SFINAE : 2;
-  unsigned WarnNoWerror : 1;
-  unsigned WarnShowInSystemHeader : 1;
-  unsigned Deferrable : 1;
-  unsigned Category : 6;
+  uint8_t DefaultSeverity : 3;
+  uint8_t Class : 3;
+  uint8_t SFINAE : 2;
+  uint8_t Category : 6;
+  uint8_t WarnNoWerror : 1;
+  uint8_t WarnShowInSystemHeader : 1;
 
-  uint16_t OptionGroupIndex;
+  uint16_t OptionGroupIndex : 15;
+  uint16_t Deferrable : 1;
 
   uint16_t DescriptionLen;
 
@@ -168,20 +168,20 @@
 #undef STRINGIFY_NAME
 
 const StaticDiagInfoRec StaticDiagInfo[] = {
+// clang-format off
 #define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
- SHOWINSYSHEADER, DEFERRABLE, CATEGORY) \
+ SHOWINSYSHEADER, DEFERRABLE, CATEGORY)\
   {\
   diag::ENUM,  \
   DEFAULT_SEVERITY,\
   CLASS,   \
   DiagnosticIDs::SFINAE,   \
+  CATEGORY,\
   NOWERROR,\
   SHOWINSYSHEADER, \
-	  DEFERRABLE,  \
-  CATEGORY,\
   GROUP,  

[PATCH] D96976: [analyzer] Fix reinterpret_cast handling for pointer-to-member

2021-02-26 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

> So here you are implying that for reinterpret casts, the 
> `CastE->path_begin()-end()` range is empty? And that is why you need to 
> manually come up with a //possible// CXXBaseSpecifier list?

@steakhal, Yes. For illustration, the following code:

  struct Base {
int field;
  };
  
  struct Derived : public Base {};
  struct DoubleDerived : public Derived {};
  
  int f() {
int DoubleDerived::*ddf = &Derived::field;
int Base::*bf1 = static_cast(ddf);
int Base::*bf2 = reinterpret_cast(ddf);
  }

produces the following (truncated) AST dump

  -FunctionDecl 0x12f3890  line:8:5 f 'int ()'
`-CompoundStmt 0x12f3ec0 
  |-DeclStmt 0x12f3b70 
  | `-VarDecl 0x12f3a18  col:23 used ddf 'int 
DoubleDerived::*' cinit
  |   `-ImplicitCastExpr 0x12f3b48  'int DoubleDerived::*' 
 Base)>
  | `-UnaryOperator 0x12f3b30  'int Base::*' prefix '&' 
cannot overflow
  |   `-DeclRefExpr 0x12f3ad0  'int' lvalue Field 
0x12f33d0 'field' 'int'
  |-DeclStmt 0x12f3d20 
  | `-VarDecl 0x12f3bf0  col:14 bf1 'int Base::*' cinit
  |   `-CXXStaticCastExpr 0x12f3ce0  'int Base::*' 
static_cast  Base)>
  | `-ImplicitCastExpr 0x12f3cc8  'int DoubleDerived::*' 
 part_of_explicit_cast
  |   `-DeclRefExpr 0x12f3c60  'int DoubleDerived::*' lvalue 
Var 0x12f3a18 'ddf' 'int DoubleDerived::*'
  `-DeclStmt 0x12f3ea8 
`-VarDecl 0x12f3d88  col:14 bf2 'int Base::*' cinit
  `-CXXReinterpretCastExpr 0x12f3e78  'int Base::*' 
reinterpret_cast 
`-ImplicitCastExpr 0x12f3e60  'int DoubleDerived::*' 
 part_of_explicit_cast
  `-DeclRefExpr 0x12f3df8  'int DoubleDerived::*' lvalue 
Var 0x12f3a18 'ddf' 'int DoubleDerived::*'

If you compare the three cases:

1. The first statement has an implicit cast inserted during parsing, and so we 
need not calculate the path manually
2. The second statement has a `static_cast` and it also supplies a path, except 
that we need to remove these bases instead of adding. (Ref to D95877 
).
3. The third statement has no path provided, because it is a `reinterpret_cast` 
and the parser cannot produce a path in all cases (if you cast to an integer 
for an instance) - so it doesn't produce any path

With the parser not providing us with info, we have to figure it out in a 
different way. 
Also, it is not one //possible// path but the //only// possible path. If there 
are multiple acceptable paths then it is illegal to define such a 
member-pointer and the frontend will reject it as such.

> I strongly encourage you to find a better alternative to this manual graph 
> search.
> This information must be available somewhere.
>
> Have you looked at `CXXRecordDecl::isDerivedFrom()`? Or any other member 
> functions of that class?

Unfortunately, all the methods on CXXRecordDecl, like the one you mentioned, 
are for querying and thus returns a `bool`, while I need the entire path.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96976

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


[PATCH] D96976: [analyzer] Fix reinterpret_cast handling for pointer-to-member

2021-02-26 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D96976#2590200 , @RedDocMD wrote:

> Unfortunately, all the methods on CXXRecordDecl, like the one you mentioned, 
> are for querying and thus returns a `bool`, while I need the entire path.

AFAIK the second overload accepts an out parameter serving exactly our needs. 
Could you check if my assumption is correct?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96976

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


[PATCH] D97437: Rewrite MSVC toolchain discovery with VFS

2021-02-26 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Thanks for fixing this :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97437

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


[PATCH] D97361: [clang-tidy] Add readability-redundant-using check

2021-02-26 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In D97361#2589673 , @balazske wrote:

> You can look into **misc/UnusedUsingDeclsCheck.cpp** (if not done yet), that 
> check handles `using` too. And that check is related to this check, the 
> module should be the same too (`misc`)?

Majority of `redundant` checks are in `readability`. Awhile ago I suggested 
separate group for `unused` checks or move them to Clang.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97361

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


[PATCH] D96245: [clangd] Propagate CodeActions in addition to Fixes for diagnostics

2021-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 326686.
kadircet added a comment.

- Update header


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96245

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -693,7 +693,8 @@
   // Transform diagnostics and check the results.
   std::vector>> LSPDiags;
   toLSPDiags(D, MainFile, Opts,
- [&](clangd::Diagnostic LSPDiag, ArrayRef Fixes) {
+ [&](clangd::Diagnostic LSPDiag, ArrayRef Fixes,
+ ArrayRef) {
LSPDiags.push_back(
{std::move(LSPDiag),
 std::vector(Fixes.begin(), Fixes.end())});
@@ -712,7 +713,8 @@
   LSPDiags.clear();
   Opts.EmitRelatedLocations = true;
   toLSPDiags(D, MainFile, Opts,
- [&](clangd::Diagnostic LSPDiag, ArrayRef Fixes) {
+ [&](clangd::Diagnostic LSPDiag, ArrayRef Fixes,
+ ArrayRef) {
LSPDiags.push_back(
{std::move(LSPDiag),
 std::vector(Fixes.begin(), Fixes.end())});
@@ -1334,16 +1336,14 @@
   D.InsideMainFile = true;
   N.InsideMainFile = false;
   toLSPDiags(D, {}, Opts,
- [&](clangd::Diagnostic LSPDiag, ArrayRef) {
-   EXPECT_EQ(LSPDiag.range, D.Range);
- });
+ [&](clangd::Diagnostic LSPDiag, ArrayRef,
+ ArrayRef) { EXPECT_EQ(LSPDiag.range, D.Range); });
 
   D.InsideMainFile = false;
   N.InsideMainFile = true;
   toLSPDiags(D, {}, Opts,
- [&](clangd::Diagnostic LSPDiag, ArrayRef) {
-   EXPECT_EQ(LSPDiag.range, N.Range);
- });
+ [&](clangd::Diagnostic LSPDiag, ArrayRef,
+ ArrayRef) { EXPECT_EQ(LSPDiag.range, N.Range); });
 }
 
 } // namespace
Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -97,6 +97,7 @@
   std::vector Notes;
   /// *Alternative* fixes for this diagnostic, one should be chosen.
   std::vector Fixes;
+  std::vector Actions;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Diag &D);
 
@@ -107,9 +108,11 @@
 /// separate diagnostics with their corresponding fixits. Notes outside main
 /// file do not have a corresponding LSP diagnostic, but can still be included
 /// as part of their main diagnostic's message.
-void toLSPDiags(
-const Diag &D, const URIForFile &File, const ClangdDiagnosticOptions &Opts,
-llvm::function_ref)> OutFn);
+void toLSPDiags(const Diag &D, const URIForFile &File,
+const ClangdDiagnosticOptions &Opts,
+llvm::function_ref,
+llvm::ArrayRef)>
+OutFn);
 
 /// Convert from Fix to LSP CodeAction.
 CodeAction toCodeAction(const Fix &D, const URIForFile &File);
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -403,9 +403,11 @@
   return Result;
 }
 
-void toLSPDiags(
-const Diag &D, const URIForFile &File, const ClangdDiagnosticOptions &Opts,
-llvm::function_ref)> OutFn) {
+void toLSPDiags(const Diag &D, const URIForFile &File,
+const ClangdDiagnosticOptions &Opts,
+llvm::function_ref,
+llvm::ArrayRef)>
+OutFn) {
   clangd::Diagnostic Main;
   Main.severity = getSeverity(D.Severity);
 
@@ -437,7 +439,7 @@
 break;
   }
   if (Opts.EmbedFixesInDiagnostics) {
-Main.codeActions.emplace();
+Main.codeActions = D.Actions;
 for (const auto &Fix : D.Fixes)
   Main.codeActions->push_back(toCodeAction(Fix, File));
 if (Main.codeActions->size() == 1)
@@ -462,7 +464,7 @@
   Main.relatedInformation->push_back(std::move(RelInfo));
 }
   }
-  OutFn(std::move(Main), D.Fixes);
+  OutFn(std::move(Main), D.Fixes, D.Actions);
 
   // If we didn't emit the notes as relatedLocations, emit separate diagnostics
   // so the user can find the locations easily.
@@ -474,7 +476,7 @@
   Res.severity = getSeverity(Note.Severity);
   Res.range = Note.Range;
   Res.message = noteMessage(D, Note, Opts);
-  OutFn(std::move(Res), llvm::ArrayRef());
+  OutFn(std::move(Res), {}, {});
 }
 }
 
@@ -542,7 +544,7 @@
   // duplicated messages due to v

[PATCH] D97555: [clangd] Add diagnostic augmentation hook to Modules

2021-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman, javed.absar.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Depends on D96245 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97555

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/Module.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/TUScheduler.cpp

Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -652,6 +652,7 @@
 printArgv(Inputs.CompileCommand.CommandLine));
 
 StoreDiags CompilerInvocationDiagConsumer;
+CompilerInvocationDiagConsumer.setDiagAugmenters(Inputs.Modules);
 std::vector CC1Args;
 std::unique_ptr Invocation = buildCompilerInvocation(
 Inputs, CompilerInvocationDiagConsumer, &CC1Args);
@@ -716,6 +717,7 @@
 IdleASTs.take(this, &ASTAccessForRead);
 if (!AST) {
   StoreDiags CompilerInvocationDiagConsumer;
+  CompilerInvocationDiagConsumer.setDiagAugmenters(FileInputs.Modules);
   std::unique_ptr Invocation =
   buildCompilerInvocation(FileInputs, CompilerInvocationDiagConsumer);
   // Try rebuilding the AST.
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -326,6 +326,7 @@
   trace::Span Tracer("BuildPreamble");
   SPAN_ATTACH(Tracer, "File", FileName);
   StoreDiags PreambleDiagnostics;
+  PreambleDiagnostics.setDiagAugmenters(Inputs.Modules);
   llvm::IntrusiveRefCntPtr PreambleDiagsEngine =
   CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(),
   &PreambleDiagnostics, false);
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -262,6 +262,7 @@
   CI->getLangOpts()->DelayedTemplateParsing = false;
 
   StoreDiags ASTDiags;
+  ASTDiags.setDiagAugmenters(Inputs.Modules);
 
   llvm::Optional Patch;
   if (Preamble) {
Index: clang-tools-extra/clangd/Module.h
===
--- clang-tools-extra/clangd/Module.h
+++ clang-tools-extra/clangd/Module.h
@@ -9,9 +9,12 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
 
+#include "Protocol.h"
 #include "support/Function.h"
 #include "support/Threading.h"
+#include "clang/Basic/Diagnostic.h"
 #include "llvm/ADT/FunctionExtras.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/JSON.h"
@@ -91,6 +94,15 @@
   /// Called by the server when shutting down, and also by tests.
   virtual bool blockUntilIdle(Deadline) { return true; }
 
+  /// Called by auxilary threads as diagnostics encountered to generate fixes.
+  /// So this can be called concurrently from multiple threads. If a module
+  /// provides a code action with a custom, it should also register itself as
+  /// that commands handler.
+  virtual llvm::Optional
+  augmentDiagFix(DiagnosticsEngine::Level L, const clang::Diagnostic &Diag) {
+return llvm::None;
+  }
+
 protected:
   /// Accessors for modules to access shared server facilities they depend on.
   Facilities &facilities();
Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIAGNOSTICS_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIAGNOSTICS_H
 
+#include "Module.h"
 #include "Protocol.h"
 #include "support/Path.h"
 #include "clang/Basic/Diagnostic.h"
@@ -145,6 +146,7 @@
   /// diagnostics, such as promoting warnings to errors, or ignoring
   /// diagnostics.
   void setLevelAdjuster(LevelAdjuster Adjuster) { this->Adjuster = Adjuster; }
+  void setDiagAugmenters(const ModuleSet *Modules) { this->Modules = Modules; }
 
 private:
   void flushLastDiag();
@@ -157,6 +159,7 @@
   llvm::Optional LastDiagLoc; // Valid only when LastDiag is set.
   bool LastDiagOriginallyError = false;  // Valid only when LastDiag is set.
   SourceManager *OrigSrcMgr = nullptr;
+  const ModuleSet *Modules = nullptr;
 
   llvm::DenseSet> IncludedErrorLocations;
   bool LastPrimaryDiagnosticWasSuppressed = false;
Index: clang-tools-extra/clangd/Dia

[PATCH] D96439: [clangd][WIP] Introduce DiagnosticAugmentationModule

2021-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet abandoned this revision.
kadircet added a comment.

see https://reviews.llvm.org/D97555 for revised version


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96439

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


[PATCH] D93347: [Test] Fix undef var in attr-speculative-load-hardening.c

2021-02-26 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre added reviewers: rsmith, rnk, kristof.beyls.
thopre added a comment.

Ping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93347

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


[PATCH] D97223: Add Alignment argument to IRBuilder CreateAtomicRMW and CreateAtomicCmpXchg.

2021-02-26 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: llvm/lib/CodeGen/AtomicExpandPass.cpp:1037
 
+  assert(AddrAlign >= ResultTy->getPrimitiveSizeInBits() / 8 &&
+ "Expected at least natural alignment at this point.");

jrtc27 wrote:
> Doesn't this introduce another copy of the same problem that D91256 is fixing 
> (even if that one happens to also be fixed by this patch)?
It sure does, although in a different function. :) Fixed in 
740e69b6fdc2b1415065f3d20acc4d10a73edb00, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97223

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


[PATCH] D97388: [analyzer] Replace StoreManager::evalIntegralCast with SValBuilder::evalCast

2021-02-26 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@steakhal

> Please make sure that you specify the parent revision or the patch can be 
> applied on top of the tree.

Sorry, probably missed to add a parent revision. Done.


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

https://reviews.llvm.org/D97388

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


[PATCH] D97561: [clang] Use CompilerInstance::createTarget to createTarget

2021-02-26 Thread Tommy Chiang via Phabricator via cfe-commits
oToToT created this revision.
oToToT added reviewers: sammccall, rsmith, klimek, dexonsmith.
oToToT added a project: clang.
oToToT requested review of this revision.
Herald added a subscriber: cfe-commits.

As proposed in D97109 , I tried to replace all 
similar target creating logics to a single CompilerInstance::createTarget call 
introduced in  D97493 .

This improve the consistency while creating Target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97561

Files:
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/ChainedIncludesSource.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/tools/clang-import-test/clang-import-test.cpp

Index: clang/tools/clang-import-test/clang-import-test.cpp
===
--- clang/tools/clang-import-test/clang-import-test.cpp
+++ clang/tools/clang-import-test/clang-import-test.cpp
@@ -205,10 +205,7 @@
 
   Ins->setInvocation(std::move(Inv));
 
-  TargetInfo *TI = TargetInfo::CreateTargetInfo(
-  Ins->getDiagnostics(), Ins->getInvocation().TargetOpts);
-  Ins->setTarget(TI);
-  Ins->getTarget().adjust(Ins->getLangOpts());
+  Ins->createTarget();
   Ins->createFileManager();
   Ins->createSourceManager(Ins->getFileManager());
   Ins->createPreprocessor(TU_Complete);
Index: clang/lib/Frontend/PrecompiledPreamble.cpp
===
--- clang/lib/Frontend/PrecompiledPreamble.cpp
+++ clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -365,17 +365,9 @@
   Clang->setDiagnostics(&Diagnostics);
 
   // Create the target instance.
-  Clang->setTarget(TargetInfo::CreateTargetInfo(
-  Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
-  if (!Clang->hasTarget())
+  if (!Clang->createTarget())
 return BuildPreambleError::CouldntCreateTargetInfo;
 
-  // Inform the target of the language options.
-  //
-  // FIXME: We shouldn't need to do this, the target should be immutable once
-  // created. This complexity should be lifted elsewhere.
-  Clang->getTarget().adjust(Clang->getLangOpts());
-
   if (Clang->getFrontendOpts().Inputs.size() != 1 ||
   Clang->getFrontendOpts().Inputs[0].getKind().getFormat() !=
   InputKind::Source ||
Index: clang/lib/Frontend/ChainedIncludesSource.cpp
===
--- clang/lib/Frontend/ChainedIncludesSource.cpp
+++ clang/lib/Frontend/ChainedIncludesSource.cpp
@@ -149,8 +149,7 @@
 new CompilerInstance(CI.getPCHContainerOperations()));
 Clang->setInvocation(std::move(CInvok));
 Clang->setDiagnostics(Diags.get());
-Clang->setTarget(TargetInfo::CreateTargetInfo(
-Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
+Clang->createTarget();
 Clang->createFileManager();
 Clang->createSourceManager(Clang->getFileManager());
 Clang->createPreprocessor(TU_Prefix);
Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -1150,17 +1150,9 @@
   Clang->setDiagnostics(&getDiagnostics());
 
   // Create the target instance.
-  Clang->setTarget(TargetInfo::CreateTargetInfo(
-  Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
-  if (!Clang->hasTarget())
+  if (!Clang->createTarget())
 return true;
 
-  // Inform the target of the language options.
-  //
-  // FIXME: We shouldn't need to do this, the target should be immutable once
-  // created. This complexity should be lifted elsewhere.
-  Clang->getTarget().adjust(Clang->getLangOpts());
-
   assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
  "Invocation must have exactly one source file!");
   assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() ==
@@ -1568,17 +1560,9 @@
   Clang->setDiagnostics(&AST->getDiagnostics());
 
   // Create the target instance.
-  Clang->setTarget(TargetInfo::CreateTargetInfo(
-  Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
-  if (!Clang->hasTarget())
+  if (!Clang->createTarget())
 return nullptr;
 
-  // Inform the target of the language options.
-  //
-  // FIXME: We shouldn't need to do this, the target should be immutable once
-  // created. This complexity should be lifted elsewhere.
-  Clang->getTarget().adjust(Clang->getLangOpts());
-
   assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
  "Invocation must have exactly one source file!");
   assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() ==
@@ -2194,19 +2178,11 @@
   ProcessWarningOptions(Diag, Inv.getDiagnosticOpts());
 
   // Create the target instance.
-  Clang->setTarget(TargetInfo::CreateTargetInfo(
-  Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
-  if (!Clang->hasTarget()) {
+  if (!Clang->createTarget()) {
 Clang->setInvocation(nullptr);
 return;
  

[PATCH] D97561: [clang] Use CompilerInstance::createTarget to createTarget

2021-02-26 Thread Tommy Chiang via Phabricator via cfe-commits
oToToT added inline comments.



Comment at: clang/lib/Frontend/PrecompiledPreamble.cpp:368
   // Create the target instance.
-  Clang->setTarget(TargetInfo::CreateTargetInfo(
-  Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
-  if (!Clang->hasTarget())
+  if (!Clang->createTarget())
 return BuildPreambleError::CouldntCreateTargetInfo;

Changing this without other further patch might cause `clangd` results in 
Runtime Error while handling files like CUDA.
Should I also include the patch of `clangd` or other related projects into this 
patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97561

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


[PATCH] D94640: adds more checks to -Wfree-nonheap-object

2021-02-26 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This seems to flag 
https://source.chromium.org/chromium/chromium/src/+/master:third_party/libsync/src/sync.c;l=142?q=sync.c&ss=chromium
 :

  info->sync_fence_info = (uint64_t) calloc(num_fences,
  sizeof(struct sync_fence_info));
  if ((void *)info->sync_fence_info == NULL)
  goto free;
  
  err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
  if (err < 0) {
  free((void *)info->sync_fence_info);
  goto free;
  }

What's the motivation for flagging an integer that's >= sizeof(void*) and 
that's explicitly cast to void*? That seems like code that's pretty explicit 
about its intentions.

Did you do true positive / false positive evaluation of this change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94640

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


[PATCH] D96120: [scudo] Port scudo sanitizer to Windows

2021-02-26 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop updated this revision to Diff 326716.
russell.gallop added a comment.

Added comment on AllocatorSize.

Applied Mingw changes suggested by @mstorsjo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96120

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
  compiler-rt/lib/scudo/CMakeLists.txt
  compiler-rt/lib/scudo/scudo_allocator.cpp
  compiler-rt/lib/scudo/scudo_crc32.cpp
  compiler-rt/lib/scudo/scudo_new_delete.cpp
  compiler-rt/lib/scudo/scudo_platform.h
  compiler-rt/lib/scudo/scudo_tsd.h
  compiler-rt/lib/scudo/scudo_tsd_shared.cpp
  compiler-rt/lib/scudo/scudo_tsd_shared.inc
  compiler-rt/test/scudo/cxx_threads.cpp
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/valloc.c
===
--- compiler-rt/test/scudo/valloc.c
+++ compiler-rt/test/scudo/valloc.c
@@ -2,7 +2,7 @@
 // RUN: %run %t valid   2>&1
 // RUN: not %run %t invalid 2>&1 | FileCheck %s
 // RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t invalid 2>&1
-// UNSUPPORTED: android
+// UNSUPPORTED: android, windows
 
 // Tests that valloc and pvalloc work as intended.
 
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- compiler-rt/test/scudo/tsd_destruction.c
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,5 +1,6 @@
 // RUN: %clang_scudo %s -o %t
 // RUN: %run %t 2>&1
+// UNSUPPORTED: windows
 
 #include 
 #include 
Index: compiler-rt/test/scudo/threads.c
===
--- compiler-rt/test/scudo/threads.c
+++ compiler-rt/test/scudo/threads.c
@@ -1,6 +1,7 @@
 // RUN: %clang_scudo %s -o %t
 // RUN: %env_scudo_opts="QuarantineSizeKb=0:ThreadLocalQuarantineSizeKb=0" %run %t 5 100 2>&1
 // RUN: %env_scudo_opts="QuarantineSizeKb=1024:ThreadLocalQuarantineSizeKb=64" %run %t 5 100 2>&1
+// UNSUPPORTED: windows
 
 // Tests parallel allocations and deallocations of memory chunks from a number
 // of concurrent threads, with and without quarantine.
Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ compiler-rt/test/scudo/symbols.test
@@ -1,4 +1,4 @@
-UNSUPPORTED: android
+UNSUPPORTED: android, windows
 
 Verify that various functions are *not* present in the minimal binary. Presence
 of those symbols in the minimal runtime would mean that the split code made it
Index: compiler-rt/test/scudo/secondary.c
===
--- compiler-rt/test/scudo/secondary.c
+++ compiler-rt/test/scudo/secondary.c
@@ -6,37 +6,60 @@
 // allocated by the Secondary allocator, or writing too far in front of it.
 
 #include 
-#include 
-#include 
+#include 
 #include 
 #include 
+#ifdef _WIN32
+#include 
+#else
+#include 
 #include 
+#endif
 
+#ifdef _WIN32
+DWORD getsystempagesize() {
+  SYSTEM_INFO si;
+  GetSystemInfo(&si);
+  return si.dwPageSize;
+}
+LONG WINAPI handler(EXCEPTION_POINTERS *ExceptionInfo) {
+  fprintf(stderr, "AccessViolation\n");
+  ExitProcess(0);
+}
+#else
 void handler(int signo, siginfo_t *info, void *uctx) {
   if (info->si_code == SEGV_ACCERR) {
-fprintf(stderr, "SCUDO SIGSEGV\n");
+fprintf(stderr, "AccessViolation\n");
 exit(0);
   }
   exit(1);
 }
+long getsystempagesize() {
+  return sysconf(_SC_PAGESIZE);
+}
+#endif
 
 int main(int argc, char **argv)
 {
   // The size must be large enough to be serviced by the secondary allocator.
-  long page_size = sysconf(_SC_PAGESIZE);
-  size_t size = (1U << 17) + page_size;
-  struct sigaction a;
+  long page_size = getsystempagesize();
+  size_t size = (1U << 19) + page_size;
 
   assert(argc == 2);
-  memset(&a, 0, sizeof(a));
-  a.sa_sigaction = handler;
-  a.sa_flags = SA_SIGINFO;
 
   char *p = (char *)malloc(size);
   assert(p);
   memset(p, 'A', size); // This should not trigger anything.
   // Set up the SIGSEGV handler now, as the rest should trigger an AV.
+#ifdef _WIN32
+  SetUnhandledExceptionFilter(handler);
+#else
+  struct sigaction a = {0};
+  a.sa_sigaction = handler;
+  a.sa_flags = SA_SIGINFO;
   sigaction(SIGSEGV, &a, NULL);

[PATCH] D96612: [clangd] Improve printing of Objective-C categories and methods

2021-02-26 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 326719.
dgoldman marked an inline comment as done.
dgoldman added a comment.

Limit changes to document symbols


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96612

Files:
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp


Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -912,6 +912,42 @@
 WithDetail(""));
 }
 
+TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $Cat[[@interface Cat
+  + (id)sharedCat;
+  @end]]
+  $SneakyCat[[@interface Cat (Sneaky)
+  - (id)sneak:(id)behavior;
+  @end]]
+
+  $MeowCat[[@interface Cat ()
+  - (void)meow;
+  @end]]
+  $PurCat[[@interface Cat ()
+  - (void)pur;
+  @end]]
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+  getSymbols(TU.build()),
+  ElementsAre(
+  AllOf(WithName("Cat"), SymRange(Main.range("Cat")),
+Children(AllOf(WithName("+sharedCat"),
+   WithKind(SymbolKind::Method,
+  AllOf(WithName("Cat(Sneaky)"), SymRange(Main.range("SneakyCat")),
+Children(
+AllOf(WithName("-sneak:"), WithKind(SymbolKind::Method,
+  AllOf(
+  WithName("Cat()"), SymRange(Main.range("MeowCat")),
+  Children(AllOf(WithName("-meow"), 
WithKind(SymbolKind::Method,
+  AllOf(WithName("Cat()"), SymRange(Main.range("PurCat")),
+Children(
+AllOf(WithName("-pur"), WithKind(SymbolKind::Method));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/FindSymbols.cpp
===
--- clang-tools-extra/clangd/FindSymbols.cpp
+++ clang-tools-extra/clangd/FindSymbols.cpp
@@ -172,6 +172,22 @@
 }
 
 namespace {
+std::string getSymbolName(ASTContext &Ctx, const NamedDecl &ND) {
+  if (const auto *Container = dyn_cast(&ND))
+return printObjCContainer(*Container);
+  if (const auto *Method = dyn_cast(&ND)) {
+std::string Name;
+llvm::raw_string_ostream OS(Name);
+
+OS << (Method->isInstanceMethod() ? '-' : '+');
+Method->getSelector().print(OS);
+
+OS.flush();
+return Name;
+  }
+  return printName(Ctx, ND);
+}
+
 std::string getSymbolDetail(ASTContext &Ctx, const NamedDecl &ND) {
   PrintingPolicy P(Ctx.getPrintingPolicy());
   P.SuppressScope = true;
@@ -220,7 +236,7 @@
   SymbolKind SK = indexSymbolKindToSymbolKind(SymInfo.Kind);
 
   DocumentSymbol SI;
-  SI.name = printName(Ctx, ND);
+  SI.name = getSymbolName(Ctx, ND);
   SI.kind = SK;
   SI.deprecated = ND.isDeprecated();
   SI.range = Range{sourceLocToPosition(SM, SymbolRange->getBegin()),


Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -912,6 +912,42 @@
 WithDetail(""));
 }
 
+TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $Cat[[@interface Cat
+  + (id)sharedCat;
+  @end]]
+  $SneakyCat[[@interface Cat (Sneaky)
+  - (id)sneak:(id)behavior;
+  @end]]
+
+  $MeowCat[[@interface Cat ()
+  - (void)meow;
+  @end]]
+  $PurCat[[@interface Cat ()
+  - (void)pur;
+  @end]]
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+  getSymbols(TU.build()),
+  ElementsAre(
+  AllOf(WithName("Cat"), SymRange(Main.range("Cat")),
+Children(AllOf(WithName("+sharedCat"),
+   WithKind(SymbolKind::Method,
+  AllOf(WithName("Cat(Sneaky)"), SymRange(Main.range("SneakyCat")),
+Children(
+AllOf(WithName("-sneak:"), WithKind(SymbolKind::Method,
+  AllOf(
+  WithName("Cat()"), SymRange(Main.range("MeowCat")),
+  Children(AllOf(WithName("-meow"), WithKind(SymbolKind::Method,
+  AllOf(WithName("Cat()"), SymRange(Main.range("PurCat")),
+Children(
+AllOf(WithName("-pur"), WithKind(SymbolKind::Method));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/FindSymbols.cpp
===
--- clang-tool

[PATCH] D97535: [clangd] Use URIs instead of paths in the index file list

2021-02-26 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/FileIndex.cpp:279
   SymbolSlabs.push_back(FileAndSymbols.second);
+  for (const auto &S : *FileAndSymbols.second) {
+if (S.Definition)

iterating over all the symbols here (and refs below) seems really unfortunate. 
But looking at the previous discussions that seems to be best of both worlds 
until we populate a file list in SymbolCollector. However, I think it would be 
better to do the looping after releasing the lock (we already have the 
information copied over to our snapshots).

moreover we seem to be still inserting keys of the Symbol and RefSlabs into 
Files, but not doing that for RelationSlabs, why? (i believe we shouldn't be 
inserting the keys at all, if we indeed want to just insert URIs and keep 
treating the keys as opaque objects).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97535

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


[PATCH] D97512: [clang] removes check against integral-to-pointer conversion...

2021-02-26 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 326723.
cjdb edited the summary of this revision.
cjdb added a comment.

updates commit message to explain what's going on and why the change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97512

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Analysis/free.c
  clang/test/Analysis/free.cpp


Index: clang/test/Analysis/free.cpp
===
--- clang/test/Analysis/free.cpp
+++ clang/test/Analysis/free.cpp
@@ -208,3 +208,15 @@
   // Unknown value
   std::free(x[offset]); // no-warning
 }
+
+struct S {
+  const char* p;
+};
+
+void t18a (S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18b (S s) {
+  std::free((void*)(unsigned long long)s.p); // no warning
+}
Index: clang/test/Analysis/free.c
===
--- clang/test/Analysis/free.c
+++ clang/test/Analysis/free.c
@@ -108,3 +108,11 @@
   // expected-warning@-1{{Argument to free() is the address of the function 
'iptr', which is not memory allocated by malloc()}}
   // expected-warning@-2{{attempt to call free on non-heap object 'iptr'}}
 }
+
+struct S {
+  const char* p;
+};
+
+void t18 (struct S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10316,11 +10316,18 @@
 const CastExpr *Cast) {
   SmallString<128> SizeString;
   llvm::raw_svector_ostream OS(SizeString);
+
+  const clang::CastKind Kind = Cast->getCastKind();
+  if (Kind == clang::CK_BitCast &&
+  !Cast->getSubExpr()->getType()->isFunctionPointerType())
+return;
+  if (Kind == clang::CK_IntegralToPointer &&
+  !isa(
+  Cast->getSubExpr()->IgnoreImplicitAsWritten()->IgnoreParens()))
+return;
+
   switch (Cast->getCastKind()) {
   case clang::CK_BitCast:
-if (!Cast->getSubExpr()->getType()->isFunctionPointerType())
-  return;
-[[clang::fallthrough]];
   case clang::CK_IntegralToPointer:
   case clang::CK_FunctionToPointerDecay:
 OS << '\'';


Index: clang/test/Analysis/free.cpp
===
--- clang/test/Analysis/free.cpp
+++ clang/test/Analysis/free.cpp
@@ -208,3 +208,15 @@
   // Unknown value
   std::free(x[offset]); // no-warning
 }
+
+struct S {
+  const char* p;
+};
+
+void t18a (S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18b (S s) {
+  std::free((void*)(unsigned long long)s.p); // no warning
+}
Index: clang/test/Analysis/free.c
===
--- clang/test/Analysis/free.c
+++ clang/test/Analysis/free.c
@@ -108,3 +108,11 @@
   // expected-warning@-1{{Argument to free() is the address of the function 'iptr', which is not memory allocated by malloc()}}
   // expected-warning@-2{{attempt to call free on non-heap object 'iptr'}}
 }
+
+struct S {
+  const char* p;
+};
+
+void t18 (struct S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10316,11 +10316,18 @@
 const CastExpr *Cast) {
   SmallString<128> SizeString;
   llvm::raw_svector_ostream OS(SizeString);
+
+  const clang::CastKind Kind = Cast->getCastKind();
+  if (Kind == clang::CK_BitCast &&
+  !Cast->getSubExpr()->getType()->isFunctionPointerType())
+return;
+  if (Kind == clang::CK_IntegralToPointer &&
+  !isa(
+  Cast->getSubExpr()->IgnoreImplicitAsWritten()->IgnoreParens()))
+return;
+
   switch (Cast->getCastKind()) {
   case clang::CK_BitCast:
-if (!Cast->getSubExpr()->getType()->isFunctionPointerType())
-  return;
-[[clang::fallthrough]];
   case clang::CK_IntegralToPointer:
   case clang::CK_FunctionToPointerDecay:
 OS << '\'';
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94640: adds more checks to -Wfree-nonheap-object

2021-02-26 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D94640#2590512 , @thakis wrote:

> This seems to flag 
> https://source.chromium.org/chromium/chromium/src/+/master:third_party/libsync/src/sync.c;l=142?q=sync.c&ss=chromium
>  :
>
>   info->sync_fence_info = (uint64_t) calloc(num_fences,
>   sizeof(struct sync_fence_info));
>   if ((void *)info->sync_fence_info == NULL)
>   goto free;
>   
>   err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
>   if (err < 0) {
>   free((void *)info->sync_fence_info);
>   goto free;
>   }
>
> What's the motivation for flagging an integer that's >= sizeof(void*) and 
> that's explicitly cast to void*? That seems like code that's pretty explicit 
> about its intentions.
>
> Did you do true positive / false positive evaluation of this change?

This change was a bit too aggressive and is being rolled back in D97512 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94640

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


[PATCH] D97563: [clang-tidy] Enable modernize-concat-nested-namespaces also on headers

2021-02-26 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin created this revision.
DmitryPolukhin added reviewers: hokein, aaron.ballman, alexfh, JonasToth, 
njames93.
DmitryPolukhin added a project: clang.
Herald added a subscriber: xazax.hun.
DmitryPolukhin requested review of this revision.

For some reason the initial implementation of the check had an explicit check
for the main file to avoid being applied in headers. This diff removes this
check and add a test for the check on a header.

Similar approach was proposed in D61989  but 
review there got stuck.

Test Plan: added new test case


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97563

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
@@ -1,4 +1,12 @@
-// RUN: %check_clang_tidy -std=c++17-or-later %s 
modernize-concat-nested-namespaces %t
+// RUN: cp 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 %T/modernize-concat-nested-namespaces.h
+// RUN: %check_clang_tidy -std=c++17 %s modernize-concat-nested-namespaces %t 
-- -header-filter=".*" -- -I %T
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 -check-prefix=CHECK-FIXES
+// Restore header file and re-run with c++2b:
+// RUN: cp 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 %T/modernize-concat-nested-namespaces.h
+// RUN: %check_clang_tidy -std=c++2b %s modernize-concat-nested-namespaces %t 
-- -header-filter=".*" -- -I %T
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 -check-prefix=CHECK-FIXES
+
+#include "modernize-concat-nested-namespaces.h"
 
 namespace n1 {}
 
@@ -159,3 +167,5 @@
 
   return 0;
 }
+
+// CHECK-MESSAGES: modernize-concat-nested-namespaces.h:1:1: warning: nested 
namespaces can be concatenated [modernize-concat-nested-namespaces]
Index: 
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
@@ -0,0 +1,7 @@
+namespace nn1 {
+namespace nn2 {
+// CHECK-FIXES: namespace nn1::nn2
+void t();
+} // namespace nn2
+} // namespace nn1
+// CHECK-FIXES: }
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -82,9 +82,6 @@
   if (!locationsInSameFile(Sources, ND.getBeginLoc(), ND.getRBraceLoc()))
 return;
 
-  if (!Sources.isInMainFile(ND.getBeginLoc()))
-return;
-
   if (anonymousOrInlineNamespace(ND))
 return;
 


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
@@ -1,4 +1,12 @@
-// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-concat-nested-namespaces %t
+// RUN: cp %S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
+// RUN: %check_clang_tidy -std=c++17 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
+// Restore header file and re-run with c++2b:
+// RUN: cp %S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
+// RUN: %check_clang_tidy -std=c++2b %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
+
+#include "modernize-concat-nested-namespaces.h"
 
 namespace n1 {}
 
@@ -159,3 +167,5 @@
 
 

[PATCH] D96120: [scudo] Port scudo sanitizer to Windows

2021-02-26 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop marked 2 inline comments as done.
russell.gallop added a comment.

In D96120#2550941 , @mstorsjo wrote:

> In D96120#2550876 , @russell.gallop 
> wrote:
>
>> In D96120#2546077 , @mstorsjo wrote:
>>
>>> As is, this breaks compilation for mingw. With the three modifications I 
>>> suggest here, it no longer breaks compilation for me - I have no idea if it 
>>> actually works in mingw configurations though, but not breaking compilation 
>>> is at least the first step.
>>
>> Thanks for the information I'll try to run up a mingw environment and check 
>> it works.
>
> In case that turns out to be tricky, I might be able to help with that, at 
> least for building a simple test program with it and running it, if you say 
> how it's supposed to be used  (building/linking with `-fsanitize=scudo`?) and 
> how to inspect whether it actually works.

Hi @mstorsjo. Thanks for the suggestions. I tried running up an mingw 
environment with msys but had trouble getting it working (running into cmake 
issues). Would you be able to help?

Yes, building and linking a program with -fsanitize=scudo is the simple way to 
build a simple program. The support for this is in 
clang/lib/Driver/ToolChains/MSVC.cpp. Would this require support in 
clang/lib/Driver/ToolChains/MinGW.cpp?

I think the best way to test is to run the scudo LIT tests with (e.g.) "ninja 
check-scudo". These build and run some simple test programs and check that 
problems are detected.

Beyond this I built LLVM with scudo and ran check-all. I don't know whether you 
want to go this far. Note that -fsanitize=scudo doesn't work for the MSVC LLVM 
build which uses link/lld-link for linking rather than going via the compiler 
driver so I hooked it into LLVM_INTEGRATED_CRT_ALLOC (see 
https://reviews.llvm.org/D96133). If mingw uses the compiler driver to link 
(like Linux) then you may be able to use -DLLVM_USE_SANITIZER=Scudo on a stage2 
build. This would require some changes to 
llvm/cmake/modules/HandleLLVMOptions.cmake to permit it (I had similar changes 
in https://reviews.llvm.org/D86694). It's harder to tell whether this has 
worked correctly. With MSVC faster ThinLTO links on multi-core machines are a 
good indicator but I guess mingw wouldn't be using the MSVC allocator.

Thanks
Russ




Comment at: compiler-rt/lib/scudo/scudo_new_delete.cpp:30
+#ifdef _WIN64
+COMMENT_EXPORT("??2@YAPEAX_K@Z")// operator new
+COMMENT_EXPORT("??2@YAPEAX_KAEBUnothrow_t@std@@@Z") // operator new nothrow

mstorsjo wrote:
> These don't work in this form for mingw targets (which use the itanium c++ 
> abi).
> 
> By changing `#if SANTIZER_WINDOWS` into `#if SANITIZER_WINDOWS && 
> !defined(__MINGW32__)`, I fixed the linker errors at least.
I've applied this suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96120

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


[PATCH] D94973: [clang][OpenMP] Use OpenMPIRBuilder for workshare loops.

2021-02-26 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:8321
+TreeTransform::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
+  // The OMPCanonicalLoop will be recreated when transforming the 
loop-associted
+  // directive.

jdenny wrote:
> Meinersbur wrote:
> > jdenny wrote:
> > > Meinersbur wrote:
> > > > jdenny wrote:
> > > > > Meinersbur wrote:
> > > > > > jdenny wrote:
> > > > > > > I'm used to seeing `TransformX` call `RebuildX` call `ActOnX`.  
> > > > > > > Why not do that for `X=OMPCanonicalLoop`?  Does 
> > > > > > > `TransformOMPExecutableDirective` really need a special case for 
> > > > > > > `OMPCanonicalLoop`?
> > > > > > The intended behaviour is: 
> > > > > > 
> > > > > > 1. Transform the child loop
> > > > > > 2. Return the child loop as representing the OMPCanonicalLoop (i.e. 
> > > > > > OMPCanonicalLoop wrapper is removed).
> > > > > > 3. Parent loop-associated directive (e.g. workshare) is processed.
> > > > > > 4. `ActOnOpenMPCanonicalLoop` adds new OMPCanonicalLoop wrapper for 
> > > > > > loop nest.
> > > > > > 
> > > > > > This guarantees maximum flexibility on what of the loop can be 
> > > > > > changed, such as
> > > > > > * Change lower bound, upper bound, step
> > > > > > * Convert between CXXForRangeStmt and ForStmt
> > > > > > * Change the associated depth (e.g. different value for `collapse` 
> > > > > > clause)
> > > > > > * Remove the directive and no OMPCanonicalLoop remain
> > > > > > 
> > > > > > This also saves adding many lines of code handling transforming 
> > > > > > each member of OMPCanonicalLoop separately.
> > > > > > The intended behaviour is: 
> > > > > > 
> > > > > > 1. Transform the child loop
> > > > > 
> > > > > For  my suggestion, that call would remain within 
> > > > > `TransformOMPCanonicalLoop` where it is now.
> > > > > 
> > > > > > 2. Return the child loop as representing the OMPCanonicalLoop (i.e. 
> > > > > > OMPCanonicalLoop wrapper is removed).
> > > > > 
> > > > > For my suggestion, this would not happen.  I think it's normal for a 
> > > > > `TransformX` to return the transformed `X` not the transformed child 
> > > > > of `X`.  If a caller wants to transform the child, then it should 
> > > > > transform the child directly instead.
> > > > > 
> > > > > > 3. Parent loop-associated directive (e.g. workshare) is processed.
> > > > > 
> > > > > It looks to me like step 3 is currently within 
> > > > > `TransformOMPExecutableDirective` and starts before the call to 
> > > > > `TranformOMPCanonicalLoop` and thus before step 1.  It completes 
> > > > > after step 4.  Or am I misunderstanding what you're describing as 
> > > > > step 3?
> > > > > 
> > > > > > 4. `ActOnOpenMPCanonicalLoop` adds new OMPCanonicalLoop wrapper for 
> > > > > > loop nest.
> > > > > 
> > > > > For my suggestion, this would still happen.  However, instead of step 
> > > > > 2: within `TransformOMPCanonicalLoop`, you would call 
> > > > > `RebuildOMPCanonicalLoop`, which would call 
> > > > > `ActOnOpenMPCanonicalLoop` as step 4.  The effect is you moved 
> > > > > `ActOnOpenMPCanonicalLoop` from the caller 
> > > > > (`TransformOMPExecutableDirective`) to the callee's callee, but the 
> > > > > behavior should remain the same.
> > > > > 
> > > > > > This guarantees maximum flexibility on what of the loop can be 
> > > > > > changed, such as
> > > > > > * Change lower bound, upper bound, step
> > > > > > * Convert between CXXForRangeStmt and ForStmt
> > > > > > * Change the associated depth (e.g. different value for `collapse` 
> > > > > > clause)
> > > > > > * Remove the directive and no OMPCanonicalLoop remain
> > > > > 
> > > > > Flexibility for whom?
> > > > > 
> > > > > A class extending `TreeTransform`?  With my suggestion, it can 
> > > > > override `TransformOMPCanonicalLoop` or `RebuildOMPCanonicalLoop`, 
> > > > > depending on how much it wants to alter the transformation.
> > > > > 
> > > > > Or a caller of `TransformOMPCanonicalLoop` within `TreeTransform`?  I 
> > > > > only see one right now, `TransformOMPExecutableDirective`, and I 
> > > > > don't see how it needs the flexibility.  Are there other callers I 
> > > > > missed?
> > > > > 
> > > > > Are you trying to create flexibility without requiring deriving from 
> > > > > `TreeTransform`?  But, as far as I can tell, you're doing so at the 
> > > > > expense of normal `TreeTransform` semantics.  Doesn't seem worth it.
> > > > > 
> > > > > If you see a precedent for your approach elsewhere in 
> > > > > `TreeTransform`, please point it out.
> > > > > 
> > > > > > This also saves adding many lines of code handling transforming 
> > > > > > each member of OMPCanonicalLoop separately.
> > > > > 
> > > > > Why would you need to?  In the other `TransformX` functions I looked 
> > > > > at, the arguments to the `RebuildX` function are transformed, and 
> > > > > those are typically just the arguments to the `ActOnX` function.  In 
> > > > > other words, y

[PATCH] D97563: [clang-tidy] Enable modernize-concat-nested-namespaces also on headers

2021-02-26 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h:7
+} // namespace nn1
+// CHECK-FIXES: }

This fix line isn't actually contributing to the test.
Perhaps a better case, assuming clang-format doesn't update the comment, would 
be:
```lang=c++
// CHECK-FIXES: void t();
// CHECK-FIXES-NEXT: } namespace nn1
```



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp:4
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 -check-prefix=CHECK-FIXES
+// Restore header file and re-run with c++2b:
+// RUN: cp 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 %T/modernize-concat-nested-namespaces.h

Why do we explicitly run on c++2b and not c++20? I understand there is no 
framework in place for using -std=c++17-or-later when header files are modified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97563

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


[PATCH] D96976: [analyzer] Fix reinterpret_cast handling for pointer-to-member

2021-02-26 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 326731.
RedDocMD added a comment.

Replaced BFS with existing CXXRecordDeclMethod


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96976

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp

Index: clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp
===
--- clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp
+++ clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp
@@ -1,11 +1,11 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
-// XFAIL: asserts
 
 void clang_analyzer_eval(bool);
 
-// TODO: The following test will work properly once reinterpret_cast on pointer-to-member is handled properly
 namespace testReinterpretCasting {
-struct Base {
+struct BaseOfBase {};
+
+struct Base : public BaseOfBase {
   int field;
 };
 
@@ -15,12 +15,51 @@
 
 struct Some {};
 
-void f() {
+void analyzableCasts() {
   int DoubleDerived::*ddf = &Base::field;
   int Base::*bf = reinterpret_cast(reinterpret_cast(reinterpret_cast(ddf)));
-  int Some::*sf = reinterpret_cast(ddf);
   Base base;
   base.field = 13;
   clang_analyzer_eval(base.*bf == 13); // expected-warning{{TRUE}}
 }
+
+void castOutsideHierarchy() {
+  int DoubleDerived::*ddf = &Base::field;
+  int Some::*sf = reinterpret_cast(ddf);
+  Some some;
+  some.*sf = 14;
+  clang_analyzer_eval(some.*sf == 14); // expected-warning{{UNKNOWN}}
+}
+
+void castAbove() {
+  int DoubleDerived::*ddf = &Base::field;
+  int BaseOfBase::*bbf = reinterpret_cast(ddf);
+  BaseOfBase bb;
+  bb.*bbf = 23;
+  clang_analyzer_eval(bb.*bbf == 23); // expected-warning{{UNKNOWN}}
+}
+
+namespace testMultipleInheritance {
+struct A {};
+struct B : public A {};
+struct C {
+  int field;
+};
+struct D : public C {};
+struct E : public B, public D {};
+struct F : public E {};
+
+void testMultiple() {
+  int F::*f = &F::field;
+  int A::*a = reinterpret_cast(f);
+  int C::*c = reinterpret_cast(f);
+  A aobj;
+  C cobj;
+  aobj.*a = 13;
+  cobj.*c = 29;
+  clang_analyzer_eval(aobj.*a == 13); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(cobj.*c == 29); // expected-warning{{TRUE}}
+}
+} // namespace testMultipleInheritance
+
 } // namespace testReinterpretCasting
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -522,8 +522,7 @@
 continue;
   }
   case CK_DerivedToBaseMemberPointer:
-  case CK_BaseToDerivedMemberPointer:
-  case CK_ReinterpretMemberPointer: {
+  case CK_BaseToDerivedMemberPointer: {
 SVal V = state->getSVal(Ex, LCtx);
 if (auto PTMSV = V.getAs()) {
   SVal CastedPTMSV =
@@ -537,6 +536,25 @@
 state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
 continue;
   }
+  case CK_ReinterpretMemberPointer: {
+SVal V = state->getSVal(Ex, LCtx);
+if (auto PTMSV = V.getAs()) {
+  if (const auto *ReinterpretE =
+  llvm::dyn_cast(CastE)) {
+if (const PointerToMemberData *Data =
+getBasicVals().basesForReinterpretCast(ReinterpretE,
+   *PTMSV)) {
+  SVal CastedPTMSV = svalBuilder.makePointerToMember(Data);
+  state = state->BindExpr(CastE, LCtx, CastedPTMSV);
+  Bldr.generateNode(CastE, Pred, state);
+  continue;
+}
+  }
+}
+// Explicitly proceed with default handler for this case cascade.
+state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
+continue;
+  }
   // Various C++ casts that are not handled yet.
   case CK_ToUnion:
   case CK_VectorSplat: {
Index: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
===
--- clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
+++ clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h"
+#include "clang/AST/CXXInheritance.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
@@ -22,8 +23,11 @@
 #include "llvm/ADT/ImmutableList.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
 #include 
 #include 
+#include

[PATCH] D96976: [analyzer] Fix reinterpret_cast handling for pointer-to-member

2021-02-26 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

@steakhal, you are absolutely right! It works. Thank you for pointing it out, 
not sure how I missed this earlier this evening.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96976

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


[PATCH] D97512: [clang] removes check against integral-to-pointer conversion...

2021-02-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:10320
+
+  const clang::CastKind Kind = Cast->getCastKind();
+  if (Kind == clang::CK_BitCast &&

We don't typically use top-level `const` on locals or params.



Comment at: clang/lib/Sema/SemaChecking.cpp:10326
+  !isa(
+  Cast->getSubExpr()->IgnoreImplicitAsWritten()->IgnoreParens()))
+return;

I'm not 100% certain, but would `IgnoreParenImpCasts()` be sufficient here? 
(`IgnoreImplicitAsWritten() seems to be a bit special -- the only use of it I 
can find in tree is for rewritten binary operator expressions.)



Comment at: clang/test/Analysis/free.cpp:221
+void t18b (S s) {
+  std::free((void*)(unsigned long long)s.p); // no warning
+}

I think it'd be useful to add tests for named casts as well as the C-style 
casts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97512

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


[PATCH] D97094: [Driver] Print process statistics report on CC_PRINT_PROC_STAT env variable.

2021-02-26 Thread Vlad Vereschaka via Phabricator via cfe-commits
vvereschaka updated this revision to Diff 326729.
vvereschaka added a comment.

Updated diff:

- updated doc parts

@aganea thanks a lot for your suggestions for doc improvements. I have updated 
it accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97094

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/cc-print-proc-stat.c
  clang/test/Driver/lit.local.cfg
  clang/tools/driver/driver.cpp

Index: clang/tools/driver/driver.cpp
===
--- clang/tools/driver/driver.cpp
+++ clang/tools/driver/driver.cpp
@@ -258,6 +258,11 @@
   TheDriver.CCLogDiagnostics = !!::getenv("CC_LOG_DIAGNOSTICS");
   if (TheDriver.CCLogDiagnostics)
 TheDriver.CCLogDiagnosticsFilename = ::getenv("CC_LOG_DIAGNOSTICS_FILE");
+
+  // Handle CC_PRINT_PROC_STAT and CC_PRINT_PROC_STAT_FILE.
+  TheDriver.CCPrintProcessStats = !!::getenv("CC_PRINT_PROC_STAT");
+  if (TheDriver.CCPrintProcessStats)
+TheDriver.CCPrintStatReportFilename = ::getenv("CC_PRINT_PROC_STAT_FILE");
 }
 
 static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,
Index: clang/test/Driver/lit.local.cfg
===
--- clang/test/Driver/lit.local.cfg
+++ clang/test/Driver/lit.local.cfg
@@ -11,7 +11,7 @@
  'IPHONEOS_DEPLOYMENT_TARGET',
  'SDKROOT', 'CCC_OVERRIDE_OPTIONS',
  'CC_PRINT_OPTIONS', 'CC_PRINT_HEADERS',
- 'CC_LOG_DIAGNOSTICS']
+ 'CC_LOG_DIAGNOSTICS', 'CC_PRINT_PROC_STAT']
 
 for name in driver_overwrite_env_vars:
   if name in config.environment:
Index: clang/test/Driver/cc-print-proc-stat.c
===
--- /dev/null
+++ clang/test/Driver/cc-print-proc-stat.c
@@ -0,0 +1,9 @@
+// RUN: env CC_PRINT_PROC_STAT=1 \
+// RUN: CC_PRINT_PROC_STAT_FILE=%t.csv \
+// RUN: %clang -no-canonical-prefixes -S -o %t.s %s
+// RUN: FileCheck --check-prefix=CHECK-CSV %s < %t.csv
+// CHECK-CSV: clang{{.*}},"{{.*}}.s",{{[0-9]+}},{{[0-9]+}},{{[0-9]+}}
+
+// RUN: env CC_PRINT_PROC_STAT=1 \
+// RUN: %clang -c -fintegrated-as %s | FileCheck %s
+// CHECK: clang{{.*}}: output={{.*}}.o, total={{[0-9.]+}} ms, user={{[0-9.]+}} ms, mem={{[0-9]+}} Kb
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -137,8 +137,9 @@
   ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT),
   DriverTitle(Title), CCPrintOptionsFilename(nullptr),
   CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr),
-  CCCPrintBindings(false), CCPrintOptions(false), CCPrintHeaders(false),
-  CCLogDiagnostics(false), CCGenDiagnostics(false),
+  CCPrintStatReportFilename(nullptr), CCCPrintBindings(false),
+  CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false),
+  CCGenDiagnostics(false), CCPrintProcessStats(false),
   TargetTriple(TargetTriple), CCCGenericGCCName(""), Saver(Alloc),
   CheckInputsExist(true), GenReproducer(false),
   SuppressMissingInputWarning(false) {
@@ -1096,6 +1097,15 @@
   GenReproducer = Args.hasFlag(options::OPT_gen_reproducer,
options::OPT_fno_crash_diagnostics,
!!::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH"));
+
+  // Process -fproc-stat-report options.
+  if (const Arg *A = Args.getLastArg(options::OPT_fproc_stat_report_EQ)) {
+CCPrintProcessStats = true;
+CCPrintStatReportFilename = A->getValue();
+  }
+  if (Args.hasArg(options::OPT_fproc_stat_report))
+CCPrintProcessStats = true;
+
   // FIXME: TargetTriple is used by the target-prefixed calls to as/ld
   // and getToolChain is const.
   if (IsCLMode()) {
@@ -4009,62 +4019,58 @@
/*TargetDeviceOffloadKind*/ Action::OFK_None);
   }
 
-  StringRef StatReportFile;
-  bool PrintProcessStat = false;
-  if (const Arg *A = C.getArgs().getLastArg(options::OPT_fproc_stat_report_EQ))
-StatReportFile = A->getValue();
-  if (C.getArgs().hasArg(options::OPT_fproc_stat_report))
-PrintProcessStat = true;
-
   // If we have more than one job, then disable integrated-cc1 for now. Do this
   // also when we need to report process execution statistics.
-  if (C.getJobs().size() > 1 || !StatReportFile.empty() || PrintProcessStat)
+  if (C.getJobs().size() > 1 || CCPrintProcessStats)
 for (auto &J : C.getJobs())
   J.InProcess = false;
 
-  if (!StatReportFile.empty() || PrintProcessStat) {
+  if (CCPrintProcessStats) {
 C.setPostCallback([=](const Command &Cmd, int Res) {
   Optional ProcStat =
   Cmd.getProcessStatistics();
   if (!ProcStat)
   

[PATCH] D96976: [analyzer] Fix reinterpret_cast handling for pointer-to-member

2021-02-26 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 326733.
RedDocMD added a comment.

Removed unnecessary includes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96976

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp

Index: clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp
===
--- clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp
+++ clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp
@@ -1,11 +1,11 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
-// XFAIL: asserts
 
 void clang_analyzer_eval(bool);
 
-// TODO: The following test will work properly once reinterpret_cast on pointer-to-member is handled properly
 namespace testReinterpretCasting {
-struct Base {
+struct BaseOfBase {};
+
+struct Base : public BaseOfBase {
   int field;
 };
 
@@ -15,12 +15,51 @@
 
 struct Some {};
 
-void f() {
+void analyzableCasts() {
   int DoubleDerived::*ddf = &Base::field;
   int Base::*bf = reinterpret_cast(reinterpret_cast(reinterpret_cast(ddf)));
-  int Some::*sf = reinterpret_cast(ddf);
   Base base;
   base.field = 13;
   clang_analyzer_eval(base.*bf == 13); // expected-warning{{TRUE}}
 }
+
+void castOutsideHierarchy() {
+  int DoubleDerived::*ddf = &Base::field;
+  int Some::*sf = reinterpret_cast(ddf);
+  Some some;
+  some.*sf = 14;
+  clang_analyzer_eval(some.*sf == 14); // expected-warning{{UNKNOWN}}
+}
+
+void castAbove() {
+  int DoubleDerived::*ddf = &Base::field;
+  int BaseOfBase::*bbf = reinterpret_cast(ddf);
+  BaseOfBase bb;
+  bb.*bbf = 23;
+  clang_analyzer_eval(bb.*bbf == 23); // expected-warning{{UNKNOWN}}
+}
+
+namespace testMultipleInheritance {
+struct A {};
+struct B : public A {};
+struct C {
+  int field;
+};
+struct D : public C {};
+struct E : public B, public D {};
+struct F : public E {};
+
+void testMultiple() {
+  int F::*f = &F::field;
+  int A::*a = reinterpret_cast(f);
+  int C::*c = reinterpret_cast(f);
+  A aobj;
+  C cobj;
+  aobj.*a = 13;
+  cobj.*c = 29;
+  clang_analyzer_eval(aobj.*a == 13); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(cobj.*c == 29); // expected-warning{{TRUE}}
+}
+} // namespace testMultipleInheritance
+
 } // namespace testReinterpretCasting
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -522,8 +522,7 @@
 continue;
   }
   case CK_DerivedToBaseMemberPointer:
-  case CK_BaseToDerivedMemberPointer:
-  case CK_ReinterpretMemberPointer: {
+  case CK_BaseToDerivedMemberPointer: {
 SVal V = state->getSVal(Ex, LCtx);
 if (auto PTMSV = V.getAs()) {
   SVal CastedPTMSV =
@@ -537,6 +536,25 @@
 state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
 continue;
   }
+  case CK_ReinterpretMemberPointer: {
+SVal V = state->getSVal(Ex, LCtx);
+if (auto PTMSV = V.getAs()) {
+  if (const auto *ReinterpretE =
+  llvm::dyn_cast(CastE)) {
+if (const PointerToMemberData *Data =
+getBasicVals().basesForReinterpretCast(ReinterpretE,
+   *PTMSV)) {
+  SVal CastedPTMSV = svalBuilder.makePointerToMember(Data);
+  state = state->BindExpr(CastE, LCtx, CastedPTMSV);
+  Bldr.generateNode(CastE, Pred, state);
+  continue;
+}
+  }
+}
+// Explicitly proceed with default handler for this case cascade.
+state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
+continue;
+  }
   // Various C++ casts that are not handled yet.
   case CK_ToUnion:
   case CK_VectorSplat: {
Index: clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
===
--- clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
+++ clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h"
+#include "clang/AST/CXXInheritance.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
@@ -22,6 +23,7 @@
 #include "llvm/ADT/ImmutableList.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
 #include 
 #include 
 #include 
@@ -239,13 +241,9

[PATCH] D97563: [clang-tidy] Enable modernize-concat-nested-namespaces also on headers

2021-02-26 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 326734.
DmitryPolukhin added a comment.

Comments resolved


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97563

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
  
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
@@ -1,4 +1,12 @@
-// RUN: %check_clang_tidy -std=c++17-or-later %s 
modernize-concat-nested-namespaces %t
+// RUN: cp 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 %T/modernize-concat-nested-namespaces.h
+// RUN: %check_clang_tidy -std=c++17 %s modernize-concat-nested-namespaces %t 
-- -header-filter=".*" -- -I %T
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 -check-prefix=CHECK-FIXES
+// Restore header file and re-run with c++20:
+// RUN: cp 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 %T/modernize-concat-nested-namespaces.h
+// RUN: %check_clang_tidy -std=c++20 %s modernize-concat-nested-namespaces %t 
-- -header-filter=".*" -- -I %T
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 -check-prefix=CHECK-FIXES
+
+#include "modernize-concat-nested-namespaces.h"
 
 namespace n1 {}
 
@@ -159,3 +167,5 @@
 
   return 0;
 }
+
+// CHECK-MESSAGES: modernize-concat-nested-namespaces.h:1:1: warning: nested 
namespaces can be concatenated [modernize-concat-nested-namespaces]
Index: 
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
@@ -0,0 +1,8 @@
+namespace nn1 {
+namespace nn2 {
+// CHECK-FIXES: namespace nn1::nn2
+void t();
+} // namespace nn2
+} // namespace nn1
+// CHECK-FIXES: void t();
+// CHECK-FIXES-NEXT: } // namespace nn1
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -82,9 +82,6 @@
   if (!locationsInSameFile(Sources, ND.getBeginLoc(), ND.getRBraceLoc()))
 return;
 
-  if (!Sources.isInMainFile(ND.getBeginLoc()))
-return;
-
   if (anonymousOrInlineNamespace(ND))
 return;
 


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
@@ -1,4 +1,12 @@
-// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-concat-nested-namespaces %t
+// RUN: cp %S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
+// RUN: %check_clang_tidy -std=c++17 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
+// Restore header file and re-run with c++20:
+// RUN: cp %S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
+// RUN: %check_clang_tidy -std=c++20 %s modernize-concat-nested-namespaces %t -- -header-filter=".*" -- -I %T
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h %S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES
+
+#include "modernize-concat-nested-namespaces.h"
 
 namespace n1 {}
 
@@ -159,3 +167,5 @@
 
   return 0;
 }
+
+// CHECK-MESSAGES: modernize-concat-nested-namespaces.h:1:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
===
--- /dev/n

[PATCH] D97544: [clang-tidy] Remove some test c++ mode restrictions.

2021-02-26 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!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97544

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


[PATCH] D97563: [clang-tidy] Enable modernize-concat-nested-namespaces also on headers

2021-02-26 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin marked an inline comment as done.
DmitryPolukhin added a comment.

@njames93 thank you for quick response and good suggestion!




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp:4
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 -check-prefix=CHECK-FIXES
+// Restore header file and re-run with c++2b:
+// RUN: cp 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 %T/modernize-concat-nested-namespaces.h

njames93 wrote:
> Why do we explicitly run on c++2b and not c++20? I understand there is no 
> framework in place for using -std=c++17-or-later when header files are 
> modified.
There is no good reason, I just took highest current version. Changed to c++20.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97563

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-02-26 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD marked an inline comment as done.
RedDocMD added a comment.

In D97183#2589445 , @NoQ wrote:

> Nice!
>
> I suspect you're adding too many notes. The note needs to not be there if the 
> *raw* pointer is not tracked. Eg., I suspect that your patch would add a note 
> in the following case in which it shouldn't be there because the raw pointer 
> value doesn't participate in the report despite smart pointer region being 
> interesting:
>
>   std::unique_ptr P;
>   A *a = P.get(); // shound't emit a note here
>   P->foo();
>
> It's important to not emit redundant notes because users typically take these 
> checker-specific notes as an indication that this information is an essential 
> piece of evidence of the bug in their program. In this example they'd believe 
> that the analyzer has figured out that the smart pointer is null by looking 
> at what happens to the raw pointer value. So they may become very confused if 
> this isn't the case.

@NoQ, in the example you have given, isn't the smart-pointer `P` null? So 
shouldn't a warning be emitted for de-referencing it? Or is it that since `a` 
is not being used, a warning shouldn't be emitted? Sorry, I could not quite 
understand that point ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[PATCH] D97411: [DebugInfo] Add an attribute to force type info to be emitted for types that are required to be complete.

2021-02-26 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 326738.
akhuang marked an inline comment as done.
akhuang added a comment.

-Add documentation
-Add more test cases and semantics tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97411

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/standalone-debug-attribute.cpp
  clang/test/Sema/attr-standalonedebug.cpp

Index: clang/test/Sema/attr-standalonedebug.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-standalonedebug.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -DCPP
+// RUN: %clang_cc1 %s -verify -fsyntax-only -x c
+
+#ifdef CPP
+int a __attribute__((standalone_debug)); // expected-warning {{'standalone_debug' attribute only applies to classes}}
+
+void __attribute__((standalone_debug)) b(); // expected-warning {{'standalone_debug' attribute only applies to classes}}
+
+struct __attribute__((standalone_debug(1))) c {}; // expected-error {{'standalone_debug' attribute takes no arguments}}
+
+#else
+// Check that attribute only works in C++.
+struct __attribute__((standalone_debug)) a {}; // expected-warning {{'standalone_debug' attribute ignored}}
+#endif
Index: clang/test/CodeGenCXX/standalone-debug-attribute.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/standalone-debug-attribute.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -DSETATTR=0 -triple x86_64-unknown-linux-gnu -emit-llvm -debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=DEBUG
+// RUN: %clang_cc1 -DSETATTR=1 -triple x86_64-unknown-linux-gnu -emit-llvm -debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=WITHATTR
+// Use -debug-info-kind=constructor because it includes all the optimizations.
+
+#if SETATTR
+#define STANDALONEDEBUGATTR __attribute__((standalone_debug))
+#else
+#define STANDALONEDEBUGATTR
+#endif
+
+struct STANDALONEDEBUGATTR StructWithConstructor {
+  StructWithConstructor() {}
+};
+void f(StructWithConstructor s) {}
+// DEBUG:  !DICompositeType({{.*}}name: "StructWithConstructor"
+// DEBUG-SAME:  flags: {{.*}}DIFlagFwdDecl
+// WITHATTR: !DICompositeType({{.*}}name: "StructWithConstructor"
+// WITHATTR-NOT: DIFlagFwdDecl
+
+union STANDALONEDEBUGATTR UnionWithConstructor {
+  UnionWithConstructor() {}
+};
+void f(UnionWithConstructor u) {}
+// DEBUG:  !DICompositeType({{.*}}name: "UnionWithConstructor"
+// DEBUG-SAME:  flags: {{.*}}DIFlagFwdDecl
+// WITHATTR: !DICompositeType({{.*}}name: "UnionWithConstructor"
+// WITHATTR-NOT: DIFlagFwdDecl
+
+template  struct ExternTemplate {
+  ExternTemplate() {}
+  T x;
+};
+extern template struct STANDALONEDEBUGATTR ExternTemplate;
+void f(ExternTemplate s) {}
+// DEBUG: !DICompositeType({{.*}}name: "ExternTemplate"
+// DEBUG-SAME: flags: {{.*}}DIFlagFwdDecl
+// WITHATTR: !DICompositeType({{.*}}name: "ExternTemplate"
+// WITHATTR-NOT: DIFlagFwdDecl
+
+struct STANDALONEDEBUGATTR CompleteTypeRequired {};
+void f(CompleteTypeRequired &s) {}
+// DEBUG: !DICompositeType({{.*}}name: "CompleteTypeRequired"
+// DEBUG-SAME: flags: {{.*}}DIFlagFwdDecl
+// WITHATTR: !DICompositeType({{.*}}name: "CompleteTypeRequired"
+// WITHATTR-NOT: DIFlagFwdDecl
+
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2385,7 +2385,8 @@
   if (DebugKind == codegenoptions::DebugLineTablesOnly)
 return true;
 
-  if (DebugKind > codegenoptions::LimitedDebugInfo)
+  if (DebugKind > codegenoptions::LimitedDebugInfo ||
+  RD->hasAttr())
 return false;
 
   if (!LangOpts.CPlusPlus)
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -1053,6 +1053,16 @@
   }];
 }
 
+def StandaloneDebugDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The ``standalone_debug`` attribute causes debug info to be emitted for a record
+type regardless of the debug info optimizations that are enabled with
+-fno-standalone-debug. This attribute only has an effect when debug info
+optimizations are enabled (e.g. with -fno-standalone-debug), and is C++-only.
+  }];
+}
+
 def NoDuplicateDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1660,6 +1660,14 @@
   let Documentation = [NoDebugDocs];
 }
 
+def StandaloneDebug : InheritableAttr {
+  let Spellings = [Clang<"standalone_debug">];
+  let 

[PATCH] D97447: Add GNU attribute 'retain'

2021-02-26 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I have performed a large-scale internal test. I don't find any problem with a 
toolchain built with D97446 /D97447 
/D97448 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97447

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


[PATCH] D97566: [WIP][RGT] Rotten Green Test checking for LLVM and Clang unittests

2021-02-26 Thread Paul Robinson via Phabricator via cfe-commits
probinson created this revision.
probinson added reviewers: MaskRay, dblaikie.
Herald added a subscriber: mgrang.
probinson requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

This is an enhancement of the 'googletest' support code, to report
test assertions (EXPECT_* and ASSERT_* macros) that are not executed.
An un-executed assertion looks like it tests something, and passes (so
is "green") but actually does nothing (so is "rotten").

Due to the number of false positives (for example, all DISABLED tests
will be reported as rotten), running the unittests under lit will
*not* report rotten tests; however, running a unittest program
manually (not under lit) will report these by default.

The RGT support has been tried on Linux using both Clang and GCC as
build compilers, and on Windows with MSVC.  MachO has not been tried.

The intent is to clean up more of the false positives before seeking
to commit the RGT support.  Some of this work has been done already.

This is a Work-In-Progress, not ready for final review, but it seems
mature enough to present to the community in its current form.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97566

Files:
  clang/test/Unit/lit.cfg.py
  clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
  clang/unittests/Tooling/Syntax/MutationsTest.cpp
  llvm/test/Unit/lit.cfg.py
  llvm/unittests/Support/ProgramTest.cpp
  llvm/utils/unittest/googletest/include/gtest/gtest.h
  llvm/utils/unittest/googletest/include/gtest/gtest_pred_impl.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-internal.h
  llvm/utils/unittest/googletest/include/gtest/internal/rgt.h
  llvm/utils/unittest/googletest/src/gtest-all.cc
  llvm/utils/unittest/googletest/src/gtest-internal-inl.h
  llvm/utils/unittest/googletest/src/gtest.cc
  llvm/utils/unittest/googletest/src/rgt.cc

Index: llvm/utils/unittest/googletest/src/rgt.cc
===
--- /dev/null
+++ llvm/utils/unittest/googletest/src/rgt.cc
@@ -0,0 +1,236 @@
+//===- rgt.cc - Rotten Green Test support -===//
+//
+// 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
+//
+//===--===//
+//
+// Support for the Rotten Green Test extension to LLVM's copy of the
+// googletest framework.
+
+#include "gtest/internal/rgt.h"
+#include 
+#include 
+#include 
+#include 
+
+// When we can't get pure static initialization of the array of items
+// describing test points, they get registered on startup and we keep
+// pointers to the data in this vector.
+
+#if GTEST_RGT_RUNTIME_INIT_
+
+namespace {
+
+using item_vector = std::vector;
+class RegisteredItems {
+  static item_vector *items;
+public:
+  RegisteredItems() = default;
+  item_vector *getItems() {
+if (!items)
+  items = new item_vector;
+return items;
+  }
+  int size() { return getItems()->size(); }
+  bool empty() { return getItems()->empty(); }
+  auto begin() { return getItems()->begin(); }
+  auto end() { return getItems()->end(); }
+  void push_back(testing::internal::RGT_item *item) {
+getItems()->push_back(item);
+  }
+};
+
+RegisteredItems registered_items;
+item_vector *RegisteredItems::items = nullptr;
+
+} // end anonymous namespace
+
+void testing::internal::RGT_record(testing::internal::RGT_item *item) {
+  registered_items.push_back(item);
+}
+
+#if GTEST_RGT_RUNTIME_INIT_MANUAL_
+// On Windows we have to allocate our own placeholder start/stop data items.
+// The linker will sort these into the right order relative to real data.
+// Because the section concatenation might be padded, we'll have to skip over
+// any items with a null file pointer, so make the first item look like it's
+// padding.
+
+#define START_SECTION_NAME GTEST_RGT_SECTION_NAME_WITH_SUFFIX_($a)
+#define STOP_SECTION_NAME GTEST_RGT_SECTION_NAME_WITH_SUFFIX_($z)
+
+#pragma section (START_SECTION_NAME,read,write)
+__declspec(allocate(START_SECTION_NAME))
+RGT_recorder RGT_manual_init_start = (RGT_recorder)1;
+
+#pragma section (STOP_SECTION_NAME,read,write)
+__declspec(allocate(STOP_SECTION_NAME))
+RGT_recorder RGT_manual_init_stop = (RGT_recorder)1;
+
+void testing::internal::RGT_init_manual() {
+  const RGT_recorder *F = &RGT_manual_init_start;
+  int call_count = 0;
+  int null_count = 0;
+  for (++F; F < &RGT_manual_init_stop; ++F) {
+if (*F) {
+  ++call_count;
+  (*F)();
+} else {
+  ++null_count;
+}
+  }
+  printf("RGT_init_manual: %d called, %d null\n", call_count, null_count);
+}
+
+#endif // GTEST_RGT_RUNTIME_INIT_MANUAL_
+#endif // GTEST_RGT_RUNTIME_INIT_
+
+// In order to deduplicate information due to template instantiations,
+// we combine all raw reports for the same sourc

[PATCH] D97553: [clang][NFC] pack StaticDiagInfoRec

2021-02-26 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!




Comment at: clang/lib/Basic/DiagnosticIDs.cpp:171
 const StaticDiagInfoRec StaticDiagInfo[] = {
+// clang-format off
 #define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, 
\

FWIW, I'd personally prefer to remove the `clang-format on` comment below. I'm 
not keen on littering the code base with workarounds for clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97553

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


[PATCH] D97446: Change some addUsedGlobal to addUsedOrCompilerUsedGlobal

2021-02-26 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 326739.
MaskRay added a comment.

Simplify with `CodeGenModule::getTriple()`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97446

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/2005-12-04-AttributeUsed.c
  clang/test/CodeGen/attr-msp430.c
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/attr-used.c
  clang/test/CodeGen/attr-x86-interrupt.c
  clang/test/CodeGen/keep-static-consts.cpp
  clang/test/CodeGenCUDA/llvm-used.cu
  clang/test/CodeGenCXX/attr-x86-interrupt.cpp
  clang/test/CodeGenCXX/extern-c.cpp

Index: clang/test/CodeGenCXX/extern-c.cpp
===
--- clang/test/CodeGenCXX/extern-c.cpp
+++ clang/test/CodeGenCXX/extern-c.cpp
@@ -70,7 +70,7 @@
 __attribute__((used)) static int duplicate_internal_fn() { return 0; }
   }
 
-  // CHECK: @llvm.used = appending global {{.*}} @internal_var {{.*}} @internal_fn 
+  // CHECK: @llvm.compiler.used = appending global {{.*}} @internal_var {{.*}} @internal_fn
 
   // CHECK-NOT: @unused
   // CHECK-NOT: @duplicate_internal
Index: clang/test/CodeGenCXX/attr-x86-interrupt.cpp
===
--- clang/test/CodeGenCXX/attr-x86-interrupt.cpp
+++ clang/test/CodeGenCXX/attr-x86-interrupt.cpp
@@ -17,11 +17,11 @@
 struct St {
 static void foo9(int *a) __attribute__((interrupt)) {}
 };
-// X86_64_LINUX: @llvm.used = appending global [3 x i8*] [i8* bitcast (void (i32*, i64)* @{{.*}}foo7{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo8{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo9{{.*}} to i8*)], section "llvm.metadata"
+// X86_64_LINUX: @llvm.compiler.used = appending global [3 x i8*] [i8* bitcast (void (i32*, i64)* @{{.*}}foo7{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo8{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo9{{.*}} to i8*)], section "llvm.metadata"
 // X86_64_LINUX: define{{.*}} x86_intrcc void @{{.*}}foo7{{.*}}(i32* byval(i32) %{{.+}}, i64 %{{.+}})
 // X86_64_LINUX: define{{.*}} x86_intrcc void @{{.*}}foo8{{.*}}(i32* byval(i32) %{{.+}})
 // X86_64_LINUX: define linkonce_odr x86_intrcc void @{{.*}}foo9{{.*}}(i32* byval(i32) %{{.+}})
-// X86_LINUX: @llvm.used = appending global [3 x i8*] [i8* bitcast (void (i32*, i32)* @{{.*}}foo7{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo8{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo9{{.*}} to i8*)], section "llvm.metadata"
+// X86_LINUX: @llvm.compiler.used = appending global [3 x i8*] [i8* bitcast (void (i32*, i32)* @{{.*}}foo7{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo8{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo9{{.*}} to i8*)], section "llvm.metadata"
 // X86_LINUX: define{{.*}} x86_intrcc void @{{.*}}foo7{{.*}}(i32* byval(i32) %{{.+}}, i32 %{{.+}})
 // X86_LINUX: define{{.*}} x86_intrcc void @{{.*}}foo8{{.*}}(i32* byval(i32) %{{.+}})
 // X86_LINUX: define linkonce_odr x86_intrcc void @{{.*}}foo9{{.*}}(i32* byval(i32) %{{.+}})
Index: clang/test/CodeGenCUDA/llvm-used.cu
===
--- clang/test/CodeGenCUDA/llvm-used.cu
+++ clang/test/CodeGenCUDA/llvm-used.cu
@@ -4,5 +4,5 @@
 // Make sure we emit the proper addrspacecast for llvm.used.  PR22383 exposed an
 // issue where we were generating a bitcast instead of an addrspacecast.
 
-// CHECK: @llvm.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(1)* bitcast ([0 x i32] addrspace(1)* @a to i8 addrspace(1)*) to i8*)], section "llvm.metadata"
+// CHECK: @llvm.compiler.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(1)* bitcast ([0 x i32] addrspace(1)* @a to i8 addrspace(1)*) to i8*)], section "llvm.metadata"
 __attribute__((device)) __attribute__((__used__)) int a[] = {};
Index: clang/test/CodeGen/keep-static-consts.cpp
===
--- clang/test/CodeGen/keep-static-consts.cpp
+++ clang/test/CodeGen/keep-static-consts.cpp
@@ -3,7 +3,7 @@
 // CHECK: @_ZL7srcvers = internal constant [4 x i8] c"xyz\00", align 1
 // CHECK: @_ZL8srcvers2 = internal constant [4 x i8] c"abc\00", align 1
 // CHECK: @_ZL1N = internal constant i32 2, align 4
-// CHECK: @llvm.used = appending global [4 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @_ZL7srcvers, i32 0, i32 0), i8* bitcast (i32* @b to i8*), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @_ZL8srcvers2, i32 0, i32 0), i8* bitcast (i32* @_ZL1N to i8*)], section "llvm.metadata"
+// CHECK: @llvm.compiler.used = appending global [4 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @_ZL7srcvers, i32 0, i32 0), i8* bitcast (i32* @b to i8*), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @_ZL8srcvers2, i32 0, i32 0), i8* bitcast (i32* @_ZL1N to i8*)], section "llvm.metadata"
 
 static const char srcvers[] 

[clang] 28cb620 - Change some addUsedGlobal to addUsedOrCompilerUsedGlobal

2021-02-26 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-02-26T10:42:07-08:00
New Revision: 28cb620321f5461255423f84c85e6891b5174c13

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

LOG: Change some addUsedGlobal to addUsedOrCompilerUsedGlobal

An global value in the `llvm.used` list does not have GC root semantics on ELF 
targets.
This will be changed in a subsequent backend patch.

Change some `llvm.used` in the ELF code path to use `llvm.compiler.used` to
prevent undesired GC root semantics.

Change one extern "C" alias (due to `__attribute__((used))` in extern "C") to 
use `llvm.compiler.used` on all targets.

GNU ld has a rule "`__start_/__stop_` references from a live input section 
retain the associated C identifier name sections",
which LLD may drop entirely (currently refined to exclude 
SHF_LINK_ORDER/SHF_GROUP) in a future release (the rule makes it clumsy to GC 
metadata sections; D96914 added a way to try the potential future behavior).
For `llvm.used` global values defined in a C identifier name section, keep 
using `llvm.used` so that
the future LLD change will not affect them.

rnk kindly categorized the changes:
```
ObjC/blocks: this wants GC root semantics, since ObjC mainly runs on Mac.
MS C++ ABI stuff: wants GC root semantics, no change
OpenMP: unsure, but GC root semantics probably don't hurt
CodeGenModule: affected in this patch to *not* use GC root semantics so that 
__attribute__((used)) behavior remains the same on ELF, plus two other minor 
use cases that don't want GC semantics
Coverage: Probably want GC root semantics
CGExpr.cpp: refers to LTO, wants GC root
CGDeclCXX.cpp: one is MS ABI specific, so yes GC root, one is some other C++ 
init functionality, which should form GC roots (C++ initializers can have side 
effects and must run)
CGDecl.cpp: Changed in this patch for __attribute__((used))
```

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

Added: 


Modified: 
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGen/2005-12-04-AttributeUsed.c
clang/test/CodeGen/attr-msp430.c
clang/test/CodeGen/attr-target-mv.c
clang/test/CodeGen/attr-used.c
clang/test/CodeGen/attr-x86-interrupt.c
clang/test/CodeGen/keep-static-consts.cpp
clang/test/CodeGenCUDA/llvm-used.cu
clang/test/CodeGenCXX/attr-x86-interrupt.cpp
clang/test/CodeGenCXX/extern-c.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index a01638f0b67b..ecf79dbbaffc 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -442,7 +442,7 @@ void CodeGenFunction::EmitStaticVarDecl(const VarDecl &D,
 var->setSection(SA->getName());
 
   if (D.hasAttr())
-CGM.addUsedGlobal(var);
+CGM.addUsedOrCompilerUsedGlobal(var);
 
   // We may have to cast the constant because of the initializer
   // mismatch above.

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 9dcdc8da4d92..564b07582376 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1820,13 +1820,13 @@ void CodeGenModule::SetCommonAttributes(GlobalDecl GD, 
llvm::GlobalValue *GV) {
 GV->setVisibility(llvm::GlobalValue::DefaultVisibility);
 
   if (D && D->hasAttr())
-addUsedGlobal(GV);
+addUsedOrCompilerUsedGlobal(GV);
 
   if (CodeGenOpts.KeepStaticConsts && D && isa(D)) {
 const auto *VD = cast(D);
 if (VD->getType().isConstQualified() &&
 VD->getStorageDuration() == SD_Static)
-  addUsedGlobal(GV);
+  addUsedOrCompilerUsedGlobal(GV);
   }
 }
 
@@ -2087,6 +2087,15 @@ void 
CodeGenModule::addCompilerUsedGlobal(llvm::GlobalValue *GV) {
   LLVMCompilerUsed.emplace_back(GV);
 }
 
+void CodeGenModule::addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV) {
+  assert((isa(GV) || !GV->isDeclaration()) &&
+ "Only globals with definition can force usage.");
+  if (getTriple().isOSBinFormatELF())
+LLVMCompilerUsed.emplace_back(GV);
+  else
+LLVMUsed.emplace_back(GV);
+}
+
 static void emitUsed(CodeGenModule &CGM, StringRef Name,
  std::vector &List) {
   // Don't create llvm.used if there is no need.
@@ -5912,7 +5921,7 @@ void CodeGenModule::EmitStaticExternCAliases() {
 IdentifierInfo *Name = I.first;
 llvm::GlobalValue *Val = I.second;
 if (Val && !getModule().getNamedValue(Name->getName()))
-  addUsedGlobal(llvm::GlobalAlias::create(Name->getName(), Val));
+  addCompilerUsedGlobal(llvm::GlobalAlias::create(Name->getName(), Val));
   }
 }
 

diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index 49f94042a787..d495a169b609 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/C

[PATCH] D97446: Change some addUsedGlobal to addUsedOrCompilerUsedGlobal

2021-02-26 Thread Fangrui Song 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 rG28cb620321f5: Change some addUsedGlobal to 
addUsedOrCompilerUsedGlobal (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97446

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/2005-12-04-AttributeUsed.c
  clang/test/CodeGen/attr-msp430.c
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/attr-used.c
  clang/test/CodeGen/attr-x86-interrupt.c
  clang/test/CodeGen/keep-static-consts.cpp
  clang/test/CodeGenCUDA/llvm-used.cu
  clang/test/CodeGenCXX/attr-x86-interrupt.cpp
  clang/test/CodeGenCXX/extern-c.cpp

Index: clang/test/CodeGenCXX/extern-c.cpp
===
--- clang/test/CodeGenCXX/extern-c.cpp
+++ clang/test/CodeGenCXX/extern-c.cpp
@@ -70,7 +70,7 @@
 __attribute__((used)) static int duplicate_internal_fn() { return 0; }
   }
 
-  // CHECK: @llvm.used = appending global {{.*}} @internal_var {{.*}} @internal_fn 
+  // CHECK: @llvm.compiler.used = appending global {{.*}} @internal_var {{.*}} @internal_fn
 
   // CHECK-NOT: @unused
   // CHECK-NOT: @duplicate_internal
Index: clang/test/CodeGenCXX/attr-x86-interrupt.cpp
===
--- clang/test/CodeGenCXX/attr-x86-interrupt.cpp
+++ clang/test/CodeGenCXX/attr-x86-interrupt.cpp
@@ -17,11 +17,11 @@
 struct St {
 static void foo9(int *a) __attribute__((interrupt)) {}
 };
-// X86_64_LINUX: @llvm.used = appending global [3 x i8*] [i8* bitcast (void (i32*, i64)* @{{.*}}foo7{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo8{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo9{{.*}} to i8*)], section "llvm.metadata"
+// X86_64_LINUX: @llvm.compiler.used = appending global [3 x i8*] [i8* bitcast (void (i32*, i64)* @{{.*}}foo7{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo8{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo9{{.*}} to i8*)], section "llvm.metadata"
 // X86_64_LINUX: define{{.*}} x86_intrcc void @{{.*}}foo7{{.*}}(i32* byval(i32) %{{.+}}, i64 %{{.+}})
 // X86_64_LINUX: define{{.*}} x86_intrcc void @{{.*}}foo8{{.*}}(i32* byval(i32) %{{.+}})
 // X86_64_LINUX: define linkonce_odr x86_intrcc void @{{.*}}foo9{{.*}}(i32* byval(i32) %{{.+}})
-// X86_LINUX: @llvm.used = appending global [3 x i8*] [i8* bitcast (void (i32*, i32)* @{{.*}}foo7{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo8{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo9{{.*}} to i8*)], section "llvm.metadata"
+// X86_LINUX: @llvm.compiler.used = appending global [3 x i8*] [i8* bitcast (void (i32*, i32)* @{{.*}}foo7{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo8{{.*}} to i8*), i8* bitcast (void (i32*)* @{{.*}}foo9{{.*}} to i8*)], section "llvm.metadata"
 // X86_LINUX: define{{.*}} x86_intrcc void @{{.*}}foo7{{.*}}(i32* byval(i32) %{{.+}}, i32 %{{.+}})
 // X86_LINUX: define{{.*}} x86_intrcc void @{{.*}}foo8{{.*}}(i32* byval(i32) %{{.+}})
 // X86_LINUX: define linkonce_odr x86_intrcc void @{{.*}}foo9{{.*}}(i32* byval(i32) %{{.+}})
Index: clang/test/CodeGenCUDA/llvm-used.cu
===
--- clang/test/CodeGenCUDA/llvm-used.cu
+++ clang/test/CodeGenCUDA/llvm-used.cu
@@ -4,5 +4,5 @@
 // Make sure we emit the proper addrspacecast for llvm.used.  PR22383 exposed an
 // issue where we were generating a bitcast instead of an addrspacecast.
 
-// CHECK: @llvm.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(1)* bitcast ([0 x i32] addrspace(1)* @a to i8 addrspace(1)*) to i8*)], section "llvm.metadata"
+// CHECK: @llvm.compiler.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(1)* bitcast ([0 x i32] addrspace(1)* @a to i8 addrspace(1)*) to i8*)], section "llvm.metadata"
 __attribute__((device)) __attribute__((__used__)) int a[] = {};
Index: clang/test/CodeGen/keep-static-consts.cpp
===
--- clang/test/CodeGen/keep-static-consts.cpp
+++ clang/test/CodeGen/keep-static-consts.cpp
@@ -3,7 +3,7 @@
 // CHECK: @_ZL7srcvers = internal constant [4 x i8] c"xyz\00", align 1
 // CHECK: @_ZL8srcvers2 = internal constant [4 x i8] c"abc\00", align 1
 // CHECK: @_ZL1N = internal constant i32 2, align 4
-// CHECK: @llvm.used = appending global [4 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @_ZL7srcvers, i32 0, i32 0), i8* bitcast (i32* @b to i8*), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @_ZL8srcvers2, i32 0, i32 0), i8* bitcast (i32* @_ZL1N to i8*)], section "llvm.metadata"
+// CHECK: @llvm.compiler.used = appending global [4 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @_ZL7srcvers, i32 0, i32 0), i8* bitcast (i32* @b to i8*), i8* getelementptr inbounds ([4 x i8], [4

[PATCH] D97488: [clang-tidy][NFC] Tweak some generation of diag messages

2021-02-26 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! Thanks, these are really nice cleanups!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97488

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


[PATCH] D97512: [clang] removes check against integral-to-pointer conversion...

2021-02-26 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 326742.
cjdb marked 2 inline comments as done.
cjdb added a comment.

applies comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97512

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Analysis/free.c
  clang/test/Analysis/free.cpp


Index: clang/test/Analysis/free.cpp
===
--- clang/test/Analysis/free.cpp
+++ clang/test/Analysis/free.cpp
@@ -208,3 +208,39 @@
   // Unknown value
   std::free(x[offset]); // no-warning
 }
+
+struct S {
+  const char* p;
+};
+
+void t18_C_style_C_style_free (S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18_C_style_C_style_std_free (S s) {
+  std::free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18_C_style_reinterpret_free (S s) {
+  free((void*)reinterpret_cast(s.p)); // no warning
+}
+
+void t18_C_style_reinterpret_std_free (S s) {
+  std::free((void*)reinterpret_cast(s.p)); // no warning
+}
+
+void t18_reinterpret_C_style_free (S s) {
+  free(reinterpret_cast((unsigned long long)(s.p))); // no warning
+}
+
+void t18_reinterpret_C_style_std_free (S s) {
+  std::free(reinterpret_cast((unsigned long long)(s.p))); // no warning
+}
+
+void t18_reinterpret_reinterpret_free (S s) {
+  free(reinterpret_cast(reinterpret_cast(s.p))); // 
no warning
+}
+
+void t18_reinterpret_reinterpret_std_free (S s) {
+  std::free(reinterpret_cast(reinterpret_cast(s.p))); // no warning
+}
Index: clang/test/Analysis/free.c
===
--- clang/test/Analysis/free.c
+++ clang/test/Analysis/free.c
@@ -108,3 +108,11 @@
   // expected-warning@-1{{Argument to free() is the address of the function 
'iptr', which is not memory allocated by malloc()}}
   // expected-warning@-2{{attempt to call free on non-heap object 'iptr'}}
 }
+
+struct S {
+  const char* p;
+};
+
+void t18 (struct S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10316,11 +10316,18 @@
 const CastExpr *Cast) {
   SmallString<128> SizeString;
   llvm::raw_svector_ostream OS(SizeString);
+
+  clang::CastKind Kind = Cast->getCastKind();
+  if (Kind == clang::CK_BitCast &&
+  !Cast->getSubExpr()->getType()->isFunctionPointerType())
+return;
+  if (Kind == clang::CK_IntegralToPointer &&
+  !isa(
+  Cast->getSubExpr()->IgnoreImplicitAsWritten()->IgnoreParens()))
+return;
+
   switch (Cast->getCastKind()) {
   case clang::CK_BitCast:
-if (!Cast->getSubExpr()->getType()->isFunctionPointerType())
-  return;
-LLVM_FALLTHROUGH;
   case clang::CK_IntegralToPointer:
   case clang::CK_FunctionToPointerDecay:
 OS << '\'';


Index: clang/test/Analysis/free.cpp
===
--- clang/test/Analysis/free.cpp
+++ clang/test/Analysis/free.cpp
@@ -208,3 +208,39 @@
   // Unknown value
   std::free(x[offset]); // no-warning
 }
+
+struct S {
+  const char* p;
+};
+
+void t18_C_style_C_style_free (S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18_C_style_C_style_std_free (S s) {
+  std::free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18_C_style_reinterpret_free (S s) {
+  free((void*)reinterpret_cast(s.p)); // no warning
+}
+
+void t18_C_style_reinterpret_std_free (S s) {
+  std::free((void*)reinterpret_cast(s.p)); // no warning
+}
+
+void t18_reinterpret_C_style_free (S s) {
+  free(reinterpret_cast((unsigned long long)(s.p))); // no warning
+}
+
+void t18_reinterpret_C_style_std_free (S s) {
+  std::free(reinterpret_cast((unsigned long long)(s.p))); // no warning
+}
+
+void t18_reinterpret_reinterpret_free (S s) {
+  free(reinterpret_cast(reinterpret_cast(s.p))); // no warning
+}
+
+void t18_reinterpret_reinterpret_std_free (S s) {
+  std::free(reinterpret_cast(reinterpret_cast(s.p))); // no warning
+}
Index: clang/test/Analysis/free.c
===
--- clang/test/Analysis/free.c
+++ clang/test/Analysis/free.c
@@ -108,3 +108,11 @@
   // expected-warning@-1{{Argument to free() is the address of the function 'iptr', which is not memory allocated by malloc()}}
   // expected-warning@-2{{attempt to call free on non-heap object 'iptr'}}
 }
+
+struct S {
+  const char* p;
+};
+
+void t18 (struct S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10316,11 +10316,18 @@
 const CastExpr *Cast) {
   SmallString<128> SizeString;
   llvm::raw_svector_ostrea

[PATCH] D97512: [clang] removes check against integral-to-pointer conversion...

2021-02-26 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a subscriber: rsmith.
cjdb added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:10320
+
+  const clang::CastKind Kind = Cast->getCastKind();
+  if (Kind == clang::CK_BitCast &&

aaron.ballman wrote:
> We don't typically use top-level `const` on locals or params.
This makes Christopher sad :(



Comment at: clang/lib/Sema/SemaChecking.cpp:10326
+  !isa(
+  Cast->getSubExpr()->IgnoreImplicitAsWritten()->IgnoreParens()))
+return;

aaron.ballman wrote:
> I'm not 100% certain, but would `IgnoreParenImpCasts()` be sufficient here? 
> (`IgnoreImplicitAsWritten() seems to be a bit special -- the only use of it I 
> can find in tree is for rewritten binary operator expressions.)
@rsmith would you mind weighing in here please? My original use-case for 
`IgnoreImplicitAsWritten` might be different to here and I don't have an answer 
for @aaron.ballman.



Comment at: clang/test/Analysis/free.cpp:221
+void t18b (S s) {
+  std::free((void*)(unsigned long long)s.p); // no warning
+}

aaron.ballman wrote:
> I think it'd be useful to add tests for named casts as well as the C-style 
> casts.
Great idea!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97512

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


[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-02-26 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:908
+
+// Compute Buitlin types
+SmallVector ProtoMaskSeq = ProtoSeq;

Buitlin->Builtin


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

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


[PATCH] D97563: [clang-tidy] Enable modernize-concat-nested-namespaces also on headers

2021-02-26 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp:4
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 -check-prefix=CHECK-FIXES
+// Restore header file and re-run with c++2b:
+// RUN: cp 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 %T/modernize-concat-nested-namespaces.h

DmitryPolukhin wrote:
> njames93 wrote:
> > Why do we explicitly run on c++2b and not c++20? I understand there is no 
> > framework in place for using -std=c++17-or-later when header files are 
> > modified.
> There is no good reason, I just took highest current version. Changed to 
> c++20.
This is just me rambling, but i think we should think about introducing a test 
mode to clang tidy, where fixes can be applied to a test directory and maybe 
try and make use of the verify diagnostic consumer. The current implementation 
works, but is very rough round the edges. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97563

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


[clang-tools-extra] b18f14d - [clang-tidy] Remove some test c++ mode restrictions.

2021-02-26 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2021-02-26T19:09:28Z
New Revision: b18f14d6897b9e9f34ffd0d8ed46b8ac596fbf05

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

LOG: [clang-tidy] Remove some test c++ mode restrictions.

Some comments are redundant, others just simple fixes.

Reviewed By: aaron.ballman

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

Added: 


Modified: 

clang-tools-extra/test/clang-tidy/checkers/abseil-faster-strsplit-delimiter.cpp
clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp

clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp

clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp

clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/abseil-faster-strsplit-delimiter.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/abseil-faster-strsplit-delimiter.cpp
index ff8c034d2b1f..b5035941c9ce 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/abseil-faster-strsplit-delimiter.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/abseil-faster-strsplit-delimiter.cpp
@@ -1,5 +1,4 @@
 // RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-faster-strsplit-delimiter %t
-// FIXME: Fix the checker to work in C++17 mode.
 
 namespace absl {
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp
index 6fd239bb457c..43d1feea1ec1 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp
@@ -1,5 +1,4 @@
 // RUN: %check_clang_tidy -std=c++11-or-later %s abseil-time-subtraction %t -- 
-- -I %S/Inputs
-// FIXME: Fix the checker to work in C++17 mode.
 
 #include "absl/time/time.h"
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
index db393a96a50d..32e65a63eb1c 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
@@ -1,5 +1,4 @@
 // RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
-// FIXME: Fix the checker to work in C++17 mode.
 
 using int64_t = long long;
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
index 4655e27cd8bc..bddc28c2d81e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
@@ -1,5 +1,4 @@
 // RUN: %check_clang_tidy -std=c++11-or-later %s google-readability-casting %t
-// FIXME: Fix the checker to work in C++17 mode.
 
 bool g() { return false; }
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
index 963379141a13..5c03d39f736a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
@@ -2,7 +2,10 @@
 // RUN:  -config='{CheckOptions: [ \
 // RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec
-// FIXME: Fix the checker to work in C++20 mode.
+// RUN: %check_clang_tidy -std=c++20-or-later %s portability-simd-intrinsics 
-check-suffix=CXX20 %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec
 
 vector int vec_add(vector int, vector int);
 
@@ -10,5 +13,6 @@ void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by 
operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by 
operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+  // CHECK-MESSAGES-CXX20: :[[@LINE-2]]:3: warning: 'vec_add' can be replaced 
by operator+ on std::simd objects [portability-simd-intrinsics]
 }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
i

[PATCH] D97544: [clang-tidy] Remove some test c++ mode restrictions.

2021-02-26 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb18f14d6897b: [clang-tidy] Remove some test c++ mode 
restrictions. (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97544

Files:
  
clang-tools-extra/test/clang-tidy/checkers/abseil-faster-strsplit-delimiter.cpp
  clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp
  
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
  clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
  clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
  clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp
@@ -2,7 +2,10 @@
 // RUN:  -config='{CheckOptions: [ \
 // RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64
-// FIXME: Fix the checker to work in C++20 mode.
+// RUN: %check_clang_tidy -std=c++20-or-later %s portability-simd-intrinsics 
-check-suffix=CXX20 %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target x86_64
 
 typedef long long __m128i __attribute__((vector_size(16)));
 typedef double __m256 __attribute__((vector_size(32)));
@@ -18,7 +21,8 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by 
operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced 
by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+  // CHECK-MESSAGES-CXX20: :[[@LINE-2]]:3: warning: '_mm_add_epi32' can be 
replaced by operator+ on std::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp
@@ -2,7 +2,10 @@
 // RUN:  -config='{CheckOptions: [ \
 // RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec
-// FIXME: Fix the checker to work in C++20 mode.
+// RUN: %check_clang_tidy -std=c++20-or-later %s portability-simd-intrinsics 
-check-suffix=CXX20 %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec
 
 vector int vec_add(vector int, vector int);
 
@@ -10,5 +13,6 @@
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by 
operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by 
operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+  // CHECK-MESSAGES-CXX20: :[[@LINE-2]]:3: warning: 'vec_add' can be replaced 
by operator+ on std::simd objects [portability-simd-intrinsics]
 }
Index: clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
@@ -1,5 +1,4 @@
 // RUN: %check_clang_tidy -std=c++11-or-later %s google-readability-casting %t
-// FIXME: Fix the checker to work in C++17 mode.
 
 bool g() { return false; }
 
Index: 
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/abseil-upgrade-duration-conversions.cpp
@@ -1,5 +1,4 @@
 // RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
-// FIXME: Fix the checker to work in C++17 mode.
 
 using int64_t = long long;
 
Index: clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-time-subtraction.cpp
@@ -1,5 +1,4 @@
 // RUN: %check_clang_tidy

[clang-tools-extra] 1a721b6 - [clang-tidy][NFC] Tweak some generation of diag messages

2021-02-26 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2021-02-26T19:10:25Z
New Revision: 1a721b6a2634d9740b389a7604275b426c22600a

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

LOG: [clang-tidy][NFC] Tweak some generation of diag messages

Fix up cases where diag is called by piecing together a string in favour of 
placeholders.
Fix up cases where select could be used instead of duplicating the message for 
sake of 1 word difference.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
clang-tools-extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/clang-tidy/llvm/PreferRegisterOverUnsignedCheck.cpp
clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp
clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/misc-uniqueptr-reset-release.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp 
b/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
index 1f1dc07351ba..4b0ef1b3f4ee 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
@@ -59,10 +59,8 @@ void DurationFactoryFloatCheck::check(const 
MatchFinder::MatchResult &Result) {
 SimpleArg = stripFloatLiteralFraction(Result, *Arg);
 
   if (SimpleArg) {
-diag(MatchedCall->getBeginLoc(),
- (llvm::Twine("use the integer version of absl::") +
-  MatchedCall->getDirectCallee()->getName())
- .str())
+diag(MatchedCall->getBeginLoc(), "use the integer version of absl::%0")
+<< MatchedCall->getDirectCallee()->getName()
 << FixItHint::CreateReplacement(Arg->getSourceRange(), *SimpleArg);
   }
 }

diff  --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp 
b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
index 850631300f7a..aa43e7dc3885 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
@@ -83,24 +83,18 @@ void StringFindStartswithCheck::check(const 
MatchFinder::MatchResult &Result) {
   Context.getLangOpts());
 
   // Create the StartsWith string, negating if comparison was "!=".
-  bool Neg = ComparisonExpr->getOpcodeStr() == "!=";
-  StringRef StartswithStr;
-  if (Neg) {
-StartswithStr = "!absl::StartsWith";
-  } else {
-StartswithStr = "absl::StartsWith";
-  }
+  bool Neg = ComparisonExpr->getOpcode() == BO_NE;
 
   // Create the warning message and a FixIt hint replacing the original expr.
-  auto Diagnostic =
-  diag(ComparisonExpr->getBeginLoc(),
-   (StringRef("use ") + StartswithStr + " instead of find() " +
-ComparisonExpr->getOpcodeStr() + " 0")
-   .str());
+  auto Diagnostic = diag(ComparisonExpr->getBeginLoc(),
+ "use %select{absl::StartsWith|!absl::StartsWith}0 "
+ "instead of find() %select{==|!=}0 0")
+<< Neg;
 
   Diagnostic << FixItHint::CreateReplacement(
   ComparisonExpr->getSourceRange(),
-  (StartswithStr + "(" + HaystackExprCode + ", " + NeedleExprCode + ")")
+  ((Neg ? "!absl::StartsWith(" : "absl::StartsWith(") + HaystackExprCode +
+   ", " + NeedleExprCode + ")")
   .str());
 
   // Create a preprocessor #include FixIt hint (CreateIncludeInsertion checks

diff  --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
index a78e93aff550..85af540b48fb 100644
--- a/clang-

[PATCH] D97488: [clang-tidy][NFC] Tweak some generation of diag messages

2021-02-26 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1a721b6a2634: [clang-tidy][NFC] Tweak some generation of 
diag messages (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97488

Files:
  clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
  clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tools-extra/clang-tidy/llvm/PreferRegisterOverUnsignedCheck.cpp
  clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
  clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
  clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseNodiscardCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstructorInitCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
  clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-uniqueptr-reset-release.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-uniqueptr-reset-release.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc-uniqueptr-reset-release.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-uniqueptr-reset-release.cpp
@@ -33,27 +33,27 @@
   std::unique_ptr *y = &b;
 
   a.reset(b.release());
-  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer ptr1 = std::move(ptr2) over ptr1.reset(ptr2.release()) [misc-uniqueptr-reset-release]
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer ptr = std::move(ptr2) over ptr.reset(ptr2.release()) [misc-uniqueptr-reset-release]
   // CHECK-FIXES: a = std::move(b);
   a.reset(c.release());
-  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer ptr1 = std::move(ptr2)
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer ptr = std::move(ptr2)
   // CHECK-FIXES: a = std::move(c);
   a.reset(Create().release());
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer ptr = ReturnUnique() over ptr.reset(ReturnUnique().release()) [misc-uniqueptr-reset-release]
   // CHECK-FIXES: a = Create();
   x->reset(y->release());
-  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: prefer ptr1 = std::move(ptr2)
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: prefer ptr = std::move(ptr2)
   // CHECK-FIXES: *x = std::move(*y);
   Look().reset(Look().release());
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer ptr1 = std::move(ptr2)
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer ptr = std::move(ptr2)
   // CHECK-FIXES: Look() = std::move(Look());
   Get()->reset(Get()->release());
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer ptr1 = std::move(ptr2)
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer ptr = std::move(ptr2)
   // CHECK-FIXES: *Get() = std::move(*Get());
 
   std::unique_ptr func_a, func_b;
   func_a.reset(func_b.release());
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer ptr1 = std::move(ptr2)
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer ptr = std::move(ptr2)
   // CHECK-FIXES: func_a = std::move(func_b);
 }
 
Index: clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
@@ -88,19 +88,20 @@
 }
 
 void UseAnyOfAllOfCheck::check(const MatchFinder::MatchResult &Result) {
-  StringRef Ranges = getLangOpts().CPlusPlus20 ? "::ranges" : "";
 
   if (const auto *S = Result.Nodes.getNodeAs("any_of_loop")) {
 if (!isViableLoop(*S, *Result.Context))
   return;
 
-diag(S->getForLoc(), "replace loop by 'std%0::any_of()'") << Ranges;
+diag(S->getForLoc(), "replace loop by 'std%select{|::ranges}0::any_of()'")
+<< getLangOpts().CPlusPlus20;
   } else if (const auto *S =
  Result.Nodes.getNodeAs("all_of_loop")) {
 if (!isViableLoop(*S, *Result.Context))
   return;
 
-diag(S->getForLoc(), "replace loop by 'std%0::all_of()'") << Ranges;
+diag(S->getForLoc(), "replace loop by 'std%select{|::ranges}0::all_of()'")
+<< getLangOpts().CPlusPlus20;
   }
 }
 
Index: clang-tools-extra/clang-tidy/readability/

[PATCH] D97512: [clang] removes check against integral-to-pointer conversion...

2021-02-26 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 326748.
cjdb added a comment.

`s/IgnoreImplicitAsWritten/IgnoreParenImpCasts/` since the latter seems to work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97512

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Analysis/free.c
  clang/test/Analysis/free.cpp


Index: clang/test/Analysis/free.cpp
===
--- clang/test/Analysis/free.cpp
+++ clang/test/Analysis/free.cpp
@@ -208,3 +208,39 @@
   // Unknown value
   std::free(x[offset]); // no-warning
 }
+
+struct S {
+  const char* p;
+};
+
+void t18_C_style_C_style_free (S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18_C_style_C_style_std_free (S s) {
+  std::free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18_C_style_reinterpret_free (S s) {
+  free((void*)reinterpret_cast(s.p)); // no warning
+}
+
+void t18_C_style_reinterpret_std_free (S s) {
+  std::free((void*)reinterpret_cast(s.p)); // no warning
+}
+
+void t18_reinterpret_C_style_free (S s) {
+  free(reinterpret_cast((unsigned long long)(s.p))); // no warning
+}
+
+void t18_reinterpret_C_style_std_free (S s) {
+  std::free(reinterpret_cast((unsigned long long)(s.p))); // no warning
+}
+
+void t18_reinterpret_reinterpret_free (S s) {
+  free(reinterpret_cast(reinterpret_cast(s.p))); // 
no warning
+}
+
+void t18_reinterpret_reinterpret_std_free (S s) {
+  std::free(reinterpret_cast(reinterpret_cast(s.p))); // no warning
+}
Index: clang/test/Analysis/free.c
===
--- clang/test/Analysis/free.c
+++ clang/test/Analysis/free.c
@@ -108,3 +108,11 @@
   // expected-warning@-1{{Argument to free() is the address of the function 
'iptr', which is not memory allocated by malloc()}}
   // expected-warning@-2{{attempt to call free on non-heap object 'iptr'}}
 }
+
+struct S {
+  const char* p;
+};
+
+void t18 (struct S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10316,11 +10316,18 @@
 const CastExpr *Cast) {
   SmallString<128> SizeString;
   llvm::raw_svector_ostream OS(SizeString);
+
+  clang::CastKind Kind = Cast->getCastKind();
+  if (Kind == clang::CK_BitCast &&
+  !Cast->getSubExpr()->getType()->isFunctionPointerType())
+return;
+  if (Kind == clang::CK_IntegralToPointer &&
+  !isa(
+  Cast->getSubExpr()->IgnoreParenImpCasts()->IgnoreParens()))
+return;
+
   switch (Cast->getCastKind()) {
   case clang::CK_BitCast:
-if (!Cast->getSubExpr()->getType()->isFunctionPointerType())
-  return;
-LLVM_FALLTHROUGH;
   case clang::CK_IntegralToPointer:
   case clang::CK_FunctionToPointerDecay:
 OS << '\'';


Index: clang/test/Analysis/free.cpp
===
--- clang/test/Analysis/free.cpp
+++ clang/test/Analysis/free.cpp
@@ -208,3 +208,39 @@
   // Unknown value
   std::free(x[offset]); // no-warning
 }
+
+struct S {
+  const char* p;
+};
+
+void t18_C_style_C_style_free (S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18_C_style_C_style_std_free (S s) {
+  std::free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18_C_style_reinterpret_free (S s) {
+  free((void*)reinterpret_cast(s.p)); // no warning
+}
+
+void t18_C_style_reinterpret_std_free (S s) {
+  std::free((void*)reinterpret_cast(s.p)); // no warning
+}
+
+void t18_reinterpret_C_style_free (S s) {
+  free(reinterpret_cast((unsigned long long)(s.p))); // no warning
+}
+
+void t18_reinterpret_C_style_std_free (S s) {
+  std::free(reinterpret_cast((unsigned long long)(s.p))); // no warning
+}
+
+void t18_reinterpret_reinterpret_free (S s) {
+  free(reinterpret_cast(reinterpret_cast(s.p))); // no warning
+}
+
+void t18_reinterpret_reinterpret_std_free (S s) {
+  std::free(reinterpret_cast(reinterpret_cast(s.p))); // no warning
+}
Index: clang/test/Analysis/free.c
===
--- clang/test/Analysis/free.c
+++ clang/test/Analysis/free.c
@@ -108,3 +108,11 @@
   // expected-warning@-1{{Argument to free() is the address of the function 'iptr', which is not memory allocated by malloc()}}
   // expected-warning@-2{{attempt to call free on non-heap object 'iptr'}}
 }
+
+struct S {
+  const char* p;
+};
+
+void t18 (struct S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10316,11 +10316,18 @@
 const CastExpr *Cast) {
   SmallString<128> SizeString;
   llv

[PATCH] D97512: [clang] removes check against integral-to-pointer conversion...

2021-02-26 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb marked an inline comment as done.
cjdb added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:10326
+  !isa(
+  Cast->getSubExpr()->IgnoreImplicitAsWritten()->IgnoreParens()))
+return;

cjdb wrote:
> aaron.ballman wrote:
> > I'm not 100% certain, but would `IgnoreParenImpCasts()` be sufficient here? 
> > (`IgnoreImplicitAsWritten() seems to be a bit special -- the only use of it 
> > I can find in tree is for rewritten binary operator expressions.)
> @rsmith would you mind weighing in here please? My original use-case for 
> `IgnoreImplicitAsWritten` might be different to here and I don't have an 
> answer for @aaron.ballman.
I've tried out `IgnoreParenImpCasts` and it seems to work, but I'd appreciate 
an answer here for future patches please.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97512

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


[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2021-02-26 Thread Felix Berger via Phabricator via cfe-commits
flx created this revision.
flx added reviewers: aaron.ballman, sbenza.
Herald added a subscriber: xazax.hun.
flx requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Until now when determining all the const uses of a VarDecl we only considered
how the variable itself was used. This change extends checking for const usages
of the type's members as well.

This increases the number of true positives for various performance checks that
share the same const usage analysis.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97567

Files:
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy.cpp
@@ -296,3 +296,37 @@
 // SS : createView(*ValueReturningIterator())) {
   }
 }
+
+void positiveConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: loop variable is copied
+// CHECK-FIXES: for (const Struct& SS : View>()) {
+auto MemberCopy = SS.Member;
+const auto &ConstRef = SS.Member;
+bool b = SS.Member.constMethod();
+use(SS.Member);
+useByConstValue(SS.Member);
+useByValue(SS.Member);
+  }
+}
+
+void negativeNonConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+SS.Member.setBool(true);
+  }
+  for (Struct SS : View>()) {
+SS.Member[1];
+  }
+  for (Struct SS : View>()) {
+mutate(SS.Member);
+  }
+  for (Struct SS : View>()) {
+mutate(&SS.Member);
+  }
+}
Index: clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -46,14 +46,19 @@
ASTContext &Context) {
   auto DeclRefToVar =
   declRefExpr(to(varDecl(equalsNode(&VarDecl.bind("declRef");
+  auto MemberExprOfVar = memberExpr(has(DeclRefToVar));
+  auto DeclRefToVarOrMemberExprOfVar =
+  stmt(anyOf(DeclRefToVar, MemberExprOfVar));
   auto ConstMethodCallee = callee(cxxMethodDecl(isConst()));
   // Match method call expressions where the variable is referenced as the this
   // implicit object argument and opertor call expression for member operators
   // where the variable is the 0-th argument.
   auto Matches = match(
-  findAll(expr(anyOf(cxxMemberCallExpr(ConstMethodCallee, on(DeclRefToVar)),
- cxxOperatorCallExpr(ConstMethodCallee,
- hasArgument(0, DeclRefToVar),
+  findAll(expr(anyOf(
+  cxxMemberCallExpr(ConstMethodCallee,
+on(DeclRefToVarOrMemberExprOfVar)),
+  cxxOperatorCallExpr(ConstMethodCallee,
+  hasArgument(0, DeclRefToVarOrMemberExprOfVar),
   Stmt, Context);
   SmallPtrSet DeclRefs;
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
@@ -65,22 +70,23 @@
   ConstReferenceOrValue,
   substTemplateTypeParmType(hasReplacementType(ConstReferenceOrValue;
   auto UsedAsConstRefOrValueArg = forEachArgumentWithParam(
-  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValueOrReplaced)));
+  DeclRefToVarOrMemberExprOfVar,
+  parmVarDecl(hasType(ConstReferenceOrValueOrReplaced)));
   Matches = match(findAll(invocation(UsedAsConstRefOrValueArg)), Stmt, Context);
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
   // References and pointers to const assignments.
-  Matches =
-  match(findAll(declStmt(
-has(varDecl(hasType(qualType(matchers::isReferenceToConst())),
-hasInitializer(ignoringImpCasts(DeclRefToVar)),
-Stmt, Context);
+  Matches = match(
+  findAll(declStmt(has(varDecl(
+  hasType(qualType(matchers::isReferenceToConst())),
+  hasInitializer(ignoringImpCasts(DeclRefToVarOrMemberExprOfVar)),
+  Stmt, Context);
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
-  Matches =
-  match(findAll(declStmt(has(varDecl(
-hasType(qualType(matchers::isPointerToConst())),
-hasInitializer(ignoringImpCasts(unaryOperator(
-hasOperatorName("&"), hasUnaryOperand(DeclRefToVar,
-Stmt, Context);
+  Matches = match(findAll(declStmt(has(varDecl(
+  hasType(qualType(matchers::isPointerToConst())),
+  hasInitializer(ignoringImpCasts(unaryOperator(
+  hasOperatorName("&"),
+  hasUnary

[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-02-26 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:56
+//
+//   e: type of "t" as is (identity)
+//   v: computes a vector type whose element type is "t" for the current LMUL

khchen wrote:
> jrtc27 wrote:
> > Do we really need to invent an esoteric DSL?
> I think this is different design choose.
> Current design is based on 
> https://repo.hca.bsc.es/gitlab/rferrer/llvm-epi/-/blob/EPI/clang/include/clang/Basic/epi_builtins.td,
>  personally I think it makes td file more simpler.
> 
> Of course we can make td file more complex little bit and list all legal type 
> and combination like 
> https://github.com/isrc-cas/rvv-llvm/blob/rvv-iscas/clang/include/clang/Basic/riscv_vector.td
>  did.
> 
> In fact, I don't have a strong opinion on which one is better
> 
> ps. current approach is similar to arm_sve.td design, maybe they know the 
> some critical reason.
I just find it really obfuscates things when we have all these magic character 
sequences.



Comment at: clang/include/clang/Basic/riscv_vector.td:66
+//  element type which is bool
+//   0: void type, ignores "t"
+//   z: size_t, ignores "t"

khchen wrote:
> jrtc27 wrote:
> > Then why aren't these just base types? We don't have to follow the 
> > brain-dead nature of printf.
> Basically builtin interface is instantiated by the "base type + LMUL" with 
> type transformers. But in some intrinsic function we need a specific type 
> regardless "base type + LMUL"
> ex. `vuint32m2_t vssrl_vx_u32m2_vl (vuint32m2_t op1, uint8_t op2, size_t vl);`
Then fix the way you define these? This is just bad design IMO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-02-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

The warning should be emitted but it shouldn't have a note at `P.get()` telling 
the user that an inner pointer was obtained.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[PATCH] D94973: [clang][OpenMP] Use OpenMPIRBuilder for workshare loops.

2021-02-26 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

One property of this patch that has bothered me is that OMPCanonicalLoop is not 
a loop.  Instead, it's an AST node that is sandwiched between a directive and a 
loop to contain extra information about the loop.  The TreeTransform issues 
we've been discussing highlight how that extra node can be confusing.

Now I remember that there's D95496 , which 
seems not to have that property.  I haven't reviewed that patch in any detail, 
and I haven't tried to locate any prior discussions.  Can you please summarize 
why you prefer the current patch over that one?




Comment at: clang/lib/Sema/TreeTransform.h:8321
+TreeTransform::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
+  // The OMPCanonicalLoop will be recreated when transforming the 
loop-associted
+  // directive.

Meinersbur wrote:
> jdenny wrote:
> > Meinersbur wrote:
> > > jdenny wrote:
> > > > Meinersbur wrote:
> > > > > jdenny wrote:
> > > > > > Meinersbur wrote:
> > > > > > > jdenny wrote:
> > > > > > > > I'm used to seeing `TransformX` call `RebuildX` call `ActOnX`.  
> > > > > > > > Why not do that for `X=OMPCanonicalLoop`?  Does 
> > > > > > > > `TransformOMPExecutableDirective` really need a special case 
> > > > > > > > for `OMPCanonicalLoop`?
> > > > > > > The intended behaviour is: 
> > > > > > > 
> > > > > > > 1. Transform the child loop
> > > > > > > 2. Return the child loop as representing the OMPCanonicalLoop 
> > > > > > > (i.e. OMPCanonicalLoop wrapper is removed).
> > > > > > > 3. Parent loop-associated directive (e.g. workshare) is processed.
> > > > > > > 4. `ActOnOpenMPCanonicalLoop` adds new OMPCanonicalLoop wrapper 
> > > > > > > for loop nest.
> > > > > > > 
> > > > > > > This guarantees maximum flexibility on what of the loop can be 
> > > > > > > changed, such as
> > > > > > > * Change lower bound, upper bound, step
> > > > > > > * Convert between CXXForRangeStmt and ForStmt
> > > > > > > * Change the associated depth (e.g. different value for 
> > > > > > > `collapse` clause)
> > > > > > > * Remove the directive and no OMPCanonicalLoop remain
> > > > > > > 
> > > > > > > This also saves adding many lines of code handling transforming 
> > > > > > > each member of OMPCanonicalLoop separately.
> > > > > > > The intended behaviour is: 
> > > > > > > 
> > > > > > > 1. Transform the child loop
> > > > > > 
> > > > > > For  my suggestion, that call would remain within 
> > > > > > `TransformOMPCanonicalLoop` where it is now.
> > > > > > 
> > > > > > > 2. Return the child loop as representing the OMPCanonicalLoop 
> > > > > > > (i.e. OMPCanonicalLoop wrapper is removed).
> > > > > > 
> > > > > > For my suggestion, this would not happen.  I think it's normal for 
> > > > > > a `TransformX` to return the transformed `X` not the transformed 
> > > > > > child of `X`.  If a caller wants to transform the child, then it 
> > > > > > should transform the child directly instead.
> > > > > > 
> > > > > > > 3. Parent loop-associated directive (e.g. workshare) is processed.
> > > > > > 
> > > > > > It looks to me like step 3 is currently within 
> > > > > > `TransformOMPExecutableDirective` and starts before the call to 
> > > > > > `TranformOMPCanonicalLoop` and thus before step 1.  It completes 
> > > > > > after step 4.  Or am I misunderstanding what you're describing as 
> > > > > > step 3?
> > > > > > 
> > > > > > > 4. `ActOnOpenMPCanonicalLoop` adds new OMPCanonicalLoop wrapper 
> > > > > > > for loop nest.
> > > > > > 
> > > > > > For my suggestion, this would still happen.  However, instead of 
> > > > > > step 2: within `TransformOMPCanonicalLoop`, you would call 
> > > > > > `RebuildOMPCanonicalLoop`, which would call 
> > > > > > `ActOnOpenMPCanonicalLoop` as step 4.  The effect is you moved 
> > > > > > `ActOnOpenMPCanonicalLoop` from the caller 
> > > > > > (`TransformOMPExecutableDirective`) to the callee's callee, but the 
> > > > > > behavior should remain the same.
> > > > > > 
> > > > > > > This guarantees maximum flexibility on what of the loop can be 
> > > > > > > changed, such as
> > > > > > > * Change lower bound, upper bound, step
> > > > > > > * Convert between CXXForRangeStmt and ForStmt
> > > > > > > * Change the associated depth (e.g. different value for 
> > > > > > > `collapse` clause)
> > > > > > > * Remove the directive and no OMPCanonicalLoop remain
> > > > > > 
> > > > > > Flexibility for whom?
> > > > > > 
> > > > > > A class extending `TreeTransform`?  With my suggestion, it can 
> > > > > > override `TransformOMPCanonicalLoop` or `RebuildOMPCanonicalLoop`, 
> > > > > > depending on how much it wants to alter the transformation.
> > > > > > 
> > > > > > Or a caller of `TransformOMPCanonicalLoop` within `TreeTransform`?  
> > > > > > I only see one right now, `TransformOMPExecutableDirective`, and I 
> > > > > > don't see how it needs the flexibility.  Are there other callers I 
> > > > > > missed?
> > > > > > 
> > > >

[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-02-26 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:66
+//  element type which is bool
+//   0: void type, ignores "t"
+//   z: size_t, ignores "t"

jrtc27 wrote:
> khchen wrote:
> > jrtc27 wrote:
> > > Then why aren't these just base types? We don't have to follow the 
> > > brain-dead nature of printf.
> > Basically builtin interface is instantiated by the "base type + LMUL" with 
> > type transformers. But in some intrinsic function we need a specific type 
> > regardless "base type + LMUL"
> > ex. `vuint32m2_t vssrl_vx_u32m2_vl (vuint32m2_t op1, uint8_t op2, size_t 
> > vl);`
> Then fix the way you define these? This is just bad design IMO.
For each signature there is effectively a single key type that is a vector. The 
type transformer is a list of rules for how to derive all of the other operands 
from that one key type. Conceptually similar to LLVMScalarOrSameVectorWidth or 
LLVMHalfElementsVectorType in Intrinsics.td. Some types are fixed and don't 
vary by the key type. Like the size_t vl operand or a store intrinsic returning 
void.  There is no separate place to put a base type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

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


[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-02-26 Thread Craig Topper via Phabricator via cfe-commits
craig.topper requested changes to this revision.
craig.topper added a comment.
This revision now requires changes to proceed.

Dropping my approval pending @jrtc27 comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

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


[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-02-26 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:116
+  D = 1 << 2,
+  ZFH = 1 << 3
+};

Zfh



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:241
+  case 8:
+ExpResult = Log2LMUL + 3;
+break;

Please be consistent and use Log2 rather than Exp



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:259-260
+
+LMULType &LMULType::operator*=(unsigned RHS) {
+  this->Log2LMUL = this->Log2LMUL + RHS;
+  return *this;

That's not how multiplication works. This is exponentiation. Multiplication 
would be `Log2LMul + log2(RHS)`. Please don't abuse operators like this.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:325
+  std::string &S = BuiltinStr;
+  if (IsVoid) {
+S = "v";

This really needs to be an enum not a bunch of mutually-exclusive booleans, 
which I though I suggested in the past?



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:450-451
+  S += "uint";
+// Vector bool is special case, the formulate is `vbool_t =
+// MVT::nxv<64/N>i1` ex. vbool16_t = MVT::
+if (IsBool && isVector())

Please try and avoid wrapping code across lines



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:624
+  }
+  // Init RISCV_Extensions
+  for (const auto &T : OutInTypes) {

Blank line



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:685
+  OS << "};\n";
+  OS << "break;\n";
+}

This is missing indentation?



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:870
+PrevDef = Def.get();
+OS << "case RISCV::BI__builtin_rvv_" << Def->getName() << ":\n";
+  }

Needs indentation?



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:567
+  // Compute type transformers
+  for (char I : Transformer.take_front(Transformer.size() - 1)) {
+switch (I) {

craig.topper wrote:
> Can we do Transformer = Transformer.drop_back() right before this loop. That 
> take_front code is harder to think about.
Or would it be better as a pop_back in the switch above?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

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


[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-02-26 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:567
+  // Compute type transformers
+  for (char I : Transformer.take_front(Transformer.size() - 1)) {
+switch (I) {

jrtc27 wrote:
> craig.topper wrote:
> > Can we do Transformer = Transformer.drop_back() right before this loop. 
> > That take_front code is harder to think about.
> Or would it be better as a pop_back in the switch above?
I don't think StringRef has a pop_back.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

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


[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-02-26 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:567
+  // Compute type transformers
+  for (char I : Transformer.take_front(Transformer.size() - 1)) {
+switch (I) {

craig.topper wrote:
> jrtc27 wrote:
> > craig.topper wrote:
> > > Can we do Transformer = Transformer.drop_back() right before this loop. 
> > > That take_front code is harder to think about.
> > Or would it be better as a pop_back in the switch above?
> I don't think StringRef has a pop_back.
Right, and it's an immutable data structure anyway so you'd need to have to 
deal with two return values. Never mind then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

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


[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-02-26 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:259-260
+
+LMULType &LMULType::operator*=(unsigned RHS) {
+  this->Log2LMUL = this->Log2LMUL + RHS;
+  return *this;

jrtc27 wrote:
> That's not how multiplication works. This is exponentiation. Multiplication 
> would be `Log2LMul + log2(RHS)`. Please don't abuse operators like this.
This seems like it must be broken, but since we don't do widening or narrowing 
in this patch we didn't notice?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

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


  1   2   >