[llvm] [clang] [clang][llvm][fatlto] Avoid cloning modules in FatLTO (PR #72180)

2023-11-28 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/72180

>From 6f07f561df390cfd1b0f36d510110f4daef0bc54 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 13 Nov 2023 23:54:51 +
Subject: [PATCH 1/3] [clang][llvm][fatlto] Avoid cloning modules in FatLTO

https://github.com/llvm/llvm-project/issues/70703 pointed out that
cloning LLVM modules could lead to miscompiles when using FatLTO.

This is due to an existing issue when cloning modules with labels
(see #55991 and #47769). Since this can lead to miscompilation,
we can avoid cloning the LLVM modules, which was desirable anyway.

This patch modifies the EmbedBitcodePass to no longer clone the module
or run an input pipeline over it. Further, it make FatLTO always perform
UnifiedLTO, so we can still defer the Thin/Full LTO decision to
link-time. Lastly, it removes dead/obsolete code related to now defunct
options that do not work with the EmbedBitcodePass implementation any
longer.
---
 clang/lib/CodeGen/BackendUtil.cpp |  9 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |  4 ++-
 clang/test/CodeGen/fat-lto-objects.c  | 10 +++---
 llvm/docs/FatLTO.rst  | 35 ++-
 llvm/include/llvm/Passes/PassBuilder.h|  3 +-
 .../llvm/Transforms/IPO/EmbedBitcodePass.h| 17 +
 llvm/lib/Passes/PassBuilder.cpp   | 20 ---
 llvm/lib/Passes/PassBuilderPipelines.cpp  | 11 +++---
 llvm/lib/Passes/PassRegistry.def  |  8 +
 llvm/lib/Transforms/IPO/EmbedBitcodePass.cpp  | 16 +
 llvm/test/CodeGen/X86/fat-lto-section.ll  |  2 +-
 llvm/test/Transforms/EmbedBitcode/embed.ll|  3 --
 12 files changed, 39 insertions(+), 99 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index a7a47d17723cb73..4114860545ade1b 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -810,7 +810,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   // Only enable CGProfilePass when using integrated assembler, since
   // non-integrated assemblers don't recognize .cgprofile section.
   PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
-  PTO.UnifiedLTO = CodeGenOpts.UnifiedLTO;
+  PTO.UnifiedLTO = CodeGenOpts.UnifiedLTO || CodeGenOpts.FatLTO;
 
   LoopAnalysisManager LAM;
   FunctionAnalysisManager FAM;
@@ -996,9 +996,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 }
 
 if (CodeGenOpts.FatLTO) {
-  MPM.addPass(PB.buildFatLTODefaultPipeline(
-  Level, PrepareForThinLTO,
-  PrepareForThinLTO || shouldEmitRegularLTOSummary()));
+  MPM.addPass(PB.buildFatLTODefaultPipeline(Level));
 } else if (PrepareForThinLTO) {
   MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(Level));
 } else if (PrepareForLTO) {
@@ -1073,7 +1071,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 if (!TheModule->getModuleFlag("EnableSplitLTOUnit"))
   TheModule->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit",
uint32_t(CodeGenOpts.EnableSplitLTOUnit));
-if (CodeGenOpts.UnifiedLTO && !TheModule->getModuleFlag("UnifiedLTO"))
+// FatLTO always means UnifiedLTO
+if (!TheModule->getModuleFlag("UnifiedLTO"))
   TheModule->addModuleFlag(llvm::Module::Error, "UnifiedLTO", uint32_t(1));
   }
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3b98c7ae6e6ec66..f4cd9cbc5eccdec 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4845,7 +4845,9 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   bool UnifiedLTO = false;
   if (IsUsingLTO) {
 UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
-  options::OPT_fno_unified_lto, Triple.isPS());
+  options::OPT_fno_unified_lto, Triple.isPS()) ||
+ Args.hasFlag(options::OPT_ffat_lto_objects,
+  options::OPT_fno_fat_lto_objects, false);
 if (UnifiedLTO)
   CmdArgs.push_back("-funified-lto");
   }
diff --git a/clang/test/CodeGen/fat-lto-objects.c 
b/clang/test/CodeGen/fat-lto-objects.c
index 2c3a4ef9c615529..6085762fa5a2467 100644
--- a/clang/test/CodeGen/fat-lto-objects.c
+++ b/clang/test/CodeGen/fat-lto-objects.c
@@ -9,22 +9,22 @@
 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full 
-ffat-lto-objects -fsplit-lto-unit -emit-obj < %s -o %t.full.split.o
 // RUN: llvm-readelf -S %t.full.split.o | FileCheck %s --check-prefixes=ELF
 // RUN: llvm-objcopy --dump-section=.llvm.lto=%t.full.split.bc %t.full.split.o
-// RUN: llvm-dis %t.full.split.bc -o - | FileCheck %s 
--check-prefixes=FULL,SPLIT,NOUNIFIED
+// RUN: llvm-dis %t.full.split.bc -o - | FileCheck %s 
--check-prefixes=FULL,SPLIT,UNIFIED
 
 // RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full 
-ffat-lto-objects -emit-obj < %s -o 

[llvm] [clang] [clang-tools-extra] [AMDGPU] Fix folding of v2i16/v2f16 splat imms (PR #72709)

2023-11-28 Thread Stanislav Mekhanoshin via cfe-commits

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


[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/73124

>From 2a2693364cb8e9b657b9ff54aa78df0466b55fe4 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 14:22:20 +0100
Subject: [PATCH 01/16] Let the linker fail on multiple definitions of main()

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 1f31c6395206ee8..740ae71177b2c3a 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -982,7 +982,20 @@ void tools::addFortranRuntimeLibs(const ToolChain ,
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// --whole-archive needs to be part of the link line to make sure
+// that the main() function from Fortran_main.a is pulled in by
+// the linker.
+//
+// We are using this --whole-archive/--no-whole-archive bracket w/o
+// any further checks, because -Wl,--whole-archive at the flang-new new
+// line will not sucessfully complete, unless the user correctly specified
+// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
+// -Wl,--no-whole-archive).
+CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
+CmdArgs.push_back("--no-whole-archive");
+
+// Perform regular linkage of the remaining runtime libraries.
 CmdArgs.push_back("-lFortranRuntime");
 CmdArgs.push_back("-lFortranDecimal");
   }
@@ -993,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
,
  ArgStringList ) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to use
+  // this in the future. In particular, on some platforms, we may need to useq
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 0d652282f4dbed2dde11df53ead3e6c8b6856bed Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 15:18:51 +0100
Subject: [PATCH 02/16] Improve comments and remove accidental typo

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 740ae71177b2c3a..464a87737de062c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -987,10 +987,10 @@ void tools::addFortranRuntimeLibs(const ToolChain ,
 // the linker.
 //
 // We are using this --whole-archive/--no-whole-archive bracket w/o
-// any further checks, because -Wl,--whole-archive at the flang-new new
-// line will not sucessfully complete, unless the user correctly specified
-// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
-// -Wl,--no-whole-archive).
+// any further checks, because -Wl,--whole-archive at the flang
+// driver's link line will not sucessfully complete, unless the user
+// correctly specified -Wl,--whole-archive/-Wl,--no-whole-archive
+// (e.g., -Wl,--whole-archive -ldummy -Wl,--no-whole-archive).
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
 CmdArgs.push_back("--no-whole-archive");
@@ -1006,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
,
  ArgStringList ) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to useq
+  // this in the future. In particular, on some platforms, we may need to use
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 39612e237cb815cf4ea0120027783d35304bcb6b Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 20:26:02 +0100
Subject: [PATCH 03/16] Correct link line test for flang-new (for Linux)

---
 flang/test/Driver/linker-flags.f90 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 85c4d60b3f09862..ea91946316cfaa6 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -28,7 +28,7 @@
 !   executable and may find the GNU linker from MinGW or Cygwin.
 ! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! UNIX-SAME: "[[object_file]]"
-! UNIX-SAME: "-lFortran_main" "-lFortranRuntime" 

[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Michael Klemm via cfe-commits


@@ -977,14 +977,61 @@ bool tools::addOpenMPRuntime(ArgStringList , 
const ToolChain ,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain ,
+void tools::addFortranRuntimeLibs(const ToolChain , const ArgList ,
   llvm::opt::ArgStringList ) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// The --whole-archive option needs to be part of the link line to
+// make sure that the main() function from Fortran_main.a is pulled
+// in by the linker.  Determine if --whole-archive is active when
+// flang will try to link Fortran_main.a.  If it is, don't add the
+// --whole-archive flag to the link line.  If it's not, add a proper
+// --whole-archive/--no-whole-archive bracket to the link line.
+bool NeedWholeArchive = true;
+auto * Arg = Args.getLastArg(options::OPT_Wl_COMMA);

mjklemm wrote:

Should be fixed, too.

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


[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Michael Klemm via cfe-commits


@@ -977,14 +977,61 @@ bool tools::addOpenMPRuntime(ArgStringList , 
const ToolChain ,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain ,
+void tools::addFortranRuntimeLibs(const ToolChain , const ArgList ,
   llvm::opt::ArgStringList ) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// The --whole-archive option needs to be part of the link line to
+// make sure that the main() function from Fortran_main.a is pulled
+// in by the linker.  Determine if --whole-archive is active when
+// flang will try to link Fortran_main.a.  If it is, don't add the
+// --whole-archive flag to the link line.  If it's not, add a proper
+// --whole-archive/--no-whole-archive bracket to the link line.
+bool NeedWholeArchive = true;
+auto * Arg = Args.getLastArg(options::OPT_Wl_COMMA);
+for (StringRef ArgValue : llvm::reverse(Arg->getValues())) {
+  if (ArgValue == "--whole-archive") {
+NeedWholeArchive = false;
+break;
+  }

mjklemm wrote:

Should be fixed now.

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


[clang-tools-extra] [llvm] [clang] [STLExtras] Add out-of-line definition of friend operator== for C++20 (PR #72348)

2023-11-28 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

Update: I verified that this change works fine with clang-17.0.6 and fails with 
clang-17.0.5 in C++20.

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/73124

>From 2a2693364cb8e9b657b9ff54aa78df0466b55fe4 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 14:22:20 +0100
Subject: [PATCH 01/16] Let the linker fail on multiple definitions of main()

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 1f31c6395206ee8..740ae71177b2c3a 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -982,7 +982,20 @@ void tools::addFortranRuntimeLibs(const ToolChain ,
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// --whole-archive needs to be part of the link line to make sure
+// that the main() function from Fortran_main.a is pulled in by
+// the linker.
+//
+// We are using this --whole-archive/--no-whole-archive bracket w/o
+// any further checks, because -Wl,--whole-archive at the flang-new new
+// line will not sucessfully complete, unless the user correctly specified
+// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
+// -Wl,--no-whole-archive).
+CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
+CmdArgs.push_back("--no-whole-archive");
+
+// Perform regular linkage of the remaining runtime libraries.
 CmdArgs.push_back("-lFortranRuntime");
 CmdArgs.push_back("-lFortranDecimal");
   }
@@ -993,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
,
  ArgStringList ) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to use
+  // this in the future. In particular, on some platforms, we may need to useq
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 0d652282f4dbed2dde11df53ead3e6c8b6856bed Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 15:18:51 +0100
Subject: [PATCH 02/16] Improve comments and remove accidental typo

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 740ae71177b2c3a..464a87737de062c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -987,10 +987,10 @@ void tools::addFortranRuntimeLibs(const ToolChain ,
 // the linker.
 //
 // We are using this --whole-archive/--no-whole-archive bracket w/o
-// any further checks, because -Wl,--whole-archive at the flang-new new
-// line will not sucessfully complete, unless the user correctly specified
-// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
-// -Wl,--no-whole-archive).
+// any further checks, because -Wl,--whole-archive at the flang
+// driver's link line will not sucessfully complete, unless the user
+// correctly specified -Wl,--whole-archive/-Wl,--no-whole-archive
+// (e.g., -Wl,--whole-archive -ldummy -Wl,--no-whole-archive).
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
 CmdArgs.push_back("--no-whole-archive");
@@ -1006,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
,
  ArgStringList ) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to useq
+  // this in the future. In particular, on some platforms, we may need to use
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 39612e237cb815cf4ea0120027783d35304bcb6b Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 20:26:02 +0100
Subject: [PATCH 03/16] Correct link line test for flang-new (for Linux)

---
 flang/test/Driver/linker-flags.f90 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 85c4d60b3f09862..ea91946316cfaa6 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -28,7 +28,7 @@
 !   executable and may find the GNU linker from MinGW or Cygwin.
 ! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! UNIX-SAME: "[[object_file]]"
-! UNIX-SAME: "-lFortran_main" "-lFortranRuntime" 

[clang] [clang] Remove unused argument. NFC. (PR #73594)

2023-11-28 Thread Adrian Prantl via cfe-commits

https://github.com/adrian-prantl approved this pull request.

I can't even remember what this was supposed to do.

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -14240,6 +14294,114 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind getConversionKind(QualType FromType,
+QualType ToType) {
+  if (ToType->isIntegerType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Integral;
+if (FromType->isIntegerType())
+  return ICK_Integral_Conversion;
+  }
+
+  if (ToType->isFloatingType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Conversion;
+if (FromType->isIntegerType())
+  return ICK_Floating_Integral;
+  }
+
+  return ICK_Identity;
+}
+
+static bool checkC23ConstexprInitConversion(Sema , const Expr *Init) {
+  assert(S.getLangOpts().C23);
+  const Expr *InitNoCast = Init->IgnoreImpCasts();
+  StandardConversionSequence SCS;
+  SCS.setAsIdentityConversion();
+  auto FromType = InitNoCast->getType();
+  auto ToType = Init->getType();
+  SCS.setToType(0, FromType);
+  SCS.setToType(1, ToType);
+  SCS.Second = getConversionKind(FromType, ToType);
+
+  APValue Value;
+  QualType PreNarrowingType;
+  // Reuse C++ narrowing check.
+  switch (SCS.getNarrowingKind(S.Context, Init, Value, PreNarrowingType,
+   /*IgnoreFloatToIntegralConversion*/ false)) {
+  // The value doesn't fit.
+  case NK_Constant_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_not_representable)
+<< Value.getAsString(S.Context, PreNarrowingType) << ToType;
+return true;
+
+  // Conversion to a narrower type.
+  case NK_Type_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_type_mismatch)
+<< ToType << FromType;
+return true;
+
+  // Since we only reuse narrowing check for C23 constexpr variables here, 
we're
+  // not really interested in these cases.
+  case NK_Dependent_Narrowing:
+  case NK_Variable_Narrowing:
+  case NK_Not_Narrowing:
+return false;
+  }
+  llvm_unreachable("unhandled case in switch");
+}
+
+static bool checkC23ConstexprInitStringLiteral(const StringLiteral *SE,
+   Sema ,
+   SourceLocation Loc) {
+  assert(SemaRef.getLangOpts().C23);
+  // String literals have the target type attached but underneath may contain
+  // values that don't really fit into the target type. Check that every
+  // character fits.
+  const ConstantArrayType *CAT =
+  SemaRef.Context.getAsConstantArrayType(SE->getType());
+  QualType CharType = CAT->getElementType();
+  uint32_t BitWidth = SemaRef.Context.getTypeSize(CharType);
+  bool isUnsigned = CharType->isUnsignedIntegerType();
+  llvm::APSInt Value(BitWidth, isUnsigned);
+  const StringRef S = SE->getBytes();
+  for (unsigned I = 0, N = SE->getLength(); I != N; ++I) {
+Value = S[I];
+if (Value != S[I]) {
+  SemaRef.Diag(Loc, diag::err_c23_constexpr_init_not_representable)
+  << S[I] << CharType;
+  return true;
+}
+  }
+  return false;
+}
+
+static bool checkC23ConstexprInitializer(Sema , const Expr *Init) {
+  const Expr *InitNoCast = Init->IgnoreImpCasts();
+  if (Init->getType() != InitNoCast->getType())
+if (checkC23ConstexprInitConversion(S, Init))
+  return true;
+
+  if (auto *SE = dyn_cast(Init))
+if (checkC23ConstexprInitStringLiteral(SE, S, Init->getBeginLoc()))
+  return true;
+
+  for (const Stmt *SubStmt : Init->children()) {
+const Expr *ChildExpr = dyn_cast_or_null(SubStmt);

AaronBallman wrote:

```suggestion
const Expr *ChildExpr = dyn_cast_or_null(SubStmt);
```

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -8605,6 +8620,28 @@ static bool checkForConflictWithNonVisibleExternC(Sema 
, const T *ND,
   return false;
 }
 
+static bool CheckC23ConstexprVarTypeQualifiers(Sema ,
+   SourceLocation VarLoc,
+   QualType T) {
+  if (const auto *A = SemaRef.Context.getAsArrayType(T)) {
+T = A->getElementType();
+  }

AaronBallman wrote:

```suggestion
  // Arrays are qualified by their element type, so get the base type (this 
works on non-arrays as well).
  T = SemaRef.Context.getBaseElementType(T);
```

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -14240,6 +14294,114 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind getConversionKind(QualType FromType,
+QualType ToType) {
+  if (ToType->isIntegerType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Integral;
+if (FromType->isIntegerType())
+  return ICK_Integral_Conversion;
+  }
+
+  if (ToType->isFloatingType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Conversion;
+if (FromType->isIntegerType())
+  return ICK_Floating_Integral;
+  }
+
+  return ICK_Identity;
+}
+
+static bool checkC23ConstexprInitConversion(Sema , const Expr *Init) {
+  assert(S.getLangOpts().C23);
+  const Expr *InitNoCast = Init->IgnoreImpCasts();
+  StandardConversionSequence SCS;
+  SCS.setAsIdentityConversion();
+  auto FromType = InitNoCast->getType();
+  auto ToType = Init->getType();
+  SCS.setToType(0, FromType);
+  SCS.setToType(1, ToType);
+  SCS.Second = getConversionKind(FromType, ToType);
+
+  APValue Value;
+  QualType PreNarrowingType;
+  // Reuse C++ narrowing check.
+  switch (SCS.getNarrowingKind(S.Context, Init, Value, PreNarrowingType,
+   /*IgnoreFloatToIntegralConversion*/ false)) {
+  // The value doesn't fit.
+  case NK_Constant_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_not_representable)
+<< Value.getAsString(S.Context, PreNarrowingType) << ToType;
+return true;
+
+  // Conversion to a narrower type.
+  case NK_Type_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_type_mismatch)
+<< ToType << FromType;
+return true;
+
+  // Since we only reuse narrowing check for C23 constexpr variables here, 
we're
+  // not really interested in these cases.
+  case NK_Dependent_Narrowing:
+  case NK_Variable_Narrowing:
+  case NK_Not_Narrowing:
+return false;
+  }
+  llvm_unreachable("unhandled case in switch");
+}
+
+static bool checkC23ConstexprInitStringLiteral(const StringLiteral *SE,
+   Sema ,
+   SourceLocation Loc) {
+  assert(SemaRef.getLangOpts().C23);
+  // String literals have the target type attached but underneath may contain
+  // values that don't really fit into the target type. Check that every
+  // character fits.
+  const ConstantArrayType *CAT =
+  SemaRef.Context.getAsConstantArrayType(SE->getType());
+  QualType CharType = CAT->getElementType();
+  uint32_t BitWidth = SemaRef.Context.getTypeSize(CharType);
+  bool isUnsigned = CharType->isUnsignedIntegerType();
+  llvm::APSInt Value(BitWidth, isUnsigned);
+  const StringRef S = SE->getBytes();
+  for (unsigned I = 0, N = SE->getLength(); I != N; ++I) {
+Value = S[I];
+if (Value != S[I]) {
+  SemaRef.Diag(Loc, diag::err_c23_constexpr_init_not_representable)
+  << S[I] << CharType;
+  return true;
+}
+  }
+  return false;
+}
+
+static bool checkC23ConstexprInitializer(Sema , const Expr *Init) {
+  const Expr *InitNoCast = Init->IgnoreImpCasts();
+  if (Init->getType() != InitNoCast->getType())
+if (checkC23ConstexprInitConversion(S, Init))
+  return true;
+
+  if (auto *SE = dyn_cast(Init))
+if (checkC23ConstexprInitStringLiteral(SE, S, Init->getBeginLoc()))
+  return true;
+
+  for (const Stmt *SubStmt : Init->children()) {
+const Expr *ChildExpr = dyn_cast_or_null(SubStmt);
+if (!ChildExpr)
+  continue;
+
+if (checkC23ConstexprInitializer(S, ChildExpr)) {
+  return true;
+}

AaronBallman wrote:

```suggestion
if (checkC23ConstexprInitializer(S, ChildExpr))
  return true;
```

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,86 @@
+// RUN: %clang_cc1 -std=c2x -verify -triple x86_64 -pedantic -Wno-conversion 
-Wno-constant-conversion %s
+
+/* WG14 N3018: Full
+ * The constexpr specifier for object definitions
+ */
+
+#define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
+#define UINT_MAX  (__INT_MAX__  *2U +1U)
+
+void Example0() {
+  constexpr unsigned int minusOne= -1;
+  // expected-error@-1 {{constexpr initializer evaluates to -1 which is not 
exactly representable in type 'unsigned int'}}
+  constexpr unsigned int uint_max= -1U;
+  constexpr double onethird  = 1.0/3.0;
+  constexpr double onethirdtrunc = (double)(1.0/3.0);
+
+  constexpr char string[] = { "\xFF", };

AaronBallman wrote:

It'd be good to have a test with wide strings and another one with concatenated 
strings. e.g.,
```
constexpr char string[] = "test""ing this out\xFF";
```

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -14240,6 +14294,114 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind getConversionKind(QualType FromType,
+QualType ToType) {
+  if (ToType->isIntegerType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Integral;
+if (FromType->isIntegerType())
+  return ICK_Integral_Conversion;
+  }
+
+  if (ToType->isFloatingType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Conversion;
+if (FromType->isIntegerType())
+  return ICK_Floating_Integral;
+  }
+
+  return ICK_Identity;
+}
+
+static bool checkC23ConstexprInitConversion(Sema , const Expr *Init) {
+  assert(S.getLangOpts().C23);
+  const Expr *InitNoCast = Init->IgnoreImpCasts();
+  StandardConversionSequence SCS;
+  SCS.setAsIdentityConversion();
+  auto FromType = InitNoCast->getType();
+  auto ToType = Init->getType();
+  SCS.setToType(0, FromType);
+  SCS.setToType(1, ToType);
+  SCS.Second = getConversionKind(FromType, ToType);
+
+  APValue Value;
+  QualType PreNarrowingType;
+  // Reuse C++ narrowing check.
+  switch (SCS.getNarrowingKind(S.Context, Init, Value, PreNarrowingType,
+   /*IgnoreFloatToIntegralConversion*/ false)) {
+  // The value doesn't fit.
+  case NK_Constant_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_not_representable)
+<< Value.getAsString(S.Context, PreNarrowingType) << ToType;
+return true;
+
+  // Conversion to a narrower type.
+  case NK_Type_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_type_mismatch)
+<< ToType << FromType;
+return true;
+
+  // Since we only reuse narrowing check for C23 constexpr variables here, 
we're
+  // not really interested in these cases.
+  case NK_Dependent_Narrowing:
+  case NK_Variable_Narrowing:
+  case NK_Not_Narrowing:
+return false;
+  }
+  llvm_unreachable("unhandled case in switch");
+}
+
+static bool checkC23ConstexprInitStringLiteral(const StringLiteral *SE,
+   Sema ,
+   SourceLocation Loc) {
+  assert(SemaRef.getLangOpts().C23);
+  // String literals have the target type attached but underneath may contain
+  // values that don't really fit into the target type. Check that every
+  // character fits.
+  const ConstantArrayType *CAT =
+  SemaRef.Context.getAsConstantArrayType(SE->getType());
+  QualType CharType = CAT->getElementType();
+  uint32_t BitWidth = SemaRef.Context.getTypeSize(CharType);
+  bool isUnsigned = CharType->isUnsignedIntegerType();
+  llvm::APSInt Value(BitWidth, isUnsigned);
+  const StringRef S = SE->getBytes();
+  for (unsigned I = 0, N = SE->getLength(); I != N; ++I) {
+Value = S[I];
+if (Value != S[I]) {
+  SemaRef.Diag(Loc, diag::err_c23_constexpr_init_not_representable)
+  << S[I] << CharType;
+  return true;
+}
+  }
+  return false;
+}
+
+static bool checkC23ConstexprInitializer(Sema , const Expr *Init) {
+  const Expr *InitNoCast = Init->IgnoreImpCasts();
+  if (Init->getType() != InitNoCast->getType())
+if (checkC23ConstexprInitConversion(S, Init))
+  return true;
+
+  if (auto *SE = dyn_cast(Init))

AaronBallman wrote:

```suggestion
  if (const auto *SE = dyn_cast(Init))
```

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -9237,6 +9282,22 @@ static FunctionDecl *CreateNewFunctionDecl(Sema 
, Declarator ,
   FunctionDecl *NewFD = nullptr;
   bool isInline = D.getDeclSpec().isInlineSpecified();
 
+  ConstexprSpecKind ConstexprKind = D.getDeclSpec().getConstexprSpecifier();
+  if (ConstexprKind == ConstexprSpecKind::Constinit ||
+  (SemaRef.getLangOpts().C23 &&
+   ConstexprKind == ConstexprSpecKind::Constexpr)) {
+
+if (SemaRef.getLangOpts().C23)
+  SemaRef.Diag(D.getDeclSpec().getConstexprSpecLoc(),
+   diag::err_c23_constexpr_not_variable);

AaronBallman wrote:

Hmmm, I'm not certain we need to change anything here, but it would be more 
clear to say that a function cannot be constexpr in C instead of saying you 
declared something constexpr that isn't a variable. WDYT?

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -8857,7 +8894,9 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
 
   if (NewVD->isConstexpr() && !T->isDependentType() &&
   RequireLiteralType(NewVD->getLocation(), T,
- diag::err_constexpr_var_non_literal)) {
+ getLangOpts().C23
+ ? diag::err_c23_constexpr_invalid_type
+ : diag::err_constexpr_var_non_literal)) {

AaronBallman wrote:

Do we need a different diagnostic here from C++? C doesn't have the same notion 
of "literal type" as C++, but that is the predicate we're checking.

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -14240,6 +14294,114 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind getConversionKind(QualType FromType,
+QualType ToType) {
+  if (ToType->isIntegerType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Integral;
+if (FromType->isIntegerType())
+  return ICK_Integral_Conversion;
+  }
+
+  if (ToType->isFloatingType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Conversion;
+if (FromType->isIntegerType())
+  return ICK_Floating_Integral;
+  }
+
+  return ICK_Identity;
+}
+
+static bool checkC23ConstexprInitConversion(Sema , const Expr *Init) {
+  assert(S.getLangOpts().C23);
+  const Expr *InitNoCast = Init->IgnoreImpCasts();
+  StandardConversionSequence SCS;
+  SCS.setAsIdentityConversion();
+  auto FromType = InitNoCast->getType();
+  auto ToType = Init->getType();
+  SCS.setToType(0, FromType);
+  SCS.setToType(1, ToType);
+  SCS.Second = getConversionKind(FromType, ToType);
+
+  APValue Value;
+  QualType PreNarrowingType;
+  // Reuse C++ narrowing check.
+  switch (SCS.getNarrowingKind(S.Context, Init, Value, PreNarrowingType,
+   /*IgnoreFloatToIntegralConversion*/ false)) {
+  // The value doesn't fit.
+  case NK_Constant_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_not_representable)
+<< Value.getAsString(S.Context, PreNarrowingType) << ToType;
+return true;
+
+  // Conversion to a narrower type.
+  case NK_Type_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_type_mismatch)
+<< ToType << FromType;
+return true;
+
+  // Since we only reuse narrowing check for C23 constexpr variables here, 
we're
+  // not really interested in these cases.
+  case NK_Dependent_Narrowing:
+  case NK_Variable_Narrowing:
+  case NK_Not_Narrowing:
+return false;
+  }
+  llvm_unreachable("unhandled case in switch");
+}
+
+static bool checkC23ConstexprInitStringLiteral(const StringLiteral *SE,
+   Sema ,
+   SourceLocation Loc) {
+  assert(SemaRef.getLangOpts().C23);
+  // String literals have the target type attached but underneath may contain
+  // values that don't really fit into the target type. Check that every
+  // character fits.
+  const ConstantArrayType *CAT =
+  SemaRef.Context.getAsConstantArrayType(SE->getType());
+  QualType CharType = CAT->getElementType();
+  uint32_t BitWidth = SemaRef.Context.getTypeSize(CharType);
+  bool isUnsigned = CharType->isUnsignedIntegerType();
+  llvm::APSInt Value(BitWidth, isUnsigned);
+  const StringRef S = SE->getBytes();
+  for (unsigned I = 0, N = SE->getLength(); I != N; ++I) {

AaronBallman wrote:

Should we be iterating over code units instead of bytes? CC @cor3ntin 

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -14397,17 +14559,21 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
   QualType baseType = Context.getBaseElementType(type);
   bool HasConstInit = true;
 
+  if (getLangOpts().C23 && var->isConstexpr() && !Init)
+Diag(var->getLocation(), diag::err_constexpr_var_requires_const_init)
+<< var;

AaronBallman wrote:

Is there a reason the existing logic below doesn't suffice and we need a 
separate code path here?

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -14240,6 +14294,114 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind getConversionKind(QualType FromType,
+QualType ToType) {
+  if (ToType->isIntegerType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Integral;
+if (FromType->isIntegerType())
+  return ICK_Integral_Conversion;
+  }
+
+  if (ToType->isFloatingType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Conversion;
+if (FromType->isIntegerType())
+  return ICK_Floating_Integral;
+  }
+
+  return ICK_Identity;
+}
+
+static bool checkC23ConstexprInitConversion(Sema , const Expr *Init) {
+  assert(S.getLangOpts().C23);
+  const Expr *InitNoCast = Init->IgnoreImpCasts();
+  StandardConversionSequence SCS;
+  SCS.setAsIdentityConversion();
+  auto FromType = InitNoCast->getType();
+  auto ToType = Init->getType();
+  SCS.setToType(0, FromType);
+  SCS.setToType(1, ToType);
+  SCS.Second = getConversionKind(FromType, ToType);
+
+  APValue Value;
+  QualType PreNarrowingType;
+  // Reuse C++ narrowing check.
+  switch (SCS.getNarrowingKind(S.Context, Init, Value, PreNarrowingType,
+   /*IgnoreFloatToIntegralConversion*/ false)) {
+  // The value doesn't fit.
+  case NK_Constant_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_not_representable)
+<< Value.getAsString(S.Context, PreNarrowingType) << ToType;
+return true;
+
+  // Conversion to a narrower type.
+  case NK_Type_Narrowing:
+S.Diag(Init->getBeginLoc(), diag::err_c23_constexpr_init_type_mismatch)
+<< ToType << FromType;
+return true;
+
+  // Since we only reuse narrowing check for C23 constexpr variables here, 
we're
+  // not really interested in these cases.
+  case NK_Dependent_Narrowing:
+  case NK_Variable_Narrowing:
+  case NK_Not_Narrowing:
+return false;
+  }
+  llvm_unreachable("unhandled case in switch");
+}
+
+static bool checkC23ConstexprInitStringLiteral(const StringLiteral *SE,
+   Sema ,
+   SourceLocation Loc) {
+  assert(SemaRef.getLangOpts().C23);
+  // String literals have the target type attached but underneath may contain
+  // values that don't really fit into the target type. Check that every
+  // character fits.
+  const ConstantArrayType *CAT =
+  SemaRef.Context.getAsConstantArrayType(SE->getType());
+  QualType CharType = CAT->getElementType();
+  uint32_t BitWidth = SemaRef.Context.getTypeSize(CharType);
+  bool isUnsigned = CharType->isUnsignedIntegerType();
+  llvm::APSInt Value(BitWidth, isUnsigned);
+  const StringRef S = SE->getBytes();
+  for (unsigned I = 0, N = SE->getLength(); I != N; ++I) {
+Value = S[I];
+if (Value != S[I]) {
+  SemaRef.Diag(Loc, diag::err_c23_constexpr_init_not_representable)
+  << S[I] << CharType;
+  return true;
+}
+  }
+  return false;
+}
+
+static bool checkC23ConstexprInitializer(Sema , const Expr *Init) {

AaronBallman wrote:

```suggestion
static bool CheckC23ConstexprInitializer(Sema , const Expr *Init) {
```

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -2932,6 +2932,22 @@ def warn_private_extern : Warning<
 def note_private_extern : Note<
   "use __attribute__((visibility(\"hidden\"))) attribute instead">;
 
+// C23 constexpr
+def err_c23_thread_local_constexpr : Error<
+  "thread-local storage is not allowed with constexpr">;
+def err_c23_extern_constexpr : Error<
+  "extern specifier is not allowed with constexpr">;

AaronBallman wrote:

I think we want to reuse `err_invalid_decl_spec_combination` for these 
diagnostics; and probably issue the diagnostic from `DeclSpec::Finish()` as 
well (which is where we diagnose other invalid combinations of declaration 
specifiers).

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -14240,6 +14294,114 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind getConversionKind(QualType FromType,
+QualType ToType) {
+  if (ToType->isIntegerType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Integral;
+if (FromType->isIntegerType())
+  return ICK_Integral_Conversion;
+  }
+
+  if (ToType->isFloatingType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Conversion;
+if (FromType->isIntegerType())
+  return ICK_Floating_Integral;
+  }
+
+  return ICK_Identity;
+}
+
+static bool checkC23ConstexprInitConversion(Sema , const Expr *Init) {

AaronBallman wrote:

```suggestion
static bool CheckC23ConstexprInitConversion(Sema , const Expr *Init) {
```

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -4110,6 +4116,10 @@ static CompleteObject findCompleteObject(EvalInfo , 
const Expr *E,
 }
 
 bool IsConstant = BaseType.isConstant(Info.Ctx);
+bool ConstexprVar = false;
+if (const auto *VD = dyn_cast_if_present(
+Info.EvaluatingDecl.dyn_cast()))
+  ConstexprVar = VD->isConstexpr();

AaronBallman wrote:

Can you explain these two changes a bit (the one here and the one on line 4142)?

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for working on this! First round of comments done (I've not 
thoroughly reviewed the test cases yet though).

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -2932,6 +2932,22 @@ def warn_private_extern : Warning<
 def note_private_extern : Note<
   "use __attribute__((visibility(\"hidden\"))) attribute instead">;
 
+// C23 constexpr
+def err_c23_thread_local_constexpr : Error<
+  "thread-local storage is not allowed with constexpr">;
+def err_c23_extern_constexpr : Error<
+  "extern specifier is not allowed with constexpr">;
+def err_c23_constexpr_not_variable : Error<
+  "constexpr is only allowed in variable declarations">;

AaronBallman wrote:

```suggestion
  "'constexpr' can only be used in variable declarations">;
```

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -208,6 +208,7 @@ C23 Feature Support
 
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
+- Clang now supports ``N3018 The constexpr specifier for object definitions``.

AaronBallman wrote:

```suggestion
- Clang now supports `N3018 The constexpr specifier for object definitions 
`_.
```

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -7894,6 +7898,17 @@ NamedDecl *Sema::ActOnVariableDeclarator(
 (getLangOpts().CPlusPlus17 ||
  Context.getTargetInfo().getCXXABI().isMicrosoft()))
   NewVD->setImplicitlyInline();
+
+if (getLangOpts().C23) {
+  DeclSpec::TSCS TSC = D.getDeclSpec().getThreadStorageClassSpec();
+  if (TSC != TSCS_unspecified) {
+Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(),
+ diag::err_c23_thread_local_constexpr);
+  }
+  if (NewVD->hasExternalStorage())
+Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(),
+ diag::err_c23_extern_constexpr);

AaronBallman wrote:

I think this is better handled by `DeclSpec::Finish()`, WDYT?

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -14240,6 +14294,114 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind getConversionKind(QualType FromType,

AaronBallman wrote:

```suggestion
static ImplicitConversionKind GetConversionKind(QualType FromType,
```

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -2231,6 +2231,12 @@ static bool CheckLValueConstantExpression(EvalInfo 
, SourceLocation Loc,
 return false;
   }
 
+  if (Info.getLangOpts().C23) {

AaronBallman wrote:

```suggestion
  // C23 6.7.1p6: If an object or subobject declared with storage-class 
specifier constexpr has pointer, 
  // integer, or arithmetic type, any explicit initializer value for it shall 
be null, an integer constant 
  // expression, or an arithmetic constant expression, respectively.
  if (Info.getLangOpts().C23) {
```
May need to adjust for 80-col limits.

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -14240,6 +14294,114 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, 
SourceLocation IdentLoc,
   : IdentLoc);
 }
 
+static ImplicitConversionKind getConversionKind(QualType FromType,
+QualType ToType) {
+  if (ToType->isIntegerType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Integral;
+if (FromType->isIntegerType())
+  return ICK_Integral_Conversion;
+  }
+
+  if (ToType->isFloatingType()) {
+if (FromType->isComplexType())
+  return ICK_Complex_Real;
+if (FromType->isFloatingType())
+  return ICK_Floating_Conversion;
+if (FromType->isIntegerType())
+  return ICK_Floating_Integral;
+  }
+
+  return ICK_Identity;
+}
+
+static bool checkC23ConstexprInitConversion(Sema , const Expr *Init) {
+  assert(S.getLangOpts().C23);
+  const Expr *InitNoCast = Init->IgnoreImpCasts();

AaronBallman wrote:

We probably want to ignore paren expressions as well.

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


[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

2023-11-28 Thread Aaron Ballman via cfe-commits


@@ -5152,13 +5152,17 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, 
AccessSpecifier AS,
 // and definitions of functions and variables.
 // C++2a [dcl.constexpr]p1: The consteval specifier shall be applied only 
to
 // the declaration of a function or function template
-if (Tag)
+if (Tag) {
   Diag(DS.getConstexprSpecLoc(), diag::err_constexpr_tag)
   << GetDiagnosticTypeSpecifierID(DS)
   << static_cast(DS.getConstexprSpecifier());
-else
-  Diag(DS.getConstexprSpecLoc(), diag::err_constexpr_wrong_decl_kind)
-  << static_cast(DS.getConstexprSpecifier());
+} else {
+  if (getLangOpts().C23)
+Diag(DS.getConstexprSpecLoc(), diag::err_c23_constexpr_not_variable);
+  else
+Diag(DS.getConstexprSpecLoc(), diag::err_constexpr_wrong_decl_kind)
+<< static_cast(DS.getConstexprSpecifier());
+}

AaronBallman wrote:

```suggestion
else if (getLangOpts().C23)
Diag(DS.getConstexprSpecLoc(), diag::err_c23_constexpr_not_variable);
else
  Diag(DS.getConstexprSpecLoc(), diag::err_constexpr_wrong_decl_kind)
  << static_cast(DS.getConstexprSpecifier());
```
(and can remove the inserted brace above, which GitHub helpfully won't let me 
add to the suggested edits..)

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


[libc] [compiler-rt] [clang] [libcxx] [llvm] [lldb] [flang] [clang-tools-extra] ✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)

2023-11-28 Thread via cfe-commits

cor3ntin wrote:

> So it's not so much that it's not actually true in the implementation 
> details, it's that it's not actually true by specification either.

+1. I really do not want `-E` to start not expanding, or transforming 
directives.
I do not see a difference between a large embed and a large include file. `-E` 
should expand both, regardless of size. Modify that very long standing behavior 
only cause pain and confusion imo.

If, we find the need for a fancier behavior (like the aforementioned 
`#embed_base64`), it's something we could consider later, under an additional 
switch (not `-E` without other flag)

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


[lld] [lldb] [openmp] [libcxx] [mlir] [compiler-rt] [flang] [llvm] [clang-tools-extra] [libc] [clang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-28 Thread Sang Ik Lee via cfe-commits


@@ -0,0 +1,31 @@
+//===- SPIRVToLLVMIRTranslation.cpp - Translate SPIRV to LLVM IR 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements a translation between the MLIR SPIRV dialect and
+// LLVM IR.
+//
+//===--===//
+
+#include "mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/IR/Operation.h"
+#include "mlir/Target/LLVMIR/ModuleTranslation.h"
+
+using namespace mlir;
+using namespace mlir::LLVM;
+
+void mlir::registerSPIRVDialectTranslation(DialectRegistry ) {
+  registry.insert();

silee2 wrote:

@joker-eph 

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


[lld] [lldb] [openmp] [libcxx] [mlir] [compiler-rt] [flang] [llvm] [clang-tools-extra] [libc] [clang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-28 Thread Sang Ik Lee via cfe-commits

https://github.com/silee2 updated 
https://github.com/llvm/llvm-project/pull/71430

>From c76403cf8629b8f7d8a5b7a3ee5da2881713a7f8 Mon Sep 17 00:00:00 2001
From: "Lee, Sang Ik" 
Date: Mon, 6 Nov 2023 18:47:23 +
Subject: [PATCH 1/5] [MLIR] Enable GPU Dialect to SYCL runtime integration

GPU Dialect lowering to SYCL runtime is driven by spirv.target_env
attached to gpu.module. As a result of this, spirv.target_env remains
as an input to LLVMIR Translation.
A SPIRVToLLVMIRTranslation without any actual translation is added to
avoid an unregistered error in mlir-cpu-runner.
SelectObjectAttr.cpp is updated to
1) Pass binary size argument to getModuleLoadFn
2) Pass parameter count to getKernelLaunchFn
This change does not impact CUDA and ROCM usage since both
mlir_cuda_runtime and mlir_rocm_runtime are already updated to
accept and ignore the extra arguments.
---
 mlir/include/mlir/Target/LLVMIR/Dialect/All.h |  3 ++
 .../Dialect/SPIRV/SPIRVToLLVMIRTranslation.h  | 31 +++
 mlir/lib/Target/LLVMIR/CMakeLists.txt |  1 +
 mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt |  1 +
 .../LLVMIR/Dialect/GPU/SelectObjectAttr.cpp   | 50 +
 .../LLVMIR/Dialect/SPIRV/CMakeLists.txt   | 13 +
 .../SPIRV/SPIRVToLLVMIRTranslation.cpp| 31 +++
 mlir/test/CMakeLists.txt  |  4 ++
 .../Integration/GPU/SYCL/gpu-to-spirv.mlir| 54 +++
 mlir/test/Integration/GPU/SYCL/lit.local.cfg  |  2 +
 mlir/test/Target/LLVMIR/gpu.mlir  |  9 ++--
 mlir/test/lit.cfg.py  |  3 ++
 mlir/test/lit.site.cfg.py.in  |  1 +
 13 files changed, 188 insertions(+), 15 deletions(-)
 create mode 100644 
mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
 create mode 100644 mlir/lib/Target/LLVMIR/Dialect/SPIRV/CMakeLists.txt
 create mode 100644 
mlir/lib/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.cpp
 create mode 100644 mlir/test/Integration/GPU/SYCL/gpu-to-spirv.mlir
 create mode 100644 mlir/test/Integration/GPU/SYCL/lit.local.cfg

diff --git a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
index 0563b9bf3d475a4..5dfc15afb75931a 100644
--- a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h
@@ -26,6 +26,7 @@
 #include "mlir/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/ROCDL/ROCDLToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Dialect/X86Vector/X86VectorToLLVMIRTranslation.h"
 
 namespace mlir {
@@ -45,6 +46,7 @@ static inline void 
registerAllToLLVMIRTranslations(DialectRegistry ) {
   registerOpenACCDialectTranslation(registry);
   registerOpenMPDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
   registerX86VectorDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
@@ -61,6 +63,7 @@ registerAllGPUToLLVMIRTranslations(DialectRegistry ) 
{
   registerLLVMDialectTranslation(registry);
   registerNVVMDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);
 
   // Extension required for translating GPU offloading Ops.
   gpu::registerOffloadingLLVMTranslationInterfaceExternalModels(registry);
diff --git 
a/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h 
b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
new file mode 100644
index 000..e9580a10b4ca780
--- /dev/null
+++ b/mlir/include/mlir/Target/LLVMIR/Dialect/SPIRV/SPIRVToLLVMIRTranslation.h
@@ -0,0 +1,31 @@
+//===- SPIRVToLLVMIRTranslation.h - SPIRV to LLVM IR *- 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
+//
+//===--===//
+//
+// This provides registration calls for SPIRV dialect to LLVM IR translation.
+//
+//===--===//
+
+#ifndef MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+#define MLIR_TARGET_LLVMIR_DIALECT_SPIRV_SPIRVTOLLVMIRTRANSLATION_H
+
+namespace mlir {
+
+class DialectRegistry;
+class MLIRContext;
+
+/// Register the SPIRV dialect and the translation from it to the LLVM IR in 
the
+/// given registry;
+void registerSPIRVDialectTranslation(DialectRegistry );
+
+/// Register the SPIRV dialect and the translation from it in the registry
+/// associated with the given context.
+void registerSPIRVDialectTranslation(MLIRContext );
+
+} // namespace mlir
+
+#endif // 

[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Krzysztof Parzyszek via cfe-commits


@@ -977,14 +977,61 @@ bool tools::addOpenMPRuntime(ArgStringList , 
const ToolChain ,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain ,
+void tools::addFortranRuntimeLibs(const ToolChain , const ArgList ,
   llvm::opt::ArgStringList ) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// The --whole-archive option needs to be part of the link line to
+// make sure that the main() function from Fortran_main.a is pulled
+// in by the linker.  Determine if --whole-archive is active when
+// flang will try to link Fortran_main.a.  If it is, don't add the
+// --whole-archive flag to the link line.  If it's not, add a proper
+// --whole-archive/--no-whole-archive bracket to the link line.
+bool NeedWholeArchive = true;
+auto * Arg = Args.getLastArg(options::OPT_Wl_COMMA);
+for (StringRef ArgValue : llvm::reverse(Arg->getValues())) {
+  if (ArgValue == "--whole-archive") {
+NeedWholeArchive = false;
+break;
+  }

kparzysz wrote:

> Are you sure? The default is to modify the link line and only not do it if 
> --whole-archive was found.

In `-Wl,-whole-archive,-lfoo,-no-whole-archive`, it will find the 
`whole-archive` part even though it's effectively disabled in the same option.

> However, there's an actual bug now, as this goes is treated wrongly:
> 
> `-Wl,--whole-archive -ldummy -Wl,-dummy`

Ahh, yes.  Indeed.


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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Michael Klemm via cfe-commits


@@ -977,14 +977,61 @@ bool tools::addOpenMPRuntime(ArgStringList , 
const ToolChain ,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain ,
+void tools::addFortranRuntimeLibs(const ToolChain , const ArgList ,
   llvm::opt::ArgStringList ) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// The --whole-archive option needs to be part of the link line to
+// make sure that the main() function from Fortran_main.a is pulled
+// in by the linker.  Determine if --whole-archive is active when
+// flang will try to link Fortran_main.a.  If it is, don't add the
+// --whole-archive flag to the link line.  If it's not, add a proper
+// --whole-archive/--no-whole-archive bracket to the link line.
+bool NeedWholeArchive = true;
+auto * Arg = Args.getLastArg(options::OPT_Wl_COMMA);

mjklemm wrote:

Right.  I'll fix this when I fixup the detecting algorithm.  The getLastArg 
thing was a red herring :-)

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Michael Klemm via cfe-commits


@@ -977,14 +977,61 @@ bool tools::addOpenMPRuntime(ArgStringList , 
const ToolChain ,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain ,
+void tools::addFortranRuntimeLibs(const ToolChain , const ArgList ,
   llvm::opt::ArgStringList ) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// The --whole-archive option needs to be part of the link line to
+// make sure that the main() function from Fortran_main.a is pulled
+// in by the linker.  Determine if --whole-archive is active when
+// flang will try to link Fortran_main.a.  If it is, don't add the
+// --whole-archive flag to the link line.  If it's not, add a proper
+// --whole-archive/--no-whole-archive bracket to the link line.
+bool NeedWholeArchive = true;
+auto * Arg = Args.getLastArg(options::OPT_Wl_COMMA);
+for (StringRef ArgValue : llvm::reverse(Arg->getValues())) {
+  if (ArgValue == "--whole-archive") {
+NeedWholeArchive = false;
+break;
+  }

mjklemm wrote:

Are you sure?  The default is to modify the link line and only not do it if 
--whole-archive was found.   However, there's an actual bug now, as this goes 
is treated wrongly:

`-Wl,--whole-archive -ldummy  -Wl,-dummy`

Now, the check does not see the --whole-archive anymore.  I need to go back to 
go through all the -Wl, and see which is the last one to have something to do 
with --whole-archive.

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


[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Krzysztof Parzyszek via cfe-commits


@@ -977,14 +977,61 @@ bool tools::addOpenMPRuntime(ArgStringList , 
const ToolChain ,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain ,
+void tools::addFortranRuntimeLibs(const ToolChain , const ArgList ,
   llvm::opt::ArgStringList ) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// The --whole-archive option needs to be part of the link line to
+// make sure that the main() function from Fortran_main.a is pulled
+// in by the linker.  Determine if --whole-archive is active when
+// flang will try to link Fortran_main.a.  If it is, don't add the
+// --whole-archive flag to the link line.  If it's not, add a proper
+// --whole-archive/--no-whole-archive bracket to the link line.
+bool NeedWholeArchive = true;
+auto * Arg = Args.getLastArg(options::OPT_Wl_COMMA);

kparzysz wrote:

This can be `nullptr` if the -Wl option wasn't present, so we need to check for 
that.

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


[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Krzysztof Parzyszek via cfe-commits


@@ -977,14 +977,61 @@ bool tools::addOpenMPRuntime(ArgStringList , 
const ToolChain ,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain ,
+void tools::addFortranRuntimeLibs(const ToolChain , const ArgList ,
   llvm::opt::ArgStringList ) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// The --whole-archive option needs to be part of the link line to
+// make sure that the main() function from Fortran_main.a is pulled
+// in by the linker.  Determine if --whole-archive is active when
+// flang will try to link Fortran_main.a.  If it is, don't add the
+// --whole-archive flag to the link line.  If it's not, add a proper
+// --whole-archive/--no-whole-archive bracket to the link line.
+bool NeedWholeArchive = true;
+auto * Arg = Args.getLastArg(options::OPT_Wl_COMMA);
+for (StringRef ArgValue : llvm::reverse(Arg->getValues())) {
+  if (ArgValue == "--whole-archive") {
+NeedWholeArchive = false;
+break;
+  }

kparzysz wrote:

This needs an `else if (ArgValue == "-no-whole-archive") break`, or otherwise 
we'll end up ignoring it.

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


[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/73124

>From 2a2693364cb8e9b657b9ff54aa78df0466b55fe4 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 14:22:20 +0100
Subject: [PATCH 01/14] Let the linker fail on multiple definitions of main()

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 1f31c6395206ee8..740ae71177b2c3a 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -982,7 +982,20 @@ void tools::addFortranRuntimeLibs(const ToolChain ,
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// --whole-archive needs to be part of the link line to make sure
+// that the main() function from Fortran_main.a is pulled in by
+// the linker.
+//
+// We are using this --whole-archive/--no-whole-archive bracket w/o
+// any further checks, because -Wl,--whole-archive at the flang-new new
+// line will not sucessfully complete, unless the user correctly specified
+// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
+// -Wl,--no-whole-archive).
+CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
+CmdArgs.push_back("--no-whole-archive");
+
+// Perform regular linkage of the remaining runtime libraries.
 CmdArgs.push_back("-lFortranRuntime");
 CmdArgs.push_back("-lFortranDecimal");
   }
@@ -993,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
,
  ArgStringList ) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to use
+  // this in the future. In particular, on some platforms, we may need to useq
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 0d652282f4dbed2dde11df53ead3e6c8b6856bed Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 15:18:51 +0100
Subject: [PATCH 02/14] Improve comments and remove accidental typo

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 740ae71177b2c3a..464a87737de062c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -987,10 +987,10 @@ void tools::addFortranRuntimeLibs(const ToolChain ,
 // the linker.
 //
 // We are using this --whole-archive/--no-whole-archive bracket w/o
-// any further checks, because -Wl,--whole-archive at the flang-new new
-// line will not sucessfully complete, unless the user correctly specified
-// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
-// -Wl,--no-whole-archive).
+// any further checks, because -Wl,--whole-archive at the flang
+// driver's link line will not sucessfully complete, unless the user
+// correctly specified -Wl,--whole-archive/-Wl,--no-whole-archive
+// (e.g., -Wl,--whole-archive -ldummy -Wl,--no-whole-archive).
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
 CmdArgs.push_back("--no-whole-archive");
@@ -1006,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
,
  ArgStringList ) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to useq
+  // this in the future. In particular, on some platforms, we may need to use
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 39612e237cb815cf4ea0120027783d35304bcb6b Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 20:26:02 +0100
Subject: [PATCH 03/14] Correct link line test for flang-new (for Linux)

---
 flang/test/Driver/linker-flags.f90 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 85c4d60b3f09862..ea91946316cfaa6 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -28,7 +28,7 @@
 !   executable and may find the GNU linker from MinGW or Cygwin.
 ! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! UNIX-SAME: "[[object_file]]"
-! UNIX-SAME: "-lFortran_main" "-lFortranRuntime" 

[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Michael Klemm via cfe-commits


@@ -977,14 +977,63 @@ bool tools::addOpenMPRuntime(ArgStringList , 
const ToolChain ,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain ,
+void tools::addFortranRuntimeLibs(const ToolChain , const ArgList ,
   llvm::opt::ArgStringList ) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// The --whole-archive option needs to be part of the link line to
+// make sure that the main() function from Fortran_main.a is pulled
+// in by the linker.  Determine if --whole-archive is active when
+// flang will try to link Fortran_main.a.  If it is, don't add the
+// --whole-archive flag to the link line.  If it's not, add a proper
+// --whole-archive/--no-whole-archive bracket to the link line.
+bool WholeArchiveActive = false;
+for (auto & : Args)

mjklemm wrote:

Thanks for the great suggestion!

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/73124

>From 2a2693364cb8e9b657b9ff54aa78df0466b55fe4 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 14:22:20 +0100
Subject: [PATCH 01/14] Let the linker fail on multiple definitions of main()

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 1f31c6395206ee8..740ae71177b2c3a 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -982,7 +982,20 @@ void tools::addFortranRuntimeLibs(const ToolChain ,
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// --whole-archive needs to be part of the link line to make sure
+// that the main() function from Fortran_main.a is pulled in by
+// the linker.
+//
+// We are using this --whole-archive/--no-whole-archive bracket w/o
+// any further checks, because -Wl,--whole-archive at the flang-new new
+// line will not sucessfully complete, unless the user correctly specified
+// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
+// -Wl,--no-whole-archive).
+CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
+CmdArgs.push_back("--no-whole-archive");
+
+// Perform regular linkage of the remaining runtime libraries.
 CmdArgs.push_back("-lFortranRuntime");
 CmdArgs.push_back("-lFortranDecimal");
   }
@@ -993,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
,
  ArgStringList ) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to use
+  // this in the future. In particular, on some platforms, we may need to useq
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 0d652282f4dbed2dde11df53ead3e6c8b6856bed Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 15:18:51 +0100
Subject: [PATCH 02/14] Improve comments and remove accidental typo

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 740ae71177b2c3a..464a87737de062c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -987,10 +987,10 @@ void tools::addFortranRuntimeLibs(const ToolChain ,
 // the linker.
 //
 // We are using this --whole-archive/--no-whole-archive bracket w/o
-// any further checks, because -Wl,--whole-archive at the flang-new new
-// line will not sucessfully complete, unless the user correctly specified
-// -Wl,--no-whole-archive (e.g., -Wl,--whole-archive -ldummy
-// -Wl,--no-whole-archive).
+// any further checks, because -Wl,--whole-archive at the flang
+// driver's link line will not sucessfully complete, unless the user
+// correctly specified -Wl,--whole-archive/-Wl,--no-whole-archive
+// (e.g., -Wl,--whole-archive -ldummy -Wl,--no-whole-archive).
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
 CmdArgs.push_back("--no-whole-archive");
@@ -1006,7 +1006,7 @@ void tools::addFortranRuntimeLibraryPath(const ToolChain 
,
  ArgStringList ) {
   // Default to the /../lib directory. This works fine on the
   // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to useq
+  // this in the future. In particular, on some platforms, we may need to use
   // lib64 instead of lib.
   SmallString<256> DefaultLibPath =
   llvm::sys::path::parent_path(TC.getDriver().Dir);

>From 39612e237cb815cf4ea0120027783d35304bcb6b Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Wed, 22 Nov 2023 20:26:02 +0100
Subject: [PATCH 03/14] Correct link line test for flang-new (for Linux)

---
 flang/test/Driver/linker-flags.f90 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index 85c4d60b3f09862..ea91946316cfaa6 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -28,7 +28,7 @@
 !   executable and may find the GNU linker from MinGW or Cygwin.
 ! UNIX-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! UNIX-SAME: "[[object_file]]"
-! UNIX-SAME: "-lFortran_main" "-lFortranRuntime" 

[clang] Refactor ASTContext::getDeclAlign() (NFC) (PR #72977)

2023-11-28 Thread Jonas Paulsson via cfe-commits

JonPsson1 wrote:

Eli, are you supposed to press some button before I merge this?

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Krzysztof Parzyszek via cfe-commits

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-28 Thread Krzysztof Parzyszek via cfe-commits


@@ -977,14 +977,63 @@ bool tools::addOpenMPRuntime(ArgStringList , 
const ToolChain ,
   return true;
 }
 
-void tools::addFortranRuntimeLibs(const ToolChain ,
+void tools::addFortranRuntimeLibs(const ToolChain , const ArgList ,
   llvm::opt::ArgStringList ) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+// The --whole-archive option needs to be part of the link line to
+// make sure that the main() function from Fortran_main.a is pulled
+// in by the linker.  Determine if --whole-archive is active when
+// flang will try to link Fortran_main.a.  If it is, don't add the
+// --whole-archive flag to the link line.  If it's not, add a proper
+// --whole-archive/--no-whole-archive bracket to the link line.
+bool WholeArchiveActive = false;
+for (auto & : Args)

kparzysz wrote:

Thanks.  If could be somewhat simplified though.  You could use
```
Arg *A = Args.getLastArg(clang::driver::options::OPT_Wl_COMMA));
```
To get the last instance of `-Wl`, and then iterate over the values in reverse, 
using `StringRef`:
```
for (StringRef V : llvm::reverse(A->getValues()))
```

`StringRef` allows comparisons against string literals, e.g. `string_ref == 
"blah"`,


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


[llvm] [clang] [clang, SystemZ] Pass HasDef flag to getMinGlobalAlign(). (PR #73511)

2023-11-28 Thread Jonas Paulsson via cfe-commits


@@ -1687,7 +1687,8 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool 
ForAlignof) const {
   if (VD->hasGlobalStorage() && !ForAlignof) {
 uint64_t TypeSize =
 !BaseT->isIncompleteType() ? getTypeSize(T.getTypePtr()) : 0;
-Align = std::max(Align, getTargetInfo().getMinGlobalAlign(TypeSize));
+Align = std::max(Align, getTargetInfo().getMinGlobalAlign(
+TypeSize, VD->hasDefinition()));

JonPsson1 wrote:

Good point!

It seems to me though that this is something the backend must handle. Even with 
this patch, e.g. a weak 4-byte integer would get the natural alignment, and 
could later be replaced with an unaligned 4-byte integer by the linker. This 
patch only removes the ABI minimal alignment, i.e. the requirement to align 
everything by at least 2 bytes.

A recent GCC does not handle this either: it emits a LARL for a weak int. Could 
it be that the linker preserves the alignment of the original (weak) object?


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


[clang] [llvm] [clang][RISCV] Change default abi when only have f extension but no d extension (PR #73489)

2023-11-28 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

> short version: GCC isn't change. long version: GCC's configure script isn't 
> change, it's configure script in riscv-gnu-toolchain

So why is there a difference between GCC and riscv-gnu-toolchain? If we set 
`with_abi` to lp64f, what is the behavior?
> 
> But I don't have strong opinion on this change since I believe user should 
> explicitly specify that, otherwise it's really to screw up to select 
> multi-lib or portability issue between different compilers.



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


[clang] [llvm] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-11-28 Thread Nikita Popov via cfe-commits

nikic wrote:

Just realized that this doesn't cover uses of isKnownNonNegative() in 
InstCombine yet, as it currently doesn't go through SimplifyQuery. I'll see 
about migrating those APIs tomorrow.

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


[clang] [llvm] [clang][RISCV] Change default abi when only have f extension but no d extension (PR #73489)

2023-11-28 Thread Kito Cheng via cfe-commits

kito-cheng wrote:

short version: GCC isn't change. 
long version: GCC's configure script isn't change, it's configure script in 
riscv-gnu-toolchain

But I don't have strong opinion on this change since I believe user should 
explicitly specify that, otherwise it's really to screw up to select multi-lib 
or portability issue between different compilers.

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


[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)

2023-11-28 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


DonatNagyE wrote:

Note that (if I understand it correctly) after this change the `ArrayBoundV2` 
check may be triggered at a slightly earlier point of the analysis and this may 
impact situations where both this checker and other checkers would emit a bug 
report. (See e.g. 
https://github.com/llvm/llvm-project/pull/72402#issuecomment-1830100604 where I 
discuss a concrete candidate for this.)

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


[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)

2023-11-28 Thread Michael Buch via cfe-commits

Michael137 wrote:

Looks like LLDB linux buildbot isn't happy, checking...

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


[clang] [clang-format] Option to ignore macro definitions (PR #70338)

2023-11-28 Thread via cfe-commits

https://github.com/tomekpaszek updated 
https://github.com/llvm/llvm-project/pull/70338

>From 25ca978ef9caf372997f2ebf227fb2b2ca443aa0 Mon Sep 17 00:00:00 2001
From: Tomek Paszek 
Date: Sat, 11 Nov 2023 19:38:00 +0100
Subject: [PATCH 01/15] Added an option to ignore macro definitions.

---
 clang/include/clang/Format/Format.h |  5 +
 clang/lib/Format/Format.cpp |  2 ++
 clang/lib/Format/UnwrappedLineFormatter.cpp |  2 ++
 clang/unittests/Format/ConfigParseTest.cpp  |  3 ++-
 clang/unittests/Format/FormatTest.cpp   | 16 
 5 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 37cb3b5cc06732e..fce68d70f4dd690 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2512,6 +2512,10 @@ struct FormatStyle {
   /// 
`_
   /// \version 13
   std::vector IfMacros;
+  
+  /// Ignore formatting in preprocessor definitions.
+  /// \version 18
+  bool IgnorePPDefinitions;
 
   /// Specify whether access modifiers should have their own indentation level.
   ///
@@ -4790,6 +4794,7 @@ struct FormatStyle {
R.IncludeStyle.IncludeIsMainRegex &&
IncludeStyle.IncludeIsMainSourceRegex ==
R.IncludeStyle.IncludeIsMainSourceRegex &&
+   IgnorePPDefinitions == R.IgnorePPDefinitions &&
IndentAccessModifiers == R.IndentAccessModifiers &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentCaseLabels == R.IndentCaseLabels &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index db0cb8a31084952..a6e451595527e73 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1002,6 +1002,7 @@ template <> struct MappingTraits {
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
 IO.mapOptional("IfMacros", Style.IfMacros);
+IO.mapOptional("IgnorePPDefinitions", Style.IgnorePPDefinitions);
 IO.mapOptional("IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
 IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
 IO.mapOptional("IncludeIsMainRegex", 
Style.IncludeStyle.IncludeIsMainRegex);
@@ -1507,6 +1508,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.ForEachMacros.push_back("Q_FOREACH");
   LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH");
   LLVMStyle.IfMacros.push_back("KJ_IF_MAYBE");
+  LLVMStyle.IgnorePPDefinitions = false;
   LLVMStyle.IncludeStyle.IncludeCategories = {
   {"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0, false},
   {"^(<|\"(gtest|gmock|isl|json)/)", 3, 0, false},
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 280485d9a90d1bf..bbf6383ff7673f6 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1355,6 +1355,8 @@ unsigned UnwrappedLineFormatter::format(
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
 bool ShouldFormat = TheLine.Affected || FixIndentation;
+if (Style.IgnorePPDefinitions && TheLine.Type == LT_PreprocessorDirective)
+  ShouldFormat = false;
 // We cannot format this line; if the reason is that the line had a
 // parsing error, remember that.
 if (ShouldFormat && TheLine.Type == LT_Invalid && Status) {
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 0c9f68f303d8653..fa4e1469e8cc136 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -167,6 +167,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
   CHECK_PARSE_BOOL(DisableFormat);
+  CHECK_PARSE_BOOL(IgnorePPDefinitions);
   CHECK_PARSE_BOOL(IndentAccessModifiers);
   CHECK_PARSE_BOOL(IndentCaseLabels);
   CHECK_PARSE_BOOL(IndentCaseBlocks);
@@ -199,7 +200,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
   CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
   CHECK_PARSE_BOOL(VerilogBreakBetweenInstancePorts);
-
+  
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements, Enabled);
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements,
   AcrossEmptyLines);
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 420afe5992f2a0b..e04ffc146404f17 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24219,6 +24219,22 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
   

[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-11-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-clang

Author: Nikita Popov (nikic)


Changes

This adds support for using dominating conditions in computeKnownBits() when 
called from InstCombine. The implementation uses a DomConditionCache, which 
stores which branches may provide information that is relevant for a given 
value.

DomConditionCache is similar to AssumptionCache, but does not try to do any 
kind of automatic tracking. Relevant branches have to be explicitly registered 
and invalidated values explicitly removed. The necessary tracking is done 
inside InstCombine.

The reason why this doesn't just do exactly the same thing as AssumptionCache 
is that a lot more transforms touch branches and branch conditions than 
assumptions. AssumptionCache is an immutable analysis and mostly gets away with 
this because only a handful of places have to register additional assumptions 
(mostly as a result of cloning). This is very much not the case for branches.

This change has some non-trivial impact on compile-time. The [first-order 
impact](http://llvm-compile-time-tracker.com/compare.php?from=1116e4f5dc2ba070dd655ec55231a5b21d33573fto=80fd5b58f63ba43d61bc1ad7011fb3f964a8768fstat=instructions%3Au)
 is about 0.2%. This is the impact if we compute the KnownBits, but don't use 
them. The [second-order 
impact](http://llvm-compile-time-tracker.com/compare.php?stat=instructions%3Aufrom=80fd5b58f63ba43d61bc1ad7011fb3f964a8768fto=d1a81a49dfb534f9a621d1a6de06998b72e11f16)
 is about 0.1% -- however, on stage2-O0-g it's actually a -0.2% improvement, 
which indicates that this change results in additional optimizations inside 
clang itself.

---

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


41 Files Affected:

- (modified) 
clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp (+1-1) 
- (added) llvm/include/llvm/Analysis/DomConditionCache.h (+56) 
- (modified) llvm/include/llvm/Analysis/SimplifyQuery.h (+4-2) 
- (modified) llvm/include/llvm/Transforms/InstCombine/InstCombiner.h (+5-1) 
- (modified) llvm/lib/Analysis/CMakeLists.txt (+1) 
- (added) llvm/lib/Analysis/DomConditionCache.cpp (+74) 
- (modified) llvm/lib/Analysis/ValueTracking.cpp (+28-3) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombineInternal.h (+1) 
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+1) 
- (modified) llvm/test/CodeGen/BPF/loop-exit-cond.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/2007-10-31-RangeCrash.ll (+5-2) 
- (modified) llvm/test/Transforms/InstCombine/2009-02-20-InstCombine-SROA.ll 
(+2-2) 
- (modified) llvm/test/Transforms/InstCombine/cast_phi.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/icmp-binop.ll (+1-2) 
- (modified) llvm/test/Transforms/InstCombine/icmp-dom.ll (+3-2) 
- (modified) llvm/test/Transforms/InstCombine/icmp-mul-zext.ll (+1-2) 
- (modified) llvm/test/Transforms/InstCombine/icmp-ne-pow2.ll (+4-8) 
- (modified) llvm/test/Transforms/InstCombine/icmp-of-or-x.ll (+2-6) 
- (modified) llvm/test/Transforms/InstCombine/known-non-zero.ll (+4-6) 
- (modified) llvm/test/Transforms/InstCombine/minmax-of-xor-x.ll (+1-4) 
- (modified) llvm/test/Transforms/InstCombine/shift.ll (+3-5) 
- (modified) llvm/test/Transforms/InstCombine/sink_instruction.ll (+5-1) 
- (modified) llvm/test/Transforms/InstCombine/sub-of-negatible-inseltpoison.ll 
(+3-4) 
- (modified) llvm/test/Transforms/InstCombine/sub-of-negatible.ll (+3-4) 
- (modified) llvm/test/Transforms/LoopUnroll/peel-loop-inner.ll (+2-2) 
- (modified) llvm/test/Transforms/LoopUnroll/peel-loop.ll (+4-4) 
- (modified) llvm/test/Transforms/LoopVectorize/AArch64/sve-vector-reverse.ll 
(+2-2) 
- (modified) llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse-mask4.ll 
(+1-1) 
- (modified) llvm/test/Transforms/LoopVectorize/ARM/mve-reductions.ll (+20-20) 
- (modified) llvm/test/Transforms/LoopVectorize/X86/small-size.ll (+1-1) 
- (modified) 
llvm/test/Transforms/LoopVectorize/X86/x86-interleaved-accesses-masked-group.ll 
(+20-20) 
- (modified) 
llvm/test/Transforms/LoopVectorize/X86/x86-interleaved-store-accesses-with-gaps.ll
 (+2-2) 
- (modified) llvm/test/Transforms/LoopVectorize/float-induction.ll (+20-20) 
- (modified) llvm/test/Transforms/LoopVectorize/if-conversion-nest.ll (+2-2) 
- (modified) llvm/test/Transforms/LoopVectorize/induction.ll (+3-3) 
- (modified) llvm/test/Transforms/LoopVectorize/reduction.ll (+11-11) 
- (modified) llvm/test/Transforms/LoopVectorize/runtime-check.ll (+1-1) 
- (modified) llvm/test/Transforms/PGOProfile/chr.ll (+3-3) 
- (modified) 
llvm/test/Transforms/PhaseOrdering/loop-rotation-vs-common-code-hoisting.ll 
(+1-1) 
- (modified) llvm/test/Transforms/SimpleLoopUnswitch/2007-08-01-LCSSA.ll (+5-2) 
- (modified) llvm/test/Transforms/SimplifyCFG/merge-cond-stores.ll (+2-3) 


``diff
diff --git 
a/clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp 

[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-11-28 Thread Nikita Popov via cfe-commits

https://github.com/nikic created https://github.com/llvm/llvm-project/pull/73662

This adds support for using dominating conditions in computeKnownBits() when 
called from InstCombine. The implementation uses a DomConditionCache, which 
stores which branches may provide information that is relevant for a given 
value.

DomConditionCache is similar to AssumptionCache, but does not try to do any 
kind of automatic tracking. Relevant branches have to be explicitly registered 
and invalidated values explicitly removed. The necessary tracking is done 
inside InstCombine.

The reason why this doesn't just do exactly the same thing as AssumptionCache 
is that a lot more transforms touch branches and branch conditions than 
assumptions. AssumptionCache is an immutable analysis and mostly gets away with 
this because only a handful of places have to register additional assumptions 
(mostly as a result of cloning). This is very much not the case for branches.

This change has some non-trivial impact on compile-time. The [first-order 
impact](http://llvm-compile-time-tracker.com/compare.php?from=1116e4f5dc2ba070dd655ec55231a5b21d33573f=80fd5b58f63ba43d61bc1ad7011fb3f964a8768f=instructions%3Au)
 is about 0.2%. This is the impact if we compute the KnownBits, but don't use 
them. The [second-order 
impact](http://llvm-compile-time-tracker.com/compare.php?stat=instructions%3Au=80fd5b58f63ba43d61bc1ad7011fb3f964a8768f=d1a81a49dfb534f9a621d1a6de06998b72e11f16)
 is about 0.1% -- however, on stage2-O0-g it's actually a -0.2% improvement, 
which indicates that this change results in additional optimizations inside 
clang itself.

>From 22bfcee8a48764cf1bdc1c53a5cc36305cf595c3 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Fri, 17 Nov 2023 12:20:44 +0100
Subject: [PATCH] [ValueTracking] Add dominating condition support in
 computeKnownBits()

---
 .../member-function-pointer.cpp   |  2 +-
 .../include/llvm/Analysis/DomConditionCache.h | 56 ++
 llvm/include/llvm/Analysis/SimplifyQuery.h|  6 +-
 .../Transforms/InstCombine/InstCombiner.h |  6 +-
 llvm/lib/Analysis/CMakeLists.txt  |  1 +
 llvm/lib/Analysis/DomConditionCache.cpp   | 74 +++
 llvm/lib/Analysis/ValueTracking.cpp   | 31 +++-
 .../InstCombine/InstCombineInternal.h |  1 +
 .../InstCombine/InstructionCombining.cpp  |  1 +
 llvm/test/CodeGen/BPF/loop-exit-cond.ll   |  2 +-
 .../InstCombine/2007-10-31-RangeCrash.ll  |  7 +-
 .../2009-02-20-InstCombine-SROA.ll|  4 +-
 llvm/test/Transforms/InstCombine/cast_phi.ll  |  2 +-
 .../test/Transforms/InstCombine/icmp-binop.ll |  3 +-
 llvm/test/Transforms/InstCombine/icmp-dom.ll  |  5 +-
 .../Transforms/InstCombine/icmp-mul-zext.ll   |  3 +-
 .../Transforms/InstCombine/icmp-ne-pow2.ll| 12 +--
 .../Transforms/InstCombine/icmp-of-or-x.ll|  8 +-
 .../Transforms/InstCombine/known-non-zero.ll  | 10 +--
 .../Transforms/InstCombine/minmax-of-xor-x.ll |  5 +-
 llvm/test/Transforms/InstCombine/shift.ll |  8 +-
 .../InstCombine/sink_instruction.ll   |  6 +-
 .../sub-of-negatible-inseltpoison.ll  |  7 +-
 .../InstCombine/sub-of-negatible.ll   |  7 +-
 .../Transforms/LoopUnroll/peel-loop-inner.ll  |  4 +-
 llvm/test/Transforms/LoopUnroll/peel-loop.ll  |  8 +-
 .../AArch64/sve-vector-reverse.ll |  4 +-
 .../AArch64/vector-reverse-mask4.ll   |  2 +-
 .../LoopVectorize/ARM/mve-reductions.ll   | 40 +-
 .../LoopVectorize/X86/small-size.ll   |  2 +-
 .../x86-interleaved-accesses-masked-group.ll  | 40 +-
 ...86-interleaved-store-accesses-with-gaps.ll |  4 +-
 .../LoopVectorize/float-induction.ll  | 40 +-
 .../LoopVectorize/if-conversion-nest.ll   |  4 +-
 .../Transforms/LoopVectorize/induction.ll |  6 +-
 .../Transforms/LoopVectorize/reduction.ll | 22 +++---
 .../Transforms/LoopVectorize/runtime-check.ll |  2 +-
 llvm/test/Transforms/PGOProfile/chr.ll|  6 +-
 .../loop-rotation-vs-common-code-hoisting.ll  |  2 +-
 .../SimpleLoopUnswitch/2007-08-01-LCSSA.ll|  7 +-
 .../SimplifyCFG/merge-cond-stores.ll  |  5 +-
 41 files changed, 310 insertions(+), 155 deletions(-)
 create mode 100644 llvm/include/llvm/Analysis/DomConditionCache.h
 create mode 100644 llvm/lib/Analysis/DomConditionCache.cpp

diff --git 
a/clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp 
b/clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
index 24f884a8d23befb..000568b3b6bf09c 100644
--- a/clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
+++ b/clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
@@ -14,7 +14,7 @@
 
 // The loading of the virtual function here should be replaced with a 
llvm.load.relative() call.
 // CHECK-NEXT:   [[vtable:%.+]] = load ptr, ptr [[this_adj]], align 8
-// CHECK-NEXT:   [[offset:%.+]] = add i64 [[fn_ptr]], -1
+// CHECK-NEXT:   [[offset:%.+]] = 

[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)

2023-11-28 Thread Michael Buch via cfe-commits

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


[clang] 7f3ee3c - [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (#73626)

2023-11-28 Thread via cfe-commits

Author: Michael Buch
Date: 2023-11-28T15:40:43Z
New Revision: 7f3ee3ca1d09daf0f7d350ed9d62796640a59bf4

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

LOG: [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member 
declarations (#73626)

In https://github.com/llvm/llvm-project/pull/71780 we started emitting
definitions for all static data-members with constant initialisers, even
if they were constants (i.e., didn't have a location). We also dropped
the DW_AT_const_value from the declaration to [help resolve
inconsistencies during type merging in the
DWARFParallelLinker](https://github.com/llvm/llvm-project/pull/68721).
However, for static data members that do have locations, we wouldn't
emit a DW_AT_const_value on it, assuming that the consumer knows how to
read the value using the location. This broke some consumers that really
wanted to find a DW_AT_const_value. Ultimately we want to attach a
DW_AT_const_value to definitions that have a location too. But to fix
consumers broken by said change, this patch adds the constant back onto
the declaration. This is what we used to do prior to
https://github.com/llvm/llvm-project/pull/71780

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
clang/test/CodeGenCXX/debug-info-static-member.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3b4932cc4a30f6b..f1f4a1b79b7bcf4 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1680,14 +1680,26 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl 
*Var, llvm::DIType *RecordTy,
   unsigned LineNumber = getLineNumber(Var->getLocation());
   StringRef VName = Var->getName();
 
+  // FIXME: to avoid complications with type merging we should
+  // emit the constant on the definition instead of the declaration.
+  llvm::Constant *C = nullptr;
+  if (Var->getInit()) {
+const APValue *Value = Var->evaluateValue();
+if (Value) {
+  if (Value->isInt())
+C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt());
+  if (Value->isFloat())
+C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat());
+}
+  }
+
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
   auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
  ? llvm::dwarf::DW_TAG_variable
  : llvm::dwarf::DW_TAG_member;
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
-  llvm::DIDerivedType *GV =
-  DBuilder.createStaticMemberType(RecordTy, VName, VUnit, LineNumber, VTy,
-  Flags, /* Val */ nullptr, Tag, Align);
+  llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
+  RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Tag, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;

diff  --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index f2d4d9408a8297a..d3b6a363c5bd8f2 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -49,19 +49,19 @@ int main() {
 
 // CHECK:  ![[INT_DECL]] = !DIDerivedType(tag: DW_TAG_member, name: 
"cexpr_int_with_addr",
 // CHECK-SAME: flags: DIFlagStaticMember
-// CHECK-NOT:  extraData:
+// CHECK-SAME: extraData: i32 25
 
 // CHECK:  ![[INT_DECL2:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, 
name: "cexpr_int2",
 // CHECK-SAME: flags: DIFlagStaticMember
-// CHECK-NOT:  extraData:
+// CHECK-SAME: extraData: i32 26
 
 // CHECK:  ![[FLOAT_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, 
name: "cexpr_float",
 // CHECK-SAME:  flags: DIFlagStaticMember
-// CHECK-NOT:   extraData:
+// CHECK-SAME:  extraData: float
 
 // CHECK:  ![[ENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, 
name: "cexpr_enum",
 // CHECK-SAME: flags: DIFlagStaticMember
-// CHECK-NOT:  extraData:
+// CHECK-SAME: extraData: i32 -1
 
 // CHECK:  ![[EMPTY_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, 
name: "cexpr_struct_with_addr",
 // CHECK-SAME:  flags: DIFlagStaticMember
@@ -69,15 +69,15 @@ int main() {
 
 // CHECK:  ![[IENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, 
name: "inline_enum",
 // CHECK-SAME:

[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)

2023-11-28 Thread Michael Buch via cfe-commits

Michael137 wrote:

> > I do wonder how feasible it would be for the downstream tests to be 
> > adjusted to look at the `DW_AT_location`..
> 
> As I mentioned on the other thread, the point is not to have to read the 
> value from the process-under-debug. This is not efficient in a 
> remote-debugging scenario.

Ah that's fair, missed your comment on the other thread

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


[clang] 0424546 - [analyzer] Use AllocaRegion in MallocChecker (#72402)

2023-11-28 Thread via cfe-commits

Author: DonatNagyE
Date: 2023-11-28T16:34:44+01:00
New Revision: 0424546ed4a7570837626922edc66530cd3c3ab7

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

LOG: [analyzer] Use AllocaRegion in MallocChecker (#72402)

...to model the results of alloca() and _alloca() calls. Previously it
acted as if these functions were returning memory from the heap, which
led to alpha.security.ArrayBoundV2 producing incorrect messages.

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
clang/test/Analysis/malloc.c
clang/test/Analysis/memory-model.cpp
clang/test/Analysis/out-of-bounds-diagnostics.c

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
index 692c4384586569e..a64cf7ae4efcb82 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -215,6 +215,15 @@ class SValBuilder {
 const LocationContext *LCtx,
 QualType type, unsigned Count);
 
+  /// Create an SVal representing the result of an alloca()-like call, that is,
+  /// an AllocaRegion on the stack.
+  ///
+  /// After calling this function, it's a good idea to set the extent of the
+  /// returned AllocaRegion.
+  loc::MemRegionVal getAllocaRegionVal(const Expr *E,
+   const LocationContext *LCtx,
+   unsigned Count);
+
   DefinedOrUnknownSVal getDerivedRegionValueSymbolVal(
   SymbolRef parentSymbol, const TypedValueRegion *region);
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index 4a56156de4b27fe..61521c259ca90a1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -81,22 +81,20 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent ,
 
   case Builtin::BI__builtin_alloca_with_align:
   case Builtin::BI__builtin_alloca: {
-// FIXME: Refactor into StoreManager itself?
-MemRegionManager& RM = C.getStoreManager().getRegionManager();
-const AllocaRegion* R =
-  RM.getAllocaRegion(CE, C.blockCount(), C.getLocationContext());
-
-// Set the extent of the region in bytes. This enables us to use the
-// SVal of the argument directly. If we save the extent in bits, we
-// cannot represent values like symbol*8.
-auto Size = Call.getArgSVal(0);
-if (Size.isUndef())
-  return true; // Return true to model purity.
-
-state = setDynamicExtent(state, R, Size.castAs(),
- C.getSValBuilder());
+SValBuilder  = C.getSValBuilder();
+const loc::MemRegionVal R =
+SVB.getAllocaRegionVal(CE, C.getLocationContext(), C.blockCount());
 
-C.addTransition(state->BindExpr(CE, LCtx, loc::MemRegionVal(R)));
+// Set the extent of the region in bytes. This enables us to use the SVal
+// of the argument directly. If we saved the extent in bits, it'd be more
+// 
diff icult to reason about values like symbol*8.
+auto Size = Call.getArgSVal(0);
+if (auto DefSize = Size.getAs()) {
+  // This `getAs()` is mostly paranoia, because core.CallAndMessage reports
+  // undefined function arguments (unless it's disabled somehow).
+  state = setDynamicExtent(state, R.getRegion(), *DefSize, SVB);
+}
+C.addTransition(state->BindExpr(CE, LCtx, R));
 return true;
   }
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index d3a4020280616b0..c5e4add501886a4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1728,13 +1728,15 @@ ProgramStateRef 
MallocChecker::MallocMemAux(CheckerContext ,
 return nullptr;
 
   // Bind the return value to the symbolic value from the heap region.
-  // TODO: We could rewrite post visit to eval call; 'malloc' does not have
-  // side effects other than what we model here.
+  // TODO: move use of this functions to an EvalCall callback, becasue
+  // BindExpr() should'nt be used elsewhere.
   unsigned Count = C.blockCount();
-  SValBuilder  = C.getSValBuilder();
+  SValBuilder  = C.getSValBuilder();
   const LocationContext *LCtx = C.getPredecessor()->getLocationContext();
-  

[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-28 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


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


[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-28 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


DonatNagyE wrote:

I'm merging this commit in its current shape because even if I'd reimplement a 
warning for the "use of `alloc(0)`", I'd do it in a separate commit.

I thought about potential approaches to implement this "use of zero-allocated" 
warning for the `AllocaRegion`s and it seems to be troublesome, so I lean 
towards not doing it.

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


[llvm] [clang] [AMDGPU] Enable OpenCL hostcall printf (WIP) (PR #72556)

2023-11-28 Thread Vikram Hegde via cfe-commits

vikramRH wrote:

@arsenm , apologies for the trouble here. I should have based this out of my 
earlier commit. currently I do not see a way to base this patch off of my 
earlier commit and it might get too confusing for other reviewers if I close 
this and raise another review. would the individual commit details suffice ?

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


[clang] [clang-format] Option to ignore macro definitions (PR #70338)

2023-11-28 Thread via cfe-commits

https://github.com/tomekpaszek updated 
https://github.com/llvm/llvm-project/pull/70338

>From b5ba0b3fde2c6662e19dfdf96a787621ec767460 Mon Sep 17 00:00:00 2001
From: Tomek Paszek 
Date: Sat, 11 Nov 2023 19:38:00 +0100
Subject: [PATCH 01/15] Added an option to ignore macro definitions.

---
 clang/include/clang/Format/Format.h |  5 +
 clang/lib/Format/Format.cpp |  2 ++
 clang/lib/Format/UnwrappedLineFormatter.cpp |  2 ++
 clang/unittests/Format/ConfigParseTest.cpp  |  3 ++-
 clang/unittests/Format/FormatTest.cpp   | 16 
 5 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3e9d1915badd87f..3af7241441c8b13 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2442,6 +2442,10 @@ struct FormatStyle {
   /// 
`_
   /// \version 13
   std::vector IfMacros;
+  
+  /// Ignore formatting in preprocessor definitions.
+  /// \version 18
+  bool IgnorePPDefinitions;
 
   /// Specify whether access modifiers should have their own indentation level.
   ///
@@ -4719,6 +4723,7 @@ struct FormatStyle {
R.IncludeStyle.IncludeIsMainRegex &&
IncludeStyle.IncludeIsMainSourceRegex ==
R.IncludeStyle.IncludeIsMainSourceRegex &&
+   IgnorePPDefinitions == R.IgnorePPDefinitions &&
IndentAccessModifiers == R.IndentAccessModifiers &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentCaseLabels == R.IndentCaseLabels &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index edb33f4af4defef..6e5ec754dfdcdd9 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1000,6 +1000,7 @@ template <> struct MappingTraits {
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
 IO.mapOptional("IfMacros", Style.IfMacros);
+IO.mapOptional("IgnorePPDefinitions", Style.IgnorePPDefinitions);
 IO.mapOptional("IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
 IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
 IO.mapOptional("IncludeIsMainRegex", 
Style.IncludeStyle.IncludeIsMainRegex);
@@ -1504,6 +1505,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.ForEachMacros.push_back("Q_FOREACH");
   LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH");
   LLVMStyle.IfMacros.push_back("KJ_IF_MAYBE");
+  LLVMStyle.IgnorePPDefinitions = false;
   LLVMStyle.IncludeStyle.IncludeCategories = {
   {"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0, false},
   {"^(<|\"(gtest|gmock|isl|json)/)", 3, 0, false},
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 280485d9a90d1bf..bbf6383ff7673f6 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1355,6 +1355,8 @@ unsigned UnwrappedLineFormatter::format(
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
 bool ShouldFormat = TheLine.Affected || FixIndentation;
+if (Style.IgnorePPDefinitions && TheLine.Type == LT_PreprocessorDirective)
+  ShouldFormat = false;
 // We cannot format this line; if the reason is that the line had a
 // parsing error, remember that.
 if (ShouldFormat && TheLine.Type == LT_Invalid && Status) {
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index f90ed178d99c286..110df624d44573c 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -166,6 +166,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
   CHECK_PARSE_BOOL(DisableFormat);
+  CHECK_PARSE_BOOL(IgnorePPDefinitions);
   CHECK_PARSE_BOOL(IndentAccessModifiers);
   CHECK_PARSE_BOOL(IndentCaseLabels);
   CHECK_PARSE_BOOL(IndentCaseBlocks);
@@ -198,7 +199,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
   CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
   CHECK_PARSE_BOOL(VerilogBreakBetweenInstancePorts);
-
+  
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements, Enabled);
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements,
   AcrossEmptyLines);
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b2d84f2ee389551..659132dcb9c3970 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24153,6 +24153,22 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
   

[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-28 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@cor3ntin I've fixed that.

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-28 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/69734

>From 8cad09416a4e362ea59249e040d6e8aaee54dee3 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 26 Nov 2023 15:06:32 +0330
Subject: [PATCH] [clang] Non-object types are non-trivially relocatable

Both active C++ proposals (P1144 and P2786) agree that
`is_trivially_relocatable_v` and `is_trivially_relocatable_v`
should be false, not true. Only complete object types
can be trivially relocatable.

Fixes #67498
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/AST/Type.cpp|  2 ++
 clang/test/SemaCXX/type-traits-incomplete.cpp |  8 +++-
 clang/test/SemaCXX/type-traits-nonobject.cpp  | 16 
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/type-traits-nonobject.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e2e8ee8d76d2e10..e4b0a2cb5e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -637,6 +637,9 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
+- ``__is_trivially_relocatable`` no longer returns true for non-object types
+  such as references and functions.
+  Fixes (`#67498 `_)
 - Fix crash when the object used as a ``static_assert`` message has ``size`` 
or ``data`` members
   which are not member functions.
 - Support UDLs in ``static_assert`` message.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index c8e452e2feab0bf..160a725939ccd4c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 
   if (BaseElementType->isIncompleteType()) {
 return false;
+  } else if (!BaseElementType->isObjectType()) {
+return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {
diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp 
b/clang/test/SemaCXX/type-traits-incomplete.cpp
index c0a520e167698af..3e341d648244075 100644
--- a/clang/test/SemaCXX/type-traits-incomplete.cpp
+++ b/clang/test/SemaCXX/type-traits-incomplete.cpp
@@ -1,8 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S; // expected-note 2 {{forward declaration of 'S'}}
+struct S; // expected-note 6 {{forward declaration of 'S'}}
 
 void f() {
   __is_pod(S); // expected-error{{incomplete type 'S' used in type trait 
expression}}
   __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait 
expression}}
+
+  __is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+  __is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+
+  __is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used 
in type trait expression}}
+  __is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used 
in type trait expression}}
 }
diff --git a/clang/test/SemaCXX/type-traits-nonobject.cpp 
b/clang/test/SemaCXX/type-traits-nonobject.cpp
new file mode 100644
index 000..c9e3c30e5533d48
--- /dev/null
+++ b/clang/test/SemaCXX/type-traits-nonobject.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+// expected-no-diagnostics
+
+static_assert(!__is_pod(void), "");
+static_assert(!__is_pod(int&), "");
+static_assert(!__is_pod(int()), "");
+
+static_assert(!__is_trivially_copyable(void), "");
+static_assert(!__is_trivially_copyable(int&), "");
+static_assert(!__is_trivially_copyable(int()), "");
+
+static_assert(!__is_trivially_relocatable(void), "");
+static_assert(!__is_trivially_relocatable(int&), "");
+static_assert(!__is_trivially_relocatable(int()), "");

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-28 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/69734

>From a0b9798dc87b313d9dff08e9fa109bf2d65a863e Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 26 Nov 2023 15:06:32 +0330
Subject: [PATCH] [clang] Non-object types are non-trivially relocatable

Both active C++ proposals (P1144 and P2786) agree that
`is_trivially_relocatable_v` and `is_trivially_relocatable_v`
should be false, not true. Only complete object types
can be trivially relocatable.

Fixes #67498
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/AST/Type.cpp|  2 ++
 clang/test/SemaCXX/type-traits-incomplete.cpp |  8 +++-
 clang/test/SemaCXX/type-traits-nonobject.cpp  | 16 
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/type-traits-nonobject.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e2e8ee8d76d2e10..8825fc03bf2d59f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -640,6 +640,9 @@ Bug Fixes in This Version
 - Fix crash when the object used as a ``static_assert`` message has ``size`` 
or ``data`` members
   which are not member functions.
 - Support UDLs in ``static_assert`` message.
+- ``__is_trivially_relocatable`` no longer returns true for non-object types
+  such as references and functions.
+  Fixes (`#67498 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index c8e452e2feab0bf..160a725939ccd4c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
 
   if (BaseElementType->isIncompleteType()) {
 return false;
+  } else if (!BaseElementType->isObjectType()) {
+return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {
diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp 
b/clang/test/SemaCXX/type-traits-incomplete.cpp
index c0a520e167698af..3e341d648244075 100644
--- a/clang/test/SemaCXX/type-traits-incomplete.cpp
+++ b/clang/test/SemaCXX/type-traits-incomplete.cpp
@@ -1,8 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S; // expected-note 2 {{forward declaration of 'S'}}
+struct S; // expected-note 6 {{forward declaration of 'S'}}
 
 void f() {
   __is_pod(S); // expected-error{{incomplete type 'S' used in type trait 
expression}}
   __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait 
expression}}
+
+  __is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+  __is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+
+  __is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used 
in type trait expression}}
+  __is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used 
in type trait expression}}
 }
diff --git a/clang/test/SemaCXX/type-traits-nonobject.cpp 
b/clang/test/SemaCXX/type-traits-nonobject.cpp
new file mode 100644
index 000..c9e3c30e5533d48
--- /dev/null
+++ b/clang/test/SemaCXX/type-traits-nonobject.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+// expected-no-diagnostics
+
+static_assert(!__is_pod(void), "");
+static_assert(!__is_pod(int&), "");
+static_assert(!__is_pod(int()), "");
+
+static_assert(!__is_trivially_copyable(void), "");
+static_assert(!__is_trivially_copyable(int&), "");
+static_assert(!__is_trivially_copyable(int()), "");
+
+static_assert(!__is_trivially_relocatable(void), "");
+static_assert(!__is_trivially_relocatable(int&), "");
+static_assert(!__is_trivially_relocatable(int()), "");

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


[clang] [clang-format] Option to ignore macro definitions (PR #70338)

2023-11-28 Thread via cfe-commits

https://github.com/tomekpaszek updated 
https://github.com/llvm/llvm-project/pull/70338

>From b5ba0b3fde2c6662e19dfdf96a787621ec767460 Mon Sep 17 00:00:00 2001
From: Tomek Paszek 
Date: Sat, 11 Nov 2023 19:38:00 +0100
Subject: [PATCH 01/15] Added an option to ignore macro definitions.

---
 clang/include/clang/Format/Format.h |  5 +
 clang/lib/Format/Format.cpp |  2 ++
 clang/lib/Format/UnwrappedLineFormatter.cpp |  2 ++
 clang/unittests/Format/ConfigParseTest.cpp  |  3 ++-
 clang/unittests/Format/FormatTest.cpp   | 16 
 5 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3e9d1915badd87f..3af7241441c8b13 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2442,6 +2442,10 @@ struct FormatStyle {
   /// 
`_
   /// \version 13
   std::vector IfMacros;
+  
+  /// Ignore formatting in preprocessor definitions.
+  /// \version 18
+  bool IgnorePPDefinitions;
 
   /// Specify whether access modifiers should have their own indentation level.
   ///
@@ -4719,6 +4723,7 @@ struct FormatStyle {
R.IncludeStyle.IncludeIsMainRegex &&
IncludeStyle.IncludeIsMainSourceRegex ==
R.IncludeStyle.IncludeIsMainSourceRegex &&
+   IgnorePPDefinitions == R.IgnorePPDefinitions &&
IndentAccessModifiers == R.IndentAccessModifiers &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentCaseLabels == R.IndentCaseLabels &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index edb33f4af4defef..6e5ec754dfdcdd9 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1000,6 +1000,7 @@ template <> struct MappingTraits {
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
 IO.mapOptional("IfMacros", Style.IfMacros);
+IO.mapOptional("IgnorePPDefinitions", Style.IgnorePPDefinitions);
 IO.mapOptional("IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
 IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
 IO.mapOptional("IncludeIsMainRegex", 
Style.IncludeStyle.IncludeIsMainRegex);
@@ -1504,6 +1505,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.ForEachMacros.push_back("Q_FOREACH");
   LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH");
   LLVMStyle.IfMacros.push_back("KJ_IF_MAYBE");
+  LLVMStyle.IgnorePPDefinitions = false;
   LLVMStyle.IncludeStyle.IncludeCategories = {
   {"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0, false},
   {"^(<|\"(gtest|gmock|isl|json)/)", 3, 0, false},
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 280485d9a90d1bf..bbf6383ff7673f6 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1355,6 +1355,8 @@ unsigned UnwrappedLineFormatter::format(
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
 bool ShouldFormat = TheLine.Affected || FixIndentation;
+if (Style.IgnorePPDefinitions && TheLine.Type == LT_PreprocessorDirective)
+  ShouldFormat = false;
 // We cannot format this line; if the reason is that the line had a
 // parsing error, remember that.
 if (ShouldFormat && TheLine.Type == LT_Invalid && Status) {
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index f90ed178d99c286..110df624d44573c 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -166,6 +166,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
   CHECK_PARSE_BOOL(DisableFormat);
+  CHECK_PARSE_BOOL(IgnorePPDefinitions);
   CHECK_PARSE_BOOL(IndentAccessModifiers);
   CHECK_PARSE_BOOL(IndentCaseLabels);
   CHECK_PARSE_BOOL(IndentCaseBlocks);
@@ -198,7 +199,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
   CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
   CHECK_PARSE_BOOL(VerilogBreakBetweenInstancePorts);
-
+  
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements, Enabled);
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements,
   AcrossEmptyLines);
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b2d84f2ee389551..659132dcb9c3970 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24153,6 +24153,22 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
   

[libunwind] [libunwind][WebAssembly] Don't build libunwind.cpp (PR #73196)

2023-11-28 Thread Alexander Richardson via cfe-commits

arichardson wrote:

> > The commit message is slightly misleading, it appears there are some parts 
> > of the file that are actually used?
> 
> As the commit message says, we only use 
> https://github.com/llvm/llvm-project/blob/main/libunwind/src/Unwind-wasm.c 
> and not libunwind.cpp. We don't use any parts of libunwind.cpp. Do you have 
> any suggestions on how to improve the message to make it clearer?

Looking at the file, there is some code that will still be compiled for wasm 
(at least for debug builds). If those functions are also not used for wasm they 
should be ifdef'd out as well?

Commit message could be something like `Omit unused parts of libunwind.cpp for 
WASM`. 



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


[llvm] [compiler-rt] [flang] [clang-tools-extra] [clang] [mlir] [clang][CodeGen] Handle template parameter objects with explicit address spaces (PR #69266)

2023-11-28 Thread Alex Voicu via cfe-commits

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

>From ded7435220d2c3527c4798d1b328a5f2940e279a Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Mon, 16 Oct 2023 22:43:55 +0100
Subject: [PATCH 1/3] Handle trying to bind a generic reference to a template
 parameter object value that is in an explicit address space.

---
 clang/lib/CodeGen/CGExpr.cpp  | 18 +--
 .../template-param-objects-address-space.cpp  | 32 +++
 2 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/CodeGenCXX/template-param-objects-address-space.cpp

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac738..784d3f7b03909e3 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2992,9 +2992,21 @@ LValue CodeGenFunction::EmitDeclRefLValue(const 
DeclRefExpr *E) {
 return MakeAddrLValue(CGM.GetAddrOfMSGuidDecl(GD), T,
   AlignmentSource::Decl);
 
-  if (const auto *TPO = dyn_cast(ND))
-return MakeAddrLValue(CGM.GetAddrOfTemplateParamObject(TPO), T,
-  AlignmentSource::Decl);
+  if (const auto *TPO = dyn_cast(ND)) {
+auto ATPO = CGM.GetAddrOfTemplateParamObject(TPO);
+auto AS = getLangASFromTargetAS(ATPO.getAddressSpace());
+
+if (AS != T.getAddressSpace()) {
+  auto TargetAS = getContext().getTargetAddressSpace(T.getAddressSpace());
+  auto PtrTy = ATPO.getElementType()->getPointerTo(TargetAS);
+  auto ASC = getTargetHooks().performAddrSpaceCast(CGM, ATPO.getPointer(),
+   AS, T.getAddressSpace(),
+   PtrTy);
+  ATPO = ConstantAddress(ASC, ATPO.getElementType(), ATPO.getAlignment());
+}
+
+return MakeAddrLValue(ATPO, T, AlignmentSource::Decl);
+  }
 
   llvm_unreachable("Unhandled DeclRefExpr");
 }
diff --git a/clang/test/CodeGenCXX/template-param-objects-address-space.cpp 
b/clang/test/CodeGenCXX/template-param-objects-address-space.cpp
new file mode 100644
index 000..b54dcfe77934ee2
--- /dev/null
+++ b/clang/test/CodeGenCXX/template-param-objects-address-space.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -std=c++20 %s -emit-llvm -o - | 
FileCheck %s
+
+struct S { char buf[32]; };
+template constexpr const char *begin() { return s.buf; }
+template constexpr const char *end() { return s.buf + 
__builtin_strlen(s.buf); }
+template constexpr const void *retval() { return  }
+extern const void *callee(const S*);
+template constexpr const void* observable_addr() { return callee(); }
+
+// CHECK: 
[[HELLO:@_ZTAXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100]]
+// CHECK-SAME: = linkonce_odr addrspace(1) constant { <{ [11 x i8], [21 x i8] 
}> } { <{ [11 x i8], [21 x i8] }> <{ [11 x i8] c"hello world", [21 x i8] 
zeroinitializer }> }, comdat
+
+// CHECK: @p
+// CHECK-SAME: addrspace(1) global ptr addrspacecast (ptr addrspace(1) 
[[HELLO]] to ptr)
+const char *p = begin();
+
+// CHECK: @q
+// CHECK-SAME: addrspace(1) global ptr addrspacecast (ptr addrspace(1) 
getelementptr (i8, ptr addrspace(1) [[HELLO]], i64 11) to ptr)
+const char *q = end();
+
+const void *(*r)() = ;
+
+// CHECK: @s
+// CHECK-SAME: addrspace(1) global ptr null
+const void *s = observable_addr();
+
+// CHECK: define linkonce_odr noundef ptr 
@_Z6retvalIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EPKvv()
+// CHECK: ret ptr addrspacecast (ptr addrspace(1) [[HELLO]] to ptr)
+
+// CHECK: define linkonce_odr noundef ptr 
@_Z15observable_addrIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EPKvv()
+// CHECK: %call = call noundef ptr @_Z6calleePK1S(ptr noundef addrspacecast 
(ptr addrspace(1) [[HELLO]] to ptr))
+// CHECK: declare noundef ptr @_Z6calleePK1S(ptr noundef)

>From 4afd54856ca8248fab731e17cd644d18ed60acbc Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Thu, 9 Nov 2023 14:51:39 -1000
Subject: [PATCH 2/3] Fix formatting error.

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

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 652d9c32a8c47b4..8abb1d8a1be4e97 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3045,9 +3045,8 @@ LValue CodeGenFunction::EmitDeclRefLValue(const 
DeclRefExpr *E) {
 if (AS != T.getAddressSpace()) {
   auto TargetAS = getContext().getTargetAddressSpace(T.getAddressSpace());
   auto PtrTy = ATPO.getElementType()->getPointerTo(TargetAS);
-  auto ASC = getTargetHooks().performAddrSpaceCast(CGM, ATPO.getPointer(),
-   AS, T.getAddressSpace(),
-   PtrTy);
+  auto ASC = getTargetHooks().performAddrSpaceCast(
+CGM, ATPO.getPointer(), 

[llvm] [clang] [SystemZ] Properly support 16 byte atomic int/fp types and ops. (PR #73134)

2023-11-28 Thread Jonas Paulsson via cfe-commits

https://github.com/JonPsson1 updated 
https://github.com/llvm/llvm-project/pull/73134

>From bf9b6b735c131833ec9457f23b72322fd50ef821 Mon Sep 17 00:00:00 2001
From: Jonas Paulsson 
Date: Fri, 3 Feb 2023 14:32:58 +0100
Subject: [PATCH 1/5] [SystemZ] Improve support for 16 byte atomic int/fp types
 and operations.

- Clang FE now has MaxAtomicPromoteWidth and MaxAtomicInlineWidth with a value
  of 128. It now produces IR instead of calls to __atomic instrinsics for 16
  bytes as well. FP loads are first loaded as i128 and then casted to fp128.
- Atomic __int128 (and long double) variables are aligned to 16 bytes
  (like gcc 14).
- AtomicExpand pass now expands also 16 byte operations.

- tests for __atomic builtins for all integer widths, with test for i128 in
  both align=8 and align=16 cases.
- Resulting behavior of __atomic_is_lock_free / __atomic_always_lock_free /
  __c11_atomic_is_lock_free is tested in gnu-atomic_is_lock_free.c
- shouldExpandAtomicRMWInIR() was already returning true for any FP type. Now
  that the backend is acepting 16 byte atomics, 16 byte FP atomicrmw:s now also
  get expanded by AtomicExpand. The default (and used)
  shouldCastAtomicRMWIInIR() says that if the type is FP, it is casted to
  integer (see atomicrmw-xchg-07.ll).
- TODO: AtomicExpand pass handles with this patch expansion of i128 atomicrmw:s.
  As a next step smaller integer types should also be possible to handle this
  way instead of in backend.

Original patch rebased.
Remove the regalloc handling for CDSG loops.
Tests improved.
---
 clang/lib/Basic/Targets/SystemZ.h |   2 +-
 clang/test/CodeGen/SystemZ/atomic-alignment.c |  35 ++
 .../SystemZ/gnu-atomic-builtins-i128-16Al.c   | 257 +
 .../SystemZ/gnu-atomic-builtins-i128-8Al.c| 301 +++
 .../CodeGen/SystemZ/gnu-atomic-builtins-i16.c | 219 
 .../CodeGen/SystemZ/gnu-atomic-builtins-i32.c | 219 
 .../CodeGen/SystemZ/gnu-atomic-builtins-i64.c | 219 
 .../CodeGen/SystemZ/gnu-atomic-builtins-i8.c  | 219 
 .../gnu-atomic_is_lock_free-i128-16Al.c   |  54 ++
 .../gnu-atomic_is_lock_free-i128-8Al.c|  28 +
 .../Target/SystemZ/SystemZISelLowering.cpp|   6 +-
 .../CodeGen/SystemZ/atomicrmw-ops-i128.ll | 496 --
 .../test/CodeGen/SystemZ/atomicrmw-xchg-07.ll |  37 +-
 13 files changed, 2030 insertions(+), 62 deletions(-)
 create mode 100644 clang/test/CodeGen/SystemZ/atomic-alignment.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i128-16Al.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i128-8Al.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i16.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i32.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i64.c
 create mode 100644 clang/test/CodeGen/SystemZ/gnu-atomic-builtins-i8.c
 create mode 100644 
clang/test/CodeGen/SystemZ/gnu-atomic_is_lock_free-i128-16Al.c
 create mode 100644 
clang/test/CodeGen/SystemZ/gnu-atomic_is_lock_free-i128-8Al.c

diff --git a/clang/lib/Basic/Targets/SystemZ.h 
b/clang/lib/Basic/Targets/SystemZ.h
index 9ba255745cf2cc5..e4ec338880f2109 100644
--- a/clang/lib/Basic/Targets/SystemZ.h
+++ b/clang/lib/Basic/Targets/SystemZ.h
@@ -60,7 +60,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public 
TargetInfo {
   resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
   "-v128:64-a:8:16-n32:64");
 }
-MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
+MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 128;
 HasStrictFP = true;
   }
 
diff --git a/clang/test/CodeGen/SystemZ/atomic-alignment.c 
b/clang/test/CodeGen/SystemZ/atomic-alignment.c
new file mode 100644
index 000..da478842ca31b2b
--- /dev/null
+++ b/clang/test/CodeGen/SystemZ/atomic-alignment.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O3 -emit-llvm %s -o - | FileCheck 
%s
+//
+// Test alignment of 128 bit Atomic int/fp types, as well as loading
+// from memory with a simple addition. The fp128 is loaded as i128 and
+// then casted.
+
+// CHECK: @Atomic_int128 = {{.*}} i128 0, align 16
+// CHECK: @Atomic_fp128 = {{.*}} fp128 0xL, 
align 16
+
+// CHECK-LABEL:  @f1
+// CHECK:  %atomic-load = load atomic i128, ptr @Atomic_int128 seq_cst, 
align 16
+// CHECK-NEXT: %add = add nsw i128 %atomic-load, 1
+// CHECK-NEXT: store i128 %add, ptr %agg.result, align 8
+// CHECK-NEXT: ret void
+
+// CHECK-LABEL:  @f2
+// CHECK:  %atomic-load = load atomic i128, ptr @Atomic_fp128 seq_cst, 
align 16
+// CHECK-NEXT: %0 = bitcast i128 %atomic-load to fp128
+// CHECK-NEXT: %add = fadd fp128 %0, 0xL3FFF
+// CHECK-NEXT: store fp128 %add, ptr %agg.result, align 8
+// CHECK-NEXT: ret void
+
+
+#include 
+
+_Atomic __int128Atomic_int128;
+_Atomic long double Atomic_fp128;
+
+__int128 f1() {
+  return Atomic_int128 + 1;
+}
+
+long double 

[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)

2023-11-28 Thread Balázs Kéri via cfe-commits

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


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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-28 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

Oh, Sure. I didn't noticed that.

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-28 Thread via cfe-commits

cor3ntin wrote:

@AMP999 can you resolve the conflict?

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


[clang] 0237f1b - clang: Add pragma clang fp reciprocal (#68267)

2023-11-28 Thread via cfe-commits

Author: Matt Arsenault
Date: 2023-11-28T23:38:50+09:00
New Revision: 0237f1b998fab69ce365f0ebc79f0ecfa4294744

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

LOG: clang: Add pragma clang fp reciprocal (#68267)

Just follow along with the reassociate pragma. This allows locally
setting the arcp fast math flag. Previously you could only access this
through the global -freciprocal-math.

Fixes #64798

Added: 
clang/test/CodeGen/fp-reciprocal-pragma.cpp

Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/PragmaKinds.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParsePragma.cpp
clang/lib/Sema/SemaAttr.cpp
clang/test/Parser/pragma-fp-contract.c
clang/test/Parser/pragma-fp.cpp
clang/test/Sema/eval-method-with-unsafe-math.c

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 294210c6ac140a9..8e01ef6cbb3997e 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -4629,6 +4629,22 @@ The pragma can take two values: ``on`` and ``off``.
 float v = t + z;
   }
 
+``#pragma clang fp reciprocal`` allows control over using reciprocal
+approximations in floating point expressions. When enabled, this
+pragma allows the expression ``x / y`` to be approximated as ``x *
+(1.0 / y)``.  This pragma can be used to disable reciprocal
+approximation when it is otherwise enabled for the translation unit
+with the ``-freciprocal-math`` flag or other fast-math options. The
+pragma can take two values: ``on`` and ``off``.
+
+.. code-block:: c++
+
+  float f(float x, float y)
+  {
+// Enable floating point reciprocal approximation
+#pragma clang fp reciprocal(on)
+return x / y;
+  }
 
 ``#pragma clang fp contract`` specifies whether the compiler should
 contract a multiply and an addition (or subtraction) into a fused FMA

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c909ac3cab6419..e2e8ee8d76d2e10 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -228,6 +228,8 @@ Non-comprehensive list of changes in this release
 * ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the 
return value ``18``
   and vector types as return value ``19``, to match GCC 14's behavior.
 
+* Added ``#pragma clang fp reciprocal``.
+
 New Compiler Flags
 --
 

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 2fd7165a422859a..21fe6066d587610 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1594,12 +1594,13 @@ def note_pragma_loop_invalid_vectorize_option : Note<
   "vectorize_width(X, scalable) where X is an integer, or 
vectorize_width('fixed' or 'scalable')">;
 
 def err_pragma_fp_invalid_option : Error<
-  "%select{invalid|missing}0 option%select{ %1|}0; expected 'contract', 
'reassociate' or 'exceptions'">;
+  "%select{invalid|missing}0 option%select{ %1|}0; expected 'contract', 
'reassociate', 'reciprocal', or 'exceptions'">;
 def err_pragma_fp_invalid_argument : Error<
   "unexpected argument '%0' to '#pragma clang fp %1'; expected "
   "%select{"
   "'fast' or 'on' or 'off'|"
   "'on' or 'off'|"
+  "'on' or 'off'|"
   "'ignore', 'maytrap' or 'strict'|"
   "'source', 'double' or 'extended'}2">;
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6e0ccdf97206682..020ff6387c28063 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6759,7 +6759,7 @@ def warn_floatingpoint_eq : Warning<
 
 def err_setting_eval_method_used_in_unsafe_context : Error <
   "%select{'#pragma clang fp eval_method'|option 'ffp-eval-method'}0 cannot be 
used with "
-  "%select{option 'fapprox-func'|option 'mreassociate'|option 
'freciprocal'|option 'ffp-eval-method'|'#pragma clang fp reassociate'}1">;
+  "%select{option 'fapprox-func'|option 'mreassociate'|option 
'freciprocal'|option 'ffp-eval-method'|'#pragma clang fp reassociate'|'#pragma 
clang fp reciprocal'}1">;
 
 def warn_remainder_division_by_zero : Warning<
   "%select{remainder|division}0 by zero is undefined">,

diff  --git a/clang/include/clang/Basic/PragmaKinds.h 
b/clang/include/clang/Basic/PragmaKinds.h
index 176bbc9ac7caaec..42f049f7323d2d4 100644
--- a/clang/include/clang/Basic/PragmaKinds.h
+++ b/clang/include/clang/Basic/PragmaKinds.h
@@ -34,6 +34,14 @@ enum PragmaFloatControlKind {
   PFC_Push,  // #pragma 

[clang] clang: Add pragma clang fp reciprocal (PR #68267)

2023-11-28 Thread Matt Arsenault via cfe-commits

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


[clang] clang: Add pragma clang fp reciprocal (PR #68267)

2023-11-28 Thread Zahira Ammarguellat via cfe-commits

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


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


[clang] clang: Add pragma clang fp reciprocal (PR #68267)

2023-11-28 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

LGTM.

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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-11-28 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@cor3ntin Could you land this for me, please?

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


[clang] clang: Add pragma clang fp reciprocal (PR #68267)

2023-11-28 Thread Yaxun Liu via cfe-commits

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

LGTM. Thanks

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


[clang-tools-extra] [flang] [clang] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-28 Thread Yi Wu via cfe-commits


@@ -9,6 +9,17 @@
 // Defines the API between compiled code and the implementations of 
time-related
 // intrinsic subroutines in the runtime library.
 
+// time-intrinsic.h
+#ifndef TIME_INTRINSIC_H
+#define TIME_INTRINSIC_H
+
+#include 
+
+void copyBufferAndPad(
+char *dest, std::size_t destChars, char *buffer, std::size_t len);

yi-wu-arm wrote:

Thanks for pointing this out!

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


[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)

2023-11-28 Thread Paul T Robinson via cfe-commits

pogo59 wrote:

> I do wonder how feasible it would be for the downstream tests to be adjusted 
> to look at the `DW_AT_location`..

As I mentioned on the other thread, the point is not to have to read the value 
from the process-under-debug. This is not efficient in a remote-debugging 
scenario.

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


[clang] [flang] [flang] Update -falias-analysis help text (PR #73548)

2023-11-28 Thread Tom Eccles via cfe-commits


@@ -6334,8 +6334,8 @@ defm loop_versioning : BoolOptionWithoutMarshalling<"f", 
"version-loops-for-stri
   PosFlag,
NegFlag>;
 defm alias_analysis : BoolOptionWithoutMarshalling<"f", "alias-analysis",
-  PosFlag,
-  NegFlag>;
+  PosFlag,
+  NegFlag>;
 } // let Visibility = [FC1Option, FlangOption]

tblah wrote:

Sure. Would it be okay to do that in a few weeks once the dust has settled from 
enabling it by default? `-fno-alias-analysis` is an easy work around if any 
problems show up

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


[clang] [clang] fix typo (PR #73644)

2023-11-28 Thread Zhikai Zeng via cfe-commits

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


[clang] 01091fd - [clang] fix typo (#73644)

2023-11-28 Thread via cfe-commits

Author: Zhikai Zeng
Date: 2023-11-28T22:08:11+08:00
New Revision: 01091fd101ee78fb8068a2b916ae007a4873d66a

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

LOG: [clang] fix typo (#73644)

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c0c321f0f200d21..50ee0a5acb5586a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10628,7 +10628,7 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
 
   bool AllowExplicit = !Kind.isCopyInit() || ListInit;
 
-  // Return true is the candidate is added successfully, false otherwise.
+  // Return true if the candidate is added successfully, false otherwise.
   auto addDeductionCandidate = [&](FunctionTemplateDecl *TD,
CXXDeductionGuideDecl *GD,
DeclAccessPair FoundDecl,



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


[clang] clang: Add pragma clang fp reciprocal (PR #68267)

2023-11-28 Thread Matt Arsenault via cfe-commits

arsenm wrote:

ping

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


[clang] [clang] fix typo (PR #73644)

2023-11-28 Thread Zhikai Zeng via cfe-commits

https://github.com/Backl1ght updated 
https://github.com/llvm/llvm-project/pull/73644

>From 1381fd047b27a019166b6c9552c55afaa916ee39 Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Tue, 28 Nov 2023 21:18:49 +0800
Subject: [PATCH] [clang] fix typo

---
 clang/lib/Sema/SemaInit.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c0c321f0f200d21..50ee0a5acb5586a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10628,7 +10628,7 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
 
   bool AllowExplicit = !Kind.isCopyInit() || ListInit;
 
-  // Return true is the candidate is added successfully, false otherwise.
+  // Return true if the candidate is added successfully, false otherwise.
   auto addDeductionCandidate = [&](FunctionTemplateDecl *TD,
CXXDeductionGuideDecl *GD,
DeclAccessPair FoundDecl,

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


[openmp] [clang] [llvm] [clang] fix typo (PR #73644)

2023-11-28 Thread Zhikai Zeng via cfe-commits

https://github.com/Backl1ght updated 
https://github.com/llvm/llvm-project/pull/73644

>From a417fb4d421cc28115bb2ea2062fb400586a7042 Mon Sep 17 00:00:00 2001
From: Backl1ght 
Date: Tue, 28 Nov 2023 21:18:49 +0800
Subject: [PATCH] [clang] fix typo

---
 clang/lib/Sema/SemaInit.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c0c321f0f200d21..50ee0a5acb5586a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10628,7 +10628,7 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
 
   bool AllowExplicit = !Kind.isCopyInit() || ListInit;
 
-  // Return true is the candidate is added successfully, false otherwise.
+  // Return true if the candidate is added successfully, false otherwise.
   auto addDeductionCandidate = [&](FunctionTemplateDecl *TD,
CXXDeductionGuideDecl *GD,
DeclAccessPair FoundDecl,

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


[clang] [libclang] Compute the right spelling location (PR #72400)

2023-11-28 Thread Sebastian Poeplau via cfe-commits

sebastianpoeplau wrote:

I just discovered #28205 which should be fixed by this change.

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


[clang] [clang] fix typo (PR #73644)

2023-11-28 Thread via cfe-commits

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

Lgtm

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


[clang] [clang] fix typo (PR #73644)

2023-11-28 Thread Timm Baeder via cfe-commits

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


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


[clang] [clang] Bounds checking on unclosed parentheses, brackets or braces in Expanded Tokens (PR #69849)

2023-11-28 Thread via cfe-commits

robozati wrote:

@HighCommander4, thank you for reviewing this PR!

Unfortunately, I’m currently in my finals and will only have time to look at 
this next week. So, I’ll update this later.

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


[clang] Improve clang-format-diff help output (PR #73491)

2023-11-28 Thread via cfe-commits

https://github.com/serge-sans-paille closed 
https://github.com/llvm/llvm-project/pull/73491
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ced0f28 - Improve clang-format-diff help output (#73491)

2023-11-28 Thread via cfe-commits

Author: serge-sans-paille
Date: 2023-11-28T13:46:37Z
New Revision: ced0f28a35b8a14759e6bd9418e8c8a7c35775c8

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

LOG: Improve clang-format-diff help output (#73491)

It is quite common to symlink clang-format-diff.py to clang-format-diff,
and in that case the help output still refers to the .py version.
Compute it instead to work in both setup.

Added: 


Modified: 
clang/tools/clang-format/clang-format-diff.py

Removed: 




diff  --git a/clang/tools/clang-format/clang-format-
diff .py b/clang/tools/clang-format/clang-format-
diff .py
index 892c1e38a462ff4..b25ee8f4337518e 100755
--- a/clang/tools/clang-format/clang-format-
diff .py
+++ b/clang/tools/clang-format/clang-format-
diff .py
@@ -13,8 +13,8 @@
 lines. This is useful to reformat all the lines touched by a specific patch.
 Example usage for git/svn users:
 
-  git 
diff  -U0 --no-color --relative HEAD^ | clang-format-
diff .py -p1 -i
-  svn 
diff  --
diff -cmd=
diff  -x-U0 | clang-format-
diff .py -i
+  git 
diff  -U0 --no-color --relative HEAD^ | {clang_format_
diff } -p1 -i
+  svn 
diff  --
diff -cmd=
diff  -x-U0 | {clang_format_
diff } -i
 
 It should be noted that the filename contained in the 
diff  is used unmodified
 to determine the source file to update. Users calling this script directly
@@ -25,6 +25,7 @@
 
 import argparse
 import 
diff lib
+import os
 import re
 import subprocess
 import sys
@@ -36,8 +37,10 @@
 
 
 def main():
+basename = os.path.basename(sys.argv[0])
 parser = argparse.ArgumentParser(
-description=__doc__, 
formatter_class=argparse.RawDescriptionHelpFormatter
+description=__doc__.format(clang_format_
diff =basename),
+formatter_class=argparse.RawDescriptionHelpFormatter,
 )
 parser.add_argument(
 "-i",



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


[clang] Improve clang-format-diff help output (PR #73491)

2023-11-28 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/73491

>From c66e50ee0c804eadd8cb09650f41cc31a76e8bdd Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Mon, 27 Nov 2023 10:17:32 +0100
Subject: [PATCH 1/2] Improve clang-format-diff help output

It is quite common to symlink clang-format-diff.py to
clang-format-diff, and in that case the help output still refers to the
.py version. Compute it instead to work in both setup.

Fix #73635
---
 clang/tools/clang-format/clang-format-diff.py | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 892c1e38a462ff4..facaaf96dd8f90a 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -13,8 +13,8 @@
 lines. This is useful to reformat all the lines touched by a specific patch.
 Example usage for git/svn users:
 
-  git diff -U0 --no-color --relative HEAD^ | clang-format-diff.py -p1 -i
-  svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i
+  git diff -U0 --no-color --relative HEAD^ | {clang_format_diff} -p1 -i
+  svn diff --diff-cmd=diff -x-U0 | {clang_format_diff} -i
 
 It should be noted that the filename contained in the diff is used unmodified
 to determine the source file to update. Users calling this script directly
@@ -25,6 +25,7 @@
 
 import argparse
 import difflib
+import os
 import re
 import subprocess
 import sys
@@ -36,8 +37,10 @@
 
 
 def main():
+basename = os.path.basename(sys.argv[0])
 parser = argparse.ArgumentParser(
-description=__doc__, 
formatter_class=argparse.RawDescriptionHelpFormatter
+description=__doc__.format(clang_format_diff=basename),
+formatter_class=argparse.RawDescriptionHelpFormatter
 )
 parser.add_argument(
 "-i",

>From 24cb032f022e711fcf6dc1e0477d54c2dcef519a Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Tue, 28 Nov 2023 14:45:38 +0100
Subject: [PATCH 2/2] fixup! Improve clang-format-diff help output

---
 clang/tools/clang-format/clang-format-diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index facaaf96dd8f90a..b25ee8f4337518e 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -40,7 +40,7 @@ def main():
 basename = os.path.basename(sys.argv[0])
 parser = argparse.ArgumentParser(
 description=__doc__.format(clang_format_diff=basename),
-formatter_class=argparse.RawDescriptionHelpFormatter
+formatter_class=argparse.RawDescriptionHelpFormatter,
 )
 parser.add_argument(
 "-i",

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


[clang] [llvm] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)

2023-11-28 Thread Björn Pettersson via cfe-commits


@@ -2282,6 +2282,15 @@ Instruction 
*InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst ) {
   if (MadeChange)
 return 
 
+  // Canonicalize constant GEPs to i8 type.

bjope wrote:

Right. So things can be expected to just work (given getTypeStoreSize(i8)==1), 
even when the addressing unit isn't 8 bits.

Since
```
%gep = getelementptr i3, ptr %p, i16 1
%gep = getelementptr i8, ptr %p, i16 1
%gep = getelementptr i16, ptr %p, i16 1
```
all are equivalent (for my target), then this patch just makes that more 
obvious by canonicalizing them into a single form. 
So we just need to update some lit test checks to expect "getelementptr i8" 
instead of "getelementptr i16" downstream, and hopefully things will be fine.

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


[clang-tools-extra] [clang] [llvm] [STLExtras] Add out-of-line definition of friend operator== for C++20 (PR #72348)

2023-11-28 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/72348

>From b29aa485f2a541243d3764f4ed711ccc5a869519 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 15 Nov 2023 06:26:19 +0100
Subject: [PATCH 1/4] [STLExctras] Add out-of-line definition of friend
 operator== for C++20

---
 llvm/include/llvm/ADT/STLExtras.h | 40 +++
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/llvm/include/llvm/ADT/STLExtras.h 
b/llvm/include/llvm/ADT/STLExtras.h
index 18bc4d108b156bf..380d4d461c4e8db 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1291,16 +1291,19 @@ class indexed_accessor_range_base {
   }
 
   /// Compare this range with another.
-  template 
-  friend bool operator==(const indexed_accessor_range_base ,
- const OtherT ) {
-return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
-  }
-  template 
-  friend bool operator!=(const indexed_accessor_range_base ,
- const OtherT ) {
-return !(lhs == rhs);
-  }
+  // FIXME: Make me a member function instead of friend when it works in C++20.
+  template 
+  friend bool
+  operator==(const indexed_accessor_range_base ,
+ const OtherT );
+  template 
+  friend bool
+  operator!=(const indexed_accessor_range_base ,
+ const OtherT );
 
   /// Return the size of this range.
   size_t size() const { return count; }
@@ -1364,6 +1367,23 @@ class indexed_accessor_range_base {
   /// The size from the owning range.
   ptrdiff_t count;
 };
+
+// FIXME: Make me a member function instead of friend when it works in C++20.
+template 
+bool operator==(const indexed_accessor_range_base ,
+const OtherT ) {
+  return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
+}
+
+template 
+bool operator!=(const indexed_accessor_range_base ,
+const OtherT ) {
+  return !(lhs == rhs);
+}
 } // end namespace detail
 
 /// This class provides an implementation of a range of

>From 064de694fb512a16005283bb140feb5f87138a6c Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 15 Nov 2023 13:58:18 +0100
Subject: [PATCH 2/4] remove friend declaration

---
 llvm/include/llvm/ADT/STLExtras.h | 19 ++-
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/llvm/include/llvm/ADT/STLExtras.h 
b/llvm/include/llvm/ADT/STLExtras.h
index 380d4d461c4e8db..9f43bbc5b63a24b 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1290,21 +1290,6 @@ class indexed_accessor_range_base {
 return (*this)[size() - 1];
   }
 
-  /// Compare this range with another.
-  // FIXME: Make me a member function instead of friend when it works in C++20.
-  template 
-  friend bool
-  operator==(const indexed_accessor_range_base ,
- const OtherT );
-  template 
-  friend bool
-  operator!=(const indexed_accessor_range_base ,
- const OtherT );
-
   /// Return the size of this range.
   size_t size() const { return count; }
 
@@ -1367,8 +1352,8 @@ class indexed_accessor_range_base {
   /// The size from the owning range.
   ptrdiff_t count;
 };
-
-// FIXME: Make me a member function instead of friend when it works in C++20.
+/// Compare this range with another.
+/// FIXME: Make me a member function instead of friend when it works in C++20.
 template 
 bool operator==(const indexed_accessor_range_baseFrom c8d3c272564f0c8d2c43c501506913c7f05a3eda Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 16 Nov 2023 11:35:18 +
Subject: [PATCH 3/4] s/DerivedT2/DerivedT2

---
 llvm/include/llvm/ADT/STLExtras.h | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/ADT/STLExtras.h 
b/llvm/include/llvm/ADT/STLExtras.h
index 9f43bbc5b63a24b..ecaa7cce1522115 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1354,18 +1354,18 @@ class indexed_accessor_range_base {
 };
 /// Compare this range with another.
 /// FIXME: Make me a member function instead of friend when it works in C++20.
-template 
-bool operator==(const indexed_accessor_range_base ,
+template 
+bool operator==(const indexed_accessor_range_base ,
 const OtherT ) {
   return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
 }
 
-template 
-bool operator!=(const indexed_accessor_range_base ,
+template 
+bool operator!=(const indexed_accessor_range_base ,
 const OtherT ) {
   return !(lhs == rhs);
 }

>From bd17e2125fa43feb447648d53136b8ebc7d58576 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 16 Nov 2023 13:11:14 +0100
Subject: [PATCH 4/4] format

---
 llvm/include/llvm/ADT/STLExtras.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/ADT/STLExtras.h 
b/llvm/include/llvm/ADT/STLExtras.h
index ecaa7cce1522115..a136eeb0ff1bd7c 100644
--- 

[clang] [clang][AST][ASTMerge] prevent AST nodes from being deallocated early (PR #73096)

2023-11-28 Thread Old Head Music via cfe-commits

yangxili2023 wrote:

Thank you everybody! The problem is solved.

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


[clang] [CUDA][HIP] Exclude external variables from constant promotion. (PR #73549)

2023-11-28 Thread Matt Arsenault via cfe-commits


@@ -104,3 +106,17 @@ void fun() {
   (void) b;
   (void) var_host_only;
 }
+
+// NEG-NOT: external_func
+extern __global__ void external_func();
+// NEG-NOT: @external_dep
+extern void* const external_dep[] = {
+  (void*)(external_func)
+};
+// NEG-NOT: @external_arr

arsenm wrote:

Not sure this negative check really works as expected; won't any global 
variable be printed at the top of the file before any functions?

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


[flang] [clang] [flang] Update -falias-analysis help text (PR #73548)

2023-11-28 Thread Andrzej Warzyński via cfe-commits

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


[clang] [flang] [flang] Update -falias-analysis help text (PR #73548)

2023-11-28 Thread Andrzej Warzyński via cfe-commits


@@ -6334,8 +6334,8 @@ defm loop_versioning : BoolOptionWithoutMarshalling<"f", 
"version-loops-for-stri
   PosFlag,
NegFlag>;
 defm alias_analysis : BoolOptionWithoutMarshalling<"f", "alias-analysis",
-  PosFlag,
-  NegFlag>;
+  PosFlag,
+  NegFlag>;
 } // let Visibility = [FC1Option, FlangOption]

banach-space wrote:

Perhaps restrict to `FC1Option`?

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


[flang] [clang] [flang] Update -falias-analysis help text (PR #73548)

2023-11-28 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space approved this pull request.

Thanks, LGTM!

> @banach-space I'm happy to change the behavior too if you'd prefer that

That would be great, but could be done independently. Up to you!

In general, I feel that `-f{no-}alias-analysis` interacts with `-O{#N}` in a 
way that should be avoided. But I'd need to look more into how `-O{#N}` are 
defined to have a more informed opinion. So just restricting this option for 
now (provided it still work for you in the intended way) should be fine.

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


[clang] [clang] fix typo (PR #73644)

2023-11-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Zhikai Zeng (Backl1ght)


Changes



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


1 Files Affected:

- (modified) clang/lib/Sema/SemaInit.cpp (+1-1) 


``diff
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c0c321f0f200d21..50ee0a5acb5586a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10628,7 +10628,7 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
 
   bool AllowExplicit = !Kind.isCopyInit() || ListInit;
 
-  // Return true is the candidate is added successfully, false otherwise.
+  // Return true if the candidate is added successfully, false otherwise.
   auto addDeductionCandidate = [&](FunctionTemplateDecl *TD,
CXXDeductionGuideDecl *GD,
DeclAccessPair FoundDecl,

``




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


<    1   2   3   4   >