[clang-tools-extra] [clang] [llvm] [X86] Emit Warnings for frontend options to enable knl/knm specific ISAs. (PR #75580)

2024-01-09 Thread Shengchen Kan via cfe-commits

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


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


[clang] [flang] [flang][Driver] Support -pthread in the frontend (PR #77360)

2024-01-09 Thread Kareem Ergawy via cfe-commits

ergawy wrote:

Thanks @tarunprabhu for opening this. I indeed closed my original PR but was 
about to reopen it after last week's discussion.

At least for the GNU toolchain, it won't be easy to come up with a simple test 
that fails without `-pthread`. The reason is that the pthread API is actually 
exported by `libc` and that `-lc` is added by the GNU toolchain in the driver 
in any case.

Just to give more context, I tested with the following program:
```
program main  
INTERFACE
  SUBROUTINE pthread_create() BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT
IMPLICIT NONE
  END SUBROUTINE pthread_create
END INTERFACE


print*, "=== Calling pthread_create() ==="
call pthread_create()
end program main
```
And expected `./bin/flang-new /tmp/test_pthread.f90 -o /tmp/test_pthread_2 -v` 
to complain that the `pthread_create()` symbol is undefined. However, it 
compiles and links fine.

And if you look at the linker command, you find it looks like this:
```
"/work/kaergawy/git/trunk18.0/build/llvm-project/bin/ld.lld" -z relro 
--hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker 
/lib64/ld-linux-x86-64.so.2 -o /tmp/test_pthread_2 /lib/x86_64-linux-gnu/crt1.o 
/lib/x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/12/crtbegin.o 
-L/work/kaergawy/git/trunk18.0/build/llvm-project/lib/clang/18/lib/x86_64-unknown-linux-gnu
 -L/usr/lib/gcc/x86_64-linux-gnu/12 
-L/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib64 -L/lib/x86_64-linux-gnu 
-L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/lib 
-L/usr/lib /tmp/test_pthread_fortran.o 
-L/work/kaergawy/git/trunk18.0/build/llvm-project/lib --whole-archive 
-lFortran_main --no-whole-archive -lFortranRuntime -lFortranDecimal -lm -lgcc 
--as-needed -lgcc_s --no-as-needed >> -lc << -lgcc --as-needed -lgcc_s 
--no-as-needed /usr/lib/gcc/x86_64-linux-gnu/12/crtend.o 
/lib/x86_64-linux-gnu/crtn.o
```
Note the `-lc` flag that I highligted with `>> ... <<` above. If you remove 
that flag from the linker command, you get:
```
ld.lld: error: undefined symbol: pthread_create
>>> referenced by FIRModule
>>>   /tmp/test_pthread_fortran.o:(_QQmain)

ld.lld: error: undefined symbol: __libc_start_main
>>> referenced by /lib/x86_64-linux-gnu/crt1.o:(_start)
```

And indeed if you `nm --defined-only /usr/lib/x86_64-linux-gnu/libc.a`, you 
find that `pthread_create` is actually defined by `libc`.

---

That said, what @tarunprabhu mentioned about OpenMPI wrappers adding the flag 
is indeed correct as mentioned by  Brian Cornille in the last flang bi-weekly. 
So adding the flag would indeed make sense even if it is redundant for the GNU 
toolchain but it would be consistent with `clang`. However, coming up with a 
failing test will prove more difficult that it initially seems.

I shared the PR with Brian since I cannot add him as a reviewer.

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


[clang] [clang-tools-extra] [llvm] [X86] Emit Warnings for frontend options to enable knl/knm specific ISAs. (PR #75580)

2024-01-09 Thread Simon Pilgrim via cfe-commits

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

LGTM - please make sure you adjust the commit message (the patch summary 
doesn't refer to removing just the knl/knm specific ISAs)

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


[clang] [ASTMatchers] fix captureVars assertion failure on capturesVariables (PR #76619)

2024-01-09 Thread Ding Fei via cfe-commits

danix800 wrote:

> Thank you for the fix, can you add more details to your summary. The summary 
> is what usually goes into the git log. We would like those to be as 
> descriptive as possible to avoid having to do extra digging to understand the 
> change at a high level.

Thanks for reminding. Summary updated, please take another look.

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


[clang] [ASTMatchers] fix captureVars assertion failure on capturesVariables (PR #76619)

2024-01-09 Thread Ding Fei via cfe-commits

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


[clang] [ASTMatchers] fix captureVars assertion failure on capturesVariables (PR #76619)

2024-01-09 Thread Ding Fei via cfe-commits

https://github.com/danix800 updated 
https://github.com/llvm/llvm-project/pull/76619

>From 50c0ccd9a28896a1f8f673446054abd6f18703a9 Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Sun, 31 Dec 2023 00:32:01 +0800
Subject: [PATCH] [ASTMatchers] fix captureVars assertion failure on
 capturesVariables

Matcher 'capturesVar' should check for capturesVariables() before
calling getCaptureVar() since it asserts this LambdaCapture does capture
a variable.

Fixes #76425
---
 clang/include/clang/ASTMatchers/ASTMatchers.h   | 2 ++
 clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 82a26356c58f556..91c33e4b1163e6d 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4817,6 +4817,8 @@ AST_MATCHER_P(LambdaExpr, hasAnyCapture, 
internal::Matcher,
 /// capturesVar(hasName("x")) matches `x` and `x = 1`.
 AST_MATCHER_P(LambdaCapture, capturesVar, internal::Matcher,
   InnerMatcher) {
+  if (!Node.capturesVariable())
+return false;
   auto *capturedVar = Node.getCapturedVar();
   return capturedVar && InnerMatcher.matches(*capturedVar, Finder, Builder);
 }
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 8f0dd5602307c53..eb493f9c3050acb 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2308,6 +2308,8 @@ TEST_P(ASTMatchersTest, 
LambdaCaptureTest_BindsToCaptureOfVarDecl) {
   matches("int main() { int cc; auto f = [=](){ return cc; }; }", 
matcher));
   EXPECT_TRUE(
   matches("int main() { int cc; auto f = [&](){ return cc; }; }", 
matcher));
+  EXPECT_TRUE(matches(
+  "void f(int a) { int cc[a]; auto f = [&](){ return cc;}; }", matcher));
 }
 
 TEST_P(ASTMatchersTest, LambdaCaptureTest_BindsToCaptureWithInitializer) {

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


[clang] [clang-tools-extra] [llvm] [AMDGPU] Flip the default value of maybeAtomic. NFCI. (PR #75220)

2024-01-09 Thread Jay Foad via cfe-commits

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


[clang-tools-extra] [llvm] [Matrix] Convert column-vector ops feeding dot product to row-vectors. (PR #72647)

2024-01-09 Thread Florian Hahn via cfe-commits

fhahn wrote:

ping :) 

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


[llvm] [clang-tools-extra] [Matrix] Convert column-vector ops feeding dot product to row-vectors. (PR #72647)

2024-01-09 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/72647

>From 3dfe86782806f048b130d46afa6293712919f672 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Fri, 14 Apr 2023 14:33:57 +0100
Subject: [PATCH] [Matrix] Convert column-vector ops feeding dot product to
 row-vectors.

Generalize the logic used to convert column-vector ops to row-vectors to
support converting chains of operations.

A potential next step is to further generalize this to convert
column-vector ops to row-vector ops in general, not just for operands of
dot products. Dot-product handling would then be driven by the general
conversion, rather than the other way around.
---
 .../Scalar/LowerMatrixIntrinsics.cpp  | 51 ++-
 .../LowerMatrixIntrinsics/dot-product-int.ll  | 47 -
 2 files changed, 47 insertions(+), 51 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp 
b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
index 72b9db1e73d73d..c6bb43d3a78cf3 100644
--- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
@@ -1332,8 +1332,8 @@ class LowerMatrixIntrinsics {
 if (!IsIntVec && !FMF.allowReassoc())
   return;
 
-auto CanBeFlattened = [this](Value *Op) {
-  if (match(Op, m_BinOp()) && ShapeMap.find(Op) != ShapeMap.end())
+auto CanBeFlattened = [](Value *Op) {
+  if (match(Op, m_BinOp()))
 return true;
   return match(
   Op, m_OneUse(m_CombineOr(
@@ -1346,6 +1346,9 @@ class LowerMatrixIntrinsics {
 // the returned cost is < 0, the argument is cheaper to use in the
 // dot-product lowering.
 auto GetCostForArg = [this, ](Value *Op, unsigned N) {
+  if (ShapeMap.find(Op) == ShapeMap.end())
+return InstructionCost::getInvalid();
+
   if (!isa(Op))
 return InstructionCost(0);
 
@@ -1356,7 +1359,7 @@ class LowerMatrixIntrinsics {
 InstructionCost EmbedCost(0);
 // Roughly estimate the cost for embedding the columns into a vector.
 for (unsigned I = 1; I < N; ++I)
-  EmbedCost -=
+  EmbedCost +=
   TTI.getShuffleCost(TTI::SK_Splice, FixedVectorType::get(EltTy, 
1),
  std::nullopt, TTI::TCK_RecipThroughput);
 return EmbedCost;
@@ -1378,7 +1381,7 @@ class LowerMatrixIntrinsics {
 // vector.
 InstructionCost EmbedCost(0);
 for (unsigned I = 1; I < N; ++I)
-  EmbedCost +=
+  EmbedCost -=
   TTI.getShuffleCost(TTI::SK_Splice, FixedVectorType::get(EltTy, 
1),
  std::nullopt, TTI::TCK_RecipThroughput);
 return EmbedCost;
@@ -1391,7 +1394,26 @@ class LowerMatrixIntrinsics {
   return TTI.getMemoryOpCost(Instruction::Load, VecTy, Align(1), 0) -
  N * TTI.getMemoryOpCost(Instruction::Load, EltTy, Align(1), 0);
 };
-auto LHSCost = GetCostForArg(LHS, LShape.NumColumns);
+
+SmallPtrSet Seen;
+SmallVector WorkList;
+SmallVector ToFlatten;
+WorkList.push_back(LHS);
+InstructionCost LHSCost(0);
+while (!WorkList.empty()) {
+  Value *Op = WorkList.pop_back_val();
+  if (!Seen.insert(Op).second)
+continue;
+
+  InstructionCost OpCost = GetCostForArg(Op, LShape.NumColumns);
+  if (OpCost + LHSCost >= LHSCost)
+continue;
+
+  LHSCost += OpCost;
+  ToFlatten.push_back(Op);
+  if (auto *I = dyn_cast(Op))
+WorkList.append(I->op_begin(), I->op_end());
+}
 
 // We compare the costs of a vector.reduce.add to sequential add.
 int AddOpCode = IsIntVec ? Instruction::Add : Instruction::FAdd;
@@ -1412,16 +1434,16 @@ class LowerMatrixIntrinsics {
 FusedInsts.insert(MatMul);
 IRBuilder<> Builder(MatMul);
 auto FlattenArg = [, , ,
-   this](Value *Op) -> Value * {
+   this](Value *Op) {
   // Matmul must be the only user of loads because we don't use LowerLoad
   // for row vectors (LowerLoad results in scalar loads and shufflevectors
   // instead of single vector load).
   if (!CanBeFlattened(Op))
-return Op;
+return;
 
   if (match(Op, m_BinOp()) && ShapeMap.find(Op) != ShapeMap.end()) {
 ShapeMap[Op] = ShapeMap[Op].t();
-return Op;
+return;
   }
 
   FusedInsts.insert(cast(Op));
@@ -1432,16 +1454,19 @@ class LowerMatrixIntrinsics {
 auto *NewLoad = Builder.CreateLoad(Op->getType(), Arg);
 Op->replaceAllUsesWith(NewLoad);
 cast(Op)->eraseFromParent();
-return NewLoad;
+return;
   } else if (match(Op, m_Intrinsic(
m_Value(Arg {
 ToRemove.push_back(cast(Op));
-return Arg;
+Op->replaceAllUsesWith(Arg);
+return;
   }
-
-  return Op;
 };
-LHS = FlattenArg(LHS);
+
+for (auto *V : ToFlatten)
+  

[llvm] [clang] [RISCV] Add experimental support of Zaamo and Zalrsc (PR #77424)

2024-01-09 Thread Wang Pengcheng via cfe-commits


@@ -0,0 +1,11 @@
+# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-zaamo < %s 2>&1 | 
FileCheck %s

wangpc-pp wrote:

This can be done in the future, I think.
Current implementation refers to the `Zmmul` (which is a sub-extension of M 
extension). The case is the same for `Zaamo` and `Zalrsc` I think.

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


[lldb] [mlir] [polly] [lld] [libcxx] [flang] [llvm] [clang] [compiler-rt] [openmp] [libc] [WebAssembly] Correctly consider signext/zext arg flags at function declaration (PR #77281)

2024-01-09 Thread Alex Bradbury via cfe-commits

asb wrote:

In case anyone was wondering how this is handled in SelectionDAG, I believe 
it's covered by CallLoweringInfo ultimately determining if an arg is sext/zext 
through CallBase::paramHasAttr, which does indeed check both the callsite and 
the called function (if it's a direct call of course). Indeed, I think you 
could just switch to using paramHasAttr in this patch and get the desired 
behaviour (which seems to be what ARMFastISel does in its `SelectCall` 
implementation).

Although this does fix a real bug, I'd strongly advise that a bug be filed 
against whatever code generated produced a call lacking the matching 
signext/zeroext attribute as the caller. I don't believe that in general LLVM 
is particularly well tested or robust against such inconsistencies, so it's 
likely to run into bugs.

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


[libclc] libclc: generic: add half implementation for erf/erfc (PR #66901)

2024-01-09 Thread Kévin Petit via cfe-commits

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

Looks infinitely better than the absence of FP16 implementation we currently 
have. I have not tried to think through rounding and other detailed 
considerations. The OpenCL CTS currently does not cover FP16 variants of these 
functions but I believe this is in the works. We can revisit the implementation 
if the conformance tests reveal issues.

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


[clang] [clang][analyzer] Implement modeling of 'fputc' in the StdLibraryFunctionsChecker (PR #77435)

2024-01-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes



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


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+14) 
- (modified) clang/test/Analysis/Inputs/std-c-library-functions.h (+1) 
- (modified) clang/test/Analysis/errno-stdlibraryfunctions.c (+14) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 034825d88a44de..f160c464dc273a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2277,6 +2277,20 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .Case({}, ErrnoMustBeChecked)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int fputc(int c, FILE *stream);
+addToFunctionSummaryMap(
+"fputc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ArgumentCondition(0, WithinRange, Range(0, UCharRangeMax)),
+   ReturnValueCondition(BO_EQ, ArgNo(0))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ArgumentCondition(0, OutOfRange, Range(0, UCharRangeMax)),
+   ReturnValueCondition(WithinRange, Range(0, UCharRangeMax))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(1;
+
 // void clearerr(FILE *stream);
 addToFunctionSummaryMap(
 "clearerr", Signature(ArgTypes{FilePtrTy}, RetType{VoidTy}),
diff --git a/clang/test/Analysis/Inputs/std-c-library-functions.h 
b/clang/test/Analysis/Inputs/std-c-library-functions.h
index 7c86c359ee21de..6cb2d1be7a9b11 100644
--- a/clang/test/Analysis/Inputs/std-c-library-functions.h
+++ b/clang/test/Analysis/Inputs/std-c-library-functions.h
@@ -37,6 +37,7 @@ int toascii(int);
 
 int getc(FILE *);
 int fgetc(FILE *);
+int fputc(int c, FILE *stream);
 int getchar(void);
 size_t fread(void *restrict, size_t, size_t, FILE *restrict);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index 9e3d07e7aa88a0..9ece662a937072 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -89,3 +89,17 @@ void errno_getcwd(char *Buf, size_t Sz) {
 if (errno) {}  // expected-warning{{An undefined value 
may be read from 'errno'}}
   }
 }
+
+void errno_fputc(int C, FILE *Fp) {
+  int Ret = fputc(C, Fp);
+  if (Ret == EOF) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  } else if (C >= 0 && C <= 255) {
+clang_analyzer_eval(Ret == C);   // expected-warning{{TRUE}}
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  } else {
+clang_analyzer_eval(Ret != C);   // expected-warning{{TRUE}}
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+}

``




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


[clang] [clang][analyzer] Implement modeling of 'fputc' in the StdLibraryFunctionsChecker (PR #77435)

2024-01-09 Thread Ben Shi via cfe-commits

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/77435

None

>From 0ff61f497b99b45b1697289cf5d44fb3ecab2aba Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Tue, 9 Jan 2024 17:48:02 +0800
Subject: [PATCH] [clang][analyzer] Implement modeling of 'fputc' in the
 StdLibraryFunctionsChecker

---
 .../Checkers/StdLibraryFunctionsChecker.cpp| 14 ++
 .../test/Analysis/Inputs/std-c-library-functions.h |  1 +
 clang/test/Analysis/errno-stdlibraryfunctions.c| 14 ++
 3 files changed, 29 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 034825d88a44de..f160c464dc273a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2277,6 +2277,20 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .Case({}, ErrnoMustBeChecked)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int fputc(int c, FILE *stream);
+addToFunctionSummaryMap(
+"fputc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ArgumentCondition(0, WithinRange, Range(0, UCharRangeMax)),
+   ReturnValueCondition(BO_EQ, ArgNo(0))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ArgumentCondition(0, OutOfRange, Range(0, UCharRangeMax)),
+   ReturnValueCondition(WithinRange, Range(0, UCharRangeMax))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(1;
+
 // void clearerr(FILE *stream);
 addToFunctionSummaryMap(
 "clearerr", Signature(ArgTypes{FilePtrTy}, RetType{VoidTy}),
diff --git a/clang/test/Analysis/Inputs/std-c-library-functions.h 
b/clang/test/Analysis/Inputs/std-c-library-functions.h
index 7c86c359ee21de..6cb2d1be7a9b11 100644
--- a/clang/test/Analysis/Inputs/std-c-library-functions.h
+++ b/clang/test/Analysis/Inputs/std-c-library-functions.h
@@ -37,6 +37,7 @@ int toascii(int);
 
 int getc(FILE *);
 int fgetc(FILE *);
+int fputc(int c, FILE *stream);
 int getchar(void);
 size_t fread(void *restrict, size_t, size_t, FILE *restrict);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index 9e3d07e7aa88a0..9ece662a937072 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -89,3 +89,17 @@ void errno_getcwd(char *Buf, size_t Sz) {
 if (errno) {}  // expected-warning{{An undefined value 
may be read from 'errno'}}
   }
 }
+
+void errno_fputc(int C, FILE *Fp) {
+  int Ret = fputc(C, Fp);
+  if (Ret == EOF) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no warning
+  } else if (C >= 0 && C <= 255) {
+clang_analyzer_eval(Ret == C);   // expected-warning{{TRUE}}
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  } else {
+clang_analyzer_eval(Ret != C);   // expected-warning{{TRUE}}
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+}

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


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

qmfrederik wrote:

@compnerd Thanks for you feedback, I addressed your comments.

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


[clang-tools-extra] [llvm] [clang] [AMDGPU] Flip the default value of maybeAtomic. NFCI. (PR #75220)

2024-01-09 Thread Jay Foad via cfe-commits

https://github.com/jayfoad updated 
https://github.com/llvm/llvm-project/pull/75220

>From 429d0a22cd4208eb0c854ccf98df1ba86fd3b0cb Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Tue, 12 Dec 2023 17:15:26 +
Subject: [PATCH] [AMDGPU] Flip the default value of maybeAtomic. NFCI.

In practice maybeAtomic = 0 is used to prevent SIMemoryLegalizer from
interfering with instructions that are mayLoad or mayStore but lack
MachineMemOperands. These instructions should be the exception not the
rule, so this patch sets maybeAtomic = 1 by default and only overrides
it to 0 where necessary.
---
 llvm/lib/Target/AMDGPU/BUFInstructions.td| 4 
 llvm/lib/Target/AMDGPU/DSInstructions.td | 1 -
 llvm/lib/Target/AMDGPU/EXPInstructions.td| 1 +
 llvm/lib/Target/AMDGPU/FLATInstructions.td   | 7 ---
 llvm/lib/Target/AMDGPU/LDSDIRInstructions.td | 1 +
 llvm/lib/Target/AMDGPU/SIInstrFormats.td | 2 +-
 llvm/lib/Target/AMDGPU/SIInstructions.td | 2 +-
 llvm/lib/Target/AMDGPU/SMInstructions.td | 1 +
 8 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/BUFInstructions.td 
b/llvm/lib/Target/AMDGPU/BUFInstructions.td
index 44fd4ef8641270..4696ea47f9cefd 100644
--- a/llvm/lib/Target/AMDGPU/BUFInstructions.td
+++ b/llvm/lib/Target/AMDGPU/BUFInstructions.td
@@ -477,7 +477,6 @@ class MUBUF_Load_Pseudo .ret;
   let mayLoad = 0;
   let mayStore = 1;
-  let maybeAtomic = 1;
   let elements = getMUBUFElements.ret;
   let tfe = isTFE;
 }
@@ -618,7 +616,6 @@ class MUBUF_Pseudo_Store_Lds
   let LGKM_CNT = 1;
   let mayLoad = 1;
   let mayStore = 1;
-  let maybeAtomic = 1;
 
   let has_vdata = 0;
   let has_vaddr = 0;
@@ -680,7 +677,6 @@ class MUBUF_Atomic_Pseudo patt
   // Most instruction load and store data, so set this as the default.
   let mayLoad = 1;
   let mayStore = 1;
-  let maybeAtomic = 1;
 
   let hasSideEffects = 0;
   let SchedRW = [WriteLDS];
diff --git a/llvm/lib/Target/AMDGPU/EXPInstructions.td 
b/llvm/lib/Target/AMDGPU/EXPInstructions.td
index ff1d661ef6fe1d..4cfee7d013ef1a 100644
--- a/llvm/lib/Target/AMDGPU/EXPInstructions.td
+++ b/llvm/lib/Target/AMDGPU/EXPInstructions.td
@@ -20,6 +20,7 @@ class EXPCommon : InstSI<
   let EXP_CNT = 1;
   let mayLoad = done;
   let mayStore = 1;
+  let maybeAtomic = 0;
   let UseNamedOperandTable = 1;
   let Uses = !if(row, [EXEC, M0], [EXEC]);
   let SchedRW = [WriteExport];
diff --git a/llvm/lib/Target/AMDGPU/FLATInstructions.td 
b/llvm/lib/Target/AMDGPU/FLATInstructions.td
index c0251164faee8b..a1ff3af663352e 100644
--- a/llvm/lib/Target/AMDGPU/FLATInstructions.td
+++ b/llvm/lib/Target/AMDGPU/FLATInstructions.td
@@ -173,7 +173,6 @@ class FLAT_Load_Pseudo  {
@@ -221,7 +219,6 @@ class FLAT_Global_Load_AddTid_Pseudo  {
@@ -450,7 +444,6 @@ class FLAT_AtomicNoRet_Pseudo : InstSI<
   let hasSideEffects = 0;
   let mayLoad = 1;
   let mayStore = 0;
+  let maybeAtomic = 0;
 
   string Mnemonic = opName;
   let UseNamedOperandTable = 1;
diff --git a/llvm/lib/Target/AMDGPU/SIInstrFormats.td 
b/llvm/lib/Target/AMDGPU/SIInstrFormats.td
index 585a3eb7861878..1b66d163714fbc 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrFormats.td
+++ b/llvm/lib/Target/AMDGPU/SIInstrFormats.td
@@ -91,7 +91,7 @@ class InstSI  {
   let hasSideEffects = 1;
-  let maybeAtomic = 1;
 }
 
 let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Uses = [EXEC] in {
@@ -557,6 +556,7 @@ def SI_MASKED_UNREACHABLE : SPseudoInstSI <(outs), (ins),
   let hasNoSchedulingInfo = 1;
   let FixedSize = 1;
   let isMeta = 1;
+  let maybeAtomic = 0;
 }
 
 // Used as an isel pseudo to directly emit initialization with an
diff --git a/llvm/lib/Target/AMDGPU/SMInstructions.td 
b/llvm/lib/Target/AMDGPU/SMInstructions.td
index c18846483cf95a..323f49ab91f01e 100644
--- a/llvm/lib/Target/AMDGPU/SMInstructions.td
+++ b/llvm/lib/Target/AMDGPU/SMInstructions.td
@@ -29,6 +29,7 @@ class SM_Pseudo  patt
   let mayStore = 0;
   let mayLoad = 1;
   let hasSideEffects = 0;
+  let maybeAtomic = 0;
   let UseNamedOperandTable = 1;
   let SchedRW = [WriteSMEM];
 

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


[clang] [clang][Parser] Pop scope prior VarDecl invalidating by invalid init (PR #77434)

2024-01-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ding Fei (danix800)


Changes

Invalid (direct) initializer would invalid `VarDecl` so `InitializerScopeRAII` 
cannot restore scope stack balance.

As with other kind of initializer, `InitializerScopeRAII::pop()` is moved up 
before `Sema::ActOnInitializerError()` which invalidates the `VarDecl`, so 
scope can be balanced and current `DeclContext` can be restored.

Fixes #30908

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


2 Files Affected:

- (modified) clang/lib/Parse/ParseDecl.cpp (+6-2) 
- (added) 
clang/test/Parser/gh30908-scope-balance-on-invalid-var-direct-init.cpp (+22) 


``diff
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index b60ae293ef8c20..ed684c5d57b1ee 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2661,7 +2661,12 @@ Decl 
*Parser::ParseDeclarationAfterDeclaratorAndAttributes(
   // ProduceConstructorSignatureHelp only on VarDecls.
   ExpressionStarts = SetPreferredType;
 }
-if (ParseExpressionList(Exprs, ExpressionStarts)) {
+
+bool SawError = ParseExpressionList(Exprs, ExpressionStarts);
+
+InitScope.pop();
+
+if (SawError) {
   if (ThisVarDecl && PP.isCodeCompletionReached() && !CalledSignatureHelp) 
{
 Actions.ProduceConstructorSignatureHelp(
 ThisVarDecl->getType()->getCanonicalTypeInternal(),
@@ -2674,7 +2679,6 @@ Decl 
*Parser::ParseDeclarationAfterDeclaratorAndAttributes(
 } else {
   // Match the ')'.
   T.consumeClose();
-  InitScope.pop();
 
   ExprResult Initializer = Actions.ActOnParenListExpr(T.getOpenLocation(),
   T.getCloseLocation(),
diff --git 
a/clang/test/Parser/gh30908-scope-balance-on-invalid-var-direct-init.cpp 
b/clang/test/Parser/gh30908-scope-balance-on-invalid-var-direct-init.cpp
new file mode 100644
index 00..02200ce4f34a75
--- /dev/null
+++ b/clang/test/Parser/gh30908-scope-balance-on-invalid-var-direct-init.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#include  // expected-error {{file not found}}
+
+class S {};
+
+template 
+class E {
+public:
+  E(S* scope) {}
+  S ();
+};
+
+class Z {
+ private:
+  static E e;
+  static S& s();
+};
+
+E Z::e(&__UNKNOWN_ID__);
+
+S& Z::s() { return Z::e.getS(); }

``




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


[clang] [clang][Parser] Pop scope prior VarDecl invalidating by invalid init (PR #77434)

2024-01-09 Thread Ding Fei via cfe-commits

https://github.com/danix800 created 
https://github.com/llvm/llvm-project/pull/77434

Invalid (direct) initializer would invalid `VarDecl` so `InitializerScopeRAII` 
cannot restore scope stack balance.

As with other kind of initializer, `InitializerScopeRAII::pop()` is moved up 
before `Sema::ActOnInitializerError()` which invalidates the `VarDecl`, so 
scope can be balanced and current `DeclContext` can be restored.

Fixes #30908

>From 6934d23d9276a0a0997a31d206ffaaa146243db1 Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Tue, 9 Jan 2024 16:40:23 +0800
Subject: [PATCH] [clang][Parser] Pop scope prior VarDecl invalidating by
 invalid direct Init

Invalid (direct) initializer would invalid VarDecl so InitializerScopeRAII
cannot restore scope stack balance.

As with other kind of initializer, InitializerScopeRAII::pop() is moved up
before Sema::ActOnInitializerError() which invalidates the VarDecl, so
scope can be balanced and current DeclContext can be restored.

Fixes #30908
---
 clang/lib/Parse/ParseDecl.cpp |  8 +--
 ...ope-balance-on-invalid-var-direct-init.cpp | 22 +++
 2 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/Parser/gh30908-scope-balance-on-invalid-var-direct-init.cpp

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index b60ae293ef8c20..ed684c5d57b1ee 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2661,7 +2661,12 @@ Decl 
*Parser::ParseDeclarationAfterDeclaratorAndAttributes(
   // ProduceConstructorSignatureHelp only on VarDecls.
   ExpressionStarts = SetPreferredType;
 }
-if (ParseExpressionList(Exprs, ExpressionStarts)) {
+
+bool SawError = ParseExpressionList(Exprs, ExpressionStarts);
+
+InitScope.pop();
+
+if (SawError) {
   if (ThisVarDecl && PP.isCodeCompletionReached() && !CalledSignatureHelp) 
{
 Actions.ProduceConstructorSignatureHelp(
 ThisVarDecl->getType()->getCanonicalTypeInternal(),
@@ -2674,7 +2679,6 @@ Decl 
*Parser::ParseDeclarationAfterDeclaratorAndAttributes(
 } else {
   // Match the ')'.
   T.consumeClose();
-  InitScope.pop();
 
   ExprResult Initializer = Actions.ActOnParenListExpr(T.getOpenLocation(),
   T.getCloseLocation(),
diff --git 
a/clang/test/Parser/gh30908-scope-balance-on-invalid-var-direct-init.cpp 
b/clang/test/Parser/gh30908-scope-balance-on-invalid-var-direct-init.cpp
new file mode 100644
index 00..02200ce4f34a75
--- /dev/null
+++ b/clang/test/Parser/gh30908-scope-balance-on-invalid-var-direct-init.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#include  // expected-error {{file not found}}
+
+class S {};
+
+template 
+class E {
+public:
+  E(S* scope) {}
+  S ();
+};
+
+class Z {
+ private:
+  static E e;
+  static S& s();
+};
+
+E Z::e(&__UNKNOWN_ID__);
+
+S& Z::s() { return Z::e.getS(); }

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


[lld] [openmp] [polly] [flang] [clang] [libcxx] [compiler-rt] [llvm] [mlir] [libc] [lldb] [WebAssembly] Correctly consider signext/zext arg flags at function declaration (PR #77281)

2024-01-09 Thread Andy Wingo via cfe-commits


@@ -839,9 +839,11 @@ bool WebAssemblyFastISel::selectCall(const Instruction *I) 
{
 
 unsigned Reg;
 
-if (Attrs.hasParamAttr(I, Attribute::SExt))
+if (Attrs.hasParamAttr(I, Attribute::SExt) ||
+(IsDirect && Func->hasParamAttribute(I, Attribute::SExt)))

wingo wrote:

I have been too long away from LLVM to LGTM, but I would guess that you would 
have a similar situation with indirect function calls as well.  Perhaps you 
could test a function that takes a function pointer parameter with sext / zext 
attributes.  But, again, perhaps this comment is off-base.

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


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

2024-01-09 Thread Budimir Aranđelović via cfe-commits


@@ -0,0 +1,132 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-format-attribute %s
+
+#include 
+#include 
+
+void f1(const std::string , ... /* args */)
+{
+va_list args;
+vscanf(str.c_str(), args); // no warning
+vprintf(str.c_str(), args); // no warning
+}
+
+__attribute__((format(printf, 1, 2))) // expected-error: {{format argument not 
a string type}}
+void f2(const std::string , ... /* args */);
+
+void f3(std::string_view str, ... /* args */)
+{
+va_list args;
+vscanf(std::string(str).c_str(), args); // no warning
+vprintf(std::string(str).c_str(), args); // no warning
+}
+
+__attribute__((format(printf, 1, 2))) // expected-error {{format argument not 
a string type}}
+void f4(std::string_view str, ... /* args */);
+
+void f5(const std::wstring , ... /* args */)
+{
+va_list args;
+vscanf((const char *)str.c_str(), args); // no warning
+vprintf((const char *)str.c_str(), args); // no warning
+}
+
+__attribute__((format(printf, 1, 2))) // expected-error {{format argument not 
a string type}}
+void f6(const std::wstring , ... /* args */);
+
+void f7(std::wstring_view str, ... /* args */)
+{
+va_list args;
+vscanf((const char *) std::wstring(str).c_str(), args); // no warning
+vprintf((const char *) std::wstring(str).c_str(), args); // no warning
+}
+
+__attribute__((format(printf, 1, 2))) // expected-error {{format argument not 
a string type}}
+void f8(std::wstring_view str, ... /* args */);
+
+void f9(const wchar_t *out, ... /* args */)
+{
+va_list args;
+vprintf(out, args); // expected-error {{no matching function for call to 
'vprintf'}}
+vscanf((const char *) out, args); // no warning
+vscanf((char *) out, args); // no warning
+}
+
+__attribute__((format(printf, 1, 2))) // expected-error {{format argument not 
a string type}}
+void f10(const wchar_t *out, ... /* args */);
+
+void f11(const char16_t *out, ... /* args */)
+{
+va_list args;
+vscanf(out, args); // expected-error {{no matching function for call to 
'vscanf'}}
+}
+
+__attribute__((format(printf, 1, 2))) // expected-error {{format argument not 
a string type}}
+void f12(const char16_t *out, ... /* args */);
+
+void f13(const char32_t *out, ... /* args */)
+{
+va_list args;
+vscanf(out, args); // expected-error {{no matching function for call to 
'vscanf'}}
+}
+
+__attribute__((format(scanf, 1, 2))) // expected-error {{format argument not a 
string type}}
+void f14(const char32_t *out, ... /* args */);
+
+void f15(const char *out, ... /* args */)
+{
+va_list args;
+vscanf(out, args); // expected-warning {{diagnostic behavior may be 
improved by adding the 'scanf' format attribute to the declaration of 'f15'}}
+}
+
+__attribute__((format(scanf, 1, 2)))
+void f16(const char *out, ... /* args */)
+{
+va_list args;
+vscanf(out, args); // no warning
+}
+
+void f17(const unsigned char *out, ... /* args */)
+{
+va_list args;
+vscanf(out, args); // expected-error {{no matching function for call to 
'vscanf'}}
+}
+
+__attribute__((format(scanf, 1, 2)))
+void f18(const unsigned char *out, ... /* args */)
+{
+va_list args;
+vscanf(out, args); // expected-error {{no matching function for call to 
'vscanf'}}
+}
+
+void f19(const signed char *out, ... /* args */)
+{
+va_list args;
+vscanf(out, args); // expected-error {{no matching function for call to 
'vscanf'}}
+}
+
+__attribute__((format(scanf, 1, 2)))
+void f20(const signed char *out, ... /* args */)
+{
+va_list args;
+vscanf(out, args); // expected-error {{no matching function for call to 
'vscanf'}}
+}
+
+void f21(const char out[], ... /* args */)
+{
+va_list args;
+vscanf(out, args); // expected-warning {{diagnostic behavior may be 
improved by adding the 'scanf' format attribute to the declaration of 'f21'}}
+}
+
+__attribute__((format(scanf, 1, 2)))
+void f22(const char out[], ... /* args */)
+{
+va_list args;
+vscanf(out, args); // no warning
+}
+
+template 
+void func(char ()[N], ...)
+{
+va_list args;
+vprintf(str, args); // no warning
+}

budimirarandjelovicsyrmia wrote:

Added tests where function is member of a class/structure/union.

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


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

2024-01-09 Thread Budimir Aranđelović via cfe-commits

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

From ca3bfcd4052276b0a776f6acfefcd83bbeab28a1 Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 13 Oct 2023 14:45:15 +0200
Subject: [PATCH] [clang] Catch missing format attributes

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9cc2a72f4c864d..1ca055f65f2115 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -65,7 +65,9 @@ Improvements to Clang's diagnostics
 ^^^
 - We now generate a diagnostic for signed integer overflow due to unary minus
   in a non-constant expression context. This fixes
-  `Issue 31643 `_
+  `Issue 31643 `_.
+- We now generate a diagnostic for missing format attributes
+  `Issue 60718 `_.
 
 Non-comprehensive list of changes in this release
 -
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 17fdcffa2d4274..114cbbc2e82b85 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -482,7 +482,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6d6f474f6dcdab..964166b70c2aee 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -936,6 +936,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 741c2503127af7..064506e7096033 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10615,6 +10615,10 @@ class Sema final {
 ChangedStateAtExit
   };
 
+  void DiagnoseMissingFormatAttributes(const FunctionDecl *FDecl,
+   ArrayRef Args,
+   SourceLocation Loc);
+
   void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind,
  SourceLocation IncludeLoc);
   void DiagnoseUnterminatedPragmaAlignPack();
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4602284309491c..d3ac6cb519c56e 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -6014,8 +6014,10 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
-  if (FD)
+  if (FD) {
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
+DiagnoseMissingFormatAttributes(FD, Args, Range.getBegin());
+  }
 }
 
 /// CheckConstructorCall - Check a constructor call for correctness and safety
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1a0bfb3d91bcc8..305ee1c230ffb3 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6849,6 +6849,109 @@ static void handleSwiftAsyncAttr(Sema , Decl *D, 
const ParsedAttr ) {
 checkSwiftAsyncErrorBlock(S, D, ErrorAttr, AsyncAttr);
 }
 
+// Check if parent function misses format attribute. If misses, emit warning.
+void Sema::DiagnoseMissingFormatAttributes(const FunctionDecl *FDecl,
+ 

[clang] [AST] Teach TextNodeDumper to print the "implicit" bit for coroutine AST nodes (PR #77311)

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

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


[clang] 414ea3a - [AST] Teach TextNodeDumper to print the "implicit" bit for coroutine AST nodes (#77311)

2024-01-09 Thread via cfe-commits

Author: Haojian Wu
Date: 2024-01-09T10:32:06+01:00
New Revision: 414ea3a77181ef01d2cc2ad34950fc1c03ce0d41

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

LOG: [AST] Teach TextNodeDumper to print the "implicit" bit for coroutine AST 
nodes (#77311)

Added: 
clang/test/AST/ast-dump-coroutine.cpp

Modified: 
clang/include/clang/AST/TextNodeDumper.h
clang/lib/AST/TextNodeDumper.cpp

Removed: 




diff  --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 2f4ed082a0c7ad..732749ad305e15 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -252,6 +252,8 @@ class TextNodeDumper
   void VisitGotoStmt(const GotoStmt *Node);
   void VisitCaseStmt(const CaseStmt *Node);
   void VisitReturnStmt(const ReturnStmt *Node);
+  void VisitCoawaitExpr(const CoawaitExpr *Node);
+  void VisitCoreturnStmt(const CoreturnStmt *Node);
   void VisitCompoundStmt(const CompoundStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);

diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index e8274fcd5cfe9c..369ff66ac4dbc6 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1094,6 +1094,16 @@ void clang::TextNodeDumper::VisitReturnStmt(const 
ReturnStmt *Node) {
   }
 }
 
+void clang::TextNodeDumper::VisitCoawaitExpr(const CoawaitExpr *Node) {
+  if (Node->isImplicit())
+OS << " implicit";
+}
+
+void clang::TextNodeDumper::VisitCoreturnStmt(const CoreturnStmt *Node) {
+  if (Node->isImplicit())
+OS << " implicit";
+}
+
 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
   if (Node->hasAPValueResult())
 AddChild("value",

diff  --git a/clang/test/AST/ast-dump-coroutine.cpp 
b/clang/test/AST/ast-dump-coroutine.cpp
new file mode 100644
index 00..5e7736300f9fee
--- /dev/null
+++ b/clang/test/AST/ast-dump-coroutine.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -std=c++20 \
+// RUN:-fsyntax-only -ast-dump -ast-dump-filter test | FileCheck %s
+
+#include "Inputs/std-coroutine.h"
+
+using namespace std;
+
+struct Task {
+  struct promise_type {
+std::suspend_always initial_suspend() { return {}; }
+Task get_return_object() {
+  return std::coroutine_handle::from_promise(*this);
+}
+std::suspend_always final_suspend() noexcept { return {}; }
+std::suspend_always return_void() { return {}; }
+void unhandled_exception() {}
+
+auto await_transform(int s) {
+  struct awaiter {
+promise_type *promise;
+bool await_ready() { return true; }
+int await_resume() { return 1; }
+void await_suspend(std::coroutine_handle<>) {}
+  };
+
+  return awaiter{this};
+}
+  };
+
+  Task(std::coroutine_handle promise);
+
+  std::coroutine_handle handle;
+};
+
+Task test()  {
+  co_await 1;
+// Writen souce code, verify no implicit bit for the co_await expr.
+// CHECK:CompoundStmt {{.*}}
+// CHECK-NEXT:   | `-ExprWithCleanups {{.*}} 'int'
+// CHECK-NEXT:   |   `-CoawaitExpr {{.*}} 'int'{{$}}
+// CHECK-NEXT:   | |-IntegerLiteral {{.*}}  'int' 1
+// CHECK-NEXT:   | |-MaterializeTemporaryExpr {{.*}} 'awaiter'
+// CHECK-NEXT:   | | `-CXXMemberCallExpr {{.*}} 'awaiter'
+// CHECK-NEXT:   | |   |-MemberExpr {{.*}} .await_transform
+}
+// Verify the implicit AST nodes for coroutines.
+// CHECK:|-DeclStmt {{.*}}
+// CHECK-NEXT:   | `-VarDecl {{.*}} implicit used __promise
+// CHECK-NEXT:   |   `-CXXConstructExpr {{.*}}
+// CHECK-NEXT:   |-ExprWithCleanups {{.*}} 'void'
+// CHECK-NEXT:   | `-CoawaitExpr {{.*}} 'void' implicit
+// CHECK-NEXT:   |-CXXMemberCallExpr  {{.*}} 'std::suspend_always'
+// CHECK-NEXT:   |   | `-MemberExpr {{.*}} .initial_suspend
+//   ...
+// FIXME: the CoreturnStmt should be marked as implicit
+// CHECK: CoreturnStmt {{.*}} {{$}}
+
+Task test2()  {
+// Writen souce code, verify no implicit bit for the co_return expr.
+// CHECK:CompoundStmt {{.*}}
+// CHECK-NEXT:   | `-CoreturnStmt {{.*}} {{$}}
+  co_return;
+}
+// Verify the implicit AST nodes for coroutines.
+// CHECK:|-DeclStmt {{.*}}
+// CHECK-NEXT:   | `-VarDecl {{.*}} implicit used __promise
+//   ...
+// FIXME: the CoreturnStmt should be marked as implicit
+// CHECK: CoreturnStmt {{.*}} {{$}}



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


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 6195e6c57b5b461dda2bffec0e5497ceb659f82c Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH 1/2] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  9 +++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..cadd6f6ad75daa 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,10 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {
 // For SEH, ExceptionAsObject may be 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits


@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {

qmfrederik wrote:

Yes, that makes the intent clearer.  I changed this.

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


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits


@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);

qmfrederik wrote:

Good remark, thanks.  Fixed this.

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


[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

2024-01-09 Thread Frederik Carlier via cfe-commits

qmfrederik wrote:

No worries, thanks! :-)

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


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 6195e6c57b5b461dda2bffec0e5497ceb659f82c Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH 1/2] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  9 +++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..cadd6f6ad75daa 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,10 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {
 // For SEH, ExceptionAsObject may be 

[llvm] [flang] [clang] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)

2024-01-09 Thread Bruno De Fraine via cfe-commits


@@ -2282,6 +2282,15 @@ Instruction 
*InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst ) {
   if (MadeChange)
 return 
 
+  // Canonicalize constant GEPs to i8 type.

brunodf-snps wrote:

Reading about the [planned 
steps](https://www.npopov.com/2024/01/01/This-year-in-LLVM-2023.html#ptradd) to 
move from getelementptr to ptradd, I would appreciate the opportunity to 
**not** add more hardcoded instances of i8 (i.e. `isIntegerTy(8)` or 
`getInt8Ty` below) in this effort. You don't need an 8 bit container, you want 
the canonical type that has getTypeStoreSize(Ty) == 1, it would be much better 
if there was a minimal API that is just a slight abstraction over i8 but that 
makes this goal apparent. (I would personally use something with the 
terminology "addressable unit type", so "isAddressableUnitType", 
"getAddressableUnitType" etc.)

For context, we are also a downstream user in architectural contexts with 
memories that are not byte addressable. This can be a main memory that is word 
addressable and does not have byte or sub-word access (so the canonical unit 
type is naturally i16 or i24... although i8 would still work), but also 
additional memories that cannot hold integers at all, for example, a separate 
memory (address space) for vectors (the canonical unit type is a vector and i8 
is not storable in that memory/address space). Whenever there are hardcoded 
instances of i8 in the code base, we typically have to review them in our tree 
(yes, SCEVExpander). But it makes a  difference whether the code is assuming an 
8 bit container, or just needs a type with getTypeStoreSize(Ty) == 1.

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


[llvm] [clang] [AMDGPU][GFX12] Add 16 bit atomic fadd instructions (PR #75917)

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


@@ -1368,6 +1391,28 @@ def int_amdgcn_struct_ptr_buffer_atomic_cmpswap : 
Intrinsic<
 // gfx908 intrinsic
 def int_amdgcn_struct_buffer_atomic_fadd : 
AMDGPUStructBufferAtomic;
 def int_amdgcn_struct_ptr_buffer_atomic_fadd : 
AMDGPUStructPtrBufferAtomic;
+// gfx12 intrinsic
+def int_amdgcn_struct_buffer_atomic_fadd_v2bf16 : Intrinsic <
+  [llvm_v2i16_ty],

arsenm wrote:

Patch to v2bf16 legal is committed, you can now update this to use it

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


[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

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

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


[clang] b81ba52 - Set dllstorage on ObjectiveC ivar offsets (#77385)

2024-01-09 Thread via cfe-commits

Author: Frederik Carlier
Date: 2024-01-09T09:15:01Z
New Revision: b81ba52e15d95c3353489d4ce2f61c3771714c28

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

LOG: Set dllstorage on ObjectiveC ivar offsets (#77385)

Mark instance variable offset symbols with `dllexport`/`dllimport` if
they are not hidden and the interface declaration is marked with
`dllexport`/`dllimport`, when using the GNUstep 2.x ABI.

/cc @davidchisnall

Added: 


Modified: 
clang/lib/CodeGen/CGObjCGNU.cpp
clang/test/CodeGenObjC/dllstorage.m

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..9443fecf9b7946 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1851,6 +1851,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 llvm::GlobalValue::HiddenVisibility :
 llvm::GlobalValue::DefaultVisibility;
 OffsetVar->setVisibility(ivarVisibility);
+if (ivarVisibility != llvm::GlobalValue::HiddenVisibility)
+  CGM.setGVProperties(OffsetVar, OID->getClassInterface());
 ivarBuilder.add(OffsetVar);
 // Ivar size
 ivarBuilder.addInt(Int32Ty,

diff  --git a/clang/test/CodeGenObjC/dllstorage.m 
b/clang/test/CodeGenObjC/dllstorage.m
index 64ba21f9769ae2..0dbf1881caa9c0 100644
--- a/clang/test/CodeGenObjC/dllstorage.m
+++ b/clang/test/CodeGenObjC/dllstorage.m
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fdeclspec 
-fobjc-runtime=ios -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck 
-allow-deprecated-dag-overlap -check-prefix CHECK-IR %s
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fdeclspec 
-fobjc-runtime=gnustep-2.0 -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck 
-allow-deprecated-dag-overlap -check-prefix CHECK-NF %s
 // RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions 
-fobjc-runtime=macosx -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | 
FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-IR %s
 // RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions 
-fobjc-runtime=objfw -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | 
FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-FW %s
 
@@ -12,6 +13,8 @@ + (instancetype) new;
 // CHECK-IR-DAG: @"OBJC_METACLASS_$_I" = external dllimport global 
%struct._class_t
 // CHECK-IR-DAG: @"OBJC_CLASS_$_I" = external dllimport global %struct._class_t
 
+// CHECK-NF-DAG: @"$_OBJC_CLASS_I" = external dllimport global ptr
+
 __declspec(dllexport)
 @interface J : I
 @end
@@ -22,6 +25,9 @@ @interface J : I
 // CHECK-FW-DAG: @_OBJC_METACLASS_J = dso_local dllexport global
 // CHECK-FW-DAG: @_OBJC_CLASS_J = dso_local dllexport global
 
+// CHECK-NF-DAG: @"$_OBJC_METACLASS_J" = internal global
+// CHECK-NF-DAG: @"$_OBJC_CLASS_J" = dllexport global
+
 @implementation J {
   id _ivar;
 }
@@ -29,6 +35,8 @@ @implementation J {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_J._ivar" = global i32
 
+// CHECK-NF-DAG: @"__objc_ivar_offset_J._ivar.\01" = hidden global i32
+
 @interface K : J
 @end
 
@@ -38,6 +46,9 @@ @interface K : J
 // CHECK-FW-DAG: @_OBJC_METACLASS_K = dso_local global
 // CHECK-FW-DAG: @_OBJC_CLASS_K = dso_local global
 
+// CHECK-NF-DAG: @"$_OBJC_METACLASS_K" = internal global
+// CHECK-NF-DAG: @"$_OBJC_CLASS_K" = global
+
 @implementation K {
   id _ivar;
 }
@@ -45,6 +56,8 @@ @implementation K {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_K._ivar" = global i32
 
+// CHECK-NF-DAG: @"__objc_ivar_offset_K._ivar.\01" = hidden global i32
+
 __declspec(dllexport)
 @interface L : K
 @end
@@ -55,6 +68,9 @@ @interface L : K
 // CHECK-FW-DAG: @_OBJC_METACLASS_L = dso_local dllexport global
 // CHECK-FW-DAG: @_OBJC_CLASS_L = dso_local dllexport global
 
+// CHECK-NF-DAG: @"$_OBJC_METACLASS_L" = internal global
+// CHECK-NF-DAG: @"$_OBJC_CLASS_L" = dllexport global
+
 @implementation L {
   id _none;
 
@@ -78,6 +94,12 @@ @implementation L {
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._package" = global i32
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._private" = global i32
 
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._none.\01" = hidden global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._public.\01" = dso_local dllexport 
global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._protected.\01" = dso_local dllexport 
global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._package.\01" = hidden global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._private.\01" = hidden global i32
+
 __declspec(dllimport)
 @interface M : I {
   @public
@@ -89,6 +111,9 @@ @interface M : I {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32
 
+// CHECK-NF-DAG: @"$_OBJC_REF_CLASS_M" = external dllimport global ptr
+// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.\01" 

[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

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

davidchisnall wrote:

I didn’t intentional hit close, not sure what happened there.

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


[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

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

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


[clang-tools-extra] [lldb] [clang] [Clang] [c++20] P1907R1: Support for generalized non-type template ar… (PR #77428)

2024-01-09 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-lldb

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

…guments of scalar type

Initially https://reviews.llvm.org/D140996

Author: @bolshakov-a

I do not plan to work on this, but I'm trying to salvage what I can from 
phabricator. This review, is completely gone. I extracted it from my mails. So 
this PR is purely to make sure we have a trace.

---

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


43 Files Affected:

- (modified) clang-tools-extra/clangd/DumpAST.cpp (+1) 
- (modified) clang-tools-extra/clangd/FindTarget.cpp (+1) 
- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/AST/ODRHash.h (+3) 
- (modified) clang/include/clang/AST/PropertiesBase.td (+14) 
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+2) 
- (modified) clang/include/clang/AST/TemplateArgumentVisitor.h (+2) 
- (modified) clang/include/clang/AST/TemplateBase.h (+53-31) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2-5) 
- (modified) clang/include/clang/Sema/Sema.h (+2-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+5) 
- (modified) clang/lib/AST/ASTImporter.cpp (+13) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+4) 
- (modified) clang/lib/AST/Decl.cpp (+4) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+37-2) 
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+62-16) 
- (modified) clang/lib/AST/ODRHash.cpp (+72) 
- (modified) clang/lib/AST/StmtProfile.cpp (+6) 
- (modified) clang/lib/AST/TemplateBase.cpp (+110-3) 
- (modified) clang/lib/AST/TypeLoc.cpp (+1) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+8) 
- (modified) clang/lib/Index/USRGeneration.cpp (+10) 
- (modified) clang/lib/Sema/SemaLookup.cpp (+1) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+9) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+129-87) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+46-18) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+6-8) 
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+2) 
- (modified) clang/lib/Sema/TreeTransform.h (+10-2) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+1) 
- (modified) clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp (+3-1) 
- (modified) clang/test/CodeGenCXX/mangle-ms-templates.cpp (+48) 
- (modified) clang/test/CodeGenCXX/mangle-template.cpp (+39-1) 
- (modified) clang/test/Modules/odr_hash.cpp (+190-3) 
- (modified) clang/test/SemaCXX/warn-bool-conversion.cpp (+2) 
- (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp (+19-21) 
- (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp (+22-18) 
- (modified) clang/tools/libclang/CIndex.cpp (+5) 
- (modified) clang/tools/libclang/CXCursor.cpp (+3) 
- (modified) clang/www/cxx_status.html (+13-5) 
- (modified) lldb/include/lldb/lldb-enumerations.h (+1) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+3) 


``diff
diff --git a/clang-tools-extra/clangd/DumpAST.cpp 
b/clang-tools-extra/clangd/DumpAST.cpp
index b0cec65c39fa31..9a525efb938e8d 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -143,6 +143,7 @@ class DumpVisitor : public RecursiveASTVisitor 
{
   TEMPLATE_ARGUMENT_KIND(Declaration);
   TEMPLATE_ARGUMENT_KIND(Template);
   TEMPLATE_ARGUMENT_KIND(TemplateExpansion);
+  TEMPLATE_ARGUMENT_KIND(StructuralValue);
 #undef TEMPLATE_ARGUMENT_KIND
 }
 llvm_unreachable("Unhandled ArgKind enum");
diff --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index 839cf6332fe8b0..a4a261030d399b 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -1032,6 +1032,7 @@ class ExplicitReferenceCollector
 case TemplateArgument::Pack:
 case TemplateArgument::Type:
 case TemplateArgument::Expression:
+case TemplateArgument::StructuralValue:
   break; // Handled by VisitType and VisitExpression.
 };
 return RecursiveASTVisitor::TraverseTemplateArgumentLoc(A);
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 980be4fe0ef741..ac30805cf7f7b1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -147,6 +147,8 @@ C++ Language Changes
 
 C++20 Feature Support
 ^
+- Implemented `P1907R1 ` which extends allowed 
non-type template argument
+  kinds with e.g. floating point values and pointers and references to 
subobjects.
 
 C++23 Feature Support
 ^
diff --git a/clang/include/clang/AST/ODRHash.h 
b/clang/include/clang/AST/ODRHash.h
index cedf644520fc32..a1caa6d39a87c3 100644
--- a/clang/include/clang/AST/ODRHash.h
+++ b/clang/include/clang/AST/ODRHash.h
@@ -25,6 +25,7 @@
 
 namespace clang {
 
+class APValue;
 class Decl;
 class IdentifierInfo;
 class 

[clang] [lldb] [clang-tools-extra] [Clang] [c++20] P1907R1: Support for generalized non-type template ar… (PR #77428)

2024-01-09 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/77428

…guments of scalar type

Initially https://reviews.llvm.org/D140996

Author: @bolshakov-a

I do not plan to work on this, but I'm trying to salvage what I can from 
phabricator. This review, is completely gone. I extracted it from my mails. So 
this PR is purely to make sure we have a trace.

>From ac4d4d517b05973a7b04deeeaad6cf1ee1e0 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Tue, 9 Jan 2024 09:57:58 +0100
Subject: [PATCH] [Clang] [c++20] P1907R1: Support for generalized non-type
 template arguments of scalar type

Initially https://reviews.llvm.org/D140996

Author: @bolshakov-a

I do not plan to work on this, but I'm trying to salvage what I can from 
phabricator.
This review, is completely gone. I extracted it from my mails.
So this PR is purely to make sure we have a trace.
---
 clang-tools-extra/clangd/DumpAST.cpp  |   1 +
 clang-tools-extra/clangd/FindTarget.cpp   |   1 +
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/ODRHash.h |   3 +
 clang/include/clang/AST/PropertiesBase.td |  14 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |   2 +
 .../clang/AST/TemplateArgumentVisitor.h   |   2 +
 clang/include/clang/AST/TemplateBase.h|  84 ---
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +-
 clang/include/clang/Sema/Sema.h   |   4 +-
 clang/lib/AST/ASTContext.cpp  |   5 +
 clang/lib/AST/ASTImporter.cpp |  13 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|   4 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/AST/ItaniumMangle.cpp   |  39 +++-
 clang/lib/AST/MicrosoftMangle.cpp |  78 +--
 clang/lib/AST/ODRHash.cpp |  72 ++
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/TemplateBase.cpp| 113 -
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/CodeGen/CGDebugInfo.cpp |   8 +
 clang/lib/Index/USRGeneration.cpp |  10 +
 clang/lib/Sema/SemaLookup.cpp |   1 +
 clang/lib/Sema/SemaOverload.cpp   |   9 +
 clang/lib/Sema/SemaTemplate.cpp   | 216 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  64 --
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  14 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |   2 +
 clang/lib/Sema/TreeTransform.h|  12 +-
 clang/lib/Serialization/ASTReader.cpp |   1 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 .../CXX/temp/temp.arg/temp.arg.nontype/p1.cpp |   4 +-
 clang/test/CodeGenCXX/mangle-ms-templates.cpp |  48 
 clang/test/CodeGenCXX/mangle-template.cpp |  40 +++-
 clang/test/Modules/odr_hash.cpp   | 193 +++-
 clang/test/SemaCXX/warn-bool-conversion.cpp   |   2 +
 .../SemaTemplate/temp_arg_nontype_cxx1z.cpp   |  40 ++--
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  40 ++--
 clang/tools/libclang/CIndex.cpp   |   5 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 clang/www/cxx_status.html |  18 +-
 lldb/include/lldb/lldb-enumerations.h |   1 +
 .../TypeSystem/Clang/TypeSystemClang.cpp  |   3 +
 43 files changed, 967 insertions(+), 223 deletions(-)

diff --git a/clang-tools-extra/clangd/DumpAST.cpp 
b/clang-tools-extra/clangd/DumpAST.cpp
index b0cec65c39fa31..9a525efb938e8d 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -143,6 +143,7 @@ class DumpVisitor : public RecursiveASTVisitor 
{
   TEMPLATE_ARGUMENT_KIND(Declaration);
   TEMPLATE_ARGUMENT_KIND(Template);
   TEMPLATE_ARGUMENT_KIND(TemplateExpansion);
+  TEMPLATE_ARGUMENT_KIND(StructuralValue);
 #undef TEMPLATE_ARGUMENT_KIND
 }
 llvm_unreachable("Unhandled ArgKind enum");
diff --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index 839cf6332fe8b0..a4a261030d399b 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -1032,6 +1032,7 @@ class ExplicitReferenceCollector
 case TemplateArgument::Pack:
 case TemplateArgument::Type:
 case TemplateArgument::Expression:
+case TemplateArgument::StructuralValue:
   break; // Handled by VisitType and VisitExpression.
 };
 return RecursiveASTVisitor::TraverseTemplateArgumentLoc(A);
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 980be4fe0ef741..ac30805cf7f7b1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -147,6 +147,8 @@ C++ Language Changes
 
 C++20 Feature Support
 ^
+- Implemented `P1907R1 ` which extends allowed 
non-type template argument
+  kinds with e.g. floating point values and pointers and references to 
subobjects.
 
 

[clang] [CMake][Release] Add option for enabling LTO to cache file (PR #77035)

2024-01-09 Thread Petr Hosek via cfe-commits

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


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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2024-01-09 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[clang] [clang][analyzer] Add function 'ungetc' to StreamChecker. (PR #77331)

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


@@ -916,6 +922,44 @@ void StreamChecker::evalFputx(const FnDescription *Desc, 
const CallEvent ,
   C.addTransition(StateFailed);
 }
 
+void StreamChecker::evalUngetc(const FnDescription *Desc, const CallEvent 
,
+   CheckerContext ) const {
+  ProgramStateRef State = C.getState();
+  SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
+  if (!StreamSym)
+return;
+
+  const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // Generate a transition for the success state.
+  std::optional PutVal = Call.getArgSVal(0).getAs();
+  if (!PutVal)
+return;
+  ProgramStateRef StateNotFailed =
+  State->BindExpr(CE, C.getLocationContext(), *PutVal);
+  StateNotFailed =
+  StateNotFailed->set(StreamSym, StreamState::getOpened(Desc));
+  C.addTransition(StateNotFailed);
+
+  // Add transition for the failed state.
+  // Failure of 'ungetc' does not result in feof or ferror state.
+  // If the PutVal has value of EofVal the function should "fail", but this is
+  // the same transition as the success state.
+  // FIXME: Is it possible that StateFailed == StateNotFailed ?
+  ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE);
+  StreamState NewSS = StreamState::getOpened(Desc);
+  StateFailed = StateFailed->set(StreamSym, NewSS);

balazske wrote:

`NewSS` is now removed.

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


[clang] [clang][analyzer] Add function 'ungetc' to StreamChecker. (PR #77331)

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


@@ -916,6 +922,44 @@ void StreamChecker::evalFputx(const FnDescription *Desc, 
const CallEvent ,
   C.addTransition(StateFailed);
 }
 
+void StreamChecker::evalUngetc(const FnDescription *Desc, const CallEvent 
,
+   CheckerContext ) const {
+  ProgramStateRef State = C.getState();
+  SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
+  if (!StreamSym)
+return;
+
+  const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // Generate a transition for the success state.
+  std::optional PutVal = Call.getArgSVal(0).getAs();
+  if (!PutVal)
+return;
+  ProgramStateRef StateNotFailed =
+  State->BindExpr(CE, C.getLocationContext(), *PutVal);
+  StateNotFailed =
+  StateNotFailed->set(StreamSym, StreamState::getOpened(Desc));
+  C.addTransition(StateNotFailed);
+
+  // Add transition for the failed state.
+  // Failure of 'ungetc' does not result in feof or ferror state.
+  // If the PutVal has value of EofVal the function should "fail", but this is
+  // the same transition as the success state.
+  // FIXME: Is it possible that StateFailed == StateNotFailed ?

balazske wrote:

I did check it, at least with EOF concrete value only one branch is added, this 
is fixed in the comment.

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


[clang] [clang][analyzer] Add function 'ungetc' to StreamChecker. (PR #77331)

2024-01-09 Thread Mitch Phillips via cfe-commits
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 


https://github.com/hctim updated https://github.com/llvm/llvm-project/pull/77331

>From 9bcc43b5c62ba969f91c495d4d570c5c4337aca2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Mon, 8 Jan 2024 16:42:58 +0100
Subject: [PATCH 1/3] [clang][analyzer] Add 'ungetc' to StreamChecker.

---
 clang/docs/ReleaseNotes.rst   |  4 +-
 .../Checkers/StdLibraryFunctionsChecker.cpp   | 19 
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 44 +++
 .../Analysis/Inputs/system-header-simulator.h |  1 +
 clang/test/Analysis/stream-error.c| 16 +++
 clang/test/Analysis/stream-noopen.c   | 25 +++
 clang/test/Analysis/stream.c  |  6 +++
 7 files changed, 113 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..3bfcd7997faa19 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1162,8 +1162,8 @@ Improvements
   (`c3a87ddad62a 
`_,
   `0954dc3fb921 
`_)
 
-- Improved the ``alpha.unix.Stream`` checker by modeling more functions like,
-  ``fflush``, ``fputs``, ``fgetc``, ``fputc``, ``fopen``, ``fdopen``, 
``fgets``, ``tmpfile``.
+- Improved the ``alpha.unix.Stream`` checker by modeling more functions:
+  ``fputs``, ``fputc``, ``fgets``, ``fgetc``, ``fdopen``, ``ungetc``, 
``fflush``.
   (`#76776 `_,
   `#74296 `_,
   `#73335 `_,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 20068653d530a3..e16bf9feb5b1c4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2201,6 +2201,25 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int ungetc(int c, FILE *stream);
+addToFunctionSummaryMap(
+"ungetc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(BO_EQ, ArgNo(0)),
+   ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
+   ArgumentCondition(0, WithinRange, {{EOFv, EOFv}})},
+  ErrnoNEZeroIrrelevant,
+  "Assuming that 'ungetc' fails because EOF was passed as "
+  "character")
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
+   ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(ArgumentCondition(
+0, WithinRange, {{EOFv, EOFv}, {0, UCharRangeMax}}))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // int fseek(FILE *stream, long offset, int whence);
 // FIXME: It can be possible to get the 'SEEK_' values (like EOFv) and use
 // these for condition of arg 2.
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 25da3c18e8519f..a3d1f34d3d1a9a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -263,6 +263,9 @@ class StreamChecker : public Checker(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // Generate a transition for the success state.
+  std::optional PutVal = Call.getArgSVal(0).getAs();
+  if (!PutVal)
+return;
+  ProgramStateRef StateNotFailed =
+  State->BindExpr(CE, C.getLocationContext(), *PutVal);
+  StateNotFailed =
+  StateNotFailed->set(StreamSym, StreamState::getOpened(Desc));
+  C.addTransition(StateNotFailed);
+
+  // Add transition for the failed state.
+  // Failure of 'ungetc' does not result in feof or ferror state.
+  // If the PutVal has value of EofVal the function should "fail", but this is
+  // the same transition as the success state.
+  // FIXME: Is it possible that StateFailed == StateNotFailed ?
+  ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE);
+  StreamState NewSS = StreamState::getOpened(Desc);
+  StateFailed = StateFailed->set(StreamSym, NewSS);
+  C.addTransition(StateFailed);
+}
+
 void StreamChecker::preFseek(const 

[clang] [clang][analyzer] Add function 'ungetc' to StreamChecker. (PR #77331)

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

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

From 9bcc43b5c62ba969f91c495d4d570c5c4337aca2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Mon, 8 Jan 2024 16:42:58 +0100
Subject: [PATCH 1/3] [clang][analyzer] Add 'ungetc' to StreamChecker.

---
 clang/docs/ReleaseNotes.rst   |  4 +-
 .../Checkers/StdLibraryFunctionsChecker.cpp   | 19 
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 44 +++
 .../Analysis/Inputs/system-header-simulator.h |  1 +
 clang/test/Analysis/stream-error.c| 16 +++
 clang/test/Analysis/stream-noopen.c   | 25 +++
 clang/test/Analysis/stream.c  |  6 +++
 7 files changed, 113 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..3bfcd7997faa19 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1162,8 +1162,8 @@ Improvements
   (`c3a87ddad62a 
`_,
   `0954dc3fb921 
`_)
 
-- Improved the ``alpha.unix.Stream`` checker by modeling more functions like,
-  ``fflush``, ``fputs``, ``fgetc``, ``fputc``, ``fopen``, ``fdopen``, 
``fgets``, ``tmpfile``.
+- Improved the ``alpha.unix.Stream`` checker by modeling more functions:
+  ``fputs``, ``fputc``, ``fgets``, ``fgetc``, ``fdopen``, ``ungetc``, 
``fflush``.
   (`#76776 `_,
   `#74296 `_,
   `#73335 `_,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 20068653d530a3..e16bf9feb5b1c4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2201,6 +2201,25 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int ungetc(int c, FILE *stream);
+addToFunctionSummaryMap(
+"ungetc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(BO_EQ, ArgNo(0)),
+   ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
+   ArgumentCondition(0, WithinRange, {{EOFv, EOFv}})},
+  ErrnoNEZeroIrrelevant,
+  "Assuming that 'ungetc' fails because EOF was passed as "
+  "character")
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
+   ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(ArgumentCondition(
+0, WithinRange, {{EOFv, EOFv}, {0, UCharRangeMax}}))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // int fseek(FILE *stream, long offset, int whence);
 // FIXME: It can be possible to get the 'SEEK_' values (like EOFv) and use
 // these for condition of arg 2.
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 25da3c18e8519f..a3d1f34d3d1a9a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -263,6 +263,9 @@ class StreamChecker : public Checker(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // Generate a transition for the success state.
+  std::optional PutVal = Call.getArgSVal(0).getAs();
+  if (!PutVal)
+return;
+  ProgramStateRef StateNotFailed =
+  State->BindExpr(CE, C.getLocationContext(), *PutVal);
+  StateNotFailed =
+  StateNotFailed->set(StreamSym, StreamState::getOpened(Desc));
+  C.addTransition(StateNotFailed);
+
+  // Add transition for the failed state.
+  // Failure of 'ungetc' does not result in feof or ferror state.
+  // If the PutVal has value of EofVal the function should "fail", but this is
+  // the same transition as the success state.
+  // FIXME: Is it possible that StateFailed == StateNotFailed ?
+  ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE);
+  StreamState NewSS = StreamState::getOpened(Desc);
+  StateFailed = StateFailed->set(StreamSym, NewSS);
+  C.addTransition(StateFailed);
+}
+
 void StreamChecker::preFseek(const FnDescription *Desc, const CallEvent ,
  CheckerContext ) 

[clang] [clang][analyzer] Add function 'ungetc' to StreamChecker. (PR #77331)

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

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

From 9bcc43b5c62ba969f91c495d4d570c5c4337aca2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Mon, 8 Jan 2024 16:42:58 +0100
Subject: [PATCH 1/2] [clang][analyzer] Add 'ungetc' to StreamChecker.

---
 clang/docs/ReleaseNotes.rst   |  4 +-
 .../Checkers/StdLibraryFunctionsChecker.cpp   | 19 
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 44 +++
 .../Analysis/Inputs/system-header-simulator.h |  1 +
 clang/test/Analysis/stream-error.c| 16 +++
 clang/test/Analysis/stream-noopen.c   | 25 +++
 clang/test/Analysis/stream.c  |  6 +++
 7 files changed, 113 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..3bfcd7997faa19 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1162,8 +1162,8 @@ Improvements
   (`c3a87ddad62a 
`_,
   `0954dc3fb921 
`_)
 
-- Improved the ``alpha.unix.Stream`` checker by modeling more functions like,
-  ``fflush``, ``fputs``, ``fgetc``, ``fputc``, ``fopen``, ``fdopen``, 
``fgets``, ``tmpfile``.
+- Improved the ``alpha.unix.Stream`` checker by modeling more functions:
+  ``fputs``, ``fputc``, ``fgets``, ``fgetc``, ``fdopen``, ``ungetc``, 
``fflush``.
   (`#76776 `_,
   `#74296 `_,
   `#73335 `_,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 20068653d530a3..e16bf9feb5b1c4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2201,6 +2201,25 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int ungetc(int c, FILE *stream);
+addToFunctionSummaryMap(
+"ungetc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(BO_EQ, ArgNo(0)),
+   ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
+   ArgumentCondition(0, WithinRange, {{EOFv, EOFv}})},
+  ErrnoNEZeroIrrelevant,
+  "Assuming that 'ungetc' fails because EOF was passed as "
+  "character")
+.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
+   ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(ArgumentCondition(
+0, WithinRange, {{EOFv, EOFv}, {0, UCharRangeMax}}))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // int fseek(FILE *stream, long offset, int whence);
 // FIXME: It can be possible to get the 'SEEK_' values (like EOFv) and use
 // these for condition of arg 2.
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 25da3c18e8519f..a3d1f34d3d1a9a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -263,6 +263,9 @@ class StreamChecker : public Checker(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // Generate a transition for the success state.
+  std::optional PutVal = Call.getArgSVal(0).getAs();
+  if (!PutVal)
+return;
+  ProgramStateRef StateNotFailed =
+  State->BindExpr(CE, C.getLocationContext(), *PutVal);
+  StateNotFailed =
+  StateNotFailed->set(StreamSym, StreamState::getOpened(Desc));
+  C.addTransition(StateNotFailed);
+
+  // Add transition for the failed state.
+  // Failure of 'ungetc' does not result in feof or ferror state.
+  // If the PutVal has value of EofVal the function should "fail", but this is
+  // the same transition as the success state.
+  // FIXME: Is it possible that StateFailed == StateNotFailed ?
+  ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE);
+  StreamState NewSS = StreamState::getOpened(Desc);
+  StateFailed = StateFailed->set(StreamSym, NewSS);
+  C.addTransition(StateFailed);
+}
+
 void StreamChecker::preFseek(const FnDescription *Desc, const CallEvent ,
  CheckerContext ) 

[clang] [llvm] [RISCV] Add experimental support of Zaamo and Zalrsc (PR #77424)

2024-01-09 Thread Yingwei Zheng via cfe-commits


@@ -0,0 +1,11 @@
+# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-zaamo < %s 2>&1 | 
FileCheck %s

dtcxzyw wrote:

Can we split `rv32a-invalid.s` into two files? I think it is better than 
duplicating tests for new extensions.


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


[clang] [RISCV] Overwrite cpu target features for full arch string in target attribute (PR #77426)

2024-01-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Luke Lau (lukel97)


Changes

This patch reworks RISCVTargetInfo::initFeatureMap to fix the issue described
in https://github.com/llvm/llvm-project/pull/74889#pullrequestreview-1773445559
(and is an alternative to #75804)

When a full arch string is specified, a "full" list of extensions is now passed
after the __RISCV_TargetAttrNeedOverride marker feature, which includes any
negative features that disable ISA extensions.

In initFeatureMap, there are now two code paths:

1. If the arch string was overriden, use the "full" list of override features,
only adding back any non-isa features that were specified.

Using the full list of positive and negative features will mean that the
target-cpu will have no effect on the final arch, e.g.
__attribute__((target("arch=rv64i"))) with -mcpu=sifive-x280 will have the
features for rv64i, not a mix of both.

2. Otherwise, parse and *append* the list of implied features. By appending, we
turn back on any features that might have been disabled by a negative
extension, i.e. this handles the case fixed in #74889.


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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/RISCV.cpp (+26-52) 
- (modified) clang/test/CodeGen/RISCV/riscv-func-attr-target.c (+4-4) 


``diff
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index daaa8639ae8358..b56c1d465ad77a 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -235,39 +235,6 @@ ArrayRef 
RISCVTargetInfo::getTargetBuiltins() const {
 clang::RISCV::LastTSBuiltin - Builtin::FirstTSBuiltin);
 }
 
-static std::vector
-collectNonISAExtFeature(ArrayRef FeaturesNeedOverride, int XLen) {
-  std::vector NonISAExtFeatureVec;
-
-  auto IsNonISAExtFeature = [](const std::string ) {
-assert(Feature.size() > 1 && (Feature[0] == '+' || Feature[0] == '-'));
-StringRef Ext = StringRef(Feature).drop_front(); // drop the +/-
-return !llvm::RISCVISAInfo::isSupportedExtensionFeature(Ext);
-  };
-  llvm::copy_if(FeaturesNeedOverride, std::back_inserter(NonISAExtFeatureVec),
-IsNonISAExtFeature);
-
-  return NonISAExtFeatureVec;
-}
-
-static std::vector
-resolveTargetAttrOverride(const std::vector ,
-  int XLen) {
-  auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride");
-  if (I == FeaturesVec.end())
-return FeaturesVec;
-
-  ArrayRef FeaturesNeedOverride(&*FeaturesVec.begin(), &*I);
-  std::vector NonISAExtFeature =
-  collectNonISAExtFeature(FeaturesNeedOverride, XLen);
-
-  std::vector ResolvedFeature(++I, FeaturesVec.end());
-  ResolvedFeature.insert(ResolvedFeature.end(), NonISAExtFeature.begin(),
- NonISAExtFeature.end());
-
-  return ResolvedFeature;
-}
-
 bool RISCVTargetInfo::initFeatureMap(
 llvm::StringMap , DiagnosticsEngine , StringRef CPU,
 const std::vector ) const {
@@ -281,10 +248,27 @@ bool RISCVTargetInfo::initFeatureMap(
 Features["32bit"] = true;
   }
 
-  std::vector NewFeaturesVec =
-  resolveTargetAttrOverride(FeaturesVec, XLen);
+  // If a target attribute specified a full arch string, override all the ISA
+  // extension target features.
+  const auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride");
+  if (I != FeaturesVec.end()) {
+std::vector OverrideFeatures = std::vector(std::next(I), 
FeaturesVec.end());
+
+// Add back any non ISA extension features, e.g. +relax.
+auto IsNonISAExtFeature = [](const std::string ) {
+  assert(Feature.size() > 1 && (Feature[0] == '+' || Feature[0] == '-'));
+  std::string Ext = Feature.substr(1); // drop the +/-
+  return !llvm::RISCVISAInfo::isSupportedExtensionFeature(Ext);
+};
+llvm::copy_if(llvm::make_range(FeaturesVec.begin(), I),
+  std::back_inserter(OverrideFeatures), IsNonISAExtFeature);
 
-  auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, NewFeaturesVec);
+return TargetInfo::initFeatureMap(Features, Diags, CPU, OverrideFeatures);
+  }
+
+  // Otherwise, parse the features and add any implied extensions.
+  std::vector AllFeatures = FeaturesVec;
+  auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, FeaturesVec);
   if (!ParseResult) {
 std::string Buffer;
 llvm::raw_string_ostream OutputErrMsg(Buffer);
@@ -295,21 +279,9 @@ bool RISCVTargetInfo::initFeatureMap(
 return false;
   }
 
-  // RISCVISAInfo makes implications for ISA features
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
-
-  // parseFeatures normalizes the feature set by dropping any explicit
-  // negatives, and non-extension features.  We need to preserve the later
-  // for correctness and want to preserve the former for consistency.
-  for (auto  : NewFeaturesVec) {
- StringRef ExtName = Feature;
- assert(ExtName.size() > 1 && (ExtName[0] == '+' || ExtName[0] 

[clang] [RISCV] Overwrite cpu target features for full arch string in target attribute (PR #77426)

2024-01-09 Thread Luke Lau via cfe-commits

https://github.com/lukel97 created 
https://github.com/llvm/llvm-project/pull/77426

This patch reworks RISCVTargetInfo::initFeatureMap to fix the issue described
in https://github.com/llvm/llvm-project/pull/74889#pullrequestreview-1773445559
(and is an alternative to #75804)

When a full arch string is specified, a "full" list of extensions is now passed
after the __RISCV_TargetAttrNeedOverride marker feature, which includes any
negative features that disable ISA extensions.

In initFeatureMap, there are now two code paths:

1. If the arch string was overriden, use the "full" list of override features,
only adding back any non-isa features that were specified.

Using the full list of positive and negative features will mean that the
target-cpu will have no effect on the final arch, e.g.
__attribute__((target("arch=rv64i"))) with -mcpu=sifive-x280 will have the
features for rv64i, not a mix of both.

2. Otherwise, parse and *append* the list of implied features. By appending, we
turn back on any features that might have been disabled by a negative
extension, i.e. this handles the case fixed in #74889.


>From 0fadce20076015fbb28d449a2b3086f2e4261604 Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Tue, 9 Jan 2024 15:32:15 +0700
Subject: [PATCH] [RISCV] Overwrite cpu target features for full arch string in
 target attribute

This patch reworks RISCVTargetInfo::initFeatureMap to fix the issue described
in https://github.com/llvm/llvm-project/pull/74889#pullrequestreview-1773445559
(and is an alternative to #75804)

When a full arch string is specified, a "full" list of extensions is now passed
after the __RISCV_TargetAttrNeedOverride marker feature, which includes any
negative features that disable ISA extensions.

In initFeatureMap, there are now two code paths:

1. If the arch string was overriden, use the "full" list of override features,
only adding back any non-isa features that were specified.

Using the full list of positive and negative features will mean that the
target-cpu will have no effect on the final arch, e.g.
__attribute__((target("arch=rv64i"))) with -mcpu=sifive-x280 will have the
features for rv64i, not a mix of both.

2. Otherwise, parse and *append* the list of implied features. By appending, we
turn back on any features that might have been disabled by a negative
extension, i.e. this handles the case fixed in #74889.
---
 clang/lib/Basic/Targets/RISCV.cpp | 78 +++
 .../CodeGen/RISCV/riscv-func-attr-target.c|  8 +-
 2 files changed, 30 insertions(+), 56 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index daaa8639ae8358..b56c1d465ad77a 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -235,39 +235,6 @@ ArrayRef 
RISCVTargetInfo::getTargetBuiltins() const {
 clang::RISCV::LastTSBuiltin - Builtin::FirstTSBuiltin);
 }
 
-static std::vector
-collectNonISAExtFeature(ArrayRef FeaturesNeedOverride, int XLen) {
-  std::vector NonISAExtFeatureVec;
-
-  auto IsNonISAExtFeature = [](const std::string ) {
-assert(Feature.size() > 1 && (Feature[0] == '+' || Feature[0] == '-'));
-StringRef Ext = StringRef(Feature).drop_front(); // drop the +/-
-return !llvm::RISCVISAInfo::isSupportedExtensionFeature(Ext);
-  };
-  llvm::copy_if(FeaturesNeedOverride, std::back_inserter(NonISAExtFeatureVec),
-IsNonISAExtFeature);
-
-  return NonISAExtFeatureVec;
-}
-
-static std::vector
-resolveTargetAttrOverride(const std::vector ,
-  int XLen) {
-  auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride");
-  if (I == FeaturesVec.end())
-return FeaturesVec;
-
-  ArrayRef FeaturesNeedOverride(&*FeaturesVec.begin(), &*I);
-  std::vector NonISAExtFeature =
-  collectNonISAExtFeature(FeaturesNeedOverride, XLen);
-
-  std::vector ResolvedFeature(++I, FeaturesVec.end());
-  ResolvedFeature.insert(ResolvedFeature.end(), NonISAExtFeature.begin(),
- NonISAExtFeature.end());
-
-  return ResolvedFeature;
-}
-
 bool RISCVTargetInfo::initFeatureMap(
 llvm::StringMap , DiagnosticsEngine , StringRef CPU,
 const std::vector ) const {
@@ -281,10 +248,27 @@ bool RISCVTargetInfo::initFeatureMap(
 Features["32bit"] = true;
   }
 
-  std::vector NewFeaturesVec =
-  resolveTargetAttrOverride(FeaturesVec, XLen);
+  // If a target attribute specified a full arch string, override all the ISA
+  // extension target features.
+  const auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride");
+  if (I != FeaturesVec.end()) {
+std::vector OverrideFeatures = std::vector(std::next(I), 
FeaturesVec.end());
+
+// Add back any non ISA extension features, e.g. +relax.
+auto IsNonISAExtFeature = [](const std::string ) {
+  assert(Feature.size() > 1 && (Feature[0] == '+' || Feature[0] == '-'));
+  std::string Ext = Feature.substr(1); // drop the +/-
+  return 

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

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

https://github.com/ChuanqiXu9 edited 
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-09 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 edited 
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] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

2024-01-09 Thread Frederik Carlier via cfe-commits

qmfrederik wrote:

Thanks @davidchisnall .  Do you plan to get this merged?

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


[clang] [llvm] [RISCV] Add experimental support of Zaamo and Zalrsc (PR #77424)

2024-01-09 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-mc

Author: Wang Pengcheng (wangpc-pp)


Changes

`A` extension has been split into two parts: Zaamo (Atomic Memory
Operations) and Zalrsc (Load-Reserved/Store-Conditional). See also
https://github.com/riscv/riscv-zaamo-zalrsc.

This patch adds the basic compiler support.

Tests for `A` extension are reused.


---

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


26 Files Affected:

- (modified) clang/lib/Basic/Targets/RISCV.cpp (+1-1) 
- (modified) clang/test/Preprocessor/riscv-target-features.c (+19) 
- (modified) llvm/docs/RISCVUsage.rst (+2) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+2) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+25-1) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+4-3) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoA.td (+20-12) 
- (modified) llvm/test/CodeGen/RISCV/atomic-cmpxchg-branch-on-result.ll (+4) 
- (modified) llvm/test/CodeGen/RISCV/atomic-cmpxchg-flag.ll (+2) 
- (modified) llvm/test/CodeGen/RISCV/atomic-cmpxchg.ll (+8) 
- (modified) llvm/test/CodeGen/RISCV/atomic-rmw-discard.ll (+4) 
- (modified) llvm/test/CodeGen/RISCV/atomic-rmw-sub.ll (+4) 
- (modified) llvm/test/CodeGen/RISCV/atomic-rmw.ll (+8) 
- (modified) llvm/test/CodeGen/RISCV/atomic-signext.ll (+4) 
- (modified) llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll (+4) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+8) 
- (modified) llvm/test/MC/RISCV/rv32i-invalid.s (+1-1) 
- (added) llvm/test/MC/RISCV/rv32zaamo-invalid.s (+11) 
- (added) llvm/test/MC/RISCV/rv32zaamo-valid.s (+122) 
- (added) llvm/test/MC/RISCV/rv32zalrsc-invalid.s (+7) 
- (added) llvm/test/MC/RISCV/rv32zalrsc-valid.s (+36) 
- (added) llvm/test/MC/RISCV/rv64zaamo-invalid.s (+11) 
- (added) llvm/test/MC/RISCV/rv64zaamo-valid.s (+157) 
- (added) llvm/test/MC/RISCV/rv64zalrsc-invalid.s (+7) 
- (added) llvm/test/MC/RISCV/rv64zalrsc-valid.s (+42) 
- (modified) llvm/unittests/Support/RISCVISAInfoTest.cpp (+2) 


``diff
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index daaa8639ae8358..7aff435b715ca1 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -176,7 +176,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__riscv_muldiv");
   }
 
-  if (ISAInfo->hasExtension("a")) {
+  if (ISAInfo->hasExtension("a") || ISAInfo->hasExtension("zaamo")) {
 Builder.defineMacro("__riscv_atomic");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 02d8d34116f804..69ba912880f800 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -114,7 +114,9 @@
 
 // CHECK-NOT: __riscv_smaia {{.*$}}
 // CHECK-NOT: __riscv_ssaia {{.*$}}
+// CHECK-NOT: __riscv_zaamo {{.*$}}
 // CHECK-NOT: __riscv_zacas {{.*$}}
+// CHECK-NOT: __riscv_zalrsc {{.*$}}
 // CHECK-NOT: __riscv_zfa {{.*$}}
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
@@ -1025,6 +1027,15 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-SSAIA-EXT %s
 // CHECK-SSAIA-EXT: __riscv_ssaia  100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zaamo0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zaamo0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
+// CHECK-ZAAMO-EXT: __riscv_atomic 1
+// CHECK-ZAAMO-EXT: __riscv_zaamo 1000{{$}}
+
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN: -march=rv32i_zacas1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
@@ -1033,6 +1044,14 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
 // CHECK-ZACAS-EXT: __riscv_zacas 100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zalrsc0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zalrsc0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
+// CHECK-ZALRSC-EXT: __riscv_zalrsc 1000{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN: -march=rv32izfa -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 99c7146825f5ee..1eb1823faebac1 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -96,6 +96,8 @@ on support follow.
  ``Svnapot``  Assembly Support
  ``Svpbmt`` 

[llvm] [clang] [RISCV] Add experimental support of Zaamo and Zalrsc (PR #77424)

2024-01-09 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp created 
https://github.com/llvm/llvm-project/pull/77424

`A` extension has been split into two parts: Zaamo (Atomic Memory
Operations) and Zalrsc (Load-Reserved/Store-Conditional). See also
https://github.com/riscv/riscv-zaamo-zalrsc.

This patch adds the basic compiler support.

Tests for `A` extension are reused.


>From a16ff19b7666060db74bebd4cb7e7132776285a7 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Tue, 9 Jan 2024 16:12:40 +0800
Subject: [PATCH] [RISCV] Add experimental support of Zaamo and Zalrsc

`A` extension has been split into two parts: Zaamo (Atomic Memory
Operations) and Zalrsc (Load-Reserved/Store-Conditional). See also
https://github.com/riscv/riscv-zaamo-zalrsc.

This patch adds the basic compiler support.

Tests for `A` extension are reused.
---
 clang/lib/Basic/Targets/RISCV.cpp |   2 +-
 .../test/Preprocessor/riscv-target-features.c |  19 +++
 llvm/docs/RISCVUsage.rst  |   2 +
 llvm/lib/Support/RISCVISAInfo.cpp |   2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|  26 ++-
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp   |   7 +-
 llvm/lib/Target/RISCV/RISCVInstrInfoA.td  |  32 ++--
 .../RISCV/atomic-cmpxchg-branch-on-result.ll  |   4 +
 .../test/CodeGen/RISCV/atomic-cmpxchg-flag.ll |   2 +
 llvm/test/CodeGen/RISCV/atomic-cmpxchg.ll |   8 +
 llvm/test/CodeGen/RISCV/atomic-rmw-discard.ll |   4 +
 llvm/test/CodeGen/RISCV/atomic-rmw-sub.ll |   4 +
 llvm/test/CodeGen/RISCV/atomic-rmw.ll |   8 +
 llvm/test/CodeGen/RISCV/atomic-signext.ll |   4 +
 .../CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll |   4 +
 llvm/test/CodeGen/RISCV/attributes.ll |   8 +
 llvm/test/MC/RISCV/rv32i-invalid.s|   2 +-
 llvm/test/MC/RISCV/rv32zaamo-invalid.s|  11 ++
 llvm/test/MC/RISCV/rv32zaamo-valid.s  | 122 ++
 llvm/test/MC/RISCV/rv32zalrsc-invalid.s   |   7 +
 llvm/test/MC/RISCV/rv32zalrsc-valid.s |  36 
 llvm/test/MC/RISCV/rv64zaamo-invalid.s|  11 ++
 llvm/test/MC/RISCV/rv64zaamo-valid.s  | 157 ++
 llvm/test/MC/RISCV/rv64zalrsc-invalid.s   |   7 +
 llvm/test/MC/RISCV/rv64zalrsc-valid.s |  42 +
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |   2 +
 26 files changed, 515 insertions(+), 18 deletions(-)
 create mode 100644 llvm/test/MC/RISCV/rv32zaamo-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv32zaamo-valid.s
 create mode 100644 llvm/test/MC/RISCV/rv32zalrsc-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv32zalrsc-valid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zaamo-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zaamo-valid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zalrsc-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zalrsc-valid.s

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index daaa8639ae8358..7aff435b715ca1 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -176,7 +176,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
,
 Builder.defineMacro("__riscv_muldiv");
   }
 
-  if (ISAInfo->hasExtension("a")) {
+  if (ISAInfo->hasExtension("a") || ISAInfo->hasExtension("zaamo")) {
 Builder.defineMacro("__riscv_atomic");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 02d8d34116f804..69ba912880f800 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -114,7 +114,9 @@
 
 // CHECK-NOT: __riscv_smaia {{.*$}}
 // CHECK-NOT: __riscv_ssaia {{.*$}}
+// CHECK-NOT: __riscv_zaamo {{.*$}}
 // CHECK-NOT: __riscv_zacas {{.*$}}
+// CHECK-NOT: __riscv_zalrsc {{.*$}}
 // CHECK-NOT: __riscv_zfa {{.*$}}
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
@@ -1025,6 +1027,15 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-SSAIA-EXT %s
 // CHECK-SSAIA-EXT: __riscv_ssaia  100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zaamo0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zaamo0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
+// CHECK-ZAAMO-EXT: __riscv_atomic 1
+// CHECK-ZAAMO-EXT: __riscv_zaamo 1000{{$}}
+
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN: -march=rv32i_zacas1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
@@ -1033,6 +1044,14 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
 // CHECK-ZACAS-EXT: __riscv_zacas 100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zalrsc0p1 -x c 

[clang] [Driver][LTO] Copy fix empty stats filename to AMDGPU, HIPAMD, MinGW (PR #74178)

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

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

Last comments requested changes 

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


[llvm] [clang] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

2024-01-09 Thread Luke Lau via cfe-commits

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


[clang] db78c30 - [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (#76942)

2024-01-09 Thread via cfe-commits

Author: Luke Lau
Date: 2024-01-09T15:33:51+07:00
New Revision: db78c30ba772af1466bb0d0c1d376c8e642ee4a9

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

LOG: [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (#76942)

toFeatures and toFeatureVector both output a list of target feature
flags, just with a slightly different interface. toFeatures keeps any
unsupported extensions, and also provides a way to append negative
extensions (AddAllExtensions=true).

This patch combines them into one function, so that a later patch will
be be able to get a std::vector of features that includes all the
negative extensions, which was previously only possible through the
StrAlloc interface.

Added: 


Modified: 
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
llvm/include/llvm/Support/RISCVISAInfo.h
llvm/lib/Object/ELFObjectFile.cpp
llvm/lib/Support/RISCVISAInfo.cpp
llvm/unittests/Support/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 59ae12eed94014..daaa8639ae8358 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -296,7 +296,7 @@ bool RISCVTargetInfo::initFeatureMap(
   }
 
   // RISCVISAInfo makes implications for ISA features
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   // parseFeatures normalizes the feature set by dropping any explicit
   // negatives, and non-extension features.  We need to preserve the later
@@ -413,7 +413,7 @@ static void handleFullArchString(StringRef FullArchStr,
 // Forward the invalid FullArchStr.
 Features.push_back("+" + FullArchStr.str());
   } else {
-std::vector FeatStrings = (*RII)->toFeatureVector();
+std::vector FeatStrings = (*RII)->toFeatures();
 Features.insert(Features.end(), FeatStrings.begin(), FeatStrings.end());
   }
 }

diff  --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 0717e3b813e1e2..16a8b3cc42bab4 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -42,9 +42,9 @@ static bool getArchFeatures(const Driver , StringRef Arch,
 return false;
   }
 
-  (*ISAInfo)->toFeatures(
-  Features, [](const Twine ) { return Args.MakeArgString(Str); },
-  /*AddAllExtensions=*/true);
+  for (const std::string  : 
(*ISAInfo)->toFeatures(/*AddAllExtension=*/true,
+   
/*IgnoreUnknown=*/false))
+Features.push_back(Args.MakeArgString(Str));
 
   if (EnableExperimentalExtensions)
 Features.push_back(Args.MakeArgString("+experimental"));

diff  --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 09c4edd6df60e9..c539448683d368 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -68,9 +68,8 @@ class RISCVISAInfo {
   parseFeatures(unsigned XLen, const std::vector );
 
   /// Convert RISC-V ISA info to a feature vector.
-  void toFeatures(std::vector ,
-  llvm::function_ref StrAlloc,
-  bool AddAllExtensions) const;
+  std::vector toFeatures(bool AddAllExtensions = false,
+  bool IgnoreUnknown = true) const;
 
   const OrderedExtensionMap () const { return Exts; };
 
@@ -83,7 +82,6 @@ class RISCVISAInfo {
 
   bool hasExtension(StringRef Ext) const;
   std::string toString() const;
-  std::vector toFeatureVector() const;
   StringRef computeDefaultABI() const;
 
   static bool isSupportedExtensionFeature(StringRef Ext);

diff  --git a/llvm/lib/Object/ELFObjectFile.cpp 
b/llvm/lib/Object/ELFObjectFile.cpp
index 95c4f9f8545db2..ae21b81c10c82a 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -315,7 +315,7 @@ Expected 
ELFObjectFileBase::getRISCVFeatures() const {
 else
   llvm_unreachable("XLEN should be 32 or 64.");
 
-Features.addFeaturesVector(ISAInfo->toFeatureVector());
+Features.addFeaturesVector(ISAInfo->toFeatures());
   }
 
   return Features;

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index a9b7e209915a13..70f531e40b90e6 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -466,35 +466,38 @@ bool RISCVISAInfo::compareExtension(const std::string 
,
   return LHS < RHS;
 }
 
-void RISCVISAInfo::toFeatures(
-std::vector ,
-llvm::function_ref StrAlloc,
-bool AddAllExtensions) const {
-  for (auto const  : Exts) {
-StringRef ExtName = Ext.first;
-
+std::vector 

[clang] [AST] Teach TextNodeDumper to print the "implicit" bit for coroutine AST nodes (PR #77311)

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

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

>From b0efa2e20f1ca7bc9e18b81231574895fe2281c3 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Mon, 8 Jan 2024 14:43:40 +0100
Subject: [PATCH 1/3] [AST] TextNodeDumper print the "implicit" bit for
 coroutine AST nodes

---
 clang/include/clang/AST/TextNodeDumper.h |  2 ++
 clang/lib/AST/TextNodeDumper.cpp | 10 ++
 clang/test/AST/ast-dump-coroutine.cpp| 46 
 3 files changed, 58 insertions(+)
 create mode 100644 clang/test/AST/ast-dump-coroutine.cpp

diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 2f4ed082a0c7ad..dd9ed56fc584a7 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -252,6 +252,8 @@ class TextNodeDumper
   void VisitGotoStmt(const GotoStmt *Node);
   void VisitCaseStmt(const CaseStmt *Node);
   void VisitReturnStmt(const ReturnStmt *Node);
+  void VisitCoawaitExpr(const CoawaitExpr* Node);
+  void VisitCoreturnStmt(const CoreturnStmt *Node);
   void VisitCompoundStmt(const CompoundStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index e8274fcd5cfe9c..d53688ea862e34 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1094,6 +1094,16 @@ void clang::TextNodeDumper::VisitReturnStmt(const 
ReturnStmt *Node) {
   }
 }
 
+void clang::TextNodeDumper::VisitCoawaitExpr(const CoawaitExpr* Node) {
+  if (Node->isImplicit())
+OS << " implicit";
+}
+
+void clang::TextNodeDumper::VisitCoreturnStmt(const CoreturnStmt *Node) {
+  if (Node->isImplicit())
+OS << " implicit";
+}
+
 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
   if (Node->hasAPValueResult())
 AddChild("value",
diff --git a/clang/test/AST/ast-dump-coroutine.cpp 
b/clang/test/AST/ast-dump-coroutine.cpp
new file mode 100644
index 00..f760809f53689a
--- /dev/null
+++ b/clang/test/AST/ast-dump-coroutine.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -std=c++20 \
+// RUN:-fsyntax-only -ast-dump -ast-dump-filter test | FileCheck %s
+
+#include "Inputs/std-coroutine.h"
+
+using namespace std;
+
+struct Task {
+  struct promise_type {
+std::suspend_always initial_suspend() { return {}; }
+Task get_return_object() {
+  return std::coroutine_handle::from_promise(*this);
+}
+std::suspend_always final_suspend() noexcept { return {}; }
+std::suspend_always return_void() { return {}; }
+void unhandled_exception() {}
+
+auto await_transform(int s) {
+  struct awaiter {
+promise_type *promise;
+bool await_ready() { return true; }
+int await_resume() { return 1; }
+void await_suspend(std::coroutine_handle<>) {}
+  };
+
+  return awaiter{this};
+}
+  };
+
+  Task(std::coroutine_handle promise);
+
+  std::coroutine_handle handle;
+};
+
+// Verify the implicit AST nodes for coroutines.
+Task test()  {
+  co_await 1;
+}
+// CHECK:|-DeclStmt {{.*}}
+// CHECK-NEXT:   | `-VarDecl {{.*}} implicit used __promise
+// CHECK-NEXT:   |   `-CXXConstructExpr {{.*}}
+// CHECK-NEXT:   |-ExprWithCleanups {{.*}} 'void'
+// CHECK-NEXT:   | `-CoawaitExpr {{.*}} 'void' implicit
+// ...
+// FIXME: the CoreturnStmt should be marked as implicit
+// CHECK: CoreturnStmt {{.*}} 

>From fb51d8c08de466c87af530edee1b9d2673e030aa Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Tue, 9 Jan 2024 09:23:30 +0100
Subject: [PATCH 2/3] Add more tests per review comment.

---
 clang/test/AST/ast-dump-coroutine.cpp | 29 ---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/clang/test/AST/ast-dump-coroutine.cpp 
b/clang/test/AST/ast-dump-coroutine.cpp
index f760809f53689a..5e7736300f9fee 100644
--- a/clang/test/AST/ast-dump-coroutine.cpp
+++ b/clang/test/AST/ast-dump-coroutine.cpp
@@ -32,15 +32,38 @@ struct Task {
   std::coroutine_handle handle;
 };
 
-// Verify the implicit AST nodes for coroutines.
 Task test()  {
   co_await 1;
+// Writen souce code, verify no implicit bit for the co_await expr.
+// CHECK:CompoundStmt {{.*}}
+// CHECK-NEXT:   | `-ExprWithCleanups {{.*}} 'int'
+// CHECK-NEXT:   |   `-CoawaitExpr {{.*}} 'int'{{$}}
+// CHECK-NEXT:   | |-IntegerLiteral {{.*}}  'int' 1
+// CHECK-NEXT:   | |-MaterializeTemporaryExpr {{.*}} 'awaiter'
+// CHECK-NEXT:   | | `-CXXMemberCallExpr {{.*}} 'awaiter'
+// CHECK-NEXT:   | |   |-MemberExpr {{.*}} .await_transform
 }
+// Verify the implicit AST nodes for coroutines.
 // CHECK:|-DeclStmt {{.*}}
 // CHECK-NEXT:   | `-VarDecl {{.*}} implicit used __promise
 // CHECK-NEXT:   |   `-CXXConstructExpr {{.*}}
 // CHECK-NEXT:   |-ExprWithCleanups {{.*}} 'void'
 // CHECK-NEXT:   | `-CoawaitExpr {{.*}} 'void' 

[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

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

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


[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

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

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


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


[clang] [clang]use correct this scope to evaluate noexcept expr (PR #77416)

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

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/77416

>From 0637a482c881f5ce31fd1debbc8dcc40a05c66ba Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 9 Jan 2024 14:53:25 +0800
Subject: [PATCH 1/3] [clang]use correct this scope to evaluate noexcept expr
 when deduce template

Fixes: #77411
When substituting deduced type, noexcept expr in function decl should be 
instantiated and evaluated.
ThisScrope should be switched to method context
---
 clang/docs/ReleaseNotes.rst   |  3 ++-
 clang/lib/Sema/TreeTransform.h|  6 ++
 .../test/SemaCXX/cxx1z-noexcept-function-type.cpp | 15 +++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 803eb2f7c74cf6..2695a0e30f58e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -610,7 +610,8 @@ Bug Fixes in This Version
   of template classes. Fixes
   (`#68543 `_,
   `#42496 `_,
-  `#77071 `_)
+  `#77071 `_,
+  `#77411 `_)
 - Fixed an issue when a shift count larger than ``__INT64_MAX__``, in a right
   shift operation, could result in missing warnings about
   ``shift count >= width of type`` or internal compiler error.
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c8c5a51bf9f94e..fb7e15b5bcbb02 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6192,6 +6192,12 @@ bool TreeTransform::TransformExceptionSpec(
 
   // Instantiate a dynamic noexcept expression, if any.
   if (isComputedNoexcept(ESI.Type)) {
+// Update this scrope because ContextDecl in Sema will be used in 
TransformExpr.
+auto *Method = dyn_cast_or_null(ESI.SourceTemplate);
+Sema::CXXThisScopeRAII ThisScope(
+SemaRef, Method ? Method->getParent() : nullptr,
+Method ? Method->getMethodQualifiers() : Qualifiers{},
+Method != nullptr);
 EnterExpressionEvaluationContext Unevaluated(
 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
diff --git a/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp 
b/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
index 11b1093f9064f6..5e56f19477d6ca 100644
--- a/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
+++ b/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
@@ -64,6 +64,21 @@ namespace DependentDefaultCtorExceptionSpec {
   struct A { multimap Map; } a;
 
   static_assert(noexcept(A()));
+
+  template  struct NoexceptWithThis {
+int ca;
+template  auto foo(T) noexcept(ca) { return true; }
+// expected-error@-1 {{noexcept specifier argument is not a constant 
expression}}
+// expected-note@-2 {{in instantiation of exception specification}}
+// expected-note@-3 {{implicit use of 'this' pointer is only allowed 
within the evaluation of a call to a 'constexpr' member function}}
+  };
+  struct InstantiateFromAnotherClass {
+template (::foo))> // expected-note {{in instantiation of function 
template specialization}}
+InstantiateFromAnotherClass(B *) {} // expected-note {{in instantiation of 
default argument}}
+  };
+  NoexceptWithThis f{};
+  // Don't crash here.
+  InstantiateFromAnotherClass b{}; // expected-note {{while substituting 
deduced template arguments into function template}}
 }
 
 #endif

>From 80b07ef334b9fdb0699d156e58eb13c8835d835a Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 9 Jan 2024 15:54:54 +0800
Subject: [PATCH 2/3] fix format

---
 clang/lib/Sema/TreeTransform.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index fb7e15b5bcbb02..9dc0c55518ae21 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6192,7 +6192,8 @@ bool TreeTransform::TransformExceptionSpec(
 
   // Instantiate a dynamic noexcept expression, if any.
   if (isComputedNoexcept(ESI.Type)) {
-// Update this scrope because ContextDecl in Sema will be used in 
TransformExpr.
+// Update this scrope because ContextDecl in Sema will be used in
+// TransformExpr.
 auto *Method = dyn_cast_or_null(ESI.SourceTemplate);
 Sema::CXXThisScopeRAII ThisScope(
 SemaRef, Method ? Method->getParent() : nullptr,

>From edaee6a67f296dae7dd6ab5defbeab32a1d34724 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 9 Jan 2024 16:27:24 +0800
Subject: [PATCH 3/3] avoid use deprecated API

---
 clang/lib/Sema/TreeTransform.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 

[clang] [AST] Teach TextNodeDumper to print the "implicit" bit for coroutine AST nodes (PR #77311)

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


@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -std=c++20 \
+// RUN:-fsyntax-only -ast-dump -ast-dump-filter test | FileCheck %s
+
+#include "Inputs/std-coroutine.h"
+
+using namespace std;
+
+struct Task {
+  struct promise_type {
+std::suspend_always initial_suspend() { return {}; }
+Task get_return_object() {
+  return std::coroutine_handle::from_promise(*this);
+}
+std::suspend_always final_suspend() noexcept { return {}; }
+std::suspend_always return_void() { return {}; }
+void unhandled_exception() {}
+
+auto await_transform(int s) {
+  struct awaiter {
+promise_type *promise;
+bool await_ready() { return true; }
+int await_resume() { return 1; }
+void await_suspend(std::coroutine_handle<>) {}
+  };
+
+  return awaiter{this};
+}
+  };
+
+  Task(std::coroutine_handle promise);
+
+  std::coroutine_handle handle;
+};
+
+// Verify the implicit AST nodes for coroutines.
+Task test()  {
+  co_await 1;
+}
+// CHECK:|-DeclStmt {{.*}}
+// CHECK-NEXT:   | `-VarDecl {{.*}} implicit used __promise
+// CHECK-NEXT:   |   `-CXXConstructExpr {{.*}}
+// CHECK-NEXT:   |-ExprWithCleanups {{.*}} 'void'
+// CHECK-NEXT:   | `-CoawaitExpr {{.*}} 'void' implicit

hokein wrote:

> Is this node implicit for initial suspend, for a call to await_transform or 
> both? 

This implicit node is just for initial suspend, it is the `InitSuspend` substmt 
of the `CoroutineBodyStmt`.

Added some more tests and matches for the written `co_await` and `co_return` 
statements.

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


[clang] [AST] Teach TextNodeDumper to print the "implicit" bit for coroutine AST nodes (PR #77311)

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

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

>From b0efa2e20f1ca7bc9e18b81231574895fe2281c3 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Mon, 8 Jan 2024 14:43:40 +0100
Subject: [PATCH 1/2] [AST] TextNodeDumper print the "implicit" bit for
 coroutine AST nodes

---
 clang/include/clang/AST/TextNodeDumper.h |  2 ++
 clang/lib/AST/TextNodeDumper.cpp | 10 ++
 clang/test/AST/ast-dump-coroutine.cpp| 46 
 3 files changed, 58 insertions(+)
 create mode 100644 clang/test/AST/ast-dump-coroutine.cpp

diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 2f4ed082a0c7ad..dd9ed56fc584a7 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -252,6 +252,8 @@ class TextNodeDumper
   void VisitGotoStmt(const GotoStmt *Node);
   void VisitCaseStmt(const CaseStmt *Node);
   void VisitReturnStmt(const ReturnStmt *Node);
+  void VisitCoawaitExpr(const CoawaitExpr* Node);
+  void VisitCoreturnStmt(const CoreturnStmt *Node);
   void VisitCompoundStmt(const CompoundStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index e8274fcd5cfe9c..d53688ea862e34 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1094,6 +1094,16 @@ void clang::TextNodeDumper::VisitReturnStmt(const 
ReturnStmt *Node) {
   }
 }
 
+void clang::TextNodeDumper::VisitCoawaitExpr(const CoawaitExpr* Node) {
+  if (Node->isImplicit())
+OS << " implicit";
+}
+
+void clang::TextNodeDumper::VisitCoreturnStmt(const CoreturnStmt *Node) {
+  if (Node->isImplicit())
+OS << " implicit";
+}
+
 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
   if (Node->hasAPValueResult())
 AddChild("value",
diff --git a/clang/test/AST/ast-dump-coroutine.cpp 
b/clang/test/AST/ast-dump-coroutine.cpp
new file mode 100644
index 00..f760809f53689a
--- /dev/null
+++ b/clang/test/AST/ast-dump-coroutine.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -std=c++20 \
+// RUN:-fsyntax-only -ast-dump -ast-dump-filter test | FileCheck %s
+
+#include "Inputs/std-coroutine.h"
+
+using namespace std;
+
+struct Task {
+  struct promise_type {
+std::suspend_always initial_suspend() { return {}; }
+Task get_return_object() {
+  return std::coroutine_handle::from_promise(*this);
+}
+std::suspend_always final_suspend() noexcept { return {}; }
+std::suspend_always return_void() { return {}; }
+void unhandled_exception() {}
+
+auto await_transform(int s) {
+  struct awaiter {
+promise_type *promise;
+bool await_ready() { return true; }
+int await_resume() { return 1; }
+void await_suspend(std::coroutine_handle<>) {}
+  };
+
+  return awaiter{this};
+}
+  };
+
+  Task(std::coroutine_handle promise);
+
+  std::coroutine_handle handle;
+};
+
+// Verify the implicit AST nodes for coroutines.
+Task test()  {
+  co_await 1;
+}
+// CHECK:|-DeclStmt {{.*}}
+// CHECK-NEXT:   | `-VarDecl {{.*}} implicit used __promise
+// CHECK-NEXT:   |   `-CXXConstructExpr {{.*}}
+// CHECK-NEXT:   |-ExprWithCleanups {{.*}} 'void'
+// CHECK-NEXT:   | `-CoawaitExpr {{.*}} 'void' implicit
+// ...
+// FIXME: the CoreturnStmt should be marked as implicit
+// CHECK: CoreturnStmt {{.*}} 

>From fb51d8c08de466c87af530edee1b9d2673e030aa Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Tue, 9 Jan 2024 09:23:30 +0100
Subject: [PATCH 2/2] Add more tests per review comment.

---
 clang/test/AST/ast-dump-coroutine.cpp | 29 ---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/clang/test/AST/ast-dump-coroutine.cpp 
b/clang/test/AST/ast-dump-coroutine.cpp
index f760809f53689a..5e7736300f9fee 100644
--- a/clang/test/AST/ast-dump-coroutine.cpp
+++ b/clang/test/AST/ast-dump-coroutine.cpp
@@ -32,15 +32,38 @@ struct Task {
   std::coroutine_handle handle;
 };
 
-// Verify the implicit AST nodes for coroutines.
 Task test()  {
   co_await 1;
+// Writen souce code, verify no implicit bit for the co_await expr.
+// CHECK:CompoundStmt {{.*}}
+// CHECK-NEXT:   | `-ExprWithCleanups {{.*}} 'int'
+// CHECK-NEXT:   |   `-CoawaitExpr {{.*}} 'int'{{$}}
+// CHECK-NEXT:   | |-IntegerLiteral {{.*}}  'int' 1
+// CHECK-NEXT:   | |-MaterializeTemporaryExpr {{.*}} 'awaiter'
+// CHECK-NEXT:   | | `-CXXMemberCallExpr {{.*}} 'awaiter'
+// CHECK-NEXT:   | |   |-MemberExpr {{.*}} .await_transform
 }
+// Verify the implicit AST nodes for coroutines.
 // CHECK:|-DeclStmt {{.*}}
 // CHECK-NEXT:   | `-VarDecl {{.*}} implicit used __promise
 // CHECK-NEXT:   |   `-CXXConstructExpr {{.*}}
 // CHECK-NEXT:   |-ExprWithCleanups {{.*}} 'void'
 // CHECK-NEXT:   | `-CoawaitExpr {{.*}} 'void' 

[clang] c6bb89f - [clang] Fix assertion failure when initializing union with FAM (#77298)

2024-01-09 Thread via cfe-commits

Author: Nikita Popov
Date: 2024-01-09T09:18:07+01:00
New Revision: c6bb89f308c6715edf3f35fb7c6257713ecfc614

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

LOG: [clang] Fix assertion failure when initializing union with FAM (#77298)

When initializing a union that constrain a struct with a flexible array
member, and the initializer list is empty, we currently trigger an
assertion failure. This happens because getFlexibleArrayInitChars()
assumes that the initializer list is non-empty.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/Decl.cpp
clang/test/CodeGen/flexible-array-init.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 803eb2f7c74cf6..980be4fe0ef741 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -696,6 +696,9 @@ Bug Fixes in This Version
 - Clang now accepts recursive non-dependent calls to functions with deduced
   return type.
   Fixes (`#71015 `_)
+- Fix assertion failure when initializing union containing struct with
+  flexible array member using empty initializer list.
+  Fixes (`#77085 `_)
 
 
 Bug Fixes to Compiler Builtins

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 12e0a6faa4c33d..e1440e5183a4e6 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2835,7 +2835,7 @@ CharUnits VarDecl::getFlexibleArrayInitChars(const 
ASTContext ) const {
   if (!Ty || !Ty->getDecl()->hasFlexibleArrayMember())
 return CharUnits::Zero();
   auto *List = dyn_cast(getInit()->IgnoreParens());
-  if (!List)
+  if (!List || List->getNumInits() == 0)
 return CharUnits::Zero();
   const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
   auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType());

diff  --git a/clang/test/CodeGen/flexible-array-init.c 
b/clang/test/CodeGen/flexible-array-init.c
index b2cf959f7e1220..bae926da5feb07 100644
--- a/clang/test/CodeGen/flexible-array-init.c
+++ b/clang/test/CodeGen/flexible-array-init.c
@@ -20,3 +20,11 @@ struct __attribute((packed, aligned(4))) { char a; int x; 
char z[]; } e = { 1, 2
 
 struct { int x; char y[]; } f = { 1, { 13, 15 } };
 // CHECK: @f ={{.*}} global <{ i32, [2 x i8] }> <{ i32 1, [2 x i8] c"\0D\0F" }>
+
+union {
+  struct {
+int a;
+char b[];
+  } x;
+} in_union = {};
+// CHECK: @in_union ={{.*}} global %union.anon zeroinitializer



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


[clang] [clang] Fix assertion failure when initializing union with FAM (PR #77298)

2024-01-09 Thread Nikita Popov via cfe-commits

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


[clang] [clang] Update cxx_dr_status.html (PR #77372)

2024-01-09 Thread via cfe-commits

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

Can you modify the commit message to reference the issue list version (113) and 
maybe link to it ?
Otherwise LGTM

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


[libunwind] [llvm] [clang] [clang-tools-extra] [libcxx] [libc] [libcxxabi] [lldb] [compiler-rt] [flang] [lld] [mlir] [clang] static operators should evaluate object argument (PR #68485)

2024-01-09 Thread Tianlan Zhou via cfe-commits

SuperSodaSea wrote:

Ping.

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


[mlir] [llvm] [lld] [compiler-rt] [clang] [sanitizer] Select non-internal frames in ReportErrorSummary (PR #77406)

2024-01-09 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/77406

>From 5ac8056f36abb37a251f3696800d52a57e24c758 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 8 Jan 2024 19:45:51 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 .../sanitizer_symbolizer_report.cpp   | 28 ++-
 .../Linux/aligned_alloc-alignment.cpp |  2 +-
 .../TestCases/Linux/pvalloc-overflow.cpp  |  2 +-
 .../Posix/posix_memalign-alignment.cpp|  2 +-
 .../TestCases/allocator_returns_null.cpp  | 16 +--
 .../test/hwasan/TestCases/halt-on-error.cpp   |  6 ++--
 .../test/hwasan/TestCases/report-unmapped.cpp |  2 +-
 .../test/hwasan/TestCases/use-after-free.c|  2 +-
 .../TestCases/allocator_returns_null.cpp  | 16 +--
 .../TestCases/max_allocation_size.cpp | 16 +--
 10 files changed, 53 insertions(+), 39 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
index 0cf250f7212943..4e5c55a8f85b22 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
@@ -95,17 +95,31 @@ void ReportErrorSummary(const char *error_type, const 
StackTrace *stack,
 #if !SANITIZER_GO
   if (!common_flags()->print_summary)
 return;
-  if (stack->size == 0) {
-ReportErrorSummary(error_type);
-return;
+
+  // Find first non-internal stack frame.
+  for (uptr i = 0; i < stack->size; ++i) {
+uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[i]);
+SymbolizedStackHolder symbolized_stack(
+Symbolizer::GetOrInit()->SymbolizePC(pc));
+if (const SymbolizedStack *frame = symbolized_stack.get()) {
+  if (const SymbolizedStack *summary_frame = SkipInternalFrames(frame)) {
+ReportErrorSummary(error_type, summary_frame->info, alt_tool_name);
+return;
+  }
+}
   }
-  // Currently, we include the first stack frame into the report summary.
-  // Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
+
+  // Fallback to the top one.
   uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
   SymbolizedStackHolder symbolized_stack(
   Symbolizer::GetOrInit()->SymbolizePC(pc));
-  const SymbolizedStack *frame = symbolized_stack.get();
-  ReportErrorSummary(error_type, frame->info, alt_tool_name);
+  if (const SymbolizedStack *frame = symbolized_stack.get()) {
+ReportErrorSummary(error_type, frame->info, alt_tool_name);
+return;
+  }
+
+  // Fallback to a summary without location.
+  ReportErrorSummary(error_type);
 #endif
 }
 
diff --git 
a/compiler-rt/test/hwasan/TestCases/Linux/aligned_alloc-alignment.cpp 
b/compiler-rt/test/hwasan/TestCases/Linux/aligned_alloc-alignment.cpp
index ad5b7616e8a7fb..35e29e8cc83435 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/aligned_alloc-alignment.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Linux/aligned_alloc-alignment.cpp
@@ -14,7 +14,7 @@ int main() {
   // CHECK: ERROR: HWAddressSanitizer: invalid alignment requested in 
aligned_alloc: 17
   // CHECK: {{#0 0x.* in .*}}{{aligned_alloc|memalign}}
   // CHECK: {{#1 0x.* in main .*aligned_alloc-alignment.cpp:}}[[@LINE-3]]
-  // CHECK: SUMMARY: HWAddressSanitizer: invalid-aligned-alloc-alignment 
{{.*}} in aligned_alloc
+  // CHECK: SUMMARY: HWAddressSanitizer: invalid-aligned-alloc-alignment 
{{.*}} in main
 
   printf("pointer after failed aligned_alloc: %zd\n", (size_t)p);
   // CHECK-NULL: pointer after failed aligned_alloc: 0
diff --git a/compiler-rt/test/hwasan/TestCases/Linux/pvalloc-overflow.cpp 
b/compiler-rt/test/hwasan/TestCases/Linux/pvalloc-overflow.cpp
index bd9f34a0dac921..6b4410449a838a 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/pvalloc-overflow.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Linux/pvalloc-overflow.cpp
@@ -39,6 +39,6 @@ int main(int argc, char *argv[]) {
 // CHECK: {{ERROR: HWAddressSanitizer: pvalloc parameters overflow: size .* 
rounded up to system page size .* cannot be represented in type size_t}}
 // CHECK: {{#0 0x.* in .*pvalloc}}
 // CHECK: {{#1 0x.* in main .*pvalloc-overflow.cpp:}}
-// CHECK: SUMMARY: HWAddressSanitizer: pvalloc-overflow {{.*}} in pvalloc
+// CHECK: SUMMARY: HWAddressSanitizer: pvalloc-overflow {{.*}} in main
 
 // CHECK-NULL: errno: 12
diff --git 
a/compiler-rt/test/hwasan/TestCases/Posix/posix_memalign-alignment.cpp 
b/compiler-rt/test/hwasan/TestCases/Posix/posix_memalign-alignment.cpp
index 029e086f99ada2..5841ca42ceb033 100644
--- a/compiler-rt/test/hwasan/TestCases/Posix/posix_memalign-alignment.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Posix/posix_memalign-alignment.cpp
@@ -11,7 +11,7 @@ int main() {
   // CHECK: ERROR: 

[clang] [clang-format] Don't apply severe penalty if no possible column formats (PR #76675)

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

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


https://github.com/llvm/llvm-project/pull/76675
___
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