[clang] ca7d944 - [clang][dataflow] Support `CXXParenListInitExpr` in `PropagateResultObject()`. (#89235)

2024-04-19 Thread via cfe-commits

Author: martinboehme
Date: 2024-04-19T09:06:13+02:00
New Revision: ca7d9442baf638f020c9594dc2af388d24c4a3e1

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

LOG: [clang][dataflow] Support `CXXParenListInitExpr` in 
`PropagateResultObject()`. (#89235)

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/ASTOps.h
clang/lib/Analysis/FlowSensitive/ASTOps.cpp
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h 
b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
index 27ad32c1694f77..f9fd3db1fb67fc 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
@@ -56,6 +56,7 @@ class RecordInitListHelper {
 public:
   // `InitList` must have record type.
   RecordInitListHelper(const InitListExpr *InitList);
+  RecordInitListHelper(const CXXParenListInitExpr *ParenInitList);
 
   // Base classes with their associated initializer expressions.
   ArrayRef> base_inits() const {
@@ -68,6 +69,9 @@ class RecordInitListHelper {
   }
 
 private:
+  RecordInitListHelper(QualType Ty, std::vector Fields,
+   ArrayRef Inits);
+
   SmallVector> BaseInits;
   SmallVector> FieldInits;
 

diff  --git a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp 
b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
index 1982c6c9f38305..6f179c1403b6f5 100644
--- a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
@@ -80,11 +80,12 @@ bool containsSameFields(const FieldSet &Fields,
 }
 
 /// Returns the fields of a `RecordDecl` that are initialized by an
-/// `InitListExpr`, in the order in which they appear in
-/// `InitListExpr::inits()`.
-/// `Init->getType()` must be a record type.
+/// `InitListExpr` or `CXXParenListInitExpr`, in the order in which they appear
+/// in `InitListExpr::inits()` / `CXXParenListInitExpr::getInitExprs()`.
+/// `InitList->getType()` must be a record type.
+template 
 static std::vector
-getFieldsForInitListExpr(const InitListExpr *InitList) {
+getFieldsForInitListExpr(const InitListT *InitList) {
   const RecordDecl *RD = InitList->getType()->getAsRecordDecl();
   assert(RD != nullptr);
 
@@ -105,19 +106,29 @@ getFieldsForInitListExpr(const InitListExpr *InitList) {
   return Fields;
 }
 
-RecordInitListHelper::RecordInitListHelper(const InitListExpr *InitList) {
-  auto *RD = InitList->getType()->getAsCXXRecordDecl();
-  assert(RD != nullptr);
+RecordInitListHelper::RecordInitListHelper(const InitListExpr *InitList)
+: RecordInitListHelper(InitList->getType(),
+   getFieldsForInitListExpr(InitList),
+   InitList->inits()) {}
+
+RecordInitListHelper::RecordInitListHelper(
+const CXXParenListInitExpr *ParenInitList)
+: RecordInitListHelper(ParenInitList->getType(),
+   getFieldsForInitListExpr(ParenInitList),
+   ParenInitList->getInitExprs()) {}
 
-  std::vector Fields = getFieldsForInitListExpr(InitList);
-  ArrayRef Inits = InitList->inits();
+RecordInitListHelper::RecordInitListHelper(
+QualType Ty, std::vector Fields,
+ArrayRef Inits) {
+  auto *RD = Ty->getAsCXXRecordDecl();
+  assert(RD != nullptr);
 
   // Unions initialized with an empty initializer list need special treatment.
   // For structs/classes initialized with an empty initializer list, Clang
   // puts `ImplicitValueInitExpr`s in `InitListExpr::inits()`, but for unions,
   // it doesn't do this -- so we create an `ImplicitValueInitExpr` ourselves.
   SmallVector InitsForUnion;
-  if (InitList->getType()->isUnionType() && Inits.empty()) {
+  if (Ty->isUnionType() && Inits.empty()) {
 assert(Fields.size() == 1);
 ImplicitValueInitForUnion.emplace(Fields.front()->getType());
 InitsForUnion.push_back(&*ImplicitValueInitForUnion);
@@ -217,6 +228,10 @@ static void getReferencedDecls(const Stmt &S, 
ReferencedDecls &Referenced) {
 if (InitList->getType()->isRecordType())
   for (const auto *FD : getFieldsForInitListExpr(InitList))
 Referenced.Fields.insert(FD);
+  } else if (auto *ParenInitList = dyn_cast(&S)) {
+if (ParenInitList->getType()->isRecordType())
+  for (const auto *FD : getFieldsForInitListExpr(ParenInitList))
+Referenced.Fields.insert(FD);
   }
 }
 

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 3f1600d9ac5d87..138773460dd749 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -401,6 +401,28 @@ class 

[clang] [clang][dataflow] Support `CXXParenListInitExpr` in `PropagateResultObject()`. (PR #89235)

2024-04-19 Thread via cfe-commits

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


[clang] [clang][dataflow] Model conditional operator correctly. (PR #89213)

2024-04-19 Thread via cfe-commits

https://github.com/martinboehme updated 
https://github.com/llvm/llvm-project/pull/89213

>From d4205b37d9ba3cecd7cd947a188ec84e9afec899 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Thu, 18 Apr 2024 10:50:40 +
Subject: [PATCH 1/3] [clang][dataflow] Model conditional operator correctly.

---
 .../FlowSensitive/DataflowEnvironment.h   | 15 +
 .../clang/Analysis/FlowSensitive/Transfer.h   |  3 +-
 .../FlowSensitive/DataflowEnvironment.cpp | 46 ++---
 clang/lib/Analysis/FlowSensitive/Transfer.cpp | 38 ++-
 .../TypeErasedDataflowAnalysis.cpp|  4 +-
 .../Analysis/FlowSensitive/TestingSupport.h   |  4 +-
 .../Analysis/FlowSensitive/TransferTest.cpp   | 66 +--
 7 files changed, 130 insertions(+), 46 deletions(-)

diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 4277792219c0af..7ad866ba3f62ff 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -244,6 +244,21 @@ class Environment {
   Environment::ValueModel &Model,
   ExprJoinBehavior ExprBehavior);
 
+  /// Returns a value that approximates both `Val1` and `Val2`, or null if no
+  /// such value can be produced.
+  ///
+  /// `Env1` and `Env2` can be used to query child values and path condition
+  /// implications of `Val1` and `Val2` respectively. The joined value will be
+  /// produced in `JoinedEnv`.
+  ///
+  /// Requirements:
+  ///
+  ///  `Val1` and `Val2` must model values of type `Type`.
+  static Value *joinValues(QualType Ty, Value *Val1, const Environment &Env1,
+   Value *Val2, const Environment &Env2,
+   Environment &JoinedEnv,
+   Environment::ValueModel &Model);
+
   /// Widens the environment point-wise, using `PrevEnv` as needed to inform 
the
   /// approximation.
   ///
diff --git a/clang/include/clang/Analysis/FlowSensitive/Transfer.h 
b/clang/include/clang/Analysis/FlowSensitive/Transfer.h
index ed148250d8eb29..940025e02100f9 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Transfer.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Transfer.h
@@ -53,7 +53,8 @@ class StmtToEnvMap {
 /// Requirements:
 ///
 ///  `S` must not be `ParenExpr` or `ExprWithCleanups`.
-void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env);
+void transfer(const StmtToEnvMap &StmtToEnv, const Stmt &S, Environment &Env,
+  Environment::ValueModel &Model);
 
 } // namespace dataflow
 } // namespace clang
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 3f1600d9ac5d87..18fd6476dedf4b 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -255,13 +255,8 @@ joinLocToVal(const llvm::MapVector &LocToVal,
   continue;
 assert(It->second != nullptr);
 
-if (areEquivalentValues(*Val, *It->second)) {
-  Result.insert({Loc, Val});
-  continue;
-}
-
-if (Value *JoinedVal = joinDistinctValues(
-Loc->getType(), *Val, Env1, *It->second, Env2, JoinedEnv, Model)) {
+if (Value *JoinedVal = Environment::joinValues(
+Loc->getType(), Val, Env1, It->second, Env2, JoinedEnv, Model)) {
   Result.insert({Loc, JoinedVal});
 }
   }
@@ -788,27 +783,16 @@ Environment Environment::join(const Environment &EnvA, 
const Environment &EnvB,
   JoinedEnv.LocForRecordReturnVal = EnvA.LocForRecordReturnVal;
   JoinedEnv.ThisPointeeLoc = EnvA.ThisPointeeLoc;
 
-  if (EnvA.ReturnVal == nullptr || EnvB.ReturnVal == nullptr) {
-// `ReturnVal` might not always get set -- for example if we have a return
-// statement of the form `return some_other_func()` and we decide not to
-// analyze `some_other_func()`.
-// In this case, we can't say anything about the joined return value -- we
-// don't simply want to propagate the return value that we do have, because
-// it might not be the correct one.
-// This occurs for example in the test `ContextSensitiveMutualRecursion`.
+  if (EnvA.CallStack.empty()) {
 JoinedEnv.ReturnVal = nullptr;
-  } else if (areEquivalentValues(*EnvA.ReturnVal, *EnvB.ReturnVal)) {
-JoinedEnv.ReturnVal = EnvA.ReturnVal;
   } else {
-assert(!EnvA.CallStack.empty());
 // FIXME: Make `CallStack` a vector of `FunctionDecl` so we don't need this
 // cast.
 auto *Func = dyn_cast(EnvA.CallStack.back());
 assert(Func != nullptr);
-if (Value *JoinedVal =
-joinDistinctValues(Func->getReturnType(), *EnvA.ReturnVal, EnvA,
-   *EnvB.ReturnVal, EnvB, JoinedEnv, Model))
-  JoinedEnv.ReturnVal = JoinedVal;
+JoinedEnv.ReturnVal =
+joinVal

[clang] Reapply "[Clang][Sema] placement new initializes typedef array with correct size (#83124)" (PR #89036)

2024-04-19 Thread via cfe-commits

mahtohappy wrote:

Check is for dependent types and earlier I was not checking that with the 
condition being only
```if (ArraySize)``` so normal arrays with new initializer also were passing 
the check.
Now added the dependent type check as well
```if (ArraySize && E->isTypeDependent())```

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


[clang] [clang][dataflow] Model conditional operator correctly. (PR #89213)

2024-04-19 Thread via cfe-commits


@@ -657,17 +658,25 @@ class TransferVisitor : public 
ConstStmtVisitor {
   }
 
   void VisitConditionalOperator(const ConditionalOperator *S) {
-// FIXME: Revisit this once flow conditions are added to the framework. For
-// `a = b ? c : d` we can add `b => a == c && !b => a == d` to the flow
-// condition.
-// When we do this, we will need to retrieve the values of the operands 
from
-// the environments for the basic blocks they are computed in, in a similar
-// way to how this is done for short-circuited logical operators in
-// `getLogicOperatorSubExprValue()`.
-if (S->isGLValue())
-  Env.setStorageLocation(*S, Env.createObject(S->getType()));
-else if (!S->getType()->isRecordType()) {
-  if (Value *Val = Env.createValue(S->getType()))
+const Environment *TrueEnv = StmtToEnv.getEnvironment(*S->getTrueExpr());
+const Environment *FalseEnv = StmtToEnv.getEnvironment(*S->getFalseExpr());
+
+if (TrueEnv == nullptr || FalseEnv == nullptr)

martinboehme wrote:

Good point. This is just a defence against crashes in production if we 
unexpectedly don't find an environment; but obviously this means the bailout 
should be paired with an assertion, which I have now added.

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


[clang] [llvm] [mlir] Fix Definition Mismatches (PR #89294)

2024-04-19 Thread Yingwei Zheng via cfe-commits

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


[clang] [llvm] [mlir] Fix Definition Mismatches (PR #89294)

2024-04-19 Thread Yingwei Zheng via cfe-commits

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


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


[clang] [llvm] [mlir] Fix Definition Mismatches (PR #89294)

2024-04-19 Thread Yingwei Zheng via cfe-commits


@@ -433,7 +433,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
   Value *foldAndOrOfICmpsOfAndWithPow2(ICmpInst *LHS, ICmpInst *RHS,
Instruction *CxtI, bool IsAnd,
bool IsLogical = false);
-  Value *matchSelectFromAndOr(Value *A, Value *B, Value *C, Value *D,

dtcxzyw wrote:

It is weird. I think it cannot fix the warning.

See the users of matchSelectFromAndOr:
```
  if (Value *V = matchSelectFromAndOr(A, C, B, D))
return replaceInstUsesWith(I, V);
  if (Value *V = matchSelectFromAndOr(A, C, D, B))
return replaceInstUsesWith(I, V);
  if (Value *V = matchSelectFromAndOr(C, A, B, D))
return replaceInstUsesWith(I, V);
  if (Value *V = matchSelectFromAndOr(C, A, D, B))
return replaceInstUsesWith(I, V);
  if (Value *V = matchSelectFromAndOr(B, D, A, C))
return replaceInstUsesWith(I, V);
  if (Value *V = matchSelectFromAndOr(B, D, C, A))
return replaceInstUsesWith(I, V);
  if (Value *V = matchSelectFromAndOr(D, B, A, C))
return replaceInstUsesWith(I, V);
  if (Value *V = matchSelectFromAndOr(D, B, C, A))
return replaceInstUsesWith(I, V);
```


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


[clang] [clang][analyzer] Move StreamChecker out of the alpha package. (PR #89247)

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

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/89247

From 7138f026e845ebb4f1a3e6a86bdeb534d666ae7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Thu, 18 Apr 2024 16:40:03 +0200
Subject: [PATCH 1/2] [clang][analyzer] Move StreamChecker out of the alpha
 package.

---
 clang/docs/analyzer/checkers.rst  | 186 +-
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  31 +--
 clang/test/Analysis/analyzer-config.c |   2 +-
 .../test/Analysis/analyzer-enabled-checkers.c |   1 +
 ...c-library-functions-arg-enabled-checkers.c |   6 +-
 .../std-c-library-functions-arg-weakdeps.c|   4 +-
 ...td-c-library-functions-vs-stream-checker.c |   8 +-
 clang/test/Analysis/stream-errno-note.c   |   4 +-
 clang/test/Analysis/stream-errno.c|   4 +-
 clang/test/Analysis/stream-error.c|   4 +-
 clang/test/Analysis/stream-invalidate.c   |   2 +-
 .../test/Analysis/stream-non-posix-function.c |   2 +-
 clang/test/Analysis/stream-noopen.c   |   2 +-
 clang/test/Analysis/stream-note.c |   8 +-
 clang/test/Analysis/stream-pedantic.c |   8 +-
 .../Analysis/stream-stdlibraryfunctionargs.c  |  10 +-
 clang/test/Analysis/stream.c  |  16 +-
 clang/test/Analysis/stream.cpp|   2 +-
 clang/www/analyzer/alpha_checks.html  |   4 +-
 clang/www/analyzer/open_projects.html |   2 +-
 20 files changed, 154 insertions(+), 152 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index fb748d23a53d01..32c2a312962754 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1462,6 +1462,99 @@ checker).
 
 Default value of the option is ``true``.
 
+.. _unix-Stream:
+
+unix.Stream (C)
+"
+Check C stream handling functions:
+``fopen, fdopen, freopen, tmpfile, fclose, fread, fwrite, fgetc, fgets, fputc, 
fputs, fprintf, fscanf, ungetc, getdelim, getline, fseek, fseeko, ftell, 
ftello, fflush, rewind, fgetpos, fsetpos, clearerr, feof, ferror, fileno``.
+
+The checker maintains information about the C stream objects (``FILE *``) and
+can detect error conditions related to use of streams. The following conditions
+are detected:
+
+* The ``FILE *`` pointer passed to the function is NULL (the single exception 
is
+  ``fflush`` where NULL is allowed).
+* Use of stream after close.
+* Opened stream is not closed.
+* Read from a stream after end-of-file. (This is not a fatal error but reported
+  by the checker. Stream remains in EOF state and the read operation fails.)
+* Use of stream when the file position is indeterminate after a previous failed
+  operation. Some functions (like ``ferror``, ``clearerr``, ``fseek``) are
+  allowed in this state.
+* Invalid 3rd ("``whence``") argument to ``fseek``.
+
+The stream operations are by this checker usually split into two cases, a 
success
+and a failure case. However, in the case of write operations (like ``fwrite``,
+``fprintf`` and even ``fsetpos``) this behavior could produce a large amount of
+unwanted reports on projects that don't have error checks around the write
+operations, so by default the checker assumes that write operations always 
succeed.
+This behavior can be controlled by the ``Pedantic`` flag: With
+``-analyzer-config unix.Stream:Pedantic=true`` the checker will model the
+cases where a write operation fails and report situations where this leads to
+erroneous behavior. (The default is ``Pedantic=false``, where write operations
+are assumed to succeed.)
+
+.. code-block:: c
+
+ void test1() {
+   FILE *p = fopen("foo", "r");
+ } // warn: opened file is never closed
+
+ void test2() {
+   FILE *p = fopen("foo", "r");
+   fseek(p, 1, SEEK_SET); // warn: stream pointer might be NULL
+   fclose(p);
+ }
+
+ void test3() {
+   FILE *p = fopen("foo", "r");
+   if (p) {
+ fseek(p, 1, 3); // warn: third arg should be SEEK_SET, SEEK_END, or 
SEEK_CUR
+ fclose(p);
+   }
+ }
+
+ void test4() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fclose(p);
+   fclose(p); // warn: stream already closed
+ }
+
+ void test5() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fgetc(p);
+   if (!ferror(p))
+ fgetc(p); // warn: possible read after end-of-file
+
+   fclose(p);
+ }
+
+ void test6() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fgetc(p);
+   if (!feof(p))
+ fgetc(p); // warn: file position may be indeterminate after I/O error
+
+   fclose(p);
+ }
+
+**Limitations**
+
+The checker does not track the correspondence between integer file descriptors
+and ``FILE *`` pointers. Operations on standard streams like ``stdin`` are not
+treated specially and are therefore often not recognized (because these streams
+are usually not opened explicitly by the program, and are global variables).
+
 .. _osx-checkers:
 
 osx
@@ -3116,99 +3209,6 @@ Check for misuse

[clang] [clang][nullability] Remove `RecordValue`. (PR #89052)

2024-04-19 Thread via cfe-commits

https://github.com/martinboehme updated 
https://github.com/llvm/llvm-project/pull/89052

>From a705853deb0cfa6596245c929e9b86ea2d2a7c26 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Wed, 17 Apr 2024 11:31:12 +
Subject: [PATCH] [clang][nullability] Remove `RecordValue`.

This class no longer serves any purpose; see also the discussion here:
https://reviews.llvm.org/D155204#inline-1503204

A lot of existing tests in TransferTest.cpp check for the existence of
`RecordValue`s. Some of these checks are now simply redundant and have been
removed. In other cases, tests were checking for the existence of a
`RecordValue` as a way of testing whether a record has been initialized. I have
typically changed these test to instead check whether a field of the record has
a value.
---
 .../FlowSensitive/DataflowEnvironment.h   |  38 +++---
 .../clang/Analysis/FlowSensitive/Value.h  |  41 --
 .../FlowSensitive/DataflowEnvironment.cpp |  98 --
 .../Analysis/FlowSensitive/DebugSupport.cpp   |   2 -
 .../lib/Analysis/FlowSensitive/HTMLLogger.cpp |  13 +-
 .../Models/UncheckedOptionalAccessModel.cpp   |  46 +++
 .../lib/Analysis/FlowSensitive/RecordOps.cpp  |   3 -
 clang/lib/Analysis/FlowSensitive/Transfer.cpp |  62 +++--
 .../TypeErasedDataflowAnalysis.cpp|   6 +-
 clang/lib/Analysis/FlowSensitive/Value.cpp|   2 -
 .../FlowSensitive/DataflowEnvironmentTest.cpp |  81 ---
 .../Analysis/FlowSensitive/RecordOpsTest.cpp  |   8 --
 .../Analysis/FlowSensitive/TransferTest.cpp   | 126 ++
 13 files changed, 130 insertions(+), 396 deletions(-)

diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 4277792219c0af..d50dba35f8264c 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -84,7 +84,7 @@ class Environment {
 virtual ComparisonResult compare(QualType Type, const Value &Val1,
  const Environment &Env1, const Value 
&Val2,
  const Environment &Env2) {
-  // FIXME: Consider adding QualType to RecordValue and removing the Type
+  // FIXME: Consider adding `QualType` to `Value` and removing the `Type`
   // argument here.
   return ComparisonResult::Unknown;
 }
@@ -407,20 +407,15 @@ class Environment {
   /// storage locations and values for indirections until it finds a
   /// non-pointer/non-reference type.
   ///
-  /// If `Type` is a class, struct, or union type, creates values for all
-  /// modeled fields (including synthetic fields) and calls `setValue()` to
-  /// associate the `RecordValue` with its storage location
-  /// (`RecordValue::getLoc()`).
-  ///
   /// If `Type` is one of the following types, this function will always return
   /// a non-null pointer:
   /// - `bool`
   /// - Any integer type
-  /// - Any class, struct, or union type
   ///
   /// Requirements:
   ///
-  ///  `Type` must not be null.
+  ///  - `Type` must not be null.
+  ///  - `Type` must not be a reference type or record type.
   Value *createValue(QualType Type);
 
   /// Creates an object (i.e. a storage location with an associated value) of
@@ -452,6 +447,7 @@ class Environment {
   /// Initializes the fields (including synthetic fields) of `Loc` with values,
   /// unless values of the field type are not supported or we hit one of the
   /// limits at which we stop producing values.
+  /// If a field already has a value, that value is preserved.
   /// If `Type` is provided, initializes only those fields that are modeled for
   /// `Type`; this is intended for use in cases where `Loc` is a derived type
   /// and we only want to initialize the fields of a base type.
@@ -461,6 +457,10 @@ class Environment {
   }
 
   /// Assigns `Val` as the value of `Loc` in the environment.
+  ///
+  /// Requirements:
+  ///
+  ///  `Loc` must not be a `RecordStorageLocation`.
   void setValue(const StorageLocation &Loc, Value &Val);
 
   /// Clears any association between `Loc` and a value in the environment.
@@ -470,20 +470,24 @@ class Environment {
   ///
   /// Requirements:
   ///
-  ///  - `E` must be a prvalue
-  ///  - If `Val` is a `RecordValue`, its `RecordStorageLocation` must be
-  ///`getResultObjectLocation(E)`. An exception to this is if `E` is an
-  ///expression that originally creates a `RecordValue` (such as a
-  ///`CXXConstructExpr` or `CallExpr`), as these establish the location of
-  ///the result object in the first place.
+  ///  - `E` must be a prvalue.
+  ///  - `E` must not have record type.
   void setValue(const Expr &E, Value &Val);
 
   /// Returns the value assigned to `Loc` in the environment or null if `Loc`
   /// isn't assigned a value in the environment.
+  ///
+  /// Requirements:
+  ///
+  ///  `Loc` must not be a `RecordStorage

[clang] b2323f4 - [AIX][Debug] generate an error instead of crash in backend for -gdwarf-5

2024-04-19 Thread Chen Zheng via cfe-commits

Author: Chen Zheng
Date: 2024-04-19T03:39:17-04:00
New Revision: b2323f43e3cdb52b4e15a7d4f434cd5c64740dd4

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

LOG: [AIX][Debug] generate an error instead of crash in backend for -gdwarf-5

Before this change -gdwarf-5 on AIX will cause backend crash, because
some DWARF5 sections are not defined in XCOFF.
Explicitly statement -gdwarf-5 as unsupported in frontend on AIX.

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/CodeGen/dwarf-version.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index f10aa4dfaa9ddd..b65b96db16bd79 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2116,8 +2116,12 @@ unsigned tools::getDwarfVersion(const ToolChain &TC,
 const llvm::opt::ArgList &Args) {
   unsigned DwarfVersion = ParseDebugDefaultVersion(TC, Args);
   if (const Arg *GDwarfN = getDwarfNArg(Args))
-if (int N = DwarfVersionNum(GDwarfN->getSpelling()))
+if (int N = DwarfVersionNum(GDwarfN->getSpelling())) {
   DwarfVersion = N;
+  if (DwarfVersion == 5 && TC.getTriple().isOSAIX())
+TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
+<< GDwarfN->getSpelling() << TC.getTriple().str();
+}
   if (DwarfVersion == 0) {
 DwarfVersion = TC.GetDefaultDwarfVersion();
 assert(DwarfVersion && "toolchain default DWARF version must be nonzero");

diff  --git a/clang/test/CodeGen/dwarf-version.c 
b/clang/test/CodeGen/dwarf-version.c
index e63316ace69c87..258c258e5f5a26 100644
--- a/clang/test/CodeGen/dwarf-version.c
+++ b/clang/test/CodeGen/dwarf-version.c
@@ -46,8 +46,10 @@
 // RUN:   FileCheck %s --check-prefix=VER3
 // RUN: %clang -target powerpc-ibm-aix-xcoff -gdwarf-4 -S -emit-llvm -o - %s | 
\
 // RUN:   FileCheck %s --check-prefix=VER4
-// RUN: %clang -target powerpc-ibm-aix-xcoff -gdwarf-5 -S -emit-llvm -o - %s | 
\
-// RUN:   FileCheck %s --check-prefix=VER5
+// RUN: not %clang -target powerpc-ibm-aix-xcoff -gdwarf-5 -S -emit-llvm -o - 
%s 2>&1 | \
+// RUN:   FileCheck %s --check-prefix=UNSUPPORTED-VER5
+// RUN: not %clang -target powerpc64-ibm-aix-xcoff -gdwarf-5 -S -emit-llvm -o 
- %s 2>&1| \
+// RUN:   FileCheck %s --check-prefix=UNSUPPORTED-VER5
 
 int main (void) {
   return 0;
@@ -59,6 +61,7 @@ int main (void) {
 // VER3: !{i32 7, !"Dwarf Version", i32 3}
 // VER4: !{i32 7, !"Dwarf Version", i32 4}
 // VER5: !{i32 7, !"Dwarf Version", i32 5}
+// UNSUPPORTED-VER5: error: unsupported option '-gdwarf-5'
 
 // NODWARF-NOT: !"Dwarf Version"
 // CODEVIEW: !{i32 2, !"CodeView", i32 1}



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


[clang] [clang][nullability] Remove `RecordValue`. (PR #89052)

2024-04-19 Thread via cfe-commits

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


[clang] e8fce95 - [clang][nullability] Remove `RecordValue`. (#89052)

2024-04-19 Thread via cfe-commits

Author: martinboehme
Date: 2024-04-19T09:39:52+02:00
New Revision: e8fce95887ecfd87a83db8dbb0cc55966b004d6f

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

LOG: [clang][nullability] Remove `RecordValue`. (#89052)

This class no longer serves any purpose; see also the discussion here:
https://reviews.llvm.org/D155204#inline-1503204

A lot of existing tests in TransferTest.cpp check for the existence of
`RecordValue`s. Some of these checks are now simply redundant and have
been
removed. In other cases, tests were checking for the existence of a
`RecordValue` as a way of testing whether a record has been initialized.
I have
typically changed these test to instead check whether a field of the
record has
a value.

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/include/clang/Analysis/FlowSensitive/Value.h
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/lib/Analysis/FlowSensitive/RecordOps.cpp
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/lib/Analysis/FlowSensitive/Value.cpp
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 4277792219c0af..d50dba35f8264c 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -84,7 +84,7 @@ class Environment {
 virtual ComparisonResult compare(QualType Type, const Value &Val1,
  const Environment &Env1, const Value 
&Val2,
  const Environment &Env2) {
-  // FIXME: Consider adding QualType to RecordValue and removing the Type
+  // FIXME: Consider adding `QualType` to `Value` and removing the `Type`
   // argument here.
   return ComparisonResult::Unknown;
 }
@@ -407,20 +407,15 @@ class Environment {
   /// storage locations and values for indirections until it finds a
   /// non-pointer/non-reference type.
   ///
-  /// If `Type` is a class, struct, or union type, creates values for all
-  /// modeled fields (including synthetic fields) and calls `setValue()` to
-  /// associate the `RecordValue` with its storage location
-  /// (`RecordValue::getLoc()`).
-  ///
   /// If `Type` is one of the following types, this function will always return
   /// a non-null pointer:
   /// - `bool`
   /// - Any integer type
-  /// - Any class, struct, or union type
   ///
   /// Requirements:
   ///
-  ///  `Type` must not be null.
+  ///  - `Type` must not be null.
+  ///  - `Type` must not be a reference type or record type.
   Value *createValue(QualType Type);
 
   /// Creates an object (i.e. a storage location with an associated value) of
@@ -452,6 +447,7 @@ class Environment {
   /// Initializes the fields (including synthetic fields) of `Loc` with values,
   /// unless values of the field type are not supported or we hit one of the
   /// limits at which we stop producing values.
+  /// If a field already has a value, that value is preserved.
   /// If `Type` is provided, initializes only those fields that are modeled for
   /// `Type`; this is intended for use in cases where `Loc` is a derived type
   /// and we only want to initialize the fields of a base type.
@@ -461,6 +457,10 @@ class Environment {
   }
 
   /// Assigns `Val` as the value of `Loc` in the environment.
+  ///
+  /// Requirements:
+  ///
+  ///  `Loc` must not be a `RecordStorageLocation`.
   void setValue(const StorageLocation &Loc, Value &Val);
 
   /// Clears any association between `Loc` and a value in the environment.
@@ -470,20 +470,24 @@ class Environment {
   ///
   /// Requirements:
   ///
-  ///  - `E` must be a prvalue
-  ///  - If `Val` is a `RecordValue`, its `RecordStorageLocation` must be
-  ///`getResultObjectLocation(E)`. An exception to this is if `E` is an
-  ///expression that originally creates a `RecordValue` (such as a
-  ///`CXXConstructExpr` or `CallExpr`), as these establish the location of
-  ///the result object in the first place.
+  ///  - `E` must be a prvalue.
+  ///  - `E` must not have record type.
   void setValue(const Expr &E, Value &Val);
 
   /// Returns the value assigned to `Loc` in the environment or null if 

[clang] [clang][dataflow] Model conditional operator correctly. (PR #89213)

2024-04-19 Thread via cfe-commits


@@ -657,17 +658,22 @@ class TransferVisitor : public 
ConstStmtVisitor {
   }
 
   void VisitConditionalOperator(const ConditionalOperator *S) {
-// FIXME: Revisit this once flow conditions are added to the framework. For
-// `a = b ? c : d` we can add `b => a == c && !b => a == d` to the flow
-// condition.
-// When we do this, we will need to retrieve the values of the operands 
from
-// the environments for the basic blocks they are computed in, in a similar
-// way to how this is done for short-circuited logical operators in
-// `getLogicOperatorSubExprValue()`.
-if (S->isGLValue())
-  Env.setStorageLocation(*S, Env.createObject(S->getType()));
-else if (!S->getType()->isRecordType()) {
-  if (Value *Val = Env.createValue(S->getType()))
+const Environment *TrueEnv = StmtToEnv.getEnvironment(*S->getTrueExpr());
+const Environment *FalseEnv = StmtToEnv.getEnvironment(*S->getFalseExpr());
+
+if (TrueEnv == nullptr || FalseEnv == nullptr)
+  return;
+
+if (S->isGLValue()) {
+  StorageLocation *TrueLoc = 
TrueEnv->getStorageLocation(*S->getTrueExpr());
+  StorageLocation *FalseLoc =
+  FalseEnv->getStorageLocation(*S->getFalseExpr());
+  if (TrueLoc == FalseLoc && TrueLoc != nullptr)
+Env.setStorageLocation(*S, *TrueLoc);
+} else if (!S->getType()->isRecordType()) {
+  if (Value *Val = Environment::joinValues(

martinboehme wrote:

I understand your reaction; generally, we want to perform joins in 
`computeBlockInputState()`. But the conditional operator is a special case.

Consider: In `computeBlockInputState()` (which calls through to 
`Environment::join()`, we join values that are associated with the _same_ 
expression or the same storage location, and then we associate the joined value 
with that same expression or storage location in the joined environment.

For the conditional operator, we want to join values that are associated with 
_different_ expressions (the two branches of the conditional operator), and 
then we associate the joined value with a third expression (the conditional 
operator itself). This join is what it means to perform transfer on the 
conditional operator.

Here's a simple example ([godbolt](https://godbolt.org/z/7ddnKo7Eh)) that 
hopefully clarifies this:

```cxx
int f(bool b, int i, int j) {
  return b ? i : j;
}
```

Here's the CFG:

```
 [B5 (ENTRY)]
   Succs (1): B4

 [B1]
   1: [B4.2] ? [B2.1] : [B3.1]
   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
   3: return [B1.2];
   Preds (2): B2 B3
   Succs (1): B0

 [B2]
   1: i
   Preds (1): B4
   Succs (1): B1

 [B3]
   1: j
   Preds (1): B4
   Succs (1): B1

 [B4]
   1: b
   2: [B4.1] (ImplicitCastExpr, LValueToRValue, _Bool)
   T: [B4.2] ? ... : ...
   Preds (1): B5
   Succs (2): B2 B3

 [B0 (EXIT)]
   Preds (1): B1
```

The expressions whose values we are joining are `i` ([B2.1]) and `j` ([B3.1]). 
The joined value is associated with the conditional operator ([B1.1]).

What would it look like if we wanted to do this join within 
`computeBlockInputState()`?

*  We would have to put code that is specific to `ConditionalOperator` in 
`computeBlockInputState()`. This would be incongruous, as 
`computeBlockInputState()` is otherwise completely general -- it doesn't 
contain any code that's specific to a particular statement kind.
*  We would be associating the joined value with the expression [B1.1] in the 
_input_ state of [B1], i.e. before we have started performing transfer on [B1]. 
This seems wrong: [B1.1] is an expression in [B1], and we should set its value 
when we transfer [B1], not before. (Put differently: If we put the logic for 
this in `computeBlockInputState()`, what would there be left for 
`TransferVisitor::VisitConditionalOperator()` to do?)

I hope this makes sense. If not, maybe it would be easiest to do a quick VC to 
discuss?

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


[clang] [clang][dataflow] Model conditional operator correctly. (PR #89213)

2024-04-19 Thread via cfe-commits

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


[clang] [clang][dataflow] Model conditional operator correctly. (PR #89213)

2024-04-19 Thread via cfe-commits

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


[clang] [clang]MveEmitter:Pass Args as const references (PR #89202)

2024-04-19 Thread via cfe-commits

https://github.com/aniplcc updated 
https://github.com/llvm/llvm-project/pull/89202

>From 650a14ed69d1296d3674e58cf66364ca6fa21932 Mon Sep 17 00:00:00 2001
From: aniplcc 
Date: Thu, 18 Apr 2024 15:38:55 +0530
Subject: [PATCH] [clang]MveEmitter:Update args with const references

---
 clang/utils/TableGen/MveEmitter.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/utils/TableGen/MveEmitter.cpp 
b/clang/utils/TableGen/MveEmitter.cpp
index 88e7b6e8546595..23c1646fa82623 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -660,7 +660,7 @@ class IRBuilderResult : public Result {
   std::map IntegerArgs;
   IRBuilderResult(StringRef CallPrefix, std::vector Args,
   std::set AddressArgs,
-  std::map IntegerArgs)
+  const std::map &IntegerArgs)
   : CallPrefix(CallPrefix), Args(Args), AddressArgs(AddressArgs),
 IntegerArgs(IntegerArgs) {}
   void genCode(raw_ostream &OS,
@@ -728,7 +728,7 @@ class IRIntrinsicResult : public Result {
   std::vector ParamTypes;
   std::vector Args;
   IRIntrinsicResult(StringRef IntrinsicID, std::vector 
ParamTypes,
-std::vector Args)
+const std::vector &Args)
   : IntrinsicID(std::string(IntrinsicID)), ParamTypes(ParamTypes),
 Args(Args) {}
   void genCode(raw_ostream &OS,

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


[clang] [clang-repl] Clone the llvm::Modules to avoid invalid memory access. (PR #89031)

2024-04-19 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev updated 
https://github.com/llvm/llvm-project/pull/89031

>From e5aae5f7b945f1f6da58453f03dafdb86c90 Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Fri, 19 Apr 2024 07:51:17 +
Subject: [PATCH] [clang-repl] Keep the first llvm::Module empty to avoid
 invalid memory access.

Clang's CodeGen is designed to work with a single llvm::Module. In many cases
for convenience various CodeGen parts have a reference to the llvm::Module
(TheModule or Module) which does not change when a new module is pushed.
However, the execution engine wants to take ownership of the module which does
not map well to CodeGen's design. To work this around we clone the module and
pass it down.

With some effort it is possible to teach CodeGen to ask the CodeGenModule for
its current module and that would have an overall positive impact on CodeGen
improving the encapsulation of various parts but that's not resilient to future
regression.

This patch takes a more conservative approach and keeps the first llvm::Module
empty intentionally and does not pass it to the Jit. That's also not bullet
proof because we have to guarantee that CodeGen does not write on the
blueprint. However, we have inserted some assertions to catch accidental
additions to that canary module.

This change will fixes a long-standing invalid memory access reported by
valgrind when we enable the TBAA optimization passes. It also unblock progress
on llvm/llvm-project#84758.
---
 clang/lib/Interpreter/IncrementalParser.cpp | 24 -
 clang/lib/Interpreter/IncrementalParser.h   |  5 +
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 5eec2a2fd6d1a6..949244f57dcef0 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -209,6 +209,10 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
   if (Err)
 return;
   CI->ExecuteAction(*Act);
+
+  if (getCodeGen())
+CachedInCodeGenModule = std::move(GenModule());
+
   std::unique_ptr IncrConsumer =
   std::make_unique(Interp, CI->takeASTConsumer());
   CI->setASTConsumer(std::move(IncrConsumer));
@@ -224,11 +228,8 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
 return; // PTU.takeError();
   }
 
-  if (CodeGenerator *CG = getCodeGen()) {
-std::unique_ptr M(CG->ReleaseModule());
-CG->StartModule("incr_module_" + std::to_string(PTUs.size()),
-M->getContext());
-PTU->TheModule = std::move(M);
+  if (getCodeGen()) {
+PTU->TheModule = std::move(GenModule());
 assert(PTU->TheModule && "Failed to create initial PTU");
   }
 }
@@ -364,6 +365,19 @@ IncrementalParser::Parse(llvm::StringRef input) {
 std::unique_ptr IncrementalParser::GenModule() {
   static unsigned ID = 0;
   if (CodeGenerator *CG = getCodeGen()) {
+// Clang's CodeGen is designed to work with a single llvm::Module. In many
+// cases for convenience various CodeGen parts have a reference to the
+// llvm::Module (TheModule or Module) which does not change when a new
+// module is pushed. However, the execution engine wants to take ownership
+// of the module which does not map well to CodeGen's design. To work this
+// around we clone the module and pass it down.
+assert((!CachedInCodeGenModule ||
+(CachedInCodeGenModule->empty() &&
+ CachedInCodeGenModule->global_empty() &&
+ CachedInCodeGenModule->alias_empty() &&
+ CachedInCodeGenModule->ifunc_empty() &&
+ CachedInCodeGenModule->named_metadata_empty())) &&
+   "CodeGen wrote to a readonly module");
 std::unique_ptr M(CG->ReleaseModule());
 CG->StartModule("incr_module_" + std::to_string(ID++), M->getContext());
 return M;
diff --git a/clang/lib/Interpreter/IncrementalParser.h 
b/clang/lib/Interpreter/IncrementalParser.h
index e13b74c7f65948..f63bce50acd3b9 100644
--- a/clang/lib/Interpreter/IncrementalParser.h
+++ b/clang/lib/Interpreter/IncrementalParser.h
@@ -24,6 +24,7 @@
 #include 
 namespace llvm {
 class LLVMContext;
+class Module;
 } // namespace llvm
 
 namespace clang {
@@ -57,6 +58,10 @@ class IncrementalParser {
   /// of code.
   std::list PTUs;
 
+  /// When CodeGen is created the first llvm::Module gets cached in many places
+  /// and we must keep it alive.
+  std::unique_ptr CachedInCodeGenModule;
+
   IncrementalParser();
 
 public:

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


[clang] [clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (PR #89031)

2024-04-19 Thread Vassil Vassilev via cfe-commits

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


[clang] [clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (PR #89031)

2024-04-19 Thread Vassil Vassilev via cfe-commits

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


[clang] [clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (PR #89031)

2024-04-19 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

After an offline discussion with @lhames, we have a more simplified approach 
which should consume less memory. Now we just keep the first llvm::Module empty 
and make sure it's used only for read-only purposes such as computing the 
llvm::DataLayout out of it in CodeGen.

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


[clang] [clang][dataflow][NFC] Fix code formatting in DataflowEnvironment.cpp (PR #89352)

2024-04-19 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/89352

For some reason, when I merged #89235, two lines were mis-formatted.

This patch corrects this; while I'm here, I'm also correcting other
existing formatting errors.


>From 483a737432dc0e063addb9b15cf8853dab709de8 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Fri, 19 Apr 2024 07:56:48 +
Subject: [PATCH] [clang][dataflow][NFC] Fix code formatting in
 DataflowEnvironment.cpp

For some reason, when I merged #89235, two lines were mis-formatted.

This patch corrects this; while I'm here, I'm also correcting other
existing formatting errors.
---
 .../Analysis/FlowSensitive/DataflowEnvironment.cpp | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 6998e6d7a5170b..05395e07a7a68c 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -400,8 +400,8 @@ class ResultObjectVisitor : public 
RecursiveASTVisitor {
   // Fields of non-record type are handled in
   // `TransferVisitor::VisitInitListExpr()`.
   if (Field->getType()->isRecordType())
-PropagateResultObject(Init,
-  
cast(Loc->getChild(*Field)));
+PropagateResultObject(
+Init, cast(Loc->getChild(*Field)));
 }
   }
 
@@ -610,8 +610,8 @@ Environment Environment::pushCall(const CallExpr *Call) 
const {
   if (const auto *MethodCall = dyn_cast(Call)) {
 if (const Expr *Arg = MethodCall->getImplicitObjectArgument()) {
   if (!isa(Arg))
-  Env.ThisPointeeLoc =
-  cast(getStorageLocation(*Arg));
+Env.ThisPointeeLoc =
+cast(getStorageLocation(*Arg));
   // Otherwise (when the argument is `this`), retain the current
   // environment's `ThisPointeeLoc`.
 }
@@ -1083,7 +1083,7 @@ StorageLocation &Environment::createObjectInternal(const 
ValueDecl *D,
 // be null.
 if (InitExpr) {
   if (auto *InitExprLoc = getStorageLocation(*InitExpr))
-  return *InitExprLoc;
+return *InitExprLoc;
 }
 
 // Even though we have an initializer, we might not get an
@@ -1191,9 +1191,7 @@ void Environment::dump(raw_ostream &OS) const {
   DACtx->dumpFlowCondition(FlowConditionToken, OS);
 }
 
-void Environment::dump() const {
-  dump(llvm::dbgs());
-}
+void Environment::dump() const { dump(llvm::dbgs()); }
 
 Environment::PrValueToResultObject Environment::buildResultObjectMap(
 DataflowAnalysisContext *DACtx, const FunctionDecl *FuncDecl,

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


[clang] [clang][dataflow][NFC] Fix code formatting in DataflowEnvironment.cpp (PR #89352)

2024-04-19 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: None (martinboehme)


Changes

For some reason, when I merged #89235, two lines were mis-formatted.

This patch corrects this; while I'm here, I'm also correcting other
existing formatting errors.


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


1 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+6-8) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 6998e6d7a5170b..05395e07a7a68c 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -400,8 +400,8 @@ class ResultObjectVisitor : public 
RecursiveASTVisitor {
   // Fields of non-record type are handled in
   // `TransferVisitor::VisitInitListExpr()`.
   if (Field->getType()->isRecordType())
-PropagateResultObject(Init,
-  
cast(Loc->getChild(*Field)));
+PropagateResultObject(
+Init, cast(Loc->getChild(*Field)));
 }
   }
 
@@ -610,8 +610,8 @@ Environment Environment::pushCall(const CallExpr *Call) 
const {
   if (const auto *MethodCall = dyn_cast(Call)) {
 if (const Expr *Arg = MethodCall->getImplicitObjectArgument()) {
   if (!isa(Arg))
-  Env.ThisPointeeLoc =
-  cast(getStorageLocation(*Arg));
+Env.ThisPointeeLoc =
+cast(getStorageLocation(*Arg));
   // Otherwise (when the argument is `this`), retain the current
   // environment's `ThisPointeeLoc`.
 }
@@ -1083,7 +1083,7 @@ StorageLocation &Environment::createObjectInternal(const 
ValueDecl *D,
 // be null.
 if (InitExpr) {
   if (auto *InitExprLoc = getStorageLocation(*InitExpr))
-  return *InitExprLoc;
+return *InitExprLoc;
 }
 
 // Even though we have an initializer, we might not get an
@@ -1191,9 +1191,7 @@ void Environment::dump(raw_ostream &OS) const {
   DACtx->dumpFlowCondition(FlowConditionToken, OS);
 }
 
-void Environment::dump() const {
-  dump(llvm::dbgs());
-}
+void Environment::dump() const { dump(llvm::dbgs()); }
 
 Environment::PrValueToResultObject Environment::buildResultObjectMap(
 DataflowAnalysisContext *DACtx, const FunctionDecl *FuncDecl,

``




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


[clang] [clang][dataflow][NFC] Fix code formatting in DataflowEnvironment.cpp (PR #89352)

2024-04-19 Thread via cfe-commits

martinboehme wrote:

Merging without review as this is a trivial, formatting-only change that was 
auto-generated by clang-format, and I'd like to expeditiously fix the 
formatting error I made in https://github.com/llvm/llvm-project/pull/89235.

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


[clang] [llvm] [mlir] Fix Definition Mismatches (PR #89294)

2024-04-19 Thread Mehdi Amini via cfe-commits


@@ -433,7 +433,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
   Value *foldAndOrOfICmpsOfAndWithPow2(ICmpInst *LHS, ICmpInst *RHS,
Instruction *CxtI, bool IsAnd,
bool IsLogical = false);
-  Value *matchSelectFromAndOr(Value *A, Value *B, Value *C, Value *D,

joker-eph wrote:

You could fix the warning by using vastly different names for the function 
parameters?

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


[clang] [llvm] [mlir] Fix warning about mismatches between function parameter and call-site args names (PR #89294)

2024-04-19 Thread Mehdi Amini via cfe-commits

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


[clang] [clang][analyzer] Move StreamChecker out of the alpha package. (PR #89247)

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

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/89247

From 7138f026e845ebb4f1a3e6a86bdeb534d666ae7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Thu, 18 Apr 2024 16:40:03 +0200
Subject: [PATCH 1/3] [clang][analyzer] Move StreamChecker out of the alpha
 package.

---
 clang/docs/analyzer/checkers.rst  | 186 +-
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  31 +--
 clang/test/Analysis/analyzer-config.c |   2 +-
 .../test/Analysis/analyzer-enabled-checkers.c |   1 +
 ...c-library-functions-arg-enabled-checkers.c |   6 +-
 .../std-c-library-functions-arg-weakdeps.c|   4 +-
 ...td-c-library-functions-vs-stream-checker.c |   8 +-
 clang/test/Analysis/stream-errno-note.c   |   4 +-
 clang/test/Analysis/stream-errno.c|   4 +-
 clang/test/Analysis/stream-error.c|   4 +-
 clang/test/Analysis/stream-invalidate.c   |   2 +-
 .../test/Analysis/stream-non-posix-function.c |   2 +-
 clang/test/Analysis/stream-noopen.c   |   2 +-
 clang/test/Analysis/stream-note.c |   8 +-
 clang/test/Analysis/stream-pedantic.c |   8 +-
 .../Analysis/stream-stdlibraryfunctionargs.c  |  10 +-
 clang/test/Analysis/stream.c  |  16 +-
 clang/test/Analysis/stream.cpp|   2 +-
 clang/www/analyzer/alpha_checks.html  |   4 +-
 clang/www/analyzer/open_projects.html |   2 +-
 20 files changed, 154 insertions(+), 152 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index fb748d23a53d01..32c2a312962754 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1462,6 +1462,99 @@ checker).
 
 Default value of the option is ``true``.
 
+.. _unix-Stream:
+
+unix.Stream (C)
+"
+Check C stream handling functions:
+``fopen, fdopen, freopen, tmpfile, fclose, fread, fwrite, fgetc, fgets, fputc, 
fputs, fprintf, fscanf, ungetc, getdelim, getline, fseek, fseeko, ftell, 
ftello, fflush, rewind, fgetpos, fsetpos, clearerr, feof, ferror, fileno``.
+
+The checker maintains information about the C stream objects (``FILE *``) and
+can detect error conditions related to use of streams. The following conditions
+are detected:
+
+* The ``FILE *`` pointer passed to the function is NULL (the single exception 
is
+  ``fflush`` where NULL is allowed).
+* Use of stream after close.
+* Opened stream is not closed.
+* Read from a stream after end-of-file. (This is not a fatal error but reported
+  by the checker. Stream remains in EOF state and the read operation fails.)
+* Use of stream when the file position is indeterminate after a previous failed
+  operation. Some functions (like ``ferror``, ``clearerr``, ``fseek``) are
+  allowed in this state.
+* Invalid 3rd ("``whence``") argument to ``fseek``.
+
+The stream operations are by this checker usually split into two cases, a 
success
+and a failure case. However, in the case of write operations (like ``fwrite``,
+``fprintf`` and even ``fsetpos``) this behavior could produce a large amount of
+unwanted reports on projects that don't have error checks around the write
+operations, so by default the checker assumes that write operations always 
succeed.
+This behavior can be controlled by the ``Pedantic`` flag: With
+``-analyzer-config unix.Stream:Pedantic=true`` the checker will model the
+cases where a write operation fails and report situations where this leads to
+erroneous behavior. (The default is ``Pedantic=false``, where write operations
+are assumed to succeed.)
+
+.. code-block:: c
+
+ void test1() {
+   FILE *p = fopen("foo", "r");
+ } // warn: opened file is never closed
+
+ void test2() {
+   FILE *p = fopen("foo", "r");
+   fseek(p, 1, SEEK_SET); // warn: stream pointer might be NULL
+   fclose(p);
+ }
+
+ void test3() {
+   FILE *p = fopen("foo", "r");
+   if (p) {
+ fseek(p, 1, 3); // warn: third arg should be SEEK_SET, SEEK_END, or 
SEEK_CUR
+ fclose(p);
+   }
+ }
+
+ void test4() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fclose(p);
+   fclose(p); // warn: stream already closed
+ }
+
+ void test5() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fgetc(p);
+   if (!ferror(p))
+ fgetc(p); // warn: possible read after end-of-file
+
+   fclose(p);
+ }
+
+ void test6() {
+   FILE *p = fopen("foo", "r");
+   if (!p)
+ return;
+
+   fgetc(p);
+   if (!feof(p))
+ fgetc(p); // warn: file position may be indeterminate after I/O error
+
+   fclose(p);
+ }
+
+**Limitations**
+
+The checker does not track the correspondence between integer file descriptors
+and ``FILE *`` pointers. Operations on standard streams like ``stdin`` are not
+treated specially and are therefore often not recognized (because these streams
+are usually not opened explicitly by the program, and are global variables).
+
 .. _osx-checkers:
 
 osx
@@ -3116,99 +3209,6 @@ Check for misuse

[clang] 1412210 - [clang][dataflow][NFC] Fix code formatting in DataflowEnvironment.cpp (#89352)

2024-04-19 Thread via cfe-commits

Author: martinboehme
Date: 2024-04-19T10:12:57+02:00
New Revision: 14122106320b88f114301bbf8694ceac9bb7a27a

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

LOG: [clang][dataflow][NFC] Fix code formatting in DataflowEnvironment.cpp 
(#89352)

For some reason, when I merged #89235, two lines were mis-formatted.

This patch corrects this; while I'm here, I'm also correcting other
existing formatting errors.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 6998e6d7a5170b..05395e07a7a68c 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -400,8 +400,8 @@ class ResultObjectVisitor : public 
RecursiveASTVisitor {
   // Fields of non-record type are handled in
   // `TransferVisitor::VisitInitListExpr()`.
   if (Field->getType()->isRecordType())
-PropagateResultObject(Init,
-  
cast(Loc->getChild(*Field)));
+PropagateResultObject(
+Init, cast(Loc->getChild(*Field)));
 }
   }
 
@@ -610,8 +610,8 @@ Environment Environment::pushCall(const CallExpr *Call) 
const {
   if (const auto *MethodCall = dyn_cast(Call)) {
 if (const Expr *Arg = MethodCall->getImplicitObjectArgument()) {
   if (!isa(Arg))
-  Env.ThisPointeeLoc =
-  cast(getStorageLocation(*Arg));
+Env.ThisPointeeLoc =
+cast(getStorageLocation(*Arg));
   // Otherwise (when the argument is `this`), retain the current
   // environment's `ThisPointeeLoc`.
 }
@@ -1083,7 +1083,7 @@ StorageLocation &Environment::createObjectInternal(const 
ValueDecl *D,
 // be null.
 if (InitExpr) {
   if (auto *InitExprLoc = getStorageLocation(*InitExpr))
-  return *InitExprLoc;
+return *InitExprLoc;
 }
 
 // Even though we have an initializer, we might not get an
@@ -1191,9 +1191,7 @@ void Environment::dump(raw_ostream &OS) const {
   DACtx->dumpFlowCondition(FlowConditionToken, OS);
 }
 
-void Environment::dump() const {
-  dump(llvm::dbgs());
-}
+void Environment::dump() const { dump(llvm::dbgs()); }
 
 Environment::PrValueToResultObject Environment::buildResultObjectMap(
 DataflowAnalysisContext *DACtx, const FunctionDecl *FuncDecl,



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


[clang] [clang][dataflow][NFC] Fix code formatting in DataflowEnvironment.cpp (PR #89352)

2024-04-19 Thread via cfe-commits

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


[clang] [llvm] [mlir] Fix warning about mismatches between function parameter and call-site args names (PR #89294)

2024-04-19 Thread Nikita Popov via cfe-commits

nikic wrote:

Isn't the warning about a mismatch between declaration and definition, not call 
args? The InstCombine change does make the definition and declaration match.

On Fri, Apr 19, 2024, at 17:07, Mehdi Amini wrote:
> 
> 
> ***@***. commented on this pull request.
> 
> 
> In llvm/lib/Transforms/InstCombine/InstCombineInternal.h 
> :
> 
> > @@ -433,7 +433,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
>Value *foldAndOrOfICmpsOfAndWithPow2(ICmpInst *LHS, ICmpInst *RHS,
> Instruction *CxtI, bool IsAnd,
> bool IsLogical = false);
> -  Value *matchSelectFromAndOr(Value *A, Value *B, Value *C, Value *D,
> 
> You could fix the warning by using vastly different names for the function 
> parameters?
> 
> 
> —
> Reply to this email directly, view it on GitHub 
> , or 
> unsubscribe 
> .
> You are receiving this because your review was requested.Message ID: 
> ***@***.***>
> 

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


[clang] [clang][RISCV] Support RVV bfloat16 C intrinsics (PR #89354)

2024-04-19 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-risc-v

Author: Brandon Wu (4vtomat)


Changes

It follows the interface defined here:
https://github.com/riscv-non-isa/rvv-intrinsic-doc/pull/293


---

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


252 Files Affected:

- (modified) clang/include/clang/Basic/riscv_vector.td (+74-22) 
- (modified) clang/include/clang/Support/RISCVVIntrinsicUtils.h (+2-1) 
- (modified) clang/lib/Sema/SemaRISCVVectorLookup.cpp (+1) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vcreate.c
 (+477) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vfncvtbf16.c
 (+219) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vfwcvtbf16.c
 (+114) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vfwmaccbf16.c
 (+480) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vget.c
 (+333) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vle16.c
 (+132) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vle16ff.c
 (+177) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlmul_ext_v.c
 (+159) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlmul_trunc_v.c
 (+159) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxei16.c
 (+141) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg2ei16.c
 (+121) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg3ei16.c
 (+99) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg4ei16.c
 (+99) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg5ei16.c
 (+77) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg6ei16.c
 (+77) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg7ei16.c
 (+77) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vloxseg8ei16.c
 (+77) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlse16.c
 (+141) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg2e16.c
 (+114) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg2e16ff.c
 (+179) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg3e16.c
 (+93) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg3e16ff.c
 (+161) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg4e16.c
 (+93) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg4e16ff.c
 (+177) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg5e16.c
 (+72) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg5e16ff.c
 (+147) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg6e16.c
 (+72) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg6e16ff.c
 (+159) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg7e16.c
 (+72) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg7e16ff.c
 (+171) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg8e16.c
 (+72) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlseg8e16ff.c
 (+183) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg2e16.c
 (+119) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg3e16.c
 (+97) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg4e16.c
 (+97) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/bfloat16/vlsseg5e16.c
 (+75) 
- (added) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogene

[clang] [llvm] [mlir] Fix warning about mismatches between function parameter and call-site args names (PR #89294)

2024-04-19 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

> Isn't the warning about a mismatch between declaration and definition, not 
> call args? The InstCombine change does make the definition and declaration 
> match.
> […](#)
> On Fri, Apr 19, 2024, at 17:07, Mehdi Amini wrote: ***@***. commented on 
> this pull request. In llvm/lib/Transforms/InstCombine/InstCombineInternal.h 
> <[#89294 
> (comment)](https://github.com/llvm/llvm-project/pull/89294#discussion_r1571996570)>:
>  > @@ -433,7 +433,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final 
> Value *foldAndOrOfICmpsOfAndWithPow2(ICmpInst *LHS, ICmpInst *RHS, 
> Instruction *CxtI, bool IsAnd, bool IsLogical = false); - Value 
> *matchSelectFromAndOr(Value *A, Value *B, Value *C, Value *D, You could fix 
> the warning by using vastly different names for the function parameters? — 
> Reply to this email directly, view it on GitHub <[#89294 
> (comment)](https://github.com/llvm/llvm-project/pull/89294#discussion_r1571996570)>,
>  or unsubscribe 
> .
>  You are receiving this because your review was requested.Message ID: 
> ***@***.***>

Sorry for my misreading. Would be better to add a header comment for the 
declaration of `matchSelectFromAndOr`.


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


[clang] aac695d - [NFC] [Serialization] Use semantical type 'DeclID' for 'CreateDeserialized'

2024-04-19 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-19T16:24:47+08:00
New Revision: aac695da42cf48ccb29c2fe495ead564cc913471

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

LOG: [NFC] [Serialization] Use semantical type 'DeclID' for 'CreateDeserialized'

Previously we use 'unsigned' as the type of ID in 'CreateDeserialized'.

And the type of `DeclID` in serialization is 'uint32_t', so there is
minor inconsistency.

Also more importantly, if we want to extend the type of DeclID from
uint32_t to uint64_t, we may be in trouble due to we forgot updating the
a lot of 'CreateDeserialized'.

So this patch tries to use semantical type 'DeclID' for
'*Decl::CreateDeserialized' to make sure it is tightly consistent.

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/DeclFriend.h
clang/include/clang/AST/DeclObjC.h
clang/include/clang/AST/DeclOpenMP.h
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/Serialization/ASTReader.h
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/DeclFriend.cpp
clang/lib/AST/DeclObjC.cpp
clang/lib/AST/DeclOpenMP.cpp
clang/lib/AST/DeclTemplate.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 0a9c9e17d3f9f9..8b121896d66d15 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -157,7 +157,7 @@ class PragmaCommentDecl final
SourceLocation CommentLoc,
PragmaMSCommentKind CommentKind,
StringRef Arg);
-  static PragmaCommentDecl *CreateDeserialized(ASTContext &C, unsigned ID,
+  static PragmaCommentDecl *CreateDeserialized(ASTContext &C, DeclID ID,
unsigned ArgSize);
 
   PragmaMSCommentKind getCommentKind() const { return CommentKind; }
@@ -192,7 +192,7 @@ class PragmaDetectMismatchDecl final
   SourceLocation Loc, StringRef Name,
   StringRef Value);
   static PragmaDetectMismatchDecl *
-  CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize);
+  CreateDeserialized(ASTContext &C, DeclID ID, unsigned NameValueSize);
 
   StringRef getName() const { return getTrailingObjects(); }
   StringRef getValue() const { return getTrailingObjects() + ValueStart; 
}
@@ -518,7 +518,7 @@ class LabelDecl : public NamedDecl {
   static LabelDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation IdentL, IdentifierInfo *II,
SourceLocation GnuLabelL);
-  static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID);
+  static LabelDecl *CreateDeserialized(ASTContext &C, DeclID ID);
 
   LabelStmt *getStmt() const { return TheStmt; }
   void setStmt(LabelStmt *T) { TheStmt = T; }
@@ -581,7 +581,7 @@ class NamespaceDecl : public NamedDecl, public DeclContext,
IdentifierInfo *Id, NamespaceDecl *PrevDecl,
bool Nested);
 
-  static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
+  static NamespaceDecl *CreateDeserialized(ASTContext &C, DeclID ID);
 
   using redecl_range = redeclarable_base::redecl_range;
   using redecl_iterator = redeclarable_base::redecl_iterator;
@@ -1146,7 +1146,7 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
  const IdentifierInfo *Id, QualType T,
  TypeSourceInfo *TInfo, StorageClass S);
 
-  static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
+  static VarDecl *CreateDeserialized(ASTContext &C, DeclID ID);
 
   SourceRange getSourceRange() const override LLVM_READONLY;
 
@@ -1728,7 +1728,7 @@ class ImplicitParamDecl : public VarDecl {
   static ImplicitParamDecl *Create(ASTContext &C, QualType T,
ImplicitParamKind ParamKind);
 
-  static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
+  static ImplicitParamDecl *CreateDeserialized(ASTContext &C, DeclID ID);
 
   ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc,
 const IdentifierInfo *Id, QualType Type,
@@ -1782,7 +1782,7 @@ class ParmVarDecl : public VarDecl {
  TypeSourceInfo *TInfo, StorageClass S,
  Expr *DefArg);
 
-  static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
+  static ParmVarDecl *CreateDeserialized(ASTContext &C, DeclID ID);
 
   SourceRange getSourceRange() const override LLVM_READONLY;
 
@@ -2178,7 +2178

[clang] [llvm] demangle function names in trace files (PR #87626)

2024-04-19 Thread via cfe-commits

https://github.com/Trass3r updated 
https://github.com/llvm/llvm-project/pull/87626

>From 153bb2fd38b8bb18281bd52c2a21b6e4a75f3fc8 Mon Sep 17 00:00:00 2001
From: Andreas Hollandt 
Date: Tue, 4 Oct 2022 12:05:39 +0200
Subject: [PATCH 1/2] demangle OptFunction trace names

This improves consistency in the trace files as other entries are demangled too.
Fixes #45901.
---
 clang/test/Driver/ftime-trace-sections.py| 11 +++
 llvm/lib/IR/LegacyPassManager.cpp|  4 +++-
 llvm/lib/Passes/CMakeLists.txt   |  1 +
 llvm/lib/Passes/StandardInstrumentations.cpp |  3 ++-
 4 files changed, 17 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 clang/test/Driver/ftime-trace-sections.py

diff --git a/clang/test/Driver/ftime-trace-sections.py 
b/clang/test/Driver/ftime-trace-sections.py
old mode 100644
new mode 100755
index 02afa4ac54eb7b..b332931d29a622
--- a/clang/test/Driver/ftime-trace-sections.py
+++ b/clang/test/Driver/ftime-trace-sections.py
@@ -19,7 +19,10 @@ def is_before(range1, range2):
 
 log_contents = json.loads(sys.stdin.read())
 events = log_contents["traceEvents"]
+
+instants = [event for event in events if event["name"] == 
"InstantiateFunction"]
 codegens = [event for event in events if event["name"] == "CodeGen Function"]
+opts = [event for event in events if event["name"] == "OptFunction"]
 frontends = [event for event in events if event["name"] == "Frontend"]
 backends = [event for event in events if event["name"] == "Backend"]
 
@@ -48,3 +51,11 @@ def is_before(range1, range2):
 ]
 ):
 sys.exit("Not all Frontend section are before all Backend sections!")
+
+# Check that entries for foo exist and are in a demangled form.
+if not any(e for e in instants if "foo" in e["args"]["detail"]):
+sys.exit("Missing Instantiate entry for foo!")
+if not any(e for e in codegens if "foo" in e["args"]["detail"]):
+sys.exit("Missing CodeGen entry for foo!")
+if not any(e for e in opts if "foo" in e["args"]["detail"]):
+sys.exit("Missing Optimize entry for foo!")
diff --git a/llvm/lib/IR/LegacyPassManager.cpp 
b/llvm/lib/IR/LegacyPassManager.cpp
index d361bd9a983912..2d0d696acddfcd 100644
--- a/llvm/lib/IR/LegacyPassManager.cpp
+++ b/llvm/lib/IR/LegacyPassManager.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/ADT/MapVector.h"
+#include "llvm/Demangle/Demangle.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/IR/LLVMContext.h"
@@ -1416,7 +1417,8 @@ bool FPPassManager::runOnFunction(Function &F) {
 
   // Store name outside of loop to avoid redundant calls.
   const StringRef Name = F.getName();
-  llvm::TimeTraceScope FunctionScope("OptFunction", Name);
+  llvm::TimeTraceScope FunctionScope(
+  "OptFunction", [&F]() { return demangle(F.getName().str()); });
 
   for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
 FunctionPass *FP = getContainedPass(Index);
diff --git a/llvm/lib/Passes/CMakeLists.txt b/llvm/lib/Passes/CMakeLists.txt
index 6425f4934b2103..b5224327d79216 100644
--- a/llvm/lib/Passes/CMakeLists.txt
+++ b/llvm/lib/Passes/CMakeLists.txt
@@ -21,6 +21,7 @@ add_llvm_component_library(LLVMPasses
   CodeGen
   Core
   Coroutines
+  Demangle
   HipStdPar
   IPO
   InstCombine
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp 
b/llvm/lib/Passes/StandardInstrumentations.cpp
index c18b462258623d..a54a15603e699a 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -22,6 +22,7 @@
 #include "llvm/CodeGen/MIRPrinter.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/Demangle/Demangle.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/Module.h"
@@ -1576,7 +1577,7 @@ void TimeProfilingPassesHandler::registerCallbacks(
 }
 
 void TimeProfilingPassesHandler::runBeforePass(StringRef PassID, Any IR) {
-  timeTraceProfilerBegin(PassID, getIRName(IR));
+  timeTraceProfilerBegin(PassID, demangle(getIRName(IR)));
 }
 
 void TimeProfilingPassesHandler::runAfterPass() { timeTraceProfilerEnd(); }

>From 5ae3effb583da45200dff2e17c0528baa5e4bcea Mon Sep 17 00:00:00 2001
From: Andreas Hollandt 
Date: Mon, 8 Apr 2024 21:32:24 +0200
Subject: [PATCH 2/2] add demangled parameter to getIRName

---
 llvm/lib/Passes/StandardInstrumentations.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp 
b/llvm/lib/Passes/StandardInstrumentations.cpp
index a54a15603e699a..13c4f38dcf448d 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -235,12 +235,12 @@ void printIR(raw_ostream &OS, const MachineFunction *MF) {
   MF->print(OS);
 }
 
-std::string getIRName(Any IR) {
+std::string getIRName(Any IR, bool demangled = false) {
   if (unwrapIR(IR))
 return "[module]";
 
   if (const auto *F = unwrapIR(IR))

[clang] [clang][RISCV] Support RVV bfloat16 C intrinsics (PR #89354)

2024-04-19 Thread Kito Cheng via cfe-commits

kito-cheng wrote:

vfncvtbf16.c, vfwcvtbf16.c and vfwmaccbf16.c already in the LLVM repo, so I 
think those files could removed from this PR?

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


[clang] [clang][RISCV] Support RVV bfloat16 C intrinsics (PR #89354)

2024-04-19 Thread Brandon Wu via cfe-commits

4vtomat wrote:

Oh, I forgot to remove them. Or do you think they should be moved to bfloat 
folder to make them consistent?

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


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

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

https://github.com/budimirarandjelovicsyrmia updated 
https://github.com/llvm/llvm-project/pull/70024

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

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/Sema/SemaChecking.cpp   |   4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 119 ++-
 clang/test/Sema/attr-format-missing.c | 272 
 clang/test/Sema/attr-format-missing.cpp   | 303 ++
 8 files changed, 704 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6c51c2d1f483ce..8cda4d62eabcbb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -366,6 +366,9 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses requires expressions with explicit object parameters.
 
+- Clang now diagnoses missing format attributes for non-template functions and
+  class/struct/union members. Fixes #GH70024
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 5251774ff4efd6..0dadc5526344e1 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -505,7 +505,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 30a8543489f48e..043214dc2400c8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1008,6 +1008,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1e89dfc58d92b1..82f93c572a2b29 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3724,6 +3724,10 @@ class Sema final : public SemaBase {
   bool DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc,
  const ParsedAttr &AL, bool IsAsync);
 
+  void DiagnoseMissingFormatAttributes(const FunctionDecl *FDecl,
+   ArrayRef Args,
+   SourceLocation Loc);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 6778bc6607f75e..32f1b564247f32 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -8040,8 +8040,10 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
-  if (FD)
+  if (FD) {
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
+DiagnoseMissingFormatAttributes(FD, Args, Range.getBegin());
+  }
 }
 
 /// CheckConstructorCall - Check a constructor call for correctness and safety
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index c3bf18a3f79e23..89cb6bd15a8b4f 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -163,6 +163,13 @@ static bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+static bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 static inline bool isNSStringType(QualType T, ASTContext &Ctx,
   bool AllowNSAttributedString = false) {
   const auto *PT = T->getAs();
@@ -312,7 +319,7 @@ static bool c

[clang] [llvm] [mlir] Fix warning about mismatches between function parameter and call-site args names (PR #89294)

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

steakhal wrote:

`StaticAnalyzer` changes LGTM.

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


[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

2024-04-19 Thread via cfe-commits

https://github.com/guillem-bartina-sonarsource edited 
https://github.com/llvm/llvm-project/pull/84515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix stores through label locations (PR #89265)

2024-04-19 Thread via cfe-commits


@@ -2358,11 +2358,12 @@ StoreRef RegionStoreManager::killBinding(Store ST, Loc 
L) {
 
 RegionBindingsRef
 RegionStoreManager::bind(RegionBindingsConstRef B, Loc L, SVal V) {
-  if (L.getAs())
+  // We only care about region locations.
+  auto MemRegVal = L.getAs();
+  if (!MemRegVal.has_value())

NagyDonat wrote:

Personal style preference: In this context I would omit the `.has_value()` 
method because it doesn't add meaningful information. (If I wanted to emphasize 
that this is an `optional` and not a pointer; I would've declared the type 
explicitly instead of using `auto`. However, here the pointer/`optional` 
difference is irrelevant for this short-lived temporary variable.)

Of course this is just subjective bikeshedding, no action required.

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


[clang] [analyzer] Fix stores through label locations (PR #89265)

2024-04-19 Thread via cfe-commits

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


[clang] [analyzer] Fix stores through label locations (PR #89265)

2024-04-19 Thread via cfe-commits

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

LGTM nice quickfix :)

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


[clang] Improve documented sampling profiler steps to best known methods (PR #88438)

2024-04-19 Thread Wei Xiao via cfe-commits


@@ -2443,27 +2443,29 @@ usual build cycle when using sample profilers for 
optimization:
usual build flags that you always build your application with. The only
requirement is that DWARF debug info including source line information is
generated. This DWARF information is important for the profiler to be able
-   to map instructions back to source line locations.
+   to map instructions back to source line locations. The usefulness of this
+   DWARF information can be improved with the ``-fdebug-info-for-profiling``
+   and ``-funique-internal-linkage-names`` options.

williamweixiao wrote:

do we also need  ``-fdebug-info-for-profiling`` and 
``-funique-internal-linkage-names`` for step 4 
("-fprofile-sample-use=code.prof") ?

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

2024-04-19 Thread Haojian Wu via cfe-commits

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

Fixes https://github.com/llvm/llvm-project/issues/85192
Fixes https://github.com/llvm/llvm-project/issues/84492

This patch implements the "IsDeducible" constraint where the template arguments 
of the alias template can be deduced from the returned type of the synthesized 
deduction guide, per C++ [over.match.class.deduct]p4. In the implementation, we 
perform the deduction directly, which is more efficient than the way specified 
in the standard.

In this patch, we add a `__is_deducible` builtin type trait, it is useful for 
ad-hoc debugging, and testing.

Also update relevant CTAD tests which were incorrectly compiled due to the 
missing constraint.




>From 19a50f5cfb67d23f979cf94c5518f41af921468e Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 19 Apr 2024 10:54:12 +0200
Subject: [PATCH] [clang] CTAD: implement the missing IsDeducible constraint
 for alias templates.

Fixes https://github.com/llvm/llvm-project/issues/85192
Fixes https://github.com/llvm/llvm-project/issues/84492
---
 clang/include/clang/Basic/TokenKinds.def  |  1 +
 clang/include/clang/Sema/Sema.h   |  9 ++
 clang/lib/Parse/ParseExprCXX.cpp  | 16 ++--
 clang/lib/Sema/SemaExprCXX.cpp| 11 +++
 clang/lib/Sema/SemaTemplate.cpp   | 83 +-
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 87 +++
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  | 26 --
 .../test/SemaCXX/type-traits-is-deducible.cpp | 47 ++
 clang/www/cxx_status.html |  8 +-
 9 files changed, 243 insertions(+), 45 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-traits-is-deducible.cpp

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index a27fbed358a60c..74102f40539681 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -537,6 +537,7 @@ TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
 TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
+TYPE_TRAIT_2(__is_deducible, IsDeducible, KEYCXX)
 
 // Embarcadero Expression Traits
 EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1e89dfc58d92b1..0d8477cf49aaf0 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9591,6 +9591,15 @@ class Sema final : public SemaBase {
   ArrayRef TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  /// Deduce the template arguments of the given template from \p FromType.
+  /// Used to implement the IsDeducible constraint for alias CTAD per C++
+  /// [over.match.class.deduct]p4.
+  ///
+  /// It only supports class or type alias templates.
+  TemplateDeductionResult
+  DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType,
+  sema::TemplateDeductionInfo &Info);
+
   TemplateDeductionResult DeduceTemplateArguments(
   TemplateParameterList *TemplateParams, ArrayRef Ps,
   ArrayRef As, sema::TemplateDeductionInfo &Info,
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 0d2ad980696fcc..af4e205eeff803 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3906,14 +3906,18 @@ ExprResult Parser::ParseTypeTrait() {
   BalancedDelimiterTracker Parens(*this, tok::l_paren);
   if (Parens.expectAndConsume())
 return ExprError();
-
+  TypeTrait TTKind = TypeTraitFromTokKind(Kind);
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName(/*SourceRange=*/nullptr,
-  getLangOpts().CPlusPlus
-  ? DeclaratorContext::TemplateTypeArg
-  : DeclaratorContext::TypeName);
+TypeResult Ty = ParseTypeName(
+/*SourceRange=*/nullptr,
+getLangOpts().CPlusPlus
+// For __is_deducible type trait, the first argument is a template
+// specification type without template argument lists.
+? (TTKind == BTT_IsDeducible ? DeclaratorContext::TemplateArg
+ : DeclaratorContext::TemplateTypeArg)
+: DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3937,7 +3941,7 @@ ExprResult Parser::ParseTypeTrait() {
 
   SourceLocation EndLoc = Parens.getCloseLocation();
 
-  return Actions.ActOnTypeTrait(TypeTraitFromTokKind(Kind), Loc, Args, EndLoc);
+  return Actions.ActOnTypeTrait(TTKind, Loc, Args, EndLoc);
 }
 
 /// ParseArrayTypeTrait - Parse t

[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

2024-04-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

Fixes https://github.com/llvm/llvm-project/issues/85192
Fixes https://github.com/llvm/llvm-project/issues/84492

This patch implements the "IsDeducible" constraint where the template arguments 
of the alias template can be deduced from the returned type of the synthesized 
deduction guide, per C++ [over.match.class.deduct]p4. In the implementation, we 
perform the deduction directly, which is more efficient than the way specified 
in the standard.

In this patch, we add a `__is_deducible` builtin type trait, it is useful for 
ad-hoc debugging, and testing.

Also update relevant CTAD tests which were incorrectly compiled due to the 
missing constraint.




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


9 Files Affected:

- (modified) clang/include/clang/Basic/TokenKinds.def (+1) 
- (modified) clang/include/clang/Sema/Sema.h (+9) 
- (modified) clang/lib/Parse/ParseExprCXX.cpp (+10-6) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+11) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+60-23) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+87) 
- (modified) clang/test/SemaCXX/cxx20-ctad-type-alias.cpp (+17-9) 
- (added) clang/test/SemaCXX/type-traits-is-deducible.cpp (+47) 
- (modified) clang/www/cxx_status.html (+1-7) 


``diff
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index a27fbed358a60c..74102f40539681 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -537,6 +537,7 @@ TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
 TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
+TYPE_TRAIT_2(__is_deducible, IsDeducible, KEYCXX)
 
 // Embarcadero Expression Traits
 EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1e89dfc58d92b1..0d8477cf49aaf0 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9591,6 +9591,15 @@ class Sema final : public SemaBase {
   ArrayRef TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  /// Deduce the template arguments of the given template from \p FromType.
+  /// Used to implement the IsDeducible constraint for alias CTAD per C++
+  /// [over.match.class.deduct]p4.
+  ///
+  /// It only supports class or type alias templates.
+  TemplateDeductionResult
+  DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType,
+  sema::TemplateDeductionInfo &Info);
+
   TemplateDeductionResult DeduceTemplateArguments(
   TemplateParameterList *TemplateParams, ArrayRef Ps,
   ArrayRef As, sema::TemplateDeductionInfo &Info,
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 0d2ad980696fcc..af4e205eeff803 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3906,14 +3906,18 @@ ExprResult Parser::ParseTypeTrait() {
   BalancedDelimiterTracker Parens(*this, tok::l_paren);
   if (Parens.expectAndConsume())
 return ExprError();
-
+  TypeTrait TTKind = TypeTraitFromTokKind(Kind);
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName(/*SourceRange=*/nullptr,
-  getLangOpts().CPlusPlus
-  ? DeclaratorContext::TemplateTypeArg
-  : DeclaratorContext::TypeName);
+TypeResult Ty = ParseTypeName(
+/*SourceRange=*/nullptr,
+getLangOpts().CPlusPlus
+// For __is_deducible type trait, the first argument is a template
+// specification type without template argument lists.
+? (TTKind == BTT_IsDeducible ? DeclaratorContext::TemplateArg
+ : DeclaratorContext::TemplateTypeArg)
+: DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3937,7 +3941,7 @@ ExprResult Parser::ParseTypeTrait() {
 
   SourceLocation EndLoc = Parens.getCloseLocation();
 
-  return Actions.ActOnTypeTrait(TypeTraitFromTokKind(Kind), Loc, Args, EndLoc);
+  return Actions.ActOnTypeTrait(TTKind, Loc, Args, EndLoc);
 }
 
 /// ParseArrayTypeTrait - Parse the built-in array type-trait
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 7582cbd75fec05..0833a985b48b88 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6100,6 +6100,17 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
   tok::kw___is_pointer_interc

[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu (PR #89359)

2024-04-19 Thread via cfe-commits

https://github.com/Khao7342 created 
https://github.com/llvm/llvm-project/pull/89359

This pull request adds definitions for the XiangShan-KunMingHu processor. 
"XiangShan" is a high-performance open-source RISC-V processor project, and 
"KunMingHu" architecture is its third generation. Official documentation can be 
found at: [documentation](https://xiangshan-doc.readthedocs.io/zh-cn/latest/).

Currently, the KunMingHu core 
supports"RV64IMAFDCV_zba_zbb_zbc_zbs_zbkb_zbkc_zbkx_zknd_zkne_zknh_zksed_zksh_svinval_zicbom_zicboz_zicsr_zifencei".
 The scheduler model and other components will be submitted in subsequent 
patches.

>From e51498e67409836b099fa892b17d71e44a7d403b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=83=9D=E5=BA=B7=E8=BE=BE?= 
Date: Fri, 19 Apr 2024 17:18:10 +0800
Subject: [PATCH] [RISCV] Add processor definition for XiangShan-KunMingHu

This pull request adds definitions for the XiangShan-KunMingHu processor. 
"XiangShan" is a high-performance open-source RISC-V processor project, and 
"KunMingHu" architecture is its third generation. Official documentation can be 
found at: [documentation](https://xiangshan-doc.readthedocs.io/zh-cn/latest/).

Currently, the KunMingHu core 
supports"RV64IMAFDCV_zba_zbb_zbc_zbs_zbkb_zbkc_zbkx_zknd_zkne_zknh_zksed_zksh_svinval_zicbom_zicboz_zicsr_zifencei".
 The scheduler model and other components will be submitted in subsequent 
patches.

Co-Authored-By: Bhe6669 <167076958+bhe6...@users.noreply.github.com>
Co-Authored-By: huxuan0307 <39661208+huxuan0...@users.noreply.github.com>
---
 clang/test/Driver/riscv-cpus.c| 36 +++
 clang/test/Misc/target-invalid-cpu-note.c |  4 +--
 llvm/lib/Target/RISCV/RISCVProcessors.td  | 27 +
 3 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index ff2bd6f7c8ba34..be13c17df04742 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -31,6 +31,39 @@
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+zks" "-target-feature" 
"+zksed" "-target-feature" "+zksh" "-target-feature" "+svinval"
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-abi" "lp64d"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=xiangshan-kunminghu | 
FileCheck -check-prefix=MCPU-XIANGSHAN-KUNMINGHU %s
+// MCPU-XIANGSHAN-KUNMINGHU: "-nostdsysteminc" "-target-cpu" 
"xiangshan-kunminghu"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+m"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+a"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+d"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+c"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+v"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicbom" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicboz" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicsr" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zifencei"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zba" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbc"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkc" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkx" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbs"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zkn" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zknd" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zkne" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zknh"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve32f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve32x"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64d"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64x"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl128b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl32b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl64b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-abi" "lp64d"
+
 // We cannot check much for -mcpu=native, but it should be replaced by a valid 
CPU string.
 // RUN: %clang --target=riscv64 -### -c %s -mcpu=native 2> %t.err || true
 // RUN: FileCheck --input-file=%t.err -check-prefix=MCPU-NATIVE %s
@@ -76,6 +109,9 @@
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=xiangshan-nanhu | 
FileCheck -check-prefix=MTUNE-XIANGSHAN-NANHU %s
 // MTUNE-XIANGSHAN-NANHU: "-tune-cpu" "xiangshan-nanhu"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=xiangshan-kunminghu | 
FileCheck -check-prefix=MTUNE-XIANGSHAN-KUNMINGHU %s
+// MTUNE-XIANGSHAN-KUNMINGHU: "-tune-cpu" "xiangshan-kunminghu"
+
 // Check mtune alias CPU has resolved to the right CPU according XLEN.
 // RUN: %clang --target=

[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu (PR #89359)

2024-04-19 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu (PR #89359)

2024-04-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: None (Khao7342)


Changes

This pull request adds definitions for the XiangShan-KunMingHu processor. 
"XiangShan" is a high-performance open-source RISC-V processor project, and 
"KunMingHu" architecture is its third generation. Official documentation can be 
found at: [documentation](https://xiangshan-doc.readthedocs.io/zh-cn/latest/).

Currently, the KunMingHu core 
supports"RV64IMAFDCV_zba_zbb_zbc_zbs_zbkb_zbkc_zbkx_zknd_zkne_zknh_zksed_zksh_svinval_zicbom_zicboz_zicsr_zifencei".
 The scheduler model and other components will be submitted in subsequent 
patches.

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


3 Files Affected:

- (modified) clang/test/Driver/riscv-cpus.c (+36) 
- (modified) clang/test/Misc/target-invalid-cpu-note.c (+2-2) 
- (modified) llvm/lib/Target/RISCV/RISCVProcessors.td (+27) 


``diff
diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index ff2bd6f7c8ba34..be13c17df04742 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -31,6 +31,39 @@
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+zks" "-target-feature" 
"+zksed" "-target-feature" "+zksh" "-target-feature" "+svinval"
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-abi" "lp64d"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=xiangshan-kunminghu | 
FileCheck -check-prefix=MCPU-XIANGSHAN-KUNMINGHU %s
+// MCPU-XIANGSHAN-KUNMINGHU: "-nostdsysteminc" "-target-cpu" 
"xiangshan-kunminghu"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+m"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+a"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+d"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+c"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+v"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicbom" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicboz" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicsr" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zifencei"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zba" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbc"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkc" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkx" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbs"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zkn" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zknd" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zkne" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zknh"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve32f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve32x"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64d"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64x"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl128b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl32b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl64b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-abi" "lp64d"
+
 // We cannot check much for -mcpu=native, but it should be replaced by a valid 
CPU string.
 // RUN: %clang --target=riscv64 -### -c %s -mcpu=native 2> %t.err || true
 // RUN: FileCheck --input-file=%t.err -check-prefix=MCPU-NATIVE %s
@@ -76,6 +109,9 @@
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=xiangshan-nanhu | 
FileCheck -check-prefix=MTUNE-XIANGSHAN-NANHU %s
 // MTUNE-XIANGSHAN-NANHU: "-tune-cpu" "xiangshan-nanhu"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=xiangshan-kunminghu | 
FileCheck -check-prefix=MTUNE-XIANGSHAN-KUNMINGHU %s
+// MTUNE-XIANGSHAN-KUNMINGHU: "-tune-cpu" "xiangshan-kunminghu"
+
 // Check mtune alias CPU has resolved to the right CPU according XLEN.
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=generic | FileCheck 
-check-prefix=MTUNE-GENERIC-32 %s
 // MTUNE-GENERIC-32: "-tune-cpu" "generic"
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 9c91c4157cd6a0..349785fed7dc72 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -85,7 +85,7 @@
 
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
-// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450, sifive-p670, sifive-s21, sifive-s51, sifive-s54, sifive-s76, 
sifive-u54, sifive-u74, sifive-x280, veyron-v1, xiangshan-nanhu{{$}}
+// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450

[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu (PR #89359)

2024-04-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: None (Khao7342)


Changes

This pull request adds definitions for the XiangShan-KunMingHu processor. 
"XiangShan" is a high-performance open-source RISC-V processor project, and 
"KunMingHu" architecture is its third generation. Official documentation can be 
found at: [documentation](https://xiangshan-doc.readthedocs.io/zh-cn/latest/).

Currently, the KunMingHu core 
supports"RV64IMAFDCV_zba_zbb_zbc_zbs_zbkb_zbkc_zbkx_zknd_zkne_zknh_zksed_zksh_svinval_zicbom_zicboz_zicsr_zifencei".
 The scheduler model and other components will be submitted in subsequent 
patches.

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


3 Files Affected:

- (modified) clang/test/Driver/riscv-cpus.c (+36) 
- (modified) clang/test/Misc/target-invalid-cpu-note.c (+2-2) 
- (modified) llvm/lib/Target/RISCV/RISCVProcessors.td (+27) 


``diff
diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index ff2bd6f7c8ba34..be13c17df04742 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -31,6 +31,39 @@
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+zks" "-target-feature" 
"+zksed" "-target-feature" "+zksh" "-target-feature" "+svinval"
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-abi" "lp64d"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=xiangshan-kunminghu | 
FileCheck -check-prefix=MCPU-XIANGSHAN-KUNMINGHU %s
+// MCPU-XIANGSHAN-KUNMINGHU: "-nostdsysteminc" "-target-cpu" 
"xiangshan-kunminghu"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+m"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+a"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+d"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+c"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+v"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicbom" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicboz" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicsr" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zifencei"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zba" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbc"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkc" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkx" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbs"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zkn" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zknd" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zkne" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zknh"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve32f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve32x"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64d"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64x"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl128b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl32b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl64b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-abi" "lp64d"
+
 // We cannot check much for -mcpu=native, but it should be replaced by a valid 
CPU string.
 // RUN: %clang --target=riscv64 -### -c %s -mcpu=native 2> %t.err || true
 // RUN: FileCheck --input-file=%t.err -check-prefix=MCPU-NATIVE %s
@@ -76,6 +109,9 @@
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=xiangshan-nanhu | 
FileCheck -check-prefix=MTUNE-XIANGSHAN-NANHU %s
 // MTUNE-XIANGSHAN-NANHU: "-tune-cpu" "xiangshan-nanhu"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=xiangshan-kunminghu | 
FileCheck -check-prefix=MTUNE-XIANGSHAN-KUNMINGHU %s
+// MTUNE-XIANGSHAN-KUNMINGHU: "-tune-cpu" "xiangshan-kunminghu"
+
 // Check mtune alias CPU has resolved to the right CPU according XLEN.
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=generic | FileCheck 
-check-prefix=MTUNE-GENERIC-32 %s
 // MTUNE-GENERIC-32: "-tune-cpu" "generic"
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 9c91c4157cd6a0..349785fed7dc72 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -85,7 +85,7 @@
 
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
-// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450, sifive-p670, sifive-s21, sifive-s51, sifive-s54, sifive-s76, 
sifive-u54, sifive-u74, sifive-x280, veyron-v1, xiangshan-nanhu{{$}}
+// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450, 

[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)

2024-04-19 Thread Haojian Wu via cfe-commits

hokein wrote:

Regarding the __is_deducible type trait, GCC also provides one, but it was 
hidden from users and only used for internal CTAD implementation. I'm not sure 
if we should follow the same strategy in clang, ideas? 

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


[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu (PR #89359)

2024-04-19 Thread Pengcheng Wang via cfe-commits

wangpc-pp wrote:

Has KunMingHu's RTl been finalized (IIRC, we have developing vector unit)? And 
can we have different doc for different generations of XiangShan?

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


[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)

2024-04-19 Thread Krishna Narayanan via cfe-commits

https://github.com/Krishna-13-cyber created 
https://github.com/llvm/llvm-project/pull/89362

Addresses #53079 

>From 4e649d105a2af038e6dbd0e93b457eebea2e543a Mon Sep 17 00:00:00 2001
From: Krishna-13-cyber 
Date: Fri, 19 Apr 2024 15:09:26 +0530
Subject: [PATCH] Add optimised LLVM IR for atomic increments/decrements on
 floats

---
 clang/lib/CodeGen/CGExprScalar.cpp|  13 +
 clang/test/CodeGen/X86/x86-atomic-float.c |  97 +++
 .../test/CodeGen/X86/x86-atomic-long_double.c | 609 +-
 3 files changed, 410 insertions(+), 309 deletions(-)
 create mode 100644 clang/test/CodeGen/X86/x86-atomic-float.c

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 1f18e0d5ba409a..e97bb5c7e9dd16 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2792,6 +2792,19 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const 
UnaryOperator *E, LValue LV,
   
llvm::AtomicOrdering::SequentiallyConsistent);
   return isPre ? Builder.CreateBinOp(op, old, amt) : old;
 }
+// Special case for atomic increment/decrement on floats
+if (type->isFloatingType()) {
+  llvm::AtomicRMWInst::BinOp aop =
+  isInc ? llvm::AtomicRMWInst::FAdd : llvm::AtomicRMWInst::FSub;
+  llvm::Instruction::BinaryOps op =
+  isInc ? llvm::Instruction::FAdd : llvm::Instruction::FSub;
+  llvm::Value *amt = llvm::ConstantFP::get(
+  VMContext, llvm::APFloat(static_cast(amount)));
+  llvm::Value *old =
+  Builder.CreateAtomicRMW(aop, LV.getAddress(CGF), amt,
+  
llvm::AtomicOrdering::SequentiallyConsistent);
+  return isPre ? Builder.CreateBinOp(op, old, amt) : old;
+}
 value = EmitLoadOfLValue(LV, E->getExprLoc());
 input = value;
 // For every other atomic operation, we need to emit a load-op-cmpxchg loop
diff --git a/clang/test/CodeGen/X86/x86-atomic-float.c 
b/clang/test/CodeGen/X86/x86-atomic-float.c
new file mode 100644
index 00..89a2605ed44461
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86-atomic-float.c
@@ -0,0 +1,97 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -target-cpu core2 %s -S -emit-llvm 
-o - | FileCheck %s
+// RUN: %clang_cc1 -triple i686-linux-gnu -target-cpu core2 %s -S -emit-llvm 
-o - | FileCheck -check-prefix=CHECK32 %s
+
+// CHECK-LABEL: define dso_local i32 @test_int_inc(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 
seq_cst, align 4
+// CHECK-NEXT:ret i32 [[TMP0]]
+//
+// CHECK32-LABEL: define dso_local i32 @test_int_inc(
+// CHECK32-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK32-NEXT:  entry:
+// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 
seq_cst, align 4
+// CHECK32-NEXT:ret i32 [[TMP0]]
+//
+int test_int_inc()
+{
+static _Atomic int n;
+return n++;
+}
+
+// CHECK-LABEL: define dso_local float @test_float_post_inc(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, 
float 1.00e+00 seq_cst, align 4
+// CHECK-NEXT:ret float [[TMP0]]
+//
+// CHECK32-LABEL: define dso_local float @test_float_post_inc(
+// CHECK32-SAME: ) #[[ATTR0]] {
+// CHECK32-NEXT:  entry:
+// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, 
float 1.00e+00 seq_cst, align 4
+// CHECK32-NEXT:ret float [[TMP0]]
+//
+float test_float_post_inc()
+{
+static _Atomic float n;
+return n++;
+}
+
+// CHECK-LABEL: define dso_local float @test_float_post_dc(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, 
float -1.00e+00 seq_cst, align 4
+// CHECK-NEXT:ret float [[TMP0]]
+//
+// CHECK32-LABEL: define dso_local float @test_float_post_dc(
+// CHECK32-SAME: ) #[[ATTR0]] {
+// CHECK32-NEXT:  entry:
+// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, 
float -1.00e+00 seq_cst, align 4
+// CHECK32-NEXT:ret float [[TMP0]]
+//
+float test_float_post_dc()
+{
+static _Atomic float n;
+return n--;
+}
+
+// CHECK-LABEL: define dso_local float @test_float_pre_dc(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, 
float -1.00e+00 seq_cst, align 4
+// CHECK-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00
+// CHECK-NEXT:ret float [[TMP1]]
+//
+// CHECK32-LABEL: define dso_local float @test_float_pre_dc(
+// CHECK32-SAME: ) #[[ATTR0]] {
+// CHECK32-NEXT:  entry:
+// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, 
float -1.00e+00 seq_cst, align 4
+// CHECK32-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00
+// CH

[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)

2024-04-19 Thread Krishna Narayanan via cfe-commits

https://github.com/Krishna-13-cyber converted_to_draft 
https://github.com/llvm/llvm-project/pull/89362
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][CodeGen] Optimised LLVM IR for atomic increments/decrements on floats (PR #89362)

2024-04-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krishna Narayanan (Krishna-13-cyber)


Changes

Addresses #53079 

---

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+13) 
- (added) clang/test/CodeGen/X86/x86-atomic-float.c (+97) 
- (modified) clang/test/CodeGen/X86/x86-atomic-long_double.c (+300-309) 


``diff
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 1f18e0d5ba409a..e97bb5c7e9dd16 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2792,6 +2792,19 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const 
UnaryOperator *E, LValue LV,
   
llvm::AtomicOrdering::SequentiallyConsistent);
   return isPre ? Builder.CreateBinOp(op, old, amt) : old;
 }
+// Special case for atomic increment/decrement on floats
+if (type->isFloatingType()) {
+  llvm::AtomicRMWInst::BinOp aop =
+  isInc ? llvm::AtomicRMWInst::FAdd : llvm::AtomicRMWInst::FSub;
+  llvm::Instruction::BinaryOps op =
+  isInc ? llvm::Instruction::FAdd : llvm::Instruction::FSub;
+  llvm::Value *amt = llvm::ConstantFP::get(
+  VMContext, llvm::APFloat(static_cast(amount)));
+  llvm::Value *old =
+  Builder.CreateAtomicRMW(aop, LV.getAddress(CGF), amt,
+  
llvm::AtomicOrdering::SequentiallyConsistent);
+  return isPre ? Builder.CreateBinOp(op, old, amt) : old;
+}
 value = EmitLoadOfLValue(LV, E->getExprLoc());
 input = value;
 // For every other atomic operation, we need to emit a load-op-cmpxchg loop
diff --git a/clang/test/CodeGen/X86/x86-atomic-float.c 
b/clang/test/CodeGen/X86/x86-atomic-float.c
new file mode 100644
index 00..89a2605ed44461
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86-atomic-float.c
@@ -0,0 +1,97 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -target-cpu core2 %s -S -emit-llvm 
-o - | FileCheck %s
+// RUN: %clang_cc1 -triple i686-linux-gnu -target-cpu core2 %s -S -emit-llvm 
-o - | FileCheck -check-prefix=CHECK32 %s
+
+// CHECK-LABEL: define dso_local i32 @test_int_inc(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 
seq_cst, align 4
+// CHECK-NEXT:ret i32 [[TMP0]]
+//
+// CHECK32-LABEL: define dso_local i32 @test_int_inc(
+// CHECK32-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK32-NEXT:  entry:
+// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw add ptr @test_int_inc.n, i32 1 
seq_cst, align 4
+// CHECK32-NEXT:ret i32 [[TMP0]]
+//
+int test_int_inc()
+{
+static _Atomic int n;
+return n++;
+}
+
+// CHECK-LABEL: define dso_local float @test_float_post_inc(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, 
float 1.00e+00 seq_cst, align 4
+// CHECK-NEXT:ret float [[TMP0]]
+//
+// CHECK32-LABEL: define dso_local float @test_float_post_inc(
+// CHECK32-SAME: ) #[[ATTR0]] {
+// CHECK32-NEXT:  entry:
+// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fadd ptr @test_float_post_inc.n, 
float 1.00e+00 seq_cst, align 4
+// CHECK32-NEXT:ret float [[TMP0]]
+//
+float test_float_post_inc()
+{
+static _Atomic float n;
+return n++;
+}
+
+// CHECK-LABEL: define dso_local float @test_float_post_dc(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, 
float -1.00e+00 seq_cst, align 4
+// CHECK-NEXT:ret float [[TMP0]]
+//
+// CHECK32-LABEL: define dso_local float @test_float_post_dc(
+// CHECK32-SAME: ) #[[ATTR0]] {
+// CHECK32-NEXT:  entry:
+// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_post_dc.n, 
float -1.00e+00 seq_cst, align 4
+// CHECK32-NEXT:ret float [[TMP0]]
+//
+float test_float_post_dc()
+{
+static _Atomic float n;
+return n--;
+}
+
+// CHECK-LABEL: define dso_local float @test_float_pre_dc(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, 
float -1.00e+00 seq_cst, align 4
+// CHECK-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00
+// CHECK-NEXT:ret float [[TMP1]]
+//
+// CHECK32-LABEL: define dso_local float @test_float_pre_dc(
+// CHECK32-SAME: ) #[[ATTR0]] {
+// CHECK32-NEXT:  entry:
+// CHECK32-NEXT:[[TMP0:%.*]] = atomicrmw fsub ptr @test_float_pre_dc.n, 
float -1.00e+00 seq_cst, align 4
+// CHECK32-NEXT:[[TMP1:%.*]] = fsub float [[TMP0]], -1.00e+00
+// CHECK32-NEXT:ret float [[TMP1]]
+//
+float test_float_pre_dc()
+{
+static _Atomic float n;
+return --n;
+}
+
+// CHECK-LABEL: define dso_local float @test_f

[clang] [clang][analyzer] Move StreamChecker out of the alpha package. (PR #89247)

2024-04-19 Thread via cfe-commits
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 



@@ -910,8 +910,8 @@ Unix Alpha Checkers
 
 
 
-
-alpha.unix.Stream
+
+unix.Stream

NagyDonat wrote:

Remove it from this file entirely.

In fact, I strongly suspect that the entire HTML documentation is obsolete and 
it should be deleted from the project (to avoid redundancy). I'm planning to 
review its contents in the foreseeable future and open a discussion if it's 
indeed superfluous, but until then let's do the bare minimum to update it.

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


[clang] [clang][analyzer] Move StreamChecker out of the alpha package. (PR #89247)

2024-04-19 Thread via cfe-commits
=?utf-8?q?Bal=C3=A1zs_K=C3=A9ri?= ,
=?utf-8?q?Bal=C3=A1zs_K=C3=A9ri?= 
Message-ID:
In-Reply-To: 



@@ -48,7 +48,7 @@ Open Projects
   (Difficulty: Medium)
   
 
-  alpha.unix.StreamChecker
+  unix.StreamChecker

NagyDonat wrote:

Yes, remove it from here.

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


[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-04-19 Thread via cfe-commits

https://github.com/NorthBlue333 updated 
https://github.com/llvm/llvm-project/pull/77456

>From 6c184f9714c94af94c7692e1264061b8dc14e912 Mon Sep 17 00:00:00 2001
From: NorthBlue333 
Date: Tue, 9 Jan 2024 14:01:14 +0100
Subject: [PATCH] [clang-format] Do not update cursor pos if no includes
 replacement

Signed-off-by: NorthBlue333 
---
 clang/lib/Format/Format.cpp |   3 +
 clang/unittests/Format/SortIncludesTest.cpp | 119 +++-
 2 files changed, 119 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 46ed5baaeacead..e12ad2ced38285 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3114,6 +3114,7 @@ static void sortCppIncludes(const FormatStyle &Style,
 return;
   }
 
+  const auto OldCursor = Cursor ? *Cursor : 0;
   std::string result;
   for (unsigned Index : Indices) {
 if (!result.empty()) {
@@ -3137,6 +3138,8 @@ static void sortCppIncludes(const FormatStyle &Style,
   // the entire range of blocks. Otherwise, no replacement is generated.
   if (replaceCRLF(result) == replaceCRLF(std::string(Code.substr(
  IncludesBeginOffset, IncludesBlockSize {
+if (Cursor)
+*Cursor = OldCursor;
 return;
   }
 
diff --git a/clang/unittests/Format/SortIncludesTest.cpp 
b/clang/unittests/Format/SortIncludesTest.cpp
index 772eb53806b4b1..791ab7bb185ed9 100644
--- a/clang/unittests/Format/SortIncludesTest.cpp
+++ b/clang/unittests/Format/SortIncludesTest.cpp
@@ -6,19 +6,19 @@
 //
 
//===--===//
 
-#include "FormatTestUtils.h"
+#include "FormatTestBase.h"
 #include "clang/Format/Format.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "gtest/gtest.h"
 
-#define DEBUG_TYPE "format-test"
+#define DEBUG_TYPE "sort-includes-test"
 
 namespace clang {
 namespace format {
 namespace {
 
-class SortIncludesTest : public ::testing::Test {
+class SortIncludesTest : public test::FormatTestBase {
 protected:
   std::vector GetCodeRange(StringRef Code) {
 return std::vector(1, tooling::Range(0, Code.size()));
@@ -821,6 +821,119 @@ TEST_F(SortIncludesTest, 
CalculatesCorrectCursorPositionWithRegrouping) {
   EXPECT_EQ(27u, newCursor(Code, 28)); // Start of last line
 }
 
+TEST_F(SortIncludesTest,
+   CalculatesCorrectCursorPositionWhenNoReplacementsWithRegroupingAndCRLF) 
{
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  FmtStyle.LineEnding = FormatStyle::LE_CRLF;
+  Style.IncludeCategories = {
+  {"^\"a\"", 0, 0, false}, {"^\"b\"", 1, 1, false}, {".*", 2, 2, false}};
+  std::string Code = "#include \"a\"\r\n" // Start of line: 0
+ "\r\n"   // Start of line: 14
+ "#include \"b\"\r\n" // Start of line: 16
+ "\r\n"   // Start of line: 30
+ "#include \"c\"\r\n" // Start of line: 32
+ "\r\n"   // Start of line: 46
+ "int i;";// Start of line: 48
+  verifyNoChange(Code);
+  EXPECT_EQ(0u, newCursor(Code, 0));
+  EXPECT_EQ(14u, newCursor(Code, 14));
+  EXPECT_EQ(16u, newCursor(Code, 16));
+  EXPECT_EQ(30u, newCursor(Code, 30));
+  EXPECT_EQ(32u, newCursor(Code, 32));
+  EXPECT_EQ(46u, newCursor(Code, 46));
+  EXPECT_EQ(48u, newCursor(Code, 48));
+}
+
+TEST_F(
+SortIncludesTest,
+
CalculatesCorrectCursorPositionWhenRemoveLinesReplacementsWithRegroupingAndCRLF)
 {
+  Style.IncludeBlocks = Style.IBS_Regroup;
+  FmtStyle.LineEnding = FormatStyle::LE_CRLF;
+  Style.IncludeCategories = {{".*", 0, 0, false}};
+  std::string Code = "#include \"a\"\r\n" // Start of line: 0
+ "\r\n"   // Start of line: 14
+ "#include \"b\"\r\n" // Start of line: 16
+ "\r\n"   // Start of line: 30
+ "#include \"c\"\r\n" // Start of line: 32
+ "\r\n"   // Start of line: 46
+ "int i;";// Start of line: 48
+  std::string Expected = "#include \"a\"\r\n" // Start of line: 0
+ "#include \"b\"\r\n" // Start of line: 14
+ "#include \"c\"\r\n" // Start of line: 28
+ "\r\n"   // Start of line: 42
+ "int i;";// Start of line: 44
+  EXPECT_EQ(Expected, sort(Code));
+  EXPECT_EQ(0u, newCursor(Code, 0));
+  EXPECT_EQ(
+  14u,
+  newCursor(Code, 14)); // cursor on empty line in include block is ignored
+  EXPECT_EQ(14u, newCursor(Code, 16));
+  EXPECT_EQ(
+  30u,
+  newCursor(Code, 30)); // cursor on empty line in include block is ignored
+  EXPECT_EQ(28u, newCursor(Code, 32));
+  EXPECT_EQ(42u, newCursor(Code, 46));
+  EXPECT_EQ(44u, newCursor(Code, 48));
+}
+
+TEST_F(
+SortIncludesTest,
+
Calculat

[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-04-19 Thread via cfe-commits

NorthBlue333 wrote:

Sure, that was was not very clear from my side I agree.

Yes, your implementation is cleaner (I don't know why I did not do that from 
the beginning, I think I was struggling to fix the other tests and ended up 
with something more complicated than necessary).

I have squashed the commits in only one.
Thanks for your time!

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


[clang] [Clang][Sema] Warn when 'exclude_from_explicit_instantiation' attribute is used on local classes and members thereof (PR #88777)

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

sdkrystian wrote:

@mikaelholmen I believe there are two uses of 
`exclude_from_explicit_instantiation` in libc++ which are responsible for all 
these warnings. I was assuming that someone more experienced with the libc++ 
side of things would handle it, but I can submit a patch that addresses these 
myself. 

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


[clang] [AST] Dump argument types for TypeTraitExpr. (PR #89370)

2024-04-19 Thread Haojian Wu via cfe-commits

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

The argument types are not modeled as children of TypeTraitExpr, therefore they 
are not dumped with the default implementation.

Dumping them is really useful for ad-hoc debugging, context #89358 

>From e8a9fcfa4210b6bf5ca342df5a055012b0fe8e88 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Thu, 18 Apr 2024 15:42:56 +0200
Subject: [PATCH] [AST] Dump argument types for TypeTraitExpr.

The argument types are not modeled as children of TypeTraitExpr,
therefore they are not dumped with the default implementation.

Dumping them is really useful for ad-hoc debugging.
---
 clang/include/clang/AST/ASTNodeTraverser.h|  6 +++
 ...dump-template-json-win32-mangler-crash.cpp | 40 ++-
 clang/test/AST/ast-dump-traits.cpp|  9 +
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index f5c47d8a7c2113..216dc9eef08b62 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -851,6 +851,12 @@ class ASTNodeTraverser
   Visit(R);
   }
 
+  void VisitTypeTraitExpr(const TypeTraitExpr *E) {
+// Argument types are not children of the TypeTraitExpr.
+for (auto *A : E->getArgs())
+  Visit(A->getType());
+  }
+
   void VisitLambdaExpr(const LambdaExpr *Node) {
 if (Traversal == TK_IgnoreUnlessSpelledInSource) {
   for (unsigned I = 0, N = Node->capture_size(); I != N; ++I) {
diff --git a/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp 
b/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
index 8c03b58abb0edb..cf740516db6f4b 100644
--- a/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
+++ b/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
@@ -2725,7 +2725,25 @@ int main()
 // CHECK-NEXT:"type": {
 // CHECK-NEXT: "qualType": "bool"
 // CHECK-NEXT:},
-// CHECK-NEXT:"valueCategory": "prvalue"
+// CHECK-NEXT:"valueCategory": "prvalue",
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "TemplateTypeParmType",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "_Ty"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "isDependent": true,
+// CHECK-NEXT:  "isInstantiationDependent": true,
+// CHECK-NEXT:  "depth": 0,
+// CHECK-NEXT:  "index": 0,
+// CHECK-NEXT:  "decl": {
+// CHECK-NEXT:   "id": "0x{{.*}}",
+// CHECK-NEXT:   "kind": "TemplateTypeParmDecl",
+// CHECK-NEXT:   "name": "_Ty"
+// CHECK-NEXT:  }
+// CHECK-NEXT: }
+// CHECK-NEXT:]
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
@@ -3003,7 +3021,25 @@ int main()
 // CHECK-NEXT:"type": {
 // CHECK-NEXT: "qualType": "bool"
 // CHECK-NEXT:},
-// CHECK-NEXT:"valueCategory": "prvalue"
+// CHECK-NEXT:"valueCategory": "prvalue",
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "TemplateTypeParmType",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "_Ty"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "isDependent": true,
+// CHECK-NEXT:  "isInstantiationDependent": true,
+// CHECK-NEXT:  "depth": 0,
+// CHECK-NEXT:  "index": 0,
+// CHECK-NEXT:  "decl": {
+// CHECK-NEXT:   "id": "0x{{.*}}",
+// CHECK-NEXT:   "kind": "TemplateTypeParmDecl",
+// CHECK-NEXT:   "name": "_Ty"
+// CHECK-NEXT:  }
+// CHECK-NEXT: }
+// CHECK-NEXT:]
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
diff --git a/clang/test/AST/ast-dump-traits.cpp 
b/clang/test/AST/ast-dump-traits.cpp
index 99ad50f528eb79..3085e5883fd2e2 100644
--- a/clang/test/AST/ast-dump-traits.cpp
+++ b/clang/test/AST/ast-dump-traits.cpp
@@ -40,10 +40,19 @@ void test_unary_expr_or_type_trait() {
 // CHECK-NEXT: |   | `-EnumDecl {{.*}}  col:8{{( imported)?}} 
referenced E
 // CHECK-NEXT: |   |-CStyleCastExpr {{.*}}  'void' 
 // CHECK-NEXT: |   | `-TypeTraitExpr {{.*}}  'bool' __is_enum
+// CHECK-NEXT: |   |   `-ElaboratedType {{.*}} 'E' sugar
+// CHECK-NEXT: |   | `-EnumType {{.*}} 'E'
+// CHECK-NEXT: |   |   `-Enum {{.*}} 'E'
 // CHECK-NEXT: |   |-CStyleCastExpr {{.*}}  'void' 
 // CHECK-NEXT: |   | `-TypeTraitExpr {{.*}}  'bool' __is_same
+// CHECK-NEXT: |   |   |-BuiltinType {{.*}} 'int'
+// CHECK-NEXT: |   |   `-BuiltinType {{.*}} 'float'
 // CHECK-NEXT: |   `-CStyleCastExpr {{.*}}  'void' 
 // CHECK-NEXT: | `-TypeTraitExpr {{.*}}  'bool' 
__is_constructible
+// CHECK-NEXT: |-BuiltinType {{.*}} 'int'
+// CHECK-NEXT: |-BuiltinType {{.*}} 'int'
+// CHECK-NEXT: |-Builti

[clang] [AST] Dump argument types for TypeTraitExpr. (PR #89370)

2024-04-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

The argument types are not modeled as children of TypeTraitExpr, therefore they 
are not dumped with the default implementation.

Dumping them is really useful for ad-hoc debugging, context #89358 

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


3 Files Affected:

- (modified) clang/include/clang/AST/ASTNodeTraverser.h (+6) 
- (modified) clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp 
(+38-2) 
- (modified) clang/test/AST/ast-dump-traits.cpp (+9) 


``diff
diff --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index f5c47d8a7c2113..216dc9eef08b62 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -851,6 +851,12 @@ class ASTNodeTraverser
   Visit(R);
   }
 
+  void VisitTypeTraitExpr(const TypeTraitExpr *E) {
+// Argument types are not children of the TypeTraitExpr.
+for (auto *A : E->getArgs())
+  Visit(A->getType());
+  }
+
   void VisitLambdaExpr(const LambdaExpr *Node) {
 if (Traversal == TK_IgnoreUnlessSpelledInSource) {
   for (unsigned I = 0, N = Node->capture_size(); I != N; ++I) {
diff --git a/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp 
b/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
index 8c03b58abb0edb..cf740516db6f4b 100644
--- a/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
+++ b/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
@@ -2725,7 +2725,25 @@ int main()
 // CHECK-NEXT:"type": {
 // CHECK-NEXT: "qualType": "bool"
 // CHECK-NEXT:},
-// CHECK-NEXT:"valueCategory": "prvalue"
+// CHECK-NEXT:"valueCategory": "prvalue",
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "TemplateTypeParmType",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "_Ty"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "isDependent": true,
+// CHECK-NEXT:  "isInstantiationDependent": true,
+// CHECK-NEXT:  "depth": 0,
+// CHECK-NEXT:  "index": 0,
+// CHECK-NEXT:  "decl": {
+// CHECK-NEXT:   "id": "0x{{.*}}",
+// CHECK-NEXT:   "kind": "TemplateTypeParmDecl",
+// CHECK-NEXT:   "name": "_Ty"
+// CHECK-NEXT:  }
+// CHECK-NEXT: }
+// CHECK-NEXT:]
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
@@ -3003,7 +3021,25 @@ int main()
 // CHECK-NEXT:"type": {
 // CHECK-NEXT: "qualType": "bool"
 // CHECK-NEXT:},
-// CHECK-NEXT:"valueCategory": "prvalue"
+// CHECK-NEXT:"valueCategory": "prvalue",
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "TemplateTypeParmType",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "_Ty"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "isDependent": true,
+// CHECK-NEXT:  "isInstantiationDependent": true,
+// CHECK-NEXT:  "depth": 0,
+// CHECK-NEXT:  "index": 0,
+// CHECK-NEXT:  "decl": {
+// CHECK-NEXT:   "id": "0x{{.*}}",
+// CHECK-NEXT:   "kind": "TemplateTypeParmDecl",
+// CHECK-NEXT:   "name": "_Ty"
+// CHECK-NEXT:  }
+// CHECK-NEXT: }
+// CHECK-NEXT:]
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
diff --git a/clang/test/AST/ast-dump-traits.cpp 
b/clang/test/AST/ast-dump-traits.cpp
index 99ad50f528eb79..3085e5883fd2e2 100644
--- a/clang/test/AST/ast-dump-traits.cpp
+++ b/clang/test/AST/ast-dump-traits.cpp
@@ -40,10 +40,19 @@ void test_unary_expr_or_type_trait() {
 // CHECK-NEXT: |   | `-EnumDecl {{.*}}  col:8{{( imported)?}} 
referenced E
 // CHECK-NEXT: |   |-CStyleCastExpr {{.*}}  'void' 
 // CHECK-NEXT: |   | `-TypeTraitExpr {{.*}}  'bool' __is_enum
+// CHECK-NEXT: |   |   `-ElaboratedType {{.*}} 'E' sugar
+// CHECK-NEXT: |   | `-EnumType {{.*}} 'E'
+// CHECK-NEXT: |   |   `-Enum {{.*}} 'E'
 // CHECK-NEXT: |   |-CStyleCastExpr {{.*}}  'void' 
 // CHECK-NEXT: |   | `-TypeTraitExpr {{.*}}  'bool' __is_same
+// CHECK-NEXT: |   |   |-BuiltinType {{.*}} 'int'
+// CHECK-NEXT: |   |   `-BuiltinType {{.*}} 'float'
 // CHECK-NEXT: |   `-CStyleCastExpr {{.*}}  'void' 
 // CHECK-NEXT: | `-TypeTraitExpr {{.*}}  'bool' 
__is_constructible
+// CHECK-NEXT: |-BuiltinType {{.*}} 'int'
+// CHECK-NEXT: |-BuiltinType {{.*}} 'int'
+// CHECK-NEXT: |-BuiltinType {{.*}} 'int'
+// CHECK-NEXT: `-BuiltinType {{.*}} 'int'
 // CHECK-NEXT: |-FunctionDecl {{.*}}  line:20:6{{( 
imported)?}} test_array_type_trait 'void ()'
 // CHECK-NEXT: | `-CompoundStmt {{.*}} 
 // CHECK-NEXT: |   `-CStyleCastExpr {{.*}}  'void' 

``




https://github.com/llvm/llv

[clang] [Clang][Sema] Warn when 'exclude_from_explicit_instantiation' attribute is used on local classes and members thereof (PR #88777)

2024-04-19 Thread via cfe-commits

mikaelholmen wrote:

Nice! I have no idea about this I just saw the warnings when I compiled and 
connected them to this patch.

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


[clang] [libclang] Compute the right spelling location (PR #72400)

2024-04-19 Thread Sebastian Poeplau via cfe-commits

https://github.com/sebastianpoeplau updated 
https://github.com/llvm/llvm-project/pull/72400

>From dd0f87b25733b4569b89ce445630ee843e3bfb2b Mon Sep 17 00:00:00 2001
From: Matthieu Eyraud 
Date: Mon, 11 Apr 2022 16:53:24 +0200
Subject: [PATCH] [libclang] Compute the right spelling location

Locations inside macro expansions have different spelling/expansion
locations. Apply a FIXME to make the libclang function
clang_getSpellingLocation return the right spelling location, and adapt
the testsuite driver code to use the file location rather than the
spelling location to compute source ranges.
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 clang/tools/c-index-test/c-index-test.c   | 54 +++
 clang/tools/libclang/CXSourceLocation.cpp |  3 +-
 clang/unittests/libclang/LibclangTest.cpp | 25 +++
 4 files changed, 55 insertions(+), 30 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3fe15934323c53..6fdc285da6ecd3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -678,6 +678,9 @@ clang-format
 libclang
 
 
+- ``clang_getSpellingLocation`` now correctly resolves macro expansions; that
+  is, it returns the spelling location instead of the expansion location.
+
 Static Analyzer
 ---
 
diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 21619888cfa5f3..e078e9bdce027a 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -464,10 +464,10 @@ static void PrintRange(CXSourceRange R, const char *str) {
   CXFile begin_file, end_file;
   unsigned begin_line, begin_column, end_line, end_column;
 
-  clang_getSpellingLocation(clang_getRangeStart(R),
-&begin_file, &begin_line, &begin_column, 0);
-  clang_getSpellingLocation(clang_getRangeEnd(R),
-&end_file, &end_line, &end_column, 0);
+  clang_getFileLocation(clang_getRangeStart(R), &begin_file, &begin_line,
+&begin_column, 0);
+  clang_getFileLocation(clang_getRangeEnd(R), &end_file, &end_line, 
&end_column,
+0);
   if (!begin_file || !end_file)
 return;
 
@@ -849,13 +849,13 @@ static void PrintCursor(CXCursor Cursor, const char 
*CommentSchemaFile) {
 printf(", ");
   
   Loc = clang_getCursorLocation(Ovl);
-  clang_getSpellingLocation(Loc, 0, &line, &column, 0);
+  clang_getFileLocation(Loc, 0, &line, &column, 0);
   printf("%d:%d", line, column);  
 }
 printf("]");
   } else {
 CXSourceLocation Loc = clang_getCursorLocation(Referenced);
-clang_getSpellingLocation(Loc, 0, &line, &column, 0);
+clang_getFileLocation(Loc, 0, &line, &column, 0);
 printf(":%d:%d", line, column);
   }
 
@@ -1047,7 +1047,7 @@ static void PrintCursor(CXCursor Cursor, const char 
*CommentSchemaFile) {
 if (!clang_equalCursors(SpecializationOf, clang_getNullCursor())) {
   CXSourceLocation Loc = clang_getCursorLocation(SpecializationOf);
   CXString Name = clang_getCursorSpelling(SpecializationOf);
-  clang_getSpellingLocation(Loc, 0, &line, &column, 0);
+  clang_getFileLocation(Loc, 0, &line, &column, 0);
   printf(" [Specialization of %s:%d:%d]",
  clang_getCString(Name), line, column);
   clang_disposeString(Name);
@@ -1094,7 +1094,7 @@ static void PrintCursor(CXCursor Cursor, const char 
*CommentSchemaFile) {
   printf(" [Overrides ");
   for (I = 0; I != num_overridden; ++I) {
 CXSourceLocation Loc = clang_getCursorLocation(overridden[I]);
-clang_getSpellingLocation(Loc, 0, &line, &column, 0);
+clang_getFileLocation(Loc, 0, &line, &column, 0);
 lineCols[I].line = line;
 lineCols[I].col = column;
   }
@@ -1257,8 +1257,8 @@ void PrintDiagnostic(CXDiagnostic Diagnostic) {
   fprintf(stderr, "%s\n", clang_getCString(Msg));
   clang_disposeString(Msg);
 
-  clang_getSpellingLocation(clang_getDiagnosticLocation(Diagnostic),
-&file, 0, 0, 0);
+  clang_getFileLocation(clang_getDiagnosticLocation(Diagnostic), &file, 0, 0,
+0);
   if (!file)
 return;
 
@@ -1271,9 +1271,8 @@ void PrintDiagnostic(CXDiagnostic Diagnostic) {
 CXSourceLocation end = clang_getRangeEnd(range);
 unsigned start_line, start_column, end_line, end_column;
 CXFile start_file, end_file;
-clang_getSpellingLocation(start, &start_file, &start_line,
-  &start_column, 0);
-clang_getSpellingLocation(end, &end_file, &end_line, &end_column, 0);
+clang_getFileLocation(start, &start_file, &start_line, &start_column, 0);
+clang_getFileLocation(end, &end_file, &end_line, &end_column, 0);
 if (clang_equalLocations(start, end)) {
   /* Insertion. */
   if (start_file == file)
@@ -1356,7 +1355,7 @@ 

[clang] [libclang] Compute the right spelling location (PR #72400)

2024-04-19 Thread Sebastian Poeplau via cfe-commits

sebastianpoeplau wrote:

Thanks for the review @jansvoboda11; I've added an entry in the release notes 
and a unit test.

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


[clang] e2f1cba - [analyzer] Use explicit call description mode (easy cases) (#88879)

2024-04-19 Thread via cfe-commits

Author: NagyDonat
Date: 2024-04-19T14:22:51+02:00
New Revision: e2f1cbae45f81f3cd9a4d3c2bcf69a094eb060fa

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

LOG: [analyzer] Use explicit call description mode (easy cases) (#88879)

This commit explicitly specifies the matching mode (C library function,
any non-method function, or C++ method) for the `CallDescription`s
constructed in various checkers where this transition was easy and
straightforward.

This change won't cause major functional changes, but isn't NFC because
it ensures that e.g. call descriptions for a non-method function won't
accidentally match a method that has the same name.

Separate commits will perform (or have already performed) this change in
other checkers. My goal is to ensure that the call description mode is
always explicitly specified and eliminate (or strongly restrict) the
vague "may be either a method or a simple function" mode that's the
current default.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
clang/lib/StaticAnalyzer/Checkers/StdVariantChecker.cpp
clang/lib/StaticAnalyzer/Checkers/StringChecker.cpp
clang/lib/StaticAnalyzer/Checkers/cert/PutenvWithAutoChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
index f02d20d45678b3..c7479d74eafc33 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
@@ -56,23 +56,23 @@ class CastValueChecker : public Checker {
 
 private:
   // These are known in the LLVM project. The pairs are in the following form:
-  // {{{namespace, call}, argument-count}, {callback, kind}}
+  // {{match-mode, {namespace, call}, argument-count}, {callback, kind}}
   const CallDescriptionMap> CDM = {
-  {{{"llvm", "cast"}, 1},
+  {{CDM::SimpleFunc, {"llvm", "cast"}, 1},
{&CastValueChecker::evalCast, CallKind::Function}},
-  {{{"llvm", "dyn_cast"}, 1},
+  {{CDM::SimpleFunc, {"llvm", "dyn_cast"}, 1},
{&CastValueChecker::evalDynCast, CallKind::Function}},
-  {{{"llvm", "cast_or_null"}, 1},
+  {{CDM::SimpleFunc, {"llvm", "cast_or_null"}, 1},
{&CastValueChecker::evalCastOrNull, CallKind::Function}},
-  {{{"llvm", "dyn_cast_or_null"}, 1},
+  {{CDM::SimpleFunc, {"llvm", "dyn_cast_or_null"}, 1},
{&CastValueChecker::evalDynCastOrNull, CallKind::Function}},
-  {{{"clang", "castAs"}, 0},
+  {{CDM::CXXMethod, {"clang", "castAs"}, 0},
{&CastValueChecker::evalCastAs, CallKind::Method}},
-  {{{"clang", "getAs"}, 0},
+  {{CDM::CXXMethod, {"clang", "getAs"}, 0},
{&CastValueChecker::evalGetAs, CallKind::Method}},
-  {{{"llvm", "isa"}, 1},
+  {{CDM::SimpleFunc, {"llvm", "isa"}, 1},
{&CastValueChecker::evalIsa, CallKind::InstanceOf}},
-  {{{"llvm", "isa_and_nonnull"}, 1},
+  {{CDM::SimpleFunc, {"llvm", "isa_and_nonnull"}, 1},
{&CastValueChecker::evalIsaAndNonNull, CallKind::InstanceOf}}};
 
   void evalCast(const CallEvent &Call, DefinedOrUnknownSVal DV,

diff  --git a/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
index be7be15022d360..3a0a01c23de03e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
@@ -43,7 +43,8 @@ class ChrootChecker : public Checker {
   // This bug refers to possibly break out of a chroot() jail.
   const BugType BT_BreakJail{this, "Break out of jail"};
 
-  const CallDescription Chroot{{"chroot"}, 1}, Chdir{{"chdir"}, 1};
+  const CallDescription Chroot{CDM::CLibrary, {"chroot"}, 1},
+  Chdir{CDM::CLibrary, {"chdir"}, 1};
 
 public:
   ChrootChecker() {}

diff  --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
index c46ebee0c94ff4..6076a6bc789737 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoTesterChecker.cpp
@@ -70,13 +70,15 @@ class ErrnoTesterChecker : public Checker {
 
   using EvalFn = std::function;
   const CallDescriptionMap TestCalls{
-  {{{"ErrnoTesterChecker_setErrno"}, 1}, 
&ErrnoTesterChecker::evalSetErrno},
-  {{{"ErrnoTesterChecker_getErrno"}, 0}, 
&ErrnoTesterChecker::evalGetErrno},
-  {{{"ErrnoTesterChecker_setErrnoIfError"}, 0},
+  {{CDM::SimpleFunc, {"ErrnoTesterChecker_setErrno"}, 1},
+   &ErrnoTesterChecker::evalSetErrno},
+  {{CDM::Simple

[clang] [analyzer] Use explicit call description mode (easy cases) (PR #88879)

2024-04-19 Thread via cfe-commits

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


[clang] [Clang][Sema] Warn when 'exclude_from_explicit_instantiation' attribute is used on local classes and members thereof (PR #88777)

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

sdkrystian wrote:

@mikaelholmen See #89377

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


[clang] [clang] CTAD: Fix require-clause is not transformed. (PR #89378)

2024-04-19 Thread Haojian Wu via cfe-commits

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

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

When building the deduction guide, we use the TemplateArgsForBuildingFPrime to 
transform the require-clause from the underlying class deduction guide. 
However, we do this at the wrong place where not all elements of 
TemplateArgsForBuildingFPrime are initialized. The fix involves rearranging the 
transformRequireClause call to the correct location.

As part of the fix, we extend the TemplateInstantiator to support more types in 
the template-rewrite mode. Otherwise, we will encounter an assertion error when 
attempting to rewrite the template type parameter type like D with a complex 
type like Derived.

>From 0476e5f735a220c8c991d88db0b4ce2d37f50383 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 19 Apr 2024 14:18:47 +0200
Subject: [PATCH] [clang] CTAD: Fix require-clause is not transformed.

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

When building the deduction guide, we use the TemplateArgsForBuildingFPrime to
transform the require-clause from the underlying class deduction guide. However,
we do this at the wrong place where not all elements of 
TemplateArgsForBuildingFPrime
are initialized. The fix involves rearranging the transformRequireClause call to
the correct location.

As part of the fix, we extend the TemplateInstantiator to support more types in
the template-rewrite mode. Otherwise, we will encounter an assertion error when
attempting to rewrite the template type parameter type like D with a complex 
type
like Derived.
---
 clang/lib/Sema/SemaTemplate.cpp  | 27 ++-
 clang/lib/Sema/SemaTemplateInstantiate.cpp   |  5 +---
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 18 +
 clang/test/SemaTemplate/deduction-guide.cpp  | 28 
 4 files changed, 61 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index d4976f9d0d11d8..4bda31ba67c02d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2962,19 +2962,6 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
   Context.getCanonicalTemplateArgument(
   Context.getInjectedTemplateArg(NewParam));
 }
-// Substitute new template parameters into requires-clause if present.
-Expr *RequiresClause =
-transformRequireClause(SemaRef, F, TemplateArgsForBuildingFPrime);
-// FIXME: implement the is_deducible constraint per C++
-// [over.match.class.deduct]p3.3:
-//... and a constraint that is satisfied if and only if the arguments
-//of A are deducible (see below) from the return type.
-auto *FPrimeTemplateParamList = TemplateParameterList::Create(
-Context, AliasTemplate->getTemplateParameters()->getTemplateLoc(),
-AliasTemplate->getTemplateParameters()->getLAngleLoc(),
-FPrimeTemplateParams,
-AliasTemplate->getTemplateParameters()->getRAngleLoc(),
-/*RequiresClause=*/RequiresClause);
 
 // To form a deduction guide f' from f, we leverage clang's instantiation
 // mechanism, we construct a template argument list where the template
@@ -3020,6 +3007,20 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 F, TemplateArgListForBuildingFPrime, AliasTemplate->getLocation(),
 Sema::CodeSynthesisContext::BuildingDeductionGuides)) {
   auto *GG = cast(FPrime);
+  // Substitute new template parameters into requires-clause if present.
+  Expr *RequiresClause =
+  transformRequireClause(SemaRef, F, TemplateArgsForBuildingFPrime);
+  // FIXME: implement the is_deducible constraint per C++
+  // [over.match.class.deduct]p3.3:
+  //... and a constraint that is satisfied if and only if the arguments
+  //of A are deducible (see below) from the return type.
+  auto *FPrimeTemplateParamList = TemplateParameterList::Create(
+  Context, AliasTemplate->getTemplateParameters()->getTemplateLoc(),
+  AliasTemplate->getTemplateParameters()->getLAngleLoc(),
+  FPrimeTemplateParams,
+  AliasTemplate->getTemplateParameters()->getRAngleLoc(),
+  /*RequiresClause=*/RequiresClause);
+
   buildDeductionGuide(SemaRef, AliasTemplate, FPrimeTemplateParamList,
   GG->getCorrespondingConstructor(),
   GG->getExplicitSpecifier(), GG->getTypeSourceInfo(),
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 7cd428de0bb32d..63894cc3cdd538 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2501,10 +2501,7 @@ 
TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
   assert(Arg.getKind() == TemplateArgument::Type &&
  "unexpected nontype template argument kind in template rewr

[clang] [clang] CTAD: Fix require-clause is not transformed. (PR #89378)

2024-04-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

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

When building the deduction guide, we use the TemplateArgsForBuildingFPrime to 
transform the require-clause from the underlying class deduction guide. 
However, we do this at the wrong place where not all elements of 
TemplateArgsForBuildingFPrime are initialized. The fix involves rearranging the 
transformRequireClause call to the correct location.

As part of the fix, we extend the TemplateInstantiator to support more types in 
the template-rewrite mode. Otherwise, we will encounter an assertion error when 
attempting to rewrite the template type parameter type like D with a complex 
type like Derived.

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


4 Files Affected:

- (modified) clang/lib/Sema/SemaTemplate.cpp (+14-13) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+1-4) 
- (modified) clang/test/SemaCXX/cxx20-ctad-type-alias.cpp (+18) 
- (modified) clang/test/SemaTemplate/deduction-guide.cpp (+28) 


``diff
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index d4976f9d0d11d8..4bda31ba67c02d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2962,19 +2962,6 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
   Context.getCanonicalTemplateArgument(
   Context.getInjectedTemplateArg(NewParam));
 }
-// Substitute new template parameters into requires-clause if present.
-Expr *RequiresClause =
-transformRequireClause(SemaRef, F, TemplateArgsForBuildingFPrime);
-// FIXME: implement the is_deducible constraint per C++
-// [over.match.class.deduct]p3.3:
-//... and a constraint that is satisfied if and only if the arguments
-//of A are deducible (see below) from the return type.
-auto *FPrimeTemplateParamList = TemplateParameterList::Create(
-Context, AliasTemplate->getTemplateParameters()->getTemplateLoc(),
-AliasTemplate->getTemplateParameters()->getLAngleLoc(),
-FPrimeTemplateParams,
-AliasTemplate->getTemplateParameters()->getRAngleLoc(),
-/*RequiresClause=*/RequiresClause);
 
 // To form a deduction guide f' from f, we leverage clang's instantiation
 // mechanism, we construct a template argument list where the template
@@ -3020,6 +3007,20 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
 F, TemplateArgListForBuildingFPrime, AliasTemplate->getLocation(),
 Sema::CodeSynthesisContext::BuildingDeductionGuides)) {
   auto *GG = cast(FPrime);
+  // Substitute new template parameters into requires-clause if present.
+  Expr *RequiresClause =
+  transformRequireClause(SemaRef, F, TemplateArgsForBuildingFPrime);
+  // FIXME: implement the is_deducible constraint per C++
+  // [over.match.class.deduct]p3.3:
+  //... and a constraint that is satisfied if and only if the arguments
+  //of A are deducible (see below) from the return type.
+  auto *FPrimeTemplateParamList = TemplateParameterList::Create(
+  Context, AliasTemplate->getTemplateParameters()->getTemplateLoc(),
+  AliasTemplate->getTemplateParameters()->getLAngleLoc(),
+  FPrimeTemplateParams,
+  AliasTemplate->getTemplateParameters()->getRAngleLoc(),
+  /*RequiresClause=*/RequiresClause);
+
   buildDeductionGuide(SemaRef, AliasTemplate, FPrimeTemplateParamList,
   GG->getCorrespondingConstructor(),
   GG->getExplicitSpecifier(), GG->getTypeSourceInfo(),
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 7cd428de0bb32d..63894cc3cdd538 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2501,10 +2501,7 @@ 
TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
   assert(Arg.getKind() == TemplateArgument::Type &&
  "unexpected nontype template argument kind in template rewrite");
   QualType NewT = Arg.getAsType();
-  assert(isa(NewT) &&
- "type parm not rewritten to type parm");
-  auto NewTL = TLB.push(NewT);
-  NewTL.setNameLoc(TL.getNameLoc());
+  TLB.pushTrivial(SemaRef.Context, NewT, TL.getNameLoc());
   return NewT;
 }
 
diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index 6f04264a655ad5..508a3a5da76a91 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -289,3 +289,21 @@ using String = Array;
 // Verify no crash on constructing the aggregate deduction guides.
 String s("hello");
 } // namespace test21
+
+// GH89013
+namespace test22 {
+class Base {};
+template 
+class Derived final : public Base {};
+
+template 
+requir

[clang] [C23] Select the correct promoted type for a bit-field (PR #89254)


AaronBallman wrote:

> > @tbaederr -- this triggers an assertion with the new constexpr interpreter 
> > in `clang/test/AST/Interp/intap.cpp` but I'm not certain I understand why. 
> > Can you help me figure out how to fix that?
> > https://buildkite.com/llvm-project/github-pull-requests/builds/56785#018ef1ee-1e9c-48be-8944-0bce2c6f441d/6-1940
> 
> In `IntegralAP::truncate()` (which we call when getting the `3` and setting 
> it as the value of the bitfield), we actually truncate the bitwith of the 
> underlying `IntAP`, not just the _value_.
> 
> This fixes things for me:
> 
> ```diff
> diff --git a/clang/lib/AST/Interp/IntegralAP.h 
> b/clang/lib/AST/Interp/IntegralAP.h
> index bab9774288bf..fb7ee1451571 100644
> --- a/clang/lib/AST/Interp/IntegralAP.h
> +++ b/clang/lib/AST/Interp/IntegralAP.h
> @@ -154,7 +154,10 @@ public:
>}
> 
>IntegralAP truncate(unsigned BitWidth) const {
> -return IntegralAP(V.trunc(BitWidth));
> +if constexpr (Signed)
> +  return IntegralAP(V.trunc(BitWidth).sextOrTrunc(this->bitWidth()));
> +else
> +  return IntegralAP(V.trunc(BitWidth).zextOrTrunc(this->bitWidth()));
>}
> 
>IntegralAP toUnsigned() const {
> ```
> 
> I'd push this (it doesn't break any existing tests), but I'm not 100% sure if 
> this is the right way to do that. Also, I should follow up with a `truncate` 
> -> `truncateValue` rename.

Thank you for the help, that does pass all the tests, so I've added a commit 
for it.

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


[clang] [flang] [flang][driver] Avoid mentions of Clang in Flang's command line reference. (PR #88932)


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


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


[clang] [polly] [clang-format] Revert breaking stream operators to previous default (PR #89016)


mydeveloperday wrote:

Do you think we should push this into the 18 branch?

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


[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)



@@ -130,6 +130,12 @@ struct LangStandard {
   /// hasDigraphs - Language supports digraphs.
   bool hasDigraphs() const { return Flags & Digraphs; }
 
+  /// hasRawStringLiterals - Language supports R"()" raw string literals.
+  bool hasRawStringLiterals() const {
+// GCC supports raw string literals in C, but not in C++ before C++11.
+return isCPlusPlus11() || (!isCPlusPlus() && isGNUMode());

AaronBallman wrote:

okay, so my guess was correct. It's still odd though because that same logic 
applies to C99 (it's "old" and the behavior can still change). But yeah, we 
should follow the same behavior as GCC in this case (less confusion for users).

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


[clang] aa39b0b - [AIX][Debug]correct the cases on AIX bot, NFC


Author: Chen Zheng
Date: 2024-04-19T08:52:28-04:00
New Revision: aa39b0b13e3b56ac072acff2660dbef9db45bca0

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

LOG: [AIX][Debug]correct the cases on AIX bot, NFC

Related to commit b2323f43e3cdb52b4e15a7d4f434cd5c64740dd4

Added: 
clang/test/Driver/debug-options-embed-source.c

Modified: 
clang/test/CodeGen/debug-info-file-checksum.c
clang/test/Driver/debug-options.c

Removed: 




diff  --git a/clang/test/CodeGen/debug-info-file-checksum.c 
b/clang/test/CodeGen/debug-info-file-checksum.c
index e018dbf64fc98f..2ca91d605d1c4b 100644
--- a/clang/test/CodeGen/debug-info-file-checksum.c
+++ b/clang/test/CodeGen/debug-info-file-checksum.c
@@ -1,3 +1,6 @@
+// AIX does not support -gdwarf-5.
+// UNSUPPORTED: target={{.*}}-aix{{.*}}
+
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c \
 // RUN: %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 // RUN: %clang -emit-llvm -S -g -gcodeview -Xclang -gsrc-hash=md5 \

diff  --git a/clang/test/Driver/debug-options-embed-source.c 
b/clang/test/Driver/debug-options-embed-source.c
new file mode 100644
index 00..acb00fca62ee03
--- /dev/null
+++ b/clang/test/Driver/debug-options-embed-source.c
@@ -0,0 +1,13 @@
+// AIX does not support -gdwarf-5 which is required by -gembed-source
+// UNSUPPORTED: target={{.*}}-aix{{.*}}
+
+// RUN: %clang -### -gdwarf-5 -gembed-source %s 2>&1 | FileCheck 
-check-prefix=GEMBED_5 %s
+// RUN: not %clang -### -gdwarf-2 -gembed-source %s 2>&1 | FileCheck 
-check-prefix=GEMBED_2 %s
+// RUN: %clang -### -gdwarf-5 -gno-embed-source %s 2>&1 | FileCheck 
-check-prefix=NOGEMBED_5 %s
+// RUN: %clang -### -gdwarf-2 -gno-embed-source %s 2>&1 | FileCheck 
-check-prefix=NOGEMBED_2 %s
+//
+// GEMBED_5:  "-gembed-source"
+// GEMBED_2:  error: invalid argument '-gembed-source' only allowed with 
'-gdwarf-5'
+// NOGEMBED_5-NOT:  "-gembed-source"
+// NOGEMBED_2-NOT:  error: invalid argument '-gembed-source' only allowed with 
'-gdwarf-5'
+//

diff  --git a/clang/test/Driver/debug-options.c 
b/clang/test/Driver/debug-options.c
index a6acfe88a38611..b209c911d1ca2b 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -410,16 +410,6 @@
 // MACRO: "-debug-info-macro"
 // NOMACRO-NOT: "-debug-info-macro"
 //
-// RUN: %clang -### -gdwarf-5 -gembed-source %s 2>&1 | FileCheck 
-check-prefix=GEMBED_5 %s
-// RUN: not %clang -### -gdwarf-2 -gembed-source %s 2>&1 | FileCheck 
-check-prefix=GEMBED_2 %s
-// RUN: %clang -### -gdwarf-5 -gno-embed-source %s 2>&1 | FileCheck 
-check-prefix=NOGEMBED_5 %s
-// RUN: %clang -### -gdwarf-2 -gno-embed-source %s 2>&1 | FileCheck 
-check-prefix=NOGEMBED_2 %s
-//
-// GEMBED_5:  "-gembed-source"
-// GEMBED_2:  error: invalid argument '-gembed-source' only allowed with 
'-gdwarf-5'
-// NOGEMBED_5-NOT:  "-gembed-source"
-// NOGEMBED_2-NOT:  error: invalid argument '-gembed-source' only allowed with 
'-gdwarf-5'
-//
 // RUN: %clang -### -g -fno-eliminate-unused-debug-types -c %s 2>&1 \
 // RUN:| FileCheck -check-prefix=DEBUG_UNUSED_TYPES %s
 // DEBUG_UNUSED_TYPES: "-debug-info-kind=unused-types"



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


[clang] Reapply "[Clang][Sema] placement new initializes typedef array with correct size (#83124)" (PR #89036)


https://github.com/erichkeane commented:

Where is the repro from the original author?  What did they share, and what 
ended up being the solution/test here for it?

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


[clang] Reapply "[Clang][Sema] placement new initializes typedef array with correct size (#83124)" (PR #89036)


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


[clang] Reapply "[Clang][Sema] placement new initializes typedef array with correct size (#83124)" (PR #89036)



@@ -12864,6 +12864,19 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 ArraySize = NewArraySize.get();
   }
 
+  // Per C++0x [expr.new]p5, the type being constructed may be a
+  // typedef of an array type.
+  QualType AllocType = AllocTypeInfo->getType();
+  if (ArraySize && E->isTypeDependent()) {

erichkeane wrote:

does Value dependence matter?  

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


[clang] [C23] Select the correct promoted type for a bit-field (PR #89254)


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


[clang] [C23] Select the correct promoted type for a bit-field (PR #89254)



@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s
+
+// GH87641 noticed that integer promotion of a bit-field of bit-precise integer
+// type was promoting to int rather than the type of the bit-field.
+struct S {
+  unsigned _BitInt(7) x : 2;
+  unsigned _BitInt(2) y : 2;
+  unsigned _BitInt(72) z : 28;

Sirraide wrote:

Is there a reason all of these are unsigned? Maybe adding some tests for signed 
`_BitInt`s as well might be a good idea—or do we have those already?

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


[clang] [C23] Select the correct promoted type for a bit-field (PR #89254)


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

Just one comment but LGTM otherwise.

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


[clang] [AST] Dump argument types for TypeTraitExpr. (PR #89370)


https://github.com/erichkeane commented:

It seems to me that exposing these as children is the better option here, 
right?  That way it would better model a CallExpr or template type-trait, and 
would work in our StmtProfiler et-al.

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)


https://github.com/erichkeane commented:

Needs a release note, and I think we actually DO have to do those diagnostics 
here.  

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)



@@ -6100,6 +6100,17 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
   tok::kw___is_pointer_interconvertible_base_of);
 
 return Self.IsPointerInterconvertibleBaseOf(Lhs, Rhs);
+  }
+  case BTT_IsDeducible: {
+if (const auto *TSTToBeDeduced =
+LhsT->getAs()) {
+  sema::TemplateDeductionInfo Info(KeyLoc);
+  return Self.DeduceTemplateArgumentsFromType(
+ TSTToBeDeduced->getTemplateName().getAsTemplateDecl(), RhsT,
+ Info) == TemplateDeductionResult::Success;
+}
+// FIXME: emit a diagnostic.

erichkeane wrote:

I dont think we can leave this as a fixme.

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)



@@ -3207,6 +3241,59 @@ 
Sema::DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial,
   return ::DeduceTemplateArguments(*this, Partial, TemplateArgs, Info);
 }
 
+TemplateDeductionResult
+Sema::DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType,
+  sema::TemplateDeductionInfo &Info) {
+  if (TD->isInvalidDecl())
+return TemplateDeductionResult::Invalid;
+
+  QualType PType;
+  if (const auto *CTD = dyn_cast(TD)) {
+// Use the InjectedClassNameType.
+PType = Context.getTypeDeclType(CTD->getTemplatedDecl());
+  } else if (const auto *AliasTemplate = dyn_cast(TD)) {
+PType = AliasTemplate->getTemplatedDecl()
+->getUnderlyingType()
+.getCanonicalType();
+  } else {
+// FIXME: emit a diagnostic, we only only support alias and class 
templates.

erichkeane wrote:

Same here.

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


[clang] [clang] CTAD: implement the missing IsDeducible constraint for alias templates (PR #89358)


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


[clang] [clang] CTAD: Fix require-clause is not transformed. (PR #89378)


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


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


[clang] [C23] Select the correct promoted type for a bit-field (PR #89254)


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


[clang] [C23] Select the correct promoted type for a bit-field (PR #89254)


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

This change looks right to me!   I don't know if there is value in a 
signed-test instead of unsigned, but a couple more tests might be nice anyway.

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


[clang] [C23] Select the correct promoted type for a bit-field (PR #89254)



@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s
+
+// GH87641 noticed that integer promotion of a bit-field of bit-precise integer
+// type was promoting to int rather than the type of the bit-field.
+struct S {
+  unsigned _BitInt(7) x : 2;
+  unsigned _BitInt(2) y : 2;
+  unsigned _BitInt(72) z : 28;

erichkeane wrote:

Wouldn't mind a 31 and a 33 as well.

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


[clang] [C23] Select the correct promoted type for a bit-field (PR #89254)



@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s
+
+// GH87641 noticed that integer promotion of a bit-field of bit-precise integer
+// type was promoting to int rather than the type of the bit-field.
+struct S {
+  unsigned _BitInt(7) x : 2;
+  unsigned _BitInt(2) y : 2;
+  unsigned _BitInt(72) z : 28;

AaronBallman wrote:

Sure, I can add some signed tests with different boundaries!

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


[clang-tools-extra] [clangd] Use TargetOpts from preamble when building ASTs (PR #88381)


zibi2 wrote:

@kadircet FYI, I noticed our Linux on Power down stream build failues related 
to this change. The upstream builds are also faling see 
https://lab.llvm.org/buildbot/#/builders/57/builds/34415 for example.

```
ld.lld: error: undefined symbol: llvm::Triple::getArchName() const
>>> referenced by ParsedASTTests.cpp
```

This symbol is define in `Triple.cpp.o` which is part of 
`libLLVMTargetParser.a`  which is not built. Not building this archive and a 
bunch of others is the root of the problem. 

Can you have a look and try to fix it?
Thanks, Zibi.

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


[clang] Reapply "[Clang][Sema] placement new initializes typedef array with correct size (#83124)" (PR #89036)



@@ -12864,6 +12864,19 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 ArraySize = NewArraySize.get();
   }
 
+  // Per C++0x [expr.new]p5, the type being constructed may be a
+  // typedef of an array type.
+  QualType AllocType = AllocTypeInfo->getType();
+  if (ArraySize && E->isTypeDependent()) {

mahtohappy wrote:

Yes, it does. Both the original testcase from @slackito  and simpler version of 
@dwblaikie are working now. 
normal arrays with new initializer also were passing the check and their type 
was correct earlier so need for modification for them. ```typedef TYPE 
TArray[8]; TArray x;``` here type of array was Tarray which should be Type* so 
the check only for type dependent case. 

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


[clang] Reapply "[Clang][Sema] placement new initializes typedef array with correct size (#83124)" (PR #89036)



@@ -12864,6 +12864,19 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 ArraySize = NewArraySize.get();
   }
 
+  // Per C++0x [expr.new]p5, the type being constructed may be a
+  // typedef of an array type.
+  QualType AllocType = AllocTypeInfo->getType();
+  if (ArraySize && E->isTypeDependent()) {

erichkeane wrote:

Note I asked about VALUE dependence, not TYPE dependence.  I see why type 
dependence would matter, but expressions can be both type and value dependent.

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


[clang] [polly] [clang-format] Correctly annotate braces in macros (PR #87953)


tstellar wrote:

@owenca Is there a PR for the cherry-pick ?

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


[clang] [analyzer] Fix stores through label locations (PR #89265)



@@ -2358,11 +2358,12 @@ StoreRef RegionStoreManager::killBinding(Store ST, Loc 
L) {
 
 RegionBindingsRef
 RegionStoreManager::bind(RegionBindingsConstRef B, Loc L, SVal V) {
-  if (L.getAs())
+  // We only care about region locations.
+  auto MemRegVal = L.getAs();
+  if (!MemRegVal.has_value())

steakhal wrote:

```suggestion
  if (!MemRegVal)
```

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


[clang] [analyzer] Fix stores through label locations (PR #89265)


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

>From 50964bf4f694ae21c2ba86b648b241b335e5d6e8 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Thu, 18 Apr 2024 18:36:29 +0200
Subject: [PATCH 1/2] [analyzer] Fix stores through label locations

Interestingly, this case crashed from the very beginning of the project,
at least starting by clang-3.

As a "fix" I just do the same thing as we do for concrete integers.
It might not be the best we could do, but arguably, it's still better
than crashing.

Fixes 89185
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp |  7 ---
 clang/test/Analysis/gh-issue-89185.c  | 14 ++
 3 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Analysis/gh-issue-89185.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6099f8ab02f443..1d98330d2e4a00 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -681,6 +681,8 @@ Static Analyzer
 - Support C++23 static operator calls. (#GH84972)
 - Fixed a crash in ``security.cert.env.InvalidPtr`` checker when accidentally
   matched user-defined ``strerror`` and similar library functions. (GH#88181)
+- Fixed a crash when storing through an address that refers to the address of
+  a label. (GH#89185)
 
 New features
 
diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp 
b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 755a8c4b22fd9e..2379db9fdb0576 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2358,11 +2358,12 @@ StoreRef RegionStoreManager::killBinding(Store ST, Loc 
L) {
 
 RegionBindingsRef
 RegionStoreManager::bind(RegionBindingsConstRef B, Loc L, SVal V) {
-  if (L.getAs())
+  // We only care about region locations.
+  auto MemRegVal = L.getAs();
+  if (!MemRegVal.has_value())
 return B;
 
-  // If we get here, the location should be a region.
-  const MemRegion *R = L.castAs().getRegion();
+  const MemRegion *R = MemRegVal->getRegion();
 
   // Check if the region is a struct region.
   if (const TypedValueRegion* TR = dyn_cast(R)) {
diff --git a/clang/test/Analysis/gh-issue-89185.c 
b/clang/test/Analysis/gh-issue-89185.c
new file mode 100644
index 00..8a907f198a5fd5
--- /dev/null
+++ b/clang/test/Analysis/gh-issue-89185.c
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
+
+void clang_analyzer_dump(char);
+void clang_analyzer_dump_ptr(char*);
+
+// https://github.com/llvm/llvm-project/issues/89185
+void binding_to_label_loc() {
+  char *b = &&MyLabel;
+MyLabel:
+  *b = 0; // no-crash
+  clang_analyzer_dump_ptr(b); // expected-warning {{&&MyLabel}}
+  clang_analyzer_dump(*b); // expected-warning {{Unknown}}
+  // FIXME: We should never reach here, as storing to a label is invalid.
+}

>From 739425eafcf1b7f3f1c6e41b8c102fd5eba7e0e8 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Fri, 19 Apr 2024 15:42:54 +0200
Subject: [PATCH 2/2] NFC Remove `.has_value()`

---
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp 
b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 2379db9fdb0576..54e88c07255db7 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2360,7 +2360,7 @@ RegionBindingsRef
 RegionStoreManager::bind(RegionBindingsConstRef B, Loc L, SVal V) {
   // We only care about region locations.
   auto MemRegVal = L.getAs();
-  if (!MemRegVal.has_value())
+  if (!MemRegVal)
 return B;
 
   const MemRegion *R = MemRegVal->getRegion();

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


[clang] [analyzer] Fix stores through label locations (PR #89265)


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

>From 50964bf4f694ae21c2ba86b648b241b335e5d6e8 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Thu, 18 Apr 2024 18:36:29 +0200
Subject: [PATCH 1/2] [analyzer] Fix stores through label locations

Interestingly, this case crashed from the very beginning of the project,
at least starting by clang-3.

As a "fix" I just do the same thing as we do for concrete integers.
It might not be the best we could do, but arguably, it's still better
than crashing.

Fixes 89185
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp |  7 ---
 clang/test/Analysis/gh-issue-89185.c  | 14 ++
 3 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Analysis/gh-issue-89185.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6099f8ab02f443..1d98330d2e4a00 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -681,6 +681,8 @@ Static Analyzer
 - Support C++23 static operator calls. (#GH84972)
 - Fixed a crash in ``security.cert.env.InvalidPtr`` checker when accidentally
   matched user-defined ``strerror`` and similar library functions. (GH#88181)
+- Fixed a crash when storing through an address that refers to the address of
+  a label. (GH#89185)
 
 New features
 
diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp 
b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 755a8c4b22fd9e..2379db9fdb0576 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2358,11 +2358,12 @@ StoreRef RegionStoreManager::killBinding(Store ST, Loc 
L) {
 
 RegionBindingsRef
 RegionStoreManager::bind(RegionBindingsConstRef B, Loc L, SVal V) {
-  if (L.getAs())
+  // We only care about region locations.
+  auto MemRegVal = L.getAs();
+  if (!MemRegVal.has_value())
 return B;
 
-  // If we get here, the location should be a region.
-  const MemRegion *R = L.castAs().getRegion();
+  const MemRegion *R = MemRegVal->getRegion();
 
   // Check if the region is a struct region.
   if (const TypedValueRegion* TR = dyn_cast(R)) {
diff --git a/clang/test/Analysis/gh-issue-89185.c 
b/clang/test/Analysis/gh-issue-89185.c
new file mode 100644
index 00..8a907f198a5fd5
--- /dev/null
+++ b/clang/test/Analysis/gh-issue-89185.c
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
+
+void clang_analyzer_dump(char);
+void clang_analyzer_dump_ptr(char*);
+
+// https://github.com/llvm/llvm-project/issues/89185
+void binding_to_label_loc() {
+  char *b = &&MyLabel;
+MyLabel:
+  *b = 0; // no-crash
+  clang_analyzer_dump_ptr(b); // expected-warning {{&&MyLabel}}
+  clang_analyzer_dump(*b); // expected-warning {{Unknown}}
+  // FIXME: We should never reach here, as storing to a label is invalid.
+}

>From 739425eafcf1b7f3f1c6e41b8c102fd5eba7e0e8 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Fri, 19 Apr 2024 15:42:54 +0200
Subject: [PATCH 2/2] NFC Remove `.has_value()`

---
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp 
b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 2379db9fdb0576..54e88c07255db7 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2360,7 +2360,7 @@ RegionBindingsRef
 RegionStoreManager::bind(RegionBindingsConstRef B, Loc L, SVal V) {
   // We only care about region locations.
   auto MemRegVal = L.getAs();
-  if (!MemRegVal.has_value())
+  if (!MemRegVal)
 return B;
 
   const MemRegion *R = MemRegVal->getRegion();

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


[clang] Reapply "[Clang][Sema] placement new initializes typedef array with correct size (#83124)" (PR #89036)



@@ -12864,6 +12864,19 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 ArraySize = NewArraySize.get();
   }
 
+  // Per C++0x [expr.new]p5, the type being constructed may be a
+  // typedef of an array type.
+  QualType AllocType = AllocTypeInfo->getType();
+  if (ArraySize && E->isTypeDependent()) {

mahtohappy wrote:

No, it doesn't have value dependence. 

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


[clang] Reapply "[Clang][Sema] placement new initializes typedef array with correct size (#83124)" (PR #89036)



@@ -0,0 +1,23 @@
+// RUN: %clang --target=x86_64-pc-linux -S -fno-discard-value-names -emit-llvm 
-o - %s | FileCheck %s
+
+namespace std {

erichkeane wrote:

Tests STILL haven't changed from the original patch.  Please add the regression 
to this test as well.

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


[clang] [clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (PR #89031)



@@ -224,11 +228,8 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
 return; // PTU.takeError();
   }
 
-  if (CodeGenerator *CG = getCodeGen()) {
-std::unique_ptr M(CG->ReleaseModule());
-CG->StartModule("incr_module_" + std::to_string(PTUs.size()),
-M->getContext());
-PTU->TheModule = std::move(M);
+  if (getCodeGen()) {
+PTU->TheModule = std::move(GenModule());

hahnjo wrote:

Just to confirm my understanding of the change: this is an independent 
deduplication cleanup, right? 

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


  1   2   3   4   >