[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #111090)

2024-10-04 Thread via cfe-commits

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


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


[clang] [Clang][Sema] fix noexecpt mismatch of friend declaration (PR #102267)

2024-10-04 Thread via cfe-commits


@@ -4698,7 +4698,22 @@ void Sema::InstantiateExceptionSpec(SourceLocation 
PointOfInstantiation,
   // Enter the scope of this instantiation. We don't use
   // PushDeclContext because we don't have a scope.
   Sema::ContextRAII savedContext(*this, Decl);
+
+  FunctionDecl *Source = Proto->getExtProtoInfo().ExceptionSpec.SourceTemplate;
+  FunctionTemplateDecl *SourceTemplate = 
Source->getDescribedFunctionTemplate();
+  llvm::SmallDenseMap InstTemplateParams;
+  if (CurrentInstantiationScope && SourceTemplate)
+if (TemplateParameterList *TPL = SourceTemplate->getTemplateParameters())
+  for (NamedDecl *TemplateParam : *TPL)
+if (auto *Found =
+CurrentInstantiationScope->findInstantiationOf(TemplateParam))
+  if (auto *InstTemplateParam = Found->dyn_cast())
+InstTemplateParams[TemplateParam] = InstTemplateParam;
+

cor3ntin wrote:

I don't think this is handling the pack case..
Do we have a generic way to copy instantiated template params? @zyn0217 
@mizvekov @Sirraide
We do similar things in a bunch of places (including when checking constraints)

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


[clang] [clang-format] Annotate ::operator as FunctionDeclarationName (PR #111115)

2024-10-04 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/15

Fix #111011

>From 41a0257541c8c9b26fd0cc8e392abc0b27d1084e Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 4 Oct 2024 01:17:13 -0700
Subject: [PATCH] [clang-format] Annotate ::operator as FunctionDeclarationName

Fix #111011
---
 clang/lib/Format/TokenAnnotator.cpp   | 7 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 8 
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index e2068e557732af..d537855fef4564 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3738,6 +3738,13 @@ static bool isFunctionDeclarationName(const LangOptions 
&LangOpts,
 
   const auto *Prev = Current.getPreviousNonComment();
   assert(Prev);
+
+  if (Prev->is(tok::coloncolon))
+Prev = Prev->Previous;
+
+  if (!Prev)
+return false;
+
   const auto &Previous = *Prev;
 
   if (const auto *PrevPrev = Previous.getPreviousNonComment();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index a89adfa3f4fdd9..56142163e5f2b1 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1007,6 +1007,14 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsOverloadedOperators) {
   EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_OverloadedOperator);
   EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_OverloadedOperatorLParen);
   EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("friend ostream& ::operator<<(ostream& lhs, foo& rhs);");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[5], tok::lessless, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_OverloadedOperatorLParen);
+  EXPECT_TOKEN(Tokens[8], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[12], tok::amp, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {

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


[clang] [MSVC] work-around for compile time issue 102513 (PR #110986)

2024-10-04 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Generally LGTM.

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


[clang] [clang][analyzer] Check initialization and argument passing in FixedAddressChecker (PR #110977)

2024-10-04 Thread Balázs Kéri via cfe-commits

balazske wrote:

I was thinking about using `check::Location` in this checker. The real problem 
is when the fixed address is used (to store or load), not if it is assigned to 
a pointer. (Or a fixed address becomes escaped.) Or both cases (with the 
current checks) can be used, but then multiple warnings may occur for the same 
case (unless the checker is improved to detect such cases).
The current checker produces relatively many warnings on the tested C projects 
(like 
[this](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=vim_v8.2.1920_balazske-fixedaddress_new_b9a919d&is-unique=off&diff-type=New&checker-name=alpha.core.FixedAddr))
 and many are (I think) no real problems because just a special value is used 
in pointers but the pointer is not dereferenced.

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


[clang] [Clang][Parser] Remove the concept from the DeclContext if the definition is invalid (PR #111179)

2024-10-04 Thread Shafik Yaghmour via cfe-commits


@@ -337,6 +343,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
   ExprResult ConstraintExprResult =
   Actions.CorrectDelayedTyposInExpr(ParseConstraintExpression());
   if (ConstraintExprResult.isInvalid()) {
+if (AddedToScope)

shafik wrote:

I really don't like the `AddedToScope` pass by reference and I am wondering why 
we can't do this inside of `ActOnStartConceptDefinition`

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


[clang] [Clang] Fix __builtin_dynamic_object_size off by 4 (PR #111015)

2024-10-04 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

The point of __counted_by is precisely to supplement the normal standard rules: 
specifically, if you have counted_by, the size of the flexible array is 
precisely the size specified by the attribute.  Not whatever size is implied by 
the access.  Otherwise, it would be illegal for __bdos to use the counted_by 
attribute at all.  The size of the array can't change based on how __bdos is 
queried.

`sizeof(struct s) + p->count * sizeof(*p->array))` is a weird compromise: it's 
not unbounded, but it's larger than the size specified by the standard.

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


[clang] [flang] [llvm] [openmp] [flang][driver] rename flang-new to flang (PR #110023)

2024-10-04 Thread Brad Richardson via cfe-commits


@@ -787,6 +787,9 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   if (Args.hasArg(options::OPT_fopenmp_force_usm))
 CmdArgs.push_back("-fopenmp-force-usm");
+  // TODO: OpenMP support isn't "done" yet, so for now we warn that it
+  // is experimental.
+  D.Diag(diag::warn_openmp_experimental);

everythingfunctional wrote:

While I was slightly hesitant to add a test for a temporary warning, I've done 
so. If anyone else thinks it doesn't belong I'll undo it.

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


[clang] Turn `-Wdeprecated-literal-operator` on by default (PR #111027)

2024-10-04 Thread Erich Keane via cfe-commits

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/111027

>From 21dc8df292d85b7f48f75ea2a707be6c4971e2f9 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Thu, 3 Oct 2024 09:41:08 -0700
Subject: [PATCH 1/2] Turn Wdeprecated-literal-operator on by default

It would be nice to see what our users think about this change, as this
is something that WG21/EWG quite wants to fix a handful of questionable
issues with UB. Depending on the outcome of this after being committed,
we might instead suggest EWG undeprecate this, and require a bit of
'magic' from the lexer.

Additionally, this patch makes it so we emit this diagnostic ALSO in
cases where the literal name is reserved.  It doesn't make sense to
limit that.
---
 clang/docs/ReleaseNotes.rst   | 22 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +-
 clang/lib/Sema/SemaExprCXX.cpp| 21 +++---
 clang/test/CXX/drs/cwg14xx.cpp|  2 +-
 clang/test/CXX/drs/cwg17xx.cpp|  3 +
 clang/test/CXX/drs/cwg25xx.cpp|  3 +
 clang/test/CXX/lex/lex.literal/lex.ext/p1.cpp |  2 +-
 .../test/CXX/lex/lex.literal/lex.ext/p10.cpp  |  2 +-
 .../test/CXX/lex/lex.literal/lex.ext/p11.cpp  |  6 +-
 clang/test/CXX/lex/lex.literal/lex.ext/p3.cpp | 10 +--
 clang/test/CXX/lex/lex.literal/lex.ext/p4.cpp | 10 +--
 clang/test/CXX/lex/lex.literal/lex.ext/p5.cpp |  8 +--
 clang/test/CXX/lex/lex.literal/lex.ext/p6.cpp |  8 +--
 clang/test/CXX/lex/lex.literal/lex.ext/p7.cpp |  6 +-
 clang/test/CXX/lex/lex.literal/lex.ext/p8.cpp |  6 +-
 clang/test/CXX/lex/lex.literal/lex.ext/p9.cpp |  2 +-
 .../CXX/over/over.oper/over.literal/p2.cpp| 28 
 .../CXX/over/over.oper/over.literal/p3.cpp| 66 +--
 .../CXX/over/over.oper/over.literal/p5.cpp| 20 +++---
 .../CXX/over/over.oper/over.literal/p6.cpp| 12 ++--
 .../CXX/over/over.oper/over.literal/p7.cpp| 10 +--
 .../CXX/over/over.oper/over.literal/p8.cpp| 16 ++---
 clang/test/FixIt/fixit-c++11.cpp  |  4 +-
 clang/test/Parser/cxx0x-literal-operators.cpp |  6 +-
 .../Parser/cxx11-user-defined-literals.cpp| 29 
 .../cxx11-user-defined-literals-unused.cpp|  4 +-
 .../SemaCXX/cxx11-user-defined-literals.cpp   | 60 -
 clang/test/SemaCXX/cxx2a-consteval.cpp|  6 +-
 clang/test/SemaCXX/cxx98-compat.cpp   |  2 +-
 clang/test/SemaCXX/literal-operators.cpp  | 46 ++---
 ...ser-defined-literals-in-system-headers.cpp |  3 +-
 clang/test/SemaCXX/reserved-identifier.cpp|  8 ++-
 clang/test/SemaCXX/warn-xor-as-pow.cpp|  6 +-
 33 files changed, 237 insertions(+), 202 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 44d5f348ed2d54..edd1f1d2302d58 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -99,6 +99,20 @@ C++ Specific Potentially Breaking Changes
 // Was error, now evaluates to false.
 constexpr bool b = f() == g();
 
+- The warning ``-Wdeprecated-literal-operator`` is now on by default, as this 
is
+  something that WG21 has shown interest in removing from the language. The
+  result is that anyone who is compiling with ``-Werror`` should see this
+  diagnostic.  To fix this diagnostic, simply removing the space character from
+  between the ``operator""`` and the user defined literal name will make the
+  source no longer deprecated. This is consistent with CWG2521.
+
+  .. code-block:: c++
+
+// Now diagnoses by default.
+unsigned operator"" _udl_name(unsigned long long);
+// Fixed version:
+unsigned operator""_udl_name(unsigned long long);
+
 ABI Changes in This Version
 ---
 
@@ -216,6 +230,10 @@ Resolutions to C++ Defect Reports
 - Clang now allows trailing requires clause on explicit deduction guides.
   (`CWG2707: Deduction guides cannot have a trailing requires-clause 
`_).
 
+- Clang now diagnoses a space in the first production of a 
``literal-operator-id``
+  by default.
+  (`CWG2521: User-defined literals and reserved identifiers 
`_).
+
 C Language Changes
 --
 
@@ -378,6 +396,10 @@ Improvements to Clang's diagnostics
 
 - Clang now emits a diagnostic note at the class declaration when the method 
definition does not match any declaration (#GH110638).
 
+- Clang now emits a ``-Wdepredcated-literal-operator`` diagnostic, even if the
+  name was a reserved name, which we improperly allowed to suppress the
+  diagnostic.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dc84110ef78211..3c9f6ecb506e36 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -439,7 +439,7 @@ def warn_reserv

[clang] 2997a67 - [Sema] Avoid repeated hash lookups (NFC) (#111090)

2024-10-04 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-10-04T07:37:11-07:00
New Revision: 2997a67172e0f3752f9f25210d86ba6fa65e63e7

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

LOG: [Sema] Avoid repeated hash lookups (NFC) (#111090)

Added: 


Modified: 
clang/lib/Sema/SemaLambda.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index c2b35856111f3b..aeb20299b714a3 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -423,11 +423,11 @@ bool Sema::DiagnoseInvalidExplicitObjectParameterInLambda(
   // is an empty cast path for the method stored in the context (signalling 
that
   // we've already diagnosed it) and then just not building the call, but that
   // doesn't really seem any simpler than diagnosing it at the call site...
-  if (auto It = Context.LambdaCastPaths.find(Method);
-  It != Context.LambdaCastPaths.end())
+  auto [It, Inserted] = Context.LambdaCastPaths.try_emplace(Method);
+  if (!Inserted)
 return It->second.empty();
 
-  CXXCastPath &Path = Context.LambdaCastPaths[Method];
+  CXXCastPath &Path = It->second;
   CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
  /*DetectVirtual=*/false);
   if (!IsDerivedFrom(RD->getLocation(), ExplicitObjectParameterType, 
LambdaType,



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


[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic (PR #111010)

2024-10-04 Thread Finn Plummer via cfe-commits


@@ -2653,6 +2653,21 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register 
ResVReg,
 .addUse(GR.getSPIRVTypeID(ResType))
 .addUse(GR.getOrCreateConstInt(3, I, IntTy, TII));
   }
+  case Intrinsic::spv_wave_read_lane_at: {
+assert(I.getNumOperands() == 4);
+assert(I.getOperand(2).isReg());
+assert(I.getOperand(3).isReg());
+
+// Defines the execution scope currently 2 for group, see scope table
+SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType(32, I, TII);
+return BuildMI(BB, I, I.getDebugLoc(),
+   TII.get(SPIRV::OpGroupNonUniformShuffle))
+.addDef(ResVReg)
+.addUse(GR.getSPIRVTypeID(ResType))
+.addUse(I.getOperand(2).getReg())
+.addUse(I.getOperand(3).getReg())
+.addUse(GR.getOrCreateConstInt(2, I, IntTy, TII));

inbelic wrote:

Right, it should facilitate communication within the wave not between waves. 
Thanks.

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


[clang] [flang] [llvm] [mlir] Make Ownership of MachineModuleInfo in Its Wrapper Pass External (PR #110443)

2024-10-04 Thread Matin Raayai via cfe-commits

matinraayai wrote:

I dug up the commit that introduced `LLVMTargetMachine`: 
https://github.com/llvm/llvm-project/commit/12e97307a10bbac6bf9e6733833b84faf06dee88.
 It dates back to before when the MC layer was created. It seems the motivation 
was to allow a hypothetical target to generate code using whatever code 
generator it wants internally (be it the one provided by LLVM at the time or 
some other external library). The MC stuff was later on added on top of it 
around 2010, which I think made this abstraction a bit pointless, since MC and 
CodeGen integrate tightly together, and there's no point to have support for 
only one layer.

Given the issues faced when joining `TM` and `LLVMTM`, I think this abstraction 
should be respected. The key takeaway from this abstraction is that `TM` 
__must__ have a function that generates object files/MC; It's just that those 
interface functions should be void of any CodeGen related constructs (even the 
`MMIWP`). TLDR: We should follow this rule of thumb: __If it uses LLVM's 
CodeGen it belongs to the `LLVMTM` class, otherwise it belongs to `TM`__ (The 
same goes for all the `MachineFunctionInfo` stuff; They should be moved to 
`LLVMTM`).

This is a cause of concern for managing the lifetime of `MMI`: For `TM` 
interfaces, `MMI`'s lifetime should be managed by the `MMIWP` pass, otherwise 
it will get deleted when it goes out of the scope of the pass building 
function. For `LLVMTM` interface, however, `MMI` should be managed externally 
by the interface user. I think both should exist.

This also relates to a question that I had regarding the new PM codegen 
interface `buildCodeGenPipeline` @aeubanks: how exactly is the `MMI`'s lifetime 
managed after calling this function? If it's possible I want to talk more about 
it offline (You can find me on LLVM's Discord).

> I see that MMI really is a Codegen concept and not a Target concept, so 
> that's why it takes an LLVMTargetMachine instead of TargetMachine. However, 
> the `static_cast`s everywhere are extremely unfortunate. And it doesn't make 
> sense to make the return type of `Target::createTargetMachine()` 
> `LLVMTargetMachine` instead of `TargetMachine`. Perhaps alternatively we make 
> the MMI constructor take `TargetMachine` and cast it inside the constructor 
> to `LLVMTargetMachine`, so we only pay the cost of this weird distinction in 
> one place rather than everywhere? wdyt?

To get back to your question @aeubanks  I don't think we should force any casts 
in the `MMI` constructor; Instead we should address the `TM`/`LLVMTM` 
abstraction issue. The casting will then take care of itself. Also there should 
be a `Target::createLLVMTargetMachine()` for those who want to explicitly 
manage `MMI`'s lifetime and want to use LLVm CodeGen.

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


[clang] Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)" (PR #111173)

2024-10-04 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Can you also add the previous regressing case to the test? Thanks
https://github.com/llvm/llvm-project/pull/106585#issuecomment-2368947247

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


[clang] Add z/OS customization file (PR #111182)

2024-10-04 Thread Sean Perry via cfe-commits

https://github.com/perry-ca created 
https://github.com/llvm/llvm-project/pull/82

On z/OS, the location of the system libraries and side decks (aka equivalent to 
libc, etc) are not in a predefined location.  The system does have a default 
location but sysadmins can change this and frequently do.  See the -mzos-hlq* 
options we have for z/OS.

To avoid every user needing to specify these -mzos-hlq* options, we added 
support for a system install default config file that is always read 
independent of the usual config file.  The compiler will read this 
customization config file before reading the usual config files.

The customization file is called clang.cfg and is located in:
- the etc dir within the compiler installation dir.
- or specified by the CLANG_CONFIG_PATH env var.  This env var can either be a 
directory or the fill path name of the file.

>From 360bab981d8ec36e17aa4fbadbb4feef42c5d135 Mon Sep 17 00:00:00 2001
From: Sean Perry 
Date: Fri, 4 Oct 2024 10:09:32 -0500
Subject: [PATCH] Add z/OS customization file

---
 clang/include/clang/Driver/Driver.h   |  5 +++
 clang/lib/Driver/Driver.cpp   | 33 +++
 clang/test/Driver/Inputs/config-zos/clang.cfg |  1 +
 clang/test/Driver/Inputs/config-zos/def.cfg   |  1 +
 .../test/Driver/Inputs/config-zos/tst/def.cfg |  1 +
 clang/test/Driver/config-zos.c| 17 ++
 clang/test/Driver/config-zos1.c   | 23 +
 7 files changed, 81 insertions(+)
 create mode 100644 clang/test/Driver/Inputs/config-zos/clang.cfg
 create mode 100644 clang/test/Driver/Inputs/config-zos/def.cfg
 create mode 100644 clang/test/Driver/Inputs/config-zos/tst/def.cfg
 create mode 100644 clang/test/Driver/config-zos.c
 create mode 100644 clang/test/Driver/config-zos1.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 9177d56718ee77..5466659044ba22 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -738,6 +738,11 @@ class Driver {
   /// \returns true if error occurred.
   bool loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx);
 
+  /// Tries to load options from customization file.
+  ///
+  /// \returns true if error occurred.
+  bool loadZOSCustomizationFile(llvm::cl::ExpansionContext &);
+
   /// Read options from the specified file.
   ///
   /// \param [in] FileName File to read.
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e9bf60d5e2ee46..dcf01cc2c29ee8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -998,6 +998,34 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation 
&C,
   //
 }
 
+bool Driver::loadZOSCustomizationFile(llvm::cl::ExpansionContext &ExpCtx) {
+  if (IsCLMode() || IsDXCMode() || IsFlangMode())
+return false;
+
+  SmallString<128> CustomizationFile;
+  StringRef PathLIBEnv = StringRef(getenv("CLANG_CONFIG_PATH")).trim();
+  // If the env var is a directory then append "/clang.cfg" and treat
+  // that as the config file.  Otherwise treat the env var as the
+  // config file.
+  if (!PathLIBEnv.empty()) {
+llvm::sys::path::append(CustomizationFile, PathLIBEnv);
+if (llvm::sys::fs::is_directory(PathLIBEnv))
+  llvm::sys::path::append(CustomizationFile, "/clang.cfg");
+if (llvm::sys::fs::is_regular_file(CustomizationFile))
+  return readConfigFile(CustomizationFile, ExpCtx);
+Diag(diag::err_drv_config_file_not_found) << CustomizationFile;
+return true;
+  }
+
+  SmallString<128> BaseDir(llvm::sys::path::parent_path(Dir));
+  llvm::sys::path::append(CustomizationFile, BaseDir + "/etc/clang.cfg");
+  if (llvm::sys::fs::is_regular_file(CustomizationFile))
+return readConfigFile(CustomizationFile, ExpCtx);
+
+  // If no customization file, just return
+  return false;
+}
+
 static void appendOneArg(InputArgList &Args, const Arg *Opt,
  const Arg *BaseArg) {
   // The args for config files or /clang: flags belong to different 
InputArgList
@@ -1179,6 +1207,11 @@ bool 
Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
 assert(!Triple.empty());
   }
 
+  // On z/OS, start by loading the customization file before loading
+  // the usual default config file(s).
+  if (llvm::Triple(Triple).isOSzOS() && loadZOSCustomizationFile(ExpCtx))
+return true;
+
   // Search for config files in the following order:
   // 1. -.cfg using real driver mode
   //(e.g. i386-pc-linux-gnu-clang++.cfg).
diff --git a/clang/test/Driver/Inputs/config-zos/clang.cfg 
b/clang/test/Driver/Inputs/config-zos/clang.cfg
new file mode 100644
index 00..43a5dbfaa61826
--- /dev/null
+++ b/clang/test/Driver/Inputs/config-zos/clang.cfg
@@ -0,0 +1 @@
+-DABC=123
diff --git a/clang/test/Driver/Inputs/config-zos/def.cfg 
b/clang/test/Driver/Inputs/config-zos/def.cfg
new file mode 100644
index 00..156f9c85fb4f2e
--- /dev/null
+++ b/clang/test/Driver/Inputs/co

[clang] Add z/OS customization file (PR #111182)

2024-10-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sean Perry (perry-ca)


Changes

On z/OS, the location of the system libraries and side decks (aka equivalent to 
libc, etc) are not in a predefined location.  The system does have a default 
location but sysadmins can change this and frequently do.  See the -mzos-hlq* 
options we have for z/OS.

To avoid every user needing to specify these -mzos-hlq* options, we added 
support for a system install default config file that is always read 
independent of the usual config file.  The compiler will read this 
customization config file before reading the usual config files.

The customization file is called clang.cfg and is located in:
- the etc dir within the compiler installation dir.
- or specified by the CLANG_CONFIG_PATH env var.  This env var can either be a 
directory or the fill path name of the file.

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


7 Files Affected:

- (modified) clang/include/clang/Driver/Driver.h (+5) 
- (modified) clang/lib/Driver/Driver.cpp (+33) 
- (added) clang/test/Driver/Inputs/config-zos/clang.cfg (+1) 
- (added) clang/test/Driver/Inputs/config-zos/def.cfg (+1) 
- (added) clang/test/Driver/Inputs/config-zos/tst/def.cfg (+1) 
- (added) clang/test/Driver/config-zos.c (+17) 
- (added) clang/test/Driver/config-zos1.c (+23) 


``diff
diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 9177d56718ee77..5466659044ba22 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -738,6 +738,11 @@ class Driver {
   /// \returns true if error occurred.
   bool loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx);
 
+  /// Tries to load options from customization file.
+  ///
+  /// \returns true if error occurred.
+  bool loadZOSCustomizationFile(llvm::cl::ExpansionContext &);
+
   /// Read options from the specified file.
   ///
   /// \param [in] FileName File to read.
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e9bf60d5e2ee46..dcf01cc2c29ee8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -998,6 +998,34 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation 
&C,
   //
 }
 
+bool Driver::loadZOSCustomizationFile(llvm::cl::ExpansionContext &ExpCtx) {
+  if (IsCLMode() || IsDXCMode() || IsFlangMode())
+return false;
+
+  SmallString<128> CustomizationFile;
+  StringRef PathLIBEnv = StringRef(getenv("CLANG_CONFIG_PATH")).trim();
+  // If the env var is a directory then append "/clang.cfg" and treat
+  // that as the config file.  Otherwise treat the env var as the
+  // config file.
+  if (!PathLIBEnv.empty()) {
+llvm::sys::path::append(CustomizationFile, PathLIBEnv);
+if (llvm::sys::fs::is_directory(PathLIBEnv))
+  llvm::sys::path::append(CustomizationFile, "/clang.cfg");
+if (llvm::sys::fs::is_regular_file(CustomizationFile))
+  return readConfigFile(CustomizationFile, ExpCtx);
+Diag(diag::err_drv_config_file_not_found) << CustomizationFile;
+return true;
+  }
+
+  SmallString<128> BaseDir(llvm::sys::path::parent_path(Dir));
+  llvm::sys::path::append(CustomizationFile, BaseDir + "/etc/clang.cfg");
+  if (llvm::sys::fs::is_regular_file(CustomizationFile))
+return readConfigFile(CustomizationFile, ExpCtx);
+
+  // If no customization file, just return
+  return false;
+}
+
 static void appendOneArg(InputArgList &Args, const Arg *Opt,
  const Arg *BaseArg) {
   // The args for config files or /clang: flags belong to different 
InputArgList
@@ -1179,6 +1207,11 @@ bool 
Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
 assert(!Triple.empty());
   }
 
+  // On z/OS, start by loading the customization file before loading
+  // the usual default config file(s).
+  if (llvm::Triple(Triple).isOSzOS() && loadZOSCustomizationFile(ExpCtx))
+return true;
+
   // Search for config files in the following order:
   // 1. -.cfg using real driver mode
   //(e.g. i386-pc-linux-gnu-clang++.cfg).
diff --git a/clang/test/Driver/Inputs/config-zos/clang.cfg 
b/clang/test/Driver/Inputs/config-zos/clang.cfg
new file mode 100644
index 00..43a5dbfaa61826
--- /dev/null
+++ b/clang/test/Driver/Inputs/config-zos/clang.cfg
@@ -0,0 +1 @@
+-DABC=123
diff --git a/clang/test/Driver/Inputs/config-zos/def.cfg 
b/clang/test/Driver/Inputs/config-zos/def.cfg
new file mode 100644
index 00..156f9c85fb4f2e
--- /dev/null
+++ b/clang/test/Driver/Inputs/config-zos/def.cfg
@@ -0,0 +1 @@
+-DDEF=456
diff --git a/clang/test/Driver/Inputs/config-zos/tst/def.cfg 
b/clang/test/Driver/Inputs/config-zos/tst/def.cfg
new file mode 100644
index 00..156f9c85fb4f2e
--- /dev/null
+++ b/clang/test/Driver/Inputs/config-zos/tst/def.cfg
@@ -0,0 +1 @@
+-DDEF=456
diff --git a/clang/test/Driver/config-zos.c b/clang/test/Driver/config-zos.c
new file mode 100644
index 00..8de02ec101b914

[clang] Add z/OS customization file (PR #111182)

2024-10-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Sean Perry (perry-ca)


Changes

On z/OS, the location of the system libraries and side decks (aka equivalent to 
libc, etc) are not in a predefined location.  The system does have a default 
location but sysadmins can change this and frequently do.  See the -mzos-hlq* 
options we have for z/OS.

To avoid every user needing to specify these -mzos-hlq* options, we added 
support for a system install default config file that is always read 
independent of the usual config file.  The compiler will read this 
customization config file before reading the usual config files.

The customization file is called clang.cfg and is located in:
- the etc dir within the compiler installation dir.
- or specified by the CLANG_CONFIG_PATH env var.  This env var can either be a 
directory or the fill path name of the file.

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


7 Files Affected:

- (modified) clang/include/clang/Driver/Driver.h (+5) 
- (modified) clang/lib/Driver/Driver.cpp (+33) 
- (added) clang/test/Driver/Inputs/config-zos/clang.cfg (+1) 
- (added) clang/test/Driver/Inputs/config-zos/def.cfg (+1) 
- (added) clang/test/Driver/Inputs/config-zos/tst/def.cfg (+1) 
- (added) clang/test/Driver/config-zos.c (+17) 
- (added) clang/test/Driver/config-zos1.c (+23) 


``diff
diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 9177d56718ee77..5466659044ba22 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -738,6 +738,11 @@ class Driver {
   /// \returns true if error occurred.
   bool loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx);
 
+  /// Tries to load options from customization file.
+  ///
+  /// \returns true if error occurred.
+  bool loadZOSCustomizationFile(llvm::cl::ExpansionContext &);
+
   /// Read options from the specified file.
   ///
   /// \param [in] FileName File to read.
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e9bf60d5e2ee46..dcf01cc2c29ee8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -998,6 +998,34 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation 
&C,
   //
 }
 
+bool Driver::loadZOSCustomizationFile(llvm::cl::ExpansionContext &ExpCtx) {
+  if (IsCLMode() || IsDXCMode() || IsFlangMode())
+return false;
+
+  SmallString<128> CustomizationFile;
+  StringRef PathLIBEnv = StringRef(getenv("CLANG_CONFIG_PATH")).trim();
+  // If the env var is a directory then append "/clang.cfg" and treat
+  // that as the config file.  Otherwise treat the env var as the
+  // config file.
+  if (!PathLIBEnv.empty()) {
+llvm::sys::path::append(CustomizationFile, PathLIBEnv);
+if (llvm::sys::fs::is_directory(PathLIBEnv))
+  llvm::sys::path::append(CustomizationFile, "/clang.cfg");
+if (llvm::sys::fs::is_regular_file(CustomizationFile))
+  return readConfigFile(CustomizationFile, ExpCtx);
+Diag(diag::err_drv_config_file_not_found) << CustomizationFile;
+return true;
+  }
+
+  SmallString<128> BaseDir(llvm::sys::path::parent_path(Dir));
+  llvm::sys::path::append(CustomizationFile, BaseDir + "/etc/clang.cfg");
+  if (llvm::sys::fs::is_regular_file(CustomizationFile))
+return readConfigFile(CustomizationFile, ExpCtx);
+
+  // If no customization file, just return
+  return false;
+}
+
 static void appendOneArg(InputArgList &Args, const Arg *Opt,
  const Arg *BaseArg) {
   // The args for config files or /clang: flags belong to different 
InputArgList
@@ -1179,6 +1207,11 @@ bool 
Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
 assert(!Triple.empty());
   }
 
+  // On z/OS, start by loading the customization file before loading
+  // the usual default config file(s).
+  if (llvm::Triple(Triple).isOSzOS() && loadZOSCustomizationFile(ExpCtx))
+return true;
+
   // Search for config files in the following order:
   // 1. -.cfg using real driver mode
   //(e.g. i386-pc-linux-gnu-clang++.cfg).
diff --git a/clang/test/Driver/Inputs/config-zos/clang.cfg 
b/clang/test/Driver/Inputs/config-zos/clang.cfg
new file mode 100644
index 00..43a5dbfaa61826
--- /dev/null
+++ b/clang/test/Driver/Inputs/config-zos/clang.cfg
@@ -0,0 +1 @@
+-DABC=123
diff --git a/clang/test/Driver/Inputs/config-zos/def.cfg 
b/clang/test/Driver/Inputs/config-zos/def.cfg
new file mode 100644
index 00..156f9c85fb4f2e
--- /dev/null
+++ b/clang/test/Driver/Inputs/config-zos/def.cfg
@@ -0,0 +1 @@
+-DDEF=456
diff --git a/clang/test/Driver/Inputs/config-zos/tst/def.cfg 
b/clang/test/Driver/Inputs/config-zos/tst/def.cfg
new file mode 100644
index 00..156f9c85fb4f2e
--- /dev/null
+++ b/clang/test/Driver/Inputs/config-zos/tst/def.cfg
@@ -0,0 +1 @@
+-DDEF=456
diff --git a/clang/test/Driver/config-zos.c b/clang/test/Driver/config-zos.c
new file mode 100644
index 00..8de02ec

[clang] Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)" (PR #111173)

2024-10-04 Thread Matheus Izvekov via cfe-commits


@@ -4159,7 +4159,7 @@ FunctionTemplateDecl *FunctionDecl::getPrimaryTemplate() 
const {
   if (FunctionTemplateSpecializationInfo *Info
 = TemplateOrSpecialization
 .dyn_cast()) {
-return Info->getTemplate();
+return Info->getTemplate()->getMostRecentDecl();

mizvekov wrote:

Why do we need to get the most recent declaration in all these places?

I worry this will cause us problems in the future, where for example in friend 
declarations, the exact redeclaration can be significant.

Won't this also degrade source representation accuracy?

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


[clang] Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)" (PR #111173)

2024-10-04 Thread Erich Keane via cfe-commits


@@ -4159,7 +4159,7 @@ FunctionTemplateDecl *FunctionDecl::getPrimaryTemplate() 
const {
   if (FunctionTemplateSpecializationInfo *Info
 = TemplateOrSpecialization
 .dyn_cast()) {
-return Info->getTemplate();
+return Info->getTemplate()->getMostRecentDecl();

erichkeane wrote:

Most recent guarantees you have 'the most' information about the declaration, 
but there might be value in getting the definition if available, else most 
recent?

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


[clang] [Clang][Parser] Remove the concept from the DeclContext if the definition is invalid (PR #111179)

2024-10-04 Thread Younan Zhang via cfe-commits


@@ -1151,3 +1151,17 @@ int test() {
 }
 
 }
+
+namespace GH109780 {
+
+template 
+concept Concept; // expected-error {{expected '='}}
+
+bool val = Concept; // expected-error {{use of undeclared identifier 
'Concept'}}

zyn0217 wrote:

It could be improved as to the confusing language 'undeclared identifier'.

We probably could continue as if the concept was defined as `= false`, but I'm 
not sure there's much value in it.

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


[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic (PR #111010)

2024-10-04 Thread Steven Perron via cfe-commits


@@ -0,0 +1,28 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32v1.3-vulkan-unknown %s -o 
- | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-unknown %s -o - 
-filetype=obj | spirv-val %}
+
+; Test lowering to spir-v backend
+
+; CHECK-DAG:   %[[#uint:]] = OpTypeInt 32 0
+; CHECK-DAG:   %[[#scope:]] = OpConstant %[[#uint]] 3
+; CHECK-DAG:   %[[#f32:]] = OpTypeFloat 32
+; CHECK-DAG:   %[[#expr:]] = OpFunctionParameter %[[#f32]]
+; CHECK-DAG:   %[[#idx:]] = OpFunctionParameter %[[#uint]]
+
+define spir_func void @test_1(float %expr, i32 %idx) #0 {
+entry:
+  %0 = call token @llvm.experimental.convergence.entry()
+; CHECK:   %[[#ret:]] = OpGroupNonUniformShuffle %[[#f32]] %[[#expr]] 
%[[#idx]] %[[#scope]]
+  %1 = call float @llvm.spv.wave.read.lane.at(float %expr, i32 %idx) [ 
"convergencectrl"(token %0) ]

s-perron wrote:

Could you add tests that check a few different expression/return types? It 
would be good to make sure that ti does not always return a float. It does not 
have to be as extensive as the DX test. Maybe just an 32-bit int and a vector 
of some sort.

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


[clang] Make PCH's respect any VFS specified. (PR #106577)

2024-10-04 Thread Ben Langmuir via cfe-commits

benlangmuir wrote:

> `-emit-pch -o "%t.pch" %t/From/../From/B.h`

> `'could not find file 
> 'D:\llvm-project\build\tools\clang\test\VFS\Output\remap-to-fake.c.tmp\From\..\From\B.h'`

Isn't that the same issue I mentioned, that it doesn't appear to work for the 
main PCH input file?  If you remove everything else except this file does it 
make progress?  If so, fixing whatever is going wrong with the main input seems 
promising.

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


[clang] [compiler-rt] [llvm] [FMV][AArch64] Unify features ssbs and ssbs2. (PR #110297)

2024-10-04 Thread Jon Roelofs via cfe-commits

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


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


[clang] Turn `-Wdeprecated-literal-operator` on by default (PR #111027)

2024-10-04 Thread Vlad Serebrennikov via cfe-commits


@@ -99,6 +99,20 @@ C++ Specific Potentially Breaking Changes
 // Was error, now evaluates to false.
 constexpr bool b = f() == g();
 
+- The warning ``-Wdeprecated-literal-operator`` is now on by default, as this 
is
+  something that WG21 has shown interest in removing from the language. The
+  result is that anyone who is compiling with ``-Werror`` should see this
+  diagnostic.  To fix this diagnostic, simply removing the space character from
+  between the ``operator""`` and the user defined literal name will make the
+  source no longer deprecated. This is consistent with CWG2521.

Endilll wrote:

```suggestion
  source no longer deprecated. This is consistent with `CWG2521 
_`.
```

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


[clang] Turn `-Wdeprecated-literal-operator` on by default (PR #111027)

2024-10-04 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

I'm happy that we stop issuing diagnostics that contradict each other.

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


[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic (PR #111010)

2024-10-04 Thread Finn Plummer via cfe-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/111010

>From 70089645ec5cf62b491a56df96ec46f4328fbc11 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Thu, 3 Oct 2024 11:43:51 -0700
Subject: [PATCH 1/3] [HLSL] Implement `WaveReadLaneAt` intrinsic

- create a clang built-in in Builtins.td
- add semantic checking in SemaHLSL.cpp
- link the WaveReadLaneAt api in hlsl_intrinsics.h
- add lowering to spirv backend op GroupNonUniformShuffle
  with Scope = 2 (Group) in SPIRVInstructionSelector.cpp

- add tests for HLSL intrinsic lowering to spirv intrinsic in
  WaveReadLaneAt.hlsl
- add tests for sema checks in WaveReadLaneAt-errors.hlsl
- add spir-v backend tests in WaveReadLaneAt.ll
---
 clang/include/clang/Basic/Builtins.td |  6 +++
 clang/lib/CodeGen/CGBuiltin.cpp   | 16 
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  7 
 clang/lib/Sema/SemaHLSL.cpp   | 20 ++
 .../CodeGenHLSL/builtins/WaveReadLaneAt.hlsl  | 40 +++
 .../BuiltIns/WaveReadLaneAt-errors.hlsl   | 21 ++
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 15 +++
 .../SPIRV/hlsl-intrinsics/WaveReadLaneAt.ll   | 28 +
 10 files changed, 155 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/WaveReadLaneAt.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/WaveReadLaneAt-errors.hlsl
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveReadLaneAt.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8090119e512fbb..eec9acd4d27d7d 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4703,6 +4703,12 @@ def HLSLWaveIsFirstLane : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "bool()";
 }
 
+def HLSLWaveReadLaneAt : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_wave_read_lane_at"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 def HLSLClamp : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_clamp"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index da3eca73bfb575..dff56af9282e9d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18835,6 +18835,22 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic();
 return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
   }
+  case Builtin::BI__builtin_hlsl_wave_read_lane_at: {
+// Due to the use of variadic arguments we must explicitly retreive them 
and
+// create our function type.
+Value *OpExpr = EmitScalarExpr(E->getArg(0));
+Value *OpIndex = EmitScalarExpr(E->getArg(1));
+llvm::FunctionType *FT = llvm::FunctionType::get(
+OpExpr->getType(), ArrayRef{OpExpr->getType(), OpIndex->getType()},
+false);
+
+// Get overloaded name
+std::string name =
+Intrinsic::getName(CGM.getHLSLRuntime().getWaveReadLaneAtIntrinsic(),
+   ArrayRef{OpExpr->getType()}, &CGM.getModule());
+return EmitRuntimeCall(CGM.CreateRuntimeFunction(FT, name, {}, false, 
true),
+   ArrayRef{OpExpr, OpIndex}, 
"hlsl.wave.read.lane.at");
+  }
   case Builtin::BI__builtin_hlsl_elementwise_sign: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 llvm::Type *Xty = Op0->getType();
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index a8aabca7348ffb..a639ce2d784f4a 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -87,6 +87,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_read_lane_at)
 
   
//===--===//
   // End of reserved area for HLSL intrinsic getters.
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 810a16d75f0228..a7bdc353ae71bf 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -2015,6 +2015,13 @@ _HLSL_AVAILABILITY(shadermodel, 6.0)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_is_first_lane)
 __attribute__((convergent)) bool WaveIsFirstLane();
 
+// \brief Returns the value of the expression for the given lane index within
+// the specified wave.
+template 
+_HLSL_AVAILABILITY(shadermodel, 6.0)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_read_lane_at)
+__attribute__((convergent)) T WaveReadLaneAt(T, int32_t);
+
 
//===---

[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic (PR #111010)

2024-10-04 Thread Finn Plummer via cfe-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/111010

>From 70089645ec5cf62b491a56df96ec46f4328fbc11 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Thu, 3 Oct 2024 11:43:51 -0700
Subject: [PATCH 1/3] [HLSL] Implement `WaveReadLaneAt` intrinsic

- create a clang built-in in Builtins.td
- add semantic checking in SemaHLSL.cpp
- link the WaveReadLaneAt api in hlsl_intrinsics.h
- add lowering to spirv backend op GroupNonUniformShuffle
  with Scope = 2 (Group) in SPIRVInstructionSelector.cpp

- add tests for HLSL intrinsic lowering to spirv intrinsic in
  WaveReadLaneAt.hlsl
- add tests for sema checks in WaveReadLaneAt-errors.hlsl
- add spir-v backend tests in WaveReadLaneAt.ll
---
 clang/include/clang/Basic/Builtins.td |  6 +++
 clang/lib/CodeGen/CGBuiltin.cpp   | 16 
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  7 
 clang/lib/Sema/SemaHLSL.cpp   | 20 ++
 .../CodeGenHLSL/builtins/WaveReadLaneAt.hlsl  | 40 +++
 .../BuiltIns/WaveReadLaneAt-errors.hlsl   | 21 ++
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 15 +++
 .../SPIRV/hlsl-intrinsics/WaveReadLaneAt.ll   | 28 +
 10 files changed, 155 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/WaveReadLaneAt.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/WaveReadLaneAt-errors.hlsl
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveReadLaneAt.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8090119e512fbb..eec9acd4d27d7d 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4703,6 +4703,12 @@ def HLSLWaveIsFirstLane : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "bool()";
 }
 
+def HLSLWaveReadLaneAt : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_wave_read_lane_at"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 def HLSLClamp : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_clamp"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index da3eca73bfb575..dff56af9282e9d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18835,6 +18835,22 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic();
 return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
   }
+  case Builtin::BI__builtin_hlsl_wave_read_lane_at: {
+// Due to the use of variadic arguments we must explicitly retreive them 
and
+// create our function type.
+Value *OpExpr = EmitScalarExpr(E->getArg(0));
+Value *OpIndex = EmitScalarExpr(E->getArg(1));
+llvm::FunctionType *FT = llvm::FunctionType::get(
+OpExpr->getType(), ArrayRef{OpExpr->getType(), OpIndex->getType()},
+false);
+
+// Get overloaded name
+std::string name =
+Intrinsic::getName(CGM.getHLSLRuntime().getWaveReadLaneAtIntrinsic(),
+   ArrayRef{OpExpr->getType()}, &CGM.getModule());
+return EmitRuntimeCall(CGM.CreateRuntimeFunction(FT, name, {}, false, 
true),
+   ArrayRef{OpExpr, OpIndex}, 
"hlsl.wave.read.lane.at");
+  }
   case Builtin::BI__builtin_hlsl_elementwise_sign: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 llvm::Type *Xty = Op0->getType();
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index a8aabca7348ffb..a639ce2d784f4a 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -87,6 +87,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_read_lane_at)
 
   
//===--===//
   // End of reserved area for HLSL intrinsic getters.
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 810a16d75f0228..a7bdc353ae71bf 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -2015,6 +2015,13 @@ _HLSL_AVAILABILITY(shadermodel, 6.0)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_is_first_lane)
 __attribute__((convergent)) bool WaveIsFirstLane();
 
+// \brief Returns the value of the expression for the given lane index within
+// the specified wave.
+template 
+_HLSL_AVAILABILITY(shadermodel, 6.0)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_read_lane_at)
+__attribute__((convergent)) T WaveReadLaneAt(T, int32_t);
+
 
//===---

[clang] Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)" (PR #111173)

2024-10-04 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/73

>From 51f84ce80ddda9e12591f263a24a19238fc69cb8 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Mon, 23 Sep 2024 10:51:21 -0400
Subject: [PATCH 1/2] Reapply "[Clang][Sema] Refactor collection of multi-level
 template argument lists (#106585)"

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/AST/DeclTemplate.h|  66 +-
 clang/include/clang/Sema/Sema.h   |  25 +-
 clang/lib/AST/DeclTemplate.cpp|  30 +-
 clang/lib/Sema/SemaConcept.cpp|  29 +-
 clang/lib/Sema/SemaDecl.cpp   |  31 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   4 +-
 clang/lib/Sema/SemaTemplate.cpp   | 179 +++--
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  33 +-
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp |  45 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 712 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  46 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  18 +-
 clang/lib/Serialization/ASTWriterDecl.cpp |  17 +-
 .../temp/temp.constr/temp.constr.decl/p4.cpp  | 175 +
 16 files changed, 762 insertions(+), 654 deletions(-)
 create mode 100644 clang/test/CXX/temp/temp.constr/temp.constr.decl/p4.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 44d5f348ed2d54..fdb1a5942e4157 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -473,6 +473,9 @@ Bug Fixes to C++ Support
   containing outer unexpanded parameters were not correctly expanded. 
(#GH101754)
 - Fixed a bug in constraint expression comparison where the ``sizeof...`` 
expression was not handled properly
   in certain friend declarations. (#GH93099)
+- Clang now uses the correct set of template argument lists when comparing the 
constraints of
+  out-of-line definitions and member templates explicitly specialized for a 
given implicit instantiation of
+  a class template. (#GH102320)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 687715a22e9fd3..05739f39d2a496 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -781,15 +781,11 @@ class RedeclarableTemplateDecl : public TemplateDecl,
  EntryType *Entry, void *InsertPos);
 
   struct CommonBase {
-CommonBase() : InstantiatedFromMember(nullptr, false) {}
+CommonBase() {}
 
 /// The template from which this was most
 /// directly instantiated (or null).
-///
-/// The boolean value indicates whether this template
-/// was explicitly specialized.
-llvm::PointerIntPair
-  InstantiatedFromMember;
+RedeclarableTemplateDecl *InstantiatedFromMember = nullptr;
 
 /// If non-null, points to an array of specializations (including
 /// partial specializations) known only by their external declaration IDs.
@@ -809,14 +805,19 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   };
 
   /// Pointer to the common data shared by all declarations of this
-  /// template.
-  mutable CommonBase *Common = nullptr;
+  /// template, and a flag indicating if the template is a member
+  /// specialization.
+  mutable llvm::PointerIntPair Common;
+
+  CommonBase *getCommonPtrInternal() const { return Common.getPointer(); }
 
   /// Retrieves the "common" pointer shared by all (re-)declarations of
   /// the same template. Calling this routine may implicitly allocate memory
   /// for the common pointer.
   CommonBase *getCommonPtr() const;
 
+  void setCommonPtr(CommonBase *C) const { Common.setPointer(C); }
+
   virtual CommonBase *newCommon(ASTContext &C) const = 0;
 
   // Construct a template decl with name, parameters, and templated element.
@@ -857,15 +858,12 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   /// template<> template
   /// struct X::Inner { /* ... */ };
   /// \endcode
-  bool isMemberSpecialization() const {
-return getCommonPtr()->InstantiatedFromMember.getInt();
-  }
+  bool isMemberSpecialization() const { return Common.getInt(); }
 
   /// Note that this member template is a specialization.
   void setMemberSpecialization() {
-assert(getCommonPtr()->InstantiatedFromMember.getPointer() &&
-   "Only member templates can be member template specializations");
-getCommonPtr()->InstantiatedFromMember.setInt(true);
+assert(!isMemberSpecialization() && "already a member specialization");
+Common.setInt(true);
   }
 
   /// Retrieve the member template from which this template was
@@ -905,12 +903,12 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   /// void X::f(T, U);
   /// \endcode
   RedeclarableTemplateDecl *getInstantiatedFromMemberTemplate() const {
-return getCommonPtr()->InstantiatedFrom

[clang] Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)" (PR #111173)

2024-10-04 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: Krystian Stasiowski (sdkrystian)


Changes

Reapplies #106585, fixing an issue where non-dependent names of member 
templates appearing prior to that member template being explicitly specialized 
for an implicitly instantiated class template specialization would incorrectly 
use the definition of the explicitly specialized member template.


---

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


18 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/AST/DeclTemplate.h (+29-53) 
- (modified) clang/include/clang/Sema/Sema.h (+6-19) 
- (modified) clang/lib/AST/Decl.cpp (+1-1) 
- (modified) clang/lib/AST/DeclTemplate.cpp (+39-20) 
- (modified) clang/lib/Sema/SemaConcept.cpp (+12-17) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+14-17) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+85-94) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+3-30) 
- (modified) clang/lib/Sema/SemaTemplateDeductionGuide.cpp (+16-29) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+350-362) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+37-9) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+2-1) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+9-9) 
- (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+7-10) 
- (modified) clang/test/AST/ast-dump-decl.cpp (+1-1) 
- (added) clang/test/CXX/temp/temp.constr/temp.constr.decl/p4.cpp (+175) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 44d5f348ed2d54..fdb1a5942e4157 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -473,6 +473,9 @@ Bug Fixes to C++ Support
   containing outer unexpanded parameters were not correctly expanded. 
(#GH101754)
 - Fixed a bug in constraint expression comparison where the ``sizeof...`` 
expression was not handled properly
   in certain friend declarations. (#GH93099)
+- Clang now uses the correct set of template argument lists when comparing the 
constraints of
+  out-of-line definitions and member templates explicitly specialized for a 
given implicit instantiation of
+  a class template. (#GH102320)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 687715a22e9fd3..58ae7420471a6f 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -781,15 +781,11 @@ class RedeclarableTemplateDecl : public TemplateDecl,
  EntryType *Entry, void *InsertPos);
 
   struct CommonBase {
-CommonBase() : InstantiatedFromMember(nullptr, false) {}
+CommonBase() {}
 
 /// The template from which this was most
 /// directly instantiated (or null).
-///
-/// The boolean value indicates whether this template
-/// was explicitly specialized.
-llvm::PointerIntPair
-  InstantiatedFromMember;
+RedeclarableTemplateDecl *InstantiatedFromMember = nullptr;
 
 /// If non-null, points to an array of specializations (including
 /// partial specializations) known only by their external declaration IDs.
@@ -809,14 +805,19 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   };
 
   /// Pointer to the common data shared by all declarations of this
-  /// template.
-  mutable CommonBase *Common = nullptr;
+  /// template, and a flag indicating if the template is a member
+  /// specialization.
+  mutable llvm::PointerIntPair Common;
+
+  CommonBase *getCommonPtrInternal() const { return Common.getPointer(); }
 
   /// Retrieves the "common" pointer shared by all (re-)declarations of
   /// the same template. Calling this routine may implicitly allocate memory
   /// for the common pointer.
   CommonBase *getCommonPtr() const;
 
+  void setCommonPtr(CommonBase *C) const { Common.setPointer(C); }
+
   virtual CommonBase *newCommon(ASTContext &C) const = 0;
 
   // Construct a template decl with name, parameters, and templated element.
@@ -857,15 +858,12 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   /// template<> template
   /// struct X::Inner { /* ... */ };
   /// \endcode
-  bool isMemberSpecialization() const {
-return getCommonPtr()->InstantiatedFromMember.getInt();
-  }
+  bool isMemberSpecialization() const { return Common.getInt(); }
 
   /// Note that this member template is a specialization.
   void setMemberSpecialization() {
-assert(getCommonPtr()->InstantiatedFromMember.getPointer() &&
-   "Only member templates can be member template specializations");
-getCommonPtr()->InstantiatedFromMember.setInt(true);
+assert(!isMemberSpecialization() && "already a member specialization");
+Common.setInt(true);
   }
 
   /// Retrieve the member template from

[clang] [clang-tools-extra] [RecursiveASTVisitor] Skip implicit instantiations. (PR #110899)

2024-10-04 Thread via cfe-commits


@@ -2069,22 +2069,24 @@ bool 
RecursiveASTVisitor::TraverseTemplateArgumentLocsHelper(
 
 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND, DECLKIND)
\
   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, {
\
+auto TSK = D->getTemplateSpecializationKind(); 
\
 /* For implicit instantiations ("set x;"), we don't want to   
\
recurse at all, since the instatiated template isn't written in 
\
the source code anywhere.  (Note the instatiated *type* --  
\
set -- is written, and will still get a callback of
\
TemplateSpecializationType).  For explicit instantiations   
\
("template set;"), we do need a callback, since this   
\
-   is the only callback that's made for this instantiation.
\
-   We use getTemplateArgsAsWritten() to distinguish. */
\
-if (const auto *ArgsWritten = D->getTemplateArgsAsWritten()) { 
\
-  /* The args that remains unspecialized. */   
\
-  TRY_TO(TraverseTemplateArgumentLocsHelper(   
\
-  ArgsWritten->getTemplateArgs(), ArgsWritten->NumTemplateArgs));  
\
+   is the only callback that's made for this instantiation. */ 
\
+if (TSK != TSK_ImplicitInstantiation) {
\

Sirraide wrote:

I’m candidly not familiar w/ template instantiation to know if it *should* 
happen; to me it just seemed that the code in `TraverseFunctionHelper()` 
suggested that it might.

@erichkeane probably knows more about this.

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


[clang] Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)" (PR #111173)

2024-10-04 Thread Erich Keane via cfe-commits

erichkeane wrote:

Can you point out the diff from the last review?  It isn't clear.

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


[clang] [clang-tools-extra] [RecursiveASTVisitor] Skip implicit instantiations. (PR #110899)

2024-10-04 Thread via cfe-commits

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


[clang] Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)" (PR #111173)

2024-10-04 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

@erichkeane All changes made since the last review are in 
dfa5179f07b5a85c1daafd93b9f1d4bed9b4e27b

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


[clang-tools-extra] [clang-tidy] Make `P +- BS / sizeof(*P)` opt-outable in `bugprone-sizeof-expression` (PR #111178)

2024-10-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: None (whisperity)


Changes

In some cases and for projects that deal with a lot of low-level buffers, a 
pattern often emerges that an array and its full size, not in the number of 
**elements** but in **bytes**, are known with no syntax-level connection 
between the two values. In order to access the array elements, the pointer 
arithmetic involved will have to divide `SizeInBytes` (a numeric value) with 
`sizeof(*Buffer)`. Since #106061, and as reported in #110551, 
this triggered a warning from `bugprone-sizeof-expression`, as `sizeof` 
appeared in pointer arithmetic where integers are scaled.

This patch adds a new check option, 
`WarnOnSizeOfPointerArithmeticWithDivisionScaled`, which allows users to 
opt-out of warning about the **division** case. In arbitrary projects, it might 
still be worthwhile to get these warnings until an opt-**out** in order to 
detect scaling issues, especially if a project might not be using low-level 
buffers intensively.

Fixes #110551.

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


6 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp 
(+11-2) 
- (modified) clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h (+1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+1-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst (+17) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-pointer-arithmetics-no-division.c
 (+12) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-pointer-arithmetics.c
 (+12-3) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index a30e63f9b0fd6a..4d09e8d0c59adb 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -70,7 +70,9 @@ SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
   Options.get("WarnOnSizeOfCompareToConstant", true)),
   WarnOnSizeOfPointerToAggregate(
   Options.get("WarnOnSizeOfPointerToAggregate", true)),
-  WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)) {}
+  WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)),
+  WarnOnSizeOfPointerArithmeticWithDivisionScaled(Options.get(
+  "WarnOnSizeOfPointerArithmeticWithDivisionScaled", true)) {}
 
 void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfConstant", WarnOnSizeOfConstant);
@@ -82,6 +84,8 @@ void 
SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfPointerToAggregate",
 WarnOnSizeOfPointerToAggregate);
   Options.store(Opts, "WarnOnSizeOfPointer", WarnOnSizeOfPointer);
+  Options.store(Opts, "WarnOnSizeOfPointerArithmeticWithDivisionScaled",
+WarnOnSizeOfPointerArithmeticWithDivisionScaled);
 }
 
 void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
@@ -306,8 +310,13 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder 
*Finder) {
  unaryExprOrTypeTraitExpr(ofKind(UETT_AlignOf)),
  offsetOfExpr()))
   .bind("sizeof-in-ptr-arithmetic-scale-expr");
+  const auto PtrArithmeticIntegerScaleExprInterestingOperatorNames = [this] {
+if (WarnOnSizeOfPointerArithmeticWithDivisionScaled)
+  return binaryOperator(hasAnyOperatorName("*", "/"));
+return binaryOperator(hasOperatorName("*"));
+  };
   const auto PtrArithmeticIntegerScaleExpr = binaryOperator(
-  hasAnyOperatorName("*", "/"),
+  PtrArithmeticIntegerScaleExprInterestingOperatorNames(),
   // sizeof(...) * sizeof(...) and sizeof(...) / sizeof(...) is handled
   // by this check on another path.
   hasOperands(expr(hasType(isInteger()), unless(SizeofLikeScaleExpr)),
diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
index 66d7c34cc9e940..45a371a26f6eec 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
@@ -31,6 +31,7 @@ class SizeofExpressionCheck : public ClangTidyCheck {
   const bool WarnOnSizeOfCompareToConstant;
   const bool WarnOnSizeOfPointerToAggregate;
   const bool WarnOnSizeOfPointer;
+  const bool WarnOnSizeOfPointerArithmeticWithDivisionScaled;
 };
 
 } // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b4792d749a86c3..57b0d2ab243487 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -144,7 +144,7 @@ Changes in existing checks
 - Improved :do

[clang-tools-extra] [clang-tidy] Make `P +- BS / sizeof(*P)` opt-outable in `bugprone-sizeof-expression` (PR #111178)

2024-10-04 Thread via cfe-commits

https://github.com/whisperity created 
https://github.com/llvm/llvm-project/pull/78

In some cases and for projects that deal with a lot of low-level buffers, a 
pattern often emerges that an array and its full size, not in the number of 
**elements** but in **bytes**, are known with no syntax-level connection 
between the two values. In order to access the array elements, the pointer 
arithmetic involved will have to divide `SizeInBytes` (a numeric value) with 
`sizeof(*Buffer)`. Since #106061, and as reported in #110551, this triggered a 
warning from `bugprone-sizeof-expression`, as `sizeof` appeared in pointer 
arithmetic where integers are scaled.

This patch adds a new check option, 
`WarnOnSizeOfPointerArithmeticWithDivisionScaled`, which allows users to 
opt-out of warning about the **division** case. In arbitrary projects, it might 
still be worthwhile to get these warnings until an opt-**out** in order to 
detect scaling issues, especially if a project might not be using low-level 
buffers intensively.

Fixes #110551.

>From 4415aaf903635d11cce7afc232e1768ad32e8592 Mon Sep 17 00:00:00 2001
From: Whisperity 
Date: Fri, 4 Oct 2024 17:30:41 +0200
Subject: [PATCH] feat(clang-tidy): Make `P + BS / sizeof(*P)` opt-outable

---
 .../bugprone/SizeofExpressionCheck.cpp  | 13 +++--
 .../clang-tidy/bugprone/SizeofExpressionCheck.h |  1 +
 clang-tools-extra/docs/ReleaseNotes.rst |  2 +-
 .../checks/bugprone/sizeof-expression.rst   | 17 +
 ...expression-pointer-arithmetics-no-division.c | 12 
 .../sizeof-expression-pointer-arithmetics.c | 15 ---
 6 files changed, 54 insertions(+), 6 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-pointer-arithmetics-no-division.c

diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index a30e63f9b0fd6a..4d09e8d0c59adb 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -70,7 +70,9 @@ SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
   Options.get("WarnOnSizeOfCompareToConstant", true)),
   WarnOnSizeOfPointerToAggregate(
   Options.get("WarnOnSizeOfPointerToAggregate", true)),
-  WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)) {}
+  WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)),
+  WarnOnSizeOfPointerArithmeticWithDivisionScaled(Options.get(
+  "WarnOnSizeOfPointerArithmeticWithDivisionScaled", true)) {}
 
 void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfConstant", WarnOnSizeOfConstant);
@@ -82,6 +84,8 @@ void 
SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfPointerToAggregate",
 WarnOnSizeOfPointerToAggregate);
   Options.store(Opts, "WarnOnSizeOfPointer", WarnOnSizeOfPointer);
+  Options.store(Opts, "WarnOnSizeOfPointerArithmeticWithDivisionScaled",
+WarnOnSizeOfPointerArithmeticWithDivisionScaled);
 }
 
 void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
@@ -306,8 +310,13 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder 
*Finder) {
  unaryExprOrTypeTraitExpr(ofKind(UETT_AlignOf)),
  offsetOfExpr()))
   .bind("sizeof-in-ptr-arithmetic-scale-expr");
+  const auto PtrArithmeticIntegerScaleExprInterestingOperatorNames = [this] {
+if (WarnOnSizeOfPointerArithmeticWithDivisionScaled)
+  return binaryOperator(hasAnyOperatorName("*", "/"));
+return binaryOperator(hasOperatorName("*"));
+  };
   const auto PtrArithmeticIntegerScaleExpr = binaryOperator(
-  hasAnyOperatorName("*", "/"),
+  PtrArithmeticIntegerScaleExprInterestingOperatorNames(),
   // sizeof(...) * sizeof(...) and sizeof(...) / sizeof(...) is handled
   // by this check on another path.
   hasOperands(expr(hasType(isInteger()), unless(SizeofLikeScaleExpr)),
diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
index 66d7c34cc9e940..45a371a26f6eec 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
@@ -31,6 +31,7 @@ class SizeofExpressionCheck : public ClangTidyCheck {
   const bool WarnOnSizeOfCompareToConstant;
   const bool WarnOnSizeOfPointerToAggregate;
   const bool WarnOnSizeOfPointer;
+  const bool WarnOnSizeOfPointerArithmeticWithDivisionScaled;
 };
 
 } // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b4792d749a86c3..57b0d2ab243487 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clan

[clang-tools-extra] [clang-tidy] Make `P +- BS / sizeof(*P)` opt-outable in `bugprone-sizeof-expression` (PR #111178)

2024-10-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: None (whisperity)


Changes

In some cases and for projects that deal with a lot of low-level buffers, a 
pattern often emerges that an array and its full size, not in the number of 
**elements** but in **bytes**, are known with no syntax-level connection 
between the two values. In order to access the array elements, the pointer 
arithmetic involved will have to divide `SizeInBytes` (a numeric value) with 
`sizeof(*Buffer)`. Since #106061, and as reported in #110551, 
this triggered a warning from `bugprone-sizeof-expression`, as `sizeof` 
appeared in pointer arithmetic where integers are scaled.

This patch adds a new check option, 
`WarnOnSizeOfPointerArithmeticWithDivisionScaled`, which allows users to 
opt-out of warning about the **division** case. In arbitrary projects, it might 
still be worthwhile to get these warnings until an opt-**out** in order to 
detect scaling issues, especially if a project might not be using low-level 
buffers intensively.

Fixes #110551.

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


6 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp 
(+11-2) 
- (modified) clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h (+1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+1-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst (+17) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-pointer-arithmetics-no-division.c
 (+12) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-pointer-arithmetics.c
 (+12-3) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index a30e63f9b0fd6a..4d09e8d0c59adb 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -70,7 +70,9 @@ SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
   Options.get("WarnOnSizeOfCompareToConstant", true)),
   WarnOnSizeOfPointerToAggregate(
   Options.get("WarnOnSizeOfPointerToAggregate", true)),
-  WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)) {}
+  WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)),
+  WarnOnSizeOfPointerArithmeticWithDivisionScaled(Options.get(
+  "WarnOnSizeOfPointerArithmeticWithDivisionScaled", true)) {}
 
 void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfConstant", WarnOnSizeOfConstant);
@@ -82,6 +84,8 @@ void 
SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfPointerToAggregate",
 WarnOnSizeOfPointerToAggregate);
   Options.store(Opts, "WarnOnSizeOfPointer", WarnOnSizeOfPointer);
+  Options.store(Opts, "WarnOnSizeOfPointerArithmeticWithDivisionScaled",
+WarnOnSizeOfPointerArithmeticWithDivisionScaled);
 }
 
 void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
@@ -306,8 +310,13 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder 
*Finder) {
  unaryExprOrTypeTraitExpr(ofKind(UETT_AlignOf)),
  offsetOfExpr()))
   .bind("sizeof-in-ptr-arithmetic-scale-expr");
+  const auto PtrArithmeticIntegerScaleExprInterestingOperatorNames = [this] {
+if (WarnOnSizeOfPointerArithmeticWithDivisionScaled)
+  return binaryOperator(hasAnyOperatorName("*", "/"));
+return binaryOperator(hasOperatorName("*"));
+  };
   const auto PtrArithmeticIntegerScaleExpr = binaryOperator(
-  hasAnyOperatorName("*", "/"),
+  PtrArithmeticIntegerScaleExprInterestingOperatorNames(),
   // sizeof(...) * sizeof(...) and sizeof(...) / sizeof(...) is handled
   // by this check on another path.
   hasOperands(expr(hasType(isInteger()), unless(SizeofLikeScaleExpr)),
diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
index 66d7c34cc9e940..45a371a26f6eec 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
@@ -31,6 +31,7 @@ class SizeofExpressionCheck : public ClangTidyCheck {
   const bool WarnOnSizeOfCompareToConstant;
   const bool WarnOnSizeOfPointerToAggregate;
   const bool WarnOnSizeOfPointer;
+  const bool WarnOnSizeOfPointerArithmeticWithDivisionScaled;
 };
 
 } // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b4792d749a86c3..57b0d2ab243487 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -144,7 +144,7 @@ Changes in existing checks
 - Improved :doc:`bugp

[clang] Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)" (PR #111173)

2024-10-04 Thread Erich Keane via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Make `P +- BS / sizeof(*P)` opt-outable in `bugprone-sizeof-expression` (PR #111178)

2024-10-04 Thread via cfe-commits

whisperity wrote:

**CC @douzzer**, who could not be added as a reviewer.

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


[clang] [Clang][Parser] Remove the concept from the DeclContext if the definition is invalid (PR #111179)

2024-10-04 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/79

Since #103867, the nullness of the concept declaration has been turned to 
represent a state in which the concept definition is being parsed and used for 
self-reference checking.

However, that PR missed a case where such a definition could be invalid and 
thus, the definition should not be found. Otherwise, the assumption in the 
evaluation would fail. This PR fixes it by removing the definition from the 
DeclContext in such situations.

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

>From fc3e60d2c1d038ae3f3ef2e4ec3e86605cfb0f69 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 4 Oct 2024 23:42:30 +0800
Subject: [PATCH] [Clang][Parser] Remove the concept from the DeclContext if
 the definition is invalid

---
 clang/include/clang/Sema/Sema.h  |  2 +-
 clang/lib/Parse/ParseTemplate.cpp| 10 +-
 clang/lib/Sema/SemaTemplate.cpp  |  6 --
 clang/test/SemaTemplate/concepts.cpp | 14 ++
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index bede971ce0191b..eea3cf4e43cde8 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11995,7 +11995,7 @@ class Sema final : public SemaBase {
 
   ConceptDecl *ActOnStartConceptDefinition(
   Scope *S, MultiTemplateParamsArg TemplateParameterLists,
-  const IdentifierInfo *Name, SourceLocation NameLoc);
+  const IdentifierInfo *Name, SourceLocation NameLoc, bool &AddedToScope);
 
   ConceptDecl *ActOnFinishConceptDefinition(Scope *S, ConceptDecl *C,
 Expr *ConstraintExpr,
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index de29652abbfd95..9ddabdf5172e41 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -322,13 +322,19 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
 
   // [C++26][basic.scope.pdecl]/p13
   // The locus of a concept-definition is immediately after its concept-name.
+  bool AddedToScope = false;
   ConceptDecl *D = Actions.ActOnStartConceptDefinition(
-  getCurScope(), *TemplateInfo.TemplateParams, Id, IdLoc);
+  getCurScope(), *TemplateInfo.TemplateParams, Id, IdLoc, AddedToScope);
 
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs);
 
   if (!TryConsumeToken(tok::equal)) {
+// The expression is unset until ActOnFinishConceptDefinition(), so remove
+// the invalid declaration from the future lookup such that the evaluation
+// wouldn't have to handle empty expressions.
+if (AddedToScope)
+  Actions.CurContext->removeDecl(D);
 Diag(Tok.getLocation(), diag::err_expected) << tok::equal;
 SkipUntil(tok::semi);
 return nullptr;
@@ -337,6 +343,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
   ExprResult ConstraintExprResult =
   Actions.CorrectDelayedTyposInExpr(ParseConstraintExpression());
   if (ConstraintExprResult.isInvalid()) {
+if (AddedToScope)
+  Actions.CurContext->removeDecl(D);
 SkipUntil(tok::semi);
 return nullptr;
   }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index eeaa1ebd7ba83a..2d8b47ea2474be 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8632,7 +8632,7 @@ Decl *Sema::ActOnTemplateDeclarator(Scope *S,
 
 ConceptDecl *Sema::ActOnStartConceptDefinition(
 Scope *S, MultiTemplateParamsArg TemplateParameterLists,
-const IdentifierInfo *Name, SourceLocation NameLoc) {
+const IdentifierInfo *Name, SourceLocation NameLoc, bool &AddedToScope) {
   DeclContext *DC = CurContext;
 
   if (!DC->getRedeclContext()->isFileContext()) {
@@ -8688,8 +8688,10 @@ ConceptDecl *Sema::ActOnStartConceptDefinition(
   // We cannot properly handle redeclarations until we parse the constraint
   // expression, so only inject the name if we are sure we are not redeclaring 
a
   // symbol
-  if (Previous.empty())
+  if (Previous.empty()) {
 PushOnScopeChains(NewDecl, S, true);
+AddedToScope = true;
+  }
 
   return NewDecl;
 }
diff --git a/clang/test/SemaTemplate/concepts.cpp 
b/clang/test/SemaTemplate/concepts.cpp
index a98ca3939222bd..9d29cc59d3ab96 100644
--- a/clang/test/SemaTemplate/concepts.cpp
+++ b/clang/test/SemaTemplate/concepts.cpp
@@ -1151,3 +1151,17 @@ int test() {
 }
 
 }
+
+namespace GH109780 {
+
+template 
+concept Concept; // expected-error {{expected '='}}
+
+bool val = Concept; // expected-error {{use of undeclared identifier 
'Concept'}}
+
+template 
+concept C = invalid; // expected-error {{use of undeclared identifier 
'invalid'}}
+
+bool val2 = C; // expected-error {{use of undeclared identifier 'C'}}
+
+} // namespace GH109780

___
cfe-commits mailing list
cfe-commits@lists.l

[clang] [Clang] [Sema] Don't crash on unexpanded pack in invalid block literal (PR #110762)

2024-10-04 Thread via cfe-commits

Sirraide wrote:

> I am not sure i understand that.
>
> Imo the issue is that `DiagnoseUnexpandedParameterPacks` (where we set 
> `LambdaScopeInfo::ContainsUnexpandedParameterPack` does not account for 
> blocks - and probably should.
> 
> Ideally
> 
> * DiagnoseUnexpandedParameterPacks would handle arbitrary capturing-scope 
> thingies (statement expressions, lambdas, blocks, eventually do expressions, 
> and other terrifying such constructs)
> * Once the innermost such construct is fully constructed, the 
> `ContainsUnexpandedParameterPack` flag could bubble upward to the enclosing 
> capturing scope

Yeah, that’s also what I figured initially. I just assumed that there was 
*some* reason why blocks don’t or can’t work that way (I have never used 
Objective-C and I candidly don’t know a lot about blocks...), but it seems that 
there isn’t.

So if you think that this is a better idea, I can instead look into refactoring 
blocks to work the same way as lambdas wrt `DiagnoseUnexpandedParameterPacks()` 
(and I think that mainly just means moving some things from `LambdaScopeInfo` 
to `CapturingScopeInfo` or whatever the base class was called again and making 
`DiagnoseUnexpandedParameterPacks()` etc. use that instead).

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


[clang] [Clang][Parser] Remove the concept from the DeclContext if the definition is invalid (PR #111179)

2024-10-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

Since #103867, the nullness of the concept declaration has been turned 
to represent a state in which the concept definition is being parsed and used 
for self-reference checking.

However, that PR missed a case where such a definition could be invalid and 
thus, the definition should not be found. Otherwise, the assumption in the 
evaluation would fail. This PR fixes it by removing the definition from the 
DeclContext in such situations.

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

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


4 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+1-1) 
- (modified) clang/lib/Parse/ParseTemplate.cpp (+9-1) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+4-2) 
- (modified) clang/test/SemaTemplate/concepts.cpp (+14) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index bede971ce0191b..eea3cf4e43cde8 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11995,7 +11995,7 @@ class Sema final : public SemaBase {
 
   ConceptDecl *ActOnStartConceptDefinition(
   Scope *S, MultiTemplateParamsArg TemplateParameterLists,
-  const IdentifierInfo *Name, SourceLocation NameLoc);
+  const IdentifierInfo *Name, SourceLocation NameLoc, bool &AddedToScope);
 
   ConceptDecl *ActOnFinishConceptDefinition(Scope *S, ConceptDecl *C,
 Expr *ConstraintExpr,
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index de29652abbfd95..9ddabdf5172e41 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -322,13 +322,19 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
 
   // [C++26][basic.scope.pdecl]/p13
   // The locus of a concept-definition is immediately after its concept-name.
+  bool AddedToScope = false;
   ConceptDecl *D = Actions.ActOnStartConceptDefinition(
-  getCurScope(), *TemplateInfo.TemplateParams, Id, IdLoc);
+  getCurScope(), *TemplateInfo.TemplateParams, Id, IdLoc, AddedToScope);
 
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs);
 
   if (!TryConsumeToken(tok::equal)) {
+// The expression is unset until ActOnFinishConceptDefinition(), so remove
+// the invalid declaration from the future lookup such that the evaluation
+// wouldn't have to handle empty expressions.
+if (AddedToScope)
+  Actions.CurContext->removeDecl(D);
 Diag(Tok.getLocation(), diag::err_expected) << tok::equal;
 SkipUntil(tok::semi);
 return nullptr;
@@ -337,6 +343,8 @@ Parser::ParseConceptDefinition(const ParsedTemplateInfo 
&TemplateInfo,
   ExprResult ConstraintExprResult =
   Actions.CorrectDelayedTyposInExpr(ParseConstraintExpression());
   if (ConstraintExprResult.isInvalid()) {
+if (AddedToScope)
+  Actions.CurContext->removeDecl(D);
 SkipUntil(tok::semi);
 return nullptr;
   }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index eeaa1ebd7ba83a..2d8b47ea2474be 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8632,7 +8632,7 @@ Decl *Sema::ActOnTemplateDeclarator(Scope *S,
 
 ConceptDecl *Sema::ActOnStartConceptDefinition(
 Scope *S, MultiTemplateParamsArg TemplateParameterLists,
-const IdentifierInfo *Name, SourceLocation NameLoc) {
+const IdentifierInfo *Name, SourceLocation NameLoc, bool &AddedToScope) {
   DeclContext *DC = CurContext;
 
   if (!DC->getRedeclContext()->isFileContext()) {
@@ -8688,8 +8688,10 @@ ConceptDecl *Sema::ActOnStartConceptDefinition(
   // We cannot properly handle redeclarations until we parse the constraint
   // expression, so only inject the name if we are sure we are not redeclaring 
a
   // symbol
-  if (Previous.empty())
+  if (Previous.empty()) {
 PushOnScopeChains(NewDecl, S, true);
+AddedToScope = true;
+  }
 
   return NewDecl;
 }
diff --git a/clang/test/SemaTemplate/concepts.cpp 
b/clang/test/SemaTemplate/concepts.cpp
index a98ca3939222bd..9d29cc59d3ab96 100644
--- a/clang/test/SemaTemplate/concepts.cpp
+++ b/clang/test/SemaTemplate/concepts.cpp
@@ -1151,3 +1151,17 @@ int test() {
 }
 
 }
+
+namespace GH109780 {
+
+template 
+concept Concept; // expected-error {{expected '='}}
+
+bool val = Concept; // expected-error {{use of undeclared identifier 
'Concept'}}
+
+template 
+concept C = invalid; // expected-error {{use of undeclared identifier 
'invalid'}}
+
+bool val2 = C; // expected-error {{use of undeclared identifier 'C'}}
+
+} // namespace GH109780

``




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


[clang] 6a8fcb0 - [TableGen] Avoid repeated hash lookups (NFC) (#111089)

2024-10-04 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-10-04T07:37:31-07:00
New Revision: 6a8fcb0fa899af0b65caa3605fbed359189bed2f

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

LOG: [TableGen] Avoid repeated hash lookups (NFC) (#111089)

Added: 


Modified: 
clang/utils/TableGen/MveEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/MveEmitter.cpp 
b/clang/utils/TableGen/MveEmitter.cpp
index 57e6353e60a141..915e914d6b9287 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -994,9 +994,10 @@ class EmitterBase {
   const VectorType *getVectorType(const ScalarType *ST, unsigned Lanes) {
 std::tuple key(ST->kind(),
ST->sizeInBits(), 
Lanes);
-if (VectorTypes.find(key) == VectorTypes.end())
-  VectorTypes[key] = std::make_unique(ST, Lanes);
-return VectorTypes[key].get();
+auto [It, Inserted] = VectorTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(ST, Lanes);
+return It->second.get();
   }
   const VectorType *getVectorType(const ScalarType *ST) {
 return getVectorType(ST, 128 / ST->sizeInBits());
@@ -1004,22 +1005,25 @@ class EmitterBase {
   const MultiVectorType *getMultiVectorType(unsigned Registers,
 const VectorType *VT) {
 std::pair key(VT->cNameBase(), Registers);
-if (MultiVectorTypes.find(key) == MultiVectorTypes.end())
-  MultiVectorTypes[key] = std::make_unique(Registers, VT);
-return MultiVectorTypes[key].get();
+auto [It, Inserted] = MultiVectorTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(Registers, VT);
+return It->second.get();
   }
   const PredicateType *getPredicateType(unsigned Lanes) {
 unsigned key = Lanes;
-if (PredicateTypes.find(key) == PredicateTypes.end())
-  PredicateTypes[key] = std::make_unique(Lanes);
-return PredicateTypes[key].get();
+auto [It, Inserted] = PredicateTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(Lanes);
+return It->second.get();
   }
   const PointerType *getPointerType(const Type *T, bool Const) {
 PointerType PT(T, Const);
 std::string key = PT.cName();
-if (PointerTypes.find(key) == PointerTypes.end())
-  PointerTypes[key] = std::make_unique(PT);
-return PointerTypes[key].get();
+auto [It, Inserted] = PointerTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(PT);
+return It->second.get();
   }
 
   // Methods to construct a type from various pieces of Tablegen. These are



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


[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #111090)

2024-10-04 Thread Kazu Hirata via cfe-commits

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


[clang] [TableGen] Avoid repeated hash lookups (NFC) (PR #111089)

2024-10-04 Thread Kazu Hirata via cfe-commits

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


[clang] c7895f0 - [DependencyScanning] Avoid repeated hash lookups (NFC) (#111088)

2024-10-04 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-10-04T07:37:54-07:00
New Revision: c7895f0d72ef3797fff6f687fd696e9a70911703

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

LOG: [DependencyScanning] Avoid repeated hash lookups (NFC) (#111088)

Added: 


Modified: 
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Removed: 




diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 677f426590ab9e..77f9d07175c2c1 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -549,7 +549,7 @@ void ModuleDepCollectorPP::EndOfMainFile() {
 auto It = MDC.ModularDeps.find(M);
 // Only report direct dependencies that were successfully handled.
 if (It != MDC.ModularDeps.end())
-  MDC.Consumer.handleDirectModuleDependency(MDC.ModularDeps[M]->ID);
+  MDC.Consumer.handleDirectModuleDependency(It->second->ID);
   }
 
   for (auto &&I : MDC.FileDeps)



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


[clang] [DependencyScanning] Avoid repeated hash lookups (NFC) (PR #111088)

2024-10-04 Thread Kazu Hirata via cfe-commits

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


[clang] [flang] [llvm] [openmp] [flang][driver] rename flang-new to flang (PR #110023)

2024-10-04 Thread Andrzej Warzyński via cfe-commits


@@ -339,11 +335,11 @@ just added using your new frontend option.
 
 ## CMake Support
 As of [#7246](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7246)
-(and soon to be released CMake 3.24.0), `cmake` can detect `flang-new` as a
+(CMake 3.28.0), `cmake` can detect `flang` as a

banach-space wrote:

https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7246 pre-dates CMake 
3.28.0 by quite a few releases, I would just remove the link.

@DavidTruby what makes 3.28 special? Should 3.28 be marked as requirement?

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


[clang] Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585)" (PR #111173)

2024-10-04 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

@zyn0217 I have quite a few test cases I'll be adding soon

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


[clang] [llvm] [IR] Allow fast math flags on calls with homogeneous FP struct types (PR #110506)

2024-10-04 Thread Benjamin Maxwell via cfe-commits

MacDue wrote:

It looks like this crash is not unique to struct types, I can reproduce it with 
array types too (which have been allowed for some time).

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


[clang] [analyzer] use `invalidateRegions()` in `VisitGCCAsmStmt` (PR #109838)

2024-10-04 Thread Pavel Skripkin via cfe-commits


@@ -40,7 +42,19 @@ void testInlineAsmMemcpyUninit(void)
 {
 int a[10], b[10] = {}, c;
 MyMemcpy(&a[1], &b[1], sizeof(b) - sizeof(b[1]));
-c = a[0]; // expected-warning{{Assigned value is garbage or undefined}}
+c = a[0]; // FIXME: should be warning about uninitialized value, but 
invalidateRegions() also
+  // invalidates super region.
+}
+
+void testInlineAsmMemcpyUninitLoop(const void *src, unsigned long len)
+{
+int a[10], c;
+unsigned long toCopy = sizeof(a) < len ? sizeof(a) : len;
+
+MyMemcpy(a, src, toCopy);
+
+for (unsigned long i = 0; i < toCopy; ++i)
+  c = a[i]; // no-warning

pskrgag wrote:

Rewrote test in linear manner. It's just possible to directly access 1st 
element to test warning

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


[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic for spirv backend (PR #111010)

2024-10-04 Thread Nathan Gauër via cfe-commits


@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple   \
+// RUN:   dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o 
- | \
+// RUN:   FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple   \
+// RUN:   spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \
+// RUN:   FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
+
+// Test basic lowering to runtime function call.
+
+// CHECK-LABEL: test_int
+int test_int(int expr, uint idx) {
+  // CHECK-SPIRV: %[[#entry_tok:]] = call token 
@llvm.experimental.convergence.entry()
+
+  // CHECK-SPIRV:  %[[RET:.*]] = call [[TY:.*]] 
@llvm.spv.wave.read.lane.at.i32([[TY]] %[[#]], i32 %[[#]])

Keenuts wrote:

Not sure if that's done on other wave intrinsics, but we might want to check 
that the `convergencectrl` attribute is attached to it.

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


[clang] [clang] Catch missing format attributes (PR #105479)

2024-10-04 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovichtec updated 
https://github.com/llvm/llvm-project/pull/105479

From 41c8d09b23b2328e727df83f022aaeb21b5e539e Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Attr.h   |   7 +
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/Sema/SemaDecl.cpp   |   2 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 219 +-
 clang/test/Sema/attr-format-missing.c | 217 +
 clang/test/Sema/attr-format-missing.cpp   | 180 ++
 9 files changed, 631 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 44d5f348ed2d54..0a663eb97c7770 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -378,6 +378,9 @@ Improvements to Clang's diagnostics
 
 - Clang now emits a diagnostic note at the class declaration when the method 
definition does not match any declaration (#GH110638).
 
+- Clang now diagnoses missing format attributes for non-template functions and
+  class/struct/union members. Fixes #GH60718
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 41e719d4d57816..850823ee7c48e3 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -529,7 +529,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 59dc81cfeb7111..f165cb6d8dc207 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1046,6 +1046,9 @@ def err_opencl_invalid_param : Error<
   "declaring function parameter of type %0 is not allowed%select{; did you 
forget * ?|}1">;
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h
index 3f0b10212789a4..37c124ca7b454a 100644
--- a/clang/include/clang/Sema/Attr.h
+++ b/clang/include/clang/Sema/Attr.h
@@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 /// Diagnose mutually exclusive attributes when present on a given
 /// declaration. Returns true if diagnosed.
 template 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index bede971ce0191b..7129fa8c8f1359 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4574,6 +4574,8 @@ class Sema final : public SemaBase {
 
   enum class RetainOwnershipKind { NS, CF, OS };
 
+  void DiagnoseMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2bf610746bc317..0ec29cfeb728bf 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16020,6 +16020,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 }
   }
 
+  DiagnoseMissingFormatAttributes(Body, FD);
+
   // We might not have found a prototype because we didn't wish to warn on
   // the lack of a missing prototype. Try again without the checks for
   // whether we want to warn on the missing prototype.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index c9b9f3a0007daa..6989c

[clang] [Clang] Implement CWG 2628 "Implicit deduction guides should propagate constraints" (PR #111143)

2024-10-04 Thread via cfe-commits


@@ -446,10 +450,46 @@ struct ConvertConstructorToDeductionGuideTransform {
   return nullptr;
 TypeSourceInfo *NewTInfo = TLB.getTypeSourceInfo(SemaRef.Context, NewType);
 
+// At this point, the function parameters are already 'instantiated' in the
+// current scope. Substitute into the constructor's trailing
+// requires-clause, if any.
+Expr *FunctionTrailingRC = nullptr;
+if (Expr *RC = CD->getTrailingRequiresClause()) {
+  MultiLevelTemplateArgumentList Args;
+  Args.setKind(TemplateSubstitutionKind::Rewrite);
+  Args.addOuterTemplateArguments(Depth1Args);
+  Args.addOuterRetainedLevel();
+  if (NestedPattern)
+Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
+  ExprResult E = SemaRef.SubstConstraintExprWithoutSatisfaction(RC, Args);
+  if (!E.isUsable())
+return nullptr;
+  FunctionTrailingRC = E.get();
+}
+
+// C++ [over.match.class.deduct]p1:
+// If C is defined, for each constructor of C, a function template with
+// the following properties:
+// [...]
+// - The associated constraints are the conjunction of the associated
+// constraints of C and the associated constraints of the constructor, if
+// any.
+if (OuterRC) {
+  // The outer template parameters are not transformed, so their
+  // associated constraints don't need substitution.
+  if (!FunctionTrailingRC)
+FunctionTrailingRC = OuterRC;
+  else
+FunctionTrailingRC = BinaryOperator::Create(

cor3ntin wrote:

I think this would make everything way too complicated when checking 
subsumption etc (and afaik we do that in a few other places)

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


[clang] [analyzer] Model overflow builtins (PR #102602)

2024-10-04 Thread Balazs Benics via cfe-commits

steakhal wrote:

FYI this PR likely caused a crash, reported in #47.

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


[clang] [Clang] Implement CWG 2628 "Implicit deduction guides should propagate constraints" (PR #111143)

2024-10-04 Thread Younan Zhang via cfe-commits


@@ -446,10 +450,46 @@ struct ConvertConstructorToDeductionGuideTransform {
   return nullptr;
 TypeSourceInfo *NewTInfo = TLB.getTypeSourceInfo(SemaRef.Context, NewType);
 
+// At this point, the function parameters are already 'instantiated' in the
+// current scope. Substitute into the constructor's trailing
+// requires-clause, if any.
+Expr *FunctionTrailingRC = nullptr;
+if (Expr *RC = CD->getTrailingRequiresClause()) {
+  MultiLevelTemplateArgumentList Args;
+  Args.setKind(TemplateSubstitutionKind::Rewrite);
+  Args.addOuterTemplateArguments(Depth1Args);
+  Args.addOuterRetainedLevel();
+  if (NestedPattern)
+Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
+  ExprResult E = SemaRef.SubstConstraintExprWithoutSatisfaction(RC, Args);
+  if (!E.isUsable())
+return nullptr;
+  FunctionTrailingRC = E.get();
+}
+
+// C++ [over.match.class.deduct]p1:
+// If C is defined, for each constructor of C, a function template with
+// the following properties:
+// [...]
+// - The associated constraints are the conjunction of the associated
+// constraints of C and the associated constraints of the constructor, if
+// any.
+if (OuterRC) {
+  // The outer template parameters are not transformed, so their
+  // associated constraints don't need substitution.
+  if (!FunctionTrailingRC)
+FunctionTrailingRC = OuterRC;
+  else
+FunctionTrailingRC = BinaryOperator::Create(

zyn0217 wrote:

Hmm, yeah, source fidelity.

But what’s also noteworthy is that we have already checked the class template’s 
constraints prior to checking the CTAD, which is required by the standard.

The binary operator actually changes the constraint-ness in the overload 
resolution against the explicit deduction guides. Though this might not be the 
intention of the DR, see my comments on the test.

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


[clang] d205191 - [MSVC] work-around for compile time issue 102513 (#110986)

2024-10-04 Thread via cfe-commits

Author: bd1976bris
Date: 2024-10-04T14:59:41+01:00
New Revision: d2051919bb42087ebde2a8bdcd5b2676ad16d8eb

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

LOG: [MSVC] work-around for compile time issue 102513 (#110986)

Disable optimizations when building clang/lib/AST/ByteCode/Interp.cpp
with Microsoft's compiler as it has a bug that causes excessive build
times. We do this only when NDEBUG is not defined on the assumption that
building without asserts indicates that a user is strongly invested in
runtime performance.

Partially addresses: https://github.com/llvm/llvm-project/issues/102513.

Once the bug is addressed in the Microsoft compiler this can be removed.

Co-authored-by: dyung

Added: 


Modified: 
clang/lib/AST/ByteCode/Interp.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index fd9a256843a0ec..b3ba81f04ff1ff 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1406,6 +1406,10 @@ bool handleFixedPointOverflow(InterpState &S, CodePtr 
OpPC,
   return S.noteUndefinedBehavior();
 }
 
+// https://github.com/llvm/llvm-project/issues/102513
+#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
+#pragma optimize("", off)
+#endif
 bool Interpret(InterpState &S, APValue &Result) {
   // The current stack frame when we started Interpret().
   // This is being used by the ops to determine wheter
@@ -1430,6 +1434,10 @@ bool Interpret(InterpState &S, APValue &Result) {
 }
   }
 }
+// https://github.com/llvm/llvm-project/issues/102513
+#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
+#pragma optimize("", on)
+#endif
 
 } // namespace interp
 } // namespace clang



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


[clang] [MSVC] work-around for compile time issue 102513 (PR #110986)

2024-10-04 Thread via cfe-commits

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


[clang] [RFC][C++20][Modules] Relax ODR check in unnamed modules (PR #111160)

2024-10-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Dmitry Polukhin (dmpolukhin)


Changes

Summary:
Option `-fskip-odr-check-in-gmf` is set by default and I think it is what most 
of C++ developers want. But in header units, Clang ODR checking is too strict, 
making them hard to use, as seen in the example in the diff. This diff relaxes 
ODR checks for unnamed modules to match GMF ODR checking.

Alternative solution is to add special handling for CXXFoldExpr to ignore 
differences in `callee`. In particular, it will treat the following fragments 
as identical. I think it might be reasonable default behavior instead of 
`-fskip-odr-check-in-gmf` for header units and GMF. It might be reasonable 
compromise for checking some ODRs but allow most common issues.
```
CXXFoldExpr 0x6588b1b8 ''
|-<<>>
|-UnresolvedLookupExpr 0x6588b140 '' lvalue (no ADL) 
= '__cmp_cat_id' 0x6588ac18
| `-TemplateArgument type '_Ts'
|   `-TemplateTypeParmType 0x6588adf0 '_Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
| `-TemplateTypeParm 0x6588ad70 '_Ts'
`-<<>>

CXXFoldExpr 0x6588b670 ''
|-UnresolvedLookupExpr 0x6588b628 '' lvalue 
(ADL) = 'operator|' 0x6588ae60
|-UnresolvedLookupExpr 0x6588b5b0 '' lvalue (no ADL) 
= '__cmp_cat_id' 0x6588b0d8
| `-TemplateArgument type '_Ts'
|   `-TemplateTypeParmType 0x6588b260 '_Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
| `-TemplateTypeParm 0x6588b1e0 '_Ts'
`-<<>>
```

Test Plan: check-clang

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


2 Files Affected:

- (modified) clang/include/clang/Serialization/ASTReader.h (+1-1) 
- (added) clang/test/Headers/header-unit-common-cmp-cat.cpp (+32) 


``diff
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index aa88560b259a3b..109c905d2bebb6 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -2527,7 +2527,7 @@ class BitsUnpacker {
 
 inline bool shouldSkipCheckingODR(const Decl *D) {
   return D->getASTContext().getLangOpts().SkipODRCheckInGMF &&
- D->isFromGlobalModule();
+ (D->isFromGlobalModule() || !D->isInNamedModule());
 }
 
 } // namespace clang
diff --git a/clang/test/Headers/header-unit-common-cmp-cat.cpp 
b/clang/test/Headers/header-unit-common-cmp-cat.cpp
new file mode 100644
index 00..b9d00ba042fda5
--- /dev/null
+++ b/clang/test/Headers/header-unit-common-cmp-cat.cpp
@@ -0,0 +1,32 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf 
-emit-header-unit -xc++-user-header bz0.h
+// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf 
-emit-header-unit -xc++-user-header bz1.h
+// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf 
-emit-header-unit -xc++-user-header -fmodule-file=bz0.pcm -fmodule-file=bz1.pcm 
bz.cpp
+
+//--- compare
+template
+inline constexpr unsigned __cmp_cat_id = 1;
+
+template
+constexpr auto __common_cmp_cat() {
+  (__cmp_cat_id<_Ts> | ...);
+}
+
+//--- bz0.h
+template 
+int operator|(T, T);
+
+#include "compare"
+// expected-no-diagnostics
+
+//--- bz1.h
+#include "compare"
+// expected-no-diagnostics
+
+//--- bz.cpp
+#include "compare"
+
+import "bz0.h"; // expected-warning {{the implementation of header units is in 
an experimental phase}}
+import "bz1.h"; // expected-warning {{the implementation of header units is in 
an experimental phase}}

``




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


[clang] [RFC][C++20][Modules] Relax ODR check in unnamed modules (PR #111160)

2024-10-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Dmitry Polukhin (dmpolukhin)


Changes

Summary:
Option `-fskip-odr-check-in-gmf` is set by default and I think it is what most 
of C++ developers want. But in header units, Clang ODR checking is too strict, 
making them hard to use, as seen in the example in the diff. This diff relaxes 
ODR checks for unnamed modules to match GMF ODR checking.

Alternative solution is to add special handling for CXXFoldExpr to ignore 
differences in `callee`. In particular, it will treat the following fragments 
as identical. I think it might be reasonable default behavior instead of 
`-fskip-odr-check-in-gmf` for header units and GMF. It might be reasonable 
compromise for checking some ODRs but allow most common issues.
```
CXXFoldExpr 0x6588b1b8 ''
|-<<>>
|-UnresolvedLookupExpr 0x6588b140 '' lvalue (no ADL) 
= '__cmp_cat_id' 0x6588ac18
| `-TemplateArgument type '_Ts'
|   `-TemplateTypeParmType 0x6588adf0 '_Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
| `-TemplateTypeParm 0x6588ad70 '_Ts'
`-<<>>

CXXFoldExpr 0x6588b670 ''
|-UnresolvedLookupExpr 0x6588b628 '' lvalue 
(ADL) = 'operator|' 0x6588ae60
|-UnresolvedLookupExpr 0x6588b5b0 '' lvalue (no ADL) 
= '__cmp_cat_id' 0x6588b0d8
| `-TemplateArgument type '_Ts'
|   `-TemplateTypeParmType 0x6588b260 '_Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
| `-TemplateTypeParm 0x6588b1e0 '_Ts'
`-<<>>
```

Test Plan: check-clang

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


2 Files Affected:

- (modified) clang/include/clang/Serialization/ASTReader.h (+1-1) 
- (added) clang/test/Headers/header-unit-common-cmp-cat.cpp (+32) 


``diff
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index aa88560b259a3b..109c905d2bebb6 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -2527,7 +2527,7 @@ class BitsUnpacker {
 
 inline bool shouldSkipCheckingODR(const Decl *D) {
   return D->getASTContext().getLangOpts().SkipODRCheckInGMF &&
- D->isFromGlobalModule();
+ (D->isFromGlobalModule() || !D->isInNamedModule());
 }
 
 } // namespace clang
diff --git a/clang/test/Headers/header-unit-common-cmp-cat.cpp 
b/clang/test/Headers/header-unit-common-cmp-cat.cpp
new file mode 100644
index 00..b9d00ba042fda5
--- /dev/null
+++ b/clang/test/Headers/header-unit-common-cmp-cat.cpp
@@ -0,0 +1,32 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf 
-emit-header-unit -xc++-user-header bz0.h
+// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf 
-emit-header-unit -xc++-user-header bz1.h
+// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf 
-emit-header-unit -xc++-user-header -fmodule-file=bz0.pcm -fmodule-file=bz1.pcm 
bz.cpp
+
+//--- compare
+template
+inline constexpr unsigned __cmp_cat_id = 1;
+
+template
+constexpr auto __common_cmp_cat() {
+  (__cmp_cat_id<_Ts> | ...);
+}
+
+//--- bz0.h
+template 
+int operator|(T, T);
+
+#include "compare"
+// expected-no-diagnostics
+
+//--- bz1.h
+#include "compare"
+// expected-no-diagnostics
+
+//--- bz.cpp
+#include "compare"
+
+import "bz0.h"; // expected-warning {{the implementation of header units is in 
an experimental phase}}
+import "bz1.h"; // expected-warning {{the implementation of header units is in 
an experimental phase}}

``




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


[clang] [RFC][C++20][Modules] Relax ODR check in unnamed modules (PR #111160)

2024-10-04 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin created 
https://github.com/llvm/llvm-project/pull/60

Summary:
Option `-fskip-odr-check-in-gmf` is set by default and I think it is what most 
of C++ developers want. But in header units, Clang ODR checking is too strict, 
making them hard to use, as seen in the example in the diff. This diff relaxes 
ODR checks for unnamed modules to match GMF ODR checking.

Alternative solution is to add special handling for CXXFoldExpr to ignore 
differences in `callee`. In particular, it will treat the following fragments 
as identical. I think it might be reasonable default behavior instead of 
`-fskip-odr-check-in-gmf` for header units and GMF. It might be reasonable 
compromise for checking some ODRs but allow most common issues.
```
CXXFoldExpr 0x6588b1b8 ''
|-<<>>
|-UnresolvedLookupExpr 0x6588b140 '' lvalue (no ADL) = 
'__cmp_cat_id' 0x6588ac18
| `-TemplateArgument type '_Ts'
|   `-TemplateTypeParmType 0x6588adf0 '_Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
| `-TemplateTypeParm 0x6588ad70 '_Ts'
`-<<>>

CXXFoldExpr 0x6588b670 ''
|-UnresolvedLookupExpr 0x6588b628 '' lvalue (ADL) 
= 'operator|' 0x6588ae60
|-UnresolvedLookupExpr 0x6588b5b0 '' lvalue (no ADL) = 
'__cmp_cat_id' 0x6588b0d8
| `-TemplateArgument type '_Ts'
|   `-TemplateTypeParmType 0x6588b260 '_Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
| `-TemplateTypeParm 0x6588b1e0 '_Ts'
`-<<>>
```

Test Plan: check-clang

>From dc4a79c2ee5630eb551ea3a40b4bd67da20c7034 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 4 Oct 2024 06:41:34 -0700
Subject: [PATCH] [RFC][C++20][Modules] Relax ODR check in unnamed modules
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Summary:
Option `-fskip-odr-check-in-gmf` is set by default and I think it is what most 
of C++ developers want. But in header units clang ODR checking is too strict 
that makes them hard to use, see example in the diff. This diff relaxes ODR 
checks for unnamed modules to match GMF ODR checking.

Alternative solution is to add special handling for CXXFoldExpr to ignore 
differences in “callee”. In particular it will treat the following fragments 
identical. I think it might be reasonable default behavior instead of 
`-fskip-odr-check-in-gmf`.
```
CXXFoldExpr 0x6588b1b8 ''
|-<<>>
|-UnresolvedLookupExpr 0x6588b140 '' lvalue (no ADL) = 
'__cmp_cat_id' 0x6588ac18
| `-TemplateArgument type '_Ts'
|   `-TemplateTypeParmType 0x6588adf0 '_Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
| `-TemplateTypeParm 0x6588ad70 '_Ts'
`-<<>>

CXXFoldExpr 0x6588b670 ''
|-UnresolvedLookupExpr 0x6588b628 '' lvalue (ADL) 
= 'operator|' 0x6588ae60
|-UnresolvedLookupExpr 0x6588b5b0 '' lvalue (no ADL) = 
'__cmp_cat_id' 0x6588b0d8
| `-TemplateArgument type '_Ts'
|   `-TemplateTypeParmType 0x6588b260 '_Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
| `-TemplateTypeParm 0x6588b1e0 '_Ts'
`-<<>>
```

Test Plan: check-clang
---
 clang/include/clang/Serialization/ASTReader.h |  2 +-
 .../Headers/header-unit-common-cmp-cat.cpp| 32 +++
 2 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Headers/header-unit-common-cmp-cat.cpp

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index aa88560b259a3b..109c905d2bebb6 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -2527,7 +2527,7 @@ class BitsUnpacker {
 
 inline bool shouldSkipCheckingODR(const Decl *D) {
   return D->getASTContext().getLangOpts().SkipODRCheckInGMF &&
- D->isFromGlobalModule();
+ (D->isFromGlobalModule() || !D->isInNamedModule());
 }
 
 } // namespace clang
diff --git a/clang/test/Headers/header-unit-common-cmp-cat.cpp 
b/clang/test/Headers/header-unit-common-cmp-cat.cpp
new file mode 100644
index 00..b9d00ba042fda5
--- /dev/null
+++ b/clang/test/Headers/header-unit-common-cmp-cat.cpp
@@ -0,0 +1,32 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf 
-emit-header-unit -xc++-user-header bz0.h
+// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf 
-emit-header-unit -xc++-user-header bz1.h
+// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf 
-emit-header-unit -xc++-user-header -fmodule-file=bz0.pcm -fmodule-file=bz1.pcm 
bz.cpp
+
+//--- compare
+template
+inline constexpr unsigned __cmp_cat_id = 1;
+
+template
+constexpr auto __common_cmp_cat() {
+  (__cmp_cat_id<_Ts> | ...);
+}
+
+//--- bz0.h
+template 
+int operator|(T, T);
+
+#include "compare"
+// expected-no-diagnostics
+
+//--- bz1.h
+#include "compare"
+// expected-no-diagnostics
+
+//--- bz.cpp
+#include "compare"
+
+import "bz0.h"; // expected-warning {{the implementation of heade

[clang] [clang][bytecode] Change isArrayElement() for narrowed composite arrays (PR #111110)

2024-10-04 Thread Timm Baeder via cfe-commits

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

Make isArrayElement() return true here, so we can know that such a pointer is 
in fact an array element and handle it properly in toAPValue().

>From d9ca4e19a4f5f9f17f941661782f20055ba1c6fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 4 Oct 2024 08:37:16 +0200
Subject: [PATCH] [clang][bytecode] Change isArrayElement() for narrowed
 composite arrays

Make isArrayElement() return true here, so we can know that such a
pointer is in fact an array element and handle it properly in
toAPValue().
---
 clang/lib/AST/ByteCode/Descriptor.cpp |  3 +++
 clang/lib/AST/ByteCode/Descriptor.h   |  4 +++-
 clang/lib/AST/ByteCode/Pointer.cpp|  8 ++--
 clang/lib/AST/ByteCode/Pointer.h  | 14 --
 clang/test/CodeGen/2008-08-07-AlignPadding1.c |  1 +
 clang/unittests/AST/ByteCode/Descriptor.cpp   |  8 
 6 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp 
b/clang/lib/AST/ByteCode/Descriptor.cpp
index 65ac7a3129abaf..5a8a2b64d5582d 100644
--- a/clang/lib/AST/ByteCode/Descriptor.cpp
+++ b/clang/lib/AST/ByteCode/Descriptor.cpp
@@ -103,6 +103,7 @@ static void ctorArrayDesc(Block *B, std::byte *Ptr, bool 
IsConst,
 Desc->IsConst = IsConst || D->IsConst;
 Desc->IsFieldMutable = IsMutable || D->IsMutable;
 Desc->InUnion = InUnion;
+Desc->IsArrayElement = true;
 
 if (auto Fn = D->ElemDesc->CtorFn)
   Fn(B, ElemLoc, Desc->IsConst, Desc->IsFieldMutable, IsActive,
@@ -408,6 +409,8 @@ QualType Descriptor::getType() const {
 QualType Descriptor::getElemQualType() const {
   assert(isArray());
   QualType T = getType();
+  if (T->isPointerOrReferenceType())
+return T->getPointeeType();
   if (const auto *AT = T->getAsArrayTypeUnsafe())
 return AT->getElementType();
   if (const auto *CT = T->getAs())
diff --git a/clang/lib/AST/ByteCode/Descriptor.h 
b/clang/lib/AST/ByteCode/Descriptor.h
index 5460199e0e991a..85e5c37ad2f896 100644
--- a/clang/lib/AST/ByteCode/Descriptor.h
+++ b/clang/lib/AST/ByteCode/Descriptor.h
@@ -96,12 +96,14 @@ struct InlineDescriptor {
   /// Flag indicating if the field is mutable (if in a record).
   LLVM_PREFERRED_TYPE(bool)
   unsigned IsFieldMutable : 1;
+  unsigned IsArrayElement : 1;
 
   const Descriptor *Desc;
 
   InlineDescriptor(const Descriptor *D)
   : Offset(sizeof(InlineDescriptor)), IsConst(false), IsInitialized(false),
-IsBase(false), IsActive(false), IsFieldMutable(false), Desc(D) {}
+IsBase(false), IsActive(false), IsFieldMutable(false),
+IsArrayElement(false), Desc(D) {}
 
   void dump() const { dump(llvm::errs()); }
   void dump(llvm::raw_ostream &OS) const;
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index 387cad9b137c02..a52f0e336ef298 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -204,18 +204,22 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) 
const {
   Path.push_back(APValue::LValuePathEntry(
   {Ptr.getFieldDesc()->asDecl(), /*IsVirtual=*/false}));
 
-  if (const auto *FD = dyn_cast(Ptr.getFieldDesc()->asDecl()))
+  if (const auto *FD =
+  dyn_cast_if_present(Ptr.getFieldDesc()->asDecl()))
 Offset += getFieldOffset(FD);
 
   Ptr = Ptr.getBase();
 } else if (Ptr.isArrayElement()) {
+  Ptr = Ptr.expand();
   unsigned Index;
   if (Ptr.isOnePastEnd())
 Index = Ptr.getArray().getNumElems();
   else
 Index = Ptr.getIndex();
 
-  Offset += (Index * ASTCtx.getTypeSizeInChars(Ptr.getType()));
+  QualType ElemType = Ptr.getFieldDesc()->getElemQualType();
+  Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
+
   Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
   Ptr = Ptr.getArray();
 } else {
diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h
index ac9b9ed4091b66..08bc4b7e40b636 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -420,8 +420,18 @@ class Pointer {
   }
   /// Checks if the pointer points to an array.
   bool isArrayElement() const {
-if (isBlockPointer())
-  return inArray() && asBlockPointer().Base != Offset;
+if (!isBlockPointer())
+  return false;
+
+const BlockPointer &BP = asBlockPointer();
+if (inArray() && BP.Base != Offset)
+  return true;
+
+// Might be a narrow()'ed element in a composite array.
+// Check the inline descriptor.
+if (BP.Base >= sizeof(InlineDescriptor) && getInlineDesc()->IsArrayElement)
+  return true;
+
 return false;
   }
   /// Pointer points directly to a block.
diff --git a/clang/test/CodeGen/2008-08-07-AlignPadding1.c 
b/clang/test/CodeGen/2008-08-07-AlignPadding1.c
index 17e88ce02659f0..b51bcbc0244da8 100644
--- a/clang/test/CodeGen/2008-08

[clang] [clang] WIP: Warn on mismatched RequiresCapability attributes (PR #67520)

2024-10-04 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Hmm, so this is causing problems:

```c++

namespace DoubleLockBug {
  class Foo {
  public:
Mutex mu_;
int a GUARDED_BY(mu_);
void foo1() EXCLUSIVE_LOCKS_REQUIRED(mu_);
  };
  void Foo::foo1() EXCLUSIVE_LOCKS_REQUIRED(mu_) {
a = 0;
  }
}
```

The AST is:
```
CXXMethodDecl 0x7d3d96ebf710 parent 0x7d3d96ebf118 prev 0x7d3d96ebf450 
<./array.cpp:57:3, line:59:3> line:57:13 foo1 'void ()'
|-CompoundStmt 0x7d3d96ebfa70 
| `-BinaryOperator 0x7d3d96ebfa48  'int' lvalue '='
|   |-MemberExpr 0x7d3d96ebf9e8  'int' lvalue ->a 0x7d3d96ebf398
|   | `-CXXThisExpr 0x7d3d96ebf9d0  'DoubleLockBug::Foo *' implicit this
|   `-IntegerLiteral 0x7d3d96ebfa20  'int' 0
|-RequiresCapabilityAttr 0x7d3d96ebf890  Inherited 
exclusive_locks_required
| `-MemberExpr 0x7d3d96ebf5f8  'Mutex' lvalue ->mu_ 0x7d3d96ebf328 
non_odr_use_unevaluated
|   `-CXXThisExpr 0x7d3d96ebf5e0  'DoubleLockBug::Foo *' implicit this
`-RequiresCapabilityAttr 0x7d3d96ebf930  
exclusive_locks_required
  `-MemberExpr 0x7d3d96ebf8f8  'Mutex' lvalue ->mu_ 0x7d3d96ebf328 
non_odr_use_unevaluated
`-CXXThisExpr 0x7d3d96ebf8e0  'DoubleLockBug::Foo *' implicit this

CXXMethodDecl 0x7d3d96ebf450 <./array.cpp:55:5, line:15:94> line:55:10 foo1 
'void ()'
`-RequiresCapabilityAttr 0x7d3d96ebf630  
exclusive_locks_required
  `-MemberExpr 0x7d3d96ebf5f8  'Mutex' lvalue ->mu_ 0x7d3d96ebf328 
non_odr_use_unevaluated
`-CXXThisExpr 0x7d3d96ebf5e0  'DoubleLockBug::Foo *' implicit this
```

So the definition has `mu_` twice, which causes us to diagnose mismatching 
attributes. Is there any sort of facility to deduplicate capabilities? 
Declaring a `std::set` of `CapabilityExpr` doesn't seem to work because there's 
no `operator<` for those.

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


[clang] [compiler-rt] [llvm] [FMV][AArch64] Unify features ssbs and ssbs2. (PR #110297)

2024-10-04 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

Ping

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


[clang] [clang] WIP: Warn on mismatched RequiresCapability attributes (PR #67520)

2024-10-04 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From 1c117257921fc1c246fbb9f51e3c95d6dc6d295e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 20 Jun 2024 07:39:20 +0200
Subject: [PATCH 1/7] Warn on RequiresCapability attribute mismatch

---
 .../clang/Analysis/Analyses/ThreadSafety.h|  4 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++-
 clang/lib/Analysis/ThreadSafety.cpp   | 34 +++
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |  7 
 4 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafety.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
index 0866b09bab2995..169eef811f5793 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafety.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
@@ -26,6 +26,7 @@ namespace clang {
 class AnalysisDeclContext;
 class FunctionDecl;
 class NamedDecl;
+class Attr;
 
 namespace threadSafety {
 
@@ -230,6 +231,9 @@ class ThreadSafetyHandler {
   /// Warn that there is a cycle in acquired_before/after dependencies.
   virtual void handleBeforeAfterCycle(Name L1Name, SourceLocation Loc) {}
 
+  virtual void handleAttributeMismatch(const FunctionDecl *FD1,
+   const FunctionDecl *FD2) {}
+
   /// Called by the analysis when starting analysis of a function.
   /// Used to issue suggestions for changes to annotations.
   virtual void enterFunction(const FunctionDecl *FD) {}
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 64e6d0407b0ce3..f218a82122c881 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4031,7 +4031,9 @@ def warn_acquired_before : Warning<
 def warn_acquired_before_after_cycle : Warning<
   "cycle in acquired_before/after dependencies, starting with '%0'">,
   InGroup, DefaultIgnore;
-
+def warn_attribute_mismatch : Warning<
+  "attribute mismatch between function definition and declaration of %0">,
+  InGroup, DefaultIgnore;
 
 // Thread safety warnings negative capabilities
 def warn_acquire_requires_negative_cap : Warning<
diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 5577f45aa5217f..25c63f130ca75e 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -2263,6 +2263,37 @@ static bool neverReturns(const CFGBlock *B) {
   return false;
 }
 
+template 
+static SmallVector collectAttrArgs(const FunctionDecl *FD) {
+  SmallVector Args;
+  for (const AttrT *A : FD->specific_attrs()) {
+for (const Expr *E : A->args())
+  Args.push_back(E);
+  }
+
+  return Args;
+}
+
+static void diagnoseMismatchedFunctionAttrs(const FunctionDecl *FD,
+ThreadSafetyHandler &Handler) {
+  assert(FD);
+  FD = FD->getDefinition();
+  assert(FD);
+  auto FDArgs = collectAttrArgs(FD);
+
+  for (const FunctionDecl *D = FD->getPreviousDecl(); D;
+   D = D->getPreviousDecl()) {
+auto DArgs = collectAttrArgs(D);
+
+for (const Expr *E : FDArgs) {
+  if (!llvm::is_contained(DArgs, E)) {
+// FD requires E, but D doesn't.
+Handler.handleAttributeMismatch(FD, D);
+  }
+}
+  }
+}
+
 /// Check a function's CFG for thread-safety violations.
 ///
 /// We traverse the blocks in the CFG, compute the set of mutexes that are held
@@ -2282,6 +2313,9 @@ void 
ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
   const NamedDecl *D = walker.getDecl();
   CurrentFunction = dyn_cast(D);
 
+  if (CurrentFunction)
+diagnoseMismatchedFunctionAttrs(CurrentFunction, Handler);
+
   if (D->hasAttr())
 return;
 
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 6496a33b8f5a50..fb4f97096fb962 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2073,6 +2073,13 @@ class ThreadSafetyReporter : public 
clang::threadSafety::ThreadSafetyHandler {
 Warnings.emplace_back(std::move(Warning), getNotes());
   }
 
+  void handleAttributeMismatch(const FunctionDecl *FD1,
+   const FunctionDecl *FD2) override {
+PartialDiagnosticAt Warning(FD2->getLocation(),
+S.PDiag(diag::warn_attribute_mismatch) << FD1);
+Warnings.emplace_back(std::move(Warning), getNotes());
+  }
+
   void enterFunction(const FunctionDecl* FD) override {
 CurrentFunction = FD;
   }

>From f3ccd5cc229ba4d6476efeb04701ade4c0d844e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 30 Sep 2024 13:13:06 +0200
Subject: [PATCH 2/7] Revert "Warn

[clang] [analyzer] use `invalidateRegions()` in `VisitGCCAsmStmt` (PR #109838)

2024-10-04 Thread Pavel Skripkin via cfe-commits

https://github.com/pskrgag updated 
https://github.com/llvm/llvm-project/pull/109838

>From dbec0e8368157684f9efc63a556037ba31d5f2ea Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Tue, 24 Sep 2024 20:18:30 +0300
Subject: [PATCH 1/3] clang/csa: use invalidateRegions() in VisitGCCAsmStmt

---
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp |  8 +--
 clang/test/Analysis/asm.cpp  | 22 
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index fdabba46992b08..a1a015715b4c8b 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3810,7 +3810,9 @@ void ExprEngine::VisitGCCAsmStmt(const GCCAsmStmt *A, 
ExplodedNode *Pred,
 assert(!isa(X)); // Should be an Lval, or unknown, undef.
 
 if (std::optional LV = X.getAs())
-  state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext());
+  state = state->invalidateRegions(*LV, A, currBldrCtx->blockCount(),
+   Pred->getLocationContext(),
+   /*CausedByPointerEscape=*/true);
   }
 
   // Do not reason about locations passed inside inline assembly.
@@ -3818,7 +3820,9 @@ void ExprEngine::VisitGCCAsmStmt(const GCCAsmStmt *A, 
ExplodedNode *Pred,
 SVal X = state->getSVal(I, Pred->getLocationContext());
 
 if (std::optional LV = X.getAs())
-  state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext());
+  state = state->invalidateRegions(*LV, A, currBldrCtx->blockCount(),
+   Pred->getLocationContext(),
+   /*CausedByPointerEscape=*/true);
   }
 
   Bldr.generateNode(A, Pred, state);
diff --git a/clang/test/Analysis/asm.cpp b/clang/test/Analysis/asm.cpp
index e0691dc4d794f5..b77038b2e83db7 100644
--- a/clang/test/Analysis/asm.cpp
+++ b/clang/test/Analysis/asm.cpp
@@ -10,8 +10,10 @@ void testRValueOutput() {
   int &ref = global;
   ref = 1;
   __asm__("" : "=r"(((int)(global;  // don't crash on rvalue output operand
-  clang_analyzer_eval(global == 1); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(ref == 1);// expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(global == 1); // expected-warning{{FALSE}}
+// expected-warning@-1{{TRUE}}
+  clang_analyzer_eval(ref == 1);// expected-warning{{FALSE}}
+// expected-warning@-1{{TRUE}}
 }
 
 void *MyMemcpy(void *d, const void *s, const int n) {
@@ -40,7 +42,19 @@ void testInlineAsmMemcpyUninit(void)
 {
 int a[10], b[10] = {}, c;
 MyMemcpy(&a[1], &b[1], sizeof(b) - sizeof(b[1]));
-c = a[0]; // expected-warning{{Assigned value is garbage or undefined}}
+c = a[0]; // FIXME: should be warning about uninitialized value, but 
invalidateRegions() also
+  // invalidates super region.
+}
+
+void testInlineAsmMemcpyUninitLoop(const void *src, unsigned long len)
+{
+int a[10], c;
+unsigned long toCopy = sizeof(a) < len ? sizeof(a) : len;
+
+MyMemcpy(&a, src, toCopy);
+
+for (unsigned long i = 0; i < toCopy; ++i)
+  c = a[i]; // no-warning
 }
 
 void testAsmWithVoidPtrArgument()
@@ -49,6 +63,6 @@ void testAsmWithVoidPtrArgument()
   clang_analyzer_dump(*(int *)globalVoidPtr); // expected-warning-re 
{{reg_${{[0-9]+}}},0 S64b,int}>}}
   clang_analyzer_dump_ptr(globalVoidPtr); // expected-warning-re 
{{&SymRegion{reg_${{[0-9]+}
   asm ("" : : "a"(globalVoidPtr)); // no crash
-  clang_analyzer_dump(*(int *)globalVoidPtr); // expected-warning {{Unknown}}
+  clang_analyzer_dump(*(int *)globalVoidPtr); // expected-warning 
{{derived_$3{conj_$2{int, LC1, S2385, #1},Element{SymRegion{reg_$0},0 S64b,int
   clang_analyzer_dump_ptr(globalVoidPtr); // expected-warning-re 
{{&SymRegion{reg_${{[0-9]+}
 }

>From cd6167144452e9af7b3a218d51d98504919d9856 Mon Sep 17 00:00:00 2001
From: Pavel Skripkin 
Date: Tue, 24 Sep 2024 21:53:11 +0300
Subject: [PATCH 2/3] use regex in test string

---
 clang/test/Analysis/asm.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/Analysis/asm.cpp b/clang/test/Analysis/asm.cpp
index b77038b2e83db7..1dae83890e6251 100644
--- a/clang/test/Analysis/asm.cpp
+++ b/clang/test/Analysis/asm.cpp
@@ -51,7 +51,7 @@ void testInlineAsmMemcpyUninitLoop(const void *src, unsigned 
long len)
 int a[10], c;
 unsigned long toCopy = sizeof(a) < len ? sizeof(a) : len;
 
-MyMemcpy(&a, src, toCopy);
+MyMemcpy(a, src, toCopy);
 
 for (unsigned long i = 0; i < toCopy; ++i)
   c = a[i]; // no-warning
@@ -63,6 +63,6 @@ void testAsmWithVoidPtrArgument()
   clang_analyzer_dump(*(int *)globalVoidPtr); // expected-warning-re 
{{reg_${{[0-9]+}}},0 S64b,int}>}}
   clang_analyzer_dump_ptr(globalVoidPtr); // expected-warning-re 
{{&SymRegion{reg_${{[0-9]+}
   

[clang] [flang] [flang][Driver] Add support for -f[no-]wrapv and -f[no]-strict-overflow in the frontend (PR #110061)

2024-10-04 Thread Yusuke MINATO via cfe-commits

https://github.com/yus3710-fj updated 
https://github.com/llvm/llvm-project/pull/110061

>From aea2cfa4b1d812dc84cb1609f93cc2ec2bcd33b4 Mon Sep 17 00:00:00 2001
From: Yusuke MINATO 
Date: Wed, 18 Sep 2024 21:12:43 +0900
Subject: [PATCH 1/2] [flang][Driver] Add support for -f[no-]wrapv and
 -f[no]-strict-overflow in the frontend

This patch introduces the options for integer overflow flags into Flang.
---
 clang/include/clang/Driver/Options.td | 11 +++---
 clang/lib/Driver/ToolChains/Flang.cpp | 11 ++
 flang/include/flang/Common/LangOptions.def|  2 ++
 flang/include/flang/Common/LangOptions.h  |  8 +
 flang/include/flang/Lower/LoweringOptions.def |  5 ++-
 flang/lib/Frontend/CompilerInvocation.cpp | 36 +--
 flang/test/Driver/frontend-forwarding.f90 |  2 ++
 flang/test/Driver/integer-overflow.f90| 10 ++
 8 files changed, 75 insertions(+), 10 deletions(-)
 create mode 100644 flang/test/Driver/integer-overflow.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9d183ff2d69b3c..4610cd917f685d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3451,7 +3451,8 @@ def fno_strict_aliasing : Flag<["-"], 
"fno-strict-aliasing">, Group,
 def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group;
 def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group;
 def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group;
-def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group;
+def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group,
+  Visibility<[ClangOption, FlangOption]>;
 def fno_pointer_tbaa : Flag<["-"], "fno-pointer-tbaa">, Group;
 def fno_temp_file : Flag<["-"], "fno-temp-file">, Group,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, HelpText<
@@ -3467,7 +3468,8 @@ def fno_verbose_asm : Flag<["-"], "fno-verbose-asm">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
   MarshallingInfoNegativeFlag>;
 def fno_working_directory : Flag<["-"], "fno-working-directory">, 
Group;
-def fno_wrapv : Flag<["-"], "fno-wrapv">, Group;
+def fno_wrapv : Flag<["-"], "fno-wrapv">, Group,
+  Visibility<[ClangOption, FlangOption]>;
 def fobjc_arc : Flag<["-"], "fobjc-arc">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Synthesize retain and release calls for Objective-C pointers">;
@@ -3963,7 +3965,8 @@ defm strict_vtable_pointers : 
BoolFOption<"strict-vtable-pointers",
   "Enable optimizations based on the strict rules for"
 " overwriting polymorphic C++ objects">,
   NegFlag>;
-def fstrict_overflow : Flag<["-"], "fstrict-overflow">, Group;
+def fstrict_overflow : Flag<["-"], "fstrict-overflow">, Group,
+  Visibility<[ClangOption, FlangOption]>;
 def fpointer_tbaa : Flag<["-"], "fpointer-tbaa">, Group;
 def fdriver_only : Flag<["-"], "fdriver-only">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
@@ -4232,7 +4235,7 @@ defm virtual_function_elimination : 
BoolFOption<"virtual-function-elimination",
   NegFlag, BothFlags<[], [ClangOption, CLOption]>>;
 
 def fwrapv : Flag<["-"], "fwrapv">, Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   HelpText<"Treat signed integer overflow as two's complement">;
 def fwritable_strings : Flag<["-"], "fwritable-strings">, Group,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 98350690f8d20e..1865fd57a2d893 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -866,6 +866,17 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 }
   }
 
+  // -fno-strict-overflow implies -fwrapv if it isn't disabled, but
+  // -fstrict-overflow won't turn off an explicitly enabled -fwrapv.
+  if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) {
+if (A->getOption().matches(options::OPT_fwrapv))
+  CmdArgs.push_back("-fwrapv");
+  } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow,
+  options::OPT_fno_strict_overflow)) {
+if (A->getOption().matches(options::OPT_fno_strict_overflow))
+  CmdArgs.push_back("-fwrapv");
+  }
+
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
diff --git a/flang/include/flang/Common/LangOptions.def 
b/flang/include/flang/Common/LangOptions.def
index d3e1e972d1519f..1bfdba9cc2c1c7 100644
--- a/flang/include/flang/Common/LangOptions.def
+++ b/flang/include/flang/Common/LangOptions.def
@@ -20,6 +20,8 @@ LANGOPT(Name, Bits, Default)
 #endif
 
 ENUM_LANGOPT(FPContractMode, FPModeKind, 2, FPM_Fast) ///< FP Contract Mode 
(off/fast)
+/// signed integer overflow handling
+ENUM_LANGOPT(SignedOverflowBehavior, SignedOverflowBeha

[clang] [clang][bytecode] Change isArrayElement() for narrowed composite arrays (PR #111110)

2024-10-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Make isArrayElement() return true here, so we can know that such a pointer is 
in fact an array element and handle it properly in toAPValue().

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


6 Files Affected:

- (modified) clang/lib/AST/ByteCode/Descriptor.cpp (+3) 
- (modified) clang/lib/AST/ByteCode/Descriptor.h (+3-1) 
- (modified) clang/lib/AST/ByteCode/Pointer.cpp (+6-2) 
- (modified) clang/lib/AST/ByteCode/Pointer.h (+12-2) 
- (modified) clang/test/CodeGen/2008-08-07-AlignPadding1.c (+1) 
- (modified) clang/unittests/AST/ByteCode/Descriptor.cpp (+4-4) 


``diff
diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp 
b/clang/lib/AST/ByteCode/Descriptor.cpp
index 65ac7a3129abaf..5a8a2b64d5582d 100644
--- a/clang/lib/AST/ByteCode/Descriptor.cpp
+++ b/clang/lib/AST/ByteCode/Descriptor.cpp
@@ -103,6 +103,7 @@ static void ctorArrayDesc(Block *B, std::byte *Ptr, bool 
IsConst,
 Desc->IsConst = IsConst || D->IsConst;
 Desc->IsFieldMutable = IsMutable || D->IsMutable;
 Desc->InUnion = InUnion;
+Desc->IsArrayElement = true;
 
 if (auto Fn = D->ElemDesc->CtorFn)
   Fn(B, ElemLoc, Desc->IsConst, Desc->IsFieldMutable, IsActive,
@@ -408,6 +409,8 @@ QualType Descriptor::getType() const {
 QualType Descriptor::getElemQualType() const {
   assert(isArray());
   QualType T = getType();
+  if (T->isPointerOrReferenceType())
+return T->getPointeeType();
   if (const auto *AT = T->getAsArrayTypeUnsafe())
 return AT->getElementType();
   if (const auto *CT = T->getAs())
diff --git a/clang/lib/AST/ByteCode/Descriptor.h 
b/clang/lib/AST/ByteCode/Descriptor.h
index 5460199e0e991a..85e5c37ad2f896 100644
--- a/clang/lib/AST/ByteCode/Descriptor.h
+++ b/clang/lib/AST/ByteCode/Descriptor.h
@@ -96,12 +96,14 @@ struct InlineDescriptor {
   /// Flag indicating if the field is mutable (if in a record).
   LLVM_PREFERRED_TYPE(bool)
   unsigned IsFieldMutable : 1;
+  unsigned IsArrayElement : 1;
 
   const Descriptor *Desc;
 
   InlineDescriptor(const Descriptor *D)
   : Offset(sizeof(InlineDescriptor)), IsConst(false), IsInitialized(false),
-IsBase(false), IsActive(false), IsFieldMutable(false), Desc(D) {}
+IsBase(false), IsActive(false), IsFieldMutable(false),
+IsArrayElement(false), Desc(D) {}
 
   void dump() const { dump(llvm::errs()); }
   void dump(llvm::raw_ostream &OS) const;
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index 387cad9b137c02..a52f0e336ef298 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -204,18 +204,22 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) 
const {
   Path.push_back(APValue::LValuePathEntry(
   {Ptr.getFieldDesc()->asDecl(), /*IsVirtual=*/false}));
 
-  if (const auto *FD = dyn_cast(Ptr.getFieldDesc()->asDecl()))
+  if (const auto *FD =
+  dyn_cast_if_present(Ptr.getFieldDesc()->asDecl()))
 Offset += getFieldOffset(FD);
 
   Ptr = Ptr.getBase();
 } else if (Ptr.isArrayElement()) {
+  Ptr = Ptr.expand();
   unsigned Index;
   if (Ptr.isOnePastEnd())
 Index = Ptr.getArray().getNumElems();
   else
 Index = Ptr.getIndex();
 
-  Offset += (Index * ASTCtx.getTypeSizeInChars(Ptr.getType()));
+  QualType ElemType = Ptr.getFieldDesc()->getElemQualType();
+  Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
+
   Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
   Ptr = Ptr.getArray();
 } else {
diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h
index ac9b9ed4091b66..08bc4b7e40b636 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -420,8 +420,18 @@ class Pointer {
   }
   /// Checks if the pointer points to an array.
   bool isArrayElement() const {
-if (isBlockPointer())
-  return inArray() && asBlockPointer().Base != Offset;
+if (!isBlockPointer())
+  return false;
+
+const BlockPointer &BP = asBlockPointer();
+if (inArray() && BP.Base != Offset)
+  return true;
+
+// Might be a narrow()'ed element in a composite array.
+// Check the inline descriptor.
+if (BP.Base >= sizeof(InlineDescriptor) && getInlineDesc()->IsArrayElement)
+  return true;
+
 return false;
   }
   /// Pointer points directly to a block.
diff --git a/clang/test/CodeGen/2008-08-07-AlignPadding1.c 
b/clang/test/CodeGen/2008-08-07-AlignPadding1.c
index 17e88ce02659f0..b51bcbc0244da8 100644
--- a/clang/test/CodeGen/2008-08-07-AlignPadding1.c
+++ b/clang/test/CodeGen/2008-08-07-AlignPadding1.c
@@ -1,4 +1,5 @@
 /* RUN: %clang_cc1 %s -emit-llvm -triple x86_64-apple-darwin -o - | FileCheck 
%s
+/* RUN: %clang_cc1 %s -emit-llvm -triple x86_64-apple-darwin -o - 
-fexperimental-new-constant-interpreter | FileCheck %s
 
 The FE must generate padding h

[clang] [clang][bytecode] Change isArrayElement() for narrowed composite arrays (PR #111110)

2024-10-04 Thread Timm Baeder via cfe-commits

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

>From 2a2f13453a467ff4afbc9976a673cacb11b4eace Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 4 Oct 2024 08:37:16 +0200
Subject: [PATCH] [clang][bytecode] Change isArrayElement() for narrowed
 composite arrays

Make isArrayElement() return true here, so we can know that such a
pointer is in fact an array element and handle it properly in
toAPValue().
---
 clang/lib/AST/ByteCode/Descriptor.cpp |  3 +++
 clang/lib/AST/ByteCode/Descriptor.h   |  6 +-
 clang/lib/AST/ByteCode/Pointer.cpp|  8 ++--
 clang/lib/AST/ByteCode/Pointer.h  | 14 --
 clang/test/CodeGen/2008-08-07-AlignPadding1.c |  1 +
 clang/unittests/AST/ByteCode/Descriptor.cpp   |  8 
 6 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp 
b/clang/lib/AST/ByteCode/Descriptor.cpp
index 65ac7a3129abaf..5a8a2b64d5582d 100644
--- a/clang/lib/AST/ByteCode/Descriptor.cpp
+++ b/clang/lib/AST/ByteCode/Descriptor.cpp
@@ -103,6 +103,7 @@ static void ctorArrayDesc(Block *B, std::byte *Ptr, bool 
IsConst,
 Desc->IsConst = IsConst || D->IsConst;
 Desc->IsFieldMutable = IsMutable || D->IsMutable;
 Desc->InUnion = InUnion;
+Desc->IsArrayElement = true;
 
 if (auto Fn = D->ElemDesc->CtorFn)
   Fn(B, ElemLoc, Desc->IsConst, Desc->IsFieldMutable, IsActive,
@@ -408,6 +409,8 @@ QualType Descriptor::getType() const {
 QualType Descriptor::getElemQualType() const {
   assert(isArray());
   QualType T = getType();
+  if (T->isPointerOrReferenceType())
+return T->getPointeeType();
   if (const auto *AT = T->getAsArrayTypeUnsafe())
 return AT->getElementType();
   if (const auto *CT = T->getAs())
diff --git a/clang/lib/AST/ByteCode/Descriptor.h 
b/clang/lib/AST/ByteCode/Descriptor.h
index 5460199e0e991a..bcb635e157f009 100644
--- a/clang/lib/AST/ByteCode/Descriptor.h
+++ b/clang/lib/AST/ByteCode/Descriptor.h
@@ -96,12 +96,16 @@ struct InlineDescriptor {
   /// Flag indicating if the field is mutable (if in a record).
   LLVM_PREFERRED_TYPE(bool)
   unsigned IsFieldMutable : 1;
+  /// Flag indicating if the field is an element of a composite array.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned IsArrayElement : 1;
 
   const Descriptor *Desc;
 
   InlineDescriptor(const Descriptor *D)
   : Offset(sizeof(InlineDescriptor)), IsConst(false), IsInitialized(false),
-IsBase(false), IsActive(false), IsFieldMutable(false), Desc(D) {}
+IsBase(false), IsActive(false), IsFieldMutable(false),
+IsArrayElement(false), Desc(D) {}
 
   void dump() const { dump(llvm::errs()); }
   void dump(llvm::raw_ostream &OS) const;
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index 387cad9b137c02..a52f0e336ef298 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -204,18 +204,22 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) 
const {
   Path.push_back(APValue::LValuePathEntry(
   {Ptr.getFieldDesc()->asDecl(), /*IsVirtual=*/false}));
 
-  if (const auto *FD = dyn_cast(Ptr.getFieldDesc()->asDecl()))
+  if (const auto *FD =
+  dyn_cast_if_present(Ptr.getFieldDesc()->asDecl()))
 Offset += getFieldOffset(FD);
 
   Ptr = Ptr.getBase();
 } else if (Ptr.isArrayElement()) {
+  Ptr = Ptr.expand();
   unsigned Index;
   if (Ptr.isOnePastEnd())
 Index = Ptr.getArray().getNumElems();
   else
 Index = Ptr.getIndex();
 
-  Offset += (Index * ASTCtx.getTypeSizeInChars(Ptr.getType()));
+  QualType ElemType = Ptr.getFieldDesc()->getElemQualType();
+  Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
+
   Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
   Ptr = Ptr.getArray();
 } else {
diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h
index ac9b9ed4091b66..08bc4b7e40b636 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -420,8 +420,18 @@ class Pointer {
   }
   /// Checks if the pointer points to an array.
   bool isArrayElement() const {
-if (isBlockPointer())
-  return inArray() && asBlockPointer().Base != Offset;
+if (!isBlockPointer())
+  return false;
+
+const BlockPointer &BP = asBlockPointer();
+if (inArray() && BP.Base != Offset)
+  return true;
+
+// Might be a narrow()'ed element in a composite array.
+// Check the inline descriptor.
+if (BP.Base >= sizeof(InlineDescriptor) && getInlineDesc()->IsArrayElement)
+  return true;
+
 return false;
   }
   /// Pointer points directly to a block.
diff --git a/clang/test/CodeGen/2008-08-07-AlignPadding1.c 
b/clang/test/CodeGen/2008-08-07-AlignPadding1.c
index 17e88ce02659f0..b51bcbc0244da8 100644
--- a/clang/test/CodeGen/2008-08-07-AlignPadding1.c
+++ b/clang/test/Code

[clang] [flang] [flang][Driver] Add support for -f[no-]wrapv and -f[no]-strict-overflow in the frontend (PR #110061)

2024-10-04 Thread Yusuke MINATO via cfe-commits


@@ -866,6 +866,17 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 }
   }
 
+  // -fno-strict-overflow implies -fwrapv if it isn't disabled, but
+  // -fstrict-overflow won't turn off an explicitly enabled -fwrapv.
+  if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) {
+if (A->getOption().matches(options::OPT_fwrapv))
+  CmdArgs.push_back("-fwrapv");
+  } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow,
+  options::OPT_fno_strict_overflow)) {
+if (A->getOption().matches(options::OPT_fno_strict_overflow))
+  CmdArgs.push_back("-fwrapv");
+  }
+

yus3710-fj wrote:

Thank you for showing me a better way.
I created a function `renderIntegerOverflowOptions` to handle common options 
between clang and flang. However, I'm not sure the name of the function is 
appropriate because there are other related options handled only by clang (e.g. 
`-ftrapv`).

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


[clang] [flang] [flang][Driver] Add support for -f[no-]wrapv and -f[no]-strict-overflow in the frontend (PR #110061)

2024-10-04 Thread Yusuke MINATO via cfe-commits


@@ -0,0 +1,10 @@
+! Test for correct forwarding of integer overflow flags from the compiler 
driver
+! to the frontend driver
+
+! RUN: %flang -### -fno-strict-overflow %s 2>&1 | FileCheck %s 
--check-prefixes CHECK,INDUCED

yus3710-fj wrote:

As you mentioned, the check for `CHECK` is redundant. I removed it.

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


[clang-tools-extra] 992e754 - Fix MSVC "not all control paths return a value" warning. NFC.

2024-10-04 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2024-10-04T09:54:13+01:00
New Revision: 992e75403f417d46ce9015147ff49d67009e736c

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

LOG: Fix MSVC "not all control paths return a value" warning. NFC.

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/SwapBinaryOperands.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/SwapBinaryOperands.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/SwapBinaryOperands.cpp
index 1602093e3d2893..9ad0089a5d0359 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/SwapBinaryOperands.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/SwapBinaryOperands.cpp
@@ -126,6 +126,7 @@ BinaryOperatorKind swapOperator(const BinaryOperatorKind 
Opcode) {
   case BinaryOperatorKind::BO_OrAssign:
 return Opcode;
   }
+  llvm_unreachable("Unknown BinaryOperatorKind enum");
 }
 
 /// Swaps the operands to a binary operator



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


[clang] [clang][analyzer] Check initialization and argument passing in FixedAddressChecker (PR #110977)

2024-10-04 Thread Balázs Kéri via cfe-commits

balazske wrote:

When `check::Location` is used it looks better to extend the 
`DereferenceChecker` with this new check that looks simple to add to it (it 
uses `check::Bind` too, probably this finds the cases when location does not 
work). Only difficulty is that this is a non-fatal error.

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


[clang] [clang] Catch missing format attributes (PR #105479)

2024-10-04 Thread Budimir Aranđelović via cfe-commits


@@ -5335,6 +5335,217 @@ static void handlePreferredTypeAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
   D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI));
 }
 
+// This function is called only if function call is not inside template body.
+// TODO: Add call for function calls inside template body.
+// Emit warnings if parent function misses format attributes.
+void Sema::DiagnoseMissingFormatAttributes(Stmt *Body,
+   const FunctionDecl *FDecl) {
+  assert(FDecl);
+
+  // If there are no function body, exit.
+  if (!Body)
+return;
+
+  // Get missing format attributes
+  std::vector MissingFormatAttributes =
+  GetMissingFormatAttributes(Body, FDecl);
+  if (MissingFormatAttributes.empty())
+return;
+
+  // Check if there are more than one format type found. In that case do not
+  // emit diagnostic.
+  const clang::IdentifierInfo *AttrType = 
MissingFormatAttributes[0]->getType();
+  if (llvm::any_of(MissingFormatAttributes, [&](const FormatAttr *Attr) {
+return AttrType != Attr->getType();
+  }))
+return;
+
+  for (const FormatAttr *FA : MissingFormatAttributes) {
+// If format index and first-to-check argument index are negative, it means
+// that this attribute is only saved for multiple format types checking.
+if (FA->getFormatIdx() < 0 || FA->getFirstArg() < 0)
+  continue;
+
+// Emit diagnostic
+SourceLocation Loc = FDecl->getLocation();
+Diag(Loc, diag::warn_missing_format_attribute)
+<< FA->getType() << FDecl
+<< FixItHint::CreateInsertion(Loc,
+  (llvm::Twine("__attribute__((format(") +
+   FA->getType()->getName() + ", " +
+   llvm::Twine(FA->getFormatIdx()) + ", " +
+   llvm::Twine(FA->getFirstArg()) + ")))")
+  .str());
+  }
+}
+
+// Returns vector of format attributes. There are no two attributes with same
+// arguments in returning vector. There can be attributes that effectivelly 
only
+// store information about format type.
+std::vector
+Sema::GetMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl) {
+  unsigned int FunctionFormatArgumentIndexOffset =
+  checkIfMethodHasImplicitObjectParameter(FDecl) ? 2 : 1;
+
+  std::vector MissingAttributes;
+
+  // Iterate over body statements.
+  for (auto *Child : Body->children()) {
+// If child statement is compound statement, recursively get missing
+// attributes.
+if (dyn_cast_or_null(Child)) {
+  std::vector CompoundStmtMissingAttributes =
+  GetMissingFormatAttributes(Child, FDecl);
+
+  // If there are already missing attributes with same arguments, do not 
add
+  // duplicates.
+  for (FormatAttr *FA : CompoundStmtMissingAttributes) {
+if (!llvm::any_of(MissingAttributes, [&](const FormatAttr *Attr) {
+  return FA->getType() == Attr->getType() &&
+ FA->getFormatIdx() == Attr->getFormatIdx() &&
+ FA->getFirstArg() == Attr->getFirstArg();
+}))
+  MissingAttributes.push_back(FA);
+  }
+
+  continue;
+}
+
+ValueStmt *VS = dyn_cast_or_null(Child);
+if (!VS)
+  continue;
+Expr *TheExpr = VS->getExprStmt();
+if (!TheExpr)
+  continue;
+CallExpr *TheCall = dyn_cast_or_null(TheExpr);
+if (!TheCall)
+  continue;
+const FunctionDecl *ChildFunction =
+dyn_cast_or_null(TheCall->getCalleeDecl());
+if (!ChildFunction || !ChildFunction->hasAttr())
+  continue;
+
+Expr **Args = TheCall->getArgs();
+unsigned int NumArgs = TheCall->getNumArgs();
+
+// If child expression is function, check if it is format function.
+// If it is, check if parent function misses format attributes.
+
+unsigned int ChildFunctionFormatArgumentIndexOffset =
+checkIfMethodHasImplicitObjectParameter(ChildFunction) ? 2 : 1;
+
+// If child function is format function and format arguments are not
+// relevant to emit diagnostic, save only information about format type
+// (format index and first-to-check argument index are set to -1).
+// Information about format type is later used to determine if there are
+// more than one format type found.
+
+// Check if function has format attribute with forwarded format string.
+IdentifierInfo *AttrType;
+const ParmVarDecl *FormatArg;
+if (!llvm::any_of(ChildFunction->specific_attrs(),
+  [&](const FormatAttr *Attr) {
+AttrType = Attr->getType();
+
+int OffsetFormatIndex =
+Attr->getFormatIdx() -
+ChildFunctionFormatArgumentIndexOffset;
+if (OffsetFormatIndex < 0 ||
+(unsigned)OffsetFor

[clang] [flang] [llvm] [openmp] [flang][driver] rename flang-new to flang (PR #110023)

2024-10-04 Thread Brad Richardson via cfe-commits

https://github.com/everythingfunctional updated 
https://github.com/llvm/llvm-project/pull/110023

>From 649a73478c78389560042030a9717a05e8e338a8 Mon Sep 17 00:00:00 2001
From: Brad Richardson 
Date: Wed, 25 Sep 2024 13:25:22 -0500
Subject: [PATCH 1/5] [flang][driver] rename flang-new to flang

---
 .github/workflows/release-binaries.yml|  2 +-
 clang/include/clang/Driver/Options.td |  4 +-
 clang/lib/Driver/Driver.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  6 +-
 clang/test/Driver/flang/flang.f90 |  2 +-
 clang/test/Driver/flang/flang_ucase.F90   |  2 +-
 .../Driver/flang/multiple-inputs-mixed.f90|  2 +-
 clang/test/Driver/flang/multiple-inputs.f90   |  4 +-
 flang/docs/FlangDriver.md | 76 +--
 flang/docs/ImplementingASemanticCheck.md  |  4 +-
 flang/docs/Overview.md| 26 +++
 .../FlangOmpReport/FlangOmpReport.cpp |  2 +-
 .../flang/Optimizer/Analysis/AliasAnalysis.h  |  2 +-
 flang/include/flang/Tools/CrossToolHelpers.h  |  2 +-
 flang/lib/Frontend/CompilerInvocation.cpp |  6 +-
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 .../ExecuteCompilerInvocation.cpp |  3 +-
 flang/runtime/CMakeLists.txt  |  6 +-
 flang/test/CMakeLists.txt |  2 +-
 flang/test/Driver/aarch64-outline-atomics.f90 |  2 +-
 .../Driver/color-diagnostics-forwarding.f90   |  4 +-
 flang/test/Driver/compiler-options.f90|  4 +-
 flang/test/Driver/convert.f90 |  2 +-
 .../test/Driver/disable-ext-name-interop.f90  |  2 +-
 flang/test/Driver/driver-version.f90  |  4 +-
 flang/test/Driver/escaped-backslash.f90   |  4 +-
 flang/test/Driver/fdefault.f90| 28 +++
 flang/test/Driver/flarge-sizes.f90| 20 ++---
 .../test/Driver/frame-pointer-forwarding.f90  |  2 +-
 flang/test/Driver/frontend-forwarding.f90 |  4 +-
 flang/test/Driver/hlfir-no-hlfir-error.f90|  4 +-
 flang/test/Driver/intrinsic-module-path.f90   |  2 +-
 flang/test/Driver/large-data-threshold.f90|  6 +-
 flang/test/Driver/lto-flags.f90   |  2 +-
 flang/test/Driver/macro-def-undef.F90 |  4 +-
 flang/test/Driver/missing-input.f90   | 14 ++--
 flang/test/Driver/multiple-input-files.f90|  2 +-
 flang/test/Driver/omp-driver-offload.f90  | 66 
 .../predefined-macros-compiler-version.F90|  4 +-
 flang/test/Driver/std2018-wrong.f90   |  2 +-
 flang/test/Driver/std2018.f90 |  2 +-
 .../Driver/supported-suffices/f03-suffix.f03  |  2 +-
 .../Driver/supported-suffices/f08-suffix.f08  |  2 +-
 flang/test/Driver/use-module-error.f90|  4 +-
 flang/test/Driver/use-module.f90  |  4 +-
 flang/test/Driver/version-loops.f90   | 18 ++---
 flang/test/Driver/wextra-ok.f90   |  2 +-
 flang/test/HLFIR/hlfir-flags.f90  |  2 +-
 .../Intrinsics/command_argument_count.f90 |  4 +-
 flang/test/Lower/Intrinsics/exit.f90  |  2 +-
 .../test/Lower/Intrinsics/ieee_is_normal.f90  |  2 +-
 flang/test/Lower/Intrinsics/isnan.f90 |  2 +-
 flang/test/Lower/Intrinsics/modulo.f90|  2 +-
 .../OpenMP/Todo/omp-declarative-allocate.f90  |  2 +-
 .../OpenMP/Todo/omp-declare-reduction.f90 |  2 +-
 .../Lower/OpenMP/Todo/omp-declare-simd.f90|  2 +-
 .../parallel-lastprivate-clause-scalar.f90|  2 +-
 .../parallel-wsloop-reduction-byref.f90   |  2 +-
 .../OpenMP/parallel-wsloop-reduction.f90  |  2 +-
 flang/test/lit.cfg.py |  4 +-
 flang/tools/f18/CMakeLists.txt| 10 +--
 flang/tools/flang-driver/CMakeLists.txt   | 12 +--
 flang/tools/flang-driver/driver.cpp   |  6 +-
 llvm/runtimes/CMakeLists.txt  | 10 +--
 offload/CMakeLists.txt|  4 +-
 openmp/CMakeLists.txt |  4 +-
 66 files changed, 220 insertions(+), 227 deletions(-)

diff --git a/.github/workflows/release-binaries.yml 
b/.github/workflows/release-binaries.yml
index 925912df6843e4..6073ebac9e6c2c 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -328,7 +328,7 @@ jobs:
   run: |
 # Build some of the mlir tools that take a long time to link
 if [ "${{ needs.prepare.outputs.build-flang }}" = "true" ]; then
-  ninja -C ${{ steps.setup-stage.outputs.build-prefix 
}}/build/tools/clang/stage2-bins/ -j2 flang-new bbc
+  ninja -C ${{ steps.setup-stage.outputs.build-prefix 
}}/build/tools/clang/stage2-bins/ -j2 flang bbc
 fi
 ninja -C ${{ steps.setup-stage.outputs.build-prefix 
}}/build/tools/clang/stage2-bins/ \
 mlir-bytecode-parser-fuzzer \
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 932cf13edab53d..4a45a825da8fa1 100644
--- a/clang/include/clang/Drive

[clang] [flang] [llvm] [openmp] [flang][driver] rename flang-new to flang (PR #110023)

2024-10-04 Thread Brad Richardson via cfe-commits


@@ -339,11 +335,11 @@ just added using your new frontend option.
 
 ## CMake Support
 As of [#7246](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7246)
-(and soon to be released CMake 3.24.0), `cmake` can detect `flang-new` as a
+(and soon to be released CMake 3.24.0), `cmake` can detect `flang` as a

everythingfunctional wrote:

So, sounds like support is there in CMake, so I've updated the note and the 
identified version.

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


[clang] [Clang][Sema] fix noexecpt mismatch of friend declaration (PR #102267)

2024-10-04 Thread Younan Zhang via cfe-commits


@@ -4698,7 +4698,22 @@ void Sema::InstantiateExceptionSpec(SourceLocation 
PointOfInstantiation,
   // Enter the scope of this instantiation. We don't use
   // PushDeclContext because we don't have a scope.
   Sema::ContextRAII savedContext(*this, Decl);
+
+  FunctionDecl *Source = Proto->getExtProtoInfo().ExceptionSpec.SourceTemplate;
+  FunctionTemplateDecl *SourceTemplate = 
Source->getDescribedFunctionTemplate();
+  llvm::SmallDenseMap InstTemplateParams;
+  if (CurrentInstantiationScope && SourceTemplate)
+if (TemplateParameterList *TPL = SourceTemplate->getTemplateParameters())
+  for (NamedDecl *TemplateParam : *TPL)
+if (auto *Found =
+CurrentInstantiationScope->findInstantiationOf(TemplateParam))
+  if (auto *InstTemplateParam = Found->dyn_cast())
+InstTemplateParams[TemplateParam] = InstTemplateParam;
+

zyn0217 wrote:

> ... the same way we normalize constraints prior to comparing them.

Which means we don't need an individual instantiation scope for the noexcept 
specification thereafter, so the question here could be resolved naturally I 
presume?

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


[clang] [Clang] Add "extend lifetime" flags and release note (PR #110000)

2024-10-04 Thread Stephen Tozer via cfe-commits

SLTozer wrote:

> The release note doesn't say: Does `-fextend-lifetimes` imply 
> `-fextend-this-pointer`? They're implemented as independent toggles but the 
> effect isn't really independent IIRC. I wonder (years after it was originally 
> implemented downstream, I know) whether we'd be better off with 
> `-fextend-lifetimes[={all,this,none}]`. (But maybe wait for a second opinion.)

Correct, this is _sort of_ implied by `-fextend-lifetimes` extending the life 
of all variables and `-fextend-this-pointer` extending just the `this` pointer, 
but it wasn't totally clear to me the first time I looked at the flag either. 
Making it into a flag that takes options is an interesting idea and one I 
broadly approve of - especially as I have some plans to add additional modes 
(e.g. `-fextend-lifetimes=params`) further down the line.

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


[clang] [Clang] Implement CWG 2628 "Implicit deduction guides should propagate constraints" (PR #111143)

2024-10-04 Thread Erich Keane via cfe-commits


@@ -446,10 +450,46 @@ struct ConvertConstructorToDeductionGuideTransform {
   return nullptr;
 TypeSourceInfo *NewTInfo = TLB.getTypeSourceInfo(SemaRef.Context, NewType);
 
+// At this point, the function parameters are already 'instantiated' in the
+// current scope. Substitute into the constructor's trailing
+// requires-clause, if any.
+Expr *FunctionTrailingRC = nullptr;
+if (Expr *RC = CD->getTrailingRequiresClause()) {
+  MultiLevelTemplateArgumentList Args;
+  Args.setKind(TemplateSubstitutionKind::Rewrite);
+  Args.addOuterTemplateArguments(Depth1Args);
+  Args.addOuterRetainedLevel();
+  if (NestedPattern)
+Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
+  ExprResult E = SemaRef.SubstConstraintExprWithoutSatisfaction(RC, Args);
+  if (!E.isUsable())
+return nullptr;
+  FunctionTrailingRC = E.get();
+}
+
+// C++ [over.match.class.deduct]p1:
+// If C is defined, for each constructor of C, a function template with
+// the following properties:
+// [...]
+// - The associated constraints are the conjunction of the associated
+// constraints of C and the associated constraints of the constructor, if
+// any.
+if (OuterRC) {
+  // The outer template parameters are not transformed, so their
+  // associated constraints don't need substitution.
+  if (!FunctionTrailingRC)
+FunctionTrailingRC = OuterRC;
+  else
+FunctionTrailingRC = BinaryOperator::Create(

erichkeane wrote:

This has a certain elegance to it, but I'm not super thrilled with having a 
BinaryOperator that doesn't have a valid source location.  I wonder if we 
should instead store a collection and check them that way.  It makes checking 
them a little more difficult down the road, but keeps source fidelity.

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


[clang] [flang] [llvm] [mlir] Make Ownership of MachineModuleInfo in Its Wrapper Pass External (PR #110443)

2024-10-04 Thread Matin Raayai via cfe-commits


@@ -1162,6 +1165,7 @@ void EmitAssemblyHelper::RunCodegenPipeline(
   // does not work with the codegen pipeline.
   // FIXME: make the new PM work with the codegen pipeline.
   legacy::PassManager CodeGenPasses;
+  std::unique_ptr MMI;

matinraayai wrote:

I'll change it to a normal construction with the `TM`.

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


[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic for spirv backend (PR #111010)

2024-10-04 Thread Nathan Gauër via cfe-commits

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


[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic for spirv backend (PR #111010)

2024-10-04 Thread Nathan Gauër via cfe-commits


@@ -2653,6 +2653,21 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register 
ResVReg,
 .addUse(GR.getSPIRVTypeID(ResType))
 .addUse(GR.getOrCreateConstInt(3, I, IntTy, TII));
   }
+  case Intrinsic::spv_wave_read_lane_at: {
+assert(I.getNumOperands() == 4);
+assert(I.getOperand(2).isReg());
+assert(I.getOperand(3).isReg());
+
+// Defines the execution scope currently 2 for group, see scope table
+SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType(32, I, TII);
+return BuildMI(BB, I, I.getDebugLoc(),
+   TII.get(SPIRV::OpGroupNonUniformShuffle))
+.addDef(ResVReg)
+.addUse(GR.getSPIRVTypeID(ResType))
+.addUse(I.getOperand(2).getReg())
+.addUse(I.getOperand(3).getReg())
+.addUse(GR.getOrCreateConstInt(2, I, IntTy, TII));

Keenuts wrote:

Looks like the correct value is 3? (cross-lane interaction, not cross-wave).
For the `OpGroupNonUniformElect`, the value MUST be 3 (spec)
DXC also generates both with a scope of 3.

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


[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic for spirv backend (PR #111010)

2024-10-04 Thread Nathan Gauër via cfe-commits

https://github.com/Keenuts commented:

Thanks for this! Some minor changes, otherwise looks good 😊

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


[clang] d0756ca - [ARM][AArch64] Introduce the Armv9.6-A architecture version (#110825)

2024-10-04 Thread via cfe-commits

Author: Jonathan Thackray
Date: 2024-10-04T10:12:41+01:00
New Revision: d0756caedcf067860240bf31e8f9d371ba706757

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

LOG: [ARM][AArch64] Introduce the Armv9.6-A architecture version (#110825)

This introduces the Armv9.6-A architecture version, including the
relevant command-line option for -march.

More details about the Armv9.6-A architecture version can be found at:
  * 
https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-a-profile-architecture-developments-2024
  * https://developer.arm.com/documentation/ddi0602/2024-09/

Added: 
clang/test/Driver/aarch64-v96a.c

Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/Basic/Targets/ARM.cpp
clang/test/CodeGen/arm-acle-coproc.c
clang/test/Driver/arm-cortex-cpus-1.c
clang/test/Preprocessor/aarch64-target-features.c
clang/test/Preprocessor/arm-target-features.c
llvm/include/llvm/TargetParser/AArch64TargetParser.h
llvm/include/llvm/TargetParser/ARMTargetParser.def
llvm/include/llvm/TargetParser/Triple.h
llvm/lib/Target/AArch64/AArch64Features.td
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/lib/Target/ARM/ARMArchitectures.td
llvm/lib/Target/ARM/ARMFeatures.td
llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
llvm/lib/TargetParser/ARMTargetParser.cpp
llvm/lib/TargetParser/ARMTargetParserCommon.cpp
llvm/lib/TargetParser/Triple.cpp
llvm/unittests/TargetParser/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 5f5dfcb722f9d4..61889861c9c803 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -373,6 +373,12 @@ void AArch64TargetInfo::getTargetDefinesARMV95A(const 
LangOptions &Opts,
   getTargetDefinesARMV94A(Opts, Builder);
 }
 
+void AArch64TargetInfo::getTargetDefinesARMV96A(const LangOptions &Opts,
+MacroBuilder &Builder) const {
+  // Armv9.6-A does not have a v8.* equivalent, but is a superset of v9.5-A.
+  getTargetDefinesARMV95A(Opts, Builder);
+}
+
 void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
  MacroBuilder &Builder) const {
   // Target identification.
@@ -657,6 +663,8 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 getTargetDefinesARMV94A(Opts, Builder);
   else if (*ArchInfo == llvm::AArch64::ARMV9_5A)
 getTargetDefinesARMV95A(Opts, Builder);
+  else if (*ArchInfo == llvm::AArch64::ARMV9_6A)
+getTargetDefinesARMV96A(Opts, Builder);
 
   // All of the __sync_(bool|val)_compare_and_swap_(1|2|4|8|16) builtins work.
   Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
@@ -1044,6 +1052,9 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
 if (Feature == "+v9.5a" &&
 ArchInfo->Version < llvm::AArch64::ARMV9_5A.Version)
   ArchInfo = &llvm::AArch64::ARMV9_5A;
+if (Feature == "+v9.6a" &&
+ArchInfo->Version < llvm::AArch64::ARMV9_6A.Version)
+  ArchInfo = &llvm::AArch64::ARMV9_6A;
 if (Feature == "+v8r")
   ArchInfo = &llvm::AArch64::ARMV8R;
 if (Feature == "+fullfp16") {

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 526f7f30a38618..1226ce4d4355c2 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -148,6 +148,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
MacroBuilder &Builder) const;
   void getTargetDefinesARMV95A(const LangOptions &Opts,
MacroBuilder &Builder) const;
+  void getTargetDefinesARMV96A(const LangOptions &Opts,
+   MacroBuilder &Builder) const;
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override;
 

diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 7423626d7c3cbf..c56b8d9a448508 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -228,6 +228,8 @@ StringRef ARMTargetInfo::getCPUAttr() const {
 return "9_4A";
   case llvm::ARM::ArchKind::ARMV9_5A:
 return "9_5A";
+  case llvm::ARM::ArchKind::ARMV9_6A:
+return "9_6A";
   case llvm::ARM::ArchKind::ARMV8MBaseline:
 return "8M_BASE";
   case llvm::ARM::ArchKind::ARMV8MMainline:
@@ -891,6 +893,7 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   case llvm::ARM::ArchKind::ARMV9_3A:
   case llvm::ARM::ArchKind::ARMV9_4A:
   case llvm::ARM::ArchKind::ARMV9_5A:
+  case llvm

[clang] [llvm] [ARM][AArch64] Introduce the Armv9.6-A architecture version (PR #110825)

2024-10-04 Thread Jonathan Thackray via cfe-commits

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


[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

2024-10-04 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [llvm] [ARM][AArch64] Introduce the Armv9.6-A architecture version (PR #110825)

2024-10-04 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-arm-ubuntu` running 
on `linaro-lldb-arm-ubuntu` while building `clang,llvm` at step 6 "test".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/18/builds/4916


Here is the relevant piece of the build log for the reference

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: lang/cpp/exceptions/TestCPPExceptionBreakpoints.py (771 of 
2809)
PASS: lldb-api :: lang/cpp/dynamic-value/TestDynamicValue.py (772 of 2809)
PASS: lldb-api :: lang/cpp/enum_types/TestCPP11EnumTypes.py (773 of 2809)
PASS: lldb-api :: lang/cpp/extern_c/TestExternCSymbols.py (774 of 2809)
PASS: lldb-api :: 
lang/cpp/forward-declared-template-specialization/TestCppForwardDeclaredTemplateSpecialization.py
 (775 of 2809)
PASS: lldb-api :: lang/cpp/fixits/TestCppFixIts.py (776 of 2809)
PASS: lldb-api :: lang/cpp/fpnan/TestFPNaN.py (777 of 2809)
PASS: lldb-api :: 
lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py (778 of 2809)
PASS: lldb-api :: 
lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py (779 
of 2809)
PASS: lldb-api :: lang/cpp/function-local-class/TestCppFunctionLocalClass.py 
(780 of 2809)
FAIL: lldb-api :: 
lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py (781 of 2809)
 TEST 'lldb-api :: 
lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py' FAILED 

Script:
--
/usr/bin/python3.10 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py 
-u CXXFLAGS -u CFLAGS --env ARCHIVER=/usr/local/bin/llvm-ar --env 
OBJCOPY=/usr/bin/llvm-objcopy --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env 
LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch 
armv8l --build-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil 
--llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin 
--lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb 
--lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/lang/c/shared_lib_stripped_symbols
 -p TestSharedLibStrippedSymbols.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 
d0756caedcf067860240bf31e8f9d371ba706757)
  clang revision d0756caedcf067860240bf31e8f9d371ba706757
  llvm revision d0756caedcf067860240bf31e8f9d371ba706757
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']

--
Command Output (stderr):
--
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_expr_dsym (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase) (test 
case does not fall in any category of interest for this run) 
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_expr_dwarf (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_expr_dwo (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_frame_variable_dsym 
(TestSharedLibStrippedSymbols.SharedLibStrippedTestCase) (test case does not 
fall in any category of interest for this run) 
XFAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_frame_variable_dwarf 
(TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
XFAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_frame_variable_dwo (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
==
FAIL: test_expr_dwo (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
   Test that types work when defined in a shared library and forwa/d-declared 
in the main executable
--
Traceback (most recent call last):
  File 
"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py",
 line 1769, in test_method
return attrvalue(self)
  File 
"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/lang/c/shared_lib_stripped_symbols/T

[clang] [flang] [flang][driver] Make -stdlib= option visible to flang and silently ignored by it (PR #110598)

2024-10-04 Thread Michael Kruse via cfe-commits

Meinersbur wrote:

>From the summary?

> This has created a nowhere to go situation, the only remaining option is to 
> make the -stdlib flag visible to flang and silently ignored.

Can you clarify? I think it is not ignored, otherwise the test would fail since 
it requires linking to the `` implementation. It must add 
`-l(std)c++` to the linker command line.


> > (and there isn't even a warning that the option is unused)
> > @pawosm-arm Wasn't this ever an issue? Should those to be consistent?
> 
> Interesting, clang would do the same as flang-new patched with my patch. 
> Maybe addition of the warning would be a good idea, if it isn't an overkill.

AFAICS your patch only makes the `-stdlib` recognized by Flang. `lc++` being 
added must have been inherited from the C++ driver, but seemingly missing from 
the C driver path. 
A lot of flags are purposefully by the driver because build systems typically 
pass the same flags to every build phase which would otherwise cause errors 
([example](https://github.com/llvm/llvm-project/issues/88173)). A warning 
usually only annoys people that compile with `-werror`.

> what I've noticed is that using -DLLVM_ENABLE_LIBCXX=True CMake flag has 
> unexpected effect when it comes to C++/Fortran mixed code.

What effects?

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


[clang] [clang][analyzer] Check initialization and argument passing in FixedAddressChecker (PR #110977)

2024-10-04 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

> I was thinking about using `check::Location` in this checker. The real 
> problem is when the fixed address is used (to store or load), not if it is 
> assigned to a pointer. (Or a fixed address becomes escaped.)

I agree that a checker that activates when a fixed address is _dereferenced_ 
would be more useful overall. In fact before you started to work on this 
checker, I misread its code and thought that it already operates that way (like 
`core.NullDereference`)

By the way, be careful with `check::Location` because I vaguely recall that 
there are a few corner cases where it does not cover some sort of location 
access: 
https://discourse.llvm.org/t/checklocation-vs-checkbind-when-isload-false/72728/6
 . (Ask @steakhal if you need more details. At that point examination of this 
problem was interrupted because I converted `ArrayBoundV2` to using `PreStmt` 
callbacks (for unrelated reasons) -- but if you want to introduce 
`check::Location` here then it might be useful to revisit the issue.)

The current behavior of this checker is not entirely useless (I can imagine 
that perhaps somebody wants to enable it to enforce a design rule), but I don't 
think that it's relevant enough to preserve.

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


[clang] 3c98d8c - [OpenACC] Implement 'tile' loop count/tightly nested loop requirement (#111038)

2024-10-04 Thread via cfe-commits

Author: Erich Keane
Date: 2024-10-04T06:03:43-07:00
New Revision: 3c98d8c14612699444ac906729c9b2872190c938

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

LOG: [OpenACC] Implement 'tile' loop count/tightly nested loop requirement 
(#111038)

the 'tile' clause requires that it be followed by N (where N is the
number of size expressions) 'tightly nested loops'.  This means the
same as it does in 'collapse', so much of the implementation is
simliar/shared with that.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/SemaOpenACC.h
clang/lib/Sema/SemaOpenACC.cpp
clang/test/ParserOpenACC/parse-clauses.c
clang/test/SemaOpenACC/loop-construct-auto_seq_independent-clauses.c
clang/test/SemaOpenACC/loop-construct-device_type-clause.c
clang/test/SemaOpenACC/loop-construct-tile-clause.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 59dc81cfeb7111..583475327c5227 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12670,19 +12670,19 @@ def err_acc_size_expr_value
 : Error<
   "OpenACC 'tile' clause size expression must be %select{an asterisk "
   "or a constant expression|positive integer value, evaluated to 
%1}0">;
-def err_acc_invalid_in_collapse_loop
-: Error<"%select{OpenACC '%1' construct|while loop|do loop}0 cannot appear 
"
-"in intervening code of a 'loop' with a 'collapse' clause">;
-def note_acc_collapse_clause_here
-: Note<"active 'collapse' clause defined here">;
-def err_acc_collapse_multiple_loops
+def err_acc_invalid_in_loop
+: Error<"%select{OpenACC '%2' construct|while loop|do loop}0 cannot appear 
"
+"in intervening code of a 'loop' with a '%1' clause">;
+def note_acc_active_clause_here
+: Note<"active '%0' clause defined here">;
+def err_acc_clause_multiple_loops
 : Error<"more than one for-loop in a loop associated with OpenACC 'loop' "
-"construct with a 'collapse' clause">;
-def err_acc_collapse_insufficient_loops
-: Error<"'collapse' clause specifies a loop count greater than the number "
+"construct with a '%select{collapse|tile}0' clause">;
+def err_acc_insufficient_loops
+: Error<"'%0' clause specifies a loop count greater than the number "
 "of available loops">;
-def err_acc_collapse_intervening_code
-: Error<"inner loops must be tightly nested inside a 'collapse' clause on "
+def err_acc_intervening_code
+: Error<"inner loops must be tightly nested inside a '%0' clause on "
 "a 'loop' construct">;
 
 // AMDGCN builtins diagnostics

diff  --git a/clang/include/clang/Sema/SemaOpenACC.h 
b/clang/include/clang/Sema/SemaOpenACC.h
index d25c52ec3be43a..97386d2378b758 100644
--- a/clang/include/clang/Sema/SemaOpenACC.h
+++ b/clang/include/clang/Sema/SemaOpenACC.h
@@ -42,6 +42,23 @@ class SemaOpenACC : public SemaBase {
   /// above collection.
   bool InsideComputeConstruct = false;
 
+  /// Certain clauses care about the same things that aren't specific to the
+  /// individual clause, but can be shared by a few, so store them here. All
+  /// require a 'no intervening constructs' rule, so we know they are all from
+  /// the same 'place'.
+  struct LoopCheckingInfo {
+/// Records whether we've seen the top level 'for'. We already diagnose
+/// later that the 'top level' is a for loop, so we use this to suppress 
the
+/// 'collapse inner loop not a 'for' loop' diagnostic.
+LLVM_PREFERRED_TYPE(bool)
+unsigned TopLevelLoopSeen : 1;
+
+/// Records whether this 'tier' of the loop has already seen a 'for' loop,
+/// used to diagnose if there are multiple 'for' loops at any one level.
+LLVM_PREFERRED_TYPE(bool)
+unsigned CurLevelHasLoopAlready : 1;
+  } LoopInfo{/*TopLevelLoopSeen=*/false, /*CurLevelHasLoopAlready=*/false};
+
   /// The 'collapse' clause requires quite a bit of checking while
   /// parsing/instantiating its body, so this structure/object keeps all of the
   /// necessary information as we do checking.  This should rarely be directly
@@ -59,25 +76,27 @@ class SemaOpenACC : public SemaBase {
 /// else it should be 'N' minus the current depth traversed.
 std::optional CurCollapseCount;
 
-/// Records whether we've seen the top level 'for'. We already diagnose
-/// later that the 'top level' is a for loop, so we use this to suppress 
the
-/// 'collapse inner loop not a 'for' loop' diagnostic.
-LLVM_PREFERRED_TYPE(bool)
-unsigned TopLevelLoopSeen : 1;
-
-/// Records whether this 'tier' of the loop has already seen a 'for' loop,
-/// 

[clang] [OpenACC] Implement 'tile' loop count/tightly nested loop requirement (PR #111038)

2024-10-04 Thread Erich Keane via cfe-commits

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


[clang] [Clang][Sema] fix noexecpt mismatch of friend declaration (PR #102267)

2024-10-04 Thread Younan Zhang via cfe-commits


@@ -4698,7 +4698,22 @@ void Sema::InstantiateExceptionSpec(SourceLocation 
PointOfInstantiation,
   // Enter the scope of this instantiation. We don't use
   // PushDeclContext because we don't have a scope.
   Sema::ContextRAII savedContext(*this, Decl);
+
+  FunctionDecl *Source = Proto->getExtProtoInfo().ExceptionSpec.SourceTemplate;
+  FunctionTemplateDecl *SourceTemplate = 
Source->getDescribedFunctionTemplate();
+  llvm::SmallDenseMap InstTemplateParams;
+  if (CurrentInstantiationScope && SourceTemplate)
+if (TemplateParameterList *TPL = SourceTemplate->getTemplateParameters())
+  for (NamedDecl *TemplateParam : *TPL)
+if (auto *Found =
+CurrentInstantiationScope->findInstantiationOf(TemplateParam))
+  if (auto *InstTemplateParam = Found->dyn_cast())
+InstTemplateParams[TemplateParam] = InstTemplateParam;
+

zyn0217 wrote:

> ... including when checking constraints ...

This might not be the case for template parameters, as we (almost always, in my 
recollection) would have transformed the associated template parameters before 
calling the constraint matching function, so...

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


[clang] [Clang] Automatically enable `-fconvergent-functions` on GPU targets (PR #111076)

2024-10-04 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> > -fno-convergent-functions to opt-out if you want to test broken behavior.
> 
> You may legitimately know there are no convergent functions in the TU. We 
> also have the noconvergent source attribute now for this

Think it would be useful to put that on functions in the wrapper headers that 
definitely aren't convergent? E.g. getting a thread id.

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


[clang] 8d661fd - [analyzer] use `invalidateRegions()` in `VisitGCCAsmStmt` (#109838)

2024-10-04 Thread via cfe-commits

Author: Pavel Skripkin
Date: 2024-10-04T16:12:29+03:00
New Revision: 8d661fd9fd50fe4be9a9d5a8cc8f52f23925e7f6

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

LOG: [analyzer] use `invalidateRegions()` in `VisitGCCAsmStmt` (#109838)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/Analysis/asm.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index b1919d7027cf4d..43ab646d398b31 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3811,7 +3811,9 @@ void ExprEngine::VisitGCCAsmStmt(const GCCAsmStmt *A, 
ExplodedNode *Pred,
 assert(!isa(X)); // Should be an Lval, or unknown, undef.
 
 if (std::optional LV = X.getAs())
-  state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext());
+  state = state->invalidateRegions(*LV, A, currBldrCtx->blockCount(),
+   Pred->getLocationContext(),
+   /*CausedByPointerEscape=*/true);
   }
 
   // Do not reason about locations passed inside inline assembly.
@@ -3819,7 +3821,9 @@ void ExprEngine::VisitGCCAsmStmt(const GCCAsmStmt *A, 
ExplodedNode *Pred,
 SVal X = state->getSVal(I, Pred->getLocationContext());
 
 if (std::optional LV = X.getAs())
-  state = state->bindLoc(*LV, UnknownVal(), Pred->getLocationContext());
+  state = state->invalidateRegions(*LV, A, currBldrCtx->blockCount(),
+   Pred->getLocationContext(),
+   /*CausedByPointerEscape=*/true);
   }
 
   Bldr.generateNode(A, Pred, state);

diff  --git a/clang/test/Analysis/asm.cpp b/clang/test/Analysis/asm.cpp
index e0691dc4d794f5..a795400ebbcaf7 100644
--- a/clang/test/Analysis/asm.cpp
+++ b/clang/test/Analysis/asm.cpp
@@ -7,11 +7,10 @@ void clang_analyzer_dump_ptr(void *);
 
 int global;
 void testRValueOutput() {
-  int &ref = global;
-  ref = 1;
+  int origVal = global;
   __asm__("" : "=r"(((int)(global;  // don't crash on rvalue output operand
-  clang_analyzer_eval(global == 1); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(ref == 1);// expected-warning{{UNKNOWN}}
+  int newVal = global; // Value "after" the invalidation.
+  clang_analyzer_eval(origVal == newVal); // expected-warning{{TRUE}} 
expected-warning{{FALSE}}
 }
 
 void *MyMemcpy(void *d, const void *s, const int n) {
@@ -40,7 +39,20 @@ void testInlineAsmMemcpyUninit(void)
 {
 int a[10], b[10] = {}, c;
 MyMemcpy(&a[1], &b[1], sizeof(b) - sizeof(b[1]));
-c = a[0]; // expected-warning{{Assigned value is garbage or undefined}}
+c = a[0]; // FIXME: should be warning about uninitialized value, but 
invalidateRegions() also
+  // invalidates super region.
+}
+
+void testInlineAsmMemcpyUninitLoop(const void *src, unsigned long len)
+{
+int a[10], c;
+unsigned long toCopy = sizeof(a) < len ? sizeof(a) : len;
+
+MyMemcpy(a, src, toCopy);
+
+// Use index 1, since before use of invalidateRegions in VisitGCCAsmStmt, 
engine bound unknown SVal only to
+// first element.
+c = a[1]; // no-warning
 }
 
 void testAsmWithVoidPtrArgument()
@@ -49,6 +61,6 @@ void testAsmWithVoidPtrArgument()
   clang_analyzer_dump(*(int *)globalVoidPtr); // expected-warning-re 
{{reg_${{[0-9]+}}},0 S64b,int}>}}
   clang_analyzer_dump_ptr(globalVoidPtr); // expected-warning-re 
{{&SymRegion{reg_${{[0-9]+}
   asm ("" : : "a"(globalVoidPtr)); // no crash
-  clang_analyzer_dump(*(int *)globalVoidPtr); // expected-warning {{Unknown}}
+  clang_analyzer_dump(*(int *)globalVoidPtr); // expected-warning {{derived_}}
   clang_analyzer_dump_ptr(globalVoidPtr); // expected-warning-re 
{{&SymRegion{reg_${{[0-9]+}
 }



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


[clang] [analyzer] use `invalidateRegions()` in `VisitGCCAsmStmt` (PR #109838)

2024-10-04 Thread Pavel Skripkin via cfe-commits

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


[clang] [Clang] Automatically enable `-fconvergent-functions` on GPU targets (PR #111076)

2024-10-04 Thread Joseph Huber via cfe-commits

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


[clang] [Clang] Automatically enable `-fconvergent-functions` on GPU targets (PR #111076)

2024-10-04 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> Think it would be useful to put that on functions in the wrapper headers that 
> definitely aren't convergent? E.g. getting a thread id.

You could, but it's trivially inferable in those cases anyway 



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


[clang] [Clang][Sema] fix noexecpt mismatch of friend declaration (PR #102267)

2024-10-04 Thread Krystian Stasiowski via cfe-commits


@@ -4698,7 +4698,22 @@ void Sema::InstantiateExceptionSpec(SourceLocation 
PointOfInstantiation,
   // Enter the scope of this instantiation. We don't use
   // PushDeclContext because we don't have a scope.
   Sema::ContextRAII savedContext(*this, Decl);
+
+  FunctionDecl *Source = Proto->getExtProtoInfo().ExceptionSpec.SourceTemplate;
+  FunctionTemplateDecl *SourceTemplate = 
Source->getDescribedFunctionTemplate();
+  llvm::SmallDenseMap InstTemplateParams;
+  if (CurrentInstantiationScope && SourceTemplate)
+if (TemplateParameterList *TPL = SourceTemplate->getTemplateParameters())
+  for (NamedDecl *TemplateParam : *TPL)
+if (auto *Found =
+CurrentInstantiationScope->findInstantiationOf(TemplateParam))
+  if (auto *InstTemplateParam = Found->dyn_cast())
+InstTemplateParams[TemplateParam] = InstTemplateParam;
+

sdkrystian wrote:

Yeah, we should wait until I reland #106585 and then we can fix this. What we 
can then do is normalize the exception specification the same way we normalize 
constraints prior to comparing them.

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


[clang] [flang] [llvm] [openmp] [Clang][OpenMP] Add permutation clause (PR #92030)

2024-10-04 Thread Michael Kruse via cfe-commits

Meinersbur wrote:

@alexey-bataev Could you have another look?

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


[clang] [clang-tools-extra] [flang] [lld] [lldb] [llvm] [NFC] Rename Option parsing related files from OptXYZ -> OptionXYZ (PR #110692)

2024-10-04 Thread Rahul Joshi via cfe-commits

jurahul wrote:

@JDevlieghere @cyndyishida @topperc gentle ping. It's mostly mechanical.

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


[clang] [llvm] [IR] Allow fast math flags on calls with homogeneous FP struct types (PR #110506)

2024-10-04 Thread Benjamin Maxwell via cfe-commits

MacDue wrote:

> Hi,
> 
> I bisected a crash to this patch. I can't share the C reproducer but it's 
> instcombine that crashes and a reduced reproducer for that is
> ```opt -passes=instcombine bbi-99792.ll -o /dev/null```
> 
> [bbi-99792.ll.gz](https://github.com/user-attachments/files/17253640/bbi-99792.ll.gz)
> 

Thanks for reporting this, I'll have a look into the crash today 👍

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


[clang] [flang] [flang][driver] Make -stdlib= option visible to flang and silently ignored by it (PR #110598)

2024-10-04 Thread Andrzej Warzyński via cfe-commits

banach-space wrote:

We should avoid dummy flags like this - they are usually an indication of a 
larger issue. 

I don't want to block this and, as @Meinersbur points out, there are some 
"inherited issues" to consider too. However, I'd like to identify the right 
long-term solution here. If possible.

> I've specified the -stdlib=libc++ option globally, in the CXXFLAGS and 
> LDFLAGS variables

Why are CXXFLAGS used when invoking a Fortran compiler? That's not correct, is 
it? 

`LDFLAGS` would make sense, but then `-stdlib=` should be treated as a linker 
flag and `flang-new` as a linker driver. In fact, it sounds like `-stdlib=` 
could fall into some special category:
* valid when **compiling** C++,
* invalid when **compiling** Fortran,
* valid when **linking** mixed C++ and Fortran object files.

To me it sounds like:
*  flags from `CXXFLAGS` should not be used in Fortran _compilation_ flows,
* `-stdlib=` should be flagged as a linker option (that seems to be missing?),
* `flang-new` should allow/ignore "linker" flags that are not "visible" in 
Fortran _compilation_ flows (as in, the "Visibility" logic could be tweaked).

If `-stdlib=` were to be made available in Fortran compilation, the help-text 
should be updated accordingly. 

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


  1   2   3   4   >