[clang] [AMDGPU] Make default AMDHSA Code Object Version to be 5 (PR #65410)

2023-09-10 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm approved this pull request.


https://github.com/llvm/llvm-project/pull/65410
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141757: [clangd] allow extracting to variable for lambda expressions

2023-09-10 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.

I'm fine with allowing partial selection for consistency with other expressions.

I think this patch is in a good state. Thanks for your patience with the review 
:) Let me know if you need me to commit it for you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141757

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


[clang-tools-extra] cbd6ac6 - [clangd] Show parameter hints for operator()

2023-09-10 Thread Younan Zhang via cfe-commits

Author: Younan Zhang
Date: 2023-09-10T15:56:00+08:00
New Revision: cbd6ac6165e683f2eed4a5066c1ccf53bed0696d

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

LOG: [clangd] Show parameter hints for operator()

Closes https://github.com/clangd/clangd/issues/1742

Reviewed By: nridge

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

Added: 


Modified: 
clang-tools-extra/clangd/InlayHints.cpp
clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 56f85ee155cb236..e6e5e11b889bff8 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -586,11 +586,13 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 if (!Cfg.InlayHints.Parameters)
   return true;
 
-// Do not show parameter hints for operator calls written using operator
-// syntax or user-defined literals. (Among other reasons, the resulting
+bool IsFunctor = isFunctionObjectCallExpr(E);
+// Do not show parameter hints for user-defined literals or
+// operator calls except for operator(). (Among other reasons, the 
resulting
 // hints can look awkward, e.g. the expression can itself be a function
 // argument and then we'd get two hints side by side).
-if (isa(E) || isa(E))
+if ((isa(E) && !IsFunctor) ||
+isa(E))
   return true;
 
 auto CalleeDecls = Resolver->resolveCalleeOfCallExpr(E);
@@ -607,7 +609,22 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 else
   return true;
 
-processCall(Callee, {E->getArgs(), E->getNumArgs()});
+// N4868 [over.call.object]p3 says,
+// The argument list submitted to overload resolution consists of the
+// argument expressions present in the function call syntax preceded by the
+// implied object argument (E).
+//
+// However, we don't have the implied object argument for static
+// operator() per clang::Sema::BuildCallToObjectOfClassType.
+llvm::ArrayRef Args = {E->getArgs(), E->getNumArgs()};
+if (IsFunctor)
+  // We don't have the implied object argument through
+  // a function pointer either.
+  if (const CXXMethodDecl *Method =
+  dyn_cast_or_null(Callee.Decl);
+  Method && Method->isInstance())
+Args = Args.drop_front(1);
+processCall(Callee, Args);
 return true;
   }
 
@@ -1203,6 +1220,12 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 return Range{HintStart, HintEnd};
   }
 
+  static bool isFunctionObjectCallExpr(CallExpr *E) noexcept {
+if (auto *CallExpr = dyn_cast(E))
+  return CallExpr->getOperator() == OverloadedOperatorKind::OO_Call;
+return false;
+  }
+
   std::vector &Results;
   ASTContext *
   const syntax::TokenBuffer &Tokens;

diff  --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 1d12db3661c9ebb..a8c3546eb80cc85 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -89,7 +89,7 @@ void assertHintsWithHeader(InlayHintKind Kind, 
llvm::StringRef AnnotatedSource,
ExpectedHints... Expected) {
   Annotations Source(AnnotatedSource);
   TestTU TU = TestTU::withCode(Source.code());
-  TU.ExtraArgs.push_back("-std=c++20");
+  TU.ExtraArgs.push_back("-std=c++23");
   TU.HeaderCode = HeaderContent;
   auto AST = TU.build();
 
@@ -807,6 +807,42 @@ TEST(ParameterHints, Operator) {
   )cpp");
 }
 
+TEST(ParameterHints, FunctionCallOperator) {
+  assertParameterHints(R"cpp(
+struct W {
+  void operator()(int x);
+};
+struct S : W {
+  using W::operator();
+  static void operator()(int x, int y);
+};
+void bar() {
+  auto l1 = [](int x) {};
+  auto l2 = [](int x) static {};
+
+  S s;
+  s($1[[1]]);
+  s.operator()($2[[1]]);
+  s.operator()($3[[1]], $4[[2]]);
+  S::operator()($5[[1]], $6[[2]]);
+
+  l1($7[[1]]);
+  l1.operator()($8[[1]]);
+  l2($9[[1]]);
+  l2.operator()($10[[1]]);
+
+  void (*ptr)(int a, int b) = &S::operator();
+  ptr($11[[1]], $12[[2]]);
+}
+  )cpp",
+   ExpectedHint{"x: ", "1"}, ExpectedHint{"x: ", "2"},
+   ExpectedHint{"x: ", "3"}, ExpectedHint{"y: ", "4"},
+   ExpectedHint{"x: ", "5"}, ExpectedHint{"y: ", "6"},
+   ExpectedHint{"x: ", "7"}, ExpectedHint{"x: ", "8"},
+   ExpectedHint{"x: ", "9"}, ExpectedHint{"x: ", "10"},
+   ExpectedHint{"a: ", "11"}, ExpectedHint{"b: ", "12"});
+}
+
 TEST(ParameterHints, Macros

[PATCH] D158926: [clangd] Show parameter hints for operator()

2023-09-10 Thread Younan Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcbd6ac6165e6: [clangd] Show parameter hints for operator() 
(authored by zyounan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158926

Files:
  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
@@ -89,7 +89,7 @@
ExpectedHints... Expected) {
   Annotations Source(AnnotatedSource);
   TestTU TU = TestTU::withCode(Source.code());
-  TU.ExtraArgs.push_back("-std=c++20");
+  TU.ExtraArgs.push_back("-std=c++23");
   TU.HeaderCode = HeaderContent;
   auto AST = TU.build();
 
@@ -807,6 +807,42 @@
   )cpp");
 }
 
+TEST(ParameterHints, FunctionCallOperator) {
+  assertParameterHints(R"cpp(
+struct W {
+  void operator()(int x);
+};
+struct S : W {
+  using W::operator();
+  static void operator()(int x, int y);
+};
+void bar() {
+  auto l1 = [](int x) {};
+  auto l2 = [](int x) static {};
+
+  S s;
+  s($1[[1]]);
+  s.operator()($2[[1]]);
+  s.operator()($3[[1]], $4[[2]]);
+  S::operator()($5[[1]], $6[[2]]);
+
+  l1($7[[1]]);
+  l1.operator()($8[[1]]);
+  l2($9[[1]]);
+  l2.operator()($10[[1]]);
+
+  void (*ptr)(int a, int b) = &S::operator();
+  ptr($11[[1]], $12[[2]]);
+}
+  )cpp",
+   ExpectedHint{"x: ", "1"}, ExpectedHint{"x: ", "2"},
+   ExpectedHint{"x: ", "3"}, ExpectedHint{"y: ", "4"},
+   ExpectedHint{"x: ", "5"}, ExpectedHint{"y: ", "6"},
+   ExpectedHint{"x: ", "7"}, ExpectedHint{"x: ", "8"},
+   ExpectedHint{"x: ", "9"}, ExpectedHint{"x: ", "10"},
+   ExpectedHint{"a: ", "11"}, ExpectedHint{"b: ", "12"});
+}
+
 TEST(ParameterHints, Macros) {
   // Handling of macros depends on where the call's argument list comes from.
 
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -586,11 +586,13 @@
 if (!Cfg.InlayHints.Parameters)
   return true;
 
-// Do not show parameter hints for operator calls written using operator
-// syntax or user-defined literals. (Among other reasons, the resulting
+bool IsFunctor = isFunctionObjectCallExpr(E);
+// Do not show parameter hints for user-defined literals or
+// operator calls except for operator(). (Among other reasons, the resulting
 // hints can look awkward, e.g. the expression can itself be a function
 // argument and then we'd get two hints side by side).
-if (isa(E) || isa(E))
+if ((isa(E) && !IsFunctor) ||
+isa(E))
   return true;
 
 auto CalleeDecls = Resolver->resolveCalleeOfCallExpr(E);
@@ -607,7 +609,22 @@
 else
   return true;
 
-processCall(Callee, {E->getArgs(), E->getNumArgs()});
+// N4868 [over.call.object]p3 says,
+// The argument list submitted to overload resolution consists of the
+// argument expressions present in the function call syntax preceded by the
+// implied object argument (E).
+//
+// However, we don't have the implied object argument for static
+// operator() per clang::Sema::BuildCallToObjectOfClassType.
+llvm::ArrayRef Args = {E->getArgs(), E->getNumArgs()};
+if (IsFunctor)
+  // We don't have the implied object argument through
+  // a function pointer either.
+  if (const CXXMethodDecl *Method =
+  dyn_cast_or_null(Callee.Decl);
+  Method && Method->isInstance())
+Args = Args.drop_front(1);
+processCall(Callee, Args);
 return true;
   }
 
@@ -1203,6 +1220,12 @@
 return Range{HintStart, HintEnd};
   }
 
+  static bool isFunctionObjectCallExpr(CallExpr *E) noexcept {
+if (auto *CallExpr = dyn_cast(E))
+  return CallExpr->getOperator() == OverloadedOperatorKind::OO_Call;
+return false;
+  }
+
   std::vector &Results;
   ASTContext *
   const syntax::TokenBuffer &Tokens;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Replace usage of -Bshareable linker flag with -shared (PR #65842)

2023-09-10 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/65842
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Forward --target to system include extraction (PR #65824)

2023-09-10 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 requested changes to this pull request.

Thanks for the patch!

There is some prior work on this which I've looked over and will summarize:

 * This change was previously proposed in 
[D138546](https://reviews.llvm.org/D138546)
 * During its review, we discovered that clangd would run a processing step on 
the compile command that sometimes _adds_ a `-target` flag, inferred from the 
compiler name, to the command, _before_ running `SystemIncludeExtractor`, and 
propagating `-target` to the extraction command then caused an error if the 
compiler was a gcc (since gcc does not support `-target`).
   * The patch was updated to fix this (by moving that processing step to 
happen _after_ `SystemIncludeExtractor`). That change was since independently 
made and merged in [D143436](https://reviews.llvm.org/D143436).
 * We also discovered that `SystemIncludeExtractor` was failing to include 
arguments like `--sysroot` in the key under which it caches its results.
   * That has since been fixed in [D146941](https://reviews.llvm.org/D146941).

Activity on [D138546](https://reviews.llvm.org/D138546) has since stalled, but 
the next step would have been to rebase it on top of 
[D143436](https://reviews.llvm.org/D143436) and 
[D146941](https://reviews.llvm.org/D146941)... which is basically what this 
patch does!

So, I think this patch should be good to go (modulo a small bug I commented on 
inline).

cc @cpsauer (author of [D138546](https://reviews.llvm.org/D138546)) as an FYI

https://github.com/llvm/llvm-project/pull/65824
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Forward --target to system include extraction (PR #65824)

2023-09-10 Thread Nathan Ridge via cfe-commits


@@ -87,12 +87,13 @@ struct DriverArgs {
   std::string Lang;
   std::string Sysroot;
   std::string ISysroot;
+  std::string Target;
 
   bool operator==(const DriverArgs &RHS) const {
 return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
-Sysroot, ISysroot) ==
+Sysroot, ISysroot, Target) ==
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
-RHS.Lang, RHS.Sysroot, ISysroot);
+RHS.Lang, RHS.Sysroot, ISysroot, Target);

HighCommander4 wrote:

This should be `RHS.Target` (and there is a pre-existing bug here, the previous 
argument should be `RHS.ISysroot`, might as well fix that while we're at it)

https://github.com/llvm/llvm-project/pull/65824
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Forward --target to system include extraction (PR #65824)

2023-09-10 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 edited 
https://github.com/llvm/llvm-project/pull/65824
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Forward --target to system include extraction (PR #65824)

2023-09-10 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 edited 
https://github.com/llvm/llvm-project/pull/65824
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Forward --target to system include extraction (PR #65824)

2023-09-10 Thread Matthew Mirvish via cfe-commits

https://github.com/mincrmatt12 updated 
https://github.com/llvm/llvm-project/pull/65824:

>From e5f74b064b303a53b267caa12738af381c17c65f Mon Sep 17 00:00:00 2001
From: Matthew Mirvish 
Date: Fri, 8 Sep 2023 19:59:58 -0400
Subject: [PATCH] [clangd] Forward --target to system include extraction

Some clang multilib configurations (such as the one currently used in
the beta ARM LLVM toolchain) wind up only reporting the C++ include paths
properly if they get passed the correct target.
---
 clang-tools-extra/clangd/SystemIncludeExtractor.cpp  | 12 ++--
 .../clangd/test/system-include-extractor.test|  5 +++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index ac99b220f6bd3f0..88df5b04ccb09f3 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -87,12 +87,13 @@ struct DriverArgs {
   std::string Lang;
   std::string Sysroot;
   std::string ISysroot;
+  std::string Target;
 
   bool operator==(const DriverArgs &RHS) const {
 return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
-Sysroot, ISysroot) ==
+Sysroot, ISysroot, Target) ==
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
-RHS.Lang, RHS.Sysroot, ISysroot);
+RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target);
   }
 
   DriverArgs(const tooling::CompileCommand &Cmd, llvm::StringRef File) {
@@ -130,6 +131,11 @@ struct DriverArgs {
   ISysroot = Cmd.CommandLine[I + 1];
 else
   ISysroot = Arg.str();
+  } else if (Arg.consume_front("--target=")) {
+Target = Arg.str();
+  } else if (Arg.consume_front("-target")) {
+if (Arg.empty() && I + 1 < E)
+  Target = Cmd.CommandLine[I + 1];
   }
 }
 
@@ -167,6 +173,8 @@ struct DriverArgs {
   Args.append({"--sysroot", Sysroot});
 if (!ISysroot.empty())
   Args.append({"-isysroot", ISysroot});
+if (!Target.empty())
+  Args.append({"-target", Target});
 return Args;
   }
 
diff --git a/clang-tools-extra/clangd/test/system-include-extractor.test 
b/clang-tools-extra/clangd/test/system-include-extractor.test
index 2a2c900316a9161..66882e424bb9216 100644
--- a/clang-tools-extra/clangd/test/system-include-extractor.test
+++ b/clang-tools-extra/clangd/test/system-include-extractor.test
@@ -17,6 +17,7 @@
 # RUN: echo '[ -z "${args##*"-nostdinc"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"--sysroot /my/sysroot/path"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"-isysroot /isysroot"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"-target arm-linux-gnueabihf"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
@@ -36,7 +37,7 @@
 
 # Generate a compile_commands.json that will query the mock driver we've
 # created. Which should add a.h and b.h into include search path.
-# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp 
-nostdinc --sysroot /my/sysroot/path -isysroot/isysroot", "file": 
"the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp 
--target=arm-linux-gnueabihf -nostdinc --sysroot /my/sysroot/path 
-isysroot/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
 
 # RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
 # On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
@@ -74,7 +75,7 @@
 {"jsonrpc":"2.0","method":"exit"}
 
 # Generate a different compile_commands.json which does not point to the mock 
driver
-# RUN: echo '[{"directory": "%/t.dir", "command": "gcc the-file.cpp -nostdinc 
--sysroot /my/sysroot/path -isysroot/isysroot", "file": "the-file.cpp"}]' > 
%t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir", "command": "gcc the-file.cpp 
--target=arm-linux-gnueabihf -nostdinc --sysroot /my/sysroot/path 
-isysroot/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
 
 # Generate a clangd config file which points to the mock driver instead
 # RUN: echo 'CompileFlags:' > %t.dir/.clangd

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


[clang-tools-extra] [clangd] Forward --target to system include extraction (PR #65824)

2023-09-10 Thread Matthew Mirvish via cfe-commits


@@ -87,12 +87,13 @@ struct DriverArgs {
   std::string Lang;
   std::string Sysroot;
   std::string ISysroot;
+  std::string Target;
 
   bool operator==(const DriverArgs &RHS) const {
 return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
-Sysroot, ISysroot) ==
+Sysroot, ISysroot, Target) ==
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
-RHS.Lang, RHS.Sysroot, ISysroot);
+RHS.Lang, RHS.Sysroot, ISysroot, Target);

mincrmatt12 wrote:

Fixed in latest revision (both for `Target` and the existing bug)

https://github.com/llvm/llvm-project/pull/65824
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Forward --target to system include extraction (PR #65824)

2023-09-10 Thread Matthew Mirvish via cfe-commits

https://github.com/mincrmatt12 resolved 
https://github.com/llvm/llvm-project/pull/65824
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 18b6e21 - [Driver] Replace usage of -Bshareable linker flag with -shared (#65842)

2023-09-10 Thread via cfe-commits

Author: Brad Smith
Date: 2023-09-10T04:35:58-04:00
New Revision: 18b6e2139ff8520bb33c3057ae6794a4cf6822e9

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

LOG: [Driver] Replace usage of -Bshareable linker flag with -shared (#65842)

The two flags mean the same thing for the bfd / lld linkers so just use
the same flag consistently everywhere.

Added: 


Modified: 
clang/lib/Driver/ToolChains/DragonFly.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/NetBSD.cpp
clang/test/Driver/freebsd.c
clang/test/Driver/netbsd.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 6f46864105e9c0c..900be9e305c902a 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -69,7 +69,7 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 if (Args.hasArg(options::OPT_rdynamic))
   CmdArgs.push_back("-export-dynamic");
 if (Args.hasArg(options::OPT_shared))
-  CmdArgs.push_back("-Bshareable");
+  CmdArgs.push_back("-shared");
 else if (!Args.hasArg(options::OPT_r)) {
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/usr/libexec/ld-elf.so.2");

diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index b6e025aac29b046..4c46861bbbd74ef 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -161,7 +161,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 if (Args.hasArg(options::OPT_rdynamic))
   CmdArgs.push_back("-export-dynamic");
 if (Args.hasArg(options::OPT_shared)) {
-  CmdArgs.push_back("-Bshareable");
+  CmdArgs.push_back("-shared");
 } else if (!Args.hasArg(options::OPT_r)) {
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");

diff  --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index ceabb06c14105b3..1ec8f1b7da4c662 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -139,7 +139,7 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 if (Args.hasArg(options::OPT_rdynamic))
   CmdArgs.push_back("-export-dynamic");
 if (Args.hasArg(options::OPT_shared)) {
-  CmdArgs.push_back("-Bshareable");
+  CmdArgs.push_back("-shared");
 } else if (!Args.hasArg(options::OPT_r)) {
   Args.AddAllArgs(CmdArgs, options::OPT_pie);
   CmdArgs.push_back("-dynamic-linker");

diff  --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c
index 28a888fedf3fe18..8ac0cb011638a8a 100644
--- a/clang/test/Driver/freebsd.c
+++ b/clang/test/Driver/freebsd.c
@@ -128,6 +128,7 @@
 // RUN: %clang --target=x86_64-pc-freebsd -shared %s \
 // RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-SHARED %s
+// CHECK-SHARED: ld{{.*}}" "--eh-frame-hdr" "-shared"
 // CHECK-SHARED: crti.o
 // CHECK-SHARED: crtbeginS.o
 

diff  --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c
index 4daa35a4a7f94fc..67c048c6e91515f 100644
--- a/clang/test/Driver/netbsd.c
+++ b/clang/test/Driver/netbsd.c
@@ -116,20 +116,20 @@
 
 // STATIC: ld{{.*}}" "--eh-frame-hdr"
 // STATIC-NOT: "-pie"
-// STATIC-NOT: "-Bshareable"
+// STATIC-NOT: "-shared"
 // STATIC: "-dynamic-linker" "/libexec/ld.elf_so"
 // STATIC-NOT: "-pie"
-// STATIC-NOT: "-Bshareable"
+// STATIC-NOT: "-shared"
 // STATIC: "{{.*}}/usr/lib{{/|}}crt0.o"
 // STATIC: "{{.*}}/usr/lib{{/|}}crti.o" 
"{{.*}}/usr/lib{{/|}}crtbegin.o"
 // STATIC: "{{.*}}/usr/lib{{/|}}crtend.o" "{{.*}}/usr/lib{{/|}}crtn.o"
 
 // STATIC-PIE: ld{{.*}}" "--eh-frame-hdr"
 // STATIC-PIE-NOT: "-dynamic-linker" "/libexec/ld.elf_so"
-// STATIC-PIE-NOT: "-Bshareable"
+// STATIC-PIE-NOT: "-shared"
 // STATIC-PIE: "-pie"
 // STATIC-PIE-NOT: "-dynamic-linker" "/libexec/ld.elf_so"
-// STATIC-PIE-NOT: "-Bshareable"
+// STATIC-PIE-NOT: "-shared"
 // STATIC-PIE: "{{.*}}/usr/lib{{/|}}crt0.o"
 // STATIC-PIE: "{{.*}}/usr/lib{{/|}}crti.o" 
"{{.*}}/usr/lib{{/|}}crtbeginS.o"
 // STATIC-PIE: "{{.*}}/usr/lib{{/|}}crtendS.o" 
"{{.*}}/usr/lib{{/|}}crtn.o"
@@ -142,9 +142,9 @@
 // SHARED: "{{.*}}/usr/lib{{/|}}crtendS.o" "{{.*}}/usr/lib{{/|}}crtn.o"
 
 // PIE: ld{{.*}}" "--eh-frame-hdr"
-// PIE-NOT: "-Bshareable"
+// PIE-NOT: "-shared"
 // PIE: "-pie" "-dynamic-linker" "/libexec/ld.elf_so"
-// PIE-NOT: "-Bshareable"
+// PIE-NOT: "-shared"
 // PIE: "{{.*}}/usr/lib{{/|}}crt0.o" "{{.*}}/usr/lib{{/|}}crti.o"
 // PIE: "{{.*}}/usr/lib{{/|}}crtbeginS.o"
 // PIE: "{{.*}}/usr/

[clang] [Driver] Replace usage of -Bshareable linker flag with -shared (PR #65842)

2023-09-10 Thread Brad Smith via cfe-commits

https://github.com/brad0 closed https://github.com/llvm/llvm-project/pull/65842
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141757: [clangd] allow extracting to variable for lambda expressions

2023-09-10 Thread Julian Schmidt via Phabricator via cfe-commits
5chmidti added a comment.

Thank you. Could you please commit this for me with `Julian Schmidt 
<44101708+5chmi...@users.noreply.github.com>`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141757

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


[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-09-10 Thread Kazushi Marukawa via Phabricator via cfe-commits
kaz7 added a comment.

I cannot write inline comment, so I'm leaving message here.

openmp/runtime/test/target/target_thread_limit.cpp:

> // checking consecutive target regions with different thread_limits
> #pragma omp target thread_limit(3)
>
>   {
> printf("\nsecond target: thread_limit = %d", omp_get_thread_limit());
>
> // OMP51: second target: thread_limit = 3

Our VE architecture supports only OpenMP runtime.  It doesn't support 
libomptarget.  If I run check-openmp on our machine, this 
omp_get_thread_limit() returns default thread limit 2147483647 (=0x7fff).  
I guess it is OK because this pragma specifies only target and our VE doensn't 
support target.  Other pragmas are containing not only target but also other 
keyword like parallel, so I guess others are running well.  I'm not clear about 
omptarget, so my assumptions here may be wrong, though.

My question is what is the best way to correct the behavior of this test?  I 
appreciate any comments or suggestions.  Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[PATCH] D159480: [Clang][AArch64] Fine-grained ldp and stp policies.

2023-09-10 Thread Dave Green via Phabricator via cfe-commits
dmgreen added a comment.

We do not usually add front-end clang options for optimizations like this. 
Users are more likely to use them incorrectly, or just not know that they 
exist. The usual method would be to make a subtarget tuning feature that 
controls whether ldp are created, and enable it for -mcpu=ampere1.

Having an internal llvm option for it (-mllvm -aarch64-stp-policy=never) sounds 
fine, but should be considered an internal option. And adding a subtarget 
feature would make sense to have this be used from ampere1. If you get the 
option committed to GCC then it might be OK for clang too, but I would suggest 
splitting this into a patch for the backend part and another for the frontend 
option in either case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159480

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


[clang] [Clang][AArch64] Define x86_64 macros for ARM64EC targets (PR #65420)

2023-09-10 Thread Jacek Caban via cfe-commits

cjacek wrote:

LGTM

https://github.com/llvm/llvm-project/pull/65420
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers created 
https://github.com/llvm/llvm-project/pull/65887:

evalIntegralCast is using APInt method to get the value of _BitInt() values 
after _BitInt() changes were introduced. Some of those methods assume values 
are less than or equal to 64-bits, which is not true for _BitInt() types. This 
change simply side steps that issue if the _BitInt() type is greater than 64 
bits.

This was caught with our internal randomized testing.

/llvm/include/llvm/ADT/APInt.h:1510:
  int64_t llvm::APInt::getSExtValue() const: Assertion
  `getSignificantBits() <= 64 && "Too many bits for int64_t"' failed.a

...
 #9  llvm::APInt::getSExtValue() const
  /llvm/include/llvm/ADT/APInt.h:1510:5
  llvm::IntrusiveRefCntPtr,
  clang::ento::SVal, clang::QualType, clang::QualType)
  /clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:607:24
  clang::Expr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&)
  /clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:413:61
...

 Fixes: https://github.com/llvm/llvm-project/issues/61960

 Reviewed By: donat.nagy

>From 82992c100b8aa7b2dd9fc59c688d40fc968f39ca Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Sat, 9 Sep 2023 21:08:47 +0200
Subject: [PATCH] [analyzer] Do not use APInt methods on _BitInt() Types

evalIntegralCast is using APInt method to get the value of _BitInt()
values after _BitInt() changes were introduced. Some of those methods
assume values are less than or equal to 64-bits, which is not true for
_BitInt() types. This change simply side steps that issue if the
_BitInt() type is greater than 64 bits.

This was caught with our internal randomized testing.

/llvm/include/llvm/ADT/APInt.h:1510:
  int64_t llvm::APInt::getSExtValue() const: Assertion
  `getSignificantBits() <= 64 && "Too many bits for int64_t"' failed.a

...
 #9  llvm::APInt::getSExtValue() const
  /llvm/include/llvm/ADT/APInt.h:1510:5
  llvm::IntrusiveRefCntPtr,
  clang::ento::SVal, clang::QualType, clang::QualType)
  /clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:607:24
  clang::Expr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&)
  /clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:413:61
...

 Fixes: https://github.com/llvm/llvm-project/issues/61960

 Reviewed By: donat.nagy
---
 clang/lib/StaticAnalyzer/Core/SValBuilder.cpp |  6 ++
 clang/test/Analysis/bitint-no-crash.c | 11 +++
 2 files changed, 17 insertions(+)
 create mode 100644 clang/test/Analysis/bitint-no-crash.c

diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
index 4fe828bdf7681fc..c9765e3a653e30a 100644
--- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -598,6 +598,12 @@ SVal SValBuilder::evalIntegralCast(ProgramStateRef state, 
SVal val,
   APSIntType ToType(getContext().getTypeSize(castTy),
 castTy->isUnsignedIntegerType());
   llvm::APSInt ToTypeMax = ToType.getMaxValue();
+  // With the introduction of _BitInt(), integral types can be
+  // > 64 bits. So check for this and skip the size checks
+  // falling back to making a non loc return type.
+  if (ToTypeMax.getSignificantBits() > 64) {
+return makeNonLoc(se, originalTy, castTy);
+  }
   NonLoc ToTypeMaxVal =
   makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue()
 : ToTypeMax.getSExtValue(),
diff --git a/clang/test/Analysis/bitint-no-crash.c 
b/clang/test/Analysis/bitint-no-crash.c
new file mode 100644
index 000..6fa041974a3c981
--- /dev/null
+++ b/clang/test/Analysis/bitint-no-crash.c
@@ -0,0 +1,11 @@
+ // RUN: %clang_analyze_cc1 -analyzer-checker=core \
+ // RUN:   -analyzer-checker=debug.ExprInspection \
+ // RUN:   -verify %s
+
+// Don't crash when using _BitInt()
+// expected-no-diagnostics
+_BitInt(256) a;
+_BitInt(129) b;
+void c() {
+  b = a;
+}

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


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers review_requested 
https://github.com/llvm/llvm-project/pull/65887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers review_requested 
https://github.com/llvm/llvm-project/pull/65887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-10 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-10 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-10 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Avoid checking magic numbers if _BitInt (PR #65888)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers created 
https://github.com/llvm/llvm-project/pull/65888:

Recent changes to add _BitInt support have caused our internal random testing 
to fail. This change just avoids a readability magic numbers check for now if a 
_BitInt. The crash seen (edited for clarity) is shown below.

/llvm/include/llvm/ADT/APInt.h:1488:
  uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits()
  <= 64 && "Too many bits for uint64_t"' failed.

...
 #9  llvm::APInt::getZExtValue() const
  /llvm/include/llvm/ADT/APInt.h:1488:5
  clang::IntegerLiteral const*) const
  
/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:198:47
  (clang::ast_matchers::MatchFinder::MatchResult
  const&, char const*)
  
/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h:67:5
  clang::ast_matchers::MatchFinder::MatchResult const&)
  
/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:152:35
...

Reviewed By: donat.nagy

>From 9ecb065a60a67cef568b0c5d60c760a72e9bac93 Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Sat, 9 Sep 2023 17:01:56 +0200
Subject: [PATCH] [clang-tidy] Avoid checking magic numbers if _BitInt

Recent changes to add _BitInt support have caused our internal random
testing to fail. This change just avoids a readability magic numbers
check for now if a _BitInt. The crash seen (edited for clarity) is shown
below.

/llvm/include/llvm/ADT/APInt.h:1488:
  uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits()
  <= 64 && "Too many bits for uint64_t"' failed.

...
 #9  llvm::APInt::getZExtValue() const
  /llvm/include/llvm/ADT/APInt.h:1488:5
  clang::IntegerLiteral const*) const
  
/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:198:47
  (clang::ast_matchers::MatchFinder::MatchResult
  const&, char const*)
  
/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h:67:5
  clang::ast_matchers::MatchFinder::MatchResult const&)
  
/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:152:35
...

Reviewed By: donat.nagy
---
 .../clang-tidy/readability/MagicNumbersCheck.cpp| 3 +++
 .../test/clang-tidy/checkers/readability/bitint-no-crash.c  | 6 ++
 2 files changed, 9 insertions(+)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c

diff --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
index 7f3c2cb9a0434cc..97c20cf200fa21c 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
@@ -191,6 +191,9 @@ bool MagicNumbersCheck::isConstant(const 
MatchFinder::MatchResult &Result,
 }
 
 bool MagicNumbersCheck::isIgnoredValue(const IntegerLiteral *Literal) const {
+  if (Literal->getType()->isBitIntType()) {
+return true;
+  }
   const llvm::APInt IntValue = Literal->getValue();
   const int64_t Value = IntValue.getZExtValue();
   if (Value == 0)
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c 
b/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
new file mode 100644
index 000..f8660924cbef5a0
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s readability-magic-numbers %t --
+
+// Don't crash
+
+_BitInt(128) A = 4533629751480627964421wb;
+// CHECK-MESSAGES: warning

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


[clang-tools-extra] [clang-tidy] Avoid checking magic numbers if _BitInt (PR #65888)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers review_requested 
https://github.com/llvm/llvm-project/pull/65888
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Avoid checking magic numbers if _BitInt (PR #65888)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers review_requested 
https://github.com/llvm/llvm-project/pull/65888
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Avoid checking magic numbers if _BitInt (PR #65888)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers review_requested 
https://github.com/llvm/llvm-project/pull/65888
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Avoid checking magic numbers if _BitInt (PR #65888)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers review_requested 
https://github.com/llvm/llvm-project/pull/65888
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-10 Thread via cfe-commits

llvmbot wrote:

@llvm/pr-subscribers-clang


Changes

evalIntegralCast is using APInt method to get the value of _BitInt() values 
after _BitInt() changes were introduced. Some of those methods assume values 
are less than or equal to 64-bits, which is not true for _BitInt() types. This 
change simply side steps that issue if the _BitInt() type is greater than 64 
bits.

This was caught with our internal randomized testing.

/llvm/include/llvm/ADT/APInt.h:1510:
  int64_t llvm::APInt::getSExtValue() const: Assertion
  `getSignificantBits() <= 64 && "Too many bits for int64_t"' failed.a

...
 #9  llvm::APInt::getSExtValue() const
  /llvm/include/llvm/ADT/APInt.h:1510:5
  llvm::IntrusiveRefCntPtr,
  clang::ento::SVal, clang::QualType, clang::QualType)
  /clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:607:24
  clang::Expr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&)
  /clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:413:61
...

 Fixes: https://github.com/llvm/llvm-project/issues/61960

 Reviewed By: donat.nagy
--
Full diff: https://github.com/llvm/llvm-project/pull/65887.diff

2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/SValBuilder.cpp (+6) 
- (added) clang/test/Analysis/bitint-no-crash.c (+11) 



diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
index 4fe828bdf7681fc..c9765e3a653e30a 100644
--- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -598,6 +598,12 @@ SVal SValBuilder::evalIntegralCast(ProgramStateRef state, 
SVal val,
   APSIntType ToType(getContext().getTypeSize(castTy),
 castTy->isUnsignedIntegerType());
   llvm::APSInt ToTypeMax = ToType.getMaxValue();
+  // With the introduction of _BitInt(), integral types can be
+  // > 64 bits. So check for this and skip the size checks
+  // falling back to making a non loc return type.
+  if (ToTypeMax.getSignificantBits() > 64) {
+return makeNonLoc(se, originalTy, castTy);
+  }
   NonLoc ToTypeMaxVal =
   makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue()
 : ToTypeMax.getSExtValue(),
diff --git a/clang/test/Analysis/bitint-no-crash.c 
b/clang/test/Analysis/bitint-no-crash.c
new file mode 100644
index 000..6fa041974a3c981
--- /dev/null
+++ b/clang/test/Analysis/bitint-no-crash.c
@@ -0,0 +1,11 @@
+ // RUN: %clang_analyze_cc1 -analyzer-checker=core \
+ // RUN:   -analyzer-checker=debug.ExprInspection \
+ // RUN:   -verify %s
+
+// Don't crash when using _BitInt()
+// expected-no-diagnostics
+_BitInt(256) a;
+_BitInt(129) b;
+void c() {
+  b = a;
+}




https://github.com/llvm/llvm-project/pull/65887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers created 
https://github.com/llvm/llvm-project/pull/65889:

This crash was exposed recently in our randomized testing. _BitInts were not 
being handled properly during IntegerLiteral visitation. This patch addresses 
the problem for now.

The BitIntType has no getKind() method, so the FoldingSetID is taken from the 
APInt value representing the _BitInt(), similar to other methods in 
StmtProfile.cpp.

Crash seen (summary form):

clang-tidy: /llvm/include/llvm/Support/Casting.h:566: decltype(auto) 
llvm::cast(const From&) [with To = clang::BuiltinType; From = clang::QualType]: 
Assertion `isa(Val) && "cast() argument of incompatible type!"' failed

...
  #9  decltype(auto) llvm::cast(clang::QualType const&)
   /llvm/include/llvm/Support/Casting.h:566:3
 #10  clang::BuiltinType const* 
clang::Type::castAs() const
   /tools/clang/include/clang/AST/TypeNodes.inc:86:1
 #11  (anonymous namespace)::StmtProfiler::VisitIntegerLiteral(
   clang::IntegerLiteral const*)
   /clang/lib/AST/StmtProfile.cpp:1362:64
 #12  clang::StmtVisitorBase::Visit(clang::Stmt const*)
   /clang/include/clang/AST/StmtNodes.inc:1225:1
...

Reviewed By: donat.nagy

>From 1311ae7e364efb3c88d3a214e511ff017b84c1ed Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Sat, 9 Sep 2023 12:19:07 +0200
Subject: [PATCH] [clang] [C23] Fix crash with _BitInt running clang-tidy

This crash was exposed recently in our randomized testing. _BitInts were
not being handled properly during IntegerLiteral visitation. This patch
addresses the problem for now.

The BitIntType has no getKind() method, so the FoldingSetID is taken
from the APInt value representing the _BitInt(), similar to other
methods in StmtProfile.cpp.

Crash seen (summary form):

clang-tidy: /llvm/include/llvm/Support/Casting.h:566:
decltype(auto) llvm::cast(const From&) [with To = clang::BuiltinType;
>From = clang::QualType]: Assertion `isa(Val) && "cast() argument
of incompatible type!"' failed

...
  #9  decltype(auto) llvm::cast(clang::QualType const&)
   /llvm/include/llvm/Support/Casting.h:566:3
 #10  clang::BuiltinType const* 
clang::Type::castAs() const
   /tools/clang/include/clang/AST/TypeNodes.inc:86:1
 #11  (anonymous namespace)::StmtProfiler::VisitIntegerLiteral(
   clang::IntegerLiteral const*)
   /clang/lib/AST/StmtProfile.cpp:1362:64
 #12  clang::StmtVisitorBase::Visit(clang::Stmt const*)
   /clang/include/clang/AST/StmtNodes.inc:1225:1
...

Reviewed By: donat.nagy
---
 .../bugprone/inc-dec-in-conditions-bitint-no-crash.c   | 10 ++
 clang/lib/AST/StmtProfile.cpp  | 10 +-
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
new file mode 100644
index 000..55921205f34875e
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s bugprone-inc-dec-in-conditions %t
+
+#define foo(x) \
+  ({   \
+_BitInt(5) y = x;  \
+16777215wb ?: ++y; \
+  })
+
+_BitInt(8) v_401_0() { 0 && foo(0); }
+// CHECK-MESSAGES: warning 
diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 27f71edd6f99b32..0a6bc388bd73e18 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -1333,7 +1333,15 @@ void StmtProfiler::VisitPredefinedExpr(const 
PredefinedExpr *S) {
 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
   VisitExpr(S);
   S->getValue().Profile(ID);
-  ID.AddInteger(S->getType()->castAs()->getKind());
+
+  int FoldingSetID = 0;
+
+  if (S->getType()->isBitIntType())
+FoldingSetID = S->getValue().getSExtValue();
+  else
+FoldingSetID = S->getType()->castAs()->getKind();
+
+  ID.AddInteger(FoldingSetID);
 }
 
 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {

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


[clang] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers review_requested 
https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers review_requested 
https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers review_requested 
https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Avoid checking magic numbers if _BitInt (PR #65888)

2023-09-10 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65888
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers review_requested 
https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

https://github.com/vabridgers review_requested 
https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Avoid checking magic numbers if _BitInt (PR #65888)

2023-09-10 Thread via cfe-commits

llvmbot wrote:

@llvm/pr-subscribers-clang-tidy


Changes

Recent changes to add _BitInt support have caused our internal random testing 
to fail. This change just avoids a readability magic numbers check for now if a 
_BitInt. The crash seen (edited for clarity) is shown below.

/llvm/include/llvm/ADT/APInt.h:1488:
  uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits()
  <= 64 && "Too many bits for uint64_t"' failed.

...
 #9  llvm::APInt::getZExtValue() const
  /llvm/include/llvm/ADT/APInt.h:1488:5
  clang::IntegerLiteral const*) const
  
/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:198:47
  (clang::ast_matchers::MatchFinder::MatchResult
  const&, char const*)
  
/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h:67:5
  clang::ast_matchers::MatchFinder::MatchResult const&)
  
/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:152:35
...

Reviewed By: donat.nagy
--
Full diff: https://github.com/llvm/llvm-project/pull/65888.diff

2 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp 
(+3) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c (+6) 



diff --git a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
index 7f3c2cb9a0434cc..97c20cf200fa21c 100644
--- a/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
@@ -191,6 +191,9 @@ bool MagicNumbersCheck::isConstant(const 
MatchFinder::MatchResult &Result,
 }
 
 bool MagicNumbersCheck::isIgnoredValue(const IntegerLiteral *Literal) const {
+  if (Literal->getType()->isBitIntType()) {
+return true;
+  }
   const llvm::APInt IntValue = Literal->getValue();
   const int64_t Value = IntValue.getZExtValue();
   if (Value == 0)
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c 
b/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
new file mode 100644
index 000..f8660924cbef5a0
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/bitint-no-crash.c
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s readability-magic-numbers %t --
+
+// Don't crash
+
+_BitInt(128) A = 4533629751480627964421wb;
+// CHECK-MESSAGES: warning




https://github.com/llvm/llvm-project/pull/65888
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

llvmbot wrote:

@llvm/pr-subscribers-clang-tidy


Changes

This crash was exposed recently in our randomized testing. _BitInts were not 
being handled properly during IntegerLiteral visitation. This patch addresses 
the problem for now.

The BitIntType has no getKind() method, so the FoldingSetID is taken from the 
APInt value representing the _BitInt(), similar to other methods in 
StmtProfile.cpp.

Crash seen (summary form):

clang-tidy: /llvm/include/llvm/Support/Casting.h:566: decltype(auto) 
llvm::cast(const From&) [with To = clang::BuiltinType; From = clang::QualType]: 
Assertion `isa(Val) && "cast() argument of incompatible type!"' failed

...
  #9  decltype(auto) llvm::cast(clang::QualType const&)
   /llvm/include/llvm/Support/Casting.h:566:3
 #10  clang::BuiltinType const* 
clang::Type::castAs() const
   /tools/clang/include/clang/AST/TypeNodes.inc:86:1
 #11  (anonymous namespace)::StmtProfiler::VisitIntegerLiteral(
   clang::IntegerLiteral const*)
   /clang/lib/AST/StmtProfile.cpp:1362:64
 #12  clang::StmtVisitorBase::Visit(clang::Stmt const*)
   /clang/include/clang/AST/StmtNodes.inc:1225:1
...

Reviewed By: donat.nagy
--
Full diff: https://github.com/llvm/llvm-project/pull/65889.diff

2 Files Affected:

- (added) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
 (+10) 
- (modified) clang/lib/AST/StmtProfile.cpp (+9-1) 



diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
new file mode 100644
index 000..55921205f34875e
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s bugprone-inc-dec-in-conditions %t
+
+#define foo(x) \
+  ({   \
+_BitInt(5) y = x;  \
+16777215wb ?: ++y; \
+  })
+
+_BitInt(8) v_401_0() { 0 && foo(0); }
+// CHECK-MESSAGES: warning 
diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 27f71edd6f99b32..0a6bc388bd73e18 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -1333,7 +1333,15 @@ void StmtProfiler::VisitPredefinedExpr(const 
PredefinedExpr *S) {
 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
   VisitExpr(S);
   S->getValue().Profile(ID);
-  ID.AddInteger(S->getType()->castAs()->getKind());
+
+  int FoldingSetID = 0;
+
+  if (S->getType()->isBitIntType())
+FoldingSetID = S->getValue().getSExtValue();
+  else
+FoldingSetID = S->getType()->castAs()->getKind();
+
+  ID.AddInteger(FoldingSetID);
 }
 
 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {




https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread via cfe-commits

llvmbot wrote:

@llvm/pr-subscribers-clang


Changes

This crash was exposed recently in our randomized testing. _BitInts were not 
being handled properly during IntegerLiteral visitation. This patch addresses 
the problem for now.

The BitIntType has no getKind() method, so the FoldingSetID is taken from the 
APInt value representing the _BitInt(), similar to other methods in 
StmtProfile.cpp.

Crash seen (summary form):

clang-tidy: /llvm/include/llvm/Support/Casting.h:566: decltype(auto) 
llvm::cast(const From&) [with To = clang::BuiltinType; From = clang::QualType]: 
Assertion `isa(Val) && "cast() argument of incompatible type!"' failed

...
  #9  decltype(auto) llvm::cast(clang::QualType const&)
   /llvm/include/llvm/Support/Casting.h:566:3
 #10  clang::BuiltinType const* 
clang::Type::castAs() const
   /tools/clang/include/clang/AST/TypeNodes.inc:86:1
 #11  (anonymous namespace)::StmtProfiler::VisitIntegerLiteral(
   clang::IntegerLiteral const*)
   /clang/lib/AST/StmtProfile.cpp:1362:64
 #12  clang::StmtVisitorBase::Visit(clang::Stmt const*)
   /clang/include/clang/AST/StmtNodes.inc:1225:1
...

Reviewed By: donat.nagy
--
Full diff: https://github.com/llvm/llvm-project/pull/65889.diff

2 Files Affected:

- (added) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
 (+10) 
- (modified) clang/lib/AST/StmtProfile.cpp (+9-1) 



diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
new file mode 100644
index 000..55921205f34875e
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inc-dec-in-conditions-bitint-no-crash.c
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s bugprone-inc-dec-in-conditions %t
+
+#define foo(x) \
+  ({   \
+_BitInt(5) y = x;  \
+16777215wb ?: ++y; \
+  })
+
+_BitInt(8) v_401_0() { 0 && foo(0); }
+// CHECK-MESSAGES: warning 
diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index 27f71edd6f99b32..0a6bc388bd73e18 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -1333,7 +1333,15 @@ void StmtProfiler::VisitPredefinedExpr(const 
PredefinedExpr *S) {
 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
   VisitExpr(S);
   S->getValue().Profile(ID);
-  ID.AddInteger(S->getType()->castAs()->getKind());
+
+  int FoldingSetID = 0;
+
+  if (S->getType()->isBitIntType())
+FoldingSetID = S->getValue().getSExtValue();
+  else
+FoldingSetID = S->getType()->castAs()->getKind();
+
+  ID.AddInteger(FoldingSetID);
 }
 
 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {




https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Do not use APInt methods on _BitInt() Types (PR #65887)

2023-09-10 Thread Balazs Benics via cfe-commits

steakhal wrote:

I guess this is one sideeffect of `getZExtValue` and `getSExtValue`.
To me, it feels like all such calls could hit the same assert, thus it fixes 
this instance, but we still lack a generic solution to this problem at other 
places.
I'm not opposing to this fix, but it might make sense to step back and grep for 
these calls to see the wider picture.

https://github.com/llvm/llvm-project/pull/65887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ExtractAPI] Create extractapi::RecordLocation (PR #65891)

2023-09-10 Thread via cfe-commits

https://github.com/Arsenic-ATG review_requested 
https://github.com/llvm/llvm-project/pull/65891
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ExtractAPI] Create extractapi::RecordLocation (PR #65891)

2023-09-10 Thread via cfe-commits

https://github.com/Arsenic-ATG labeled 
https://github.com/llvm/llvm-project/pull/65891
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ExtractAPI] Create extractapi::RecordLocation (PR #65891)

2023-09-10 Thread via cfe-commits

https://github.com/Arsenic-ATG created 
https://github.com/llvm/llvm-project/pull/65891:

Create and use `extractapi::RecordLocation` instead of conventional 
`clang::PresumedLoc` to track the location of an APIRecord, this reduces the 
dependency of APISet on SourceManager and would help if someone wants to create 
APISet from JSON Serialized SymbolGraph.

These changes also add `extractapi::CommentLine` which is similar to 
RawComment::CommentLine but use RecordLocation instead of PresumedLoc.


This was initially being tracked on llvm Phabricator
Differential Revision: https://reviews.llvm.org/D157810

>From 373e29b1b40574af861b40505f779d548d718552 Mon Sep 17 00:00:00 2001
From: Ankur 
Date: Sat, 26 Aug 2023 19:30:35 +0530
Subject: [PATCH] [clang][ExtractAPI] Create extractapi::RecordLocation

Create and use extractapi::RecordLocation instead of conventional
clang::PresumedLoc to track the location of an APIRecord, this reduces
the dependency of APISet on SourceManager and would help if someone
wants to create APISet from JSON Serialized SymbolGraph.

These changes also add extractapi::CommentLine which is similar to
RawComment::CommentLine but use RecordLocation instead of PresumedLoc.

Differential Revision: https://reviews.llvm.org/D157810
---
 clang/include/clang/ExtractAPI/API.h  | 363 ++
 .../clang/ExtractAPI/ExtractAPIVisitor.h  | 178 +++--
 clang/lib/ExtractAPI/API.cpp  |  90 ++---
 .../Serialization/SymbolGraphSerializer.cpp   |  10 +-
 clang/tools/libclang/CXExtractAPI.cpp |   9 +-
 5 files changed, 312 insertions(+), 338 deletions(-)

diff --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index b4c0e0ad39cdf2a..d4367caf647550f 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -134,7 +134,48 @@ class Template {
   bool empty() const { return Parameters.empty() && Constraints.empty(); }
 };
 
-/// DocComment is a vector of RawComment::CommentLine.
+/// Slightly cut down version of PresumedLoc to suit the needs of
+/// ExtractAPI.
+class RecordLocation {
+  unsigned Line, Col;
+  std::string Filename;
+
+public:
+  RecordLocation(const unsigned Line, const unsigned Col,
+ std::string Filename = "")
+  : Line(Line), Col(Col), Filename(Filename) {}
+  RecordLocation(const PresumedLoc &Location)
+  : Line(Location.getLine()), Col(Location.getColumn()),
+Filename(Location.getFilename()) {}
+  RecordLocation() = default;
+
+  bool isInvalid() const { return Filename.empty(); }
+  bool isValid() const { return !isInvalid(); }
+
+  const char *getFilename() const { return Filename.c_str(); }
+
+  unsigned getLine() const { return Line; }
+
+  unsigned getColumn() const { return Col; }
+};
+
+/// Store a documentation comment line of an APIRecord
+///
+/// Similar to RawComment::CommentLine but use RecordLocation instead
+/// of PresumedLoc.
+struct CommentLine {
+
+  std::string Text;
+  RecordLocation Begin;
+  RecordLocation End;
+
+  CommentLine(llvm::StringRef Text, RecordLocation Begin, RecordLocation End)
+  : Text(Text), Begin(Begin), End(End) {}
+  CommentLine(const RawComment::CommentLine RComment)
+  : Text(RComment.Text), Begin(RComment.Begin), End(RComment.End) {}
+};
+
+/// DocComment is a vector of extractapi::CommentLine.
 ///
 /// Each line represents one line of striped documentation comment,
 /// with source range information. This simplifies calculating the source
@@ -147,7 +188,7 @@ class Template {
 ///   /// with multiple lines.
 ///   ^~~' Second line.
 /// \endcode
-using DocComment = std::vector;
+using DocComment = std::vector;
 
 // Classes deriving from APIRecord need to have USR be the first constructor
 // argument. This is so that they are compatible with `addTopLevelRecord`
@@ -223,7 +264,7 @@ struct APIRecord {
 
   StringRef USR;
   StringRef Name;
-  PresumedLoc Location;
+  RecordLocation Location;
   AvailabilitySet Availabilities;
   LinkageInfo Linkage;
 
@@ -256,7 +297,7 @@ struct APIRecord {
   APIRecord() = delete;
 
   APIRecord(RecordKind Kind, StringRef USR, StringRef Name,
-PresumedLoc Location, AvailabilitySet Availabilities,
+RecordLocation Location, AvailabilitySet Availabilities,
 LinkageInfo Linkage, const DocComment &Comment,
 DeclarationFragments Declaration, DeclarationFragments SubHeading,
 bool IsFromSystemHeader)
@@ -273,7 +314,7 @@ struct APIRecord {
 };
 
 struct NamespaceRecord : APIRecord {
-  NamespaceRecord(StringRef USR, StringRef Name, PresumedLoc Loc,
+  NamespaceRecord(StringRef USR, StringRef Name, RecordLocation Loc,
   AvailabilitySet Availabilities, LinkageInfo Linkage,
   const DocComment &Comment, DeclarationFragments Declaration,
   DeclarationFragments SubHeading, bool IsFromSystemHeader)
@@ -290,19 +331,20 @@ st

[clang] [clang][ExtractAPI] Create extractapi::RecordLocation (PR #65891)

2023-09-10 Thread via cfe-commits

https://github.com/Arsenic-ATG review_requested 
https://github.com/llvm/llvm-project/pull/65891
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ExtractAPI] Create extractapi::RecordLocation (PR #65891)

2023-09-10 Thread via cfe-commits

llvmbot wrote:

@llvm/pr-subscribers-clang


Changes

Create and use `extractapi::RecordLocation` instead of conventional 
`clang::PresumedLoc` to track the location of an APIRecord, this reduces the 
dependency of APISet on SourceManager and would help if someone wants to create 
APISet from JSON Serialized SymbolGraph.

These changes also add `extractapi::CommentLine` which is similar to 
RawComment::CommentLine but use RecordLocation instead of PresumedLoc.


This was initially being tracked on llvm Phabricator
Differential Revision: https://reviews.llvm.org/D157810
--

Patch is 92.55 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/65891.diff

5 Files Affected:

- (modified) clang/include/clang/ExtractAPI/API.h (+212-151) 
- (modified) clang/include/clang/ExtractAPI/ExtractAPIVisitor.h (+43-135) 
- (modified) clang/lib/ExtractAPI/API.cpp (+46-44) 
- (modified) clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
(+5-5) 
- (modified) clang/tools/libclang/CXExtractAPI.cpp (+6-3) 



diff --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index b4c0e0ad39cdf2a..d4367caf647550f 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -134,7 +134,48 @@ class Template {
   bool empty() const { return Parameters.empty() && Constraints.empty(); }
 };
 
-/// DocComment is a vector of RawComment::CommentLine.
+/// Slightly cut down version of PresumedLoc to suit the needs of
+/// ExtractAPI.
+class RecordLocation {
+  unsigned Line, Col;
+  std::string Filename;
+
+public:
+  RecordLocation(const unsigned Line, const unsigned Col,
+ std::string Filename = "")
+  : Line(Line), Col(Col), Filename(Filename) {}
+  RecordLocation(const PresumedLoc &Location)
+  : Line(Location.getLine()), Col(Location.getColumn()),
+Filename(Location.getFilename()) {}
+  RecordLocation() = default;
+
+  bool isInvalid() const { return Filename.empty(); }
+  bool isValid() const { return !isInvalid(); }
+
+  const char *getFilename() const { return Filename.c_str(); }
+
+  unsigned getLine() const { return Line; }
+
+  unsigned getColumn() const { return Col; }
+};
+
+/// Store a documentation comment line of an APIRecord
+///
+/// Similar to RawComment::CommentLine but use RecordLocation instead
+/// of PresumedLoc.
+struct CommentLine {
+
+  std::string Text;
+  RecordLocation Begin;
+  RecordLocation End;
+
+  CommentLine(llvm::StringRef Text, RecordLocation Begin, RecordLocation End)
+  : Text(Text), Begin(Begin), End(End) {}
+  CommentLine(const RawComment::CommentLine RComment)
+  : Text(RComment.Text), Begin(RComment.Begin), End(RComment.End) {}
+};
+
+/// DocComment is a vector of extractapi::CommentLine.
 ///
 /// Each line represents one line of striped documentation comment,
 /// with source range information. This simplifies calculating the source
@@ -147,7 +188,7 @@ class Template {
 ///   /// with multiple lines.
 ///   ^~~' Second line.
 /// \endcode
-using DocComment = std::vector;
+using DocComment = std::vector;
 
 // Classes deriving from APIRecord need to have USR be the first constructor
 // argument. This is so that they are compatible with `addTopLevelRecord`
@@ -223,7 +264,7 @@ struct APIRecord {
 
   StringRef USR;
   StringRef Name;
-  PresumedLoc Location;
+  RecordLocation Location;
   AvailabilitySet Availabilities;
   LinkageInfo Linkage;
 
@@ -256,7 +297,7 @@ struct APIRecord {
   APIRecord() = delete;
 
   APIRecord(RecordKind Kind, StringRef USR, StringRef Name,
-PresumedLoc Location, AvailabilitySet Availabilities,
+RecordLocation Location, AvailabilitySet Availabilities,
 LinkageInfo Linkage, const DocComment &Comment,
 DeclarationFragments Declaration, DeclarationFragments SubHeading,
 bool IsFromSystemHeader)
@@ -273,7 +314,7 @@ struct APIRecord {
 };
 
 struct NamespaceRecord : APIRecord {
-  NamespaceRecord(StringRef USR, StringRef Name, PresumedLoc Loc,
+  NamespaceRecord(StringRef USR, StringRef Name, RecordLocation Loc,
   AvailabilitySet Availabilities, LinkageInfo Linkage,
   const DocComment &Comment, DeclarationFragments Declaration,
   DeclarationFragments SubHeading, bool IsFromSystemHeader)
@@ -290,19 +331,20 @@ struct NamespaceRecord : APIRecord {
 struct GlobalFunctionRecord : APIRecord {
   FunctionSignature Signature;
 
-  GlobalFunctionRecord(StringRef USR, StringRef Name, PresumedLoc Loc,
+  GlobalFunctionRecord(StringRef USR, StringRef Name,
+   RecordLocation RecordLocation,
AvailabilitySet Availabilities, LinkageInfo Linkage,
const DocComment &Comment,
DeclarationFragments Declaration,
DeclarationFragments SubHeading,
FunctionSignature 

[clang] [clang][ExtractAPI] Create extractapi::RecordLocation (PR #65891)

2023-09-10 Thread via cfe-commits


@@ -134,7 +134,48 @@ class Template {
   bool empty() const { return Parameters.empty() && Constraints.empty(); }
 };
 
-/// DocComment is a vector of RawComment::CommentLine.
+/// Slightly cut down version of PresumedLoc to suit the needs of
+/// ExtractAPI.
+class RecordLocation {
+  unsigned Line, Col;
+  std::string Filename;

Arsenic-ATG wrote:

Due to some reasons, I am currently unable to open the original deferential 
revision (https://reviews.llvm.org/D157810).

So for those who are facing the same issue, It had the following review comment 
from @ributzka 

> There is an opportunity for optimization by avoiding the allocation of 
> separate strings for each source location, especially since many source 
> locations will be in the same file. As an example, APISet utilizes a 
> BumpPtrAllocator to allocate and deduplicate strings. It is recommended to 
> consider using the same allocator or a similar concept.

https://github.com/llvm/llvm-project/pull/65891
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158371: [clang-tidy] Fix DanglingHandleCheck to work in C++17 and later mode

2023-09-10 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

In D158371#4640664 , @loskutov wrote:

> However, I don't have push access to the repo, so could you commit the change?

Name / Email (to be used as author) ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158371

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


[clang] [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (PR #65699)

2023-09-10 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/65699:

>From f4271e03667b64c8d10d7e4de16e78b37e845229 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Fri, 8 Sep 2023 00:21:59 +0100
Subject: [PATCH] AS_cast the argument to `eh_typeid_for` iff typeinfo is not
 in the default AS.

---
 clang/lib/CodeGen/CGException.cpp |  5 +++-
 .../try-catch-with-address-space.cpp  | 25 +++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/try-catch-with-address-space.cpp

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 3996f2948349cb5..49cf4ec4b84307b 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1149,7 +1149,10 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
 assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
 assert(typeValue && "fell into catch-all case!");
-typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
+llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+// With opaque ptrs, only the address space can be a mismatch.
+if (typeValue->getType() != argTy)
+  typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);
 
 // Figure out the next block.
 bool nextIsEnd;
diff --git a/clang/test/CodeGenCXX/try-catch-with-address-space.cpp 
b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
new file mode 100644
index 000..279d29f50fd4101
--- /dev/null
+++ b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s
+
+struct X { };
+
+const X g();
+
+void f() {
+  try {
+throw g();
+// CHECK: ptr addrspace(1) @_ZTI1X
+  } catch (const X x) {
+// CHECK: catch ptr addrspace(1) @_ZTI1X
+// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) 
@_ZTI1X to ptr))
+  }
+}
+
+void h() {
+  try {
+throw "ABC";
+// CHECK: ptr addrspace(1) @_ZTIPKc
+  } catch (char const(&)[4]) {
+// CHECK: catch ptr addrspace(1) @_ZTIA4_c
+// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) 
@_ZTIA4_c to ptr))
+  }
+}

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


[clang] [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (PR #65699)

2023-09-10 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65699
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (PR #65699)

2023-09-10 Thread via cfe-commits

llvmbot wrote:

@llvm/pr-subscribers-clang


Changes

This change is symmetric with the one reviewed in 
 and handles the exception handling specific 
intrinsic, which slipped through the cracks, in the same way, by inserting an 
address-space cast iff RTTI is in a non-default AS.
--
Full diff: https://github.com/llvm/llvm-project/pull/65699.diff

2 Files Affected:

- (modified) clang/lib/CodeGen/CGException.cpp (+4-1) 
- (added) clang/test/CodeGenCXX/try-catch-with-address-space.cpp (+25) 



diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 3996f2948349cb5..49cf4ec4b84307b 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1149,7 +1149,10 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
 assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
 assert(typeValue && "fell into catch-all case!");
-typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
+llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+// With opaque ptrs, only the address space can be a mismatch.
+if (typeValue->getType() != argTy)
+  typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);
 
 // Figure out the next block.
 bool nextIsEnd;
diff --git a/clang/test/CodeGenCXX/try-catch-with-address-space.cpp 
b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
new file mode 100644
index 000..279d29f50fd4101
--- /dev/null
+++ b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s
+
+struct X { };
+
+const X g();
+
+void f() {
+  try {
+throw g();
+// CHECK: ptr addrspace(1) @_ZTI1X
+  } catch (const X x) {
+// CHECK: catch ptr addrspace(1) @_ZTI1X
+// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) 
@_ZTI1X to ptr))
+  }
+}
+
+void h() {
+  try {
+throw "ABC";
+// CHECK: ptr addrspace(1) @_ZTIPKc
+  } catch (char const(&)[4]) {
+// CHECK: catch ptr addrspace(1) @_ZTIA4_c
+// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) 
@_ZTIA4_c to ptr))
+  }
+}




https://github.com/llvm/llvm-project/pull/65699
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra][ExtractAPI] create clang-symbolgraph-merger (PR #65894)

2023-09-10 Thread via cfe-commits

https://github.com/Arsenic-ATG review_requested 
https://github.com/llvm/llvm-project/pull/65894
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tools-extra][ExtractAPI] create clang-symbolgraph-merger (PR #65894)

2023-09-10 Thread via cfe-commits

https://github.com/Arsenic-ATG labeled 
https://github.com/llvm/llvm-project/pull/65894
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra][ExtractAPI] create clang-symbolgraph-merger (PR #65894)

2023-09-10 Thread via cfe-commits

https://github.com/Arsenic-ATG labeled 
https://github.com/llvm/llvm-project/pull/65894
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra][ExtractAPI] create clang-symbolgraph-merger (PR #65894)

2023-09-10 Thread via cfe-commits

llvmbot wrote:

@llvm/pr-subscribers-clang


Changes

Create a clang tool to merge all the JSON symbolgraph emited by 
--emit-symbol-graph or -extract-api options into one unified JSON symbolgraph 
file.

Differential Revision: https://reviews.llvm.org/D158646
--

Patch is 127.06 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/65894.diff

16 Files Affected:

- (modified) clang-tools-extra/CMakeLists.txt (+1) 
- (added) clang-tools-extra/clang-symbolgraph-merger/CMakeLists.txt (+3) 
- (added) 
clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraph.h
 (+48) 
- (added) 
clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraphMerger.h
 (+45) 
- (added) 
clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraphVisitor.h
 (+68) 
- (added) clang-tools-extra/clang-symbolgraph-merger/lib/CMakeLists.txt (+14) 
- (added) clang-tools-extra/clang-symbolgraph-merger/lib/SymbolGraph.cpp (+243) 
- (added) clang-tools-extra/clang-symbolgraph-merger/lib/SymbolGraphMerger.cpp 
(+290) 
- (added) clang-tools-extra/clang-symbolgraph-merger/tool/CMakeLists.txt (+13) 
- (added) 
clang-tools-extra/clang-symbolgraph-merger/tool/SymbolGraphMergerMain.cpp 
(+125) 
- (modified) clang/include/clang/ExtractAPI/API.h (+212-151) 
- (modified) clang/include/clang/ExtractAPI/AvailabilityInfo.h (+6) 
- (modified) clang/include/clang/ExtractAPI/ExtractAPIVisitor.h (+43-135) 
- (modified) clang/lib/ExtractAPI/API.cpp (+46-44) 
- (modified) clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
(+5-5) 
- (modified) clang/tools/libclang/CXExtractAPI.cpp (+6-3) 



diff --git a/clang-tools-extra/CMakeLists.txt b/clang-tools-extra/CMakeLists.txt
index 6a3f741721ee6c7..a4052e0894076ef 100644
--- a/clang-tools-extra/CMakeLists.txt
+++ b/clang-tools-extra/CMakeLists.txt
@@ -13,6 +13,7 @@ if(CLANG_INCLUDE_TESTS)
   endif()
 endif()
 
+add_subdirectory(clang-symbolgraph-merger)
 add_subdirectory(clang-apply-replacements)
 add_subdirectory(clang-reorder-fields)
 add_subdirectory(modularize)
diff --git a/clang-tools-extra/clang-symbolgraph-merger/CMakeLists.txt 
b/clang-tools-extra/clang-symbolgraph-merger/CMakeLists.txt
new file mode 100644
index 000..a071a8a11693337
--- /dev/null
+++ b/clang-tools-extra/clang-symbolgraph-merger/CMakeLists.txt
@@ -0,0 +1,3 @@
+include_directories(include)
+add_subdirectory(lib)
+add_subdirectory(tool)
diff --git 
a/clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraph.h
 
b/clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraph.h
new file mode 100755
index 000..a613f833ffad73b
--- /dev/null
+++ 
b/clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraph.h
@@ -0,0 +1,48 @@
+#ifndef SYMBOLGRAPH_H
+#define SYMBOLGRAPH_H
+
+#include "clang/Basic/LangStandard.h"
+#include "clang/ExtractAPI/API.h"
+#include "clang/ExtractAPI/AvailabilityInfo.h"
+#include "clang/ExtractAPI/DeclarationFragments.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+#include 
+#include 
+
+namespace sgmerger {
+
+// see https://github.com/apple/swift-docc-symbolkit/bdob/main/openapi.yaml
+struct SymbolGraph {
+
+  struct Symbol {
+Symbol(const llvm::json::Object &SymbolObj);
+
+llvm::json::Object SymbolObj;
+std::string AccessLevel;
+clang::extractapi::APIRecord::RecordKind Kind;
+clang::extractapi::DeclarationFragments DeclFragments;
+clang::extractapi::FunctionSignature FunctionSign;
+std::string Name;
+std::string USR;
+clang::extractapi::AvailabilitySet Availabilities;
+clang::extractapi::DocComment Comments;
+clang::extractapi::RecordLocation Location;
+clang::extractapi::DeclarationFragments SubHeadings;
+
+// underlying type in case of Typedef
+clang::extractapi::SymbolReference UnderLyingType;
+  };
+
+  SymbolGraph(const llvm::StringRef JSON);
+  llvm::json::Object SymbolGraphObject;
+  llvm::json::Object Metadata;
+  llvm::json::Object Module;
+  std::vector Symbols;
+  llvm::json::Array Relationships;
+};
+
+} // namespace sgmerger
+
+#endif /* SYMBOLGRAPH_H */
diff --git 
a/clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraphMerger.h
 
b/clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraphMerger.h
new file mode 100755
index 000..179cadafd877825
--- /dev/null
+++ 
b/clang-tools-extra/clang-symbolgraph-merger/include/clang-symbolgraph-merger/SymbolGraphMerger.h
@@ -0,0 +1,45 @@
+#ifndef SYMBOLGRAPHMERGER_H
+#define SYMBOLGRAPHMERGER_H
+
+#include "clang-symbolgraph-merger/SymbolGraph.h"
+#include "clang-symbolgraph-merger/SymbolGraphVisitor.h"
+#include "clang/Basic/LangStandard.h"
+#include "clang/ExtractAPI/API.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "l

[PATCH] D158646: [clang-tools-extra][ExtractAPI] create clang-symbolgraph-merger

2023-09-10 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic added a comment.

In D158646#4639599 , @dang wrote:

> As per https://discourse.llvm.org/t/pull-request-migration-schedule/71595 we 
> should move this review to GitHub to make sure we don't lose track of it.

The patch has been moved to GitHub ( 
https://github.com/llvm/llvm-project/pull/65894 )


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

https://reviews.llvm.org/D158646

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


[clang-tools-extra] [clang-tools-extra][ExtractAPI] create clang-symbolgraph-merger (PR #65894)

2023-09-10 Thread via cfe-commits

Arsenic-ATG wrote:

- The changes were initially being tracked on llvm Phabricator 
Differential Revision: https://reviews.llvm.org/D158646
- Dependent on #65891 
- Currently keeping this as draft pull request and would be opening it for 
review once it is ready and tested completely.

https://github.com/llvm/llvm-project/pull/65894
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Extension: allow recursive macros (PR #65851)

2023-09-10 Thread via cfe-commits

https://github.com/kelbon updated 
https://github.com/llvm/llvm-project/pull/65851:

>From 2f807b312baef8c6038c2452b84232acb6d6d2c2 Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Sat, 9 Sep 2023 17:51:15 +0400
Subject: [PATCH 1/2] add define2 pp directive

---
 clang/include/clang/Basic/TokenKinds.def |  1 +
 clang/include/clang/Lex/MacroInfo.h  | 19 +--
 clang/include/clang/Lex/Preprocessor.h   |  2 +-
 clang/lib/Basic/IdentifierTable.cpp  |  2 ++
 clang/lib/Format/WhitespaceManager.cpp   |  2 +-
 clang/lib/Lex/MacroInfo.cpp  |  3 ++-
 clang/lib/Lex/PPDirectives.cpp   | 16 +++-
 7 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 45ebc200b168986..f059d809823ab42 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -115,6 +115,7 @@ PPKEYWORD(__include_macros)
 
 // C99 6.10.3 - Macro Replacement.
 PPKEYWORD(define)
+PPKEYWORD(define2)
 PPKEYWORD(undef)
 
 // C99 6.10.4 - Line Control.
diff --git a/clang/include/clang/Lex/MacroInfo.h 
b/clang/include/clang/Lex/MacroInfo.h
index 00c1c3866bbd9ca..4f0c8e987610e50 100644
--- a/clang/include/clang/Lex/MacroInfo.h
+++ b/clang/include/clang/Lex/MacroInfo.h
@@ -102,6 +102,10 @@ class MacroInfo {
   /// like \#define A A.
   bool IsDisabled : 1;
 
+  // True if 'define2' used,
+  // ignores 'IsDisabled' and enables expansion anyway
+  bool AllowRecurse : 1;
+
   /// True if this macro is either defined in the main file and has
   /// been used, or if it is not defined in the main file.
   ///
@@ -278,18 +282,13 @@ class MacroInfo {
   /// Return true if this macro is enabled.
   ///
   /// In other words, that we are not currently in an expansion of this macro.
-  bool isEnabled() const { return !IsDisabled; }
-
-  void EnableMacro() {
-assert(IsDisabled && "Cannot enable an already-enabled macro!");
-IsDisabled = false;
-  }
+  bool isEnabled() const { return AllowRecurse || !IsDisabled; }
+  void setAllowRecursive(bool Allow) { AllowRecurse = Allow; }
+  bool isAllowRecurse() const { return AllowRecurse; }
 
-  void DisableMacro() {
-assert(!IsDisabled && "Cannot disable an already-disabled macro!");
-IsDisabled = true;
-  }
+  void EnableMacro() { IsDisabled = false; }
 
+  void DisableMacro() { IsDisabled = true; }
   /// Determine whether this macro was used for a header guard.
   bool isUsedForHeaderGuard() const { return UsedForHeaderGuard; }
 
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 9efe439bc5f2192..de121ce82fd1d7b 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2754,7 +2754,7 @@ class Preprocessor {
   void replayPreambleConditionalStack();
 
   // Macro handling.
-  void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterHeaderGuard);
+  void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterHeaderGuard, 
bool AllowRecurse);
   void HandleUndefDirective();
 
   // Conditional Inclusion.
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index afb30268f2973ce..4de3565c8c6d9a8 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -433,6 +433,8 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   unsigned Len = getLength();
   if (Len < 2) return tok::pp_not_keyword;
   const char *Name = getNameStart();
+  if (std::string_view(Name, Len) == "define2")
+return tok::pp_define2;
   switch (HASH(Len, Name[0], Name[2])) {
   default: return tok::pp_not_keyword;
   CASE( 2, 'i', '\0', if);
diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index b7bd8d27dc976b1..d8ab76d6761553e 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -743,7 +743,7 @@ void WhitespaceManager::alignConsecutiveMacros() {
 if (!Current || Current->isNot(tok::identifier))
   return false;
 
-if (!Current->Previous || Current->Previous->isNot(tok::pp_define))
+if (!Current->Previous || !Current->Previous->isOneOf(tok::pp_define, 
tok::pp_define2))
   return false;
 
 // For a macro function, 0 spaces are required between the
diff --git a/clang/lib/Lex/MacroInfo.cpp b/clang/lib/Lex/MacroInfo.cpp
index 39bb0f44eff25ba..9c3619c7c909304 100644
--- a/clang/lib/Lex/MacroInfo.cpp
+++ b/clang/lib/Lex/MacroInfo.cpp
@@ -50,7 +50,7 @@ static_assert(MacroInfoSizeChecker::AsExpected,
 MacroInfo::MacroInfo(SourceLocation DefLoc)
 : Location(DefLoc), IsDefinitionLengthCached(false), IsFunctionLike(false),
   IsC99Varargs(false), IsGNUVarargs(false), IsBuiltinMacro(false),
-  HasCommaPasting(false), IsDisabled(false), IsUsed(false),
+  HasCommaPasting(false), IsDisabled(false), AllowRecurse(false), 
IsUsed(false),
   IsAllowRedefinitionsW

[PATCH] D156057: [Clang][Sema] Diagnose indeterminately sequenced accesses

2023-09-10 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@aaron.ballman that's been waiting for a while - i don't feel comfortable 
reviewing it, mind looking at it?


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

https://reviews.llvm.org/D156057

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


[PATCH] D158371: [clang-tidy] Fix DanglingHandleCheck to work in C++17 and later mode

2023-09-10 Thread Ignat Loskutov via Phabricator via cfe-commits
loskutov added a comment.

In D158371#4642758 , @PiotrZSL wrote:

> Name / Email (to be used as author) ?

Ignat Loskutov 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158371

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


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/65896:

Before:

array.cpp:319:10: note: read of uninitialized object is not allowed in a 
constant expression
  319 |return aaa;
  |   ^

After:

array.cpp:319:10: note: read of uninitialized object is not allowed in a 
constant expression
  319 |return aaa;
  |   ^~~

>From 00132d7f98dd3c4b994b6afd2a94773e2a46a496 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 10 Sep 2023 14:28:02 +0200
Subject: [PATCH] [clang][Diagnostics] Add source range to uninitialized
 diagnostics

Before:

array.cpp:319:10: note: read of uninitialized object is not allowed in a 
constant expression
  319 |return aaa;
  |   ^

After:

array.cpp:319:10: note: read of uninitialized object is not allowed in a 
constant expression
  319 |return aaa;
  |   ^~~
---
 clang/lib/AST/ExprConstant.cpp  | 5 +++--
 clang/lib/AST/Interp/Interp.cpp | 6 +++---
 clang/test/Misc/constexpr-source-ranges.cpp | 8 
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d8632f53bb1eef4..54a8d582939e118 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3711,7 +3711,8 @@ findSubobject(EvalInfo &Info, const Expr *E, const 
CompleteObject &Obj,
  !isValidIndeterminateAccess(handler.AccessKind))) {
   if (!Info.checkingPotentialConstantExpression())
 Info.FFDiag(E, diag::note_constexpr_access_uninit)
-<< handler.AccessKind << O->isIndeterminate();
+<< handler.AccessKind << O->isIndeterminate()
+<< E->getSourceRange();
   return handler.failed();
 }
 
@@ -4443,7 +,7 @@ struct CompoundAssignSubobjectHandler {
   return foundVector(Subobj, SubobjType);
 case APValue::Indeterminate:
   Info.FFDiag(E, diag::note_constexpr_access_uninit)
-  << /*read of=*/0 << /*uninitialized object=*/1;
+  << /*read of=*/0 << /*uninitialized object=*/1 << 
E->getSourceRange();
   return false;
 default:
   // FIXME: can this happen?
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 719a96daaebdd73..c94b48c8fc614e6 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -261,9 +261,9 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
 return true;
 
   if (!S.checkingPotentialConstantExpression()) {
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_constexpr_access_uninit)
-<< AK << /*uninitialized=*/true;
+const Expr *E = S.Current->getExpr(OpPC);
+S.FFDiag(E, diag::note_constexpr_access_uninit)
+<< AK << /*uninitialized=*/true << E->getSourceRange();
   }
   return false;
 }
diff --git a/clang/test/Misc/constexpr-source-ranges.cpp 
b/clang/test/Misc/constexpr-source-ranges.cpp
index f21373eff3a95ca..7f5c522ae305b54 100644
--- a/clang/test/Misc/constexpr-source-ranges.cpp
+++ b/clang/test/Misc/constexpr-source-ranges.cpp
@@ -41,3 +41,11 @@ int x = -1 + __INT_MAX__ + 2 + 3;
 // CHECK:  :{[[@LINE+1]]:9-[[@LINE+1]]:19}:
 int a = -(1 << 31) + 1;
 }
+
+
+constexpr int uninit() {
+  int aaa;
+  // CHECK: :{[[@LINE+1]]:10-[[@LINE+1]]:13}:
+  return aaa;
+}
+static_assert(uninit() == 0, "");

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


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr review_requested 
https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr edited 
https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread via cfe-commits

llvmbot wrote:

@llvm/pr-subscribers-clang


Changes

Before:

```
array.cpp:319:10: note: read of uninitialized object is not allowed in a 
constant expression
  319 |return aaa;
  |   ^
```

After:

```
array.cpp:319:10: note: read of uninitialized object is not allowed in a 
constant expression
  319 |return aaa;
  |   ^~~
```
--
Full diff: https://github.com/llvm/llvm-project/pull/65896.diff

3 Files Affected:

- (modified) clang/lib/AST/ExprConstant.cpp (+3-2) 
- (modified) clang/lib/AST/Interp/Interp.cpp (+3-3) 
- (modified) clang/test/Misc/constexpr-source-ranges.cpp (+8) 



diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d8632f53bb1eef4..54a8d582939e118 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3711,7 +3711,8 @@ findSubobject(EvalInfo &Info, const Expr *E, const 
CompleteObject &Obj,
  !isValidIndeterminateAccess(handler.AccessKind))) {
   if (!Info.checkingPotentialConstantExpression())
 Info.FFDiag(E, diag::note_constexpr_access_uninit)
-<< handler.AccessKind << O->isIndeterminate();
+<< handler.AccessKind << O->isIndeterminate()
+<< E->getSourceRange();
   return handler.failed();
 }
 
@@ -4443,7 +,7 @@ struct CompoundAssignSubobjectHandler {
   return foundVector(Subobj, SubobjType);
 case APValue::Indeterminate:
   Info.FFDiag(E, diag::note_constexpr_access_uninit)
-  << /*read of=*/0 << /*uninitialized object=*/1;
+  << /*read of=*/0 << /*uninitialized object=*/1 << 
E->getSourceRange();
   return false;
 default:
   // FIXME: can this happen?
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 719a96daaebdd73..c94b48c8fc614e6 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -261,9 +261,9 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
 return true;
 
   if (!S.checkingPotentialConstantExpression()) {
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_constexpr_access_uninit)
-<< AK << /*uninitialized=*/true;
+const Expr *E = S.Current->getExpr(OpPC);
+S.FFDiag(E, diag::note_constexpr_access_uninit)
+<< AK << /*uninitialized=*/true << E->getSourceRange();
   }
   return false;
 }
diff --git a/clang/test/Misc/constexpr-source-ranges.cpp 
b/clang/test/Misc/constexpr-source-ranges.cpp
index f21373eff3a95ca..7f5c522ae305b54 100644
--- a/clang/test/Misc/constexpr-source-ranges.cpp
+++ b/clang/test/Misc/constexpr-source-ranges.cpp
@@ -41,3 +41,11 @@ int x = -1 + __INT_MAX__ + 2 + 3;
 // CHECK:  :{[[@LINE+1]]:9-[[@LINE+1]]:19}:
 int a = -(1 << 31) + 1;
 }
+
+
+constexpr int uninit() {
+  int aaa;
+  // CHECK: :{[[@LINE+1]]:10-[[@LINE+1]]:13}:
+  return aaa;
+}
+static_assert(uninit() == 0, "");




https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr review_requested 
https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr review_requested 
https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr review_requested 
https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread via cfe-commits


@@ -4443,7 +,7 @@ struct CompoundAssignSubobjectHandler {
   return foundVector(Subobj, SubobjType);
 case APValue::Indeterminate:
   Info.FFDiag(E, diag::note_constexpr_access_uninit)
-  << /*read of=*/0 << /*uninitialized object=*/1;
+  << /*read of=*/0 << /*uninitialized object=*/1 << 
E->getSourceRange();

cor3ntin wrote:

Did you run clang-format?

https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread via cfe-commits

https://github.com/cor3ntin edited 
https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Avoid checking magic numbers if _BitInt (PR #65888)

2023-09-10 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

LGTM, 
not perfect, as we going to ignore big ints, but still better than crashing for 
now.

https://github.com/llvm/llvm-project/pull/65888
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 01c1156 - [clang-tidy] Add IgnoreTypes option to modernize-use-nullptr

2023-09-10 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-09-10T12:22:53Z
New Revision: 01c11569fc67b2a00403f64695fff6d2b4e78fe5

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

LOG: [clang-tidy] Add IgnoreTypes option to modernize-use-nullptr

New option added and configured in a way, so types
related to std::strong_ordering would be ignored.

Fixes: #63478

Reviewed By: ccotter

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
clang-tools-extra/clang-tidy/utils/Matchers.cpp
clang-tools-extra/clang-tidy/utils/Matchers.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
index efffc0c80fed8d1..6a003a347badacf 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -7,6 +7,8 @@
 
//===--===//
 
 #include "UseNullptrCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -33,11 +35,13 @@ AST_MATCHER(Type, sugaredNullptrType) {
 /// to null within.
 /// Finding sequences of explicit casts is necessary so that an entire sequence
 /// can be replaced instead of just the inner-most implicit cast.
-StatementMatcher makeCastSequenceMatcher() {
-  StatementMatcher ImplicitCastToNull = implicitCastExpr(
+StatementMatcher makeCastSequenceMatcher(llvm::ArrayRef NameList) {
+  auto ImplicitCastToNull = implicitCastExpr(
   anyOf(hasCastKind(CK_NullToPointer), 
hasCastKind(CK_NullToMemberPointer)),
   
unless(hasImplicitDestinationType(qualType(substTemplateTypeParmType(,
-  unless(hasSourceExpression(hasType(sugaredNullptrType();
+  unless(hasSourceExpression(hasType(sugaredNullptrType(,
+  unless(hasImplicitDestinationType(
+  qualType(matchers::matchesAnyListedTypeName(NameList);
 
   auto IsOrHasDescendant = [](auto InnerMatcher) {
 return anyOf(InnerMatcher, hasDescendant(InnerMatcher));
@@ -477,16 +481,21 @@ class CastSequenceVisitor : public 
RecursiveASTVisitor {
 
 UseNullptrCheck::UseNullptrCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  NullMacrosStr(Options.get("NullMacros", "NULL")) {
+  NullMacrosStr(Options.get("NullMacros", "NULL")),
+  IgnoredTypes(utils::options::parseStringList(Options.get(
+  "IgnoredTypes",
+  "std::_CmpUnspecifiedParam::;^std::__cmp_cat::__unspec"))) {
   StringRef(NullMacrosStr).split(NullMacros, ",");
 }
 
 void UseNullptrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "NullMacros", NullMacrosStr);
+  Options.store(Opts, "IgnoredTypes",
+utils::options::serializeStringList(IgnoredTypes));
 }
 
 void UseNullptrCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(makeCastSequenceMatcher(), this);
+  Finder->addMatcher(makeCastSequenceMatcher(IgnoredTypes), this);
 }
 
 void UseNullptrCheck::check(const MatchFinder::MatchResult &Result) {

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
index a8d2a8c0667bbdf..6c32a4edb4ff96e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
@@ -28,6 +28,7 @@ class UseNullptrCheck : public ClangTidyCheck {
 private:
   const StringRef NullMacrosStr;
   SmallVector NullMacros;
+  std::vector IgnoredTypes;
 };
 
 } // namespace clang::tidy::modernize

diff  --git a/clang-tools-extra/clang-tidy/utils/Matchers.cpp 
b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
index 440038e36d76437..7e89cae1c3316e4 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.cpp
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
@@ -17,4 +17,32 @@ bool NotIdenticalStatementsPredicate::operator()(
 Nodes.getNodeAs(ID), *Context);
 }
 
+MatchesAnyListedTypeNameMatcher::MatchesAnyListedTypeNameMatcher(
+llvm::ArrayRef NameList)
+: NameMatchers(NameList.begin(), NameList.end()) {}
+
+MatchesAnyListedTypeNameMatcher::~MatchesAnyListedTypeNameMatcher() = default;
+
+bool MatchesAnyListedTypeNameMatcher::matches(
+const QualType &Node, ast_ma

[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Meh this breaks a test in `clang/AST/Interp`, for unrelated reasons.

https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] f2e5000 - [clang-tidy] Fix DanglingHandleCheck to work in C++17 and later mode

2023-09-10 Thread Piotr Zegar via cfe-commits

Author: Ignat Loskutov
Date: 2023-09-10T12:52:47Z
New Revision: f2e5000937235aa35a9ee4423045b265c2c79e85

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

LOG: [clang-tidy] Fix DanglingHandleCheck to work in C++17 and later mode

Due to guaranteed copy elision, not only do some nodes get removed from the AST,
but also some existing nodes change the source locations they correspond to.
Hence, the check works slightly differently in pre-C++17 and C++17-and-later 
modes
in terms of what gets highlighted.

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
index 82c07bdc2ba95c6..9ded699ba78e66b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -36,9 +36,9 @@ ast_matchers::internal::Matcher 
handleFromTemporaryValue(
   // If a ternary operator returns a temporary value, then both branches hold a
   // temporary value. If one of them is not a temporary then it must be copied
   // into one to satisfy the type of the operator.
-  const auto TemporaryTernary =
-  conditionalOperator(hasTrueExpression(cxxBindTemporaryExpr()),
-  hasFalseExpression(cxxBindTemporaryExpr()));
+  const auto TemporaryTernary = conditionalOperator(
+  hasTrueExpression(ignoringParenImpCasts(cxxBindTemporaryExpr())),
+  hasFalseExpression(ignoringParenImpCasts(cxxBindTemporaryExpr(;
 
   return handleFrom(IsAHandle, anyOf(cxxBindTemporaryExpr(), 
TemporaryTernary));
 }
@@ -103,26 +103,17 @@ void 
DanglingHandleCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 void DanglingHandleCheck::registerMatchersForVariables(MatchFinder *Finder) {
   const auto ConvertedHandle = handleFromTemporaryValue(IsAHandle);
 
-  // Find 'Handle foo(ReturnsAValue());'
+  // Find 'Handle foo(ReturnsAValue());', 'Handle foo = ReturnsAValue();'
   Finder->addMatcher(
   varDecl(hasType(hasUnqualifiedDesugaredType(
   recordType(hasDeclaration(cxxRecordDecl(IsAHandle),
+  unless(parmVarDecl()),
   hasInitializer(
-  exprWithCleanups(has(ignoringParenImpCasts(ConvertedHandle)))
+  exprWithCleanups(ignoringElidableConstructorCall(has(
+   
ignoringParenImpCasts(ConvertedHandle
   .bind("bad_stmt"))),
   this);
 
-  // Find 'Handle foo = ReturnsAValue();'
-  Finder->addMatcher(
-  traverse(TK_AsIs,
-   varDecl(hasType(hasUnqualifiedDesugaredType(recordType(
-   hasDeclaration(cxxRecordDecl(IsAHandle),
-   unless(parmVarDecl()),
-   hasInitializer(exprWithCleanups(
-  has(ignoringParenImpCasts(handleFrom(
-  IsAHandle, ConvertedHandle
-  .bind("bad_stmt",
-  this);
   // Find 'foo = ReturnsAValue();  // foo is Handle'
   Finder->addMatcher(
   traverse(TK_AsIs,
@@ -141,36 +132,35 @@ void 
DanglingHandleCheck::registerMatchersForVariables(MatchFinder *Finder) {
 void DanglingHandleCheck::registerMatchersForReturn(MatchFinder *Finder) {
   // Return a local.
   Finder->addMatcher(
-  traverse(
-  TK_AsIs,
-  returnStmt(
-  // The AST contains two constructor calls:
-  //   1. Value to Handle conversion.
-  //   2. Handle copy construction.
-  // We have to match both.
-  has(ignoringImplicit(handleFrom(
-  IsAHandle,
-  handleFrom(IsAHandle,
- declRefExpr(to(varDecl(
- // Is function scope ...
- hasAutomaticStorageDuration(),
- // ... and it is a local array or Value.
- anyOf(hasType(arrayType()),
-   hasType(hasUnqualifiedDesugaredType(
-   
recordType(hasDeclaration(recordDecl(
-   unless(IsAHandle)),
-  // Temporary fix for false positives inside lambdas.
-  unless(hasAncestor(lambdaExpr(
-  .bind("bad_stmt")),
+  traverse(TK_AsIs,
+   returnStmt(
+  

[clang-tools-extra] [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (PR #65699)

2023-09-10 Thread Yaxun Liu via cfe-commits


@@ -1149,7 +1149,10 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
 assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
 assert(typeValue && "fell into catch-all case!");
-typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
+llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+// With opaque ptrs, only the address space can be a mismatch.
+if (typeValue->getType() != argTy)
+  typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);

yxsamliu wrote:

can we use CGF.Builder.CreateAddrSpaceCast instead?

https://github.com/llvm/llvm-project/pull/65699
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158928: [clang-tidy] Add IgnoreTypes option to modernize-use-nullptr

2023-09-10 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL closed this revision.
PiotrZSL added a comment.

Commited in 01c11569fc67b2a00403f64695fff6d2b4e78fe5


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158928

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


[clang-tools-extra] [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (PR #65699)

2023-09-10 Thread Yaxun Liu via cfe-commits


@@ -1149,7 +1149,10 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
 assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
 assert(typeValue && "fell into catch-all case!");
-typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
+llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+// With opaque ptrs, only the address space can be a mismatch.
+if (typeValue->getType() != argTy)
+  typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);

yxsamliu wrote:

sorry I mean getTargetHooks().performAddrSpaceCast

https://github.com/llvm/llvm-project/pull/65699
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158371: [clang-tidy] Fix DanglingHandleCheck to work in C++17 and later mode

2023-09-10 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL closed this revision.
PiotrZSL added a comment.

Commited in f2e5000937235aa35a9ee4423045b265c2c79e85


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158371

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


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Takuya Shimizu via cfe-commits


@@ -4443,7 +,7 @@ struct CompoundAssignSubobjectHandler {
   return foundVector(Subobj, SubobjType);
 case APValue::Indeterminate:
   Info.FFDiag(E, diag::note_constexpr_access_uninit)
-  << /*read of=*/0 << /*uninitialized object=*/1;
+  << /*read of=*/0 << /*uninitialized object=*/1 << 
E->getSourceRange();

hazohelet wrote:

I prefer `E->getLHS()->getSourceRange()` because the uninitialized object is 
known to exist in LHS.

https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/65896:

>From 698f706c66fd5332afbc8f99de30727d08faf430 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 10 Sep 2023 14:28:02 +0200
Subject: [PATCH] [clang][Diagnostics] Add source range to uninitialized
 diagnostics

Before:

array.cpp:319:10: note: read of uninitialized object is not allowed in a 
constant expression
  319 |return aaa;
  |   ^

After:

array.cpp:319:10: note: read of uninitialized object is not allowed in a 
constant expression
  319 |return aaa;
  |   ^~~
---
 clang/lib/AST/ExprConstant.cpp  | 5 +++--
 clang/lib/AST/Interp/Interp.cpp | 6 +++---
 clang/lib/AST/Interp/InterpFrame.cpp| 3 +++
 clang/test/Misc/constexpr-source-ranges.cpp | 8 
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d8632f53bb1eef4..54a8d582939e118 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3711,7 +3711,8 @@ findSubobject(EvalInfo &Info, const Expr *E, const 
CompleteObject &Obj,
  !isValidIndeterminateAccess(handler.AccessKind))) {
   if (!Info.checkingPotentialConstantExpression())
 Info.FFDiag(E, diag::note_constexpr_access_uninit)
-<< handler.AccessKind << O->isIndeterminate();
+<< handler.AccessKind << O->isIndeterminate()
+<< E->getSourceRange();
   return handler.failed();
 }
 
@@ -4443,7 +,7 @@ struct CompoundAssignSubobjectHandler {
   return foundVector(Subobj, SubobjType);
 case APValue::Indeterminate:
   Info.FFDiag(E, diag::note_constexpr_access_uninit)
-  << /*read of=*/0 << /*uninitialized object=*/1;
+  << /*read of=*/0 << /*uninitialized object=*/1 << 
E->getSourceRange();
   return false;
 default:
   // FIXME: can this happen?
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 719a96daaebdd73..c94b48c8fc614e6 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -261,9 +261,9 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
 return true;
 
   if (!S.checkingPotentialConstantExpression()) {
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_constexpr_access_uninit)
-<< AK << /*uninitialized=*/true;
+const Expr *E = S.Current->getExpr(OpPC);
+S.FFDiag(E, diag::note_constexpr_access_uninit)
+<< AK << /*uninitialized=*/true << E->getSourceRange();
   }
   return false;
 }
diff --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index ab3116eccf2017e..49db83a965ab001 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -230,5 +230,8 @@ SourceLocation InterpFrame::getLocation(CodePtr PC) const {
 }
 
 SourceRange InterpFrame::getRange(CodePtr PC) const {
+  if (Func && Func->getDecl()->isImplicit() && Caller)
+return Caller->getRange(RetPC);
+
   return S.getRange(Func, PC);
 }
diff --git a/clang/test/Misc/constexpr-source-ranges.cpp 
b/clang/test/Misc/constexpr-source-ranges.cpp
index f21373eff3a95ca..7f5c522ae305b54 100644
--- a/clang/test/Misc/constexpr-source-ranges.cpp
+++ b/clang/test/Misc/constexpr-source-ranges.cpp
@@ -41,3 +41,11 @@ int x = -1 + __INT_MAX__ + 2 + 3;
 // CHECK:  :{[[@LINE+1]]:9-[[@LINE+1]]:19}:
 int a = -(1 << 31) + 1;
 }
+
+
+constexpr int uninit() {
+  int aaa;
+  // CHECK: :{[[@LINE+1]]:10-[[@LINE+1]]:13}:
+  return aaa;
+}
+static_assert(uninit() == 0, "");

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


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Timm Baeder via cfe-commits


@@ -4443,7 +,7 @@ struct CompoundAssignSubobjectHandler {
   return foundVector(Subobj, SubobjType);
 case APValue::Indeterminate:
   Info.FFDiag(E, diag::note_constexpr_access_uninit)
-  << /*read of=*/0 << /*uninitialized object=*/1;
+  << /*read of=*/0 << /*uninitialized object=*/1 << 
E->getSourceRange();

tbaederr wrote:

Just re-checked, yes.

https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr resolved 
https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/65896:

>From 3d0a747ef78fb85fc09d6de65ccf57d4b832823a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 10 Sep 2023 14:28:02 +0200
Subject: [PATCH] [clang][Diagnostics] Add source range to uninitialized
 diagnostics

Before:

array.cpp:319:10: note: read of uninitialized object is not allowed in a 
constant expression
  319 |return aaa;
  |   ^

After:

array.cpp:319:10: note: read of uninitialized object is not allowed in a 
constant expression
  319 |return aaa;
  |   ^~~
---
 clang/lib/AST/ExprConstant.cpp  | 5 +++--
 clang/lib/AST/Interp/Interp.cpp | 6 +++---
 clang/lib/AST/Interp/InterpFrame.cpp| 3 +++
 clang/test/Misc/constexpr-source-ranges.cpp | 8 
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d8632f53bb1eef4..65628a2a8bb28dc 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3711,7 +3711,8 @@ findSubobject(EvalInfo &Info, const Expr *E, const 
CompleteObject &Obj,
  !isValidIndeterminateAccess(handler.AccessKind))) {
   if (!Info.checkingPotentialConstantExpression())
 Info.FFDiag(E, diag::note_constexpr_access_uninit)
-<< handler.AccessKind << O->isIndeterminate();
+<< handler.AccessKind << O->isIndeterminate()
+<< E->getSourceRange();
   return handler.failed();
 }
 
@@ -4443,7 +,7 @@ struct CompoundAssignSubobjectHandler {
   return foundVector(Subobj, SubobjType);
 case APValue::Indeterminate:
   Info.FFDiag(E, diag::note_constexpr_access_uninit)
-  << /*read of=*/0 << /*uninitialized object=*/1;
+  << /*read of=*/0 << /*uninitialized object=*/1 << 
E->getLHS()->getSourceRange();
   return false;
 default:
   // FIXME: can this happen?
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 719a96daaebdd73..c94b48c8fc614e6 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -261,9 +261,9 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
 return true;
 
   if (!S.checkingPotentialConstantExpression()) {
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_constexpr_access_uninit)
-<< AK << /*uninitialized=*/true;
+const Expr *E = S.Current->getExpr(OpPC);
+S.FFDiag(E, diag::note_constexpr_access_uninit)
+<< AK << /*uninitialized=*/true << E->getSourceRange();
   }
   return false;
 }
diff --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index ab3116eccf2017e..49db83a965ab001 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -230,5 +230,8 @@ SourceLocation InterpFrame::getLocation(CodePtr PC) const {
 }
 
 SourceRange InterpFrame::getRange(CodePtr PC) const {
+  if (Func && Func->getDecl()->isImplicit() && Caller)
+return Caller->getRange(RetPC);
+
   return S.getRange(Func, PC);
 }
diff --git a/clang/test/Misc/constexpr-source-ranges.cpp 
b/clang/test/Misc/constexpr-source-ranges.cpp
index f21373eff3a95ca..7f5c522ae305b54 100644
--- a/clang/test/Misc/constexpr-source-ranges.cpp
+++ b/clang/test/Misc/constexpr-source-ranges.cpp
@@ -41,3 +41,11 @@ int x = -1 + __INT_MAX__ + 2 + 3;
 // CHECK:  :{[[@LINE+1]]:9-[[@LINE+1]]:19}:
 int a = -(1 << 31) + 1;
 }
+
+
+constexpr int uninit() {
+  int aaa;
+  // CHECK: :{[[@LINE+1]]:10-[[@LINE+1]]:13}:
+  return aaa;
+}
+static_assert(uninit() == 0, "");

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


[clang-tools-extra] [clang] [C23] Fix crash with _BitInt running clang-tidy (PR #65889)

2023-09-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr edited 
https://github.com/llvm/llvm-project/pull/65889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Add source range to uninitialized diagnostics (PR #65896)

2023-09-10 Thread Takuya Shimizu via cfe-commits

https://github.com/hazohelet approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/65896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (PR #65699)

2023-09-10 Thread Alex Voicu via cfe-commits


@@ -1149,7 +1149,10 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
 assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
 assert(typeValue && "fell into catch-all case!");
-typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
+llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+// With opaque ptrs, only the address space can be a mismatch.
+if (typeValue->getType() != argTy)
+  typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);

AlexVlx wrote:

We can, I've only used the builder for symmetry (everything else uses direct 
emission) and convenience (we already have the LLVM types handy). I'll switch 
it over to the hook, and hoist the intrinsic arg type retrieval since it 
doesn't need to be in the loop.

https://github.com/llvm/llvm-project/pull/65699
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Properly indent lines inside Verilog case structure (PR #65861)

2023-09-10 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks approved this pull request.


https://github.com/llvm/llvm-project/pull/65861
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 89471d5 - [Fuchsia] Disable libcxx timezone database (#65870)

2023-09-10 Thread via cfe-commits

Author: Alex Brachet
Date: 2023-09-10T10:04:04-04:00
New Revision: 89471d50e8fc72b5157db17d7c9f77790b76b840

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

LOG: [Fuchsia] Disable libcxx timezone database (#65870)

tzdb is currently broken when cross compiling from non Linux to Linux.
Lets just disable it totally in our toolchain for now. We should remove
this when #65859 lands.

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 4890040b1b6a2b4..10e5cacf51c4b7b 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -181,6 +181,9 @@ foreach(target 
aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
 set(RUNTIMES_${target}_LLVM_TOOLS_DIR "${CMAKE_BINARY_DIR}/bin" CACHE BOOL 
"")
 set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
 
+# TODO: Remove this once #65859 lands.
+set(RUNTIMES_${target}_LIBCXX_ENABLE_TIME_ZONE_DATABASE OFF CACHE STRING 
"")
+
 # Use .build-id link.
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}")
   endif()



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


[clang] [Fuchsia] Disable libcxx timezone database (PR #65870)

2023-09-10 Thread Alex Brachet via cfe-commits

https://github.com/abrachet closed 
https://github.com/llvm/llvm-project/pull/65870
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-09-10 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D152054#4642725 , @kaz7 wrote:

> I run check-openmp on our machine, this omp_get_thread_limit() returns 
> default thread limit 2147483647 (=0x7fff).

That is something wrong because this patch is about host instead of offloading.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[clang-tools-extra] [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (PR #65699)

2023-09-10 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/65699:

>From f4271e03667b64c8d10d7e4de16e78b37e845229 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Fri, 8 Sep 2023 00:21:59 +0100
Subject: [PATCH 1/2] AS_cast the argument to `eh_typeid_for` iff typeinfo is
 not in the default AS.

---
 clang/lib/CodeGen/CGException.cpp |  5 +++-
 .../try-catch-with-address-space.cpp  | 25 +++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/try-catch-with-address-space.cpp

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 3996f2948349cb5..49cf4ec4b84307b 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1149,7 +1149,10 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
 assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
 assert(typeValue && "fell into catch-all case!");
-typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
+llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+// With opaque ptrs, only the address space can be a mismatch.
+if (typeValue->getType() != argTy)
+  typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);
 
 // Figure out the next block.
 bool nextIsEnd;
diff --git a/clang/test/CodeGenCXX/try-catch-with-address-space.cpp 
b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
new file mode 100644
index 000..279d29f50fd4101
--- /dev/null
+++ b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s
+
+struct X { };
+
+const X g();
+
+void f() {
+  try {
+throw g();
+// CHECK: ptr addrspace(1) @_ZTI1X
+  } catch (const X x) {
+// CHECK: catch ptr addrspace(1) @_ZTI1X
+// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) 
@_ZTI1X to ptr))
+  }
+}
+
+void h() {
+  try {
+throw "ABC";
+// CHECK: ptr addrspace(1) @_ZTIPKc
+  } catch (char const(&)[4]) {
+// CHECK: catch ptr addrspace(1) @_ZTIA4_c
+// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) 
@_ZTIA4_c to ptr))
+  }
+}

>From 938c798b39be0fd03f1e6c57ce7dd39c93145acb Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Sun, 10 Sep 2023 15:45:10 +0100
Subject: [PATCH 2/2] Switch to using the target hook for the as-cast.

---
 clang/lib/CodeGen/CGException.cpp | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 49cf4ec4b84307b..87594f71b26ec53 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1136,6 +1136,8 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
   // Select the right handler.
   llvm::Function *llvm_eh_typeid_for =
 CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_typeid_for);
+  llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+  LangAS globAS = CGF.CGM.GetGlobalVarAddressSpace(nullptr);
 
   // Load the selector value.
   llvm::Value *selector = CGF.getSelectorFromSlot();
@@ -1149,10 +1151,11 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
 assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
 assert(typeValue && "fell into catch-all case!");
-llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
 // With opaque ptrs, only the address space can be a mismatch.
 if (typeValue->getType() != argTy)
-  typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);
+  typeValue =
+CGF.getTargetHooks().performAddrSpaceCast(CGF, typeValue, globAS,
+  LangAS::Default, argTy);
 
 // Figure out the next block.
 bool nextIsEnd;

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


[clang-tools-extra] [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (PR #65699)

2023-09-10 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx resolved 
https://github.com/llvm/llvm-project/pull/65699
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (PR #65699)

2023-09-10 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/65699:

>From f4271e03667b64c8d10d7e4de16e78b37e845229 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Fri, 8 Sep 2023 00:21:59 +0100
Subject: [PATCH 1/2] AS_cast the argument to `eh_typeid_for` iff typeinfo is
 not in the default AS.

---
 clang/lib/CodeGen/CGException.cpp |  5 +++-
 .../try-catch-with-address-space.cpp  | 25 +++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/try-catch-with-address-space.cpp

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 3996f2948349cb5..49cf4ec4b84307b 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1149,7 +1149,10 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
 assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
 assert(typeValue && "fell into catch-all case!");
-typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
+llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+// With opaque ptrs, only the address space can be a mismatch.
+if (typeValue->getType() != argTy)
+  typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);
 
 // Figure out the next block.
 bool nextIsEnd;
diff --git a/clang/test/CodeGenCXX/try-catch-with-address-space.cpp 
b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
new file mode 100644
index 000..279d29f50fd4101
--- /dev/null
+++ b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s
+
+struct X { };
+
+const X g();
+
+void f() {
+  try {
+throw g();
+// CHECK: ptr addrspace(1) @_ZTI1X
+  } catch (const X x) {
+// CHECK: catch ptr addrspace(1) @_ZTI1X
+// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) 
@_ZTI1X to ptr))
+  }
+}
+
+void h() {
+  try {
+throw "ABC";
+// CHECK: ptr addrspace(1) @_ZTIPKc
+  } catch (char const(&)[4]) {
+// CHECK: catch ptr addrspace(1) @_ZTIA4_c
+// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) 
@_ZTIA4_c to ptr))
+  }
+}

>From 938c798b39be0fd03f1e6c57ce7dd39c93145acb Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Sun, 10 Sep 2023 15:45:10 +0100
Subject: [PATCH 2/2] Switch to using the target hook for the as-cast.

---
 clang/lib/CodeGen/CGException.cpp | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 49cf4ec4b84307b..87594f71b26ec53 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1136,6 +1136,8 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
   // Select the right handler.
   llvm::Function *llvm_eh_typeid_for =
 CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_typeid_for);
+  llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+  LangAS globAS = CGF.CGM.GetGlobalVarAddressSpace(nullptr);
 
   // Load the selector value.
   llvm::Value *selector = CGF.getSelectorFromSlot();
@@ -1149,10 +1151,11 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
 assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
 assert(typeValue && "fell into catch-all case!");
-llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
 // With opaque ptrs, only the address space can be a mismatch.
 if (typeValue->getType() != argTy)
-  typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);
+  typeValue =
+CGF.getTargetHooks().performAddrSpaceCast(CGF, typeValue, globAS,
+  LangAS::Default, argTy);
 
 // Figure out the next block.
 bool nextIsEnd;

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


[clang-tools-extra] [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (PR #65699)

2023-09-10 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx resolved 
https://github.com/llvm/llvm-project/pull/65699
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >