[clang] [llvm] [AMDGPU] Enable OpenCL hostcall printf (WIP) (PR #72556)

2024-01-22 Thread Sameer Sahasrabuddhe via cfe-commits


@@ -198,15 +213,31 @@ RValue 
CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E) {
 }
 
 llvm::Value *Arg = A.getRValue(*this).getScalarVal();
+if (isString(A.getType().getTypePtr()) && CGM.getLangOpts().OpenCL)
+  Arg = Builder.CreateAddrSpaceCast(Arg, CGM.Int8PtrTy);
 Args.push_back(Arg);
   }
 
-  llvm::IRBuilder<> IRB(Builder.GetInsertBlock(), Builder.GetInsertPoint());
-  IRB.SetCurrentDebugLocation(Builder.getCurrentDebugLocation());
+  auto PFK = CGM.getTarget().getTargetOpts().AMDGPUPrintfKindVal;
+  bool isBuffered =
+   (PFK == clang::TargetOptions::AMDGPUPrintfKind::Buffered);
+
+  StringRef FmtStr;
+  if (llvm::getConstantStringInfo(Args[0], FmtStr)) {
+if (FmtStr.empty())
+  FmtStr = StringRef("", 1);
+  } else {
+if (CGM.getLangOpts().OpenCL) {

ssahasra wrote:

This looks like the wrong place for a diagnostic. For an OpenCL program, 
shouldn't Sema have already verified that the arguments match the required 
types, such as "constant address space" for the format string?

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -1700,43 +1776,116 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  markSkipped(S->getIfLoc(), getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else) {
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  markSkipped(S->getIfLoc(), Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+propagateCounts(ParentCount, Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);
+const bool isTrue = E->getResultAsAPSInt().getExtValue();
+
+extendRegion(S);
+
+const auto *Init = S->getInit();
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+// ignore 'if constexpr ('
+SourceLocation startOfSkipped = S->getIfLoc();
+
+if (Init) {
+  // don't mark initialisation as ignored
+  markSkipped(startOfSkipped, getStart(Init));
+  propagateCounts(ParentCount, Init);
+  // ignore after initialisation: '; )'...
+  startOfSkipped = getEnd(Init);

cor3ntin wrote:

I don't know if we care but you can technically write  things like

```cpp
if(using foo = int; true) {}```

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -1700,43 +1776,116 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  markSkipped(S->getIfLoc(), getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else) {
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  markSkipped(S->getIfLoc(), Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+propagateCounts(ParentCount, Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);
+const bool isTrue = E->getResultAsAPSInt().getExtValue();
+
+extendRegion(S);
+
+const auto *Init = S->getInit();
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+// ignore 'if constexpr ('
+SourceLocation startOfSkipped = S->getIfLoc();
+
+if (Init) {

cor3ntin wrote:

```suggestion
if (auto *Stmt = S->getInit()) {
```

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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -1700,43 +1776,116 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility

cor3ntin wrote:

Can you reword the comment with we/passive voice/ ? 

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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread via cfe-commits
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= 
Message-ID:
In-Reply-To: 


https://github.com/cor3ntin commented:

Looks great!
I added a few comments
This probably needs another edit of the release notes

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -1700,43 +1776,116 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  markSkipped(S->getIfLoc(), getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else) {
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  markSkipped(S->getIfLoc(), Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+propagateCounts(ParentCount, Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);

cor3ntin wrote:

you can just use `cast` that is the same as dyn_cast + assert

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -1700,43 +1776,116 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  markSkipped(S->getIfLoc(), getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else) {
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  markSkipped(S->getIfLoc(), Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+propagateCounts(ParentCount, Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);
+const bool isTrue = E->getResultAsAPSInt().getExtValue();
+
+extendRegion(S);
+
+const auto *Init = S->getInit();
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+// ignore 'if constexpr ('
+SourceLocation startOfSkipped = S->getIfLoc();
+
+if (Init) {
+  // don't mark initialisation as ignored
+  markSkipped(startOfSkipped, getStart(Init));
+  propagateCounts(ParentCount, Init);
+  // ignore after initialisation: '; )'...
+  startOfSkipped = getEnd(Init);
+}
+
+if (isTrue) {
+  // ignore ')'
+  markSkipped(startOfSkipped, getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else)
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+} else {
+  // ignore ')  [else]'
+  markSkipped(startOfSkipped, Else ? getStart(Else) : getEnd(Then));
+
+  if (Else) {
+propagateCounts(ParentCount, Else);
+  }

cor3ntin wrote:

```suggestion
  if (Else)
propagateCounts(ParentCount, Else);
```

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -1700,43 +1777,116 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  markSkipped(S->getIfLoc(), getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else) {
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  markSkipped(S->getIfLoc(), Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+propagateCounts(ParentCount, Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);
+const bool isTrue = E->getResultAsAPSInt().getExtValue();
+
+extendRegion(S);
+
+const auto *Init = S->getInit();
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+// ignore 'if constexpr ('
+SourceLocation startOfSkipped = S->getIfLoc();
+
+if (Init) {
+  // don't mark initialisation as ignored
+  markSkipped(startOfSkipped, getStart(Init));
+  propagateCounts(ParentCount, Init);
+  // ignore after initialisation: '; )'...
+  startOfSkipped = getEnd(Init);
+}
+
+if (isTrue) {
+  // ignore ')'
+  markSkipped(startOfSkipped, getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else)
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+} else {
+  // ignore ')  [else]'
+  markSkipped(startOfSkipped, Else ? getStart(Else) : getEnd(Then));
+
+  if (Else) {
+propagateCounts(ParentCount, Else);
+  }
+}
+  }
+
   void VisitIfStmt(const IfStmt *S) {
+// "if constexpr" and "if consteval" are not normal conditional statements,
+// they should behave more like a preprocessor conditions
+if (S->isConsteval())
+  return CoverIfConsteval(S);
+else if (S->isConstexpr())
+  return CoverIfConstexpr(S);

cor3ntin wrote:

I like it but can we say something like "their discarded statement should be 
skipped" instead of "like a preprocessor condition"? 

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 


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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Jessica Paquette via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -1700,43 +1776,116 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {

ornata wrote:

nit: LLVM style guidelines say function names ought to be camel case, starting 
with a lower-case letter

https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

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


[clang] [libclang/python] Expose Rewriter to the python binding (PR #77269)

2024-01-22 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

@linux4life798 Nice catch! I see that so far only `CompilationDatabase` and 
`CompletionChunk` expose functions in camelCase. It would be nice to change 
them, too, but those are decade-old APIs that _I think_ we promise stability 
for, so it might not be possible.

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Jessica Paquette via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -1700,43 +1776,116 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  markSkipped(S->getIfLoc(), getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else) {
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  markSkipped(S->getIfLoc(), Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+propagateCounts(ParentCount, Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);
+const bool isTrue = E->getResultAsAPSInt().getExtValue();
+
+extendRegion(S);
+
+const auto *Init = S->getInit();
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+// ignore 'if constexpr ('
+SourceLocation startOfSkipped = S->getIfLoc();
+
+if (Init) {
+  // don't mark initialisation as ignored
+  markSkipped(startOfSkipped, getStart(Init));
+  propagateCounts(ParentCount, Init);
+  // ignore after initialisation: '; )'...
+  startOfSkipped = getEnd(Init);
+}
+
+if (isTrue) {
+  // ignore ')'
+  markSkipped(startOfSkipped, getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else)
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+} else {
+  // ignore ')  [else]'
+  markSkipped(startOfSkipped, Else ? getStart(Else) : getEnd(Then));
+
+  if (Else) {

ornata wrote:

style nit: LLVM prefers omitting braces on single-line `if`/`while`/`for`

https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements

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


[clang] Improved is simple type specifier (PR #78903)

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

owenca wrote:

> Here's the sort of approach I"m looking at @owenca

Can you restore the clang-format files for this pull request? I'll open another 
PR that depends on this one.

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


[clang] [clang][dataflow] Treat comma operator correctly in `getResultObjectLocation()`. (PR #78427)

2024-01-22 Thread via cfe-commits

martinboehme wrote:

> On the other hand, I am still wondering whether it is a good idea to expose 
> this publicly to the checks or we could do it automatically when necessary in 
> the engine code. That being said, I think the "publicness" of this API is not 
> that important to solve at this point.

You mean the publicness of `getResultObjectLocation()`?

I don't really see a good alternative. Consider the 
UncheckedOptionalAccessModel. It needs to provide its own custom transfer 
function for the constructor of an `optional`, which initializes the state of 
the optional object, and to do so, it needs to answer the question "in which 
location will this end up getting stored". Put differently, it needs to know 
what the constructor's implicit `this` argument is. That's what 
`getResultObjectLocation()` returns.

Maybe you're reacting to the verbose and slightly opaque name? I don't love the 
name either, but it kind of follows from the terms that the standard uses. 
["Result object"](https://en.cppreference.com/w/cpp/language/value_category) is 
the term that the standard uses for "what is the object that this prvalue ends 
up initializing", and given that term, `getResultObjectLocation()` is a pretty 
obvious (though verbose) name for the function.

But we'll certainly keep this on the table -- maybe we come up with a good 
alternative in the future.

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/78033

From ae319fd34659c1373ce573346b93ffaa290a3312 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Mon, 22 Jan 2024 00:00:43 +0100
Subject: [PATCH 1/5] [coverage] skipping code coverage for 'if constexpr' and
 'if consteval'

---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 212 +++---
 .../CoverageMapping/branch-constfolded.cpp|   8 +-
 clang/test/CoverageMapping/if.cpp | 138 
 .../ProfileData/Coverage/CoverageMapping.cpp  |  14 +-
 .../ProfileData/CoverageMappingTest.cpp   |  24 +-
 5 files changed, 317 insertions(+), 79 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 4a44d113ddec9e..0f0f0459406fb3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,12 +119,16 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch, or anything skipped but not empty line / comments)
+  bool SkippedRegion;
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
   bool GapRegion = false)
-  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) 
{
-  }
+  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(Counter Count, std::optional FalseCount,
   MCDCParameters MCDCParams,
@@ -132,13 +136,14 @@ class SourceMappingRegion {
   std::optional LocEnd,
   bool GapRegion = false)
   : Count(Count), FalseCount(FalseCount), MCDCParams(MCDCParams),
-LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) {}
+LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(MCDCParameters MCDCParams,
   std::optional LocStart,
   std::optional LocEnd)
   : MCDCParams(MCDCParams), LocStart(LocStart), LocEnd(LocEnd),
-GapRegion(false) {}
+GapRegion(false), SkippedRegion(false) {}
 
   const Counter &getCounter() const { return Count; }
 
@@ -174,6 +179,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +477,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1251,6 +1264,70 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Find a valid range starting with \p StartingLoc and ending before \p
+  /// BeforeLoc.
+  std::optional findAreaStartingFromTo(SourceLocation StartingLoc,
+SourceLocation BeforeLoc) {
+// If StartingLoc is in function-like macro, use its start location.
+if (StartingLoc.isMacroID()) {
+  FileID FID = SM.getFileID(StartingLoc);
+  const SrcMgr::ExpansionInfo *EI = &SM.getSLocEntry(FID).getExpansion();
+  if (EI->isFunctionMacroExpansion())
+StartingLoc = EI->getExpansionLocStart();
+}
+
+size_t StartDepth = locationDepth(StartingLoc);
+size_t EndDepth = locationDepth(BeforeLoc);
+while (!SM.isWrittenInSameFile(StartingLoc, BeforeLoc)) {
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+assert(SM.isWrittenInSameFile(getStartOfFileOrMacro(BeforeLoc),
+  BeforeLoc));
+
+BeforeLoc = getIncludeOrExpansionLoc(BeforeLoc);
+assert(BeforeLoc.isValid());
+EndDepth--;
+  }
+  if (UnnestStart) {
+assert(SM.isWrittenInSameFile(StartingLoc,
+  getStartOfFileOrMacro(StartingLoc)));
+
+StartingLoc = getIncludeOrExpansionLoc(StartingLoc);
+assert(StartingLoc.isValid());
+StartDepth--;
+  }
+}
+// If the start and end locations of 

[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Jessica Paquette via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -1251,6 +1264,69 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Find a valid range starting with \p StartingLoc and ending before \p
+  /// BeforeLoc.
+  std::optional findAreaStartingFromTo(SourceLocation StartingLoc,
+SourceLocation BeforeLoc) {
+// If StartingLoc is in function-like macro, use its start location.
+if (StartingLoc.isMacroID()) {
+  FileID FID = SM.getFileID(StartingLoc);
+  const SrcMgr::ExpansionInfo *EI = &SM.getSLocEntry(FID).getExpansion();
+  if (EI->isFunctionMacroExpansion())
+StartingLoc = EI->getExpansionLocStart();
+}
+
+size_t StartDepth = locationDepth(StartingLoc);
+size_t EndDepth = locationDepth(BeforeLoc);
+while (!SM.isWrittenInSameFile(StartingLoc, BeforeLoc)) {
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {

ornata wrote:

Could you add a comment explaining `UnnestStart` and `UnnestEnd`?

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-22 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> Would you like to give an reproducer so that I can debug?

Not easily at the moment, unless you want to go through building the entirety 
of ROOT :-/

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/78033

From ae319fd34659c1373ce573346b93ffaa290a3312 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Mon, 22 Jan 2024 00:00:43 +0100
Subject: [PATCH 1/6] [coverage] skipping code coverage for 'if constexpr' and
 'if consteval'

---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 212 +++---
 .../CoverageMapping/branch-constfolded.cpp|   8 +-
 clang/test/CoverageMapping/if.cpp | 138 
 .../ProfileData/Coverage/CoverageMapping.cpp  |  14 +-
 .../ProfileData/CoverageMappingTest.cpp   |  24 +-
 5 files changed, 317 insertions(+), 79 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 4a44d113ddec9e..0f0f0459406fb3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,12 +119,16 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch, or anything skipped but not empty line / comments)
+  bool SkippedRegion;
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
   bool GapRegion = false)
-  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) 
{
-  }
+  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(Counter Count, std::optional FalseCount,
   MCDCParameters MCDCParams,
@@ -132,13 +136,14 @@ class SourceMappingRegion {
   std::optional LocEnd,
   bool GapRegion = false)
   : Count(Count), FalseCount(FalseCount), MCDCParams(MCDCParams),
-LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) {}
+LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(MCDCParameters MCDCParams,
   std::optional LocStart,
   std::optional LocEnd)
   : MCDCParams(MCDCParams), LocStart(LocStart), LocEnd(LocEnd),
-GapRegion(false) {}
+GapRegion(false), SkippedRegion(false) {}
 
   const Counter &getCounter() const { return Count; }
 
@@ -174,6 +179,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +477,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1251,6 +1264,70 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Find a valid range starting with \p StartingLoc and ending before \p
+  /// BeforeLoc.
+  std::optional findAreaStartingFromTo(SourceLocation StartingLoc,
+SourceLocation BeforeLoc) {
+// If StartingLoc is in function-like macro, use its start location.
+if (StartingLoc.isMacroID()) {
+  FileID FID = SM.getFileID(StartingLoc);
+  const SrcMgr::ExpansionInfo *EI = &SM.getSLocEntry(FID).getExpansion();
+  if (EI->isFunctionMacroExpansion())
+StartingLoc = EI->getExpansionLocStart();
+}
+
+size_t StartDepth = locationDepth(StartingLoc);
+size_t EndDepth = locationDepth(BeforeLoc);
+while (!SM.isWrittenInSameFile(StartingLoc, BeforeLoc)) {
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+assert(SM.isWrittenInSameFile(getStartOfFileOrMacro(BeforeLoc),
+  BeforeLoc));
+
+BeforeLoc = getIncludeOrExpansionLoc(BeforeLoc);
+assert(BeforeLoc.isValid());
+EndDepth--;
+  }
+  if (UnnestStart) {
+assert(SM.isWrittenInSameFile(StartingLoc,
+  getStartOfFileOrMacro(StartingLoc)));
+
+StartingLoc = getIncludeOrExpansionLoc(StartingLoc);
+assert(StartingLoc.isValid());
+StartDepth--;
+  }
+}
+// If the start and end locations of 

[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Jessica Paquette via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -174,6 +179,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }

ornata wrote:

Unrelated to this patch: I wonder if `SkippedRegion` is being used elsewhere. 
This could be nice clean up.

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


[clang] 234da20 - [Analysis] Use StringRef::ends_with_insensitive (NFC)

2024-01-22 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-01-22T00:13:27-08:00
New Revision: 234da203779be31c83541d99ee28e01ee422c506

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

LOG: [Analysis] Use StringRef::ends_with_insensitive (NFC)

Added: 


Modified: 
clang/lib/Analysis/RetainSummaryManager.cpp

Removed: 




diff  --git a/clang/lib/Analysis/RetainSummaryManager.cpp 
b/clang/lib/Analysis/RetainSummaryManager.cpp
index 6f50d95b179f41..8d279d969b613e 100644
--- a/clang/lib/Analysis/RetainSummaryManager.cpp
+++ b/clang/lib/Analysis/RetainSummaryManager.cpp
@@ -1098,7 +1098,7 @@ RetainSummaryManager::getStandardMethodSummary(const 
ObjCMethodDecl *MD,
   if (S.isKeywordSelector()) {
 for (unsigned i = 0, e = S.getNumArgs(); i != e; ++i) {
   StringRef Slot = S.getNameForSlot(i);
-  if (Slot.substr(Slot.size() - 8).equals_insensitive("delegate")) {
+  if (Slot.ends_with_insensitive("delegate")) {
 if (ResultEff == ObjCInitRetE)
   ResultEff = RetEffect::MakeNoRetHard();
 else



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


[clang-tools-extra] a54463a - [clang-tidy] Use llvm::any_of (NFC)

2024-01-22 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-01-22T00:13:29-08:00
New Revision: a54463a4c6c32810b064e02b39e2c8f0de974006

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

LOG: [clang-tidy] Use llvm::any_of (NFC)

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
index 865c88391b0b4b..ff5b885aa95f81 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
@@ -46,7 +46,7 @@ AST_MATCHER_P(CompoundStmt, hasAnyTextFromList, 
std::vector,
   StringRef Text = Lexer::getSourceText(
   CharSourceRange::getTokenRange(Node.getSourceRange()), SM,
   Context.getLangOpts());
-  return std::any_of(List.begin(), List.end(), [&](const StringRef &Str) {
+  return llvm::any_of(List, [&](const StringRef &Str) {
 return Text.contains_insensitive(Str);
   });
 }



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


[clang] [clang-format] Add MainIncludeChar option. (PR #78752)

2024-01-22 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata updated 
https://github.com/llvm/llvm-project/pull/78752

>From b6284b7498a283d28bfd5025897041dee23354c8 Mon Sep 17 00:00:00 2001
From: Julien Jorge 
Date: Fri, 19 Jan 2024 18:44:58 +0100
Subject: [PATCH] [clang-format] Add MainIncludeChar option.

Resolves #27008, #39735, #53013, #63619.
---
 clang/docs/ClangFormatStyleOptions.rst|  19 
 clang/include/clang/Format/Format.h   |   1 +
 .../clang/Tooling/Inclusions/IncludeStyle.h   |  23 
 clang/lib/Format/Format.cpp   |   2 +
 .../lib/Tooling/Inclusions/HeaderIncludes.cpp |  14 ++-
 clang/lib/Tooling/Inclusions/IncludeStyle.cpp |   7 ++
 clang/unittests/Format/SortIncludesTest.cpp   | 106 ++
 7 files changed, 170 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f265..ac74db2c2bdf58 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4116,6 +4116,25 @@ the configuration (without a prefix: ``Auto``).
  A(z); -> z;
  A(a, b); // will not be expanded.
 
+.. _MainIncludeChar:
+
+**MainIncludeChar** (``MainIncludeCharDiscriminator``) 
:versionbadge:`clang-format 18` :ref:`¶ `
+  When guessing whether a #include is the "main" include, only the include
+  directives that use the specified character are considered.
+
+  Possible values:
+
+  * ``MICD_Quote`` (in configuration: ``Quote``)
+Main include uses quotes: ``#include "foo.hpp"`` (the default).
+
+  * ``MICD_AngleBracket`` (in configuration: ``AngleBracket``)
+Main include uses angle brackets: ``#include ``.
+
+  * ``MICD_Any`` (in configuration: ``Any``)
+Main include uses either quotes or angle brackets.
+
+
+
 .. _MaxEmptyLinesToKeep:
 
 **MaxEmptyLinesToKeep** (``Unsigned``) :versionbadge:`clang-format 3.7` 
:ref:`¶ `
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc9eecd42f9ebf..a37d5f28c53e9b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4842,6 +4842,7 @@ struct FormatStyle {
R.IncludeStyle.IncludeIsMainRegex &&
IncludeStyle.IncludeIsMainSourceRegex ==
R.IncludeStyle.IncludeIsMainSourceRegex &&
+   IncludeStyle.MainIncludeChar == R.IncludeStyle.MainIncludeChar &&
IndentAccessModifiers == R.IndentAccessModifiers &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentCaseLabels == R.IndentCaseLabels &&
diff --git a/clang/include/clang/Tooling/Inclusions/IncludeStyle.h 
b/clang/include/clang/Tooling/Inclusions/IncludeStyle.h
index d6b2b0192477dc..c91e4a6b0ac54a 100644
--- a/clang/include/clang/Tooling/Inclusions/IncludeStyle.h
+++ b/clang/include/clang/Tooling/Inclusions/IncludeStyle.h
@@ -151,6 +151,21 @@ struct IncludeStyle {
   /// before any other include.
   /// \version 10
   std::string IncludeIsMainSourceRegex;
+
+  /// Character to consider in the include directives for the main header.
+  enum MainIncludeCharDiscriminator : int8_t {
+/// Main include uses quotes: ``#include "foo.hpp"`` (the default).
+MICD_Quote,
+/// Main include uses angle brackets: ``#include ``.
+MICD_AngleBracket,
+/// Main include uses either quotes or angle brackets.
+MICD_Any
+  };
+
+  /// When guessing whether a #include is the "main" include, only the include
+  /// directives that use the specified character are considered.
+  /// \version 18
+  MainIncludeCharDiscriminator MainIncludeChar;
 };
 
 } // namespace tooling
@@ -174,6 +189,14 @@ struct ScalarEnumerationTraits<
   enumeration(IO &IO, clang::tooling::IncludeStyle::IncludeBlocksStyle &Value);
 };
 
+template <>
+struct ScalarEnumerationTraits<
+clang::tooling::IncludeStyle::MainIncludeCharDiscriminator> {
+  static void enumeration(
+  IO &IO,
+  clang::tooling::IncludeStyle::MainIncludeCharDiscriminator &Value);
+};
+
 } // namespace yaml
 } // namespace llvm
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff326dc784783b..3d0eaf74e14dba 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1032,6 +1032,7 @@ template <> struct MappingTraits {
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("Macros", Style.Macros);
+IO.mapOptional("MainIncludeChar", Style.IncludeStyle.MainIncludeChar);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
 IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation);
 IO.mapOptional("NamespaceMacros", Style.NamespaceMacros);
@@ -1515,6 +1516,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   {".*", 1, 0, false}};
   LLVMStyle.IncludeStyle.IncludeIsMainRegex = "(Test)?$";
   LLVMStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  LLVMStyle.

[clang] [clang-format] Add MainIncludeChar option. (PR #78752)

2024-01-22 Thread via cfe-commits

https://github.com/j-jorge updated 
https://github.com/llvm/llvm-project/pull/78752

>From b6284b7498a283d28bfd5025897041dee23354c8 Mon Sep 17 00:00:00 2001
From: Julien Jorge 
Date: Fri, 19 Jan 2024 18:44:58 +0100
Subject: [PATCH] [clang-format] Add MainIncludeChar option.

Resolves #27008, #39735, #53013, #63619.
---
 clang/docs/ClangFormatStyleOptions.rst|  19 
 clang/include/clang/Format/Format.h   |   1 +
 .../clang/Tooling/Inclusions/IncludeStyle.h   |  23 
 clang/lib/Format/Format.cpp   |   2 +
 .../lib/Tooling/Inclusions/HeaderIncludes.cpp |  14 ++-
 clang/lib/Tooling/Inclusions/IncludeStyle.cpp |   7 ++
 clang/unittests/Format/SortIncludesTest.cpp   | 106 ++
 7 files changed, 170 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f265..ac74db2c2bdf58 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4116,6 +4116,25 @@ the configuration (without a prefix: ``Auto``).
  A(z); -> z;
  A(a, b); // will not be expanded.
 
+.. _MainIncludeChar:
+
+**MainIncludeChar** (``MainIncludeCharDiscriminator``) 
:versionbadge:`clang-format 18` :ref:`¶ `
+  When guessing whether a #include is the "main" include, only the include
+  directives that use the specified character are considered.
+
+  Possible values:
+
+  * ``MICD_Quote`` (in configuration: ``Quote``)
+Main include uses quotes: ``#include "foo.hpp"`` (the default).
+
+  * ``MICD_AngleBracket`` (in configuration: ``AngleBracket``)
+Main include uses angle brackets: ``#include ``.
+
+  * ``MICD_Any`` (in configuration: ``Any``)
+Main include uses either quotes or angle brackets.
+
+
+
 .. _MaxEmptyLinesToKeep:
 
 **MaxEmptyLinesToKeep** (``Unsigned``) :versionbadge:`clang-format 3.7` 
:ref:`¶ `
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc9eecd42f9ebf..a37d5f28c53e9b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4842,6 +4842,7 @@ struct FormatStyle {
R.IncludeStyle.IncludeIsMainRegex &&
IncludeStyle.IncludeIsMainSourceRegex ==
R.IncludeStyle.IncludeIsMainSourceRegex &&
+   IncludeStyle.MainIncludeChar == R.IncludeStyle.MainIncludeChar &&
IndentAccessModifiers == R.IndentAccessModifiers &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentCaseLabels == R.IndentCaseLabels &&
diff --git a/clang/include/clang/Tooling/Inclusions/IncludeStyle.h 
b/clang/include/clang/Tooling/Inclusions/IncludeStyle.h
index d6b2b0192477dc..c91e4a6b0ac54a 100644
--- a/clang/include/clang/Tooling/Inclusions/IncludeStyle.h
+++ b/clang/include/clang/Tooling/Inclusions/IncludeStyle.h
@@ -151,6 +151,21 @@ struct IncludeStyle {
   /// before any other include.
   /// \version 10
   std::string IncludeIsMainSourceRegex;
+
+  /// Character to consider in the include directives for the main header.
+  enum MainIncludeCharDiscriminator : int8_t {
+/// Main include uses quotes: ``#include "foo.hpp"`` (the default).
+MICD_Quote,
+/// Main include uses angle brackets: ``#include ``.
+MICD_AngleBracket,
+/// Main include uses either quotes or angle brackets.
+MICD_Any
+  };
+
+  /// When guessing whether a #include is the "main" include, only the include
+  /// directives that use the specified character are considered.
+  /// \version 18
+  MainIncludeCharDiscriminator MainIncludeChar;
 };
 
 } // namespace tooling
@@ -174,6 +189,14 @@ struct ScalarEnumerationTraits<
   enumeration(IO &IO, clang::tooling::IncludeStyle::IncludeBlocksStyle &Value);
 };
 
+template <>
+struct ScalarEnumerationTraits<
+clang::tooling::IncludeStyle::MainIncludeCharDiscriminator> {
+  static void enumeration(
+  IO &IO,
+  clang::tooling::IncludeStyle::MainIncludeCharDiscriminator &Value);
+};
+
 } // namespace yaml
 } // namespace llvm
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff326dc784783b..3d0eaf74e14dba 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1032,6 +1032,7 @@ template <> struct MappingTraits {
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("Macros", Style.Macros);
+IO.mapOptional("MainIncludeChar", Style.IncludeStyle.MainIncludeChar);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
 IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation);
 IO.mapOptional("NamespaceMacros", Style.NamespaceMacros);
@@ -1515,6 +1516,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   {".*", 1, 0, false}};
   LLVMStyle.IncludeStyle.IncludeIsMainRegex = "(Test)?$";
   LLVMStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  LLVMStyle.Include

[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

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

owenca wrote:

> You either have to use a new option, or adapt the documentation. Latter 
> clearly only refers to `C++11 attributes`, which `__attribute__(())` isn't.
> 
> I don't think a new option is needed.
> 
> When you are already at it, you may also consider handling `__declspec()`.

+1.

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/78033

From ae319fd34659c1373ce573346b93ffaa290a3312 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Mon, 22 Jan 2024 00:00:43 +0100
Subject: [PATCH 1/7] [coverage] skipping code coverage for 'if constexpr' and
 'if consteval'

---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 212 +++---
 .../CoverageMapping/branch-constfolded.cpp|   8 +-
 clang/test/CoverageMapping/if.cpp | 138 
 .../ProfileData/Coverage/CoverageMapping.cpp  |  14 +-
 .../ProfileData/CoverageMappingTest.cpp   |  24 +-
 5 files changed, 317 insertions(+), 79 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 4a44d113ddec9e..0f0f0459406fb3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,12 +119,16 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch, or anything skipped but not empty line / comments)
+  bool SkippedRegion;
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
   bool GapRegion = false)
-  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) 
{
-  }
+  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(Counter Count, std::optional FalseCount,
   MCDCParameters MCDCParams,
@@ -132,13 +136,14 @@ class SourceMappingRegion {
   std::optional LocEnd,
   bool GapRegion = false)
   : Count(Count), FalseCount(FalseCount), MCDCParams(MCDCParams),
-LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) {}
+LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(MCDCParameters MCDCParams,
   std::optional LocStart,
   std::optional LocEnd)
   : MCDCParams(MCDCParams), LocStart(LocStart), LocEnd(LocEnd),
-GapRegion(false) {}
+GapRegion(false), SkippedRegion(false) {}
 
   const Counter &getCounter() const { return Count; }
 
@@ -174,6 +179,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +477,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1251,6 +1264,70 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Find a valid range starting with \p StartingLoc and ending before \p
+  /// BeforeLoc.
+  std::optional findAreaStartingFromTo(SourceLocation StartingLoc,
+SourceLocation BeforeLoc) {
+// If StartingLoc is in function-like macro, use its start location.
+if (StartingLoc.isMacroID()) {
+  FileID FID = SM.getFileID(StartingLoc);
+  const SrcMgr::ExpansionInfo *EI = &SM.getSLocEntry(FID).getExpansion();
+  if (EI->isFunctionMacroExpansion())
+StartingLoc = EI->getExpansionLocStart();
+}
+
+size_t StartDepth = locationDepth(StartingLoc);
+size_t EndDepth = locationDepth(BeforeLoc);
+while (!SM.isWrittenInSameFile(StartingLoc, BeforeLoc)) {
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+assert(SM.isWrittenInSameFile(getStartOfFileOrMacro(BeforeLoc),
+  BeforeLoc));
+
+BeforeLoc = getIncludeOrExpansionLoc(BeforeLoc);
+assert(BeforeLoc.isValid());
+EndDepth--;
+  }
+  if (UnnestStart) {
+assert(SM.isWrittenInSameFile(StartingLoc,
+  getStartOfFileOrMacro(StartingLoc)));
+
+StartingLoc = getIncludeOrExpansionLoc(StartingLoc);
+assert(StartingLoc.isValid());
+StartDepth--;
+  }
+}
+// If the start and end locations of 

[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits


@@ -1700,43 +1776,116 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  markSkipped(S->getIfLoc(), getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else) {
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  markSkipped(S->getIfLoc(), Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+propagateCounts(ParentCount, Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);
+const bool isTrue = E->getResultAsAPSInt().getExtValue();
+
+extendRegion(S);
+
+const auto *Init = S->getInit();
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+// ignore 'if constexpr ('
+SourceLocation startOfSkipped = S->getIfLoc();
+
+if (Init) {
+  // don't mark initialisation as ignored
+  markSkipped(startOfSkipped, getStart(Init));
+  propagateCounts(ParentCount, Init);
+  // ignore after initialisation: '; )'...
+  startOfSkipped = getEnd(Init);

hanickadot wrote:

yes, and it will be dealt as with declaration, in `propagateCounts` it will 
recurse into it

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


[clang] [clang] Update documentation for `#pragma diagnostic` (PR #78095)

2024-01-22 Thread Vlad Serebrennikov via cfe-commits

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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits


@@ -174,6 +179,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }

hanickadot wrote:

SkippedRegions are also created by preprocessor for comments and whitespaces, 
then they are squeezed out of line with any coverage. This patch allows making 
them also while walking AST and fixes `LineCoverageStats` to properly show such 
lines as mapped.

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


[clang] [clang] Update documentation for `#pragma diagnostic` (PR #78095)

2024-01-22 Thread Vlad Serebrennikov via cfe-commits

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


[llvm] [clang] [RISCV] Add Zicfiss support to the shadow call stack implementation. (PR #68075)

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

yetingk wrote:

Ping.

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


[clang] a2caa49 - [clang][dataflow] Treat comma operator correctly in `getResultObjectLocation()`. (#78427)

2024-01-22 Thread via cfe-commits

Author: martinboehme
Date: 2024-01-22T09:23:06+01:00
New Revision: a2caa4929e8e8a24ee5f03ab37a9be7462a0

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

LOG: [clang][dataflow] Treat comma operator correctly in 
`getResultObjectLocation()`. (#78427)

Added: 


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

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 07dc3a9f76ac23..196a1360a7750a 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -782,8 +782,13 @@ Environment::getResultObjectLocation(const Expr 
&RecordPRValue) const {
 return Val->getLoc();
   }
 
-  // Expression nodes that propagate a record prvalue should have exactly one
-  // child.
+  if (auto *Op = dyn_cast(&RecordPRValue);
+  Op && Op->isCommaOp()) {
+return getResultObjectLocation(*Op->getRHS());
+  }
+
+  // All other expression nodes that propagate a record prvalue should have
+  // exactly one child.
   llvm::SmallVector children(RecordPRValue.child_begin(),
RecordPRValue.child_end());
   assert(children.size() == 1);

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index d0a0e6d3f58364..85ae24f0b6f165 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2642,14 +2642,17 @@ TEST(TransferTest, ResultObjectLocation) {
 };
 
 void target() {
-  A();
+  0, A();
   (void)0; // [[p]]
 }
   )";
+  using ast_matchers::binaryOperator;
   using ast_matchers::cxxBindTemporaryExpr;
   using ast_matchers::cxxTemporaryObjectExpr;
   using ast_matchers::exprWithCleanups;
   using ast_matchers::has;
+  using ast_matchers::hasOperatorName;
+  using ast_matchers::hasRHS;
   using ast_matchers::match;
   using ast_matchers::selectFirst;
   using ast_matchers::traverse;
@@ -2659,26 +2662,33 @@ TEST(TransferTest, ResultObjectLocation) {
  ASTContext &ASTCtx) {
 const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
 
-// The expresssion `A()` in the code above produces the following
-// structure, consisting of three prvalues of record type.
+// The expression `0, A()` in the code above produces the following
+// structure, consisting of four prvalues of record type.
 // `Env.getResultObjectLocation()` should return the same location for
 // all of these.
 auto MatchResult = match(
 traverse(TK_AsIs,
  exprWithCleanups(
- has(cxxBindTemporaryExpr(
- has(cxxTemporaryObjectExpr().bind("toe")))
- .bind("bte")))
+ has(binaryOperator(
+ hasOperatorName(","),
+ hasRHS(cxxBindTemporaryExpr(
+has(cxxTemporaryObjectExpr().bind(
+"toe")))
+.bind("bte")))
+ .bind("comma")))
  .bind("ewc")),
 ASTCtx);
 auto *TOE = selectFirst("toe", MatchResult);
 ASSERT_NE(TOE, nullptr);
+auto *Comma = selectFirst("comma", MatchResult);
+ASSERT_NE(Comma, nullptr);
 auto *EWC = selectFirst("ewc", MatchResult);
 ASSERT_NE(EWC, nullptr);
 auto *BTE = selectFirst("bte", MatchResult);
 ASSERT_NE(BTE, nullptr);
 
 RecordStorageLocation &Loc = Env.getResultObjectLocation(*TOE);
+EXPECT_EQ(&Loc, &Env.getResultObjectLocation(*Comma));
 EXPECT_EQ(&Loc, &Env.getResultObjectLocation(*EWC));
 EXPECT_EQ(&Loc, &Env.getResultObjectLocation(*BTE));
   });



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


[clang] [clang][dataflow] Treat comma operator correctly in `getResultObjectLocation()`. (PR #78427)

2024-01-22 Thread via cfe-commits

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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/78033

From ae319fd34659c1373ce573346b93ffaa290a3312 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Mon, 22 Jan 2024 00:00:43 +0100
Subject: [PATCH 1/5] [coverage] skipping code coverage for 'if constexpr' and
 'if consteval'

---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 212 +++---
 .../CoverageMapping/branch-constfolded.cpp|   8 +-
 clang/test/CoverageMapping/if.cpp | 138 
 .../ProfileData/Coverage/CoverageMapping.cpp  |  14 +-
 .../ProfileData/CoverageMappingTest.cpp   |  24 +-
 5 files changed, 317 insertions(+), 79 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 4a44d113ddec9e..0f0f0459406fb3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,12 +119,16 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch, or anything skipped but not empty line / comments)
+  bool SkippedRegion;
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
   bool GapRegion = false)
-  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) 
{
-  }
+  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(Counter Count, std::optional FalseCount,
   MCDCParameters MCDCParams,
@@ -132,13 +136,14 @@ class SourceMappingRegion {
   std::optional LocEnd,
   bool GapRegion = false)
   : Count(Count), FalseCount(FalseCount), MCDCParams(MCDCParams),
-LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) {}
+LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(MCDCParameters MCDCParams,
   std::optional LocStart,
   std::optional LocEnd)
   : MCDCParams(MCDCParams), LocStart(LocStart), LocEnd(LocEnd),
-GapRegion(false) {}
+GapRegion(false), SkippedRegion(false) {}
 
   const Counter &getCounter() const { return Count; }
 
@@ -174,6 +179,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +477,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1251,6 +1264,70 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Find a valid range starting with \p StartingLoc and ending before \p
+  /// BeforeLoc.
+  std::optional findAreaStartingFromTo(SourceLocation StartingLoc,
+SourceLocation BeforeLoc) {
+// If StartingLoc is in function-like macro, use its start location.
+if (StartingLoc.isMacroID()) {
+  FileID FID = SM.getFileID(StartingLoc);
+  const SrcMgr::ExpansionInfo *EI = &SM.getSLocEntry(FID).getExpansion();
+  if (EI->isFunctionMacroExpansion())
+StartingLoc = EI->getExpansionLocStart();
+}
+
+size_t StartDepth = locationDepth(StartingLoc);
+size_t EndDepth = locationDepth(BeforeLoc);
+while (!SM.isWrittenInSameFile(StartingLoc, BeforeLoc)) {
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+assert(SM.isWrittenInSameFile(getStartOfFileOrMacro(BeforeLoc),
+  BeforeLoc));
+
+BeforeLoc = getIncludeOrExpansionLoc(BeforeLoc);
+assert(BeforeLoc.isValid());
+EndDepth--;
+  }
+  if (UnnestStart) {
+assert(SM.isWrittenInSameFile(StartingLoc,
+  getStartOfFileOrMacro(StartingLoc)));
+
+StartingLoc = getIncludeOrExpansionLoc(StartingLoc);
+assert(StartingLoc.isValid());
+StartDepth--;
+  }
+}
+// If the start and end locations of 

[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits


@@ -1251,6 +1264,69 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Find a valid range starting with \p StartingLoc and ending before \p
+  /// BeforeLoc.
+  std::optional findAreaStartingFromTo(SourceLocation StartingLoc,
+SourceLocation BeforeLoc) {
+// If StartingLoc is in function-like macro, use its start location.
+if (StartingLoc.isMacroID()) {
+  FileID FID = SM.getFileID(StartingLoc);
+  const SrcMgr::ExpansionInfo *EI = &SM.getSLocEntry(FID).getExpansion();
+  if (EI->isFunctionMacroExpansion())
+StartingLoc = EI->getExpansionLocStart();
+}
+
+size_t StartDepth = locationDepth(StartingLoc);
+size_t EndDepth = locationDepth(BeforeLoc);
+while (!SM.isWrittenInSameFile(StartingLoc, BeforeLoc)) {
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {

hanickadot wrote:

it's a pattern used thru whole `CoverageMappingGen.cpp` file, it's copied and 
modified existing functions for calculating Gap regions, so I would rather not

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


[flang] [clang] [flang]Add support for -moutline-atomics and -mno-outline-atomics (PR #78755)

2024-01-22 Thread Andrzej Warzyński via cfe-commits


@@ -354,6 +354,27 @@ void Flang::addTargetOptions(const ArgList &Args,
 CmdArgs.push_back(Args.MakeArgString(CPU));
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
+   options::OPT_mno_outline_atomics)) {
+// Option -moutline-atomics supported for AArch64 target only.
+if (!Triple.isAArch64()) {
+  D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
+  << Triple.getArchName() << A->getOption().getName();
+} else {
+  if (A->getOption().matches(options::OPT_moutline_atomics)) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+outline-atomics");
+  } else {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("-outline-atomics");
+  }
+}
+  } else if (Triple.isAArch64() &&
+ getToolChain().IsAArch64OutlineAtomicsDefault(Args)) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+outline-atomics");
+  }

banach-space wrote:

That's usually done in places like 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/CommonArgs.cpp

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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/78033

From ae319fd34659c1373ce573346b93ffaa290a3312 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Mon, 22 Jan 2024 00:00:43 +0100
Subject: [PATCH 1/6] [coverage] skipping code coverage for 'if constexpr' and
 'if consteval'

---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 212 +++---
 .../CoverageMapping/branch-constfolded.cpp|   8 +-
 clang/test/CoverageMapping/if.cpp | 138 
 .../ProfileData/Coverage/CoverageMapping.cpp  |  14 +-
 .../ProfileData/CoverageMappingTest.cpp   |  24 +-
 5 files changed, 317 insertions(+), 79 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 4a44d113ddec9e8..0f0f0459406fb32 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,12 +119,16 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch, or anything skipped but not empty line / comments)
+  bool SkippedRegion;
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
   bool GapRegion = false)
-  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) 
{
-  }
+  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(Counter Count, std::optional FalseCount,
   MCDCParameters MCDCParams,
@@ -132,13 +136,14 @@ class SourceMappingRegion {
   std::optional LocEnd,
   bool GapRegion = false)
   : Count(Count), FalseCount(FalseCount), MCDCParams(MCDCParams),
-LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) {}
+LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(MCDCParameters MCDCParams,
   std::optional LocStart,
   std::optional LocEnd)
   : MCDCParams(MCDCParams), LocStart(LocStart), LocEnd(LocEnd),
-GapRegion(false) {}
+GapRegion(false), SkippedRegion(false) {}
 
   const Counter &getCounter() const { return Count; }
 
@@ -174,6 +179,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +477,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1251,6 +1264,70 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Find a valid range starting with \p StartingLoc and ending before \p
+  /// BeforeLoc.
+  std::optional findAreaStartingFromTo(SourceLocation StartingLoc,
+SourceLocation BeforeLoc) {
+// If StartingLoc is in function-like macro, use its start location.
+if (StartingLoc.isMacroID()) {
+  FileID FID = SM.getFileID(StartingLoc);
+  const SrcMgr::ExpansionInfo *EI = &SM.getSLocEntry(FID).getExpansion();
+  if (EI->isFunctionMacroExpansion())
+StartingLoc = EI->getExpansionLocStart();
+}
+
+size_t StartDepth = locationDepth(StartingLoc);
+size_t EndDepth = locationDepth(BeforeLoc);
+while (!SM.isWrittenInSameFile(StartingLoc, BeforeLoc)) {
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+assert(SM.isWrittenInSameFile(getStartOfFileOrMacro(BeforeLoc),
+  BeforeLoc));
+
+BeforeLoc = getIncludeOrExpansionLoc(BeforeLoc);
+assert(BeforeLoc.isValid());
+EndDepth--;
+  }
+  if (UnnestStart) {
+assert(SM.isWrittenInSameFile(StartingLoc,
+  getStartOfFileOrMacro(StartingLoc)));
+
+StartingLoc = getIncludeOrExpansionLoc(StartingLoc);
+assert(StartingLoc.isValid());
+StartDepth--;
+  }
+}
+// If the start and end locations o

[clang] 8658d15 - Revert "[Clang][Sema] Diagnose function/variable templates that shadow their own template parameters (#78274)"

2024-01-22 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-01-22T09:29:01+01:00
New Revision: 8658d157654832fe24b4f3d2a9a62784a4d6a162

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

LOG: Revert "[Clang][Sema] Diagnose function/variable templates that shadow 
their own template parameters (#78274)"

This reverts commit fc0253264445be7f88d4cf0f9129dcb10c2fb84b.

This errors is disruptive to downstream projects
and should be reintroduced as a separate on-by-default
warning.

https://github.com/llvm/llvm-project/pull/78274

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/CXX/temp/temp.res/temp.local/p6.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2c7c7b8a21b8e74..7c9f9ecca727a48 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -590,7 +590,6 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses the requirement that non-template friend declarations 
with requires clauses
   and template friend declarations with a constraint that depends on a 
template parameter from an
   enclosing template must be a definition.
-- Clang now diagnoses function/variable templates that shadow their own 
template parameters, e.g. ``template void T();``.
 - Clang now diagnoses incorrect usage of ``const`` and ``pure`` attributes, so 
``-Wignored-attributes`` diagnoses more cases.
 - Clang now emits more descriptive diagnostics for 'unusual' expressions (e.g. 
incomplete index
   expressions on matrix types or builtin functions without an argument list) 
as placement-args

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8dff2cdc063df32..13ca438e6a487fe 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6377,6 +6377,12 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator 
&D,
   } else if (DiagnoseUnexpandedParameterPack(NameInfo, UPPC_DeclarationType))
 return nullptr;
 
+  // The scope passed in may not be a decl scope.  Zip up the scope tree until
+  // we find one that is.
+  while ((S->getFlags() & Scope::DeclScope) == 0 ||
+ (S->getFlags() & Scope::TemplateParamScope) != 0)
+S = S->getParent();
+
   DeclContext *DC = CurContext;
   if (D.getCXXScopeSpec().isInvalid())
 D.setInvalidType();
@@ -6529,12 +6535,6 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator 
&D,
   if (getLangOpts().CPlusPlus)
 CheckExtraCXXDefaultArguments(D);
 
-  // The scope passed in may not be a decl scope.  Zip up the scope tree until
-  // we find one that is.
-  while ((S->getFlags() & Scope::DeclScope) == 0 ||
- (S->getFlags() & Scope::TemplateParamScope) != 0)
-S = S->getParent();
-
   NamedDecl *New;
 
   bool AddToScope = true;

diff  --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index 0702966e5685480..e2aa0ff344291d2 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -127,30 +127,16 @@ template struct Z { // expected-note 16{{declared 
here}}
 template // expected-note {{declared here}}
 void f(int T) {} // expected-error {{declaration of 'T' shadows template 
parameter}}
 
+// FIXME: These are ill-formed: a template-parameter shall not have the same 
name as the template name.
 namespace A {
   template struct T {};  // expected-error{{declaration of 'T' 
shadows template parameter}}
  // expected-note@-1{{template parameter 
is declared here}}
-  template struct U {
-template struct V {}; // expected-error{{declaration of 'V' 
shadows template parameter}}
-  // expected-note@-1{{template parameter 
is declared here}}
-  };
 }
 namespace B {
-  template void T() {} // expected-error{{declaration of 'T' 
shadows template parameter}}
-   // expected-note@-1{{template parameter is 
declared here}}
-
-  template struct U {
-template void V(); // expected-error{{declaration of 'V' 
shadows template parameter}}
-   // expected-note@-1{{template parameter is 
declared here}}
-  };
+  template void T() {}
 }
 namespace C {
-  template int T; // expected-error{{declaration of 'T' shadows 
template parameter}}
-  // expected-note@-1{{template parameter is 
declared here}}
-  template struct U {
-template static int V; // expected-error{{declaration of 'V' 
shadows template parameter}}
-   // expected-note@-1{{template parameter 
is declared here}}
-  };
+  template int T;
 }
 
 namespace PR28023 {



___
cfe-commits mailing list
c

[libclc] 262735b - libclc: add missing AMD gfx symlinks (#78884)

2024-01-22 Thread via cfe-commits

Author: Zoltán Böszörményi
Date: 2024-01-22T15:32:13+07:00
New Revision: 262735bbcc22f216a688b934ca9ff50b427c9dc1

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

LOG: libclc: add missing AMD gfx symlinks (#78884)

Fixes #44186

-

Signed-off-by: Zoltán Böszörményi 

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 9daef8265c16f26..fa1d8e4adbcc4fb 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -142,17 +142,15 @@ set( cypress_aliases hemlock )
 set( barts_aliases turks caicos )
 set( cayman_aliases aruba )
 set( tahiti_aliases pitcairn verde oland hainan bonaire kabini kaveri hawaii
-   mullins tonga iceland carrizo fiji stoney polaris10 polaris11 )
-
-# Support for gfx9 was added in LLVM 5.0 (r295554)
-if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "4.99.99" )
-   set( tahiti_aliases ${tahiti_aliases} gfx900 gfx902 )
-endif()
-
-# Support for Vega12 and Vega20 was added in LLVM 7 (r331215)
-if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "6.99.99" )
-   set( tahiti_aliases ${tahiti_aliases} gfx904 gfx906 )
-endif()
+   mullins tonga tongapro iceland carrizo fiji stoney polaris10 polaris11
+   gfx602 gfx705 gfx805
+   gfx900 gfx902 gfx904 gfx906 gfx908 gfx909 gfx90a gfx90c gfx940 gfx941 
gfx942
+   gfx1010 gfx1011 gfx1012 gfx1013
+   gfx1030 gfx1031 gfx1032 gfx1033 gfx1034 gfx1035 gfx1036
+   gfx1100 gfx1101 gfx1102 gfx1103
+   gfx1150 gfx1151
+   gfx1200 gfx1201
+)
 
 # pkg-config file
 configure_file( libclc.pc.in libclc.pc @ONLY )



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


[libclc] libclc: add missing AMD gfx symlinks (PR #78884)

2024-01-22 Thread Matt Arsenault via cfe-commits
=?utf-8?b?Wm9sdMOhbiBCw7ZzesO2cm3DqW55aQ=?=,
=?utf-8?b?Wm9sdMOhbiBCw7ZzesO2cm3DqW55aQ=?Message-ID:
In-Reply-To: 


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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Jessica Paquette via cfe-commits
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= 
Message-ID:
In-Reply-To: 


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

LGTM

https://github.com/llvm/llvm-project/pull/78033
___
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-01-22 Thread via cfe-commits

NorthBlue333 wrote:

`clang-check` builds in local.

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] f36845d - Enable direct methods and fast alloc calls for libobjc2. (#78030)

2024-01-22 Thread via cfe-commits

Author: David Chisnall
Date: 2024-01-22T08:38:41Z
New Revision: f36845d0c696023ea97931a4201b43ddfababf9c

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

LOG: Enable direct methods and fast alloc calls for libobjc2. (#78030)

These will be supported in the upcoming 2.2 release and so are gated on
that version.

Direct methods call `objc_send_initialize` if they are class methods
that may not have called initialize. This is guarded by checking for the
class flag bit that is set on initialisation in the class. This bit now
forms part of the ABI, but it's been stable for 30+ years so that's fine
as a contract going forwards.

Added: 
clang/test/CodeGenObjC/gnustep2-direct-method.m

Modified: 
clang/include/clang/Basic/ObjCRuntime.h
clang/lib/CodeGen/CGObjCGNU.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/ObjCRuntime.h 
b/clang/include/clang/Basic/ObjCRuntime.h
index f05debe6fea5121..1ccf60f0b7bee70 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -211,7 +211,13 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  // This could be enabled for all versions, except for the fact that the
+  // implementation of `objc_retain` and friends prior to 2.2 call [object
+  // retain] in their fall-back paths, which leads to infinite recursion if
+  // the runtime is built with this enabled.  Since distributions typically
+  // build all Objective-C things with the same compiler version and flags,
+  // it's better to be conservative here.
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW:
   return false;
 }
@@ -248,7 +254,7 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  return getVersion() >= VersionTuple(2, 2);
 case ObjFW:
   return false;
 }
@@ -266,6 +272,8 @@ class ObjCRuntime {
   return getVersion() >= VersionTuple(12, 2);
 case WatchOS:
   return getVersion() >= VersionTuple(5, 2);
+case GNUstep:
+  return getVersion() >= VersionTuple(2, 2);
 default:
   return false;
 }
@@ -463,7 +471,8 @@ class ObjCRuntime {
 case iOS: return true;
 case WatchOS: return true;
 case GCC: return false;
-case GNUstep: return false;
+case GNUstep:
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW: return false;
 }
 llvm_unreachable("bad kind");

diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9cc7f32815f7e9e..a36b0cdddaf0afd 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -18,6 +18,8 @@
 #include "CGObjCRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "CodeGenTypes.h"
+#include "SanitizerMetadata.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
@@ -597,6 +599,10 @@ class CGObjCGNU : public CGObjCRuntime {
 
   llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
  const ObjCContainerDecl *CD) override;
+
+  // Map to unify direct method definitions.
+  llvm::DenseMap
+  DirectMethodDefinitions;
   void GenerateDirectMethodPrologue(CodeGenFunction &CGF, llvm::Function *Fn,
 const ObjCMethodDecl *OMD,
 const ObjCContainerDecl *CD) override;
@@ -917,6 +923,14 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 ClassAliasSection,
 ConstantStringSection
   };
+  /// The subset of `objc_class_flags` used at compile time.
+  enum ClassFlags {
+/// This is a metaclass
+ClassFlagMeta = (1 << 0),
+/// This class has been initialised by the runtime (+initialize has been
+/// sent if necessary).
+ClassFlagInitialized = (1 << 8),
+  };
   static const char *const SectionsBaseNames[8];
   static const char *const PECOFFSectionsBaseNames[8];
   template
@@ -932,6 +946,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   /// structure describing the receiver and the class, and a selector as
   /// arguments.  Returns the IMP for the corresponding method.
   LazyRuntimeFunction MsgLookupSuperFn;
+  /// Function to ensure that +initialize is sent to a class.
+  LazyRuntimeFunction SentInitializeFn;
   /// A flag indicating if we've emitted at least one protocol.
   /// If we haven't, then we need to emit an empty protocol, to ensure that the
   /// __start__objc_protocols and __stop__objc_protocols sections exist.
@@ -1719,7 +1735,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 metaclassFields.addInt(LongTy, 0);
 // unsigned long info;
 // objc_class_flag_meta
-metaclassFields.addInt(LongTy, 1);
+   

[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-22 Thread David Chisnall via cfe-commits

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


[clang-tools-extra] [include-cleaner] Add --only-headers flag, opposite of --ignore-headers (PR #78714)

2024-01-22 Thread Haojian Wu via cfe-commits

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


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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -1700,43 +1776,116 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  markSkipped(S->getIfLoc(), getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else) {
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  markSkipped(S->getIfLoc(), Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+propagateCounts(ParentCount, Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);
+const bool isTrue = E->getResultAsAPSInt().getExtValue();
+
+extendRegion(S);
+
+const auto *Init = S->getInit();
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+// ignore 'if constexpr ('
+SourceLocation startOfSkipped = S->getIfLoc();
+
+if (Init) {
+  // don't mark initialisation as ignored
+  markSkipped(startOfSkipped, getStart(Init));
+  propagateCounts(ParentCount, Init);
+  // ignore after initialisation: '; )'...
+  startOfSkipped = getEnd(Init);

cor3ntin wrote:

can you add a test?

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


[clang] [Clang][AST] fix crash in mangle lambda expression (PR #78896)

2024-01-22 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/78896

>From e4ac395028e651721677d85caf6c76e3a7f79308 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH 1/2] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 -
 clang/test/SemaTemplate/default-parm-init.cpp | 50 +++
 2 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b4..1ed63db75294aab 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+auto NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3063,11 +3064,18 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 000..4bcea7eaa101763
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}

>From 4ec05f6b08ba5dd4f411399efe482993b4f174f3 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 21 Jan 2024 20:30:06 +0800
Subject: [PATCH 2/2] [Clang] fix crash in mangle lambda expression

---
 clang/lib/AST/ItaniumMangle.cpp   |  2 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 +
 .../AST/mangle-lambda-expression-no-crash.cpp |  4 ++
 clang/test/SemaTemplate/default-parm-init.cpp | 50 ---
 4 files changed, 8 insertions(+), 60 deletions(-)
 create mode 100644 clang/test/AST/mangle-lambda-expression-no-crash.cpp
 delete mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b1678479888eb77..20f1ec969155a8b 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2128,6 +2128,7 @@ void CXXNameMangler::mangleLambda(const CXXRecordDecl 
*Lambda) {
 }
 
 void CXXNameMangler::mangleLambdaSig(const CXXRecordDecl *Lambda) {
+  FunctionTypeDepthState saved = FunctionTypeDepth.push();
   // Proposed on https://github.com/itanium-cxx-abi/cxx-abi/issues/31.
   for (auto *D : Lambda->getLambdaExplicitTemplateParameters())
 mangleTemplateParamDecl(D);
@@ -2140,6 +2141,7 @@ void CXXNameMangler::mangleLambdaSig(const CXXRecordDecl 
*Lambda) {
   Lambda->getLambdaTypeInfo()->getType()->castAs();
   mangleBareFunctionType(Proto, /*MangleReturnType=*/false,
  Lambda->getLambdaStaticInvoker());
+  FunctionTypeDepth.pop(saved);
 }
 
 void CXXNameMangler::manglePrefix(NestedNameSpecifier *qualifier) {
diff -

[mlir] [openmp] [libc] [libcxx] [libclc] [lld] [lldb] [clang-tools-extra] [compiler-rt] [clang] [llvm] Make llvm-strip not eat the .gnu_debuglink section (PR #78919)

2024-01-22 Thread Felix Kellenbenz via cfe-commits

https://github.com/felixkellenbenz updated 
https://github.com/llvm/llvm-project/pull/78919

>From bf376afe7bd69fd25a006890b2910f2fd32c191b Mon Sep 17 00:00:00 2001
From: Felix Kellenbenz 
Date: Mon, 22 Jan 2024 00:49:21 +0100
Subject: [PATCH] Make llvm-strip not eat the .gnu_debuglink section

---
 llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp 
b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index daf03810fd7bff..b6d77d17bae36c 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -450,6 +450,8 @@ static Error replaceAndRemoveSections(const CommonConfig 
&Config,
 return false;
   if (StringRef(Sec.Name).starts_with(".gnu.warning"))
 return false;
+  if (StringRef(Sec.Name).starts_with(".gnu_debuglink"))
+return false;
   // We keep the .ARM.attribute section to maintain compatibility
   // with Debian derived distributions. This is a bug in their
   // patchset as documented here:

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


[lldb] [libcxx] [libc] [compiler-rt] [flang] [llvm] [clang] [clang-tools-extra] [lld] [AMDGPU][GFX12] VOP encoding and codegen - add support for v_cvt fp8/… (PR #78414)

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

https://github.com/arsenm commented:

Why is so there so much special casing in the assembler/disassembler?

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


[mlir] [openmp] [libc] [libcxx] [libclc] [lld] [lldb] [clang-tools-extra] [compiler-rt] [clang] [llvm] Make llvm-strip not eat the .gnu_debuglink section (PR #78919)

2024-01-22 Thread James Henderson via cfe-commits

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

Hi, thanks for the contribution.

Please could you add a new lit test case to show that this behaviour works as 
intended.

I note that this code as-is only impacts `--strip-all` behaviour. This means 
that if you use `--strip-debug`, the section will get removed. Is this 
intentional? What do GNU strip or objcopy do in these cases?

https://github.com/llvm/llvm-project/pull/78919
___
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-01-22 Thread via cfe-commits

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

>From a3ddae11b909a319d73fccff409fa5c0648a234f 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

---
 clang/lib/Format/Format.cpp | 13 +++--
 clang/unittests/Format/SortIncludesTest.cpp | 61 -
 2 files changed, 67 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff326dc784783b2..3d8cffaca1ded3c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3123,6 +3123,7 @@ static void sortCppIncludes(const FormatStyle &Style,
   }
 
   std::string result;
+  unsigned NewCursor = UINT_MAX;
   for (unsigned Index : Indices) {
 if (!result.empty()) {
   result += "\n";
@@ -3134,13 +3135,10 @@ static void sortCppIncludes(const FormatStyle &Style,
 }
 result += Includes[Index].Text;
 if (Cursor && CursorIndex == Index)
-  *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
+  NewCursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
 CurrentCategory = Includes[Index].Category;
   }
 
-  if (Cursor && *Cursor >= IncludesEndOffset)
-*Cursor += result.size() - IncludesBlockSize;
-
   // If the #includes are out of order, we generate a single replacement fixing
   // the entire range of blocks. Otherwise, no replacement is generated.
   if (replaceCRLF(result) == replaceCRLF(std::string(Code.substr(
@@ -3148,6 +3146,13 @@ static void sortCppIncludes(const FormatStyle &Style,
 return;
   }
 
+  if (Cursor) {
+if (NewCursor != UINT_MAX)
+  *Cursor = NewCursor;
+else if (*Cursor >= IncludesEndOffset)
+  *Cursor += result.size() - IncludesBlockSize;
+  }
+
   auto Err = Replaces.add(tooling::Replacement(
   FileName, Includes.front().Offset, IncludesBlockSize, result));
   // FIXME: better error handling. For now, just skip the replacement for the
diff --git a/clang/unittests/Format/SortIncludesTest.cpp 
b/clang/unittests/Format/SortIncludesTest.cpp
index ec142e03b12854e..d180767b6ff9fab 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,61 @@ 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 li

[clang] [Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT options (PR #69133)

2024-01-22 Thread David Spickett via cfe-commits

DavidSpickett wrote:

I think because bots don't always clean their cmake files, revert incoming.

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


[clang] 0845514 - [clang][analyzer] Add function 'fscanf' to StreamChecker. (#78180)

2024-01-22 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-01-22T09:58:09+01:00
New Revision: 0845514d1a78ca04ef90b775d8819a8a8f19a533

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

LOG: [clang][analyzer] Add function 'fscanf' to StreamChecker. (#78180)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
clang/test/Analysis/stream-error.c
clang/test/Analysis/stream.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 95c7503e49e0d3..84923732fe1b28 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -266,6 +266,9 @@ class StreamChecker : public Checker(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  SValBuilder &SVB = C.getSValBuilder();
+  ASTContext &ACtx = C.getASTContext();
+
+  // Add the success state.
+  // In this context "success" means there is not an EOF or other read error
+  // before any item is matched in 'fscanf'. But there may be match failure,
+  // therefore return value can be 0 or greater.
+  // It is not specified what happens if some items (not all) are matched and
+  // then EOF or read error happens. Now this case is handled like a "success"
+  // case, and no error flags are set on the stream. This is probably not
+  // accurate, and the POSIX documentation does not tell more.
+  if (OldSS->ErrorState != ErrorFEof) {
+NonLoc RetVal = makeRetVal(C, CE).castAs();
+ProgramStateRef StateNotFailed =
+State->BindExpr(CE, C.getLocationContext(), RetVal);
+auto RetGeZero =
+SVB.evalBinOp(StateNotFailed, BO_GE, RetVal,
+  SVB.makeZeroVal(ACtx.IntTy), SVB.getConditionType())
+.getAs();
+if (!RetGeZero)
+  return;
+StateNotFailed = StateNotFailed->assume(*RetGeZero, true);
+
+C.addTransition(StateNotFailed);
+  }
+
+  // Add transition for the failed state.
+  // Error occurs if nothing is matched yet and reading the input fails.
+  // Error can be EOF, or other error. At "other error" FERROR or 'errno' can
+  // be set but it is not further specified if all are required to be set.
+  // Documentation does not mention, but file position will be set to
+  // indeterminate similarly as at 'fread'.
+  ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE);
+  StreamErrorState NewES = (OldSS->ErrorState == ErrorFEof)
+   ? ErrorFEof
+   : ErrorNone | ErrorFEof | ErrorFError;
+  StreamState NewSS = StreamState::getOpened(Desc, NewES, !NewES.isFEof());
+  StateFailed = StateFailed->set(StreamSym, NewSS);
+  if (OldSS->ErrorState != ErrorFEof)
+C.addTransition(StateFailed, constructSetEofNoteTag(C, StreamSym));
+  else
+C.addTransition(StateFailed);
+}
+
 void StreamChecker::evalUngetc(const FnDescription *Desc, const CallEvent 
&Call,
CheckerContext &C) const {
   ProgramStateRef State = C.getState();

diff  --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 0f7fdddc0dd4cd..2cf46e1d4ad51f 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -208,6 +208,31 @@ void error_fprintf(void) {
   fprintf(F, "ccc"); // expected-warning {{Stream might be already closed}}
 }
 
+void error_fscanf(int *A) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  int Ret = fscanf(F, "a%ib", A);
+  if (Ret >= 0) {
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+fscanf(F, "bbb");  // no-warning
+  } else {
+if (ferror(F)) {
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  fscanf(F, "bbb");   // expected-warning {{might be 
'indeterminate'}}
+} else if (feof(F)) {
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  fscanf(F, "bbb");   // expected-warning {{is in EOF state}}
+  clang_analyzer_eval(feof(F));   // expected-warning {{TRUE}}
+} else {
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  fscanf(F, "bbb");   // expected-warning {{might be 
'indeterminate'}}
+}
+  }
+  fclose(F);
+  fscanf(F, "ccc"); // expected-warning {{Stream might be already closed}}
+}
+
 void error_ungetc() {
   FILE *F = tmpfile();
   if (!F)

diff  --git a/clang/test/Analysis/stream.c b/clang/test/Analysis/stream.c
index e8f06922bdb2f3..36a9b4e26b07a2 100644
--- a/clang/test/Analysis/stream.c
+++ b/clang/test/Analysis/stream.c
@@ -45,6 +45,12 @@ void check_fprintf(void) {
  

[clang] [clang][analyzer] Add function 'fscanf' to StreamChecker. (PR #78180)

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

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


[clang] 6c47419 - Revert "[Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT options (#69133)"

2024-01-22 Thread David Spickett via cfe-commits

Author: David Spickett
Date: 2024-01-22T08:58:17Z
New Revision: 6c47419703acfcd7dcca9e30ab9dba6a7a42f977

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

LOG: Revert "[Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT 
options (#69133)"

This reverts commit 745883bba69007f1d2c5135f3d5b0f1efcfc82cd.

This is failing to configure on many of our bots:
https://lab.llvm.org/buildbot/#/builders/245/builds/19468

This did not get caught right away because generally bots only
clean the build every so often.

Added: 


Modified: 
clang/CMakeLists.txt
clang/cmake/caches/BOLT.cmake
clang/utils/perf-training/CMakeLists.txt
clang/utils/perf-training/bolt.lit.cfg
clang/utils/perf-training/bolt.lit.site.cfg.in
clang/utils/perf-training/perf-helper.py

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index b9c193f360bc488..5f2b7f064da4377 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -876,38 +876,23 @@ if (CLANG_ENABLE_BOOTSTRAP)
   endforeach()
 endif()
 
-set(CLANG_BOLT "INSTRUMENT" CACHE STRING "Apply BOLT optimization to Clang. \
-  May be specified as Instrument or Perf or LBR to use a particular profiling \
-  mechanism.")
-string(TOUPPER "${CLANG_BOLT}" CLANG_BOLT)
-
-if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
+if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
   set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
-  set(CLANG_INSTRUMENTED 
${LLVM_RUNTIME_OUTPUT_INTDIR}/${CLANG_BOLT_INSTRUMENTED})
+  set(CLANG_INSTRUMENTED ${CLANG_PATH}-bolt.inst)
   set(BOLT_FDATA ${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/prof.fdata)
 
-  # Pass extra flag in no-LBR mode
-  if (CLANG_BOLT STREQUAL "PERF")
-set(BOLT_NO_LBR "-nl")
-  endif()
-
-  if (CLANG_BOLT STREQUAL "INSTRUMENT")
-# Instrument clang with BOLT
-add_custom_target(clang-instrumented
-  DEPENDS ${CLANG_INSTRUMENTED}
-)
-add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
-  DEPENDS clang llvm-bolt
-  COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
--instrument --instrumentation-file-append-pid
---instrumentation-file=${BOLT_FDATA}
-  COMMENT "Instrumenting clang binary with BOLT"
-  VERBATIM
-)
-add_custom_target(clang-bolt-training-deps DEPENDS clang-instrumented)
-  else() # perf or LBR
-add_custom_target(clang-bolt-training-deps DEPENDS clang)
-  endif()
+  # Instrument clang with BOLT
+  add_custom_target(clang-instrumented
+DEPENDS ${CLANG_INSTRUMENTED}
+  )
+  add_custom_command(OUTPUT ${CLANG_INSTRUMENTED}
+DEPENDS clang llvm-bolt
+COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
+  -instrument --instrumentation-file-append-pid
+  --instrumentation-file=${BOLT_FDATA}
+COMMENT "Instrumenting clang binary with BOLT"
+VERBATIM
+  )
 
   # Optimize original (pre-bolt) Clang using the collected profile
   set(CLANG_OPTIMIZED ${CMAKE_CURRENT_BINARY_DIR}/clang.bolt)
@@ -921,7 +906,6 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   -data ${BOLT_FDATA}
   -reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions
   -split-all-cold -split-eh -dyno-stats -icf=1 -use-gnu-stack
-  ${BOLT_NO_LBR}
 COMMAND ${CMAKE_COMMAND} -E rename ${CLANG_OPTIMIZED} $
 COMMENT "Optimizing Clang with BOLT"
 VERBATIM

diff  --git a/clang/cmake/caches/BOLT.cmake b/clang/cmake/caches/BOLT.cmake
index eba2346b2f4ca12..0442f73e5426ac7 100644
--- a/clang/cmake/caches/BOLT.cmake
+++ b/clang/cmake/caches/BOLT.cmake
@@ -1,5 +1,5 @@
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
-set(CLANG_BOLT "INSTRUMENT" CACHE STRING "")
+set(CLANG_BOLT_INSTRUMENT ON CACHE BOOL "")
 set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "")
 
 set(LLVM_ENABLE_PROJECTS "bolt;clang" CACHE STRING "")

diff  --git a/clang/utils/perf-training/CMakeLists.txt 
b/clang/utils/perf-training/CMakeLists.txt
index 601f40902fa34ea..c6d51863fb1b5c2 100644
--- a/clang/utils/perf-training/CMakeLists.txt
+++ b/clang/utils/perf-training/CMakeLists.txt
@@ -62,9 +62,7 @@ if(APPLE AND DTRACE AND NOT LLVM_TOOL_LLVM_DRIVER_BUILD)
 DEPENDS generate-dtrace-logs)
 endif()
 
-if(CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
-  set(CLANG_BOLT_INSTRUMENTED "clang-bolt.inst" CACHE STRING
-"Name of BOLT-instrumented Clang binary")
+if(CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
   configure_lit_site_cfg(
 ${CMAKE_CURRENT_SOURCE_DIR}/bolt.lit.site.cfg.in
 ${CMAKE_CURRENT_BINARY_DIR}/bolt-fdata/lit.site.cfg
@@ -73,37 +71,16 @@ if(CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   add_lit_testsuite(generate-bolt-fdata "Generating BOLT profile for Clang"
 ${CMAKE_CURRENT_BINARY_DIR}/bolt-fdata/
 EXCLUDE_FROM_CHECK_ALL
-DEPENDS clang-bolt-

[clang] [Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT options (PR #69133)

2024-01-22 Thread David Spickett via cfe-commits

DavidSpickett wrote:

https://lab.llvm.org/buildbot/#/builders/245/builds/19468

```
CMake Error at 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/utils/perf-training/CMakeLists.txt:105
 (add_custom_target):
  Error evaluating generator expression:
$
  No target "merge-fdata"
```

This particular bot is clang+llvm and only the ARM target, but we've seen it on 
our AArch64 bots too. 

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


[compiler-rt] [lldb] [lld] [llvm] [flang] [clang-tools-extra] [libcxx] [clang] [libc] [clang] Fix assertion failure with deleted overloaded unary operators (PR #78316)

2024-01-22 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Driver failure seems unrelated.

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


[compiler-rt] [llvm] [clang-tools-extra] [libcxx] [clang] [libc] [mlir] [flang] [clang] Remove `CXXNewInitializationStyle::Implicit` (PR #78793)

2024-01-22 Thread via cfe-commits

https://github.com/tomasz-kaminski-sonarsource commented:

LGTM. Thanks.

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


[clang] 11d1310 - [clang] Fix assertion failure with deleted overloaded unary operators (#78316)

2024-01-22 Thread via cfe-commits

Author: Mariya Podchishchaeva
Date: 2024-01-22T10:06:26+01:00
New Revision: 11d1310b57a9f2defb4d65a35b90a69020c52e46

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

LOG: [clang] Fix assertion failure with deleted overloaded unary operators 
(#78316)

When emitting notes related to wrong number of arguments do not consider
object argument.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/overloaded-operator.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c9f9ecca727a4..4888ffe6f4dfc8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -837,6 +837,8 @@ Bug Fixes in This Version
 - Fix an issue with missing symbol definitions when the first coroutine
   statement appears in a discarded ``if constexpr`` branch.
   Fixes (`#78290 `_)
+- Fixed assertion failure with deleted overloaded unary operators.
+  Fixes (`#78314 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 697a1c0cfc404e..030878899b8122 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -14332,12 +14332,17 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, 
UnaryOperatorKind Opc,
 return ExprError();
 
   case OR_Deleted:
+// CreateOverloadedUnaryOp fills the first element of ArgsArray with the
+// object whose method was called. Later in NoteCandidates size of 
ArgsArray
+// is passed further and it eventually ends up compared to number of
+// function candidate parameters which never includes the object parameter,
+// so slice ArgsArray to make sure apples are compared to apples.
 CandidateSet.NoteCandidates(
 PartialDiagnosticAt(OpLoc, PDiag(diag::err_ovl_deleted_oper)
<< UnaryOperator::getOpcodeStr(Opc)
<< Input->getSourceRange()),
-*this, OCD_AllCandidates, ArgsArray, UnaryOperator::getOpcodeStr(Opc),
-OpLoc);
+*this, OCD_AllCandidates, ArgsArray.drop_front(),
+UnaryOperator::getOpcodeStr(Opc), OpLoc);
 return ExprError();
   }
 

diff  --git a/clang/test/SemaCXX/overloaded-operator.cpp 
b/clang/test/SemaCXX/overloaded-operator.cpp
index 83a7e65b43dd01..887848c29b83c5 100644
--- a/clang/test/SemaCXX/overloaded-operator.cpp
+++ b/clang/test/SemaCXX/overloaded-operator.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx23 -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx23 -std=c++23 %s
+
 class X { };
 
 X operator+(X, X);
@@ -33,7 +35,9 @@ struct A {
 
 A make_A();
 
-bool operator==(A&, Z&); // expected-note 3{{candidate function}}
+bool operator==(A&, Z&); // expected-note 3{{candidate function}} \
+ // cxx23-note 2{{candidate function}}
+
 
 void h(A a, const A ac, Z z) {
   make_A() == z; // expected-warning{{equality comparison result unused}}
@@ -68,7 +72,9 @@ struct E2 {
 };
 
 // C++ [over.match.oper]p3 - enum restriction.
-float& operator==(E1, E2);  // expected-note{{candidate function}}
+float& operator==(E1, E2);  // expected-note{{candidate function}} \
+// cxx23-note{{candidate function}}
+
 
 void enum_test(Enum1 enum1, Enum2 enum2, E1 e1, E2 e2, Enum1 next_enum1) {
   float &f1 = (e1 == e2);
@@ -86,7 +92,8 @@ class pr5244_foo
 };
 
 bool operator==(const pr5244_foo& s1, const pr5244_foo& s2); // 
expected-note{{candidate function}}
-bool operator==(char c, const pr5244_foo& s); // expected-note{{candidate 
function}}
+bool operator==(char c, const pr5244_foo& s); // expected-note{{candidate 
function}} \
+  // cxx23-note{{candidate 
function}}
 
 enum pr5244_bar
 {
@@ -130,7 +137,7 @@ struct SmartPtr {
 };
 
 void test_smartptr(SmartPtr ptr, const SmartPtr cptr, 
-   const volatile SmartPtr cvptr) {
+   const volatile SmartPtr cvptr) { // cxx23-warning 
{{volatile-qualified parameter type 'const volatile SmartPtr' is deprecated}}
   int &ir = *ptr;
   long &lr = *cptr;
   long &lr2 = *cvptr;
@@ -598,3 +605,43 @@ namespace B {
 }
 void g(B::X x) { A::f(x); }
 }
+
+namespace GH78314 {
+
+class a {
+public:
+  void operator--() = delete; // expected-note {{candidate function has been 
explicitly deleted}} \
+  // expected-note {{candidate function not 
viable: require

[clang] [Clang][CMake] Support perf, LBR, and Instrument CLANG_BOLT options (PR #69133)

2024-01-22 Thread David Spickett via cfe-commits


@@ -850,23 +850,38 @@ if (CLANG_ENABLE_BOOTSTRAP)
   endforeach()
 endif()
 
-if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+set(CLANG_BOLT "INSTRUMENT" CACHE STRING "Apply BOLT optimization to Clang. \

DavidSpickett wrote:

Wild guess, this defaults to `INSTRUMENT`, but it should default to some `OFF` 
value?

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


[compiler-rt] [lldb] [lld] [llvm] [flang] [clang-tools-extra] [libcxx] [clang] [libc] [clang] Fix assertion failure with deleted overloaded unary operators (PR #78316)

2024-01-22 Thread Mariya Podchishchaeva via cfe-commits

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


[compiler-rt] [mlir] [lldb] [lld] [llvm] [openmp] [clang-tools-extra] [libcxx] [libclc] [clang] [libc] Make llvm-strip not eat the .gnu_debuglink section (PR #78919)

2024-01-22 Thread Felix Kellenbenz via cfe-commits

felixkellenbenz wrote:

Hey thanks for the review, 

I will add a test case in a moment.

That's true, my change only impacts `--strip-all`. I tested `llvm-strip` with 
the `--strip-debug` flag and this didn't  remove the `.gnu_debuglink` section. 
This is also seen when using `GNU strip`.

Here are the commands I used when testing the `--strip-debug` flag:
```
gcc -g -xc /dev/null -ffreestanding -shared -o a.out
llvm-objcopy --only-keep-debug a.out a.out.dbg
llvm-objcopy --add-gnu-debuglink=a.out.dbg a.out
llvm-strip --strip-debug -o a.out.stripped a.out
readelf -wk a.out
```

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


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-22 Thread Maciej Gabka via cfe-commits


@@ -31,3 +31,31 @@
 
 // RUN: %clang -fveclib=Accelerate %s -nodefaultlibs -target 
arm64-apple-ios8.0.0 -### 2>&1 | FileCheck 
--check-prefix=CHECK-LINK-NODEFAULTLIBS %s
 // CHECK-LINK-NODEFAULTLIBS-NOT: "-framework" "Accelerate"
+
+
+/* Verify that the correct vector library is passed to LTO flags. */
+
+
+// RUN: %clang -### -fveclib=none -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-NOLIB %s
+// CHECK-LTO-NOLIB: "-plugin-opt=-vector-library=none"
+
+// RUN: %clang -### -fveclib=Accelerate -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-ACCELERATE %s
+// CHECK-LTO-ACCELERATE: "-plugin-opt=-vector-library=Accelerate"
+
+// RUN: %clang -### -fveclib=LIBMVEC -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-LIBMVEC %s
+// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"
+
+// RUN: %clang -### -fveclib=MASSV -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-MASSV %s
+// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
+
+// RUN: not %clang -### -fveclib=SVML -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-SVML %s
+// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"
+
+// RUN: %clang -### -fveclib=SLEEF -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-SLEEF %s
+// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"
+
+// RUN: %clang -### -fveclib=Darwin_libsystem_m -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-DARWIN %s
+// CHECK-LTO-DARWIN: "-plugin-opt=-vector-library=Darwin_libsystem_m"
+
+// RUN: %clang -### -fveclib=ArmPL -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-ARMPL %s

mgabka wrote:

don't you have to specify here --target=aarch64-none-none ? and similarly 
relevant targets for other veclibs? 

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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/78033

From ae319fd34659c1373ce573346b93ffaa290a3312 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Mon, 22 Jan 2024 00:00:43 +0100
Subject: [PATCH 1/7] [coverage] skipping code coverage for 'if constexpr' and
 'if consteval'

---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 212 +++---
 .../CoverageMapping/branch-constfolded.cpp|   8 +-
 clang/test/CoverageMapping/if.cpp | 138 
 .../ProfileData/Coverage/CoverageMapping.cpp  |  14 +-
 .../ProfileData/CoverageMappingTest.cpp   |  24 +-
 5 files changed, 317 insertions(+), 79 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 4a44d113ddec9e8..0f0f0459406fb32 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,12 +119,16 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch, or anything skipped but not empty line / comments)
+  bool SkippedRegion;
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
   bool GapRegion = false)
-  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) 
{
-  }
+  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(Counter Count, std::optional FalseCount,
   MCDCParameters MCDCParams,
@@ -132,13 +136,14 @@ class SourceMappingRegion {
   std::optional LocEnd,
   bool GapRegion = false)
   : Count(Count), FalseCount(FalseCount), MCDCParams(MCDCParams),
-LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) {}
+LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(MCDCParameters MCDCParams,
   std::optional LocStart,
   std::optional LocEnd)
   : MCDCParams(MCDCParams), LocStart(LocStart), LocEnd(LocEnd),
-GapRegion(false) {}
+GapRegion(false), SkippedRegion(false) {}
 
   const Counter &getCounter() const { return Count; }
 
@@ -174,6 +179,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +477,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1251,6 +1264,70 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Find a valid range starting with \p StartingLoc and ending before \p
+  /// BeforeLoc.
+  std::optional findAreaStartingFromTo(SourceLocation StartingLoc,
+SourceLocation BeforeLoc) {
+// If StartingLoc is in function-like macro, use its start location.
+if (StartingLoc.isMacroID()) {
+  FileID FID = SM.getFileID(StartingLoc);
+  const SrcMgr::ExpansionInfo *EI = &SM.getSLocEntry(FID).getExpansion();
+  if (EI->isFunctionMacroExpansion())
+StartingLoc = EI->getExpansionLocStart();
+}
+
+size_t StartDepth = locationDepth(StartingLoc);
+size_t EndDepth = locationDepth(BeforeLoc);
+while (!SM.isWrittenInSameFile(StartingLoc, BeforeLoc)) {
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+assert(SM.isWrittenInSameFile(getStartOfFileOrMacro(BeforeLoc),
+  BeforeLoc));
+
+BeforeLoc = getIncludeOrExpansionLoc(BeforeLoc);
+assert(BeforeLoc.isValid());
+EndDepth--;
+  }
+  if (UnnestStart) {
+assert(SM.isWrittenInSameFile(StartingLoc,
+  getStartOfFileOrMacro(StartingLoc)));
+
+StartingLoc = getIncludeOrExpansionLoc(StartingLoc);
+assert(StartingLoc.isValid());
+StartDepth--;
+  }
+}
+// If the start and end locations o

[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/78033

From ae319fd34659c1373ce573346b93ffaa290a3312 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Mon, 22 Jan 2024 00:00:43 +0100
Subject: [PATCH 1/8] [coverage] skipping code coverage for 'if constexpr' and
 'if consteval'

---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 212 +++---
 .../CoverageMapping/branch-constfolded.cpp|   8 +-
 clang/test/CoverageMapping/if.cpp | 138 
 .../ProfileData/Coverage/CoverageMapping.cpp  |  14 +-
 .../ProfileData/CoverageMappingTest.cpp   |  24 +-
 5 files changed, 317 insertions(+), 79 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 4a44d113ddec9e8..0f0f0459406fb32 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,12 +119,16 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch, or anything skipped but not empty line / comments)
+  bool SkippedRegion;
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
   bool GapRegion = false)
-  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) 
{
-  }
+  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(Counter Count, std::optional FalseCount,
   MCDCParameters MCDCParams,
@@ -132,13 +136,14 @@ class SourceMappingRegion {
   std::optional LocEnd,
   bool GapRegion = false)
   : Count(Count), FalseCount(FalseCount), MCDCParams(MCDCParams),
-LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) {}
+LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(MCDCParameters MCDCParams,
   std::optional LocStart,
   std::optional LocEnd)
   : MCDCParams(MCDCParams), LocStart(LocStart), LocEnd(LocEnd),
-GapRegion(false) {}
+GapRegion(false), SkippedRegion(false) {}
 
   const Counter &getCounter() const { return Count; }
 
@@ -174,6 +179,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +477,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1251,6 +1264,70 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Find a valid range starting with \p StartingLoc and ending before \p
+  /// BeforeLoc.
+  std::optional findAreaStartingFromTo(SourceLocation StartingLoc,
+SourceLocation BeforeLoc) {
+// If StartingLoc is in function-like macro, use its start location.
+if (StartingLoc.isMacroID()) {
+  FileID FID = SM.getFileID(StartingLoc);
+  const SrcMgr::ExpansionInfo *EI = &SM.getSLocEntry(FID).getExpansion();
+  if (EI->isFunctionMacroExpansion())
+StartingLoc = EI->getExpansionLocStart();
+}
+
+size_t StartDepth = locationDepth(StartingLoc);
+size_t EndDepth = locationDepth(BeforeLoc);
+while (!SM.isWrittenInSameFile(StartingLoc, BeforeLoc)) {
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+assert(SM.isWrittenInSameFile(getStartOfFileOrMacro(BeforeLoc),
+  BeforeLoc));
+
+BeforeLoc = getIncludeOrExpansionLoc(BeforeLoc);
+assert(BeforeLoc.isValid());
+EndDepth--;
+  }
+  if (UnnestStart) {
+assert(SM.isWrittenInSameFile(StartingLoc,
+  getStartOfFileOrMacro(StartingLoc)));
+
+StartingLoc = getIncludeOrExpansionLoc(StartingLoc);
+assert(StartingLoc.isValid());
+StartDepth--;
+  }
+}
+// If the start and end locations o

[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits


@@ -1700,43 +1776,116 @@ struct CounterCoverageMappingBuilder
 Visit(S->getSubStmt());
   }
 
+  void CoverIfConsteval(const IfStmt *S) {
+assert(S->isConsteval());
+
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+extendRegion(S);
+
+if (S->isNegatedConsteval()) {
+  // ignore 'if consteval'
+  markSkipped(S->getIfLoc(), getStart(Then));
+  propagateCounts(ParentCount, Then);
+
+  if (Else) {
+// ignore 'else '
+markSkipped(getEnd(Then), getEnd(Else));
+  }
+} else {
+  assert(S->isNonNegatedConsteval());
+  // ignore 'if consteval  [else]'
+  markSkipped(S->getIfLoc(), Else ? getStart(Else) : getEnd(Then));
+
+  if (Else)
+propagateCounts(ParentCount, Else);
+}
+  }
+
+  void CoverIfConstexpr(const IfStmt *S) {
+assert(S->isConstexpr());
+
+// evaluate constant condition...
+const auto *E = dyn_cast(S->getCond());
+assert(E != nullptr);
+const bool isTrue = E->getResultAsAPSInt().getExtValue();
+
+extendRegion(S);
+
+const auto *Init = S->getInit();
+const auto *Then = S->getThen();
+const auto *Else = S->getElse();
+
+// I'm using 'propagateCounts' later as new region is better and allows me
+// to properly calculate line coverage in llvm-cov utility
+const Counter ParentCount = getRegion().getCounter();
+
+// ignore 'if constexpr ('
+SourceLocation startOfSkipped = S->getIfLoc();
+
+if (Init) {
+  // don't mark initialisation as ignored
+  markSkipped(startOfSkipped, getStart(Init));
+  propagateCounts(ParentCount, Init);
+  // ignore after initialisation: '; )'...
+  startOfSkipped = getEnd(Init);

hanickadot wrote:

test added :) it catched a crash as for some reason `using foo = int` there 
doesn't have right source location

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-01-22 Thread Henry Linjamäki via cfe-commits

https://github.com/linehill updated 
https://github.com/llvm/llvm-project/pull/77897

From 6165987ab890156a503d7afa38ad5c88510368b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Thu, 21 Dec 2023 08:43:16 +0200
Subject: [PATCH 1/2] [SPIR-V] Prefer llvm-spirv- tool

Prefer using `llvm-spirv-` tool
(i.e. `llvm-spirv-18`) over plain `llvm-spirv`. If the versioned tool
is not found in PATH, fall back to use the plain `llvm-spirv`.

An issue with the using `llvm-spirv` is that the one found in PATH
might be compiled against older LLVM version which could lead to
crashes or obscure bugs. For example, `llvm-spirv` distributed by
Ubuntu links against different LLVM version depending on the Ubuntu
release (LLVM-10 in 20.04LTS, LLVM-13 in 22.04LTS).
---
 clang/lib/Driver/ToolChains/SPIRV.cpp  | 12 ++--
 clang/test/Driver/hipspv-toolchain.hip | 13 +
 clang/test/Driver/spirv-toolchain.cl   | 10 ++
 clang/test/lit.site.cfg.py.in  |  1 +
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index 27de69550853cf9..ce900600cbee515 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 #include "SPIRV.h"
 #include "CommonArgs.h"
+#include "clang/Basic/Version.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/InputInfo.h"
@@ -32,8 +33,15 @@ void SPIRV::constructTranslateCommand(Compilation &C, const 
Tool &T,
 
   CmdArgs.append({"-o", Output.getFilename()});
 
-  const char *Exec =
-  C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
+  // Try to find "llvm-spirv-". Otherwise, fall back to
+  // plain "llvm-spirv".
+  using namespace std::string_literals;
+  auto VersionedTool = "llvm-spirv-"s + std::to_string(LLVM_VERSION_MAJOR);
+  std::string ExeCand = T.getToolChain().GetProgramPath(VersionedTool.c_str());
+  if (!llvm::sys::fs::can_execute(ExeCand))
+ExeCand = T.getToolChain().GetProgramPath("llvm-spirv");
+
+  const char *Exec = C.getArgs().MakeArgString(ExeCand);
   C.addCommand(std::make_unique(JA, T, ResponseFileSupport::None(),
  Exec, CmdArgs, Input, Output));
 }
diff --git a/clang/test/Driver/hipspv-toolchain.hip 
b/clang/test/Driver/hipspv-toolchain.hip
index bfae41049ba4dd1..5f6dcc069afe8b7 100644
--- a/clang/test/Driver/hipspv-toolchain.hip
+++ b/clang/test/Driver/hipspv-toolchain.hip
@@ -34,3 +34,16 @@
 // CHECK-SAME: "-o" [[OBJ_HOST:".*o"]] "-x" "hip"
 
 // CHECK: {{".*ld.*"}} {{.*}}[[OBJ_HOST]]
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### -target x86_64-linux-gnu \
+// RUN:   --offload=spirv64 --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major \
+// RUN:   --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/Driver/spirv-toolchain.cl 
b/clang/test/Driver/spirv-toolchain.cl
index db3ee4d3fe02f82..de818177cb19f15 100644
--- a/clang/test/Driver/spirv-toolchain.cl
+++ b/clang/test/Driver/spirv-toolchain.cl
@@ -77,3 +77,13 @@
 
 // XTOR: {{llvm-spirv.*"}}
 // BACKEND-NOT: {{llvm-spirv.*"}}
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### --target=spirv64 -x cl -c %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index ef75770a2c3c9ac..b4e88096aaa0f3c 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -41,6 +41,7 @@ config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
 config.standalone_build = @CLANG_BUILT_STANDALONE@
 config.ppc_linux_default_ieeelongdouble = @PPC_LINUX_DEFAULT_IEEELONGDOUBLE@
 config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@
+config.substitutions.append(("%llvm-version-major", "@LLVM_VERSION_MAJOR@"))
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)

From fc1e2d0693d196b6bc4a0f1c51fd5ecc71e60f92 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Mon, 22 Jan 2024 11:25:46 +0200
Subject: [PATCH 2/2] Document llvm-spirv-

---
 clang/docs/UsersManual.rst | 6 +++---
 1

[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-01-22 Thread Henry Linjamäki via cfe-commits

linehill wrote:

@AnastasiaStulova, @MaskRay, gentle ping.

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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -809,7 +809,7 @@ Bug Fixes in This Version
   invalidation by invalid initializer Expr.
   Fixes (`#30908 `_)
 - Clang now emits correct source location for code-coverage regions in `if 
constexpr`
-  and `if consteval` branches.
+  and `if consteval` branches. Untaken branch is now skipped.

cor3ntin wrote:

```suggestion
  and `if consteval` branches. Untaken branches are now skipped.
```

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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread via cfe-commits
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= ,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= 
Message-ID:
In-Reply-To: 


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

LGTM (with a nit)
Thanks!

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


[llvm] [clang] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/78033

From ae319fd34659c1373ce573346b93ffaa290a3312 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Mon, 22 Jan 2024 00:00:43 +0100
Subject: [PATCH 1/9] [coverage] skipping code coverage for 'if constexpr' and
 'if consteval'

---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 212 +++---
 .../CoverageMapping/branch-constfolded.cpp|   8 +-
 clang/test/CoverageMapping/if.cpp | 138 
 .../ProfileData/Coverage/CoverageMapping.cpp  |  14 +-
 .../ProfileData/CoverageMappingTest.cpp   |  24 +-
 5 files changed, 317 insertions(+), 79 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 4a44d113ddec9e..0f0f0459406fb3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,12 +119,16 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch, or anything skipped but not empty line / comments)
+  bool SkippedRegion;
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
   bool GapRegion = false)
-  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) 
{
-  }
+  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(Counter Count, std::optional FalseCount,
   MCDCParameters MCDCParams,
@@ -132,13 +136,14 @@ class SourceMappingRegion {
   std::optional LocEnd,
   bool GapRegion = false)
   : Count(Count), FalseCount(FalseCount), MCDCParams(MCDCParams),
-LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) {}
+LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(MCDCParameters MCDCParams,
   std::optional LocStart,
   std::optional LocEnd)
   : MCDCParams(MCDCParams), LocStart(LocStart), LocEnd(LocEnd),
-GapRegion(false) {}
+GapRegion(false), SkippedRegion(false) {}
 
   const Counter &getCounter() const { return Count; }
 
@@ -174,6 +179,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +477,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1251,6 +1264,70 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Find a valid range starting with \p StartingLoc and ending before \p
+  /// BeforeLoc.
+  std::optional findAreaStartingFromTo(SourceLocation StartingLoc,
+SourceLocation BeforeLoc) {
+// If StartingLoc is in function-like macro, use its start location.
+if (StartingLoc.isMacroID()) {
+  FileID FID = SM.getFileID(StartingLoc);
+  const SrcMgr::ExpansionInfo *EI = &SM.getSLocEntry(FID).getExpansion();
+  if (EI->isFunctionMacroExpansion())
+StartingLoc = EI->getExpansionLocStart();
+}
+
+size_t StartDepth = locationDepth(StartingLoc);
+size_t EndDepth = locationDepth(BeforeLoc);
+while (!SM.isWrittenInSameFile(StartingLoc, BeforeLoc)) {
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+assert(SM.isWrittenInSameFile(getStartOfFileOrMacro(BeforeLoc),
+  BeforeLoc));
+
+BeforeLoc = getIncludeOrExpansionLoc(BeforeLoc);
+assert(BeforeLoc.isValid());
+EndDepth--;
+  }
+  if (UnnestStart) {
+assert(SM.isWrittenInSameFile(StartingLoc,
+  getStartOfFileOrMacro(StartingLoc)));
+
+StartingLoc = getIncludeOrExpansionLoc(StartingLoc);
+assert(StartingLoc.isValid());
+StartDepth--;
+  }
+}
+// If the start and end locations of 

[clang] Add option -fstdlib-hardening= (PR #78763)

2024-01-22 Thread Akira Hatanaka via cfe-commits


@@ -7730,6 +7730,14 @@ def source_date_epoch : Separate<["-"], 
"source-date-epoch">,
 
 } // let Visibility = [CC1Option]
 
+def stdlib_hardening_EQ : Joined<["-"], "fstdlib-hardening=">,
+  Values<"none,fast,extensive,debug">,
+  NormalizedValues<["STDLIB_HARDENING_MODE_NONE", 
"STDLIB_HARDENING_MODE_FAST", "STDLIB_HARDENING_MODE_EXTENSIVE", 
"STDLIB_HARDENING_MODE_DEBUG"]>,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"standard library hardening mode">,
+  NormalizedValuesScope<"LangOptions">,
+  MarshallingInfoEnum, 
"STDLIB_HARDENING_MODE_NOT_SPECIFIED">;

ahatanak wrote:

Isn't `DocName` only for `OptionGroup`?
https://github.com/llvm/llvm-project/blob/ac296b696ccf3081b2fc920f860da894fb1d8eb0/clang/utils/TableGen/ClangOptionDocEmitter.cpp#L393

Do you mean `DocBrief`?

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


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-22 Thread David Sherwood via cfe-commits


@@ -31,3 +31,31 @@
 
 // RUN: %clang -fveclib=Accelerate %s -nodefaultlibs -target 
arm64-apple-ios8.0.0 -### 2>&1 | FileCheck 
--check-prefix=CHECK-LINK-NODEFAULTLIBS %s
 // CHECK-LINK-NODEFAULTLIBS-NOT: "-framework" "Accelerate"
+
+
+/* Verify that the correct vector library is passed to LTO flags. */
+
+
+// RUN: %clang -### -fveclib=none -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-NOLIB %s
+// CHECK-LTO-NOLIB: "-plugin-opt=-vector-library=none"
+
+// RUN: %clang -### -fveclib=Accelerate -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-ACCELERATE %s
+// CHECK-LTO-ACCELERATE: "-plugin-opt=-vector-library=Accelerate"
+
+// RUN: %clang -### -fveclib=LIBMVEC -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-LIBMVEC %s
+// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"
+
+// RUN: %clang -### -fveclib=MASSV -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-MASSV %s
+// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
+
+// RUN: not %clang -### -fveclib=SVML -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-SVML %s
+// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"
+
+// RUN: %clang -### -fveclib=SLEEF -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-SLEEF %s
+// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"
+
+// RUN: %clang -### -fveclib=Darwin_libsystem_m -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-DARWIN %s
+// CHECK-LTO-DARWIN: "-plugin-opt=-vector-library=Darwin_libsystem_m"
+
+// RUN: %clang -### -fveclib=ArmPL -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-ARMPL %s

david-arm wrote:

Looks like `--target=aarch64-none-none` is needed for SLEEF and ArmPL perhaps? 
In the first 8 RUN lines it looks like we don't specify the target except for 
those cases.

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


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-22 Thread David Sherwood via cfe-commits


@@ -783,6 +783,28 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
  "-generate-arange-section"));
   }
 
+  // Pass vector library arguments to LTO.
+  Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
+  if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
+// Map the vector library names from clang front-end to opt front-end. The
+// values are taken from the TargetLibraryInfo class command line options.
+std::optional OptVal =
+llvm::StringSwitch>(ArgVecLib->getValue())

david-arm wrote:

Is it possible to refactor and reuse existing TargetLibraryInfo code, i.e. 
create a common static function that maps the values so that it can be called 
in multiple places?

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


[clang] [llvm] [coverage] skipping code coverage for 'if constexpr' and 'if consteval' (PR #78033)

2024-01-22 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/78033

From e2e0ecab6693547938274ffa0a7f517cedf52205 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Mon, 22 Jan 2024 00:00:43 +0100
Subject: [PATCH 1/9] [coverage] skipping code coverage for 'if constexpr' and
 'if consteval'

---
 clang/lib/CodeGen/CoverageMappingGen.cpp  | 212 +++---
 .../CoverageMapping/branch-constfolded.cpp|   8 +-
 clang/test/CoverageMapping/if.cpp | 138 
 .../ProfileData/Coverage/CoverageMapping.cpp  |  14 +-
 .../ProfileData/CoverageMappingTest.cpp   |  24 +-
 5 files changed, 317 insertions(+), 79 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 4a44d113ddec9e..0f0f0459406fb3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -119,12 +119,16 @@ class SourceMappingRegion {
   /// as the line execution count if there are no other regions on the line.
   bool GapRegion;
 
+  /// Whetever this region is skipped ('if constexpr' or 'if consteval' untaken
+  /// branch, or anything skipped but not empty line / comments)
+  bool SkippedRegion;
+
 public:
   SourceMappingRegion(Counter Count, std::optional LocStart,
   std::optional LocEnd,
   bool GapRegion = false)
-  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) 
{
-  }
+  : Count(Count), LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(Counter Count, std::optional FalseCount,
   MCDCParameters MCDCParams,
@@ -132,13 +136,14 @@ class SourceMappingRegion {
   std::optional LocEnd,
   bool GapRegion = false)
   : Count(Count), FalseCount(FalseCount), MCDCParams(MCDCParams),
-LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion) {}
+LocStart(LocStart), LocEnd(LocEnd), GapRegion(GapRegion),
+SkippedRegion(false) {}
 
   SourceMappingRegion(MCDCParameters MCDCParams,
   std::optional LocStart,
   std::optional LocEnd)
   : MCDCParams(MCDCParams), LocStart(LocStart), LocEnd(LocEnd),
-GapRegion(false) {}
+GapRegion(false), SkippedRegion(false) {}
 
   const Counter &getCounter() const { return Count; }
 
@@ -174,6 +179,10 @@ class SourceMappingRegion {
 
   void setGap(bool Gap) { GapRegion = Gap; }
 
+  bool isSkipped() const { return SkippedRegion; }
+
+  void setSkipped(bool Skipped) { SkippedRegion = Skipped; }
+
   bool isBranch() const { return FalseCount.has_value(); }
 
   bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
@@ -468,6 +477,10 @@ class CoverageMappingBuilder {
 MappingRegions.push_back(CounterMappingRegion::makeGapRegion(
 Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
 SR.LineEnd, SR.ColumnEnd));
+  } else if (Region.isSkipped()) {
+MappingRegions.push_back(CounterMappingRegion::makeSkipped(
+*CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd,
+SR.ColumnEnd));
   } else if (Region.isBranch()) {
 MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
 Region.getCounter(), Region.getFalseCounter(),
@@ -1251,6 +1264,70 @@ struct CounterCoverageMappingBuilder
 popRegions(Index);
   }
 
+  /// Find a valid range starting with \p StartingLoc and ending before \p
+  /// BeforeLoc.
+  std::optional findAreaStartingFromTo(SourceLocation StartingLoc,
+SourceLocation BeforeLoc) {
+// If StartingLoc is in function-like macro, use its start location.
+if (StartingLoc.isMacroID()) {
+  FileID FID = SM.getFileID(StartingLoc);
+  const SrcMgr::ExpansionInfo *EI = &SM.getSLocEntry(FID).getExpansion();
+  if (EI->isFunctionMacroExpansion())
+StartingLoc = EI->getExpansionLocStart();
+}
+
+size_t StartDepth = locationDepth(StartingLoc);
+size_t EndDepth = locationDepth(BeforeLoc);
+while (!SM.isWrittenInSameFile(StartingLoc, BeforeLoc)) {
+  bool UnnestStart = StartDepth >= EndDepth;
+  bool UnnestEnd = EndDepth >= StartDepth;
+  if (UnnestEnd) {
+assert(SM.isWrittenInSameFile(getStartOfFileOrMacro(BeforeLoc),
+  BeforeLoc));
+
+BeforeLoc = getIncludeOrExpansionLoc(BeforeLoc);
+assert(BeforeLoc.isValid());
+EndDepth--;
+  }
+  if (UnnestStart) {
+assert(SM.isWrittenInSameFile(StartingLoc,
+  getStartOfFileOrMacro(StartingLoc)));
+
+StartingLoc = getIncludeOrExpansionLoc(StartingLoc);
+assert(StartingLoc.isValid());
+StartDepth--;
+  }
+}
+// If the start and end locations of 

[llvm] [clang-tools-extra] [clang] [clang-format] Option to ignore macro definitions (PR #70338)

2024-01-22 Thread via cfe-commits


@@ -1157,7 +1157,15 @@ void UnwrappedLineParser::parsePPDefine() {
   // guard processing above, and changes preprocessing nesting.
   FormatTok->Tok.setKind(tok::identifier);
   FormatTok->Tok.setIdentifierInfo(Keywords.kw_internal_ident_after_define);
-  nextToken();
+
+  if (Style.SkipMacroDefinitionBody) {
+do {
+  nextToken();
+} while (!eof());
+  } else {
+nextToken();
+  }

tomekpaszek wrote:

Hi!
Maybe it's a little late, but I wanted to let you know that I've tried that but 
it didn't give the expected results. Didn't have time to dig into this approach.

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


[openmp] [compiler-rt] [libclc] [llvm] [clang-tools-extra] [libcxx] [clang] [libc] [mlir] [lld] [lldb] Make llvm-strip not eat the .gnu_debuglink section (PR #78919)

2024-01-22 Thread Felix Kellenbenz via cfe-commits

https://github.com/felixkellenbenz updated 
https://github.com/llvm/llvm-project/pull/78919

>From bf376afe7bd69fd25a006890b2910f2fd32c191b Mon Sep 17 00:00:00 2001
From: Felix Kellenbenz 
Date: Mon, 22 Jan 2024 00:49:21 +0100
Subject: [PATCH 1/2] Make llvm-strip not eat the .gnu_debuglink section

---
 llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp 
b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index daf03810fd7bff..b6d77d17bae36c 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -450,6 +450,8 @@ static Error replaceAndRemoveSections(const CommonConfig 
&Config,
 return false;
   if (StringRef(Sec.Name).starts_with(".gnu.warning"))
 return false;
+  if (StringRef(Sec.Name).starts_with(".gnu_debuglink"))
+return false;
   // We keep the .ARM.attribute section to maintain compatibility
   // with Debian derived distributions. This is a bug in their
   // patchset as documented here:

>From b014ffa827fbf8c301a190e2fbf7aa943c78e6f1 Mon Sep 17 00:00:00 2001
From: Felix Kellenbenz 
Date: Mon, 22 Jan 2024 10:37:22 +0100
Subject: [PATCH 2/2] Add test that checks if llvm-strip removes the
 .gnu_debuglink section

---
 llvm/test/tools/llvm-objcopy/ELF/strip-all.test | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-all.test 
b/llvm/test/tools/llvm-objcopy/ELF/strip-all.test
index 20f3c9addf556b..efc3d42f22953f 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/strip-all.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/strip-all.test
@@ -68,6 +68,8 @@ Sections:
 Flags:   [ ]
   - Name:.gnu.warning.foo
 Type:SHT_PROGBITS
+  - Name:.gnu_debuglink
+Type:SHT_PROGBITS
 ProgramHeaders:
   # Use an arbitrary segment type to show that the segment type is unimportant.
   - Type: 0x61234567

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-22 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/76774

>From 26bd7dc5139811b2b0d8d8642a67b67340eeb1d5 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 3 Jan 2024 11:33:17 +0800
Subject: [PATCH 1/4] Load Specializations Lazily

---
 clang/include/clang/AST/DeclTemplate.h|  35 ++--
 clang/include/clang/AST/ExternalASTSource.h   |   6 +
 clang/include/clang/AST/ODRHash.h |   3 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |  28 +++
 clang/include/clang/Serialization/ASTWriter.h |   6 +
 clang/lib/AST/DeclTemplate.cpp|  67 +---
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 clang/lib/AST/ODRHash.cpp |   3 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |   6 +
 clang/lib/Serialization/ASTReader.cpp | 125 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  35 +++-
 clang/lib/Serialization/ASTReaderInternals.h  |  80 +
 clang/lib/Serialization/ASTWriter.cpp | 144 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  78 ++---
 clang/test/Modules/odr_hash.cpp   |   4 +-
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazily.cpp  | 159 ++
 19 files changed, 729 insertions(+), 65 deletions(-)
 create mode 100644 clang/unittests/Serialization/LoadSpecLazily.cpp

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 832ad2de6b08a8..4699dd17bc182c 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -525,8 +525,11 @@ class FunctionTemplateSpecializationInfo final
 return Function.getInt();
   }
 
+  void loadExternalRedecls();
+
 public:
   friend TrailingObjects;
+  friend class ASTReader;
 
   static FunctionTemplateSpecializationInfo *
   Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
@@ -789,13 +792,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
-  void loadLazySpecializationsImpl() const;
+  void loadExternalSpecializations() const;
 
   template 
   typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
  void *&InsertPos, ProfileArguments &&...ProfileArgs);
 
+  void loadLazySpecializationsWithArgs(ArrayRef 
TemplateArgs);
+
   template 
   void addSpecializationImpl(llvm::FoldingSetVector &Specs,
  EntryType *Entry, void *InsertPos);
@@ -814,9 +819,13 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 /// If non-null, points to an array of specializations (including
 /// partial specializations) known only by their external declaration IDs.
 ///
+/// These specializations needs to be loaded at once in
+/// loadExternalSpecializations to complete the redecl chain or be 
preparing
+/// for template resolution.
+///
 /// The first value in the array is the number of specializations/partial
 /// specializations that follow.
-uint32_t *LazySpecializations = nullptr;
+uint32_t *ExternalSpecializations = nullptr;
 
 /// The set of "injected" template arguments used within this
 /// template.
@@ -850,6 +859,8 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   friend class ASTDeclWriter;
   friend class ASTReader;
   template  friend class RedeclarableTemplate;
+  friend class ClassTemplateSpecializationDecl;
+  friend class VarTemplateSpecializationDecl;
 
   /// Retrieves the canonical declaration of this template.
   RedeclarableTemplateDecl *getCanonicalDecl() override {
@@ -977,6 +988,7 @@ SpecEntryTraits {
 class FunctionTemplateDecl : public RedeclarableTemplateDecl {
 protected:
   friend class FunctionDecl;
+  friend class FunctionTemplateSpecializationInfo;
 
   /// Data that is common to all of the declarations of a given
   /// function template.
@@ -1012,13 +1024,13 @@ class FunctionTemplateDecl : public 
RedeclarableTemplateDecl {
   void addSpecialization(FunctionTemplateSpecializationInfo* Info,
  void *InsertPos);
 
+  /// Load any lazily-loaded specializations from the external source.
+  void LoadLazySpecializations() const;
+
 public:
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
 
-  /// Load any lazily-loaded specializations from the external source.
-  void LoadLazySpecializations() const;
-
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
 return static_cast(TemplatedDecl);
@@ -1839,6 +1851,8 @@ class ClassTemplateSpecializationDecl
   LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
   unsigned SpecializationKind : 3;
 
+  void loadExternalRedecls();
+
 protected:
   ClassTemplateSpecializationDecl(A

[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-22 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

In the newest push, I changed 2 things:
- In `ASTReader::LoadExternalSpecializations`, I am moving `Deserializing 
LookupResults(this);` before calculating the ODR hash for template arguments. 
Since I didn't realize that the ODRHash may trigger deserializing before.
- I introduced `-fno-load-external-specializations-lazily` to ease the 
debugging. When this option specified, all the specializations will be loaded 
when required, which keeps the previous behavior.

So if the new patch can pass directly, then it implies the issue is that I 
didn't realize the ODRHash may trigger deserializing.

And if not but it can pass with `-fno-load-external-specializations-lazily`, 
then it confirms the concern that the ODRHash algorithm for template arguments 
is not good.

Then if it can't pass with `-fno-load-external-specializations-lazily` too, it 
implies that I missed something : (

CC: @ilya-biryukov @hahnjo 

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-22 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/76774

>From 26bd7dc5139811b2b0d8d8642a67b67340eeb1d5 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 3 Jan 2024 11:33:17 +0800
Subject: [PATCH 1/4] Load Specializations Lazily

---
 clang/include/clang/AST/DeclTemplate.h|  35 ++--
 clang/include/clang/AST/ExternalASTSource.h   |   6 +
 clang/include/clang/AST/ODRHash.h |   3 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |  28 +++
 clang/include/clang/Serialization/ASTWriter.h |   6 +
 clang/lib/AST/DeclTemplate.cpp|  67 +---
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 clang/lib/AST/ODRHash.cpp |   3 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |   6 +
 clang/lib/Serialization/ASTReader.cpp | 125 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  35 +++-
 clang/lib/Serialization/ASTReaderInternals.h  |  80 +
 clang/lib/Serialization/ASTWriter.cpp | 144 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  78 ++---
 clang/test/Modules/odr_hash.cpp   |   4 +-
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazily.cpp  | 159 ++
 19 files changed, 729 insertions(+), 65 deletions(-)
 create mode 100644 clang/unittests/Serialization/LoadSpecLazily.cpp

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 832ad2de6b08a82..4699dd17bc182cd 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -525,8 +525,11 @@ class FunctionTemplateSpecializationInfo final
 return Function.getInt();
   }
 
+  void loadExternalRedecls();
+
 public:
   friend TrailingObjects;
+  friend class ASTReader;
 
   static FunctionTemplateSpecializationInfo *
   Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
@@ -789,13 +792,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
-  void loadLazySpecializationsImpl() const;
+  void loadExternalSpecializations() const;
 
   template 
   typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
  void *&InsertPos, ProfileArguments &&...ProfileArgs);
 
+  void loadLazySpecializationsWithArgs(ArrayRef 
TemplateArgs);
+
   template 
   void addSpecializationImpl(llvm::FoldingSetVector &Specs,
  EntryType *Entry, void *InsertPos);
@@ -814,9 +819,13 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 /// If non-null, points to an array of specializations (including
 /// partial specializations) known only by their external declaration IDs.
 ///
+/// These specializations needs to be loaded at once in
+/// loadExternalSpecializations to complete the redecl chain or be 
preparing
+/// for template resolution.
+///
 /// The first value in the array is the number of specializations/partial
 /// specializations that follow.
-uint32_t *LazySpecializations = nullptr;
+uint32_t *ExternalSpecializations = nullptr;
 
 /// The set of "injected" template arguments used within this
 /// template.
@@ -850,6 +859,8 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   friend class ASTDeclWriter;
   friend class ASTReader;
   template  friend class RedeclarableTemplate;
+  friend class ClassTemplateSpecializationDecl;
+  friend class VarTemplateSpecializationDecl;
 
   /// Retrieves the canonical declaration of this template.
   RedeclarableTemplateDecl *getCanonicalDecl() override {
@@ -977,6 +988,7 @@ SpecEntryTraits {
 class FunctionTemplateDecl : public RedeclarableTemplateDecl {
 protected:
   friend class FunctionDecl;
+  friend class FunctionTemplateSpecializationInfo;
 
   /// Data that is common to all of the declarations of a given
   /// function template.
@@ -1012,13 +1024,13 @@ class FunctionTemplateDecl : public 
RedeclarableTemplateDecl {
   void addSpecialization(FunctionTemplateSpecializationInfo* Info,
  void *InsertPos);
 
+  /// Load any lazily-loaded specializations from the external source.
+  void LoadLazySpecializations() const;
+
 public:
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
 
-  /// Load any lazily-loaded specializations from the external source.
-  void LoadLazySpecializations() const;
-
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
 return static_cast(TemplatedDecl);
@@ -1839,6 +1851,8 @@ class ClassTemplateSpecializationDecl
   LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
   unsigned SpecializationKind : 3;
 
+  void loadExternalRedecls();
+
 protected:
   ClassTemplateSpecializationDecl

[libc] [flang] [compiler-rt] [llvm] [clang-tools-extra] [lldb] [clang] [libcxx] [lld] [AMDGPU][GFX12] VOP encoding and codegen - add support for v_cvt fp8/… (PR #78414)

2024-01-22 Thread Mariusz Sikora via cfe-commits

mariusz-sikora-at-amd wrote:

> Why is so there so much special casing in the assembler/disassembler?

I'm not an original author of these change, but from what I understand it is a 
workaround to handle VOP3 instructions which have a single source but require 
the use of two bits from OPSEL.
`V_CVT_F32_FP8` has one source but is using two bits from OPSEL to specify 
which part from 32 bit register to convert ([7:0], [15:8], [23: 16] or 31 : 
24]). And since OPSELs are correlated with sources/destination (one bit from 
OPSEL with one soruce/destination) these is required without any deeper changes 
to TableGen.

I'm open to change TableGen, but I would prefer to create new ticket and do it 
with new PR. These change may take longer than one day and we would like to 
have these PR merged before LLVM branching.

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


[libc] [flang] [compiler-rt] [llvm] [clang-tools-extra] [lldb] [clang] [libcxx] [lld] [AMDGPU][GFX12] VOP encoding and codegen - add support for v_cvt fp8/… (PR #78414)

2024-01-22 Thread Mirko Brkušanin via cfe-commits

mbrkusanin wrote:

> > Why is so there so much special casing in the assembler/disassembler?
> 
> I'm not an original author of these change, but from what I understand it is 
> a workaround to handle VOP3 instructions which have a single source but 
> require the use of two bits from OPSEL. `V_CVT_F32_FP8` has one source but is 
> using two bits from OPSEL to specify which part from 32 bit register to 
> convert ([7:0], [15:8], [23: 16] or 31 : 24]). And since OPSELs are 
> correlated with sources/destination (one bit from OPSEL with one 
> soruce/destination) these is required without any deeper changes to TableGen.
> 
> I'm open to change TableGen, but I would prefer to create new ticket and do 
> it with new PR. These change may take longer than one day and we would like 
> to have these PR merged before LLVM branching.

Correct some of these instructions use opsel[1] which in LLVM in stored in 
src1_modifiers so a dummy src1 is used. And as far as I know we can not have 
src1_modfiers without src1 operand.

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


[compiler-rt] [clang-tools-extra] [llvm] [clang] [flang] [libc] [mlir] [libcxx] [clang] Remove `CXXNewInitializationStyle::Implicit` (PR #78793)

2024-01-22 Thread via cfe-commits

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

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


@@ -4842,19 +4842,19 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (Right.isOneOf(tok::identifier, tok::numeric_constant)) {
   // The alternative operators for ~ and ! are "compl" and "not".
   // If they are used instead, we do not want to combine them with
   // the token to the right, unless that is a left paren.

owenca wrote:

The comment needs to be updated.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

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


@@ -24160,6 +24160,14 @@ TEST_F(FormatTest, AlternativeOperators) {
   verifyFormat("int a compl(5);");
   verifyFormat("int a not(5);");
 
+  verifyFormat("v(not)");
+  verifyFormat("v(not!)");
+  verifyFormat("Symbol(not, None)");
+  verifyFormat("Symbol(not!, None)");
+
+  verifyFormat("assert(!\"fail\")");
+  verifyFormat("assert(not\"fail\")");

owenca wrote:

We should drop  them as they are invalid code (i.e. trigger compiler warnings).

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

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


@@ -4842,19 +4842,19 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (Right.isOneOf(tok::identifier, tok::numeric_constant)) {
   // The alternative operators for ~ and ! are "compl" and "not".
   // If they are used instead, we do not want to combine them with
   // the token to the right, unless that is a left paren.
   if (Left.is(tok::exclaim) && Left.TokenText == "not")
 return true;
   if (Left.is(tok::tilde) && Left.TokenText == "compl")
 return true;
-  // Lambda captures allow for a lone &, so "&]" needs to be properly
-  // handled.
-  if (Left.is(tok::amp) && Right.is(tok::r_square))
-return Style.SpacesInSquareBrackets;
 }
+// Lambda captures allow for a lone &, so "&]" needs to be properly
+// handled.
+if (Left.is(tok::amp) && Right.is(tok::r_square))
+  return Style.SpacesInSquareBrackets;
 return (Style.SpaceAfterLogicalNot && Left.is(tok::exclaim)) ||
Right.is(TT_BinaryOperator);

owenca wrote:

```suggestion
return Style.SpaceAfterLogicalNot && Left.is(tok::exclaim);
```
Would this suffice?

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


[libc] [clang] [libcxx] [llvm] [lld] [clang-tools-extra] [flang] [compiler-rt] [lldb] [AMDGPU][GFX12] VOP encoding and codegen - add support for v_cvt fp8/… (PR #78414)

2024-01-22 Thread Mirko Brkušanin via cfe-commits

mbrkusanin wrote:

> > > Why is so there so much special casing in the assembler/disassembler?
> > 
> > 
> > I'm not an original author of these change, but from what I understand it 
> > is a workaround to handle VOP3 instructions which have a single source but 
> > require the use of two bits from OPSEL. `V_CVT_F32_FP8` has one source but 
> > is using two bits from OPSEL to specify which part from 32 bit register to 
> > convert ([7:0], [15:8], [23: 16] or 31 : 24]). And since OPSELs are 
> > correlated with sources/destination (one bit from OPSEL with one 
> > soruce/destination) these is required without any deeper changes to 
> > TableGen.
> > I'm open to change TableGen, but I would prefer to create new ticket and do 
> > it with new PR. These change may take longer than one day and we would like 
> > to have these PR merged before LLVM branching.
> 
> Correct, some of these instructions use opsel[1] which in LLVM in stored in 
> src1_modifiers so a dummy src1 is used. And as far as I know we can not have 
> src1_modfiers without src1 operand.

Similarly V_CVT_SR_BF8_F32 for example uses opsel[2] and opsel[3] so we need 
src2_modifiers and src2.

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


[clang] [clang] WIP: Implement CTAD for type alias template. (PR #77890)

2024-01-22 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/77890

>From 89ae5aaf3bd6b4908191902b999ef9f6782d645f Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 26 Jul 2023 09:40:12 +0200
Subject: [PATCH 1/6] [clang] WIP: Implement CTAD for type alias template.

This is a preliminary,  WIP and messy implementation.

While it is still missing many pieces (see FIXMEs), it works for happy
cases.
---
 clang/include/clang/Sema/Sema.h   |  16 +-
 clang/lib/Sema/SemaInit.cpp   | 513 +-
 clang/lib/Sema/SemaTemplateDeduction.cpp  |   9 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  26 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  17 +-
 ...xx1z-class-template-argument-deduction.cpp |   6 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  |  32 ++
 7 files changed, 603 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0db39333b0ee347..d4348f03658200b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9280,6 +9280,14 @@ class Sema final {
   const TemplateArgumentList &TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  TemplateDeductionResult
+  DeduceTemplateArguments(TemplateParameterList *TemplateParams,
+  ArrayRef Ps,
+  ArrayRef As,
+  sema::TemplateDeductionInfo &Info,
+  SmallVectorImpl &Deduced,
+  bool NumberOfArgumentsMustMatch);
+
   TemplateDeductionResult SubstituteExplicitTemplateArguments(
   FunctionTemplateDecl *FunctionTemplate,
   TemplateArgumentListInfo &ExplicitTemplateArgs,
@@ -10432,9 +10440,11 @@ class Sema final {
   SourceLocation PointOfInstantiation, FunctionDecl *Decl,
   ArrayRef TemplateArgs,
   ConstraintSatisfaction &Satisfaction);
-  FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD,
-   const TemplateArgumentList 
*Args,
-   SourceLocation Loc);
+  FunctionDecl *InstantiateFunctionDeclaration(
+  FunctionTemplateDecl *FTD, const TemplateArgumentList *Args,
+  SourceLocation Loc,
+  CodeSynthesisContext::SynthesisKind CSC =
+  CodeSynthesisContext::ExplicitTemplateArgumentSubstitution);
   void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
  FunctionDecl *Function,
  bool Recursive = false,
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 18440a69e3a3d92..208fcd20b428f70 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10,13 +10,17 @@
 //
 
//===--===//
 
+#include "TreeTransform.h"
+#include "TypeLocBuilder.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclAccessPair.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
-#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
 #include "clang/AST/IgnoreExpr.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceManager.h"
@@ -28,6 +32,7 @@
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Ownership.h"
 #include "clang/Sema/SemaInternal.h"
+#include "clang/Sema/Template.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/PointerIntPair.h"
@@ -10583,6 +10588,381 @@ static bool 
isOrIsDerivedFromSpecializationOf(CXXRecordDecl *RD,
   return !(NotSpecialization(RD) && RD->forallBases(NotSpecialization));
 }
 
+
+/// FIXME: this is a copy-paste from SemaTemplate.cpp
+/// Tree transform to "extract" a transformed type from a class template's
+/// constructor to a deduction guide.
+class ExtractTypeForDeductionGuide
+  : public TreeTransform {
+  llvm::SmallVectorImpl &MaterializedTypedefs;
+
+public:
+  typedef TreeTransform Base;
+  ExtractTypeForDeductionGuide(
+  Sema &SemaRef,
+  llvm::SmallVectorImpl &MaterializedTypedefs)
+  : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs) {}
+
+  TypeSourceInfo *transform(TypeSourceInfo *TSI) { return TransformType(TSI); }
+
+  QualType TransformTypedefType(TypeLocBuilder &TLB, TypedefTypeLoc TL) {
+ASTContext &Context = SemaRef.getASTContext();
+TypedefNameDecl *OrigDecl = TL.getTypedefNameDecl();
+TypedefNameDecl *Decl = OrigDecl;
+// Transform the underlying type of the typedef and clone the Decl only if
+// the typedef has a dependent context.
+if (OrigDecl->getDeclContext()->isDependentContext()) {
+  TypeLocBuilder InnerTLB;
+  QualType Transformed =

[clang] [clang][analyzer] Add function 'fscanf' to StreamChecker. (PR #78180)

2024-01-22 Thread Balazs Benics via cfe-commits
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 


steakhal wrote:

This patch breaks a downstream test, like this:
```c++
void test_fscanf_2() {
  FILE *F1 = tmpfile();
  if (!F1)
return;

  int a;
  unsigned b;
  fscanf(F1, "%d %u", &a, &b);
  clang_analyzer_dump_int(a); // FP warning: 1st function call argument is an 
uninitialized value
  fclose(F1);
}
```
The FP is present, even if I guard the dump with `if (ret == 2)`.

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


[clang] [clang][Sema] Add checks for validity of default ctor's class (PR #78898)

2024-01-22 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> I decided to not include tests, because our testing infrastructure is not 
> ready to test that Clang doesn't crash without overspecifying the tests using 
> `-verify` mode.

Could you elaborate a bit more on that? What is the exact problem with the 
testing infrastructure? Can we just add a separate test with the cases from the 
issues, perhaps without `-verify` at all?

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-22 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm updated 
https://github.com/llvm/llvm-project/pull/77941

>From 34da3f6446c826ec1d2c7f6eb8020d1c18146b51 Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Thu, 4 Jan 2024 14:03:04 +
Subject: [PATCH 1/3] [Clang] Amend SME attributes with support for ZT0.

This patch builds on top of #76971 and implements support for:
* __arm_new("zt0")
* __arm_in("zt0")
* __arm_out("zt0")
* __arm_inout("zt0")
* __arm_preserves("zt0")

The patch is ready for review but won't be able to land until LLVM
implements support for handling ZT0 state.
---
 clang/include/clang/AST/Type.h| 16 --
 clang/include/clang/Basic/Attr.td |  3 +
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/AST/TypePrinter.cpp |  8 +++
 clang/lib/CodeGen/CGCall.cpp  | 10 
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +
 clang/lib/Sema/SemaChecking.cpp   | 22 +++
 clang/lib/Sema/SemaDecl.cpp   | 11 
 clang/lib/Sema/SemaDeclAttr.cpp   |  8 +++
 clang/lib/Sema/SemaType.cpp   |  3 +
 .../aarch64-sme2-attrs.cpp| 57 +++
 ...-sme-func-attrs-without-target-feature.cpp |  2 +
 clang/test/Sema/aarch64-sme-func-attrs.c  | 45 +++
 13 files changed, 186 insertions(+), 5 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 259e920acf9ff3b..ea425791fc97f05 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4056,10 +4056,12 @@ class FunctionType : public Type {
 // Describes the value of the state using ArmStateValue.
 SME_ZAShift = 2,
 SME_ZAMask = 0b111 << SME_ZAShift,
+SME_ZT0Shift = 5,
+SME_ZT0Mask = 0b111 << SME_ZT0Shift,
 
-SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeArmAttributes
-  // and ExtProtoInfo.
+SME_AttributeMask =
+0b111'111'11 // We can't support more than 8 bits because of
+ // the bitmask in FunctionTypeExtraBitfields.
   };
 
   enum ArmStateValue : unsigned {
@@ -4074,13 +4076,17 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
+  static ArmStateValue getArmZT0State(unsigned AttrBits) {
+return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
+  }
+
   /// A holder for Arm type attributes as described in the Arm C/C++
   /// Language extensions which are not particularly common to all
   /// types and therefore accounted separately from FunctionTypeBitfields.
   struct alignas(void *) FunctionTypeArmAttributes {
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 
 FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
   };
@@ -4266,7 +4272,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;
 RefQualifierKind RefQualifier = RQ_None;
 ExceptionSpecInfo ExceptionSpec;
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 78a9229aeaf081e..58838b01b4fd7ca 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2552,6 +2552,9 @@ def ArmNew : InheritableAttr, 
TargetSpecificAttr {
 bool isNewZA() const {
   return llvm::is_contained(newArgs(), "za");
 }
+bool isNewZT0() const {
+  return llvm::is_contained(newArgs(), "zt0");
+}
   }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 501968cb7d5f992..e027e754477fcf4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3706,10 +3706,14 @@ def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires 'sme'">;
 def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
+def err_sme_zt0_call_no_zt0_state : Error<
+  "call to a shared ZT0 function requires the caller to have ZT0 state">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<
   "function using ZA state requires 'sme'">;
+def err_sme_definition_using_zt0_in_non_sme2_target : Error<
+  "function using ZT0 state requires 'sme2'">;
 def err_conflicting_attributes_arm_state : Error<
 

[clang] [AArch64][Clang] Fix linker error for function multiversioning (PR #74358)

2024-01-22 Thread via cfe-commits

DanielKristofKiss wrote:

ping

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


[clang] [flang] [flang][driver] Allow explicit specification of -lFortran_main (PR #78152)

2024-01-22 Thread Tom Eccles via cfe-commits

tblah wrote:

> My suggestion:
> 
> * rename `Fortran_main.a` as e.g. `flang_fortran_main.a`,
> 
> * introduce `-ffortran-main` on top of `-fno-fortran-main`,
> 
> * disallow `-lFortran_main.a` and `-lflang_fortran_main.a` - this library 
> should be kept as an implementation detail of Flang that can change in the 
> future.

I tentatively support this. But I am concerned that disallowing 
`-lFortran_main` and renaming the library will break some existing (badly 
configured) builds (this is not just theoretical - see my comments above). 
Maybe we should merge a deprecation warning on -lFortran_main before the LLVM 
release, then make these changes only after the release has branched?

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


[clang] [clang-format] Add options to set number of empty lines after includes (PR #78957)

2024-01-22 Thread via cfe-commits

https://github.com/seranu created 
https://github.com/llvm/llvm-project/pull/78957

Add option to set the number of empty lines after include areas. 

An include area is a list of consecutive include statements. Include areas may 
be composed of multiple include blocks(group of related include statements) and 
may contain conditional compilation statements. Although in most cases source 
files have only one include area, there may be cases with several include areas.

EmtpyLinesAfterIncludes can be used to determine the number of empty lines to 
keep after each include area.

>From 351995614fb6155bcb621860f18d97f727ece101 Mon Sep 17 00:00:00 2001
From: Serban Ungureanu 
Date: Sat, 20 Jan 2024 17:02:04 +0200
Subject: [PATCH] [clang-format] Add options to set number of empty lines after
 includes

---
 clang/docs/ClangFormatStyleOptions.rst |  19 +++
 clang/docs/ReleaseNotes.rst|   1 +
 clang/include/clang/Format/Format.h|  18 ++
 clang/lib/Format/CMakeLists.txt|   1 +
 clang/lib/Format/Format.cpp|   9 +
 clang/lib/Format/IncludesSeparator.cpp | 160 ++
 clang/lib/Format/IncludesSeparator.h   |  42 +
 clang/lib/Format/TokenAnnotator.h  |   8 +
 clang/unittests/Format/ConfigParseTest.cpp |   2 +
 clang/unittests/Format/FormatTest.cpp  | 185 +
 10 files changed, 445 insertions(+)
 create mode 100644 clang/lib/Format/IncludesSeparator.cpp
 create mode 100644 clang/lib/Format/IncludesSeparator.h

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f265..4ba38808cd5090 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3220,6 +3220,25 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _EmptyLinesAfterIncludes:
+
+**EmptyLinesAfterIncludes** (``Unsigned``) :versionbadge:`clang-format 18` 
:ref:`¶ `
+  Number of lines after each include area. An include area is
+  a list of consecutive include statements. The include area may be
+  composed of multiple include blocks.
+  Limited by MaxEmptyLinesToKeep.
+  Example:
+
+  .. code-block:: c++
+
+
+ EmptyLinesAfterIncludes: 1  vs.  EmptyLinesAfterIncludes: 2
+ #include #include 
+ #include#include 
+
+ class Test {};
+  class Test {};
+
 .. _ExperimentalAutoDetectBinPacking:
 
 **ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 
3.7` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4888ffe6f4dfc8..e1bf86c8a83b67 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1260,6 +1260,7 @@ clang-format
 - Add ``.clang-format-ignore`` files.
 - Add ``AlignFunctionPointers`` sub-option for 
``AlignConsecutiveDeclarations``.
 - Add ``SkipMacroDefinitionBody`` option.
+- Add ``EmptyLinesAfterIncludes`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc9eecd42f9ebf..84d1a0b70b9efd 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2459,6 +2459,23 @@ struct FormatStyle {
   /// \version 12
   EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
 
+  /// \brief Number of lines after each include area. An include area is
+  /// a list of consecutive include statements. The include area may be
+  /// composed of multiple include blocks.
+  /// Limited by MaxEmptyLinesToKeep.
+  /// Example:
+  /// \code
+  ///
+  ///EmptyLinesAfterIncludes: 1  vs.  EmptyLinesAfterIncludes: 2
+  ///#include #include 
+  ///#include#include 
+  ///
+  ///class Test {};
+  /// class Test {};
+  /// \endcode
+  /// \version 18
+  std::optional EmptyLinesAfterIncludes;
+
   /// If ``true``, clang-format detects whether function calls and
   /// definitions are formatted with one parameter per line.
   ///
@@ -4831,6 +4848,7 @@ struct FormatStyle {
DerivePointerAlignment == R.DerivePointerAlignment &&
DisableFormat == R.DisableFormat &&
EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
+   EmptyLinesAfterIncludes == R.EmptyLinesAfterIncludes &&
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
diff --git a/clang/lib/Format/CMakeLists.txt b/clang/lib/Format/CMakeLists.txt
index 84a3c136f650a8..ff3860426407ad 100644
--- a/clang/lib/Format/CMakeLists.txt
+++ b/clang/lib/Format/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_library(clangFormat
   Format.cpp
   FormatToken.cpp
   FormatTokenLexer.cpp
+  IncludesSeparator.cpp
   IntegerLiteralSeparatorFixer.cpp
   MacroCallReconstructor.cpp
   MacroExpander.cp

[clang] [clang-format] Add options to set number of empty lines after includes (PR #78957)

2024-01-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: serbanu (seranu)


Changes

Add option to set the number of empty lines after include areas. 

An include area is a list of consecutive include statements. Include areas may 
be composed of multiple include blocks(group of related include statements) and 
may contain conditional compilation statements. Although in most cases source 
files have only one include area, there may be cases with several include areas.

EmtpyLinesAfterIncludes can be used to determine the number of empty lines to 
keep after each include area.

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


10 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+19) 
- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Format/Format.h (+18) 
- (modified) clang/lib/Format/CMakeLists.txt (+1) 
- (modified) clang/lib/Format/Format.cpp (+9) 
- (added) clang/lib/Format/IncludesSeparator.cpp (+160) 
- (added) clang/lib/Format/IncludesSeparator.h (+42) 
- (modified) clang/lib/Format/TokenAnnotator.h (+8) 
- (modified) clang/unittests/Format/ConfigParseTest.cpp (+2) 
- (modified) clang/unittests/Format/FormatTest.cpp (+185) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f2650..4ba38808cd5090a 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3220,6 +3220,25 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _EmptyLinesAfterIncludes:
+
+**EmptyLinesAfterIncludes** (``Unsigned``) :versionbadge:`clang-format 18` 
:ref:`¶ `
+  Number of lines after each include area. An include area is
+  a list of consecutive include statements. The include area may be
+  composed of multiple include blocks.
+  Limited by MaxEmptyLinesToKeep.
+  Example:
+
+  .. code-block:: c++
+
+
+ EmptyLinesAfterIncludes: 1  vs.  EmptyLinesAfterIncludes: 2
+ #include #include 
+ #include#include 
+
+ class Test {};
+  class Test {};
+
 .. _ExperimentalAutoDetectBinPacking:
 
 **ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 
3.7` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4888ffe6f4dfc85..e1bf86c8a83b671 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1260,6 +1260,7 @@ clang-format
 - Add ``.clang-format-ignore`` files.
 - Add ``AlignFunctionPointers`` sub-option for 
``AlignConsecutiveDeclarations``.
 - Add ``SkipMacroDefinitionBody`` option.
+- Add ``EmptyLinesAfterIncludes`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc9eecd42f9ebfd..84d1a0b70b9efd2 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2459,6 +2459,23 @@ struct FormatStyle {
   /// \version 12
   EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
 
+  /// \brief Number of lines after each include area. An include area is
+  /// a list of consecutive include statements. The include area may be
+  /// composed of multiple include blocks.
+  /// Limited by MaxEmptyLinesToKeep.
+  /// Example:
+  /// \code
+  ///
+  ///EmptyLinesAfterIncludes: 1  vs.  EmptyLinesAfterIncludes: 2
+  ///#include #include 
+  ///#include#include 
+  ///
+  ///class Test {};
+  /// class Test {};
+  /// \endcode
+  /// \version 18
+  std::optional EmptyLinesAfterIncludes;
+
   /// If ``true``, clang-format detects whether function calls and
   /// definitions are formatted with one parameter per line.
   ///
@@ -4831,6 +4848,7 @@ struct FormatStyle {
DerivePointerAlignment == R.DerivePointerAlignment &&
DisableFormat == R.DisableFormat &&
EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
+   EmptyLinesAfterIncludes == R.EmptyLinesAfterIncludes &&
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
diff --git a/clang/lib/Format/CMakeLists.txt b/clang/lib/Format/CMakeLists.txt
index 84a3c136f650a85..ff3860426407adc 100644
--- a/clang/lib/Format/CMakeLists.txt
+++ b/clang/lib/Format/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_library(clangFormat
   Format.cpp
   FormatToken.cpp
   FormatTokenLexer.cpp
+  IncludesSeparator.cpp
   IntegerLiteralSeparatorFixer.cpp
   MacroCallReconstructor.cpp
   MacroExpander.cpp
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff326dc784783b2..f068da97e6dfbff 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -20,6 +20,7 @@
 #include "FormatInternal.h"
 #include "FormatToken.h"
 #include "FormatTok

[clang] [clang] WIP: Implement CTAD for type alias template. (PR #77890)

2024-01-22 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/77890

>From 0f7ac82eaf79a483159351a44782c4b375f8e31b Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 26 Jul 2023 09:40:12 +0200
Subject: [PATCH 1/6] [clang] WIP: Implement CTAD for type alias template.

This is a preliminary,  WIP and messy implementation.

While it is still missing many pieces (see FIXMEs), it works for happy
cases.
---
 clang/include/clang/Sema/Sema.h   |  16 +-
 clang/lib/Sema/SemaInit.cpp   | 513 +-
 clang/lib/Sema/SemaTemplateDeduction.cpp  |   9 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  26 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  17 +-
 ...xx1z-class-template-argument-deduction.cpp |   6 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  |  32 ++
 7 files changed, 603 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d0f62afdf7bb16..8fbfe3f420ec48 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9280,6 +9280,14 @@ class Sema final {
   const TemplateArgumentList &TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  TemplateDeductionResult
+  DeduceTemplateArguments(TemplateParameterList *TemplateParams,
+  ArrayRef Ps,
+  ArrayRef As,
+  sema::TemplateDeductionInfo &Info,
+  SmallVectorImpl &Deduced,
+  bool NumberOfArgumentsMustMatch);
+
   TemplateDeductionResult SubstituteExplicitTemplateArguments(
   FunctionTemplateDecl *FunctionTemplate,
   TemplateArgumentListInfo &ExplicitTemplateArgs,
@@ -10432,9 +10440,11 @@ class Sema final {
   SourceLocation PointOfInstantiation, FunctionDecl *Decl,
   ArrayRef TemplateArgs,
   ConstraintSatisfaction &Satisfaction);
-  FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD,
-   const TemplateArgumentList 
*Args,
-   SourceLocation Loc);
+  FunctionDecl *InstantiateFunctionDeclaration(
+  FunctionTemplateDecl *FTD, const TemplateArgumentList *Args,
+  SourceLocation Loc,
+  CodeSynthesisContext::SynthesisKind CSC =
+  CodeSynthesisContext::ExplicitTemplateArgumentSubstitution);
   void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
  FunctionDecl *Function,
  bool Recursive = false,
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 91e4cb7b68a24a..177ff9cf1570b2 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10,13 +10,17 @@
 //
 
//===--===//
 
+#include "TreeTransform.h"
+#include "TypeLocBuilder.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclAccessPair.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
-#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
 #include "clang/AST/IgnoreExpr.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceManager.h"
@@ -28,6 +32,7 @@
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Ownership.h"
 #include "clang/Sema/SemaInternal.h"
+#include "clang/Sema/Template.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/PointerIntPair.h"
@@ -10603,6 +10608,381 @@ static bool 
isOrIsDerivedFromSpecializationOf(CXXRecordDecl *RD,
   return !(NotSpecialization(RD) && RD->forallBases(NotSpecialization));
 }
 
+
+/// FIXME: this is a copy-paste from SemaTemplate.cpp
+/// Tree transform to "extract" a transformed type from a class template's
+/// constructor to a deduction guide.
+class ExtractTypeForDeductionGuide
+  : public TreeTransform {
+  llvm::SmallVectorImpl &MaterializedTypedefs;
+
+public:
+  typedef TreeTransform Base;
+  ExtractTypeForDeductionGuide(
+  Sema &SemaRef,
+  llvm::SmallVectorImpl &MaterializedTypedefs)
+  : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs) {}
+
+  TypeSourceInfo *transform(TypeSourceInfo *TSI) { return TransformType(TSI); }
+
+  QualType TransformTypedefType(TypeLocBuilder &TLB, TypedefTypeLoc TL) {
+ASTContext &Context = SemaRef.getASTContext();
+TypedefNameDecl *OrigDecl = TL.getTypedefNameDecl();
+TypedefNameDecl *Decl = OrigDecl;
+// Transform the underlying type of the typedef and clone the Decl only if
+// the typedef has a dependent context.
+if (OrigDecl->getDeclContext()->isDependentContext()) {
+  TypeLocBuilder InnerTLB;
+  QualType Transformed =
+   

[clang] [clang-format] Add options to set number of empty lines after includes (PR #78957)

2024-01-22 Thread via cfe-commits

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


[clang] [clang-format] Add options to set number of empty lines after includes (PR #78957)

2024-01-22 Thread via cfe-commits

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


[clang] [clang] WIP: Implement CTAD for type alias template. (PR #77890)

2024-01-22 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/77890

>From 0b592732066e79c7ea64bdd2550a58bc86d9b464 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 26 Jul 2023 09:40:12 +0200
Subject: [PATCH 1/6] [clang] WIP: Implement CTAD for type alias template.

This is a preliminary,  WIP and messy implementation.

While it is still missing many pieces (see FIXMEs), it works for happy
cases.
---
 clang/include/clang/Sema/Sema.h   |  16 +-
 clang/lib/Sema/SemaInit.cpp   | 513 +-
 clang/lib/Sema/SemaTemplateDeduction.cpp  |   9 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  26 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  17 +-
 ...xx1z-class-template-argument-deduction.cpp |   6 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  |  32 ++
 7 files changed, 603 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d0f62afdf7bb163..8fbfe3f420ec485 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9280,6 +9280,14 @@ class Sema final {
   const TemplateArgumentList &TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  TemplateDeductionResult
+  DeduceTemplateArguments(TemplateParameterList *TemplateParams,
+  ArrayRef Ps,
+  ArrayRef As,
+  sema::TemplateDeductionInfo &Info,
+  SmallVectorImpl &Deduced,
+  bool NumberOfArgumentsMustMatch);
+
   TemplateDeductionResult SubstituteExplicitTemplateArguments(
   FunctionTemplateDecl *FunctionTemplate,
   TemplateArgumentListInfo &ExplicitTemplateArgs,
@@ -10432,9 +10440,11 @@ class Sema final {
   SourceLocation PointOfInstantiation, FunctionDecl *Decl,
   ArrayRef TemplateArgs,
   ConstraintSatisfaction &Satisfaction);
-  FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD,
-   const TemplateArgumentList 
*Args,
-   SourceLocation Loc);
+  FunctionDecl *InstantiateFunctionDeclaration(
+  FunctionTemplateDecl *FTD, const TemplateArgumentList *Args,
+  SourceLocation Loc,
+  CodeSynthesisContext::SynthesisKind CSC =
+  CodeSynthesisContext::ExplicitTemplateArgumentSubstitution);
   void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
  FunctionDecl *Function,
  bool Recursive = false,
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 91e4cb7b68a24a9..177ff9cf1570b28 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10,13 +10,17 @@
 //
 
//===--===//
 
+#include "TreeTransform.h"
+#include "TypeLocBuilder.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclAccessPair.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
-#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
 #include "clang/AST/IgnoreExpr.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceManager.h"
@@ -28,6 +32,7 @@
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Ownership.h"
 #include "clang/Sema/SemaInternal.h"
+#include "clang/Sema/Template.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/PointerIntPair.h"
@@ -10603,6 +10608,381 @@ static bool 
isOrIsDerivedFromSpecializationOf(CXXRecordDecl *RD,
   return !(NotSpecialization(RD) && RD->forallBases(NotSpecialization));
 }
 
+
+/// FIXME: this is a copy-paste from SemaTemplate.cpp
+/// Tree transform to "extract" a transformed type from a class template's
+/// constructor to a deduction guide.
+class ExtractTypeForDeductionGuide
+  : public TreeTransform {
+  llvm::SmallVectorImpl &MaterializedTypedefs;
+
+public:
+  typedef TreeTransform Base;
+  ExtractTypeForDeductionGuide(
+  Sema &SemaRef,
+  llvm::SmallVectorImpl &MaterializedTypedefs)
+  : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs) {}
+
+  TypeSourceInfo *transform(TypeSourceInfo *TSI) { return TransformType(TSI); }
+
+  QualType TransformTypedefType(TypeLocBuilder &TLB, TypedefTypeLoc TL) {
+ASTContext &Context = SemaRef.getASTContext();
+TypedefNameDecl *OrigDecl = TL.getTypedefNameDecl();
+TypedefNameDecl *Decl = OrigDecl;
+// Transform the underlying type of the typedef and clone the Decl only if
+// the typedef has a dependent context.
+if (OrigDecl->getDeclContext()->isDependentContext()) {
+  TypeLocBuilder InnerTLB;
+  QualType Transformed =

[clang] [clang-format] Add options to set number of empty lines after includes (PR #78957)

2024-01-22 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff cc38cff05cfafb92bf91aadc39692ec5e12710a0 
351995614fb6155bcb621860f18d97f727ece101 -- 
clang/lib/Format/IncludesSeparator.cpp clang/lib/Format/IncludesSeparator.h 
clang/include/clang/Format/Format.h clang/lib/Format/Format.cpp 
clang/lib/Format/TokenAnnotator.h clang/unittests/Format/ConfigParseTest.cpp 
clang/unittests/Format/FormatTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Format/IncludesSeparator.cpp 
b/clang/lib/Format/IncludesSeparator.cpp
index 7aad7b9d36..0e74383c7c 100644
--- a/clang/lib/Format/IncludesSeparator.cpp
+++ b/clang/lib/Format/IncludesSeparator.cpp
@@ -157,4 +157,3 @@ void IncludesSeparator::separateIncludes(
 }
 } // namespace format
 } // namespace clang
-
\ No newline at end of file

``




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


[clang] [clang-format] Separate License text and include blocks (PR #77918)

2024-01-22 Thread via cfe-commits

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


  1   2   3   4   5   6   7   >