[PATCH] D120134: [analyzer] refactor makeIntValWithPtrWidth, remove getZeroWithPtrWidth (NFC)

2022-03-22 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 417415.
vabridgers added a comment.

update per @NoQ's latest comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120134/new/

https://reviews.llvm.org/D120134

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp


Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -742,9 +742,6 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
-  //and `getIntWithPtrWidth()` functions to prevent future
-  //confusion
   if (!Ty->isReferenceType())
 return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
   CastTy);
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1344,8 +1344,9 @@
 case Stmt::GNUNullExprClass: {
   // GNU __null is a pointer-width integer, not an actual pointer.
   ProgramStateRef state = Pred->getState();
-  state = state->BindExpr(S, Pred->getLocationContext(),
-  svalBuilder.makeIntValWithPtrWidth(0, false));
+  state = state->BindExpr(
+  S, Pred->getLocationContext(),
+  svalBuilder.makeIntValWithWidth(getContext().VoidPtrTy, 0));
   Bldr.generateNode(S, Pred, state);
   break;
 }
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2608,8 +2608,9 @@
 
   // Compare the size argument to 0.
   DefinedOrUnknownSVal SizeZero =
-svalBuilder.evalEQ(State, TotalSize.castAs(),
-   svalBuilder.makeIntValWithPtrWidth(0, false));
+  svalBuilder.evalEQ(State, TotalSize.castAs(),
+ svalBuilder.makeIntValWithWidth(
+ svalBuilder.getContext().getSizeType(), 0));
 
   ProgramStateRef StatePtrIsNull, StatePtrNotNull;
   std::tie(StatePtrIsNull, StatePtrNotNull) = State->assume(PtrEQ);
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -332,9 +332,8 @@
 return nonloc::ConcreteInt(BasicVals.getIntValue(integer, isUnsigned));
   }
 
-  NonLoc makeIntValWithPtrWidth(uint64_t integer, bool isUnsigned) {
-return nonloc::ConcreteInt(
-BasicVals.getIntWithPtrWidth(integer, isUnsigned));
+  NonLoc makeIntValWithWidth(QualType ptrType, uint64_t integer) {
+return nonloc::ConcreteInt(BasicVals.getValue(integer, ptrType));
   }
 
   NonLoc makeLocAsInteger(Loc loc, unsigned bits) {
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -220,14 +220,6 @@
 return getValue(0, Ctx.getTypeSize(T), true);
   }
 
-  const llvm::APSInt &getZeroWithPtrWidth(bool isUnsigned = true) {
-return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
-  }
-
-  const llvm::APSInt &getIntWithPtrWidth(uint64_t X, bool isUnsigned) {
-return getValue(X, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
-  }
-
   const llvm::APSInt &getTruthValue(bool b, QualType T) {
 return getValue(b ? 1 : 0, Ctx.getIntWidth(T),
 T->isUnsignedIntegerOrEnumerationType());


Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -742,9 +742,6 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
-  //and `getIntWithPtrWidth()` functions to preven

[PATCH] D120134: [analyzer] refactor makeIntValWithPtrWidth, remove getZeroWithPtrWidth (NFC)

2022-03-22 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked an inline comment as done.
vabridgers added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:2570
+  State, TotalSize.castAs(),
+  svalBuilder.makeIntValWithPtrWidth(Arg1->getType(), 0));
 

NoQ wrote:
> steakhal wrote:
> > We peobably wanted to use a different tspe for this expressuon. 
> > 'getArrayIndexType()' is a better fit IMO.
> > We shall see.
> `TotalSize` is literally `size_t` so `ASTContext.getSizeType()` is the right 
> type. `getArrayIndexType()` is signed so it's different.
Thanks @NoQ , the review is update. Best


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120134/new/

https://reviews.llvm.org/D120134

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


[PATCH] D121824: [clang] Do not crash on arrow operator on dependent type.

2022-03-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a subscriber: rsmith.
sammccall added a comment.

In D121824#3400720 , @hokein wrote:

> Sorry, I thought this crash is fixed as a bonus effort by improving the AST 
> for reference-type var-decl.
>
> Beyond the crash cased by the dependent-type `RecoveryExpr` built in 
> `Sema::BuildDeclarationNameExpr`, I think there is another issue which is 
> worth fixing: whether we should mark the reference-type var-decl valid if it 
> doesn't have an initializer (either the initializer is not provided in the 
> source code or too broken to preserve). The current AST behavior is 
> inconsistent:

Agree about the inconsistency. I think ideally we'd move in the direction of 
*not* marking such things invalid. Here's the quote from Richard:

In D76831#1973053 , @rsmith wrote:

> Generally I think we should be moving towards finer-grained "invalid" / 
> "contains errors" bits, so that we can preserve as much of the AST as 
> possible and produce accurate diagnostics for independent errors wherever 
> possible. To that end, I think generally the "invalid" bit on a declaration 
> should concern *only* the "declaration" part of that declaration (how it's 
> seen from other contexts that don't "look too closely"). So in particular:
>
> - The initializer of a variable should play no part in its "invalid" bit. If 
> the initializer expression is marked as "contains errors", then things that 
> care about the initializer (in particular, constant evaluation and any 
> diagnostics that look into the initializer) may need to bail out, but we 
> should be able to form a `DeclRefExpr` referring to that variable -- even if 
> (say) the variable is `constexpr`. Exception: if the variable has a deduced 
> type and the type can't be deduced due to an invalid initializer, then the 
> declaration should be marked invalid.
> - The body of a function should play no part in its "invalid" bit. (This came 
> up in a different code review recently.)

But practically, it's at least as important to make changes that make 
diagnostics better and not worse, and don't introduce new crashes. This is hard 
to do while keeping scope limited, so I'm OK with bending principle too.

> Another option would be to mark `a` valid regardless of the initializer. 
> Pros: preserve more AST nodes for `a`; the valid bit are consistent among 
> three cases. Cons: unknown? whether it'll break some subtle invariants in 
> clang; the bogus `requires an initializer` diagnostic is still there.
> But yeah, this is a separate issue, we should fix the crash first.

+1




Comment at: clang/lib/Sema/TreeTransform.h:14708
   } else if (Op == OO_Arrow) {
+if (First->getType()->isDependentType())
+  return ExprError();

hokein wrote:
> I'm not sure this is the only place triggering the crash, it looks like that 
> we're fixing a symptom.
> 
> While here, `First` refers to a dependent-type `RecoveryExpr` (which is built 
> from the code path: `TransformDeclRefExpr` -> `RebuildDeclRefExpr`-> 
> `Sema::BuildDeclarationNameExpr`). So I think we have a high chance that the 
> `RecoveryExpr` will spread multiple places in the `TreeTransform` and cause 
> similar violations in other places.
> 
> A safe fix will be to not build the `RecoveryExpr` in 
> `TreeTransform::TransformDeclRefExpr` -- `Sema::BuildDeclarationNameExpr` has 
> a `AcceptInvalidDecl` parameter (by default it is false), we could reuse it 
> to control whether we should build a `RecoveryExpr`.
>  
I agree with this FWIW: in principle it makes sense to have RecoveryExpr 
produced in template instantiation, in practice we probably haven't weakened 
the assumptions in template instantiation enough to do so safely, in the way 
that we have for "regular" sema.

We could try to do so in an ongoing way, but at least for syntax based tools 
like clangd the payoff won't be large as long as we keep mostly ignoring 
template instantiations.

That said, the current form of the patch is simple and fixes the crash in an 
obvious way, if this really is a more general problem then we'll see it again 
and have more data to generalize.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121824/new/

https://reviews.llvm.org/D121824

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


[PATCH] D121824: [clang] Do not crash on arrow operator on dependent type.

2022-03-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Oops, forgot conclusion:
Thanks for incorporating my testcase, and the patch LGTM in its current form 
(most of the alternatives discussed also sound OK).
I'll leave to Haojian to stamp.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121824/new/

https://reviews.llvm.org/D121824

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


[PATCH] D118935: [SYCL] Disallow explicit casts between mismatching address spaces

2022-03-22 Thread Harald van Dijk via Phabricator via cfe-commits
hvdijk added a comment.

In D118935#3399095 , @Fznamznon wrote:

> I was under impression that the change is small and therefore easy to 
> understand. Would some comment like "SYCL re-uses OpenCL mode diagnostics to 
> emit errors in case the cast happens between disjoint address spaces" help?

Speaking only for myself, but it was clear to me that that's what it did. What 
wasn't clear to me was why that's okay, and that was because I was under the 
impression that there were ways around this in OpenCL that are unavailable in 
SYCL. What might have helped me was a comment not saying that the cast is also 
an error is OpenCL mode, but that there is no way at all to express the 
conversion in OpenCL mode. This is all in hindsight though, I am not sure to 
what extent my confusion was foreseeable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118935/new/

https://reviews.llvm.org/D118935

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


[PATCH] D120573: [OpenMP] Support runtime user conditions in metadirective

2022-03-22 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:1852
+int BestIdx = getBestVariantMatchForContext(StaticVMIs, OMPCtx);
+
+EmitStmt(StaticWhenClauses[BestIdx]->getDirective());

This approach is valid for static conditions. How you are going to take care of 
multiple dynamic/runtime conditions?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120573/new/

https://reviews.llvm.org/D120573

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


[PATCH] D122265: [Clang][NFC] Cleanup dcl.constexpr/p3 tests

2022-03-22 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Check for warnings instead of using -Werror, to avoid masking the

type of diagnostic emitted

- use different -verify labels instead of using conditional

compilation of diagnostic checks


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122265

Files:
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp

Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
+++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++11 -Werror=c++14-extensions -Werror=c++20-extensions -Werror=c++2b-extensions %s
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++14 -DCXX14 -Werror=c++20-extensions -Werror=c++2b-extensions %s
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++20 -DCXX14 -DCXX20 -Werror=c++2b-extensions %s
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++2b -DCXX14 -DCXX20 -DCXX2b %s
+// RUN: %clang_cc1 -fcxx-exceptions -verify=expected,beforecxx14,beforecxx20,beforecxx2b -std=c++11 %s
+// RUN: %clang_cc1 -fcxx-exceptions -verify=expected,aftercxx14,beforecxx20,beforecxx2b -std=c++14 %s
+// RUN: %clang_cc1 -fcxx-exceptions -verify=expected,aftercxx14,aftercxx20,beforecxx2b -std=c++20  %s
+// RUN: %clang_cc1 -fcxx-exceptions -verify=expected,aftercxx14,aftercxx20 -std=c++2b %s
 
 namespace N {
   typedef char C;
@@ -21,10 +21,7 @@
 };
 
 struct S {
-  virtual int ImplicitlyVirtual() const = 0;
-#if __cplusplus <= 201703L
-  // expected-note@-2 {{overridden virtual function}}
-#endif
+  virtual int ImplicitlyVirtual() const = 0; // beforecxx20-note {{overridden virtual function}}
 };
 struct SS : S {
   int ImplicitlyVirtual() const;
@@ -37,31 +34,17 @@
   constexpr int f() const;
 
   //  - it shall not be virtual; [until C++20]
-  virtual constexpr int ExplicitlyVirtual() const { return 0; }
-#if __cplusplus <= 201703L
-  // expected-error@-2 {{virtual function cannot be constexpr}}
-#endif
+  virtual constexpr int ExplicitlyVirtual() const { return 0; } // beforecxx20-error {{virtual function cannot be constexpr}}
 
-  constexpr int ImplicitlyVirtual() const { return 0; }
-#if __cplusplus <= 201703L
-  // expected-error@-2 {{virtual function cannot be constexpr}}
-#endif
+  constexpr int ImplicitlyVirtual() const { return 0; } // beforecxx20-error {{virtual function cannot be constexpr}}
 
-  virtual constexpr int OutOfLineVirtual() const;
-#if __cplusplus <= 201703L
-  // expected-error@-2 {{virtual function cannot be constexpr}}
-#endif
+  virtual constexpr int OutOfLineVirtual() const; // beforecxx20-error {{virtual function cannot be constexpr}}
 
   //  - its return type shall be a literal type;
   constexpr NonLiteral NonLiteralReturn() const { return {}; } // expected-error {{constexpr function's return type 'NonLiteral' is not a literal type}}
-  constexpr void VoidReturn() const { return; }
-#ifndef CXX14
-  // expected-error@-2 {{constexpr function's return type 'void' is not a literal type}}
-#endif
-  constexpr ~T();
-#ifndef CXX20
-  // expected-error@-2 {{destructor cannot be declared constexpr}}
-#endif
+  constexpr void VoidReturn() const { return; }// beforecxx14-error {{constexpr function's return type 'void' is not a literal type}}
+  constexpr ~T();  // beforecxx20-error {{destructor cannot be declared constexpr}}
+
   typedef NonLiteral F() const;
   constexpr F NonLiteralReturn2; // ok until definition
 
@@ -78,29 +61,21 @@
   // destructor can be defaulted. Destructors can't be constexpr since they
   // don't have a literal return type. Defaulted assignment operators can't be
   // constexpr since they can't be const.
-  constexpr T &operator=(const T&) = default;
-#ifndef CXX14
-  // expected-error@-2 {{an explicitly-defaulted copy assignment operator may not have 'const', 'constexpr' or 'volatile' qualifiers}}
-  // expected-warning@-3 {{C++14}}
-#else
-  // expected-error@-5 {{defaulted definition of copy assignment operator is not constexpr}}
-#endif
+  constexpr T &operator=(const T &) = default; // beforecxx14-error {{an explicitly-defaulted copy assignment operator may not have 'const', 'constexpr' or 'volatile' qualifiers}} \
+   // beforecxx14-warning {{C++14}} \
+   // aftercxx14-error{{defaulted definition of copy assignment operator is not constexpr}}
 };
 
 constexpr int T::OutOfLineVirtual() const { return 0; }
-#ifdef CXX14
+#if __cplusplus >= 201402L
 struct T2 {
   int n = 0;
   constexpr T2 &operator=(const T2&) = default; //

[PATCH] D121951: [AMDGPU] Only warn when mixing printf and hostcall

2022-03-22 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D121951#3393928 , @sameerds wrote:

> In D121951#3392470 , @scott.linder 
> wrote:
>
>> In D121951#3391472 , @sameerds 
>> wrote:
>>
>>> The check for "__ockl_hostcall_internal" is not longer relevant with the 
>>> new hostcall attribute. Can we simply remove this check? What is the 
>>> situation where the warning is still useful?
>>
>> I wasn't aware of the new attribute, I'm happy to just delete it.
>
> Yeah, it happened in D119216 .
>
> But I am still curious about the check itself. Do we need to worry about a 
> situation where it is important to check whether OpenCL printf (non-hostcall) 
> and some other hostcall service are active in the same application?

I don't know how important it is to notify the user, but my understanding is 
pre-code-object-v5 we will use the same kernarg for both the printf and 
hostcall pointers. I don't know what actually happens (does the runtime notice 
it can't actually construct the kernarg and fail? does the code just fail when 
one of the two uses of the kernarg are incorrect?). Should I try to nail down 
exactly what currently happens?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121951/new/

https://reviews.llvm.org/D121951

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


[PATCH] D120573: [OpenMP] Support runtime user conditions in metadirective

2022-03-22 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:1793
+void CodeGenFunction::EmitOMPMetaDirective(const OMPMetaDirective &D) {
+  llvm::BasicBlock *AfterBlock =
+  createBasicBlock("omp.meta.user.condition.after");

Why are you skipping the AST building part? Any special significance of this 
approach?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120573/new/

https://reviews.llvm.org/D120573

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


[PATCH] D121873: [clang][extract-api] Add enum support

2022-03-22 Thread Zixu Wang via Phabricator via cfe-commits
zixuw updated this revision to Diff 417424.
zixuw added a comment.

Rebase on main with changed and merged refactoring in D122160 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121873/new/

https://reviews.llvm.org/D121873

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/enum.c

Index: clang/test/ExtractAPI/enum.c
===
--- /dev/null
+++ clang/test/ExtractAPI/enum.c
@@ -0,0 +1,505 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api -target arm64-apple-macosx \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+/// Kinds of vehicles
+enum Vehicle {
+  Bicycle,
+  Car,
+  Train, ///< Move this to the top! -Sheldon
+  Ship,
+  Airplane,
+};
+
+enum Direction : unsigned char {
+  North = 0,
+  East,
+  South,
+  West
+};
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [
+{
+  "kind": "memberOf",
+  "source": "c:@E@Vehicle@Bicycle",
+  "target": "c:@E@Vehicle"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Vehicle@Car",
+  "target": "c:@E@Vehicle"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Vehicle@Train",
+  "target": "c:@E@Vehicle"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Vehicle@Ship",
+  "target": "c:@E@Vehicle"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Vehicle@Airplane",
+  "target": "c:@E@Vehicle"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Direction@North",
+  "target": "c:@E@Direction"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Direction@East",
+  "target": "c:@E@Direction"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Direction@South",
+  "target": "c:@E@Direction"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Direction@West",
+  "target": "c:@E@Direction"
+}
+  ],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "enum"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Vehicle"
+},
+{
+  "kind": "text",
+  "spelling": ": "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+}
+  ],
+  "docComment": {
+"lines": [
+  {
+"range": {
+  "end": {
+"character": 22,
+"line": 1
+  },
+  "start": {
+"character": 5,
+"line": 1
+  }
+},
+"text": "Kinds of vehicles"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@E@Vehicle"
+  },
+  "kind": {
+"displayName": "Enumeration",
+"identifier": "c.enum"
+  },
+  "location": {
+"character": 6,
+"line": 2,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Vehicle"
+  }
+],
+"title": "Vehicle"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "identifier",
+  "spelling": "Bicycle"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@E@Vehicle@Bicycle"
+  },
+  "kind": {
+"displayName": "Enumeration Case",
+"identifier": "c.enum.case"
+  },
+  "location":

[PATCH] D121969: Pass split-machine-functions to code generator when flto is used

2022-03-22 Thread Wenlei He via Phabricator via cfe-commits
wenlei added a comment.

The linter warning seems legit, otherwise looks good.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121969/new/

https://reviews.llvm.org/D121969

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


[PATCH] D122202: [clang][extract-api] Add struct support

2022-03-22 Thread Zixu Wang via Phabricator via cfe-commits
zixuw updated this revision to Diff 417430.
zixuw added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122202/new/

https://reviews.llvm.org/D122202

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/struct.c

Index: clang/test/ExtractAPI/struct.c
===
--- /dev/null
+++ clang/test/ExtractAPI/struct.c
@@ -0,0 +1,303 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api -target arm64-apple-macosx \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+/// Color in RGBA
+struct Color {
+  unsigned Red;
+  unsigned Green;
+  unsigned Blue;
+  /// Alpha channel for transparency
+  unsigned Alpha;
+};
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Red",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Green",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Blue",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Alpha",
+  "target": "c:@S@Color"
+}
+  ],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "struct"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Color"
+}
+  ],
+  "docComment": {
+"lines": [
+  {
+"range": {
+  "end": {
+"character": 18,
+"line": 1
+  },
+  "start": {
+"character": 5,
+"line": 1
+  }
+},
+"text": "Color in RGBA"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Color"
+  },
+  "kind": {
+"displayName": "Struct",
+"identifier": "c.struct"
+  },
+  "location": {
+"character": 8,
+"line": 2,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Color"
+  }
+],
+"title": "Color"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Red"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Color@FI@Red"
+  },
+  "kind": {
+"displayName": "Struct Field",
+"identifier": "c.struct.field"
+  },
+  "location": {
+"character": 12,
+"line": 3,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Red"
+  }
+],
+"title": "Red"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Green"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Color@FI@Green"
+  },
+  

[PATCH] D122271: [Clang] -Wunused-but-set-variable warning - handle also pre/post unary operators

2022-03-22 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 created this revision.
xbolva00 added reviewers: efriedma, yonghong-song.
Herald added a project: All.
xbolva00 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang fails to diagnose:

  void test() {
  int j = 0;
  for (int i = 0; i < 1000; i++)
  j++;
  return;
  }

Reason: Missing support for UnaryOperator.

We should not warn with volatile variables... so add check for it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122271

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/Sema/warn-unused-but-set-variables.c
  clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp


Index: clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
===
--- clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -7,6 +7,7 @@
 struct __attribute__((warn_unused)) SWarnUnused {
   int j;
   void operator +=(int);
+  void operator ++();
 };
 
 int f0() {
@@ -62,3 +63,9 @@
   SWarnUnused swu;
   swu += n;
 }
+
+template  void f5() {
+  // Don't warn for overloaded pre/post operators in template code.
+  SWarnUnused swu;
+  ++swu;
+}
Index: clang/test/Sema/warn-unused-but-set-variables.c
===
--- clang/test/Sema/warn-unused-but-set-variables.c
+++ clang/test/Sema/warn-unused-but-set-variables.c
@@ -73,3 +73,20 @@
   __attribute__((__cleanup__(for_cleanup))) int x;
   x = 5;
 }
+
+void f4(void) {
+  int x1 = 0; // expected-warning{{variable 'x1' set but not used}}
+  x1++;
+  int x2 = 0; // expected-warning{{variable 'x2' set but not used}}
+  x2--;
+  int x3 = 0; // expected-warning{{variable 'x3' set but not used}}
+  ++x3;
+  int x4 = 0; // expected-warning{{variable 'x4' set but not used}}
+  --x4;
+
+  volatile int v1 = 0;
+  ++v1;
+  typedef volatile int volint;
+  volint v2 = 0;
+  v2++;
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -7926,6 +7926,7 @@
 Expr *E, llvm::DenseMap &RefsMinusAssignments) {
   DeclRefExpr *LHS = nullptr;
   bool IsCompoundAssign = false;
+  bool isIncrementDecrementUnaryOp = false;
   if (BinaryOperator *BO = dyn_cast(E)) {
 if (BO->getLHS()->getType()->isDependentType() ||
 BO->getRHS()->getType()->isDependentType()) {
@@ -7940,6 +7941,11 @@
 if (COCE->getOperator() != OO_Equal)
   return;
 LHS = dyn_cast(COCE->getArg(0));
+  } else if (UnaryOperator *UO = dyn_cast(E)) {
+if (!UO->isIncrementDecrementOp())
+  return;
+isIncrementDecrementUnaryOp = true;
+LHS = dyn_cast(UO->getSubExpr());
   }
   if (!LHS)
 return;
@@ -7947,8 +7953,10 @@
   if (!VD)
 return;
   // Don't decrement RefsMinusAssignments if volatile variable with compound
-  // assignment (+=, ...) to avoid potential unused-but-set-variable warning.
-  if (IsCompoundAssign && VD->getType().isVolatileQualified())
+  // assignment (+=, ...) or increment/decrement unary operator to avoid
+  // potential unused-but-set-variable warning.
+  if ((IsCompoundAssign || isIncrementDecrementUnaryOp) &&
+  VD->getType().isVolatileQualified())
 return;
   auto iter = RefsMinusAssignments.find(VD);
   if (iter == RefsMinusAssignments.end())


Index: clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
===
--- clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -7,6 +7,7 @@
 struct __attribute__((warn_unused)) SWarnUnused {
   int j;
   void operator +=(int);
+  void operator ++();
 };
 
 int f0() {
@@ -62,3 +63,9 @@
   SWarnUnused swu;
   swu += n;
 }
+
+template  void f5() {
+  // Don't warn for overloaded pre/post operators in template code.
+  SWarnUnused swu;
+  ++swu;
+}
Index: clang/test/Sema/warn-unused-but-set-variables.c
===
--- clang/test/Sema/warn-unused-but-set-variables.c
+++ clang/test/Sema/warn-unused-but-set-variables.c
@@ -73,3 +73,20 @@
   __attribute__((__cleanup__(for_cleanup))) int x;
   x = 5;
 }
+
+void f4(void) {
+  int x1 = 0; // expected-warning{{variable 'x1' set but not used}}
+  x1++;
+  int x2 = 0; // expected-warning{{variable 'x2' set but not used}}
+  x2--;
+  int x3 = 0; // expected-warning{{variable 'x3' set but not used}}
+  ++x3;
+  int x4 = 0; // expected-warning{{variable 'x4' set but not used}}
+  --x4;
+
+  volatile int v1 = 0;
+  ++v1;
+  typedef volatile int volint;
+  volint v2 = 0;
+  v2++;
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -7926,6 +7926,7 @@
 Expr *E, llvm

[clang-tools-extra] 07675b0 - [clang-tidy] Fix false positives in `misc-redundant-expression` check

2022-03-22 Thread Fabian Wolff via cfe-commits

Author: Fabian Wolff
Date: 2022-03-23T00:32:45+01:00
New Revision: 07675b0b38e930c2c582122ac93efcdf7859a772

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

LOG: [clang-tidy] Fix false positives in `misc-redundant-expression` check

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122111

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index f8073bff5ea98..e68384348bd9c 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -569,6 +569,7 @@ matchRelationalIntegerConstantExpr(StringRef Id) {
   std::string SwapId = (Id + "-swap").str();
   std::string NegateId = (Id + "-negate").str();
   std::string OverloadId = (Id + "-overload").str();
+  std::string ConstId = (Id + "-const").str();
 
   const auto RelationalExpr = ignoringParenImpCasts(binaryOperator(
   isComparisonOperator(), expr().bind(Id),
@@ -600,7 +601,9 @@ matchRelationalIntegerConstantExpr(StringRef Id) {
   cxxOperatorCallExpr(
   hasAnyOverloadedOperatorName("==", "!=", "<", "<=", ">", ">="),
   // Filter noisy false positives.
-  unless(isMacro()), unless(isInTemplateInstantiation()))
+  unless(isMacro()), unless(isInTemplateInstantiation()),
+  anyOf(hasLHS(ignoringParenImpCasts(integerLiteral().bind(ConstId))),
+hasRHS(ignoringParenImpCasts(integerLiteral().bind(ConstId)
   .bind(OverloadId);
 
   return anyOf(RelationalExpr, CastExpr, NegateRelationalExpr,
@@ -674,16 +677,38 @@ static bool retrieveRelationalIntegerConstantExpr(
 if (canOverloadedOperatorArgsBeModified(OverloadedOperatorExpr, false))
   return false;
 
+bool IntegerConstantIsFirstArg = false;
+
 if (const auto *Arg = OverloadedOperatorExpr->getArg(1)) {
   if (!Arg->isValueDependent() &&
-  !Arg->isIntegerConstantExpr(*Result.Context))
-return false;
-}
-Symbol = OverloadedOperatorExpr->getArg(0);
+  !Arg->isIntegerConstantExpr(*Result.Context)) {
+IntegerConstantIsFirstArg = true;
+if (const auto *Arg = OverloadedOperatorExpr->getArg(0)) {
+  if (!Arg->isValueDependent() &&
+  !Arg->isIntegerConstantExpr(*Result.Context))
+return false;
+} else
+  return false;
+  }
+} else
+  return false;
+
+Symbol = OverloadedOperatorExpr->getArg(IntegerConstantIsFirstArg ? 1 : 0);
 OperandExpr = OverloadedOperatorExpr;
 Opcode = 
BinaryOperator::getOverloadedOpcode(OverloadedOperatorExpr->getOperator());
 
-return BinaryOperator::isComparisonOp(Opcode);
+if (!retrieveIntegerConstantExpr(Result, Id, Value, ConstExpr))
+  return false;
+
+if (!BinaryOperator::isComparisonOp(Opcode))
+  return false;
+
+// The call site of this function expects the constant on the RHS,
+// so change the opcode accordingly.
+if (IntegerConstantIsFirstArg)
+  Opcode = BinaryOperator::reverseComparisonOp(Opcode);
+
+return true;
   } else {
 return false;
   }

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 551e36dea0937..9e68fb1c7b0f8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -116,6 +116,9 @@ Changes in existing checks
   ` when a pure virtual 
function
   overrided has a const return type. Removed the fix for a virtual function.
 
+- Fixed a false positive in :doc:`misc-redundant-expression 
`
+  involving overloaded comparison operators.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
index 075c3aca9d03f..31fe8e0275b02 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
@@ -369,6 +369,11 @@ struct S {
 bool operator<=(const S &s, int i) { return s.x <= i; } // not modifying
 bool operator>=(const S &s, const int &i) { return s.x >= i; } // not modifying
 
+bool operator==(int i, const S &s) { return s == i; } // not modifying
+bool operator<(const int &i, const S &s) { return s > i; } // not modifying
+bool operator<=(const int &i, const S &s) { return s >= i; } // not modifying
+bool operator>(const int &i, const S &

[PATCH] D122111: [clang-tidy] Fix false positives in `misc-redundant-expression` check

2022-03-22 Thread Fabian Wolff via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
fwolff marked an inline comment as done.
Closed by commit rG07675b0b38e9: [clang-tidy] Fix false positives in 
`misc-redundant-expression` check (authored by fwolff).

Changed prior to commit:
  https://reviews.llvm.org/D122111?vs=417054&id=417433#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122111/new/

https://reviews.llvm.org/D122111

Files:
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
@@ -369,6 +369,11 @@
 bool operator<=(const S &s, int i) { return s.x <= i; } // not modifying
 bool operator>=(const S &s, const int &i) { return s.x >= i; } // not modifying
 
+bool operator==(int i, const S &s) { return s == i; } // not modifying
+bool operator<(const int &i, const S &s) { return s > i; } // not modifying
+bool operator<=(const int &i, const S &s) { return s >= i; } // not modifying
+bool operator>(const int &i, const S &s) { return s < i; } // not modifying
+
 struct S2 {
   S2() { x = 1; }
   int x;
@@ -452,6 +457,25 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: logical expression is always false
   if (s1 >= 1 || s1 <= 1) return true;
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always true
+  if (s1 >= 2 && s1 <= 0) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always false
+
+  // Same test as above but with swapped LHS/RHS on one side of the logical operator.
+  if (1 == s1 && s1 == 1) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: equivalent expression on both sides of logical operator
+  if (1 == s1 || s1 != 1) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always true
+  if (1 < s1 && s1 < 1) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: logical expression is always false
+  if (1 <= s1 || s1 <= 1) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always true
+  if (2 < s1 && 0 > s1) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: logical expression is always false
+
+  // Test for absence of false positives (issue #54011).
+  if (s1 == 1 || s1 == 2) return true;
+  if (s1 > 1 && s1 < 3) return true;
+  if (s1 >= 2 || s1 <= 0) return true;
 
   // Test for overloaded operators that may modify their params.
   S2 s2;
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -116,6 +116,9 @@
   ` when a pure virtual function
   overrided has a const return type. Removed the fix for a virtual function.
 
+- Fixed a false positive in :doc:`misc-redundant-expression `
+  involving overloaded comparison operators.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -569,6 +569,7 @@
   std::string SwapId = (Id + "-swap").str();
   std::string NegateId = (Id + "-negate").str();
   std::string OverloadId = (Id + "-overload").str();
+  std::string ConstId = (Id + "-const").str();
 
   const auto RelationalExpr = ignoringParenImpCasts(binaryOperator(
   isComparisonOperator(), expr().bind(Id),
@@ -600,7 +601,9 @@
   cxxOperatorCallExpr(
   hasAnyOverloadedOperatorName("==", "!=", "<", "<=", ">", ">="),
   // Filter noisy false positives.
-  unless(isMacro()), unless(isInTemplateInstantiation()))
+  unless(isMacro()), unless(isInTemplateInstantiation()),
+  anyOf(hasLHS(ignoringParenImpCasts(integerLiteral().bind(ConstId))),
+hasRHS(ignoringParenImpCasts(integerLiteral().bind(ConstId)
   .bind(OverloadId);
 
   return anyOf(RelationalExpr, CastExpr, NegateRelationalExpr,
@@ -674,16 +677,38 @@
 if (canOverloadedOperatorArgsBeModified(OverloadedOperatorExpr, false))
   return false;
 
+bool IntegerConstantIsFirstArg = false;
+
 if (const auto *Arg = OverloadedOperatorExpr->getArg(1)) {
   if (!Arg->isValueDependent() &&
-  !Arg->isIntegerConstantExpr(*Result.Context))
-return false;
-}
-Symbol = OverloadedOperatorExpr->getArg(0);
+  !Arg->isIntegerConstantExpr(*Result.Context)) {
+IntegerConstantIsFirstArg = true;
+if (const auto *Arg =

[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-22 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa updated this revision to Diff 417435.
yihanaa added a reviewer: xbolva00.
yihanaa added a comment.

Remove code formatting changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122248/new/

https://reviews.llvm.org/D122248

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/dump-struct-builtin.c

Index: clang/test/CodeGen/dump-struct-builtin.c
===
--- clang/test/CodeGen/dump-struct-builtin.c
+++ clang/test/CodeGen/dump-struct-builtin.c
@@ -126,7 +126,7 @@
   .a = 12,
   };
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U1]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U1A, %struct.U1A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U1A, %struct.U1A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* [[FIELD_U1]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i16, i16* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U1]], i32 0, i32 0), i16 [[LOAD1]])
@@ -144,7 +144,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U2]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U2A, %struct.U2A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U2A, %struct.U2A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* [[FIELD_U2]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i16, i16* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U2]], i32 0, i32 0), i16 [[LOAD1]])
@@ -162,7 +162,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U3]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U3A, %struct.U3A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U3A, %struct.U3A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* [[FIELD_U3]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U3]], i32 0, i32 0), i32 [[LOAD1]])
@@ -180,7 +180,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U4]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U4A, %struct.U4A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U4A, %struct.U4A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* [[FIELD_U4]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U4]], i32 0, i32 0), i32 [[LOAD1]])
@@ -198,7 +198,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U5]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U5A, %struct.U5A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U5A, %struct.U5A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* [[FIELD_U5]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U5]], i32 0, i32 0), i64 [[LOAD1]])
@@ -216,7 +216,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U6]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U6A, %struct.U6A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U6A, %struct.U6A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* [[FIELD_U6]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U6]], i32 0, i32 0), i64 [[LOAD1]])
@@ -234,7 +234,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U7]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U7A, %struct.U7A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U7A, %struct.U7A* %a, i32 0, 

[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-22 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added a comment.

In D122248#3400408 , @xbolva00 wrote:

>>> the remaining changes are code formatting
>
> Please remove code formatting changes.

Okay, i have removed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122248/new/

https://reviews.llvm.org/D122248

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


[PATCH] D122202: [clang][extract-api] Add struct support

2022-03-22 Thread Zixu Wang via Phabricator via cfe-commits
zixuw updated this revision to Diff 417438.
zixuw marked 3 inline comments as done.
zixuw added a comment.

Address review issues: fix Symbol Graph struct kind identifiers and display 
names


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122202/new/

https://reviews.llvm.org/D122202

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/struct.c

Index: clang/test/ExtractAPI/struct.c
===
--- /dev/null
+++ clang/test/ExtractAPI/struct.c
@@ -0,0 +1,303 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api -target arm64-apple-macosx \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+/// Color in RGBA
+struct Color {
+  unsigned Red;
+  unsigned Green;
+  unsigned Blue;
+  /// Alpha channel for transparency
+  unsigned Alpha;
+};
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Red",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Green",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Blue",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Alpha",
+  "target": "c:@S@Color"
+}
+  ],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "struct"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Color"
+}
+  ],
+  "docComment": {
+"lines": [
+  {
+"range": {
+  "end": {
+"character": 18,
+"line": 1
+  },
+  "start": {
+"character": 5,
+"line": 1
+  }
+},
+"text": "Color in RGBA"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Color"
+  },
+  "kind": {
+"displayName": "Structure",
+"identifier": "c.struct"
+  },
+  "location": {
+"character": 8,
+"line": 2,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Color"
+  }
+],
+"title": "Color"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Red"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Color@FI@Red"
+  },
+  "kind": {
+"displayName": "Instance Property",
+"identifier": "c.property"
+  },
+  "location": {
+"character": 12,
+"line": 3,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Red"
+  }
+],
+"title": "Red"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Green"
+}
+  

[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-22 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa updated this revision to Diff 417439.
yihanaa added a comment.

Remove useless comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122248/new/

https://reviews.llvm.org/D122248

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/dump-struct-builtin.c

Index: clang/test/CodeGen/dump-struct-builtin.c
===
--- clang/test/CodeGen/dump-struct-builtin.c
+++ clang/test/CodeGen/dump-struct-builtin.c
@@ -126,7 +126,7 @@
   .a = 12,
   };
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U1]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U1A, %struct.U1A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U1A, %struct.U1A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* [[FIELD_U1]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i16, i16* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U1]], i32 0, i32 0), i16 [[LOAD1]])
@@ -144,7 +144,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U2]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U2A, %struct.U2A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U2A, %struct.U2A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* [[FIELD_U2]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i16, i16* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U2]], i32 0, i32 0), i16 [[LOAD1]])
@@ -162,7 +162,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U3]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U3A, %struct.U3A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U3A, %struct.U3A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* [[FIELD_U3]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U3]], i32 0, i32 0), i32 [[LOAD1]])
@@ -180,7 +180,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U4]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U4A, %struct.U4A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U4A, %struct.U4A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* [[FIELD_U4]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U4]], i32 0, i32 0), i32 [[LOAD1]])
@@ -198,7 +198,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U5]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U5A, %struct.U5A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U5A, %struct.U5A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* [[FIELD_U5]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U5]], i32 0, i32 0), i64 [[LOAD1]])
@@ -216,7 +216,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U6]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U6A, %struct.U6A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U6A, %struct.U6A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* [[FIELD_U6]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U6]], i32 0, i32 0), i64 [[LOAD1]])
@@ -234,7 +234,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U7]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U7A, %struct.U7A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U7A, %struct.U7A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @pri

[PATCH] D121927: [Clang] Work with multiple pragmas weak before definition

2022-03-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast updated this revision to Diff 417443.
hubert.reinterpretcast added a comment.

- Address review comments: Add release notes, expand comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121927/new/

https://reviews.llvm.org/D121927

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Weak.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGen/pragma-weak.c
  clang/test/PCH/pragma-weak-functional.c
  clang/test/PCH/pragma-weak-functional.h

Index: clang/test/PCH/pragma-weak-functional.h
===
--- /dev/null
+++ clang/test/PCH/pragma-weak-functional.h
@@ -0,0 +1,6 @@
+// Header for PCH test pragma-weak-functional.c
+
+#pragma weak undecfunc_alias2 = undecfunc
+#pragma weak undecfunc_alias4 = undecfunc_alias1
+#pragma weak undecfunc_alias3 = undecfunc_alias1
+#pragma weak undecfunc_alias1 = undecfunc
Index: clang/test/PCH/pragma-weak-functional.c
===
--- /dev/null
+++ clang/test/PCH/pragma-weak-functional.c
@@ -0,0 +1,17 @@
+// Test this without pch.
+// RUN: %clang_cc1 -include %S/pragma-weak-functional.h %s -verify -emit-llvm -o - | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -x c-header -emit-pch -o %t %S/pragma-weak-functional.h
+// RUN: %clang_cc1 -include-pch %t %s -verify -emit-llvm -o - | FileCheck %s
+
+// CHECK-DAG: @undecfunc_alias1 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias2 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias3 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias4 = weak{{.*}} alias void (), void ()* @undecfunc
+
+/ PR28611: Try multiple aliases of same undeclared symbol or alias
+void undecfunc_alias1(void);
+void undecfunc(void) { }
+// expected-warning@pragma-weak-functional.h:4 {{alias will always resolve to undecfunc}}
+// expected-warning@pragma-weak-functional.h:5 {{alias will always resolve to undecfunc}}
Index: clang/test/CodeGen/pragma-weak.c
===
--- clang/test/CodeGen/pragma-weak.c
+++ clang/test/CodeGen/pragma-weak.c
@@ -17,6 +17,10 @@
 // CHECK-DAG: @mix2 = weak{{.*}} alias void (), void ()* @__mix2
 // CHECK-DAG: @a1 = weak{{.*}} alias void (), void ()* @__a1
 // CHECK-DAG: @xxx = weak{{.*}} alias void (), void ()* @__xxx
+// CHECK-DAG: @undecfunc_alias1 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias2 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias3 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias4 = weak{{.*}} alias void (), void ()* @undecfunc
 
 
 
@@ -136,6 +140,15 @@
 __attribute((pure,noinline,const)) void __xxx(void) { }
 // CHECK: void @__xxx() [[RN:#[0-9]+]]
 
+/ PR28611: Try multiple aliases of same undeclared symbol or alias
+#pragma weak undecfunc_alias1 = undecfunc
+#pragma weak undecfunc_alias1 = undecfunc // Try specifying same alias/target pair a second time.
+#pragma weak undecfunc_alias3 = undecfunc_alias2 // expected-warning {{alias will always resolve to undecfunc}}
+#pragma weak undecfunc_alias4 = undecfunc_alias2 // expected-warning {{alias will always resolve to undecfunc}}
+#pragma weak undecfunc_alias2 = undecfunc
+void undecfunc_alias2(void);
+void undecfunc(void) { }
+
 / PR10878: Make sure we can call a weak alias
 void SHA512Pad(void *context) {}
 #pragma weak SHA384Pad = SHA512Pad
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4559,13 +4559,14 @@
   // entire table, since later PCH files in a PCH chain are only interested in
   // the results at the end of the chain.
   RecordData WeakUndeclaredIdentifiers;
-  for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) {
-IdentifierInfo *II = WeakUndeclaredIdentifier.first;
-WeakInfo &WI = WeakUndeclaredIdentifier.second;
-AddIdentifierRef(II, WeakUndeclaredIdentifiers);
-AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers);
-AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers);
-WeakUndeclaredIdentifiers.push_back(WI.getUsed());
+  for (const auto &WeakUndeclaredIdentifierList :
+   SemaRef.WeakUndeclaredIdentifiers) {
+const IdentifierInfo *const II = WeakUndeclaredIdentifierList.first;
+for (const auto &WI : WeakUndeclaredIdentifierList.second) {
+  AddIdentifierRef(II, WeakUndeclaredIdentifiers);
+  AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers);
+  AddSourceLocation(WI.getLocati

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/Format.cpp:2692-2695
+  for (int i = Matches.size() - 1; i > 0; i--) {
+if (!Matches[i].empty())
+  return Matches[i];
+  }

I think you missed `Matches[0]`.



Comment at: clang/lib/Format/Format.cpp:3056
 
+inline StringRef trimInclude(StringRef IncludeName) {
+  return IncludeName.trim("\"<>;");

We should make it `static` if it's only used in this file.



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:176-188
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ 
]*([^;]+;)))";
+
+// Returns the last match group in the above regex (IncludeRegexPattern) that
+// is not empty.
+StringRef getIncludeNameFromMatches(const SmallVectorImpl &Matches) 
{
+  for (int i = Matches.size() - 1; i > 0; i--) {

If these are the same as in `Format.cpp` above, we should move the definitions 
to `HeaderIncludes.h`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

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


[PATCH] D122277: [analyzer] Fix crash in RangedConstraintManager.cpp

2022-03-22 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: martong, NoQ.
Herald added subscribers: manas, steakhal, ASDenysPetrov, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a project: All.
vabridgers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change fixes a crash in RangedConstraintManager.cpp:assumeSym due to an
unhandled BO_Div case.

clang: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp:51:

  virtual clang::ento::ProgramStateRef
  clang::ento::RangedConstraintManager::assumeSym(clang::ento::ProgramStateRef,
clang::ento::SymbolRef, bool):
  Assertion `BinaryOperator::isComparisonOp(Op)' failed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122277

Files:
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/symbol-simplification-bo-div.c

Index: clang/test/Analysis/symbol-simplification-bo-div.c
===
--- /dev/null
+++ clang/test/Analysis/symbol-simplification-bo-div.c
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core %s \
+// RUN:-triple x86_64-pc-linux-gnu -verify
+
+// don't crash
+// expected-no-diagnostics
+
+int a, b;
+int c(void) {
+  unsigned d = a;
+  --d;
+  short e = b / b - a;
+  ++e;
+  return d <= 0 && e && e;
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -48,47 +48,49 @@
 
   if (const auto *SSE = dyn_cast(Sym)) {
 BinaryOperator::Opcode Op = SSE->getOpcode();
-assert(BinaryOperator::isComparisonOp(Op));
-
-// We convert equality operations for pointers only.
-if (Loc::isLocType(SSE->getLHS()->getType()) &&
-Loc::isLocType(SSE->getRHS()->getType())) {
-  // Translate "a != b" to "(b - a) != 0".
-  // We invert the order of the operands as a heuristic for how loop
-  // conditions are usually written ("begin != end") as compared to length
-  // calculations ("end - begin"). The more correct thing to do would be to
-  // canonicalize "a - b" and "b - a", which would allow us to treat
-  // "a != b" and "b != a" the same.
-
-  SymbolManager &SymMgr = getSymbolManager();
-  QualType DiffTy = SymMgr.getContext().getPointerDiffType();
-  SymbolRef Subtraction =
-  SymMgr.getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
-
-  const llvm::APSInt &Zero = getBasicVals().getValue(0, DiffTy);
-  Op = BinaryOperator::reverseComparisonOp(Op);
-  if (!Assumption)
-Op = BinaryOperator::negateComparisonOp(Op);
-  return assumeSymRel(State, Subtraction, Op, Zero);
-}
+// assert(BinaryOperator::isComparisonOp(Op));
+if (BinaryOperator::isComparisonOp(Op)) {
+
+  // We convert equality operations for pointers only.
+  if (Loc::isLocType(SSE->getLHS()->getType()) &&
+  Loc::isLocType(SSE->getRHS()->getType())) {
+// Translate "a != b" to "(b - a) != 0".
+// We invert the order of the operands as a heuristic for how loop
+// conditions are usually written ("begin != end") as compared to length
+// calculations ("end - begin"). The more correct thing to do would be
+// to canonicalize "a - b" and "b - a", which would allow us to treat "a
+// != b" and "b != a" the same.
+
+SymbolManager &SymMgr = getSymbolManager();
+QualType DiffTy = SymMgr.getContext().getPointerDiffType();
+SymbolRef Subtraction =
+SymMgr.getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
+
+const llvm::APSInt &Zero = getBasicVals().getValue(0, DiffTy);
+Op = BinaryOperator::reverseComparisonOp(Op);
+if (!Assumption)
+  Op = BinaryOperator::negateComparisonOp(Op);
+return assumeSymRel(State, Subtraction, Op, Zero);
+  }
 
-if (BinaryOperator::isEqualityOp(Op)) {
-  SymbolManager &SymMgr = getSymbolManager();
+  if (BinaryOperator::isEqualityOp(Op)) {
+SymbolManager &SymMgr = getSymbolManager();
 
-  QualType ExprType = SSE->getType();
-  SymbolRef CanonicalEquality =
-  SymMgr.getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
+QualType ExprType = SSE->getType();
+SymbolRef CanonicalEquality =
+SymMgr.getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
 
-  bool WasEqual = SSE->getOpcode() == BO_EQ;
-  bool IsExpectedEqual = WasEqual == Assumption;
+bool WasEqual = SSE->getOpcode() == BO_EQ;
+bool IsExpectedEqual = WasEqual == Assumption;
 
-  const llvm::APSInt &Zero = getBasicVals().getValue(0, ExprType);
+const llvm::APSInt &Zero = getBasicVals().g

[PATCH] D122277: [analyzer] Fix crash in RangedConstraintManager.cpp

2022-03-22 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 417450.
vabridgers added a comment.

remove assert that was commented out


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122277/new/

https://reviews.llvm.org/D122277

Files:
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/symbol-simplification-bo-div.c

Index: clang/test/Analysis/symbol-simplification-bo-div.c
===
--- /dev/null
+++ clang/test/Analysis/symbol-simplification-bo-div.c
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core %s \
+// RUN:-triple x86_64-pc-linux-gnu -verify
+
+// don't crash
+// expected-no-diagnostics
+
+int a, b;
+int c(void) {
+  unsigned d = a;
+  --d;
+  short e = b / b - a;
+  ++e;
+  return d <= 0 && e && e;
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -48,47 +48,48 @@
 
   if (const auto *SSE = dyn_cast(Sym)) {
 BinaryOperator::Opcode Op = SSE->getOpcode();
-assert(BinaryOperator::isComparisonOp(Op));
-
-// We convert equality operations for pointers only.
-if (Loc::isLocType(SSE->getLHS()->getType()) &&
-Loc::isLocType(SSE->getRHS()->getType())) {
-  // Translate "a != b" to "(b - a) != 0".
-  // We invert the order of the operands as a heuristic for how loop
-  // conditions are usually written ("begin != end") as compared to length
-  // calculations ("end - begin"). The more correct thing to do would be to
-  // canonicalize "a - b" and "b - a", which would allow us to treat
-  // "a != b" and "b != a" the same.
-
-  SymbolManager &SymMgr = getSymbolManager();
-  QualType DiffTy = SymMgr.getContext().getPointerDiffType();
-  SymbolRef Subtraction =
-  SymMgr.getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
-
-  const llvm::APSInt &Zero = getBasicVals().getValue(0, DiffTy);
-  Op = BinaryOperator::reverseComparisonOp(Op);
-  if (!Assumption)
-Op = BinaryOperator::negateComparisonOp(Op);
-  return assumeSymRel(State, Subtraction, Op, Zero);
-}
+if (BinaryOperator::isComparisonOp(Op)) {
+
+  // We convert equality operations for pointers only.
+  if (Loc::isLocType(SSE->getLHS()->getType()) &&
+  Loc::isLocType(SSE->getRHS()->getType())) {
+// Translate "a != b" to "(b - a) != 0".
+// We invert the order of the operands as a heuristic for how loop
+// conditions are usually written ("begin != end") as compared to length
+// calculations ("end - begin"). The more correct thing to do would be
+// to canonicalize "a - b" and "b - a", which would allow us to treat "a
+// != b" and "b != a" the same.
+
+SymbolManager &SymMgr = getSymbolManager();
+QualType DiffTy = SymMgr.getContext().getPointerDiffType();
+SymbolRef Subtraction =
+SymMgr.getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
+
+const llvm::APSInt &Zero = getBasicVals().getValue(0, DiffTy);
+Op = BinaryOperator::reverseComparisonOp(Op);
+if (!Assumption)
+  Op = BinaryOperator::negateComparisonOp(Op);
+return assumeSymRel(State, Subtraction, Op, Zero);
+  }
 
-if (BinaryOperator::isEqualityOp(Op)) {
-  SymbolManager &SymMgr = getSymbolManager();
+  if (BinaryOperator::isEqualityOp(Op)) {
+SymbolManager &SymMgr = getSymbolManager();
 
-  QualType ExprType = SSE->getType();
-  SymbolRef CanonicalEquality =
-  SymMgr.getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
+QualType ExprType = SSE->getType();
+SymbolRef CanonicalEquality =
+SymMgr.getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
 
-  bool WasEqual = SSE->getOpcode() == BO_EQ;
-  bool IsExpectedEqual = WasEqual == Assumption;
+bool WasEqual = SSE->getOpcode() == BO_EQ;
+bool IsExpectedEqual = WasEqual == Assumption;
 
-  const llvm::APSInt &Zero = getBasicVals().getValue(0, ExprType);
+const llvm::APSInt &Zero = getBasicVals().getValue(0, ExprType);
 
-  if (IsExpectedEqual) {
-return assumeSymNE(State, CanonicalEquality, Zero, Zero);
-  }
+if (IsExpectedEqual) {
+  return assumeSymNE(State, CanonicalEquality, Zero, Zero);
+}
 
-  return assumeSymEQ(State, CanonicalEquality, Zero, Zero);
+return assumeSymEQ(State, CanonicalEquality, Zero, Zero);
+  }
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:176-188
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ 
]*([^;]+;)))";
+
+// Returns the last match group in the above regex (IncludeRegexPattern) that
+// is not empty.
+StringRef getIncludeNameFromMatches(const SmallVectorImpl &Matches) 
{
+  for (int i = Matches.size() - 1; i > 0; i--) {

owenpan wrote:
> If these are the same as in `Format.cpp` above, we should move the 
> definitions to `HeaderIncludes.h`.
> If these are the same as in `Format.cpp` above, we should move the 
> definitions to `HeaderIncludes.h`.

I meant we should remove the definitions from `Format.cpp` and add the 
declarations to `HeaderIncludes.h`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

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


[PATCH] D122175: [clang][extract-api] Enable processing of multiple headers

2022-03-22 Thread Juergen Ributzka via Phabricator via cfe-commits
ributzka added inline comments.



Comment at: clang/include/clang/SymbolGraph/FrontendActions.h:35
+  /// This is called before executing the action on any inputs. This merges all
+  /// the provided headers into a single header for processing.
+  bool PrepareToExecuteAction(CompilerInstance &CI) override;

This comment confused me a bit. By looking at the code further down, it only 
adds include statements for each header, which is different from merging all 
headers into a single header/buffer.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122175/new/

https://reviews.llvm.org/D122175

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


[PATCH] D122278: [clang] Improve diagnostic for reopened inline namespace

2022-03-22 Thread Fabian Wolff via Phabricator via cfe-commits
fwolff created this revision.
fwolff added reviewers: rsmith, cor3ntin, mizvekov.
fwolff added a project: clang.
Herald added a project: All.
fwolff requested review of this revision.
Herald added a subscriber: cfe-commits.

Fixes #50794 . Reopening an 
inline namespace without the `inline` keyword yields a warning:

  inline namespace abc {}
  namespace abc {}
  namespace abc {}

  :2:11: warning: inline namespace reopened as a non-inline namespace 
[-Winline-namespace-reopened-noninline]
  namespace abc {}
^
  inline 
  :1:18: note: previous definition is here
  inline namespace abc {}
   ^
  :3:11: warning: inline namespace reopened as a non-inline namespace 
[-Winline-namespace-reopened-noninline]
  namespace abc {}
^
  inline 
  :2:11: note: previous definition is here
  namespace abc {}
^

But you'll notice that the second "previous definition is here" is actually not 
helpful, because this previous definition isn't explicitly marked `inline`. I 
think that the note should point to the first definition instead, which must 
always  have the `inline` if 
the namespace is supposed to be an inline namespace.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122278

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
  clang/test/SemaCXX/warn-inline-namespace-reopened-twice.cpp


Index: clang/test/SemaCXX/warn-inline-namespace-reopened-twice.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-inline-namespace-reopened-twice.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -Wall -verify -std=c++11 %s
+
+// Regression test for #50794.
+
+// expected-note@+1 2 {{previous definition is here}}
+inline namespace X {}
+
+namespace X {} // expected-warning {{inline namespace reopened as a non-inline 
namespace}}
+namespace X {} // expected-warning {{inline namespace reopened as a non-inline 
namespace}}
Index: clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
===
--- clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
+++ clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
@@ -17,7 +17,7 @@
 // expected-warning@+2 {{inline nested namespace definition is incompatible 
with C++ standards before C++20}}
 #endif
 namespace valid1::valid2::inline valid3::inline valid4::valid5 {}
-// expected-note@-1 2 {{previous definition is here}}
+// expected-note@-1 4 {{previous definition is here}}
 
 #if __cplusplus <= 201402L
 // expected-warning@+3 {{nested namespace definition is a C++17 extension; 
define each namespace separately}}
@@ -34,7 +34,6 @@
 // expected-warning@+2 {{inline nested namespace definition is incompatible 
with C++ standards before C++20}}
 #endif
 namespace valid1::valid2::inline valid3::inline valid4::valid5 {}
-// expected-note@-1 2 {{previous definition is here}}
 
 namespace valid1 {
 namespace valid2 {
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11059,6 +11059,12 @@
 NamespaceDecl *PrevNS) {
   assert(*IsInline != PrevNS->isInline());
 
+  if (auto *FirstNS = PrevNS->getFirstDecl())
+// 'inline' must appear on the original definition, but not necessarily
+// on all extension definitions, so the note should point to the first
+// definition to avoid confusion.
+PrevNS = FirstNS;
+
   if (PrevNS->isInline())
 // The user probably just forgot the 'inline', so suggest that it
 // be added back.


Index: clang/test/SemaCXX/warn-inline-namespace-reopened-twice.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-inline-namespace-reopened-twice.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -Wall -verify -std=c++11 %s
+
+// Regression test for #50794.
+
+// expected-note@+1 2 {{previous definition is here}}
+inline namespace X {}
+
+namespace X {} // expected-warning {{inline namespace reopened as a non-inline namespace}}
+namespace X {} // expected-warning {{inline namespace reopened as a non-inline namespace}}
Index: clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
===
--- clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
+++ clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
@@ -17,7 +17,7 @@
 // expected-warning@+2 {{inline nested namespace definition is incompatible with C++ standards before C++20}}
 #endif
 namespace valid1::valid2::inline valid3::inline valid4::valid5 {}
-// expected-note@-1 2 {{previous definition is here}}
+// expected-note@-1 4 {{

[PATCH] D121969: Pass split-machine-functions to code generator when flto is used

2022-03-22 Thread Junfeng Dong via Phabricator via cfe-commits
junfd updated this revision to Diff 417458.
junfd added a comment.

Apply clang format.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121969/new/

https://reviews.llvm.org/D121969

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/fsplit-machine-functions2.c


Index: clang/test/Driver/fsplit-machine-functions2.c
===
--- /dev/null
+++ clang/test/Driver/fsplit-machine-functions2.c
@@ -0,0 +1,12 @@
+// Test -fsplit-machine-functions option pass-through with lto
+// RUN: %clang -### -target x86_64-unknown-linux -flto 
-fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+
+// Test no pass-through to ld without lto
+// RUN: %clang -### -target x86_64-unknown-linux -fsplit-machine-functions %s 
2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
+
+// Test the mix of -fsplit-machine-functions and -fno-split-machine-functions
+// RUN: %clang -### -target x86_64-unknown-linux -flto 
-fsplit-machine-functions -fno-split-machine-functions %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-NOPASS
+// RUN: %clang -### -target x86_64-unknown-linux -flto 
-fno-split-machine-functions -fsplit-machine-functions %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-PASS
+
+// CHECK-PASS:  "-plugin-opt=-split-machine-functions"
+// CHECK-NOPASS-NOT:"-plugin-opt=-split-machine-functions"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -574,6 +574,13 @@
 CmdArgs.push_back("-plugin-opt=-data-sections");
   }
 
+  // Pass an option to enable split machine functions.
+  if (auto *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
+options::OPT_fno_split_machine_functions)) {
+if (A->getOption().matches(options::OPT_fsplit_machine_functions))
+  CmdArgs.push_back("-plugin-opt=-split-machine-functions");
+  }
+
   if (Arg *A = getLastProfileSampleUseArg(Args)) {
 StringRef FName = A->getValue();
 if (!llvm::sys::fs::exists(FName))


Index: clang/test/Driver/fsplit-machine-functions2.c
===
--- /dev/null
+++ clang/test/Driver/fsplit-machine-functions2.c
@@ -0,0 +1,12 @@
+// Test -fsplit-machine-functions option pass-through with lto
+// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+
+// Test no pass-through to ld without lto
+// RUN: %clang -### -target x86_64-unknown-linux -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
+
+// Test the mix of -fsplit-machine-functions and -fno-split-machine-functions
+// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions -fno-split-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
+// RUN: %clang -### -target x86_64-unknown-linux -flto -fno-split-machine-functions -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+
+// CHECK-PASS:  "-plugin-opt=-split-machine-functions"
+// CHECK-NOPASS-NOT:"-plugin-opt=-split-machine-functions"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -574,6 +574,13 @@
 CmdArgs.push_back("-plugin-opt=-data-sections");
   }
 
+  // Pass an option to enable split machine functions.
+  if (auto *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
+options::OPT_fno_split_machine_functions)) {
+if (A->getOption().matches(options::OPT_fsplit_machine_functions))
+  CmdArgs.push_back("-plugin-opt=-split-machine-functions");
+  }
+
   if (Arg *A = getLastProfileSampleUseArg(Args)) {
 StringRef FName = A->getValue();
 if (!llvm::sys::fs::exists(FName))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 818e72d - [NFC][Clang][OpaquePtr] Remove calls to Address::deprecated in

2022-03-22 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2022-03-22T18:39:16-07:00
New Revision: 818e72d1b09bc5fc3b7a2c9f90b981a9c0d2a5db

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

LOG: [NFC][Clang][OpaquePtr] Remove calls to Address::deprecated in
TargetInfo.cpp

Differential Revision: https://reviews.llvm.org/D122199

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 915ffca27bd1c..61d1444916150 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -100,6 +100,11 @@ Address ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address 
VAListAddr,
   return Address::invalid();
 }
 
+static llvm::Type *getVAListElementType(CodeGenFunction &CGF) {
+  return CGF.ConvertTypeForMem(
+  CGF.getContext().getBuiltinVaListType()->getPointeeType());
+}
+
 bool ABIInfo::isPromotableIntegerTypeForABI(QualType Ty) const {
   if (Ty->isPromotableIntegerType())
 return true;
@@ -375,7 +380,7 @@ static Address emitVoidPtrVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   }
 
   // Cast the address we've calculated to the right type.
-  llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy);
+  llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy), *ElementTy = DirectTy;
   if (IsIndirect)
 DirectTy = DirectTy->getPointerTo(0);
 
@@ -384,7 +389,7 @@ static Address emitVoidPtrVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
  SlotSizeAndAlign, AllowHigherAlign);
 
   if (IsIndirect) {
-Addr = Address::deprecated(CGF.Builder.CreateLoad(Addr), ValueInfo.Align);
+Addr = Address(CGF.Builder.CreateLoad(Addr), ElementTy, ValueInfo.Align);
   }
 
   return Addr;
@@ -688,11 +693,11 @@ Address EmitVAArgInstr(CodeGenFunction &CGF, Address 
VAListAddr, QualType Ty,
 auto TyInfo = CGF.getContext().getTypeInfoInChars(Ty);
 CharUnits TyAlignForABI = TyInfo.Align;
 
-llvm::Type *BaseTy =
-llvm::PointerType::getUnqual(CGF.ConvertTypeForMem(Ty));
+llvm::Type *ElementTy = CGF.ConvertTypeForMem(Ty);
+llvm::Type *BaseTy = llvm::PointerType::getUnqual(ElementTy);
 llvm::Value *Addr =
 CGF.Builder.CreateVAArg(VAListAddr.getPointer(), BaseTy);
-return Address::deprecated(Addr, TyAlignForABI);
+return Address(Addr, ElementTy, TyAlignForABI);
   } else {
 assert((AI.isDirect() || AI.isExtend()) &&
"Unexpected ArgInfo Kind in generic VAArg emitter!");
@@ -4826,7 +4831,7 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction 
&CGF, Address VAList,
 
   Builder.CreateCondBr(CC, UsingRegs, UsingOverflow);
 
-  llvm::Type *DirectTy = CGF.ConvertType(Ty);
+  llvm::Type *DirectTy = CGF.ConvertType(Ty), *ElementTy = DirectTy;
   if (isIndirect) DirectTy = DirectTy->getPointerTo(0);
 
   // Case 1: consume registers.
@@ -4835,8 +4840,8 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction 
&CGF, Address VAList,
 CGF.EmitBlock(UsingRegs);
 
 Address RegSaveAreaPtr = Builder.CreateStructGEP(VAList, 4);
-RegAddr = Address::deprecated(Builder.CreateLoad(RegSaveAreaPtr),
-  CharUnits::fromQuantity(8));
+RegAddr = Address(Builder.CreateLoad(RegSaveAreaPtr), CGF.Int8Ty,
+  CharUnits::fromQuantity(8));
 assert(RegAddr.getElementType() == CGF.Int8Ty);
 
 // Floating-point registers start after the general-purpose registers.
@@ -4883,14 +4888,15 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction 
&CGF, Address VAList,
 }
 
 Address OverflowAreaAddr = Builder.CreateStructGEP(VAList, 3);
-Address OverflowArea = Address::deprecated(
-Builder.CreateLoad(OverflowAreaAddr, "argp.cur"), OverflowAreaAlign);
+Address OverflowArea =
+Address(Builder.CreateLoad(OverflowAreaAddr, "argp.cur"), CGF.Int8Ty,
+OverflowAreaAlign);
 // Round up address of argument to alignment
 CharUnits Align = CGF.getContext().getTypeAlignInChars(Ty);
 if (Align > OverflowAreaAlign) {
   llvm::Value *Ptr = OverflowArea.getPointer();
-  OverflowArea = Address::deprecated(
-  emitRoundPointerUpToAlignment(CGF, Ptr, Align), Align);
+  OverflowArea = Address(emitRoundPointerUpToAlignment(CGF, Ptr, Align),
+ OverflowArea.getElementType(), Align);
 }
 
 MemAddr = Builder.CreateElementBitCast(OverflowArea, DirectTy);
@@ -4909,8 +4915,8 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction 
&CGF, Address VAList,
 
   // Load the pointer if the argument was passed indirectly.
   if (isIndirect) {
-Result = Address::deprecated(Builder.CreateLoad(Result, "aggr"),
- getContext().getTypeAlignInChars(Ty));
+Result = Address(

[PATCH] D122199: [NFC][Clang][OpaquePtr] Remove calls to Address::deprecated in TargetInfo.cpp

2022-03-22 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG818e72d1b09b: [NFC][Clang][OpaquePtr] Remove calls to 
Address::deprecated in (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122199/new/

https://reviews.llvm.org/D122199

Files:
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -100,6 +100,11 @@
   return Address::invalid();
 }
 
+static llvm::Type *getVAListElementType(CodeGenFunction &CGF) {
+  return CGF.ConvertTypeForMem(
+  CGF.getContext().getBuiltinVaListType()->getPointeeType());
+}
+
 bool ABIInfo::isPromotableIntegerTypeForABI(QualType Ty) const {
   if (Ty->isPromotableIntegerType())
 return true;
@@ -375,7 +380,7 @@
   }
 
   // Cast the address we've calculated to the right type.
-  llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy);
+  llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy), *ElementTy = DirectTy;
   if (IsIndirect)
 DirectTy = DirectTy->getPointerTo(0);
 
@@ -384,7 +389,7 @@
  SlotSizeAndAlign, AllowHigherAlign);
 
   if (IsIndirect) {
-Addr = Address::deprecated(CGF.Builder.CreateLoad(Addr), ValueInfo.Align);
+Addr = Address(CGF.Builder.CreateLoad(Addr), ElementTy, ValueInfo.Align);
   }
 
   return Addr;
@@ -688,11 +693,11 @@
 auto TyInfo = CGF.getContext().getTypeInfoInChars(Ty);
 CharUnits TyAlignForABI = TyInfo.Align;
 
-llvm::Type *BaseTy =
-llvm::PointerType::getUnqual(CGF.ConvertTypeForMem(Ty));
+llvm::Type *ElementTy = CGF.ConvertTypeForMem(Ty);
+llvm::Type *BaseTy = llvm::PointerType::getUnqual(ElementTy);
 llvm::Value *Addr =
 CGF.Builder.CreateVAArg(VAListAddr.getPointer(), BaseTy);
-return Address::deprecated(Addr, TyAlignForABI);
+return Address(Addr, ElementTy, TyAlignForABI);
   } else {
 assert((AI.isDirect() || AI.isExtend()) &&
"Unexpected ArgInfo Kind in generic VAArg emitter!");
@@ -4826,7 +4831,7 @@
 
   Builder.CreateCondBr(CC, UsingRegs, UsingOverflow);
 
-  llvm::Type *DirectTy = CGF.ConvertType(Ty);
+  llvm::Type *DirectTy = CGF.ConvertType(Ty), *ElementTy = DirectTy;
   if (isIndirect) DirectTy = DirectTy->getPointerTo(0);
 
   // Case 1: consume registers.
@@ -4835,8 +4840,8 @@
 CGF.EmitBlock(UsingRegs);
 
 Address RegSaveAreaPtr = Builder.CreateStructGEP(VAList, 4);
-RegAddr = Address::deprecated(Builder.CreateLoad(RegSaveAreaPtr),
-  CharUnits::fromQuantity(8));
+RegAddr = Address(Builder.CreateLoad(RegSaveAreaPtr), CGF.Int8Ty,
+  CharUnits::fromQuantity(8));
 assert(RegAddr.getElementType() == CGF.Int8Ty);
 
 // Floating-point registers start after the general-purpose registers.
@@ -4883,14 +4888,15 @@
 }
 
 Address OverflowAreaAddr = Builder.CreateStructGEP(VAList, 3);
-Address OverflowArea = Address::deprecated(
-Builder.CreateLoad(OverflowAreaAddr, "argp.cur"), OverflowAreaAlign);
+Address OverflowArea =
+Address(Builder.CreateLoad(OverflowAreaAddr, "argp.cur"), CGF.Int8Ty,
+OverflowAreaAlign);
 // Round up address of argument to alignment
 CharUnits Align = CGF.getContext().getTypeAlignInChars(Ty);
 if (Align > OverflowAreaAlign) {
   llvm::Value *Ptr = OverflowArea.getPointer();
-  OverflowArea = Address::deprecated(
-  emitRoundPointerUpToAlignment(CGF, Ptr, Align), Align);
+  OverflowArea = Address(emitRoundPointerUpToAlignment(CGF, Ptr, Align),
+ OverflowArea.getElementType(), Align);
 }
 
 MemAddr = Builder.CreateElementBitCast(OverflowArea, DirectTy);
@@ -4909,8 +4915,8 @@
 
   // Load the pointer if the argument was passed indirectly.
   if (isIndirect) {
-Result = Address::deprecated(Builder.CreateLoad(Result, "aggr"),
- getContext().getTypeAlignInChars(Ty));
+Result = Address(Builder.CreateLoad(Result, "aggr"), ElementTy,
+ getContext().getTypeAlignInChars(Ty));
   }
 
   return Result;
@@ -6060,7 +6066,7 @@
   Address BaseAddr(CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, reg_top, reg_offs),
CGF.Int8Ty, CharUnits::fromQuantity(IsFPR ? 16 : 8));
   Address RegAddr = Address::invalid();
-  llvm::Type *MemTy = CGF.ConvertTypeForMem(Ty);
+  llvm::Type *MemTy = CGF.ConvertTypeForMem(Ty), *ElementTy = MemTy;
 
   if (IsIndirect) {
 // If it's been passed indirectly (actually a struct), whatever we find from
@@ -6143,8 +6149,8 @@
 
 OnStackPtr = CGF.Builder.CreateIntToPtr(OnStackPtr, CGF.Int8PtrTy);
   }
-  Address OnStackAddr = Address::deprecated(
-  OnStackPtr, std::max(CharUnits::fromQuantity(8), TyAlign));
+  Add

[PATCH] D115248: [Clang] Fix PR28101

2022-03-22 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao updated this revision to Diff 417461.
rZhBoYao retitled this revision from "[clang] Fix PR28101" to "[Clang] Fix 
PR28101".
rZhBoYao edited the summary of this revision.
rZhBoYao added a reviewer: cor3ntin.
rZhBoYao set the repository for this revision to rG LLVM Github Monorepo.
rZhBoYao added a comment.
Herald added a project: All.

The previous diff was indeed very specific and doesn't handle

  template 
  struct A {
A(void*) {}
T A{}; // expected-error{{member 'A' cannot have template arguments}}
  };
  
  A instantiate() { return {nullptr}; }

I have since realized the invalid decorator is the problem and the parentheses 
are insignificant. It's like:

  template  struct S {};
  int S{};

which gcc diagnoses to

> error: invalid declarator before '{' token

Then I found there was a new diagnostic added by D120881 
. So the fix is pretty straightforward at 
this point. I simply stand on the shoulder of the giant and set the invalid 
flag of the declarator.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115248/new/

https://reviews.llvm.org/D115248

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/PR28101.cpp


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template 
+struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template 
+struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template 
+struct S {};
+
+template 
+struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U>
+class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template 
arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}
+};
+
+template 
+struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,7 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template 
+struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template 
+struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template 
+struct S {};
+
+template 
+struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U>
+class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}
+};
+
+template 
+struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,7 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6edfe45 - [AVR] Add more devices

2022-03-22 Thread Ben Shi via cfe-commits

Author: Ben Shi
Date: 2022-03-23T02:00:15Z
New Revision: 6edfe45a63125a8938a5bea13534a118b0e31023

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

LOG: [AVR] Add more devices

Synchronize AVR device lists with gcc-avr-5.4.0 and avr-libc-2.0.0.

Reviewed By: dylanmckay, aykevl

Differential Revision: https://reviews.llvm.org/D121359

Added: 


Modified: 
clang/lib/Basic/Targets/AVR.cpp
clang/lib/Driver/ToolChains/AVR.cpp
clang/test/Misc/target-invalid-cpu-note.c
llvm/lib/Target/AVR/AVRDevices.td

Removed: 




diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index 6266ed72cd5c0..dfc98c3d085d9 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -27,7 +27,7 @@ struct LLVM_LIBRARY_VISIBILITY MCUInfo {
   const int NumFlashBanks; // -1 means the device does not support LPM/ELPM.
 };
 
-// This list should be kept up-to-date with AVRDevices.td in LLVM.
+// NOTE: This list has been synchronized with gcc-avr 5.4.0 and avr-libc 2.0.0.
 static MCUInfo AVRMcus[] = {
 {"at90s1200", "__AVR_AT90S1200__", 0},
 {"attiny11", "__AVR_ATtiny11__", 0},
@@ -83,6 +83,8 @@ static MCUInfo AVRMcus[] = {
 {"at90usb82", "__AVR_AT90USB82__", 1},
 {"at90usb162", "__AVR_AT90USB162__", 1},
 {"ata5505", "__AVR_ATA5505__", 1},
+{"ata6617c", "__AVR_ATA6617C__", 1},
+{"ata664251", "__AVR_ATA664251__", 1},
 {"atmega8u2", "__AVR_ATmega8U2__", 1},
 {"atmega16u2", "__AVR_ATmega16U2__", 1},
 {"atmega32u2", "__AVR_ATmega32U2__", 1},
@@ -92,6 +94,7 @@ static MCUInfo AVRMcus[] = {
 {"atmega8a", "__AVR_ATmega8A__", 1},
 {"ata6285", "__AVR_ATA6285__", 1},
 {"ata6286", "__AVR_ATA6286__", 1},
+{"ata6612c", "__AVR_ATA6612C__", 1},
 {"atmega48", "__AVR_ATmega48__", 1},
 {"atmega48a", "__AVR_ATmega48A__", 1},
 {"atmega48pa", "__AVR_ATmega48PA__", 1},
@@ -111,8 +114,17 @@ static MCUInfo AVRMcus[] = {
 {"at90pwm3", "__AVR_AT90PWM3__", 1},
 {"at90pwm3b", "__AVR_AT90PWM3B__", 1},
 {"at90pwm81", "__AVR_AT90PWM81__", 1},
+{"ata5702m322", "__AVR_ATA5702M322__", 1},
+{"ata5782", "__AVR_ATA5782__", 1},
 {"ata5790", "__AVR_ATA5790__", 1},
+{"ata5790n", "__AVR_ATA5790N__", 1},
+{"ata5791", "__AVR_ATA5791__", 1},
 {"ata5795", "__AVR_ATA5795__", 1},
+{"ata5831", "__AVR_ATA5831__", 1},
+{"ata6613c", "__AVR_ATA6613C__", 1},
+{"ata6614q", "__AVR_ATA6614Q__", 1},
+{"ata8210", "__AVR_ATA8210__", 1},
+{"ata8510", "__AVR_ATA8510__", 1},
 {"atmega16", "__AVR_ATmega16__", 1},
 {"atmega16a", "__AVR_ATmega16A__", 1},
 {"atmega161", "__AVR_ATmega161__", 1},
@@ -189,6 +201,7 @@ static MCUInfo AVRMcus[] = {
 {"atmega32hvb", "__AVR_ATmega32HVB__", 1},
 {"atmega32hvbrevb", "__AVR_ATmega32HVBREVB__", 1},
 {"atmega64hve", "__AVR_ATmega64HVE__", 1},
+{"atmega64hve2", "__AVR_ATmega64HVE2__", 1},
 {"at90can32", "__AVR_AT90CAN32__", 1},
 {"at90can64", "__AVR_AT90CAN64__", 1},
 {"at90pwm161", "__AVR_AT90PWM161__", 1},
@@ -229,7 +242,9 @@ static MCUInfo AVRMcus[] = {
 {"atxmega16d4", "__AVR_ATxmega16D4__", 1},
 {"atxmega32a4", "__AVR_ATxmega32A4__", 1},
 {"atxmega32a4u", "__AVR_ATxmega32A4U__", 1},
+{"atxmega32c3", "__AVR_ATxmega32C3__", 1},
 {"atxmega32c4", "__AVR_ATxmega32C4__", 1},
+{"atxmega32d3", "__AVR_ATxmega32D3__", 1},
 {"atxmega32d4", "__AVR_ATxmega32D4__", 1},
 {"atxmega32e5", "__AVR_ATxmega32E5__", 1},
 {"atxmega16e5", "__AVR_ATxmega16E5__", 1},

diff  --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 2cf16cf9fdb49..5577c709a09fc 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -28,6 +28,7 @@ using namespace llvm::opt;
 
 namespace {
 
+// NOTE: This list has been synchronized with gcc-avr 5.4.0 and avr-libc 2.0.0.
 constexpr struct {
   StringRef Name;
   StringRef SubPath;
@@ -88,6 +89,8 @@ constexpr struct {
 {"at90usb82", "avr35", "avr35", 0x800100},
 {"at90usb162", "avr35", "avr35", 0x800100},
 {"ata5505", "avr35", "avr35", 0x800100},
+{"ata6617c", "avr35", "avr35", 0x800100},
+{"ata664251", "avr35", "avr35", 0x800100},
 {"atmega8u2", "avr35", "avr35", 0x800100},
 {"atmega16u2", "avr35", "avr35", 0x800100},
 {"atmega32u2", "avr35", "avr35", 0x800100},
@@ -97,6 +100,7 @@ constexpr struct {
 {"atmega8a", "avr4", "avr4", 0x800060},
 {"ata6285", "avr4", "avr4", 0x800100},
 {"ata6286", "avr4", "avr4", 0x800100},
+{"ata6612c", "avr4", "avr4", 0x800100},
 {"atmega48", "avr4", "avr4", 0x800100},
 {"atmega48a", "avr4", "avr4", 0x800100},
 {"atmega48pa", "avr4", "avr4", 0x800100},
@@ -116,8 +120,17 @@ constexpr struct {
 {"at90pwm3", "avr4

[PATCH] D121359: [AVR] Add more devices

2022-03-22 Thread Ben Shi via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6edfe45a6312: [AVR] Add more devices (authored by benshi001).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121359/new/

https://reviews.llvm.org/D121359

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/lib/Target/AVR/AVRDevices.td

Index: llvm/lib/Target/AVR/AVRDevices.td
===
--- llvm/lib/Target/AVR/AVRDevices.td
+++ llvm/lib/Target/AVR/AVRDevices.td
@@ -245,6 +245,7 @@
 def : Device<"avrtiny", FamilyTiny, ELFArchTiny>;
 
 // Specific MCUs
+// NOTE: This list has been synchronized with gcc-avr 5.4.0 and avr-libc 2.0.0.
 def : Device<"at90s1200", FamilyAVR0, ELFArchAVR1>;
 def : Device<"attiny11", FamilyAVR1, ELFArchAVR1>;
 def : Device<"attiny12", FamilyAVR1, ELFArchAVR1>;
@@ -299,6 +300,8 @@
 def : Device<"at90usb82", FamilyAVR35, ELFArchAVR35>;
 def : Device<"at90usb162", FamilyAVR35, ELFArchAVR35>;
 def : Device<"ata5505", FamilyAVR35, ELFArchAVR35>;
+def : Device<"ata6617c", FamilyAVR35, ELFArchAVR35>;
+def : Device<"ata664251", FamilyAVR35, ELFArchAVR35>;
 def : Device<"atmega8u2", FamilyAVR35, ELFArchAVR35>;
 def : Device<"atmega16u2", FamilyAVR35, ELFArchAVR35>;
 def : Device<"atmega32u2", FamilyAVR35, ELFArchAVR35>;
@@ -310,6 +313,7 @@
  [FeatureMultiplication, FeatureMOVW, FeatureLPMX, FeatureSPM]>;
 def : Device<"ata6285", FamilyAVR4, ELFArchAVR4>;
 def : Device<"ata6286", FamilyAVR4, ELFArchAVR4>;
+def : Device<"ata6612c", FamilyAVR4, ELFArchAVR4>;
 def : Device<"atmega48", FamilyAVR4, ELFArchAVR4>;
 def : Device<"atmega48a", FamilyAVR4, ELFArchAVR4>;
 def : Device<"atmega48pa", FamilyAVR4, ELFArchAVR4>;
@@ -331,8 +335,17 @@
 def : Device<"at90pwm3", FamilyAVR4, ELFArchAVR4>;
 def : Device<"at90pwm3b", FamilyAVR4, ELFArchAVR4>;
 def : Device<"at90pwm81", FamilyAVR4, ELFArchAVR4>;
+def : Device<"ata5702m322", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata5782", FamilyAVR5, ELFArchAVR5>;
 def : Device<"ata5790", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata5790n", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata5791", FamilyAVR5, ELFArchAVR5>;
 def : Device<"ata5795", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata5831", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata6613c", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata6614q", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata8210", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata8510", FamilyAVR5, ELFArchAVR5>;
 def : Device<"atmega16", FamilyAVR5, ELFArchAVR5>;
 def : Device<"atmega16a", FamilyAVR5, ELFArchAVR5>;
 def : Device<"atmega161", FamilyAVR3, ELFArchAVR5,
@@ -411,6 +424,7 @@
 def : Device<"atmega32hvb", FamilyAVR5, ELFArchAVR5>;
 def : Device<"atmega32hvbrevb", FamilyAVR5, ELFArchAVR5>;
 def : Device<"atmega64hve", FamilyAVR5, ELFArchAVR5>;
+def : Device<"atmega64hve2", FamilyAVR5, ELFArchAVR5>;
 def : Device<"at90can32", FamilyAVR5, ELFArchAVR5>;
 def : Device<"at90can64", FamilyAVR5, ELFArchAVR5>;
 def : Device<"at90pwm161", FamilyAVR5, ELFArchAVR5>;
@@ -452,7 +466,9 @@
 def : Device<"atxmega16d4", FamilyXMEGA, ELFArchXMEGA2>;
 def : Device<"atxmega32a4", FamilyXMEGA, ELFArchXMEGA2>;
 def : Device<"atxmega32a4u", FamilyXMEGAU, ELFArchXMEGA2>;
+def : Device<"atxmega32c3", FamilyXMEGAU, ELFArchXMEGA2>;
 def : Device<"atxmega32c4", FamilyXMEGAU, ELFArchXMEGA2>;
+def : Device<"atxmega32d3", FamilyXMEGA, ELFArchXMEGA2>;
 def : Device<"atxmega32d4", FamilyXMEGA, ELFArchXMEGA2>;
 def : Device<"atxmega32e5", FamilyXMEGAU, ELFArchXMEGA2>;
 def : Device<"atxmega16e5", FamilyXMEGAU, ELFArchXMEGA2>;
Index: clang/test/Misc/target-invalid-cpu-note.c
===
--- clang/test/Misc/target-invalid-cpu-note.c
+++ clang/test/Misc/target-invalid-cpu-note.c
@@ -77,7 +77,7 @@
 
 // RUN: not %clang_cc1 -triple avr--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AVR
 // AVR: error: unknown target CPU 'not-a-cpu'
-// AVR-NEXT: note: valid target CPU values are: avr1, avr2, avr25, avr3, avr31, avr35, avr4, avr5, avr51, avr6, avrxmega1, avrxmega2, avrxmega3, avrxmega4, avrxmega5, avrxmega6, avrxmega7, avrtiny, at90s1200, attiny11, attiny12, attiny15, attiny28, at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26, at86rf401, at90s4414, at90s4433, at90s4434, at90s8515, at90c8534, at90s8535, ata5272, attiny13, attiny13a, attiny2313, attiny2313a, attiny24, attiny24a, attiny4313, attiny44, attiny44a, attiny84, attiny84a, attiny25, attiny45, attiny85, attiny261, attiny261a, attiny441, attiny461, attiny461a, attiny841, attiny861, attiny861a, attiny87, attiny43u, attiny48, attiny88, attiny828, at43usb355, at76c711, atmega103, at43usb320, attiny167, at90usb82, at90usb162, ata5505, atmega8u2, atmega16u2, atmega32u2, attiny1634, atmega8, ata6289, atmeg

[PATCH] D118525: [modules] Merge ObjC interface ivars with anonymous types.

2022-03-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 417468.
vsapsai added a comment.

Fix bug with anonymous enum constant lookup in C++.

Turns out the lookup was broken by using `ObjCInterfaceDecl` as a semantic decl
context for anonymous enums. Fixing that fixed the lookup.

Also added in tests checking scoped enums in C++. Scoped enums cannot be
anonymous, so test only named enum definitions inside Objective-C code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118525/new/

https://reviews.llvm.org/D118525

Files:
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/AST/ast-dump-decl.mm
  clang/test/Modules/merge-anon-record-definition-in-objc.m
  clang/test/SemaObjC/check-dup-decls-inside-objc.m

Index: clang/test/SemaObjC/check-dup-decls-inside-objc.m
===
--- /dev/null
+++ clang/test/SemaObjC/check-dup-decls-inside-objc.m
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class -x objective-c++ %s
+
+// Test decls inside Objective-C entities are considered to be duplicates of same-name decls outside of these entities.
+
+@protocol SomeProtocol
+struct InProtocol {}; // expected-note {{previous definition is here}}
+- (union MethodReturnType { int x; float y; })returningMethod; // expected-note {{previous definition is here}}
+#ifdef __cplusplus
+// expected-error@-2 {{'MethodReturnType' cannot be defined in a parameter type}}
+#endif
+@end
+
+@interface Container {
+  struct InInterfaceCurliesWithField {} field; // expected-note {{previous definition is here}}
+  union InInterfaceCurlies { int x; float y; }; // expected-note {{previous definition is here}}
+}
+enum InInterface { kX = 0, }; // expected-note {{previous definition is here}}
+#ifdef __cplusplus
+enum class InInterfaceScoped { kXScoped = 0, }; // expected-note {{previous definition is here}}
+#endif
+@end
+
+@interface Container(Category)
+union InCategory { int x; float y; }; // expected-note {{previous definition is here}}
+@end
+
+@interface Container() {
+  enum InExtensionCurliesWithField: int { kY = 1, } extensionField; // expected-note {{previous definition is here}}
+  struct InExtensionCurlies {}; // expected-note {{previous definition is here}}
+}
+union InExtension { int x; float y; }; // expected-note {{previous definition is here}}
+@end
+
+@implementation Container {
+  union InImplementationCurliesWithField { int x; float y; } implField; // expected-note {{previous definition is here}}
+  enum InImplementationCurlies { kZ = 2, }; // expected-note {{previous definition is here}}
+}
+struct InImplementation {}; // expected-note {{previous definition is here}}
+@end
+
+@implementation Container(Category)
+enum InCategoryImplementation { kW = 3, }; // expected-note {{previous definition is here}}
+@end
+
+
+struct InProtocol { int a; }; // expected-error {{redefinition of 'InProtocol'}}
+union MethodReturnType { int a; long b; }; // expected-error {{redefinition of 'MethodReturnType'}}
+
+struct InInterfaceCurliesWithField { int a; }; // expected-error {{redefinition of 'InInterfaceCurliesWithField'}}
+union InInterfaceCurlies { int a; long b; }; // expected-error {{redefinition of 'InInterfaceCurlies'}}
+enum InInterface { kA = 10, }; // expected-error {{redefinition of 'InInterface'}}
+#ifdef __cplusplus
+enum class InInterfaceScoped { kAScoped = 10, }; // expected-error {{redefinition of 'InInterfaceScoped'}}
+#endif
+
+union InCategory { int a; long b; }; // expected-error {{redefinition of 'InCategory'}}
+
+enum InExtensionCurliesWithField: int { kB = 11, }; // expected-error {{redefinition of 'InExtensionCurliesWithField'}}
+struct InExtensionCurlies { int a; }; // expected-error {{redefinition of 'InExtensionCurlies'}}
+union InExtension { int a; long b; }; // expected-error {{redefinition of 'InExtension'}}
+
+union InImplementationCurliesWithField { int a; long b; }; // expected-error {{redefinition of 'InImplementationCurliesWithField'}}
+enum InImplementationCurlies { kC = 12, }; // expected-error {{redefinition of 'InImplementationCurlies'}}
+struct InImplementation { int a; }; // expected-error {{redefinition of 'InImplementation'}}
+
+enum InCategoryImplementation { kD = 13, }; // expected-error {{redefinition of 'InCategoryImplementation'}}
Index: clang/test/Modules/merge-anon-record-definition-in-objc.m
===
--- /dev/null
+++ clang/test/Modules/merge-anon-record-definition-in-objc.m
@@ -0,0 +1,84 @@
+// UNSUPPORTED: -zos, -aix
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -fsyntax-only -F%t/Frameworks %t/test.m -Wno-objc-property-implementation -Wno-incomplete-implementation \
+// RUN:-fmodules -fmodule-name=Target -fimplicit-modul

[PATCH] D121176: [ASTStructuralEquivalence] Add support for comparing ObjCCategoryDecl.

2022-03-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

@shafik, can you please check the patch? Or maybe recommend somebody who worked 
both on ASTStructuralEquivalence and Objective-C part of clang?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121176/new/

https://reviews.llvm.org/D121176

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


[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-22 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.

LGTM too!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121812/new/

https://reviews.llvm.org/D121812

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


[PATCH] D122119: [C++20][Modules] Adjust handling of exports of namespaces and using-decls.

2022-03-22 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D122119#3400032 , @urnathan wrote:

> In D122119#3398949 , @ChuanqiXu 
> wrote:
>
>> 
>
>
>
>> The first feeling I saw the change is that not every C++ programmer knows 
>> about linkage. OK, it depends on the environment really and every one might 
>> has their own opinion.
>
> You may be confusing object-file linkage with the linkage concepts of C++, 
> which are specified in [basic.link]?  Sadly we have to live with the 
> overloaded term.
>
>> Another thought is that 10.2.6 (http://eel.is/c++draft/module.interface#6) 
>> doesn't talk anything about linkage:
>>
>>> A redeclaration of an entity X is implicitly exported if X was introduced 
>>> by an exported declaration; otherwise it shall not be exported.
>>
>> So it looks like confusing to talk about linkage this time. In my 
>> imagination, there might be a such situation:
>>
>> A programmer met the error when he tries to export a redeclaration which is 
>> internal linkage (maybe a simple const variable). Then the message told him 
>> the internal linkage is not allowed to re-export. Then he removes the const 
>> specifier. Now he meets the error again. It tells that we couldn't export 
>> redeclaration which is module linkage. I guess he would feel bad. Then he 
>> might try to export the first declaration to get passed. However, the 
>> `const` specifier is lost in the case. And in the current message, I guess 
>> he would add export to the first declaration directly after he reads the 
>> message.
>
> further, with attachment, the original error 'cannot export as previous was 
> not exported' is not correct in general.  Consider:
>
> module;
> // Pretend this is from #include, ok?
> void Foo ();
> module bob;
> extern "C++" export void Foo ();  // can export even though prior was not 
> exported

I think the example is invalid since it violates [[ 
http://eel.is/c++draft/module.interface#6 | [module.interface]p6 ]] explicitly. 
If this is intended behavior or by design, we should change the wording.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122119/new/

https://reviews.llvm.org/D122119

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


[PATCH] D115248: [Clang] Fix PR28101

2022-03-22 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao updated this revision to Diff 417475.
rZhBoYao added a comment.

Don't break template declarations.
re-clang-format


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115248/new/

https://reviews.llvm.org/D115248

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/PR28101.cpp


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template  struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template  struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template  struct S {};
+
+template  struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U> class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template 
arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}
+};
+
+template  struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,7 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template  struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template  struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template  struct S {};
+
+template  struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U> class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}
+};
+
+template  struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,7 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119409: [C++20] [Modules] Remain dynamic initializing internal-linkage variables in module interface unit

2022-03-22 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a subscriber: urnathan.
ChuanqiXu added a comment.

In D119409#3400287 , @dblaikie wrote:

> In D119409#3398483 , @ChuanqiXu 
> wrote:
>
>> In D119409#3396690 , @dblaikie 
>> wrote:
>>
>>> Not even necessarily then - if you have code like protobufs (large amounts 
>>> of autogenerated code, much of which you might never call) - or even just 
>>> libraries where you only use a subset of their features - then you might 
>>> have more code generated with an inline-function-homing
>>
>> From the perspective of code size, it would be larger in 
>> inline-function-homing strategies in cases you described. But I guess it 
>> wouldn't hurt in compilation speed, is it?
>
> Depending on optimizations, some amount of compilation time is proportional 
> to code size.

Yeah, I am not strict enough. I mean the compilation time of the importee 
wouldn't be hurt. The compilation time of the module itself would be more of 
course. Given the module is imported in many places, it would be a win. But if 
it is not, then it might be a bad idea.
So the conclusion would be that inline-function-homing wouldn't be a pure win 
all the time.  I just want to say it might be a win in a lot of cases.

>> For the consideration of code size, I think we could mitigate the problem by 
>> thinLTO. (Although we couldn't solve the problem completely since thinLTO 
>> couldn't help for *.o, *.a and *.so files.)
>
> Yep. But with ThinLTO we wouldn't need to produce `available_externally` 
> definitions anyway, since ThinLTO can cross-object import anyway.

Yeah. My point is that with the inline-function-homing strategy, we could not 
produce `available_externally`  functions in the frontend so that we could get 
a big compilation speedup. In some of my experiments, the speed could be 5x 
than before : ) It is exciting.

>>> Possibly - there's still the possibility that even without any importing (& 
>>> just homing into the module object file) that it'll cost more than it 
>>> benefits due to inline functions that are never called.
>>
>> Yeah, I met the situation before. In a simple case, that the time spent on 
>> the deserialization looks more than the time we saved. By from my experience 
>> (my experience is not complete though), this kind of cases is relatively 
>> small.
>>
>> ---
>>
>> @dblaikie given that the talk involves further optimization, which is beyond 
>> the scope of current patch. Would you like to accept this one?
>
> I don't have enough context for the current state of this patch - might be 
> useful to post a summary of the current state?

Yeah. Let me try to give a summary. The intention of the patch is fix the 
following problem:

  // Hello.cppm
  module;
  #include 
  export module Hello;
  export void SayHello()
  {
  std::printf("Hello World.\n");
  
  }
  // main.cpp
  import Hello;
  int main() {
 SayHello();
 return 0;
  }

The program compiled in this way would met a segment fault at run time if it 
uses libstdc++. The root cause is that libstdc++ uses the constructor of the 
following static variable to do resources initializations.

  // For construction of filebuffers for cout, cin, cerr, clog et. al.
  static ios_base::Init __ioinit;

And in the original implementation, the static variable (with internal linkage) 
is considered invisible to the outside so it wouldn't be generated in the PCM 
(the binary form of AST).

To solve the problem, the patch intends to remain the static variable (or say, 
variable with internal linkage). Then @urnathan pointed that we should only 
generate the static variables with dynamic initializer. Then this is the 
current status of patch.

Although the discuss is very long, almost of them talks about the 
inline-function-strategy. We talked a lot about that whether it is valid or 
whether it is useful. But all of them are beyond the scope of the patch : )


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119409/new/

https://reviews.llvm.org/D119409

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


[PATCH] D120874: [C++20] [Modules] Use '-' as the separator of partitions when searching in filesystems

2022-03-22 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@iains  ping~


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120874/new/

https://reviews.llvm.org/D120874

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


[PATCH] D107141: [Inline-asm] Add diagnosts for unsupported inline assembly arguments

2022-03-22 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 accepted this revision.
jyu2 added a comment.
This revision is now accepted and ready to land.

This is okay with me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107141/new/

https://reviews.llvm.org/D107141

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


[PATCH] D107141: [Inline-asm] Add diagnosts for unsupported inline assembly arguments

2022-03-22 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Thanks @jyu2 !


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107141/new/

https://reviews.llvm.org/D107141

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


[PATCH] D120397: [C++20] [Modules] Make the linkage consistent for template and its specialization

2022-03-22 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 417479.
ChuanqiXu added a comment.

Address comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120397/new/

https://reviews.llvm.org/D120397

Files:
  clang/lib/AST/Decl.cpp
  clang/unittests/AST/DeclTest.cpp


Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -171,3 +171,26 @@
   selectFirst("f", match(functionDecl().bind("f"), Ctx));
   EXPECT_TRUE(f->isInExportDeclContext());
 }
+
+TEST(Decl, InConsistLinkageForTemplates) {
+  llvm::Annotations Code(R"(
+export module m;
+export template 
+void f() {}
+
+template <>
+void f() {})");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  llvm::SmallVector Funcs =
+  match(functionDecl().bind("f"), Ctx);
+
+  EXPECT_EQ(Funcs.size(), 2);
+  const FunctionDecl *TemplateF = Funcs[0].getNodeAs("f");
+  const FunctionDecl *SpecializedF = Funcs[1].getNodeAs("f");
+  EXPECT_EQ(TemplateF->getLinkageInternal(),
+SpecializedF->getLinkageInternal());
+}
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -391,11 +391,18 @@
   bool considerVisibility =
 shouldConsiderTemplateVisibility(fn, specInfo);
 
-  // Merge information from the template parameters.
   FunctionTemplateDecl *temp = specInfo->getTemplate();
-  LinkageInfo tempLV =
-getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
-  LV.mergeMaybeWithVisibility(tempLV, considerVisibility);
+
+  // Merge information from the template declaration.
+  LinkageInfo tempLV = getLVForDecl(temp, computation);
+  // The linkage of the specialization should be consistent with the
+  // template declaration.
+  LV.setLinkage(tempLV.getLinkage());
+
+  // Merge information from the template parameters.
+  LinkageInfo paramsLV =
+  getLVForTemplateParameterList(temp->getTemplateParameters(), 
computation);
+  LV.mergeMaybeWithVisibility(paramsLV, considerVisibility);
 
   // Merge information from the template arguments.
   const TemplateArgumentList &templateArgs = *specInfo->TemplateArguments;


Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -171,3 +171,26 @@
   selectFirst("f", match(functionDecl().bind("f"), Ctx));
   EXPECT_TRUE(f->isInExportDeclContext());
 }
+
+TEST(Decl, InConsistLinkageForTemplates) {
+  llvm::Annotations Code(R"(
+export module m;
+export template 
+void f() {}
+
+template <>
+void f() {})");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  llvm::SmallVector Funcs =
+  match(functionDecl().bind("f"), Ctx);
+
+  EXPECT_EQ(Funcs.size(), 2);
+  const FunctionDecl *TemplateF = Funcs[0].getNodeAs("f");
+  const FunctionDecl *SpecializedF = Funcs[1].getNodeAs("f");
+  EXPECT_EQ(TemplateF->getLinkageInternal(),
+SpecializedF->getLinkageInternal());
+}
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -391,11 +391,18 @@
   bool considerVisibility =
 shouldConsiderTemplateVisibility(fn, specInfo);
 
-  // Merge information from the template parameters.
   FunctionTemplateDecl *temp = specInfo->getTemplate();
-  LinkageInfo tempLV =
-getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
-  LV.mergeMaybeWithVisibility(tempLV, considerVisibility);
+
+  // Merge information from the template declaration.
+  LinkageInfo tempLV = getLVForDecl(temp, computation);
+  // The linkage of the specialization should be consistent with the
+  // template declaration.
+  LV.setLinkage(tempLV.getLinkage());
+
+  // Merge information from the template parameters.
+  LinkageInfo paramsLV =
+  getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
+  LV.mergeMaybeWithVisibility(paramsLV, considerVisibility);
 
   // Merge information from the template arguments.
   const TemplateArgumentList &templateArgs = *specInfo->TemplateArguments;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120397: [C++20] [Modules] Make the linkage consistent for template and its specialization

2022-03-22 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked an inline comment as done.
ChuanqiXu added a comment.

In D120397#3399808 , @aaron.ballman 
wrote:

> Can you also add a release note that explains we've fixed the crash?

My thought is to edit a release note standalone. Since there are already many 
works in modules now. I guess it might be better to try to give a summarize.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120397/new/

https://reviews.llvm.org/D120397

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


[PATCH] D121868: [cc1as] Add support for emitting the build version load command for -darwin-target-variant

2022-03-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.
Herald added a subscriber: StephenFan.

This may need a test in `clang/test/Misc/cc1as-*`.

Can you add to the description what the `clang -cc1as` usage looks like?




Comment at: clang/tools/driver/cc1as_main.cpp:217
+llvm::Triple TVT(A->getValue());
+Opts.DarwinTargetVariantTriple = TVT;
+  }





Comment at: clang/tools/driver/cc1as_main.cpp:419
+  if (Opts.DarwinTargetVariantTriple) {
+MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple);
+  }

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


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121868/new/

https://reviews.llvm.org/D121868

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


[clang] 3210360 - [Inline-asm] Add diagnosts for unsupported inline assembly arguments

2022-03-22 Thread Phoebe Wang via cfe-commits

Author: Phoebe Wang
Date: 2022-03-23T11:25:19+08:00
New Revision: 32103608fc073700f04238872d8b22655ddec3fb

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

LOG: [Inline-asm] Add diagnosts for unsupported inline assembly arguments

GCC supports power-of-2 size structures for the arguments. Clang supports fewer 
than GCC. But Clang always crashes for the unsupported cases.

This patch adds sema checks to do the diagnosts to solve these crashes.

Reviewed By: jyu2

Differential Revision: https://reviews.llvm.org/D107141

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGStmt.cpp
clang/lib/Sema/SemaStmtAsm.cpp
clang/test/Sema/asm.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dbde2af216d97..14b276cf82295 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8783,6 +8783,8 @@ let CategoryName = "Inline Assembly Issue" in {
 " in asm %select{input|output}1 with a memory constraint '%2'">;
   def err_asm_input_duplicate_match : Error<
 "more than one input constraint matches the same output '%0'">;
+  def err_store_value_to_reg : Error<
+"impossible constraint in asm: can't store value into a register">;
 
   def warn_asm_label_on_auto_decl : Warning<
 "ignored asm label '%0' on automatic variable">;

diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 5796bb849971f..2b27d64bc93ef 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -2744,9 +2744,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
   QualType Ty = getContext().getIntTypeForBitwidth(Size, /*Signed*/ false);
   if (Ty.isNull()) {
 const Expr *OutExpr = S.getOutputExpr(i);
-CGM.Error(
-OutExpr->getExprLoc(),
-"impossible constraint in asm: can't store value into a register");
+CGM.getDiags().Report(OutExpr->getExprLoc(),
+  diag::err_store_value_to_reg);
 return;
   }
   Dest = MakeAddrLValue(A, Ty);

diff  --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 49f7a8d573d5a..fbca36b1216a8 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -667,8 +667,17 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 // output was a register, just extend the shorter one to the size of the
 // larger one.
 if (!SmallerValueMentioned && InputDomain != AD_Other &&
-OutputConstraintInfos[TiedTo].allowsRegister())
+OutputConstraintInfos[TiedTo].allowsRegister()) {
+  // FIXME: GCC supports the OutSize to be 128 at maximum. Currently 
codegen
+  // crash when the size larger than the register size. So we limit it 
here.
+  if (OutTy->isStructureType() &&
+  Context.getIntTypeForBitwidth(OutSize, /*Signed*/ false).isNull()) {
+targetDiag(OutputExpr->getExprLoc(), diag::err_store_value_to_reg);
+return NS;
+  }
+
   continue;
+}
 
 // Either both of the operands were mentioned or the smaller one was
 // mentioned.  One more special case that we'll allow: if the tied input is

diff  --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c
index 540a2769fa3b3..3c7952f410c6d 100644
--- a/clang/test/Sema/asm.c
+++ b/clang/test/Sema/asm.c
@@ -313,3 +313,54 @@ lab2:;
   asm ("jne %l0":::);
   asm goto ("jne %l0"lab);
 }
+
+typedef struct _st_size64 {
+  int a;
+  char b;
+} st_size64;
+
+typedef struct _st_size96 {
+  int a;
+  int b;
+  int c;
+} st_size96;
+
+typedef struct _st_size16 {
+  char a;
+  char b;
+} st_size16;
+
+typedef struct _st_size32 {
+  char a;
+  char b;
+  char c;
+  char d;
+} st_size32;
+
+typedef struct _st_size128 {
+  int a;
+  int b;
+  int c;
+  int d;
+} st_size128;
+
+void test19(long long x)
+{
+  st_size64 a;
+  st_size96 b;
+  st_size16 c;
+  st_size32 d;
+  st_size128 e;
+  asm ("" : "=rm" (a): "0" (1)); // no-error
+  asm ("" : "=rm" (d): "0" (1)); // no-error
+  asm ("" : "=rm" (c): "0" (x)); // no-error
+  // FIXME: This case is actually supported by codegen.
+  asm ("" : "=rm" (x): "0" (a)); // expected-error {{unsupported inline asm: 
input with type 'st_size64' (aka 'struct _st_size64') matching output with type 
'long long'}}
+  // FIXME: This case is actually supported by codegen.
+  asm ("" : "=rm" (a): "0" (d)); // expected-error {{unsupported inline asm: 
input with type 'st_size32' (aka 'struct _st_size32') matching output with type 
'st_size64' (aka 'struct _st_size64')}}
+  asm ("" : "=rm" (b): "0" (1)); // expected-error {{impossible constraint in 
asm:

[PATCH] D107141: [Inline-asm] Add diagnosts for unsupported inline assembly arguments

2022-03-22 Thread Phoebe Wang via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG32103608fc07: [Inline-asm] Add diagnosts for unsupported 
inline assembly arguments (authored by pengfei).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107141/new/

https://reviews.llvm.org/D107141

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/test/Sema/asm.c

Index: clang/test/Sema/asm.c
===
--- clang/test/Sema/asm.c
+++ clang/test/Sema/asm.c
@@ -313,3 +313,54 @@
   asm ("jne %l0":::);
   asm goto ("jne %l0"lab);
 }
+
+typedef struct _st_size64 {
+  int a;
+  char b;
+} st_size64;
+
+typedef struct _st_size96 {
+  int a;
+  int b;
+  int c;
+} st_size96;
+
+typedef struct _st_size16 {
+  char a;
+  char b;
+} st_size16;
+
+typedef struct _st_size32 {
+  char a;
+  char b;
+  char c;
+  char d;
+} st_size32;
+
+typedef struct _st_size128 {
+  int a;
+  int b;
+  int c;
+  int d;
+} st_size128;
+
+void test19(long long x)
+{
+  st_size64 a;
+  st_size96 b;
+  st_size16 c;
+  st_size32 d;
+  st_size128 e;
+  asm ("" : "=rm" (a): "0" (1)); // no-error
+  asm ("" : "=rm" (d): "0" (1)); // no-error
+  asm ("" : "=rm" (c): "0" (x)); // no-error
+  // FIXME: This case is actually supported by codegen.
+  asm ("" : "=rm" (x): "0" (a)); // expected-error {{unsupported inline asm: input with type 'st_size64' (aka 'struct _st_size64') matching output with type 'long long'}}
+  // FIXME: This case is actually supported by codegen.
+  asm ("" : "=rm" (a): "0" (d)); // expected-error {{unsupported inline asm: input with type 'st_size32' (aka 'struct _st_size32') matching output with type 'st_size64' (aka 'struct _st_size64')}}
+  asm ("" : "=rm" (b): "0" (1)); // expected-error {{impossible constraint in asm: can't store value into a register}}
+  // FIXME: This case should be supported by codegen, but it fails now.
+  asm ("" : "=rm" (e): "0" (1)); // no-error
+  // FIXME: This case should be supported by codegen, but it fails now.
+  asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: input with type 'st_size128' (aka 'struct _st_size128') matching output with type 'long long'}}
+}
Index: clang/lib/Sema/SemaStmtAsm.cpp
===
--- clang/lib/Sema/SemaStmtAsm.cpp
+++ clang/lib/Sema/SemaStmtAsm.cpp
@@ -667,8 +667,17 @@
 // output was a register, just extend the shorter one to the size of the
 // larger one.
 if (!SmallerValueMentioned && InputDomain != AD_Other &&
-OutputConstraintInfos[TiedTo].allowsRegister())
+OutputConstraintInfos[TiedTo].allowsRegister()) {
+  // FIXME: GCC supports the OutSize to be 128 at maximum. Currently codegen
+  // crash when the size larger than the register size. So we limit it here.
+  if (OutTy->isStructureType() &&
+  Context.getIntTypeForBitwidth(OutSize, /*Signed*/ false).isNull()) {
+targetDiag(OutputExpr->getExprLoc(), diag::err_store_value_to_reg);
+return NS;
+  }
+
   continue;
+}
 
 // Either both of the operands were mentioned or the smaller one was
 // mentioned.  One more special case that we'll allow: if the tied input is
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2744,9 +2744,8 @@
   QualType Ty = getContext().getIntTypeForBitwidth(Size, /*Signed*/ false);
   if (Ty.isNull()) {
 const Expr *OutExpr = S.getOutputExpr(i);
-CGM.Error(
-OutExpr->getExprLoc(),
-"impossible constraint in asm: can't store value into a register");
+CGM.getDiags().Report(OutExpr->getExprLoc(),
+  diag::err_store_value_to_reg);
 return;
   }
   Dest = MakeAddrLValue(A, Ty);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8783,6 +8783,8 @@
 " in asm %select{input|output}1 with a memory constraint '%2'">;
   def err_asm_input_duplicate_match : Error<
 "more than one input constraint matches the same output '%0'">;
+  def err_store_value_to_reg : Error<
+"impossible constraint in asm: can't store value into a register">;
 
   def warn_asm_label_on_auto_decl : Warning<
 "ignored asm label '%0' on automatic variable">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118493: Set rpath on openmp executables

2022-03-22 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

In D118493#3398808 , @JonChesterfield 
wrote:

> It lets applications run with the libomp and libomptarget built with the 
> toolchain. For users, they don't have to be root. For compiler devs, we test 
> our work instead of whatever the distro had installed.
>
> There's no info at that link. What's 'broken rpath'? If they mean runpath, 
> then it's really on fedora to have Wl,--rpath set rpath instead of runpath. 
> Setting the default in the linker to the one your own build tools reject will 
> break everything, not just llvm openmp.
>
> Edit: https://fedoraproject.org/wiki/Changes/Broken_RPATH_will_fail_rpmbuild
> Doesn't mean runpath. There's a list of strings Fedora (IBM?) have decided 
> they don't like, named 'broken' or 'invalid', and declared shall not be 
> present. Page doesn't go into the rpath/runpath distinction, maybe they mean 
> for the string restrictions to apply to both.

I'm not sure I follow this, but there is a script run after every RPM built for 
fedora that checks for RUNPATH (among other things in the binary).  I have been 
building packages for Fedora with clang14 and the script fails for packages 
built with clang + -fopenmp

> Can't tell which rule we're violating (will need to work out what the install 
> directory resolves to on fedora), though the one about executing untrusted 
> code seems likely, where untrusted seems to be anything not owned by root. 
> E.g. applications people have written themselves.

The rule that is broken is "standard RPATHs" Fedora installs libomp to 
/usr/lib64.

> We can introduce a cmake flag that changes the default on this commandline 
> argument, set when building on Fedora (and maybe redhat, centos-stream, 
> others). That'll annoy anyone developing openmp on, or using a local llvm 
> build on, Fedora but that might be zero people and they could override the 
> cmake flag and disable the build checking scripts.

I don't really like adding CMake options for things like this.  I think what 
we'll do in Fedora is just add -fno-openmp-implicit-rpath to the default CFLAGS 
so we can get the old behavior for official RPMs.

> Or disable building openmp on Fedora, that seems reasonable too.

We want to be able to build packages that use OpenMP, so disabling is not 
really an option.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118493/new/

https://reviews.llvm.org/D118493

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


[PATCH] D122285: [analyzer] Add path note tags to standard library function summaries.

2022-03-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: t-rasmud, Szelethus, martong, steakhal, ASDenysPetrov, 
balazske, gamesh411.
Herald added subscribers: manas, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
NoQ requested review of this revision.

This is a solution to the issue with `getenv()` 
(https://github.com/llvm/llvm-project/issues/53276) but I covered a few more 
functions just because I could.

The patch is straightforward except the tiny fix in `BugReporterVisitors.cpp` 
that suppresses a default note for "Assuming pointer value is null" when a note 
tag from the checker is present. This is probably the right thing to do but 
also definitely not a complete solution to the problem of different sources of 
path notes being unaware of each other, which is a large and annoying issue 
that we have to deal with. Note tags really help there because they're nicely 
introspectable. The problem is demonstrated by the newly added `getenv()` test; 
I did not investigate why doesn't the original buggy report have the same note 
but I agree that this might be interesting to figure out.

The notes are currently optional but I think we should eventually implement all 
of them and then make them mandatory.

The notes are prunable, i.e. they won't bring-in entire stack frames worth of 
notes just because they're there, but they will be always visible regardless of 
whether the value is of interest to the bug report. I think this is debatable, 
the arguably better solution is to make them non-prunable but conditional to 
the value being tracked back to the call, which would probably need a better 
tracking infrastructure.


Repository:
  rC Clang

https://reviews.llvm.org/D122285

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-path-notes.c

Index: clang/test/Analysis/std-c-library-functions-path-notes.c
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-path-notes.c
@@ -0,0 +1,46 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN: -analyzer-checker=core,apiModeling \
+// RUN: -analyzer-config assume-controlled-environment=false \
+// RUN: -analyzer-output=text
+
+#define NULL ((void *)0)
+
+char *getenv(const char *);
+int isalpha(int);
+int isdigit(int);
+
+char test_getenv() {
+  char *env = getenv("VAR"); // \
+  // expected-note{{Assuming the environment variable does not exist}} \
+  // expected-note{{'env' initialized here}}
+
+  return env[0]; // \
+  // expected-warning{{Array access (from variable 'env') results in a null pointer dereference}} \
+  // expected-note   {{Array access (from variable 'env') results in a null pointer dereference}}
+}
+
+int test_isalpha(int *x, char c) {
+  if (isalpha(c)) {// \
+// expected-note{{Assuming the character is alphabetical}} \
+// expected-note{{Taking true branch}}
+x = NULL; // \
+// expected-note{{Null pointer value stored to 'x'}}
+  }
+
+  return *x; // \
+  // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
+  // expected-note   {{Dereference of null pointer (loaded from variable 'x')}}
+}
+
+int test_isdigit(int *x, char c) {
+  if (!isdigit(c)) {// \
+// expected-note{{Assuming the character is not a digit}} \
+// expected-note{{Taking true branch}}
+x = NULL; // \
+// expected-note{{Null pointer value stored to 'x'}}
+  }
+
+  return *x; // \
+  // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
+  // expected-note   {{Dereference of null pointer (loaded from variable 'x')}}
+}
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -38,7 +38,8 @@
 }
 
 void test_alnum_symbolic(int x) {
-  int ret = isalnum(x);
+  int ret = isalnum(x); // \
+  // bugpath-note{{Assuming the character is non-alphanumeric}}
   (void)ret;
 
   clang_analyzer_eval(EOF <= x && x <= 255); // \
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1691,6 +1691,13 @@
 
 // Construct a new PathDiagnosticPiece.
 ProgramPoint P = N->getLocation();
+
+// If this node already have a specialized note, it's probably better
+// than our generic note.
+// FIXME: This only looks for note tags, not for other ways to add a note.
+if (isa_and_nonnull(P.getTag()))
+  return nullptr;
+
 PathDiagnosticLocation L =

[PATCH] D122285: [analyzer] Add path note tags to standard library function summaries.

2022-03-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:41
 //
-// The following standard C functions are currently supported:
-//

This comment has been out of date for years and I don't think it makes sense to 
have it in the first place.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1215-1217
   // The locale-specific range.
   // No post-condition. We are completely unaware of
   // locale-specific return values.

I'm not adding notes to these ranges because these days I think they were a 
mistake. A three-way (sometimes four-way) state split is pretty hard to 
justify. It's much safer to drop the case and stick to the two ASCII cases.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122285/new/

https://reviews.llvm.org/D122285

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


[PATCH] D122277: [analyzer] Fix crash in RangedConstraintManager.cpp

2022-03-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Thanks! I agree that this assertion doesn't make much sense. Judging by the 
name, the function should be able to handle all symbols.




Comment at: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp:61
+// to canonicalize "a - b" and "b - a", which would allow us to treat 
"a
+// != b" and "b != a" the same.
+

The new line break in the middle of `a != b` doesn't make much sense.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122277/new/

https://reviews.llvm.org/D122277

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


[PATCH] D122271: [Clang] -Wunused-but-set-variable warning - handle also pre/post unary operators

2022-03-22 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

LGTM. Maybe @efriedma can look at this as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122271/new/

https://reviews.llvm.org/D122271

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


[PATCH] D122104: [X86][regcall] Support passing / returning structures

2022-03-22 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 417502.
pengfei added a comment.

clang-formatted.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122104/new/

https://reviews.llvm.org/D122104

Files:
  clang/include/clang/CodeGen/CGFunctionInfo.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aarch64-neon-tbl.c
  clang/test/CodeGen/regcall2.c

Index: clang/test/CodeGen/regcall2.c
===
--- /dev/null
+++ clang/test/CodeGen/regcall2.c
@@ -0,0 +1,28 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -target-feature +avx512vl -triple=x86_64-pc-win32 | FileCheck %s --check-prefix=Win
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -target-feature +avx512vl -triple=x86_64-pc-linux-gnu | FileCheck %s --check-prefix=Lin
+
+#include 
+
+typedef struct {
+  __m512d r1[4];
+  __m512 r2[4];
+} __sVector;
+__sVector A;
+
+__sVector __regcall foo(int a) {
+  return A;
+}
+
+double __regcall bar(__sVector a) {
+  return a.r1[0][4];
+}
+
+// FIXME: Do we need to change for Windows?
+// Win: define dso_local x86_regcallcc void @__regcall3__foo(%struct.__sVector* noalias sret(%struct.__sVector) align 64 %agg.result, i32 noundef %a) #0
+// Win: define dso_local x86_regcallcc double @__regcall3__bar(%struct.__sVector* noundef %a) #0
+// Win: attributes #0 = { noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-builtins" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+avx,+avx2,+avx512f,+avx512vl,+crc32,+cx8,+f16c,+fma,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" }
+
+// Lin: define dso_local x86_regcallcc %struct.__sVector @__regcall3__foo(i32 noundef %a) #0
+// Lin: define dso_local x86_regcallcc double @__regcall3__bar([4 x <8 x double>] %a.coerce0, [4 x <16 x float>] %a.coerce1) #0
+// Lin: attributes #0 = { noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="512" "no-builtins" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+avx,+avx2,+avx512f,+avx512vl,+crc32,+cx8,+f16c,+fma,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" }
Index: clang/test/CodeGen/aarch64-neon-tbl.c
===
--- clang/test/CodeGen/aarch64-neon-tbl.c
+++ clang/test/CodeGen/aarch64-neon-tbl.c
@@ -42,7 +42,7 @@
   return vtbl2_s8(a, b);
 }
 
-// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl2_s8([2 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #0 {
+// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl2_s8([2 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #1 {
 // CHECK:   [[__P0_I:%.*]] = alloca %struct.int8x16x2_t, align 16
 // CHECK:   [[A:%.*]] = alloca %struct.int8x16x2_t, align 16
 // CHECK:   [[COERCE_DIVE:%.*]] = getelementptr inbounds %struct.int8x16x2_t, %struct.int8x16x2_t* [[A]], i32 0, i32 0
@@ -89,7 +89,7 @@
   return vtbl3_s8(a, b);
 }
 
-// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl3_s8([3 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #0 {
+// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl3_s8([3 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #1 {
 // CHECK:   [[__P0_I:%.*]] = alloca %struct.int8x16x3_t, align 16
 // CHECK:   [[A:%.*]] = alloca %struct.int8x16x3_t, align 16
 // CHECK:   [[COERCE_DIVE:%.*]] = getelementptr inbounds %struct.int8x16x3_t, %struct.int8x16x3_t* [[A]], i32 0, i32 0
@@ -142,7 +142,7 @@
   return vtbl4_s8(a, b);
 }
 
-// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl4_s8([4 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #0 {
+// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl4_s8([4 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #1 {
 // CHECK:   [[__P0_I:%.*]] = alloca %struct.int8x16x4_t, align 16
 // CHECK:   [[A:%.*]] = alloca %struct.int8x16x4_t, align 16
 // CHECK:   [[COERCE_DIVE:%.*]] = getelementptr inbounds %struct.int8x16x4_t, %struct.int8x16x4_t* [[A]], i32 0, i32 0
@@ -352,7 +352,7 @@
   return vqtbx1_s8(a, b, c);
 }
 
-// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbx2_s8(<8 x i8> noundef %a, [2 x <16 x i8>] %b.coerce, <8 x i8> noundef %c) #0 {
+// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbx2_s8(<8 x i8> noundef %a, [2 x <16 x i8>] %b.coerce, <8 x i8> noundef %c) #1 {
 // CHECK:   [[__P1_I:%.*]] = alloca %struct.int8x16x2_t, align 16
 // CHECK:   [[B:%.*]] = alloca %struct.int8x16x2_t, align 16
 // CHECK:   [[COERCE_DIVE:%.*]] = getelementptr inbounds %struct.int8x16x2_t, %struct.int8x16x2_t* [[B]], i32 0, i32 0
@@ -373,7 +373,7 @@
   return vqtbx2_s8(a, b, c);
 }
 
-// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbx3_s8(<8 x i8> noundef %a, [3 x <16 x i8>] %b.coerce, <8 x i8> noundef %c) #0 {
+// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbx3_s8(<8 x i8> noundef %a, [3 x <16 x i8>] %b.coerce, <8 x i8> noundef %c) #1 {
 // CHECK:

[PATCH] D115248: [Clang] Fix PR28101

2022-03-22 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao updated this revision to Diff 417504.
rZhBoYao set the repository for this revision to rG LLVM Github Monorepo.
rZhBoYao added a comment.

Diagnose "same name as its class" before setting the declarator invalid as 
otherwise it would not be diagnosed. This also aligns with gcc's behavior.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115248/new/

https://reviews.llvm.org/D115248

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/PR28101.cpp


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template  struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template  struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template  struct S {};
+
+template  struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U> class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template 
arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+template  struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,9 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  if (cast(CurContext)->getDeclName() == Name)
+Diag(Loc, diag::err_member_name_of_class) << Name;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template  struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template  struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template  struct S {};
+
+template  struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U> class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+template  struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,9 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  if (cast(CurContext)->getDeclName() == Name)
+Diag(Loc, diag::err_member_name_of_class) << Name;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122249: [Clang] Add a compatibiliy warning for non-literals in constexpr.

2022-03-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:1905
+if (SemaRef.LangOpts.CPlusPlus2b) {
+  if (!VD->getType()->isLiteralType(SemaRef.Context))
+SemaRef.Diag(VD->getLocation(),

This seems to trigger even when the type is dependent:
```
:1:36: warning: definition of a variable of non-literal type in a 
constexpr function is incompatible with C++ standards before C++2b 
[-Wpre-c++2b-compat]
auto qq = [](auto x) { decltype(x) n; };
   ^
1 warning generated.
```

This also seems to emit even when `Kind` is not 
`Sema::CheckConstexprKind::Diagnose` (unlike the `static`/`thread_local` case 
above). Is the `CheckLiteralType` logic not reusable for this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122249/new/

https://reviews.llvm.org/D122249

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


[PATCH] D122249: [Clang] Add a compatibiliy warning for non-literals in constexpr.

2022-03-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/SemaCXX/constant-expression-cxx2b.cpp:219
+  NonLiteral n; // cxx2b-note {{non-literal type 'NonLiteral' cannot be 
used in a constant expression}} \
+// cxx2b-warning {{definition of a variable of non-literal 
type in a constexpr function is incompatible with C++ standards before C++2b}}
 return 0;

Not sure how much we want the message in this case. The lambda is not marked 
`constexpr` (although it is implicitly `constexpr` in C++2b).

Note that we don't get a message for this:
```
auto qq = [] { return 0; static int x = 42; };
constexpr int qx = qq();
```

I am not sure how difficult it would be to come at this from the 
used-in-constant-evaluation side, but there is probably a larger class of 
messages in the same situation (so it would probably be a separate endeavour).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122249/new/

https://reviews.llvm.org/D122249

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


[clang] 98fd3b3 - Driver: Don't warn on -mbranch-protection when linking

2022-03-22 Thread Tom Stellard via cfe-commits

Author: Tom Stellard
Date: 2022-03-22T23:17:42-07:00
New Revision: 98fd3b359866f474ab1c097c22fb5c3be356b996

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

LOG: Driver: Don't warn on -mbranch-protection when linking

The -mbranch-protection definition in Options.td was not given a Group,
so this was causing clang to emit a -Wunused-command-line-argument
warning when this flag was passed to the linker driver.  This was a
problem, because some build systems, like cmake, automatically pass the
C flags to the linker.  Therefore, any program that was compiled with
-Werror and -mbranch-protection would fail to link with the error:

argument unused during compilation: '-mbranch-protection=standard' 
[-Werror,-Wunused-command-line-argument]

Reviewed By: vhscampos

Differential Revision: https://reviews.llvm.org/D121983

Added: 
clang/test/Driver/Inputs/main.c

Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/aarch64-security-options.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2a23695c149fa..e35b36af91c33 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3442,6 +3442,7 @@ def msign_return_address_EQ : Joined<["-"], 
"msign-return-address=">,
   Flags<[CC1Option]>, Group, Values<"none,all,non-leaf">,
   HelpText<"Select return address signing scope">;
 def mbranch_protection_EQ : Joined<["-"], "mbranch-protection=">,
+  Group,
   HelpText<"Enforce targets of indirect branches and function returns">;
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,

diff  --git a/clang/test/Driver/Inputs/main.c b/clang/test/Driver/Inputs/main.c
new file mode 100644
index 0..5c2fa9bb6a78e
--- /dev/null
+++ b/clang/test/Driver/Inputs/main.c
@@ -0,0 +1,3 @@
+int main(int argc, char **argv) {
+  return 0;
+}

diff  --git a/clang/test/Driver/aarch64-security-options.c 
b/clang/test/Driver/aarch64-security-options.c
index 6ea4b8ae58385..e9db540d53ede 100644
--- a/clang/test/Driver/aarch64-security-options.c
+++ b/clang/test/Driver/aarch64-security-options.c
@@ -27,6 +27,10 @@
 // RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=bar   
  2>&1 | \
 // RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION --check-prefix=WARN
 
+// RUN: %clang -target aarch64--none-eabi -o %t-main.o 
-mbranch-protection=standard -c %S/Inputs/main.c
+// RUN: %clang -target aarch64--none-eabi -o %t-main 
-mbranch-protection=standard %t-main.o 2>&1 | \
+// RUN: FileCheck --allow-empty %s --check-prefix=LINKER-DRIVER
+
 // WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 
'aarch64' architecture does not support it [-Wbranch-protection]
 
 // RA-OFF: "-msign-return-address=none"
@@ -46,3 +50,7 @@
 
 // BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in 
'-mbranch-protection={{.*}}'
 // BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in 
'-mbranch-protection={{.*}}'
+
+// Check that the linker driver doesn't warn about -mbranch-protection=standard
+// as an unused option.
+// LINKER-DRIVER-NOT: warning:



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


[PATCH] D121983: Driver: Don't warn on -mbranch-protection when linking

2022-03-22 Thread Tom Stellard via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG98fd3b359866: Driver: Don't warn on -mbranch-protection 
when linking (authored by tstellar).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121983/new/

https://reviews.llvm.org/D121983

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/Inputs/main.c
  clang/test/Driver/aarch64-security-options.c


Index: clang/test/Driver/aarch64-security-options.c
===
--- clang/test/Driver/aarch64-security-options.c
+++ clang/test/Driver/aarch64-security-options.c
@@ -27,6 +27,10 @@
 // RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=bar   
  2>&1 | \
 // RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION --check-prefix=WARN
 
+// RUN: %clang -target aarch64--none-eabi -o %t-main.o 
-mbranch-protection=standard -c %S/Inputs/main.c
+// RUN: %clang -target aarch64--none-eabi -o %t-main 
-mbranch-protection=standard %t-main.o 2>&1 | \
+// RUN: FileCheck --allow-empty %s --check-prefix=LINKER-DRIVER
+
 // WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 
'aarch64' architecture does not support it [-Wbranch-protection]
 
 // RA-OFF: "-msign-return-address=none"
@@ -46,3 +50,7 @@
 
 // BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in 
'-mbranch-protection={{.*}}'
 // BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in 
'-mbranch-protection={{.*}}'
+
+// Check that the linker driver doesn't warn about -mbranch-protection=standard
+// as an unused option.
+// LINKER-DRIVER-NOT: warning:
Index: clang/test/Driver/Inputs/main.c
===
--- /dev/null
+++ clang/test/Driver/Inputs/main.c
@@ -0,0 +1,3 @@
+int main(int argc, char **argv) {
+  return 0;
+}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3442,6 +3442,7 @@
   Flags<[CC1Option]>, Group, Values<"none,all,non-leaf">,
   HelpText<"Select return address signing scope">;
 def mbranch_protection_EQ : Joined<["-"], "mbranch-protection=">,
+  Group,
   HelpText<"Enforce targets of indirect branches and function returns">;
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,


Index: clang/test/Driver/aarch64-security-options.c
===
--- clang/test/Driver/aarch64-security-options.c
+++ clang/test/Driver/aarch64-security-options.c
@@ -27,6 +27,10 @@
 // RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=bar 2>&1 | \
 // RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION --check-prefix=WARN
 
+// RUN: %clang -target aarch64--none-eabi -o %t-main.o -mbranch-protection=standard -c %S/Inputs/main.c
+// RUN: %clang -target aarch64--none-eabi -o %t-main -mbranch-protection=standard %t-main.o 2>&1 | \
+// RUN: FileCheck --allow-empty %s --check-prefix=LINKER-DRIVER
+
 // WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 'aarch64' architecture does not support it [-Wbranch-protection]
 
 // RA-OFF: "-msign-return-address=none"
@@ -46,3 +50,7 @@
 
 // BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in '-mbranch-protection={{.*}}'
 // BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in '-mbranch-protection={{.*}}'
+
+// Check that the linker driver doesn't warn about -mbranch-protection=standard
+// as an unused option.
+// LINKER-DRIVER-NOT: warning:
Index: clang/test/Driver/Inputs/main.c
===
--- /dev/null
+++ clang/test/Driver/Inputs/main.c
@@ -0,0 +1,3 @@
+int main(int argc, char **argv) {
+  return 0;
+}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3442,6 +3442,7 @@
   Flags<[CC1Option]>, Group, Values<"none,all,non-leaf">,
   HelpText<"Select return address signing scope">;
 def mbranch_protection_EQ : Joined<["-"], "mbranch-protection=">,
+  Group,
   HelpText<"Enforce targets of indirect branches and function returns">;
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121201: [clang] Merge the SourceRange into ParsedAttributes

2022-03-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 417509.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121201/new/

https://reviews.llvm.org/D121201

Files:
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaOpenCL/address-spaces.cl

Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -258,7 +258,7 @@
 
 void func_multiple_addr2(void) {
   typedef __private int private_int_t;
-  __private __attribute__((opencl_global)) int var1;   // expected-error {{multiple address spaces specified for type}} \
+  __attribute__((opencl_global)) __private int var1;   // expected-error {{multiple address spaces specified for type}} \
// expected-error {{function scope variable cannot be declared in global address space}}
   __private __attribute__((opencl_global)) int *var2;  // expected-error {{multiple address spaces specified for type}}
   __attribute__((opencl_global)) private_int_t var3;   // expected-error {{multiple address spaces specified for type}}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -368,7 +368,8 @@
 };
 
 static void processTypeAttrs(TypeProcessingState &state, QualType &type,
- TypeAttrLocation TAL, ParsedAttributesView &attrs);
+ TypeAttrLocation TAL,
+ const ParsedAttributesView &attrs);
 
 static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
QualType &type);
@@ -8138,7 +8139,12 @@
 
 static void processTypeAttrs(TypeProcessingState &state, QualType &type,
  TypeAttrLocation TAL,
- ParsedAttributesView &attrs) {
+ const ParsedAttributesView &attrs) {
+
+  state.setParsedNoDeref(false);
+  if (attrs.empty())
+return;
+
   // Scan through and apply attributes to this type where it makes sense.  Some
   // attributes (such as __address_space__, __vector_size__, etc) apply to the
   // type, but others can be present in the type specifiers even though they
@@ -8148,9 +8154,6 @@
   // sure we visit every element once. Copy the attributes list, and iterate
   // over that.
   ParsedAttributesView AttrsCopy{attrs};
-
-  state.setParsedNoDeref(false);
-
   for (ParsedAttr &attr : AttrsCopy) {
 
 // Skip attributes that were marked to be invalid.
Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -495,8 +495,7 @@
   }
 }
 
-void Sema::ProcessStmtAttributes(Stmt *S,
- const ParsedAttributesWithRange &InAttrs,
+void Sema::ProcessStmtAttributes(Stmt *S, const ParsedAttributes &InAttrs,
  SmallVectorImpl &OutAttrs) {
   for (const ParsedAttr &AL : InAttrs) {
 if (const Attr *A = ProcessStmtAttribute(*this, S, AL, InAttrs.Range))
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -587,7 +587,7 @@
   return AttributedStmt::Create(Context, AttrsLoc, Attrs, SubStmt);
 }
 
-StmtResult Sema::ActOnAttributedStmt(const ParsedAttributesWithRange &Attrs,
+StmtResult Sema::ActOnAttributedStmt(const ParsedAttributes &Attrs,
  Stmt *SubStmt) {
   SmallVector SemanticAttrs;
   ProcessStmtAttributes(SubStmt, Attrs, SemanticAttrs);
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -2615,12 +2615,11 @@
 /// example:
 ///class foo : public bar, virtual private baz {
 /// 'public bar' and 'virtual private baz' are each base-specifiers.
-BaseResult
-Sema::ActOnBaseSpecifier(Decl *classdecl, SourceRange SpecifierRange,
- ParsedAttributes &Attributes,
- bool Virtual, AccessSpecifier Access,
-

[clang] 1089cdd - Revert "Driver: Don't warn on -mbranch-protection when linking"

2022-03-22 Thread Tom Stellard via cfe-commits

Author: Tom Stellard
Date: 2022-03-22T23:36:57-07:00
New Revision: 1089cdda776bbd437d6507242f2621ec83af7118

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

LOG: Revert "Driver: Don't warn on -mbranch-protection when linking"

This reverts commit 98fd3b359866f474ab1c097c22fb5c3be356b996.

This patch broke multiple bots.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/aarch64-security-options.c

Removed: 
clang/test/Driver/Inputs/main.c



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e35b36af91c33..2a23695c149fa 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3442,7 +3442,6 @@ def msign_return_address_EQ : Joined<["-"], 
"msign-return-address=">,
   Flags<[CC1Option]>, Group, Values<"none,all,non-leaf">,
   HelpText<"Select return address signing scope">;
 def mbranch_protection_EQ : Joined<["-"], "mbranch-protection=">,
-  Group,
   HelpText<"Enforce targets of indirect branches and function returns">;
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,

diff  --git a/clang/test/Driver/Inputs/main.c b/clang/test/Driver/Inputs/main.c
deleted file mode 100644
index 5c2fa9bb6a78e..0
--- a/clang/test/Driver/Inputs/main.c
+++ /dev/null
@@ -1,3 +0,0 @@
-int main(int argc, char **argv) {
-  return 0;
-}

diff  --git a/clang/test/Driver/aarch64-security-options.c 
b/clang/test/Driver/aarch64-security-options.c
index e9db540d53ede..6ea4b8ae58385 100644
--- a/clang/test/Driver/aarch64-security-options.c
+++ b/clang/test/Driver/aarch64-security-options.c
@@ -27,10 +27,6 @@
 // RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=bar   
  2>&1 | \
 // RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION --check-prefix=WARN
 
-// RUN: %clang -target aarch64--none-eabi -o %t-main.o 
-mbranch-protection=standard -c %S/Inputs/main.c
-// RUN: %clang -target aarch64--none-eabi -o %t-main 
-mbranch-protection=standard %t-main.o 2>&1 | \
-// RUN: FileCheck --allow-empty %s --check-prefix=LINKER-DRIVER
-
 // WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 
'aarch64' architecture does not support it [-Wbranch-protection]
 
 // RA-OFF: "-msign-return-address=none"
@@ -50,7 +46,3 @@
 
 // BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in 
'-mbranch-protection={{.*}}'
 // BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in 
'-mbranch-protection={{.*}}'
-
-// Check that the linker driver doesn't warn about -mbranch-protection=standard
-// as an unused option.
-// LINKER-DRIVER-NOT: warning:



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


<    1   2   3