[clang] [clang] pointer to member with qualified-id enclosed in parentheses in unevaluated context should be invalid (PR #89713)

2024-05-01 Thread via cfe-commits


@@ -27,3 +26,20 @@ namespace rdar10544564 {
   X (Y::*func_mem_ptr1)() = ::memfunc1;
   X (Y::*func_mem_ptr2)() = ::memfunc2;
 }
+
+namespace test2 {
+  struct A {
+int val;
+void func() {}
+  };
+
+  void test() {
+decltype(&(A::val)) ptr1; // expected-error {{invalid use of non-static 
data member 'val'}}
+int A::* ptr2 = &(A::val); // expected-error {{invalid use of non-static 
data member 'val'}}
+
+// FIXME: Error messages in these cases are less than clear, we can do
+// better.
+int size = sizeof(&(A::func)); // expected-error {{call to non-static 
member function without an object argument}}
+void (A::* ptr3)() = &(A::func); // expected-error {{call to non-static 
member function without an object argument}}

zwuis wrote:

> I think creating an issue, or a new PR is the way to go. Would that work for 
> you?

Yes. Issue made: #90822. I will create PR in a few days.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

This solves some ambuguity introduced in P0522 regarding how template template 
parameters are partially ordered, and should reduce the negative impact of 
enabling `-frelaxed-template-template-args` by default.

A template template parameter containing no packs should be more specialized 
than one that does.

Given the following example:
```C++
templateclass T2 struct A;
templatetemplateclass ...T3s class TT1, class T4 struct 
ATT1T4; #1
templatetemplateclassT5  class TT2, class T6 struct 
ATT2T6; #2

templateclass T1 struct B;
template struct ABchar;
```

Prior to P0522, #2 would be the only viable candidate. After P0522, 
#1 is also viable, and neither is considered more specialized, so this 
becomes ambiguous.
With this change, #2 is considered more specialized, so that is what is 
picked and we remain compatible with pre-P0522 implementations.

The problem we solve here is that the specialization rules in 
`[temp.arg.template]/4` are defined in terms of a rewrite to function 
templates, but in the case of partial ordering, the rules on how P and A lists 
are matched to each other is swapped regarding how specialization makes sense 
conceptually.

---

Since this changes provisional implementation of CWG2398 which has not been 
released yet, and already contains a changelog entry, we don't provide a 
changelog entry here.

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


4 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+3-2) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+6-4) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+59-20) 
- (modified) clang/test/SemaTemplate/cwg2398.cpp (-6) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a80ac6dbc76137..2bea8732f61fcd 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9238,7 +9238,7 @@ class Sema final : public SemaBase {
CheckTemplateArgumentKind CTAK);
   bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc );
+ TemplateArgumentLoc , bool IsDeduced);
 
   void NoteTemplateLocation(const NamedDecl ,
 std::optional ParamRange = {});
@@ -9708,7 +9708,8 @@ class Sema final : public SemaBase {
 sema::TemplateDeductionInfo );
 
   bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
-  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc);
+  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc,
+  bool IsDeduced);
 
   void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced,
   unsigned Depth, llvm::SmallBitVector );
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 989f3995ca5991..2c921d4365db0a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6384,7 +6384,8 @@ bool Sema::CheckTemplateArgument(
 
   case TemplateArgument::Template:
   case TemplateArgument::TemplateExpansion:
-if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
+if (CheckTemplateTemplateArgument(TempParm, Params, Arg,
+  /*IsDeduced=*/CTAK != CTAK_Specified))
   return true;
 
 SugaredConverted.push_back(Arg.getArgument());
@@ -8296,7 +8297,8 @@ static void DiagnoseTemplateParameterListArityMismatch(
 /// It returns true if an error occurred, and false otherwise.
 bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc ) {
+ TemplateArgumentLoc ,
+ bool IsDeduced) {
   TemplateName Name = Arg.getArgument().getAsTemplateOrTemplatePattern();
   TemplateDecl *Template = Name.getAsTemplateDecl();
   if (!Template) {
@@ -8348,8 +8350,8 @@ bool 
Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
 !Template->hasAssociatedConstraints())
   return false;
 
-if (isTemplateTemplateParameterAtLeastAsSpecializedAs(Params, Template,
-  Arg.getLocation())) {
+if (isTemplateTemplateParameterAtLeastAsSpecializedAs(
+Params, Template, Arg.getLocation(), IsDeduced)) {
   // P2113
   // C++20[temp.func.order]p2
   //   [...] If both deductions succeed, the partial ordering selects the
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 9f9e4422827173..4fbaecd7dba960 100644
--- 

[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-01 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/90820

This solves some ambuguity introduced in P0522 regarding how template template 
parameters are partially ordered, and should reduce the negative impact of 
enabling `-frelaxed-template-template-args` by default.

A template template parameter containing no packs should be more specialized 
than one that does.

Given the following example:
```C++
template struct A;
template class TT1, class T4> struct A>; #1
template class TT2, class T6> struct A>; #2

template struct B;
template struct A>;
```

Prior to P0522, #2 would be the only viable candidate. After P0522, #1 is also 
viable, and neither is considered more specialized, so this becomes ambiguous.
With this change, #2 is considered more specialized, so that is what is picked 
and we remain compatible with pre-P0522 implementations.

The problem we solve here is that the specialization rules in 
`[temp.arg.template]/4` are defined in terms of a rewrite to function 
templates, but in the case of partial ordering, the rules on how P and A lists 
are matched to each other is swapped regarding how specialization makes sense 
conceptually.

---

Since this changes provisional implementation of CWG2398 which has not been 
released yet, and already contains a changelog entry, we don't provide a 
changelog entry here.

>From b7df9a342724479e129af252f2ff37229f30d41b Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 1 May 2024 22:29:45 -0300
Subject: [PATCH] [clang] Implement provisional wording for CWG2398 regarding
 packs

This solves some ambuguity introduced in P0522 regarding how
template template parameters are partially ordered, and should reduce
the negative impact of enabling `-frelaxed-template-template-args`
by default.

A template template parameter containing no packs should be more
specialized than one that does.

Given the following example:
```C++
template struct A;
template class TT1, class T4> struct A>; #1
template class TT2, class T6> struct A>; #2

template struct B;
template struct A>;
```

Prior to P0522, #2 would be the only viable candidate.
After P0522, #1 is also viable, and neither is considered more specialized,
so this becomes ambiguous.
With this change, #2 is considered more specialized, so that is what is picked
and we remain compatible with pre-P0522 implementations.

The problem we solve here is that the specialization rules in
`[temp.arg.template]/4` are defined in terms of a rewrite to
function templates, but in the case of partial ordering, the
rules on how P and A lists are matched to each other
is swapped regarding how specialization makes sense conceptually.

---

Since this changes provisional implementation of CWG2398 which has
not been released yet, and already contains a changelog entry,
we don't provide a changelog entry here.
---
 clang/include/clang/Sema/Sema.h  |  5 +-
 clang/lib/Sema/SemaTemplate.cpp  | 10 +--
 clang/lib/Sema/SemaTemplateDeduction.cpp | 79 ++--
 clang/test/SemaTemplate/cwg2398.cpp  |  6 --
 4 files changed, 68 insertions(+), 32 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a80ac6dbc76137..2bea8732f61fcd 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9238,7 +9238,7 @@ class Sema final : public SemaBase {
CheckTemplateArgumentKind CTAK);
   bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc );
+ TemplateArgumentLoc , bool IsDeduced);
 
   void NoteTemplateLocation(const NamedDecl ,
 std::optional ParamRange = {});
@@ -9708,7 +9708,8 @@ class Sema final : public SemaBase {
 sema::TemplateDeductionInfo );
 
   bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
-  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc);
+  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc,
+  bool IsDeduced);
 
   void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced,
   unsigned Depth, llvm::SmallBitVector );
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 989f3995ca5991..2c921d4365db0a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6384,7 +6384,8 @@ bool Sema::CheckTemplateArgument(
 
   case TemplateArgument::Template:
   case TemplateArgument::TemplateExpansion:
-if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
+if (CheckTemplateTemplateArgument(TempParm, Params, Arg,
+  /*IsDeduced=*/CTAK != CTAK_Specified))
   return true;
 
 SugaredConverted.push_back(Arg.getArgument());
@@ -8296,7 

[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

2024-05-01 Thread Matheus Izvekov via cfe-commits

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


[clang] b86e099 - [clang] Enable C++17 relaxed template template argument matching by default (#89807)

2024-05-01 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-05-02T02:02:35-03:00
New Revision: b86e0992bfa6c58be077d82d824016f590ac5d90

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

LOG: [clang] Enable C++17 relaxed template template argument matching by 
default (#89807)

This patch will finally allow us to mark C++17 support in clang as
complete.

In order to implement this as a DR and avoid breaking reasonable code
that worked before P0522, this patch implements a provisional resolution
for CWG2398: When deducing template template parameters against each other,
and the argument side names a template specialization, instead of just
deducing A, we deduce a synthesized template template parameter based
on A, but with it's parameters using the template specialization's arguments
as defaults.

The driver flag is deprecated with a warning.

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

Added: 
clang/test/Driver/frelaxed-template-template-args.cpp
clang/test/SemaTemplate/cwg2398.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/SanitizerArgs.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
clang/test/CodeGenCXX/mangle-concept.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/SemaTemplate/default-arguments.cpp
clang/test/SemaTemplate/instantiate-template-template-parm.cpp
clang/test/SemaTemplate/nested-template.cpp
clang/test/SemaTemplate/temp_arg_template.cpp
clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0e3f7cf89ca885..d402babc8aaa6c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -48,6 +48,11 @@ C++ Specific Potentially Breaking Changes
 - Clang now diagnoses function/variable templates that shadow their own 
template parameters, e.g. ``template void T();``.
   This error can be disabled via `-Wno-strict-primary-template-shadow` for 
compatibility with previous versions of clang.
 
+- The behavior controlled by the `-frelaxed-template-template-args` flag is now
+  on by default, and the flag is deprecated. Until the flag is finally removed,
+  it's negative spelling can be used to obtain compatibility with previous
+  versions of clang.
+
 ABI Changes in This Version
 ---
 - Fixed Microsoft name mangling of implicitly defined variables used for thread
@@ -94,6 +99,17 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- C++17 support is now completed, with the enablement of the
+  relaxed temlate template argument matching rules introduced in P0522,
+  which was retroactively applied as a defect report.
+  While the implementation already existed since Clang 4, it was turned off by
+  default, and was controlled with the `-frelaxed-template-template-args` flag.
+  In this release, we implement provisional wording for a core defect on
+  P0522 (CWG2398), which avoids the most serious compatibility issues caused
+  by it, allowing us to enable it by default in this release.
+  The flag is now deprecated, and will be removed in the next release, but can
+  still be used to turn it off and regain compatibility with previous versions
+  (#GH36505).
 - Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang 
extension with ``unsigned`` modifiers also allowed. (#GH85223).
 
 C++17 Feature Support
@@ -173,6 +189,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 
`_).
 
+- P0522 implementation is enabled by default in all language versions, and
+  provisional wording for CWG2398 is implemented.
+
 C Language Changes
 --
 

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index ed3fd9b1c4a55b..9781fcaa4ff5e9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -435,7 +435,7 @@ def warn_drv_diagnostics_misexpect_requires_pgo : Warning<
 def warn_drv_clang_unsupported : Warning<
   "the clang compiler does not support '%0'">;
 def warn_drv_deprecated_arg : Warning<
-  "argument '%0' is deprecated, use '%1' instead">, InGroup;
+  "argument '%0' is 

[clang] [llvm] [DirectX][DXIL] Set DXIL Version in DXIL target triple based on shader model version (PR #90809)

2024-05-01 Thread Xiang Li via cfe-commits


@@ -760,7 +760,7 @@ using namespace clang::targets;
 TargetInfo *
 TargetInfo::CreateTargetInfo(DiagnosticsEngine ,
  const std::shared_ptr ) {
-  llvm::Triple Triple(Opts->Triple);
+  llvm::Triple Triple(llvm::Triple::normalize(Opts->Triple));

python3kgae wrote:

I see. It is trying to add subarch for dxil.
Could we allow Triple::NoSubArch for dxil?
Backend could do the job to translate NoSubArch to the version based on shader 
model.

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Ignore methods of WTF String classes. (PR #90704)

2024-05-01 Thread Ryosuke Niwa via cfe-commits

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


[clang] df91cde - [alpha.webkit.UncountedCallArgsChecker] Ignore methods of WTF String classes. (#90704)

2024-05-01 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-05-01T20:29:25-07:00
New Revision: df91cde4da62aec22e4d384b1bc800590c7f561a

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

LOG: [alpha.webkit.UncountedCallArgsChecker] Ignore methods of WTF String 
classes. (#90704)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp
clang/test/Analysis/Checkers/WebKit/mock-types.h

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index ae494de58da3da..0f40ecc7ba3000 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -227,10 +227,17 @@ class UncountedCallArgsChecker
 return NamespaceName == "WTF" &&
(MethodName == "find" || MethodName == "findIf" ||
 MethodName == "reverseFind" || MethodName == "reverseFindIf" ||
-MethodName == "get" || MethodName == "inlineGet" ||
-MethodName == "contains" || MethodName == "containsIf") &&
+MethodName == "findIgnoringASCIICase" || MethodName == "get" ||
+MethodName == "inlineGet" || MethodName == "contains" ||
+MethodName == "containsIf" ||
+MethodName == "containsIgnoringASCIICase" ||
+MethodName == "startsWith" || MethodName == "endsWith" ||
+MethodName == "startsWithIgnoringASCIICase" ||
+MethodName == "endsWithIgnoringASCIICase" ||
+MethodName == "substring") &&
(ClsName.ends_with("Vector") || ClsName.ends_with("Set") ||
-ClsName.ends_with("Map"));
+ClsName.ends_with("Map") || ClsName == "StringImpl" ||
+ClsName.ends_with("String"));
   }
 
   void reportBug(const Expr *CallArg, const ParmVarDecl *Param) const {

diff  --git a/clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp
index 0a63a789856127..17e25d9a627039 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-wtf-containers.cpp
@@ -4,6 +4,92 @@
 
 namespace WTF {
 
+  constexpr unsigned long notFound = static_cast(-1);
+
+  class String;
+  class StringImpl;
+
+  class StringView {
+  public:
+StringView(const String&);
+  private:
+RefPtr m_impl;
+  };
+
+  class StringImpl {
+  public:
+void ref() const { ++m_refCount; }
+void deref() const {
+  if (!--m_refCount)
+delete this;
+}
+
+static constexpr unsigned s_flagIs8Bit = 1u << 0;
+bool is8Bit() const { return m_hashAndFlags & s_flagIs8Bit; }
+const char* characters8() const { return m_char8; }
+const short* characters16() const { return m_char16; }
+unsigned length() const { return m_length; }
+Ref substring(unsigned position, unsigned length) const;
+
+unsigned long find(char) const;
+unsigned long find(StringView) const;
+unsigned long contains(StringView) const;
+unsigned long findIgnoringASCIICase(StringView) const;
+
+bool startsWith(StringView) const;
+bool startsWithIgnoringASCIICase(StringView) const;
+bool endsWith(StringView) const;
+bool endsWithIgnoringASCIICase(StringView) const;
+
+  private:
+mutable unsigned m_refCount { 0 };
+unsigned m_length { 0 };
+union {
+  const char* m_char8;
+  const short* m_char16;
+};
+unsigned m_hashAndFlags { 0 };
+  };
+
+  class String {
+  public:
+String() = default;
+String(StringImpl& impl) : m_impl() { }
+String(StringImpl* impl) : m_impl(impl) { }
+String(Ref&& impl) : m_impl(impl.get()) { }
+StringImpl* impl() { return m_impl.get(); }
+unsigned length() const { return m_impl ? m_impl->length() : 0; }
+const char* characters8() const { return m_impl ? m_impl->characters8() : 
nullptr; }
+const short* characters16() const { return m_impl ? m_impl->characters16() 
: nullptr; }
+
+bool is8Bit() const { return !m_impl || m_impl->is8Bit(); }
+
+unsigned long find(char character) const { return m_impl ? 
m_impl->find(character) : notFound; }
+unsigned long find(StringView str) const { return m_impl ? 
m_impl->find(str) : notFound; }
+unsigned long findIgnoringASCIICase(StringView) const;
+
+bool contains(char character) const { return find(character) != notFound; }
+bool contains(StringView) const;
+bool containsIgnoringASCIICase(StringView) const;
+
+bool startsWith(StringView) const;
+bool startsWithIgnoringASCIICase(StringView) const;
+

[clang] [llvm] [RISCV] Add smstateen extension (PR #90818)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mc

Author: Craig Topper (topperc)


Changes



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


5 Files Affected:

- (modified) clang/test/Preprocessor/riscv-target-features.c (+9) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+3) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+4) 
- (modified) llvm/test/MC/RISCV/attribute-arch.s (+3) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+1) 


``diff
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index ee4f81cd654bca..913093bb51db6d 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -27,6 +27,7 @@
 // CHECK-NOT: __riscv_shvstvecd {{.*$}}
 // CHECK-NOT: __riscv_smaia {{.*$}}
 // CHECK-NOT: __riscv_smepmp {{.*$}}
+// CHECK-NOT: __riscv_smstateen {{.*$}}
 // CHECK-NOT: __riscv_ssaia {{.*$}}
 // CHECK-NOT: __riscv_ssccptr {{.*$}}
 // CHECK-NOT: __riscv_sscofpmf {{.*$}}
@@ -373,6 +374,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSCOUNTERENW-EXT %s
 // CHECK-SSCOUNTERENW-EXT: __riscv_sscounterenw 100{{$}}
 
+// RUN: %clang --target=riscv32-unknown-linux-gnu \
+// RUN:   -march=rv32ismstateen -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SMSTATEEN-EXT %s
+// RUN: %clang --target=riscv64-unknown-linux-gnu \
+// RUN:   -march=rv64ismstateen -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SMSTATEEN-EXT %s
+// CHECK-SMSTATEEN-EXT: __riscv_smstateen 100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32issstateen -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSSTATEEN-EXT %s
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index eab1863fdc32ea..a9107a7374d2d9 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -867,6 +867,9 @@ def FeatureStdExtSscounterenw
  "'Sscounterenw' (Support writeable scounteren enable "
  "bit for any hpmcounter that is not read-only zero)">;
 
+def FeatureStdExtSmstateen
+: RISCVExtension<"smstateen", 1, 0,
+ "'Smstateen' (Machine-mode view of the state-enable 
extension.)">;
 def FeatureStdExtSsstateen
 : RISCVExtension<"ssstateen", 1, 0,
  "'Ssstateen' (Supervisor-mode view of the state-enable 
extension)">;
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 7bd3440c9dc0ef..8f49f6648ad281 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -44,6 +44,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+ssccptr %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSCCPTR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+sscofpmf %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSCOFPMF %s
 ; RUN: llc -mtriple=riscv32 -mattr=+sscounterenw %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSCOUNTERENW %s
+; RUN: llc -mtriple=riscv32 -mattr=+smstateen %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SMSTATEEN %s
 ; RUN: llc -mtriple=riscv32 -mattr=+ssstateen %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSSTATEEN %s
 ; RUN: llc -mtriple=riscv32 -mattr=+ssstrict %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSSTRICT %s
 ; RUN: llc -mtriple=riscv32 -mattr=+sstc %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSTC %s
@@ -170,6 +171,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+ssccptr %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSCCPTR %s
 ; RUN: llc -mtriple=riscv64 -mattr=+sscofpmf %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSCOFPMF %s
 ; RUN: llc -mtriple=riscv64 -mattr=+sscounterenw %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSCOUNTERENW %s
+; RUN: llc -mtriple=riscv64 -mattr=+smstateen %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SMSTATEEN %s
 ; RUN: llc -mtriple=riscv64 -mattr=+ssstateen %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSSTATEEN %s
 ; RUN: llc -mtriple=riscv64 -mattr=+ssstrict %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSSTRICT %s
 ; RUN: llc -mtriple=riscv64 -mattr=+sstc %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSTC %s
@@ -314,6 +316,7 @@
 ; RV32SSCCPTR: .attribute 5, "rv32i2p1_ssccptr1p0"
 ; RV32SSCOFPMF: .attribute 5, "rv32i2p1_sscofpmf1p0"
 ; RV32SSCOUNTERENW: .attribute 5, "rv32i2p1_sscounterenw1p0"
+; RV32SMSTATEEN: .attribute 5, "rv32i2p1_smstateen1p0"
 ; RV32SSSTATEEN: .attribute 5, "rv32i2p1_ssstateen1p0"
 ; RV32SSSTRICT: .attribute 5, "rv32i2p1_ssstrict1p0"
 ; RV32SSTC: .attribute 5, "rv32i2p1_sstc1p0"
@@ -443,6 +446,7 @@
 ; RV64SSCCPTR: .attribute 5, "rv64i2p1_ssccptr1p0"
 ; RV64SSCOFPMF: .attribute 5, "rv64i2p1_sscofpmf1p0"
 ; RV64SSCOUNTERENW: .attribute 5, "rv64i2p1_sscounterenw1p0"
+; RV64SMSTATEEN: .attribute 5, "rv64i2p1_smstateen1p0"
 ; RV64SSSTATEEN: .attribute 5, "rv64i2p1_ssstateen1p0"
 ; RV64SSSTRICT: .attribute 5, 

[clang] [llvm] [RISCV] Add smstateen extension (PR #90818)

2024-05-01 Thread Craig Topper via cfe-commits

https://github.com/topperc created 
https://github.com/llvm/llvm-project/pull/90818

None

>From ef8985a4bb9fe78c273d9d3cb2af17b0d65459c2 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Wed, 1 May 2024 20:27:15 -0700
Subject: [PATCH] [RISCV] Add smstateen extension

---
 clang/test/Preprocessor/riscv-target-features.c  | 9 +
 llvm/lib/Target/RISCV/RISCVFeatures.td   | 3 +++
 llvm/test/CodeGen/RISCV/attributes.ll| 4 
 llvm/test/MC/RISCV/attribute-arch.s  | 3 +++
 llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 1 +
 5 files changed, 20 insertions(+)

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index ee4f81cd654bca..913093bb51db6d 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -27,6 +27,7 @@
 // CHECK-NOT: __riscv_shvstvecd {{.*$}}
 // CHECK-NOT: __riscv_smaia {{.*$}}
 // CHECK-NOT: __riscv_smepmp {{.*$}}
+// CHECK-NOT: __riscv_smstateen {{.*$}}
 // CHECK-NOT: __riscv_ssaia {{.*$}}
 // CHECK-NOT: __riscv_ssccptr {{.*$}}
 // CHECK-NOT: __riscv_sscofpmf {{.*$}}
@@ -373,6 +374,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSCOUNTERENW-EXT %s
 // CHECK-SSCOUNTERENW-EXT: __riscv_sscounterenw 100{{$}}
 
+// RUN: %clang --target=riscv32-unknown-linux-gnu \
+// RUN:   -march=rv32ismstateen -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SMSTATEEN-EXT %s
+// RUN: %clang --target=riscv64-unknown-linux-gnu \
+// RUN:   -march=rv64ismstateen -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SMSTATEEN-EXT %s
+// CHECK-SMSTATEEN-EXT: __riscv_smstateen 100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32issstateen -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSSTATEEN-EXT %s
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index eab1863fdc32ea..a9107a7374d2d9 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -867,6 +867,9 @@ def FeatureStdExtSscounterenw
  "'Sscounterenw' (Support writeable scounteren enable "
  "bit for any hpmcounter that is not read-only zero)">;
 
+def FeatureStdExtSmstateen
+: RISCVExtension<"smstateen", 1, 0,
+ "'Smstateen' (Machine-mode view of the state-enable 
extension.)">;
 def FeatureStdExtSsstateen
 : RISCVExtension<"ssstateen", 1, 0,
  "'Ssstateen' (Supervisor-mode view of the state-enable 
extension)">;
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 7bd3440c9dc0ef..8f49f6648ad281 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -44,6 +44,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+ssccptr %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSCCPTR %s
 ; RUN: llc -mtriple=riscv32 -mattr=+sscofpmf %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSCOFPMF %s
 ; RUN: llc -mtriple=riscv32 -mattr=+sscounterenw %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSCOUNTERENW %s
+; RUN: llc -mtriple=riscv32 -mattr=+smstateen %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SMSTATEEN %s
 ; RUN: llc -mtriple=riscv32 -mattr=+ssstateen %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSSTATEEN %s
 ; RUN: llc -mtriple=riscv32 -mattr=+ssstrict %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSSTRICT %s
 ; RUN: llc -mtriple=riscv32 -mattr=+sstc %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SSTC %s
@@ -170,6 +171,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+ssccptr %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSCCPTR %s
 ; RUN: llc -mtriple=riscv64 -mattr=+sscofpmf %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSCOFPMF %s
 ; RUN: llc -mtriple=riscv64 -mattr=+sscounterenw %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSCOUNTERENW %s
+; RUN: llc -mtriple=riscv64 -mattr=+smstateen %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SMSTATEEN %s
 ; RUN: llc -mtriple=riscv64 -mattr=+ssstateen %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSSTATEEN %s
 ; RUN: llc -mtriple=riscv64 -mattr=+ssstrict %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSSTRICT %s
 ; RUN: llc -mtriple=riscv64 -mattr=+sstc %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SSTC %s
@@ -314,6 +316,7 @@
 ; RV32SSCCPTR: .attribute 5, "rv32i2p1_ssccptr1p0"
 ; RV32SSCOFPMF: .attribute 5, "rv32i2p1_sscofpmf1p0"
 ; RV32SSCOUNTERENW: .attribute 5, "rv32i2p1_sscounterenw1p0"
+; RV32SMSTATEEN: .attribute 5, "rv32i2p1_smstateen1p0"
 ; RV32SSSTATEEN: .attribute 5, "rv32i2p1_ssstateen1p0"
 ; RV32SSSTRICT: .attribute 5, "rv32i2p1_ssstrict1p0"
 ; RV32SSTC: .attribute 5, "rv32i2p1_sstc1p0"
@@ -443,6 +446,7 @@
 ; RV64SSCCPTR: .attribute 5, "rv64i2p1_ssccptr1p0"
 ; RV64SSCOFPMF: .attribute 5, "rv64i2p1_sscofpmf1p0"
 ; RV64SSCOUNTERENW: .attribute 5, "rv64i2p1_sscounterenw1p0"
+; RV64SMSTATEEN: .attribute 5, 

[clang] [llvm] [DirectX][DXIL] Set DXIL Version in DXIL target triple based on shader model version (PR #90809)

2024-05-01 Thread Xiang Li via cfe-commits


@@ -760,7 +760,7 @@ using namespace clang::targets;
 TargetInfo *
 TargetInfo::CreateTargetInfo(DiagnosticsEngine ,
  const std::shared_ptr ) {
-  llvm::Triple Triple(Opts->Triple);
+  llvm::Triple Triple(llvm::Triple::normalize(Opts->Triple));

python3kgae wrote:

Why do we need to call llvm::Triple::normalize here?

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


[clang] [clang] MangledSymbol: remove pointless copy of vector (PR #90012)

2024-05-01 Thread Andrew Sukach via cfe-commits

https://github.com/soukatch updated 
https://github.com/llvm/llvm-project/pull/90012

>From 9007597af4f138d2744405bb7980fce4555d7508 Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Wed, 24 Apr 2024 22:50:50 -0400
Subject: [PATCH 1/3] [clang] MangledSymbol: remove pointless copy of vector

---
 clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp 
b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
index d58f5bb0919906..81a827dba26b90 100644
--- a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
+++ b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
@@ -33,7 +33,8 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
 
 MangledSymbol(const std::string , uint8_t Type, uint8_t Binding,
   std::vector Names)
-: ParentName(ParentName), Type(Type), Binding(Binding), Names(Names) {}
+: ParentName(ParentName), Type(Type), Binding(Binding),
+  Names(std::move(Names)) {}
   };
   using MangledSymbols = std::map;
 

>From 7774ca198e84946f45ae9301769f53ee91aaddac Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Fri, 26 Apr 2024 01:29:28 -0400
Subject: [PATCH 2/3]


>From f215551cda763e96c1a7096f86b6d5c1cc0b6bea Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Wed, 1 May 2024 23:16:16 -0400
Subject: [PATCH 3/3]


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


[clang] [llvm] [RISCV] Teach .option arch to support experimental extensions. (PR #89727)

2024-05-01 Thread Yeting Kuo via cfe-commits


@@ -51,7 +51,6 @@ STATISTIC(RISCVNumInstrsCompressed,
 
 static cl::opt AddBuildAttributes("riscv-add-build-attributes",
 cl::init(false));
-

yetingk wrote:

Done.

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


[clang] [llvm] [RISCV] Teach .option arch to support experimental extensions. (PR #89727)

2024-05-01 Thread Yeting Kuo via cfe-commits


@@ -2824,8 +2826,12 @@ bool RISCVAsmParser::parseDirectiveOption() {
 break;
   }
 
-  auto Ext = llvm::lower_bound(RISCVFeatureKV, Arch);
-  if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Arch ||
+  std::string Feature = RISCVISAInfo::getTargetFeatureForExtension(Arch);
+  if (!enableExperimentalExtension() &&
+  StringRef(Feature).starts_with("experimental-"))
+return Error(Loc, "Unexpected experimental extensions.");
+  auto Ext = llvm::lower_bound(RISCVFeatureKV, Feature);
+  if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Feature ||
   !RISCVISAInfo::isSupportedExtension(Arch)) {

yetingk wrote:

Done. Thank you.

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


[clang] [llvm] [RISCV] Teach .option arch to support experimental extensions. (PR #89727)

2024-05-01 Thread Yeting Kuo via cfe-commits

https://github.com/yetingk updated 
https://github.com/llvm/llvm-project/pull/89727

>From a43014cf3daa1b0fd9092bfe41da979205ba64aa Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 23 Apr 2024 02:16:04 -0700
Subject: [PATCH 1/5] [RISCV] Teach .option arch to support experimental
 extensions.

Previously .option arch denied extenions are not belongs to RISC-V features. But
experimental features have experimental- prefix, so .option arch can not
serve for experimental extension.
This patch uses the features of extensions to identify extension
existance.
---
 llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp | 7 ---
 llvm/test/MC/RISCV/option-arch.s   | 9 -
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 3f4a73ad89bf8a..80ff70f1095f4c 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -2824,8 +2824,9 @@ bool RISCVAsmParser::parseDirectiveOption() {
 break;
   }
 
-  auto Ext = llvm::lower_bound(RISCVFeatureKV, Arch);
-  if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Arch ||
+  std::string & = RISCVISAInfo::getTargetFeatureForExtension(Arch);
+  auto Ext = llvm::lower_bound(RISCVFeatureKV, Feature);
+  if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Feature ||
   !RISCVISAInfo::isSupportedExtension(Arch)) {
 if (isDigit(Arch.back()))
   return Error(
@@ -2834,7 +2835,7 @@ bool RISCVAsmParser::parseDirectiveOption() {
 return Error(Loc, "unknown extension feature");
   }
 
-  Args.emplace_back(Type, Ext->Key);
+  Args.emplace_back(Type, Arch.str());
 
   if (Type == RISCVOptionArchArgType::Plus) {
 FeatureBitset OldFeatureBits = STI->getFeatureBits();
diff --git a/llvm/test/MC/RISCV/option-arch.s b/llvm/test/MC/RISCV/option-arch.s
index 6ee133c7159a27..40675f9e4b434b 100644
--- a/llvm/test/MC/RISCV/option-arch.s
+++ b/llvm/test/MC/RISCV/option-arch.s
@@ -1,7 +1,7 @@
 # RUN: llvm-mc -triple riscv32 -show-encoding < %s \
 # RUN:   | FileCheck -check-prefixes=CHECK %s
 # RUN: llvm-mc -triple riscv32 -filetype=obj < %s \
-# RUN:   | llvm-objdump  --triple=riscv32 --mattr=+c,+m,+a,+f,+zba -d -M 
no-aliases - \
+# RUN:   | llvm-objdump  --triple=riscv32 
--mattr=+c,+m,+a,+f,+zba,+experimental-zicfiss -d -M no-aliases - \
 # RUN:   | FileCheck -check-prefixes=CHECK-INST %s
 
 # Test '.option arch, +' and '.option arch, -' directive
@@ -78,6 +78,13 @@ lr.w t0, (t1)
 # CHECK: encoding: [0xb3,0x22,0x73,0x20]
 sh1add t0, t1, t2
 
+# Test experimental extension
+# CHECK: .option arch, +zicfiss
+.option arch, +zicfiss
+# CHECK-INST: sspopchk ra
+# CHECK: encoding: [0x73,0xc0,0xc0,0xcd]
+sspopchk ra
+
 # Test '.option arch, ' directive
 # CHECK: .option arch, rv32i2p1_m2p0_a2p1_c2p0
 .option arch, rv32i2p1_m2p0_a2p1_c2p0

>From 471abce617a9d18ef91370303eef90bab228d9d3 Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 23 Apr 2024 21:55:12 -0700
Subject: [PATCH 2/5] Make this pr obey menable-experimental-extensions.

---
 clang/lib/Driver/ToolChains/Clang.cpp  | 5 +
 clang/test/Driver/riscv-option-arch.s  | 5 +
 llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp | 6 ++
 3 files changed, 16 insertions(+)
 create mode 100644 clang/test/Driver/riscv-option-arch.s

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5894a48e0e378b..8b0f523763486f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8449,6 +8449,11 @@ void ClangAs::AddRISCVTargetArgs(const ArgList ,
   CmdArgs.push_back("-mllvm");
   CmdArgs.push_back("-riscv-add-build-attributes");
   }
+
+  if (!Args.hasArg(options::OPT_menable_experimental_extensions)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-riscv-disable-experimental-ext");
+  }
 }
 
 void ClangAs::ConstructJob(Compilation , const JobAction ,
diff --git a/clang/test/Driver/riscv-option-arch.s 
b/clang/test/Driver/riscv-option-arch.s
new file mode 100644
index 00..8ce84dd8ffe79d
--- /dev/null
+++ b/clang/test/Driver/riscv-option-arch.s
@@ -0,0 +1,5 @@
+# RUN: %clang --target=riscv64 -menable-experimental-extensions -c -o 
/dev/null %s
+# RUN: ! %clang --target=riscv64 -c -o /dev/null %s 2>&1 | FileCheck 
-check-prefixes=CHECK-ERR %s
+
+.option arch, +zicfiss
+# CHECK-ERR: Unexpected experimental extensions.
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 80ff70f1095f4c..6225e0707015fe 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -51,6 +51,9 @@ STATISTIC(RISCVNumInstrsCompressed,
 
 static cl::opt 

[clang-tools-extra] [clang-tidy] Relax readability-const-return-type (PR #90560)

2024-05-01 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] 1f1a417 - [clang-tidy] Relax readability-const-return-type (#90560)

2024-05-01 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-05-02T04:43:35+02:00
New Revision: 1f1a417925624a67cb6cb2bbbdd901e0e90ee237

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

LOG: [clang-tidy] Relax readability-const-return-type (#90560)

>From now readability-const-return-type won't provide warnings for
returning const types, where const is not on top level. In such case
const there is a performance issue, but not a readability.

Closes #73270

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
index e92350632b556b..c13a8010c22210 100644
--- a/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
@@ -55,14 +55,6 @@ AST_MATCHER(QualType, isLocalConstQualified) {
   return Node.isLocalConstQualified();
 }
 
-AST_MATCHER(QualType, isTypeOfType) {
-  return isa(Node.getTypePtr());
-}
-
-AST_MATCHER(QualType, isTypeOfExprType) {
-  return isa(Node.getTypePtr());
-}
-
 struct CheckResult {
   // Source range of the relevant `const` token in the definition being 
checked.
   CharSourceRange ConstRange;
@@ -110,16 +102,11 @@ void 
ConstReturnTypeCheck::storeOptions(ClangTidyOptions::OptionMap ) {
 void ConstReturnTypeCheck::registerMatchers(MatchFinder *Finder) {
   // Find all function definitions for which the return types are `const`
   // qualified, ignoring decltype types.
-  auto NonLocalConstType =
-  qualType(unless(isLocalConstQualified()),
-   anyOf(decltypeType(), autoType(), isTypeOfType(),
- isTypeOfExprType(), substTemplateTypeParmType()));
   Finder->addMatcher(
-  functionDecl(
-  returns(allOf(isConstQualified(), unless(NonLocalConstType))),
-  anyOf(isDefinition(), cxxMethodDecl(isPure())),
-  // Overridden functions are not actionable.
-  unless(cxxMethodDecl(isOverride(
+  functionDecl(returns(isLocalConstQualified()),
+   anyOf(isDefinition(), cxxMethodDecl(isPure())),
+   // Overridden functions are not actionable.
+   unless(cxxMethodDecl(isOverride(
   .bind("func"),
   this);
 }

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6c9745d585b1c1..d59da3a61b7b61 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -318,6 +318,10 @@ Changes in existing checks
   ` check by adding
   fix-its.
 
+- Improved :doc:`readability-const-return-type
+  ` check to eliminate false
+  positives when returning types with const not at the top level.
+
 - Improved :doc:`readability-duplicate-include
   ` check by excluding include
   directives that form the filename using macro.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
index 10b2858c9caa82..76a3555663b180 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
@@ -215,11 +215,9 @@ CREATE_FUNCTION();
 
 using ty = const int;
 ty p21() {}
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'ty' (aka 'const int') 
is
 
 typedef const int ty2;
 ty2 p22() {}
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'ty2' (aka 'const int') 
i
 
 // Declaration uses a macro, while definition doesn't.  In this case, we won't
 // fix the declaration, and will instead issue a warning.
@@ -249,7 +247,6 @@ auto p27() -> int const { return 3; }
 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 
'const'-qu
 
 std::add_const::type p28() { return 3; }
-// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 
'std::add_const::typ
 
 // p29, p30 are based on
 // llvm/projects/test-suite/SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp:
@@ -355,3 +352,20 @@ struct p41 {
   // CHECK-FIXES: T foo() const { return 2; }
 };
 template struct p41;
+
+namespace PR73270 {
+  template
+  struct Pair {
+using first_type = const K;
+using second_type = V;
+  };
+
+  template
+  typename PairType::first_type getFirst() {
+return {};
+  }
+
+  void test() {
+getFirst>();
+  }
+}



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


[clang-tools-extra] [clang-tidy] Ignore casts from void to void in bugprone-casting-through-void (PR #90566)

2024-05-01 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] 889e60d - [clang-tidy] Ignore casts from void to void in bugprone-casting-through-void (#90566)

2024-05-01 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-05-02T04:42:42+02:00
New Revision: 889e60db2daf93c0bb3f7ae0db0a60bfefb86d89

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

LOG: [clang-tidy] Ignore casts from void to void in 
bugprone-casting-through-void (#90566)

Improved bugprone-casting-through-void check by ignoring casts where
source is already a void pointer, making middle void pointer casts
bug-free.

Closes #87069

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
index 4c2416a89aef9b..9e714b4be4dfea 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
@@ -7,12 +7,10 @@
 
//===--===//
 
 #include "CastingThroughVoidCheck.h"
-#include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Type.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "llvm/ADT/StringSet.h"
 
 using namespace clang::ast_matchers;
 
@@ -27,7 +25,8 @@ void CastingThroughVoidCheck::registerMatchers(MatchFinder 
*Finder) {
   hasSourceExpression(
   explicitCastExpr(
   hasSourceExpression(
-  expr(hasType(qualType().bind("source_type",
+  expr(hasType(qualType(unless(pointsTo(voidType(
+   .bind("source_type",
   hasDestinationType(
   qualType(pointsTo(voidType())).bind("void_type")))
   .bind("cast"))),

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5956ccb925485c..6c9745d585b1c1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -173,6 +173,11 @@ Changes in existing checks
   ` check by detecting side
   effect from calling a method with non-const reference parameters.
 
+- Improved :doc:`bugprone-casting-through-void
+  ` check by ignoring casts
+  where source is already a ``void``` pointer, making middle ``void`` pointer
+  casts bug-free.
+
 - Improved :doc:`bugprone-forwarding-reference-overload
   `
   check to ignore deleted constructors which won't hide other overloads.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp
index 3913d2d8a295c7..a784e498858738 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp
@@ -89,3 +89,10 @@ void bit_cast() {
   __builtin_bit_cast(int *, static_cast());
   // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not cast 'double *' to 'int 
*' through 'void *' [bugprone-casting-through-void]
 }
+
+namespace PR87069 {
+  void castconstVoidToVoid() {
+const void* ptr = nullptr;
+int* numberPtr = static_cast(const_cast(ptr));
+  }
+}



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


[clang-tools-extra] [NFC][clang-tidy] update check list document (PR #90813)

2024-05-01 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] a370d57 - [NFC][clang-tidy] update check list document (#90813)

2024-05-01 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-05-02T10:41:39+08:00
New Revision: a370d57b9ff9e385e9a51bf6b1d366890f4091cd

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

LOG: [NFC][clang-tidy] update check list document (#90813)

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 49747ff896ba5c..5cdaf9e35b6acd 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -120,7 +120,7 @@ Clang-Tidy Checks
:doc:`bugprone-posix-return `, "Yes"
:doc:`bugprone-redundant-branch-condition 
`, "Yes"
:doc:`bugprone-reserved-identifier `, "Yes"
-   :doc:`bugprone-return-const-ref-from-parameter 
`
+   :doc:`bugprone-return-const-ref-from-parameter 
`,
:doc:`bugprone-shared-ptr-array-mismatch 
`, "Yes"
:doc:`bugprone-signal-handler `,
:doc:`bugprone-signed-char-misuse `,



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


[clang-tools-extra] [clang-tidy] Handle expr with side-effects in readability-static-accessed-through-instance (PR #90736)

2024-05-01 Thread Piotr Zegar via cfe-commits


@@ -380,3 +387,20 @@ namespace PR51861 {
 // CHECK-FIXES: {{^}}PR51861::Foo::getBar();{{$}}
   }
 }
+
+namespace PR75163 {

PiotrZSL wrote:

PR = Problem Report (in this context)

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


[clang-tools-extra] [NFC][clang-tidy] update check list document (PR #90813)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




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

Author: Congcong Cai (HerrCai0907)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1-1) 


``diff
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 49747ff896ba5c..5cdaf9e35b6acd 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -120,7 +120,7 @@ Clang-Tidy Checks
:doc:`bugprone-posix-return `, "Yes"
:doc:`bugprone-redundant-branch-condition 
`, "Yes"
:doc:`bugprone-reserved-identifier `, "Yes"
-   :doc:`bugprone-return-const-ref-from-parameter 
`
+   :doc:`bugprone-return-const-ref-from-parameter 
`,
:doc:`bugprone-shared-ptr-array-mismatch 
`, "Yes"
:doc:`bugprone-signal-handler `,
:doc:`bugprone-signed-char-misuse `,

``




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


[clang-tools-extra] [NFC][clang-tidy] update check list document (PR #90813)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1-1) 


``diff
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 49747ff896ba5c..5cdaf9e35b6acd 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -120,7 +120,7 @@ Clang-Tidy Checks
:doc:`bugprone-posix-return `, "Yes"
:doc:`bugprone-redundant-branch-condition 
`, "Yes"
:doc:`bugprone-reserved-identifier `, "Yes"
-   :doc:`bugprone-return-const-ref-from-parameter 
`
+   :doc:`bugprone-return-const-ref-from-parameter 
`,
:doc:`bugprone-shared-ptr-array-mismatch 
`, "Yes"
:doc:`bugprone-signal-handler `,
:doc:`bugprone-signed-char-misuse `,

``




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


[clang-tools-extra] [NFC][clang-tidy] update check list document (PR #90813)

2024-05-01 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/90813

None

>From fb7b2eec7dcd065ff3edfa0f76efc012e8439a63 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 2 May 2024 10:36:11 +0800
Subject: [PATCH] [NFC][clang-tidy] update check list document

---
 clang-tools-extra/docs/clang-tidy/checks/list.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 49747ff896ba5c..5cdaf9e35b6acd 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -120,7 +120,7 @@ Clang-Tidy Checks
:doc:`bugprone-posix-return `, "Yes"
:doc:`bugprone-redundant-branch-condition 
`, "Yes"
:doc:`bugprone-reserved-identifier `, "Yes"
-   :doc:`bugprone-return-const-ref-from-parameter 
`
+   :doc:`bugprone-return-const-ref-from-parameter 
`,
:doc:`bugprone-shared-ptr-array-mismatch 
`, "Yes"
:doc:`bugprone-signal-handler `,
:doc:`bugprone-signed-char-misuse `,

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


[clang] [alpha.webkit.UncountedLocalVarsChecker] Don't warning on inlined functions (PR #90733)

2024-05-01 Thread Artem Dergachev via cfe-commits

haoNoQ wrote:

@mikhailramalho long time no see!

I think @rniwa is right on this one. "Inline" is completely orthogonal to 
"safe". Fundamentally it only matters what the function _actually does_; it 
doesn't matter how it's defined or where or how the code is generated for it.

These checkers don't follow our usual paradigm of "false positives are bad". 
They're coding convention checkers that force WebKit to use smart pointers 
consistently, even if the compiler hasn't identified any specific memory leaks 
or use-after-free vulnerabilities to worry about. While it's still valuable to 
avoid emitting warnings when the code is "obviously safe", they probably 
wouldn't go for a very approximate reasoning such as "all inline functions are 
safe" . We do this sort of stuff quite often in the rest of the static analyzer 
where false positives are much more terrifying than false negatives. But here, 
WebKit people such as @rniwa have consensually accepted a potentially high 
"false positive" rate as long as this means getting close to _some real safety_.

So this whole "trivial function analysis" thing aggressively treats unknown 
functions as unsafe by default, and when it actually gets to see the body 
(which correlates quite a bit with being inline) it carefully inspects it and 
confirms that it's actually "trivial" enough to not screw memory management. If 
you turn it off for inline functions, that's pretty close to turning it off 
entirely. That's probably not what they're looking for. There has to be a more 
careful solution to the false positves you're seeing.

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


[clang] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin and frexp. (PR #88978)

2024-05-01 Thread Hubert Tong via cfe-commits

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


[clang] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin and frexp. (PR #88978)

2024-05-01 Thread Hubert Tong via cfe-commits


@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -DWIN -verify -std=c++23 -fsyntax-only  %s
+// RUN: %clang_cc1 -verify -std=c++23 -fsyntax-only  %s
+
+// expected-no-diagnostics
+
+
+#ifdef WIN
+#define INFINITY ((float)(1e+300 * 1e+300))
+#define NAN  (-(float)(INFINITY * 0.0F))
+#else
+#define NAN (__builtin_nanf(""))
+#define INFINITY (__builtin_inff())
+#endif
+
+extern "C" void abort() noexcept;
+extern "C" int write(int, const void*, unsigned long);
+
+#define assert(condition) \
+  do { \
+if (!(condition)) {\
+  write(2, "Assertion failed: ", 18);  \
+  write(2, #condition, sizeof(#condition) - 1);\
+  write(2, "\n", 1);   \
+  abort(); \
+}  \
+  } while (false)
+
+int main() {
+int i;
+
+// fmin
+static_assert(__builtin_fmin(15.24, 1.3) == 1.3, "");
+static_assert(__builtin_fmin(-0.0, +0.0) == -0.0, "");
+static_assert(__builtin_fmin(+0.0, -0.0) == -0.0, "");
+assert(__builtin_isnan(__builtin_fminf(NAN,NAN)));
+assert(__builtin_isnan(__builtin_fminf(NAN, -1)));
+assert(__builtin_isnan(__builtin_fminf(-INFINITY, 0)));
+assert(__builtin_iszero(__builtin_fminf(+INFINITY, 0)));
+
+// frexp
+static_assert(__builtin_frexp(123.45, ) == 0.9644531250002);

hubert-reinterpretcast wrote:

@zahiraam, make `simulateFrexp` a `constexpr` function (maybe with `float` and 
`long double` overloads as well).

```
template 
struct FrexpResult {
  constexpr FrexpResult(T fraction, int exponent) : fraction(fraction), 
exponent(exponent) {}
  T fraction;
  int exponent;
  friend constexpr bool operator<=>(const FrexpResult &, const FrexpResult &) = 
default;
};

constexpr auto q() { return FrexpResult{0.5, 0}; };
static_assert(q() == FrexpResult{0.5, 0});
```

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


[clang] [llvm] [DirectX][DXIL] Set DXIL Version in DXIL target triple based on shader model version (PR #90809)

2024-05-01 Thread Joshua Batista via cfe-commits


@@ -115,6 +115,30 @@ StringRef Triple::getArchName(ArchType Kind, SubArchType 
SubArch) {
 if (SubArch == AArch64SubArch_arm64e)
   return "arm64e";
 break;
+  case Triple::dxil:
+switch (SubArch) {
+case Triple::NoSubArch:
+case Triple::DXILSubArch_v1_0:
+  return "dxilv1.0";
+case Triple::DXILSubArch_v1_1:
+  return "dxilv1.1";
+case Triple::DXILSubArch_v1_2:
+  return "dxilv1.2";
+case Triple::DXILSubArch_v1_3:
+  return "dxilv1.3";
+case Triple::DXILSubArch_v1_4:
+  return "dxilv1.4";
+case Triple::DXILSubArch_v1_5:
+  return "dxilv1.5";
+case Triple::DXILSubArch_v1_6:
+  return "dxilv1.6";
+case Triple::DXILSubArch_v1_7:
+  return "dxilv1.7";
+case Triple::DXILSubArch_v1_8:
+  return "dxilv1.8";
+default:
+  return "";

bob80905 wrote:

Would we want to llvm_unreachable or otherwise fail here, or does the caller 
handle this case well?

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


[clang] [llvm] [DirectX][DXIL] Set DXIL Version in DXIL target triple based on shader model version (PR #90809)

2024-05-01 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-hlsl

Author: S. Bharadwaj Yadavalli (bharadwajy)


Changes

An earlier commit provided a way to decouple DXIL version from Shader Model 
version
by representing the DXIL version as `SubArch` in the DXIL Target Triple and 
adding 
corresponding valid DXIL Arch types.

This change constructs DXIL target triple with DXIL version that is deduced
from Shader Model version specified in the following scenarios:

1. When compilation target profile is specified: 
   For e.g., DXIL target triple `dxilv1.8-unknown-shader6.8-library` is 
constructed 
   when `-T lib_6_8` is specified. 
2. When DXIL target triple without DXIL version is specified:
For e.g., DXIL target triple `dxilv1.8-pc-shadermodel6.8-library` is 
constructed
when `-mtriple=dxil-pc-shadermodel6.8-library` is specified.

Note that this is an alternate / expanded implementation to that proposed in PR 
#89823.

PR #89823 implements functionality (1) above. However, it requires any 
DXIL target  
triple to explicitly include DXIL version anywhere DXIL target triple is 
expected (e.g., 
`dxilv1.8-pc-shadermodel6.8-library`) while a triple without DXIL version 
(e.g., `dxil-pc-shadermodel6.8-library`) is considered invalid. This 
functionality is
implemented as a change to `tryParseProfile()` and is included in this PR.

This PR adds the functionality (2) to eliminate the above requirement to 
explicitly 
specify DXIL version in the target triple thereby considering a triple without 
DXIL 
version ( e.g., `dxil-pc-shadermodel6.8-library`) to be valid. A triple with 
DXIL version 
is inferred based on the shader mode version specified. If no shader model 
version is 
specified, DXIL version is defaulted to 1.0. This functionality is implemented 
in the 
"Special case logic ..." section of `Triple::normalize()`. 
 
Updated relevant HLSL tests that check for target triple. 

Update one MIR test to reflect use of normalized target triple.

Validated that Clang (`check-clang`) and LLVM (`check-llvm`) regression tests 
pass. 

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


13 Files Affected:

- (modified) clang/lib/Basic/Targets.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/HLSL.cpp (+42-2) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+4-3) 
- (modified) clang/test/CodeGenHLSL/basic-target.c (+1-1) 
- (modified) clang/test/Driver/dxc_dxv_path.hlsl (+3-3) 
- (modified) clang/test/Options/enable_16bit_types_validation.hlsl (+2-2) 
- (modified) clang/unittests/Driver/DXCModeTest.cpp (+12-10) 
- (modified) llvm/include/llvm/TargetParser/Triple.h (+1) 
- (modified) llvm/lib/CodeGen/CommandFlags.cpp (+1-1) 
- (modified) llvm/lib/IR/Verifier.cpp (+2-2) 
- (modified) llvm/lib/TargetParser/Triple.cpp (+45) 
- (modified) llvm/test/tools/llvm-reduce/mir/infer-triple-unknown-target.mir 
(+1-1) 
- (modified) llvm/tools/opt/optdriver.cpp (+1-1) 


``diff
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index e3283510c6aac7..dc1792b3471e6c 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -760,7 +760,7 @@ using namespace clang::targets;
 TargetInfo *
 TargetInfo::CreateTargetInfo(DiagnosticsEngine ,
  const std::shared_ptr ) {
-  llvm::Triple Triple(Opts->Triple);
+  llvm::Triple Triple(llvm::Triple::normalize(Opts->Triple));
 
   // Construct the target
   std::unique_ptr Target = AllocateTarget(Triple, *Opts);
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 1169b5d8c92dd6..c4c92613f44723 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -98,9 +98,49 @@ std::optional tryParseProfile(StringRef 
Profile) {
   else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
 return std::nullopt;
 
-  // dxil-unknown-shadermodel-hull
+  // Determine DXIL version using the minor version number of Shader
+  // Model version specified in target profile. Prior to decoupling DXIL 
version
+  // numbering from that of Shader Model DXIL version 1.Y corresponds to SM 
6.Y.
+  // E.g., dxilv1.Y-unknown-shadermodelX.Y-hull
   llvm::Triple T;
-  T.setArch(Triple::ArchType::dxil);
+  Triple::SubArchType SubArch = llvm::Triple::NoSubArch;
+  switch (Minor) {
+  case 0:
+SubArch = llvm::Triple::DXILSubArch_v1_0;
+break;
+  case 1:
+SubArch = llvm::Triple::DXILSubArch_v1_1;
+break;
+  case 2:
+SubArch = llvm::Triple::DXILSubArch_v1_2;
+break;
+  case 3:
+SubArch = llvm::Triple::DXILSubArch_v1_3;
+break;
+  case 4:
+SubArch = llvm::Triple::DXILSubArch_v1_4;
+break;
+  case 5:
+SubArch = llvm::Triple::DXILSubArch_v1_5;
+break;
+  case 6:
+SubArch = llvm::Triple::DXILSubArch_v1_6;
+break;
+  case 7:
+SubArch = llvm::Triple::DXILSubArch_v1_7;
+break;
+  case 8:
+SubArch = llvm::Triple::DXILSubArch_v1_8;
+break;
+  case OfflineLibMinor:

[clang] [llvm] [DirectX][DXIL] Set DXIL Version in DXIL target triple based on shader model version (PR #90809)

2024-05-01 Thread S. Bharadwaj Yadavalli via cfe-commits

https://github.com/bharadwajy created 
https://github.com/llvm/llvm-project/pull/90809

An earlier commit provided a way to decouple DXIL version from Shader Model 
version
by representing the DXIL version as `SubArch` in the DXIL Target Triple and 
adding 
corresponding valid DXIL Arch types.

This change constructs DXIL target triple with DXIL version that is deduced
from Shader Model version specified in the following scenarios:

1. When compilation target profile is specified: 
   For e.g., DXIL target triple `dxilv1.8-unknown-shader6.8-library` is 
constructed 
   when `-T lib_6_8` is specified. 
2. When DXIL target triple without DXIL version is specified:
For e.g., DXIL target triple `dxilv1.8-pc-shadermodel6.8-library` is 
constructed
when `-mtriple=dxil-pc-shadermodel6.8-library` is specified.

Note that this is an alternate / expanded implementation to that proposed in PR 
#89823.

PR #89823 implements functionality (1) above. However, it requires any DXIL 
target  
triple to explicitly include DXIL version anywhere DXIL target triple is 
expected (e.g., 
`dxilv1.8-pc-shadermodel6.8-library`) while a triple without DXIL version 
(e.g., `dxil-pc-shadermodel6.8-library`) is considered invalid. This 
functionality is
implemented as a change to `tryParseProfile()` and is included in this PR.

This PR adds the functionality (2) to eliminate the above requirement to 
explicitly 
specify DXIL version in the target triple thereby considering a triple without 
DXIL 
version ( e.g., `dxil-pc-shadermodel6.8-library`) to be valid. A triple with 
DXIL version 
is inferred based on the shader mode version specified. If no shader model 
version is 
specified, DXIL version is defaulted to 1.0. This functionality is implemented 
in the 
"Special case logic ..." section of `Triple::normalize()`. 
 
Updated relevant HLSL tests that check for target triple. 

Update one MIR test to reflect use of normalized target triple.

Validated that Clang (`check-clang`) and LLVM (`check-llvm`) regression tests 
pass. 

>From 1b6bb5bf115c9f72adde27b6d77d957edbc49321 Mon Sep 17 00:00:00 2001
From: Bharadwaj Yadavalli 
Date: Wed, 1 May 2024 14:42:42 -0400
Subject: [PATCH] Set DXIL Version in DXIL target triple based on shader model
 version a) specified as compilation target profile or b) specified as target
 triple string

Update relevant HLSL tests that check for target triple.
Update one MIR test to reflect use of normalized target triple.
---
 clang/lib/Basic/Targets.cpp   |  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  | 44 +-
 clang/lib/Frontend/CompilerInvocation.cpp |  7 +--
 clang/test/CodeGenHLSL/basic-target.c |  2 +-
 clang/test/Driver/dxc_dxv_path.hlsl   |  6 +--
 .../enable_16bit_types_validation.hlsl|  4 +-
 clang/unittests/Driver/DXCModeTest.cpp| 22 -
 llvm/include/llvm/TargetParser/Triple.h   |  1 +
 llvm/lib/CodeGen/CommandFlags.cpp |  2 +-
 llvm/lib/IR/Verifier.cpp  |  4 +-
 llvm/lib/TargetParser/Triple.cpp  | 45 +++
 .../mir/infer-triple-unknown-target.mir   |  2 +-
 llvm/tools/opt/optdriver.cpp  |  2 +-
 13 files changed, 116 insertions(+), 27 deletions(-)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index e3283510c6aac7..dc1792b3471e6c 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -760,7 +760,7 @@ using namespace clang::targets;
 TargetInfo *
 TargetInfo::CreateTargetInfo(DiagnosticsEngine ,
  const std::shared_ptr ) {
-  llvm::Triple Triple(Opts->Triple);
+  llvm::Triple Triple(llvm::Triple::normalize(Opts->Triple));
 
   // Construct the target
   std::unique_ptr Target = AllocateTarget(Triple, *Opts);
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 1169b5d8c92dd6..c4c92613f44723 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -98,9 +98,49 @@ std::optional tryParseProfile(StringRef 
Profile) {
   else if (llvm::getAsUnsignedInteger(Parts[2], 0, Minor))
 return std::nullopt;
 
-  // dxil-unknown-shadermodel-hull
+  // Determine DXIL version using the minor version number of Shader
+  // Model version specified in target profile. Prior to decoupling DXIL 
version
+  // numbering from that of Shader Model DXIL version 1.Y corresponds to SM 
6.Y.
+  // E.g., dxilv1.Y-unknown-shadermodelX.Y-hull
   llvm::Triple T;
-  T.setArch(Triple::ArchType::dxil);
+  Triple::SubArchType SubArch = llvm::Triple::NoSubArch;
+  switch (Minor) {
+  case 0:
+SubArch = llvm::Triple::DXILSubArch_v1_0;
+break;
+  case 1:
+SubArch = llvm::Triple::DXILSubArch_v1_1;
+break;
+  case 2:
+SubArch = llvm::Triple::DXILSubArch_v1_2;
+break;
+  case 3:
+SubArch = llvm::Triple::DXILSubArch_v1_3;
+break;
+  case 4:
+SubArch = 

[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)

2024-05-01 Thread Doug Wyatt via cfe-commits

https://github.com/dougsonos updated 
https://github.com/llvm/llvm-project/pull/90702

>From 4c312af7af5d0e419269c5b2304b0f898363bb85 Mon Sep 17 00:00:00 2001
From: Doug Wyatt 
Date: Tue, 30 Apr 2024 21:43:16 -0700
Subject: [PATCH 1/5] In AArch64's DataLayout, specify a minimum function
 alignment of 4. This addresses an issue where the explicit alignment of 2
 (for C++ ABI reasons) was being propagated to the back end and causing
 under-aligned functions (in special sections). (#90358)

---
 clang/lib/Basic/Targets/AArch64.cpp  | 12 ++--
 llvm/lib/IR/AutoUpgrade.cpp  |  8 
 llvm/lib/Target/AArch64/AArch64TargetMachine.cpp |  8 
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c8d243a8fb7aea..a5dd803f636b90 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1480,11 +1480,11 @@ AArch64leTargetInfo::AArch64leTargetInfo(const 
llvm::Triple ,
 void AArch64leTargetInfo::setDataLayout() {
   if (getTriple().isOSBinFormatMachO()) {
 if(getTriple().isArch32Bit())
-  resetDataLayout("e-m:o-p:32:32-i64:64-i128:128-n32:64-S128", "_");
+  resetDataLayout("e-m:o-p:32:32-Fn32-i64:64-i128:128-n32:64-S128", "_");
 else
-  resetDataLayout("e-m:o-i64:64-i128:128-n32:64-S128", "_");
+  resetDataLayout("e-m:o-Fn32-i64:64-i128:128-n32:64-S128", "_");
   } else
-resetDataLayout("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+
resetDataLayout("e-m:e-Fn32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
 }
 
 void AArch64leTargetInfo::getTargetDefines(const LangOptions ,
@@ -1507,7 +1507,7 @@ void AArch64beTargetInfo::getTargetDefines(const 
LangOptions ,
 
 void AArch64beTargetInfo::setDataLayout() {
   assert(!getTriple().isOSBinFormatMachO());
-  resetDataLayout("E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
+  resetDataLayout("E-m:e-Fn32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128");
 }
 
 WindowsARM64TargetInfo::WindowsARM64TargetInfo(const llvm::Triple ,
@@ -1530,8 +1530,8 @@ WindowsARM64TargetInfo::WindowsARM64TargetInfo(const 
llvm::Triple ,
 
 void WindowsARM64TargetInfo::setDataLayout() {
   resetDataLayout(Triple.isOSBinFormatMachO()
-  ? "e-m:o-i64:64-i128:128-n32:64-S128"
-  : "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128",
+  ? "e-m:o-Fn32-i64:64-i128:128-n32:64-S128"
+  : 
"e-m:w-p:64:64-Fn32-i32:32-i64:64-i128:128-n32:64-S128",
   Triple.isOSBinFormatMachO() ? "_" : "");
 }
 
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 634b2dd5119e8d..eed946dc36580e 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -5387,6 +5387,14 @@ std::string llvm::UpgradeDataLayoutString(StringRef DL, 
StringRef TT) {
 return Res;
   }
 
+  // AArch64 data layout upgrades.
+  if (T.isAArch64()) {
+// Add "-Fn32"
+if (!DL.contains("-Fn32"))
+  Res.append("-Fn32");
+return Res;
+  }
+
   if (!T.isX86())
 return Res;
 
diff --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp 
b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
index 7ef78cbba352a5..4ff5fb94162a93 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -275,15 +275,15 @@ static std::string computeDataLayout(const Triple ,
  bool LittleEndian) {
   if (TT.isOSBinFormatMachO()) {
 if (TT.getArch() == Triple::aarch64_32)
-  return "e-m:o-p:32:32-i64:64-i128:128-n32:64-S128";
-return "e-m:o-i64:64-i128:128-n32:64-S128";
+  return "e-m:o-p:32:32-Fn32-i64:64-i128:128-n32:64-S128";
+return "e-m:o-Fn32-i64:64-i128:128-n32:64-S128";
   }
   if (TT.isOSBinFormatCOFF())
-return "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128";
+return "e-m:w-p:64:64-Fn32-i32:32-i64:64-i128:128-n32:64-S128";
   std::string Endian = LittleEndian ? "e" : "E";
   std::string Ptr32 = TT.getEnvironment() == Triple::GNUILP32 ? "-p:32:32" : 
"";
   return Endian + "-m:e" + Ptr32 +
- "-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128";
+ "-Fn32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128";
 }
 
 static StringRef computeDefaultCPU(const Triple , StringRef CPU) {

>From 5a2b9e1b0444c52cd7f7cf9a3ddbb573403101a5 Mon Sep 17 00:00:00 2001
From: Doug Wyatt 
Date: Wed, 1 May 2024 07:27:11 -0700
Subject: [PATCH 2/5] Move "-Fn32" to the end of the data layout strings, to
 make the auto-upgrade simplest.

---
 clang/lib/Basic/Targets/AArch64.cpp  | 12 ++--
 llvm/lib/Target/AArch64/AArch64TargetMachine.cpp |  8 
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index a5dd803f636b90..1a02520d7bd1f8 100644
--- 

[clang] [clang] Set correct FPOptions if attribute 'optnone' presents (PR #85605)

2024-05-01 Thread via cfe-commits

wjristow wrote:

Hi @spavloff.

Regarding:
> With that goal in mind, having `optnone` and `-O0` be deliberately different 
> here makes no sense.

There's no need for them to behave differently here. And in fact, we _want_ 
them to behave the same.  There's a subtle point about FP contraction, in that 
doing an FP contraction (within a statement in C/C++) isn't considered an 
"optimization".  It's a bit counterintuitive, but there's a good reason.

A Fused Multiply Add (FMA) will, in general, produce a slightly different 
bit-wise floating point result than a multiply/add sequence.  For architectures 
that have FMA instructions, if we enabled FMA at (for example) `-O2` but not at 
lower optimizations, then our `-O0` and `-O2` FP results would generally not be 
bit-wise identical.  And we don't want that.  Essentially, we have a 
requirement that "safe" optimizations like `-O2` (as opposed to "unsafe" 
optimizations like `-ffast-math`) should not change the results of correct 
programs.  So if FMA is to be enabled at `-O2`, we must also enable it at `-O0`.

The legal values and semantics in C/C++ for `-ffp-contract=` are:

```
-ffp-contract=off   Never use FMA
-ffp-contract=onUse FMA within a statement (default)
-ffp-contract=fast  Use FMA across multiple statements
```

See: https://clang.llvm.org/docs/UsersManual.html#cmdoption-ffp-contract

(There is also one other legal setting: `-ffp-contract=fast-honor-pragmas`, but 
it's not relevant to the issue here.)

So setting `-ffp-contract=off` isn't setting it to the `-O0` value, and setting 
it to the `-O0` value _is_ what we want.

To put it another way, for a target that has FMA instructions, a valid program 
will produce identical results for `-O0`, `-O1` and `-O2` (as desired), but 
with the change of this commit, applying the attribute `optnone` can now 
produce slightly different floating point results.

As you said earlier:

> The observed difference is due to the FP contraction turned off if optnone is 
> specified. In O0 this optimization is still applied. As a result, the 
> function with optnone contains separate fadd and fmul, while without this 
> attribute the function contains combined operatin fmuladd.

In short, `optnone` shouldn't set `-ffp-contract=off`, it should set 
`-ffp-contract=on`.  Which, as I'm sure you realize, can be done via:

```
diff --git clang/include/clang/Basic/LangOptions.h 
clang/include/clang/Basic/LangOptions.h
index e2a2aa71b880..a5a7b3895d58 100644
--- clang/include/clang/Basic/LangOptions.h
+++ clang/include/clang/Basic/LangOptions.h
@@ -970,7 +970,7 @@ public:

   void setDisallowOptimizations() {
 setFPPreciseEnabled(true);
-setDisallowFPContract();
+setAllowFPContractWithinStatement();
   }

   storage_type getAsOpaqueInt() const {
```

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


[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-01 Thread Krystian Stasiowski via cfe-commits

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


[clang] [clang][PGO] Apply artificial DebugLoc to llvm.instrprof.increment instructions (PR #90717)

2024-05-01 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/90717

>From 94c812abc4e528d3d3cb96fa3c3b7f78b6a87a91 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Wed, 1 May 2024 11:03:08 +0100
Subject: [PATCH 1/2] [clang][PGO] Apply artificial DebugLoc to
 llvm.instrprof.increment instructions

Prior to this change the debug-location for the `llvm.instrprof.increment`
intrinsic was set to whatever the current DIBuilder's current debug
location was set to. This meant that for switch-statements, a counter's
location was set to the previous case's debug-location, causing
confusing stepping behaviour in debuggers. This patch makes sure we
attach a dummy debug-location for the increment instructions.

rdar://123050737
---
 clang/lib/CodeGen/CodeGenFunction.h   |  4 +-
 .../debug-info-instr_profile_switch.cpp   | 40 +++
 2 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Profile/debug-info-instr_profile_switch.cpp

diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index ff1873325d409f..8a1c2ea0326c35 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -1587,8 +1587,10 @@ class CodeGenFunction : public CodeGenTypeCache {
   void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) {
 if (CGM.getCodeGenOpts().hasProfileClangInstr() &&
 !CurFn->hasFnAttribute(llvm::Attribute::NoProfile) &&
-!CurFn->hasFnAttribute(llvm::Attribute::SkipProfile))
+!CurFn->hasFnAttribute(llvm::Attribute::SkipProfile)) {
+  auto AL = ApplyDebugLocation::CreateArtificial(*this);
   PGO.emitCounterSetOrIncrement(Builder, S, StepV);
+}
 PGO.setCurrentStmt(S);
   }
 
diff --git a/clang/test/Profile/debug-info-instr_profile_switch.cpp 
b/clang/test/Profile/debug-info-instr_profile_switch.cpp
new file mode 100644
index 00..09edf9a96b0167
--- /dev/null
+++ b/clang/test/Profile/debug-info-instr_profile_switch.cpp
@@ -0,0 +1,40 @@
+// Tests that we don't attach misleading debug locations to 
llvm.instrprof.increment
+// counters.
+
+// RUN: %clang_cc1 -x c++ %s -debug-info-kind=standalone -triple 
%itanium_abi_triple -main-file-name debug-info-instr_profile_switch.cpp 
-std=c++11 -o - -emit-llvm -fprofile-instrument=clang | FileCheck %s
+
+int main(int argc, const char *argv[]) {
+  switch(argc) {
+case 0:
+  return 0;
+case 1:
+  return 1;
+  }
+}
+
+// CHECK: define noundef i32 @main(i32 noundef %argc, ptr noundef %argv) #0 
!dbg ![[MAIN_SCOPE:[0-9]+]]
+
+// CHECK:switch i32 {{.*}}, label {{.*}} [
+// CHECK-NEXT: i32 0, label %[[CASE1_LBL:[a-z0-9.]+]]
+// CHECK-NEXT: i32 1, label %[[CASE2_LBL:[a-z0-9.]+]]
+// CHECK-NEXT:   ], !dbg ![[SWITCH_LOC:[0-9]+]]
+
+// CHECK:   [[CASE1_LBL]]:
+// CHECK-NEXT: %{{.*}} = load i64, ptr getelementptr inbounds ({{.*}}, ptr 
@__profc_main, {{.*}}), align {{.*}}, !dbg ![[CTR_LOC:[0-9]+]]
+// CHECK-NEXT: %{{.*}} = add {{.*}}, !dbg ![[CTR_LOC]]
+// CHECK-NEXT: store i64 {{.*}}, ptr getelementptr inbounds ({{.*}}, ptr 
@__profc_main, {{.*}}), align {{.*}}, !dbg ![[CTR_LOC]]
+// CHECK-NEXT: store i32 0, {{.*}} !dbg ![[CASE1_LOC:[0-9]+]]
+// CHECK-NEXT: br label {{.*}}, !dbg ![[CASE1_LOC]]
+
+// CHECK:   [[CASE2_LBL]]:
+// CHECK-NEXT: %{{.*}} = load i64, ptr getelementptr inbounds ({{.*}}, ptr 
@__profc_main, {{.*}}), align {{.*}}, !dbg ![[CTR_LOC]]
+// CHECK-NEXT: %{{.*}} = add {{.*}}, !dbg ![[CTR_LOC]]
+// CHECK-NEXT: store i64 {{.*}}, ptr getelementptr inbounds ({{.*}}, ptr 
@__profc_main, {{.*}}), align {{.*}}, !dbg ![[CTR_LOC]]
+// CHECK-NEXT: store i32 1, {{.*}} !dbg ![[CASE2_LOC:[0-9]+]]
+// CHECK-NEXT: br label {{.*}}, !dbg ![[CASE2_LOC]]
+
+// CHECK: ![[SWITCH_LOC]] = !DILocation({{.*}}, scope: ![[MAIN_SCOPE]])
+// CHECK: ![[CTR_LOC]] = !DILocation(line: 0, scope: ![[BLOCK_SCOPE:[0-9]+]])
+// CHECK: ![[BLOCK_SCOPE]] = distinct !DILexicalBlock(scope: ![[MAIN_SCOPE]]
+// CHECK: ![[CASE1_LOC]] = !DILocation(line: {{.*}}, column: {{.*}}, scope: 
![[BLOCK_SCOPE]])
+// CHECK: ![[CASE2_LOC]] = !DILocation(line: {{.*}}, column: {{.*}}, scope: 
![[BLOCK_SCOPE]])

>From 8fc35f6ff0b70cb6726ed3b435acf9c463895d22 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 2 May 2024 01:32:16 +0100
Subject: [PATCH 2/2] fixup! make FileCheck pattern less strict. Resolve
 Linux/Windows test failures

---
 clang/test/Profile/debug-info-instr_profile_switch.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Profile/debug-info-instr_profile_switch.cpp 
b/clang/test/Profile/debug-info-instr_profile_switch.cpp
index 09edf9a96b0167..205195a0e1225c 100644
--- a/clang/test/Profile/debug-info-instr_profile_switch.cpp
+++ b/clang/test/Profile/debug-info-instr_profile_switch.cpp
@@ -12,7 +12,7 @@ int main(int argc, const char *argv[]) {
   }
 }
 
-// CHECK: define noundef i32 @main(i32 noundef 

[clang] Fix sanitize problem. (PR #90800)

2024-05-01 Thread via cfe-commits

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


[clang] 4b75fcf - Triple::normalize: Use none as OS for XX-none-ABI (#89638)

2024-05-01 Thread via cfe-commits

Author: YunQiang Su
Date: 2024-05-02T08:04:53+08:00
New Revision: 4b75fcf0a50f4be955b611e8e20d84d90ea133c8

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

LOG: Triple::normalize: Use none as OS for XX-none-ABI (#89638)

When parsing a 3-component triple, after we determine Arch and Env, if
the middle component is "none", treat it as OS instead of Vendor.

See:
https://discourse.llvm.org/t/rfc-baremetal-target-triple-normalization/78524
Fixes: #89582.

Added: 


Modified: 
clang/docs/Multilib.rst
clang/test/Driver/arm-ias-Wa.s
clang/test/Driver/arm-triple.c
clang/test/Driver/baremetal-multilib-layered.yaml
clang/test/Driver/baremetal-multilib.yaml
clang/test/Driver/baremetal-sysroot.cpp
clang/test/Driver/baremetal.cpp
clang/test/Driver/print-multi-selection-flags.c
clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
llvm/lib/TargetParser/Triple.cpp
llvm/unittests/TargetParser/TripleTest.cpp

Removed: 




diff  --git a/clang/docs/Multilib.rst b/clang/docs/Multilib.rst
index ab737e43b97d23..063fe9a336f2fe 100644
--- a/clang/docs/Multilib.rst
+++ b/clang/docs/Multilib.rst
@@ -188,9 +188,9 @@ For a more comprehensive example see
   - Dir: thumb/v6-m
 # List of one or more normalized command line options, as generated by 
Clang
 # from the command line options or from Mappings below.
-# Here, if the flags are a superset of {target=thumbv6m-none-unknown-eabi}
+# Here, if the flags are a superset of {target=thumbv6m-unknown-none-eabi}
 # then this multilib variant will be considered a match.
-Flags: [--target=thumbv6m-none-unknown-eabi]
+Flags: [--target=thumbv6m-unknown-none-eabi]
 
   # Similarly, a multilib variant targeting Arm v7-M with an FPU (floating
   # point unit).

diff  --git a/clang/test/Driver/arm-ias-Wa.s b/clang/test/Driver/arm-ias-Wa.s
index b82ce8dfb31ab3..5e9518ed2dc423 100644
--- a/clang/test/Driver/arm-ias-Wa.s
+++ b/clang/test/Driver/arm-ias-Wa.s
@@ -71,7 +71,7 @@
 
 // RUN: %clang -target armv7r-none-eabi -c %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-R-PROFILE %s
-// CHECK-R-PROFILE: "-triple" "armv7r-none-unknown-eabi"
+// CHECK-R-PROFILE: "-triple" "armv7r-unknown-none-eabi"
 
 // RUN: %clang -target armv7m-none-eabi -c %s -### 2>&1 \
 // RUN: %clang -target thumbv7m-none-eabi -c %s -### 2>&1 \

diff  --git a/clang/test/Driver/arm-triple.c b/clang/test/Driver/arm-triple.c
index fa9f7b189c8278..1fb2b5afe22a51 100644
--- a/clang/test/Driver/arm-triple.c
+++ b/clang/test/Driver/arm-triple.c
@@ -7,7 +7,7 @@
 // RUN: %clang -print-effective-triple \
 // RUN:   --target=arm-none-eabihf -march=armv4t -mfloat-abi=softfp \
 // RUN:   | FileCheck %s --check-prefix=CHECK-DEFAULT
-// CHECK-DEFAULT: armv4t-none-unknown-eabi
+// CHECK-DEFAULT: armv4t-unknown-none-eabi
 
 // RUN: %clang -print-effective-triple \
 // RUN:   --target=armeb-none-eabi \
@@ -15,7 +15,7 @@
 // RUN: %clang -print-effective-triple \
 // RUN:   --target=arm-none-eabi -mbig-endian \
 // RUN:   | FileCheck %s --check-prefix=CHECK-EB
-// CHECK-EB: armebv4t-none-unknown-eabi
+// CHECK-EB: armebv4t-unknown-none-eabi
 
 // RUN: %clang -print-effective-triple \
 // RUN:   --target=arm-none-eabihf -march=armv4t \
@@ -23,7 +23,7 @@
 // RUN: %clang -print-effective-triple \
 // RUN:   --target=arm-none-eabi -mfloat-abi=hard \
 // RUN:   | FileCheck %s --check-prefix=CHECK-HF
-// CHECK-HF: armv4t-none-unknown-eabihf
+// CHECK-HF: armv4t-unknown-none-eabihf
 
 // RUN: %clang -print-effective-triple \
 // RUN:   --target=armeb-none-eabihf -march=armv4t \
@@ -37,7 +37,7 @@
 // RUN: %clang -print-effective-triple \
 // RUN:   --target=arm-none-eabi -mbig-endian -mfloat-abi=hard \
 // RUN:   | FileCheck %s --check-prefix=CHECK-EB-HF
-// CHECK-EB-HF: armebv4t-none-unknown-eabihf
+// CHECK-EB-HF: armebv4t-unknown-none-eabihf
 
 // RUN: %clang -print-effective-triple \
 // RUN:   --target=arm-none-eabi -march=armv8m.main -mbig-endian 
-mfloat-abi=hard \
@@ -45,4 +45,4 @@
 // RUN: %clang -print-effective-triple \
 // RUN:   --target=arm-none-eabi -mcpu=cortex-m33 -mbig-endian 
-mfloat-abi=hard \
 // RUN:   | FileCheck %s --check-prefix=CHECK-V8M-EB-HF
-// CHECK-V8M-EB-HF: thumbebv8m.main-none-unknown-eabihf
+// CHECK-V8M-EB-HF: thumbebv8m.main-unknown-none-eabihf

diff  --git a/clang/test/Driver/baremetal-multilib-layered.yaml 
b/clang/test/Driver/baremetal-multilib-layered.yaml
index 2f86f8e3ea4f5f..a525436d8122f5 100644
--- a/clang/test/Driver/baremetal-multilib-layered.yaml
+++ b/clang/test/Driver/baremetal-multilib-layered.yaml
@@ -18,7 +18,7 @@
 # RUN: %T/baremetal_multilib_layered/bin/clang -no-canonical-prefixes -x c++ 
%s -### -o %t.out 2>&1 \
 # RUN: --target=thumbv7m-none-eabi -mfloat-abi=softfp --sysroot= \
 

[clang] [llvm] Triple::normalize: Use none as OS for XX-none-ABI (PR #89638)

2024-05-01 Thread YunQiang Su via cfe-commits

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


[clang] [WebAssembly] Disable reference types in generic CPU (PR #90792)

2024-05-01 Thread Heejin Ahn via cfe-commits

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


[clang] 8c64a30 - [WebAssembly] Disable reference types in generic CPU (#90792)

2024-05-01 Thread via cfe-commits

Author: Heejin Ahn
Date: 2024-05-01T16:50:58-07:00
New Revision: 8c64a304123b77d598eda73a14cf3ff0ec7970dc

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

LOG: [WebAssembly] Disable reference types in generic CPU (#90792)

#80923 newly enabled multivalue and reference-types in the generic CPU.
But enabling reference-types ended up breaking up Wasm's Chromium CI
(https://chromium-review.googlesource.com/c/emscripten-releases/+/5500231)
because the way the table index is encoded is different from MVP (u32)
vs. reference-types (LEB), which caused different encodings for
`call_indirect`.

And Chromium CI's and Emscripten's minimum required node version is v16,
which does not yet support reference-types, which does not recognize
that table index encoding. reference-types is first supported in node
v17.2.

We knew the current minimum required node for Emscripten (v16) did not
support reference-types, but thought it was fine because unless you
explicitly use `__funcref` or `__externref` things would be fine, and if
you want to use them explicitly, you would have a newer node. But it
turned out it also affected the encoding of `call_indirect`.

While we are discussing the potential solutions, I will disable
reference-types to unblock the rolls.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Targets/WebAssembly.cpp
clang/test/Preprocessor/wasm-target-features.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2c5308fbcb319a..0e3f7cf89ca885 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -742,10 +742,10 @@ AIX Support
 WebAssembly Support
 ^^^
 
-The -mcpu=generic configuration now enables multivalue and 
reference-types.These
-proposals are standardized and available in all major engines. Enabling
-multivalue here only enables the language feature but does not turn on the
-multivalue ABI (this enables non-ABI uses of multivalue, like exnref).
+The -mcpu=generic configuration now enables multivalue feature, which is
+standardized and available in all major engines. Enabling multivalue here only
+enables the language feature but does not turn on the multivalue ABI (this
+enables non-ABI uses of multivalue, like exnref).
 
 AVR Support
 ^^^

diff  --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 1f0418b21c1f86..a6d820e108088f 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -153,7 +153,6 @@ bool WebAssemblyTargetInfo::initFeatureMap(
   auto addGenericFeatures = [&]() {
 Features["multivalue"] = true;
 Features["mutable-globals"] = true;
-Features["reference-types"] = true;
 Features["sign-ext"] = true;
   };
   auto addBleedingEdgeFeatures = [&]() {
@@ -162,6 +161,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
 Features["bulk-memory"] = true;
 Features["multimemory"] = true;
 Features["nontrapping-fptoint"] = true;
+Features["reference-types"] = true;
 Features["tail-call"] = true;
 Features["half-precision"] = true;
 setSIMDLevel(Features, SIMD128, true);

diff  --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index 72ecc60a6e7898..5a4f85461d5aa2 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -164,7 +164,6 @@
 //
 // GENERIC-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
-// GENERIC-INCLUDE-DAG: #define __wasm_reference_types__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_sign_ext__ 1{{$}}
 //
 // RUN: %clang -E -dM %s -o - 2>&1 \
@@ -181,6 +180,7 @@
 // GENERIC-NOT: #define __wasm_half_precision__ 1{{$}}
 // GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT: #define __wasm_nontrapping_fptoint__ 1{{$}}
+// GENERIC-NOT: #define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
 // GENERIC-NOT: #define __wasm_simd128__ 1{{$}}
 // GENERIC-NOT: #define __wasm_tail_call__ 1{{$}}



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


[clang] [WebAssembly] Disable reference types in generic CPU (PR #90792)

2024-05-01 Thread Heejin Ahn via cfe-commits

aheejin wrote:

Will land this given that this is necessary to unblock the rolls and the full 
CI will take more than a full day.

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


[clang] Fix sanitize problem. (PR #90800)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (jyu2-git)


Changes

Currently isMapType could return OpenMPMapModifierKind.

The change is to return OpenMPMapTypeKind only, if it is not MapType Kind 
OMPC_MAP_unknown is returned.

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


1 Files Affected:

- (modified) clang/lib/Parse/ParseOpenMP.cpp (+6-2) 


``diff
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 53d89ce2fa3e99..b1cff11af590a5 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4316,7 +4316,7 @@ bool 
Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) {
 }
 
 /// Checks if the token is a valid map-type.
-/// FIXME: It will return an OpenMPMapModifierKind if that's what it parses.
+/// If it is not MapType kind, OMPC_MAP_unknown is returned.
 static OpenMPMapClauseKind isMapType(Parser ) {
   Token Tok = P.getCurToken();
   // The map-type token can be either an identifier or the C++ delete keyword.
@@ -4326,7 +4326,11 @@ static OpenMPMapClauseKind isMapType(Parser ) {
   OpenMPMapClauseKind MapType =
   static_cast(getOpenMPSimpleClauseType(
   OMPC_map, PP.getSpelling(Tok), P.getLangOpts()));
-  return MapType;
+  if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_from ||
+  MapType == OMPC_MAP_tofrom || MapType == OMPC_MAP_alloc ||
+  MapType == OMPC_MAP_delete || MapType == OMPC_MAP_release)
+return MapType;
+  return OMPC_MAP_unknown;
 }
 
 /// Parse map-type in map clause.

``




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


[clang] Fix sanitize problem. (PR #90800)

2024-05-01 Thread via cfe-commits

https://github.com/jyu2-git created 
https://github.com/llvm/llvm-project/pull/90800

Currently isMapType could return OpenMPMapModifierKind.

The change is to return OpenMPMapTypeKind only, if it is not MapType Kind 
OMPC_MAP_unknown is returned.

>From ef84e989066318f0f7652080b471c91f8cb1360e Mon Sep 17 00:00:00 2001
From: Jennifer Yu 
Date: Wed, 1 May 2024 15:38:36 -0700
Subject: [PATCH] Fix sanitize problem.

Currently isMapType could return OpenMPMapModifierKind.

The change is to return OpenMPMapTypeKind only, if it is not MapType
Kind OMPC_MAP_unknown is returned.
---
 clang/lib/Parse/ParseOpenMP.cpp | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 53d89ce2fa3e99..b1cff11af590a5 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4316,7 +4316,7 @@ bool 
Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) {
 }
 
 /// Checks if the token is a valid map-type.
-/// FIXME: It will return an OpenMPMapModifierKind if that's what it parses.
+/// If it is not MapType kind, OMPC_MAP_unknown is returned.
 static OpenMPMapClauseKind isMapType(Parser ) {
   Token Tok = P.getCurToken();
   // The map-type token can be either an identifier or the C++ delete keyword.
@@ -4326,7 +4326,11 @@ static OpenMPMapClauseKind isMapType(Parser ) {
   OpenMPMapClauseKind MapType =
   static_cast(getOpenMPSimpleClauseType(
   OMPC_map, PP.getSpelling(Tok), P.getLangOpts()));
-  return MapType;
+  if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_from ||
+  MapType == OMPC_MAP_tofrom || MapType == OMPC_MAP_alloc ||
+  MapType == OMPC_MAP_delete || MapType == OMPC_MAP_release)
+return MapType;
+  return OMPC_MAP_unknown;
 }
 
 /// Parse map-type in map clause.

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


[clang] [llvm] [Libomptarget] Statically link all plugin runtimes (PR #87009)

2024-05-01 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/87009

>From 8c4b7ffb49c8f91768af3bec00669bac5433ec0f Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 28 Mar 2024 16:18:19 -0500
Subject: [PATCH] [Libomptarget] Statically link all plugin runtimes

Summary:
This patch overhauls the `libomptarget` and plugin interface. Currently,
we define a C API and compile each plugin as a separate shared library.
Then, `libomptarget` loads these API functions and forwards its internal
calls to them. This was originally designed to allow multiple
implementations of a library to be live. However, since then no one has
used this functionality and it prevents us from using much nicer
interfaces. If the old behavior is desired it should instead be
implemented as a separate plugin.

This patch replaces the `PluginAdaptorTy` interface with the
`GenericPluginTy` that is used by the plugins. Each plugin exports a
`createPlugin_` function that is used to get the specific
implementation. This code is now shared with `libomptarget`.

There are some notable improvements to this.
1. Massively improved lifetimes of life runtime objects
2. The plugins can use a C++ interface
3. Global state does not need to be duplicated for each plugin +
   libomptarget
4. Easier to use and add features and improve error handling
5. Less function call overhead / Improved LTO performance.

Additional changes in this plugin are related to contending with the
fact that state is now shared. Initialization and deinitialization is
now handled correctly and in phase with the underlying runtime, allowing
us to actually know when something is getting deallocated.

Depends on https://github.com/llvm/llvm-project/pull/86971 
https://github.com/llvm/llvm-project/pull/86875 
https://github.com/llvm/llvm-project/pull/86868
---
 clang/test/Driver/linker-wrapper-image.c  |   2 +-
 .../Frontend/Offloading/OffloadWrapper.cpp|   7 +-
 offload/include/PluginManager.h   |  61 ++
 offload/include/device.h  |   8 +-
 offload/plugins-nextgen/CMakeLists.txt|  19 +-
 offload/plugins-nextgen/amdgpu/CMakeLists.txt |   5 -
 offload/plugins-nextgen/amdgpu/src/rtl.cpp|  14 +-
 offload/plugins-nextgen/common/CMakeLists.txt |   4 +-
 .../common/include/PluginInterface.h  |  94 +---
 .../common/include/Utils/ELF.h|   2 -
 offload/plugins-nextgen/common/src/JIT.cpp|  40 ++--
 .../common/src/PluginInterface.cpp| 205 --
 offload/plugins-nextgen/cuda/CMakeLists.txt   |   5 -
 offload/plugins-nextgen/cuda/src/rtl.cpp  |  14 +-
 offload/plugins-nextgen/host/CMakeLists.txt   |   8 -
 offload/plugins-nextgen/host/src/rtl.cpp  |  14 +-
 offload/src/CMakeLists.txt|   4 +
 offload/src/OffloadRTL.cpp|   1 +
 offload/src/OpenMP/InteropAPI.cpp |   4 +-
 offload/src/PluginManager.cpp | 129 ---
 offload/src/device.cpp|   3 +-
 offload/src/interface.cpp |   2 +-
 .../kernelreplay/llvm-omp-kernel-replay.cpp   |   2 -
 .../unittests/Plugins/NextgenPluginsTest.cpp  |   1 -
 24 files changed, 126 insertions(+), 522 deletions(-)

diff --git a/clang/test/Driver/linker-wrapper-image.c 
b/clang/test/Driver/linker-wrapper-image.c
index d01445e3aed04e..5d5d62805e174d 100644
--- a/clang/test/Driver/linker-wrapper-image.c
+++ b/clang/test/Driver/linker-wrapper-image.c
@@ -30,8 +30,8 @@
 
 //  OPENMP: define internal void @.omp_offloading.descriptor_reg() section 
".text.startup" {
 // OPENMP-NEXT: entry:
-// OPENMP-NEXT:   %0 = call i32 @atexit(ptr @.omp_offloading.descriptor_unreg)
 // OPENMP-NEXT:   call void @__tgt_register_lib(ptr 
@.omp_offloading.descriptor)
+// OPENMP-NEXT:   %0 = call i32 @atexit(ptr @.omp_offloading.descriptor_unreg)
 // OPENMP-NEXT:   ret void
 // OPENMP-NEXT: }
 
diff --git a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp 
b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
index 7241d15ed1c670..8b6f9ea1f4cca3 100644
--- a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
+++ b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
@@ -232,12 +232,13 @@ void createRegisterFunction(Module , GlobalVariable 
*BinDesc,
   // Construct function body
   IRBuilder<> Builder(BasicBlock::Create(C, "entry", Func));
 
+  Builder.CreateCall(RegFuncC, BinDesc);
+
   // Register the destructors with 'atexit'. This is expected by the CUDA
   // runtime and ensures that we clean up before dynamic objects are destroyed.
-  // This needs to be done before the runtime is called and registers its own.
+  // This needs to be done after plugin initialization to ensure that it is
+  // called before the plugin runtime is destroyed.
   Builder.CreateCall(AtExit, UnregFunc);
-
-  Builder.CreateCall(RegFuncC, BinDesc);
   Builder.CreateRetVoid();
 
   // Add this function to constructors.
diff --git a/offload/include/PluginManager.h 

[clang] [WebAssembly] Disable reference types in generic CPU (PR #90792)

2024-05-01 Thread Heejin Ahn via cfe-commits

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


[clang] [OpenACC} Implement SubArray Parsing/Sema (PR #90796)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Erich Keane (erichkeane)


Changes

This implementation takes quite a bit from the OMP implementation of array 
sections, but only has to enforce the rules as applicable to OpenACC.  
Additionally, it does its best to create an AST node (with the assistance of 
RecoveryExprs) with as much checking done as soon as possible in the case of 
instantiations.

---

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


12 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+22-2) 
- (modified) clang/lib/Parse/ParseExpr.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaOpenACC.cpp (+220-12) 
- (modified) clang/test/ParserOpenACC/parse-cache-construct.c (+1-2) 
- (modified) clang/test/ParserOpenACC/parse-cache-construct.cpp (+4-4) 
- (modified) clang/test/ParserOpenACC/parse-clauses.c (-2) 
- (added) clang/test/ParserOpenACC/parse-sub-array.cpp (+89) 
- (modified) clang/test/SemaOpenACC/compute-construct-private-clause.c (+9-17) 
- (modified) clang/test/SemaOpenACC/compute-construct-private-clause.cpp (+1-2) 
- (modified) clang/test/SemaOpenACC/compute-construct-varlist-ast.cpp (+9) 
- (added) clang/test/SemaOpenACC/sub-array-ast.cpp (+566) 
- (added) clang/test/SemaOpenACC/sub-array.cpp (+208) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4b074b853bfe65..fbb107679d94ba 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12291,8 +12291,8 @@ def warn_acc_if_self_conflict
   "evaluates to true">,
   InGroup>;
 def err_acc_int_expr_requires_integer
-: Error<"OpenACC %select{clause|directive}0 '%1' requires expression of "
-"integer type (%2 invalid)">;
+: Error<"OpenACC %select{clause '%1'|directive '%2'|sub-array bound}0 "
+"requires expression of integer type (%3 invalid)">;
 def err_acc_int_expr_incomplete_class_type
 : Error<"OpenACC integer expression has incomplete class type %0">;
 def err_acc_int_expr_explicit_conversion
@@ -12310,4 +12310,24 @@ def err_acc_num_gangs_num_args
 def err_acc_not_a_var_ref
 : Error<"OpenACC variable is not a valid variable name, sub-array, array "
 "element, or composite variable member">;
+def err_acc_typecheck_subarray_value
+: Error<"OpenACC sub-array subscripted value is not an array or pointer">;
+def err_acc_subarray_function_type
+: Error<"OpenACC sub-array cannot be of function type %0">;
+def err_acc_subarray_incomplete_type
+: Error<"OpenACC sub-array base is of incomplete type %0">;
+def err_acc_subarray_no_length
+: Error<"OpenACC sub-array length is unspecified and cannot be inferred "
+"because the subscripted value is %select{not an array|an array of 
"
+"unknown bound}0">;
+def err_acc_subarray_negative
+: Error<"OpenACC sub-array %select{lower bound|length}0 evaluated to "
+"negative value %1">;
+def err_acc_subarray_out_of_range
+: Error<"OpenACC sub-array %select{lower bound|length}0 evaluated to a "
+"value (%1) that would be out of the range of the subscripted "
+"array size of %2">;
+def err_acc_subarray_base_plus_length_out_of_range
+: Error<"OpenACC sub-array specified range [%0:%1] would be out of the "
+"range of the subscripted array size of %2">;
 } // end of sema component.
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 7d6febb04a82c4..5f5f9a79c8c408 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2039,7 +2039,8 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
 if (Tok.is(tok::colon)) {
   // Consume ':'
   ColonLocFirst = ConsumeToken();
-  Length = Actions.CorrectDelayedTyposInExpr(ParseExpression());
+  if (Tok.isNot(tok::r_square))
+Length = Actions.CorrectDelayedTyposInExpr(ParseExpression());
 }
   } else if (ArgExprs.size() <= 1 && getLangOpts().OpenMP) {
 ColonProtectionRAIIObject RAII(*this);
diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 3ea81e0497c203..a203ece7ff3130 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -16,6 +16,7 @@
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/OpenACCKinds.h"
 #include "clang/Sema/Sema.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Casting.h"
 
 using namespace clang;
@@ -367,7 +368,9 @@ ExprResult SemaOpenACC::ActOnIntExpr(OpenACCDirectiveKind 
DK,
   assert(((DK != OpenACCDirectiveKind::Invalid &&
CK == OpenACCClauseKind::Invalid) ||
   (DK == OpenACCDirectiveKind::Invalid &&
-   CK != OpenACCClauseKind::Invalid)) &&
+   CK != OpenACCClauseKind::Invalid) ||

[clang] [OpenACC} Implement SubArray Parsing/Sema (PR #90796)

2024-05-01 Thread Erich Keane via cfe-commits

https://github.com/erichkeane created 
https://github.com/llvm/llvm-project/pull/90796

This implementation takes quite a bit from the OMP implementation of array 
sections, but only has to enforce the rules as applicable to OpenACC.  
Additionally, it does its best to create an AST node (with the assistance of 
RecoveryExprs) with as much checking done as soon as possible in the case of 
instantiations.

>From ac69522bf15c7c169c4cdb9d3d1547c5c0962193 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Tue, 30 Apr 2024 11:42:35 -0700
Subject: [PATCH] [OpenACC} Implement SubArray Parsing/Sema

This implementation takes quite a bit from the OMP implementation of
array sections, but only has to enforce the rules as applicable to
OpenACC.  Additionally, it does its best to create an AST node (with the
assistance of RecoveryExprs) with as much checking done as soon as
possible in the case of instantiations.
---
 .../clang/Basic/DiagnosticSemaKinds.td|  24 +-
 clang/lib/Parse/ParseExpr.cpp |   3 +-
 clang/lib/Sema/SemaOpenACC.cpp| 232 ++-
 .../ParserOpenACC/parse-cache-construct.c |   3 +-
 .../ParserOpenACC/parse-cache-construct.cpp   |   8 +-
 clang/test/ParserOpenACC/parse-clauses.c  |   2 -
 clang/test/ParserOpenACC/parse-sub-array.cpp  |  89 +++
 .../compute-construct-private-clause.c|  26 +-
 .../compute-construct-private-clause.cpp  |   3 +-
 .../compute-construct-varlist-ast.cpp |   9 +
 clang/test/SemaOpenACC/sub-array-ast.cpp  | 566 ++
 clang/test/SemaOpenACC/sub-array.cpp  | 208 +++
 12 files changed, 1131 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/ParserOpenACC/parse-sub-array.cpp
 create mode 100644 clang/test/SemaOpenACC/sub-array-ast.cpp
 create mode 100644 clang/test/SemaOpenACC/sub-array.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4b074b853bfe65..fbb107679d94ba 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12291,8 +12291,8 @@ def warn_acc_if_self_conflict
   "evaluates to true">,
   InGroup>;
 def err_acc_int_expr_requires_integer
-: Error<"OpenACC %select{clause|directive}0 '%1' requires expression of "
-"integer type (%2 invalid)">;
+: Error<"OpenACC %select{clause '%1'|directive '%2'|sub-array bound}0 "
+"requires expression of integer type (%3 invalid)">;
 def err_acc_int_expr_incomplete_class_type
 : Error<"OpenACC integer expression has incomplete class type %0">;
 def err_acc_int_expr_explicit_conversion
@@ -12310,4 +12310,24 @@ def err_acc_num_gangs_num_args
 def err_acc_not_a_var_ref
 : Error<"OpenACC variable is not a valid variable name, sub-array, array "
 "element, or composite variable member">;
+def err_acc_typecheck_subarray_value
+: Error<"OpenACC sub-array subscripted value is not an array or pointer">;
+def err_acc_subarray_function_type
+: Error<"OpenACC sub-array cannot be of function type %0">;
+def err_acc_subarray_incomplete_type
+: Error<"OpenACC sub-array base is of incomplete type %0">;
+def err_acc_subarray_no_length
+: Error<"OpenACC sub-array length is unspecified and cannot be inferred "
+"because the subscripted value is %select{not an array|an array of 
"
+"unknown bound}0">;
+def err_acc_subarray_negative
+: Error<"OpenACC sub-array %select{lower bound|length}0 evaluated to "
+"negative value %1">;
+def err_acc_subarray_out_of_range
+: Error<"OpenACC sub-array %select{lower bound|length}0 evaluated to a "
+"value (%1) that would be out of the range of the subscripted "
+"array size of %2">;
+def err_acc_subarray_base_plus_length_out_of_range
+: Error<"OpenACC sub-array specified range [%0:%1] would be out of the "
+"range of the subscripted array size of %2">;
 } // end of sema component.
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 7d6febb04a82c4..5f5f9a79c8c408 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2039,7 +2039,8 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
 if (Tok.is(tok::colon)) {
   // Consume ':'
   ColonLocFirst = ConsumeToken();
-  Length = Actions.CorrectDelayedTyposInExpr(ParseExpression());
+  if (Tok.isNot(tok::r_square))
+Length = Actions.CorrectDelayedTyposInExpr(ParseExpression());
 }
   } else if (ArgExprs.size() <= 1 && getLangOpts().OpenMP) {
 ColonProtectionRAIIObject RAII(*this);
diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 3ea81e0497c203..a203ece7ff3130 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -16,6 +16,7 @@
 #include "clang/Basic/DiagnosticSema.h"
 #include 

[clang] [WebAssembly] Disable reference types in generic CPU (PR #90792)

2024-05-01 Thread Derek Schuff via cfe-commits

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


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


[clang] [llvm] [Libomptarget] Statically link all plugin runtimes (PR #87009)

2024-05-01 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/87009

>From 473a4b9bad09bd9af8186932984be7696711692e Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 28 Mar 2024 16:18:19 -0500
Subject: [PATCH] [Libomptarget] Statically link all plugin runtimes

Summary:
This patch overhauls the `libomptarget` and plugin interface. Currently,
we define a C API and compile each plugin as a separate shared library.
Then, `libomptarget` loads these API functions and forwards its internal
calls to them. This was originally designed to allow multiple
implementations of a library to be live. However, since then no one has
used this functionality and it prevents us from using much nicer
interfaces. If the old behavior is desired it should instead be
implemented as a separate plugin.

This patch replaces the `PluginAdaptorTy` interface with the
`GenericPluginTy` that is used by the plugins. Each plugin exports a
`createPlugin_` function that is used to get the specific
implementation. This code is now shared with `libomptarget`.

There are some notable improvements to this.
1. Massively improved lifetimes of life runtime objects
2. The plugins can use a C++ interface
3. Global state does not need to be duplicated for each plugin +
   libomptarget
4. Easier to use and add features and improve error handling
5. Less function call overhead / Improved LTO performance.

Additional changes in this plugin are related to contending with the
fact that state is now shared. Initialization and deinitialization is
now handled correctly and in phase with the underlying runtime, allowing
us to actually know when something is getting deallocated.

Depends on https://github.com/llvm/llvm-project/pull/86971 
https://github.com/llvm/llvm-project/pull/86875 
https://github.com/llvm/llvm-project/pull/86868
---
 clang/test/Driver/linker-wrapper-image.c  |   2 +-
 .../Frontend/Offloading/OffloadWrapper.cpp|   7 +-
 offload/include/PluginManager.h   |  61 ++
 offload/include/device.h  |   8 +-
 offload/plugins-nextgen/CMakeLists.txt|  19 +-
 offload/plugins-nextgen/amdgpu/CMakeLists.txt |   5 -
 offload/plugins-nextgen/amdgpu/src/rtl.cpp|  14 +-
 offload/plugins-nextgen/common/CMakeLists.txt |   4 +-
 .../common/include/PluginInterface.h  |  94 +---
 .../common/include/Utils/ELF.h|   2 -
 offload/plugins-nextgen/common/src/JIT.cpp|  40 ++--
 .../common/src/PluginInterface.cpp| 205 --
 offload/plugins-nextgen/cuda/CMakeLists.txt   |   5 -
 offload/plugins-nextgen/cuda/src/rtl.cpp  |  14 +-
 offload/plugins-nextgen/host/CMakeLists.txt   |   8 -
 offload/plugins-nextgen/host/src/rtl.cpp  |  14 +-
 offload/src/CMakeLists.txt|   4 +
 offload/src/OffloadRTL.cpp|   1 +
 offload/src/OpenMP/InteropAPI.cpp |   4 +-
 offload/src/PluginManager.cpp | 129 ---
 offload/src/device.cpp|   3 +-
 offload/src/interface.cpp |   2 +-
 .../kernelreplay/llvm-omp-kernel-replay.cpp   |   2 -
 .../unittests/Plugins/NextgenPluginsTest.cpp  |   1 -
 24 files changed, 127 insertions(+), 521 deletions(-)

diff --git a/clang/test/Driver/linker-wrapper-image.c 
b/clang/test/Driver/linker-wrapper-image.c
index d01445e3aed04e..5d5d62805e174d 100644
--- a/clang/test/Driver/linker-wrapper-image.c
+++ b/clang/test/Driver/linker-wrapper-image.c
@@ -30,8 +30,8 @@
 
 //  OPENMP: define internal void @.omp_offloading.descriptor_reg() section 
".text.startup" {
 // OPENMP-NEXT: entry:
-// OPENMP-NEXT:   %0 = call i32 @atexit(ptr @.omp_offloading.descriptor_unreg)
 // OPENMP-NEXT:   call void @__tgt_register_lib(ptr 
@.omp_offloading.descriptor)
+// OPENMP-NEXT:   %0 = call i32 @atexit(ptr @.omp_offloading.descriptor_unreg)
 // OPENMP-NEXT:   ret void
 // OPENMP-NEXT: }
 
diff --git a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp 
b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
index 7241d15ed1c670..8b6f9ea1f4cca3 100644
--- a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
+++ b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
@@ -232,12 +232,13 @@ void createRegisterFunction(Module , GlobalVariable 
*BinDesc,
   // Construct function body
   IRBuilder<> Builder(BasicBlock::Create(C, "entry", Func));
 
+  Builder.CreateCall(RegFuncC, BinDesc);
+
   // Register the destructors with 'atexit'. This is expected by the CUDA
   // runtime and ensures that we clean up before dynamic objects are destroyed.
-  // This needs to be done before the runtime is called and registers its own.
+  // This needs to be done after plugin initialization to ensure that it is
+  // called before the plugin runtime is destroyed.
   Builder.CreateCall(AtExit, UnregFunc);
-
-  Builder.CreateCall(RegFuncC, BinDesc);
   Builder.CreateRetVoid();
 
   // Add this function to constructors.
diff --git a/offload/include/PluginManager.h 

[clang] [clang][SPARC] Treat empty structs as if it's a one-bit type in the CC (PR #90338)

2024-05-01 Thread via cfe-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/90338

>From 5935e661941fd681b2bf6b3d915e97fe0d73fcd8 Mon Sep 17 00:00:00 2001
From: Koakuma 
Date: Thu, 25 Apr 2024 22:37:03 +0700
Subject: [PATCH 1/2] [clang][SPARC] Treat empty structs as if it's a one-bit
 type in the CC

Make sure that empty structs are treated as if it has a size of
one bit in function parameters and return types so that it occupies
a full argument and/or return register slot.

This fixes crashes and miscompilations when passing and/or returning
empty structs.
---
 clang/lib/CodeGen/Targets/Sparc.cpp | 5 -
 clang/test/CodeGen/sparcv9-abi.c| 6 ++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/Sparc.cpp 
b/clang/lib/CodeGen/Targets/Sparc.cpp
index 9025a633f328e2..b82e9a69e19671 100644
--- a/clang/lib/CodeGen/Targets/Sparc.cpp
+++ b/clang/lib/CodeGen/Targets/Sparc.cpp
@@ -263,7 +263,10 @@ SparcV9ABIInfo::classifyType(QualType Ty, unsigned 
SizeLimit) const {
 
   CoerceBuilder CB(getVMContext(), getDataLayout());
   CB.addStruct(0, StrTy);
-  CB.pad(llvm::alignTo(CB.DL.getTypeSizeInBits(StrTy), 64));
+  // All structs, even empty ones, should take up a register argument slot,
+  // so pin the minimum struct size to one bit.
+  CB.pad(llvm::alignTo(
+  std::max(CB.DL.getTypeSizeInBits(StrTy).getKnownMinValue(), 1UL), 64));
 
   // Try to use the original type for coercion.
   llvm::Type *CoerceTy = CB.isUsableType(StrTy) ? StrTy : CB.getType();
diff --git a/clang/test/CodeGen/sparcv9-abi.c b/clang/test/CodeGen/sparcv9-abi.c
index 5e74a9a883cefa..360bd9d9019e56 100644
--- a/clang/test/CodeGen/sparcv9-abi.c
+++ b/clang/test/CodeGen/sparcv9-abi.c
@@ -21,6 +21,12 @@ char f_int_4(char x) { return x; }
 // CHECK-LABEL: define{{.*}} fp128 @f_ld(fp128 noundef %x)
 long double f_ld(long double x) { return x; }
 
+// Empty struct is lowered as a placeholder word parameter.
+struct empty {};
+
+// CHECK-LABEL: define{{.*}} i64 @f_empty(i64 %x.coerce)
+struct empty f_empty(struct empty x) { return x; }
+
 // Small structs are passed in registers.
 struct small {
   int *a, *b;

>From e93fd507429a1fb3be2618caa20656a94bbaa6a5 Mon Sep 17 00:00:00 2001
From: Koakuma 
Date: Thu, 2 May 2024 05:52:02 +0700
Subject: [PATCH 2/2] Add more tests to check for corner cases

---
 clang/test/CodeGen/sparcv9-abi.c | 37 +++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/clang/test/CodeGen/sparcv9-abi.c b/clang/test/CodeGen/sparcv9-abi.c
index 360bd9d9019e56..616e24e7c519d8 100644
--- a/clang/test/CodeGen/sparcv9-abi.c
+++ b/clang/test/CodeGen/sparcv9-abi.c
@@ -21,12 +21,47 @@ char f_int_4(char x) { return x; }
 // CHECK-LABEL: define{{.*}} fp128 @f_ld(fp128 noundef %x)
 long double f_ld(long double x) { return x; }
 
-// Empty struct is lowered as a placeholder word parameter.
+// Zero-sized structs reserves an argument register slot if passed directly.
 struct empty {};
+struct emptyarr { struct empty a[10]; };
 
 // CHECK-LABEL: define{{.*}} i64 @f_empty(i64 %x.coerce)
 struct empty f_empty(struct empty x) { return x; }
 
+// CHECK-LABEL: define{{.*}} i64 @f_emptyarr(i64 %x.coerce)
+struct empty f_emptyarr(struct emptyarr x) { return x.a[0]; }
+
+// CHECK-LABEL: define{{.*}} i64 @f_emptyvar(i32 noundef zeroext %count, ...)
+long f_emptyvar(unsigned count, ...) {
+long ret;
+va_list args;
+va_start(args, count);
+
+// CHECK: %[[CUR:[^ ]+]] = load ptr, ptr %args
+// CHECK-DAG: %[[NXT:[^ ]+]] = getelementptr inbounds i8, ptr %[[CUR]], i64 8
+// CHECK-DAG: store ptr %[[NXT]], ptr %args
+va_arg(args, struct empty);
+
+// CHECK: %[[CUR:[^ ]+]] = load ptr, ptr %args
+// CHECK-DAG: %[[NXT:[^ ]+]] = getelementptr inbounds i8, ptr %[[CUR]], i64 8
+// CHECK-DAG: store ptr %[[NXT]], ptr %args
+// CHECK-DAG: load i64, ptr %[[CUR]]
+ret = va_arg(args, long);
+va_end(args);
+return ret;
+}
+
+// If the zero-sized struct is contained in a non-zero-sized struct,
+// though, it doesn't reserve any registers.
+struct emptymixed { struct empty a; long b; };
+struct emptyflex { unsigned count; struct empty data[10]; };
+
+// CHECK-LABEL: define{{.*}} i64 @f_emptymixed(i64 %x.coerce)
+long f_emptymixed(struct emptymixed x) { return x.b; }
+
+// CHECK-LABEL: define{{.*}} i64 @f_emptyflex(i64 %x.coerce, i64 noundef %y)
+long f_emptyflex(struct emptyflex x, long y) { return y; }
+
 // Small structs are passed in registers.
 struct small {
   int *a, *b;

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


[clang] [clang][SPARC] Treat empty structs as if it's a one-bit type in the CC (PR #90338)

2024-05-01 Thread via cfe-commits


@@ -21,6 +21,12 @@ char f_int_4(char x) { return x; }
 // CHECK-LABEL: define{{.*}} fp128 @f_ld(fp128 noundef %x)
 long double f_ld(long double x) { return x; }
 
+// Empty struct is lowered as a placeholder word parameter.
+struct empty {};
+
+// CHECK-LABEL: define{{.*}} i64 @f_empty(i64 %x.coerce)
+struct empty f_empty(struct empty x) { return x; }
+

koachan wrote:

> struct with an empty base class

I don't think that this would affect C++, given that it already specifies empty 
structs/classes to have a size of one byte.
This is only an issue for C when using GCC's empty struct extension (as empty 
structs are zero bytes in it)...


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


[clang] [WebAssembly] Disable reference types in generic CPU (PR #90792)

2024-05-01 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-webassembly

@llvm/pr-subscribers-clang

Author: Heejin Ahn (aheejin)


Changes

 #80923 newly enabled multivalue and reference-types in the generic CPU.
But enabling reference-types ended up breaking up Wasm's Chromium CI 
(https://chromium-review.googlesource.com/c/emscripten-releases/+/5500231) 
because the way the table index is encoded different from MVP (u32) vs. 
reference-types (LEB), which caused different encodings for `call_indirect`.

And Chromium CI's and Emscripten's minimum required node version is v16, which 
does not yet support reference-types, which does not recognize that table index 
encoding. reference-types is first supported in node v17.2.

We knew the current minimum required node for Emscripten (v16) did not support 
reference-types, but thought it was fine because unless you explicitly use 
`__funcref` or `__externref` things would be fine, and if you want to use them 
explicitly, you would have a newer node. But it turned out it also affected the 
encoding of `call_indirect`.

While we are discussing the potential solutions, I will disable reference-types 
to unblock the rolls.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4-4) 
- (modified) clang/lib/Basic/Targets/WebAssembly.cpp (+1-1) 
- (modified) clang/test/Preprocessor/wasm-target-features.c (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2c5308fbcb319a..0e3f7cf89ca885 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -742,10 +742,10 @@ AIX Support
 WebAssembly Support
 ^^^
 
-The -mcpu=generic configuration now enables multivalue and 
reference-types.These
-proposals are standardized and available in all major engines. Enabling
-multivalue here only enables the language feature but does not turn on the
-multivalue ABI (this enables non-ABI uses of multivalue, like exnref).
+The -mcpu=generic configuration now enables multivalue feature, which is
+standardized and available in all major engines. Enabling multivalue here only
+enables the language feature but does not turn on the multivalue ABI (this
+enables non-ABI uses of multivalue, like exnref).
 
 AVR Support
 ^^^
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 1f0418b21c1f86..a6d820e108088f 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -153,7 +153,6 @@ bool WebAssemblyTargetInfo::initFeatureMap(
   auto addGenericFeatures = [&]() {
 Features["multivalue"] = true;
 Features["mutable-globals"] = true;
-Features["reference-types"] = true;
 Features["sign-ext"] = true;
   };
   auto addBleedingEdgeFeatures = [&]() {
@@ -162,6 +161,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
 Features["bulk-memory"] = true;
 Features["multimemory"] = true;
 Features["nontrapping-fptoint"] = true;
+Features["reference-types"] = true;
 Features["tail-call"] = true;
 Features["half-precision"] = true;
 setSIMDLevel(Features, SIMD128, true);
diff --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index 72ecc60a6e7898..5a4f85461d5aa2 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -164,7 +164,6 @@
 //
 // GENERIC-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
-// GENERIC-INCLUDE-DAG: #define __wasm_reference_types__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_sign_ext__ 1{{$}}
 //
 // RUN: %clang -E -dM %s -o - 2>&1 \
@@ -181,6 +180,7 @@
 // GENERIC-NOT: #define __wasm_half_precision__ 1{{$}}
 // GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT: #define __wasm_nontrapping_fptoint__ 1{{$}}
+// GENERIC-NOT: #define __wasm_reference_types__ 1{{$}}
 // GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
 // GENERIC-NOT: #define __wasm_simd128__ 1{{$}}
 // GENERIC-NOT: #define __wasm_tail_call__ 1{{$}}

``




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


[clang] [WebAssembly] Disable reference types in generic CPU (PR #90792)

2024-05-01 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin created 
https://github.com/llvm/llvm-project/pull/90792

 #80923 newly enabled multivalue and reference-types in the generic CPU.
But enabling reference-types ended up breaking up Wasm's Chromium CI 
(https://chromium-review.googlesource.com/c/emscripten-releases/+/5500231) 
because the way the table index is encoded different from MVP (u32) vs. 
reference-types (LEB), which caused different encodings for `call_indirect`.

And Chromium CI's and Emscripten's minimum required node version is v16, which 
does not yet support reference-types, which does not recognize that table index 
encoding. reference-types is first supported in node v17.2.

We knew the current minimum required node for Emscripten (v16) did not support 
reference-types, but thought it was fine because unless you explicitly use 
`__funcref` or `__externref` things would be fine, and if you want to use them 
explicitly, you would have a newer node. But it turned out it also affected the 
encoding of `call_indirect`.

While we are discussing the potential solutions, I will disable reference-types 
to unblock the rolls.

>From b96e36be110517740b39b9ae305edc0bbc595260 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Wed, 1 May 2024 22:49:22 +
Subject: [PATCH] [WebAssembly] Disable reference types in generic CPU

 #80923 newly enabled multivalue and reference-types in the generic CPU.
But enabling reference-types ended up breaking up Wasm's Chromium CI
(https://chromium-review.googlesource.com/c/emscripten-releases/+/5500231)
because the way the table index is encoded different from MVP (u32) vs.
reference-types (LEB), which caused different encodings for
`call_indirect`.

And Chromium CI's and Emscripten's minimum required node version is v16,
which does not yet support reference-types, which does not recognize
that table index encoding. reference-types is first supported in node
v17.2.

We knew the current minimum required node for Emscripten (v16) did not
support reference-types, but thought it was fine because unless you
explicitly use `__funcref` or `__externref` things would be fine, and if
you want to use them explicitly, you would have a newer node. But it
turned out it also affected the encoding of `call_indirect`.

While we are discussing the potential solutions, I will disable
reference-types to unblock the rolls.
---
 clang/docs/ReleaseNotes.rst| 8 
 clang/lib/Basic/Targets/WebAssembly.cpp| 2 +-
 clang/test/Preprocessor/wasm-target-features.c | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2c5308fbcb319a..0e3f7cf89ca885 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -742,10 +742,10 @@ AIX Support
 WebAssembly Support
 ^^^
 
-The -mcpu=generic configuration now enables multivalue and 
reference-types.These
-proposals are standardized and available in all major engines. Enabling
-multivalue here only enables the language feature but does not turn on the
-multivalue ABI (this enables non-ABI uses of multivalue, like exnref).
+The -mcpu=generic configuration now enables multivalue feature, which is
+standardized and available in all major engines. Enabling multivalue here only
+enables the language feature but does not turn on the multivalue ABI (this
+enables non-ABI uses of multivalue, like exnref).
 
 AVR Support
 ^^^
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 1f0418b21c1f86..a6d820e108088f 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -153,7 +153,6 @@ bool WebAssemblyTargetInfo::initFeatureMap(
   auto addGenericFeatures = [&]() {
 Features["multivalue"] = true;
 Features["mutable-globals"] = true;
-Features["reference-types"] = true;
 Features["sign-ext"] = true;
   };
   auto addBleedingEdgeFeatures = [&]() {
@@ -162,6 +161,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
 Features["bulk-memory"] = true;
 Features["multimemory"] = true;
 Features["nontrapping-fptoint"] = true;
+Features["reference-types"] = true;
 Features["tail-call"] = true;
 Features["half-precision"] = true;
 setSIMDLevel(Features, SIMD128, true);
diff --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index 72ecc60a6e7898..5a4f85461d5aa2 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -164,7 +164,6 @@
 //
 // GENERIC-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
-// GENERIC-INCLUDE-DAG: #define __wasm_reference_types__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_sign_ext__ 1{{$}}
 //
 // RUN: %clang -E -dM %s -o - 2>&1 \
@@ -181,6 +180,7 @@
 // GENERIC-NOT: #define __wasm_half_precision__ 1{{$}}
 // 

[clang] [llvm] Implement resource binding type prefix mismatch errors (PR #87578)

2024-05-01 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/87578

>From 3960050439964fe3c0536696490b284a6c470cd1 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 3 Apr 2024 13:15:59 -0700
Subject: [PATCH 01/12] implement binding type error for t/cbuffers and
 rwbuffers

---
 .../clang/Basic/DiagnosticSemaKinds.td|  1 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 19 +++--
 clang/lib/Sema/SemaDeclAttr.cpp   | 73 ++-
 .../resource_binding_attr_error_mismatch.hlsl | 65 +
 4 files changed, 149 insertions(+), 9 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 51af81bf1f6fc5..9a0946276f80fb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12149,6 +12149,7 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
+def err_hlsl_mismatching_register_type_and_name: Error<"invalid register name 
prefix '%0' for register type '%1' (expected '%2')">;
 def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 1a1febf7a35241..479689ec82dcee 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -119,8 +119,10 @@ struct BuiltinTypeDeclBuilder {
 ResourceKind RK, bool IsROV) {
 if (Record->isCompleteDefinition())
   return *this;
-Record->addAttr(HLSLResourceAttr::CreateImplicit(Record->getASTContext(),
- RC, RK, IsROV));
+HLSLResourceAttr *attr = HLSLResourceAttr::CreateImplicit(
+Record->getASTContext(), RC, RK, IsROV);
+
+Record->addAttr(attr);
 return *this;
   }
 
@@ -482,15 +484,18 @@ static BuiltinTypeDeclBuilder 
setupBufferType(CXXRecordDecl *Decl, Sema ,
   bool IsROV) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
-  Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
- .addSimpleTemplateParams({"element_type"})
- .Record;
+  Decl =
+  BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
+  .addSimpleTemplateParams({"element_type"})
+  .annotateResourceClass(ResourceClass::UAV, ResourceKind::TypedBuffer,
+ /*IsROV=*/false)
+  .Record;
+
   onCompletion(Decl, [this](CXXRecordDecl *Decl) {
 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
 ResourceKind::TypedBuffer, /*IsROV=*/false)
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index f25f3afd0f4af2..e720fe56c3ea17 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7333,12 +7333,12 @@ static void handleHLSLResourceBindingAttr(Sema , Decl 
*D,
   } else {
 Slot = Str;
   }
-
+  QualType Ty = ((clang::ValueDecl *)D)->getType();
   // Validate.
   if (!Slot.empty()) {
 switch (Slot[0]) {
-case 'u':
 case 'b':
+case 'u':
 case 's':
 case 't':
   break;
@@ -7367,6 +7367,75 @@ static void handleHLSLResourceBindingAttr(Sema , Decl 
*D,
 return;
   }
 
+  VarDecl *VD = dyn_cast(D);
+  HLSLBufferDecl *BD = dyn_cast(D);
+
+  if (VD || BD) {
+llvm::hlsl::ResourceClass RC;
+std::string varTy = "";
+if (VD) {
+
+  const Type *Ty = VD->getType()->getPointeeOrArrayElementType();
+  if (!Ty)
+return;
+  QualType t = ((ElaboratedType *)Ty)->getNamedType();
+  const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
+  if (!RD)
+return;
+
+  if (auto TDecl = dyn_cast(RD))
+RD = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+  RD = RD->getCanonicalDecl();
+  const auto *Attr = RD->getAttr();
+  if (!Attr)
+return;
+
+  RC = Attr->getResourceClass();
+  varTy = RD->getNameAsString();
+} else {
+  if (BD->isCBuffer()) {
+RC = llvm::hlsl::ResourceClass::CBuffer;
+varTy = "cbuffer";
+  } else {
+RC = llvm::hlsl::ResourceClass::CBuffer;
+

[clang] [clang][SPARC] Treat empty structs as if it's a one-bit type in the CC (PR #90338)

2024-05-01 Thread via cfe-commits


@@ -263,7 +263,10 @@ SparcV9ABIInfo::classifyType(QualType Ty, unsigned 
SizeLimit) const {
 
   CoerceBuilder CB(getVMContext(), getDataLayout());
   CB.addStruct(0, StrTy);
-  CB.pad(llvm::alignTo(CB.DL.getTypeSizeInBits(StrTy), 64));
+  // All structs, even empty ones, should take up a register argument slot,
+  // so pin the minimum struct size to one bit.
+  CB.pad(llvm::alignTo(
+  std::max(CB.DL.getTypeSizeInBits(StrTy).getKnownMinValue(), 1UL), 64));

koachan wrote:

Using `getInt64Ty` like that results in LLVM throwing these errors, it seems:
```
Function return type does not match operand type of return inst!
```

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


[clang] [llvm] [AMDGPU] Extend __builtin_amdgcn_sched_group_barrier to support rules. (PR #85304)

2024-05-01 Thread Jeffrey Byrnes via cfe-commits


@@ -437,16 +437,18 @@ void test_sched_group_barrier()
 }
 
 // CHECK-LABEL: @test_sched_group_barrier_rule
-// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 0, i32 1, i32 2, 
i32 0)
-// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 1, i32 2, i32 4, 
i32 0)
-// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 4, i32 8, i32 
16, i32 100)
-// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 15, i32 1, 
i32 -1, i32 -100)
+// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 0, i32 1, i32 2, 
i64 1)
+// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 1, i32 2, i32 4, 
i64 1)
+// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 1, i32 2, i32 4, 
i64 -9223372036854775808)
+// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 2, i32 4, i32 6, 
i64 255)
+// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 2, i32 4, i32 6, 
i64 1)
 void test_sched_group_barrier_rule()
 {
   __builtin_amdgcn_sched_group_barrier(0, 1, 2, 0);
   __builtin_amdgcn_sched_group_barrier(1, 2, 4, 0);
-  __builtin_amdgcn_sched_group_barrier(4, 8, 16, 100);
-  __builtin_amdgcn_sched_group_barrier(15, 1, -1, -100);
+  __builtin_amdgcn_sched_group_barrier(1, 2, 4, 63);
+  __builtin_amdgcn_sched_group_barrier(2, 4, 6, 0, 1, 2, 3, 4, 5, 6, 7);

jrbyrnes wrote:

Do you prefer having the latest iteration wherein users provide a mask instead 
of the variadic ? 

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


[clang] [llvm] [AMDGPU] Extend __builtin_amdgcn_sched_group_barrier to support rules. (PR #85304)

2024-05-01 Thread Jeffrey Byrnes via cfe-commits

https://github.com/jrbyrnes updated 
https://github.com/llvm/llvm-project/pull/85304

>From 04dc59ff7757dea18e2202d1cbff1d675885fdae Mon Sep 17 00:00:00 2001
From: Jeffrey Byrnes 
Date: Tue, 12 Mar 2024 10:22:24 -0700
Subject: [PATCH 1/4] [AMDGPU] Extend __builtin_amdgcn_sched_group_barrier to
 support rules.

Change-Id: Id8460dc42f41575760793c0fc70e0bc0aecc0d5e
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   2 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |  17 +++
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  14 +++
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |  15 ++-
 llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp | 112 --
 llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp  |  14 +++
 llvm/lib/Target/AMDGPU/SIInstructions.td  |  16 +++
 llvm/lib/Target/AMDGPU/SIPostRABundler.cpp|   3 +-
 .../AMDGPU/llvm.amdgcn.sched.group.barrier.ll |  25 
 9 files changed, 202 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 61ec8b79bf054d..f7b6a4610bd80a 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -63,7 +63,7 @@ BUILTIN(__builtin_amdgcn_s_sendmsghalt, "vIiUi", "n")
 BUILTIN(__builtin_amdgcn_s_barrier, "v", "n")
 BUILTIN(__builtin_amdgcn_wave_barrier, "v", "n")
 BUILTIN(__builtin_amdgcn_sched_barrier, "vIi", "n")
-BUILTIN(__builtin_amdgcn_sched_group_barrier, "vIiIiIi", "n")
+BUILTIN(__builtin_amdgcn_sched_group_barrier, "vIiIiIi.", "n")
 BUILTIN(__builtin_amdgcn_iglp_opt, "vIi", "n")
 BUILTIN(__builtin_amdgcn_s_dcache_inv, "v", "n")
 BUILTIN(__builtin_amdgcn_buffer_wbinvl1, "v", "n")
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 528a13fb275124..4bf71c7535db63 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18761,6 +18761,23 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_grid_size_z:
 return EmitAMDGPUGridSize(*this, 2);
 
+  // scheduling builtins
+  case AMDGPU::BI__builtin_amdgcn_sched_group_barrier: {
+return E->getNumArgs() == 3
+   ? Builder.CreateCall(
+ CGM.getIntrinsic(Intrinsic::amdgcn_sched_group_barrier),
+ {EmitScalarExpr(E->getArg(0)),
+  EmitScalarExpr(E->getArg(1)),
+  EmitScalarExpr(E->getArg(2))})
+   : Builder.CreateCall(
+ CGM.getIntrinsic(
+ Intrinsic::amdgcn_sched_group_barrier_rule),
+ {EmitScalarExpr(E->getArg(0)),
+  EmitScalarExpr(E->getArg(1)),
+  EmitScalarExpr(E->getArg(2)),
+  EmitScalarExpr(E->getArg(3))});
+  }
+
   // r600 intrinsics
   case AMDGPU::BI__builtin_r600_recipsqrt_ieee:
   case AMDGPU::BI__builtin_r600_recipsqrt_ieeef:
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
index 8a4533633706b2..e28e0a6987484b 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -436,6 +436,20 @@ void test_sched_group_barrier()
   __builtin_amdgcn_sched_group_barrier(15, 1, -1);
 }
 
+// CHECK-LABEL: @test_sched_group_barrier_rule
+// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 0, i32 1, i32 2, 
i32 0)
+// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 1, i32 2, i32 4, 
i32 0)
+// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 4, i32 8, i32 
16, i32 100)
+// CHECK: call void @llvm.amdgcn.sched.group.barrier.rule(i32 15, i32 1, 
i32 -1, i32 -100)
+void test_sched_group_barrier_rule()
+{
+  __builtin_amdgcn_sched_group_barrier(0, 1, 2, 0);
+  __builtin_amdgcn_sched_group_barrier(1, 2, 4, 0);
+  __builtin_amdgcn_sched_group_barrier(4, 8, 16, 100);
+  __builtin_amdgcn_sched_group_barrier(15, 1, -1, -100);
+}
+
+
 // CHECK-LABEL: @test_iglp_opt
 // CHECK: call void @llvm.amdgcn.iglp.opt(i32 0)
 // CHECK: call void @llvm.amdgcn.iglp.opt(i32 1)
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td 
b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 051e603c0819d2..68fe42a8f04d21 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -297,10 +297,17 @@ def int_amdgcn_sched_barrier : 
ClangBuiltin<"__builtin_amdgcn_sched_barrier">,
 // matching instructions that will be associated with this sched_group_barrier.
 // The third parameter is an identifier which is used to describe what other
 // sched_group_barriers should be synchronized with.
-def int_amdgcn_sched_group_barrier : 
ClangBuiltin<"__builtin_amdgcn_sched_group_barrier">,
-  Intrinsic<[], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
-  [ImmArg>, ImmArg>, ImmArg>, IntrNoMem, 
IntrHasSideEffects,
-   IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
+multiclass 

[clang] [alpha.webkit.UncountedCallArgsChecker] Ignore methods of WTF String classes. (PR #90704)

2024-05-01 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

> LGTM! The revert was caused entirely by something in the mock headers in 
> tests right?

Yeah, there were some typos in mock-types. Not sure why checks didn't catch it.

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Ignore methods of WTF String classes. (PR #90704)

2024-05-01 Thread Artem Dergachev via cfe-commits

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

LGTM! The revert was caused entirely by something in the mock headers in tests 
right?

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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-05-01 Thread Yeoul Na via cfe-commits

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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-05-01 Thread Dan Liew via cfe-commits

delcypher wrote:

@rapidsna You may want to close this PR but I'll leave this up to you.

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


[clang] [HLSL] Support packoffset attribute in AST (PR #89836)

2024-05-01 Thread Chris B via cfe-commits

https://github.com/llvm-beanz requested changes to this pull request.

I'm marking this as requesting changes because I don't think we should land 
this as-is.

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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-05-01 Thread Dan Liew via cfe-commits

delcypher wrote:

@rapidsna I've put my version of this PR in my own pull request because when I 
edit the PR summary here it looks like you wrote it which is weird: 
https://github.com/llvm/llvm-project/pull/90786

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


[clang] [HLSL] Support packoffset attribute in AST (PR #89836)

2024-05-01 Thread Chris B via cfe-commits


@@ -108,3 +108,18 @@ behavior between Clang and DXC. Some examples include:
   diagnostic notifying the user of the conversion rather than silently altering
   precision relative to the other overloads (as FXC does) or generating code
   that will fail validation (as DXC does).
+
+Mix packoffset and non-packoffset
+=
+
+DXC allows mixing packoffset and non-packoffset elements in the same cbuffer,
+accompanied by a warning.
+
+However, both Clang and FXC do not permit this and instead report an error.

llvm-beanz wrote:

I worry about this. I thought we had discussed this and DXC did something sane 
and reasonable so we could do the same in Clang. Is there some detail I'm 
missing as to why we can't match DXC.

(cc @tex3d)

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


[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Dan Liew (delcypher)


Changes

Previously the attribute was only allowed on flexible array members. This patch 
patch changes this to also allow the attribute on pointer fields in structs and 
also allows late parsing of the attribute in some contexts.

For example this previously wasn't allowed:

```
struct BufferTypeDeclAttributePosition {
  size_t count;
  char* buffer __counted_by(count); // Now allowed
}
```

Note the attribute is prevented on pointee types where the size isn't known at 
compile time. In particular pointee types that are:

* Incomplete (e.g. `void`) and sizeless types
* Function types (e.g. the pointee of a function pointer)
* Struct types with a flexible array member

This patch also introduces late parsing of the attribute when used in the 
declaration attribute position. For example

```
struct BufferTypeDeclAttributePosition {
  char* buffer __counted_by(count); // Now allowed
  size_t count;
}
```

is now allowed but **only** when passing
`-fexperimental-late-parse-attributes`.  The motivation for using late parsing 
here is to avoid breaking the data layout of structs in existing code that want 
to use the `counted_by` attribute. This patch is the first use of 
`LateAttrParseExperimentalExt` in `Attr.td` that was introduced in a previous 
patch.

Note by allowing the attribute on struct member pointers this now allows the 
possiblity of writing the attribute in the type attribute position. For example:

```
struct BufferTypeAttributePosition {
  size_t count;
  char *__counted_by(count) buffer; // Now allowed
}
```

However, the attribute in this position is still currently parsed immediately 
rather than late parsed. So this will not parse currently:

```
struct BufferTypeAttributePosition {
  char *__counted_by(count) buffer; // Fails to parse
  size_t count;
}
```

The intention is to lift this restriction in future patches. It has not been 
done in this patch to keep this size of this commit small.

There are also several other follow up changes that will need to be addressed 
in future patches:

* Make late parsing working with anonymous structs (see `on_pointer_anon_buf` 
in `attr-counted-by-late-parsed-struct-ptrs.c`).
* Allow `counted_by` on more subjects (e.g. parameters, returns types) when 
`-fbounds-safety` is enabled.
* Make use of the attribute on pointer types in code gen (e.g. for 
`_builtin_dynamic_object_size` and UBSan's array-bounds checks).

This work is heavily based on a patch originally written by Yeoul Na.

rdar://125400257

---

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


18 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+18-1) 
- (modified) clang/include/clang/AST/Type.h (+1) 
- (modified) clang/include/clang/Basic/Attr.td (+2-1) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+13-2) 
- (modified) clang/include/clang/Parse/Parser.h (+6-1) 
- (modified) clang/include/clang/Sema/Sema.h (+2-1) 
- (modified) clang/lib/AST/Type.cpp (+12) 
- (modified) clang/lib/Parse/ParseDecl.cpp (+97-7) 
- (modified) clang/lib/Parse/ParseObjc.cpp (+6-4) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+56-15) 
- (modified) clang/lib/Sema/SemaType.cpp (+3-3) 
- (modified) clang/lib/Sema/TreeTransform.h (+1-1) 
- (added) clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c (+45) 
- (added) clang/test/Sema/attr-counted-by-late-parsed-off.c (+26) 
- (added) clang/test/Sema/attr-counted-by-late-parsed-struct-ptrs.c (+185) 
- (added) clang/test/Sema/attr-counted-by-struct-ptrs-sizeless-types.c (+17) 
- (added) clang/test/Sema/attr-counted-by-struct-ptrs.c (+163) 
- (modified) clang/test/Sema/attr-counted-by.c (+3-2) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c0fe5bcf6b122..81d0a89b294878 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -258,7 +258,8 @@ New Compiler Flags
 
 - ``-fexperimental-late-parse-attributes`` enables an experimental feature to
   allow late parsing certain attributes in specific contexts where they would
-  not normally be late parsed.
+  not normally be late parsed. Currently this allows late parsing the
+  `counted_by` attribute in C. See `Attribute Changes in Clang`_.
 
 Deprecated Compiler Flags
 -
@@ -335,6 +336,22 @@ Attribute Changes in Clang
 - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
   is ignored when applied to a local class or a member thereof.
 
+- The ``counted_by`` attribute can now be late parsed in C when
+  ``-fexperimental-late-parse-attributes`` is passed but only when attribute is
+  used in the declaration attribute position. This allows using the
+  attribute on existing code where it previously impossible to do so without
+  re-ordering struct field declarations would break ABI as shown below.
+
+  .. code-block:: c
+
+ struct 

[clang] [BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C (PR #90786)

2024-05-01 Thread Dan Liew via cfe-commits

https://github.com/delcypher created 
https://github.com/llvm/llvm-project/pull/90786

Previously the attribute was only allowed on flexible array members. This patch 
patch changes this to also allow the attribute on pointer fields in structs and 
also allows late parsing of the attribute in some contexts.

For example this previously wasn't allowed:

```
struct BufferTypeDeclAttributePosition {
  size_t count;
  char* buffer __counted_by(count); // Now allowed
}
```

Note the attribute is prevented on pointee types where the size isn't known at 
compile time. In particular pointee types that are:

* Incomplete (e.g. `void`) and sizeless types
* Function types (e.g. the pointee of a function pointer)
* Struct types with a flexible array member

This patch also introduces late parsing of the attribute when used in the 
declaration attribute position. For example

```
struct BufferTypeDeclAttributePosition {
  char* buffer __counted_by(count); // Now allowed
  size_t count;
}
```

is now allowed but **only** when passing
`-fexperimental-late-parse-attributes`.  The motivation for using late parsing 
here is to avoid breaking the data layout of structs in existing code that want 
to use the `counted_by` attribute. This patch is the first use of 
`LateAttrParseExperimentalExt` in `Attr.td` that was introduced in a previous 
patch.

Note by allowing the attribute on struct member pointers this now allows the 
possiblity of writing the attribute in the type attribute position. For example:

```
struct BufferTypeAttributePosition {
  size_t count;
  char *__counted_by(count) buffer; // Now allowed
}
```

However, the attribute in this position is still currently parsed immediately 
rather than late parsed. So this will not parse currently:

```
struct BufferTypeAttributePosition {
  char *__counted_by(count) buffer; // Fails to parse
  size_t count;
}
```

The intention is to lift this restriction in future patches. It has not been 
done in this patch to keep this size of this commit small.

There are also several other follow up changes that will need to be addressed 
in future patches:

* Make late parsing working with anonymous structs (see `on_pointer_anon_buf` 
in `attr-counted-by-late-parsed-struct-ptrs.c`).
* Allow `counted_by` on more subjects (e.g. parameters, returns types) when 
`-fbounds-safety` is enabled.
* Make use of the attribute on pointer types in code gen (e.g. for 
`_builtin_dynamic_object_size` and UBSan's array-bounds checks).

This work is heavily based on a patch originally written by Yeoul Na.

rdar://125400257

>From a89cca7fecae5ef5130cd9c8da834a186e99dbb5 Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Wed, 1 May 2024 13:56:52 -0700
Subject: [PATCH] [BoundsSafety] Allow 'counted_by' attribute on pointers in
 structs in C

Previously the attribute was only allowed on flexible array members.
This patch patch changes this to also allow the attribute on pointer
fields in structs and also allows late parsing of the attribute in some
contexts.

For example this previously wasn't allowed:

```
struct BufferTypeDeclAttributePosition {
  size_t count;
  char* buffer __counted_by(count); // Now allowed
}
```

Note the attribute is prevented on pointee types where the size isn't
known at compile time. In particular pointee types that are:

* Incomplete (e.g. `void`) and sizeless types
* Function types (e.g. the pointee of a function pointer)
* Struct types with a flexible array member

This patch also introduces late parsing of the attribute when used
in the declaration attribute position. For example

```
struct BufferTypeDeclAttributePosition {
  char* buffer __counted_by(count); // Now allowed
  size_t count;
}
```

is now allowed but **only** when passing
`-fexperimental-late-parse-attributes`.  The motivation for using late
parsing here is to avoid breaking the data layout of structs in existing
code that want to use the `counted_by` attribute. This patch is the
first use of `LateAttrParseExperimentalExt` in `Attr.td` that was
introduced in a previous patch.

Note by allowing the attribute on struct member pointers this now allows
the possiblity of writing the attribute in the type attribute position.
For example:

```
struct BufferTypeAttributePosition {
  size_t count;
  char *__counted_by(count) buffer; // Now allowed
}
```

However, the attribute in this position is still currently parsed
immediately rather than late parsed. So this will not parse currently:

```
struct BufferTypeAttributePosition {
  char *__counted_by(count) buffer; // Fails to parse
  size_t count;
}
```

The intention is to lift this restriction in future patches. It has not
been done in this patch to keep this size of this commit small.

There are also several other follow up changes that will need to be
addressed in future patches:

* Make late parsing working with anonymous structs (see
  `on_pointer_anon_buf` in `attr-counted-by-late-parsed-struct-ptrs.c`).
* Allow `counted_by` on more subjedts (e.g. 

[clang] [HLSL] Support packoffset attribute in AST (PR #89836)

2024-05-01 Thread Chris B via cfe-commits


@@ -4372,6 +4372,13 @@ def HLSLResourceBinding: InheritableAttr {
   let Documentation = [HLSLResourceBindingDocs];
 }
 
+def HLSLPackOffset: HLSLAnnotationAttr {
+  let Spellings = [HLSLAnnotation<"packoffset">];
+  let LangOpts = [HLSL];
+  let Args = [IntArgument<"Offset">];

llvm-beanz wrote:

I think it is fine to keep these as integers.

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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-05-01 Thread Dan Liew via cfe-commits

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


[clang] [compiler-rt] [asan][windows] Eliminate the static asan runtime on windows (PR #81677)

2024-05-01 Thread Charlie Barto via cfe-commits


@@ -35,6 +35,9 @@
 // RUN:  %p/../../../../lib/sanitizer_common/sanitizer_coverage_interface.inc  
   \
 // RUN:  | grep -e "INTERFACE_\(WEAK_\)\?FUNCTION" 
   \
 // RUN:  | grep -v "__sanitizer_weak_hook" 
   \
+// RUN:  | grep -v "__sanitizer_override_function" 
   \

barcharcraz wrote:

It would cause test failures on linux/darwin. These tests grep the interface 
files for "expected" imports and do not run the preprocessor on them, so the 
new interface symbols on windows need to be excluded.

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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-05-01 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/87596

>From a89cca7fecae5ef5130cd9c8da834a186e99dbb5 Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Wed, 1 May 2024 13:56:52 -0700
Subject: [PATCH] [BoundsSafety] Allow 'counted_by' attribute on pointers in
 structs in C

Previously the attribute was only allowed on flexible array members.
This patch patch changes this to also allow the attribute on pointer
fields in structs and also allows late parsing of the attribute in some
contexts.

For example this previously wasn't allowed:

```
struct BufferTypeDeclAttributePosition {
  size_t count;
  char* buffer __counted_by(count); // Now allowed
}
```

Note the attribute is prevented on pointee types where the size isn't
known at compile time. In particular pointee types that are:

* Incomplete (e.g. `void`) and sizeless types
* Function types (e.g. the pointee of a function pointer)
* Struct types with a flexible array member

This patch also introduces late parsing of the attribute when used
in the declaration attribute position. For example

```
struct BufferTypeDeclAttributePosition {
  char* buffer __counted_by(count); // Now allowed
  size_t count;
}
```

is now allowed but **only** when passing
`-fexperimental-late-parse-attributes`.  The motivation for using late
parsing here is to avoid breaking the data layout of structs in existing
code that want to use the `counted_by` attribute. This patch is the
first use of `LateAttrParseExperimentalExt` in `Attr.td` that was
introduced in a previous patch.

Note by allowing the attribute on struct member pointers this now allows
the possiblity of writing the attribute in the type attribute position.
For example:

```
struct BufferTypeAttributePosition {
  size_t count;
  char *__counted_by(count) buffer; // Now allowed
}
```

However, the attribute in this position is still currently parsed
immediately rather than late parsed. So this will not parse currently:

```
struct BufferTypeAttributePosition {
  char *__counted_by(count) buffer; // Fails to parse
  size_t count;
}
```

The intention is to lift this restriction in future patches. It has not
been done in this patch to keep this size of this commit small.

There are also several other follow up changes that will need to be
addressed in future patches:

* Make late parsing working with anonymous structs (see
  `on_pointer_anon_buf` in `attr-counted-by-late-parsed-struct-ptrs.c`).
* Allow `counted_by` on more subjedts (e.g. parameters, returns types)
  when `-fbounds-safety` is enabled.
* Make use of the attribute on pointer types in code gen (e.g.
for `_builtin_dynamic_object_size` and UBSan's array-bounds checks).

This work is heavily based on a patch originally written by Yeoul Na.

rdar://125400257
---
 clang/docs/ReleaseNotes.rst   |  19 +-
 clang/include/clang/AST/Type.h|   1 +
 clang/include/clang/Basic/Attr.td |   3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  15 +-
 clang/include/clang/Parse/Parser.h|   7 +-
 clang/include/clang/Sema/Sema.h   |   3 +-
 clang/lib/AST/Type.cpp|  12 ++
 clang/lib/Parse/ParseDecl.cpp | 104 +-
 clang/lib/Parse/ParseObjc.cpp |  10 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  71 +--
 clang/lib/Sema/SemaType.cpp   |   6 +-
 clang/lib/Sema/TreeTransform.h|   2 +-
 .../attr-counted-by-late-parsed-struct-ptrs.c |  45 +
 .../Sema/attr-counted-by-late-parsed-off.c|  26 +++
 .../attr-counted-by-late-parsed-struct-ptrs.c | 185 ++
 ...tr-counted-by-struct-ptrs-sizeless-types.c |  17 ++
 clang/test/Sema/attr-counted-by-struct-ptrs.c | 163 +++
 clang/test/Sema/attr-counted-by.c |   5 +-
 18 files changed, 656 insertions(+), 38 deletions(-)
 create mode 100644 clang/test/AST/attr-counted-by-late-parsed-struct-ptrs.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-off.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-struct-ptrs.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs-sizeless-types.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c0fe5bcf6b122..81d0a89b294878 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -258,7 +258,8 @@ New Compiler Flags
 
 - ``-fexperimental-late-parse-attributes`` enables an experimental feature to
   allow late parsing certain attributes in specific contexts where they would
-  not normally be late parsed.
+  not normally be late parsed. Currently this allows late parsing the
+  `counted_by` attribute in C. See `Attribute Changes in Clang`_.
 
 Deprecated Compiler Flags
 -
@@ -335,6 +336,22 @@ Attribute Changes in Clang
 - Clang now warns that the ``exclude_from_explicit_instantiation`` 

[clang] [llvm] [WebAssembly] Sort target features (NFC) (PR #90777)

2024-05-01 Thread Thomas Lively via cfe-commits

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


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


[clang] [Modules] Detect ODR mismatches for enums in non-C++ like in C++. (PR #90298)

2024-05-01 Thread Volodymyr Sapsai via cfe-commits

vsapsai wrote:

@dwblaikie if you have no further comments, I'll merge this approved change 
some time soon (in a day or two).

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


[clang-tools-extra] [clangd] Remove potential prefix from enum value names (PR #83412)

2024-05-01 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti commented:

When the enumerators start with the enum name, but the names contain a `_` as a 
separator, then applying this tweak will result in `_`-prefixed enumerators. 
Can you please handle that case as well and remove the `_`? Otherwise, this 
looks good to me

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


[clang] [HLSL] Support packoffset attribute in AST (PR #89836)

2024-05-01 Thread Damyan Pepper via cfe-commits

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


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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-05-01 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/87596

>From 50e628d2d6fb496c1cb2fa188b653529508e383c Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Wed, 1 May 2024 13:56:52 -0700
Subject: [PATCH] [BoundsSafety] Allow 'counted_by' attribute on pointers in
 structs in C

Previously the attribute was only allowed on flexible array members.
This patch patch changes this to also allow the attribute on pointer
fields in structs and also allows late parsing of the attribute in some
contexts.

For example this previously wasn't allowed:

```
struct BufferTypeDeclAttributePosition {
  size_t count;
  char* buffer __counted_by(count); // Now allowed
}
```

Note the attribute is prevented on pointee types where the size isn't
known at compile time. In particular pointee types that are:

* Incomplete (e.g. `void`) and sizeless types
* Function types (e.g. the pointee of a function pointer)
* Struct types with a flexible array member

This patch also introduces late parsing of the attribute when used
in the declaration attribute position. For example

```
struct BufferTypeDeclAttributePosition {
  char* buffer __counted_by(count); // Now allowed
  size_t count;
}
```

is now allowed but **only** when passing
`-fexperimental-late-parse-attributes`.  The motivation for using late
parsing here is to avoid breaking the data layout of structs in existing
code that want to use the `counted_by` attribute. This patch is the
first use of `LateAttrParseExperimentalExt` in `Attr.td` that was
introduced in a previous patch.

Note by allowing the attribute on struct member pointers this now allows
the possiblity of writing the attribute in the type attribute position.
For example:

```
struct BufferTypeAttributePosition {
  size_t count;
  char *__counted_by(count) buffer; // Now allowed
}
```

However, the attribute in this position is still currently parsed
immediately rather than late parsed. So this will not parse currently:

```
struct BufferTypeAttributePosition {
  char *__counted_by(count) buffer; // Fails to parse
  size_t count;
}
```

The intention is to lift this restriction in future patches. It has not
been done in this patch to keep this size of this commit small.

Note this patch only allows parsing of semantic analysis of the
attribute on pointers. It does not make use of this on the codegen side
(e.g. for _builtin_dynamic_object_size and UBSan's array-bounds checks).
Making use of the attribute on pointers will be handled in separate
patches.

This work is heavily based on a patch originally written by Yeoul Na.

rdar://125400257
---
 clang/docs/ReleaseNotes.rst   |  19 +-
 clang/include/clang/AST/Type.h|   1 +
 clang/include/clang/Basic/Attr.td |   3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  15 +-
 clang/include/clang/Parse/Parser.h|   7 +-
 clang/include/clang/Sema/Sema.h   |   3 +-
 clang/lib/AST/Type.cpp|  12 ++
 clang/lib/Parse/ParseDecl.cpp | 104 ++-
 clang/lib/Parse/ParseObjc.cpp |  10 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  71 ++--
 clang/lib/Sema/SemaType.cpp   |   6 +-
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/AST/attr-counted-by-late-parsed.c  |  31 
 .../Sema/attr-counted-by-late-parsed-off.c|  26 +++
 .../attr-counted-by-late-parsed-struct-ptrs.c | 169 ++
 ...tr-counted-by-struct-ptrs-sizeless-types.c |  17 ++
 clang/test/Sema/attr-counted-by-struct-ptrs.c | 163 +
 clang/test/Sema/attr-counted-by.c |   5 +-
 18 files changed, 626 insertions(+), 38 deletions(-)
 create mode 100644 clang/test/AST/attr-counted-by-late-parsed.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-off.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-struct-ptrs.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs-sizeless-types.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c0fe5bcf6b122..81d0a89b294878 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -258,7 +258,8 @@ New Compiler Flags
 
 - ``-fexperimental-late-parse-attributes`` enables an experimental feature to
   allow late parsing certain attributes in specific contexts where they would
-  not normally be late parsed.
+  not normally be late parsed. Currently this allows late parsing the
+  `counted_by` attribute in C. See `Attribute Changes in Clang`_.
 
 Deprecated Compiler Flags
 -
@@ -335,6 +336,22 @@ Attribute Changes in Clang
 - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
   is ignored when applied to a local class or a member thereof.
 
+- The ``counted_by`` attribute can now be late parsed in C when
+  ``-fexperimental-late-parse-attributes`` is passed 

[clang] [HLSL] Support packoffset attribute in AST (PR #89836)

2024-05-01 Thread Xiang Li via cfe-commits


@@ -7398,6 +7398,26 @@ The full documentation is available here: 
https://docs.microsoft.com/en-us/windo
   }];
 }
 
+def HLSLPackOffsetDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The packoffset attribute is used to change the layout of a cbuffer.
+Attribute spelling in HLSL is: ``packoffset( c[Subcomponent][.component] )``.
+A subcomponent is a register number, which is an integer. A component is in 
the form of [.xyzw].
+
+Here're packoffset examples with and without component:

python3kgae wrote:

Updated.

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


[clang] [HLSL] Support packoffset attribute in AST (PR #89836)

2024-05-01 Thread Xiang Li via cfe-commits

https://github.com/python3kgae updated 
https://github.com/llvm/llvm-project/pull/89836

>From 4d8c72688656fe3b2ce8817087d8cf7352b5876b Mon Sep 17 00:00:00 2001
From: Xiang Li 
Date: Tue, 23 Apr 2024 17:49:02 -0400
Subject: [PATCH 1/6] [HLSL] Support packoffset attribute in AST

Add HLSLPackOffsetAttr to save packoffset in AST.

Since we have to parse the attribute manually in ParseHLSLAnnotations,
we could create the ParsedAttribute with a integer offset parameter instead of 
string.
This approach avoids parsing the string if the offset is saved as a string in 
HLSLPackOffsetAttr.
---
 clang/include/clang/Basic/Attr.td |  7 ++
 clang/include/clang/Basic/AttrDocs.td | 18 +
 .../clang/Basic/DiagnosticParseKinds.td   |  2 +
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/lib/Parse/ParseHLSL.cpp | 80 +++
 clang/lib/Sema/SemaDeclAttr.cpp   | 44 ++
 clang/lib/Sema/SemaHLSL.cpp   | 48 +++
 clang/test/AST/HLSL/packoffset.hlsl   | 16 
 clang/test/SemaHLSL/packoffset-invalid.hlsl   | 55 +
 9 files changed, 273 insertions(+)
 create mode 100644 clang/test/AST/HLSL/packoffset.hlsl
 create mode 100644 clang/test/SemaHLSL/packoffset-invalid.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 4408d517e70e58..d3d006ed9633f4 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4372,6 +4372,13 @@ def HLSLResourceBinding: InheritableAttr {
   let Documentation = [HLSLResourceBindingDocs];
 }
 
+def HLSLPackOffset: HLSLAnnotationAttr {
+  let Spellings = [HLSLAnnotation<"packoffset">];
+  let LangOpts = [HLSL];
+  let Args = [IntArgument<"Offset">];
+  let Documentation = [HLSLPackOffsetDocs];
+}
+
 def HLSLSV_DispatchThreadID: HLSLAnnotationAttr {
   let Spellings = [HLSLAnnotation<"SV_DispatchThreadID">];
   let Subjects = SubjectList<[ParmVar, Field]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c5722..6bc7813bd43cb4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7398,6 +7398,24 @@ The full documentation is available here: 
https://docs.microsoft.com/en-us/windo
   }];
 }
 
+def HLSLPackOffsetDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The packoffset attribute is used to change the layout of a cbuffer.
+Attribute spelling in HLSL is: ``packoffset(c[Subcomponent[.component]])``.
+A subcomponent is a register number, which is an integer. A component is in 
the form of [.xyzw].
+
+Here're packoffset examples with and without component:
+.. code-block:: c++
+  cbuffer A {
+float3 a : packoffset(c0.y);
+float4 b : packoffset(c4);
+  }
+
+The full documentation is available here: 
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-variable-packoffset
+  }];
+}
+
 def HLSLSV_DispatchThreadIDDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 38174cf3549f14..81433ee79d48b2 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1745,5 +1745,7 @@ def err_hlsl_separate_attr_arg_and_number : Error<"wrong 
argument format for hls
 def ext_hlsl_access_specifiers : ExtWarn<
   "access specifiers are a clang HLSL extension">,
   InGroup;
+def err_hlsl_unsupported_component : Error<"invalid component '%0' used; 
expected 'x', 'y', 'z', or 'w'">;
+def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier 
'%0' for packoffset, expected 'c'">;
 
 } // end of Parser diagnostics
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 63e951daec7477..bde9617c9820a8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12167,6 +12167,9 @@ def err_hlsl_init_priority_unsupported : Error<
 def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
+def err_hlsl_packoffset_mix : Error<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">;
+def err_hlsl_packoffset_overlap : Error<"packoffset overlap between %0, %1">;
+def err_hlsl_packoffset_cross_reg_boundary : Error<"packoffset cannot cross 
register boundary">;
 def err_hlsl_pointers_unsupported : Error<
   "%select{pointers|references}0 are unsupported in HLSL">;
 
diff --git a/clang/lib/Parse/ParseHLSL.cpp 

[clang] [llvm] [WebAssembly] Sort target features (NFC) (PR #90777)

2024-05-01 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin updated 
https://github.com/llvm/llvm-project/pull/90777

>From b9fd03c2740fe924c0ea49bb78c9898412364105 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Mon, 29 Apr 2024 22:16:46 +
Subject: [PATCH 1/2] [WebAssembly] Sort target features (NFC)

---
 clang/include/clang/Driver/Options.td |  40 ++---
 clang/lib/Basic/Targets/WebAssembly.cpp   | 166 +-
 clang/lib/Basic/Targets/WebAssembly.h |  18 +-
 clang/test/Driver/wasm-features.c |  88 +-
 llvm/lib/Target/WebAssembly/WebAssembly.td|  64 +++
 .../WebAssembly/WebAssemblyInstrInfo.td   |  72 
 .../Target/WebAssembly/WebAssemblySubtarget.h |  32 ++--
 7 files changed, 241 insertions(+), 239 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 864da4e1157f7d..5b79b066d384ad 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4895,34 +4895,34 @@ def mharden_sls_EQ : Joined<["-"], "mharden-sls=">, 
Group,
" blr(ARM/AArch64), comdat(ARM/AArch64), nocomdat(ARM/AArch64),"
" return(X86), indirect-jmp(X86)">;
 
-def msimd128 : Flag<["-"], "msimd128">, Group;
-def mno_simd128 : Flag<["-"], "mno-simd128">, Group;
-def mrelaxed_simd : Flag<["-"], "mrelaxed-simd">, Group;
-def mno_relaxed_simd : Flag<["-"], "mno-relaxed-simd">, 
Group;
-def mhalf_precision : Flag<["-"], "mhalf-precision">, 
Group;
-def mno_half_precision : Flag<["-"], "mno-half-precision">, 
Group;
-def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, 
Group;
-def mno_nontrapping_fptoint : Flag<["-"], "mno-nontrapping-fptoint">, 
Group;
-def msign_ext : Flag<["-"], "msign-ext">, Group;
-def mno_sign_ext : Flag<["-"], "mno-sign-ext">, Group;
-def mexception_handing : Flag<["-"], "mexception-handling">, 
Group;
-def mno_exception_handing : Flag<["-"], "mno-exception-handling">, 
Group;
 def matomics : Flag<["-"], "matomics">, Group;
 def mno_atomics : Flag<["-"], "mno-atomics">, Group;
 def mbulk_memory : Flag<["-"], "mbulk-memory">, Group;
 def mno_bulk_memory : Flag<["-"], "mno-bulk-memory">, 
Group;
-def mmutable_globals : Flag<["-"], "mmutable-globals">, 
Group;
-def mno_mutable_globals : Flag<["-"], "mno-mutable-globals">, 
Group;
-def mmultivalue : Flag<["-"], "mmultivalue">, Group;
-def mno_multivalue : Flag<["-"], "mno-multivalue">, 
Group;
-def mtail_call : Flag<["-"], "mtail-call">, Group;
-def mno_tail_call : Flag<["-"], "mno-tail-call">, Group;
-def mreference_types : Flag<["-"], "mreference-types">, 
Group;
-def mno_reference_types : Flag<["-"], "mno-reference-types">, 
Group;
+def mexception_handing : Flag<["-"], "mexception-handling">, 
Group;
+def mno_exception_handing : Flag<["-"], "mno-exception-handling">, 
Group;
 def mextended_const : Flag<["-"], "mextended-const">, 
Group;
 def mno_extended_const : Flag<["-"], "mno-extended-const">, 
Group;
+def mhalf_precision : Flag<["-"], "mhalf-precision">, 
Group;
+def mno_half_precision : Flag<["-"], "mno-half-precision">, 
Group;
 def mmultimemory : Flag<["-"], "mmultimemory">, Group;
 def mno_multimemory : Flag<["-"], "mno-multimemory">, 
Group;
+def mmultivalue : Flag<["-"], "mmultivalue">, Group;
+def mno_multivalue : Flag<["-"], "mno-multivalue">, 
Group;
+def mmutable_globals : Flag<["-"], "mmutable-globals">, 
Group;
+def mno_mutable_globals : Flag<["-"], "mno-mutable-globals">, 
Group;
+def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, 
Group;
+def mno_nontrapping_fptoint : Flag<["-"], "mno-nontrapping-fptoint">, 
Group;
+def mreference_types : Flag<["-"], "mreference-types">, 
Group;
+def mno_reference_types : Flag<["-"], "mno-reference-types">, 
Group;
+def mrelaxed_simd : Flag<["-"], "mrelaxed-simd">, Group;
+def mno_relaxed_simd : Flag<["-"], "mno-relaxed-simd">, 
Group;
+def msign_ext : Flag<["-"], "msign-ext">, Group;
+def mno_sign_ext : Flag<["-"], "mno-sign-ext">, Group;
+def msimd128 : Flag<["-"], "msimd128">, Group;
+def mno_simd128 : Flag<["-"], "mno-simd128">, Group;
+def mtail_call : Flag<["-"], "mtail-call">, Group;
+def mno_tail_call : Flag<["-"], "mno-tail-call">, Group;
 def mexec_model_EQ : Joined<["-"], "mexec-model=">, 
Group,
  Values<"command,reactor">,
  HelpText<"Execution model (WebAssembly only)">,
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 1f0418b21c1f86..a363478680570c 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -45,20 +45,20 @@ bool WebAssemblyTargetInfo::setABI(const std::string ) 
{
 
 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
   return llvm::StringSwitch(Feature)
-  .Case("simd128", SIMDLevel >= SIMD128)
-  .Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
+  .Case("atomics", HasAtomics)
+  .Case("bulk-memory", HasBulkMemory)
+  

[clang] [llvm] [WebAssembly] Sort target features (NFC) (PR #90777)

2024-05-01 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 a1c12794226ffde0a84c96b9188a266eafd85fb3 
b9fd03c2740fe924c0ea49bb78c9898412364105 -- 
clang/lib/Basic/Targets/WebAssembly.cpp clang/lib/Basic/Targets/WebAssembly.h 
clang/test/Driver/wasm-features.c 
llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index a363478680..b9c1f3c0f0 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -88,7 +88,7 @@ void WebAssemblyTargetInfo::getTargetDefines(const 
LangOptions ,
 Builder.defineMacro("__wasm_half_precision__");
   if (HasMultivalue)
 Builder.defineMacro("__wasm_multivalue__");
- if (HasMutableGlobals)
+  if (HasMutableGlobals)
 Builder.defineMacro("__wasm_mutable_globals__");
   if (HasNontrappingFPToInt)
 Builder.defineMacro("__wasm_nontrapping_fptoint__");

``




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


[clang] [llvm] [WebAssembly] Sort target features (NFC) (PR #90777)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-webassembly

Author: Heejin Ahn (aheejin)


Changes



---

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


7 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+20-20) 
- (modified) clang/lib/Basic/Targets/WebAssembly.cpp (+83-83) 
- (modified) clang/lib/Basic/Targets/WebAssembly.h (+9-9) 
- (modified) clang/test/Driver/wasm-features.c (+44-44) 
- (modified) llvm/lib/Target/WebAssembly/WebAssembly.td (+32-32) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td (+37-35) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h (+16-16) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 864da4e1157f7d..5b79b066d384ad 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4895,34 +4895,34 @@ def mharden_sls_EQ : Joined<["-"], "mharden-sls=">, 
Group,
" blr(ARM/AArch64), comdat(ARM/AArch64), nocomdat(ARM/AArch64),"
" return(X86), indirect-jmp(X86)">;
 
-def msimd128 : Flag<["-"], "msimd128">, Group;
-def mno_simd128 : Flag<["-"], "mno-simd128">, Group;
-def mrelaxed_simd : Flag<["-"], "mrelaxed-simd">, Group;
-def mno_relaxed_simd : Flag<["-"], "mno-relaxed-simd">, 
Group;
-def mhalf_precision : Flag<["-"], "mhalf-precision">, 
Group;
-def mno_half_precision : Flag<["-"], "mno-half-precision">, 
Group;
-def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, 
Group;
-def mno_nontrapping_fptoint : Flag<["-"], "mno-nontrapping-fptoint">, 
Group;
-def msign_ext : Flag<["-"], "msign-ext">, Group;
-def mno_sign_ext : Flag<["-"], "mno-sign-ext">, Group;
-def mexception_handing : Flag<["-"], "mexception-handling">, 
Group;
-def mno_exception_handing : Flag<["-"], "mno-exception-handling">, 
Group;
 def matomics : Flag<["-"], "matomics">, Group;
 def mno_atomics : Flag<["-"], "mno-atomics">, Group;
 def mbulk_memory : Flag<["-"], "mbulk-memory">, Group;
 def mno_bulk_memory : Flag<["-"], "mno-bulk-memory">, 
Group;
-def mmutable_globals : Flag<["-"], "mmutable-globals">, 
Group;
-def mno_mutable_globals : Flag<["-"], "mno-mutable-globals">, 
Group;
-def mmultivalue : Flag<["-"], "mmultivalue">, Group;
-def mno_multivalue : Flag<["-"], "mno-multivalue">, 
Group;
-def mtail_call : Flag<["-"], "mtail-call">, Group;
-def mno_tail_call : Flag<["-"], "mno-tail-call">, Group;
-def mreference_types : Flag<["-"], "mreference-types">, 
Group;
-def mno_reference_types : Flag<["-"], "mno-reference-types">, 
Group;
+def mexception_handing : Flag<["-"], "mexception-handling">, 
Group;
+def mno_exception_handing : Flag<["-"], "mno-exception-handling">, 
Group;
 def mextended_const : Flag<["-"], "mextended-const">, 
Group;
 def mno_extended_const : Flag<["-"], "mno-extended-const">, 
Group;
+def mhalf_precision : Flag<["-"], "mhalf-precision">, 
Group;
+def mno_half_precision : Flag<["-"], "mno-half-precision">, 
Group;
 def mmultimemory : Flag<["-"], "mmultimemory">, Group;
 def mno_multimemory : Flag<["-"], "mno-multimemory">, 
Group;
+def mmultivalue : Flag<["-"], "mmultivalue">, Group;
+def mno_multivalue : Flag<["-"], "mno-multivalue">, 
Group;
+def mmutable_globals : Flag<["-"], "mmutable-globals">, 
Group;
+def mno_mutable_globals : Flag<["-"], "mno-mutable-globals">, 
Group;
+def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, 
Group;
+def mno_nontrapping_fptoint : Flag<["-"], "mno-nontrapping-fptoint">, 
Group;
+def mreference_types : Flag<["-"], "mreference-types">, 
Group;
+def mno_reference_types : Flag<["-"], "mno-reference-types">, 
Group;
+def mrelaxed_simd : Flag<["-"], "mrelaxed-simd">, Group;
+def mno_relaxed_simd : Flag<["-"], "mno-relaxed-simd">, 
Group;
+def msign_ext : Flag<["-"], "msign-ext">, Group;
+def mno_sign_ext : Flag<["-"], "mno-sign-ext">, Group;
+def msimd128 : Flag<["-"], "msimd128">, Group;
+def mno_simd128 : Flag<["-"], "mno-simd128">, Group;
+def mtail_call : Flag<["-"], "mtail-call">, Group;
+def mno_tail_call : Flag<["-"], "mno-tail-call">, Group;
 def mexec_model_EQ : Joined<["-"], "mexec-model=">, 
Group,
  Values<"command,reactor">,
  HelpText<"Execution model (WebAssembly only)">,
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 1f0418b21c1f86..a363478680570c 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -45,20 +45,20 @@ bool WebAssemblyTargetInfo::setABI(const std::string ) 
{
 
 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
   return llvm::StringSwitch(Feature)
-  .Case("simd128", SIMDLevel >= SIMD128)
-  .Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
+  .Case("atomics", HasAtomics)
+  .Case("bulk-memory", HasBulkMemory)
+  .Case("exception-handling", HasExceptionHandling)
+  

[clang] [llvm] [WebAssembly] Sort target features (NFC) (PR #90777)

2024-05-01 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin created 
https://github.com/llvm/llvm-project/pull/90777

None

>From b9fd03c2740fe924c0ea49bb78c9898412364105 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Mon, 29 Apr 2024 22:16:46 +
Subject: [PATCH] [WebAssembly] Sort target features (NFC)

---
 clang/include/clang/Driver/Options.td |  40 ++---
 clang/lib/Basic/Targets/WebAssembly.cpp   | 166 +-
 clang/lib/Basic/Targets/WebAssembly.h |  18 +-
 clang/test/Driver/wasm-features.c |  88 +-
 llvm/lib/Target/WebAssembly/WebAssembly.td|  64 +++
 .../WebAssembly/WebAssemblyInstrInfo.td   |  72 
 .../Target/WebAssembly/WebAssemblySubtarget.h |  32 ++--
 7 files changed, 241 insertions(+), 239 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 864da4e1157f7d..5b79b066d384ad 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4895,34 +4895,34 @@ def mharden_sls_EQ : Joined<["-"], "mharden-sls=">, 
Group,
" blr(ARM/AArch64), comdat(ARM/AArch64), nocomdat(ARM/AArch64),"
" return(X86), indirect-jmp(X86)">;
 
-def msimd128 : Flag<["-"], "msimd128">, Group;
-def mno_simd128 : Flag<["-"], "mno-simd128">, Group;
-def mrelaxed_simd : Flag<["-"], "mrelaxed-simd">, Group;
-def mno_relaxed_simd : Flag<["-"], "mno-relaxed-simd">, 
Group;
-def mhalf_precision : Flag<["-"], "mhalf-precision">, 
Group;
-def mno_half_precision : Flag<["-"], "mno-half-precision">, 
Group;
-def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, 
Group;
-def mno_nontrapping_fptoint : Flag<["-"], "mno-nontrapping-fptoint">, 
Group;
-def msign_ext : Flag<["-"], "msign-ext">, Group;
-def mno_sign_ext : Flag<["-"], "mno-sign-ext">, Group;
-def mexception_handing : Flag<["-"], "mexception-handling">, 
Group;
-def mno_exception_handing : Flag<["-"], "mno-exception-handling">, 
Group;
 def matomics : Flag<["-"], "matomics">, Group;
 def mno_atomics : Flag<["-"], "mno-atomics">, Group;
 def mbulk_memory : Flag<["-"], "mbulk-memory">, Group;
 def mno_bulk_memory : Flag<["-"], "mno-bulk-memory">, 
Group;
-def mmutable_globals : Flag<["-"], "mmutable-globals">, 
Group;
-def mno_mutable_globals : Flag<["-"], "mno-mutable-globals">, 
Group;
-def mmultivalue : Flag<["-"], "mmultivalue">, Group;
-def mno_multivalue : Flag<["-"], "mno-multivalue">, 
Group;
-def mtail_call : Flag<["-"], "mtail-call">, Group;
-def mno_tail_call : Flag<["-"], "mno-tail-call">, Group;
-def mreference_types : Flag<["-"], "mreference-types">, 
Group;
-def mno_reference_types : Flag<["-"], "mno-reference-types">, 
Group;
+def mexception_handing : Flag<["-"], "mexception-handling">, 
Group;
+def mno_exception_handing : Flag<["-"], "mno-exception-handling">, 
Group;
 def mextended_const : Flag<["-"], "mextended-const">, 
Group;
 def mno_extended_const : Flag<["-"], "mno-extended-const">, 
Group;
+def mhalf_precision : Flag<["-"], "mhalf-precision">, 
Group;
+def mno_half_precision : Flag<["-"], "mno-half-precision">, 
Group;
 def mmultimemory : Flag<["-"], "mmultimemory">, Group;
 def mno_multimemory : Flag<["-"], "mno-multimemory">, 
Group;
+def mmultivalue : Flag<["-"], "mmultivalue">, Group;
+def mno_multivalue : Flag<["-"], "mno-multivalue">, 
Group;
+def mmutable_globals : Flag<["-"], "mmutable-globals">, 
Group;
+def mno_mutable_globals : Flag<["-"], "mno-mutable-globals">, 
Group;
+def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, 
Group;
+def mno_nontrapping_fptoint : Flag<["-"], "mno-nontrapping-fptoint">, 
Group;
+def mreference_types : Flag<["-"], "mreference-types">, 
Group;
+def mno_reference_types : Flag<["-"], "mno-reference-types">, 
Group;
+def mrelaxed_simd : Flag<["-"], "mrelaxed-simd">, Group;
+def mno_relaxed_simd : Flag<["-"], "mno-relaxed-simd">, 
Group;
+def msign_ext : Flag<["-"], "msign-ext">, Group;
+def mno_sign_ext : Flag<["-"], "mno-sign-ext">, Group;
+def msimd128 : Flag<["-"], "msimd128">, Group;
+def mno_simd128 : Flag<["-"], "mno-simd128">, Group;
+def mtail_call : Flag<["-"], "mtail-call">, Group;
+def mno_tail_call : Flag<["-"], "mno-tail-call">, Group;
 def mexec_model_EQ : Joined<["-"], "mexec-model=">, 
Group,
  Values<"command,reactor">,
  HelpText<"Execution model (WebAssembly only)">,
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 1f0418b21c1f86..a363478680570c 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -45,20 +45,20 @@ bool WebAssemblyTargetInfo::setABI(const std::string ) 
{
 
 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
   return llvm::StringSwitch(Feature)
-  .Case("simd128", SIMDLevel >= SIMD128)
-  .Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
+  .Case("atomics", HasAtomics)
+  .Case("bulk-memory", HasBulkMemory)
+  

[clang-tools-extra] [clang-tidy] Handle implicit casts in hicpp-signed-bitwise for IgnorePositiveIntegerLiterals (PR #90621)

2024-05-01 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.


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


[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)

2024-05-01 Thread Doug Wyatt via cfe-commits


@@ -86,7 +86,7 @@ TEST(DataLayoutUpgradeTest, NoDataLayoutUpgrade) {
   "-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64"
   "-f80:128:128-n8:16:32:64-S128");
   EXPECT_EQ(DL2, "e-m:e-i64:64-n32:64");
-  EXPECT_EQ(DL3, "e-m:o-i64:64-i128:128-n32:64-S128");
+  EXPECT_EQ(DL3, "e-m:o-i64:64-i128:128-n32:64-S128-Fn32");

dougsonos wrote:

Actually this is supposed to be a no-op test; this should be moved and replaced 
with one which tests a no-op situation.

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


[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-05-01 Thread Dan Liew via cfe-commits

https://github.com/delcypher updated 
https://github.com/llvm/llvm-project/pull/87596

>From 4e6130ea07e655081df3f2ca9c89fd1be035a68d Mon Sep 17 00:00:00 2001
From: Dan Liew 
Date: Wed, 1 May 2024 13:56:52 -0700
Subject: [PATCH] [BoundsSafety] Allow 'counted_by' attribute on pointers in
 structs in C

Previously the attribute was only allowed on flexible array members.
This patch patch changes this to also allow the attribute on pointer
fields in structs and also allows late parsing of the attribute in some
contexts.

For example this previously wasn't allowed:

```
struct BufferTypeDeclAttributePosition {
  size_t count;
  char* buffer __counted_by(count); // Now allowed
}
```

Note the attribute is prevented on pointee types where the size isn't
known at compile time. In particular pointee types that are:

* Incomplete (e.g. `void`) and sizeless types
* Function types (e.g. the pointee of a function pointer)
* Struct types with a flexible array member

This patch also introduces late parsing of the attribute when used
in the declaration attribute position. For example

```
struct BufferTypeDeclAttributePosition {
  char* buffer __counted_by(count); // Now allowed
  size_t count;
}
```

is now allowed but **only** when passing
`-fexperimental-late-parse-attributes`.  The motivation for using late
parsing here is to avoid breaking the data layout of structs in existing
code that want to use the `counted_by` attribute. This patch is the
first use of `LateAttrParseExperimentalExt` in `Attr.td` that was
introduced in a previous patch.

Note by allowing the attribute on struct member pointers this now allows
the possiblity of writing the attribute in the type attribute position.
For example:

```
struct BufferTypeAttributePosition {
  size_t count;
  char *__counted_by(count) buffer; // Now allowed
}
```

However, the attribute in this position is still currently parsed
immediately rather than late parsed. So this will not parse currently:

```
struct BufferTypeAttributePosition {
  char *__counted_by(count) buffer; // Fails to parse
  size_t count;
}
```

The intention is to lift this restriction in future patches. It has not
been done in this patch to keep this size of this commit small.

Note this patch only allows parsing of semantic analysis of the
attribute on pointers. It does not make use of this on the codegen side
(e.g. for _builtin_dynamic_object_size and UBSan's array-bounds checks).
Making use of the attribute on pointers will be handled in separate
patches.

This work is heavily based on a patch originally written by Yeoul Na.

rdar://125400257
---
 clang/docs/ReleaseNotes.rst   |  19 +-
 clang/include/clang/AST/Type.h|   1 +
 clang/include/clang/Basic/Attr.td |   3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  15 +-
 clang/include/clang/Parse/Parser.h|   8 +-
 clang/include/clang/Sema/Sema.h   |   3 +-
 clang/lib/AST/Type.cpp|  12 ++
 clang/lib/Parse/ParseDecl.cpp | 102 ++-
 clang/lib/Parse/ParseObjc.cpp |   6 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  71 ++--
 clang/lib/Sema/SemaType.cpp   |   6 +-
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/AST/attr-counted-by-late-parsed.c  |  31 
 .../Sema/attr-counted-by-late-parsed-off.c|  26 +++
 .../attr-counted-by-late-parsed-struct-ptrs.c | 169 ++
 ...tr-counted-by-struct-ptrs-sizeless-types.c |  17 ++
 clang/test/Sema/attr-counted-by-struct-ptrs.c | 163 +
 clang/test/Sema/attr-counted-by.c |   5 +-
 18 files changed, 623 insertions(+), 36 deletions(-)
 create mode 100644 clang/test/AST/attr-counted-by-late-parsed.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-off.c
 create mode 100644 clang/test/Sema/attr-counted-by-late-parsed-struct-ptrs.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs-sizeless-types.c
 create mode 100644 clang/test/Sema/attr-counted-by-struct-ptrs.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c0fe5bcf6b122..81d0a89b294878 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -258,7 +258,8 @@ New Compiler Flags
 
 - ``-fexperimental-late-parse-attributes`` enables an experimental feature to
   allow late parsing certain attributes in specific contexts where they would
-  not normally be late parsed.
+  not normally be late parsed. Currently this allows late parsing the
+  `counted_by` attribute in C. See `Attribute Changes in Clang`_.
 
 Deprecated Compiler Flags
 -
@@ -335,6 +336,22 @@ Attribute Changes in Clang
 - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
   is ignored when applied to a local class or a member thereof.
 
+- The ``counted_by`` attribute can now be late parsed in C when
+  ``-fexperimental-late-parse-attributes`` is passed 

[clang-tools-extra] [clang-tidy] Handle expr with side-effects in readability-static-accessed-through-instance (PR #90736)

2024-05-01 Thread Julian Schmidt via cfe-commits


@@ -380,3 +387,20 @@ namespace PR51861 {
 // CHECK-FIXES: {{^}}PR51861::Foo::getBar();{{$}}
   }
 }
+
+namespace PR75163 {

5chmidti wrote:

Nit: `GH` instead of `PR`?

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


[clang-tools-extra] [clang-tidy] Handle expr with side-effects in readability-static-accessed-through-instance (PR #90736)

2024-05-01 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.

LGTM

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


[clang-tools-extra] [clang-tidy] Handle expr with side-effects in readability-static-accessed-through-instance (PR #90736)

2024-05-01 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)

2024-05-01 Thread Vadim D. via cfe-commits

vvd170501 wrote:

Ping. Can anyone review this, please?

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


[clang] [HLSL] Shore up floating point conversions (PR #90222)

2024-05-01 Thread Tex Riddell via cfe-commits

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


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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-05-01 Thread via cfe-commits


@@ -27,6 +27,8 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"

Sirraide wrote:

No yeah, that part makes sense; I’d assume that you need to link to 
clangASTMatchers to be able to use AST matchers. I’m just saying I’m not sure 
whether we want to use AST matchers in Sema as there doesn’t seem to be a 
precedent for it—though I’m not familiar enough w/ the analysis part of Sema to 
know whether we’ve just never needed them or whether there’s another reason why 
you might not want to use them (afaik AST matchers are one of those components 
like libclang that are maintained on a best-effort basis, but I could be wrong).

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

2024-05-01 Thread Chris Apple via cfe-commits


@@ -27,6 +27,8 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"

cjappl wrote:

To be less prescriptive with the solution:

I was getting linker errors saying that the symbols found in the ASTMatchers 
headers (used later in this file) were missing. I fixed it with this CMake 
change. Let me know if anyone needs more info and I'll re-generate the error.

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


[clang-tools-extra] [clang-tidy] Relax readability-const-return-type (PR #90560)

2024-05-01 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.


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


[clang-tools-extra] [clang-tidy] Ignore casts from void to void in bugprone-casting-through-void (PR #90566)

2024-05-01 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.

LGTM

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


[clang] [HLSL] Shore up floating point conversions (PR #90222)

2024-05-01 Thread Chris B via cfe-commits

https://github.com/llvm-beanz updated 
https://github.com/llvm/llvm-project/pull/90222

>From a173605b6043739e69f89d3a559a4f6a68d5fc0a Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Thu, 25 Apr 2024 15:47:22 -0500
Subject: [PATCH 1/2] [HLSL] Shore up floating point conversions

This PR fixes bugs in HLSL floating conversions. HLSL always has
`half`, `float` and `double` types, which promote in the order:

`half`->`float`->`double`

and convert in the order:

`double`->`float`->`half`

As with other conversions in C++, promotions are preferred over
conversions.

We do have floating conversions documented in the draft language
specification (https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf
[Conv.rank.float]) although the exact language is still in flux
(https://github.com/microsoft/hlsl-specs/pull/206).

Resolves #81047
---
 clang/lib/Sema/SemaOverload.cpp   |  43 +++-
 .../SemaHLSL/ScalarOverloadResolution.hlsl| 229 ++
 .../VectorElementOverloadResolution.hlsl  | 228 +
 3 files changed, 499 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaHLSL/ScalarOverloadResolution.hlsl
 create mode 100644 clang/test/SemaHLSL/VectorElementOverloadResolution.hlsl

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 04cd9e78739d20..a416df2e97c439 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2587,7 +2587,8 @@ bool Sema::IsIntegralPromotion(Expr *From, QualType 
FromType, QualType ToType) {
 
   // In HLSL an rvalue of integral type can be promoted to an rvalue of a 
larger
   // integral type.
-  if (Context.getLangOpts().HLSL)
+  if (Context.getLangOpts().HLSL && FromType->isIntegerType() &&
+  ToType->isIntegerType())
 return Context.getTypeSize(FromType) < Context.getTypeSize(ToType);
 
   return false;
@@ -2616,6 +2617,13 @@ bool Sema::IsFloatingPointPromotion(QualType FromType, 
QualType ToType) {
ToBuiltin->getKind() == BuiltinType::Ibm128))
 return true;
 
+  // In HLSL, `half` promotes to `float` or `double`, regardless of whether
+  // or not native half types are enabled.
+  if (getLangOpts().HLSL && FromBuiltin->getKind() == BuiltinType::Half &&
+  (ToBuiltin->getKind() == BuiltinType::Float ||
+   ToBuiltin->getKind() == BuiltinType::Double))
+return true;
+
   // Half can be promoted to float.
   if (!getLangOpts().NativeHalfType &&
FromBuiltin->getKind() == BuiltinType::Half &&
@@ -4393,6 +4401,24 @@ getFixedEnumPromtion(Sema , const 
StandardConversionSequence ) {
   return FixedEnumPromotion::ToPromotedUnderlyingType;
 }
 
+static ImplicitConversionSequence::CompareKind
+HLSLCompareFloatingRank(QualType LHS, QualType RHS) {
+  assert(LHS->isVectorType() == RHS->isVectorType() &&
+ "Either both elements should be vectors or neither should.");
+  if (const auto *VT = LHS->getAs())
+LHS = VT->getElementType();
+
+  if (const auto *VT = RHS->getAs())
+RHS = VT->getElementType();
+
+  const auto L = LHS->getAs()->getKind();
+  const auto R = RHS->getAs()->getKind();
+  if (L == R)
+return ImplicitConversionSequence::Indistinguishable;
+  return L < R ? ImplicitConversionSequence::Better
+   : ImplicitConversionSequence::Worse;
+}
+
 /// CompareStandardConversionSequences - Compare two standard
 /// conversion sequences to determine whether one is better than the
 /// other or if they are indistinguishable (C++ 13.3.3.2p3).
@@ -4634,6 +4660,21 @@ CompareStandardConversionSequences(Sema , 
SourceLocation Loc,
  : ImplicitConversionSequence::Worse;
   }
 
+  if (S.getLangOpts().HLSL) {
+// On a promotion we prefer the lower rank to disambiguate.
+if ((SCS1.Second == ICK_Floating_Promotion &&
+ SCS2.Second == ICK_Floating_Promotion) ||
+(SCS1.Element == ICK_Floating_Promotion &&
+ SCS2.Element == ICK_Floating_Promotion))
+  return HLSLCompareFloatingRank(SCS1.getToType(2), SCS2.getToType(2));
+// On a conversion we prefer the higher rank to disambiguate.
+if ((SCS1.Second == ICK_Floating_Conversion &&
+ SCS2.Second == ICK_Floating_Conversion) ||
+(SCS1.Element == ICK_Floating_Conversion &&
+ SCS2.Element == ICK_Floating_Conversion))
+  return HLSLCompareFloatingRank(SCS2.getToType(2), SCS1.getToType(2));
+  }
+
   return ImplicitConversionSequence::Indistinguishable;
 }
 
diff --git a/clang/test/SemaHLSL/ScalarOverloadResolution.hlsl 
b/clang/test/SemaHLSL/ScalarOverloadResolution.hlsl
new file mode 100644
index 00..13758995ec6a1e
--- /dev/null
+++ b/clang/test/SemaHLSL/ScalarOverloadResolution.hlsl
@@ -0,0 +1,229 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type 
-finclude-default-header -Wconversion -verify -o - %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type 
-finclude-default-header 

[clang] [HLSL] Support packoffset attribute in AST (PR #89836)

2024-05-01 Thread Xiang Li via cfe-commits


@@ -1745,5 +1745,7 @@ def err_hlsl_separate_attr_arg_and_number : Error<"wrong 
argument format for hls
 def ext_hlsl_access_specifiers : ExtWarn<
   "access specifiers are a clang HLSL extension">,
   InGroup;
+def err_hlsl_unsupported_component : Error<"invalid component '%0' used; 
expected 'x', 'y', 'z', or 'w'">;
+def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier 
'%0' for packoffset, expected 'c'">;

python3kgae wrote:

Yes. I'll add that.

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


[clang-tools-extra] [clang-tidy] Ignore unevaluated context in bugprone-optional-value-conversion (PR #90410)

2024-05-01 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti commented:

Do we maybe want to explicitly match `decltype`, `sizeof`, `static_cast` etc. 
instead of `typeLoc`?
Because I don't think we would want to ignore https://godbolt.org/z/r3bK961do

```c++
#include 

constexpr std::optional foo() { return 42; }

constexpr int select(std::optional val) { return val.value_or(0); }

template 
struct bar {};

void use() { using F = bar; }
```

(There are other checks with this ignore pattern, depending on the answer to my 
question we should check those as well)

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


[clang] [HLSL] Support packoffset attribute in AST (PR #89836)

2024-05-01 Thread Damyan Pepper via cfe-commits

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


[clang] [HLSL] Support packoffset attribute in AST (PR #89836)

2024-05-01 Thread Damyan Pepper via cfe-commits


@@ -1745,5 +1745,7 @@ def err_hlsl_separate_attr_arg_and_number : Error<"wrong 
argument format for hls
 def ext_hlsl_access_specifiers : ExtWarn<
   "access specifiers are a clang HLSL extension">,
   InGroup;
+def err_hlsl_unsupported_component : Error<"invalid component '%0' used; 
expected 'x', 'y', 'z', or 'w'">;
+def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier 
'%0' for packoffset, expected 'c'">;

damyanp wrote:

Should we document that this is an error, while in DXC it is just a warning, in 
the Clang vs DXC differences page?

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


[clang] [HLSL] Support packoffset attribute in AST (PR #89836)

2024-05-01 Thread Damyan Pepper via cfe-commits


@@ -7398,6 +7398,26 @@ The full documentation is available here: 
https://docs.microsoft.com/en-us/windo
   }];
 }
 
+def HLSLPackOffsetDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The packoffset attribute is used to change the layout of a cbuffer.
+Attribute spelling in HLSL is: ``packoffset( c[Subcomponent][.component] )``.
+A subcomponent is a register number, which is an integer. A component is in 
the form of [.xyzw].
+
+Here're packoffset examples with and without component:

damyanp wrote:

```suggestion
Here are some packoffset examples with and without component:
```

Or:

```suggestion
Examples:
```


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


[clang] [HLSL] Support packoffset attribute in AST (PR #89836)

2024-05-01 Thread Damyan Pepper via cfe-commits

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

Apologies, it looks like I forgot to submit this review!  Hopefully the 
comments aren't too out of date.

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


  1   2   3   4   >