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

2022-06-02 Thread Diana Picus via Phabricator via cfe-commits
rovka added a comment.

In D126291#3550563 , @Meinersbur 
wrote:

> While the test passes now, I still get `LINK : fatal error LNK1561: entry 
> point must be defined` when trying to actually link. Isn't it expected to not 
> work yet?
>
> Linking with `lld-link.exe` does work. objdump says there is a `_QQmain` 
> symbol, why does lld consider this to be the entry point?

It doesn't - we're linking in a `main` as part of the `Fortran_main.lib`, which 
then calls `_QQmain`.

I don't really know why `link.exe` doesn't work. According to the docs 
,
 it should find `main` and choose the subsystem on its own. The only hunch I 
have is that maybe it doesn't work because `main` is in a library as opposed to 
one of the object files, but I'm still going through the docs trying to figure 
this out. I don't have a lot of experience with `link.exe` so I might be 
missing something obvious.


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-02 Thread Diana Picus via Phabricator via cfe-commits
rovka added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:753
+  llvm::opt::ArgStringList &CmdArgs) {
+  if (TC.getTriple().isOSWindows()) {
+CmdArgs.push_back("Fortran_main.lib");

mmuetzel wrote:
> Are those correct for MinGW? Should this be checking for 
> `TC.getTriple().isKnownWindowsMSVCEnvironment()` instead?
Right, I hadn't considered MinGW. Thanks for pointing it out, I'll update the 
patch.


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] D126857: [HLSL] Add WaveActiveCountBits as Langugage builtin function for HLSL

2022-06-02 Thread Xiang Li via Phabricator via cfe-commits
python3kgae created this revision.
python3kgae added reviewers: Anastasia, svenvh, jdoerfert, azabaznov, beanz, 
tra, yaxunl, pow2clk.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

One clang builtins are introduced
 uint WaveActiveCountBits( bool bBit ) as Langugage builtin function for HLSL.

The detail for WaveActiveCountBits is at
https://github.com/microsoft/DirectXShaderCompiler/wiki/Wave-Intrinsics#uint-waveactivecountbits-bool-bbit-

This is only clang part change to make WaveActiveCountBits into AST.
llvm intrinsic for WaveActiveCountBits will be add in separate PR.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126857

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/test/SemaHLSL/Wave.hlsl


Index: clang/test/SemaHLSL/Wave.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/Wave.hlsl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1  -x hlsl -triple dxil--shadermodel6.7-library -ast-dump  %s 
 -o - -finclude-default-header | FileCheck %s
+
+// Make sure WaveActiveCountBits is used in AST.
+// CHECK: BuiltinFnToFnPtr>
+// CHECK-NEXT:-DeclRefExpr 0x{{.*}}  '' Function 
0x{{.*}} 'WaveActiveCountBits' 'unsigned int (bool)
+uint foo(bool b) {
+return WaveActiveCountBits(b);
+}
\ No newline at end of file
Index: clang/include/clang/Basic/Builtins.h
===
--- clang/include/clang/Basic/Builtins.h
+++ clang/include/clang/Basic/Builtins.h
@@ -42,6 +42,7 @@
   OCL_PIPE = 0x200,  // builtin requires OpenCL pipe.
   OCL_DSE = 0x400,   // builtin requires OpenCL device side enqueue.
   ALL_OCL_LANGUAGES = 0x800, // builtin for OCL languages.
+  HLSL_LANG = 0x1000,// builtin requires HLSL.
   ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
   ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,  // builtin requires GNU mode.
   ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.
Index: clang/include/clang/Basic/Builtins.def
===
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -1693,6 +1693,9 @@
 // CUDA/HIP
 LANGBUILTIN(__builtin_get_device_side_mangled_name, "cC*.", "ncT", CUDA_LANG)
 
+// HLSL
+LANGBUILTIN(WaveActiveCountBits, "Uib", "nc", HLSL_LANG)
+
 // Builtins for XRay
 BUILTIN(__xray_customevent, "vcC*z", "")
 BUILTIN(__xray_typedevent, "vzcC*z", "")


Index: clang/test/SemaHLSL/Wave.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/Wave.hlsl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1  -x hlsl -triple dxil--shadermodel6.7-library -ast-dump  %s  -o - -finclude-default-header | FileCheck %s
+
+// Make sure WaveActiveCountBits is used in AST.
+// CHECK: BuiltinFnToFnPtr>
+// CHECK-NEXT:-DeclRefExpr 0x{{.*}}  '' Function 0x{{.*}} 'WaveActiveCountBits' 'unsigned int (bool)
+uint foo(bool b) {
+return WaveActiveCountBits(b);
+}
\ No newline at end of file
Index: clang/include/clang/Basic/Builtins.h
===
--- clang/include/clang/Basic/Builtins.h
+++ clang/include/clang/Basic/Builtins.h
@@ -42,6 +42,7 @@
   OCL_PIPE = 0x200,  // builtin requires OpenCL pipe.
   OCL_DSE = 0x400,   // builtin requires OpenCL device side enqueue.
   ALL_OCL_LANGUAGES = 0x800, // builtin for OCL languages.
+  HLSL_LANG = 0x1000,// builtin requires HLSL.
   ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
   ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,  // builtin requires GNU mode.
   ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.
Index: clang/include/clang/Basic/Builtins.def
===
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -1693,6 +1693,9 @@
 // CUDA/HIP
 LANGBUILTIN(__builtin_get_device_side_mangled_name, "cC*.", "ncT", CUDA_LANG)
 
+// HLSL
+LANGBUILTIN(WaveActiveCountBits, "Uib", "nc", HLSL_LANG)
+
 // Builtins for XRay
 BUILTIN(__xray_customevent, "vcC*z", "")
 BUILTIN(__xray_typedevent, "vzcC*z", "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125862: [clang][driver] Add gcc-toolset/devtoolset 12 to prefixes

2022-06-02 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 2 inline comments as done.
tbaeder added inline comments.



Comment at: clang/unittests/Driver/ToolChainTest.cpp:623
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+

MaskRay wrote:
> delete `public`.
> 
> Can you avoid using a derived DiagnosticConsumer?
I can use the `SimpleDiagnosticConsumer` class created earlier in the file.


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

https://reviews.llvm.org/D125862

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


[PATCH] D125862: [clang][driver] Add gcc-toolset/devtoolset 12 to prefixes

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

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

https://reviews.llvm.org/D125862

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/unittests/Driver/ToolChainTest.cpp

Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -18,6 +18,7 @@
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/MC/TargetRegistry.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
@@ -610,4 +611,94 @@
   DiagConsumer->clear();
 }
 
+TEST(ToolChainTest, Toolsets) {
+  // Ignore this test on Windows hosts.
+  llvm::Triple Host(llvm::sys::getProcessTriple());
+  if (Host.isOSWindows())
+GTEST_SKIP();
+
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+
+  // Check (newer) GCC toolset installation.
+  {
+IntrusiveRefCntPtr InMemoryFileSystem(
+new llvm::vfs::InMemoryFileSystem);
+
+// These should be ignored.
+InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-2", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--1", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+// File needed for GCC installation detection.
+InMemoryFileSystem->addFile(
+"/opt/rh/gcc-toolset-12/lib/gcc/x86_64-redhat-linux/11/crtbegin.o", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new SimpleDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"--gcc-toolchain="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+EXPECT_EQ("Found candidate GCC installation: "
+  "/opt/rh/gcc-toolset-12/lib/gcc/x86_64-redhat-linux/11\n"
+  "Selected GCC installation: "
+  "/opt/rh/gcc-toolset-12/lib/gcc/x86_64-redhat-linux/11\n"
+  "Candidate multilib: .;@m64\n"
+  "Selected multilib: .;@m64\n",
+  S);
+  }
+
+  // And older devtoolset.
+  {
+IntrusiveRefCntPtr InMemoryFileSystem(
+new llvm::vfs::InMemoryFileSystem);
+
+// These should be ignored.
+InMemoryFileSystem->addFile("/opt/rh/devtoolset-2", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/devtoolset-", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/devtoolset--", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+InMemoryFileSystem->addFile("/opt/rh/devtoolset--1", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+// File needed for GCC installation detection.
+InMemoryFileSystem->addFile(
+"/opt/rh/devtoolset-12/lib/gcc/x86_64-redhat-linux/11/crtbegin.o", 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new SimpleDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"--gcc-toolchain="}));
+ASSERT_TRUE(C);
+std::string S;
+{
+  llvm::raw_string_ostream OS(S);
+  C->getDefaultToolChain().printVerboseInfo(OS);
+}
+EXPECT_EQ("Found candidate GCC installation: "
+  "/opt/rh/devtoolset-12/lib/gcc/x86_64-redhat-linux/11\n"
+  "Selected GCC installation: "
+  "/opt/rh/devtoolset-12/lib/gcc/x86_64-redhat-linux/11\n"
+  "Candidate multilib: .;@m64\n"
+  "Selected multilib: .;@m64\n",
+  S);
+  }
+}
+
 } // end anonymous namespace.
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2130,17 +2130,31 @@
   // and gcc-toolsets.
   if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux &&
   D.getVFS().exists("/opt/rh")) {
-Prefixes.push_back("/opt/rh/gcc-toolset-11/root/usr");
-Prefixes.push_back("/opt/rh/gcc-tool

[PATCH] D126757: Fix clang RecursiveASTVisitor for definition of XXXTemplateSpecializationDecl

2022-06-02 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

It seems you have uploaded just the changes relative to the previous patch. If 
you made a second commit, you need to `squash` it into the first and resubmit.

Otherwise the test looks good, thanks!




Comment at: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp:811
+  )cpp",
+  // Template specialization
+  R"cpp(

nit: `// Explicit template specialization` to be a bit more specific


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126757

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


[PATCH] D126758: [clang-format] Handle do-while loops for RemoveBracesLLVM

2022-06-02 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.h:118-119
   TokenType NextLBracesType = TT_Unknown,
+  bool *HasDoWhile = nullptr,
   bool *HasLabel = nullptr);
   bool tryToParseBracedList();

owenpan wrote:
> HazardyKnusperkeks wrote:
> > Should we merge that to something like `KeepBraces`? Or do we use 
> > `HasLabel` and `HasDoWhile` differently?
> We will use them differently. There will be no configuration for labels but 
> some configurations for do-while loops eventually.
Ok.


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

https://reviews.llvm.org/D126758

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


[PATCH] D124749: [clang-format] Handle Verilog preprocessor directives

2022-06-02 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1889
   TokenCount = Line->Tokens.size();
-  if (TokenCount == 1 ||
-  (TokenCount == 2 && Line->Tokens.front().Tok->is(tok::comment))) {

Why did you remove that if?



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1906
+
 if (FormatTok->is(tok::colon) && !Line->MustBeDeclaration) {
   Line->Tokens.begin()->Tok->MustBreakBefore = true;

And now the indentation here is off.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124749

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


[PATCH] D126340: [clang][AIX] add option -mdefault-visibility-export-mapping

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

It looks like this causes a major compile-time regression in the clang 
frontend: 
http://llvm-compile-time-tracker.com/compare.php?from=6232a8f3d61e5856c17e7b314385e9ea8068cdc1&to=8c8a2679a20f621994fa904bcfc68775e7345edc&stat=instructions
 For example, tramp3d-v4 is up 5% in `-O0` builds.

Not familiar with this area, but my first guess would be that 
getLinkageAndVisibility() is actually expensive and you're introducing a ton of 
calls to it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126340

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


[PATCH] D120495: [clang][dataflow] Add transfer functions for structured bindings

2022-06-02 Thread Stanislav Gatev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sgatev marked an inline comment as done.
Closed by commit rG0e286b77cf7b: [clang][dataflow] Add transfer functions for 
structured bindings (authored by sgatev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120495

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3369,4 +3369,192 @@
   LangStandard::lang_cxx17, /*ApplyBuiltinTransfer=*/true, "operator=");
 }
 
+TEST_F(TransferTest, StructuredBindingAssignFromStructIntMembersToRefs) {
+  std::string Code = R"(
+struct A {
+  int Foo;
+  int Bar;
+};
+
+void target() {
+  int Qux;
+  A Baz;
+  Baz.Foo = Qux;
+  auto &FooRef = Baz.Foo;
+  auto &BarRef = Baz.Bar;
+  auto &[BoundFooRef, BoundBarRef] = Baz;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooRefDecl = findValueDecl(ASTCtx, "FooRef");
+ASSERT_THAT(FooRefDecl, NotNull());
+
+const ValueDecl *BarRefDecl = findValueDecl(ASTCtx, "BarRef");
+ASSERT_THAT(BarRefDecl, NotNull());
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+
+const ValueDecl *BoundFooRefDecl = findValueDecl(ASTCtx, "BoundFooRef");
+ASSERT_THAT(BoundFooRefDecl, NotNull());
+
+const ValueDecl *BoundBarRefDecl = findValueDecl(ASTCtx, "BoundBarRef");
+ASSERT_THAT(BoundBarRefDecl, NotNull());
+
+const StorageLocation *FooRefLoc =
+Env.getStorageLocation(*FooRefDecl, SkipPast::Reference);
+ASSERT_THAT(FooRefLoc, NotNull());
+
+const StorageLocation *BarRefLoc =
+Env.getStorageLocation(*BarRefDecl, SkipPast::Reference);
+ASSERT_THAT(BarRefLoc, NotNull());
+
+const Value *QuxVal = Env.getValue(*QuxDecl, SkipPast::None);
+ASSERT_THAT(QuxVal, NotNull());
+
+const StorageLocation *BoundFooRefLoc =
+Env.getStorageLocation(*BoundFooRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundFooRefLoc, FooRefLoc);
+
+const StorageLocation *BoundBarRefLoc =
+Env.getStorageLocation(*BoundBarRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundBarRefLoc, BarRefLoc);
+
+EXPECT_EQ(Env.getValue(*BoundFooRefDecl, SkipPast::Reference), QuxVal);
+  });
+}
+
+TEST_F(TransferTest, StructuredBindingAssignFromStructRefMembersToRefs) {
+  std::string Code = R"(
+struct A {
+  int &Foo;
+  int &Bar;
+};
+
+void target(A Baz) {
+  int Qux;
+  Baz.Foo = Qux;
+  auto &FooRef = Baz.Foo;
+  auto &BarRef = Baz.Bar;
+  auto &[BoundFooRef, BoundBarRef] = Baz;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooRefDecl = findValueDecl(ASTCtx, "FooRef");
+ASSERT_THAT(FooRefDecl, NotNull());
+
+const ValueDecl *BarRefDecl = findValueDecl(ASTCtx, "BarRef");
+ASSERT_THAT(BarRefDecl, NotNull());
+
+const ValueDecl *QuxDecl = findValueDecl(ASTCtx, "Qux");
+ASSERT_THAT(QuxDecl, NotNull());
+
+const ValueDecl *BoundFooRefDecl = findValueDecl(ASTCtx, "BoundFooRef");
+ASSERT_THAT(BoundFooRefDecl, NotNull());
+
+const ValueDecl *BoundBarRefDecl = findValueDecl(ASTCtx, "BoundBarRef");
+ASSERT_THAT(BoundBarRefDecl, NotNull());
+
+const StorageLocation *FooRefLoc =
+Env.getStorageLocation(*FooRefDecl, SkipPast::Reference);
+ASSERT_THAT(FooRefLoc, NotNull());
+
+const StorageLocation *BarRefLoc =
+Env.getStorageLocation(*BarRefDecl, SkipPast::Reference);
+ASSERT_THAT(BarRefLoc, NotNull());
+
+const Value *QuxVal = Env.getValue(*QuxDecl, SkipPast::None);
+ASSERT_THAT(QuxVal, NotNull());
+
+const StorageLocation *BoundFooRefLoc =
+Env.getStorageLocation(*BoundFooRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundFooRefLoc, FooRefLoc);
+
+const StorageLocation *BoundBarRefLoc =
+Env.getStorageLocation(*BoundBarRefDecl, SkipPast::Reference);
+EXPECT_EQ(BoundBarRefLoc, BarR

[clang] 0e286b7 - [clang][dataflow] Add transfer functions for structured bindings

2022-06-02 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2022-06-02T08:02:26Z
New Revision: 0e286b77cf7bebca568b60ac81c1717291040bc3

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

LOG: [clang][dataflow] Add transfer functions for structured bindings

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

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

Reviewed-by: ymandel, xazax.hun

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index fc04e0b55ffc7..a56e277f7962f 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -136,9 +136,6 @@ class TransferVisitor : public 
ConstStmtVisitor {
   return;
 }
 
-InitExpr = D.getInit();
-assert(InitExpr != nullptr);
-
 if (D.getType()->isReferenceType()) {
   // Initializing a reference variable - do not create a reference to
   // reference.
@@ -147,25 +144,52 @@ class TransferVisitor : public 
ConstStmtVisitor {
 auto &Val =
 Env.takeOwnership(std::make_unique(*InitExprLoc));
 Env.setValue(Loc, Val);
-return;
   }
 } else if (auto *InitExprVal = Env.getValue(*InitExpr, SkipPast::None)) {
   Env.setValue(Loc, *InitExprVal);
-  return;
 }
 
-// We arrive here in (the few) cases where an expression is intentionally
-// "uninterpreted". There are two ways to handle this situation: propagate
-// the status, so that uninterpreted initializers result in uninterpreted
-// variables, or provide a default value. We choose the latter so that 
later
-// refinements of the variable can be used for reasoning about the
-// surrounding code.
-//
-// FIXME. If and when we interpret all language cases, change this to 
assert
-// that `InitExpr` is interpreted, rather than supplying a default value
-// (assuming we don't update the environment API to return references).
-if (Value *Val = Env.createValue(D.getType()))
-  Env.setValue(Loc, *Val);
+if (Env.getValue(Loc) == nullptr) {
+  // We arrive here in (the few) cases where an expression is intentionally
+  // "uninterpreted". There are two ways to handle this situation: 
propagate
+  // the status, so that uninterpreted initializers result in uninterpreted
+  // variables, or provide a default value. We choose the latter so that
+  // later refinements of the variable can be used for reasoning about the
+  // surrounding code.
+  //
+  // FIXME. If and when we interpret all language cases, change this to
+  // assert that `InitExpr` is interpreted, rather than supplying a default
+  // value (assuming we don't update the environment API to return
+  // references).
+  if (Value *Val = Env.createValue(D.getType()))
+Env.setValue(Loc, *Val);
+}
+
+if (const auto *Decomp = dyn_cast(&D)) {
+  // If VarDecl is a DecompositionDecl, evaluate each of its bindings. This
+  // needs to be evaluated after initializing the values in the storage for
+  // VarDecl, as the bindings refer to them.
+  // FIXME: Add support for ArraySubscriptExpr.
+  // FIXME: Consider adding AST nodes that are used for structured bindings
+  // to the CFG.
+  for (const auto *B : Decomp->bindings()) {
+auto *ME = dyn_cast_or_null(B->getBinding());
+if (ME == nullptr)
+  continue;
+
+auto *DE = dyn_cast_or_null(ME->getBase());
+if (DE == nullptr)
+  continue;
+
+// ME and its base haven't been visited because they aren't included in
+// the statements of the CFG basic block.
+VisitDeclRefExpr(DE);
+VisitMemberExpr(ME);
+
+if (auto *Loc = Env.getStorageLocation(*ME, SkipPast::Reference))
+  Env.setStorageLocation(*B, *Loc);
+  }
+}
   }
 
   void VisitImplicitCastExpr(const ImplicitCastExpr *S) {

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index efea7797b45fb..a8552161b70d0 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3369,4 +3369,192 @@ TEST_F(TransferTest, DoesNotCrashOnUnionThisExpr) {
   LangStandard::lang_cxx17, /*ApplyBuiltinTransfer=*/true, "operator=");
 }
 
+TEST_F(TransferTest, StructuredBindingAssignFromStructIntMembersToRefs) {
+  std::string Code = R"(
+struct A {
+  int Foo;
+  int Ba

[clang] db15e31 - [clang-format] Handle do-while loops for RemoveBracesLLVM

2022-06-02 Thread via cfe-commits

Author: owenca
Date: 2022-06-02T01:08:40-07:00
New Revision: db15e31212436ae51c04e8b5fcc2f140db4d6626

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

LOG: [clang-format] Handle do-while loops for RemoveBracesLLVM

Also updates the unit tests to match the updated LLVM Coding
Standards.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 9a5d85cead889..8de7fae9ae51d 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -480,6 +480,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
   : TT_Unknown;
   const bool IsPrecededByCommentOrPPDirective =
   !Style.RemoveBracesLLVM || precededByCommentOrPPDirective();
+  bool HasDoWhile = false;
   bool HasLabel = false;
   unsigned StatementCount = 0;
   bool SwitchLabelEncountered = false;
@@ -495,8 +496,9 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
   kind = tok::r_brace;
 
 auto ParseDefault = [this, OpeningBrace, IfKind, NextLevelLBracesType,
- &HasLabel, &StatementCount] {
+ &HasDoWhile, &HasLabel, &StatementCount] {
   parseStructuralElement(IfKind, !OpeningBrace, NextLevelLBracesType,
+ HasDoWhile ? nullptr : &HasDoWhile,
  HasLabel ? nullptr : &HasLabel);
   ++StatementCount;
   assert(StatementCount > 0 && "StatementCount overflow!");
@@ -536,7 +538,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
   return false;
 }
 if (FormatTok->isNot(tok::r_brace) || StatementCount != 1 || HasLabel 
||
-IsPrecededByCommentOrPPDirective ||
+HasDoWhile || IsPrecededByCommentOrPPDirective ||
 precededByCommentOrPPDirective()) {
   return false;
 }
@@ -1415,6 +1417,7 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() {
 void UnwrappedLineParser::parseStructuralElement(IfStmtKind *IfKind,
  bool IsTopLevel,
  TokenType NextLBracesType,
+ bool *HasDoWhile,
  bool *HasLabel) {
   if (Style.Language == FormatStyle::LK_TableGen &&
   FormatTok->is(tok::pp_include)) {
@@ -1476,6 +1479,8 @@ void 
UnwrappedLineParser::parseStructuralElement(IfStmtKind *IfKind,
   break;
 }
 parseDoWhile();
+if (HasDoWhile)
+  *HasDoWhile = true;
 return;
   case tok::kw_switch:
 if (Style.isJavaScript() && Line->MustBeDeclaration) {

diff  --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index ffba36cd01706..38f83a896e1d6 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -115,6 +115,7 @@ class UnwrappedLineParser {
   void parseStructuralElement(IfStmtKind *IfKind = nullptr,
   bool IsTopLevel = false,
   TokenType NextLBracesType = TT_Unknown,
+  bool *HasDoWhile = nullptr,
   bool *HasLabel = nullptr);
   bool tryToParseBracedList();
   bool parseBracedList(bool ContinueOnSemicolons = false, bool IsEnum = false,

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index c1257059c8649..f8f2715c39768 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25100,12 +25100,12 @@ TEST_F(FormatTest, RemoveBraces) {
   FormatStyle Style = getLLVMStyle();
   Style.RemoveBracesLLVM = true;
 
-  // The following eight test cases are fully-braced versions of the examples 
at
+  // The following test cases are fully-braced versions of the examples at
   // "llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-
   // statement-bodies-of-if-else-loop-statements".
 
-  // 1. Omit the braces, since the body is simple and clearly associated with
-  // the if.
+  // Omit the braces since the body is simple and clearly associated with the
+  // `if`.
   verifyFormat("if (isa(D))\n"
"  handleFunctionDecl(D);\n"
"else if (isa(D))\n"
@@ -25117,7 +25117,7 @@ TEST_F(FormatTest, RemoveBraces) {
"}",
Style);
 
-  // 2. Here we document the condition itself and not the body.
+  

[PATCH] D126758: [clang-format] Handle do-while loops for RemoveBracesLLVM

2022-06-02 Thread Owen Pan 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 rGdb15e3121243: [clang-format] Handle do-while loops for 
RemoveBracesLLVM (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126758

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25100,12 +25100,12 @@
   FormatStyle Style = getLLVMStyle();
   Style.RemoveBracesLLVM = true;
 
-  // The following eight test cases are fully-braced versions of the examples at
+  // The following test cases are fully-braced versions of the examples at
   // "llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-
   // statement-bodies-of-if-else-loop-statements".
 
-  // 1. Omit the braces, since the body is simple and clearly associated with
-  // the if.
+  // Omit the braces since the body is simple and clearly associated with the
+  // `if`.
   verifyFormat("if (isa(D))\n"
"  handleFunctionDecl(D);\n"
"else if (isa(D))\n"
@@ -25117,7 +25117,7 @@
"}",
Style);
 
-  // 2. Here we document the condition itself and not the body.
+  // Here we document the condition itself and not the body.
   verifyFormat("if (isa(D)) {\n"
"  // It is necessary that we explain the situation with this\n"
"  // surprisingly long comment, so it would be unclear\n"
@@ -25125,32 +25125,29 @@
"  // the scope of the `if`.\n"
"  // Because the condition is documented, we can't really\n"
"  // hoist this comment that applies to the body above the\n"
-   "  // if.\n"
+   "  // `if`.\n"
"  handleOtherDecl(D);\n"
"}",
Style);
 
-  // 3. Use braces on the outer `if` to avoid a potential dangling else
+  // Use braces on the outer `if` to avoid a potential dangling `else`
   // situation.
   verifyFormat("if (isa(D)) {\n"
-   "  for (auto *A : D.attrs())\n"
-   "if (shouldProcessAttr(A))\n"
-   "  handleAttr(A);\n"
+   "  if (shouldProcessAttr(A))\n"
+   "handleAttr(A);\n"
"}",
"if (isa(D)) {\n"
-   "  for (auto *A : D.attrs()) {\n"
-   "if (shouldProcessAttr(A)) {\n"
-   "  handleAttr(A);\n"
-   "}\n"
+   "  if (shouldProcessAttr(A)) {\n"
+   "handleAttr(A);\n"
"  }\n"
"}",
Style);
 
-  // 4. Use braces for the `if` block to keep it uniform with the else block.
+  // Use braces for the `if` block to keep it uniform with the `else` block.
   verifyFormat("if (isa(D)) {\n"
"  handleFunctionDecl(D);\n"
"} else {\n"
-   "  // In this else case, it is necessary that we explain the\n"
+   "  // In this `else` case, it is necessary that we explain the\n"
"  // situation with this surprisingly long comment, so it\n"
"  // would be unclear without the braces whether the\n"
"  // following statement is in the scope of the `if`.\n"
@@ -25158,9 +25155,9 @@
"}",
Style);
 
-  // 5. This should also omit braces.  The `for` loop contains only a single
+  // This should also omit braces. The `for` loop contains only a single
   // statement, so it shouldn't have braces.  The `if` also only contains a
-  // single simple statement (the for loop), so it also should omit braces.
+  // single simple statement (the `for` loop), so it also should omit braces.
   verifyFormat("if (isa(D))\n"
"  for (auto *A : D.attrs())\n"
"handleAttr(A);",
@@ -25171,18 +25168,26 @@
"}",
Style);
 
-  // 6. Use braces for the outer `if` since the nested `for` is braced.
+  // Use braces for a `do-while` loop and its enclosing statement.
+  verifyFormat("if (Tok->is(tok::l_brace)) {\n"
+   "  do {\n"
+   "Tok = Tok->Next;\n"
+   "  } while (Tok);\n"
+   "}",
+   Style);
+
+  // Use braces for the outer `if` since the nested `for` is braced.
   verifyFormat("if (isa(D)) {\n"
"  for (auto *A : D.attrs()) {\n"
-   "// In this for loop body, it is necessary that we explain\n"
-   "// the situation with this surprisingly long comment,\n"
-   "// forcing braces on the `for` block.\n"
+

[PATCH] D126859: [clangd] Validate clang-tidy CheckOptions in clangd config

2022-06-02 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: sammccall, kadircet.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
njames93 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Expand D92874  to also ensure all items in 
CheckOptions correspond to actual options in the clang-tidy checks.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126859

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

Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -338,7 +338,9 @@
   EXPECT_EQ(
   Conf.Diagnostics.ClangTidy.Checks,
   "bugprone-use-after-move,llvm-*,-llvm-include-order,-readability-*");
-  EXPECT_THAT(Diags.Diagnostics, IsEmpty());
+  EXPECT_THAT(Diags.Diagnostics,
+  ElementsAre(diagMessage(
+  "unknown clang-tidy option 'example-check.ExampleOption'")));
 #else // !CLANGD_TIDY_CHECKS
   EXPECT_EQ(Conf.Diagnostics.ClangTidy.Checks, "llvm-*,-readability-*");
   EXPECT_THAT(
@@ -346,7 +348,9 @@
   ElementsAre(
   diagMessage(
   "clang-tidy check 'bugprone-use-after-move' was not found"),
-  diagMessage("clang-tidy check 'llvm-include-order' was not found")));
+  diagMessage("clang-tidy check 'llvm-include-order' was not found"),
+  diagMessage(
+  "unknown clang-tidy option 'example-check.ExampleOption'")));
 #endif
 }
 
@@ -355,6 +359,15 @@
   Tidy.Add.emplace_back("unknown-check");
   Tidy.Remove.emplace_back("*");
   Tidy.Remove.emplace_back("llvm-includeorder");
+#if CLANGD_TIDY_CHECKS
+  StringRef IncludeOrderMessage =
+  "clang-tidy check 'llvm-includeorder' was not found; did you mean "
+  "'llvm-include-order'";
+#else // !CLANGD_TIDY_CHECKS
+  StringRef IncludeOrderMessage =
+  "clang-tidy check 'llvm-includeorder' was not found";
+#endif
+
   EXPECT_TRUE(compileAndApply());
   // Ensure bad checks are stripped from the glob.
   EXPECT_EQ(Conf.Diagnostics.ClangTidy.Checks, "-*");
@@ -363,9 +376,49 @@
   ElementsAre(
   AllOf(diagMessage("clang-tidy check 'unknown-check' was not found"),
 diagKind(llvm::SourceMgr::DK_Warning)),
-  AllOf(
-  diagMessage("clang-tidy check 'llvm-includeorder' was not found"),
-  diagKind(llvm::SourceMgr::DK_Warning;
+  AllOf(diagMessage(IncludeOrderMessage),
+diagKind(llvm::SourceMgr::DK_Warning;
+}
+
+TEST_F(ConfigCompileTests, TidyBadOptions) {
+  auto &Tidy = Frag.Diagnostics.ClangTidy;
+  Tidy.CheckOptions.emplace_back(
+  std::make_pair(std::string("BadGlobal"), std::string("true")));
+  Tidy.CheckOptions.emplace_back(
+  std::make_pair(std::string("StrictModes"), std::string("true")));
+  Tidy.CheckOptions.emplace_back(std::make_pair(
+  std::string("readability-braces-around-statements.ShortStatementsLines"),
+  std::string("1")));
+  Tidy.CheckOptions.emplace_back(std::make_pair(
+  std::string("readability-braces-around-statements.ShortStatementLines"),
+  std::string("1")));
+  EXPECT_TRUE(compileAndApply());
+#if CLANGD_TIDY_CHECKS
+  EXPECT_THAT(
+  Diags.Diagnostics,
+  ElementsAre(
+  diagMessage("unknown clang-tidy option 'BadGlobal'"),
+  diagMessage("unknown clang-tidy option 'StrictModes'; did you mean "
+  "'StrictMode'"),
+  diagMessage(
+  "unknown clang-tidy option "
+  "'readability-braces-around-statements.ShortStatementsLines'; "
+  "did you mean "
+  "'readability-braces-around-statements.ShortStatementLines'")));
+#else // !CLANGD_TIDY_CHECKS
+  EXPECT_THAT(
+  Diags.Diagnostics,
+  ElementsAre(
+  diagMessage("unknown clang-tidy option 'BadGlobal'"),
+  diagMessage("unknown clang-tidy option 'StrictModes'; did you mean "
+  "'StrictMode'"),
+  diagMessage(
+  "unknown clang-tidy option "
+  "'readability-braces-around-statements.ShortStatementsLines'"),
+  diagMessage(
+  "unknown clang-tidy option "
+  "'readability-braces-around-statements.ShortStatementLines'")));
+#endif
 }
 
 TEST_F(ConfigCompileTests, ExternalServerNeedsTrusted) {
Index: clang-tools-extra/clangd/TidyProvider.h
===
--- clang-tools-extra/clangd/TidyProvider.h
+++ clang-tools-extra/clangd/TidyProvider.h
@@ -58,7 +58,11 @@
 
 /// Returns if \p Check is a register

[PATCH] D126801: [analyzer][NFC] Add partial specializations for ProgramStateTraits

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

Nice!




Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h:287
 
-  // Partial specialization for void*.
-  template <> struct ProgramStatePartialTrait {
-using data_type = void *;
+  // Partial specialization for enums.
+  template 

How is it different than the partial specialization for integral types? Could 
we have the 2 contracted?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126801

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


[PATCH] D126742: [RISCV][Clang] Support RVV policy functions.

2022-06-02 Thread Yeting Kuo via Phabricator via cfe-commits
fakepaper56 added inline comments.



Comment at: clang/lib/Sema/SemaRVVLookup.cpp:329
+
+  auto appendPolicySuffix = [&](std::string suffix) {
+Name += suffix;

Using `const std::string &suffix`.



Comment at: clang/lib/Support/RISCVVIntrinsicUtils.cpp:876
+
+  auto appendPolicySuffix = [&](std::string suffix) {
+Name += suffix;

Using `const std::string &suffix`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126742

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


[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-02 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a subscriber: tonic.
tstellar added a comment.

In D125624#3552463 , @ruiu wrote:

>> OK, as I mentioned. I think we need an attorney to review this change and 
>> confirm that it actually accomplishes this goal.
>
> Can you add an attorney as a reviewer of this change so that we can proceed?

Yes, I've notified @tonic and she will reach out to the attorney.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[clang] f730749 - [clang] [ARM] Add __builtin_sponentry like on aarch64

2022-06-02 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2022-06-02T12:29:59+03:00
New Revision: f730749e8584fe7ea3927d0359f20d167d281e80

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

LOG: [clang] [ARM] Add __builtin_sponentry like on aarch64

This is used for calling the SEH aware setjmp on MinGW.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsARM.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtin-sponentry.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsARM.def 
b/clang/include/clang/Basic/BuiltinsARM.def
index be20c24aa28ae..0cea0a9051e5b 100644
--- a/clang/include/clang/Basic/BuiltinsARM.def
+++ b/clang/include/clang/Basic/BuiltinsARM.def
@@ -197,6 +197,9 @@ BUILTIN(__builtin_arm_wsr, "vcC*Ui", "nc")
 BUILTIN(__builtin_arm_wsr64, "vcC*LLUi", "nc")
 BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc")
 
+// Misc
+BUILTIN(__builtin_sponentry, "v*", "c")
+
 // Builtins for implementing ACLE MVE intrinsics. (Unlike NEON, these
 // don't need to live in a separate BuiltinsMVE.def, because they
 // aren't included from both here and BuiltinsAArch64.def.)

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bdc638299c4bd..1c10d32de5fe9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7783,6 +7783,11 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
   AccessKind);
   }
 
+  if (BuiltinID == ARM::BI__builtin_sponentry) {
+llvm::Function *F = CGM.getIntrinsic(Intrinsic::sponentry, 
AllocaInt8PtrTy);
+return Builder.CreateCall(F);
+  }
+
   // Handle MSVC intrinsics before argument evaluation to prevent double
   // evaluation.
   if (Optional MsvcIntId = translateArmToMsvcIntrin(BuiltinID))

diff  --git a/clang/test/CodeGen/builtin-sponentry.c 
b/clang/test/CodeGen/builtin-sponentry.c
index ce389f6aee374..7487f602f36b8 100644
--- a/clang/test/CodeGen/builtin-sponentry.c
+++ b/clang/test/CodeGen/builtin-sponentry.c
@@ -1,8 +1,9 @@
 // RUN: %clang_cc1 -no-opaque-pointers -triple aarch64-windows-gnu -Oz 
-emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -triple thumbv7-windows-gnu -Oz 
-emit-llvm %s -o - | FileCheck %s
 
 void *test_sponentry(void) {
   return __builtin_sponentry();
 }
-// CHECK-LABEL: define dso_local i8* @test_sponentry()
+// CHECK-LABEL: define dso_local {{(arm_aapcs_vfpcc )?}}i8* @test_sponentry()
 // CHECK: = tail call i8* @llvm.sponentry.p0i8()
 // CHECK: ret i8*



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


[PATCH] D126764: [clang] [ARM] Add __builtin_sponentry like on aarch64

2022-06-02 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf730749e8584: [clang] [ARM] Add __builtin_sponentry like on 
aarch64 (authored by mstorsjo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126764

Files:
  clang/include/clang/Basic/BuiltinsARM.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtin-sponentry.c


Index: clang/test/CodeGen/builtin-sponentry.c
===
--- clang/test/CodeGen/builtin-sponentry.c
+++ clang/test/CodeGen/builtin-sponentry.c
@@ -1,8 +1,9 @@
 // RUN: %clang_cc1 -no-opaque-pointers -triple aarch64-windows-gnu -Oz 
-emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -triple thumbv7-windows-gnu -Oz 
-emit-llvm %s -o - | FileCheck %s
 
 void *test_sponentry(void) {
   return __builtin_sponentry();
 }
-// CHECK-LABEL: define dso_local i8* @test_sponentry()
+// CHECK-LABEL: define dso_local {{(arm_aapcs_vfpcc )?}}i8* @test_sponentry()
 // CHECK: = tail call i8* @llvm.sponentry.p0i8()
 // CHECK: ret i8*
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -7783,6 +7783,11 @@
   AccessKind);
   }
 
+  if (BuiltinID == ARM::BI__builtin_sponentry) {
+llvm::Function *F = CGM.getIntrinsic(Intrinsic::sponentry, 
AllocaInt8PtrTy);
+return Builder.CreateCall(F);
+  }
+
   // Handle MSVC intrinsics before argument evaluation to prevent double
   // evaluation.
   if (Optional MsvcIntId = translateArmToMsvcIntrin(BuiltinID))
Index: clang/include/clang/Basic/BuiltinsARM.def
===
--- clang/include/clang/Basic/BuiltinsARM.def
+++ clang/include/clang/Basic/BuiltinsARM.def
@@ -197,6 +197,9 @@
 BUILTIN(__builtin_arm_wsr64, "vcC*LLUi", "nc")
 BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc")
 
+// Misc
+BUILTIN(__builtin_sponentry, "v*", "c")
+
 // Builtins for implementing ACLE MVE intrinsics. (Unlike NEON, these
 // don't need to live in a separate BuiltinsMVE.def, because they
 // aren't included from both here and BuiltinsAArch64.def.)


Index: clang/test/CodeGen/builtin-sponentry.c
===
--- clang/test/CodeGen/builtin-sponentry.c
+++ clang/test/CodeGen/builtin-sponentry.c
@@ -1,8 +1,9 @@
 // RUN: %clang_cc1 -no-opaque-pointers -triple aarch64-windows-gnu -Oz -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -triple thumbv7-windows-gnu -Oz -emit-llvm %s -o - | FileCheck %s
 
 void *test_sponentry(void) {
   return __builtin_sponentry();
 }
-// CHECK-LABEL: define dso_local i8* @test_sponentry()
+// CHECK-LABEL: define dso_local {{(arm_aapcs_vfpcc )?}}i8* @test_sponentry()
 // CHECK: = tail call i8* @llvm.sponentry.p0i8()
 // CHECK: ret i8*
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -7783,6 +7783,11 @@
   AccessKind);
   }
 
+  if (BuiltinID == ARM::BI__builtin_sponentry) {
+llvm::Function *F = CGM.getIntrinsic(Intrinsic::sponentry, AllocaInt8PtrTy);
+return Builder.CreateCall(F);
+  }
+
   // Handle MSVC intrinsics before argument evaluation to prevent double
   // evaluation.
   if (Optional MsvcIntId = translateArmToMsvcIntrin(BuiltinID))
Index: clang/include/clang/Basic/BuiltinsARM.def
===
--- clang/include/clang/Basic/BuiltinsARM.def
+++ clang/include/clang/Basic/BuiltinsARM.def
@@ -197,6 +197,9 @@
 BUILTIN(__builtin_arm_wsr64, "vcC*LLUi", "nc")
 BUILTIN(__builtin_arm_wsrp, "vcC*vC*", "nc")
 
+// Misc
+BUILTIN(__builtin_sponentry, "v*", "c")
+
 // Builtins for implementing ACLE MVE intrinsics. (Unlike NEON, these
 // don't need to live in a separate BuiltinsMVE.def, because they
 // aren't included from both here and BuiltinsAArch64.def.)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126781: [CodeGen] Correctly handle weak symbols in the codegen

2022-06-02 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 433694.
junaire added a comment.

also swap TBAA


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -248,4 +248,22 @@
   EXPECT_EQ(42, fn(NewA));
 }
 
+TEST(InterpreterTest, InlineDecls) {
+  Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
+
+  // Create the diagnostic engine with unowned consumer.
+  std::string DiagnosticOutput;
+  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+  auto DiagPrinter = std::make_unique(
+  DiagnosticsOS, new DiagnosticOptions());
+
+  auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
+
+  auto R1 = Interp->Parse("inline int foo() { return 42;}");
+  EXPECT_TRUE(!!R1);
+
+  auto R2 = Interp->Parse("int x = foo();");
+  EXPECT_TRUE(!!R2);
+}
+
 } // end anonymous namespace
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -133,8 +133,40 @@
 llvm::Module *StartModule(llvm::StringRef ModuleName,
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
+
+  std::unique_ptr OldBuilder;
+  OldBuilder.swap(Builder);
+
+  assert(OldBuilder->getEmittedDeferredDecls().empty() &&
+ "Still have (unmerged) EmittedDeferredDecls deferred decls");
+
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
   Initialize(*Ctx);
+
+  assert(OldBuilder->getDeferredDeclsToEmit().empty() &&
+ "Should have emitted all decls deferred to emit.");
+  assert(Builder->getDeferredDecls().empty() &&
+ "Newly created module should not have deferred decls");
+
+  Builder->getDeferredDecls().swap(OldBuilder->getDeferredDecls());
+
+  assert(Builder->getDeferredVTables().empty() &&
+ "Newly created module should not have deferred vtables");
+
+  Builder->getDeferredVTables().swap(OldBuilder->getDeferredVTables());
+
+  assert(Builder->getMangledDeclNames().empty() &&
+ "Newly created module should not have mangled decl names");
+  assert(Builder->getManglings().empty() &&
+ "Newly created module should not have manglings");
+
+  Builder->getManglings() = std::move(OldBuilder->getManglings());
+
+  assert(OldBuilder->getWeakRefReferences().empty() &&
+ "Not all WeakRefRefs have been applied");
+
+  Builder->getTBAA().swap(OldBuilder->getTBAA());
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -339,11 +339,30 @@
   /// yet.
   llvm::DenseMap DeferredDecls;
 
+  /// Decls that were DeferredDecls and have now been emitted.
+  llvm::DenseMap EmittedDeferredDecls;
+
+  void addEmittedDeferredDecl(GlobalDecl GD) {
+bool IsAFunction = isa(GD.getDecl());
+const VarDecl *VD = IsAFunction ? nullptr : dyn_cast(GD.getDecl());
+assert((IsAFunction || VD) && "Unexpected Decl type!");
+llvm::GlobalValue::LinkageTypes L =
+IsAFunction
+? getFunctionLinkage(GD)
+: getLLVMLinkageVarDefinition(
+  VD, isTypeConstant(VD->getType(), /*ExcludeCtor=*/false));
+if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+llvm::GlobalValue::isWeakLinkage(L)) {
+  EmittedDeferredDecls[getMangledName(GD)] = GD;
+}
+  }
+
   /// This is a list of deferred decls which we have seen that *are* actually
   /// referenced. These get code generated when the module is done.
   std::vector DeferredDeclsToEmit;
   void addDeferredDeclToEmit(GlobalDecl GD) {
 DeferredDeclsToEmit.emplace_back(GD);
+addEmittedDeferredDecl(GD);
   }
 
   /// List of alias we have emitted. Used to make sure that what they point to
@@ -1477,6 +1496,36 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  llvm::SmallPtrSetImpl &getEmittedDeferredDecls() {
+return EmittedModuleInitializers;
+  }
+
+  llvm::DenseMap &getDeferredDecls() {
+return DeferredDecls;
+  }
+
+  std::vector &getDeferredDeclsToEmit() {
+return DeferredDeclsToEmit;
+  }
+
+  std::vector &getDeferredVTables() {
+return DeferredVTables;
+  }
+
+  llvm::MapVector &getMangledDeclNames() {
+return MangledDeclNames;
+  }
+
+  llvm::String

[PATCH] D126862: [clang] [MSVC] Enable unwind tables for ARM

2022-06-02 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: efriedma, zzheng.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: clang.

The backend now can generate working unwind information for this
target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126862

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp


Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -449,8 +449,8 @@
   // All non-x86_32 Windows targets require unwind tables. However, LLVM
   // doesn't know how to generate them for all targets, so only enable
   // the ones that are actually implemented.
-  return getArch() == llvm::Triple::x86_64 ||
- getArch() == llvm::Triple::aarch64;
+  return getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::arm ||
+ getArch() == llvm::Triple::thumb || getArch() == 
llvm::Triple::aarch64;
 }
 
 bool MSVCToolChain::isPICDefault() const {


Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -449,8 +449,8 @@
   // All non-x86_32 Windows targets require unwind tables. However, LLVM
   // doesn't know how to generate them for all targets, so only enable
   // the ones that are actually implemented.
-  return getArch() == llvm::Triple::x86_64 ||
- getArch() == llvm::Triple::aarch64;
+  return getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::arm ||
+ getArch() == llvm::Triple::thumb || getArch() == llvm::Triple::aarch64;
 }
 
 bool MSVCToolChain::isPICDefault() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays for stricter handling of flexible arrays

2022-06-02 Thread serge via Phabricator via cfe-commits
serge-sans-paille created this revision.
serge-sans-paille added reviewers: george.burgess.iv, kees.
Herald added subscribers: krytarowski, arichardson, emaste.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Some code [0] consider that trailing arrays are flexible, whatever their size.
Support for these legacy code has been introduced in
f8f632498307d22e10fab0704548b270b15f1e1e but it prevents evaluation of
__builtin_object_size in some legit cases. Introduce -fstrict-flex-arrays to
have stricter conformance when it is desirable.

[0] 
https://docs.freebsd.org/en/books/developers-handbook/sockets/#sockets-essential-functions


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126864

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/object-size-flex-array.c

Index: clang/test/CodeGen/object-size-flex-array.c
===
--- /dev/null
+++ clang/test/CodeGen/object-size-flex-array.c
@@ -0,0 +1,60 @@
+// RUN: %clang -fstrict-flex-arrays-target x86_64-apple-darwin -S -emit-llvm %s -o - 2>&1 | FileCheck --check-prefix CHECK-STRICT %s
+// RUN: %clang -fno-strict-flex-arrays -target x86_64-apple-darwin -S -emit-llvm %s -o - 2>&1 | FileCheck %s
+
+#ifndef DYNAMIC
+#define OBJECT_SIZE_BUILTIN __builtin_object_size
+#else
+#define OBJECT_SIZE_BUILTIN __builtin_dynamic_object_size
+#endif
+
+typedef struct {
+  float f;
+  double c[];
+} foo_t;
+
+typedef struct {
+  float f;
+  double c[0];
+} foo0_t;
+
+typedef struct {
+  float f;
+  double c[1];
+} foo1_t;
+
+typedef struct {
+  float f;
+  double c[2];
+} foo2_t;
+
+// CHECK-LABEL: @bar
+// CHECK-STRICT-LABEL: @bar
+unsigned bar(foo_t *f) {
+  // CHECK: ret i32 %
+  // CHECK-STRICT: ret i32 %
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
+}
+
+// CHECK-LABEL: @bar0
+// CHECK-STRICT-LABEL: @bar
+unsigned bar0(foo0_t *f) {
+  // CHECK: ret i32 %
+  // CHECK-STRICT: ret i32 0
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
+}
+
+// CHECK-LABEL: @bar1
+// CHECK-STRICT-LABEL: @bar
+unsigned bar1(foo1_t *f) {
+  // CHECK: ret i32 %
+  // CHECK-STRICT: ret i32 8
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
+}
+
+// CHECK-LABEL: @bar2
+// CHECK-STRICT-LABEL: @bar
+unsigned bar2(foo2_t *f) {
+  // CHECK: ret i32 %
+  // CHECK-STRICT: ret i32 16
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6214,6 +6214,9 @@
   Args.AddLastArg(CmdArgs, options::OPT_funroll_loops,
   options::OPT_fno_unroll_loops);
 
+  Args.addOptInFlag(CmdArgs, options::OPT_fstrict_flex_arrays,
+options::OPT_fno_strict_flex_arrays);
+
   Args.AddLastArg(CmdArgs, options::OPT_pthread);
 
   if (Args.hasFlag(options::OPT_mspeculative_load_hardening,
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -11600,6 +11600,8 @@
   return LVal.InvalidBase &&
  Designator.Entries.size() == Designator.MostDerivedPathLength &&
  Designator.MostDerivedIsArrayElement &&
+ (Designator.isMostDerivedAnUnsizedArray() ||
+  !Ctx.getLangOpts().StrictFlexArrays) &&
  isDesignatorAtObjectEnd(Ctx, LVal);
 }
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1132,6 +1132,10 @@
 def fapple_kext : Flag<["-"], "fapple-kext">, Group, Flags<[CC1Option]>,
   HelpText<"Use Apple's kernel extensions ABI">,
   MarshallingInfoFlag>;
+defm strict_flex_arrays : BoolFOption<"strict-flex-arrays",
+  LangOpts<"StrictFlexArrays">, DefaultFalse,
+  PosFlag,
+  NegFlag>;
 defm apple_pragma_pack : BoolFOption<"apple-pragma-pack",
   LangOpts<"ApplePragmaPack">, DefaultFalse,
   PosFlag,
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -422,6 +422,7 @@
 LANGOPT(RegisterStaticDestructors, 1, 1, "Register C++ static destructors")
 
 LANGOPT(MatrixTypes, 1, 0, "Enable or disable the builtin matrix type")
+LANGOPT(StrictFlexArrays, 1, 0, "Rely on strict definition of flexible arrays")
 
 COMPATIBLE_VALUE_LANGOPT(MaxTokens, 32, 0, "Max number of tokens per TU or 0")
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/

[PATCH] D126865: [clang] [Headers] Check __SEH__, when checking if ARM EHABI is implied

2022-06-02 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: MaskRay, efriedma, zzheng.
Herald added subscribers: StephenFan, kristof.beyls.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: clang.

ARM EHABI isn't signalled by any specific compiler builtin define,
but is implied by the lack of defines specifying any other
exception handling mechanism, `__USING_SJLJ_EXCEPTIONS__` or
`__ARM_DWARF_EH__`.

As Windows SEH also can be used for unwinding, check for the
`__SEH__` define too, in the same way.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126865

Files:
  clang/lib/Headers/unwind.h


Index: clang/lib/Headers/unwind.h
===
--- clang/lib/Headers/unwind.h
+++ clang/lib/Headers/unwind.h
@@ -62,7 +62,8 @@
 typedef uintptr_t _uleb128_t;
 
 struct _Unwind_Context;
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || 
defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 struct _Unwind_Control_Block;
 typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
 #else
@@ -72,7 +73,7 @@
 typedef enum {
   _URC_NO_REASON = 0,
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
-!defined(__ARM_DWARF_EH__)
+!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
   _URC_OK = 0, /* used by ARM EHABI */
 #endif
   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
@@ -86,7 +87,7 @@
   _URC_INSTALL_CONTEXT = 7,
   _URC_CONTINUE_UNWIND = 8,
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
-!defined(__ARM_DWARF_EH__)
+!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
   _URC_FAILURE = 9 /* used by ARM EHABI */
 #endif
 } _Unwind_Reason_Code;
@@ -103,7 +104,8 @@
 typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code,
  _Unwind_Exception *);
 
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || 
defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 typedef struct _Unwind_Control_Block _Unwind_Control_Block;
 typedef uint32_t _Unwind_EHT_Header;
 
@@ -167,7 +169,8 @@
 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
 void *);
 
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || 
defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) ||
\
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 typedef enum {
   _UVRSC_CORE = 0,/* integer register */
   _UVRSC_VFP = 1, /* vfp */


Index: clang/lib/Headers/unwind.h
===
--- clang/lib/Headers/unwind.h
+++ clang/lib/Headers/unwind.h
@@ -62,7 +62,8 @@
 typedef uintptr_t _uleb128_t;
 
 struct _Unwind_Context;
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 struct _Unwind_Control_Block;
 typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
 #else
@@ -72,7 +73,7 @@
 typedef enum {
   _URC_NO_REASON = 0,
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
-!defined(__ARM_DWARF_EH__)
+!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
   _URC_OK = 0, /* used by ARM EHABI */
 #endif
   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
@@ -86,7 +87,7 @@
   _URC_INSTALL_CONTEXT = 7,
   _URC_CONTINUE_UNWIND = 8,
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
-!defined(__ARM_DWARF_EH__)
+!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
   _URC_FAILURE = 9 /* used by ARM EHABI */
 #endif
 } _Unwind_Reason_Code;
@@ -103,7 +104,8 @@
 typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code,
  _Unwind_Exception *);
 
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 typedef struct _Unwind_Control_Block _Unwind_Control_Block;
 typedef uint32_t _Unwind_EHT_Header;
 
@@ -167,7 +169,8 @@
 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
 void *);
 
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) ||\
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 typedef enum {
   _UVRSC_CORE = 0,/* integer register */
   _UVRSC_VFP = 1,

[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays for stricter handling of flexible arrays

2022-06-02 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

Note: I named the option `-fstrict-flex-arrays` and not `-fstrict-flex-array` 
because we already have `-fstrict-enums`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126864

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


[PATCH] D124749: [clang-format] Handle Verilog preprocessor directives

2022-06-02 Thread sstwcw via Phabricator via cfe-commits
sstwcw marked 2 inline comments as done.
sstwcw added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1889
   TokenCount = Line->Tokens.size();
-  if (TokenCount == 1 ||
-  (TokenCount == 2 && Line->Tokens.front().Tok->is(tok::comment))) {

HazardyKnusperkeks wrote:
> Why did you remove that if?
Previously the if checked whether the line is comment and an identifier.  For 
Verilog it's comment, a backtick, and an identifier. I found it easier to break 
if the line doesn't match the pattern.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124749

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


[clang] 81e4441 - [analyzer][NFC] Move overconstrained check from reAssume to assumeDualImpl

2022-06-02 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2022-06-02T11:41:19+02:00
New Revision: 81e44414aa925f5dcaf05ef658d1bffd8937ef4c

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

LOG: [analyzer][NFC] Move overconstrained check from reAssume to assumeDualImpl

Depends on D126406. Checking of the overconstrained property is much
better suited here.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
index 78abd0a0e42d7..ffae070b48a9f 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -118,8 +118,6 @@ class ProgramState : public llvm::FoldingSetNode {
   // overconstrained-related functions. We want to keep this API inaccessible
   // for Checkers.
   friend class ConstraintManager;
-  friend ProgramStateRef reAssume(ProgramStateRef State,
-  const RangeSet *Constraint, SVal TheValue);
   bool isPosteriorlyOverconstrained() const {
 return PosteriorlyOverconstrained;
   }

diff  --git a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
index 096266f75ce6c..8b04d3df845d9 100644
--- a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -46,6 +46,9 @@ template 
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDualImpl(ProgramStateRef &State,
   AssumeFunction &Assume) {
+  if (State->isPosteriorlyOverconstrained())
+return {State, State};
+
   ProgramStateRef StTrue = Assume(true);
 
   if (!StTrue) {

diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index bf535a8d02057..e788a7a608302 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -20,8 +20,8 @@
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/ImmutableSet.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -2535,19 +2535,10 @@ EquivalenceClass::removeMember(ProgramStateRef State, 
const SymbolRef Old) {
   return State;
 }
 
-// We must declare reAssume in clang::ento, otherwise we could not declare that
-// as a friend in ProgramState. More precisely, the call of reAssume would be
-// ambiguous (one in the global namespace and an other which is declared in
-// ProgramState is in clang::ento).
-namespace clang {
-namespace ento {
 // Re-evaluate an SVal with top-level `State->assume` logic.
 LLVM_NODISCARD ProgramStateRef reAssume(ProgramStateRef State,
 const RangeSet *Constraint,
 SVal TheValue) {
-  assert(State);
-  if (State->isPosteriorlyOverconstrained())
-return nullptr;
   if (!Constraint)
 return State;
 
@@ -2570,8 +2561,6 @@ LLVM_NODISCARD ProgramStateRef reAssume(ProgramStateRef 
State,
   return State->assumeInclusiveRange(DefinedVal, Constraint->getMinValue(),
  Constraint->getMaxValue(), true);
 }
-} // namespace ento
-} // namespace clang
 
 // Iterate over all symbols and try to simplify them. Once a symbol is
 // simplified then we check if we can merge the simplified symbol's equivalence



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


[PATCH] D126707: [analyzer][NFC] Move overconstrained check from reAssume to assumeDualImpl

2022-06-02 Thread Gabor Marton 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 rG81e44414aa92: [analyzer][NFC] Move overconstrained check 
from reAssume to assumeDualImpl (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126707

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp


Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -20,8 +20,8 @@
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/ImmutableSet.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -2535,19 +2535,10 @@
   return State;
 }
 
-// We must declare reAssume in clang::ento, otherwise we could not declare that
-// as a friend in ProgramState. More precisely, the call of reAssume would be
-// ambiguous (one in the global namespace and an other which is declared in
-// ProgramState is in clang::ento).
-namespace clang {
-namespace ento {
 // Re-evaluate an SVal with top-level `State->assume` logic.
 LLVM_NODISCARD ProgramStateRef reAssume(ProgramStateRef State,
 const RangeSet *Constraint,
 SVal TheValue) {
-  assert(State);
-  if (State->isPosteriorlyOverconstrained())
-return nullptr;
   if (!Constraint)
 return State;
 
@@ -2570,8 +2561,6 @@
   return State->assumeInclusiveRange(DefinedVal, Constraint->getMinValue(),
  Constraint->getMaxValue(), true);
 }
-} // namespace ento
-} // namespace clang
 
 // Iterate over all symbols and try to simplify them. Once a symbol is
 // simplified then we check if we can merge the simplified symbol's equivalence
Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -46,6 +46,9 @@
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDualImpl(ProgramStateRef &State,
   AssumeFunction &Assume) {
+  if (State->isPosteriorlyOverconstrained())
+return {State, State};
+
   ProgramStateRef StTrue = Assume(true);
 
   if (!StTrue) {
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -118,8 +118,6 @@
   // overconstrained-related functions. We want to keep this API inaccessible
   // for Checkers.
   friend class ConstraintManager;
-  friend ProgramStateRef reAssume(ProgramStateRef State,
-  const RangeSet *Constraint, SVal TheValue);
   bool isPosteriorlyOverconstrained() const {
 return PosteriorlyOverconstrained;
   }


Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -20,8 +20,8 @@
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/ImmutableSet.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -2535,19 +2535,10 @@
   return State;
 }
 
-// We must declare reAssume in clang::ento, otherwise we could not declare that
-// as a friend in ProgramState. More precisely, the call of reAssume would be
-// ambiguous (one in the global namespace and an other which is declared in
-// ProgramState is in clang::ento).
-namespace clang {
-namespace ento {
 // Re-evaluate an SVal with top-level `State->assume` logic.
 LLVM_NODISCARD ProgramStateRef reAssume(ProgramStateRef State,
 const RangeSet *Constraint,
 SVal TheValue) {
-  assert(State);
-  if (State->isPosteriorlyOverconstrained())
-return nullptr;
   if (!Constraint)
 return State;
 
@@ -2570,8 +2561,6 @@
   return State->assumeInclusiveRange(DefinedVal, Constraint->getMinValue(),
  Constraint->getMaxValue(), true);
 }
-} // namespace ento
-} // n

[PATCH] D126495: [clang-tidy] Organize test docs into subdirectories by module (NFC)

2022-06-02 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Can I ask what the motivation is for this change?

You may want to check the actual header files for the checks. A lot of them 
have a comment saying.

  /// For the user-facing documentation see:
  /// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone-reserved-identifier.html

I'm no expert on the inner workings of search engines, but I feel this will 
temporarily mess up my go to way of finding out a checks documentation, just 
googling its name. 
I wouldn't say its reason for blocking this, just my 0.02$.




Comment at: clang-tools-extra/clang-tidy/add_new_check.py:88
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/%(check_name_dashes)s.html
 class %(check_name)s : public ClangTidyCheck {

Again, this comment would need to be updated to use the new directory structure/


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

https://reviews.llvm.org/D126495

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


[PATCH] D124749: [clang-format] Handle Verilog preprocessor directives

2022-06-02 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 433702.
sstwcw added a comment.

- add comment and format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124749

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -30,7 +30,9 @@
 return *Result;
   }
 
-  static std::string format(llvm::StringRef Code, const FormatStyle &Style) {
+  static std::string
+  format(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Verilog)) {
 return format(Code, 0, Code.size(), Style);
   }
 
@@ -43,6 +45,29 @@
   }
 };
 
+TEST_F(FormatTestVerilog, Delay) {
+  // Delay by the default unit.
+  verifyFormat("#0;");
+  verifyFormat("#1;");
+  verifyFormat("#10;");
+  verifyFormat("#1.5;");
+  // Explicit unit.
+  verifyFormat("#1fs;");
+  verifyFormat("#1.5fs;");
+  verifyFormat("#1ns;");
+  verifyFormat("#1.5ns;");
+  verifyFormat("#1us;");
+  verifyFormat("#1.5us;");
+  verifyFormat("#1ms;");
+  verifyFormat("#1.5ms;");
+  verifyFormat("#1s;");
+  verifyFormat("#1.5s;");
+  // The following expression should be on the same line.
+  verifyFormat("#1 x = x;");
+  EXPECT_EQ("#1 x = x;", format("#1\n"
+"x = x;"));
+}
+
 TEST_F(FormatTestVerilog, If) {
   verifyFormat("if (x)\n"
"  x = x;");
@@ -114,5 +139,113 @@
"  {x} = {x};");
 }
 
+TEST_F(FormatTestVerilog, Preprocessor) {
+  auto Style = getLLVMStyle(FormatStyle::LK_Verilog);
+  Style.ColumnLimit = 20;
+
+  // Macro definitions.
+  EXPECT_EQ("`define X  \\\n"
+"  if (x)   \\\n"
+"x = x;",
+format("`define X if(x)x=x;", Style));
+  EXPECT_EQ("`define X(x)   \\\n"
+"  if (x)   \\\n"
+"x = x;",
+format("`define X(x) if(x)x=x;", Style));
+  EXPECT_EQ("`define X  \\\n"
+"  x = x;   \\\n"
+"  x = x;",
+format("`define X x=x;x=x;", Style));
+  // Macro definitions with invocations inside.
+  EXPECT_EQ("`define LIST   \\\n"
+"  `ENTRY   \\\n"
+"  `ENTRY",
+format("`define LIST \\\n"
+   "`ENTRY \\\n"
+   "`ENTRY",
+   Style));
+  EXPECT_EQ("`define LIST   \\\n"
+"  `x = `x; \\\n"
+"  `x = `x;",
+format("`define LIST \\\n"
+   "`x = `x; \\\n"
+   "`x = `x;",
+   Style));
+  EXPECT_EQ("`define LIST   \\\n"
+"  `x = `x; \\\n"
+"  `x = `x;",
+format("`define LIST `x=`x;`x=`x;", Style));
+  // Macro invocations.
+  verifyFormat("`x = (`x1 + `x2 + x);");
+  // Lines starting with a preprocessor directive should not be indented.
+  std::string Directives[] = {
+  "begin_keywords",
+  "celldefine",
+  "default_nettype",
+  "define",
+  "else",
+  "elsif",
+  "end_keywords",
+  "endcelldefine",
+  "endif",
+  "ifdef",
+  "ifndef",
+  "include",
+  "line",
+  "nounconnected_drive",
+  "pragma",
+  "resetall",
+  "timescale",
+  "unconnected_drive",
+  "undef",
+  "undefineall",
+  };
+  for (auto &Name : Directives) {
+EXPECT_EQ("if (x)\n"
+  "`" +
+  Name +
+  "\n"
+  "  ;",
+  format("if (x)\n"
+ "`" +
+ Name +
+ "\n"
+ ";",
+ Style));
+  }
+  // Lines starting with a regular macro invocation should be indented as a
+  // normal line.
+  EXPECT_EQ("if (x)\n"
+"  `x = `x;\n"
+"`timescale 1ns / 1ps",
+format("if (x)\n"
+   "`x = `x;\n"
+   "`timescale 1ns / 1ps",
+   Style));
+  EXPECT_EQ("if (x)\n"
+"`timescale 1ns / 1ps\n"
+"  `x = `x;",
+format("if (x)\n"
+   "`timescale 1ns / 1ps\n"
+   "`x = `x;",
+   Style));
+  std::string NonDirectives[] = {
+  // For `__FILE__` and `__LINE__`, although the standard classifies them as
+  // preprocessor directives, they are used like regular macros.
+  "__FILE__", "__LINE__", "elif", "foo", "x",
+  };
+  for (auto &Name : NonDirectives) {
+EXPECT_EQ("if (x)\n"
+  "  `" +
+  Name + ";",
+  

[PATCH] D126802: [analyzer][NFC] Uplift checkers after D126801

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

I think we should avoid `auto` when using `State->get<>` because the type is 
not immediate for the reader. (Unlike in a `cast`.)




Comment at: clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp:198
   // The special errno region should never garbage collected.
-  if (const auto *ErrnoR = getErrnoRegion(State))
+  if (const auto *ErrnoR = State->get())
 SR.markLive(ErrnoR);





Comment at: clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp:108
   if (SymbolRef sym = val.getAsSymbol())
-if (const unsigned *attachedFlags = state->get(sym))
+if (const auto *attachedFlags = state->get(sym))
   return (SelfFlagEnum)*attachedFlags;

I'd rather keep the type here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126802

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


[PATCH] D126871: [clang] [MinGW] Use SEH for unwind info on ARM by default

2022-06-02 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: efriedma, zzheng.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: clang.

This goes hand in hand with D126870 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126871

Files:
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/test/Driver/windows-exceptions.cpp


Index: clang/test/Driver/windows-exceptions.cpp
===
--- clang/test/Driver/windows-exceptions.cpp
+++ clang/test/Driver/windows-exceptions.cpp
@@ -2,6 +2,8 @@
 // RUN: %clang -target x86_64-windows-msvc -c %s -### 2>&1 | FileCheck 
-check-prefix=MSVC %s
 // RUN: %clang -target i686-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-DWARF %s
 // RUN: %clang -target x86_64-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-SEH %s
+// RUN: %clang -target armv7-windows-gnu -fdwarf-exceptions -c %s -### 2>&1 | 
FileCheck -check-prefix=MINGW-DWARF %s
+// RUN: %clang -target armv7-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-SEH %s
 // RUN: %clang -target aarch64-windows-gnu -fdwarf-exceptions -c %s -### 2>&1 
| FileCheck -check-prefix=MINGW-DWARF %s
 // RUN: %clang -target aarch64-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-SEH %s
 
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -478,8 +478,8 @@
   if (ExceptionArg &&
   ExceptionArg->getOption().matches(options::OPT_fseh_exceptions))
 return true;
-  return getArch() == llvm::Triple::x86_64 ||
- getArch() == llvm::Triple::aarch64;
+  return getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::arm ||
+ getArch() == llvm::Triple::thumb || getArch() == 
llvm::Triple::aarch64;
 }
 
 bool toolchains::MinGW::isPICDefault() const {
@@ -495,7 +495,8 @@
 
 llvm::ExceptionHandling
 toolchains::MinGW::GetExceptionModel(const ArgList &Args) const {
-  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64)
+  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64 
||
+  getArch() == llvm::Triple::arm || getArch() == llvm::Triple::thumb)
 return llvm::ExceptionHandling::WinEH;
   return llvm::ExceptionHandling::DwarfCFI;
 }


Index: clang/test/Driver/windows-exceptions.cpp
===
--- clang/test/Driver/windows-exceptions.cpp
+++ clang/test/Driver/windows-exceptions.cpp
@@ -2,6 +2,8 @@
 // RUN: %clang -target x86_64-windows-msvc -c %s -### 2>&1 | FileCheck -check-prefix=MSVC %s
 // RUN: %clang -target i686-windows-gnu -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-DWARF %s
 // RUN: %clang -target x86_64-windows-gnu -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-SEH %s
+// RUN: %clang -target armv7-windows-gnu -fdwarf-exceptions -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-DWARF %s
+// RUN: %clang -target armv7-windows-gnu -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-SEH %s
 // RUN: %clang -target aarch64-windows-gnu -fdwarf-exceptions -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-DWARF %s
 // RUN: %clang -target aarch64-windows-gnu -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-SEH %s
 
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -478,8 +478,8 @@
   if (ExceptionArg &&
   ExceptionArg->getOption().matches(options::OPT_fseh_exceptions))
 return true;
-  return getArch() == llvm::Triple::x86_64 ||
- getArch() == llvm::Triple::aarch64;
+  return getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::arm ||
+ getArch() == llvm::Triple::thumb || getArch() == llvm::Triple::aarch64;
 }
 
 bool toolchains::MinGW::isPICDefault() const {
@@ -495,7 +495,8 @@
 
 llvm::ExceptionHandling
 toolchains::MinGW::GetExceptionModel(const ArgList &Args) const {
-  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64)
+  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64 ||
+  getArch() == llvm::Triple::arm || getArch() == llvm::Triple::thumb)
 return llvm::ExceptionHandling::WinEH;
   return llvm::ExceptionHandling::DwarfCFI;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126803: [llvm][analyzer][NFC] Introduce SFINAE for specializing FoldingSetTraits

2022-06-02 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126803

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


[PATCH] D126845: [clang-format] Handle Verilog numbers and operators

2022-06-02 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/FormatToken.h:138
   TYPE(CSharpGenericTypeConstraintComma)   
\
+  TYPE(VerilogNumberBase) /* for the base in a number literal, not including   
\
+ the quote */  
\

One should move the CSharp stuff, since all other languages are sorted 
correctly. So I'd say please move above the CSharp.



Comment at: clang/lib/Format/FormatToken.h:1421
+  // Symbols in Verilog that don't exist in C++.
+  IdentifierInfo *quote;
+

apostrophe



Comment at: clang/lib/Format/FormatTokenLexer.cpp:247
+  TT_BinaryOperator))
+  return;
+// Module paths in specify blocks and implications in properties.

I think here are braces needed.



Comment at: clang/unittests/Format/FormatTestVerilog.cpp:163
 
+TEST_F(FormatTestVerilog, Operators) {
+  // Test that unary operators are not followed by space.

You should add token annotator tests to see if the tokens are parsed as you 
want to. Formatting mostly follows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126845

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


[clang-tools-extra] 35f0890 - [clang-tidy] Remove extra ";" in ModernizeModuleTest.cpp

2022-06-02 Thread Mikael Holmen via cfe-commits

Author: Mikael Holmen
Date: 2022-06-02T12:50:00+02:00
New Revision: 35f0890c4edce1975b17d0901607f2fba9216462

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

LOG: [clang-tidy] Remove extra ";" in ModernizeModuleTest.cpp

Without this fix we get

../../clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp:270:2: 
error: extra ';' outside of a function is incompatible with C++98 
[-Werror,-Wc++98-compat-extra-semi]
};
 ^
1 error generated.

when compiling with -Werror.

Added: 


Modified: 
clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp

Removed: 




diff  --git a/clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp
index 2461dacd5684a..4a8c1c3e5f312 100644
--- a/clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp
@@ -267,7 +267,7 @@ static const SizeParam SizeParams[] = {
 
 TEST_P(SizeTest, TokenSize) {
   EXPECT_EQ(sizeText(GetParam().Text), GetParam().Size);
-};
+}
 
 INSTANTIATE_TEST_SUITE_P(IntegralLiteralExpressionMatcherTests, SizeTest,
  ::testing::ValuesIn(SizeParams));



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


Re: [PATCH] D125052: [HLSL] Enable vector types for hlsl.

2022-06-02 Thread Shubham Rastogi via cfe-commits
Hi Xiang,

I would be more than happy to test the fix for you :). Though it is 11:45 pm 
for me now and I am going to bed. But I can take a look tomorrow.

Thanks,

Shubham

> On Jun 1, 2022, at 11:42 PM, stan li  wrote:
> 
> Hi Shubham,
>  
> I found one issue in the change.
> But I don’t have a Mac environment to test.
> Could you help to test if this fix the issue?
>  
> The patch is in attachment.
>  
> Thanks
> Xiang
>  
>  
> Sent from Mail  for Windows
>  
> From: Shubham Sandeep Rastogi via Phabricator 
> 
> Sent: Wednesday, June 1, 2022 11:28 PM
> To: python3k...@outlook.com ; 
> sven.vanhaastr...@arm.com ; 
> andrew.savonic...@gmail.com ; 
> chris.biene...@me.com ; goyor...@gmail.com 
> ; anastasia.stul...@arm.com 
> 
> Cc: srastog...@apple.com ; tha...@chromium.org 
> ; mask...@google.com ; 
> cfe-commits@lists.llvm.org ; 
> mgo...@gentoo.org ; bhuvanendra.kum...@amd.com 
> ;1135831...@qq.com 
> ; gandhi21...@gmail.com 
> ; aeuba...@google.com 
> ; mlek...@skidmore.edu 
> ; blitzrak...@gmail.com 
> ; shen...@google.com 
> ;david.gr...@arm.com ; 
> simon.m...@emea.nec.com 
> Subject: [PATCH] D125052: [HLSL] Enable vector types for hlsl.
>  
> rastogishubham added a comment.
> 
> Hi, this patch causes an issue with the CMake Xcode build configuration, if I 
> try to use xcode as the generator with CMake, using the build command:
> 
> xcrun cmake -G Xcode -DCMAKE_BUILD_TYPE:STRING=Debug 
> -DLLVM_ENABLE_ASSERTIONS:BOOL=TRUE -DCMAKE_C_COMPILER=/usr/bin/clang 
> -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DLLVM_ENABLE_PROJECTS='clang;' 
> -DCMAKE_IGNORE_PATH="/usr/lib;/usr/local/lib;/lib" 
> -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" ../llvm
> 
> I get:
> 
>   CMake Error in 
> /Users/shubham/Development/llvm-project/clang/lib/Headers/CMakeLists.txt:
> The custom command generating
>   
>   
> /Users/shubham/Development/llvm-project/build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/lib/clang/15.0.0/include/hlsl.h
>   
> is attached to multiple targets:
>   
>   hlsl-resource-headers
>   clang-resource-headers
>   
> but none of these is a common dependency of the other(s).  This is not
> allowed by the Xcode "new build system".
>   
>   
>   CMake Error in 
> /Users/shubham/Development/llvm-project/third-party/benchmark/CMakeLists.txt:
> The custom command generating
>   
>   
> /Users/shubham/Development/llvm-project/build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/lib/clang/15.0.0/include/hlsl.h
>   
> is attached to multiple targets:
>   
>   hlsl-resource-headers
>   clang-resource-headers
>   
> but none of these is a common dependency of the other(s).  This is not
> allowed by the Xcode "new build system".
>   
>   
>   CMake Generate step failed.  Build files cannot be regenerated correctly.
> 
> This is similar to the issue that was found in this patch: 
> https://reviews.llvm.org/D123498 
> 
> 
> Repository:
>   rG LLVM Github Monorepo
> 
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D125052/new/ 
> 
> 
> https://reviews.llvm.org/D125052 
>  
> 

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


[PATCH] D126780: [clang-tidy] `bugprone-use-after-move`: Fix handling of moves in lambda captures

2022-06-02 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.
This revision is now accepted and ready to land.

LGTM, But please add a note to ReleaseNotes before landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126780

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


[PATCH] D126560: [analyzer][NFC] SimpleSValBuilder simplification: Remove superfluous workaround code and track Assume call stack rather

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

I've made some measurements with the diff down below. So, it seems like the 
chance of being a recursive call is very unlikely (roughly 1/1). Thus I am 
going to update this condition with `LLVM_UNLIKELY`. Besides, the depth of the 
call stack seems to be less than 4 in the majority of cases (99.98%). However, 
there are edge cases (ffmpeg) when the depth is even bigger than 16. 
Consequently, a `SmallPtrSet` with 4 as the small buffer size would be better 
than the `SmallVector`.

Attached the csa-testbanch results.
F23289845: stats.html 

Plus, attached a summarizing excel sheet about the assume stack depth (courtesy 
of @steakhal).
F23289850: assume-stack-depths.xlsx 

  diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  index f1b75a57115b..097d0ff8d162 100644
  --- 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  +++ 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  @@ -153,6 +153,7 @@ protected:
   bool contains(const ProgramState *S) const {
 return llvm::find(Aux, S) != Aux.end();
   }
  +size_t size() { return Aux.size(); }
  
 private:
   llvm::SmallVector Aux;
  diff --git a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
  index 0866d3d0db74..11bbda9dd899 100644
  --- a/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
  +++ b/clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
  @@ -17,10 +17,25 @@
   #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
   #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
   #include "llvm/ADT/ScopeExit.h"
  +#include "llvm/ADT/Statistic.h"
  
   using namespace clang;
   using namespace ento;
  
  +#define DEBUG_TYPE "CoreEngine"
  +
  +STATISTIC(NumAssume, "The # of assume calls");
  +STATISTIC(NumAssumeRecurse, "The # of recursive assume calls");
  +STATISTIC(AssumeStackSize01, "The # of assume stack size between 0 and 1");
  +STATISTIC(AssumeStackSize23, "The # of assume stack size between 2 and 3");
  +STATISTIC(AssumeStackSize45, "The # of assume stack size between 4 and 5");
  +STATISTIC(AssumeStackSize67, "The # of assume stack size between 6 and 7");
  +STATISTIC(AssumeStackSize89, "The # of assume stack size between 8 and 9");
  +STATISTIC(AssumeStackSize1011, "The # of assume stack size between 10 and 
11");
  +STATISTIC(AssumeStackSize1213, "The # of assume stack size between 12 and 
13");
  +STATISTIC(AssumeStackSize1415, "The # of assume stack size between 14 and 
15");
  +STATISTIC(AssumeStackSize16XX, "The # of assume stack size greater equal 
than 16");
  +
   ConstraintManager::~ConstraintManager() = default;
  
   static DefinedSVal getLocFromSymbol(const ProgramStateRef &State,
  @@ -53,9 +68,30 @@ ConstraintManager::assumeDualImpl(ProgramStateRef &State,
 // fixpoint.
 // We avoid infinite recursion of assume calls by checking already visited
 // States on the stack of assume function calls.
  +  ++NumAssume;
  +  if (AssumeStack.size() < 2)
  +++AssumeStackSize01;
  +  else if (AssumeStack.size() < 4)
  +++AssumeStackSize23;
  +  else if (AssumeStack.size() < 6)
  +++AssumeStackSize45;
  +  else if (AssumeStack.size() < 8)
  +++AssumeStackSize67;
  +  else if (AssumeStack.size() < 10)
  +++AssumeStackSize89;
  +  else if (AssumeStack.size() < 12)
  +++AssumeStackSize1011;
  +  else if (AssumeStack.size() < 14)
  +++AssumeStackSize1213;
  +  else if (AssumeStack.size() < 16)
  +++AssumeStackSize1415;
  +  else
  +++AssumeStackSize16XX;
 const ProgramState *RawSt = State.get();
  -  if (AssumeStack.contains(RawSt))
  +  if (AssumeStack.contains(RawSt)) {
  +++NumAssumeRecurse;
   return {State, State};
  +  }
 AssumeStack.push(RawSt);
 auto AssumeStackBuilder =
 llvm::make_scope_exit([this]() { AssumeStack.pop(); });


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126560

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


[PATCH] D125802: Fix std::has_unique_object_representations for _BitInt types with padding bits

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

In D125802#3552047 , @browneee wrote:

> It looks like the leak is rooted at the allocation here:
> https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L3857
>
> The VarTemplateSpecializationDecl is allocated using placement new which uses 
> the AST structure for ownership: 
> https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/lib/AST/DeclBase.cpp#L99
>
> The problem is the TemplateArgumentListInfo inside 
> https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/DeclTemplate.h#L2721
> This object contains a vector which does not use placement new: 
> https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/TemplateBase.h#L564
>
> Apparently ASTTemplateArgumentListInfo 
> 
>  should be used instead 
> https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/TemplateBase.h#L575

Wow, thank you for the fantastic sleuthing! It seems that declaration is nine 
years old, so I'm surprised the leak is only being discovered now and as part 
of this particular test case.

I don't have a particularly easy way to test this locally at the moment -- do 
you know if switching `VarTemplateSpecializationDecl::TemplateArgsInfo` to be a 
`ASTTemplateArgumentListInfo` solves the issue for you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125802

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


[PATCH] D125373: [pp-trace] Print HashLoc in InclusionDirective callback

2022-06-02 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! Can you add a release note for the change? (There's an `Improvements to 
pp-trace` section in docs\ReleaseNotes.rst)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125373

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


[PATCH] D126560: [analyzer] Track assume call stack to detect fixpoint

2022-06-02 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 4 inline comments as done.
martong added a comment.

> Consequently, a SmallPtrSet with 4 as the small buffer size would be better 
> than the SmallVector

Ahh, SmallVector is still better, because with the set we need to do a search 
in the `erase, which compares badly to a simple decrement in the vector's 
pop_back.




Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h:21
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/SaveAndRestore.h"

steakhal wrote:
> Unused.
Thx.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h:154
+bool contains(const ProgramState *S) const {
+  return llvm::find(Aux, S) != Aux.end();
+}

steakhal wrote:
> Use `llvm::is_contained()` instead.
Ok.



Comment at: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp:60
+  AssumeStack.push(RawSt);
+  auto AssumeStackBuilder =
+  llvm::make_scope_exit([this]() { AssumeStack.pop(); });

steakhal wrote:
> Don't we call these 'Guards'?
Yeah, we tend to call them guards in the context of exception safety and 
resource management. But, I think, "builder" is more expressive here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126560

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


[PATCH] D126560: [analyzer] Track assume call stack to detect fixpoint

2022-06-02 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 433719.
martong marked 3 inline comments as done.
martong edited the summary of this revision.
martong added a comment.

- Add LLVM_UNLIKELY


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126560

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/lib/StaticAnalyzer/Core/ConstraintManager.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
@@ -320,7 +320,6 @@
   else
 llvm_unreachable("Operation not suitable for unchecked rearrangement!");
 
-  // FIXME: Can we use assume() without getting into an infinite recursion?
   if (LSym == RSym)
 return SVB.evalBinOpNN(State, Op, nonloc::ConcreteInt(LInt),
nonloc::ConcreteInt(RInt), ResultTy)
@@ -1190,7 +1189,6 @@
 
 const llvm::APSInt *SimpleSValBuilder::getKnownValue(ProgramStateRef state,
SVal V) {
-  V = simplifySVal(state, V);
   if (V.isUnknownOrUndef())
 return nullptr;
 
@@ -1376,14 +1374,6 @@
 SVal VisitSVal(SVal V) { return V; }
   };
 
-  // A crude way of preventing this function from calling itself from 
evalBinOp.
-  static bool isReentering = false;
-  if (isReentering)
-return V;
-
-  isReentering = true;
   SVal SimplifiedV = Simplifier(State).Visit(V);
-  isReentering = false;
-
   return SimplifiedV;
 }
Index: clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/ConstraintManager.cpp
@@ -16,6 +16,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
+#include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
 using namespace ento;
@@ -46,6 +47,19 @@
 ConstraintManager::ProgramStatePair
 ConstraintManager::assumeDualImpl(ProgramStateRef &State,
   AssumeFunction &Assume) {
+
+  // Assume functions might recurse (see `reAssume` or `tryRearrange`). During
+  // the recursion the State might not change anymore, that means we reached a
+  // fixpoint.
+  // We avoid infinite recursion of assume calls by checking already visited
+  // States on the stack of assume function calls.
+  const ProgramState *RawSt = State.get();
+  if (LLVM_UNLIKELY(AssumeStack.contains(RawSt)))
+return {State, State};
+  AssumeStack.push(RawSt);
+  auto AssumeStackBuilder =
+  llvm::make_scope_exit([this]() { AssumeStack.pop(); });
+
   ProgramStateRef StTrue = Assume(true);
 
   if (!StTrue) {
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
@@ -144,6 +144,20 @@
   /// but not thread-safe.
   bool NotifyAssumeClients = true;
 
+  /// A helper class to simulate the call stack of nested assume calls.
+  class AssumeStackTy {
+  public:
+void push(const ProgramState *S) { Aux.push_back(S); }
+void pop() { Aux.pop_back(); }
+bool contains(const ProgramState *S) const {
+  return llvm::is_contained(Aux, S);
+}
+
+  private:
+llvm::SmallVector Aux;
+  };
+  AssumeStackTy AssumeStack;
+
   virtual ProgramStateRef assumeInternal(ProgramStateRef state,
  DefinedSVal Cond, bool Assumption) = 
0;
 


Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -320,7 +320,6 @@
   else
 llvm_unreachable("Operation not suitable for unchecked rearrangement!");
 
-  // FIXME: Can we use assume() without getting into an infinite recursion?
   if (LSym == RSym)
 return SVB.evalBinOpNN(State, Op, nonloc::ConcreteInt(LInt),
nonloc::ConcreteInt(RInt), ResultTy)
@@ -1190,7 +1189,6 @@
 
 const llvm::APSInt *SimpleSValBuilder::getKnownValue(ProgramStateRef state,
SVal V) {
-  V = simplifySVal(state, V);
   if (V.isUnknownOrUndef())
 return nullptr;
 
@@ -1376,14 +1374,6 @@
 SVal VisitSVal(SVal V) { return V; }
   };
 
-  // A crude way of preventing this function from calling itself from evalBinOp.
-  static bool isReentering = false;
-  if (isReentering)
-return V;

[clang] c745f2c - Revert "Drop qualifiers from return types in C (DR423)"

2022-06-02 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-06-02T08:28:43-04:00
New Revision: c745f2ce6c03bc6d1e59cac69cc15923d4400191

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

LOG: Revert "Drop qualifiers from return types in C (DR423)"

This reverts commit d374b65f2da1bdd3d9a7e9ac8ed4ad5467c882f9.

The changes lose AST fidelity (reported in #55778), but also may be
improperly dropping _Atomic qualifiers. I am rolling the changes back
until I've finished discussions in WG14 about the proper resolution to
DR423.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaType.cpp
clang/test/CodeGen/xcore-stringtype.c
clang/test/Sema/block-call.c
clang/test/Sema/c89.c
clang/test/Sema/function.c
clang/test/Sema/warn-missing-prototypes.c
clang/test/SemaObjC/block-omitted-return-type.m
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
clang/unittests/ASTMatchers/ASTMatchersTest.h

Removed: 
clang/test/Sema/wg14-dr423.c



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b58f85680049..be21872546bb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -355,11 +355,6 @@ AIX Support
 
 C Language Changes in Clang
 ---
-- Finished implementing support for DR423. We already correctly handled
-  stripping qualifiers from cast expressions, but we did not strip qualifiers
-  on function return types. We now properly treat the function as though it
-  were declarated with an unqualified, non-atomic return type. Fixes
-  `Issue 39595 `_.
 
 C2x Feature Support
 ---

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0f8ed0a6e8c3..469f79a86752 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6137,6 +6137,9 @@ def note_exits_block_captures_non_trivial_c_struct : Note<
 def note_exits_compound_literal_scope : Note<
   "jump exits lifetime of a compound literal that is non-trivial to destruct">;
 
+def err_func_returning_qualified_void : ExtWarn<
+  "function cannot return qualified void type %0">,
+  InGroup>;
 def err_func_returning_array_function : Error<
   "function cannot return %select{array|function}0 type %1">;
 def err_field_declared_as_function : Error<"field %0 declared as a function">;

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 5c4d3b9c2a29..3c1b2931efc7 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5182,11 +5182,15 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   if ((T.getCVRQualifiers() || T->isAtomicType()) &&
   !(S.getLangOpts().CPlusPlus &&
 (T->isDependentType() || T->isRecordType( {
-// WG14 DR 423 updated 6.7.6.3p4 to have the function declarator drop
-// all qualifiers from the return type.
-diagnoseRedundantReturnTypeQualifiers(S, T, D, chunkIndex);
-if (!S.getLangOpts().CPlusPlus)
-  T = T.getAtomicUnqualifiedType();
+if (T->isVoidType() && !S.getLangOpts().CPlusPlus &&
+D.getFunctionDefinitionKind() ==
+FunctionDefinitionKind::Definition) {
+  // [6.9.1/3] qualified void return is invalid on a C
+  // function definition.  Apparently ok on declarations and
+  // in C++ though (!)
+  S.Diag(DeclType.Loc, diag::err_func_returning_qualified_void) << T;
+} else
+  diagnoseRedundantReturnTypeQualifiers(S, T, D, chunkIndex);
 
 // C++2a [dcl.fct]p12:
 //   A volatile-qualified return type is deprecated

diff  --git a/clang/test/CodeGen/xcore-stringtype.c 
b/clang/test/CodeGen/xcore-stringtype.c
index 365a36dc60cc..4b9429caa1df 100644
--- a/clang/test/CodeGen/xcore-stringtype.c
+++ b/clang/test/CodeGen/xcore-stringtype.c
@@ -42,8 +42,8 @@ double _Complex Complex; // not supported
 // CHECK: !{{[0-9]+}} = !{void ()* @eV, !"f{0}(0)"}
 // CHECK: !{{[0-9]+}} = !{void (i32, ...)* @gVA, !"f{0}(si,va)"}
 // CHECK: !{{[0-9]+}} = !{void (i32, ...)* @eVA, !"f{0}(si,va)"}
-// CHECK: !{{[0-9]+}} = !{i32* (i32*)* @gQ, !"f{p(cv:si)}(p(cv:si))"}
-// CHECK: !{{[0-9]+}} = !{i32* (i32*)* @eQ, !"f{p(cv:si)}(p(cv:si))"}
+// CHECK: !{{[0-9]+}} = !{i32* (i32*)* @gQ, !"f{crv:p(cv:si)}(p(cv:si))"}
+// CHECK: !{{[0-9]+}} = !{i32* (i32*)* @eQ, !"f{crv:p(cv:si)}(p(cv:si))"}
 extern void eI();
 void gI() {eI();};
 extern void eV(void);

diff  --git a/clang/test/Sema/block-call.c b/clang/test/Sema/block-call.c
index 81071121b6ad..0b96c3bee5e3 100644
--- a/clang/test/Sema/block-c

[PATCH] D125373: [pp-trace] Print HashLoc in InclusionDirective callback

2022-06-02 Thread Tommy Chiang via Phabricator via cfe-commits
oToToT updated this revision to Diff 433722.
oToToT added a comment.

Added a release note for the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125373

Files:
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/pp-trace.rst
  clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/test/pp-trace/pp-trace-include.cpp


Index: clang-tools-extra/test/pp-trace/pp-trace-include.cpp
===
--- clang-tools-extra/test/pp-trace/pp-trace-include.cpp
+++ clang-tools-extra/test/pp-trace/pp-trace-include.cpp
@@ -51,6 +51,7 @@
 // CHECK-NEXT:   FileType: C_User
 // CHECK-NEXT:   PrevFID: (getFileEntryForID failed)
 // CHECK-NEXT: - Callback: InclusionDirective
+// CHECK-NEXT:   HashLoc: "{{.*}}{{[/\\]}}pp-trace-include.cpp:3:1"
 // CHECK-NEXT:   IncludeTok: include
 // CHECK-NEXT:   FileName: "Inputs/Level1A.h"
 // CHECK-NEXT:   IsAngled: false
@@ -65,6 +66,7 @@
 // CHECK-NEXT:   FileType: C_User
 // CHECK-NEXT:   PrevFID: (invalid)
 // CHECK-NEXT: - Callback: InclusionDirective
+// CHECK-NEXT:   HashLoc: "{{.*}}{{[/\\]}}Inputs/Level1A.h:1:1"
 // CHECK-NEXT:   IncludeTok: include
 // CHECK-NEXT:   FileName: "Level2A.h"
 // CHECK-NEXT:   IsAngled: false
@@ -95,6 +97,7 @@
 // CHECK-NEXT:   FileType: C_User
 // CHECK-NEXT:   PrevFID: "{{.*}}{{[/\\]}}Inputs/Level1A.h"
 // CHECK-NEXT: - Callback: InclusionDirective
+// CHECK-NEXT:   HashLoc: "{{.*}}{{[/\\]}}pp-trace-include.cpp:4:1"
 // CHECK-NEXT:   IncludeTok: include
 // CHECK-NEXT:   FileName: "Inputs/Level1B.h"
 // CHECK-NEXT:   IsAngled: false
@@ -109,6 +112,7 @@
 // CHECK-NEXT:   FileType: C_User
 // CHECK-NEXT:   PrevFID: (invalid)
 // CHECK-NEXT: - Callback: InclusionDirective
+// CHECK-NEXT:   HashLoc: "{{.*}}{{[/\\]}}Inputs/Level1B.h:1:1"
 // CHECK-NEXT:   IncludeTok: include
 // CHECK-NEXT:   FileName: "Level2B.h"
 // CHECK-NEXT:   IsAngled: false
Index: clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
===
--- clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
+++ clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
@@ -137,6 +137,7 @@
 llvm::StringRef SearchPath, llvm::StringRef RelativePath,
 const Module *Imported, SrcMgr::CharacteristicKind FileType) {
   beginCallback("InclusionDirective");
+  appendArgument("HashLoc", HashLoc);
   appendArgument("IncludeTok", IncludeTok);
   appendFilePathArgument("FileName", FileName);
   appendArgument("IsAngled", IsAngled);
Index: clang-tools-extra/docs/pp-trace.rst
===
--- clang-tools-extra/docs/pp-trace.rst
+++ clang-tools-extra/docs/pp-trace.rst
@@ -223,6 +223,7 @@
 Example:::
 
   - Callback: InclusionDirective
+HashLoc: 
"D:/Clang/llvmnewmod/clang-tools-extra/test/pp-trace/pp-trace-include.cpp:4:1"
 IncludeTok: include
 FileName: "Input/Level1B.h"
 IsAngled: false
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -206,7 +206,7 @@
 Improvements to pp-trace
 
 
-The improvements are...
+- Added `HashLoc` information to `InclusionDirective` callback output.
 
 Clang-tidy Visual Studio plugin
 ---


Index: clang-tools-extra/test/pp-trace/pp-trace-include.cpp
===
--- clang-tools-extra/test/pp-trace/pp-trace-include.cpp
+++ clang-tools-extra/test/pp-trace/pp-trace-include.cpp
@@ -51,6 +51,7 @@
 // CHECK-NEXT:   FileType: C_User
 // CHECK-NEXT:   PrevFID: (getFileEntryForID failed)
 // CHECK-NEXT: - Callback: InclusionDirective
+// CHECK-NEXT:   HashLoc: "{{.*}}{{[/\\]}}pp-trace-include.cpp:3:1"
 // CHECK-NEXT:   IncludeTok: include
 // CHECK-NEXT:   FileName: "Inputs/Level1A.h"
 // CHECK-NEXT:   IsAngled: false
@@ -65,6 +66,7 @@
 // CHECK-NEXT:   FileType: C_User
 // CHECK-NEXT:   PrevFID: (invalid)
 // CHECK-NEXT: - Callback: InclusionDirective
+// CHECK-NEXT:   HashLoc: "{{.*}}{{[/\\]}}Inputs/Level1A.h:1:1"
 // CHECK-NEXT:   IncludeTok: include
 // CHECK-NEXT:   FileName: "Level2A.h"
 // CHECK-NEXT:   IsAngled: false
@@ -95,6 +97,7 @@
 // CHECK-NEXT:   FileType: C_User
 // CHECK-NEXT:   PrevFID: "{{.*}}{{[/\\]}}Inputs/Level1A.h"
 // CHECK-NEXT: - Callback: InclusionDirective
+// CHECK-NEXT:   HashLoc: "{{.*}}{{[/\\]}}pp-trace-include.cpp:4:1"
 // CHECK-NEXT:   IncludeTok: include
 // CHECK-NEXT:   FileName: "Inputs/Level1B.h"
 // CHECK-NEXT:   IsAngled: false
@@ -109,6 +112,7 @@
 // CHECK-NEXT:   FileType: C_User
 // CHECK-NEXT:   PrevFID: (invalid)
 // CHECK-NEXT: - Callback: InclusionDirective
+// CHECK-NEXT:   HashLoc: "{{.*}}{{[/\\]}}Inputs/Level1B.h:1:1"
 // CHECK-NEXT:   IncludeTok: include
 // CHECK-NEXT:   FileName: 

[PATCH] D126340: [clang][AIX] add option -mdefault-visibility-export-mapping

2022-06-02 Thread David Tenty via Phabricator via cfe-commits
daltenty added a comment.

In D126340#3552645 , @nikic wrote:

> It looks like this causes a major compile-time regression in the clang 
> frontend: 
> http://llvm-compile-time-tracker.com/compare.php?from=6232a8f3d61e5856c17e7b314385e9ea8068cdc1&to=8c8a2679a20f621994fa904bcfc68775e7345edc&stat=instructions
>  For example, tramp3d-v4 is up 5% in `-O0` builds.
>
> Not familiar with this area, but my first guess would be that 
> getLinkageAndVisibility() is actually expensive and you're introducing a ton 
> of calls to it?

@nikic thanks for catching this! Looking into it now, I'll put in a revert if I 
can't get things sorted shortly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126340

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


[clang] 30ad481 - Revert "cmake: use llvm dir variables for clang/utils/hmaptool"

2022-06-02 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-06-02T14:55:58+02:00
New Revision: 30ad481e87ca7cd2250bd5771ab66ddfe623eb10

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

LOG: Revert "cmake: use llvm dir variables for clang/utils/hmaptool"

As discussed on the review, this change breaks the standalone
clang build. When building against an installed LLVM, the
LLVM_TOOLS_BINARY_DIR cmake variable points to the location of
the installed LLVM tools, not to the cmake build directory. This
means that we would end up trying to move hmaptool into something
like /usr/bin as part of the normal build, while this should only
be happening when running an install target.

This reverts commit bf1ab1f0eb9578914343f48096229ecccd0ecf52.

Added: 


Modified: 
clang/utils/hmaptool/CMakeLists.txt

Removed: 




diff  --git a/clang/utils/hmaptool/CMakeLists.txt 
b/clang/utils/hmaptool/CMakeLists.txt
index 01b6a920fb94..f0d9866782b8 100644
--- a/clang/utils/hmaptool/CMakeLists.txt
+++ b/clang/utils/hmaptool/CMakeLists.txt
@@ -1,9 +1,19 @@
-add_custom_command(OUTPUT "${LLVM_TOOLS_BINARY_DIR}/hmaptool"
-   COMMAND "${CMAKE_COMMAND}" -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${LLVM_TOOLS_BINARY_DIR}"
-   DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
+set(CLANG_HMAPTOOL hmaptool)
 
-install(PROGRAMS hmaptool DESTINATION "${LLVM_TOOLS_INSTALL_DIR}" COMPONENT 
hmaptool)
-add_custom_target(hmaptool ALL DEPENDS "${LLVM_TOOLS_BINARY_DIR}/hmaptool")
+add_custom_command(OUTPUT 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}
+   COMMAND ${CMAKE_COMMAND} -E make_directory
+ ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin
+   COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}
+ ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/
+   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL})
+
+list(APPEND Depends 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL})
+install(PROGRAMS ${CLANG_HMAPTOOL}
+DESTINATION "${CMAKE_INSTALL_BINDIR}"
+COMPONENT hmaptool)
+
+add_custom_target(hmaptool ALL DEPENDS ${Depends})
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 
 if(NOT LLVM_ENABLE_IDE)



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


[PATCH] D125802: Fix std::has_unique_object_representations for _BitInt types with padding bits

2022-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D125802#3553015 , @aaron.ballman 
wrote:

> In D125802#3552047 , @browneee 
> wrote:
>
>> It looks like the leak is rooted at the allocation here:
>> https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L3857
>>
>> The VarTemplateSpecializationDecl is allocated using placement new which 
>> uses the AST structure for ownership: 
>> https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/lib/AST/DeclBase.cpp#L99
>>
>> The problem is the TemplateArgumentListInfo inside 
>> https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/DeclTemplate.h#L2721
>> This object contains a vector which does not use placement new: 
>> https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/TemplateBase.h#L564
>>
>> Apparently ASTTemplateArgumentListInfo 
>> 
>>  should be used instead 
>> https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/TemplateBase.h#L575
>
> Wow, thank you for the fantastic sleuthing! It seems that declaration is nine 
> years old, so I'm surprised the leak is only being discovered now and as part 
> of this particular test case.
>
> I don't have a particularly easy way to test this locally at the moment -- do 
> you know if switching `VarTemplateSpecializationDecl::TemplateArgsInfo` to be 
> a `ASTTemplateArgumentListInfo` solves the issue for you?

Ah, ouch!  This is definitely going to be the problem.  `TemplateArgumentList` 
is generally just an 'observing' collection, stuff stored in the AST seems to 
need to use `ASTTEmplateArgumentListInfo`.  The reason  you might not notice 
it, is much of the time the former just references a bunch of template 
arguments stored elsewhere in the AST, so unless you hold it juuust right and 
find one that gets deleted before the rest of the AST, you won't have this 
problem.  I'm not sure what is causing it in this test though.

Either way, I very much suggest we should make this change.  Note there are a 
few places where this might be used that a conversion between the two will have 
to be made, but that is expected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125802

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


[PATCH] D126560: [analyzer] Track assume call stack to detect fixpoint

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

Looks good!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126560

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


[libunwind] dfaee3c - [libunwind][ci][AIX] Add libunwind to buildbot CI

2022-06-02 Thread Xing Xue via cfe-commits

Author: Xing Xue
Date: 2022-06-02T09:03:10-04:00
New Revision: dfaee3c9cfa17fce6af317ddcae89c6f6550cf94

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

LOG: [libunwind][ci][AIX] Add libunwind to buildbot CI

Summary:
This patch changes scripts to add libunwind CI on AIX. Test config file 
ibm-libunwind-shared.cfg.in is introduced for testing on AIX.

Reviewed by: ldionne, MaskRay, libunwind, ibc++abi

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

Added: 
libunwind/test/configs/ibm-libunwind-shared.cfg.in

Modified: 
libcxx/cmake/caches/AIX.cmake
libcxx/utils/ci/run-buildbot

Removed: 




diff  --git a/libcxx/cmake/caches/AIX.cmake b/libcxx/cmake/caches/AIX.cmake
index 029b8deae3d7..fcd4ec25ec20 100644
--- a/libcxx/cmake/caches/AIX.cmake
+++ b/libcxx/cmake/caches/AIX.cmake
@@ -14,3 +14,6 @@ set(LIBCXX_ENABLE_STATIC OFF CACHE BOOL "")
 set(LIBCXXABI_ENABLE_SHARED ON CACHE BOOL "")
 set(LIBCXXABI_ENABLE_STATIC OFF CACHE BOOL "")
 set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
+set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
+set(LIBUNWIND_ENABLE_SHARED ON CACHE BOOL "")
+set(LIBUNWIND_ENABLE_STATIC OFF CACHE BOOL "")

diff  --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index 2b9f129fd258..2213a3a46d3f 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -575,10 +575,8 @@ aix)
 generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/AIX.cmake" \
-DLIBCXX_TEST_CONFIG="ibm-libc++-shared.cfg.in" \
-DLIBCXXABI_TEST_CONFIG="ibm-libc++abi-shared.cfg.in" \
-   -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi"
-# TODO: use check-runtimes once libunwind builds cleanly on AIX.
-${NINJA} -vC "${BUILD_DIR}" install-cxx install-cxxabi
-${NINJA} -vC "${BUILD_DIR}" check-cxx check-cxxabi
+   -DLIBUNWIND_TEST_CONFIG="ibm-libunwind-shared.cfg.in"
+check-runtimes
 ;;
 #
 # Insert vendor-specific internal configurations below.

diff  --git a/libunwind/test/configs/ibm-libunwind-shared.cfg.in 
b/libunwind/test/configs/ibm-libunwind-shared.cfg.in
new file mode 100644
index ..c3c0ddd5c726
--- /dev/null
+++ b/libunwind/test/configs/ibm-libunwind-shared.cfg.in
@@ -0,0 +1,25 @@
+# Configuration file for running the libunwind tests on AIX.
+#
+
+lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
+
+config.substitutions.append(('%{flags}', ''))
+config.substitutions.append(('%{compile_flags}',
+'-nostdinc++ -I %{include} -I %{cxx-include}'
+))
+config.substitutions.append(('%{link_flags}',
+'-nostdlib++ -L %{lib} -lunwind -ldl -Wl,-bbigtoc'
+))
+config.substitutions.append(('%{exec}',
+'%{executor} --execdir %T --env LIBPATH=%{lib} -- '
+))
+
+import os, site
+site.addsitedir(os.path.join('@LIBUNWIND_LIBCXX_PATH@', 'utils'))
+import libcxx.test.params, libcxx.test.newconfig, libcxx.test.newconfig
+libcxx.test.newconfig.configure(
+libcxx.test.params.DEFAULT_PARAMETERS,
+libcxx.test.features.DEFAULT_FEATURES,
+config,
+lit_config
+)



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


[PATCH] D126560: [analyzer] Track assume call stack to detect fixpoint

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

Express why this is not an NFC patch in the summary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126560

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


[PATCH] D126818: Itanium ABI: Implement mangling for constrained friends

2022-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane planned changes to this revision.
erichkeane added a comment.

In D126818#3551504 , @erichkeane 
wrote:

> Note this was mentioned as a 'must also do' in my discussion on deferred 
> constraints with @rsmith, however as this already fails, I don't see this as 
> a prerequisite.  However, I think this is easy enough to just do.
>
> THAT SAID: The proposal on the itanium-abi github wasn't particularly clear 
> as to which of the following three options were the 'right' answer.  I'm 
> hoping @rjmccall can decide whether this is acceptable:
>
> Option 1: Change the mangling of ALL friend functions.  I determined this is 
> likely an ABI break on otherwise 'settled' code, and figured we wouldn't want 
> to do this.
>
> Option 2: Change the mangling for ALL constrained friend functions.  This 
> seemed easy enough to do, AND changes the mangling for things only covered by 
> 'experimental' concepts support.  So I think changing the ABI for current 
> things is OK here.
>
> Option 3: Change the mangling for constrained friend functions that fall 
> under temp.friend p9.  The only difference between this and Option2 is that 
> this would need to check the 'template friend function depends on containing 
> scope'.  I don't believe this is necessary so long as we are consistent with 
> it.  Presumably this could end up with multiple symbols for functions that 
> are the 'same declaration' by rule in separate translation units, such as:
>
>   struct Base{};
>   template
>   struct S {
> template
> friend void func(Base&) requires(U::value) {}
>   };
>   void uses() {
> S<1> s;
> S<2> s2; // This is an error during Sema, since 'func' is a duplicate 
> here.
> func(s); // all Ss SHOULD end up with the same declaration, but in 
> different TUs they might end up with different copies here?
>   }
>
> In typing this comment up, I believe I got the 'option' wrong here.  Should I 
> have gone with #3 above?   I'm going to think about it overnight (and hope 
> you reviewer folks can chime in!) and get to it in the morning.

After thinking about it, I'm about 99% sure I made the wrong choice here.  I 
should have gone with #3.  That likely requires the infrastructure from the 
deferred concepts patch, so I'll get that ready, then rebase this to be ready.


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

https://reviews.llvm.org/D126818

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


[PATCH] D126878: [analyzer] Remove NotifyAssumeClients

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

Depends on D126560 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126878

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp


Index: clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -44,7 +44,7 @@
 ProgramStateRef SimpleConstraintManager::assume(ProgramStateRef State,
 NonLoc Cond, bool Assumption) {
   State = assumeAux(State, Cond, Assumption);
-  if (NotifyAssumeClients && EE)
+  if (EE)
 return EE->processAssume(State, Cond, Assumption);
   return State;
 }
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
@@ -130,20 +130,10 @@
   /// Convenience method to query the state to see if a symbol is null or
   /// not null, or if neither assumption can be made.
   ConditionTruthVal isNull(ProgramStateRef State, SymbolRef Sym) {
-SaveAndRestore DisableNotify(NotifyAssumeClients, false);
-
 return checkNull(State, Sym);
   }
 
 protected:
-  /// A flag to indicate that clients should be notified of assumptions.
-  /// By default this is the case, but sometimes this needs to be restricted
-  /// to avoid infinite recursions within the ConstraintManager.
-  ///
-  /// Note that this flag allows the ConstraintManager to be re-entrant,
-  /// but not thread-safe.
-  bool NotifyAssumeClients = true;
-
   /// A helper class to simulate the call stack of nested assume calls.
   class AssumeStackTy {
   public:


Index: clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -44,7 +44,7 @@
 ProgramStateRef SimpleConstraintManager::assume(ProgramStateRef State,
 NonLoc Cond, bool Assumption) {
   State = assumeAux(State, Cond, Assumption);
-  if (NotifyAssumeClients && EE)
+  if (EE)
 return EE->processAssume(State, Cond, Assumption);
   return State;
 }
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
@@ -130,20 +130,10 @@
   /// Convenience method to query the state to see if a symbol is null or
   /// not null, or if neither assumption can be made.
   ConditionTruthVal isNull(ProgramStateRef State, SymbolRef Sym) {
-SaveAndRestore DisableNotify(NotifyAssumeClients, false);
-
 return checkNull(State, Sym);
   }
 
 protected:
-  /// A flag to indicate that clients should be notified of assumptions.
-  /// By default this is the case, but sometimes this needs to be restricted
-  /// to avoid infinite recursions within the ConstraintManager.
-  ///
-  /// Note that this flag allows the ConstraintManager to be re-entrant,
-  /// but not thread-safe.
-  bool NotifyAssumeClients = true;
-
   /// A helper class to simulate the call stack of nested assume calls.
   class AssumeStackTy {
   public:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-06-02 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 433729.
mizvekov edited the summary of this revision.
mizvekov added a comment.

- fix for standalone builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126308

Files:
  clang/utils/hmaptool/CMakeLists.txt


Index: clang/utils/hmaptool/CMakeLists.txt
===
--- clang/utils/hmaptool/CMakeLists.txt
+++ clang/utils/hmaptool/CMakeLists.txt
@@ -1,19 +1,14 @@
-set(CLANG_HMAPTOOL hmaptool)
+# FIXME: ideally we would just provide CURRENT_TOOLS_DIR globally instead of
+#computing it just for function(configure_lit_site_cfg)
+set_llvm_build_mode()
+string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" CURRENT_TOOLS_DIR 
"${LLVM_RUNTIME_OUTPUT_INTDIR}")
 
-add_custom_command(OUTPUT 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}
-   COMMAND ${CMAKE_COMMAND} -E make_directory
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin
-   COMMAND ${CMAKE_COMMAND} -E copy
- ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/
-   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL})
+add_custom_command(OUTPUT "${CURRENT_TOOLS_DIR}/hmaptool"
+   COMMAND "${CMAKE_COMMAND}" -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${CURRENT_TOOLS_DIR}"
+   DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-list(APPEND Depends 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL})
-install(PROGRAMS ${CLANG_HMAPTOOL}
-DESTINATION "${CMAKE_INSTALL_BINDIR}"
-COMPONENT hmaptool)
-
-add_custom_target(hmaptool ALL DEPENDS ${Depends})
+install(PROGRAMS hmaptool DESTINATION "${LLVM_TOOLS_INSTALL_DIR}" COMPONENT 
hmaptool)
+add_custom_target(hmaptool ALL DEPENDS "${CURRENT_TOOLS_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 
 if(NOT LLVM_ENABLE_IDE)


Index: clang/utils/hmaptool/CMakeLists.txt
===
--- clang/utils/hmaptool/CMakeLists.txt
+++ clang/utils/hmaptool/CMakeLists.txt
@@ -1,19 +1,14 @@
-set(CLANG_HMAPTOOL hmaptool)
+# FIXME: ideally we would just provide CURRENT_TOOLS_DIR globally instead of
+#computing it just for function(configure_lit_site_cfg)
+set_llvm_build_mode()
+string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" CURRENT_TOOLS_DIR "${LLVM_RUNTIME_OUTPUT_INTDIR}")
 
-add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}
-   COMMAND ${CMAKE_COMMAND} -E make_directory
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin
-   COMMAND ${CMAKE_COMMAND} -E copy
- ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/
-   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL})
+add_custom_command(OUTPUT "${CURRENT_TOOLS_DIR}/hmaptool"
+   COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${CURRENT_TOOLS_DIR}"
+   DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL})
-install(PROGRAMS ${CLANG_HMAPTOOL}
-DESTINATION "${CMAKE_INSTALL_BINDIR}"
-COMPONENT hmaptool)
-
-add_custom_target(hmaptool ALL DEPENDS ${Depends})
+install(PROGRAMS hmaptool DESTINATION "${LLVM_TOOLS_INSTALL_DIR}" COMPONENT hmaptool)
+add_custom_target(hmaptool ALL DEPENDS "${CURRENT_TOOLS_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 
 if(NOT LLVM_ENABLE_IDE)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d42fe9a - Revert "[clang][AIX] add option mdefault-visibility-export-mapping"

2022-06-02 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2022-06-02T15:09:39+02:00
New Revision: d42fe9aa84203a8f51b43a901d72fdc39eea69f7

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

LOG: Revert "[clang][AIX] add option mdefault-visibility-export-mapping"

This caused assertions, see comment on the code review:

llvm/clang/lib/AST/Decl.cpp:1510:
clang::LinkageInfo clang::LinkageComputer::getLVForDecl(const clang::NamedDecl 
*, clang::LVComputationKind):
Assertion `D->getCachedLinkage() == LV.getLinkage()' failed.

> The option mdefault-visibility-export-mapping is created to allow
> mapping default visibility to an explicit shared library export
> (e.g. dllexport). Exactly how and if this is manifested is target
> dependent (since it depends on how they map dllexport in the IR).
>
> Three values are provided for the option:
>
> * none: the default and behavior without the option, no additional export 
> linkage information is created.
> * explicit: add the export for entities with explict default visibility from 
> the source, including RTTI
> * all: add the export for all entities with default visibility
>
> This option is useful for targets which do not export symbols as part of
> their usual default linkage behaviour (e.g. AIX), such targets
> traditionally specified such information in external files (e.g. export
> lists), but this mapping allows them to use the visibility information
> typically used for this purpose on other (e.g. ELF) platforms.
>
> Reviewed By: MaskRay
>
> Differential Revision: https://reviews.llvm.org/D126340

This reverts commit 8c8a2679a20f621994fa904bcfc68775e7345edc.

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
clang/test/CodeGen/mdefault-visibility-export-mapping.c
clang/test/CodeGenCXX/mdefault-visibility-export-mapping-alias.cpp
clang/test/CodeGenCXX/mdefault-visibility-export-mapping-rtti.cpp
clang/test/CodeGenCXX/mdefault-visibility-export-mapping.cpp



diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index e12dc72407b13..b8c468333a67b 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3626,23 +3626,6 @@ Clang expects the GCC executable "gcc.exe" compiled for
 `Some tests might fail `_ on
 ``x86_64-w64-mingw32``.
 
-AIX
-^^^
-
-The ``-mdefault-visibility-export-mapping=`` option can be used to control
-mapping of default visibility to an explicit shared object export
-(i.e. XCOFF exported visibility). Three values are provided for the option:
-
-* ``-mdefault-visibility-export-mapping=none``: no additional export
-  information is created for entities with default visibility.
-* ``-mdefault-visibility-export-mapping=explicit``: mark entities for export
-  if they have explict (e.g. via an attribute) default visibility from the
-  source, including RTTI.
-* ``-mdefault-visibility-export-mapping=all``: set XCOFF exported visibility
-  for all entities with default visibility from any source. This gives a
-  export behavior similar to ELF platforms where all entities with default
-  visibility are exported.
-
 .. _spir-v:
 
 SPIR-V support

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 4a52a65847bbb..6e1a01c6c9767 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -289,7 +289,6 @@ BENIGN_LANGOPT(DumpRecordLayoutsComplete , 1, 0, "dumping 
the AST layout of all
 BENIGN_LANGOPT(DumpVTableLayouts , 1, 0, "dumping the layouts of emitted 
vtables")
 LANGOPT(NoConstantCFStrings , 1, 0, "no constant CoreFoundation strings")
 BENIGN_LANGOPT(InlineVisibilityHidden , 1, 0, "hidden visibility for inline 
C++ methods")
-BENIGN_ENUM_LANGOPT(DefaultVisibilityExportMapping, 
DefaultVisiblityExportMapping, 2, DefaultVisiblityExportMapping::None, 
"controls mapping of default visibility to dllexport")
 BENIGN_LANGOPT(IgnoreXCOFFVisibility, 1, 0, "All the visibility attributes 
that are specified in the source code are ignored in aix XCOFF.")
 BENIGN_LANGOPT(VisibilityInlinesHiddenStaticLocalVar, 1, 0,
"hidden visibility for static local variables in inline C++ "

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 575fa5a920cbf..6e7763a4a2b47 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -350,14 +350,6 @@ c

[PATCH] D126340: [clang][AIX] add option -mdefault-visibility-export-mapping

2022-06-02 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

We're hitting an assertion in Chromium due to this:

  llvm/clang/lib/AST/Decl.cpp:1510: clang::LinkageInfo 
clang::LinkageComputer::getLVForDecl(const clang::NamedDecl *, 
clang::LVComputationKind): Assertion `D->getCachedLinkage() == LV.getLinkage()' 
failed.

See https://bugs.chromium.org/p/chromium/issues/detail?id=1331274#c2 for a 
reproducer.

I've reverted this in d42fe9aa84203a8f51b43a901d72fdc39eea69f7 
 in the 
meantime.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126340

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


[PATCH] D126495: [clang-tidy] Organize test docs into subdirectories by module (NFC)

2022-06-02 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.

In D126495#3552887 , @njames93 wrote:

> Can I ask what the motivation is for this change?

https://discourse.llvm.org/t/clang-tidy-rfc-use-module-name-as-a-directory-for-organizing-files/62499


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

https://reviews.llvm.org/D126495

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


[PATCH] D126878: [analyzer] Remove NotifyAssumeClients

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

Measure if it changes any reports.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126878

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


[clang] b2c6251 - [PS5] Support r and y specifiers of freebsd_kernel_printf format strings

2022-06-02 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-06-02T06:27:11-07:00
New Revision: b2c6251c06700bfe8a69b780cb27928d3ba029db

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

LOG: [PS5] Support r and y specifiers of freebsd_kernel_printf format strings

Added: 


Modified: 
clang/lib/AST/FormatString.cpp
clang/test/Sema/format-strings-freebsd.c

Removed: 




diff  --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 102bcca96a389..4977aaa513195 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -760,7 +760,7 @@ bool FormatSpecifier::hasValidLengthModifier(const 
TargetInfo &Target,
   return true;
 case ConversionSpecifier::FreeBSDrArg:
 case ConversionSpecifier::FreeBSDyArg:
-  return Target.getTriple().isOSFreeBSD() || 
Target.getTriple().isPS4();
+  return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS();
 default:
   return false;
   }
@@ -795,7 +795,7 @@ bool FormatSpecifier::hasValidLengthModifier(const 
TargetInfo &Target,
   return true;
 case ConversionSpecifier::FreeBSDrArg:
 case ConversionSpecifier::FreeBSDyArg:
-  return Target.getTriple().isOSFreeBSD() || 
Target.getTriple().isPS4();
+  return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS();
 default:
   return false;
   }

diff  --git a/clang/test/Sema/format-strings-freebsd.c 
b/clang/test/Sema/format-strings-freebsd.c
index 965d7c287be65..64b526eb2f076 100644
--- a/clang/test/Sema/format-strings-freebsd.c
+++ b/clang/test/Sema/format-strings-freebsd.c
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-unknown-freebsd %s
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd %s
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-scei-ps4 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-sie-ps5 %s
 
 // Test FreeBSD kernel printf extensions.
 int freebsd_kernel_printf(const char *, ...) 
__attribute__((__format__(__freebsd_kprintf__, 1, 2)));



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


[clang] e374216 - Revert "unbreak Modules/cxx20-export-import.cpp with LLVM_APPEND_VC_REV after 8c8a2679a20f"

2022-06-02 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-06-02T09:31:57-04:00
New Revision: e37421669e223ac4e67a0158eae7d78af2ff0b88

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

LOG: Revert "unbreak Modules/cxx20-export-import.cpp with LLVM_APPEND_VC_REV 
after 8c8a2679a20f"

This reverts commit 4463bd0f89181234e0cef982e21de2e96038f873.
8c8a2679a20f was reverted in d42fe9aa8420.

Added: 


Modified: 
clang/include/clang/Serialization/ASTBitCodes.h

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 0ea8b9002a974..1ed234e644e79 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -41,7 +41,7 @@ namespace serialization {
 /// Version 4 of AST files also requires that the version control branch and
 /// revision match exactly, since there is no backward compatibility of
 /// AST files at this time.
-const unsigned VERSION_MAJOR = 20;
+const unsigned VERSION_MAJOR = 19;
 
 /// AST file minor version number supported by this version of
 /// Clang.



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


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

2022-06-02 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

@nikic can you confirm this new patch is good for standalone?

@Ericson2314 FYI in case your patch is going to improve on this.


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] D126340: [clang][AIX] add option -mdefault-visibility-export-mapping

2022-06-02 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

When you reland this, please reland 4463bd0f89181234e0cef982e21de2e96038f873 
 at the 
same time. Else, this breaks tests in some build configurations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126340

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


[clang] 0b46121 - Update more DR status information for C.

2022-06-02 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-06-02T09:32:44-04:00
New Revision: 0b46121c4130eec702066bca65802c21a9517539

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

LOG: Update more DR status information for C.

This adds new files to track DRs 100-199 and 400-499, but the file
contents are still a work in progress. It also updates the associated
status in the DR tracking page.

Added: 
clang/test/C/drs/dr1xx.c
clang/test/C/drs/dr4xx.c

Modified: 
clang/test/C/drs/dr0xx.c
clang/www/c_dr_status.html

Removed: 




diff  --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index 5cc0823eeb0b7..522f36c7141f3 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -9,6 +9,9 @@
 /* The following are DRs which do not require tests to demonstrate
  * conformance or nonconformance.
  *
+ * WG14 DR001: yes
+ * Do functions return values by copying?
+ *
  * WG14 DR005: yes
  * May a conforming implementation define and recognize a pragma which would
  * change the semantics of the language?

diff  --git a/clang/test/C/drs/dr1xx.c b/clang/test/C/drs/dr1xx.c
new file mode 100644
index 0..58c4386b3fe3b
--- /dev/null
+++ b/clang/test/C/drs/dr1xx.c
@@ -0,0 +1,73 @@
+/* RUN: %clang_cc1 -std=c89 -verify=expected,c89only -pedantic 
-Wno-c11-extensions %s
+   RUN: %clang_cc1 -std=c99 -verify=expected,c99untilc2x -pedantic 
-Wno-c11-extensions %s
+   RUN: %clang_cc1 -std=c11 -verify=expected,c99untilc2x -pedantic %s
+   RUN: %clang_cc1 -std=c17 -verify=expected,c99untilc2x -pedantic %s
+   RUN: %clang_cc1 -std=c2x -verify=expected,c2xandup -pedantic %s
+ */
+
+/* The following are DRs which do not require tests to demonstrate
+ * conformance or nonconformance.
+ *
+ * WG14 DR100: dup 001
+ * Defect with the return statement
+ *
+ * WG14 DR104: dup 084
+ * Incomplete tag types in a parameter list
+ */
+
+
+/* WG14 DR101: yes
+ * Type qualifiers and "as if by assignment"
+ */
+void dr101_callee(const int val);
+void dr101_caller(void) {
+  int val = 1;
+  dr101_callee(val); /* ok; const qualifier on the parameter doesn't prevent 
as-if assignment. */
+}
+
+/* WG14 DR102: yes
+ * Tag redeclaration constraints
+ */
+void dr102(void) {
+  struct S { int member; }; /* expected-note {{previous definition is here}} */
+  struct S { int member; }; /* expected-error {{redefinition of 'S'}} */
+
+  union U { int member; }; /* expected-note {{previous definition is here}} */
+  union U { int member; }; /* expected-error {{redefinition of 'U'}} */
+
+  enum E { member }; /* expected-note 2{{previous definition is here}} */
+  enum E { member }; /* expected-error {{redefinition of 'E'}}
+expected-error {{redefinition of enumerator 'member'}} 
*/
+}
+
+/* WG14 DR103: yes
+ * Formal parameters of incomplete type
+ */
+void dr103_1(int arg[]); /* ok, not an incomplete type due to rewrite */
+void dr103_2(struct S s) {} /* expected-warning {{declaration of 'struct S' 
will not be visible outside of this function}}
+   expected-error {{variable has incomplete type 
'struct S'}}
+   expected-note {{forward declaration of 'struct 
S'}} */
+void dr103_3(struct S s);   /* expected-warning {{declaration of 
'struct S' will not be visible outside of this function}}
+   expected-note {{previous 
declaration is here}} */
+void dr103_3(struct S { int a; } s) { } /* expected-warning {{declaration of 
'struct S' will not be visible outside of this function}}
+   expected-error {{conflicting types 
for 'dr103_3'}} */
+void dr103_4(struct S s1, struct S { int a; } s2); /* expected-warning 
{{declaration of 'struct S' will not be visible outside of this function}} */
+
+/* WG14 DR105: dup 017
+ * Precedence of requirements on compatible types
+ *
+ * NB: This is also Question 3 from DR017.
+ */
+void dr105(void) {
+  /* According to C2x 6.7.6.3p14 the return type and parameter types to be
+   * compatible types, but qualifiers are dropped from the parameter type.
+   */
+  extern void func(int);
+  extern void func(const int); /* FIXME: this should be pedantically 
diagnosed. */
+
+  extern void other_func(int);   /* expected-note {{previous declaration is 
here}} */
+  extern void other_func(int *); /* expected-error {{conflicting types for 
'other_func'}} */
+
+  extern int i;   /* expected-note {{previous declaration is here}} */
+  extern float i; /* expected-error {{redeclaration of 'i' with a 
diff erent type: 'float' vs 'int'}} */
+}

diff  --git a/clang/test/C/drs/dr4xx.c b/clang/test/C/drs/dr4xx.c
new file mode 100644
index 0..ab3407520f592
--- /dev/null
+++ b/clang/test/C/drs/dr4xx.c
@@ -0,0 +1,32 @@
+/

[PATCH] D126633: [pseudo] Use the pseudoCXX library in fuzzer.

2022-06-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

As discussed offline:

- this should really be a cross-cutting change for all tools
- we're going to have multiple grammars or variants (e.g. c, c++, obj-c)
- it would be nice to preserve the ability for tools to use a grammar from a 
file

This all points at having a library shared between {fuzzer, clang-pseudo, 
benchmark} that supports `--grammar=cxx` and `--grammar=/some/path`.

It needs to depend on CXX but isn't itself CXX, so I think it's a new library. 
Maybe `clangPseudoCLI`? I think for now the easiest thing is for the library to 
define the cl::opt flags and just expose functions to get the "current" 
grammar. (And maybe langopts should go there too)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126633

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


[PATCH] D126689: [IR] Enable opaque pointers by default

2022-06-02 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

Is anyone here ever using llvm-stress?
I noticed that with this patch, llvm-stress seems to start producing code that 
llc crashes on, and it crashes even if I run on older llc versions.
One example:

  llc -o /dev/null stress.ll

crashes with

  llc: ../lib/CodeGen/SelectionDAG/SelectionDAG.cpp:5974: llvm::SDValue 
llvm::SelectionDAG::getNode(unsigned int, const llvm::SDLoc &, llvm::EVT, 
llvm::SDValue, llvm::SDValue, const llvm::SDNodeFlags): Assertion 
`VT.isInteger() && N2.getValueType().isInteger() && "Shifts only work on 
integers"' failed.

Or is the X86 backend just not up to date with opaque pointers yet?
F23291141: stress.ll 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126689

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


[PATCH] D124690: [clangd] add inlay hints for std::forward-ed parameter packs

2022-06-02 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj updated this revision to Diff 433732.
upsj added a comment.

- fix varargs, again :)
- remove parameter names entirely if they occur multiple times


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124690

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -174,6 +174,44 @@
   )cpp");
 }
 
+TEST(ParameterHints, NoNameVariadicDeclaration) {
+  // No hint for anonymous variadic parameter
+  assertParameterHints(R"cpp(
+template 
+void foo(Args&& ...);
+void bar() {
+  foo(42);
+}
+  )cpp");
+}
+
+TEST(ParameterHints, NoNameVariadicForwarded) {
+  // No hint for anonymous variadic parameter
+  // This prototype of std::forward is sufficient for clang to recognize it
+  assertParameterHints(R"cpp(
+namespace std { template  T&& forward(T&); }
+void foo(int);
+template 
+void bar(Args&&... args) { return foo(std::forward($fwd[[args]])...); }
+void baz() {
+  bar(42);
+}
+  )cpp",
+   ExpectedHint{"&: ", "fwd"});
+}
+
+TEST(ParameterHints, NoNameVariadicPlain) {
+  // No hint for anonymous variadic parameter
+  assertParameterHints(R"cpp(
+void foo(int);
+template 
+void bar(Args&&... args) { return foo(args...); }
+void baz() {
+  bar(42);
+}
+  )cpp");
+}
+
 TEST(ParameterHints, NameInDefinition) {
   // Parameter name picked up from definition if necessary.
   assertParameterHints(R"cpp(
@@ -186,6 +224,19 @@
ExpectedHint{"param: ", "param"});
 }
 
+TEST(ParameterHints, NamePartiallyInDefinition) {
+  // Parameter name picked up from definition if necessary.
+  assertParameterHints(R"cpp(
+void foo(int, int b);
+void bar() {
+  foo($param1[[42]], $param2[[42]]);
+}
+void foo(int a, int) {};
+  )cpp",
+   ExpectedHint{"a: ", "param1"},
+   ExpectedHint{"b: ", "param2"});
+}
+
 TEST(ParameterHints, NameMismatch) {
   // Prefer name from declaration.
   assertParameterHints(R"cpp(
@@ -258,6 +309,276 @@
ExpectedHint{"param: ", "param"});
 }
 
+TEST(ParameterHints, VariadicForwardedConstructor) {
+  // Name hint for variadic parameter
+  // This prototype of std::forward is sufficient for clang to recognize it
+  assertParameterHints(R"cpp(
+namespace std { template  T&& forward(T&); }
+struct S { S(int a); };
+template 
+T bar(Args&&... args) { return T{std::forward($fwd[[args]])...}; }
+void baz() {
+  int b;
+  bar($param[[b]]);
+}
+  )cpp",
+   ExpectedHint{"&: ", "fwd"},
+   ExpectedHint{"a: ", "param"});
+}
+
+TEST(ParameterHints, VariadicPlainConstructor) {
+  // Name hint for variadic parameter
+  assertParameterHints(R"cpp(
+struct S { S(int a); };
+template 
+T bar(Args&&... args) { return T{args...}; }
+void baz() {
+  int b;
+  bar($param[[b]]);
+}
+  )cpp",
+   ExpectedHint{"a: ", "param"});
+}
+
+TEST(ParameterHints, VariadicForwardedNewConstructor) {
+  // Name hint for variadic parameter
+  // This prototype of std::forward is sufficient for clang to recognize it
+  assertParameterHints(R"cpp(
+namespace std { template  T&& forward(T&); }
+struct S { S(int a); };
+template 
+T* bar(Args&&... args) { return new T{std::forward($fwd[[args]])...}; }
+void baz() {
+  int b;
+  bar($param[[b]]);
+}
+  )cpp",
+   ExpectedHint{"&: ", "fwd"},
+   ExpectedHint{"a: ", "param"});
+}
+
+TEST(ParameterHints, VariadicPlainNewConstructor) {
+  // Name hint for variadic parameter
+  assertParameterHints(R"cpp(
+struct S { S(int a); };
+template 
+T* bar(Args&&... args) { return new T{args...}; }
+void baz() {
+  int b;
+  bar($param[[b]]);
+}
+  )cpp",
+   ExpectedHint{"a: ", "param"});
+}
+
+TEST(ParameterHints, VariadicForwarded) {
+  // Name for variadic parameter
+  // This prototype of std::forward is sufficient for clang to recognize it
+  assertParameterHints(R"cpp(
+namespace std { template  T&& forward(T&); }
+void foo(int a);
+template 
+void bar(Args&&... args) { return foo(std::forward($fwd[[args]])...); }
+void baz() {
+  int b;
+  bar($param[[b]]);
+}
+  )cpp",
+   ExpectedHint{"&: ", "fwd"},
+   ExpectedHint{"a: ", "param"});
+}
+
+TEST(ParameterHints, VariadicPlain) {
+  // Name hint for variadic parameter
+  assertParameterHints(R"cpp(
+void 

[PATCH] D126801: [analyzer][NFC] Add partial specializations for ProgramStateTraits

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

- host common implementation


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

https://reviews.llvm.org/D126801

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h
  clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -82,9 +82,7 @@
 REGISTER_SET_WITH_PROGRAMSTATE(InvalidMemoryRegions, const MemRegion *)
 
 // Stores the region of the environment pointer of 'main' (if present).
-// Note: This pointer has type 'const MemRegion *', however the trait is only
-// specialized to 'const void*' and 'void*'
-REGISTER_TRAIT_WITH_PROGRAMSTATE(EnvPtrRegion, const void *)
+REGISTER_TRAIT_WITH_PROGRAMSTATE(EnvPtrRegion, const MemRegion *)
 
 // Stores key-value pairs, where key is function declaration and value is
 // pointer to memory region returned by previous call of this function
@@ -95,11 +93,9 @@
  CheckerContext &C) const {
   StringRef FunctionName = Call.getCalleeIdentifier()->getName();
   ProgramStateRef State = C.getState();
-  const auto *Reg = State->get();
-  if (!Reg)
+  const MemRegion *SymbolicEnvPtrRegion = State->get();
+  if (!SymbolicEnvPtrRegion)
 return;
-  const auto *SymbolicEnvPtrRegion =
-  reinterpret_cast(const_cast(Reg));
 
   State = State->add(SymbolicEnvPtrRegion);
 
@@ -245,9 +241,7 @@
 
   // Save the memory region pointed by the environment pointer parameter of
   // 'main'.
-  State = State->set(
-  reinterpret_cast(const_cast(EnvpReg)));
-  C.addTransition(State);
+  C.addTransition(State->set(EnvpReg));
 }
 
 // Check if invalidated region is being dereferenced.
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h
@@ -21,29 +21,33 @@
 #include "llvm/ADT/ImmutableSet.h"
 #include "llvm/Support/Allocator.h"
 #include 
+#include 
 
 namespace clang {
 namespace ento {
 
-  template  struct ProgramStatePartialTrait;
-
-  /// Declares a program state trait for type \p Type called \p Name, and
-  /// introduce a type named \c NameTy.
-  /// The macro should not be used inside namespaces.
-  #define REGISTER_TRAIT_WITH_PROGRAMSTATE(Name, Type) \
-namespace { \
-  class Name {}; \
-  using Name ## Ty = Type; \
-} \
-namespace clang { \
-namespace ento { \
-  template <> \
-  struct ProgramStateTrait \
-: public ProgramStatePartialTrait { \
-static void *GDMIndex() { static int Index; return &Index; } \
-  }; \
-} \
-}
+template 
+struct ProgramStatePartialTrait;
+
+/// Declares a program state trait for type \p Type called \p Name, and
+/// introduce a type named \c NameTy.
+/// The macro should not be used inside namespaces.
+#define REGISTER_TRAIT_WITH_PROGRAMSTATE(Name, Type)   \
+  namespace {  \
+  class Name {};   \
+  using Name##Ty = Type;   \
+  }\
+  namespace clang {\
+  namespace ento { \
+  template <>  \
+  struct ProgramStateTrait : public ProgramStatePartialTrait { \
+static void *GDMIndex() {  \
+  static int Index;\
+  return &Index;   \
+}  \
+  };   \
+  }\
+  }
 
   /// Declares a factory for objects of type \p Type in the program state
   /// manager. The type must provide a ::Factory sub-class. Commonly used for
@@ -267,60 +271,28 @@
 }
   };
 
-  // Partial specialization for bool.
-  template <> struct ProgramStatePartialTrait {
-using data_type = bool;
-
-static data_type MakeData(void *const *p) {
-  return p ? (data_type) (uintptr_t) *p
-   : data_type();
-}
-
-static void *MakeVoidPtr

[PATCH] D126802: [analyzer][NFC] Uplift checkers after D126801

2022-06-02 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 433737.
steakhal marked 2 inline comments as done.
steakhal added a comment.

- replace `auto`


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

https://reviews.llvm.org/D126802

Files:
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
@@ -101,7 +101,7 @@
 /// 'self' contains. This keeps the "self flags" assigned to the 'self'
 /// object before the call so we can assign them to the new object that 'self'
 /// points to after the call.
-REGISTER_TRAIT_WITH_PROGRAMSTATE(PreCallSelfFlags, unsigned)
+REGISTER_TRAIT_WITH_PROGRAMSTATE(PreCallSelfFlags, SelfFlagEnum)
 
 static SelfFlagEnum getSelfFlags(SVal val, ProgramStateRef state) {
   if (SymbolRef sym = val.getAsSymbol())
@@ -251,11 +251,12 @@
   for (unsigned i = 0; i < NumArgs; ++i) {
 SVal argV = CE.getArgSVal(i);
 if (isSelfVar(argV, C)) {
-  unsigned selfFlags = getSelfFlags(state->getSVal(argV.castAs()), C);
+  SelfFlagEnum selfFlags =
+  getSelfFlags(state->getSVal(argV.castAs()), C);
   C.addTransition(state->set(selfFlags));
   return;
 } else if (hasSelfFlag(argV, SelfFlag_Self, C)) {
-  unsigned selfFlags = getSelfFlags(argV, C);
+  SelfFlagEnum selfFlags = getSelfFlags(argV, C);
   C.addTransition(state->set(selfFlags));
   return;
 }
Index: clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
@@ -68,13 +68,7 @@
 
 /// Store a MemRegion that contains the 'errno' integer value.
 /// The value is null if the 'errno' value was not recognized in the AST.
-REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoRegion, const void *)
-
-/// An internal function accessing the errno region.
-/// Returns null if there isn't any associated memory region.
-static const MemRegion *getErrnoRegion(ProgramStateRef State) {
-  return reinterpret_cast(State->get());
-}
+REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoRegion, const MemRegion *)
 
 /// Search for a variable called "errno" in the AST.
 /// Return nullptr if not found.
@@ -185,7 +179,7 @@
   if (ErrnoLocationCalls.contains(Call)) {
 ProgramStateRef State = C.getState();
 
-const MemRegion *ErrnoR = getErrnoRegion(State);
+const MemRegion *ErrnoR = State->get();
 if (!ErrnoR)
   return false;
 
@@ -201,7 +195,7 @@
 void ErrnoModeling::checkLiveSymbols(ProgramStateRef State,
  SymbolReaper &SR) const {
   // The special errno region should never garbage collected.
-  if (const auto *ErrnoR = getErrnoRegion(State))
+  if (const MemRegion *ErrnoR = State->get())
 SR.markLive(ErrnoR);
 }
 
@@ -210,7 +204,7 @@
 namespace errno_modeling {
 
 Optional getErrnoValue(ProgramStateRef State) {
-  const MemRegion *ErrnoR = getErrnoRegion(State);
+  const MemRegion *ErrnoR = State->get();
   if (!ErrnoR)
 return {};
   QualType IntTy = State->getAnalysisManager().getASTContext().IntTy;
@@ -219,7 +213,7 @@
 
 ProgramStateRef setErrnoValue(ProgramStateRef State,
   const LocationContext *LCtx, SVal Value) {
-  const MemRegion *ErrnoR = getErrnoRegion(State);
+  const MemRegion *ErrnoR = State->get();
   if (!ErrnoR)
 return State;
   return State->bindLoc(loc::MemRegionVal{ErrnoR}, Value, LCtx);
@@ -227,7 +221,7 @@
 
 ProgramStateRef setErrnoValue(ProgramStateRef State, CheckerContext &C,
   uint64_t Value) {
-  const MemRegion *ErrnoR = getErrnoRegion(State);
+  const MemRegion *ErrnoR = State->get();
   if (!ErrnoR)
 return State;
   return State->bindLoc(


Index: clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
@@ -101,7 +101,7 @@
 /// 'self' contains. This keeps the "self flags" assigned to the 'self'
 /// object before the call so we can assign them to the new object that 'self'
 /// points to after the call.
-REGISTER_TRAIT_WITH_PROGRAMSTATE(PreCallSelfFlags, unsigned)
+REGISTER_TRAIT_WITH_PROGRAMSTATE(PreCallSelfFlags, SelfFlagEnum)
 
 static SelfFlagEnum getSelfFlags(SVal val, ProgramStateRef state) {
   if (SymbolRef sym = val.getAsSymbol())
@@ -251,11 +251,12 @@
   for (unsigned i = 0; i < NumArgs; ++i) {
 SVal argV = CE.getArgSVal(i);
 if (isSelfVar(argV, C)) {
-  unsigned selfFlags = getSelfFlags(state->getSVal(argV.castAs()), C);
+  SelfFlagEnum selfFlags =
+  getSelfFlags(stat

[PATCH] D126803: [llvm][analyzer][NFC] Introduce SFINAE for specializing FoldingSetTraits

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

- rebase


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

https://reviews.llvm.org/D126803

Files:
  clang/include/clang/Basic/SourceLocation.h
  clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
  llvm/include/llvm/ADT/FoldingSet.h
  llvm/include/llvm/CodeGen/SelectionDAG.h

Index: llvm/include/llvm/CodeGen/SelectionDAG.h
===
--- llvm/include/llvm/CodeGen/SelectionDAG.h
+++ llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -58,7 +58,7 @@
 class Type;
 template  struct GraphTraits;
 template  class SmallSetVector;
-template  struct FoldingSetTrait;
+template  struct FoldingSetTrait;
 class AAResults;
 class BlockAddress;
 class BlockFrequencyInfo;
Index: llvm/include/llvm/ADT/FoldingSet.h
===
--- llvm/include/llvm/ADT/FoldingSet.h
+++ llvm/include/llvm/ADT/FoldingSet.h
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace llvm {
@@ -256,8 +257,8 @@
 /// through template specialization the behavior can be tailored for specific
 /// types.  Combined with the FoldingSetNodeWrapper class, one can add objects
 /// to FoldingSets that were not originally designed to have that behavior.
-template struct FoldingSetTrait
-  : public DefaultFoldingSetTrait {};
+template 
+struct FoldingSetTrait : public DefaultFoldingSetTrait {};
 
 /// DefaultContextualFoldingSetTrait - Like DefaultFoldingSetTrait, but
 /// for ContextualFoldingSets.
@@ -828,6 +829,14 @@
   }
 };
 
+template 
+struct FoldingSetTrait<
+T, typename std::enable_if_t::value, void>> {
+  static void Profile(const T &X, FoldingSetNodeID &ID) {
+ID.AddInteger(static_cast>(X));
+  }
+};
+
 } // end namespace llvm
 
 #endif // LLVM_ADT_FOLDINGSET_H
Index: clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
@@ -94,7 +94,7 @@
 };
 }
 
-REGISTER_MAP_WITH_PROGRAMSTATE(SelfFlag, SymbolRef, unsigned)
+REGISTER_MAP_WITH_PROGRAMSTATE(SelfFlag, SymbolRef, SelfFlagEnum)
 REGISTER_TRAIT_WITH_PROGRAMSTATE(CalledInit, bool)
 
 /// A call receiving a reference to 'self' invalidates the object that
@@ -105,8 +105,8 @@
 
 static SelfFlagEnum getSelfFlags(SVal val, ProgramStateRef state) {
   if (SymbolRef sym = val.getAsSymbol())
-if (const unsigned *attachedFlags = state->get(sym))
-  return (SelfFlagEnum)*attachedFlags;
+if (const SelfFlagEnum *attachedFlags = state->get(sym))
+  return *attachedFlags;
   return SelfFlag_None;
 }
 
@@ -118,7 +118,8 @@
 SelfFlagEnum flag, CheckerContext &C) {
   // We tag the symbol that the SVal wraps.
   if (SymbolRef sym = val.getAsSymbol()) {
-state = state->set(sym, getSelfFlags(val, state) | flag);
+state = state->set(sym,
+ SelfFlagEnum(getSelfFlags(val, state) | flag));
 C.addTransition(state);
   }
 }
@@ -271,7 +272,7 @@
 return;
 
   ProgramStateRef state = C.getState();
-  SelfFlagEnum prevFlags = (SelfFlagEnum)state->get();
+  SelfFlagEnum prevFlags = state->get();
   if (!prevFlags)
 return;
   state = state->remove();
@@ -339,7 +340,7 @@
  const char *NL, const char *Sep) const {
   SelfFlagTy FlagMap = State->get();
   bool DidCallInit = State->get();
-  SelfFlagEnum PreCallFlags = (SelfFlagEnum)State->get();
+  SelfFlagEnum PreCallFlags = State->get();
 
   if (FlagMap.isEmpty() && !DidCallInit && !PreCallFlags)
 return;
Index: clang/include/clang/Basic/SourceLocation.h
===
--- clang/include/clang/Basic/SourceLocation.h
+++ clang/include/clang/Basic/SourceLocation.h
@@ -24,7 +24,7 @@
 namespace llvm {
 
 class FoldingSetNodeID;
-template  struct FoldingSetTrait;
+template  struct FoldingSetTrait;
 
 } // namespace llvm
 
@@ -87,7 +87,7 @@
   friend class ASTReader;
   friend class ASTWriter;
   friend class SourceManager;
-  friend struct llvm::FoldingSetTrait;
+  friend struct llvm::FoldingSetTrait;
 
 public:
   using UIntTy = uint32_t;
@@ -507,7 +507,7 @@
   };
 
   // Allow calling FoldingSetNodeID::Add with SourceLocation object as parameter
-  template <> struct FoldingSetTrait {
+  template <> struct FoldingSetTrait {
 static void Profile(const clang::SourceLocation &X, FoldingSetNodeID &ID);
   };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126816: Only issue warning for subtraction involving null pointers on live code paths

2022-06-02 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser updated this revision to Diff 433736.
jamieschmeiser edited the summary of this revision.
jamieschmeiser added a comment.

Respond to review comments: add cpp test.


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

https://reviews.llvm.org/D126816

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/pointer-subtraction.c
  clang/test/Sema/pointer-subtraction.cpp


Index: clang/test/Sema/pointer-subtraction.cpp
===
--- clang/test/Sema/pointer-subtraction.cpp
+++ clang/test/Sema/pointer-subtraction.cpp
@@ -11,6 +11,16 @@
   f = (char *)(f - (char *)0); // expected-warning {{performing 
pointer subtraction with a null pointer may have undefined behavior}}
   f = (char *)((char *)0 - (char *)0); // valid in C++
 
+  if (1)
+f = (char *)((char *)0 - f); // expected-warning {{performing 
pointer subtraction with a null pointer may have undefined behavior}}
+  else
+f = (char *)((char *)0 - f);
+
+  if (0)
+f = (char *)((char *)0 - f);
+  else
+f = (char *)((char *)0 - f); // expected-warning {{performing 
pointer subtraction with a null pointer may have undefined behavior}}
+
 #ifndef SYSTEM_WARNINGS
   SYSTEM_MACRO(f);
 #else
Index: clang/test/Sema/pointer-subtraction.c
===
--- clang/test/Sema/pointer-subtraction.c
+++ clang/test/Sema/pointer-subtraction.c
@@ -11,6 +11,16 @@
   f = (char *)(f - (char *)0); // expected-warning {{performing 
pointer subtraction with a null pointer has undefined behavior}}
   f = (char *)((char *)0 - (char *)0); // expected-warning {{performing 
pointer subtraction with a null pointer has undefined behavior}} 
expected-warning {{performing pointer subtraction with a null pointer has 
undefined behavior}}
 
+  if (1)
+f = (char *)((char *)0 - f); // expected-warning {{performing 
pointer subtraction with a null pointer has undefined behavior}}
+  else
+f = (char *)((char *)0 - f);
+
+  if (0)
+f = (char *)((char *)0 - f);
+  else
+f = (char *)((char *)0 - f); // expected-warning {{performing 
pointer subtraction with a null pointer has undefined behavior}}
+
 #ifndef SYSTEM_WARNINGS
   SYSTEM_MACRO(f);
 #else
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -10845,8 +10845,10 @@
   if (S.Diags.getSuppressSystemWarnings() && S.SourceMgr.isInSystemMacro(Loc))
 return;
 
-  S.Diag(Loc, diag::warn_pointer_sub_null_ptr)
-  << S.getLangOpts().CPlusPlus << Pointer->getSourceRange();
+  S.DiagRuntimeBehavior(Loc, Pointer,
+S.PDiag(diag::warn_pointer_sub_null_ptr)
+<< S.getLangOpts().CPlusPlus
+<< Pointer->getSourceRange());
 }
 
 /// Diagnose invalid arithmetic on two function pointers.


Index: clang/test/Sema/pointer-subtraction.cpp
===
--- clang/test/Sema/pointer-subtraction.cpp
+++ clang/test/Sema/pointer-subtraction.cpp
@@ -11,6 +11,16 @@
   f = (char *)(f - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}}
   f = (char *)((char *)0 - (char *)0); // valid in C++
 
+  if (1)
+f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}}
+  else
+f = (char *)((char *)0 - f);
+
+  if (0)
+f = (char *)((char *)0 - f);
+  else
+f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer may have undefined behavior}}
+
 #ifndef SYSTEM_WARNINGS
   SYSTEM_MACRO(f);
 #else
Index: clang/test/Sema/pointer-subtraction.c
===
--- clang/test/Sema/pointer-subtraction.c
+++ clang/test/Sema/pointer-subtraction.c
@@ -11,6 +11,16 @@
   f = (char *)(f - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
   f = (char *)((char *)0 - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}} expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
 
+  if (1)
+f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+  else
+f = (char *)((char *)0 - f);
+
+  if (0)
+f = (char *)((char *)0 - f);
+  else
+f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+
 #ifndef SYSTEM_WARNINGS
   SYSTEM_MACRO(f);
 #else
Index: clang/lib/Sema/SemaExpr.cpp
=

[PATCH] D126801: [analyzer][NFC] Add partial specializations for ProgramStateTraits

2022-06-02 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h:292
 
-static void *MakeVoidPtr(data_type d) {
-  return const_cast(d);
-}
-  };
+  // Partial specialization for non-const and const pointers.
+  template 




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

https://reviews.llvm.org/D126801

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


[PATCH] D126880: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

2022-06-02 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp created this revision.
Herald added subscribers: shchenz, kbarton, xazax.hun, mgorny, nemanjai.
Herald added a project: All.
carlosgalvezp requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Flags uses of const-qualified and reference data members in structs.
Implements rule C.12 of C++ Core Guidelines.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126880

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-const-or-ref-data-members.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
@@ -0,0 +1,121 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-const-or-ref-data-members %t
+namespace std {
+template 
+struct reference_wrapper {};
+} // namespace std
+
+namespace gsl {
+template 
+struct not_null {};
+} // namespace gsl
+
+struct Ok {
+  int i;
+  int *p;
+  const int *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember {
+  const int c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
+};
+
+struct RefMember {
+  int &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+};
+
+struct RefRefMember {
+  int &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstRefMember {
+  const int &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'r' is a reference
+};
+
+struct ConstAndRefMember {
+  int const c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  int &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+  int &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct Foo {};
+
+struct Ok2 {
+  Foo i;
+  Foo *p;
+  const Foo *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
+};
+
+struct RefMember2 {
+  Foo &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+};
+
+struct RefRefMember2 {
+  Foo &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstRefMember2 {
+  const Foo &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'r' is a reference
+};
+
+struct ConstAndRefMember2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  Foo &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+  Foo &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+using ConstType = const int;
+using RefType = int &;
+using RefRefType = int &&;
+
+struct WithAlias {
+  ConstType c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  RefType r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: member 'r' is a reference
+  RefRefType rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'rr' is a reference
+};
+
+template 
+struct TemplatedConst {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is const qualified
+};
+
+template 
+struct TemplatedRef {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is a reference
+};
+
+template 
+struct TemplatedOk {
+  T t;
+};
+
+TemplatedConst t1{123};
+TemplatedRef t2{123};
+TemplatedRef t3{123};
+TemplatedOk t4{};
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -151,6 +151,7 @@
`clang-analyzer-valist.Unterminated `_,
`concurrency-mt-unsafe `_,
`concurrency-thread-canceltype-asynchronous `_,
+   `cppcoreguidelines-avoid-const-or-ref-data-members `_,
`cppcoreguidelines-avoid-goto `_,
`cppcoreguidelines-avoid-non-const-global-variables `_,
`cppcoreguidelines-init-variables `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-const-or-ref-data-members.rst
===

[PATCH] D126802: [analyzer][NFC] Uplift checkers after D126801

2022-06-02 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D126802

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


[PATCH] D126881: Use default arguments instead of overloads.

2022-06-02 Thread Andy Soffer via Phabricator via cfe-commits
asoffer created this revision.
Herald added a project: All.
asoffer 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/D126881

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


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -757,6 +757,7 @@
 std::unique_ptr ASTUnit::LoadFromASTFile(
 const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
 WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+IntrusiveRefCntPtr VFS,
 const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
 bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
 bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
@@ -775,8 +776,6 @@
   AST->OnlyLocalDecls = OnlyLocalDecls;
   AST->CaptureDiagnostics = CaptureDiagnostics;
   AST->Diagnostics = Diags;
-  IntrusiveRefCntPtr VFS =
-  llvm::vfs::getRealFileSystem();
   AST->FileMgr = new FileManager(FileSystemOpts, VFS);
   AST->UserFilesAreVolatile = UserFilesAreVolatile;
   AST->SourceMgr = new SourceManager(AST->getDiagnostics(),
@@ -867,6 +866,18 @@
   return AST;
 }
 
+std::unique_ptr ASTUnit::LoadFromASTFile(
+const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
+WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
+bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
+bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
+  return LoadFromASTFile(Filename, PCHContainerRdr, ToLoad, Diags,
+ llvm::vfs::getRealFileSystem(), FileSystemOpts,
+ UseDebugInfo, OnlyLocalDecls, CaptureDiagnostics,
+ AllowASTWithCompilerErrors, UserFilesAreVolatile);
+}
+
 /// Add the given macro to the hash of all top-level entities.
 static void AddDefinedMacroToHash(const Token &MacroNameTok, unsigned &Hash) {
   Hash = llvm::djbHash(MacroNameTok.getIdentifierInfo()->getName(), Hash);
Index: clang/include/clang/Frontend/ASTUnit.h
===
--- clang/include/clang/Frontend/ASTUnit.h
+++ clang/include/clang/Frontend/ASTUnit.h
@@ -688,17 +688,25 @@
   /// lifetime is expected to extend past that of the returned ASTUnit.
   ///
   /// \returns - The initialized ASTUnit or null if the AST failed to load.
-  static std::unique_ptr
-  LoadFromASTFile(const std::string &Filename,
-  const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad,
-  IntrusiveRefCntPtr Diags,
-  const FileSystemOptions &FileSystemOpts,
-  bool UseDebugInfo = false, bool OnlyLocalDecls = false,
-  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
-  bool AllowASTWithCompilerErrors = false,
-  bool UserFilesAreVolatile = false);
+  static std::unique_ptr LoadFromASTFile(
+  const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
+  WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+  IntrusiveRefCntPtr VFS,
+  const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false,
+  bool OnlyLocalDecls = false,
+  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
+  bool AllowASTWithCompilerErrors = false,
+  bool UserFilesAreVolatile = false);
+  static std::unique_ptr LoadFromASTFile(
+  const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
+  WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+  const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false,
+  bool OnlyLocalDecls = false,
+  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
+  bool AllowASTWithCompilerErrors = false,
+  bool UserFilesAreVolatile = false);
 
-private:
+ private:
   /// Helper function for \c LoadFromCompilerInvocation() and
   /// \c LoadFromCommandLine(), which loads an AST from a compiler invocation.
   ///


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -757,6 +757,7 @@
 std::unique_ptr ASTUnit::LoadFromASTFile(
 const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
 WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+IntrusiveRefCntPtr VFS,
 const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
 bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
 bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
@@ -775,8 +776,6 @@
   AST->OnlyLocalDecls = OnlyLocalDecls;
   AST->CaptureDiagnostics = CaptureDiagnostics;
   AST->Diagnostics = Diags;
-  IntrusiveRefCntPtr VFS =
-  llvm::

[PATCH] D126880: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

2022-06-02 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 433743.
carlosgalvezp added a comment.

Fix FIXME


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126880

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-const-or-ref-data-members.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
@@ -0,0 +1,121 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-const-or-ref-data-members %t
+namespace std {
+template 
+struct reference_wrapper {};
+} // namespace std
+
+namespace gsl {
+template 
+struct not_null {};
+} // namespace gsl
+
+struct Ok {
+  int i;
+  int *p;
+  const int *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember {
+  const int c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
+};
+
+struct RefMember {
+  int &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+};
+
+struct RefRefMember {
+  int &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstRefMember {
+  const int &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'r' is a reference
+};
+
+struct ConstAndRefMember {
+  int const c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  int &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+  int &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct Foo {};
+
+struct Ok2 {
+  Foo i;
+  Foo *p;
+  const Foo *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
+};
+
+struct RefMember2 {
+  Foo &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+};
+
+struct RefRefMember2 {
+  Foo &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstRefMember2 {
+  const Foo &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'r' is a reference
+};
+
+struct ConstAndRefMember2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  Foo &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+  Foo &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+using ConstType = const int;
+using RefType = int &;
+using RefRefType = int &&;
+
+struct WithAlias {
+  ConstType c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  RefType r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: member 'r' is a reference
+  RefRefType rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'rr' is a reference
+};
+
+template 
+struct TemplatedConst {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is const qualified
+};
+
+template 
+struct TemplatedRef {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is a reference
+};
+
+template 
+struct TemplatedOk {
+  T t;
+};
+
+TemplatedConst t1{123};
+TemplatedRef t2{123};
+TemplatedRef t3{123};
+TemplatedOk t4{};
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -151,6 +151,7 @@
`clang-analyzer-valist.Unterminated `_,
`concurrency-mt-unsafe `_,
`concurrency-thread-canceltype-asynchronous `_,
+   `cppcoreguidelines-avoid-const-or-ref-data-members `_,
`cppcoreguidelines-avoid-goto `_,
`cppcoreguidelines-avoid-non-const-global-variables `_,
`cppcoreguidelines-init-variables `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-const-or-ref-data-members.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-const-or-ref-data-members.rst
@@ -0,0 +1,48 @@
+.. title:: clang-tidy - cppcoreguidelines-avoid-const-or-ref-data-members

[PATCH] D126881: Use default arguments instead of overloads.

2022-06-02 Thread Andy Soffer via Phabricator via cfe-commits
asoffer updated this revision to Diff 433744.
asoffer added a comment.

Use default arguments instead of overloads.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126881

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


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -757,6 +757,7 @@
 std::unique_ptr ASTUnit::LoadFromASTFile(
 const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
 WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+IntrusiveRefCntPtr VFS,
 const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
 bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
 bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
@@ -775,8 +776,6 @@
   AST->OnlyLocalDecls = OnlyLocalDecls;
   AST->CaptureDiagnostics = CaptureDiagnostics;
   AST->Diagnostics = Diags;
-  IntrusiveRefCntPtr VFS =
-  llvm::vfs::getRealFileSystem();
   AST->FileMgr = new FileManager(FileSystemOpts, VFS);
   AST->UserFilesAreVolatile = UserFilesAreVolatile;
   AST->SourceMgr = new SourceManager(AST->getDiagnostics(),
@@ -867,6 +866,18 @@
   return AST;
 }
 
+std::unique_ptr ASTUnit::LoadFromASTFile(
+const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
+WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
+bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
+bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
+  return LoadFromASTFile(Filename, PCHContainerRdr, ToLoad, Diags,
+ llvm::vfs::getRealFileSystem(), FileSystemOpts,
+ UseDebugInfo, OnlyLocalDecls, CaptureDiagnostics,
+ AllowASTWithCompilerErrors, UserFilesAreVolatile);
+}
+
 /// Add the given macro to the hash of all top-level entities.
 static void AddDefinedMacroToHash(const Token &MacroNameTok, unsigned &Hash) {
   Hash = llvm::djbHash(MacroNameTok.getIdentifierInfo()->getName(), Hash);
Index: clang/include/clang/Frontend/ASTUnit.h
===
--- clang/include/clang/Frontend/ASTUnit.h
+++ clang/include/clang/Frontend/ASTUnit.h
@@ -688,17 +688,25 @@
   /// lifetime is expected to extend past that of the returned ASTUnit.
   ///
   /// \returns - The initialized ASTUnit or null if the AST failed to load.
-  static std::unique_ptr
-  LoadFromASTFile(const std::string &Filename,
-  const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad,
-  IntrusiveRefCntPtr Diags,
-  const FileSystemOptions &FileSystemOpts,
-  bool UseDebugInfo = false, bool OnlyLocalDecls = false,
-  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
-  bool AllowASTWithCompilerErrors = false,
-  bool UserFilesAreVolatile = false);
+  static std::unique_ptr LoadFromASTFile(
+  const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
+  WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+  IntrusiveRefCntPtr VFS,
+  const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false,
+  bool OnlyLocalDecls = false,
+  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
+  bool AllowASTWithCompilerErrors = false,
+  bool UserFilesAreVolatile = false);
+  static std::unique_ptr LoadFromASTFile(
+  const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
+  WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+  const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false,
+  bool OnlyLocalDecls = false,
+  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
+  bool AllowASTWithCompilerErrors = false,
+  bool UserFilesAreVolatile = false);
 
-private:
+ private:
   /// Helper function for \c LoadFromCompilerInvocation() and
   /// \c LoadFromCommandLine(), which loads an AST from a compiler invocation.
   ///


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -757,6 +757,7 @@
 std::unique_ptr ASTUnit::LoadFromASTFile(
 const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
 WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+IntrusiveRefCntPtr VFS,
 const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
 bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
 bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
@@ -775,8 +776,6 @@
   AST->OnlyLocalDecls = OnlyLocalDecls;
   AST->CaptureDiagnostics = CaptureDiagnostics;
   AST->Diagnostics = Diags;
-  IntrusiveRefCntPtr VFS =
-  

[PATCH] D126881: Use default arguments instead of overloads.

2022-06-02 Thread Andy Soffer via Phabricator via cfe-commits
asoffer updated this revision to Diff 433745.
asoffer added a comment.

Remove non-existant overload from cpp file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126881

Files:
  clang/lib/Frontend/ASTUnit.cpp


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -866,18 +866,6 @@
   return AST;
 }
 
-std::unique_ptr ASTUnit::LoadFromASTFile(
-const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
-WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
-const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
-bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
-bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
-  return LoadFromASTFile(Filename, PCHContainerRdr, ToLoad, Diags,
- llvm::vfs::getRealFileSystem(), FileSystemOpts,
- UseDebugInfo, OnlyLocalDecls, CaptureDiagnostics,
- AllowASTWithCompilerErrors, UserFilesAreVolatile);
-}
-
 /// Add the given macro to the hash of all top-level entities.
 static void AddDefinedMacroToHash(const Token &MacroNameTok, unsigned &Hash) {
   Hash = llvm::djbHash(MacroNameTok.getIdentifierInfo()->getName(), Hash);


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -866,18 +866,6 @@
   return AST;
 }
 
-std::unique_ptr ASTUnit::LoadFromASTFile(
-const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
-WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
-const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
-bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
-bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
-  return LoadFromASTFile(Filename, PCHContainerRdr, ToLoad, Diags,
- llvm::vfs::getRealFileSystem(), FileSystemOpts,
- UseDebugInfo, OnlyLocalDecls, CaptureDiagnostics,
- AllowASTWithCompilerErrors, UserFilesAreVolatile);
-}
-
 /// Add the given macro to the hash of all top-level entities.
 static void AddDefinedMacroToHash(const Token &MacroNameTok, unsigned &Hash) {
   Hash = llvm::djbHash(MacroNameTok.getIdentifierInfo()->getName(), Hash);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126689: [IR] Enable opaque pointers by default

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

@uabelho Here's a slightly cleaned up test case that does not use opaque 
pointers:

  target triple = "x86_64-unknown-linux-gnu"
  
  define void @test(i1 %cond, <1 x i16>* %p) {
br label %loop
  
  loop:
%v = load <1 x i16>, <1 x i16>* %p, align 2
%ins = insertelement <4 x double> zeroinitializer, double 0.00e+00, i32 0
%cmp = fcmp uge <4 x double> %ins, zeroinitializer
%ashr = ashr <1 x i16> %v, %v
%shuf = shufflevector <4 x i1> %cmp, <4 x i1> zeroinitializer, <4 x i32> 
zeroinitializer
br i1 %cond, label %loop, label %exit
  
  exit:
%use1 = add <4 x i1> %shuf, zeroinitializer
%use2 = add <1 x i16> %ashr, zeroinitializer
ret void
  }

llvm-stress can probably generate certain code patterns when opaque pointers 
are enabled, which it does not produce when typed pointers are used. In this 
case at least, the used pointer type doesn't matter in the end.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126689

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


[PATCH] D126806: Add an overload to ASTUnit::LoadFromASTFile that accepts a virtual file system.

2022-06-02 Thread Andy Soffer via Phabricator via cfe-commits
asoffer updated this revision to Diff 433747.
asoffer added a comment.

Use default arguments instead of overloads.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126806

Files:
  clang/lib/Frontend/ASTUnit.cpp


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -866,18 +866,6 @@
   return AST;
 }
 
-std::unique_ptr ASTUnit::LoadFromASTFile(
-const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
-WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
-const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
-bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
-bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
-  return LoadFromASTFile(Filename, PCHContainerRdr, ToLoad, Diags,
- llvm::vfs::getRealFileSystem(), FileSystemOpts,
- UseDebugInfo, OnlyLocalDecls, CaptureDiagnostics,
- AllowASTWithCompilerErrors, UserFilesAreVolatile);
-}
-
 /// Add the given macro to the hash of all top-level entities.
 static void AddDefinedMacroToHash(const Token &MacroNameTok, unsigned &Hash) {
   Hash = llvm::djbHash(MacroNameTok.getIdentifierInfo()->getName(), Hash);


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -866,18 +866,6 @@
   return AST;
 }
 
-std::unique_ptr ASTUnit::LoadFromASTFile(
-const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
-WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
-const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
-bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
-bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
-  return LoadFromASTFile(Filename, PCHContainerRdr, ToLoad, Diags,
- llvm::vfs::getRealFileSystem(), FileSystemOpts,
- UseDebugInfo, OnlyLocalDecls, CaptureDiagnostics,
- AllowASTWithCompilerErrors, UserFilesAreVolatile);
-}
-
 /// Add the given macro to the hash of all top-level entities.
 static void AddDefinedMacroToHash(const Token &MacroNameTok, unsigned &Hash) {
   Hash = llvm::djbHash(MacroNameTok.getIdentifierInfo()->getName(), Hash);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126806: Add an overload to ASTUnit::LoadFromASTFile that accepts a virtual file system.

2022-06-02 Thread Andy Soffer via Phabricator via cfe-commits
asoffer abandoned this revision.
asoffer added a comment.

I don't know what happened here, but when I update a diff half my changes 
disappear. I'm going to recreate this in a new diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126806

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


[clang] 5a6352b - Tidy up `pragma comment lib` handling and testing

2022-06-02 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-06-02T07:52:26-07:00
New Revision: 5a6352bc70fb0f309de22ea75ef132f32d8be9b4

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

LOG: Tidy up `pragma comment lib` handling and testing

A bit of historical research shows that over the years:
Commit 99efc036 added `pragma comment lib` support for PS4.
Commit fd4db533 added `pragma comment lib` support for all ELF targets.
Commit 1d16515f reworked dependent-library support for all ELF targets.

The upshot is that some PS4-specific code became dead, and the
testing became somewhat fragmented.  I've removed the dead code and
combined the previous PS4-specific and linux-specific tests for the
diagnostics into one generic ELF test.
Also added a couple of PS5 runs while I was in there.

Added: 
clang/test/Preprocessor/pragma-comment-elf.c

Modified: 
clang/lib/Parse/ParsePragma.cpp
clang/test/CodeGen/pragma-comment.c

Removed: 
clang/test/Preprocessor/pragma-comment-linux.c
clang/test/Preprocessor/pragma_ps4.c



diff  --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index f8e311c7c35ad..c94640c31c500 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -3027,14 +3027,6 @@ void PragmaCommentHandler::HandlePragma(Preprocessor &PP,
 return;
   }
 
-  // On PS4, issue a warning about any pragma comments other than
-  // #pragma comment lib.
-  if (PP.getTargetInfo().getTriple().isPS4() && Kind != PCK_Lib) {
-PP.Diag(Tok.getLocation(), diag::warn_pragma_comment_ignored)
-  << II->getName();
-return;
-  }
-
   // Read the optional string if present.
   PP.Lex(Tok);
   std::string ArgumentString;

diff  --git a/clang/test/CodeGen/pragma-comment.c 
b/clang/test/CodeGen/pragma-comment.c
index 25675d94c5a4d..a4746f5c47bf6 100644
--- a/clang/test/CodeGen/pragma-comment.c
+++ b/clang/test/CodeGen/pragma-comment.c
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 %s -triple thumbv7-linux-gnueabihf -fms-extensions 
-emit-llvm -o - | FileCheck -check-prefix ELF %s --implicit-check-not 
llvm.linker.options
 // RUN: %clang_cc1 %s -triple i686-pc-linux -fms-extensions -emit-llvm -o - | 
FileCheck -check-prefix ELF %s --implicit-check-not llvm.linker.options
 // RUN: %clang_cc1 %s -triple x86_64-scei-ps4 -fms-extensions -emit-llvm -o - 
| FileCheck -check-prefix ELF %s --implicit-check-not llvm.linker.options
+// RUN: %clang_cc1 %s -triple x86_64-sie-ps5 -fms-extensions -emit-llvm -o - | 
FileCheck -check-prefix ELF %s --implicit-check-not llvm.linker.options
 // RUN: %clang_cc1 %s -triple aarch64-windows-msvc -fms-extensions -emit-llvm 
-o - | FileCheck %s
 
 #pragma comment(lib, "msvcrt.lib")

diff  --git a/clang/test/Preprocessor/pragma_ps4.c 
b/clang/test/Preprocessor/pragma-comment-elf.c
similarity index 79%
rename from clang/test/Preprocessor/pragma_ps4.c
rename to clang/test/Preprocessor/pragma-comment-elf.c
index 63651b6a96fb1..7b84aba51a0da 100644
--- a/clang/test/Preprocessor/pragma_ps4.c
+++ b/clang/test/Preprocessor/pragma-comment-elf.c
@@ -1,6 +1,8 @@
-// RUN: %clang_cc1 %s -triple x86_64-scei-ps4 -fsyntax-only -verify 
-fms-extensions 
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions -triple 
x86_64-scei-ps4
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions -triple 
x86_64-sie-ps5
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions -triple 
i686-unknown-linux-gnu
 
-// On PS4, issue a diagnostic that pragma comments are ignored except:
+// On ELF targets, issue a diagnostic that pragma comments are ignored except:
 //   #pragma comment lib
 
 #pragma comment(lib)

diff  --git a/clang/test/Preprocessor/pragma-comment-linux.c 
b/clang/test/Preprocessor/pragma-comment-linux.c
deleted file mode 100644
index fcac049f46e83..0
--- a/clang/test/Preprocessor/pragma-comment-linux.c
+++ /dev/null
@@ -1,5 +0,0 @@
-// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fsyntax-only -verify %s 
-Wunknown-pragmas
-
-#pragma comment(linker, "")
-// expected-warning@-1 {{'#pragma comment linker' ignored}}
-



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


[PATCH] D126803: [llvm][analyzer][NFC] Introduce SFINAE for specializing FoldingSetTraits

2022-06-02 Thread Aman LaChapelle via Phabricator via cfe-commits
bzcheeseman added inline comments.



Comment at: llvm/include/llvm/ADT/FoldingSet.h:260
 /// to FoldingSets that were not originally designed to have that behavior.
-template struct FoldingSetTrait
-  : public DefaultFoldingSetTrait {};
+template 
+struct FoldingSetTrait : public DefaultFoldingSetTrait {};

supernit: I generally prefer named template parameters - can call it something 
like `Enable`?



Comment at: llvm/include/llvm/ADT/FoldingSet.h:834
+struct FoldingSetTrait<
+T, typename std::enable_if_t::value, void>> {
+  static void Profile(const T &X, FoldingSetNodeID &ID) {

supernit - the default type of std::enable_if_t is `void` so you don't need to 
specify it :)


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

https://reviews.llvm.org/D126803

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


[PATCH] D126880: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

2022-06-02 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 433757.
carlosgalvezp added a comment.

Move logic from check to registerMatchers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126880

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-const-or-ref-data-members.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
@@ -0,0 +1,121 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-const-or-ref-data-members %t
+namespace std {
+template 
+struct reference_wrapper {};
+} // namespace std
+
+namespace gsl {
+template 
+struct not_null {};
+} // namespace gsl
+
+struct Ok {
+  int i;
+  int *p;
+  const int *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember {
+  const int c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
+};
+
+struct RefMember {
+  int &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+};
+
+struct RefRefMember {
+  int &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstRefMember {
+  const int &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'r' is a reference
+};
+
+struct ConstAndRefMember {
+  int const c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  int &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+  int &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct Foo {};
+
+struct Ok2 {
+  Foo i;
+  Foo *p;
+  const Foo *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
+};
+
+struct RefMember2 {
+  Foo &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+};
+
+struct RefRefMember2 {
+  Foo &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstRefMember2 {
+  const Foo &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'r' is a reference
+};
+
+struct ConstAndRefMember2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  Foo &r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'r' is a reference
+  Foo &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+using ConstType = const int;
+using RefType = int &;
+using RefRefType = int &&;
+
+struct WithAlias {
+  ConstType c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  RefType r;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: member 'r' is a reference
+  RefRefType rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'rr' is a reference
+};
+
+template 
+struct TemplatedConst {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is const qualified
+};
+
+template 
+struct TemplatedRef {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is a reference
+};
+
+template 
+struct TemplatedOk {
+  T t;
+};
+
+TemplatedConst t1{123};
+TemplatedRef t2{123};
+TemplatedRef t3{123};
+TemplatedOk t4{};
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -151,6 +151,7 @@
`clang-analyzer-valist.Unterminated `_,
`concurrency-mt-unsafe `_,
`concurrency-thread-canceltype-asynchronous `_,
+   `cppcoreguidelines-avoid-const-or-ref-data-members `_,
`cppcoreguidelines-avoid-goto `_,
`cppcoreguidelines-avoid-non-const-global-variables `_,
`cppcoreguidelines-init-variables `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-const-or-ref-data-members.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-const-or-ref-data-members.rst
@@ -0,0 +1,48 @@
+.. title:: clang-tidy - cppcoreguidelines

[PATCH] D126689: [IR] Enable opaque pointers by default

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

I believe https://reviews.llvm.org/D126886 should fix the DAGCombiner issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126689

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


[PATCH] D125373: [pp-trace] Print HashLoc in InclusionDirective callback

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

LGTM!

Do you need me to commit on your behalf? If so, what name and email address 
would you like me to use for patch attribution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125373

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


[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

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

In D126796#3551996 , @cjdb wrote:

> In D126796#3551834 , @tschuett 
> wrote:
>
>> In D126796#3551781 , @cjdb wrote:
>>
>>> In D126796#3551312 , @tschuett 
>>> wrote:
>>>
 Would a JSON dump help you for your tools?
>>>
>>> Do you think a JSON dump would be more appropriate? I was just going for 
>>> something not unlike `--help` here.
>>
>> I thought that you need this for your diagnostics campaign.
>
> Ah, gotcha. The idea for this feature came about while @aaron.ballman was 
> reviewing a draft of that RFC, but it's orthogonal to that. I can't 
> immediately see how users would benefit from this outputting JSON, but open 
> to ideas.

+1 -- I think JSON output would be a better feature for `diagtool`. My goal 
with proposing the idea @cjdb has graciously worked on is to make warnings more 
discoverable for users in Clang itself, so I don't think JSON output helps 
there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126796

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


[PATCH] D126084: [Sema] Reject list-initialization of a scoped enum variable from an element of a different scoped enum type

2022-06-02 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! Can you also add a release note about the fix before landing the changes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126084

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


[PATCH] D126888: Add a parameter to LoadFromASTFile that accepts a file system and defaults to the real file-system.

2022-06-02 Thread Andy Soffer via Phabricator via cfe-commits
asoffer created this revision.
asoffer added a reviewer: ymandel.
Herald added a project: All.
asoffer 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/D126888

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


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -759,7 +759,8 @@
 WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
 const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
 bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
-bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
+bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile,
+IntrusiveRefCntPtr VFS) {
   std::unique_ptr AST(new ASTUnit(true));
 
   // Recover resources if we crash before exiting this method.
@@ -775,8 +776,6 @@
   AST->OnlyLocalDecls = OnlyLocalDecls;
   AST->CaptureDiagnostics = CaptureDiagnostics;
   AST->Diagnostics = Diags;
-  IntrusiveRefCntPtr VFS =
-  llvm::vfs::getRealFileSystem();
   AST->FileMgr = new FileManager(FileSystemOpts, VFS);
   AST->UserFilesAreVolatile = UserFilesAreVolatile;
   AST->SourceMgr = new SourceManager(AST->getDiagnostics(),
Index: clang/include/clang/Frontend/ASTUnit.h
===
--- clang/include/clang/Frontend/ASTUnit.h
+++ clang/include/clang/Frontend/ASTUnit.h
@@ -696,7 +696,9 @@
   bool UseDebugInfo = false, bool OnlyLocalDecls = false,
   CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
   bool AllowASTWithCompilerErrors = false,
-  bool UserFilesAreVolatile = false);
+  bool UserFilesAreVolatile = false,
+  IntrusiveRefCntPtr VFS =
+  llvm::vfs::getRealFileSystem());
 
 private:
   /// Helper function for \c LoadFromCompilerInvocation() and


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -759,7 +759,8 @@
 WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
 const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
 bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
-bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
+bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile,
+IntrusiveRefCntPtr VFS) {
   std::unique_ptr AST(new ASTUnit(true));
 
   // Recover resources if we crash before exiting this method.
@@ -775,8 +776,6 @@
   AST->OnlyLocalDecls = OnlyLocalDecls;
   AST->CaptureDiagnostics = CaptureDiagnostics;
   AST->Diagnostics = Diags;
-  IntrusiveRefCntPtr VFS =
-  llvm::vfs::getRealFileSystem();
   AST->FileMgr = new FileManager(FileSystemOpts, VFS);
   AST->UserFilesAreVolatile = UserFilesAreVolatile;
   AST->SourceMgr = new SourceManager(AST->getDiagnostics(),
Index: clang/include/clang/Frontend/ASTUnit.h
===
--- clang/include/clang/Frontend/ASTUnit.h
+++ clang/include/clang/Frontend/ASTUnit.h
@@ -696,7 +696,9 @@
   bool UseDebugInfo = false, bool OnlyLocalDecls = false,
   CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
   bool AllowASTWithCompilerErrors = false,
-  bool UserFilesAreVolatile = false);
+  bool UserFilesAreVolatile = false,
+  IntrusiveRefCntPtr VFS =
+  llvm::vfs::getRealFileSystem());
 
 private:
   /// Helper function for \c LoadFromCompilerInvocation() and
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126832: [clang][tablegen] adds human documentation to `WarningOption`

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

Can you post some examples of the output from this option so we can see what 
the end results look like more easily?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126832

___
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-02 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

In D126291#3552573 , @rovka 
wrote://italic text//

> I don't really know why `link.exe` doesn't work. According to the docs 
> ,
>  it should find `main` and choose the subsystem on its own. The only hunch I 
> have is that maybe it doesn't work because `main` is in a library as opposed 
> to one of the object files, but I'm still going through the docs trying to 
> figure this out. I don't have a lot of experience with `link.exe` so I might 
> be missing something obvious.

It does work when passing `/SUBSYSTEM:CONSOLE` explicitly. Indeed maybe the 
autoselect only looks into symbols found in object file. Maybe pass 
`/SUBSYSTEM:CONSOLE` as well to the linker command? `llvm-link` should accept 
it as well. AFAIU there is no other subsystem Flang supports anyway. Even if, 
it requires changes to `Fortran_main.lib`.


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] D102122: Support warn_unused_result on typedefs

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

LGTM!




Comment at: clang/include/clang/Basic/Attr.td:2945
C2x<"", "nodiscard", 201904>,
CXX11<"clang", "warn_unused_result">,
GCC<"warn_unused_result">];

dblaikie wrote:
> aaron.ballman wrote:
> > Oops, it looks like we support this spelling in C++ but not in C (not your 
> > bug, just an observation): https://godbolt.org/z/1hPq6coba
> Oh, so we'd have to put `C2x<"clang", "warn_unused_result">` in here? Fair 
> enough, yeah, separate issue.
Yeah, I can take care of that one pretty quickly once your changes land (so we 
don't step on each other's toes). Or if you want to tackle it, I'm fine with 
that as well.



Comment at: clang/lib/AST/Expr.cpp:1525-1527
+  if (const auto *TD = getCallReturnType(Ctx)->getAs())
+if (const auto *A = TD->getDecl()->getAttr())
+  return A;

dblaikie wrote:
> aaron.ballman wrote:
> > rsmith wrote:
> > > This should loop over `TypedefType` sugar; the attribute could be in a 
> > > nested typedef.
> > I agree with Richard here. I think this is needed for a case like:
> > ```
> > typedef int foo __attribute__((warn_unused_result));
> > typedef foo foob;
> > 
> > foob func();
> > 
> > int main() {
> >   func(); // Still want to be barked at here
> > }
> > ```
> > But this example brings up an interesting question of expectations. What's 
> > your intuition on how this should behave?
> > ```
> > typedef int foo __attribute__((warn_unused_result));
> > typedef foo *foo_ptr;
> > 
> > foo_ptr func();
> > 
> > int main() {
> >   func(); // Bark? Silence? Other?
> > }
> > ```
> > FWIW, my initial inclination was that this would diagnose the call to 
> > `func()` but now I'm second-guessing that, hence the question about type 
> > composition in a typedef.
> > I agree with Richard here. I think this is needed for a case like:
> > ```
> > typedef int foo __attribute__((warn_unused_result));
> > typedef foo foob;
> > 
> > foob func();
> > 
> > int main() {
> >  func(); // Still want to be barked at here
> > }
> > ```
> 
> Oh, sorry, I marked this as "done" because I'd done this - but hadn't updated 
> the patch. Should be updated now, including a test case 
> (warn-unused-result.cpp:unused_typedef_result::indirect).
> 
> > But this example brings up an interesting question of expectations. What's 
> > your intuition on how this should behave?
> > ```
> > typedef int foo __attribute__((warn_unused_result));
> > typedef foo *foo_ptr;
> > 
> > foo_ptr func();
> > 
> > int main() {
> >   func(); // Bark? Silence? Other?
> > }
> > ```
> > FWIW, my initial inclination was that this would diagnose the call to 
> > func() but now I'm second-guessing that, hence the question about type 
> > composition in a typedef.
> 
> Yeah, I'm OK with/think that probably shouldn't warn - like instantiating a 
> template with a warn_unused_result doesn't/shouldn't designate that template 
> specialization as warn_unused_result - it's a related/derived type, but 
> doesn't necessarily have the same properties (I guess another example in that 
> direction: a function pointer, where one of the parameters/result type are 
> warn_unused_result doesn't make the function pointer type itself 
> warn_unused_result).
> Yeah, I'm OK with/think that probably shouldn't warn - like instantiating a 
> template with a warn_unused_result doesn't/shouldn't designate that template 
> specialization as warn_unused_result - it's a related/derived type, but 
> doesn't necessarily have the same properties (I guess another example in that 
> direction: a function pointer, where one of the parameters/result type are 
> warn_unused_result doesn't make the function pointer type itself 
> warn_unused_result).

SGTM, thanks for thinking it through with me!



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:3159
 
+  if ((!AL.isGNUAttribute() && !(AL.isStandardAttributeSyntax() && 
AL.isClangScope())) && isa(D)) {
+S.Diag(AL.getLoc(), diag::warn_unused_result_typedef_unsupported_spelling) 
<< AL.isGNUScope();

This looks like it goes over the usual 80-col limit, so you should probably 
format this when landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102122

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


[PATCH] D116593: Fix `performance-unnecessary-value-param` for template specialization

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



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:205-208
+- Fixed a crash in :doc:`performance-unnecessary-value-param
+  ` when the 
specialization
+  template has an unnecessary value paramter. Removed the fix for a template.
+

This is not at the expected alphabetical place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116593

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


[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

2022-06-02 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D126796#3551288 , @aaron.ballman 
wrote:

> In D126796#3551280 , @MaskRay wrote:
>
>> In D126796#3551261 , @cjdb wrote:
>>
>>> In D126796#3550848 , @MaskRay 
>>> wrote:
>>>
 FYI `diagtool tree` dumps the diagnostics. You can even provide -W options 
 and observe the differences.
>>>
>>> Is `diagtool tree` something that users widely know about?
>>
>> I think no. But any random new option to clang will have the same 
>> discoverability problem.
>
> Yes, but I think there's a pretty wide discoverability gap between 
> "documented command line option that shows up in Clang" and "random utility 
> that doesn't have any obvious relationship to Clang specifically".

Agreed. I think a combination of Clang-next's release notes, plus this 
appearing in `--help` and web docs will be enough.

On discoverability, I'm thinking `--print-all-warning-options` might be a 
better name, since 'diagnostic' is a fairly technical term (and this is also 
not printing all diagnostics).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126796

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


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

2022-06-02 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: aaron.ballman, njames93, LegalizeAdulthood, 
whisperity.
Herald added subscribers: carlosgalvezp, martong, rnkovacs, kbarton, xazax.hun, 
nemanjai.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The `cppcoreguidelines-virtual-class-destructor` supposed to enforce
http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c35-a-base-class-destructor-should-be-either-public-and-virtual-or-protected-and-non-virtual

Quote:

> A **base** class destructor should be either public and virtual, or
> protected and non-virtual

[emphasis mine]

However, this check still rules the following case:

  class MostDerived final : public Base {
  public:
MostDerived() = default;
~MostDerived() = default;
void func() final;
  };

Even though `MostDerived` class is marked `final`, thus it should not be
considered as a **base** class. Consequently, the rule is satisfied, yet
the check still flags this code.

In this patch, I'm proposing to ignore `final` classes since they cannot
be //base// classes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126891

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


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
@@ -320,3 +320,22 @@
 #undef XMACRO
 #undef CONCAT
 } // namespace macro_tests
+
+namespace FinalClassCannotBeBaseClass {
+class Base {
+public:
+  Base() = default;
+  virtual void func() = 0;
+
+protected:
+  ~Base() = default;
+};
+
+// no-warning: 'MostDerived' cannot be a base class, since it's marked 'final'.
+class MostDerived final : public Base {
+public:
+  MostDerived() = default;
+  ~MostDerived() = default;
+  void func() final;
+};
+} // namespace FinalClassCannotBeBaseClass
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -165,6 +165,12 @@
   Fixed an issue when there was already an initializer in the constructor and
   the check would try to create another initializer for the same member.
 
+- Fixed a false positive in :doc:`cppcoreguidelines-virtual-class-destructor
+  ` involving
+  `final` classes. The check will not diagnose `final` marked classes, since
+  those cannot be used as base classes, consequently they can not violate the
+  rule.
+
 - Fixed a crash in :doc:`llvmlibc-callee-namespace
   ` when executing for C++ code
   that contain calls to advanced constructs, e.g. overloaded operators.
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
@@ -41,6 +41,7 @@
   Finder->addMatcher(
   cxxRecordDecl(
   anyOf(has(cxxMethodDecl(isVirtual())), InheritsVirtualMethod),
+  unless(isFinal()),
   unless(hasPublicVirtualOrProtectedNonVirtualDestructor()))
   .bind("ProblematicClassOrStruct"),
   this);


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
@@ -320,3 +320,22 @@
 #undef XMACRO
 #undef CONCAT
 } // namespace macro_tests
+
+namespace FinalClassCannotBeBaseClass {
+class Base {
+public:
+  Base() = default;
+  virtual void func() = 0;
+
+protected:
+  ~Base() = default;
+};
+
+// no-warning: 'MostDerived' cannot be a base class, since it's marked 'final'.
+class MostDerived final : public Base {
+public:
+  MostDerived() = default;
+  ~MostDerived() = default;
+  void func() final;
+};
+} // namespace FinalClassCannotBeBaseClass
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -165,6 +165,12 @@
   Fixed an issue when there was already an initializer in the constructor and
   the check would try to create another initializer for the same member.
 
+- Fixed a false positive 

[PATCH] D126158: [MLIR][GPU] Replace fdiv on fp16 with promoted (fp32) multiplication with reciprocal plus one (conditional) Newton iteration.

2022-06-02 Thread Christian Sigg via Phabricator via cfe-commits
csigg updated this revision to Diff 433772.
csigg added a comment.

Rename pass.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126158

Files:
  mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
  mlir/include/mlir/Dialect/LLVMIR/Transforms/OptimizeForNVVM.h
  mlir/include/mlir/Dialect/LLVMIR/Transforms/Passes.h
  mlir/include/mlir/Dialect/LLVMIR/Transforms/Passes.td
  mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt
  mlir/lib/Dialect/LLVMIR/Transforms/OptimizeForNVVM.cpp
  mlir/test/Dialect/LLVMIR/nvvm-optimize.mlir
  mlir/test/Dialect/LLVMIR/nvvm.mlir
  mlir/test/Target/LLVMIR/nvvmir.mlir
  utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -3379,7 +3379,9 @@
 ":IR",
 ":LLVMDialect",
 ":LLVMPassIncGen",
+":NVVMDialect",
 ":Pass",
+":Transforms",
 ],
 )
 
Index: mlir/test/Target/LLVMIR/nvvmir.mlir
===
--- mlir/test/Target/LLVMIR/nvvmir.mlir
+++ mlir/test/Target/LLVMIR/nvvmir.mlir
@@ -33,6 +33,13 @@
   llvm.return %1 : i32
 }
 
+// CHECK-LABEL: @nvvm_rcp
+llvm.func @nvvm_rcp(%0: f32) -> f32 {
+  // CHECK: call float @llvm.nvvm.rcp.approx.ftz.f
+  %1 = nvvm.rcp.approx.ftz.f %0 : f32
+  llvm.return %1 : f32
+}
+
 // CHECK-LABEL: @llvm_nvvm_barrier0
 llvm.func @llvm_nvvm_barrier0() {
   // CHECK: call void @llvm.nvvm.barrier0()
Index: mlir/test/Dialect/LLVMIR/nvvm.mlir
===
--- mlir/test/Dialect/LLVMIR/nvvm.mlir
+++ mlir/test/Dialect/LLVMIR/nvvm.mlir
@@ -29,6 +29,13 @@
   llvm.return %0 : i32
 }
 
+// CHECK-LABEL: @nvvm_rcp
+func.func @nvvm_rcp(%arg0: f32) -> f32 {
+  // CHECK: nvvm.rcp.approx.ftz.f %arg0 : f32
+  %0 = nvvm.rcp.approx.ftz.f %arg0 : f32
+  llvm.return %0 : f32
+}
+
 // CHECK-LABEL: @llvm_nvvm_barrier0
 func.func @llvm_nvvm_barrier0() {
   // CHECK: nvvm.barrier0
Index: mlir/test/Dialect/LLVMIR/nvvm-optimize.mlir
===
--- /dev/null
+++ mlir/test/Dialect/LLVMIR/nvvm-optimize.mlir
@@ -0,0 +1,24 @@
+// RUN: mlir-opt %s -llvm-optimize-for-nvvm-target | FileCheck %s
+
+// CHECK-LABEL: llvm.func @fdiv_fp16
+llvm.func @fdiv_fp16(%arg0 : f16, %arg1 : f16) -> f16 {
+  // CHECK-DAG: %[[c0:.*]]  = llvm.mlir.constant(0 : ui32) : i32
+  // CHECK-DAG: %[[mask:.*]]= llvm.mlir.constant(2139095040 : ui32) : i32
+  // CHECK-DAG: %[[lhs:.*]] = llvm.fpext %arg0 : f16 to f32
+  // CHECK-DAG: %[[rhs:.*]] = llvm.fpext %arg1 : f16 to f32
+  // CHECK-DAG: %[[rcp:.*]] = nvvm.rcp.approx.ftz.f %[[rhs]] : f32
+  // CHECK-DAG: %[[approx:.*]]  = llvm.fmul %[[lhs]], %[[rcp]] : f32
+  // CHECK-DAG: %[[neg:.*]] = llvm.fneg %[[rhs]] : f32
+  // CHECK-DAG: %[[err:.*]] = "llvm.intr.fma"(%[[approx]], %[[neg]], %[[lhs]]) : (f32, f32, f32) -> f32
+  // CHECK-DAG: %[[refined:.*]] = "llvm.intr.fma"(%[[err]], %[[rcp]], %[[approx]]) : (f32, f32, f32) -> f32
+  // CHECK-DAG: %[[cast:.*]]= llvm.bitcast %[[approx]] : f32 to i32
+  // CHECK-DAG: %[[exp:.*]] = llvm.and %[[cast]], %[[mask]] : i32
+  // CHECK-DAG: %[[is_zero:.*]] = llvm.icmp "eq" %[[exp]], %[[c0]] : i32
+  // CHECK-DAG: %[[is_mask:.*]] = llvm.icmp "eq" %[[exp]], %[[mask]] : i32
+  // CHECK-DAG: %[[pred:.*]]= llvm.or %[[is_zero]], %[[is_mask]] : i1
+  // CHECK-DAG: %[[select:.*]]  = llvm.select %[[pred]], %[[approx]], %[[refined]] : i1, f32
+  // CHECK-DAG: %[[result:.*]]  = llvm.fptrunc %[[select]] : f32 to f16
+  %result = llvm.fdiv %arg0, %arg1 : f16
+  // CHECK: llvm.return %[[result]] : f16
+  llvm.return %result : f16
+}
Index: mlir/lib/Dialect/LLVMIR/Transforms/OptimizeForNVVM.cpp
===
--- /dev/null
+++ mlir/lib/Dialect/LLVMIR/Transforms/OptimizeForNVVM.cpp
@@ -0,0 +1,100 @@
+//===- OptimizeNVVM.cpp - Optimize NVVM IR -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "PassDetail.h"
+#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
+#include "mlir/Dialect/LLVMIR/Transforms/OptimizeNVVM.h"
+#include "mlir/IR/Block.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
+
+using namespace mlir;
+
+namespace {
+// Replaces fdiv on fp16 with fp32 multiplication with reciprocal plus one
+// (conditional) Newton iteration.
+//
+// This as accurate as promoting the 

[PATCH] D126689: [IR] Enable opaque pointers by default

2022-06-02 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

It looks like this patch has broken 168 tests in LLDB: 
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/44239/changes#41d5033eb162cb92b684855166cabfa3983b74c6
I'm going to dig a little deeper, but I might ask you to revert this until we 
can figure out a solution.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126689

___
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-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D125723#3550956 , @steplong wrote:

> Appreciate the help! It's not clear to me how to go from the strings "Os", 
> "foo1", "foo2", "foo3" to adding "-Os -ffoo1 -ffoo2 -ffoo3" to the 
> compilation line for that function

I may be misunderstanding the issue here, but what I had envisioned was that 
the `OptimizeAttr` would take either a string or integer argument (I don't know 
how easy that will be to model in Attr.td, FWIW; it may require adding a new 
kind of `Argument` for attributes) and then add a "fake" `Argument` or use the 
`AdditionalMembers` field to add a member that stores the converted "value" of 
that string or integer in whatever form makes the most sense for the semantics 
(I was envisioning an enumeration for the various kinds of optimization 
options, but maybe that doesn't work for the -f arguments?). Then, when doing 
CodeGen, you can look at the function to see if it has an `OptimizeAttr`, and 
if it does, use the fake/additional member to determine what information to 
lower to IR (or not lower, as the case may be). Does that help get you unstuck 
somewhat?

Btw, one possibility would be to not support any -f flags initially and only 
support optimization levels, if that's easier. We can add support for 
individual flags at a later step but still get utility out of the attribute 
this way.


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


[PATCH] D126892: [NFC] Fix issue on CMake Xcode build configuration.

2022-06-02 Thread Xiang Li via Phabricator via cfe-commits
python3kgae created this revision.
python3kgae added a reviewer: rastogishubham.
Herald added subscribers: Anastasia, mgorny.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

add missing dependency for hlsl-resource-headers and clang-resource-headers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126892

Files:
  clang/lib/Headers/CMakeLists.txt


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -378,6 +378,7 @@
  "cuda-resource-headers"
  "hexagon-resource-headers"
  "hip-resource-headers"
+ "hlsl-resource-headers"
  "mips-resource-headers"
  "ppc-resource-headers"
  "ppc-htm-resource-headers"


Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -378,6 +378,7 @@
  "cuda-resource-headers"
  "hexagon-resource-headers"
  "hip-resource-headers"
+ "hlsl-resource-headers"
  "mips-resource-headers"
  "ppc-resource-headers"
  "ppc-htm-resource-headers"
___
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-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In D125723#3553664 , @aaron.ballman 
wrote:

> In D125723#3550956 , @steplong 
> wrote:
>
>> Appreciate the help! It's not clear to me how to go from the strings "Os", 
>> "foo1", "foo2", "foo3" to adding "-Os -ffoo1 -ffoo2 -ffoo3" to the 
>> compilation line for that function
>
> I may be misunderstanding the issue here, but what I had envisioned was that 
> the `OptimizeAttr` would take either a string or integer argument (I don't 
> know how easy that will be to model in Attr.td, FWIW; it may require adding a 
> new kind of `Argument` for attributes) and then add a "fake" `Argument` or 
> use the `AdditionalMembers` field to add a member that stores the converted 
> "value" of that string or integer in whatever form makes the most sense for 
> the semantics (I was envisioning an enumeration for the various kinds of 
> optimization options, but maybe that doesn't work for the -f arguments?). 
> Then, when doing CodeGen, you can look at the function to see if it has an 
> `OptimizeAttr`, and if it does, use the fake/additional member to determine 
> what information to lower to IR (or not lower, as the case may be). Does that 
> help get you unstuck somewhat?
>
> Btw, one possibility would be to not support any -f flags initially and only 
> support optimization levels, if that's easier. We can add support for 
> individual flags at a later step but still get utility out of the attribute 
> this way.

I would really like to limit the scope here to foreclose any future possibility 
of sending attribute strings through the command line parser. That would expose 
a big, general API surface, with lots of possibilities for confusing 
interactions with other features.

I think it will be cleaner to keep the attributes as close as possible to 
simple booleans, which then correspond relatively directly to the LLVM IR 
`optnone`, `optsize`, etc attributes.


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


[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

2022-06-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

If you still decide to add an option to clang, I think "diagnostics" is better 
than "warnings". There are many diagnostics which are errors by default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126796

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


[PATCH] D126602: [Clang][OpenMP] Replace IgnoreImpCasts with IgnoreImplicitAsWritten in atomic compare

2022-06-02 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

I will refine some logics to set `X`, `E`, etc. to avoid more `IgnoreImpCasts`. 
However, I don't know how to deal with type promotion in the condition 
statement. Here we consider the following case:

  if (x == e) { x = d; }

`x` and `d` can be set easily w/o need of `IgnoreImpCasts`. When it comes to 
`e`, things become complicated. There are basically three cases:

1. `x` and `e` are not promoted. That is the case when `x` and `e` are of same 
type, and they are both at least `int`. In this case, we don't need 
`IgnoreImpCasts` here. If they are of the same with shorter representation, 
such as `int16_t`, they will all be promoted, which will be mentioned later.
2. `x` is not promoted, but `e` is promoted. That is the case when `x` has 
higher ranking than `e`. In this case, we should not use `IgnoreImpCasts`.
3. Both `x` and `e` are promoted. This case is very common, and it can be 
further divided into following cases:
  - `x` and `e` of the same type with lower ranking. For example, when `x` and 
`e` are both `short`, they will be promoted to `int`. In this case, we want 
`IgnoreImpCasts`.
  - `x` and `e` are of different types, but they can be implicitly converted. 
For example, `x` is `int`, while `e` is `short`. In this case, we don't want 
`IgnoreImpCasts` because `e` is implicitly promoted to `int`, which is exactly 
what we want.

I'm thinking we may want to avoid using `IgnoreImpCasts` and later create cast 
if necessary. However, that may cause some unnecessary casts, at least in LLVM 
IR, such as the following case:

  %1 = load i8 *%e
  %2 = cast to i32 %1
  %3 = cast to i8 %2
  cmpxchg i8 * %x, i8 %3

I'm not sure eventually `%2` and `%3` will be optimized out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126602

___
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-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D125723#3553705 , @rnk wrote:

> In D125723#3553664 , @aaron.ballman 
> wrote:
>
>> In D125723#3550956 , @steplong 
>> wrote:
>>
>>> Appreciate the help! It's not clear to me how to go from the strings "Os", 
>>> "foo1", "foo2", "foo3" to adding "-Os -ffoo1 -ffoo2 -ffoo3" to the 
>>> compilation line for that function
>>
>> I may be misunderstanding the issue here, but what I had envisioned was that 
>> the `OptimizeAttr` would take either a string or integer argument (I don't 
>> know how easy that will be to model in Attr.td, FWIW; it may require adding 
>> a new kind of `Argument` for attributes) and then add a "fake" `Argument` or 
>> use the `AdditionalMembers` field to add a member that stores the converted 
>> "value" of that string or integer in whatever form makes the most sense for 
>> the semantics (I was envisioning an enumeration for the various kinds of 
>> optimization options, but maybe that doesn't work for the -f arguments?). 
>> Then, when doing CodeGen, you can look at the function to see if it has an 
>> `OptimizeAttr`, and if it does, use the fake/additional member to determine 
>> what information to lower to IR (or not lower, as the case may be). Does 
>> that help get you unstuck somewhat?
>>
>> Btw, one possibility would be to not support any -f flags initially and only 
>> support optimization levels, if that's easier. We can add support for 
>> individual flags at a later step but still get utility out of the attribute 
>> this way.
>
> I would really like to limit the scope here to foreclose any future 
> possibility of sending attribute strings through the command line parser. 
> That would expose a big, general API surface, with lots of possibilities for 
> confusing interactions with other features.

Agreed.

> I think it will be cleaner to keep the attributes as close as possible to 
> simple booleans, which then correspond relatively directly to the LLVM IR 
> `optnone`, `optsize`, etc attributes.

Also agreed. One thing I was double-checking and am 99% sure of is that we 
basically can't support those -f options in Clang anyway and so we likely just 
want to eat them (silently so we don't cause issues when cross compiling with 
GCC?). Clang does not have a mapping between -O flags and -f flags in the same 
way that GCC does. Also, it's not clear to me that there's always a way to 
specify the -f flag effects for only a single function. Given that GCC 
documents the `optimize` attribute as "The optimize attribute should be used 
for debugging purposes only. It is not suitable in production code.", I think 
it's reasonable just to punt on -f flags entirely.


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   >