[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Christian Walther via Phabricator via cfe-commits
cwalther added a comment.

Thanks for the comments. Yes, `powerpc-*-eabi` should be valid (sorry if I was 
unclear about that – my parenthetical was only about AArch64). There is a 
PowerPC EABI: https://www.nxp.com/docs/en/application-note/PPCEABI.pdf . I 
wouldn’t know if Clang/LLD obey it, but it works for us…

I am fine with removing the vendor check if that is the consensus.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154357

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


[PATCH] D154861: [clang][AST] Propagate the contains-errors bit to DeclRefExpr from VarDecl's initializer.

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 538929.
hokein marked 2 inline comments as done.
hokein added a comment.

address comments and add release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154861

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ComputeDependence.cpp
  clang/test/AST/ast-dump-recovery.c
  clang/test/SemaCXX/cxx11-crashes.cpp


Index: clang/test/SemaCXX/cxx11-crashes.cpp
===
--- clang/test/SemaCXX/cxx11-crashes.cpp
+++ clang/test/SemaCXX/cxx11-crashes.cpp
@@ -65,7 +65,7 @@
   struct S {}; // expected-note 3{{candidate}}
   void f() {
 S s(1, 2, 3); // expected-error {{no matching}}
-for (auto x : s) { // expected-error {{invalid range expression of}}
+for (auto x : s) {
   // We used to attempt to evaluate the initializer of this variable,
   // and crash because it has an undeduced type.
   const int &n(x);
Index: clang/test/AST/ast-dump-recovery.c
===
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -126,3 +126,25 @@
   // CHECK-NEXT:   `-RecoveryExpr {{.*}} ''
   sizeof array / sizeof foo(undef);
 }
+
+// No crash on DeclRefExpr that refers to ValueDecl with invalid initializers.
+void test7() {
+  int b[] = {""()};
+
+  // CHECK:  CStyleCastExpr {{.*}} 'unsigned int' contains-errors
+  // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  (unsigned) b; // GH50236
+
+  // CHECK:  BinaryOperator {{.*}} '' contains-errors '+'
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int[]' contains-errors
+  // CHECK-NEXT: `-IntegerLiteral {{.*}}
+  b + 1; // GH50243
+
+  // CHECK:  CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int ()' Function
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  return c(b); // GH48636
+}
+int test8_GH50320_b[] = {""()};
+// CHECK: ArraySubscriptExpr {{.*}} 'int' contains-errors lvalue
+int test8 = test_8GH50320_b[0];
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -489,7 +489,7 @@
   // more bullets here that we handle by treating the declaration as having a
   // dependent type if they involve a placeholder type that can't be deduced.]
   if (Type->isDependentType())
-return Deps | ExprDependence::TypeValueInstantiation;
+Deps |= ExprDependence::TypeValueInstantiation;
   else if (Type->isInstantiationDependentType())
 Deps |= ExprDependence::Instantiation;
 
@@ -525,13 +525,13 @@
   //   - it names a potentially-constant variable that is initialized with an
   // expression that is value-dependent
   if (const auto *Var = dyn_cast(Decl)) {
-if (Var->mightBeUsableInConstantExpressions(Ctx)) {
-  if (const Expr *Init = Var->getAnyInitializer()) {
-if (Init->isValueDependent())
-  Deps |= ExprDependence::ValueInstantiation;
-if (Init->containsErrors())
-  Deps |= ExprDependence::Error;
-  }
+if (const Expr *Init = Var->getAnyInitializer()) {
+  if (Init->containsErrors())
+Deps |= ExprDependence::Error;
+
+  if (Var->mightBeUsableInConstantExpressions(Ctx) &&
+  Init->isValueDependent())
+Deps |= ExprDependence::ValueInstantiation;
 }
 
 // - it names a static data member that is a dependent member of the
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -573,6 +573,12 @@
 - Stop evaluating a constant expression if the condition expression which in
   switch statement contains errors.
   (`#63453 _`)
+- Fix the contains-errors bit not being set for DeclRefExpr that refers to a
+  VarDecl with invalid initializer. This fixes:
+  (`#50236 `_),
+  (`#50243 `_),
+  (`#48636 `_),
+  (`#50320 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/cxx11-crashes.cpp
===
--- clang/test/SemaCXX/cxx11-crashes.cpp
+++ clang/test/SemaCXX/cxx11-crashes.cpp
@@ -65,7 +65,7 @@
   struct S {}; // expected-note 3{{candidate}}
   void f() {
 S s(1, 2, 3); // expected-error {{no matching}}
-for (auto x : s) { // expected-error {{invalid range expression of}}
+for (auto x : s) {
   // We used to attempt to evaluate the initializer of this variable,
   // and crash because it has an undeduced type.
   const int 

[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D154357#4487896 , @cwalther wrote:

> Thanks for the comments. Yes, `powerpc-*-eabi` should be valid (sorry if I 
> was unclear about that – my parenthetical was only about AArch64). There is a 
> PowerPC EABI: https://www.nxp.com/docs/en/application-note/PPCEABI.pdf . I 
> wouldn’t know if Clang/LLD obey it, but it works for us…
>
> I am fine with removing the vendor check if that is the consensus.

Sounds good. I think `&&` is cleaner: `return Triple.getOS() == 
llvm::Triple::UnknownOS && ...`;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154357

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


[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D154357#4487896 , @cwalther wrote:

> [...] There is a PowerPC EABI: 
> https://www.nxp.com/docs/en/application-note/PPCEABI.pdf . I wouldn’t know if 
> Clang/LLD obey it, but it works for us…

Good to know! I read a newer ABI named Power Architecture® 32-bit Application 
Binary Interface Supplement 1.0 - Linux® & Embedded which contains `EABI` as 
well but I forgot it after I implemented ld.lld PPC32 back in 2019 (D62464 
 and a few others) :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154357

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


[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Christian Walther via Phabricator via cfe-commits
cwalther added a comment.

> I think `&&` is cleaner: `return Triple.getOS() == llvm::Triple::UnknownOS && 
> ...`;

Totally agree. I was just following precedent there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154357

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


[clang] 9ca395b - [clang][AST] Propagate the contains-errors bit to DeclRefExpr from VarDecl's initializer.

2023-07-11 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-07-11T09:14:27+02:00
New Revision: 9ca395b5ade105aee63db20534d49a1c58ac76c7

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

LOG: [clang][AST] Propagate the contains-errors bit to DeclRefExpr from 
VarDecl's initializer.

Similar to the https://reviews.llvm.org/D86048 (it only sets the bit for C++
code), we propagate the contains-errors bit for C-code path.

Fixes https://github.com/llvm/llvm-project/issues/50236
Fixes https://github.com/llvm/llvm-project/issues/50243
Fixes https://github.com/llvm/llvm-project/issues/48636
Fixes https://github.com/llvm/llvm-project/issues/50320

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ComputeDependence.cpp
clang/test/AST/ast-dump-recovery.c
clang/test/SemaCXX/cxx11-crashes.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ae88de6a4aa7e6..6a1e2fc3ea0e64 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -576,6 +576,12 @@ Bug Fixes in This Version
 - Fixed false positive error diagnostic when pack expansion appears in template
   parameters of a member expression.
   (`#48731 `_)
+- Fix the contains-errors bit not being set for DeclRefExpr that refers to a
+  VarDecl with invalid initializer. This fixes:
+  (`#50236 `_),
+  (`#50243 `_),
+  (`#48636 `_),
+  (`#50320 `_).
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/AST/ComputeDependence.cpp 
b/clang/lib/AST/ComputeDependence.cpp
index 632f38f711fb1b..09df5401d6693a 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -489,7 +489,7 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, 
const ASTContext &Ctx) {
   // more bullets here that we handle by treating the declaration as having a
   // dependent type if they involve a placeholder type that can't be deduced.]
   if (Type->isDependentType())
-return Deps | ExprDependence::TypeValueInstantiation;
+Deps |= ExprDependence::TypeValueInstantiation;
   else if (Type->isInstantiationDependentType())
 Deps |= ExprDependence::Instantiation;
 
@@ -525,13 +525,13 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, 
const ASTContext &Ctx) {
   //   - it names a potentially-constant variable that is initialized with an
   // expression that is value-dependent
   if (const auto *Var = dyn_cast(Decl)) {
-if (Var->mightBeUsableInConstantExpressions(Ctx)) {
-  if (const Expr *Init = Var->getAnyInitializer()) {
-if (Init->isValueDependent())
-  Deps |= ExprDependence::ValueInstantiation;
-if (Init->containsErrors())
-  Deps |= ExprDependence::Error;
-  }
+if (const Expr *Init = Var->getAnyInitializer()) {
+  if (Init->containsErrors())
+Deps |= ExprDependence::Error;
+
+  if (Var->mightBeUsableInConstantExpressions(Ctx) &&
+  Init->isValueDependent())
+Deps |= ExprDependence::ValueInstantiation;
 }
 
 // - it names a static data member that is a dependent member of the

diff  --git a/clang/test/AST/ast-dump-recovery.c 
b/clang/test/AST/ast-dump-recovery.c
index 969e0e7941244a..68d3f182dd9f64 100644
--- a/clang/test/AST/ast-dump-recovery.c
+++ b/clang/test/AST/ast-dump-recovery.c
@@ -126,3 +126,25 @@ void test6_GH50244() {
   // CHECK-NEXT:   `-RecoveryExpr {{.*}} ''
   sizeof array / sizeof foo(undef);
 }
+
+// No crash on DeclRefExpr that refers to ValueDecl with invalid initializers.
+void test7() {
+  int b[] = {""()};
+
+  // CHECK:  CStyleCastExpr {{.*}} 'unsigned int' contains-errors
+  // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  (unsigned) b; // GH50236
+
+  // CHECK:  BinaryOperator {{.*}} '' contains-errors '+'
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int[]' contains-errors
+  // CHECK-NEXT: `-IntegerLiteral {{.*}}
+  b + 1; // GH50243
+
+  // CHECK:  CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int ()' Function
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  return c(b); // GH48636
+}
+int test8_GH50320_b[] = {""()};
+// CHECK: ArraySubscriptExpr {{.*}} 'int' contains-errors lvalue
+int test8 = test_8GH50320_b[0];

diff  --git a/clang/test/SemaCXX/cxx11-crashes.cpp 
b/clang/test/SemaCXX/cxx11-crashes.cpp
index a15fea336f8c5e..11bc42315421d6 100644
--- a/clang/test/SemaCXX/cxx11-crashes.cpp
+++ b/clang/test/SemaCXX/cxx11-crashes.

[PATCH] D154861: [clang][AST] Propagate the contains-errors bit to DeclRefExpr from VarDecl's initializer.

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9ca395b5ade1: [clang][AST] Propagate the contains-errors bit 
to DeclRefExpr from VarDecl's… (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D154861?vs=538929&id=538931#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154861

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ComputeDependence.cpp
  clang/test/AST/ast-dump-recovery.c
  clang/test/SemaCXX/cxx11-crashes.cpp


Index: clang/test/SemaCXX/cxx11-crashes.cpp
===
--- clang/test/SemaCXX/cxx11-crashes.cpp
+++ clang/test/SemaCXX/cxx11-crashes.cpp
@@ -65,7 +65,7 @@
   struct S {}; // expected-note 3{{candidate}}
   void f() {
 S s(1, 2, 3); // expected-error {{no matching}}
-for (auto x : s) { // expected-error {{invalid range expression of}}
+for (auto x : s) {
   // We used to attempt to evaluate the initializer of this variable,
   // and crash because it has an undeduced type.
   const int &n(x);
Index: clang/test/AST/ast-dump-recovery.c
===
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -126,3 +126,25 @@
   // CHECK-NEXT:   `-RecoveryExpr {{.*}} ''
   sizeof array / sizeof foo(undef);
 }
+
+// No crash on DeclRefExpr that refers to ValueDecl with invalid initializers.
+void test7() {
+  int b[] = {""()};
+
+  // CHECK:  CStyleCastExpr {{.*}} 'unsigned int' contains-errors
+  // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  (unsigned) b; // GH50236
+
+  // CHECK:  BinaryOperator {{.*}} '' contains-errors '+'
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int[]' contains-errors
+  // CHECK-NEXT: `-IntegerLiteral {{.*}}
+  b + 1; // GH50243
+
+  // CHECK:  CallExpr {{.*}} '' contains-errors
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int ()' Function
+  // CHECK-NEXT: `-DeclRefExpr {{.*}} 'int[]' contains-errors
+  return c(b); // GH48636
+}
+int test8_GH50320_b[] = {""()};
+// CHECK: ArraySubscriptExpr {{.*}} 'int' contains-errors lvalue
+int test8 = test_8GH50320_b[0];
Index: clang/lib/AST/ComputeDependence.cpp
===
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -489,7 +489,7 @@
   // more bullets here that we handle by treating the declaration as having a
   // dependent type if they involve a placeholder type that can't be deduced.]
   if (Type->isDependentType())
-return Deps | ExprDependence::TypeValueInstantiation;
+Deps |= ExprDependence::TypeValueInstantiation;
   else if (Type->isInstantiationDependentType())
 Deps |= ExprDependence::Instantiation;
 
@@ -525,13 +525,13 @@
   //   - it names a potentially-constant variable that is initialized with an
   // expression that is value-dependent
   if (const auto *Var = dyn_cast(Decl)) {
-if (Var->mightBeUsableInConstantExpressions(Ctx)) {
-  if (const Expr *Init = Var->getAnyInitializer()) {
-if (Init->isValueDependent())
-  Deps |= ExprDependence::ValueInstantiation;
-if (Init->containsErrors())
-  Deps |= ExprDependence::Error;
-  }
+if (const Expr *Init = Var->getAnyInitializer()) {
+  if (Init->containsErrors())
+Deps |= ExprDependence::Error;
+
+  if (Var->mightBeUsableInConstantExpressions(Ctx) &&
+  Init->isValueDependent())
+Deps |= ExprDependence::ValueInstantiation;
 }
 
 // - it names a static data member that is a dependent member of the
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -576,6 +576,12 @@
 - Fixed false positive error diagnostic when pack expansion appears in template
   parameters of a member expression.
   (`#48731 `_)
+- Fix the contains-errors bit not being set for DeclRefExpr that refers to a
+  VarDecl with invalid initializer. This fixes:
+  (`#50236 `_),
+  (`#50243 `_),
+  (`#48636 `_),
+  (`#50320 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/cxx11-crashes.cpp
===
--- clang/test/SemaCXX/cxx11-crashes.cpp
+++ clang/test/SemaCXX/cxx11-crashes.cpp
@@ -65,7 +65,7 @@
   struct S {}; // expected-note 3{{candidate}}
   void f() {
 S s(1, 2, 3); // expected-error {{no matching}}
-for (auto x : s) { // expected-error 

[PATCH] D153989: [compiler-rt] Move crt into builtins

2023-07-11 Thread Petr Hosek via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
phosek marked an inline comment as done.
Closed by commit rGdae9d1b52469: [compiler-rt] Move crt into builtins (authored 
by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D153989?vs=535452&id=538935#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153989

Files:
  compiler-rt/CMakeLists.txt
  compiler-rt/cmake/builtin-config-ix.cmake
  compiler-rt/lib/CMakeLists.txt
  compiler-rt/lib/builtins/CMakeLists.txt
  compiler-rt/lib/builtins/crtbegin.c
  compiler-rt/lib/builtins/crtend.c
  compiler-rt/lib/crt/CMakeLists.txt
  compiler-rt/lib/crt/crtbegin.c
  compiler-rt/lib/crt/crtend.c
  compiler-rt/test/CMakeLists.txt
  compiler-rt/test/builtins/CMakeLists.txt
  compiler-rt/test/builtins/Unit/ctor_dtor.c
  compiler-rt/test/builtins/Unit/dso_handle.cpp
  compiler-rt/test/builtins/Unit/lit.cfg.py
  compiler-rt/test/builtins/Unit/lit.site.cfg.py.in
  compiler-rt/test/crt/CMakeLists.txt
  compiler-rt/test/crt/ctor_dtor.c
  compiler-rt/test/crt/dso_handle.cpp
  compiler-rt/test/crt/lit.cfg.py
  compiler-rt/test/crt/lit.site.cfg.py.in

Index: compiler-rt/test/crt/lit.site.cfg.py.in
===
--- compiler-rt/test/crt/lit.site.cfg.py.in
+++ /dev/null
@@ -1,14 +0,0 @@
-@LIT_SITE_CFG_IN_HEADER@
-
-# Tool-specific config options.
-config.name_suffix = "@CRT_TEST_CONFIG_SUFFIX@"
-config.crt_lit_source_dir = "@CRT_LIT_SOURCE_DIR@"
-config.target_cflags = "@CRT_TEST_TARGET_CFLAGS@"
-config.target_arch = "@CRT_TEST_TARGET_ARCH@"
-config.sanitizer_cxx_lib = "@SANITIZER_TEST_CXX_LIBNAME@"
-
-# Load common config for all compiler-rt lit tests
-lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
-
-# Load tool-specific config that would do the real work.
-lit_config.load_config(config, "@CRT_LIT_SOURCE_DIR@/lit.cfg.py")
Index: compiler-rt/test/crt/lit.cfg.py
===
--- compiler-rt/test/crt/lit.cfg.py
+++ /dev/null
@@ -1,95 +0,0 @@
-# -*- Python -*-
-
-import os
-import subprocess
-import shlex
-
-# Setup config name.
-config.name = "CRT" + config.name_suffix
-
-# Setup source root.
-config.test_source_root = os.path.dirname(__file__)
-
-
-# Choose between lit's internal shell pipeline runner and a real shell.  If
-# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
-use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
-if use_lit_shell:
-# 0 is external, "" is default, and everything else is internal.
-execute_external = use_lit_shell == "0"
-else:
-# Otherwise we default to internal on Windows and external elsewhere, as
-# bash on Windows is usually very slow.
-execute_external = not sys.platform in ["win32"]
-
-
-def get_library_path(file):
-cmd = subprocess.Popen(
-[config.clang.strip(), "-print-file-name=%s" % file]
-+ shlex.split(config.target_cflags),
-stdout=subprocess.PIPE,
-env=config.environment,
-universal_newlines=True,
-)
-if not cmd.stdout:
-lit_config.fatal("Couldn't find the library path for '%s'" % file)
-dir = cmd.stdout.read().strip()
-if sys.platform in ["win32"] and execute_external:
-# Don't pass dosish path separator to msys bash.exe.
-dir = dir.replace("\\", "/")
-return dir
-
-
-def get_libgcc_file_name():
-cmd = subprocess.Popen(
-[config.clang.strip(), "-print-libgcc-file-name"]
-+ shlex.split(config.target_cflags),
-stdout=subprocess.PIPE,
-env=config.environment,
-universal_newlines=True,
-)
-if not cmd.stdout:
-lit_config.fatal("Couldn't find the library path for '%s'" % file)
-dir = cmd.stdout.read().strip()
-if sys.platform in ["win32"] and execute_external:
-# Don't pass dosish path separator to msys bash.exe.
-dir = dir.replace("\\", "/")
-return dir
-
-
-def build_invocation(compile_flags):
-return " " + " ".join([config.clang] + compile_flags) + " "
-
-
-# Setup substitutions.
-config.substitutions.append(("%clang ", build_invocation([config.target_cflags])))
-config.substitutions.append(
-("%clangxx ", build_invocation(config.cxx_mode_flags + [config.target_cflags]))
-)
-
-base_lib = os.path.join(
-config.compiler_rt_libdir, "clang_rt.%%s%s.o" % config.target_suffix
-)
-
-if sys.platform in ["win32"] and execute_external:
-# Don't pass dosish path separator to msys bash.exe.
-base_lib = base_lib.replace("\\", "/")
-
-config.substitutions.append(("%crtbegin", base_lib % "crtbegin"))
-config.substitutions.append(("%crtend", base_lib % "crtend"))
-
-config.substitutions.append(("%crt1", get_library_path("crt1.o")))
-config.substitutions.append(("%crti", get_library_path("crti.o"

[PATCH] D154884: [clang-tidy] Make MatchesAnyListedNameMatcher cope with unnamed Decl

2023-07-11 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 538940.
mikecrowe marked an inline comment as done.
mikecrowe added a comment.

Remove unnecessary init-statement and test case in commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154884

Files:
  clang-tools-extra/clang-tidy/utils/Matchers.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
@@ -3,7 +3,7 @@
 // RUN: [ \
 // RUN:  { \
 // RUN:   key: modernize-use-std-print.PrintfLikeFunctions, \
-// RUN:   value: '::myprintf; mynamespace::myprintf2' \
+// RUN:   value: 'unqualified_printf;::myprintf; 
mynamespace::myprintf2' \
 // RUN:  }, \
 // RUN:  { \
 // RUN:   key: modernize-use-std-print.FprintfLikeFunctions, \
@@ -14,7 +14,7 @@
 // RUN:   -- -isystem %clang_tidy_headers
 
 #include 
-#include 
+#include 
 
 int myprintf(const char *, ...);
 int myfprintf(FILE *fp, const char *, ...);
@@ -85,3 +85,10 @@
   // CHECK-MESSAGES-NOT: [[@LINE-1]]:10: warning: use 'std::println' instead 
of 'myprintf' [modernize-use-std-print]
   // CHECK-FIXES-NOT: std::println(stderr, "return value {}", i);
 }
+
+// Ensure that MatchesAnyListedNameMatcher::NameMatcher::match() can cope with 
a
+// NamedDecl that has no name when we're trying to match unqualified_printf.
+void no_name(const std::string &in)
+{
+  "A" + in;
+}
Index: clang-tools-extra/clang-tidy/utils/Matchers.h
===
--- clang-tools-extra/clang-tidy/utils/Matchers.h
+++ clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -112,7 +112,9 @@
   case MatchMode::MatchFullyQualified:
 return Regex.match("::" + ND.getQualifiedNameAsString());
   default:
-return Regex.match(ND.getName());
+if (const IdentifierInfo *II = ND.getIdentifier())
+  return Regex.match(II->getName());
+return false;
   }
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
@@ -3,7 +3,7 @@
 // RUN: [ \
 // RUN:  { \
 // RUN:   key: modernize-use-std-print.PrintfLikeFunctions, \
-// RUN:   value: '::myprintf; mynamespace::myprintf2' \
+// RUN:   value: 'unqualified_printf;::myprintf; mynamespace::myprintf2' \
 // RUN:  }, \
 // RUN:  { \
 // RUN:   key: modernize-use-std-print.FprintfLikeFunctions, \
@@ -14,7 +14,7 @@
 // RUN:   -- -isystem %clang_tidy_headers
 
 #include 
-#include 
+#include 
 
 int myprintf(const char *, ...);
 int myfprintf(FILE *fp, const char *, ...);
@@ -85,3 +85,10 @@
   // CHECK-MESSAGES-NOT: [[@LINE-1]]:10: warning: use 'std::println' instead of 'myprintf' [modernize-use-std-print]
   // CHECK-FIXES-NOT: std::println(stderr, "return value {}", i);
 }
+
+// Ensure that MatchesAnyListedNameMatcher::NameMatcher::match() can cope with a
+// NamedDecl that has no name when we're trying to match unqualified_printf.
+void no_name(const std::string &in)
+{
+  "A" + in;
+}
Index: clang-tools-extra/clang-tidy/utils/Matchers.h
===
--- clang-tools-extra/clang-tidy/utils/Matchers.h
+++ clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -112,7 +112,9 @@
   case MatchMode::MatchFullyQualified:
 return Regex.match("::" + ND.getQualifiedNameAsString());
   default:
-return Regex.match(ND.getName());
+if (const IdentifierInfo *II = ND.getIdentifier())
+  return Regex.match(II->getName());
+return false;
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153114: [clangd] [C++20] [Modules] Support C++20 modules for clangd

2023-07-11 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@sammccall @nridge gentle ping~


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

https://reviews.llvm.org/D153114

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


[PATCH] D154884: [clang-tidy] Make MatchesAnyListedNameMatcher cope with unnamed Decl

2023-07-11 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

Thanks for the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154884

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


[clang] f82df0b - [C++20] [Modules] Use CanonicalType for base classes

2023-07-11 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-07-11T15:59:03+08:00
New Revision: f82df0b285acd8a7115f0bfc55ce44474251c2d1

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

LOG: [C++20] [Modules] Use CanonicalType for base classes

This comes from https://reviews.llvm.org/D153003

By @rsmith, the test case is valid since:

> Per [temp.type]/1.4 (http://eel.is/c++draft/temp.type#1.4),
>
>> Two template-ids are the same if [...] their corresponding template
>> template-arguments refer to the same template.
> so B and B are the same type. The stricter "same sequence of
> tokens" rule doesn't apply here, because using-declarations are not
> definitions.

> we should either (preferably) be including only the syntactic form of
> the base specifier (because local syntax is what the ODR covers), or
> the canonical type (which should be the same for both
> using-declarations).

Here we adopt the second suggested solutions.

Reviewed By: cor3ntin, v.g.vassilev

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

Added: 
clang/test/Modules/pr63595.cppm

Modified: 
clang/lib/AST/ODRHash.cpp

Removed: 




diff  --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp
index 507fb0b49f8ad3..40d68a310dd2a8 100644
--- a/clang/lib/AST/ODRHash.cpp
+++ b/clang/lib/AST/ODRHash.cpp
@@ -593,7 +593,7 @@ void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) 
{
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
   for (const auto &Base : Bases) {
-AddQualType(Base.getType());
+AddQualType(Base.getType().getCanonicalType());
 ID.AddInteger(Base.isVirtual());
 ID.AddInteger(Base.getAccessSpecifierAsWritten());
   }

diff  --git a/clang/test/Modules/pr63595.cppm b/clang/test/Modules/pr63595.cppm
new file mode 100644
index 00..f2caf629ac10b8
--- /dev/null
+++ b/clang/test/Modules/pr63595.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module1.cppm -o 
%t/module1.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module2.cppm -o 
%t/module2.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/merge.cpp -verify 
-fsyntax-only
+
+//--- header.h
+namespace NS {
+template 
+class A {
+};
+
+template  class T>
+class B {
+};
+}
+
+//--- module1.cppm
+// inside NS, using C = B
+module;
+export module module1;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- module2.cppm
+// inside NS, using C = B
+module;
+export module module2;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- merge.cpp
+// expected-no-diagnostics
+import module1;
+import module2;
+D d;



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


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang added inline comments.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:22-25
+  RN_T0 = 0xC,
+  RN_T1 = 0xD,
+  RN_RA = 0x1,
+  RN_SP = 0x3,

xen0n wrote:
> I think people usually just declare the register ABI names with decimal 
> numbers for readability?
> 
> This is minor but I personally find it slightly distracting to have to think 
> about what's `0xc` in decimal (that's the case even though I'm already very 
> familiar with these kinds of thing). Not sure if others also prefer decimals 
> though...
Ok,  use decimal numbers to declare the register ABI names.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:32
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rj << 5 | Rd | Imm << 10);
+}

xen0n wrote:
> Parens not needed in this case. (If you want to enhance readability for those 
> people having difficulties remembering precedence and associativeness of 
> operators, you should instead put the parens around `Rj << 5` and `Imm << 
> 10`...)
> 
> I'd suggest re-ordering the operands too, to imitate the expected bit layout 
> of the result.
What you said makes sense. Thanks for your suggestion and attentiveness. I have 
adjusted parens and operands order.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:39
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rd | Imm << 5);
+}

xen0n wrote:
> Similarly here.
Done.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:42-47
+// Encode instructions in 2RI16 format, e.g. jirl.
+inline static uint32_t
+encodeInstruction2RI16(uint32_t Opcode, uint32_t Rd, uint32_t Rj,
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rj << 5 | Rd | Imm << 10);
+}

xen0n wrote:
> Does this look *very* similar to `encodeInstruction2RI12`? ;-)
> 
> Actually, if you don't bounds-check the operands, you only need one helper 
> for each combination of slots involved. Check for example the `static 
> uint32_t insn` implementation in my D138135, or [[ 
> https://gitlab.com/qemu-project/qemu/-/blob/master/tcg/loongarch64/tcg-insn-defs.c.inc
>  | the auto-generated encoding helpers for the QEMU TCG LoongArch64 port ]], 
> for some alternative approaches.
It is indeed similar to `encodeInstruction2RI12`. Given its exclusive use in 
this context, I prefer the unified `2RIx` format.

Thanks for the suggestion. While we appreciate it, we are more inclined to use 
one `2RIx` format helper here.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:58
+  //   11 NOPs (44 bytes)
+  //   .tmpN
+  //

xen0n wrote:
> `.tmpN:` for it to not look like a directive?
Use the real `.Lxray_sled_endN`.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:71
+  //   ori t1, t1, %abs_lo12(function_id);pass function id
+  //   jirlra, t0, 0 ;call Tracing hook
+  //   ld.dra, sp, 8 ;restore return address

xen0n wrote:
> All-lowercase i.e. `tracing` for consistency? Or am I missing something?
It should be a copy from `mips`. I think it can be written `tracing hook` or 
`TracingHook`. To maintain all-lowercase consistency here, I use `tracing hook`.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:73
+  //   ld.dra, sp, 8 ;restore return address
+  //   addi.d  sp, sp, 16;delete stack frame
+  //

xen0n wrote:
> I think idiomatically it's not "create/delete stack frame" but rather 
> "(de-)allocate" or "setup/teardown"... anyway please fix the usage of 
> articles (put the "the"'s properly) and also add a space after the `;` 
> because it's usually aesthetically better.
> 
> This is all minor though, and it's not like people will misunderstand 
> anything otherwise, but rather it's mostly just me pushing for more natural 
> English usage.
Ok, a space after the `;`   is added.  About article `the`,  i also added it. 
But i am not sure whether the usage of `the` is proper. If  there are any 
further issues , I would greatly appreciate your feedback.

Thanks for your effort.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:80
+  //
+  // When |Enable|==false, we set back the first instruction in the sled to be
+  //   B #48

xen0n wrote:
> ("set back" happens to be an idiomatic phrase verb so I got confused here for 
> ~1 second, so I think it's probably easier to just avoid this coincidence.)
Done.



Comment at: compiler-rt/lib/xray/xray_trampoline_loongarch64.S:83
+  // a1=1 means that we are tracing an exit event
+  ori $a1, $zero, 1
+  // Function ID is in t1 (the first parameter).

xen0n wrote:
> Use pseudo-instruction for idiomatic expression of inten

[PATCH] D154324: [C++20] [Modules] [ODRHash] Use CanonicalType for base classes

2023-07-11 Thread Chuanqi Xu via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Changes 
Planned".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf82df0b285ac: [C++20] [Modules] Use CanonicalType for base 
classes (authored by ChuanqiXu).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154324

Files:
  clang/lib/AST/ODRHash.cpp
  clang/test/Modules/pr63595.cppm


Index: clang/test/Modules/pr63595.cppm
===
--- /dev/null
+++ clang/test/Modules/pr63595.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module1.cppm -o 
%t/module1.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module2.cppm -o 
%t/module2.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/merge.cpp -verify 
-fsyntax-only
+
+//--- header.h
+namespace NS {
+template 
+class A {
+};
+
+template  class T>
+class B {
+};
+}
+
+//--- module1.cppm
+// inside NS, using C = B
+module;
+export module module1;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- module2.cppm
+// inside NS, using C = B
+module;
+export module module2;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- merge.cpp
+// expected-no-diagnostics
+import module1;
+import module2;
+D d;
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -593,7 +593,7 @@
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
   for (const auto &Base : Bases) {
-AddQualType(Base.getType());
+AddQualType(Base.getType().getCanonicalType());
 ID.AddInteger(Base.isVirtual());
 ID.AddInteger(Base.getAccessSpecifierAsWritten());
   }


Index: clang/test/Modules/pr63595.cppm
===
--- /dev/null
+++ clang/test/Modules/pr63595.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module1.cppm -o %t/module1.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/module2.cppm -o %t/module2.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/merge.cpp -verify -fsyntax-only
+
+//--- header.h
+namespace NS {
+template 
+class A {
+};
+
+template  class T>
+class B {
+};
+}
+
+//--- module1.cppm
+// inside NS, using C = B
+module;
+export module module1;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- module2.cppm
+// inside NS, using C = B
+module;
+export module module2;
+#include "header.h"
+namespace NS {
+using C = B;
+}
+export struct D : NS::C {};
+
+//--- merge.cpp
+// expected-no-diagnostics
+import module1;
+import module2;
+D d;
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -593,7 +593,7 @@
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
   for (const auto &Base : Bases) {
-AddQualType(Base.getType());
+AddQualType(Base.getType().getCanonicalType());
 ID.AddInteger(Base.isVirtual());
 ID.AddInteger(Base.getAccessSpecifierAsWritten());
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang updated this revision to Diff 538948.
Ami-zhang added a comment.

Addressed @xen0n's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_loongarch64.cpp
  compiler-rt/lib/xray/xray_trampoline_loongarch64.S
  compiler-rt/lib/xray/xray_tsc.h
  compiler-rt/test/xray/TestCases/Posix/c-test.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-thread-order.cpp
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchSubtarget.h
  llvm/lib/XRay/InstrumentationMap.cpp
  llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
@@ -0,0 +1,56 @@
+; RUN: llc --mtriple=loongarch64 %s -o - | FileCheck %s
+; RUN: llc --mtriple=loongarch64 -filetype=obj %s -o %t
+; RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: foo:
+; CHECK-LABEL: .Lfunc_begin0:
+; CHECK:   .p2align 2
+; CHECK-LABEL: .Lxray_sled_begin0:
+; CHECK-NEXT:  b .Lxray_sled_end0
+; CHECK-COUNT-11:  nop
+; CHECK-LABEL: .Lxray_sled_end0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_begin1:
+; CHECK-NEXT:  b .Lxray_sled_end1
+; CHECK-COUNT-11:  nop
+; CHECK-NEXT: .Lxray_sled_end1:
+; CHECK-NEXT:  ret
+; CHECK-NEXT: .Lfunc_end0:
+}
+
+; CHECK-LABEL: .section xray_instr_map
+; CHECK-NEXT: .Lxray_sleds_start0:
+; CHECK-NEXT: .Ltmp0:
+; CHECK-NEXT: .dword .Lxray_sled_begin0-.Ltmp0
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp0+8)
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Ltmp1:
+; CHECK-NEXT: .dword .Lxray_sled_begin1-.Ltmp1
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp1+8)
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Lxray_sleds_end0:
+
+; CHECK-LABEL:  .section xray_fn_idx
+; CHECK-LABEL:  .Lxray_fn_idx0:
+; CHECK:  .dword .Lxray_sleds_start0-.Lxray_fn_idx0
+; CHECK-NEXT: .dword 2
+
+; RELOC:  Section ([[#]]) .relaxray_instr_map {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x8 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x20 R_LARCH_64_PCREL .text 0x34
+; RELOC-NEXT:   0x28 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .relaxray_fn_idx {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL xray_instr_map 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .rela.eh_frame {
+; RELOC-NEXT:   0x1C R_LARCH_32_PCREL .text 0x0
+; RELOC-NEXT: }
Index: llvm/lib/XRay/InstrumentationMap.cpp
===
--- llvm/lib/XRay/InstrumentationMap.cpp
+++ llvm/lib/XRay/InstrumentationMap.cpp
@@ -60,6 +60,7 @@
   // Find the section named "xray_instr_map".
   if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
   !(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
+ObjFile.getBinary()->getArch() == Triple::loongarch64 ||
 ObjFile.getBinary()->getArch() == Triple::ppc64le ||
 ObjFile.getBinary()->getArch() == Triple::arm ||
 ObjFile.getBinary()->getArch() == Triple::aarch64))
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.h
===
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -96,6 +96,7 @@
   MVT getGRLenVT() const { return GRLenVT; }
   unsigned getGRLen() const { return GRLen; }
   LoongArchABI::ABI getTargetABI() const { return TargetABI; }
+  bool isXRaySupported() const override { return is64Bit(); }
 };
 } // end namespace llvm
 
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
@@ -42,6 +42,9 @@
  const char *ExtraCode, raw_ostream &OS) override;
 
   void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
+  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
+  void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
+  void emitSled(const MachineInstr &MI, SledKind Kind);
 
   // tblgen'erated function.
   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
===
--- ll

[PATCH] D154853: [clangd][c++20]Consider the constraint of a constrained auto in FindTarget.

2023-07-11 Thread Jens Massberg via Phabricator via cfe-commits
massberg updated this revision to Diff 538952.
massberg added a comment.

clang-format code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154853

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -487,6 +487,46 @@
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "int";
}},
+  // constraint of constrained auto
+  {R"cpp(
+template  concept Fooable = true;
+[[Foo^able]] auto x = 1;
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \n"
+ "concept Fooable = true";
+   }},
+  {R"cpp(
+template  concept Fooable = true;
+template<[[Fooa^ble]] auto x> void Foo() {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \n"
+ "concept Fooable = true";
+   }},
+  // concept
+  {R"cpp(
+template 
+concept Fooable = requires (T t) { t.foo(); };
+
+template  requires [[Fo^oable]]
+void bar(T t) {
+  t.foo();
+}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \n"
+ "concept Fooable = requires(T t) { t.foo(); }";
+   }},
   // auto on lambda
   {R"cpp(
 void foo() {
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -572,6 +572,23 @@
   )cpp";
   EXPECT_DECLS("ConceptSpecializationExpr",
{"template  concept Fooable = true"});
+
+  // Constrained auto
+  Code = R"cpp(
+template 
+concept Fooable = true;
+
+[[Fooable]] auto i = 42;
+  )cpp";
+  EXPECT_DECLS("AutoTypeLoc", {"template  concept Fooable = 
true"});
+
+  Code = R"cpp(
+template 
+concept Fooable = true;
+
+template<[[Fooable]] auto x> void Foo() {}
+  )cpp";
+  EXPECT_DECLS("AutoTypeLoc", {"template  concept Fooable = 
true"});
 }
 
 TEST_F(TargetDeclTest, Coroutine) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -471,6 +471,12 @@
   void VisitObjCInterfaceType(const ObjCInterfaceType *OIT) {
 Outer.add(OIT->getDecl(), Flags);
   }
+  void VisitAutoType(const AutoType *T) {
+if (T->isConstrained()) {
+  Outer.add(T->getTypeConstraintConcept(), Flags);
+}
+TypeVisitor::VisitAutoType(T);
+  }
 };
 Visitor(*this, Flags).Visit(T.getTypePtr());
   }


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -487,6 +487,46 @@
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "int";
}},
+  // constraint of constrained auto
+  {R"cpp(
+template  concept Fooable = true;
+[[Foo^able]] auto x = 1;
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \n"
+ "concept Fooable = true";
+   }},
+  {R"cpp(
+template  concept Fooable = true;
+template<[[Fooa^ble]] auto x> void Foo() {}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template \n"
+ "concept Fooable = true";
+   }},
+  // concept
+  {R"cpp(
+template 
+concept Fooable = requires (T t) { t.foo(); };
+
+template  requires [[Fo^oable]]
+void bar(T t) {
+  t.foo();
+}
+)cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "Fooable";
+ HI.Kind = index::SymbolKind::Concept;
+ HI.Definition = "template

[PATCH] D154928: [clang][Interp] Call dtor or Floating values

2023-07-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  The APFloat might heap-allocate some memory, so we need to call its
  destructor.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154928

Files:
  clang/lib/AST/Interp/Descriptor.cpp
  clang/test/AST/Interp/floats.cpp


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -137,3 +137,7 @@
   constexpr A b{12};
   static_assert(a.f == 0.0, "");
 };
+
+namespace LongDouble {
+  constexpr long double ld = 3.1425926539;
+}
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -189,6 +189,11 @@
 }
 
 static BlockDtorFn getDtorPrim(PrimType Type) {
+  // Floating types are special. They are primitives, but need their
+  // destructor called, since they might allocate memory.
+  if (Type == PT_Float)
+return dtorTy::T>;
+
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }
 


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -137,3 +137,7 @@
   constexpr A b{12};
   static_assert(a.f == 0.0, "");
 };
+
+namespace LongDouble {
+  constexpr long double ld = 3.1425926539;
+}
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -189,6 +189,11 @@
 }
 
 static BlockDtorFn getDtorPrim(PrimType Type) {
+  // Floating types are special. They are primitives, but need their
+  // destructor called, since they might allocate memory.
+  if (Type == PT_Float)
+return dtorTy::T>;
+
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 74258f4 - [C++20] [Modules] Allow Stmt::Profile to treat lambdas as equal conditionally

2023-07-11 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-07-11T16:13:06+08:00
New Revision: 74258f4189e2b6bacabd40ee6f588fd9d1b37741

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

LOG: [C++20] [Modules] Allow Stmt::Profile to treat lambdas as equal 
conditionally

Close https://github.com/llvm/llvm-project/issues/63544.

Background: We landed std modules in libcxx recently but we haven't
landed the corresponding in-tree tests. According to @Mordante, there
are only 1% libcxx tests failing with std modules. And the major
blocking issue is the lambda expression in the require clauses.

The root cause of the issue is that previously we never consider any
lambda expression as the same. Per [temp.over.link]p5:
> Two lambda-expressions are never considered equivalent.

I thought this is an oversight at first but @rsmith explains that in the
wording, the program is as if there is only a single definition, and a
single lambda-expression. So we don't need worry about this in the spec.
The explanation makes sense. But it didn't reflect to the implementation
directly.

Here is a cycle in the implementation. If we want to merge two
definitions, we need to make sure its implementation are the same. But
according to the explanation above, we need to judge if two
lambda-expression are the same by looking at its parent definitions. So
here is the problem.

To solve the problem, I think we have to profile the lambda expressions
actually to get the accurate information. But we can't do this
universally. So in this patch I tried to modify the interface of
`Stmt::Profile` and only profile the lambda expression during the
process of merging the constraint expressions.

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

Added: 
clang/test/Modules/merge-requires-with-lambdas.cppm
clang/test/Modules/pr63544.cppm

Modified: 
clang/include/clang/AST/Stmt.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/StmtProfile.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 9a77f876c08ae7..156dd0a436a900 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1297,8 +1297,13 @@ class alignas(void *) Stmt {
   /// parameters are identified by index/level rather than their
   /// declaration pointers) or the exact representation of the statement as
   /// written in the source.
+  /// \param ProfileLambdaExpr whether or not to profile lambda expressions.
+  /// When false, the lambda expressions are never considered to be equal to
+  /// other lambda expressions. When true, the lambda expressions with the same
+  /// implementation will be considered to be the same. ProfileLambdaExpr 
should
+  /// only be true when we try to merge two declarations within modules.
   void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
-   bool Canonical) const;
+   bool Canonical, bool ProfileLambdaExpr = false) const;
 
   /// Calculate a unique representation for a statement that is
   /// stable across compiler invocations.

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 2b84673cf6b8fc..7acacd7bf4f504 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6328,8 +6328,8 @@ bool ASTContext::isSameConstraintExpr(const Expr *XCE, 
const Expr *YCE) const {
 return true;
 
   llvm::FoldingSetNodeID XCEID, YCEID;
-  XCE->Profile(XCEID, *this, /*Canonical=*/true);
-  YCE->Profile(YCEID, *this, /*Canonical=*/true);
+  XCE->Profile(XCEID, *this, /*Canonical=*/true, /*ProfileLambdaExpr=*/true);
+  YCE->Profile(YCEID, *this, /*Canonical=*/true, /*ProfileLambdaExpr=*/true);
   return XCEID == YCEID;
 }
 
@@ -6694,13 +6694,8 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const 
NamedDecl *Y) const {
 // ConceptDecl wouldn't be the same if their constraint expression 
diff ers.
 if (const auto *ConceptX = dyn_cast(X)) {
   const auto *ConceptY = cast(Y);
-  const Expr *XCE = ConceptX->getConstraintExpr();
-  const Expr *YCE = ConceptY->getConstraintExpr();
-  assert(XCE && YCE && "ConceptDecl without constraint expression?");
-  llvm::FoldingSetNodeID XID, YID;
-  XCE->Profile(XID, *this, /*Canonical=*/true);
-  YCE->Profile(YID, *this, /*Canonical=*/true);
-  if (XID != YID)
+  if (!isSameConstraintExpr(ConceptX->getConstraintExpr(),
+ConceptY->getConstraintExpr()))
 return false;
 }
 

diff  --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index a9c4e14e87eff3..307ad4925d36b7 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -29,10 +29,12 @@ namespace {
   protected:
 llvm::FoldingSetNodeID &ID;
 bool Canonical;
+

[PATCH] D153957: [C++20] [Modules] Allow Stmt::Profile to treat lambdas as equal conditionally

2023-07-11 Thread Chuanqi Xu via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG74258f4189e2: [C++20] [Modules] Allow Stmt::Profile to treat 
lambdas as equal conditionally (authored by ChuanqiXu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153957

Files:
  clang/include/clang/AST/Stmt.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/test/Modules/merge-requires-with-lambdas.cppm
  clang/test/Modules/pr63544.cppm

Index: clang/test/Modules/pr63544.cppm
===
--- /dev/null
+++ clang/test/Modules/pr63544.cppm
@@ -0,0 +1,88 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++23 %t/a.cppm -emit-module-interface -o %t/m-a.pcm
+// RUN: %clang_cc1 -std=c++23 %t/b.cppm -emit-module-interface -o %t/m-b.pcm
+// RUN: %clang_cc1 -std=c++23 %t/m.cppm -emit-module-interface -o %t/m.pcm \
+// RUN: -fprebuilt-module-path=%t
+// RUN: %clang_cc1 -std=c++23 %t/pr63544.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+
+//--- foo.h
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+namespace std {
+template 
+class optional {
+private:
+using value_type = _Tp;
+value_type __val_;
+bool __engaged_;
+public:
+constexpr bool has_value() const noexcept
+{
+return this->__engaged_;
+}
+
+constexpr const value_type& operator*() const& noexcept
+{
+return __val_;
+}
+
+optional(_Tp v) : __val_(v) {
+__engaged_ = true;
+}
+};
+
+template 
+concept __is_derived_from_optional = requires(const _Tp& __t) { [](const optional<__Up>&) {}(__t); };
+
+template 
+requires(!__is_derived_from_optional<_Up>)
+constexpr strong_ordering
+operator<=>(const optional<_Tp>& __x, const _Up& __v) {
+return __x.has_value() ? *__x <=> __v : strong_ordering::less;
+}
+} // namespace std
+
+//--- a.cppm
+module;
+#include "foo.h"
+export module m:a;
+export namespace std {
+using std::optional;
+using std::operator<=>;
+}
+
+//--- b.cppm
+module;
+#include "foo.h"
+export module m:b;
+export namespace std {
+using std::optional;
+using std::operator<=>;
+}
+
+//--- m.cppm
+export module m;
+export import :a;
+export import :b;
+
+//--- pr63544.cpp
+// expected-no-diagnostics
+import m;
+int pr63544() {
+std::optional a(43);
+int t{3};
+return a<=>t;
+}
Index: clang/test/Modules/merge-requires-with-lambdas.cppm
===
--- /dev/null
+++ clang/test/Modules/merge-requires-with-lambdas.cppm
@@ -0,0 +1,100 @@
+// Tests that we can merge the concept declarations with lambda well.
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/A0.cppm -emit-module-interface -o %t/A0.pcm
+// RUN: %clang_cc1 -std=c++20 %t/TestA.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+//
+// RUN: %clang_cc1 -std=c++20 %t/A1.cppm -emit-module-interface -o %t/A1.pcm
+// RUN: %clang_cc1 -std=c++20 %t/TestA1.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+//
+// RUN: %clang_cc1 -std=c++20 %t/A2.cppm -emit-module-interface -o %t/A2.pcm
+// RUN: %clang_cc1 -std=c++20 %t/TestA2.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+//
+// RUN: %clang_cc1 -std=c++20 %t/A3.cppm -emit-module-interface -o %t/A3.pcm
+// RUN: %clang_cc1 -std=c++20 %t/TestA3.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+
+//--- A.h
+template 
+concept A = requires(const _Tp& __t) { [](const __Up&) {}(__t); };
+
+//--- A1.h
+template 
+concept A = requires(const _Tp& __t) { [](__Up) {}(__t); };
+
+//--- A2.h
+template 
+concept A = requires(const _Tp& __t) { [](const __Up& __u) {
+(int)__u;
+}(__t); };
+
+//--- A3.h
+template 
+concept A = requires(const _Tp& __t) { [t = '?'](const __Up&) {
+(int)t;
+}(__t); };
+
+//--- A.cppm
+module;
+#include "A.h"
+export module A;
+export using ::A;
+
+//--- A0.cppm
+module;
+#include "A.h"
+export module A0;
+export using ::A;
+
+//--- TestA.cpp
+// expected-no-diagnostics
+import A;
+import A0;
+
+template 
+void f(C) requires(A) {}
+
+//--- A1.cppm
+module;
+#include "A1.h"
+export module A1;
+export using ::A;
+
+//--- TestA1.cpp
+import A;
+import A1;
+
+template 
+void f(C) requires(A) {} // expected-error 1+{{reference to 'A' is ambiguous}}
+// expected-note@

[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.
This revision is now accepted and ready to land.

Thanks for following up with the suggestions. This now looks mostly okay to me; 
let's wait for more people to chip in!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

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


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

Ah, the patch summary probably needs some update as well. We no longer care 
about version 0 and the backend changes for `R_LARCH_64_PCREL` are already in, 
for example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

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


[PATCH] D154709: [clang][ASTImporter] Add a 'Message' member to ASTImportError and use it throughout ASTImporter

2023-07-11 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

In D154709#4487776 , @balazske wrote:

> The goal is to have a message always in `ASTImportError`? Then probably the 
> constructor without message can be removed, at least to check if really the 
> message is added at all places. I found that it is missing in 
> `VisitObjCImplementationDecl`.

Agree, will do that

> I do not know what happens with messages passed to FromDiag or ToDiag and if 
> these are available somehow to LLDB.

Ideally yes, but I found they're not very helpful in LLDB's use-case because:

1. the diagnostic doesn't get issued at all call-sites
2. LLDB switches off any `odr` related warnings because AFAIU they occur a lot 
(outside the ASTImporter) and would flood the user with redundant information

> Otherwise it would be even better to remove all FromDiag and ToDiag messages 
> from ASTImporter and put these messages into ASTImportError and use later in 
> the way that is needed by the use case. This would require to pass a message 
> to HandleNameConflict but then we have always the detailed message. There are 
> places where diagnostic is generated but there is no error, we should check 
> if this is correct and if we can remove the diagnostic or make import error.

That sounds like a good way forward. The `-ast-merge` clang option does benefit 
from these diagnostics. So we would probably need to change it to dump the 
`ASTImportError` instead of relying on the diagnostics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154709

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


[PATCH] D154910: [ARM][AArch64] Make ACLE __clzl/__clzll return unsigned int instead of unsigned long/uint64_t.

2023-07-11 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson accepted this revision.
tmatheson added a comment.
This revision is now accepted and ready to land.

LGTM, thanks. Seems odd that the ACLE mixes `uint32_t` and `unsigned int`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154910

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


[PATCH] D154856: [MemProf] Use new option/pass for profile feedback and matching

2023-07-11 Thread Jan-Patrick Lehr via Phabricator via cfe-commits
jplehr added a comment.

The preparation patch (https://reviews.llvm.org/D154872) caused the AMD GPU 
OpenMP buildbot to fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154856

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


[clang] 133b2fc - [clang][Interp][NFC] Use template types instead of auto

2023-07-11 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-11T11:25:00+02:00
New Revision: 133b2fc9cc27d03f3f5f922ec7f058c3b617a1ea

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

LOG: [clang][Interp][NFC] Use template types instead of auto

Added: 


Modified: 
clang/lib/AST/Interp/InterpStack.h

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpStack.h 
b/clang/lib/AST/Interp/InterpStack.h
index fa2f9d5b242de9..e61d8e6dc7daf6 100644
--- a/clang/lib/AST/Interp/InterpStack.h
+++ b/clang/lib/AST/Interp/InterpStack.h
@@ -44,8 +44,8 @@ class InterpStack final {
 assert(ItemTypes.back() == toPrimType());
 ItemTypes.pop_back();
 #endif
-auto *Ptr = &peekInternal();
-auto Value = std::move(*Ptr);
+T *Ptr = &peekInternal();
+T Value = std::move(*Ptr);
 Ptr->~T();
 shrink(aligned_size());
 return Value;
@@ -57,7 +57,7 @@ class InterpStack final {
 assert(ItemTypes.back() == toPrimType());
 ItemTypes.pop_back();
 #endif
-auto *Ptr = &peekInternal();
+T *Ptr = &peekInternal();
 Ptr->~T();
 shrink(aligned_size());
   }



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


[PATCH] D154934: [clang][dataflow] Use `IntegerValue` instead of `StructValue` in `ValueTest`.

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Soon, it will no longer be possible to default-construct `StructValue`.
For details, see https://discourse.llvm.org/t/70086.

For completeness, also add a test that `areEquivalentValues()` on different
`IntegerValue`s returns false.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154934

Files:
  clang/unittests/Analysis/FlowSensitive/ValueTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
@@ -19,10 +19,16 @@
 using namespace dataflow;
 
 TEST(ValueTest, EquivalenceReflexive) {
-  StructValue V;
+  IntegerValue V;
   EXPECT_TRUE(areEquivalentValues(V, V));
 }
 
+TEST(ValueTest, DifferentIntegerValuesNotEquivalent) {
+  IntegerValue V1;
+  IntegerValue V2;
+  EXPECT_FALSE(areEquivalentValues(V1, V2));
+}
+
 TEST(ValueTest, AliasedReferencesEquivalent) {
   auto L = ScalarStorageLocation(QualType());
   ReferenceValue V1(L);


Index: clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/ValueTest.cpp
@@ -19,10 +19,16 @@
 using namespace dataflow;
 
 TEST(ValueTest, EquivalenceReflexive) {
-  StructValue V;
+  IntegerValue V;
   EXPECT_TRUE(areEquivalentValues(V, V));
 }
 
+TEST(ValueTest, DifferentIntegerValuesNotEquivalent) {
+  IntegerValue V1;
+  IntegerValue V2;
+  EXPECT_FALSE(areEquivalentValues(V1, V2));
+}
+
 TEST(ValueTest, AliasedReferencesEquivalent) {
   auto L = ScalarStorageLocation(QualType());
   ReferenceValue V1(L);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154935: [clang][dataflow] Introduce `getFieldValue()` test helpers.

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

These insulate tests against changes to the `getChild()` functions of
`AggregateStorageLocation` and `StructValue` that will happen as part of the
migration to strict handling of value categories (see
https://discourse.llvm.org/t/70086 for details):

- `AggregateStorageLocation::getChild()` will soon return a `StorageLocation *` 
instead of a `StorageLocation &`. When this happens, `getFieldValue()` will be 
changed to return null if `AggregateStorageLocation::getChild()` returns null; 
test code will not need to change as it should already be checking whether the 
return value of `getFieldValue()` is null.

- `StructValue::getChild()` will soon return a `StorageLocation *` instead of a 
`Value *`. When this happens, `getFieldValue()` will be changed to look up the 
`Value *` in the `Environment`. Again, test code will not need to change.

The test helpers will continue to serve a useful purpose once the API changes
are complete, so the intent is to leave them in place.

This patch changes DataflowEnvironmentTest.cpp and RecordOpsTest.cpp to use the
test helpers. TransferTest.cpp will be changed in an upcoming patch to help keep
patch sizes manageable for review.

Depends On D154934 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154935

Files:
  clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
  clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -451,6 +451,28 @@
   return *cast(Env.getValue(*VD));
 }
 
+/// Returns the value of a `Field` on the record referenced by `Loc.`
+/// Returns null if `Loc` is null.
+inline Value *getFieldValue(const AggregateStorageLocation *Loc,
+const ValueDecl &Field, const Environment &Env) {
+  if (Loc == nullptr)
+return nullptr;
+  return Env.getValue(Loc->getChild(Field));
+}
+
+/// Returns the value of a `Field` on a `Struct.
+/// Returns null if `Struct` is null.
+///
+/// Note: This function currently does not use the `Env` parameter, but it will
+/// soon be needed to look up the `Value` when `setChild()` changes to return a
+/// `StorageLocation *`.
+inline Value *getFieldValue(const StructValue *Struct, const ValueDecl &Field,
+const Environment &Env) {
+  if (Struct == nullptr)
+return nullptr;
+  return Struct->getChild(Field);
+}
+
 /// Creates and owns constraints which are boolean values.
 class ConstraintContext {
   unsigned NextAtom = 0;
Index: clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
@@ -63,12 +63,12 @@
 auto &Inner1 = cast(S1.getChild(*InnerDecl));
 auto &Inner2 = cast(S2.getChild(*InnerDecl));
 
-EXPECT_NE(Env.getValue(S1.getChild(*OuterIntDecl)),
-  Env.getValue(S2.getChild(*OuterIntDecl)));
+EXPECT_NE(getFieldValue(&S1, *OuterIntDecl, Env),
+  getFieldValue(&S2, *OuterIntDecl, Env));
 EXPECT_NE(Env.getValue(S1.getChild(*RefDecl)),
   Env.getValue(S2.getChild(*RefDecl)));
-EXPECT_NE(Env.getValue(Inner1.getChild(*InnerIntDecl)),
-  Env.getValue(Inner2.getChild(*InnerIntDecl)));
+EXPECT_NE(getFieldValue(&Inner1, *InnerIntDecl, Env),
+  getFieldValue(&Inner2, *InnerIntDecl, Env));
 
 auto *S1Val = cast(Env.getValue(S1));
 auto *S2Val = cast(Env.getValue(S2));
@@ -78,12 +78,12 @@
 
 copyRecord(S1, S2, Env);
 
-EXPECT_EQ(Env.getValue(S1.getChild(*OuterIntDecl)),
-  Env.getValue(S2.getChild(*OuterIntDecl)));
+EXPECT_EQ(getFieldValue(&S1, *OuterIntDecl, Env),
+  getFieldValue(&S2, *OuterIntDecl, Env));
 EXPECT_EQ(Env.getValue(S1.getChild(*RefDecl)),
   Env.getValue(S2.getChild(*RefDecl)));
-EXPECT_EQ(Env.getValue(Inner1.getChild(*InnerIntDecl)),
-  Env.getValue(Inner2.getChild(*InnerIntDecl)));
+EXPECT_EQ(getFieldValue(&Inner1, *InnerIntDecl, Env),
+  getFieldValue(&Inner2, *InnerIntDecl, Env));
 
 S1Val = cast(Env.getValue(S1));
 S2Val = cast(Env.getValue(S2));
Index: clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp

[PATCH] D154471: [clang] Add serialization support for the DynamicAllocLValue variant of APValue::LValueBase::Ptr

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

I believe the fix is correct.

Though the fix has been verified by a real-world example, I think it would be 
nice to get a reproducible testcase. Looking at the stacktrace:

- the crash occurs during the pch deserialization
- and we miss handling the case where LValue base is a `DynamicAllocLValue`

so it looks like we can construct a `DynamicAllocLValue` case, and try to 
deserialize it (e.g. emitting a pch), and it should reproduce the crash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154471

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


[PATCH] D146054: [RISCV] Add --print-supported-extensions support

2023-07-11 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat marked an inline comment as done.
4vtomat added a comment.

@MaskRay if you are available, please help me to check the revision, thanks!!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146054

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


[PATCH] D154935: [clang][dataflow] Introduce `getFieldValue()` test helpers.

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added inline comments.



Comment at: 
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp:95
-  StructValue *SVal = clang::dyn_cast(Val);
-  ASSERT_NE(SVal, nullptr);
-  Val = SVal->getChild(*R);

Using the opportunity to simplify the code here a bit: If we `cast<>`, we don't 
need to assert for non-nullness because `cast<>` already does that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154935

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


[clang] 3ab7ef2 - Revert "[MemProf] Use new option/pass for profile feedback and matching"

2023-07-11 Thread JP Lehr via cfe-commits

Author: JP Lehr
Date: 2023-07-11T05:44:42-04:00
New Revision: 3ab7ef28eebf9019eb3d3c4efd7ebfd160106bb1

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

LOG: Revert "[MemProf] Use new option/pass for profile feedback and matching"

This reverts commit b4a82b62258c5f650a1cccf5b179933e6bae4867.

Broke AMDGPU OpenMP Offload buildbot

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/memprof.cpp
clang/test/Driver/fmemprof.cpp
llvm/include/llvm/Support/PGOOptions.h
llvm/include/llvm/Transforms/Instrumentation/MemProfiler.h
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Support/PGOOptions.cpp
llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/test/Transforms/PGOProfile/memprof.ll
llvm/test/Transforms/PGOProfile/memprofmissingfunc.ll
llvm/tools/opt/NewPMDriver.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index fadfff48582eea..b0f22411e1ad20 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -282,9 +282,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Name of the profile file to use as output for with -fmemory-profile.
   std::string MemoryProfileOutput;
 
-  /// Name of the profile file to use as input for -fmemory-profile-use.
-  std::string MemoryProfileUsePath;
-
   /// Name of the profile file to use as input for -fprofile-instr-use
   std::string ProfileInstrumentUsePath;
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c5230d11baeddf..a34eab4064997a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1772,10 +1772,6 @@ defm memory_profile : OptInCC1FFlag<"memory-profile", 
"Enable", "Disable", " hea
 def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">,
 Group, Flags<[CC1Option]>, MetaVarName<"">,
 HelpText<"Enable heap memory profiling and dump results into ">;
-def fmemory_profile_use_EQ : Joined<["-"], "fmemory-profile-use=">,
-Group, Flags<[CC1Option, CoreOption]>, MetaVarName<"">,
-HelpText<"Use memory profile for profile-guided memory optimization">,
-MarshallingInfoString>;
 
 // Begin sanitizer flags. These should all be core options exposed in all 
driver
 // modes.

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 06af08023d1be9..458756509b3a3d 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -762,37 +762,31 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 PGOOpt = PGOOptions(
 CodeGenOpts.InstrProfileOutput.empty() ? getDefaultProfileGenName()
: 
CodeGenOpts.InstrProfileOutput,
-"", "", CodeGenOpts.MemoryProfileUsePath, nullptr, PGOOptions::IRInstr,
-PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling);
+"", "", nullptr, PGOOptions::IRInstr, PGOOptions::NoCSAction,
+CodeGenOpts.DebugInfoForProfiling);
   else if (CodeGenOpts.hasProfileIRUse()) {
 // -fprofile-use.
 auto CSAction = CodeGenOpts.hasProfileCSIRUse() ? PGOOptions::CSIRUse
 : PGOOptions::NoCSAction;
-PGOOpt = PGOOptions(
-CodeGenOpts.ProfileInstrumentUsePath, "",
-CodeGenOpts.ProfileRemappingFile, CodeGenOpts.MemoryProfileUsePath, 
VFS,
-PGOOptions::IRUse, CSAction, CodeGenOpts.DebugInfoForProfiling);
+PGOOpt =
+PGOOptions(CodeGenOpts.ProfileInstrumentUsePath, "",
+   CodeGenOpts.ProfileRemappingFile, VFS, PGOOptions::IRUse,
+   CSAction, CodeGenOpts.DebugInfoForProfiling);
   } else if (!CodeGenOpts.SampleProfileFile.empty())
 // -fprofile-sample-use
 PGOOpt = PGOOptions(
 CodeGenOpts.SampleProfileFile, "", CodeGenOpts.ProfileRemappingFile,
-CodeGenOpts.MemoryProfileUsePath, VFS, PGOOptions::SampleUse,
-PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling,
-CodeGenOpts.PseudoProbeForProfiling);
-  else if (!CodeGenOpts.MemoryProfileUsePath.empty())
-// -fmemory-profile-use (without any of the above options)
-PGOOpt = PGOOptions("", "", "", CodeGenOpts.MemoryProfileUsePath, VFS,
-PGOOptions::NoAction, PGOOptions::NoCSAction,
-CodeGenOpts.DebugInfoForProfiling);
+

[PATCH] D144943: [clang][Interp] Implement bitcasts (WIP)

2023-07-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

I'm gonna close this, since the new approach is too different.


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

https://reviews.llvm.org/D144943

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


[PATCH] D149013: [clang][Interp] Check pointers when accessing base class

2023-07-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149013

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


[PATCH] D154471: [clang] Add serialization support for the DynamicAllocLValue variant of APValue::LValueBase::Ptr

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

I gave it a try, here is a testcase that triggers the crash

  // clang -cc1 -emit-pch -o /tmp/t.pch /tmp/t.cpp
  #ifndef HEADER
  #define HEADER
  
  struct A {  int *p; };
  const A &w = A{ new int(10) };
  
  #endif


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154471

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


[PATCH] D41416: [modules] [pch] Do not deserialize all lazy template specializations when looking for one.

2023-07-11 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In D41416#4487516 , @ChuanqiXu wrote:

> But some local in tree tests got failed. I took some time to investigate them 
> but I didn't get insights :  (

If the failures involve template template parameters, please note that you need 
https://reviews.llvm.org/D153003 for that to properly hash and find in the list 
of lazy specializations.




Comment at: clang/lib/AST/DeclTemplate.cpp:366
+  Args,
+  TemplateParameterList 
*TPL) const {
+  CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr();

ChuanqiXu wrote:
> TPL here looks not used.
This is required because of the argument forwarding from 
`findSpecializationImpl` below...


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

https://reviews.llvm.org/D41416

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


[PATCH] D154931: [LoongArch] Support InlineAsm for LSX and LASX

2023-07-11 Thread 陈荔 via Phabricator via cfe-commits
leecheechen created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
leecheechen added reviewers: xen0n, xry111, hev, gonglingqin, SixWeining, 
wangleiat.
leecheechen published this revision for review.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

The author of the following files is licongtian :

- clang/lib/Basic/Targets/LoongArch.cpp
- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
- llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

The files mentioned above implement InlineAsm for LSX and LASX as follows:

- Enable clang parsing LSX/LASX register name, such as $vr0.
- Support the case which operand type is 128bit or 256bit when the constraints 
is 'f'.
- Support the way of specifying LSX/LASX register by using constraint, such as 
"={$xr0}".
- Support the operand modifiers 'u' and 'w'.
- Support and legalize the data types and register classes involved in LSX/LASX 
in the lowering process.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154931

Files:
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/test/CodeGen/LoongArch/lasx/inline-asm-gcc-regs-error.c
  clang/test/CodeGen/LoongArch/lasx/inline-asm-gcc-regs.c
  clang/test/CodeGen/LoongArch/lasx/inline-asm-operand-modifier.c
  clang/test/CodeGen/LoongArch/lsx/inline-asm-gcc-regs-error.c
  clang/test/CodeGen/LoongArch/lsx/inline-asm-gcc-regs.c
  clang/test/CodeGen/LoongArch/lsx/inline-asm-operand-modifier.c
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/test/CodeGen/LoongArch/lasx/inline-asm-operand-modifier.ll
  llvm/test/CodeGen/LoongArch/lasx/inline-asm-reg-names.ll
  llvm/test/CodeGen/LoongArch/lsx/inline-asm-operand-modifier.ll
  llvm/test/CodeGen/LoongArch/lsx/inline-asm-reg-names.ll

Index: llvm/test/CodeGen/LoongArch/lsx/inline-asm-reg-names.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/lsx/inline-asm-reg-names.ll
@@ -0,0 +1,58 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc --mtriple=loongarch64 --mattr=+lsx < %s | FileCheck %s
+
+define void @register_vr1() nounwind {
+; CHECK-LABEL: register_vr1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:#APP
+; CHECK-NEXT:vldi $vr1, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call <2 x i64> asm sideeffect "vldi ${0:w}, 1", "={$vr1}"()
+  ret void
+}
+
+define void @register_vr7() nounwind {
+; CHECK-LABEL: register_vr7:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:#APP
+; CHECK-NEXT:vldi $vr7, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call <2 x i64> asm sideeffect "vldi ${0:w}, 1", "={$vr7}"()
+  ret void
+}
+
+define void @register_vr23() nounwind {
+; CHECK-LABEL: register_vr23:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:#APP
+; CHECK-NEXT:vldi $vr23, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call <2 x i64> asm sideeffect "vldi ${0:w}, 1", "={$vr23}"()
+  ret void
+}
+
+;; The lower half of the vector register '$vr31' is same as the
+;; floating-point register '$f31'. And '$f31' is a callee-saved
+;; register which is preserved across calls. That's why the
+;; fst.d and fld.d instructions are emitted.
+define void @register_vr31() nounwind {
+; CHECK-LABEL: register_vr31:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:addi.d $sp, $sp, -16
+; CHECK-NEXT:fst.d $fs7, $sp, 8 # 8-byte Folded Spill
+; CHECK-NEXT:#APP
+; CHECK-NEXT:vldi $vr31, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:fld.d $fs7, $sp, 8 # 8-byte Folded Reload
+; CHECK-NEXT:addi.d $sp, $sp, 16
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call <2 x i64> asm sideeffect "vldi ${0:w}, 1", "={$vr31}"()
+  ret void
+}
Index: llvm/test/CodeGen/LoongArch/lsx/inline-asm-operand-modifier.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/lsx/inline-asm-operand-modifier.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc --mtriple=loongarch64 --mattr=+lsx < %s | FileCheck %s
+
+define void @test_w() nounwind {
+; CHECK-LABEL: test_w:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:#APP
+; CHECK-NEXT:vldi $vr0, 1
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call <2 x i64> asm sideeffect "vldi ${0:w}, 1", "=f"()
+  ret void
+}
Index: llvm/test/CodeGen/LoongArch/lasx/inline-asm-reg-names.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/lasx/inline-asm-reg-names.ll
@@ -0,0 +1,58 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc --mtriple=loongarch64 --mattr=+lasx < %s | FileCheck %s
+
+define void @register_xr

[PATCH] D154893: [Clang] Fix some triviality computations

2023-07-11 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

This is a bit confusing but I think it is correct.
LGTM modulo typos.




Comment at: clang/docs/ReleaseNotes.rst:70
 ---
-- A bug in evaluating the ineligibility of some special member functions has 
been fixed. This can
-  make some classes trivially copyable that were not trivially copyable 
before. (`#62555 `_)
+- Two bug in evaluating the ineligibility of some special member functions has 
been fixed. This can
+  make some classes trivially copyable that were not trivially copyable before.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154893

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


[PATCH] D154948: [dataflow] improve determinism of generated SAT system

2023-07-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: ymandel, xazax.hun.
Herald added subscribers: ChuanqiXu, martong, mgrang.
Herald added a reviewer: NoQ.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes two places where we relied on map iteration order when processing
values, which leaked nondeterminism into the generated SAT formulas.
Adds a couple of tests that directly assert that the SAT system is
equivalent on each run.

It's desirable that the formulas are deterministic based on the input:

- our SAT solver is naive and perfermance is sensitive to even simple 
semantics-preserving transformations like A|B to B|A. (e.g. it's likely to 
choose a different variable to split on). Timeout failures are bad, but *flaky* 
ones are terrible to debug.
- similarly when debugging, it's important to have a consistent understanding 
of what e.g. "V23" means across runs.

---

Both changes in this patch were isolated from a nullability analysis of
real-world code which was extremely slow, spending ages in the SAT
solver at "random" points that varied on each run.
I've included a reduced version of the code as a regression test.

One of the changes shows up directly as flow-condition nondeterminism
with a no-op analysis, the other relied on bits of the nullability
analysis but I found a synthetic example to show the problem.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154948

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/DeterminismTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DeterminismTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/DeterminismTest.cpp
@@ -0,0 +1,137 @@
+//===- unittests/Analysis/FlowSensitive/DeterminismTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestingSupport.h"
+#include "clang/AST/Decl.h"
+#include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
+#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/Formula.h"
+#include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
+#include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace clang::dataflow {
+
+// Run a no-op analysis, and return a textual representation of the
+// flow-condition at function exit.
+std::string analyzeAndPrintExitCondition(llvm::StringRef Code) {
+  DataflowAnalysisContext DACtx(std::make_unique());
+  clang::TestAST AST(Code);
+  const auto *Target =
+  cast(test::findValueDecl(AST.context(), "target"));
+  Environment InitEnv(DACtx, *Target);
+  auto CFCtx = cantFail(ControlFlowContext::build(*Target));
+
+  NoopAnalysis Analysis(AST.context(), DataflowAnalysisOptions{});
+
+  auto Result = runDataflowAnalysis(CFCtx, Analysis, InitEnv);
+  EXPECT_FALSE(!Result) << Result.takeError();
+
+  Atom FinalFC = (*Result)[CFCtx.getCFG().getExit().getBlockID()]
+ ->Env.getFlowConditionToken();
+  std::string Textual;
+  llvm::raw_string_ostream OS(Textual);
+  DACtx.dumpFlowCondition(FinalFC, OS);
+  return Textual;
+}
+
+TEST(DeterminismTest, NestedSwitch) {
+  // Example extracted from real-world code that had wildly nondeterministic
+  // analysis times.
+  // Its flow condition depends on the order we join predecessor blocks.
+  const char *Code = R"cpp(
+struct Tree;
+struct Rep {
+  Tree *tree();
+  int length;
+};
+struct Tree{
+  int height();
+  Rep *edge(int);
+  int length;
+};
+struct RetVal {};
+int getInt();
+bool maybe();
+
+RetVal make(int size);
+inline RetVal target(int size, Tree& self) {
+  Tree* tree = &self;
+  const int height = self.height();
+  Tree* n1 = tree;
+  Tree* n2 = tree;
+  switch (height) {
+case 3:
+  tree = tree->edge(0)->tree();
+  if (maybe()) return {};
+  n2 = tree;
+case 2:
+  tree = tree->edge(0)->tree();
+  n1 = tree;
+ 

[PATCH] D154784: [clang] Fix crash caused by PseudoObjectExprBitfields::NumSubExprs overflow

2023-07-11 Thread Yurong via Phabricator via cfe-commits
yronglin added a comment.

In D154784#4486721 , @rjmccall wrote:

> We had that discussion in the bug report.  Let's just increase the widths 
> unconditionally; this is not such a common expression class that we need to 
> worry about using an extra word.

Thanks for your review!

> Let's just increase the widths unconditionally

Do you mean:

  class PseudoObjectExprBitfields {
  friend class ASTStmtReader; // deserialization
  friend class PseudoObjectExpr;
  
  unsigned : NumExprBits;
  unsigned NumSubExprs : 16;
  unsigned ResultIndex : 16;
};


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154784

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


[PATCH] D154949: [clang][dataflow] Use `getFieldValue()` in TransferTest.cpp.

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For context, see https://reviews.llvm.org/D154935.

Depends On D154935 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154949

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

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -262,7 +262,8 @@
 cast(&FooLoc->getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -310,7 +311,8 @@
 cast(&FooLoc->getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -357,7 +359,8 @@
 cast(&FooLoc->getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal = cast(FooVal->getChild(*BarDecl));
+const auto *BarVal =
+cast(getFieldValue(FooVal, *BarDecl, Env));
 EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
   });
 }
@@ -470,37 +473,37 @@
 ASSERT_THAT(BazRefDecl, NotNull());
 ASSERT_THAT(BazPtrDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
-const auto *FooReferentVal = cast(Env.getValue(*FooLoc));
+const auto &FooLoc =
+*cast(Env.getStorageLocation(*FooDecl));
+const auto &FooReferentVal = *cast(Env.getValue(FooLoc));
 
-const auto *BarVal =
-cast(FooReferentVal->getChild(*BarDecl));
-const auto *BarReferentVal =
-cast(Env.getValue(BarVal->getReferentLoc()));
+const auto &BarVal =
+*cast(FooReferentVal.getChild(*BarDecl));
+const auto &BarReferentVal =
+*cast(Env.getValue(BarVal.getReferentLoc()));
 
-const auto *FooRefVal =
-cast(BarReferentVal->getChild(*FooRefDecl));
+const auto &FooRefVal =
+*cast(getFieldValue(&BarReferentVal, *FooRefDecl, Env));
 const auto &FooReferentLoc =
-cast(FooRefVal->getReferentLoc());
+cast(FooRefVal.getReferentLoc());
 EXPECT_THAT(Env.getValue(FooReferentLoc), NotNull());
-EXPECT_THAT(Env.getValue(FooReferentLoc.getChild(*BarDecl)), IsNull());
+EXPECT_THAT(getFieldValue(&FooReferentLoc, *BarDecl, Env), IsNull());
 
-const auto *FooPtrVal =
-cast(BarReferentVal->getChild(*FooPtrDecl));
+const auto &FooPtrVal =
+*cast(getFieldValue(&BarReferentVal, *FooPtrDecl, Env));
 const auto &FooPtrPointeeLoc =
-cast(FooPtrVal->getPointeeLoc());
+cast(FooPtrVal.getPointeeLoc());
 EXPECT_THAT(Env.getValue(FooPtrPointeeLoc), NotNull());
-EXPECT_THAT(Env.getValue(FooPtrPointeeLoc.getChild(*BarDecl)), IsNull());
+EXPECT_THAT(getFieldValue(&FooPtrPointeeLoc, *BarDecl, Env), IsNull());
 
-const auto *BazRefVal =
-cast(BarReferentVal->getChild(*BazRefDecl));
-const StorageLocation &BazReferentLoc = BazRefVal->getReferentLoc();
+const auto &BazRefVal =
+*cast(getFieldValue(&BarReferentVal, *BazRefDecl, Env));
+const StorageLocation &BazReferentLoc = BazRefVal.getReferentLoc();
 EXPECT_THAT(Env.getValue(BazReferentLoc), NotNull());
 
-const auto *BazPtrVal =
-cast(BarReferentVal->getChild(*BazPtrDecl));
-const StorageLocation &BazPtrPointeeLoc = BazPtrVal->getPointeeLoc();
+const auto &BazPtrVal =
+*cast(getFieldValue(&BarReferentVal, *BazPtrDecl, Env));
+const StorageLocation &BazPtrPointeeLoc = BazPtrVal.getPointeeLoc();
 EXPECT_THAT(Env.getValue(BazPtrPointeeLoc), NotNull());
   });
 }
@@ -630,35 +633,36 @@
 ASSERT_THAT(BazRefDecl, NotNull());
 ASSERT_THAT(BazPtrDecl, NotNull());
 
-const auto *FooLoc =
-cast(Env.getStorageLocation(*FooDecl));
-const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *FooPointeeVal =
-cast(Env.getValue(FooVal->getPointeeLoc()));
-
-const auto *BarVal =
-cast(FooPointeeVal->getChild(*BarDecl));
-const auto *BarPointeeVal =
-cast(Env.getValue(BarVal->getPointeeLoc()));
-
-const auto *FooRefVal =
-cast(BarPointeeVal->getChild(*FooRefDecl));
-const StorageLocation &FooReferentLoc = FooRefVal->getReferentLoc();
+c

[PATCH] D41416: [modules] [pch] Do not deserialize all lazy template specializations when looking for one.

2023-07-11 Thread Shreyas via Phabricator via cfe-commits
SAtacker added inline comments.



Comment at: clang/lib/Serialization/ASTWriterDecl.cpp:288
+  }
+  for (auto &SpecInfo : LazySpecializations) {
+Record.push_back(SpecInfo.DeclID);

ChuanqiXu wrote:
> v.g.vassilev wrote:
> > We should not store the lazy specialization information as an array of 
> > items because that makes the search slow. Instead we should use the 
> > `OnDiskHashTable` approach which we use already to store the identifier 
> > data.
> Do you want to implement it in this patch? Or this is a note for future 
> optimizations?
I tried it here https://reviews.llvm.org/D144831 but to my surprise it gives 
worse performance for my testing environment which generates random 
specializations per module and a single main file.


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

https://reviews.llvm.org/D41416

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


[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-07-11 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 539017.
koops added a comment.

1. Taking care of Alexy & David suggestions: a) Using update_cc_test_checks.py 
to generate CHECK statements. b) Change in error message from "handled" to 
"allowed". c) Adding comments for the bind clause. d) Mangled names of the 
functions in the CHECK statements are more generic with regular expressions.


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

https://reviews.llvm.org/D144634

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/generic_loop_ast_print.cpp
  clang/test/OpenMP/loop_bind_codegen.cpp
  clang/test/OpenMP/loop_bind_enclosed.cpp
  clang/test/OpenMP/loop_bind_messages.cpp
  clang/test/OpenMP/nested_loop_codegen.cpp

Index: clang/test/OpenMP/nested_loop_codegen.cpp
===
--- clang/test/OpenMP/nested_loop_codegen.cpp
+++ clang/test/OpenMP/nested_loop_codegen.cpp
@@ -58,6 +58,12 @@
 // CHECK1-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[I_ADDR:%.*]] = alloca ptr, align 8
+// CHECK1-NEXT:[[TMP:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_IV:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_LB:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_UB:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
+// CHECK1-NEXT:[[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[K:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
 // CHECK1-NEXT:store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
@@ -66,35 +72,27 @@
 // CHECK1-NEXT:store i32 0, ptr [[TMP0]], align 4
 // CHECK1-NEXT:br label [[FOR_COND:%.*]]
 // CHECK1:   for.cond:
-// CHECK1-NEXT:[[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
-// CHECK1-NEXT:[[CMP:%.*]] = icmp slt i32 [[TMP1]], 10
-// CHECK1-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END7:%.*]]
 // CHECK1:   for.body:
-// CHECK1-NEXT:store i32 0, ptr [[K]], align 4
-// CHECK1-NEXT:br label [[FOR_COND1:%.*]]
-// CHECK1:   for.cond1:
-// CHECK1-NEXT:[[TMP2:%.*]] = load i32, ptr [[K]], align 4
-// CHECK1-NEXT:[[CMP2:%.*]] = icmp slt i32 [[TMP2]], 5
-// CHECK1-NEXT:br i1 [[CMP2]], label [[FOR_BODY3:%.*]], label [[FOR_END:%.*]]
-// CHECK1:   for.body3:
-// CHECK1-NEXT:[[TMP3:%.*]] = load i32, ptr [[K]], align 4
-// CHECK1-NEXT:[[INC:%.*]] = add nsw i32 [[TMP3]], 1
-// CHECK1-NEXT:store i32 [[INC]], ptr [[K]], align 4
-// CHECK1-NEXT:br label [[FOR_INC:%.*]]
-// CHECK1:   for.inc:
-// CHECK1-NEXT:[[TMP4:%.*]] = load i32, ptr [[K]], align 4
-// CHECK1-NEXT:[[INC4:%.*]] = add nsw i32 [[TMP4]], 1
-// CHECK1-NEXT:store i32 [[INC4]], ptr [[K]], align 4
-// CHECK1-NEXT:br label [[FOR_COND1]], !llvm.loop [[LOOP3:![0-9]+]]
-// CHECK1:   for.end:
-// CHECK1-NEXT:br label [[FOR_INC5:%.*]]
-// CHECK1:   for.inc5:
-// CHECK1-NEXT:[[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
-// CHECK1-NEXT:[[INC6:%.*]] = add nsw i32 [[TMP5]], 1
-// CHECK1-NEXT:store i32 [[INC6]], ptr [[TMP0]], align 4
-// CHECK1-NEXT:br label [[FOR_COND]], !llvm.loop [[LOOP5:![0-9]+]]
-// CHECK1:   for.end7:
-// CHECK1-NEXT:ret void
+// CHECK1-NEXT [[TMP2:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK1-NEXT [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4
+// CHECK1-NEXT call void @__kmpc_for_static_init_4(ptr @1, i32 [[TMP3]], i32 34, ptr [[DOTOMP_IS_LAST]], ptr [[DOTOMP_LB]], ptr [[DOTOMP_UB]], ptr [[DOTOMP_STRIDE]], i32 1, i32 1)
+//CHECK1 cond.end:
+//CHECK1 omp.inner.for.cond:
+//CHECK1 omp.inner.for.body:
+//CHECK1 omp.body.continue:
+//CHECK1 omp.inner.for.inc:
+//CHECK1 omp.inner.for.end:
+//CHECK1 omp.loop.exit:
+// CHECK1-NEXT [[TMP13:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK1-NEXT [[TMP14:%.*]] = load i32, ptr [[TMP12]], align 4
+// CHECK1-NEXT call void @__kmpc_for_static_fini(ptr @1, i32 [[TMP14]])
+// CHECK1-NEXT [[TMP15:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
+// CHECK1-NEXT [[TMP16:%.*]] = load i32, ptr [[TMP15]], align 4
+// CHECK1-NEXT call void @__kmpc_barrier(ptr @2, i32 [[TMP16]])
+//CHECK1 for.inc:
+//CHECK1 for.end:
+// CHECK1-NEXT ret void
+//
 //
 //
 // CHECK1-LABEL: define {{[^@]+}}@_Z11inline_declv
@@ -114,45 +112,36 @@
 // CHECK1-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[I_ADDR:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:[[RES_ADDR:%.*]] = alloca ptr, align 8
-// CHECK1-NEXT:[[K:%.*]] = alloca i32, align 4
-// CHECK1-NEXT:store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8

[PATCH] D153989: [compiler-rt] Move crt into builtins

2023-07-11 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

Seems that it caused:
https://github.com/llvm/llvm-project/issues/63799


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153989

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


[PATCH] D154935: [clang][dataflow] Introduce `getFieldValue()` test helpers.

2023-07-11 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp:27
 using namespace dataflow;
+using test::getFieldValue;
 using ::testing::ElementsAre;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154935

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


[PATCH] D154948: [dataflow] improve determinism of generated SAT system

2023-07-11 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Analysis/FlowSensitive/DeterminismTest.cpp:62
+};
+struct Tree{
+  int height();




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154948

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


[PATCH] D154950: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.

The fixIncludes was using the `input` as the main file path, this will
results in inserting header at wrong places.

We need the main file path to so that we can get the real main-file
header.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154950

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,7 +300,8 @@
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"
 #include "a.h"
 #include "aa.h"
 #include "ab.h"
Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -164,7 +164,7 @@
   Results.Missing.clear();
 if (!Remove)
   Results.Unused.clear();
-std::string Final = fixIncludes(Results, Code, getStyle(Path));
+std::string Final = fixIncludes(Results, Path, Code, getStyle(Path));
 
 if (Print.getNumOccurrences()) {
   switch (Print) {
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -112,15 +112,16 @@
   return Results;
 }
 
-std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults &Results,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle &Style) {
   assert(Style.isCpp() && "Only C++ style supports include insertions!");
   tooling::Replacements R;
   // Encode insertions/deletions in the magic way clang-format understands.
   for (const Include *I : Results.Unused)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 1, I->quote(;
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 1, I->quote(;
   for (llvm::StringRef Spelled : Results.Missing)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 0,
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 0,
 ("#include " + Spelled).str(;
   // "cleanup" actually turns the UINT_MAX replacements into concrete edits.
   auto Positioned = cantFail(format::cleanupAroundReplacements(Code, R, 
Style));
Index: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -79,7 +79,8 @@
 /// Removes unused includes and inserts missing ones in the main file.
 /// Returns the modified main-file code.
 /// The FormatStyle must be C++ or ObjC (to support include ordering).
-std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults &Results,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle &IncludeStyle);
 
 /// Gets all the providers for a symbol by traversing each location.


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,7 +300,8 @@
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"
 #include "a.h"
 #include 

[PATCH] D154951: [clang][Interp] __builtin_bit_cast, Take 2

2023-07-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This implements `__builtin_bit_cast()`.

The new opcodes are `BitCast`, which bitcasts to a non-floating primitive type, 
`BitCastFP`, which bitcasts to a floating type, and `BitCastPtr`, which 
bitcasts to a composite type. Everything is implemented in `InterpBitcast.cpp`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154951

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBitcast.cpp
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/builtin-bit-cast.cpp
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -98,6 +98,11 @@
 static_assert(p != nullptr, "");
 static_assert(*p == 10, "");
 
+constexpr const void *cp = (void *)p;
+// FIXME: This should be an error in the new interpreter.
+constexpr const int *pm = (int*)cp; // ref-error {{ must be initialized by a constant expression}} \
+// ref-note {{cast from 'const void *' is not allowed}}
+
 constexpr const int* getIntPointer() {
   return &m;
 }
Index: clang/test/AST/Interp/builtin-bit-cast.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/builtin-bit-cast.cpp
@@ -0,0 +1,683 @@
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -fexperimental-new-constant-interpreter %s
+// RUN: %clang_cc1 -verify=ref -std=c++2a -fsyntax-only %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple aarch64_be-linux-gnu -fexperimental-new-constant-interpreter %s
+// RUN: %clang_cc1 -verify=ref -std=c++2a -fsyntax-only -triple aarch64_be-linux-gnu %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -fexperimental-new-constant-interpreter -triple powerpc64le-unknown-unknown -mabi=ieeelongdouble %s
+// RUN: %clang_cc1 -verify=ref -std=c++2a -fsyntax-only -triple powerpc64le-unknown-unknown -mabi=ieeelongdouble %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -fexperimental-new-constant-interpreter -triple powerpc64-unknown-unknown -mabi=ieeelongdouble %s
+// RUN: %clang_cc1 -verify=ref -std=c++2a -fsyntax-only -triple powerpc64-unknown-unknown -mabi=ieeelongdouble %s
+
+/// FIXME: This is a version of
+///   clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp with the currently
+///   supported subset of operations. They should *all* be supported though.
+
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#  define LITTLE_END 1
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#  define LITTLE_END 0
+#else
+#  error "huh?"
+#endif
+
+typedef decltype(nullptr) nullptr_t;
+
+static_assert(sizeof(int) == 4);
+static_assert(sizeof(long long) == 8);
+
+template 
+constexpr To bit_cast(const From &from) {
+  static_assert(sizeof(To) == sizeof(From));
+  return __builtin_bit_cast(To, from); // ref-note 2{{indeterminate value can only initialize}} \
+   // expected-note 2{{indeterminate value can only initialize}}
+}
+
+template 
+constexpr bool round_trip(const Init &init) {
+  return bit_cast(bit_cast(init)) == init;
+}
+
+/// We can ignore it.
+constexpr int foo() {
+  (void)__builtin_bit_cast(int, 3);
+  return 1;
+}
+static_assert(foo() == 1, "");
+
+namespace Ints {
+  static_assert(round_trip((int)-1));
+  static_assert(round_trip((int)0x12345678));
+  static_assert(round_trip((int)0x87654321));
+  static_assert(round_trip((int)0x0C05FEFE));
+  static_assert(round_trip((int)0x0C05FEFE));
+}
+
+namespace FloatToDouble {
+  constexpr float F1[] = {1.0f, 2.0f};
+  constexpr double D1 = __builtin_bit_cast(double, F1);
+  static_assert(D1 > 0);
+}
+
+namespace Arrays {
+  constexpr unsigned char input[] = {0xCA, 0xFE, 0xBA, 0xBE};
+  constexpr unsigned expected = LITTLE_END ? 0xBEBAFECA : 0xCAFEBABE;
+  static_assert(bit_cast(input) == expected);
+
+  constexpr short S[] = {10, 20};
+  constexpr int I = __builtin_bit_cast(int, S);
+  static_assert(I == (LITTLE_END ? 1310730 : 655380));
+}
+
+struct int_splicer {
+  unsigned x;
+  unsigned y;
+
+  constexpr int_splicer() : x(1), y(2) {}
+  constexpr int_splicer(unsigned x, unsigned y) : x(x), y(y) {}
+
+  constexpr bool operator==(const int_splicer &other) const {
+return other.x == x && other.y == y;
+  }
+};
+
+constexpr int_splicer splice(0x0C05FEFE, 0xCAFEBABE);
+
+static_assert(bit_cast(splice) == (LITTLE_END
+   

[PATCH] D154948: [dataflow] improve determinism of generated SAT system

2023-07-11 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.

Thank you, Sam!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154948

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


[PATCH] D154950: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:303
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"

can you also have a test in which we insert "d.h" and it gets put into the 
right place?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154950

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


[PATCH] D154952: [clang][dataflow] Various refactorings in TypeErasedDataflowAnalysisTest.cpp

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

These simplify the code in their own right, but they are also useful in that
they minimize the number of changes that will need to be made when then API of
`AggregateStorageLocation` and `StructValue` changes as part of the migration to
strict handling of value categories (see https://discourse.llvm.org/t/70086).

Depends On D154949 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154952

Files:
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -370,6 +370,13 @@
   // FIXME: Called functions at point `p` should contain only "foo".
 }
 
+StructValue &createNewStructValue(AggregateStorageLocation &Loc,
+  Environment &Env) {
+  auto &Val = *cast(Env.createValue(Loc.getType()));
+  Env.setValue(Loc, Val);
+  return Val;
+}
+
 // Models an analysis that uses flow conditions.
 class SpecialBoolAnalysis final
 : public DataflowAnalysis {
@@ -390,23 +397,18 @@
 if (const auto *E = selectFirst(
 "call", match(cxxConstructExpr(HasSpecialBoolType).bind("call"), 
*S,
   getASTContext( {
-  auto &ConstructorVal = *Env.createValue(E->getType());
-  ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(false));
-  Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), 
ConstructorVal);
+  cast(Env.getValueStrict(*E))
+  ->setProperty("is_set", Env.getBoolLiteralValue(false));
 } else if (const auto *E = selectFirst(
"call", 
match(cxxMemberCallExpr(callee(cxxMethodDecl(ofClass(

SpecialBoolRecordDecl
  .bind("call"),
  *S, getASTContext( {
-  auto *Object = E->getImplicitObjectArgument();
-  assert(Object != nullptr);
-
-  auto *ObjectLoc = getImplicitObjectLocation(*E, Env);
-  assert(ObjectLoc != nullptr);
+  auto &ObjectLoc =
+  *cast(getImplicitObjectLocation(*E, Env));
 
-  auto &ConstructorVal = *Env.createValue(Object->getType());
-  ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(true));
-  Env.setValue(*ObjectLoc, ConstructorVal);
+  createNewStructValue(ObjectLoc, Env)
+  .setProperty("is_set", Env.getBoolLiteralValue(true));
 }
   }
 
@@ -551,21 +553,19 @@
 *S, getASTContext());
 if (const auto *E = selectFirst(
 "construct", Matches)) {
-  auto &ConstructorVal = *Env.createValue(E->getType());
-  ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(false));
-  Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), 
ConstructorVal);
+  cast(Env.getValueStrict(*E))
+  ->setProperty("has_value", Env.getBoolLiteralValue(false));
 } else if (const auto *E =
selectFirst("operator", Matches)) {
   assert(E->getNumArgs() > 0);
   auto *Object = E->getArg(0);
   assert(Object != nullptr);
 
-  auto *ObjectLoc = Env.getStorageLocation(*Object, SkipPast::Reference);
-  assert(ObjectLoc != nullptr);
+  auto &ObjectLoc = *cast(
+  Env.getStorageLocation(*Object, SkipPast::Reference));
 
-  auto &ConstructorVal = *Env.createValue(Object->getType());
-  ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(true));
-  Env.setValue(*ObjectLoc, ConstructorVal);
+  createNewStructValue(ObjectLoc, Env)
+  .setProperty("has_value", Env.getBoolLiteralValue(true));
 }
   }
 
@@ -1227,9 +1227,7 @@
 match(callExpr(callee(functionDecl(hasName("makeTop".bind("top"),
   *S, getASTContext());
 if (const auto *E = selectFirst("top", Matches)) {
-  auto &Loc = Env.createStorageLocation(*E);
-  Env.setValue(Loc, Env.makeTopBoolValue());
-  Env.setStorageLocation(*E, Loc);
+  Env.setValueStrict(*E, Env.makeTopBoolValue());
 }
   }
 


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -370,6 +370,13 @@
   // FIXME: Called functions at point `p` should contain only "foo".
 }
 
+StructValue &createNewStructValue(AggregateStorageLocation &Loc,
+

[PATCH] D154952: [clang][dataflow] Various refactorings in TypeErasedDataflowAnalysisTest.cpp

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added inline comments.



Comment at: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:400
   getASTContext( {
-  auto &ConstructorVal = *Env.createValue(E->getType());
-  ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(false));
-  Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), 
ConstructorVal);
+  cast(Env.getValueStrict(*E))
+  ->setProperty("is_set", Env.getBoolLiteralValue(false));

This works because we know that constructor has already created a fresh value 
for `E`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154952

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


[PATCH] D154786: [Clang][Driver] Pass through the --be8 endian flag to linker in BareMetal driver For Arm.

2023-07-11 Thread Simi Pallipurath via Phabricator via cfe-commits
simpal01 updated this revision to Diff 539031.
simpal01 added a comment.

Addressing Review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154786

Files:
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.h
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/baremetal.cpp

Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-internal-isystem" "[[SYSROOT]]{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
 // CHECk-V6M-C-SAME: "-internal-isystem" "[[SYSROOT]]{{[/\\]+}}include"
 // CHECK-V6M-C-SAME: "-x" "c++" "{{.*}}baremetal.cpp"
-// CHECK-V6M-C-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-C-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
@@ -34,7 +34,7 @@
 // CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
 // CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
-// CHECK-ARMV7M-PER-TARGET: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
 // CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
@@ -42,7 +42,7 @@
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck --check-prefix=CHECK-V6M-DEFAULTCXX %s
 // CHECK-V6M-DEFAULTCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
-// CHECK-V6M-DEFAULTCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-DEFAULTCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-DEFAULTCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
@@ -53,7 +53,7 @@
 // CHECK-V6M-LIBCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-V6M-LIBCXX-NOT: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}{{[^v].*}}"
 // CHECK-V6M-LIBCXX-SAME: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
-// CHECK-V6M-LIBCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-LIBCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-LIBCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
@@ -66,7 +66,7 @@
 // CHECK-V6M-LIBSTDCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-V6M-LIBSTDCXX-NOT: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
 // CHECK-V6M-LIBSTDCXX-SAME: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}6.0.0"
-// CHECK-V6M-LIBSTDCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-LIBSTDCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-LIBSTDCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBSTDCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind"
@@ -77,7 +77,7 @@
 // RUN: -nodefaultlibs \
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-NDL %s
 // CHECK-V6M-NDL: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
-// CHECK-V6M-NDL: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-NDL: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-NDL-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-NDL-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 
@@ -117,6 +117,46 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-SYSROOT-INC
 // CHECK-SYSROOT-INC-NOT: "-internal-isystem" "include"
 
+// RUN: %clang -### %s --target=armebv7-none-eabi --sysroot=%S/Inputs/baremetal_arm 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7EB %s
+// CHECK-ARMV7EB: "{{.*}}ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "--be8" "-EB"
+
+// RUN: %clang -### %s --target=armv7-none-eabi -mbig-endian --sysroot=%S/Inputs/baremetal_arm 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7EB %s
+
+// RUN: %clang -### %s --target=armebv7-none-eabi -mbig-endian --sysroot=%S/Inputs/baremetal_arm 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7EB %s
+
+// RUN: %clang -### %s --target=armv7-none-eabi --sysroot=%S/Inputs/baremetal_arm 2>&1 \
+// RUN:   | FileC

[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Christian Walther via Phabricator via cfe-commits
cwalther updated this revision to Diff 539033.
cwalther added a comment.

Updated patch according to current discussion:

- remove check for vendor, any vendor is accepted
- replace cascaded `if` by `&&`
- rebase on main a3f9ce6 



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

https://reviews.llvm.org/D154357

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -345,6 +345,58 @@
 // CHECK-RV32IMAFC-SAME: 
"-L[[SYSROOT:[^"]+]]{{[/\\]+}}rv32imafc{{[/\\]+}}ilp32f{{[/\\]+}}lib"
 // CHECK-RV32IMAFC-SAME: 
"-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal{{[/\\]+}}rv32imafc{{[/\\]+}}ilp32f"
 
+// RUN: %clang %s -### --target=powerpc-unknown-eabi 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPCEABI %s
+// CHECK-PPCEABI: InstalledDir: [[INSTALLEDDIR:.+]]
+// CHECK-PPCEABI: "-nostdsysteminc"
+// CHECK-PPCEABI-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK-PPCEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-PPCEABI-SAME: "-internal-isystem" "[[RESOURCE]]{{[/\\]+}}include"
+// CHECK-PPCEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include"
+// CHECK-PPCEABI-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-PPCEABI-SAME: 
"-L[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}lib"
+// CHECK-PPCEABI-SAME: "-L[[RESOURCE]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-PPCEABI-SAME: "-lc" "-lm" "-lclang_rt.builtins-powerpc" "-o" "a.out"
+
+// RUN: %clang %s -### --target=powerpc64-unknown-eabi 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPC64EABI %s
+// CHECK-PPC64EABI: InstalledDir: [[INSTALLEDDIR:.+]]
+// CHECK-PPC64EABI: "-nostdsysteminc"
+// CHECK-PPC64EABI-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK-PPC64EABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-PPC64EABI-SAME: "-internal-isystem" "[[RESOURCE]]{{[/\\]+}}include"
+// CHECK-PPC64EABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include"
+// CHECK-PPC64EABI-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-PPC64EABI-SAME: 
"-L[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}lib"
+// CHECK-PPC64EABI-SAME: "-L[[RESOURCE]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-PPC64EABI-SAME: "-lc" "-lm" "-lclang_rt.builtins-powerpc64" "-o" 
"a.out"
+
+// RUN: %clang %s -### --target=powerpcle-unknown-eabi 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPCLEEABI %s
+// CHECK-PPCLEEABI: InstalledDir: [[INSTALLEDDIR:.+]]
+// CHECK-PPCLEEABI: "-nostdsysteminc"
+// CHECK-PPCLEEABI-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK-PPCLEEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-PPCLEEABI-SAME: "-internal-isystem" "[[RESOURCE]]{{[/\\]+}}include"
+// CHECK-PPCLEEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include"
+// CHECK-PPCLEEABI-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-PPCLEEABI-SAME: 
"-L[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}lib"
+// CHECK-PPCLEEABI-SAME: "-L[[RESOURCE]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-PPCLEEABI-SAME: "-lc" "-lm" "-lclang_rt.builtins-powerpcle" "-o" 
"a.out"
+
+// RUN: %clang %s -### --target=powerpc64le-unknown-eabi 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-PPC64LEEABI %s
+// CHECK-PPC64LEEABI: InstalledDir: [[INSTALLEDDIR:.+]]
+// CHECK-PPC64LEEABI: "-nostdsysteminc"
+// CHECK-PPC64LEEABI-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]"
+// CHECK-PPC64LEEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-PPC64LEEABI-SAME: "-internal-isystem" "[[RESOURCE]]{{[/\\]+}}include"
+// CHECK-PPC64LEEABI-SAME: "-internal-isystem" 
"[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include"
+// CHECK-PPC64LEEABI-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-PPC64LEEABI-SAME: 
"-L[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}lib"
+// CHECK-PPC64LEEABI-SAME: "-L[[RESOURCE]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-PPC64LEEABI-SAME: "-lc" "-lm" "-lclang_rt.builtins-powerpc64le" "-o" 
"a.out"
+
 // Check that compiler-rt library without the arch filename suffix will
 // be used if present.
 // RUN: rm -rf %T/ba

[PATCH] D154357: [Driver] Recognize powerpc-unknown-eabi as a bare-metal toolchain

2023-07-11 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.

No concerns from the perspective of PowerPC here. Of course, my focus is 
primarily on the server side of things but I am not aware of any other group 
that could be adversely affected.


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

https://reviews.llvm.org/D154357

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


[PATCH] D154950: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 539045.
hokein added a comment.

add a testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154950

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,11 +300,22 @@
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"
 #include "a.h"
 #include "aa.h"
 #include "ab.h"
 #include 
+)cpp");
+
+  Results = {};
+  Results.Missing.push_back("\"d.h\"");
+  Code = R"cpp(#include "a.h")cpp";
+  // FIXME: this isn't correct, the main-file header d.h should be added before
+  // a.h.
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "a.h"
+#include "d.h"
 )cpp");
 }
 
Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -164,7 +164,7 @@
   Results.Missing.clear();
 if (!Remove)
   Results.Unused.clear();
-std::string Final = fixIncludes(Results, Code, getStyle(Path));
+std::string Final = fixIncludes(Results, Path, Code, getStyle(Path));
 
 if (Print.getNumOccurrences()) {
   switch (Print) {
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -112,15 +112,16 @@
   return Results;
 }
 
-std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults &Results,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle &Style) {
   assert(Style.isCpp() && "Only C++ style supports include insertions!");
   tooling::Replacements R;
   // Encode insertions/deletions in the magic way clang-format understands.
   for (const Include *I : Results.Unused)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 1, I->quote(;
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 1, I->quote(;
   for (llvm::StringRef Spelled : Results.Missing)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 0,
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 0,
 ("#include " + Spelled).str(;
   // "cleanup" actually turns the UINT_MAX replacements into concrete edits.
   auto Positioned = cantFail(format::cleanupAroundReplacements(Code, R, 
Style));
Index: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -79,7 +79,8 @@
 /// Removes unused includes and inserts missing ones in the main file.
 /// Returns the modified main-file code.
 /// The FormatStyle must be C++ or ObjC (to support include ordering).
-std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults &Results,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle &IncludeStyle);
 
 /// Gets all the providers for a symbol by traversing each location.


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,11 +300,22 @@
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  

[PATCH] D154950: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:303
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"

kadircet wrote:
> can you also have a test in which we insert "d.h" and it gets put into the 
> right place?
added a test with a FIXME -- unfortunately, this case doesn't work yet (I 
believe this is a bug in the `tooling::HeaderIncludes`, I plan to fix it 
afterwards.)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154950

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


[clang-tools-extra] 7f3d2cd - [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-07-11T15:02:26+02:00
New Revision: 7f3d2cd7ec254cda659c5e5a19a42105e370e04c

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

LOG: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

The fixIncludes was using the `input` as the main file path, this will
results in inserting header at wrong places.

We need the main file path to so that we can get the real main-file
header.

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
clang-tools-extra/include-cleaner/lib/Analysis.cpp
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h 
b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
index 547e9dd7261ca3..77be4f1dad5212 100644
--- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -79,7 +79,8 @@ analyze(llvm::ArrayRef ASTRoots,
 /// Removes unused includes and inserts missing ones in the main file.
 /// Returns the modified main-file code.
 /// The FormatStyle must be C++ or ObjC (to support include ordering).
-std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults &Results,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle &IncludeStyle);
 
 /// Gets all the providers for a symbol by traversing each location.

diff  --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index 616eeae43a87ee..e76929f6824ce7 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -112,15 +112,16 @@ analyze(llvm::ArrayRef ASTRoots,
   return Results;
 }
 
-std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults &Results,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle &Style) {
   assert(Style.isCpp() && "Only C++ style supports include insertions!");
   tooling::Replacements R;
   // Encode insertions/deletions in the magic way clang-format understands.
   for (const Include *I : Results.Unused)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 1, I->quote(;
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 1, I->quote(;
   for (llvm::StringRef Spelled : Results.Missing)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 0,
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 0,
 ("#include " + Spelled).str(;
   // "cleanup" actually turns the UINT_MAX replacements into concrete edits.
   auto Positioned = cantFail(format::cleanupAroundReplacements(Code, R, 
Style));

diff  --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp 
b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
index e7ae0c68c88214..c6cd7995d2e829 100644
--- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -164,7 +164,7 @@ class Action : public clang::ASTFrontendAction {
   Results.Missing.clear();
 if (!Remove)
   Results.Unused.clear();
-std::string Final = fixIncludes(Results, Code, getStyle(Path));
+std::string Final = fixIncludes(Results, Path, Code, getStyle(Path));
 
 if (Print.getNumOccurrences()) {
   switch (Print) {

diff  --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
index b6521d56bcff44..64dd6bc1e84cae 100644
--- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@ TEST_F(AnalyzeTest, NoCrashWhenUnresolved) {
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,11 +300,22 @@ TEST(FixIncludes, Basic) {
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"
 #include "a.h"
 #include "aa.h"
 #include "ab.h"
 #include 
+)cpp");
+
+  Results = {};
+  Resul

[PATCH] D154950: [include-cleaner] Fix the `fixIncludes` API not respect main-file header.

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7f3d2cd7ec25: [include-cleaner] Fix the `fixIncludes` API 
not respect main-file header. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154950

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,11 +300,22 @@
   Results.Unused.push_back(Inc.atLine(3));
   Results.Unused.push_back(Inc.atLine(4));
 
-  EXPECT_EQ(fixIncludes(Results, Code, format::getLLVMStyle()), R"cpp(
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "d.h"
 #include "a.h"
 #include "aa.h"
 #include "ab.h"
 #include 
+)cpp");
+
+  Results = {};
+  Results.Missing.push_back("\"d.h\"");
+  Code = R"cpp(#include "a.h")cpp";
+  // FIXME: this isn't correct, the main-file header d.h should be added before
+  // a.h.
+  EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
+R"cpp(#include "a.h"
+#include "d.h"
 )cpp");
 }
 
Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -164,7 +164,7 @@
   Results.Missing.clear();
 if (!Remove)
   Results.Unused.clear();
-std::string Final = fixIncludes(Results, Code, getStyle(Path));
+std::string Final = fixIncludes(Results, Path, Code, getStyle(Path));
 
 if (Print.getNumOccurrences()) {
   switch (Print) {
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -112,15 +112,16 @@
   return Results;
 }
 
-std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults &Results,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle &Style) {
   assert(Style.isCpp() && "Only C++ style supports include insertions!");
   tooling::Replacements R;
   // Encode insertions/deletions in the magic way clang-format understands.
   for (const Include *I : Results.Unused)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 1, I->quote(;
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 1, I->quote(;
   for (llvm::StringRef Spelled : Results.Missing)
-cantFail(R.add(tooling::Replacement("input", UINT_MAX, 0,
+cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 0,
 ("#include " + Spelled).str(;
   // "cleanup" actually turns the UINT_MAX replacements into concrete edits.
   auto Positioned = cantFail(format::cleanupAroundReplacements(Code, R, 
Style));
Index: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -79,7 +79,8 @@
 /// Removes unused includes and inserts missing ones in the main file.
 /// Returns the modified main-file code.
 /// The FormatStyle must be C++ or ObjC (to support include ordering).
-std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
+std::string fixIncludes(const AnalysisResults &Results,
+llvm::StringRef FileName, llvm::StringRef Code,
 const format::FormatStyle &IncludeStyle);
 
 /// Gets all the providers for a symbol by traversing each location.


Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -274,7 +274,7 @@
 }
 
 TEST(FixIncludes, Basic) {
-  llvm::StringRef Code = R"cpp(
+  llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
 #include "b.h"
 #include 
@@ -300,11 +30

[PATCH] D153339: [clang] Support vectors in __builtin_isfpclass

2023-07-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

This seems reasonable to me, but I do wonder if changing the return type from 
int to bool will cause surprises for anyone. I see why it's done, but this 
seems more like a C interface (to me) which would return an `int`; returning a 
`bool` gets promoted to `int` when you sneeze near it, so I wonder about 
performance implications. But at the same time, we wouldn't want a vector of 
ints returns in the vector case, I would suspect.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153339

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


[PATCH] D153612: [clang][analyzer] Add and change NoteTags in StdLibraryFunctionsChecker.

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



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1305
+  std::string Note =
+  llvm::formatv(Case.getNote().str().c_str(),
+cast(Call.getDecl())->getDeclName());

donat.nagy wrote:
> Consider using the method `StringRef::data()` which directly converts a 
> `StringRef` to a `const char *`. Your two-step conversion has the advantage 
> that it adds a `\0` terminator even if the `StringRef` isn't null-terminated, 
> but I cannot imagine a "natural" code change that would introduce references 
> to non-null-terminated char arrays as note message templates.
I would prefer not to rely on that `StringRef`s (here) are expected to be 
null-terminated, unless benchmarks demonstrate that this is important. If that 
would turn out to be the case, then we would need to enforce this using some 
sort of `assert` expression.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1337
+// if 'errno' is interesting.
+if (const auto *D = dyn_cast_or_null(Call.getDecl()))
+  if (const NoteTag *NT =

Previously, we had a `cast<>(Call.getDecl())`, thus we should only have a 
`dyn_cast` here.



Comment at: clang/test/Analysis/stream-note.c:61-62
   FILE *F1 = fopen("foo1.c", "r"); // expected-note {{Stream opened here}}
+  // stdargs-note@-1 {{'fopen' is successful}}
+  // stdargs-note@-2 {{'fopen' is successful}}
   if (!F1)

Why are these notes doubled?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153612

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


[PATCH] D153659: [RISCV] Fix name mangling for LMUL!=1 vector types with attribute(rvv_vector_bits)

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153659

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


[PATCH] D152632: [Clang] Add warnings for CWG2521

2023-07-11 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill accepted this revision as: Endill.
Endill added a comment.

DR testing side looks good, but you should wait for more approvals.
Thank you for addressing all the issues there!


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

https://reviews.llvm.org/D152632

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


[PATCH] D153156: [Clang] CWG1473: do not err on the lack of space after operator""

2023-07-11 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added inline comments.



Comment at: clang/test/CXX/drs/dr14xx.cpp:491
+  float operator ""_E(const char *);
+  // expected-warning@+1 {{user-defined literal suffixes not starting with '_' 
are reserved; no literal will invoke this operator}}
+  float operator ""E(const char *); // don't err on the lack of spaces even 
when the literal suffix identifier is invalid

Can you move this down, so that offset is negative (after @)?


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

https://reviews.llvm.org/D153156

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


[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-07-11 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9838
+def err_omp_loop_reduction_clause : Error<
+  "reduction clause not allowed with '#pragma omp loop bind(teams)'">;
 def warn_break_binds_to_switch : Warning<

'reduction'



Comment at: clang/lib/Sema/SemaOpenMP.cpp:6105
+bool Sema::mapLoopConstruct(
+llvm::SmallVector *ClausesWithoutBind,
+ArrayRef Clauses, OpenMPBindClauseKind BindKind,

Why ClausesWithoutBind passing by pointer? Use `llvm::SmallVectorImpl &ClausesWithoutBind` instead



Comment at: clang/lib/Sema/SemaOpenMP.cpp:6107
+ArrayRef Clauses, OpenMPBindClauseKind BindKind,
+OpenMPDirectiveKind *Kind) {
+

Same, pass by reference



Comment at: clang/lib/Sema/SemaOpenMP.cpp:14088-14089
   setFunctionHasBranchProtectedScope();
-  return OMPDistributeDirective::Create(Context, StartLoc, EndLoc,
-NestedLoopCount, Clauses, AStmt, B);
+  return OMPDistributeDirective::Create(
+  Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B);
 }

Restore formatting


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

https://reviews.llvm.org/D144634

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


[PATCH] D154675: [Clang] Fix crash when emitting diagnostic for out of order designated initializers in C++

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

LGTM but please land with a release note.




Comment at: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp:66
   .y = 1, // override-note {{previous}}
-  .y = 1, // override-error {{overrides prior initialization}}
+  .y = 1, // override-error {{overrides prior initialization}} // reorder-note 
{{previous initialization for field 'y' is here}}
   .x = 1, // reorder-error {{declaration order}} override-error {{overrides 
prior initialization}} override-note {{previous}}

shafik wrote:
> aaron.ballman wrote:
> > A few questions: 1) what is this new note attached to? The only `reorder-*` 
> > diagnostic I see in the test is for the initialization of `x`. 2) is the 
> > note actually on the correct previous use? I would have expected this to be 
> > on the assignment to `y` one line above.
> It is attached to :
> 
> ```
> .x = 1, // reorder-error {{declaration order}}
> ```
> 
> We were not issuing it before b/c it was broken, in this case it was just not 
> crashing but it was still broken.
> 
> We could argue the note should go on the first `.y` although I could see both 
> sides since the override is a warning and not an error I think using the 
> second is defensible. 
> 
> 
Oh! I had a brain fart and thought this was about *re*initialization of `y`. I 
see what's going on now and yeah, this makes sense. I'm not worried about which 
`y` the note attaches to.


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

https://reviews.llvm.org/D154675

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


[clang] 1bbaabb - [clang] Add test for CWG1710 and related issues

2023-07-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-07-11T16:24:39+03:00
New Revision: 1bbaabb90dd72f78ea290b71dfe3bf2689ad7403

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

LOG: [clang] Add test for CWG1710 and related issues

Those issues focus on `template` keyword being optional in certain type-only 
contexts (base specifiers, member initializers, typename specifiers), as 
opposed to be disallowed by the grammar, or required by some implementations. 
GCC accepts all the tests this patch touches since 10, others fail on various 
tests: https://godbolt.org/z/1M6KE3W1a

It should be noted that the wording in [[ 
https://cplusplus.github.io/CWG/issues/1710.html | 1710 ]] that resolves those 
issues has been substantially changed by [[ https://wg21.link/p1787 | P1787 ]]. 
I can't find the post-P1787 wording that covers those issues, but I can't find 
the intent of changing relevant behavior in P1787 either, so I assume that 
intent of the 1710 resolution is preserved somewhere.

This patch covers the following issues:
[[ https://cplusplus.github.io/CWG/issues/314.html  | CWG314 ]]
[[ https://cplusplus.github.io/CWG/issues/343.html  | CWG343 ]]
[[ https://cplusplus.github.io/CWG/issues/1710.html | CWG1710 ]]
[[ https://cplusplus.github.io/CWG/issues/1794.html | CWG1794 ]]
[[ https://cplusplus.github.io/CWG/issues/1812.html | CWG1812 ]]

Reviewed By: #clang-language-wg, cor3ntin

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

Added: 


Modified: 
clang/test/CXX/drs/dr17xx.cpp
clang/test/CXX/drs/dr18xx.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr17xx.cpp b/clang/test/CXX/drs/dr17xx.cpp
index e91f4a6d69b3ac..219119d1a4cd08 100644
--- a/clang/test/CXX/drs/dr17xx.cpp
+++ b/clang/test/CXX/drs/dr17xx.cpp
@@ -1,7 +1,22 @@
 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
-// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+
+namespace dr1710 { // dr1710: no
+// FIXME: all of the following is well-formed
+template  struct D1 : T::template B::template C {};
+template  struct D2 : T::B::template C {};
+// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent 
template name}}
+template  struct D3 : T::template B::C {};
+// expected-error@-1 {{use 'template' keyword to treat 'C' as a dependent 
template name}}
+template  struct D4 : T::B::C {};
+// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent 
template name}}
+// expected-error@-2 {{use 'template' keyword to treat 'C' as a dependent 
template name}}
+} // namespace dr1710
 
 namespace dr1715 { // dr1715: 3.9
 #if __cplusplus >= 201103L
@@ -146,3 +161,18 @@ namespace dr1778 { // dr1778: 9
   static_assert(noexcept(D()), "");
 #endif
 }
+
+namespace dr1794 { // dr1794: yes
+   // NB: dup 1710
+#if __cplusplus >= 201103L
+template  class Template> struct Internal {
+  template  using Bind = Template;
+};
+
+template  class Template, typename Arg>
+using Instantiate = Template;
+
+template  class Template, typename Argument>
+using Bind = Instantiate::template Bind, Argument>;
+#endif
+} // namespace dr1794

diff  --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index 3d57f5e5b74dbd..7ac26737382281 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -4,12 +4,23 @@
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 
 #if __cplusplus < 201103L
 // expected-error@+1 {{variadic macro}}
 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
 #endif
 
+namespace dr1812 { // dr1812: no
+   // NB: dup 1710
+

[PATCH] D151697: [clang] Add test for CWG1710 and related issues

2023-07-11 Thread Vlad Serebrennikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1bbaabb90dd7: [clang] Add test for CWG1710 and related 
issues (authored by Endill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151697

Files:
  clang/test/CXX/drs/dr17xx.cpp
  clang/test/CXX/drs/dr18xx.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -1923,7 +1923,7 @@
 https://cplusplus.github.io/CWG/issues/314.html";>314
 C++17
 template in base class specifier
-Unknown
+No
   
   
 https://cplusplus.github.io/CWG/issues/315.html";>315
@@ -2097,7 +2097,7 @@
 https://cplusplus.github.io/CWG/issues/343.html";>343
 C++17
 Make template optional in contexts that require a type
-Unknown
+No
   
   
 https://cplusplus.github.io/CWG/issues/344.html";>344
@@ -10067,7 +10067,7 @@
 https://cplusplus.github.io/CWG/issues/1710.html";>1710
 C++17
 Missing template keyword in class-or-decltype
-Unknown
+No
   
   
 https://cplusplus.github.io/CWG/issues/1711.html";>1711
@@ -10571,7 +10571,7 @@
 https://cplusplus.github.io/CWG/issues/1794.html";>1794
 C++17
 template keyword and alias templates
-Unknown
+Yes
   
   
 https://cplusplus.github.io/CWG/issues/1795.html";>1795
@@ -10679,7 +10679,7 @@
 https://cplusplus.github.io/CWG/issues/1812.html";>1812
 C++17
 Omission of template in a typename-specifier
-Unknown
+No
   
   
 https://cplusplus.github.io/CWG/issues/1813.html";>1813
Index: clang/test/CXX/drs/dr3xx.cpp
===
--- clang/test/CXX/drs/dr3xx.cpp
+++ clang/test/CXX/drs/dr3xx.cpp
@@ -208,14 +208,20 @@
 #endif
 }
 
-namespace dr314 { // FIXME 314: dup 1710
-  template struct A {
-template struct B {};
-  };
-  template struct C : public A::template B {
-C() : A::template B() {}
-  };
-}
+namespace dr314 { // dr314: no
+  // NB: dup 1710
+template  struct A {
+  template  struct B {};
+};
+template  struct C : public A::template B {
+  C() : A::template B() {}
+};
+template  struct C2 : public A::B {
+  // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
+  C2() : A::B() {}
+  // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
+};
+} // namespace dr314
 
 // dr315: na
 // dr316: sup 1004
@@ -591,7 +597,7 @@
 
 // dr342: na
 
-namespace dr343 { // FIXME 343: no
+namespace dr343 { // dr343: no
   // FIXME: dup 1710
   template struct A {
 template struct B {};
Index: clang/test/CXX/drs/dr18xx.cpp
===
--- clang/test/CXX/drs/dr18xx.cpp
+++ clang/test/CXX/drs/dr18xx.cpp
@@ -4,12 +4,23 @@
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 
 #if __cplusplus < 201103L
 // expected-error@+1 {{variadic macro}}
 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
 #endif
 
+namespace dr1812 { // dr1812: no
+   // NB: dup 1710
+#if __cplusplus >= 201103L
+template  struct A {
+  using B = typename T::C;
+  // expected-error@-1 {{use 'template' keyword to treat 'C' as a dependent template name}}
+};
+#endif
+} // namespace dr1812
+
 namespace dr1813 { // dr1813: 7
   struct B { int i; };
   struct C : B {};
Index: clang/test/CXX/drs/dr17xx.cpp
===
--- clang/test/CXX/drs/dr17xx.cpp
+++ clang/test/CXX/drs/dr17xx.cpp
@@ -1,7 +1,22 @@
 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s -verify -fexceptions -fcxx

[PATCH] D154961: [clang][dataflow] Include fields initialized in an `InitListExpr` in `getModeledFields()`.

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Previously, we were including these fields only in the specific instance that
was initialized by the `InitListExpr`, but not in other instances of the same
type. This is inconsistent and error-prone.

Depends On D154952 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154961

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

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2833,6 +2833,7 @@
 
 void target(int BarArg, int FooArg, int QuxArg) {
   B Quux{BarArg, {FooArg}, QuxArg};
+  B OtherB;
   /*[[p]]*/
 }
   )";
@@ -2849,6 +2850,7 @@
 
 void target(int BarArg, int FooArg, int QuxArg) {
   B Quux = {BarArg, FooArg, QuxArg};
+  B OtherB;
   /*[[p]]*/
 }
   )";
@@ -2898,6 +2900,14 @@
   EXPECT_EQ(getFieldValue(QuuxVal, *BarDecl, Env), BarArgVal);
   EXPECT_EQ(getFieldValue(BazVal, *FooDecl, Env), FooArgVal);
   EXPECT_EQ(getFieldValue(QuuxVal, *QuxDecl, Env), QuxArgVal);
+
+  // Check that fields initialized in an initializer list are always
+  // modeled in other instances of the same type.
+  const auto &OtherBVal =
+  getValueForDecl(ASTCtx, Env, "OtherB");
+  EXPECT_THAT(OtherBVal.getChild(*BarDecl), NotNull());
+  EXPECT_THAT(OtherBVal.getChild(*BazDecl), NotNull());
+  EXPECT_THAT(OtherBVal.getChild(*QuxDecl), NotNull());
 });
   }
 }
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -715,14 +715,8 @@
 Env.setValue(Loc, *Val);
 
 if (Type->isStructureOrClassType()) {
-  // Unnamed bitfields are only used for padding and are not appearing in
-  // `InitListExpr`'s inits. However, those fields do appear in RecordDecl's
-  // field list, and we thus need to remove them before mapping inits to
-  // fields to avoid mapping inits to the wrongs fields.
-  std::vector Fields;
-  llvm::copy_if(
-  Type->getAsRecordDecl()->fields(), std::back_inserter(Fields),
-  [](const FieldDecl *Field) { return !Field->isUnnamedBitfield(); });
+  std::vector Fields =
+  getFieldsForInitListExpr(Type->getAsRecordDecl());
   for (auto It : llvm::zip(Fields, S->inits())) {
 const FieldDecl *Field = std::get<0>(It);
 assert(Field != nullptr);
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -212,6 +212,10 @@
 insertIfFunction(*VD, Funcs);
 if (const auto *FD = dyn_cast(VD))
   Fields.insert(FD);
+  } else if (auto *InitList = dyn_cast(&S)) {
+if (RecordDecl *RD = InitList->getType()->getAsRecordDecl())
+  for (const auto *FD : getFieldsForInitListExpr(RD))
+Fields.insert(FD);
   }
 }
 
@@ -955,5 +959,17 @@
   return cast(Loc);
 }
 
+std::vector getFieldsForInitListExpr(const RecordDecl *RD) {
+  // Unnamed bitfields are only used for padding and do not appear in
+  // `InitListExpr`'s inits. However, those fields do appear in `RecordDecl`'s
+  // field list, and we thus need to remove them before mapping inits to
+  // fields to avoid mapping inits to the wrongs fields.
+  std::vector Fields;
+  llvm::copy_if(
+  RD->fields(), std::back_inserter(Fields),
+  [](const FieldDecl *Field) { return !Field->isUnnamedBitfield(); });
+  return Fields;
+}
+
 } // namespace dataflow
 } // namespace clang
Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -644,6 +644,10 @@
 AggregateStorageLocation *getBaseObjectLocation(const MemberExpr &ME,
 const Environment &Env);
 
+/// Returns the fields of `RD` that are initialized by an `InitListExpr`, in the
+/// order in which they appear in `InitListExpr::inits()`.
+std::vector getFieldsForInitListExpr(const RecordDec

[PATCH] D154962: [clangd] Use canonical path as resolved path for includes.

2023-07-11 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154962

Files:
  clang-tools-extra/clangd/Headers.cpp


Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/Path.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -53,8 +54,11 @@
   auto &Inc = Out->MainFileIncludes.back();
   Inc.Written =
   (IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").str();
-  Inc.Resolved =
-  std::string(File ? File->getFileEntry().tryGetRealPathName() : "");
+  auto CanonicalPath =
+  File ? getCanonicalPath(File->getFileEntry().getLastRef(),
+  SM.getFileManager())
+   : std::nullopt;
+  Inc.Resolved = std::string(CanonicalPath ? *CanonicalPath : "");
   Inc.HashOffset = SM.getFileOffset(HashLoc);
   Inc.HashLine =
   SM.getLineNumber(SM.getFileID(HashLoc), Inc.HashOffset) - 1;


Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/Path.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -53,8 +54,11 @@
   auto &Inc = Out->MainFileIncludes.back();
   Inc.Written =
   (IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").str();
-  Inc.Resolved =
-  std::string(File ? File->getFileEntry().tryGetRealPathName() : "");
+  auto CanonicalPath =
+  File ? getCanonicalPath(File->getFileEntry().getLastRef(),
+  SM.getFileManager())
+   : std::nullopt;
+  Inc.Resolved = std::string(CanonicalPath ? *CanonicalPath : "");
   Inc.HashOffset = SM.getFileOffset(HashLoc);
   Inc.HashLine =
   SM.getLineNumber(SM.getFileID(HashLoc), Inc.HashOffset) - 1;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154963: [Format][Tooling] Fix HeaderIncludes::insert not respect the main-file header.

2023-07-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: sammccall, kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added projects: clang, clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154963

Files:
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Tooling/HeaderIncludesTest.cpp


Index: clang/unittests/Tooling/HeaderIncludesTest.cpp
===
--- clang/unittests/Tooling/HeaderIncludesTest.cpp
+++ clang/unittests/Tooling/HeaderIncludesTest.cpp
@@ -143,6 +143,17 @@
   EXPECT_NE(Expected, insert(Code, "")) << "Not main header";
 }
 
+TEST_F(HeaderIncludesTest, InsertMainHeader) {
+  std::string Code = R"cpp(#include "a.h")cpp";
+  std::string Expected = R"cpp(#include "fix.h"
+#include "a.h")cpp";
+
+  Style = format::getGoogleStyle(format::FormatStyle::LanguageKind::LK_Cpp)
+  .IncludeStyle;
+  FileName = "fix.cpp";
+  EXPECT_EQ(Expected, insert(Code, "\"fix.h\""));
+}
+
 TEST_F(HeaderIncludesTest, InsertBeforeSystemHeaderLLVM) {
   std::string Code = "#include \n"
  "\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -335,7 +335,7 @@
   // Only record the offset of current #include if we can insert after it.
   if (CurInclude.R.getOffset() <= MaxInsertOffset) {
 int Priority = Categories.getIncludePriority(
-CurInclude.Name, /*CheckMainHeader=*/FirstIncludeOffset < 0);
+CurInclude.Name, /*CheckMainHeader=*/true);
 CategoryEndOffsets[Priority] = NextLineOffset;
 IncludesByPriority[Priority].push_back(&CurInclude);
 if (FirstIncludeOffset < 0)
@@ -362,7 +362,7 @@
   std::string(llvm::formatv(IsAngled ? "<{0}>" : "\"{0}\"", IncludeName));
   StringRef QuotedName = Quoted;
   int Priority = Categories.getIncludePriority(
-  QuotedName, /*CheckMainHeader=*/FirstIncludeOffset < 0);
+  QuotedName, /*CheckMainHeader=*/true);
   auto CatOffset = CategoryEndOffsets.find(Priority);
   assert(CatOffset != CategoryEndOffsets.end());
   unsigned InsertOffset = CatOffset->second; // Fall back offset
Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -311,12 +311,9 @@
   Results = {};
   Results.Missing.push_back("\"d.h\"");
   Code = R"cpp(#include "a.h")cpp";
-  // FIXME: this isn't correct, the main-file header d.h should be added before
-  // a.h.
   EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
-R"cpp(#include "a.h"
-#include "d.h"
-)cpp");
+R"cpp(#include "d.h"
+#include "a.h")cpp");
 }
 
 MATCHER_P3(expandedAt, FileID, Offset, SM, "") {


Index: clang/unittests/Tooling/HeaderIncludesTest.cpp
===
--- clang/unittests/Tooling/HeaderIncludesTest.cpp
+++ clang/unittests/Tooling/HeaderIncludesTest.cpp
@@ -143,6 +143,17 @@
   EXPECT_NE(Expected, insert(Code, "")) << "Not main header";
 }
 
+TEST_F(HeaderIncludesTest, InsertMainHeader) {
+  std::string Code = R"cpp(#include "a.h")cpp";
+  std::string Expected = R"cpp(#include "fix.h"
+#include "a.h")cpp";
+
+  Style = format::getGoogleStyle(format::FormatStyle::LanguageKind::LK_Cpp)
+  .IncludeStyle;
+  FileName = "fix.cpp";
+  EXPECT_EQ(Expected, insert(Code, "\"fix.h\""));
+}
+
 TEST_F(HeaderIncludesTest, InsertBeforeSystemHeaderLLVM) {
   std::string Code = "#include \n"
  "\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -335,7 +335,7 @@
   // Only record the offset of current #include if we can insert after it.
   if (CurInclude.R.getOffset() <= MaxInsertOffset) {
 int Priority = Categories.getIncludePriority(
-CurInclude.Name, /*CheckMainHeader=*/FirstIncludeOffset < 0);
+CurInclude.Name, /*CheckMainHeader=*/true);
 CategoryEndOffsets[Priority] = NextLineOffset;
 IncludesByPriority[Priority].push_back(&CurInclude);
 if (FirstIncludeOffset < 0)
@@ -362,7 +362,7 @@
   std::string(llvm::formatv(IsAngled ? "<{0}>" : "\"{0}\"", IncludeName));
   StringRef QuotedName = Quoted;
   int Priority = Categories.getIncludePriority(
-  QuotedName, /*CheckMainHeader=*/FirstIncludeOffset < 0);
+  QuotedName, /*CheckMainHeader=*/true);
   auto CatOffset = CategoryEndOffsets.find(Priority);
   assert(CatOffset != CategoryEndOffsets.end());
   unsigned InsertOffse

[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

2023-07-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for the fix! This generally LGTM, but I did find some extra test 
cases to add.




Comment at: clang/test/AST/ast-print-method-decl.cpp:1
+// RUN: %clang_cc1 -ast-print %s -o - | FileCheck %s
+

I think the file should be named `ast-print-delegating-constructor.cpp`, WDYT?



Comment at: clang/test/AST/ast-print-method-decl.cpp:15
+  // CHECK-NEXT: };
+};

I'd also like to see test cases along the lines of:
```
struct B {
  template 
  B(Ty);
  B(int X) : B((float)X) {}
};

struct C {
  C(auto);
  C(int) : C("") {}
};
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154186

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-11 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:507
 
+  // C++ [basic.scope.hiding]p2:
+  //   A class name or enumeration name can be hidden by the name of

shafik wrote:
> This section does not exist anymore, it was replaced in 
> [p1787](https://wg21.link/p1787) which resolved a very large number of DRs 
> and reflector discussions. I have not fully digested the paper myself but 
> this change should reflect the new wording as it exists in the current draft. 
It looks like https://eel.is/c++draft/basic.lookup#general-4 is the same thing 
but worded differently. That draft hasn't gone into a published standard 
though, and could change before it gets published, and the same section is 
referenced elsewhere in this file (and there are probably other references in 
this file to parts of the standard that will get changed in the next version), 
so I think it would make more sense to change all such comments at once when 
that change has gone into a published version of the standard.



Comment at: clang/test/SemaCXX/using-hiding.cpp:20
+
+// Using declaration causes A::X to be hidden, so X is not ambiguous.
+namespace Test2 {

shafik wrote:
> I think [namespace.udecl p10](https://eel.is/c++draft/namespace.udecl#10) 
> disagrees, specifically:
> 
> ```
>  using A::g;   // error: conflicts with B​::​g
> ```
> 
> but I may be misreading CC @Endill who has been looking at p1787r6 in details 
> where a lot of this wording changed.
I think that would mean that the using-declaration is ill-formed (i.e. we would 
give an error before we even arrived at looking up the name X). I'll try to 
adjust these tests so that they won't fail due to this when clang implements 
this behaviour.


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

https://reviews.llvm.org/D154503

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


[PATCH] D154962: [clangd] Use canonical path as resolved path for includes.

2023-07-11 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/Headers.cpp:57-61
+  auto CanonicalPath =
+  File ? getCanonicalPath(File->getFileEntry().getLastRef(),
+  SM.getFileManager())
+   : std::nullopt;
+  Inc.Resolved = std::string(CanonicalPath ? *CanonicalPath : "");

`File` is already a `OptionalFileEntryRef`, no need to go to a `FileEntry` and 
back into a `FileEntryRef`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154962

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


[PATCH] D154903: clangd: Provide the resource dir via environment variable

2023-07-11 Thread Paul Smith via Phabricator via cfe-commits
madscientist added a comment.

Thanks for adding Sam.  I tried to do this but failed: his Phabricator handle 
isn't available in CODE_OWNERS.txt and my attempts to add him via his email 
address failed.  I have no Phabricator fu!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154903

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


[PATCH] D154295: [Driver][MSVC] Support DWARF fission when using LTO on Windows

2023-07-11 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D154295#4482818 , @HaohaiWen wrote:

> In D154295#4477203 , @hans wrote:
>
>> In D154295#4477165 , @HaohaiWen 
>> wrote:
>>
 It would be nice to have some documentation for this feature though.
>>>
>>> This feature is same as Linux -gsplit-dwarf.
>>
>> Right, but it would be nice to document that clang-cl supports it (which is 
>> not obvious since it's mostly trying to be cl.exe compatible).
>
> Do you know which doc file should be updated? I haven't found a doc describe 
> -gdwarf for Windows.

I'd suggest putting it under 
https://clang.llvm.org/docs/UsersManual.html#clang-cl

But it seems we might not even have any docs for `-gsplit-dwarf` on non-Windows 
either, I suppose this is already as documented as it was before :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154295

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


[PATCH] D154965: [clang][dataflow] Fix initializaing a reference field with an `InitListExpr`.

2023-07-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I added a test for this as the ongoing migration to strict handling of value
categories (see https://discourse.llvm.org/t/70086) will change the code that
handles this case. It turns out we already didn't handle this correctly, so I
fixed the existing implementation.

Depends On D154961 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154965

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


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2912,6 +2912,34 @@
   }
 }
 
+TEST(TransferTest, AggregateInitializationReferenceField) {
+  std::string Code = R"(
+struct S {
+  int &RefField;
+};
+
+void target(int i) {
+  S s = { i };
+  /*[[p]]*/
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *RefFieldDecl = findValueDecl(ASTCtx, "RefField");
+
+auto &ILoc = getLocForDecl(ASTCtx, Env, "i");
+auto &SLoc = getLocForDecl(ASTCtx, Env, "s");
+
+auto &RefValue =
+*cast(getFieldValue(&SLoc, *RefFieldDecl, Env));
+EXPECT_EQ(&RefValue.getReferentLoc(), &ILoc);
+  });
+}
+
 TEST(TransferTest, AssignToUnionMember) {
   std::string Code = R"(
 union A {
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -724,7 +724,11 @@
 const Expr *Init = std::get<1>(It);
 assert(Init != nullptr);
 
-if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
+if (Field->getType()->isReferenceType()) {
+  if (StorageLocation *Loc = Env.getStorageLocationStrict(*Init))
+cast(Val)->setChild(*Field,
+ Env.create(*Loc));
+} else if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
   cast(Val)->setChild(*Field, *InitVal);
   }
 }


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2912,6 +2912,34 @@
   }
 }
 
+TEST(TransferTest, AggregateInitializationReferenceField) {
+  std::string Code = R"(
+struct S {
+  int &RefField;
+};
+
+void target(int i) {
+  S s = { i };
+  /*[[p]]*/
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *RefFieldDecl = findValueDecl(ASTCtx, "RefField");
+
+auto &ILoc = getLocForDecl(ASTCtx, Env, "i");
+auto &SLoc = getLocForDecl(ASTCtx, Env, "s");
+
+auto &RefValue =
+*cast(getFieldValue(&SLoc, *RefFieldDecl, Env));
+EXPECT_EQ(&RefValue.getReferentLoc(), &ILoc);
+  });
+}
+
 TEST(TransferTest, AssignToUnionMember) {
   std::string Code = R"(
 union A {
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -724,7 +724,11 @@
 const Expr *Init = std::get<1>(It);
 assert(Init != nullptr);
 
-if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
+if (Field->getType()->isReferenceType()) {
+  if (StorageLocation *Loc = Env.getStorageLocationStrict(*Init))
+cast(Val)->setChild(*Field,
+ Env.create(*Loc));
+} else if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
   cast(Val)->setChild(*Field, *InitVal);
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154935: [clang][dataflow] Introduce `getFieldValue()` test helpers.

2023-07-11 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.



Comment at: 
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp:94
   Environment Env(DAContext, *Fun);
-  Value *Val = Env.createValue(Ty);
-  ASSERT_NE(Val, nullptr);
-  StructValue *SVal = clang::dyn_cast(Val);
-  ASSERT_NE(SVal, nullptr);
-  Val = SVal->getChild(*R);
-  ASSERT_NE(Val, nullptr);
-  PointerValue *PV = clang::dyn_cast(Val);
-  EXPECT_NE(PV, nullptr);
+  StructValue *SVal = clang::cast(Env.createValue(Ty));
+  PointerValue *PV = cast_or_null(getFieldValue(SVal, *R, Env));




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154935

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-11 Thread John Brawn via Phabricator via cfe-commits
john.brawn added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:542
+N = Decls.size();
+  }
+

rjmccall wrote:
> john.brawn wrote:
> > rjmccall wrote:
> > > This is going to fire on every single ordinary lookup that finds multiple 
> > > declarations, right?  I haven't fully internalized the issue you're 
> > > solving here, but this is a very performance-sensitive path in the 
> > > compiler; there's a reason this code is written to very carefully only do 
> > > extra work when we've detected in the loop below that we're in a 
> > > hidden-declarations situation.  Is there any way we can restore that 
> > > basic structure?
> > Test4 in the added tests is an example of why we can't wait until after the 
> > main loop. The `using A::X` in namespace D is eliminated by the 
> > UniqueResult check, so the check for a declaration being hidden can only 
> > see the using declarations in namespace C. We also can't do it in the loop 
> > itself, as then we can't handle Test5: at the time we process the `using 
> > A::X` in namespace D it looks like it may cause ambiguity, but it's later 
> > hidden by the `using B::X` in the same namespace which we haven't yet 
> > processed.
> > 
> > I have adjusted it though so the nested loop and erasing of decls only 
> > happens when we both have things that hide and things that can be hidden. 
> > Doing some quick testing of compiling SemaOpenMP.cpp (the largest file in 
> > clang), LookupResult::resolveKind is called 75318 times, of which 75283 
> > calls have HideTags=true, of which 56 meet this condition, i.e. 0.07%.
> Okay, I can see why you need to not mix tag-hiding with the removal of 
> duplicates.  However, I think you can maintain the current structure by 
> delaying the actual removal of declarations until after the main loop; have 
> the loop build up a set of indices to remove instead.  (Also, you can keep 
> this set as a bitset instead of a `std::set`.)
> 
> It's a shame that the hiding algorithm has to check every other declaration 
> in the lookup in case they're from different scopes.  I guess to avoid that 
> we'd have to do the filtering immediately when we collect the declarations 
> from a particular DC.
I think that delaying the removal until after the main loop would just 
complicate things, as then in the main loop we would have to check each index 
to see if it's something we're going to later remove. I can adjust it to do the 
erasing more like it's done in the main loop though, i.e. move the erased 
element to the end and decrement N, so the call to Decls.truncate will remove 
it. We can't use bitset though, as that takes the size of the bitset (which in 
this case would be the number of decls) as a template parameter.


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

https://reviews.llvm.org/D154503

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


[PATCH] D154969: [dataflow] document flow condition

2023-07-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: ymandel.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

There's some documentation of this concept at
https://clang.llvm.org/docs/DataFlowAnalysisIntro.html
but it would be nice to have it closer to the code.

I also was laboring under an obvious but wrong mental model that
the flow condition token represented "execution reached this point",
I'd like to explicitly call that out as wrong.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154969

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h


Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -22,6 +22,7 @@
 #include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/Formula.h"
 #include "clang/Analysis/FlowSensitive/Logger.h"
 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
@@ -524,16 +525,30 @@
 arena().makeEquals(LHS.formula(), RHS.formula()));
   }
 
-  /// Returns the token that identifies the flow condition of the environment.
+  /// Returns a boolean variable that identifies the flow condition.
+  ///
+  /// The flow condition is a set of facts that are necessarily true when the
+  /// program reaches the current point, expressed as boolean formulas.
+  /// The flow condition token is equivalent to the AND of these facts.
+  ///
+  /// These may e.g. constrain the value of certain variables. A pointer
+  /// variable may have a consistent modeled PointerValue throughout, but at a
+  /// given point the Environment may tell us that the value must be non-null.
+  ///
+  /// The FC is necessary but not sufficient for this point to be reachable.
+  /// In particular, where the FC token appears in flow conditions of successor
+  /// environments, it means "point X may have been reached", not
+  /// "point X was reached".
   Atom getFlowConditionToken() const { return FlowConditionToken; }
 
-  /// Adds `Val` to the set of clauses that constitute the flow condition.
+  /// Record a fact that must be true if this point in the program is reached.
   void addToFlowCondition(const Formula &);
   /// Deprecated: Use Formula version instead.
   void addToFlowCondition(BoolValue &Val);
 
-  /// Returns true if and only if the clauses that constitute the flow 
condition
-  /// imply that `Val` is true.
+  /// Returns true if the formula is always true when this point is reached.
+  /// Returns false if the formula may be false, or if the flow condition isn't
+  /// sufficiently precise to prove that it is true.
   bool flowConditionImplies(const Formula &) const;
   /// Deprecated: Use Formula version instead.
   bool flowConditionImplies(BoolValue &Val) const;


Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -22,6 +22,7 @@
 #include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/Formula.h"
 #include "clang/Analysis/FlowSensitive/Logger.h"
 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
@@ -524,16 +525,30 @@
 arena().makeEquals(LHS.formula(), RHS.formula()));
   }
 
-  /// Returns the token that identifies the flow condition of the environment.
+  /// Returns a boolean variable that identifies the flow condition.
+  ///
+  /// The flow condition is a set of facts that are necessarily true when the
+  /// program reaches the current point, expressed as boolean formulas.
+  /// The flow condition token is equivalent to the AND of these facts.
+  ///
+  /// These may e.g. constrain the value of certain variables. A pointer
+  /// variable may have a consistent modeled PointerValue throughout, but at a
+  /// given point the Environment may tell us that the value must be non-null.
+  ///
+  /// The FC is necessary but not sufficient for this point to be reachable.
+  /// In particular, where the FC token appears in flow conditions of successor
+  /// environments, it means "point X may have been reached", not
+  /// "point X was reached".
   Atom getFlowConditionToken() con

[PATCH] D154905: [clang] Implement `PointerLikeTraits` for `{File,Directory}EntryRef`

2023-07-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 539089.
jansvoboda11 added a comment.

Forward `NumLowBitsAvailable` to `PointerLikeTypeTraits` of the underlying 
pointer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154905

Files:
  clang/include/clang/Basic/DirectoryEntry.h
  clang/include/clang/Basic/FileEntry.h
  clang/include/clang/Basic/Module.h
  clang/lib/Basic/Module.cpp
  clang/lib/Lex/ModuleMap.cpp

Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -1162,7 +1162,7 @@
 Module *Mod, FileEntryRef UmbrellaHeader, const Twine &NameAsWritten,
 const Twine &PathRelativeToRootModuleDirectory) {
   Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader));
-  Mod->Umbrella = &UmbrellaHeader.getMapEntry();
+  Mod->Umbrella = UmbrellaHeader;
   Mod->UmbrellaAsWritten = NameAsWritten.str();
   Mod->UmbrellaRelativeToRootModuleDirectory =
   PathRelativeToRootModuleDirectory.str();
@@ -1176,7 +1176,7 @@
 void ModuleMap::setUmbrellaDirAsWritten(
 Module *Mod, DirectoryEntryRef UmbrellaDir, const Twine &NameAsWritten,
 const Twine &PathRelativeToRootModuleDirectory) {
-  Mod->Umbrella = &UmbrellaDir.getMapEntry();
+  Mod->Umbrella = UmbrellaDir;
   Mod->UmbrellaAsWritten = NameAsWritten.str();
   Mod->UmbrellaRelativeToRootModuleDirectory =
   PathRelativeToRootModuleDirectory.str();
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -264,10 +264,10 @@
 }
 
 OptionalDirectoryEntryRef Module::getEffectiveUmbrellaDir() const {
-  if (const auto *ME = Umbrella.dyn_cast())
-return FileEntryRef(*ME).getDir();
-  if (const auto *ME = Umbrella.dyn_cast())
-return DirectoryEntryRef(*ME);
+  if (Umbrella && Umbrella.is())
+return Umbrella.get().getDir();
+  if (Umbrella && Umbrella.is())
+return Umbrella.get();
   return std::nullopt;
 }
 
Index: clang/include/clang/Basic/Module.h
===
--- clang/include/clang/Basic/Module.h
+++ clang/include/clang/Basic/Module.h
@@ -156,9 +156,7 @@
   std::string PresumedModuleMapFile;
 
   /// The umbrella header or directory.
-  llvm::PointerUnion
-  Umbrella;
+  llvm::PointerUnion Umbrella;
 
   /// The module signature.
   ASTFileSignature Signature;
@@ -650,19 +648,18 @@
 
   /// Retrieve the umbrella directory as written.
   std::optional getUmbrellaDirAsWritten() const {
-if (const auto *ME =
-Umbrella.dyn_cast())
+if (Umbrella && Umbrella.is())
   return DirectoryName{UmbrellaAsWritten,
UmbrellaRelativeToRootModuleDirectory,
-   DirectoryEntryRef(*ME)};
+   Umbrella.get()};
 return std::nullopt;
   }
 
   /// Retrieve the umbrella header as written.
   std::optional getUmbrellaHeaderAsWritten() const {
-if (const auto *ME = Umbrella.dyn_cast())
+if (Umbrella && Umbrella.is())
   return Header{UmbrellaAsWritten, UmbrellaRelativeToRootModuleDirectory,
-FileEntryRef(*ME)};
+Umbrella.get()};
 return std::nullopt;
   }
 
Index: clang/include/clang/Basic/FileEntry.h
===
--- clang/include/clang/Basic/FileEntry.h
+++ clang/include/clang/Basic/FileEntry.h
@@ -234,6 +234,21 @@
 } // namespace clang
 
 namespace llvm {
+
+template <> struct PointerLikeTypeTraits {
+  static inline void *getAsVoidPointer(clang::FileEntryRef File) {
+return const_cast(&File.getMapEntry());
+  }
+
+  static inline clang::FileEntryRef getFromVoidPointer(void *Ptr) {
+return clang::FileEntryRef(
+*reinterpret_cast(Ptr));
+  }
+
+  static constexpr int NumLowBitsAvailable = PointerLikeTypeTraits<
+  const clang::FileEntryRef::MapEntry *>::NumLowBitsAvailable;
+};
+
 /// Specialisation of DenseMapInfo for FileEntryRef.
 template <> struct DenseMapInfo {
   static inline clang::FileEntryRef getEmptyKey() {
Index: clang/include/clang/Basic/DirectoryEntry.h
===
--- clang/include/clang/Basic/DirectoryEntry.h
+++ clang/include/clang/Basic/DirectoryEntry.h
@@ -72,7 +72,7 @@
   bool isSameRef(DirectoryEntryRef RHS) const { return ME == RHS.ME; }
 
   DirectoryEntryRef() = delete;
-  DirectoryEntryRef(const MapEntry &ME) : ME(&ME) {}
+  explicit DirectoryEntryRef(const MapEntry &ME) : ME(&ME) {}
 
   /// Allow DirectoryEntryRef to degrade into 'const DirectoryEntry*' to
   /// facilitate incremental adoption.
@@ -197,6 +197,21 @@
 } // namespace clang
 
 namespace llvm {
+
+template <> struct PointerLikeTypeTraits {
+  static inline void *getAsVoidPointer(clang::DirectoryEntryRef Dir) {
+   

[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-11 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:542
+N = Decls.size();
+  }
+

john.brawn wrote:
> rjmccall wrote:
> > john.brawn wrote:
> > > rjmccall wrote:
> > > > This is going to fire on every single ordinary lookup that finds 
> > > > multiple declarations, right?  I haven't fully internalized the issue 
> > > > you're solving here, but this is a very performance-sensitive path in 
> > > > the compiler; there's a reason this code is written to very carefully 
> > > > only do extra work when we've detected in the loop below that we're in 
> > > > a hidden-declarations situation.  Is there any way we can restore that 
> > > > basic structure?
> > > Test4 in the added tests is an example of why we can't wait until after 
> > > the main loop. The `using A::X` in namespace D is eliminated by the 
> > > UniqueResult check, so the check for a declaration being hidden can only 
> > > see the using declarations in namespace C. We also can't do it in the 
> > > loop itself, as then we can't handle Test5: at the time we process the 
> > > `using A::X` in namespace D it looks like it may cause ambiguity, but 
> > > it's later hidden by the `using B::X` in the same namespace which we 
> > > haven't yet processed.
> > > 
> > > I have adjusted it though so the nested loop and erasing of decls only 
> > > happens when we both have things that hide and things that can be hidden. 
> > > Doing some quick testing of compiling SemaOpenMP.cpp (the largest file in 
> > > clang), LookupResult::resolveKind is called 75318 times, of which 75283 
> > > calls have HideTags=true, of which 56 meet this condition, i.e. 0.07%.
> > Okay, I can see why you need to not mix tag-hiding with the removal of 
> > duplicates.  However, I think you can maintain the current structure by 
> > delaying the actual removal of declarations until after the main loop; have 
> > the loop build up a set of indices to remove instead.  (Also, you can keep 
> > this set as a bitset instead of a `std::set`.)
> > 
> > It's a shame that the hiding algorithm has to check every other declaration 
> > in the lookup in case they're from different scopes.  I guess to avoid that 
> > we'd have to do the filtering immediately when we collect the declarations 
> > from a particular DC.
> I think that delaying the removal until after the main loop would just 
> complicate things, as then in the main loop we would have to check each index 
> to see if it's something we're going to later remove. I can adjust it to do 
> the erasing more like it's done in the main loop though, i.e. move the erased 
> element to the end and decrement N, so the call to Decls.truncate will remove 
> it. We can't use bitset though, as that takes the size of the bitset (which 
> in this case would be the number of decls) as a template parameter.
llvm::BitVector should work for this. 


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

https://reviews.llvm.org/D154503

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


[PATCH] D154905: [clang] Implement `PointerLikeTraits` for `{File,Directory}EntryRef`

2023-07-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 marked an inline comment as done.
jansvoboda11 added inline comments.



Comment at: clang/include/clang/Basic/DirectoryEntry.h:211
+
+  static constexpr int NumLowBitsAvailable = 3;
+};

benlangmuir wrote:
> I suggest not hard-coding it if you can get away with it; maybe 
> `PointerLikeTypeTraits *>::NumLowBitsAvailable`? I think 3 could be wrong on a 32-bit platform for 
> example.
Good idea, updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154905

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


[PATCH] D154701: [clang] Overridden CXXMethodDecl::isVirtual() assertion failed before fully imported.

2023-07-11 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

It is possible to reproduce the same problem with this test added to 
ASTImporterTest.cpp:

  TEST_P(ASTImporterOptionSpecificTestBase, ImportVirtualOverriddenMethodTest) {
const char *Code =
R"(
void f1();
class A {
  virtual void f(){}
};
class B: public A {
  void f() override {
f1();
  }
};
class C: public B {
  void f() override {}
};
void f1() { C c; }
)";
Decl *FromTU = getTuDecl(Code, Lang_CXX11);
  
auto *FromF = FirstDeclMatcher().match(
FromTU, cxxMethodDecl(hasName("B::f")));
  
auto *ToBF = Import(FromF, Lang_CXX11);
EXPECT_TRUE(ToBF->isVirtual());
  
auto *ToCF = FirstDeclMatcher().match(
ToBF->getTranslationUnitDecl(), cxxMethodDecl(hasName("C::f")));
EXPECT_TRUE(ToCF->isVirtual());
  }

I am not opposed to removal of the assertion as fix because it looks not very 
important (probably it can be replaced by another assertion for example to not 
allow constructors here, see this 

 commit) but another person in the AST area should check this.




Comment at: clang/test/Analysis/ctu-astimport-virtual-assertion/main.cpp:22
+
+#include "Inputs/input.h"

Such tests are not in the //Analysis// folder but in the //ASTMerge// folder 
instead. I would say that this test is not necessary if the other test (in my 
added note) is inserted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154701

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


[clang] 7d6c2e1 - [clang] Use llvm.is_fpclass to implement FP classification functions

2023-07-11 Thread Serge Pavlov via cfe-commits

Author: Serge Pavlov
Date: 2023-07-11T21:34:53+07:00
New Revision: 7d6c2e18114de9900d1b012cf9c219803b183f63

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

LOG: [clang] Use llvm.is_fpclass to implement FP classification functions

Builtin floating-point number classification functions:

- __builtin_isnan,
- __builtin_isinf,
- __builtin_finite, and
- __builtin_isnormal

now are implemented using `llvm.is_fpclass`.

This change makes the target callback `TargetCodeGenInfo::testFPKind`
unneeded. It is preserved in this change and should be removed later.

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/X86/strictfp_builtins.c
clang/test/CodeGen/aarch64-strictfp-builtins.c
clang/test/CodeGen/builtin_float.c
clang/test/CodeGen/builtin_float_strictfp.c
clang/test/CodeGen/builtins.c
clang/test/CodeGen/isfpclass.c
clang/test/CodeGen/strictfp_builtins.c
clang/test/Headers/__clang_hip_math.hip
clang/test/Headers/hip-header.hip
clang/test/Headers/openmp_device_math_isnan.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 088fb46faee5d8..1fbf29abcaae54 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -31,6 +31,7 @@
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/FloatingPointMode.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Analysis/ValueTracking.h"
@@ -2239,6 +2240,17 @@ static unsigned mutateLongDoubleBuiltin(unsigned 
BuiltinID) {
   }
 }
 
+static Value *tryUseTestFPKind(CodeGenFunction &CGF, unsigned BuiltinID,
+   Value *V) {
+  if (CGF.Builder.getIsFPConstrained() &&
+  CGF.Builder.getDefaultConstrainedExcept() != fp::ebIgnore) {
+if (Value *Result =
+CGF.getTargetHooks().testFPKind(V, BuiltinID, CGF.Builder, 
CGF.CGM))
+  return Result;
+  }
+  return nullptr;
+}
+
 RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned 
BuiltinID,
 const CallExpr *E,
 ReturnValueSlot ReturnValue) {
@@ -3122,37 +3134,49 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 // ZExt bool to int type.
 return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType(;
   }
+
   case Builtin::BI__builtin_isnan: {
 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
 Value *V = EmitScalarExpr(E->getArg(0));
-llvm::Type *Ty = V->getType();
-const llvm::fltSemantics &Semantics = Ty->getFltSemantics();
-if (!Builder.getIsFPConstrained() ||
-Builder.getDefaultConstrainedExcept() == fp::ebIgnore ||
-!Ty->isIEEE()) {
-  V = Builder.CreateFCmpUNO(V, V, "cmp");
-  return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType(;
-}
+if (Value *Result = tryUseTestFPKind(*this, BuiltinID, V))
+  return RValue::get(Result);
+return RValue::get(
+Builder.CreateZExt(Builder.createIsFPClass(V, FPClassTest::fcNan),
+   ConvertType(E->getType(;
+  }
 
-if (Value *Result = getTargetHooks().testFPKind(V, BuiltinID, Builder, 
CGM))
+  case Builtin::BI__builtin_isinf: {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+Value *V = EmitScalarExpr(E->getArg(0));
+if (Value *Result = tryUseTestFPKind(*this, BuiltinID, V))
   return RValue::get(Result);
+return RValue::get(
+Builder.CreateZExt(Builder.createIsFPClass(V, FPClassTest::fcInf),
+   ConvertType(E->getType(;
+  }
 
-// NaN has all exp bits set and a non zero significand. Therefore:
-// isnan(V) == ((exp mask - (abs(V) & exp mask)) < 0)
-unsigned bitsize = Ty->getScalarSizeInBits();
-llvm::IntegerType *IntTy = Builder.getIntNTy(bitsize);
-Value *IntV = Builder.CreateBitCast(V, IntTy);
-APInt AndMask = APInt::getSignedMaxValue(bitsize);
-Value *AbsV =
-Builder.CreateAnd(IntV, llvm::ConstantInt::get(IntTy, AndMask));
-APInt ExpMask = APFloat::getInf(Semantics).bitcastToAPInt();
-Value *Sub =
-Builder.CreateSub(llvm::ConstantInt::get(IntTy, ExpMask), AbsV);
-// V = sign bit (Sub) <=> V = (Sub < 0)
-V = Builder.CreateLShr(Sub, llvm::ConstantInt::get(IntTy, bitsize - 1));
-if (bitsize > 32)
-  V = Builder.CreateTrunc(V, ConvertType(E->getType()));
-return RValue::get(V);
+  case Builtin::BIfinite:
+  case Builtin::BI__finite:
+  case Builtin::BIfinitef:
+  case Builtin::BI__finitef:
+  case Builtin:

[PATCH] D112932: Use llvm.is_fpclass to implement FP classification functions

2023-07-11 Thread Serge Pavlov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7d6c2e18114d: [clang] Use llvm.is_fpclass to implement FP 
classification functions (authored by sepavloff).

Changed prior to commit:
  https://reviews.llvm.org/D112932?vs=529156&id=539095#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112932

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/X86/strictfp_builtins.c
  clang/test/CodeGen/aarch64-strictfp-builtins.c
  clang/test/CodeGen/builtin_float.c
  clang/test/CodeGen/builtin_float_strictfp.c
  clang/test/CodeGen/builtins.c
  clang/test/CodeGen/isfpclass.c
  clang/test/CodeGen/strictfp_builtins.c
  clang/test/Headers/__clang_hip_math.hip
  clang/test/Headers/hip-header.hip
  clang/test/Headers/openmp_device_math_isnan.cpp

Index: clang/test/Headers/openmp_device_math_isnan.cpp
===
--- clang/test/Headers/openmp_device_math_isnan.cpp
+++ clang/test/Headers/openmp_device_math_isnan.cpp
@@ -21,18 +21,18 @@
 double math(float f, double d) {
   double r = 0;
   // INT_RETURN: call i32 @__nv_isnanf(float
-  // AMD_INT_RETURN_SAFE: fcmp uno float
-  // AMD_INT_RETURN_FAST: sitofp i32 0 to double
+  // AMD_INT_RETURN_SAFE: call i1 @llvm.is.fpclass.f32(float{{.*}}, i32 3)
+  // AMD_INT_RETURN_FAST: sitofp i32 {{.*}} to double
   // BOOL_RETURN: call i32 @__nv_isnanf(float
-  // AMD_BOOL_RETURN_SAFE: fcmp uno float
-  // AMD_BOOL_RETURN_FAST: icmp ne i32 0, 0
+  // AMD_BOOL_RETURN_SAFE: call i1 @llvm.is.fpclass.f32(float{{.*}}, i32 3)
+  // AMD_BOOL_RETURN_FAST: icmp ne i32 {{.*}}, 0
   r += std::isnan(f);
   // INT_RETURN: call i32 @__nv_isnand(double
-  // AMD_INT_RETURN_SAFE: fcmp uno double
-  // AMD_INT_RETURN_FAST: sitofp i32 0 to double
+  // AMD_INT_RETURN_SAFE: call i1 @llvm.is.fpclass.f64(double{{.*}}, i32 3)
+  // AMD_INT_RETURN_FAST: sitofp i32 {{.*}} to double
   // BOOL_RETURN: call i32 @__nv_isnand(double
-  // AMD_BOOL_RETURN_SAFE: fcmp uno double
-  // AMD_BOOL_RETURN_FAST: icmp ne i32 0, 0
+  // AMD_BOOL_RETURN_SAFE: call i1 @llvm.is.fpclass.f64(double{{.*}}, i32 3)
+  // AMD_BOOL_RETURN_FAST: icmp ne i32 {{.*}}, 0
   r += std::isnan(d);
   return r;
 }
Index: clang/test/Headers/hip-header.hip
===
--- clang/test/Headers/hip-header.hip
+++ clang/test/Headers/hip-header.hip
@@ -120,12 +120,12 @@
   double d = 5.0;
   float f = 5.0;
 
-  // AMD_INT_RETURN: fcmp contract uno float
-  // AMD_BOOL_RETURN: fcmp contract uno float
+  // AMD_INT_RETURN: call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 3)
+  // AMD_BOOL_RETURN: call i1 @llvm.is.fpclass.f32(float {{.*}}, i32 3)
   r += isnan(f);
 
-  // AMD_INT_RETURN: fcmp contract uno double
-  // AMD_BOOL_RETURN: fcmp contract uno double
+  // AMD_INT_RETURN: call i1 @llvm.is.fpclass.f64(double {{.*}}, i32 3)
+  // AMD_BOOL_RETURN: call i1 @llvm.is.fpclass.f64(double {{.*}}, i32 3)
   r += isnan(d);
 
   return r ;
Index: clang/test/Headers/__clang_hip_math.hip
===
--- clang/test/Headers/__clang_hip_math.hip
+++ clang/test/Headers/__clang_hip_math.hip
@@ -1143,9 +1143,8 @@
 
 // DEFAULT-LABEL: @test___finitef(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[TMP0:%.*]] = tail call contract float @llvm.fabs.f32(float [[X:%.*]]) #[[ATTR17:[0-9]+]]
-// DEFAULT-NEXT:[[CMPINF_I:%.*]] = fcmp contract one float [[TMP0]], 0x7FF0
-// DEFAULT-NEXT:[[CONV:%.*]] = zext i1 [[CMPINF_I]] to i32
+// DEFAULT-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X:%.*]], i32 504)
+// DEFAULT-NEXT:[[CONV:%.*]] = zext i1 [[TMP0]] to i32
 // DEFAULT-NEXT:ret i32 [[CONV]]
 //
 // FINITEONLY-LABEL: @test___finitef(
@@ -1158,9 +1157,8 @@
 
 // DEFAULT-LABEL: @test___finite(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[TMP0:%.*]] = tail call contract double @llvm.fabs.f64(double [[X:%.*]]) #[[ATTR17]]
-// DEFAULT-NEXT:[[CMPINF_I:%.*]] = fcmp contract one double [[TMP0]], 0x7FF0
-// DEFAULT-NEXT:[[CONV:%.*]] = zext i1 [[CMPINF_I]] to i32
+// DEFAULT-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f64(double [[X:%.*]], i32 504)
+// DEFAULT-NEXT:[[CONV:%.*]] = zext i1 [[TMP0]] to i32
 // DEFAULT-NEXT:ret i32 [[CONV]]
 //
 // FINITEONLY-LABEL: @test___finite(
@@ -1173,9 +1171,8 @@
 
 // DEFAULT-LABEL: @test___isinff(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[TMP0:%.*]] = tail call contract float @llvm.fabs.f32(float [[X:%.*]]) #[[ATTR17]]
-// DEFAULT-NEXT:[[CMPINF_I:%.*]] = fcmp contract oeq float [[TMP0]], 0x7FF0
-// DEFAULT-NEXT:[[CONV:%.*]] = zext i1 [[CMPINF_I]] to i32
+// DEFAULT-NEXT:[[TMP0:%.*]] = tail call i1 @llvm.is.fpclass.f32(float [[X:%.*]], i32 516)
+// DEFAULT-NEXT:[[CONV:%

[PATCH] D154965: [clang][dataflow] Fix initializaing a reference field with an `InitListExpr`.

2023-07-11 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:720-725
   for (auto It : llvm::zip(Fields, S->inits())) {
 const FieldDecl *Field = std::get<0>(It);
 assert(Field != nullptr);
 
 const Expr *Init = std::get<1>(It);
 assert(Init != nullptr);




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154965

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


[PATCH] D154915: [ARM][AArch64] Add ARM specific builtin for clz that is not undefined for 0 in ubsan.

2023-07-11 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson added a comment.

I would prefer the simplicity of adding a check in the intrinsic itself, rather 
than adding the target-specific builtins. Slightly worse codegen at -O0 doesn't 
matter imho. However I don't feel very strongly about it, so if others are 
happy with this then LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154915

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


[PATCH] D154915: [ARM][AArch64] Add ARM specific builtin for clz that is not undefined for 0 in ubsan.

2023-07-11 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson added a comment.

Also thanks for fixing this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154915

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


[PATCH] D154969: [dataflow] document flow condition

2023-07-11 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:528
 
-  /// Returns the token that identifies the flow condition of the environment.
+  /// Returns a boolean variable that identifies the flow condition.
+  ///

The FC abbreviation is used later, so we should define it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154969

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


[PATCH] D153892: [NFC] Initialize class member pointers to nullptr.

2023-07-11 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann accepted this revision.
tahonermann added a comment.
This revision is now accepted and ready to land.

Thanks, Sindhu! This looks good to me!


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

https://reviews.llvm.org/D153892

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


[PATCH] D152658: [InstCombine] Change SimplifyDemandedVectorElts to use PoisonElts instead of UndefElts

2023-07-11 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito added a comment.
Herald added a subscriber: wangpc.

ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152658

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


[PATCH] D152021: [clang][AIX] Fix Overly Strict LTO Option Checking against `data-sections` when `mxcoff-roptr` is in Effect

2023-07-11 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 539105.
qiongsiwu1 added a comment.

Fixing inconsistent braces. Thanks for the feedback @hubert.reinterpretcast !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152021

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/ppc-roptr.c


Index: clang/test/Driver/ppc-roptr.c
===
--- clang/test/Driver/ppc-roptr.c
+++ clang/test/Driver/ppc-roptr.c
@@ -12,7 +12,7 @@
 // RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=NO_ROPTR
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 
2>&1 | \
-// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR
+// RUN: FileCheck %s 
--check-prefixes=NO_DATA_SECTION_ERR,ROPTR,LINK,LTO_ROPTR
 // RUN: touch %t.o
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | 
\
 // RUN: FileCheck %s --check-prefix=LINK
@@ -33,14 +33,14 @@
 // RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr 
-flto \
 // RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
 
-// ROPTR: "-mxcoff-roptr"
-// LINK: "-bforceimprw"
-// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
-// NO_ROPTR-NOT: "-mxcoff-roptr"
-// NO_ROPTR-NOT: "-bforceimprw"
-
 // DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with 
-fdata-sections
 // NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with 
-fdata-sections
 // TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 
'powerpc64le-unknown-linux-gnu'
 // TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 
'powerpc64le-unknown-linux-gnu'
 // SHARED_ERR: error: -mxcoff-roptr is not supported with -shared
+
+// ROPTR: "-mxcoff-roptr"
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"
+// NO_ROPTR-NOT: "-bforceimprw"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -727,13 +727,16 @@
 CmdArgs.push_back(
 Args.MakeArgString(Twine(PluginOptPrefix) + "-function-sections=0"));
 
+  bool DataSectionsTurnedOff = false;
   if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
-   UseSeparateSections))
+   UseSeparateSections)) {
 CmdArgs.push_back(
 Args.MakeArgString(Twine(PluginOptPrefix) + "-data-sections=1"));
-  else if (Args.hasArg(options::OPT_fno_data_sections))
+  } else if (Args.hasArg(options::OPT_fno_data_sections)) {
+DataSectionsTurnedOff = true;
 CmdArgs.push_back(
 Args.MakeArgString(Twine(PluginOptPrefix) + "-data-sections=0"));
+  }
 
   if (Args.hasArg(options::OPT_mxcoff_roptr) ||
   Args.hasArg(options::OPT_mno_xcoff_roptr)) {
@@ -746,8 +749,10 @@
   << OptStr << ToolChain.getTriple().str();
 
 if (HasRoptr) {
-  if (!Args.hasFlag(options::OPT_fdata_sections,
-options::OPT_fno_data_sections, UseSeparateSections))
+  // The data sections option is on by default on AIX. We only need to 
error
+  // out when -fno-data-sections is specified explicitly to turn off data
+  // sections.
+  if (DataSectionsTurnedOff)
 D.Diag(diag::err_roptr_requires_data_sections);
 
   CmdArgs.push_back(


Index: clang/test/Driver/ppc-roptr.c
===
--- clang/test/Driver/ppc-roptr.c
+++ clang/test/Driver/ppc-roptr.c
@@ -12,7 +12,7 @@
 // RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=NO_ROPTR
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 2>&1 | \
-// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR
+// RUN: FileCheck %s --check-prefixes=NO_DATA_SECTION_ERR,ROPTR,LINK,LTO_ROPTR
 // RUN: touch %t.o
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | \
 // RUN: FileCheck %s --check-prefix=LINK
@@ -33,14 +33,14 @@
 // RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr -flto \
 // RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
 
-// ROPTR: "-mxcoff-roptr"
-// LINK: "-bforceimprw"
-// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
-// NO_ROPTR-NOT: "-mxcoff-roptr"
-// NO_ROPTR-NOT: "-bforceimprw"
-
 // DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections
 // NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with -fdata-sections
 // TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
 // TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 'powerpc64le-unknown-linux-g

[PATCH] D154969: [dataflow] document flow condition

2023-07-11 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Nice! Definitely should have been defined earlier...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154969

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


[PATCH] D154869: [Flang] [FlangRT] Implement FlangRT library as solution to Flang's runtime LLVM integration

2023-07-11 Thread Paul Scoropan via Phabricator via cfe-commits
pscoro updated this revision to Diff 539113.
pscoro added a comment.

Some small changes, still non functional


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154869

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  flang-rt/CMakeLists.txt
  flang-rt/src/dummy.cpp
  flang/CMakeLists.txt
  flang/cmake/modules/AddFlang.cmake
  flang/include/flang/Runtime/float128.h
  flang/lib/Decimal/CMakeLists.txt
  flang/runtime/CMakeLists.txt
  flang/test/CMakeLists.txt
  flang/test/Driver/linker-flags.f90
  flang/test/lit.cfg.py
  lld/COFF/MinGW.cpp
  llvm/CMakeLists.txt
  llvm/projects/CMakeLists.txt
  runtimes/CMakeLists.txt

Index: runtimes/CMakeLists.txt
===
--- runtimes/CMakeLists.txt
+++ runtimes/CMakeLists.txt
@@ -19,7 +19,7 @@
 
 # We order libraries to mirror roughly how they are layered, except that compiler-rt can depend
 # on libc++, so we put it after.
-set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp")
+set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;flang-rt")
 set(LLVM_SUPPORTED_RUNTIMES "${LLVM_DEFAULT_RUNTIMES};llvm-libgcc")
 set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
   "Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")
Index: llvm/projects/CMakeLists.txt
===
--- llvm/projects/CMakeLists.txt
+++ llvm/projects/CMakeLists.txt
@@ -6,6 +6,7 @@
   if(IS_DIRECTORY ${entry} AND EXISTS ${entry}/CMakeLists.txt)
 if((NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt) AND
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/dragonegg) AND
+   (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/flang-rt) AND
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libcxx) AND
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libcxxabi) AND
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/libunwind) AND
@@ -42,6 +43,8 @@
 add_llvm_external_project(dragonegg)
 add_llvm_external_project(openmp)
 
+add_llvm_external_project(flang-rt)
+
 if(LLVM_INCLUDE_TESTS)
   add_llvm_external_project(cross-project-tests)
 endif()
Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -149,7 +149,10 @@
 # As we migrate runtimes to using the bootstrapping build, the set of default runtimes
 # should grow as we remove those runtimes from LLVM_ENABLE_PROJECTS above.
 set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind")
-set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc")
+if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)
+  set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind;flang-rt")
+endif()
+set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;flang-rt")
 set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
   "Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")
 if(LLVM_ENABLE_RUNTIMES STREQUAL "all")
Index: lld/COFF/MinGW.cpp
===
--- lld/COFF/MinGW.cpp
+++ lld/COFF/MinGW.cpp
@@ -50,8 +50,7 @@
   "libc++",
   "libc++abi",
   "libFortran_main",
-  "libFortranRuntime",
-  "libFortranDecimal",
+  "libflang-rt",
   "libunwind",
   "libmsvcrt",
   "libucrtbase",
Index: flang/test/lit.cfg.py
===
--- flang/test/lit.cfg.py
+++ flang/test/lit.cfg.py
@@ -153,19 +153,16 @@
 # the C++ runtime libraries. For this we need a C compiler. If for some reason
 # we don't have one, we can just disable the test.
 if config.cc:
-libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a")
-libdecimal = os.path.join(config.flang_lib_dir, "libFortranDecimal.a")
+libruntime = os.path.join(config.flang_lib_dir, "libflang-rt.a")
 include = os.path.join(config.flang_src_dir, "include")
 
 if (
 os.path.isfile(libruntime)
-and os.path.isfile(libdecimal)
 and os.path.isdir(include)
 ):
 config.available_features.add("c-compiler")
 tools.append(ToolSubst("%cc", command=config.cc, unresolved="fatal"))
 tools.append(ToolSubst("%libruntime", command=libruntime, unresolved="fatal"))
-tools.append(ToolSubst("%libdecimal", command=libdecimal, unresolved="fatal"))
 tools.append(ToolSubst("%include", command=include, unresolved="fatal"))
 
 # Add all the tools and their substitutions (if applicable). Use the search paths provided for
Index: flang/test/Driver/linker-flags.f90
===
--- fl

[PATCH] D145302: [clangd] Add library for clangd main function

2023-07-11 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko updated this revision to Diff 539119.
ivanmurashko added a comment.

rebase before the final push


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145302

Files:
  clang-tools-extra/clangd/tool/CMakeLists.txt
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/tool/ClangdMain.h
  clang-tools-extra/clangd/tool/ClangdToolMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdToolMain.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/tool/ClangdToolMain.cpp
@@ -0,0 +1,13 @@
+//===--- ClangdToolMain.cpp - clangd main function ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangdMain.h"
+
+int main(int argc, char **argv) {
+  return clang::clangd::clangdMain(argc, argv);
+}
Index: clang-tools-extra/clangd/tool/ClangdMain.h
===
--- /dev/null
+++ clang-tools-extra/clangd/tool/ClangdMain.h
@@ -0,0 +1,19 @@
+//===--- ClangdMain.h - clangd main function ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+
+namespace clang {
+namespace clangd {
+// clangd main function (clangd server loop)
+int clangdMain(int argc, char *argv[]);
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "ClangdMain.h"
 #include "ClangdLSPServer.h"
 #include "CodeComplete.h"
 #include "Compiler.h"
@@ -710,8 +711,6 @@
   }
 };
 } // namespace
-} // namespace clangd
-} // namespace clang
 
 enum class ErrorResultCode : int {
   NoShutdownRequest = 1,
@@ -719,10 +718,7 @@
   CheckFailed = 3
 };
 
-int main(int argc, char *argv[]) {
-  using namespace clang;
-  using namespace clang::clangd;
-
+int clangdMain(int argc, char *argv[]) {
   llvm::InitializeAllTargetInfos();
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::sys::AddSignalHandler(
@@ -1041,3 +1037,6 @@
 
   return ExitCode;
 }
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/tool/CMakeLists.txt
===
--- clang-tools-extra/clangd/tool/CMakeLists.txt
+++ clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -1,6 +1,13 @@
-add_clang_tool(clangd
+# Needed by LLVM's CMake checks because this file defines multiple targets.
+set(LLVM_OPTIONAL_SOURCES ClangdToolMain.cpp)
+
+add_clang_library(clangdMain
   ClangdMain.cpp
   Check.cpp
+  )
+
+add_clang_tool(clangd
+  ClangdToolMain.cpp
   $
   )
 
@@ -13,7 +20,7 @@
   list(APPEND CLANGD_XPC_LIBS "clangdXpcJsonConversions" "clangdXpcTransport")
 endif()
 
-clang_target_link_libraries(clangd
+clang_target_link_libraries(clangdMain
   PRIVATE
   clangAST
   clangBasic
@@ -25,14 +32,14 @@
   clangToolingCore
   clangToolingRefactoring
   clangToolingSyntax
-  )
-
-target_link_libraries(clangd
-  PRIVATE
   clangTidy
-
   clangDaemon
   clangdRemoteIndex
   clangdSupport
   ${CLANGD_XPC_LIBS}
   )
+
+clang_target_link_libraries(clangd
+  PRIVATE
+  clangdMain
+  )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150292: [clang][modules] Serialize `Module::DefinitionLoc`

2023-07-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 539120.
jansvoboda11 added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150292

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -200,7 +200,9 @@
 CB(F);
 FileID FID = SourceMgr.translateFile(F);
 SourceLocation Loc = SourceMgr.getIncludeLoc(FID);
-while (Loc.isValid()) {
+// The include location of inferred module maps can point into the header
+// file that triggered the inferring. Cut off the walk if that's the case.
+while (Loc.isValid() && isModuleMap(SourceMgr.getFileCharacteristic(Loc))) {
   FID = SourceMgr.getFileID(Loc);
   CB(*SourceMgr.getFileEntryRefForID(FID));
   Loc = SourceMgr.getIncludeLoc(FID);
@@ -209,11 +211,18 @@
 
   auto ProcessModuleOnce = [&](const Module *M) {
 for (const Module *Mod = M; Mod; Mod = Mod->Parent)
-  if (ProcessedModules.insert(Mod).second)
+  if (ProcessedModules.insert(Mod).second) {
+auto Insert = [&](FileEntryRef F) { ModuleMaps.insert(F); };
+// The containing module map is affecting, because it's being pointed
+// into by Module::DefinitionLoc.
+if (auto ModuleMapFile = MM.getContainingModuleMapFile(Mod))
+  ForIncludeChain(*ModuleMapFile, Insert);
+// For inferred modules, the module map that allowed inferring is not in
+// the include chain of the virtual containing module map file. It did
+// affect the compilation, though.
 if (auto ModuleMapFile = MM.getModuleMapFileForUniquing(Mod))
-  ForIncludeChain(*ModuleMapFile, [&](FileEntryRef F) {
-ModuleMaps.insert(F);
-  });
+  ForIncludeChain(*ModuleMapFile, Insert);
+  }
   };
 
   for (const Module *CurrentModule : ModulesToProcess) {
@@ -2721,6 +2730,7 @@
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // Kind
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Definition location
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem
@@ -2821,12 +2831,16 @@
   ParentID = SubmoduleIDs[Mod->Parent];
 }
 
+uint64_t DefinitionLoc =
+SourceLocationEncoding::encode(getAdjustedLocation(Mod->DefinitionLoc));
+
 // Emit the definition of the block.
 {
   RecordData::value_type Record[] = {SUBMODULE_DEFINITION,
  ID,
  ParentID,
  (RecordData::value_type)Mod->Kind,
+ DefinitionLoc,
  Mod->IsFramework,
  Mod->IsExplicit,
  Mod->IsSystem,
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -5619,7 +5619,7 @@
   break;
 
 case SUBMODULE_DEFINITION: {
-  if (Record.size() < 12)
+  if (Record.size() < 13)
 return llvm::createStringError(std::errc::illegal_byte_sequence,
"malformed module definition");
 
@@ -5628,6 +5628,7 @@
   SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]);
   SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]);
   Module::ModuleKind Kind = (Module::ModuleKind)Record[Idx++];
+  SourceLocation DefinitionLoc = ReadSourceLocation(F, Record[Idx++]);
   bool IsFramework = Record[Idx++];
   bool IsExplicit = Record[Idx++];
   bool IsSystem = Record[Idx++];
@@ -5648,8 +5649,7 @@
   ModMap.findOrCreateModule(Name, ParentModule, IsFramework, IsExplicit)
   .first;
 
-  // FIXME: set the definition loc for CurrentModule, or call
-  // ModMap.setInferredModuleAllowedBy()
+  // FIXME: Call ModMap.setInferredModuleAllowedBy()
 
   SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS;
   if (GlobalIndex >= SubmodulesLoaded.size() ||
@@ -5678,6 +5678,7 @@
   }
 
   CurrentModule->Kind = Kind;
+  CurrentModule->DefinitionLoc = DefinitionLoc;
   CurrentModule->Signature = F.Signature;
   CurrentModule->IsFromModuleFile = true;
   CurrentModule->IsS

[PATCH] D154962: [clangd] Use canonical path as resolved path for includes.

2023-07-11 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 539121.
VitaNuo added a comment.

Address comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154962

Files:
  clang-tools-extra/clangd/Headers.cpp


Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/Path.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -53,8 +54,9 @@
   auto &Inc = Out->MainFileIncludes.back();
   Inc.Written =
   (IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").str();
-  Inc.Resolved =
-  std::string(File ? File->getFileEntry().tryGetRealPathName() : "");
+  Inc.Resolved = std::string(
+  File ? getCanonicalPath(*File, SM.getFileManager()).value_or("")
+   : "");
   Inc.HashOffset = SM.getFileOffset(HashLoc);
   Inc.HashLine =
   SM.getLineNumber(SM.getFileID(HashLoc), Inc.HashOffset) - 1;


Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/Path.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -53,8 +54,9 @@
   auto &Inc = Out->MainFileIncludes.back();
   Inc.Written =
   (IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").str();
-  Inc.Resolved =
-  std::string(File ? File->getFileEntry().tryGetRealPathName() : "");
+  Inc.Resolved = std::string(
+  File ? getCanonicalPath(*File, SM.getFileManager()).value_or("")
+   : "");
   Inc.HashOffset = SM.getFileOffset(HashLoc);
   Inc.HashLine =
   SM.getLineNumber(SM.getFileID(HashLoc), Inc.HashOffset) - 1;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150320: [clang][modules][deps] Avoid checks for relocated modules

2023-07-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 539122.
jansvoboda11 added a comment.

Rename the new preprocessor option, fix failing test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150320

Files:
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/header-search-pruning-transitive.c

Index: clang/test/ClangScanDeps/header-search-pruning-transitive.c
===
--- clang/test/ClangScanDeps/header-search-pruning-transitive.c
+++ clang/test/ClangScanDeps/header-search-pruning-transitive.c
@@ -72,8 +72,8 @@
 // CHECK:],
 // CHECK-NEXT:   "context-hash": "[[HASH_X:.*]]",
 // CHECK-NEXT:   "file-deps": [
-// CHECK-NEXT: "[[PREFIX]]/./X.h",
-// CHECK-NEXT: "[[PREFIX]]/./module.modulemap"
+// CHECK-NEXT: "[[PREFIX]]/X.h",
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "name": "X"
 // CHECK-NEXT: },
@@ -84,11 +84,11 @@
 // CHECK:],
 // CHECK-NEXT:   "context-hash": "[[HASH_Y_WITH_A]]",
 // CHECK-NEXT:   "file-deps": [
-// CHECK-NEXT: "[[PREFIX]]/./Y.h",
-// CHECK-NEXT: "[[PREFIX]]/./a/a.h",
-// CHECK-NEXT: "[[PREFIX]]/./begin/begin.h",
-// CHECK-NEXT: "[[PREFIX]]/./end/end.h",
-// CHECK-NEXT: "[[PREFIX]]/./module.modulemap"
+// CHECK-NEXT: "[[PREFIX]]/Y.h",
+// CHECK-NEXT: "[[PREFIX]]/a/a.h",
+// CHECK-NEXT: "[[PREFIX]]/begin/begin.h",
+// CHECK-NEXT: "[[PREFIX]]/end/end.h",
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "name": "Y"
 // CHECK-NEXT: }
@@ -126,8 +126,8 @@
 // also has a different context hash from the first version of module X.
 // CHECK-NOT:"context-hash": "[[HASH_X]]",
 // CHECK:"file-deps": [
-// CHECK-NEXT: "[[PREFIX]]/./X.h",
-// CHECK-NEXT: "[[PREFIX]]/./module.modulemap"
+// CHECK-NEXT: "[[PREFIX]]/X.h",
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "name": "X"
 // CHECK-NEXT: },
@@ -138,10 +138,10 @@
 // CHECK:],
 // CHECK-NEXT:   "context-hash": "[[HASH_Y_WITHOUT_A]]",
 // CHECK-NEXT:   "file-deps": [
-// CHECK-NEXT: "[[PREFIX]]/./Y.h",
-// CHECK-NEXT: "[[PREFIX]]/./begin/begin.h",
-// CHECK-NEXT: "[[PREFIX]]/./end/end.h",
-// CHECK-NEXT: "[[PREFIX]]/./module.modulemap"
+// CHECK-NEXT: "[[PREFIX]]/Y.h",
+// CHECK-NEXT: "[[PREFIX]]/begin/begin.h",
+// CHECK-NEXT: "[[PREFIX]]/end/end.h",
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "name": "Y"
 // CHECK-NEXT: }
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -253,6 +253,9 @@
 // context hashing.
 ScanInstance.getHeaderSearchOpts().ModulesStrictContextHash = true;
 
+// Avoid some checks and module map parsing when loading PCM files.
+ScanInstance.getPreprocessorOpts().ModulesCheckRelocated = false;
+
 std::unique_ptr Action;
 
 if (ModuleName)
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -2982,6 +2982,9 @@
   BaseDirectoryAsWritten = Blob;
   assert(!F.ModuleName.empty() &&
  "MODULE_DIRECTORY found before MODULE_NAME");
+  F.BaseDirectory = std::string(Blob);
+  if (!PP.getPreprocessorOpts().ModulesCheckRelocated)
+break;
   // If we've already loaded a module map file covering this module, we may
   // have a better path for it (relative to the current build).
   Module *M = PP.getHeaderSearchInfo().lookupModule(
@@ -3003,8 +3006,6 @@
   }
 }
 F.BaseDirectory = std::string(M->Directory->getName());
-  } else {
-F.BaseDirectory = std::string(Blob);
   }
   break;
 }
@@ -4002,7 +4003,8 @@
   // usable header search context.
   assert(!F.ModuleName.empty() &&
  "MODULE_NAME should come before MODULE_MAP_FILE");
-  if (F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) {
+  if (PP.getPreprocessorOpts().ModulesCheckRelocated &&
+  F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) {
 // An implicitly-loaded module file should have its module listed in some
 // module map file that we've already loaded.
 Module *M =
Index: clang/inc

[PATCH] D154962: [clangd] Use canonical path as resolved path for includes.

2023-07-11 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked an inline comment as done.
VitaNuo added a comment.

Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154962

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


[PATCH] D41416: [modules] [pch] Do not deserialize all lazy template specializations when looking for one.

2023-07-11 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/DeclTemplate.cpp:337
+void RedeclarableTemplateDecl::loadLazySpecializationsImpl(
+ bool OnlyPartial/*=false*/) const 
{
   // Grab the most recent declaration to ensure we've loaded any lazy

`/*=false*/` is this left over code that was meant to be removed?



Comment at: clang/lib/AST/DeclTemplate.cpp:561
 ClassTemplateDecl::getPartialSpecializations() const {
-  LoadLazySpecializations();
+  LoadLazySpecializations(/*PartialOnly = */ true);
   return getCommonPtr()->PartialSpecializations;

nit



Comment at: clang/lib/AST/DeclTemplate.cpp:1294
+void VarTemplateDecl::LoadLazySpecializations(
+ bool OnlyPartial/*=false*/) const 
{
+  loadLazySpecializationsImpl(OnlyPartial);

Was `/*=false*/` meant to be removed?



Comment at: clang/lib/AST/DeclTemplate.cpp:1306
 VarTemplateDecl::getPartialSpecializations() const {
-  LoadLazySpecializations();
+  LoadLazySpecializations(/*PartialOnly = */ true);
   return getCommonPtr()->PartialSpecializations;




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

https://reviews.llvm.org/D41416

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


  1   2   3   >