[PATCH] D140875: [clangd] prototype: Implement unused include warnings with include-cleaner library.

2023-01-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

sorry for the hassle 2133e8b9f942f91ec54e28c580fccf6d6b26c62e 
 should fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140875

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


[clang-tools-extra] 2133e8b - [clangd] Fix shared lib builds

2023-01-19 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-01-20T08:57:21+01:00
New Revision: 2133e8b9f942f91ec54e28c580fccf6d6b26c62e

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

LOG: [clangd] Fix shared lib builds

Added: 


Modified: 
clang-tools-extra/clangd/CMakeLists.txt
clang-tools-extra/clangd/fuzzer/CMakeLists.txt
clang-tools-extra/clangd/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index af8a188056738..183a3666ee58f 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -163,7 +163,6 @@ clang_target_link_libraries(clangDaemon
   clangDriver
   clangFormat
   clangFrontend
-  clangIncludeCleaner
   clangIndex
   clangLex
   clangSema
@@ -179,11 +178,11 @@ target_link_libraries(clangDaemon
   PRIVATE
   ${LLVM_PTHREAD_LIB}
 
+  clangIncludeCleaner
+  clangPseudo
   clangTidy
 
   clangdSupport
-
-  clangPseudo
   )
 if(CLANGD_TIDY_CHECKS)
   target_link_libraries(clangDaemon PRIVATE ${ALL_CLANG_TIDY_CHECKS})

diff  --git a/clang-tools-extra/clangd/fuzzer/CMakeLists.txt 
b/clang-tools-extra/clangd/fuzzer/CMakeLists.txt
index 72feb52e1f02a..9cfaeca189777 100644
--- a/clang-tools-extra/clangd/fuzzer/CMakeLists.txt
+++ b/clang-tools-extra/clangd/fuzzer/CMakeLists.txt
@@ -14,7 +14,6 @@ clang_target_link_libraries(clangd-fuzzer
   clangBasic
   clangFormat
   clangFrontend
-  clangIncludeCleaner
   clangSema
   clangTooling
   clangToolingCore
@@ -22,5 +21,6 @@ clang_target_link_libraries(clangd-fuzzer
 target_link_libraries(clangd-fuzzer
   PRIVATE
   clangDaemon
+  clangIncludeCleaner
   clangdSupport
   )

diff  --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt 
b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index ee278b4365be7..a68d8cb0b78ff 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -164,11 +164,13 @@ clang_target_link_libraries(ClangdTests
   )
 target_link_libraries(ClangdTests
   PRIVATE
-  clangDaemon
-  clangdSupport
-  clangTidy
   LLVMTestingAnnotations
   LLVMTestingSupport
+
+  clangDaemon
+  clangIncludeCleaner
+  clangTidy
+  clangdSupport
   )
 
 if (CLANGD_ENABLE_REMOTE)



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


[PATCH] D139704: [clang][RISCV] Added target attributes to runtime functions

2023-01-19 Thread Elena Lepilkina via Phabricator via cfe-commits
eklepilkina added a comment.

> How does this affect LTO?

This problem appeared only under lto as far as it's processed as one module.

> Is this not just one of many symptoms of RISC-V not having the right 
> module-level subtarget under LTO, which is a real problem that needs fixing?

Not exactly, to build right subtarget we need attributes. As far as mentioned 
in comments in code the main approach to provide subtarget information is 
adding information in functions attributes. Why not to provide this information 
for runtime functions? If we don't have right attributes what shall we use to 
find out proper target features?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139704

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


[PATCH] D142085: [Clang][RISCV] Add `__riscv_` prefix for all RVV intrinsics

2023-01-19 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

(For some reason Phab won't let me comment inline from the Changeset View page, 
just does nothing when I click reply or click a line...)

Or just leave the test names alone? The __riscv_ is for namespacing the 
intrinsics, you don't need to namespace the tests when they're already in a 
RISC-V test directory.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142085

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


[PATCH] D142085: [Clang][RISCV] Add `__riscv_` prefix for all RVV intrinsics

2023-01-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:1535
 enum RVV_CSR {
   RVV_VSTART = 0,
   RVV_VXSAT,

Not related to this patch, but this enum should probably be using double 
underscores for its names.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142085

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


[PATCH] D142085: [Clang][RISCV] Add `__riscv_` prefix for all RVV intrinsics

2023-01-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaadd.c:5-14
 // RUN:   FileCheck --check-prefix=CHECK-RV64 %s
 
 #include 
 
-// CHECK-RV64-LABEL: @test_vaadd_vv_i8mf8(
+// CHECK-RV64-LABEL: @test___riscv_vaadd_vv_i8mf8(
 // CHECK-RV64-NEXT:  entry:
 // CHECK-RV64-NEXT:[[TMP0:%.*]] = call  
@llvm.riscv.vaadd.nxv1i8.nxv1i8.i64( poison,  
[[OP1:%.*]],  [[OP2:%.*]], i64 [[VL:%.*]])

Can we use 2 underscores instead of 3?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142085

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


[PATCH] D141796: [15/15][Clang][RISCV][NFC] Set data member under Policy as constants

2023-01-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper 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/D141796/new/

https://reviews.llvm.org/D141796

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


[PATCH] D139705: [clang] fix zero-initialization fix-it for variable template

2023-01-19 Thread Chris Lattner via Phabricator via cfe-commits
lattner added a comment.

Got it this time, sorry for the confusion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139705

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


[PATCH] D140875: [clangd] prototype: Implement unused include warnings with include-cleaner library.

2023-01-19 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

with `-DLLVM_LINK_LLVM_DYLIB=ON`, in case it matters.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140875

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


[PATCH] D140875: [clangd] prototype: Implement unused include warnings with include-cleaner library.

2023-01-19 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

I'm still seeing the build error on clangd-fuzzer on a commit that clearly has 
e84d69f52d9a9fab9162128d8fe8ebec99ea60da 
 in its 
history.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140875

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


[PATCH] D142174: [OpenMP] Don't set rpath for system paths

2023-01-19 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:799
+.Default(false);
+}
+

I wasn't sure exactly how to determine if something is a system path, so I'm 
open to other ideas here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142174

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


[PATCH] D142174: [OpenMP] Don't set rpath for system paths

2023-01-19 Thread Tom Stellard via Phabricator via cfe-commits
tstellar created this revision.
tstellar added reviewers: JonChesterfield, MaskRay.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
tstellar requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Suggested in https://reviews.llvm.org/D118493#3402001


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142174

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


Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -791,6 +791,13 @@
  /*IsLTO=*/true, PluginOptPrefix);
 }
 
+static bool isSystemPath(const StringRef ) {
+  return llvm::StringSwitch(path)
+.Case("/usr/lib", true)
+.Case("/usr/lib64", true)
+.Default(false);
+}
+
 void tools::addOpenMPRuntimeSpecificRPath(const ToolChain ,
   const ArgList ,
   ArgStringList ) {
@@ -802,6 +809,11 @@
 SmallString<256> DefaultLibPath =
 llvm::sys::path::parent_path(TC.getDriver().Dir);
 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
+
+// If clang is installed to a 'system path' there is no reason to add 
rpath.
+if (isSystemPath(DefaultLibPath))
+  return;
+
 CmdArgs.push_back("-rpath");
 CmdArgs.push_back(Args.MakeArgString(DefaultLibPath));
   }


Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -791,6 +791,13 @@
  /*IsLTO=*/true, PluginOptPrefix);
 }
 
+static bool isSystemPath(const StringRef ) {
+  return llvm::StringSwitch(path)
+.Case("/usr/lib", true)
+.Case("/usr/lib64", true)
+.Default(false);
+}
+
 void tools::addOpenMPRuntimeSpecificRPath(const ToolChain ,
   const ArgList ,
   ArgStringList ) {
@@ -802,6 +809,11 @@
 SmallString<256> DefaultLibPath =
 llvm::sys::path::parent_path(TC.getDriver().Dir);
 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
+
+// If clang is installed to a 'system path' there is no reason to add rpath.
+if (isSystemPath(DefaultLibPath))
+  return;
+
 CmdArgs.push_back("-rpath");
 CmdArgs.push_back(Args.MakeArgString(DefaultLibPath));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142022: [Clang][OpenMP] Fix handling of -mcode-object-version for OpenMP

2023-01-19 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

Is this patch really necessary? `-mcode-object-version=` option does not go 
through any translation in derived args. If it is in derived args, it should 
also be in the original args. HIPAMD toolchain just uses the original driver 
args. Why OpenMP toolchain needs to use the derived args?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142022

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


[PATCH] D142075: [Clang][OpenMP] Allow `f16` literal suffix when compiling OpenMP target offloading for NVPTX

2023-01-19 Thread Shilei Tian 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 rG9c2cfaaada66: [Clang][OpenMP] Allow `f16` literal suffix 
when compiling OpenMP target… (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142075

Files:
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/OpenMP/float16_sema.cpp


Index: clang/test/OpenMP/float16_sema.cpp
===
--- /dev/null
+++ clang/test/OpenMP/float16_sema.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -x c++ -triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-targets=nvptx64 -verify %s
+// expected-no-diagnostics
+
+int foo() {
+#pragma omp target
+  {
+__fp16 a = -1.0f16;
+  }
+  return 0;
+}
Index: clang/lib/Lex/LiteralSupport.cpp
===
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -943,9 +943,13 @@
 
   // CUDA host and device may have different _Float16 support, therefore
   // allows f16 literals to avoid false alarm.
+  // When we compile for OpenMP target offloading on NVPTX, f16 suffix
+  // should also be supported.
   // ToDo: more precise check for CUDA.
-  if ((Target.hasFloat16Type() || LangOpts.CUDA) && s + 2 < ThisTokEnd &&
-  s[1] == '1' && s[2] == '6') {
+  // TODO: AMDGPU might also support it in the future.
+  if ((Target.hasFloat16Type() || LangOpts.CUDA ||
+   (LangOpts.OpenMPIsDevice && Target.getTriple().isNVPTX())) &&
+  s + 2 < ThisTokEnd && s[1] == '1' && s[2] == '6') {
 s += 2; // success, eat up 2 characters.
 isFloat16 = true;
 continue;


Index: clang/test/OpenMP/float16_sema.cpp
===
--- /dev/null
+++ clang/test/OpenMP/float16_sema.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -x c++ -triple x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=nvptx64 -verify %s
+// expected-no-diagnostics
+
+int foo() {
+#pragma omp target
+  {
+__fp16 a = -1.0f16;
+  }
+  return 0;
+}
Index: clang/lib/Lex/LiteralSupport.cpp
===
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -943,9 +943,13 @@
 
   // CUDA host and device may have different _Float16 support, therefore
   // allows f16 literals to avoid false alarm.
+  // When we compile for OpenMP target offloading on NVPTX, f16 suffix
+  // should also be supported.
   // ToDo: more precise check for CUDA.
-  if ((Target.hasFloat16Type() || LangOpts.CUDA) && s + 2 < ThisTokEnd &&
-  s[1] == '1' && s[2] == '6') {
+  // TODO: AMDGPU might also support it in the future.
+  if ((Target.hasFloat16Type() || LangOpts.CUDA ||
+   (LangOpts.OpenMPIsDevice && Target.getTriple().isNVPTX())) &&
+  s + 2 < ThisTokEnd && s[1] == '1' && s[2] == '6') {
 s += 2; // success, eat up 2 characters.
 isFloat16 = true;
 continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9c2cfaa - [Clang][OpenMP] Allow `f16` literal suffix when compiling OpenMP target offloading for NVPTX

2023-01-19 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2023-01-19T22:24:38-05:00
New Revision: 9c2cfaaada66f323d10e25ac961ce1524d7b5f1f

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

LOG: [Clang][OpenMP] Allow `f16` literal suffix when compiling OpenMP target 
offloading for NVPTX

Fix #58087.

Reviewed By: jhuber6

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

Added: 
clang/test/OpenMP/float16_sema.cpp

Modified: 
clang/lib/Lex/LiteralSupport.cpp

Removed: 




diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index fb2b14601a6ae..421a853360430 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -943,9 +943,13 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
 
   // CUDA host and device may have 
diff erent _Float16 support, therefore
   // allows f16 literals to avoid false alarm.
+  // When we compile for OpenMP target offloading on NVPTX, f16 suffix
+  // should also be supported.
   // ToDo: more precise check for CUDA.
-  if ((Target.hasFloat16Type() || LangOpts.CUDA) && s + 2 < ThisTokEnd &&
-  s[1] == '1' && s[2] == '6') {
+  // TODO: AMDGPU might also support it in the future.
+  if ((Target.hasFloat16Type() || LangOpts.CUDA ||
+   (LangOpts.OpenMPIsDevice && Target.getTriple().isNVPTX())) &&
+  s + 2 < ThisTokEnd && s[1] == '1' && s[2] == '6') {
 s += 2; // success, eat up 2 characters.
 isFloat16 = true;
 continue;

diff  --git a/clang/test/OpenMP/float16_sema.cpp 
b/clang/test/OpenMP/float16_sema.cpp
new file mode 100644
index 0..4b9f3399eb30d
--- /dev/null
+++ b/clang/test/OpenMP/float16_sema.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -x c++ -triple x86_64-unknown-linux-gnu 
-fopenmp -fopenmp-targets=nvptx64 -verify %s
+// expected-no-diagnostics
+
+int foo() {
+#pragma omp target
+  {
+__fp16 a = -1.0f16;
+  }
+  return 0;
+}



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


[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-19 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 490701.
ccotter added a comment.

- cleanup comments, docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp
@@ -0,0 +1,92 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t
+
+struct Obj {
+  void lambdas_that_warn_default_capture_copy() {
+int local{};
+int local2{};
+
+auto explicit_this_capture = [=, this]() { };
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture = [this]() { };
+
+auto explicit_this_capture_locals1 = [=, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_locals1 = [local, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_locals2 = [=, this]() { return (local+local2) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_locals2 = [local, local2, this]() { return (local+local2) > 10; };
+
+auto explicit_this_capture_local_ref = [=, this, ]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref = [this, ]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref2 = [=, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref2 = [, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref3 = [=, , this, ]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref3 = [, this, ]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref4 = [=, , , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref4 = [, , this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref_extra_whitespace = [=, &  local, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:62: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref_extra_whitespace = [&  local, , this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref_with_comment = [=, & /* byref */ local, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:58: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref_with_comment = [& /* byref */ local, , this]() { return (local+x) > 10; };
+
+auto implicit_this_capture = [=]() { return x > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that implicitly capture 'this' should not specify a capture default 

[PATCH] D142118: [HIP] Unbundler allows missing host entry

2023-01-19 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rG3006cb2aa8d9: [HIP] Unbundler allows missing host entry 
(authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D142118?vs=490512=490699#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142118

Files:
  clang/lib/Driver/OffloadBundler.cpp
  clang/test/Driver/clang-offload-bundler.c


Index: clang/test/Driver/clang-offload-bundler.c
===
--- clang/test/Driver/clang-offload-bundler.c
+++ clang/test/Driver/clang-offload-bundler.c
@@ -224,8 +224,11 @@
 // RUN: diff %t.empty %t.res.tgt2
 
 // Check that bindler prints an error if given host bundle does not exist in 
the fat binary.
-// RUN: not clang-offload-bundler -type=s 
-targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu 
-output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle 
-allow-missing-bundles 2>&1 | FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
-// CK-NO-HOST-BUNDLE: error: Can't find bundle for the host target
+// RUN: not clang-offload-bundler -type=s 
-targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu 
-output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle 2>&1 | 
FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
+// CK-NO-HOST-BUNDLE: error: Can't find bundles for host-amdgcn-xxx-linux-gnu
+
+// Check missing host entry is allowed with -allow-missing-bundles
+// RUN: clang-offload-bundler -type=s 
-targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu 
-output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle 
-allow-missing-bundles
 
 //
 // Check binary bundle/unbundle. The content that we have before bundling must 
be the same we have after unbundling.
Index: clang/lib/Driver/OffloadBundler.cpp
===
--- clang/lib/Driver/OffloadBundler.cpp
+++ clang/lib/Driver/OffloadBundler.cpp
@@ -1060,7 +1060,8 @@
 
   // If we found elements, we emit an error if none of those were for the host
   // in case host bundle name was provided in command line.
-  if (!FoundHostBundle && BundlerConfig.HostInputIndex != ~0u)
+  if (!(FoundHostBundle || BundlerConfig.HostInputIndex == ~0u ||
+BundlerConfig.AllowMissingBundles))
 return createStringError(inconvertibleErrorCode(),
  "Can't find bundle for the host target");
 


Index: clang/test/Driver/clang-offload-bundler.c
===
--- clang/test/Driver/clang-offload-bundler.c
+++ clang/test/Driver/clang-offload-bundler.c
@@ -224,8 +224,11 @@
 // RUN: diff %t.empty %t.res.tgt2
 
 // Check that bindler prints an error if given host bundle does not exist in the fat binary.
-// RUN: not clang-offload-bundler -type=s -targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu -output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle -allow-missing-bundles 2>&1 | FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
-// CK-NO-HOST-BUNDLE: error: Can't find bundle for the host target
+// RUN: not clang-offload-bundler -type=s -targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu -output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle 2>&1 | FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
+// CK-NO-HOST-BUNDLE: error: Can't find bundles for host-amdgcn-xxx-linux-gnu
+
+// Check missing host entry is allowed with -allow-missing-bundles
+// RUN: clang-offload-bundler -type=s -targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu -output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle -allow-missing-bundles
 
 //
 // Check binary bundle/unbundle. The content that we have before bundling must be the same we have after unbundling.
Index: clang/lib/Driver/OffloadBundler.cpp
===
--- clang/lib/Driver/OffloadBundler.cpp
+++ clang/lib/Driver/OffloadBundler.cpp
@@ -1060,7 +1060,8 @@
 
   // If we found elements, we emit an error if none of those were for the host
   // in case host bundle name was provided in command line.
-  if (!FoundHostBundle && BundlerConfig.HostInputIndex != ~0u)
+  if (!(FoundHostBundle || BundlerConfig.HostInputIndex == ~0u ||
+BundlerConfig.AllowMissingBundles))
 return createStringError(inconvertibleErrorCode(),
  "Can't find bundle for the host target");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3006cb2 - [HIP] Unbundler allows missing host entry

2023-01-19 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-01-19T22:13:17-05:00
New Revision: 3006cb2aa8d9fb1cbcb15a7e4dcd321614fa7478

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

LOG: [HIP] Unbundler allows missing host entry

Reviewed by: Artem Belevich

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

Added: 


Modified: 
clang/lib/Driver/OffloadBundler.cpp
clang/test/Driver/clang-offload-bundler.c

Removed: 




diff  --git a/clang/lib/Driver/OffloadBundler.cpp 
b/clang/lib/Driver/OffloadBundler.cpp
index d304ea5e9281..cdacceb0a86a 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -1060,7 +1060,8 @@ Error OffloadBundler::UnbundleFiles() {
 
   // If we found elements, we emit an error if none of those were for the host
   // in case host bundle name was provided in command line.
-  if (!FoundHostBundle && BundlerConfig.HostInputIndex != ~0u)
+  if (!(FoundHostBundle || BundlerConfig.HostInputIndex == ~0u ||
+BundlerConfig.AllowMissingBundles))
 return createStringError(inconvertibleErrorCode(),
  "Can't find bundle for the host target");
 

diff  --git a/clang/test/Driver/clang-offload-bundler.c 
b/clang/test/Driver/clang-offload-bundler.c
index b803db5f90ca..0d5d26afcb62 100644
--- a/clang/test/Driver/clang-offload-bundler.c
+++ b/clang/test/Driver/clang-offload-bundler.c
@@ -224,8 +224,11 @@
 // RUN: 
diff  %t.empty %t.res.tgt2
 
 // Check that bindler prints an error if given host bundle does not exist in 
the fat binary.
-// RUN: not clang-offload-bundler -type=s 
-targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu 
-output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle 
-allow-missing-bundles 2>&1 | FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
-// CK-NO-HOST-BUNDLE: error: Can't find bundle for the host target
+// RUN: not clang-offload-bundler -type=s 
-targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu 
-output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle 2>&1 | 
FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
+// CK-NO-HOST-BUNDLE: error: Can't find bundles for host-amdgcn-xxx-linux-gnu
+
+// Check missing host entry is allowed with -allow-missing-bundles
+// RUN: clang-offload-bundler -type=s 
-targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu 
-output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle 
-allow-missing-bundles
 
 //
 // Check binary bundle/unbundle. The content that we have before bundling must 
be the same we have after unbundling.



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


[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-19 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp:1
+//===--- AvoidCaptureDefaultWhenCapturingThisCheck.cpp - clang-tidy
+//-===//

Ditto.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h:1
+//===--- AvoidCaptureDefaultWhenCapturingThisCheck.h - clang-tidy *- C++
+//-*-===//

Please merge these two lines. Amount of dashes and equal signs could be reduced.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:117
+
+  Warns when lambda specify a capture default and capture ``this``. The check 
also
+  offers fix-its.

`The check also offers fix-its.` could be omitted. This information presents in 
check table.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2023-01-19 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski updated this revision to Diff 490698.
calebzulawski added a comment.

This revision is basically the same as before, but with two changes:

- `darwin` targets (e.g. `x86_64-apple-darwin`) do not automatically detect the 
SDK. There is another bug where these targets don't seem to properly pass the 
target version (e.g. `x86_64-apple-darwin9`) whenever an SDK is provided.
- A new flag `--no-detect-xcode` disables this detection.

Fingers crossed, this passes all tests for me locally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-ld-platform-version-macos.c
  clang/test/Driver/darwin-sdk-detect.c

Index: clang/test/Driver/darwin-sdk-detect.c
===
--- /dev/null
+++ clang/test/Driver/darwin-sdk-detect.c
@@ -0,0 +1,20 @@
+// REQUIRES: system-darwin
+
+// Check that we default to running `xcrun --show-sdk-path` if there is no
+// SDKROOT defined in the environment.
+//
+// RUN: env -u SDKROOT %clang -target x86_64-apple-macos -c %s -### 2> %t.log
+// RUN: FileCheck --check-prefix=CHECK-XC < %t.log %s
+//
+// CHECK-XC: clang
+// CHECK-XC: "-cc1"
+// CHECK-XC: "-isysroot" "{{.*MacOSX[0-9\.]*\.sdk}}"
+
+// Check once again that we default to running `xcrun`, this time with another target.
+//
+// RUN: env -u SDKROOT %clang -target arm64-apple-ios -c %s -### 2> %t.log
+// RUN: FileCheck --check-prefix=CHECK-XC-IOS < %t.log %s
+//
+// CHECK-XC-IOS: clang
+// CHECK-XC-IOS: "-cc1"
+// CHECK-XC-IOS: "-isysroot" "{{.*iPhoneOS[0-9\.]*\.sdk}}"
Index: clang/test/Driver/darwin-ld-platform-version-macos.c
===
--- clang/test/Driver/darwin-ld-platform-version-macos.c
+++ clang/test/Driver/darwin-ld-platform-version-macos.c
@@ -41,7 +41,7 @@
 // ARM64_NEW_1: "-platform_version" "macos" "11.1.0" "10.14"
 // ARM64_OLD: "-macosx_version_min" "11.0.0"
 
-// RUN: %clang -target x86_64-apple-macos10.13 -mlinker-version=520 \
+// RUN: %clang --no-detect-xcode -target x86_64-apple-macos10.13 -mlinker-version=520 \
 // RUN:   -### %t.o 2>&1 \
 // RUN:   | FileCheck --check-prefix=NOSDK %s
 // RUN: %clang -target x86_64-apple-darwin17 -mlinker-version=520 \
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -18,15 +18,22 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include  // ::getenv
+#include   // std::unique_ptr
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -2078,21 +2085,90 @@
 void Darwin::AddDeploymentTarget(DerivedArgList ) const {
   const OptTable  = getDriver().getOpts();
 
-  // Support allowing the SDKROOT environment variable used by xcrun and other
-  // Xcode tools to define the default sysroot, by making it the default for
-  // isysroot.
+  // On Apple platforms, standard headers and libraries are not provided with
+  // the base system (e.g. in /usr/{include,lib}). Instead, they are provided
+  // in various SDKs for the different Apple platforms. Clang needs to know
+  // where that SDK lives, and there are a couple ways this can be achieved:
+  //
+  // (1) If `-isysroot ` is passed explicitly, use that.
   if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
 // Warn if the path does not exist.
 if (!getVFS().exists(A->getValue()))
   getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
-  } else {
-if (char *env = ::getenv("SDKROOT")) {
-  // We only use this value as the default if it is an absolute path,
-  // exists, and it is not the root path.
-  if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
-  StringRef(env) != "/") {
-Args.append(Args.MakeSeparateArg(
-nullptr, Opts.getOption(options::OPT_isysroot), env));
+  }
+
+  // (2) If the SDKROOT environment variable is defined and points to a valid
+  // path, use that. $SDKROOT is set by `xcrun` and other Xcode tools, so
+  // running `xcrun clang` will work by going through this path.
+  else if (char *env = 

[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-19 Thread Chris Cotter via Phabricator via cfe-commits
ccotter marked 2 inline comments as done.
ccotter added a comment.

Would someone with merge access mind committing this? I double checked and this 
diff can be applied on the latest upstream/main. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2023-01-19 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski reopened this revision.
calebzulawski added a comment.
This revision is now accepted and ready to land.

@thakis thanks. I have an updated revision that can be reviewed properly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D140875: [clangd] prototype: Implement unused include warnings with include-cleaner library.

2023-01-19 Thread Khem Raj via Phabricator via cfe-commits
raj.khem added a comment.

In D140875#4065824 , @hokein wrote:

> In D140875#4065763 , @ckandeler 
> wrote:
>
>> With this, I now get:
>> FAILED: bin/clangd-fuzzer 
>> : && /usr/lib/icecream/libexec/icecc/bin/c++ -fPIC 
>> -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time 
>> -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
>> -Wno-missing-field-initializers -pedantic -Wno-long-long 
>> -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess 
>> -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type 
>> -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
>> -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
>> -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
>> -fno-strict-aliasing -O2 -g -DNDEBUG -fuse-ld=lld -Wl,--color-diagnostics
>> -Wl,--gc-sections 
>> tools/clang/tools/extra/clangd/fuzzer/CMakeFiles/clangd-fuzzer.dir/FuzzerClangdMain.cpp.o
>>  
>> tools/clang/tools/extra/clangd/fuzzer/CMakeFiles/clangd-fuzzer.dir/clangd-fuzzer.cpp.o
>>  -o bin/clangd-fuzzer  -Wl,-rpath,"\$ORIGIN/../lib"  lib/libclangDaemon.a  
>> lib/libclangdSupport.a  lib/libclangPseudo.a  lib/libclangPseudoGrammar.a  
>> lib/libclangTidyAndroidModule.a  lib/libclangTidyAbseilModule.a  
>> lib/libclangTidyAlteraModule.a  lib/libclangTidyBoostModule.a  
>> lib/libclangTidyCERTModule.a  lib/libclangTidyConcurrencyModule.a  
>> lib/libclangTidyDarwinModule.a  lib/libclangTidyFuchsiaModule.a  
>> lib/libclangTidyHICPPModule.a  lib/libclangTidyBugproneModule.a  
>> lib/libclangTidyCppCoreGuidelinesModule.a  lib/libclangTidyGoogleModule.a  
>> lib/libclangTidyLinuxKernelModule.a  lib/libclangTidyLLVMModule.a  
>> lib/libclangTidyLLVMLibcModule.a  lib/libclangTidyMiscModule.a  
>> lib/libclangAnalysis.a  lib/libclangASTMatchers.a  lib/libclangAST.a  
>> lib/libclangLex.a  lib/libclangBasic.a  lib/libclangTidyModernizeModule.a  
>> lib/libclangTidyObjCModule.a  lib/libclangTidyOpenMPModule.a  
>> lib/libclangTidyPerformanceModule.a  lib/libclangTidyPortabilityModule.a  
>> lib/libclangTidyReadabilityModule.a  lib/libclangTidyZirconModule.a  
>> lib/libclangTidyMPIModule.a  lib/libclangTidyUtils.a  lib/libclangTidy.a  
>> lib/libclang-cpp.so.16git  lib/libLLVM-16git.so && :
>> ld.lld: error: undefined symbol: 
>> clang::include_cleaner::walkUsed(llvm::ArrayRef, 
>> llvm::ArrayRef, 
>> clang::include_cleaner::PragmaIncludes const*, clang::SourceManager const&, 
>> llvm::function_ref> llvm::ArrayRef)>)
>>
> referenced by IncludeCleaner.cpp:504 
> (/sda/home/christian/dev/llvm/clang-tools-extra/clangd/IncludeCleaner.cpp:504)
>
>   
> IncludeCleaner.cpp.o:(clang::clangd::computeUnusedIncludesExperimental(clang::clangd::ParsedAST&)
>  (.localalias)) in archive lib/libclangDaemon.a
>
> sorry, should be fixed in 
> https://github.com/llvm/llvm-project/commit/e84d69f52d9a9fab9162128d8fe8ebec99ea60da.

this seems to be not enough, I am also seeing clangd build failiures

  /mnt/b/yoe/master/build/tmp/hosttools/ld: 
lib/libclangDaemon.a(Preamble.cpp.o): in function `clang::clangd::(anonymous 
namespace)::CppFilePreambleCallbacks::BeforeExecute(clang::CompilerInstance&)':
  
Preamble.cpp:(.text._ZN5clang6clangd12_GLOBAL__N_124CppFilePreambleCallbacks13BeforeExecuteERNS_16CompilerInstanceE+0x8b):
 undefined reference to 
`clang::include_cleaner::PragmaIncludes::record(clang::CompilerInsta
  nce const&)'
  /mnt/b/yoe/master/build/tmp/hosttools/ld: 
lib/libclangDaemon.a(IncludeCleaner.cpp.o): in function 
`clang::clangd::computeUnusedIncludesExperimental(clang::clangd::ParsedAST&) 
[clone .localalias]':
  
IncludeCleaner.cpp:(.text._ZN5clang6clangd33computeUnusedIncludesExperimentalERNS0_9ParsedASTE+0x3a1):
 undefined reference to 
`clang::include_cleaner::walkUsed(llvm::ArrayRef, 
llvm::ArrayRef, clang::include_cleaner::PragmaIncludes 
const*, clang::SourceManager const&, llvm::function_ref)>)'
  collect2: error: ld returned 1 exit status
  [193/193] Linking CXX executable bin/clangd
  FAILED: bin/clangd


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140875

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


[PATCH] D139705: [clang] fix zero-initialization fix-it for variable template

2023-01-19 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry added a comment.

In D139705#4067370 , @lattner wrote:

> I'm pretty sure I'm on top of commit access requests now, plz let me know if 
> I missed you or something!  Could be spam filter or who knows what

I sent an email from  to 
 on last Friday, and I've received no reply so far. I've 
checked the email address many times so it was not likely to be sent to the 
wrong person.

I can resend the email. Or maybe we can deal with it here? If so, my GitHub 
username is v1nh1shungry (https://github.com/v1nh1shungry).

Thank you so much!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139705

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


[PATCH] D141745: [clang] Don't short-circuit constant evaluation for array or record types

2023-01-19 Thread Charles Magahern 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 rG3ac4299d3798: [clang] Dont short-circuit constant 
evaluation for array or record types (authored by cmagahern).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141745

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/CodeGen/2007-06-15-AnnotateAttribute.c


Index: clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
===
--- clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
+++ clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
@@ -14,6 +14,20 @@
   return y + x;
 }
 
+/* Attribute with struct argument. */
+struct TestStruct {
+  int a;
+  int b;
+};
+int Y __attribute__((annotate(
+  "GlobalValAnnotationWithArgs", 
+  42,
+  (struct TestStruct) { .a = 1, .b = 2 }
+)));
+
+// CHECK: @.str.3 = private unnamed_addr constant [28 x i8] 
c"GlobalValAnnotationWithArgs\00", section "llvm.metadata"
+// CHECK-NEXT: @.args = private unnamed_addr constant { i32, 
%struct.TestStruct } { i32 42, %struct.TestStruct { i32 1, i32 2 } }, section 
"llvm.metadata"
+
 int main(void) {
   static int a __attribute__((annotate("GlobalValAnnotation")));
   a = foo(2);
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15313,7 +15313,7 @@
   assert(!isValueDependent() &&
  "Expression evaluator can't be called on a dependent expression.");
   bool IsConst;
-  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
+  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst) && 
Result.Val.hasValue())
 return true;
 
   ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");


Index: clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
===
--- clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
+++ clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
@@ -14,6 +14,20 @@
   return y + x;
 }
 
+/* Attribute with struct argument. */
+struct TestStruct {
+  int a;
+  int b;
+};
+int Y __attribute__((annotate(
+  "GlobalValAnnotationWithArgs", 
+  42,
+  (struct TestStruct) { .a = 1, .b = 2 }
+)));
+
+// CHECK: @.str.3 = private unnamed_addr constant [28 x i8] c"GlobalValAnnotationWithArgs\00", section "llvm.metadata"
+// CHECK-NEXT: @.args = private unnamed_addr constant { i32, %struct.TestStruct } { i32 42, %struct.TestStruct { i32 1, i32 2 } }, section "llvm.metadata"
+
 int main(void) {
   static int a __attribute__((annotate("GlobalValAnnotation")));
   a = foo(2);
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15313,7 +15313,7 @@
   assert(!isValueDependent() &&
  "Expression evaluator can't be called on a dependent expression.");
   bool IsConst;
-  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
+  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst) && Result.Val.hasValue())
 return true;
 
   ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3ac4299 - [clang] Don't short-circuit constant evaluation for array or record types

2023-01-19 Thread Charles Magahern via cfe-commits

Author: Charles Magahern
Date: 2023-01-19T18:04:00-08:00
New Revision: 3ac4299d3798eb7078905d5fc8f23781556c90a1

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

LOG: [clang] Don't short-circuit constant evaluation for array or record types

FastEvaluateAsRValue returns `true` without setting a result value for when a
given constant expression is an array or record type.

Clang attributes must be able to support constant expressions that are array or
record types, so proceed with the slower path for evaluation in the case where
`FastEvaluateAsRValue` does not yield an evaluation result.

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

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/CodeGen/2007-06-15-AnnotateAttribute.c

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 7105c7dfa7530..912a210fd2545 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15313,7 +15313,7 @@ bool Expr::EvaluateAsConstantExpr(EvalResult , 
const ASTContext ,
   assert(!isValueDependent() &&
  "Expression evaluator can't be called on a dependent expression.");
   bool IsConst;
-  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
+  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst) && 
Result.Val.hasValue())
 return true;
 
   ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");

diff  --git a/clang/test/CodeGen/2007-06-15-AnnotateAttribute.c 
b/clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
index 754d7169aabbe..05a9e6d7dc394 100644
--- a/clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
+++ b/clang/test/CodeGen/2007-06-15-AnnotateAttribute.c
@@ -14,6 +14,20 @@ int foo(int y 
__attribute__((annotate("LocalValAnnotation" {
   return y + x;
 }
 
+/* Attribute with struct argument. */
+struct TestStruct {
+  int a;
+  int b;
+};
+int Y __attribute__((annotate(
+  "GlobalValAnnotationWithArgs", 
+  42,
+  (struct TestStruct) { .a = 1, .b = 2 }
+)));
+
+// CHECK: @.str.3 = private unnamed_addr constant [28 x i8] 
c"GlobalValAnnotationWithArgs\00", section "llvm.metadata"
+// CHECK-NEXT: @.args = private unnamed_addr constant { i32, 
%struct.TestStruct } { i32 42, %struct.TestStruct { i32 1, i32 2 } }, section 
"llvm.metadata"
+
 int main(void) {
   static int a __attribute__((annotate("GlobalValAnnotation")));
   a = foo(2);



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


[PATCH] D78441: Delete NaCl support

2023-01-19 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added a comment.

Sorry, no :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78441

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


[PATCH] D136651: [Clang] Give Clang the ability to use a shared stat cache

2023-01-19 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

If it's not too much trouble, maybe you could cherry-pick and amend 
8d498e08deaf6e06a578cfedb4eb259b722ac7f6 
 into the 
commit that relands this.

(If not, no worries.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2023-01-19 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:520
+  getOpenMPRuntime().emitDeclareTargetVarDefinition(D, Addr, PerformInit))
+return;
+

I don't really like the copy-pasted bits here.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:5006
+if (NeedsGlobalCtor || NeedsGlobalDtor)
+  DelayedCXXInitPosition[D] = ~0U;
+  } else {

zahiraam wrote:
> efriedma wrote:
> > zahiraam wrote:
> > > efriedma wrote:
> > > > zahiraam wrote:
> > > > > efriedma wrote:
> > > > > > zahiraam wrote:
> > > > > > > Do you agree this should be done only when one of those flags is 
> > > > > > > on?
> > > > > > Yes, that's fine; I wasn't really paying close attention to the 
> > > > > > exact code.  Just wanted to make the point about the structure of 
> > > > > > the if statements, and code was the easiest way to explain it.
> > > > > > 
> > > > > > Maybe the outer if statement should actually be `if 
> > > > > > (isStaticInit(D, getLangOpts()) && NeedsGlobalCtor) {`.
> > > > > > 
> > > > > > On a related note, we might want to avoid the name "ctor", in case 
> > > > > > that accidentally conflicts with some user code; an "__"-prefixed 
> > > > > > name would be appropriate.
> > > > > >> Maybe the outer if statement should actually be if 
> > > > > >> (isStaticInit(D, getLangOpts()) && NeedsGlobalCtor) {
> > > > > Not sure about that! There are cases where (isStaticInit(D, 
> > > > > getLangOpts())) = true and NeedsGlobalCtor=false, but 
> > > > > NeedsGlobalDtor=true. In which case a __dtor needs to be emitted, no?
> > > > > 
> > > > > Writing the condition as you are proposing would actually not get me 
> > > > > into the body to emit the __dtor. Is that what we want?
> > > > EmitCXXGlobalVarDeclInitFunc should be able to handle that case.
> > > > 
> > > > Looking again, I'm a little concerned that in the isStaticInit() case, 
> > > > we're skipping a bunch of the logic in EmitCXXGlobalVarDeclInitFunc. 
> > > > EmitCXXCtorInit handles the basic cases correctly, but there are a lot 
> > > > of special cases in EmitCXXGlobalVarDeclInitFunc.
> > > I have left the condition as it was to make sure no cases are left. What 
> > > other cases are you thinking of? 
> > > 
> > EmitCXXGlobalVarDeclInitFunc has special cases for CUDA, OpenMP, 
> > thread-local variables, the InitSeg attribute, and inline variables.
> Let me know if this works? I have added one additional LIT test. I referred 
> to 
> https://learn.microsoft.com/en-us/cpp/cpp/storage-classes-cpp?view=msvc-170#thread_local
>  for thread_local. 
> For the inline variables, I couldn't find much information about 
> initialization of inline variables. I tried to find a case that wouldn't pass 
> by the new code and wouldn't pass by EmitCXXGlobalVarDeclInitFunc, but no 
> success.
Inline variable example:

```
__declspec(dllimport) extern int x;
inline int *y = 
int **z = 
```

This should trigger your new codepath, I think?



Comment at: clang/test/CodeGenCXX/constant-init.cpp:17
+
+// CHECK: define internal void @"??__Ft2@@YAXXZ"() #0 {
+// CHECK: entry:

This doesn't look like your new codepath is triggering?  If your code is 
working correctly, it should, I think?


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

https://reviews.llvm.org/D137107

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2023-01-19 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Reverted in a5f446bc4bb1ac78d6852cc8e251a1229899b783 for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[clang] a5f446b - Revert "[clang][Darwin] Try to guess the SDK root with xcrun when unspecified"

2023-01-19 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2023-01-19T20:05:11-05:00
New Revision: a5f446bc4bb1ac78d6852cc8e251a1229899b783

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

LOG: Revert "[clang][Darwin] Try to guess the SDK root with xcrun when 
unspecified"

This reverts commit ecade80d93960ad01d8665db02c23841e055a80f.
Breaks tests on macOS and tries to run xcrun on non-mac platforms,
see comments on https://reviews.llvm.org/D136315

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/lib/Driver/ToolChains/Darwin.cpp

Removed: 
clang/test/Driver/darwin-sdk-detect.c



diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index e0030d24c23b1..7dd8ecb5fcc4d 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3824,20 +3824,6 @@ backend.
 Operating System Features and Limitations
 -
 
-Apple
-^
-
-On Apple platforms, the standard headers and libraries are not provided by
-the base system and are instead part of the Xcode SDK application. The location
-of the SDK is determined any of the following ways:
-
-- If passed to Clang, the ``-isysroot`` option specifies the path to the SDK.
-
-- If the sysroot isn't provided, the ``SDKROOT`` environment variable is 
checked.
-  This variable is set by various Xcode tools.
-
-- Otherwise, Clang uses Xcode's ``xcrun`` tool to find the SDK.
-
 Windows
 ^^^
 

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 03c28c14a0ecb..9f95c962ee9aa 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -18,22 +18,15 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
-#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/ProfileData/InstrProf.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/Program.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include  // ::getenv
-#include   // std::unique_ptr
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -2085,89 +2078,21 @@ std::optional 
parseSDKSettings(llvm::vfs::FileSystem ,
 void Darwin::AddDeploymentTarget(DerivedArgList ) const {
   const OptTable  = getDriver().getOpts();
 
-  // On Apple platforms, standard headers and libraries are not provided with
-  // the base system (e.g. in /usr/{include,lib}). Instead, they are provided
-  // in various SDKs for the 
diff erent Apple platforms. Clang needs to know
-  // where that SDK lives, and there are a couple ways this can be achieved:
-  //
-  // (1) If `-isysroot ` is passed explicitly, use that.
+  // Support allowing the SDKROOT environment variable used by xcrun and other
+  // Xcode tools to define the default sysroot, by making it the default for
+  // isysroot.
   if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
 // Warn if the path does not exist.
 if (!getVFS().exists(A->getValue()))
   getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
-  }
-
-  // (2) If the SDKROOT environment variable is defined and points to a valid
-  // path, use that. $SDKROOT is set by `xcrun` and other Xcode tools, so
-  // running `xcrun clang` will work by going through this path.
-  else if (char *env = ::getenv("SDKROOT")) {
-// We only use this value as the default if it is an absolute path,
-// exists, and it is not the root path.
-if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
-StringRef(env) != "/") {
-  Args.append(Args.MakeSeparateArg(
-  nullptr, Opts.getOption(options::OPT_isysroot), env));
-}
-  }
-
-  // (3) Otherwise, we try to guess the path of the default SDK by running
-  // `xcrun --show-sdk-path`. This won't always be correct, but if the
-  //  user wants to use the non-default SDK, they should specify it
-  //  explicitly with methods (1) or (2) above.
-  else {
-llvm::SmallString<64> OutputFile;
-llvm::sys::fs::createTemporaryFile("print-sdk-path", "" /* No Suffix */,
-   OutputFile);
-llvm::FileRemover OutputRemover(OutputFile.c_str());
-std::optional Redirects[] = {{""}, OutputFile.str(), 
{""}};
-
-Optional SDKName = std::nullopt;
-switch (getTriple().getOS()) {
-case llvm::Triple::OSType::WatchOS:
-  if (getTriple().isSimulatorEnvironment())
-SDKName = 

[PATCH] D142167: [clang][modules] Disallow importing private framework in the implementation

2023-01-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:544
   // FIXME: Should we warn on a redundant import of the current module?
-  if (Mod->getTopLevelModuleName() == getLangOpts().CurrentModule &&
+  if (Mod->isForBuilding(getLangOpts()) &&
   (getLangOpts().isCompilingModule() || !getLangOpts().ModulesTS)) {

This is the functional change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142167

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2023-01-19 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

I've confirmed that this breaks a pretty vanilla build setup.

  /Applications/CMake.app/Contents/bin/cmake -GNinja -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_ASSERTIONS=ON 
-DLLVM_ENABLE_PROJECTS='clang;compiler-rt;clang-tools-extra;lld' 
-DLLVM_APPEND_VC_REV=NO -DLLVM_TARGETS_TO_BUILD='X86' 
-DCMAKE_C_COMPILER=$PWD/../llvm-project/out/gn/bin/clang 
-DCMAKE_CXX_COMPILER=$PWD/../llvm-project/out/gn/bin/clang++ 
-DCMAKE_OSX_SYSROOT=$HOME/llvm-project/sysroot/MacOSX.sdk 
-DDARWIN_macosx_CACHED_SYSROOT=$HOME/src/llvm-project/sysroot/MacOSX.sdk 
-DDARWIN_iphoneos_CACHED_SYSROOT=$HOME/src/llvm-project/sysroot/iPhoneOS.sdk 
-DDARWIN_iphonesimulator_CACHED_SYSROOT=$HOME/src/llvm-project/sysroot/iPhoneSimulator.sdk
 ../llvm-project/llvm
  
  % time caffeinate ninja check-clang
  ...
Clang :: Driver/arc.c
Clang :: Driver/clang-g-opts.c
Clang :: Driver/clang-translation.c
Clang :: Driver/darwin-debug-flags.c
Clang :: Driver/darwin-header-search-system.cpp
Clang :: Driver/darwin-ld-platform-version-macos.c
Clang :: Driver/darwin-ld.c
Clang :: Driver/darwin-multiarch-arm.c
Clang :: Driver/darwin-objc-options.m
Clang :: Driver/darwin-version.c
Clang :: Driver/debug-options.c
Clang :: Driver/fsanitize.c
Clang :: Driver/macos-apple-silicon-slice-link-libs.cpp
Clang :: Driver/target-triple-deployment.c

This is on macOS 13.1.

(sysroot dir created via ` llvm/utils/sysroot.py make-fake --out-dir sysroot`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D142167: [clang][modules] Disallow importing private framework in the implementation

2023-01-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added a reviewer: benlangmuir.
Herald added subscribers: ChuanqiXu, ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Whenever we are compiling implementation of a framework (with the 
`-fmodule-name=FW` option), we never translate `#import ` to an 
import, regardless of whether "Header.h" belongs to "FW" or "FW_Private". For 
the same reasons, we also disallow `@import FW`. However, we still allow 
`@import FW_Private`. This patch disallows that a well, to be consistent with 
the rest of the rules.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142167

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/Basic/Module.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/implementation-of-module-private.m

Index: clang/test/Modules/implementation-of-module-private.m
===
--- /dev/null
+++ clang/test/Modules/implementation-of-module-private.m
@@ -0,0 +1,13 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- frameworks/FW.framework/Modules/module.modulemap
+framework module FW {}
+//--- frameworks/FW.framework/Modules/module.private.modulemap
+framework module FW_Private {}
+
+//--- tu.m
+@import FW_Private; // expected-error{{@import of module 'FW_Private' in implementation of 'FW'; use #import}}
+
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fimplicit-module-maps \
+// RUN:   -fmodule-name=FW -F %t/frameworks %t/tu.m -verify
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -541,7 +541,7 @@
   // of the same top-level module. Until we do, make it an error rather than
   // silently ignoring the import.
   // FIXME: Should we warn on a redundant import of the current module?
-  if (Mod->getTopLevelModuleName() == getLangOpts().CurrentModule &&
+  if (Mod->isForBuilding(getLangOpts()) &&
   (getLangOpts().isCompilingModule() || !getLangOpts().ModulesTS)) {
 Diag(ImportLoc, getLangOpts().isCompilingModule()
 ? diag::err_module_self_import
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -109,25 +109,6 @@
   PED_Elifndef
 };
 
-// The -fmodule-name option tells the compiler to textually include headers in
-// the specified module, meaning clang won't build the specified module. This is
-// useful in a number of situations, for instance, when building a library that
-// vends a module map, one might want to avoid hitting intermediate build
-// products containimg the module map or avoid finding the system installed
-// modulemap for that library.
-static bool isForModuleBuilding(Module *M, StringRef CurrentModule,
-StringRef ModuleName) {
-  StringRef TopLevelName = M->getTopLevelModuleName();
-
-  // When building framework Foo, we wanna make sure that Foo *and* Foo_Private
-  // are textually included and no modules are built for both.
-  if (M->getTopLevelModule()->IsFramework && CurrentModule == ModuleName &&
-  !CurrentModule.endswith("_Private") && TopLevelName.endswith("_Private"))
-TopLevelName = TopLevelName.drop_back(8);
-
-  return TopLevelName == CurrentModule;
-}
-
 static MacroDiag shouldWarnOnMacroDef(Preprocessor , IdentifierInfo *II) {
   const LangOptions  = PP.getLangOpts();
   if (isReservedInAllContexts(II->isReserved(Lang))) {
@@ -2219,14 +2200,13 @@
   alreadyIncluded(*File))
 Action = IncludeLimitReached;
 
-  bool MaybeTranslateInclude = Action == Enter && File && SuggestedModule &&
-   !isForModuleBuilding(SuggestedModule.getModule(),
-getLangOpts().CurrentModule,
-getLangOpts().ModuleName);
-
   // FIXME: We do not have a good way to disambiguate C++ clang modules from
   // C++ standard modules (other than use/non-use of Header Units).
   Module *SM = SuggestedModule.getModule();
+
+  bool MaybeTranslateInclude =
+  Action == Enter && File && SM && !SM->isForBuilding(getLangOpts());
+
   // Maybe a usable Header Unit
   bool UsableHeaderUnit = false;
   if (getLangOpts().CPlusPlusModules && SM && SM->isHeaderUnit()) {
@@ -2556,9 +2536,7 @@
 // that behaves the same as the header would behave in a compilation using
 // that PCH, which means we should enter the submodule. We need to teach
 // the AST serialization layer to deal with the resulting AST.
-if (getLangOpts().CompilingPCH &&
-isForModuleBuilding(SM, getLangOpts().CurrentModule,
-getLangOpts().ModuleName))
+if 

[PATCH] D139395: Add CFI integer types normalization

2023-01-19 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

In D139395#4066948 , @samitolvanen 
wrote:

> Thanks for the patch, Ramon. This looks like a reasonable approach to me, and 
> just for reference, here appears to be the corresponding rustc change:
>
> https://github.com/rust-lang/rust/pull/105452/commits/9087c336103d0fa0b465acf8dbc1e4651250fb05
>
> @pcc did you have any other concerns about adding this option?

I discussed this out of band with Ramon and we agreed that the new option 
should be marked as experimental because the rustc implementation is not yet 
finalized. I think that the criteria for removing the experimental marking 
should be that there is a full implementation of integer normalization for Rust 
(or some other language) that has been tested against a large codebase that 
uses FFI. Aside from that I have no further concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139395

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2023-01-19 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski added a comment.

@jryans thanks.

I've confirmed that this is specifically a bug with `darwin` targets (not 
`macos`) not respecting platform versions when an SDK is present, I can even 
reproduce this with clang provided with Xcode.

The following patch, for example, completely resolves all test errors for me:

  diff
  diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
  index 03c28c14a0ec..a177a1d289b4 100644
  --- a/clang/lib/Driver/ToolChains/Darwin.cpp
  +++ b/clang/lib/Driver/ToolChains/Darwin.cpp
  @@ -2141,13 +2141,14 @@ void Darwin::AddDeploymentTarget(DerivedArgList 
) const {
 else
   SDKName = "iphoneos";
 break;
  -case llvm::Triple::OSType::Darwin:
   case llvm::Triple::OSType::MacOSX:
 SDKName = "macosx";
 break;
   case llvm::Triple::OSType::DriverKit:
 SDKName = "driverkit";
 break;
  +case llvm::Triple::OSType::Darwin:
  +  break;
   default:
 llvm_unreachable("unknown kind of Darwin platform");
   }
  diff --git a/clang/test/Driver/darwin-ld-platform-version-macos.c 
b/clang/test/Driver/darwin-ld-platform-version-macos.c
  index 355df8dfc1bc..5e50d84df6da 100644
  --- a/clang/test/Driver/darwin-ld-platform-version-macos.c
  +++ b/clang/test/Driver/darwin-ld-platform-version-macos.c
  @@ -41,9 +41,6 @@
   // ARM64_NEW_1: "-platform_version" "macos" "11.1.0" "10.14"
   // ARM64_OLD: "-macosx_version_min" "11.0.0"
  
  -// RUN: %clang -target x86_64-apple-macos10.13 -mlinker-version=520 \
  -// RUN:   -### %t.o 2>&1 \
  -// RUN:   | FileCheck --check-prefix=NOSDK %s
   // RUN: %clang -target x86_64-apple-darwin17 -mlinker-version=520 \
   // RUN:   -### %t.o 2>&1 \
   // RUN:   | FileCheck --check-prefix=NOSDK %s
  diff --git a/clang/test/Driver/darwin-sdk-detect.c 
b/clang/test/Driver/darwin-sdk-detect.c
  index dff4def0568a..c5b270c526bd 100644
  --- a/clang/test/Driver/darwin-sdk-detect.c
  +++ b/clang/test/Driver/darwin-sdk-detect.c
  @@ -3,7 +3,7 @@
   // Check that we default to running `xcrun --show-sdk-path` if there is no
   // SDKROOT defined in the environment.
   //
  -// RUN: env -u SDKROOT %clang -target x86_64-apple-darwin -c %s -### 2> 
%t.log
  +// RUN: env -u SDKROOT %clang -target x86_64-apple-macos -c %s -### 2> %t.log
   // RUN: FileCheck --check-prefix=CHECK-XC < %t.log %s
   //
   // CHECK-XC: clang


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D139705: [clang] fix zero-initialization fix-it for variable template

2023-01-19 Thread Chris Lattner via Phabricator via cfe-commits
lattner added a comment.

I'm pretty sure I'm on top of commit access requests now, plz let me know if I 
missed you or something!  Could be spam filter or who knows what


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139705

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


[PATCH] D139737: [-Wunsafe-buffer-usage] Initiate Fix-it generation for local variable declarations

2023-01-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:385
+
+class Strategy;
+

There's already a forward declaration on line 144!



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:412
+arraySubscriptExpr(BaseIsArrayOrPtrDRE,
+   unless(hasIndex(integerLiteral(equals(0)
+.bind(ULCArraySubscriptTag);

Subscripts `[0]` might be safe, but this doesn't mean we should avoid emitting 
fixits when we see them. I think this clause should be dropped here. (Might be 
worth adding a test).



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:723
+  OS << "{";
+  Init->printPretty(OS, nullptr, PP);
+  OS << ", ";

Uhh, I'm worried about this approach. I'm not sure these pretty-printers are 
even correct. They try to look similar to the underlying code, but I don't 
think they're required to. And even if they were, It only takes one forgotten 
override in `StmtPrinter` to produce incorrect pretty-prints that won't 
compile. So it's very unreliable technology.

I think the intended way to do these things is to simply avoid overwriting code 
that you want to preserve. Instead, modify code around it. Eg., if you want to 
change
```lang=c++
int *x = foo();
```
to
```lang=c++
std::span x { foo(), N };
```
then you add `std::span<` before `int`, then don't touch `int`, then replace ` 
*` with `> `, then replace `=` with ` {`, then don't touch `foo()`, then add `, 
N }` immediately after.

If you actually need to move code around (eg., make preserved chunks appear in 
a different order), I think this should go through a facility like 
`Lexer::getSourceText()` which would give you the exact source code as written.


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

https://reviews.llvm.org/D139737

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2023-01-19 Thread J. Ryan Stinnett via Phabricator via cfe-commits
jryans added a comment.

Since we seem to have several breakages here, it does seem best to revert for 
now so that a revised approach can be investigated. I will aim to revert 
tomorrow when back at my desk.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D140179: [WIP][-Wunsafe-buffer-usage] Add unsafe buffer checking opt-out pragmas

2023-01-19 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:551-555
+allOf(declStmt().bind("any_ds"), notInSafeBufferOptOut())
+// We match all DREs regardless of whether they are in safe-buffer
+// opt-out region. Because an unclaimed DRE 'd', regardless of where 
it is,
+// should prevent a Fixable associated to the same variable as 'd'
+// from being emitting.

NoQ wrote:
> ziqingluo-90 wrote:
> > NoQ wrote:
> > > I think we should match all DeclStmts as well, because otherwise we may 
> > > be unable to find the variable to fix.
> > In case we are unable to find the variable to fix,  it means that the 
> > variable declaration is in an opt-out zone.  So we don't fix the variable 
> > anyway, right?
> > 
> > Or do you mean that a variable may still get fixed even if its declaration 
> > is in an opt-out zone?   I could imagine it is possible if the variable is 
> > involved in some assignments that we want to fix.
> > do you mean that a variable may still get fixed even if its declaration is 
> > in an opt-out zone?
> 
> Yes I think that's the case. We do have tests about this right?:
> ```lang=c++
> #pragma clang unsafe_buffer_usage begin
>   ...
>   int *p3 = new int[10]; // expected-warning{{'p3' is an unsafe pointer used 
> for buffer access}}
> 
> #pragma clang unsafe_buffer_usage end
>   ...
>   p3[5]; //expected-note{{used in buffer access here}}
> ```
> And I think it's safe to assume that every time we emit a warning, we also 
> want to emit a fixit.
> 
> If only we had any fixits implemented, this code would have been much easier 
> to refactor because we'd have some actual tests covering it 樂
sorry I didn't think it through when I reply the comments.  You are right.
Fixables and variable declarations should be irrelevant to opt-out regions.

I'll rebase this patch w.r.t. https://reviews.llvm.org/D139737 so that we will 
have tests covering it.


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

https://reviews.llvm.org/D140179

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


[PATCH] D142165: [clang][deps] Account for transitive spurious dependencies

2023-01-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In D106100 , we started guarding against 
spurious dependencies on modules that ended up being textual includes and thus 
didn't have any AST file associated. That patch accounted only for direct 
dependencies. There's a way how to get spurious dependencies for modules that 
are transitive. This patch guards against that scenario and adds a test case.

rdar://104324602


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142165

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-implementation-private.c

Index: clang/test/ClangScanDeps/modules-implementation-private.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-implementation-private.c
@@ -0,0 +1,70 @@
+// This test checks that we don't crash or report spurious dependencies on
+// FW_Private when compiling the implementation of framework module FW.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "file": "DIR/tu.c",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -fmodule-name=FW -F DIR/frameworks -c DIR/tu.c -o DIR/tu.o"
+}]
+
+//--- frameworks/FW.framework/Modules/module.modulemap
+framework module FW { umbrella header "FW.h" }
+//--- frameworks/FW.framework/Modules/module.private.modulemap
+framework module FW_Private { umbrella header "FW_Private.h" }
+//--- frameworks/FW.framework/Headers/FW.h
+//--- frameworks/FW.framework/PrivateHeaders/FW_Private.h
+//--- frameworks/FW.framework/PrivateHeaders/Missed.h
+#import  // When included from tu.c, this ends up adding (spurious) dependency on FW for FW_Private.
+
+//--- tu.c
+@import FW_Private; // This is a direct dependency.
+#import 
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+
+// CHECK:  {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap",
+// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/FW_Private.h"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "name": "FW_Private"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "translation-units": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "commands": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-context-hash": "{{.*}}",
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "FW_Private"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "executable": "clang",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/tu.c",
+// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/Missed.h",
+// CHECK-NEXT: "[[PREFIX]]/frameworks/FW.framework/Headers/FW.h"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "input-file": "[[PREFIX]]/tu.c"
+// CHECK-NEXT: }
+// CHECK:]
+// CHECK:  }
+// CHECK:]
+// CHECK:  }
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -379,15 +379,8 @@
 if (!MDC.isPrebuiltModule(M))
   DirectModularDeps.insert(M);
 
-  for (const Module *M : DirectModularDeps) {
-// A top-level module might not be actually imported as a module when
-// -fmodule-name is used to compile a translation unit that imports this
-// module. In that case it can be skipped. The appropriate header
-// dependencies will still be reported as expected.
-if (!M->getASTFile())
-  continue;
+  for (const Module *M : DirectModularDeps)
 handleTopLevelModule(M);
-  }
 
   MDC.Consumer.handleDependencyOutputOpts(*MDC.Opts);
 
@@ -401,9 +394,17 @@
 

[PATCH] D140179: [WIP][-Wunsafe-buffer-usage] Add unsafe buffer checking opt-out pragmas

2023-01-19 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:543
 #define GADGET(x)  
\
-x ## Gadget::matcher().bind(#x),
+allOf(x ## Gadget::matcher().bind(#x), notInSafeBufferOptOut()),
 #include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def"

ziqingluo-90 wrote:
> NoQ wrote:
> > This prevents safe fixable gadgets from being found in the opt-out zone. I 
> > think this clause should only apply to warning gadgets.
> You are right!  Fixables should be found regardless of whether they are in an 
> opt-out zone.  A Fixable could later be immediately discarded once we know 
> that the variable declaration associated to the Fixable is in an opt-out zone.
Oh wait, scratch what I said above.

`FixableGadget`s should be found regardless of whether they are in an opt-out 
zone.   They will be attached to variable declarations.  The emission of an 
Unsafe Buffer diagnostic of a variable declaration only depends on 
`WarningGadget`s.   So `FixableGadget`s have nothing to do with opt-out 
regions. 



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

https://reviews.llvm.org/D140179

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


[PATCH] D141738: Add initial support for cross compile Windows runtimes under Linux when building Fuchsia clang toolchain

2023-01-19 Thread Haowei Wu via Phabricator via cfe-commits
haowei marked 2 inline comments as done.
haowei added inline comments.



Comment at: clang/cmake/caches/Fuchsia-stage2.cmake:73
+
+if(WIN32 OR (LINUX AND WINDOWS_SDK_DIR))
+#if(WINDOWS_SDK_DIR)

phosek wrote:
> I'd drop this part altogether, let's build these anytime when 
> `WINDOWS_SDK_DIR` is set.
We need to do a soft transition if we drop the "WIN32" since the bots are not 
passing the WINSYSROOT flag yet. Let's keep the WIN32 here.



Comment at: clang/cmake/caches/Fuchsia-stage2.cmake:105-108
+-libpath:"${WINDOWS_SDK_DIR}/VC/Tools/MSVC/14.34.31933/lib/x64"
+-libpath:"${WINDOWS_SDK_DIR}/VC/Tools/MSVC/14.34.31933/atlmfc/lib/x64"
+-libpath:"${WINDOWS_SDK_DIR}/Windows Kits/10/Lib/10.0.19041.0/ucrt/x64"
+-libpath:"${WINDOWS_SDK_DIR}/Windows Kits/10/Lib/10.0.19041.0/um/x64")

phosek wrote:
> These should be set automatically if you set `/winsysroot` (through 
> `LLVM_WINSYSROOT`), see 
> https://github.com/llvm/llvm-project/blob/a64846bee0bb4b4912c8cf6bf018ba5d892065d1/clang/lib/Driver/ToolChains/MSVC.cpp#L107.
There is an issue that "CLANG_CL" variable is not correctly set when clang 
kicks runtime build. When CLANG_CL is not set, the /winsysroot will not be 
added by the LLVM_WINSYSROOT flag. I have some thoughts about it and prefer to 
address this issue in a follow up patch instead of put everything here.



Comment at: clang/cmake/caches/Fuchsia-stage2.cmake:144-145
+"${WINDOWS_SDK_DIR}/llvm-vfsoverlay.yaml"
+/winsysroot
+${WINDOWS_SDK_DIR})
+string(REPLACE ";" " " CLANG_WINDOWS_CROSS_FLAGS 
"${CLANG_WINDOWS_CROSS_FLAGS}")

phosek wrote:
> Can we instead set `RUNTIMES_${target}_LLVM_WINSYSROOT` to 
> `${WINDOWS_SDK_DIR}`?
As stated in an earlier comment, this will require fixing the setting the 
"CLANG_CL" variable in compiler version detection. 



Comment at: llvm/runtimes/CMakeLists.txt:359
 
-  if(NOT RUNTIMES_${name}_LLVM_USE_LINKER AND NOT 
RUNTIMES_${target}_LLVM_USE_LINKER)
+  if(NOT RUNTIMES_${name}_LLVM_USE_LINKER AND NOT 
RUNTIMES_${target}_LLVM_USE_LINKER AND NOT ${target} STREQUAL 
"x86_64-pc-windows-msvc")
 list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER})

phosek wrote:
> We should fix the build so that this isn't needed, it should be possible to 
> use `LLVM_USE_LINKER=lld` when targeting Windows.
I made some other changes and now the /fuse-ld=lld will be passed to 
lld-link.exe if we leave this line unchanged. 
It will through a warning but won't stop the build.
Once I fix the CLANG_CL issue, I can prevent it from inserting `/fuse-ld=lld` 
when using CLANG_CL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141738

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


[PATCH] D140179: [WIP][-Wunsafe-buffer-usage] Add unsafe buffer checking opt-out pragmas

2023-01-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:551-555
+allOf(declStmt().bind("any_ds"), notInSafeBufferOptOut())
+// We match all DREs regardless of whether they are in safe-buffer
+// opt-out region. Because an unclaimed DRE 'd', regardless of where 
it is,
+// should prevent a Fixable associated to the same variable as 'd'
+// from being emitting.

ziqingluo-90 wrote:
> NoQ wrote:
> > I think we should match all DeclStmts as well, because otherwise we may be 
> > unable to find the variable to fix.
> In case we are unable to find the variable to fix,  it means that the 
> variable declaration is in an opt-out zone.  So we don't fix the variable 
> anyway, right?
> 
> Or do you mean that a variable may still get fixed even if its declaration is 
> in an opt-out zone?   I could imagine it is possible if the variable is 
> involved in some assignments that we want to fix.
> do you mean that a variable may still get fixed even if its declaration is in 
> an opt-out zone?

Yes I think that's the case. We do have tests about this right?:
```lang=c++
#pragma clang unsafe_buffer_usage begin
  ...
  int *p3 = new int[10]; // expected-warning{{'p3' is an unsafe pointer used 
for buffer access}}

#pragma clang unsafe_buffer_usage end
  ...
  p3[5]; //expected-note{{used in buffer access here}}
```
And I think it's safe to assume that every time we emit a warning, we also want 
to emit a fixit.

If only we had any fixits implemented, this code would have been much easier to 
refactor because we'd have some actual tests covering it 樂


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

https://reviews.llvm.org/D140179

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


[PATCH] D141738: Add initial support for cross compile Windows runtimes under Linux when building Fuchsia clang toolchain

2023-01-19 Thread Haowei Wu via Phabricator via cfe-commits
haowei updated this revision to Diff 490679.
haowei retitled this revision from "[WIP] Add initial support for cross compile 
Windows runtimes under Linux when building Fuchsia clang toolchain" to "Add 
initial support for cross compile Windows runtimes under Linux when building 
Fuchsia clang toolchain".
haowei edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141738

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  llvm/cmake/modules/LLVMExternalProjectUtils.cmake


Index: llvm/cmake/modules/LLVMExternalProjectUtils.cmake
===
--- llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -213,6 +213,12 @@
 if(llvm-readelf IN_LIST TOOLCHAIN_TOOLS)
   list(APPEND compiler_args 
-DCMAKE_READELF=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-readelf${CMAKE_EXECUTABLE_SUFFIX})
 endif()
+if(llvm-mt IN_LIST TOOLCHAIN_TOOLS AND is_msvc_target)
+  list(APPEND compiler_args 
-DCMAKE_MT=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-mt${CMAKE_EXECUTABLE_SUFFIX})
+endif()
+if(llvm-rc IN_LIST TOOLCHAIN_TOOLS AND is_msvc_target)
+  list(APPEND compiler_args 
-DCMAKE_RC_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-rc${CMAKE_EXECUTABLE_SUFFIX})
+endif()
 list(APPEND ARG_DEPENDS ${TOOLCHAIN_TOOLS})
   endif()
 
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -69,13 +69,48 @@
   set(RUNTIMES_CMAKE_ARGS 
"-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13;-DCMAKE_OSX_ARCHITECTURES=arm64|x86_64" 
CACHE STRING "")
 endif()
 
-if(WIN32)
+if(WIN32 OR LLVM_WINSYSROOT)
+  if((NOT WIN32) AND (NOT LLVM_VFSOVERLAY))
+message(FATAL_ERROR "LLVM_VFSOVERLAY should be defined.")
+  endif()
   set(target "x86_64-pc-windows-msvc")
 
+  if (LLVM_WINSYSROOT)
+set(CLANG_WINDOWS_CROSS_FLAGS
+  -Xclang
+  -ivfsoverlay
+  -Xclang
+  ${LLVM_VFSOVERLAY}
+  # TODO: /winsysroot should be set by HandleLLVMOptions.cmake 
automatically
+  # but it current has a bug that prevents it from working under cross
+  # compilation. Set this flag manually for now.
+  /winsysroot
+  ${LLVM_WINSYSROOT})
+string(REPLACE ";" " " CLANG_WINDOWS_CROSS_FLAGS 
"${CLANG_WINDOWS_CROSS_FLAGS}")
+set(LINK_WINDOWS_CROSS_FLAGS
+/vfsoverlay:${LLVM_VFSOVERLAY}
+# TODO: On Windows, linker is invoked by cmake instead of the clang-cl 
driver,
+# so we have to manually set the libpath. We use clang-cl driver if we 
can
+# and remove these libpath flags.
+-libpath:"${LLVM_WINSYSROOT}/VC/Tools/MSVC/14.34.31933/lib/x64"
+-libpath:"${LLVM_WINSYSROOT}/VC/Tools/MSVC/14.34.31933/atlmfc/lib/x64"
+-libpath:"${LLVM_WINSYSROOT}/Windows Kits/10/Lib/10.0.19041.0/ucrt/x64"
+-libpath:"${LLVM_WINSYSROOT}/Windows Kits/10/Lib/10.0.19041.0/um/x64")
+string(REPLACE ";" " " LINK_WINDOWS_CROSS_FLAGS 
"${LINK_WINDOWS_CROSS_FLAGS}")
+  endif()
+
   list(APPEND BUILTIN_TARGETS "${target}")
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
 
+  if(LLVM_WINSYSROOT)
+set(BUILTINS_${target}_CMAKE_C_FLAGS ${CLANG_WINDOWS_CROSS_FLAGS} CACHE 
STRING "")
+set(BUILTINS_${target}_CMAKE_CXX_FLAGS ${CLANG_WINDOWS_CROSS_FLAGS} CACHE 
STRING "")
+set(BUILTINS_${target}_CMAKE_EXE_LINKER_FLAGS ${LINK_WINDOWS_CROSS_FLAGS} 
CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_SHARED_LINKER_FLAGS 
${LINK_WINDOWS_CROSS_FLAGS} CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_MODULE_LINKER_FLAGS 
${LINK_WINDOWS_CROSS_FLAGS} CACHE STRING "")
+  endif()
+
   list(APPEND RUNTIME_TARGETS "${target}")
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
@@ -84,6 +119,15 @@
   set(RUNTIMES_${target}_LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE 
STRING "")
+
+  if(LLVM_WINSYSROOT)
+set(RUNTIMES_${target}_CMAKE_REQUIRED_FLAGS ${CLANG_WINDOWS_CROSS_FLAGS} 
CACHE STRING "")
+set(RUNTIMES_${target}_CMAKE_C_FLAGS ${CLANG_WINDOWS_CROSS_FLAGS} CACHE 
STRING "")
+set(RUNTIMES_${target}_CMAKE_CXX_FLAGS ${CLANG_WINDOWS_CROSS_FLAGS} CACHE 
STRING "")
+set(RUNTIMES_${target}_CMAKE_EXE_LINKER_FLAGS ${LINK_WINDOWS_CROSS_FLAGS} 
CACHE STRING "")
+set(RUNTIMES_${target}_CMAKE_SHARED_LINKER_FLAGS 
${LINK_WINDOWS_CROSS_FLAGS} CACHE STRING "")
+set(RUNTIMES_${target}_CMAKE_MODULE_LINKER_FLAGS 
${LINK_WINDOWS_CROSS_FLAGS} CACHE STRING "")
+  endif()
 endif()
 
 foreach(target 

[PATCH] D142118: [HIP] Unbundler allows missing host entry

2023-01-19 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/lib/Driver/OffloadBundler.cpp:1063
   // in case host bundle name was provided in command line.
-  if (!FoundHostBundle && BundlerConfig.HostInputIndex != ~0u)
+  if (!FoundHostBundle && BundlerConfig.HostInputIndex != ~0u && 
!BundlerConfig.AllowMissingBundles)
 return createStringError(inconvertibleErrorCode(),

tra wrote:
> Nit: My usual pet peeve - too many negations. 
> 
> `if (!(FoundHostBundle || BundlerConfig.HostInputIndex == ~0u || 
> BundlerConfig.AllowMissingBundles)))` is easier to understand, IMO.
will fix when committing


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

https://reviews.llvm.org/D142118

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


[PATCH] D140059: [APSInt] Fix bug in APSInt mentioned in https://github.com/llvm/llvm-project/issues/59515

2023-01-19 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140059

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


[PATCH] D142143: [Lex] For dependency directive lexing, angled includes in `__has_include` should be lexed as string literals

2023-01-19 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
akyrtzi marked an inline comment as done.
Closed by commit rGed6d09dd4ead: [Lex] For dependency directive lexing, angled 
includes in `__has_include`… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142143

Files:
  clang/lib/Lex/Lexer.cpp
  clang/test/ClangScanDeps/depscan-lex-has-include.c


Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+// CHECK: t.c
+// CHECK: something.h
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-error.json.template > %t/cdb-error.json
+// RUN: not clang-scan-deps -compilation-database %t/cdb-error.json 2>&1 | 
FileCheck %s -check-prefix=ERROR
+// ERROR: error: expected '>'
+// ERROR: error: expected value in expression
+
+//--- cdb.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/t.c -I DIR",
+"file": "DIR/t.c"
+  }
+]
+
+//--- cdb-error.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/error.c",
+"file": "DIR/error.c"
+  }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include()
+#include 
+#endif
+
+//--- something/something.h
+
+//--- error.c
+#if __has_include(= BufferPtr)
+break;
+  ++NextDepDirectiveTokenIndex;
+}
+return true;
+  }
+
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 
   if (Result.is(tok::hash) && Result.isAtStartOfLine()) {


Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+// CHECK: t.c
+// CHECK: something.h
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-error.json.template > %t/cdb-error.json
+// RUN: not clang-scan-deps -compilation-database %t/cdb-error.json 2>&1 | FileCheck %s -check-prefix=ERROR
+// ERROR: error: expected '>'
+// ERROR: error: expected value in expression
+
+//--- cdb.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/t.c -I DIR",
+"file": "DIR/t.c"
+  }
+]
+
+//--- cdb-error.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/error.c",
+"file": "DIR/error.c"
+  }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include()
+#include 
+#endif
+
+//--- something/something.h
+
+//--- error.c
+#if __has_include(= BufferPtr)
+break;
+  ++NextDepDirectiveTokenIndex;
+}
+return true;
+  }
+
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 
   if (Result.is(tok::hash) && Result.isAtStartOfLine()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ed6d09d - [Lex] For dependency directive lexing, angled includes in `__has_include` should be lexed as string literals

2023-01-19 Thread Argyrios Kyrtzidis via cfe-commits

Author: Argyrios Kyrtzidis
Date: 2023-01-19T15:23:21-08:00
New Revision: ed6d09dd4ead70d2858d56c530af38eefa1ef595

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

LOG: [Lex] For dependency directive lexing, angled includes in `__has_include` 
should be lexed as string literals

rdar://104386604

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

Added: 
clang/test/ClangScanDeps/depscan-lex-has-include.c

Modified: 
clang/lib/Lex/Lexer.cpp

Removed: 




diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 578bd69ddbfbc..d49d9e9e4b142 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -4408,6 +4408,22 @@ bool Lexer::LexDependencyDirectiveToken(Token ) {
 MIOpt.ReadToken();
   }
 
+  if (ParsingFilename && DDTok.is(tok::less)) {
+BufferPtr = BufferStart + DDTok.Offset;
+LexAngledStringLiteral(Result, BufferPtr + 1);
+if (Result.isNot(tok::header_name))
+  return true;
+// Advance the index of lexed tokens.
+while (true) {
+  const dependency_directives_scan::Token  =
+  DepDirectives.front().Tokens[NextDepDirectiveTokenIndex];
+  if (BufferStart + NextTok.Offset >= BufferPtr)
+break;
+  ++NextDepDirectiveTokenIndex;
+}
+return true;
+  }
+
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 
   if (Result.is(tok::hash) && Result.isAtStartOfLine()) {

diff  --git a/clang/test/ClangScanDeps/depscan-lex-has-include.c 
b/clang/test/ClangScanDeps/depscan-lex-has-include.c
new file mode 100644
index 0..4d46e8d7d19e2
--- /dev/null
+++ b/clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+// CHECK: t.c
+// CHECK: something.h
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-error.json.template > %t/cdb-error.json
+// RUN: not clang-scan-deps -compilation-database %t/cdb-error.json 2>&1 | 
FileCheck %s -check-prefix=ERROR
+// ERROR: error: expected '>'
+// ERROR: error: expected value in expression
+
+//--- cdb.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/t.c -I DIR",
+"file": "DIR/t.c"
+  }
+]
+
+//--- cdb-error.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/error.c",
+"file": "DIR/error.c"
+  }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include()
+#include 
+#endif
+
+//--- something/something.h
+
+//--- error.c
+#if __has_include(https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141625: [DeclContext] Sort the Decls before adding into DeclContext

2023-01-19 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D141625#4066961 , @steven_wu wrote:

> No, reverse iteration will not break diff test for a small number of decls. 
> Everything will be in reverse order so it is the same.

Hmm, I'm not sure I'm following why that is - could you explain this in more 
detail? The usual problem is that, say, we're outputting based on an unstable 
order - even two items would be enough to cause a test of that to fail in 
either forward or reverse iteration mode until the order is stabilized.

Is that not the case here? Is there some interaction between iteration order 
that's part of the nondeterminism here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141625

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


[PATCH] D139837: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

2023-01-19 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added a comment.

Thanks for your effort on this!

FYI I landed parenthesized aggregate initialization in D141546 
, so CTAD for that feature should no longer 
be blocked.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139837

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2023-01-19 Thread Caleb Zulawski via Phabricator via cfe-commits
calebzulawski added a comment.

One thing to throw into the mix: Apple's clang has a default sysroot 
configured, so with the default system compiler, there is no way to replicate 
this "build without a sysroot" scenario as far as I can tell.  For the system 
compiler, I believe this behavior is a strict improvement.

Looking at all of the errors, it looks like the common thread is that when a 
sysroot is present, the version in the target triple (e.g. 
`x86_64-apple-macos10`) isn't respected.  If this is true, I think this 
possibly uncovered an existing bug...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D139741: [clang][CodeGen] Use base subobject type layout for potentially-overlapping fields

2023-01-19 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139741

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


[PATCH] D140663: CUDA/HIP: Use kernel name to map to symbol

2023-01-19 Thread Daniele Castagna 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 rG32c26e27b6fc: CUDA/HIP: Use kernel name to map to symbol 
(authored by dcastagna).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140663

Files:
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/test/CodeGenCUDA/incomplete-func-ptr-type.cu

Index: clang/test/CodeGenCUDA/incomplete-func-ptr-type.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/incomplete-func-ptr-type.cu
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -x hip %s -o - \
+// RUN: | FileCheck %s
+
+#define __global__ __attribute__((global))
+// CHECK: @_Z4kern7TempValIjE = constant ptr @_Z19__device_stub__kern7TempValIjE, align 8
+// CHECK: @0 = private unnamed_addr constant [19 x i8] c"_Z4kern7TempValIjE\00", align 1
+template 
+struct TempVal {
+  type value;
+};
+
+__global__ void kern(TempVal in_val);
+
+int main(int argc, char ** argv) {
+  auto* fptr = &(kern);
+// CHECK:   store ptr @_Z4kern7TempValIjE, ptr %fptr, align 8
+  return 0;
+}
+// CHECK:  define dso_local void @_Z19__device_stub__kern7TempValIjE(i32 %in_val.coerce) #1 {
+// CHECK:  %2 = call i32 @hipLaunchByPtr(ptr @_Z4kern7TempValIjE)
+
+// CHECK:  define internal void @__hip_register_globals(ptr %0) {
+// CHECK:%1 = call i32 @__hipRegisterFunction(ptr %0, ptr @_Z4kern7TempValIjE, ptr @0, ptr @0, i32 -1, ptr null, ptr null, ptr null, ptr null, ptr null)
+
+__global__ void kern(TempVal in_val) {
+}
+
Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -49,10 +49,10 @@
 const Decl *D;
   };
   llvm::SmallVector EmittedKernels;
-  // Map a device stub function to a symbol for identifying kernel in host code.
+  // Map a kernel mangled name to a symbol for identifying kernel in host code
   // For CUDA, the symbol for identifying the kernel is the same as the device
   // stub function. For HIP, they are different.
-  llvm::DenseMap KernelHandles;
+  llvm::DenseMap KernelHandles;
   // Map a kernel handle to the kernel stub.
   llvm::DenseMap KernelStubs;
   struct VarInfo {
@@ -310,7 +310,8 @@
 void CGNVCUDARuntime::emitDeviceStub(CodeGenFunction ,
  FunctionArgList ) {
   EmittedKernels.push_back({CGF.CurFn, CGF.CurFuncDecl});
-  if (auto *GV = dyn_cast(KernelHandles[CGF.CurFn])) {
+  if (auto *GV =
+  dyn_cast(KernelHandles[CGF.CurFn->getName()])) {
 GV->setLinkage(CGF.CurFn->getLinkage());
 GV->setInitializer(CGF.CurFn);
   }
@@ -400,8 +401,8 @@
ShmemSize.getPointer(), Stream.getPointer()});
 
   // Emit the call to cudaLaunch
-  llvm::Value *Kernel =
-  CGF.Builder.CreatePointerCast(KernelHandles[CGF.CurFn], VoidPtrTy);
+  llvm::Value *Kernel = CGF.Builder.CreatePointerCast(
+  KernelHandles[CGF.CurFn->getName()], VoidPtrTy);
   CallArgList LaunchKernelArgs;
   LaunchKernelArgs.add(RValue::get(Kernel),
cudaLaunchKernelFD->getParamDecl(0)->getType());
@@ -456,8 +457,8 @@
 
   // Emit the call to cudaLaunch
   llvm::FunctionCallee cudaLaunchFn = getLaunchFn();
-  llvm::Value *Arg =
-  CGF.Builder.CreatePointerCast(KernelHandles[CGF.CurFn], CharPtrTy);
+  llvm::Value *Arg = CGF.Builder.CreatePointerCast(
+  KernelHandles[CGF.CurFn->getName()], CharPtrTy);
   CGF.EmitRuntimeCallOrInvoke(cudaLaunchFn, Arg);
   CGF.EmitBranch(EndBlock);
 
@@ -551,7 +552,7 @@
 llvm::Constant *NullPtr = llvm::ConstantPointerNull::get(VoidPtrTy);
 llvm::Value *Args[] = {
 ,
-Builder.CreateBitCast(KernelHandles[I.Kernel], VoidPtrTy),
+Builder.CreateBitCast(KernelHandles[I.Kernel->getName()], VoidPtrTy),
 KernelName,
 KernelName,
 llvm::ConstantInt::get(IntTy, -1),
@@ -1130,7 +1131,7 @@
   StringRef Section = CGM.getLangOpts().HIP ? "hip_offloading_entries"
 : "cuda_offloading_entries";
   for (KernelInfo  : EmittedKernels)
-OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel],
+OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel->getName()],
getDeviceSideName(cast(I.D)), 0,
DeviceVarFlags::OffloadGlobalEntry, Section);
 
@@ -1193,12 +1194,12 @@
 
 llvm::GlobalValue *CGNVCUDARuntime::getKernelHandle(llvm::Function *F,
 GlobalDecl GD) {
-  auto Loc = KernelHandles.find(F);
+  auto Loc = KernelHandles.find(F->getName());
   if (Loc != KernelHandles.end())
 return Loc->second;
 
   if (!CGM.getLangOpts().HIP) {
-KernelHandles[F] = F;
+KernelHandles[F->getName()] = F;
 KernelStubs[F] = F;

[clang] 32c26e2 - CUDA/HIP: Use kernel name to map to symbol

2023-01-19 Thread Daniele Castagna via cfe-commits

Author: Daniele Castagna
Date: 2023-01-19T15:02:14-08:00
New Revision: 32c26e27b6fcd12703dcd00adf178330d0ad8449

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

LOG: CUDA/HIP: Use kernel name to map to symbol

Currently CGCUDANV uses an llvm::Function as a key to map kernels to a
symbol in host code.  HIP adds one level of indirection and uses the
llvm::Function to map to a global variable that will be initialized to
the kernel stub ptr.

Unfortunately there is no garantee that the llvm::Function created
by GetOrCreateLLVMFunction will be the same.  In fact, the first
time we encounter GetOrCrateLLVMFunction for a kernel, the type
might not be completed yet, and the type of llvm::Function will be
a generic {}, since the complete type is not required to get a symbol
to a function.  In this case we end up creating two global variables,
one for the llvm::Function with the incomplete type and one for the
function with the complete type. The first global variable will be
declared by not defined, resulting in a linking error.

This change uses the mangled name of the llvm::Function as key in the
KernelHandles map, in this way the same llvm::Function will be
associated to the same kernel handle even if they types are different.

Reviewed By: yaxunl

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

Added: 
clang/test/CodeGenCUDA/incomplete-func-ptr-type.cu

Modified: 
clang/lib/CodeGen/CGCUDANV.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index abf320996dc4d..bb887df3e4e04 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -49,10 +49,10 @@ class CGNVCUDARuntime : public CGCUDARuntime {
 const Decl *D;
   };
   llvm::SmallVector EmittedKernels;
-  // Map a device stub function to a symbol for identifying kernel in host 
code.
+  // Map a kernel mangled name to a symbol for identifying kernel in host code
   // For CUDA, the symbol for identifying the kernel is the same as the device
   // stub function. For HIP, they are 
diff erent.
-  llvm::DenseMap KernelHandles;
+  llvm::DenseMap KernelHandles;
   // Map a kernel handle to the kernel stub.
   llvm::DenseMap KernelStubs;
   struct VarInfo {
@@ -310,7 +310,8 @@ std::string CGNVCUDARuntime::getDeviceSideName(const 
NamedDecl *ND) {
 void CGNVCUDARuntime::emitDeviceStub(CodeGenFunction ,
  FunctionArgList ) {
   EmittedKernels.push_back({CGF.CurFn, CGF.CurFuncDecl});
-  if (auto *GV = dyn_cast(KernelHandles[CGF.CurFn])) {
+  if (auto *GV =
+  dyn_cast(KernelHandles[CGF.CurFn->getName()])) 
{
 GV->setLinkage(CGF.CurFn->getLinkage());
 GV->setInitializer(CGF.CurFn);
   }
@@ -400,8 +401,8 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction 
,
ShmemSize.getPointer(), Stream.getPointer()});
 
   // Emit the call to cudaLaunch
-  llvm::Value *Kernel =
-  CGF.Builder.CreatePointerCast(KernelHandles[CGF.CurFn], VoidPtrTy);
+  llvm::Value *Kernel = CGF.Builder.CreatePointerCast(
+  KernelHandles[CGF.CurFn->getName()], VoidPtrTy);
   CallArgList LaunchKernelArgs;
   LaunchKernelArgs.add(RValue::get(Kernel),
cudaLaunchKernelFD->getParamDecl(0)->getType());
@@ -456,8 +457,8 @@ void 
CGNVCUDARuntime::emitDeviceStubBodyLegacy(CodeGenFunction ,
 
   // Emit the call to cudaLaunch
   llvm::FunctionCallee cudaLaunchFn = getLaunchFn();
-  llvm::Value *Arg =
-  CGF.Builder.CreatePointerCast(KernelHandles[CGF.CurFn], CharPtrTy);
+  llvm::Value *Arg = CGF.Builder.CreatePointerCast(
+  KernelHandles[CGF.CurFn->getName()], CharPtrTy);
   CGF.EmitRuntimeCallOrInvoke(cudaLaunchFn, Arg);
   CGF.EmitBranch(EndBlock);
 
@@ -551,7 +552,7 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
 llvm::Constant *NullPtr = llvm::ConstantPointerNull::get(VoidPtrTy);
 llvm::Value *Args[] = {
 ,
-Builder.CreateBitCast(KernelHandles[I.Kernel], VoidPtrTy),
+Builder.CreateBitCast(KernelHandles[I.Kernel->getName()], VoidPtrTy),
 KernelName,
 KernelName,
 llvm::ConstantInt::get(IntTy, -1),
@@ -1130,7 +1131,7 @@ void CGNVCUDARuntime::createOffloadingEntries() {
   StringRef Section = CGM.getLangOpts().HIP ? "hip_offloading_entries"
 : "cuda_offloading_entries";
   for (KernelInfo  : EmittedKernels)
-OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel],
+OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel->getName()],
getDeviceSideName(cast(I.D)), 0,
DeviceVarFlags::OffloadGlobalEntry, 
Section);
 
@@ -1193,12 +1194,12 @@ llvm::Function 

[PATCH] D141310: [clang] add -Wcompare-function-pointers

2023-01-19 Thread Adrian Dole via Phabricator via cfe-commits
adriandole updated this revision to Diff 490671.
adriandole added a comment.

Only trigger this warning when comparing function pointers of the same type, 
since comparing distinct types is already an error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141310

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/compare-function-pointer.cpp


Index: clang/test/SemaCXX/compare-function-pointer.cpp
===
--- clang/test/SemaCXX/compare-function-pointer.cpp
+++ clang/test/SemaCXX/compare-function-pointer.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify 
-Wcompare-function-pointers %s
 
 using fp0_t = void (*)();
 using fp1_t = int (*)();
@@ -6,8 +6,8 @@
 extern fp0_t a, b;
 extern fp1_t c;
 
-bool eq0 = a == b;
-bool ne0 = a != b;
+bool eq0 = a == b;  // expected-warning {{distinct function pointers ('fp0_t' 
(aka 'void (*)()') and 'fp0_t')}}
+bool ne0 = a != b;  // expected-warning {{distinct function pointers}}
 bool lt0 = a < b;   // expected-warning {{ordered comparison of function 
pointers ('fp0_t' (aka 'void (*)()') and 'fp0_t')}}
 bool le0 = a <= b;  // expected-warning {{ordered comparison of function 
pointers}}
 bool gt0 = a > b;   // expected-warning {{ordered comparison of function 
pointers}}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -12714,6 +12714,13 @@
LHS.get()->getSourceRange());
   }
 
+  if (!IsOrdered && LHSType->isFunctionPointerType() &&
+  RHSType->isFunctionPointerType() && !LHSIsNull && !RHSIsNull &&
+  RHSType == LHSType)
+Diag(Loc, diag::warn_typecheck_comparison_of_function_pointers)
+  << LHSType << RHSType
+  << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
+
   if (IsOrdered && LHSType->isFunctionPointerType() &&
   RHSType->isFunctionPointerType()) {
 // Valid unless a relational comparison of function pointers
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7010,6 +7010,10 @@
   "%0 is %select{|in}2complete and "
   "%1 is %select{|in}3complete">,
   InGroup;
+def warn_typecheck_comparison_of_function_pointers : Warning<
+  "distinct function pointers (%0 and %1) may compare equal "
+  "when using identical code folding">,
+  InGroup, DefaultIgnore;
 def warn_typecheck_ordered_comparison_of_function_pointers : Warning<
   "ordered comparison of function pointers (%0 and %1)">,
   InGroup;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -565,6 +565,7 @@
 def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
 def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
 def OrderedCompareFunctionPointers : 
DiagGroup<"ordered-compare-function-pointers">;
+def CompareFunctionPointers : DiagGroup<"compare-function-pointers", 
[OrderedCompareFunctionPointers]>;
 def PackedNonPod : DiagGroup<"packed-non-pod">;
 def Packed : DiagGroup<"packed", [PackedNonPod]>;
 def Padded : DiagGroup<"padded">;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -465,6 +465,8 @@
 - Clang now automatically adds ``[[clang::lifetimebound]]`` to the parameters 
of
   ``std::move, std::forward`` et al, this enables Clang to diagnose more cases
   where the returned reference outlives the object.
+- Add ``-Wcompare-function-pointers`` to warn about comparisons that may have 
their behavior
+  change when enabling the identical code folding optimization feature of some 
linkers.
 
 Non-comprehensive list of changes in this release
 -


Index: clang/test/SemaCXX/compare-function-pointer.cpp
===
--- clang/test/SemaCXX/compare-function-pointer.cpp
+++ clang/test/SemaCXX/compare-function-pointer.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify -Wcompare-function-pointers %s
 
 using fp0_t = void (*)();
 using fp1_t = int (*)();
@@ -6,8 +6,8 @@
 extern fp0_t a, b;
 extern fp1_t c;
 
-bool eq0 = a == b;
-bool ne0 = a != b;
+bool eq0 = a == b;  // 

[PATCH] D142101: [clang] [extract-api] Don't crash for category in libclang APIs

2023-01-19 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:537-544
+  generatePathComponents(Record, API,
+ [Lang, ](const PathComponent ) {
+   ParentContexts.push_back(
+   serializeParentContext(PC, Lang));
+ });
+
+  // The last component would be the record itself so let's remove it.

bnbarham wrote:
> It's not really clear to me what the intended behavior was meant to be here, 
> ie. whether if any parent fails we skip writing all *or* if we should be 
> writing all valid parents. I'll leave that to someone that knows more about 
> the symbolgraph output.
> 
> But this fixes the obvious crash, so that part is fine with me.
I think it is a bit of a grey area, having parent contexts and related symbols 
allows downstream clients to perform link resolution on declaration fragment 
chunks e.t.c I figured it would be best to do a best effort and provide the 
known parents.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142101

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


[PATCH] D142113: [clang][nfc] refactor Module::Header to use OptionalFileEntryRef

2023-01-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 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/D142113/new/

https://reviews.llvm.org/D142113

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2023-01-19 Thread Daniel Thornburgh via Phabricator via cfe-commits
mysterymath added a comment.

This also appears to be breaking the Darwin build for the Fuchsia toolchain, 
with similar test failures to those seen by @thakis.
Given the scope of the breakages, can we revert this and reland later?

See: 
https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-mac-x64/b8791526664823090241/overview


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D142118: [HIP] Unbundler allows missing host entry

2023-01-19 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/OffloadBundler.cpp:1063
   // in case host bundle name was provided in command line.
-  if (!FoundHostBundle && BundlerConfig.HostInputIndex != ~0u)
+  if (!FoundHostBundle && BundlerConfig.HostInputIndex != ~0u && 
!BundlerConfig.AllowMissingBundles)
 return createStringError(inconvertibleErrorCode(),

Nit: My usual pet peeve - too many negations. 

`if (!(FoundHostBundle || BundlerConfig.HostInputIndex == ~0u || 
BundlerConfig.AllowMissingBundles)))` is easier to understand, IMO.


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

https://reviews.llvm.org/D142118

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


[PATCH] D141871: [Clang][OpenMP] Add parse and sema for iterator map modifier

2023-01-19 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 490659.

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

https://reviews.llvm.org/D141871

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/declare_mapper_ast_print.c
  clang/test/OpenMP/declare_mapper_messages.c
  clang/test/OpenMP/target_ast_print.cpp
  clang/test/OpenMP/target_map_messages.cpp

Index: clang/test/OpenMP/target_map_messages.cpp
===
--- clang/test/OpenMP/target_map_messages.cpp
+++ clang/test/OpenMP/target_map_messages.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -verify=expected,lt50,lt51,omp,lt51-omp -fopenmp -fno-openmp-extensions -fopenmp-version=45 -ferror-limit 300 %s -Wno-openmp-target -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,ge50,lt51,omp,lt51-omp -fopenmp -fno-openmp-extensions -fopenmp-version=50 -ferror-limit 300 %s -Wno-openmp-target -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,ge50,ge51,omp,ge51-omp -fopenmp -fno-openmp-extensions -fopenmp-version=51 -ferror-limit 300 %s -Wno-openmp-target -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,ge50,ge51,ge52,omp,ge52-omp -fopenmp -fno-openmp-extensions -fopenmp-version=52 -ferror-limit 300 %s -Wno-openmp-target -Wuninitialized
 // RUN: %clang_cc1 -DCCODE -verify -fopenmp -fno-openmp-extensions -ferror-limit 300 -x c %s -Wno-openmp -Wuninitialized
 
 // -fopenmp-simd, -fno-openmp-extensions
@@ -158,23 +159,28 @@
 // expected-error@+1 {{use of undeclared identifier 'present'}}
 #pragma omp target map(present)
 {}
+// ge52-omp-error@+3 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // ge51-omp-error@+2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
 #pragma omp target map(ompx_hold, tofrom: c,f)
 {}
+// ge52-omp-error@+3 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // ge51-omp-error@+2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
 #pragma omp target map(ompx_hold, tofrom: c[1:2],f)
 {}
+// ge52-omp-error@+3 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // ge51-omp-error@+2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
 #pragma omp target map(ompx_hold, tofrom: c,f[1:2])
 {}
+// ge52-omp-error@+4 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // expected-error@+3 {{section length is unspecified and cannot be inferred because subscripted value is not an array}}
 // ge51-omp-error@+2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
 #pragma omp target map(ompx_hold, tofrom: c[:],f)
 {}
+// ge52-omp-error@+4 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // expected-error@+3 {{section length is unspecified and cannot be inferred because subscripted value is not an array}}
 // ge51-omp-error@+2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
@@ -191,11 +197,15 @@
 // lt51-error@+1 2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper'}}
 #pragma omp target map(present, present, tofrom: a)
 {}
+// ge52-omp-error@+5 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
+// ge52-omp-error@+4 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present', 'iterator'}}
 // ompx-error@+3 {{same map type modifier has been specified more than once}}
 // ge51-omp-error@+2 2 {{incorrect map type modifier, expected one of: 'always', 'close', 'mapper', 'present'}}
 // lt51-omp-error@+1 2 

[PATCH] D140179: [WIP][-Wunsafe-buffer-usage] Add unsafe buffer checking opt-out pragmas

2023-01-19 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added inline comments.



Comment at: clang/include/clang/Basic/Diagnostic.h:1040-1043
+  // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in one
+  // translation unit. Each region is represented by a pair of start and end
+  // locations.
+  SmallVector, 8> 
SafeBufferOptOutMap;

NoQ wrote:
> Ok, now I no longer see why this data should live in DiagnosticEngine. It's 
> mostly about analysis, right? The pragma simply makes our analysis produce 
> different results, regardless of whether these results are used for producing 
> diagnostics or something else. Maybe let's keep it all in Preprocessor?
make sense to me!



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:543
 #define GADGET(x)  
\
-x ## Gadget::matcher().bind(#x),
+allOf(x ## Gadget::matcher().bind(#x), notInSafeBufferOptOut()),
 #include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def"

NoQ wrote:
> This prevents safe fixable gadgets from being found in the opt-out zone. I 
> think this clause should only apply to warning gadgets.
You are right!  Fixables should be found regardless of whether they are in an 
opt-out zone.  A Fixable could later be immediately discarded once we know that 
the variable declaration associated to the Fixable is in an opt-out zone.



Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:551-555
+allOf(declStmt().bind("any_ds"), notInSafeBufferOptOut())
+// We match all DREs regardless of whether they are in safe-buffer
+// opt-out region. Because an unclaimed DRE 'd', regardless of where 
it is,
+// should prevent a Fixable associated to the same variable as 'd'
+// from being emitting.

NoQ wrote:
> I think we should match all DeclStmts as well, because otherwise we may be 
> unable to find the variable to fix.
In case we are unable to find the variable to fix,  it means that the variable 
declaration is in an opt-out zone.  So we don't fix the variable anyway, right?

Or do you mean that a variable may still get fixed even if its declaration is 
in an opt-out zone?   I could imagine it is possible if the variable is 
involved in some assignments that we want to fix.


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

https://reviews.llvm.org/D140179

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


[PATCH] D136651: [Clang] Give Clang the ability to use a shared stat cache

2023-01-19 Thread Frederic Riss via Phabricator via cfe-commits
friss added a comment.

In D136651#4067012 , @glandium wrote:

> Oh yes, we're using `-DLLVM_LINK_LLVM_DYLIB=ON` too, so that would be the 
> main trigger.

This was indeed the main trigger. Thanks for the help narrowing this down. I 
reverted for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


[clang] cf12709 - Revert "[Clang] Give Clang the ability to use a shared stat cache"

2023-01-19 Thread Fred Riss via cfe-commits

Author: Fred Riss
Date: 2023-01-19T14:07:34-08:00
New Revision: cf12709222a4699ff5a4bb257cb891b55b5f6fba

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

LOG: Revert "[Clang] Give Clang the ability to use a shared stat cache"

This reverts commit c5abe893120b115907376359a5809229a9f9608a.
This reverts commit a033dbbe5c43247b60869b008e67ed86ed230eaa.

This broke the build with -DLLVM_LINK_LLVM_DYLIB=ON. Reverting while I
investigate.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/CompilerInvocation.h
clang/include/clang/Lex/HeaderSearchOptions.h
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CMakeLists.txt
clang/tools/CMakeLists.txt
llvm/lib/Support/CMakeLists.txt
llvm/unittests/Support/VirtualFileSystemTest.cpp

Removed: 
clang/test/Driver/vfsstatcache.c
clang/test/clang-stat-cache/cache-effects.c
clang/test/clang-stat-cache/errors.test
clang/tools/clang-stat-cache/CMakeLists.txt
clang/tools/clang-stat-cache/clang-stat-cache.cpp
llvm/include/llvm/Support/StatCacheFileSystem.h
llvm/lib/Support/StatCacheFileSystem.cpp



diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index e106858688ac7..d0f672ae5a1bd 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -256,11 +256,6 @@ def err_test_module_file_extension_version : Error<
   "test module file extension '%0' has 
diff erent version (%1.%2) than expected "
   "(%3.%4)">;
 
-def err_missing_vfs_stat_cache_file : Error<
-  "stat cache file '%0' not found">, DefaultFatal;
-def err_invalid_vfs_stat_cache : Error<
-  "invalid stat cache file '%0'">, DefaultFatal;
-
 def err_missing_vfs_overlay_file : Error<
   "virtual filesystem overlay file '%0' not found">, DefaultFatal;
 def err_invalid_vfs_overlay : Error<

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9334e6319d57b..ba49b335cf287 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3357,8 +3357,6 @@ def iwithsysroot : JoinedOrSeparate<["-"], 
"iwithsysroot">, Group
   HelpText<"Add directory to SYSTEM include search path, "
"absolute paths are relative to -isysroot">, 
MetaVarName<"">,
   Flags<[CC1Option]>;
-def ivfsstatcache : JoinedOrSeparate<["-"], "ivfsstatcache">, 
Group, Flags<[CC1Option]>,
-  HelpText<"Use the stat data cached in file instead of doing filesystem 
syscalls. See clang-stat-cache utility.">;
 def ivfsoverlay : JoinedOrSeparate<["-"], "ivfsoverlay">, 
Group, Flags<[CC1Option]>,
   HelpText<"Overlay the virtual filesystem described by file over the real 
file system">;
 def imultilib : Separate<["-"], "imultilib">, Group;

diff  --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index 9cc6aa5c4d8a1..254f048ed3c7e 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -296,7 +296,6 @@ IntrusiveRefCntPtr 
createVFSFromCompilerInvocation(
 
 IntrusiveRefCntPtr
 createVFSFromOverlayFiles(ArrayRef VFSOverlayFiles,
-  ArrayRef VFSStatCacheFiles,
   DiagnosticsEngine ,
   IntrusiveRefCntPtr BaseFS);
 

diff  --git a/clang/include/clang/Lex/HeaderSearchOptions.h 
b/clang/include/clang/Lex/HeaderSearchOptions.h
index 548f7d4493de4..6436a9b3bde20 100644
--- a/clang/include/clang/Lex/HeaderSearchOptions.h
+++ b/clang/include/clang/Lex/HeaderSearchOptions.h
@@ -181,9 +181,6 @@ class HeaderSearchOptions {
   /// of computing the module hash.
   llvm::SmallSetVector ModulesIgnoreMacros;
 
-  /// The set of user-provided stat cache files.
-  std::vector VFSStatCacheFiles;
-
   /// The set of user-provided virtual filesystem overlay files.
   std::vector VFSOverlayFiles;
 
@@ -253,10 +250,6 @@ class HeaderSearchOptions {
 SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
   }
 
-  void AddVFSStatCacheFile(StringRef Name) {
-VFSStatCacheFiles.push_back(std::string(Name));
-  }
-
   void AddVFSOverlayFile(StringRef Name) {
 VFSOverlayFiles.push_back(std::string(Name));
   }

diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index dbf55d95746e9..3b4f25182ac95 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -574,7 +574,7 @@ class ASTInfoCollector : public ASTReaderListener {
 // performs the initialization too late (once both target and language
 

[PATCH] D71734: [ODRHash] Hash `RecordDecl` and diagnose discovered mismatches.

2023-01-19 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
vsapsai marked an inline comment as done.
Closed by commit rG160bc160b9b1: [ODRHash] Hash `RecordDecl` and diagnose 
discovered mismatches. (authored by vsapsai).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71734

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/ODRDiagsEmitter.h
  clang/include/clang/AST/ODRHash.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ODRDiagsEmitter.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/compare-record.c

Index: clang/test/Modules/compare-record.c
===
--- /dev/null
+++ clang/test/Modules/compare-record.c
@@ -0,0 +1,418 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// Build first header file
+// RUN: echo "#define FIRST" >> %t/include/first.h
+// RUN: cat %t/test.c>> %t/include/first.h
+// RUN: echo "#undef FIRST"  >> %t/include/first.h
+
+// Build second header file
+// RUN: echo "#define SECOND" >> %t/include/second.h
+// RUN: cat %t/test.c >> %t/include/second.h
+// RUN: echo "#undef SECOND"  >> %t/include/second.h
+
+// Test that each header can compile
+// RUN: %clang_cc1 -fsyntax-only -x objective-c %t/include/first.h -fblocks -fobjc-arc
+// RUN: %clang_cc1 -fsyntax-only -x objective-c %t/include/second.h -fblocks -fobjc-arc
+
+// Run test
+// RUN: %clang_cc1 -I%t/include -verify %t/test.c -fblocks -fobjc-arc \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+
+// Run tests for nested structs
+// DEFINE: %{filename} = test-nested-struct.c
+// DEFINE: %{macro_flag} = -DCASE1=1
+// DEFINE: %{command} = %clang_cc1 -I%t/include -verify %t/%{filename} -fblocks -fobjc-arc \
+// DEFINE: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache \
+// DEFINE: %{macro_flag} -emit-llvm -o %t/%{filename}.bc
+// RUN: %{command}
+// REDEFINE: %{macro_flag} = -DCASE2=1
+// RUN: %{command}
+// REDEFINE: %{macro_flag} = -DCASE3=1
+// RUN: %{command}
+
+// Test that we don't accept different structs and unions with the same name
+// from multiple modules but detect mismatches and provide actionable
+// diagnostic.
+
+//--- include/first-empty.h
+//--- include/module.modulemap
+module First {
+  module Empty {
+header "first-empty.h"
+  }
+  module Hidden {
+header "first.h"
+header "first-nested-struct.h"
+export *
+  }
+}
+module Second {
+  header "second.h"
+  header "second-nested-struct.h"
+  export *
+}
+
+//--- test.c
+#if !defined(FIRST) && !defined(SECOND)
+# include "first-empty.h"
+# include "second.h"
+#endif
+
+#if defined(FIRST)
+struct CompareForwardDeclaration1;
+struct CompareForwardDeclaration2 {};
+#elif defined(SECOND)
+struct CompareForwardDeclaration1 {};
+struct CompareForwardDeclaration2;
+#else
+struct CompareForwardDeclaration1 *compareForwardDeclaration1;
+struct CompareForwardDeclaration2 *compareForwardDeclaration2;
+#endif
+
+#if defined(FIRST)
+struct CompareMatchingFields {
+  int matchingFieldName;
+};
+
+struct CompareFieldPresence1 {
+  int fieldPresence1;
+};
+struct CompareFieldPresence2 {};
+
+struct CompareFieldName {
+  int fieldNameA;
+};
+
+struct CompareFieldOrder {
+  int fieldOrderX;
+  int fieldOrderY;
+};
+#elif defined(SECOND)
+struct CompareMatchingFields {
+  int matchingFieldName;
+};
+
+struct CompareFieldPresence1 {
+};
+struct CompareFieldPresence2 {
+  int fieldPresence2;
+};
+
+struct CompareFieldName {
+  int fieldNameB;
+};
+
+struct CompareFieldOrder {
+  int fieldOrderY;
+  int fieldOrderX;
+};
+#else
+struct CompareMatchingFields compareMatchingFields;
+struct CompareFieldPresence1 compareFieldPresence1;
+// expected-error@first.h:* {{'CompareFieldPresence1' has different definitions in different modules; first difference is definition in module 'First.Hidden' found field}}
+// expected-note@second.h:* {{but in 'Second' found end of class}}
+struct CompareFieldPresence2 compareFieldPresence2;
+// expected-error@second.h:* {{'CompareFieldPresence2::fieldPresence2' from module 'Second' is not present in definition of 'struct CompareFieldPresence2' in module 'First.Hidden'}}
+// expected-note@first.h:* {{definition has no member 'fieldPresence2'}}
+struct CompareFieldName compareFieldName;
+// expected-error@second.h:* {{'CompareFieldName::fieldNameB' from module 'Second' is not present in definition of 'struct CompareFieldName' in module 'First.Hidden'}}
+// expected-note@first.h:* {{definition has no member 'fieldNameB'}}
+struct CompareFieldOrder compareFieldOrder;
+// 

[PATCH] D140055: [ODRHash] Detect mismatches in anonymous `RecordDecl`.

2023-01-19 Thread Volodymyr Sapsai 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 rGf33b5b1bf703: [ODRHash] Detect mismatches in anonymous 
`RecordDecl`. (authored by vsapsai).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140055

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Modules/compare-record.c

Index: clang/test/Modules/compare-record.c
===
--- clang/test/Modules/compare-record.c
+++ clang/test/Modules/compare-record.c
@@ -31,6 +31,15 @@
 // REDEFINE: %{macro_flag} = -DCASE3=1
 // RUN: %{command}
 
+// Run tests for anonymous nested structs and unions
+// REDEFINE: %{filename} = test-anonymous.c
+// REDEFINE: %{macro_flag} = -DCASE1=1
+// RUN: %{command}
+// REDEFINE: %{macro_flag} = -DCASE2=1
+// RUN: %{command}
+// REDEFINE: %{macro_flag} = -DCASE3=1
+// RUN: %{command}
+
 // Test that we don't accept different structs and unions with the same name
 // from multiple modules but detect mismatches and provide actionable
 // diagnostic.
@@ -44,12 +53,14 @@
   module Hidden {
 header "first.h"
 header "first-nested-struct.h"
+header "first-anonymous.h"
 export *
   }
 }
 module Second {
   header "second.h"
   header "second-nested-struct.h"
+  header "second-anonymous.h"
   export *
 }
 
@@ -416,3 +427,71 @@
 // expected-error@second-nested-struct.h:* {{'IndirectStruct::mismatchingField' from module 'Second' is not present in definition of 'struct IndirectStruct' in module 'First.Hidden'}}
 // expected-note@first-nested-struct.h:* {{declaration of 'mismatchingField' does not match}}
 #endif
+
+//--- include/first-anonymous.h
+struct CompareAnonymousNestedUnion {
+  union {
+int anonymousNestedUnionField;
+  };
+};
+
+struct CompareAnonymousNestedStruct {
+  struct {
+int anonymousNestedStructField;
+  };
+};
+
+struct CompareDeeplyNestedAnonymousUnionsAndStructs {
+  union {
+int x;
+union {
+  int y;
+  struct {
+int z;
+  };
+};
+  };
+};
+
+//--- include/second-anonymous.h
+struct CompareAnonymousNestedUnion {
+  union {
+float anonymousNestedUnionField;
+  };
+};
+
+struct CompareAnonymousNestedStruct {
+  struct {
+float anonymousNestedStructField;
+  };
+};
+
+struct CompareDeeplyNestedAnonymousUnionsAndStructs {
+  union {
+int x;
+union {
+  int y;
+  struct {
+float z;
+  };
+};
+  };
+};
+
+//--- test-anonymous.c
+#include "first-empty.h"
+#include "second-anonymous.h"
+
+#if defined(CASE1)
+struct CompareAnonymousNestedUnion compareAnonymousNestedUnion;
+// expected-error-re@second-anonymous.h:* {{'CompareAnonymousNestedUnion::(anonymous union)::anonymousNestedUnionField' from module 'Second' is not present in definition of 'union CompareAnonymousNestedUnion::(anonymous at {{.*}})' in module 'First.Hidden'}}
+// expected-note@first-anonymous.h:* {{declaration of 'anonymousNestedUnionField' does not match}}
+#elif defined(CASE2)
+struct CompareAnonymousNestedStruct compareAnonymousNestedStruct;
+// expected-error-re@second-anonymous.h:* {{'CompareAnonymousNestedStruct::(anonymous struct)::anonymousNestedStructField' from module 'Second' is not present in definition of 'struct CompareAnonymousNestedStruct::(anonymous at {{.*}})' in module 'First.Hidden'}}
+// expected-note@first-anonymous.h:* {{declaration of 'anonymousNestedStructField' does not match}}
+#elif defined(CASE3)
+struct CompareDeeplyNestedAnonymousUnionsAndStructs compareDeeplyNested;
+// expected-error-re@second-anonymous.h:* {{'CompareDeeplyNestedAnonymousUnionsAndStructs::(anonymous union)::(anonymous union)::(anonymous struct)::z' from module 'Second' is not present in definition of 'struct CompareDeeplyNestedAnonymousUnionsAndStructs::(anonymous at {{.*}})' in module 'First.Hidden'}}
+// expected-note@first-anonymous.h:* {{declaration of 'z' does not match}}
+#endif
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -7301,7 +7301,7 @@
   //
   // FIXME: Merging a function definition should merge
   // all mergeable entities within it.
-  if (isa(DC)) {
+  if (isa(DC)) {
 if (DeclarationName Name = cast(D)->getDeclName()) {
   if (!getContext().getLangOpts().CPlusPlus &&
   isa(DC)) {
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -3280,6 +3280,8 @@
 
   if (D->hasExternalLexicalStorage() && !D->getDefinition())
 getExternalSource()->CompleteType(const_cast(D));
+  // Complete the redecl chain (if necessary).
+  (void)D->getMostRecentDecl();
 
   D 

[clang] f33b5b1 - [ODRHash] Detect mismatches in anonymous `RecordDecl`.

2023-01-19 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2023-01-19T15:58:31-06:00
New Revision: f33b5b1bf703ee5ff73126fefe2a9bcbd54db457

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

LOG: [ODRHash] Detect mismatches in anonymous `RecordDecl`.

Allow completing a redeclaration check for anonymous structs/unions
inside `RecordDecl`, so we deserialize and compare anonymous entities
from different modules.

Completing the redeclaration chain for `RecordDecl` in
`ASTContext::getASTRecordLayout` mimics the behavior in
`CXXRecordDecl::dataPtr`. Instead of completing the redeclaration chain
every time we request a definition, do that right before we need a
complete definition in `ASTContext::getASTRecordLayout`.

Such code is required only for anonymous `RecordDecl` because we
deserialize named decls when we look them up by name. But it doesn't
work for anonymous decls as they don't have a name. That's why need to
force deserialization of anonymous decls in a different way.

rdar://81864186

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

Added: 


Modified: 
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/Serialization/ASTReader.cpp
clang/test/Modules/compare-record.c

Removed: 




diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 52bd3f20221f4..da27f73ea94e2 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -3280,6 +3280,8 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const 
{
 
   if (D->hasExternalLexicalStorage() && !D->getDefinition())
 getExternalSource()->CompleteType(const_cast(D));
+  // Complete the redecl chain (if necessary).
+  (void)D->getMostRecentDecl();
 
   D = D->getDefinition();
   assert(D && "Cannot get layout of forward declarations!");

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 77f29f6be4063..88d548a45b37d 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -7301,7 +7301,7 @@ void ASTReader::CompleteRedeclChain(const Decl *D) {
   //
   // FIXME: Merging a function definition should merge
   // all mergeable entities within it.
-  if (isa(DC)) {
+  if (isa(DC)) {
 if (DeclarationName Name = cast(D)->getDeclName()) {
   if (!getContext().getLangOpts().CPlusPlus &&
   isa(DC)) {

diff  --git a/clang/test/Modules/compare-record.c 
b/clang/test/Modules/compare-record.c
index 23dbe8191a343..a07843341296d 100644
--- a/clang/test/Modules/compare-record.c
+++ b/clang/test/Modules/compare-record.c
@@ -31,6 +31,15 @@
 // REDEFINE: %{macro_flag} = -DCASE3=1
 // RUN: %{command}
 
+// Run tests for anonymous nested structs and unions
+// REDEFINE: %{filename} = test-anonymous.c
+// REDEFINE: %{macro_flag} = -DCASE1=1
+// RUN: %{command}
+// REDEFINE: %{macro_flag} = -DCASE2=1
+// RUN: %{command}
+// REDEFINE: %{macro_flag} = -DCASE3=1
+// RUN: %{command}
+
 // Test that we don't accept 
diff erent structs and unions with the same name
 // from multiple modules but detect mismatches and provide actionable
 // diagnostic.
@@ -44,12 +53,14 @@ module First {
   module Hidden {
 header "first.h"
 header "first-nested-struct.h"
+header "first-anonymous.h"
 export *
   }
 }
 module Second {
   header "second.h"
   header "second-nested-struct.h"
+  header "second-anonymous.h"
   export *
 }
 
@@ -416,3 +427,71 @@ struct CompareIndirectStructPointer 
compareIndirectStructPointer;
 // expected-error@second-nested-struct.h:* 
{{'IndirectStruct::mismatchingField' from module 'Second' is not present in 
definition of 'struct IndirectStruct' in module 'First.Hidden'}}
 // expected-note@first-nested-struct.h:* {{declaration of 'mismatchingField' 
does not match}}
 #endif
+
+//--- include/first-anonymous.h
+struct CompareAnonymousNestedUnion {
+  union {
+int anonymousNestedUnionField;
+  };
+};
+
+struct CompareAnonymousNestedStruct {
+  struct {
+int anonymousNestedStructField;
+  };
+};
+
+struct CompareDeeplyNestedAnonymousUnionsAndStructs {
+  union {
+int x;
+union {
+  int y;
+  struct {
+int z;
+  };
+};
+  };
+};
+
+//--- include/second-anonymous.h
+struct CompareAnonymousNestedUnion {
+  union {
+float anonymousNestedUnionField;
+  };
+};
+
+struct CompareAnonymousNestedStruct {
+  struct {
+float anonymousNestedStructField;
+  };
+};
+
+struct CompareDeeplyNestedAnonymousUnionsAndStructs {
+  union {
+int x;
+union {
+  int y;
+  struct {
+float z;
+  };
+};
+  };
+};
+
+//--- test-anonymous.c
+#include "first-empty.h"
+#include "second-anonymous.h"
+
+#if defined(CASE1)
+struct CompareAnonymousNestedUnion compareAnonymousNestedUnion;
+// 

[clang] 160bc16 - [ODRHash] Hash `RecordDecl` and diagnose discovered mismatches.

2023-01-19 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2023-01-19T15:57:48-06:00
New Revision: 160bc160b9b114069a8cb9b4cc887aa86e5ca7c4

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

LOG: [ODRHash] Hash `RecordDecl` and diagnose discovered mismatches.

When two modules contain struct/union with the same name, check the
definitions are equivalent and diagnose if they are not. This is similar
to `CXXRecordDecl` where we already discover and diagnose mismatches.

rdar://problem/56764293

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

Added: 
clang/test/Modules/compare-record.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/ODRDiagsEmitter.h
clang/include/clang/AST/ODRHash.h
clang/include/clang/Serialization/ASTReader.h
clang/lib/AST/Decl.cpp
clang/lib/AST/ODRDiagsEmitter.cpp
clang/lib/AST/ODRHash.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 541f8e1eb671d..9f9fdc5a97a79 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -192,6 +192,10 @@ code bases.
   these definitions were allowed.  Note that such definitions are ODR
   violations if the header is included more than once.
 
+- Clang now diagnoses if structs/unions with the same name are 
diff erent in
+  
diff erent used modules. Behavior in C and Objective-C language modes now is
+  the same as in C++.
+
 What's New in Clang |release|?
 ==
 Some of the major new features and improvements to Clang are listed

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7322d4bcbc7f3..863f6ac57f2aa 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3998,6 +3998,7 @@ class RecordDecl : public TagDecl {
   // to save some space. Use the provided accessors to access it.
 public:
   friend class DeclContext;
+  friend class ASTDeclReader;
   /// Enum that represents the 
diff erent ways arguments are passed to and
   /// returned from function calls. This takes into account the target-specific
   /// and version-specific rules along with the rules determined by the
@@ -4253,9 +4254,16 @@ class RecordDecl : public TagDecl {
   /// nullptr is returned if no named data member exists.
   const FieldDecl *findFirstNamedDataMember() const;
 
+  /// Get precomputed ODRHash or add a new one.
+  unsigned getODRHash();
+
 private:
   /// Deserialize just the fields.
   void LoadFieldsFromExternalStorage() const;
+
+  /// True if a valid hash is stored in ODRHash.
+  bool hasODRHash() const { return RecordDeclBits.ODRHash; }
+  void setODRHash(unsigned Hash) { RecordDeclBits.ODRHash = Hash; }
 };
 
 class FileScopeAsmDecl : public Decl {

diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 8a5f75573095b..6134fdde8a2c9 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1577,10 +1577,14 @@ class DeclContext {
 
 /// Indicates whether this struct has had its field layout randomized.
 uint64_t IsRandomized : 1;
+
+/// True if a valid hash is stored in ODRHash. This should shave off some
+/// extra storage and prevent CXXRecordDecl to store unused bits.
+uint64_t ODRHash : 26;
   };
 
   /// Number of non-inherited bits in RecordDeclBitfields.
-  enum { NumRecordDeclBits = 15 };
+  enum { NumRecordDeclBits = 41 };
 
   /// Stores the bits used by OMPDeclareReductionDecl.
   /// If modified NumOMPDeclareReductionDeclBits and the accessor

diff  --git a/clang/include/clang/AST/ODRDiagsEmitter.h 
b/clang/include/clang/AST/ODRDiagsEmitter.h
index d3b7f5e6b4109..00a681b78a5eb 100644
--- a/clang/include/clang/AST/ODRDiagsEmitter.h
+++ b/clang/include/clang/AST/ODRDiagsEmitter.h
@@ -45,6 +45,12 @@ class ODRDiagsEmitter {
const CXXRecordDecl *SecondRecord,
const struct CXXRecordDecl::DefinitionData *SecondDD) const;
 
+  /// Diagnose ODR mismatch between 2 RecordDecl that are not CXXRecordDecl.
+  ///
+  /// Returns true if found a mismatch and diagnosed it.
+  bool diagnoseMismatch(const RecordDecl *FirstRecord,
+const RecordDecl *SecondRecord) const;
+
   /// Diagnose ODR mismatch between 2 ObjCProtocolDecl.
   ///
   /// Returns true if found a mismatch and diagnosed it.

diff  --git a/clang/include/clang/AST/ODRHash.h 
b/clang/include/clang/AST/ODRHash.h
index 1ab20013a3670..a489bb73deb67 100644
--- a/clang/include/clang/AST/ODRHash.h
+++ b/clang/include/clang/AST/ODRHash.h
@@ -55,6 +55,10 @@ 

[PATCH] D136651: [Clang] Give Clang the ability to use a shared stat cache

2023-01-19 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

Oh yes, we're using `-DLLVM_LINK_LLVM_DYLIB=ON` too, so that would be the main 
trigger.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


[PATCH] D139737: [-Wunsafe-buffer-usage] Initiate Fix-it generation for local variable declarations

2023-01-19 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 490648.
ziqingluo-90 added a comment.

Rebased the code w.r.t. a series of refactoring in [-Wunsafe-buffer-usage].
Added a `FixableGadget` for array subscripts of the form `DRE[*]` in the 
context of lvalue-to-rvalue casting.

Also did a refactoring at the place where matchers are applied:  Matchers of a 
`FixableGadget` and  of a `WarningGadget` cat match for the same AST node.  So 
they should not be put in an `anyOf` group, otherwise they can disable each 
other due to short-circuiting.


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

https://reviews.llvm.org/D139737

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
@@ -0,0 +1,86 @@
+// RUN: cp %s %t.cpp
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fixit %t.cpp
+// RUN: grep -v CHECK %t.cpp | FileCheck %s
+typedef int * Int_ptr_t;
+typedef int Int_t;
+
+void local_array_subscript_simple() {
+  int tmp;
+// CHECK: std::span p{new int [10], 10};
+// CHECK: std::span q{new int [10], 10};
+// CHECK: tmp = p[5];
+// CHECK: tmp = q[5];
+  int *p = new int[10];
+  const int *q = new int[10];
+  tmp = p[5];
+  tmp = q[5];
+
+// CHECK: std::span x{new int [10], 10};
+// CHECK: std::span y{new int, 1};
+// CHECK: std::span z{new int [10], 10};
+// CHECK: std::span w{new Int_t [10], 10};
+
+  Int_ptr_t x = new int[10];
+  Int_ptr_t y = new int;
+  Int_t * z = new int[10];
+  Int_t * w = new Int_t[10];
+
+  // CHECK: tmp = x[5];
+  tmp = x[5];
+  // CHECK: tmp = y[5];
+  tmp = y[5]; // y[5] will crash after being span
+  // CHECK: tmp = z[5];
+  tmp = z[5];
+  // CHECK: tmp = w[5];
+  tmp = w[5];
+}
+
+void local_array_subscript_auto() {
+  int tmp;
+// CHECK: std::span p{new int [10], 10};
+// CHECK: tmp = p[5];
+  auto p = new int[10];
+  tmp = p[5];
+}
+
+void local_array_subscript_variable_extent() {
+  int n = 10;
+  int tmp;
+  //FIXME: need to think it twice about side effects in the expressions
+  //used to initialize span objects
+  // CHECK: std::span p{new int [n], n};
+  // CHECK: std::span q{new int [n++], <# placeholder #>};
+  // CHECK: tmp = p[5];
+  // CHECK: tmp = q[5];
+  int *p = new int[n];
+  // If the extent expression does not have a constant value, we cannot fill the extent for users...
+  int *q = new int[n++];
+  tmp = p[5];
+  tmp = q[5];
+}
+
+
+void local_ptr_to_array() {
+  int tmp;
+  int n = 10;
+  int a[10];
+  int b[n];  // If the extent expression does not have a constant value, we cannot fill the extent for users...
+  // CHECK: std::span p{a, 10};
+  // CHECK: std::span q{b, <# placeholder #>};
+  // CHECK: tmp = p[5];
+  // CHECK: tmp = q[5];
+  int *p = a;
+  int *q = b;
+  tmp = p[5];
+  tmp = q[5];
+}
+
+void local_ptr_addrof_init() {
+  int var;
+// CHECK: std::span q{, 1};
+// CHECK: var = q[5];
+  int * q = 
+  // This expression involves unsafe buffer accesses, which will crash
+  // at runtime after applying the fix-it,
+  var = q[5];
+}
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -115,6 +115,21 @@
   MatchDescendantVisitor Visitor(, Finder, Builder, ASTMatchFinder::BK_All);  
   return Visitor.findMatch(DynTypedNode::create(Node));
 }
+
+AST_MATCHER_P(CastExpr, castSubExpr, internal::Matcher, innerMatcher) {
+  return innerMatcher.matches(*Node.getSubExpr(), Finder, Builder);
+}
+
+// Returns a matcher that matches any expression 'e' such that `innerMatcher`
+// matches 'e' and 'e' is in an Unspecified Lvalue Context.
+static auto isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) {
+  auto isLvalueToRvalueCast = [](internal::Matcher M) {
+return implicitCastExpr(hasCastKind(CastKind::CK_LValueToRValue),
+castSubExpr(M));
+  };
+  //FIXME: add assignmentTo context...
+  return isLvalueToRvalueCast(innerMatcher);
+}
 } // namespace clang::ast_matchers
 
 namespace {
@@ -282,7 +297,7 @@
 /// Array subscript expressions on raw pointers as if they're arrays. Unsafe as
 /// it doesn't have any bounds checks for the array.
 class ArraySubscriptGadget : public WarningGadget {
-  static constexpr const char *const ArraySubscrTag = "arraySubscr";
+  static constexpr const char *const ArraySubscrTag = "ArraySubscript";
   const ArraySubscriptExpr *ASE;
 
 public:
@@ -366,6 +381,51 @@
   // FIXME: pointer adding zero should be fine
   //FIXME: this gadge will need a fix-it
 };
+
+class Strategy;
+
+// Represents expressions of 

[PATCH] D136651: [Clang] Give Clang the ability to use a shared stat cache

2023-01-19 Thread Frederic Riss via Phabricator via cfe-commits
friss added a comment.

In D136651#4066960 , @mstorsjo wrote:

> In D136651#4066949 , @friss wrote:
>
>> Thanks for the report, unfortunately I have no way of testing this setup.
>
> Can you try a build with `-DLLVM_LINK_LLVM_DYLIB=ON`?

Trying. If that's indeed the issue (and not the cross-compile environment), 
I'll revert while looking at it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


[PATCH] D140663: CUDA/HIP: Use kernel name to map to symbol

2023-01-19 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140663

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


[PATCH] D140663: CUDA/HIP: Use kernel name to map to symbol

2023-01-19 Thread Daniele Castagna via Phabricator via cfe-commits
dcastagna updated this revision to Diff 490644.
dcastagna added a comment.

Add a check for device side kernel name


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140663

Files:
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/test/CodeGenCUDA/incomplete-func-ptr-type.cu

Index: clang/test/CodeGenCUDA/incomplete-func-ptr-type.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/incomplete-func-ptr-type.cu
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -x hip %s -o - \
+// RUN: | FileCheck %s
+
+#define __global__ __attribute__((global))
+// CHECK: @_Z4kern7TempValIjE = constant ptr @_Z19__device_stub__kern7TempValIjE, align 8
+// CHECK: @0 = private unnamed_addr constant [19 x i8] c"_Z4kern7TempValIjE\00", align 1
+template 
+struct TempVal {
+  type value;
+};
+
+__global__ void kern(TempVal in_val);
+
+int main(int argc, char ** argv) {
+  auto* fptr = &(kern);
+// CHECK:   store ptr @_Z4kern7TempValIjE, ptr %fptr, align 8
+  return 0;
+}
+// CHECK:  define dso_local void @_Z19__device_stub__kern7TempValIjE(i32 %in_val.coerce) #1 {
+// CHECK:  %2 = call i32 @hipLaunchByPtr(ptr @_Z4kern7TempValIjE)
+
+// CHECK:  define internal void @__hip_register_globals(ptr %0) {
+// CHECK:%1 = call i32 @__hipRegisterFunction(ptr %0, ptr @_Z4kern7TempValIjE, ptr @0, ptr @0, i32 -1, ptr null, ptr null, ptr null, ptr null, ptr null)
+
+__global__ void kern(TempVal in_val) {
+}
+
Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -49,10 +49,10 @@
 const Decl *D;
   };
   llvm::SmallVector EmittedKernels;
-  // Map a device stub function to a symbol for identifying kernel in host code.
+  // Map a kernel mangled name to a symbol for identifying kernel in host code
   // For CUDA, the symbol for identifying the kernel is the same as the device
   // stub function. For HIP, they are different.
-  llvm::DenseMap KernelHandles;
+  llvm::DenseMap KernelHandles;
   // Map a kernel handle to the kernel stub.
   llvm::DenseMap KernelStubs;
   struct VarInfo {
@@ -310,7 +310,8 @@
 void CGNVCUDARuntime::emitDeviceStub(CodeGenFunction ,
  FunctionArgList ) {
   EmittedKernels.push_back({CGF.CurFn, CGF.CurFuncDecl});
-  if (auto *GV = dyn_cast(KernelHandles[CGF.CurFn])) {
+  if (auto *GV =
+  dyn_cast(KernelHandles[CGF.CurFn->getName()])) {
 GV->setLinkage(CGF.CurFn->getLinkage());
 GV->setInitializer(CGF.CurFn);
   }
@@ -400,8 +401,8 @@
ShmemSize.getPointer(), Stream.getPointer()});
 
   // Emit the call to cudaLaunch
-  llvm::Value *Kernel =
-  CGF.Builder.CreatePointerCast(KernelHandles[CGF.CurFn], VoidPtrTy);
+  llvm::Value *Kernel = CGF.Builder.CreatePointerCast(
+  KernelHandles[CGF.CurFn->getName()], VoidPtrTy);
   CallArgList LaunchKernelArgs;
   LaunchKernelArgs.add(RValue::get(Kernel),
cudaLaunchKernelFD->getParamDecl(0)->getType());
@@ -456,8 +457,8 @@
 
   // Emit the call to cudaLaunch
   llvm::FunctionCallee cudaLaunchFn = getLaunchFn();
-  llvm::Value *Arg =
-  CGF.Builder.CreatePointerCast(KernelHandles[CGF.CurFn], CharPtrTy);
+  llvm::Value *Arg = CGF.Builder.CreatePointerCast(
+  KernelHandles[CGF.CurFn->getName()], CharPtrTy);
   CGF.EmitRuntimeCallOrInvoke(cudaLaunchFn, Arg);
   CGF.EmitBranch(EndBlock);
 
@@ -551,7 +552,7 @@
 llvm::Constant *NullPtr = llvm::ConstantPointerNull::get(VoidPtrTy);
 llvm::Value *Args[] = {
 ,
-Builder.CreateBitCast(KernelHandles[I.Kernel], VoidPtrTy),
+Builder.CreateBitCast(KernelHandles[I.Kernel->getName()], VoidPtrTy),
 KernelName,
 KernelName,
 llvm::ConstantInt::get(IntTy, -1),
@@ -1130,7 +1131,7 @@
   StringRef Section = CGM.getLangOpts().HIP ? "hip_offloading_entries"
 : "cuda_offloading_entries";
   for (KernelInfo  : EmittedKernels)
-OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel],
+OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel->getName()],
getDeviceSideName(cast(I.D)), 0,
DeviceVarFlags::OffloadGlobalEntry, Section);
 
@@ -1193,12 +1194,12 @@
 
 llvm::GlobalValue *CGNVCUDARuntime::getKernelHandle(llvm::Function *F,
 GlobalDecl GD) {
-  auto Loc = KernelHandles.find(F);
+  auto Loc = KernelHandles.find(F->getName());
   if (Loc != KernelHandles.end())
 return Loc->second;
 
   if (!CGM.getLangOpts().HIP) {
-KernelHandles[F] = F;
+KernelHandles[F->getName()] = F;
 KernelStubs[F] = F;
 return F;
   }
@@ -1212,7 +1213,7 @@
   Var->setDSOLocal(F->isDSOLocal());
   

[clang] 31b0be4 - [Clang] Add lifetimebound attribute to std::move/std::forward

2023-01-19 Thread Alexander Shaposhnikov via cfe-commits

Author: Alexander Shaposhnikov
Date: 2023-01-19T20:57:24Z
New Revision: 31b0be4eba9e8e9244799f0ebcb18175faff69ab

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

LOG: [Clang] Add lifetimebound attribute to std::move/std::forward

Clang now automatically adds [[clang::lifetimebound]] to the parameters of
std::move, std::forward et al, this enables Clang to diagnose more cases
where the returned reference outlives the object.
Associated GitHub issue: https://github.com/llvm/llvm-project/issues/60020

Test plan: ninja check-clang check-all

Differential revision: https://reviews.llvm.org/D141744

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/attr-lifetimebound.cpp
clang/test/SemaCXX/builtin-std-move.cpp
clang/test/SemaCXX/builtins.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index dbec1cd7c196..2e99a6072a94 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2933,7 +2933,8 @@ implementation details of ``__sync_lock_test_and_set()``. 
 The
 ``__builtin_addressof`` performs the functionality of the built-in ``&``
 operator, ignoring any ``operator&`` overload.  This is useful in constant
 expressions in C++11, where there is no other way to take the address of an
-object that overloads ``operator&``.
+object that overloads ``operator&``. Clang automatically adds
+``[[clang::lifetimebound]]`` to the parameter of ``__builtin_addressof``.
 
 **Example of use**:
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 97ce8866d3cc..541f8e1eb671 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -458,6 +458,9 @@ Improvements to Clang's diagnostics
   only when ``x`` is a string literal.
 - Clang will now reject the GNU extension address of label in coroutines 
explicitly.
   This fixes `Issue 56436 
`_.
+- Clang now automatically adds ``[[clang::lifetimebound]]`` to the parameters 
of
+  ``std::move, std::forward`` et al, this enables Clang to diagnose more cases
+  where the returned reference outlives the object.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index faa75f671fde..3ae3e33a6704 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16182,6 +16182,24 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl 
*FD) {
 default:
   break;
 }
+
+// Add lifetime attribute to std::move, std::fowrard et al.
+switch (BuiltinID) {
+case Builtin::BIaddressof:
+case Builtin::BI__addressof:
+case Builtin::BI__builtin_addressof:
+case Builtin::BIas_const:
+case Builtin::BIforward:
+case Builtin::BImove:
+case Builtin::BImove_if_noexcept:
+  if (ParmVarDecl *P = FD->getParamDecl(0u);
+  !P->hasAttr())
+P->addAttr(
+LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation()));
+  break;
+default:
+  break;
+}
   }
 
   AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(FD);

diff  --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index 90124c323d02..22cf5d0ab001 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -113,3 +113,77 @@ namespace p0936r0_examples {
   std::map m;
   const std::string  = findOrDefault(m, "foo"s, "bar"s); // expected-warning 
{{temporary bound to local reference 'v'}}
 }
+
+// definitions for std::move, std::forward et al.
+namespace std {
+inline namespace foo {
+
+template  struct remove_reference {
+typedef T type;
+};
+template  struct remove_reference {
+typedef T type;
+};
+template  struct remove_reference {
+typedef T type;
+};
+
+template  constexpr typename remove_reference::type &(T &) {
+return static_cast::type>(t);
+}
+
+template 
+constexpr T &(typename remove_reference::type ) {
+return static_cast(t);
+}
+
+template 
+constexpr T &(typename remove_reference::type &) {
+return static_cast(t);
+}
+
+template  constexpr const T _const(T ) { return x; }
+
+template  struct PickRef {
+using type = typename remove_reference::type &;
+};
+template  struct PickRef {
+using type = typename remove_reference::type &&;
+};
+
+template 
+auto move_if_noexcept(T ) ->
+typename PickRef(t)))>::type {
+return static_cast<
+typename PickRef(t)))>::type>(t);
+}
+
+template  T *addressof(T ) {
+return reinterpret_cast(
+_cast(reinterpret_cast(arg)));
+}

[PATCH] D141744: [Clang] Add lifetimebound attribute to std::move/std::forward

2023-01-19 Thread Alexander Shaposhnikov 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 rG31b0be4eba9e: [Clang] Add lifetimebound attribute to 
std::move/std::forward (authored by alexander-shaposhnikov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141744

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/attr-lifetimebound.cpp
  clang/test/SemaCXX/builtin-std-move.cpp
  clang/test/SemaCXX/builtins.cpp

Index: clang/test/SemaCXX/builtins.cpp
===
--- clang/test/SemaCXX/builtins.cpp
+++ clang/test/SemaCXX/builtins.cpp
@@ -40,7 +40,7 @@
   struct U { int n : 5; } u;
   int *pbf = __builtin_addressof(u.n); // expected-error {{address of bit-field requested}}
 
-  S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address of a temporary}}
+  S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address of a temporary}} expected-warning {{temporary whose address is used as value of local variable 'ptmp' will be destroyed at the end of the full-expression}}
 }
 
 namespace function_start {
Index: clang/test/SemaCXX/builtin-std-move.cpp
===
--- clang/test/SemaCXX/builtin-std-move.cpp
+++ clang/test/SemaCXX/builtin-std-move.cpp
@@ -85,7 +85,7 @@
 
 A _rval_as_lval() {
   std::forward(A()); // expected-warning {{const attribute}}
-  return std::forward(A()); // expected-note {{instantiation of}}
+  return std::forward(A()); // expected-note {{instantiation of}} expected-warning {{returning reference}}
 }
 
 struct B {};
Index: clang/test/SemaCXX/attr-lifetimebound.cpp
===
--- clang/test/SemaCXX/attr-lifetimebound.cpp
+++ clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -113,3 +113,77 @@
   std::map m;
   const std::string  = findOrDefault(m, "foo"s, "bar"s); // expected-warning {{temporary bound to local reference 'v'}}
 }
+
+// definitions for std::move, std::forward et al.
+namespace std {
+inline namespace foo {
+
+template  struct remove_reference {
+typedef T type;
+};
+template  struct remove_reference {
+typedef T type;
+};
+template  struct remove_reference {
+typedef T type;
+};
+
+template  constexpr typename remove_reference::type &(T &) {
+return static_cast::type>(t);
+}
+
+template 
+constexpr T &(typename remove_reference::type ) {
+return static_cast(t);
+}
+
+template 
+constexpr T &(typename remove_reference::type &) {
+return static_cast(t);
+}
+
+template  constexpr const T _const(T ) { return x; }
+
+template  struct PickRef {
+using type = typename remove_reference::type &;
+};
+template  struct PickRef {
+using type = typename remove_reference::type &&;
+};
+
+template 
+auto move_if_noexcept(T ) ->
+typename PickRef(t)))>::type {
+return static_cast<
+typename PickRef(t)))>::type>(t);
+}
+
+template  T *addressof(T ) {
+return reinterpret_cast(
+_cast(reinterpret_cast(arg)));
+}
+
+} // namespace foo
+} // namespace std
+
+namespace move_forward_et_al_examples {
+  struct S {
+S () [[clang::lifetimebound]] { return *this; }
+  };
+
+  S & = std::move(S{}); // expected-warning {{temporary bound to local reference 'Move' will be destroyed at the end of the full-expression}}
+  S MoveOk = std::move(S{});
+
+  S & = std::forward(S{}); // expected-warning {{temporary bound to local reference 'Forward' will be destroyed at the end of the full-expression}}
+  S ForwardOk = std::forward(S{});
+
+  const S  = std::as_const(S{}.self()); // expected-warning {{temporary bound to local reference 'Const' will be destroyed at the end of the full-expression}}
+  const S ConstOk = std::as_const(S{}.self());
+
+  S & = std::move_if_noexcept(S{}.self()); // expected-warning {{temporary bound to local reference 'MoveIfNoExcept' will be destroyed at the end of the full-expression}}
+  S MoveIfNoExceptOk = std::move_if_noexcept(S{}.self());
+
+  S *AddressOf = std::addressof(S{}.self()); // expected-warning {{temporary whose address is used as value of local variable 'AddressOf' will be destroyed at the end of the full-expression}}
+  S X;
+  S *AddressOfOk = std::addressof(X);
+} // namespace move_forward_et_al_examples
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16182,6 +16182,24 @@
 default:
   break;
 }
+
+// Add lifetime attribute to std::move, std::fowrard et al.
+switch (BuiltinID) {
+case Builtin::BIaddressof:
+case Builtin::BI__addressof:
+case Builtin::BI__builtin_addressof:
+case Builtin::BIas_const:
+case Builtin::BIforward:
+case 

[PATCH] D141625: [DeclContext] Sort the Decls before adding into DeclContext

2023-01-19 Thread Steven Wu via Phabricator via cfe-commits
steven_wu added a comment.

No, reverse iteration will not break diff test for a small number of decls. 
Everything will be in reverse order so it is the same. Current test will fail 
early in reverse iteration and will fail in the end statistically for forward 
iteration. Will pass in all configurations. I think paying a bit more decls to 
make it fail in forward iteration is not a bad trade off.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141625

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


[PATCH] D136651: [Clang] Give Clang the ability to use a shared stat cache

2023-01-19 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D136651#4066949 , @friss wrote:

> Thanks for the report, unfortunately I have no way of testing this setup.

Can you try a build with `-DLLVM_LINK_LLVM_DYLIB=ON`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


[PATCH] D136651: [Clang] Give Clang the ability to use a shared stat cache

2023-01-19 Thread Frederic Riss via Phabricator via cfe-commits
friss added a comment.

In D136651#4064474 , @glandium wrote:

> In D136651#4064260 , @glandium 
> wrote:
>
>> This broke our mac builds with errors like:
>>
>>   ld64.lld: error: undefined symbol: CFRunLoopRun
>>   >>> referenced by 
>> tools/clang/tools/clang-stat-cache/CMakeFiles/clang-stat-cache.dir/clang-stat-cache.cpp.o:(symbol
>>  main+0x11be)
>>
>> (and many more symbols)
>
> Additional information: those are cross-compiled, and for some reason the 
> `-framework CoreServices` in the CMakeLists.txt doesn't seem to make it to 
> the command line, which is surprising because something similar works fine 
> for e.g. dsymutil.

Thanks for the report, unfortunately I have no way of testing this setup. Any 
chance you can experiment on your side? DirectoryWatcher uses the came decency, 
I'm wondering why it's not an issue there. If it helps to revert the change 
while someone investigates, that's perfectly fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136651

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


[PATCH] D139395: Add CFI integer types normalization

2023-01-19 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added a comment.

Thanks for the patch, Ramon. This looks like a reasonable approach to me, and 
just for reference, here appears to be the corresponding rustc change:

https://github.com/rust-lang/rust/pull/105452/commits/9087c336103d0fa0b465acf8dbc1e4651250fb05

@pcc did you have any other concerns about adding this option?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139395

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


[PATCH] D140891: [analyzer] Fix assertion failure in SMT conversion for unary operator on floats.

2023-01-19 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho accepted this revision.
mikhail.ramalho 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/D140891/new/

https://reviews.llvm.org/D140891

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


[PATCH] D136315: [clang][Darwin] Try to guess the SDK root with xcrun when unspecified

2023-01-19 Thread Steven Wu via Phabricator via cfe-commits
steven_wu added a comment.

This breaks macOS bot too: 
https://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/33839/

I think this changes might be more disruptive than expected. While it is 
encouraged to use `-isysroot` when building anything on Darwin platform, it is 
also perfectly "fine" to build without sysroot specified. Forcing a sysroot on 
users who are not specifying the isysroot will change the header/library search 
behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136315

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


[PATCH] D141625: [DeclContext] Sort the Decls before adding into DeclContext

2023-01-19 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D141625#4066681 , @steven_wu wrote:

> In D141625#4066466 , @dblaikie 
> wrote:
>
>> In D141625#4066362 , @steven_wu 
>> wrote:
>>
>>> @dblaikie Do you have any objection for committing the patch as it is? I 
>>> don't think reverse iteration test is a proper way to test for this 
>>> specific bug.
>>
>> I think reverse iteration is the right way to test this specific bug (& any 
>> bug where behavior may be unintentionally nondeterministic due to 
>> non-deterministically ordered containers) - it makes the testing more 
>> reliable rather than depending on implementation details of such containers 
>> that aren't guaranteed (that being the point/problem).
>>
>> But it's not the worst/most unwieldy test for this sort of thing & if we 
>> don't have bots using it... hmm, actually I looked more closely & maybe we 
>> do have reverse iteration builders: 
>> https://github.com/llvm/llvm-zorg/search?q=reverse-iteration (though I'm 
>> having trouble navigating the builder UI to see whether there are up-to-date 
>> builds for this configuration)
>>
>> Could you help me understand your perspective regarding using reverse 
>> iteration to test this specific bug? (are there some bugs you find reverse 
>> iteration suitable for? what's different about this one from them?)
>
> With reverse iteration, you can make sure that the we didn't iterate over the 
> non-deterministic container by checking the ordering of the decls in the 
> module, which is fine.

I'm not sure I follow - does building LLVM with reverse iteration not break the 
integration/diff test you've written? I'd expect it would, and that it would 
fail a smaller test with only a couple of decls?

> But no one really runs that tests regularly.
> Without the reverse iteration, the ordering check will always succeed because 
> the anonymous decls will be numbered and ordered in the ascending order as 
> iteration. It is not easy to decode which decl is which by analyze the output 
> of llvm-bcanalyzer. Current test (which is not big at all) will put (80 - 32) 
> entries into hash table of smallptrset, thus it kind of triggers the bug near 
> 100% of the time. I would think the current test is more valuable than a test 
> only fail in reverse iteration.

Given stability issues are pretty rare/unstable to reproduce, I think a test 
that only fails in one of reverse or forward iteration mode is acceptable/a 
suitable way to test stability problems & I'm OK with/would personally prefer 
the test be reduced to only that, rather than having to add enough to cause the 
hashing to tip over into instability - that's why reverse iteration was added, 
to catch these sort of issues, including through intentional tests of features 
that would expose problems when combined with reverse iteration.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141625

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


[PATCH] D142001: [clang] Use FP options from AST for emitting code for casts

2023-01-19 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142001

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


[PATCH] D139774: [libclang] Add API to set temporary directory location

2023-01-19 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Don't let me hold this up - I think it all feels a bit too ad-hoc for my own 
preferences (feels like there should be fairly general solutions to this - 
rather than playing whack-a-mole on only the biggest temporary files - both in 
terms of the options KDevelop developers have considered/accepted/declined, and 
in terms of what's being proposed to be added to Clang), but I don't feel 
strongly enough about any of that to veto/push very hard here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139774

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


[PATCH] D141744: [Clang] Add lifetimebound attribute to std::move/std::forward

2023-01-19 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov updated this revision to Diff 490637.
alexander-shaposhnikov added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141744

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/attr-lifetimebound.cpp
  clang/test/SemaCXX/builtin-std-move.cpp
  clang/test/SemaCXX/builtins.cpp

Index: clang/test/SemaCXX/builtins.cpp
===
--- clang/test/SemaCXX/builtins.cpp
+++ clang/test/SemaCXX/builtins.cpp
@@ -40,7 +40,7 @@
   struct U { int n : 5; } u;
   int *pbf = __builtin_addressof(u.n); // expected-error {{address of bit-field requested}}
 
-  S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address of a temporary}}
+  S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address of a temporary}} expected-warning {{temporary whose address is used as value of local variable 'ptmp' will be destroyed at the end of the full-expression}}
 }
 
 namespace function_start {
Index: clang/test/SemaCXX/builtin-std-move.cpp
===
--- clang/test/SemaCXX/builtin-std-move.cpp
+++ clang/test/SemaCXX/builtin-std-move.cpp
@@ -85,7 +85,7 @@
 
 A _rval_as_lval() {
   std::forward(A()); // expected-warning {{const attribute}}
-  return std::forward(A()); // expected-note {{instantiation of}}
+  return std::forward(A()); // expected-note {{instantiation of}} expected-warning {{returning reference}}
 }
 
 struct B {};
Index: clang/test/SemaCXX/attr-lifetimebound.cpp
===
--- clang/test/SemaCXX/attr-lifetimebound.cpp
+++ clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -113,3 +113,77 @@
   std::map m;
   const std::string  = findOrDefault(m, "foo"s, "bar"s); // expected-warning {{temporary bound to local reference 'v'}}
 }
+
+// definitions for std::move, std::forward et al.
+namespace std {
+inline namespace foo {
+
+template  struct remove_reference {
+typedef T type;
+};
+template  struct remove_reference {
+typedef T type;
+};
+template  struct remove_reference {
+typedef T type;
+};
+
+template  constexpr typename remove_reference::type &(T &) {
+return static_cast::type>(t);
+}
+
+template 
+constexpr T &(typename remove_reference::type ) {
+return static_cast(t);
+}
+
+template 
+constexpr T &(typename remove_reference::type &) {
+return static_cast(t);
+}
+
+template  constexpr const T _const(T ) { return x; }
+
+template  struct PickRef {
+using type = typename remove_reference::type &;
+};
+template  struct PickRef {
+using type = typename remove_reference::type &&;
+};
+
+template 
+auto move_if_noexcept(T ) ->
+typename PickRef(t)))>::type {
+return static_cast<
+typename PickRef(t)))>::type>(t);
+}
+
+template  T *addressof(T ) {
+return reinterpret_cast(
+_cast(reinterpret_cast(arg)));
+}
+
+} // namespace foo
+} // namespace std
+
+namespace move_forward_et_al_examples {
+  struct S {
+S () [[clang::lifetimebound]] { return *this; }
+  };
+
+  S & = std::move(S{}); // expected-warning {{temporary bound to local reference 'Move' will be destroyed at the end of the full-expression}}
+  S MoveOk = std::move(S{});
+
+  S & = std::forward(S{}); // expected-warning {{temporary bound to local reference 'Forward' will be destroyed at the end of the full-expression}}
+  S ForwardOk = std::forward(S{});
+
+  const S  = std::as_const(S{}.self()); // expected-warning {{temporary bound to local reference 'Const' will be destroyed at the end of the full-expression}}
+  const S ConstOk = std::as_const(S{}.self());
+
+  S & = std::move_if_noexcept(S{}.self()); // expected-warning {{temporary bound to local reference 'MoveIfNoExcept' will be destroyed at the end of the full-expression}}
+  S MoveIfNoExceptOk = std::move_if_noexcept(S{}.self());
+
+  S *AddressOf = std::addressof(S{}.self()); // expected-warning {{temporary whose address is used as value of local variable 'AddressOf' will be destroyed at the end of the full-expression}}
+  S X;
+  S *AddressOfOk = std::addressof(X);
+} // namespace move_forward_et_al_examples
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16182,6 +16182,24 @@
 default:
   break;
 }
+
+// Add lifetime attribute to std::move, std::fowrard et al.
+switch (BuiltinID) {
+case Builtin::BIaddressof:
+case Builtin::BI__addressof:
+case Builtin::BI__builtin_addressof:
+case Builtin::BIas_const:
+case Builtin::BIforward:
+case Builtin::BImove:
+case Builtin::BImove_if_noexcept:
+  if (ParmVarDecl *P = FD->getParamDecl(0u);
+  !P->hasAttr())
+P->addAttr(

[PATCH] D137753: [Clang][AIX][p]Enable -p Functionality

2023-01-19 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 490638.
francii added a comment.

Specifically check for AIX before pushing pg


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137753

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aix-ld.c


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -135,6 +135,8 @@
 // CHECK-LD32-PROF-NOT: "--no-as-needed"
 // CHECK-LD32-PROF-NOT: "-lm"
 // CHECK-LD32-PROF: "-lc"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib/profiled"
 
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable profiling.
 // RUN: %clang %s -### 2>&1 \
@@ -162,6 +164,8 @@
 // CHECK-LD64-PROF-NOT: "--no-as-needed"
 // CHECK-LD64-PROF-NOT: "-lm"
 // CHECK-LD64-PROF: "-lc"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/usr/lib/profiled
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable g-profiling.
 // RUN: %clang %s -### 2>&1 \
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6260,6 +6260,8 @@
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }
+if (TC.getTriple().isOSAIX())
+  CmdArgs.push_back("-pg");
   }
 
   if (Args.getLastArg(options::OPT_fapple_kext) ||
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -252,7 +252,7 @@
 
 CmdArgs.push_back("-lc");
 
-if (Args.hasArg(options::OPT_pg)) {
+if (Args.hasArg(options::OPT_p, options::OPT_pg)) {
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
"/lib/profiled"));
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4136,6 +4136,7 @@
   MarshallingInfoFlag>;
 def pedantic : Flag<["-", "--"], "pedantic">, Group, 
Flags<[CC1Option,FlangOption,FC1Option]>,
   HelpText<"Warn on language extensions">, 
MarshallingInfoFlag>;
+def p : Flag<["-"], "p">, HelpText<"Enable mcount instrumentation with prof">, 
Flags<[CC1Option]>;
 def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, 
Flags<[CC1Option]>,
   MarshallingInfoFlag>;
 def pipe : Flag<["-", "--"], "pipe">,
@@ -4182,7 +4183,6 @@
   LangOpts<"POSIXThreads">, DefaultFalse,
   PosFlag,
   NegFlag, BothFlags<[CC1Option]>>;
-def p : Flag<["-"], "p">;
 def pie : Flag<["-"], "pie">, Group;
 def static_pie : Flag<["-"], "static-pie">, Group;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -135,6 +135,8 @@
 // CHECK-LD32-PROF-NOT: "--no-as-needed"
 // CHECK-LD32-PROF-NOT: "-lm"
 // CHECK-LD32-PROF: "-lc"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib/profiled"
 
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable profiling.
 // RUN: %clang %s -### 2>&1 \
@@ -162,6 +164,8 @@
 // CHECK-LD64-PROF-NOT: "--no-as-needed"
 // CHECK-LD64-PROF-NOT: "-lm"
 // CHECK-LD64-PROF: "-lc"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/usr/lib/profiled
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable g-profiling.
 // RUN: %clang %s -### 2>&1 \
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6260,6 +6260,8 @@
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }
+if (TC.getTriple().isOSAIX())
+  CmdArgs.push_back("-pg");
   }
 
   if (Args.getLastArg(options::OPT_fapple_kext) ||
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -252,7 +252,7 @@
 
 CmdArgs.push_back("-lc");
 
-if (Args.hasArg(options::OPT_pg)) {
+if (Args.hasArg(options::OPT_p, options::OPT_pg)) {
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
"/lib/profiled"));
   

[PATCH] D141324: [clang] extend external_source_symbol attribute with the USR clause

2023-01-19 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/utils/TableGen/ClangAttrEmitter.cpp:3318
+for (const auto  : Attr->getValueAsListOfDefs("Spellings")) {
+  if (Spelling->getValueAsString("Variety") == Variety ||
+  Spelling->getValueAsString("Variety") == "Clang") {

arphaman wrote:
> erichkeane wrote:
> > Why is this =="Clang" specific?  Since you've added the Version to the 
> > spelling, I'd anticipate us to just be able to grab it for the current 
> > spelling.  I wouldn't want an individual spelling here to override it, 
> > particularly since with this change Clang could potentially override the 
> > standards version.
> I needed it since there's no specific "Clang" variety that's being called for 
> this function. Otherwise the "GNU" variety passed to the function doesn't 
> match "Clang" variety in the record. What's the best way to compute the 
> current spelling in this case?
Hmm... that is strange.  I would have expected this to be called for each of 
the individual spellings, it doesn't really make sense that it wouldn't pick it 
up from the base 'Spellings'.  I've unfortunately not debugged this code 
generation in a while.  BUT, we care about the 'version' on a per-spelling 
basis, so it would presumably need to 'pick' an actual spelling.


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

https://reviews.llvm.org/D141324

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


[PATCH] D140663: CUDA/HIP: Use kernel name to map to symbol

2023-01-19 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/test/CodeGenCUDA/incomplete-func-ptr-type.cu:22
+// CHECK:  define internal void @__hip_register_globals(ptr %0) {
+// CHECK:%1 = call i32 @__hipRegisterFunction(ptr %0, ptr 
@_Z4kern7TempValIjE, ptr @0, ptr @0, i32 -1, ptr null, ptr null, ptr null, ptr 
null, ptr null)
+

pls also check @0, which is the device side kernel name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140663

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


[PATCH] D141324: [clang] extend external_source_symbol attribute with the USR clause

2023-01-19 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:962
+  let Spellings = [Clang<"external_source_symbol", /*allowInC=*/1,
+   /*version=*/2>];
   let Args = [StringArgument<"language", 1>,

erichkeane wrote:
> For standards version numbers, we tend to set this to a 'date' more or less, 
> so something like `20230119`.  I wonder if there is value to making THAT how 
> we do this here too?
That's a good idea, I can update it to be a specific date.



Comment at: clang/utils/TableGen/ClangAttrEmitter.cpp:3318
+for (const auto  : Attr->getValueAsListOfDefs("Spellings")) {
+  if (Spelling->getValueAsString("Variety") == Variety ||
+  Spelling->getValueAsString("Variety") == "Clang") {

erichkeane wrote:
> Why is this =="Clang" specific?  Since you've added the Version to the 
> spelling, I'd anticipate us to just be able to grab it for the current 
> spelling.  I wouldn't want an individual spelling here to override it, 
> particularly since with this change Clang could potentially override the 
> standards version.
I needed it since there's no specific "Clang" variety that's being called for 
this function. Otherwise the "GNU" variety passed to the function doesn't match 
"Clang" variety in the record. What's the best way to compute the current 
spelling in this case?


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

https://reviews.llvm.org/D141324

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


[PATCH] D142123: [clang-tidy] Add check to suggest use of #pragma once

2023-01-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D142123#4066805 , @KyleFromKitware 
wrote:

> The refactoring that I've done in D142121  
> is most of the way to being able to implement my above proposal. I just need 
> to shift a few things around and add the new classes. @aaron.ballman if this 
> proposal is good with you I'll get started on it.

I think this sounds like a sensible approach to me, but I'd like to make sure 
@njames93 agrees before you start doing any work on it.


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

https://reviews.llvm.org/D142123

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


[PATCH] D142143: [Lex] For dependency directive lexing, angled includes in `__has_include` should be lexed as string literals

2023-01-19 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi marked an inline comment as done.
akyrtzi added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:4415
+if (Result.isNot(tok::header_name))
+  return true;
+// Advance the index of lexed tokens.

benlangmuir wrote:
> This case is missing a test I think.
Added a test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142143

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


[PATCH] D142143: [Lex] For dependency directive lexing, angled includes in `__has_include` should be lexed as string literals

2023-01-19 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 490629.
akyrtzi added a comment.

Add test case for dependency directive lexing of ill-formed include inside 
`__has_include`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142143

Files:
  clang/lib/Lex/Lexer.cpp
  clang/test/ClangScanDeps/depscan-lex-has-include.c


Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+// CHECK: t.c
+// CHECK: something.h
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-error.json.template > %t/cdb-error.json
+// RUN: not clang-scan-deps -compilation-database %t/cdb-error.json 2>&1 | 
FileCheck %s -check-prefix=ERROR
+// ERROR: error: expected '>'
+// ERROR: error: expected value in expression
+
+//--- cdb.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/t.c -I DIR",
+"file": "DIR/t.c"
+  }
+]
+
+//--- cdb-error.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/error.c",
+"file": "DIR/error.c"
+  }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include()
+#include 
+#endif
+
+//--- something/something.h
+
+//--- error.c
+#if __has_include(= BufferPtr)
+break;
+  ++NextDepDirectiveTokenIndex;
+}
+return true;
+  }
+
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 
   if (Result.is(tok::hash) && Result.isAtStartOfLine()) {


Index: clang/test/ClangScanDeps/depscan-lex-has-include.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/depscan-lex-has-include.c
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json | FileCheck %s
+// CHECK: t.c
+// CHECK: something.h
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-error.json.template > %t/cdb-error.json
+// RUN: not clang-scan-deps -compilation-database %t/cdb-error.json 2>&1 | FileCheck %s -check-prefix=ERROR
+// ERROR: error: expected '>'
+// ERROR: error: expected value in expression
+
+//--- cdb.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/t.c -I DIR",
+"file": "DIR/t.c"
+  }
+]
+
+//--- cdb-error.json.template
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/error.c",
+"file": "DIR/error.c"
+  }
+]
+
+//--- t.c
+
+#define something
+
+// Make sure the include is lexed as a literal, ignoring the macro.
+#if __has_include()
+#include 
+#endif
+
+//--- something/something.h
+
+//--- error.c
+#if __has_include(= BufferPtr)
+break;
+  ++NextDepDirectiveTokenIndex;
+}
+return true;
+  }
+
   const char *TokPtr = convertDependencyDirectiveToken(DDTok, Result);
 
   if (Result.is(tok::hash) && Result.isAtStartOfLine()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142113: [clang][nfc] refactor Module::Header to use OptionalFileEntryRef

2023-01-19 Thread Richard Howell via Phabricator via cfe-commits
rmaz updated this revision to Diff 490624.
rmaz added a comment.

rebase on last successful build: 
https://buildkite.com/llvm-project/llvm-main/builds/6356


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142113

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Serialization/ASTReader.cpp

Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1947,7 +1947,7 @@
   Reader.ResolveImportedPath(M, Filename);
 // FIXME: NameAsWritten
 Module::Header H = {std::string(key.Filename), "",
-*FileMgr.getFile(Filename)};
+FileMgr.getOptionalFileRef(Filename)};
 ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true);
 HFI.isModuleHeader |= ModuleMap::isModular(HeaderRole);
   }
@@ -5661,7 +5661,7 @@
   //`Headers/`, so this path will never exist.
   std::string Filename = std::string(Blob);
   ResolveImportedPath(F, Filename);
-  if (auto Umbrella = PP.getFileManager().getFile(Filename)) {
+  if (auto Umbrella = PP.getFileManager().getOptionalFileRef(Filename)) {
 if (!CurrentModule->getUmbrellaHeader()) {
   // FIXME: NameAsWritten
   ModMap.setUmbrellaHeader(CurrentModule, *Umbrella, Blob, "");
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -120,12 +120,12 @@
   // TODO: Make the C++20 header lookup independent.
   // When the input is pre-processed source, we need a file ref to the original
   // file for the header map.
-  auto F = SourceMgr.getFileManager().getFile(HUName);
+  auto F = SourceMgr.getFileManager().getOptionalFileRef(HUName);
   // For the sake of error recovery (if someone has moved the original header
   // after creating the pre-processed output) fall back to obtaining the file
   // ref for the input file, which must be present.
   if (!F)
-F = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
+F = SourceMgr.getFileEntryRefForID(SourceMgr.getMainFileID());
   assert(F && "failed to find the header unit source?");
   Module::Header H{HUName.str(), HUName.str(), *F};
   auto  = PP.getHeaderSearchInfo().getModuleMap();
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -304,7 +304,7 @@
   // supplied by Clang. Find that builtin header.
   SmallString<128> Path;
   llvm::sys::path::append(Path, BuiltinIncludeDir->getName(), Header.FileName);
-  auto File = SourceMgr.getFileManager().getFile(Path);
+  auto File = SourceMgr.getFileManager().getOptionalFileRef(Path);
   if (!File)
 return false;
 
@@ -1024,7 +1024,7 @@
   // Look for an umbrella header.
   SmallString<128> UmbrellaName = StringRef(FrameworkDir->getName());
   llvm::sys::path::append(UmbrellaName, "Headers", ModuleName + ".h");
-  auto UmbrellaHeader = FileMgr.getFile(UmbrellaName);
+  auto UmbrellaHeader = FileMgr.getOptionalFileRef(UmbrellaName);
 
   // FIXME: If there's no umbrella header, we could probably scan the
   // framework to load *everything*. But, it's not clear that this is a good
@@ -1136,14 +1136,14 @@
 }
 
 void ModuleMap::setUmbrellaHeader(
-Module *Mod, const FileEntry *UmbrellaHeader, const Twine ,
+Module *Mod, FileEntryRef UmbrellaHeader, const Twine ,
 const Twine ) {
   Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader));
-  Mod->Umbrella = UmbrellaHeader;
+  Mod->Umbrella = ();
   Mod->UmbrellaAsWritten = NameAsWritten.str();
   Mod->UmbrellaRelativeToRootModuleDirectory =
   PathRelativeToRootModuleDirectory.str();
-  UmbrellaDirs[UmbrellaHeader->getDir()] = Mod;
+  UmbrellaDirs[UmbrellaHeader.getDir()] = Mod;
 
   // Notify callbacks that we just added a new header.
   for (const auto  : Callbacks)
@@ -2510,8 +2510,8 @@
 SourceMgr.getFileManager().getVirtualFileSystem();
 for (llvm::vfs::recursive_directory_iterator I(FS, Dir->getName(), EC), E;
  I != E && !EC; I.increment(EC)) {
-  if (auto FE = SourceMgr.getFileManager().getFile(I->path())) {
-Module::Header Header = {"", std::string(I->path()), *FE};
+  if (auto FE = SourceMgr.getFileManager().getOptionalFileRef(I->path())) {
+Module::Header Header = {"", std::string(I->path()), FE};
 Headers.push_back(std::move(Header));
   }
 }
Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ 

[PATCH] D142143: [Lex] For dependency directive lexing, angled includes in `__has_include` should be lexed as string literals

2023-01-19 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: clang/lib/Lex/Lexer.cpp:4420
+  DepDirectives.front().Tokens[NextDepDirectiveTokenIndex];
+  if (BufferStart + NextTok.Offset >= BufferPtr)
+break;

benlangmuir wrote:
> How do we know this will terminate?
If `LexAngledStringLiteral()` returns `tok::header_name` there were valid 
tokens that formed a header include and it has set `BufferPtr` after the `>` 
token. I can't think of reason it would not terminate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142143

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


[PATCH] D142046: [BPF][clang] Ignore stack protector options for BPF target

2023-01-19 Thread Eduard Zingerman via Phabricator via cfe-commits
eddyz87 added a comment.

I can relax the warning to note to be on the same page with GCC, the reason I 
didn't is that similar things in DiagnosticDriverKinds.td are warnings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142046

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


[PATCH] D142123: [clang-tidy] Add check to suggest use of #pragma once

2023-01-19 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware added a comment.

Basically, anything that extends `HeaderGuardCheck` (or `HeaderGuardBase` from 
D142121 ) is really just a fancy 
configuration option, rather than a separate check, and should be treated as 
such. My proposal is this:

1. Create a new base class called `HeaderGuardStyle` which controls all 
behavior that happens after a header guard or `#pragma once` is discovered, and 
create associated `llvm::Registry`
2. Modify `HeaderGuardCheck` to select a `HeaderGuardStyle` from the registry 
based on a configuration option
3. Create a class called `MacroHeaderGuardStyle` which extends 
`HeaderGuardStyle` and basically does what D142121 
 does now
4. Rename `LLVMHeaderGuardCheck` to `LLVMHeaderGuardStyle` and modify it to 
extend `MacroHeaderGuardStyle` and add it to the registry
5. Add `PragmaOnceHeaderGuardStyle` which extends `HeaderGuardStyle` and add it 
to the registry

The refactoring that I've done in D142121  is 
most of the way to being able to implement my above proposal. I just need to 
shift a few things around and add the new classes. @aaron.ballman if this 
proposal is good with you I'll get started on it.


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

https://reviews.llvm.org/D142123

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


[PATCH] D142046: [BPF][clang] Ignore stack protector options for BPF target

2023-01-19 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

Sorry, I double checked. '-fstack-protector -fno-stack-protector' will not 
result in warnings. So the patch LGTM. So gentoo people can add 
-fno-stack-protector to suppress warnings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142046

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


[PATCH] D142123: [clang-tidy] Add check to suggest use of #pragma once

2023-01-19 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D142123#4066460 , @aaron.ballman 
wrote:

> In D142123#4066447 , @lebedev.ri 
> wrote:
>
>> In D142123#4066351 , @njames93 
>> wrote:
>>
>>> Given the fact its non-standard, it has caveats and peoples eagerness to 
>>> blindly enable all checks (or all checks from a module). 
>>> I feel this check would likely cause more harm than good.
>>
>> Shall we remove abseil checks?
>> Shall we remove libc++-specific checks?
>> Shall we remove webkit checks?
>> Shall we remove backwards-compatibility checks?
>>
>> Nothing is ever useful for everyone. Much like `-Weverything`,
>> enabling all checks comes with an explcit caveat that
>> one needs to disable the checks that are not applicable for the codebase.
>>
>> +1 to having this check.
>
> We're not asking for it to be useful to everyone; we are asking for 
> justification for the current proposed form because there are problems with 
> what's proposed. We're trying to figure out what the correct approach is 
> (fwiw, I'd be opposed to what's proposed as-is but would be fine with a 
> tweaked proposal).

Thanks!


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

https://reviews.llvm.org/D142123

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


[PATCH] D141868: [Clang] [Sema] Removed a fix-it for system headers

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

LGTM!




Comment at: clang/docs/ReleaseNotes.rst:356
 ^^^
+- Disabled FIT-IT suggested for a case of bad conversion in system headers.
 - Clang will now check compile-time determinable string literals as format 
strings.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141868

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


[PATCH] D142046: [BPF][clang] Ignore stack protector options for BPF target

2023-01-19 Thread Alexei Starovoitov via Phabricator via cfe-commits
ast added a comment.

In D142046#4066758 , @yonghong-song 
wrote:

> @ast With this patch, gentoo clang compilation will hit the warning even if 
> people appends -fno-stack-protector. Is this okay? In general, if the option 
> is '-fstack-protector -fno-stack-protector', we should not issue warning, 
> right?

ahh. yeah. -fno-stack-protector should silence the warning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142046

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


  1   2   3   >