[clang] [clang] Implement `__is_virtual_base_of()` intrinsic (PR #100393)

2024-07-26 Thread via cfe-commits

cor3ntin wrote:

The CI issues are unrelated so I'll merge this (someone should investigate why 
`clang-doc` tests are still failing though @PeterChou1. Thanks)

@Endilll Thanks for the patch :)

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


[clang] 988fd95 - [clang] Implement `__builtin_is_virtual_base_of()` intrinsic (#100393)

2024-07-26 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-07-26T09:09:54+02:00
New Revision: 988fd956e776bad8057a8b7ee051a524308c097b

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

LOG: [clang] Implement `__builtin_is_virtual_base_of()` intrinsic (#100393)

This patch adds compiler support for
[P2985R0](https://wg21.link/p2985r0) "A type trait for detecting virtual
base classes".
Like we recently did with `__is_layout_compatible()` and
`__is_pointer_interconvertible_base_of()`, we support it only in C++
mode, and reject VLAs.

Resolves #98310.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/TokenKinds.def
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 81784c75081ba..a747464582e77 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1546,6 +1546,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__array_extent(type, dim)`` (Embarcadero):
   The ``dim``'th array bound in the type ``type``, or ``0`` if
   ``dim >= __array_rank(type)``.
+* ``__builtin_is_virtual_base_of`` (C++, GNU, Microsoft)
 * ``__can_pass_in_regs`` (C++)
   Returns whether a class can be passed in registers under the current
   ABI. This type can only be applied to unqualified class types.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 58f1c5af5..b165f6e65636d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -81,6 +81,9 @@ C++23 Feature Support
 C++2c Feature Support
 ^
 
+- Add ``__builtin_is_virtual_base_of`` intrinsic, which supports
+  `P2985R0 A type trait for detecting virtual base classes 
`_
+
 Resolutions to C++ Defect Reports
 ^
 

diff  --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 8c54661e65cf4..7e638dc1ddcdb 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -501,6 +501,7 @@ TYPE_TRAIT_1(__has_trivial_move_assign, 
HasTrivialMoveAssign, KEYCXX)
 TYPE_TRAIT_1(__has_trivial_move_constructor, HasTrivialMoveConstructor, KEYCXX)
 
 // GNU and MS Type Traits
+TYPE_TRAIT_2(__builtin_is_virtual_base_of, IsVirtualBaseOf, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_assign, HasNothrowAssign, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_copy, HasNothrowCopy, KEYCXX)
 TYPE_TRAIT_1(__has_nothrow_constructor, HasNothrowConstructor, KEYCXX)

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 51c4a36808fce..029969c1722b7 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6030,6 +6030,32 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
 return cast(rhsRecord->getDecl())
   ->isDerivedFrom(cast(lhsRecord->getDecl()));
   }
+  case BTT_IsVirtualBaseOf: {
+const RecordType *BaseRecord = LhsT->getAs();
+const RecordType *DerivedRecord = RhsT->getAs();
+
+if (!BaseRecord || !DerivedRecord) {
+  DiagnoseVLAInCXXTypeTrait(Self, Lhs,
+tok::kw___builtin_is_virtual_base_of);
+  DiagnoseVLAInCXXTypeTrait(Self, Rhs,
+tok::kw___builtin_is_virtual_base_of);
+  return false;
+}
+
+if (BaseRecord->isUnionType() || DerivedRecord->isUnionType())
+  return false;
+
+if (!BaseRecord->isStructureOrClassType() ||
+!DerivedRecord->isStructureOrClassType())
+  return false;
+
+if (Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
+ diag::err_incomplete_type))
+  return false;
+
+return cast(DerivedRecord->getDecl())
+->isVirtuallyDerivedFrom(cast(BaseRecord->getDecl()));
+  }
   case BTT_IsSame:
 return Self.Context.hasSameType(LhsT, RhsT);
   case BTT_TypeCompatible: {

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 23b07cac13eaf..e131212bb1071 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -2402,11 +2402,11 @@ template struct DerivedB : BaseA { };
 template struct CrazyDerived : T { };
 
 
-class class_forward; // expected-note 2 {{forward declaration of 
'class_forward'}}
+class class_forward; // expected-note 4 {{forward declaration of 
'class_forward'}}
 
 template  class DerivedTemp : Base {};
 template  class NonderivedTemp {};
-template  class UndefinedTemp; // expected-note {{declared here}}
+template  class UndefinedTemp; // expected-note 2 {{declared here}}
 
 

[clang] [clang] Implement `__is_virtual_base_of()` intrinsic (PR #100393)

2024-07-26 Thread via cfe-commits

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


[clang] [clang][FMV][AArch64] Improve streaming mode compatibility. (PR #100181)

2024-07-26 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm approved this pull request.

Thanks for addressing the feedback @labrinea, LGTM!

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


[clang] [Clang] Use private address space for builtin_alloca return type for OpenCL (PR #95750)

2024-07-26 Thread Vikash Gupta via cfe-commits

https://github.com/vg0204 updated 
https://github.com/llvm/llvm-project/pull/95750

>From ac967e4f887bd511bdfcaf30a0c94aa083cbf980 Mon Sep 17 00:00:00 2001
From: vg0204 
Date: Mon, 17 Jun 2024 11:20:02 +0530
Subject: [PATCH 1/9] [Clang] Use private address space for builtin_alloca for
 OpenCL

The __builtin_alloca was returning a flat pointer with no address
space when compiled using openCL1.2 or below but worked fine with
openCL2.0 and above. This accounts to the fact that later uses the
concept of generic address space which supports cast to other address
space(i.e to private address space which is used for stack allocation)
.

So, in general for OpenCL, built_alloca should always return pointer
to private address space, thus eliminating need of use of address
space cast. Thus,it requires redefintion of the builtin function with
return pointer type to private address space.
---
 clang/lib/Sema/SemaExpr.cpp | 23 +-
 clang/test/CodeGenOpenCL/builtins-alloca.cl | 86 +
 clang/test/CodeGenOpenCL/memcpy.cl  |  0
 3 files changed, 106 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenOpenCL/builtins-alloca.cl
 mode change 100644 => 100755 clang/test/CodeGenOpenCL/memcpy.cl

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8d24e34520e77..cf4c98fbe2c38 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6121,7 +6121,10 @@ bool Sema::CheckArgsForPlaceholders(MultiExprArg args) {
 ///  it does not contain any pointer arguments without
 ///  an address space qualifer.  Otherwise the rewritten
 ///  FunctionDecl is returned.
-/// TODO: Handle pointer return types.
+///
+/// Pointer return type with no explicit address space is assigned the
+/// default address space where pointer points to based on the language
+/// option used to compile it.
 static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext 
&Context,
 FunctionDecl *FDecl,
 MultiExprArg ArgExprs) {
@@ -6165,13 +6168,27 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema 
*Sema, ASTContext &Context,
 OverloadParams.push_back(Context.getPointerType(PointeeType));
   }
 
+  QualType ReturnTy = FT->getReturnType();
+  QualType OverloadReturnTy = ReturnTy;
+  if (ReturnTy->isPointerType() &&
+  !ReturnTy->getPointeeType().hasAddressSpace()) {
+if (Sema->getLangOpts().OpenCL) {
+  NeedsNewDecl = true;
+
+  QualType ReturnPtTy = ReturnTy->getPointeeType();
+  LangAS defClAS = Context.getDefaultOpenCLPointeeAddrSpace();
+  ReturnPtTy = Context.getAddrSpaceQualType(ReturnPtTy, defClAS);
+  OverloadReturnTy = Context.getPointerType(ReturnPtTy);
+}
+  }
+
   if (!NeedsNewDecl)
 return nullptr;
 
   FunctionProtoType::ExtProtoInfo EPI;
   EPI.Variadic = FT->isVariadic();
-  QualType OverloadTy = Context.getFunctionType(FT->getReturnType(),
-OverloadParams, EPI);
+  QualType OverloadTy =
+  Context.getFunctionType(OverloadReturnTy, OverloadParams, EPI);
   DeclContext *Parent = FDecl->getParent();
   FunctionDecl *OverloadDecl = FunctionDecl::Create(
   Context, Parent, FDecl->getLocation(), FDecl->getLocation(),
diff --git a/clang/test/CodeGenOpenCL/builtins-alloca.cl 
b/clang/test/CodeGenOpenCL/builtins-alloca.cl
new file mode 100644
index 0..74a86955f2e4f
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-alloca.cl
@@ -0,0 +1,86 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL1.2 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL12 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL20 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL30 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 
-cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck 
--check-prefix=OPENCL30-EXT %s
+
+// OPENCL12-LABEL: define dso_local ptr addrspace(5) @test1(
+// OPENCL12-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL12-NEXT:  [[ENTRY:.*:]]
+// OPENCL12-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL12-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL12-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:ret ptr addrspace(5) [[TMP1]]
+//
+// OPENCL20-LABEL: define dso_local ptr @test1(
+// OPENCL20-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL20-NEXT:  [[ENTRY:.*:]]
+// OPENCL20-NEXT:[[ALLOC_PTR:%.*]] = alloca 

[clang-tools-extra] ed1c67b - Add a description parameter to the add_new_check script (#100111)

2024-07-26 Thread via cfe-commits

Author: Nathan James
Date: 2024-07-26T08:16:08+01:00
New Revision: ed1c67b129bdb4343a147e1d72968e7d1f0cd1cf

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

LOG: Add a description parameter to the add_new_check script (#100111)

Adds a description parameter that automatically fills in the Release
notes and first line of the checks documentation. If omitted the usually
FIXME markers are left in their place.

Added: 


Modified: 
clang-tools-extra/clang-tidy/add_new_check.py

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index 3a62df1f510ba..1ce2019ee33fe 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -16,6 +16,7 @@
 import os
 import re
 import sys
+import textwrap
 
 # Adapts the module's CMakelist file. Returns 'True' if it could add a new
 # entry and 'False' if the entry already existed.
@@ -53,7 +54,14 @@ def adapt_cmake(module_path, check_name_camel):
 
 
 # Adds a header for the new check.
-def write_header(module_path, module, namespace, check_name, check_name_camel):
+def write_header(
+module_path, module, namespace, check_name, check_name_camel, description
+):
+wrapped_desc = "\n".join(
+textwrap.wrap(
+description, width=80, initial_indent="/// ", 
subsequent_indent="/// "
+)
+)
 filename = os.path.join(module_path, check_name_camel) + ".h"
 print("Creating %s..." % filename)
 with io.open(filename, "w", encoding="utf8", newline="\n") as f:
@@ -85,7 +93,7 @@ def write_header(module_path, module, namespace, check_name, 
check_name_camel):
 
 namespace clang::tidy::%(namespace)s {
 
-/// FIXME: Write a short description.
+%(description)s
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/%(module)s/%(check_name)s.html
@@ -107,6 +115,7 @@ class %(check_name_camel)s : public ClangTidyCheck {
 "check_name": check_name,
 "module": module,
 "namespace": namespace,
+"description": wrapped_desc,
 }
 )
 
@@ -235,7 +244,12 @@ def adapt_module(module_path, module, check_name, 
check_name_camel):
 
 
 # Adds a release notes entry.
-def add_release_notes(module_path, module, check_name):
+def add_release_notes(module_path, module, check_name, description):
+wrapped_desc = "\n".join(
+textwrap.wrap(
+description, width=80, initial_indent="  ", subsequent_indent="  "
+)
+)
 check_name_dashes = module + "-" + check_name
 filename = os.path.normpath(
 os.path.join(module_path, "../../docs/ReleaseNotes.rst")
@@ -281,10 +295,10 @@ def add_release_notes(module_path, module, check_name):
 """- New :doc:`%s
   ` check.
 
-  FIXME: add release notes.
+%s
 
 """
-% (check_name_dashes, module, check_name)
+% (check_name_dashes, module, check_name, 
wrapped_desc)
 )
 note_added = True
 
@@ -612,6 +626,13 @@ def main():
 default="c++",
 metavar="LANG",
 )
+parser.add_argument(
+"--description",
+"-d",
+help="short description of what the check does",
+default="FIXME: Write a short description",
+type=str,
+)
 parser.add_argument(
 "module",
 nargs="?",
@@ -652,10 +673,16 @@ def main():
 else:
 namespace = module
 
-write_header(module_path, module, namespace, check_name, check_name_camel)
+description = args.description
+if not description.endswith("."):
+description += "."
+
+write_header(
+module_path, module, namespace, check_name, check_name_camel, 
description
+)
 write_implementation(module_path, module, namespace, check_name_camel)
 adapt_module(module_path, module, check_name, check_name_camel)
-add_release_notes(module_path, module, check_name)
+add_release_notes(module_path, module, check_name, description)
 test_extension = language_to_extension.get(args.language)
 write_test(module_path, module, check_name, test_extension)
 write_docs(module_path, module, check_name)



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


[clang-tools-extra] Add a description parameter to the add_new_check script (PR #100111)

2024-07-26 Thread Nathan James via cfe-commits

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


[clang] Fix #99858 (PR #99859)

2024-07-26 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

My impression is that in this case, the Decl is supposed to be instantiated 
here, so in valid code, a instantiation would be found, so strictly speaking 
the null check would not be the right thing.

But we do have cases where we don't instantiate in case the Decl is invalid.
In that case, the right thing to do would be to guard on an `!isInvalidDecl()` 
check.

Can you double check you are seeing an Invalid declaration here?

For example,

```
assert(!ParmPack.first.get()->isInvalidDecl());
```

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


[clang] [clang] Enable the -Wdangling-assignment-gsl diagnostic by default. (PR #100708)

2024-07-26 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/100708

None

>From 69670cf28f04d82adde27be86af6b8ce40e7a01c Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 26 Jul 2024 09:17:50 +0200
Subject: [PATCH] [clang] Enable the -Wdangling-assignment-gsl diagnostic by
 default.

---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 58f1c5af5..bba03f8d3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -130,6 +130,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses undefined behavior in constant expressions more 
consistently. This includes invalid shifts, and signed overflow in arithmetic.
 
+- -Wdangling-assignment-gsl is enabled by default.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 810abe4f23e31..50211a6ab5186 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10133,7 +10133,7 @@ def warn_dangling_lifetime_pointer : Warning<
   InGroup;
 def warn_dangling_lifetime_pointer_assignment : Warning<"object backing the "
   "pointer %0 will be destroyed at the end of the full-expression">,
-  InGroup, DefaultIgnore;
+  InGroup;
 def warn_new_dangling_initializer_list : Warning<
   "array backing "
   "%select{initializer list subobject of the allocated object|"

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


[clang] [clang] Enable the -Wdangling-assignment-gsl diagnostic by default. (PR #100708)

2024-07-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes



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


2 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 58f1c5af5..bba03f8d3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -130,6 +130,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses undefined behavior in constant expressions more 
consistently. This includes invalid shifts, and signed overflow in arithmetic.
 
+- -Wdangling-assignment-gsl is enabled by default.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 810abe4f23e31..50211a6ab5186 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10133,7 +10133,7 @@ def warn_dangling_lifetime_pointer : Warning<
   InGroup;
 def warn_dangling_lifetime_pointer_assignment : Warning<"object backing the "
   "pointer %0 will be destroyed at the end of the full-expression">,
-  InGroup, DefaultIgnore;
+  InGroup;
 def warn_new_dangling_initializer_list : Warning<
   "array backing "
   "%select{initializer list subobject of the allocated object|"

``




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


[clang] 9482a83 - [PS5][Driver] Ensure stack sizes are emitted by LTO (#100592)

2024-07-26 Thread via cfe-commits

Author: Edd Dawson
Date: 2024-07-26T08:21:42+01:00
New Revision: 9482a8385b94f2c32379fb0b946516ff54261b32

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

LOG: [PS5][Driver] Ensure stack sizes are emitted by LTO (#100592)

... when requested.

Upstreaming a private patch.

SIE tracker: TOOLCHAIN-16575

Added: 


Modified: 
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/test/Driver/stack-size-section.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 813a0fbedd2b1..f883f29f0c8ca 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -266,6 +266,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (UseJMC)
 AddLTOFlag("-enable-jmc-instrument");
 
+  if (Args.hasFlag(options::OPT_fstack_size_section,
+   options::OPT_fno_stack_size_section, false))
+AddLTOFlag("-stack-size-section");
+
   if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
 AddLTOFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
 

diff  --git a/clang/test/Driver/stack-size-section.c 
b/clang/test/Driver/stack-size-section.c
index 71b9f85692b99..7cd41e491a817 100644
--- a/clang/test/Driver/stack-size-section.c
+++ b/clang/test/Driver/stack-size-section.c
@@ -14,6 +14,7 @@
 
 // RUN: %clang -### --target=x86_64-linux-gnu -flto -fstack-size-section %s 
2>&1 | FileCheck %s --check-prefix=LTO
 // RUN: %clang -### --target=x86_64-linux-gnu -flto -fstack-size-section 
-fno-stack-size-section %s 2>&1 | FileCheck %s --check-prefix=LTO-NO
+// RUN: %clang -### --target=x86_64-sie-ps5 -fstack-size-section %s 2>&1 | 
FileCheck %s --check-prefix=LTO
 
 // LTO: "-plugin-opt=-stack-size-section"
 // LTO-NO-NOT: "-plugin-opt=-stack-size-section"



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


[clang] [PS5][Driver] Ensure stack sizes are emitted by LTO (PR #100592)

2024-07-26 Thread Edd Dawson via cfe-commits

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


[clang] [clang] [SemaCXX] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-07-26 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/78112

>From 92f8720e3d21521b589d5291f086a2f32b87bfe0 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 14 Jan 2024 19:52:31 +
Subject: [PATCH 01/10] [clang] [SemaCXX] Implement CWG2627 Bit-fields and
 narrowing conversions

---
 clang/docs/ReleaseNotes.rst   |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Overload.h   |   7 +-
 clang/lib/Sema/SemaExpr.cpp   |  10 +-
 clang/lib/Sema/SemaInit.cpp   |  20 ++-
 clang/lib/Sema/SemaOverload.cpp   | 119 +--
 .../dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp |  24 
 clang/test/CXX/drs/dr26xx.cpp | 136 ++
 clang/www/cxx_dr_status.html  |   2 +-
 9 files changed, 278 insertions(+), 48 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 92563262cc673..28202fc604e29 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,11 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- Casts from a bit-field to an integral type is now not considered narrowing 
if the
+  width of the bit-field means that all potential values are in the range
+  of the target type, even if the type of the bit-field is larger.
+  (`CWG2627. Bit-fields and narrowing conversions  
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdca82934cb4d..6cdb439be30ae 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6253,6 +6253,9 @@ def ext_init_list_variable_narrowing_const_reference : 
ExtWarn<
 def ext_init_list_constant_narrowing : ExtWarn<
   "constant expression evaluates to %0 which cannot be narrowed to type %1">,
   InGroup, DefaultError, SFINAEFailure;
+def ext_bit_field_narrowing : Extension<
+  "narrowing non-constant-expression from %0 bit-field of width %2 to %1 is a 
C++23 extension">,
+  InGroup, SFINAEFailure;
 def ext_init_list_constant_narrowing_const_reference : ExtWarn<
   ext_init_list_constant_narrowing.Summary>,
   InGroup, DefaultError, SFINAEFailure;
diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 76311b00d2fc5..0d94045cc13f7 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -244,7 +244,11 @@ class Sema;
 /// Not a narrowing conversion.
 NK_Not_Narrowing,
 
-/// A narrowing conversion by virtue of the source and destination types.
+/// Not a narrowing conversion in C++23 because the source is a bit-field
+/// whose range can fit in the target type
+NK_BitField_Not_Narrowing,
+
+/// A narrowing conversion by virtue of the source and target types.
 NK_Type_Narrowing,
 
 /// A narrowing conversion, because a constant expression got narrowed.
@@ -387,6 +391,7 @@ class Sema;
 NarrowingKind
 getNarrowingKind(ASTContext &Context, const Expr *Converted,
  APValue &ConstantValue, QualType &ConstantType,
+ unsigned &BitFieldWidth,
  bool IgnoreFloatToIntegralConversion = false) const;
 bool isPointerConversionToBool() const;
 bool isPointerConversionToVoidPointer(ASTContext& Context) const;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 50f92c496a539..4c16fcc60fc77 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -12361,8 +12361,9 @@ static bool checkThreeWayNarrowingConversion(Sema &S, 
QualType ToType, Expr *E,
 
   APValue PreNarrowingValue;
   QualType PreNarrowingType;
+  unsigned BitFieldWidth;
   switch (SCS.getNarrowingKind(S.Context, E, PreNarrowingValue,
-   PreNarrowingType,
+   PreNarrowingType, BitFieldWidth,
/*IgnoreFloatToIntegralConversion*/ true)) {
   case NK_Dependent_Narrowing:
 // Implicit conversion to a narrower type, but the expression is
@@ -12370,6 +12371,13 @@ static bool checkThreeWayNarrowingConversion(Sema &S, 
QualType ToType, Expr *E,
   case NK_Not_Narrowing:
 return false;
 
+  case NK_BitField_Not_Narrowing:
+if (!S.getLangOpts().CPlusPlus23) {
+  return S.Diag(E->getBeginLoc(), diag::ext_bit_field_narrowing)
+ << FromType << ToType << BitFieldWidth;
+}
+return false;
+
   case NK_Constant_Narrowing:
 // Implicit conversion to a narrower type, and the value is not a constant
 // expression.
diff --git a/cl

[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-07-26 Thread Mital Ashok via cfe-commits

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


[clang] [clang] Enable the -Wdangling-assignment-gsl diagnostic by default. (PR #100708)

2024-07-26 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

LGTM!

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


[clang] [clang] Implement CWG2627 Bit-fields and narrowing conversions (PR #78112)

2024-07-26 Thread Mital Ashok via cfe-commits

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


[clang] [clang] Implement CWG2851: floating-point conversions in converted constant expressions (PR #90387)

2024-07-26 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/90387

>From 77cb28e6faf95f5beb3fadc225cb5f0525b3dfe6 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 28 Apr 2024 09:48:47 +0100
Subject: [PATCH 1/3] [clang] Implement CWG2851: floating-point conversions in
 converted constant expressions

---
 clang/docs/ReleaseNotes.rst   |  3 +
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/Sema/SemaOverload.cpp   | 38 ++-
 clang/test/CXX/drs/dr28xx.cpp | 64 +++
 clang/www/cxx_dr_status.html  |  2 +-
 5 files changed, 107 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 604782ca43dd5..6fb0b2d1030be 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -166,6 +166,9 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- Allow floating-point promotions and conversions in converted constant 
expressions.
+  (`CWG2851 Allow floating-point conversions in converted constant expressions 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdca82934cb4d..cb248f2ea6374 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -85,6 +85,10 @@ def err_expr_not_cce : Error<
   "%select{case value|enumerator value|non-type template argument|"
   "array size|explicit specifier argument|noexcept specifier argument|"
   "call to 'size()'|call to 'data()'}0 is not a constant expression">;
+def err_float_conv_cant_represent : Error<
+  "non-type template argument evaluates to %0 which cannot be "
+  "exactly represented in type %1"
+>;
 def ext_cce_narrowing : ExtWarn<
   "%select{case value|enumerator value|non-type template argument|"
   "array size|explicit specifier argument|noexcept specifier argument|"
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 04cd9e78739d2..40d65638e3afc 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6072,6 +6072,10 @@ static bool CheckConvertedConstantConversions(Sema &S,
   case ICK_Integral_Promotion:
   case ICK_Integral_Conversion: // Narrowing conversions are checked elsewhere.
   case ICK_Zero_Queue_Conversion:
+  // Per CWG2851, floating-point promotions and conversions are allowed.
+  // The value of a conversion is checked afterwards.
+  case ICK_Floating_Promotion:
+  case ICK_Floating_Conversion:
 return true;
 
   case ICK_Boolean_Conversion:
@@ -6091,9 +6095,7 @@ static bool CheckConvertedConstantConversions(Sema &S,
 // only permitted if the source type is std::nullptr_t.
 return SCS.getFromType()->isNullPtrType();
 
-  case ICK_Floating_Promotion:
   case ICK_Complex_Promotion:
-  case ICK_Floating_Conversion:
   case ICK_Complex_Conversion:
   case ICK_Floating_Integral:
   case ICK_Compatible_Conversion:
@@ -6229,7 +6231,37 @@ static ExprResult BuildConvertedConstantExpression(Sema 
&S, Expr *From,
   if (Result.isInvalid())
 return Result;
 
-  // Check for a narrowing implicit conversion.
+  if (SCS->Second == ICK_Floating_Conversion) {
+// Unlike with narrowing conversions, the value must fit
+// exactly even if it is in range
+assert(CCE == Sema::CCEKind::CCEK_TemplateArg &&
+   "Only non-type template args should use floating-point 
conversions");
+
+// Initializer is From, except it is a full-expression
+const Expr *Initializer =
+IgnoreNarrowingConversion(S.Context, Result.get());
+
+// If it's value-dependent, we can't tell whether it will fit
+if (Initializer->isValueDependent())
+  return Result;
+
+// Not-constant diagnosed afterwards
+if (!Initializer->isCXX11ConstantExpr(S.Context, &PreNarrowingValue))
+  return Result;
+
+llvm::APFloat PostNarrowingValue = PreNarrowingValue.getFloat();
+bool LosesInfo = true;
+PostNarrowingValue.convert(S.Context.getFloatTypeSemantics(T),
+   llvm::APFloat::rmNearestTiesToEven, &LosesInfo);
+
+if (LosesInfo)
+  S.Diag(From->getBeginLoc(), diag::err_float_conv_cant_represent)
+  << PreNarrowingValue.getAsString(S.Context, From->getType()) << T;
+
+return Result;
+  }
+
+  // Check for a narrowing integer conversion.
   bool ReturnPreNarrowingValue = false;
   QualType PreNarrowingType;
   switch (SCS->getNarrowingKind(S.Context, Result.get(), PreNarrowingValue,
diff --git a/clang/test/CXX/drs/dr28xx.cpp b/clang/test/CXX/drs/dr28xx.cpp
index be35d366bdd61..9076598da1418 100644
--- a/clang/te

[clang] [clang][Driver] Support passing arbitrary args to -cc1as with -Xclangas. (PR #100714)

2024-07-26 Thread Alex Rønne Petersen via cfe-commits

https://github.com/alexrp created 
https://github.com/llvm/llvm-project/pull/100714

This is one of the ideas I gave in #97517. I opted to propose this one first as 
introducing a new `-Xclangas` option comes with no concerns about GCC 
compatibility as with `-Xassembler`.

I am not sure where would be an appropriate place to test this, or how it would 
make sense to do so. I would appreciate any guidance on this. I tested manually 
like this:

```console
❯ ./bin/clang -target arm-linux-gnueabi -c test.s
test.s:1:1: error: instruction requires: armv5t
blx lr
^
❯ make -j
❯ ./bin/clang -target arm-linux-gnueabi -c test.s -Xclangas -target-feature 
-Xclangas +v5t
❯ file test.o
test.o: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), not stripped
```

From c1da400d71a9b479e012362cb581b5fd7c95bfbe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= 
Date: Fri, 26 Jul 2024 09:40:42 +0200
Subject: [PATCH] [clang][Driver] Support passing arbitrary args to -cc1as with
 -Xclangas.

Closes #97517.
---
 clang/docs/UsersManual.rst| 1 +
 clang/include/clang/Driver/Options.td | 8 
 clang/lib/Driver/ToolChains/Clang.cpp | 6 ++
 3 files changed, 15 insertions(+)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index e9b95739ea2ab..7f55080321fea 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -4876,6 +4876,7 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   -v  Show commands to run and use verbose output
   -W Enable the specified warning
   -XclangPass  to the clang compiler
+  -Xclangas  Pass  to the clang assembler
 
 The /clang: Option
 ^^
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 26811bf948ae5..c7839c3941eb9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1028,10 +1028,18 @@ def Xclang : Separate<["-"], "Xclang">,
   HelpText<"Pass  to clang -cc1">, MetaVarName<"">,
   Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
   Group;
+def Xclangas : Separate<["-"], "Xclangas">,
+  HelpText<"Pass  to clang -cc1as">, MetaVarName<"">,
+  Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
+  Group;
 def : Joined<["-"], "Xclang=">, Group,
   Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias,
   HelpText<"Alias for -Xclang">, MetaVarName<"">;
+def : Joined<["-"], "Xclangas=">, Group,
+  Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
+  Alias,
+  HelpText<"Alias for -Xclangas">, MetaVarName<"">;
 def Xcuda_fatbinary : Separate<["-"], "Xcuda-fatbinary">,
   HelpText<"Pass  to fatbinary invocation">, MetaVarName<"">;
 def Xcuda_ptxas : Separate<["-"], "Xcuda-ptxas">,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 4a94df7d5f42e..90b8db11c46c6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8711,6 +8711,12 @@ void ClangAs::ConstructJob(Compilation &C, const 
JobAction &JA,
   CollectArgsForIntegratedAssembler(C, Args, CmdArgs,
 getToolChain().getDriver());
 
+  // Forward -Xclangas arguments to -cc1as
+  for (auto Arg : Args.filtered(options::OPT_Xclangas)) {
+Arg->claim();
+CmdArgs.push_back(Arg->getValue());
+  }
+
   Args.AddAllArgs(CmdArgs, options::OPT_mllvm);
 
   if (DebugInfoKind > llvm::codegenoptions::NoDebugInfo && Output.isFilename())

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


[clang] [clang][Driver] Support passing arbitrary args to -cc1as with -Xclangas. (PR #100714)

2024-07-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Alex Rønne Petersen (alexrp)


Changes

This is one of the ideas I gave in #97517. I opted to propose this one 
first as introducing a new `-Xclangas` option comes with no concerns about GCC 
compatibility as with `-Xassembler`.

I am not sure where would be an appropriate place to test this, or how it would 
make sense to do so. I would appreciate any guidance on this. I tested manually 
like this:

```console
❯ ./bin/clang -target arm-linux-gnueabi -c test.s
test.s:1:1: error: instruction requires: armv5t
blx lr
^
❯ make -j
❯ ./bin/clang -target arm-linux-gnueabi -c test.s -Xclangas -target-feature 
-Xclangas +v5t
❯ file test.o
test.o: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), not stripped
```

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


3 Files Affected:

- (modified) clang/docs/UsersManual.rst (+1) 
- (modified) clang/include/clang/Driver/Options.td (+8) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+6) 


``diff
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index e9b95739ea2ab..7f55080321fea 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -4876,6 +4876,7 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   -v  Show commands to run and use verbose output
   -W Enable the specified warning
   -XclangPass  to the clang compiler
+  -Xclangas  Pass  to the clang assembler
 
 The /clang: Option
 ^^
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 26811bf948ae5..c7839c3941eb9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1028,10 +1028,18 @@ def Xclang : Separate<["-"], "Xclang">,
   HelpText<"Pass  to clang -cc1">, MetaVarName<"">,
   Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
   Group;
+def Xclangas : Separate<["-"], "Xclangas">,
+  HelpText<"Pass  to clang -cc1as">, MetaVarName<"">,
+  Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
+  Group;
 def : Joined<["-"], "Xclang=">, Group,
   Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
   Alias,
   HelpText<"Alias for -Xclang">, MetaVarName<"">;
+def : Joined<["-"], "Xclangas=">, Group,
+  Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
+  Alias,
+  HelpText<"Alias for -Xclangas">, MetaVarName<"">;
 def Xcuda_fatbinary : Separate<["-"], "Xcuda-fatbinary">,
   HelpText<"Pass  to fatbinary invocation">, MetaVarName<"">;
 def Xcuda_ptxas : Separate<["-"], "Xcuda-ptxas">,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 4a94df7d5f42e..90b8db11c46c6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8711,6 +8711,12 @@ void ClangAs::ConstructJob(Compilation &C, const 
JobAction &JA,
   CollectArgsForIntegratedAssembler(C, Args, CmdArgs,
 getToolChain().getDriver());
 
+  // Forward -Xclangas arguments to -cc1as
+  for (auto Arg : Args.filtered(options::OPT_Xclangas)) {
+Arg->claim();
+CmdArgs.push_back(Arg->getValue());
+  }
+
   Args.AddAllArgs(CmdArgs, options::OPT_mllvm);
 
   if (DebugInfoKind > llvm::codegenoptions::NoDebugInfo && Output.isFilename())

``




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


[clang] [flang] [Flang-new][OpenMP] Add bitcode files for AMD GPU OpenMP (PR #96742)

2024-07-26 Thread Dominik Adamski via cfe-commits

https://github.com/DominikAdamski updated 
https://github.com/llvm/llvm-project/pull/96742

>From 5b487aac3c8414b6f37f6888f361ca7488094048 Mon Sep 17 00:00:00 2001
From: Dominik Adamski 
Date: Fri, 21 Jun 2024 18:03:53 +0200
Subject: [PATCH 1/5] [Flang-new][OpenMP] Add offload related flags for AMDGPU

Flang-new needs to add mlink-builtin-bitcode objects
to properly support offload code generation for AMD GPU.

fcuda-is-device flag is not used by Flang currently.
In the future it will be needed for Flang equivalent function:
AMDGPUTargetCodeGenInfo::getGlobalVarAddressSpace.
---
 clang/include/clang/Driver/Options.td |  4 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  3 ++
 flang/test/Driver/omp-driver-offload.f90  | 58 +--
 flang/test/Driver/target-cpu-features.f90 |  4 +-
 flang/test/Driver/target-gpu-features.f90 |  2 +-
 5 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index dd55838dcf384..612d5793232ce 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8016,7 +8016,7 @@ def source_date_epoch : Separate<["-"], 
"source-date-epoch">,
 // CUDA Options
 
//===--===//
 
-let Visibility = [CC1Option] in {
+let Visibility = [CC1Option, FC1Option] in {
 
 def fcuda_is_device : Flag<["-"], "fcuda-is-device">,
   HelpText<"Generate code for CUDA device">,
@@ -8031,7 +8031,7 @@ def fno_cuda_host_device_constexpr : Flag<["-"], 
"fno-cuda-host-device-constexpr
   HelpText<"Don't treat unattributed constexpr functions as __host__ 
__device__.">,
   MarshallingInfoNegativeFlag>;
 
-} // let Visibility = [CC1Option]
+} // let Visibility = [CC1Option, FC1Option]
 
 
//===--===//
 // OpenMP Options
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..2679f284c5016 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -333,6 +333,9 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
 StringRef Val = A->getValue();
 CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
   }
+
+  const ToolChain &TC = getToolChain();
+  TC.addClangTargetOptions(Args, CmdArgs, Action::OffloadKind::OFK_OpenMP);
 }
 
 void Flang::addTargetOptions(const ArgList &Args,
diff --git a/flang/test/Driver/omp-driver-offload.f90 
b/flang/test/Driver/omp-driver-offload.f90
index 6fb4f4ca1..da81a6ee3ba8f 100644
--- a/flang/test/Driver/omp-driver-offload.f90
+++ b/flang/test/Driver/omp-driver-offload.f90
@@ -14,12 +14,12 @@
 ! Test regular -fopenmp with offload, and invocation filtering options
 ! RUN: %flang -S -### %s -o %t 2>&1 \
 ! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 \
-! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
 ! RUN:   | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE
 
 ! RUN: %flang -S -### %s -o %t 2>&1 \
 ! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 
--offload-host-device \
-! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
 ! RUN:   | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE
 
 ! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
@@ -29,7 +29,7 @@
 
 ! RUN: %flang -S -### %s -o %t 2>&1 \
 ! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-host-only 
\
-! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
 ! RUN:   | FileCheck %s --check-prefix=OFFLOAD-HOST
 
 ! OFFLOAD-HOST: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
@@ -39,7 +39,7 @@
 
 ! RUN: %flang -S -### %s 2>&1 \
 ! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 
--offload-device-only \
-! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
 ! RUN:   | FileCheck %s --check-prefix=OFFLOAD-DEVICE
 
 ! OFFLOAD-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
@@ -48,13 +48,13 @@
 ! OFFLOAD-DEVICE-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
 
 ! Test regular -fopenmp with offload for basic fopenmp-is-target-device flag 
addition and correct fopenmp 
-! RUN: %flang -### -fopenmp --offload-arch=gfx90a 
-fopenmp-targets=amdgcn-amd-amdhsa %s 2>&1 | FileCheck 
--check-prefixes=CHECK-OPENMP-IS-TARGET-DEVICE %s
+! RUN: %flang -### -fopenmp --offload-arch=gfx90a 
-fopenmp-targets=amdgcn-amd-amdhsa -nogpulib %s 2>&1 | FileCheck 
--check-prefixes=CHECK-OPENMP-IS-TARGET-DEVICE %s
 ! CHECK-OPENMP-IS-TARGET-DEVICE: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" 
{{.*}} "-fopenmp-is-target-device" {{.*}}.f90"
 
 ! Testing appropriate flags are gnerated and appropriately assigned by the 
dr

[clang] [Clang] Add __builtin_is_within_lifetime to implement P2641R4's std::is_within_lifetime (PR #91895)

2024-07-26 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/91895

>From 56aed689dc5825fc5bacc6dfdff58ee0eaf71f82 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 12 May 2024 19:48:24 +0100
Subject: [PATCH 1/9] [Clang] Add attribute for consteval builtins; Declare
 constexpr builtins as constexpr in C++

Also support redeclaring now-constexpr builtins without constexpr
---
 clang/include/clang/Basic/Builtins.h  |  5 +
 clang/include/clang/Basic/BuiltinsBase.td |  2 ++
 clang/lib/Sema/SemaDecl.cpp   | 15 +++
 clang/lib/Sema/SemaDeclCXX.cpp| 18 +-
 clang/lib/Sema/SemaExpr.cpp   |  8 ++--
 clang/test/Sema/builtin-redecl.cpp| 15 ++-
 6 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index f955d21169556..e85ec5b2dca14 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -280,6 +280,11 @@ class Context {
 return strchr(getRecord(ID).Attributes, 'E') != nullptr;
   }
 
+  /// Returns true if this is an immediate (consteval) function
+  bool isImmediate(unsigned ID) const {
+return strchr(getRecord(ID).Attributes, 'G') != nullptr;
+  }
+
 private:
   const Info &getRecord(unsigned ID) const;
 
diff --git a/clang/include/clang/Basic/BuiltinsBase.td 
b/clang/include/clang/Basic/BuiltinsBase.td
index 724747ec76d73..1196b9e15c10d 100644
--- a/clang/include/clang/Basic/BuiltinsBase.td
+++ b/clang/include/clang/Basic/BuiltinsBase.td
@@ -70,6 +70,8 @@ class VScanfFormat : IndexedAttribute<"S", I>;
 
 // Builtin can be constant evaluated
 def Constexpr : Attribute<"E">;
+// Builtin is immediate and must be constant evaluated. Implies Constexpr.
+def Consteval : Attribute<"EG">;
 
 // Builtin kinds
 // =
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fb913034bd836..6b0a04585928a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2409,10 +2409,17 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, 
QualType Type,
 Parent = CLinkageDecl;
   }
 
-  FunctionDecl *New = FunctionDecl::Create(Context, Parent, Loc, Loc, II, Type,
-   /*TInfo=*/nullptr, SC_Extern,
-   
getCurFPFeatures().isFPConstrained(),
-   false, Type->isFunctionProtoType());
+  ConstexprSpecKind ConstexprKind = ConstexprSpecKind::Unspecified;
+  if (getLangOpts().CPlusPlus && Context.BuiltinInfo.isConstantEvaluated(ID)) {
+ConstexprKind = ConstexprSpecKind::Constexpr;
+if (Context.BuiltinInfo.isImmediate(ID))
+  ConstexprKind = ConstexprSpecKind::Consteval;
+  }
+
+  FunctionDecl *New = FunctionDecl::Create(
+  Context, Parent, Loc, Loc, II, Type, /*TInfo=*/nullptr, SC_Extern,
+  getCurFPFeatures().isFPConstrained(), /*isInlineSpecified=*/false,
+  Type->isFunctionProtoType(), ConstexprKind);
   New->setImplicit();
   New->addAttr(BuiltinAttr::CreateImplicit(Context, ID));
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 53238d355ea09..1b558d70f9b48 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -676,11 +676,19 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, 
FunctionDecl *Old,
   // template has a constexpr specifier then all its declarations shall
   // contain the constexpr specifier.
   if (New->getConstexprKind() != Old->getConstexprKind()) {
-Diag(New->getLocation(), diag::err_constexpr_redecl_mismatch)
-<< New << static_cast(New->getConstexprKind())
-<< static_cast(Old->getConstexprKind());
-Diag(Old->getLocation(), diag::note_previous_declaration);
-Invalid = true;
+if (Old->getBuiltinID() &&
+Old->getConstexprKind() == ConstexprSpecKind::Constexpr &&
+New->getConstexprKind() == ConstexprSpecKind::Unspecified) {
+  // Except allow redeclaring a builtin as non-constexpr to match C
+  // redeclarations which will not be constexpr
+  New->setConstexprKind(ConstexprSpecKind::Constexpr);
+} else {
+  Diag(New->getLocation(), diag::err_constexpr_redecl_mismatch)
+  << New << static_cast(New->getConstexprKind())
+  << static_cast(Old->getConstexprKind());
+  Diag(Old->getLocation(), diag::note_previous_declaration);
+  Invalid = true;
+}
   } else if (!Old->getMostRecentDecl()->isInlined() && New->isInlined() &&
  Old->isDefined(Def) &&
  // If a friend function is inlined but does not have 'inline'
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index bb4b116fd73ca..39aa32526d2b1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7095,8 +7095,12 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, 
NamedDecl *NDecl,
   }
 
   // Bail

[clang] [flang] [Flang-new][OpenMP] Add bitcode files for AMD GPU OpenMP (PR #96742)

2024-07-26 Thread Dominik Adamski via cfe-commits

DominikAdamski wrote:

> > > Who could be the right person to ask?
> > 
> > I don't know. Open-source LLVM Flang meetings can be good place to ask this 
> > question.
>
> Did you ask? What feedback did you get?

@banach-space I asked question on flang-slack, I mentioned the issue on the 
latest Flang technical meeting and I described potential solution here: 
https://discourse.llvm.org/t/offloading-on-nvptx64-target-with-flang-new-leads-to-undefined-reference-s/80237
 . I got no feedback.

Can I merge this PR? The issue with -`fcuda-is-device` is resolved. If you wish 
I can extend driver checks for `-mlink-builtin-bitcode` as a separate PR.

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


[clang] [clang][Driver] Support passing arbitrary args to -cc1as with -Xclangas. (PR #100714)

2024-07-26 Thread Alex Rønne Petersen via cfe-commits

alexrp wrote:

I'm assuming this failure is not caused by my changes: 
https://github.com/llvm/llvm-project/actions/runs/10107700664/job/27952082137?pr=100714

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


[clang] 9440a49 - [clang][analyzer] MmapWriteExecChecker improvements (#97078)

2024-07-26 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-07-26T10:10:36+02:00
New Revision: 9440a49b0ff812c889927e4dc81e746b32124bb4

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

LOG: [clang][analyzer] MmapWriteExecChecker improvements (#97078)

Read the 'mmap' flags from macro values and use a better test for the
error situation. Checker messages are improved too.

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/mmap-writeexec.c

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index ec5dbd28a5272..38b55a0eb0a7b 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1045,18 +1045,6 @@ def MallocOverflowSecurityChecker : 
Checker<"MallocOverflow">,
 
 def MmapWriteExecChecker : Checker<"MmapWriteExec">,
   HelpText<"Warn on mmap() calls that are both writable and executable">,
-  CheckerOptions<[
-CmdLineOption,
-CmdLineOption
-  ]>,
   Documentation;
 
 def ReturnPointerRangeChecker : Checker<"ReturnPtrRange">,

diff  --git a/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
index cd1dd1b2fc511..4b8e5216550d9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -21,49 +21,56 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 
 using namespace clang;
 using namespace ento;
 
 namespace {
-class MmapWriteExecChecker : public Checker {
+class MmapWriteExecChecker
+: public Checker, check::PreCall> {
   CallDescription MmapFn{CDM::CLibrary, {"mmap"}, 6};
   CallDescription MprotectFn{CDM::CLibrary, {"mprotect"}, 3};
-  static int ProtWrite;
-  static int ProtExec;
-  static int ProtRead;
   const BugType BT{this, "W^X check fails, Write Exec prot flags set",
"Security"};
 
+  // Default values are used if definition of the flags is not found.
+  mutable int ProtRead = 0x01;
+  mutable int ProtWrite = 0x02;
+  mutable int ProtExec = 0x04;
+
 public:
+  void checkASTDecl(const TranslationUnitDecl *TU, AnalysisManager &Mgr,
+BugReporter &BR) const;
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
-  int ProtExecOv;
-  int ProtReadOv;
 };
 }
 
-int MmapWriteExecChecker::ProtWrite = 0x02;
-int MmapWriteExecChecker::ProtExec  = 0x04;
-int MmapWriteExecChecker::ProtRead  = 0x01;
+void MmapWriteExecChecker::checkASTDecl(const TranslationUnitDecl *TU,
+AnalysisManager &Mgr,
+BugReporter &BR) const {
+  Preprocessor &PP = Mgr.getPreprocessor();
+  const std::optional FoundProtRead = tryExpandAsInteger("PROT_READ", PP);
+  const std::optional FoundProtWrite =
+  tryExpandAsInteger("PROT_WRITE", PP);
+  const std::optional FoundProtExec = tryExpandAsInteger("PROT_EXEC", PP);
+  if (FoundProtRead && FoundProtWrite && FoundProtExec) {
+ProtRead = *FoundProtRead;
+ProtWrite = *FoundProtWrite;
+ProtExec = *FoundProtExec;
+  }
+}
 
 void MmapWriteExecChecker::checkPreCall(const CallEvent &Call,
- CheckerContext &C) const {
+CheckerContext &C) const {
   if (matchesAny(Call, MmapFn, MprotectFn)) {
 SVal ProtVal = Call.getArgSVal(2);
 auto ProtLoc = ProtVal.getAs();
 if (!ProtLoc)
   return;
 int64_t Prot = ProtLoc->getValue().getSExtValue();
-if (ProtExecOv != ProtExec)
-  ProtExec = ProtExecOv;
-if (ProtReadOv != ProtRead)
-  ProtRead = ProtReadOv;
-
-// Wrong settings
-if (ProtRead == ProtExec)
-  return;
 
-if ((Prot & (ProtWrite | ProtExec)) == (ProtWrite | ProtExec)) {
+if ((Prot & ProtWrite) && (Prot & ProtExec)) {
   ExplodedNode *N = C.generateNonFatalErrorNode();
   if (!N)
 return;
@@ -80,17 +87,10 @@ void MmapWriteExecChecker::checkPreCall(const CallEvent 
&Call,
   }
 }
 
-void ento::registerMmapWriteExecChecker(CheckerManager &mgr) {
-  MmapWriteExecChecker *Mwec =
-  mgr.registerChecker();
-  Mwec->ProtExecOv =
-mgr.getAnalyzerOptions()
-  .getCheckerIntegerOption(Mwec, "MmapProtExec");
-  Mwec->ProtReadOv =
-mgr.getAnalyzerOptions()
-  .getCheckerIntegerOption(Mwec, "Mm

[clang] [clang][analyzer] MmapWriteExecChecker improvements (PR #97078)

2024-07-26 Thread Balázs Kéri via cfe-commits

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


[clang] f8ae128 - [clang][FMV][AArch64] Improve streaming mode compatibility. (#100181)

2024-07-26 Thread via cfe-commits

Author: Alexandros Lamprineas
Date: 2024-07-26T09:22:47+01:00
New Revision: f8ae128755777424cf4133e4e8e819c0bc08d2b1

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

LOG: [clang][FMV][AArch64] Improve streaming mode compatibility. (#100181)

* Allow arm-streaming if all the functions versions adhere to it.
* Allow arm-streaming-compatible if all the functions versions adhere to
it.

When the caller needs to toggle the streaming mode all the function
versions of the callee must adhere to the same mode, otherwise the call
will yield a runtime error.

Imagine the versions of the callee live in separate TUs. The version
that is visible to the caller will determine the calling convention used
when generating code for the callsite. Therefore we cannot support
mixing streaming with non-streaming function versions. Imagine TU1 has a
streaming caller and calls foo._sme which is streaming-compatible. The
codegen for the callsite will not switch off the streaming mode. Then in
TU2 we have a version which is non-streaming and could potentially be
called in streaming mode. Similarly if the caller is non-streaming and
the called version is streaming-compatible the codegen for the callsite
will not switch on the streaming mode, but other versions may be
streaming.

Added: 
clang/test/CodeGen/aarch64-fmv-streaming.c
clang/test/Sema/aarch64-fmv-streaming.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/aarch64-sme-func-attrs.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 810abe4f23e31..beee2432fdb06 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3812,8 +3812,6 @@ def warn_sme_locally_streaming_has_vl_args_returns : 
Warning<
   InGroup, DefaultIgnore;
 def err_conflicting_attributes_arm_state : Error<
   "conflicting attributes for state '%0'">;
-def err_sme_streaming_cannot_be_multiversioned : Error<
-  "streaming function cannot be multi-versioned">;
 def err_unknown_arm_state : Error<
   "unknown state '%0'">;
 def err_missing_arm_state : Error<

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 575bd292f27de..7bdecb2546f30 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11009,6 +11009,9 @@ static bool AttrCompatibleWithMultiVersion(attr::Kind 
Kind,
   switch (Kind) {
   default:
 return false;
+  case attr::ArmLocallyStreaming:
+return MVKind == MultiVersionKind::TargetVersion ||
+   MVKind == MultiVersionKind::TargetClones;
   case attr::Used:
 return MVKind == MultiVersionKind::Target;
   case attr::NonNull:
@@ -11145,7 +11148,21 @@ bool Sema::areMultiversionVariantFunctionsCompatible(
 FunctionType::ExtInfo OldTypeInfo = OldType->getExtInfo();
 FunctionType::ExtInfo NewTypeInfo = NewType->getExtInfo();
 
-if (OldTypeInfo.getCC() != NewTypeInfo.getCC())
+const auto *OldFPT = OldFD->getType()->getAs();
+const auto *NewFPT = NewFD->getType()->getAs();
+
+bool ArmStreamingCCMismatched = false;
+if (OldFPT && NewFPT) {
+  unsigned Diff =
+  OldFPT->getAArch64SMEAttributes() ^ 
NewFPT->getAArch64SMEAttributes();
+  // Arm-streaming, arm-streaming-compatible and non-streaming versions
+  // cannot be mixed.
+  if (Diff & (FunctionType::SME_PStateSMEnabledMask |
+  FunctionType::SME_PStateSMCompatibleMask))
+ArmStreamingCCMismatched = true;
+}
+
+if (OldTypeInfo.getCC() != NewTypeInfo.getCC() || ArmStreamingCCMismatched)
   return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << CallingConv;
 
 QualType OldReturnType = OldType->getReturnType();
@@ -11165,9 +11182,8 @@ bool Sema::areMultiversionVariantFunctionsCompatible(
 if (!CLinkageMayDiffer && OldFD->isExternC() != NewFD->isExternC())
   return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << LanguageLinkage;
 
-if (CheckEquivalentExceptionSpec(
-OldFD->getType()->getAs(), OldFD->getLocation(),
-NewFD->getType()->getAs(), 
NewFD->getLocation()))
+if (CheckEquivalentExceptionSpec(OldFPT, OldFD->getLocation(), NewFPT,
+ NewFD->getLocation()))
   return true;
   }
   return false;

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 300bd8967790f..8b0a6bf4caf48 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3034,9 +3034,6 @@ bool Sema::checkTargetVersionAttr(SourceLocation 
LiteralLoc, Decl *D,
   return Diag(LiteralLoc, diag::warn_unsupported_target_att

[clang] [clang][FMV][AArch64] Improve streaming mode compatibility. (PR #100181)

2024-07-26 Thread Alexandros Lamprineas via cfe-commits

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


[clang] [llvm] [AArch64] Implement intrinsics for SME2 FAMIN/FAMAX (PR #99063)

2024-07-26 Thread via cfe-commits

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

Thank you Momchil, the patch looks fine.
This time a checked the flags in arm_sve.td and they look ok.

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


[clang] [Clang] Qualified functions can't decay into pointers (PR #90353)

2024-07-26 Thread via cfe-commits

https://github.com/cor3ntin commented:

Thanks!
I think the general approach makes sense

There are a few DR that might be worth mentioning/add tests for/look into

https://cplusplus.github.io/CWG/issues/713.html
https://cplusplus.github.io/CWG/issues/1417.html
https://cplusplus.github.io/CWG/issues/1584.html 

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


[clang] [Clang] Qualified functions can't decay into pointers (PR #90353)

2024-07-26 Thread via cfe-commits


@@ -15071,6 +15071,13 @@ ParmVarDecl *Sema::CheckParameter(DeclContext *DC, 
SourceLocation StartLoc,
 T = Context.getLifetimeQualifiedType(T, lifetime);
   }
 
+  if (T->isFunctionType() && !T.isReferenceable()) {
+Diag(NameLoc, diag::err_compound_qualified_function_type)
+<< 1 << true << T
+<< T->castAs()->getFunctionQualifiersAsString();
+return nullptr;
+  }
+

cor3ntin wrote:

We have similar logic thorough this PR, having a function like 
`DiagnoseUnreferenceableFunctionTypes would be nice`

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


[clang] [Clang] Qualified functions can't decay into pointers (PR #90353)

2024-07-26 Thread via cfe-commits

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


[clang] [clang][FMV][AArch64] Improve streaming mode compatibility. (PR #100181)

2024-07-26 Thread via cfe-commits

llvmbot wrote:


Failed to cherry-pick: 
[f8ae128](https://github.com/llvm/llvm-project/commit/f8ae128755777424cf4133e4e8e819c0bc08d2b1)

https://github.com/llvm/llvm-project/actions/runs/10108416112

Please manually backport the fix and push it to your github fork.  Once this is 
done, please create a [pull 
request](https://github.com/llvm/llvm-project/compare)

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

2024-07-26 Thread via cfe-commits


@@ -10673,6 +10673,11 @@ class Sema final : public SemaBase {
SourceLocation EndLoc);
   void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
 
+  /// DiagnoseDiscardedNodiscard - Given an expression that is semantically
+  /// a discarded-value expression, diagnose if any [[nodiscard]] value
+  /// has been discarded
+  void DiagnoseDiscardedNodiscard(const Expr *E);

cor3ntin wrote:

Can we find a better name for that function?

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


[clang] [analyzer][NFC] Eliminate a dyn_cast (PR #100719)

2024-07-26 Thread Kristóf Umann via cfe-commits

https://github.com/Szelethus created 
https://github.com/llvm/llvm-project/pull/100719

Response to the catch in this comment: 
https://github.com/llvm/llvm-project/pull/94357/files/07f6daf2cf0f5d5bd4fc9950f2585a3f52b4ad2f#r1692084074

From d176b03b211144dadaa1efb4b7da959110d7725c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Krist=C3=B3f=20Umann?= 
Date: Fri, 26 Jul 2024 11:01:41 +0200
Subject: [PATCH] [analyzer][NFC] Eliminate a dyn_cast

---
 clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp  | 5 ++---
 clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h | 2 +-
 clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp  | 5 ++---
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index fe202c79ed620..39e5c7c014a2a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -796,14 +796,13 @@ class NoMemOwnershipChangeVisitor final : public 
NoOwnershipChangeVisitor {
   /// done syntactically, because we are trying to argue about alternative
   /// paths of execution, and as a consequence we don't have path-sensitive
   /// information.
-  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+  bool doesFnIntendToHandleOwnership(const FunctionDecl *Callee,
  ASTContext &ACtx) final {
 using namespace clang::ast_matchers;
-const FunctionDecl *FD = dyn_cast(Callee);
 
 auto Matches = match(findAll(stmt(anyOf(cxxDeleteExpr().bind("delete"),
 callExpr().bind("call",
- *FD->getBody(), ACtx);
+ Callee->getBody(), ACtx);
 for (BoundNodes Match : Matches) {
   if (Match.getNodeAs("delete"))
 return true;
diff --git a/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h 
b/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h
index 027f1a156a7c0..7be74860d863b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h
+++ b/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h
@@ -26,7 +26,7 @@ class NoOwnershipChangeVisitor : public 
NoStateChangeFuncVisitor {
   /// is done syntactically, because we are trying to argue about alternative
   /// paths of execution, and as a consequence we don't have path-sensitive
   /// information.
-  virtual bool doesFnIntendToHandleOwnership(const Decl *Callee,
+  virtual bool doesFnIntendToHandleOwnership(const FunctionDecl *Callee,
  ASTContext &ACtx) = 0;
 
   virtual bool hasResourceStateChanged(ProgramStateRef CallEnterState,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 9aee7f952ad2d..41187ee9b5cdf 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -746,13 +746,12 @@ class NoStreamStateChangeVisitor final : public 
NoOwnershipChangeVisitor {
 return StreamChk->FCloseDesc.matchesAsWritten(Call);
   }
 
-  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+  bool doesFnIntendToHandleOwnership(const FunctionDecl *Callee,
  ASTContext &ACtx) final {
 using namespace clang::ast_matchers;
-const FunctionDecl *FD = dyn_cast(Callee);
 
 auto Matches =
-match(findAll(callExpr().bind("call")), *FD->getBody(), ACtx);
+match(findAll(callExpr().bind("call")), Callee->getBody(), ACtx);
 for (BoundNodes Match : Matches) {
   if (const auto *Call = Match.getNodeAs("call"))
 if (isClosingCallAsWritten(*Call))

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


[clang] [analyzer][NFC] Factor out NoOwnershipChangeVisitor (PR #94357)

2024-07-26 Thread Kristóf Umann via cfe-commits


@@ -804,23 +751,21 @@ class NoOwnershipChangeVisitor final : public 
NoStateChangeFuncVisitor {
 return false;
   }
 
+  bool hasResourceStateChanged(ProgramStateRef CallEnterState,
+   ProgramStateRef CallExitEndState) final {
+return CallEnterState->get(Sym) !=
+   CallExitEndState->get(Sym);
+  }
+
   /// Heuristically guess whether the callee intended to free memory. This is
   /// done syntactically, because we are trying to argue about alternative
   /// paths of execution, and as a consequence we don't have path-sensitive
   /// information.
-  bool doesFnIntendToHandleOwnership(const Decl *Callee, ASTContext &ACtx) {
+  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+ ASTContext &ACtx) final {
 using namespace clang::ast_matchers;
 const FunctionDecl *FD = dyn_cast(Callee);

Szelethus wrote:

Nice catch! Fix is here: https://github.com/llvm/llvm-project/pull/100719

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


[clang] [analyzer][NFC] Eliminate a dyn_cast (PR #100719)

2024-07-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Kristóf Umann (Szelethus)


Changes

Response to the catch in this comment: 
https://github.com/llvm/llvm-project/pull/94357/files/07f6daf2cf0f5d5bd4fc9950f2585a3f52b4ad2f#r1692084074

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


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (+2-3) 
- (modified) clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h 
(+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+2-3) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index fe202c79ed620..39e5c7c014a2a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -796,14 +796,13 @@ class NoMemOwnershipChangeVisitor final : public 
NoOwnershipChangeVisitor {
   /// done syntactically, because we are trying to argue about alternative
   /// paths of execution, and as a consequence we don't have path-sensitive
   /// information.
-  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+  bool doesFnIntendToHandleOwnership(const FunctionDecl *Callee,
  ASTContext &ACtx) final {
 using namespace clang::ast_matchers;
-const FunctionDecl *FD = dyn_cast(Callee);
 
 auto Matches = match(findAll(stmt(anyOf(cxxDeleteExpr().bind("delete"),
 callExpr().bind("call",
- *FD->getBody(), ACtx);
+ Callee->getBody(), ACtx);
 for (BoundNodes Match : Matches) {
   if (Match.getNodeAs("delete"))
 return true;
diff --git a/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h 
b/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h
index 027f1a156a7c0..7be74860d863b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h
+++ b/clang/lib/StaticAnalyzer/Checkers/NoOwnershipChangeVisitor.h
@@ -26,7 +26,7 @@ class NoOwnershipChangeVisitor : public 
NoStateChangeFuncVisitor {
   /// is done syntactically, because we are trying to argue about alternative
   /// paths of execution, and as a consequence we don't have path-sensitive
   /// information.
-  virtual bool doesFnIntendToHandleOwnership(const Decl *Callee,
+  virtual bool doesFnIntendToHandleOwnership(const FunctionDecl *Callee,
  ASTContext &ACtx) = 0;
 
   virtual bool hasResourceStateChanged(ProgramStateRef CallEnterState,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 9aee7f952ad2d..41187ee9b5cdf 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -746,13 +746,12 @@ class NoStreamStateChangeVisitor final : public 
NoOwnershipChangeVisitor {
 return StreamChk->FCloseDesc.matchesAsWritten(Call);
   }
 
-  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+  bool doesFnIntendToHandleOwnership(const FunctionDecl *Callee,
  ASTContext &ACtx) final {
 using namespace clang::ast_matchers;
-const FunctionDecl *FD = dyn_cast(Callee);
 
 auto Matches =
-match(findAll(callExpr().bind("call")), *FD->getBody(), ACtx);
+match(findAll(callExpr().bind("call")), Callee->getBody(), ACtx);
 for (BoundNodes Match : Matches) {
   if (const auto *Call = Match.getNodeAs("call"))
 if (isClosingCallAsWritten(*Call))

``




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


[clang] [analyzer][NFC] Eliminate a dyn_cast (PR #100719)

2024-07-26 Thread Donát Nagy via cfe-commits

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


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


[clang] [clang][ASTImporter] Fix import of template parameter default values. (PR #100100)

2024-07-26 Thread Donát Nagy via cfe-commits

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


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


[clang] [clang][ASTImporter] Fix import of template parameter default values. (PR #100100)

2024-07-26 Thread Donát Nagy via cfe-commits


@@ -359,6 +359,31 @@ namespace clang {
   Params, Importer.getToContext().getTranslationUnitDecl());
 }
 
+template 
+void tryUpdateTemplateParmDeclInheritedFrom(NamedDecl *RecentParm,
+NamedDecl *NewParm) {
+  if (auto *ParmT = dyn_cast(RecentParm)) {
+if (ParmT->hasDefaultArgument()) {
+  auto *P = cast(NewParm);
+  P->removeDefaultArgument();
+  P->setInheritedDefaultArgument(Importer.ToContext, ParmT);
+}
+  }
+}
+
+void updateTemplateParametersInheritedFrom(

NagyDonat wrote:

Thanks for the clarifications!

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


[clang] [clang] replaced the usage of `asctime` with `std::put_time` (PR #99075)

2024-07-26 Thread Rainer Orth via cfe-commits

rorth wrote:

> > At least in the short term. ISTM that `clang++` may need to do something 
> > along the lines of Bug 33767 (resp. the underlying GCC bug/patch), 
> > otherwise users are in for a nasty surprise.
> 
> Agreed; long-term we need a better solution. Hopefully someone maintaining 
> Solaris support can step in and help there, because this is quite surprising 
> behavior.

The cleaned-up hack is in the final rounds of testing.  Wlll create a PR once 
that's done.

There's no real Solaris maintainer AFAIK: while I do run the buildbots and try 
to keep the port in shape as time allows, I can only do so much.  The Solaris 
GCC maintainership takes enough of my time and splitting it would only be to 
the detriment of both projects.

TBH, I wouldn't even know where to look: I've mostly dealt with `compiler-rt` 
and driver issues so far.

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

2024-07-26 Thread via cfe-commits


@@ -222,17 +222,17 @@ static bool DiagnoseNoDiscard(Sema &S, const 
WarnUnusedResultAttr *A,
   return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
 }
 
-void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
-  if (const LabelStmt *Label = dyn_cast_or_null(S))
-return DiagnoseUnusedExprResult(Label->getSubStmt(), DiagID);
-
-  const Expr *E = dyn_cast_or_null(S);
-  if (!E)
-return;
+static void DiagnoseUnused(Sema &S, const Expr *E,
+   std::optional DiagID) {
+  // When called from Sema::DiagnoseUnusedExprResult, DiagID is a diagnostic 
for
+  // where this expression is not used. When called from
+  // Sema::DiagnoseDiscardedNodiscard, DiagID is std::nullopt and this function
+  // will only diagnose [[nodiscard]], [[gnu::warn_unused_result]] and similar

cor3ntin wrote:

```suggestion
  // Diagnoses unused expressions that call functions marked [[nodiscard]], 
[[gnu::warn_unused_result]] and similar. Additionally, a DiagID can be provided 
to emit a warning in additional contexts (such as for an unused LHS of a comma 
expression)
```

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

2024-07-26 Thread via cfe-commits

https://github.com/cor3ntin commented:

General direction looks good

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

2024-07-26 Thread via cfe-commits


@@ -222,17 +222,17 @@ static bool DiagnoseNoDiscard(Sema &S, const 
WarnUnusedResultAttr *A,
   return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
 }
 
-void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
-  if (const LabelStmt *Label = dyn_cast_or_null(S))
-return DiagnoseUnusedExprResult(Label->getSubStmt(), DiagID);
-
-  const Expr *E = dyn_cast_or_null(S);
-  if (!E)
-return;
+static void DiagnoseUnused(Sema &S, const Expr *E,
+   std::optional DiagID) {
+  // When called from Sema::DiagnoseUnusedExprResult, DiagID is a diagnostic 
for
+  // where this expression is not used. When called from
+  // Sema::DiagnoseDiscardedNodiscard, DiagID is std::nullopt and this function
+  // will only diagnose [[nodiscard]], [[gnu::warn_unused_result]] and similar

cor3ntin wrote:

TBH, `warn_unused_comma_left_operand` seem to be the only scenario at a glance 
so maybe we would be better off introduce an enum for that 3rd parameter

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

2024-07-26 Thread via cfe-commits

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


[clang] [clang] Handle tm mangling on Solaris in PPMacroExpansion.cpp (PR #100724)

2024-07-26 Thread Rainer Orth via cfe-commits

https://github.com/rorth created 
https://github.com/llvm/llvm-project/pull/100724

The introduction of `std::put_time` in
fad17b43dbc09ac7e0a95535459845f72c2b739a broke the Solaris build:
```
Undefined   first referenced
 symbol in file
_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_RSt8ios_basecPKSt2tmPKcSB_
 lib/libclangLex.a(PPMacroExpansion.cpp.o)
ld: fatal: symbol referencing errors
```
As discussed in PR #99075, the problem is that GCC mangles `std::tm` as `tm` on 
Solaris for binary compatility, while `clang` doesn't (Issue #33114).

As a stop-gap measure, this patch introduces an `asm` level alias to the same 
effect.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and 
`x86_64-pc-linux-gnu`.

>From 139569a6e48ceda0adc9fa8ca8e2d5d238f0712a Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Fri, 26 Jul 2024 11:15:16 +0200
Subject: [PATCH] [clang] Handle tm mangling on Solaris in PPMacroExpansion.cpp

The introduction of `std::put_time` in
fad17b43dbc09ac7e0a95535459845f72c2b739a broke the Solaris build:
```
Undefined   first referenced
 symbol in file
_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_RSt8ios_basecPKSt2tmPKcSB_
 lib/libclangLex.a(PPMacroExpansion.cpp.o)
ld: fatal: symbol referencing errors
```
As discussed in PR #99075, the problem is that GCC mangles `std::tm` as
`tm` on Solaris for binary compatility, while `clang` doesn't (Issue

As a stop-gap measure, this patch introduces an `asm` level alias to the
same effect.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and
`x86_64-pc-linux-gnu`.
---
 clang/lib/Lex/PPMacroExpansion.cpp | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 879f01e87806e..1e31fcc3d731e 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1604,6 +1604,16 @@ static bool isTargetVariantEnvironment(const TargetInfo 
&TI,
   return false;
 }
 
+#if defined(__sun__) && defined(__svr4__)
+// GCC mangles std::tm as tm for binary compatibility on Solaris (Issue
+// #33114).  We need to match this to allow the std::put_time calls to link
+// (PR #99075).
+asm("_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_"
+"RSt8ios_basecPKSt2tmPKcSB_ = "
+"_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_"
+"RSt8ios_basecPK2tmPKcSB_");
+#endif
+
 /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
 /// as a builtin macro, handle it and return the next token as 'Tok'.
 void Preprocessor::ExpandBuiltinMacro(Token &Tok) {

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


[clang] [clang] Handle tm mangling on Solaris in PPMacroExpansion.cpp (PR #100724)

2024-07-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rainer Orth (rorth)


Changes

The introduction of `std::put_time` in
fad17b43dbc09ac7e0a95535459845f72c2b739a broke the Solaris build:
```
Undefined   first referenced
 symbol in file
_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_RSt8ios_basecPKSt2tmPKcSB_
 lib/libclangLex.a(PPMacroExpansion.cpp.o)
ld: fatal: symbol referencing errors
```
As discussed in PR #99075, the problem is that GCC mangles `std::tm` as 
`tm` on Solaris for binary compatility, while `clang` doesn't (Issue #33114).

As a stop-gap measure, this patch introduces an `asm` level alias to the same 
effect.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and 
`x86_64-pc-linux-gnu`.

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


1 Files Affected:

- (modified) clang/lib/Lex/PPMacroExpansion.cpp (+10) 


``diff
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 879f01e87806e..1e31fcc3d731e 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1604,6 +1604,16 @@ static bool isTargetVariantEnvironment(const TargetInfo 
&TI,
   return false;
 }
 
+#if defined(__sun__) && defined(__svr4__)
+// GCC mangles std::tm as tm for binary compatibility on Solaris (Issue
+// #33114).  We need to match this to allow the std::put_time calls to link
+// (PR #99075).
+asm("_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_"
+"RSt8ios_basecPKSt2tmPKcSB_ = "
+"_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_"
+"RSt8ios_basecPK2tmPKcSB_");
+#endif
+
 /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
 /// as a builtin macro, handle it and return the next token as 'Tok'.
 void Preprocessor::ExpandBuiltinMacro(Token &Tok) {

``




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


[clang] d65f037 - [Clang] Use private address space for builtin_alloca return type for OpenCL (#95750)

2024-07-26 Thread via cfe-commits

Author: Vikash Gupta
Date: 2024-07-26T15:24:06+05:30
New Revision: d65f0375910f6dfeaa94c1060e7d81fb7bdf76be

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

LOG: [Clang] Use private address space for builtin_alloca return type for 
OpenCL (#95750)

The __builtin_alloca was returning a flat pointer with no address space
when compiled using openCL1.2 or below but worked fine with openCL2.0
and above. This accounts to the fact that later uses the concept of
generic address space which supports cast to other address space(i.e to
private address space which is used for stack allocation) .

But, in actuality, as it returns pointer to the stack, it should be
pointing to private address space irrespective of openCL version becuase
builtin_alloca allocates stack memory used for current function in which
it is called. Thus,it requires redefintion of the builtin function with
appropraite return pointer to private address space.

Added: 
clang/test/CodeGenOpenCL/builtins-alloca.cl

Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 07a34fda494d8..bb30b1e289a1c 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1477,6 +1477,18 @@ static bool BuiltinSEHScopeCheck(Sema &SemaRef, CallExpr 
*TheCall,
   return false;
 }
 
+// In OpenCL, __builtin_alloca_* should return a pointer to address space
+// that corresponds to the stack address space i.e private address space.
+static void builtinAllocaAddrSpace(Sema &S, CallExpr *TheCall) {
+  QualType RT = TheCall->getType();
+  assert((RT->isPointerType() && !(RT->getPointeeType().hasAddressSpace())) &&
+ "__builtin_alloca has invalid address space");
+
+  RT = RT->getPointeeType();
+  RT = S.Context.getAddrSpaceQualType(RT, LangAS::opencl_private);
+  TheCall->setType(S.Context.getPointerType(RT));
+}
+
 namespace {
 enum PointerAuthOpKind {
   PAO_Strip,
@@ -2214,6 +2226,9 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   case Builtin::BI__builtin_alloca_uninitialized:
 Diag(TheCall->getBeginLoc(), diag::warn_alloca)
 << TheCall->getDirectCallee();
+if (getLangOpts().OpenCL) {
+  builtinAllocaAddrSpace(*this, TheCall);
+}
 break;
   case Builtin::BI__arithmetic_fence:
 if (BuiltinArithmeticFence(TheCall))

diff  --git a/clang/test/CodeGenOpenCL/builtins-alloca.cl 
b/clang/test/CodeGenOpenCL/builtins-alloca.cl
new file mode 100644
index 0..474e95e74e006
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-alloca.cl
@@ -0,0 +1,141 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL1.2 \
+// RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 \
+// RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 \
+// RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 
-cl-ext=+__opencl_c_generic_address_space \
+// RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL %s
+
+// OPENCL-LABEL: define dso_local void @test1_builtin_alloca(
+// OPENCL-SAME: i32 noundef [[N:%.*]]) #[[ATTR0:[0-9]+]] {
+// OPENCL-NEXT:  [[ENTRY:.*:]]
+// OPENCL-NEXT:[[N_ADDR:%.*]] = alloca i32, align 4, addrspace(5)
+// OPENCL-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL-NEXT:store i32 [[N]], ptr addrspace(5) [[N_ADDR]], align 4
+// OPENCL-NEXT:[[TMP0:%.*]] = load i32, ptr addrspace(5) [[N_ADDR]], align 
4
+// OPENCL-NEXT:[[CONV:%.*]] = zext i32 [[TMP0]] to i64
+// OPENCL-NEXT:[[MUL:%.*]] = mul i64 [[CONV]], 4
+// OPENCL-NEXT:[[TMP1:%.*]] = alloca i8, i64 [[MUL]], align 8, addrspace(5)
+// OPENCL-NEXT:store ptr addrspace(5) [[TMP1]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL-NEXT:ret void
+//
+void test1_builtin_alloca(unsigned n) {
+__private float* alloc_ptr = (__private 
float*)__builtin_alloca(n*sizeof(int));
+}
+
+// OPENCL-LABEL: define dso_local void @test1_builtin_alloca_uninitialized(
+// OPENCL-SAME: i32 noundef [[N:%.*]]) #[[ATTR0]] {
+// OPENCL-NEXT:  [[ENTRY:.*:]]
+// OPENCL-NEXT:[[N_ADDR:%.*]] = alloca i32, align 4, addrspace(5)
+// OPENCL-NEXT:[[ALLOC_PTR_UNINITIALIZED:%.*]] = alloca ptr addrspace(5), 
align 4, addrspace(5)
+// OPENCL-NEXT:store i32 [[N]], ptr addrspace(5) [[N_ADDR]], align 4
+// OPENCL-NEXT:[[TMP0:%.*]] = load i32, ptr addrspace(5) [[N_ADDR]], align 
4
+// OPENCL-NEXT:[[CONV:%.*]] = ze

[clang] [Clang] Use private address space for builtin_alloca return type for OpenCL (PR #95750)

2024-07-26 Thread Vikash Gupta via cfe-commits

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


[clang] Avoid accessing unset optional, workaround for #100095 (PR #100408)

2024-07-26 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

> Could we merge the test into this change? I think we could then land this as 
> a temporary workaround indeed. I'll keep looking into fixing this proper and 
> will remove the XFAIL line when appropriate.

I've added the test to the change and verified it:
* fails  without the SemaTemplateDeduction.cpp change, when compiled against 
libc++ with hardening enabled and with LLVM assertions disabled
* passes with the SemaTemplateDeduction.cpp change, when compiled against 
libc++ with hardening enabled and with LLVM assertions disabled
* XFAILs with the SemaTemplateDeduction.cpp change, when compiled against 
libc++ with hardening enabled and with LLVM assertions enabled.

Unfortunately, we don't have a buildbot with LLVM tests built against libc++ + 
hardening, but we're going to test it routinely internally at Google.

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


[clang] [clang][analyzer] MmapWriteExecChecker improvements (PR #97078)

2024-07-26 Thread LLVM Continuous Integration via cfe-commits
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 


llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-bootstrap-asan` running on `sanitizer-buildbot1` while 
building `clang` at step 2 "annotate".

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

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using lld-link: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld64.lld: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using wasm-ld: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld.lld: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using lld-link: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld64.lld: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using wasm-ld: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 84689 of 84690 tests, 88 workers --
Testing:  0.. 10.. 20
FAIL: Clang Tools :: clang-doc/basic-project.test (19740 of 84689)
 TEST 'Clang Tools :: clang-doc/basic-project.test' FAILED 

Exit Code: 1

Command Output (stdout):
--
Emiting docs in html format.
Mapping decls...
Collecting infos...
Reducing 5 infos...
Generating docs...
Generating assets for docs...

--
Command Output (stderr):
--
RUN: at line 1: rm -rf 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp
 && mkdir -p 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs
 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/build
+ rm -rf 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp
+ mkdir -p 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs
 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/build
RUN: at line 2: sed 
's|$test_dir|/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang-tools-extra/test/clang-doc|g'
 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang-tools-extra/test/clang-doc/Inputs/basic-project/database_template.json
 > 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/build/compile_commands.json
+ sed 
's|$test_dir|/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang-tools-extra/test/clang-doc|g'
 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang-tools-extra/test/clang-doc/Inputs/basic-project/database_template.json
RUN: at line 3: clang-doc --format=html 
--output=/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs
 --executor=all-TUs 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/build/compile_commands.json
+ clang-doc --format=html 
--output=/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/tools/extra/test/clang-doc/Output/basic-project.test.tmp/docs
 --executor=all-TUs 
/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/clang/tools/extra/test/clang-doc/Output/

[clang] [clang][CGRecordLayout] Remove dependency on isZeroSize (PR #96422)

2024-07-26 Thread Sergei Barannikov via cfe-commits


@@ -137,6 +137,16 @@ bool isEmptyField(ASTContext &Context, const FieldDecl 
*FD, bool AllowArrays,
 bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays,
bool AsIfNoUniqueAddr = false);
 
+/// isEmptyFieldForLayout - Return true iff the field is "empty", that is,
+/// either a zero-width bit-field or an \ref isEmptyRecordForLayout.
+bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD);
+
+/// isEmptyRecordForLayout - Return true iff a structure contains only empty
+/// base classes (per \ref isEmptyRecordForLayout) and fields (per
+/// \ref isEmptyFieldForLayout). Note, C++ record fields are considered empty
+/// if the [[no_unique_address]] attribute would have made them empty.
+bool isEmptyRecordForLayout(const ASTContext &Context, QualType T);

s-barannikov wrote:

These functions don't belong here. This file contains helper functions for use 
in implementations of ABIInfo class.
I guess CGRecordLayout* could be a better place for them.


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


[clang-tools-extra] 88549cf - [clang-doc] Disable flaky test `basic-project.test`

2024-07-26 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-07-26T13:15:35+03:00
New Revision: 88549cf47cafc4c4a6042393ee07fc2dc20566cc

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

LOG: [clang-doc] Disable flaky test `basic-project.test`

Added: 


Modified: 
clang-tools-extra/test/clang-doc/basic-project.test

Removed: 




diff  --git a/clang-tools-extra/test/clang-doc/basic-project.test 
b/clang-tools-extra/test/clang-doc/basic-project.test
index 51d3ac6ce6dcd..38569d824f1f0 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -1,3 +1,6 @@
+// See https://github.com/llvm/llvm-project/issues/97507.
+// UNSUPPORTED: target={{.*}}
+
 // RUN: rm -rf %t && mkdir -p %t/docs %t/build
 // RUN: sed 's|$test_dir|%/S|g' %S/Inputs/basic-project/database_template.json 
> %t/build/compile_commands.json
 // RUN: clang-doc --format=html --output=%t/docs --executor=all-TUs 
%t/build/compile_commands.json



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


[clang] [llvm] [AARCH64][SVE] Add intrinsics for SVE LUTI instructions (PR #97058)

2024-07-26 Thread via cfe-commits

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

LGTM

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


[clang] [clang] Enable the -Wdangling-assignment-gsl diagnostic by default. (PR #100708)

2024-07-26 Thread Utkarsh Saxena via cfe-commits

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

Thanks. Looks good since we are past the branch cut.

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


[clang] Add _MM_FROUND_TO_NEAREST_TIES_EVEN to avx512fintrin.h (PR #99691)

2024-07-26 Thread Robin Charles Gilbert via cfe-commits

robincharlesgilbert wrote:

To be fair, regarding MSVC, it might be more than just a chicken and the egg 
problem. It is sometimes in the best interests of Microsoft to make it as 
painful as possible for their customers to port their code onto other 
platforms, or to use standard libraries which are not implemented by Microsoft. 
On the other hand, when it comes to the rounding modes (for other functions 
than the intrinsics of this PR), MSVC has non-standard functions found nowhere 
else (e.g. _controlfp) which are using more objectionable names (_RC_CHOP for 
round toward zero... instead of a more natural name like _RC_ZERO).

Outside the Microsoft ecosystem, code portability is usually less of an issue. 
There is also less of a need to twist the hand of a patron to get the owner of 
a proprietary compiler to fix something.

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


[clang] [analyzer][NFC] Eliminate a dyn_cast (PR #100719)

2024-07-26 Thread Balazs Benics via cfe-commits

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


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


[clang] [NFC][clang] Avoid unnecessary assignment (PR #100728)

2024-07-26 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/100728

`IsStartOfLine` is set to false at the end of the loop.

>From e41e817050df138a0ac791c8aac0a3331c66d8df Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Fri, 26 Jul 2024 03:39:51 -0700
Subject: [PATCH] [NFC][clang] Avoid unnecessary assignment

`IsStartOfLine` is set to false at the end of the loop.
---
 clang/lib/Frontend/PrintPreprocessedOutput.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp 
b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 0592423c12eca..135dca0e6a177 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -980,7 +980,6 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token 
&Tok,
 *Callbacks->OS << static_cast(*Iter);
 PrintComma = true;
   }
-  IsStartOfLine = true;
 } else if (Tok.isAnnotation()) {
   // Ignore annotation tokens created by pragmas - the pragmas themselves
   // will be reproduced in the preprocessed output.

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


[clang] [NFC][clang] Avoid unnecessary assignment (PR #100728)

2024-07-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariya Podchishchaeva (Fznamznon)


Changes

`IsStartOfLine` is set to false at the end of the loop.

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


1 Files Affected:

- (modified) clang/lib/Frontend/PrintPreprocessedOutput.cpp (-1) 


``diff
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp 
b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 0592423c12eca..135dca0e6a177 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -980,7 +980,6 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token 
&Tok,
 *Callbacks->OS << static_cast(*Iter);
 PrintComma = true;
   }
-  IsStartOfLine = true;
 } else if (Tok.isAnnotation()) {
   // Ignore annotation tokens created by pragmas - the pragmas themselves
   // will be reproduced in the preprocessed output.

``




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


[clang] [llvm] [AArch64] Implement intrinsics for SVE FAMIN/FAMAX (PR #99042)

2024-07-26 Thread Momchil Velikov via cfe-commits


@@ -2385,3 +2385,8 @@ let SVETargetGuard = "sve2p1", SMETargetGuard = "sme2" in 
{
   def SVBFMLSLB_LANE : SInst<"svbfmlslb_lane[_{d}]", "dd$$i", "f", MergeNone, 
"aarch64_sve_bfmlslb_lane", [IsOverloadNone, VerifyRuntimeMode], [ImmCheck<3, 
ImmCheck0_7>]>;
   def SVBFMLSLT_LANE : SInst<"svbfmlslt_lane[_{d}]", "dd$$i", "f", MergeNone, 
"aarch64_sve_bfmlslt_lane", [IsOverloadNone, VerifyRuntimeMode], [ImmCheck<3, 
ImmCheck0_7>]>;
 }
+

momchil-velikov wrote:

It comes from `SInstZPZZ`.

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


[clang] [flang] [Flang][Driver] Introduce -fopenmp-targets offloading option (PR #100152)

2024-07-26 Thread Sergio Afonso via cfe-commits


@@ -492,6 +493,18 @@ void Flang::addOffloadOptions(Compilation &C, const 
InputInfoList &Inputs,
 if (Args.hasArg(options::OPT_nogpulib))
   CmdArgs.push_back("-nogpulib");
   }
+
+  // For all the host OpenMP offloading compile jobs we need to pass the 
targets
+  // information using -fopenmp-targets= option.
+  if (JA.isHostOffloading(Action::OFK_OpenMP)) {
+SmallString<128> Targets("-fopenmp-targets=");

skatrak wrote:

> For now, I would grudgingly accept the code as-is if this was done for the 
> rest of the file, but hope that we can avoid all this code duplication in the 
> future.
> 
> Did you consider to just extract the lines from `Clang.cpp` into another 
> function to some location this is accessible to both?

I agree that we should try to avoid duplicating code like this as much as 
possible. In this case, I just followed what's been done for other similar 
options and just copied it from clang.

After a quick look, I don't see an obvious place to add this shared code, but 
it looks like one way to get there would be to create a `Driver` or similar 
class deriving from `Tool` and make that the shared parent for the `Clang` and 
`Flang` classes, putting in it common option processing code used by both. 
Something like this would probably be best done on its own patch after some 
discussion, though. In any case, I think @banach-space is the expert on this 
area, so maybe he knows of any plans already in place to improve this situation 
or can give us some pointers on how to better deal with this in the short term.

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


[clang] [llvm] [Sanitizer] Make sanitizer passes idempotent (PR #99439)

2024-07-26 Thread via cfe-commits

https://github.com/skc7 updated https://github.com/llvm/llvm-project/pull/99439

>From 8a2a63ba5e2005fb2bf03b24610dc0e19130a978 Mon Sep 17 00:00:00 2001
From: skc7 
Date: Thu, 18 Jul 2024 11:49:24 +0530
Subject: [PATCH 1/7] [ASAN] Make asan pass idempotent.

---
 .../Instrumentation/AddressSanitizer.cpp  | 11 
 .../AddressSanitizer/asan-pass-second-run.ll  | 56 +++
 2 files changed, 67 insertions(+)
 create mode 100644 
llvm/test/Instrumentation/AddressSanitizer/asan-pass-second-run.ll

diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 9fb1df7ab2b79..3cc14515d6b15 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1249,8 +1249,19 @@ AddressSanitizerPass::AddressSanitizerPass(
   UseOdrIndicator(UseOdrIndicator), DestructorKind(DestructorKind),
   ConstructorKind(ConstructorKind) {}
 
+static bool hasAsanModuleCtor(Module &M) {
+  if (M.getFunction(kAsanModuleCtorName))
+return true;
+  return false;
+}
+
 PreservedAnalyses AddressSanitizerPass::run(Module &M,
 ModuleAnalysisManager &MAM) {
+  // Return early if asan.module_ctor is already present in the module.
+  // This implies that asan pass has already run before.
+  if (hasAsanModuleCtor(M))
+return PreservedAnalyses::all();
+
   ModuleAddressSanitizer ModuleSanitizer(
   M, Options.InsertVersionCheck, Options.CompileKernel, Options.Recover,
   UseGlobalGC, UseOdrIndicator, DestructorKind, ConstructorKind);
diff --git a/llvm/test/Instrumentation/AddressSanitizer/asan-pass-second-run.ll 
b/llvm/test/Instrumentation/AddressSanitizer/asan-pass-second-run.ll
new file mode 100644
index 0..65d72a72f605b
--- /dev/null
+++ b/llvm/test/Instrumentation/AddressSanitizer/asan-pass-second-run.ll
@@ -0,0 +1,56 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --check-globals all --version 5
+; This test checks in the second run, function is not instrumented again.
+; RUN: opt < %s -passes=asan,asan -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function with sanitize_address is instrumented.
+; Function Attrs: nounwind uwtable
+;.
+; CHECK: @llvm.used = appending global [1 x ptr] [ptr @asan.module_ctor], 
section "llvm.metadata"
+; CHECK: @___asan_globals_registered = common hidden global i64 0
+; CHECK: @__start_asan_globals = extern_weak hidden global i64
+; CHECK: @__stop_asan_globals = extern_weak hidden global i64
+; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, 
ptr, ptr } { i32 1, ptr @asan.module_ctor, ptr @asan.module_ctor }]
+;.
+define void @instr_sa(ptr %a) sanitize_address {
+; CHECK-LABEL: define void @instr_sa(
+; CHECK-SAME: ptr [[A:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:[[TMP0:%.*]] = ptrtoint ptr [[A]] to i64
+; CHECK-NEXT:[[TMP1:%.*]] = lshr i64 [[TMP0]], 3
+; CHECK-NEXT:[[TMP2:%.*]] = add i64 [[TMP1]], 2147450880
+; CHECK-NEXT:[[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr
+; CHECK-NEXT:[[TMP4:%.*]] = load i8, ptr [[TMP3]], align 1
+; CHECK-NEXT:[[TMP5:%.*]] = icmp ne i8 [[TMP4]], 0
+; CHECK-NEXT:br i1 [[TMP5]], label %[[BB6:.*]], label %[[BB12:.*]], !prof 
[[PROF0:![0-9]+]]
+; CHECK:   [[BB6]]:
+; CHECK-NEXT:[[TMP7:%.*]] = and i64 [[TMP0]], 7
+; CHECK-NEXT:[[TMP8:%.*]] = add i64 [[TMP7]], 3
+; CHECK-NEXT:[[TMP9:%.*]] = trunc i64 [[TMP8]] to i8
+; CHECK-NEXT:[[TMP10:%.*]] = icmp sge i8 [[TMP9]], [[TMP4]]
+; CHECK-NEXT:br i1 [[TMP10]], label %[[BB11:.*]], label %[[BB12]]
+; CHECK:   [[BB11]]:
+; CHECK-NEXT:call void @__asan_report_load4(i64 [[TMP0]]) #[[ATTR3:[0-9]+]]
+; CHECK-NEXT:unreachable
+; CHECK:   [[BB12]]:
+; CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[A]], align 4
+; CHECK-NEXT:[[TMP2:%.*]] = add i32 [[TMP1]], 1
+; CHECK-NEXT:store i32 [[TMP2]], ptr [[A]], align 4
+; CHECK-NEXT:ret void
+;
+entry:
+  %tmp1 = load i32, ptr %a, align 4
+  %tmp2 = add i32 %tmp1,  1
+  store i32 %tmp2, ptr %a, align 4
+  ret void
+}
+;.
+; CHECK: attributes #[[ATTR0]] = { sanitize_address }
+; CHECK: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind 
speculatable willreturn memory(none) }
+; CHECK: attributes #[[ATTR2:[0-9]+]] = { nounwind }
+; CHECK: attributes #[[ATTR3]] = { nomerge }
+;.
+; CHECK: [[PROF0]] = !{!"branch_weights", i32 1, i32 1048575}
+;.

>From 6552d844ab844b60fb29b1dcaf70905484075dbd Mon Sep 17 00:00:00 2001
From: skc7 
Date: Mon, 22 Jul 2024 15:41:25 +0530
Subject: [PATCH 2/7] [ASAN] Use nosanitize module flag.

---
 .../Instrumentation/AddressSanitizer.cpp  | 12 
 .../AddressSanitizer/asan-pass-second-run.ll  | 15 +++
 .../AddressSanitizer/missing_dbg.l

[clang] 8d4cb92 - [NFC][Clang][Interp] Add more test for `__builtin_os_log_format_buffer_size` (#100566)

2024-07-26 Thread via cfe-commits

Author: yronglin
Date: 2024-07-26T19:34:27+08:00
New Revision: 8d4cb92e3536e86b177c354c9c5cf6f06bd61c8d

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

LOG: [NFC][Clang][Interp] Add more test for 
`__builtin_os_log_format_buffer_size` (#100566)

Signed-off-by: yronglin 

Added: 


Modified: 
clang/test/AST/Interp/builtins.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/builtins.cpp 
b/clang/test/AST/Interp/builtins.cpp
index a74b68bb9d89b..9b2b20773be58 100644
--- a/clang/test/AST/Interp/builtins.cpp
+++ b/clang/test/AST/Interp/builtins.cpp
@@ -31,3 +31,8 @@ constexpr bool assume() {
   return true;
 }
 static_assert(assume(), "");
+
+void test_builtin_os_log(void *buf, int i, const char *data) {
+  constexpr int len = __builtin_os_log_format_buffer_size("%d %{public}s 
%{private}.16P", i, data, data);
+  static_assert(len > 0, "Expect len > 0");
+}



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


[clang] [NFC][Clang][Interp] Add more test for `__builtin_os_log_format_buffer_size` (PR #100566)

2024-07-26 Thread via cfe-commits

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


[clang] Avoid accessing unset optional, workaround for #100095 (PR #100408)

2024-07-26 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov approved this pull request.

LGTM, since it now has a test that executes this code path and changes from UB 
to defined (even if undesired behavior).

As mentioned earlier, I'm working on a proper fix for those cases

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


[clang] Avoid accessing unset optional, workaround for #100095 (PR #100408)

2024-07-26 Thread Ilya Biryukov via cfe-commits

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


[clang] [Clang] prevent checking destructor reference with an invalid initializer (PR #97860)

2024-07-26 Thread Oleksandr T. via cfe-commits

a-tarasyuk wrote:

@cor3ntin If no further feedback is needed, could you please proceed with the 
merge? Thanks

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


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2024-07-26 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman requested changes to this pull request.

Thank you for this! I think there's some work left to be done though.

1) Please add an extension warning (and tests for it) so users know where the 
extension is being used even if they opt into it explicitly. This is important 
for `-pedantic` mode.
2) This should be controllable via `-fms-extensions`/`-fno-ms-extensions`; 
having its own dialect flag is a bit novel but I'm not strongly opposed. CC 
@MaskRay @jansvoboda11 for driver/options opinions
3) Please document the extension in `clang/docs/LanguageExtensions.rst`

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


[clang] [clang-tools-extra] [llvm] [mlir] [clang][lldb][mlir] Fix some identical sub-expressions warnings (NFC) (PR #95715)

2024-07-26 Thread Shivam Gupta via cfe-commits


@@ -96,7 +96,7 @@ bool areStatementsIdentical(const Stmt *FirstStmt, const Stmt 
*SecondStmt,
   if (FirstStmt == SecondStmt)
 return true;
 
-  if (FirstStmt->getStmtClass() != FirstStmt->getStmtClass())
+  if (FirstStmt->getStmtClass() != SecondStmt->getStmtClass())

xgupta wrote:

@PiotrZSL If I removed this condition and ninja target still passes. Shall I 
remove this or can you provide a test case or guidance? I have this function is 
used in BranchCloneCheck.cpp but I am not sure how the test case look like. 

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


[clang] [clang-tools-extra] [llvm] [mlir] [clang][lldb][mlir] Fix some identical sub-expressions warnings (NFC) (PR #95715)

2024-07-26 Thread Shivam Gupta via cfe-commits


@@ -4368,7 +4368,7 @@ bool 
Sema::DiagRedefinedPlaceholderFieldDecl(SourceLocation Loc,
   Diag(Loc, diag::err_using_placeholder_variable) << Name;
   for (DeclContextLookupResult::iterator It = Found; It != Result.end(); It++) 
{
 const NamedDecl *ND = *It;
-if (ND->getDeclContext() != ND->getDeclContext())
+if (ND->getDeclContext() != ClassDecl->getDeclContext())

xgupta wrote:

I am not familiar with this part of code to add a testcase, and not even sure 
it is right fix. I will just remove this changes from this PR. 

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


[clang] [NFC][clang] Avoid unnecessary assignment (PR #100728)

2024-07-26 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang] [clang] Handle tm mangling on Solaris in PPMacroExpansion.cpp (PR #100724)

2024-07-26 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for helping out with this odd edge case! I don't suppose there's a 
way we can shove this hack into CMake (basically, like a kind of linker script 
hack)? If so, can we apply it broadly enough so that any use of `time_put` in 
other TUs will also benefit?

(If there are better alternatives than this approach, I'd love to hear about 
them, this is a pretty gnarly way to go about working around the issue.)

CC @petrhosek @MaskRay @efriedma-quic 

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


[clang] [llvm] [mlir] [clang][lldb][mlir] Fix some identical sub-expressions warnings (NFC) (PR #95715)

2024-07-26 Thread Shivam Gupta via cfe-commits

https://github.com/xgupta updated 
https://github.com/llvm/llvm-project/pull/95715

>From c30bfb621f413c7271bb5a02a7d699e68e053ba1 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Sun, 16 Jun 2024 23:39:47 +0530
Subject: [PATCH 1/4] [clang][lldb][mlir] Fix some identical sub-expressions
 warnings (NFC)

This is actually reported in 
https://pvs-studio.com/en/blog/posts/cpp/1126/, fragment N4-8

V501 There are identical sub-expressions 'FirstStmt->getStmtClass()' to the 
left and to the right of the '!=' operator. ASTUtils.cpp:99
V501 There are identical sub-expressions to the left and to the right of 
the '!=' operator: Fn1->isVariadic() != Fn1->isVariadic(). 
SemaOverload.cpp:10190
V501 There are identical sub-expressions to the left and to the right of 
the '<' operator: G1->Rank < G1->Rank. SCCIterator.h:285
V501 There are identical sub-expressions 'slice1.getMixedOffsets().size()' 
to the left and to the right of the '==' operator. 
ValueBoundsOpInterface.cpp:581
V501 There are identical sub-expressions 'slice1.getMixedSizes().size()' to 
the left and to the right of the '==' operator. ValueBoundsOpInterface.cpp:583
V501 There are identical sub-expressions 'slice1.getMixedStrides().size()' 
to the left and to the right of the '==' operator. 
ValueBoundsOpInterface.cpp:585
V501 There are identical sub-expressions 'slice1.getMixedOffsets().size()' 
to the left and to the right of the '==' operator. 
ValueBoundsOpInterface.cpp:646
V501 There are identical sub-expressions 'slice1.getMixedSizes().size()' to 
the left and to the right of the '==' operator. ValueBoundsOpInterface.cpp:648
V501 There are identical sub-expressions 'slice1.getMixedStrides().size()' 
to the left and to the right of the '==' operator. 
ValueBoundsOpInterface.cpp:650
V501 There are identical sub-expressions 'EltRange.getEnd() >= 
Range.getEnd()' to the left and to the right of the '||' operator. 
HTMLLogger.cpp:421
V501 There are identical sub-expressions 'SrcExpr.get()->containsErrors()' 
to the left and to the right of the '||' operator. SemaCast.cpp:2938
V501 There are identical sub-expressions 'ND->getDeclContext()' to the left 
and to the right of the '!=' operator. SemaDeclCXX.cpp:4391
V501 There are identical sub-expressions 'DepType != OMPC_DOACROSS_source' 
to the left and to the right of the '&&' operator. SemaOpenMP.cpp:24348
V501 There are identical sub-expressions '!OldMethod->isStatic()' to the 
left and to the right of the '&&' operator. SemaOverload.cpp:1425
V501 There are identical sub-expressions 'lldb::eTypeClassUnion' to the 
left and to the right of the '|' operator. JSONUtils.cpp:139
V501 There are identical sub-expressions to the left and to the right of 
the '&&' operator: !BFI &&!BFI. JumpThreading.cpp:2531
V501 There are identical sub-expressions 'BI->isConditional()' to the left 
and to the right of the '&&' operator. VPlanHCFGBuilder.cpp:401
V501 There are identical sub-expressions to the left and to the right of 
the '==' operator: getNumRows() == getNumRows(). Simplex.cpp:108
---
 clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp|  7 +++
 clang/lib/Sema/SemaCast.cpp|  3 +--
 clang/lib/Sema/SemaDeclCXX.cpp |  2 +-
 clang/lib/Sema/SemaOpenMP.cpp  |  3 +--
 llvm/lib/Transforms/Scalar/JumpThreading.cpp   |  2 +-
 llvm/lib/Transforms/Vectorize/VPlanHCFGBuilder.cpp |  2 +-
 mlir/lib/Analysis/Presburger/Simplex.cpp   |  2 +-
 mlir/lib/Interfaces/ValueBoundsOpInterface.cpp | 12 ++--
 8 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp 
b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
index a36cb41a63dfb..323f9698dc2aa 100644
--- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
+++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
@@ -430,11 +430,10 @@ class HTMLLogger : public Logger {
   AST.getSourceManager(), AST.getLangOpts());
   if (EltRange.isInvalid())
 continue;
-  if (EltRange.getBegin() < Range.getBegin() ||
-  EltRange.getEnd() >= Range.getEnd() ||
-  EltRange.getEnd() < Range.getBegin() ||
-  EltRange.getEnd() >= Range.getEnd())
+  if (EltRange.getEnd() <= Range.getBegin() ||
+  EltRange.getBegin() >= Range.getEnd())
 continue;
+
   unsigned Off = EltRange.getBegin().getRawEncoding() -
  Range.getBegin().getRawEncoding();
   unsigned Len = EltRange.getEnd().getRawEncoding() -
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index eca8363ee9605..18de4f6007d87 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -2945,8 +2945,7 @@ void CastOperation::CheckCStyleCast() {
   if (Self.getASTContext().isDependenceAllowed() &&
   (DestType->isDependentType() || SrcExpr.get()->is

[clang] [llvm] [mlir] [clang][lldb][mlir] Fix some identical sub-expressions warnings (NFC) (PR #95715)

2024-07-26 Thread Shivam Gupta via cfe-commits

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


[clang] c9c91f5 - Remove FiniteMathOnly and use only NoHonorINFs and NoHonorNANs. (#97342)

2024-07-26 Thread via cfe-commits

Author: Zahira Ammarguellat
Date: 2024-07-26T08:16:38-04:00
New Revision: c9c91f59c318e28d884e5762f303348ba5724d21

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

LOG: Remove FiniteMathOnly  and use only NoHonorINFs and NoHonorNANs. (#97342)

Currently `__FINITE_MATH_ONLY__` is set when `FiniteMathOnly`. And
`FiniteMathOnly` is set when `NoHonorInfs` && `NoHonorNans` is true. But
what happens one of the latter flags is false?
To avoid potential inconsistencies, the internal option `FiniteMathOnly`
is removed option and the macro `__FINITE_MATH_ONLY__` is set when
`NoHonorInfs` && `NoHonorNans`.

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Basic/LangOptions.cpp
clang/lib/Basic/Targets/OSTargets.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/CodeGen/finite-math.c
clang/test/CodeGen/fp-floatcontrol-stack.cpp
clang/test/CodeGen/fp-options-to-fast-math-flags.c
clang/test/CodeGen/nofpclass.c
clang/test/CodeGenOpenCL/relaxed-fpmath.cl
clang/test/Driver/opencl.cl
clang/test/Headers/__clang_hip_cmath.hip
clang/test/Headers/__clang_hip_math.hip
clang/test/Headers/float.c
clang/test/Preprocessor/predefined-macros.c
clang/test/Sema/warn-infinity-nan-disabled-lnx.cpp
clang/test/Sema/warn-infinity-nan-disabled-win.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 834a6f6cd43e3..0035092ce0d86 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -224,7 +224,6 @@ COMPATIBLE_LANGOPT(GNUInline , 1, 0, "GNU inline 
semantics")
 COMPATIBLE_LANGOPT(NoInlineDefine, 1, 0, "__NO_INLINE__ predefined macro")
 COMPATIBLE_LANGOPT(Deprecated, 1, 0, "__DEPRECATED predefined macro")
 COMPATIBLE_LANGOPT(FastMath  , 1, 0, "fast FP math optimizations, and 
__FAST_MATH__ predefined macro")
-COMPATIBLE_LANGOPT(FiniteMathOnly, 1, 0, "__FINITE_MATH_ONLY__ predefined 
macro")
 COMPATIBLE_LANGOPT(UnsafeFPMath  , 1, 0, "Unsafe Floating Point Math")
 COMPATIBLE_LANGOPT(ProtectParens , 1, 0, "optimizer honors parentheses "
"when floating-point expressions are evaluated")
@@ -340,7 +339,6 @@ LANGOPT(SinglePrecisionConstants , 1, 0, "treating 
double-precision floating poi
 LANGOPT(FastRelaxedMath , 1, 0, "OpenCL fast relaxed math")
 BENIGN_LANGOPT(CLNoSignedZero , 1, 0, "Permit Floating Point optimization 
without regard to signed zeros")
 COMPATIBLE_LANGOPT(CLUnsafeMath , 1, 0, "Unsafe Floating Point Math")
-COMPATIBLE_LANGOPT(CLFiniteMathOnly , 1, 0, "__FINITE_MATH_ONLY__ predefined 
macro")
 /// FP_CONTRACT mode (on/off/fast).
 BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP 
contraction type")
 COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating 
point")

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 26811bf948ae5..c95148fca 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1117,8 +1117,7 @@ def cl_single_precision_constant : Flag<["-"], 
"cl-single-precision-constant">,
   MarshallingInfoFlag>;
 def cl_finite_math_only : Flag<["-"], "cl-finite-math-only">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
-  HelpText<"OpenCL only. Allow floating-point optimizations that assume 
arguments and results are not NaNs or +-Inf.">,
-  MarshallingInfoFlag>;
+  HelpText<"OpenCL only. Allow floating-point optimizations that assume 
arguments and results are not NaNs or +-Inf.">;
 def cl_kernel_arg_info : Flag<["-"], "cl-kernel-arg-info">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"OpenCL only. Generate kernel argument metadata.">,
@@ -2609,13 +2608,12 @@ defm approx_func : BoolFOption<"approx-func", 
LangOpts<"ApproxFunc">, DefaultFal
"with an approximately equivalent calculation",
[funsafe_math_optimizations.KeyPath]>,
NegFlag>;
-defm finite_math_only : BoolFOption<"finite-math-only",
-  LangOpts<"FiniteMathOnly">, DefaultFalse,
+defm finite_math_only : BoolOptionWithoutMarshalling<"f", "finite-math-only",
   PosFlag,
+  [ffast_math.KeyPath]>,
   NegFlag>;
 defm signed_zeros : BoolFOption<"signed-zeros",
   LangOpts<"NoSignedZero">, DefaultFalse,
@@ -7815,10 +7813,10 @@ def mreassociate : Flag<["-"], "mreassociate">,
   MarshallingInfoFlag>, 
ImpliedByAnyOf<[funsafe_math_optimizations.KeyPath]>;
 def menable_no_nans : Flag<["-"], "menable-no-nans">,
   HelpText<"Allow optimization to assume there are no NaNs.">,
-  MarshallingInfoFlag>, 
ImpliedByAnyOf<[f

[clang] Remove FiniteMathOnly and use only NoHonorINFs and NoHonorNANs. (PR #97342)

2024-07-26 Thread Zahira Ammarguellat via cfe-commits

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


[clang] [clang] Handle tm mangling on Solaris in PPMacroExpansion.cpp (PR #100724)

2024-07-26 Thread Rainer Orth via cfe-commits

rorth wrote:

> Thank you for helping out with this odd edge case! I don't suppose there's a 
> way we can shove this hack into CMake (basically, like a kind of linker 
> script hack)? If so, can we apply it broadly enough so that any use of 
> `time_put` in other TUs will also benefit?

This would have to apply to all instances of `std::tm`, so I cannot say if this 
is feasible at all.  Besides, `clang` on Solaris supports both Solaris `ld` and 
GNU `ld`, which have different linker script syntax, duplicating the code if in 
fact both support the renaming.

This all seems like a waste of time to me.

> (If there are better alternatives than this approach, I'd love to hear about 
> them, this is a pretty gnarly way to go about working around the issue.)

I believe `clang` should something like `g++` to handle the mangling difference 
itself.  On the `g++` side of things, there's the 
`TARGET_CXX_DECL_MANGLING_CONTEXT` target hook, implemented for Solaris in 
`gcc/config/sol2-cxx.cc` (`solaris_cxx_decl_mangling_context`) and applied in 
`gcc/cp/mangle.cc` (`decl_mangling_context`) where it is called as 
`targetm.cxx.decl_mangling_context`.

As I've mentioned before, I've no idea where to do something similar in 
`clang`.  I believe that would be `clang/lib/CodeGen`

Whatever the case, we need at least a short-term solution now: the Solaris 
buildbots have been broken for two days now.


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


[clang] bfa0cae - [NFC][clang] Avoid unnecessary assignment (#100728)

2024-07-26 Thread via cfe-commits

Author: Mariya Podchishchaeva
Date: 2024-07-26T14:19:16+02:00
New Revision: bfa0cae31c1db7627c41dcebd660f5eaea796778

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

LOG: [NFC][clang] Avoid unnecessary assignment (#100728)

`IsStartOfLine` is set to false at the end of the loop.

Added: 


Modified: 
clang/lib/Frontend/PrintPreprocessedOutput.cpp

Removed: 




diff  --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp 
b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 0592423c12eca..135dca0e6a177 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -980,7 +980,6 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token 
&Tok,
 *Callbacks->OS << static_cast(*Iter);
 PrintComma = true;
   }
-  IsStartOfLine = true;
 } else if (Tok.isAnnotation()) {
   // Ignore annotation tokens created by pragmas - the pragmas themselves
   // will be reproduced in the preprocessed output.



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


[clang] [NFC][clang] Avoid unnecessary assignment (PR #100728)

2024-07-26 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-07-26 Thread via cfe-commits

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


[clang] 8322a30 - Avoid accessing unset optional, workaround for #100095 (#100408)

2024-07-26 Thread via cfe-commits

Author: Alexander Kornienko
Date: 2024-07-26T14:24:56+02:00
New Revision: 8322a3085c902de9759a40ccdcd194a4c46e7185

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

LOG: Avoid accessing unset optional, workaround for #100095 (#100408)

This patch avoids accessing an unset `std::optional<>`, which is a part
of the manifestation of #100095. The other part is an assertion failure
that is not addressed here. This is not a proper fix, but enables Clang
to continue working with more libc++ runtime checks enabled
(specifically, `-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST`,
which checks access to unset optionals among other things). A proper fix
is being discussed on #100095.

Added: 
clang/test/SemaCXX/pr100095.cpp

Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index b7b857ebf804b..db7f233dcef73 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -951,9 +951,11 @@ class PackDeductionScope {
 
 // Skip over the pack elements that were expanded into separate arguments.
 // If we partially expanded, this is the number of partial arguments.
+// FIXME: `&& FixedNumExpansions` is a workaround for UB described in
+// https://github.com/llvm/llvm-project/issues/100095
 if (IsPartiallyExpanded)
   PackElements += NumPartialPackArgs;
-else if (IsExpanded)
+else if (IsExpanded && FixedNumExpansions)
   PackElements += *FixedNumExpansions;
 
 for (auto &Pack : Packs) {

diff  --git a/clang/test/SemaCXX/pr100095.cpp b/clang/test/SemaCXX/pr100095.cpp
new file mode 100644
index 0..15913fec9d5ae
--- /dev/null
+++ b/clang/test/SemaCXX/pr100095.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s
+// XFAIL: asserts
+
+template  struct Pair;
+template  struct Tuple {
+  template  Tuple(_Up);
+};
+template  struct StatusOr;
+template  using ElementType = int;
+template 
+using Key = Tuple...>;
+template 
+StatusOr>> Parser();
+struct Helper { Helper(Tuple<>, Tuple<>, int, int); };
+struct D : Helper {
+  D(Key<> f, int n, int e) : Helper(f, Parser<>, n, e) {}
+};



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


[clang] Avoid accessing unset optional, workaround for #100095 (PR #100408)

2024-07-26 Thread Alexander Kornienko via cfe-commits

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


[clang] [Clang][NFC] Remove unnecessary copy (PR #100688)

2024-07-26 Thread via cfe-commits

smanna12 wrote:

Thank you @cor3ntin for reviews!

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


[clang] 6e0a913 - [Clang][NFC] Remove unnecessary copy (#100688)

2024-07-26 Thread via cfe-commits

Author: smanna12
Date: 2024-07-26T07:27:09-05:00
New Revision: 6e0a913973111926f9fdbd82b72ea640b013167e

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

LOG: [Clang][NFC] Remove unnecessary copy (#100688)

Reported by Static Analyzer Tool:

In Sema::checkIncorrectVTablePointerAuthenticationAttribute(): Using the
auto keyword without an & causes the copy of an object of type
CXXBaseSpecifier.

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 1cca8ac9b9343..5782daa041f32 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10385,7 +10385,7 @@ void 
Sema::checkIncorrectVTablePointerAuthenticationAttribute(
   while (1) {
 assert(PrimaryBase);
 const CXXRecordDecl *Base = nullptr;
-for (auto BasePtr : PrimaryBase->bases()) {
+for (const CXXBaseSpecifier &BasePtr : PrimaryBase->bases()) {
   if (!BasePtr.getType()->getAsCXXRecordDecl()->isDynamicClass())
 continue;
   Base = BasePtr.getType()->getAsCXXRecordDecl();



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


[clang] [Clang][NFC] Remove unnecessary copy (PR #100688)

2024-07-26 Thread via cfe-commits

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


[clang] [Clang] Remove `IDNS_Ordinary` flag in `IndirectFieldDecl::IdentifierNamespace` (PR #100525)

2024-07-26 Thread Aaron Ballman via cfe-commits

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

The C standard does not make this particularly clear, but the changes are 
correct.

Per C23 6.2.1p4 Each member of the structure has file scope (because why not) 
but per 6.2.3p1, each member is in a distinct name space and the member is 
disambiguated by the type of the expression used to access the member via the 
`.` or `->` operator. That last bit is why the member cannot be an ordinary 
identifier within the structure itself.

So LGTM, thank you!

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


[clang] [Clang] Remove `IDNS_Ordinary` flag in `IndirectFieldDecl::IdentifierNamespace` (PR #100525)

2024-07-26 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

Thank you for your review!

I don't have commit access. Please help me merge this PR if it's ready.

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


[clang] [Clang] Qualified functions can't decay into pointers (PR #90353)

2024-07-26 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

> https://cplusplus.github.io/CWG/issues/713.html

This one is entirely editorial: it adds a note and edits another note. I've 
added a test for what the note says

> https://cplusplus.github.io/CWG/issues/1417.html

I'm not sure that this DR actually changes anything. It seems 
pointers/references to function pointers were ill-formed before and remain 
ill-formed afterwards.

> https://cplusplus.github.io/CWG/issues/1584.html

Clang 7 implemented the 2015 resolution of this: 
413f3c55955537552b556a556d678d5756a9f16b

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


[clang] [Clang] Qualified functions can't decay into pointers (PR #90353)

2024-07-26 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/90353

>From d983badd09dcc227f5945f4b4759214b7b6adbf5 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Fri, 26 Jul 2024 08:44:19 +0100
Subject: [PATCH 1/4] [Clang] Qualified functions can't decay into pointers

---
 clang/docs/ReleaseNotes.rst   |  3 ++
 clang/include/clang/AST/Type.h|  4 +-
 clang/lib/AST/TypePrinter.cpp | 23 ++
 clang/lib/Sema/SemaDecl.cpp   |  7 +++
 clang/lib/Sema/SemaDeclCXX.cpp| 16 +--
 clang/lib/Sema/SemaTemplate.cpp   | 10 +++-
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 14 +-
 clang/lib/Sema/SemaType.cpp   | 46 +++
 .../dcl.decl/dcl.meaning/dcl.fct/p6-0x.cpp|  5 +-
 .../CXX/dcl.decl/dcl.meaning/dcl.fct/p6.cpp   |  5 +-
 clang/test/SemaCXX/function-type-qual.cpp | 36 ++-
 clang/test/SemaCXX/type-traits.cpp| 12 +
 12 files changed, 138 insertions(+), 43 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b165f6e65636d..f25f178bccf7f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -145,6 +145,9 @@ Bug Fixes in This Version
 - Fixed the definition of ``ATOMIC_FLAG_INIT`` in  so it can
   be used in C++.
 
+- cv- and ref- qualified function types no longer silently produce invalid 
pointer to
+  qualified function types when they implicitly decay in some places. Fixes 
(#GH27059).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 72723c7c56e07..fa5dac96b996d 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -5377,6 +5377,8 @@ class FunctionProtoType final
 return static_cast(FunctionTypeBits.RefQualifier);
   }
 
+  std::string getFunctionQualifiersAsString() const;
+
   using param_type_iterator = const QualType *;
 
   ArrayRef param_types() const {
@@ -7758,7 +7760,7 @@ inline bool QualType::isReferenceable() const {
   if (const auto *F = Self.getAs())
 return F->getMethodQuals().empty() && F->getRefQualifier() == RQ_None;
 
-  return false;
+  return Self.isFunctionType();
 }
 
 inline SplitQualType QualType::split() const {
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index ffec3ef9d2269..499e049923e2f 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2605,3 +2605,26 @@ raw_ostream &clang::operator<<(raw_ostream &OS, QualType 
QT) {
   TypePrinter(LangOptions()).print(S.Ty, S.Quals, OS, /*PlaceHolder=*/"");
   return OS;
 }
+
+std::string FunctionProtoType::getFunctionQualifiersAsString() const {
+  std::string Quals = getMethodQuals().getAsString();
+
+  switch (getRefQualifier()) {
+  case RQ_None:
+break;
+
+  case RQ_LValue:
+if (!Quals.empty())
+  Quals += ' ';
+Quals += '&';
+break;
+
+  case RQ_RValue:
+if (!Quals.empty())
+  Quals += ' ';
+Quals += "&&";
+break;
+  }
+
+  return Quals;
+}
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 575bd292f27de..123dc46c7d884 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15071,6 +15071,13 @@ ParmVarDecl *Sema::CheckParameter(DeclContext *DC, 
SourceLocation StartLoc,
 T = Context.getLifetimeQualifiedType(T, lifetime);
   }
 
+  if (T->isFunctionType() && !T.isReferenceable()) {
+Diag(NameLoc, diag::err_compound_qualified_function_type)
+<< 1 << true << T
+<< T->castAs()->getFunctionQualifiersAsString();
+return nullptr;
+  }
+
   ParmVarDecl *New = ParmVarDecl::Create(Context, DC, StartLoc, NameLoc, Name,
  Context.getAdjustedParameterType(T),
  TSInfo, SC, nullptr);
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 1cca8ac9b9343..58b21a1d6f33e 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11123,7 +11123,8 @@ void Sema::CheckConversionDeclarator(Declarator &D, 
QualType &R,
 D.setInvalidType();
   } else if (ConvType->isFunctionType()) {
 Diag(D.getIdentifierLoc(), diag::err_conv_function_to_function);
-ConvType = Context.getPointerType(ConvType);
+if (ConvType.isReferenceable())
+  ConvType = Context.getPointerType(ConvType);
 D.setInvalidType();
   }
 
@@ -16719,8 +16720,17 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S, 
TypeSourceInfo *TInfo,
   // Arrays and functions decay.
   if (ExDeclType->isArrayType())
 ExDeclType = Context.getArrayDecayedType(ExDeclType);
-  else if (ExDeclType->isFunctionType())
-ExDeclType = Context.getPointerType(ExDeclType);
+  else if (ExDeclType->isFunctionType()) {
+if (ExDeclType.isReferenceable())
+  ExDeclType = Context.getPointerType(ExDeclType

[clang] 9d22095 - [Clang] Remove `IDNS_Ordinary` flag in `IndirectFieldDecl::IdentifierNamespace` (#100525)

2024-07-26 Thread via cfe-commits

Author: Yanzuo Liu
Date: 2024-07-26T08:39:46-04:00
New Revision: 9d220956320a36fd127ee14ed41f0ecdcc0fb5b0

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

LOG: [Clang] Remove `IDNS_Ordinary` flag in 
`IndirectFieldDecl::IdentifierNamespace` (#100525)

There is a `IDNS_Ordinary` flag in
`IndirectFieldDecl::IdentifierNamespace` so that members in nested
anonymous struct/union can be found as ordinary identifiers.

```c
struct S {
  struct { int x; };
  // Previous behaviour: `x` in previous line is found
  // Expected: nothing is found
  int arr[sizeof(x)];
};
```

This PR fixes this issue.

Fixes #31295.

Added: 
clang/test/Parser/namelookup-anonymous-struct.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/DeclBase.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b165f6e65636d..286f319d41a23 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -166,6 +166,9 @@ Miscellaneous Bug Fixes
 Miscellaneous Clang Crashes Fixed
 ^
 
+- Fixed a crash in C due to incorrect lookup that members in nested anonymous 
struct/union
+  can be found as ordinary identifiers in struct/union definition. (#GH31295)
+
 OpenACC Specific Changes
 
 

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index bc5a9206c0db2..a1f70546bde42 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -879,8 +879,6 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) 
{
   return IDNS_Ordinary;
 case Label:
   return IDNS_Label;
-case IndirectField:
-  return IDNS_Ordinary | IDNS_Member;
 
 case Binding:
 case NonTypeTemplateParm:
@@ -918,6 +916,7 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) 
{
   return IDNS_ObjCProtocol;
 
 case Field:
+case IndirectField:
 case ObjCAtDefsField:
 case ObjCIvar:
   return IDNS_Member;

diff  --git a/clang/test/Parser/namelookup-anonymous-struct.c 
b/clang/test/Parser/namelookup-anonymous-struct.c
new file mode 100644
index 0..cb691c22f97ff
--- /dev/null
+++ b/clang/test/Parser/namelookup-anonymous-struct.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c11 -verify %s
+
+struct GH31295 {
+  struct { int x; };
+  int arr[sizeof(x)]; // expected-error{{use of undeclared identifier 'x'}}
+};



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


[clang] [Clang] Remove `IDNS_Ordinary` flag in `IndirectFieldDecl::IdentifierNamespace` (PR #100525)

2024-07-26 Thread Aaron Ballman via cfe-commits

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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-07-26 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

I've just found out "accepted" is a resolved DR, not open: 
https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#Issue%20Status

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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-07-26 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/97200

>From 0dea95701ca4dfca9b7d0bd889003fc35aa3017e Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 30 Jun 2024 10:39:15 +0100
Subject: [PATCH 01/13] [NFC] [Clang] Some core issues have changed status from
 tentatively ready -> ready / review

---
 clang/test/CXX/drs/cwg25xx.cpp |   2 +-
 clang/test/CXX/drs/cwg28xx.cpp |  16 ++--
 clang/www/cxx_dr_status.html   | 130 +++--
 clang/www/make_cxx_dr_status   |   6 +-
 4 files changed, 104 insertions(+), 50 deletions(-)

diff --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp
index 0934f0cc19c6a..5f8a058f8157a 100644
--- a/clang/test/CXX/drs/cwg25xx.cpp
+++ b/clang/test/CXX/drs/cwg25xx.cpp
@@ -139,7 +139,7 @@ struct D3 : B {
 #endif
 
 #if __cplusplus >= 202302L
-namespace cwg2561 { // cwg2561: no tentatively ready 2024-03-18
+namespace cwg2561 { // cwg2561: no ready 2024-03-18
 struct C {
 constexpr C(auto) { }
 };
diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp
index c77bd433d8e21..524e67b52de51 100644
--- a/clang/test/CXX/drs/cwg28xx.cpp
+++ b/clang/test/CXX/drs/cwg28xx.cpp
@@ -30,7 +30,7 @@ using U2 = decltype(&main);
 #endif
 } // namespace cwg2811
 
-namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01
+namespace cwg2819 { // cwg2819: 19 ready 2023-12-01
 #if __cpp_constexpr >= 202306L
   constexpr void* p = nullptr;
   constexpr int* q = static_cast(p);
@@ -111,7 +111,7 @@ struct D : N::B {
 #endif
 } // namespace cwg2857
 
-namespace cwg2858 { // cwg2858: 19 tentatively ready 2024-04-05
+namespace cwg2858 { // cwg2858: 19 ready 2024-04-05
 
 #if __cplusplus > 202302L
 
@@ -134,7 +134,7 @@ struct A {
 
 } // namespace cwg2858
 
-namespace cwg2877 { // cwg2877: 19 tentatively ready 2024-05-31
+namespace cwg2877 { // cwg2877: 19 ready 2024-05-31
 #if __cplusplus >= 202002L
 enum E { x };
 void f() {
@@ -150,7 +150,7 @@ void g() {
 #endif
 } // namespace cwg2877
 
-namespace cwg2881 { // cwg2881: 19 tentatively ready 2024-04-19
+namespace cwg2881 { // cwg2881: 19 ready 2024-04-19
 
 #if __cplusplus >= 202302L
 
@@ -220,7 +220,7 @@ void f() {
 
 } // namespace cwg2881
 
-namespace cwg2882 { // cwg2882: 2.7 tentatively ready 2024-05-31
+namespace cwg2882 { // cwg2882: 2.7 ready 2024-05-31
 struct C {
   operator void() = delete;
   // expected-warning@-1 {{conversion function converting 'cwg2882::C' to 
'void' will never be used}}
@@ -232,7 +232,7 @@ void f(C c) {
 }
 } // namespace cwg2882
 
-namespace cwg2883 { // cwg2883: no tentatively ready 2024-05-31
+namespace cwg2883 { // cwg2883: no ready 2024-05-31
 #if __cplusplus >= 201103L
 void f() {
   int x;
@@ -257,7 +257,7 @@ void g() {
 #endif
 } // namespace cwg2883
 
-namespace cwg2885 { // cwg2885: 16 tentatively ready 2024-05-31
+namespace cwg2885 { // cwg2885: 16 review 2024-05-31
 #if __cplusplus >= 202002L
 template 
 struct A {
@@ -271,7 +271,7 @@ static_assert(!__is_trivially_constructible(B));
 #endif
 } // namespace cwg2885
 
-namespace cwg2886 { // cwg2886: 9 tentatively ready 2024-05-31
+namespace cwg2886 { // cwg2886: 9 ready 2024-05-31
 #if __cplusplus >= 201103L
 struct C {
   C() = default;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 937f67981e296..64b361976a5a5 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1442,7 +1442,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/233.html";>233
-tentatively ready
+ready
 References vs pointers in UDC overload resolution
 Not resolved
   
@@ -7329,11 +7329,11 @@ C++ defect report implementation 
status
 Overloading member function templates based on dependent return 
type
 Unknown
   
-  
+  
 https://cplusplus.github.io/CWG/issues/1253.html";>1253
-open
+C++17
 Generic non-template members
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/1254.html";>1254
@@ -12677,7 +12677,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2144.html";>2144
-tentatively ready
+ready
 Function/variable declaration ambiguity
 Not resolved
   
@@ -15179,7 +15179,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2561.html";>2561
-tentatively ready
+ready
 Conversion to function pointer for lambda with explicit object 
parameter
 Not Resolved*
   
@@ -15341,7 +15341,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2588.html";>2588
-tentatively ready
+ready
 friend declarations and module linkage
 Not resolved
   
@@ -15541,7 +15541,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2621.html";>2621
 C++23
 Kind of lookup for using enum declarations
-Superseded by 287

[clang] [Clang] Qualified functions can't decay into pointers (PR #90353)

2024-07-26 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang] Qualified functions can't decay into pointers (PR #90353)

2024-07-26 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

Current CWG713 behavior was introduced sometime after Clang 18, and is not 
affected by this patch.
Current CWG1584 behavior was introduced in Clang 7, and is also not affected by 
this patch. (https://godbolt.org/z/xYec9rP5x)
This PR is large enough already. I suggest to move those tests out to a 
separate PR.


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


[clang] [Clang] Qualified functions can't decay into pointers (PR #90353)

2024-07-26 Thread Vlad Serebrennikov via cfe-commits


@@ -71,6 +76,17 @@ namespace cwg712 { // cwg712: partial
 #endif
 }
 
+namespace cwg713 { // cwg713: yes

Endilll wrote:

Please, run your test through various Clang versions before claiming 
availability. In this case, this is rejected by 18, but accepted on trunk: 
https://godbolt.org/z/dbq67deWE
So the right status might be 19 or 20 depending on when we started to accept 
this.

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


[clang] [Clang] Qualified functions can't decay into pointers (PR #90353)

2024-07-26 Thread Vlad Serebrennikov via cfe-commits


@@ -71,6 +76,17 @@ namespace cwg712 { // cwg712: partial
 #endif
 }
 
+namespace cwg713 { // cwg713: yes
+static_assert(!__is_const(void()const), "");
+static_assert(!__is_const(void()const&), "");
+// cxx98-error@-1 {{reference qualifiers on functions are a C++11 extension}}

Endilll wrote:

I think this test and another one later should be hidden behind `#ifdef 
__cplusplus`

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


[clang] [C++20][Modules] Allow using stdarg.h with header units (PR #100739)

2024-07-26 Thread Dmitry Polukhin via cfe-commits

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

Summary:
Macro like `va_start`/`va_end` marked as builtin functions that makes these 
identifiers special and it results in redefinition of the identifiers as 
builtins and it hides macro definitions during preloading C++ modules. In case 
of modules Clang ignores special identifiers but `PP.getCurrentModule()` was 
not set. This diff fixes IsModule detection logic for this particular case.

Test Plan: check-clang

>From edc7f5c84caefeae197a5884c91ec2194fd3148b Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 26 Jul 2024 05:02:52 -0700
Subject: [PATCH] [C++20][Modules] Allow using stdarg.h with header units

Summary:
Macro like `va_start`/`va_end` marked as builtin functions that makes
these identifiers special and it results in false redifinition for the
identifiers and hides macro definitions.

Test Plan: check-clang
---
 clang/lib/Serialization/ASTReader.cpp |  9 
 clang/test/Headers/stdarg-cxx-modules.cpp | 27 +++
 2 files changed, 31 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Headers/stdarg-cxx-modules.cpp

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 3cb96df12e4da..f3e8027526f6a 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1051,10 +1051,9 @@ IdentifierID 
ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d)
   return Reader.getGlobalIdentifierID(F, RawID >> 1);
 }
 
-static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II) {
+static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II, bool 
IsModule) {
   if (!II.isFromAST()) {
 II.setIsFromAST();
-bool IsModule = Reader.getPreprocessor().getCurrentModule() != nullptr;
 if (isInterestingIdentifier(Reader, II, IsModule))
   II.setChangedSinceDeserialization();
   }
@@ -1080,7 +1079,7 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const 
internal_key_type& k,
 II = &Reader.getIdentifierTable().getOwn(k);
 KnownII = II;
   }
-  markIdentifierFromAST(Reader, *II);
+  markIdentifierFromAST(Reader, *II, 
Reader.getPreprocessor().getCurrentModule() != nullptr);
   Reader.markIdentifierUpToDate(II);
 
   IdentifierID ID = Reader.getGlobalIdentifierID(F, RawID);
@@ -4543,7 +4542,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef 
FileName, ModuleKind Type,
 
   // Mark this identifier as being from an AST file so that we can track
   // whether we need to serialize it.
-  markIdentifierFromAST(*this, *II);
+  markIdentifierFromAST(*this, *II, true);
 
   // Associate the ID with the identifier so that the writer can reuse it.
   auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first);
@@ -8961,7 +8960,7 @@ IdentifierInfo 
*ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
 auto Key = Trait.ReadKey(Data, KeyDataLen.first);
 auto &II = PP.getIdentifierTable().get(Key);
 IdentifiersLoaded[Index] = &II;
-markIdentifierFromAST(*this,  II);
+markIdentifierFromAST(*this,  II, getPreprocessor().getCurrentModule() != 
nullptr);
 if (DeserializationListener)
   DeserializationListener->IdentifierRead(ID, &II);
   }
diff --git a/clang/test/Headers/stdarg-cxx-modules.cpp 
b/clang/test/Headers/stdarg-cxx-modules.cpp
new file mode 100644
index 0..b7c4486c89374
--- /dev/null
+++ b/clang/test/Headers/stdarg-cxx-modules.cpp
@@ -0,0 +1,27 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header h1.h
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header h2.h 
-fmodule-file=h1.pcm
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only main.cpp -fmodule-file=h1.pcm 
-fmodule-file=h2.pcm
+
+//--- h1.h
+#pragma once
+#include 
+// expected-no-diagnostics
+
+//--- h2.h
+#pragma once
+import "h1.h";
+// expected-no-diagnostics
+
+//--- main.cpp
+import "h1.h";
+import "h2.h";
+
+void foo(int x, ...) {
+  va_list v;
+  va_start(v, x);
+  va_end(v);
+}
+// expected-no-diagnostics

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


[clang] [C++20][Modules] Allow using stdarg.h with header units (PR #100739)

2024-07-26 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: Dmitry Polukhin (dmpolukhin)


Changes

Summary:
Macro like `va_start`/`va_end` marked as builtin functions that makes these 
identifiers special and it results in redefinition of the identifiers as 
builtins and it hides macro definitions during preloading C++ modules. In case 
of modules Clang ignores special identifiers but `PP.getCurrentModule()` was 
not set. This diff fixes IsModule detection logic for this particular case.

Test Plan: check-clang

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


2 Files Affected:

- (modified) clang/lib/Serialization/ASTReader.cpp (+4-5) 
- (added) clang/test/Headers/stdarg-cxx-modules.cpp (+27) 


``diff
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 3cb96df12e4da..f3e8027526f6a 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1051,10 +1051,9 @@ IdentifierID 
ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d)
   return Reader.getGlobalIdentifierID(F, RawID >> 1);
 }
 
-static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II) {
+static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II, bool 
IsModule) {
   if (!II.isFromAST()) {
 II.setIsFromAST();
-bool IsModule = Reader.getPreprocessor().getCurrentModule() != nullptr;
 if (isInterestingIdentifier(Reader, II, IsModule))
   II.setChangedSinceDeserialization();
   }
@@ -1080,7 +1079,7 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const 
internal_key_type& k,
 II = &Reader.getIdentifierTable().getOwn(k);
 KnownII = II;
   }
-  markIdentifierFromAST(Reader, *II);
+  markIdentifierFromAST(Reader, *II, 
Reader.getPreprocessor().getCurrentModule() != nullptr);
   Reader.markIdentifierUpToDate(II);
 
   IdentifierID ID = Reader.getGlobalIdentifierID(F, RawID);
@@ -4543,7 +4542,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef 
FileName, ModuleKind Type,
 
   // Mark this identifier as being from an AST file so that we can track
   // whether we need to serialize it.
-  markIdentifierFromAST(*this, *II);
+  markIdentifierFromAST(*this, *II, true);
 
   // Associate the ID with the identifier so that the writer can reuse it.
   auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first);
@@ -8961,7 +8960,7 @@ IdentifierInfo 
*ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
 auto Key = Trait.ReadKey(Data, KeyDataLen.first);
 auto &II = PP.getIdentifierTable().get(Key);
 IdentifiersLoaded[Index] = &II;
-markIdentifierFromAST(*this,  II);
+markIdentifierFromAST(*this,  II, getPreprocessor().getCurrentModule() != 
nullptr);
 if (DeserializationListener)
   DeserializationListener->IdentifierRead(ID, &II);
   }
diff --git a/clang/test/Headers/stdarg-cxx-modules.cpp 
b/clang/test/Headers/stdarg-cxx-modules.cpp
new file mode 100644
index 0..b7c4486c89374
--- /dev/null
+++ b/clang/test/Headers/stdarg-cxx-modules.cpp
@@ -0,0 +1,27 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header h1.h
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header h2.h 
-fmodule-file=h1.pcm
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only main.cpp -fmodule-file=h1.pcm 
-fmodule-file=h2.pcm
+
+//--- h1.h
+#pragma once
+#include 
+// expected-no-diagnostics
+
+//--- h2.h
+#pragma once
+import "h1.h";
+// expected-no-diagnostics
+
+//--- main.cpp
+import "h1.h";
+import "h2.h";
+
+void foo(int x, ...) {
+  va_list v;
+  va_start(v, x);
+  va_end(v);
+}
+// expected-no-diagnostics

``




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


[clang] [C++20][Modules] Allow using stdarg.h with header units (PR #100739)

2024-07-26 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 38d0b2d174efe05504a18988299b4d78d37999b7 
edc7f5c84caefeae197a5884c91ec2194fd3148b --extensions cpp -- 
clang/test/Headers/stdarg-cxx-modules.cpp clang/lib/Serialization/ASTReader.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index f3e8027526..76f08e4fe7 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1051,7 +1051,8 @@ IdentifierID 
ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d)
   return Reader.getGlobalIdentifierID(F, RawID >> 1);
 }
 
-static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II, bool 
IsModule) {
+static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II,
+  bool IsModule) {
   if (!II.isFromAST()) {
 II.setIsFromAST();
 if (isInterestingIdentifier(Reader, II, IsModule))
@@ -1079,7 +1080,8 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const 
internal_key_type& k,
 II = &Reader.getIdentifierTable().getOwn(k);
 KnownII = II;
   }
-  markIdentifierFromAST(Reader, *II, 
Reader.getPreprocessor().getCurrentModule() != nullptr);
+  markIdentifierFromAST(Reader, *II,
+Reader.getPreprocessor().getCurrentModule() != 
nullptr);
   Reader.markIdentifierUpToDate(II);
 
   IdentifierID ID = Reader.getGlobalIdentifierID(F, RawID);
@@ -8960,7 +8962,8 @@ IdentifierInfo 
*ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
 auto Key = Trait.ReadKey(Data, KeyDataLen.first);
 auto &II = PP.getIdentifierTable().get(Key);
 IdentifiersLoaded[Index] = &II;
-markIdentifierFromAST(*this,  II, getPreprocessor().getCurrentModule() != 
nullptr);
+markIdentifierFromAST(*this, II,
+  getPreprocessor().getCurrentModule() != nullptr);
 if (DeserializationListener)
   DeserializationListener->IdentifierRead(ID, &II);
   }

``




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


[clang] [Clang] Remove `IDNS_Ordinary` flag in `IndirectFieldDecl::IdentifierNamespace` (PR #100525)

2024-07-26 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

> I don’t believe the standard supports anonymous structs in C++

Do we need tests about anonymous union? C++ standard supports it.

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


  1   2   3   4   >