[clang] [OpenMP 5.2] Deprecate syntax of map modifiers without comma separators (PR #69534)

2023-10-19 Thread Fazlay Rabbi via cfe-commits

https://github.com/mdfazlay updated 
https://github.com/llvm/llvm-project/pull/69534

>From 0b162fd70f24f734f823816171ee0ae5df466d87 Mon Sep 17 00:00:00 2001
From: Fazlay Rabbi 
Date: Wed, 18 Oct 2023 13:21:17 -0700
Subject: [PATCH] [OpenMP 5.2] Deprecate syntax of map modifiers without comma
 separators

The syntax of modifiers without comma separators in the map clause was
deprecated in OpenMP 5.2.

Reference: OpenMP 5.2 Spec, Page 627, Line 19
---
 clang/include/clang/Basic/DiagnosticParseKinds.td  |  1 +
 clang/lib/Parse/ParseOpenMP.cpp|  9 +
 clang/test/OpenMP/declare_mapper_ast_print.c   |  2 +-
 clang/test/OpenMP/declare_mapper_messages.c|  8 
 clang/test/OpenMP/target_ast_print.cpp | 10 +-
 clang/test/OpenMP/target_map_messages.cpp  |  9 +
 clang/test/OpenMP/target_parallel_for_map_messages.cpp |  4 
 .../OpenMP/target_parallel_for_simd_map_messages.cpp   |  4 
 clang/test/OpenMP/target_parallel_map_messages.cpp |  4 
 clang/test/OpenMP/target_simd_map_messages.cpp |  4 
 .../OpenMP/target_teams_distribute_map_messages.cpp|  4 
 ...rget_teams_distribute_parallel_for_map_messages.cpp |  3 +++
 ...teams_distribute_parallel_for_simd_map_messages.cpp |  4 
 .../target_teams_distribute_simd_map_messages.cpp  |  4 
 clang/test/OpenMP/target_teams_map_messages.cpp|  3 +++
 15 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 43a5f000eda6cb9..9d33b014d5fd8c3 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1534,6 +1534,7 @@ def warn_omp51_compat_attributes : Warning<
   "standards before OpenMP 5.1">,
   InGroup, DefaultIgnore;
 def err_omp_expected_colon : Error<"missing ':' in %0">;
+def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
 def err_omp_requires_out_inout_depend_type : Error<
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 995834a78c795fb..1a80bce0cfde53c 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4198,6 +4198,10 @@ bool 
Parser::parseMapTypeModifiers(Sema::OpenMPVarListDataTy ) {
 TypeModifier == OMPC_MAP_MODIFIER_ompx_hold) {
   Data.MapTypeModifiers.push_back(TypeModifier);
   Data.MapTypeModifiersLoc.push_back(Tok.getLocation());
+  if (PP.LookAhead(0).isNot(tok::comma) &&
+  PP.LookAhead(0).isNot(tok::colon) && getLangOpts().OpenMP >= 52)
+Diag(Tok.getLocation(), diag::err_omp_missing_comma)
+<< "map type modifier";
   ConsumeToken();
 } else if (TypeModifier == OMPC_MAP_MODIFIER_mapper) {
   Data.MapTypeModifiers.push_back(TypeModifier);
@@ -4205,6 +4209,11 @@ bool 
Parser::parseMapTypeModifiers(Sema::OpenMPVarListDataTy ) {
   ConsumeToken();
   if (parseMapperModifier(Data))
 return true;
+  if (Tok.isNot(tok::comma) && Tok.isNot(tok::colon) &&
+  getLangOpts().OpenMP >= 52)
+Diag(Data.MapTypeModifiersLoc.back(), diag::err_omp_missing_comma)
+<< "map type modifier";
+
 } else {
   // For the case of unknown map-type-modifier or a map-type.
   // Map-type is followed by a colon; the function returns when it
diff --git a/clang/test/OpenMP/declare_mapper_ast_print.c 
b/clang/test/OpenMP/declare_mapper_ast_print.c
index 7c30b21c48b956e..e6a0546fe5c98a1 100644
--- a/clang/test/OpenMP/declare_mapper_ast_print.c
+++ b/clang/test/OpenMP/declare_mapper_ast_print.c
@@ -58,7 +58,7 @@ int main(void) {
 // CHECK: #pragma omp declare mapper (id : struct vec v) map(tofrom: v.len)
 struct vec vv;
 struct dat dd[10];
-#pragma omp target map(mapper(id) alloc: vv)
+#pragma omp target map(mapper(id), alloc: vv)
 // CHECK: #pragma omp target map(mapper(id),alloc: vv)
 { vv.len++; }
 #pragma omp target map(mapper(default), from: dd[0:10])
diff --git a/clang/test/OpenMP/declare_mapper_messages.c 
b/clang/test/OpenMP/declare_mapper_messages.c
index 17315738155b104..288caca097648c0 100644
--- a/clang/test/OpenMP/declare_mapper_messages.c
+++ b/clang/test/OpenMP/declare_mapper_messages.c
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -verify=omp50,expected -fopenmp -fopenmp-version=50 
-ferror-limit 100 -DOMP50 %s
 // RUN: %clang_cc1 -verify=omp51,expected -fopenmp -ferror-limit 100 %s
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -ferror-limit 100 
-DOMP52 %s
+// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp -fopenmp-version=52 
-ferror-limit 100 -DOMP52 %s
 
 // RUN: %clang_cc1 -verify=omp50,expected -fopenmp-simd -fopenmp-version=50 
-ferror-limit 100 -DOMP50 %s
 // RUN: %clang_cc1 -verify=omp51-simd,expected -fopenmp-simd -ferror-limit 100 

[clang] [X86][AMX] remove related code of X86PreAMXConfigPass (PR #69569)

2023-10-19 Thread via cfe-commits

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


[clang] f2517cb - [X86][AMX] remove related code of X86PreAMXConfigPass (#69569)

2023-10-19 Thread via cfe-commits

Author: yubingex007-a11y
Date: 2023-10-20T13:43:34+08:00
New Revision: f2517cbceec0bd9b049ba24f36cb3a2508c988fa

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

LOG: [X86][AMX] remove related code of X86PreAMXConfigPass (#69569)

In https://reviews.llvm.org/D125075, we switched to use
FastPreTileConfig in O0 and abandoned X86PreAMXConfigPass.
we can remove related code of X86PreAMXConfigPass safely.

Added: 


Modified: 
clang/docs/tools/clang-formatted-files.txt
llvm/include/llvm/CodeGen/Passes.h
llvm/lib/Target/X86/CMakeLists.txt
llvm/lib/Target/X86/X86.h
llvm/lib/Target/X86/X86TargetMachine.cpp
llvm/tools/opt/opt.cpp
llvm/utils/gn/secondary/llvm/lib/Target/X86/BUILD.gn

Removed: 
llvm/lib/Target/X86/X86PreAMXConfig.cpp
llvm/test/CodeGen/X86/AMX/amx-configO2toO0-precfg.ll



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 16f84727117e28d..48cd800bffd0046 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -6813,7 +6813,6 @@ llvm/lib/Target/X86/X86LoadValueInjectionRetHardening.cpp
 llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp
 llvm/lib/Target/X86/X86LowerAMXType.cpp
 llvm/lib/Target/X86/X86LowerTileCopy.cpp
-llvm/lib/Target/X86/X86PreAMXConfig.cpp
 llvm/lib/Target/X86/X86PreTileConfig.cpp
 llvm/lib/Target/X86/X86RegisterBankInfo.h
 llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp

diff  --git a/llvm/include/llvm/CodeGen/Passes.h 
b/llvm/include/llvm/CodeGen/Passes.h
index 598c0b838c1b97d..8d14eef949e91b4 100644
--- a/llvm/include/llvm/CodeGen/Passes.h
+++ b/llvm/include/llvm/CodeGen/Passes.h
@@ -584,9 +584,6 @@ namespace llvm {
   /// or split the data to two <128 x i32>.
   FunctionPass *createX86LowerAMXTypePass();
 
-  /// The pass insert tile config intrinsics for AMX fast register allocation.
-  FunctionPass *createX86PreAMXConfigPass();
-
   /// The pass transforms amx intrinsics to scalar operation if the function 
has
   /// optnone attribute or it is O0.
   FunctionPass *createX86LowerAMXIntrinsicsPass();

diff  --git a/llvm/lib/Target/X86/CMakeLists.txt 
b/llvm/lib/Target/X86/CMakeLists.txt
index c387d59ea981a52..0b7a98ad6341dde 100644
--- a/llvm/lib/Target/X86/CMakeLists.txt
+++ b/llvm/lib/Target/X86/CMakeLists.txt
@@ -33,7 +33,6 @@ set(sources
   X86DiscriminateMemOps.cpp
   X86LowerTileCopy.cpp
   X86LowerAMXType.cpp
-  X86PreAMXConfig.cpp
   X86LowerAMXIntrinsics.cpp
   X86TileConfig.cpp
   X86FastPreTileConfig.cpp

diff  --git a/llvm/lib/Target/X86/X86.h b/llvm/lib/Target/X86/X86.h
index 3c5ca0788498032..485afbc1dfbc241 100644
--- a/llvm/lib/Target/X86/X86.h
+++ b/llvm/lib/Target/X86/X86.h
@@ -194,7 +194,6 @@ void initializeX86LowerAMXTypeLegacyPassPass(PassRegistry 
&);
 void initializeX86LowerTileCopyPass(PassRegistry &);
 void initializeX86OptimizeLEAPassPass(PassRegistry &);
 void initializeX86PartialReductionPass(PassRegistry &);
-void initializeX86PreAMXConfigPassPass(PassRegistry &);
 void initializeX86PreTileConfigPass(PassRegistry &);
 void initializeX86ReturnThunksPass(PassRegistry &);
 void initializeX86SpeculativeExecutionSideEffectSuppressionPass(PassRegistry 
&);

diff  --git a/llvm/lib/Target/X86/X86PreAMXConfig.cpp 
b/llvm/lib/Target/X86/X86PreAMXConfig.cpp
deleted file mode 100644
index 7872a64061d438c..000
--- a/llvm/lib/Target/X86/X86PreAMXConfig.cpp
+++ /dev/null
@@ -1,415 +0,0 @@
-//===- Target/X86/X86PreAMXConfig.cpp - *- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-/// Insert tilecfg for each area of key AMX intrinsic.
-/// All the key AMX intrinsic's tile operand must come from tileload. And the
-/// def tile of key AMX intrinsic must be tilestored.
-/// take tdpbssd for example:
-/// --
-/// %t1 = call x86_amx @llvm.x86.tileloadd64.internal(...)key
-/// %t2 = call x86_amx @llvm.x86.tileloadd64.internal(...) |
-/// %t3 = call x86_amx @llvm.x86.tileloadd64.internal(...)amx
-/// %td = tail call x86_amx @llvm.x86.tdpbssd.internal(t1, t2, t3) |
-/// call void @llvm.x86.tilestored64.internal(... td) area
-/// --
-/// This pass will insert tilecfg before every key-amx-area, some like:
-/// --
-/// %cfgmem = 

[clang] [clang][repl] fix `new` on Mac M1 (PR #69072)

2023-10-19 Thread Maksim Levental via cfe-commits

https://github.com/makslevental updated 
https://github.com/llvm/llvm-project/pull/69072

>From 891cdd5ceea279362c3df221fd4ae73c142b2f7e Mon Sep 17 00:00:00 2001
From: max 
Date: Sat, 14 Oct 2023 12:46:42 -0500
Subject: [PATCH] [clang][repl] fix `new`

---
 clang/lib/Interpreter/Interpreter.cpp | 24 ---
 .../unittests/Interpreter/InterpreterTest.cpp | 19 ---
 2 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 7968c62cbd3e7b3..57514f2d0cc424d 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,6 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-void* operator new(__SIZE_TYPE__, void* __p) noexcept;
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
@@ -257,14 +256,9 @@ const char *const Runtimes = R"(
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double);
 void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long 
long);
 template 
-void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size) {
-  for (auto Idx = 0; Idx < Size; ++Idx)
-new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]);
-}
+void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size);
 template 
-void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size) {
-  __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
-}
+void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size);
 )";
 
 llvm::Expected>
@@ -762,6 +756,20 @@ __clang_Interpreter_SetValueNoAlloc(void *This, void 
*OutVal,
   VRef = Value(static_cast(This), OpaqueType);
 }
 
+template 
+REPL_EXTERNAL_VISIBILITY void
+__clang_Interpreter_SetValueCopyArr(T *Src, void *Placement,
+unsigned long Size) {
+  for (unsigned long Idx = 0; Idx < Size; ++Idx)
+new ((void *)(((T *)Placement) + Idx)) T(Src[Idx]);
+}
+template 
+REPL_EXTERNAL_VISIBILITY void
+__clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void *Placement,
+unsigned long Size) {
+  __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
+}
+
 static void SetValueDataBasedOnQualType(Value , unsigned long long Data) {
   QualType QT = V.getType();
   if (const auto *ET = QT->getAs())
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 5f2911e9a7adad3..6b4230a22357d2c 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -24,6 +24,7 @@
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/TargetParser/Host.h"
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -45,13 +46,25 @@ static std::unique_ptr
 createInterpreter(const Args  = {},
   DiagnosticConsumer *Client = nullptr) {
   Args ClangArgs = {"-Xclang", "-emit-llvm-only"};
+  if (llvm::Triple(llvm::sys::getProcessTriple()).isOSDarwin()) {
+Args macOsArgs = {"-Xcc", "-isysroot",
+  "/Applications/Xcode.app/Contents/Developer/Platforms/"
+  "MacOSX.platform/Developer/SDKs/MacOSX.sdk"};
+ClangArgs.insert(ClangArgs.end(), macOsArgs.begin(), macOsArgs.end());
+  }
   ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
   auto CB = clang::IncrementalCompilerBuilder();
   CB.SetCompilerArgs(ClangArgs);
   auto CI = cantFail(CB.CreateCpp());
   if (Client)
 CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false);
-  return cantFail(clang::Interpreter::create(std::move(CI)));
+  auto interp = cantFail(clang::Interpreter::create(std::move(CI)));
+  if (llvm::Triple(llvm::sys::getProcessTriple()).isOSDarwin())
+(void)cantFail(interp->Parse("#include "));
+  else
+(void)cantFail(interp->Parse(
+"void* operator new(__SIZE_TYPE__, void* __p) noexcept;"));
+  return interp;
 }
 
 static size_t DeclsSize(TranslationUnitDecl *PTUDecl) {
@@ -148,12 +161,12 @@ TEST(InterpreterTest, UndoCommand) {
   auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
 
   // Fail to undo.
-  auto Err1 = Interp->Undo();
+  auto Err1 = Interp->Undo(2);
   EXPECT_EQ("Operation failed. Too many undos",
 llvm::toString(std::move(Err1)));
   auto Err2 = Interp->Parse("int foo = 42;");
   EXPECT_TRUE(!!Err2);
-  auto Err3 = Interp->Undo(2);
+  auto Err3 = Interp->Undo(3);
   

[clang] [clang][repl] fix `new` on Mac M1 (PR #69072)

2023-10-19 Thread Maksim Levental via cfe-commits

makslevental wrote:

@vgvassilev this seems acceptable?

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


[clang] [clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse (PR #69078)

2023-10-19 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> I hope that we do not drop `LLVM_LIBRARY_VISIBILITY` arbitrarily from 
> `clang::driver::toolchains::*` classes, just because some unittests need to 
> reference the symbols in a shared object.

That’s a reasonable point.

> ```c
> #if !defined(LLVM_BUILD_SHARED_LIBS)
> ```
> 
> is not great but is not too bad. `-DBUILD_SHARED_LIBS=on` modes are slow to 
> execute tests and are not used often for Release builds.

I guess that’s a reasonable tradeoff. We’d need to do the same for dylib mode 
as well, which probably is used a bit more. But the main point is that whoever 
is working on modifying that implementation can run the tests fairly easy, and 
that they get run somewhere in some configurations at least.

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


[clang] [clang][repl] fix `new` on Mac M1 (PR #69072)

2023-10-19 Thread Maksim Levental via cfe-commits

https://github.com/makslevental updated 
https://github.com/llvm/llvm-project/pull/69072

>From 940da2de0fc92e8e0da64fd35ad08effb6093447 Mon Sep 17 00:00:00 2001
From: max 
Date: Sat, 14 Oct 2023 12:46:42 -0500
Subject: [PATCH] [clang][repl] fix `new`

---
 clang/lib/Interpreter/Interpreter.cpp | 24 ---
 .../unittests/Interpreter/InterpreterTest.cpp | 21 +---
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 7968c62cbd3e7b3..57514f2d0cc424d 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,6 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-void* operator new(__SIZE_TYPE__, void* __p) noexcept;
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
@@ -257,14 +256,9 @@ const char *const Runtimes = R"(
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double);
 void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long 
long);
 template 
-void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size) {
-  for (auto Idx = 0; Idx < Size; ++Idx)
-new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]);
-}
+void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size);
 template 
-void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size) {
-  __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
-}
+void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size);
 )";
 
 llvm::Expected>
@@ -762,6 +756,20 @@ __clang_Interpreter_SetValueNoAlloc(void *This, void 
*OutVal,
   VRef = Value(static_cast(This), OpaqueType);
 }
 
+template 
+REPL_EXTERNAL_VISIBILITY void
+__clang_Interpreter_SetValueCopyArr(T *Src, void *Placement,
+unsigned long Size) {
+  for (unsigned long Idx = 0; Idx < Size; ++Idx)
+new ((void *)(((T *)Placement) + Idx)) T(Src[Idx]);
+}
+template 
+REPL_EXTERNAL_VISIBILITY void
+__clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void *Placement,
+unsigned long Size) {
+  __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
+}
+
 static void SetValueDataBasedOnQualType(Value , unsigned long long Data) {
   QualType QT = V.getType();
   if (const auto *ET = QT->getAs())
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 5f2911e9a7adad3..4963846dffa6f98 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -24,10 +24,13 @@
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/TargetParser/Host.h"
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+#include 
+
 using namespace clang;
 
 #if defined(_AIX)
@@ -45,13 +48,25 @@ static std::unique_ptr
 createInterpreter(const Args  = {},
   DiagnosticConsumer *Client = nullptr) {
   Args ClangArgs = {"-Xclang", "-emit-llvm-only"};
+  if (llvm::Triple(llvm::sys::getProcessTriple()).isOSDarwin()) {
+Args macOsArgs = {"-Xcc", "-isysroot",
+  "/Applications/Xcode.app/Contents/Developer/Platforms/"
+  "MacOSX.platform/Developer/SDKs/MacOSX.sdk"};
+ClangArgs.insert(ClangArgs.end(), macOsArgs.begin(), macOsArgs.end());
+  }
   ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
   auto CB = clang::IncrementalCompilerBuilder();
   CB.SetCompilerArgs(ClangArgs);
   auto CI = cantFail(CB.CreateCpp());
   if (Client)
 CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false);
-  return cantFail(clang::Interpreter::create(std::move(CI)));
+  auto interp = cantFail(clang::Interpreter::create(std::move(CI)));
+  if (llvm::Triple(llvm::sys::getProcessTriple()).isOSDarwin())
+(void)cantFail(interp->Parse("#include "));
+  else
+(void)cantFail(interp->Parse(
+"void* operator new(__SIZE_TYPE__, void* __p) noexcept;"));
+  return interp;
 }
 
 static size_t DeclsSize(TranslationUnitDecl *PTUDecl) {
@@ -148,12 +163,12 @@ TEST(InterpreterTest, UndoCommand) {
   auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
 
   // Fail to undo.
-  auto Err1 = Interp->Undo();
+  auto Err1 = Interp->Undo(2);
   EXPECT_EQ("Operation failed. Too many undos",
 llvm::toString(std::move(Err1)));
   auto Err2 = Interp->Parse("int foo = 42;");
   EXPECT_TRUE(!!Err2);
-  auto Err3 = 

[clang] [RISCV] Convert all floating point vector type operands to integer vector type (PR #69559)

2023-10-19 Thread Brandon Wu via cfe-commits


@@ -450,6 +474,18 @@ multiclass VPatVC_XVV;
+  // Add another patterns for float type return value.
+  if !ne(wti.SEW, 8) then {
+defvar wfti = !cast("VF"#wti.SEW#wti.LMul.MX);

4vtomat wrote:

Do you think test cases all of combination of vector type arguments(including 
float and int) are needed?
Or just provide test cases for some mix type arguments are enough.

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


[clang] [clang]Avoid to check created local variable multiple time when evaluating (PR #69106)

2023-10-19 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (PR #69501)

2023-10-19 Thread Congcong Cai via cfe-commits


@@ -14,13 +14,42 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+static bool hasConstQualifier(QualType Type) {
+  const QualType PtrType = Type->getPointeeType();
+  if (!PtrType.isNull())
+return hasConstQualifier(PtrType);
+
+  return Type.isConstQualified();

HerrCai0907 wrote:

In cppreference, `const_cast` means converting between types with different 
cv-qualification.
So `isConstQualified` is not enough, `isVolatileQualified` is also needed.

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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (PR #69501)

2023-10-19 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (PR #69501)

2023-10-19 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (PR #69501)

2023-10-19 Thread Congcong Cai via cfe-commits

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


[clang] [RISCV] Convert all floating point vector type operands to integer vector type (PR #69559)

2023-10-19 Thread Brandon Wu via cfe-commits


@@ -450,6 +474,18 @@ multiclass VPatVC_XVV;
+  // Add another patterns for float type return value.
+  if !ne(wti.SEW, 8) then {
+defvar wfti = !cast("VF"#wti.SEW#wti.LMul.MX);

4vtomat wrote:

Yes, I'll add some tests for it~

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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (PR #69501)

2023-10-19 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (PR #69501)

2023-10-19 Thread Congcong Cai via cfe-commits


@@ -14,13 +14,42 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+static bool hasConstQualifier(QualType Type) {
+  const QualType PtrType = Type->getPointeeType();
+  if (!PtrType.isNull())
+return hasConstQualifier(PtrType);
+
+  return Type.isConstQualified();
+}
+
+namespace {
+AST_MATCHER(QualType, hasConst) { return hasConstQualifier(Node); }
+} // namespace
+
+ProTypeConstCastCheck::ProTypeConstCastCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", false)) {}
+
+void ProTypeConstCastCheck::storeOptions(ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "StrictMode", StrictMode);
+}
+
 void ProTypeConstCastCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(cxxConstCastExpr().bind("cast"), this);
+  if (StrictMode)
+Finder->addMatcher(cxxConstCastExpr().bind("cast"), this);
+  else
+Finder->addMatcher(cxxConstCastExpr(unless(hasDestinationType(
+hasCanonicalType(hasConst()
+   .bind("cast"),
+   this);
 }
 
 void ProTypeConstCastCheck::check(const MatchFinder::MatchResult ) {
   const auto *MatchedCast = Result.Nodes.getNodeAs("cast");
-  diag(MatchedCast->getOperatorLoc(), "do not use const_cast");
+  diag(MatchedCast->getOperatorLoc(),
+   "do not use const_cast%select{ to cast away const|}0")

HerrCai0907 wrote:

`cast away const` sounds like a little bit strange.
```suggestion
   "do not use const_cast%select{ to remove const qualifier|}0")
```

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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (PR #69501)

2023-10-19 Thread Congcong Cai via cfe-commits

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


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


[clang] [clang][repl] fix `new` on Mac M1 (PR #69072)

2023-10-19 Thread Maksim Levental via cfe-commits

https://github.com/makslevental updated 
https://github.com/llvm/llvm-project/pull/69072

>From 737bef4f36139f0347e9ab58838e41aadbb45d16 Mon Sep 17 00:00:00 2001
From: max 
Date: Sat, 14 Oct 2023 12:46:42 -0500
Subject: [PATCH] [clang][repl] fix `new`

---
 clang/lib/Interpreter/Interpreter.cpp | 24 ---
 clang/test/Interpreter/execute.cpp|  2 ++
 .../unittests/Interpreter/InterpreterTest.cpp |  5 +++-
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 7968c62cbd3e7b3..57514f2d0cc424d 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,6 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-void* operator new(__SIZE_TYPE__, void* __p) noexcept;
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
@@ -257,14 +256,9 @@ const char *const Runtimes = R"(
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double);
 void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long 
long);
 template 
-void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size) {
-  for (auto Idx = 0; Idx < Size; ++Idx)
-new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]);
-}
+void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size);
 template 
-void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size) {
-  __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
-}
+void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size);
 )";
 
 llvm::Expected>
@@ -762,6 +756,20 @@ __clang_Interpreter_SetValueNoAlloc(void *This, void 
*OutVal,
   VRef = Value(static_cast(This), OpaqueType);
 }
 
+template 
+REPL_EXTERNAL_VISIBILITY void
+__clang_Interpreter_SetValueCopyArr(T *Src, void *Placement,
+unsigned long Size) {
+  for (unsigned long Idx = 0; Idx < Size; ++Idx)
+new ((void *)(((T *)Placement) + Idx)) T(Src[Idx]);
+}
+template 
+REPL_EXTERNAL_VISIBILITY void
+__clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void *Placement,
+unsigned long Size) {
+  __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
+}
+
 static void SetValueDataBasedOnQualType(Value , unsigned long long Data) {
   QualType QT = V.getType();
   if (const auto *ET = QT->getAs())
diff --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index 6e73ed3927e8155..d54ab99749c1bac 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -20,4 +20,6 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, 
reinterpret_cast
+
 %quit
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 5f2911e9a7adad3..cc00d52d8d3bfa6 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -51,7 +51,10 @@ createInterpreter(const Args  = {},
   auto CI = cantFail(CB.CreateCpp());
   if (Client)
 CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false);
-  return cantFail(clang::Interpreter::create(std::move(CI)));
+  auto interp = cantFail(clang::Interpreter::create(std::move(CI)));
+  (void)cantFail(
+  interp->Parse("void* operator new(__SIZE_TYPE__, void* __p) noexcept;"));
+  return interp;
 }
 
 static size_t DeclsSize(TranslationUnitDecl *PTUDecl) {

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


[clang] [clang][repl] fix `new` on Mac M1 (PR #69072)

2023-10-19 Thread Maksim Levental via cfe-commits

https://github.com/makslevental updated 
https://github.com/llvm/llvm-project/pull/69072

>From f2d35a0f0356d5ea570019bc02558bd5fc143afb Mon Sep 17 00:00:00 2001
From: max 
Date: Sat, 14 Oct 2023 12:46:42 -0500
Subject: [PATCH 1/3] [clang][repl] fix `new`

---
 clang/lib/Interpreter/Interpreter.cpp | 2 +-
 clang/test/Interpreter/execute.cpp| 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 7968c62cbd3e7b3..ddfbc9ac01c6743 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,7 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-void* operator new(__SIZE_TYPE__, void* __p) noexcept;
+#include 
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
diff --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index 6e73ed3927e8155..d54ab99749c1bac 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -20,4 +20,6 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, 
reinterpret_cast
+
 %quit

>From a9799463a5d2a4bb2d788f871b454d5d3fa0add8 Mon Sep 17 00:00:00 2001
From: Maksim Levental 
Date: Sat, 14 Oct 2023 19:26:04 -0500
Subject: [PATCH 2/3] Update clang/lib/Interpreter/Interpreter.cpp

Remove include new

Co-authored-by: Vassil Vassilev 
---
 clang/lib/Interpreter/Interpreter.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index ddfbc9ac01c6743..30348e1c03f8c76 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,6 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-#include 
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);

>From d5e4a70a01054e667285f6b3ca77141ae63a71cb Mon Sep 17 00:00:00 2001
From: max 
Date: Sat, 14 Oct 2023 23:44:01 -0500
Subject: [PATCH 3/3] branch on isdarwin

---
 clang/lib/Interpreter/Interpreter.cpp | 28 +--
 clang/test/Interpreter/execute.cpp|  2 --
 .../unittests/Interpreter/InterpreterTest.cpp | 25 -
 3 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 30348e1c03f8c76..a249a12b3a1aaf9 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -244,28 +244,6 @@ Interpreter::~Interpreter() {
   }
 }
 
-// These better to put in a runtime header but we can't. This is because we
-// can't find the precise resource directory in unittests so we have to hard
-// code them.
-const char *const Runtimes = R"(
-void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
-void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
-void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
-void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, float);
-void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double);
-void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double);
-void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long 
long);
-template 
-void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size) {
-  for (auto Idx = 0; Idx < Size; ++Idx)
-new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]);
-}
-template 
-void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long Size) {
-  __clang_Interpreter_SetValueCopyArr(Src[0], Placement, Size);
-}
-)";
-
 llvm::Expected>
 Interpreter::create(std::unique_ptr CI) {
   llvm::Error Err = llvm::Error::success();
@@ -274,10 +252,6 @@ Interpreter::create(std::unique_ptr CI) {
   if (Err)
 return std::move(Err);
 
-  auto PTU = Interp->Parse(Runtimes);
-  if (!PTU)
-return PTU.takeError();
-
   Interp->ValuePrintingInfo.resize(3);
   // FIXME: This is a ugly hack. Undo command checks its availability by 
looking
   // at the size of the PTU list. However we have parsed something in the
@@ -351,7 +325,7 @@ Interpreter::Parse(llvm::StringRef Code) {
   return std::move(E);
   }
 
-  // Tell the interpreter sliently ignore unused expressions since value
+  // Tell the interpreter silently ignore unused expressions since value
   // printing could cause it.
 

[clang] [clang] [unittest] Add a test for Generic_GCC::GCCVersion::Parse (PR #69078)

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

MaskRay wrote:

I hope that we do not drop `LLVM_LIBRARY_VISIBILITY` arbitrarily from 
`clang::driver::toolchains::*` classes, just because some unittests need to 
reference the symbols in a shared object.

```c
#if !defined(LLVM_BUILD_SHARED_LIBS)
```

is not great but is not too bad. `-DBUILD_SHARED_LIBS=on` modes are slow to 
execute tests and are not used often for Release builds.

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


[clang] [Driver] Corrections for linker flags passed with relocatable linking on OpenBSD (PR #67254)

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


@@ -36,10 +36,12 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64-LD %s
 // RUN: %clang --target=mips64el-unknown-openbsd -### %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s
-// CHECK-LD-R: "-r"
+// CHECK-LD-R-NOT: "-e" "__start"

MaskRay wrote:

`// CHECK-LD-R-NOT: "-e"`

Assert that no `-e` is passed.

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


[clang] [PGO] Add ability to mark cold functions as optsize/minsize/optnone (PR #69030)

2023-10-19 Thread David Li via cfe-commits


@@ -0,0 +1,65 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Transforms/Instrumentation/MarkColdFunctions.h"
+#include "llvm/Analysis/BlockFrequencyInfo.h"
+#include "llvm/Analysis/ProfileSummaryInfo.h"
+#include "llvm/IR/PassManager.h"
+
+using namespace llvm;
+
+PreservedAnalyses MarkColdFunctionsPass::run(Module ,
+ ModuleAnalysisManager ) {
+  if (ColdType == PGOOptions::ColdFuncAttr::None)
+return PreservedAnalyses::all();
+  ProfileSummaryInfo  = AM.getResult(M);
+  if (!PSI.hasProfileSummary())
+return PreservedAnalyses::all();
+  FunctionAnalysisManager  =
+  AM.getResult(M).getManager();
+  bool MadeChange = false;
+  for (Function  : M) {
+if (F.isDeclaration())
+  continue;
+BlockFrequencyInfo  = FAM.getResult(F);
+if (!PSI.isFunctionColdInCallGraph(, BFI))

david-xl wrote:

The same optimization strategy should also be applied to function already 
marked with cold attribute (either by user or previous passes).

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


[clang] [Driver] Corrections for linker flags passed with relocatable linking on OpenBSD (PR #67254)

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

MaskRay wrote:

`-Bdynamic` is the linker default, so you can remove it. Gnu.cpp uses 
`-Bdynamic` like `)` to close `-Bstatic`: `-Bstatic ... `-Bdynamic`

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


[clang] [Driver] Corrections for linker flags passed with relocatable linking on OpenBSD (PR #67254)

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

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


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


[clang] [Sema] Fixed faulty shift count warning (PR #69521)

2023-10-19 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/69521

>From a9bfc65f6d6b0953cd762f851fb6044e1c4b8ab8 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Wed, 18 Oct 2023 16:40:53 +0200
Subject: [PATCH 1/2] [Sema] Fixed faulty shift count warning

Constant values of _BitInt have the bitwith to exactly fit the constant
number. This patch fix a problem in Sema when building an APInt where the
supplied bitwidth can become too small and simply truncate the value leading to
a faulty warning.
---
 clang/lib/Sema/SemaExpr.cpp  |  7 +++
 clang/test/Sema/c2x-expr-range.c | 12 
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index aa30a3a03887558..c00178ee1835e00 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -12120,8 +12120,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
, ExprResult ,
 auto FXSema = S.Context.getFixedPointSemantics(LHSExprType);
 LeftSize = FXSema.getWidth() - (unsigned)FXSema.hasUnsignedPadding();
   }
-  llvm::APInt LeftBits(Right.getBitWidth(), LeftSize);
-  if (Right.uge(LeftBits)) {
+  if (Right.uge(LeftSize)) {
 S.DiagRuntimeBehavior(Loc, RHS.get(),
   S.PDiag(diag::warn_shift_gt_typewidth)
 << RHS.get()->getSourceRange());
@@ -12163,7 +12162,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
, ExprResult ,
 
   llvm::APInt ResultBits =
   static_cast(Right) + Left.getSignificantBits();
-  if (LeftBits.uge(ResultBits))
+  if (ResultBits.ule(LeftSize))
 return;
   llvm::APSInt Result = Left.extend(ResultBits.getLimitedValue());
   Result = Result.shl(Right);
@@ -12177,7 +12176,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
, ExprResult ,
   // bugs -- if the result is cast back to an unsigned type, it will have the
   // expected value. Thus we place this behind a different warning that can be
   // turned off separately if needed.
-  if (LeftBits == ResultBits - 1) {
+  if (ResultBits - 1 == LeftSize) {
 S.Diag(Loc, diag::warn_shift_result_sets_sign_bit)
 << HexResult << LHSType
 << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
diff --git a/clang/test/Sema/c2x-expr-range.c b/clang/test/Sema/c2x-expr-range.c
index 73683e6bfe684aa..eff0b7cd4d9f546 100644
--- a/clang/test/Sema/c2x-expr-range.c
+++ b/clang/test/Sema/c2x-expr-range.c
@@ -12,3 +12,15 @@ void test1(int *a) {
 void test2(__uint128_t *a) {
   (void)(*a >> ((__uint128_t)__UINT64_MAX__ + 1) <= 0); // expected-warning 
{{shift count >= width of type}}
 }
+
+// Regression test for bug where a faulty warning was given. We don't expect to
+// see any warning in this case.
+_BitInt(128) test3(_BitInt(128) a) {
+  return a << 12wb;
+}
+
+// Similar to test3 above, but with a too large shift count. We expect to see a
+// warning in this case.
+_BitInt(128) test4(_BitInt(128) a) {
+  return a << 129wb; // expected-warning {{shift count >= width of type}}
+}

>From a57f7401a691c865bf12740dd5b85e330bb6a0ca Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Fri, 20 Oct 2023 05:57:10 +0200
Subject: [PATCH 2/2] [Sema] Fixed faulty shift count warning

Added a line about this in the release note.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 81cbfd90155fe0b..0d2ac4e29f6f41e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -400,6 +400,9 @@ Bug Fixes in This Version
   operator in C. No longer issuing a confusing diagnostic along the lines of
   "incompatible operand types ('foo' and 'foo')" with extensions such as matrix
   types. Fixes (`#69008 `_)
+- Fixed an issue when a shift count specified by a small constant 
``_BitInt()``,
+  in a left shift operation, could result in a faulty warnings about
+  ``shift count >= width of type``.
 
 Bug Fixes to Compiler Builtins
 ^^

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


[clang] [RISCV] Convert all floating point vector type operands to integer vector type (PR #69559)

2023-10-19 Thread Craig Topper via cfe-commits


@@ -450,6 +474,18 @@ multiclass VPatVC_XVV;
+  // Add another patterns for float type return value.
+  if !ne(wti.SEW, 8) then {
+defvar wfti = !cast("VF"#wti.SEW#wti.LMul.MX);

topperc wrote:

Do we need new tests for this?

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


[clang] [clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes (PR #68379)

2023-10-19 Thread via cfe-commits

antangelo wrote:

I've posted a candidate reland of this PR at #69676 .

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


[clang] Reland "[clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes" (PR #69676)

2023-10-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (antangelo)


Changes

Reland of dd0fba11690f9fef304d5f48cde646e5eca8d3c0

When a nested template is instantiated, the template pattern of the inner class 
is not copied into the outer class
ClassTemplateSpecializationDecl. The specialization contains a 
ClassTemplateDecl with an empty record that points to the original template 
pattern instead.

As a result, when looking up the constructors of the inner class, no results 
are returned. This patch finds the original template pattern and uses that for 
the lookup instead.

Based on CWG2471 we must also substitute the known outer template arguments 
when creating deduction guides for the inner class.

Changes from the last iteration:
1. The outer retained levels from the outer template are always added to the 
`MultiLevelTemplateArgumentList` for rewriting `FunctionTemplateDecl` 
arguments, even if there is no FTD and the arguments are empty.
2. When building implicit deduction guides, the template pattern underlying 
decl is pushed as the current context. This resolves the issue where 
`FindInstantiatedDecl` is unable to find the inner template class.
3. Tests are updated to cover the failing case, and to assert that the type is 
correct after argument deduction in the implicit case. 

---
Full diff: https://github.com/llvm/llvm-project/pull/69676.diff


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+5) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+25-1) 
- (modified) clang/test/SemaTemplate/nested-deduction-guides.cpp (+5) 
- (added) clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp (+15) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..53a9507fc26613a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -536,6 +536,11 @@ Bug Fixes to C++ Support
   declaration definition. Fixes:
   (`#61763 `_)
 
+- Fix a bug where implicit deduction guides are not correctly generated for 
nested template
+  classes. Fixes:
+  (`#46200 `_)
+  (`#57812 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index f0197f7c102a857..c2477ec0063e418 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2253,6 +2253,7 @@ struct ConvertConstructorToDeductionGuideTransform {
 
   Sema 
   ClassTemplateDecl *Template;
+  ClassTemplateDecl *NestedPattern = nullptr;
 
   DeclContext *DC = Template->getDeclContext();
   CXXRecordDecl *Primary = Template->getTemplatedDecl();
@@ -2332,6 +2333,9 @@ struct ConvertConstructorToDeductionGuideTransform {
   Args.addOuterRetainedLevel();
 }
 
+if (NestedPattern)
+  Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
+
 FunctionProtoTypeLoc FPTL = CD->getTypeSourceInfo()->getTypeLoc()
.getAsAdjusted();
 assert(FPTL && "no prototype for constructor declaration");
@@ -2441,10 +2445,17 @@ struct ConvertConstructorToDeductionGuideTransform {
 SmallVector ParamTypes;
 const FunctionProtoType *T = TL.getTypePtr();
 
+MultiLevelTemplateArgumentList OuterInstantiationArgs;
+if (NestedPattern)
+  OuterInstantiationArgs = SemaRef.getTemplateInstantiationArgs(Template);
+
 //-- The types of the function parameters are those of the constructor.
 for (auto *OldParam : TL.getParams()) {
   ParmVarDecl *NewParam =
   transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
+  if (NestedPattern && NewParam)
+NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs,
+  MaterializedTypedefs);
   if (!NewParam)
 return QualType();
   ParamTypes.push_back(NewParam->getType());
@@ -2650,13 +2661,24 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl 
*Template,
   if (BuildingDeductionGuides.isInvalid())
 return;
 
+  // If the template is nested, then we need to use the original
+  // pattern to iterate over the constructors.
+  ClassTemplateDecl *Pattern = Transform.Template;
+  while (Pattern->getInstantiatedFromMemberTemplate()) {
+if (Pattern->isMemberSpecialization())
+  break;
+Pattern = Pattern->getInstantiatedFromMemberTemplate();
+Transform.NestedPattern = Pattern;
+  }
+
   // Convert declared constructors into deduction guide templates.
   // FIXME: Skip constructors for which deduction must necessarily fail (those
   // for which some class template parameter without a default argument never
   // appears in a deduced context).
+  ContextRAII SavedContext(*this, Pattern->getTemplatedDecl());
   llvm::SmallPtrSet 

[clang] Reland "[clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes" (PR #69676)

2023-10-19 Thread via cfe-commits

https://github.com/antangelo created 
https://github.com/llvm/llvm-project/pull/69676

Reland of dd0fba11690f9fef304d5f48cde646e5eca8d3c0

When a nested template is instantiated, the template pattern of the inner class 
is not copied into the outer class
ClassTemplateSpecializationDecl. The specialization contains a 
ClassTemplateDecl with an empty record that points to the original template 
pattern instead.

As a result, when looking up the constructors of the inner class, no results 
are returned. This patch finds the original template pattern and uses that for 
the lookup instead.

Based on CWG2471 we must also substitute the known outer template arguments 
when creating deduction guides for the inner class.

Changes from the last iteration:
1. The outer retained levels from the outer template are always added to the 
`MultiLevelTemplateArgumentList` for rewriting `FunctionTemplateDecl` 
arguments, even if there is no FTD and the arguments are empty.
2. When building implicit deduction guides, the template pattern underlying 
decl is pushed as the current context. This resolves the issue where 
`FindInstantiatedDecl` is unable to find the inner template class.
3. Tests are updated to cover the failing case, and to assert that the type is 
correct after argument deduction in the implicit case. 

>From 7310e2869aeb2d8c225907a908446a80e0b607bc Mon Sep 17 00:00:00 2001
From: antangelo 
Date: Mon, 16 Oct 2023 15:17:36 -0400
Subject: [PATCH] Reland "[clang][Sema] Use original template pattern when
 declaring implicit deduction guides for nested template classes (#68379)"

When a nested template is instantiated, the template pattern of the
inner class is not copied into the outer class
ClassTemplateSpecializationDecl. The specialization contains a
ClassTemplateDecl with an empty record that points to the original
template pattern instead.

As a result, when looking up the constructors of the inner class, no
results are returned. This patch finds the original template pattern and
uses that for the lookup instead.

Based on CWG2471 we must also substitute the known outer template
arguments when creating deduction guides for the inner class.
---
 clang/docs/ReleaseNotes.rst   |  5 
 clang/lib/Sema/SemaTemplate.cpp   | 26 ++-
 .../SemaTemplate/nested-deduction-guides.cpp  |  5 
 .../nested-implicit-deduction-guides.cpp  | 15 +++
 4 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..53a9507fc26613a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -536,6 +536,11 @@ Bug Fixes to C++ Support
   declaration definition. Fixes:
   (`#61763 `_)
 
+- Fix a bug where implicit deduction guides are not correctly generated for 
nested template
+  classes. Fixes:
+  (`#46200 `_)
+  (`#57812 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index f0197f7c102a857..c2477ec0063e418 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2253,6 +2253,7 @@ struct ConvertConstructorToDeductionGuideTransform {
 
   Sema 
   ClassTemplateDecl *Template;
+  ClassTemplateDecl *NestedPattern = nullptr;
 
   DeclContext *DC = Template->getDeclContext();
   CXXRecordDecl *Primary = Template->getTemplatedDecl();
@@ -2332,6 +2333,9 @@ struct ConvertConstructorToDeductionGuideTransform {
   Args.addOuterRetainedLevel();
 }
 
+if (NestedPattern)
+  Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
+
 FunctionProtoTypeLoc FPTL = CD->getTypeSourceInfo()->getTypeLoc()
.getAsAdjusted();
 assert(FPTL && "no prototype for constructor declaration");
@@ -2441,10 +2445,17 @@ struct ConvertConstructorToDeductionGuideTransform {
 SmallVector ParamTypes;
 const FunctionProtoType *T = TL.getTypePtr();
 
+MultiLevelTemplateArgumentList OuterInstantiationArgs;
+if (NestedPattern)
+  OuterInstantiationArgs = SemaRef.getTemplateInstantiationArgs(Template);
+
 //-- The types of the function parameters are those of the constructor.
 for (auto *OldParam : TL.getParams()) {
   ParmVarDecl *NewParam =
   transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
+  if (NestedPattern && NewParam)
+NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs,
+  MaterializedTypedefs);
   if (!NewParam)
 return QualType();
   ParamTypes.push_back(NewParam->getType());
@@ 

[clang] [clang][repl] fix `new` on Mac M1 (PR #69072)

2023-10-19 Thread Maksim Levental via cfe-commits

https://github.com/makslevental updated 
https://github.com/llvm/llvm-project/pull/69072

>From d7c57d94d7e75ed1e0df87ebf3c4464e7b951453 Mon Sep 17 00:00:00 2001
From: max 
Date: Sat, 14 Oct 2023 12:46:42 -0500
Subject: [PATCH 1/3] [clang][repl] fix `new`

---
 clang/lib/Interpreter/Interpreter.cpp | 2 +-
 clang/test/Interpreter/execute.cpp| 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 7968c62cbd3e7b3..ddfbc9ac01c6743 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,7 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-void* operator new(__SIZE_TYPE__, void* __p) noexcept;
+#include 
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
diff --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index 6e73ed3927e8155..d54ab99749c1bac 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -20,4 +20,6 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, 
reinterpret_cast
+
 %quit

>From b3c62d0d295129ad94f94fc641e789038c78f03a Mon Sep 17 00:00:00 2001
From: Maksim Levental 
Date: Sat, 14 Oct 2023 19:26:04 -0500
Subject: [PATCH 2/3] Update clang/lib/Interpreter/Interpreter.cpp

Remove include new

Co-authored-by: Vassil Vassilev 
---
 clang/lib/Interpreter/Interpreter.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index ddfbc9ac01c6743..30348e1c03f8c76 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -248,7 +248,6 @@ Interpreter::~Interpreter() {
 // can't find the precise resource directory in unittests so we have to hard
 // code them.
 const char *const Runtimes = R"(
-#include 
 void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
 void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);

>From 9a071b39c2b31aa9bb1c2dfdd5de139666a06c1d Mon Sep 17 00:00:00 2001
From: max 
Date: Sat, 14 Oct 2023 23:44:01 -0500
Subject: [PATCH 3/3] branch on isdarwin

---
 clang/lib/Interpreter/Interpreter.cpp | 28 +--
 clang/test/Interpreter/ClangReplPrologue.h| 26 +
 clang/test/Interpreter/code-undo.cpp  |  5 +++-
 clang/test/Interpreter/const.cpp  |  6 ++--
 .../Interpreter/disambiguate-decl-stmt.cpp|  6 ++--
 clang/test/Interpreter/dynamic-library.cpp|  4 ++-
 clang/test/Interpreter/execute-stmts.cpp  |  5 ++--
 clang/test/Interpreter/execute-weak.cpp   |  4 ++-
 clang/test/Interpreter/execute.cpp|  7 +++--
 clang/test/Interpreter/fail.cpp   |  5 +++-
 clang/test/Interpreter/global-dtor.cpp|  4 ++-
 clang/test/Interpreter/inline-virtual.cpp |  6 ++--
 clang/test/Interpreter/lambda.cpp |  7 +++--
 clang/test/Interpreter/multiline.cpp  |  4 ++-
 clang/test/Interpreter/plugins.cpp|  4 ++-
 clang/test/Interpreter/simple-exception.cpp   |  4 ++-
 clang/test/Interpreter/stmt-serialization.cpp |  4 ++-
 17 files changed, 81 insertions(+), 48 deletions(-)
 create mode 100644 clang/test/Interpreter/ClangReplPrologue.h

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 30348e1c03f8c76..a249a12b3a1aaf9 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -244,28 +244,6 @@ Interpreter::~Interpreter() {
   }
 }
 
-// These better to put in a runtime header but we can't. This is because we
-// can't find the precise resource directory in unittests so we have to hard
-// code them.
-const char *const Runtimes = R"(
-void *__clang_Interpreter_SetValueWithAlloc(void*, void*, void*);
-void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*);
-void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, void*);
-void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, float);
-void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, double);
-void __clang_Interpreter_SetValueNoAlloc(void*, void*, void*, long double);
-void __clang_Interpreter_SetValueNoAlloc(void*,void*,void*,unsigned long 
long);
-template 
-void __clang_Interpreter_SetValueCopyArr(T* Src, void* Placement, unsigned 
long Size) {
-  for (auto Idx = 0; Idx < Size; ++Idx)
-new ((void*)(((T*)Placement) + Idx)) T(Src[Idx]);
-}
-template 
-void __clang_Interpreter_SetValueCopyArr(const T (*Src)[N], void* 
Placement, unsigned long 

[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-10-19 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

This looks great to me, thanks. @rjmccall should sign off on it though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-19 Thread Brandon Wu via cfe-commits

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


[clang] ✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)

2023-10-19 Thread via cfe-commits

h-vetinari wrote:

JeanHeyd wrote up a [blog 
post](https://thephd.dev/implementing-embed-c-and-c++) about this 
implementation, which is probably helpful as background material for any 
prospective reviewers. :)

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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-19 Thread Craig Topper via cfe-commits

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

LGTM

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


[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow

2023-10-19 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 557798.
MaskRay retitled this revision from "[ItaniumCXXABI] Make __cxa_end_catch calls 
unconditionally nounwind" to "[ItaniumCXXABI] Add 
-fassume-nothrow-exception-dtor to assume that an exception object' destructor 
is nothrow".
MaskRay edited the summary of this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Switch to opt-in

Add -fassume-nothrow-exception-dtor


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108905

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCXX/eh.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/Driver/clang-exception-flags.cpp

Index: clang/test/Driver/clang-exception-flags.cpp
===
--- clang/test/Driver/clang-exception-flags.cpp
+++ clang/test/Driver/clang-exception-flags.cpp
@@ -27,3 +27,6 @@
 // RUN: %clang -### -target x86_64-scei-ps4 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // RUN: %clang -### -target x86_64-sie-ps5 %s 2>&1 | FileCheck %s -check-prefix=PS-OFF
 // PS-OFF-NOT: "-cc1" {{.*}} "-f{{(cxx-)?}}exceptions"
+
+// RUN: %clang -### -fexceptions -fno-assume-nothrow-exception-dtor -fassume-nothrow-exception-dtor %s 2>&1 | FileCheck %s --check-prefix=NOTHROW-DTOR
+// NOTHROW-DTOR: "-cc1"{{.*}} "-fcxx-exceptions" "-fassume-nothrow-exception-dtor"
Index: clang/test/CodeGenCoroutines/coro-cleanup.cpp
===
--- clang/test/CodeGenCoroutines/coro-cleanup.cpp
+++ clang/test/CodeGenCoroutines/coro-cleanup.cpp
@@ -1,5 +1,6 @@
 // Verify that coroutine promise and allocated memory are freed up on exception.
-// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,THROWEND
+// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -fassume-nothrow-exception-dtor -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,NOTHROWEND
 
 namespace std {
 template  struct coroutine_traits;
@@ -49,7 +50,9 @@
   // CHECK: [[DeallocPad]]:
   // CHECK-NEXT: landingpad
   // CHECK-NEXT:   cleanup
-  // CHECK: br label %[[Dealloc:.+]]
+  // THROWEND:br label %[[Dealloc:.+]]
+  // NOTHROWEND:  icmp ne ptr %[[#]], null
+  // NOTHROWEND-NEXT: br i1 %[[#]], label %[[Dealloc:.+]], label
 
   Cleanup cleanup;
   may_throw();
@@ -64,17 +67,18 @@
   // CHECK-NEXT:   catch ptr null
   // CHECK:  call void @_ZN7CleanupD1Ev(
   // CHECK:  br label %[[Catch:.+]]
-
   // CHECK: [[Catch]]:
   // CHECK:call ptr @__cxa_begin_catch(
   // CHECK:call void @_ZNSt16coroutine_traitsIJvEE12promise_type19unhandled_exceptionEv(
-  // CHECK:invoke void @__cxa_end_catch()
-  // CHECK-NEXT:to label %[[Cont:.+]] unwind
+  // THROWEND:invoke void @__cxa_end_catch()
+  // THROWEND-NEXT: to label %[[Cont:.+]] unwind
+  // NOTHROWEND:  call void @__cxa_end_catch()
+  // NOTHROWEND-NEXT:   br label %[[Cont2:.+]]
 
-  // CHECK: [[Cont]]:
-  // CHECK-NEXT: br label %[[Cont2:.+]]
-  // CHECK: [[Cont2]]:
-  // CHECK-NEXT: br label %[[Cleanup:.+]]
+  // THROWEND: [[Cont]]:
+  // THROWEND-NEXT:   br label %[[Cont2:.+]]
+  // CHECK:[[Cont2]]:
+  // CHECK-NEXT:br label %[[Cleanup:.+]]
 
   // CHECK: [[Cleanup]]:
   // CHECK: call void @_ZNSt16coroutine_traitsIJvEE12promise_typeD1Ev(
@@ -82,8 +86,8 @@
   // CHECK: call void @_ZdlPv(ptr noundef %[[Mem0]]
 
   // CHECK: [[Dealloc]]:
-  // CHECK:   %[[Mem:.+]] = call ptr @llvm.coro.free(
-  // CHECK:   call void @_ZdlPv(ptr noundef %[[Mem]])
+  // THROWEND:   %[[Mem:.+]] = call ptr @llvm.coro.free(
+  // THROWEND:   call void @_ZdlPv(ptr noundef %[[Mem]])
 
   co_return;
 }
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++98 -o - -fcxx-exceptions -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s
-// RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++11 -o - -fcxx-exceptions -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis %s -triple=x86_64-linux-gnu -emit-llvm -std=c++11 -o - -fcxx-exceptions -fexceptions | FileCheck 

[clang-tools-extra] [FixBUG][llvm-tblgen] : The correct td file ending with #endif cannot be compiled (PR #69411)

2023-10-19 Thread zhao jiangtao via cfe-commits

https://github.com/whousemyname updated 
https://github.com/llvm/llvm-project/pull/69411

>From 043d29cd597a7447037286293fe1a1b3ccf8d79d Mon Sep 17 00:00:00 2001
From: angryZ 
Date: Wed, 18 Oct 2023 10:39:56 +0800
Subject: [PATCH] [llvm][Tablegen][BUG] : The correct td file ending with
 #endif (there are no other characters after #endif, including newlines) still
 cannot be compiled. This PR is to solve this bug.

---
 llvm/lib/TableGen/TGLexer.cpp | 52 +--
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index d5140e91fce9e94..697441abf2a 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -346,31 +346,31 @@ tgtok::TokKind TGLexer::LexIdentifier() {
   StringRef Str(IdentStart, CurPtr-IdentStart);
 
   tgtok::TokKind Kind = StringSwitch(Str)
-.Case("int", tgtok::Int)
-.Case("bit", tgtok::Bit)
-.Case("bits", tgtok::Bits)
-.Case("string", tgtok::String)
-.Case("list", tgtok::List)
-.Case("code", tgtok::Code)
-.Case("dag", tgtok::Dag)
-.Case("class", tgtok::Class)
-.Case("def", tgtok::Def)
-.Case("true", tgtok::TrueVal)
-.Case("false", tgtok::FalseVal)
-.Case("foreach", tgtok::Foreach)
-.Case("defm", tgtok::Defm)
-.Case("defset", tgtok::Defset)
-.Case("multiclass", tgtok::MultiClass)
-.Case("field", tgtok::Field)
-.Case("let", tgtok::Let)
-.Case("in", tgtok::In)
-.Case("defvar", tgtok::Defvar)
-.Case("include", tgtok::Include)
-.Case("if", tgtok::If)
-.Case("then", tgtok::Then)
-.Case("else", tgtok::ElseKW)
-.Case("assert", tgtok::Assert)
-.Default(tgtok::Id);
+.Case("int", tgtok::Int)
+.Case("bit", tgtok::Bit)
+.Case("bits", tgtok::Bits)
+.Case("string", tgtok::String)
+.Case("list", tgtok::List)
+.Case("code", tgtok::Code)
+.Case("dag", tgtok::Dag)
+.Case("class", tgtok::Class)
+.Case("def", tgtok::Def)
+.Case("true", tgtok::TrueVal)
+.Case("false", tgtok::FalseVal)
+.Case("foreach", tgtok::Foreach)
+.Case("defm", tgtok::Defm)
+.Case("defset", tgtok::Defset)
+.Case("multiclass", tgtok::MultiClass)
+.Case("field", tgtok::Field)
+.Case("let", tgtok::Let)
+.Case("in", tgtok::In)
+.Case("defvar", tgtok::Defvar)
+.Case("include", tgtok::Include)
+.Case("if", tgtok::If)
+.Case("then", tgtok::Then)
+.Case("else", tgtok::ElseKW)
+.Case("assert", tgtok::Assert)
+.Default(tgtok::Id);
 
   // A couple of tokens require special processing.
   switch (Kind) {
@@ -664,7 +664,7 @@ tgtok::TokKind TGLexer::prepIsDirective() const {
   // It looks like TableGen does not support '\r' as the actual
   // carriage return, e.g. getNextChar() treats a single '\r'
   // as '\n'.  So we do the same here.
-  NextChar == '\r')
+  NextChar == '\r' || NextChar == '\0')
 return Kind;
 
   // Allow comments after some directives, e.g.:

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


[clang] [FixBUG][llvm-tblgen] : The correct td file ending with #endif cannot be compiled (PR #69411)

2023-10-19 Thread zhao jiangtao via cfe-commits

https://github.com/whousemyname updated 
https://github.com/llvm/llvm-project/pull/69411

>From 043d29cd597a7447037286293fe1a1b3ccf8d79d Mon Sep 17 00:00:00 2001
From: angryZ 
Date: Wed, 18 Oct 2023 10:39:56 +0800
Subject: [PATCH] [llvm][Tablegen][BUG] : The correct td file ending with
 #endif (there are no other characters after #endif, including newlines) still
 cannot be compiled. This PR is to solve this bug.

---
 llvm/lib/TableGen/TGLexer.cpp | 52 +--
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index d5140e91fce9e94..697441abf2a 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -346,31 +346,31 @@ tgtok::TokKind TGLexer::LexIdentifier() {
   StringRef Str(IdentStart, CurPtr-IdentStart);
 
   tgtok::TokKind Kind = StringSwitch(Str)
-.Case("int", tgtok::Int)
-.Case("bit", tgtok::Bit)
-.Case("bits", tgtok::Bits)
-.Case("string", tgtok::String)
-.Case("list", tgtok::List)
-.Case("code", tgtok::Code)
-.Case("dag", tgtok::Dag)
-.Case("class", tgtok::Class)
-.Case("def", tgtok::Def)
-.Case("true", tgtok::TrueVal)
-.Case("false", tgtok::FalseVal)
-.Case("foreach", tgtok::Foreach)
-.Case("defm", tgtok::Defm)
-.Case("defset", tgtok::Defset)
-.Case("multiclass", tgtok::MultiClass)
-.Case("field", tgtok::Field)
-.Case("let", tgtok::Let)
-.Case("in", tgtok::In)
-.Case("defvar", tgtok::Defvar)
-.Case("include", tgtok::Include)
-.Case("if", tgtok::If)
-.Case("then", tgtok::Then)
-.Case("else", tgtok::ElseKW)
-.Case("assert", tgtok::Assert)
-.Default(tgtok::Id);
+.Case("int", tgtok::Int)
+.Case("bit", tgtok::Bit)
+.Case("bits", tgtok::Bits)
+.Case("string", tgtok::String)
+.Case("list", tgtok::List)
+.Case("code", tgtok::Code)
+.Case("dag", tgtok::Dag)
+.Case("class", tgtok::Class)
+.Case("def", tgtok::Def)
+.Case("true", tgtok::TrueVal)
+.Case("false", tgtok::FalseVal)
+.Case("foreach", tgtok::Foreach)
+.Case("defm", tgtok::Defm)
+.Case("defset", tgtok::Defset)
+.Case("multiclass", tgtok::MultiClass)
+.Case("field", tgtok::Field)
+.Case("let", tgtok::Let)
+.Case("in", tgtok::In)
+.Case("defvar", tgtok::Defvar)
+.Case("include", tgtok::Include)
+.Case("if", tgtok::If)
+.Case("then", tgtok::Then)
+.Case("else", tgtok::ElseKW)
+.Case("assert", tgtok::Assert)
+.Default(tgtok::Id);
 
   // A couple of tokens require special processing.
   switch (Kind) {
@@ -664,7 +664,7 @@ tgtok::TokKind TGLexer::prepIsDirective() const {
   // It looks like TableGen does not support '\r' as the actual
   // carriage return, e.g. getNextChar() treats a single '\r'
   // as '\n'.  So we do the same here.
-  NextChar == '\r')
+  NextChar == '\r' || NextChar == '\0')
 return Kind;
 
   // Allow comments after some directives, e.g.:

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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-19 Thread Brandon Wu via cfe-commits


@@ -476,6 +524,31 @@ class GetFTypeInfo {
   !eq(Scalar, f64) : "FPR64");
 }
 
+multiclass VPatVMACC info_pairs, ValueType vec_m1> {
+  foreach pair = info_pairs in {
+defvar VdInfo = pair.Wti;
+defvar Vs2Info = pair.Vti;
+let Predicates = [HasVInstructions] in
+def : VPatTernaryNoMaskWithPolicy<"int_riscv_sf_" # intrinsic,
+  "Pseudo" # instruction, kind, 
VdInfo.Vector,
+  vec_m1, Vs2Info.Vector,
+  Vs2Info.Log2SEW, Vs2Info.LMul,
+  VdInfo.RegClass, VR, Vs2Info.RegClass>;
+  }
+}
+
+defset list VQMACCInfoPairs = {
+  def : VTypeInfoToWide;
+  def : VTypeInfoToWide;
+  def : VTypeInfoToWide;
+  def : VTypeInfoToWide;
+}
+
+multiclass VPatVQMACC {
+  defm : VPatVMACC;

4vtomat wrote:

Sure~

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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-19 Thread Brandon Wu via cfe-commits


@@ -558,6 +558,12 @@ DecodeStatus RISCVDisassembler::getInstruction(MCInst , 
uint64_t ,
   "XTHeadVdot custom opcode table");
 TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfvcp, DecoderTableXSfvcp32,
   "SiFive VCIX custom opcode table");
+TRY_TO_DECODE_FEATURE(
+RISCV::FeatureVendorXSfvqmaccdod, DecoderTableXSfvqmaccdod32,
+"SiFive Matrix Multiplication Instruction opcode table");
+TRY_TO_DECODE_FEATURE(
+RISCV::FeatureVendorXSfvqmaccqoq, DecoderTableXSfvqmaccqoq32,
+"SiFive Matrix Multiplication Instruction opcode table");

4vtomat wrote:

Got it~

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


[clang] Let clang-cl support CUDA/HIP (PR #68921)

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

yxsamliu wrote:

[AMD Official Use Only - General]

Fixed by 9d10fbbb299eae4a63f1028274e2ffe92bf8e75a

From: Nico Weber ***@***.***>
Sent: Thursday, October 19, 2023 8:03 PM
To: llvm/llvm-project ***@***.***>
Cc: Liu, Yaxun (Sam) ***@***.***>; State change ***@***.***>
Subject: Re: [llvm/llvm-project] Let clang-cl support CUDA/HIP (PR #68921)

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.


Hello, it looks like this breaks check-clang on mac: 
http://45.33.8.238/macm1/71368/step_7.txt

Please take a look and revert for now if it takes a while to fix.

—
Reply to this email directly, view it on 
GitHub,
 or 
unsubscribe.
You are receiving this because you modified the open/close state.Message ID: 
***@***.**@***.***>>


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


[clang] 9d10fbb - Fix test clang/test/Driver/cl-offload.cu

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

Author: Yaxun (Sam) Liu
Date: 2023-10-19T21:48:05-04:00
New Revision: 9d10fbbb299eae4a63f1028274e2ffe92bf8e75a

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

LOG: Fix test clang/test/Driver/cl-offload.cu

Exclude it from Darwin since /Users will be treated as a MSVC option.

http://45.33.8.238/macm1/71368/step_7.txt

Added: 


Modified: 
clang/test/Driver/cl-offload.cu

Removed: 




diff  --git a/clang/test/Driver/cl-offload.cu b/clang/test/Driver/cl-offload.cu
index c3bc5a2c08275e0..ec1d8ba54954a44 100644
--- a/clang/test/Driver/cl-offload.cu
+++ b/clang/test/Driver/cl-offload.cu
@@ -1,3 +1,7 @@
+// REQUIRES: !system-darwin
+
+// The test cannot be run on Darwin because /Users will be treated as a MSVC 
option.
+
 // RUN: %clang_cl -### -target x86_64-pc-windows-msvc --offload-arch=sm_35 
-fgpu-rdc \
 // RUN:   --cuda-path=%S/Inputs/CUDA/usr/local/cuda \
 // RUN:   /Wall -x cuda %s 2>&1 \



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


[clang] [X86][AMX] remove related code of X86PreAMXConfigPass (PR #69569)

2023-10-19 Thread Kazu Hirata via cfe-commits

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

LGTM.  Thanks!

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


[clang] Let clang-cl support CUDA/HIP (PR #68921)

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

yxsamliu wrote:

[AMD Official Use Only - General]

Will fix it now. Thanks.

Sam

From: Nico Weber ***@***.***>
Sent: Thursday, October 19, 2023 8:03 PM
To: llvm/llvm-project ***@***.***>
Cc: Liu, Yaxun (Sam) ***@***.***>; State change ***@***.***>
Subject: Re: [llvm/llvm-project] Let clang-cl support CUDA/HIP (PR #68921)

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.


Hello, it looks like this breaks check-clang on mac: 
http://45.33.8.238/macm1/71368/step_7.txt

Please take a look and revert for now if it takes a while to fix.

—
Reply to this email directly, view it on 
GitHub,
 or 
unsubscribe.
You are receiving this because you modified the open/close state.Message ID: 
***@***.**@***.***>>


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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-19 Thread Owen Pan via cfe-commits


@@ -491,11 +491,19 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   SmallVector LBraceStack;
   assert(Tok->is(tok::l_brace));
   do {
-// Get next non-comment token.
-FormatToken *NextTok;
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->is(tok::comment));
+// Get next non-comment, non-preprocessor token.
+FormatToken *NextTok = Tokens->getNextToken();
+while (NextTok->is(tok::comment) ||
+   (NextTok->is(tok::hash) && isOnNewLine(*NextTok))) {
+  while (NextTok->is(tok::comment))
+NextTok = Tokens->getNextToken();
+  while (NextTok->is(tok::hash) && isOnNewLine(*NextTok)) {
+ScopedMacroState MacroState(*Line, Tokens, NextTok);
+do {
+  NextTok = Tokens->getNextToken();
+} while (NextTok->isNot(tok::eof));
+  }
+}

owenca wrote:

Tested on the following case without `isOnNewLine()`:
```
struct Foo {
  Foo() : a(2) {
#define FOO(foo) \
  /* foo */ #foo
  }

  Foo +=(const Foo &) {
return *this;
  }
};
```
Also works if the comment is deleted.

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-19 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-19 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-19 Thread Owen Pan via cfe-commits


@@ -491,11 +491,19 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   SmallVector LBraceStack;
   assert(Tok->is(tok::l_brace));
   do {
-// Get next non-comment token.
-FormatToken *NextTok;
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->is(tok::comment));
+// Get next non-comment, non-preprocessor token.
+FormatToken *NextTok = Tokens->getNextToken();
+while (NextTok->is(tok::comment) ||
+   (NextTok->is(tok::hash) && isOnNewLine(*NextTok))) {
+  while (NextTok->is(tok::comment))
+NextTok = Tokens->getNextToken();
+  while (NextTok->is(tok::hash) && isOnNewLine(*NextTok)) {
+ScopedMacroState MacroState(*Line, Tokens, NextTok);
+do {
+  NextTok = Tokens->getNextToken();
+} while (NextTok->isNot(tok::eof));
+  }
+}

owenca wrote:

Can you give a valid C/C++ example? As far as I know, you can't have `#` after 
`{`.

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-19 Thread Emilia Kond via cfe-commits


@@ -491,11 +491,19 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   SmallVector LBraceStack;
   assert(Tok->is(tok::l_brace));
   do {
-// Get next non-comment token.
-FormatToken *NextTok;
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->is(tok::comment));
+// Get next non-comment, non-preprocessor token.
+FormatToken *NextTok = Tokens->getNextToken();
+while (NextTok->is(tok::comment) ||
+   (NextTok->is(tok::hash) && isOnNewLine(*NextTok))) {
+  while (NextTok->is(tok::comment))
+NextTok = Tokens->getNextToken();
+  while (NextTok->is(tok::hash) && isOnNewLine(*NextTok)) {
+ScopedMacroState MacroState(*Line, Tokens, NextTok);
+do {
+  NextTok = Tokens->getNextToken();
+} while (NextTok->isNot(tok::eof));
+  }
+}

rymiel wrote:

removing isOnNewLine causes test failures containing macro stringizing 
operators (which also uses `#`)

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


[clang] [Windows] Add git-clang-format wrapper bat file (PR #69228)

2023-10-19 Thread Owen Pan via cfe-commits

owenca wrote:

@mydeveloperday what do you think?

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


[clang] Let clang-cl support CUDA/HIP (PR #68921)

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

nico wrote:

Hello, it looks like this breaks check-clang on mac: 
http://45.33.8.238/macm1/71368/step_7.txt

Please take a look and revert for now if it takes a while to fix.

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


[clang] [clang][repl] fix `new` on Mac M1 (PR #69072)

2023-10-19 Thread Vassil Vassilev via cfe-commits


@@ -275,7 +274,14 @@ Interpreter::create(std::unique_ptr CI) {
   if (Err)
 return std::move(Err);
 
-  auto PTU = Interp->Parse(Runtimes);
+  std::string runtimes = "";
+  if (llvm::Triple(llvm::sys::getProcessTriple()).isOSDarwin())
+runtimes += "#include \n";

vgvassilev wrote:

I think I understand. One way out would be to move that call of new into a new 
function whose definition is available only at compile time, forward declare it 
uniformly here and use it. 

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


[clang] [llvm] Use XMACROS for MachO platforms. (PR #69262)

2023-10-19 Thread Juergen Ributzka via cfe-commits

https://github.com/ributzka updated 
https://github.com/llvm/llvm-project/pull/69262

>From ceaf58ba2f752b8a5353568013ff18603b0e615b Mon Sep 17 00:00:00 2001
From: Juergen Ributzka 
Date: Mon, 28 Aug 2023 15:25:48 -0700
Subject: [PATCH] [llvm] Use XMACROS for MachO platforms.

This change adds the PLATFORM XMACRO to simplify the addition of new MachO
platforms and reduce the number of required changes. Many of the changes needed
for adding a new platform are mechanical, such as adding new cases to a switch
statement. This will help streamline the process by consolidating much of the
necessary information into the MachO.def file.
---
 clang/lib/CodeGen/CGObjC.cpp |  2 +-
 llvm/include/llvm/BinaryFormat/MachO.def | 16 +
 llvm/include/llvm/BinaryFormat/MachO.h   | 15 +++--
 llvm/include/llvm/Object/MachO.h | 15 +++--
 llvm/lib/MC/MCAsmStreamer.cpp| 17 +++---
 llvm/lib/MC/MCParser/DarwinAsmParser.cpp | 15 -
 llvm/lib/TextAPI/Platform.cpp| 41 ++--
 llvm/lib/TextAPI/Target.cpp  | 14 +++-
 llvm/lib/TextAPI/TextStub.cpp| 39 --
 9 files changed, 57 insertions(+), 117 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 6c594b5db4bca1f..aa3a0ff57003d7c 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -3954,7 +3954,7 @@ static unsigned getBaseMachOPlatformID(const llvm::Triple 
) {
   case llvm::Triple::DriverKit:
 return llvm::MachO::PLATFORM_DRIVERKIT;
   default:
-return /*Unknown platform*/ 0;
+return llvm::MachO::PLATFORM_UNKNOWN;
   }
 }
 
diff --git a/llvm/include/llvm/BinaryFormat/MachO.def 
b/llvm/include/llvm/BinaryFormat/MachO.def
index d841b42ee808b2e..df527b4a8ab7c3c 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.def
+++ b/llvm/include/llvm/BinaryFormat/MachO.def
@@ -120,5 +120,21 @@ LOAD_COMMAND_STRUCT(fileset_entry_command)
 
 #endif
 
+#ifdef PLATFORM
+// PLATFORM(platform, id, name, build_name, target, tapi_target, marketing)
+PLATFORM(UNKNOWN, 0, unknown, unknown, unknown, unknown, unknown)
+PLATFORM(MACOS, 1, macos, macos, macos, macos, macOS)
+PLATFORM(IOS, 2, ios, ios, ios, ios, iOS)
+PLATFORM(TVOS, 3, tvos, tvos, tvos, tvos, tvOS)
+PLATFORM(WATCHOS, 4, watchos, watchos, watchos, watchos, watchOS)
+PLATFORM(BRIDGEOS, 5, bridgeos, bridgeos, bridgeos, bridgeos, bridgeOS)
+PLATFORM(MACCATALYST, 6, macCatalyst, macCatalyst, ios-macabi, maccatalyst, 
macCatalyst)
+PLATFORM(IOSSIMULATOR, 7, iossimulator, iossimulator, ios-simulator, 
ios-simulator, iOS Simulator)
+PLATFORM(TVOSSIMULATOR, 8, tvossimulator, tvossimulator, tvos-simulator, 
tvos-simulator, tvOS Simulator)
+PLATFORM(WATCHOSSIMULATOR, 9, watchossimulator, watchossimulator, 
watchos-simulator, watchos-simulator, watchOS Simulator)
+PLATFORM(DRIVERKIT, 10, driverkit, driverkit, driverkit, driverkit, DriverKit)
+#endif
+
 #undef HANDLE_LOAD_COMMAND
 #undef LOAD_COMMAND_STRUCT
+#undef PLATFORM
diff --git a/llvm/include/llvm/BinaryFormat/MachO.h 
b/llvm/include/llvm/BinaryFormat/MachO.h
index f59cd14c1b5c055..49991ebe7bfaf27 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.h
+++ b/llvm/include/llvm/BinaryFormat/MachO.h
@@ -497,17 +497,10 @@ enum { VM_PROT_READ = 0x1, VM_PROT_WRITE = 0x2, 
VM_PROT_EXECUTE = 0x4 };
 
 // Values for platform field in build_version_command.
 enum PlatformType {
-  PLATFORM_UNKNOWN = 0,
-  PLATFORM_MACOS = 1,
-  PLATFORM_IOS = 2,
-  PLATFORM_TVOS = 3,
-  PLATFORM_WATCHOS = 4,
-  PLATFORM_BRIDGEOS = 5,
-  PLATFORM_MACCATALYST = 6,
-  PLATFORM_IOSSIMULATOR = 7,
-  PLATFORM_TVOSSIMULATOR = 8,
-  PLATFORM_WATCHOSSIMULATOR = 9,
-  PLATFORM_DRIVERKIT = 10,
+#define PLATFORM(platform, id, name, build_name, target, tapi_target,  
\
+ marketing)
\
+  PLATFORM_##platform = id,
+#include "MachO.def"
 };
 
 // Values for tools enum in build_tool_version.
diff --git a/llvm/include/llvm/Object/MachO.h b/llvm/include/llvm/Object/MachO.h
index 894252db538f9e7..f91f21d837ce7b1 100644
--- a/llvm/include/llvm/Object/MachO.h
+++ b/llvm/include/llvm/Object/MachO.h
@@ -789,16 +789,11 @@ class MachOObjectFile : public ObjectFile {
 
   static std::string getBuildPlatform(uint32_t platform) {
 switch (platform) {
-case MachO::PLATFORM_MACOS: return "macos";
-case MachO::PLATFORM_IOS: return "ios";
-case MachO::PLATFORM_TVOS: return "tvos";
-case MachO::PLATFORM_WATCHOS: return "watchos";
-case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
-case MachO::PLATFORM_MACCATALYST: return "macCatalyst";
-case MachO::PLATFORM_IOSSIMULATOR: return "iossimulator";
-case MachO::PLATFORM_TVOSSIMULATOR: return "tvossimulator";
-case MachO::PLATFORM_WATCHOSSIMULATOR: return "watchossimulator";
-case MachO::PLATFORM_DRIVERKIT: return "driverkit";
+#define PLATFORM(platform, id, name, build_name, target, tapi_target,  

[clang-tools-extra] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-19 Thread Matheus Izvekov via cfe-commits


@@ -153,6 +153,67 @@ Please run this, then file a bug with the instructions and 
reduced .bc file
 that bugpoint emits.  If something goes wrong with bugpoint, please submit
 the "foo.bc" file and the option that llc crashes with.
 
+LTO bugs
+---
+
+If you encounter a bug that leads to crashes in the LLVM LTO phase when using
+the `-flto` option, follow these steps to diagnose and report the issue:
+
+Compile your source file to a .bc (Bitcode) file with the following flags,
+in addition to your existing compilation options:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" 
LDFLAGS="-Wl,-plugin-opt=save-temps"
+
+These flags enable LTO and save temporary files generated during compilation
+for later analysis.
+
+On Windows, you should use lld-link as the linker. Adjust your compilation 
+flags as follows:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld-link" CXXFLAGS="-flto -fuse-ld=lld-link" 
LDFLAGS="-Wl,-plugin-opt=save-temps"

mizvekov wrote:

Does this actually work? The option is spelled `/lldsavetemps` in the COFF 
linker.

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


[clang] [llvm] Use XMACROS for MachO platforms. (PR #69262)

2023-10-19 Thread Juergen Ributzka via cfe-commits

ributzka wrote:

Unrelated build issue on windows:
C:\ws\src\mlir\include\mlir/IR/BuiltinTypeInterfaces.h(14): fatal error C1083: 
Cannot open include file: 'mlir/IR/BuiltinTypeInterfaces.h.inc': No such file 
or directory

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-19 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-19 Thread Owen Pan via cfe-commits

owenca wrote:

> Here's my solution to one of the regressions I caused (#68404)

I don't think it's a regression. On the contrary, it actually exposed another 
bug. :)


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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-19 Thread Owen Pan via cfe-commits


@@ -491,11 +491,19 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   SmallVector LBraceStack;
   assert(Tok->is(tok::l_brace));
   do {
-// Get next non-comment token.
-FormatToken *NextTok;
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->is(tok::comment));
+// Get next non-comment, non-preprocessor token.
+FormatToken *NextTok = Tokens->getNextToken();
+while (NextTok->is(tok::comment) ||
+   (NextTok->is(tok::hash) && isOnNewLine(*NextTok))) {
+  while (NextTok->is(tok::comment))
+NextTok = Tokens->getNextToken();
+  while (NextTok->is(tok::hash) && isOnNewLine(*NextTok)) {
+ScopedMacroState MacroState(*Line, Tokens, NextTok);
+do {
+  NextTok = Tokens->getNextToken();
+} while (NextTok->isNot(tok::eof));
+  }
+}

owenca wrote:

```suggestion
while (NextTok->is(tok::hash)) {
  NextTok = Tokens->getNextToken();
  do {
NextTok = Tokens->getNextToken();
  } while (NextTok->is(tok::comment) || (NextTok->NewlinesBefore == 0 &&
 NextTok->isNot(tok::eof)));
} while(NextTok->is(tok::hash));
```
And keep the deleted lines (494-498).

I don't think we need to (or should) use `isOnNewLine()` as it might miss 
PPDirective lines started with block comments.

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


[clang] [Modules] textual headers in submodules never resolve their `use`s (PR #69651)

2023-10-19 Thread Michael Spencer via cfe-commits

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

LGTM. The rest of clang reasons about this at the top level module, so so 
should this.

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


[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/69649

>From 0c57e45f6ee16e43cc6388b1ca6beb88bbc7b925 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 19 Oct 2023 22:23:03 +
Subject: [PATCH 1/3] Update stdckdint.h and make it available in pre-C23
 modes.

Update some tests and docs.
---
 clang/docs/ReleaseNotes.rst| 2 +-
 clang/lib/Headers/stdckdint.h  | 4 
 clang/test/C/C2x/n2359.c   | 5 -
 clang/test/C/C2x/n2683.c   | 1 +
 clang/test/C/C2x/n2683_2.c | 1 +
 clang/test/Headers/stdckdint.c | 7 +--
 6 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..d0de52a5bf122f4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,7 @@ C23 Feature Support
 - Clang now supports ``N3007 Type inference for object definitions``.
 
 - Clang now supports  which defines several macros for 
performing
-  checked integer arithmetic.
+  checked integer arithmetic. And it is also exposed in pre-C23 modes.
 
 Non-comprehensive list of changes in this release
 -
diff --git a/clang/lib/Headers/stdckdint.h b/clang/lib/Headers/stdckdint.h
index 22972d78d9077a4..77290b260ff3bd4 100644
--- a/clang/lib/Headers/stdckdint.h
+++ b/clang/lib/Headers/stdckdint.h
@@ -21,9 +21,6 @@
 
 /* C23 7.20.1 Defines several macros for performing checked integer 
arithmetic*/
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
-#define __STDC_VERSION_STDCKDINT_H__ 202311L
-
 // Both A and B shall be any integer type other than "plain" char, bool, a bit-
 // precise integer type, or an enumerated type, and they need not be the same.
 
@@ -38,7 +35,6 @@
 #define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R))
 #define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (R))
 #define ckd_mul(R, A, B) __builtin_mul_overflow((A), (B), (R))
-#endif
 
 #endif /* __STDC_HOSTED__ */
 #endif /* __STDCKDINT_H */
diff --git a/clang/test/C/C2x/n2359.c b/clang/test/C/C2x/n2359.c
index dc38bab43c9db8d..0a1b801e505e146 100644
--- a/clang/test/C/C2x/n2359.c
+++ b/clang/test/C/C2x/n2359.c
@@ -33,8 +33,3 @@
 #error "__STDC_VERSION_STDINT_H__ not defined"
 // expected-error@-1 {{"__STDC_VERSION_STDINT_H__ not defined"}}
 #endif
-
-#include 
-#ifndef __STDC_VERSION_STDCKDINT_H__
-#error "__STDC_VERSION_STDCKDINT_H__ not defined"
-#endif
diff --git a/clang/test/C/C2x/n2683.c b/clang/test/C/C2x/n2683.c
index 0c666c5fd8782ba..a785d46c063c2cc 100644
--- a/clang/test/C/C2x/n2683.c
+++ b/clang/test/C/C2x/n2683.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c2x %s
 // RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c23 %s
 
 /* WG14 N2683: Clang 18
diff --git a/clang/test/C/C2x/n2683_2.c b/clang/test/C/C2x/n2683_2.c
index 247f6de8fe4bfe1..867d6b876cf0d9d 100644
--- a/clang/test/C/C2x/n2683_2.c
+++ b/clang/test/C/C2x/n2683_2.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c2x %s | FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
 
 #include 
diff --git a/clang/test/Headers/stdckdint.c b/clang/test/Headers/stdckdint.c
index 896c740360065b6..7774cecfa7c3317 100644
--- a/clang/test/Headers/stdckdint.c
+++ b/clang/test/Headers/stdckdint.c
@@ -1,12 +1,15 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c99 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c11 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c17 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c2x %s -o - | 
FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | 
FileCheck %s
 
 // expected-no-diagnostics
 
+#include 
 #include 
 
-_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");
-
 // CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add(
 // CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:

>From 4e2fd920121b15e014a6146c6c6672973bae4443 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 19 Oct 2023 22:23:03 +
Subject: [PATCH 2/3] Update stdckdint.h and make it available in pre-C23
 modes.

Update some tests and docs.
---
 clang/docs/ReleaseNotes.rst   | 2 +-
 clang/lib/Headers/stdckdint.h | 4 
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0de52a5bf122f4..1b1f25ae244ef9f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,7 @@ C23 Feature Support
 - Clang 

[clang] [Modules] textual headers in submodules never resolve their `use`s (PR #69651)

2023-10-19 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder updated 
https://github.com/llvm/llvm-project/pull/69651

>From 7b88bf3102240d1734feab8919a049f8a92ca0e0 Mon Sep 17 00:00:00 2001
From: Ian Anderson 
Date: Thu, 19 Oct 2023 15:22:11 -0700
Subject: [PATCH] [Modules] textual headers in submodules never resolve their
 `use`s

When an include from a textual header is resolved, the textual header's 
submodule is used as the requesting module. The submodule's uses are resolved, 
but that doesn't work because only top level modules have uses, and only the 
top level module uses are used for checking uses in Module::directlyUses. 
ModuleMap::resolveUses to resolve the top level module instead of the submodule.
---
 clang/lib/Lex/ModuleMap.cpp | 13 +
 clang/test/Modules/no-undeclared-includes.c | 31 +
 2 files changed, 38 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/Modules/no-undeclared-includes.c

diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index f65a5f145c04395..259c97796ae19f2 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1398,16 +1398,17 @@ bool ModuleMap::resolveExports(Module *Mod, bool 
Complain) {
 }
 
 bool ModuleMap::resolveUses(Module *Mod, bool Complain) {
-  auto Unresolved = std::move(Mod->UnresolvedDirectUses);
-  Mod->UnresolvedDirectUses.clear();
+  auto *Top = Mod->getTopLevelModule();
+  auto Unresolved = std::move(Top->UnresolvedDirectUses);
+  Top->UnresolvedDirectUses.clear();
   for (auto  : Unresolved) {
-Module *DirectUse = resolveModuleId(UDU, Mod, Complain);
+Module *DirectUse = resolveModuleId(UDU, Top, Complain);
 if (DirectUse)
-  Mod->DirectUses.push_back(DirectUse);
+  Top->DirectUses.push_back(DirectUse);
 else
-  Mod->UnresolvedDirectUses.push_back(UDU);
+  Top->UnresolvedDirectUses.push_back(UDU);
   }
-  return !Mod->UnresolvedDirectUses.empty();
+  return !Top->UnresolvedDirectUses.empty();
 }
 
 bool ModuleMap::resolveConflicts(Module *Mod, bool Complain) {
diff --git a/clang/test/Modules/no-undeclared-includes.c 
b/clang/test/Modules/no-undeclared-includes.c
new file mode 100644
index 000..83a654f6ed77539
--- /dev/null
+++ b/clang/test/Modules/no-undeclared-includes.c
@@ -0,0 +1,31 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I 
%t %t/no-undeclared-includes.c -verify
+
+//--- no-undeclared-includes.c
+// expected-no-diagnostics
+#include 
+
+//--- assert.h
+#include 
+
+//--- base.h
+#ifndef base_h
+#define base_h
+
+
+
+#endif /* base_h */
+
+//--- module.modulemap
+module cstd [system] [no_undeclared_includes] {
+  use base
+  module assert {
+textual header "assert.h"
+  }
+}
+
+module base [system] {
+  header "base.h"
+  export *
+}

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


[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/69649

>From 0c57e45f6ee16e43cc6388b1ca6beb88bbc7b925 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 19 Oct 2023 22:23:03 +
Subject: [PATCH 1/2] Update stdckdint.h and make it available in pre-C23
 modes.

Update some tests and docs.
---
 clang/docs/ReleaseNotes.rst| 2 +-
 clang/lib/Headers/stdckdint.h  | 4 
 clang/test/C/C2x/n2359.c   | 5 -
 clang/test/C/C2x/n2683.c   | 1 +
 clang/test/C/C2x/n2683_2.c | 1 +
 clang/test/Headers/stdckdint.c | 7 +--
 6 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..d0de52a5bf122f4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,7 @@ C23 Feature Support
 - Clang now supports ``N3007 Type inference for object definitions``.
 
 - Clang now supports  which defines several macros for 
performing
-  checked integer arithmetic.
+  checked integer arithmetic. And it is also exposed in pre-C23 modes.
 
 Non-comprehensive list of changes in this release
 -
diff --git a/clang/lib/Headers/stdckdint.h b/clang/lib/Headers/stdckdint.h
index 22972d78d9077a4..77290b260ff3bd4 100644
--- a/clang/lib/Headers/stdckdint.h
+++ b/clang/lib/Headers/stdckdint.h
@@ -21,9 +21,6 @@
 
 /* C23 7.20.1 Defines several macros for performing checked integer 
arithmetic*/
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
-#define __STDC_VERSION_STDCKDINT_H__ 202311L
-
 // Both A and B shall be any integer type other than "plain" char, bool, a bit-
 // precise integer type, or an enumerated type, and they need not be the same.
 
@@ -38,7 +35,6 @@
 #define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R))
 #define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (R))
 #define ckd_mul(R, A, B) __builtin_mul_overflow((A), (B), (R))
-#endif
 
 #endif /* __STDC_HOSTED__ */
 #endif /* __STDCKDINT_H */
diff --git a/clang/test/C/C2x/n2359.c b/clang/test/C/C2x/n2359.c
index dc38bab43c9db8d..0a1b801e505e146 100644
--- a/clang/test/C/C2x/n2359.c
+++ b/clang/test/C/C2x/n2359.c
@@ -33,8 +33,3 @@
 #error "__STDC_VERSION_STDINT_H__ not defined"
 // expected-error@-1 {{"__STDC_VERSION_STDINT_H__ not defined"}}
 #endif
-
-#include 
-#ifndef __STDC_VERSION_STDCKDINT_H__
-#error "__STDC_VERSION_STDCKDINT_H__ not defined"
-#endif
diff --git a/clang/test/C/C2x/n2683.c b/clang/test/C/C2x/n2683.c
index 0c666c5fd8782ba..a785d46c063c2cc 100644
--- a/clang/test/C/C2x/n2683.c
+++ b/clang/test/C/C2x/n2683.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c2x %s
 // RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c23 %s
 
 /* WG14 N2683: Clang 18
diff --git a/clang/test/C/C2x/n2683_2.c b/clang/test/C/C2x/n2683_2.c
index 247f6de8fe4bfe1..867d6b876cf0d9d 100644
--- a/clang/test/C/C2x/n2683_2.c
+++ b/clang/test/C/C2x/n2683_2.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c2x %s | FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
 
 #include 
diff --git a/clang/test/Headers/stdckdint.c b/clang/test/Headers/stdckdint.c
index 896c740360065b6..7774cecfa7c3317 100644
--- a/clang/test/Headers/stdckdint.c
+++ b/clang/test/Headers/stdckdint.c
@@ -1,12 +1,15 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c99 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c11 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c17 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c2x %s -o - | 
FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | 
FileCheck %s
 
 // expected-no-diagnostics
 
+#include 
 #include 
 
-_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");
-
 // CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add(
 // CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:

>From 4e2fd920121b15e014a6146c6c6672973bae4443 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 19 Oct 2023 22:23:03 +
Subject: [PATCH 2/2] Update stdckdint.h and make it available in pre-C23
 modes.

Update some tests and docs.
---
 clang/docs/ReleaseNotes.rst   | 2 +-
 clang/lib/Headers/stdckdint.h | 4 
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0de52a5bf122f4..1b1f25ae244ef9f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,7 @@ C23 Feature Support
 - Clang 

[clang] 5070c1e - [analyzer] WebKit checkers: recognize dynamicDowncast as a safe function.

2023-10-19 Thread Artem Dergachev via cfe-commits

Author: Ryosuke Niwa
Date: 2023-10-19T16:10:57-07:00
New Revision: 5070c1e3b07c5b384fe0a064aa99f25b8af4b7e9

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

LOG: [analyzer] WebKit checkers: recognize dynamicDowncast as a safe function.

It can take raw pointers without triggering a warning.

Also retire the support for makeRef and makeWeakPtr as they have been removed
from WebKit.

Added: 
clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp

Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
clang/test/Analysis/Checkers/WebKit/call-args.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 9b1d7ae3e6a320c..c1f180f31338cb3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -186,8 +186,7 @@ bool isPtrConversion(const FunctionDecl *F) {
   // FIXME: check # of params == 1
   const auto FunctionName = safeGetName(F);
   if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
-  FunctionName == "makeWeakPtr"
-
+  FunctionName == "dynamicDowncast"
   || FunctionName == "downcast" || FunctionName == "bitwise_cast")
 return true;
 

diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 4ae8c442fa70755..407b6ba7a76428c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -149,7 +149,7 @@ class UncountedCallArgsChecker
 
 auto name = safeGetName(Callee);
 if (name == "adoptRef" || name == "getPtr" || name == "WeakPtr" ||
-name == "makeWeakPtr" || name == "downcast" || name == "bitwise_cast" 
||
+name == "dynamicDowncast" || name == "downcast" || name == 
"bitwise_cast" ||
 name == "is" || name == "equal" || name == "hash" ||
 name == "isType"
 // FIXME: Most/all of these should be implemented via attributes.

diff  --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp
new file mode 100644
index 000..28156623d9a0fd7
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+class Base {
+public:
+inline void ref();
+inline void deref();
+};
+
+class Derived : public Base {
+public:
+  virtual ~Derived();
+
+  void ref() const;
+  void deref() const;
+};
+
+class SubDerived final : public Derived {
+};
+
+class OtherObject {
+public:
+Derived* obj();
+};
+
+template
+inline Target* dynamicDowncast(Source* source)
+{
+return static_cast(source);
+}
+
+void foo(OtherObject* other)
+{
+dynamicDowncast(other->obj());
+}

diff  --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index a56c4222adb514a..716219836e6b445 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -262,22 +262,6 @@ namespace param_forwarding_method {
   }
 }
 
-namespace make_ref {
-  void makeRef(RefCountable*) {}
-  void makeRefPtr(RefCountable*) {}
-  void makeWeakPtr(RefCountable*) {}
-  void makeWeakPtr(RefCountable&) {}
-
-  void foo() {
-makeRef(provide());
-makeRefPtr(provide());
-RefPtr a(provide());
-Ref b(provide());
-makeWeakPtr(provide());
-makeWeakPtr(*provide());
-  }
-}
-
 namespace downcast {
   void consume_ref_countable(RefCountable*) {}
   RefCountable* downcast(RefCountable*) { return nullptr; }



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


[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/69649

>From 0c57e45f6ee16e43cc6388b1ca6beb88bbc7b925 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 19 Oct 2023 22:23:03 +
Subject: [PATCH 1/2] Update stdckdint.h and make it available in pre-C23
 modes.

Update some tests and docs.
---
 clang/docs/ReleaseNotes.rst| 2 +-
 clang/lib/Headers/stdckdint.h  | 4 
 clang/test/C/C2x/n2359.c   | 5 -
 clang/test/C/C2x/n2683.c   | 1 +
 clang/test/C/C2x/n2683_2.c | 1 +
 clang/test/Headers/stdckdint.c | 7 +--
 6 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..d0de52a5bf122f4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,7 @@ C23 Feature Support
 - Clang now supports ``N3007 Type inference for object definitions``.
 
 - Clang now supports  which defines several macros for 
performing
-  checked integer arithmetic.
+  checked integer arithmetic. And it is also exposed in pre-C23 modes.
 
 Non-comprehensive list of changes in this release
 -
diff --git a/clang/lib/Headers/stdckdint.h b/clang/lib/Headers/stdckdint.h
index 22972d78d9077a4..77290b260ff3bd4 100644
--- a/clang/lib/Headers/stdckdint.h
+++ b/clang/lib/Headers/stdckdint.h
@@ -21,9 +21,6 @@
 
 /* C23 7.20.1 Defines several macros for performing checked integer 
arithmetic*/
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
-#define __STDC_VERSION_STDCKDINT_H__ 202311L
-
 // Both A and B shall be any integer type other than "plain" char, bool, a bit-
 // precise integer type, or an enumerated type, and they need not be the same.
 
@@ -38,7 +35,6 @@
 #define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R))
 #define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (R))
 #define ckd_mul(R, A, B) __builtin_mul_overflow((A), (B), (R))
-#endif
 
 #endif /* __STDC_HOSTED__ */
 #endif /* __STDCKDINT_H */
diff --git a/clang/test/C/C2x/n2359.c b/clang/test/C/C2x/n2359.c
index dc38bab43c9db8d..0a1b801e505e146 100644
--- a/clang/test/C/C2x/n2359.c
+++ b/clang/test/C/C2x/n2359.c
@@ -33,8 +33,3 @@
 #error "__STDC_VERSION_STDINT_H__ not defined"
 // expected-error@-1 {{"__STDC_VERSION_STDINT_H__ not defined"}}
 #endif
-
-#include 
-#ifndef __STDC_VERSION_STDCKDINT_H__
-#error "__STDC_VERSION_STDCKDINT_H__ not defined"
-#endif
diff --git a/clang/test/C/C2x/n2683.c b/clang/test/C/C2x/n2683.c
index 0c666c5fd8782ba..a785d46c063c2cc 100644
--- a/clang/test/C/C2x/n2683.c
+++ b/clang/test/C/C2x/n2683.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c2x %s
 // RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c23 %s
 
 /* WG14 N2683: Clang 18
diff --git a/clang/test/C/C2x/n2683_2.c b/clang/test/C/C2x/n2683_2.c
index 247f6de8fe4bfe1..867d6b876cf0d9d 100644
--- a/clang/test/C/C2x/n2683_2.c
+++ b/clang/test/C/C2x/n2683_2.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c2x %s | FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
 
 #include 
diff --git a/clang/test/Headers/stdckdint.c b/clang/test/Headers/stdckdint.c
index 896c740360065b6..7774cecfa7c3317 100644
--- a/clang/test/Headers/stdckdint.c
+++ b/clang/test/Headers/stdckdint.c
@@ -1,12 +1,15 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c99 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c11 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c17 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c2x %s -o - | 
FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | 
FileCheck %s
 
 // expected-no-diagnostics
 
+#include 
 #include 
 
-_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");
-
 // CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add(
 // CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:

>From 4e2fd920121b15e014a6146c6c6672973bae4443 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 19 Oct 2023 22:23:03 +
Subject: [PATCH 2/2] Update stdckdint.h and make it available in pre-C23
 modes.

Update some tests and docs.
---
 clang/docs/ReleaseNotes.rst   | 2 +-
 clang/lib/Headers/stdckdint.h | 4 
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0de52a5bf122f4..1b1f25ae244ef9f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,7 @@ C23 Feature Support
 - Clang 

[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/69649

>From 0c57e45f6ee16e43cc6388b1ca6beb88bbc7b925 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 19 Oct 2023 22:23:03 +
Subject: [PATCH] Update stdckdint.h and make it available in pre-C23 modes.

Update some tests and docs.
---
 clang/docs/ReleaseNotes.rst| 2 +-
 clang/lib/Headers/stdckdint.h  | 4 
 clang/test/C/C2x/n2359.c   | 5 -
 clang/test/C/C2x/n2683.c   | 1 +
 clang/test/C/C2x/n2683_2.c | 1 +
 clang/test/Headers/stdckdint.c | 7 +--
 6 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..d0de52a5bf122f4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,7 @@ C23 Feature Support
 - Clang now supports ``N3007 Type inference for object definitions``.
 
 - Clang now supports  which defines several macros for 
performing
-  checked integer arithmetic.
+  checked integer arithmetic. And it is also exposed in pre-C23 modes.
 
 Non-comprehensive list of changes in this release
 -
diff --git a/clang/lib/Headers/stdckdint.h b/clang/lib/Headers/stdckdint.h
index 22972d78d9077a4..77290b260ff3bd4 100644
--- a/clang/lib/Headers/stdckdint.h
+++ b/clang/lib/Headers/stdckdint.h
@@ -21,9 +21,6 @@
 
 /* C23 7.20.1 Defines several macros for performing checked integer 
arithmetic*/
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
-#define __STDC_VERSION_STDCKDINT_H__ 202311L
-
 // Both A and B shall be any integer type other than "plain" char, bool, a bit-
 // precise integer type, or an enumerated type, and they need not be the same.
 
@@ -38,7 +35,6 @@
 #define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R))
 #define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (R))
 #define ckd_mul(R, A, B) __builtin_mul_overflow((A), (B), (R))
-#endif
 
 #endif /* __STDC_HOSTED__ */
 #endif /* __STDCKDINT_H */
diff --git a/clang/test/C/C2x/n2359.c b/clang/test/C/C2x/n2359.c
index dc38bab43c9db8d..0a1b801e505e146 100644
--- a/clang/test/C/C2x/n2359.c
+++ b/clang/test/C/C2x/n2359.c
@@ -33,8 +33,3 @@
 #error "__STDC_VERSION_STDINT_H__ not defined"
 // expected-error@-1 {{"__STDC_VERSION_STDINT_H__ not defined"}}
 #endif
-
-#include 
-#ifndef __STDC_VERSION_STDCKDINT_H__
-#error "__STDC_VERSION_STDCKDINT_H__ not defined"
-#endif
diff --git a/clang/test/C/C2x/n2683.c b/clang/test/C/C2x/n2683.c
index 0c666c5fd8782ba..a785d46c063c2cc 100644
--- a/clang/test/C/C2x/n2683.c
+++ b/clang/test/C/C2x/n2683.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c2x %s
 // RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c23 %s
 
 /* WG14 N2683: Clang 18
diff --git a/clang/test/C/C2x/n2683_2.c b/clang/test/C/C2x/n2683_2.c
index 247f6de8fe4bfe1..867d6b876cf0d9d 100644
--- a/clang/test/C/C2x/n2683_2.c
+++ b/clang/test/C/C2x/n2683_2.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c2x %s | FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
 
 #include 
diff --git a/clang/test/Headers/stdckdint.c b/clang/test/Headers/stdckdint.c
index 896c740360065b6..7774cecfa7c3317 100644
--- a/clang/test/Headers/stdckdint.c
+++ b/clang/test/Headers/stdckdint.c
@@ -1,12 +1,15 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c99 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c11 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c17 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c2x %s -o - | 
FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | 
FileCheck %s
 
 // expected-no-diagnostics
 
+#include 
 #include 
 
-_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");
-
 // CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add(
 // CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:

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


[clang] [Profile] Refactor profile correlation. (PR #69656)

2023-10-19 Thread David Li via cfe-commits

https://github.com/david-xl approved this pull request.


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


[clang] [Profile] Refactor profile correlation. (PR #69656)

2023-10-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Zequan Wu (ZequanWu)


Changes

Refactor some code from #69493. 

---

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


21 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+10-4) 
- (modified) compiler-rt/lib/profile/InstrProfiling.c (+4) 
- (modified) compiler-rt/lib/profile/InstrProfiling.h (+6) 
- (modified) compiler-rt/lib/profile/InstrProfilingBuffer.c (+11) 
- (modified) compiler-rt/lib/profile/InstrProfilingMerge.c (+6-5) 
- (modified) compiler-rt/lib/profile/InstrProfilingWriter.c (+10-11) 
- (modified) compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c 
(+2-2) 
- (modified) 
compiler-rt/test/profile/Linux/instrprof-debug-info-correlate-warnings.c (+1-1) 
- (modified) compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c 
(+3-3) 
- (modified) 
compiler-rt/test/profile/Linux/instrprof-show-debug-info-correlation.c (+3-3) 
- (modified) llvm/docs/CommandGuide/llvm-profdata.rst (+2-2) 
- (modified) llvm/include/llvm/ProfileData/InstrProfCorrelator.h (+10-3) 
- (modified) llvm/include/llvm/ProfileData/InstrProfReader.h (+2) 
- (modified) llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h 
(-2) 
- (modified) llvm/lib/ProfileData/InstrProfCorrelator.cpp (+80-38) 
- (modified) llvm/lib/ProfileData/InstrProfReader.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp (+10-9) 
- (modified) llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (+5-1) 
- (modified) 
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll 
(+1-1) 
- (modified) llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll 
(+1-1) 
- (modified) llvm/tools/llvm-profdata/llvm-profdata.cpp (+6-3) 


``diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..83b81a38a768523 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -42,6 +42,7 @@
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Passes/PassPlugin.h"
 #include "llvm/Passes/StandardInstrumentations.h"
+#include "llvm/ProfileData/InstrProfCorrelator.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -55,6 +56,7 @@
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/TargetParser/SubtargetFeature.h"
 #include "llvm/TargetParser/Triple.h"
+#include "llvm/Transforms/HipStdPar/HipStdPar.h"
 #include "llvm/Transforms/IPO/EmbedBitcodePass.h"
 #include "llvm/Transforms/IPO/LowerTypeTests.h"
 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
@@ -78,7 +80,6 @@
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Scalar/JumpThreading.h"
-#include "llvm/Transforms/HipStdPar/HipStdPar.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -98,13 +99,18 @@ extern cl::opt PrintPipelinePasses;
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
 "sanitizer-early-opt-ep", cl::Optional,
 cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
-}
+
+extern cl::opt DebugInfoCorrelate;
+extern cl::opt ProfileCorrelate;
+} // namespace llvm
 
 namespace {
 
 // Default filename used for profile generation.
 std::string getDefaultProfileGenName() {
-  return DebugInfoCorrelate ? "default_%m.proflite" : "default_%m.profraw";
+  return DebugInfoCorrelate || ProfileCorrelate != InstrProfCorrelator::NONE
+ ? "default_%m.proflite"
+ : "default_%m.profraw";
 }
 
 class EmitAssemblyHelper {
@@ -197,7 +203,7 @@ class EmitAssemblyHelper {
   void EmitAssembly(BackendAction Action,
 std::unique_ptr OS);
 };
-}
+} // namespace
 
 static SanitizerCoverageOptions
 getSancovOptsFromCGOpts(const CodeGenOptions ) {
diff --git a/compiler-rt/lib/profile/InstrProfiling.c 
b/compiler-rt/lib/profile/InstrProfiling.c
index 0dd5ff5ae6331cb..e3bb8329216363e 100644
--- a/compiler-rt/lib/profile/InstrProfiling.c
+++ b/compiler-rt/lib/profile/InstrProfiling.c
@@ -85,3 +85,7 @@ COMPILER_RT_VISIBILITY void 
__llvm_profile_reset_counters(void) {
   }
   lprofSetProfileDumped(0);
 }
+
+inline int hasCorrelation() {
+  return (__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE) != 0ULL;
+}
diff --git a/compiler-rt/lib/profile/InstrProfiling.h 
b/compiler-rt/lib/profile/InstrProfiling.h
index 4433d7bd48871fc..c3203d51d5ca75c 100644
--- a/compiler-rt/lib/profile/InstrProfiling.h
+++ b/compiler-rt/lib/profile/InstrProfiling.h
@@ -259,6 +259,9 @@ uint64_t __llvm_profile_get_magic(void);
 /*! \brief Get the version of the file format. */
 uint64_t __llvm_profile_get_version(void);
 
+/*! \brief If the binary is compiled with profile correlation. */
+int hasCorrelation();
+
 /*! \brief Get 

[clang] [Profile] Refactor profile correlation. (PR #69656)

2023-10-19 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu created 
https://github.com/llvm/llvm-project/pull/69656

Refactor some code from #69493. 

>From 89f041c62da8c0924ee45a6ed8d9ab7afb560935 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Thu, 19 Oct 2023 18:55:08 -0400
Subject: [PATCH] [Profile] Refactor profile correlation.

---
 clang/lib/CodeGen/BackendUtil.cpp |  14 ++-
 compiler-rt/lib/profile/InstrProfiling.c  |   4 +
 compiler-rt/lib/profile/InstrProfiling.h  |   6 +
 .../lib/profile/InstrProfilingBuffer.c|  11 ++
 compiler-rt/lib/profile/InstrProfilingMerge.c |  11 +-
 .../lib/profile/InstrProfilingWriter.c|  21 ++--
 .../Darwin/instrprof-debug-info-correlate.c   |   4 +-
 .../instrprof-debug-info-correlate-warnings.c |   2 +-
 .../Linux/instrprof-debug-info-correlate.c|   6 +-
 .../instrprof-show-debug-info-correlation.c   |   6 +-
 llvm/docs/CommandGuide/llvm-profdata.rst  |   4 +-
 .../llvm/ProfileData/InstrProfCorrelator.h|  13 +-
 .../llvm/ProfileData/InstrProfReader.h|   2 +
 .../Instrumentation/PGOInstrumentation.h  |   2 -
 llvm/lib/ProfileData/InstrProfCorrelator.cpp  | 118 --
 llvm/lib/ProfileData/InstrProfReader.cpp  |   4 +-
 .../Instrumentation/InstrProfiling.cpp|  19 +--
 .../Instrumentation/PGOInstrumentation.cpp|   6 +-
 .../debug-info-correlate-coverage.ll  |   2 +-
 .../InstrProfiling/debug-info-correlate.ll|   2 +-
 llvm/tools/llvm-profdata/llvm-profdata.cpp|   9 +-
 21 files changed, 175 insertions(+), 91 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..83b81a38a768523 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -42,6 +42,7 @@
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Passes/PassPlugin.h"
 #include "llvm/Passes/StandardInstrumentations.h"
+#include "llvm/ProfileData/InstrProfCorrelator.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -55,6 +56,7 @@
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/TargetParser/SubtargetFeature.h"
 #include "llvm/TargetParser/Triple.h"
+#include "llvm/Transforms/HipStdPar/HipStdPar.h"
 #include "llvm/Transforms/IPO/EmbedBitcodePass.h"
 #include "llvm/Transforms/IPO/LowerTypeTests.h"
 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
@@ -78,7 +80,6 @@
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Scalar/JumpThreading.h"
-#include "llvm/Transforms/HipStdPar/HipStdPar.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -98,13 +99,18 @@ extern cl::opt PrintPipelinePasses;
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
 "sanitizer-early-opt-ep", cl::Optional,
 cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
-}
+
+extern cl::opt DebugInfoCorrelate;
+extern cl::opt ProfileCorrelate;
+} // namespace llvm
 
 namespace {
 
 // Default filename used for profile generation.
 std::string getDefaultProfileGenName() {
-  return DebugInfoCorrelate ? "default_%m.proflite" : "default_%m.profraw";
+  return DebugInfoCorrelate || ProfileCorrelate != InstrProfCorrelator::NONE
+ ? "default_%m.proflite"
+ : "default_%m.profraw";
 }
 
 class EmitAssemblyHelper {
@@ -197,7 +203,7 @@ class EmitAssemblyHelper {
   void EmitAssembly(BackendAction Action,
 std::unique_ptr OS);
 };
-}
+} // namespace
 
 static SanitizerCoverageOptions
 getSancovOptsFromCGOpts(const CodeGenOptions ) {
diff --git a/compiler-rt/lib/profile/InstrProfiling.c 
b/compiler-rt/lib/profile/InstrProfiling.c
index 0dd5ff5ae6331cb..e3bb8329216363e 100644
--- a/compiler-rt/lib/profile/InstrProfiling.c
+++ b/compiler-rt/lib/profile/InstrProfiling.c
@@ -85,3 +85,7 @@ COMPILER_RT_VISIBILITY void 
__llvm_profile_reset_counters(void) {
   }
   lprofSetProfileDumped(0);
 }
+
+inline int hasCorrelation() {
+  return (__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE) != 0ULL;
+}
diff --git a/compiler-rt/lib/profile/InstrProfiling.h 
b/compiler-rt/lib/profile/InstrProfiling.h
index 4433d7bd48871fc..c3203d51d5ca75c 100644
--- a/compiler-rt/lib/profile/InstrProfiling.h
+++ b/compiler-rt/lib/profile/InstrProfiling.h
@@ -259,6 +259,9 @@ uint64_t __llvm_profile_get_magic(void);
 /*! \brief Get the version of the file format. */
 uint64_t __llvm_profile_get_version(void);
 
+/*! \brief If the binary is compiled with profile correlation. */
+int hasCorrelation();
+
 /*! \brief Get the number of entries in the profile data section. */
 uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin,
  const __llvm_profile_data *End);
@@ -276,6 +279,9 @@ uint64_t __llvm_profile_get_num_counters(const char *Begin, 
const char *End);
 /*! 

[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread Jessica Clarke via cfe-commits


@@ -21,9 +21,6 @@
 
 /* C23 7.20.1 Defines several macros for performing checked integer 
arithmetic*/
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
-#define __STDC_VERSION_STDCKDINT_H__ 202311L

jrtc27 wrote:

This needs to stay, `__STDC_VERSION_STDCKDINT_H__` is defined by C23, not just 
something Clang invented

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


[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread Jessica Clarke via cfe-commits


@@ -177,7 +177,7 @@ C23 Feature Support
 - Clang now supports ``N3007 Type inference for object definitions``.
 
 - Clang now supports  which defines several macros for 
performing
-  checked integer arithmetic.
+  checked integer arithmetic. And it is also exposed in pre-C23 modes.

jrtc27 wrote:

Don't start a sentence with And

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


[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread Jessica Clarke via cfe-commits


@@ -33,8 +33,3 @@
 #error "__STDC_VERSION_STDINT_H__ not defined"
 // expected-error@-1 {{"__STDC_VERSION_STDINT_H__ not defined"}}
 #endif
-
-#include 
-#ifndef __STDC_VERSION_STDCKDINT_H__
-#error "__STDC_VERSION_STDCKDINT_H__ not defined"

jrtc27 wrote:

And this test needs to stay

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


[clang] [analyzer] WebKit checkers: support ref and deref defined on different classes. (PR #68170)

2023-10-19 Thread Artem Dergachev via cfe-commits


@@ -44,9 +46,25 @@ bool hasPublicRefAndDeref(const CXXRecordDecl *R) {
 
 namespace clang {
 
-std::optional
-isRefCountable(const CXXBaseSpecifier* Base)
-{
+std::optional
+hasPublicRefInBase(const CXXBaseSpecifier *Base) {
+  assert(Base);
+
+  const Type *T = Base->getType().getTypePtrOrNull();
+  if (!T)
+return std::nullopt;

haoNoQ wrote:

All these nullopt cases are so frustrating to spell out! It looks like the only 
reason we have them is that we wanted to analyze not-fully-instantiated 
templates. (If they're ever instantiated, we'd still reanalyze each 
instantiation. So it only fights false negatives on templates that literally 
nobody instantiates.) In particular, this alternative approach doesn't seem to 
cause any test failures:
```diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index a66fa38315f4..042682487710 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -46,47 +46,31 @@ bool hasPublicDerefMethod(const CXXRecordDecl *R) {
 
 namespace clang {
 
-std::optional
+const CXXRecordDecl *
 hasPublicRefInBase(const CXXBaseSpecifier *Base) {
   assert(Base);
 
-  const Type *T = Base->getType().getTypePtrOrNull();
-  if (!T)
-return std::nullopt;
-
+  QualType T = Base->getType();
   const CXXRecordDecl *R = T->getAsCXXRecordDecl();
-  if (!R)
-return std::nullopt;
-  if (!R->hasDefinition())
-return std::nullopt;
-
+  assert(R && R->hasDefinition());
   return hasPublicRefMethod(R) ? R : nullptr;
 }
 
-std::optional
+const CXXRecordDecl *
 hasPublicDerefInBase(const CXXBaseSpecifier *Base) {
   assert(Base);
 
-  const Type *T = Base->getType().getTypePtrOrNull();
-  if (!T)
-return std::nullopt;
-
+  QualType T = Base->getType();
   const CXXRecordDecl *R = T->getAsCXXRecordDecl();
-  if (!R)
-return std::nullopt;
-  if (!R->hasDefinition())
-return std::nullopt;
-
+  assert(R && R->hasDefinition());
   return hasPublicDerefMethod(R) ? R : nullptr;
 }
 
 std::optional isRefCountable(const CXXRecordDecl* R)
 {
   assert(R);
-
   R = R->getDefinition();
-  if (!R)
-return std::nullopt;
+  assert(R);
 
   bool hasRef = hasPublicRefMethod(R);
   bool hasDeref = hasPublicDerefMethod(R);
@@ -96,37 +80,19 @@ std::optional isRefCountable(const CXXRecordDecl* R)
   CXXBasePaths Paths;
   Paths.setOrigin(const_cast(R));
 
-  bool AnyInconclusiveBase = false;
-  const auto hasPublicRefInBase =
-  [](const CXXBaseSpecifier *Base, CXXBasePath &) {
-auto hasRefInBase = clang::hasPublicRefInBase(Base);
-if (!hasRefInBase) {
-  AnyInconclusiveBase = true;
-  return false;
-}
-return (*hasRefInBase) != nullptr;
-  };
-
-  hasRef =
-  R->lookupInBases(hasPublicRefInBase, Paths, /*LookupInDependent =*/true);
-  if (AnyInconclusiveBase)
-return std::nullopt;
-
-  const auto hasPublicDerefInBase =
-  [](const CXXBaseSpecifier *Base, CXXBasePath &) {
-auto hasDerefInBase = clang::hasPublicDerefInBase(Base);
-if (!hasDerefInBase) {
-  AnyInconclusiveBase = true;
-  return false;
-}
-return (*hasDerefInBase) != nullptr;
-  };
-  hasDeref = R->lookupInBases(hasPublicDerefInBase, Paths,
-  /*LookupInDependent =*/true);
-  if (AnyInconclusiveBase)
-return std::nullopt;
-
-  return hasRef && hasDeref;
+  bool hasDeepRef = R->lookupInBases(
+  [](const CXXBaseSpecifier *B, CXXBasePath &) {
+return (bool)hasPublicRefInBase(B);
+  },
+  Paths,
+  /*LookupInDependent =*/true);
+  bool hasDeepDeref = R->lookupInBases(
+  [](const CXXBaseSpecifier *B, CXXBasePath &) {
+return (bool)hasPublicDerefInBase(B);
+  },
+  Paths,
+  /*LookupInDependent =*/true);
+  return (hasRef || hasDeepRef) && (hasDeref || hasDeepDeref);
 }
 
 bool isCtorOfRefCounted(const clang::FunctionDecl *F) {
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index 9c7a933b9ee9..ec80870d58e9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -27,13 +27,13 @@ class Type;
 // Ref.
 
 /// \returns CXXRecordDecl of the base if the type has ref as a public method,
-/// nullptr if not, std::nullopt if inconclusive.
-std::optional
+/// nullptr if not.
+const clang::CXXRecordDecl *
 hasPublicRefInBase(const CXXBaseSpecifier *Base);
 
 /// \returns CXXRecordDecl of the base if the type has deref as a public
-/// method, nullptr if not, std::nullopt if inconclusive.
-std::optional
+/// method, nullptr if not.
+const clang::CXXRecordDecl *
 hasPublicDerefInBase(const CXXBaseSpecifier *Base);
 
 /// \returns true if \p Class is 

[clang] [analyzer] WebKit checkers: support ref and deref defined on different classes. (PR #68170)

2023-10-19 Thread Artem Dergachev via cfe-commits


@@ -70,29 +88,45 @@ std::optional isRefCountable(const CXXRecordDecl* R)
   if (!R)
 return std::nullopt;
 
-  if (hasPublicRefAndDeref(R))
+  bool hasRef = hasPublicRefMethod(R);
+  bool hasDeref = hasPublicDerefMethod(R);
+  if (hasRef && hasDeref)
 return true;
 
   CXXBasePaths Paths;
   Paths.setOrigin(const_cast(R));
 
   bool AnyInconclusiveBase = false;
-  const auto isRefCountableBase =
-  [](const CXXBaseSpecifier* Base, CXXBasePath&) {
-  std::optional IsRefCountable = 
clang::isRefCountable(Base);
-  if (!IsRefCountable) {
-  AnyInconclusiveBase = true;
-  return false;
-  }
-  return (*IsRefCountable) != nullptr;
+  const auto hasPublicRefInBase =
+  [](const CXXBaseSpecifier *Base, CXXBasePath &) {
+auto hasRefInBase = clang::hasPublicRefInBase(Base);
+if (!hasRefInBase) {
+  AnyInconclusiveBase = true;
+  return false;
+}
+return (*hasRefInBase) != nullptr;
   };
 
-  bool BasesResult = R->lookupInBases(isRefCountableBase, Paths,
-  /*LookupInDependent =*/true);
+  hasRef =
+  R->lookupInBases(hasPublicRefInBase, Paths, /*LookupInDependent =*/true);
+  if (AnyInconclusiveBase)
+return std::nullopt;
+
+  const auto hasPublicDerefInBase =
+  [](const CXXBaseSpecifier *Base, CXXBasePath &) {
+auto hasDerefInBase = clang::hasPublicDerefInBase(Base);
+if (!hasDerefInBase) {
+  AnyInconclusiveBase = true;
+  return false;
+}
+return (*hasDerefInBase) != nullptr;
+  };
+  hasDeref = R->lookupInBases(hasPublicDerefInBase, Paths,
+  /*LookupInDependent =*/true);

haoNoQ wrote:

This overwrites the old `hasDeref` value, so it may give an incorrect answer if 
eg. `Deref` is in the class itself but `Ref` is in a base class.

In the other copy of similar code we see `hasDeref = hasDeref || 
lookupInBases(...)` which is probably more correct.

(Which makes me wish there weren't two copies of this code in the first place.)

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


[clang] [analyzer] WebKit checkers: support ref and deref defined on different classes. (PR #68170)

2023-10-19 Thread Artem Dergachev via cfe-commits


@@ -18,24 +18,26 @@ using namespace clang;
 
 namespace {
 
-bool hasPublicRefAndDeref(const CXXRecordDecl *R) {
+bool hasPublicRefMethod(const CXXRecordDecl *R) {
   assert(R);
   assert(R->hasDefinition());
 
-  bool hasRef = false;
-  bool hasDeref = false;
   for (const CXXMethodDecl *MD : R->methods()) {
 const auto MethodName = safeGetName(MD);
+if (MethodName == "ref" && MD->getAccess() == AS_public)
+  return true;
+  }
+  return false;
+}
 
-if (MethodName == "ref" && MD->getAccess() == AS_public) {
-  if (hasDeref)
-return true;
-  hasRef = true;
-} else if (MethodName == "deref" && MD->getAccess() == AS_public) {
-  if (hasRef)
-return true;
-  hasDeref = true;
-}
+bool hasPublicDerefMethod(const CXXRecordDecl *R) {

haoNoQ wrote:

It's probably a good idea to deduplicate some code here, eg. have a function 
`hasPublicMethod[InBase]WithName(string)` and pass `"Ref"` and `"Deref"` as 
parameters.

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


[clang] [analyzer] WebKit checkers: support ref and deref defined on different classes. (PR #68170)

2023-10-19 Thread Artem Dergachev via cfe-commits

https://github.com/haoNoQ commented:

@rniwa I had a look and I think everything looks mostly good! I found one 
possible bug and made a couple comments about how I'm frustrated about code 
duplication.

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


[clang] [analyzer] WebKit checkers: support ref and deref defined on different classes. (PR #68170)

2023-10-19 Thread Artem Dergachev via cfe-commits

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


[clang] [Modules] textual headers in submodules never resolve their `use`s (PR #69651)

2023-10-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Ian Anderson (ian-twilightcoder)


Changes

When an include from a textual header is resolved, the textual header's 
submodule is used as the requesting module. The submodule's uses are resolved, 
but that doesn't work because only top level modules have uses, and only the 
top level module uses are used for checking uses in Module::directlyUses. 
ModuleMap::resolveUses to resolve the top level module instead of the submodule.

---
Full diff: https://github.com/llvm/llvm-project/pull/69651.diff


5 Files Affected:

- (modified) clang/lib/Lex/ModuleMap.cpp (+7-6) 
- (added) clang/test/Modules/Inputs/no-undeclared-includes/assert.h (+1) 
- (added) clang/test/Modules/Inputs/no-undeclared-includes/base.h (+6) 
- (added) clang/test/Modules/Inputs/no-undeclared-includes/module.modulemap 
(+11) 
- (added) clang/test/Modules/no-undeclared-includes.c (+5) 


``diff
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index f65a5f145c04395..259c97796ae19f2 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1398,16 +1398,17 @@ bool ModuleMap::resolveExports(Module *Mod, bool 
Complain) {
 }
 
 bool ModuleMap::resolveUses(Module *Mod, bool Complain) {
-  auto Unresolved = std::move(Mod->UnresolvedDirectUses);
-  Mod->UnresolvedDirectUses.clear();
+  auto *Top = Mod->getTopLevelModule();
+  auto Unresolved = std::move(Top->UnresolvedDirectUses);
+  Top->UnresolvedDirectUses.clear();
   for (auto  : Unresolved) {
-Module *DirectUse = resolveModuleId(UDU, Mod, Complain);
+Module *DirectUse = resolveModuleId(UDU, Top, Complain);
 if (DirectUse)
-  Mod->DirectUses.push_back(DirectUse);
+  Top->DirectUses.push_back(DirectUse);
 else
-  Mod->UnresolvedDirectUses.push_back(UDU);
+  Top->UnresolvedDirectUses.push_back(UDU);
   }
-  return !Mod->UnresolvedDirectUses.empty();
+  return !Top->UnresolvedDirectUses.empty();
 }
 
 bool ModuleMap::resolveConflicts(Module *Mod, bool Complain) {
diff --git a/clang/test/Modules/Inputs/no-undeclared-includes/assert.h 
b/clang/test/Modules/Inputs/no-undeclared-includes/assert.h
new file mode 100644
index 000..6ca1ffb2ad7ea6e
--- /dev/null
+++ b/clang/test/Modules/Inputs/no-undeclared-includes/assert.h
@@ -0,0 +1 @@
+#include 
diff --git a/clang/test/Modules/Inputs/no-undeclared-includes/base.h 
b/clang/test/Modules/Inputs/no-undeclared-includes/base.h
new file mode 100644
index 000..e559063bef43311
--- /dev/null
+++ b/clang/test/Modules/Inputs/no-undeclared-includes/base.h
@@ -0,0 +1,6 @@
+#ifndef base_h
+#define base_h
+
+
+
+#endif /* base_h */
diff --git a/clang/test/Modules/Inputs/no-undeclared-includes/module.modulemap 
b/clang/test/Modules/Inputs/no-undeclared-includes/module.modulemap
new file mode 100644
index 000..23d04305b3becbd
--- /dev/null
+++ b/clang/test/Modules/Inputs/no-undeclared-includes/module.modulemap
@@ -0,0 +1,11 @@
+module cstd [system] [no_undeclared_includes] {
+  use base
+  module assert {
+textual header "assert.h"
+  }
+}
+
+module base [system] {
+  header "base.h"
+  export *
+}
diff --git a/clang/test/Modules/no-undeclared-includes.c 
b/clang/test/Modules/no-undeclared-includes.c
new file mode 100644
index 000..613418ef0041328
--- /dev/null
+++ b/clang/test/Modules/no-undeclared-includes.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I 
%S/Inputs/no-undeclared-includes %s -verify
+
+// expected-no-diagnostics
+#include 

``




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


[clang] [Modules] textual headers in submodules never resolve their `use`s (PR #69651)

2023-10-19 Thread Ian Anderson via cfe-commits

ian-twilightcoder wrote:

Somewhat indirectly caused by https://reviews.llvm.org/D132779

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


[clang] [Modules] textual headers in submodules never resolve their `use`s (PR #69651)

2023-10-19 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder created 
https://github.com/llvm/llvm-project/pull/69651

When an include from a textual header is resolved, the textual header's 
submodule is used as the requesting module. The submodule's uses are resolved, 
but that doesn't work because only top level modules have uses, and only the 
top level module uses are used for checking uses in Module::directlyUses. 
ModuleMap::resolveUses to resolve the top level module instead of the submodule.

>From 1f6f9023fd11c7413f814e249bf77933d289fb73 Mon Sep 17 00:00:00 2001
From: Ian Anderson 
Date: Thu, 19 Oct 2023 15:22:11 -0700
Subject: [PATCH] [Modules] textual headers in submodules never resolve their
 `use`s

When an include from a textual header is resolved, the textual header's 
submodule is used as the requesting module. The submodule's uses are resolved, 
but that doesn't work because only top level modules have uses, and only the 
top level module uses are used for checking uses in Module::directlyUses. 
ModuleMap::resolveUses to resolve the top level module instead of the submodule.
---
 clang/lib/Lex/ModuleMap.cpp | 13 +++--
 .../Modules/Inputs/no-undeclared-includes/assert.h  |  1 +
 .../Modules/Inputs/no-undeclared-includes/base.h|  6 ++
 .../Inputs/no-undeclared-includes/module.modulemap  | 11 +++
 clang/test/Modules/no-undeclared-includes.c |  5 +
 5 files changed, 30 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/Modules/Inputs/no-undeclared-includes/assert.h
 create mode 100644 clang/test/Modules/Inputs/no-undeclared-includes/base.h
 create mode 100644 
clang/test/Modules/Inputs/no-undeclared-includes/module.modulemap
 create mode 100644 clang/test/Modules/no-undeclared-includes.c

diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index f65a5f145c04395..259c97796ae19f2 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1398,16 +1398,17 @@ bool ModuleMap::resolveExports(Module *Mod, bool 
Complain) {
 }
 
 bool ModuleMap::resolveUses(Module *Mod, bool Complain) {
-  auto Unresolved = std::move(Mod->UnresolvedDirectUses);
-  Mod->UnresolvedDirectUses.clear();
+  auto *Top = Mod->getTopLevelModule();
+  auto Unresolved = std::move(Top->UnresolvedDirectUses);
+  Top->UnresolvedDirectUses.clear();
   for (auto  : Unresolved) {
-Module *DirectUse = resolveModuleId(UDU, Mod, Complain);
+Module *DirectUse = resolveModuleId(UDU, Top, Complain);
 if (DirectUse)
-  Mod->DirectUses.push_back(DirectUse);
+  Top->DirectUses.push_back(DirectUse);
 else
-  Mod->UnresolvedDirectUses.push_back(UDU);
+  Top->UnresolvedDirectUses.push_back(UDU);
   }
-  return !Mod->UnresolvedDirectUses.empty();
+  return !Top->UnresolvedDirectUses.empty();
 }
 
 bool ModuleMap::resolveConflicts(Module *Mod, bool Complain) {
diff --git a/clang/test/Modules/Inputs/no-undeclared-includes/assert.h 
b/clang/test/Modules/Inputs/no-undeclared-includes/assert.h
new file mode 100644
index 000..6ca1ffb2ad7ea6e
--- /dev/null
+++ b/clang/test/Modules/Inputs/no-undeclared-includes/assert.h
@@ -0,0 +1 @@
+#include 
diff --git a/clang/test/Modules/Inputs/no-undeclared-includes/base.h 
b/clang/test/Modules/Inputs/no-undeclared-includes/base.h
new file mode 100644
index 000..e559063bef43311
--- /dev/null
+++ b/clang/test/Modules/Inputs/no-undeclared-includes/base.h
@@ -0,0 +1,6 @@
+#ifndef base_h
+#define base_h
+
+
+
+#endif /* base_h */
diff --git a/clang/test/Modules/Inputs/no-undeclared-includes/module.modulemap 
b/clang/test/Modules/Inputs/no-undeclared-includes/module.modulemap
new file mode 100644
index 000..23d04305b3becbd
--- /dev/null
+++ b/clang/test/Modules/Inputs/no-undeclared-includes/module.modulemap
@@ -0,0 +1,11 @@
+module cstd [system] [no_undeclared_includes] {
+  use base
+  module assert {
+textual header "assert.h"
+  }
+}
+
+module base [system] {
+  header "base.h"
+  export *
+}
diff --git a/clang/test/Modules/no-undeclared-includes.c 
b/clang/test/Modules/no-undeclared-includes.c
new file mode 100644
index 000..613418ef0041328
--- /dev/null
+++ b/clang/test/Modules/no-undeclared-includes.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I 
%S/Inputs/no-undeclared-includes %s -verify
+
+// expected-no-diagnostics
+#include 

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


[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: None (ZijunZhaoCCK)


Changes

Update some tests and docs.

---
Full diff: https://github.com/llvm/llvm-project/pull/69649.diff


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1-1) 
- (modified) clang/lib/Headers/stdckdint.h (-4) 
- (modified) clang/test/C/C2x/n2359.c (-5) 
- (modified) clang/test/C/C2x/n2683.c (+1) 
- (modified) clang/test/C/C2x/n2683_2.c (+1) 
- (modified) clang/test/Headers/stdckdint.c (+5-2) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..d0de52a5bf122f4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,7 @@ C23 Feature Support
 - Clang now supports ``N3007 Type inference for object definitions``.
 
 - Clang now supports  which defines several macros for 
performing
-  checked integer arithmetic.
+  checked integer arithmetic. And it is also exposed in pre-C23 modes.
 
 Non-comprehensive list of changes in this release
 -
diff --git a/clang/lib/Headers/stdckdint.h b/clang/lib/Headers/stdckdint.h
index 22972d78d9077a4..77290b260ff3bd4 100644
--- a/clang/lib/Headers/stdckdint.h
+++ b/clang/lib/Headers/stdckdint.h
@@ -21,9 +21,6 @@
 
 /* C23 7.20.1 Defines several macros for performing checked integer 
arithmetic*/
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
-#define __STDC_VERSION_STDCKDINT_H__ 202311L
-
 // Both A and B shall be any integer type other than "plain" char, bool, a bit-
 // precise integer type, or an enumerated type, and they need not be the same.
 
@@ -38,7 +35,6 @@
 #define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R))
 #define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (R))
 #define ckd_mul(R, A, B) __builtin_mul_overflow((A), (B), (R))
-#endif
 
 #endif /* __STDC_HOSTED__ */
 #endif /* __STDCKDINT_H */
diff --git a/clang/test/C/C2x/n2359.c b/clang/test/C/C2x/n2359.c
index dc38bab43c9db8d..0a1b801e505e146 100644
--- a/clang/test/C/C2x/n2359.c
+++ b/clang/test/C/C2x/n2359.c
@@ -33,8 +33,3 @@
 #error "__STDC_VERSION_STDINT_H__ not defined"
 // expected-error@-1 {{"__STDC_VERSION_STDINT_H__ not defined"}}
 #endif
-
-#include 
-#ifndef __STDC_VERSION_STDCKDINT_H__
-#error "__STDC_VERSION_STDCKDINT_H__ not defined"
-#endif
diff --git a/clang/test/C/C2x/n2683.c b/clang/test/C/C2x/n2683.c
index 0c666c5fd8782ba..a785d46c063c2cc 100644
--- a/clang/test/C/C2x/n2683.c
+++ b/clang/test/C/C2x/n2683.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c2x %s
 // RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c23 %s
 
 /* WG14 N2683: Clang 18
diff --git a/clang/test/C/C2x/n2683_2.c b/clang/test/C/C2x/n2683_2.c
index 247f6de8fe4bfe1..867d6b876cf0d9d 100644
--- a/clang/test/C/C2x/n2683_2.c
+++ b/clang/test/C/C2x/n2683_2.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c2x %s | FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
 
 #include 
diff --git a/clang/test/Headers/stdckdint.c b/clang/test/Headers/stdckdint.c
index 896c740360065b6..7774cecfa7c3317 100644
--- a/clang/test/Headers/stdckdint.c
+++ b/clang/test/Headers/stdckdint.c
@@ -1,12 +1,15 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c99 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c11 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c17 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c2x %s -o - | 
FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | 
FileCheck %s
 
 // expected-no-diagnostics
 
+#include 
 #include 
 
-_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");
-
 // CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add(
 // CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:

``




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


[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread via cfe-commits

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


[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/69649

>From 0c57e45f6ee16e43cc6388b1ca6beb88bbc7b925 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 19 Oct 2023 22:23:03 +
Subject: [PATCH] Update stdckdint.h and make it available in pre-C23 modes.

Update some tests and docs.
---
 clang/docs/ReleaseNotes.rst| 2 +-
 clang/lib/Headers/stdckdint.h  | 4 
 clang/test/C/C2x/n2359.c   | 5 -
 clang/test/C/C2x/n2683.c   | 1 +
 clang/test/C/C2x/n2683_2.c | 1 +
 clang/test/Headers/stdckdint.c | 7 +--
 6 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..d0de52a5bf122f4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,7 @@ C23 Feature Support
 - Clang now supports ``N3007 Type inference for object definitions``.
 
 - Clang now supports  which defines several macros for 
performing
-  checked integer arithmetic.
+  checked integer arithmetic. And it is also exposed in pre-C23 modes.
 
 Non-comprehensive list of changes in this release
 -
diff --git a/clang/lib/Headers/stdckdint.h b/clang/lib/Headers/stdckdint.h
index 22972d78d9077a4..77290b260ff3bd4 100644
--- a/clang/lib/Headers/stdckdint.h
+++ b/clang/lib/Headers/stdckdint.h
@@ -21,9 +21,6 @@
 
 /* C23 7.20.1 Defines several macros for performing checked integer 
arithmetic*/
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
-#define __STDC_VERSION_STDCKDINT_H__ 202311L
-
 // Both A and B shall be any integer type other than "plain" char, bool, a bit-
 // precise integer type, or an enumerated type, and they need not be the same.
 
@@ -38,7 +35,6 @@
 #define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R))
 #define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (R))
 #define ckd_mul(R, A, B) __builtin_mul_overflow((A), (B), (R))
-#endif
 
 #endif /* __STDC_HOSTED__ */
 #endif /* __STDCKDINT_H */
diff --git a/clang/test/C/C2x/n2359.c b/clang/test/C/C2x/n2359.c
index dc38bab43c9db8d..0a1b801e505e146 100644
--- a/clang/test/C/C2x/n2359.c
+++ b/clang/test/C/C2x/n2359.c
@@ -33,8 +33,3 @@
 #error "__STDC_VERSION_STDINT_H__ not defined"
 // expected-error@-1 {{"__STDC_VERSION_STDINT_H__ not defined"}}
 #endif
-
-#include 
-#ifndef __STDC_VERSION_STDCKDINT_H__
-#error "__STDC_VERSION_STDCKDINT_H__ not defined"
-#endif
diff --git a/clang/test/C/C2x/n2683.c b/clang/test/C/C2x/n2683.c
index 0c666c5fd8782ba..a785d46c063c2cc 100644
--- a/clang/test/C/C2x/n2683.c
+++ b/clang/test/C/C2x/n2683.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c2x %s
 // RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c23 %s
 
 /* WG14 N2683: Clang 18
diff --git a/clang/test/C/C2x/n2683_2.c b/clang/test/C/C2x/n2683_2.c
index 247f6de8fe4bfe1..867d6b876cf0d9d 100644
--- a/clang/test/C/C2x/n2683_2.c
+++ b/clang/test/C/C2x/n2683_2.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c2x %s | FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
 
 #include 
diff --git a/clang/test/Headers/stdckdint.c b/clang/test/Headers/stdckdint.c
index 896c740360065b6..7774cecfa7c3317 100644
--- a/clang/test/Headers/stdckdint.c
+++ b/clang/test/Headers/stdckdint.c
@@ -1,12 +1,15 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c99 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c11 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c17 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c2x %s -o - | 
FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | 
FileCheck %s
 
 // expected-no-diagnostics
 
+#include 
 #include 
 
-_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");
-
 // CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add(
 // CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:

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


[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-19 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff e353cd8173db939af22a6fd90705e35fbadb01a7 
95b9d423a9e4fc0f317e2468696a9dafefd20f46 -- 
mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
``





View the diff from clang-format here.


``diff
diff --git a/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp 
b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
index f3a082922d61..619d88e889f7 100644
--- a/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
+++ b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
@@ -65,36 +65,37 @@ auto catchAll(F &) {
 
 static sycl::device getDefaultDevice() {
   static sycl::device syclDevice;
-  static bool isDeviceInitialised = false; 
-  if(!isDeviceInitialised) {
-  auto platformList = sycl::platform::get_platforms();
-  for (const auto  : platformList) {
-auto platformName = platform.get_info();
-bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
-if (!isLevelZero)
-  continue;
-
-syclDevice = platform.get_devices()[0];
-isDeviceInitialised = true;
-return syclDevice;
-  }
+  static bool isDeviceInitialised = false;
+  if (!isDeviceInitialised) {
+auto platformList = sycl::platform::get_platforms();
+for (const auto  : platformList) {
+  auto platformName = platform.get_info();
+  bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
+  if (!isLevelZero)
+continue;
+
+  syclDevice = platform.get_devices()[0];
+  isDeviceInitialised = true;
+  return syclDevice;
+}
 throw std::runtime_error("getDefaultDevice failed");
-  }
-  else
+  } else
 return syclDevice;
 }
 
 static sycl::context getDefaultContext() {
-  static sycl::context syclContext { getDefaultDevice() };
+  static sycl::context syclContext{getDefaultDevice()};
   return syclContext;
 }
 
 static void *allocDeviceMemory(sycl::queue *queue, size_t size, bool isShared) 
{
   void *memPtr = nullptr;
   if (isShared) {
-memPtr = sycl::aligned_alloc_shared(64, size, getDefaultDevice(), 
getDefaultContext());
+memPtr = sycl::aligned_alloc_shared(64, size, getDefaultDevice(),
+getDefaultContext());
   } else {
-memPtr = sycl::aligned_alloc_device(64, size, getDefaultDevice(), 
getDefaultContext());
+memPtr = sycl::aligned_alloc_device(64, size, getDefaultDevice(),
+getDefaultContext());
   }
   if (memPtr == nullptr) {
 throw std::runtime_error("mem allocation failed!");
@@ -116,10 +117,10 @@ static ze_module_handle_t loadModule(const void *data, 
size_t dataSize) {
(const uint8_t *)data,
nullptr,
nullptr};
-  auto zeDevice =
-  
sycl::get_native(getDefaultDevice());
-  auto zeContext =
-  
sycl::get_native(getDefaultContext());
+  auto zeDevice = sycl::get_native(
+  getDefaultDevice());
+  auto zeContext = sycl::get_native(
+  getDefaultContext());
   L0_SAFE_CALL(zeModuleCreate(zeContext, zeDevice, , , nullptr));
   return zeModule;
 }
@@ -134,8 +135,8 @@ static sycl::kernel *getKernel(ze_module_handle_t zeModule, 
const char *name) {
   L0_SAFE_CALL(zeKernelCreate(zeModule, , ));
   sycl::kernel_bundle kernelBundle =
   sycl::make_kernel_bundle({zeModule},
-   
getDefaultContext());
+   sycl::bundle_state::executable>(
+  {zeModule}, getDefaultContext());
 
   auto kernel = sycl::make_kernel(
   {kernelBundle, zeKernel}, getDefaultContext());

``




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


[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread via cfe-commits


@@ -1,12 +1,15 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c99 %s -o - | 
FileCheck %s

ZijunZhaoCCK wrote:

I don't add tests in clang/test/Headers/c11.c because I think here already 
covers and there are some specific flags/arguments in some of commands in c11.c.

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


[clang] Update stdckdint.h and make it available in pre-C23 modes. (PR #69649)

2023-10-19 Thread via cfe-commits

https://github.com/ZijunZhaoCCK created 
https://github.com/llvm/llvm-project/pull/69649

Update some tests and docs.

>From 0c57e45f6ee16e43cc6388b1ca6beb88bbc7b925 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 19 Oct 2023 22:23:03 +
Subject: [PATCH] Update stdckdint.h and make it available in pre-C23 modes.

Update some tests and docs.
---
 clang/docs/ReleaseNotes.rst| 2 +-
 clang/lib/Headers/stdckdint.h  | 4 
 clang/test/C/C2x/n2359.c   | 5 -
 clang/test/C/C2x/n2683.c   | 1 +
 clang/test/C/C2x/n2683_2.c | 1 +
 clang/test/Headers/stdckdint.c | 7 +--
 6 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..d0de52a5bf122f4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,7 +177,7 @@ C23 Feature Support
 - Clang now supports ``N3007 Type inference for object definitions``.
 
 - Clang now supports  which defines several macros for 
performing
-  checked integer arithmetic.
+  checked integer arithmetic. And it is also exposed in pre-C23 modes.
 
 Non-comprehensive list of changes in this release
 -
diff --git a/clang/lib/Headers/stdckdint.h b/clang/lib/Headers/stdckdint.h
index 22972d78d9077a4..77290b260ff3bd4 100644
--- a/clang/lib/Headers/stdckdint.h
+++ b/clang/lib/Headers/stdckdint.h
@@ -21,9 +21,6 @@
 
 /* C23 7.20.1 Defines several macros for performing checked integer 
arithmetic*/
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
-#define __STDC_VERSION_STDCKDINT_H__ 202311L
-
 // Both A and B shall be any integer type other than "plain" char, bool, a bit-
 // precise integer type, or an enumerated type, and they need not be the same.
 
@@ -38,7 +35,6 @@
 #define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R))
 #define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (R))
 #define ckd_mul(R, A, B) __builtin_mul_overflow((A), (B), (R))
-#endif
 
 #endif /* __STDC_HOSTED__ */
 #endif /* __STDCKDINT_H */
diff --git a/clang/test/C/C2x/n2359.c b/clang/test/C/C2x/n2359.c
index dc38bab43c9db8d..0a1b801e505e146 100644
--- a/clang/test/C/C2x/n2359.c
+++ b/clang/test/C/C2x/n2359.c
@@ -33,8 +33,3 @@
 #error "__STDC_VERSION_STDINT_H__ not defined"
 // expected-error@-1 {{"__STDC_VERSION_STDINT_H__ not defined"}}
 #endif
-
-#include 
-#ifndef __STDC_VERSION_STDCKDINT_H__
-#error "__STDC_VERSION_STDCKDINT_H__ not defined"
-#endif
diff --git a/clang/test/C/C2x/n2683.c b/clang/test/C/C2x/n2683.c
index 0c666c5fd8782ba..a785d46c063c2cc 100644
--- a/clang/test/C/C2x/n2683.c
+++ b/clang/test/C/C2x/n2683.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c2x %s
 // RUN: %clang_cc1 -triple=x86_64 -verify -ffreestanding -std=c23 %s
 
 /* WG14 N2683: Clang 18
diff --git a/clang/test/C/C2x/n2683_2.c b/clang/test/C/C2x/n2683_2.c
index 247f6de8fe4bfe1..867d6b876cf0d9d 100644
--- a/clang/test/C/C2x/n2683_2.c
+++ b/clang/test/C/C2x/n2683_2.c
@@ -1,4 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c2x %s | FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -o - -std=c23 %s | FileCheck %s
 
 #include 
diff --git a/clang/test/Headers/stdckdint.c b/clang/test/Headers/stdckdint.c
index 896c740360065b6..7774cecfa7c3317 100644
--- a/clang/test/Headers/stdckdint.c
+++ b/clang/test/Headers/stdckdint.c
@@ -1,12 +1,15 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c99 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c11 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c17 %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c2x %s -o - | 
FileCheck %s
 // RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | 
FileCheck %s
 
 // expected-no-diagnostics
 
+#include 
 #include 
 
-_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");
-
 // CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add(
 // CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:

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


[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-19 Thread Nishant Patel via cfe-commits

https://github.com/nbpatel created 
https://github.com/llvm/llvm-project/pull/69648

This PR is a breakdown of the big PR #65539  which enables intel gpu 
integration. In this PR we add the code for the sycl runtime wrappers and also 
the cmake modules to find the dependent components. Integration test will be a 
follow up PR.

This PR is a joint effort by Nishant Patel & Sang Ik Lee.

>From 843d9b200f3708676119ed0b2b3b0657cd3fd47b Mon Sep 17 00:00:00 2001
From: Nishant Patel 
Date: Mon, 18 Sep 2023 18:26:22 +
Subject: [PATCH 1/3] Add SYCL runtimet wrappers

---
 .../ExecutionEngine/SyclRuntimeWrappers.cpp   | 221 ++
 1 file changed, 221 insertions(+)
 create mode 100644 mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp

diff --git a/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp 
b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
new file mode 100644
index 000..5bb58ea0dbe0c21
--- /dev/null
+++ b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
@@ -0,0 +1,221 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32
+
+namespace {
+
+template 
+auto catchAll(F &) {
+  try {
+return func();
+  } catch (const std::exception ) {
+fprintf(stdout, "An exception was thrown: %s\n", e.what());
+fflush(stdout);
+abort();
+  } catch (...) {
+fprintf(stdout, "An unknown exception was thrown\n");
+fflush(stdout);
+abort();
+  }
+}
+
+#define L0_SAFE_CALL(call) 
\
+  {
\
+ze_result_t status = (call);   
\
+if (status != ZE_RESULT_SUCCESS) { 
\
+  fprintf(stdout, "L0 error %d\n", status);
\
+  fflush(stdout);  
\
+  abort(); 
\
+}  
\
+  }
+
+} // namespace
+
+static sycl::device getDefaultDevice() {
+  auto platformList = sycl::platform::get_platforms();
+  for (const auto  : platformList) {
+auto platformName = platform.get_info();
+bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
+if (!isLevelZero)
+  continue;
+
+return platform.get_devices()[0];
+  }
+  throw std::runtime_error("getDefaultDevice failed");
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wglobal-constructors"
+
+// Create global device and context
+sycl::device syclDevice = getDefaultDevice();
+sycl::context syclContext { syclDevice };
+
+#pragma clang diagnostic pop
+
+struct QUEUE {
+  sycl::queue syclQueue_;
+
+  QUEUE() { syclQueue_ = sycl::queue(syclContext, syclDevice); }
+};
+
+static void *allocDeviceMemory(QUEUE *queue, size_t size, bool isShared) {
+  void *memPtr = nullptr;
+  if (isShared) {
+memPtr = sycl::aligned_alloc_shared(64, size, syclDevice, syclContext);
+  } else {
+memPtr = sycl::aligned_alloc_device(64, size, syclDevice, syclContext);
+  }
+  if (memPtr == nullptr) {
+throw std::runtime_error("mem allocation failed!");
+  }
+  return memPtr;
+}
+
+static void deallocDeviceMemory(QUEUE *queue, void *ptr) {
+  sycl::free(ptr, queue->syclQueue_);
+}
+
+static ze_module_handle_t loadModule(const void *data, size_t dataSize) {
+  assert(data);
+  ze_module_handle_t zeModule;
+  ze_module_desc_t desc = {ZE_STRUCTURE_TYPE_MODULE_DESC,
+   nullptr,
+   ZE_MODULE_FORMAT_IL_SPIRV,
+   dataSize,
+   (const uint8_t *)data,
+   nullptr,
+   nullptr};
+  auto zeDevice =
+  sycl::get_native(syclDevice);
+  auto zeContext =
+  sycl::get_native(syclContext);
+  L0_SAFE_CALL(zeModuleCreate(zeContext, zeDevice, , , nullptr));
+  return zeModule;
+}
+
+static sycl::kernel *getKernel(ze_module_handle_t zeModule, const char *name) {
+  assert(zeModule);
+  assert(name);
+  ze_kernel_handle_t zeKernel;
+  sycl::kernel *syclKernel;
+  ze_kernel_desc_t 

[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-19 Thread Nishant Patel via cfe-commits

https://github.com/nbpatel created 
https://github.com/llvm/llvm-project/pull/69648

This PR is a breakdown of the big PR #65539  which enables intel gpu 
integration. In this PR we add the code for the sycl runtime wrappers and also 
the cmake modules to find the dependent components. Integration test will be a 
follow up PR.

This PR is a joint effort by Nishant Patel & Sang Ik Lee.

>From 843d9b200f3708676119ed0b2b3b0657cd3fd47b Mon Sep 17 00:00:00 2001
From: Nishant Patel 
Date: Mon, 18 Sep 2023 18:26:22 +
Subject: [PATCH 1/3] Add SYCL runtimet wrappers

---
 .../ExecutionEngine/SyclRuntimeWrappers.cpp   | 221 ++
 1 file changed, 221 insertions(+)
 create mode 100644 mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp

diff --git a/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp 
b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
new file mode 100644
index 000..5bb58ea0dbe0c21
--- /dev/null
+++ b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
@@ -0,0 +1,221 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32
+
+namespace {
+
+template 
+auto catchAll(F &) {
+  try {
+return func();
+  } catch (const std::exception ) {
+fprintf(stdout, "An exception was thrown: %s\n", e.what());
+fflush(stdout);
+abort();
+  } catch (...) {
+fprintf(stdout, "An unknown exception was thrown\n");
+fflush(stdout);
+abort();
+  }
+}
+
+#define L0_SAFE_CALL(call) 
\
+  {
\
+ze_result_t status = (call);   
\
+if (status != ZE_RESULT_SUCCESS) { 
\
+  fprintf(stdout, "L0 error %d\n", status);
\
+  fflush(stdout);  
\
+  abort(); 
\
+}  
\
+  }
+
+} // namespace
+
+static sycl::device getDefaultDevice() {
+  auto platformList = sycl::platform::get_platforms();
+  for (const auto  : platformList) {
+auto platformName = platform.get_info();
+bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
+if (!isLevelZero)
+  continue;
+
+return platform.get_devices()[0];
+  }
+  throw std::runtime_error("getDefaultDevice failed");
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wglobal-constructors"
+
+// Create global device and context
+sycl::device syclDevice = getDefaultDevice();
+sycl::context syclContext { syclDevice };
+
+#pragma clang diagnostic pop
+
+struct QUEUE {
+  sycl::queue syclQueue_;
+
+  QUEUE() { syclQueue_ = sycl::queue(syclContext, syclDevice); }
+};
+
+static void *allocDeviceMemory(QUEUE *queue, size_t size, bool isShared) {
+  void *memPtr = nullptr;
+  if (isShared) {
+memPtr = sycl::aligned_alloc_shared(64, size, syclDevice, syclContext);
+  } else {
+memPtr = sycl::aligned_alloc_device(64, size, syclDevice, syclContext);
+  }
+  if (memPtr == nullptr) {
+throw std::runtime_error("mem allocation failed!");
+  }
+  return memPtr;
+}
+
+static void deallocDeviceMemory(QUEUE *queue, void *ptr) {
+  sycl::free(ptr, queue->syclQueue_);
+}
+
+static ze_module_handle_t loadModule(const void *data, size_t dataSize) {
+  assert(data);
+  ze_module_handle_t zeModule;
+  ze_module_desc_t desc = {ZE_STRUCTURE_TYPE_MODULE_DESC,
+   nullptr,
+   ZE_MODULE_FORMAT_IL_SPIRV,
+   dataSize,
+   (const uint8_t *)data,
+   nullptr,
+   nullptr};
+  auto zeDevice =
+  sycl::get_native(syclDevice);
+  auto zeContext =
+  sycl::get_native(syclContext);
+  L0_SAFE_CALL(zeModuleCreate(zeContext, zeDevice, , , nullptr));
+  return zeModule;
+}
+
+static sycl::kernel *getKernel(ze_module_handle_t zeModule, const char *name) {
+  assert(zeModule);
+  assert(name);
+  ze_kernel_handle_t zeKernel;
+  sycl::kernel *syclKernel;
+  ze_kernel_desc_t 

[clang] 1d8985f - [Fuchsia] Add lldb-dap to LLDB distribution

2023-10-19 Thread Daniel Thornburgh via cfe-commits

Author: Daniel Thornburgh
Date: 2023-10-19T14:45:34-07:00
New Revision: 1d8985fc14457429c8120b09ae842250bdd225b1

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

LOG: [Fuchsia] Add lldb-dap to LLDB distribution

Added: 


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

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 0dcc35ee1495f55..13bb5ad3546e98f 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -368,6 +368,7 @@ if(FUCHSIA_ENABLE_LLDB)
 liblldb
 lldb-server
 lldb-argdumper
+lldb-dap
   )
   if(LLDB_ENABLE_PYTHON)
 list(APPEND _FUCHSIA_LLDB_COMPONENTS lldb-python-scripts)



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


[clang] [Windows] Add git-clang-format wrapper bat file (PR #69228)

2023-10-19 Thread Chris B via cfe-commits

llvm-beanz wrote:

> Can you open an issue and link to it from here?

Filed #69643.

> It seems `git clang-format` works in Command Prompt without this new batch 
> file.

IIUC, `git clang-format` works if you have WSL installed, but not with a 
default Windows installation. We definitely have users on my team that are 
Windows-only users who encounter an error running that command even if the 
git-clang-format script is on the path, and the presence of the `.bat` file 
solves the issue.

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


[clang] [Windows] Add git-clang-format wrapper bat file (PR #69228)

2023-10-19 Thread Chris B via cfe-commits

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


[clang] Support MemProf on darwin (PR #69640)

2023-10-19 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff ea9e116e5a24e834142bc4024b57697b48599a9e 
8ce32592e780e693a9378f30237a25629a822897 -- clang/test/Driver/darwin-memprof.c 
compiler-rt/lib/memprof/memprof_mac.cpp 
compiler-rt/lib/memprof/memprof_malloc_mac.cpp 
compiler-rt/test/memprof/TestCases/Darwin/memprof_dump.cpp 
clang/lib/Driver/ToolChains/Darwin.cpp 
compiler-rt/lib/memprof/memprof_allocator.cpp 
compiler-rt/lib/memprof/memprof_allocator.h 
compiler-rt/lib/memprof/memprof_interceptors.cpp 
compiler-rt/lib/memprof/memprof_interceptors.h 
compiler-rt/lib/memprof/memprof_linux.cpp 
compiler-rt/lib/memprof/memprof_malloc_linux.cpp 
compiler-rt/lib/memprof/memprof_new_delete.cpp 
compiler-rt/test/asan/TestCases/Darwin/asan-symbolize-templated-cxx.cpp
``





View the diff from clang-format here.


``diff
diff --git a/compiler-rt/lib/memprof/memprof_mac.cpp 
b/compiler-rt/lib/memprof/memprof_mac.cpp
index 71439501bb11..a931dd364b0b 100644
--- a/compiler-rt/lib/memprof/memprof_mac.cpp
+++ b/compiler-rt/lib/memprof/memprof_mac.cpp
@@ -42,9 +42,7 @@ void InitializePlatformInterceptors() {}
 void InitializePlatformExceptionHandlers() {}
 
 // No-op. Mac does not support static linkage anyway.
-void *MemprofDoesNotSupportStaticLinkage() {
-  return 0;
-}
+void *MemprofDoesNotSupportStaticLinkage() { return 0; }
 
 uptr FindDynamicShadowStart() {
   uptr shadow_size_bytes = MemToShadowSize(kHighMemEnd);

``




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


[clang] [OpenMP 5.2] Deprecate syntax of map modifiers without comma separators (PR #69534)

2023-10-19 Thread Fazlay Rabbi via cfe-commits

https://github.com/mdfazlay updated 
https://github.com/llvm/llvm-project/pull/69534

>From a8f51dbafe6350ac20f00b01565bf273dde776f4 Mon Sep 17 00:00:00 2001
From: Fazlay Rabbi 
Date: Wed, 18 Oct 2023 13:21:17 -0700
Subject: [PATCH] [OpenMP 5.2] Deprecate syntax of map modifiers without comma
 separators

The syntax of modifiers without comma separators in the map clause was
deprecated in OpenMP 5.2.

Reference: OpenMP 5.2 Spec, Page 627, Line 19
---
 clang/include/clang/Basic/DiagnosticParseKinds.td  |  1 +
 clang/lib/Parse/ParseOpenMP.cpp|  9 +
 clang/test/OpenMP/declare_mapper_ast_print.c   |  2 +-
 clang/test/OpenMP/declare_mapper_messages.c|  8 
 clang/test/OpenMP/target_ast_print.cpp | 10 +-
 clang/test/OpenMP/target_map_messages.cpp  |  9 +
 clang/test/OpenMP/target_parallel_for_map_messages.cpp |  4 
 .../OpenMP/target_parallel_for_simd_map_messages.cpp   |  4 
 clang/test/OpenMP/target_parallel_map_messages.cpp |  4 
 clang/test/OpenMP/target_simd_map_messages.cpp |  4 
 .../OpenMP/target_teams_distribute_map_messages.cpp|  4 
 ...rget_teams_distribute_parallel_for_map_messages.cpp |  3 +++
 ...teams_distribute_parallel_for_simd_map_messages.cpp |  4 
 .../target_teams_distribute_simd_map_messages.cpp  |  4 
 clang/test/OpenMP/target_teams_map_messages.cpp|  3 +++
 15 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 43a5f000eda6cb9..9d33b014d5fd8c3 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1534,6 +1534,7 @@ def warn_omp51_compat_attributes : Warning<
   "standards before OpenMP 5.1">,
   InGroup, DefaultIgnore;
 def err_omp_expected_colon : Error<"missing ':' in %0">;
+def err_omp_missing_comma : Error< "missing ',' after %0">;
 def err_omp_expected_context_selector
 : Error<"expected valid context selector in %0">;
 def err_omp_requires_out_inout_depend_type : Error<
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 995834a78c795fb..1a80bce0cfde53c 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4198,6 +4198,10 @@ bool 
Parser::parseMapTypeModifiers(Sema::OpenMPVarListDataTy ) {
 TypeModifier == OMPC_MAP_MODIFIER_ompx_hold) {
   Data.MapTypeModifiers.push_back(TypeModifier);
   Data.MapTypeModifiersLoc.push_back(Tok.getLocation());
+  if (PP.LookAhead(0).isNot(tok::comma) &&
+  PP.LookAhead(0).isNot(tok::colon) && getLangOpts().OpenMP >= 52)
+Diag(Tok.getLocation(), diag::err_omp_missing_comma)
+<< "map type modifier";
   ConsumeToken();
 } else if (TypeModifier == OMPC_MAP_MODIFIER_mapper) {
   Data.MapTypeModifiers.push_back(TypeModifier);
@@ -4205,6 +4209,11 @@ bool 
Parser::parseMapTypeModifiers(Sema::OpenMPVarListDataTy ) {
   ConsumeToken();
   if (parseMapperModifier(Data))
 return true;
+  if (Tok.isNot(tok::comma) && Tok.isNot(tok::colon) &&
+  getLangOpts().OpenMP >= 52)
+Diag(Data.MapTypeModifiersLoc.back(), diag::err_omp_missing_comma)
+<< "map type modifier";
+
 } else {
   // For the case of unknown map-type-modifier or a map-type.
   // Map-type is followed by a colon; the function returns when it
diff --git a/clang/test/OpenMP/declare_mapper_ast_print.c 
b/clang/test/OpenMP/declare_mapper_ast_print.c
index 7c30b21c48b956e..e6a0546fe5c98a1 100644
--- a/clang/test/OpenMP/declare_mapper_ast_print.c
+++ b/clang/test/OpenMP/declare_mapper_ast_print.c
@@ -58,7 +58,7 @@ int main(void) {
 // CHECK: #pragma omp declare mapper (id : struct vec v) map(tofrom: v.len)
 struct vec vv;
 struct dat dd[10];
-#pragma omp target map(mapper(id) alloc: vv)
+#pragma omp target map(mapper(id), alloc: vv)
 // CHECK: #pragma omp target map(mapper(id),alloc: vv)
 { vv.len++; }
 #pragma omp target map(mapper(default), from: dd[0:10])
diff --git a/clang/test/OpenMP/declare_mapper_messages.c 
b/clang/test/OpenMP/declare_mapper_messages.c
index 17315738155b104..288caca097648c0 100644
--- a/clang/test/OpenMP/declare_mapper_messages.c
+++ b/clang/test/OpenMP/declare_mapper_messages.c
@@ -1,10 +1,10 @@
 // RUN: %clang_cc1 -verify=omp50,expected -fopenmp -fopenmp-version=50 
-ferror-limit 100 -DOMP50 %s
 // RUN: %clang_cc1 -verify=omp51,expected -fopenmp -ferror-limit 100 %s
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -ferror-limit 100 
-DOMP52 %s
+// RUN: %clang_cc1 -verify=expected,omp52 -fopenmp -fopenmp-version=52 
-ferror-limit 100 -DOMP52 %s
 
 // RUN: %clang_cc1 -verify=omp50,expected -fopenmp-simd -fopenmp-version=50 
-ferror-limit 100 -DOMP50 %s
 // RUN: %clang_cc1 -verify=omp51-simd,expected -fopenmp-simd -ferror-limit 100 

[clang] Support MemProf on darwin (PR #69640)

2023-10-19 Thread Manman Ren via cfe-commits

https://github.com/manman-ren created 
https://github.com/llvm/llvm-project/pull/69640

None

>From 86dc0db55bf6aa629639b1beac5c2cf5f39177ec Mon Sep 17 00:00:00 2001
From: Manman Ren 
Date: Tue, 10 Oct 2023 20:54:07 -0700
Subject: [PATCH 1/2] memprof support on Darwin

---
 clang/lib/Driver/ToolChains/Darwin.cpp|  3 +
 clang/test/Driver/darwin-memprof.c| 13 +
 .../cmake/Modules/AllSupportedArchDefs.cmake  |  2 +-
 compiler-rt/cmake/config-ix.cmake |  4 +-
 compiler-rt/lib/memprof/CMakeLists.txt| 30 +-
 compiler-rt/lib/memprof/memprof_allocator.cpp |  4 ++
 compiler-rt/lib/memprof/memprof_allocator.h   | 25 +---
 .../lib/memprof/memprof_interceptors.cpp  |  5 +-
 .../lib/memprof/memprof_interceptors.h|  6 ++
 compiler-rt/lib/memprof/memprof_linux.cpp |  5 +-
 compiler-rt/lib/memprof/memprof_mac.cpp   | 58 +++
 .../lib/memprof/memprof_malloc_linux.cpp  |  5 +-
 .../lib/memprof/memprof_malloc_mac.cpp| 37 
 .../lib/memprof/memprof_new_delete.cpp|  4 ++
 compiler-rt/lib/memprof/tests/CMakeLists.txt  |  2 +-
 compiler-rt/test/memprof/CMakeLists.txt   |  2 +-
 16 files changed, 184 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/Driver/darwin-memprof.c
 create mode 100644 compiler-rt/lib/memprof/memprof_mac.cpp
 create mode 100644 compiler-rt/lib/memprof/memprof_malloc_mac.cpp

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 15b9889157b903c..e3a7a29e196e435 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1505,6 +1505,9 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
,
  "Static sanitizer runtimes not supported");
   AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
 }
+if (Sanitize.needsMemProfRt()) {
+  AddLinkSanitizerLibArgs(Args, CmdArgs, "memprof");
+}
 if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
   AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
 
diff --git a/clang/test/Driver/darwin-memprof.c 
b/clang/test/Driver/darwin-memprof.c
new file mode 100644
index 000..67746d88823b4a8
--- /dev/null
+++ b/clang/test/Driver/darwin-memprof.c
@@ -0,0 +1,13 @@
+// Test sanitizer link flags on Darwin.
+
+// RUN: %clang -### --target=x86_64-darwin \
+// RUN:   -stdlib=platform -fmemory-profile %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MEMPROF %s
+
+// CHECK-MEMPROF: "{{.*}}ld{{(.exe)?}}"
+// CHECK-MEMPROF-NOT: "-lstdc++"
+// CHECK-MEMPROF-NOT: "-lc++"
+// CHECK-MEMPROF: libclang_rt.memprof_osx_dynamic.dylib"
+// CHECK-MEMPROF: "-rpath" "@executable_path"
+// CHECK-MEMPROF: "-rpath" "{{.*}}lib{{.*}}darwin"
+
diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake 
b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 416777171d2ca75..e34f4d8804ddcb8 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -61,7 +61,7 @@ endif()
 set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X}
 ${LOONGARCH64})
 set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${RISCV64})
-set(ALL_MEMPROF_SUPPORTED_ARCH ${X86_64})
+set(ALL_MEMPROF_SUPPORTED_ARCH ${X86_64} ${ARM64})
 set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC32} 
${PPC64}
 ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
 ${RISCV32} ${RISCV64} ${LOONGARCH64})
diff --git a/compiler-rt/cmake/config-ix.cmake 
b/compiler-rt/cmake/config-ix.cmake
index a8e078f1ebc9888..ebf62b2fdb5e8ee 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -446,6 +446,7 @@ if(APPLE)
   endif()
 
   set(SANITIZER_COMMON_SUPPORTED_OS osx)
+  set(MEMPROF_SUPPORTED_OS osx)
   set(PROFILE_SUPPORTED_OS osx)
   set(TSAN_SUPPORTED_OS osx)
   set(XRAY_SUPPORTED_OS osx)
@@ -566,6 +567,7 @@ if(APPLE)
 message(STATUS "${platform} supported arches: 
${DARWIN_${platform}_ARCHS}")
 if(DARWIN_${platform}_ARCHS)
   list(APPEND SANITIZER_COMMON_SUPPORTED_OS ${platform})
+  list(APPEND MEMPROF_SUPPORTED_OS ${platform})
   list(APPEND PROFILE_SUPPORTED_OS ${platform})
 
   list_intersect(DARWIN_${platform}_TSAN_ARCHS 
DARWIN_${platform}_ARCHS ALL_TSAN_SUPPORTED_ARCH)
@@ -782,7 +784,7 @@ else()
 endif()
 
 if (COMPILER_RT_HAS_SANITIZER_COMMON AND MEMPROF_SUPPORTED_ARCH AND
-OS_NAME MATCHES "Linux")
+OS_NAME MATCHES "Darwin|Linux")
   set(COMPILER_RT_HAS_MEMPROF TRUE)
 else()
   set(COMPILER_RT_HAS_MEMPROF FALSE)
diff --git a/compiler-rt/lib/memprof/CMakeLists.txt 
b/compiler-rt/lib/memprof/CMakeLists.txt
index 3f55c2f5e075eed..b8bbcc55da11866 100644
--- a/compiler-rt/lib/memprof/CMakeLists.txt
+++ b/compiler-rt/lib/memprof/CMakeLists.txt
@@ -7,7 +7,9 @@ set(MEMPROF_SOURCES
   memprof_interceptors.cpp
   

[libunwind] [libc++] Implement ranges::contains (PR #65148)

2023-10-19 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/65148

>From 02e9afd761228f401df4d9f8dfaaca44ffae0c6e Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 31 Aug 2023 20:08:32 +
Subject: [PATCH 01/16] [libc++] Implement ranges::contains

Differential Revision: https://reviews.llvm.org/D159232
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__algorithm/ranges_contains.h  |  60 ++
 libcxx/include/algorithm  |   9 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../alg.contains/ranges.contains.pass.cpp | 190 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 265 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 77a7269121ec142..024aa8959fb7200 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains.h 
b/libcxx/include/__algorithm/ranges_contains.h
new file mode 100644
index 000..647b7ea34be3421
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains.h
@@ -0,0 +1,60 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+
+#include <__algorithm/in_in_result.h>
+#include <__algorithm/ranges_find.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains {
+struct __fn {
+  template  _Sent, class _Type, 
class _Proj = identity>
+requires indirect_binary_predicate, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = 
{}) const {
+return ranges::find(std::move(__first), std::move(__last), __value, 
std::ref(__proj)) != __last;
+  }
+
+  template 
+requires indirect_binary_predicate, _Proj>, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
+return ranges::find(ranges::begin(__range), ranges::end(__range), __value, 
std::ref(__proj)) != ranges::end(__range);
+  }
+};
+} // namespace __contains
+inline namespace __cpo {
+inline constexpr auto contains = __contains::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 76e0d22bf73ef85..003bf132b38b4d8 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -226,6 +226,14 @@ namespace ranges {
   template
 using copy_backward_result = in_out_result;
 // since C++20
 
+  template S, class T, class Proj = identity>
+requires indirect_binary_predicate, 
const T*>
+constexpr bool ranges::contains(I first, S last, const T& value, Proj proj 
= {});   // since C++23
+
+  template
+requires indirect_binary_predicate, Proj>, const T*>
+constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
 // since C++23
+
   template S, weakly_incrementable O>
 requires indirectly_copyable
 constexpr ranges::copy_result ranges::copy(I first, S last, O 
result);// since C++20
@@ -1827,6 +1835,7 @@ template 
 #include <__algorithm/ranges_any_of.h>
 #include <__algorithm/ranges_binary_search.h>
 #include <__algorithm/ranges_clamp.h>
+#include <__algorithm/ranges_contains.h>
 #include <__algorithm/ranges_copy.h>
 #include <__algorithm/ranges_copy_backward.h>
 #include <__algorithm/ranges_copy_if.h>
diff --git 

[clang] [C++20] [Modules] [Driver] Don't enable -fdelayed-template-parsing by default on windows with C++20 modules (PR #69431)

2023-10-19 Thread Markus Böck via cfe-commits

zero9178 wrote:

> > According to the docs [0], MSVC actually defaults to 
> > `-fno-delayed-template-parsing` (`/Zc:twoPhase-` with MSVC CLI) if using 
> > C++20. This is due to `-std:c++20` implying `/permissive-` which implies 
> > `/Zc:twoPhase-`. We could therefore just disable it based on language 
> > version alone, not just based on whether we are using modules.
> > I previously tried to make it the default everywhere in 
> > https://reviews.llvm.org/D103772. @rnk argued we could always make it the 
> > default. Given that MSVC is essentially phasing it out and making all their 
> > headers compatible with `/Zc:twoPhase-` for the sake of C++20 support, it 
> > should be more feasible than previously.
> > [0] 
> > https://learn.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-170
> 
> Thanks for the info! It looks like your patch can cover this patch. And we 
> can be sure that this patch itself is correct.
> 
> Would you like to send that patch itself soon? If not, I'd like to land the 
> patch soon to give better user experience. Then you can revert this. If you 
> plan to send that patch soon, I'd like to discard the patch itself.

I sadly won't have the time to push this so feel free to proceed working on 
this PR.

> > > I still support disabling delayed template parsing by default in all 
> > > configurations. Ultimately, this feature is a source of bugs, and we 
> > > should start the clock on its deprecation and removal. This, of course, 
> > > involves real work, and I haven't allocated any time (mine or others') to 
> > > it.
> > 
> > 
> > So @ChuanqiXu9 's patch is at least a conservative step towards that 
> > (limiting the change to C++20 modules where we know there is a problem) - 
> > we could then extend that to C++20, in general (as per @zero9178 's comment 
> > above). As you say deprecation and removal is more work.
> 
> Yeah, how about we at least match MSVC here - and. generalize it to C++20 
> today, leaving the older deprecation work to others/another time?

I would also support this approach as it can also be seen as matching MSVC 
behaviour

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


[clang] [llvm] Use XMACROS for MachO platforms. (PR #69262)

2023-10-19 Thread Juergen Ributzka via cfe-commits

https://github.com/ributzka updated 
https://github.com/llvm/llvm-project/pull/69262

>From d6a4d1cc70e7d3a13b94ff397bef8a0a75e21257 Mon Sep 17 00:00:00 2001
From: Juergen Ributzka 
Date: Mon, 28 Aug 2023 15:25:48 -0700
Subject: [PATCH 1/3] [llvm] Use XMACROS for MachO platforms.

This change adds the PLATFORM XMACRO to simplify the addition of new MachO
platforms and reduce the number of required changes. Many of the changes needed
for adding a new platform are mechanical, such as adding new cases to a switch
statement. This will help streamline the process by consolidating much of the
necessary information into the MachO.def file.
---
 clang/lib/CodeGen/CGObjC.cpp |  2 +-
 llvm/include/llvm/BinaryFormat/MachO.def | 16 ++
 llvm/include/llvm/BinaryFormat/MachO.h   | 14 ++---
 llvm/include/llvm/Object/MachO.h | 14 +++--
 llvm/lib/MC/MCAsmStreamer.cpp| 16 +++---
 llvm/lib/MC/MCParser/DarwinAsmParser.cpp | 14 -
 llvm/lib/TextAPI/Platform.cpp| 39 +---
 llvm/lib/TextAPI/Target.cpp  | 13 ++--
 llvm/lib/TextAPI/TextStub.cpp| 38 +++
 9 files changed, 49 insertions(+), 117 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 6c594b5db4bca1f..aa3a0ff57003d7c 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -3954,7 +3954,7 @@ static unsigned getBaseMachOPlatformID(const llvm::Triple 
) {
   case llvm::Triple::DriverKit:
 return llvm::MachO::PLATFORM_DRIVERKIT;
   default:
-return /*Unknown platform*/ 0;
+return llvm::MachO::PLATFORM_UNKNOWN;
   }
 }
 
diff --git a/llvm/include/llvm/BinaryFormat/MachO.def 
b/llvm/include/llvm/BinaryFormat/MachO.def
index d841b42ee808b2e..70966952ca7efe1 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.def
+++ b/llvm/include/llvm/BinaryFormat/MachO.def
@@ -120,5 +120,21 @@ LOAD_COMMAND_STRUCT(fileset_entry_command)
 
 #endif
 
+#ifdef PLATFORM
+// PLATFORM(platform, id, name, target, tapi_target, marketing)
+PLATFORM(UNKNOWN, 0, unknown, unknown, unknown, unknown)
+PLATFORM(MACOS, 1, macos, macos, macos, macOS)
+PLATFORM(IOS, 2, ios, ios, ios, iOS)
+PLATFORM(TVOS, 3, tvos, tvos, tvos, tvOS)
+PLATFORM(WATCHOS, 4, watchos, watchos, watchos, watchOS)
+PLATFORM(BRIDGEOS, 5, bridgeos, bridgeos, bridgeos, bridgeOS)
+PLATFORM(MACCATALYST, 6, macCatalyst, ios-macabi, maccatalyst, macCatalyst)
+PLATFORM(IOSSIMULATOR, 7, iossimulator, ios-simulator, ios-simulator, iOS 
Simulator)
+PLATFORM(TVOSSIMULATOR, 8, tvossimulator, tvos-simulator, tvos-simulator, tvOS 
Simulator)
+PLATFORM(WATCHOSSIMULATOR, 9, watchossimulator, watchos-simulator, 
watchos-simulator, watchOS Simulator)
+PLATFORM(DRIVERKIT, 10, driverkit, driverkit, driverkit, DriverKit)
+#endif
+
 #undef HANDLE_LOAD_COMMAND
 #undef LOAD_COMMAND_STRUCT
+#undef PLATFORM
diff --git a/llvm/include/llvm/BinaryFormat/MachO.h 
b/llvm/include/llvm/BinaryFormat/MachO.h
index f59cd14c1b5c055..6dfc115c7e905fc 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.h
+++ b/llvm/include/llvm/BinaryFormat/MachO.h
@@ -497,17 +497,9 @@ enum { VM_PROT_READ = 0x1, VM_PROT_WRITE = 0x2, 
VM_PROT_EXECUTE = 0x4 };
 
 // Values for platform field in build_version_command.
 enum PlatformType {
-  PLATFORM_UNKNOWN = 0,
-  PLATFORM_MACOS = 1,
-  PLATFORM_IOS = 2,
-  PLATFORM_TVOS = 3,
-  PLATFORM_WATCHOS = 4,
-  PLATFORM_BRIDGEOS = 5,
-  PLATFORM_MACCATALYST = 6,
-  PLATFORM_IOSSIMULATOR = 7,
-  PLATFORM_TVOSSIMULATOR = 8,
-  PLATFORM_WATCHOSSIMULATOR = 9,
-  PLATFORM_DRIVERKIT = 10,
+#define PLATFORM(platform, id, name, target, tapi_target, marketing)   
\
+  PLATFORM_##platform = id,
+#include "MachO.def"
 };
 
 // Values for tools enum in build_tool_version.
diff --git a/llvm/include/llvm/Object/MachO.h b/llvm/include/llvm/Object/MachO.h
index 894252db538f9e7..7bb2be76ff5b865 100644
--- a/llvm/include/llvm/Object/MachO.h
+++ b/llvm/include/llvm/Object/MachO.h
@@ -789,16 +789,10 @@ class MachOObjectFile : public ObjectFile {
 
   static std::string getBuildPlatform(uint32_t platform) {
 switch (platform) {
-case MachO::PLATFORM_MACOS: return "macos";
-case MachO::PLATFORM_IOS: return "ios";
-case MachO::PLATFORM_TVOS: return "tvos";
-case MachO::PLATFORM_WATCHOS: return "watchos";
-case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
-case MachO::PLATFORM_MACCATALYST: return "macCatalyst";
-case MachO::PLATFORM_IOSSIMULATOR: return "iossimulator";
-case MachO::PLATFORM_TVOSSIMULATOR: return "tvossimulator";
-case MachO::PLATFORM_WATCHOSSIMULATOR: return "watchossimulator";
-case MachO::PLATFORM_DRIVERKIT: return "driverkit";
+#define PLATFORM(platform, id, name, target, tapi_target, marketing)   
\
+  case MachO::PLATFORM_##platform: 
\
+return #name;
+#include "llvm/BinaryFormat/MachO.def"
 default:
   std::string ret;
   

[clang-tools-extra] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-19 Thread Wael Yehia via cfe-commits

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


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


[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-19 Thread Utkarsh Saxena via cfe-commits

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


[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-19 Thread Utkarsh Saxena via cfe-commits

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


[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-19 Thread Utkarsh Saxena via cfe-commits


@@ -960,18 +960,13 @@ static bool shouldAddReversedEqEq(Sema , SourceLocation 
OpLoc,
 return true;
   }
   // Otherwise the search scope is the namespace scope of which F is a member.
-  LookupResult NonMembers(S, NotEqOp, OpLoc,
-  Sema::LookupNameKind::LookupOperatorName);
-  S.LookupName(NonMembers,
-   S.getScopeForContext(EqFD->getEnclosingNamespaceContext()));
-  NonMembers.suppressAccessDiagnostics();
-  for (NamedDecl *Op : NonMembers) {
-auto *FD = Op->getAsFunction();
-if(auto* UD = dyn_cast(Op))
-  FD = UD->getUnderlyingDecl()->getAsFunction();
-if (FunctionsCorrespond(S.Context, EqFD, FD) &&
-declaresSameEntity(cast(EqFD->getDeclContext()),
-   cast(Op->getDeclContext(
+  for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
+auto *NotEqFD = Op->getAsFunction();

usx95 wrote:

Added this test. This fails now as expected.

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


[clang] b2f50b4 - [clang-format][NFC] Use UnwrappedLineParser::eof() for consistency

2023-10-19 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-10-19T13:38:49-07:00
New Revision: b2f50b49a8c45305d27f0393ee6248e3e8851788

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

LOG: [clang-format][NFC] Use UnwrappedLineParser::eof() for consistency

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index bdedfad3b78ba72..7bb487d020ea6f7 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -213,7 +213,7 @@ void UnwrappedLineParser::parse() {
 }
 
 // Create line with eof token.
-assert(FormatTok->is(tok::eof));
+assert(eof());
 pushToken(FormatTok);
 addUnwrappedLine();
 



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


  1   2   3   4   5   >