[clang] [clang-forma] Support `PointerAlignment: Left` for pointer to member (PR #86253)

2024-03-22 Thread Owen Pan via cfe-commits

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

Fixes #85761.

>From d1a3b743b808a64f022897dfd832ce9a25c8f2c0 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 21 Mar 2024 23:43:23 -0700
Subject: [PATCH] [clang-forma] Support `PointerAlignment: Left` for pointer to
 member

Fixes #85761.
---
 clang/lib/Format/TokenAnnotator.cpp   | 31 ---
 clang/unittests/Format/FormatTest.cpp |  7 +-
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 94d2266555f6b9..d54a0fe4ce6748 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4351,9 +4351,11 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;
 
+  const auto *BeforeLeft = Left.Previous;
+
   // operator co_await(x)
-  if (Right.is(tok::l_paren) && Left.is(tok::kw_co_await) && Left.Previous &&
-  Left.Previous->is(tok::kw_operator)) {
+  if (Right.is(tok::l_paren) && Left.is(tok::kw_co_await) && BeforeLeft &&
+  BeforeLeft->is(tok::kw_operator)) {
 return false;
   }
   // co_await (x), co_yield (x), co_return (x)
@@ -4404,8 +4406,8 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   return false;
   }
   if (Right.is(tok::ellipsis)) {
-return Left.Tok.isLiteral() || (Left.is(tok::identifier) && Left.Previous 
&&
-Left.Previous->is(tok::kw_case));
+return Left.Tok.isLiteral() || (Left.is(tok::identifier) && BeforeLeft &&
+BeforeLeft->is(tok::kw_case));
   }
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return Style.SpacesInSquareBrackets;
@@ -4473,8 +4475,8 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 if (Right.is(tok::l_brace) && Right.is(BK_Block))
   return true;
 // for (auto a = 0, b = 0; const auto& c : {1, 2, 3})
-if (Left.Previous && Left.Previous->isTypeOrIdentifier(IsCpp) &&
-Right.Next && Right.Next->is(TT_RangeBasedForLoopColon)) {
+if (BeforeLeft && BeforeLeft->isTypeOrIdentifier(IsCpp) && Right.Next &&
+Right.Next->is(TT_RangeBasedForLoopColon)) {
   return getTokenPointerOrReferenceAlignment(Left) !=
  FormatStyle::PAS_Right;
 }
@@ -4496,12 +4498,17 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   startsWithInitStatement(Line {
   return false;
 }
-return Left.Previous && !Left.Previous->isOneOf(
-tok::l_paren, tok::coloncolon, tok::l_square);
+if (!BeforeLeft)
+  return false;
+if (BeforeLeft->is(tok::coloncolon)) {
+  return Left.is(tok::star) &&
+ Style.PointerAlignment != FormatStyle::PAS_Right;
+}
+return !BeforeLeft->isOneOf(tok::l_paren, tok::l_square);
   }
   // Ensure right pointer alignment with ellipsis e.g. int *...P
-  if (Left.is(tok::ellipsis) && Left.Previous &&
-  Left.Previous->isPointerOrReference()) {
+  if (Left.is(tok::ellipsis) && BeforeLeft &&
+  BeforeLeft->isPointerOrReference()) {
 return Style.PointerAlignment != FormatStyle::PAS_Right;
   }
 
@@ -4663,13 +4670,13 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   return Style.SpaceBeforeParensOptions.AfterFunctionDefinitionName ||
  spaceRequiredBeforeParens(Right);
 }
-if (!Left.Previous || !Left.Previous->isOneOf(tok::period, tok::arrow)) {
+if (!BeforeLeft || !BeforeLeft->isOneOf(tok::period, tok::arrow)) {
   if (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch)) {
 return Style.SpaceBeforeParensOptions.AfterControlStatements ||
spaceRequiredBeforeParens(Right);
   }
   if (Left.isOneOf(tok::kw_new, tok::kw_delete)) {
-return ((!Line.MightBeFunctionDecl || !Left.Previous) &&
+return ((!Line.MightBeFunctionDecl || !BeforeLeft) &&
 Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
spaceRequiredBeforeParens(Right);
   }
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index bea989c8c306db..cab5556af47cc0 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11054,7 +11054,12 @@ TEST_F(FormatTest, UnderstandsPointersToMembers) {
   "aaa(aaa));");
   FormatStyle Style = getLLVMStyle();
   Style.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("typedef bool* (Class::*Member)() const;", Style);
+  verifyFormat("typedef bool* (Class::* Member)() const;", Style);
+  verifyFormat("void function(int A::* parameter, int* parameter2) {\n"
+   "  int A::* variable = &A::B;\n"
+   "  int* A::B;\n"

[clang] [clang-format] Fix anonymous reference parameter with default value (PR #86254)

2024-03-22 Thread via cfe-commits

https://github.com/rayroudc created 
https://github.com/llvm/llvm-project/pull/86254

When enabling alignment of consecutive declarations and reference right 
alignment, the needed space between `& ` and ` = ` is removed in the following 
use case.

Problem (does not compile)
```
inta(const Test&= Test());
double b();
```

Expected:
```
inta(const Test & = Test());
double b();
```

Test command:

```
echo "inta(const Test& = Test()); double b();"  | clang-format 
-style="{AlignConsecutiveDeclarations: true, ReferenceAlignment: Right}"
```

>From 3feaef98f0b47de919146e05daeb37552bfea36a Mon Sep 17 00:00:00 2001
From: "C. Rayroud" 
Date: Mon, 18 Mar 2024 06:39:26 +
Subject: [PATCH] [clang-format] Fix anonymous reference parameter with default
 value

---
 clang/lib/Format/WhitespaceManager.cpp | 4 
 clang/unittests/Format/FormatTest.cpp  | 7 +++
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 6577c19cdf7978..c4a7d54e5bc8ed 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -471,6 +471,10 @@ AlignTokenSequence(const FormatStyle &Style, unsigned 
Start, unsigned End,
Previous >= 0 &&
Changes[Previous].Tok->getType() == TT_PointerOrReference;
--Previous) {
+// Don't align function default argument using return type maximum size
+if (Changes[Previous + 1].Tok->is(tok::equal)) {
+  continue;
+}
 assert(Changes[Previous].Tok->isPointerOrReference());
 if (Changes[Previous].Tok->isNot(tok::star)) {
   if (ReferenceNotRightAligned)
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a14b002c37c631..23169363542ec1 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -19056,6 +19056,9 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
   verifyFormat("inta(int x);\n"
"double b();",
Alignment);
+  verifyFormat("inta(const Test & = Test());\n"
+   "double b();",
+   Alignment);
   verifyFormat("struct Test {\n"
"  Test(const Test &) = default;\n"
"  ~Test() = default;\n"
@@ -19277,6 +19280,10 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
"intfoobar;",
AlignmentLeft);
 
+  verifyFormat("inta(const Test& = Test());\n"
+   "double b();",
+   AlignmentLeft);
+
   // PAS_Middle
   FormatStyle AlignmentMiddle = Alignment;
   AlignmentMiddle.PointerAlignment = FormatStyle::PAS_Middle;

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


[clang] [clang-format] Fix anonymous reference parameter with default value (PR #86254)

2024-03-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (rayroudc)


Changes

When enabling alignment of consecutive declarations and reference right 
alignment, the needed space between `& ` and ` = ` is removed in the 
following use case.

Problem (does not compile)
```
inta(const Test&= Test());
double b();
```

Expected:
```
inta(const Test & = Test());
double b();
```

Test command:

```
echo "inta(const Test& = Test()); double b();" | clang-format 
-style="{AlignConsecutiveDeclarations: true, ReferenceAlignment: Right}"
```

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


2 Files Affected:

- (modified) clang/lib/Format/WhitespaceManager.cpp (+4) 
- (modified) clang/unittests/Format/FormatTest.cpp (+7) 


``diff
diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 6577c19cdf7978..c4a7d54e5bc8ed 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -471,6 +471,10 @@ AlignTokenSequence(const FormatStyle &Style, unsigned 
Start, unsigned End,
Previous >= 0 &&
Changes[Previous].Tok->getType() == TT_PointerOrReference;
--Previous) {
+// Don't align function default argument using return type maximum size
+if (Changes[Previous + 1].Tok->is(tok::equal)) {
+  continue;
+}
 assert(Changes[Previous].Tok->isPointerOrReference());
 if (Changes[Previous].Tok->isNot(tok::star)) {
   if (ReferenceNotRightAligned)
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a14b002c37c631..23169363542ec1 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -19056,6 +19056,9 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
   verifyFormat("inta(int x);\n"
"double b();",
Alignment);
+  verifyFormat("inta(const Test & = Test());\n"
+   "double b();",
+   Alignment);
   verifyFormat("struct Test {\n"
"  Test(const Test &) = default;\n"
"  ~Test() = default;\n"
@@ -19277,6 +19280,10 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
"intfoobar;",
AlignmentLeft);
 
+  verifyFormat("inta(const Test& = Test());\n"
+   "double b();",
+   AlignmentLeft);
+
   // PAS_Middle
   FormatStyle AlignmentMiddle = Alignment;
   AlignmentMiddle.PointerAlignment = FormatStyle::PAS_Middle;

``




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


[clang] [clang-format] Fix anonymous reference parameter with default value (PR #86254)

2024-03-22 Thread via cfe-commits

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


[clang] [clang-format] Fix anonymous reference parameter with default value (PR #86254)

2024-03-22 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 65ae09eeb6773b14189fc67051870c8fc4eb9ae3 
3feaef98f0b47de919146e05daeb37552bfea36a -- 
clang/lib/Format/WhitespaceManager.cpp clang/unittests/Format/FormatTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index c4a7d54e5b..a04aca47b1 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -472,9 +472,8 @@ AlignTokenSequence(const FormatStyle &Style, unsigned 
Start, unsigned End,
Changes[Previous].Tok->getType() == TT_PointerOrReference;
--Previous) {
 // Don't align function default argument using return type maximum size
-if (Changes[Previous + 1].Tok->is(tok::equal)) {
+if (Changes[Previous + 1].Tok->is(tok::equal))
   continue;
-}
 assert(Changes[Previous].Tok->isPointerOrReference());
 if (Changes[Previous].Tok->isNot(tok::star)) {
   if (ReferenceNotRightAligned)

``




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


[clang] [cfi][CodeGen] Call SetLLVMFunctionAttributes{, ForDefinition} on __cf… (PR #78253)

2024-03-22 Thread Pavel Kosov via cfe-commits

https://github.com/kpdev updated https://github.com/llvm/llvm-project/pull/78253

>From ebe0b998fc0476aed38fff7fcf368a08ddbda8a3 Mon Sep 17 00:00:00 2001
From: Nikolai Kholiavin 
Date: Wed, 20 Dec 2023 16:19:03 +
Subject: [PATCH] [cfi][CodeGen] Call SetLLVMFunctionAttributes{,ForDefinition}
 on __cfi_check

This causes __cfi_check, just as __cfi_check_fail, to get the proper
target-specific attributes, in particular uwtable for unwind table
generation. Previously, nounwind attribute could be inferred for
__cfi_check, which caused it to lose its unwind table even with
-funwind-table option.
---
 clang/docs/ReleaseNotes.rst  |  4 
 clang/lib/CodeGen/CGExpr.cpp | 21 +++--
 clang/test/CodeGen/cfi-check-attrs.c |  5 +
 clang/test/CodeGen/cfi-check-fail.c  |  2 +-
 4 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/cfi-check-attrs.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e16b9f0c67dbd..62a6b1fb26493d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -416,6 +416,10 @@ Sanitizers
   manually disable potentially noisy signed integer overflow checks with
   ``-fno-sanitize=signed-integer-overflow``
 
+- ``-fsanitize=cfi -fsanitize-cfi-cross-dso`` (cross-DSO CFI instrumentation)
+  now generates the ``__cfi_check`` function with proper target-specific
+  attributes, for example allowing unwind table generation.
+
 Python Binding Changes
 --
 
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 59a7fe8925001c..cebaf9b32cfad5 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3682,12 +3682,29 @@ void CodeGenFunction::EmitCfiSlowPathCheck(
 // symbol in LTO mode.
 void CodeGenFunction::EmitCfiCheckStub() {
   llvm::Module *M = &CGM.getModule();
-  auto &Ctx = M->getContext();
+  ASTContext &C = getContext();
+  QualType QInt64Ty = C.getIntTypeForBitwidth(64, false);
+
+  FunctionArgList FnArgs;
+  ImplicitParamDecl ArgCallsiteTypeId(C, QInt64Ty, ImplicitParamKind::Other);
+  ImplicitParamDecl ArgAddr(C, C.VoidPtrTy, ImplicitParamKind::Other);
+  ImplicitParamDecl ArgCFICheckFailData(C, C.VoidPtrTy,
+ImplicitParamKind::Other);
+  FnArgs.push_back(&ArgCallsiteTypeId);
+  FnArgs.push_back(&ArgAddr);
+  FnArgs.push_back(&ArgCFICheckFailData);
+  const CGFunctionInfo &FI =
+  CGM.getTypes().arrangeBuiltinFunctionDeclaration(C.VoidTy, FnArgs);
+
   llvm::Function *F = llvm::Function::Create(
-  llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false),
+  llvm::FunctionType::get(VoidTy, {Int64Ty, VoidPtrTy, VoidPtrTy}, false),
   llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M);
+  CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, F, /*IsThunk=*/false);
+  CGM.SetLLVMFunctionAttributesForDefinition(nullptr, F);
   F->setAlignment(llvm::Align(4096));
   CGM.setDSOLocal(F);
+
+  llvm::LLVMContext &Ctx = M->getContext();
   llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);
   // CrossDSOCFI pass is not executed if there is no executable code.
   SmallVector Args{F->getArg(2), F->getArg(1)};
diff --git a/clang/test/CodeGen/cfi-check-attrs.c 
b/clang/test/CodeGen/cfi-check-attrs.c
new file mode 100644
index 00..375aa30074d887
--- /dev/null
+++ b/clang/test/CodeGen/cfi-check-attrs.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple arm-unknown-linux -funwind-tables=1 
-fsanitize-cfi-cross-dso -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: define weak {{.*}}void @__cfi_check({{.*}} [[ATTR:#[0-9]*]]
+
+// CHECK: attributes [[ATTR]] = {{.*}} uwtable(sync)
diff --git a/clang/test/CodeGen/cfi-check-fail.c 
b/clang/test/CodeGen/cfi-check-fail.c
index 2f12cee9dec602..15f6c77abf2b20 100644
--- a/clang/test/CodeGen/cfi-check-fail.c
+++ b/clang/test/CodeGen/cfi-check-fail.c
@@ -72,7 +72,7 @@ void caller(void (*f)(void)) {
 // CHECK: [[CONT5]]:
 // CHECK:   ret void
 
-// CHECK: define weak void @__cfi_check(i64 %[[TYPE:.*]], ptr %[[ADDR:.*]], 
ptr %[[DATA:.*]]) align 4096
+// CHECK: define weak void @__cfi_check(i64 noundef %[[TYPE:.*]], ptr noundef 
%[[ADDR:.*]], ptr noundef %[[DATA:.*]]){{.*}} align 4096
 // CHECK-NOT: }
 // CHECK: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]])
 // CHECK-NEXT: ret void

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-22 Thread Alejandro Álvarez Ayllón via cfe-commits

https://github.com/alejandro-alvarez-sonarsource updated 
https://github.com/llvm/llvm-project/pull/83027

From a061464b75ac02c21e5d74fc4dff8d8afdbba66b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 
Date: Wed, 20 Mar 2024 10:49:08 +0100
Subject: [PATCH 01/23] [NFC] UnixAPIMisuseChecker inherits from
 Checker

---
 .../Checkers/UnixAPIChecker.cpp   | 60 +--
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
index 19f1ca2dc824c9..599e5e6cedc606 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -17,6 +17,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "llvm/ADT/STLExtras.h"
@@ -41,8 +42,7 @@ enum class OpenVariant {
 namespace {
 
 class UnixAPIMisuseChecker
-: public Checker,
- check::ASTDecl> {
+: public Checker> {
   const BugType BT_open{this, "Improper use of 'open'", categories::UnixAPI};
   const BugType BT_pthreadOnce{this, "Improper use of 'pthread_once'",
categories::UnixAPI};
@@ -52,14 +52,14 @@ class UnixAPIMisuseChecker
   void checkASTDecl(const TranslationUnitDecl *TU, AnalysisManager &Mgr,
 BugReporter &BR) const;
 
-  void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
+  void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
 
-  void CheckOpen(CheckerContext &C, const CallExpr *CE) const;
-  void CheckOpenAt(CheckerContext &C, const CallExpr *CE) const;
-  void CheckPthreadOnce(CheckerContext &C, const CallExpr *CE) const;
+  void CheckOpen(CheckerContext &C, const CallEvent &Call) const;
+  void CheckOpenAt(CheckerContext &C, const CallEvent &Call) const;
+  void CheckPthreadOnce(CheckerContext &C, const CallEvent &Call) const;
 
-  void CheckOpenVariant(CheckerContext &C,
-const CallExpr *CE, OpenVariant Variant) const;
+  void CheckOpenVariant(CheckerContext &C, const CallEvent &Call,
+OpenVariant Variant) const;
 
   void ReportOpenBug(CheckerContext &C, ProgramStateRef State, const char *Msg,
  SourceRange SR) const;
@@ -113,9 +113,9 @@ void UnixAPIMisuseChecker::checkASTDecl(const 
TranslationUnitDecl *TU,
 // "open" (man 2 open)
 //===--===/
 
-void UnixAPIMisuseChecker::checkPreStmt(const CallExpr *CE,
+void UnixAPIMisuseChecker::checkPreCall(const CallEvent &Call,
 CheckerContext &C) const {
-  const FunctionDecl *FD = C.getCalleeDecl(CE);
+  const FunctionDecl *FD = dyn_cast_if_present(Call.getDecl());
   if (!FD || FD->getKind() != Decl::Function)
 return;
 
@@ -130,13 +130,13 @@ void UnixAPIMisuseChecker::checkPreStmt(const CallExpr 
*CE,
 return;
 
   if (FName == "open")
-CheckOpen(C, CE);
+CheckOpen(C, Call);
 
   else if (FName == "openat")
-CheckOpenAt(C, CE);
+CheckOpenAt(C, Call);
 
   else if (FName == "pthread_once")
-CheckPthreadOnce(C, CE);
+CheckPthreadOnce(C, Call);
 }
 void UnixAPIMisuseChecker::ReportOpenBug(CheckerContext &C,
  ProgramStateRef State,
@@ -152,17 +152,17 @@ void UnixAPIMisuseChecker::ReportOpenBug(CheckerContext 
&C,
 }
 
 void UnixAPIMisuseChecker::CheckOpen(CheckerContext &C,
- const CallExpr *CE) const {
-  CheckOpenVariant(C, CE, OpenVariant::Open);
+ const CallEvent &Call) const {
+  CheckOpenVariant(C, Call, OpenVariant::Open);
 }
 
 void UnixAPIMisuseChecker::CheckOpenAt(CheckerContext &C,
-   const CallExpr *CE) const {
-  CheckOpenVariant(C, CE, OpenVariant::OpenAt);
+   const CallEvent &Call) const {
+  CheckOpenVariant(C, Call, OpenVariant::OpenAt);
 }
 
 void UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
-const CallExpr *CE,
+const CallEvent &Call,
 OpenVariant Variant) const {
   // The index of the argument taking the flags open flags (O_RDONLY,
   // O_WRONLY, O_CREAT, etc.),
@@ -191,11 +191,11 @@ void 
UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
 
   ProgramStateRef state = C.getState();
 
-  if (CE->getNumArgs() < MinArgCount) {
+  if (Call.getNumArgs() < MinArgCount) {
 // The frontend

[clang] [X86_64] fix arg pass error in struct. (PR #85394)

2024-03-22 Thread Longsheng Mou via cfe-commits

https://github.com/CoTinker updated 
https://github.com/llvm/llvm-project/pull/85394

>From 57cdbcab4ad13441a3f8731c4cdedc51acfbc7b1 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 15 Mar 2024 20:50:54 +0800
Subject: [PATCH] [X86_64] fix arg pass error in struct.

typedef long long ll __attribute__((aligned (4)));
struct S {
  int a;
  ll b;
};

when classify:
a: Lo = Integer, Hi = NoClass
b: Lo = Integer, Hi = NoClass
struct S: Lo = Integer, Hi = NoClass

In this case, only one i64 register is used when the structure
parameter is transferred, which is obviously incorrect.So we need
to treat the split case specially.
---
 clang/lib/CodeGen/Targets/X86.cpp |  6 +-
 clang/test/CodeGen/X86/x86_64-arguments.c | 18 ++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 2291c991fb1107..de0dfe32a54d3a 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2100,8 +2100,12 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 postMerge(Size, Lo, Hi);
 return;
   }
+
+  bool InMemory = Offset % getContext().getTypeAlign(i->getType()) ||
+  (i->getType()->getAs() &&
+   Offset % getContext().getTypeSize(i->getType()));
   // Note, skip this test for bit-fields, see below.
-  if (!BitField && Offset % getContext().getTypeAlign(i->getType())) {
+  if (!BitField && InMemory) {
 Lo = Memory;
 postMerge(Size, Lo, Hi);
 return;
diff --git a/clang/test/CodeGen/X86/x86_64-arguments.c 
b/clang/test/CodeGen/X86/x86_64-arguments.c
index cf5636cfd518b6..82845f0a2b31fd 100644
--- a/clang/test/CodeGen/X86/x86_64-arguments.c
+++ b/clang/test/CodeGen/X86/x86_64-arguments.c
@@ -533,6 +533,24 @@ typedef float t66 __attribute__((__vector_size__(128), 
__aligned__(128)));
 void f66(t66 a0) {
 }
 
+typedef long long t67 __attribute__((aligned (4)));
+struct s67 {
+  int a;
+  t67 b;
+};
+// CHECK-LABEL: define{{.*}} void @f67(ptr noundef byval(%struct.s67) align 8 
%x)
+void f67(struct s67 x) {
+}
+
+typedef double t68 __attribute__((aligned (4)));
+struct s68 {
+  int a;
+  t68 b;
+};
+// CHECK-LABEL: define{{.*}} void @f68(ptr noundef byval(%struct.s68) align 8 
%x)
+void f68(struct s68 x) {
+}
+
 /// The synthesized __va_list_tag does not have file/line fields.
 // CHECK:  = distinct !DICompositeType(tag: DW_TAG_structure_type, name: 
"__va_list_tag",
 // CHECK-NOT:  file:

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-22 Thread Alejandro Álvarez Ayllón via cfe-commits


@@ -376,3 +377,122 @@ void fflush_on_open_failed_stream(void) {
   }
   fclose(F);
 }
+
+void getline_null_file() {
+  char *buffer = NULL;
+  size_t n = 0;
+  getline(&buffer, &n, NULL); // expected-warning {{Stream pointer might be 
NULL}}
+}
+
+void getdelim_null_file() {
+  char *buffer = NULL;
+  size_t n = 0;
+  getdelim(&buffer, &n, '\n', NULL); // expected-warning {{Stream pointer 
might be NULL}}
+}
+
+void getline_no_return_check() {
+  FILE *file = fopen("file.txt", "r");
+  if (file == NULL) {
+return;
+  }
+
+  char *line = NULL;
+  size_t len = 0;
+  getline(&line, &len, file);
+
+  if (line[0] == '\0') {} // expected-warning {{The left operand of '==' is a 
garbage value}}
+
+  free(line);
+  fclose(file);
+}
+
+void getline_after_eof() {
+  FILE *file = fopen("file.txt", "r");
+  if (file == NULL) {
+return;
+  }
+
+  size_t n = 10;
+  char *buffer = malloc(n);
+  ssize_t read = fread(buffer, n, 1, file);
+  if (!feof(file)) {
+getline(&buffer, &n, file); // expected-warning {{File position of the 
stream might be 'indeterminate' after a failed operation. Can cause undefined 
behavior}}
+  }
+  fclose(file);
+  free(buffer);
+}
+
+void getline_feof() {
+  FILE *file = fopen("file.txt", "r");
+  if (file == NULL) {
+return;
+  }
+
+  size_t n = 10;
+  char *buffer = malloc(n);
+  ssize_t read = fread(buffer, n, 1, file);
+  getline(&buffer, &n, file); // expected-warning {{File position of the 
stream might be 'indeterminate' after a failed operation. Can cause undefined 
behavior}} \\
+  expected-warning {{Read function called when stream is in EOF state. 
Function has no effect}}
+  fclose(file);
+  free(buffer);
+}
+
+void getline_feof_check() {
+  FILE *file = fopen("file.txt", "r");
+  if (file == NULL) {
+return;
+  }
+
+  char *line = NULL;
+  size_t len = 0;
+  ssize_t r = getline(&line, &len, file);
+
+  if (r != -1) {
+// success, end-of-file is not possible
+int f = feof(file);
+clang_analyzer_eval(f == 0); // expected-warning {{TRUE}}
+  } else {
+// failure, end-of-file is possible, but not the only reason to fail
+int f = feof(file);
+clang_analyzer_eval(f == 0); // expected-warning {{TRUE}} \\
+expected-warning {{FALSE}}
+  }
+  free(line);
+  fclose(file);
+}
+
+void getline_ret_value() {
+  FILE *file = fopen("file.txt", "r");
+  if (file == NULL) {
+return;
+  }
+
+  size_t n = 0;
+  char *buffer = NULL;
+  ssize_t r = getline(&buffer, &n, file);
+
+  if (r > -1) {
+// The return value does *not* include the terminating null byte.
+// The buffer must be large enough to include it.
+clang_analyzer_eval(n > r); // expected-warning{{TRUE}}
+  }
+
+  fclose(file);
+  free(buffer);
+}
+
+
+void getline_buffer_size_invariant(char *buffer) {

alejandro-alvarez-sonarsource wrote:

I have reworked the test, including a couple of calls to `clang_analyze_eval ` 
to make sure the -1 is changed after the call.

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


[clang] [clang-forma] Support `PointerAlignment: Left` for pointer to member (PR #86253)

2024-03-22 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/86253

>From d1a3b743b808a64f022897dfd832ce9a25c8f2c0 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 21 Mar 2024 23:43:23 -0700
Subject: [PATCH 1/2] [clang-forma] Support `PointerAlignment: Left` for
 pointer to member

Fixes #85761.
---
 clang/lib/Format/TokenAnnotator.cpp   | 31 ---
 clang/unittests/Format/FormatTest.cpp |  7 +-
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 94d2266555f6b9..d54a0fe4ce6748 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4351,9 +4351,11 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;
 
+  const auto *BeforeLeft = Left.Previous;
+
   // operator co_await(x)
-  if (Right.is(tok::l_paren) && Left.is(tok::kw_co_await) && Left.Previous &&
-  Left.Previous->is(tok::kw_operator)) {
+  if (Right.is(tok::l_paren) && Left.is(tok::kw_co_await) && BeforeLeft &&
+  BeforeLeft->is(tok::kw_operator)) {
 return false;
   }
   // co_await (x), co_yield (x), co_return (x)
@@ -4404,8 +4406,8 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   return false;
   }
   if (Right.is(tok::ellipsis)) {
-return Left.Tok.isLiteral() || (Left.is(tok::identifier) && Left.Previous 
&&
-Left.Previous->is(tok::kw_case));
+return Left.Tok.isLiteral() || (Left.is(tok::identifier) && BeforeLeft &&
+BeforeLeft->is(tok::kw_case));
   }
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return Style.SpacesInSquareBrackets;
@@ -4473,8 +4475,8 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 if (Right.is(tok::l_brace) && Right.is(BK_Block))
   return true;
 // for (auto a = 0, b = 0; const auto& c : {1, 2, 3})
-if (Left.Previous && Left.Previous->isTypeOrIdentifier(IsCpp) &&
-Right.Next && Right.Next->is(TT_RangeBasedForLoopColon)) {
+if (BeforeLeft && BeforeLeft->isTypeOrIdentifier(IsCpp) && Right.Next &&
+Right.Next->is(TT_RangeBasedForLoopColon)) {
   return getTokenPointerOrReferenceAlignment(Left) !=
  FormatStyle::PAS_Right;
 }
@@ -4496,12 +4498,17 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   startsWithInitStatement(Line {
   return false;
 }
-return Left.Previous && !Left.Previous->isOneOf(
-tok::l_paren, tok::coloncolon, tok::l_square);
+if (!BeforeLeft)
+  return false;
+if (BeforeLeft->is(tok::coloncolon)) {
+  return Left.is(tok::star) &&
+ Style.PointerAlignment != FormatStyle::PAS_Right;
+}
+return !BeforeLeft->isOneOf(tok::l_paren, tok::l_square);
   }
   // Ensure right pointer alignment with ellipsis e.g. int *...P
-  if (Left.is(tok::ellipsis) && Left.Previous &&
-  Left.Previous->isPointerOrReference()) {
+  if (Left.is(tok::ellipsis) && BeforeLeft &&
+  BeforeLeft->isPointerOrReference()) {
 return Style.PointerAlignment != FormatStyle::PAS_Right;
   }
 
@@ -4663,13 +4670,13 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   return Style.SpaceBeforeParensOptions.AfterFunctionDefinitionName ||
  spaceRequiredBeforeParens(Right);
 }
-if (!Left.Previous || !Left.Previous->isOneOf(tok::period, tok::arrow)) {
+if (!BeforeLeft || !BeforeLeft->isOneOf(tok::period, tok::arrow)) {
   if (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch)) {
 return Style.SpaceBeforeParensOptions.AfterControlStatements ||
spaceRequiredBeforeParens(Right);
   }
   if (Left.isOneOf(tok::kw_new, tok::kw_delete)) {
-return ((!Line.MightBeFunctionDecl || !Left.Previous) &&
+return ((!Line.MightBeFunctionDecl || !BeforeLeft) &&
 Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
spaceRequiredBeforeParens(Right);
   }
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index bea989c8c306db..cab5556af47cc0 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11054,7 +11054,12 @@ TEST_F(FormatTest, UnderstandsPointersToMembers) {
   "aaa(aaa));");
   FormatStyle Style = getLLVMStyle();
   Style.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("typedef bool* (Class::*Member)() const;", Style);
+  verifyFormat("typedef bool* (Class::* Member)() const;", Style);
+  verifyFormat("void function(int A::* parameter, int* parameter2) {\n"
+   "  int A::* variable = &A::B;\n"
+   "  int* A::B;\n"
+  

[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-22 Thread Balázs Kéri via cfe-commits

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

I did not find more issues (at least in `StreamChecker` and its tests). But did 
not check in detail the `UnixAPIChecker` part and tests.

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-22 Thread Alejandro Álvarez Ayllón via cfe-commits

https://github.com/alejandro-alvarez-sonarsource updated 
https://github.com/llvm/llvm-project/pull/83027

From a061464b75ac02c21e5d74fc4dff8d8afdbba66b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 
Date: Wed, 20 Mar 2024 10:49:08 +0100
Subject: [PATCH 01/24] [NFC] UnixAPIMisuseChecker inherits from
 Checker

---
 .../Checkers/UnixAPIChecker.cpp   | 60 +--
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
index 19f1ca2dc824c9..599e5e6cedc606 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -17,6 +17,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "llvm/ADT/STLExtras.h"
@@ -41,8 +42,7 @@ enum class OpenVariant {
 namespace {
 
 class UnixAPIMisuseChecker
-: public Checker,
- check::ASTDecl> {
+: public Checker> {
   const BugType BT_open{this, "Improper use of 'open'", categories::UnixAPI};
   const BugType BT_pthreadOnce{this, "Improper use of 'pthread_once'",
categories::UnixAPI};
@@ -52,14 +52,14 @@ class UnixAPIMisuseChecker
   void checkASTDecl(const TranslationUnitDecl *TU, AnalysisManager &Mgr,
 BugReporter &BR) const;
 
-  void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
+  void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
 
-  void CheckOpen(CheckerContext &C, const CallExpr *CE) const;
-  void CheckOpenAt(CheckerContext &C, const CallExpr *CE) const;
-  void CheckPthreadOnce(CheckerContext &C, const CallExpr *CE) const;
+  void CheckOpen(CheckerContext &C, const CallEvent &Call) const;
+  void CheckOpenAt(CheckerContext &C, const CallEvent &Call) const;
+  void CheckPthreadOnce(CheckerContext &C, const CallEvent &Call) const;
 
-  void CheckOpenVariant(CheckerContext &C,
-const CallExpr *CE, OpenVariant Variant) const;
+  void CheckOpenVariant(CheckerContext &C, const CallEvent &Call,
+OpenVariant Variant) const;
 
   void ReportOpenBug(CheckerContext &C, ProgramStateRef State, const char *Msg,
  SourceRange SR) const;
@@ -113,9 +113,9 @@ void UnixAPIMisuseChecker::checkASTDecl(const 
TranslationUnitDecl *TU,
 // "open" (man 2 open)
 //===--===/
 
-void UnixAPIMisuseChecker::checkPreStmt(const CallExpr *CE,
+void UnixAPIMisuseChecker::checkPreCall(const CallEvent &Call,
 CheckerContext &C) const {
-  const FunctionDecl *FD = C.getCalleeDecl(CE);
+  const FunctionDecl *FD = dyn_cast_if_present(Call.getDecl());
   if (!FD || FD->getKind() != Decl::Function)
 return;
 
@@ -130,13 +130,13 @@ void UnixAPIMisuseChecker::checkPreStmt(const CallExpr 
*CE,
 return;
 
   if (FName == "open")
-CheckOpen(C, CE);
+CheckOpen(C, Call);
 
   else if (FName == "openat")
-CheckOpenAt(C, CE);
+CheckOpenAt(C, Call);
 
   else if (FName == "pthread_once")
-CheckPthreadOnce(C, CE);
+CheckPthreadOnce(C, Call);
 }
 void UnixAPIMisuseChecker::ReportOpenBug(CheckerContext &C,
  ProgramStateRef State,
@@ -152,17 +152,17 @@ void UnixAPIMisuseChecker::ReportOpenBug(CheckerContext 
&C,
 }
 
 void UnixAPIMisuseChecker::CheckOpen(CheckerContext &C,
- const CallExpr *CE) const {
-  CheckOpenVariant(C, CE, OpenVariant::Open);
+ const CallEvent &Call) const {
+  CheckOpenVariant(C, Call, OpenVariant::Open);
 }
 
 void UnixAPIMisuseChecker::CheckOpenAt(CheckerContext &C,
-   const CallExpr *CE) const {
-  CheckOpenVariant(C, CE, OpenVariant::OpenAt);
+   const CallEvent &Call) const {
+  CheckOpenVariant(C, Call, OpenVariant::OpenAt);
 }
 
 void UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
-const CallExpr *CE,
+const CallEvent &Call,
 OpenVariant Variant) const {
   // The index of the argument taking the flags open flags (O_RDONLY,
   // O_WRONLY, O_CREAT, etc.),
@@ -191,11 +191,11 @@ void 
UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
 
   ProgramStateRef state = C.getState();
 
-  if (CE->getNumArgs() < MinArgCount) {
+  if (Call.getNumArgs() < MinArgCount) {
 // The frontend

[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-22 Thread Alejandro Álvarez Ayllón via cfe-commits


@@ -376,3 +377,75 @@ void fflush_on_open_failed_stream(void) {
   }
   fclose(F);
 }
+
+void getline_null_file() {
+  char *buffer = NULL;
+  size_t n = 0;
+  getline(&buffer, &n, NULL); // expected-warning {{Stream pointer might be 
NULL}}
+}
+
+void getdelim_null_file() {
+  char *buffer = NULL;
+  size_t n = 0;
+  getdelim(&buffer, &n, '\n', NULL); // expected-warning {{Stream pointer 
might be NULL}}
+}
+
+void getline_buffer_on_error() {
+  FILE *file = fopen("file.txt", "r");
+  if (file == NULL) {
+return;
+  }
+
+  char *line = NULL;
+  size_t len = 0;
+  if (getline(&line, &len, file) == -1) {
+if (line[0] == '\0') {} // expected-warning {{The left operand of '==' is 
a garbage value}}
+  } else {
+if (line[0] == '\0') {} // no warning
+  }
+
+  free(line);
+  fclose(file);
+}
+
+void getline_ret_value() {
+  FILE *file = fopen("file.txt", "r");
+  if (file == NULL) {
+return;
+  }
+
+  size_t n = 0;
+  char *buffer = NULL;
+  ssize_t r = getline(&buffer, &n, file);
+
+  if (r > -1) {
+// The return value does *not* include the terminating null byte.
+// The buffer must be large enough to include it.
+clang_analyzer_eval(n > r); // expected-warning{{TRUE}}
+clang_analyzer_eval(buffer != NULL);  // expected-warning{{TRUE}}
+  }
+
+  fclose(file);
+  free(buffer);
+}
+
+
+void getline_buffer_size_negative() {
+  FILE *file = fopen("file.txt", "r");
+  if (file == NULL) {
+return;
+  }
+
+  size_t n = -1;
+  clang_analyzer_eval((ssize_t)n >= 0); // expected-warning{{FALSE}}
+  char *buffer = NULL;
+  ssize_t r = getline(&buffer, &n, file);
+
+  if (r > -1) {
+clang_analyzer_eval((ssize_t)n > r); // expected-warning{{TRUE}}
+   clang_analyzer_eval(buffer != NULL); // expected-warning{{TRUE}}

alejandro-alvarez-sonarsource wrote:

Replaced with spaces.

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-22 Thread Balázs Kéri via cfe-commits


@@ -376,3 +377,75 @@ void fflush_on_open_failed_stream(void) {
   }
   fclose(F);
 }
+
+void getline_null_file() {
+  char *buffer = NULL;
+  size_t n = 0;
+  getline(&buffer, &n, NULL); // expected-warning {{Stream pointer might be 
NULL}}
+}
+
+void getdelim_null_file() {
+  char *buffer = NULL;
+  size_t n = 0;
+  getdelim(&buffer, &n, '\n', NULL); // expected-warning {{Stream pointer 
might be NULL}}
+}
+
+void getline_buffer_on_error() {
+  FILE *file = fopen("file.txt", "r");
+  if (file == NULL) {
+return;
+  }
+
+  char *line = NULL;
+  size_t len = 0;
+  if (getline(&line, &len, file) == -1) {
+if (line[0] == '\0') {} // expected-warning {{The left operand of '==' is 
a garbage value}}
+  } else {
+if (line[0] == '\0') {} // no warning
+  }
+
+  free(line);
+  fclose(file);
+}
+
+void getline_ret_value() {
+  FILE *file = fopen("file.txt", "r");
+  if (file == NULL) {
+return;
+  }
+
+  size_t n = 0;
+  char *buffer = NULL;
+  ssize_t r = getline(&buffer, &n, file);
+
+  if (r > -1) {
+// The return value does *not* include the terminating null byte.
+// The buffer must be large enough to include it.
+clang_analyzer_eval(n > r); // expected-warning{{TRUE}}
+clang_analyzer_eval(buffer != NULL);  // expected-warning{{TRUE}}
+  }
+
+  fclose(file);
+  free(buffer);
+}
+
+
+void getline_buffer_size_negative() {
+  FILE *file = fopen("file.txt", "r");
+  if (file == NULL) {
+return;
+  }
+
+  size_t n = -1;
+  clang_analyzer_eval((ssize_t)n >= 0); // expected-warning{{FALSE}}
+  char *buffer = NULL;
+  ssize_t r = getline(&buffer, &n, file);
+
+  if (r > -1) {
+clang_analyzer_eval((ssize_t)n > r); // expected-warning{{TRUE}}
+   clang_analyzer_eval(buffer != NULL); // expected-warning{{TRUE}}

balazske wrote:

This looks like an indentation problem.

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


[clang] [clang][analyzer] Bring cplusplus.ArrayDelete out of alpha (PR #83985)

2024-03-22 Thread via cfe-commits

https://github.com/Discookie updated 
https://github.com/llvm/llvm-project/pull/83985

>From 881701d528255e2c49ed64f5f1df98f0f44c1d7b Mon Sep 17 00:00:00 2001
From: Viktor 
Date: Tue, 5 Mar 2024 09:46:26 +
Subject: [PATCH 1/2] [clang][analyzer] Bring cplusplus.ArrayDelete out of
 alpha

---
 clang/docs/analyzer/checkers.rst  | 69 ---
 .../clang/StaticAnalyzer/Checkers/Checkers.td | 10 +--
 .../Checkers/CXXDeleteChecker.cpp |  4 +-
 clang/test/Analysis/ArrayDelete.cpp   |  2 +-
 clang/www/analyzer/alpha_checks.html  | 20 --
 clang/www/analyzer/available_checks.html  | 27 
 6 files changed, 80 insertions(+), 52 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index fe211514914272..c49f7e09f946a1 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -340,6 +340,51 @@ cplusplus
 
 C++ Checkers.
 
+.. _cplusplus-ArrayDelete:
+
+cplusplus.ArrayDelete (C++)
+"""
+
+Reports destructions of arrays of polymorphic objects that are destructed as
+their base class. If the dynamic type of the array is different from its static
+type, calling `delete[]` is undefined.
+
+This checker corresponds to the CERT rule `EXP51-CPP: Do not delete an array 
through a pointer of the incorrect type 
`_.
+
+.. code-block:: cpp
+
+ class Base {
+ public:
+   virtual ~Base() {}
+ };
+ class Derived : public Base {};
+
+ Base *create() {
+   Base *x = new Derived[10]; // note: Casting from 'Derived' to 'Base' here
+   return x;
+ }
+
+ void foo() {
+   Base *x = create();
+   delete[] x; // warn: Deleting an array of 'Derived' objects as their base 
class 'Base' is undefined
+ }
+
+**Limitations**
+
+The checker does not emit note tags when casting to and from reference types,
+even though the pointer values are tracked across references.
+
+.. code-block:: cpp
+
+ void foo() {
+   Derived *d = new Derived[10];
+   Derived &dref = *d;
+
+   Base &bref = static_cast(dref); // no note
+   Base *b = &bref;
+   delete[] b; // warn: Deleting an array of 'Derived' objects as their base 
class 'Base' is undefined
+ }
+
 .. _cplusplus-InnerPointer:
 
 cplusplus.InnerPointer (C++)
@@ -2139,30 +2184,6 @@ Either the comparison is useless or there is division by 
zero.
 alpha.cplusplus
 ^^^
 
-.. _alpha-cplusplus-ArrayDelete:
-
-alpha.cplusplus.ArrayDelete (C++)
-"
-Reports destructions of arrays of polymorphic objects that are destructed as 
their base class.
-This checker corresponds to the CERT rule `EXP51-CPP: Do not delete an array 
through a pointer of the incorrect type 
`_.
-
-.. code-block:: cpp
-
- class Base {
-   virtual ~Base() {}
- };
- class Derived : public Base {}
-
- Base *create() {
-   Base *x = new Derived[10]; // note: Casting from 'Derived' to 'Base' here
-   return x;
- }
-
- void foo() {
-   Base *x = create();
-   delete[] x; // warn: Deleting an array of 'Derived' objects as their base 
class 'Base' is undefined
- }
-
 .. _alpha-cplusplus-DeleteWithNonVirtualDtor:
 
 alpha.cplusplus.DeleteWithNonVirtualDtor (C++)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index a224b81c33a624..97fa8ac060eafa 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -622,6 +622,11 @@ def BlockInCriticalSectionChecker : 
Checker<"BlockInCriticalSection">,
 
 let ParentPackage = Cplusplus in {
 
+def ArrayDeleteChecker : Checker<"ArrayDelete">,
+  HelpText<"Reports destructions of arrays of polymorphic objects that are "
+   "destructed as their base class.">,
+  Documentation;
+
 def InnerPointerChecker : Checker<"InnerPointer">,
   HelpText<"Check for inner pointers of C++ containers used after "
"re/deallocation">,
@@ -777,11 +782,6 @@ def ContainerModeling : Checker<"ContainerModeling">,
   Documentation,
   Hidden;
 
-def CXXArrayDeleteChecker : Checker<"ArrayDelete">,
-  HelpText<"Reports destructions of arrays of polymorphic objects that are "
-   "destructed as their base class.">,
-  Documentation;
-
 def DeleteWithNonVirtualDtorChecker : Checker<"DeleteWithNonVirtualDtor">,
   HelpText<"Reports destructions of polymorphic objects with a non-virtual "
"destructor in their base class">,
diff --git a/clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp
index b4dee1e300e886..1b1226a7f1a71d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CXXDeleteCh

[clang] [X86_64] fix arg pass error in struct. (PR #85394)

2024-03-22 Thread Longsheng Mou via cfe-commits

https://github.com/CoTinker updated 
https://github.com/llvm/llvm-project/pull/85394

>From 07e8b31dbe6eaa1a385d52160bf1913c9fa1c17e Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 15 Mar 2024 20:50:54 +0800
Subject: [PATCH] [X86_64] fix arg pass error in struct.

In some struct like s67, only one i64 register is used when the structure
parameter is transferred, which is obviously incorrect.So we need
to treat the split case specially.
---
 clang/lib/CodeGen/Targets/X86.cpp |  6 +-
 clang/test/CodeGen/X86/x86_64-arguments.c | 18 ++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 2291c991fb1107..de0dfe32a54d3a 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2100,8 +2100,12 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 postMerge(Size, Lo, Hi);
 return;
   }
+
+  bool InMemory = Offset % getContext().getTypeAlign(i->getType()) ||
+  (i->getType()->getAs() &&
+   Offset % getContext().getTypeSize(i->getType()));
   // Note, skip this test for bit-fields, see below.
-  if (!BitField && Offset % getContext().getTypeAlign(i->getType())) {
+  if (!BitField && InMemory) {
 Lo = Memory;
 postMerge(Size, Lo, Hi);
 return;
diff --git a/clang/test/CodeGen/X86/x86_64-arguments.c 
b/clang/test/CodeGen/X86/x86_64-arguments.c
index cf5636cfd518b6..82845f0a2b31fd 100644
--- a/clang/test/CodeGen/X86/x86_64-arguments.c
+++ b/clang/test/CodeGen/X86/x86_64-arguments.c
@@ -533,6 +533,24 @@ typedef float t66 __attribute__((__vector_size__(128), 
__aligned__(128)));
 void f66(t66 a0) {
 }
 
+typedef long long t67 __attribute__((aligned (4)));
+struct s67 {
+  int a;
+  t67 b;
+};
+// CHECK-LABEL: define{{.*}} void @f67(ptr noundef byval(%struct.s67) align 8 
%x)
+void f67(struct s67 x) {
+}
+
+typedef double t68 __attribute__((aligned (4)));
+struct s68 {
+  int a;
+  t68 b;
+};
+// CHECK-LABEL: define{{.*}} void @f68(ptr noundef byval(%struct.s68) align 8 
%x)
+void f68(struct s68 x) {
+}
+
 /// The synthesized __va_list_tag does not have file/line fields.
 // CHECK:  = distinct !DICompositeType(tag: DW_TAG_structure_type, name: 
"__va_list_tag",
 // CHECK-NOT:  file:

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


[clang] Split -Wcast-function-type into a separate group (PR #86131)

2024-03-22 Thread Abhin P Jose via cfe-commits

Abhinkop wrote:

@AaronBallman @amy-kwan I am working on a patch for this build breaking in 
https://lab.llvm.org/buildbot/#/builders/57/builds/33656. Is there anything 
else I should also be considering?

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-22 Thread Alejandro Álvarez Ayllón via cfe-commits

https://github.com/alejandro-alvarez-sonarsource updated 
https://github.com/llvm/llvm-project/pull/83027

From 18569fc14e2d9050acbc63c2367f9a1ec6f8577b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 
Date: Wed, 20 Mar 2024 10:49:08 +0100
Subject: [PATCH 1/2] [clang][analyzer][NFC] UnixAPIMisuseChecker inherits from
 Checker

---
 .../Checkers/UnixAPIChecker.cpp   | 60 +--
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
index 19f1ca2dc824c9..599e5e6cedc606 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -17,6 +17,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "llvm/ADT/STLExtras.h"
@@ -41,8 +42,7 @@ enum class OpenVariant {
 namespace {
 
 class UnixAPIMisuseChecker
-: public Checker,
- check::ASTDecl> {
+: public Checker> {
   const BugType BT_open{this, "Improper use of 'open'", categories::UnixAPI};
   const BugType BT_pthreadOnce{this, "Improper use of 'pthread_once'",
categories::UnixAPI};
@@ -52,14 +52,14 @@ class UnixAPIMisuseChecker
   void checkASTDecl(const TranslationUnitDecl *TU, AnalysisManager &Mgr,
 BugReporter &BR) const;
 
-  void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
+  void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
 
-  void CheckOpen(CheckerContext &C, const CallExpr *CE) const;
-  void CheckOpenAt(CheckerContext &C, const CallExpr *CE) const;
-  void CheckPthreadOnce(CheckerContext &C, const CallExpr *CE) const;
+  void CheckOpen(CheckerContext &C, const CallEvent &Call) const;
+  void CheckOpenAt(CheckerContext &C, const CallEvent &Call) const;
+  void CheckPthreadOnce(CheckerContext &C, const CallEvent &Call) const;
 
-  void CheckOpenVariant(CheckerContext &C,
-const CallExpr *CE, OpenVariant Variant) const;
+  void CheckOpenVariant(CheckerContext &C, const CallEvent &Call,
+OpenVariant Variant) const;
 
   void ReportOpenBug(CheckerContext &C, ProgramStateRef State, const char *Msg,
  SourceRange SR) const;
@@ -113,9 +113,9 @@ void UnixAPIMisuseChecker::checkASTDecl(const 
TranslationUnitDecl *TU,
 // "open" (man 2 open)
 //===--===/
 
-void UnixAPIMisuseChecker::checkPreStmt(const CallExpr *CE,
+void UnixAPIMisuseChecker::checkPreCall(const CallEvent &Call,
 CheckerContext &C) const {
-  const FunctionDecl *FD = C.getCalleeDecl(CE);
+  const FunctionDecl *FD = dyn_cast_if_present(Call.getDecl());
   if (!FD || FD->getKind() != Decl::Function)
 return;
 
@@ -130,13 +130,13 @@ void UnixAPIMisuseChecker::checkPreStmt(const CallExpr 
*CE,
 return;
 
   if (FName == "open")
-CheckOpen(C, CE);
+CheckOpen(C, Call);
 
   else if (FName == "openat")
-CheckOpenAt(C, CE);
+CheckOpenAt(C, Call);
 
   else if (FName == "pthread_once")
-CheckPthreadOnce(C, CE);
+CheckPthreadOnce(C, Call);
 }
 void UnixAPIMisuseChecker::ReportOpenBug(CheckerContext &C,
  ProgramStateRef State,
@@ -152,17 +152,17 @@ void UnixAPIMisuseChecker::ReportOpenBug(CheckerContext 
&C,
 }
 
 void UnixAPIMisuseChecker::CheckOpen(CheckerContext &C,
- const CallExpr *CE) const {
-  CheckOpenVariant(C, CE, OpenVariant::Open);
+ const CallEvent &Call) const {
+  CheckOpenVariant(C, Call, OpenVariant::Open);
 }
 
 void UnixAPIMisuseChecker::CheckOpenAt(CheckerContext &C,
-   const CallExpr *CE) const {
-  CheckOpenVariant(C, CE, OpenVariant::OpenAt);
+   const CallEvent &Call) const {
+  CheckOpenVariant(C, Call, OpenVariant::OpenAt);
 }
 
 void UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
-const CallExpr *CE,
+const CallEvent &Call,
 OpenVariant Variant) const {
   // The index of the argument taking the flags open flags (O_RDONLY,
   // O_WRONLY, O_CREAT, etc.),
@@ -191,11 +191,11 @@ void 
UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
 
   ProgramStateRef state = C.getState();
 
-  if (CE->getNumArgs() < MinArgCount) {
+  if (Call.getNumArgs() < MinArgCount) {
 

[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-22 Thread Alejandro Álvarez Ayllón via cfe-commits

alejandro-alvarez-sonarsource wrote:

Rebased and squashed into two commits that should be kept separate.

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-22 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> Sorry for the delayed response, this fell off my radar (thanks @Endilll for 
> mentioning this after meeting with @hazohelet!).

No problem. As I wrote above I work in an out of tree backend and I have 
already implemented this in our downstream repo. Our customer that requested 
this already have this feature. To me this is not at all urgent.

> This would be novel but might not be a terrible approach. I'm not convinced 
> that #3 is a particularly good design (and #6 doesn't seem critical to me 
> either), but I think modifying tablegen to improve support here would be a 
> heavy lift for little benefit. I'd say let's try that approach and see how we 
> like it, and go from there. WDYT?

Sounds good. I think what is currently implemented in this pull request use 
@hazohelet  idea with the dummy warning. As this was started in December I 
think I have to rebase this onto a more recent main branch.

I will look through the code in the pull request (as it was a while ago since I 
looked at this) and do the rebase ...


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


[clang] Add `clang_getCursorCallExprKind` to get the underlying type of CallExpr (PR #86143)

2024-03-22 Thread via cfe-commits

https://github.com/16bit-ykiko closed 
https://github.com/llvm/llvm-project/pull/86143
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add `clang_getCursorCallExprKind` to get the underlying type of CallExpr (PR #86143)

2024-03-22 Thread via cfe-commits

16bit-ykiko wrote:

I find there are something wrong with libclang, some fix need to be added.

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


[clang] [Sema] Preserve ContainsUnexpandedParameterPack in TransformLambdaExpr (PR #86265)

2024-03-22 Thread Younan Zhang via cfe-commits

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

None

>From 6e7b38b3e3f781e11db2fa5d552fdfb6123609df Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 22 Mar 2024 17:34:08 +0800
Subject: [PATCH] [Sema] Preserve ContainsUnexpandedParameterPack in
 TransformLambdaExpr

---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang/Sema/Sema.h   |  8 +++
 clang/lib/Sema/SemaTemplateVariadic.cpp   | 16 +-
 clang/lib/Sema/TreeTransform.h| 18 ++
 .../test/SemaTemplate/lambda-capture-pack.cpp | 57 +++
 5 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 690fc7ed271a3d..2d11a4b8c092a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -344,6 +344,8 @@ Bug Fixes to C++ Support
   when one of the function had more specialized templates.
   Fixes (`#82509 `_)
   and (`#74494 `_)
+- Fixed a crash where template parameter packs were not expanded correctly in 
a lambda being
+  used as a pattern of a folded expression. (#GH56852), (#GH85667)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index cfc1c3b3494788..0d1a2e54840e52 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11201,6 +11201,14 @@ class Sema final {
   void collectUnexpandedParameterPacks(
   QualType T, SmallVectorImpl &Unexpanded);
 
+  /// Collect the set of unexpanded parameter packs from a lambda call 
operator.
+  ///
+  /// \param LambdaCall The lambda call operator that will be traversed to find
+  /// unexpanded parameter packs.
+  void collectUnexpandedParameterPacksFromLambda(
+  CXXMethodDecl *LambdaCall,
+  SmallVectorImpl &Unexpanded);
+
   /// Collect the set of unexpanded parameter packs within the given
   /// type.
   ///
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 903fbfd18e779c..638ceac4148aec 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -8,14 +8,15 @@
 //  This file implements semantic analysis for C++0x variadic templates.
 //===--===/
 
-#include "clang/Sema/Sema.h"
 #include "TypeLocBuilder.h"
+#include "clang/AST/ASTLambda.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/ScopeInfo.h"
+#include "clang/Sema/Sema.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
 #include 
@@ -61,8 +62,9 @@ namespace {
 
   public:
 explicit CollectUnexpandedParameterPacksVisitor(
-SmallVectorImpl &Unexpanded)
-: Unexpanded(Unexpanded) {}
+SmallVectorImpl &Unexpanded,
+bool InLambda = false)
+: Unexpanded(Unexpanded), InLambda(InLambda) {}
 
 bool shouldWalkTypesOfTypeLocs() const { return false; }
 
@@ -544,6 +546,14 @@ void Sema::collectUnexpandedParameterPacks(QualType T,
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
 }
 
+void Sema::collectUnexpandedParameterPacksFromLambda(
+CXXMethodDecl *LambdaCall,
+SmallVectorImpl &Unexpanded) {
+  assert(isLambdaCallOperator(LambdaCall) && "Expected a lambda call 
operator");
+  CollectUnexpandedParameterPacksVisitor(Unexpanded, /*InLambda=*/true)
+  .TraverseDecl(LambdaCall);
+}
+
 void Sema::collectUnexpandedParameterPacks(TypeLoc TL,
SmallVectorImpl &Unexpanded) {
   CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 2d22692f3ab750..f5a859c57034a5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13748,6 +13748,8 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 }
 NewVDs.push_back(NewVD);
 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
+LSI->ContainsUnexpandedParameterPack |=
+Init.get()->containsUnexpandedParameterPack();
   }
 
   if (Invalid)
@@ -13936,6 +13938,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 /*IsInstantiation*/ true);
   SavedContext.pop();
 
+  // The lambda may contain a pack that would be expanded by a fold expression
+  // outside. We should preserve the ContainsUnexpandedParameterPack flag here
+  // because CXXFoldExprs use it for the pattern.
+  // For example,
+  //
+  // []() { ([I = Is()]() {}, ...); }
+  //
+  // forgetting the flag will result in getPattern() of CXXFoldExpr returning
+  // null in term

[clang] [libcxx] [libc++] Implement LWG3528 (`make_from_tuple` can perform (the equivalent of) a C-style cast) (PR #85263)

2024-03-22 Thread via cfe-commits

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


[clang] 66f88de - [RISCV] Support RISC-V Profiles in -march option (#76357)

2024-03-22 Thread via cfe-commits

Author: Wang Pengcheng
Date: 2024-03-22T18:24:23+08:00
New Revision: 66f88de80599ec4461b0fdac3d1e396b6e83052d

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

LOG: [RISCV] Support RISC-V Profiles in -march option (#76357)

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.

Added: 
clang/test/Driver/riscv-profiles.c

Modified: 
clang/docs/ReleaseNotes.rst
llvm/lib/Support/RISCVISAInfo.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fd12bb41be47a3..005cdebc0d8ace 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -520,6 +520,7 @@ RISC-V Support
 ^^
 
 - ``__attribute__((rvv_vector_bits(N)))`` is now supported for RVV vbool*_t 
types.
+- Profile names in ``-march`` option are now supported.
 
 CUDA/HIP Language Changes
 ^

diff  --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..904f0c371f4442
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,312 @@
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+ziccamoa"
+// RVA20U64: "-target-feature" "+ziccif"
+// RVA20U64: "-target-feature" "+zicclsm"
+// RVA20U64: "-target-feature" "+ziccrse"
+// RVA20U64: "-target-feature" "+zicntr"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-feature" "+za128rs"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+ziccamoa"
+// RVA20S64: "-target-feature" "+ziccif"
+// RVA20S64: "-target-feature" "+zicclsm"
+// RVA20S64: "-target-feature" "+ziccrse"
+// RVA20S64: "-target-feature" "+zicntr"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-feature" "+za128rs"
+// RVA20S64: "-target-feature" "+ssccptr"
+// RVA20S64: "-target-feature" "+sstvala"
+// RVA20S64: "-target-feature" "+sstvecd"
+// RVA20S64: "-target-feature" "+svade"
+// RVA20S64: "-target-feature" "+svbare"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zic64b"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+ziccamoa"
+// RVA22U64: "-target-feature" "+ziccif"
+// RVA22U64: "-target-feature" "+zicclsm"
+// RVA22U64: "-target-feature" "+ziccrse"
+// RVA22U64: "-target-feature" "+zicntr"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zihpm"
+// RVA22U64: "-target-feature" "+za64rs"
+// RVA22U64: "-target-feature" "+zfhmin"
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck 
-check-prefix=RVA22S64 %s
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-target-feature" "+zic64b"
+// RVA22S64: "-target-feature" "+zicbom"
+// RVA22S64: "-target-feature" "+zicbop"
+// RVA22S64: "-target-feature" "+zicboz"
+// RVA22S64: "-target-feature" "+ziccamoa"
+// RVA22S64: "-target-feature" "+ziccif"
+// RVA22S64: "-target-feature" "+zicclsm"
+// RVA22S64: "-target-feature

[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-22 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> > I don't think intrinsics are meant for users. Builtins are the user-facing 
> > front. :-)
> 
> Depending on who you consider an user. Are folks writing MLIR generators 
> users?

They're consumers of an unstable API, changing intrinsics is fine 

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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-22 Thread Matt Arsenault via cfe-commits

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


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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-22 Thread Matt Arsenault via cfe-commits


@@ -432,13 +432,15 @@ TARGET_BUILTIN(__builtin_amdgcn_s_wakeup_barrier, "vi", 
"n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_barrier_leave, "b", "n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_get_barrier_state, "Uii", "n", "gfx12-insts")
 
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
-
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8bf16, "V8yV8y*1", "nc", 
"gfx12-insts,wavefrontsize32")
+
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4bf16, "V4yV4y*1", "nc", 
"gfx12-insts,wavefrontsize64")

arsenm wrote:

Do we really need the f16/bf16 versions? You can always bitcast the i16 
versions. 

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


[clang] [llvm] [RISCV] Support RISC-V Profiles in -march option (PR #76357)

2024-03-22 Thread Wang Pengcheng via cfe-commits

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


[clang] [libcxx] [libc++] Implement LWG3528 (`make_from_tuple` can perform (the equivalent of) a C-style cast) (PR #85263)

2024-03-22 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/85263

>From fc8c1a24f09c8860269fbdcfb0b285ffd19f427c Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Fri, 15 Mar 2024 00:48:08 +0800
Subject: [PATCH 01/12] [libc++] Implement LWG3528 (`make_from_tuple` can
 perform (the equivalent of) a C-style cast)

Signed-off-by: yronglin 
---
 libcxx/docs/Status/Cxx23Issues.csv|  2 +-
 libcxx/include/tuple  | 12 ++-
 .../tuple.apply/make_from_tuple.verify.cpp| 74 +++
 3 files changed, 85 insertions(+), 3 deletions(-)
 create mode 100644 
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.verify.cpp

diff --git a/libcxx/docs/Status/Cxx23Issues.csv 
b/libcxx/docs/Status/Cxx23Issues.csv
index e00345533b865d..0fd58649b0cf64 100644
--- a/libcxx/docs/Status/Cxx23Issues.csv
+++ b/libcxx/docs/Status/Cxx23Issues.csv
@@ -77,7 +77,7 @@
 `3523 `__,"``iota_view::sentinel`` is not always 
``iota_view``'s sentinel","June 2021","","","|ranges|"
 `3526 `__,"Return types of 
``uses_allocator_construction_args`` unspecified","June 2021","",""
 `3527 `__,"``uses_allocator_construction_args`` 
handles rvalue pairs of rvalue references incorrectly","June 2021","",""
-`3528 `__,"``make_from_tuple`` can perform (the 
equivalent of) a C-style cast","June 2021","",""
+`3528 `__,"``make_from_tuple`` can perform (the 
equivalent of) a C-style cast","June 2021","|Complete|","19.0"
 `3529 `__,"``priority_queue(first, last)`` should 
construct ``c`` with ``(first, last)``","June 2021","|Complete|","14.0"
 `3530 `__,"``BUILTIN-PTR-MEOW`` should not opt the 
type out of syntactic checks","June 2021","",""
 `3532 `__,"``split_view::inner-iterator::operator++(int)`` should depend on ``Base``","June 
2021","","","|ranges|"
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index 8808db6739fb9b..1ef546c5b2153d 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -1423,8 +1423,16 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) 
apply(_Fn&& __f, _Tuple&&
 typename 
__make_tuple_indices>>::type{}))
 
 template 
-inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& 
__t, __tuple_indices<_Idx...>)
-_LIBCPP_NOEXCEPT_RETURN(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...))
+inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& 
__t, __tuple_indices<_Idx...>) 
+  noexcept(noexcept(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...)))
+#if _LIBCPP_STD_VER >= 20
+  requires is_constructible_v<_Tp, 
decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...>
+#endif
+{
+  static_assert(is_constructible_v<_Tp, 
decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...>, 
+"Cannot constructible target type from the fields of the 
argument tuple.");
+  return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...);
+}
 
 template 
 inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp make_from_tuple(_Tuple&& __t)
diff --git 
a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.verify.cpp
 
b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.verify.cpp
new file mode 100644
index 00..9bdca4dc7813cb
--- /dev/null
+++ 
b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.verify.cpp
@@ -0,0 +1,74 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// 
+
+// template  constexpr T make_from_tuple(Tuple&&);
+
+#include 
+
+int main() {
+  // clang-format off
+#if _LIBCPP_STD_VER <= 20
+  // reinterpret_cast
+  {
+struct B { int b; } b;
+std::tuple t{&b};
+auto a = std::make_from_tuple(t); // expected-error-re@*:* {{static 
assertion failed {{.*}}Cannot constructible target type from the fields of the 
argument tuple.}}
+(void)a;
+  }
+
+  // const_cast
+  {
+const char *str = "Hello";
+std::tuple t{str};
+auto a = std::make_from_tuple(t); // expected-error-re@*:* 
{{static assertion failed {{.*}}Cannot constructible target type from the 
fields of the argument tuple.}}
+(void)a;
+  }
+
+  // static_cast
+  {
+struct B {};
+struct C : public B {} c;
+B &br = c;
+std::tuple t{br};
+auto a = std::make_from_tuple(t); // expected-error-re@*:* 
{{static assertion failed {{.*}}Cannot constructible target type from the 
fields of the argument tuple.}}
+(void)a;
+  }
+#else
+  // reinterpret_cast
+  {
+   

[clang] 6e755c5 - Revert "[RISCV] Support RISC-V Profiles in -march option (#76357)"

2024-03-22 Thread Wang Pengcheng via cfe-commits

Author: Wang Pengcheng
Date: 2024-03-22T18:49:25+08:00
New Revision: 6e755c51a916dc521ffe89738bcab47a5442ad06

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

LOG: Revert "[RISCV] Support RISC-V Profiles in -march option (#76357)"

This reverts commit 66f88de80599ec4461b0fdac3d1e396b6e83052d as
there are some failures.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
llvm/lib/Support/RISCVISAInfo.cpp

Removed: 
clang/test/Driver/riscv-profiles.c



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 005cdebc0d8ace..fd12bb41be47a3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -520,7 +520,6 @@ RISC-V Support
 ^^
 
 - ``__attribute__((rvv_vector_bits(N)))`` is now supported for RVV vbool*_t 
types.
-- Profile names in ``-march`` option are now supported.
 
 CUDA/HIP Language Changes
 ^

diff  --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
deleted file mode 100644
index 904f0c371f4442..00
--- a/clang/test/Driver/riscv-profiles.c
+++ /dev/null
@@ -1,312 +0,0 @@
-// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
-// RVI20U32: "-target-feature" "-a"
-// RVI20U32: "-target-feature" "-c"
-// RVI20U32: "-target-feature" "-d"
-// RVI20U32: "-target-feature" "-f"
-// RVI20U32: "-target-feature" "-m"
-
-// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck 
-check-prefix=RVI20U64 %s
-// RVI20U64: "-target-feature" "-a"
-// RVI20U64: "-target-feature" "-c"
-// RVI20U64: "-target-feature" "-d"
-// RVI20U64: "-target-feature" "-f"
-// RVI20U64: "-target-feature" "-m"
-
-// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck 
-check-prefix=RVA20U64 %s
-// RVA20U64: "-target-feature" "+m"
-// RVA20U64: "-target-feature" "+a"
-// RVA20U64: "-target-feature" "+f"
-// RVA20U64: "-target-feature" "+d"
-// RVA20U64: "-target-feature" "+c"
-// RVA20U64: "-target-feature" "+ziccamoa"
-// RVA20U64: "-target-feature" "+ziccif"
-// RVA20U64: "-target-feature" "+zicclsm"
-// RVA20U64: "-target-feature" "+ziccrse"
-// RVA20U64: "-target-feature" "+zicntr"
-// RVA20U64: "-target-feature" "+zicsr"
-// RVA20U64: "-target-feature" "+za128rs"
-
-// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck 
-check-prefix=RVA20S64 %s
-// RVA20S64: "-target-feature" "+m"
-// RVA20S64: "-target-feature" "+a"
-// RVA20S64: "-target-feature" "+f"
-// RVA20S64: "-target-feature" "+d"
-// RVA20S64: "-target-feature" "+c"
-// RVA20S64: "-target-feature" "+ziccamoa"
-// RVA20S64: "-target-feature" "+ziccif"
-// RVA20S64: "-target-feature" "+zicclsm"
-// RVA20S64: "-target-feature" "+ziccrse"
-// RVA20S64: "-target-feature" "+zicntr"
-// RVA20S64: "-target-feature" "+zicsr"
-// RVA20S64: "-target-feature" "+zifencei"
-// RVA20S64: "-target-feature" "+za128rs"
-// RVA20S64: "-target-feature" "+ssccptr"
-// RVA20S64: "-target-feature" "+sstvala"
-// RVA20S64: "-target-feature" "+sstvecd"
-// RVA20S64: "-target-feature" "+svade"
-// RVA20S64: "-target-feature" "+svbare"
-
-// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck 
-check-prefix=RVA22U64 %s
-// RVA22U64: "-target-feature" "+m"
-// RVA22U64: "-target-feature" "+a"
-// RVA22U64: "-target-feature" "+f"
-// RVA22U64: "-target-feature" "+d"
-// RVA22U64: "-target-feature" "+c"
-// RVA22U64: "-target-feature" "+zic64b"
-// RVA22U64: "-target-feature" "+zicbom"
-// RVA22U64: "-target-feature" "+zicbop"
-// RVA22U64: "-target-feature" "+zicboz"
-// RVA22U64: "-target-feature" "+ziccamoa"
-// RVA22U64: "-target-feature" "+ziccif"
-// RVA22U64: "-target-feature" "+zicclsm"
-// RVA22U64: "-target-feature" "+ziccrse"
-// RVA22U64: "-target-feature" "+zicntr"
-// RVA22U64: "-target-feature" "+zicsr"
-// RVA22U64: "-target-feature" "+zihintpause"
-// RVA22U64: "-target-feature" "+zihpm"
-// RVA22U64: "-target-feature" "+za64rs"
-// RVA22U64: "-target-feature" "+zfhmin"
-// RVA22U64: "-target-feature" "+zba"
-// RVA22U64: "-target-feature" "+zbb"
-// RVA22U64: "-target-feature" "+zbs"
-// RVA22U64: "-target-feature" "+zkt"
-
-// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck 
-check-prefix=RVA22S64 %s
-// RVA22S64: "-target-feature" "+m"
-// RVA22S64: "-target-feature" "+a"
-// RVA22S64: "-target-feature" "+f"
-// RVA22S64: "-target-feature" "+d"
-// RVA22S64: "-target-feature" "+c"
-// RVA22S64: "-target-feature" "+zic64b"
-// RVA22S64: "-target-feature" "+zicbom"
-// RVA22S64: "-target-feature" "+zicbop"
-// RVA22S64: "-target-feature" "+zicboz"
-// RVA22S64: "-target-feature" "+ziccamoa"
-// RVA22S64: "-target-feature" "+ziccif"
-// RVA22S64: "-target-feature" "+zicclsm"
-// RVA22S64: "-target-feature" "+ziccrse"
-// RVA22S64: "-target-feature" "+zicntr"
-// RVA22S64: "-target

[clang] [libcxx] [libc++] Implement LWG3528 (`make_from_tuple` can perform (the equivalent of) a C-style cast) (PR #85263)

2024-03-22 Thread Mark de Wever via cfe-commits

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

Thanks LGTM!

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


[clang] a62441d - [clang][analyzer][NFC] UnixAPIMisuseChecker inherits from Checker (#83027)

2024-03-22 Thread Balazs Benics via cfe-commits

Author: Alejandro Álvarez Ayllón
Date: 2024-03-22T11:50:34+01:00
New Revision: a62441d4bb6bd0cd8eccab8c5692340c5a2c60bb

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

LOG: [clang][analyzer][NFC] UnixAPIMisuseChecker inherits from 
Checker (#83027)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
index 19f1ca2dc824c9..599e5e6cedc606 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -17,6 +17,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "llvm/ADT/STLExtras.h"
@@ -41,8 +42,7 @@ enum class OpenVariant {
 namespace {
 
 class UnixAPIMisuseChecker
-: public Checker,
- check::ASTDecl> {
+: public Checker> {
   const BugType BT_open{this, "Improper use of 'open'", categories::UnixAPI};
   const BugType BT_pthreadOnce{this, "Improper use of 'pthread_once'",
categories::UnixAPI};
@@ -52,14 +52,14 @@ class UnixAPIMisuseChecker
   void checkASTDecl(const TranslationUnitDecl *TU, AnalysisManager &Mgr,
 BugReporter &BR) const;
 
-  void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
+  void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
 
-  void CheckOpen(CheckerContext &C, const CallExpr *CE) const;
-  void CheckOpenAt(CheckerContext &C, const CallExpr *CE) const;
-  void CheckPthreadOnce(CheckerContext &C, const CallExpr *CE) const;
+  void CheckOpen(CheckerContext &C, const CallEvent &Call) const;
+  void CheckOpenAt(CheckerContext &C, const CallEvent &Call) const;
+  void CheckPthreadOnce(CheckerContext &C, const CallEvent &Call) const;
 
-  void CheckOpenVariant(CheckerContext &C,
-const CallExpr *CE, OpenVariant Variant) const;
+  void CheckOpenVariant(CheckerContext &C, const CallEvent &Call,
+OpenVariant Variant) const;
 
   void ReportOpenBug(CheckerContext &C, ProgramStateRef State, const char *Msg,
  SourceRange SR) const;
@@ -113,9 +113,9 @@ void UnixAPIMisuseChecker::checkASTDecl(const 
TranslationUnitDecl *TU,
 // "open" (man 2 open)
 //===--===/
 
-void UnixAPIMisuseChecker::checkPreStmt(const CallExpr *CE,
+void UnixAPIMisuseChecker::checkPreCall(const CallEvent &Call,
 CheckerContext &C) const {
-  const FunctionDecl *FD = C.getCalleeDecl(CE);
+  const FunctionDecl *FD = dyn_cast_if_present(Call.getDecl());
   if (!FD || FD->getKind() != Decl::Function)
 return;
 
@@ -130,13 +130,13 @@ void UnixAPIMisuseChecker::checkPreStmt(const CallExpr 
*CE,
 return;
 
   if (FName == "open")
-CheckOpen(C, CE);
+CheckOpen(C, Call);
 
   else if (FName == "openat")
-CheckOpenAt(C, CE);
+CheckOpenAt(C, Call);
 
   else if (FName == "pthread_once")
-CheckPthreadOnce(C, CE);
+CheckPthreadOnce(C, Call);
 }
 void UnixAPIMisuseChecker::ReportOpenBug(CheckerContext &C,
  ProgramStateRef State,
@@ -152,17 +152,17 @@ void UnixAPIMisuseChecker::ReportOpenBug(CheckerContext 
&C,
 }
 
 void UnixAPIMisuseChecker::CheckOpen(CheckerContext &C,
- const CallExpr *CE) const {
-  CheckOpenVariant(C, CE, OpenVariant::Open);
+ const CallEvent &Call) const {
+  CheckOpenVariant(C, Call, OpenVariant::Open);
 }
 
 void UnixAPIMisuseChecker::CheckOpenAt(CheckerContext &C,
-   const CallExpr *CE) const {
-  CheckOpenVariant(C, CE, OpenVariant::OpenAt);
+   const CallEvent &Call) const {
+  CheckOpenVariant(C, Call, OpenVariant::OpenAt);
 }
 
 void UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
-const CallExpr *CE,
+const CallEvent &Call,
 OpenVariant Variant) const {
   // The index of the argument taking the flags open flags (O_RDONLY,
   // O_WRONLY, O_CREAT, etc.),
@@ -191,11 +191,11 @@ void 
UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
 
   ProgramStateRef state = C.getState();
 
-  if 

[clang] [clang-repl] Factor out CreateJITBuilder() and allow specialization in derived classes (PR #84461)

2024-03-22 Thread Stefan Gränitz via cfe-commits

https://github.com/weliveindetail updated 
https://github.com/llvm/llvm-project/pull/84461

From fae2f46d25650b8480f9d3135f33a0d6532f43ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Thu, 7 Mar 2024 23:04:22 +0100
Subject: [PATCH 1/2] [clang-repl] Add CreateJITBuilder() for specialization in
 derived classes

The LLJITBuilder interface provides a very convenient way to configure the JIT.
---
 clang/include/clang/Interpreter/Interpreter.h |   9 ++
 clang/lib/Interpreter/IncrementalExecutor.cpp |  33 ++---
 clang/lib/Interpreter/IncrementalExecutor.h   |   9 +-
 clang/lib/Interpreter/Interpreter.cpp |  26 +++-
 .../Interpreter/InterpreterExtensionsTest.cpp | 117 +-
 5 files changed, 173 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 1dcba1ef967980..33ce4bbf5bea10 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -29,7 +29,9 @@
 
 namespace llvm {
 namespace orc {
+class JITTargetMachineBuilder;
 class LLJIT;
+class LLJITBuilder;
 class ThreadSafeContext;
 } // namespace orc
 } // namespace llvm
@@ -127,6 +129,13 @@ class Interpreter {
   // custom runtime.
   virtual std::unique_ptr FindRuntimeInterface();
 
+  // Lazily construct thev ORCv2 JITBuilder. This called when the internal
+  // IncrementalExecutor is created. The default implementation populates an
+  // in-process JIT with debugging support. Override this to configure the JIT
+  // engine used for execution.
+  virtual llvm::Expected>
+  CreateJITBuilder(CompilerInstance &CI);
+
 public:
   virtual ~Interpreter();
 
diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 40bcef94797d43..6f036107c14a9c 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -20,6 +20,7 @@
 #include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
+#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
 #include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
@@ -36,26 +37,28 @@ LLVM_ATTRIBUTE_USED void linkComponents() {
 
 namespace clang {
 
+llvm::Expected>
+IncrementalExecutor::createDefaultJITBuilder(
+llvm::orc::JITTargetMachineBuilder JTMB) {
+  auto JITBuilder = std::make_unique();
+  JITBuilder->setJITTargetMachineBuilder(std::move(JTMB));
+  JITBuilder->setPrePlatformSetup([](llvm::orc::LLJIT &J) {
+// Try to enable debugging of JIT'd code (only works with JITLink for
+// ELF and MachO).
+consumeError(llvm::orc::enableDebuggerSupport(J));
+return llvm::Error::success();
+  });
+  return std::move(JITBuilder);
+}
+
 IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
- llvm::Error &Err,
- const clang::TargetInfo &TI)
+ llvm::orc::LLJITBuilder &JITBuilder,
+ llvm::Error &Err)
 : TSCtx(TSC) {
   using namespace llvm::orc;
   llvm::ErrorAsOutParameter EAO(&Err);
 
-  auto JTMB = JITTargetMachineBuilder(TI.getTriple());
-  JTMB.addFeatures(TI.getTargetOpts().Features);
-  LLJITBuilder Builder;
-  Builder.setJITTargetMachineBuilder(JTMB);
-  Builder.setPrePlatformSetup(
-  [](LLJIT &J) {
-// Try to enable debugging of JIT'd code (only works with JITLink for
-// ELF and MachO).
-consumeError(enableDebuggerSupport(J));
-return llvm::Error::success();
-  });
-
-  if (auto JitOrErr = Builder.create())
+  if (auto JitOrErr = JITBuilder.create())
 Jit = std::move(*JitOrErr);
   else {
 Err = JitOrErr.takeError();
diff --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index dd0a210a061415..b4347209e14fe3 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -23,7 +23,9 @@
 namespace llvm {
 class Error;
 namespace orc {
+class JITTargetMachineBuilder;
 class LLJIT;
+class LLJITBuilder;
 class ThreadSafeContext;
 } // namespace orc
 } // namespace llvm
@@ -44,8 +46,8 @@ class IncrementalExecutor {
 public:
   enum SymbolNameKind { IRName, LinkerName };
 
-  IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC, llvm::Error &Err,
-  const clang::TargetInfo &TI);
+  IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
+  llvm::orc::LLJITBuilder &JITBuilder, llvm::Error &Err);
   ~IncrementalExecutor();
 
   llvm::Error addModule(PartialTranslationUnit &PTU);
@@ -56,6 +58,9 @@ class IncrementalExecutor {
   getSymbolA

[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-22 Thread Balazs Benics via cfe-commits
Alejandro =?utf-8?q?=C3=81lvarez_Ayll=C3=B3n?=
Message-ID:
In-Reply-To: 


steakhal wrote:

Rebase merged.

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


[clang] [analyzer] Set and display CSA analysis entry points as notes on debugging (PR #84823)

2024-03-22 Thread Balazs Benics via cfe-commits

steakhal wrote:

Ping @NagyDonat 

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


[clang] [clang][analyzer] Model more getline/getdelim pre and postconditions (PR #83027)

2024-03-22 Thread Balazs Benics via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 


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


[clang] [analyzer] Support C++23 static operator calls (PR #84972)

2024-03-22 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/84972

>From f66c62bcf3fd1427ad3f5061ec23110c1c3a5b6e Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Tue, 12 Mar 2024 19:55:29 +0100
Subject: [PATCH] [analyzer] Support C++23 static operator calls

Made by following:
https://github.com/llvm/llvm-project/pull/83585#issuecomment-1980340866

Thanks for the details Tomek!
---
 clang/docs/ReleaseNotes.rst   |  1 +
 .../Core/PathSensitive/CallEvent.h| 72 +++
 clang/lib/StaticAnalyzer/Core/CallEvent.cpp   |  5 +-
 .../Core/ExprEngineCallAndReturn.cpp  |  1 +
 clang/test/Analysis/cxx23-static-operator.cpp | 38 ++
 5 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Analysis/cxx23-static-operator.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fd12bb41be47a3..45b2e01af997c5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -576,6 +576,7 @@ Static Analyzer
 - Fixed crashing on loops if the loop variable was declared in switch blocks
   but not under any case blocks if ``unroll-loops=true`` analyzer config is
   set. (#GH68819)
+- Support C++23 static operator calls. (#GH84972)
 
 New features
 
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index 0d36587484bf9c..549c864dc91ef2 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -59,6 +59,7 @@ namespace ento {
 
 enum CallEventKind {
   CE_Function,
+  CE_CXXStaticOperator,
   CE_CXXMember,
   CE_CXXMemberOperator,
   CE_CXXDestructor,
@@ -709,6 +710,77 @@ class CXXInstanceCall : public AnyFunctionCall {
   }
 };
 
+/// Represents a static C++ operator call.
+///
+/// "A" in this example.
+/// However, "B" and "C" are represented by SimpleFunctionCall.
+/// \code
+///   struct S {
+/// int pad;
+/// static void operator()(int x, int y);
+///   };
+///   S s{10};
+///   void (*fptr)(int, int) = &S::operator();
+///
+///   s(1, 2);  // A
+///   S::operator()(1, 2);  // B
+///   fptr(1, 2); // C
+/// \endcode
+class CXXStaticOperatorCall : public SimpleFunctionCall {
+  friend class CallEventManager;
+
+protected:
+  CXXStaticOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St,
+const LocationContext *LCtx,
+CFGBlock::ConstCFGElementRef ElemRef)
+  : SimpleFunctionCall(CE, St, LCtx, ElemRef) {}
+  CXXStaticOperatorCall(const CXXStaticOperatorCall &Other) = default;
+
+  void cloneTo(void *Dest) const override {
+new (Dest) CXXStaticOperatorCall(*this);
+  }
+
+public:
+  const CXXOperatorCallExpr *getOriginExpr() const override {
+return cast(SimpleFunctionCall::getOriginExpr());
+  }
+
+  unsigned getNumArgs() const override {
+// Ignore the object parameter that is not used for static member 
functions.
+assert(getOriginExpr()->getNumArgs() > 0);
+return getOriginExpr()->getNumArgs() - 1;
+  }
+
+  const Expr *getArgExpr(unsigned Index) const override {
+// Ignore the object parameter that is not used for static member 
functions.
+return getOriginExpr()->getArg(Index + 1);
+  }
+
+  std::optional
+  getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override {
+// Ignore the object parameter that is not used for static member 
functions.
+if (ASTArgumentIndex == 0)
+  return std::nullopt;
+return ASTArgumentIndex - 1;
+  }
+
+  unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override {
+// Account for the object parameter for the static member function.
+return CallArgumentIndex + 1;
+  }
+
+  OverloadedOperatorKind getOverloadedOperator() const {
+return getOriginExpr()->getOperator();
+  }
+
+  Kind getKind() const override { return CE_CXXStaticOperator; }
+  StringRef getKindAsString() const override { return "CXXStaticOperatorCall"; 
}
+
+  static bool classof(const CallEvent *CA) {
+return CA->getKind() == CE_CXXStaticOperator;
+  }
+};
+
 /// Represents a non-static C++ member function call.
 ///
 /// Example: \c obj.fun()
diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp 
b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
index bc14aea27f6736..0e317ec765ec09 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -1408,9 +1408,12 @@ CallEventManager::getSimpleCall(const CallExpr *CE, 
ProgramStateRef State,
 
   if (const auto *OpCE = dyn_cast(CE)) {
 const FunctionDecl *DirectCallee = OpCE->getDirectCallee();
-if (const auto *MD = dyn_cast(DirectCallee))
+if (const auto *MD = dyn_cast(DirectCallee)) {
   if (MD->isImplicitObjectMemberFunction())
 return create(OpCE, State, LCtx, ElemRef);
+  if (MD->isStatic())
+return create

[clang] 730ca47 - [clang][analyzer] Model getline/getdelim preconditions and evaluation (#83027)

2024-03-22 Thread Balazs Benics via cfe-commits

Author: Alejandro Álvarez Ayllón
Date: 2024-03-22T11:50:34+01:00
New Revision: 730ca47a0cc7380def6df1d25b30c1378fd8bf14

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

LOG: [clang][analyzer] Model getline/getdelim preconditions and evaluation 
(#83027)

According to POSIX 2018.

1. lineptr, n and stream can not be NULL.
2. If *n is non-zero, *lineptr must point to a region of at least *n
   bytes, or be a NULL pointer.

Additionally, if *lineptr is not NULL, *n must not be undefined.

Added: 
clang/test/Analysis/getline-unixapi.c

Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
clang/test/Analysis/stream.c

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
index 60421e5437d82f..d053a97189123a 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
@@ -15,7 +15,6 @@
 
 #include "ProgramState_Fwd.h"
 #include "SVals.h"
-
 #include "clang/AST/OperationKinds.h"
 #include "clang/AST/Stmt.h"
 #include "clang/Basic/OperatorKinds.h"
@@ -113,8 +112,7 @@ class OperatorKind {
 OperatorKind operationKindFromOverloadedOperator(OverloadedOperatorKind OOK,
  bool IsBinary);
 
-std::optional getPointeeDefVal(SVal PtrSVal,
-ProgramStateRef State);
+std::optional getPointeeVal(SVal PtrSVal, ProgramStateRef State);
 
 } // namespace ento
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 03cb7696707fe2..c2d96f59260906 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1441,7 +1441,7 @@ void MallocChecker::preGetdelim(const CallEvent &Call,
 return;
 
   ProgramStateRef State = C.getState();
-  const auto LinePtr = getPointeeDefVal(Call.getArgSVal(0), State);
+  const auto LinePtr = getPointeeVal(Call.getArgSVal(0), State);
   if (!LinePtr)
 return;
 
@@ -1470,8 +1470,10 @@ void MallocChecker::checkGetdelim(const CallEvent &Call,
 
   SValBuilder &SVB = C.getSValBuilder();
 
-  const auto LinePtr = getPointeeDefVal(Call.getArgSVal(0), State);
-  const auto Size = getPointeeDefVal(Call.getArgSVal(1), State);
+  const auto LinePtr =
+  getPointeeVal(Call.getArgSVal(0), State)->getAs();
+  const auto Size =
+  getPointeeVal(Call.getArgSVal(1), State)->getAs();
   if (!LinePtr || !Size || !LinePtr->getAsRegion())
 return;
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 10972158f39862..902c42a2799be4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -1200,10 +1200,25 @@ void StreamChecker::evalGetdelim(const FnDescription 
*Desc,
 
 // Add transition for the successful state.
 NonLoc RetVal = makeRetVal(C, E.CE).castAs();
-ProgramStateRef StateNotFailed =
-State->BindExpr(E.CE, C.getLocationContext(), RetVal);
+ProgramStateRef StateNotFailed = E.bindReturnValue(State, C, RetVal);
 StateNotFailed =
 E.assumeBinOpNN(StateNotFailed, BO_GE, RetVal, E.getZeroVal(Call));
+
+// On success, a buffer is allocated.
+auto NewLinePtr = getPointeeVal(Call.getArgSVal(0), State);
+if (NewLinePtr && isa(*NewLinePtr))
+  StateNotFailed = StateNotFailed->assume(
+  NewLinePtr->castAs(), true);
+
+// The buffer size `*n` must be enough to hold the whole line, and
+// greater than the return value, since it has to account for '\0'.
+SVal SizePtrSval = Call.getArgSVal(1);
+auto NVal = getPointeeVal(SizePtrSval, State);
+if (NVal && isa(*NVal)) {
+  StateNotFailed = E.assumeBinOpNN(StateNotFailed, BO_GT,
+   NVal->castAs(), RetVal);
+  StateNotFailed = E.bindReturnValue(StateNotFailed, C, RetVal);
+}
 if (!StateNotFailed)
   return;
 C.addTransition(StateNotFailed);
@@ -1217,6 +1232,10 @@ void StreamChecker::evalGetdelim(const FnDescription 
*Desc,
   E.isStreamEof() ? ErrorFEof : ErrorFEof | ErrorFError;
   StateFailed = E.setStreamState(
   StateFailed, StreamState::getOpened(Desc, NewES, !NewES.isFEof()));
+  // On failure, the content of the buffer is undefined.
+  if (auto Ne

[clang] e925968 - [analyzer] Support C++23 static operator calls (#84972)

2024-03-22 Thread via cfe-commits

Author: Balazs Benics
Date: 2024-03-22T12:04:44+01:00
New Revision: e925968e7815ac3810fdb54bb884b8a8bed02eb5

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

LOG: [analyzer] Support C++23 static operator calls (#84972)

Made by following:
https://github.com/llvm/llvm-project/pull/83585#issuecomment-1980340866

Thanks for the details Tomek!

CPP-5080

Added: 
clang/test/Analysis/cxx23-static-operator.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
clang/lib/StaticAnalyzer/Core/CallEvent.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fd12bb41be47a3..45b2e01af997c5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -576,6 +576,7 @@ Static Analyzer
 - Fixed crashing on loops if the loop variable was declared in switch blocks
   but not under any case blocks if ``unroll-loops=true`` analyzer config is
   set. (#GH68819)
+- Support C++23 static operator calls. (#GH84972)
 
 New features
 

diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index 0d36587484bf9c..549c864dc91ef2 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -59,6 +59,7 @@ namespace ento {
 
 enum CallEventKind {
   CE_Function,
+  CE_CXXStaticOperator,
   CE_CXXMember,
   CE_CXXMemberOperator,
   CE_CXXDestructor,
@@ -709,6 +710,77 @@ class CXXInstanceCall : public AnyFunctionCall {
   }
 };
 
+/// Represents a static C++ operator call.
+///
+/// "A" in this example.
+/// However, "B" and "C" are represented by SimpleFunctionCall.
+/// \code
+///   struct S {
+/// int pad;
+/// static void operator()(int x, int y);
+///   };
+///   S s{10};
+///   void (*fptr)(int, int) = &S::operator();
+///
+///   s(1, 2);  // A
+///   S::operator()(1, 2);  // B
+///   fptr(1, 2); // C
+/// \endcode
+class CXXStaticOperatorCall : public SimpleFunctionCall {
+  friend class CallEventManager;
+
+protected:
+  CXXStaticOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St,
+const LocationContext *LCtx,
+CFGBlock::ConstCFGElementRef ElemRef)
+  : SimpleFunctionCall(CE, St, LCtx, ElemRef) {}
+  CXXStaticOperatorCall(const CXXStaticOperatorCall &Other) = default;
+
+  void cloneTo(void *Dest) const override {
+new (Dest) CXXStaticOperatorCall(*this);
+  }
+
+public:
+  const CXXOperatorCallExpr *getOriginExpr() const override {
+return cast(SimpleFunctionCall::getOriginExpr());
+  }
+
+  unsigned getNumArgs() const override {
+// Ignore the object parameter that is not used for static member 
functions.
+assert(getOriginExpr()->getNumArgs() > 0);
+return getOriginExpr()->getNumArgs() - 1;
+  }
+
+  const Expr *getArgExpr(unsigned Index) const override {
+// Ignore the object parameter that is not used for static member 
functions.
+return getOriginExpr()->getArg(Index + 1);
+  }
+
+  std::optional
+  getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override {
+// Ignore the object parameter that is not used for static member 
functions.
+if (ASTArgumentIndex == 0)
+  return std::nullopt;
+return ASTArgumentIndex - 1;
+  }
+
+  unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override {
+// Account for the object parameter for the static member function.
+return CallArgumentIndex + 1;
+  }
+
+  OverloadedOperatorKind getOverloadedOperator() const {
+return getOriginExpr()->getOperator();
+  }
+
+  Kind getKind() const override { return CE_CXXStaticOperator; }
+  StringRef getKindAsString() const override { return "CXXStaticOperatorCall"; 
}
+
+  static bool classof(const CallEvent *CA) {
+return CA->getKind() == CE_CXXStaticOperator;
+  }
+};
+
 /// Represents a non-static C++ member function call.
 ///
 /// Example: \c obj.fun()

diff  --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp 
b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
index bc14aea27f6736..0e317ec765ec09 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -1408,9 +1408,12 @@ CallEventManager::getSimpleCall(const CallExpr *CE, 
ProgramStateRef State,
 
   if (const auto *OpCE = dyn_cast(CE)) {
 const FunctionDecl *DirectCallee = OpCE->getDirectCallee();
-if (const auto *MD = dyn_cast(DirectCallee))
+if (const auto *MD = dyn_cast(DirectCallee)) {
   if (MD->isImplicitObjectMemberFunction())
 return create(OpCE, State, LCtx, Ele

[clang] [analyzer] Support C++23 static operator calls (PR #84972)

2024-03-22 Thread Balazs Benics via cfe-commits

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


[clang] [FMV] Allow fmv without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/85454

>From 60a6fcd7560ec434a8369240f7a9cd13cf035c42 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Fri, 15 Mar 2024 19:25:16 +
Subject: [PATCH] [FMV] Allow multi versioning without default declaration.

This was a limitation which has now been lifted. Please read the
thread below for more details:

https://github.com/llvm/llvm-project/pull/84405#discussion_r1525583647

Basically it allows to separate versioned implementations across
different TUs without having to share private header files which
contain the default declaration.

The ACLE spec has been updated accordingly to make this explicit:
"Each version declaration should be visible at the translation
 unit in which the corresponding function version resides."

https://github.com/ARM-software/acle/pull/310

If a resolver is required (because there is a caller in the TU),
then a default declaration is implicitly generated.
---
 clang/lib/CodeGen/CodeGenModule.cpp   | 124 
 clang/lib/Sema/SemaDecl.cpp   |   6 +-
 clang/lib/Sema/SemaOverload.cpp   |  44 ++-
 clang/test/CodeGen/attr-target-version.c  | 298 --
 clang/test/CodeGenCXX/attr-target-version.cpp |  62 ++--
 clang/test/Sema/aarch64-sme-func-attrs.c  |   8 +-
 clang/test/Sema/attr-target-version.c |   8 +-
 clang/test/SemaCXX/attr-target-version.cpp|  11 +-
 8 files changed, 339 insertions(+), 222 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index cb153066b28dd1..72a6dd63ce51b0 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4092,6 +4092,23 @@ llvm::GlobalValue::LinkageTypes 
getMultiversionLinkage(CodeGenModule &CGM,
   return llvm::GlobalValue::WeakODRLinkage;
 }
 
+static FunctionDecl *createDefaultTargetVersionFrom(const FunctionDecl *FD) {
+  DeclContext *DeclCtx = FD->getASTContext().getTranslationUnitDecl();
+  TypeSourceInfo *TInfo = FD->getTypeSourceInfo();
+  StorageClass SC = FD->getStorageClass();
+  DeclarationName Name = FD->getNameInfo().getName();
+
+  FunctionDecl *NewDecl =
+  FunctionDecl::Create(FD->getASTContext(), DeclCtx, FD->getBeginLoc(),
+   FD->getEndLoc(), Name, TInfo->getType(), TInfo, SC);
+
+  NewDecl->setIsMultiVersion();
+  NewDecl->addAttr(TargetVersionAttr::CreateImplicit(
+  NewDecl->getASTContext(), "default", NewDecl->getSourceRange()));
+
+  return NewDecl;
+}
+
 void CodeGenModule::emitMultiVersionFunctions() {
   std::vector MVFuncsToEmit;
   MultiVersionFuncs.swap(MVFuncsToEmit);
@@ -4099,70 +4116,54 @@ void CodeGenModule::emitMultiVersionFunctions() {
 const auto *FD = cast(GD.getDecl());
 assert(FD && "Expected a FunctionDecl");
 
-bool EmitResolver = !FD->isTargetVersionMultiVersion();
+auto createFunction = [&](const FunctionDecl *Decl, unsigned MVIdx = 0) {
+  GlobalDecl CurGD{Decl->isDefined() ? Decl->getDefinition() : Decl, 
MVIdx};
+  StringRef MangledName = getMangledName(CurGD);
+  llvm::Constant *Func = GetGlobalValue(MangledName);
+  if (!Func) {
+if (Decl->isDefined()) {
+  EmitGlobalFunctionDefinition(CurGD, nullptr);
+  Func = GetGlobalValue(MangledName);
+} else {
+  const CGFunctionInfo &FI = 
getTypes().arrangeGlobalDeclaration(CurGD);
+  llvm::FunctionType *Ty = getTypes().GetFunctionType(FI);
+  Func = GetAddrOfFunction(CurGD, Ty, /*ForVTable=*/false,
+   /*DontDefer=*/false, ForDefinition);
+}
+assert(Func && "This should have just been created");
+  }
+  return cast(Func);
+};
+
+bool HasDefaultDecl = !FD->isTargetVersionMultiVersion();
+bool ShouldEmitResolver = !FD->isTargetVersionMultiVersion();
 SmallVector Options;
 if (FD->isTargetMultiVersion()) {
   getContext().forEachMultiversionedFunctionVersion(
-  FD, [this, &GD, &Options, &EmitResolver](const FunctionDecl *CurFD) {
-GlobalDecl CurGD{
-(CurFD->isDefined() ? CurFD->getDefinition() : CurFD)};
-StringRef MangledName = getMangledName(CurGD);
-llvm::Constant *Func = GetGlobalValue(MangledName);
-if (!Func) {
-  if (CurFD->isDefined()) {
-EmitGlobalFunctionDefinition(CurGD, nullptr);
-Func = GetGlobalValue(MangledName);
-  } else {
-const CGFunctionInfo &FI =
-getTypes().arrangeGlobalDeclaration(GD);
-llvm::FunctionType *Ty = getTypes().GetFunctionType(FI);
-Func = GetAddrOfFunction(CurGD, Ty, /*ForVTable=*/false,
- /*DontDefer=*/false, ForDefinition);
-  }
-  assert(Func && "This should have just been created");
-}
-if (CurF

[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-22 Thread Karl-Johan Karlsson via cfe-commits

https://github.com/karka228 updated 
https://github.com/llvm/llvm-project/pull/74440

>From aa9d6cd10ff32fdcdd3d1b2ef334aa70f56cccb1 Mon Sep 17 00:00:00 2001
From: Karl-Johan Karlsson 
Date: Tue, 5 Dec 2023 10:03:00 +0100
Subject: [PATCH 1/7] [Sema] Implement support for -Wformat-signedness

In gcc there exist a modifier option -Wformat-signedness that turns on
additional signedness warnings in the already existing -Wformat warning.

This patch implements that support in clang.
---
 clang/include/clang/AST/FormatString.h|   2 +
 .../include/clang/Basic/DiagnosticOptions.def |   1 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/AST/FormatString.cpp|  29 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   2 +
 clang/lib/Sema/SemaChecking.cpp   |  26 -
 format-strings-signedness.c   | 107 ++
 7 files changed, 158 insertions(+), 12 deletions(-)
 create mode 100644 format-strings-signedness.c

diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index e2232fb4a47153..41cd0443ca2ac7 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -275,6 +275,8 @@ class ArgType {
 /// The conversion specifier and the argument type are compatible. For
 /// instance, "%d" and int.
 Match = 1,
+/// The conversion specifier and the argument type have different sign
+MatchSignedness,
 /// The conversion specifier and the argument type are compatible because 
of
 /// default argument promotions. For instance, "%hhd" and int.
 MatchPromotion,
diff --git a/clang/include/clang/Basic/DiagnosticOptions.def 
b/clang/include/clang/Basic/DiagnosticOptions.def
index 6d0c1b14acc120..a9562e7d8dcb0d 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.def
+++ b/clang/include/clang/Basic/DiagnosticOptions.def
@@ -44,6 +44,7 @@ DIAGOPT(Name, Bits, Default)
 #endif
 
 SEMANTIC_DIAGOPT(IgnoreWarnings, 1, 0)   /// -w
+DIAGOPT(FormatSignedness, 1, 0) /// -Wformat-signedness
 DIAGOPT(NoRewriteMacros, 1, 0)  /// -Wno-rewrite-macros
 DIAGOPT(Pedantic, 1, 0) /// -pedantic
 DIAGOPT(PedanticErrors, 1, 0)   /// -pedantic-errors
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4a954258ce40b6..1698c6c89e6e98 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -954,6 +954,9 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
+def Wformat_signedness : Flag<["-"], "Wformat-signedness">,
+  Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
+  MarshallingInfoFlag>;
 def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
   Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index 0c80ad109ccbb2..bdd2f046113e7e 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -413,7 +413,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const {
 return Match;
   if (const auto *BT = argTy->getAs()) {
 // Check if the only difference between them is signed vs unsigned
-// if true, we consider they are compatible.
+// if true, return match signedness.
 switch (BT->getKind()) {
   default:
 break;
@@ -423,44 +423,53 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 [[fallthrough]];
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchTypeConfusion;
+if (T == C.UnsignedCharTy)
+  return MatchSignedness;
+if (T == C.SignedCharTy)
+  return Match;
+break;
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
 if (T == C.UnsignedShortTy || T == C.ShortTy)
   return NoMatchTypeConfusion;
-if (T == C.UnsignedCharTy || T == C.SignedCharTy)
+if (T == C.UnsignedCharTy)
   return Match;
+if (T == C.SignedCharTy)
+  return MatchSignedness;
 break;
   case BuiltinType::Short:
 if (T == C.UnsignedShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::UShort:
 if (T == C.ShortTy)
-  return Match;
+  return MatchSignedness;
 break;
   case BuiltinType::Int:
 if (T == C.UnsignedIntTy)
-  return Match;
+  return MatchSignedness;
 b

[clang] [FMV] Allow fmv without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits

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


[clang] [clang-repl] Fix Value for platforms where unqualified char is unsigned (PR #86118)

2024-03-22 Thread Stefan Gränitz via cfe-commits

https://github.com/weliveindetail updated 
https://github.com/llvm/llvm-project/pull/86118

From 0b7f4bc8bf57219f5f1e5ffa06c986beb16b9546 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Thu, 21 Mar 2024 14:04:10 +0100
Subject: [PATCH 1/3] Add reproducer

---
 clang/unittests/Interpreter/InterpreterTest.cpp | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index e76c0677db5ead..25f6e4f900c882 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -340,6 +340,11 @@ TEST(InterpreterTest, Value) {
   EXPECT_EQ(V1.getKind(), Value::K_Int);
   EXPECT_FALSE(V1.isManuallyAlloc());
 
+  Value V1b;
+  llvm::cantFail(Interp->ParseAndExecute("char x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("c", &V1b));
+  EXPECT_TRUE(V1b.getKind() == Value::K_Char_S);
+
   Value V2;
   llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
   llvm::cantFail(Interp->ParseAndExecute("y", &V2));

From eace13b5c95680feeab7792eab675e8dd56a56ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Thu, 21 Mar 2024 14:05:05 +0100
Subject: [PATCH 2/3] Add missing REPL_BUILTIN_TYPE

---
 clang/include/clang/Interpreter/Value.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/include/clang/Interpreter/Value.h 
b/clang/include/clang/Interpreter/Value.h
index c380cd91550def..d70e8f8719026b 100644
--- a/clang/include/clang/Interpreter/Value.h
+++ b/clang/include/clang/Interpreter/Value.h
@@ -76,6 +76,7 @@ class QualType;
   X(bool, Bool)
\
   X(char, Char_S)  
\
   X(signed char, SChar)
\
+  X(unsigned char, Char_U) 
\
   X(unsigned char, UChar)  
\
   X(short, Short)  
\
   X(unsigned short, UShort)
\

From 7db25a9f186818297d3ec0e7d3deff67e4549927 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Thu, 21 Mar 2024 14:33:50 +0100
Subject: [PATCH 3/3] Accept signed or unsigned for unqualified char in
 reproducer

---
 clang/unittests/Interpreter/InterpreterTest.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 25f6e4f900c882..69bc2da242884e 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -341,9 +341,10 @@ TEST(InterpreterTest, Value) {
   EXPECT_FALSE(V1.isManuallyAlloc());
 
   Value V1b;
-  llvm::cantFail(Interp->ParseAndExecute("char x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("char c = 42;"));
   llvm::cantFail(Interp->ParseAndExecute("c", &V1b));
-  EXPECT_TRUE(V1b.getKind() == Value::K_Char_S);
+  EXPECT_TRUE(V1b.getKind() == Value::K_Char_S ||
+  V1b.getKind() == Value::K_Char_U);
 
   Value V2;
   llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));

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


[clang] [clang-repl] Fix Value for platforms where unqualified char is unsigned (PR #86118)

2024-03-22 Thread Stefan Gränitz via cfe-commits

weliveindetail wrote:

Let's give the pre-merge checks a 2nd chance..

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


[clang] [libcxx] [libc++] Implement LWG3528 (`make_from_tuple` can perform (the equivalent of) a C-style cast) (PR #85263)

2024-03-22 Thread via cfe-commits

yronglin wrote:

> Thanks LGTM!

Thanks for your review!

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


[clang] [FMV] Allow fmv without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

Update: The ACLE spec is now explicit about this (see 
https://github.com/ARM-software/acle/pull/310), so we can safely implement the 
change in the compiler. Implementation-wise I have moved the static cast to 
`llvm::Function` inside the `createFunction()` lambda.

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


[clang] [FMV] Allow multi versioning without default declaration. (PR #85454)

2024-03-22 Thread Alexandros Lamprineas via cfe-commits

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


[clang] Split -Wcast-function-type into a separate group (PR #86131)

2024-03-22 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> @AaronBallman @amy-kwan I am working on a patch for this build breaking in 
> https://lab.llvm.org/buildbot/#/builders/57/builds/33656. Is there anything 
> else I should also be considering?

Thank you for working on the patch! I would change the definition of 
`MallocStress()` in `asan_noinst_test.cpp` to accept a `void *` as expected by 
`pthread_create()`, then remove the cast in `ThreadedMallocStressTest` and add 
a cast for the call in `NoInstMallocTest`.

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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-22 Thread zhijian lin via cfe-commits

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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-22 Thread zhijian lin via cfe-commits

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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-22 Thread zhijian lin via cfe-commits


@@ -337,12 +347,58 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(uint64_t &TypeSize) const {
+  llvm::Type *ElemTy;
+  unsigned RegsNeeded; // Registers Needed for Complex.
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+RegsNeeded = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+RegsNeeded = (TypeSize + 31) / 32;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int &ArgGPRsLeft) const {
+  assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  ASTContext &Context = getContext();
+
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (IsComplexInRegABI && Ty->isAnyComplexType() &&
+  TypeSize <= RegLen * ArgGPRsLeft) {
+assert(Ty->isAnyComplexType() && "Ty must be Complex type.");
+ArgGPRsLeft -= TypeSize / RegLen;
+return handleComplex(TypeSize);
+  }
+
+  if (ArgGPRsLeft) {
+// Records with non-trivial destructors/copy-constructors should not be
+// passed by value.
+if (isAggregateTypeForABI(Ty))
+  ArgGPRsLeft -= 1;
+else if (!Ty->isFloatingType()) {
+  // For other premitive types.
+  if (TypeSize > RegLen && TypeSize <= 2 * RegLen)
+ArgGPRsLeft -= TypeSize / RegLen;

diggerlin wrote:

for a test case `foo6(_Complex long double foo4(int x1, long  long y1, int x2, 
_Complex double z,)`
 
 `int x1` will have r3, 
`long long y1` will have r5,r6 (skip r4 since it is even, for 64bit integer 
need to start start odd register.)
`int x2` will have r7, 
` _Complex double z`  need to occupy 4 registers, there is no enough register , 
it can not pass `_Complex double z` in r8,r9,r10 , you have to pass ` _Complex 
double z` in by pointer (you can not call `handleComplex()`). 

but in your code, 
ArgGPRsLeft is 7 after int x1,
ArgGPRsLeft is 5 after long long y1
ArgGPRsLeft is 4 after int x2

there is still have 4 registers left for ` _Complex double z`, you can call 
`handleComplex()`,  you will pass ` _Complex double z` by value 

can you check how gcc deal with this case   `foo6(_Complex long double foo4(int 
x1, long  long y1, int x2, _Complex double z,)`  ?

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


[clang] d03f470 - [Clang] Make '-frtlib-add-rpath' include the standard library directory (#86217)

2024-03-22 Thread via cfe-commits

Author: Joseph Huber
Date: 2024-03-22T06:54:33-05:00
New Revision: d03f470cbdbae3f86469ea4d79bb54d3ef680512

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

LOG: [Clang] Make '-frtlib-add-rpath' include the standard library directory 
(#86217)

Summary:
The original intention of the `openmp-add-rpath` option was to add the
rpath to the language runtime directory. However, the current
implementation only adds it to the compiler's resource directory. This
patch adds support for appending the `-rpath` to the compiler's standard
library directory as well. Currently this is `/../lib/`.

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4478865313636d..6b1fbba7abd031 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1142,7 +1142,11 @@ void tools::addArchSpecificRPath(const ToolChain &TC, 
const ArgList &Args,
 options::OPT_fno_rtlib_add_rpath, false))
 return;
 
-  for (const auto &CandidateRPath : TC.getArchSpecificLibPaths()) {
+  SmallVector CandidateRPaths(TC.getArchSpecificLibPaths());
+  if (const auto CandidateRPath = TC.getStdlibPath())
+CandidateRPaths.emplace_back(*CandidateRPath);
+
+  for (const auto &CandidateRPath : CandidateRPaths) {
 if (TC.getVFS().exists(CandidateRPath)) {
   CmdArgs.push_back("-rpath");
   CmdArgs.push_back(Args.MakeArgString(CandidateRPath));



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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-22 Thread zhijian lin via cfe-commits

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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-22 Thread zhijian lin via cfe-commits


@@ -337,12 +347,58 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(uint64_t &TypeSize) const {
+  llvm::Type *ElemTy;
+  unsigned RegsNeeded; // Registers Needed for Complex.
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+RegsNeeded = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+RegsNeeded = (TypeSize + 31) / 32;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int &ArgGPRsLeft) const {
+  assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  ASTContext &Context = getContext();
+
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (IsComplexInRegABI && Ty->isAnyComplexType() &&
+  TypeSize <= RegLen * ArgGPRsLeft) {
+assert(Ty->isAnyComplexType() && "Ty must be Complex type.");
+ArgGPRsLeft -= TypeSize / RegLen;
+return handleComplex(TypeSize);
+  }
+
+  if (ArgGPRsLeft) {
+// Records with non-trivial destructors/copy-constructors should not be
+// passed by value.
+if (isAggregateTypeForABI(Ty))
+  ArgGPRsLeft -= 1;
+else if (!Ty->isFloatingType()) {
+  // For other premitive types.
+  if (TypeSize > RegLen && TypeSize <= 2 * RegLen)
+ArgGPRsLeft -= TypeSize / RegLen;

diggerlin wrote:

for a test case `foo6(_Complex long double foo4(int x1, long  long y1, int x2, 
_Complex double z,)`
 
 `int x1` will have r3, 
`long long y1` will have r5,r6 (skip r4 since it is even, for 64bit integer 
need to start start odd register.)
`int x2` will have r7, 
` _Complex double z`  need to occupy 4 registers, there is no enough register , 
it can not pass `_Complex double z` in r8,r9,r10 , you have to pass ` _Complex 
double z` in by pointer (you can not call `handleComplex()`). 

but in your code, 
ArgGPRsLeft is 7 after int x1,
ArgGPRsLeft is 5 after long long y1
ArgGPRsLeft is 4 after int x2

there is still have 4 registers left for ` _Complex double z`, you can call 
`handleComplex()`,  you will pass ` _Complex double z` by value 

can you check how gcc deal with this case   `foo6(_Complex long double foo4(int 
x1, long  long y1, int x2, _Complex double z,)`  ?

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


[clang] [Clang] Make '-frtlib-add-rpath' include the standard library directory (PR #86217)

2024-03-22 Thread Joseph Huber via cfe-commits

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


[clang] [cfi][CodeGen] Call SetLLVMFunctionAttributes{, ForDefinition} on __cf… (PR #78253)

2024-03-22 Thread Aaron Ballman via cfe-commits

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

LGTM, do you need someone to land this on your behalf?

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


[clang] Split -Wcast-function-type into a separate group (PR #86131)

2024-03-22 Thread Abhin P Jose via cfe-commits

Abhinkop wrote:

Yes. I have done that. The tests failed because zlib was not enabled. Running 
them with a rebuild after force-enabling zlib now. Will keep you updated on the 
results.

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


[clang] 04a6e0f - [X86][Headers] change 'yields' to 'returns' in more places

2024-03-22 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2024-03-22T05:36:41-07:00
New Revision: 04a6e0f1634f9a53120c27a30250d26dff4ada1c

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

LOG: [X86][Headers] change 'yields' to 'returns' in more places

Added: 


Modified: 
clang/lib/Headers/mmintrin.h
clang/lib/Headers/smmintrin.h
clang/lib/Headers/xmmintrin.h

Removed: 




diff  --git a/clang/lib/Headers/mmintrin.h b/clang/lib/Headers/mmintrin.h
index 962d24738e7aa4..4e154e2d859353 100644
--- a/clang/lib/Headers/mmintrin.h
+++ b/clang/lib/Headers/mmintrin.h
@@ -1141,7 +1141,7 @@ _mm_xor_si64(__m64 __m1, __m64 __m2)
 ///[8 x i8] to determine if the element of the first vector is equal to the
 ///corresponding element of the second vector.
 ///
-///The comparison yields 0 for false, 0xFF for true.
+///Each comparison returns 0 for false, 0xFF for true.
 ///
 /// \headerfile 
 ///
@@ -1163,7 +1163,7 @@ _mm_cmpeq_pi8(__m64 __m1, __m64 __m2)
 ///[4 x i16] to determine if the element of the first vector is equal to 
the
 ///corresponding element of the second vector.
 ///
-///The comparison yields 0 for false, 0x for true.
+///Each comparison returns 0 for false, 0x for true.
 ///
 /// \headerfile 
 ///
@@ -1185,7 +1185,7 @@ _mm_cmpeq_pi16(__m64 __m1, __m64 __m2)
 ///[2 x i32] to determine if the element of the first vector is equal to 
the
 ///corresponding element of the second vector.
 ///
-///The comparison yields 0 for false, 0x for true.
+///Each comparison returns 0 for false, 0x for true.
 ///
 /// \headerfile 
 ///
@@ -1207,7 +1207,7 @@ _mm_cmpeq_pi32(__m64 __m1, __m64 __m2)
 ///[8 x i8] to determine if the element of the first vector is greater than
 ///the corresponding element of the second vector.
 ///
-///The comparison yields 0 for false, 0xFF for true.
+///Each comparison returns 0 for false, 0xFF for true.
 ///
 /// \headerfile 
 ///
@@ -1229,7 +1229,7 @@ _mm_cmpgt_pi8(__m64 __m1, __m64 __m2)
 ///[4 x i16] to determine if the element of the first vector is greater 
than
 ///the corresponding element of the second vector.
 ///
-///The comparison yields 0 for false, 0x for true.
+///Each comparison returns 0 for false, 0x for true.
 ///
 /// \headerfile 
 ///
@@ -1251,7 +1251,7 @@ _mm_cmpgt_pi16(__m64 __m1, __m64 __m2)
 ///[2 x i32] to determine if the element of the first vector is greater 
than
 ///the corresponding element of the second vector.
 ///
-///The comparison yields 0 for false, 0x for true.
+///Each comparison returns 0 for false, 0x for true.
 ///
 /// \headerfile 
 ///

diff  --git a/clang/lib/Headers/smmintrin.h b/clang/lib/Headers/smmintrin.h
index 9fb9cc9b01348c..b3fec474e35a1e 100644
--- a/clang/lib/Headers/smmintrin.h
+++ b/clang/lib/Headers/smmintrin.h
@@ -1188,7 +1188,7 @@ static __inline__ int __DEFAULT_FN_ATTRS 
_mm_testnzc_si128(__m128i __M,
 /// Compares each of the corresponding 64-bit values of the 128-bit
 ///integer vectors for equality.
 ///
-///Each comparison yields 0x0 for false, 0x for true.
+///Each comparison returns 0x0 for false, 0x for true.
 ///
 /// \headerfile 
 ///
@@ -2303,7 +2303,7 @@ static __inline__ __m128i __DEFAULT_FN_ATTRS 
_mm_minpos_epu16(__m128i __V) {
 ///integer vectors to determine if the values in the first operand are
 ///greater than those in the second operand.
 ///
-///Each comparison yields 0x0 for false, 0x for true.
+///Each comparison returns 0x0 for false, 0x for true.
 ///
 /// \headerfile 
 ///

diff  --git a/clang/lib/Headers/xmmintrin.h b/clang/lib/Headers/xmmintrin.h
index 040194786a2799..1ef89de9c9f562 100644
--- a/clang/lib/Headers/xmmintrin.h
+++ b/clang/lib/Headers/xmmintrin.h
@@ -484,7 +484,7 @@ _mm_xor_ps(__m128 __a, __m128 __b)
 /// Compares two 32-bit float values in the low-order bits of both
 ///operands for equality.
 ///
-///The comparison yields 0x0 for false, 0x for true, in the
+///The comparison returns 0x0 for false, 0x for true, in the
 ///low-order bits of a vector [4 x float].
 ///If either value in a comparison is NaN, returns false.
 ///
@@ -509,7 +509,7 @@ _mm_cmpeq_ss(__m128 __a, __m128 __b)
 /// Compares each of the corresponding 32-bit float values of the
 ///128-bit vectors of [4 x float] for equality.
 ///
-///Each comparison yields 0x0 for false, 0x for true.
+///Each comparison returns 0x0 for false, 0x for true.
 ///If either value in a comparison is NaN, returns false.
 ///
 /// \headerfile 
@@ -531,7 +531,7 @@ _mm_cmpeq_ps(__m128 __a, __m128 __b)
 ///operands to determine if the va

[clang] [libcxx] [libc++] Implement LWG3528 (`make_from_tuple` can perform (the equivalent of) a C-style cast) (PR #85263)

2024-03-22 Thread via cfe-commits

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


[clang] [HIP][NFC] Refactor managed var codegen (PR #85976)

2024-03-22 Thread Yaxun Liu via cfe-commits


@@ -1160,9 +1152,8 @@ void CGNVCUDARuntime::createOffloadingEntries() {
 
 // Returns module constructor to be added.
 llvm::Function *CGNVCUDARuntime::finalizeModule() {
+  transformManagedVars();

yxsamliu wrote:

we did the equivalent transformation previously during registration of managed 
var by calling replaceManagedVar directly, so it is actually NFC. We have lit 
test 
https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/managed-var.cu
 that covers transformation in both device and host code.

We also have execution tests in hip-tests 
https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenCUDA/managed-var.cu


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


[clang] [HIP][NFC] Refactor managed var codegen (PR #85976)

2024-03-22 Thread Yaxun Liu via cfe-commits

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


[clang] [HIP][NFC] Refactor managed var codegen (PR #85976)

2024-03-22 Thread Yaxun Liu via cfe-commits


@@ -1160,9 +1152,8 @@ void CGNVCUDARuntime::createOffloadingEntries() {
 
 // Returns module constructor to be added.
 llvm::Function *CGNVCUDARuntime::finalizeModule() {
+  transformManagedVars();

yxsamliu wrote:

we do not have test for managed var in llvm-test-suite

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


[clang] 3b3de48 - [BOLT] Add BB index to BAT (#86044)

2024-03-22 Thread via cfe-commits

Author: Amir Ayupov
Date: 2024-03-22T06:07:17-07:00
New Revision: 3b3de48fd84b8269d5f45ee0a9dc6b7448368424

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

LOG: [BOLT] Add BB index to BAT (#86044)

Added: 


Modified: 
bolt/docs/BAT.md
bolt/include/bolt/Profile/BoltAddressTranslation.h
bolt/lib/Profile/BoltAddressTranslation.cpp
bolt/test/X86/bolt-address-translation-yaml.test
bolt/test/X86/bolt-address-translation.test
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/unsupported-option-gpu.c
lld/MachO/Driver.cpp
lld/MachO/InputSection.cpp
lld/MachO/InputSection.h
lld/MachO/ObjC.cpp
lld/MachO/SyntheticSections.cpp

Removed: 




diff  --git a/bolt/docs/BAT.md b/bolt/docs/BAT.md
index 186b0e5ea89d38..436593478a398e 100644
--- a/bolt/docs/BAT.md
+++ b/bolt/docs/BAT.md
@@ -90,11 +90,12 @@ current function.
 ### Address translation table
 Delta encoding means that only the 
diff erence with the previous corresponding
 entry is encoded. Input offsets implicitly start at zero.
-| Entry  | Encoding | Description |
-| -- | --| --- |
-| `OutputOffset` | Continuous, Delta, ULEB128 | Function offset in output 
binary |
-| `InputOffset` | Optional, Delta, SLEB128 | Function offset in input binary 
with `BRANCHENTRY` LSB bit |
-| `BBHash` | Optional, 8b | Basic block entries only: basic block hash in 
input binary |
+| Entry  | Encoding | Description | Branch/BB |
+| -- | --| --- | -- |
+| `OutputOffset` | Continuous, Delta, ULEB128 | Function offset in output 
binary | Both |
+| `InputOffset` | Optional, Delta, SLEB128 | Function offset in input binary 
with `BRANCHENTRY` LSB bit | Both |
+| `BBHash` | Optional, 8b | Basic block hash in input binary | BB |
+| `BBIdx`  | Optional, Delta, ULEB128 | Basic block index in input binary | BB 
|
 
 `BRANCHENTRY` bit denotes whether a given offset pair is a control flow source
 (branch or call instruction). If not set, it signifies a control flow target

diff  --git a/bolt/include/bolt/Profile/BoltAddressTranslation.h 
b/bolt/include/bolt/Profile/BoltAddressTranslation.h
index 1f53f6d344ad74..eda2b318f0d0a3 100644
--- a/bolt/include/bolt/Profile/BoltAddressTranslation.h
+++ b/bolt/include/bolt/Profile/BoltAddressTranslation.h
@@ -122,6 +122,10 @@ class BoltAddressTranslation {
   /// Returns BF hash by function output address (after BOLT).
   size_t getBFHash(uint64_t OutputAddress) const;
 
+  /// Returns BB index by function output address (after BOLT) and basic block
+  /// input offset.
+  unsigned getBBIndex(uint64_t FuncOutputAddress, uint32_t BBInputOffset) 
const;
+
   /// True if a given \p Address is a function with translation table entry.
   bool isBATFunction(uint64_t Address) const { return Maps.count(Address); }
 
@@ -154,7 +158,8 @@ class BoltAddressTranslation {
 
   std::map Maps;
 
-  using BBHashMap = std::unordered_map;
+  /// Map basic block input offset to a basic block index and hash pair.
+  using BBHashMap = std::unordered_map>;
   std::unordered_map> FuncHashes;
 
   /// Links outlined cold bocks to their original function

diff  --git a/bolt/lib/Profile/BoltAddressTranslation.cpp 
b/bolt/lib/Profile/BoltAddressTranslation.cpp
index 1d61a1b735b403..8fe976cc00e53c 100644
--- a/bolt/lib/Profile/BoltAddressTranslation.cpp
+++ b/bolt/lib/Profile/BoltAddressTranslation.cpp
@@ -45,6 +45,8 @@ void BoltAddressTranslation::writeEntriesForBB(MapTy &Map,
   LLVM_DEBUG(dbgs() << formatv(" Hash: {0:x}\n",
getBBHash(HotFuncAddress, BBInputOffset)));
   (void)HotFuncAddress;
+  LLVM_DEBUG(dbgs() << formatv(" Index: {0}\n",
+   getBBIndex(HotFuncAddress, BBInputOffset)));
   // In case of conflicts (same Key mapping to 
diff erent Vals), the last
   // update takes precedence. Of course it is not ideal to have conflicts and
   // those happen when we have an empty BB that either contained only
@@ -217,6 +219,7 @@ void BoltAddressTranslation::writeMaps(std::map &Maps,
 }
 size_t Index = 0;
 uint64_t InOffset = 0;
+size_t PrevBBIndex = 0;
 // Output and Input addresses and delta-encoded
 for (std::pair &KeyVal : Map) {
   const uint64_t OutputAddress = KeyVal.first + Address;
@@ -226,11 +229,15 @@ void BoltAddressTranslation::writeMaps(std::map &Maps,
 encodeSLEB128(KeyVal.second - InOffset, OS);
   InOffset = KeyVal.second; // Keeping InOffset as if BRANCHENTRY is 
encoded
   if ((InOffset & BRANCHENTRY) == 0) {
-// Basic block hash
-size_t BBHash = FuncHashPair.second[InOffset >> 1];
+unsigned BBIndex;
+size_t BBHash;
+std::tie(BBIndex, BBHash) = FuncHashPair.second[InOffset >> 1];
 OS.write(reinterpre

[clang] [HIP][NFC] Refactor managed var codegen (PR #85976)

2024-03-22 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/85976

>From 1d14bcff6363b34ae48eac2bf68221b16dd1c855 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Wed, 20 Mar 2024 13:34:29 -0400
Subject: [PATCH] [HIP][NFC] Refactor managed var codegen

Refactor managed variable handling in codegen so that
the transformation is done separately from registration.

This will allow the new driver to register the managed
var in the linker wrapper.
---
 clang/lib/CodeGen/CGCUDANV.cpp | 27 +--
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index d3f2573fd5e38a..b756318c46a900 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -605,20 +605,10 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
   uint64_t VarSize =
   CGM.getDataLayout().getTypeAllocSize(Var->getValueType());
   if (Info.Flags.isManaged()) {
-auto *ManagedVar = new llvm::GlobalVariable(
-CGM.getModule(), Var->getType(),
-/*isConstant=*/false, Var->getLinkage(),
-/*Init=*/Var->isDeclaration()
-? nullptr
-: llvm::ConstantPointerNull::get(Var->getType()),
-/*Name=*/"", /*InsertBefore=*/nullptr,
-llvm::GlobalVariable::NotThreadLocal);
-ManagedVar->setDSOLocal(Var->isDSOLocal());
-ManagedVar->setVisibility(Var->getVisibility());
-ManagedVar->setExternallyInitialized(true);
-ManagedVar->takeName(Var);
-Var->setName(Twine(ManagedVar->getName() + ".managed"));
-replaceManagedVar(Var, ManagedVar);
+assert(Var->getName().ends_with(".managed") &&
+   "HIP managed variables not transformed");
+auto *ManagedVar = CGM.getModule().getNamedGlobal(
+Var->getName().drop_back(StringRef(".managed").size()));
 llvm::Value *Args[] = {
 &GpuBinaryHandlePtr,
 ManagedVar,
@@ -1093,7 +1083,9 @@ void CGNVCUDARuntime::transformManagedVars() {
   : llvm::ConstantPointerNull::get(Var->getType()),
   /*Name=*/"", /*InsertBefore=*/nullptr,
   llvm::GlobalVariable::NotThreadLocal,
-  CGM.getContext().getTargetAddressSpace(LangAS::cuda_device));
+  CGM.getContext().getTargetAddressSpace(CGM.getLangOpts().CUDAIsDevice
+ ? LangAS::cuda_device
+ : LangAS::Default));
   ManagedVar->setDSOLocal(Var->isDSOLocal());
   ManagedVar->setVisibility(Var->getVisibility());
   ManagedVar->setExternallyInitialized(true);
@@ -1102,7 +1094,7 @@ void CGNVCUDARuntime::transformManagedVars() {
   Var->setName(Twine(ManagedVar->getName()) + ".managed");
   // Keep managed variables even if they are not used in device code since
   // they need to be allocated by the runtime.
-  if (!Var->isDeclaration()) {
+  if (CGM.getLangOpts().CUDAIsDevice && !Var->isDeclaration()) {
 assert(!ManagedVar->isDeclaration());
 CGM.addCompilerUsedGlobal(Var);
 CGM.addCompilerUsedGlobal(ManagedVar);
@@ -1160,9 +1152,8 @@ void CGNVCUDARuntime::createOffloadingEntries() {
 
 // Returns module constructor to be added.
 llvm::Function *CGNVCUDARuntime::finalizeModule() {
+  transformManagedVars();
   if (CGM.getLangOpts().CUDAIsDevice) {
-transformManagedVars();
-
 // Mark ODR-used device variables as compiler used to prevent it from being
 // eliminated by optimization. This is necessary for device variables
 // ODR-used by host functions. Sema correctly marks them as ODR-used no

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


[clang] Split -Wcast-function-type into a separate group (PR #86131)

2024-03-22 Thread Amy Kwan via cfe-commits

amy-kwan wrote:

I have also found one more that is not related to the sanitizers, but when 
`llvm-project/llvm/lib/IR/Core.cpp`: 
https://lab.llvm.org/buildbot/#/builders/36/builds/43840/steps/12/logs/stdio

Would it be possible to also resolve this one, as well?


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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits


@@ -2515,6 +2517,53 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  SVal MaxLength = SVB.makeIntVal(256, C.getASTContext().IntTy);
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+  assumeZero(C, State, SizeVal, SizeTy);
+
+  if (StateZeroSize) {
+StateZeroSize = State->BindExpr(Call.getOriginExpr(), 
C.getLocationContext(),

NagyDonat wrote:

```suggestion
StateZeroSize = StateZeroSize->BindExpr(Call.getOriginExpr(), 
C.getLocationContext(),
```
For the sake of consistency always avoid using "stale" state values, because 
this leads to loss of information and inconsistencies.

The only situation where this is not important is the case when you perform a 
dual assumption (an assume call that returns two state references, e.g. the 
`assumeZero` above this) _and_ you checked that one of the two state references 
is NULL. In that case the other returned state reference will be practically 
equivalent to the state before the assumption (but even then there are some 
little arcane details that may differ). 

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits


@@ -2515,6 +2517,53 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  SVal MaxLength = SVB.makeIntVal(256, C.getASTContext().IntTy);
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+  assumeZero(C, State, SizeVal, SizeTy);
+
+  if (StateZeroSize) {
+StateZeroSize = State->BindExpr(Call.getOriginExpr(), 
C.getLocationContext(),
+  SVB.makeZeroVal(C.getASTContext().IntTy));
+C.addTransition(StateZeroSize);
+return;
+  }
+
+  SVal Buff = C.getSVal(Buffer.Expression);
+  State = checkNonNull(C, StateNonZeroSize, Buffer, Buff);
+  if (!State)
+return;
+
+  QualType cmpTy = C.getSValBuilder().getConditionType();
+  ProgramStateRef sizeAboveLimit, sizeNotAboveLimit;
+  std::tie(sizeAboveLimit, sizeNotAboveLimit) = State->assume(
+SVB
+   .evalBinOpNN(State, BO_GT, *SizeVal.getAs(), 
*MaxLength.getAs(), cmpTy)

NagyDonat wrote:

Declare `SizeVal` and `MaxLength` as `NonLoc` instead of doing this immediately 
dereferenced `getAs()`. In the case of `SizeVal` you should do an early return 
in the unlikely case when the value is not a `NonLoc`.

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits


@@ -2515,6 +2517,53 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  SVal MaxLength = SVB.makeIntVal(256, C.getASTContext().IntTy);
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+  assumeZero(C, State, SizeVal, SizeTy);
+
+  if (StateZeroSize) {
+StateZeroSize = State->BindExpr(Call.getOriginExpr(), 
C.getLocationContext(),
+  SVB.makeZeroVal(C.getASTContext().IntTy));
+C.addTransition(StateZeroSize);
+return;
+  }
+
+  SVal Buff = C.getSVal(Buffer.Expression);
+  State = checkNonNull(C, StateNonZeroSize, Buffer, Buff);
+  if (!State)
+return;
+
+  QualType cmpTy = C.getSValBuilder().getConditionType();
+  ProgramStateRef sizeAboveLimit, sizeNotAboveLimit;
+  std::tie(sizeAboveLimit, sizeNotAboveLimit) = State->assume(
+SVB
+   .evalBinOpNN(State, BO_GT, *SizeVal.getAs(), 
*MaxLength.getAs(), cmpTy)
+   .castAs());
+  if (sizeAboveLimit) {
+ErrorMessage Message;
+emitOutOfBoundsBug(C, sizeAboveLimit, Buffer.Expression, "must be smaller 
than or equal to 256");
+  } else {
+State = CheckBufferAccess(C, State, Buffer, Size, AccessKind::write);

NagyDonat wrote:

```suggestion
State = CheckBufferAccess(C, sizeNotAboveLimit, Buffer, Size, 
AccessKind::write);
```
As I said before, try to use the most recent state value.

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits


@@ -2515,6 +2517,53 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  SVal MaxLength = SVB.makeIntVal(256, C.getASTContext().IntTy);
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =

NagyDonat wrote:

```suggestion
  auto [StateZeroSize, StateNonZeroSize] =
```
We have C++17, we can use structured bindings instead of `std::tie`.

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits


@@ -2515,6 +2517,53 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  SVal MaxLength = SVB.makeIntVal(256, C.getASTContext().IntTy);
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+  assumeZero(C, State, SizeVal, SizeTy);
+
+  if (StateZeroSize) {
+StateZeroSize = State->BindExpr(Call.getOriginExpr(), 
C.getLocationContext(),
+  SVB.makeZeroVal(C.getASTContext().IntTy));
+C.addTransition(StateZeroSize);
+return;
+  }
+
+  SVal Buff = C.getSVal(Buffer.Expression);
+  State = checkNonNull(C, StateNonZeroSize, Buffer, Buff);
+  if (!State)
+return;
+
+  QualType cmpTy = C.getSValBuilder().getConditionType();
+  ProgramStateRef sizeAboveLimit, sizeNotAboveLimit;
+  std::tie(sizeAboveLimit, sizeNotAboveLimit) = State->assume(
+SVB
+   .evalBinOpNN(State, BO_GT, *SizeVal.getAs(), 
*MaxLength.getAs(), cmpTy)
+   .castAs());
+  if (sizeAboveLimit) {
+ErrorMessage Message;
+emitOutOfBoundsBug(C, sizeAboveLimit, Buffer.Expression, "must be smaller 
than or equal to 256");
+  } else {
+State = CheckBufferAccess(C, State, Buffer, Size, AccessKind::write);
+if (!State)
+  return;
+
+State = invalidateDestinationBufferBySize(C, State, Buffer.Expression,
+Buff,
+SizeVal, SizeTy);
+C.addTransition(State);

NagyDonat wrote:

According to the man page, the return value of this function is either 0 
(success) or -1 (failure), so you should probably bind a conjured symbolic 
value to the call expression and assume that it's in the range [-1, 0].

Moreover, it would be good to handle the success and failure as separate 
branches (modeling the fact that e.g. `errno` is set on a failure), but that 
could be left for a follow-up commit.

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits


@@ -2516,6 +2518,47 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C,
+const CallEvent &Call) const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  constexpr int BufferMaxSize = 256;
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+  assumeZero(C, State, SizeVal, SizeTy);

NagyDonat wrote:

Yes, if the current code encounters a situation when the size may be zero _and_ 
may be nonzero (so `assumeZero` splits the state and returns two non-null state 
references), then it will act as if the size argument was _known to be_ zero 
and transitions to a state where the return value is _known to be_ zero.

You need to explicitly handle this ambiguous case somehow:
(1) either you do a state split and create two separate transitions to the two 
possible branches (and create note tags that e.g. say "assuming the 'size' 
argument is zero" on the branch where you assume that)
(2) or, alternatively, you keep a single transition and try to ensure that the 
potentially affected values are marked as unknown (e.g. don't bind a value to 
the call expression and probably you should invalidate the buffer contents).

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits


@@ -2515,6 +2517,53 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  SVal MaxLength = SVB.makeIntVal(256, C.getASTContext().IntTy);
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+  assumeZero(C, State, SizeVal, SizeTy);
+
+  if (StateZeroSize) {
+StateZeroSize = State->BindExpr(Call.getOriginExpr(), 
C.getLocationContext(),
+  SVB.makeZeroVal(C.getASTContext().IntTy));
+C.addTransition(StateZeroSize);
+return;
+  }
+
+  SVal Buff = C.getSVal(Buffer.Expression);
+  State = checkNonNull(C, StateNonZeroSize, Buffer, Buff);
+  if (!State)
+return;
+
+  QualType cmpTy = C.getSValBuilder().getConditionType();
+  ProgramStateRef sizeAboveLimit, sizeNotAboveLimit;
+  std::tie(sizeAboveLimit, sizeNotAboveLimit) = State->assume(

NagyDonat wrote:

```suggestion
  auto [sizeAboveLimit, sizeNotAboveLimit] = State->assume(
```

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits


@@ -529,3 +529,37 @@ void nocrash_on_locint_offset(void *addr, void* from, 
struct S s) {
   size_t iAdd = (size_t) addr;
   memcpy(((void *) &(s.f)), from, iAdd);
 }
+
+//===--===//
+// getentropy()
+//===--===//
+
+int getentropy(void *d, size_t n);
+
+int getentropy0(void) {
+  char buf[16] = {0};
+
+  int r = getentropy(buf, sizeof(buf)); // no-warning
+  return r;
+}
+
+int getentropy1(void) {
+  char buf[257] = {0};
+
+  int r = getentropy(buf, 256); // no-warning
+  return r;
+}
+
+int getentropy2(void) {
+  char buf[1024] = {0};
+
+  int r = getentropy(buf, sizeof(buf)); // expected-warning{{must be smaller 
than or equal to 256}}
+  return r;
+}
+
+int getentropy3(void) {
+  char buf[256] = {0};
+
+  int r = getentropy(buf, 0); // no-wwarning

NagyDonat wrote:

```suggestion
  int r = getentropy(buf, 0); // no-warning
```
Just a typo. (By the way, "no-warning" is just a comment, it's not significant 
for the test engine. The tests will fail if when any unexpected warning 
appears, but it's customary to write no-warning after the statements that are 
the "central" parts of a testcase but should not produce a warning.)

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits


@@ -529,3 +529,37 @@ void nocrash_on_locint_offset(void *addr, void* from, 
struct S s) {
   size_t iAdd = (size_t) addr;
   memcpy(((void *) &(s.f)), from, iAdd);
 }
+
+//===--===//
+// getentropy()
+//===--===//
+
+int getentropy(void *d, size_t n);
+
+int getentropy0(void) {
+  char buf[16] = {0};
+
+  int r = getentropy(buf, sizeof(buf)); // no-warning
+  return r;
+}
+
+int getentropy1(void) {
+  char buf[257] = {0};
+
+  int r = getentropy(buf, 256); // no-warning
+  return r;
+}
+
+int getentropy2(void) {
+  char buf[1024] = {0};
+
+  int r = getentropy(buf, sizeof(buf)); // expected-warning{{must be smaller 
than or equal to 256}}
+  return r;
+}
+
+int getentropy3(void) {
+  char buf[256] = {0};
+
+  int r = getentropy(buf, 0); // no-wwarning
+  return r;
+}

NagyDonat wrote:

Add testcases like

```
int getentropy4(size_t arg) {
  char buf[257] = {0};

  int r = getentropy(buf, arg); // no-warning
  return r;
}

void do_something();
int getentropy5(size_t arg) {
  char buf[257] = {0};

  // split the state and introduce a separate execution path where arg > 256
  if (arg <= 256)
do_something();

  int r = getentropy(buf, arg); // expected-warning{{must be smaller than or 
equal to 256}}
  return r;
}
```

and also create a few testcases where `getentropy` fails because the buffer is 
a nullpointer or the specified size is larger than the buffer size.

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


[clang] [HIP][NFC] Refactor managed var codegen (PR #85976)

2024-03-22 Thread Joseph Huber via cfe-commits

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


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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits


@@ -2515,6 +2517,53 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  SVal MaxLength = SVB.makeIntVal(256, C.getASTContext().IntTy);
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+  assumeZero(C, State, SizeVal, SizeTy);
+
+  if (StateZeroSize) {
+StateZeroSize = State->BindExpr(Call.getOriginExpr(), 
C.getLocationContext(),
+  SVB.makeZeroVal(C.getASTContext().IntTy));
+C.addTransition(StateZeroSize);
+return;
+  }
+
+  SVal Buff = C.getSVal(Buffer.Expression);
+  State = checkNonNull(C, StateNonZeroSize, Buffer, Buff);
+  if (!State)
+return;
+
+  QualType cmpTy = C.getSValBuilder().getConditionType();
+  ProgramStateRef sizeAboveLimit, sizeNotAboveLimit;
+  std::tie(sizeAboveLimit, sizeNotAboveLimit) = State->assume(
+SVB
+   .evalBinOpNN(State, BO_GT, *SizeVal.getAs(), 
*MaxLength.getAs(), cmpTy)
+   .castAs());
+  if (sizeAboveLimit) {
+ErrorMessage Message;

NagyDonat wrote:

```suggestion
```
This seems to be unused.

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits


@@ -2515,6 +2517,53 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  SVal MaxLength = SVB.makeIntVal(256, C.getASTContext().IntTy);
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+  assumeZero(C, State, SizeVal, SizeTy);
+
+  if (StateZeroSize) {
+StateZeroSize = State->BindExpr(Call.getOriginExpr(), 
C.getLocationContext(),
+  SVB.makeZeroVal(C.getASTContext().IntTy));
+C.addTransition(StateZeroSize);
+return;
+  }
+
+  SVal Buff = C.getSVal(Buffer.Expression);
+  State = checkNonNull(C, StateNonZeroSize, Buffer, Buff);
+  if (!State)
+return;
+
+  QualType cmpTy = C.getSValBuilder().getConditionType();
+  ProgramStateRef sizeAboveLimit, sizeNotAboveLimit;
+  std::tie(sizeAboveLimit, sizeNotAboveLimit) = State->assume(
+SVB
+   .evalBinOpNN(State, BO_GT, *SizeVal.getAs(), 
*MaxLength.getAs(), cmpTy)
+   .castAs());
+  if (sizeAboveLimit) {

NagyDonat wrote:

```suggestion
  if (sizeAboveLimit && !sizeNotAboveLimit) {
```
In ambiguous situations (when both situations may be possible) the checkers 
must be lenient -- they should report errors only when they're certain that the 
error will happen. (Otherwise we'd get an overwhelming amount of false 
positives from the code parts where the analyzer doesn't know the values of the 
variables.)

The only exception is that if a value is marked as "tainted" (attacker 
controlled, see the GenericTaint checker which can mark values as tainted), 
then we assume the worst about it (if the situation is ambiguous and a tainted 
variable is involved, then we report an error). Some checkers are "taint aware" 
and incorporate this check into their logic, but it's perfectly fine if a 
checker is not (yet) taint aware, so you shouldn't bother with this (in this 
commit).

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits

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

I'll try to take over this review process and help with finalizing this commit. 
I also added @balazske who's also familiar with this area.

Unfortunately currently there are significant problems in the state/assumption 
manipulation logic: it looks as if you thought that functions like `assumeZero` 
and `assume` always returned one nullpointer and one non-null state ref (in 
either order) -- while they have a third possibility where both returned 
references are non-null.

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-22 Thread via cfe-commits

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


[clang] Split -Wcast-function-type into a separate group (PR #86131)

2024-03-22 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Oof, that one is a bit messier to resolve -- it's mixing unrelated reference 
and pointer types and hoping the casts correctly convert back and forth 
properly. The fix to that should probably be done separately from the sanitizer 
fix so we get reasonable code review from LLVM folks.

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


[clang] Split -Wcast-function-type into a separate group (PR #86131)

2024-03-22 Thread Abhin P Jose via cfe-commits

Abhinkop wrote:

Yes, I will create a separate patch. I'm not sure it would be able to do it in 
this patch. I am halfway through verifying the fix in this patch.

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


[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-03-22 Thread via cfe-commits

wheatman wrote:

I made the changes, added the tests, and fixed some things that the tests found.

A few questions.
It seems like n3030 is only partially supported, specifically 
```
extern enum forward fwd_val0; /* Constraint violation: incomplete type */
extern enum forward* fwd_ptr0; /* Constraint violation: enums cannot be
  used like other incomplete types */
```
However, these seem unrelated to the rest of the changes and I am not really 
sure how to begin with them so I just labeled the support as partial for now.

Also, I did not touch anything on the msvc side due to this comment
```
  // For MSVC ABI compatibility, unfixed enums must use an underlying type
  // of 'int'. However, if this is an unfixed forward declaration, don't set
  // the underlying type unless the user enables -fms-compatibility. This
  // makes unfixed forward declared enums incomplete and is more conforming.
```
It seems like they don't support these features yet and I figured breaking 
matched behavior was not desirable.
How do I set up the tests to not run on the msvc side?

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


[libunwind] [libunwind] Tweak tests for musl support. (PR #85097)

2024-03-22 Thread Alastair Houghton via cfe-commits


@@ -11,20 +11,27 @@
 
 // Basic test for float registers number are accepted.
 
-#include 
 #include 
 #include 
 #include 
 
+// Using __attribute__((section("main_func"))) is Linux specific, but then

al45tair wrote:

Fair point.

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


[clang] [analyzer] Set and display CSA analysis entry points as notes on debugging (PR #84823)

2024-03-22 Thread via cfe-commits

NagyDonat wrote:

> Did you envision [debug] XYZ, and XYZ [-analyzer-note-analysis-entry-points]?
Which should I pursue?

I slightly prefer [debug] because this mode can be activated by two different 
flags, but mentioning the flag is also fine.

(Sorry for not answering earlier, I didn't have a strong preference.)

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


[clang] [clang][AArch64] Enable fp128 for aarch64 linux target (PR #85070)

2024-03-22 Thread Matthew Devereau via cfe-commits

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-22 Thread Aaron Ballman via cfe-commits


@@ -12465,6 +12465,20 @@ isArithmeticArgumentPromotion(Sema &S, const 
ImplicitCastExpr *ICE) {
  S.Context.getFloatingTypeOrder(From, To) < 0;
 }
 
+static analyze_format_string::ArgType::MatchKind
+handleFormatSignedness(analyze_format_string::ArgType::MatchKind Match,
+   DiagnosticsEngine &Diags, SourceLocation Loc) {
+  if (Match == analyze_format_string::ArgType::NoMatchSignedness) {
+if (!Diags.isIgnored(
+diag::warn_format_conversion_argument_type_mismatch_signedness,
+Loc))
+  Match = analyze_format_string::ArgType::NoMatch;
+else
+  Match = analyze_format_string::ArgType::Match;

AaronBallman wrote:

```suggestion
   Match = Diags.isIgnored(
diag::warn_format_conversion_argument_type_mismatch_signedness,
Loc) ? analyze_format_string::ArgType::Match : 
analyze_format_string::ArgType::NoMatch;
```
Probably need to be reformatted, but makes the code a little bit more clear 
(IMO).

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-22 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Can you also add a test showing the difference between `-Wformat 
-Wformat-signedness` and `-Wformat-signedness` by itself (which does nothing)? 
I'd also like to see a test demonstrating that `#pragma GCC diagnostic ignored 
-Wformat` disables the signedness warnings.

Otherwise, this generally LGTM!

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


[clang] [clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. (PR #86150)

2024-03-22 Thread Hirofumi Nakamura via cfe-commits

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


[clang] e54af60 - [clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. (#86150)

2024-03-22 Thread via cfe-commits

Author: Hirofumi Nakamura
Date: 2024-03-22T23:11:36+09:00
New Revision: e54af608160350baa7ae1b8069f916eb625beadd

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

LOG: [clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. 
(#86150)

The option to specify the style of alignment of the colons inside TableGen's 
DAGArg.

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/WhitespaceManager.cpp
clang/lib/Format/WhitespaceManager.h
clang/unittests/Format/FormatTestTableGen.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index be021dfc5c084c..2ee36f24d7ce4b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -955,6 +955,151 @@ the configuration (without a prefix: ``Auto``).
   }
 
 
+.. _AlignConsecutiveTableGenBreakingDAGArgColons:
+
+**AlignConsecutiveTableGenBreakingDAGArgColons** (``AlignConsecutiveStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ 
`
+  Style of aligning consecutive TableGen DAGArg operator colons.
+  If enabled, align the colon inside DAGArg which have line break inside.
+  This works only when TableGenBreakInsideDAGArg is BreakElements or
+  BreakAll and the DAGArg is not excepted by
+  TableGenBreakingDAGArgOperators's effect.
+
+  .. code-block:: c++
+
+let dagarg = (ins
+a  :$src1,
+aa :$src2,
+aaa:$src3
+)
+
+  Nested configuration flags:
+
+  Alignment options.
+
+  They can also be read as a whole for compatibility. The choices are:
+  - None
+  - Consecutive
+  - AcrossEmptyLines
+  - AcrossComments
+  - AcrossEmptyLinesAndComments
+
+  For example, to align across empty lines and not across comments, either
+  of these work.
+
+  .. code-block:: c++
+
+AlignConsecutiveTableGenBreakingDAGArgColons: AcrossEmptyLines
+
+AlignConsecutiveTableGenBreakingDAGArgColons:
+  Enabled: true
+  AcrossEmptyLines: true
+  AcrossComments: false
+
+  * ``bool Enabled`` Whether aligning is enabled.
+
+.. code-block:: c++
+
+  #define SHORT_NAME   42
+  #define LONGER_NAME  0x007f
+  #define EVEN_LONGER_NAME (2)
+  #define foo(x)   (x * x)
+  #define bar(y, z)(y + z)
+
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int  : 1;
+  int b: 12;
+  int ccc  : 8;
+
+  int  = 12;
+  float   b = 23;
+  std::string ccc;
+
+  * ``bool AcrossEmptyLines`` Whether to align across empty lines.
+
+.. code-block:: c++
+
+  true:
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int d= 3;
+
+  false:
+  int a= 1;
+  int somelongname = 2;
+  double c = 3;
+
+  int d = 3;
+
+  * ``bool AcrossComments`` Whether to align across comments.
+
+.. code-block:: c++
+
+  true:
+  int d= 3;
+  /* A comment. */
+  double e = 4;
+
+  false:
+  int d = 3;
+  /* A comment. */
+  double e = 4;
+
+  * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``.  Whether 
compound assignments
+like ``+=`` are aligned along with ``=``.
+
+.. code-block:: c++
+
+  true:
+  a   &= 2;
+  bbb  = 2;
+
+  false:
+  a &= 2;
+  bbb = 2;
+
+  * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. 
Whether function pointers are
+aligned.
+
+.. code-block:: c++
+
+  true:
+  unsigned i;
+  int &r;
+  int *p;
+  int  (*f)();
+
+  false:
+  unsigned i;
+  int &r;
+  int *p;
+  int (*f)();
+
+  * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``.  Whether 
short assignment
+operators are left-padded to the same length as long ones in order to
+put all assignment operators to the right of the left hand side.
+
+.. code-block:: c++
+
+  true:
+  a   >>= 2;
+  bbb   = 2;
+
+  a = 2;
+  bbb >>= 2;
+
+  false:
+  a >>= 2;
+  bbb = 2;
+
+  a = 2;
+  bbb >>= 2;
+
+
 .. _AlignConsecutiveTableGenCondOperatorColons:
 
 **AlignConsecutiveTableGenCondOperatorColons** (``AlignConsecutiveStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ 
`

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 7ad2579bf7773b..0720c8283cd75c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/

[clang] d231e3b - [C11] Add test & update status of N1282 and DR087

2024-03-22 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2024-03-22T10:17:50-04:00
New Revision: d231e3b10ead90e4360f7ceb88e4bca9d42d7d04

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

LOG: [C11] Add test & update status of N1282 and DR087

Our existing diagnostics for catching unsequenced modifications handles
test coverage for N1282, which is correcting the standard based on the
resolution of DR087.

Added: 
clang/test/C/C11/n1282.c

Modified: 
clang/test/C/drs/dr0xx.c
clang/www/c_dr_status.html
clang/www/c_status.html

Removed: 




diff  --git a/clang/test/C/C11/n1282.c b/clang/test/C/C11/n1282.c
new file mode 100644
index 00..ed952790c88333
--- /dev/null
+++ b/clang/test/C/C11/n1282.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -Wunsequenced -Wno-unused-value %s
+
+/* WG14 N1282: Yes
+ * Clarification of Expressions
+ */
+
+int g;
+
+int f(int i) {
+  g = i;
+  return 0;
+}
+
+int main(void) {
+  int x;
+  x = (10, g = 1, 20) + (30, g = 2, 40); /* Line A */ // expected-warning 
{{multiple unsequenced modifications to 'g'}}
+  x = (10, f(1), 20) + (30, f(2), 40); /* Line B */
+  x = (g = 1) + (g = 2); /* Line C */ // expected-warning 
{{multiple unsequenced modifications to 'g'}}
+  return 0;
+}

diff  --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index c93cfb63d604cf..36de32a93da95d 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -73,6 +73,10 @@
  * WG14 DR085: yes
  * Returning from main
  *
+ * WG14 DR087: yes
+ * Order of evaluation
+ * Note: this DR is covered by C/C11/n1282.c
+ *
  * WG14 DR086: yes
  * Object-like macros in system headers
  *

diff  --git a/clang/www/c_dr_status.html b/clang/www/c_dr_status.html
index fa2ceb1be58bdc..ed45123ffd0ecb 100644
--- a/clang/www/c_dr_status.html
+++ b/clang/www/c_dr_status.html
@@ -577,7 +577,7 @@ C defect report implementation status
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_087.html";>87
 NAD
 Order of evaluation
-Unknown
+Yes
   
   
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_088.html";>88

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index b1f5ab4cbc4f07..0069da74cbd56c 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -401,7 +401,7 @@ C11 implementation status
 
   Clarification of expressions
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1282.pdf";>N1282
-  Unknown
+  Yes
 
 
   Extending the lifetime of temporary objects (factored approach)



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


[clang] [clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. (PR #86150)

2024-03-22 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

@HazardyKnusperkeks 
Thank you very much!
It took about 4 month with ten or more PRs for the parts of the first concept 
of TableGen formatting. 
You reviewed every time and gave me many valuable suggestions. I appreciate you 
again and again!

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-03-22 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

All the split parts of this PR is merged. Thank you!

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2024-03-22 Thread Hirofumi Nakamura via cfe-commits

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2024-03-22 Thread Aaron Ballman via cfe-commits

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


[clang] Split -Wcast-function-type into a separate group (PR #86131)

2024-03-22 Thread Abhin P Jose via cfe-commits

Abhinkop wrote:

@AaronBallman @amy-kwan Here is the pull request for compiler-rt patch 
https://github.com/llvm/llvm-project/pull/86290. I am not able to add reviewers 
to that pull request.

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


[clang] [llvm] [CodeGen][LLVM] Make the `va_list` related intrinsics generic. (PR #85460)

2024-03-22 Thread Matt Arsenault via cfe-commits

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


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


[clang] AMDGPU: Rename and add bf16 support for global_load_tr builtins (PR #86202)

2024-03-22 Thread Changpeng Fang via cfe-commits

changpeng wrote:

[AMD Official Use Only - General]

I am fine to remove f16/bf16 versions. Enumerating all possible types could be 
very painful. For example we gave up enumerating for B64, and ended up using 
v2i32 only. What do others think removing f16/bf16 versions? Thanks

Get Outlook for iOS

From: Matt Arsenault ***@***.***>
Sent: Friday, March 22, 2024 3:45:53 AM
To: llvm/llvm-project ***@***.***>
Cc: Fang, Changpeng ***@***.***>; Author ***@***.***>
Subject: Re: [llvm/llvm-project] AMDGPU: Rename and add bf16 support for 
global_load_tr builtins (PR #86202)

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.


@arsenm commented on this pull request.



In 
clang/include/clang/Basic/BuiltinsAMDGPU.def:

> -TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v2i32, "V2iV2i*1", "nc", 
> "gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
-
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
-TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8bf16, "V8yV8y*1", "nc", 
"gfx12-insts,wavefrontsize32")
+
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4bf16, "V4yV4y*1", "nc", 
"gfx12-insts,wavefrontsize64")


Do we really need the f16/bf16 versions? You can always bitcast the i16 
versions.

—
Reply to this email directly, view it on 
GitHub,
 or 
unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>


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


[clang] b44771f - [RISCV] Support RISC-V Profiles in -march option (#76357)

2024-03-22 Thread Wang Pengcheng via cfe-commits

Author: Wang Pengcheng
Date: 2024-03-22T23:21:11+08:00
New Revision: b44771f480385fa93ba7719a57e759e19747e709

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

LOG: [RISCV] Support RISC-V Profiles in -march option (#76357)

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.

This is recommitted as 66f88de was reverted because of failures
caused by lacking `--target` option.

Added: 
clang/test/Driver/riscv-profiles.c

Modified: 
clang/docs/ReleaseNotes.rst
llvm/lib/Support/RISCVISAInfo.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45b2e01af997c5..d6e179ca9d6904 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -520,6 +520,7 @@ RISC-V Support
 ^^
 
 - ``__attribute__((rvv_vector_bits(N)))`` is now supported for RVV vbool*_t 
types.
+- Profile names in ``-march`` option are now supported.
 
 CUDA/HIP Language Changes
 ^

diff  --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..0227487015ba7c
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,324 @@
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -march=rvi20u32 \
+// RUN:   | FileCheck -check-prefix=RVI20U32 %s
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rvi20u64 \
+// RUN:  | FileCheck -check-prefix=RVI20U64 %s
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rva20u64 \
+// RUN:   | FileCheck -check-prefix=RVA20U64 %s
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+ziccamoa"
+// RVA20U64: "-target-feature" "+ziccif"
+// RVA20U64: "-target-feature" "+zicclsm"
+// RVA20U64: "-target-feature" "+ziccrse"
+// RVA20U64: "-target-feature" "+zicntr"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-feature" "+za128rs"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rva20s64 \
+// RUN:   | FileCheck -check-prefix=RVA20S64 %s
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+ziccamoa"
+// RVA20S64: "-target-feature" "+ziccif"
+// RVA20S64: "-target-feature" "+zicclsm"
+// RVA20S64: "-target-feature" "+ziccrse"
+// RVA20S64: "-target-feature" "+zicntr"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-feature" "+za128rs"
+// RVA20S64: "-target-feature" "+ssccptr"
+// RVA20S64: "-target-feature" "+sstvala"
+// RVA20S64: "-target-feature" "+sstvecd"
+// RVA20S64: "-target-feature" "+svade"
+// RVA20S64: "-target-feature" "+svbare"
+
+// RUN: %clang --target=riscv64 --target=riscv64 -### -c %s 2>&1 
-march=rva22u64 \
+// RUN:   | FileCheck -check-prefix=RVA22U64 %s
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zic64b"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+ziccamoa"
+// RVA22U64: "-target-feature" "+ziccif"
+// RVA22U64: "-target-feature" "+zicclsm"
+// RVA22U64: "-target-feature" "+ziccrse"
+// RVA22U64: "-target-feature" "+zicntr"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zihpm"
+// RVA22U64: "-target-feature" "+za64rs"
+// RVA22U64: "-target-feature" "+zfhmin"
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+
+// RUN: %clang --target=riscv64 --target=riscv64 -### -c %s 2>&1 
-march=rva22s64 \
+// RUN:   | FileCheck -check-prefix=RVA22S64 %s
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-

  1   2   3   >