[PATCH] D114162: [X86][clang] Enable floating-point type for -mno-x87 option on 32-bits

2021-11-29 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic accepted this revision.
asavonic added a comment.
This revision is now accepted and ready to land.

LGTM. We can also remove all code related to HasFPReturn, it is no longer 
needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114162

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


[PATCH] D110833: [clang-format] Refactor SpaceBeforeParens to add options

2021-11-29 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I'm looking at a bug (sorry can't log it as we don't seem to have a working bug 
tracker!) that causes a regression on `operator new(` and `operator delete(` 
which I believe I've tracked to this change

v12

  ~foo() { ::operator delete(bar); }
  
  ::operator delete(bar)

after this change, (space between delete and (bar) when at function depth, but 
not at global)

  ~foo() { ::operator delete (bar); }
  
  ::operator delete(bar)


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

https://reviews.llvm.org/D110833

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


[PATCH] D114667: [clangd] Add fixes for clang "include " diagnostics

2021-11-29 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

Thanks, this is nice low-hanging fruit.




Comment at: clang-tools-extra/clangd/Diagnostics.cpp:830
+  if (!ReplacementFixes.empty()) {
+LastDiag->Fixes.insert(LastDiag->Fixes.end(), ReplacementFixes.begin(),
+   ReplacementFixes.end());

Do we maybe want to assert `Info.getFixItHints().empty()` here, so that if 
clang later introduces its own fix-it it gets on our radar and we can decide 
which one to prefer?



Comment at: clang-tools-extra/clangd/IncludeFixer.cpp:52
+llvm::Optional getArgStr(const clang::Diagnostic &Info,
+  unsigned I) {
+  switch (Info.getArgKind(I)) {

nit: Index or Idx?



Comment at: clang-tools-extra/clangd/IncludeFixer.cpp:495
+  if (auto Edit = Inserter->insert(Name))
+return {Fix{llvm::formatv("Include {0}", Name).str(), {std::move(*Edit)}}};
+  return {};

In the `note_include_header_or_declare` case, we could pull the second arg from 
the diagnostic (the name of the symbol) and use it to provide the slightly more 
detailed hint description that [fixUnresolvedName() 
does](https://searchfox.org/llvm/rev/168bc7ce7e2ebe6527bf3fdd9262ef5c0deab4fc/clang-tools-extra/clangd/IncludeFixer.cpp#168).
 Up to you if you think that's worth doing.



Comment at: clang-tools-extra/clangd/IncludeFixer.h:43
   /// Returns include insertions that can potentially recover the diagnostic.
+  /// If Info describes a note, it will be replaced by any returned fixes.
   std::vector fix(DiagnosticsEngine::Level DiagLevel,

The added comment describes the behaviour of calling code, not the behaviour of 
this method. Perhaps it would make more sense in the calling code?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114667

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


[PATCH] D91000: [clang-tidy] Add cert-msc24-c checker.

2021-11-29 Thread Fütő Gergely via Phabricator via cfe-commits
futogergely updated this revision to Diff 390270.
futogergely retitled this revision from "[clang-tidy] CERT MSC24-C Obsolescent 
Functions check" to "[clang-tidy] Add cert-msc24-c checker.".
futogergely edited the summary of this revision.

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

https://reviews.llvm.org/D91000

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

Index: clang-tools-extra/test/clang-tidy/checkers/cert-msc24-c.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-msc24-c.c
@@ -0,0 +1,96 @@
+// RUN: %check_clang_tidy -check-suffix=WITH-ANNEX-K%s cert-msc24-c %t -- -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-c %t -- -- -U__STDC_LIB_EXT1__   -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-c %t -- -- -D__STDC_LIB_EXT1__=1 -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-c %t -- -- -U__STDC_LIB_EXT1__   -D__STDC_WANT_LIB_EXT1__=1
+
+typedef void *FILE;
+char *gets(char *s);
+void rewind(FILE *stream);
+void setbuf(FILE *stream, char *buf);
+
+void f1(char *s, FILE *f) {
+  gets(s);
+  // CHECK-MESSAGES-WITH-ANNEX-K::[[@LINE-1]]:3: warning: function 'gets' is deprecated as of C99, removed from C11.
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-2]]:3: warning: function 'gets' is deprecated as of C99, removed from C11.
+
+  rewind(f);
+  // CHECK-MESSAGES-WITH-ANNEX-K::[[@LINE-1]]:3: warning: function 'rewind' has no error detection; 'fseek' should be used instead.
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-2]]:3: warning: function 'rewind' has no error detection; 'fseek' should be used instead.
+
+  setbuf(f, s);
+  // CHECK-MESSAGES-WITH-ANNEX-K::[[@LINE-1]]:3: warning: function 'setbuf' has no error detection; 'setvbuf' should be used instead.
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-2]]:3: warning: function 'setbuf' has no error detection; 'setvbuf' should be used instead.
+}
+
+struct tm;
+char *asctime(const struct tm *timeptr);
+
+void f2(const struct tm *timeptr) {
+  asctime(timeptr);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'asctime' is non-reentrant; 'asctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  char *(*f_ptr1)(const struct tm *) = asctime;
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:40: warning: function 'asctime' is non-reentrant; 'asctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  char *(*f_ptr2)(const struct tm *) = &asctime;
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:41: warning: function 'asctime' is non-reentrant; 'asctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+}
+
+FILE *fopen(const char *filename, const char *mode);
+FILE *freopen(const char *filename, const char *mode, FILE *stream);
+int fscanf(FILE *stream, const char *format, ...);
+
+void f3(char *s, FILE *f) {
+  fopen(s, s);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'fopen' has no exclusive access to file; 'fopen_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  freopen(s, s, f);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'freopen' has no exclusive access to file; 'freopen_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  int i;
+  fscanf(f, "%d", &i);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'fscanf' is obsolescent; 'fscanf_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+}
+
+typedef int time_t;
+char *ctime(const time_t *timer);
+
+void f4(const time_t *timer) {
+  ctime(timer);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'ctime' is non-reentrant; 'ctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+}
+
+typedef int errno_t;
+typedef size_t rsize_t;
+errno_t asctime_s(char *s, rsize_t maxsize, const struct tm *timeptr);
+errno_t strcat_s(char *s1, rsize_t s1max, const char *s2);
+int fseek(FILE *stream, long int offset, int whence);
+int setvbuf(FILE *stream, char *buf, int mode, size_t size);
+
+void fUsingSafeFunctions(const struct tm *timeptr, FILE *f) {
+  const size_t BUFFSIZE = 32;
+  char buf[BUFFSIZE] = {0};
+
+  // no-warning, safe function from annex K is used
+  if (asctime_s(buf, BUFFSIZE, timeptr) != 0)
+return;
+
+  // no-warning, safe function from annex K is used
+  if (strcat_s(buf, BUFFSIZE, "something") != 0)
+return;
+
+  /

[clang-tools-extra] 0540485 - [libtooling][clang-tidy] Fix crashing on rendering invalid SourceRanges

2021-11-29 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-11-29T09:56:43+01:00
New Revision: 0540485436c4dd225e6a40e6db1240f096d145d3

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

LOG: [libtooling][clang-tidy] Fix crashing on rendering invalid SourceRanges

Invalid SourceRanges can occur generally if the code does not compile,
thus we expect clang error diagnostics.
Unlike `clang`, `clang-tidy` did not swallow invalid source ranges, but
tried to highlight them, and blow various assertions.

The following two examples produce invalid source ranges, but this is
not a complete list:

  void test(x); // error: unknown type name 'x'
  struct Foo {
member; // error: C++ requires a type specifier for all declarations
  };

Thanks @whisperity helping me fix this.

Reviewed-By: xazax.hun

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 5b410ba9d2ea4..764866d550839 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -79,16 +79,22 @@ class ClangTidyDiagnosticRenderer : public 
DiagnosticRenderer {
   return CharSourceRange::getCharRange(SourceRange.getBegin(), End);
 };
 
+// We are only interested in valid ranges.
+auto ValidRanges =
+llvm::make_filter_range(Ranges, [](const CharSourceRange &R) {
+  return R.getAsRange().isValid();
+});
+
 if (Level == DiagnosticsEngine::Note) {
   Error.Notes.push_back(TidyMessage);
-  for (const CharSourceRange &SourceRange : Ranges)
+  for (const CharSourceRange &SourceRange : ValidRanges)
 Error.Notes.back().Ranges.emplace_back(Loc.getManager(),
ToCharRange(SourceRange));
   return;
 }
 assert(Error.Message.Message.empty() && "Overwriting a diagnostic 
message");
 Error.Message = TidyMessage;
-for (const CharSourceRange &SourceRange : Ranges)
+for (const CharSourceRange &SourceRange : ValidRanges)
   Error.Message.Ranges.emplace_back(Loc.getManager(),
 ToCharRange(SourceRange));
   }

diff  --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
index 414c7967bc825..033798ceec46d 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
@@ -7,6 +7,11 @@ X(f)
 int a[-1];
 int b[0];
 
+void test(x);
+struct Foo {
+  member;
+};
+
 // CHECK-MESSAGES: -input.cpp:2:1: warning: no previous prototype for function 
'ff' [clang-diagnostic-missing-prototypes]
 // CHECK-MESSAGES: -input.cpp:1:19: note: expanded from macro 'X'
 // CHECK-MESSAGES: {{^}}note: expanded from here{{$}}
@@ -14,6 +19,8 @@ int b[0];
 // CHECK-MESSAGES: -input.cpp:1:14: note: expanded from macro 'X'
 // CHECK-MESSAGES: -input.cpp:3:7: error: 'a' declared as an array with a 
negative size [clang-diagnostic-error]
 // CHECK-MESSAGES: -input.cpp:4:7: warning: zero size arrays are an extension 
[clang-diagnostic-zero-length-array]
+// CHECK-MESSAGES: -input.cpp:6:11: error: unknown type name 'x' 
[clang-diagnostic-error]
+// CHECK-MESSAGES: -input.cpp:8:3: error: C++ requires a type specifier for 
all declarations [clang-diagnostic-error]
 
 // CHECK-YAML: ---
 // CHECK-YAML-NEXT: MainSourceFile:  '{{.*}}-input.cpp'
@@ -71,4 +78,20 @@ int b[0];
 // CHECK-YAML-NEXT:  Length:  1
 // CHECK-YAML-NEXT: Level:   Warning
 // CHECK-YAML-NEXT: BuildDirectory:  '{{.*}}'
+// CHECK-YAML-NEXT:   - DiagnosticName:  clang-diagnostic-error
+// CHECK-YAML-NEXT: DiagnosticMessage:
+// CHECK-YAML-NEXT:   Message: 'unknown type name ''x'''
+// CHECK-YAML-NEXT:   FilePath:'{{.*}}-input.cpp'
+// CHECK-YAML-NEXT:   FileOffset:  67
+// CHECK-YAML-NEXT:   Replacements:[]
+// CHECK-YAML-NEXT: Level:   Error
+// CHECK-YAML-NEXT: BuildDirectory:  '{{.*}}'
+// CHECK-YAML-NEXT:   - DiagnosticName:  clang-diagnostic-error
+// CHECK-YAML-NEXT: DiagnosticMessage:
+// CHECK-YAML-NEXT:   Message: 'C++ requires a type specifier for 
all declarations'
+// CHECK-YAML-NEXT:   FilePath:'{{.*}}-input.cpp'
+// CHECK-YAML-NEXT:   FileOffset:  86
+// CHECK-YAM

[clang-tools-extra] e1d0673 - [clang-tidy] Fix crashing altera-struct-pack-align on invalid RecordDecls

2021-11-29 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-11-29T09:56:43+01:00
New Revision: e1d0673aeeece138d4865385a24a86f6954dff72

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

LOG: [clang-tidy] Fix crashing altera-struct-pack-align on invalid RecordDecls

Reviewed-By: martong

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-invalid-decl-no-crash.cpp

Modified: 
clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp 
b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
index ef5fe41fd8c9c..6ae53512fca5e 100644
--- a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
@@ -51,6 +51,10 @@ void StructPackAlignCheck::check(const 
MatchFinder::MatchResult &Result) {
   if (Struct->isTemplated())
  return;
 
+  // Packing and alignment requirements for invalid decls are meaningless.
+  if (Struct->isInvalidDecl())
+return;
+
   // Get sizing info for the struct.
   llvm::SmallVector, 10> FieldSizes;
   unsigned int TotalBitSize = 0;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-invalid-decl-no-crash.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-invalid-decl-no-crash.cpp
new file mode 100644
index 0..d52ff94446213
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-invalid-decl-no-crash.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s altera-struct-pack-align 
%t -- -header-filter=.*
+
+struct Foo {
+  member; // no-crash
+};
+// CHECK-MESSAGES: :[[@LINE-2]]:3: error: C++ requires a type specifier for 
all declarations [clang-diagnostic-error]



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


[clang-tools-extra] 0685e83 - Fix cppcoreguidelines-virtual-base-class-destructor in macros

2021-11-29 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-11-29T09:56:43+01:00
New Revision: 0685e83534ef8917f277b394da2927cabff8129f

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

LOG: Fix cppcoreguidelines-virtual-base-class-destructor in macros

The `cppcoreguidelines-virtual-base-class-destructor` checker crashed on
this example:

  #define DECLARE(CLASS) \
  class CLASS {  \
  protected: \
virtual ~CLASS();\
  }
  DECLARE(Foo); // no-crash

The checker will hit the following assertion:

  clang-tidy: llvm/include/llvm/ADT/Optional.h:196: T 
&llvm::optional_detail::OptionalStorage::getValue() & [T = 
clang::Token]: Assertion `hasVal' failed."

It turns out, `Lexer::findNextToken()` returned `llvm::None` within the
`getVirtualKeywordRange()` function when the `VirtualEndLoc`
SourceLocation represents a macro expansion.
To prevent this from happening, I decided to propagate the `llvm::None`
further up and only create the removal of `virtual` if the
`getVirtualKeywordRange()` succeeds.

I considered an alternative fix for this issue:
I could have checked the `Destructor.getLocation().isMacroID()` before
doing any Fixit calculation inside the `check()` function.
In contrast to this approach my patch will preserve the diagnostics and
drop the fixits only if it would have crashed.

Reviewed By: whisperity

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

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
index 0cf7cc9ad6d52..fa5e06c8e7b26 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
@@ -46,9 +46,12 @@ void 
VirtualClassDestructorCheck::registerMatchers(MatchFinder *Finder) {
   this);
 }
 
-static CharSourceRange
+static Optional
 getVirtualKeywordRange(const CXXDestructorDecl &Destructor,
const SourceManager &SM, const LangOptions &LangOpts) {
+  if (Destructor.getLocation().isMacroID())
+return None;
+
   SourceLocation VirtualBeginLoc = Destructor.getBeginLoc();
   SourceLocation VirtualEndLoc = VirtualBeginLoc.getLocWithOffset(
   Lexer::MeasureTokenLength(VirtualBeginLoc, SM, LangOpts));
@@ -190,8 +193,10 @@ void VirtualClassDestructorCheck::check(
   Fix = FixItHint::CreateInsertion(Destructor->getLocation(), "virtual ");
 } else if (Destructor->getAccess() == AccessSpecifier::AS_protected) {
   ProtectedAndVirtual = true;
-  Fix = FixItHint::CreateRemoval(getVirtualKeywordRange(
-  *Destructor, *Result.SourceManager, Result.Context->getLangOpts()));
+  if (const auto MaybeRange =
+  getVirtualKeywordRange(*Destructor, *Result.SourceManager,
+ Result.Context->getLangOpts()))
+Fix = FixItHint::CreateRemoval(*MaybeRange);
 }
   } else {
 Fix = generateUserDeclaredDestructor(*MatchedClassOrStruct,

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
index 51535f89ac43d..c14a2e68def88 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
@@ -270,3 +270,53 @@ using DerivedFromTemplateNonVirtualBaseStruct2Typedef = 
DerivedFromTemplateNonVi
 DerivedFromTemplateNonVirtualBaseStruct2Typedef 
InstantiationWithPublicNonVirtualBaseStruct2;
 
 } // namespace Bugzilla_51912
+
+namespace macro_tests {
+#define CONCAT(x, y) x##y
+
+// CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar1' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+1]]:7: note: make it protected and non-virtual
+class FooBar1 {
+protected:
+  CONCAT(vir, tual) CONCAT(~Foo, Bar1()); // no-fixit
+};
+
+// CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar2' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+1]]:7: note: make it protected and non-virtual
+class FooBar2 {
+protected:
+  virtual CONCAT(~Foo, Bar2()); // FIXME: We should have a fixit for this.
+};
+
+// CHECK-MESSAGES: :[[@LINE+6]]:7: warning: destructor of 'FooBar3' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-

[clang-tools-extra] a8120a7 - [clang-tidy] Ignore narrowing conversions in case of bitfields

2021-11-29 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-11-29T09:56:43+01:00
New Revision: a8120a771143c15480b508c19a14c0c85a36378c

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

LOG: [clang-tidy] Ignore narrowing conversions in case of bitfields

Bitfields are special. Due to integral promotion [conv.prom/5] bitfield
member access expressions are frequently wrapped by an implicit cast to
`int` if that type can represent all the values of the bitfield.

Consider these examples:
  struct SmallBitfield { unsigned int id : 4; };
  x.id & 1; (case-1)
  x.id & 1u;(case-2)
  x.id << 1u;   (case-3)
  (unsigned)x.id << 1;  (case-4)

Due to the promotion rules, we would get a warning for case-1. It's
debatable how useful this is, but the user at least has a convenient way
of //fixing// it by adding the `u` unsigned-suffix to the literal as
demonstrated by case-2. However, this won't work for shift operators like
the one in case-3. In case of a normal binary operator, both operands
contribute to the result type. However, the type of the shift expression is
the promoted type of the left operand. One could still suppress this
superfluous warning by explicitly casting the bitfield member access as
case-4 demonstrates, but why? The compiler already knew that the value from
the member access should safely fit into an `int`, why do we have this
warning in the first place? So, hereby we suppress this specific scenario,
when a bitfield's value is implicitly cast to int (likely due to integral
promotion).

Note that the bitshift operation might invoke unspecified/undefined
behavior, but that's another topic, this checker is about detecting
conversion-related defects.

Example AST for `x.id << 1`:
  BinaryOperator 'int' '<<'
  |-ImplicitCastExpr 'int' 
  | `-ImplicitCastExpr 'unsigned int' 
  |   `-MemberExpr 'unsigned int' lvalue bitfield .id
  | `-DeclRefExpr 'SmallBitfield' lvalue ParmVar 'x' 'SmallBitfield'
  `-IntegerLiteral 'int' 1

Reviewed By: courbet

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-bitfields.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
index 5e59462b2900b..4d67c33361c17 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -58,6 +58,14 @@ void NarrowingConversionsCheck::storeOptions(
   Options.store(Opts, "PedanticMode", PedanticMode);
 }
 
+AST_MATCHER(FieldDecl, hasIntBitwidth) {
+  assert(Node.isBitField());
+  const ASTContext &Ctx = Node.getASTContext();
+  unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
+  unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
+  return IntBitWidth == CurrentBitWidth;
+}
+
 void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
   // ceil() and floor() are guaranteed to return integers, even though the type
   // is not integral.
@@ -83,6 +91,46 @@ void NarrowingConversionsCheck::registerMatchers(MatchFinder 
*Finder) {
 binaryOperator(hasOperands(IsConversionFromIgnoredType,
hasType(isInteger();
 
+  // Bitfields are special. Due to integral promotion [conv.prom/5] bitfield
+  // member access expressions are frequently wrapped by an implicit cast to
+  // `int` if that type can represent all the values of the bitfield.
+  //
+  // Consider these examples:
+  //   struct SmallBitfield { unsigned int id : 4; };
+  //   x.id & 1; (case-1)
+  //   x.id & 1u;(case-2)
+  //   x.id << 1u;   (case-3)
+  //   (unsigned)x.id << 1;  (case-4)
+  //
+  // Due to the promotion rules, we would get a warning for case-1. It's
+  // debatable how useful this is, but the user at least has a convenient way 
of
+  // //fixing// it by adding the `u` unsigned-suffix to the literal as
+  // demonstrated by case-2. However, this won't work for shift operators like
+  // the one in case-3. In case of a normal binary operator, both operands
+  // contribute to the result type. However, the type of the shift expression 
is
+  // the promoted type of the left operand. One could still suppress this
+  // superfluous warning by explicitly casting the bitfield member access as
+  // case-4 demonstrates, but why? The compiler already knew that the value 
from
+  // the member access should safely fit into an `int`, why do we have this
+  // warning in the first place? So, hereby we suppres

[PATCH] D113558: [clang-tidy] Fix cppcoreguidelines-virtual-base-class-destructor in macros

2021-11-29 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0685e83534ef: Fix 
cppcoreguidelines-virtual-base-class-destructor in macros (authored by 
steakhal).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113558

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
@@ -270,3 +270,53 @@
 DerivedFromTemplateNonVirtualBaseStruct2Typedef 
InstantiationWithPublicNonVirtualBaseStruct2;
 
 } // namespace Bugzilla_51912
+
+namespace macro_tests {
+#define CONCAT(x, y) x##y
+
+// CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar1' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+1]]:7: note: make it protected and non-virtual
+class FooBar1 {
+protected:
+  CONCAT(vir, tual) CONCAT(~Foo, Bar1()); // no-fixit
+};
+
+// CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar2' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+1]]:7: note: make it protected and non-virtual
+class FooBar2 {
+protected:
+  virtual CONCAT(~Foo, Bar2()); // FIXME: We should have a fixit for this.
+};
+
+// CHECK-MESSAGES: :[[@LINE+6]]:7: warning: destructor of 'FooBar3' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+5]]:7: note: make it protected and non-virtual
+// CHECK-FIXES:  class FooBar3 {
+// CHECK-FIXES-NEXT: protected:
+// CHECK-FIXES-NEXT:   ~FooBar3();
+// CHECK-FIXES-NEXT: };
+class FooBar3 {
+protected:
+  CONCAT(vir, tual) ~FooBar3();
+};
+
+// CHECK-MESSAGES: :[[@LINE+6]]:7: warning: destructor of 'FooBar4' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+5]]:7: note: make it protected and non-virtual
+// CHECK-FIXES:  class FooBar4 {
+// CHECK-FIXES-NEXT: protected:
+// CHECK-FIXES-NEXT:   ~CONCAT(Foo, Bar4());
+// CHECK-FIXES-NEXT: };
+class FooBar4 {
+protected:
+  CONCAT(vir, tual) ~CONCAT(Foo, Bar4());
+};
+
+// CHECK-MESSAGES: :[[@LINE+3]]:7: warning: destructor of 'FooBar5' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+2]]:7: note: make it protected and non-virtual
+#define XMACRO(COLUMN1, COLUMN2) COLUMN1 COLUMN2
+class FooBar5 {
+protected:
+  XMACRO(CONCAT(vir, tual), ~CONCAT(Foo, Bar5());) // no-crash, no-fixit
+};
+#undef XMACRO
+#undef CONCAT
+} // namespace macro_tests
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
@@ -46,9 +46,12 @@
   this);
 }
 
-static CharSourceRange
+static Optional
 getVirtualKeywordRange(const CXXDestructorDecl &Destructor,
const SourceManager &SM, const LangOptions &LangOpts) {
+  if (Destructor.getLocation().isMacroID())
+return None;
+
   SourceLocation VirtualBeginLoc = Destructor.getBeginLoc();
   SourceLocation VirtualEndLoc = VirtualBeginLoc.getLocWithOffset(
   Lexer::MeasureTokenLength(VirtualBeginLoc, SM, LangOpts));
@@ -190,8 +193,10 @@
   Fix = FixItHint::CreateInsertion(Destructor->getLocation(), "virtual ");
 } else if (Destructor->getAccess() == AccessSpecifier::AS_protected) {
   ProtectedAndVirtual = true;
-  Fix = FixItHint::CreateRemoval(getVirtualKeywordRange(
-  *Destructor, *Result.SourceManager, Result.Context->getLangOpts()));
+  if (const auto MaybeRange =
+  getVirtualKeywordRange(*Destructor, *Result.SourceManager,
+ Result.Context->getLangOpts()))
+Fix = FixItHint::CreateRemoval(*MaybeRange);
 }
   } else {
 Fix = generateUserDeclaredDestructor(*MatchedClassOrStruct,


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
@@ -270,3 +270,53 @@
 DerivedFromTemplateNonVirtualBaseStruct2Typedef InstantiationWithPublicNonVirtualBaseStruct2;
 
 } // namespace Bugzilla_51912
+
+namespace macro_test

[PATCH] D114254: [libtooling][clang-tidy] Fix crashing on rendering invalid SourceRanges

2021-11-29 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0540485436c4: [libtooling][clang-tidy] Fix crashing on 
rendering invalid SourceRanges (authored by steakhal).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114254

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
@@ -37,6 +37,33 @@
   }
 };
 
+class InvalidRangeTestCheck : public ClangTidyCheck {
+public:
+  InvalidRangeTestCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override {
+Finder->addMatcher(ast_matchers::varDecl().bind("var"), this);
+  }
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override {
+const auto *Var = Result.Nodes.getNodeAs("var");
+SourceLocation ValidBeginLoc = Var->getBeginLoc();
+SourceLocation ValidEndLoc = Var->getEndLoc();
+SourceLocation InvalidLoc;
+ASSERT_TRUE(ValidBeginLoc.isValid());
+ASSERT_TRUE(ValidEndLoc.isValid());
+ASSERT_TRUE(InvalidLoc.isInvalid());
+
+diag(ValidBeginLoc, "valid->valid")
+<< SourceRange(ValidBeginLoc, ValidEndLoc);
+diag(ValidBeginLoc, "valid->invalid")
+<< SourceRange(ValidBeginLoc, InvalidLoc);
+diag(ValidBeginLoc, "invalid->valid")
+<< SourceRange(InvalidLoc, ValidEndLoc);
+diag(ValidBeginLoc, "invalid->invalid")
+<< SourceRange(InvalidLoc, InvalidLoc);
+  }
+};
+
 } // namespace
 
 TEST(ClangTidyDiagnosticConsumer, SortsErrors) {
@@ -66,6 +93,24 @@
   EXPECT_EQ(7ul, Errors[0].Message.Ranges[0].Length);
 }
 
+TEST(ClangTidyDiagnosticConsumer, InvalidSourceLocationRangesIgnored) {
+  std::vector Errors;
+  runCheckOnCode("int x;", &Errors);
+  EXPECT_EQ(4ul, Errors.size());
+
+  EXPECT_EQ("invalid->invalid", Errors[0].Message.Message);
+  EXPECT_TRUE(Errors[0].Message.Ranges.empty());
+
+  EXPECT_EQ("invalid->valid", Errors[1].Message.Message);
+  EXPECT_TRUE(Errors[1].Message.Ranges.empty());
+
+  EXPECT_EQ("valid->invalid", Errors[2].Message.Message);
+  EXPECT_TRUE(Errors[2].Message.Ranges.empty());
+
+  EXPECT_EQ("valid->valid", Errors[3].Message.Message);
+  EXPECT_EQ(1ul, Errors[3].Message.Ranges.size());
+}
+
 } // namespace test
 } // namespace tidy
 } // namespace clang
Index: clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
@@ -7,6 +7,11 @@
 int a[-1];
 int b[0];
 
+void test(x);
+struct Foo {
+  member;
+};
+
 // CHECK-MESSAGES: -input.cpp:2:1: warning: no previous prototype for function 'ff' [clang-diagnostic-missing-prototypes]
 // CHECK-MESSAGES: -input.cpp:1:19: note: expanded from macro 'X'
 // CHECK-MESSAGES: {{^}}note: expanded from here{{$}}
@@ -14,6 +19,8 @@
 // CHECK-MESSAGES: -input.cpp:1:14: note: expanded from macro 'X'
 // CHECK-MESSAGES: -input.cpp:3:7: error: 'a' declared as an array with a negative size [clang-diagnostic-error]
 // CHECK-MESSAGES: -input.cpp:4:7: warning: zero size arrays are an extension [clang-diagnostic-zero-length-array]
+// CHECK-MESSAGES: -input.cpp:6:11: error: unknown type name 'x' [clang-diagnostic-error]
+// CHECK-MESSAGES: -input.cpp:8:3: error: C++ requires a type specifier for all declarations [clang-diagnostic-error]
 
 // CHECK-YAML: ---
 // CHECK-YAML-NEXT: MainSourceFile:  '{{.*}}-input.cpp'
@@ -71,4 +78,20 @@
 // CHECK-YAML-NEXT:  Length:  1
 // CHECK-YAML-NEXT: Level:   Warning
 // CHECK-YAML-NEXT: BuildDirectory:  '{{.*}}'
+// CHECK-YAML-NEXT:   - DiagnosticName:  clang-diagnostic-error
+// CHECK-YAML-NEXT: DiagnosticMessage:
+// CHECK-YAML-NEXT:   Message: 'unknown type name ''x'''
+// CHECK-YAML-NEXT:   FilePath:'{{.*}}-input.cpp'
+// CHECK-YAML-NEXT:   FileOffset:  67
+// CHECK-YAML-NEXT:   Replacements:[]
+// CHECK-YAML-NEXT: Level:   Error
+// CHECK-YAML-NEXT: BuildDirectory:  '{{.*}}'
+// CHECK-YAML-NEXT:   - DiagnosticName:  clang-diagnostic-error
+// CHECK-YAML-NEXT: DiagnosticMessage:
+// CHECK-YAML-NEXT:   Message: 'C++ requires a type specifier for all declarations'
+// CHECK-YAML-NEXT:   FilePath:'{{.*}}-input.cpp'
+// CHECK-YAML-NEXT:   FileOffset:  86
+/

[PATCH] D114256: [clang-tidy] Fix crashing altera-struct-pack-align on invalid RecordDecls

2021-11-29 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe1d0673aeeec: [clang-tidy] Fix crashing 
altera-struct-pack-align on invalid RecordDecls (authored by steakhal).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114256

Files:
  clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-invalid-decl-no-crash.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-invalid-decl-no-crash.cpp
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-invalid-decl-no-crash.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s altera-struct-pack-align 
%t -- -header-filter=.*
+
+struct Foo {
+  member; // no-crash
+};
+// CHECK-MESSAGES: :[[@LINE-2]]:3: error: C++ requires a type specifier for 
all declarations [clang-diagnostic-error]
Index: clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
@@ -51,6 +51,10 @@
   if (Struct->isTemplated())
  return;
 
+  // Packing and alignment requirements for invalid decls are meaningless.
+  if (Struct->isInvalidDecl())
+return;
+
   // Get sizing info for the struct.
   llvm::SmallVector, 10> FieldSizes;
   unsigned int TotalBitSize = 0;


Index: clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-invalid-decl-no-crash.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-invalid-decl-no-crash.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s altera-struct-pack-align %t -- -header-filter=.*
+
+struct Foo {
+  member; // no-crash
+};
+// CHECK-MESSAGES: :[[@LINE-2]]:3: error: C++ requires a type specifier for all declarations [clang-diagnostic-error]
Index: clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
===
--- clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
@@ -51,6 +51,10 @@
   if (Struct->isTemplated())
  return;
 
+  // Packing and alignment requirements for invalid decls are meaningless.
+  if (Struct->isInvalidDecl())
+return;
+
   // Get sizing info for the struct.
   llvm::SmallVector, 10> FieldSizes;
   unsigned int TotalBitSize = 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114105: [clang-tidy] Ignore narrowing conversions in case of bitfields

2021-11-29 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa8120a771143: [clang-tidy] Ignore narrowing conversions in 
case of bitfields (authored by steakhal).

Changed prior to commit:
  https://reviews.llvm.org/D114105?vs=389711&id=390275#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114105

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-bitfields.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-bitfields.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-narrowing-conversions-bitfields.cpp
@@ -0,0 +1,203 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-narrowing-conversions %t \
+// RUN:   -std=c++17 -- -target x86_64-unknown-linux
+
+#define CHAR_BITS 8
+static_assert(sizeof(unsigned int) == 32 / CHAR_BITS);
+
+template 
+struct is_same {
+  static constexpr bool value = false;
+};
+template 
+struct is_same {
+  static constexpr bool value = true;
+};
+
+template 
+static constexpr bool is_same_v = is_same::value;
+
+struct NoBitfield {
+  unsigned int id;
+};
+struct SmallBitfield {
+  unsigned int id : 4;
+};
+
+struct BigBitfield {
+  unsigned int id : 31;
+};
+struct CompleteBitfield {
+  unsigned int id : 32;
+};
+
+int example_warning(unsigned x) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
+  return x;
+}
+
+void test_binary_and(SmallBitfield x) {
+  static_assert(is_same_v);
+  static_assert(is_same_v);
+
+  x.id & 1;
+  x.id & 1u;
+
+  1 & x.id;
+  1u & x.id;
+}
+
+void test_binary_or(SmallBitfield x) {
+  static_assert(is_same_v);
+  static_assert(is_same_v);
+
+  x.id | 1;
+  x.id | 1u;
+
+  1 | x.id;
+  1u | x.id;
+}
+
+template 
+void take(T);
+
+void test_parameter_passing(NoBitfield x) {
+  take(x.id);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: narrowing conversion from 'unsigned int' to signed type 'char' is implementation-defined
+  take(x.id);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: narrowing conversion from 'unsigned int' to signed type 'short' is implementation-defined
+  take(x.id);
+  take(x.id);
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined
+  take(x.id);
+  take(x.id);
+}
+
+void test_parameter_passing(SmallBitfield x) {
+  take(x.id);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: narrowing conversion from 'unsigned int' to signed type 'char' is implementation-defined
+  take(x.id);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: narrowing conversion from 'unsigned int' to signed type 'short' is implementation-defined
+  take(x.id);
+  take(x.id); // no-warning
+  take(x.id);
+  take(x.id);
+}
+
+void test_parameter_passing(BigBitfield x) {
+  take(x.id);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: narrowing conversion from 'unsigned int' to signed type 'char' is implementation-defined
+  take(x.id);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: narrowing conversion from 'unsigned int' to signed type 'short' is implementation-defined
+  take(x.id);
+  take(x.id); // no-warning
+  take(x.id);
+  take(x.id);
+}
+
+void test_parameter_passing(CompleteBitfield x) {
+  take(x.id);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: narrowing conversion from 'unsigned int' to signed type 'char' is implementation-defined
+  take(x.id);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: narrowing conversion from 'unsigned int' to signed type 'short' is implementation-defined
+  take(x.id);
+  take(x.id);
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined
+  take(x.id);
+  take(x.id);
+}
+
+void test(NoBitfield x) {
+  static_assert(is_same_v);
+  static_assert(is_same_v);
+  static_assert(is_same_v);
+  static_assert(is_same_v);
+
+  x.id << 1;
+  x.id << 1u;
+  x.id >> 1;
+  x.id >> 1u;
+  x.id + 1;
+  x.id + 1u;
+
+  1 << x.id;
+  1u << x.id;
+  1 >> x.id;
+  1u >> x.id;
+  1 + x.id;
+  1u + x.id;
+}
+
+void test(SmallBitfield x) {
+  static_assert(is_same_v);
+  static_assert(is_same_v);
+
+  x.id << 1;
+  x.id << 1u;
+  x.id >> 1;
+  x.id >> 1u;
+
+  x.id + 1;
+  x.id + 1u;
+
+  1 << x.id;
+  1u << x.id;
+  1 >> x.id;
+  1u >> x.id;
+
+  1 + x.id;
+  1u + x.id;
+}
+
+void test(BigBitfield x) {
+  static_assert(is_same_v);
+  static_assert(is_same_v);
+
+  x.id << 1;
+  x.id << 1u;
+  x.id >> 1;
+  x.id >> 1u;
+
+  x.id + 1;
+  x.id + 1u;
+
+  1 << x.id;
+  1u << x.id;
+  1 >> x.id;
+  1u >> x.id;
+
+  1 + x.id;
+  1u + x.id;
+}
+
+void test(CompleteBitfield x) {
+  static_

[PATCH] D110833: [clang-format] Refactor SpaceBeforeParens to add options

2021-11-29 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3161-3169
+if (Line.MightBeFunctionDecl && (Left.is(TT_FunctionDeclarationName) ||
+ Right.is(TT_OverloadedOperatorLParen))) {
+  if (Line.mightBeFunctionDefinition())
+return Style.SpaceBeforeParensOptions.AfterFunctionDefinitionName ||
+   spaceRequiredBeforeParens(Right);
+  else
+return Style.SpaceBeforeParensOptions.AfterFunctionDeclarationName ||

This is a change in behaviour for operators, it breaks LLVM style and we are 
going to either have to fix this or revert the whole change until we can decide 
what is best.



Comment at: clang/unittests/Format/FormatTest.cpp:14165
+  SpaceFuncDecl.SpaceBeforeParens = FormatStyle::SBPO_Custom;
+  SpaceFuncDecl.SpaceBeforeParensOptions.AfterFunctionDeclarationName = true;
+

are you testing the -ve case anywhere?


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

https://reviews.llvm.org/D110833

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


[PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2021-11-29 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/include/llvm/Support/Compiler.h:106-108
 /// Sadly, this is separate from just rvalue reference support because GCC
 /// and MSVC implemented this later than everything else. This appears to be
 /// corrected in MSVC 2019 but not MSVC 2017.

jhenderson wrote:
> RKSimon wrote:
> > jhenderson wrote:
> > > Does this comment need changing?
> > An even bigger question is - can we get rid of the 
> > LLVM_HAS_RVALUE_REFERENCE_THIS define entirely now? Either as part of this 
> > patch or as a followup
> Yeah, another patch entirely to sort this would be fine.
I'll add a FIXME to this patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp:342
+  auto w = new int(x);
+}

carlosgalvezp wrote:
> carlosgalvezp wrote:
> > Quuxplusone wrote:
> > > What about
> > > ```
> > > template T foo(int i) { return T(i); }
> > > int main() {
> > > foo>(); // valid, OK(!)
> > > foo(); // valid, not OK
> > > }
> > > ```
> > > What about
> > > ```
> > > struct Widget { Widget(int); };
> > > using T = Widget;
> > > using U = Widget&;
> > > int i = 42;
> > > Widget t = T(i);  // valid, OK?
> > > Widget u = U(i);  // valid C++, should definitely not be OK
> > > ```
> > > https://quuxplusone.github.io/blog/2020/01/22/expression-list-in-functional-cast/
> > Good point, thanks! I've added the first one to the unit test.
> > 
> > Regarding the second check, I'm not sure if it's the scope of this check. 
> > This check does not care whether the constructor of the class is implicit 
> > or not - if you use a class type, then you are calling the constructor so 
> > it's fine. Same goes when it's a reference - in my opinion this check is 
> > not concerned with that.
> > 
> > I definitely see the problems that can arise from the example that you 
> > posted, but maybe it fits better as a separate check in the `bugprone` 
> > category? This check (`google-readability-casting`) is focused only about 
> > avoiding C-style casting, i.e. it's a readability/style/modernize matter 
> > IMO. If cpplint is not diagnosing that, I don't think this check should 
> > either.
> It seems I should be able to just add the second example as a test and 
> clang-tidy would warn but, what should be the fixit for it? A 
> `static_cast` would lead to compiler error (which I personally would 
> gladly take, but I don't know in general if we want clang-tidy to "fix" code 
> leading to compiler errors"). Adding an ad-hoc message for this particular 
> error seems out of the scope of a "readability" check. 
> 
> What do you guys think?
> It seems I should be able to just add the second example as a test and 
> clang-tidy would warn but, what should be the fixit for it?

If I run the second example, but with old style C casts instead:

Input:
```lang=cpp
struct Widget { Widget(int); };
using T = Widget;
using U = Widget&;
int i = 42;
Widget t = (T)(i);
Widget u = (U)(i);
```

Output after fixits:
```lang=cpp
struct Widget { Widget(int); };
using T = Widget;
using U = Widget&;
int i = 42;
Widget t = T(i);
Widget u = (U)(i);
```

I guess the fix `Widget t = T(i);` is OK as it is covered by this exception:
>You may use cast formats like `T(x)` only when `T` is a class type.

For the `Widget u = (U)(i);` line, clang-tidy has warned about it but not 
offered a fix.


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

https://reviews.llvm.org/D114427

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


[PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2021-11-29 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon updated this revision to Diff 390283.
RKSimon added a comment.

rebase and add FIXME


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/UsersManual.rst
  llvm/cmake/modules/CheckCompilerVersion.cmake
  llvm/docs/CMake.rst
  llvm/docs/GettingStarted.rst
  llvm/docs/GettingStartedVS.rst
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/Compiler.h

Index: llvm/include/llvm/Support/Compiler.h
===
--- llvm/include/llvm/Support/Compiler.h
+++ llvm/include/llvm/Support/Compiler.h
@@ -80,12 +80,21 @@
 /// * 1916: VS2017, version 15.9
 /// * 1920: VS2019, version 16.0
 /// * 1921: VS2019, version 16.1
+/// * 1922: VS2019, version 16.2
+/// * 1923: VS2019, version 16.3
+/// * 1924: VS2019, version 16.4
+/// * 1925: VS2019, version 16.5
+/// * 1926: VS2019, version 16.6
+/// * 1927: VS2019, version 16.7
+/// * 1928: VS2019, version 16.8 + 16.9
+/// * 1929: VS2019, version 16.10 + 16.11
+/// * 1930: VS2022, version 17.0
 #ifdef _MSC_VER
 #define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version))
 
-// We require at least MSVC 2017.
-#if !LLVM_MSC_PREREQ(1910)
-#error LLVM requires at least MSVC 2017.
+// We require at least VS 2019.
+#if !LLVM_MSC_PREREQ(1920)
+#error LLVM requires at least VS 2019.
 #endif
 
 #else
@@ -97,12 +106,8 @@
 /// Sadly, this is separate from just rvalue reference support because GCC
 /// and MSVC implemented this later than everything else. This appears to be
 /// corrected in MSVC 2019 but not MSVC 2017.
-#if __has_feature(cxx_rvalue_references) || defined(__GNUC__) ||   \
-LLVM_MSC_PREREQ(1920)
+/// FIXME: Remove LLVM_HAS_RVALUE_REFERENCE_THIS macro
 #define LLVM_HAS_RVALUE_REFERENCE_THIS 1
-#else
-#define LLVM_HAS_RVALUE_REFERENCE_THIS 0
-#endif
 
 /// Expands to '&' if ref-qualifiers for *this are supported.
 ///
Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -65,7 +65,7 @@
 Changes to building LLVM
 
 
-* ...
+* Building LLVM with Visual Studio now requires version 2019 or later.
 
 Changes to TableGen
 ---
Index: llvm/docs/GettingStartedVS.rst
===
--- llvm/docs/GettingStartedVS.rst
+++ llvm/docs/GettingStartedVS.rst
@@ -36,7 +36,7 @@
 
 Hardware
 
-Any system that can adequately run Visual Studio 2017 is fine. The LLVM
+Any system that can adequately run Visual Studio 2019 is fine. The LLVM
 source tree including the git index consumes approximately 3GB.
 Object files, libraries and executables consume approximately 5GB in
 Release mode and much more in Debug mode. SSD drive and >16GB RAM are
@@ -45,8 +45,8 @@
 
 Software
 
-You will need `Visual Studio `_ 2017 or
-higher, with the latest Update installed. Visual Studio Community Edition
+You will need `Visual Studio `_ 2019 or
+later, with the latest Update installed. Visual Studio Community Edition
 suffices.
 
 You will also need the `CMake `_ build system since it
Index: llvm/docs/GettingStarted.rst
===
--- llvm/docs/GettingStarted.rst
+++ llvm/docs/GettingStarted.rst
@@ -238,7 +238,7 @@
 * Clang 3.5
 * Apple Clang 6.0
 * GCC 5.1
-* Visual Studio 2017
+* Visual Studio 2019
 
 Anything older than these toolchains *may* work, but will require forcing the
 build system with a special option and is not really a supported host platform.
@@ -273,8 +273,8 @@
 This section mostly applies to Linux and older BSDs. On macOS, you should
 have a sufficiently modern Xcode, or you will likely need to upgrade until you
 do. Windows does not have a "system compiler", so you must install either Visual
-Studio 2017 or a recent version of mingw64. FreeBSD 10.0 and newer have a modern
-Clang as the system compiler.
+Studio 2019 (or later), or a recent version of mingw64. FreeBSD 10.0 and newer
+have a modern Clang as the system compiler.
 
 However, some Linux distributions and some other or older BSDs sometimes have
 extremely old versions of GCC. These steps attempt to help you upgrade you
Index: llvm/docs/CMake.rst
===
--- llvm/docs/CMake.rst
+++ llvm/docs/CMake.rst
@@ -447,9 +447,7 @@
   creation of certain convenience build system targets, such as the various
   ``install-*`` and ``check-*`` targets, since IDEs don't always deal well with
   a large number of targets. This is usually autodetected, but it can be
-  configured manually to explicitly control the generation of those targets. One
-  scenario where a manual override may be desirable is whe

[PATCH] D114441: [analyzer][NFC] Refactor AnalysisConsumer::getModeForDecl()

2021-11-29 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf37d4b6fee8: [analyzer][NFC] Refactor 
AnalysisConsumer::getModeForDecl() (authored by steakhal).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114441

Files:
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp


Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -591,16 +591,24 @@
   // - Main source file: run both path-sensitive and non-path-sensitive checks.
   // - Header files: run non-path-sensitive checks only.
   // - System headers: don't run any checks.
-  SourceManager &SM = Ctx->getSourceManager();
-  const Stmt *Body = D->getBody();
-  SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation();
-  SL = SM.getExpansionLoc(SL);
-
-  if (!Opts->AnalyzeAll && !Mgr->isInCodeFile(SL)) {
-if (SL.isInvalid() || SM.isInSystemHeader(SL))
-  return AM_None;
+  if (Opts->AnalyzeAll)
+return Mode;
+
+  const SourceManager &SM = Ctx->getSourceManager();
+
+  const SourceLocation Loc = [&SM](Decl *D) -> SourceLocation {
+const Stmt *Body = D->getBody();
+SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation();
+return SM.getExpansionLoc(SL);
+  }(D);
+
+  // Ignore system headers.
+  if (Loc.isInvalid() || SM.isInSystemHeader(Loc))
+return AM_None;
+
+  // Disable path sensitive analysis in user-headers.
+  if (!Mgr->isInCodeFile(Loc))
 return Mode & ~AM_Path;
-  }
 
   return Mode;
 }


Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -591,16 +591,24 @@
   // - Main source file: run both path-sensitive and non-path-sensitive checks.
   // - Header files: run non-path-sensitive checks only.
   // - System headers: don't run any checks.
-  SourceManager &SM = Ctx->getSourceManager();
-  const Stmt *Body = D->getBody();
-  SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation();
-  SL = SM.getExpansionLoc(SL);
-
-  if (!Opts->AnalyzeAll && !Mgr->isInCodeFile(SL)) {
-if (SL.isInvalid() || SM.isInSystemHeader(SL))
-  return AM_None;
+  if (Opts->AnalyzeAll)
+return Mode;
+
+  const SourceManager &SM = Ctx->getSourceManager();
+
+  const SourceLocation Loc = [&SM](Decl *D) -> SourceLocation {
+const Stmt *Body = D->getBody();
+SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation();
+return SM.getExpansionLoc(SL);
+  }(D);
+
+  // Ignore system headers.
+  if (Loc.isInvalid() || SM.isInSystemHeader(Loc))
+return AM_None;
+
+  // Disable path sensitive analysis in user-headers.
+  if (!Mgr->isInCodeFile(Loc))
 return Mode & ~AM_Path;
-  }
 
   return Mode;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] af37d4b - [analyzer][NFC] Refactor AnalysisConsumer::getModeForDecl()

2021-11-29 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-11-29T10:39:36+01:00
New Revision: af37d4b6fee8990d5b029796681b59e0d0390c28

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

LOG: [analyzer][NFC] Refactor AnalysisConsumer::getModeForDecl()

I just read this part of the code, and I found the nested ifs less
readable.

Reviewed By: martong

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp 
b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 31de49033ac2b..f692c68045eeb 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -591,16 +591,24 @@ AnalysisConsumer::getModeForDecl(Decl *D, AnalysisMode 
Mode) {
   // - Main source file: run both path-sensitive and non-path-sensitive checks.
   // - Header files: run non-path-sensitive checks only.
   // - System headers: don't run any checks.
-  SourceManager &SM = Ctx->getSourceManager();
-  const Stmt *Body = D->getBody();
-  SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation();
-  SL = SM.getExpansionLoc(SL);
-
-  if (!Opts->AnalyzeAll && !Mgr->isInCodeFile(SL)) {
-if (SL.isInvalid() || SM.isInSystemHeader(SL))
-  return AM_None;
+  if (Opts->AnalyzeAll)
+return Mode;
+
+  const SourceManager &SM = Ctx->getSourceManager();
+
+  const SourceLocation Loc = [&SM](Decl *D) -> SourceLocation {
+const Stmt *Body = D->getBody();
+SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation();
+return SM.getExpansionLoc(SL);
+  }(D);
+
+  // Ignore system headers.
+  if (Loc.isInvalid() || SM.isInSystemHeader(Loc))
+return AM_None;
+
+  // Disable path sensitive analysis in user-headers.
+  if (!Mgr->isInCodeFile(Loc))
 return Mode & ~AM_Path;
-  }
 
   return Mode;
 }



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


[PATCH] D114696: [clang-format] regressed default behavior for operator parentheses

2021-11-29 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: HazardyKnusperkeks, crayroud, curdeius, owenpan.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay requested review of this revision.

D110833: [clang-format] Refactor SpaceBeforeParens to add options 
 regressed behavior of spaces before 
parentheses for operators, this revision reverts that so that operators are 
handled as they were before.

I think in hindsight it was a mistake to try and consume operator behaviour in 
with the function behaviour, I think Operators can be considered a special 
style. Its seems the code is getting confused as to if this is a function 
declaration or definition.

I think latterly we can consider adding an operator parentheses specific custom 
option but this should have been explicitly called out as it can impact 
projects.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114696

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9164,6 +9164,11 @@
   // https://llvm.org/PR50629
   // verifyFormat("void f() { operator*(a & a); }");
   // verifyFormat("void f() { operator&(a, b * b); }");
+
+  verifyFormat("::operator delete(foo);");
+  verifyFormat("::operator new(n * sizeof(foo));");
+  verifyFormat("foo() { ::operator delete(foo); }");
+  verifyFormat("foo() { ::operator new(n * sizeof(foo)); }");
 }
 
 TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
@@ -14096,8 +14101,9 @@
   verifyFormat("static_assert (sizeof (char) == 1, \"Impossible!\");", Space);
   verifyFormat("int f () throw (Deprecated);", Space);
   verifyFormat("typedef void (*cb) (int);", Space);
-  verifyFormat("T A::operator() ();", Space);
-  verifyFormat("X A::operator++ (T);", Space);
+  // FIXME these tests regressed behaviour.
+  // verifyFormat("T A::operator() ();", Space);
+  // verifyFormat("X A::operator++ (T);", Space);
   verifyFormat("auto lambda = [] () { return 0; };", Space);
   verifyFormat("int x = int (y);", Space);
 
@@ -14153,7 +14159,8 @@
   verifyFormat("int f() throw (Deprecated);", SomeSpace);
   verifyFormat("typedef void (*cb) (int);", SomeSpace);
   verifyFormat("T A::operator()();", SomeSpace);
-  verifyFormat("X A::operator++ (T);", SomeSpace);
+  // FIXME these tests regressed behaviour.
+  // verifyFormat("X A::operator++ (T);", SomeSpace);
   verifyFormat("int x = int (y);", SomeSpace);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace);
 
@@ -14209,8 +14216,9 @@
SpaceFuncDecl);
   verifyFormat("int f () throw(Deprecated);", SpaceFuncDecl);
   verifyFormat("typedef void (*cb)(int);", SpaceFuncDecl);
-  verifyFormat("T A::operator() ();", SpaceFuncDecl);
-  verifyFormat("X A::operator++ (T);", SpaceFuncDecl);
+  // FIXME these tests regressed behaviour.
+  // verifyFormat("T A::operator() ();", SpaceFuncDecl);
+  // verifyFormat("X A::operator++ (T);", SpaceFuncDecl);
   verifyFormat("T A::operator()() {}", SpaceFuncDecl);
   verifyFormat("auto lambda = []() { return 0; };", SpaceFuncDecl);
   verifyFormat("int x = int(y);", SpaceFuncDecl);
@@ -14245,7 +14253,7 @@
   verifyFormat("typedef void (*cb)(int);", SpaceFuncDef);
   verifyFormat("T A::operator()();", SpaceFuncDef);
   verifyFormat("X A::operator++(T);", SpaceFuncDef);
-  verifyFormat("T A::operator() () {}", SpaceFuncDef);
+  // verifyFormat("T A::operator() () {}", SpaceFuncDef);
   verifyFormat("auto lambda = [] () { return 0; };", SpaceFuncDef);
   verifyFormat("int x = int(y);", SpaceFuncDef);
   verifyFormat("M(std::size_t R, std::size_t C) : C(C), data(R) {}",
@@ -14320,7 +14328,7 @@
   verifyFormat("int f() throw (Deprecated);", SomeSpace2);
   verifyFormat("typedef void (*cb) (int);", SomeSpace2);
   verifyFormat("T A::operator()();", SomeSpace2);
-  verifyFormat("X A::operator++ (T);", SomeSpace2);
+  // verifyFormat("X A::operator++ (T);", SomeSpace2);
   verifyFormat("int x = int (y);", SomeSpace2);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
 }
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3169,9 +3169,13 @@
 if (Left.isIf(Line.Type != LT_PreprocessorDirective))
   return Style.SpaceBeforeParensOptions.AfterControlStatements ||
  spaceRequiredBeforeParens(Right);
+
+// TODO add Operator overloading specific Options to
+// SpaceBeforeParensOptions
+if (Right.is(TT_OverloadedOperatorLParen))
+  return spaceRequiredBeforeParens(Right);
 // Function declaration or definition
-if (Line.MightBeFunctionDecl && (Left.is(TT_FunctionDeclarationName) ||
- Righ

[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz added a comment.

I think the primary goal is satisfied - in all cases the cast is identified and 
a warning is generated.

For the `Widget&` case, a warning is generated but no fixit is offered, but 
that isn't any worse than the existing C-style cast fixits.
It does sound like a case where offering no fix is better than offering a fix 
that makes things worse.

What would be the right fixit for that anyway?
`Widget u = U(i);   -->   Widget u = T(i);` ?


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

https://reviews.llvm.org/D114427

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


[PATCH] D114326: Update the list of CUDA versions up to 11.5

2021-11-29 Thread Mojca Miklavec via Phabricator via cfe-commits
mojca added a comment.

@tra: what should be done about the unit test that checks whether CUDA SDK 8.0 
specifically has been found?
Apparently you are taking care of the buildbot configuration performing those 
tests.

And how should we proceed in general, what can I do next? Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114326

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


[PATCH] D91000: [clang-tidy] Add cert-msc24-c checker.

2021-11-29 Thread Balázs Benics via Phabricator via cfe-commits
steakhal resigned from this revision.
steakhal added a comment.

I've already reviewed this change offline, thus I resign. For me this looks 
great, I'm eager to hear your opinions!


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

https://reviews.llvm.org/D91000

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


[PATCH] D114421: [asan] Add support for disable_sanitizer_instrumentation attribute

2021-11-29 Thread Alexander Potapenko via Phabricator via cfe-commits
glider added a comment.

Vitaly, Evgenii, can one of you please take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114421

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


[PATCH] D113995: [clangd] Dex Trigrams: Improve query trigram generation

2021-11-29 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 390297.
kbobyrev marked 5 inline comments as done.
kbobyrev added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113995

Files:
  clang-tools-extra/clangd/index/dex/Trigram.cpp
  clang-tools-extra/clangd/unittests/DexTests.cpp

Index: clang-tools-extra/clangd/unittests/DexTests.cpp
===
--- clang-tools-extra/clangd/unittests/DexTests.cpp
+++ clang-tools-extra/clangd/unittests/DexTests.cpp
@@ -386,30 +386,35 @@
   trigramsAre({"c", "cl", "cla", "lan", "ang", "ngd"}));
 
   EXPECT_THAT(identifierTrigramTokens("abc_def"),
-  trigramsAre({"a", "ab", "ad", "abc", "abd", "ade", "bcd", "bde",
-   "cde", "def"}));
+  trigramsAre({"a", "d", "ab", "ad", "de", "abc", "abd", "ade",
+   "bcd", "bde", "cde", "def"}));
 
   EXPECT_THAT(identifierTrigramTokens("a_b_c_d_e_"),
-  trigramsAre({"a", "a_", "ab", "abc", "bcd", "cde"}));
+  trigramsAre({"a", "b", "ab", "bc", "abc", "bcd", "cde"}));
 
   EXPECT_THAT(identifierTrigramTokens("unique_ptr"),
-  trigramsAre({"u", "un", "up", "uni", "unp", "upt", "niq", "nip",
-   "npt", "iqu", "iqp", "ipt", "que", "qup", "qpt",
-   "uep", "ept", "ptr"}));
+  trigramsAre({"u",   "p",   "un",  "up",  "pt",  "uni", "unp",
+   "upt", "niq", "nip", "npt", "iqu", "iqp", "ipt",
+   "que", "qup", "qpt", "uep", "ept", "ptr"}));
 
-  EXPECT_THAT(
-  identifierTrigramTokens("TUDecl"),
-  trigramsAre({"t", "tu", "td", "tud", "tde", "ude", "dec", "ecl"}));
+  EXPECT_THAT(identifierTrigramTokens("TUDecl"),
+  trigramsAre({"t", "d", "tu", "td", "de", "tud", "tde", "ude",
+   "dec", "ecl"}));
 
   EXPECT_THAT(identifierTrigramTokens("IsOK"),
-  trigramsAre({"i", "is", "io", "iso", "iok", "sok"}));
+  trigramsAre({"i", "o", "is", "ok", "io", "iso", "iok", "sok"}));
 
-  EXPECT_THAT(
-  identifierTrigramTokens("abc_defGhij__klm"),
-  trigramsAre({"a",   "ab",  "ad",  "abc", "abd", "ade", "adg", "bcd",
-   "bde", "bdg", "cde", "cdg", "def", "deg", "dgh", "dgk",
-   "efg", "egh", "egk", "fgh", "fgk", "ghi", "ghk", "gkl",
-   "hij", "hik", "hkl", "ijk", "ikl", "jkl", "klm"}));
+  EXPECT_THAT(identifierTrigramTokens("_pb"),
+  trigramsAre({"_", "_p", "p", "pb"}));
+  EXPECT_THAT(identifierTrigramTokens("__pb"),
+  trigramsAre({"_", "_p", "p", "pb"}));
+
+  EXPECT_THAT(identifierTrigramTokens("abc_defGhij__klm"),
+  trigramsAre({"a",   "d",   "ab",  "ad",  "dg",  "de",  "abc",
+   "abd", "ade", "adg", "bcd", "bde", "bdg", "cde",
+   "cdg", "def", "deg", "dgh", "dgk", "efg", "egh",
+   "egk", "fgh", "fgk", "ghi", "ghk", "gkl", "hij",
+   "hik", "hkl", "ijk", "ikl", "jkl", "klm"}));
 }
 
 TEST(DexTrigrams, QueryTrigrams) {
@@ -419,8 +424,16 @@
 
   EXPECT_THAT(generateQueryTrigrams(""), trigramsAre({}));
   EXPECT_THAT(generateQueryTrigrams("_"), trigramsAre({"_"}));
-  EXPECT_THAT(generateQueryTrigrams("__"), trigramsAre({"__"}));
-  EXPECT_THAT(generateQueryTrigrams("___"), trigramsAre({}));
+  EXPECT_THAT(generateQueryTrigrams("__"), trigramsAre({"_"}));
+  EXPECT_THAT(generateQueryTrigrams("___"), trigramsAre({"_"}));
+
+  EXPECT_THAT(generateQueryTrigrams("m_"), trigramsAre({"m"}));
+
+  EXPECT_THAT(generateQueryTrigrams("p_b"), trigramsAre({"pb"}));
+  EXPECT_THAT(generateQueryTrigrams("pb_"), trigramsAre({"pb"}));
+  EXPECT_THAT(generateQueryTrigrams("_p"), trigramsAre({"_p"}));
+  EXPECT_THAT(generateQueryTrigrams("_pb_"), trigramsAre({"pb"}));
+  EXPECT_THAT(generateQueryTrigrams("__pb"), trigramsAre({"pb"}));
 
   EXPECT_THAT(generateQueryTrigrams("X86"), trigramsAre({"x86"}));
 
@@ -525,25 +538,45 @@
 }
 
 TEST(DexTest, ShortQuery) {
-  auto I = Dex::build(generateSymbols({"OneTwoThreeFour"}), RefSlab(),
+  auto I = Dex::build(generateSymbols({"_OneTwoFourSix"}), RefSlab(),
   RelationSlab());
   FuzzyFindRequest Req;
   Req.AnyScope = true;
   bool Incomplete;
 
-  EXPECT_THAT(match(*I, Req, &Incomplete), ElementsAre("OneTwoThreeFour"));
+  EXPECT_THAT(match(*I, Req, &Incomplete), ElementsAre("_OneTwoFourSix"));
   EXPECT_FALSE(Incomplete) << "Empty string is not a short query";
 
-  Req.Query = "t";
-  EXPECT_THAT(match(*I, Req, &Incomplete), ElementsAre());
-  EXPECT_TRUE(Incomplete) << "Short queries have different semantics";
+  Req.Query = "o";
+  EXPECT_THAT(match(*I, Req, &Incomplete), ElementsAre("_OneTwoFourSix"));
+  EXPECT_TRUE(Incomplete) << "Using first head as unigram

[PATCH] D113995: [clangd] Dex Trigrams: Improve query trigram generation

2021-11-29 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 390298.
kbobyrev added a comment.

Slightly improve docs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113995

Files:
  clang-tools-extra/clangd/index/dex/Trigram.cpp
  clang-tools-extra/clangd/unittests/DexTests.cpp

Index: clang-tools-extra/clangd/unittests/DexTests.cpp
===
--- clang-tools-extra/clangd/unittests/DexTests.cpp
+++ clang-tools-extra/clangd/unittests/DexTests.cpp
@@ -386,30 +386,35 @@
   trigramsAre({"c", "cl", "cla", "lan", "ang", "ngd"}));
 
   EXPECT_THAT(identifierTrigramTokens("abc_def"),
-  trigramsAre({"a", "ab", "ad", "abc", "abd", "ade", "bcd", "bde",
-   "cde", "def"}));
+  trigramsAre({"a", "d", "ab", "ad", "de", "abc", "abd", "ade",
+   "bcd", "bde", "cde", "def"}));
 
   EXPECT_THAT(identifierTrigramTokens("a_b_c_d_e_"),
-  trigramsAre({"a", "a_", "ab", "abc", "bcd", "cde"}));
+  trigramsAre({"a", "b", "ab", "bc", "abc", "bcd", "cde"}));
 
   EXPECT_THAT(identifierTrigramTokens("unique_ptr"),
-  trigramsAre({"u", "un", "up", "uni", "unp", "upt", "niq", "nip",
-   "npt", "iqu", "iqp", "ipt", "que", "qup", "qpt",
-   "uep", "ept", "ptr"}));
+  trigramsAre({"u",   "p",   "un",  "up",  "pt",  "uni", "unp",
+   "upt", "niq", "nip", "npt", "iqu", "iqp", "ipt",
+   "que", "qup", "qpt", "uep", "ept", "ptr"}));
 
-  EXPECT_THAT(
-  identifierTrigramTokens("TUDecl"),
-  trigramsAre({"t", "tu", "td", "tud", "tde", "ude", "dec", "ecl"}));
+  EXPECT_THAT(identifierTrigramTokens("TUDecl"),
+  trigramsAre({"t", "d", "tu", "td", "de", "tud", "tde", "ude",
+   "dec", "ecl"}));
 
   EXPECT_THAT(identifierTrigramTokens("IsOK"),
-  trigramsAre({"i", "is", "io", "iso", "iok", "sok"}));
+  trigramsAre({"i", "o", "is", "ok", "io", "iso", "iok", "sok"}));
 
-  EXPECT_THAT(
-  identifierTrigramTokens("abc_defGhij__klm"),
-  trigramsAre({"a",   "ab",  "ad",  "abc", "abd", "ade", "adg", "bcd",
-   "bde", "bdg", "cde", "cdg", "def", "deg", "dgh", "dgk",
-   "efg", "egh", "egk", "fgh", "fgk", "ghi", "ghk", "gkl",
-   "hij", "hik", "hkl", "ijk", "ikl", "jkl", "klm"}));
+  EXPECT_THAT(identifierTrigramTokens("_pb"),
+  trigramsAre({"_", "_p", "p", "pb"}));
+  EXPECT_THAT(identifierTrigramTokens("__pb"),
+  trigramsAre({"_", "_p", "p", "pb"}));
+
+  EXPECT_THAT(identifierTrigramTokens("abc_defGhij__klm"),
+  trigramsAre({"a",   "d",   "ab",  "ad",  "dg",  "de",  "abc",
+   "abd", "ade", "adg", "bcd", "bde", "bdg", "cde",
+   "cdg", "def", "deg", "dgh", "dgk", "efg", "egh",
+   "egk", "fgh", "fgk", "ghi", "ghk", "gkl", "hij",
+   "hik", "hkl", "ijk", "ikl", "jkl", "klm"}));
 }
 
 TEST(DexTrigrams, QueryTrigrams) {
@@ -419,8 +424,16 @@
 
   EXPECT_THAT(generateQueryTrigrams(""), trigramsAre({}));
   EXPECT_THAT(generateQueryTrigrams("_"), trigramsAre({"_"}));
-  EXPECT_THAT(generateQueryTrigrams("__"), trigramsAre({"__"}));
-  EXPECT_THAT(generateQueryTrigrams("___"), trigramsAre({}));
+  EXPECT_THAT(generateQueryTrigrams("__"), trigramsAre({"_"}));
+  EXPECT_THAT(generateQueryTrigrams("___"), trigramsAre({"_"}));
+
+  EXPECT_THAT(generateQueryTrigrams("m_"), trigramsAre({"m"}));
+
+  EXPECT_THAT(generateQueryTrigrams("p_b"), trigramsAre({"pb"}));
+  EXPECT_THAT(generateQueryTrigrams("pb_"), trigramsAre({"pb"}));
+  EXPECT_THAT(generateQueryTrigrams("_p"), trigramsAre({"_p"}));
+  EXPECT_THAT(generateQueryTrigrams("_pb_"), trigramsAre({"pb"}));
+  EXPECT_THAT(generateQueryTrigrams("__pb"), trigramsAre({"pb"}));
 
   EXPECT_THAT(generateQueryTrigrams("X86"), trigramsAre({"x86"}));
 
@@ -525,25 +538,45 @@
 }
 
 TEST(DexTest, ShortQuery) {
-  auto I = Dex::build(generateSymbols({"OneTwoThreeFour"}), RefSlab(),
+  auto I = Dex::build(generateSymbols({"_OneTwoFourSix"}), RefSlab(),
   RelationSlab());
   FuzzyFindRequest Req;
   Req.AnyScope = true;
   bool Incomplete;
 
-  EXPECT_THAT(match(*I, Req, &Incomplete), ElementsAre("OneTwoThreeFour"));
+  EXPECT_THAT(match(*I, Req, &Incomplete), ElementsAre("_OneTwoFourSix"));
   EXPECT_FALSE(Incomplete) << "Empty string is not a short query";
 
-  Req.Query = "t";
-  EXPECT_THAT(match(*I, Req, &Incomplete), ElementsAre());
-  EXPECT_TRUE(Incomplete) << "Short queries have different semantics";
+  Req.Query = "o";
+  EXPECT_THAT(match(*I, Req, &Incomplete), ElementsAre("_OneTwoFourSix"));
+  EXPECT_TRUE(Incomplete) << "Using first head as unigram";
+
+  Req.Query = "_o";
+  EXPECT_THAT(matc

[PATCH] D114441: [analyzer][NFC] Refactor AnalysisConsumer::getModeForDecl()

2021-11-29 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:599-603
+  const SourceLocation Loc = [&SM](Decl *D) -> SourceLocation {
+const Stmt *Body = D->getBody();
+SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation();
+return SM.getExpansionLoc(SL);
+  }(D);

Why don't just leave this snippet as it was but add `const SourceLocation Loc` 
instead of re-assigning `SL`? Your construction made me stumbled for a while. 
As this patch is meant to bring readability, I wouldn't like to see such a 
code-trick. I see your intention to hide `SL` but IMO let compiler do this for 
us. See suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114441

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


[PATCH] D114251: [AST] Add a sugar type for types found via UsingDecl

2021-11-29 Thread David Rector via Phabricator via cfe-commits
davrec accepted this revision.
davrec added a comment.
This revision is now accepted and ready to land.

Looks great, thanks for identifying the need and banging this out so quickly.
Hope you had some time to enjoy the holiday with your family!
Dave




Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:2106
+TRY_TO(TraverseDecl(Child));
+}
   }

So the idea is, the UsingDecl which introduced the shadows will have already 
been traversed within its DeclStmt via the body traversal, but not the 
UsingShadowDecls it introduced?  Nicely spotted.



Comment at: clang/include/clang/AST/Type.h:4381
+public:
+  NamedDecl *getFoundDecl() const { return Found; }
+  QualType getUnderlyingType() const { return UnderlyingTy; }

sammccall wrote:
> davrec wrote:
> >  I would rename this to `getDecl()`, to match the interface for other types 
> > that just wrap a decl.  E.g. if something is a RecordType I know I can call 
> > getDecl() to get the RecordDecl; likewise a TypedefType::getDecl() returns 
> > a TypedefNameDecl; I think it would follow this pattern for UsingType to 
> > have a getDecl() method that returns a UsingShadowDecl (or whatever else it 
> > can be, per other question).
> > 
> I do prefer `getFoundDecl()` for a few reasons:
>  - the parallel with `NamedDecl::getFoundDecl()` is closer/more important 
> than with `TypedefDecl` I think
>  - there are always two decls here: the invisible UsingShadowDecl and the 
> underlying one. Saying "decl" without a hint seems error-prone to me. 
> (Compare with TypedefType where in general there's no underlying decl).
>  - I **do** find TypedefType::getDecl() confusing, because wherever I see it 
> called I have to verify that it's TypedefType::getDecl() rather than some 
> Type::getDecl() to be sure I understand the semantics.
> 
> Would be happy to hear a third opinion here though.
I'm persuaded by your reasoning, particularly that UsingShadowDecl is invisible 
and thus returning one already introduces some confusion -- i.e. a user might 
reasonably expect getDecl() to return a UsingDecl, so better to call this 
something with other parallels.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114251

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


[PATCH] D114696: [clang-format] regressed default behavior for operator parentheses

2021-11-29 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114696

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


[PATCH] D114696: [clang-format] regressed default behavior for operator parentheses

2021-11-29 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

@crayroud I'm going to commit this change to get past the regression, but we 
can continue to discuss here how you'd like to proceed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114696

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


[PATCH] D91000: [clang-tidy] Add cert-msc24-c checker.

2021-11-29 Thread Fütő Gergely via Phabricator via cfe-commits
futogergely updated this revision to Diff 390309.
futogergely added a comment.

x64 debian failed


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

https://reviews.llvm.org/D91000

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

Index: clang-tools-extra/test/clang-tidy/checkers/cert-msc24-c.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-msc24-c.c
@@ -0,0 +1,97 @@
+// RUN: %check_clang_tidy -check-suffix=WITH-ANNEX-K%s cert-msc24-c %t -- -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-c %t -- -- -U__STDC_LIB_EXT1__   -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-c %t -- -- -D__STDC_LIB_EXT1__=1 -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-c %t -- -- -U__STDC_LIB_EXT1__   -D__STDC_WANT_LIB_EXT1__=1
+
+typedef void *FILE;
+char *gets(char *s);
+void rewind(FILE *stream);
+void setbuf(FILE *stream, char *buf);
+
+void f1(char *s, FILE *f) {
+  gets(s);
+  // CHECK-MESSAGES-WITH-ANNEX-K::[[@LINE-1]]:3: warning: function 'gets' is deprecated as of C99, removed from C11.
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-2]]:3: warning: function 'gets' is deprecated as of C99, removed from C11.
+
+  rewind(f);
+  // CHECK-MESSAGES-WITH-ANNEX-K::[[@LINE-1]]:3: warning: function 'rewind' has no error detection; 'fseek' should be used instead.
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-2]]:3: warning: function 'rewind' has no error detection; 'fseek' should be used instead.
+
+  setbuf(f, s);
+  // CHECK-MESSAGES-WITH-ANNEX-K::[[@LINE-1]]:3: warning: function 'setbuf' has no error detection; 'setvbuf' should be used instead.
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-2]]:3: warning: function 'setbuf' has no error detection; 'setvbuf' should be used instead.
+}
+
+struct tm;
+char *asctime(const struct tm *timeptr);
+
+void f2(const struct tm *timeptr) {
+  asctime(timeptr);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'asctime' is non-reentrant; 'asctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  char *(*f_ptr1)(const struct tm *) = asctime;
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:40: warning: function 'asctime' is non-reentrant; 'asctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  char *(*f_ptr2)(const struct tm *) = &asctime;
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:41: warning: function 'asctime' is non-reentrant; 'asctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+}
+
+FILE *fopen(const char *filename, const char *mode);
+FILE *freopen(const char *filename, const char *mode, FILE *stream);
+int fscanf(FILE *stream, const char *format, ...);
+
+void f3(char *s, FILE *f) {
+  fopen(s, s);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'fopen' has no exclusive access to file; 'fopen_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  freopen(s, s, f);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'freopen' has no exclusive access to file; 'freopen_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  int i;
+  fscanf(f, "%d", &i);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'fscanf' is obsolescent; 'fscanf_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+}
+
+typedef int time_t;
+char *ctime(const time_t *timer);
+
+void f4(const time_t *timer) {
+  ctime(timer);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'ctime' is non-reentrant; 'ctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+}
+
+typedef int errno_t;
+typedef __SIZE_TYPE__ size_t;
+typedef size_t rsize_t;
+errno_t asctime_s(char *s, rsize_t maxsize, const struct tm *timeptr);
+errno_t strcat_s(char *s1, rsize_t s1max, const char *s2);
+int fseek(FILE *stream, long int offset, int whence);
+int setvbuf(FILE *stream, char *buf, int mode, size_t size);
+
+void fUsingSafeFunctions(const struct tm *timeptr, FILE *f) {
+  const size_t BUFFSIZE = 32;
+  char buf[BUFFSIZE] = {0};
+
+  // no-warning, safe function from annex K is used
+  if (asctime_s(buf, BUFFSIZE, timeptr) != 0)
+return;
+
+  // no-warning, safe function from annex K is used
+  if (strcat_s(buf, BUFFSIZE, "something") != 0)
+return;
+
+  // no-warning, fseeks supports error checking
+  if (fseek(f, 0, 0) != 0)
+return;
+
+  // no-warning, setvb

[clang-tools-extra] d96f92f - fix typos in comments

2021-11-29 Thread Sylvestre Ledru via cfe-commits

Author: Zhuo Zhang
Date: 2021-11-29T14:06:33+01:00
New Revision: d96f92ff16edab72cf78811673f02371f07a5a70

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

LOG: fix typos in comments

Added: 


Modified: 
clang-tools-extra/clang-doc/ClangDoc.h
llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
llvm/test/tools/llvm-objcopy/ELF/Inputs/ihex-elf-sections.yaml

Removed: 




diff  --git a/clang-tools-extra/clang-doc/ClangDoc.h 
b/clang-tools-extra/clang-doc/ClangDoc.h
index f3820d2c71d27..1f0c43d70db17 100644
--- a/clang-tools-extra/clang-doc/ClangDoc.h
+++ b/clang-tools-extra/clang-doc/ClangDoc.h
@@ -6,7 +6,7 @@
 //
 
//===--===//
 //
-// This file exposes a method to craete the FrontendActionFactory for the
+// This file exposes a method to create the FrontendActionFactory for the
 // clang-doc tool. The factory runs the clang-doc mapper on a given set of
 // source code files, storing the results key-value pairs in its
 // ExecutionContext.

diff  --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp 
b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
index 1b7fdb5882756..0de76ab78e0fd 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -1301,7 +1301,7 @@ RuntimeDyldELF::processRelocationRef(
 MemMgr.allowStubAllocation()) {
   resolveAArch64Branch(SectionID, Value, RelI, Stubs);
 } else if (RelType == ELF::R_AARCH64_ADR_GOT_PAGE) {
-  // Craete new GOT entry or find existing one. If GOT entry is
+  // Create new GOT entry or find existing one. If GOT entry is
   // to be created, then we also emit ABS64 relocation for it.
   uint64_t GOTOffset = findOrAllocGOTEntry(Value, ELF::R_AARCH64_ABS64);
   resolveGOTOffsetRelocation(SectionID, Offset, GOTOffset + Addend,

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/Inputs/ihex-elf-sections.yaml 
b/llvm/test/tools/llvm-objcopy/ELF/Inputs/ihex-elf-sections.yaml
index 9a71b3175efaa..8a534332a6525 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/Inputs/ihex-elf-sections.yaml
+++ b/llvm/test/tools/llvm-objcopy/ELF/Inputs/ihex-elf-sections.yaml
@@ -33,7 +33,7 @@ Sections:
   - Name:.data3
 # The last section not only overlaps segment boundary, but
 # also has linear address which doesn't fit 20 bits. The 
-# following records should be craeted:
+# following records should be created:
 # 'SegmentAddr'(02) record with address 0x0
 # 'ExtendedAddr'(04) record with address 0x10
 # 'Data'(00) record with 8 bytes of section data



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


[PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2021-11-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Have you checked whether there are any bots in the lab that will need to be 
updated?




Comment at: clang/docs/UsersManual.rst:3546
 
-cmake -G"Visual Studio 15 2017" -T LLVM ..
+cmake -G"Visual Studio 17 2022" -T LLVM ..
 

jhenderson wrote:
> I think the missing space should be fixed to :)
+1 to the missing space.



Comment at: llvm/cmake/modules/CheckCompilerVersion.cmake:17-18
+# _MSC_VER == 1929 MSVC++ 14.29 Visual Studio 2019 Version 16.10 & 16.11
+set(MSVC_MIN 19.20)
+set(MSVC_SOFT_ERROR 19.29)
 

I'm a bit less certain that this is reasonable. 16.11.0 is from August 2021, 
which seems incredibly new for giving soft errors on.



Comment at: llvm/include/llvm/Support/Compiler.h:106-108
 /// Sadly, this is separate from just rvalue reference support because GCC
 /// and MSVC implemented this later than everything else. This appears to be
 /// corrected in MSVC 2019 but not MSVC 2017.

RKSimon wrote:
> jhenderson wrote:
> > RKSimon wrote:
> > > jhenderson wrote:
> > > > Does this comment need changing?
> > > An even bigger question is - can we get rid of the 
> > > LLVM_HAS_RVALUE_REFERENCE_THIS define entirely now? Either as part of 
> > > this patch or as a followup
> > Yeah, another patch entirely to sort this would be fine.
> I'll add a FIXME to this patch
+1; FWIW, the last time we tried to get rid of this, the only thing we could 
realistically do was remove it and see how the bots/community reacted. Doing 
that in a follow-up patch seems like a good idea to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

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


[PATCH] D112420: [clang][ARM] PACBTI-M assembly support

2021-11-29 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 390314.
stuij marked 2 inline comments as done.
stuij added a comment.

addressed review comment and clang-format suggestions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112420

Files:
  clang/test/Driver/armv8.1m.main.c
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/include/llvm/Support/ARMTargetParser.h
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMInstrThumb2.td
  llvm/lib/Target/ARM/ARMPredicates.td
  llvm/lib/Target/ARM/ARMRegisterInfo.td
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/lib/Target/ARM/ARMSystemRegister.td
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
  llvm/test/CodeGen/Thumb/high-reg-clobber.mir
  llvm/test/MC/ARM/armv8.1m-pacbti-error.s
  llvm/test/MC/ARM/armv8.1m-pacbti.s
  llvm/test/MC/ARM/implicit-it-generation-v8.s
  llvm/test/MC/Disassembler/ARM/armv8.1m-pacbti.txt

Index: llvm/test/MC/Disassembler/ARM/armv8.1m-pacbti.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/ARM/armv8.1m-pacbti.txt
@@ -0,0 +1,137 @@
+# RUN: llvm-mc -triple thumbv8.1m.main-arm-none-eabi -mattr=+pacbti -disassemble %s 2> /dev/null | FileCheck %s
+
+0x51,0xfb,0x02,0x0f
+0x5e,0xfb,0x0d,0xcf
+0xaf,0xf3,0x2d,0x80
+0x51,0xfb,0x12,0x0f
+0xaf,0xf3,0x0f,0x80
+0x61,0xfb,0x02,0xf0
+0x6e,0xfb,0x0d,0xfc
+0xaf,0xf3,0x1d,0x80
+0xaf,0xf3,0x0d,0x80
+0x80,0xf3,0x20,0x88
+0x80,0xf3,0x21,0x88
+0x80,0xf3,0x22,0x88
+0x80,0xf3,0x23,0x88
+0x80,0xf3,0x24,0x88
+0x80,0xf3,0x25,0x88
+0x80,0xf3,0x26,0x88
+0x80,0xf3,0x27,0x88
+0x80,0xf3,0xa0,0x88
+0x80,0xf3,0xa1,0x88
+0x80,0xf3,0xa2,0x88
+0x80,0xf3,0xa3,0x88
+0x80,0xf3,0xa4,0x88
+0x80,0xf3,0xa5,0x88
+0x80,0xf3,0xa6,0x88
+0x80,0xf3,0xa7,0x88
+0xef,0xf3,0x20,0x80
+0xef,0xf3,0x21,0x80
+0xef,0xf3,0x22,0x80
+0xef,0xf3,0x23,0x80
+0xef,0xf3,0x24,0x80
+0xef,0xf3,0x25,0x80
+0xef,0xf3,0x26,0x80
+0xef,0xf3,0x27,0x80
+0xef,0xf3,0xa0,0x80
+0xef,0xf3,0xa1,0x80
+0xef,0xf3,0xa2,0x80
+0xef,0xf3,0xa3,0x80
+0xef,0xf3,0xa4,0x80
+0xef,0xf3,0xa5,0x80
+0xef,0xf3,0xa6,0x80
+0xef,0xf3,0xa7,0x80
+
+# Test softfail encodings
+0xa7,0xf3,0x1d,0x80
+0xab,0xf3,0x1d,0x80
+0xad,0xf3,0x1d,0x80
+0xae,0xf3,0x1d,0x80
+0xaf,0xf3,0x1d,0x88
+0xaf,0xf3,0x1d,0xa0
+0xaf,0xf3,0x2d,0x80
+0xab,0xf3,0x2d,0x80
+0xad,0xf3,0x2d,0x80
+0xae,0xf3,0x2d,0x80
+0xaf,0xf3,0x2d,0x88
+0xaf,0xf3,0x2d,0xa0
+0xa7,0xf3,0x0f,0x80
+0xab,0xf3,0x0f,0x80
+0xad,0xf3,0x0f,0x80
+0xae,0xf3,0x0f,0x80
+0xaf,0xf3,0x0f,0x88
+0xaf,0xf3,0x0f,0xa0
+0xa7,0xf3,0x0d,0x80
+0xab,0xf3,0x0d,0x80
+0xad,0xf3,0x0d,0x80
+0xae,0xf3,0x0d,0x80
+0xaf,0xf3,0x0d,0x88
+0xaf,0xf3,0x0d,0xa0
+
+# CHECK: autg	r0, r1, r2
+# CHECK: autg r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: bxautr0, r1, r2
+# CHECK: bti
+# CHECK: pacg	r0, r1, r2
+# CHECK: pacg	r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
+# CHECK: msr	pac_key_p_0, r0
+# CHECK: msr	pac_key_p_1, r0
+# CHECK: msr	pac_key_p_2, r0
+# CHECK: msr	pac_key_p_3, r0
+# CHECK: msr	pac_key_u_0, r0
+# CHECK: msr	pac_key_u_1, r0
+# CHECK: msr	pac_key_u_2, r0
+# CHECK: msr	pac_key_u_3, r0
+# CHECK: msr	pac_key_p_0_ns, r0
+# CHECK: msr	pac_key_p_1_ns, r0
+# CHECK: msr	pac_key_p_2_ns, r0
+# CHECK: msr	pac_key_p_3_ns, r0
+# CHECK: msr	pac_key_u_0_ns, r0
+# CHECK: msr	pac_key_u_1_ns, r0
+# CHECK: msr	pac_key_u_2_ns, r0
+# CHECK: msr	pac_key_u_3_ns, r0
+# CHECK: mrs	r0, pac_key_p_0
+# CHECK: mrs	r0, pac_key_p_1
+# CHECK: mrs	r0, pac_key_p_2
+# CHECK: mrs	r0, pac_key_p_3
+# CHECK: mrs	r0, pac_key_u_0
+# CHECK: mrs	r0, pac_key_u_1
+# CHECK: mrs	r0, pac_key_u_2
+# CHECK: mrs	r0, pac_key_u_3
+# CHECK: mrs	r0, pac_key_p_0_ns
+# CHECK: mrs	r0, pac_key_p_1_ns
+# CHECK: mrs	r0, pac_key_p_2_ns
+# CHECK: mrs	r0, pac_key_p_3_ns
+# CHECK: mrs	r0, pac_key_u_0_ns
+# CHECK: mrs	r0, pac_key_u_1_ns
+# CHECK: mrs	r0, pac_key_u_2_ns
+# CHECK: mrs	r0, pac_key_u_3_ns
+
+# Softfail encodings
+# CHECK: pac  r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: pac  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: aut  r12, lr, sp
+# CHECK: bti
+# CHECK: bti
+# CHECK: bti
+# CHECK: bti
+# CHECK: bti
+# CHECK: bti
+# CHECK: pacbti   r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
+# CHECK: pacbti   r12, lr, sp
Index: llvm/test/MC/ARM/implicit-it-generation-v8.s
===
--- /dev/null
+++ llvm/test/MC/ARM/implicit-it-generation-v8.s
@@ -0,0 +1,9 @@
+@ RUN: llvm-mc -triple thumbv8.1m.main-arm-none-eabi -arm-implicit-it=always -mattr=+pacbti < %s -show-encoding | FileCheck %s
+
+autgeq r0, r1

[PATCH] D112421: [clang][ARM] PACBTI-M frontend support

2021-11-29 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 390316.
stuij added a comment.

minor clang-format conformance changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112421

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/arm-branch-protection-attr-1.c
  clang/test/CodeGen/arm-branch-protection-attr-2.c
  clang/test/CodeGen/arm_neon_intrinsics.c
  clang/test/Driver/aarch64-security-options.c
  clang/test/Driver/arm-security-options.c
  clang/test/Frontend/arm-invalid-branch-protection.c
  clang/test/Sema/aarch64-branch-protection-attr-err.c
  clang/test/Sema/arm-branch-protection-attr-err.c
  clang/test/Sema/branch-protection-attr-err.c
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/lib/Support/TargetParser.cpp

Index: llvm/lib/Support/TargetParser.cpp
===
--- llvm/lib/Support/TargetParser.cpp
+++ llvm/lib/Support/TargetParser.cpp
@@ -333,3 +333,51 @@
 
 } // namespace RISCV
 } // namespace llvm
+
+// Parse a branch protection specification, which has the form
+//   standard | none | [bti,pac-ret[+b-key,+leaf]*]
+// Returns true on success, with individual elements of the specification
+// returned in `PBP`. Returns false in error, with `Err` containing
+// an erroneous part of the spec.
+bool ARM::parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
+StringRef &Err) {
+  PBP = {"none", "a_key", false};
+  if (Spec == "none")
+return true; // defaults are ok
+
+  if (Spec == "standard") {
+PBP.Scope = "non-leaf";
+PBP.BranchTargetEnforcement = true;
+return true;
+  }
+
+  SmallVector Opts;
+  Spec.split(Opts, "+");
+  for (int I = 0, E = Opts.size(); I != E; ++I) {
+StringRef Opt = Opts[I].trim();
+if (Opt == "bti") {
+  PBP.BranchTargetEnforcement = true;
+  continue;
+}
+if (Opt == "pac-ret") {
+  PBP.Scope = "non-leaf";
+  for (; I + 1 != E; ++I) {
+StringRef PACOpt = Opts[I + 1].trim();
+if (PACOpt == "leaf")
+  PBP.Scope = "all";
+else if (PACOpt == "b-key")
+  PBP.Key = "b_key";
+else
+  break;
+  }
+  continue;
+}
+if (Opt == "")
+  Err = "";
+else
+  Err = Opt;
+return false;
+  }
+
+  return true;
+}
Index: llvm/lib/Support/AArch64TargetParser.cpp
===
--- llvm/lib/Support/AArch64TargetParser.cpp
+++ llvm/lib/Support/AArch64TargetParser.cpp
@@ -240,52 +240,4 @@
   return C.ArchID;
   }
   return ArchKind::INVALID;
-}
-
-// Parse a branch protection specification, which has the form
-//   standard | none | [bti,pac-ret[+b-key,+leaf]*]
-// Returns true on success, with individual elements of the specification
-// returned in `PBP`. Returns false in error, with `Err` containing
-// an erroneous part of the spec.
-bool AArch64::parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
-StringRef &Err) {
-  PBP = {"none", "a_key", false};
-  if (Spec == "none")
-return true; // defaults are ok
-
-  if (Spec == "standard") {
-PBP.Scope = "non-leaf";
-PBP.BranchTargetEnforcement = true;
-return true;
-  }
-
-  SmallVector Opts;
-  Spec.split(Opts, "+");
-  for (int I = 0, E = Opts.size(); I != E; ++I) {
-StringRef Opt = Opts[I].trim();
-if (Opt == "bti") {
-  PBP.BranchTargetEnforcement = true;
-  continue;
-}
-if (Opt == "pac-ret") {
-  PBP.Scope = "non-leaf";
-  for (; I + 1 != E; ++I) {
-StringRef PACOpt = Opts[I + 1].trim();
-if (PACOpt == "leaf")
-  PBP.Scope = "all";
-else if (PACOpt == "b-key")
-  PBP.Key = "b_key";
-else
-  break;
-  }
-  continue;
-}
-if (Opt == "")
-  Err = "";
-else
-  Err = Opt;
-return false;
-  }
-
-  return true;
-}
+}
\ No newline at end of file
Index: llvm/include/llvm/Support/TargetParser.h
===
--- llvm/include/llvm/Support/TargetParser.h
+++ llvm/include/llvm/Support/TargetParser.h
@@ -177,6 +177,18 @@
 
 } // namespace RISCV
 
+namespace ARM {
+struct ParsedBranchProtection {
+  StringRef Scope;
+  StringRef Key;
+  bool BranchTargetEnforcement;
+};
+
+bool parseBranchProtection(StringRef Spec, ParsedBranchProtection &PBP,
+   StringRef &Err);
+
+} // n

[PATCH] D114441: [analyzer][NFC] Refactor AnalysisConsumer::getModeForDecl()

2021-11-29 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:599-603
+  const SourceLocation Loc = [&SM](Decl *D) -> SourceLocation {
+const Stmt *Body = D->getBody();
+SourceLocation SL = Body ? Body->getBeginLoc() : D->getLocation();
+return SM.getExpansionLoc(SL);
+  }(D);

ASDenysPetrov wrote:
> Why don't just leave this snippet as it was but add `const SourceLocation 
> Loc` instead of re-assigning `SL`? Your construction made me stumbled for a 
> while. As this patch is meant to bring readability, I wouldn't like to see 
> such a code-trick. I see your intention to hide `SL` but IMO let compiler do 
> this for us. See suggested.
Hm, you are probably right. The main idea was to reduce the number of unrelated 
declarations in the scope by nesting them into the calculation of the important 
ones.
However, we could relax in this case. I agree that would be even better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114441

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


[PATCH] D114703: [AArch64] Use Feature for A53 Erratum 835769 Fix

2021-11-29 Thread Sam Elliott via Phabricator via cfe-commits
lenary created this revision.
lenary added a reviewer: ostannard.
Herald added subscribers: hiraditya, kristof.beyls.
lenary requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

When this pass was originally implemented, the fix pass was enabled
using a llvm command-line flag. This works fine, except in the case of
LTO, where the flag is not passed into the linker plugin in order to
enable the function pass in the LTO backend.

Now LTO exists, the expectation now is to use target features rather
than command-line arguments to control code generation, as this ensures
that different command-line arguments in different files are correctly
represented, and target-features always get to the LTO plugin as they
are encoded into LLVM IR.

The fall-out of this change is that the fix pass has to always be added
to the backend pass pipeline, so now it makes no changes if the function
does not have the right target feature to enable it. This should make a
minimal difference to compile time.

One advantage is it's now much easier to enable when compiling for a
Cortex-A53, as CPUs imply their own individual sets of target-features,
in a more fine-grained way. I haven't done this yet, but it is an
option, if the fix should be enabled in more places.

Existing tests of the user interface are unaffected, the changes are to
reflect that the argument is now turned into a target feature.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114703

Files:
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aarch64-fix-cortex-a53-835769.c
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64A53Fix835769.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll
  llvm/test/CodeGen/AArch64/aarch64-fix-cortex-a53-835769.ll

Index: llvm/test/CodeGen/AArch64/aarch64-fix-cortex-a53-835769.ll
===
--- llvm/test/CodeGen/AArch64/aarch64-fix-cortex-a53-835769.ll
+++ llvm/test/CodeGen/AArch64/aarch64-fix-cortex-a53-835769.ll
@@ -3,9 +3,9 @@
 ; therefore, the tests are a bit fragile/reliant on instruction scheduling. The
 ; test cases have been minimized as much as possible, but still most of the test
 ; cases could break if instruction scheduling heuristics for cortex-a53 change
-; RUN: llc < %s -mcpu=cortex-a53 -aarch64-fix-cortex-a53-835769=1 -frame-pointer=non-leaf -stats 2>&1 \
+; RUN: llc < %s -mcpu=cortex-a53 -mattr=+fix-cortex-a53-835769 -frame-pointer=non-leaf -stats 2>&1 \
 ; RUN:  | FileCheck %s
-; RUN: llc < %s -mcpu=cortex-a53 -aarch64-fix-cortex-a53-835769=0 -frame-pointer=non-leaf -stats 2>&1 \
+; RUN: llc < %s -mcpu=cortex-a53 -mattr=-fix-cortex-a53-835769 -frame-pointer=non-leaf -stats 2>&1 \
 ; RUN:  | FileCheck %s --check-prefix CHECK-NOWORKAROUND
 ; The following run lines are just to verify whether or not this pass runs by
 ; default for given CPUs. Given the fragility of the tests, this is only run on
Index: llvm/test/CodeGen/AArch64/O3-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -195,6 +195,7 @@
 ; CHECK-NEXT:   Insert XRay ops
 ; CHECK-NEXT:   Implement the 'patchable-function' attribute
 ; CHECK-NEXT:   AArch64 load / store optimization pass
+; CHECK-NEXT:   Workaround A53 erratum 835769 pass
 ; CHECK-NEXT:   AArch64 Branch Targets
 ; CHECK-NEXT:   Branch relaxation pass
 ; CHECK-NEXT:   AArch64 Compress Jump Tables
Index: llvm/test/CodeGen/AArch64/O0-pipeline.ll
===
--- llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -60,6 +60,7 @@
 ; CHECK-NEXT:   Insert fentry calls
 ; CHECK-NEXT:   Insert XRay ops
 ; CHECK-NEXT:   Implement the 'patchable-function' attribute
+; CHECK-NEXT:   Workaround A53 erratum 835769 pass
 ; CHECK-NEXT:   AArch64 Branch Targets
 ; CHECK-NEXT:   Branch relaxation pass
 ; CHECK-NEXT:   Contiguously Lay Out Funclets
Index: llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -116,11 +116,6 @@
   cl::desc("Enable the condition optimizer pass"),
   cl::init(true), cl::Hidden);
 
-static cl::opt
-EnableA53Fix835769("aarch64-fix-cortex-a53-835769", cl::Hidden,
-cl::desc("Work around Cortex-A53 erratum 835769"),
-cl::init(false));
-
 static cl::opt
 EnableGEPOpt("aarch64-enable-gep-opt", cl::Hidden,
  cl::desc("Enable optimizations 

[PATCH] D114231: [clang][docs][dataflow] Added an introduction to dataflow analysis

2021-11-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/docs/DataFlowAnalysisIntro.md:24
+*   [Introduction to Dataflow 
Analysis](https://www.youtube.com/watch?v=OROXJ9-wUQE)
+*   [Introduction to abstract 
interpretation](http://www.cs.tau.ac.il/~msagiv/courses/asv/absint-1.pdf).
+*   [Introduction to symbolic 
execution](https://www.cs.umd.edu/~mwh/se-tutorial/symbolic-exec.pdf).

xazax.hun wrote:
> I know, everyone has their favorite set of resources. Let me share mine: 
> `https://cs.au.dk/~amoeller/spa/`
> I think this one might have a bit more content with more examples. Feel free 
> to leave it as is. 
Forgot about this book -- I also like it a lot, added!



Comment at: clang/docs/DataFlowAnalysisIntro.md:49
+  int x;
+  // x is {}
+  if (n > 0) {

xazax.hun wrote:
> Nit: I wonder if representing the value of `x` with an empty set is a good 
> choice. One could argue that `x` has an indeterminate value that could be 
> represented with the set of all integers using top. Others could argue for a 
> bottom value. Those concepts are not yet introduced. Maybe initializing `x` 
> in the source code would side step this problem.
Since there is a discussion of these topics below, I agree that avoiding the 
question at this point is better. Added initialization.



Comment at: clang/docs/DataFlowAnalysisIntro.md:71-72
+Abstract algebra provides a nice formalism that models this type of structure,
+namely, a lattice. A lattice is a partially ordered set, in which every two
+elements have a least upper bound (called a *join*).
+

xazax.hun wrote:
> Technically, I think this would be a `join-semilattice`. To have a `lattice`, 
> we would need both `join` and `meet`.
Corrected.



Comment at: clang/docs/DataFlowAnalysisIntro.md:86-87
+
+Computing the join in the lattice corresponds to finding the lowest common
+ancestor between two nodes in its Hasse diagram.
+

xazax.hun wrote:
> If we want to be practical, I wonder if we want to give some guidance how to 
> implement that efficiently. E.g. we could cite a paper like this: 
> https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.106.4911&rep=rep1&type=pdf
Thanks, added.



Comment at: clang/docs/DataFlowAnalysisIntro.md:111-112
+information that we track. In this case, we can, for example, arbitrarily limit
+the size of sets to 3 elements. If at a certain program point `x` has more than
+3 possible values, we stop tracking specific values at that program point.
+Instead, we denote possible values of `x` with the symbol `⊤` (pronounced "top"

xazax.hun wrote:
> I wonder if we want to cite widening and narrowing in this context to give 
> people some pointers where to look for more info.
I think it should be a separate section, with a slightly different example. To 
show the value of widening we need a lattice that can abstract the infinite set 
`{0; 1; 2; ...}` more precisely than "⊤" (e.g., "non-negative"). There would be 
also the usual handwaving about figuring out how to make those types of 
conclusions in the general case. I think adding all that here would break the 
flow and make the explanation less crisp. Adding a separate section on widening 
would be good one day, when the dataflow framework gets the feature. I don't 
think it is necessary right now.



Comment at: clang/docs/DataFlowAnalysisIntro.md:182
+void Example(int n) {
+  int x;  // x is ⊥
+  if (n > 0) {

xazax.hun wrote:
> I think it would make sense to include the whole program state in the 
> comments. E.g. `// x is ⊥, n is ⊤`.
> This could showcase how we constrain the value of `n` to `42` in one of the 
> branches.
So far we have been focusing on figuring out the values of `x` the local 
variable, not `n` the parameter, so I'd rather not deviate. Also, comparing `n` 
to 42 wouldn't necessarily lead to constraining the set of values here (for 
example, in the framework we do it in the flow condition).



Comment at: clang/docs/DataFlowAnalysisIntro.md:279
+```
+out = transfer(basic_block, join(in_1, in_2, ..., in_n))
+```

xazax.hun wrote:
> While I agree that this is the general formula, people sometimes do small 
> variations, e.g.:
> ```
> out =  join(transfer(basic_block,in_1), transfer(basic_block,in_2), ..., 
> transfer(basic_block,in_n))
> ```
> 
> This is less efficient as we end up invoking the transfer function more 
> often, but it can be more precise. E.g. with some ad-hoc notation:
> 
> ```
> Given the branches: x: {1}, x: {2}, x: {3}, x: {4}
> join(in...) : x : {⊤}
> transfer("x/2", ...) == x : {⊤}
> 
> vs.
> Given the branches: x: {1}, x: {2}, x: {3}, x: {4}
> transfer("x/2", ...) ==x : {0}, x : {1}, x : {1}, x: {2} == outs
> join(outs) == x: {0, 1, 2}
> ```
This section is only attempting to give the readers an intuition of why 
dataflow w

[PATCH] D112422: [clang][ARM] emit PACBTI-M feature defines

2021-11-29 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 390320.
stuij added a comment.

obeying clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112422

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/test/Preprocessor/arm-target-features.c


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -877,6 +877,25 @@
 // RUN: %clang -target arm-none-none-eabi -march=armv7-m -mfpu=softvfp -x c -E 
-dM %s -o - | FileCheck --check-prefix=CHECK-SOFTVFP %s
 // CHECK-SOFTVFP-NOT: #define __ARM_FP 0x
 
+// Test Armv8.1-M PACBTI
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-NOBTI,CHECK-NOPAC %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-BTI,CHECK-NOPAC %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY-LEAF,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC,CHECK-BTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY,CHECK-BTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-LEAF,CHECK-BTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main 
-mbranch-protection=bti+pac-ret+b-key+leaf -x c -E -dM %s -o - | FileCheck 
--check-prefixes=CHECK-PAC-BKEY-LEAF,CHECK-BTI %s
+// CHECK-NOBTI-NOT: #define __ARM_FEATURE_BTI_DEFAULT
+// CHECK-NOPAC-NOT: #define __ARM_FEATURE_PAC_DEFAULT
+// CHECK-BTI: #define __ARM_FEATURE_BTI_DEFAULT 1
+// CHECK-PAC: #define __ARM_FEATURE_PAC_DEFAULT 1
+// CHECK-PAC-BKEY: #define __ARM_FEATURE_PAC_DEFAULT 2
+// CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
+// CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
+
 // == Check BFloat16 Extensions.
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.6-a+bf16 -x c -E -dM %s 
-o - 2>&1 | FileCheck -check-prefix=CHECK-BFLOAT %s
 // CHECK-BFLOAT: #define __ARM_BF16_FORMAT_ALTERNATIVE 1
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -896,6 +896,16 @@
 Builder.defineMacro("__ARM_BF16_FORMAT_ALTERNATIVE", "1");
   }
 
+  if (Opts.BranchTargetEnforcement)
+Builder.defineMacro("__ARM_FEATURE_BTI_DEFAULT", "1");
+
+  if (Opts.hasSignReturnAddress()) {
+unsigned Value = Opts.isSignReturnAddressWithAKey() ? 1 : 2;
+if (Opts.isSignReturnAddressScopeAll())
+  Value |= 1 << 2;
+Builder.defineMacro("__ARM_FEATURE_PAC_DEFAULT", Twine(Value));
+  }
+
   switch (ArchKind) {
   default:
 break;


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -877,6 +877,25 @@
 // RUN: %clang -target arm-none-none-eabi -march=armv7-m -mfpu=softvfp -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SOFTVFP %s
 // CHECK-SOFTVFP-NOT: #define __ARM_FP 0x
 
+// Test Armv8.1-M PACBTI
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-NOBTI,CHECK-NOPAC %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -mbranch-protection=bti -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-BTI,CHECK-NOPAC %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -mbranch-protection=pac-ret -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-PAC,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -mbranch-protection=pac-ret+b-key -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-PAC-BKEY,CHECK-NOBTI %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -mbranch-protection=pac-ret+leaf 

[PATCH] D114651: [clang-cl] Expose -Wall to clang-cl by unaliasing -Wall, keeping /Wall as alias to -Weverything

2021-11-29 Thread Sylvain Audi via Phabricator via cfe-commits
saudi abandoned this revision.
saudi added a comment.

I understand, making `clang-cl -Wall` behave differently than `/Wall' is indeed 
confusing.
We'll take different steps for setting up the warnings in our Build System.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114651

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp:342
+  auto w = new int(x);
+}

salman-javed-nz wrote:
> carlosgalvezp wrote:
> > carlosgalvezp wrote:
> > > Quuxplusone wrote:
> > > > What about
> > > > ```
> > > > template T foo(int i) { return T(i); }
> > > > int main() {
> > > > foo>(); // valid, OK(!)
> > > > foo(); // valid, not OK
> > > > }
> > > > ```
> > > > What about
> > > > ```
> > > > struct Widget { Widget(int); };
> > > > using T = Widget;
> > > > using U = Widget&;
> > > > int i = 42;
> > > > Widget t = T(i);  // valid, OK?
> > > > Widget u = U(i);  // valid C++, should definitely not be OK
> > > > ```
> > > > https://quuxplusone.github.io/blog/2020/01/22/expression-list-in-functional-cast/
> > > Good point, thanks! I've added the first one to the unit test.
> > > 
> > > Regarding the second check, I'm not sure if it's the scope of this check. 
> > > This check does not care whether the constructor of the class is implicit 
> > > or not - if you use a class type, then you are calling the constructor so 
> > > it's fine. Same goes when it's a reference - in my opinion this check is 
> > > not concerned with that.
> > > 
> > > I definitely see the problems that can arise from the example that you 
> > > posted, but maybe it fits better as a separate check in the `bugprone` 
> > > category? This check (`google-readability-casting`) is focused only about 
> > > avoiding C-style casting, i.e. it's a readability/style/modernize matter 
> > > IMO. If cpplint is not diagnosing that, I don't think this check should 
> > > either.
> > It seems I should be able to just add the second example as a test and 
> > clang-tidy would warn but, what should be the fixit for it? A 
> > `static_cast` would lead to compiler error (which I personally would 
> > gladly take, but I don't know in general if we want clang-tidy to "fix" 
> > code leading to compiler errors"). Adding an ad-hoc message for this 
> > particular error seems out of the scope of a "readability" check. 
> > 
> > What do you guys think?
> > It seems I should be able to just add the second example as a test and 
> > clang-tidy would warn but, what should be the fixit for it?
> 
> If I run the second example, but with old style C casts instead:
> 
> Input:
> ```lang=cpp
> struct Widget { Widget(int); };
> using T = Widget;
> using U = Widget&;
> int i = 42;
> Widget t = (T)(i);
> Widget u = (U)(i);
> ```
> 
> Output after fixits:
> ```lang=cpp
> struct Widget { Widget(int); };
> using T = Widget;
> using U = Widget&;
> int i = 42;
> Widget t = T(i);
> Widget u = (U)(i);
> ```
> 
> I guess the fix `Widget t = T(i);` is OK as it is covered by this exception:
> >You may use cast formats like `T(x)` only when `T` is a class type.
> 
> For the `Widget u = (U)(i);` line, clang-tidy has warned about it but not 
> offered a fix.
> What would be the right fixit for that anyway?
> `Widget u = U(i);   -->   Widget u = static_cast(i);` ?

No, this is a reinterpret_cast, so it would be
```
Widget u = reinterpret_cast(i);
```
at least in C++. I don't know about C, but I imagine the problem doesn't come 
up.

(If the programmer looks at this line and says "oh geez, that's wrong," well, 
he'll either fix it or file a task to revisit weird reinterpret_casts in the 
codebase. If the programmer thinks the cast is //correct//, then personally I'd 
hope he rewrites it as `Widget u = *reinterpret_cast(&i);` for 
clarity, but that's not a clang-tidy issue.)

Relevant: "fixits versus suppression mechanisms" 
https://quuxplusone.github.io/blog/2020/09/02/wparentheses/ `reinterpret_cast` 
is a suppression mechanism; I infer that you're casting about for a fixit, 
which won't exist in this case.


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

https://reviews.llvm.org/D114427

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


[PATCH] D114706: [analyzer] Fix sensitive argument logic in GenericTaintChecker

2021-11-29 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 created this revision.
gamesh411 added reviewers: steakhal, Szelethus, NoQ.
Herald added subscribers: manas, ASDenysPetrov, martong, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
gamesh411 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The semantics of taint sinks is that if ANY of the arguments is tainted, a
warning should be emmitted. Before this change, if there were multiple
arguments that are sensitive, and if the first arg is not tainted, but any of
the noninitial are tainted, a warning is not emitted. After this change the
correct semantics is reflected in code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114706

Files:
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/test/Analysis/taint-generic.c

Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -209,6 +209,15 @@
   strncat(dst2, dst, ts); // no-warning
 }
 
+void testTaintedBufferSizeNoninitialTaintedArg() {
+  size_t ts;
+  scanf("%zd", &ts);
+
+  const int nontainted_num = 1;
+
+  (void)calloc(nontainted_num, ts); //expected-warning {{Untrusted data is used to specify the buffer size}}
+}
+
 #define AF_UNIX   1   /* local to host (pipes) */
 #define AF_INET   2   /* internetwork: UDP, TCP, etc. */
 #define AF_LOCAL  AF_UNIX   /* backward compatibility */
Index: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -869,24 +869,26 @@
   // TODO: It might make sense to run this check on demand. In some cases,
   // we should check if the environment has been cleansed here. We also might
   // need to know if the user was reset before these calls(seteuid).
-  unsigned ArgNum = llvm::StringSwitch(Name)
-.Case("system", 0)
-.Case("popen", 0)
-.Case("execl", 0)
-.Case("execle", 0)
-.Case("execlp", 0)
-.Case("execv", 0)
-.Case("execvp", 0)
-.Case("execvP", 0)
-.Case("execve", 0)
-.Case("dlopen", 0)
-.Default(InvalidArgIndex);
-
-  if (ArgNum == InvalidArgIndex || Call.getNumArgs() < (ArgNum + 1))
-return false;
-
-  return generateReportIfTainted(Call.getArgExpr(ArgNum), MsgSanitizeSystemArgs,
- C);
+  const ArgVector SensitiveArgs = llvm::StringSwitch(Name)
+  .Case("system", {0})
+  .Case("popen", {0})
+  .Case("execl", {0, 1})
+  .Case("execle", {0, 1})
+  .Case("execlp", {0, 1})
+  .Case("execv", {0, 1})
+  .Case("execvp", {0, 1})
+  .Case("execvP", {0})
+  .Case("execve", {0, 1, 2})
+  .Case("dlopen", {0})
+  .Default({});
+
+  // Find the first argument that receives a tainted value.
+  // The report is emitted as a side-effect.
+  return llvm::find_if(SensitiveArgs, [this, &C, &Call](unsigned Idx) {
+   return Idx < Call.getNumArgs() &&
+  generateReportIfTainted(Call.getArgExpr(Idx),
+  MsgSanitizeSystemArgs, C);
+ }) != SensitiveArgs.end();
 }
 
 // TODO: Should this check be a part of the CString checker?
@@ -895,40 +897,45 @@
  CheckerContext &C) const {
   const auto *FDecl = Call.getDecl()->getAsFunction();
   // If the function has a buffer size argument, set ArgNum.
-  unsigned ArgNum = InvalidArgIndex;
+  ArgVector SensitiveArgs = {};
   unsigned BId = 0;
   if ((BId = FDecl->getMemoryFunctionKind())) {
 switch (BId) {
 case Builtin::BImemcpy:
 case Builtin::BImemmove:
 case Builtin::BIstrncpy:
-  ArgNum = 2;
+  SensitiveArgs = {2};
   break;
 case Builtin::BIstrndup:
-  ArgNum = 1;
+  SensitiveArgs = {1};
   break;
 default:
   break;
 }
   }
 
-  if (ArgNum == InvalidArgIndex) {
+  if (SensitiveArgs.empty()) {
 using CCtx = CheckerContext;
 if (CCtx::isCLibraryFunction(FDecl, "malloc") ||
-CCtx::isCLibraryFunction(FDecl, "calloc") ||
 CCtx::isCLibraryFunction(FDecl, "alloca"))
-  ArgNum = 0;
+  SensitiveArgs = {0};
+else if (CCtx::isCLibraryFunction(FDecl,

[PATCH] D112430: [ARM][libunwind] add PACBTI-M support for libunwind

2021-11-29 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 390333.
stuij added a comment.

uploading after rebase as per reviewer request (no changes in the patch itself)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112430

Files:
  clang/lib/Headers/unwind.h
  libunwind/include/libunwind.h
  libunwind/include/unwind_arm_ehabi.h
  libunwind/src/DwarfInstructions.hpp
  libunwind/src/Registers.hpp
  libunwind/src/Unwind-EHABI.cpp
  libunwind/src/UnwindCursor.hpp
  libunwind/src/UnwindRegistersRestore.S
  libunwind/src/assembly.h

Index: libunwind/src/assembly.h
===
--- libunwind/src/assembly.h
+++ libunwind/src/assembly.h
@@ -81,7 +81,7 @@
 #define PPC64_OPD2
 #endif
 
-#if defined(__ARM_FEATURE_BTI_DEFAULT)
+#if defined(__aarch64__) && defined(__ARM_FEATURE_BTI_DEFAULT)
   .pushsection ".note.gnu.property", "a" SEPARATOR \
   .balign 8 SEPARATOR  \
   .long 4 SEPARATOR\
@@ -99,6 +99,17 @@
 #define AARCH64_BTI
 #endif
 
+#if !defined(__aarch64__)
+#ifdef __ARM_FEATURE_PAC_DEFAULT
+  .eabi_attribute Tag_PAC_extension, 2
+  .eabi_attribute Tag_PACRET_use, 1
+#endif
+#ifdef __ARM_FEATURE_BTI_DEFAULT
+  .eabi_attribute Tag_BTI_extension, 1
+  .eabi_attribute Tag_BTI_use, 1
+#endif
+#endif
+
 #define GLUE2(a, b) a ## b
 #define GLUE(a, b) GLUE2(a, b)
 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
Index: libunwind/src/UnwindRegistersRestore.S
===
--- libunwind/src/UnwindRegistersRestore.S
+++ libunwind/src/UnwindRegistersRestore.S
@@ -660,7 +660,13 @@
   ldr sp, [lr, #52]
   ldr lr, [lr, #60]  @ restore pc into lr
 #endif
+#if defined(__ARM_FEATURE_BTI_DEFAULT) && !defined(__ARM_ARCH_ISA_ARM)
+  // 'bx' is not BTI setting when used with lr, therefore r12 is used instead
+  mov r12, lr
+  JMP(r12)
+#else
   JMP(lr)
+#endif
 
 @
 @ static void libunwind::Registers_arm::restoreVFPWithFLDMD(unw_fpreg_t* values)
Index: libunwind/src/UnwindCursor.hpp
===
--- libunwind/src/UnwindCursor.hpp
+++ libunwind/src/UnwindCursor.hpp
@@ -655,7 +655,9 @@
 #if defined(_LIBUNWIND_TARGET_X86_64)
   if (regNum >= UNW_X86_64_RAX && regNum <= UNW_X86_64_R15) return true;
 #elif defined(_LIBUNWIND_TARGET_ARM)
-  if (regNum >= UNW_ARM_R0 && regNum <= UNW_ARM_R15) return true;
+  if ((regNum >= UNW_ARM_R0 && regNum <= UNW_ARM_R15) ||
+  regNum == UNW_ARM_RA_AUTH_CODE)
+return true;
 #elif defined(_LIBUNWIND_TARGET_AARCH64)
   if (regNum >= UNW_AARCH64_X0 && regNum <= UNW_ARM64_X30) return true;
 #endif
Index: libunwind/src/Unwind-EHABI.cpp
===
--- libunwind/src/Unwind-EHABI.cpp
+++ libunwind/src/Unwind-EHABI.cpp
@@ -261,6 +261,7 @@
   size_t offset, size_t len) {
   bool wrotePC = false;
   bool finish = false;
+  bool hasReturnAddrAuthCode = false;
   while (offset < len && !finish) {
 uint8_t byte = getByte(data, offset++);
 if ((byte & 0x80) == 0) {
@@ -347,6 +348,10 @@
   break;
 }
 case 0xb4:
+  hasReturnAddrAuthCode = true;
+  _Unwind_VRS_Pop(context, _UVRSC_PSEUDO,
+  0 /* Return Address Auth Code */, _UVRSD_UINT32);
+  break;
 case 0xb5:
 case 0xb6:
 case 0xb7:
@@ -422,6 +427,16 @@
   if (!wrotePC) {
 uint32_t lr;
 _Unwind_VRS_Get(context, _UVRSC_CORE, UNW_ARM_LR, _UVRSD_UINT32, &lr);
+#ifdef __ARM_FEATURE_PAUTH
+if (hasReturnAddrAuthCode) {
+  uint32_t sp;
+  uint32_t pac;
+  _Unwind_VRS_Get(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32, &sp);
+  _Unwind_VRS_Get(context, _UVRSC_PSEUDO, UNW_ARM_RA_AUTH_CODE,
+  _UVRSD_UINT32, &pac);
+  __asm__ __volatile__("autg %0, %1, %2" : : "r"(pac), "r"(lr), "r"(sp) :);
+}
+#endif
 _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_IP, _UVRSD_UINT32, &lr);
   }
   return _URC_CONTINUE_UNWIND;
@@ -941,6 +956,15 @@
 case _UVRSC_WMMXD:
   break;
 #endif
+case _UVRSC_PSEUDO:
+  // There's only one pseudo-register, PAC, with regno == 0.
+  if (representation != _UVRSD_UINT32 || regno != 0)
+return _UVRSR_FAILED;
+  return __unw_set_reg(cursor, (unw_regnum_t)(UNW_ARM_RA_AUTH_CODE),
+   *(unw_word_t *)valuep) == UNW_ESUCCESS
+ ? _UVRSR_OK
+ : _UVRSR_FAILED;
+  break;
   }
   _LIBUNWIND_ABORT("unsupported register class");
 }
@@ -995,6 +1019,15 @@
 case _UVRSC_WMMXD:
   break;
 #endif
+case _UVRSC_PSEUDO:
+  // There's only one pseudo-register, PAC, with regno == 0.
+  if (representation != _UVRSD

[clang] 90010c2 - Don't consider 'LinkageSpec' when calculating DeclContext 'Encloses'

2021-11-29 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2021-11-29T06:08:16-08:00
New Revision: 90010c2e1d60c6a9a4a0b30a113d4dae2b7214eb

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

LOG: Don't consider 'LinkageSpec' when calculating DeclContext 'Encloses'

We don't properly handle lookup through using directives when there is
a linkage spec in the common chain.  This is because `CppLookupName` and
`CppNamespaceLookup` end up skipping `LinkageSpec`'s (correctly, as they
are not lookup scopes), but the `UnqualUsingDirectiveSet` does not.

I discovered that when we are calculating the `CommonAncestor` for a
using-directive, we were coming up with the `LinkageSpec`, instead of
the `LinkageSpec`'s parent.  Then, when we use
`UnqualUsingDirectiveSet::getNamespacesFor` a scope, we don't end up
finding any that were in the `LinkageSpec` (again, since `CppLookupName`
skips linkage specs), so those don't end up participating in the lookup.

The function `UnqualUsingDirectiveSet::addUsingDirective` calculates
this common ancestor via a loop through the the `DeclSpec::Encloses`
function.

Changing this Encloses function to believe that a `LinkageSpec`
`Encloses` nothing ends up fixing the problem without breaking any other tests,
so I opted to do that.  A less aggressive patch could perhaps change only
the `addUsingDirective`, but my examination of all uses of `Encloses`
showed that it seems to be used exclusively in lookup, which makes me think
this is correct everywhere.

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

Added: 
clang/test/SemaCXX/lookup-through-linkage.cpp

Modified: 
clang/lib/AST/DeclBase.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index d8eaf706384f5..064012ba865c8 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1212,7 +1212,7 @@ bool DeclContext::Encloses(const DeclContext *DC) const {
 return getPrimaryContext()->Encloses(DC);
 
   for (; DC; DC = DC->getParent())
-if (DC->getPrimaryContext() == this)
+if (!isa(DC) && DC->getPrimaryContext() == this)
   return true;
   return false;
 }

diff  --git a/clang/test/SemaCXX/lookup-through-linkage.cpp 
b/clang/test/SemaCXX/lookup-through-linkage.cpp
new file mode 100644
index 0..0a2d609e9dbd9
--- /dev/null
+++ b/clang/test/SemaCXX/lookup-through-linkage.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 %s -verify
+
+// expected-no-diagnostics
+
+extern "C++" {
+namespace A {
+namespace B {
+int bar;
+}
+} // namespace A
+namespace C {
+void foo() {
+  using namespace A;
+  (void)B::bar;
+}
+} // namespace C
+}
+
+extern "C" {
+extern "C++" {
+namespace D {
+namespace E {
+int bar;
+}
+} // namespace A
+namespace F {
+void foo() {
+  using namespace D;
+  (void)E::bar;
+}
+} // namespace C
+}
+}



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


[PATCH] D113709: Don't consider `LinkageSpec` when calculating DeclContext `Encloses`

2021-11-29 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG90010c2e1d60: Don't consider 'LinkageSpec' 
when calculating DeclContext 'Encloses' (authored by erichkeane).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D113709?vs=386635&id=390337#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113709

Files:
  clang/lib/AST/DeclBase.cpp
  clang/test/SemaCXX/lookup-through-linkage.cpp


Index: clang/test/SemaCXX/lookup-through-linkage.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/lookup-through-linkage.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 %s -verify
+
+// expected-no-diagnostics
+
+extern "C++" {
+namespace A {
+namespace B {
+int bar;
+}
+} // namespace A
+namespace C {
+void foo() {
+  using namespace A;
+  (void)B::bar;
+}
+} // namespace C
+}
+
+extern "C" {
+extern "C++" {
+namespace D {
+namespace E {
+int bar;
+}
+} // namespace A
+namespace F {
+void foo() {
+  using namespace D;
+  (void)E::bar;
+}
+} // namespace C
+}
+}
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1212,7 +1212,7 @@
 return getPrimaryContext()->Encloses(DC);
 
   for (; DC; DC = DC->getParent())
-if (DC->getPrimaryContext() == this)
+if (!isa(DC) && DC->getPrimaryContext() == this)
   return true;
   return false;
 }


Index: clang/test/SemaCXX/lookup-through-linkage.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/lookup-through-linkage.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 %s -verify
+
+// expected-no-diagnostics
+
+extern "C++" {
+namespace A {
+namespace B {
+int bar;
+}
+} // namespace A
+namespace C {
+void foo() {
+  using namespace A;
+  (void)B::bar;
+}
+} // namespace C
+}
+
+extern "C" {
+extern "C++" {
+namespace D {
+namespace E {
+int bar;
+}
+} // namespace A
+namespace F {
+void foo() {
+  using namespace D;
+  (void)E::bar;
+}
+} // namespace C
+}
+}
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1212,7 +1212,7 @@
 return getPrimaryContext()->Encloses(DC);
 
   for (; DC; DC = DC->getParent())
-if (DC->getPrimaryContext() == this)
+if (!isa(DC) && DC->getPrimaryContext() == this)
   return true;
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 814aaba - [clang-format] regressed default behavior for operator parentheses

2021-11-29 Thread via cfe-commits

Author: mydeveloperday
Date: 2021-11-29T14:27:16Z
New Revision: 814aabae37757d21d96e22608ccb98e91c1f3a06

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

LOG: [clang-format] regressed default behavior for operator parentheses

{D110833} regressed behavior of spaces before parentheses for operators, this 
revision reverts that so that operators are handled as they were before.

I think in hindsight it was a mistake to try and consume operator behaviour in 
with the function behaviour, I think Operators can be considered a special 
style. Its seems the code is getting confused as to if this is a function 
declaration or definition.

I think latterly we can consider adding an operator parentheses specific custom 
option but this should have been explicitly called out as it can impact 
projects.

Reviewed By: HazardyKnusperkeks, curdeius

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index fba55fb32da2d..22faf54b017da 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3169,9 +3169,13 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 if (Left.isIf(Line.Type != LT_PreprocessorDirective))
   return Style.SpaceBeforeParensOptions.AfterControlStatements ||
  spaceRequiredBeforeParens(Right);
+
+// TODO add Operator overloading specific Options to
+// SpaceBeforeParensOptions
+if (Right.is(TT_OverloadedOperatorLParen))
+  return spaceRequiredBeforeParens(Right);
 // Function declaration or definition
-if (Line.MightBeFunctionDecl && (Left.is(TT_FunctionDeclarationName) ||
- Right.is(TT_OverloadedOperatorLParen))) {
+if (Line.MightBeFunctionDecl && (Left.is(TT_FunctionDeclarationName))) {
   if (Line.mightBeFunctionDefinition())
 return Style.SpaceBeforeParensOptions.AfterFunctionDefinitionName ||
spaceRequiredBeforeParens(Right);

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 845b1e5e8809a..39f1b835fb766 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9185,6 +9185,11 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) {
   // https://llvm.org/PR50629
   // verifyFormat("void f() { operator*(a & a); }");
   // verifyFormat("void f() { operator&(a, b * b); }");
+
+  verifyFormat("::operator delete(foo);");
+  verifyFormat("::operator new(n * sizeof(foo));");
+  verifyFormat("foo() { ::operator delete(foo); }");
+  verifyFormat("foo() { ::operator new(n * sizeof(foo)); }");
 }
 
 TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
@@ -14117,8 +14122,9 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("static_assert (sizeof (char) == 1, \"Impossible!\");", Space);
   verifyFormat("int f () throw (Deprecated);", Space);
   verifyFormat("typedef void (*cb) (int);", Space);
-  verifyFormat("T A::operator() ();", Space);
-  verifyFormat("X A::operator++ (T);", Space);
+  // FIXME these tests regressed behaviour.
+  // verifyFormat("T A::operator() ();", Space);
+  // verifyFormat("X A::operator++ (T);", Space);
   verifyFormat("auto lambda = [] () { return 0; };", Space);
   verifyFormat("int x = int (y);", Space);
 
@@ -14174,7 +14180,8 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("int f() throw (Deprecated);", SomeSpace);
   verifyFormat("typedef void (*cb) (int);", SomeSpace);
   verifyFormat("T A::operator()();", SomeSpace);
-  verifyFormat("X A::operator++ (T);", SomeSpace);
+  // FIXME these tests regressed behaviour.
+  // verifyFormat("X A::operator++ (T);", SomeSpace);
   verifyFormat("int x = int (y);", SomeSpace);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace);
 
@@ -14230,8 +14237,9 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
SpaceFuncDecl);
   verifyFormat("int f () throw(Deprecated);", SpaceFuncDecl);
   verifyFormat("typedef void (*cb)(int);", SpaceFuncDecl);
-  verifyFormat("T A::operator() ();", SpaceFuncDecl);
-  verifyFormat("X A::operator++ (T);", SpaceFuncDecl);
+  // FIXME these tests regressed behaviour.
+  // verifyFormat("T A::operator() ();", SpaceFuncDecl);
+  // verifyFormat("X A::operator++ (T);", SpaceFuncDecl);
   verifyFormat("T A::operator()() {}", SpaceFuncDecl);
   verifyFormat("auto lambda = []() { return 0; };", SpaceFuncDecl);
   verifyFormat("int x = int(y);", SpaceFuncDecl);
@@ -14266,7 +14274,7 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("typ

[PATCH] D114696: [clang-format] regressed default behavior for operator parentheses

2021-11-29 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG814aabae3775: [clang-format] regressed default behavior for 
operator parentheses (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114696

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9185,6 +9185,11 @@
   // https://llvm.org/PR50629
   // verifyFormat("void f() { operator*(a & a); }");
   // verifyFormat("void f() { operator&(a, b * b); }");
+
+  verifyFormat("::operator delete(foo);");
+  verifyFormat("::operator new(n * sizeof(foo));");
+  verifyFormat("foo() { ::operator delete(foo); }");
+  verifyFormat("foo() { ::operator new(n * sizeof(foo)); }");
 }
 
 TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
@@ -14117,8 +14122,9 @@
   verifyFormat("static_assert (sizeof (char) == 1, \"Impossible!\");", Space);
   verifyFormat("int f () throw (Deprecated);", Space);
   verifyFormat("typedef void (*cb) (int);", Space);
-  verifyFormat("T A::operator() ();", Space);
-  verifyFormat("X A::operator++ (T);", Space);
+  // FIXME these tests regressed behaviour.
+  // verifyFormat("T A::operator() ();", Space);
+  // verifyFormat("X A::operator++ (T);", Space);
   verifyFormat("auto lambda = [] () { return 0; };", Space);
   verifyFormat("int x = int (y);", Space);
 
@@ -14174,7 +14180,8 @@
   verifyFormat("int f() throw (Deprecated);", SomeSpace);
   verifyFormat("typedef void (*cb) (int);", SomeSpace);
   verifyFormat("T A::operator()();", SomeSpace);
-  verifyFormat("X A::operator++ (T);", SomeSpace);
+  // FIXME these tests regressed behaviour.
+  // verifyFormat("X A::operator++ (T);", SomeSpace);
   verifyFormat("int x = int (y);", SomeSpace);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace);
 
@@ -14230,8 +14237,9 @@
SpaceFuncDecl);
   verifyFormat("int f () throw(Deprecated);", SpaceFuncDecl);
   verifyFormat("typedef void (*cb)(int);", SpaceFuncDecl);
-  verifyFormat("T A::operator() ();", SpaceFuncDecl);
-  verifyFormat("X A::operator++ (T);", SpaceFuncDecl);
+  // FIXME these tests regressed behaviour.
+  // verifyFormat("T A::operator() ();", SpaceFuncDecl);
+  // verifyFormat("X A::operator++ (T);", SpaceFuncDecl);
   verifyFormat("T A::operator()() {}", SpaceFuncDecl);
   verifyFormat("auto lambda = []() { return 0; };", SpaceFuncDecl);
   verifyFormat("int x = int(y);", SpaceFuncDecl);
@@ -14266,7 +14274,7 @@
   verifyFormat("typedef void (*cb)(int);", SpaceFuncDef);
   verifyFormat("T A::operator()();", SpaceFuncDef);
   verifyFormat("X A::operator++(T);", SpaceFuncDef);
-  verifyFormat("T A::operator() () {}", SpaceFuncDef);
+  // verifyFormat("T A::operator() () {}", SpaceFuncDef);
   verifyFormat("auto lambda = [] () { return 0; };", SpaceFuncDef);
   verifyFormat("int x = int(y);", SpaceFuncDef);
   verifyFormat("M(std::size_t R, std::size_t C) : C(C), data(R) {}",
@@ -14341,7 +14349,7 @@
   verifyFormat("int f() throw (Deprecated);", SomeSpace2);
   verifyFormat("typedef void (*cb) (int);", SomeSpace2);
   verifyFormat("T A::operator()();", SomeSpace2);
-  verifyFormat("X A::operator++ (T);", SomeSpace2);
+  // verifyFormat("X A::operator++ (T);", SomeSpace2);
   verifyFormat("int x = int (y);", SomeSpace2);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
 }
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3169,9 +3169,13 @@
 if (Left.isIf(Line.Type != LT_PreprocessorDirective))
   return Style.SpaceBeforeParensOptions.AfterControlStatements ||
  spaceRequiredBeforeParens(Right);
+
+// TODO add Operator overloading specific Options to
+// SpaceBeforeParensOptions
+if (Right.is(TT_OverloadedOperatorLParen))
+  return spaceRequiredBeforeParens(Right);
 // Function declaration or definition
-if (Line.MightBeFunctionDecl && (Left.is(TT_FunctionDeclarationName) ||
- Right.is(TT_OverloadedOperatorLParen))) {
+if (Line.MightBeFunctionDecl && (Left.is(TT_FunctionDeclarationName))) {
   if (Line.mightBeFunctionDefinition())
 return Style.SpaceBeforeParensOptions.AfterFunctionDefinitionName ||
spaceRequiredBeforeParens(Right);


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9185,6 +9185,11 @@
   // https://llvm.org/PR50629
   // verifyFormat("void f() { operator*(a & a); }");
   // verifyFormat("void

[PATCH] D106339: Add support to generate Sphinx DOCX documentation

2021-11-29 Thread Louis Dionne via Phabricator via cfe-commits
ldionne removed projects: libc++, libunwind.
ldionne removed reviewers: libunwind, libc++, ldionne.
ldionne added a comment.
Herald added projects: libc++, libunwind.
Herald added a reviewer: libc++.
Herald added a reviewer: libunwind.

Removing from the runtimes review queue -- please ping me directly if you need 
my attention on this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106339

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


[PATCH] D114631: [DebugInfo][InstrRef] Turn instruction referencing on by default for x86

2021-11-29 Thread Jeremy Morse via Phabricator via cfe-commits
jmorse created this revision.
jmorse added reviewers: StephenTozer, Orlando, TWeaver, djtodoro.
Herald added subscribers: dang, pengfei, hiraditya.
jmorse requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This patch makes instruction referencing on-by-default for x86, as discussed in 
https://lists.llvm.org/pipermail/llvm-dev/2021-November/153653.html . I'm sure 
there'll be an amount of unexpected breakage, so I'll land in two parts, with a 
minimal sized patch switching the default so that reverting is easy.

It seems there are a number of complicated interactions between the cc1 
arguments and the codegen flags -- I don't really want to untangle them, so 
I've just removed the cc1 argument for instruction referencing. It'll still be 
accessible with `-mllvm -experimental-debug-variable-locations=true`

This is probably the point to discuss tests that I'm not intending on updating 
for instruction referencing and still have 
-experimental-debug-variable-locations=false in the arguments. They are:

  MIR/X86/dvl-livedebugvalues-clobber.mir
  MIR/X86/dvl-livedebugvalues-join.mir
  MIR/X86/dvl-livedebugvalues-movements.mir
  MIR/X86/dvl-livedebugvalues-spillrestore.mir
  X86/dbg-val-list-dangling.ll

^ they involve variadic variable locations, which is currently "future work" 
for December,

  MIR/X86/kill-after-spill.mir
  MIR/X86/live-debug-values-restore-collide.mir
  MIR/X86/mlicm-hoist-post-regalloc.mir
  X86/live-debug-variables.ll
  X86/live-debug-vars-discard-invalid.mir
  X86/live-debug-vars-intervals.mir
  MIR/X86/live-debug-vars-unused-arg-debugonly.mir
  MIR/X86/live-debug-vars-unused-arg.mir
  MIR/X86/livedebugvars-crossbb-interval.mir
  MIR/X86/backup-entry-values-usage.mir

^ these all test very DBG_VALUE specific parts of code, usuallly 
LiveDebugVariables which is a no-op when using instruction referencing. One of 
them tests what VarLocBasedLDV does does with spills when they're followed by 
kill flags, which is another thing InstrRefBasedLDV doesn't care about.

  Generic/linear-dbg-value.ll

^ this seems to just check that DBG_VALUE instructions are generated, I don't 
think it's really testing any interesting behaviours.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114631

Files:
  clang/include/clang/Driver/Options.td
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/DebugInfo/X86/instr-ref-flag.ll

Index: llvm/test/DebugInfo/X86/instr-ref-flag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/instr-ref-flag.ll
@@ -0,0 +1,46 @@
+; RUN: llc %s -o - -stop-before=finalize-isel -march=x86-64 \
+; RUN: | FileCheck %s --check-prefixes=INSTRREFON
+; RUN: llc %s -o - -stop-before=finalize-isel -march=x86-64 \
+; RUN:-experimental-debug-variable-locations=true \
+; RUN: | FileCheck %s --check-prefixes=INSTRREFON
+
+; RUN: llc %s -o - -stop-before=finalize-isel -march=x86-64 \
+; RUN:-experimental-debug-variable-locations=false \
+; RUN: | FileCheck %s --check-prefixes=INSTRREFOFF \
+; RUN:--implicit-check-not=DBG_INSTR_REF
+
+;; This test checks that for an x86 triple, instruction referencing is used
+;; by llc by default, and that it can be turned explicitly on or off as
+;; desired.
+
+; INSTRREFON: DBG_INSTR_REF
+; INSTRREFOFF: DBG_VALUE
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-unknown"
+
+define hidden i32 @foo(i32 %a) local_unnamed_addr !dbg !7 {
+  %b = add i32 %a, 1
+  call void @llvm.dbg.value(metadata i32 %b, metadata !11, metadata !DIExpression()), !dbg !12
+  ret i32 %b, !dbg !12
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5, !6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "foo.cpp", directory: ".")
+!2 = !DIBasicType(name: "int", size: 8, encoding: DW_ATE_signed)
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 2}
+!6 = !{i32 7, !"PIC Level", i32 2}
+!7 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 6, type: !8, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!2, !2}
+!10 = !{!11}
+!11 = !DILocalVariable(name: "baz", scope: !7, file: !1, line: 7, type: !2)
+!12 = !DILocation(line: 10, scope: !7)
Index: llvm/lib/Target/X86/X86TargetMachine.cpp
===
--- llvm/lib/Target/X86/X86TargetMachine.c

[PATCH] D114413: [OpenMPIRBuilder] Implement static-chunked workshare-loop schedules.

2021-11-29 Thread Peixin Qiao via Phabricator via cfe-commits
peixin added a comment.

@Meinersbur Please rebase on main. The function "getPreheader()" was moved into 
OMPIRBuilder.h.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114413

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


[PATCH] D114631: [DebugInfo][InstrRef] Turn instruction referencing on by default for x86

2021-11-29 Thread Jeremy Morse via Phabricator via cfe-commits
jmorse updated this revision to Diff 390003.
jmorse added a comment.

(Don't test for cc1 flag that's being deleted)


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

https://reviews.llvm.org/D114631

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/debug-var-experimental-switch.c
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/DebugInfo/X86/instr-ref-flag.ll

Index: llvm/test/DebugInfo/X86/instr-ref-flag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/instr-ref-flag.ll
@@ -0,0 +1,46 @@
+; RUN: llc %s -o - -stop-before=finalize-isel -march=x86-64 \
+; RUN: | FileCheck %s --check-prefixes=INSTRREFON
+; RUN: llc %s -o - -stop-before=finalize-isel -march=x86-64 \
+; RUN:-experimental-debug-variable-locations=true \
+; RUN: | FileCheck %s --check-prefixes=INSTRREFON
+
+; RUN: llc %s -o - -stop-before=finalize-isel -march=x86-64 \
+; RUN:-experimental-debug-variable-locations=false \
+; RUN: | FileCheck %s --check-prefixes=INSTRREFOFF \
+; RUN:--implicit-check-not=DBG_INSTR_REF
+
+;; This test checks that for an x86 triple, instruction referencing is used
+;; by llc by default, and that it can be turned explicitly on or off as
+;; desired.
+
+; INSTRREFON: DBG_INSTR_REF
+; INSTRREFOFF: DBG_VALUE
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-unknown"
+
+define hidden i32 @foo(i32 %a) local_unnamed_addr !dbg !7 {
+  %b = add i32 %a, 1
+  call void @llvm.dbg.value(metadata i32 %b, metadata !11, metadata !DIExpression()), !dbg !12
+  ret i32 %b, !dbg !12
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5, !6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "foo.cpp", directory: ".")
+!2 = !DIBasicType(name: "int", size: 8, encoding: DW_ATE_signed)
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 2}
+!6 = !{i32 7, !"PIC Level", i32 2}
+!7 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 6, type: !8, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!2, !2}
+!10 = !{!11}
+!11 = !DILocalVariable(name: "baz", scope: !7, file: !1, line: 7, type: !2)
+!12 = !DILocation(line: 10, scope: !7)
Index: llvm/lib/Target/X86/X86TargetMachine.cpp
===
--- llvm/lib/Target/X86/X86TargetMachine.cpp
+++ llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -26,6 +26,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/CodeGen/ExecutionDomainFix.h"
 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
 #include "llvm/CodeGen/GlobalISel/IRTranslator.h"
Index: llvm/lib/CodeGen/CommandFlags.cpp
===
--- llvm/lib/CodeGen/CommandFlags.cpp
+++ llvm/lib/CodeGen/CommandFlags.cpp
@@ -90,7 +90,7 @@
 CGOPT(bool, EmitCallSiteInfo)
 CGOPT(bool, EnableMachineFunctionSplitter)
 CGOPT(bool, EnableDebugEntryValues)
-CGOPT(bool, ValueTrackingVariableLocations)
+CGOPT_EXP(bool, ValueTrackingVariableLocations)
 CGOPT(bool, ForceDwarfFrameSection)
 CGOPT(bool, XRayOmitFunctionIndex)
 CGOPT(bool, DebugStrictDwarf)
@@ -534,12 +534,17 @@
   Options.EmitAddrsig = getEnableAddrsig();
   Options.EmitCallSiteInfo = getEmitCallSiteInfo();
   Options.EnableDebugEntryValues = getEnableDebugEntryValues();
-  Options.ValueTrackingVariableLocations = getValueTrackingVariableLocations();
   Options.ForceDwarfFrameSection = getForceDwarfFrameSection();
   Options.XRayOmitFunctionIndex = getXRayOmitFunctionIndex();
   Options.DebugStrictDwarf = getDebugStrictDwarf();
   Options.LoopAlignment = getAlignLoops();
 
+  if (auto Opt = getExplicitValueTrackingVariableLocations())
+Options.ValueTrackingVariableLocations = *Opt;
+  else
+Options.ValueTrackingVariableLocations =
+getDefaultValueTrackingVariableLocations(TheTriple);
+
   Options.MCOptions = mc::InitMCTargetOptionsFromFlags();
 
   Options.ThreadModel = getThreadModel();
@@ -692,3 +697,9 @@
   for (Function &F : M)
 setFunctionAttributes(CPU, Features, F);
 }
+
+bool codegen::getDefaultValueTrackingVariableLocations(const llvm::Triple &T) {
+  if (T.getArch() == llvm::Triple::x86_64)
+return true;
+  return false;
+}
Index: llvm/include/llvm/CodeGen/CommandFlags.h
==

[PATCH] D114631: [DebugInfo][InstrRef] Turn instruction referencing on by default for x86

2021-11-29 Thread Orlando Cazalet-Hyams via Phabricator via cfe-commits
Orlando added a comment.

Driver flag change seems ok but would appreciate another pair of eyes checking 
it makes sense. Everything else (test change omissions, new test, default flag 
settings) LGTM.




Comment at: llvm/lib/Target/X86/X86TargetMachine.cpp:29
 #include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/CodeGen/ExecutionDomainFix.h"

nit: Is this change necessary?


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

https://reviews.llvm.org/D114631

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


[PATCH] D114484: [NFC][AIX]Disable unsupported hip test on AIX

2021-11-29 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114484

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


[PATCH] D112431: [ARM][clang] Define feature test macro for the PACBTI-M extension

2021-11-29 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 390340.
stuij added a comment.

reuploading after rebase to resolve patch apply failure


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112431

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/test/Preprocessor/arm-target-features.c


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -896,6 +896,13 @@
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-NOBTI-EXT,CHECK-NOPAC-EXT %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m+pacbti -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-PACBTI-EXT %s
+// CHECK-NOBTI-EXT-NOT: #define __ARM_FEATURE_BTI 1
+// CHECK-NOPAC-EXT-NOT: #define __ARM_FEATURE_PAUTH 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_BTI 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_PAUTH 1
+
 // == Check BFloat16 Extensions.
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.6-a+bf16 -x c -E -dM %s 
-o - 2>&1 | FileCheck -check-prefix=CHECK-BFLOAT %s
 // CHECK-BFLOAT: #define __ARM_BF16_FORMAT_ALTERNATIVE 1
Index: clang/lib/Basic/Targets/ARM.h
===
--- clang/lib/Basic/Targets/ARM.h
+++ clang/lib/Basic/Targets/ARM.h
@@ -79,6 +79,8 @@
   unsigned DotProd : 1;
   unsigned HasMatMul : 1;
   unsigned FPRegsDisabled : 1;
+  unsigned HasPAC : 1;
+  unsigned HasBTI : 1;
 
   enum {
 LDREX_B = (1 << 0), /// byte (8-bit)
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -465,6 +465,8 @@
   HWDiv = 0;
   DotProd = 0;
   HasMatMul = 0;
+  HasPAC = 0;
+  HasBTI = 0;
   HasFloat16 = true;
   ARMCDECoprocMask = 0;
   HasBFloat16 = false;
@@ -547,6 +549,9 @@
   HasBFloat16 = true;
 } else if (Feature == "-fpregs") {
   FPRegsDisabled = true;
+} else if (Feature == "+pacbti") {
+  HasPAC = 1;
+  HasBTI = 1;
 }
   }
 
@@ -890,6 +895,12 @@
   if (HasMatMul)
 Builder.defineMacro("__ARM_FEATURE_MATMUL_INT8", "1");
 
+  if (HasPAC)
+Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
+
+  if (HasBTI)
+Builder.defineMacro("__ARM_FEATURE_BTI", "1");
+
   if (HasBFloat16) {
 Builder.defineMacro("__ARM_FEATURE_BF16", "1");
 Builder.defineMacro("__ARM_FEATURE_BF16_VECTOR_ARITHMETIC", "1");


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -896,6 +896,13 @@
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-NOBTI-EXT,CHECK-NOPAC-EXT %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m+pacbti -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-PACBTI-EXT %s
+// CHECK-NOBTI-EXT-NOT: #define __ARM_FEATURE_BTI 1
+// CHECK-NOPAC-EXT-NOT: #define __ARM_FEATURE_PAUTH 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_BTI 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_PAUTH 1
+
 // == Check BFloat16 Extensions.
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.6-a+bf16 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-BFLOAT %s
 // CHECK-BFLOAT: #define __ARM_BF16_FORMAT_ALTERNATIVE 1
Index: clang/lib/Basic/Targets/ARM.h
===
--- clang/lib/Basic/Targets/ARM.h
+++ clang/lib/Basic/Targets/ARM.h
@@ -79,6 +79,8 @@
   unsigned DotProd : 1;
   unsigned HasMatMul : 1;
   unsigned FPRegsDisabled : 1;
+  unsigned HasPAC : 1;
+  unsigned HasBTI : 1;
 
   enum {
 LDREX_B = (1 << 0), /// byte (8-bit)
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -465,6 +465,8 @@
   HWDiv = 0;
   DotProd = 0;
   HasMatMul = 0;
+  HasPAC = 0;
+  HasBTI = 0;
   HasFloat16 = true;
   ARMCDECoprocMask = 0;
   HasBFloat16 = false;
@@ -547,6 +549,9 @@
   HasBFloat16 = true;
 } else if (Feature == "-fpregs") {
   FPRegsDisabled = true;
+} else if (Feature == "+pacbti") {
+  HasPAC = 1;
+  HasBTI = 1;
 }
   }
 
@@ -890,6 +895,12 @@
   if (HasMatMul)
 Builder.defineMacro("__ARM_FEATURE_MATMUL_INT8", "1");
 
+  if (HasPAC)
+Builder.defineMacro("__ARM_FEATURE_PAUTH", 

[PATCH] D108643: Introduce _BitInt, deprecate _ExtInt

2021-11-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D108643#3140927 , @aaron.ballman 
wrote:

> In D108643#3093323 , @aaron.ballman 
> wrote:
>
>> In D108643#3106438 , 
>> @aaron.ballman wrote:
>>
>>> Ping
>>
>> Ping.
>
> Ping.

Ping.


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

https://reviews.llvm.org/D108643

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


[clang] fc53eb6 - Reapply 'Implement target_clones multiversioning'

2021-11-29 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2021-11-29T06:30:01-08:00
New Revision: fc53eb69c26cdd7efa6b629c187d04326f0448ca

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

LOG: Reapply 'Implement target_clones multiversioning'

See discussion in D51650, this change was a little aggressive in an
error while doing a 'while we were here', so this removes that error
condition, as it is apparently useful.

This reverts commit bb4934601d731465e01e2e22c80ce2dbe687d73f.

Added: 
clang/test/CodeGen/attr-target-clones.c
clang/test/CodeGenCXX/attr-target-clones.cpp
clang/test/Sema/attr-target-clones.c
clang/test/SemaCXX/attr-target-clones.cpp

Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Decl.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/test/Sema/attr-cpuspecific.c

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 85a3a8ab69708..2eacf1105c18c 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1840,7 +1840,8 @@ enum class MultiVersionKind {
   None,
   Target,
   CPUSpecific,
-  CPUDispatch
+  CPUDispatch,
+  TargetClones
 };
 
 /// Represents a function declaration or definition.
@@ -2459,6 +2460,10 @@ class FunctionDecl : public DeclaratorDecl,
   /// the target functionality.
   bool isTargetMultiVersion() const;
 
+  /// True if this function is a multiversioned dispatch function as a part of
+  /// the target-clones functionality.
+  bool isTargetClonesMultiVersion() const;
+
   /// \brief Get the associated-constraints of this function declaration.
   /// Currently, this will either be a vector of size 1 containing the
   /// trailing-requires-clause or an empty vector.

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 39588d94cf09b..fab3f3edfb831 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2677,6 +2677,40 @@ def Target : InheritableAttr {
   }];
 }
 
+def TargetClones : InheritableAttr {
+  let Spellings = [GCC<"target_clones">];
+  let Args = [VariadicStringArgument<"featuresStrs">];
+  let Documentation = [TargetClonesDocs];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let AdditionalMembers = [{
+StringRef getFeatureStr(unsigned Index) const {
+  return *(featuresStrs_begin() + Index);
+}
+// 'default' is always moved to the end, so it isn't considered
+// when mangling the index.
+unsigned getMangledIndex(unsigned Index) const {
+  if (getFeatureStr(Index) == "default")
+return std::count_if(featuresStrs_begin(), featuresStrs_end(),
+  [](StringRef S) { return S != "default"; });
+
+  return std::count_if(featuresStrs_begin(), featuresStrs_begin() + Index,
+   [](StringRef S) { return S != "default"; });
+}
+
+// True if this is the first of this version to appear in the config 
string.
+// This is used to make sure we don't try to emit this function multiple
+// times.
+bool isFirstOfVersion(unsigned Index) const {
+  StringRef FeatureStr(getFeatureStr(Index));
+  return 0 == std::count_if(
+  featuresStrs_begin(), featuresStrs_begin() + Index,
+  [FeatureStr](StringRef S) { return S == FeatureStr; });
+}
+  }];
+}
+
+def : MutualExclusions<[TargetClones, Target, CPUDispatch, CPUSpecific]>;
+
 def MinVectorWidth : InheritableAttr {
   let Spellings = [Clang<"min_vector_width">];
   let Args = [UnsignedArgument<"VectorWidth">];

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index e7afb3699eb17..10cce4c2d6898 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2233,6 +2233,40 @@ Additionally, a function may not become multiversioned 
after its first use.
 }];
 }
 
+def TargetClonesDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``target_clones("OPTIONS")`` attribute. This attribute may 
be
+attached to a function declaration and causes function multiversioning, where
+multiple versions of the function will be emitted with 
diff erent code
+generation options.  Additionally, these versions will be resolved at runtime
+based on the priority of their attribute opt

[PATCH] D51650: Implement target_clones multiversioning

2021-11-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Relanded: fc53eb69c26cdd7efa6b629c187d04326f0448ca 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D51650

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


[PATCH] D105169: [Clang/Test]: Rename enable_noundef_analysis to disable-noundef-analysis and turn it off by default

2021-11-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D105169#3130355 , @hyeongyukim 
wrote:

> In D105169#3115814 , @erichkeane 
> wrote:
>
>> Either this or D108453  (which were 
>> committed together!) caused this assert according to my git-bisect: 
>> https://godbolt.org/z/4rqYKfW7K
>>
>> NOTE that this fails in a lit-test for me, clang CodeGen/ifunc.c (though my 
>> downstream seems to run the verifier even with -emit-llvm, so you might need 
>> to just swap it to an -emit-obj to get this to repro).
>
> The lit-test failure of CodeGen/ifunc.c was not directly related to this 
> patch.
> `emitIFuncDefinition` was creating an incorrect function attribute.
> It added the noundef attribute to the function even though there are no 
> parameters (`foo_ifunc` function of `ifunc.c`), and it was fixed a few days 
> ago.
>
> The patch that solved this problem is D113352 
> .
>
>> The `emitIFuncDefinition` fucntion incorrectly passes the GlobalDecl of the 
>> IFunc itself to the call to GetOrCreateLLVMFunction for creating the 
>> resolver, which causes it to be created with a wrong attribute list, which 
>> fails `Verifier::visitFunction` with "Attribute after last parameter!". 
>> You'll note that unlike the relationship between aliases and their aliasees, 
>> the resolver and the ifunc have different types - the resolver takes no 
>> parameters.

Thanks for the update!  Sorry for the late response, i was on vacation the last 
two weeks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105169

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


[PATCH] D103317: [Analyzer][Core] Make SValBuilder to better simplify svals with 3 symbols in the tree

2021-11-29 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 390343.
martong marked an inline comment as done.
martong added a comment.

- Update a test case
- Rebase to the parent patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103317

Files:
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/svalbuilder-simplify-compound-svals.cpp
  clang/test/Analysis/taint-tester.c

Index: clang/test/Analysis/taint-tester.c
===
--- clang/test/Analysis/taint-tester.c
+++ clang/test/Analysis/taint-tester.c
@@ -59,7 +59,7 @@
   int tty = xy.y; // expected-warning + {{tainted}}
 }
 
-void BitwiseOp(int in, char inn) {
+void BitwiseOp(int in, char inn, int zz) {
   // Taint on bitwise operations, integer to integer cast.
   int m;
   int x = 0;
@@ -67,11 +67,12 @@
   int y = (in << (x << in)) * 5;// expected-warning + {{tainted}}
   // The next line tests integer to integer cast.
   int z = y & inn; // expected-warning + {{tainted}}
-  if (y == 5) // expected-warning + {{tainted}}
+  if (y == zz) { // expected-warning + {{tainted}}
 m = z | z;// expected-warning + {{tainted}}
+  }
   else
 m = inn;
-  int mm = m; // expected-warning + {{tainted}}
+  int mm = m; // expected-warning 1 {{tainted}}
 }
 
 // Test getenv.
Index: clang/test/Analysis/svalbuilder-simplify-compound-svals.cpp
===
--- /dev/null
+++ clang/test/Analysis/svalbuilder-simplify-compound-svals.cpp
@@ -0,0 +1,76 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -verify
+
+// Here we test whether the SValBuilder is capable to simplify existing
+// compound SVals (where there are at leaset 3 symbols in the tree) based on
+// newly added constraints.
+
+void clang_analyzer_eval(bool);
+void clang_analyzer_warnIfReached();
+
+void test_left_tree_constrained(int x, int y, int z) {
+  if (x + y + z != 0)
+return;
+  if (x + y != 0)
+return;
+  clang_analyzer_eval(x + y + z == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x + y == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(z == 0); // expected-warning{{TRUE}}
+  x = y = z = 1;
+  return;
+}
+
+void test_right_tree_constrained(int x, int y, int z) {
+  if (x + y * z != 0)
+return;
+  if (y * z != 0)
+return;
+  clang_analyzer_eval(x + y * z == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(y * z == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
+  return;
+}
+
+void test_left_tree_constrained_minus(int x, int y, int z) {
+  if (x - y - z != 0)
+return;
+  if (x - y != 0)
+return;
+  clang_analyzer_eval(x - y - z == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x - y == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(z == 0); // expected-warning{{TRUE}}
+  x = y = z = 1;
+  return;
+}
+
+void test_SymInt_constrained(int x, int y, int z) {
+  if (x * y * z != 4)
+return;
+  if (z != 2)
+return;
+  if (x * y == 3) {
+clang_analyzer_warnIfReached(); // no-warning
+return;
+  }
+  (void)(x * y * z);
+}
+
+void test_SValBuilder_simplifies_IntSym(int x, int y, int z) {
+  // Most IntSym BinOps are transformed to SymInt in SimpleSValBuilder.
+  // Division is one exception.
+  x = 77 / (y + z);
+  if (y + z != 1)
+return;
+  clang_analyzer_eval(x == 77); // expected-warning{{TRUE}}
+  (void)(x * y * z);
+}
+
+void recurring_symbol(int b) {
+  if (b * b != b)
+if ((b * b) * b * b != (b * b) * b)
+  if (b * b == 1)   // no-crash (assert should not fire)
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -1102,7 +1102,6 @@
   if (SymbolRef Sym = V.getAsSymbol())
 return state->getConstraintManager().getSymVal(state, Sym);
 
-  // FIXME: Add support for SymExprs.
   return nullptr;
 }
 
@@ -1134,6 +1133,24 @@
   return cache(Sym, SVB.makeSymbolVal(Sym));
 }
 
+// Return the known const value for the Sym if available, or return Undef
+// otherwise.
+SVal getConst(SymbolRef Sym) {
+  const llvm::APSInt *Const =
+  State->getConstraintManager().getSymVal(State, Sym);
+  if (Const)
+return Loc::isLocType(Sym->getType()) ? (SVal)SVB.makeIntLocVal(*Const)
+  : (SVal)SVB.makeIntVal(*Const);
+  return UndefinedVal();
+}
+
+SVal getConstOrVisit(SymbolRef Sym) {
+  const SVal Ret = getConst(Sym);
+  if (Re

[PATCH] D103317: [Analyzer][Core] Make SValBuilder to better simplify svals with 3 symbols in the tree

2021-11-29 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added inline comments.



Comment at: clang/test/Analysis/svalbuilder-simplify-compound-svals.cpp:75
+  if (b * b == 1)
+; // no-crash (assertion should not be violated)
+  }

steakhal wrote:
> I guess, this statement should not be reachable.
> Please demonstrate it by using the `clang_analyzer_WarnIfReached()`.
Actually, L72 simplifies to `1 != b`, L73 simplifies to the same, L74 is `b ^ 2 
== 1`. And this system has a solution: `b == -1` satisfies both L72 and L74 
conditions.
So, this line is reachable, correctly and I've updated the test case like so.

Note that, however, the ConstraintAssignor is not smart enough to deduce that 
`b == -1`. I have a WIP branch to accomplish that [[ 
https://github.com/martong/llvm-project/commit/ed7af2938789c8d2efea7f21b37c6da2d3580d9e
 | here ]].


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103317

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


[PATCH] D114080: [SYCL] Diagnose uses of zero length arrays

2021-11-29 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 390346.
Fznamznon marked an inline comment as done.
Fznamznon added a comment.

Apply suggestion from @bader


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114080

Files:
  clang/lib/Sema/SemaSYCL.cpp


Index: clang/lib/Sema/SemaSYCL.cpp
===
--- clang/lib/Sema/SemaSYCL.cpp
+++ clang/lib/Sema/SemaSYCL.cpp
@@ -122,8 +122,8 @@
   NeedToEmitNotes = false;
 }
 
-// In case pointer/array/reference type is met get pointeetype, then 
proceed
-// with that type.
+// In case pointer/array/reference type is met get pointee type, then
+// proceed with that type.
 while (NextTy->isAnyPointerType() || NextTy->isArrayType() ||
NextTy->isReferenceType()) {
   if (NextTy->isArrayType())


Index: clang/lib/Sema/SemaSYCL.cpp
===
--- clang/lib/Sema/SemaSYCL.cpp
+++ clang/lib/Sema/SemaSYCL.cpp
@@ -122,8 +122,8 @@
   NeedToEmitNotes = false;
 }
 
-// In case pointer/array/reference type is met get pointeetype, then proceed
-// with that type.
+// In case pointer/array/reference type is met get pointee type, then
+// proceed with that type.
 while (NextTy->isAnyPointerType() || NextTy->isArrayType() ||
NextTy->isReferenceType()) {
   if (NextTy->isArrayType())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114080: [SYCL] Diagnose uses of zero length arrays

2021-11-29 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon marked an inline comment as not done.
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaSYCL.cpp:68-75
+bool ErrorFound = false;
+if (isZeroSizedArray(*this, TypeToCheck)) {
+  SYCLDiagIfDeviceCode(UsedAt, diag::err_sycl_zero_array_size);
+  ErrorFound = true;
+}
+// Checks for other types can also be done here.
+if (ErrorFound) {

bader wrote:
> 
I'm not sure about this suggestion. I've made this place this way so It is easy 
to extend it to diagnose other types (for example variable length arrays). Is 
it ok if I leave it as is?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114080

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


[PATCH] D114619: [Analyzer][solver] Do not remove the simplified symbol from the eq class

2021-11-29 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 390349.
martong marked 4 inline comments as done.
martong added a comment.

- Update a comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114619

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/expr-inspection-printState-eq-classes.c
  clang/test/Analysis/symbol-simplification-disequality-info.cpp
  clang/test/Analysis/symbol-simplification-fixpoint-one-iteration.cpp
  clang/test/Analysis/symbol-simplification-fixpoint-two-iterations.cpp

Index: clang/test/Analysis/symbol-simplification-fixpoint-two-iterations.cpp
===
--- clang/test/Analysis/symbol-simplification-fixpoint-two-iterations.cpp
+++ clang/test/Analysis/symbol-simplification-fixpoint-two-iterations.cpp
@@ -27,17 +27,20 @@
   if (b != 0)
 return;
   clang_analyzer_printState();
-  // CHECK:   "constraints": [
-  // CHECK-NEXT:{ "symbol": "(reg_$0) != (reg_$3)", "range": "{ [0, 0] }" },
-  // CHECK-NEXT:{ "symbol": "reg_$1", "range": "{ [0, 0] }" },
-  // CHECK-NEXT:{ "symbol": "reg_$2", "range": "{ [0, 0] }" }
-  // CHECK-NEXT:  ],
-  // CHECK-NEXT:  "equivalence_classes": [
-  // CHECK-NEXT:[ "(reg_$0) != (reg_$3)" ],
-  // CHECK-NEXT:[ "reg_$0", "reg_$3" ],
-  // CHECK-NEXT:[ "reg_$2" ]
-  // CHECK-NEXT:  ],
-  // CHECK-NEXT:  "disequality_info": null,
+  // CHECK:  "constraints": [
+  // CHECK-NEXT:   { "symbol": "(((reg_$0) + (reg_$1)) + (reg_$2)) != (reg_$3)", "range": "{ [0, 0] }" },
+  // CHECK-NEXT:   { "symbol": "((reg_$0) + (reg_$2)) != (reg_$3)", "range": "{ [0, 0] }" },
+  // CHECK-NEXT:   { "symbol": "(reg_$0) != (reg_$3)", "range": "{ [0, 0] }" },
+  // CHECK-NEXT:   { "symbol": "(reg_$2) + (reg_$1)", "range": "{ [0, 0] }" },
+  // CHECK-NEXT:   { "symbol": "reg_$1", "range": "{ [0, 0] }" },
+  // CHECK-NEXT:   { "symbol": "reg_$2", "range": "{ [0, 0] }" }
+  // CHECK-NEXT: ],
+  // CHECK-NEXT: "equivalence_classes": [
+  // CHECK-NEXT:   [ "(((reg_$0) + (reg_$1)) + (reg_$2)) != (reg_$3)", "((reg_$0) + (reg_$2)) != (reg_$3)", "(reg_$0) != (reg_$3)" ],
+  // CHECK-NEXT:   [ "((reg_$0) + (reg_$1)) + (reg_$2)", "(reg_$0) + (reg_$2)", "reg_$0", "reg_$3" ],
+  // CHECK-NEXT:   [ "(reg_$2) + (reg_$1)", "reg_$2" ]
+  // CHECK-NEXT: ],
+  // CHECK-NEXT: "disequality_info": null,
 
   // Keep the symbols and the constraints! alive.
   (void)(a * b * c * d);
Index: clang/test/Analysis/symbol-simplification-fixpoint-one-iteration.cpp
===
--- clang/test/Analysis/symbol-simplification-fixpoint-one-iteration.cpp
+++ clang/test/Analysis/symbol-simplification-fixpoint-one-iteration.cpp
@@ -24,14 +24,15 @@
   if (b != 0)
 return;
   clang_analyzer_printState();
-  // CHECK:"constraints": [
-  // CHECK-NEXT: { "symbol": "(reg_$0) != (reg_$2)", "range": "{ [0, 0] }" },
-  // CHECK-NEXT: { "symbol": "reg_$1", "range": "{ [0, 0] }" }
-  // CHECK-NEXT:   ],
-  // CHECK-NEXT:   "equivalence_classes": [
-  // CHECK-NEXT: [ "(reg_$0) != (reg_$2)" ],
-  // CHECK-NEXT: [ "reg_$0", "reg_$2" ]
-  // CHECK-NEXT:   ],
+  // CHECK:  "constraints": [
+  // CHECK-NEXT:   { "symbol": "((reg_$0) + (reg_$1)) != (reg_$2)", "range": "{ [0, 0] }" },
+  // CHECK-NEXT:   { "symbol": "(reg_$0) != (reg_$2)", "range": "{ [0, 0] }" },
+  // CHECK-NEXT:   { "symbol": "reg_$1", "range": "{ [0, 0] }" }
+  // CHECK-NEXT: ],
+  // CHECK-NEXT: "equivalence_classes": [
+  // CHECK-NEXT:   [ "((reg_$0) + (reg_$1)) != (reg_$2)", "(reg_$0) != (reg_$2)" ],
+  // CHECK-NEXT:   [ "(reg_$0) + (reg_$1)", "reg_$0", "reg_$2" ]
+  // CHECK-NEXT: ],
   // CHECK-NEXT: "disequality_info": null,
 
   // Keep the symbols and the constraints! alive.
Index: clang/test/Analysis/symbol-simplification-disequality-info.cpp
===
--- clang/test/Analysis/symbol-simplification-disequality-info.cpp
+++ clang/test/Analysis/symbol-simplification-disequality-info.cpp
@@ -12,18 +12,18 @@
   if (a + b + c == d)
 return;
   clang_analyzer_printState();
-  // CHECK:   "disequality_info": [
-  // CHECK-NEXT:{
-  // CHECK-NEXT:  "class": [ "((reg_$0) + (reg_$1)) + (reg_$2)" ],
-  // CHECK-NEXT:  "disequal_to": [
-  // CHECK-NEXT:[ "reg_$3" ]]
-  // CHECK-NEXT:},
-  // CHECK-NEXT:{
-  // CHECK-NEXT:  "class": [ "reg_$3" ],
-  // CHECK-NEXT:  "disequal_to": [
-  // CHECK-NEXT:[ "((reg_$0) + (reg_$1)) + (reg_$2)" ]]
-  // CHECK-NEXT:}
-  // CHECK-NEXT:  ],
+  // CHECK:  "disequality_info": [
+  // CHECK-NEXT:   {
+  // CHECK-NEXT: "class": [ "((reg_$0) + (reg_$1)) + (reg_$2)" ],
+  // CHECK-NEXT: "disequal_to": [
+  // CHECK-NEXT:   [ "reg_$3" ]]
+  // CHECK-NEXT:   },
+  // CHECK-NEXT:   {
+  // CHECK-NEXT: "class": [ "reg_$3" 

[PATCH] D114619: [Analyzer][solver] Do not remove the simplified symbol from the eq class

2021-11-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:2226
+  //
+  // Empirical measurements show that if we relax assumption G then the
+  // runtime does not grow noticeably. This is most probably because the

steakhal wrote:
> Emphasize what you mean by //relaxation//. You meant probably something like 
> //not replacing the complex symbol, just adding the simplified version to the 
> class//.
ok



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:2227
+  // Empirical measurements show that if we relax assumption G then the
+  // runtime does not grow noticeably. This is most probably because the
+  // cost of removing the simplified member is much higher than the cost of

steakhal wrote:
> nor memory consumption
ok



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:2228-2229
+  // runtime does not grow noticeably. This is most probably because the
+  // cost of removing the simplified member is much higher than the cost of
+  // simplifying the symbol.
   State = reAssume(State, ClassConstraint, SimplifiedMemberVal);

steakhal wrote:
> Could you please elaborate on this in the review? I don't get the reasoning. 
> I might miss something.
It's not a reasoning, just a guessing. Another reason could be that simply the 
time we spend here is negligible compared to the time we spend e.g. in 
removeDeadBindings. (Actually,  removeDeadBindings is very hot and takes 
roughly 15-20 % of the runtime.) Perhaps I could do a measurement with a 
sampling profiler to be able to provide a precise explanation to this. But I 
think the point is that the runtime/memory consumption do not grow and the 
concrete reason is secondary.

However, you are right, I should not get into guessing here, I'll just remove 
this sentence.



Comment at: clang/test/Analysis/symbol-simplification-disequality-info.cpp:15-26
+  // CHECK:  "disequality_info": [
+  // CHECK-NEXT:   {
+  // CHECK-NEXT: "class": [ "((reg_$0) + (reg_$1)) + 
(reg_$2)" ],
+  // CHECK-NEXT: "disequal_to": [
+  // CHECK-NEXT:   [ "reg_$3" ]]
+  // CHECK-NEXT:   },
+  // CHECK-NEXT:   {

steakhal wrote:
> Please try to omit unnecessary changes.
I've made this change intentionally, so all hunks for each simplification steps 
are indented similarly. E.g., after the `CHECK-NEXT:` string comes 3 space 
characters until we the `{` character, see L16 and L34 and L51. Actually, I've 
made an indentation error in a previous patch, which I though I can correct now.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114619

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


[PATCH] D114619: [Analyzer][solver] Do not remove the simplified symbol from the eq class

2021-11-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D114619#3155363 , @steakhal wrote:

> I see. Simplification is always good. Let's measure and compare the runtime 
> characteristics before moving forward.

Here they are. Seems like the runtime and memory consumption are pretty much 
the same.

F20788018: no_removemember.png 

F20788026: stats.html 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114619

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


[PATCH] D114080: [SYCL] Diagnose uses of zero length arrays

2021-11-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I note that this is missing a test, otherwise I don't see any issues with it 
from my end.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114080

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 390352.
carlosgalvezp added a comment.

Added Widget test case (reusing the S2 struct instead of adding a new struct 
Widget)


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

https://reviews.llvm.org/D114427

Files:
  clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp

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
@@ -143,11 +143,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant cast to the same type
   // CHECK-FIXES: {{^}}  kZero;
 
-  int b2 = int(b);
-  int b3 = static_cast(b);
-  int b4 = b;
+  int b2 = static_cast(b);
+  int b3 = b;
   double aa = a;
-  (void)b2;
+  (void)aa;
   return (void)g();
 }
 
@@ -321,3 +320,50 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use constructor call syntax [
   // CHECK-FIXES: auto s6 = S(cr);
 }
+
+template 
+T functional_cast_template_used_by_class(float i) {
+  return T(i);
+}
+
+template 
+T functional_cast_template_used_by_int(float i) {
+  return T(i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; use static_cast
+  // CHECK-FIXES: return static_cast(i);
+}
+
+struct S2 {
+  S2(float);
+};
+using T = S2;
+using U = S2 &;
+
+void functional_casts() {
+  float x = 1.5F;
+  auto y = int(x);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: C-style casts are discouraged; use static_cast
+  // CHECK-FIXES: auto y = static_cast(x);
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wc++11-narrowing"
+  // This if fine, compiler will warn about implicit conversions with brace initialization
+  auto z = int{x};
+#pragma clang diagnostic pop
+
+  // Functional casts are allowed if S is of class type
+  const char *str = "foo";
+  auto s = S(str);
+
+  // Functional casts in template functions
+  functional_cast_template_used_by_class(x);
+  functional_cast_template_used_by_int(x);
+
+  // New expressions are not functional casts
+  auto w = new int(x);
+
+  // Typedefs
+  S2 t = T(x); // OK, constructor call
+  S2 u = U(x); // NOK, it's a reinterpret_cast in disguise
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -133,9 +133,11 @@
 Changes in existing checks
 ^^
 
-- Removed default setting `cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors = "true"`,
+- Removed default setting ``cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors = "true"``,
   to match the current state of the C++ Core Guidelines.
 
+- Updated ``google-readability-casting`` to diagnose and fix functional casts, to achieve feature
+  parity with the corresponding ``cpplint.py`` check.
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -31,6 +31,11 @@
   unless(isInTemplateInstantiation()))
   .bind("cast"),
   this);
+  Finder->addMatcher(
+  cxxFunctionalCastExpr(unless(hasDescendant(cxxConstructExpr())),
+unless(hasDescendant(initListExpr(
+  .bind("cast"),
+  this);
 }
 
 static bool needsConstCast(QualType SourceType, QualType DestType) {
@@ -55,8 +60,39 @@
   return T1.getUnqualifiedType() == T2.getUnqualifiedType();
 }
 
+static clang::CharSourceRange getReplaceRange(const CStyleCastExpr *CastExpr) {
+  return CharSourceRange::getCharRange(
+  CastExpr->getLParenLoc(), CastExpr->getSubExprAsWritten()->getBeginLoc());
+}
+
+static clang::CharSourceRange
+getReplaceRange(const CXXFunctionalCastExpr *CastExpr) {
+  return CharSourceRange::getCharRange(CastExpr->getBeginLoc(),
+   CastExpr->getLParenLoc());
+}
+
+static StringRef getDestTypeString(const SourceManager &SM,
+   const LangOptions &LangOpts,
+   const CStyleCastExpr *CastExpr) {
+  return Lexer::getSourceText(
+  CharSourceRange::getTokenRange(
+  CastExpr->getLParenLoc().getLocWithOffset(1),
+  CastExpr->getRParenLoc().getLocWithOffset(-1)),
+  SM, LangOpts);
+}
+
+static StringRef getDestTypeString(const SourceManager &SM,
+ 

[PATCH] D114553: [HIP] Add atomic load, atomic store and atomic cmpxchng_weak builtin support in HIP-clang

2021-11-29 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/test/SemaCUDA/atomic-ops.cu:69-74
+  flag = __hip_atomic_compare_exchange_weak(ptr, 0, 0, 0, 0, 
__HIP_MEMORY_SCOPE_SYSTEM); // expected-warning {{null passed to a callee that 
requires a non-null argument}}
+  flag = __hip_atomic_compare_exchange_weak(ptr, &val, desired, 0, 0, 
__HIP_MEMORY_SCOPE_SYSTEM);
+  flag = __hip_atomic_compare_exchange_weak(ptr, &val, desired, 1, 0, 
__HIP_MEMORY_SCOPE_SINGLETHREAD);
+  flag = __hip_atomic_compare_exchange_weak(ptr, &val, desired, 1, 0, 
__HIP_MEMORY_SCOPE_WAVEFRONT);
+  flag = __hip_atomic_compare_exchange_weak(ptr, &val, desired, 1, 1, 
__HIP_MEMORY_SCOPE_WORKGROUP);
+  flag = __hip_atomic_compare_exchange_weak(ptr, &val, desired, 1, 1, 
__HIP_MEMORY_SCOPE_AGENT);

pls use pre-defined macros for memory order


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114553

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp:342
+  auto w = new int(x);
+}

Quuxplusone wrote:
> salman-javed-nz wrote:
> > carlosgalvezp wrote:
> > > carlosgalvezp wrote:
> > > > Quuxplusone wrote:
> > > > > What about
> > > > > ```
> > > > > template T foo(int i) { return T(i); }
> > > > > int main() {
> > > > > foo>(); // valid, OK(!)
> > > > > foo(); // valid, not OK
> > > > > }
> > > > > ```
> > > > > What about
> > > > > ```
> > > > > struct Widget { Widget(int); };
> > > > > using T = Widget;
> > > > > using U = Widget&;
> > > > > int i = 42;
> > > > > Widget t = T(i);  // valid, OK?
> > > > > Widget u = U(i);  // valid C++, should definitely not be OK
> > > > > ```
> > > > > https://quuxplusone.github.io/blog/2020/01/22/expression-list-in-functional-cast/
> > > > Good point, thanks! I've added the first one to the unit test.
> > > > 
> > > > Regarding the second check, I'm not sure if it's the scope of this 
> > > > check. This check does not care whether the constructor of the class is 
> > > > implicit or not - if you use a class type, then you are calling the 
> > > > constructor so it's fine. Same goes when it's a reference - in my 
> > > > opinion this check is not concerned with that.
> > > > 
> > > > I definitely see the problems that can arise from the example that you 
> > > > posted, but maybe it fits better as a separate check in the `bugprone` 
> > > > category? This check (`google-readability-casting`) is focused only 
> > > > about avoiding C-style casting, i.e. it's a readability/style/modernize 
> > > > matter IMO. If cpplint is not diagnosing that, I don't think this check 
> > > > should either.
> > > It seems I should be able to just add the second example as a test and 
> > > clang-tidy would warn but, what should be the fixit for it? A 
> > > `static_cast` would lead to compiler error (which I personally would 
> > > gladly take, but I don't know in general if we want clang-tidy to "fix" 
> > > code leading to compiler errors"). Adding an ad-hoc message for this 
> > > particular error seems out of the scope of a "readability" check. 
> > > 
> > > What do you guys think?
> > > It seems I should be able to just add the second example as a test and 
> > > clang-tidy would warn but, what should be the fixit for it?
> > 
> > If I run the second example, but with old style C casts instead:
> > 
> > Input:
> > ```lang=cpp
> > struct Widget { Widget(int); };
> > using T = Widget;
> > using U = Widget&;
> > int i = 42;
> > Widget t = (T)(i);
> > Widget u = (U)(i);
> > ```
> > 
> > Output after fixits:
> > ```lang=cpp
> > struct Widget { Widget(int); };
> > using T = Widget;
> > using U = Widget&;
> > int i = 42;
> > Widget t = T(i);
> > Widget u = (U)(i);
> > ```
> > 
> > I guess the fix `Widget t = T(i);` is OK as it is covered by this exception:
> > >You may use cast formats like `T(x)` only when `T` is a class type.
> > 
> > For the `Widget u = (U)(i);` line, clang-tidy has warned about it but not 
> > offered a fix.
> > What would be the right fixit for that anyway?
> > `Widget u = U(i);   -->   Widget u = static_cast(i);` ?
> 
> No, this is a reinterpret_cast, so it would be
> ```
> Widget u = reinterpret_cast(i);
> ```
> at least in C++. I don't know about C, but I imagine the problem doesn't come 
> up.
> 
> (If the programmer looks at this line and says "oh geez, that's wrong," well, 
> he'll either fix it or file a task to revisit weird reinterpret_casts in the 
> codebase. If the programmer thinks the cast is //correct//, then personally 
> I'd hope he rewrites it as `Widget u = *reinterpret_cast(&i);` for 
> clarity, but that's not a clang-tidy issue.)
> 
> Relevant: "fixits versus suppression mechanisms" 
> https://quuxplusone.github.io/blog/2020/09/02/wparentheses/ 
> `reinterpret_cast` is a suppression mechanism; I infer that you're casting 
> about for a fixit, which won't exist in this case.
Added test case, currently it provides a generic comment.

Thanks a lot for the explanation, this was eye-opening to me. I only thought of 
reinterpret casts when using pointers, but of course references are kind of the 
same thing :) 

Let me know if you are happy with the patch!


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

https://reviews.llvm.org/D114427

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


[PATCH] D114080: [SYCL] Diagnose uses of zero length arrays

2021-11-29 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

In D114080#3158323 , @erichkeane 
wrote:

> I note that this is missing a test, otherwise I don't see any issues with it 
> from my end.

There is a test SemaSYCL/zero-length-arrays.cpp. For some reason after I 
updated this revision Phabricator doesn't show the full diff, but it shows both 
commits. The first commit with main changes and the test is available here - 
https://reviews.llvm.org/D114080?id=387904 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114080

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


[PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2021-11-29 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

> Have you checked whether there are any bots in the lab that will need to be 
> updated?

I did find a number of bots that I think need addressing, I am intending to 
privately email the owners but I haven't done that yet - @rnk maintains the 
sanitizer-windows and windows-gcebot2 machines, but there are others.




Comment at: clang/docs/UsersManual.rst:3546
 
-cmake -G"Visual Studio 15 2017" -T LLVM ..
+cmake -G"Visual Studio 17 2022" -T LLVM ..
 

aaron.ballman wrote:
> jhenderson wrote:
> > I think the missing space should be fixed to :)
> +1 to the missing space.
This one is confusing - it isn't in my local diff, the raw diff, or if I 
reapply the raw diff - it looks to have just appeared when you quote it in phab 
comments?



Comment at: llvm/cmake/modules/CheckCompilerVersion.cmake:17-18
+# _MSC_VER == 1929 MSVC++ 14.29 Visual Studio 2019 Version 16.10 & 16.11
+set(MSVC_MIN 19.20)
+set(MSVC_SOFT_ERROR 19.29)
 

aaron.ballman wrote:
> I'm a bit less certain that this is reasonable. 16.11.0 is from August 2021, 
> which seems incredibly new for giving soft errors on.
Our docs do say the latest update of the compiler, but I take your point.

16.10 (same _MSC_VER) was released in May 2021
https://docs.microsoft.com/en-us/visualstudio/install/visual-studio-build-numbers-and-release-dates?view=vs-2019

If we want something a year old, 16.8 + 16.9 (1928) is about right.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone accepted this revision.
Quuxplusone added a comment.

Marking "accepted" for the record; but my checkmark means merely "I'm not 
intending to block this," not "I claim the authority to say you //should// land 
this." :)




Comment at: clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp:170
+  : getDestTypeString(SM, getLangOpts(),
+  dyn_cast(CastExpr));
 

IMO, this repeated conditional (compare lines 119–122) should be factored out 
into the //body// of the helper function `getDestTypeString` (rather than being 
repeated at every call-site), and `getDestTypeString` should take a `const 
ExplicitCastExpr *` instead of having two overloads. (Notice that you never 
//use// the overloading for anything: everywhere you call into the overload 
set, you do so with a non-dependent `dyn_cast` wrapped in a `?:`, indicating 
that you don't really want overloading at all.)
```
StringRef DestTypeString = getDestTypeString(SM, getLangOpts(), CastExpr);
```



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp:358-360
+  // Functional casts in template functions
+  functional_cast_template_used_by_class(x);
+  functional_cast_template_used_by_int(x);

FWIW, I'd prefer to instantiate the same function template in both cases 
(because that's the interesting case for practical purposes — a template that's 
only instantiated once doesn't pose a problem for the programmer). But I get 
that you're doing this because it's easier to express the expected output.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp:369
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; 
use static_cast/const_cast/reinterpret_cast
+}

It has also just now occurred to me that it might be interesting to see what 
happens with this warning in a SFINAE context, e.g.
```
template auto is_castable(int i) -> decltype(T(i), void(), true) { 
return true; }
```
but I suppose none of the things we could do there would be remotely sensible, 
so you'd just be testing basically that clang-tidy doesn't crash in that case. 
Anyway, no action needed.


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

https://reviews.llvm.org/D114427

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


[PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2021-11-29 Thread James Henderson via Phabricator via cfe-commits
jhenderson added inline comments.



Comment at: clang/docs/UsersManual.rst:3546
 
-cmake -G"Visual Studio 15 2017" -T LLVM ..
+cmake -G"Visual Studio 17 2022" -T LLVM ..
 

RKSimon wrote:
> aaron.ballman wrote:
> > jhenderson wrote:
> > > I think the missing space should be fixed to :)
> > +1 to the missing space.
> This one is confusing - it isn't in my local diff, the raw diff, or if I 
> reapply the raw diff - it looks to have just appeared when you quote it in 
> phab comments?
The fact that the space is missing? It's missing in the current repo too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

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


[PATCH] D114713: [AArch64][SVE][NEON] Add NEON-SVE-Bridge intrinsics

2021-11-29 Thread Matt Devereau via Phabricator via cfe-commits
MattDevereau created this revision.
MattDevereau added reviewers: bsmith, peterwaller-arm, DavidTruby, 
paulwalker-arm.
Herald added subscribers: psnobl, hiraditya, kristof.beyls, tschuett, mgorny.
Herald added a reviewer: efriedma.
MattDevereau requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Adds svset_neonq, svget_neonq, svdup_neonq AArch64 intrinsics.

These are described in the ACLE specification:
https://github.com/ARM-software/acle/pull/72


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114713

Files:
  clang/include/clang/Basic/BuiltinsAArch64NeonSVEBridge.def
  clang/include/clang/Basic/BuiltinsAArch64NeonSVEBridge_cg.def
  clang/include/clang/Basic/BuiltinsSVE.def
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/arm_neon_sve_bridge.h
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_get_neonq.c
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_set_neonq.c
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -1322,6 +1322,7 @@
   setOperationAction(ISD::MGATHER, VT, Custom);
   setOperationAction(ISD::MSCATTER, VT, Custom);
   setOperationAction(ISD::MLOAD, VT, Custom);
+  setOperationAction(ISD::INSERT_SUBVECTOR, VT, Custom);
 }
 
 setOperationAction(ISD::SPLAT_VECTOR, MVT::nxv8bf16, Custom);
Index: clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_set_neonq.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_set_neonq.c
@@ -0,0 +1,188 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve2 -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve2 -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve2 -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -o /dev/null %s
+#include 
+
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+
+// CHECK-LABEL: @test_svset_neonq_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv16i8.v16i8( [[S:%.*]], <16 x i8> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z19test_svset_neonq_s8u10__SVInt8_t11__Int8x16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv16i8.v16i8( [[S:%.*]], <16 x i8> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint8_t test_svset_neonq_s8(svint8_t s, int8x16_t n)
+{
+  return SVE_ACLE_FUNC(svset_neonq,_s8,,)(s, n);
+}
+
+// CHECK-LABEL: @test_svset_neonq_s16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv8i16.v8i16( [[S:%.*]], <8 x i16> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svset_neonq_s16u11__SVInt16_t11__Int16x8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv8i16.v8i16( [[S:%.*]], <8 x i16> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint16_t test_svset_neonq_s16(svint16_t s, int16x8_t n)
+{
+  return SVE_ACLE_FUNC(svset_neonq,_s16,,)(s, n);
+}
+
+// CHECK-LABEL: @test_svset_neonq_s32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv4i32.v4i32( [[S:%.*]], <4 x i32> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svset_neonq_s32u11__SVInt32_t11__Int32x4_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv4i32.v4i32( [[S:%.*]], <4 x i32> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint32_t test_svset_neonq_s32(svint32_t s, int32x4_t n)
+{
+  return SVE_ACLE_FUNC(svset_neonq,_s32,,)(s, n);
+}
+
+// CHECK-LABEL: @test_svset_neonq_s64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv2i64.v2i64( [[S:%.*]], <2 x i64> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 

[PATCH] D114080: [SYCL] Diagnose uses of zero length arrays

2021-11-29 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 390376.
Fznamznon added a comment.

An attempt to fix review page


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114080

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/test/SemaSYCL/zero-length-arrays.cpp

Index: clang/test/SemaSYCL/zero-length-arrays.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/zero-length-arrays.cpp
@@ -0,0 +1,125 @@
+// RUN: %clang_cc1 -fsycl-is-device -triple spir64 -fsyntax-only -verify %s
+//
+// This test checks if compiler reports compilation error on an attempt to use
+// a zero-length array inside device code.
+
+template 
+__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
+  // expected-note@+1 5{{called by 'kernel}}
+  kernelFunc(); // #KernelObjCall
+}
+
+typedef float ZEROARR[0];
+
+struct Wrapper {
+  int A;
+  int BadArray[0]; // expected-note 3{{field of illegal type 'int[0]' declared here}}
+};
+
+struct WrapperOfWrapper { // expected-error 2{{zero-length arrays are not permitted in SYCL device code}}
+  Wrapper F;  // expected-note 2{{within field of type 'Wrapper' declared here}}
+  ZEROARR *Ptr;   //expected-note 5{{field of illegal pointer type 'ZEROARR *' (aka 'float (*)[0]') declared here}}
+};
+
+template  struct InnerTemplated {
+  double Array[Size]; // expected-note 8{{field of illegal type 'double[0]' declared here}}
+};
+
+template  struct Templated {
+  unsigned A;
+  Ty Arr[Size];
+  InnerTemplated Array[Size + 1]; // expected-note 8{{within field of type 'InnerTemplated<0U>[1]' declared here}}
+};
+
+struct KernelSt {
+  int A;
+  int BadArray[0]; // expected-note {{field of illegal type 'int[0]' declared here}}
+  void operator()() const {}
+};
+
+WrapperOfWrapper offendingFoo() {
+  // expected-note@+1 {{called by 'offendingFoo'}}
+  return WrapperOfWrapper{};
+}
+
+template 
+void templatedContext() {
+  Templated Var;
+  // expected-error@#KernelObjCall 2{{zero-length arrays are not permitted in SYCL device code}}
+  // expected-note@#KernelObjCall {{called by 'kernel([=] {
+// expected-note@+1 {{within field of type 'Templated<0U, float>' declared here}}
+(void)Var; // expected-error 2{{zero-length arrays are not permitted in SYCL device code}}
+  });
+  // expected-error@#KernelObjCall {{zero-length arrays are not permitted in SYCL device code}}
+  // expected-note@+2 {{in instantiation of function template specialization}}
+  // expected-note@+1 {{within field of type 'Templated<0U, float>' declared here}}
+  kernel([Var] {
+  });
+}
+
+void foo(const unsigned X) {
+  int Arr[0];  // expected-note 2{{declared here}}
+  ZEROARR TypeDef; // expected-note {{declared here}}
+  ZEROARR *Ptr;// expected-note {{declared here}}
+   // expected-error@#KernelObjCall 3{{zero-length arrays are not permitted in SYCL device code}}
+  // expected-note@+1 {{in instantiation of function template specialization}}
+  kernel([=]() {
+(void)Arr; // expected-error {{zero-length arrays are not permitted in SYCL device code}}
+(void)TypeDef; // expected-error {{zero-length arrays are not permitted in SYCL device code}}
+// expected-note@+1 {{field of illegal pointer type 'ZEROARR *' (aka 'float (*)[0]') declared here}}
+(void)Ptr; // expected-error {{zero-length arrays are not permitted in SYCL device code}}
+  });
+  // expected-error@#KernelObjCall {{zero-length arrays are not permitted in SYCL device code}}
+  // expected-note@+2 {{in instantiation of function template specialization}}
+  // expected-note@+1 {{field of illegal type 'int[0]' declared here}}
+  kernel([Arr] { // expected-error {{zero-length arrays are not permitted in SYCL device code}}
+  });
+  WrapperOfWrapper St;
+  // expected-error@#KernelObjCall 2{{zero-length arrays are not permitted in SYCL device code}}
+  // expected-note@+1 {{in instantiation of function template specialization}}
+  kernel([=] {
+// expected-note@+1 {{within field of type 'WrapperOfWrapper' declared here}}
+(void)St.F.BadArray; // expected-error 4{{zero-length arrays are not permitted in SYCL device code}}
+  });
+  // expected-error@#KernelObjCall 2{{zero-length arrays are not permitted in SYCL device code}}
+  // expected-note@+2 {{in instantiation of function template specialization}}
+  // expected-note@+1 {{within field of type 'WrapperOfWrapper' declared here}}
+  kernel([St] { // expected-error 2{{zero-length arrays are not permitted in SYCL device code}}
+  });
+
+  Templated<1, int> OK;
+  Templated<1 - 1, double> Weirdo;
+  Templated<0, float> Zero;
+  // expected-error@#KernelObjCall 4{{zero-length arrays are not permitted in SYCL device code}}
+  // expected-note@+1 {{in instantiation of function template specialization}}
+  

[PATCH] D114553: [HIP] Add atomic load, atomic store and atomic cmpxchng_weak builtin support in HIP-clang

2021-11-29 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 390377.
gandhi21299 added a comment.

- replaced integers with memory order macros in SemaCUDA/atomic-ops.cu


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114553

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/Expr.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGenCUDA/atomic-ops.cu
  clang/test/SemaCUDA/atomic-ops.cu

Index: clang/test/SemaCUDA/atomic-ops.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/atomic-ops.cu
@@ -0,0 +1,86 @@
+// RUN: %clang_cc1 -x hip -std=c++11 -triple amdgcn -fcuda-is-device -verify -fsyntax-only %s
+
+#include "Inputs/cuda.h"
+
+__device__ int test_hip_atomic_load(int *pi32, unsigned int *pu32, long long *pll, unsigned long long *pull, float *fp, double *dbl) {
+  int val = __hip_atomic_load(0);  // expected-error {{too few arguments to function call, expected 3, have 1}}
+  val = __hip_atomic_load(0, 0, 0, 0); // expected-error {{too many arguments to function call, expected 3, have 4}}
+  val = __hip_atomic_load(0, 0, 0);// expected-error {{address argument to atomic builtin must be a pointer ('int' invalid)}}
+  val = __hip_atomic_load(pi32, 0, 0); // expected-error {{synchronization scope argument to atomic operation is invalid}}
+  val = __hip_atomic_load(pi32, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  val = __hip_atomic_load(pi32, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_WAVEFRONT);
+  val = __hip_atomic_load(pi32, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_WORKGROUP);
+  val = __hip_atomic_load(pi32, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT);
+  val = __hip_atomic_load(pi32, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SYSTEM);
+  val = __hip_atomic_load(pi32, __ATOMIC_RELAXED, 6); // expected-error {{synchronization scope argument to atomic operation is invalid}}
+  val = __hip_atomic_load(pi32, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  val = __hip_atomic_load(pi32, __ATOMIC_SEQ_CST, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  val = __hip_atomic_load(pi32, __ATOMIC_CONSUME, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  val = __hip_atomic_load(pi32, __ATOMIC_ACQUIRE, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  val = __hip_atomic_load(pi32, __ATOMIC_ACQ_REL, __HIP_MEMORY_SCOPE_SINGLETHREAD); // expected-warning{{memory order argument to atomic operation is invalid}}
+  val = __hip_atomic_load(pu32, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  val = __hip_atomic_load(pll, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  val = __hip_atomic_load(pull, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  val = __hip_atomic_load(fp, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  val = __hip_atomic_load(dbl, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  return val;
+}
+
+__device__ int test_hip_atomic_store(int *pi32, unsigned int *pu32, long long *pll, unsigned long long *pull, float *fp, double *dbl,
+ int i32, unsigned int u32, long long i64, unsigned long long u64, float f32, double f64) {
+  __hip_atomic_store(0); // expected-error {{too few arguments to function call, expected 4, have 1}}
+  __hip_atomic_store(0, 0, 0, 0, 0); // expected-error {{too many arguments to function call, expected 4, have 5}}
+  __hip_atomic_store(0, 0, 0, 0);// expected-error {{address argument to atomic builtin must be a pointer ('int' invalid)}}
+  __hip_atomic_store(pi32, 0, 0, 0); // expected-error {{synchronization scope argument to atomic operation is invalid}}
+  __hip_atomic_store(pi32, 0, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  __hip_atomic_store(pi32, 0, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_WAVEFRONT);
+  __hip_atomic_store(pi32, 0, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_WORKGROUP);
+  __hip_atomic_store(pi32, 0, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT);
+  __hip_atomic_store(pi32, 0, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SYSTEM);
+  __hip_atomic_store(pi32, 0, __ATOMIC_RELAXED, 6); // expected-error {{synchronization scope argument to atomic operation is invalid}}
+  __hip_atomic_store(pi32, 0, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  __hip_atomic_store(pi32, 0, __ATOMIC_SEQ_CST, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+  __hip_atomic_store(pi32, 0, __ATOMIC_CONSUME, __HIP_MEMORY_SCOPE_SINGLETHREAD); // expected-warning{{memory order argument to atomic operation is invalid}}
+  __hip_atomic_store(pi32, 0, __ATOMIC_ACQUIRE, __HIP_MEMORY_SCOPE_SINGLETHREAD); // expected-warning{{memory order argument to atomic operation is invalid}}
+  __hip_atomic_store(pi32, 0, __ATOMIC_ACQ_REL, __HIP_MEMORY_SCOPE_SINGLETHREAD); // expected-warning{{memory order argument to atomic operation is invalid}}
+  __hip_atomic_store(pi32, i32, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SINGLETHREAD);
+ 

[PATCH] D114080: [SYCL] Diagnose uses of zero length arrays

2021-11-29 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

In D114080#3158368 , @Fznamznon wrote:

> In D114080#3158323 , @erichkeane 
> wrote:
>
>> I note that this is missing a test, otherwise I don't see any issues with it 
>> from my end.
>
> There is a test SemaSYCL/zero-length-arrays.cpp. For some reason after I 
> updated this revision Phabricator doesn't show the full diff, but it shows 
> both commits. The first commit with main changes and the test is available 
> here - https://reviews.llvm.org/D114080?id=387904 .

It seems I was able to fix that. Now the link to this revision shows the full 
diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114080

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


[PATCH] D110833: [clang-format] Refactor SpaceBeforeParens to add options

2021-11-29 Thread C. Rayroud via Phabricator via cfe-commits
crayroud added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:14165
+  SpaceFuncDecl.SpaceBeforeParens = FormatStyle::SBPO_Custom;
+  SpaceFuncDecl.SpaceBeforeParensOptions.AfterFunctionDeclarationName = true;
+

MyDeveloperDay wrote:
> are you testing the -ve case anywhere?
What do you mean by "-ve case" ?


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

https://reviews.llvm.org/D110833

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


[PATCH] D113837: Sema: Let InitListExpr have dependent type instead of 'void'

2021-11-29 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

Ping @rsmith.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113837

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


[PATCH] D114713: [AArch64][SVE][NEON] Add NEON-SVE-Bridge intrinsics

2021-11-29 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:1325
   setOperationAction(ISD::MLOAD, VT, Custom);
+  setOperationAction(ISD::INSERT_SUBVECTOR, VT, Custom);
 }

Can you extract this into its own patch as it's really not relevant to the rest 
of the patch and is currently missing tests.  Presumably 
`llvm/test/CodeGen/AArch64/sve-insert-vector.ll` needs updating?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114713

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


[PATCH] D112881: [clang-tidy] Allow disabling integer to floating-point narrowing conversions for cppcoreguidelines-narrowing-conversions

2021-11-29 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, with a few small nits. It'd be nice to update the patch summary with more 
information about why the option is needed.




Comment at: clang-tools-extra/docs/ReleaseNotes.rst:122
 
+- :doc:`cppcoreguidelines-narrowing-conversions 
` check now supports 
a WarnOnIntegerToFloatingPointNarrowingConversion option to control whether to 
warn on narrowing integer to floating-point conversions.
+

Can you add backticks around `WarnOnIntegerToFloatingPointNarrowingConversion` 
so it gets highlighted properly, and reflow to the usual 80-col limit (it's 
fine to ignore it when links get too long, but not fine for a whole paragraph).


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

https://reviews.llvm.org/D112881

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


[PATCH] D114696: [clang-format] regressed default behavior for operator parentheses

2021-11-29 Thread C. Rayroud via Phabricator via cfe-commits
crayroud added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:14126-14127
+  // FIXME these tests regressed behaviour.
+  // verifyFormat("T A::operator() ();", Space);
+  // verifyFormat("X A::operator++ (T);", Space);
   verifyFormat("auto lambda = [] () { return 0; };", Space);

Why did you comment these lines? When SpaceBeforeParens is set to always it is 
not correct to have a space before the opening parenthesis, for operators ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114696

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 390380.
carlosgalvezp marked 6 inline comments as done.
carlosgalvezp added a comment.

Moved conditionals inside function body.


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

https://reviews.llvm.org/D114427

Files:
  clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp

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
@@ -143,11 +143,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant cast to the same type
   // CHECK-FIXES: {{^}}  kZero;
 
-  int b2 = int(b);
-  int b3 = static_cast(b);
-  int b4 = b;
+  int b2 = static_cast(b);
+  int b3 = b;
   double aa = a;
-  (void)b2;
+  (void)aa;
   return (void)g();
 }
 
@@ -321,3 +320,50 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use constructor call syntax [
   // CHECK-FIXES: auto s6 = S(cr);
 }
+
+template 
+T functional_cast_template_used_by_class(float i) {
+  return T(i);
+}
+
+template 
+T functional_cast_template_used_by_int(float i) {
+  return T(i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; use static_cast
+  // CHECK-FIXES: return static_cast(i);
+}
+
+struct S2 {
+  S2(float);
+};
+using T = S2;
+using U = S2 &;
+
+void functional_casts() {
+  float x = 1.5F;
+  auto y = int(x);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: C-style casts are discouraged; use static_cast
+  // CHECK-FIXES: auto y = static_cast(x);
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wc++11-narrowing"
+  // This if fine, compiler will warn about implicit conversions with brace initialization
+  auto z = int{x};
+#pragma clang diagnostic pop
+
+  // Functional casts are allowed if S is of class type
+  const char *str = "foo";
+  auto s = S(str);
+
+  // Functional casts in template functions
+  functional_cast_template_used_by_class(x);
+  functional_cast_template_used_by_int(x);
+
+  // New expressions are not functional casts
+  auto w = new int(x);
+
+  // Typedefs
+  S2 t = T(x); // OK, constructor call
+  S2 u = U(x); // NOK, it's a reinterpret_cast in disguise
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -133,9 +133,11 @@
 Changes in existing checks
 ^^
 
-- Removed default setting `cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors = "true"`,
+- Removed default setting ``cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors = "true"``,
   to match the current state of the C++ Core Guidelines.
 
+- Updated ``google-readability-casting`` to diagnose and fix functional casts, to achieve feature
+  parity with the corresponding ``cpplint.py`` check.
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -31,6 +31,11 @@
   unless(isInTemplateInstantiation()))
   .bind("cast"),
   this);
+  Finder->addMatcher(
+  cxxFunctionalCastExpr(unless(hasDescendant(cxxConstructExpr())),
+unless(hasDescendant(initListExpr(
+  .bind("cast"),
+  this);
 }
 
 static bool needsConstCast(QualType SourceType, QualType DestType) {
@@ -55,8 +60,57 @@
   return T1.getUnqualifiedType() == T2.getUnqualifiedType();
 }
 
+static clang::CharSourceRange getReplaceRange(const CStyleCastExpr *CastExpr) {
+  return CharSourceRange::getCharRange(
+  CastExpr->getLParenLoc(), CastExpr->getSubExprAsWritten()->getBeginLoc());
+}
+
+static clang::CharSourceRange
+getReplaceRange(const CXXFunctionalCastExpr *CastExpr) {
+  return CharSourceRange::getCharRange(CastExpr->getBeginLoc(),
+   CastExpr->getLParenLoc());
+}
+
+static clang::CharSourceRange
+getReplaceRange(const ExplicitCastExpr *CastExpr) {
+  return isa(CastExpr)
+ ? getReplaceRange(dyn_cast(CastExpr))
+ : getReplaceRange(dyn_cast(CastExpr));
+}
+
+static StringRef getDestTypeString(const SourceManager &SM,
+   const LangOptions &LangOpts,
+   const CStyleCastExpr *CastExpr) {
+  return Lexer::getSourceText(
+  CharSourceRange::

[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp:170
+  : getDestTypeString(SM, getLangOpts(),
+  dyn_cast(CastExpr));
 

Quuxplusone wrote:
> IMO, this repeated conditional (compare lines 119–122) should be factored out 
> into the //body// of the helper function `getDestTypeString` (rather than 
> being repeated at every call-site), and `getDestTypeString` should take a 
> `const ExplicitCastExpr *` instead of having two overloads. (Notice that you 
> never //use// the overloading for anything: everywhere you call into the 
> overload set, you do so with a non-dependent `dyn_cast` wrapped in a `?:`, 
> indicating that you don't really want overloading at all.)
> ```
> StringRef DestTypeString = getDestTypeString(SM, getLangOpts(), CastExpr);
> ```
Updated to move the conditional into the function. I cannot avoid the casting 
though, because there is no common base class of `CXXFunctionalCastExpr` and 
`CStyleCastExpr` that has the methods `getLParenLoc` and so on, so that's why I 
need the type explicitly instead of invoking those methods from the base class.

The original solution used templates instead of overloading for this, but 
@salman-javed-nz suggested overloading instead. I think that's a bit easier to 
read IMO, with small functions having a single responsibility.

Let me know if you like the update :) 



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp:358-360
+  // Functional casts in template functions
+  functional_cast_template_used_by_class(x);
+  functional_cast_template_used_by_int(x);

Quuxplusone wrote:
> FWIW, I'd prefer to instantiate the same function template in both cases 
> (because that's the interesting case for practical purposes — a template 
> that's only instantiated once doesn't pose a problem for the programmer). But 
> I get that you're doing this because it's easier to express the expected 
> output.
Yeah I'd prefer that too, but I wasn't sure how to set expectations on the same 
line for different inputs.


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

https://reviews.llvm.org/D114427

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D114427#3158405 , @Quuxplusone 
wrote:

> Marking "accepted" for the record; but my checkmark means merely "I'm not 
> intending to block this," not "I claim the authority to say you //should// 
> land this." :)

Thanks! I was recently told that this is not recommended, as the patch no 
longer shows the status "Needs review to proceed" and reviewers might not be 
able to see it immediately in their dashboards, thus delaying review.


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

https://reviews.llvm.org/D114427

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


[PATCH] D103317: [Analyzer][Core] Make SValBuilder to better simplify svals with 3 symbols in the tree

2021-11-29 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

Still looks great.




Comment at: clang/test/Analysis/svalbuilder-simplify-compound-svals.cpp:75
+  if (b * b == 1)
+; // no-crash (assertion should not be violated)
+  }

martong wrote:
> steakhal wrote:
> > I guess, this statement should not be reachable.
> > Please demonstrate it by using the `clang_analyzer_WarnIfReached()`.
> Actually, L72 simplifies to `1 != b`, L73 simplifies to the same, L74 is `b ^ 
> 2 == 1`. And this system has a solution: `b == -1` satisfies both L72 and L74 
> conditions.
> So, this line is reachable, correctly and I've updated the test case like so.
> 
> Note that, however, the ConstraintAssignor is not smart enough to deduce that 
> `b == -1`. I have a WIP branch to accomplish that [[ 
> https://github.com/martong/llvm-project/commit/ed7af2938789c8d2efea7f21b37c6da2d3580d9e
>  | here ]].
Uh, you are right. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103317

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


[PATCH] D114615: [NFC][clang]Increase the number of driver diagnostics

2021-11-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Please ignore the clang-format suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114615

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


[PATCH] D114619: [Analyzer][solver] Do not remove the simplified symbol from the eq class

2021-11-29 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

I think it looks great.




Comment at: clang/test/Analysis/symbol-simplification-disequality-info.cpp:15-26
+  // CHECK:  "disequality_info": [
+  // CHECK-NEXT:   {
+  // CHECK-NEXT: "class": [ "((reg_$0) + (reg_$1)) + 
(reg_$2)" ],
+  // CHECK-NEXT: "disequal_to": [
+  // CHECK-NEXT:   [ "reg_$3" ]]
+  // CHECK-NEXT:   },
+  // CHECK-NEXT:   {

martong wrote:
> steakhal wrote:
> > Please try to omit unnecessary changes.
> I've made this change intentionally, so all hunks for each simplification 
> steps are indented similarly. E.g., after the `CHECK-NEXT:` string comes 3 
> space characters until we the `{` character, see L16 and L34 and L51. 
> Actually, I've made an indentation error in a previous patch, which I though 
> I can correct now.
> 
Fine by me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114619

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp:101-110
+static StringRef getDestTypeString(const SourceManager &SM,
+   const LangOptions &LangOpts,
+   const ExplicitCastExpr *CastExpr) {
+  return isa(CastExpr)
+ ? getDestTypeString(SM, LangOpts,
+ dyn_cast(CastExpr))
+ : getDestTypeString(

I actually meant to move the conditional //inside// the body, like this. ^
Now there's only one function, and the reader doesn't have to do mental 
overload resolution to figure out what the caller's behavior is intended to be.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp:318
   // FIXME: This should be a static_cast.
   // C HECK-FIXES: auto s5 = static_cast(cr);
   auto s6 = (S)cr;

Pre-existing: This looks accidental.


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

https://reviews.llvm.org/D114427

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


[PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2021-11-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D114639#3158401 , @RKSimon wrote:

>> Have you checked whether there are any bots in the lab that will need to be 
>> updated?
>
> I did find a number of bots that I think need addressing, I am intending to 
> privately email the owners but I haven't done that yet - @rnk maintains the 
> sanitizer-windows and windows-gcebot2 machines, but there are others.

Thanks! I think we'll need the bot situation sorted out before we land this, 
otherwise we'll have bots red and failing to report newly introduced 
regressions from other patches. (Hopefully we'll replace the bots with ones 
that test newer VS configurations rather than lose the coverage entirely.)




Comment at: llvm/cmake/modules/CheckCompilerVersion.cmake:17-18
+# _MSC_VER == 1929 MSVC++ 14.29 Visual Studio 2019 Version 16.10 & 16.11
+set(MSVC_MIN 19.20)
+set(MSVC_SOFT_ERROR 19.29)
 

RKSimon wrote:
> aaron.ballman wrote:
> > I'm a bit less certain that this is reasonable. 16.11.0 is from August 
> > 2021, which seems incredibly new for giving soft errors on.
> Our docs do say the latest update of the compiler, but I take your point.
> 
> 16.10 (same _MSC_VER) was released in May 2021
> https://docs.microsoft.com/en-us/visualstudio/install/visual-studio-build-numbers-and-release-dates?view=vs-2019
> 
> If we want something a year old, 16.8 + 16.9 (1928) is about right.
16.7 (1927) would also be quite reasonable (Aug 2020). I don't have a strong 
preference for 16.7 vs 16.8, so I took a look at the release notes. 16.8 added 
support for newer C++ features, but not ones we care about consuming in our 
code base (coroutines, concepts, , some STL improvements, etc), so I 
think we'd be fine with 16.7 if we wanted to be more conservative on the window 
for the soft error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp:63-79
+static clang::CharSourceRange getReplaceRange(const CStyleCastExpr *CastExpr) {
+  return CharSourceRange::getCharRange(
+  CastExpr->getLParenLoc(), 
CastExpr->getSubExprAsWritten()->getBeginLoc());
+}
+
+static clang::CharSourceRange
+getReplaceRange(const CXXFunctionalCastExpr *CastExpr) {

Ditto here:
```
static clang::CharSourceRange
getReplaceRange(const ExplicitCastExpr *Expr) {
  if (const auto *CastExpr = dyn_cast(Expr)) {
return CharSourceRange::getCharRange(
CastExpr->getLParenLoc(), 
CastExpr->getSubExprAsWritten()->getBeginLoc());
  } else if (const auto *CastExpr = dyn_cast(Expr)) {
return CharSourceRange::getCharRange(CastExpr->getBeginLoc(),
 CastExpr->getLParenLoc());
  } else {
// however Clang spells "unreachable"
  }
}
```
Besides saving some reader-brain-cells, this also makes it clearer that there's 
a potential null dereference in the old code (if both `dyn_cast`s fail) that 
we're hoping is unreachable. This way, we have a place we can annotate that 
with `assert(false)` or whatever, instead of just dereferencing null.


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

https://reviews.llvm.org/D114427

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


[PATCH] D114718: [analyzer] Implement a new checker for Strict Aliasing Rule.

2021-11-29 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: rsmith, martong, NoQ, vsavchenko, steakhal, 
aaron.ballman, xazax.hun, Szelethus.
ASDenysPetrov added a project: clang.
Herald added subscribers: manas, jeroen.dobbelaere, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, mgorny.
ASDenysPetrov requested review of this revision.
Herald added a subscriber: cfe-commits.

`StrictAliasingChecker` implements checks on violation of the next paragraph of 
the Standard which is known as **Strict Aliasing Rule**. It operates on 
variable loads and stores. The checker compares the original type of the value 
with the type of the pointer with which the value is aliased.
The paragraph:

> C++20 7.2.1 p11 [basic.lval]:
>  If a program attempts to access the stored value of an object through a 
> glvalue whose type is not similar to one of the following types the behavior 
> is undefined:
>
> - the dynamic type of the object,
> - a type that is the signed or unsigned type corresponding to the dynamic 
> type of the object, or
> - a char, unsigned char, or std​::​byte type.

Example:

  int x = 42;
  auto c = *((char*)&x); // The original type is `int`. The aliased type is 
`char`. OK. 
  auto f = *((float*)&x); // The original type is `int`. The aliased type is 
`float`. UB. 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114718

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/StrictAliasingChecker.cpp
  clang/test/Analysis/Checkers/StrictAliasingChecker/strict-aliasing.cpp

Index: clang/test/Analysis/Checkers/StrictAliasingChecker/strict-aliasing.cpp
===
--- /dev/null
+++ clang/test/Analysis/Checkers/StrictAliasingChecker/strict-aliasing.cpp
@@ -0,0 +1,160 @@
+// RUN: %clang_cc1 -analyze -analyzer-config eagerly-assume=false -analyzer-checker=debug.ExprInspection,alpha.core.StrictAliasing -verify %s
+
+template 
+void clang_analyzer_dump(T x);
+void clang_analyzer_eval(int);
+
+namespace std {
+enum class byte : unsigned char {};
+enum class otherByte : unsigned char {};
+}; // namespace std
+enum class intEnum : int {};
+
+class Class {};
+class ClassInt {
+  int x;
+};
+
+using AliasedStdByte = std::byte;
+using AliasedChar = char;
+using AliasedSChar = signed char;
+using AliasedInt = int;
+using AliasedUInt = unsigned int;
+using AliasedULong = unsigned long;
+
+namespace ns1 {
+
+void var_cast() {
+  using MyInt = int;
+  MyInt x = {};
+  {
+auto *ptr = (std::byte *)&x;
+auto y = *ptr; // no-warning
+  }
+  {
+auto *ptr = (std::otherByte *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (intEnum *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (Class *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (ClassInt *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (char *)&x;
+auto y = *ptr; // no-warning
+  }
+  {
+auto *ptr = (unsigned char *)&x;
+auto y = *ptr; // no-warning
+  }
+  {
+auto *ptr = (const char *)&x;
+auto y = *ptr; // no-warning
+  }
+  {
+auto *ptr = (const unsigned char *)&x;
+auto y = *ptr; // no-warning
+  }
+  {
+auto *ptr = (signed char *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (short *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (unsigned short *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (signed short *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (int *)&x;
+auto y = *ptr; // no-warning
+  }
+  {
+auto *ptr = (unsigned int *)&x;
+auto y = *ptr; // no-warning
+  }
+  {
+auto *ptr = (signed int *)&x;
+auto y = *ptr; // no-warning
+  }
+  {
+auto *ptr = (long *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (unsigned long *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (signed long *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (long long *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (unsigned long long *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (signed long long *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (float *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (double *)&x;
+auto y = *ptr; // expected-warning{{Undefined behavior}}
+  }
+  {
+auto *ptr = (long double *)&x;
+

[PATCH] D114718: [analyzer] Implement a new checker for Strict Aliasing Rule.

2021-11-29 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@rsmith, @aaron.ballman I kindly invite you to join the review process 
especially in a part of the Standard interpretation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114718

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-29 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 390394.
carlosgalvezp added a comment.

Move logic into single functions.


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

https://reviews.llvm.org/D114427

Files:
  clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp

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
@@ -143,11 +143,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant cast to the same type
   // CHECK-FIXES: {{^}}  kZero;
 
-  int b2 = int(b);
-  int b3 = static_cast(b);
-  int b4 = b;
+  int b2 = static_cast(b);
+  int b3 = b;
   double aa = a;
-  (void)b2;
+  (void)aa;
   return (void)g();
 }
 
@@ -321,3 +320,50 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use constructor call syntax [
   // CHECK-FIXES: auto s6 = S(cr);
 }
+
+template 
+T functional_cast_template_used_by_class(float i) {
+  return T(i);
+}
+
+template 
+T functional_cast_template_used_by_int(float i) {
+  return T(i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; use static_cast
+  // CHECK-FIXES: return static_cast(i);
+}
+
+struct S2 {
+  S2(float);
+};
+using T = S2;
+using U = S2 &;
+
+void functional_casts() {
+  float x = 1.5F;
+  auto y = int(x);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: C-style casts are discouraged; use static_cast
+  // CHECK-FIXES: auto y = static_cast(x);
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wc++11-narrowing"
+  // This if fine, compiler will warn about implicit conversions with brace initialization
+  auto z = int{x};
+#pragma clang diagnostic pop
+
+  // Functional casts are allowed if S is of class type
+  const char *str = "foo";
+  auto s = S(str);
+
+  // Functional casts in template functions
+  functional_cast_template_used_by_class(x);
+  functional_cast_template_used_by_int(x);
+
+  // New expressions are not functional casts
+  auto w = new int(x);
+
+  // Typedefs
+  S2 t = T(x); // OK, constructor call
+  S2 u = U(x); // NOK, it's a reinterpret_cast in disguise
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -133,9 +133,11 @@
 Changes in existing checks
 ^^
 
-- Removed default setting `cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors = "true"`,
+- Removed default setting ``cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors = "true"``,
   to match the current state of the C++ Core Guidelines.
 
+- Updated ``google-readability-casting`` to diagnose and fix functional casts, to achieve feature
+  parity with the corresponding ``cpplint.py`` check.
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -31,6 +31,11 @@
   unless(isInTemplateInstantiation()))
   .bind("cast"),
   this);
+  Finder->addMatcher(
+  cxxFunctionalCastExpr(unless(hasDescendant(cxxConstructExpr())),
+unless(hasDescendant(initListExpr(
+  .bind("cast"),
+  this);
 }
 
 static bool needsConstCast(QualType SourceType, QualType DestType) {
@@ -55,8 +60,39 @@
   return T1.getUnqualifiedType() == T2.getUnqualifiedType();
 }
 
+static clang::CharSourceRange getReplaceRange(const ExplicitCastExpr *Expr) {
+  if (const auto *CastExpr = dyn_cast(Expr)) {
+return CharSourceRange::getCharRange(
+CastExpr->getLParenLoc(),
+CastExpr->getSubExprAsWritten()->getBeginLoc());
+  } else if (const auto *CastExpr = dyn_cast(Expr)) {
+return CharSourceRange::getCharRange(CastExpr->getBeginLoc(),
+ CastExpr->getLParenLoc());
+  } else
+llvm_unreachable("Unsupported CastExpr");
+}
+
+static StringRef getDestTypeString(const SourceManager &SM,
+   const LangOptions &LangOpts,
+   const ExplicitCastExpr *Expr) {
+  SourceLocation BeginLoc;
+  SourceLocation EndLoc;
+
+  if (const auto *CastExpr = dyn_cast(Expr)) {
+BeginLoc = CastExpr->getLParenLoc().getLocWithOffset(1);
+EndLoc = CastExpr->getRParenLoc().getLocWithOffset(-1);
+  } else if (const aut

[PATCH] D114721: [clang][dataflow] Add unit tests for PostOrderCFGView

2021-11-29 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev created this revision.
sgatev added reviewers: ymandel, xazax.hun, gribozavr2.
Herald added subscribers: rnkovacs, mgorny.
sgatev requested review of this revision.
Herald added a project: clang.

This adds unit tests for the PostOrderCFGView class which will be
used as part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114721

Files:
  clang/unittests/Analysis/Analyses/CMakeLists.txt
  clang/unittests/Analysis/Analyses/PostOrderCFGViewTest.cpp
  clang/unittests/Analysis/CMakeLists.txt

Index: clang/unittests/Analysis/CMakeLists.txt
===
--- clang/unittests/Analysis/CMakeLists.txt
+++ clang/unittests/Analysis/CMakeLists.txt
@@ -28,3 +28,5 @@
   PRIVATE
   LLVMTestingSupport
   )
+
+add_subdirectory(Analyses)
Index: clang/unittests/Analysis/Analyses/PostOrderCFGViewTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/Analyses/PostOrderCFGViewTest.cpp
@@ -0,0 +1,384 @@
+//===- unittests/Analysis/Analyses/PostOrderCFGViewTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/Analyses/PostOrderCFGView.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace analysis {
+namespace analyses {
+namespace {
+
+using ::testing::ElementsAre;
+using ::testing::NotNull;
+
+class PostOrderBlockIDMatchCallback
+: public ast_matchers::MatchFinder::MatchCallback {
+public:
+  const std::vector &getPostOrderBlockIDs() const {
+return PostOrderBlockIDs;
+  }
+
+  void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
+const auto *Func = Result.Nodes.getNodeAs("func");
+ASSERT_THAT(Func, NotNull());
+
+Stmt *Body = Func->getBody();
+ASSERT_THAT(Body, NotNull());
+
+CFG::BuildOptions Options;
+Options.AddImplicitDtors = true;
+Options.AddTemporaryDtors = true;
+Options.setAllAlwaysAdd();
+
+std::unique_ptr Cfg =
+CFG::buildCFG(nullptr, Body, Result.Context, Options);
+ASSERT_THAT(Cfg, NotNull());
+
+PostOrderCFGView POV(Cfg.get());
+std::priority_queue,
+PostOrderCFGView::BlockOrderCompare>
+BlocksQueue(POV.getComparator());
+for (const CFGBlock *Block : *Cfg)
+  BlocksQueue.push(Block);
+
+while (!BlocksQueue.empty()) {
+  PostOrderBlockIDs.push_back(BlocksQueue.top()->getBlockID());
+  BlocksQueue.pop();
+}
+  }
+
+private:
+  std::vector PostOrderBlockIDs;
+};
+
+template 
+void expectPostOrderBlockIDs(const char *Code, T MatchesPostOrderBlockIDs) {
+  std::unique_ptr AST =
+  tooling::buildASTFromCodeWithArgs(Code, {"-std=c++11"});
+  ASSERT_THAT(AST, NotNull());
+
+  PostOrderBlockIDMatchCallback Callback;
+  ast_matchers::MatchFinder Finder;
+  Finder.addMatcher(
+  ast_matchers::functionDecl(ast_matchers::hasName("target")).bind("func"),
+  &Callback);
+  Finder.matchAST(AST->getASTContext());
+
+  EXPECT_THAT(Callback.getPostOrderBlockIDs(), MatchesPostOrderBlockIDs);
+}
+
+TEST(PostOrderCFGViewTest, EmptyFunc) {
+  expectPostOrderBlockIDs(R"(
+// B1 (succs: B0)
+void target() {
+}
+// B0
+  )",
+  ElementsAre(0, 1));
+}
+
+TEST(PostOrderCFGViewTest, IfStmt) {
+  expectPostOrderBlockIDs(R"(
+bool foo();
+
+// B5 (succs: B4)
+void target() {
+  // B4 (succs: B3, B2)
+  foo();
+  if (foo()) {
+// B3 (succs: B1)
+foo();
+  } else {
+// B2 (succs: B1)
+foo();
+  }
+  // B1 (succs: B0)
+  foo();
+}
+// B0
+  )",
+  ElementsAre(0, 1, 3, 2, 4, 5));
+}
+
+TEST(PostOrderCFGViewTest, IfStmtLogicalAnd) {
+  expectPostOrderBlockIDs(R"(
+bool foo();
+
+// B6 (succs: B5)
+void target() {
+  // B5 (succs: B4, B2)
+  foo();
+  if (foo() && /*B4 (succs: B3, B2)*/ foo()) {
+// B3 (succs: B1)
+foo();
+  } else {
+// B2 (succs: B1)
+foo();
+  }
+  // B1 (succs: B0)
+  foo();
+}
+// B0
+  )",
+  ElementsAre(0, 1, 3, 2, 4, 5, 6));
+}
+
+TEST(PostOrderCFGViewTest, IfStmtLogicalOr) {
+  expectPostOrderBlockIDs(R"(
+bool foo();
+
+// B6 (succs: B5)
+void target() {
+  // B5 (succs: B3, B4)
+  foo();
+  if (f

[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2021-11-29 Thread Vaibhav Yenamandra via Phabricator via cfe-commits
vaibhav.y updated this revision to Diff 390396.
vaibhav.y marked 6 inline comments as done.
vaibhav.y added a comment.

Rebase on upstream/main:

- [clangBasic] Format code
- [clangBasic] Mark all constructors taking single values `explicit`
- [clangBasic] Convert `StringRef` to `std::string` fields that own the data
- [clangBasic] Fixup outdated comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109701

Files:
  clang/include/clang/Basic/Sarif.h
  clang/include/clang/Basic/SourceLocation.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Sarif.cpp
  clang/lib/Basic/SourceLocation.cpp
  clang/unittests/Basic/CMakeLists.txt
  clang/unittests/Basic/SarifTest.cpp

Index: clang/unittests/Basic/SarifTest.cpp
===
--- /dev/null
+++ clang/unittests/Basic/SarifTest.cpp
@@ -0,0 +1,138 @@
+//===- unittests/Basic/SarifTest.cpp - Test writing SARIF documents ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Sarif.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+#include 
+
+#include "gmock/gmock.h"
+#include "gtest/gtest-death-test.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace llvm;
+
+namespace {
+
+TEST(SarifDocumentWriterTest, createEmptyDocument) {
+  // GIVEN:
+  SarifDocumentWriter writer;
+
+  // WHEN:
+  const json::Object &emptyDocument = writer.createDocument();
+  std::vector keys(emptyDocument.size());
+  std::transform(emptyDocument.begin(), emptyDocument.end(), keys.begin(),
+ [](auto item) { return item.getFirst(); });
+
+  // THEN:
+  ASSERT_THAT(keys, testing::UnorderedElementsAre("$schema", "version"));
+}
+
+// Test that a newly inserted run will associate correct tool names
+TEST(SarifDocumentWriterTest, documentWithARun) {
+  // GIVEN:
+  SarifDocumentWriter writer;
+  const char *shortName = "sariftest";
+  const char *longName = "sarif writer test";
+
+  // WHEN:
+  writer.createRun(shortName, longName);
+  writer.endRun();
+  const json::Object &document = writer.createDocument();
+  const json::Array *runs = document.getArray("runs");
+
+  // THEN:
+  // A run was created
+  ASSERT_THAT(runs, testing::NotNull());
+
+  // It is the only run
+  ASSERT_EQ(runs->size(), 1UL);
+
+  // The tool associated with the run was the tool
+  const json::Object *driver =
+  runs->begin()->getAsObject()->getObject("tool")->getObject("driver");
+  ASSERT_THAT(driver, testing::NotNull());
+
+  ASSERT_TRUE(driver->getString("name").hasValue());
+  ASSERT_TRUE(driver->getString("fullName").hasValue());
+  ASSERT_TRUE(driver->getString("language").hasValue());
+
+  EXPECT_EQ(driver->getString("name").getValue(), shortName);
+  EXPECT_EQ(driver->getString("fullName").getValue(), longName);
+  EXPECT_EQ(driver->getString("language").getValue(), "en-US");
+}
+
+// Test adding result without a run causes a crash
+TEST(SarifDocumentWriterTest, addingResultsWillCrashIfThereIsNoRun) {
+  // GIVEN:
+  SarifDocumentWriter writer;
+
+  // WHEN:
+  //  A SarifDocumentWriter::createRun(...) was not called prior to
+  //  SarifDocumentWriter::appendResult(...)
+  // But a rule exists
+  auto ruleIdx = writer.createRule(SarifRule::create());
+  SarifResult &&emptyResult = SarifResult::create(ruleIdx);
+
+  // THEN:
+  ASSERT_DEATH({ writer.appendResult(emptyResult); }, ".*create a run first.*");
+}
+
+// Test adding rule and result shows up in the final document
+TEST(SarifDocumentWriterTest, addResultWithValidRuleIsOk) {
+  // GIVEN:
+  SarifDocumentWriter writer;
+  const SarifRule &rule =
+  SarifRule::create()
+  .setRuleId("clang.unittest")
+  .setDescription("Example rule created during unit tests")
+  .setName("clang unit test");
+
+  // WHEN:
+  writer.createRun("sarif test", "sarif test runner");
+  unsigned ruleIdx = writer.createRule(rule);
+  const SarifResult &result = SarifResult::create(ruleIdx);
+
+  writer.appendResult(result);
+  const json::Object &document = writer.createDocument();
+
+  // THEN:
+  // A document with a valid schema and version exists
+  ASSERT_THAT(document.get("$schema"), ::testing::NotNull());
+  ASSERT_THAT(document.get("version"), ::testing::NotNull());
+  const json::Array *runs = document.getArray("runs");
+
+  // A run exists on this document
+  ASSERT_THAT(runs, ::testing::NotNull());
+  ASSERT_EQ(runs->size(), 1UL);
+  const json::Object *theRun = runs->back().getAsObject();
+
+  // The run has slots for tools, results, rules and artifacts
+  ASSERT_THAT(theRun->get("tool"), ::testing::NotNull());
+  ASSERT_THAT(theRun->get("results"), ::testing::NotNull());

[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2021-11-29 Thread Vaibhav Yenamandra via Phabricator via cfe-commits
vaibhav.y added inline comments.



Comment at: clang/include/clang/Basic/Sarif.h:80-82
+  static SarifArtifactLocation create(StringRef URI) {
+return SarifArtifactLocation{URI};
+  }

aaron.ballman wrote:
> One thing that's worth calling out is that `StringRef` is non-owning which 
> means that the argument passed to create the `SarifArtifactLocation` has to 
> outlive the returned object to avoid dangling references. This makes the 
> class a bit more dangerous to use because `Twine` or automatic `std::string` 
> objects may cause lifetime concerns.
> 
> Should these classes be storing a `std::string` so that the memory is owned 
> by SARIF?
Good point! Will change it to `std::string` to start with.

Some fields such as MimeType, RuleID would probably do better with 
`SmallString`, I haven't been able to find any good measurements on how the 
lengths of those two are distributed, can it be made into `SmallString` in a 
future PR?



Comment at: clang/include/clang/Basic/Sarif.h:116
+  static SarifArtifact create(const SarifArtifactLocation &Loc) {
+return SarifArtifactLocation{Loc};
+  }

aaron.ballman wrote:
> `Loc` is already a `SarifArtifactLocation`, did you mean `SarifArtifact` by 
> any chance?
> 
> (Note, this suggests to me we should mark the ctor's here as `explicit`.)
Agree, I've marked all constructors taking a single parameter as explicit.



Comment at: clang/include/clang/Basic/Sarif.h:243-245
+  // While this cannot be negative, since this type needs to be serialized
+  // to JSON, it needs to be `int64_t`. The best we can do is assert that
+  // a negative value isn't used to create it

aaron.ballman wrote:
> This comment looks incorrect to me.
Ack, fixed that as well. the right rationale for `uint32_t` is that it is the 
largest non-negative type that can be safely promoted to `int64_t` (which is 
what LLVM's json encoder supports)



Comment at: clang/include/clang/Basic/SourceLocation.h:441-456
+bool operator()(const FullSourceLoc &lhs, const FullSourceLoc &rhs) const {
   return lhs.isBeforeInTranslationUnitThan(rhs);
 }
   };
 
   /// Prints information about this FullSourceLoc to stderr.
   ///

aaron.ballman wrote:
> Looks like unrelated formatting changes; feel free to submit these as an NFC 
> change if you'd like, but the changes should be reverted from this patch for 
> clarity.
Ack, these are definitely a result of a bad rebase. 



Comment at: clang/lib/Basic/Sarif.cpp:199
+const SarifArtifactLocation &Location =
+SarifArtifactLocation::create(FileURI).setIndex(Idx);
+const SarifArtifact &Artifact = SarifArtifact::create(Location)

aaron.ballman wrote:
> This seems like it'll be a use-after-free because the local `std::string` 
> will be destroyed before the lifetime of the `SarifArtifactLocation` ends.
Will run it through a pass of asan & msan, is the best way to add: 
`-fsanitize=memory -fsanitize=address` to the test CMakeLists.txt & run them?

I've changed all strings to `std::string`, so this one should no longer be a 
problem but I wonder if there's any others I have missed as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109701

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


[PATCH] D114622: [clang-tidy][analyzer] Fix false-positive in IdenticalExprChecker and misc-redundant-expression

2021-11-29 Thread David Rector via Phabricator via cfe-commits
davrec added a comment.

A couple thoughts/cases to consider...




Comment at: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:52
 
 static bool areEquivalentNameSpecifier(const NestedNameSpecifier *Left,
const NestedNameSpecifier *Right) {

This function should probably either be made into a lambda private to 
`areEquivalentDeclRefs()`, or renamed to make clear it does not apply 
generically to all NNS's.  

Part of the reason is that this is only implemented for type NNS's.  But the 
more important reason is that, when either a) `!Left || !Right`, or b) 
`!Left->getAsType() || !Right->getAsType()`, this returns true, since 
(presumably*) this gives us the desired behavior within 
areEquivalentDeclRefs(), despite that in general a null NNS should probably not 
be considered the same as a nonnull NNS.  

(*Is this indeed the desired behavior? Probably should add some tests that 
check qualified DeclRefExprs against unqualified DeclRefExprs, to be sure.)



Comment at: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:53
 static bool areEquivalentNameSpecifier(const NestedNameSpecifier *Left,
const NestedNameSpecifier *Right) {
+  const Type *LTy = Left->getAsType();

Suggest you move the null check from `areEquivalentDeclRefs()` here, i.e.
```
if (!Left || !Right)
  return true;
```
mainly since this is needs to be done in recursive calls (see below), but also 
since you do the same logic on LTy and RTy subsequently.





Comment at: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:59
+   RTy->getCanonicalTypeUnqualified();
+
+  // FIXME: We should probably check the other kinds of nested name specifiers.

It occurs to me this needs to be recursive, to check a sequence of qualifiers, 
i.e.
```
  const Type *LTy = Left->getAsType();
  const Type *RTy = Right->getAsType();
  if (!LTy || !RTy) 
return true;
  if (LTy->getCanonicalTypeUnqualified() !=
   RTy->getCanonicalTypeUnqualified())
return false;
  return areEquivalentNameSpecifier(Left->getPrefix(), Right->getPrefix());
```

The reason is, if there is a prefix qualifier to this qualifier, we run into 
the original problem, e.g.:
```
struct Base {
  struct Inner { 
static const bool value = true;
  };
};
struct Outer1 : Base {};
struct Outer2 : Base {};

// We do not want the following to warn, but without checking the prefix of 
Inner, 
// I believe these will be interpreted as equivalent DeclRefs and will warn:
auto sink = Outer1::Inner::value || Outer2::Inner::value;
```




Comment at: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:72
+  // The decls were already matched, so just return true at any later point.
+  if (!Left->hasQualifier() || !Right->hasQualifier())
+return true;

Suggest you move this null check into areEquivalentNameSpecifier, see above


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

https://reviews.llvm.org/D114622

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


[PATCH] D114651: [clang-cl] Expose -Wall to clang-cl by unaliasing -Wall, keeping /Wall as alias to -Weverything

2021-11-29 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I will add that multiple users have run into this problem, and I think it might 
be more practical to consider unaliasing Wall altogether. Clang doesn't emit 
the same set of warnings as MSVC. Anyone seriously using `clang-cl /Wall` is 
going to receive a pile of `-WcxxNN-compat` warnings that are 
self-contradictory, and they are going to need to curate a set of 
clang-specific warning flags anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114651

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


[PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2021-11-29 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added inline comments.



Comment at: clang/docs/UsersManual.rst:3546
 
-cmake -G"Visual Studio 15 2017" -T LLVM ..
+cmake -G"Visual Studio 17 2022" -T LLVM ..
 

jhenderson wrote:
> RKSimon wrote:
> > aaron.ballman wrote:
> > > jhenderson wrote:
> > > > I think the missing space should be fixed to :)
> > > +1 to the missing space.
> > This one is confusing - it isn't in my local diff, the raw diff, or if I 
> > reapply the raw diff - it looks to have just appeared when you quote it in 
> > phab comments?
> The fact that the space is missing? It's missing in the current repo too.
It works with and without the space, like `-GNinja` and `-G Ninja` both work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

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


[PATCH] D114721: [clang][dataflow] Add unit tests for PostOrderCFGView

2021-11-29 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Looks good, but why split the test into its own directory? I see that the 
implementation file is in clang/lib/Analysis and, in general, the lib and 
unittest directories are often flatter than the corresponding include 
directories. Maybe just put it directly into unittests/Analysis?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114721

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


  1   2   >