[clang] ffe7950 - Reland "[analyzer] Deprecate `-analyzer-store region` flag"

2022-06-14 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2022-06-14T09:20:41+02:00
New Revision: ffe7950ebc62380c3afc7c71f454a1db3f6f5c76

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

LOG: Reland "[analyzer] Deprecate `-analyzer-store region` flag"

I'm trying to remove unused options from the `Analyses.def` file, then
merge the rest of the useful options into the `AnalyzerOptions.def`.
Then make sure one can set these by an `-analyzer-config XXX=YYY` style
flag.
Then surface the `-analyzer-config` to the `clang` frontend;

After all of this, we can pursue the tablegen approach described
https://discourse.llvm.org/t/rfc-tablegen-clang-static-analyzer-engine-options-for-better-documentation/61488

In this patch, I'm proposing flag deprecations.
We should support deprecated analyzer flags for exactly one release. In
this case I'm planning to drop this flag in `clang-16`.

In the clang frontend, now we won't pass this option to the cc1
frontend, rather emit a warning diagnostic reminding the users about
this deprecated flag, which will be turned into error in clang-16.

Unfortunately, I had to remove all the tests referring to this flag,
causing a mass change. I've also added a test for checking this warning.

I've seen that `scan-build` also uses this flag, but I think we should
remove that part only after we turn this into a hard error.

Reviewed By: martong

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

Added: 
clang/test/Analysis/deprecated-flags-and-options.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Driver/Options.td
clang/include/clang/StaticAnalyzer/Core/Analyses.def
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
clang/test/Analysis/CFNumber.c
clang/test/Analysis/CFRetainRelease_NSAssertionHandler.m
clang/test/Analysis/CGColorSpace.c
clang/test/Analysis/Malloc+MismatchedDeallocator_intersections.cpp
clang/test/Analysis/NSPanel.m
clang/test/Analysis/NSString.m
clang/test/Analysis/NSWindow.m
clang/test/Analysis/OSAtomic_mac.cpp
clang/test/Analysis/PR3991.m
clang/test/Analysis/PR7218.c
clang/test/Analysis/analyzeOneFunction.m
clang/test/Analysis/array-struct.c
clang/test/Analysis/blocks.m
clang/test/Analysis/bool-assignment.c
clang/test/Analysis/bstring.cpp
clang/test/Analysis/casts.c
clang/test/Analysis/casts.cpp
clang/test/Analysis/casts.m
clang/test/Analysis/cfref_PR2519.c
clang/test/Analysis/cfref_rdar6080742.c
clang/test/Analysis/chroot.c
clang/test/Analysis/concrete-address.c
clang/test/Analysis/coverage.c
clang/test/Analysis/cstring-syntax-cxx.cpp
clang/test/Analysis/cxx-method-names.cpp
clang/test/Analysis/dead-stores.cpp
clang/test/Analysis/default-diagnostic-visitors.c
clang/test/Analysis/delegates.m
clang/test/Analysis/disable-all-checks.c
clang/test/Analysis/elementtype.c
clang/test/Analysis/fields.c
clang/test/Analysis/free.c
clang/test/Analysis/free.cpp
clang/test/Analysis/func.c
clang/test/Analysis/gmalloc.c
clang/test/Analysis/ivars.m
clang/test/Analysis/keychainAPI-diagnostic-visitor.m
clang/test/Analysis/localization-aggressive.m
clang/test/Analysis/localization.m
clang/test/Analysis/lvalue.cpp
clang/test/Analysis/malloc-annotations.c
clang/test/Analysis/malloc-annotations.cpp
clang/test/Analysis/malloc.c
clang/test/Analysis/malloc.m
clang/test/Analysis/method-call-intra-p.cpp
clang/test/Analysis/misc-ps-64.m
clang/test/Analysis/misc-ps-arm.m
clang/test/Analysis/misc-ps-eager-assume.m
clang/test/Analysis/misc-ps-ranges.m
clang/test/Analysis/misc-ps-region-store-i386.m
clang/test/Analysis/misc-ps-region-store-x86_64.m
clang/test/Analysis/misc-ps-region-store.cpp
clang/test/Analysis/misc-ps-region-store.m
clang/test/Analysis/misc-ps-region-store.mm
clang/test/Analysis/misc-ps.m
clang/test/Analysis/new-with-exceptions.cpp
clang/test/Analysis/new.cpp
clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret-region.m
clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
clang/test/Analysis/no-exit-cfg.c
clang/test/Analysis/no-outofbounds.c
clang/test/Analysis/null-deref-path-notes.m
clang/test/Analysis/null-deref-ps.c
clang/test/Analysis/nullptr.cpp
clang/test/Analysis/objc-boxing.m
clang/test/Analysis/objc-message.m
clang/test/Analysis/objc-subscript.m
clang/test/Analysis/outofbound-notwork.c
clang/test/Analysis/outofbound.c
clang/test/Analysis/override-werror.c
clan

[PATCH] D126215: [analyzer] Deprecate `-analyzer-store region` flag

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGffe7950ebc62: Reland "[analyzer] Deprecate 
`-analyzer-store region` flag" (authored by steakhal).

Changed prior to commit:
  https://reviews.llvm.org/D126215?vs=436124&id=436677#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126215

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/StaticAnalyzer/Core/Analyses.def
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  clang/test/Analysis/CFNumber.c
  clang/test/Analysis/CFRetainRelease_NSAssertionHandler.m
  clang/test/Analysis/CGColorSpace.c
  clang/test/Analysis/Malloc+MismatchedDeallocator_intersections.cpp
  clang/test/Analysis/NSPanel.m
  clang/test/Analysis/NSString.m
  clang/test/Analysis/NSWindow.m
  clang/test/Analysis/OSAtomic_mac.cpp
  clang/test/Analysis/PR3991.m
  clang/test/Analysis/PR7218.c
  clang/test/Analysis/analyzeOneFunction.m
  clang/test/Analysis/array-struct.c
  clang/test/Analysis/blocks.m
  clang/test/Analysis/bool-assignment.c
  clang/test/Analysis/bstring.cpp
  clang/test/Analysis/casts.c
  clang/test/Analysis/casts.cpp
  clang/test/Analysis/casts.m
  clang/test/Analysis/cfref_PR2519.c
  clang/test/Analysis/cfref_rdar6080742.c
  clang/test/Analysis/chroot.c
  clang/test/Analysis/concrete-address.c
  clang/test/Analysis/coverage.c
  clang/test/Analysis/cstring-syntax-cxx.cpp
  clang/test/Analysis/cxx-method-names.cpp
  clang/test/Analysis/dead-stores.cpp
  clang/test/Analysis/default-diagnostic-visitors.c
  clang/test/Analysis/delegates.m
  clang/test/Analysis/deprecated-flags-and-options.cpp
  clang/test/Analysis/disable-all-checks.c
  clang/test/Analysis/elementtype.c
  clang/test/Analysis/fields.c
  clang/test/Analysis/free.c
  clang/test/Analysis/free.cpp
  clang/test/Analysis/func.c
  clang/test/Analysis/gmalloc.c
  clang/test/Analysis/ivars.m
  clang/test/Analysis/keychainAPI-diagnostic-visitor.m
  clang/test/Analysis/localization-aggressive.m
  clang/test/Analysis/localization.m
  clang/test/Analysis/lvalue.cpp
  clang/test/Analysis/malloc-annotations.c
  clang/test/Analysis/malloc-annotations.cpp
  clang/test/Analysis/malloc.c
  clang/test/Analysis/malloc.m
  clang/test/Analysis/method-call-intra-p.cpp
  clang/test/Analysis/misc-ps-64.m
  clang/test/Analysis/misc-ps-arm.m
  clang/test/Analysis/misc-ps-eager-assume.m
  clang/test/Analysis/misc-ps-ranges.m
  clang/test/Analysis/misc-ps-region-store-i386.m
  clang/test/Analysis/misc-ps-region-store-x86_64.m
  clang/test/Analysis/misc-ps-region-store.cpp
  clang/test/Analysis/misc-ps-region-store.m
  clang/test/Analysis/misc-ps-region-store.mm
  clang/test/Analysis/misc-ps.m
  clang/test/Analysis/new-with-exceptions.cpp
  clang/test/Analysis/new.cpp
  clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret-region.m
  clang/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
  clang/test/Analysis/no-exit-cfg.c
  clang/test/Analysis/no-outofbounds.c
  clang/test/Analysis/null-deref-path-notes.m
  clang/test/Analysis/null-deref-ps.c
  clang/test/Analysis/nullptr.cpp
  clang/test/Analysis/objc-boxing.m
  clang/test/Analysis/objc-message.m
  clang/test/Analysis/objc-subscript.m
  clang/test/Analysis/outofbound-notwork.c
  clang/test/Analysis/outofbound.c
  clang/test/Analysis/override-werror.c
  clang/test/Analysis/pr22954.c
  clang/test/Analysis/pr4209.m
  clang/test/Analysis/pr_2542_rdar_6793404.m
  clang/test/Analysis/pr_4164.c
  clang/test/Analysis/properties.m
  clang/test/Analysis/properties.mm
  clang/test/Analysis/ptr-arith.c
  clang/test/Analysis/qt_malloc.cpp
  clang/test/Analysis/range_casts.c
  clang/test/Analysis/rdar-6442306-1.m
  clang/test/Analysis/rdar-6541136-region.c
  clang/test/Analysis/rdar-6562655.m
  clang/test/Analysis/rdar-6600344-nil-receiver-undefined-struct-ret.m
  clang/test/Analysis/rdar-7168531.m
  clang/test/Analysis/refcnt_naming.m
  clang/test/Analysis/reference.cpp
  clang/test/Analysis/region-1.m
  clang/test/Analysis/retain-release-path-notes.m
  clang/test/Analysis/retain-release-region-store.m
  clang/test/Analysis/retain-release.mm
  clang/test/Analysis/stack-addr-ps.c
  clang/test/Analysis/stack-addr-ps.cpp
  clang/test/Analysis/stack-block-returned.cpp
  clang/test/Analysis/string-fail.c
  clang/test/Analysis/undef-buffers.c
  clang/test/Analysis/uninit-ps-rdar6145427.m
  clang/test/Analysis/uninit-vals-union.c
  clang/test/Analysis/uninit-vals.m
  clang/test/Analysis/unions-region.m
  clang/test/Analysis/u

[PATCH] D127403: [clangd] Implement semantic token modifier "definition"

2022-06-14 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler updated this revision to Diff 436678.
ckandeler added a comment.

Objective-C improvements.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127403

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/test/initialize-params.test
  clang-tools-extra/clangd/test/semantic-tokens.test
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/AnnotateHighlightingsTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/AnnotateHighlightingsTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/AnnotateHighlightingsTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/AnnotateHighlightingsTests.cpp
@@ -18,18 +18,18 @@
 TEST_F(AnnotateHighlightingsTest, Test) {
   EXPECT_AVAILABLE("^vo^id^ ^f(^) {^}^"); // available everywhere.
   EXPECT_AVAILABLE("[[int a; int b;]]");
-  EXPECT_EQ("void /* Function [decl] [globalScope] */f() {}",
+  EXPECT_EQ("void /* Function [decl] [def] [globalScope] */f() {}",
 apply("void ^f() {}"));
 
   EXPECT_EQ(apply("[[int f1(); const int x = f1();]]"),
 "int /* Function [decl] [globalScope] */f1(); "
-"const int /* Variable [decl] [readonly] [fileScope] */x = "
+"const int /* Variable [decl] [def] [readonly] [fileScope] */x = "
 "/* Function [globalScope] */f1();");
 
   // Only the targeted range is annotated.
   EXPECT_EQ(apply("void f1(); void f2() {^}"),
 "void f1(); "
-"void /* Function [decl] [globalScope] */f2() {}");
+"void /* Function [decl] [def] [globalScope] */f2() {}");
 }
 
 } // namespace
Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -97,52 +97,52 @@
 TEST(SemanticHighlighting, GetsCorrectTokens) {
   const char *TestCases[] = {
   R"cpp(
-  struct $Class_decl[[AS]] {
+  struct $Class_decl_def[[AS]] {
 double $Field_decl[[SomeMember]];
   };
   struct {
-  } $Variable_decl[[S]];
-  void $Function_decl[[foo]](int $Parameter_decl[[A]], $Class[[AS]] $Parameter_decl[[As]]) {
-$Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_decl[[VeryLongVariableName]] = 12312;
-$Class[[AS]] $LocalVariable_decl[[AA]];
-$Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_decl[[L]] = $LocalVariable[[AA]].$Field[[SomeMember]] + $Parameter[[A]];
-auto $LocalVariable_decl[[FN]] = [ $LocalVariable[[AA]]](int $Parameter_decl[[A]]) -> void {};
+  } $Variable_decl_def[[S]];
+  void $Function_decl_def[[foo]](int $Parameter_decl[[A]], $Class[[AS]] $Parameter_decl[[As]]) {
+$Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_decl_def[[VeryLongVariableName]] = 12312;
+$Class[[AS]] $LocalVariable_decl_def[[AA]];
+$Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_decl_def[[L]] = $LocalVariable[[AA]].$Field[[SomeMember]] + $Parameter[[A]];
+auto $LocalVariable_decl_def[[FN]] = [ $LocalVariable[[AA]]](int $Parameter_decl[[A]]) -> void {};
 $LocalVariable[[FN]](12312);
   }
 )cpp",
   R"cpp(
   void $Function_decl[[foo]](int);
   void $Function_decl[[Gah]]();
-  void $Function_decl[[foo]]() {
-auto $LocalVariable_decl[[Bou]] = $Function[[Gah]];
+  void $Function_decl_def[[foo]]() {
+auto $LocalVariable_decl_def[[Bou]] = $Function[[Gah]];
   }
-  struct $Class_decl[[A]] {
+  struct $Class_decl_def[[A]] {
 void $Method_decl[[abc]]();
   };
 )cpp",
   R"cpp(
   namespace $Namespace_decl[[abc]] {
 template
-struct $Class_decl[[A]] {
+struct $Class_decl_def[[A]] {
   $TemplateParameter[[T]] $Field_decl[[t]];
 };
   }
   template
-  struct $Class_decl[[C]] : $Namespace[[abc]]::$Class[[A]]<$TemplateParameter[[T]]> {
+  struct $Class_decl_def[[C]] : $Namespace[[abc]]::$Class[[A]]<$TemplateParameter[[T]]> {
 typename $TemplateParameter[[T]]::$Type_dependentName[[A]]* $Field_decl[[D]];
   };
-  $Namespace[[abc]]::$Class[[A]] $Variable_decl[[AA]];
+  $Namespace[[abc]]::$Class[[A]] $Variable_decl_def[[AA]];
   typedef $Namespace[[abc]]::$Class[[A]] $Class_decl[[AAA]];
-  struct $Class_decl[[B]] {
+  struct $Class_decl_def[[B]] {
 $Class_decl[[B]]();
 ~$Class[[B]](); // FIXME: inconsistent with constructor
 void operator<<($Class[[B]]);
 $Class[[AAA]] $Field_decl[[AA]];
   };
-  $Class[[B]]::$Class_decl[[B]]() {}
+  $Class[[B]]::$Class_decl_d

[PATCH] D127599: [clang] small speed improvement of Sema::AddArgumentDependentLookupCandidates

2022-06-14 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

The context of the diff is missing. Please re-run the diff making with 
`-U999`.




Comment at: clang/include/clang/Sema/Lookup.h:817
+  bool empty(void) { return Decls.empty(); }
+
   using iterator =

`(void)`? LLVM is a C++ project.


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

https://reviews.llvm.org/D127599

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


[PATCH] D127649: [analyzer][NFC][test] Add new RUN line with support-symbolic-integer-casts=true to expr-inspection.cpp

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/test/Analysis/expr-inspection.cpp:11-13
 void clang_analyzer_denote(int x, const char *str);
+void clang_analyzer_denote(unsigned x, const char *str);
 void clang_analyzer_express(int x);




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127649

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


[PATCH] D127646: [analyzer][NFC][test] Add new RUN lint with support-symbolic-integer-casts=true to svalbuilder-rearrange-comparisons.c

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/Analysis/svalbuilder-rearrange-comparisons.cpp:16-17
+
+template 
+void clang_analyzer_eval(T x);
+template 




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127646

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


[clang] 24bd47d - [analyzer][NFC] Inline AnalyzerOptions::getUserMode()

2022-06-14 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2022-06-14T09:42:58+02:00
New Revision: 24bd47dc172f5dc81de7baac880c55b1e615fa70

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

LOG: [analyzer][NFC] Inline AnalyzerOptions::getUserMode()

When I read the code I found it easier to reason about if `getUserMode`
is inlined. It might be a personal preference though.

Reviewed By: martong

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index f6d36e797e0b..dcc6495b28bf 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -360,11 +360,6 @@ class AnalyzerOptions : public 
RefCountedBase {
StringRef OptionName,
bool SearchInParents = false) const;
 
-  /// Retrieves and sets the UserMode. This is a high-level option,
-  /// which is used to set other low-level options. It is not accessible
-  /// outside of AnalyzerOptions.
-  UserModeKind getUserMode() const;
-
   ExplorationStrategyKind getExplorationStrategy() const;
   CTUPhase1InliningKind getCTUPhase1Inlining() const;
 
@@ -404,15 +399,6 @@ using AnalyzerOptionsRef = 
IntrusiveRefCntPtr;
 // For this reason, implement some methods in this header file.
 
//===--===//
 
-inline UserModeKind AnalyzerOptions::getUserMode() const {
-  auto K = llvm::StringSwitch>(UserMode)
-.Case("shallow", UMK_Shallow)
-.Case("deep", UMK_Deep)
-.Default(None);
-  assert(K.hasValue() && "User mode is invalid.");
-  return K.getValue();
-}
-
 inline std::vector
 AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental) {
   static constexpr llvm::StringLiteral StaticAnalyzerCheckerNames[] = {

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index e093582e6934..deec3e81f656 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1089,25 +1089,22 @@ static void initOption(AnalyzerOptions::ConfigTable 
&Config,
 static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
  DiagnosticsEngine *Diags) {
   // TODO: There's no need to store the entire configtable, it'd be plenty
-  // enough tostore checker options.
+  // enough to store checker options.
 
 #define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)
\
   initOption(AnOpts.Config, Diags, AnOpts.NAME, CMDFLAG, DEFAULT_VAL);
+#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(...)
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
 
-#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,
\
-   SHALLOW_VAL, DEEP_VAL)  
\
-  switch (AnOpts.getUserMode()) {  
\
-  case UMK_Shallow:
\
-initOption(AnOpts.Config, Diags, AnOpts.NAME, CMDFLAG, SHALLOW_VAL);   
\
-break; 
\
-  case UMK_Deep:   
\
-initOption(AnOpts.Config, Diags, AnOpts.NAME, CMDFLAG, DEEP_VAL);  
\
-break; 
\
-  }
\
+  assert(AnOpts.UserMode == "shallow" || AnOpts.UserMode == "deep");
+  const bool InShallowMode = AnOpts.UserMode == "shallow";
 
+#define ANALYZER_OPTION(...)
+#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,
\
+ SHALLOW_VAL, DEEP_VAL)
\
+  initOption(AnOpts.Config, Diags, AnOpts.NAME, CMDFLAG,   
\
+ InShallowMode ? SHALLOW_VAL : DEEP_VAL);
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
-#undef ANALYZER_OPTION
-#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
 
   // At this point, AnalyzerOptions is configured. Let's validate some options.
 



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


[PATCH] D127486: [analyzer][NFC] Inline AnalyzerOptions::getUserMode()

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG24bd47dc172f: [analyzer][NFC] Inline 
AnalyzerOptions::getUserMode() (authored by steakhal).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127486

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1089,25 +1089,22 @@
 static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
  DiagnosticsEngine *Diags) {
   // TODO: There's no need to store the entire configtable, it'd be plenty
-  // enough tostore checker options.
+  // enough to store checker options.
 
 #define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)
\
   initOption(AnOpts.Config, Diags, AnOpts.NAME, CMDFLAG, DEFAULT_VAL);
+#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(...)
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
 
-#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,
\
-   SHALLOW_VAL, DEEP_VAL)  
\
-  switch (AnOpts.getUserMode()) {  
\
-  case UMK_Shallow:
\
-initOption(AnOpts.Config, Diags, AnOpts.NAME, CMDFLAG, SHALLOW_VAL);   
\
-break; 
\
-  case UMK_Deep:   
\
-initOption(AnOpts.Config, Diags, AnOpts.NAME, CMDFLAG, DEEP_VAL);  
\
-break; 
\
-  }
\
+  assert(AnOpts.UserMode == "shallow" || AnOpts.UserMode == "deep");
+  const bool InShallowMode = AnOpts.UserMode == "shallow";
 
+#define ANALYZER_OPTION(...)
+#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,
\
+ SHALLOW_VAL, DEEP_VAL)
\
+  initOption(AnOpts.Config, Diags, AnOpts.NAME, CMDFLAG,   
\
+ InShallowMode ? SHALLOW_VAL : DEEP_VAL);
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
-#undef ANALYZER_OPTION
-#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
 
   // At this point, AnalyzerOptions is configured. Let's validate some options.
 
Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===
--- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -360,11 +360,6 @@
StringRef OptionName,
bool SearchInParents = false) const;
 
-  /// Retrieves and sets the UserMode. This is a high-level option,
-  /// which is used to set other low-level options. It is not accessible
-  /// outside of AnalyzerOptions.
-  UserModeKind getUserMode() const;
-
   ExplorationStrategyKind getExplorationStrategy() const;
   CTUPhase1InliningKind getCTUPhase1Inlining() const;
 
@@ -404,15 +399,6 @@
 // For this reason, implement some methods in this header file.
 
//===--===//
 
-inline UserModeKind AnalyzerOptions::getUserMode() const {
-  auto K = llvm::StringSwitch>(UserMode)
-.Case("shallow", UMK_Shallow)
-.Case("deep", UMK_Deep)
-.Default(None);
-  assert(K.hasValue() && "User mode is invalid.");
-  return K.getValue();
-}
-
 inline std::vector
 AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental) {
   static constexpr llvm::StringLiteral StaticAnalyzerCheckerNames[] = {


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1089,25 +1089,22 @@
 static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
  DiagnosticsEngine *Diags) {
   // TODO: There's no need to store the entire configtable, it'd be plenty
-  // enough tostore checker options.
+  // enough to store checker options.
 
 #define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL)\
   initOption(AnOpts.Config, Diags, AnOpts.NAME, CMDFLAG, DEFAULT_VAL);
+#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(...)
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
 
-#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC,\
- 

[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-06-14 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 436682.
cor3ntin marked 12 inline comments as done.
cor3ntin added a comment.

Regenerate UnicodeNameToCodepointGenerated.cpp to fix the formatting of its
header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/Lexer.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/FixIt/fixit-unicode-named-escape-sequences.c
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Lexer/unicode.c
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/ucn-identifiers.c
  llvm/CMakeLists.txt
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/CMakeLists.txt
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-06-14 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin marked an inline comment as done.
cor3ntin added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:3237-3239
+  if (C != '{') {
+if (Diagnose)
+  Diag(StartPtr, diag::warn_ucn_escape_incomplete);

aaron.ballman wrote:
> Is this a case where we might want a fixit because the user did `\N` when 
> they meant to do `\n`?
> 
> (Should we look for `\N(` and fixit that to `\N{`?)
I think if we wanted to diagnose \n we should also diagnose \U, which we don't 
do, Maybe a follow up patch, what do you think?
I can't imagine trying to be smart about `\N(` would be exercised  by many users


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

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


[PATCH] D126291: [flang][Driver] Update link job on windows

2022-06-14 Thread Diana Picus via Phabricator via cfe-commits
rovka updated this revision to Diff 436687.
rovka added a comment.

Clarified test checks.


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

https://reviews.llvm.org/D126291

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  flang/test/Driver/linker-flags.f90

Index: flang/test/Driver/linker-flags.f90
===
--- flang/test/Driver/linker-flags.f90
+++ flang/test/Driver/linker-flags.f90
@@ -2,18 +2,13 @@
 ! invocation. These libraries are added on top of other standard runtime
 ! libraries that the Clang driver will include.
 
-! NOTE: The additional linker flags tested here are currently only specified for
-! GNU and Darwin. The following line will make sure that this test is skipped on
-! Windows. If you are running this test on a yet another platform and it is
-! failing for you, please either update the following or (preferably) update the
-! linker invocation accordingly.
-! UNSUPPORTED: system-windows
-
-!
-! RUN COMMAND
-!
-! Use `--ld-path` so that the linker location (used in the LABEL below) is deterministic.
-! RUN: %flang -### -flang-experimental-exec --ld-path=/usr/bin/ld %S/Inputs/hello.f90 2>&1 | FileCheck %s
+!-
+! RUN COMMANDS
+!-
+! RUN: %flang -### -flang-experimental-exec -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -flang-experimental-exec -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### -flang-experimental-exec -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MINGW
+! RUN: %flang -### -flang-experimental-exec -target aarch64-windows-msvc %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC
 
 !
 ! EXPECTED OUTPUT
@@ -23,9 +18,35 @@
 ! CHECK-SAME:  "-o" "[[object_file:.*\.o]]" {{.*}}Inputs/hello.f90
 
 ! Linker invocation to generate the executable
-! CHECK-LABEL:  "/usr/bin/ld"
-! CHECK-SAME: "[[object_file]]"
-! CHECK-SAME: -lFortran_main
-! CHECK-SAME: -lFortranRuntime
-! CHECK-SAME: -lFortranDecimal
-! CHECK-SAME: -lm
+! GNU-LABEL:  "{{.*}}ld" 
+! GNU-SAME: "[[object_file]]"
+! GNU-SAME: -lFortran_main
+! GNU-SAME: -lFortranRuntime
+! GNU-SAME: -lFortranDecimal
+! GNU-SAME: -lm
+
+! DARWIN-LABEL:  "{{.*}}ld" 
+! DARWIN-SAME: "[[object_file]]"
+! DARWIN-SAME: -lFortran_main
+! DARWIN-SAME: -lFortranRuntime
+! DARWIN-SAME: -lFortranDecimal
+
+! MINGW-LABEL:  "{{.*}}ld" 
+! MINGW-SAME: "[[object_file]]"
+! MINGW-SAME: -lFortran_main
+! MINGW-SAME: -lFortranRuntime
+! MINGW-SAME: -lFortranDecimal
+
+! NOTE: This check should also match if the default linker is lld-link.exe
+! MSVC-LABEL: link.exe
+! These libraries are added by clang, but are not needed when compiling
+! Fortran code, and they might bring in other dependencies.
+! MSVC-NOT: libcmt
+! MSVC-NOT: oldnames
+! MSVC-SAME: Fortran_main.lib
+! MSVC-SAME: FortranRuntime.lib
+! MSVC-SAME: FortranDecimal.lib
+! MSVC-SAME: /subsystem:console
+! MSVC-NOT: libcmt
+! MSVC-NOT: oldnames
+! MSVC-SAME: "[[object_file]]"
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -218,6 +218,11 @@
 
   AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
 
+  if (C.getDriver().IsFlangMode()) {
+addFortranRuntimeLibraryPath(TC, Args, CmdArgs);
+addFortranRuntimeLibs(TC, CmdArgs);
+  }
+
   // TODO: Add profile stuff here
 
   if (TC.ShouldLinkCXXStdlib(Args)) {
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -81,7 +81,7 @@
 Args.MakeArgString(std::string("-out:") + Output.getFilename()));
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
-  !C.getDriver().IsCLMode()) {
+  !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
 CmdArgs.push_back("-defaultlib:libcmt");
 CmdArgs.push_back("-defaultlib:oldnames");
   }
@@ -130,6 +130,16 @@
   Args.MakeArgString(std::string("-libpath:") + WindowsSdkLibPath));
   }
 
+  if (C.getDriver().IsFlangMode()) {
+addFortranRuntimeLibraryPath(TC, Args, CmdArgs);
+addFortranRuntimeLibs(TC, CmdArgs);
+
+// Inform the MSVC linker that we're generating a console application, i.e.
+// one with `main` as the "user-defined" entry point. The `main` function is
+// defined in flang's runtime libraries.
+CmdArgs.push_back("/subsystem:console");
+  }
+
   // Add the compiler-rt library directories to libpath if 

[PATCH] D127638: [clang][sema] Provide better diagnostic for missing template parameters

2022-06-14 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 436690.

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

https://reviews.llvm.org/D127638

Files:
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/test/SemaCXX/nested-name-spec.cpp


Index: clang/test/SemaCXX/nested-name-spec.cpp
===
--- clang/test/SemaCXX/nested-name-spec.cpp
+++ clang/test/SemaCXX/nested-name-spec.cpp
@@ -473,3 +473,10 @@
 x: goto x;
   }
 }
+
+template 
+struct x; // expected-note {{template is declared here}}
+
+template 
+int issue55962 = x::a; // expected-error {{use of class template 'x' requires 
template arguments}} \
+   // expected-warning {{variable templates are a C++14 
extension}}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -828,10 +828,14 @@
   }
 
   if (!Found.empty()) {
-if (TypeDecl *TD = Found.getAsSingle())
+if (TypeDecl *TD = Found.getAsSingle()) {
   Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
   << Context.getTypeDeclType(TD) << getLangOpts().CPlusPlus;
-else {
+} else if (Found.getAsSingle()) {
+  ParsedType SuggestedType;
+  DiagnoseUnknownTypeName(IdInfo.Identifier, IdInfo.IdentifierLoc, S, &SS,
+  SuggestedType);
+} else {
   Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
   << IdInfo.Identifier << getLangOpts().CPlusPlus;
   if (NamedDecl *ND = Found.getAsSingle())


Index: clang/test/SemaCXX/nested-name-spec.cpp
===
--- clang/test/SemaCXX/nested-name-spec.cpp
+++ clang/test/SemaCXX/nested-name-spec.cpp
@@ -473,3 +473,10 @@
 x: goto x;
   }
 }
+
+template 
+struct x; // expected-note {{template is declared here}}
+
+template 
+int issue55962 = x::a; // expected-error {{use of class template 'x' requires template arguments}} \
+   // expected-warning {{variable templates are a C++14 extension}}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -828,10 +828,14 @@
   }
 
   if (!Found.empty()) {
-if (TypeDecl *TD = Found.getAsSingle())
+if (TypeDecl *TD = Found.getAsSingle()) {
   Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
   << Context.getTypeDeclType(TD) << getLangOpts().CPlusPlus;
-else {
+} else if (Found.getAsSingle()) {
+  ParsedType SuggestedType;
+  DiagnoseUnknownTypeName(IdInfo.Identifier, IdInfo.IdentifierLoc, S, &SS,
+  SuggestedType);
+} else {
   Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
   << IdInfo.Identifier << getLangOpts().CPlusPlus;
   if (NamedDecl *ND = Found.getAsSingle())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126291: [flang][Driver] Update link job on windows

2022-06-14 Thread Markus Mützel via Phabricator via cfe-commits
mmuetzel added inline comments.



Comment at: flang/test/Driver/linker-flags.f90:51
+! MSVC-NOT: libcmt
+! MSVC-NOT: oldnames
+! MSVC-SAME: "[[object_file]]"

Lines 50-51 seem to be duplicates of lines 44-45. Is this intentional?


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

https://reviews.llvm.org/D126291

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


[PATCH] D126291: [flang][Driver] Update link job on windows

2022-06-14 Thread Diana Picus via Phabricator via cfe-commits
rovka added inline comments.



Comment at: flang/test/Driver/linker-flags.f90:51
+! MSVC-NOT: libcmt
+! MSVC-NOT: oldnames
+! MSVC-SAME: "[[object_file]]"

mmuetzel wrote:
> Lines 50-51 seem to be duplicates of lines 44-45. Is this intentional?
Yes, I don't want those to appear either before or after the Fortran libs. I 
guess if we wanted to be pedantic we'd also check that they don't appear after 
the object_file, or between the libs and the subsystem, but that seems a bit 
much.


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

https://reviews.llvm.org/D126291

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


[clang] 9da697e - Reland "[analyzer] Deprecate the unused 'analyzer-opt-analyze-nested-blocks' cc1 flag"

2022-06-14 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2022-06-14T10:22:37+02:00
New Revision: 9da697e1bcefda6a75cd63a10679efe51333d7f9

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

LOG: Reland "[analyzer] Deprecate the unused 
'analyzer-opt-analyze-nested-blocks' cc1 flag"

It was previously reverted by 8406839d1926486de900c7cabeea9f841bd3edf2.

---

This flag was introduced by
https://github.com/llvm/llvm-project/commit/6818991d7165f68fe196922d9e5c6648dd57cc47
commit 6818991d7165f68fe196922d9e5c6648dd57cc47
Author: Ted Kremenek 
Date:   Mon Dec 7 22:06:12 2009 +

  Add clang-cc option '-analyzer-opt-analyze-nested-blocks' to treat
  block literals as an entry point for analyzer checks.

The last reference was removed by this commit:
https://github.com/llvm/llvm-project/commit/5c32dfc5fb1cfcff8ae3671284e17daa8da3a188

commit 5c32dfc5fb1cfcff8ae3671284e17daa8da3a188
Author: Anna Zaks 
Date:   Fri Dec 21 01:19:15 2012 +

  [analyzer] Add blocks and ObjC messages to the call graph.
  This paves the road for constructing a better function dependency graph.
  If we analyze a function before the functions it calls and inlines,
  there is more opportunity for optimization.
  Note, we add call edges to the called methods that correspond to
  function definitions (declarations with bodies).

Consequently, we should remove this dead flag.
However, this arises a couple of burning questions.
 - Should the `cc1` frontend still accept this flag - to keep
   tools/users passing this flag directly to `cc1` (which is unsupported,
   unadvertised) working.
 - If we should remain backward compatible, how long?
 - How can we get rid of deprecated and obsolete flags at some point?

Reviewed By: martong

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Analysis/OSAtomic_mac.cpp
clang/test/Analysis/analyzer-stats.c
clang/test/Analysis/blocks.m
clang/test/Analysis/blocks.mm
clang/test/Analysis/deprecated-flags-and-options.cpp
clang/test/Analysis/misc-ps-arm.m
clang/test/Analysis/misc-ps-region-store.cpp
clang/test/Analysis/misc-ps-region-store.m
clang/test/Analysis/misc-ps-region-store.mm
clang/test/Analysis/objc-arc.m
clang/test/Analysis/unreachable-code-path.c

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 1eedea90a46ed..57b19bd30c1c3 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -442,7 +442,6 @@ ClangTidyASTConsumerFactory::createASTConsumer(
   if (!AnalyzerOptions->CheckersAndPackages.empty()) {
 setStaticAnalyzerCheckerOpts(Context.getOptions(), *AnalyzerOptions);
 AnalyzerOptions->AnalysisDiagOpt = PD_NONE;
-AnalyzerOptions->AnalyzeNestedBlocks = true;
 AnalyzerOptions->eagerlyAssumeBinOpBifurcation = true;
 std::unique_ptr AnalysisConsumer =
 ento::CreateAnalysisConsumer(Compiler);

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 458fa714672fc..e68640074cea5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -550,9 +550,10 @@ Static Analyzer
   `strcmp``, ``strncmp``, ``strcpy``, ``strlen``, ``strsep`` and many more. 
Although
   this checker currently is in list of alpha checkers due to a false positive.
 
-- Deprecate ``-analyzer-store region`` analyzer flag.
-  This flag is still accepted, but a warning will be displayed.
-  This flag will be rejected, thus turned into a hard error starting with
+- Deprecate the ``-analyzer-store region`` and
+  ``-analyzer-opt-analyze-nested-blocks`` analyzer flags.
+  These flags are still accepted, but a warning will be displayed.
+  These flags will be rejected, thus turned into a hard error starting with
   ``clang-16``.
 
 .. _release-notes-ubsan:

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ad75f80153ef2..5fa681f538194 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5036,9 +5036,9 @@ def analyzer_purge_EQ : Joined<["-"], "analyzer-purge=">, 
Alias;
 def analyzer_opt_analyze_headers : Flag<["-"], "analyzer-opt-analyze-headers">,
   HelpText<"Force the static analyzer to analyze functions defined in header 
files">,
   MarshallingInfoFlag>;
+// We should remove this option in clang-16 release.
 def analyzer_opt_analyze_nested_blocks : Flag<["-"], 
"analyzer-opt-analyze-neste

[PATCH] D127460: Rename GCCBuiltin into ClangBuiltin

2022-06-14 Thread Guillaume Gomez via Phabricator via cfe-commits
GuillaumeGomez added a comment.

@efriedma It was falling the tests because of that, which is why I updated it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127460

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


[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-06-14 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 436703.
cor3ntin added a comment.

Fix more style issue (variable casing)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/Lexer.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/FixIt/fixit-unicode-named-escape-sequences.c
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Lexer/unicode.c
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/ucn-identifiers.c
  llvm/CMakeLists.txt
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/CMakeLists.txt
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[PATCH] D127460: Rename GCCBuiltin into ClangBuiltin

2022-06-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/lib/IR/Function.cpp:1430
+// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
 #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
 #include "llvm/IR/IntrinsicImpl.inc"

Should this be updated to use GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127460

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


[PATCH] D127306: [analyzer] Treat system globals as mutable if they are not const

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 436707.
steakhal marked an inline comment as done.
steakhal added a comment.

- Modify the `GenericTaintChecker::isStdin()` to look through //derived 
symbols//, to mitigate the effect of invalidations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127306

Files:
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/Inputs/some_system_globals.h
  clang/test/Analysis/Inputs/some_user_globals.h
  clang/test/Analysis/globals-are-not-always-immutable.c

Index: clang/test/Analysis/globals-are-not-always-immutable.c
===
--- /dev/null
+++ clang/test/Analysis/globals-are-not-always-immutable.c
@@ -0,0 +1,71 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -analyzer-checker=core,debug.ExprInspection
+
+#include "Inputs/errno_var.h"
+#include "Inputs/some_system_globals.h"
+#include "Inputs/some_user_globals.h"
+
+extern void abort() __attribute__((__noreturn__));
+#define assert(expr) ((expr) ? (void)(0) : abort())
+
+void invalidate_globals(void);
+void clang_analyzer_eval(int x);
+
+/// Test the special system 'errno'
+void test_errno_constraint() {
+  assert(errno > 2);
+  clang_analyzer_eval(errno > 2); // expected-warning {{TRUE}}
+  invalidate_globals();
+  clang_analyzer_eval(errno > 2); // expected-warning {{UNKNOWN}}
+}
+void test_errno_assign(int x) {
+  errno = x;
+  clang_analyzer_eval(errno == x); // expected-warning {{TRUE}}
+  invalidate_globals();
+  clang_analyzer_eval(errno == x); // expected-warning {{UNKNOWN}}
+}
+
+/// Test user global variables
+void test_my_const_user_global_constraint() {
+  assert(my_const_user_global > 2);
+  clang_analyzer_eval(my_const_user_global > 2); // expected-warning {{TRUE}}
+  invalidate_globals();
+  clang_analyzer_eval(my_const_user_global > 2); // expected-warning {{TRUE}}
+}
+void test_my_const_user_global_assign(int); // One cannot assign value to a const lvalue.
+
+void test_my_mutable_user_global_constraint() {
+  assert(my_mutable_user_global > 2);
+  clang_analyzer_eval(my_mutable_user_global > 2); // expected-warning {{TRUE}}
+  invalidate_globals();
+  clang_analyzer_eval(my_mutable_user_global > 2); // expected-warning {{UNKNOWN}}
+}
+void test_my_mutable_user_global_assign(int x) {
+  my_mutable_user_global = x;
+  clang_analyzer_eval(my_mutable_user_global == x); // expected-warning {{TRUE}}
+  invalidate_globals();
+  clang_analyzer_eval(my_mutable_user_global == x); // expected-warning {{UNKNOWN}}
+}
+
+/// Test system global variables
+void test_my_const_system_global_constraint() {
+  assert(my_const_system_global > 2);
+  clang_analyzer_eval(my_const_system_global > 2); // expected-warning {{TRUE}}
+  invalidate_globals();
+  clang_analyzer_eval(my_const_system_global > 2); // expected-warning {{TRUE}}
+}
+void test_my_const_system_global_assign(int);// One cannot assign value to a const lvalue.
+
+void test_my_mutable_system_global_constraint() {
+  assert(my_mutable_system_global > 2);
+  clang_analyzer_eval(my_mutable_system_global > 2); // expected-warning {{TRUE}}
+  invalidate_globals();
+  clang_analyzer_eval(my_mutable_system_global > 2); // expected-warning {{UNKNOWN}}
+}
+void test_my_mutable_system_global_assign(int x) {
+  my_mutable_system_global = x;
+  clang_analyzer_eval(my_mutable_system_global == x); // expected-warning {{TRUE}}
+  invalidate_globals();
+  clang_analyzer_eval(my_mutable_system_global == x); // expected-warning {{UNKNOWN}}
+}
Index: clang/test/Analysis/Inputs/some_user_globals.h
===
--- /dev/null
+++ clang/test/Analysis/Inputs/some_user_globals.h
@@ -0,0 +1,2 @@
+extern const int my_const_user_global;
+extern int my_mutable_user_global;
Index: clang/test/Analysis/Inputs/some_system_globals.h
===
--- /dev/null
+++ clang/test/Analysis/Inputs/some_system_globals.h
@@ -0,0 +1,4 @@
+#pragma clang system_header
+
+extern const int my_const_system_global;
+extern int my_mutable_system_global;
Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -973,26 +973,16 @@
   const MemRegion *sReg = nullptr;
 
   if (D->hasGlobalStorage() && !D->isStaticLocal()) {
-
-// First handle the globals defined in system headers.
-if (Ctx.getSourceManager().isInSystemHeader(D->getLocation())) {
-  //  Allow the system globals which often DO GET modified, assume the
-  // rest are immutable.
-  if (D->getName().contains("errno"))
-sReg = getGlobalsRegion(MemRegion::GlobalSystemSpaceRegionKind);
-  else

[PATCH] D127306: [analyzer] Treat system globals as mutable if they are not const

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal requested review of this revision.
steakhal added a comment.

Please check this again @martong @xazax.hun.
I'll also conduct a measurement, investigating what report changes we 
experience with this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127306

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


[PATCH] D125931: [clang][dataflow] Add support for correlated branches to optional model

2022-06-14 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 436710.
sgatev marked 4 inline comments as done.
sgatev added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125931

Files:
  
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1861,7 +1861,26 @@
   )",
  UnorderedElementsAre(Pair("check", "safe")));
 
-  // FIXME: Add tests that call `emplace` in conditional branches.
+  // FIXME: Add tests that call `emplace` in conditional branches:
+  //  ExpectLatticeChecksFor(
+  //  R"(
+  //#include "unchecked_optional_access_test.h"
+  //
+  //void target($ns::$optional opt, bool b) {
+  //  if (b) {
+  //opt.emplace(0);
+  //  }
+  //  if (b) {
+  //opt.value();
+  ///*[[check-1]]*/
+  //  } else {
+  //opt.value();
+  ///*[[check-2]]*/
+  //  }
+  //}
+  //  )",
+  //  UnorderedElementsAre(Pair("check-1", "safe"),
+  //   Pair("check-2", "unsafe: input.cc:12:9")));
 }
 
 TEST_P(UncheckedOptionalAccessTest, Reset) {
@@ -1892,7 +1911,27 @@
   )",
   UnorderedElementsAre(Pair("check", "unsafe: input.cc:7:9")));
 
-  // FIXME: Add tests that call `reset` in conditional branches.
+  // FIXME: Add tests that call `reset` in conditional branches:
+  //  ExpectLatticeChecksFor(
+  //  R"(
+  //#include "unchecked_optional_access_test.h"
+  //
+  //void target(bool b) {
+  //  $ns::$optional opt = $ns::make_optional(0);
+  //  if (b) {
+  //opt.reset();
+  //  }
+  //  if (b) {
+  //opt.value();
+  ///*[[check-1]]*/
+  //  } else {
+  //opt.value();
+  ///*[[check-2]]*/
+  //  }
+  //}
+  //  )",
+  //  UnorderedElementsAre(Pair("check-1", "unsafe: input.cc:10:9"),
+  //   Pair("check-2", "safe")));
 }
 
 TEST_P(UncheckedOptionalAccessTest, ValueAssignment) {
@@ -2347,6 +2386,265 @@
   UnorderedElementsAre(Pair("check", "unsafe: input.cc:12:7")));
 }
 
+TEST_P(UncheckedOptionalAccessTest, CorrelatedBranches) {
+  ExpectLatticeChecksFor(R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (b || opt.has_value()) {
+if (!b) {
+  opt.value();
+  /*[[check-1]]*/
+}
+  }
+}
+  )code",
+ UnorderedElementsAre(Pair("check-1", "safe")));
+
+  ExpectLatticeChecksFor(R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (b && !opt.has_value()) return;
+  if (b) {
+opt.value();
+/*[[check-2]]*/
+  }
+}
+  )code",
+ UnorderedElementsAre(Pair("check-2", "safe")));
+
+  ExpectLatticeChecksFor(
+  R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (opt.has_value()) b = true;
+  if (b) {
+opt.value();
+/*[[check-3]]*/
+  }
+}
+  )code",
+  UnorderedElementsAre(Pair("check-3", "unsafe: input.cc:7:9")));
+
+  ExpectLatticeChecksFor(R"code(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (b) return;
+  if (opt.has_value()) b = true;
+  if (b) {
+opt.value();
+/*[[check-4]]*/
+  }
+}
+  )code",
+ UnorderedElementsAre(Pair("check-4", "safe")));
+
+  ExpectLatticeChecksFor(R"(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (opt.has_value() == b) {
+if (b) {
+  opt.value();
+  /*[[check-5]]*/
+}
+  }
+}
+  )",
+ UnorderedElementsAre(Pair("check-5", "safe")));
+
+  ExpectLatticeChecksFor(R"(
+#include "unchecked_optional_access_test.h"
+
+void target(bool b, $ns::$optional opt) {
+  if (opt.has_value() != b) {
+if (!b) {
+  opt.value();
+  /*[[check-6]]*/
+}
+  }
+}
+  )",
+ UnorderedElementsAre(Pair("check-6", "safe")));
+
+  // FIXME: Add support for operator==.
+  // ExpectLatticeChecksFor(R"(
+  //   #include "unchecked_optional_access_test.h"
+  //
+  //   void target($ns::$optional opt1, $ns::$optional opt2) {
+  // if (opt1 == opt2) {
+  //   if (opt1.has

[PATCH] D127379: [Lex] Keep track of skipped preprocessor blocks and advance the lexer directly if they are revisited

2022-06-14 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

Do you believe an entry in the ReleaseNotes would get this achievement more 
visibility?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127379

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


[PATCH] D111548: [Clang] Add the `annotate_type` attribute

2022-06-14 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 436713.
mboehme added a comment.

Change attribute documentation so it's not specific to C++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111548

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/attr-annotate-type.c
  clang/test/CodeGenCXX/annotate-type.cpp
  clang/test/Sema/annotate-type.c
  clang/test/SemaCXX/annotate-type.cpp
  clang/unittests/AST/AttrTest.cpp

Index: clang/unittests/AST/AttrTest.cpp
===
--- clang/unittests/AST/AttrTest.cpp
+++ clang/unittests/AST/AttrTest.cpp
@@ -7,7 +7,10 @@
 //===--===//
 
 #include "clang/AST/Attr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/AttrKinds.h"
+#include "clang/Tooling/Tooling.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -15,10 +18,154 @@
 
 namespace {
 
+using clang::ast_matchers::constantExpr;
+using clang::ast_matchers::equals;
+using clang::ast_matchers::functionDecl;
+using clang::ast_matchers::has;
+using clang::ast_matchers::hasDescendant;
+using clang::ast_matchers::hasName;
+using clang::ast_matchers::integerLiteral;
+using clang::ast_matchers::match;
+using clang::ast_matchers::selectFirst;
+using clang::ast_matchers::stringLiteral;
+using clang::ast_matchers::varDecl;
+using clang::tooling::buildASTFromCode;
+using clang::tooling::buildASTFromCodeWithArgs;
+
 TEST(Attr, Doc) {
   EXPECT_THAT(Attr::getDocumentation(attr::Used).str(),
   testing::HasSubstr("The compiler must emit the definition even "
  "if it appears to be unused"));
 }
 
+const FunctionDecl *getFunctionNode(ASTUnit *AST, const std::string &Name) {
+  auto Result =
+  match(functionDecl(hasName(Name)).bind("fn"), AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("fn");
+}
+
+const VarDecl *getVariableNode(ASTUnit *AST, const std::string &Name) {
+  auto Result = match(varDecl(hasName(Name)).bind("var"), AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("var");
+}
+
+template 
+void AssertAnnotatedAs(TypeLoc TL, llvm::StringRef annotation,
+   ModifiedTypeLoc &ModifiedTL,
+   const AnnotateTypeAttr **AnnotateOut = nullptr) {
+  const auto AttributedTL = TL.getAs();
+  ASSERT_FALSE(AttributedTL.isNull());
+  ModifiedTL = AttributedTL.getModifiedLoc().getAs();
+  ASSERT_TRUE(ModifiedTL);
+
+  ASSERT_NE(AttributedTL.getAttr(), nullptr);
+  const auto *Annotate = dyn_cast(AttributedTL.getAttr());
+  ASSERT_NE(Annotate, nullptr);
+  EXPECT_EQ(Annotate->getAnnotation(), annotation);
+  if (AnnotateOut) {
+*AnnotateOut = Annotate;
+  }
+}
+
+TEST(Attr, AnnotateType) {
+
+  // Test that the AnnotateType attribute shows up in the right places and that
+  // it stores its arguments correctly.
+
+  auto AST = buildASTFromCode(R"cpp(
+void f(int* [[clang::annotate_type("foo", "arg1", 2)]] *,
+   int [[clang::annotate_type("bar")]]);
+
+int [[clang::annotate_type("int")]] * [[clang::annotate_type("ptr")]]
+  array[10] [[clang::annotate_type("arr")]];
+
+void (* [[clang::annotate_type("funcptr")]] fp)(void);
+
+struct S { int mem; };
+int [[clang::annotate_type("int")]]
+S::* [[clang::annotate_type("ptr_to_mem")]] ptr_to_member = &S::mem;
+  )cpp");
+
+  {
+const FunctionDecl *Func = getFunctionNode(AST.get(), "f");
+
+// First parameter.
+const auto PointerTL = Func->getParamDecl(0)
+   ->getTypeSourceInfo()
+   ->getTypeLoc()
+   .getAs();
+ASSERT_FALSE(PointerTL.isNull());
+PointerTypeLoc PointerPointerTL;
+const AnnotateTypeAttr *Annotate;
+AssertAnnotatedAs(PointerTL.getPointeeLoc(), "foo", PointerPointerTL,
+  &Annotate);
+
+EXPECT_EQ(Annotate->args_size(), 2);
+const auto *StringLit = selectFirst(
+"str", match(constantExpr(hasDescendant(stringLiteral().bind("str"))),
+ *Annotate->args_begin()[0], AST->getASTContext()));
+ASSERT_NE(StringLit, nullptr);
+EXPECT_EQ(StringLit->getString(), "arg1");
+EXPECT_EQ(match(constantExpr(has(integerLiteral(equals(2)).bind("int"))),
+*Annotate->args_begin()[1], AST->getASTContext())
+  .size(),
+  1);
+
+// Second parameter.
+BuiltinTypeLoc IntTL;
+AssertAnnotatedAs(Func->getParamDecl(1)->getTypeSourceInfo()->g

[PATCH] D126291: [flang][Driver] Update link job on windows

2022-06-14 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/test/Driver/linker-flags.f90:51
+! MSVC-NOT: libcmt
+! MSVC-NOT: oldnames
+! MSVC-SAME: "[[object_file]]"

rovka wrote:
> mmuetzel wrote:
> > Lines 50-51 seem to be duplicates of lines 44-45. Is this intentional?
> Yes, I don't want those to appear either before or after the Fortran libs. I 
> guess if we wanted to be pedantic we'd also check that they don't appear 
> after the object_file, or between the libs and the subsystem, but that seems 
> a bit much.
Based on the [[ 
https://llvm.org/docs/CommandGuide/FileCheck.html#the-check-same-directive | 
docs ]], I'd say that this would be the idiomatic way to do this:
```lang=bash
! MSVC-LABEL:
! MSVC-NOT: 
! MSVC-SAME:
```
IIUC, the following would only be needed if there's a potential for `libcmt` or 
`oldnames` to appear on a separate line:
```
```lang=bash
! MSVC-LABEL:
! MSVC-NOT: 
! MSVC-SAME:
! MSVC-NOT:
```
But this wouldn't happen, right? (there's going to be only one linker 
invocation). Also, you could just use [[ 
https://llvm.org/docs/CommandGuide/FileCheck.html#options | 
--implicit-check-not ]] :)


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

https://reviews.llvm.org/D126291

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


[PATCH] D125291: Introduce @llvm.threadlocal.address intrinsic to access TLS variable

2022-06-14 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D125291#3548671 , @jyknight wrote:

> Anyhow -- I think the prototype I'm fiddling with is also along the path to 
> the ideal long-term state, but pushing it beyond a prototype seems like it'll 
> be a pain in the ass due to the bitcode compatibility requirement. (The 
> bitcode upgrader would need to know how to transform all constant expressions 
> using a TLS global into non-constant IR instructions, starting with a call to 
> llvm.threadlocal.address -- in every function where the "constant" is 
> referenced. For uses outside a function body, it transforms to an arbitrary 
> address (e.g. null), instead.)

I have implemented support for converting constant expressions to instructions 
in the bitcode reader in https://reviews.llvm.org/D127729. This was originally 
intended for constant expression removal, but I think with that infrastructure 
in place, upgrading TLS global references to use an intrinsic would be fairly 
simple.


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

https://reviews.llvm.org/D125291

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


[PATCH] D125931: [clang][dataflow] Add support for correlated branches to optional model

2022-06-14 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:174
+/// property of the optional value `OptionalVal`.
+void setHasValue(StructValue &OptionalVal, BoolValue &HasValueVal) {
+  OptionalVal.setProperty("has_value", HasValueVal);

ymandel wrote:
> I believe you can relax this to `Value` because `setProperty` is no longer 
> specific to `StructValue`.
I did that intentionally because I still think it makes sense to assert that an 
optional is modeled as a `StructValue`. I haven't thought about where and how 
it'd be best to assert that though so I'll happily remove the casts for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125931

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


[PATCH] D127730: Reland "[CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder"

2022-06-14 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This reverts commits:
d3ddc251acae631bf5ab4da13878f7e8b5b5a451 

d90eecff5c9e7e9f8263de6cd72d70322400829f 


This relands below commit with asan fix:

The intent of this patch is to selectively carry some states over to
the Builder so we won't lose the information of the previous symbols.

This used to be several downstream patches of Cling, it aims to fix
errors in Clang Interpreter when trying to use inline functions.
Before this patch:

clang-repl> inline int foo() { return 42;}
clang-repl> int x = foo();

JIT session error: Symbols not found: [ _Z3foov ]
error: Failed to materialize symbols:
{ (main, { x, $.incr_module_1.__inits.0, __orc_init_func.incr_module_1 }) }

Co-authored-by: Axel Naumann 
Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127730

Files:
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -134,7 +134,14 @@
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
+
+  std::unique_ptr OldBuilder = std::move(Builder);
+
   Initialize(*Ctx);
+
+  if (OldBuilder)
+OldBuilder->moveLazyEmissionStates(Builder.get());
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1486,6 +1486,33 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  /// Move some lazily-emitted states to the NewBuilder. This is especially
+  /// essential for the incremental parsing environment like Clang Interpreter,
+  /// because we'll lose all important information after each repl.
+  void moveLazyEmissionStates(CodeGenModule *NewBuilder) {
+assert(DeferredDeclsToEmit.empty() &&
+   "Should have emitted all decls deferred to emit.");
+assert(NewBuilder->DeferredDecls.empty() &&
+   "Newly created module should not have deferred decls");
+std::swap(NewBuilder->DeferredDecls, DeferredDecls);
+
+assert(NewBuilder->DeferredVTables.empty() &&
+   "Newly created module should not have deferred vtables");
+std::swap(NewBuilder->DeferredVTables, DeferredVTables);
+
+assert(NewBuilder->MangledDeclNames.empty() &&
+   "Newly created module should not have mangled decl names");
+assert(NewBuilder->Manglings.empty() &&
+   "Newly created module should not have manglings");
+std::swap(NewBuilder->Manglings, Manglings);
+
+assert(WeakRefReferences.empty() &&
+   "Not all WeakRefRefs have been applied");
+std::swap(NewBuilder->WeakRefReferences, WeakRefReferences);
+
+std::swap(NewBuilder->TBAA, TBAA);
+  }
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -134,7 +134,14 @@
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
+
+  std::unique_ptr OldBuilder = std::move(Builder);
+
   Initialize(*Ctx);
+
+  if (OldBuilder)
+OldBuilder->moveLazyEmissionStates(Builder.get());
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===

[PATCH] D126291: [flang][Driver] Update link job on windows

2022-06-14 Thread Diana Picus via Phabricator via cfe-commits
rovka added inline comments.



Comment at: flang/test/Driver/linker-flags.f90:51
+! MSVC-NOT: libcmt
+! MSVC-NOT: oldnames
+! MSVC-SAME: "[[object_file]]"

awarzynski wrote:
> rovka wrote:
> > mmuetzel wrote:
> > > Lines 50-51 seem to be duplicates of lines 44-45. Is this intentional?
> > Yes, I don't want those to appear either before or after the Fortran libs. 
> > I guess if we wanted to be pedantic we'd also check that they don't appear 
> > after the object_file, or between the libs and the subsystem, but that 
> > seems a bit much.
> Based on the [[ 
> https://llvm.org/docs/CommandGuide/FileCheck.html#the-check-same-directive | 
> docs ]], I'd say that this would be the idiomatic way to do this:
> ```lang=bash
> ! MSVC-LABEL:
> ! MSVC-NOT: 
> ! MSVC-SAME:
> ```
> IIUC, the following would only be needed if there's a potential for `libcmt` 
> or `oldnames` to appear on a separate line:
> ```
> ```lang=bash
> ! MSVC-LABEL:
> ! MSVC-NOT: 
> ! MSVC-SAME:
> ! MSVC-NOT:
> ```
> But this wouldn't happen, right? (there's going to be only one linker 
> invocation). Also, you could just use [[ 
> https://llvm.org/docs/CommandGuide/FileCheck.html#options | 
> --implicit-check-not ]] :)
> Based on the [[ 
> https://llvm.org/docs/CommandGuide/FileCheck.html#the-check-same-directive | 
> docs ]], I'd say that this would be the idiomatic way to do this:
> ```lang=bash
> ! MSVC-LABEL:
> ! MSVC-NOT: 
> ! MSVC-SAME:
> ```

Based on the same docs, I would say it shouldn't be enough to mention it just 
once. But that's just what I expect, the docs are completely unhelpful about 
the actual behaviour here. For instance, I would expect to be able to write
```
! MSVC-NOT: should-only-come-after-X
! MSVC-SAME: X
```
If the MSVC-NOT applies to the whole line, then lines with 'X 
should-come-after-X' get rejected, but imo they should be accepted (I'll admit 
I didn't actually verify this, and anyway the implicit-check-not makes the 
whole discussion moot).

> IIUC, the following would only be needed if there's a potential for `libcmt` 
> or `oldnames` to appear on a separate line:
> ```
> ```lang=bash
> ! MSVC-LABEL:
> ! MSVC-NOT: 
> ! MSVC-SAME:
> ! MSVC-NOT:
> ```

I agree that if there's no MSVC-SAME after the last MSVC-NOT, then the MSVC-NOT 
would apply to the following line. 

> But this wouldn't happen, right? (there's going to be only one linker 
> invocation). Also, you could just use [[ 
> https://llvm.org/docs/CommandGuide/FileCheck.html#options | 
> --implicit-check-not ]] :)

Wooow 😍 I didn't know about that one, I'll definitely update the test to use 
it, thanks! 


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

https://reviews.llvm.org/D126291

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


[PATCH] D126291: [flang][Driver] Update link job on windows

2022-06-14 Thread Diana Picus via Phabricator via cfe-commits
rovka updated this revision to Diff 436722.
rovka added a comment.

- Use --implicit-not-check <3


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

https://reviews.llvm.org/D126291

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  flang/test/Driver/linker-flags.f90

Index: flang/test/Driver/linker-flags.f90
===
--- flang/test/Driver/linker-flags.f90
+++ flang/test/Driver/linker-flags.f90
@@ -2,18 +2,17 @@
 ! invocation. These libraries are added on top of other standard runtime
 ! libraries that the Clang driver will include.
 
-! NOTE: The additional linker flags tested here are currently only specified for
-! GNU and Darwin. The following line will make sure that this test is skipped on
-! Windows. If you are running this test on a yet another platform and it is
-! failing for you, please either update the following or (preferably) update the
-! linker invocation accordingly.
-! UNSUPPORTED: system-windows
+!-
+! RUN COMMANDS
+!-
+! RUN: %flang -### -flang-experimental-exec -target ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,GNU
+! RUN: %flang -### -flang-experimental-exec -target aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,DARWIN
+! RUN: %flang -### -flang-experimental-exec -target x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MINGW
 
-!
-! RUN COMMAND
-!
-! Use `--ld-path` so that the linker location (used in the LABEL below) is deterministic.
-! RUN: %flang -### -flang-experimental-exec --ld-path=/usr/bin/ld %S/Inputs/hello.f90 2>&1 | FileCheck %s
+! NOTE: Clang usually adds 'libcmt' and 'oldnames' on Windows, but
+!   they are not needed when compiling Fortran code and they might
+!   bring in additional dependencies. Make sure they're not added.
+! RUN: %flang -### -flang-experimental-exec -target aarch64-windows-msvc %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
 
 !
 ! EXPECTED OUTPUT
@@ -23,9 +22,29 @@
 ! CHECK-SAME:  "-o" "[[object_file:.*\.o]]" {{.*}}Inputs/hello.f90
 
 ! Linker invocation to generate the executable
-! CHECK-LABEL:  "/usr/bin/ld"
-! CHECK-SAME: "[[object_file]]"
-! CHECK-SAME: -lFortran_main
-! CHECK-SAME: -lFortranRuntime
-! CHECK-SAME: -lFortranDecimal
-! CHECK-SAME: -lm
+! GNU-LABEL:  "{{.*}}ld" 
+! GNU-SAME: "[[object_file]]"
+! GNU-SAME: -lFortran_main
+! GNU-SAME: -lFortranRuntime
+! GNU-SAME: -lFortranDecimal
+! GNU-SAME: -lm
+
+! DARWIN-LABEL:  "{{.*}}ld" 
+! DARWIN-SAME: "[[object_file]]"
+! DARWIN-SAME: -lFortran_main
+! DARWIN-SAME: -lFortranRuntime
+! DARWIN-SAME: -lFortranDecimal
+
+! MINGW-LABEL:  "{{.*}}ld" 
+! MINGW-SAME: "[[object_file]]"
+! MINGW-SAME: -lFortran_main
+! MINGW-SAME: -lFortranRuntime
+! MINGW-SAME: -lFortranDecimal
+
+! NOTE: This check should also match if the default linker is lld-link.exe
+! MSVC-LABEL: link.exe
+! MSVC-SAME: Fortran_main.lib
+! MSVC-SAME: FortranRuntime.lib
+! MSVC-SAME: FortranDecimal.lib
+! MSVC-SAME: /subsystem:console
+! MSVC-SAME: "[[object_file]]"
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -218,6 +218,11 @@
 
   AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
 
+  if (C.getDriver().IsFlangMode()) {
+addFortranRuntimeLibraryPath(TC, Args, CmdArgs);
+addFortranRuntimeLibs(TC, CmdArgs);
+  }
+
   // TODO: Add profile stuff here
 
   if (TC.ShouldLinkCXXStdlib(Args)) {
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -81,7 +81,7 @@
 Args.MakeArgString(std::string("-out:") + Output.getFilename()));
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
-  !C.getDriver().IsCLMode()) {
+  !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
 CmdArgs.push_back("-defaultlib:libcmt");
 CmdArgs.push_back("-defaultlib:oldnames");
   }
@@ -130,6 +130,16 @@
   Args.MakeArgString(std::string("-libpath:") + WindowsSdkLibPath));
   }
 
+  if (C.getDriver().IsFlangMode()) {
+addFortranRuntimeLibraryPath(TC, Args, CmdArgs);
+addFortranRuntimeLibs(TC, CmdArgs);
+
+// Inform the MSVC linker that we're generating a console application, i.e.
+// one with `main` as the "user-defined" entry point. The `main` function is
+// defined in flang's runtime libraries.
+CmdArgs.push_back("/subsystem:console");
+  }
+
 

[PATCH] D127732: [analyzer][NFC] Remove unused ExprEngine::evalBinOp functions

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added a reviewer: martong.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127732

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h


Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -608,17 +608,6 @@
  StmtNodeBuilder &Bldr);
 
 public:
-  SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
- NonLoc L, NonLoc R, QualType T) {
-return svalBuilder.evalBinOpNN(state, op, L, R, T);
-  }
-
-  SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
- NonLoc L, SVal R, QualType T) {
-return R.isValid() ? svalBuilder.evalBinOpNN(state, op, L,
- R.castAs(), T) : R;
-  }
-
   SVal evalBinOp(ProgramStateRef ST, BinaryOperator::Opcode Op,
  SVal LHS, SVal RHS, QualType T) {
 return svalBuilder.evalBinOp(ST, Op, LHS, RHS, T);


Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -608,17 +608,6 @@
  StmtNodeBuilder &Bldr);
 
 public:
-  SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
- NonLoc L, NonLoc R, QualType T) {
-return svalBuilder.evalBinOpNN(state, op, L, R, T);
-  }
-
-  SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
- NonLoc L, SVal R, QualType T) {
-return R.isValid() ? svalBuilder.evalBinOpNN(state, op, L,
- R.castAs(), T) : R;
-  }
-
   SVal evalBinOp(ProgramStateRef ST, BinaryOperator::Opcode Op,
  SVal LHS, SVal RHS, QualType T) {
 return svalBuilder.evalBinOp(ST, Op, LHS, RHS, T);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126127: [analyzer][NFC] Relocate unary transfer functions

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 436725.
steakhal added a comment.

rebase; ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126127

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


Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -63,8 +63,6 @@
   : SValBuilder(alloc, context, stateMgr) {}
   ~SimpleSValBuilder() override {}
 
-  SVal evalMinus(NonLoc val) override;
-  SVal evalComplement(NonLoc val) override;
   SVal evalBinOpNN(ProgramStateRef state, BinaryOperator::Opcode op,
NonLoc lhs, NonLoc rhs, QualType resultTy) override;
   SVal evalBinOpLL(ProgramStateRef state, BinaryOperator::Opcode op,
@@ -90,34 +88,6 @@
   return new SimpleSValBuilder(alloc, context, stateMgr);
 }
 
-//===--===//
-// Transfer function for unary operators.
-//===--===//
-
-SVal SimpleSValBuilder::evalMinus(NonLoc val) {
-  switch (val.getSubKind()) {
-  case nonloc::ConcreteIntKind:
-return val.castAs().evalMinus(*this);
-  case nonloc::SymbolValKind:
-return makeNonLoc(val.castAs().getSymbol(), UO_Minus,
-  val.getType(Context));
-  default:
-return UnknownVal();
-  }
-}
-
-SVal SimpleSValBuilder::evalComplement(NonLoc X) {
-  switch (X.getSubKind()) {
-  case nonloc::ConcreteIntKind:
-return X.castAs().evalComplement(*this);
-  case nonloc::SymbolValKind:
-return makeNonLoc(X.castAs().getSymbol(), UO_Not,
-  X.getType(Context));
-  default:
-return UnknownVal();
-  }
-}
-
 // Checks if the negation the value and flipping sign preserve
 // the semantics on the operation in the resultType
 static bool isNegationValuePreserving(const llvm::APSInt &Value,
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -441,6 +441,30 @@
   return UnknownVal();
 }
 
+SVal SValBuilder::evalMinus(NonLoc val) {
+  switch (val.getSubKind()) {
+  case nonloc::ConcreteIntKind:
+return val.castAs().evalMinus(*this);
+  case nonloc::SymbolValKind:
+return makeNonLoc(val.castAs().getSymbol(), UO_Minus,
+  val.getType(Context));
+  default:
+return UnknownVal();
+  }
+}
+
+SVal SValBuilder::evalComplement(NonLoc X) {
+  switch (X.getSubKind()) {
+  case nonloc::ConcreteIntKind:
+return X.castAs().evalComplement(*this);
+  case nonloc::SymbolValKind:
+return makeNonLoc(X.castAs().getSymbol(), UO_Not,
+  X.getType(Context));
+  default:
+return UnknownVal();
+  }
+}
+
 SVal SValBuilder::evalUnaryOp(ProgramStateRef state, UnaryOperator::Opcode opc,
  SVal operand, QualType type) {
   auto OpN = operand.getAs();
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -120,9 +120,8 @@
   SVal evalIntegralCast(ProgramStateRef state, SVal val, QualType castTy,
 QualType originalType);
 
-  virtual SVal evalMinus(NonLoc val) = 0;
-
-  virtual SVal evalComplement(NonLoc val) = 0;
+  SVal evalMinus(NonLoc val);
+  SVal evalComplement(NonLoc val);
 
   /// Create a new value which represents a binary expression with two non-
   /// location operands.


Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -63,8 +63,6 @@
   : SValBuilder(alloc, context, stateMgr) {}
   ~SimpleSValBuilder() override {}
 
-  SVal evalMinus(NonLoc val) override;
-  SVal evalComplement(NonLoc val) override;
   SVal evalBinOpNN(ProgramStateRef state, BinaryOperator::Opcode op,
NonLoc lhs, NonLoc rhs, QualType resultTy) override;
   SVal evalBinOpLL(ProgramStateRef state, BinaryOperator::Opcode op,
@@ -90,34 +88,6 @@
   return new SimpleSValBuilder(alloc, context, stateMgr);
 }
 
-//===--===//
-// Transfer function for unary operators.
-//===--===//
-
-SVal SimpleSValBuilder::evalMinus(NonLoc val) {
-  switch (

[PATCH] D127734: [analyzer][NFC] Substitute the SVal::evalMinus and evalComplement functions

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added a reviewer: martong.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Depends on D126127 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127734

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


Index: clang/lib/StaticAnalyzer/Core/SVals.cpp
===
--- clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -252,20 +252,6 @@
   return isConstant(0);
 }
 
-//===--===//
-// Transfer function dispatch for Non-Locs.
-//===--===//
-
-nonloc::ConcreteInt
-nonloc::ConcreteInt::evalComplement(SValBuilder &svalBuilder) const {
-  return svalBuilder.makeIntVal(~getValue());
-}
-
-nonloc::ConcreteInt
-nonloc::ConcreteInt::evalMinus(SValBuilder &svalBuilder) const {
-  return svalBuilder.makeIntVal(-getValue());
-}
-
 
//===--===//
 // Pretty-Printing.
 
//===--===//
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -441,13 +441,13 @@
   return UnknownVal();
 }
 
-SVal SValBuilder::evalMinus(NonLoc val) {
-  switch (val.getSubKind()) {
+SVal SValBuilder::evalMinus(NonLoc X) {
+  switch (X.getSubKind()) {
   case nonloc::ConcreteIntKind:
-return val.castAs().evalMinus(*this);
+return makeIntVal(-X.castAs().getValue());
   case nonloc::SymbolValKind:
-return makeNonLoc(val.castAs().getSymbol(), UO_Minus,
-  val.getType(Context));
+return makeNonLoc(X.castAs().getSymbol(), UO_Minus,
+  X.getType(Context));
   default:
 return UnknownVal();
   }
@@ -456,7 +456,7 @@
 SVal SValBuilder::evalComplement(NonLoc X) {
   switch (X.getSubKind()) {
   case nonloc::ConcreteIntKind:
-return X.castAs().evalComplement(*this);
+return makeIntVal(~X.castAs().getValue());
   case nonloc::SymbolValKind:
 return makeNonLoc(X.castAs().getSymbol(), UO_Not,
   X.getType(Context));
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -338,11 +338,6 @@
 return *static_cast(Data);
   }
 
-  // Transfer functions for unary operations on ConcreteInts.
-  ConcreteInt evalComplement(SValBuilder &svalBuilder) const;
-
-  ConcreteInt evalMinus(SValBuilder &svalBuilder) const;
-
   static bool classof(SVal V) {
 return V.getBaseKind() == NonLocKind && V.getSubKind() == ConcreteIntKind;
   }


Index: clang/lib/StaticAnalyzer/Core/SVals.cpp
===
--- clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -252,20 +252,6 @@
   return isConstant(0);
 }
 
-//===--===//
-// Transfer function dispatch for Non-Locs.
-//===--===//
-
-nonloc::ConcreteInt
-nonloc::ConcreteInt::evalComplement(SValBuilder &svalBuilder) const {
-  return svalBuilder.makeIntVal(~getValue());
-}
-
-nonloc::ConcreteInt
-nonloc::ConcreteInt::evalMinus(SValBuilder &svalBuilder) const {
-  return svalBuilder.makeIntVal(-getValue());
-}
-
 //===--===//
 // Pretty-Printing.
 //===--===//
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -441,13 +441,13 @@
   return UnknownVal();
 }
 
-SVal SValBuilder::evalMinus(NonLoc val) {
-  switch (val.getSubKind()) {
+SVal SValBuilder::evalMinus(NonLoc X) {
+  switch (X.getSubKind()) {
   case nonloc::ConcreteIntKind:
-return val.castAs().evalMinus(*this);
+return makeIntVal(-X.castAs().getValue());
   case nonloc::SymbolValKind:
-return makeNonLoc(val.castAs().getSymbol(), UO_M

[PATCH] D126891: [clang-tidy] The check should ignore final classes

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

ping again; @whisperity


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126891

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


[clang] 781ee53 - Reland "[CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder"

2022-06-14 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-06-14T18:36:03+08:00
New Revision: 781ee538da1855876b085989a37ec959e3f2ecd1

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

LOG: Reland "[CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder"

This reverts commits:
d3ddc251acae631bf5ab4da13878f7e8b5b5a451
d90eecff5c9e7e9f8263de6cd72d70322400829f

This relands below commit with asan fix:

The intent of this patch is to selectively carry some states over to
the Builder so we won't lose the information of the previous symbols.

This used to be several downstream patches of Cling, it aims to fix
errors in Clang Interpreter when trying to use inline functions.
Before this patch:

clang-repl> inline int foo() { return 42;}
clang-repl> int x = foo();

JIT session error: Symbols not found: [ _Z3foov ]
error: Failed to materialize symbols:
{ (main, { x, $.incr_module_1.__inits.0, __orc_init_func.incr_module_1 }) }

Co-authored-by: Axel Naumann 
Signed-off-by: Jun Zhang 

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/ModuleBuilder.cpp
clang/test/Interpreter/execute.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index 779d94ad62d98..cce8e46ad5ac6 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1486,6 +1486,33 @@ class CodeGenModule : public CodeGenTypeCache {
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  /// Move some lazily-emitted states to the NewBuilder. This is especially
+  /// essential for the incremental parsing environment like Clang Interpreter,
+  /// because we'll lose all important information after each repl.
+  void moveLazyEmissionStates(CodeGenModule *NewBuilder) {
+assert(DeferredDeclsToEmit.empty() &&
+   "Should have emitted all decls deferred to emit.");
+assert(NewBuilder->DeferredDecls.empty() &&
+   "Newly created module should not have deferred decls");
+std::swap(NewBuilder->DeferredDecls, DeferredDecls);
+
+assert(NewBuilder->DeferredVTables.empty() &&
+   "Newly created module should not have deferred vtables");
+std::swap(NewBuilder->DeferredVTables, DeferredVTables);
+
+assert(NewBuilder->MangledDeclNames.empty() &&
+   "Newly created module should not have mangled decl names");
+assert(NewBuilder->Manglings.empty() &&
+   "Newly created module should not have manglings");
+std::swap(NewBuilder->Manglings, Manglings);
+
+assert(WeakRefReferences.empty() &&
+   "Not all WeakRefRefs have been applied");
+std::swap(NewBuilder->WeakRefReferences, WeakRefReferences);
+
+std::swap(NewBuilder->TBAA, TBAA);
+  }
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,

diff  --git a/clang/lib/CodeGen/ModuleBuilder.cpp 
b/clang/lib/CodeGen/ModuleBuilder.cpp
index 50b7fd8eb993c..8e97a298ce7fa 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -134,7 +134,14 @@ namespace {
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
+
+  std::unique_ptr OldBuilder = std::move(Builder);
+
   Initialize(*Ctx);
+
+  if (OldBuilder)
+OldBuilder->moveLazyEmissionStates(Builder.get());
+
   return M.get();
 }
 

diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index 298046c068c37..61e68990acf96 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@ struct S { float f = 1.0; S *m = nullptr;} s;
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit



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


[PATCH] D127730: Reland "[CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder"

2022-06-14 Thread Jun Zhang via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG781ee538da18: Reland "[CodeGen] Keep track info of 
lazy-emitted symbols in ModuleBuilder" (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127730

Files:
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -134,7 +134,14 @@
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
+
+  std::unique_ptr OldBuilder = std::move(Builder);
+
   Initialize(*Ctx);
+
+  if (OldBuilder)
+OldBuilder->moveLazyEmissionStates(Builder.get());
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1486,6 +1486,33 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  /// Move some lazily-emitted states to the NewBuilder. This is especially
+  /// essential for the incremental parsing environment like Clang Interpreter,
+  /// because we'll lose all important information after each repl.
+  void moveLazyEmissionStates(CodeGenModule *NewBuilder) {
+assert(DeferredDeclsToEmit.empty() &&
+   "Should have emitted all decls deferred to emit.");
+assert(NewBuilder->DeferredDecls.empty() &&
+   "Newly created module should not have deferred decls");
+std::swap(NewBuilder->DeferredDecls, DeferredDecls);
+
+assert(NewBuilder->DeferredVTables.empty() &&
+   "Newly created module should not have deferred vtables");
+std::swap(NewBuilder->DeferredVTables, DeferredVTables);
+
+assert(NewBuilder->MangledDeclNames.empty() &&
+   "Newly created module should not have mangled decl names");
+assert(NewBuilder->Manglings.empty() &&
+   "Newly created module should not have manglings");
+std::swap(NewBuilder->Manglings, Manglings);
+
+assert(WeakRefReferences.empty() &&
+   "Not all WeakRefRefs have been applied");
+std::swap(NewBuilder->WeakRefReferences, WeakRefReferences);
+
+std::swap(NewBuilder->TBAA, TBAA);
+  }
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -134,7 +134,14 @@
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
+
+  std::unique_ptr OldBuilder = std::move(Builder);
+
   Initialize(*Ctx);
+
+  if (OldBuilder)
+OldBuilder->moveLazyEmissionStates(Builder.get());
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1486,6 +1486,33 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  /// Move some lazily-emitted states to the NewBuilder. This is especially
+  /// essential for the incremental parsing environment like Clang Interpreter,
+  /// because we'll lose all important information after each repl.
+  void moveLazyEmissionStates(CodeGenModule *NewBuilder) {
+assert(DeferredDeclsToEmit.empty() &&
+   "Should have emitted all decls deferred to emit.");
+assert(NewBuilder->DeferredDecls.empty() &&

[PATCH] D126308: cmake: use llvm dir variables for clang/utils/hmaptool

2022-06-14 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

Hi @mizvekov, this change seems to have broken the location of the hmaptool 
when using the Visual Studio builder on Windows. After your commit, 7 clang 
tests fail because hmaptool cannot be found at the expected location. For 
example, the test clang/test/Preprocessor/headermap-rel.c:

  FAIL: Clang :: Preprocessor/headermap-rel.c (1 of 1)
   TEST 'Clang :: Preprocessor/headermap-rel.c' FAILED 

  Script:
  --
  : 'RUN: at line 1';   rm -f 
D:\src\upstream\51608515faa7-PS4-Release\tools\clang\test\Preprocessor\Output\headermap-rel.c.tmp.hmap
  : 'RUN: at line 2';   'C:/Program Files/Python310/python.exe' 
D:\src\upstream\51608515faa7-PS4-Release\Release\bin\hmaptool write 
D:\src\upstream\llvm_clean_git\clang\test\Preprocessor/Inputs/headermap-rel/foo.hmap.json
 
D:\src\upstream\51608515faa7-PS4-Release\tools\clang\test\Preprocessor\Output\headermap-rel.c.tmp.hmap
  : 'RUN: at line 3';   
d:\src\upstream\51608515faa7-ps4-release\release\bin\clang.exe -cc1 
-internal-isystem 
d:\src\upstream\51608515faa7-ps4-release\release\lib\clang\15.0.0\include 
-nostdsysteminc -E 
D:\src\upstream\llvm_clean_git\clang\test\Preprocessor\headermap-rel.c -o 
D:\src\upstream\51608515faa7-PS4-Release\tools\clang\test\Preprocessor\Output\headermap-rel.c.tmp.i
 -I 
D:\src\upstream\51608515faa7-PS4-Release\tools\clang\test\Preprocessor\Output\headermap-rel.c.tmp.hmap
 -F D:\src\upstream\llvm_clean_git\clang\test\Preprocessor/Inputs/headermap-rel
  : 'RUN: at line 4';   
d:\src\upstream\51608515faa7-ps4-release\release\bin\filecheck.exe 
D:\src\upstream\llvm_clean_git\clang\test\Preprocessor\headermap-rel.c 
-input-file 
D:\src\upstream\51608515faa7-PS4-Release\tools\clang\test\Preprocessor\Output\headermap-rel.c.tmp.i
  --
  Exit Code: 2
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ "rm" "-f" 
"D:\src\upstream\51608515faa7-PS4-Release\tools\clang\test\Preprocessor\Output\headermap-rel.c.tmp.hmap"
  $ ":" "RUN: at line 2"
  $ "C:/Program Files/Python310/python.exe" 
"D:\src\upstream\51608515faa7-PS4-Release\Release\bin\hmaptool" "write" 
"D:\src\upstream\llvm_clean_git\clang\test\Preprocessor/Inputs/headermap-rel/foo.hmap.json"
 
"D:\src\upstream\51608515faa7-PS4-Release\tools\clang\test\Preprocessor\Output\headermap-rel.c.tmp.hmap"
  # command stderr:
  C:/Program Files/Python310/python.exe: can't open file 
'D:\\src\\upstream\\51608515faa7-PS4-Release\\Release\\bin\\hmaptool': [Errno 
2] No such file or directory
  
  error: command failed with exit status: 2

Before your change, in this particular case when doing a Release build with 
Visual Studio, hmaptool can be found at \Release\bin\hmaptool, but 
after your change, it is now located at \s\bin\hmaptool which is not 
where lit expects to find it causing the test to fail.

Can you take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126308

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


[PATCH] D124762: [WinEHPrepare] Avoid truncation of EH funclets with GNUstep ObjC runtime

2022-06-14 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz updated this revision to Diff 436730.
sgraenitz added a comment.

Update LLVM CodeGen test for mainline opaque pointers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124762

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGenObjCXX/arc-exceptions-seh.mm
  llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
  llvm/lib/CodeGen/WinEHPrepare.cpp
  llvm/test/CodeGen/X86/win64-funclet-preisel-intrinsics.ll

Index: llvm/test/CodeGen/X86/win64-funclet-preisel-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/win64-funclet-preisel-intrinsics.ll
@@ -0,0 +1,68 @@
+; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
+
+; Reduced IR generated from ObjC++ source:
+;
+; @class Ety;
+; void opaque(void);
+; void test_catch(void) {
+;   @try {
+; opaque();
+;   } @catch (Ety *ex) {
+; // Destroy ex when leaving catchpad. This emits calls to two intrinsic
+; // functions, llvm.objc.retain and llvm.objc.storeStrong, but only one
+; // is required to trigger the funclet truncation.
+;   }
+; }
+
+define void @test_catch() personality ptr @__CxxFrameHandler3 {
+entry:
+  %exn.slot = alloca ptr, align 8
+  %ex2 = alloca ptr, align 8
+  invoke void @opaque() to label %invoke.cont unwind label %catch.dispatch
+
+catch.dispatch:
+  %0 = catchswitch within none [label %catch] unwind to caller
+
+invoke.cont:
+  unreachable
+
+catch:
+  %1 = catchpad within %0 [ptr null, i32 64, ptr %exn.slot]
+  call void @llvm.objc.storeStrong(ptr %ex2, ptr null) [ "funclet"(token %1) ]
+  catchret from %1 to label %catchret.dest
+
+catchret.dest:
+  ret void
+}
+
+declare void @opaque()
+declare void @llvm.objc.storeStrong(ptr, ptr) #0
+declare i32 @__CxxFrameHandler3(...)
+
+attributes #0 = { nounwind }
+
+; llvm.objc.storeStrong is a Pre-ISel intrinsic, which used to cause truncations
+; when it occurred in SEH funclets like catchpads:
+; CHECK: # %catch
+; CHECK: pushq   %rbp
+; CHECK: .seh_pushreg %rbp
+;...
+; CHECK: .seh_endprologue
+;
+; At this point the code used to be truncated (and sometimes terminated with an
+; int3 opcode):
+; CHECK-NOT: int3
+;
+; Instead, the call to objc_storeStrong should be emitted:
+; CHECK: leaq	-24(%rbp), %rcx
+; CHECK: xorl	%edx, %edx
+; CHECK: callq	objc_storeStrong
+;...
+; 
+; This is the end of the funclet:
+; CHECK: popq	%rbp
+; CHECK: retq# CATCHRET
+;...
+; CHECK: .seh_handlerdata
+;...
+; CHECK: .seh_endproc
Index: llvm/lib/CodeGen/WinEHPrepare.cpp
===
--- llvm/lib/CodeGen/WinEHPrepare.cpp
+++ llvm/lib/CodeGen/WinEHPrepare.cpp
@@ -963,7 +963,7 @@
 if (auto BU = CB->getOperandBundle(LLVMContext::OB_funclet))
   FuncletBundleOperand = BU->Inputs.front();
 
-if (FuncletBundleOperand == FuncletPad)
+if (!FuncletPad || FuncletBundleOperand == FuncletPad)
   continue;
 
 // Skip call sites which are nounwind intrinsics or inline asm.
Index: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
===
--- llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -107,7 +107,9 @@
 
 IRBuilder<> Builder(CI->getParent(), CI->getIterator());
 SmallVector Args(CI->args());
-CallInst *NewCI = Builder.CreateCall(FCache, Args);
+SmallVector BundleList;
+CI->getOperandBundlesAsDefs(BundleList);
+CallInst *NewCI = Builder.CreateCall(FCache, Args, BundleList);
 NewCI->setName(CI->getName());
 
 // Try to set the most appropriate TailCallKind based on both the current
Index: clang/test/CodeGenObjCXX/arc-exceptions-seh.mm
===
--- /dev/null
+++ clang/test/CodeGenObjCXX/arc-exceptions-seh.mm
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm -fobjc-arc -fexceptions -fobjc-exceptions -fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s
+
+@class Ety;
+void opaque(void);
+void test_catch_preisel_intrinsic(void) {
+  @try {
+opaque();
+  } @catch (Ety *ex) {
+// Destroy ex when leaving catchpad. Emits calls to two intrinsic functions,
+// that should both have a "funclet" bundle operand that refers to the
+// catchpad's SSA value.
+  }
+}
+
+// CHECK-LABEL: define{{.*}} void {{.*}}test_catch_preisel_intrinsic
+//...
+// CHECK:   catch.dispatch:
+// CHECK-NEXT:[[CATCHSWITCH:%[0-9]+]] = catchswitch within none
+//...
+// CHECK:   catch:
+// CHECK-NEXT:[[CATCHPAD:%[0-9]+]] = catchpad within [[CATCHSWITCH]]
+// CHECK: {{%[0-9]+}} = call {{.*}} @llvm.objc.retain{{.*}} [ "funcle

[PATCH] D127638: [clang][sema] Provide better diagnostic for missing template parameters

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

LGTM, thanks for the fix! Please add a release note when you land the changes. 
:-)


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

https://reviews.llvm.org/D127638

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


[PATCH] D127518: [Diagnostics] Fix inconsistent shift-overflow warnings in C++20

2022-06-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:11423-11425
+  // Don't warn in C++2A mode (and newer), as signed left shifts
+  // always wrap and never overflow.
+  if (S.getLangOpts().CPlusPlus20)

I think this should also be checking `|| isSignedOverflowDefined()` -- if 
signed overflow is defined, then all the rest of the diagnostics shouldn't be 
triggered because the behavior is defined.

(Eventually, we should remove the check for `CPlusPlus20` and use ONLY 
`isSignedOverflowDefined()` -- that should account for the current language 
mode instead of requiring us to check additional predicates. But that doesn't 
have to be fixed up as part of this patch.)



Comment at: clang/lib/Sema/SemaExpr.cpp:11430
   // then, the behavior is undefined before C++2a. Warn about it.
-  if (Left.isNegative() && !S.getLangOpts().isSignedOverflowDefined() &&
-  !S.getLangOpts().CPlusPlus20) {
+  if (Left.isNegative() && !S.getLangOpts().isSignedOverflowDefined()) {
 S.DiagRuntimeBehavior(Loc, LHS.get(),

Then the `isSignedOverflowDefined()` check can be removed here.


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

https://reviews.llvm.org/D127518

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


[clang] d9b8d13 - [NFC][Alignment] Use MaybeAlign in CGCleanup/CGExpr

2022-06-14 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2022-06-14T10:56:36Z
New Revision: d9b8d13f8b58086e2c8d5c59be6f79222a07931e

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

LOG: [NFC][Alignment] Use MaybeAlign in CGCleanup/CGExpr

Added: 


Modified: 
clang/include/clang/AST/CharUnits.h
clang/lib/CodeGen/CGCleanup.cpp
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/include/clang/AST/CharUnits.h 
b/clang/include/clang/AST/CharUnits.h
index f14d3abf71e5e..2705f24789e4c 100644
--- a/clang/include/clang/AST/CharUnits.h
+++ b/clang/include/clang/AST/CharUnits.h
@@ -182,6 +182,12 @@ namespace clang {
   /// Beware llvm::Align assumes power of two 8-bit bytes.
   llvm::Align getAsAlign() const { return llvm::Align(Quantity); }
 
+  /// getAsMaybeAlign - Returns Quantity as a valid llvm::Align or
+  /// llvm::None, Beware llvm::MaybeAlign assumes power of two 8-bit bytes.
+  llvm::MaybeAlign getAsMaybeAlign() const {
+return llvm::MaybeAlign(Quantity);
+  }
+
   /// alignTo - Returns the next integer (mod 2**64) that is
   /// greater than or equal to this quantity and is a multiple of \p Align.
   /// Align must be non-zero.

diff  --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index a10851edfb82c..5035ed34358d2 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -77,7 +77,7 @@ RValue 
DominatingValue::saved_type::restore(CodeGenFunction &CGF) {
   auto getSavingAddress = [&](llvm::Value *value) {
 auto *AI = cast(value);
 return Address(value, AI->getAllocatedType(),
-   CharUnits::fromQuantity(AI->getAlignment()));
+   CharUnits::fromQuantity(AI->getAlign().value()));
   };
   switch (K) {
   case ScalarLiteral:

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 3d7f13aed0aba..cbeb6c938bee7 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -757,23 +757,23 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, 
SourceLocation Loc,
 }
   }
 
-  uint64_t AlignVal = 0;
+  llvm::MaybeAlign AlignVal;
   llvm::Value *PtrAsInt = nullptr;
 
   if (SanOpts.has(SanitizerKind::Alignment) &&
   !SkippedChecks.has(SanitizerKind::Alignment)) {
-AlignVal = Alignment.getQuantity();
+AlignVal = Alignment.getAsMaybeAlign();
 if (!Ty->isIncompleteType() && !AlignVal)
   AlignVal = CGM.getNaturalTypeAlignment(Ty, nullptr, nullptr,
  /*ForPointeeType=*/true)
- .getQuantity();
+ .getAsMaybeAlign();
 
 // The glvalue must be suitably aligned.
-if (AlignVal > 1 &&
-(!PtrToAlloca || PtrToAlloca->getAlignment() < AlignVal)) {
+if (AlignVal && *AlignVal > llvm::Align(1) &&
+(!PtrToAlloca || PtrToAlloca->getAlign() < *AlignVal)) {
   PtrAsInt = Builder.CreatePtrToInt(Ptr, IntPtrTy);
   llvm::Value *Align = Builder.CreateAnd(
-  PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));
+  PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal->value() - 1));
   llvm::Value *Aligned =
   Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0));
   if (Aligned != True)
@@ -782,12 +782,9 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, 
SourceLocation Loc,
   }
 
   if (Checks.size() > 0) {
-// Make sure we're not losing information. Alignment needs to be a power of
-// 2
-assert(!AlignVal || (uint64_t)1 << llvm::Log2_64(AlignVal) == AlignVal);
 llvm::Constant *StaticData[] = {
 EmitCheckSourceLocation(Loc), EmitCheckTypeDescriptor(Ty),
-llvm::ConstantInt::get(Int8Ty, AlignVal ? llvm::Log2_64(AlignVal) : 1),
+llvm::ConstantInt::get(Int8Ty, AlignVal ? llvm::Log2(*AlignVal) : 1),
 llvm::ConstantInt::get(Int8Ty, TCK)};
 EmitCheck(Checks, SanitizerHandler::TypeMismatch, StaticData,
   PtrAsInt ? PtrAsInt : Ptr);



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


[PATCH] D111548: [Clang] Add the `annotate_type` attribute

2022-06-14 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 436732.
mboehme marked 2 inline comments as done.
mboehme added a comment.

Instead of allowing all type attributes on the decl-specifier-seq, allow only
`annotate_type` for now. The more general change will be done in
https://reviews.llvm.org/D126061.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111548

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/attr-annotate-type.c
  clang/test/CodeGenCXX/annotate-type.cpp
  clang/test/Sema/annotate-type.c
  clang/test/SemaCXX/annotate-type.cpp
  clang/unittests/AST/AttrTest.cpp

Index: clang/unittests/AST/AttrTest.cpp
===
--- clang/unittests/AST/AttrTest.cpp
+++ clang/unittests/AST/AttrTest.cpp
@@ -7,7 +7,10 @@
 //===--===//
 
 #include "clang/AST/Attr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/AttrKinds.h"
+#include "clang/Tooling/Tooling.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -15,10 +18,154 @@
 
 namespace {
 
+using clang::ast_matchers::constantExpr;
+using clang::ast_matchers::equals;
+using clang::ast_matchers::functionDecl;
+using clang::ast_matchers::has;
+using clang::ast_matchers::hasDescendant;
+using clang::ast_matchers::hasName;
+using clang::ast_matchers::integerLiteral;
+using clang::ast_matchers::match;
+using clang::ast_matchers::selectFirst;
+using clang::ast_matchers::stringLiteral;
+using clang::ast_matchers::varDecl;
+using clang::tooling::buildASTFromCode;
+using clang::tooling::buildASTFromCodeWithArgs;
+
 TEST(Attr, Doc) {
   EXPECT_THAT(Attr::getDocumentation(attr::Used).str(),
   testing::HasSubstr("The compiler must emit the definition even "
  "if it appears to be unused"));
 }
 
+const FunctionDecl *getFunctionNode(ASTUnit *AST, const std::string &Name) {
+  auto Result =
+  match(functionDecl(hasName(Name)).bind("fn"), AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("fn");
+}
+
+const VarDecl *getVariableNode(ASTUnit *AST, const std::string &Name) {
+  auto Result = match(varDecl(hasName(Name)).bind("var"), AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("var");
+}
+
+template 
+void AssertAnnotatedAs(TypeLoc TL, llvm::StringRef annotation,
+   ModifiedTypeLoc &ModifiedTL,
+   const AnnotateTypeAttr **AnnotateOut = nullptr) {
+  const auto AttributedTL = TL.getAs();
+  ASSERT_FALSE(AttributedTL.isNull());
+  ModifiedTL = AttributedTL.getModifiedLoc().getAs();
+  ASSERT_TRUE(ModifiedTL);
+
+  ASSERT_NE(AttributedTL.getAttr(), nullptr);
+  const auto *Annotate = dyn_cast(AttributedTL.getAttr());
+  ASSERT_NE(Annotate, nullptr);
+  EXPECT_EQ(Annotate->getAnnotation(), annotation);
+  if (AnnotateOut) {
+*AnnotateOut = Annotate;
+  }
+}
+
+TEST(Attr, AnnotateType) {
+
+  // Test that the AnnotateType attribute shows up in the right places and that
+  // it stores its arguments correctly.
+
+  auto AST = buildASTFromCode(R"cpp(
+void f(int* [[clang::annotate_type("foo", "arg1", 2)]] *,
+   int [[clang::annotate_type("bar")]]);
+
+int [[clang::annotate_type("int")]] * [[clang::annotate_type("ptr")]]
+  array[10] [[clang::annotate_type("arr")]];
+
+void (* [[clang::annotate_type("funcptr")]] fp)(void);
+
+struct S { int mem; };
+int [[clang::annotate_type("int")]]
+S::* [[clang::annotate_type("ptr_to_mem")]] ptr_to_member = &S::mem;
+  )cpp");
+
+  {
+const FunctionDecl *Func = getFunctionNode(AST.get(), "f");
+
+// First parameter.
+const auto PointerTL = Func->getParamDecl(0)
+   ->getTypeSourceInfo()
+   ->getTypeLoc()
+   .getAs();
+ASSERT_FALSE(PointerTL.isNull());
+PointerTypeLoc PointerPointerTL;
+const AnnotateTypeAttr *Annotate;
+AssertAnnotatedAs(PointerTL.getPointeeLoc(), "foo", PointerPointerTL,
+  &Annotate);
+
+EXPECT_EQ(Annotate->args_size(), 2);
+const auto *StringLit = selectFirst(
+"str", match(constantExpr(hasDescendant(stringLiteral().bind("str"))),
+ *Annotate->args_begin()[0], AST->getASTContext()));
+ASSERT_NE(StringLit, nullptr);
+EXPECT_EQ(StringLit->getString(), "arg1");
+EXPECT_EQ(match(constantExpr(has(integerLiteral(equals(2)).bind("int"))),
+*Annotate->args_begin()[1], AST->getASTContext())
+  

[PATCH] D112916: [clang-tidy] Confusable identifiers detection

2022-06-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D112916#3554181 , @tstellar wrote:

> In D112916#3554158 , @Mordante 
> wrote:
>
>> In D112916#3113140 , @tstellar 
>> wrote:
>>
>>> The LLVM Board of Directors will do a legal review of this change.  We will 
>>> give an update in 4-6 weeks.
>>
>> @tstellar, is there an update from the LLVM Board of Directors regarding 
>> using Unicode data?
>> I'm implementing extended grapheme clustering in libc++ which requires using 
>> Unicode data.
>> Note that MSVC STL (which is using the same license as the LLVM project) 
>> already uses Unicode data in the following generated header
>> https://github.com/microsoft/STL/blob/main/stl/inc/__msvc_format_ucd_tables.hpp
>
> Yes, it's fine to include the unicode data.

@tstellar -- Do we have any license requirements we need to follow? @rsmith 
pointed out:

> (b) this copyright and permission notice appear in associated Documentation.

which sounds like we need to update one of our license files.

(I'll assume the same answer applies for the Unicode named escape sequences 
patch happening in Clang currently.)




Comment at: clang-tools-extra/clang-tidy/misc/Homoglyph.cpp:84
+  if (const auto *ND = Result.Nodes.getNodeAs("nameddecl")) {
+if(IdentifierInfo * II = ND->getIdentifier()) {
+  StringRef NDName = II->getName();

(Formatting -- might just want to run clang-format over the patch.)



Comment at: clang-tools-extra/docs/clang-tidy/checks/misc-homoglyph.rst:6-10
+Warn about confusable identifiers, i.e. identifiers that are visually close to
+each other, but use different unicode characters. This detetcs potential attack
+as described in `Trojan Source `_.
+
+Example:





Comment at: clang-tools-extra/docs/clang-tidy/checks/misc-homoglyph.rst:14-15
+
+int fo;
+int 𝐟o;




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

https://reviews.llvm.org/D112916

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


[PATCH] D111548: [Clang] Add the `annotate_type` attribute

2022-06-14 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked an inline comment as done.
mboehme added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:6501
+
+The attribute does not have any effect on the semantics of C++ code, neither
+type checking rules, nor runtime semantics. In particular:

aaron.ballman wrote:
> (Since this is for C as well as C++)
Good point -- done.



Comment at: clang/lib/Parse/ParseDecl.cpp:3187-3193
+  // We reject AT_LifetimeBound and AT_AnyX86NoCfCheck, even though 
they
+  // are type attributes, because we historically haven't allowed these
+  // to be used as type attributes in C++11 / C2x syntax.
+  if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_LifetimeBound 
&&
+  PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck)
+continue;
+  Diag(PA.getLoc(), diag::err_attribute_not_type_attr) << PA;

aaron.ballman wrote:
> Should this be done as part of D126061 instead?
Thanks for raising this question!

In this patch, I had originally allowed all type attributes to be placed on the 
decl-specifier-seq because a) I needed this to be true for `annotate_type` so 
that I could test the attribute in this position, and b) there didn't appear to 
be any harm in allowing any type attribute instead of just `annotate_type`.

However, subsequent discussion on https://reviews.llvm.org/D126061 has made it 
clear that not all type attributes should actually be allowed on the 
decl-specifier-seq -- at least not initially, since they won't currently work 
correctly in that context (see extensive discussion on that other patch). So 
I've made the code here more restrictive to allow only `annotate_type` on the 
decl-specifier-seq (which is all that I need here).

https://reviews.llvm.org/D126061 now contains the change that allows type 
attributes on the decl-specifier-seq more generally, which is fine because it 
also contains additional code to disable this behavior again for the specific 
attributes that need it.

Given that I'm planning to land this patch and https://reviews.llvm.org/D126061 
at the same time, it's not _super_ critical where we make this change, but a) 
the way it's done now makes the patches more logically cohesive, and b) there's 
always a chance that a patch may need to be reverted, and having the right 
changes together in one patch will be important then.

Thanks again for bringing this to my attention!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111548

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


[PATCH] D127460: Rename GCCBuiltin into ClangBuiltin

2022-06-14 Thread Guillaume Gomez via Phabricator via cfe-commits
GuillaumeGomez added inline comments.



Comment at: llvm/lib/IR/Function.cpp:1430
+// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
 #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
 #include "llvm/IR/IntrinsicImpl.inc"

RKSimon wrote:
> Should this be updated to use GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN?
I think it should for coherency. I'll send an update.



Comment at: llvm/lib/IR/Function.cpp:1430
+// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
 #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
 #include "llvm/IR/IntrinsicImpl.inc"

GuillaumeGomez wrote:
> RKSimon wrote:
> > Should this be updated to use GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN?
> I think it should for coherency. I'll send an update.
When replacing with `CLANG`, it cannot build. After some investigations, it's 
because of this:

```
llvm/utils/TableGen/IntrinsicEmitter.cpp:908:  OS << "#ifdef 
GET_LLVM_INTRINSIC_FOR_" << CompilerName << "_BUILTIN\n";
```

So I'll let it as is for the time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127460

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


[PATCH] D127379: [Lex] Keep track of skipped preprocessor blocks and advance the lexer directly if they are revisited

2022-06-14 Thread Raul Tambre via Phabricator via cfe-commits
tambre added a comment.

In D127379#3581009 , @tschuett wrote:

> Do you believe an entry in the ReleaseNotes would get this achievement more 
> visibility?

I second that this would be worthy of a release note. Seems like quite a big 
improvement.

I wonder how much is the total speedup for a full LLVM build or such?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127379

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


[PATCH] D125931: [clang][dataflow] Add support for correlated branches to optional model

2022-06-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added inline comments.



Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:174
+/// property of the optional value `OptionalVal`.
+void setHasValue(StructValue &OptionalVal, BoolValue &HasValueVal) {
+  OptionalVal.setProperty("has_value", HasValueVal);

sgatev wrote:
> ymandel wrote:
> > I believe you can relax this to `Value` because `setProperty` is no longer 
> > specific to `StructValue`.
> I did that intentionally because I still think it makes sense to assert that 
> an optional is modeled as a `StructValue`. I haven't thought about where and 
> how it'd be best to assert that though so I'll happily remove the casts for 
> now.
Sounds good. I had the same thought. But, it occurs to me that at this point, 
are we using the `StructValue` at all? If not, then the only reason we expect 
it to be a `StructValue` is because we know the optional type is a record type. 
But, that's not an assumption of our model. So, maybe we should be agnostic to 
the underlying representation?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125931

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


[clang] de6ba97 - [analyzer][Casting] Support isa, cast, dyn_cast of SVals

2022-06-14 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2022-06-14T13:43:04+02:00
New Revision: de6ba9704d0b4fa047a030b5bf369e425b937198

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

LOG: [analyzer][Casting] Support isa, cast, dyn_cast of SVals

This change specializes the LLVM RTTI mechanism for SVals.
After this change, we can use the well-known `isa`, `cast`, `dyn_cast`.

Examples:

  // SVal V = ...;
  // Loc MyLoc = ...;

  bool IsInteresting = isa(MyLoc);
  auto MRV = cast(MyLoc);
  Optional MaybeMRV = dyn_cast(V)

The current `SVal::getAs` and `castAs` member functions are redundant at
this point, but I believe that they are still handy.

The member function version is terse and reads left-to-right, which IMO
is a great plus. However, we should probably add a variadic `isa` member
function version to have the same casting API in both cases.

Thanks for the extensive TMP help @bzcheeseman!

Reviewed By: bzcheeseman

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
index 7c5f23b6d466a..c3750b2320c89 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -98,19 +98,12 @@ class SVal {
 
   /// Convert to the specified SVal type, asserting that this SVal is of
   /// the desired type.
-  template
-  T castAs() const {
-assert(T::classof(*this));
-return *static_cast(this);
-  }
+  template  T castAs() const { return llvm::cast(*this); }
 
   /// Convert to the specified SVal type, returning None if this SVal is
   /// not of the desired type.
-  template
-  Optional getAs() const {
-if (!T::classof(*this))
-  return None;
-return *static_cast(this);
+  template  Optional getAs() const {
+return llvm::dyn_cast(*this);
   }
 
   unsigned getRawKind() const { return Kind; }
@@ -564,4 +557,28 @@ class ConcreteInt : public Loc {
 } // namespace ento
 } // namespace clang
 
+namespace llvm {
+template 
+struct CastInfo<
+To, From,
+std::enable_if_t::value>>
+: public CastIsPossible {
+  using Self = CastInfo<
+  To, From,
+  std::enable_if_t::value>>;
+  static bool isPossible(const From &V) {
+return To::classof(*static_cast(&V));
+  }
+  static Optional castFailed() { return Optional{}; }
+  static To doCast(const From &f) {
+return *static_cast(cast<::clang::ento::SVal>(&f));
+  }
+  static Optional doCastIfPossible(const From &f) {
+if (!Self::isPossible(f))
+  return Self::castFailed();
+return doCast(f);
+  }
+};
+} // namespace llvm
+
 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H

diff  --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index 2c210fb6cdb97..b143ef93282f9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -446,7 +446,7 @@ void CFNumberChecker::checkPreStmt(const CallExpr *CE,
 
   // FIXME: We really should allow ranges of valid theType values, and
   //   bifurcate the state appropriately.
-  Optional V = TheTypeVal.getAs();
+  Optional V = dyn_cast(TheTypeVal);
   if (!V)
 return;
 
@@ -907,7 +907,7 @@ static ProgramStateRef checkElementNonNil(CheckerContext &C,
 
   // Go ahead and assume the value is non-nil.
   SVal Val = State->getSVal(*ElementLoc);
-  return State->assume(Val.castAs(), true);
+  return State->assume(cast(Val), true);
 }
 
 /// Returns NULL state if the collection is known to contain elements



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


[PATCH] D125709: [analyzer][Casting] Support isa, cast, dyn_cast of SVals

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGde6ba9704d0b: [analyzer][Casting] Support isa, cast, 
dyn_cast of SVals (authored by steakhal).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125709

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp


Index: clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -446,7 +446,7 @@
 
   // FIXME: We really should allow ranges of valid theType values, and
   //   bifurcate the state appropriately.
-  Optional V = TheTypeVal.getAs();
+  Optional V = dyn_cast(TheTypeVal);
   if (!V)
 return;
 
@@ -907,7 +907,7 @@
 
   // Go ahead and assume the value is non-nil.
   SVal Val = State->getSVal(*ElementLoc);
-  return State->assume(Val.castAs(), true);
+  return State->assume(cast(Val), true);
 }
 
 /// Returns NULL state if the collection is known to contain elements
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -98,19 +98,12 @@
 
   /// Convert to the specified SVal type, asserting that this SVal is of
   /// the desired type.
-  template
-  T castAs() const {
-assert(T::classof(*this));
-return *static_cast(this);
-  }
+  template  T castAs() const { return llvm::cast(*this); }
 
   /// Convert to the specified SVal type, returning None if this SVal is
   /// not of the desired type.
-  template
-  Optional getAs() const {
-if (!T::classof(*this))
-  return None;
-return *static_cast(this);
+  template  Optional getAs() const {
+return llvm::dyn_cast(*this);
   }
 
   unsigned getRawKind() const { return Kind; }
@@ -564,4 +557,28 @@
 } // namespace ento
 } // namespace clang
 
+namespace llvm {
+template 
+struct CastInfo<
+To, From,
+std::enable_if_t::value>>
+: public CastIsPossible {
+  using Self = CastInfo<
+  To, From,
+  std::enable_if_t::value>>;
+  static bool isPossible(const From &V) {
+return To::classof(*static_cast(&V));
+  }
+  static Optional castFailed() { return Optional{}; }
+  static To doCast(const From &f) {
+return *static_cast(cast<::clang::ento::SVal>(&f));
+  }
+  static Optional doCastIfPossible(const From &f) {
+if (!Self::isPossible(f))
+  return Self::castFailed();
+return doCast(f);
+  }
+};
+} // namespace llvm
+
 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H


Index: clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -446,7 +446,7 @@
 
   // FIXME: We really should allow ranges of valid theType values, and
   //   bifurcate the state appropriately.
-  Optional V = TheTypeVal.getAs();
+  Optional V = dyn_cast(TheTypeVal);
   if (!V)
 return;
 
@@ -907,7 +907,7 @@
 
   // Go ahead and assume the value is non-nil.
   SVal Val = State->getSVal(*ElementLoc);
-  return State->assume(Val.castAs(), true);
+  return State->assume(cast(Val), true);
 }
 
 /// Returns NULL state if the collection is known to contain elements
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -98,19 +98,12 @@
 
   /// Convert to the specified SVal type, asserting that this SVal is of
   /// the desired type.
-  template
-  T castAs() const {
-assert(T::classof(*this));
-return *static_cast(this);
-  }
+  template  T castAs() const { return llvm::cast(*this); }
 
   /// Convert to the specified SVal type, returning None if this SVal is
   /// not of the desired type.
-  template
-  Optional getAs() const {
-if (!T::classof(*this))
-  return None;
-return *static_cast(this);
+  template  Optional getAs() const {
+return llvm::dyn_cast(*this);
   }
 
   unsigned getRawKind() const { return Kind; }
@@ -564,4 +557,28 @@
 } // namespace ento
 } // namespace clang
 
+namespace llvm {
+template 
+struct CastInfo<
+To, From,
+std::enable_if_t::value>>
+: public CastIsPossible {
+  using Self = CastInfo<
+  To, From,
+  std::enable_if_t::value>>;
+  static bool isPossible(const From &V) {
+return To::classof(*static_cast(&V));
+  }
+  static Optional castFa

[clang] 44f0a26 - Revert "Reland "[CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder""

2022-06-14 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-06-14T19:53:17+08:00
New Revision: 44f0a2658d22ffc12bac6ca2c8f4a3d98603ea3a

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

LOG: Revert "Reland "[CodeGen] Keep track info of lazy-emitted symbols in 
ModuleBuilder""

This reverts commit 781ee538da1855876b085989a37ec959e3f2ecd1.

Asan build is still broken :(

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/ModuleBuilder.cpp
clang/test/Interpreter/execute.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index cce8e46ad5ac6..779d94ad62d98 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1486,33 +1486,6 @@ class CodeGenModule : public CodeGenTypeCache {
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
-  /// Move some lazily-emitted states to the NewBuilder. This is especially
-  /// essential for the incremental parsing environment like Clang Interpreter,
-  /// because we'll lose all important information after each repl.
-  void moveLazyEmissionStates(CodeGenModule *NewBuilder) {
-assert(DeferredDeclsToEmit.empty() &&
-   "Should have emitted all decls deferred to emit.");
-assert(NewBuilder->DeferredDecls.empty() &&
-   "Newly created module should not have deferred decls");
-std::swap(NewBuilder->DeferredDecls, DeferredDecls);
-
-assert(NewBuilder->DeferredVTables.empty() &&
-   "Newly created module should not have deferred vtables");
-std::swap(NewBuilder->DeferredVTables, DeferredVTables);
-
-assert(NewBuilder->MangledDeclNames.empty() &&
-   "Newly created module should not have mangled decl names");
-assert(NewBuilder->Manglings.empty() &&
-   "Newly created module should not have manglings");
-std::swap(NewBuilder->Manglings, Manglings);
-
-assert(WeakRefReferences.empty() &&
-   "Not all WeakRefRefs have been applied");
-std::swap(NewBuilder->WeakRefReferences, WeakRefReferences);
-
-std::swap(NewBuilder->TBAA, TBAA);
-  }
-
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,

diff  --git a/clang/lib/CodeGen/ModuleBuilder.cpp 
b/clang/lib/CodeGen/ModuleBuilder.cpp
index 8e97a298ce7fa..50b7fd8eb993c 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -134,14 +134,7 @@ namespace {
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
-
-  std::unique_ptr OldBuilder = std::move(Builder);
-
   Initialize(*Ctx);
-
-  if (OldBuilder)
-OldBuilder->moveLazyEmissionStates(Builder.get());
-
   return M.get();
 }
 

diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index 61e68990acf96..298046c068c37 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -13,8 +13,4 @@ struct S { float f = 1.0; S *m = nullptr;} s;
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
-
 quit



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


[PATCH] D126479: [Clang] Allow 'Complex float __attribute__((mode(HC)))'

2022-06-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/TargetInfo.h:223-224
   unsigned HasAlignMac68kSupport : 1;
-  unsigned RealTypeUsesObjCFPRet : 3;
+  unsigned RealTypeUsesObjCFPRet : (1 << (int)FloatModeKind::Float) |
+   (1 << (int)FloatModeKind::Double);
   unsigned ComplexLongDoubleUsesFP2Ret : 1;

tahonermann wrote:
> aaron.ballman wrote:
> > jolanta.jensen wrote:
> > > tahonermann wrote:
> > > > This doesn't look right to me. The size of the bit field would be `(1 
> > > > << 1) | (1 << 2)` which is `0b110` which is 6, but more by coincidence 
> > > > than by construction. I think what we want is:
> > > >   unsigned RealTypeUsesObjCFPRet  : (int)FloatModeKind::Last + 1;
> > > Sorry. I mixed things up.
> > >I think what we want is:
> > >`unsigned RealTypeUsesObjCFPRet  : (int)FloatModeKind::Last + 1;`
> > 
> > I think this is wrong in two different ways. We need as many bits as 
> > required to store the enumerator value. The highest value is 255 
> > (`NoFloat`), so we need at least 8 bits for that. But also, the last 
> > enumerator value is just that -- a value, not a width.
> > 
> > I'd probably skip the `Last` entry and force the bit-field to 8 bits.
> `RealTypeUsesObjCFPRet` is used as a bit mask indexed by the `FloatModeKind` 
> enumerator values; the `X86_32TargetInfo` constructor in 
> `clang/lib/Basic/Targets/X86.h` has the following code:
> 
>   420 // Use fpret for all types.
>   421 RealTypeUsesObjCFPRet =
>   422 ((1 << (int)FloatModeKind::Float) | (1 << 
> (int)FloatModeKind::Double) |
>   423  (1 << (int)FloatModeKind::LongDouble));
> 
> `NoFloat` is a special case for which a mask bit is not needed.
> 
> I think this code is correct as is, but Aaron's comment suggests some 
> clarification would be useful. Perhaps the data member should be renamed to 
> something like `RealTypeUsesObjCFPRetMask` (though I suspect a better name 
> can be found).
A, yeah, I definitely did not pick up the fact that these were used as part 
of a mask. I'm more used to masks being represented directly in the enumeration 
itself, e.g., `enum Whatever { FirstThing = 1 << 0, SecondThing = 1 << 1, 
ThirdThing = 1 << 2 };` These aren't really masks, they're shift amounts to be 
used to form a mask. Any reason we don't switch to that form to make it more 
clear (and simplify other code)? Actually, any reason why we don't want to 
switch the enumeration to use bitmask enums 
(https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/BitmaskEnum.h)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126479

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


[PATCH] D127641: [clang-cl][MSVC] Add default /Zc conformance arguments

2022-06-14 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: clang/test/Driver/cl-zc.cpp:98
 // thread safe statics are off for versions < 19.
 // RUN: %clang_cl /c -### -fms-compatibility-version=18 -- %s 2>&1 | FileCheck 
-check-prefix=NoThreadSafeStatics %s
 // RUN: %clang_cl /Zc:threadSafeInit /Zc:threadSafeInit- /c -### -- %s 2>&1 | 
FileCheck -check-prefix=NoThreadSafeStatics %s

steplong wrote:
> This line will fail, but I can't find any documentation on thread safe 
> statics being off for versions < 19. 
> https://docs.microsoft.com/en-us/cpp/build/reference/zc-threadsafeinit-thread-safe-local-static-initialization?view=msvc-170
>  says Visual Studio 2015 implements this by default.
VS 2015 has _MSC_VER 1900.
The test was added here: 
https://github.com/llvm/llvm-project/commit/c371ff048df8731052976f4e628ed1861cf61cfd
 and I assume David verified locally that 19 is the real cutoff.
I just tested locally with VS 2013, and it is indeed off there

```
C:\src\tmp>type a.cc && cl -c a.cc && dumpbin /disasm a.obj
int g();

int f() {
static int x = g();
return x;
}
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

a.cc
Microsoft (R) COFF/PE Dumper Version 12.00.31101.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file a.obj

File Type: COFF OBJECT

?f@@YAHXZ (int __cdecl f(void)):
  : 55 pushebp
  0001: 8B EC  mov ebp,esp
  0003: A1 00 00 00 00 mov eax,dword ptr [?$S1@?1??f@@YAHXZ@4IA]
  0008: 83 E0 01   and eax,1
  000B: 75 19  jne 0026
  000D: 8B 0D 00 00 00 00  mov ecx,dword ptr [?$S1@?1??f@@YAHXZ@4IA]
  0013: 83 C9 01   or  ecx,1
  0016: 89 0D 00 00 00 00  mov dword ptr [?$S1@?1??f@@YAHXZ@4IA],ecx
  001C: E8 00 00 00 00 call?g@@YAHXZ
  0021: A3 00 00 00 00 mov dword ptr [?x@?1??f@@YAHXZ@4HA],eax
  0026: A1 00 00 00 00 mov eax,dword ptr [?x@?1??f@@YAHXZ@4HA]
  002B: 5D pop ebp
  002C: C3 ret

  Summary

   8 .bss
  64 .debug$S
  2F .drectve
  2D .text$mn
```



Comment at: clang/tools/driver/driver.cpp:237
 
+static void insertDefaultClangCLZcConformanceArgs(
+SmallVectorImpl &ArgVector) {

Instead of injecting flags like this which seems a bit crude and won't work in 
non-clang-cl mode, can't we just enable these features keyed off the MSVC 
version like we already do for e.g. thread-safe statics?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127641

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


[PATCH] D126061: [clang] Reject non-declaration C++11 attributes on declarations

2022-06-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

Only thing left for me are the nits I pointed out in the last review, otherwise 
I think this is all set. Giving my LG because I don't think we need another 
round of review for those nits unless you want it




Comment at: clang/lib/Sema/ParsedAttr.cpp:241
+  case AT_ObjCGC:
+  case AT_VectorSize:
+return true;

rsmith wrote:
> mboehme wrote:
> > rsmith wrote:
> > > This one is weird. Given:
> > > 
> > > ```
> > > [[gnu::vector_size(8)]] int x;
> > > int [[gnu::vector_size(8)]] y;
> > > int *[[gnu::vector_size(8)]]* z;
> > > ```
> > > 
> > > - Clang and GCC accept `x`
> > > - Clang rejects `y` and GCC warns that the attribute is ignored on `y`
> > > - Clang accepts `z` with a warning that GCC would ignore the attribute, 
> > > whereas GCC silently accepts
> > > 
> > > I guess after this patch we'll silently accept `x` (treated as the 
> > > "sliding" behavior) and accept `y` and `z` with a warning that it's 
> > > GCC-incompatible?
> > > This one is weird. Given:
> > > 
> > > ```
> > > [[gnu::vector_size(8)]] int x;
> > > int [[gnu::vector_size(8)]] y;
> > > int *[[gnu::vector_size(8)]]* z;
> > > ```
> > > 
> > > - Clang and GCC accept `x`
> > > - Clang rejects `y` and GCC warns that the attribute is ignored on `y`
> > > - Clang accepts `z` with a warning that GCC would ignore the attribute, 
> > > whereas GCC silently accepts
> > 
> > Actually, for z, Clang gives me not just a warning but also an error: 
> > 
> > ```
> > :1:8: warning: GCC does not allow the 'vector_size' attribute to be 
> > written on a type [-Wgcc-compat]
> > int *[[gnu::vector_size(8)]]* z;
> >^
> > :1:8: error: invalid vector element type 'int *'
> > ```
> > 
> > https://godbolt.org/z/E4ss8rzWE
> > 
> > > I guess after this patch we'll silently accept `x` (treated as the 
> > > "sliding" behavior) and accept `y` and `z` with a warning that it's 
> > > GCC-incompatible?
> > 
> > Thanks for pointing this out to me!
> > 
> > Actually, I must not have checked the GCC behavior previously, so I went 
> > too far and gave `vector_size` meaning when placed on `y` instead of just 
> > ignoring it. I’ve now changed the code to ignore the attribute and emit a 
> > warning, like GCC does. (See tests in `vector-gcc-compat.c`.)
> > 
> > It’s particularly surprising to me that GCC allows `vector_size` to be 
> > applied to a pointer type (the `z` case) – particularly so since the 
> > [documentation](https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html) 
> > explicitly states: “The vector_size attribute is only applicable to 
> > integral and floating scalars, although arrays, pointers, and function 
> > return values are allowed in conjunction with this construct.”
> > 
> > I wanted to test whether GCC just silently ignores the attribute when 
> > placed on a pointer or whether it has an effect. Here are some test cases:
> > 
> > https://godbolt.org/z/Ke1E7TnYe
> > 
> > From looking at the generated code, it appears that `vector_size`, when 
> > applied to a pointer type, _does_ have an effect – though a maybe slightly 
> > surprising one: It is applied to the base type, rather than the pointer 
> > type. I suspect that GCC simply treats the C++11 spelling the same as the 
> > `__attribute__` spelling (i.e. it doesn’t apply the stricter C++11 rules on 
> > what the attribute should appertain to), and it seems that both spellings 
> > get applied to the base type of the declaration no matter where they appear 
> > in the declaration (except if the attribute is ignored entirely).
> > 
> > Interestingly, this means that Clang’s warning (“GCC does not allow the 
> > 'vector_size' attribute to be written on a type”) is wrong. Maybe this is 
> > behavior in GCC that has changed since the warning was introduced?
> > 
> > Given all of this, I propose we treat the various cases as follows (and 
> > I’ve implemented this in the code):
> > 
> > * We continue to accept `x` without a warning, just as we do today (same 
> > behavior as GCC)
> > * We allow `y` but warn that the attribute doesn’t have an effect (same 
> > behavior as GCC)
> > * We continue to reject `z`, even though GCC allows it and it has an effect 
> > there. Rationale: a) We reject this today, so this isn’t a regression; b) 
> > this usage is unusual and likely not to occur often in the wild; c) fixing 
> > this to be consistent with GCC will take a non-trivial amount of code, so 
> > I’d like to keep it outside the scope of this change.
> > https://godbolt.org/z/Ke1E7TnYe
> 
> That GCC behavior is shocking. Shocking enough that I think the following 
> approach would make sense:
> 
> 1) For compatibility, emulate the GCC behavior as much as possible for 
> `[[gnu::vector_size]]`, except:
> - Continue to error rather than only warning in the cases where the 
> attribute does not create a vector type at all, and
> - Warn on cases like `int *[[gnu::vector_size(N)]]` (a

[PATCH] D126682: [Interpreter][ClangRepl] Implement undo command

2022-06-14 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added reviewers: sgraenitz, lhames, rjmccall.
v.g.vassilev added a comment.
Herald added a subscriber: StephenFan.

I think we are in a good shape to broaden the list of reviewers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126682

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


[PATCH] D126620: [clang] AST/Print: honor AlwaysIncludeTypeForTemplateArgument policy

2022-06-14 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

Let's move forward with this and rely on eventual post-commit review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126620

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


[PATCH] D112916: [clang-tidy] Confusable identifiers detection

2022-06-14 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 436739.
serge-sans-paille marked an inline comment as done.
serge-sans-paille added a comment.

Take into account @aaron.ballman review


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

https://reviews.llvm.org/D112916

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/ConfusableTable/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/ConfusableTable/build_confusable_table.cpp
  clang-tools-extra/clang-tidy/misc/ConfusableTable/confusables.txt
  clang-tools-extra/clang-tidy/misc/Homoglyph.cpp
  clang-tools-extra/clang-tidy/misc/Homoglyph.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-homoglyph.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-homoglyph.cpp

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


[PATCH] D125669: Adding support for target in_reduction

2022-06-14 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:5035-5039
+llvm::APInt TrueOrFalse(32,
+S.hasClausesOfKind() ? 0 : 
1);
+IntegerLiteral IfCond(getContext(), TrueOrFalse,
+  getContext().getIntTypeForBitwidth(32, /*Signed=*/0),
+  SourceLocation());

Why integer, not a boolean? Also, this is currently meaningless, since these 2 
vars are not visible outside of the if context.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125669

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


[PATCH] D127518: [Diagnostics] Fix inconsistent shift-overflow warnings in C++20

2022-06-14 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 436746.
xgupta added a comment.

.


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

https://reviews.llvm.org/D127518

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/expr/expr.const/p2-0x.cpp
  clang/test/SemaCXX/constant-expression-cxx2a.cpp
  clang/test/SemaCXX/shift.cpp


Index: clang/test/SemaCXX/shift.cpp
===
--- clang/test/SemaCXX/shift.cpp
+++ clang/test/SemaCXX/shift.cpp
@@ -41,8 +41,8 @@
 
   int i;
   i = 1 << (WORD_BIT - 2);
-  i = 2 << (WORD_BIT - 1); // expected-warning {{bits to represent, but 'int' 
only has}}
-  i = 1 << (WORD_BIT - 1); // expected-warning {{sets the sign bit of the 
shift expression}}
+  i = 2 << (WORD_BIT - 1); // cxx17-warning {{bits to represent, but 'int' 
only has}}
+  i = 1 << (WORD_BIT - 1); // cxx17-warning {{sets the sign bit of the shift 
expression}}
   i = -1 << (WORD_BIT - 1); // cxx17-warning {{shifting a negative signed 
value is undefined}}
   i = -1 << 0; // cxx17-warning {{shifting a negative signed value is 
undefined}}
   i = 0 << (WORD_BIT - 1);
@@ -53,7 +53,7 @@
   u = 5U << (WORD_BIT - 1);
 
   long long int lli;
-  lli = INT_MIN << 2; // cxx17-warning {{shifting a negative signed value is 
undefined}} cxx2a-warning {{requires 34 bits to represent}}
+  lli = INT_MIN << 2; // cxx17-warning {{shifting a negative signed value is 
undefined}}
   lli = 1LL << (sizeof(long long) * CHAR_BIT - 2);
 }
 
Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -530,8 +530,8 @@
   using int32 = __INT32_TYPE__;
   static_assert(uint32(int32(0x1234) << 16) == 0x1234);
   static_assert(uint32(int32(0x1234) << 19) == 0x91a0);
-  static_assert(uint32(int32(0x1234) << 20) == 0x2340); // 
expected-warning {{requires 34 bits}}
-  static_assert(uint32(int32(0x1234) << 24) == 0x3400); // 
expected-warning {{requires 38 bits}}
+  static_assert(uint32(int32(0x1234) << 20) == 0x2340);
+  static_assert(uint32(int32(0x1234) << 24) == 0x3400);
   static_assert(uint32(int32(-1) << 31) == 0x8000);
 
   static_assert(-1 >> 1 == -1);
Index: clang/test/CXX/expr/expr.const/p2-0x.cpp
===
--- clang/test/CXX/expr/expr.const/p2-0x.cpp
+++ clang/test/CXX/expr/expr.const/p2-0x.cpp
@@ -162,9 +162,9 @@
   constexpr int shl_signed_ok = 1 << 30; // ok
   constexpr int shl_signed_into_sign = 1 << 31; // ok (DR1457)
   constexpr int shl_signed_into_sign_2 = 0x7fff << 1; // ok (DR1457)
-  constexpr int shl_signed_off_end = 2 << 31; // cxx11-error {{constant 
expression}} cxx11-note {{signed left shift discards bits}} expected-warning 
{{signed shift result (0x1) requires 34 bits to represent, but 'int' 
only has 32 bits}}
-  constexpr int shl_signed_off_end_2 = 0x7fff << 2; // cxx11-error 
{{constant expression}} cxx11-note {{signed left shift discards bits}} 
expected-warning {{signed shift result (0x1FFFC) requires 34 bits to 
represent, but 'int' only has 32 bits}}
-  constexpr int shl_signed_overflow = 1024 << 31; // cxx11-error {{constant 
expression}} cxx11-note {{signed left shift discards bits}} expected-warning 
{{requires 43 bits to represent}}
+  constexpr int shl_signed_off_end = 2 << 31; // cxx11-error {{constant 
expression}} cxx11-note {{signed left shift discards bits}} cxx11-warning 
{{signed shift result (0x1) requires 34 bits to represent, but 'int' 
only has 32 bits}}
+  constexpr int shl_signed_off_end_2 = 0x7fff << 2; // cxx11-error 
{{constant expression}} cxx11-note {{signed left shift discards bits}} 
cxx11-warning {{signed shift result (0x1FFFC) requires 34 bits to 
represent, but 'int' only has 32 bits}}
+  constexpr int shl_signed_overflow = 1024 << 31; // cxx11-error {{constant 
expression}} cxx11-note {{signed left shift discards bits}} cxx11-warning 
{{requires 43 bits to represent}}
   constexpr int shl_signed_ok2 = 1024 << 20; // ok
 
   constexpr int shr_m1 = 0 >> -1; // expected-error {{constant expression}} 
expected-note {{negative shift count -1}}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -11416,10 +11416,16 @@
 return;
   llvm::APSInt Left = LHSResult.Val.getInt();
 
-  // If LHS does not have a signed type and non-negative value
-  // then, the behavior is undefined before C++2a. Warn about it.
-  if (Left.isNegative() && !S.getLangOpts().isSignedOverflowDefined() &&
-  !S.getLangOpts().CPlusPlus20) {
+  // Don't warn if signed overflow is defined, then all the rest of the
+  // diagnostics will not be triggered because the behavior is defined.
+  // Also don't warn in C++20 mode (and newer), as sign

[PATCH] D111548: [Clang] Add the `annotate_type` attribute

2022-06-14 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, thank you for this! I did find one small formatting issue in the release 
notes, but you can fix that up when landing.




Comment at: clang/docs/ReleaseNotes.rst:349
 
+- Added the `clang::annotate_type` attribute, which can be used to add
+  annotations to types (see documentation for details).




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111548

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


[PATCH] D126291: [flang][Driver] Update link job on windows

2022-06-14 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/test/Driver/linker-flags.f90:51
+! MSVC-NOT: libcmt
+! MSVC-NOT: oldnames
+! MSVC-SAME: "[[object_file]]"

rovka wrote:
> awarzynski wrote:
> > rovka wrote:
> > > mmuetzel wrote:
> > > > Lines 50-51 seem to be duplicates of lines 44-45. Is this intentional?
> > > Yes, I don't want those to appear either before or after the Fortran 
> > > libs. I guess if we wanted to be pedantic we'd also check that they don't 
> > > appear after the object_file, or between the libs and the subsystem, but 
> > > that seems a bit much.
> > Based on the [[ 
> > https://llvm.org/docs/CommandGuide/FileCheck.html#the-check-same-directive 
> > | docs ]], I'd say that this would be the idiomatic way to do this:
> > ```lang=bash
> > ! MSVC-LABEL:
> > ! MSVC-NOT: 
> > ! MSVC-SAME:
> > ```
> > IIUC, the following would only be needed if there's a potential for 
> > `libcmt` or `oldnames` to appear on a separate line:
> > ```
> > ```lang=bash
> > ! MSVC-LABEL:
> > ! MSVC-NOT: 
> > ! MSVC-SAME:
> > ! MSVC-NOT:
> > ```
> > But this wouldn't happen, right? (there's going to be only one linker 
> > invocation). Also, you could just use [[ 
> > https://llvm.org/docs/CommandGuide/FileCheck.html#options | 
> > --implicit-check-not ]] :)
> > Based on the [[ 
> > https://llvm.org/docs/CommandGuide/FileCheck.html#the-check-same-directive 
> > | docs ]], I'd say that this would be the idiomatic way to do this:
> > ```lang=bash
> > ! MSVC-LABEL:
> > ! MSVC-NOT: 
> > ! MSVC-SAME:
> > ```
> 
> Based on the same docs, I would say it shouldn't be enough to mention it just 
> once. But that's just what I expect, the docs are completely unhelpful about 
> the actual behaviour here. For instance, I would expect to be able to write
> ```
> ! MSVC-NOT: should-only-come-after-X
> ! MSVC-SAME: X
> ```
> If the MSVC-NOT applies to the whole line, then lines with 'X 
> should-come-after-X' get rejected, but imo they should be accepted (I'll 
> admit I didn't actually verify this, and anyway the implicit-check-not makes 
> the whole discussion moot).
> 
> > IIUC, the following would only be needed if there's a potential for 
> > `libcmt` or `oldnames` to appear on a separate line:
> > ```
> > ```lang=bash
> > ! MSVC-LABEL:
> > ! MSVC-NOT: 
> > ! MSVC-SAME:
> > ! MSVC-NOT:
> > ```
> 
> I agree that if there's no MSVC-SAME after the last MSVC-NOT, then the 
> MSVC-NOT would apply to the following line. 
> 
> > But this wouldn't happen, right? (there's going to be only one linker 
> > invocation). Also, you could just use [[ 
> > https://llvm.org/docs/CommandGuide/FileCheck.html#options | 
> > --implicit-check-not ]] :)
> 
> Wooow 😍 I didn't know about that one, I'll definitely update the test to use 
> it, thanks! 
> Based on the same docs, I would say it shouldn't be enough to mention it just 
> once. 

I'm re-rereading the docs and agree. Sounds like `--implicit-check-not` is the 
best option.

> For instance, I would expect to be able to write
> ```
> ! MSVC-NOT: should-only-come-after-X
> ! MSVC-SAME: X
> ```
> If the MSVC-NOT applies to the whole line, then lines with 'X 
> should-come-after-X' get rejected

I think that it //should// and //is// accepted. Example below:

**file.f90**
```lang=bash
! RUN: cat %S/test.f90 | FileCheck %s

! CHECK-LABEL: my-label
! CHECK-NOT: should-only-come-after-X
! CHECK-SAME: X
! CHECK-SAME: should-only-come-after-X
```

**test.f90**
```lang=bash
my-label X should-only-come-after-X
```
I copied the above into the Driver test dir and run like this:
```
$ bin/llvm-lit -va ../../flang/test/Driver/file.f90
-- Testing: 1 tests, 1 workers --
PASS: Flang :: Driver/file.f90 (1 of 1)

Testing Time: 0.03s
  Passed: 1
```

Does this agree with your experiments?

#filecheck-is-confusing :)


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

https://reviews.llvm.org/D126291

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


[PATCH] D125094: [ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records

2022-06-14 Thread Lucas Prates via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7625e01d6616: [ARM][Thumb] Command-line option to ensure 
AAPCS compliant Frame Records (authored by pratlucas).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125094

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp
  llvm/lib/Target/ARM/ARMCallingConv.td
  llvm/lib/Target/ARM/ARMFrameLowering.cpp
  llvm/lib/Target/ARM/ARMFrameLowering.h
  llvm/lib/Target/ARM/ARMMachineFunctionInfo.h
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
  llvm/lib/Target/ARM/ThumbRegisterInfo.cpp
  llvm/test/CodeGen/ARM/frame-chain-reserved-fp.ll
  llvm/test/CodeGen/ARM/frame-chain.ll
  llvm/test/CodeGen/Thumb/frame-access.ll
  llvm/test/CodeGen/Thumb/frame-chain-reserved-fp.ll
  llvm/test/CodeGen/Thumb/frame-chain.ll

Index: llvm/test/CodeGen/Thumb/frame-chain.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb/frame-chain.ll
@@ -0,0 +1,288 @@
+; RUN: llc -mtriple thumb-arm-none-eabi -filetype asm -o - %s -frame-pointer=all | FileCheck %s --check-prefixes=FP,LEAF-FP
+; RUN: llc -mtriple thumb-arm-none-eabi -filetype asm -o - %s -frame-pointer=all -mattr=+aapcs-frame-chain | FileCheck %s --check-prefixes=FP-AAPCS,LEAF-FP
+; RUN: llc -mtriple thumb-arm-none-eabi -filetype asm -o - %s -frame-pointer=all -mattr=+aapcs-frame-chain-leaf | FileCheck %s --check-prefixes=FP-AAPCS,LEAF-FP-AAPCS
+; RUN: llc -mtriple thumb-arm-none-eabi -filetype asm -o - %s -frame-pointer=non-leaf | FileCheck %s --check-prefixes=FP,LEAF-NOFP
+; RUN: llc -mtriple thumb-arm-none-eabi -filetype asm -o - %s -frame-pointer=non-leaf -mattr=+aapcs-frame-chain | FileCheck %s --check-prefixes=FP-AAPCS,LEAF-NOFP
+; RUN: llc -mtriple thumb-arm-none-eabi -filetype asm -o - %s -frame-pointer=non-leaf -mattr=+aapcs-frame-chain-leaf | FileCheck %s --check-prefixes=FP-AAPCS,LEAF-NOFP-AAPCS
+; RUN: llc -mtriple thumb-arm-none-eabi -filetype asm -o - %s -frame-pointer=none | FileCheck %s --check-prefixes=NOFP,LEAF-NOFP
+; RUN: llc -mtriple thumb-arm-none-eabi -filetype asm -o - %s -frame-pointer=none -mattr=+aapcs-frame-chain | FileCheck %s --check-prefixes=NOFP-AAPCS,LEAF-NOFP
+; RUN: llc -mtriple thumb-arm-none-eabi -filetype asm -o - %s -frame-pointer=none -mattr=+aapcs-frame-chain-leaf | FileCheck %s --check-prefixes=NOFP-AAPCS,LEAF-NOFP-AAPCS
+
+define dso_local noundef i32 @leaf(i32 noundef %0) {
+; LEAF-FP-LABEL: leaf:
+; LEAF-FP:   @ %bb.0:
+; LEAF-FP-NEXT:.pad #4
+; LEAF-FP-NEXT:sub sp, #4
+; LEAF-FP-NEXT:str r0, [sp]
+; LEAF-FP-NEXT:adds r0, r0, #4
+; LEAF-FP-NEXT:add sp, #4
+; LEAF-FP-NEXT:bx lr
+;
+; LEAF-FP-AAPCS-LABEL: leaf:
+; LEAF-FP-AAPCS:   @ %bb.0:
+; LEAF-FP-AAPCS-NEXT:.save {lr}
+; LEAF-FP-AAPCS-NEXT:push {lr}
+; LEAF-FP-AAPCS-NEXT:mov lr, r11
+; LEAF-FP-AAPCS-NEXT:.save {r11}
+; LEAF-FP-AAPCS-NEXT:push {lr}
+; LEAF-FP-AAPCS-NEXT:.setfp r11, sp
+; LEAF-FP-AAPCS-NEXT:mov r11, sp
+; LEAF-FP-AAPCS-NEXT:.pad #4
+; LEAF-FP-AAPCS-NEXT:sub sp, #4
+; LEAF-FP-AAPCS-NEXT:str r0, [sp]
+; LEAF-FP-AAPCS-NEXT:adds r0, r0, #4
+; LEAF-FP-AAPCS-NEXT:add sp, #4
+; LEAF-FP-AAPCS-NEXT:pop {r1}
+; LEAF-FP-AAPCS-NEXT:mov r11, r1
+; LEAF-FP-AAPCS-NEXT:pop {r1}
+; LEAF-FP-AAPCS-NEXT:bx r1
+;
+; LEAF-NOFP-LABEL: leaf:
+; LEAF-NOFP:   @ %bb.0:
+; LEAF-NOFP-NEXT:.pad #4
+; LEAF-NOFP-NEXT:sub sp, #4
+; LEAF-NOFP-NEXT:str r0, [sp]
+; LEAF-NOFP-NEXT:adds r0, r0, #4
+; LEAF-NOFP-NEXT:add sp, #4
+; LEAF-NOFP-NEXT:bx lr
+;
+; LEAF-NOFP-AAPCS-LABEL: leaf:
+; LEAF-NOFP-AAPCS:   @ %bb.0:
+; LEAF-NOFP-AAPCS-NEXT:.pad #4
+; LEAF-NOFP-AAPCS-NEXT:sub sp, #4
+; LEAF-NOFP-AAPCS-NEXT:str r0, [sp]
+; LEAF-NOFP-AAPCS-NEXT:adds r0, r0, #4
+; LEAF-NOFP-AAPCS-NEXT:add sp, #4
+; LEAF-NOFP-AAPCS-NEXT:bx lr
+  %2 = alloca i32, align 4
+  store i32 %0, i32* %2, align 4
+  %3 = load i32, i32* %2, align 4
+  %4 = add nsw i32 %3, 4
+  ret i32 %4
+}
+
+define dso_local noundef i32 @non_leaf(i32 noundef %0) {
+; FP-LABEL: non_leaf:
+; FP:   @ %bb.0:
+; FP-NEXT:.save {r7, lr}
+; FP-NEXT:push {r7, lr}
+; FP-NEXT:.setfp r7, sp
+; FP-NEXT:add r7, sp, #0
+; FP-NEXT:.pad #8
+; FP-NEXT:sub sp, #8
+; FP-NEXT:str r0, [sp, #4]
+; FP-NEXT:bl leaf
+; FP-NEXT:adds r0, r0, #1
+; FP-NEXT:add sp, #8
+; FP-NEXT:pop {r7}
+; FP-NEXT:pop {r1}
+; FP-NEXT:bx r1
+;
+; FP-AAPCS-LABEL: non_leaf:
+; FP-AAPCS:   @ %bb.0:
+; FP-AAPCS-NEXT:.save {lr}
+; FP-AAPCS-NEXT:push {lr}
+; FP-AAPCS-NEXT:mov lr, r11
+; FP-AAPCS-NEXT:.save {r11}
+; FP-AAPCS-NEXT:push {lr}
+; FP-AAP

[clang] 7625e01 - [ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records

2022-06-14 Thread Lucas Prates via cfe-commits

Author: Lucas Prates
Date: 2022-06-14T13:37:51+01:00
New Revision: 7625e01d661644a560884057755d48a0da8b77b4

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

LOG: [ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records

Currently the a AAPCS compliant frame record is not always created for
functions when it should. Although a consistent frame record might not
be required in some cases, there are still scenarios where applications
may want to make use of the call hierarchy made available trough it.

In order to enable the use of AAPCS compliant frame records whilst keep
backwards compatibility, this patch introduces a new command-line option
(`-mframe-chain=[none|aapcs|aapcs+leaf]`) for Aarch32 and Thumb backends.
The option allows users to explicitly select when to use it, and is also
useful to ensure the extra overhead introduced by the frame records is
only introduced when necessary, in particular for Thumb targets.

Reviewed By: efriedma

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

Added: 
llvm/test/CodeGen/ARM/frame-chain-reserved-fp.ll
llvm/test/CodeGen/ARM/frame-chain.ll
llvm/test/CodeGen/Thumb/frame-chain-reserved-fp.ll
llvm/test/CodeGen/Thumb/frame-chain.ll

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Arch/ARM.cpp
llvm/lib/Target/ARM/ARM.td
llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp
llvm/lib/Target/ARM/ARMCallingConv.td
llvm/lib/Target/ARM/ARMFrameLowering.cpp
llvm/lib/Target/ARM/ARMFrameLowering.h
llvm/lib/Target/ARM/ARMMachineFunctionInfo.h
llvm/lib/Target/ARM/ARMSubtarget.h
llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
llvm/lib/Target/ARM/ThumbRegisterInfo.cpp
llvm/test/CodeGen/Thumb/frame-access.ll

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5fa681f53819..b40cb1167388 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3478,7 +3478,9 @@ defm aapcs_bitfield_width : BoolOption<"f", 
"aapcs-bitfield-width",
   BothFlags<[NoXarchOption, CC1Option], " the AAPCS standard requirement 
stating that"
 " volatile bit-field width is dictated by the field container 
type. (ARM only).">>,
   Group;
-
+def mframe_chain : Joined<["-"], "mframe-chain=">,
+  Group, Values<"none,aapcs,aapcs+leaf">,
+  HelpText<"Select the frame chain model used to emit frame records (Arm 
only).">;
 def mgeneral_regs_only : Flag<["-"], "mgeneral-regs-only">, Group,
   HelpText<"Generate code which only uses the general purpose registers 
(AArch64/x86 only)">;
 def mfix_cmse_cve_2021_35465 : Flag<["-"], "mfix-cmse-cve-2021-35465">,

diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index dc6b35e39cfd..b79d1f00ea48 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -718,6 +718,15 @@ void arm::getARMTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
 }
   }
 
+  // Propagate frame-chain model selection
+  if (Arg *A = Args.getLastArg(options::OPT_mframe_chain)) {
+StringRef FrameChainOption = A->getValue();
+if (FrameChainOption.startswith("aapcs"))
+  Features.push_back("+aapcs-frame-chain");
+if (FrameChainOption == "aapcs+leaf")
+  Features.push_back("+aapcs-frame-chain-leaf");
+  }
+
   // CMSE: Check for target 8M (for -mcmse to be applicable) is performed 
later.
   if (Args.getLastArg(options::OPT_mcmse))
 Features.push_back("+8msecext");

diff  --git a/llvm/lib/Target/ARM/ARM.td b/llvm/lib/Target/ARM/ARM.td
index e8970b916a5f..48559a89a30a 100644
--- a/llvm/lib/Target/ARM/ARM.td
+++ b/llvm/lib/Target/ARM/ARM.td
@@ -546,6 +546,16 @@ def FeatureFixCortexA57AES1742098 : 
SubtargetFeature<"fix-cortex-a57-aes-1742098
   "FixCortexA57AES1742098", "true",
   "Work around Cortex-A57 Erratum 1742098 / Cortex-A72 Erratum 1655431 (AES)">;
 
+def FeatureAAPCSFrameChain : SubtargetFeature<"aapcs-frame-chain",
+  "CreateAAPCSFrameChain", "true",
+  "Create an AAPCS compliant frame 
chain">;
+
+def FeatureAAPCSFrameChainLeaf : SubtargetFeature<"aapcs-frame-chain-leaf",
+  "CreateAAPCSFrameChainLeaf", 
"true",
+  "Create an AAPCS compliant 
frame chain "
+  "for leaf functions",
+  [FeatureAAPCSFrameChain]>;
+
 
//===--===//
 // ARM architecture class
 //

diff  --git a/llvm/lib/Target/ARM/

[PATCH] D127201: [clang] Add tests for statement expression in initializers

2022-06-14 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! (The precommit CI failures appear to be unrelated to the changes in this 
patch.) Thanks for the additional test coverage!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127201

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


[PATCH] D126183: Implement soft reset of the diagnostics engine.

2022-06-14 Thread Tapasweni Pathak via Phabricator via cfe-commits
tapaswenipathak updated this revision to Diff 436750.
tapaswenipathak edited the summary of this revision.
tapaswenipathak added a comment.

Addresses review comment by @v.g.vassilev.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126183

Files:
  clang/include/clang/Basic/Diagnostic.h
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/test/Interpreter/error-recovery-pragmas.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Basic/DiagnosticTest.cpp

Index: clang/unittests/Basic/DiagnosticTest.cpp
===
--- clang/unittests/Basic/DiagnosticTest.cpp
+++ clang/unittests/Basic/DiagnosticTest.cpp
@@ -14,6 +14,15 @@
 using namespace llvm;
 using namespace clang;
 
+void clang::DiagnosticsTestHelper(DiagnosticsEngine &diag) {
+  unsigned delayedDiagID = 0U;
+
+  EXPECT_EQ(diag.DelayedDiagID, delayedDiagID);
+  EXPECT_FALSE(diag.DiagStates.empty());
+  EXPECT_TRUE(diag.DiagStatesByLoc.empty());
+  EXPECT_TRUE(diag.DiagStateOnPushStack.empty());
+}
+
 namespace {
 
 // Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
@@ -71,6 +80,32 @@
 EXPECT_EQ(Diags.getNumWarnings(), FatalsAsError);
   }
 }
+
+// Check that soft RESET works as intended
+TEST(DiagnosticTest, softReset) {
+  DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
+  new IgnoringDiagConsumer());
+
+  unsigned numWarnings = 0U, numErrors = 0U;
+
+  Diags.Reset(true);
+  // Check For ErrorOccurred and TrapNumErrorsOccurred
+  EXPECT_FALSE(Diags.hasErrorOccurred());
+  EXPECT_FALSE(Diags.hasFatalErrorOccurred());
+  EXPECT_FALSE(Diags.hasUncompilableErrorOccurred());
+  // Check for UnrecoverableErrorOccurred and TrapNumUnrecoverableErrorsOccurred
+  EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
+
+  EXPECT_EQ(Diags.getNumWarnings(), numWarnings);
+  EXPECT_EQ(Diags.getNumErrors(), numErrors);
+
+  // Check for private variables of DiagnosticsEngine differentiating soft reset
+  DiagnosticsTestHelper(Diags);
+
+  EXPECT_FALSE(Diags.isDiagnosticInFlight());
+  EXPECT_TRUE(Diags.isLastDiagnosticIgnored());
+}
+
 TEST(DiagnosticTest, diagnosticError) {
   DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
   new IgnoringDiagConsumer());
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -49,6 +49,23 @@
   exit(GenCrashDiag ? 70 : 1);
 }
 
+// If we are running with -verify a reported has to be returned as unsuccess.
+// This is relevant especially for the test suite.
+static int checkDiagErrors(const clang::CompilerInstance *CI) {
+  unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
+  if (CI->getDiagnosticOpts().VerifyDiagnostics) {
+// If there was an error that came from the verifier we must return 1 as
+// an exit code for the process. This will make the test fail as expected.
+clang::DiagnosticConsumer *Client = CI->getDiagnostics().getClient();
+Client->EndSourceFile();
+Errs = Client->getNumErrors();
+
+// The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
+Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
+  }
+  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+}
+
 llvm::ExitOnError ExitOnErr;
 int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
@@ -104,5 +121,5 @@
 
   llvm::llvm_shutdown();
 
-  return 0;
+  return checkDiagErrors(Interp->getCompilerInstance());
 }
Index: clang/test/Interpreter/error-recovery-pragmas.cpp
===
--- /dev/null
+++ clang/test/Interpreter/error-recovery-pragmas.cpp
@@ -0,0 +1,7 @@
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+// Reset should not delete #pragmas
+error; // expected-error {{a type specifier is required for all declarations}}
+void no_diag_multichar(void) { char c = (char)'ab'; }
+quit
Index: clang/lib/Interpreter/IncrementalParser.cpp
===
--- clang/lib/Interpreter/IncrementalParser.cpp
+++ clang/lib/Interpreter/IncrementalParser.cpp
@@ -197,8 +197,7 @@
   }
 }
 
-// FIXME: Do not reset the pragma handlers.
-Diags.Reset();
+Diags.Reset(/*soft=*/true);
 return llvm::make_error("Parsing failed.",
std::error_code());
   }
Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -130,7 +130,7 @@
   return true;
 }
 
-void DiagnosticsEngine::Reset() {
+void Diagnos

[PATCH] D126061: [clang] Reject non-declaration C++11 attributes on declarations

2022-06-14 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked 11 inline comments as done.
mboehme added a comment.

In D126061#3581350 , @aaron.ballman 
wrote:

> Only thing left for me are the nits I pointed out in the last review, 
> otherwise I think this is all set.

Thanks for the quick turnaround!

> Giving my LG because I don't think we need another round of review for those 
> nits unless you want it

Just two things I'd appreciate a quick confirmation on:

- My question on `isAlignasAttribute()`
- Feedback on whether you think my refactoring of the complex boolean 
expression makes sense




Comment at: clang/include/clang/Basic/AttributeCommonInfo.h:153
 // FIXME: Use a better mechanism to determine this.
+// We use this in `isCXX11Attribute` below, so it _should_ only return
+// true for the `alignas` spelling, but it currently also returns true

aaron.ballman wrote:
> Now that C23 has attributes, it's also not clear whether `_Alignas` will be 
> handled slightly differently in the future as an attribute rather than a 
> declaration specifier as happened with `_Noreturn` for C23. So agreed this is 
> a tricky area.
Thanks for pointing this out! Is there anything specific I should add to the 
code comment, or is your comment just for general awareness?



Comment at: clang/include/clang/Sema/DeclSpec.h:1916
+  /// declaration, i.e. `x` and `y` in this case.
+  Declarator(const DeclSpec &ds, const ParsedAttributesView &DeclarationAttrs,
+ DeclaratorContext C)

aaron.ballman wrote:
> I know it's pre-existing code, but since you're updating the parameters and 
> adding some great comments, can you rename `ds` to `DS` per coding style 
> guides?
No problem -- done!



Comment at: clang/include/clang/Sema/DeclSpec.h:1928-1930
+assert(llvm::all_of(DeclarationAttrs, [](const ParsedAttr &AL) {
+  return AL.isStandardAttributeSyntax();
+}));

aaron.ballman wrote:
> Can you add an `&& "and this is what the assert is testing for"` message here 
> so when the assertion fails there's more details as to what went sideways?
Good point -- done.



Comment at: clang/include/clang/Sema/ParsedAttr.h:1126
+/// `Result`. Sets `Result.Range` to the combined range of `First` and 
`Second`.
+void ConcatenateAttributes(ParsedAttributes &First, ParsedAttributes &Second,
+   ParsedAttributes &Result);

aaron.ballman wrote:
> I think `Concatenate` implies that `First` and `Second` are untouched, but 
> that's not really the case here. Perhaps `takeAndConcatenateAll()` or 
> something along those lines instead? Also, the function should start with a 
> lowercase letter per the usual coding style rules.
Good point. Done, with a slightly different name -- WDYT?



Comment at: clang/lib/Parse/ParseStmt.cpp:229
   default: {
+auto isStmtAttr = [](ParsedAttr &Attr) { return Attr.isStmtAttr(); };
 if ((getLangOpts().CPlusPlus || getLangOpts().MicrosoftExt ||

aaron.ballman wrote:
> Coding style nit.
Done.



Comment at: clang/lib/Parse/ParseStmt.cpp:230-237
 if ((getLangOpts().CPlusPlus || getLangOpts().MicrosoftExt ||
  (StmtCtx & ParsedStmtContext::AllowDeclarationsInC) !=
  ParsedStmtContext()) &&
 ((GNUAttributeLoc.isValid() &&
-  !(!Attrs.empty() &&
-llvm::all_of(
-Attrs, [](ParsedAttr &Attr) { return Attr.isStmtAttr(); }))) ||
+  !(!(CXX11Attrs.empty() && GNUAttrs.empty()) &&
+llvm::all_of(CXX11Attrs, isStmtAttr) &&
+llvm::all_of(GNUAttrs, isStmtAttr))) ||

aaron.ballman wrote:
> The logic is correct here, but this predicate has gotten really difficult to 
> understand. If you wanted to split some of those conditions out into named 
> variables for clarity, I would not be sad (but I also don't insist either).
Yes, this is confusing. I've factored out some variables that I hope make this 
more readable.

By the way, it might look as if `GNUAttributeLoc.isValid()` implies 
`HaveAttributes` and that the latter is therefore redundant, but this isn’t 
actually true if we failed to parse the GNU attribute. Removing the 
`HaveAttributes` makes some tests fail, e.g. line 78 of 
clang/test/Parser/stmt-attributes.c.



Comment at: clang/lib/Parse/ParseStmt.cpp:248-251
+  if (CXX11Attrs.Range.getBegin().isValid())
+DeclStart = CXX11Attrs.Range.getBegin();
+  else if (GNUAttrs.Range.getBegin().isValid())
+DeclStart = GNUAttrs.Range.getBegin();

aaron.ballman wrote:
> Do CXX attributes always precede GNU ones, or do we need to do a source 
> location comparison here to see which location is lexically earlier?
Yes, we can rely on this being the case. This function is called from only one 
place where both CXX11Attrs and GNUAttrs can po

[clang] 6a6484c - [OpenMP] Fix offload packager not writing to temps correctly

2022-06-14 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-06-14T09:16:28-04:00
New Revision: 6a6484c666ed037f20126c4275e70b02807e09f8

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

LOG: [OpenMP] Fix offload packager not writing to temps correctly

The offloading packager doesn't have a normal offloading kind. This
would result in its output being sent to the executable name when in
save-temps mode. This would then get overwritten by the actual output.
This patch adds specific checks to make sure that it gets the correct
name.

Reviewed By: tra

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

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/test/Driver/openmp-offload-gpu-new.c

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 70816def4b3fc..7b6e442d7801a 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5416,8 +5416,9 @@ InputInfoList Driver::BuildJobsForActionNoCache(
 // action.
 std::string OffloadingPrefix = Action::GetOffloadingFileNamePrefix(
 A->getOffloadingDeviceKind(), TC->getTriple().normalize(),
-/*CreatePrefixForHost=*/!!A->getOffloadingHostActiveKinds() &&
-!AtTopLevel);
+/*CreatePrefixForHost=*/isa(A) ||
+!(A->getOffloadingHostActiveKinds() == Action::OFK_None ||
+  AtTopLevel));
 if (isa(JA)) {
   if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
 BaseInput = FinalOutput->getValue();
@@ -5654,7 +5655,8 @@ const char *Driver::GetNamedOutputPath(Compilation &C, 
const JobAction &JA,
   bool IsHIPNoRDC = JA.getOffloadingDeviceKind() == Action::OFK_HIP &&
 !C.getArgs().hasFlag(options::OPT_fgpu_rdc,
  options::OPT_fno_gpu_rdc, false);
-  if (IsHIPNoRDC) {
+  bool UseOutExtension = IsHIPNoRDC || isa(JA);
+  if (UseOutExtension) {
 Output = BaseName;
 llvm::sys::path::replace_extension(Output, "");
   }
@@ -5663,7 +5665,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, 
const JobAction &JA,
 Output += "-";
 Output.append(BoundArch);
   }
-  if (IsHIPNoRDC)
+  if (UseOutExtension)
 Output += ".out";
   NamedOutput = C.getArgs().MakeArgString(Output.c_str());
 }

diff  --git a/clang/test/Driver/openmp-offload-gpu-new.c 
b/clang/test/Driver/openmp-offload-gpu-new.c
index d1bd497f65ff4..8eb197af1fd41 100644
--- a/clang/test/Driver/openmp-offload-gpu-new.c
+++ b/clang/test/Driver/openmp-offload-gpu-new.c
@@ -40,13 +40,16 @@
 // CHECK-PHASES: 14: clang-linker-wrapper, {13}, image, (host-openmp)
 
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda 
-Xopenmp-target=nvptx64-nvidia-cuda -march=sm_52 -nogpulib %s 2>&1 | FileCheck 
%s --check-prefix=CHECK-BINDINGS
-// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[INPUT:.*]]"], output: "[[HOST_BC:.*]]"
-// CHECK-BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]", 
"[[HOST_BC]]"], output: "[[DEVICE_BC:.*]]"
-// CHECK-BINDINGS: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: 
["[[DEVICE_BC]]"], output: "[[DEVICE_OBJ:.*]]"
-// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Packager", inputs: 
["[[DEVICE_OBJ]]"], output: "[[BINARY:.*]]"
-// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[HOST_BC]]", "[[BINARY]]"], output: "[[HOST_OBJ:.*]]"
+// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[INPUT:.+]]"], output: "[[HOST_BC:.+]]"
+// CHECK-BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]", 
"[[HOST_BC]]"], output: "[[DEVICE_BC:.+]]"
+// CHECK-BINDINGS: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: 
["[[DEVICE_BC]]"], output: "[[DEVICE_OBJ:.+]]"
+// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Packager", inputs: 
["[[DEVICE_OBJ]]"], output: "[[BINARY:.+.out]]"
+// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[HOST_BC]]", "[[BINARY]]"], output: "[[HOST_OBJ:.+]]"
 // CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: 
["[[HOST_OBJ]]"], output: "a.out"
 
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda 
-Xopenmp-target=nvptx64-nvidia-cuda -march=sm_52 -nogpulib -save-temps %s 2>&1 
| FileCheck %s --check-prefix=CHECK-TEMP-BINDINGS
+// CHECK-TEMP-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Packager", 
inputs: ["[[DEVICE_OBJ:.+]]"], output: "[[BINARY:.+.out]]"
+
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda --offload-arch=sm_52 
--offload-arch=sm

[PATCH] D127673: [OpenMP] Fix offload packager not writing to temps correctly

2022-06-14 Thread Joseph Huber via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6a6484c666ed: [OpenMP] Fix offload packager not writing to 
temps correctly (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127673

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/openmp-offload-gpu-new.c


Index: clang/test/Driver/openmp-offload-gpu-new.c
===
--- clang/test/Driver/openmp-offload-gpu-new.c
+++ clang/test/Driver/openmp-offload-gpu-new.c
@@ -40,13 +40,16 @@
 // CHECK-PHASES: 14: clang-linker-wrapper, {13}, image, (host-openmp)
 
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda 
-Xopenmp-target=nvptx64-nvidia-cuda -march=sm_52 -nogpulib %s 2>&1 | FileCheck 
%s --check-prefix=CHECK-BINDINGS
-// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[INPUT:.*]]"], output: "[[HOST_BC:.*]]"
-// CHECK-BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]", 
"[[HOST_BC]]"], output: "[[DEVICE_BC:.*]]"
-// CHECK-BINDINGS: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: 
["[[DEVICE_BC]]"], output: "[[DEVICE_OBJ:.*]]"
-// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Packager", inputs: 
["[[DEVICE_OBJ]]"], output: "[[BINARY:.*]]"
-// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[HOST_BC]]", "[[BINARY]]"], output: "[[HOST_OBJ:.*]]"
+// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[INPUT:.+]]"], output: "[[HOST_BC:.+]]"
+// CHECK-BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]", 
"[[HOST_BC]]"], output: "[[DEVICE_BC:.+]]"
+// CHECK-BINDINGS: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: 
["[[DEVICE_BC]]"], output: "[[DEVICE_OBJ:.+]]"
+// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Packager", inputs: 
["[[DEVICE_OBJ]]"], output: "[[BINARY:.+.out]]"
+// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[HOST_BC]]", "[[BINARY]]"], output: "[[HOST_OBJ:.+]]"
 // CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: 
["[[HOST_OBJ]]"], output: "a.out"
 
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda 
-Xopenmp-target=nvptx64-nvidia-cuda -march=sm_52 -nogpulib -save-temps %s 2>&1 
| FileCheck %s --check-prefix=CHECK-TEMP-BINDINGS
+// CHECK-TEMP-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Packager", 
inputs: ["[[DEVICE_OBJ:.+]]"], output: "[[BINARY:.+.out]]"
+
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings 
-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda --offload-arch=sm_52 
--offload-arch=sm_70 -nogpulib %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-ARCH-BINDINGS
 // CHECK-ARCH-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: 
["[[INPUT:.*]]"], output: "[[HOST_BC:.*]]"
 // CHECK-ARCH-BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]", 
"[[HOST_BC]]"], output: "[[DEVICE_BC_SM_52:.*]]"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5416,8 +5416,9 @@
 // action.
 std::string OffloadingPrefix = Action::GetOffloadingFileNamePrefix(
 A->getOffloadingDeviceKind(), TC->getTriple().normalize(),
-/*CreatePrefixForHost=*/!!A->getOffloadingHostActiveKinds() &&
-!AtTopLevel);
+/*CreatePrefixForHost=*/isa(A) ||
+!(A->getOffloadingHostActiveKinds() == Action::OFK_None ||
+  AtTopLevel));
 if (isa(JA)) {
   if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
 BaseInput = FinalOutput->getValue();
@@ -5654,7 +5655,8 @@
   bool IsHIPNoRDC = JA.getOffloadingDeviceKind() == Action::OFK_HIP &&
 !C.getArgs().hasFlag(options::OPT_fgpu_rdc,
  options::OPT_fno_gpu_rdc, false);
-  if (IsHIPNoRDC) {
+  bool UseOutExtension = IsHIPNoRDC || isa(JA);
+  if (UseOutExtension) {
 Output = BaseName;
 llvm::sys::path::replace_extension(Output, "");
   }
@@ -5663,7 +5665,7 @@
 Output += "-";
 Output.append(BoundArch);
   }
-  if (IsHIPNoRDC)
+  if (UseOutExtension)
 Output += ".out";
   NamedOutput = C.getArgs().MakeArgString(Output.c_str());
 }


Index: clang/test/Driver/openmp-offload-gpu-new.c
===
--- clang/test/Driver/openmp-offload-gpu-new.c
+++ clang/test/Driver/openmp-offload-gpu-new.c
@@ -40,13 +40,16 @@
 // CHECK-PHASES: 14: clang-linker-wrapper, {13}, image, (host-openmp)
 
 // RUN:   %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fop

[PATCH] D111548: [Clang] Add the `annotate_type` attribute

2022-06-14 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 436764.
mboehme marked an inline comment as done.
mboehme added a comment.

Fixed syntax error in ReleaseNotes.rst.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111548

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/attr-annotate-type.c
  clang/test/CodeGenCXX/annotate-type.cpp
  clang/test/Sema/annotate-type.c
  clang/test/SemaCXX/annotate-type.cpp
  clang/unittests/AST/AttrTest.cpp

Index: clang/unittests/AST/AttrTest.cpp
===
--- clang/unittests/AST/AttrTest.cpp
+++ clang/unittests/AST/AttrTest.cpp
@@ -7,7 +7,10 @@
 //===--===//
 
 #include "clang/AST/Attr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/AttrKinds.h"
+#include "clang/Tooling/Tooling.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -15,10 +18,154 @@
 
 namespace {
 
+using clang::ast_matchers::constantExpr;
+using clang::ast_matchers::equals;
+using clang::ast_matchers::functionDecl;
+using clang::ast_matchers::has;
+using clang::ast_matchers::hasDescendant;
+using clang::ast_matchers::hasName;
+using clang::ast_matchers::integerLiteral;
+using clang::ast_matchers::match;
+using clang::ast_matchers::selectFirst;
+using clang::ast_matchers::stringLiteral;
+using clang::ast_matchers::varDecl;
+using clang::tooling::buildASTFromCode;
+using clang::tooling::buildASTFromCodeWithArgs;
+
 TEST(Attr, Doc) {
   EXPECT_THAT(Attr::getDocumentation(attr::Used).str(),
   testing::HasSubstr("The compiler must emit the definition even "
  "if it appears to be unused"));
 }
 
+const FunctionDecl *getFunctionNode(ASTUnit *AST, const std::string &Name) {
+  auto Result =
+  match(functionDecl(hasName(Name)).bind("fn"), AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("fn");
+}
+
+const VarDecl *getVariableNode(ASTUnit *AST, const std::string &Name) {
+  auto Result = match(varDecl(hasName(Name)).bind("var"), AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("var");
+}
+
+template 
+void AssertAnnotatedAs(TypeLoc TL, llvm::StringRef annotation,
+   ModifiedTypeLoc &ModifiedTL,
+   const AnnotateTypeAttr **AnnotateOut = nullptr) {
+  const auto AttributedTL = TL.getAs();
+  ASSERT_FALSE(AttributedTL.isNull());
+  ModifiedTL = AttributedTL.getModifiedLoc().getAs();
+  ASSERT_TRUE(ModifiedTL);
+
+  ASSERT_NE(AttributedTL.getAttr(), nullptr);
+  const auto *Annotate = dyn_cast(AttributedTL.getAttr());
+  ASSERT_NE(Annotate, nullptr);
+  EXPECT_EQ(Annotate->getAnnotation(), annotation);
+  if (AnnotateOut) {
+*AnnotateOut = Annotate;
+  }
+}
+
+TEST(Attr, AnnotateType) {
+
+  // Test that the AnnotateType attribute shows up in the right places and that
+  // it stores its arguments correctly.
+
+  auto AST = buildASTFromCode(R"cpp(
+void f(int* [[clang::annotate_type("foo", "arg1", 2)]] *,
+   int [[clang::annotate_type("bar")]]);
+
+int [[clang::annotate_type("int")]] * [[clang::annotate_type("ptr")]]
+  array[10] [[clang::annotate_type("arr")]];
+
+void (* [[clang::annotate_type("funcptr")]] fp)(void);
+
+struct S { int mem; };
+int [[clang::annotate_type("int")]]
+S::* [[clang::annotate_type("ptr_to_mem")]] ptr_to_member = &S::mem;
+  )cpp");
+
+  {
+const FunctionDecl *Func = getFunctionNode(AST.get(), "f");
+
+// First parameter.
+const auto PointerTL = Func->getParamDecl(0)
+   ->getTypeSourceInfo()
+   ->getTypeLoc()
+   .getAs();
+ASSERT_FALSE(PointerTL.isNull());
+PointerTypeLoc PointerPointerTL;
+const AnnotateTypeAttr *Annotate;
+AssertAnnotatedAs(PointerTL.getPointeeLoc(), "foo", PointerPointerTL,
+  &Annotate);
+
+EXPECT_EQ(Annotate->args_size(), 2);
+const auto *StringLit = selectFirst(
+"str", match(constantExpr(hasDescendant(stringLiteral().bind("str"))),
+ *Annotate->args_begin()[0], AST->getASTContext()));
+ASSERT_NE(StringLit, nullptr);
+EXPECT_EQ(StringLit->getString(), "arg1");
+EXPECT_EQ(match(constantExpr(has(integerLiteral(equals(2)).bind("int"))),
+*Annotate->args_begin()[1], AST->getASTContext())
+  .size(),
+  1);
+
+// Second parameter.
+BuiltinTypeLoc IntTL;
+AssertAnnotatedAs(Func->getParamDecl(1)->

[PATCH] D111548: [Clang] Add the `annotate_type` attribute

2022-06-14 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked an inline comment as done.
mboehme added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:349
 
+- Added the `clang::annotate_type` attribute, which can be used to add
+  annotations to types (see documentation for details).

aaron.ballman wrote:
> 
Thanks for catching -- fixed. (I'm too used to Markdown syntax...)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111548

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


[PATCH] D126534: [analyzer] Deadstore static analysis: Fix false positive on C++17 assignments

2022-06-14 Thread Fred Tingaud via Phabricator via cfe-commits
frederic-tingaud-sonarsource updated this revision to Diff 436766.
frederic-tingaud-sonarsource added a comment.

Update diagnostic location to highlight the whole content of the initialization.


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

https://reviews.llvm.org/D126534

Files:
  clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
  clang/test/Analysis/dead-stores.cpp


Index: clang/test/Analysis/dead-stores.cpp
===
--- clang/test/Analysis/dead-stores.cpp
+++ clang/test/Analysis/dead-stores.cpp
@@ -11,6 +11,10 @@
 // RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -fblocks -std=c++11   
 \
 // RUN:  -analyzer-checker=deadcode.DeadStores -Wno-unreachable-code   
 \
 // RUN:  -verify=non-nested,nested %s
+//
+// RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -fblocks -std=c++17   
 \
+// RUN:  -analyzer-checker=deadcode.DeadStores -Wno-unreachable-code   
 \
+// RUN:  -verify=non-nested,nested %s
 
 
//===--===//
 // Basic dead store checking (but in C++ mode).
@@ -52,6 +56,18 @@
   return x;
 }
 
+class TestConstructor {
+public:
+  TestConstructor(int &y);
+};
+void copy(int x) {
+  // All these calls might have side effects in the opaque constructor
+  TestConstructor tc1 = x;// no-warning potential side 
effects
+  TestConstructor tc2 = TestConstructor(x);   // no-warning potential side 
effects
+  TestConstructor tc3 = (TestConstructor(x)); // no-warning potential side 
effects
+  TestConstructor tc4 = (TestConstructor)(x); // no-warning potential side 
effects
+}
+
 
//===--===//
 // Dead store checking involving CXXTemporaryExprs
 
//===--===//
Index: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -103,8 +103,8 @@
 static const Expr *
 LookThroughTransitiveAssignmentsAndCommaOperators(const Expr *Ex) {
   while (Ex) {
-const BinaryOperator *BO =
-  dyn_cast(Ex->IgnoreParenCasts());
+Ex = Ex->IgnoreParenCasts();
+const BinaryOperator *BO = dyn_cast(Ex);
 if (!BO)
   break;
 BinaryOperatorKind Op = BO->getOpcode();
@@ -331,8 +331,7 @@
   // Special case: check for assigning null to a pointer.
   //  This is a common form of defensive programming.
   const Expr *RHS =
-LookThroughTransitiveAssignmentsAndCommaOperators(B->getRHS());
-  RHS = RHS->IgnoreParenCasts();
+  LookThroughTransitiveAssignmentsAndCommaOperators(B->getRHS());
 
   QualType T = VD->getType();
   if (T.isVolatileQualified())
@@ -415,8 +414,7 @@
   if (isConstant(E))
 return;
 
-  if (const DeclRefExpr *DRE =
-  dyn_cast(E->IgnoreParenCasts()))
+  if (const DeclRefExpr *DRE = dyn_cast(E))
 if (const VarDecl *VD = dyn_cast(DRE->getDecl())) {
   // Special case: check for initialization from constant
   //  variables.
@@ -438,7 +436,7 @@
 
   PathDiagnosticLocation Loc =
 PathDiagnosticLocation::create(V, BR.getSourceManager());
-  Report(V, DeadInit, Loc, E->getSourceRange());
+  Report(V, DeadInit, Loc, V->getInit()->getSourceRange());
 }
   }
 }
@@ -450,8 +448,9 @@
   bool isConstant(const InitListExpr *Candidate) const {
 // We consider init list to be constant if each member of the list can be
 // interpreted as constant.
-return llvm::all_of(Candidate->inits(),
-[this](const Expr *Init) { return isConstant(Init); });
+return llvm::all_of(Candidate->inits(), [this](const Expr *Init) {
+  return isConstant(Init->IgnoreParenCasts());
+});
   }
 
   /// Return true if the given expression can be interpreted as constant
@@ -461,7 +460,7 @@
   return true;
 
 // We should also allow defensive initialization of structs, i.e. { 0 }
-if (const auto *ILE = dyn_cast(E->IgnoreParenCasts())) {
+if (const auto *ILE = dyn_cast(E)) {
   return isConstant(ILE);
 }
 


Index: clang/test/Analysis/dead-stores.cpp
===
--- clang/test/Analysis/dead-stores.cpp
+++ clang/test/Analysis/dead-stores.cpp
@@ -11,6 +11,10 @@
 // RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -fblocks -std=c++11\
 // RUN:  -analyzer-checker=deadcode.DeadStores -Wno-unreachable-code\
 // RUN:  -verify=non-nested,nested %s
+//
+// RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -fblocks -s

[PATCH] D125094: [ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records

2022-06-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

@pratlucas I'm seeing errors on my EXPENSIVE_CHECKS builds - please can you 
take a look?

  Command Output (stdout):
  --
  $ ":" "RUN: at line 1"
  $ "e:\llvm\ninja\bin\llc.exe" "-mtriple" "thumb-arm-none-eabi" "-filetype" 
"asm" "-o" "-" "E:\llvm\llvm-project\llvm\test\CodeGen\Thumb\frame-chain.ll" 
"-frame-pointer=all"
  # command stderr:
  
  # After Prologue/Epilogue Insertion & Frame Finalization
  # Machine code for function required_fp: NoPHIs, TracksLiveness, NoVRegs, 
TiedOpsRewritten, TracksDebugUserValues
  Frame Objects:
fi#0: size=4, align=4, at location [SP-20]
fi#1: size=4, align=4, at location [SP-24]
fi#2: size=4, align=8, at location [SP-32]
fi#3: size=8, align=8, at location [SP-40]
fi#4: variable sized, align=1, at location [SP-40]
fi#5: size=4, align=4, at location [SP-4]
fi#6: size=4, align=4, at location [SP-8]
fi#7: size=4, align=4, at location [SP-12]
fi#8: size=4, align=4, at location [SP-16]
  Function Live Ins: $r0, $r1
  
  bb.0 (%ir-block.2):
liveins: $r0, $r1, $r4, $lr
frame-setup tPUSH 14, $noreg, killed $r4, killed $r6, killed $r7, killed 
$lr, implicit-def $sp, implicit $sp
frame-setup CFI_INSTRUCTION def_cfa_offset 16
frame-setup CFI_INSTRUCTION offset $lr, -4
frame-setup CFI_INSTRUCTION offset $r7, -8
frame-setup CFI_INSTRUCTION offset $r6, -12
frame-setup CFI_INSTRUCTION offset $r4, -16
$r7 = frame-setup tADDrSPi $sp, 2, 14, $noreg
frame-setup CFI_INSTRUCTION def_cfa $r7, 8
$sp = frame-setup tSUBspi $sp(tied-def 0), 6, 14, $noreg
$r6 = tMOVr $sp, 14, $noreg
$r2 = tMOVr killed $r6, 14, $noreg
tSTRi killed renamable $r1, renamable $r2, 4, 14, $noreg :: (store (s32) 
into %ir.4)
tSTRi renamable $r0, renamable $r2, 5, 14, $noreg :: (store (s32) into 
%ir.3)
renamable $r1 = COPY $sp
tSTRi killed renamable $r1, renamable $r2, 2, 14, $noreg :: (store (s32) 
into %ir.5, align 8)
renamable $r1, dead $cpsr = tLSLri renamable $r0, 2, 14, $noreg
renamable $r1, dead $cpsr = nuw tADDi3 killed renamable $r1, 7, 14, $noreg
renamable $r3, dead $cpsr = tMOVi8 7, 14, $noreg
renamable $r1, dead $cpsr = tBIC killed renamable $r1(tied-def 0), killed 
renamable $r3, 14, $noreg
renamable $r3 = COPY $sp
renamable $r1, dead $cpsr = tSUBrr killed renamable $r3, killed renamable 
$r1, 14, $noreg
$sp = COPY killed renamable $r1
renamable $r1, dead $cpsr = tMOVi8 0, 14, $noreg
tSTRi killed renamable $r1, $r6, 1, 14, $noreg :: (store (s32) into %ir.6 + 
4, basealign 8)
tSTRi killed renamable $r0, killed renamable $r2, 0, 14, $noreg :: (store 
(s32) into %ir.6, align 8)
$r4, $cpsr = frame-destroy tSUBi3 killed $r7, 7, 14, $noreg
$r4, $cpsr = frame-destroy tSUBi8 $r4(tied-def 0), 1, 14, $noreg
$sp = frame-destroy tMOVr $r4, 14, $noreg
frame-destroy tPOP 14, $noreg, def $r4, def $r6, def $r7, implicit-def $sp, 
implicit $sp
frame-destroy tPOP 14, $noreg, def $r0, implicit-def $sp, implicit $sp
$lr = frame-destroy tMOVr killed $r0, 14, $noreg
tBX_RET 14, $noreg
  
  # End machine code for function required_fp.
  
  *** Bad machine code: Non-flag-setting Thumb1 mov is v6-only ***
  - function:required_fp
  - basic block: %bb.0  (0x166ad7b18e8)
  - instruction: $r2 = tMOVr killed $r6, 14, $noreg
  LLVM ERROR: Found 1 machine code errors.
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125094

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


[PATCH] D127742: [analyzer][NFC] Prefer using isa<> instead getAs<> in conditions

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: martong, NoQ.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Depends on D125709 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127742

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
  clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/GTestChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  
clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
  clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  clang/lib/StaticAnalyzer/Core/ProgramState.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/Store.cpp

Index: clang/lib/StaticAnalyzer/Core/Store.cpp
===
--- clang/lib/StaticAnalyzer/Core/Store.cpp
+++ clang/lib/StaticAnalyzer/Core/Store.cpp
@@ -459,10 +459,10 @@
   // FIXME: For absolute pointer addresses, we just return that value back as
   //  well, although in reality we should return the offset added to that
   //  value. See also the similar FIXME in getLValueFieldOrIvar().
-  if (Base.isUnknownOrUndef() || Base.getAs())
+  if (Base.isUnknownOrUndef() || isa(Base))
 return Base;
 
-  if (Base.getAs())
+  if (isa(Base))
 return UnknownVal();
 
   const SubRegion *BaseRegion =
@@ -488,7 +488,7 @@
 
   SVal BaseIdx = ElemR->getIndex();
 
-  if (!BaseIdx.getAs())
+  if (!isa(BaseIdx))
 return UnknownVal();
 
   const llvm::APSInt &BaseIdxI =
@@ -497,7 +497,7 @@
   // Only allow non-integer offsets if the base region has no offset itself.
   // FIXME: This is a somewhat arbitrary restriction. We should be using
   // SValBuilder here to add the two offsets without checking their types.
-  if (!Offset.getAs()) {
+  if (!isa(Offset)) {
 if (isa(BaseRegion->StripCasts()))
   return UnknownVal();
 
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -886,7 +886,7 @@
 // This must come after the test if the RHS is a symbol, which is used to
 // build constraints. The address of any non-symbolic region is guaranteed
 // to be non-NULL, as is any label.
-assert(rhs.getAs() || rhs.getAs());
+assert((isa(rhs)));
 if (lhs.isZeroConstant()) {
   switch (op) {
   default:
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -462,8 +462,7 @@
   if (lhs.isUnknown() || rhs.isUnknown())
 return UnknownVal();
 
-  if (lhs.getAs() ||
-  rhs.getAs()) {
+  if (isa(lhs) || isa(rhs)) {
 return UnknownVal();
   }
 
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ clang/lib/StaticAnalyzer

[PATCH] D125094: [ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records

2022-06-14 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas added a comment.

The newly added `frame-chain.ll` test uncovered an issue with an invalid use of 
the tMOVr instruction, which is only available from V6 onwards. The failure was 
captured by a buildbot with expensive checks enabled.
The issue is unrelated to the codegen changes from this patch, and still 
happens when compiling the same IR code if the changes are reverted.
Given the above, I've updated the test to use thumbv6m while the issue is not 
resolved: rGcbcce82ef6b5 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125094

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


[PATCH] D125094: [ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records

2022-06-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Cheers! Are you looking at a fix or please can you raise a ticket?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125094

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


[PATCH] D127518: [Diagnostics] Fix inconsistent shift-overflow warnings in C++20

2022-06-14 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.






























































[PATCH] D127518: [Diagnostics] Fix inconsistent shift-overflow warnings in C++20

2022-06-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

LGTM! Please add a release note about the issue that was fixed when landing.


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

https://reviews.llvm.org/D127518

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


[PATCH] D125094: [ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records

2022-06-14 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas added a comment.

@RKSimon I was writting my comment above just before I saw your message, lucky 
they went in in the correct order :)
I'm tracking down the source of the invalid `tMOVr` and I'll raise a ticket 
with the details.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125094

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


[PATCH] D125749: [analyzer][NFC] Introduce SVal::isa

2022-06-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal abandoned this revision.
steakhal added a comment.

We don't have the consensus to make me confident in landing this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125749

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


[PATCH] D127454: [OpenMP] Initial parsing and sema for 'parallel masked' construct

2022-06-14 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang-c/Index.h:2641
*/
-  CXCursor_TranslationUnit = 300,
+  CXCursor_TranslationUnit = 350,
 

Does this change affect anything else in the compiler?



Comment at: clang/include/clang/AST/StmtOpenMP.h:2315
+///
+class OMPParallelMaskedDirective : public OMPExecutableDirective {
+  friend class ASTStmtReader;

`final`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127454

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


[PATCH] D127460: Rename GCCBuiltin into ClangBuiltin

2022-06-14 Thread Guillaume Gomez via Phabricator via cfe-commits
GuillaumeGomez updated this revision to Diff 436774.
GuillaumeGomez added a comment.

Update #define as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127460

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/IR/Intrinsics.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/include/llvm/IR/IntrinsicsAMDGPU.td
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/include/llvm/IR/IntrinsicsBPF.td
  llvm/include/llvm/IR/IntrinsicsHexagon.td
  llvm/include/llvm/IR/IntrinsicsMips.td
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/include/llvm/IR/IntrinsicsSystemZ.td
  llvm/include/llvm/IR/IntrinsicsVE.td
  llvm/include/llvm/IR/IntrinsicsVEVL.gen.td
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/IR/IntrinsicsXCore.td
  llvm/lib/IR/Function.cpp
  llvm/utils/TableGen/CodeGenIntrinsics.h
  llvm/utils/TableGen/CodeGenTarget.cpp
  llvm/utils/TableGen/IntrinsicEmitter.cpp

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


Re: [clang] d4bcb45 - [MC][re-land] Omit DWARF unwind info if compact unwind is present where eligible

2022-06-14 Thread Jez Ng via cfe-commits
Ack. The only change in this case was moving 
llvm/test/MC/MachO/emit-dwarf-unwind.s to 
llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s. Will include it in the commit 
message in the future.

From: David Blaikie 
Sent: Monday, June 13, 2022 5:01 PM
To: Jez Ng ; Jez Ng 
Cc: cfe-commits 
Subject: Re: [clang] d4bcb45 - [MC][re-land] Omit DWARF unwind info if compact 
unwind is present where eligible

Please include details of what changed between one commit and a recommit of a 
patch - helpful for reviewers checking what's changed since the last commit, 
double-checking that the patch fully addresses the issues, etc.

On Sun, Jun 12, 2022 at 2:24 PM Jez Ng via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:

Author: Jez Ng
Date: 2022-06-12T17:24:19-04:00
New Revision: d4bcb45db78dc7ca371224cb01bea8dcb14e0698

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

LOG: [MC][re-land] Omit DWARF unwind info if compact unwind is present where 
eligible

This reverts commit d941d597837d9e1405086f008c9bd6a71e7263c9.

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

Added:
clang/test/Driver/femit-dwarf-unwind.c
clang/test/Driver/femit-dwarf-unwind.s
llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s
llvm/test/MC/X86/compact-unwind-mode-dwarf.s

Modified:
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/tools/driver/cc1as_main.cpp
llvm/include/llvm/MC/MCContext.h
llvm/include/llvm/MC/MCTargetOptions.h
llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
llvm/lib/CodeGen/LLVMTargetMachine.cpp
llvm/lib/CodeGen/MachineModuleInfo.cpp
llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp
llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
llvm/lib/MC/MCContext.cpp
llvm/lib/MC/MCDwarf.cpp
llvm/lib/MC/MCObjectFileInfo.cpp
llvm/lib/MC/MCTargetOptions.cpp
llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

Removed:




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index d8f667dc387bb..8e89106993c26 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -114,6 +114,10 @@ CODEGENOPT(StackSizeSection  , 1, 0) ///< Set when 
-fstack-size-section is enabl
 CODEGENOPT(ForceDwarfFrameSection , 1, 0) ///< Set when -fforce-dwarf-frame is
   ///< enabled.

+///< Set when -femit-dwarf-unwind is passed.
+ENUM_CODEGENOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,
+llvm::EmitDwarfUnwindType::Default)
+
 ///< Set when -fxray-always-emit-customevents is enabled.
 CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0)


diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 95840760f7746..002cd6cc8cb17 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3044,6 +3044,13 @@ def fmacro_prefix_map_EQ
 defm force_dwarf_frame : BoolFOption<"force-dwarf-frame",
   CodeGenOpts<"ForceDwarfFrameSection">, DefaultFalse,
   PosFlag, 
NegFlag>;
+def femit_dwarf_unwind_EQ : Joined<["-"], "femit-dwarf-unwind=">,
+  Group, Flags<[CC1Option, CC1AsOption]>,
+  HelpText<"When to emit DWARF unwind (EH frame) info">,
+  Values<"always,no-compact-unwind,default">,
+  NormalizedValues<["Always", "NoCompactUnwind", "Default"]>,
+  NormalizedValuesScope<"llvm::EmitDwarfUnwindType">,
+  MarshallingInfoEnum, "Default">;
 def g_Flag : Flag<["-"], "g">, Group,
   HelpText<"Generate source-level debug information">;
 def gline_tables_only : Flag<["-"], "gline-tables-only">, Group,

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 0de15b1e48078..4b294c254e476 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -453,6 +453,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   }

   Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
+  Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
   Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
   Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
   Options.MCOptions.MCUseDwarfDirectory =

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index ceac142653ebe..62e891ce38c49 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2518,6 +2518,8 @@ static void CollectArgsForIntegratedAssem

[PATCH] D127460: Rename GCCBuiltin into ClangBuiltin

2022-06-14 Thread Guillaume Gomez via Phabricator via cfe-commits
GuillaumeGomez added a comment.

I applied the changes suggested by @RKSimon and @efriedma.




Comment at: llvm/include/llvm/ADT/Triple.h:1031
   /// @}
   /// @name Static helpers for IDs.
   /// @{

ldionne wrote:
> Comment applies to `test_demangle.pass.cpp` (it's a binary file so I can't 
> comment on it). The test is currently failing because you need to change 
> `_ZN4llvm9Intrinsic25getIntrinsicForClangBuiltinEPKcS2_` to 
> `_ZN4llvm9Intrinsic27getIntrinsicForClangBuiltinEPKcS2_`.
You're right, I removed this change as it's unrelated.



Comment at: llvm/lib/IR/Function.cpp:1430
+// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
 #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
 #include "llvm/IR/IntrinsicImpl.inc"

GuillaumeGomez wrote:
> GuillaumeGomez wrote:
> > RKSimon wrote:
> > > Should this be updated to use GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN?
> > I think it should for coherency. I'll send an update.
> When replacing with `CLANG`, it cannot build. After some investigations, it's 
> because of this:
> 
> ```
> llvm/utils/TableGen/IntrinsicEmitter.cpp:908:  OS << "#ifdef 
> GET_LLVM_INTRINSIC_FOR_" << CompilerName << "_BUILTIN\n";
> ```
> 
> So I'll let it as is for the time.
I fixed the error so it's now done. Thanks for the suggestion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127460

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


[PATCH] D126061: [clang] Reject non-declaration C++11 attributes on declarations

2022-06-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM!




Comment at: clang/include/clang/Basic/AttributeCommonInfo.h:153
 // FIXME: Use a better mechanism to determine this.
+// We use this in `isCXX11Attribute` below, so it _should_ only return
+// true for the `alignas` spelling, but it currently also returns true

mboehme wrote:
> aaron.ballman wrote:
> > Now that C23 has attributes, it's also not clear whether `_Alignas` will be 
> > handled slightly differently in the future as an attribute rather than a 
> > declaration specifier as happened with `_Noreturn` for C23. So agreed this 
> > is a tricky area.
> Thanks for pointing this out! Is there anything specific I should add to the 
> code comment, or is your comment just for general awareness?
Nope, just spreading the information around to more people's brains -- nothing 
needs to be changed here.



Comment at: clang/include/clang/Sema/ParsedAttr.h:1126
+/// `Result`. Sets `Result.Range` to the combined range of `First` and 
`Second`.
+void ConcatenateAttributes(ParsedAttributes &First, ParsedAttributes &Second,
+   ParsedAttributes &Result);

mboehme wrote:
> aaron.ballman wrote:
> > I think `Concatenate` implies that `First` and `Second` are untouched, but 
> > that's not really the case here. Perhaps `takeAndConcatenateAll()` or 
> > something along those lines instead? Also, the function should start with a 
> > lowercase letter per the usual coding style rules.
> Good point. Done, with a slightly different name -- WDYT?
Works great for me!



Comment at: clang/lib/Parse/ParseStmt.cpp:229
   default: {
+bool HaveAttrs = !(CXX11Attrs.empty() && GNUAttrs.empty());
+auto IsStmtAttr = [](ParsedAttr &Attr) { return Attr.isStmtAttr(); };

I don't insist, but I think it's a tiny bit easier to read this way.



Comment at: clang/lib/Parse/ParseStmt.cpp:321-323
+for (const ParsedAttr &AL : CXX11Attrs) {
+  Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
+}





Comment at: clang/lib/Parse/ParseStmt.cpp:230-237
 if ((getLangOpts().CPlusPlus || getLangOpts().MicrosoftExt ||
  (StmtCtx & ParsedStmtContext::AllowDeclarationsInC) !=
  ParsedStmtContext()) &&
 ((GNUAttributeLoc.isValid() &&
-  !(!Attrs.empty() &&
-llvm::all_of(
-Attrs, [](ParsedAttr &Attr) { return Attr.isStmtAttr(); }))) ||
+  !(!(CXX11Attrs.empty() && GNUAttrs.empty()) &&
+llvm::all_of(CXX11Attrs, isStmtAttr) &&
+llvm::all_of(GNUAttrs, isStmtAttr))) ||

mboehme wrote:
> aaron.ballman wrote:
> > The logic is correct here, but this predicate has gotten really difficult 
> > to understand. If you wanted to split some of those conditions out into 
> > named variables for clarity, I would not be sad (but I also don't insist 
> > either).
> Yes, this is confusing. I've factored out some variables that I hope make 
> this more readable.
> 
> By the way, it might look as if `GNUAttributeLoc.isValid()` implies 
> `HaveAttributes` and that the latter is therefore redundant, but this isn’t 
> actually true if we failed to parse the GNU attribute. Removing the 
> `HaveAttributes` makes some tests fail, e.g. line 78 of 
> clang/test/Parser/stmt-attributes.c.
Thanks, I think this is more readable this way!



Comment at: clang/lib/Parse/ParseStmt.cpp:248-251
+  if (CXX11Attrs.Range.getBegin().isValid())
+DeclStart = CXX11Attrs.Range.getBegin();
+  else if (GNUAttrs.Range.getBegin().isValid())
+DeclStart = GNUAttrs.Range.getBegin();

mboehme wrote:
> aaron.ballman wrote:
> > Do CXX attributes always precede GNU ones, or do we need to do a source 
> > location comparison here to see which location is lexically earlier?
> Yes, we can rely on this being the case. This function is called from only 
> one place where both CXX11Attrs and GNUAttrs can potentially contain 
> attributes, namely `ParseStatementOrDeclaration()` (line 114 in this file). 
> There, the CXX11Attrs are parsed before the GNUAttrs. I’ve added an 
> assertion, however, since this guarantee is important to the correctness of 
> the code here.
Thank you for the confirmation and the added assertion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126061

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


[PATCH] D127460: Rename GCCBuiltin into ClangBuiltin

2022-06-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/utils/TableGen/IntrinsicEmitter.cpp:883
 void IntrinsicEmitter::EmitIntrinsicToBuiltinMap(
 const CodeGenIntrinsicTable &Ints, bool IsGCC, raw_ostream &OS) {
+  StringRef CompilerName = (IsGCC ? "Clang" : "MS");

IsGCC?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127460

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


[PATCH] D127460: Rename GCCBuiltin into ClangBuiltin

2022-06-14 Thread Guillaume Gomez via Phabricator via cfe-commits
GuillaumeGomez updated this revision to Diff 436778.
GuillaumeGomez added a comment.

Rename `IsGCC` function parameter into `IsClang`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127460

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/IR/Intrinsics.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/include/llvm/IR/IntrinsicsAMDGPU.td
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/include/llvm/IR/IntrinsicsBPF.td
  llvm/include/llvm/IR/IntrinsicsHexagon.td
  llvm/include/llvm/IR/IntrinsicsMips.td
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/include/llvm/IR/IntrinsicsSystemZ.td
  llvm/include/llvm/IR/IntrinsicsVE.td
  llvm/include/llvm/IR/IntrinsicsVEVL.gen.td
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/include/llvm/IR/IntrinsicsXCore.td
  llvm/lib/IR/Function.cpp
  llvm/utils/TableGen/CodeGenIntrinsics.h
  llvm/utils/TableGen/CodeGenTarget.cpp
  llvm/utils/TableGen/IntrinsicEmitter.cpp

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


[PATCH] D127460: Rename GCCBuiltin into ClangBuiltin

2022-06-14 Thread Guillaume Gomez via Phabricator via cfe-commits
GuillaumeGomez added a comment.

Applied @RKSimon's suggestion.




Comment at: llvm/utils/TableGen/IntrinsicEmitter.cpp:883
 void IntrinsicEmitter::EmitIntrinsicToBuiltinMap(
 const CodeGenIntrinsicTable &Ints, bool IsGCC, raw_ostream &OS) {
+  StringRef CompilerName = (IsGCC ? "Clang" : "MS");

RKSimon wrote:
> IsGCC?
I didn't even notice when updating it... Updating to `IsClang`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127460

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


[PATCH] D126984: [clang] Add support for optimize function attribute

2022-06-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D126984#3579842 , @jdoerfert wrote:

> In D126984#3571573 , @aeubanks 
> wrote:
>
>> IIRC in the past there was a strong preference to not have the pass manager 
>> support this sort of thing
>> if you want to support this, there should be an RFC for how the optimization 
>> part of this will work as it may require invasive changes to the LLVM pass 
>> manager
>>
>> (if this is purely a clang frontend thing then ignore me)
>
> We actually should *not* make this a clang frontend only thing. It is 
> confusing and not helpful. That said, we have code to integrate this into the 
> new PM already as we were planning on proposing something along these lines 
> too. We didn't manage to get to it during last years GSoC but the code could 
> be used as a basis still.
>
> +1 for RFC
> strong preference for proper integration of this into the new PM.

I'm not opposed to an RFC to extend this functionality, but it seems to me that 
we have incremental progress already with this patch and landing this patch 
unblocks the work @steplong was originally doing for the MSVC pragma. Do you 
have a concern if we move forward with this less-functional form so that work 
isn't held up on an RFC for the more fully functional form?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126984

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


[clang] 48e1829 - [Diagnostics] Fix inconsistent shift-overflow warnings in C++20

2022-06-14 Thread Shivam Gupta via cfe-commits

Author: Shivam Gupta
Date: 2022-06-14T20:19:46+05:30
New Revision: 48e1829874df15fd57e731d4824604f28e177585

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

LOG: [Diagnostics] Fix inconsistent shift-overflow warnings in C++20

This fixes https://github.com/llvm/llvm-project/issues/52873.
Don't warn in C++2A mode (and newer), as signed left shifts
always wrap and never overflow. Ref. -
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1236r1.html.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/expr/expr.const/p2-0x.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaCXX/shift.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e68640074cea5..8766adb27a09a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -256,6 +256,10 @@ Improvements to Clang's diagnostics
 - The ``-Wdeprecated`` diagnostic will now warn on out-of-line ``constexpr``
   declarations downgraded to definitions in C++1z, in addition to the
   existing warning on out-of-line ``const`` declarations.
+- ``-Wshift-overflow`` will not warn for signed left shifts in C++20 mode
+  (and newer), as it will always wrap and never overflow. This fixes
+  `Issue 52873 `_.
+
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 7e6618bd2d11d..6edf5b355d029 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -11416,10 +11416,16 @@ static void DiagnoseBadShiftValues(Sema& S, 
ExprResult &LHS, ExprResult &RHS,
 return;
   llvm::APSInt Left = LHSResult.Val.getInt();
 
-  // If LHS does not have a signed type and non-negative value
-  // then, the behavior is undefined before C++2a. Warn about it.
-  if (Left.isNegative() && !S.getLangOpts().isSignedOverflowDefined() &&
-  !S.getLangOpts().CPlusPlus20) {
+  // Don't warn if signed overflow is defined, then all the rest of the
+  // diagnostics will not be triggered because the behavior is defined.
+  // Also don't warn in C++20 mode (and newer), as signed left shifts
+  // always wrap and never overflow.
+  if (S.getLangOpts().isSignedOverflowDefined() || S.getLangOpts().CPlusPlus20)
+return;
+
+  // If LHS does not have a non-negative value then, the
+  // behavior is undefined before C++2a. Warn about it.
+  if (Left.isNegative()) {
 S.DiagRuntimeBehavior(Loc, LHS.get(),
   S.PDiag(diag::warn_shift_lhs_negative)
 << LHS.get()->getSourceRange());

diff  --git a/clang/test/CXX/expr/expr.const/p2-0x.cpp 
b/clang/test/CXX/expr/expr.const/p2-0x.cpp
index 81efbb0a47271..6d2bc3f25179b 100644
--- a/clang/test/CXX/expr/expr.const/p2-0x.cpp
+++ b/clang/test/CXX/expr/expr.const/p2-0x.cpp
@@ -162,9 +162,9 @@ namespace UndefinedBehavior {
   constexpr int shl_signed_ok = 1 << 30; // ok
   constexpr int shl_signed_into_sign = 1 << 31; // ok (DR1457)
   constexpr int shl_signed_into_sign_2 = 0x7fff << 1; // ok (DR1457)
-  constexpr int shl_signed_off_end = 2 << 31; // cxx11-error {{constant 
expression}} cxx11-note {{signed left shift discards bits}} expected-warning 
{{signed shift result (0x1) requires 34 bits to represent, but 'int' 
only has 32 bits}}
-  constexpr int shl_signed_off_end_2 = 0x7fff << 2; // cxx11-error 
{{constant expression}} cxx11-note {{signed left shift discards bits}} 
expected-warning {{signed shift result (0x1FFFC) requires 34 bits to 
represent, but 'int' only has 32 bits}}
-  constexpr int shl_signed_overflow = 1024 << 31; // cxx11-error {{constant 
expression}} cxx11-note {{signed left shift discards bits}} expected-warning 
{{requires 43 bits to represent}}
+  constexpr int shl_signed_off_end = 2 << 31; // cxx11-error {{constant 
expression}} cxx11-note {{signed left shift discards bits}} cxx11-warning 
{{signed shift result (0x1) requires 34 bits to represent, but 'int' 
only has 32 bits}}
+  constexpr int shl_signed_off_end_2 = 0x7fff << 2; // cxx11-error 
{{constant expression}} cxx11-note {{signed left shift discards bits}} 
cxx11-warning {{signed shift result (0x1FFFC) requires 34 bits to 
represent, but 'int' only has 32 bits}}
+  constexpr int shl_signed_overflow = 1024 << 31; // cxx11-error {{constant 
expression}} cxx11-note {{signed left shift discards bits}} cxx11-warning 
{{requires 43 bits to represent}}
   constexpr int shl_signed_ok2 = 1024 << 20; // ok
 
   constexpr int shr_m1 = 0 >> -1; // expected-error {{constant expression}} 
expected-note {{negative shift count -1}}

diff  --git a/cl

[PATCH] D127518: [Diagnostics] Fix inconsistent shift-overflow warnings in C++20

2022-06-14 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta closed this revision.
xgupta added a comment.

In D127518#3581620 , @aaron.ballman 
wrote:

> LGTM! Please add a release note about the issue that was fixed when landing.

Done, Thank you for reviewing.

Committed in 
https://reviews.llvm.org/rG48e1829874df15fd57e731d4824604f28e177585.


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

https://reviews.llvm.org/D127518

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


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for this, can you also add a release note for the fix?




Comment at: clang/lib/Sema/SemaDeclAttr.cpp:8849
 break;
-  
   // HLSL attributes:

Spurious whitespace change?



Comment at: clang/test/CodeGen/hwasan-globals.cpp:1-2
+// RUN: echo "int extra_global;" > %t.extra-source.cpp
+// RUN: echo "global:*ignorelisted_global*" > %t.ignorelist
+// RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=hwaddress 
-fsanitize-ignorelist=%t.ignorelist -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=CHECK

Are these files automatically deleted when the test is done because we're using 
%t, or do we need to clean those up manually?



Comment at: clang/test/CodeGen/hwasan-globals.cpp:9
+int global;
+int __attribute__((no_sanitize("hwaddress"))) attributed_global;
+int __attribute__((disable_sanitizer_instrumentation)) 
disable_instrumentation_global;

Should we add a `memtag` test as well given that also changed in this patch?



Comment at: compiler-rt/test/hwasan/TestCases/global-with-reduction.c:25
 
-int x = 1;
+#include 
 

I'm not a compiler-rt expert, but is this valid? I assume this is using the 
system stdlib.h which is not something we usually want in lit tests.

I think that's why `atoi` was previously being forward declared; then we don't 
need to include the whole header file.



Comment at: compiler-rt/test/hwasan/TestCases/global-with-reduction.c:50
+  f()[atoi(argv[1])] = 1;
+  return 0;
 }

This is unnecessary -- falling off `main` already returns 0.



Comment at: compiler-rt/test/hwasan/TestCases/global.c:47
   (&x)[atoi(argv[1])] = 1;
+  return 0;
 }

This is unnecessary -- falling off `main` already returns 0.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127544

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


[PATCH] D127745: [clang][dataflow] Rename `getPointeeLoc` to `getReferencePointeeLoc` and `getPointerPointeeLoc` respectively for ReferenceValue and PointerValue.

2022-06-14 Thread weiyi via Phabricator via cfe-commits
wyt created this revision.
Herald added subscribers: tschuett, steakhal, xazax.hun.
Herald added a project: All.
wyt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We distinguish between getting pointee location for `ReferenceValue` and 
`PointerValue` as the former must be non-empty but the latter may be empty in 
the case of a `nullptr`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127745

Files:
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -676,7 +676,7 @@
 Env.getStorageLocation(*FooDecl, SkipPast::None));
 const auto *BarVal =
 cast(Env.getValue(*BarDecl, SkipPast::None));
-EXPECT_EQ(&BarVal->getPointeeLoc(), FooLoc);
+EXPECT_EQ(&BarVal->getPointerPointeeLoc(), FooLoc);
   });
 }
 
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -293,29 +293,29 @@
   // [[p]]
 }
   )";
-  runDataflow(Code,
-  [](llvm::ArrayRef<
- std::pair>>
- Results,
- ASTContext &ASTCtx) {
-ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
-const Environment &Env = Results[0].second.Env;
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
-ASSERT_THAT(FooDecl, NotNull());
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
 
-const StorageLocation *FooLoc =
-Env.getStorageLocation(*FooDecl, SkipPast::None);
-ASSERT_TRUE(isa_and_nonnull(FooLoc));
+const StorageLocation *FooLoc =
+Env.getStorageLocation(*FooDecl, SkipPast::None);
+ASSERT_TRUE(isa_and_nonnull(FooLoc));
 
-const ReferenceValue *FooVal =
-cast(Env.getValue(*FooLoc));
-const StorageLocation &FooPointeeLoc = FooVal->getPointeeLoc();
-EXPECT_TRUE(isa(&FooPointeeLoc));
+const ReferenceValue *FooVal =
+cast(Env.getValue(*FooLoc));
+const StorageLocation &FooPointeeLoc = FooVal->getReferencePointeeLoc();
+EXPECT_TRUE(isa(&FooPointeeLoc));
 
-const Value *FooPointeeVal = Env.getValue(FooPointeeLoc);
-EXPECT_TRUE(isa_and_nonnull(FooPointeeVal));
-  });
+const Value *FooPointeeVal = Env.getValue(FooPointeeLoc);
+EXPECT_TRUE(isa_and_nonnull(FooPointeeVal));
+  });
 }
 
 TEST_F(TransferTest, SelfReferentialReferenceVarDecl) {
@@ -398,31 +398,33 @@
 Env.getStorageLocation(*FooDecl, SkipPast::None));
 const auto *FooVal = cast(Env.getValue(*FooLoc));
 const auto *FooPointeeVal =
-cast(Env.getValue(FooVal->getPointeeLoc()));
+cast(Env.getValue(FooVal->getReferencePointeeLoc()));
 
 const auto *BarVal =
 cast(FooPointeeVal->getChild(*BarDecl));
 const auto *BarPointeeVal =
-cast(Env.getValue(BarVal->getPointeeLoc()));
+cast(Env.getValue(BarVal->getReferencePointeeLoc()));
 
 const auto *FooRefVal =
 cast(BarPointeeVal->getChild(*FooRefDecl));
-const StorageLocation &FooRefPointeeLoc = FooRefVal->getPointeeLoc();
+const StorageLocation &FooRefPointeeLoc =
+FooRefVal->getReferencePointeeLoc();
 EXPECT_THAT(Env.getValue(FooRefPointeeLoc), IsNull());
 
 const auto *FooPtrVal =
 cast(BarPointeeVal->getChild(*FooPtrDecl));
-const StorageLocation &FooPtrPointeeLoc = FooPtrVal->getPointeeLoc();
+const StorageLocation &FooPtrPointeeLoc = FooPtrVal->getPointerPointeeLoc();
 EXPECT_THAT(Env.getValue(FooPtrPointeeLoc), IsNull());
 
 const auto *BazRefVal =
 cast(BarPointeeVal->getChild(*BazRefDecl));
-const StorageLocation &BazRefPointeeLoc = BazRefVal->getPointee

[PATCH] D127746: [clang][dataflow] Convert `PointeeLoc` of PointerValue from reference to pointer. This allows PointeeLoc to be empty in the case of `nullptr`

2022-06-14 Thread weiyi via Phabricator via cfe-commits
wyt created this revision.
Herald added subscribers: tschuett, steakhal, xazax.hun.
Herald added a project: All.
wyt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Depends On D127745 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127746

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -676,7 +676,7 @@
 Env.getStorageLocation(*FooDecl, SkipPast::None));
 const auto *BarVal =
 cast(Env.getValue(*BarDecl, SkipPast::None));
-EXPECT_EQ(&BarVal->getPointerPointeeLoc(), FooLoc);
+EXPECT_EQ(BarVal->getPointerPointeeLoc(), FooLoc);
   });
 }
 
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -413,8 +413,9 @@
 
 const auto *FooPtrVal =
 cast(BarPointeeVal->getChild(*FooPtrDecl));
-const StorageLocation &FooPtrPointeeLoc = FooPtrVal->getPointerPointeeLoc();
-EXPECT_THAT(Env.getValue(FooPtrPointeeLoc), IsNull());
+const StorageLocation *FooPtrPointeeLoc = FooPtrVal->getPointerPointeeLoc();
+ASSERT_THAT(FooPtrPointeeLoc, NotNull());
+EXPECT_THAT(Env.getValue(*FooPtrPointeeLoc), IsNull());
 
 const auto *BazRefVal =
 cast(BarPointeeVal->getChild(*BazRefDecl));
@@ -424,8 +425,9 @@
 
 const auto *BazPtrVal =
 cast(BarPointeeVal->getChild(*BazPtrDecl));
-const StorageLocation &BazPtrPointeeLoc = BazPtrVal->getPointerPointeeLoc();
-EXPECT_THAT(Env.getValue(BazPtrPointeeLoc), NotNull());
+const StorageLocation *BazPtrPointeeLoc = BazPtrVal->getPointerPointeeLoc();
+ASSERT_THAT(BazPtrPointeeLoc, NotNull());
+EXPECT_THAT(Env.getValue(*BazPtrPointeeLoc), NotNull());
   });
 }
 
@@ -456,10 +458,10 @@
 ASSERT_TRUE(isa_and_nonnull(FooLoc));
 
 const PointerValue *FooVal = cast(Env.getValue(*FooLoc));
-const StorageLocation &FooPointeeLoc = FooVal->getPointerPointeeLoc();
-EXPECT_TRUE(isa(&FooPointeeLoc));
+const StorageLocation *FooPointeeLoc = FooVal->getPointerPointeeLoc();
+EXPECT_TRUE(isa_and_nonnull(FooPointeeLoc));
 
-const Value *FooPointeeVal = Env.getValue(FooPointeeLoc);
+const Value *FooPointeeVal = Env.getValue(*FooPointeeLoc);
 EXPECT_TRUE(isa_and_nonnull(FooPointeeVal));
   });
 }
@@ -488,106 +490,106 @@
   // [[p]]
 }
   )";
-  runDataflow(
-  Code, [](llvm::ArrayRef<
-   std::pair>>
-   Results,
-   ASTContext &ASTCtx) {
-ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
-const Environment &Env = Results[0].second.Env;
+  runDataflow(Code, [](llvm::ArrayRef>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
 
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
-ASSERT_THAT(FooDecl, NotNull());
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
 
-ASSERT_TRUE(FooDecl->getType()->isPointerType());
-ASSERT_TRUE(FooDecl->getType()
-->getAs()
-->getPointeeType()
-->isStructureType());
-const auto FooFields = FooDecl->getType()
-   ->getAs()
-   ->getPointeeType()
-   ->getAsRecordDecl()
-   ->fields();
+ASSERT_TRUE(FooDecl->getType()->isPointerType());
+ASSERT_TRUE(FooDecl->getType()
+->getAs()
+->getPointeeType()
+->isStructureType());
+const auto FooFields = FooDecl->getType()
+   ->getAs()
+   ->getPointeeType()
+   ->getAsRecordDecl()
+   ->fields();
 
-FieldDecl *BarDecl = nullptr;
-for (FieldDecl *Field : FooFields) {
-  if (Field->get

[clang] 6117784 - [NFC] Remove unused function parameter

2022-06-14 Thread Serge Pavlov via cfe-commits

Author: Serge Pavlov
Date: 2022-06-14T22:00:59+07:00
New Revision: 6117784c5f2b70d0adb71afb50903f2dc457996a

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

LOG: [NFC] Remove unused function parameter

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 3c62a83618a13..65782fbb1eaea 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2552,18 +2552,15 @@ static bool HandleFloatToIntCast(EvalInfo &Info, const 
Expr *E,
   return true;
 }
 
-/// Get rounding mode used for evaluation of the specified expression.
-/// \param[out] DynamicRM Is set to true is the requested rounding mode is
-///   dynamic.
+/// Get rounding mode to use in evaluation of the specified expression.
+///
 /// If rounding mode is unknown at compile time, still try to evaluate the
 /// expression. If the result is exact, it does not depend on rounding mode.
 /// So return "tonearest" mode instead of "dynamic".
-static llvm::RoundingMode getActiveRoundingMode(EvalInfo &Info, const Expr *E,
-bool &DynamicRM) {
+static llvm::RoundingMode getActiveRoundingMode(EvalInfo &Info, const Expr *E) 
{
   llvm::RoundingMode RM =
   E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()).getRoundingMode();
-  DynamicRM = (RM == llvm::RoundingMode::Dynamic);
-  if (DynamicRM)
+  if (RM == llvm::RoundingMode::Dynamic)
 RM = llvm::RoundingMode::NearestTiesToEven;
   return RM;
 }
@@ -2613,8 +2610,7 @@ static bool HandleFloatToFloatCast(EvalInfo &Info, const 
Expr *E,
QualType SrcType, QualType DestType,
APFloat &Result) {
   assert(isa(E) || isa(E));
-  bool DynamicRM;
-  llvm::RoundingMode RM = getActiveRoundingMode(Info, E, DynamicRM);
+  llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
   APFloat::opStatus St;
   APFloat Value = Result;
   bool ignored;
@@ -2849,8 +2845,7 @@ static bool handleIntIntBinOp(EvalInfo &Info, const Expr 
*E, const APSInt &LHS,
 static bool handleFloatFloatBinOp(EvalInfo &Info, const BinaryOperator *E,
   APFloat &LHS, BinaryOperatorKind Opcode,
   const APFloat &RHS) {
-  bool DynamicRM;
-  llvm::RoundingMode RM = getActiveRoundingMode(Info, E, DynamicRM);
+  llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
   APFloat::opStatus St;
   switch (Opcode) {
   default:



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


[PATCH] D127748: Adds a warning for aligned new in MSVC before C++17

2022-06-14 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google created this revision.
Herald added a project: All.
luken-google requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

MSVC requires C++17 to support aligned new and defining the macro
__cpp_aligned_new. Clang does not, which could result in incompatibility
between clang-cl and msvc-built binaries. Issue a warning when this
use case is detected.

BUG=https://github.com/llvm/llvm-project/issues/55389


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127748

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Frontend/aligned-new-before-cpp17.cpp


Index: clang/test/Frontend/aligned-new-before-cpp17.cpp
===
--- /dev/null
+++ clang/test/Frontend/aligned-new-before-cpp17.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fms-compatibility -faligned-allocation -std=c++03 %s
+// CHECK: warning: possible incompatibility with MSVC, it does not support 
alignedNew before C++17
+// RUN: %clang_cc1 -fms-compatibility -faligned-allocation -std=c++11 %s
+// CHECK: warning: possible incompatibility with MSVC, it does not support 
alignedNew before C++17
+// RUN: %clang_cc1 -fms-compatibility -faligned-allocation -std=c++14 %s
+// CHECK: warning: possible incompatibility with MSVC, it does not support 
alignedNew before C++17
+// RUN: %clang_cc1 -fms-compatibility -faligned-allocation -std=c++17 %s
+// expected-no-diagnostics
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -591,7 +591,8 @@
 /// Initialize the predefined C++ language feature test macros defined in
 /// ISO/IEC JTC1/SC22/WG21 (C++) SD-6: "SG10 Feature Test Recommendations".
 static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
- MacroBuilder &Builder) {
+ MacroBuilder &Builder,
+ DiagnosticsEngine &Diags) {
   // C++98 features.
   if (LangOpts.RTTI)
 Builder.defineMacro("__cpp_rtti", "199711L");
@@ -666,8 +667,13 @@
 Builder.defineMacro("__cpp_guaranteed_copy_elision", "201606L");
 Builder.defineMacro("__cpp_nontype_template_parameter_auto", "201606L");
   }
-  if (LangOpts.AlignedAllocation && !LangOpts.AlignedAllocationUnavailable)
+  if (LangOpts.AlignedAllocation && !LangOpts.AlignedAllocationUnavailable) {
+// LLVM supports __cpp_aligned_new in C++ version older than C++17, but 
MSVC
+// does not. Warn about the difference in support.
+if (LangOpts.MSVCCompat && LangOpts.CPlusPlus && !LangOpts.CPlusPlus17)
+  Diags.Report(diag::warn_fe_msvc_aligned_new_before_cpp17);
 Builder.defineMacro("__cpp_aligned_new", "201606L");
+  }
   if (LangOpts.RelaxedTemplateTemplateArgs)
 Builder.defineMacro("__cpp_template_template_args", "201611L");
 
@@ -728,7 +734,8 @@
const LangOptions &LangOpts,
const FrontendOptions &FEOpts,
const PreprocessorOptions &PPOpts,
-   MacroBuilder &Builder) {
+   MacroBuilder &Builder,
+   DiagnosticsEngine &Diags) {
   // Compiler version introspection macros.
   Builder.defineMacro("__llvm__");  // LLVM Backend
   Builder.defineMacro("__clang__"); // Clang Frontend
@@ -856,7 +863,7 @@
   Twine(TI.useSignedCharForObjCBool() ? "0" : "1"));
 
   if (LangOpts.CPlusPlus)
-InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder);
+InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder, Diags);
 
   // darwin_constant_cfstrings controls this. This is also dependent
   // on other things like the runtime I believe.  This is set even for C code.
@@ -1326,10 +1333,10 @@
 if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice || LangOpts.SYCLIsDevice) &&
 PP.getAuxTargetInfo())
   InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
- PP.getPreprocessorOpts(), Builder);
+ PP.getPreprocessorOpts(), Builder, 
PP.getDiagnostics());
 
 InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts,
-   PP.getPreprocessorOpts(), Builder);
+   PP.getPreprocessorOpts(), Builder, 
PP.getDiagnostics());
 
 // Install definitions to make Objective-C++ ARC work well with various
 // C++ Standard Library implementations.
Index: clang/include/clang/Basic/DiagnosticFrontendKinds.td
===
--- clang/include/clang/Basic/DiagnosticFrontendKin

[PATCH] D127683: Adds a warning for aligned new in MSVC before C++17

2022-06-14 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google abandoned this revision.
luken-google added a comment.

Mistakenly updated change here: https://reviews.llvm.org/D127748


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127683

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


[PATCH] D127306: [analyzer] Treat system globals as mutable if they are not const

2022-06-14 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D127306#3580981 , @steakhal wrote:

> - Modify the `GenericTaintChecker::isStdin()` to look through //derived 
> symbols//, to mitigate the effect of invalidations.

So, the taint property is still not propagated by the engine after the 
invalidation. BUT, since we have the

  static bool isTaintedOrPointsToTainted(const Expr *E,  {
if (isTainted(State, E, C.getLocationContext()) || isStdin(E, C))
  return true;

condition and the modified `isStdin`, now we consider the `Expr*` associated to 
stdin as tainted. Please confirm my understanding is correct.




Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:98-101
+  const auto *DeclReg = dyn_cast_or_null(
+  isa(Sym)   ? cast(Sym)->getRegion()
+  : isa(Sym) ? cast(Sym)->getRegion()
+: nullptr);

This code yields to a virtual function call. And we fortunately have that 
virtual function in the base class.
Use `SymExpr::getOriginRegion()` and `dyn_cast_or_null` to `DeclRegion`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127306

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


[PATCH] D127749: [clangd] Wire up compilation for style blocks

2022-06-14 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: adamcz.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127749

Files:
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp


Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -261,6 +261,19 @@
   EXPECT_THAT(Results[0].Diagnostics.Includes.IgnoreHeader,
   ElementsAre(val("foo"), val("bar")));
 }
+
+TEST(ParseYAML, Style) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+Style:
+  FullyQualifiedNamespaces: [foo, bar])yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(Results[0].Style.FullyQualifiedNamespaces,
+  ElementsAre(val("foo"), val("bar")));
+}
 } // namespace
 } // namespace config
 } // namespace clangd
Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -536,6 +536,14 @@
   EXPECT_TRUE(compileAndApply());
   EXPECT_TRUE(Conf.Completion.AllScopes);
 }
+
+TEST_F(ConfigCompileTests, Style) {
+  Frag = {};
+  Frag.Style.FullyQualifiedNamespaces.push_back(std::string("foo"));
+  Frag.Style.FullyQualifiedNamespaces.push_back(std::string("bar"));
+  EXPECT_TRUE(compileAndApply());
+  EXPECT_THAT(Conf.Style.FullyQualifiedNamespaces, ElementsAre("foo", "bar"));
+}
 } // namespace
 } // namespace config
 } // namespace clangd
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -197,6 +197,7 @@
 compile(std::move(F.Completion));
 compile(std::move(F.Hover));
 compile(std::move(F.InlayHints));
+compile(std::move(F.Style));
   }
 
   void compile(Fragment::IfBlock &&F) {


Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -261,6 +261,19 @@
   EXPECT_THAT(Results[0].Diagnostics.Includes.IgnoreHeader,
   ElementsAre(val("foo"), val("bar")));
 }
+
+TEST(ParseYAML, Style) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+Style:
+  FullyQualifiedNamespaces: [foo, bar])yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(Results[0].Style.FullyQualifiedNamespaces,
+  ElementsAre(val("foo"), val("bar")));
+}
 } // namespace
 } // namespace config
 } // namespace clangd
Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -536,6 +536,14 @@
   EXPECT_TRUE(compileAndApply());
   EXPECT_TRUE(Conf.Completion.AllScopes);
 }
+
+TEST_F(ConfigCompileTests, Style) {
+  Frag = {};
+  Frag.Style.FullyQualifiedNamespaces.push_back(std::string("foo"));
+  Frag.Style.FullyQualifiedNamespaces.push_back(std::string("bar"));
+  EXPECT_TRUE(compileAndApply());
+  EXPECT_THAT(Conf.Style.FullyQualifiedNamespaces, ElementsAre("foo", "bar"));
+}
 } // namespace
 } // namespace config
 } // namespace clangd
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -197,6 +197,7 @@
 compile(std::move(F.Completion));
 compile(std::move(F.Hover));
 compile(std::move(F.InlayHints));
+compile(std::move(F.Style));
   }
 
   void compile(Fragment::IfBlock &&F) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126984: [clang] Add support for optimize function attribute

2022-06-14 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D126984#3581708 , @aaron.ballman 
wrote:

> In D126984#3579842 , @jdoerfert 
> wrote:
>
>> In D126984#3571573 , @aeubanks 
>> wrote:
>>
>>> IIRC in the past there was a strong preference to not have the pass manager 
>>> support this sort of thing
>>> if you want to support this, there should be an RFC for how the 
>>> optimization part of this will work as it may require invasive changes to 
>>> the LLVM pass manager
>>>
>>> (if this is purely a clang frontend thing then ignore me)
>>
>> We actually should *not* make this a clang frontend only thing. It is 
>> confusing and not helpful. That said, we have code to integrate this into 
>> the new PM already as we were planning on proposing something along these 
>> lines too. We didn't manage to get to it during last years GSoC but the code 
>> could be used as a basis still.
>>
>> +1 for RFC
>> strong preference for proper integration of this into the new PM.
>
> I'm not opposed to an RFC to extend this functionality, but it seems to me 
> that we have incremental progress already with this patch and landing this 
> patch unblocks the work @steplong was originally doing for the MSVC pragma. 
> Do you have a concern if we move forward with this less-functional form so 
> that work isn't held up on an RFC for the more fully functional form?

I was thinking about this again and I am more and more unsure about this 
feature. -Os/-Oz is something more than just some attribute.

Look here: 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
 and see lines (conditions) with SizeLevel and OptLevel.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126984

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


[PATCH] D127749: [clangd] Wire up compilation for style blocks

2022-06-14 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz accepted this revision.
adamcz added a comment.
This revision is now accepted and ready to land.

Wait, what? How? Whaaat? How did that happen?

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127749

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


[PATCH] D126479: [Clang] Allow 'Complex float __attribute__((mode(HC)))'

2022-06-14 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/include/clang/Basic/TargetInfo.h:223-224
   unsigned HasAlignMac68kSupport : 1;
-  unsigned RealTypeUsesObjCFPRet : 3;
+  unsigned RealTypeUsesObjCFPRet : (1 << (int)FloatModeKind::Float) |
+   (1 << (int)FloatModeKind::Double);
   unsigned ComplexLongDoubleUsesFP2Ret : 1;

aaron.ballman wrote:
> tahonermann wrote:
> > aaron.ballman wrote:
> > > jolanta.jensen wrote:
> > > > tahonermann wrote:
> > > > > This doesn't look right to me. The size of the bit field would be `(1 
> > > > > << 1) | (1 << 2)` which is `0b110` which is 6, but more by 
> > > > > coincidence than by construction. I think what we want is:
> > > > >   unsigned RealTypeUsesObjCFPRet  : (int)FloatModeKind::Last + 1;
> > > > Sorry. I mixed things up.
> > > >I think what we want is:
> > > >`unsigned RealTypeUsesObjCFPRet  : (int)FloatModeKind::Last + 1;`
> > > 
> > > I think this is wrong in two different ways. We need as many bits as 
> > > required to store the enumerator value. The highest value is 255 
> > > (`NoFloat`), so we need at least 8 bits for that. But also, the last 
> > > enumerator value is just that -- a value, not a width.
> > > 
> > > I'd probably skip the `Last` entry and force the bit-field to 8 bits.
> > `RealTypeUsesObjCFPRet` is used as a bit mask indexed by the 
> > `FloatModeKind` enumerator values; the `X86_32TargetInfo` constructor in 
> > `clang/lib/Basic/Targets/X86.h` has the following code:
> > 
> >   420 // Use fpret for all types.
> >   421 RealTypeUsesObjCFPRet =
> >   422 ((1 << (int)FloatModeKind::Float) | (1 << 
> > (int)FloatModeKind::Double) |
> >   423  (1 << (int)FloatModeKind::LongDouble));
> > 
> > `NoFloat` is a special case for which a mask bit is not needed.
> > 
> > I think this code is correct as is, but Aaron's comment suggests some 
> > clarification would be useful. Perhaps the data member should be renamed to 
> > something like `RealTypeUsesObjCFPRetMask` (though I suspect a better name 
> > can be found).
> A, yeah, I definitely did not pick up the fact that these were used as 
> part of a mask. I'm more used to masks being represented directly in the 
> enumeration itself, e.g., `enum Whatever { FirstThing = 1 << 0, SecondThing = 
> 1 << 1, ThirdThing = 1 << 2 };` These aren't really masks, they're shift 
> amounts to be used to form a mask. Any reason we don't switch to that form to 
> make it more clear (and simplify other code)? Actually, any reason why we 
> don't want to switch the enumeration to use bitmask enums 
> (https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/BitmaskEnum.h)?
I agree using the facilities provided by `BitmaskEnum.h` would be an 
improvement. Such a change request is arguably out of scope for this review, 
but if @jolanta.jensen wants to take that on, then great! I'm ok with the code 
as is (though a comment or some other explicit indicator that the enumeration 
and data member are used as a bit mask would be appreciated).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126479

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


[PATCH] D125723: [MSVC] Add support for MSVC pragma optimize

2022-06-14 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D125723#3547789 , @rnk wrote:

> I think it's fine to implement this, but I wanted to share some of the 
> motivation for the current state of things. In our experience, the majority 
> of uses of pragma optimize were to work around MSVC compiler bugs. So, 
> instead of honoring them, we felt it was best to ignore them with a warning 
> (`-Wignored-pragma-optimize`). Of course, that warning is typically disabled 
> in build systems of large projects, so our current behavior can still 
> surprise users. Implementing the feature is probably the most predictable and 
> least surprising thing Clang can do.
>
> Something we can't easily support for either GCC or MSVC attribute is 
> enabling optimizations for some functions in an -O0 build. Maybe it's now 
> possible to set up a full pass pipeline after semantic analysis is complete, 
> but it's not straightforward. You should consider what to do with that corner 
> case.

What is a real motivation to have it in Clang as well? As you said, for MSVC, 
to work around bugs. You may say optimise(-Oz), but we have attribute minsize 
for that. Just to match MSVC?

As shown https://reviews.llvm.org/D126984, things work a bit different in Clang 
vs MSVC/GCC so to justify this pragma, optimise attribute (and related (huge, 
imho) rework to move other attributes under OptimiseAttr, maybe rework of LLVM 
attributes), I would like to hear quite strong motivating words.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125723

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


  1   2   3   >