[clang] [clang][dataflow] Emit an error if source code is not compiled as C++. (PR #65301)

2023-11-16 Thread via cfe-commits

martinboehme wrote:

> Is this the right place to add this check? It doesn't seem like there's any 
> C++-specific logic here.
> 
> Presumably the real incompatibility is `clang::CFG` or one of the consumers 
> of `dataflow::ControlFlowContext`?

Much of the logic in the dataflow framework assumes that the AST comes from a 
C++ compilation. For example, the code in Transfer.cpp makes a lot of 
assumptions around this, but other places do too.

`ControlFlowContext::build()` is a good central place to check whether the 
language is C++ and abort with a meaningful error message if it isn't.



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


[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

2023-11-16 Thread Piotr Zegar via cfe-commits

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

Code is fine and can be merged, unless you want it merged as 
"schen...@users.noreply.github.com" you may need to disable email privacy 
options or try to squash all commits in one.

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


[clang] [AArch64][SME2] Add FCLAMP, CNTP builtins for SME2 (PR #72487)

2023-11-16 Thread Sander de Smalen via cfe-commits


@@ -1970,17 +1969,20 @@ def SVBFMLSLT_LANE : SInst<"svbfmlslt_lane[_{d}]", 
"dd$$i", "f", MergeNone, "aar
 let TargetGuard = "sve2p1" in {
 def SVSCLAMP : SInst<"svclamp[_{d}]", "", "csil", MergeNone, 
"aarch64_sve_sclamp", [], []>;
 def SVUCLAMP : SInst<"svclamp[_{d}]", "", "UcUsUiUl", MergeNone, 
"aarch64_sve_uclamp", [], []>;
-
 def SVPSEL_B : SInst<"svpsel_lane_b8",  "PPPm", "Pc", MergeNone, "", [], []>;
 def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", [], []>;
 def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", [], []>;
 def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", [], []>;
 
-def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_cntp_{d}", [IsOverloadNone], [ImmCheck<1, ImmCheck2_4_Mul2>]>;
-
 defm SVREVD : SInstZPZ<"svrevd", "csilUcUsUiUl", "aarch64_sve_revd">;
 }
 
+let TargetGuard = "sve2p1|sme2" in {
+  def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [IsStreamingCompatible], []>;
+  def SVFCLAMP_BF   : SInst<"svclamp[_{d}]", "", "b", MergeNone, 
"aarch64_sve_fclamp", [IsStreamingCompatible], []>;

sdesmalen-arm wrote:

SVFCLAMP_BF should additionally be predicated under +b16b16 which is optionally 
available with SVE2 or SME2.

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


[clang] 10ad98d - [NFC] [C++20] [Modules] Add a test from issue 71484

2023-11-16 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-11-16T16:05:46+08:00
New Revision: 10ad98dc160497699930f295dcb4c998ef561d2e

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

LOG: [NFC] [C++20] [Modules] Add a test from issue 71484

The example from issue report 71484 works fine on trunk. Add the example to the
tests since testing is always good.

Added: 
clang/test/Modules/pr71484.cppm

Modified: 


Removed: 




diff  --git a/clang/test/Modules/pr71484.cppm b/clang/test/Modules/pr71484.cppm
new file mode 100644
index 000..088a4cf9f4e457d
--- /dev/null
+++ b/clang/test/Modules/pr71484.cppm
@@ -0,0 +1,41 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/mod1.cppm -emit-module-interface -o 
%t/mod1.pcm
+// RUN: %clang_cc1 -std=c++20 %t/mod2.cppm -emit-module-interface -o 
%t/mod2.pcm \
+// RUN: -fprebuilt-module-path=%t
+// RUN:  %clang_cc1 -std=c++20 %t/mod3.cppm -fsyntax-only -verify \
+// RUN: -fprebuilt-module-path=%t
+
+// RUN: %clang_cc1 -std=c++20 %t/mod1.cppm -emit-obj -o %t/mod1.o 
-fmodule-output=%t/mod1.pcm
+// RUN: %clang_cc1 -std=c++20 %t/mod2.cppm -emit-obj -o %t/mod2.o 
-fmodule-output=%t/mod2.pcm \
+// RUN: -fprebuilt-module-path=%t
+// RUN:  %clang_cc1 -std=c++20 %t/mod3.cppm -fsyntax-only -verify \
+// RUN: -fprebuilt-module-path=%t
+
+//--- mod1.cppm
+export module mod1;
+
+export template
+T mod1_f(T x) {
+return x;
+}
+
+//--- mod2.cppm
+export module mod2;
+import mod1;
+
+export template
+U mod2_g(U y) {
+return mod1_f(y);
+}
+
+//--- mod3.cppm
+// expected-no-diagnostics
+export module mod3;
+import mod2;
+
+export int mod3_h(int p) {
+return mod2_g(p);
+}



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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-16 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,106 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStartsEndsWithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+const auto DefaultStringLikeClasses =
+"::std::basic_string;::std::basic_string_view";
+
+UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(utils::options::parseStringList(
+  Options.get("StringLikeClasses", DefaultStringLikeClasses))) {}
+
+void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto StringClassMatcher = cxxRecordDecl(hasAnyName(StringLikeClasses));

PiotrZSL wrote:

Check this other matcher that we have, the one from utils directory, that is 
already used for example in enum-size check

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-16 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,106 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStartsEndsWithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+const auto DefaultStringLikeClasses =
+"::std::basic_string;::std::basic_string_view";
+
+UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(utils::options::parseStringList(
+  Options.get("StringLikeClasses", DefaultStringLikeClasses))) {}
+
+void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto StringClassMatcher = cxxRecordDecl(hasAnyName(StringLikeClasses));
+  const auto StringType = hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(StringClassMatcher)));
+
+  const auto StringFind = cxxMemberCallExpr(
+  // .find()-call on a string...
+  callee(cxxMethodDecl(hasName("find")).bind("findfun")),
+  on(hasType(StringType)),

PiotrZSL wrote:

this wont work with class inheritence, if someone derive from std::string, 
instead you could use:
callee(cxxMethodDecl(ofClass(hasAnyName)))

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-16 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,106 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStartsEndsWithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+const auto DefaultStringLikeClasses =
+"::std::basic_string;::std::basic_string_view";
+
+UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(utils::options::parseStringList(
+  Options.get("StringLikeClasses", DefaultStringLikeClasses))) {}
+
+void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto StringClassMatcher = cxxRecordDecl(hasAnyName(StringLikeClasses));
+  const auto StringType = hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(StringClassMatcher)));
+
+  const auto StringFind = cxxMemberCallExpr(
+  // .find()-call on a string...
+  callee(cxxMethodDecl(hasName("find")).bind("findfun")),
+  on(hasType(StringType)),

PiotrZSL wrote:

Also in same place you could verify if class got also starts_with and ends_wth 
method, in such case classes like llvm::StringRef or some boost one could be 
supported at hock.

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-16 Thread Piotr Zegar via cfe-commits


@@ -31,6 +30,10 @@ class StringFindStartswithCheck : public ClangTidyCheck {
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+// Prefer performance-use-starts-ends-with when C++20 is available.
+return LangOpts.CPlusPlus && !LangOpts.CPlusPlus20;
+  }
 

PiotrZSL wrote:

Use TK_IgnoreUnlessSpelledInSource to exclude things like template instances 
and  implicit code.

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


[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

2023-11-16 Thread via cfe-commits

https://github.com/schenker updated 
https://github.com/llvm/llvm-project/pull/71974

>From d899ad40afd6a84210313e6e5f94bb1d678a4778 Mon Sep 17 00:00:00 2001
From: Thomas Schenker 
Date: Fri, 10 Nov 2023 18:58:26 +0100
Subject: [PATCH] [clang-tidy] bugprone-assert-side-effect non-const operator
 methods

With this PR, `bugprone-assert-side-effect` assumes that operator methods
that are not marked as `const` have side effects. This matches the
existing rule for non-operator methods.

E.g. the following snippet is now reported and was previously not:
```
std::stringstream ss;
assert(ss << 1);
```
---
 .../bugprone/AssertSideEffectCheck.cpp|  6 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +
 .../checkers/bugprone/assert-side-effect.cpp  | 22 +++
 3 files changed, 33 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 07a987359d4d8d7..43bedd4f73ef447 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -41,12 +41,18 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, 
CheckFunctionCalls,
   }
 
   if (const auto *OpCallExpr = dyn_cast(E)) {
+if (const auto *MethodDecl =
+dyn_cast_or_null(OpCallExpr->getDirectCallee()))
+  if (MethodDecl->isConst())
+return false;
+
 OverloadedOperatorKind OpKind = OpCallExpr->getOperator();
 return OpKind == OO_Equal || OpKind == OO_PlusEqual ||
OpKind == OO_MinusEqual || OpKind == OO_StarEqual ||
OpKind == OO_SlashEqual || OpKind == OO_AmpEqual ||
OpKind == OO_PipeEqual || OpKind == OO_CaretEqual ||
OpKind == OO_LessLessEqual || OpKind == OO_GreaterGreaterEqual ||
+   OpKind == OO_LessLess || OpKind == OO_GreaterGreater ||
OpKind == OO_PlusPlus || OpKind == OO_MinusMinus ||
OpKind == OO_PercentEqual || OpKind == OO_New ||
OpKind == OO_Delete || OpKind == OO_Array_New ||
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 353c6fe20269274..23111be4371e2e1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -212,6 +212,11 @@ Changes in existing checks
   ` check to also consider
   ``std::basic_string_view`` in addition to ``std::basic_string`` by default.
 
+- Improved :doc:`bugprone-assert-side-effect
+  ` check to report usage of
+  non-const ``<<`` and ``>>`` operators in assertions and fixed some 
false-positives
+  with const operators.
+
 - Improved :doc:`bugprone-dangling-handle
   ` check to support functional
   casting during type conversions at variable initialization, now with improved
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
index 6c41e1e320adeac..c11638aa823aaeb 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
@@ -84,5 +84,27 @@ int main() {
   msvc_assert(mc2 = mc);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in msvc_assert() 
condition discarded in release builds
 
+  struct OperatorTest {
+int operator<<(int i) const { return i; }
+int operator<<(int i) { return i; }
+int operator+=(int i) const { return i; }
+int operator+=(int i) { return i; }
+  };
+
+  const OperatorTest const_instance;
+  assert(const_instance << 1);
+  assert(const_instance += 1);
+
+  OperatorTest non_const_instance;
+  assert(static_cast(non_const_instance) << 1);
+  assert(static_cast(non_const_instance) += 1);
+  assert(non_const_instance << 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
+  assert(non_const_instance += 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
+
+  assert(5<<1);
+  assert(5>>1);
+
   return 0;
 }

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-16 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,106 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStartsEndsWithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+const auto DefaultStringLikeClasses =
+"::std::basic_string;::std::basic_string_view";
+
+UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(utils::options::parseStringList(
+  Options.get("StringLikeClasses", DefaultStringLikeClasses))) {}
+
+void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto StringClassMatcher = cxxRecordDecl(hasAnyName(StringLikeClasses));
+  const auto StringType = hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(StringClassMatcher)));
+
+  const auto StringFind = cxxMemberCallExpr(
+  // .find()-call on a string...
+  callee(cxxMethodDecl(hasName("find")).bind("findfun")),
+  on(hasType(StringType)),
+  // ... with some search expression ...
+  hasArgument(0, expr().bind("needle")),
+  // ... and either "0" as second argument or the default argument (also 
0).
+  anyOf(hasArgument(1, ZeroLiteral), argumentCountIs(1)));
+
+  const auto StringRFind = cxxMemberCallExpr(
+  // .rfind()-call on a string...
+  callee(cxxMethodDecl(hasName("rfind")).bind("rfindfun")),
+  on(hasType(StringType)),
+  // ... with some search expression ...
+  hasArgument(0, expr().bind("needle")),
+  // ... and "0" as second argument.
+  hasArgument(1, ZeroLiteral));
+
+  Finder->addMatcher(
+  // Match [=!]= with a zero on one side and a string.(r?)find on the 
other.
+  binaryOperator(
+  hasAnyOperatorName("==", "!="),
+  hasOperands(ZeroLiteral,
+  cxxMemberCallExpr(anyOf(StringFind, StringRFind))
+  .bind("findexpr")))
+  .bind("expr"),
+  this);
+}
+
+void UseStartsEndsWithCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+  const SourceManager &Source = Context.getSourceManager();
+
+  const auto *ComparisonExpr = Result.Nodes.getNodeAs("expr");
+  const auto *Needle = Result.Nodes.getNodeAs("needle");
+  const Expr *Haystack = Result.Nodes.getNodeAs("findexpr")
+ ->getImplicitObjectArgument();
+  const auto *FindFun = Result.Nodes.getNodeAs("findfun");
+  const auto *RFindFun = Result.Nodes.getNodeAs("rfindfun");
+  assert(!FindFun != !RFindFun); // XOR.
+
+  if (ComparisonExpr->getBeginLoc().isMacroID()) {
+return;
+  }
+
+  const StringRef NeedleExprCode = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Needle->getSourceRange()), Source,
+  Context.getLangOpts());
+  const StringRef HaystackExprCode = Lexer::getSourceText(

PiotrZSL wrote:

if possible avoid using getSourceText this mess out with multiple fixes.
Consider just using multiple CreateReplacement and CreateInsertion

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-16 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,106 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStartsEndsWithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+const auto DefaultStringLikeClasses =
+"::std::basic_string;::std::basic_string_view";
+
+UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(utils::options::parseStringList(
+  Options.get("StringLikeClasses", DefaultStringLikeClasses))) {}
+
+void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto StringClassMatcher = cxxRecordDecl(hasAnyName(StringLikeClasses));
+  const auto StringType = hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(StringClassMatcher)));
+
+  const auto StringFind = cxxMemberCallExpr(
+  // .find()-call on a string...
+  callee(cxxMethodDecl(hasName("find")).bind("findfun")),
+  on(hasType(StringType)),
+  // ... with some search expression ...
+  hasArgument(0, expr().bind("needle")),
+  // ... and either "0" as second argument or the default argument (also 
0).
+  anyOf(hasArgument(1, ZeroLiteral), argumentCountIs(1)));
+
+  const auto StringRFind = cxxMemberCallExpr(
+  // .rfind()-call on a string...
+  callee(cxxMethodDecl(hasName("rfind")).bind("rfindfun")),
+  on(hasType(StringType)),
+  // ... with some search expression ...
+  hasArgument(0, expr().bind("needle")),
+  // ... and "0" as second argument.
+  hasArgument(1, ZeroLiteral));
+
+  Finder->addMatcher(
+  // Match [=!]= with a zero on one side and a string.(r?)find on the 
other.
+  binaryOperator(
+  hasAnyOperatorName("==", "!="),
+  hasOperands(ZeroLiteral,
+  cxxMemberCallExpr(anyOf(StringFind, StringRFind))
+  .bind("findexpr")))
+  .bind("expr"),
+  this);
+}
+
+void UseStartsEndsWithCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+  const SourceManager &Source = Context.getSourceManager();
+
+  const auto *ComparisonExpr = Result.Nodes.getNodeAs("expr");
+  const auto *Needle = Result.Nodes.getNodeAs("needle");
+  const Expr *Haystack = Result.Nodes.getNodeAs("findexpr")
+ ->getImplicitObjectArgument();
+  const auto *FindFun = Result.Nodes.getNodeAs("findfun");
+  const auto *RFindFun = Result.Nodes.getNodeAs("rfindfun");
+  assert(!FindFun != !RFindFun); // XOR.
+
+  if (ComparisonExpr->getBeginLoc().isMacroID()) {
+return;
+  }
+
+  const StringRef NeedleExprCode = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Needle->getSourceRange()), Source,
+  Context.getLangOpts());
+  const StringRef HaystackExprCode = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Haystack->getSourceRange()), Source,

PiotrZSL wrote:

#define STR str
if Haystack is from macro:
```
  std::string STR;
  if (0 == STR.find("ala"))
```

then it won't work.

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-16 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,106 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStartsEndsWithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+const auto DefaultStringLikeClasses =
+"::std::basic_string;::std::basic_string_view";
+
+UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(utils::options::parseStringList(
+  Options.get("StringLikeClasses", DefaultStringLikeClasses))) {}
+
+void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto StringClassMatcher = cxxRecordDecl(hasAnyName(StringLikeClasses));
+  const auto StringType = hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(StringClassMatcher)));
+
+  const auto StringFind = cxxMemberCallExpr(
+  // .find()-call on a string...
+  callee(cxxMethodDecl(hasName("find")).bind("findfun")),
+  on(hasType(StringType)),
+  // ... with some search expression ...
+  hasArgument(0, expr().bind("needle")),
+  // ... and either "0" as second argument or the default argument (also 
0).
+  anyOf(hasArgument(1, ZeroLiteral), argumentCountIs(1)));
+
+  const auto StringRFind = cxxMemberCallExpr(
+  // .rfind()-call on a string...
+  callee(cxxMethodDecl(hasName("rfind")).bind("rfindfun")),
+  on(hasType(StringType)),
+  // ... with some search expression ...
+  hasArgument(0, expr().bind("needle")),
+  // ... and "0" as second argument.
+  hasArgument(1, ZeroLiteral));
+
+  Finder->addMatcher(
+  // Match [=!]= with a zero on one side and a string.(r?)find on the 
other.
+  binaryOperator(
+  hasAnyOperatorName("==", "!="),
+  hasOperands(ZeroLiteral,
+  cxxMemberCallExpr(anyOf(StringFind, StringRFind))
+  .bind("findexpr")))
+  .bind("expr"),
+  this);
+}
+
+void UseStartsEndsWithCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+  const SourceManager &Source = Context.getSourceManager();
+
+  const auto *ComparisonExpr = Result.Nodes.getNodeAs("expr");
+  const auto *Needle = Result.Nodes.getNodeAs("needle");
+  const Expr *Haystack = Result.Nodes.getNodeAs("findexpr")
+ ->getImplicitObjectArgument();
+  const auto *FindFun = Result.Nodes.getNodeAs("findfun");
+  const auto *RFindFun = Result.Nodes.getNodeAs("rfindfun");
+  assert(!FindFun != !RFindFun); // XOR.
+
+  if (ComparisonExpr->getBeginLoc().isMacroID()) {
+return;
+  }
+
+  const StringRef NeedleExprCode = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Needle->getSourceRange()), Source,
+  Context.getLangOpts());
+  const StringRef HaystackExprCode = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Haystack->getSourceRange()), Source,
+  Context.getLangOpts());
+
+  const bool Rev = RFindFun != nullptr;
+  const bool Neg = ComparisonExpr->getOpcode() == BO_NE;
+  const std::string ReplacementCode = ((Neg ? "!" : "") + HaystackExprCode +
+   ".starts_with(" + NeedleExprCode + ")")
+  .str();
+
+  diag(ComparisonExpr->getBeginLoc(),

PiotrZSL wrote:

actually you could point here to place where call to find/rfind happen

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-16 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-16 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,106 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStartsEndsWithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+const auto DefaultStringLikeClasses =
+"::std::basic_string;::std::basic_string_view";
+
+UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(utils::options::parseStringList(
+  Options.get("StringLikeClasses", DefaultStringLikeClasses))) {}
+
+void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto StringClassMatcher = cxxRecordDecl(hasAnyName(StringLikeClasses));
+  const auto StringType = hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(StringClassMatcher)));
+
+  const auto StringFind = cxxMemberCallExpr(
+  // .find()-call on a string...
+  callee(cxxMethodDecl(hasName("find")).bind("findfun")),
+  on(hasType(StringType)),
+  // ... with some search expression ...
+  hasArgument(0, expr().bind("needle")),
+  // ... and either "0" as second argument or the default argument (also 
0).
+  anyOf(hasArgument(1, ZeroLiteral), argumentCountIs(1)));
+
+  const auto StringRFind = cxxMemberCallExpr(
+  // .rfind()-call on a string...
+  callee(cxxMethodDecl(hasName("rfind")).bind("rfindfun")),
+  on(hasType(StringType)),
+  // ... with some search expression ...
+  hasArgument(0, expr().bind("needle")),
+  // ... and "0" as second argument.
+  hasArgument(1, ZeroLiteral));
+
+  Finder->addMatcher(
+  // Match [=!]= with a zero on one side and a string.(r?)find on the 
other.
+  binaryOperator(
+  hasAnyOperatorName("==", "!="),
+  hasOperands(ZeroLiteral,
+  cxxMemberCallExpr(anyOf(StringFind, StringRFind))
+  .bind("findexpr")))
+  .bind("expr"),
+  this);
+}
+
+void UseStartsEndsWithCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+  const SourceManager &Source = Context.getSourceManager();
+
+  const auto *ComparisonExpr = Result.Nodes.getNodeAs("expr");
+  const auto *Needle = Result.Nodes.getNodeAs("needle");
+  const Expr *Haystack = Result.Nodes.getNodeAs("findexpr")
+ ->getImplicitObjectArgument();
+  const auto *FindFun = Result.Nodes.getNodeAs("findfun");
+  const auto *RFindFun = Result.Nodes.getNodeAs("rfindfun");
+  assert(!FindFun != !RFindFun); // XOR.
+
+  if (ComparisonExpr->getBeginLoc().isMacroID()) {
+return;
+  }
+
+  const StringRef NeedleExprCode = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Needle->getSourceRange()), Source,
+  Context.getLangOpts());
+  const StringRef HaystackExprCode = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Haystack->getSourceRange()), Source,
+  Context.getLangOpts());
+
+  const bool Rev = RFindFun != nullptr;
+  const bool Neg = ComparisonExpr->getOpcode() == BO_NE;
+  const std::string ReplacementCode = ((Neg ? "!" : "") + HaystackExprCode +
+   ".starts_with(" + NeedleExprCode + ")")
+  .str();
+
+  diag(ComparisonExpr->getBeginLoc(),
+   "use starts_with "
+   "instead of %select{find()|rfind()}0 %select{==|!=}1 0")
+  << Rev << Neg
+  << FixItHint::CreateReplacement(ComparisonExpr->getSourceRange(),

PiotrZSL wrote:

may cause problem with comparison ends with macro

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-16 Thread Piotr Zegar via cfe-commits


@@ -8,6 +8,10 @@ corresponding ``std::string_view`` methods) result is compared 
with 0, and
 suggests replacing with ``absl::StartsWith()``. This is both a readability and
 performance issue.
 
+``starts_with`` was added as a built-in function on those types in C++20. If
+available, prefer enabling performance-use-starts-ends-with instead of this

PiotrZSL wrote:

use :doc:`performance-use-starts-ends-with 
<../performance/use-starts-ends-with>`

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


[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

2023-11-16 Thread via cfe-commits

schenker wrote:

Thanks for pointing out, I squashed and changed the settings.

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-16 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,105 @@
+//===--- StringFindStartswithCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "StringFindStartswithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+const auto DefaultStringLikeClasses =
+"::std::basic_string;::std::basic_string_view";
+
+StringFindStartswithCheck::StringFindStartswithCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(utils::options::parseStringList(
+  Options.get("StringLikeClasses", DefaultStringLikeClasses))) {}
+
+void StringFindStartswithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto StringClassMatcher = cxxRecordDecl(hasAnyName(StringLikeClasses));
+  const auto StringType = hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(StringClassMatcher)));
+
+  const auto StringFind = cxxMemberCallExpr(
+  // .find()-call on a string...
+  callee(cxxMethodDecl(hasName("find")).bind("findfun")),
+  on(hasType(StringType)),
+  // ... with some search expression ...
+  hasArgument(0, expr().bind("needle")),
+  // ... and either "0" as second argument or the default argument (also 
0).
+  anyOf(hasArgument(1, ZeroLiteral), hasArgument(1, cxxDefaultArgExpr(;
+
+  const auto StringRFind = cxxMemberCallExpr(
+  // .rfind()-call on a string...
+  callee(cxxMethodDecl(hasName("rfind")).bind("findfun")),
+  on(hasType(StringType)),
+  // ... with some search expression ...
+  hasArgument(0, expr().bind("needle")),
+  // ... and "0" as second argument.
+  hasArgument(1, ZeroLiteral));
+
+  Finder->addMatcher(
+  // Match [=!]= with a zero on one side and a string.(r?)find on the 
other.
+  binaryOperator(
+  hasAnyOperatorName("==", "!="),
+  hasOperands(ignoringParenImpCasts(ZeroLiteral),
+  ignoringParenImpCasts(
+  cxxMemberCallExpr(anyOf(StringFind, StringRFind))
+  .bind("findexpr"
+  .bind("expr"),
+  this);
+}
+
+void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto &Context = *Result.Context;
+  const auto &Source = Context.getSourceManager();
+
+  const auto *ComparisonExpr = Result.Nodes.getNodeAs("expr");
+  const auto *Needle = Result.Nodes.getNodeAs("needle");
+  const auto *Haystack = Result.Nodes.getNodeAs("findexpr")
+ ->getImplicitObjectArgument();
+  const auto *FindFun = Result.Nodes.getNodeAs("findfun");
+
+  if (ComparisonExpr->getBeginLoc().isMacroID()) {
+return;
+  }
+
+  const auto Rev = FindFun->getName().contains("rfind");
+  const auto Neg = ComparisonExpr->getOpcode() == BO_NE;
+
+  const auto NeedleExprCode = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Needle->getSourceRange()), Source,
+  Context.getLangOpts());
+  const auto HaystackExprCode = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Haystack->getSourceRange()), Source,

PiotrZSL wrote:

only begin location

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


[clang] [clang][Interp] Implement IntegralAP::mul() (PR #72491)

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

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

None

>From 9d97134dc0d1b93ac5368f5014bf180317725175 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 16 Nov 2023 09:26:27 +0100
Subject: [PATCH] [clang][Interp] Implement IntegralAP::mul()

---
 clang/lib/AST/Interp/IntegralAP.h | 12 +---
 clang/test/AST/Interp/intap.cpp   | 16 
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index b8e37878ce2f848..b9d7eab331d27bd 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -191,17 +191,15 @@ template  class IntegralAP final {
   }
 
   static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-return CheckAddSubUB(A, B, OpBits, R);
+return CheckAddSubMulUB(A, B, OpBits, R);
   }
 
   static bool sub(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-return CheckAddSubUB(A, B, OpBits, R);
+return CheckAddSubMulUB(A, B, OpBits, R);
   }
 
   static bool mul(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-return false;
+return CheckAddSubMulUB(A, B, OpBits, R);
   }
 
   static bool rem(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
@@ -264,8 +262,8 @@ template  class IntegralAP final {
 
 private:
   template  class Op>
-  static bool CheckAddSubUB(const IntegralAP &A, const IntegralAP &B,
-unsigned BitWidth, IntegralAP *R) {
+  static bool CheckAddSubMulUB(const IntegralAP &A, const IntegralAP &B,
+   unsigned BitWidth, IntegralAP *R) {
 if constexpr (!Signed) {
   R->V = Op{}(A.V, B.V);
   return false;
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index c3cae9a64780d5c..f04a82af2736ca5 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -35,6 +35,15 @@ static_assert(UBitIntZero1 == 0, "");
 constexpr unsigned _BitInt(2) BI1 = 3u;
 static_assert(BI1 == 3, "");
 
+constexpr _BitInt(4) MulA = 5;
+constexpr _BitInt(4) MulB = 7;
+static_assert(MulA * MulB == 50, ""); // ref-error {{not an integral constant 
expression}} \
+  // ref-note {{value 35 is outside the 
range of representable values of type '_BitInt(4)'}} \
+  // expected-error {{not an integral 
constant expression}} \
+  // expected-note {{value 35 is outside 
the range of representable values of type '_BitInt(4)'}}
+static_assert(MulA * 5 == 25, "");
+static_assert(-1 * MulB == -7, "");
+
 namespace APCast {
   constexpr _BitInt(10) A = 1;
   constexpr _BitInt(11) B = A;
@@ -66,6 +75,8 @@ namespace i128 {
// ref-error {{static assertion 
failed}} \
// ref-note 
{{'340282366920938463463374607431768211455 == 1'}}
 
+  constexpr uint128_t TooMuch = UINT128_MAX * 2;
+
   static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
   static_assert(INT128_MAX != 0, "");
   static_assert(INT128_MAX == 0, ""); // expected-error {{failed}} \
@@ -73,6 +84,11 @@ namespace i128 {
   // ref-error {{failed}} \
   // ref-note {{evaluates to 
'170141183460469231731687303715884105727 == 0'}}
 
+  constexpr int128_t TooMuch2 = INT128_MAX * INT128_MAX; // ref-error {{must 
be initialized by a constant expression}} \
+// ref-note {{value 
28948022309329048855892746252171976962977213799489202546401021394546514198529 
is outside the range of representable}} \
+// expected-error {{must be 
initialized by a constant expression}} \
+// expected-note {{value 
28948022309329048855892746252171976962977213799489202546401021394546514198529 
is outside the range of representable}}
+
   static const __int128_t INT128_MIN = -INT128_MAX - 1;
   constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be 
initialized by a constant expression}} \
  // expected-note {{value 
170141183460469231731687303715884105728 is outside the range}} \

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


[clang] [clang][Interp] Implement IntegralAP::mul() (PR #72491)

2023-11-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


2 Files Affected:

- (modified) clang/lib/AST/Interp/IntegralAP.h (+5-7) 
- (modified) clang/test/AST/Interp/intap.cpp (+16) 


``diff
diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index b8e37878ce2f848..b9d7eab331d27bd 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -191,17 +191,15 @@ template  class IntegralAP final {
   }
 
   static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-return CheckAddSubUB(A, B, OpBits, R);
+return CheckAddSubMulUB(A, B, OpBits, R);
   }
 
   static bool sub(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-return CheckAddSubUB(A, B, OpBits, R);
+return CheckAddSubMulUB(A, B, OpBits, R);
   }
 
   static bool mul(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-return false;
+return CheckAddSubMulUB(A, B, OpBits, R);
   }
 
   static bool rem(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
@@ -264,8 +262,8 @@ template  class IntegralAP final {
 
 private:
   template  class Op>
-  static bool CheckAddSubUB(const IntegralAP &A, const IntegralAP &B,
-unsigned BitWidth, IntegralAP *R) {
+  static bool CheckAddSubMulUB(const IntegralAP &A, const IntegralAP &B,
+   unsigned BitWidth, IntegralAP *R) {
 if constexpr (!Signed) {
   R->V = Op{}(A.V, B.V);
   return false;
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index c3cae9a64780d5c..f04a82af2736ca5 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -35,6 +35,15 @@ static_assert(UBitIntZero1 == 0, "");
 constexpr unsigned _BitInt(2) BI1 = 3u;
 static_assert(BI1 == 3, "");
 
+constexpr _BitInt(4) MulA = 5;
+constexpr _BitInt(4) MulB = 7;
+static_assert(MulA * MulB == 50, ""); // ref-error {{not an integral constant 
expression}} \
+  // ref-note {{value 35 is outside the 
range of representable values of type '_BitInt(4)'}} \
+  // expected-error {{not an integral 
constant expression}} \
+  // expected-note {{value 35 is outside 
the range of representable values of type '_BitInt(4)'}}
+static_assert(MulA * 5 == 25, "");
+static_assert(-1 * MulB == -7, "");
+
 namespace APCast {
   constexpr _BitInt(10) A = 1;
   constexpr _BitInt(11) B = A;
@@ -66,6 +75,8 @@ namespace i128 {
// ref-error {{static assertion 
failed}} \
// ref-note 
{{'340282366920938463463374607431768211455 == 1'}}
 
+  constexpr uint128_t TooMuch = UINT128_MAX * 2;
+
   static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
   static_assert(INT128_MAX != 0, "");
   static_assert(INT128_MAX == 0, ""); // expected-error {{failed}} \
@@ -73,6 +84,11 @@ namespace i128 {
   // ref-error {{failed}} \
   // ref-note {{evaluates to 
'170141183460469231731687303715884105727 == 0'}}
 
+  constexpr int128_t TooMuch2 = INT128_MAX * INT128_MAX; // ref-error {{must 
be initialized by a constant expression}} \
+// ref-note {{value 
28948022309329048855892746252171976962977213799489202546401021394546514198529 
is outside the range of representable}} \
+// expected-error {{must be 
initialized by a constant expression}} \
+// expected-note {{value 
28948022309329048855892746252171976962977213799489202546401021394546514198529 
is outside the range of representable}}
+
   static const __int128_t INT128_MIN = -INT128_MAX - 1;
   constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be 
initialized by a constant expression}} \
  // expected-note {{value 
170141183460469231731687303715884105728 is outside the range}} \

``




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


[clang] [clang-format] Handle lambdas in QualifierAlignment (PR #72456)

2023-11-16 Thread Björn Schäpers via cfe-commits

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


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


[clang] aa4e34b - [clang][Interp] Implement bitwise operations for IntegralAP (#71807)

2023-11-16 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-11-16T09:31:24+01:00
New Revision: aa4e34bd814a7d34551ab2e88cb2c45e78ada442

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

LOG: [clang][Interp] Implement bitwise operations for IntegralAP (#71807)

Added: 


Modified: 
clang/lib/AST/Interp/IntegralAP.h
clang/test/AST/Interp/intap.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index b8e37878ce2f848..d85904a8f9572eb 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -218,21 +218,19 @@ template  class IntegralAP final {
 
   static bool bitAnd(IntegralAP A, IntegralAP B, unsigned OpBits,
  IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
+*R = IntegralAP(A.V & B.V);
 return false;
   }
 
   static bool bitOr(IntegralAP A, IntegralAP B, unsigned OpBits,
 IntegralAP *R) {
-assert(false);
+*R = IntegralAP(A.V | B.V);
 return false;
   }
 
   static bool bitXor(IntegralAP A, IntegralAP B, unsigned OpBits,
  IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
+*R = IntegralAP(A.V ^ B.V);
 return false;
   }
 

diff  --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index c3cae9a64780d5c..4a18f1f9459e301 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -172,4 +172,16 @@ namespace Bitfields {
 // expected-warning {{changes value from 100 to 0}}
 }
 
+namespace BitOps {
+  constexpr unsigned __int128 UZero = 0;
+  constexpr unsigned __int128 Max = ~UZero;
+  static_assert(Max == ~0, "");
+  static_assert((Max & 0) == 0, "");
+  static_assert((UZero | 0) == 0, "");
+  static_assert((Max ^ Max) == 0, "");
+  static_assert((Max & 1) == 1, "");
+  static_assert((UZero | 1) == 1, "");
+  static_assert((Max ^ UZero) == Max, "");
+}
+
 #endif



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


[clang] [clang][Interp] Implement bitwise operations for IntegralAP (PR #71807)

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

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


[clang] [clang][Interp] Diagnose reads from non-const global variables (PR #71919)

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

tbaederr wrote:

Ping

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


[clang] [clang] Add bitint classification for __builtin_classify_type (PR #72036)

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

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

>From ed41b0889b6da62fa30757ce185f516f3af1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 11 Nov 2023 18:44:13 +0100
Subject: [PATCH] [clang] Add bitint classification for __builtin_classify_type

See #71911
---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/lib/AST/ExprConstant.cpp   | 7 ++-
 clang/test/Sema/builtin-classify-type.c  | 5 -
 clang/test/SemaCXX/builtin-classify-type.cpp | 5 -
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed1a978b5382d71..e030f97ab662fdb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -219,6 +219,8 @@ Non-comprehensive list of changes in this release
   determined at runtime.
 * The ``__datasizeof`` keyword has been added. It is similar to ``sizeof``
   except that it returns the size of a type ignoring tail padding.
+* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the 
return value ``18``,
+  to match GCC 14's behavior.
 
 New Compiler Flags
 --
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 373972eb6cab11b..4fb444e3b9f7e1b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11520,6 +11520,9 @@ enum class GCCTypeClass {
   // decay to pointer. (Prior to version 6 it was only used in C++ mode).
   // GCC reserves 15 for strings, but actually uses 5 (pointer) for string
   // literals.
+  // Lang = 16,
+  // OpaqueType = 17,
+  BitInt = 18
 };
 
 /// EvaluateBuiltinClassifyType - Evaluate __builtin_classify_type the same way
@@ -11652,11 +11655,13 @@ EvaluateBuiltinClassifyType(QualType T, const 
LangOptions &LangOpts) {
   case Type::ObjCInterface:
   case Type::ObjCObjectPointer:
   case Type::Pipe:
-  case Type::BitInt:
 // GCC classifies vectors as None. We follow its lead and classify all
 // other types that don't fit into the regular classification the same way.
 return GCCTypeClass::None;
 
+  case Type::BitInt:
+return GCCTypeClass::BitInt;
+
   case Type::LValueReference:
   case Type::RValueReference:
 llvm_unreachable("invalid type for expression");
diff --git a/clang/test/Sema/builtin-classify-type.c 
b/clang/test/Sema/builtin-classify-type.c
index a222ac8af0e32fd..9a4de34e823f231 100644
--- a/clang/test/Sema/builtin-classify-type.c
+++ b/clang/test/Sema/builtin-classify-type.c
@@ -11,7 +11,8 @@ enum gcc_type_class {
   function_type_class, method_type_class,
   record_type_class, union_type_class,
   array_type_class, string_type_class,
-  lang_type_class
+  lang_type_class, opaque_type_class,
+  bitint_type_class
 };
 
 void foo(void) {
@@ -45,6 +46,7 @@ void foo(void) {
   vint32_t3 vt5;
   typedef _BitInt(64) vint64_t3 __attribute__((vector_size(16)));
   vint64_t3 vt6;
+  _BitInt(16) bitint;
 
   _Atomic int atomic_i;
   _Atomic double atomic_d;
@@ -70,6 +72,7 @@ void foo(void) {
   int a17[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
   int a18[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];
   int a19[__builtin_classify_type(complex_d) == complex_type_class ? 1 : -1];
+  int a20[__builtin_classify_type(bitint) == bitint_type_class ? 1 : -1];
 }
 
 extern int (^p)(void);
diff --git a/clang/test/SemaCXX/builtin-classify-type.cpp 
b/clang/test/SemaCXX/builtin-classify-type.cpp
index ebc81425e401f11..ed5430960001002 100644
--- a/clang/test/SemaCXX/builtin-classify-type.cpp
+++ b/clang/test/SemaCXX/builtin-classify-type.cpp
@@ -11,7 +11,8 @@ enum gcc_type_class {
   function_type_class, method_type_class,
   record_type_class, union_type_class,
   array_type_class, string_type_class,
-  lang_type_class
+  lang_type_class, opaque_type_class,
+  bitint_type_class
 };
 
 class cl {
@@ -42,6 +43,7 @@ void foo() {
   _Atomic double atomic_d;
   _Complex int complex_i;
   _Complex double complex_d;
+  _BitInt(32) bitint;
 
   int a1[__builtin_classify_type(f()) == void_type_class ? 1 : -1];
   int a2[__builtin_classify_type(i) == integer_type_class ? 1 : -1];
@@ -65,5 +67,6 @@ void foo() {
   int a20[__builtin_classify_type(atomic_d) == real_type_class ? 1 : -1];
   int a21[__builtin_classify_type(complex_i) == complex_type_class ? 1 : -1];
   int a22[__builtin_classify_type(complex_d) == complex_type_class ? 1 : -1];
+  int a23[__builtin_classify_type(bitint) == bitint_type_class ? 1 : -1];
 }
 

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


[clang] [Work-in-Progress][Clang][RISCV] Create supporting intrinsics around RVV BFloat16 type (PR #72463)

2023-11-16 Thread Yueh-Ting Chen via cfe-commits

https://github.com/eopXD updated https://github.com/llvm/llvm-project/pull/72463

>From 8a3db304250683dcd03cc56a5332d03ecdcff140 Mon Sep 17 00:00:00 2001
From: eopXD 
Date: Wed, 15 Nov 2023 18:10:54 -0800
Subject: [PATCH 1/2] [Clang][RISCV] Type alignment for the type recording
 required extensions. NFC

---
 clang/include/clang/Support/RISCVVIntrinsicUtils.h | 5 +++--
 clang/utils/TableGen/RISCVVEmitter.cpp | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 49ce32553da81eb..11eba8df5040550 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -485,7 +485,8 @@ class RVVIntrinsic {
 
 // RVVRequire should be sync'ed with target features, but only
 // required features used in riscv_vector.td.
-enum RVVRequire : uint16_t {
+using RVVRequireT = uint16_t;
+enum RVVRequire : RVVRequireT {
   RVV_REQ_None = 0,
   RVV_REQ_RV64 = 1 << 0,
   RVV_REQ_ZvfhminOrZvfh = 1 << 1,
@@ -536,7 +537,7 @@ struct RVVIntrinsicRecord {
   uint8_t OverloadedSuffixSize;
 
   // Required target features for this intrinsic.
-  uint16_t RequiredExtensions;
+  RVVRequireT RequiredExtensions;
 
   // Supported type, mask of BasicType.
   uint8_t TypeRangeMask;
diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index cf731e8414a3b83..0fd9009f679cedd 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -46,7 +46,7 @@ struct SemaRecord {
   unsigned Log2LMULMask;
 
   // Required extensions for this intrinsic.
-  unsigned RequiredExtensions;
+  RVVRequireT RequiredExtensions;
 
   // Prototype for this intrinsic.
   SmallVector Prototype;

>From f3bdd76d81cf07f0d240ebc1b2ace5a9dc8fa320 Mon Sep 17 00:00:00 2001
From: eopXD 
Date: Wed, 15 Nov 2023 19:24:54 -0800
Subject: [PATCH 2/2] [Clang][RISCV] Add vle16 intrinsic for RVV bfloat16 type

---
 clang/include/clang/Basic/riscv_vector.td |   2 +
 .../clang/Support/RISCVVIntrinsicUtils.h  |   5 +-
 clang/lib/Sema/SemaRISCVVectorLookup.cpp  |  10 ++
 .../non-policy/non-overloaded/vle16.c | 132 ++
 .../zvfbfmin-error.c  |  24 
 clang/utils/TableGen/RISCVVEmitter.cpp|   1 +
 6 files changed, 172 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/CodeGen/RISCV/bfloat16-intrinsics/non-policy/non-overloaded/vle16.c
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfbfmin-error.c

diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 682f1d5c8af68c0..3d245637096b68e 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -683,6 +683,8 @@ defm vle8: RVVVLEBuiltin<["c"]>;
 defm vle16: RVVVLEBuiltin<["s"]>;
 let Name = "vle16_v", RequiredFeatures = ["ZvfhminOrZvfh"] in
   defm vle16_h: RVVVLEBuiltin<["x"]>;
+let Name = "vle16_v", RequiredFeatures = ["Zvfbfmin"] in
+  defm vle16_b: RVVVLEBuiltin<["b"]>;
 defm vle32: RVVVLEBuiltin<["i","f"]>;
 defm vle64: RVVVLEBuiltin<["l","d"]>;
 
diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 11eba8df5040550..38a8e5970b4add3 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -485,7 +485,7 @@ class RVVIntrinsic {
 
 // RVVRequire should be sync'ed with target features, but only
 // required features used in riscv_vector.td.
-using RVVRequireT = uint16_t;
+using RVVRequireT = uint32_t;
 enum RVVRequire : RVVRequireT {
   RVV_REQ_None = 0,
   RVV_REQ_RV64 = 1 << 0,
@@ -504,8 +504,9 @@ enum RVVRequire : RVVRequireT {
   RVV_REQ_Zvknhb = 1 << 13,
   RVV_REQ_Zvksed = 1 << 14,
   RVV_REQ_Zvksh = 1 << 15,
+  RVV_REQ_Zvfbfmin = 1 << 16,
 
-  LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Zvksh)
+  LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Zvfbfmin)
 };
 
 // Raw RVV intrinsic info, used to expand later.
diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index 9a5aecf669a07df..536778c1d1ad179 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -288,6 +288,16 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
 }
   }
 
+  if (BaseType == BasicType::BFloat16) {
+if (Record.RequiredExtensions & RVV_REQ_Zvfbfmin) {
+  if (!TI.hasFeature("experimental-zvfbfmin"))
+continue;
+} else {
+  llvm_unreachable_internal(
+  "Non-basic BFloat16 intrinsics are not implemented yet.");
+}
+  }
+
   // Expanded with different LMUL.
   for (int Log2LMUL = -3; Log2LMUL <= 3; Log2LMUL++) {
 if (!(Record.Log2LMULMask & (1 << (Log2LMUL + 3
diff --git 
a/clang/test/C

[clang] [Work-in-Progress][Clang][RISCV] Create supporting intrinsics around RVV BFloat16 type (PR #72463)

2023-11-16 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 aa4e34bd814a7d34551ab2e88cb2c45e78ada442 
f3bdd76d81cf07f0d240ebc1b2ace5a9dc8fa320 -- 
clang/test/CodeGen/RISCV/bfloat16-intrinsics/non-policy/non-overloaded/vle16.c 
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfbfmin-error.c 
clang/include/clang/Support/RISCVVIntrinsicUtils.h 
clang/lib/Sema/SemaRISCVVectorLookup.cpp clang/utils/TableGen/RISCVVEmitter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index c225934df8..e6a503243c 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -656,25 +656,26 @@ void RVVEmitter::createRVVIntrinsics(
 
 SR.RequiredExtensions = 0;
 for (auto RequiredFeature : RequiredFeatures) {
-  RVVRequire RequireExt = StringSwitch(RequiredFeature)
-  .Case("RV64", RVV_REQ_RV64)
-  .Case("ZvfhminOrZvfh", RVV_REQ_ZvfhminOrZvfh)
-  .Case("Xsfvcp", RVV_REQ_Xsfvcp)
-  .Case("Xsfvfnrclipxfqf", 
RVV_REQ_Xsfvfnrclipxfqf)
-  .Case("Xsfvfwmaccqqq", RVV_REQ_Xsfvfwmaccqqq)
-  .Case("Xsfvqmaccdod", RVV_REQ_Xsfvqmaccdod)
-  .Case("Xsfvqmaccqoq", RVV_REQ_Xsfvqmaccqoq)
-  .Case("Zvbb", RVV_REQ_Zvbb)
-  .Case("Zvbc", RVV_REQ_Zvbc)
-  .Case("Zvkb", RVV_REQ_Zvkb)
-  .Case("Zvkg", RVV_REQ_Zvkg)
-  .Case("Zvkned", RVV_REQ_Zvkned)
-  .Case("Zvknha", RVV_REQ_Zvknha)
-  .Case("Zvknhb", RVV_REQ_Zvknhb)
-  .Case("Zvksed", RVV_REQ_Zvksed)
-  .Case("Zvksh", RVV_REQ_Zvksh)
-  .Case("Zvfbfmin", RVV_REQ_Zvfbfmin)
-  .Default(RVV_REQ_None);
+  RVVRequire RequireExt =
+  StringSwitch(RequiredFeature)
+  .Case("RV64", RVV_REQ_RV64)
+  .Case("ZvfhminOrZvfh", RVV_REQ_ZvfhminOrZvfh)
+  .Case("Xsfvcp", RVV_REQ_Xsfvcp)
+  .Case("Xsfvfnrclipxfqf", RVV_REQ_Xsfvfnrclipxfqf)
+  .Case("Xsfvfwmaccqqq", RVV_REQ_Xsfvfwmaccqqq)
+  .Case("Xsfvqmaccdod", RVV_REQ_Xsfvqmaccdod)
+  .Case("Xsfvqmaccqoq", RVV_REQ_Xsfvqmaccqoq)
+  .Case("Zvbb", RVV_REQ_Zvbb)
+  .Case("Zvbc", RVV_REQ_Zvbc)
+  .Case("Zvkb", RVV_REQ_Zvkb)
+  .Case("Zvkg", RVV_REQ_Zvkg)
+  .Case("Zvkned", RVV_REQ_Zvkned)
+  .Case("Zvknha", RVV_REQ_Zvknha)
+  .Case("Zvknhb", RVV_REQ_Zvknhb)
+  .Case("Zvksed", RVV_REQ_Zvksed)
+  .Case("Zvksh", RVV_REQ_Zvksh)
+  .Case("Zvfbfmin", RVV_REQ_Zvfbfmin)
+  .Default(RVV_REQ_None);
   assert(RequireExt != RVV_REQ_None && "Unrecognized required feature?");
   SR.RequiredExtensions |= RequireExt;
 }

``




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


[clang] [Work-in-Progress][Clang][RISCV] Create supporting intrinsics around RVV BFloat16 type (PR #72463)

2023-11-16 Thread Yueh-Ting Chen via cfe-commits

https://github.com/eopXD updated https://github.com/llvm/llvm-project/pull/72463

>From 8a3db304250683dcd03cc56a5332d03ecdcff140 Mon Sep 17 00:00:00 2001
From: eopXD 
Date: Wed, 15 Nov 2023 18:10:54 -0800
Subject: [PATCH 1/2] [Clang][RISCV] Type alignment for the type recording
 required extensions. NFC

---
 clang/include/clang/Support/RISCVVIntrinsicUtils.h | 5 +++--
 clang/utils/TableGen/RISCVVEmitter.cpp | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 49ce32553da81eb..11eba8df5040550 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -485,7 +485,8 @@ class RVVIntrinsic {
 
 // RVVRequire should be sync'ed with target features, but only
 // required features used in riscv_vector.td.
-enum RVVRequire : uint16_t {
+using RVVRequireT = uint16_t;
+enum RVVRequire : RVVRequireT {
   RVV_REQ_None = 0,
   RVV_REQ_RV64 = 1 << 0,
   RVV_REQ_ZvfhminOrZvfh = 1 << 1,
@@ -536,7 +537,7 @@ struct RVVIntrinsicRecord {
   uint8_t OverloadedSuffixSize;
 
   // Required target features for this intrinsic.
-  uint16_t RequiredExtensions;
+  RVVRequireT RequiredExtensions;
 
   // Supported type, mask of BasicType.
   uint8_t TypeRangeMask;
diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index cf731e8414a3b83..0fd9009f679cedd 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -46,7 +46,7 @@ struct SemaRecord {
   unsigned Log2LMULMask;
 
   // Required extensions for this intrinsic.
-  unsigned RequiredExtensions;
+  RVVRequireT RequiredExtensions;
 
   // Prototype for this intrinsic.
   SmallVector Prototype;

>From 554283f5ab88c62ce0410fe795a48939db11a229 Mon Sep 17 00:00:00 2001
From: eopXD 
Date: Thu, 16 Nov 2023 00:47:11 -0800
Subject: [PATCH 2/2] [Clang][RISCV] Add vle16 intrinsic for RVV bfloat16 type

---
 clang/include/clang/Basic/riscv_vector.td |   2 +
 .../clang/Support/RISCVVIntrinsicUtils.h  |   5 +-
 clang/lib/Sema/SemaRISCVVectorLookup.cpp  |  10 ++
 .../non-policy/non-overloaded/vle16.c | 132 ++
 .../zvfbfmin-error.c  |  24 
 clang/utils/TableGen/RISCVVEmitter.cpp|  38 ++---
 6 files changed, 191 insertions(+), 20 deletions(-)
 create mode 100644 
clang/test/CodeGen/RISCV/bfloat16-intrinsics/non-policy/non-overloaded/vle16.c
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfbfmin-error.c

diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 682f1d5c8af68c0..3d245637096b68e 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -683,6 +683,8 @@ defm vle8: RVVVLEBuiltin<["c"]>;
 defm vle16: RVVVLEBuiltin<["s"]>;
 let Name = "vle16_v", RequiredFeatures = ["ZvfhminOrZvfh"] in
   defm vle16_h: RVVVLEBuiltin<["x"]>;
+let Name = "vle16_v", RequiredFeatures = ["Zvfbfmin"] in
+  defm vle16_b: RVVVLEBuiltin<["b"]>;
 defm vle32: RVVVLEBuiltin<["i","f"]>;
 defm vle64: RVVVLEBuiltin<["l","d"]>;
 
diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 11eba8df5040550..38a8e5970b4add3 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -485,7 +485,7 @@ class RVVIntrinsic {
 
 // RVVRequire should be sync'ed with target features, but only
 // required features used in riscv_vector.td.
-using RVVRequireT = uint16_t;
+using RVVRequireT = uint32_t;
 enum RVVRequire : RVVRequireT {
   RVV_REQ_None = 0,
   RVV_REQ_RV64 = 1 << 0,
@@ -504,8 +504,9 @@ enum RVVRequire : RVVRequireT {
   RVV_REQ_Zvknhb = 1 << 13,
   RVV_REQ_Zvksed = 1 << 14,
   RVV_REQ_Zvksh = 1 << 15,
+  RVV_REQ_Zvfbfmin = 1 << 16,
 
-  LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Zvksh)
+  LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Zvfbfmin)
 };
 
 // Raw RVV intrinsic info, used to expand later.
diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index 9a5aecf669a07df..536778c1d1ad179 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -288,6 +288,16 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
 }
   }
 
+  if (BaseType == BasicType::BFloat16) {
+if (Record.RequiredExtensions & RVV_REQ_Zvfbfmin) {
+  if (!TI.hasFeature("experimental-zvfbfmin"))
+continue;
+} else {
+  llvm_unreachable_internal(
+  "Non-basic BFloat16 intrinsics are not implemented yet.");
+}
+  }
+
   // Expanded with different LMUL.
   for (int Log2LMUL = -3; Log2LMUL <= 3; Log2LMUL++) {
 if (!(Record.Log2LMULMask & (1 << (Log2LMUL + 3
diff --git 
a/clang/t

[llvm] [clang-tools-extra] [PowerPC] Combine sub within setcc back to sext (PR #66978)

2023-11-16 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/66978

>From 2a7b9be6cd0705590c85c51b35ea99fe053aaf47 Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Wed, 6 Sep 2023 16:16:34 +0800
Subject: [PATCH 1/2] [PowerPC] Combine sub within setcc back to sext

---
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 37 +-
 llvm/test/CodeGen/PowerPC/setcc-to-sub.ll   | 42 +
 2 files changed, 69 insertions(+), 10 deletions(-)

diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp 
b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index f4e3531980d165f..4659ebef35ecf62 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -14407,15 +14407,18 @@ SDValue 
PPCTargetLowering::DAGCombineExtBoolTrunc(SDNode *N,
   ShiftCst);
 }
 
-SDValue PPCTargetLowering::combineSetCC(SDNode *N,
-DAGCombinerInfo &DCI) const {
-  assert(N->getOpcode() == ISD::SETCC &&
- "Should be called with a SETCC node");
+SDValue PPCTargetLowering::combineSetCC(SDNode *N, DAGCombinerInfo &DCI) const 
{
+  assert(N->getOpcode() == ISD::SETCC && "Should be called with a SETCC node");
 
   ISD::CondCode CC = cast(N->getOperand(2))->get();
+  SDValue LHS = N->getOperand(0);
+  SDValue RHS = N->getOperand(1);
+  SDLoc DL(N);
+  SelectionDAG &DAG = DCI.DAG;
+  EVT VT = N->getValueType(0);
+  EVT OpVT = LHS.getValueType();
+
   if (CC == ISD::SETNE || CC == ISD::SETEQ) {
-SDValue LHS = N->getOperand(0);
-SDValue RHS = N->getOperand(1);
 
 // If there is a '0 - y' pattern, canonicalize the pattern to the RHS.
 if (LHS.getOpcode() == ISD::SUB && isNullConstant(LHS.getOperand(0)) &&
@@ -14426,15 +14429,29 @@ SDValue PPCTargetLowering::combineSetCC(SDNode *N,
 // x != 0-y --> x+y != 0
 if (RHS.getOpcode() == ISD::SUB && isNullConstant(RHS.getOperand(0)) &&
 RHS.hasOneUse()) {
-  SDLoc DL(N);
-  SelectionDAG &DAG = DCI.DAG;
-  EVT VT = N->getValueType(0);
-  EVT OpVT = LHS.getValueType();
   SDValue Add = DAG.getNode(ISD::ADD, DL, OpVT, LHS, RHS.getOperand(1));
   return DAG.getSetCC(DL, VT, Add, DAG.getConstant(0, DL, OpVT), CC);
 }
   }
 
+  // Combine (a-2^(M-1)) => sext(trunc(a, M), 64)
+  if (CC == ISD::SETULT && LHS.getOpcode() == ISD::ADD && OpVT == MVT::i64 &&
+  isa(RHS) && isa(LHS.getOperand(1))) {
+uint64_t ShiftVal =
+~(cast(LHS.getOperand(1))->getZExtValue()) + 1;
+uint64_t CmpVal = ~(cast(RHS)->getZExtValue()) + 1;
+if (isPowerOf2_64(ShiftVal) && ShiftVal << 1 == CmpVal) {
+  unsigned DestBits = Log2_64(CmpVal);
+  if (DestBits == 8 || DestBits == 16 || DestBits == 32) {
+SDValue Conv =
+DAG.getSExtOrTrunc(DAG.getSExtOrTrunc(LHS.getOperand(0), DL,
+  MVT::getIntegerVT(DestBits)),
+   DL, OpVT);
+return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
+  }
+}
+  }
+
   return DAGCombineTruncBoolExt(N, DCI);
 }
 
diff --git a/llvm/test/CodeGen/PowerPC/setcc-to-sub.ll 
b/llvm/test/CodeGen/PowerPC/setcc-to-sub.ll
index 13c629b6349450c..ce75b77eed29666 100644
--- a/llvm/test/CodeGen/PowerPC/setcc-to-sub.ll
+++ b/llvm/test/CodeGen/PowerPC/setcc-to-sub.ll
@@ -89,6 +89,48 @@ entry:
   ret i1 %cmp.i5
 }
 
+define zeroext i1 @test5(i64 %a) {
+; CHECK-LABEL: test5:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:extsw 4, 3
+; CHECK-NEXT:xor 3, 3, 4
+; CHECK-NEXT:addic 4, 3, -1
+; CHECK-NEXT:subfe 3, 4, 3
+; CHECK-NEXT:blr
+entry:
+  %0 = add i64 %a, -2147483648
+  %cmp = icmp ult i64 %0, -4294967296
+  ret i1 %cmp
+}
+
+define zeroext i1 @test6(i64 %a) {
+; CHECK-LABEL: test6:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:extsh 4, 3
+; CHECK-NEXT:xor 3, 3, 4
+; CHECK-NEXT:addic 4, 3, -1
+; CHECK-NEXT:subfe 3, 4, 3
+; CHECK-NEXT:blr
+entry:
+  %0 = add i64 %a, -32768
+  %cmp = icmp ult i64 %0, -65536
+  ret i1 %cmp
+}
+
+define zeroext i1 @test7(i64 %a) {
+; CHECK-LABEL: test7:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:extsb 4, 3
+; CHECK-NEXT:xor 3, 3, 4
+; CHECK-NEXT:addic 4, 3, -1
+; CHECK-NEXT:subfe 3, 4, 3
+; CHECK-NEXT:blr
+entry:
+  %0 = add i64 %a, -128
+  %cmp = icmp ult i64 %0, -256
+  ret i1 %cmp
+}
+
 !1 = !{!2, !2, i64 0}
 !2 = !{!"int", !3, i64 0}
 !3 = !{!"omnipotent char", !4, i64 0}

>From fbb7e6362d6223f8e0ee6014e000c1cc5ae6e777 Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Wed, 6 Sep 2023 16:16:34 +0800
Subject: [PATCH 2/2] [PowerPC] Combine sub within setcc back to sext

---
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 37 +-
 llvm/test/CodeGen/PowerPC/setcc-to-sub.ll   | 42 +
 2 files changed, 69 insertions(+), 10 deletions(-)

diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp 
b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index f4e3531980d165f..4659

[clang-tools-extra] c95d581 - [clang-tidy] bugprone-assert-side-effect non-const operator methods (#71974)

2023-11-16 Thread via cfe-commits

Author: schenker
Date: 2023-11-16T09:53:40+01:00
New Revision: c95d5813b823bbb61cd7d676b959e64754098f49

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

LOG: [clang-tidy] bugprone-assert-side-effect non-const operator methods 
(#71974)

With this PR, `bugprone-assert-side-effect` reports non-const calls to
`<<` and `>>` operators and does no longer consider any const operator
calls to have side effects.

E.g. the following snippet is now reported and was previously not:
```
std::stringstream ss;
assert(ss << 1);
```

The following snippet was previously a false-positive and is not
reported anymore:
```
struct {
  int operator+=(int i) const { return i; }
} t;
assert(t += 1);
```

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 07a987359d4d8d7..43bedd4f73ef447 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -41,12 +41,18 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, 
CheckFunctionCalls,
   }
 
   if (const auto *OpCallExpr = dyn_cast(E)) {
+if (const auto *MethodDecl =
+dyn_cast_or_null(OpCallExpr->getDirectCallee()))
+  if (MethodDecl->isConst())
+return false;
+
 OverloadedOperatorKind OpKind = OpCallExpr->getOperator();
 return OpKind == OO_Equal || OpKind == OO_PlusEqual ||
OpKind == OO_MinusEqual || OpKind == OO_StarEqual ||
OpKind == OO_SlashEqual || OpKind == OO_AmpEqual ||
OpKind == OO_PipeEqual || OpKind == OO_CaretEqual ||
OpKind == OO_LessLessEqual || OpKind == OO_GreaterGreaterEqual ||
+   OpKind == OO_LessLess || OpKind == OO_GreaterGreater ||
OpKind == OO_PlusPlus || OpKind == OO_MinusMinus ||
OpKind == OO_PercentEqual || OpKind == OO_New ||
OpKind == OO_Delete || OpKind == OO_Array_New ||

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 353c6fe20269274..23111be4371e2e1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -212,6 +212,11 @@ Changes in existing checks
   ` check to also consider
   ``std::basic_string_view`` in addition to ``std::basic_string`` by default.
 
+- Improved :doc:`bugprone-assert-side-effect
+  ` check to report usage of
+  non-const ``<<`` and ``>>`` operators in assertions and fixed some 
false-positives
+  with const operators.
+
 - Improved :doc:`bugprone-dangling-handle
   ` check to support functional
   casting during type conversions at variable initialization, now with improved

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
index 6c41e1e320adeac..c11638aa823aaeb 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assert-side-effect.cpp
@@ -84,5 +84,27 @@ int main() {
   msvc_assert(mc2 = mc);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in msvc_assert() 
condition discarded in release builds
 
+  struct OperatorTest {
+int operator<<(int i) const { return i; }
+int operator<<(int i) { return i; }
+int operator+=(int i) const { return i; }
+int operator+=(int i) { return i; }
+  };
+
+  const OperatorTest const_instance;
+  assert(const_instance << 1);
+  assert(const_instance += 1);
+
+  OperatorTest non_const_instance;
+  assert(static_cast(non_const_instance) << 1);
+  assert(static_cast(non_const_instance) += 1);
+  assert(non_const_instance << 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
+  assert(non_const_instance += 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() 
condition discarded in release builds
+
+  assert(5<<1);
+  assert(5>>1);
+
   return 0;
 }



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


[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

2023-11-16 Thread Piotr Zegar via cfe-commits

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


[clang] [Work-in-Progress][Clang][RISCV] Create supporting intrinsics around RVV BFloat16 type (PR #72463)

2023-11-16 Thread Yueh-Ting Chen via cfe-commits

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


[llvm] [clang] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-16 Thread David Spickett via cfe-commits


@@ -0,0 +1,35 @@
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 
-save-temps=obj -S -o - %s | FileCheck %s
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m55 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s

DavidSpickett wrote:

I presume without this fix, this command would fail because it fails to build 
the object?

If so a comment here would be good, otherwise they look like mistakes as they 
are RUNs without CHECKs. I'd also put them first, then a blank line, then the 
RUN + FileCheck lines, just to make it even clearer.

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


[llvm] [clang] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-16 Thread David Spickett via cfe-commits


@@ -0,0 +1,35 @@
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 
-save-temps=obj -S -o - %s | FileCheck %s

DavidSpickett wrote:

Should there be an m55 test for this as well, as you've got 55 and 85 for 
save-temps.

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


[llvm] [clang] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-16 Thread David Spickett via cfe-commits


@@ -0,0 +1,35 @@
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 
-save-temps=obj -S -o - %s | FileCheck %s
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m55 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s
+
+// REQUIRES: arm-registered-target
+
+// CHECK: .fpu   fpv5-d16
+// CHECK-NEXT  .arch_extension mve.fp
+
+#define DUMMY_CONST_1 (0.0012345F)
+#define DUMMY_CONST_2 (0.01F)
+#define DUMMY_CONST_3 (0.02F)
+#define DUMMY_CONST_4 (0.03F)
+#define DUMMY_CONST_5 (0.04F)

DavidSpickett wrote:

I get defining DUMMY_CONST_1 but it seems you could just write the values of 
the others in `foo`.

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


[llvm] [clang] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-16 Thread David Spickett via cfe-commits

DavidSpickett wrote:

Just small things on the test case from me. Nominate @davemgreen to give it a 
final check and approval, since I have not been around this area in a while.

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


[clang] [Clang][Sema] Differentiate between partial/explicit specializations when diagnosing unexpanded packs (PR #72015)

2023-11-16 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

@erichkeane Unless you would like someone else to review this, could you please 
merge this when you have time? I don't have write access 🙂

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


[clang] 979eb55 - [Clang][Sema] Differentiate between partial/explicit specializations when diagnosing unexpanded packs (#72015)

2023-11-16 Thread via cfe-commits

Author: Krystian Stasiowski
Date: 2023-11-16T10:46:44+01:00
New Revision: 979eb558dd7c203be10fa24ab2b0d7cb93c3443b

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

LOG: [Clang][Sema] Differentiate between partial/explicit specializations when 
diagnosing unexpanded packs (#72015)

This adds `UnexpandedParameterPackContext::UPPC_ExplicitSpecialization`
and passes it to `DiagnoseUnexpandedParameterPack` when checking
class/variable template explicit specializations.

Right now we don't check for unexpanded packs in function template
explicit specializations at all, so I will be addressing that in a
followup PR.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f9dec60cf990784..a9dde041bc22a6d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5655,9 +5655,9 @@ def err_unexpanded_parameter_pack : Error<
   "%select{expression|base type|declaration type|data member type|bit-field "
   "size|static assertion|fixed underlying type|enumerator value|"
   "using declaration|friend declaration|qualifier|initializer|default 
argument|"
-  "non-type template parameter type|exception type|partial specialization|"
-  "__if_exists name|__if_not_exists name|lambda|block|type constraint|"
-  "requirement|requires clause}0 "
+  "non-type template parameter type|exception type|explicit specialization|"
+  "partial specialization|__if_exists name|__if_not_exists name|lambda|block|"
+  "type constraint|requirement|requires clause}0 "
   "contains%plural{0: an|:}1 unexpanded parameter pack"
   "%plural{0:|1: %2|2:s %2 and %3|:s %2, %3, ...}1">;
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a35a3c2c26c22ad..731d0886a7367dc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8842,6 +8842,9 @@ class Sema final {
 /// The type of an exception.
 UPPC_ExceptionType,
 
+/// Explicit specialization.
+UPPC_ExplicitSpecialization,
+
 /// Partial specialization.
 UPPC_PartialSpecialization,
 

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 6865e04b94b2050..766ebd90fded0c4 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4559,7 +4559,9 @@ DeclResult Sema::ActOnVarTemplateSpecialization(
   // Check for unexpanded parameter packs in any of the template arguments.
   for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
 if (DiagnoseUnexpandedParameterPack(TemplateArgs[I],
-UPPC_PartialSpecialization))
+IsPartialSpecialization
+? UPPC_PartialSpecialization
+: UPPC_ExplicitSpecialization))
   return true;
 
   // Check that the template argument list is well-formed for this
@@ -8744,7 +8746,9 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
   // Check for unexpanded parameter packs in any of the template arguments.
   for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
 if (DiagnoseUnexpandedParameterPack(TemplateArgs[I],
-UPPC_PartialSpecialization))
+isPartialSpecialization
+? UPPC_PartialSpecialization
+: UPPC_ExplicitSpecialization))
   return true;
 
   // Check that the template argument list is well-formed for this

diff  --git a/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp 
b/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
index 7536339c14a2e08..30ce6b40e1fb5f0 100644
--- a/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
@@ -369,9 +369,39 @@ void test_unexpanded_exprs(Types ...values) {
   void f(int arg = values); // expected-error{{default argument contains 
unexpanded parameter pack 'values'}}
 }
 
-// Test unexpanded parameter packs in partial specializations.
-template
-struct TestUnexpandedDecls; // expected-error{{partial 
specialization contains unexpanded parameter pack 'Types'}}
+// Test unexpanded parameter packs in partial/explicit specializations.
+namespace Specializations {
+  template
+  struct PrimaryClass;
+  template
+  struct PrimaryClass; // expected-error{{partial specialization contains 
unexpanded parameter pack 'Ts'}}
+
+#

[clang] [Clang][Sema] Differentiate between partial/explicit specializations when diagnosing unexpanded packs (PR #72015)

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

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


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

2023-11-16 Thread via cfe-commits


@@ -266,13 +266,18 @@ void CheckUseZeroAllocated1(void) {
 }
 
 char CheckUseZeroAllocated2(void) {
+  // FIXME: The return value of `alloca()` is modeled with `AllocaRegion`
+  // instead of `SymbolicRegion`, so the current implementation of
+  // `MallocChecker::checkUseZeroAllocated()` cannot handle it; and we get an
+  // unrelated, but suitable warning from core.uninitialized.UndefReturn.
   char *p = alloca(0);
-  return *p; // expected-warning {{Use of memory allocated with size zero}}
+  return *p; // expected-warning {{Undefined or garbage value returned to 
caller}}

DonatNagyE wrote:

Ok, I'll test that.

Unfortunately this "allocated with size zero" report is based on the private 
"Symbol -> state enum" map that's maintained by MallocChecker (so it's 
independent of the dynamic extent). I'd guess that switching to dynamic extent 
wouldn't be too difficult and it could simplify the code, but I think that 
belongs to a separate commit.

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


[libunwind] [lld] [lldb] [clang] [clang-tools-extra] [compiler-rt] [llvm] [flang] [libcxx] [AMDGPU] - Add constant folding for s_quadmask (PR #72381)

2023-11-16 Thread Jessica Del via cfe-commits

https://github.com/OutOfCache updated 
https://github.com/llvm/llvm-project/pull/72381

>From 00d0f99207242befc8022031ccd8faf573cbf014 Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Tue, 14 Nov 2023 22:17:26 +0100
Subject: [PATCH 1/2] [AMDGPU] - Add constant folding for s_quadmask

If the input is a constant we can constant fold the `s_quadmask`
intrinsic.
---
 llvm/lib/Analysis/ConstantFolding.cpp| 14 ++
 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll | 12 
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 966a65ac26b8017..40b5938fcda0c2a 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1533,6 +1533,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, 
const Function *F) {
   case Intrinsic::amdgcn_perm:
   case Intrinsic::amdgcn_wave_reduce_umin:
   case Intrinsic::amdgcn_wave_reduce_umax:
+  case Intrinsic::amdgcn_s_quadmask:
   case Intrinsic::arm_mve_vctp8:
   case Intrinsic::arm_mve_vctp16:
   case Intrinsic::arm_mve_vctp32:
@@ -2422,6 +2423,19 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
 
   return ConstantFP::get(Ty->getContext(), Val);
 }
+
+case Intrinsic::amdgcn_s_quadmask: {
+  uint64_t Val = Op->getZExtValue();
+  uint64_t QuadMask = 0;
+  for (unsigned i = 0; i < Op->getBitWidth() / 4; ++i, Val >>= 4) {
+if (!(Val & 0xF))
+  continue;
+
+QuadMask |= (1 << i);
+  }
+  return ConstantInt::get(Ty, QuadMask);
+}
+
 default:
   return nullptr;
 }
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
index 65443a6efa789d9..0f500c0999ad9a8 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
@@ -9,11 +9,10 @@ define i32 @test_quadmask_constant_i32() {
 ; GFX11-LABEL: test_quadmask_constant_i32:
 ; GFX11:   ; %bb.0: ; %entry
 ; GFX11-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX11-NEXT:s_quadmask_b32 s0, 0x85fe3a92
-; GFX11-NEXT:v_mov_b32_e32 v0, s0
+; GFX11-NEXT:v_mov_b32_e32 v0, 0xcb
 ; GFX11-NEXT:s_setpc_b64 s[30:31]
 entry:
-  %qm = call i32 @llvm.amdgcn.s.quadmask.i32(i32 u0x85FE3A92)
+  %qm = call i32 @llvm.amdgcn.s.quadmask.i32(i32 u0x85003092)
   ret i32 %qm
 }
 
@@ -50,13 +49,10 @@ define i64 @test_quadmask_constant_i64() {
 ; GFX11-LABEL: test_quadmask_constant_i64:
 ; GFX11:   ; %bb.0: ; %entry
 ; GFX11-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX11-NEXT:s_mov_b32 s0, 0x85fe3a92
-; GFX11-NEXT:s_mov_b32 s1, 0x67de48fc
-; GFX11-NEXT:s_quadmask_b64 s[0:1], s[0:1]
-; GFX11-NEXT:v_dual_mov_b32 v0, s0 :: v_dual_mov_b32 v1, s1
+; GFX11-NEXT:v_dual_mov_b32 v0, 0xe3e6 :: v_dual_mov_b32 v1, 0
 ; GFX11-NEXT:s_setpc_b64 s[30:31]
 entry:
-  %qm = call i64 @llvm.amdgcn.s.quadmask.i64(i64 u0x67DE48FC85FE3A92)
+  %qm = call i64 @llvm.amdgcn.s.quadmask.i64(i64 u0x67D000FC85F00A90)
   ret i64 %qm
 }
 

>From 144c4dc164ec137e518cfd647c116373e7a61b8f Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Wed, 15 Nov 2023 15:59:56 +0100
Subject: [PATCH 2/2] fixup! [AMDGPU] - Add constant folding for s_quadmask

---
 llvm/lib/Analysis/ConstantFolding.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 40b5938fcda0c2a..39bbb04fbcf26cc 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2427,11 +2427,11 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
 case Intrinsic::amdgcn_s_quadmask: {
   uint64_t Val = Op->getZExtValue();
   uint64_t QuadMask = 0;
-  for (unsigned i = 0; i < Op->getBitWidth() / 4; ++i, Val >>= 4) {
+  for (unsigned I = 0; I < Op->getBitWidth() / 4; ++I, Val >>= 4) {
 if (!(Val & 0xF))
   continue;
 
-QuadMask |= (1 << i);
+QuadMask |= (1 << I);
   }
   return ConstantInt::get(Ty, QuadMask);
 }

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


[libcxx] [lld] [compiler-rt] [clang-tools-extra] [flang] [libunwind] [clang] [lldb] [llvm] [AMDGPU] - Add constant folding for s_quadmask (PR #72381)

2023-11-16 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 979eb558dd7c203be10fa24ab2b0d7cb93c3443b 
3302aaf961982c5c32d692fb813fa25ad7ea33d4 -- 
llvm/lib/Analysis/ConstantFolding.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 64d088ea7a..33f7b85e16 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2425,7 +2425,6 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
   return ConstantFP::get(Ty->getContext(), Val);
 }
 
-
 case Intrinsic::amdgcn_s_quadmask: {
   uint64_t Val = Op->getZExtValue();
   uint64_t QuadMask = 0;
@@ -2446,7 +2445,6 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
   Val = (Val & 0xULL) | (Val & 0xULL) << 1;
   Val = Val | Val << 1;
   return ConstantInt::get(Ty, Val);
-
 }
 
 default:

``




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


[clang-tools-extra] [libunwind] [libcxx] [llvm] [compiler-rt] [lld] [lldb] [clang] [flang] [AMDGPU] - Add constant folding for s_quadmask (PR #72381)

2023-11-16 Thread Jessica Del via cfe-commits

https://github.com/OutOfCache updated 
https://github.com/llvm/llvm-project/pull/72381

>From 00d0f99207242befc8022031ccd8faf573cbf014 Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Tue, 14 Nov 2023 22:17:26 +0100
Subject: [PATCH 1/3] [AMDGPU] - Add constant folding for s_quadmask

If the input is a constant we can constant fold the `s_quadmask`
intrinsic.
---
 llvm/lib/Analysis/ConstantFolding.cpp| 14 ++
 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll | 12 
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 966a65ac26b8017..40b5938fcda0c2a 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1533,6 +1533,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, 
const Function *F) {
   case Intrinsic::amdgcn_perm:
   case Intrinsic::amdgcn_wave_reduce_umin:
   case Intrinsic::amdgcn_wave_reduce_umax:
+  case Intrinsic::amdgcn_s_quadmask:
   case Intrinsic::arm_mve_vctp8:
   case Intrinsic::arm_mve_vctp16:
   case Intrinsic::arm_mve_vctp32:
@@ -2422,6 +2423,19 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
 
   return ConstantFP::get(Ty->getContext(), Val);
 }
+
+case Intrinsic::amdgcn_s_quadmask: {
+  uint64_t Val = Op->getZExtValue();
+  uint64_t QuadMask = 0;
+  for (unsigned i = 0; i < Op->getBitWidth() / 4; ++i, Val >>= 4) {
+if (!(Val & 0xF))
+  continue;
+
+QuadMask |= (1 << i);
+  }
+  return ConstantInt::get(Ty, QuadMask);
+}
+
 default:
   return nullptr;
 }
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
index 65443a6efa789d9..0f500c0999ad9a8 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
@@ -9,11 +9,10 @@ define i32 @test_quadmask_constant_i32() {
 ; GFX11-LABEL: test_quadmask_constant_i32:
 ; GFX11:   ; %bb.0: ; %entry
 ; GFX11-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX11-NEXT:s_quadmask_b32 s0, 0x85fe3a92
-; GFX11-NEXT:v_mov_b32_e32 v0, s0
+; GFX11-NEXT:v_mov_b32_e32 v0, 0xcb
 ; GFX11-NEXT:s_setpc_b64 s[30:31]
 entry:
-  %qm = call i32 @llvm.amdgcn.s.quadmask.i32(i32 u0x85FE3A92)
+  %qm = call i32 @llvm.amdgcn.s.quadmask.i32(i32 u0x85003092)
   ret i32 %qm
 }
 
@@ -50,13 +49,10 @@ define i64 @test_quadmask_constant_i64() {
 ; GFX11-LABEL: test_quadmask_constant_i64:
 ; GFX11:   ; %bb.0: ; %entry
 ; GFX11-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX11-NEXT:s_mov_b32 s0, 0x85fe3a92
-; GFX11-NEXT:s_mov_b32 s1, 0x67de48fc
-; GFX11-NEXT:s_quadmask_b64 s[0:1], s[0:1]
-; GFX11-NEXT:v_dual_mov_b32 v0, s0 :: v_dual_mov_b32 v1, s1
+; GFX11-NEXT:v_dual_mov_b32 v0, 0xe3e6 :: v_dual_mov_b32 v1, 0
 ; GFX11-NEXT:s_setpc_b64 s[30:31]
 entry:
-  %qm = call i64 @llvm.amdgcn.s.quadmask.i64(i64 u0x67DE48FC85FE3A92)
+  %qm = call i64 @llvm.amdgcn.s.quadmask.i64(i64 u0x67D000FC85F00A90)
   ret i64 %qm
 }
 

>From 144c4dc164ec137e518cfd647c116373e7a61b8f Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Wed, 15 Nov 2023 15:59:56 +0100
Subject: [PATCH 2/3] fixup! [AMDGPU] - Add constant folding for s_quadmask

---
 llvm/lib/Analysis/ConstantFolding.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 40b5938fcda0c2a..39bbb04fbcf26cc 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2427,11 +2427,11 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
 case Intrinsic::amdgcn_s_quadmask: {
   uint64_t Val = Op->getZExtValue();
   uint64_t QuadMask = 0;
-  for (unsigned i = 0; i < Op->getBitWidth() / 4; ++i, Val >>= 4) {
+  for (unsigned I = 0; I < Op->getBitWidth() / 4; ++I, Val >>= 4) {
 if (!(Val & 0xF))
   continue;
 
-QuadMask |= (1 << i);
+QuadMask |= (1 << I);
   }
   return ConstantInt::get(Ty, QuadMask);
 }

>From 65bb0b1164ff9b7491589cb88decb1d135504c1b Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Thu, 16 Nov 2023 11:22:52 +0100
Subject: [PATCH 3/3] fixup! Merge branch 'main' into quadmask-folding

---
 llvm/lib/Analysis/ConstantFolding.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 64d088ea7a46404..2771a3d574f7799 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2425,7 +2425,6 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
   return ConstantFP::get(Ty->getContext(), Val);
 }
 
-
 case Intrinsic::amdgcn_s_quadmask: {
   uint64_t Val = Op->getZExtValue();
   uint64_t QuadMask = 0;
@@ -2436,6 +2435,7 @@ static Constant

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

2023-11-16 Thread via cfe-commits


@@ -477,10 +477,10 @@ Bug Fixes in This Version
 - Clang now prints unnamed members in diagnostic messages instead of giving an
   empty ''. Fixes
   (`#63759 `_)
-- Fix crash in __builtin_strncmp and related builtins when the size value
-  exceeded the maximum value representable by int64_t. Fixes
+- Fix crash in ``__builtin_strncmp`` and related builtins when the size value
+  exceeded the maximum value representable by ``int64_t``. Fixes
   (`#64876 `_)
-- Fixed an assertion if a function has cleanups and fatal erors.
+- Fixed an assertion if a function has cleanups and fatal errors.

cor3ntin wrote:

Can you revert that and commit it separately in a separate NFC patch? thanks

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


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

2023-11-16 Thread via cfe-commits

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


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


[clang] fix: compatible C++ empty record with align UB with gcc (PR #72197)

2023-11-16 Thread via cfe-commits

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


[clang] e8dd7ec - Revert "[AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (#71795)"

2023-11-16 Thread Matt Devereau via cfe-commits

Author: Matt Devereau
Date: 2023-11-16T11:01:27Z
New Revision: e8dd7ecbc4668cdf767478fd9b1dd666c38d0105

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

LOG: Revert "[AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics 
(#71795)"

This reverts commit cc1244980b74f45a06e2002a33444ce757b577aa.

Added: 


Modified: 
clang/include/clang/Basic/arm_sme.td
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.h
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
llvm/lib/Target/AArch64/SMEInstrFormats.td

Removed: 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
llvm/test/CodeGen/AArch64/sme2-intrinsics-zt0.ll



diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index fb3f54ecff95080..b5655afdf419ecf 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,11 +298,3 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
-
-//
-// Spill and fill of ZT0
-//
-let TargetGuard = "sme2" in {
-  def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
-  def SVSTR_ZT : Inst<"svstr_zt", "vi%", "", MergeNone, "aarch64_sme_str_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
-}

diff  --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
deleted file mode 100644
index 7ae6769c8237f6c..000
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
+++ /dev/null
@@ -1,51 +0,0 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-
-// REQUIRES: aarch64-registered-target
-
-// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
-// RUN: %clang_cc1 -fclang-abi-compat=latest -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sme2 -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s
-// RUN: %clang_cc1 -fclang-abi-compat=latest -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sme2 -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
-// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
-
-#include 
-
-#ifdef SVE_OVERLOADED_FORMS
-// A simple used,unused... macro, long enough to represent any SVE builtin.
-#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1
-#else
-#define SVE_ACLE_FUNC(A1,A2) A1##A2
-#endif
-
-// LDR ZT0
-
-// CHECK-LABEL: @test_svldr_zt(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
-// CHECK-NEXT:ret void
-//
-// CPP-CHECK-LABEL: @_Z13test_svldr_ztPKv(
-// CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
-// CPP-CHECK-NEXT:ret void
-//
-void test_svldr_zt(const void *base) __arm_streaming_compatible 
__arm_shared_za __arm_preserves_za {
-  svldr_zt(0, base);
-} ;
-
-
-// STR ZT0
-
-// CHECK-LABEL: @test_svstr_zt(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
-// CHECK-NEXT:ret void
-//
-// CPP-CHECK-LABEL: @_Z13test_svstr_ztPv(
-// CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
-// CPP-CHECK-NEXT:ret void
-//
-void test_svstr_zt(void *base) __arm_streaming_compatible __arm_shared_za 
__arm_preserves_za {
-  svstr_zt(0, base);
-}

diff  --git a/llvm/include/llvm/IR/IntrinsicsAArch64.td 
b/llvm/include/llvm/IR/IntrinsicsAArch64.td
index 9164604f7d78cbc..a42e2c49cb477ba 100644
--- a/llvm/include/llvm/IR/IntrinsicsAArch64.td
+++ b/llvm/include/llvm/IR/IntrinsicsAArch64.td
@@ -2679,10 +2679,10 @@ let TargetPrefix = "aarch64" in {
   def int_aarch64_sme_st1q_vert  : SME_Load_Store_Int

[llvm] [clang] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (PR #71795)

2023-11-16 Thread Matthew Devereau via cfe-commits

MDevereau wrote:

@mikaelholmen Thanks. I've reverted the patch

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


[llvm] [compiler-rt] [clang] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-16 Thread Pavel Iliin via cfe-commits

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


[llvm] [compiler-rt] [clang] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-16 Thread Pavel Iliin via cfe-commits

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

LGTM overall, thanks, just address one nit above.

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


[llvm] [clang] [compiler-rt] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-16 Thread Pavel Iliin via cfe-commits


@@ -293,6 +294,7 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"sme-lutv2", AArch64::AEK_SME_LUTv2, "+sme-lutv2", "-sme-lutv2", 
FEAT_INIT, "", 0},
 {"sme-f8f16", AArch64::AEK_SMEF8F16, "+sme-f8f16", "-sme-f8f16", 
FEAT_INIT, "+sme2,+fp8", 0},
 {"sme-f8f32", AArch64::AEK_SMEF8F32, "+sme-f8f32", "-sme-f8f32", 
FEAT_INIT, "+sme2,+fp8", 0},
+{"sme-fa64",  AArch64::AEK_SMEFA64,  "+sme-fa64",  "-sme-fa64",  
FEAT_INIT, "", 0},

ilinpv wrote:

Small nit: remove extra space before FEAT_INIT here

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


[clang] [llvm] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-16 Thread via cfe-commits

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


[clang] [llvm] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-16 Thread via cfe-commits

https://github.com/simpal01 updated 
https://github.com/llvm/llvm-project/pull/71545

>From e2b6fa1cb088f2c3cf05a38959a3f3d34eda92c5 Mon Sep 17 00:00:00 2001
From: Simi Pallipurath 
Date: Tue, 7 Nov 2023 13:05:08 +
Subject: [PATCH 1/5] [ARM] .fpu equals fpv5-d16 disables floating point MVE
 which leads to unsupported MVE instructions for cortex M85/M55.

The floating-point and MVE features together specify the MVE functionality that 
is supported on the Cortex-M85 processor. But the FPU extension for the 
underlying architecture(armv8.1-m.main) is FPV5 which does not include MVE-F.

So either when we explictly specify -mfpu=fpv5-d16 or Compiler's -S output and 
`-save-temps=obj` loses MVE feature which leads to assembler error. What 
happening here is .fpu directive overrides any previously set features by .cpu 
directive. Since the the corresponding .fpu generated (.fpu fpv5-d16) does not 
include MVE-F, it overrides those features even though it is supported and set 
by the .cpu directive. Looks like .fpu is supposed to do this.

In this case, there should be an .arch_extension directive re-enabling the 
relevant extensions after .fpu  if the goal is to keep these extensions 
enabled. GCC also does the same.

So this patch enables the MVE features by:
  .fpu fpv5-d16
  .arch_extension mve.fp
---
 clang/test/CodeGen/arm-v8.1m-check-mve.ll | 56 +++
 .../lib/Target/ARM/AsmParser/ARMAsmParser.cpp |  3 +
 .../ARM/MCTargetDesc/ARMTargetStreamer.cpp| 16 --
 3 files changed, 69 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/arm-v8.1m-check-mve.ll

diff --git a/clang/test/CodeGen/arm-v8.1m-check-mve.ll 
b/clang/test/CodeGen/arm-v8.1m-check-mve.ll
new file mode 100644
index 000..cfcb0223961e31e
--- /dev/null
+++ b/clang/test/CodeGen/arm-v8.1m-check-mve.ll
@@ -0,0 +1,56 @@
+; REQUIRES: arm-registered-target
+; RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard 
-save-temps=obj -S -o - %s | FileCheck %s
+; RUN: %clang --target=arm-none-eabi -mcpu=cortex-m55 -mfloat-abi=hard 
-save-temps=obj -S -o - %s | FileCheck %s
+; RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s
+; RUN: %clang --target=arm-none-eabi -mcpu=cortex-m55 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s
+; CHECK: .fpu   fpv5-d16
+; CHECK  .arch_extension mve.fp
+target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
+target triple = "thumbv8.1m.main-none-unknown-eabihf"
+
+%struct.dummy_t = type { float, float, float, float }
+
+define dso_local signext i8 @foo(ptr noundef %handle) #0 {
+entry:
+  %handle.addr = alloca ptr, align 4
+  store ptr %handle, ptr %handle.addr, align 4
+  %0 = load ptr, ptr %handle.addr, align 4
+  %a = getelementptr inbounds %struct.dummy_t, ptr %0, i32 0, i32 0
+  %1 = load float, ptr %a, align 4
+  %sub = fsub float 0x3F5439DE4000, %1
+  %2 = load ptr, ptr %handle.addr, align 4
+  %a1 = getelementptr inbounds %struct.dummy_t, ptr %2, i32 0, i32 0
+  %3 = load float, ptr %a1, align 4
+  %4 = call float @llvm.fmuladd.f32(float 0x3F847AE14000, float %sub, 
float %3)
+  store float %4, ptr %a1, align 4
+  %5 = load ptr, ptr %handle.addr, align 4
+  %b = getelementptr inbounds %struct.dummy_t, ptr %5, i32 0, i32 1
+  %6 = load float, ptr %b, align 4
+  %sub2 = fsub float 0x3F5439DE4000, %6
+  %7 = load ptr, ptr %handle.addr, align 4
+  %b3 = getelementptr inbounds %struct.dummy_t, ptr %7, i32 0, i32 1
+  %8 = load float, ptr %b3, align 4
+  %9 = call float @llvm.fmuladd.f32(float 0x3F947AE14000, float %sub2, 
float %8)
+  store float %9, ptr %b3, align 4
+  %10 = load ptr, ptr %handle.addr, align 4
+  %c = getelementptr inbounds %struct.dummy_t, ptr %10, i32 0, i32 2
+  %11 = load float, ptr %c, align 4
+  %sub4 = fsub float 0x3F5439DE4000, %11
+  %12 = load ptr, ptr %handle.addr, align 4
+  %c5 = getelementptr inbounds %struct.dummy_t, ptr %12, i32 0, i32 2
+  %13 = load float, ptr %c5, align 4
+  %14 = call float @llvm.fmuladd.f32(float 0x3F9EB851E000, float %sub4, 
float %13)
+  store float %14, ptr %c5, align 4
+  %15 = load ptr, ptr %handle.addr, align 4
+  %d = getelementptr inbounds %struct.dummy_t, ptr %15, i32 0, i32 3
+  %16 = load float, ptr %d, align 4
+  %sub6 = fsub float 0x3F5439DE4000, %16
+  %17 = load ptr, ptr %handle.addr, align 4
+  %d7 = getelementptr inbounds %struct.dummy_t, ptr %17, i32 0, i32 3
+  %18 = load float, ptr %d7, align 4
+  %19 = call float @llvm.fmuladd.f32(float 0x3FA47AE14000, float %sub6, 
float %18)
+  store float %19, ptr %d7, align 4
+  ret i8 0
+}
+
+declare float @llvm.fmuladd.f32(float, float, float) #1
diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp 
b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index 373d5b59bca6640..20b52ebc544a1ed 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -12648,6 +12648,9 @@ bool A

[clang] [llvm] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-16 Thread via cfe-commits


@@ -0,0 +1,35 @@
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 
-save-temps=obj -S -o - %s | FileCheck %s
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m55 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s
+
+// REQUIRES: arm-registered-target
+
+// CHECK: .fpu   fpv5-d16
+// CHECK-NEXT  .arch_extension mve.fp
+
+#define DUMMY_CONST_1 (0.0012345F)
+#define DUMMY_CONST_2 (0.01F)
+#define DUMMY_CONST_3 (0.02F)
+#define DUMMY_CONST_4 (0.03F)
+#define DUMMY_CONST_5 (0.04F)

simpal01 wrote:

Done

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


[clang] [llvm] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-16 Thread via cfe-commits


@@ -0,0 +1,35 @@
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 
-save-temps=obj -S -o - %s | FileCheck %s
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m55 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s

simpal01 wrote:

Done

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


[clang] [llvm] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-16 Thread via cfe-commits


@@ -0,0 +1,35 @@
+// RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 
-save-temps=obj -S -o - %s | FileCheck %s

simpal01 wrote:

Done

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


[clang] [llvm] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-16 Thread David Spickett via cfe-commits

DavidSpickett wrote:

Tests now LGTM, thanks for the updates.

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


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

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

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

>From 187bfbf15993911f6fd17092fad2f7cd7172180b Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Thu, 16 Nov 2023 15:03:06 +0330
Subject: [PATCH] [clang] Non-object types are non-trivially relocatable

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

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed1a978b5382d71..d5835c7b8ab5f06 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -557,6 +557,9 @@ Bug Fixes in This Version
   Fixes (`#67317 `_)
 - Fixed an issue that a benign assertion might hit when instantiating a pack 
expansion
   inside a lambda. (`#61460 
`_)
+- ``__is_trivially_relocatable`` no longer returns true for non-object types
+  such as references and functions.
+  Fixes (`#67498 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index c8e452e2feab0bf..160a725939ccd4c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext &Context) const {
 
   if (BaseElementType->isIncompleteType()) {
 return false;
+  } else if (!BaseElementType->isObjectType()) {
+return false;
   } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
 return RD->canPassInRegisters();
   } else {
diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp 
b/clang/test/SemaCXX/type-traits-incomplete.cpp
index c0a520e167698af..3e341d648244075 100644
--- a/clang/test/SemaCXX/type-traits-incomplete.cpp
+++ b/clang/test/SemaCXX/type-traits-incomplete.cpp
@@ -1,8 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S; // expected-note 2 {{forward declaration of 'S'}}
+struct S; // expected-note 6 {{forward declaration of 'S'}}
 
 void f() {
   __is_pod(S); // expected-error{{incomplete type 'S' used in type trait 
expression}}
   __is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait 
expression}}
+
+  __is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+  __is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in 
type trait expression}}
+
+  __is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used 
in type trait expression}}
+  __is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used 
in type trait expression}}
 }
diff --git a/clang/test/SemaCXX/type-traits-nonobject.cpp 
b/clang/test/SemaCXX/type-traits-nonobject.cpp
new file mode 100644
index 000..c9e3c30e5533d48
--- /dev/null
+++ b/clang/test/SemaCXX/type-traits-nonobject.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+// expected-no-diagnostics
+
+static_assert(!__is_pod(void), "");
+static_assert(!__is_pod(int&), "");
+static_assert(!__is_pod(int()), "");
+
+static_assert(!__is_trivially_copyable(void), "");
+static_assert(!__is_trivially_copyable(int&), "");
+static_assert(!__is_trivially_copyable(int()), "");
+
+static_assert(!__is_trivially_relocatable(void), "");
+static_assert(!__is_trivially_relocatable(int&), "");
+static_assert(!__is_trivially_relocatable(int()), "");

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


[clang] [AArch64][SME2] Add FCLAMP, CNTP builtins for SME2 (PR #72487)

2023-11-16 Thread Dinar Temirbulatov via cfe-commits

https://github.com/dtemirbulatov updated 
https://github.com/llvm/llvm-project/pull/72487

>From dc691934814029de64494272697d562ddb86dfee Mon Sep 17 00:00:00 2001
From: Dinar Temirbulatov 
Date: Thu, 16 Nov 2023 07:21:17 +
Subject: [PATCH 1/2] [AArch64][SME2] Add FCLAMP, CNTP builtins for SME2

This change enables FCLAMP, FCLAMP_BF16, CNTP builtins for SME2 target.
---
 clang/include/clang/Basic/arm_sve.td  | 10 +++---
 .../acle_sve2p1_bfclamp.c | 35 +++
 .../acle_sve2p1_cntp.c|  3 ++
 .../acle_sve2p1_fclamp.c  |  8 +
 4 files changed, 52 insertions(+), 4 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfclamp.c

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 40e474d5f0a8f4e..5947a1a1054cc16 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1860,7 +1860,6 @@ def SVBGRP_N : SInst<"svbgrp[_n_{d}]", "dda", "UcUsUiUl", 
MergeNone, "aarch64_sv
 }
 
 let TargetGuard = "sve2p1" in {
-def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [], []>;
 def SVPTRUE_COUNT  : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, 
"aarch64_sve_ptrue_{d}", [IsOverloadNone], []>;
 def SVPFALSE_COUNT_ALIAS : SInst<"svpfalse_c", "}v", "", MergeNone, "", 
[IsOverloadNone]>;
 
@@ -1970,17 +1969,20 @@ def SVBFMLSLT_LANE : SInst<"svbfmlslt_lane[_{d}]", 
"dd$$i", "f", MergeNone, "aar
 let TargetGuard = "sve2p1" in {
 def SVSCLAMP : SInst<"svclamp[_{d}]", "", "csil", MergeNone, 
"aarch64_sve_sclamp", [], []>;
 def SVUCLAMP : SInst<"svclamp[_{d}]", "", "UcUsUiUl", MergeNone, 
"aarch64_sve_uclamp", [], []>;
-
 def SVPSEL_B : SInst<"svpsel_lane_b8",  "PPPm", "Pc", MergeNone, "", [], []>;
 def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", [], []>;
 def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", [], []>;
 def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", [], []>;
 
-def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_cntp_{d}", [IsOverloadNone], [ImmCheck<1, ImmCheck2_4_Mul2>]>;
-
 defm SVREVD : SInstZPZ<"svrevd", "csilUcUsUiUl", "aarch64_sve_revd">;
 }
 
+let TargetGuard = "sve2p1|sme2" in {
+  def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [IsStreamingCompatible], []>;
+  def SVFCLAMP_BF   : SInst<"svclamp[_{d}]", "", "b", MergeNone, 
"aarch64_sve_fclamp", [IsStreamingCompatible], []>;
+  def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_cntp_{d}", [IsOverloadNone, IsStreamingCompatible], [ImmCheck<1, 
ImmCheck2_4_Mul2>]>;
+}
+
 

 // SME2
 
diff --git a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfclamp.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfclamp.c
new file mode 100644
index 000..4cd5627eb5c4dd8
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfclamp.c
@@ -0,0 +1,35 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +bf16 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +bf16 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +bf16 -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +bf16 -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -target-feature +bf16 -S -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -target-feature +bf16 -S -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +sve -target-feature +bf16 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
me

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

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


@@ -477,10 +477,10 @@ Bug Fixes in This Version
 - Clang now prints unnamed members in diagnostic messages instead of giving an
   empty ''. Fixes
   (`#63759 `_)
-- Fix crash in __builtin_strncmp and related builtins when the size value
-  exceeded the maximum value representable by int64_t. Fixes
+- Fix crash in ``__builtin_strncmp`` and related builtins when the size value
+  exceeded the maximum value representable by ``int64_t``. Fixes
   (`#64876 `_)
-- Fixed an assertion if a function has cleanups and fatal erors.
+- Fixed an assertion if a function has cleanups and fatal errors.

AMP999 wrote:

Sure, it's done!

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


[clang] [clang] Refactor `IdentifierInfo::ObjcOrBuiltinID` (PR #71709)

2023-11-16 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/71709

>From 2823d38544d18213b5bf48c67e4eedd52acce850 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 8 Nov 2023 20:30:37 +0300
Subject: [PATCH 1/2] [clang] Refactor `IdentifierInfo::ObjcOrBuiltinID`

This patch refactors how values are stored inside 
`IdentifierInfo::ObjcOrBuiltinID` bit-field, and annotates it with 
`preferred_type`. In order to make the value easier to interpret by debuggers, 
a new `ObjCKeywordOrInterestingOrBuiltin` is added. Previous "layout" of this 
fields couldn't be represented with this new enum, because it skipped over some 
arbitrary enumerators, so a new "layout" was invented based on 
`ObjCKeywordOrInterestingOrBuiltin` enum. I believe the new layout is simpler 
than the new one.
---
 clang/include/clang/Basic/IdentifierTable.h | 117 
 1 file changed, 73 insertions(+), 44 deletions(-)

diff --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 0898e7d39dd7dee..fa76228da2b143a 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
 
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/DiagnosticIDs.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TokenKinds.h"
@@ -86,19 +87,26 @@ enum { IdentifierInfoAlignment = 8 };
 static constexpr int ObjCOrBuiltinIDBits = 16;
 
 /// The "layout" of ObjCOrBuiltinID is:
-///  - The first value (0) represents "not a special identifier".
-///  - The next (NUM_OBJC_KEYWORDS - 1) values represent ObjCKeywordKinds (not
-///including objc_not_keyword).
-///  - The next (NUM_INTERESTING_IDENTIFIERS - 1) values represent
-///InterestingIdentifierKinds (not including not_interesting).
-///  - The rest of the values represent builtin IDs (not including NotBuiltin).
-static constexpr int FirstObjCKeywordID = 1;
-static constexpr int LastObjCKeywordID =
-FirstObjCKeywordID + tok::NUM_OBJC_KEYWORDS - 2;
-static constexpr int FirstInterestingIdentifierID = LastObjCKeywordID + 1;
-static constexpr int LastInterestingIdentifierID =
-FirstInterestingIdentifierID + tok::NUM_INTERESTING_IDENTIFIERS - 2;
-static constexpr int FirstBuiltinID = LastInterestingIdentifierID + 1;
+///  - ObjCKeywordKind enumerators
+///  - InterestingIdentifierKind enumerators
+///  - Builtin::ID enumerators
+///  - NonSpecialIdentifier
+enum class ObjCKeywordOrInterestingOrBuiltin {
+#define OBJC_AT_KEYWORD(X) objc_##X,
+#include "clang/Basic/TokenKinds.def"
+  NUM_OBJC_KEYWORDS,
+
+#define INTERESTING_IDENTIFIER(X) X,
+#include "clang/Basic/TokenKinds.def"
+  NUM_OBJC_KEYWORDS_AND_INTERESTING_IDENTIFIERS,
+
+  NotBuiltin,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/Builtins.def"
+  FirstTSBuiltin,
+
+  NonSpecialIdentifier = 65534
+};
 
 /// One of these records is kept for each identifier that
 /// is lexed.  This contains information about whether the token was 
\#define'd,
@@ -113,9 +121,7 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   LLVM_PREFERRED_TYPE(tok::TokenKind)
   unsigned TokenID : 9;
 
-  // ObjC keyword ('protocol' in '@protocol') or builtin (__builtin_inf).
-  // First NUM_OBJC_KEYWORDS values are for Objective-C,
-  // the remaining values are for builtins.
+  LLVM_PREFERRED_TYPE(ObjCKeywordOrInterestingOrBuiltin)
   unsigned ObjCOrBuiltinID : ObjCOrBuiltinIDBits;
 
   // True if there is a #define for this.
@@ -198,13 +204,16 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   llvm::StringMapEntry *Entry = nullptr;
 
   IdentifierInfo()
-  : TokenID(tok::identifier), ObjCOrBuiltinID(0), HasMacro(false),
-HadMacro(false), IsExtension(false), IsFutureCompatKeyword(false),
-IsPoisoned(false), IsCPPOperatorKeyword(false),
-NeedsHandleIdentifier(false), IsFromAST(false), 
ChangedAfterLoad(false),
-FEChangedAfterLoad(false), RevertedTokenID(false), OutOfDate(false),
-IsModulesImport(false), IsMangledOpenMPVariantName(false),
-IsDeprecatedMacro(false), IsRestrictExpansion(false), IsFinal(false) {}
+  : TokenID(tok::identifier),
+ObjCOrBuiltinID(llvm::to_underlying(
+ObjCKeywordOrInterestingOrBuiltin::NonSpecialIdentifier)),
+HasMacro(false), HadMacro(false), IsExtension(false),
+IsFutureCompatKeyword(false), IsPoisoned(false),
+IsCPPOperatorKeyword(false), NeedsHandleIdentifier(false),
+IsFromAST(false), ChangedAfterLoad(false), FEChangedAfterLoad(false),
+RevertedTokenID(false), OutOfDate(false), IsModulesImport(false),
+IsMangledOpenMPVariantName(false), IsDeprecatedMacro(false),
+IsRestrictExpansion(false), IsFinal(false) {}
 
 public:
   IdentifierInfo(const IdentifierInfo &) = delete;
@@ -332,42 +341,62 @@ class alignas(IdentifierInfoAlignment

[clang] [clang] Refactor `IdentifierInfo::ObjcOrBuiltinID` (PR #71709)

2023-11-16 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

Finally got past previous test failures. But the following tests started to 
fail:
```
  Clang :: AST/HLSL/pch.hlsl
  Clang :: PCH/__va_list_tag-typedef.c
  Clang :: PCH/builtin-is-constant-evaluated.cpp
  Clang-Unit :: Lex/./LexTests/failed_to_discover_tests_from_gtest
```
Here is full test output (don't mind `LibClang/symbols.test`, that's my local 
failure):
https://gist.github.com/Endilll/5d63e138b59af121067d30c77752c437

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


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

2023-11-16 Thread via cfe-commits

DonatNagyE wrote:

> Hmm, it really worries me that `MallocChecker` is setting a return value 
> outside of `evalCall()`. This can easily lead to conflicts if multiple 
> checkers try to do this: `evalCall()` is protected from conflicts (the engine 
> asserts that at most one checker evaluates each call) but `checkPostCall()` 
> isn't.
> 
> To the best of my knowledge, the only legal way to use `State->BindExpr(...)` 
> in a checker is to set the return value in `evalCall()`. Ideally we should 
> have an assertion about this ("Environment is unchanged after checker 
> callback invocation, unless the callback is a successful `evalCall()`").

I agree and there's already a FIXME which suggests moving this modeling step 
into an EvalCall callback. If you feel that this is an important improvement, I 
could create a separate commit that does it.

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

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

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

>From 89a2d60fc012742a74a008fb77213bcd47734503 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Fri, 10 Nov 2023 15:10:44 +0100
Subject: [PATCH 1/9] [coroutines] Introduce [[clang::coro_return_type]] and
 [[clang::co ro_wrapper]]

---
 clang/include/clang/Basic/Attr.td | 16 +
 clang/include/clang/Basic/AttrDocs.td | 67 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/Sema/Sema.h   |  1 +
 clang/lib/Sema/SemaDecl.cpp   | 25 ++-
 ...a-attribute-supported-attributes-list.test |  2 +
 .../SemaCXX/coro-return-type-and-wrapper.cpp  | 56 
 7 files changed, 169 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/coro-return-type-and-wrapper.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 31434565becaec6..f7a2b83b15ef5bc 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1094,6 +1094,22 @@ def CoroOnlyDestroyWhenComplete : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroReturnType : InheritableAttr {
+  let Spellings = [Clang<"coro_return_type">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroReturnTypeAndWrapperDoc];
+  let SimpleHandler = 1;
+}
+
+def CoroWrapper : InheritableAttr {
+  let Spellings = [Clang<"coro_wrapper">];
+  let Subjects = SubjectList<[Function]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroReturnTypeAndWrapperDoc];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fa6f6acd0c30e88..66c92bcaa2d4a4a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7482,3 +7482,70 @@ generation of the other destruction cases, optimizing 
the above `foo.destroy` to
 
   }];
 }
+
+
+def CoroReturnTypeAndWrapperDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+The `coro_only_destroy_when_complete` attribute should be marked on a C++ 
class. The coroutines
+whose return type is marked with the attribute are assumed to be destroyed 
only after the coroutine has
+reached the final suspend point.
+
+This is helpful for the optimizers to reduce the size of the destroy function 
for the coroutines.
+
+For example,
+
+.. code-block:: c++
+
+  A foo() {
+dtor d;
+co_await something();
+dtor d1;
+co_await something();
+dtor d2;
+co_return 43;
+  }
+
+The compiler may generate the following pseudocode:
+
+.. code-block:: c++
+
+  void foo.destroy(foo.Frame *frame) {
+switch(frame->suspend_index()) {
+  case 1:
+frame->d.~dtor();
+break;
+  case 2:
+frame->d.~dtor();
+frame->d1.~dtor();
+break;
+  case 3:
+frame->d.~dtor();
+frame->d1.~dtor();
+frame->d2.~dtor();
+break;
+  default: // coroutine completed or haven't started
+break;
+}
+
+frame->promise.~promise_type();
+delete frame;
+  }
+
+The `foo.destroy()` function's purpose is to release all of the resources
+initialized for the coroutine when it is destroyed in a suspended state.
+However, if the coroutine is only ever destroyed at the final suspend state,
+the rest of the conditions are superfluous.
+
+The user can use the `coro_only_destroy_when_complete` attributo suppress
+generation of the other destruction cases, optimizing the above `foo.destroy` 
to:
+
+.. code-block:: c++
+
+  void foo.destroy(foo.Frame *frame) {
+frame->promise.~promise_type();
+delete frame;
+  }
+
+  }];
+}
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4614324babb1c91..0200457b39ce5eb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11591,6 +11591,10 @@ def err_conflicting_aligned_options : Error <
 def err_coro_invalid_addr_of_label : Error<
   "the GNU address of label extension is not allowed in coroutines."
 >;
+def err_coroutine_return_type : Error<
+  "function returns a coroutine return type %0 but is neither a coroutine nor 
a coroutine wrapper; "
+  "non-coroutines should be marked with [[clang::coro_wrapper]] to allow 
returning coroutine return type"
+>;
 } // end of coroutines issue category
 
 let CategoryName = "Documentation Issue" in {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f69f366c1750918..4d45698e5786740 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11183,6 +11183,7 @@ class Sema final {
   bool buildCoroutineParameterMoves(SourceLocation Loc);
   VarDecl *

[clang] Recommit "[Clang][RISCV] Introduce tuple types for RVV bfloat16 #72216" (PR #72370)

2023-11-16 Thread Yueh-Ting Chen via cfe-commits

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


[clang] Recommit "[Clang][RISCV] Introduce tuple types for RVV bfloat16 #72216" (PR #72370)

2023-11-16 Thread Yueh-Ting Chen via cfe-commits


@@ -1101,7 +1101,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 500;
+const unsigned NUM_PREDEF_TYPE_IDS = 502;

eopXD wrote:

Yes you are right. My mistake here. Update the PR description.

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


[clang] [clang] Add bitint classification for __builtin_classify_type (PR #72036)

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

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


[clang] [clang] Add bitint classification for __builtin_classify_type (PR #72036)

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

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


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


[clang] [clang] Add bitint classification for __builtin_classify_type (PR #72036)

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


@@ -217,6 +217,8 @@ Non-comprehensive list of changes in this release
   (e.g., ``uint16x8_t``), this returns the constant number of elements at 
compile-time.
   For scalable vectors, e.g., SVE or RISC-V V, the number of elements is not 
known at compile-time and is
   determined at runtime.
+* ``__builtin_classify_type()`` now classifies ``_BitInt`` values as the 
return value ``18``,
+  to match GCC 14's behavior.

AaronBallman wrote:

Okay, that's reasonable.

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


[clang] [clang][Interp] Implement IntegralAP::mul() (PR #72491)

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

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

LGTM

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


[clang] [clang][Interp] Implement __builtin_classify_type (PR #71972)

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

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

LGTM!

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


[clang] [clang][Interp] Implement __builtin_bitreverse (PR #71687)

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

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


[clang] [clang][Interp] Implement __builtin_bitreverse (PR #71687)

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

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

LGTM

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


[clang] [clang][Interp] Implement __builtin_bitreverse (PR #71687)

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


@@ -59,13 +59,54 @@ static void pushInt(InterpState &S, int32_t Val) {
 llvm_unreachable("Int isn't 16 or 32 bit?");
 }
 
-static bool retInt(InterpState &S, CodePtr OpPC, APValue &Result) {
-  PrimType IntType = getIntPrimType(S);
-  if (IntType == PT_Sint32)
-return Ret(S, OpPC, Result);
-  else if (IntType == PT_Sint16)
-return Ret(S, OpPC, Result);
-  llvm_unreachable("Int isn't 16 or 32 bit?");
+static void pushAPSInt(InterpState &S, const APSInt &Val) {
+  bool Signed = Val.isSigned();
+
+  if (Signed) {
+switch (Val.getBitWidth()) {
+case 64:
+  S.Stk.push>(
+  Integral<64, true>::from(Val.getSExtValue()));
+  break;
+case 32:
+  S.Stk.push>(
+  Integral<32, true>::from(Val.getSExtValue()));
+  break;
+case 16:
+  S.Stk.push>(
+  Integral<16, true>::from(Val.getSExtValue()));
+  break;
+case 8:
+  S.Stk.push>(
+  Integral<8, true>::from(Val.getSExtValue()));
+  break;
+default:
+  llvm_unreachable("Invalid integer bitwidth");

AaronBallman wrote:

Yeah, that's the situation I'm worried about (not really specific to bitreverse 
as that only has hardcoded bit widths). However, now that I look at 
builtins.def more closely, most of the ones taking variadic arguments are doing 
so because they have custom type-checking that often disallows 
non-power-of-two-types. So I think we're fine for now, probably.

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


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

2023-11-16 Thread via cfe-commits


@@ -266,13 +266,18 @@ void CheckUseZeroAllocated1(void) {
 }
 
 char CheckUseZeroAllocated2(void) {
+  // FIXME: The return value of `alloca()` is modeled with `AllocaRegion`
+  // instead of `SymbolicRegion`, so the current implementation of
+  // `MallocChecker::checkUseZeroAllocated()` cannot handle it; and we get an
+  // unrelated, but suitable warning from core.uninitialized.UndefReturn.
   char *p = alloca(0);
-  return *p; // expected-warning {{Use of memory allocated with size zero}}
+  return *p; // expected-warning {{Undefined or garbage value returned to 
caller}}

DonatNagyE wrote:

Also note that the report "Use of memory allocated with size zero" is redundant 
with ArrayBoundV2, which detects and reports that the offset (0) is not smaller 
than the extent (also 0). Based on this I'm not sure that it's useful to 
maintain this "size zero" special case.

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


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

2023-11-16 Thread via cfe-commits

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


[llvm] [clang] [AArch64] Introduce the Armv9.5-A architecture version (PR #72392)

2023-11-16 Thread Jonathan Thackray via cfe-commits

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

LGTM.

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


[clang] fix: compatible C++ empty record with align UB with gcc (PR #72197)

2023-11-16 Thread via cfe-commits

hstk30-hw wrote:

This is the code I debug located. Seem the comment is out of date?

https://github.com/llvm/llvm-project/blob/1b82cc1186b8bf716205c9b86b851db667792a64/clang/lib/CodeGen/Targets/AArch64.cpp#L298C1-L311C4
 

This issue 
https://github.com/llvm/llvm-project/commit/1711cc930bda8d27e87a2092bd220c18e4600c98
 point that when pass the empty class the `va_list` will get out of sync.


> we should not be considering this an empty class.

It confuse me whether an empty class with alignment (size > 1) is an empty 
class in C++?



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


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

2023-11-16 Thread via cfe-commits

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

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

AaronBallman wrote:

Oh wow, same failure a second time...

Ohh, this looks familiar now, but... it was already fixed, so why are we still 
hitting this failure?
```
| expected: clang::TreeTransform<(anonymous 
namespace)::CurrentInstantiationRebuilder>::RebuildArrayType(clang::QualType, 
clang::ArraySizeModifier, llvm::APInt const*, clang::Expr*, unsigned int, 
clang::SourceRange)
| got: 0,   clang::TreeTransform<(anonymous 
namespace)::CurrentInstantiationRebuilder>::RebuildArrayType(clang::QualType, 
clang::ArrayType::ArraySizeModifier, llvm::APInt const*, clang::Expr*, unsigned 
int, clang::SourceRange)
```
should have been fixed by 
https://github.com/llvm/llvm-project/commit/f5f4c5b313fc809b9b1b9d600d0ec3cec0d12941
 over two weeks ago. CC @Endilll 

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


[clang] [libcxx] [libc] [compiler-rt] [clang-tools-extra] [flang] [llvm] [lldb] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

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

https://github.com/PAX-12-WU updated 
https://github.com/llvm/llvm-project/pull/71222

>From e0d99fb5baa4231ab351f7fd5abf0a1ffe589547 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:55:06 +
Subject: [PATCH 1/6] FDATE extension implementation: get date and time in
 ctime format

reference to gfortran fdate https://gcc.gnu.org/onlinedocs/gfortran/FDATE.html
usage:
CHARACTER(32) :: time
CALL fdate(time)
WRITE(*,*) time
---
 flang/docs/Intrinsics.md |  2 +-
 flang/include/flang/Runtime/command.h|  5 +
 flang/include/flang/Runtime/extensions.h |  2 ++
 flang/runtime/command.cpp| 28 
 flang/runtime/extensions.cpp |  5 +
 flang/unittests/Runtime/CommandTest.cpp  | 14 
 6 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e5538..982be8208164296 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, FDATE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec6289390545479..07f6d8e169ead6c 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -23,6 +23,11 @@ extern "C" {
 // integer kind.
 std::int32_t RTNAME(ArgumentCount)();
 
+// Try to get the the current date (same format as CTIME: convert to a string)
+// Return a STATUS as described in the standard.
+std::int32_t RTNAME(FDate)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 // 16.9.82 GET_COMMAND
 // Try to get the value of the whole command. All of the parameters are
 // optional.
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb79..92b9907860121aa 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -24,6 +24,8 @@ void FORTRAN_PROCEDURE_NAME(flush)(const int &unit);
 // GNU Fortran 77 compatibility function IARGC.
 std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 
+void FORTRAN_PROCEDURE_NAME(fdate)(std::int8_t *string, std::int64_t length);
+
 // GNU Fortran 77 compatibility subroutine GETARG(N, ARG).
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t &n, std::int8_t *arg, std::int64_t length);
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e571b..da0803c39f49b6d 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -14,6 +14,7 @@
 #include "flang/Runtime/descriptor.h"
 #include 
 #include 
+#include 
 
 namespace Fortran::runtime {
 std::int32_t RTNAME(ArgumentCount)() {
@@ -125,6 +126,33 @@ static bool FitsInDescriptor(
   kind, terminator, value);
 }
 
+void removeNewLine(char *str) {
+  char *newlinePos = strchr(str, '\n');
+  if (newlinePos != NULL) {
+*newlinePos = '\0'; // Replace with null terminator
+  }
+}
+
+std::int32_t RTNAME(FDate)(const Descriptor *value, const Descriptor *errmsg) {
+  FillWithSpaces(*value);
+
+  time_t current_time;
+  time(¤t_time);
+
+  char *time_string = ctime(¤t_time);
+  removeNewLine(time_string);
+  std::int64_t stringLen{StringLength(time_string)};
+  if (stringLen <= 0) {
+return ToErrmsg(errmsg, StatMissingArgument);
+  }
+
+  if (value) {
+return CopyToDescriptor(*value, time_string, stringLen, errmsg);
+  }
+
+  return StatOk;
+}
+
 std::int32_t RTNAME(GetCommandArgument)(std::int32_t n, const Descriptor 
*value,
 const Descriptor *length, const Descriptor *errmsg, const char *sourceFile,
 int line) {
diff --git a/flang/run

[clang] [libcxx] [libc] [compiler-rt] [clang-tools-extra] [flang] [llvm] [lldb] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

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

https://github.com/PAX-12-WU updated 
https://github.com/llvm/llvm-project/pull/71222

>From e0d99fb5baa4231ab351f7fd5abf0a1ffe589547 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:55:06 +
Subject: [PATCH 1/6] FDATE extension implementation: get date and time in
 ctime format

reference to gfortran fdate https://gcc.gnu.org/onlinedocs/gfortran/FDATE.html
usage:
CHARACTER(32) :: time
CALL fdate(time)
WRITE(*,*) time
---
 flang/docs/Intrinsics.md |  2 +-
 flang/include/flang/Runtime/command.h|  5 +
 flang/include/flang/Runtime/extensions.h |  2 ++
 flang/runtime/command.cpp| 28 
 flang/runtime/extensions.cpp |  5 +
 flang/unittests/Runtime/CommandTest.cpp  | 14 
 6 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e5538..982be8208164296 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, FDATE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec6289390545479..07f6d8e169ead6c 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -23,6 +23,11 @@ extern "C" {
 // integer kind.
 std::int32_t RTNAME(ArgumentCount)();
 
+// Try to get the the current date (same format as CTIME: convert to a string)
+// Return a STATUS as described in the standard.
+std::int32_t RTNAME(FDate)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 // 16.9.82 GET_COMMAND
 // Try to get the value of the whole command. All of the parameters are
 // optional.
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb79..92b9907860121aa 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -24,6 +24,8 @@ void FORTRAN_PROCEDURE_NAME(flush)(const int &unit);
 // GNU Fortran 77 compatibility function IARGC.
 std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 
+void FORTRAN_PROCEDURE_NAME(fdate)(std::int8_t *string, std::int64_t length);
+
 // GNU Fortran 77 compatibility subroutine GETARG(N, ARG).
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t &n, std::int8_t *arg, std::int64_t length);
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e571b..da0803c39f49b6d 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -14,6 +14,7 @@
 #include "flang/Runtime/descriptor.h"
 #include 
 #include 
+#include 
 
 namespace Fortran::runtime {
 std::int32_t RTNAME(ArgumentCount)() {
@@ -125,6 +126,33 @@ static bool FitsInDescriptor(
   kind, terminator, value);
 }
 
+void removeNewLine(char *str) {
+  char *newlinePos = strchr(str, '\n');
+  if (newlinePos != NULL) {
+*newlinePos = '\0'; // Replace with null terminator
+  }
+}
+
+std::int32_t RTNAME(FDate)(const Descriptor *value, const Descriptor *errmsg) {
+  FillWithSpaces(*value);
+
+  time_t current_time;
+  time(¤t_time);
+
+  char *time_string = ctime(¤t_time);
+  removeNewLine(time_string);
+  std::int64_t stringLen{StringLength(time_string)};
+  if (stringLen <= 0) {
+return ToErrmsg(errmsg, StatMissingArgument);
+  }
+
+  if (value) {
+return CopyToDescriptor(*value, time_string, stringLen, errmsg);
+  }
+
+  return StatOk;
+}
+
 std::int32_t RTNAME(GetCommandArgument)(std::int32_t n, const Descriptor 
*value,
 const Descriptor *length, const Descriptor *errmsg, const char *sourceFile,
 int line) {
diff --git a/flang/run

[clang] [clang-tools-extra] [clang][AST] Fix crash in MatchChildASTVisitor::TraverseLambdaExpr (PR #70962)

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

AaronBallman wrote:

> Would be nice to simply not crash in such case, whatever someone will fix 
> origin issue later is up to debate. I would like to see this change on 17.0.6 
> (that means 2 weeks left to merge this). Unless someone fixes this somewere 
> in lower layers.

The worry with pushing this as a fix is that it seems to be papering over a 
real issue; if we "fix" it this way, 1) less incentive to go fix the actual 
issue, and 2) easy to forget to come tear this code back out when we do fix it 
and that makes future maintenance harder.

I don't think this should change for 17.0.6 unless we have a correct fix that 
we agree is *definitely* safe and correct.

Unfortunately, I think we need to spend some time looking into the root cause 
more (not certain when I'll have the time to poke at that myself, but it would 
likely be in the next year timeframe for me at this point due to holidays 
coming up).

You can definitely see the NULL entry in the AST in 
https://godbolt.org/z/bax6Ghj3n but the code also seems to behave correctly and 
the assembly generated seems reasonable. I think the issue is likely near here: 
https://github.com/llvm/llvm-project/blob/108380da357e2db513f016d33adede0d58636bea/clang/include/clang/AST/RecursiveASTVisitor.h#L2657

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


[clang] [llvm] [clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2023-11-16 Thread via cfe-commits

https://github.com/kuganv updated 
https://github.com/llvm/llvm-project/pull/70801

>From 1d50caf93e4b8fb3fc9e24fe7fba83b328f08d57 Mon Sep 17 00:00:00 2001
From: Kugan <34810920+kug...@users.noreply.github.com>
Date: Tue, 31 Oct 2023 12:12:10 +
Subject: [PATCH] Apply format only if --format is specified

clang-apply-replacements is now applying format even when --format is 
specified.  This because, methods like createReplacementsForHeaders only takes 
the Spec.Style and would re-order the headers even when it was not requested. 
The fix is to set up Spec.Style only if --format is provided.
---
 .../tool/ClangApplyReplacementsMain.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
 
b/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
index 9331898bf2570e6..68b5743c6540f8a 100644
--- 
a/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
+++ 
b/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
@@ -141,9 +141,9 @@ int main(int argc, char **argv) {
 
   tooling::ApplyChangesSpec Spec;
   Spec.Cleanup = true;
-  Spec.Style = FormatStyle;
   Spec.Format = DoFormat ? tooling::ApplyChangesSpec::kAll
  : tooling::ApplyChangesSpec::kNone;
+  Spec.Style = DoFormat ? FormatStyle : format::getNoStyle();
 
   for (const auto &FileChange : Changes) {
 FileEntryRef Entry = FileChange.first;

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


[clang] 27e6e4a - [CUDA][HIP] make trivial ctor/dtor host device (#72394)

2023-11-16 Thread via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-11-16T08:42:54-05:00
New Revision: 27e6e4a4d0e3296cebad8db577ec0469a286795e

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

LOG: [CUDA][HIP] make trivial ctor/dtor host device (#72394)

Make trivial ctor/dtor implicitly host device functions so that they can
be used to initialize file-scope
device variables to match nvcc behavior.

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

Fixes: SWDEV-432412

Added: 
clang/test/SemaCUDA/trivial-ctor-dtor.cu

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCUDA/call-host-fn-from-device.cu
clang/test/SemaCUDA/default-ctor.cu
clang/test/SemaCUDA/implicit-member-target-collision-cxx11.cu
clang/test/SemaCUDA/implicit-member-target-collision.cu
clang/test/SemaCUDA/implicit-member-target-inherited.cu
clang/test/SemaCUDA/implicit-member-target.cu

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 731d0886a7367dc..501dc01200a1c34 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13453,6 +13453,10 @@ class Sema final {
   void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD,
const LookupResult &Previous);
 
+  /// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to a
+  /// trivial cotr/dtor that does not have host and device attributes.
+  void maybeAddCUDAHostDeviceAttrsToTrivialCtorDtor(FunctionDecl *FD);
+
   /// May add implicit CUDAConstantAttr attribute to VD, depending on VD
   /// and current compilation settings.
   void MaybeAddCUDAConstantAttr(VarDecl *VD);

diff  --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 318174f7be8fa95..b94f448dabe7517 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -772,6 +772,22 @@ void Sema::maybeAddCUDAHostDeviceAttrs(FunctionDecl *NewD,
   NewD->addAttr(CUDADeviceAttr::CreateImplicit(Context));
 }
 
+// If a trivial ctor/dtor has no host/device
+// attributes, make it implicitly host device function.
+void Sema::maybeAddCUDAHostDeviceAttrsToTrivialCtorDtor(FunctionDecl *FD) {
+  bool IsTrivialCtor = false;
+  if (auto *CD = dyn_cast(FD))
+IsTrivialCtor = isEmptyCudaConstructor(SourceLocation(), CD);
+  bool IsTrivialDtor = false;
+  if (auto *DD = dyn_cast(FD))
+IsTrivialDtor = isEmptyCudaDestructor(SourceLocation(), DD);
+  if ((IsTrivialCtor || IsTrivialDtor) && !FD->hasAttr() &&
+  !FD->hasAttr()) {
+FD->addAttr(CUDAHostAttr::CreateImplicit(Context));
+FD->addAttr(CUDADeviceAttr::CreateImplicit(Context));
+  }
+}
+
 // TODO: `__constant__` memory may be a limited resource for certain targets.
 // A safeguard may be needed at the end of compilation pipeline if
 // `__constant__` memory usage goes beyond limit.

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3876eb501083acb..a6cd0bb9ea2a829 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16232,6 +16232,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
   if (FD && !FD->isDeleted())
 checkTypeSupport(FD->getType(), FD->getLocation(), FD);
 
+  if (LangOpts.CUDA)
+maybeAddCUDAHostDeviceAttrsToTrivialCtorDtor(FD);
+
   return dcl;
 }
 

diff  --git a/clang/test/SemaCUDA/call-host-fn-from-device.cu 
b/clang/test/SemaCUDA/call-host-fn-from-device.cu
index acdd291b664579b..b62de92db02d6de 100644
--- a/clang/test/SemaCUDA/call-host-fn-from-device.cu
+++ b/clang/test/SemaCUDA/call-host-fn-from-device.cu
@@ -12,7 +12,7 @@ extern "C" void host_fn() {}
 struct Dummy {};
 
 struct S {
-  S() {}
+  S() { static int nontrivial_ctor = 1; }
   // expected-note@-1 2 {{'S' declared here}}
   ~S() { host_fn(); }
   // expected-note@-1 {{'~S' declared here}}

diff  --git a/clang/test/SemaCUDA/default-ctor.cu 
b/clang/test/SemaCUDA/default-ctor.cu
index cbad7a1774c1501..31971fe6b3863c7 100644
--- a/clang/test/SemaCUDA/default-ctor.cu
+++ b/clang/test/SemaCUDA/default-ctor.cu
@@ -25,7 +25,7 @@ __device__ void fd() {
   InD ind;
   InH inh; // expected-error{{no matching constructor for initialization of 
'InH'}}
   InHD inhd;
-  Out out; // expected-error{{no matching constructor for initialization of 
'Out'}}
+  Out out;
   OutD outd;
   OutH outh; // expected-error{{no matching constructor for initialization of 
'OutH'}}
   OutHD outhd;

diff  --git a/clang/test/SemaCUDA/implicit-member-target-collision-cxx11.cu 
b/clang/test/SemaCUDA/implicit-member-target-collision-cxx11.cu
index 06015ed0d6d8edc..edb543f637ccc18 100644
--- a/clang/test/SemaCUDA/implicit-member-target-collision-cxx11.cu
+++ b/clang/test/SemaCUDA/implicit-member-target-collision-cx

[clang] [CUDA][HIP] make trivial ctor/dtor host device (PR #72394)

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

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


[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-11-16 Thread Simon Tatham via cfe-commits

https://github.com/statham-arm updated 
https://github.com/llvm/llvm-project/pull/69447

>From 2a65ae75e8c8e62e7275a439849837919599e896 Mon Sep 17 00:00:00 2001
From: Simon Tatham 
Date: Thu, 14 Sep 2023 14:51:17 +0100
Subject: [PATCH 1/4] [Driver] Add ExclusiveGroup feature to multilib.yaml.

This allows a YAML-based multilib configuration to specify explicitly
that a subset of its library directories are alternatives to each
other, i.e. at most one of that subset should be selected.

So if you have multiple sysroots each including a full set of headers
and libraries, you can mark them as members of the same
ExclusiveGroup, and then you'll be sure that only one of them is
selected, even if two or more are compatible with the compile options.

This is particularly important in multilib setups including the libc++
headers, where selecting the include directories from two different
sysroots can cause an actual build failure. This occurs when including
, for example: libc++'s stdio.h is included first, and will
try to use `#include_next` to fetch the underlying libc's version. But
if there are two include directories from separate multilibs, then
both of their C++ include directories will end up on the include path
first, followed by both the C directories. So the `#include_next` from
the first libc++ stdio.h will include the second libc++ stdio.h, which
will do nothing because it has the same include guard macro, and the
libc header won't ever be included at all.

If more than one of the options in an ExclusiveGroup matches the given
flags, the last one wins.
---
 clang/include/clang/Driver/Multilib.h | 16 -
 clang/lib/Driver/Multilib.cpp | 49 ++---
 .../baremetal-multilib-exclusive-group.yaml   | 69 +++
 3 files changed, 122 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/Driver/baremetal-multilib-exclusive-group.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index 1416559414f894b..6a9533e6dd831f1 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -39,13 +39,22 @@ class Multilib {
   std::string IncludeSuffix;
   flags_list Flags;
 
+  // Optionally, a multilib can be assigned a string tag indicating that it's
+  // part of a group of mutually exclusive possibilities. If two or more
+  // multilibs have the same non-empty value of ExclusiveGroup, then only the
+  // last matching one of them will be selected.
+  //
+  // Setting this to the empty string is a special case, indicating that the
+  // directory is not mutually exclusive with anything else.
+  std::string ExclusiveGroup;
+
 public:
   /// GCCSuffix, OSSuffix & IncludeSuffix will be appended directly to the
   /// sysroot string so they must either be empty or begin with a '/' 
character.
   /// This is enforced with an assert in the constructor.
   Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
-   StringRef IncludeSuffix = {},
-   const flags_list &Flags = flags_list());
+   StringRef IncludeSuffix = {}, const flags_list &Flags = 
flags_list(),
+   StringRef ExclusiveGroup = {});
 
   /// Get the detected GCC installation path suffix for the multi-arch
   /// target variant. Always starts with a '/', unless empty
@@ -63,6 +72,9 @@ class Multilib {
   /// All elements begin with either '-' or '!'
   const flags_list &flags() const { return Flags; }
 
+  /// Get the exclusive group label.
+  const std::string &exclusiveGroup() const { return ExclusiveGroup; }
+
   LLVM_DUMP_METHOD void dump() const;
   /// print summary of the Multilib
   void print(raw_ostream &OS) const;
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 48a494d9fa38db5..085ccee7b25752e 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -29,9 +29,10 @@ using namespace driver;
 using namespace llvm::sys;
 
 Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,
-   StringRef IncludeSuffix, const flags_list &Flags)
+   StringRef IncludeSuffix, const flags_list &Flags,
+   StringRef ExclusiveGroup)
 : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),
-  Flags(Flags) {
+  Flags(Flags), ExclusiveGroup(ExclusiveGroup) {
   assert(GCCSuffix.empty() ||
  (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
   assert(OSSuffix.empty() ||
@@ -96,13 +97,39 @@ bool MultilibSet::select(const Multilib::flags_list &Flags,
  llvm::SmallVector &Selected) const {
   llvm::StringSet<> FlagSet(expandFlags(Flags));
   Selected.clear();
-  llvm::copy_if(Multilibs, std::back_inserter(Selected),
-[&FlagSet](const Multilib &M) {
-  for (const std::string &F : M.flags())
-if (!FlagSet.contains(F))
-  return false;
-  return 

[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-11-16 Thread Simon Tatham via cfe-commits

statham-arm wrote:

OK, here's a version with the syntax that way. I've added another test to 
demonstrate the new error checks.

The implementation of exclusion is still done by having an `ExclusiveGroup` 
field in the actual `Multilib` class. Implementing mutually-dependent groups or 
nested groups is enough extra effort that I'd rather leave it until we actually 
need it! But now the user-facing syntax in `multilib.yaml` is futureproof 
against wanting to add those features later, so _only_ the implementation 
should need to change.

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


[clang] [compiler-rt] [flang] [llvm] [clang-tools-extra] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-16 Thread via cfe-commits


@@ -322,6 +322,71 @@ static Attr *handleUnlikely(Sema &S, Stmt *St, const 
ParsedAttr &A,
   return ::new (S.Context) UnlikelyAttr(S.Context, A);
 }
 
+CodeAlignAttr *Sema::BuildCodeAlignAttr(const AttributeCommonInfo &CI,
+Expr *E) {
+  if (!E->isValueDependent()) {
+llvm::APSInt ArgVal;
+ExprResult Res = VerifyIntegerConstantExpression(E, &ArgVal);
+if (Res.isInvalid())
+  return nullptr;
+E = Res.get();
+
+// This attribute requires an integer argument which is a constant power of
+// two between 1 and 4096 inclusive.
+if (ArgVal < CodeAlignAttr::MinimumAlignment ||
+   ArgVal > CodeAlignAttr::MaximumAlignment ||
+(ArgVal < CodeAlignAttr::MaximumAlignment && !ArgVal.isPowerOf2())) {
+  if (std::optional Value = ArgVal.trySExtValue())
+Diag(CI.getLoc(), diag::err_attribute_power_of_two_in_range)
+<< CI << CodeAlignAttr::MinimumAlignment
+<< CodeAlignAttr::MaximumAlignment << Value.value();
+  else
+Diag(CI.getLoc(), diag::err_attribute_power_of_two_in_range)
+<< CI << CodeAlignAttr::MinimumAlignment
+<< CodeAlignAttr::MaximumAlignment << E;
+  return nullptr;
+}
+  }
+  return new (Context) CodeAlignAttr(Context, CI, E);
+}
+
+static Attr *handleCodeAlignAttr(Sema &S, Stmt *St, const ParsedAttr &A) {
+
+  Expr *E = A.getArgAsExpr(0);
+  return S.BuildCodeAlignAttr(A, E);
+}
+
+// Emit duplicate error for [[clang::code_align()]] attribute.
+static void CheckForDuplicateCodeAlignAttrs(Sema &S,
+ArrayRef Attrs) {
+  // Create a list of CodeAlign attributes only.
+  SmallVector OnlyCodeAlignAttrs;

smanna12 wrote:

@erichkeane, i have updated duplicate attribute values check with commit 
https://github.com/llvm/llvm-project/pull/70762/commits/a8b13eb4846d6f1cb41b12088aa371b3fe4edd24
 in a simpler way.

>>What is the point of going through all of this?

I could not able figure out in a simple way, so ended up going through all of 
this while using llvm::find_if()

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


[clang] [compiler-rt] [flang] [llvm] [clang-tools-extra] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-16 Thread via cfe-commits

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


[clang] [APINotes] Upstream APINotesManager (PR #72389)

2023-11-16 Thread Egor Zhdan via cfe-commits

https://github.com/egorzhdan updated 
https://github.com/llvm/llvm-project/pull/72389

>From c4c9e3bffdcc80d7c153c0c4945844876894d98e Mon Sep 17 00:00:00 2001
From: Egor Zhdan 
Date: Wed, 15 Nov 2023 13:46:54 +
Subject: [PATCH] [APINotes] Upstream APINotesManager

This upstreams more of the Clang API Notes functionality that is currently 
implemented in the Apple fork: 
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes
---
 .../include/clang/APINotes/APINotesManager.h  | 175 +++
 clang/include/clang/APINotes/Types.h  |   3 +
 .../clang/Basic/DiagnosticCommonKinds.td  |  13 +
 clang/include/clang/Basic/LangOptions.def |   2 +
 clang/include/clang/Basic/Module.h|   3 +
 clang/include/clang/Basic/SourceMgrAdapter.h  |  85 
 clang/lib/APINotes/APINotesManager.cpp| 458 ++
 clang/lib/APINotes/CMakeLists.txt |   1 +
 clang/lib/Basic/CMakeLists.txt|   1 +
 clang/lib/Basic/SourceMgrAdapter.cpp  | 136 ++
 10 files changed, 877 insertions(+)
 create mode 100644 clang/include/clang/APINotes/APINotesManager.h
 create mode 100644 clang/include/clang/Basic/SourceMgrAdapter.h
 create mode 100644 clang/lib/APINotes/APINotesManager.cpp
 create mode 100644 clang/lib/Basic/SourceMgrAdapter.cpp

diff --git a/clang/include/clang/APINotes/APINotesManager.h 
b/clang/include/clang/APINotes/APINotesManager.h
new file mode 100644
index 000..823b52ed28b5981
--- /dev/null
+++ b/clang/include/clang/APINotes/APINotesManager.h
@@ -0,0 +1,175 @@
+//===--- APINotesManager.h - Manage API Notes Files -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_APINOTES_APINOTESMANAGER_H
+#define LLVM_CLANG_APINOTES_APINOTESMANAGER_H
+
+#include "clang/Basic/Module.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VersionTuple.h"
+#include 
+#include 
+
+namespace clang {
+
+class DirectoryEntry;
+class FileEntry;
+class LangOptions;
+class SourceManager;
+
+namespace api_notes {
+
+class APINotesReader;
+
+/// The API notes manager helps find API notes associated with declarations.
+///
+/// API notes are externally-provided annotations for declarations that can
+/// introduce new attributes (covering availability, nullability of
+/// parameters/results, and so on) for specific declarations without directly
+/// modifying the headers that contain those declarations.
+///
+/// The API notes manager is responsible for finding and loading the
+/// external API notes files that correspond to a given header. Its primary
+/// operation is \c findAPINotes(), which finds the API notes reader that
+/// provides information about the declarations at that location.
+class APINotesManager {
+  using ReaderEntry = llvm::PointerUnion;
+
+  SourceManager &SM;
+
+  /// Whether to implicitly search for API notes files based on the
+  /// source file from which an entity was declared.
+  bool ImplicitAPINotes;
+
+  /// The Swift version to use when interpreting versioned API notes.
+  llvm::VersionTuple SwiftVersion;
+
+  enum ReaderKind : unsigned { Public = 0, Private = 1 };
+
+  /// API notes readers for the current module.
+  ///
+  /// There can be up to two of these, one for public headers and one
+  /// for private headers.
+  ///
+  /// Not using std::unique_ptr to store these, since the reader pointers are
+  /// also stored in llvm::PointerUnion below.
+  APINotesReader *CurrentModuleReaders[2] = {nullptr, nullptr};
+
+  /// A mapping from header file directories to the API notes reader for
+  /// that directory, or a redirection to another directory entry that may
+  /// have more information, or NULL to indicate that there is no API notes
+  /// reader for this directory.
+  llvm::DenseMap Readers;
+
+  /// Load the API notes associated with the given file, whether it is
+  /// the binary or source form of API notes.
+  ///
+  /// \returns the API notes reader for this file, or null if there is
+  /// a failure.
+  std::unique_ptr loadAPINotes(FileEntryRef APINotesFile);
+
+  /// Load the API notes associated with the given buffer, whether it is
+  /// the binary or source form of API notes.
+  ///
+  /// \returns the API notes reader for this file, or null if there is
+  /// a failure.
+  std::unique_ptr loadAPINotes(StringRef Buffer);
+
+  /// Load the given API notes file for the given header directory.
+  ///
+  /// \param HeaderDir The directory at which we
+  ///
+  /// \returns true if an error occurred.
+  bool loadAPINotes(const DirectoryEntry *HeaderDir, FileEntryRef 
APINotesF

[clang] [APINotes] Upstream APINotesManager (PR #72389)

2023-11-16 Thread Egor Zhdan via cfe-commits


@@ -0,0 +1,163 @@
+//===--- APINotesManager.h - Manage API Notes Files -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_APINOTES_APINOTESMANAGER_H
+#define LLVM_CLANG_APINOTES_APINOTESMANAGER_H
+
+#include "clang/Basic/Module.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VersionTuple.h"
+#include 
+#include 
+
+namespace clang {
+
+class DirectoryEntry;
+class FileEntry;
+class LangOptions;
+class SourceManager;
+
+namespace api_notes {
+
+class APINotesReader;
+
+/// The API notes manager helps find API notes associated with declarations.
+///
+/// API notes are externally-provided annotations for declarations that can
+/// introduce new attributes (covering availability, nullability of
+/// parameters/results, and so on) for specific declarations without directly
+/// modifying the headers that contain those declarations.
+///
+/// The API notes manager is responsible for finding and loading the
+/// external API notes files that correspond to a given header. Its primary
+/// operation is \c findAPINotes(), which finds the API notes reader that
+/// provides information about the declarations at that location.
+class APINotesManager {
+  using ReaderEntry = llvm::PointerUnion;
+
+  SourceManager &SM;
+
+  /// Whether to implicitly search for API notes files based on the
+  /// source file from which an entity was declared.
+  bool ImplicitAPINotes;
+
+  /// The Swift version to use when interpreting versioned API notes.
+  llvm::VersionTuple SwiftVersion;
+
+  /// API notes readers for the current module.
+  ///
+  /// There can be up to two of these, one for public headers and one
+  /// for private headers.
+  APINotesReader *CurrentModuleReaders[2] = {nullptr, nullptr};
+
+  /// A mapping from header file directories to the API notes reader for
+  /// that directory, or a redirection to another directory entry that may
+  /// have more information, or NULL to indicate that there is no API notes
+  /// reader for this directory.
+  llvm::DenseMap Readers;
+
+  /// Load the API notes associated with the given file, whether it is
+  /// the binary or source form of API notes.
+  ///
+  /// \returns the API notes reader for this file, or null if there is
+  /// a failure.
+  std::unique_ptr loadAPINotes(FileEntryRef APINotesFile);
+
+  /// Load the API notes associated with the given buffer, whether it is
+  /// the binary or source form of API notes.
+  ///
+  /// \returns the API notes reader for this file, or null if there is
+  /// a failure.
+  std::unique_ptr loadAPINotes(StringRef Buffer);
+
+  /// Load the given API notes file for the given header directory.
+  ///
+  /// \param HeaderDir The directory at which we
+  ///
+  /// \returns true if an error occurred.
+  bool loadAPINotes(const DirectoryEntry *HeaderDir, FileEntryRef 
APINotesFile);
+
+  /// Look for API notes in the given directory.
+  ///
+  /// This might find either a binary or source API notes.
+  OptionalFileEntryRef findAPINotesFile(DirectoryEntryRef Directory,
+StringRef FileName,
+bool WantPublic = true);
+
+  /// Attempt to load API notes for the given framework.
+  ///
+  /// \param FrameworkPath The path to the framework.
+  /// \param Public Whether to load the public API notes. Otherwise, attempt
+  /// to load the private API notes.
+  ///
+  /// \returns the header directory entry (e.g., for Headers or PrivateHeaders)
+  /// for which the API notes were successfully loaded, or NULL if API notes
+  /// could not be loaded for any reason.
+  OptionalDirectoryEntryRef loadFrameworkAPINotes(llvm::StringRef 
FrameworkPath,

egorzhdan wrote:

Good point, added a comment to reflect that

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


[clang] [APINotes] Upstream APINotesManager (PR #72389)

2023-11-16 Thread Egor Zhdan via cfe-commits


@@ -0,0 +1,469 @@
+//===--- APINotesManager.cpp - Manage API Notes Files 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/APINotes/APINotesManager.h"
+#include "clang/APINotes/APINotesReader.h"
+#include "clang/APINotes/APINotesYAMLCompiler.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/SourceMgrAdapter.h"
+#include "clang/Basic/Version.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/PrettyStackTrace.h"
+
+using namespace clang;
+using namespace api_notes;
+
+#define DEBUG_TYPE "API Notes"
+STATISTIC(NumHeaderAPINotes, "non-framework API notes files loaded");
+STATISTIC(NumPublicFrameworkAPINotes, "framework public API notes loaded");
+STATISTIC(NumPrivateFrameworkAPINotes, "framework private API notes loaded");
+STATISTIC(NumFrameworksSearched, "frameworks searched");
+STATISTIC(NumDirectoriesSearched, "header directories searched");
+STATISTIC(NumDirectoryCacheHits, "directory cache hits");
+
+namespace {
+/// Prints two successive strings, which much be kept alive as long as the
+/// PrettyStackTrace entry.
+class PrettyStackTraceDoubleString : public llvm::PrettyStackTraceEntry {
+  StringRef First, Second;
+
+public:
+  PrettyStackTraceDoubleString(StringRef First, StringRef Second)
+  : First(First), Second(Second) {}
+  void print(raw_ostream &OS) const override { OS << First << Second; }
+};
+} // namespace
+
+APINotesManager::APINotesManager(SourceManager &SM, const LangOptions 
&LangOpts)
+: SM(SM), ImplicitAPINotes(LangOpts.APINotes) {}
+
+APINotesManager::~APINotesManager() {
+  // Free the API notes readers.
+  for (const auto &Entry : Readers) {
+if (auto Reader = Entry.second.dyn_cast())

egorzhdan wrote:

Done, added a comment

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


[clang] [clang][Interp] Implement IntegralAP::mul() (PR #72491)

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

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


[clang] 4cf996d - [clang][Interp] Implement IntegralAP::mul() (#72491)

2023-11-16 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-11-16T15:06:11+01:00
New Revision: 4cf996d6a20d8fd0817c953fd383d261409e6d04

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

LOG: [clang][Interp] Implement IntegralAP::mul() (#72491)

Added: 


Modified: 
clang/lib/AST/Interp/IntegralAP.h
clang/test/AST/Interp/intap.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index d85904a8f9572eb..bd665959cf3dcc4 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -191,17 +191,15 @@ template  class IntegralAP final {
   }
 
   static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-return CheckAddSubUB(A, B, OpBits, R);
+return CheckAddSubMulUB(A, B, OpBits, R);
   }
 
   static bool sub(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-return CheckAddSubUB(A, B, OpBits, R);
+return CheckAddSubMulUB(A, B, OpBits, R);
   }
 
   static bool mul(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-return false;
+return CheckAddSubMulUB(A, B, OpBits, R);
   }
 
   static bool rem(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
@@ -262,8 +260,8 @@ template  class IntegralAP final {
 
 private:
   template  class Op>
-  static bool CheckAddSubUB(const IntegralAP &A, const IntegralAP &B,
-unsigned BitWidth, IntegralAP *R) {
+  static bool CheckAddSubMulUB(const IntegralAP &A, const IntegralAP &B,
+   unsigned BitWidth, IntegralAP *R) {
 if constexpr (!Signed) {
   R->V = Op{}(A.V, B.V);
   return false;

diff  --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 4a18f1f9459e301..c93ec331296647b 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -35,6 +35,15 @@ static_assert(UBitIntZero1 == 0, "");
 constexpr unsigned _BitInt(2) BI1 = 3u;
 static_assert(BI1 == 3, "");
 
+constexpr _BitInt(4) MulA = 5;
+constexpr _BitInt(4) MulB = 7;
+static_assert(MulA * MulB == 50, ""); // ref-error {{not an integral constant 
expression}} \
+  // ref-note {{value 35 is outside the 
range of representable values of type '_BitInt(4)'}} \
+  // expected-error {{not an integral 
constant expression}} \
+  // expected-note {{value 35 is outside 
the range of representable values of type '_BitInt(4)'}}
+static_assert(MulA * 5 == 25, "");
+static_assert(-1 * MulB == -7, "");
+
 namespace APCast {
   constexpr _BitInt(10) A = 1;
   constexpr _BitInt(11) B = A;
@@ -66,6 +75,8 @@ namespace i128 {
// ref-error {{static assertion 
failed}} \
// ref-note 
{{'340282366920938463463374607431768211455 == 1'}}
 
+  constexpr uint128_t TooMuch = UINT128_MAX * 2;
+
   static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
   static_assert(INT128_MAX != 0, "");
   static_assert(INT128_MAX == 0, ""); // expected-error {{failed}} \
@@ -73,6 +84,11 @@ namespace i128 {
   // ref-error {{failed}} \
   // ref-note {{evaluates to 
'170141183460469231731687303715884105727 == 0'}}
 
+  constexpr int128_t TooMuch2 = INT128_MAX * INT128_MAX; // ref-error {{must 
be initialized by a constant expression}} \
+// ref-note {{value 
28948022309329048855892746252171976962977213799489202546401021394546514198529 
is outside the range of representable}} \
+// expected-error {{must be 
initialized by a constant expression}} \
+// expected-note {{value 
28948022309329048855892746252171976962977213799489202546401021394546514198529 
is outside the range of representable}}
+
   static const __int128_t INT128_MIN = -INT128_MAX - 1;
   constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be 
initialized by a constant expression}} \
  // expected-note {{value 
170141183460469231731687303715884105728 is outside the range}} \



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


[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-16 Thread Lu Weining via cfe-commits

https://github.com/SixWeining created 
https://github.com/llvm/llvm-project/pull/72514

7e42545 rejects unsupported mcmodel options, but small/medium/large should be 
supported models for LoongArch. In addition, to be compatible with gcc, mapping 
some of their values to clang's.

The mapping is:
```
 gcc  vs clang
   "normal""small"
   "medium""medium"
   "extreme"   "large"
```

And AFAIK, gcc side doesn't plan to implement the "large" code model.

Link: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html
Link: https://reviews.llvm.org/D150522

>From 8dd5bebcd4681e5e7849743aba0ce90c2959ee23 Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Thu, 16 Nov 2023 21:57:03 +0800
Subject: [PATCH] [Driver] Support -mcmodel= for LoongArch

7e42545 rejects unsupported mcmodel options, but small/medium/large
should be supported models for LoongArch. In addition, to be compatible
with gcc, mapping some of their values to clang's.

The mapping is:
 gcc[1] vs clang[2]
   "normal""small"
   "medium""medium"
   "extreme"   "large"

And AFAIK, gcc side doesn't plan to implement the "large" code model.

[1]: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html
[2]: https://reviews.llvm.org/D150522
---
 clang/lib/Driver/ToolChains/Clang.cpp | 10 ++
 clang/test/Driver/mcmodel.c   | 13 +
 2 files changed, 23 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b462f5a44057d94..3a7e56f37259cb8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (CM == "large" && RelocationModel != llvm::Reloc::Static)
 D.Diag(diag::err_drv_argument_only_allowed_with)
 << A->getAsString(Args) << "-fno-pic";
+} else if (Triple.isLoongArch()) {
+  CM = llvm::StringSwitch(CM)
+   .Case("normal", "small")
+   .Case("extreme", "large")
+   .Default(CM);
+  if (CM == "large" &&
+  Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false))
+D.Diag(diag::err_drv_argument_not_allowed_with)
+<< A->getAsString(Args) << "-fplt";
+  Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isPPC64() || Triple.isOSAIX()) {
   Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isRISCV()) {
diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c
index d8a41b0f5abd9aa..72be740216a81b3 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -15,6 +15,15 @@
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=ERR-MEDIUM %s
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
 // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | 
FileCheck --check-prefix=ERR-AARCH64_32 %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck 
--check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | 
FileCheck --check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=MEDIUM %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=large %s 2>&1 | FileCheck 
--check-prefix=LARGE %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | 
FileCheck --check-prefix=LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=tiny %s 2>&1 | 
FileCheck --check-prefix=ERR-TINY %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=large -fplt %s 2>&1 | 
FileCheck --check-prefix=ERR-LOONGARCH64-PLT-LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=extreme -fplt %s 2>&1 
| FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s
 
 // TINY: "-mcmodel=tiny"
 // SMALL: "-mcmodel=small"
@@ -25,9 +34,13 @@
 
 // INVALID: error: unsupported argument 'lager' to option '-mcmodel=' for 
target '{{.*}}'
 
+// ERR-TINY: error: unsupported argument 'tiny' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-MEDIUM: error: unsupported argument 'medium' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-KERNEL: error: unsupported argument 'kernel' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-LARGE:  error: unsupported argument 'large' to option '-mcmodel=' for 
target '{{.*}}'
 
 // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed 
with '-fno-pic'
 // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' 
for target 'aarch64_32-unknown-linux'
+
+// ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not 
allowed with '-fplt'
+

[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Lu Weining (SixWeining)


Changes

7e42545 rejects unsupported mcmodel options, but small/medium/large should be 
supported models for LoongArch. In addition, to be compatible with gcc, mapping 
some of their values to clang's.

The mapping is:
```
 gcc  vs clang
   "normal""small"
   "medium""medium"
   "extreme"   "large"
```

And AFAIK, gcc side doesn't plan to implement the "large" code model.

Link: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html
Link: https://reviews.llvm.org/D150522

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+10) 
- (modified) clang/test/Driver/mcmodel.c (+13) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b462f5a44057d94..3a7e56f37259cb8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (CM == "large" && RelocationModel != llvm::Reloc::Static)
 D.Diag(diag::err_drv_argument_only_allowed_with)
 << A->getAsString(Args) << "-fno-pic";
+} else if (Triple.isLoongArch()) {
+  CM = llvm::StringSwitch(CM)
+   .Case("normal", "small")
+   .Case("extreme", "large")
+   .Default(CM);
+  if (CM == "large" &&
+  Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false))
+D.Diag(diag::err_drv_argument_not_allowed_with)
+<< A->getAsString(Args) << "-fplt";
+  Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isPPC64() || Triple.isOSAIX()) {
   Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isRISCV()) {
diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c
index d8a41b0f5abd9aa..72be740216a81b3 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -15,6 +15,15 @@
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=ERR-MEDIUM %s
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
 // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | 
FileCheck --check-prefix=ERR-AARCH64_32 %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck 
--check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | 
FileCheck --check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=MEDIUM %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=large %s 2>&1 | FileCheck 
--check-prefix=LARGE %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | 
FileCheck --check-prefix=LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=tiny %s 2>&1 | 
FileCheck --check-prefix=ERR-TINY %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=large -fplt %s 2>&1 | 
FileCheck --check-prefix=ERR-LOONGARCH64-PLT-LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=extreme -fplt %s 2>&1 
| FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s
 
 // TINY: "-mcmodel=tiny"
 // SMALL: "-mcmodel=small"
@@ -25,9 +34,13 @@
 
 // INVALID: error: unsupported argument 'lager' to option '-mcmodel=' for 
target '{{.*}}'
 
+// ERR-TINY: error: unsupported argument 'tiny' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-MEDIUM: error: unsupported argument 'medium' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-KERNEL: error: unsupported argument 'kernel' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-LARGE:  error: unsupported argument 'large' to option '-mcmodel=' for 
target '{{.*}}'
 
 // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed 
with '-fno-pic'
 // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' 
for target 'aarch64_32-unknown-linux'
+
+// ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not 
allowed with '-fplt'
+// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not 
allowed with '-fplt'

``




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


[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Lu Weining (SixWeining)


Changes

7e42545 rejects unsupported mcmodel options, but small/medium/large should be 
supported models for LoongArch. In addition, to be compatible with gcc, mapping 
some of their values to clang's.

The mapping is:
```
 gcc  vs clang
   "normal""small"
   "medium""medium"
   "extreme"   "large"
```

And AFAIK, gcc side doesn't plan to implement the "large" code model.

Link: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html
Link: https://reviews.llvm.org/D150522

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+10) 
- (modified) clang/test/Driver/mcmodel.c (+13) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b462f5a44057d94..3a7e56f37259cb8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (CM == "large" && RelocationModel != llvm::Reloc::Static)
 D.Diag(diag::err_drv_argument_only_allowed_with)
 << A->getAsString(Args) << "-fno-pic";
+} else if (Triple.isLoongArch()) {
+  CM = llvm::StringSwitch(CM)
+   .Case("normal", "small")
+   .Case("extreme", "large")
+   .Default(CM);
+  if (CM == "large" &&
+  Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false))
+D.Diag(diag::err_drv_argument_not_allowed_with)
+<< A->getAsString(Args) << "-fplt";
+  Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isPPC64() || Triple.isOSAIX()) {
   Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isRISCV()) {
diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c
index d8a41b0f5abd9aa..72be740216a81b3 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -15,6 +15,15 @@
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=ERR-MEDIUM %s
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
 // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | 
FileCheck --check-prefix=ERR-AARCH64_32 %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck 
--check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | 
FileCheck --check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=MEDIUM %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=large %s 2>&1 | FileCheck 
--check-prefix=LARGE %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | 
FileCheck --check-prefix=LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=tiny %s 2>&1 | 
FileCheck --check-prefix=ERR-TINY %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=large -fplt %s 2>&1 | 
FileCheck --check-prefix=ERR-LOONGARCH64-PLT-LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=extreme -fplt %s 2>&1 
| FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s
 
 // TINY: "-mcmodel=tiny"
 // SMALL: "-mcmodel=small"
@@ -25,9 +34,13 @@
 
 // INVALID: error: unsupported argument 'lager' to option '-mcmodel=' for 
target '{{.*}}'
 
+// ERR-TINY: error: unsupported argument 'tiny' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-MEDIUM: error: unsupported argument 'medium' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-KERNEL: error: unsupported argument 'kernel' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-LARGE:  error: unsupported argument 'large' to option '-mcmodel=' for 
target '{{.*}}'
 
 // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed 
with '-fno-pic'
 // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' 
for target 'aarch64_32-unknown-linux'
+
+// ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not 
allowed with '-fplt'
+// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not 
allowed with '-fplt'

``




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


[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-16 Thread Lu Weining via cfe-commits

SixWeining wrote:

cc @xen0n @xry111 

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


[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-11-16 Thread Simon Tatham via cfe-commits

statham-arm wrote:

(btw, that `squash!` commit contains the revised commit message I plan to put 
on the final version, so I need to not forget to do the squash by hand to get 
that right)

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


Add me to LLVM-clang contributor list

2023-11-16 Thread Shahid Iqbal via cfe-commits
Hi,
I want to contribute in LLVM-clang from bug fixes perspective but cannot
assign a ticket/issue in github , please add me to contributor list

My github user: *shahidiqbal13*

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


  1   2   3   4   >