[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-10-14 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D129443#3857608 , @rymiel wrote:

> Changing the default LLVM style would change the output of all the 
> requires-related test cases in `FormatTest.Concepts`. Should I change these 
> test cases to use the new indentation or pass the `REI_Keyword` style to them?

I prefer the latter so as to minimize the diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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


[PATCH] D135518: [clangAST] support TypeLoc in TextNodeDumper

2022-10-14 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj updated this revision to Diff 467698.
upsj marked 6 inline comments as done.
upsj added a comment.

I incorporated the `cast`, `ASTContext` and `StringRef` suggestions. About 
JSONDumper, I was surprised to see that it doesn't seem to use `AddChild` for 
the AST hierarchy at all, so I'm not quite clear how (if?) it builds a nested 
output. What's the easiest way to invoke it?


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

https://reviews.llvm.org/D135518

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/TypeLoc.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/TypeLoc.cpp

Index: clang/lib/AST/TypeLoc.cpp
===
--- clang/lib/AST/TypeLoc.cpp
+++ clang/lib/AST/TypeLoc.cpp
@@ -57,6 +57,22 @@
 
 namespace {
 
+class TypeNamer : public TypeLocVisitor {
+public:
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+  llvm::StringRef Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { return #CLASS; }
+#include "clang/AST/TypeLocNodes.def"
+};
+
+} // namespace
+
+llvm::StringRef TypeLoc::getTypeLocClassName() const {
+  return TypeNamer().Visit(*this);
+}
+
+namespace {
+
 class TypeAligner : public TypeLocVisitor {
 public:
 #define ABSTRACT_TYPELOC(CLASS, PARENT)
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/LocInfoType.h"
 #include "clang/AST/Type.h"
+#include "clang/AST/TypeLocVisitor.h"
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Specifiers.h"
@@ -239,6 +240,18 @@
   OS << " " << T.split().Quals.getAsString();
 }
 
+void TextNodeDumper::Visit(TypeLoc TL) {
+  {
+ColorScope Color(OS, ShowColors, TypeColor);
+OS << TL.getTypeLocClassName() << "TypeLoc";
+  }
+  dumpSourceRange(TL.getSourceRange());
+  OS << " ";
+  dumpBareType(TL.getType(), false);
+
+  TypeLocVisitor::Visit(TL);
+}
+
 void TextNodeDumper::Visit(const Decl *D) {
   if (!D) {
 ColorScope Color(OS, ShowColors, NullColor);
@@ -1622,6 +1635,116 @@
 OS << " expansions " << *N;
 }
 
+void TextNodeDumper::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
+  OS << " " << TL.getType().split().Quals.getAsString();
+}
+
+void TextNodeDumper::VisitRValueReferenceTypeLoc(ReferenceTypeLoc TL) {
+  VisitReferenceType(cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitArrayTypeLoc(ArrayTypeLoc TL) {
+  if (Context)
+VisitArrayType(Context->getAsArrayType(TL.getType()));
+}
+
+void TextNodeDumper::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) {
+  if (Context)
+VisitConstantArrayType(Context->getAsConstantArrayType(TL.getType()));
+}
+
+void TextNodeDumper::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
+  if (Context)
+VisitVariableArrayType(Context->getAsVariableArrayType(TL.getType()));
+}
+
+void TextNodeDumper::VisitDependentSizedArrayTypeLoc(
+DependentSizedArrayTypeLoc TL) {
+  if (Context)
+VisitDependentSizedArrayType(
+Context->getAsDependentSizedArrayType(TL.getType()));
+}
+
+void TextNodeDumper::VisitDependentSizedExtVectorTypeLoc(
+DependentSizedExtVectorTypeLoc TL) {
+  VisitDependentSizedExtVectorType(
+  cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitVectorTypeLoc(VectorTypeLoc TL) {
+  VisitVectorType(cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitFunctionTypeLoc(FunctionTypeLoc TL) {
+  VisitFunctionType(cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) {
+  VisitFunctionProtoType(cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
+  VisitUnresolvedUsingType(
+  cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitUsingTypeLoc(UsingTypeLoc TL) {
+  VisitUsingType(cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
+  VisitTypedefType(cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
+  VisitUnaryTransformType(cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitTagTypeLoc(TagTypeLoc TL) {
+  VisitTagType(cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
+  VisitTemplateTypeParmType(
+  cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitSubstTemplateTypeParmTypeLoc(
+SubstTemplateTypeParmTypeLoc TL) {
+  VisitSubstTemplateTypeParmType(
+  cast(TL.getType().getTypePtr()));
+}
+
+void TextNodeDumper::VisitAutoTypeLoc(AutoTypeLoc TL) {
+  VisitAutoType(cast(TL.getType().getTypePtr()));
+

[PATCH] D135518: [clangAST] support TypeLoc in TextNodeDumper

2022-10-14 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj added inline comments.



Comment at: clang/include/clang/AST/TextNodeDumper.h:337
+  void VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL);
+  void VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL);
+  void VisitDependentSizedArrayTypeLoc(DependentSizedArrayTypeLoc TL);

aaron.ballman wrote:
> Should you also handle `IncompleteArrayTypeLoc` as well?
Not sure about this one, since it has no additional metadata - the type 
location visitor already prints out the type class name


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

https://reviews.llvm.org/D135518

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


[PATCH] D135859: [Includecleaner] Introduce RefType to ast walking

2022-10-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/AnalysisInternal.h:33
+/// Indicates the relation between the reference and the target.
+enum class RefType {
+  /// Target is explicit from the reference, e.g. function call.

I'm wondering what's our plan of supporting policy (different coding-style may 
have different decisions about which includes are used)?

IIUC, the RefType is part of the picture, providing fine-grained information 
about each reference, and the caller can make their decisions based on it?

Thinking about the `Implicit` type, I think cases like non-spelled constructor 
call, implicit conversion calls (maybe more?) fall into this type, if we 
support `Policy.Constructor`, and `Policy.Conversion`, how do we distinguish 
with these cases? We can probably do some ad-hoc checks on the `TargetDecl`, 
but I'm not sure that the tuple `` will 
provide enough information to implement different policy .



Comment at: clang-tools-extra/include-cleaner/lib/AnalysisInternal.h:36
+  Explicit,
+  /// Target isn't spelled, e.g. default constructor call.
+  Implicit,

nit: `default constructor call` is vague -- `S s = S();` it is a default 
constructor call, but it is not implicit, maybe more specific by giving a 
simple example, like default constructor call in `S s;`?



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:12
 #include "gtest/gtest.h"
+#include 
+#include 

nit: it seems unused.



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:177
 TEST(WalkAST, ConstructExprs) {
-  testWalk("struct ^S {};", "S ^t;");
-  testWalk("struct S { ^S(int); };", "S ^t(42);");
+  testWalk("struct $implicit^S {};", "S ^t;");
+  testWalk("struct S { $explicit^S(int); };", "S ^t(42);");

maybe add this following case, I think it will mark the the constructor `S()` 
implicit. 

```
struct S { S(); };
S ^t;
```



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:178
+  testWalk("struct $implicit^S {};", "S ^t;");
+  testWalk("struct S { $explicit^S(int); };", "S ^t(42);");
 }

nit: also  add an implicit case

```
S t = 42; 
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135859

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


[PATCH] D135025: [clang][Interp] Support base class constructors

2022-10-14 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 467699.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D135025

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -1,8 +1,6 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -verify=ref %s
 
-// expected-no-diagnostics
-
 struct BoolPair {
   bool first;
   bool second;
@@ -169,3 +167,110 @@
 static_assert(LT2.v[0].second == false, "");
 static_assert(LT2.v[2].first == true, "");
 static_assert(LT2.v[2].second == false, "");
+
+class Base {
+public:
+  int i;
+  constexpr Base() : i(10) {}
+  constexpr Base(int i) : i(i) {}
+};
+
+class A : public Base {
+public:
+  constexpr A() : Base(100) {}
+  constexpr A(int a) : Base(a) {}
+};
+constexpr A a{};
+static_assert(a.i == 100, "");
+constexpr A a2{12};
+static_assert(a2.i == 12, "");
+static_assert(a2.i == 200, ""); // ref-error {{static assertion failed}} \
+// ref-note {{evaluates to '12 == 200'}} \
+// expected-error {{static assertion failed}} \
+// expected-note {{evaluates to '12 == 200'}}
+
+namespace MI {
+  class A {
+  public:
+int a;
+constexpr A(int a) : a(a) {}
+  };
+
+  class B {
+  public:
+int b;
+constexpr B(int b) : b(b) {}
+  };
+
+  class C : public A, public B {
+  public:
+constexpr C() : A(10), B(20) {}
+  };
+  constexpr C c = {};
+  static_assert(c.a == 10);
+  static_assert(c.b == 20);
+
+
+  class D : private A, private B {
+public:
+constexpr D() : A(20), B(30) {}
+constexpr int getA() const { return a; }
+constexpr int getB() const { return b; }
+  };
+  constexpr D d = {};
+  static_assert(d.getA() == 20);
+  static_assert(d.getB() == 30);
+};
+
+namespace DeriveFailures {
+  struct Base { // ref-note 2{{declared here}}
+int Val;
+  };
+
+  struct Derived : Base {
+int OtherVal;
+
+constexpr Derived(int i) : OtherVal(i) {} // ref-error {{never produces a constant expression}} \
+  // ref-note 2{{non-constexpr constructor 'Base' cannot be used in a constant expression}}
+  };
+
+  // FIXME: This is currently not being diagnosed with the new constant interpreter.
+  constexpr Derived D(12); // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{in call to 'Derived(12)'}} \
+   // ref-note {{declared here}} \
+   // expected-error {{must be initialized by a constant expression}}
+  static_assert(D.Val == 0); // ref-error {{not an integral constant expression}} \
+ // ref-note {{initializer of 'D' is not a constant expression}}
+
+  struct AnotherBase {
+int Val;
+constexpr AnotherBase(int i) : Val(12 / i) {} //ref-note {{division by zero}} \
+  //expected-note {{division by zero}}
+  };
+
+  struct AnotherDerived : AnotherBase {
+constexpr AnotherDerived(int i) : AnotherBase(i) {}
+  };
+  constexpr AnotherBase Derp(0); // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{in call to 'AnotherBase(0)'}} \
+ // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{in call to 'AnotherBase(}}
+ // FIXME Previous note uses the wrong value
+
+  struct YetAnotherBase {
+int Val;
+constexpr YetAnotherBase(int i) : Val(i) {}
+  };
+
+  struct YetAnotherDerived : YetAnotherBase {
+using YetAnotherBase::YetAnotherBase; //ref-note {{declared here}}
+int OtherVal;
+
+constexpr bool doit() const { return Val == OtherVal; }
+  };
+
+  constexpr YetAnotherDerived Oops(0); // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{constructor inherited from base class 'YetAnotherBase' cannot be used in a constant expression}} \
+   // expected-error {{must be initialized by a constant expression}}
+   // FIXME: Missing reason for rejection.
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -54,6 +54,11 @@
   list Types;
 }
 
+def IntegerTypeClass : TypeClass {
+  let Types = [Sint8, Uint8, Sint16, Uint16, Sint

[PATCH] D135025: [clang][Interp] Support base class constructors

2022-10-14 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/records.cpp:209
+  static_assert(d.getA() == 20);
+  static_assert(d.getB() == 30);
+};

aaron.ballman wrote:
> I'd appreciate some more failure test cases, if they're not already covered 
> elsewhere:
> ```
> struct Base {
>   int Val;
> };
> 
> struct Derived : Base {
>   int OtherVal;
> 
>   constexpr Derived(int i) : OtherVal(i) {}
> };
> 
> // Something here should be diagnosed; either because the Derived ctor is not 
> a
> // valid constexpr function or because we're accessing an uninitialized 
> member.
> constexpr Derived D(12);
> static_assert(D.Val == 0);
> 
> 
> // Another test is when a constexpr ctor calls a non-constexpr base class 
> ctor.
> struct AnotherBase {
>   int Val;
>   constexpr AnotherBase(int i) : Val(12 / i) {}
> };
> 
> struct AnotherDerived : AnotherBase {
>   constexpr AnotherDerived(int i) : AnotherBase(i) {}
> };
> constexpr AnotherDerived Derp(0);
> 
> // Skipping the derived class constructor is also
> // interesting to consider:
> struct YetAnotherBase {
>   int Val;
>   constexpr YetAnotherBase(int i) : Val(i) {}
> };
> 
> struct YetAnotherDerived : YetAnotherBase {
>   using YetAnotherBase::YetAnotherBase;
>   
>   int OtherVal;
> 
>   constexpr bool doit() const { return Val == OtherVal; }
> };
> 
> constexpr YetAnotherDerived Oops(0);
> ```
Thanks for the tests. I added them but it doesn't look very good.


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

https://reviews.llvm.org/D135025

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


[PATCH] D135858: [clang][Interp] Support pointer arithmethic in binary operators

2022-10-14 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:241
+  // Pointer arithmethic special case. This is supported for one of
+  // LHS and RHS being a pointer type and the other being an integer type.
+  if (BO->getType()->isPointerType()) {

shafik wrote:
> I am not sure if this is the right place to handle this but there are a bunch 
> of other cases.
> 
> - `nullptr` can have `0` added or subtracted
> - You can only do addition/subtraction from a pointer if the result in within 
> bounds or one after the end
> - You can subtract two pointers if they point to the same object.
> 
> godbolt: https://godbolt.org/z/5YTY93z8M
I will probably move this special case out of the function and into its own.
Thanks for the tests, I think this should all already work except for adding 
two pointers. I'll update the diff once I checked that out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135858

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


[PATCH] D135518: [clangAST] support TypeLoc in TextNodeDumper

2022-10-14 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj added a comment.

Let me backtrack my previous question: I misremembered where AddChild is 
actually being called in the traversal (ASTNodeTraverser, not TextNodeDumper), 
so I'll see if adding this to the JSON output is feasible


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

https://reviews.llvm.org/D135518

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


[PATCH] D135932: [X86] Add AVX-IFMA instructions.

2022-10-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/test/CodeGen/avxifma-builtins.c:1
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +avxifma -emit-llvm -o - -Wall -Werror | FileCheck %s
+

32-bit test coverage?



Comment at: clang/test/Preprocessor/predefined-arch-macros-x86.c:35
 // X86_64_V3:  #define __AVX2__ 1
-// X86_64_V3-NEXT: #define __AVX__ 1
+// X86_64_V3 : #define __AVX__ 1
 // X86_64_V3:  #define __BMI2__ 1

?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135932

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


[PATCH] D135933: [X86] Add CMPCCXADD instructions.

2022-10-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/test/CodeGen/X86/cmpccxadd-builtins-error.c:2
+// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown \
+// RUN: -target-feature +cmpccxadd  -emit-llvm -fsyntax-only -verify
+

Add 32-bit test coverage to ensure the intrinsics aren't visible?



Comment at: llvm/CMakeLists.txt:887
+  list(APPEND features_enabled_by_default
+   ${LLVM_INTELFEATURE_PREFIX}_ISA_CMPCCXADD)
 

What is this for?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135933

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


[clang] 0e93b6b - [clang][Interp][NFC] Add more tests for if expressions

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T10:21:53+02:00
New Revision: 0e93b6bd51a0f002e37e76d6efa8e71dde6d3e5f

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

LOG: [clang][Interp][NFC] Add more tests for if expressions

Rename the old if_consteval.cpp to just if.cpp and add tests for the
if declaration.

Added: 
clang/test/AST/Interp/if.cpp

Modified: 


Removed: 
clang/test/AST/Interp/if_consteval.cpp



diff  --git a/clang/test/AST/Interp/if.cpp b/clang/test/AST/Interp/if.cpp
new file mode 100644
index 0..5d35868cd00ec
--- /dev/null
+++ b/clang/test/AST/Interp/if.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only 
-fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only %s -verify=ref
+
+// expected-no-diagnostics
+// ref-no-diagnostics
+
+namespace ConstEval {
+  constexpr int f() {
+int i = 0;
+if consteval {
+  i = 1;
+}
+return i;
+  }
+  static_assert(f() == 1, "");
+
+  constexpr int f2() {
+int i = 0;
+if !consteval {
+i = 12;
+  if consteval {
+i = i + 1;
+  }
+}
+return i;
+  }
+  static_assert(f2() == 0, "");
+};
+
+namespace InitDecl {
+  constexpr bool f() {
+if (int i = 5; i != 10) {
+  return true;
+}
+return false;
+  }
+  static_assert(f(), "");
+
+  constexpr bool f2() {
+if (bool b = false; b) {
+  return true;
+}
+return false;
+  }
+  static_assert(!f2(), "");
+};

diff  --git a/clang/test/AST/Interp/if_consteval.cpp 
b/clang/test/AST/Interp/if_consteval.cpp
deleted file mode 100644
index 1a3ff9b91d720..0
--- a/clang/test/AST/Interp/if_consteval.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only 
-fexperimental-new-constant-interpreter %s -verify
-// RUN: %clang_cc1 -std=c++2b -fsyntax-only %s -verify
-// expected-no-diagnostics
-
-constexpr void f() {
-  int i = 0;
-  if consteval {
-i = 1;
-  }
-  else {
-i = 2;
-  }
-
-  if consteval {
-i = 1;
-  }
-
-  if !consteval {
-i = 1;
-  }
-
-  if !consteval {
-i = 1;
-  }
-  else {
-i = 1;
-  }
-}



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


[clang] 1928da1 - [clang][Interp] Don't run functions immediately after compiling them

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T10:21:53+02:00
New Revision: 1928da1ef73c383ea4daeffb41691882bdb074c2

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

LOG: [clang][Interp] Don't run functions immediately after compiling them

This doesn't make much sense with functions that expect valid parameters
and/or a certain call stack on the caller side like This/RVO pointers.

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

Added: 


Modified: 
clang/lib/AST/Interp/Context.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index 9f3f5542fe83..7ce3397e6a4f 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -39,11 +39,7 @@ bool Context::isPotentialConstantExpr(State &Parent, const 
FunctionDecl *FD) {
 }
   }
 
-  if (!Func->isConstexpr())
-return false;
-
-  APValue Dummy;
-  return Run(Parent, Func, Dummy);
+  return Func->isConstexpr();
 }
 
 bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {



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


[clang] 773b468 - [clang][Interp][NFC] Add a TODO comment

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T10:21:52+02:00
New Revision: 773b468543c8c5f0a226c0757a503cb9a40650a5

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

LOG: [clang][Interp][NFC] Add a TODO comment

We can ignore casts where FromT and ToT are the same type. But that's a
performance optimization that I'd like to do later. For now, this code
is doing the right thing.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 9264357c568a3..e23727aad256e 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -127,6 +127,7 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 if (!this->Visit(SubExpr))
   return false;
 
+// TODO: Emit this only if FromT != ToT.
 return this->emitCast(*FromT, *ToT, CE);
   }
 



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


[clang] 1942a25 - [clang][Interp] Start implementing record types

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T10:21:53+02:00
New Revision: 1942a2538b86fe55b9723800db950391cc05402b

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

LOG: [clang][Interp] Start implementing record types

Implement simple constructors as well as member access expressions.

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

Added: 
clang/test/AST/Interp/records.cpp

Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Record.h
clang/test/AST/Interp/references.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e23727aad256..2e8343504e5a 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -304,6 +304,28 @@ bool 
ByteCodeExprGen::VisitUnaryExprOrTypeTraitExpr(
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitMemberExpr(const MemberExpr *E) {
+  // 'Base.Member'
+  const Expr *Base = E->getBase();
+  const ValueDecl *Member = E->getMemberDecl();
+
+  if (!this->visit(Base))
+return false;
+
+  // Base above gives us a pointer on the stack.
+  // TODO: Implement non-FieldDecl members.
+  if (const auto *FD = dyn_cast(Member)) {
+const RecordDecl *RD = FD->getParent();
+const Record *R = getRecord(RD);
+const Record::Field *F = R->getField(FD);
+// Leave a pointer to the field on the stack.
+return this->emitGetPtrField(F->Offset, E);
+  }
+
+  return false;
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
@@ -609,6 +631,78 @@ bool ByteCodeExprGen::visitArrayInitializer(const 
Expr *Initializer) {
   return true;
 }
 
+template 
+bool ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) 
{
+  Initializer = Initializer->IgnoreParenImpCasts();
+  assert(Initializer->getType()->isRecordType());
+
+  if (const auto CtorExpr = dyn_cast(Initializer)) {
+const CXXConstructorDecl *Ctor = CtorExpr->getConstructor();
+const RecordDecl *RD = Ctor->getParent();
+const Record *R = getRecord(RD);
+
+for (const auto *Init : Ctor->inits()) {
+  const FieldDecl *Member = Init->getMember();
+  const Expr *InitExpr = Init->getInit();
+
+  if (Optional T = classify(InitExpr->getType())) {
+const Record::Field *F = R->getField(Member);
+
+if (!this->emitDupPtr(Initializer))
+  return false;
+
+if (!this->visit(InitExpr))
+  return false;
+
+if (!this->emitInitField(*T, F->Offset, Initializer))
+  return false;
+  } else {
+assert(false && "Handle initializer for non-primitive values");
+  }
+}
+
+// FIXME: Actually visit() the constructor Body
+const Stmt *Body = Ctor->getBody();
+(void)Body;
+return true;
+  } else if (const auto *InitList = dyn_cast(Initializer)) {
+const Record *R = getRecord(InitList->getType());
+
+unsigned InitIndex = 0;
+for (const Expr *Init : InitList->inits()) {
+  const Record::Field *FieldToInit = R->getField(InitIndex);
+
+  if (Optional T = classify(Init->getType())) {
+if (!this->emitDupPtr(Initializer))
+  return false;
+
+if (!this->visit(Init))
+  return false;
+
+if (!this->emitInitField(*T, FieldToInit->Offset, Initializer))
+  return false;
+  }
+  ++InitIndex;
+}
+
+return true;
+  } else if (const CallExpr *CE = dyn_cast(Initializer)) {
+const Decl *Callee = CE->getCalleeDecl();
+const Function *Func = P.getFunction(dyn_cast(Callee));
+
+if (Func->hasRVO()) {
+  // RVO functions expect a pointer to initialize on the stack.
+  // Dup our existing pointer so it has its own copy to use.
+  if (!this->emitDupPtr(Initializer))
+return false;
+
+  return this->visit(CE);
+}
+  }
+
+  return false;
+}
+
 template 
 bool ByteCodeExprGen::visitInitializer(const Expr *Initializer) {
   QualType InitializerType = Initializer->getType();
@@ -616,6 +710,9 @@ bool ByteCodeExprGen::visitInitializer(const Expr 
*Initializer) {
   if (InitializerType->isArrayType())
 return visitArrayInitializer(Initializer);
 
+  if (InitializerType->isRecordType())
+return visitRecordInitializer(Initializer);
+
   // Otherwise, visit the expression like normal.
   return this->Visit(Initializer);
 }
@@ -755,6 +852,8 @@ bool ByteCodeExprGen::VisitCallExpr(const CallExpr 
*E) {
 return this->emitCall(*T, Func, E);
   return this->emitCallVoid(Func, E);
 } else {
+  if (Func->hasRVO())
+return this->emit

[clang] 0ddd13a - [clang][Interp] Implement This pointer passing to methods

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T10:21:53+02:00
New Revision: 0ddd13acc9e9b820c8f610c9006ef59aef8e5320

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

LOG: [clang][Interp] Implement This pointer passing to methods

Implement passing the this pointer to member functions and constructors.
The this pointer is passed via the stack. This changes the functions to
explicitly track whether they have a RVO pointer and a this pointer.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/Function.cpp
clang/lib/AST/Interp/Function.h
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/InterpFrame.h
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index 20e054ab87df..7fa189ad0806 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -31,8 +31,21 @@ Expected ByteCodeEmitter::compileFunc(const 
FunctionDecl *F) {
 
   // If the return is not a primitive, a pointer to the storage where the value
   // is initialized in is passed as the first argument.
+  // See 'RVO' elsewhere in the code.
   QualType Ty = F->getReturnType();
+  bool HasRVO = false;
   if (!Ty->isVoidType() && !Ctx.classify(Ty)) {
+HasRVO = true;
+ParamTypes.push_back(PT_Ptr);
+ParamOffset += align(primSize(PT_Ptr));
+  }
+
+  // If the function decl is a member decl, the next parameter is
+  // the 'this' pointer. This parameter is pop()ed from the
+  // InterStack when calling the function.
+  bool HasThisPointer = false;
+  if (const auto *MD = dyn_cast(F); MD && MD->isInstance()) {
+HasThisPointer = true;
 ParamTypes.push_back(PT_Ptr);
 ParamOffset += align(primSize(PT_Ptr));
   }
@@ -55,8 +68,9 @@ Expected ByteCodeEmitter::compileFunc(const 
FunctionDecl *F) {
   }
 
   // Create a handle over the emitted code.
-  Function *Func = P.createFunction(F, ParamOffset, std::move(ParamTypes),
-std::move(ParamDescriptors));
+  Function *Func =
+  P.createFunction(F, ParamOffset, std::move(ParamTypes),
+   std::move(ParamDescriptors), HasThisPointer, HasRVO);
   // Compile the function body.
   if (!F->isConstexpr() || !visitFunc(F)) {
 // Return a dummy function if compilation failed.

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 2e8343504e5a..d743e3a22342 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -637,34 +637,16 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
   assert(Initializer->getType()->isRecordType());
 
   if (const auto CtorExpr = dyn_cast(Initializer)) {
-const CXXConstructorDecl *Ctor = CtorExpr->getConstructor();
-const RecordDecl *RD = Ctor->getParent();
-const Record *R = getRecord(RD);
-
-for (const auto *Init : Ctor->inits()) {
-  const FieldDecl *Member = Init->getMember();
-  const Expr *InitExpr = Init->getInit();
-
-  if (Optional T = classify(InitExpr->getType())) {
-const Record::Field *F = R->getField(Member);
-
-if (!this->emitDupPtr(Initializer))
-  return false;
+const Function *Func = getFunction(CtorExpr->getConstructor());
 
-if (!this->visit(InitExpr))
-  return false;
-
-if (!this->emitInitField(*T, F->Offset, Initializer))
-  return false;
-  } else {
-assert(false && "Handle initializer for non-primitive values");
-  }
-}
+if (!Func)
+  return false;
 
-// FIXME: Actually visit() the constructor Body
-const Stmt *Body = Ctor->getBody();
-(void)Body;
-return true;
+// The This pointer is already on the stack because this is an initializer,
+// but we need to dup() so the call() below has its own copy.
+if (!this->emitDupPtr(Initializer))
+  return false;
+return this->emitCallVoid(Func, Initializer);
   } else if (const auto *InitList = dyn_cast(Initializer)) {
 const Record *R = getRecord(InitList->getType());
 
@@ -688,7 +670,10 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
 return true;
   } else if (const CallExpr *CE = dyn_cast(Initializer)) {
 const Decl *Callee = CE->getCalleeDecl();
-const Function *Func = P.getFunction(dyn_cast(Callee));
+const Function 

[clang] cb5f205 - [clang][Interp] Implement nested struct initialization

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T10:21:53+02:00
New Revision: cb5f205828e696fb23cfe3de57af83d151ffad38

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

LOG: [clang][Interp] Implement nested struct initialization

Recurse into visitInitializer() if necessary.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d743e3a22342..66e373e427c8 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -613,9 +613,11 @@ bool ByteCodeExprGen::visitArrayInitializer(const 
Expr *Initializer) {
   return false;
   } else if (Optional T = classify(InitType)) {
 // Visit the primitive element like normal.
+if (!this->emitDupPtr(Init))
+  return false;
 if (!this->visit(Init))
   return false;
-if (!this->emitInitElem(*T, ElementIndex, Init))
+if (!this->emitInitElemPop(*T, ElementIndex, Init))
   return false;
   } else {
 assert(false && "Unhandled type in array initializer initlist");
@@ -623,12 +625,13 @@ bool 
ByteCodeExprGen::visitArrayInitializer(const Expr *Initializer) {
 
   ++ElementIndex;
 }
-
-  } else {
-assert(false && "Unknown expression for array initialization");
+return true;
+  } else if (const auto *DIE = dyn_cast(Initializer)) {
+return this->visitInitializer(DIE->getExpr());
   }
 
-  return true;
+  assert(false && "Unknown expression for array initialization");
+  return false;
 }
 
 template 
@@ -683,7 +686,10 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
 
   return this->visit(CE);
 }
+  } else if (const auto *DIE = dyn_cast(Initializer)) {
+return this->visitInitializer(DIE->getExpr());
   }
+
   return false;
 }
 

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 54a0f50d198b..b4a61ebed0e7 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -102,10 +102,9 @@ bool ByteCodeStmtGen::visitFunc(const 
FunctionDecl *F) {
 for (const auto *Init : Ctor->inits()) {
   const FieldDecl *Member = Init->getMember();
   const Expr *InitExpr = Init->getInit();
+  const Record::Field *F = R->getField(Member);
 
   if (Optional T = this->classify(InitExpr->getType())) {
-const Record::Field *F = R->getField(Member);
-
 if (!this->emitDupPtr(InitExpr))
   return false;
 
@@ -115,7 +114,19 @@ bool ByteCodeStmtGen::visitFunc(const 
FunctionDecl *F) {
 if (!this->emitInitField(*T, F->Offset, InitExpr))
   return false;
   } else {
-assert(false && "Handle initializer for non-primitive values");
+// Non-primitive case. Get a pointer to the field-to-initialize
+// on the stack and call visitInitialzer() for it.
+if (!this->emitDupPtr(InitExpr))
+  return false;
+
+if (!this->emitGetPtrField(F->Offset, InitExpr))
+  return false;
+
+if (!this->visitInitializer(InitExpr))
+  return false;
+
+if (!this->emitPopPtr(InitExpr))
+  return false;
   }
 }
   }

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index ab363ffc8770..8d62b53d622a 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -12,7 +12,8 @@ struct Ints {
   int a = 20;
   int b = 30;
   bool c = true;
-  // BoolPair bp = {true, false}; FIXME
+  BoolPair bp = {true, false};
+  int numbers[3] = {1,2,3};
 
   static const int five = 5;
   static constexpr int getFive() {
@@ -32,6 +33,13 @@ static_assert(ints.b == 30, "");
 static_assert(ints.c, "");
 static_assert(ints.getTen() == 10, "");
 
+constexpr const BoolPair &BP = ints.bp;
+static_assert(BP.first, "");
+static_assert(!BP.second, "");
+static_assert(ints.bp.first, "");
+static_assert(!ints.bp.second, "");
+
+
 constexpr Ints ints2{-20, -30, false};
 static_assert(ints2.a == -20, "");
 static_assert(ints2.b == -30, "");



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


[clang] 33b5283 - [clang][Interp] Fix using default copy constructors

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T10:21:53+02:00
New Revision: 33b52836de6e093acea15f24b6ae633f969d194a

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

LOG: [clang][Interp] Fix using default copy constructors

Implement ArrayInitLoopExprs, which are used in copy constructors to
copy arrays. Also fix problems encountered while doing that.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 66e373e427c8..b9e7f4e2cdad 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -326,6 +326,18 @@ bool ByteCodeExprGen::VisitMemberExpr(const 
MemberExpr *E) {
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitArrayInitIndexExpr(
+const ArrayInitIndexExpr *E) {
+  assert(ArrayIndex);
+  return this->emitConstUint64(*ArrayIndex, E);
+}
+
+template 
+bool ByteCodeExprGen::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
+  return this->visit(E->getSourceExpr());
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
@@ -628,6 +640,32 @@ bool ByteCodeExprGen::visitArrayInitializer(const 
Expr *Initializer) {
 return true;
   } else if (const auto *DIE = dyn_cast(Initializer)) {
 return this->visitInitializer(DIE->getExpr());
+  } else if (const auto *AILE = dyn_cast(Initializer)) {
+// TODO: This compiles to quite a lot of bytecode if the array is larger.
+//   Investigate compiling this to a loop, or at least try to use
+//   the AILE's Common expr.
+const Expr *SubExpr = AILE->getSubExpr();
+size_t Size = AILE->getArraySize().getZExtValue();
+Optional ElemT = classify(SubExpr->getType());
+
+if (!ElemT)
+  return false;
+
+for (size_t I = 0; I != Size; ++I) {
+  ArrayIndexScope IndexScope(this, I);
+  if (!this->emitDupPtr(SubExpr))
+return false;
+
+  if (!this->visit(SubExpr))
+return false;
+
+  if (!this->emitInitElem(*ElemT, I, Initializer))
+return false;
+
+  if (!this->emitPopPtr(Initializer))
+return false;
+}
+return true;
   }
 
   assert(false && "Unknown expression for array initialization");
@@ -642,13 +680,20 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
   if (const auto CtorExpr = dyn_cast(Initializer)) {
 const Function *Func = getFunction(CtorExpr->getConstructor());
 
-if (!Func)
+if (!Func || !Func->isConstexpr())
   return false;
 
 // The This pointer is already on the stack because this is an initializer,
 // but we need to dup() so the call() below has its own copy.
 if (!this->emitDupPtr(Initializer))
   return false;
+
+// Constructor arguments.
+for (const auto *Arg : CtorExpr->arguments()) {
+  if (!this->visit(Arg))
+return false;
+}
+
 return this->emitCallVoid(Func, Initializer);
   } else if (const auto *InitList = dyn_cast(Initializer)) {
 const Record *R = getRecord(InitList->getType());
@@ -657,15 +702,26 @@ bool 
ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
 for (const Expr *Init : InitList->inits()) {
   const Record::Field *FieldToInit = R->getField(InitIndex);
 
-  if (Optional T = classify(Init->getType())) {
-if (!this->emitDupPtr(Initializer))
-  return false;
+  if (!this->emitDupPtr(Initializer))
+return false;
 
+  if (Optional T = classify(Init->getType())) {
 if (!this->visit(Init))
   return false;
 
 if (!this->emitInitField(*T, FieldToInit->Offset, Initializer))
   return false;
+  } else {
+// Non-primitive case. Get a pointer to the field-to-initialize
+// on the stack and recurse into visitInitializer().
+if (!this->emitGetPtrField(FieldToInit->Offset, Init))
+  return false;
+
+if (!this->visitInitializer(Init))
+  return false;
+
+if (!this->emitPopPtr(Initializer))
+  return false;
   }
   ++InitIndex;
 }

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 14356ec9cdee..32ff72aa36fb 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -34,6 +34,7 @@ template  class RecordScope;
 template  class VariableScope;
 template  class DeclScope;
 template  class OptionScope;
+template  class ArrayIndexScope;
 
 /// Com

[PATCH] D135569: [clang][Interp] Don't run functions immediately after compiling them

2022-10-14 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1928da1ef73c: [clang][Interp] Don't run functions 
immediately after compiling them (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D135569?vs=466462&id=467706#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135569

Files:
  clang/lib/AST/Interp/Context.cpp


Index: clang/lib/AST/Interp/Context.cpp
===
--- clang/lib/AST/Interp/Context.cpp
+++ clang/lib/AST/Interp/Context.cpp
@@ -39,11 +39,7 @@
 }
   }
 
-  if (!Func->isConstexpr())
-return false;
-
-  APValue Dummy;
-  return Run(Parent, Func, Dummy);
+  return Func->isConstexpr();
 }
 
 bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {


Index: clang/lib/AST/Interp/Context.cpp
===
--- clang/lib/AST/Interp/Context.cpp
+++ clang/lib/AST/Interp/Context.cpp
@@ -39,11 +39,7 @@
 }
   }
 
-  if (!Func->isConstexpr())
-return false;
-
-  APValue Dummy;
-  return Run(Parent, Func, Dummy);
+  return Func->isConstexpr();
 }
 
 bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134057: [clang][Interp] Start implementing record types

2022-10-14 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
tbaeder marked an inline comment as done.
Closed by commit rG1942a2538b86: [clang][Interp] Start implementing record 
types (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D134057?vs=461148&id=467707#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134057

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Record.h
  clang/test/AST/Interp/records.cpp
  clang/test/AST/Interp/references.cpp

Index: clang/test/AST/Interp/references.cpp
===
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -83,9 +83,8 @@
   S s{1, 2};
 
   int &j = s.i;
-  j += 10;
+  j = j + 10;
 
   return j;
 }
-// FIXME: Should be accepted.
-static_assert(RefToMemberExpr() == 11, ""); // expected-error {{not an integral constant expression}}
+static_assert(RefToMemberExpr() == 11, "");
Index: clang/test/AST/Interp/records.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/records.cpp
@@ -0,0 +1,105 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+// ref-no-diagnostics
+// expected-no-diagnostics
+
+struct BoolPair {
+  bool first;
+  bool second;
+};
+
+struct Ints {
+  int a = 20;
+  int b = 30;
+  bool c = true;
+  // BoolPair bp = {true, false}; FIXME
+
+  static const int five = 5;
+  static constexpr int getFive() {
+return five;
+  }
+
+  constexpr int getTen() const {
+return 10;
+  }
+};
+
+static_assert(Ints::getFive() == 5, "");
+
+constexpr Ints ints;
+static_assert(ints.a == 20, "");
+static_assert(ints.b == 30, "");
+static_assert(ints.c, "");
+static_assert(ints.getTen() == 10, "");
+
+constexpr Ints ints2{-20, -30, false};
+static_assert(ints2.a == -20, "");
+static_assert(ints2.b == -30, "");
+static_assert(!ints2.c, "");
+
+#if 0
+constexpr Ints getInts() {
+  return {64, 128, true};
+}
+constexpr Ints ints3 = getInts();
+static_assert(ints3.a == 64, "");
+static_assert(ints3.b == 128, "");
+static_assert(ints3.c, "");
+#endif
+
+constexpr Ints ints4 = {
+  .a = 40 * 50,
+  .b = 0,
+  .c = (ints.a > 0),
+
+};
+static_assert(ints4.a == (40 * 50), "");
+static_assert(ints4.b == 0, "");
+static_assert(ints4.c, "");
+
+
+// FIXME: Implement initialization by DeclRefExpr.
+//constexpr Ints ints4 = ints3;  TODO
+
+
+
+struct Ints2 {
+  int a = 10;
+  int b;
+};
+// FIXME: Broken in the new constant interpreter.
+//   Should be rejected, but without asan errors.
+//constexpr Ints2 ints2;
+
+class C {
+  public:
+int a;
+int b;
+
+  constexpr C() : a(100), b(200) {}
+};
+
+constexpr C c;
+static_assert(c.a == 100, "");
+static_assert(c.b == 200, "");
+
+constexpr int getB() {
+  C c;
+  int &j = c.b;
+
+  j = j * 2;
+
+  return c.b;
+}
+static_assert(getB() == 400, "");
+
+constexpr int getA(const C &c) {
+  return c.a;
+}
+static_assert(getA(c) == 100, "");
+
+constexpr const C* getPointer() {
+  return &c;
+}
+static_assert(getPointer()->a == 100, "");
Index: clang/lib/AST/Interp/Record.h
===
--- clang/lib/AST/Interp/Record.h
+++ clang/lib/AST/Interp/Record.h
@@ -67,6 +67,7 @@
   }
 
   unsigned getNumFields() const { return Fields.size(); }
+  const Field *getField(unsigned I) const { return &Fields[I]; }
   Field *getField(unsigned I) { return &Fields[I]; }
 
   using const_base_iter = BaseList::const_iterator;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -492,6 +492,9 @@
   return true;
 }
 
+/// 1) Pops the value from the stack
+/// 2) Pops a pointer from the stack
+/// 3) Writes the value to field I of the pointer
 template ::T>
 bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
   const T &Value = S.Stk.pop();
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -94,10 +94,6 @@
   // Classify the return type.
   ReturnType = this->classify(F->getReturnType());
 
-  // Set up fields and context if a constructor.
-  if (auto *MD = dyn_cast(F))
-return this->bail(MD);
-
   if (auto *Body = F->getBody())
 if (!visitStmt(Body))
   return false;
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +7

[PATCH] D134699: [clang][Interp] Implement This pointer passing to methods

2022-10-14 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
tbaeder marked an inline comment as done.
Closed by commit rG0ddd13acc9e9: [clang][Interp] Implement This pointer passing 
to methods (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D134699?vs=465966&id=467708#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134699

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Disasm.cpp
  clang/lib/AST/Interp/EvalEmitter.cpp
  clang/lib/AST/Interp/Function.cpp
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/lib/AST/Interp/InterpFrame.h
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -1,7 +1,6 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -verify=ref %s
 
-// ref-no-diagnostics
 // expected-no-diagnostics
 
 struct BoolPair {
@@ -38,7 +37,6 @@
 static_assert(ints2.b == -30, "");
 static_assert(!ints2.c, "");
 
-#if 0
 constexpr Ints getInts() {
   return {64, 128, true};
 }
@@ -46,7 +44,6 @@
 static_assert(ints3.a == 64, "");
 static_assert(ints3.b == 128, "");
 static_assert(ints3.c, "");
-#endif
 
 constexpr Ints ints4 = {
   .a = 40 * 50,
@@ -103,3 +100,38 @@
   return &c;
 }
 static_assert(getPointer()->a == 100, "");
+
+constexpr C RVOAndParams(const C *c) {
+  return C();
+}
+constexpr C RVOAndParamsResult = RVOAndParams(&c);
+
+constexpr int locals() {
+  C c;
+  c.a = 10;
+
+  // Assignment, not an initializer.
+  // c = C(); FIXME
+  c.a = 10;
+
+
+  // Assignment, not an initializer.
+  //c = RVOAndParams(&c); FIXME
+
+  return c.a;
+}
+static_assert(locals() == 10, "");
+
+namespace thisPointer {
+  struct S {
+constexpr int get12() { return 12; }
+  };
+
+  constexpr int foo() { // ref-error {{never produces a constant expression}}
+S *s = nullptr;
+return s->get12(); // ref-note 2{{member call on dereferenced null pointer}}
+  }
+  // FIXME: The new interpreter doesn't reject this currently.
+  static_assert(foo() == 12, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to 'foo()'}}
+};
Index: clang/lib/AST/Interp/InterpFrame.h
===
--- clang/lib/AST/Interp/InterpFrame.h
+++ clang/lib/AST/Interp/InterpFrame.h
@@ -35,6 +35,11 @@
   InterpFrame(InterpState &S, Function *Func, InterpFrame *Caller,
   CodePtr RetPC, Pointer &&This);
 
+  /// Creates a new frame with the values that make sense.
+  /// I.e., the caller is the current frame of S,
+  /// and the This() pointer is the current Pointer on the top of S's stack,
+  InterpFrame(InterpState &S, Function *Func, CodePtr RetPC);
+
   /// Destroys the frame, killing all live pointers to stack slots.
   ~InterpFrame();
 
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -36,6 +36,36 @@
   }
 }
 
+InterpFrame::InterpFrame(InterpState &S, Function *Func, CodePtr RetPC)
+: Caller(S.Current), S(S), Func(Func), RetPC(RetPC),
+  ArgSize(Func ? Func->getArgSize() : 0),
+  Args(static_cast(S.Stk.top())), FrameOffset(S.Stk.size()) {
+  assert(Func);
+
+  // As per our calling convention, the this pointer is
+  // part of the ArgSize.
+  // If the function has RVO, the RVO pointer is first.
+  // If the fuction has a This pointer, that one is next.
+  // Then follow the actual arguments (but those are handled
+  // in getParamPointer()).
+  if (Func->hasThisPointer()) {
+if (Func->hasRVO())
+  This = stackRef(sizeof(Pointer));
+else
+  This = stackRef(0);
+  }
+
+  if (unsigned FrameSize = Func->getFrameSize()) {
+Locals = std::make_unique(FrameSize);
+for (auto &Scope : Func->scopes()) {
+  for (auto &Local : Scope.locals()) {
+Block *B = new (localBlock(Local.Offset)) Block(Local.Desc);
+B->invokeCtor();
+  }
+}
+  }
+}
+
 InterpFrame::~InterpFrame() {
   if (Func && Func->isConstructor() && This.isBaseClass())
 This.initialize();
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -55,8 +55,7 @@
 
 template ::T>
 static bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
-  S.Current =
-  new InterpFrame(S, const_cast(Func), S.Current, 

[PATCH] D134175: [clang][Interp] Implement record instance functions and returning struct types

2022-10-14 Thread Timm Bäder 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 rGcb5f205828e6: [clang][Interp] Implement nested struct 
initialization (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134175

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -12,7 +12,8 @@
   int a = 20;
   int b = 30;
   bool c = true;
-  // BoolPair bp = {true, false}; FIXME
+  BoolPair bp = {true, false};
+  int numbers[3] = {1,2,3};
 
   static const int five = 5;
   static constexpr int getFive() {
@@ -32,6 +33,13 @@
 static_assert(ints.c, "");
 static_assert(ints.getTen() == 10, "");
 
+constexpr const BoolPair &BP = ints.bp;
+static_assert(BP.first, "");
+static_assert(!BP.second, "");
+static_assert(ints.bp.first, "");
+static_assert(!ints.bp.second, "");
+
+
 constexpr Ints ints2{-20, -30, false};
 static_assert(ints2.a == -20, "");
 static_assert(ints2.b == -30, "");
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -102,10 +102,9 @@
 for (const auto *Init : Ctor->inits()) {
   const FieldDecl *Member = Init->getMember();
   const Expr *InitExpr = Init->getInit();
+  const Record::Field *F = R->getField(Member);
 
   if (Optional T = this->classify(InitExpr->getType())) {
-const Record::Field *F = R->getField(Member);
-
 if (!this->emitDupPtr(InitExpr))
   return false;
 
@@ -115,7 +114,19 @@
 if (!this->emitInitField(*T, F->Offset, InitExpr))
   return false;
   } else {
-assert(false && "Handle initializer for non-primitive values");
+// Non-primitive case. Get a pointer to the field-to-initialize
+// on the stack and call visitInitialzer() for it.
+if (!this->emitDupPtr(InitExpr))
+  return false;
+
+if (!this->emitGetPtrField(F->Offset, InitExpr))
+  return false;
+
+if (!this->visitInitializer(InitExpr))
+  return false;
+
+if (!this->emitPopPtr(InitExpr))
+  return false;
   }
 }
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -613,9 +613,11 @@
   return false;
   } else if (Optional T = classify(InitType)) {
 // Visit the primitive element like normal.
+if (!this->emitDupPtr(Init))
+  return false;
 if (!this->visit(Init))
   return false;
-if (!this->emitInitElem(*T, ElementIndex, Init))
+if (!this->emitInitElemPop(*T, ElementIndex, Init))
   return false;
   } else {
 assert(false && "Unhandled type in array initializer initlist");
@@ -623,12 +625,13 @@
 
   ++ElementIndex;
 }
-
-  } else {
-assert(false && "Unknown expression for array initialization");
+return true;
+  } else if (const auto *DIE = dyn_cast(Initializer)) {
+return this->visitInitializer(DIE->getExpr());
   }
 
-  return true;
+  assert(false && "Unknown expression for array initialization");
+  return false;
 }
 
 template 
@@ -683,7 +686,10 @@
 
   return this->visit(CE);
 }
+  } else if (const auto *DIE = dyn_cast(Initializer)) {
+return this->visitInitializer(DIE->getExpr());
   }
+
   return false;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134361: [clang][Interp] Fix copy constructors of structs with array members

2022-10-14 Thread Timm Bäder 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 rG33b52836de6e: [clang][Interp] Fix using default copy 
constructors (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D134361?vs=463522&id=467710#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134361

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -32,6 +32,9 @@
 static_assert(ints.b == 30, "");
 static_assert(ints.c, "");
 static_assert(ints.getTen() == 10, "");
+static_assert(ints.numbers[0] == 1, "");
+static_assert(ints.numbers[1] == 2, "");
+static_assert(ints.numbers[2] == 3, "");
 
 constexpr const BoolPair &BP = ints.bp;
 static_assert(BP.first, "");
@@ -62,11 +65,17 @@
 static_assert(ints4.a == (40 * 50), "");
 static_assert(ints4.b == 0, "");
 static_assert(ints4.c, "");
-
-
-// FIXME: Implement initialization by DeclRefExpr.
-//constexpr Ints ints4 = ints3;  TODO
-
+static_assert(ints4.numbers[0] == 1, "");
+static_assert(ints4.numbers[1] == 2, "");
+static_assert(ints4.numbers[2] == 3, "");
+
+constexpr Ints ints5 = ints4;
+static_assert(ints5.a == (40 * 50), "");
+static_assert(ints5.b == 0, "");
+static_assert(ints5.c, "");
+static_assert(ints5.numbers[0] == 1, "");
+static_assert(ints5.numbers[1] == 2, "");
+static_assert(ints5.numbers[2] == 3, "");
 
 
 struct Ints2 {
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -105,7 +105,7 @@
   const Record::Field *F = R->getField(Member);
 
   if (Optional T = this->classify(InitExpr->getType())) {
-if (!this->emitDupPtr(InitExpr))
+if (!this->emitThis(InitExpr))
   return false;
 
 if (!this->visit(InitExpr))
@@ -116,7 +116,7 @@
   } else {
 // Non-primitive case. Get a pointer to the field-to-initialize
 // on the stack and call visitInitialzer() for it.
-if (!this->emitDupPtr(InitExpr))
+if (!this->emitThis(InitExpr))
   return false;
 
 if (!this->emitGetPtrField(F->Offset, InitExpr))
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -34,6 +34,7 @@
 template  class VariableScope;
 template  class DeclScope;
 template  class OptionScope;
+template  class ArrayIndexScope;
 
 /// Compilation context for expressions.
 template 
@@ -85,6 +86,8 @@
   bool VisitConstantExpr(const ConstantExpr *E);
   bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
   bool VisitMemberExpr(const MemberExpr *E);
+  bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E);
+  bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
@@ -199,6 +202,7 @@
   friend class RecordScope;
   friend class DeclScope;
   friend class OptionScope;
+  friend class ArrayIndexScope;
 
   /// Emits a zero initializer.
   bool visitZeroInitializer(PrimType T, const Expr *E);
@@ -260,7 +264,7 @@
   /// Current scope.
   VariableScope *VarScope = nullptr;
 
-  /// Current argument index.
+  /// Current argument index. Needed to emit ArrayInitIndexExpr.
   llvm::Optional ArrayIndex;
 
   /// Flag indicating if return value is to be discarded.
@@ -362,6 +366,20 @@
   }
 };
 
+template  class ArrayIndexScope final {
+public:
+  ArrayIndexScope(ByteCodeExprGen *Ctx, uint64_t Index) : Ctx(Ctx) {
+OldArrayIndex = Ctx->ArrayIndex;
+Ctx->ArrayIndex = Index;
+  }
+
+  ~ArrayIndexScope() { Ctx->ArrayIndex = OldArrayIndex; }
+
+private:
+  ByteCodeExprGen *Ctx;
+  Optional OldArrayIndex;
+};
+
 } // namespace interp
 } // namespace clang
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -326,6 +326,18 @@
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitArrayInitIndexExpr(
+const ArrayInitIndexExpr *E) {
+  assert(ArrayIndex);
+  return this->emitConstUint64(*ArrayIndex, E);
+}
+
+template 
+bool ByteCodeExprGen::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
+  return this->visit(E->getSourceExpr());
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) {
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
@@ -628,6 +640,32 @@
 return true;
 

[PATCH] D135936: [X86] Support -march=raptorlake

2022-10-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/lib/Support/Host.cpp:828
+  *Subtype = X86::INTEL_COREI7_RAPTORLAKE;
+  break;
 // Icelake Xeon:

newline to separate the defs



Comment at: llvm/lib/Target/X86/X86.td:1423
 ProcessorFeatures.TRMTuning>;
+def : ProcModel<"raptorlake", SLMModel, ProcessorFeatures.ADLFeatures,
+ProcessorFeatures.TRMTuning>;

Shouldn't this be next to alderlake and use AlderlakePModel + ADLTuning?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135936

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


[PATCH] D135937: [X86] Support -march=meteorlake

2022-10-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:1424
+def : ProcModel<"meteorlake", SLMModel, ProcessorFeatures.ADLFeatures,
+ProcessorFeatures.TRMTuning>;
 

This should be with the alderlake/raptorlake defs below (and use ADL 
model/features/tuning)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135937

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


[PATCH] D135938: [X86] Add AVX-VNNI-INT8 instructions.

2022-10-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/test/CodeGen/avxvnniint8-builtins.c:1
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-unknown-unknown -target-feature +avxvnniint8 -emit-llvm -o - 
-Wall -Werror | FileCheck %s
+

32-bit test coverage?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135938

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


[PATCH] D135930: [X86] Add AVX-NE-CONVERT instructions.

2022-10-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/test/CodeGen/X86/avxneconvert-builtins.c:2
+// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown 
-target-feature +avx2 -target-feature +avxneconvert \
+// RUN: -target-feature +avx512fp16 -emit-llvm -o - -Wall -Werror -pedantic 
-Wno-gnu-statement-expression | FileCheck %s
+

32-bit test coverage?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135930

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


[PATCH] D135951: [X86][WIP] SUPPORT RAO-INT

2022-10-14 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
pengfei requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

For more details about these instructions, please refer to the latest ISE 
document: 
https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135951

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Headers/cpuid.h
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_target_features.c
  llvm/include/llvm/Support/X86TargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/lib/Target/X86/X86InstrRAOINT.td
  llvm/test/MC/Disassembler/X86/rao-int.txt
  llvm/test/MC/Disassembler/X86/x86-64-rao-int.txt
  llvm/test/MC/X86/rao-int-att.s
  llvm/test/MC/X86/rao-int-intel.s
  llvm/test/MC/X86/x86-64-rao-int-att.s
  llvm/test/MC/X86/x86-64-rao-int-intel.s

Index: llvm/test/MC/X86/x86-64-rao-int-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/x86-64-rao-int-intel.s
@@ -0,0 +1,193 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+
+// CHECK:  aadd qword ptr [rbp + 8*r14 + 268435456], r9
+// CHECK: encoding: [0x4e,0x0f,0x38,0xfc,0x8c,0xf5,0x00,0x00,0x00,0x10]
+   aadd qword ptr [rbp + 8*r14 + 268435456], r9
+
+// CHECK:  aadd qword ptr [r8 + 4*rax + 291], r9
+// CHECK: encoding: [0x4d,0x0f,0x38,0xfc,0x8c,0x80,0x23,0x01,0x00,0x00]
+   aadd qword ptr [r8 + 4*rax + 291], r9
+
+// CHECK:  aadd qword ptr [rip], r9
+// CHECK: encoding: [0x4c,0x0f,0x38,0xfc,0x0d,0x00,0x00,0x00,0x00]
+   aadd qword ptr [rip], r9
+
+// CHECK:  aadd qword ptr [2*rbp - 512], r9
+// CHECK: encoding: [0x4c,0x0f,0x38,0xfc,0x0c,0x6d,0x00,0xfe,0xff,0xff]
+   aadd qword ptr [2*rbp - 512], r9
+
+// CHECK:  aadd qword ptr [rcx + 2032], r9
+// CHECK: encoding: [0x4c,0x0f,0x38,0xfc,0x89,0xf0,0x07,0x00,0x00]
+   aadd qword ptr [rcx + 2032], r9
+
+// CHECK:  aadd qword ptr [rdx - 2048], r9
+// CHECK: encoding: [0x4c,0x0f,0x38,0xfc,0x8a,0x00,0xf8,0xff,0xff]
+   aadd qword ptr [rdx - 2048], r9
+
+// CHECK:  aadd dword ptr [esp + 8*esi + 268435456], ebx
+// CHECK: encoding: [0x67,0x0f,0x38,0xfc,0x9c,0xf4,0x00,0x00,0x00,0x10]
+   aadd dword ptr [esp + 8*esi + 268435456], ebx
+
+// CHECK:  aadd dword ptr [edi + 4*eax + 291], ebx
+// CHECK: encoding: [0x67,0x0f,0x38,0xfc,0x9c,0x87,0x23,0x01,0x00,0x00]
+   aadd dword ptr [edi + 4*eax + 291], ebx
+
+// CHECK:  aadd dword ptr [eax], ebx
+// CHECK: encoding: [0x67,0x0f,0x38,0xfc,0x18]
+   aadd dword ptr [eax], ebx
+
+// CHECK:  aadd dword ptr [2*ebp - 512], ebx
+// CHECK: encoding: [0x67,0x0f,0x38,0xfc,0x1c,0x6d,0x00,0xfe,0xff,0xff]
+   aadd dword ptr [2*ebp - 512], ebx
+
+// CHECK:  aadd dword ptr [ecx + 2032], ebx
+// CHECK: encoding: [0x67,0x0f,0x38,0xfc,0x99,0xf0,0x07,0x00,0x00]
+   aadd dword ptr [ecx + 2032], ebx
+
+// CHECK:  aadd dword ptr [edx - 2048], ebx
+// CHECK: encoding: [0x67,0x0f,0x38,0xfc,0x9a,0x00,0xf8,0xff,0xff]
+   aadd dword ptr [edx - 2048], ebx
+
+// CHECK:  aand qword ptr [rbp + 8*r14 + 268435456], r9
+// CHECK: encoding: [0x66,0x4e,0x0f,0x38,0xfc,0x8c,0xf5,0x00,0x00,0x00,0x10]
+   aand qword ptr [rbp + 8*r14 + 268435456], r9
+
+// CHECK:  aand qword ptr [r8 + 4*rax + 291], r9
+// CHECK: encoding: [0x66,0x4d,0x0f,0x38,0xfc,0x8c,0x80,0x23,0x01,0x00,0x00]
+   aand qword ptr [r8 + 4*rax + 291], r9
+
+// CHECK:  aand qword ptr [rip], r9
+// CHECK: encoding: [0x66,0x4c,0x0f,0x38,0xfc,0x0d,0x00,0x00,0x00,0x00]
+   aand qword ptr [rip], r9
+
+// CHECK:  aand qword ptr [2*rbp - 512], r9
+// CHECK: encoding: [0x66,0x4c,0x0f,0x38,0xfc,0x0c,0x6d,0x00,0xfe,0xff,0xff]
+   aand qword ptr [2*rbp - 512], r9
+
+// CHECK:  aand qword ptr [rcx + 2032], r9
+// CHECK: encoding: [0x66,0x4c,0x0f,0x38,0xfc,0x89,0xf0,0x07,0x00,0x00]
+   aand qword ptr [rcx + 2032], r9
+
+// CHECK:  aand qword ptr [rdx - 2048], r9
+// CHECK: encoding: [0x66,0x4c,0x0f,0x38,0xfc,0x8a,0x00,0xf8,0xff,0xff]
+   aand qword ptr [rdx - 2048], r9
+
+// CHECK:  aand dword ptr [esp + 8*esi + 268435456], ebx
+// CHECK: encoding: [0x67,0x66,0x0f,0x38,0xfc,0x9c,0xf4,0x00,0x00,0x00,0x10]
+   aand dword ptr [esp + 8*esi + 268435456], ebx
+
+// CHECK:  aand dword ptr [edi + 4*eax + 291], ebx
+// CHECK: encoding: [0x67,0x66,0x

[clang] 2f35705 - [Interp] Silence warning in release builds. NFC.

2022-10-14 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2022-10-14T10:38:32+02:00
New Revision: 2f357054d705459c534a74781e4dc24debe78fcb

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

LOG: [Interp] Silence warning in release builds. NFC.

Added: 


Modified: 
clang/lib/AST/Interp/EvalEmitter.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index 94cd1ba9bf94..aa4396f135d2 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -113,6 +113,7 @@ bool EvalEmitter::emitCall(const Function *Func, const 
SourceInfo &Info) {
 bool EvalEmitter::emitCallVoid(const Function *Func, const SourceInfo &Info) {
   APValue VoidResult;
   InterpFrame *before = S.Current;
+  (void)before;
   S.Current = new InterpFrame(S, const_cast(Func), {});
   bool Success = Interpret(S, VoidResult);
   assert(VoidResult.isAbsent());



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


[clang] c004d75 - [clang][Interp] Disable some RVO tests

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T10:45:23+02:00
New Revision: c004d7534dcefcfebc3e07a7fa12f5492be80279

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

LOG: [clang][Interp] Disable some RVO tests

Apparently this breaks a couple of builders:
https://lab.llvm.org/buildbot/#/builders/139/builds/29552
https://lab.llvm.org/buildbot/#/builders/216/builds/11240

Added: 


Modified: 
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 1e61d4845a43..ae0287b1347d 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -48,6 +48,7 @@ static_assert(ints2.a == -20, "");
 static_assert(ints2.b == -30, "");
 static_assert(!ints2.c, "");
 
+#if 0
 constexpr Ints getInts() {
   return {64, 128, true};
 }
@@ -55,6 +56,7 @@ constexpr Ints ints3 = getInts();
 static_assert(ints3.a == 64, "");
 static_assert(ints3.b == 128, "");
 static_assert(ints3.c, "");
+#endif
 
 constexpr Ints ints4 = {
   .a = 40 * 50,
@@ -118,10 +120,12 @@ constexpr const C* getPointer() {
 }
 static_assert(getPointer()->a == 100, "");
 
+#if 0
 constexpr C RVOAndParams(const C *c) {
   return C();
 }
 constexpr C RVOAndParamsResult = RVOAndParams(&c);
+#endif
 
 constexpr int locals() {
   C c;



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


[PATCH] D135953: [IncludeCleaner] Introduce decl to location mapping

2022-10-14 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: hokein, sammccall.
Herald added a subscriber: mgrang.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Creates a one to many mapping, by returning all the possible locations
providing a decl. Also includes an "is definition" signal for the
location, that can be used for ranking afterwards.

This also takes care of stdlib symbols by having a variant of locations.

Depends on D135859 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135953

Files:
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -1,10 +1,15 @@
 #include "AnalysisInternal.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/Expr.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Testing/TestAST.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Testing/Support/Annotations.h"
@@ -12,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -194,6 +200,58 @@
   testWalk("enum class E : int {};", "enum class ^E : int ;");
 }
 
+// Looks for a decl named `foo` and performs locateDecl on it. Expects all the
+// locations marked in `Code` with the right annotation to be generated.
+void testLocate(llvm::StringRef Code) {
+  llvm::Annotations Target(Code);
+
+  TestInputs Inputs(Target.code());
+  Inputs.ExtraArgs.push_back("-std=c++17");
+  TestAST AST(Inputs);
+  const auto &SM = AST.sourceManager();
+
+  const NamedDecl *Foo;
+  struct MatchCB : public ast_matchers::MatchFinder::MatchCallback {
+MatchCB(const NamedDecl *&Out) : Out(Out) {}
+void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
+  Out = Result.Nodes.getNodeAs("id");
+  assert(Out);
+  Out = llvm::cast(Out->getCanonicalDecl());
+}
+const NamedDecl *&Out;
+  } CB(Foo);
+  ast_matchers::MatchFinder Finder;
+  Finder.addMatcher(
+  ast_matchers::namedDecl(ast_matchers::unless(ast_matchers::isImplicit()),
+  ast_matchers::hasName("foo"))
+  .bind("id"),
+  &CB);
+  Finder.matchAST(AST.context());
+  ASSERT_TRUE(Foo);
+  std::vector> ReferencedOffsets;
+  for (auto Loc : locateDecl(*Foo)) {
+if (auto *SL = std::get_if(&Loc.first)) {
+  auto [FID, Offset] = SM.getDecomposedLoc(SM.getFileLoc(*SL));
+  ASSERT_EQ(FID, SM.getMainFileID());
+  ReferencedOffsets.push_back(
+  {Offset, llvm::StringRef(Loc.second ? "$def" : "")});
+} else {
+  ADD_FAILURE() << "Got stdlib symbol: " << Foo->getNameAsString();
+}
+  }
+  llvm::sort(ReferencedOffsets);
+  auto AnnotatedCode = Target.code().str();
+  for (auto [Offset, Annotation] : llvm::reverse(ReferencedOffsets))
+AnnotatedCode.insert(Offset, (Annotation + "^").str());
+  EXPECT_EQ(Code, AnnotatedCode);
+}
+
+TEST(LocateDecl, General) {
+  testLocate("struct ^foo; struct $def^foo {};");
+  testLocate("namespace ns { void ^foo(); void $def^foo() {} }");
+  testLocate("enum class ^foo; enum class $def^foo {};");
+}
+
 } // namespace
 } // namespace include_cleaner
 } // namespace clang
Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -17,6 +17,7 @@
   clangAST
   clangBasic
   clangFrontend
+  clangToolingInclusionsStdlib
   )
 
 target_link_libraries(ClangIncludeCleanerTests
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -16,8 +16,11 @@
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
+#include 
+#include 
 
 namespace clang {
 namespace include_cleaner

[PATCH] D135937: [X86] Support -march=meteorlake

2022-10-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Please add this to llvm-project\llvm\test\CodeGen\X86\cpus-intel.ll


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135937

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


[clang] ae27323 - [clang][Interp] Classify ArrayInitIndexExpr type

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T11:10:28+02:00
New Revision: ae27323428ff9666b1c4cf32e0ea928681ce778e

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

LOG: [clang][Interp] Classify ArrayInitIndexExpr type

We can't just push a uint64 unconditionally here, since on 32bit arches
we later expect a different type, e.g. uint32.

This broke e.g. these builders:
https://lab.llvm.org/buildbot#builders/171/builds/21514
https://lab.llvm.org/buildbot#builders/38/builds/6643

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index b9e7f4e2cdad..5af97ebbcf27 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -330,7 +330,9 @@ template 
 bool ByteCodeExprGen::VisitArrayInitIndexExpr(
 const ArrayInitIndexExpr *E) {
   assert(ArrayIndex);
-  return this->emitConstUint64(*ArrayIndex, E);
+  QualType IndexType = E->getType();
+  APInt Value(getIntWidth(IndexType), *ArrayIndex);
+  return this->emitConst(classifyPrim(IndexType), 0, Value, E);
 }
 
 template 



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


[clang] 7229227 - [clang][Interp][NFC] Run record tests on i686 as well

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T11:19:24+02:00
New Revision: 72292271f6635a812bef42814808f60070297268

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

LOG: [clang][Interp][NFC] Run record tests on i686 as well

So we have some test coverage on a 32bit arch.

Added: 


Modified: 
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index ae0287b1347d..8b2c92ca32ac 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple i686 
-verify %s
 // RUN: %clang_cc1 -verify=ref %s
+// RUN: %clang_cc1 -verify=ref -triple i686 %s
 
 // expected-no-diagnostics
 



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


[clang] b3d495e - [clang][Interp][NFC] Explain why tests are disabled

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T11:47:25+02:00
New Revision: b3d495e7e082c3a3c77bfcf2ed928f6f18f69fc4

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

LOG: [clang][Interp][NFC] Explain why tests are disabled

Disabled to make the buildbots happy in
c004d7534dcefcfebc3e07a7fa12f5492be80279. In C++14, the functions here
use a MaterializeTemporaryExpr, which the new constant interpreter
doesn't support yet. Add comments for this and two new RUN lines.

Added: 


Modified: 
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 8b2c92ca32ac..002ea1985923 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify 
%s
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple i686 
-verify %s
 // RUN: %clang_cc1 -verify=ref %s
+// RUN: %clang_cc1 -verify=ref -std=c++14 %s
 // RUN: %clang_cc1 -verify=ref -triple i686 %s
 
 // expected-no-diagnostics
@@ -50,7 +52,9 @@ static_assert(ints2.a == -20, "");
 static_assert(ints2.b == -30, "");
 static_assert(!ints2.c, "");
 
-#if 0
+#if __cplusplus >= 201703L
+// FIXME: In c++14, this uses a MaterializeTemporaryExpr,
+//   which the new interpreter doesn't support yet.
 constexpr Ints getInts() {
   return {64, 128, true};
 }
@@ -122,7 +126,9 @@ constexpr const C* getPointer() {
 }
 static_assert(getPointer()->a == 100, "");
 
-#if 0
+#if __cplusplus >= 201703L
+// FIXME: In c++14, this uses a MaterializeTemporaryExpr,
+//   which the new interpreter doesn't support yet.
 constexpr C RVOAndParams(const C *c) {
   return C();
 }



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


[PATCH] D135707: [clang-format] Correctly annotate star/amp in function pointer params

2022-10-14 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Thanks @rymiel its great to have another active contributor, especially one who 
seems so focused on github issues. Really appreciate your recent contributions. 
Can we start including you as one of the default reviewers that we use to 
review our stuff?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135707

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


[PATCH] D135953: [IncludeCleaner] Introduce decl to location mapping

2022-10-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/AnalysisInternal.h:64
 
+using SymbolLocation = std::variant;
+/// A set of locations that provides the declaration, while indicating if

This is an important public API concept ==> It should be documented and part of 
a public header, I think



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:167
 
+std::vector>
+locateDecl(const NamedDecl &ND) {

I don't think "definition" is the right concept here, the better signal in 
experiments was "is this declaration usable in general", which a function 
forward declaration **is**.
(In the prototype this was `IsComplete` and only set for template/class cases 
where completeness matters, `InIncomplete` is probably a bit cleaner.)

Also it would be nice to avoid passing bools around to represent subtle 
concepts (which definition is).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135953

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


[PATCH] D134523: [clang][Interp] Fix copy constructors with record array members

2022-10-14 Thread Timm Bäder 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 rG6e83209f623e: [clang][Interp] Fix copy constructors with 
record array members (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D134523?vs=463094&id=467723#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134523

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Pointer.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -164,3 +164,24 @@
   static_assert(foo() == 12, ""); // ref-error {{not an integral constant expression}} \
   // ref-note {{in call to 'foo()'}}
 };
+
+struct FourBoolPairs {
+  BoolPair v[4] = {
+{false, false},
+{false,  true},
+{true,  false},
+{true,  true },
+  };
+};
+// Init
+constexpr FourBoolPairs LT;
+// Copy ctor
+constexpr FourBoolPairs LT2 = LT;
+// FIXME: The copy constructor call above
+//   works, but APValue we generate for it is
+//   not sufficiently correct, so the lvalue-to-rvalue
+//   conversion in ExprConstant.c runs into an assertion.
+//static_assert(LT2.v[0].first == false, "");
+//static_assert(LT2.v[0].second == false, "");
+//static_assert(LT2.v[2].first == true, "");
+//static_assert(LT2.v[2].second == false, "");
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -135,6 +135,7 @@
 bool Pointer::isInitialized() const {
   assert(Pointee && "Cannot check if null pointer was initialized");
   Descriptor *Desc = getFieldDesc();
+  assert(Desc);
   if (Desc->isPrimitiveArray()) {
 if (Pointee->IsStatic)
   return true;
@@ -155,6 +156,7 @@
   assert(Pointee && "Cannot initialize null pointer");
   Descriptor *Desc = getFieldDesc();
 
+  assert(Desc);
   if (Desc->isArray()) {
 if (Desc->isPrimitiveArray() && !Pointee->IsStatic) {
   // Primitive array initializer.
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -494,7 +494,7 @@
 
 /// 1) Pops the value from the stack
 /// 2) Pops a pointer from the stack
-/// 3) Writes the value to field I of the pointer
+/// 3) Pushes the value to field I of the pointer on the stack
 template ::T>
 bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
   const T &Value = S.Stk.pop();
@@ -548,6 +548,8 @@
   return true;
 }
 
+/// 1) Pops a Pointer from the stack
+/// 2) Pushes Pointer.atField(Off) on the stack
 inline bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off) {
   const Pointer &Ptr = S.Stk.pop();
   if (!CheckNull(S, OpPC, Ptr, CSK_Field))
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -329,7 +329,10 @@
 template 
 bool ByteCodeExprGen::VisitArrayInitIndexExpr(
 const ArrayInitIndexExpr *E) {
-  assert(ArrayIndex);
+  // ArrayIndex might not be set if a ArrayInitIndexExpr is being evaluated
+  // stand-alone, e.g. via EvaluateAsInt().
+  if (!ArrayIndex)
+return false;
   QualType IndexType = E->getType();
   APInt Value(getIntWidth(IndexType), *ArrayIndex);
   return this->emitConst(classifyPrim(IndexType), 0, Value, E);
@@ -608,9 +611,15 @@
   if (const auto *InitList = dyn_cast(Initializer)) {
 unsigned ElementIndex = 0;
 for (const Expr *Init : InitList->inits()) {
-  QualType InitType = Init->getType();
-
-  if (InitType->isArrayType()) {
+  if (Optional T = classify(Init->getType())) {
+// Visit the primitive element like normal.
+if (!this->emitDupPtr(Init))
+  return false;
+if (!this->visit(Init))
+  return false;
+if (!this->emitInitElem(*T, ElementIndex, Init))
+  return false;
+  } else {
 // Advance the pointer currently on the stack to the given
 // dimension and narrow().
 if (!this->emitDupPtr(Init))
@@ -621,21 +630,12 @@
   return false;
 if (!this->emitNarrowPtr(Init))
   return false;
-if (!visitArrayInitializer(Init))
+
+if (!visitInitializer(Init))
   return false;
+  }
 if (!this->emitPopPtr(Init))
   return false;
-  } else if (Optional T = classify(InitType)) {
-// Visit the primitive element like normal.
-if (!this->emitDupPtr(Init))
-  return false;
-if (!this->visit(Init))
-  return false;
-   

[clang] 6e83209 - [clang][Interp] Fix copy constructors with record array members

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T11:57:26+02:00
New Revision: 6e83209f623e00b16f5858efbfa0fd6409abf1fe

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

LOG: [clang][Interp] Fix copy constructors with record array members

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Pointer.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5af97ebbcf27..904a99b4f872 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -329,7 +329,10 @@ bool ByteCodeExprGen::VisitMemberExpr(const 
MemberExpr *E) {
 template 
 bool ByteCodeExprGen::VisitArrayInitIndexExpr(
 const ArrayInitIndexExpr *E) {
-  assert(ArrayIndex);
+  // ArrayIndex might not be set if a ArrayInitIndexExpr is being evaluated
+  // stand-alone, e.g. via EvaluateAsInt().
+  if (!ArrayIndex)
+return false;
   QualType IndexType = E->getType();
   APInt Value(getIntWidth(IndexType), *ArrayIndex);
   return this->emitConst(classifyPrim(IndexType), 0, Value, E);
@@ -608,9 +611,15 @@ bool ByteCodeExprGen::visitArrayInitializer(const 
Expr *Initializer) {
   if (const auto *InitList = dyn_cast(Initializer)) {
 unsigned ElementIndex = 0;
 for (const Expr *Init : InitList->inits()) {
-  QualType InitType = Init->getType();
-
-  if (InitType->isArrayType()) {
+  if (Optional T = classify(Init->getType())) {
+// Visit the primitive element like normal.
+if (!this->emitDupPtr(Init))
+  return false;
+if (!this->visit(Init))
+  return false;
+if (!this->emitInitElem(*T, ElementIndex, Init))
+  return false;
+  } else {
 // Advance the pointer currently on the stack to the given
 // dimension and narrow().
 if (!this->emitDupPtr(Init))
@@ -621,21 +630,12 @@ bool 
ByteCodeExprGen::visitArrayInitializer(const Expr *Initializer) {
   return false;
 if (!this->emitNarrowPtr(Init))
   return false;
-if (!visitArrayInitializer(Init))
+
+if (!visitInitializer(Init))
   return false;
+  }
 if (!this->emitPopPtr(Init))
   return false;
-  } else if (Optional T = classify(InitType)) {
-// Visit the primitive element like normal.
-if (!this->emitDupPtr(Init))
-  return false;
-if (!this->visit(Init))
-  return false;
-if (!this->emitInitElemPop(*T, ElementIndex, Init))
-  return false;
-  } else {
-assert(false && "Unhandled type in array initializer initlist");
-  }
 
   ++ElementIndex;
 }
@@ -650,19 +650,34 @@ bool 
ByteCodeExprGen::visitArrayInitializer(const Expr *Initializer) {
 size_t Size = AILE->getArraySize().getZExtValue();
 Optional ElemT = classify(SubExpr->getType());
 
-if (!ElemT)
-  return false;
-
+// So, every iteration, we execute an assignment here
+// where the LHS is on the stack (the target array)
+// and the RHS is our SubExpr.
 for (size_t I = 0; I != Size; ++I) {
   ArrayIndexScope IndexScope(this, I);
-  if (!this->emitDupPtr(SubExpr))
-return false;
 
-  if (!this->visit(SubExpr))
+  if (!this->emitDupPtr(SubExpr)) // LHS
 return false;
 
-  if (!this->emitInitElem(*ElemT, I, Initializer))
-return false;
+  if (ElemT) {
+if (!this->visit(SubExpr))
+  return false;
+if (!this->emitInitElem(*ElemT, I, Initializer))
+  return false;
+  } else {
+// Narrow to our array element and recurse into visitInitializer()
+if (!this->emitConstUint64(I, SubExpr))
+  return false;
+
+if (!this->emitAddOffsetUint64(SubExpr))
+  return false;
+
+if (!this->emitNarrowPtr(SubExpr))
+  return false;
+
+if (!visitInitializer(SubExpr))
+  return false;
+  }
 
   if (!this->emitPopPtr(Initializer))
 return false;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 9356c572ddd9..5d5164a95f00 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -494,7 +494,7 @@ bool InitThisFieldActive(InterpState &S, CodePtr OpPC, 
uint32_t I) {
 
 /// 1) Pops the value from the stack
 /// 2) Pops a pointer from the stack
-/// 3) Writes the value to field I of the pointer
+/// 3) Pushes the value to field I of the pointer on the stack
 template ::T>
 bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
   const T &Value = S.Stk.pop();
@@ -548,6 +548,8 @@ in

[clang] 55c7ad3 - [clang][Interp][NFC] Pass Function* pointers around as const

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T12:31:24+02:00
New Revision: 55c7ad31aacb6cdef19a7296fda56cc8b177e2b4

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

LOG: [clang][Interp][NFC] Pass Function* pointers around as const

Added: 


Modified: 
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/EvalEmitter.h
clang/lib/AST/Interp/Function.h
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/InterpFrame.h
clang/lib/AST/Interp/InterpState.h
clang/lib/AST/Interp/Source.cpp
clang/lib/AST/Interp/Source.h

Removed: 




diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index aa4396f135d2..0638a68297ed 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -105,7 +105,7 @@ template  bool EvalEmitter::emitRet(const 
SourceInfo &Info) {
 template 
 bool EvalEmitter::emitCall(const Function *Func, const SourceInfo &Info) {
 
-  S.Current = new InterpFrame(S, const_cast(Func), {});
+  S.Current = new InterpFrame(S, Func, {});
   // Result of call will be on the stack and needs to be handled by the caller.
   return Interpret(S, Result);
 }
@@ -114,7 +114,7 @@ bool EvalEmitter::emitCallVoid(const Function *Func, const 
SourceInfo &Info) {
   APValue VoidResult;
   InterpFrame *before = S.Current;
   (void)before;
-  S.Current = new InterpFrame(S, const_cast(Func), {});
+  S.Current = new InterpFrame(S, Func, {});
   bool Success = Interpret(S, VoidResult);
   assert(VoidResult.isAbsent());
   assert(S.Current == before);

diff  --git a/clang/lib/AST/Interp/EvalEmitter.h 
b/clang/lib/AST/Interp/EvalEmitter.h
index 94c58ec11e2b..560ce6f6f470 100644
--- a/clang/lib/AST/Interp/EvalEmitter.h
+++ b/clang/lib/AST/Interp/EvalEmitter.h
@@ -71,7 +71,7 @@ class EvalEmitter : public SourceMapper {
   Local createLocal(Descriptor *D);
 
   /// Returns the source location of the current opcode.
-  SourceInfo getSource(Function *F, CodePtr PC) const override {
+  SourceInfo getSource(const Function *F, CodePtr PC) const override {
 return F ? F->getSource(PC) : CurrentSource;
   }
 

diff  --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h
index 1fc27ee60734..bb99ea72a442 100644
--- a/clang/lib/AST/Interp/Function.h
+++ b/clang/lib/AST/Interp/Function.h
@@ -43,7 +43,7 @@ class Scope final {
 
   Scope(LocalVectorTy &&Descriptors) : Descriptors(std::move(Descriptors)) {}
 
-  llvm::iterator_range locals() {
+  llvm::iterator_range locals() const {
 return llvm::make_range(Descriptors.begin(), Descriptors.end());
   }
 
@@ -102,18 +102,21 @@ class Function final {
   bool hasRVO() const { return HasRVO; }
 
   /// Range over the scope blocks.
-  llvm::iterator_range::iterator> scopes() {
+  llvm::iterator_range::const_iterator>
+  scopes() const {
 return llvm::make_range(Scopes.begin(), Scopes.end());
   }
 
   /// Range over argument types.
-  using arg_reverse_iterator = SmallVectorImpl::reverse_iterator;
-  llvm::iterator_range args_reverse() {
+  using arg_reverse_iterator =
+  SmallVectorImpl::const_reverse_iterator;
+  llvm::iterator_range args_reverse() const {
 return llvm::make_range(ParamTypes.rbegin(), ParamTypes.rend());
   }
 
   /// Returns a specific scope.
   Scope &getScope(unsigned Idx) { return Scopes[Idx]; }
+  const Scope &getScope(unsigned Idx) const { return Scopes[Idx]; }
 
   /// Returns the source information at a given PC.
   SourceInfo getSource(CodePtr PC) const;

diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index fb8e5cf51a95..a2320f0d2076 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -18,8 +18,8 @@
 using namespace clang;
 using namespace clang::interp;
 
-InterpFrame::InterpFrame(InterpState &S, Function *Func, InterpFrame *Caller,
- CodePtr RetPC, Pointer &&This)
+InterpFrame::InterpFrame(InterpState &S, const Function *Func,
+ InterpFrame *Caller, CodePtr RetPC, Pointer &&This)
 : Caller(Caller), S(S), Func(Func), This(std::move(This)), RetPC(RetPC),
   ArgSize(Func ? Func->getArgSize() : 0),
   Args(static_cast(S.Stk.top())), FrameOffset(S.Stk.size()) {
@@ -36,7 +36,7 @@ InterpFrame::InterpFrame(InterpState &S, Function *Func, 
InterpFrame *Caller,
   }
 }
 
-InterpFrame::InterpFrame(InterpState &S, Function *Func, CodePtr RetPC)
+InterpFrame::InterpFrame(InterpState &S, const Function *Func, CodePtr RetPC)
 : Caller(S.Current), S(S), Func(Func), RetPC(RetPC),
   ArgSize(Func ? Func->getArgSize() : 0),
   Args(static_cast(S.Stk.top())), FrameOffset(S.Stk.size()) {

diff  --git a/clang/lib/AST/Interp/InterpFrame.h 
b/clang/lib/AST/Interp/InterpF

[clang] 4d2d426 - [clang][Interp] Fix Pointer::toAPValue() LValuePath order

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T12:31:24+02:00
New Revision: 4d2d426a51e122231443d89b196b0c6e91a5b147

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

LOG: [clang][Interp] Fix Pointer::toAPValue() LValuePath order

Added: 


Modified: 
clang/lib/AST/Interp/Pointer.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index ec00afc37124..ad4e4e8a8a85 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -129,6 +129,12 @@ APValue Pointer::toAPValue() const {
 }
   }
 
+  // We assemble the LValuePath starting from the innermost pointer to the
+  // outermost one. SO in a.b.c, the first element in Path will refer to
+  // the field 'c', while later code expects it to refer to 'a'.
+  // Just invert the order of the elements.
+  std::reverse(Path.begin(), Path.end());
+
   return APValue(Base, Offset, Path, IsOnePastEnd, IsNullPtr);
 }
 

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 8839c597530c..d0a40c8d2583 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -177,11 +177,7 @@ struct FourBoolPairs {
 constexpr FourBoolPairs LT;
 // Copy ctor
 constexpr FourBoolPairs LT2 = LT;
-// FIXME: The copy constructor call above
-//   works, but APValue we generate for it is
-//   not sufficiently correct, so the lvalue-to-rvalue
-//   conversion in ExprConstant.c runs into an assertion.
-//static_assert(LT2.v[0].first == false, "");
-//static_assert(LT2.v[0].second == false, "");
-//static_assert(LT2.v[2].first == true, "");
-//static_assert(LT2.v[2].second == false, "");
+static_assert(LT2.v[0].first == false, "");
+static_assert(LT2.v[0].second == false, "");
+static_assert(LT2.v[2].first == true, "");
+static_assert(LT2.v[2].second == false, "");



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


[clang] 699449d - [clang][Interp][NFC] Use a SourceRange for errors

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T12:46:51+02:00
New Revision: 699449d71eadb1499bf6a98999c2abdaa6b1294a

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

LOG: [clang][Interp][NFC] Use a SourceRange for errors

This makes the error message generated by bail() a bit more pleasant to
read.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeGenError.h
clang/lib/AST/Interp/Context.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeGenError.h 
b/clang/lib/AST/Interp/ByteCodeGenError.h
index a4fa4917705d..af464b5ed4ab 100644
--- a/clang/lib/AST/Interp/ByteCodeGenError.h
+++ b/clang/lib/AST/Interp/ByteCodeGenError.h
@@ -20,19 +20,19 @@ namespace interp {
 /// Error thrown by the compiler.
 struct ByteCodeGenError : public llvm::ErrorInfo {
 public:
-  ByteCodeGenError(SourceLocation Loc) : Loc(Loc) {}
-  ByteCodeGenError(const Stmt *S) : ByteCodeGenError(S->getBeginLoc()) {}
-  ByteCodeGenError(const Decl *D) : ByteCodeGenError(D->getBeginLoc()) {}
+  ByteCodeGenError(SourceRange Range) : Range(Range) {}
+  ByteCodeGenError(const Stmt *S) : ByteCodeGenError(S->getSourceRange()) {}
+  ByteCodeGenError(const Decl *D) : ByteCodeGenError(D->getSourceRange()) {}
 
   void log(raw_ostream &OS) const override { OS << "unimplemented feature"; }
 
-  const SourceLocation &getLoc() const { return Loc; }
+  const SourceRange &getRange() const { return Range; }
 
   static char ID;
 
 private:
-  // Start of the item where the error occurred.
-  SourceLocation Loc;
+  // Range of the item where the error occurred.
+  SourceRange Range;
 
   // Users are not expected to use error_code.
   std::error_code convertToErrorCode() const override {

diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index 7ce3397e6a4f..a43ced4f856c 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -33,7 +33,9 @@ bool Context::isPotentialConstantExpr(State &Parent, const 
FunctionDecl *FD) {
   Func = *R;
 } else {
   handleAllErrors(R.takeError(), [&Parent](ByteCodeGenError &Err) {
-Parent.FFDiag(Err.getLoc(), 
diag::err_experimental_clang_interp_failed);
+Parent.FFDiag(Err.getRange().getBegin(),
+  diag::err_experimental_clang_interp_failed)
+<< Err.getRange();
   });
   return false;
 }
@@ -119,7 +121,9 @@ bool Context::Check(State &Parent, llvm::Expected 
&&Flag) {
   if (Flag)
 return *Flag;
   handleAllErrors(Flag.takeError(), [&Parent](ByteCodeGenError &Err) {
-Parent.FFDiag(Err.getLoc(), diag::err_experimental_clang_interp_failed);
+Parent.FFDiag(Err.getRange().getBegin(),
+  diag::err_experimental_clang_interp_failed)
+<< Err.getRange();
   });
   return false;
 }



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


[clang] 81c5b5d - [clang][Interp][NFC] Simplify Integral using constexpr if

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T12:47:07+02:00
New Revision: 81c5b5d80efab9de616d6f8e42cd007f9c16e36b

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

LOG: [clang][Interp][NFC] Simplify Integral using constexpr if

Just keep one version of the function and differentiate between
std::is_signed() and unsigned using a constexpr if, instead of having
two different versions for the signed and unsigned cases.

Added: 


Modified: 
clang/lib/AST/Interp/Integral.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 50c9d7b6cc86..b5d20fb8c49a 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -213,55 +213,38 @@ template  class Integral 
final {
   }
 
 private:
-  template 
-  static std::enable_if_t::value, bool> CheckAddUB(T A, T B,
- T &R) {
-return llvm::AddOverflow(A, B, R);
+  template  static bool CheckAddUB(T A, T B, T &R) {
+if constexpr (std::is_signed_v) {
+  return llvm::AddOverflow(A, B, R);
+} else {
+  R = A + B;
+  return false;
+}
   }
 
-  template 
-  static std::enable_if_t::value, bool> CheckAddUB(T A, T 
B,
-   T &R) {
-R = A + B;
-return false;
-  }
-
-  template 
-  static std::enable_if_t::value, bool> CheckSubUB(T A, T B,
- T &R) {
-return llvm::SubOverflow(A, B, R);
-  }
-
-  template 
-  static std::enable_if_t::value, bool> CheckSubUB(T A, T 
B,
-   T &R) {
-R = A - B;
-return false;
+  template  static bool CheckSubUB(T A, T B, T &R) {
+if constexpr (std::is_signed_v) {
+  return llvm::SubOverflow(A, B, R);
+} else {
+  R = A - B;
+  return false;
+}
   }
 
-  template 
-  static std::enable_if_t::value, bool> CheckMulUB(T A, T B,
- T &R) {
-return llvm::MulOverflow(A, B, R);
+  template  static bool CheckMulUB(T A, T B, T &R) {
+if constexpr (std::is_signed_v) {
+  return llvm::MulOverflow(A, B, R);
+} else {
+  R = A * B;
+  return false;
+}
   }
-
-  template 
-  static std::enable_if_t::value, bool> CheckMulUB(T A, T 
B,
-   T &R) {
-R = A * B;
-return false;
-  }
-
-  template 
-  static std::enable_if_t::value, bool>
-  CheckRange(int64_t V) {
-return Min <= V && V <= Max;
-  }
-
-  template 
-  static std::enable_if_t::value, bool>
-  CheckRange(int64_t V) {
-return V >= 0 && static_cast(V) <= Max;
+  template  static bool CheckRange(int64_t V) {
+if constexpr (std::is_signed_v) {
+  return Min <= V && V <= Max;
+} else {
+  return V >= 0 && static_cast(V) <= Max;
+}
   }
 };
 



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


[PATCH] D135956: [include-cleaner] Add include-cleaner tool, with initial HTML report

2022-10-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added a subscriber: mgrang.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The immediate goal is to start producing an HTML report to debug and explain
include-cleaner recommendations.
For now, this includes only the lowest-level piece: a list of the references
found in the source code.

How this fits into future ideas:

- under refs we can also show the headers providing the symbol, which includes 
match those headers etc
- we can also annotate the #include lines with which symbols they cover, and 
add whichever includes we're suggesting too
- the include-cleaner tool will likely have modes where it emits diagnostics 
and/or applies edits, so the HTML report is behind a flag


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135956

Files:
  clang-tools-extra/include-cleaner/CMakeLists.txt
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Hooks.h
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/lib/Hooks.cpp
  clang-tools-extra/include-cleaner/tool/CMakeLists.txt
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -0,0 +1,100 @@
+//===--- IncludeCleaner.cpp - standalone tool for include analysis ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "AnalysisInternal.h"
+#include "clang-include-cleaner/Hooks.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace clang {
+namespace include_cleaner {
+namespace {
+namespace cl = llvm::cl;
+
+llvm::StringRef Overview = llvm::StringLiteral(R"(
+clang-include-cleaner analyzes the #include directives in source code.
+
+It suggests removing headers that the code is not using.
+It suggests inserting headers that the code relies on, but does not include.
+These changes make the file more self-contained and (at scale) make the codebase
+easier to reason about and modify.
+
+The tool operates on *working* source code. This means it can suggest including
+headers that are only indirectly included, but cannot suggest those that are
+missing entirely. (clang-include-fixer can do this).
+)")
+   .trim();
+
+cl::OptionCategory IncludeCleaner("clang-include-cleaner");
+
+cl::opt HTMLReportPath{
+"html",
+cl::desc("Specify an output filename for an HTML report. "
+ "This describes both recommendations and reasons for changes."),
+cl::cat(IncludeCleaner),
+};
+
+class HTMLReportAction : public clang::ASTFrontendAction {
+  RecordedAST AST;
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+ StringRef File) override {
+return AST.record();
+  }
+
+  void EndSourceFile() override {
+std::error_code EC;
+llvm::raw_fd_ostream OS(HTMLReportPath, EC);
+if (EC) {
+  llvm::errs() << "Unable to write HTML report to " << HTMLReportPath
+   << ": " << EC.message() << "\n";
+  exit(1);
+}
+writeHTMLReport(AST.Ctx->getSourceManager().getMainFileID(),
+AST.TopLevelDecls, *AST.Ctx, OS);
+  }
+};
+
+} // namespace
+} // namespace include_cleaner
+} // namespace clang
+
+int main(int argc, const char **argv) {
+  using namespace clang::include_cleaner;
+
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+  auto OptionsParser =
+  clang::tooling::CommonOptionsParser::create(argc, argv, IncludeCleaner);
+  if (!OptionsParser) {
+llvm::errs() << toString(OptionsParser.takeError());
+return 1;
+  }
+
+  std::unique_ptr Factory;
+  if (HTMLReportPath.getNumOccurrences()) {
+if (OptionsParser->getSourcePathList().size() != 1) {
+  llvm::errs() << "-" << HTMLReportPath.ArgStr
+   << " requires a single input file";
+  return 1;
+}
+Factory = clang::tooling::newFrontendActionFactory();
+  } else {
+llvm::errs() << "Unimplemented\n";
+return 1;
+  }
+
+  return clang::tooling::ClangTool(OptionsParser->getCompilations(),
+   OptionsParser->getSourcePa

[clang] 5421234 - [clang][Interp] Implement bitwise not operations

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T12:57:57+02:00
New Revision: 542123465f9e523ccd82bd91ee17f407ea4b0cd1

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

LOG: [clang][Interp] Implement bitwise not operations

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 904a99b4f872..06963562638e 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1022,6 +1022,11 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
   return DiscardResult ? this->emitPop(T, E) : true;
 });
   case UO_Not:// ~x
+if (!this->Visit(SubExpr))
+  return false;
+if (Optional T = classify(E->getType()))
+  return this->emitComp(*T, E);
+return false;
   case UO_Real:   // __real x
   case UO_Imag:   // __imag x
   case UO_Extension:

diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index b5d20fb8c49a..d02b68ac8379 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -212,6 +212,11 @@ template  class Integral final 
{
 return false;
   }
 
+  static bool comp(Integral A, Integral *R) {
+*R = Integral(~A.V);
+return false;
+  }
+
 private:
   template  static bool CheckAddUB(T A, T B, T &R) {
 if constexpr (std::is_signed_v) {

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 5d5164a95f00..f94fcc955d40 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -183,6 +183,20 @@ bool Neg(InterpState &S, CodePtr OpPC) {
   return true;
 }
 
+/// 1) Pops the value from the stack.
+/// 2) Pushes the bitwise complemented value on the stack (~V).
+template ::T>
+bool Comp(InterpState &S, CodePtr OpPC) {
+  const T &Val = S.Stk.pop();
+  T Result;
+  if (!T::comp(Val, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+
+  return false;
+}
+
 
//===--===//
 // EQ, NE, GT, GE, LT, LE
 
//===--===//

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 7591c3dc7c30..64d7e31d013c 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -411,6 +411,12 @@ def Neg: Opcode {
   let HasGroup = 1;
 }
 
+// [Real] -> [Real]
+def Comp: Opcode {
+  let Types = [NumberTypeClass];
+  let HasGroup = 1;
+}
+
 
//===--===//
 // Cast.
 
//===--===//

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 5de727f005c8..592d393fad80 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -3,6 +3,10 @@
 // RUN: %clang_cc1 -std=c++11 -verify=ref %s
 // RUN: %clang_cc1 -std=c++20 -verify=ref %s
 
+#define INT_MIN (~__INT_MAX__)
+#define INT_MAX __INT_MAX__
+
+
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
 static_assert(nullptr == nullptr, "");
@@ -66,6 +70,18 @@ static_assert(!0, "");
 static_assert(-true, "");
 static_assert(-false, ""); //expected-error{{failed}} ref-error{{failed}}
 
+static_assert(~0 == -1, "");
+static_assert(~1 == -2, "");
+static_assert(~-1 == 0, "");
+static_assert(~255 == -256, "");
+static_assert(~INT_MIN == INT_MAX, "");
+static_assert(~INT_MAX == INT_MIN, "");
+
+enum E {};
+constexpr E e = static_cast(0);
+static_assert(~e == -1, "");
+
+
 constexpr int m = 10;
 constexpr const int *p = &m;
 static_assert(p != nullptr, "");



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


[clang] c9ad877 - [clang][Interp] Implement rem opcode

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T12:57:57+02:00
New Revision: c9ad877844a7fd52726ed3f11bb6e7fb90e9358e

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

LOG: [clang][Interp] Implement rem opcode

Implement an opcode to get the remainder of the divison between LHS and
RHS.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 06963562638e..1574f8b6c6c8 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -212,6 +212,8 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   return Discard(this->emitAdd(*T, BO));
 case BO_Mul:
   return Discard(this->emitMul(*T, BO));
+case BO_Rem:
+  return Discard(this->emitRem(*T, BO));
 case BO_Assign:
   if (!this->emitStore(*T, BO))
 return false;

diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index d02b68ac8379..c7e558965531 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -207,6 +207,11 @@ template  class Integral final 
{
 return CheckMulUB(A.V, B.V, R->V);
   }
 
+  static bool rem(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V % B.V);
+return false;
+  }
+
   static bool neg(Integral A, Integral *R) {
 *R = -A;
 return false;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index f94fcc955d40..4d0c7f62f46c 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -153,6 +153,39 @@ bool Mul(InterpState &S, CodePtr OpPC) {
   return AddSubMulHelper(S, OpPC, Bits, LHS, RHS);
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).
+template ::T>
+bool Rem(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  if (RHS.isZero()) {
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+return false;
+  }
+
+  if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
+APSInt LHSInt = LHS.toAPSInt();
+SmallString<32> Trunc;
+(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+const Expr *E = S.Current->getExpr(OpPC);
+S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
+return false;
+  }
+
+  const unsigned Bits = RHS.bitWidth() * 2;
+  T Result;
+  if (!T::rem(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 
//===--===//
 // Inv
 
//===--===//

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 64d7e31d013c..61f97337fd04 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -54,9 +54,13 @@ class TypeClass {
   list Types;
 }
 
-def AluTypeClass : TypeClass {
+def NumberTypeClass : TypeClass {
   let Types = [Sint8, Uint8, Sint16, Uint16, Sint32,
-   Uint32, Sint64, Uint64, Bool];
+   Uint32, Sint64, Uint64];
+}
+
+def AluTypeClass : TypeClass {
+  let Types = !listconcat(NumberTypeClass.Types, [Bool]);
 }
 
 def PtrTypeClass : TypeClass {
@@ -393,6 +397,10 @@ def SubOffset : AluOpcode;
 def Sub : AluOpcode;
 def Add : AluOpcode;
 def Mul : AluOpcode;
+def Rem : Opcode {
+  let Types = [NumberTypeClass];
+  let HasGroup = 1;
+}
 
 
 
//===--===//

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 592d393fad80..19c80f478d1a 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -161,3 +161,30 @@ namespace SizeOf {
 
 #endif
 };
+
+namespace rem {
+  static_assert(2 % 2 == 0, "");
+  static_assert(2 % 1 == 0, "");
+  static_assert(-3 % 4 == -3, "");
+  static_assert(4 % -2 == 0, "");
+  static_assert(-3 % -4 == -3, "");
+
+  constexpr int zero() { return 0; }
+  static_assert(10 % zero() == 20, ""); // ref-error {{not an integral 
constant expression}} \
+// ref-note {{division by zero}} \
+// expected-error {{not an

[clang] d704ba2 - [clang][Interp] Implement div opcode

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T12:57:57+02:00
New Revision: d704ba26b9144829f1c4905c168f6b6278c7a3e6

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

LOG: [clang][Interp] Implement div opcode

Implement an opcode for division of two integrals.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 1574f8b6c6c8..107fd77c974d 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -214,6 +214,8 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   return Discard(this->emitMul(*T, BO));
 case BO_Rem:
   return Discard(this->emitRem(*T, BO));
+case BO_Div:
+  return Discard(this->emitDiv(*T, BO));
 case BO_Assign:
   if (!this->emitStore(*T, BO))
 return false;

diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index c7e558965531..b50a567d18c7 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -212,6 +212,11 @@ template  class Integral final 
{
 return false;
   }
 
+  static bool div(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V / B.V);
+return false;
+  }
+
   static bool neg(Integral A, Integral *R) {
 *R = -A;
 return false;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 4d0c7f62f46c..6ad3a6aeaa31 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -186,6 +186,39 @@ bool Rem(InterpState &S, CodePtr OpPC) {
   return false;
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS / RHS' on the stack
+template ::T>
+bool Div(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  if (RHS.isZero()) {
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+return false;
+  }
+
+  if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
+APSInt LHSInt = LHS.toAPSInt();
+SmallString<32> Trunc;
+(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+const Expr *E = S.Current->getExpr(OpPC);
+S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
+return false;
+  }
+
+  const unsigned Bits = RHS.bitWidth() * 2;
+  T Result;
+  if (!T::div(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 
//===--===//
 // Inv
 
//===--===//

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 61f97337fd04..f47f6492fcd7 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -401,7 +401,10 @@ def Rem : Opcode {
   let Types = [NumberTypeClass];
   let HasGroup = 1;
 }
-
+def Div : Opcode {
+  let Types = [NumberTypeClass];
+  let HasGroup = 1;
+}
 
 
//===--===//
 // Unary operators.

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 19c80f478d1a..cc868266e4a2 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -188,3 +188,25 @@ namespace rem {
// expected-note {{value 2147483648 is 
outside the range}} \
 
 };
+
+namespace div {
+  constexpr int zero() { return 0; }
+  static_assert(12 / 3 == 4, "");
+  static_assert(12 / zero() == 12, ""); // ref-error {{not an integral 
constant expression}} \
+// ref-note {{division by zero}} \
+// expected-error {{not an integral 
constant expression}} \
+// expected-note {{division by zero}}
+  static_assert(12 / -3 == -4, "");
+  static_assert(-12 / 3 == -4, "");
+
+
+  constexpr int LHS = 12;
+  constexpr long unsigned RHS = 3;
+  static_assert(LHS / RHS == 4, "");
+
+  constexpr int x = INT_MIN / - 1; // ref-error {{must be initialized by a 
constant expression}} \
+   // ref-note {{value 2147483648 is outside 
the range}} \
+   // expected-error {{must be initialized by 
a c

[PATCH] D134804: [clang][Interp] Implement bitwise Not operations

2022-10-14 Thread Timm Bäder 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 rG542123465f9e: [clang][Interp] Implement bitwise not 
operations (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D134804?vs=464155&id=467731#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134804

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -3,6 +3,10 @@
 // RUN: %clang_cc1 -std=c++11 -verify=ref %s
 // RUN: %clang_cc1 -std=c++20 -verify=ref %s
 
+#define INT_MIN (~__INT_MAX__)
+#define INT_MAX __INT_MAX__
+
+
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
 static_assert(nullptr == nullptr, "");
@@ -66,6 +70,18 @@
 static_assert(-true, "");
 static_assert(-false, ""); //expected-error{{failed}} ref-error{{failed}}
 
+static_assert(~0 == -1, "");
+static_assert(~1 == -2, "");
+static_assert(~-1 == 0, "");
+static_assert(~255 == -256, "");
+static_assert(~INT_MIN == INT_MAX, "");
+static_assert(~INT_MAX == INT_MIN, "");
+
+enum E {};
+constexpr E e = static_cast(0);
+static_assert(~e == -1, "");
+
+
 constexpr int m = 10;
 constexpr const int *p = &m;
 static_assert(p != nullptr, "");
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -411,6 +411,12 @@
   let HasGroup = 1;
 }
 
+// [Real] -> [Real]
+def Comp: Opcode {
+  let Types = [NumberTypeClass];
+  let HasGroup = 1;
+}
+
 //===--===//
 // Cast.
 //===--===//
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -183,6 +183,20 @@
   return true;
 }
 
+/// 1) Pops the value from the stack.
+/// 2) Pushes the bitwise complemented value on the stack (~V).
+template ::T>
+bool Comp(InterpState &S, CodePtr OpPC) {
+  const T &Val = S.Stk.pop();
+  T Result;
+  if (!T::comp(Val, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+
+  return false;
+}
+
 //===--===//
 // EQ, NE, GT, GE, LT, LE
 //===--===//
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -212,6 +212,11 @@
 return false;
   }
 
+  static bool comp(Integral A, Integral *R) {
+*R = Integral(~A.V);
+return false;
+  }
+
 private:
   template  static bool CheckAddUB(T A, T B, T &R) {
 if constexpr (std::is_signed_v) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1022,6 +1022,11 @@
   return DiscardResult ? this->emitPop(T, E) : true;
 });
   case UO_Not:// ~x
+if (!this->Visit(SubExpr))
+  return false;
+if (Optional T = classify(E->getType()))
+  return this->emitComp(*T, E);
+return false;
   case UO_Real:   // __real x
   case UO_Imag:   // __imag x
   case UO_Extension:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134744: [clang][Interp] Implement rem opcode

2022-10-14 Thread Timm Bäder 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 rGc9ad877844a7: [clang][Interp] Implement rem opcode (authored 
by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D134744?vs=463543&id=467732#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134744

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -161,3 +161,30 @@
 
 #endif
 };
+
+namespace rem {
+  static_assert(2 % 2 == 0, "");
+  static_assert(2 % 1 == 0, "");
+  static_assert(-3 % 4 == -3, "");
+  static_assert(4 % -2 == 0, "");
+  static_assert(-3 % -4 == -3, "");
+
+  constexpr int zero() { return 0; }
+  static_assert(10 % zero() == 20, ""); // ref-error {{not an integral constant expression}} \
+// ref-note {{division by zero}} \
+// expected-error {{not an integral constant expression}} \
+// expected-note {{division by zero}}
+
+
+  static_assert(true % true == 0, "");
+  static_assert(false % true == 0, "");
+  static_assert(true % false == 10, ""); // ref-error {{not an integral constant expression}} \
+ // ref-note {{division by zero}} \
+ // expected-error {{not an integral constant expression}} \
+ // expected-note {{division by zero}}
+  constexpr int x = INT_MIN % - 1; // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{value 2147483648 is outside the range}} \
+   // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{value 2147483648 is outside the range}} \
+
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -54,9 +54,13 @@
   list Types;
 }
 
-def AluTypeClass : TypeClass {
+def NumberTypeClass : TypeClass {
   let Types = [Sint8, Uint8, Sint16, Uint16, Sint32,
-   Uint32, Sint64, Uint64, Bool];
+   Uint32, Sint64, Uint64];
+}
+
+def AluTypeClass : TypeClass {
+  let Types = !listconcat(NumberTypeClass.Types, [Bool]);
 }
 
 def PtrTypeClass : TypeClass {
@@ -393,6 +397,10 @@
 def Sub : AluOpcode;
 def Add : AluOpcode;
 def Mul : AluOpcode;
+def Rem : Opcode {
+  let Types = [NumberTypeClass];
+  let HasGroup = 1;
+}
 
 
 //===--===//
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -153,6 +153,39 @@
   return AddSubMulHelper(S, OpPC, Bits, LHS, RHS);
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).
+template ::T>
+bool Rem(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  if (RHS.isZero()) {
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+return false;
+  }
+
+  if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
+APSInt LHSInt = LHS.toAPSInt();
+SmallString<32> Trunc;
+(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+const Expr *E = S.Current->getExpr(OpPC);
+S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
+return false;
+  }
+
+  const unsigned Bits = RHS.bitWidth() * 2;
+  T Result;
+  if (!T::rem(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 //===--===//
 // Inv
 //===--===//
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -207,6 +207,11 @@
 return CheckMulUB(A.V, B.V, R->V);
   }
 
+  static bool rem(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V % B.V);
+return false;
+  }
+
   static bool neg(Integral A, Integral *R) {
 *R = -A;
 return 

[PATCH] D134749: [clang][Interp] Implement Div opcode

2022-10-14 Thread Timm Bäder 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 rGd704ba26b914: [clang][Interp] Implement div opcode (authored 
by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134749

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -188,3 +188,25 @@
// expected-note {{value 2147483648 is outside the range}} \
 
 };
+
+namespace div {
+  constexpr int zero() { return 0; }
+  static_assert(12 / 3 == 4, "");
+  static_assert(12 / zero() == 12, ""); // ref-error {{not an integral constant expression}} \
+// ref-note {{division by zero}} \
+// expected-error {{not an integral constant expression}} \
+// expected-note {{division by zero}}
+  static_assert(12 / -3 == -4, "");
+  static_assert(-12 / 3 == -4, "");
+
+
+  constexpr int LHS = 12;
+  constexpr long unsigned RHS = 3;
+  static_assert(LHS / RHS == 4, "");
+
+  constexpr int x = INT_MIN / - 1; // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{value 2147483648 is outside the range}} \
+   // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{value 2147483648 is outside the range}} \
+
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -401,7 +401,10 @@
   let Types = [NumberTypeClass];
   let HasGroup = 1;
 }
-
+def Div : Opcode {
+  let Types = [NumberTypeClass];
+  let HasGroup = 1;
+}
 
 //===--===//
 // Unary operators.
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -186,6 +186,39 @@
   return false;
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS / RHS' on the stack
+template ::T>
+bool Div(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  if (RHS.isZero()) {
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+S.FFDiag(Loc, diag::note_expr_divide_by_zero);
+return false;
+  }
+
+  if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
+APSInt LHSInt = LHS.toAPSInt();
+SmallString<32> Trunc;
+(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+const Expr *E = S.Current->getExpr(OpPC);
+S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
+return false;
+  }
+
+  const unsigned Bits = RHS.bitWidth() * 2;
+  T Result;
+  if (!T::div(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 //===--===//
 // Inv
 //===--===//
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -212,6 +212,11 @@
 return false;
   }
 
+  static bool div(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V / B.V);
+return false;
+  }
+
   static bool neg(Integral A, Integral *R) {
 *R = -A;
 return false;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -214,6 +214,8 @@
   return Discard(this->emitMul(*T, BO));
 case BO_Rem:
   return Discard(this->emitRem(*T, BO));
+case BO_Div:
+  return Discard(this->emitDiv(*T, BO));
 case BO_Assign:
   if (!this->emitStore(*T, BO))
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134629: [clang][Interp] Fix Pointer::toAPValue() LValuePath order

2022-10-14 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder closed this revision.
tbaeder added a comment.

Meh, looks like I forgot to fix up the commit message for 
https://github.com/llvm/llvm-project/commit/4d2d426a51e122231443d89b196b0c6e91a5b147.


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

https://reviews.llvm.org/D134629

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


[PATCH] D135956: [include-cleaner] Add include-cleaner tool, with initial HTML report

2022-10-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall added reviewers: kadircet, hokein.
sammccall added a comment.

Demo: 
https://htmlpreview.github.io/?https://gist.githubusercontent.com/sam-mccall/0cc7dd1f6c5605837966cb113babe591/raw/7c9a29142eca1fc1f486540f255586a0f72a9c9e/AST.html

This is missing tests, my plan is:

- add some basic smoke tests of `include-cleaner -html` via lit
- don't do any additional direct testing of writeHTMLReport
- add unit tests for RecordedAST (this is part of the public API that's used 
when you don't have something like clangd tracking decls already)

Will add those after initial feedback of whether this is the right thing at all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135956

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


[PATCH] D134801: [clang][Interp] Implement ConditionalOperators

2022-10-14 Thread Timm Bäder 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 rG77aaf469a7ae: [clang][Interp] Implement ConditionalOperators 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D134801?vs=464165&id=467738#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134801

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/literals.cpp
  clang/test/SemaCXX/constexpr-factorial.cpp

Index: clang/test/SemaCXX/constexpr-factorial.cpp
===
--- clang/test/SemaCXX/constexpr-factorial.cpp
+++ clang/test/SemaCXX/constexpr-factorial.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fexperimental-new-constant-interpreter %s
 
 constexpr unsigned oddfac(unsigned n) {
   return n == 1 ? 1 : n * oddfac(n-2);
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -210,3 +210,54 @@
// expected-note {{value 2147483648 is outside the range}} \
 
 };
+
+namespace cond {
+  constexpr bool isEven(int n) {
+return n % 2 == 0 ? true : false;
+  }
+  static_assert(isEven(2), "");
+  static_assert(!isEven(3), "");
+  static_assert(isEven(100), "");
+
+  constexpr int M = 5 ? 10 : 20;
+  static_assert(M == 10, "");
+
+  static_assert(5 ? 13 : 16 == 13, "");
+  static_assert(0 ? 13 : 16 == 16, "");
+
+  static_assert(number ?: -15 == number, "");
+  static_assert(0 ?: 100 == 100 , "");
+
+#if __cplusplus >= 201402L
+  constexpr int N = 20;
+  constexpr int foo() {
+int m = N > 0 ? 5 : 10;
+
+return m == 5 ? isEven(m) : true;
+  }
+  static_assert(foo() == false, "");
+
+  constexpr int dontCallMe(unsigned m) {
+if (m == 0) return 0;
+return dontCallMe(m - 2);
+  }
+
+  // Can't call this because it will run into infinite recursion.
+  constexpr int assertNotReached() {
+return dontCallMe(3);
+  }
+
+  constexpr int testCond() {
+return true ? 5 : assertNotReached();
+  }
+
+  constexpr int testCond2() {
+return false ? assertNotReached() : 10;
+  }
+
+  static_assert(testCond() == 5, "");
+  static_assert(testCond2() == 10, "");
+
+#endif
+
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -88,6 +88,7 @@
   bool VisitMemberExpr(const MemberExpr *E);
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E);
   bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
+  bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -347,6 +347,37 @@
   return this->visit(E->getSourceExpr());
 }
 
+template 
+bool ByteCodeExprGen::VisitAbstractConditionalOperator(
+const AbstractConditionalOperator *E) {
+  const Expr *Condition = E->getCond();
+  const Expr *TrueExpr = E->getTrueExpr();
+  const Expr *FalseExpr = E->getFalseExpr();
+
+  LabelTy LabelEnd = this->getLabel();   // Label after the operator.
+  LabelTy LabelFalse = this->getLabel(); // Label for the false expr.
+
+  if (!this->visit(Condition))
+return false;
+  if (!this->jumpFalse(LabelFalse))
+return false;
+
+  if (!this->visit(TrueExpr))
+return false;
+  if (!this->jump(LabelEnd))
+return false;
+
+  this->emitLabel(LabelFalse);
+
+  if (!this->visit(FalseExpr))
+return false;
+
+  this->fallthrough(LabelEnd);
+  this->emitLabel(LabelEnd);
+
+  return true;
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) {
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 77aaf46 - [clang][Interp] Implement ConditionalOperators

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T13:16:10+02:00
New Revision: 77aaf469a7ae5af26a8fe92ed9d548404831d3ed

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

LOG: [clang][Interp] Implement ConditionalOperators

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/literals.cpp
clang/test/SemaCXX/constexpr-factorial.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 107fd77c974d6..2a25380df6072 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -347,6 +347,37 @@ bool ByteCodeExprGen::VisitOpaqueValueExpr(const 
OpaqueValueExpr *E) {
   return this->visit(E->getSourceExpr());
 }
 
+template 
+bool ByteCodeExprGen::VisitAbstractConditionalOperator(
+const AbstractConditionalOperator *E) {
+  const Expr *Condition = E->getCond();
+  const Expr *TrueExpr = E->getTrueExpr();
+  const Expr *FalseExpr = E->getFalseExpr();
+
+  LabelTy LabelEnd = this->getLabel();   // Label after the operator.
+  LabelTy LabelFalse = this->getLabel(); // Label for the false expr.
+
+  if (!this->visit(Condition))
+return false;
+  if (!this->jumpFalse(LabelFalse))
+return false;
+
+  if (!this->visit(TrueExpr))
+return false;
+  if (!this->jump(LabelEnd))
+return false;
+
+  this->emitLabel(LabelFalse);
+
+  if (!this->visit(FalseExpr))
+return false;
+
+  this->fallthrough(LabelEnd);
+  this->emitLabel(LabelEnd);
+
+  return true;
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 32ff72aa36fb8..5e5bbbd6948aa 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -88,6 +88,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitMemberExpr(const MemberExpr *E);
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E);
   bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
+  bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index cc868266e4a28..f11107c0efb76 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -210,3 +210,54 @@ namespace div {
// expected-note {{value 2147483648 is 
outside the range}} \
 
 };
+
+namespace cond {
+  constexpr bool isEven(int n) {
+return n % 2 == 0 ? true : false;
+  }
+  static_assert(isEven(2), "");
+  static_assert(!isEven(3), "");
+  static_assert(isEven(100), "");
+
+  constexpr int M = 5 ? 10 : 20;
+  static_assert(M == 10, "");
+
+  static_assert(5 ? 13 : 16 == 13, "");
+  static_assert(0 ? 13 : 16 == 16, "");
+
+  static_assert(number ?: -15 == number, "");
+  static_assert(0 ?: 100 == 100 , "");
+
+#if __cplusplus >= 201402L
+  constexpr int N = 20;
+  constexpr int foo() {
+int m = N > 0 ? 5 : 10;
+
+return m == 5 ? isEven(m) : true;
+  }
+  static_assert(foo() == false, "");
+
+  constexpr int dontCallMe(unsigned m) {
+if (m == 0) return 0;
+return dontCallMe(m - 2);
+  }
+
+  // Can't call this because it will run into infinite recursion.
+  constexpr int assertNotReached() {
+return dontCallMe(3);
+  }
+
+  constexpr int testCond() {
+return true ? 5 : assertNotReached();
+  }
+
+  constexpr int testCond2() {
+return false ? assertNotReached() : 10;
+  }
+
+  static_assert(testCond() == 5, "");
+  static_assert(testCond2() == 10, "");
+
+#endif
+
+};

diff  --git a/clang/test/SemaCXX/constexpr-factorial.cpp 
b/clang/test/SemaCXX/constexpr-factorial.cpp
index b6cdde59d3fa2..3f9928bb20ea7 100644
--- a/clang/test/SemaCXX/constexpr-factorial.cpp
+++ b/clang/test/SemaCXX/constexpr-factorial.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only 
-fexperimental-new-constant-interpreter %s
 
 constexpr unsigned oddfac(unsigned n) {
   return n == 1 ? 1 : n * oddfac(n-2);



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


[PATCH] D135397: [clang][dataflow] Add support for a Top value in boolean formulas.

2022-10-14 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.



Comment at: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp:69
 
-TEST(SolverTest, UnitConflict) {
-  ConstraintContext Ctx;

Why delete this test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135397

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


[clang] 0e69014 - [clang][Interp][NFC] Add a failing test case

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T13:31:52+02:00
New Revision: 0e6901421247b1c7ce0a2e925666d5314a34fffa

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

LOG: [clang][Interp][NFC] Add a failing test case

Added: 


Modified: 
clang/test/AST/Interp/cxx20.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index e088f6bafb7e..1b1a613b34b6 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -60,3 +60,21 @@ constexpr int unInitLocal() {
 static_assert(unInitLocal() == 0, ""); // expected-error {{not an integral 
constant expression}} \
// ref-error {{not an integral constant 
expression}} \
// ref-note {{in call to 
'unInitLocal()'}}
+
+/// TODO: The example above is correctly rejected by the new constexpr
+///   interpreter, but for the wrong reasons. We don't reject it because
+///   it is an uninitialized read, we reject it simply because
+///   the local variable does not have an initializer.
+///
+///   The code below should be accepted but is also being rejected
+///   right now.
+#if 0
+constexpr int initializedLocal() {
+  int a;
+  int b;
+
+  a = 20;
+  return a;
+}
+static_assert(initializedLocal() == 20);
+#endif



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


[clang] 9b2f2d8 - [clang][Interp][NFC] Remove unused function

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T13:32:00+02:00
New Revision: 9b2f2d846345dfbc4256db1ebf2b6176553fa157

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

LOG: [clang][Interp][NFC] Remove unused function

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 2a25380df607..448bea9ab267 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -815,18 +815,6 @@ bool ByteCodeExprGen::visitInitializer(const Expr 
*Initializer) {
   return this->Visit(Initializer);
 }
 
-template 
-bool ByteCodeExprGen::getPtrVarDecl(const VarDecl *VD, const Expr *E) 
{
-  // Generate a pointer to the local, loading refs.
-  if (Optional Idx = getGlobalIdx(VD)) {
-if (VD->getType()->isReferenceType())
-  return this->emitGetGlobalPtr(*Idx, E);
-else
-  return this->emitGetPtrGlobal(*Idx, E);
-  }
-  return this->bail(VD);
-}
-
 template 
 llvm::Optional
 ByteCodeExprGen::getGlobalIdx(const VarDecl *VD) {

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 5e5bbbd6948a..f55ac2ff433b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -243,9 +243,6 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 return emitConst(*Ctx.classify(Ty), NumBits, WrappedValue, E);
   }
 
-  /// Returns a pointer to a variable declaration.
-  bool getPtrVarDecl(const VarDecl *VD, const Expr *E);
-
   /// Returns the index of a global.
   llvm::Optional getGlobalIdx(const VarDecl *VD);
 



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


[clang] 7fbfe55 - [clang][Interp][NFC] Rename a parameter to be more descriptive

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T13:32:31+02:00
New Revision: 7fbfe5518c363da8ee7eb60352948f0e904f283b

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

LOG: [clang][Interp][NFC] Rename a parameter to be more descriptive

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/ByteCodeEmitter.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index 7fa189ad0806..d653da31d162 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -19,9 +19,11 @@ using namespace clang::interp;
 using APSInt = llvm::APSInt;
 using Error = llvm::Error;
 
-Expected ByteCodeEmitter::compileFunc(const FunctionDecl *F) {
+Expected
+ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
   // Do not try to compile undefined functions.
-  if (!F->isDefined(F) || (!F->hasBody() && F->willHaveBody()))
+  if (!FuncDecl->isDefined(FuncDecl) ||
+  (!FuncDecl->hasBody() && FuncDecl->willHaveBody()))
 return nullptr;
 
   // Set up argument indices.
@@ -32,7 +34,7 @@ Expected ByteCodeEmitter::compileFunc(const 
FunctionDecl *F) {
   // If the return is not a primitive, a pointer to the storage where the value
   // is initialized in is passed as the first argument.
   // See 'RVO' elsewhere in the code.
-  QualType Ty = F->getReturnType();
+  QualType Ty = FuncDecl->getReturnType();
   bool HasRVO = false;
   if (!Ty->isVoidType() && !Ctx.classify(Ty)) {
 HasRVO = true;
@@ -44,7 +46,8 @@ Expected ByteCodeEmitter::compileFunc(const 
FunctionDecl *F) {
   // the 'this' pointer. This parameter is pop()ed from the
   // InterStack when calling the function.
   bool HasThisPointer = false;
-  if (const auto *MD = dyn_cast(F); MD && MD->isInstance()) {
+  if (const auto *MD = dyn_cast(FuncDecl);
+  MD && !MD->isStatic()) {
 HasThisPointer = true;
 ParamTypes.push_back(PT_Ptr);
 ParamOffset += align(primSize(PT_Ptr));
@@ -52,7 +55,7 @@ Expected ByteCodeEmitter::compileFunc(const 
FunctionDecl *F) {
 
   // Assign descriptors to all parameters.
   // Composite objects are lowered to pointers.
-  for (const ParmVarDecl *PD : F->parameters()) {
+  for (const ParmVarDecl *PD : FuncDecl->parameters()) {
 PrimType Ty;
 if (llvm::Optional T = Ctx.classify(PD->getType())) {
   Ty = *T;
@@ -69,10 +72,10 @@ Expected ByteCodeEmitter::compileFunc(const 
FunctionDecl *F) {
 
   // Create a handle over the emitted code.
   Function *Func =
-  P.createFunction(F, ParamOffset, std::move(ParamTypes),
+  P.createFunction(FuncDecl, ParamOffset, std::move(ParamTypes),
std::move(ParamDescriptors), HasThisPointer, HasRVO);
   // Compile the function body.
-  if (!F->isConstexpr() || !visitFunc(F)) {
+  if (!FuncDecl->isConstexpr() || !visitFunc(FuncDecl)) {
 // Return a dummy function if compilation failed.
 if (BailLocation)
   return llvm::make_error(*BailLocation);

diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.h 
b/clang/lib/AST/Interp/ByteCodeEmitter.h
index 03452a350c96..e560d0ef38dd 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.h
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.h
@@ -37,7 +37,7 @@ class ByteCodeEmitter {
 
 public:
   /// Compiles the function into the module.
-  llvm::Expected compileFunc(const FunctionDecl *F);
+  llvm::Expected compileFunc(const FunctionDecl *FuncDecl);
 
 protected:
   ByteCodeEmitter(Context &Ctx, Program &P) : Ctx(Ctx), P(P) {}



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


[clang] 1b731bd - [clang][Interp][NFC] Zero-initialize Function::FrameSize

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T13:32:55+02:00
New Revision: 1b731bd8724c2f56550f87d3c4f0fa820b8b4527

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

LOG: [clang][Interp][NFC] Zero-initialize Function::FrameSize

It's never going to be used since it's only uninitialized if the
function is invalid, but let's zero it for readbility of
Function::dump().

Added: 


Modified: 
clang/lib/AST/Interp/Function.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h
index bb99ea72a442..67a4e27b3753 100644
--- a/clang/lib/AST/Interp/Function.h
+++ b/clang/lib/AST/Interp/Function.h
@@ -167,7 +167,7 @@ class Function final {
   /// Declaration this function was compiled from.
   const FunctionDecl *F;
   /// Local area size: storage + metadata.
-  unsigned FrameSize;
+  unsigned FrameSize = 0;
   /// Size of the argument stack.
   unsigned ArgSize;
   /// Program code.



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


[clang] 11f3604 - [clang][Interp][NFC] Remove an unnecessary local variable

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T13:33:04+02:00
New Revision: 11f360469599e5c7c470b2071692fc6647cf3280

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

LOG: [clang][Interp][NFC] Remove an unnecessary local variable

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 448bea9ab267..d504ff36bb99 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1063,7 +1063,6 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 template 
 bool ByteCodeExprGen::VisitDeclRefExpr(const DeclRefExpr *E) {
   const auto *Decl = E->getDecl();
-  bool IsReference = Decl->getType()->isReferenceType();
   bool FoundDecl = false;
 
   if (auto It = Locals.find(Decl); It != Locals.end()) {
@@ -1094,7 +1093,7 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   // References are implemented using pointers, so when we get here,
   // we have a pointer to a pointer, which we need to de-reference once.
   if (FoundDecl) {
-if (IsReference) {
+if (Decl->getType()->isReferenceType()) {
   if (!this->emitLoadPopPtr(E))
 return false;
 }



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


[PATCH] D135012: [clang][Interp] Implement bitwise and operations

2022-10-14 Thread Timm Bäder 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 rG62a58050ba0a: [clang][Interp] Implement bitwise and 
operations (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D135012?vs=464902&id=467744#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135012

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -261,3 +261,11 @@
 #endif
 
 };
+
+namespace band {
+  static_assert((10 & 1) == 0, "");
+  static_assert((10 & 10) == 10, "");
+
+  static_assert((1337 & -1) == 1337, "");
+  static_assert((0 & gimme(12)) == 0, "");
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -59,6 +59,11 @@
Uint32, Sint64, Uint64];
 }
 
+def IntegerTypeClass : TypeClass {
+  let Types = [Sint8, Uint8, Sint16, Uint16, Sint32,
+   Uint32, Sint64, Uint64];
+}
+
 def AluTypeClass : TypeClass {
   let Types = !listconcat(NumberTypeClass.Types, [Bool]);
 }
@@ -103,6 +108,11 @@
   let HasGroup = 1;
 }
 
+class IntegerOpcode : Opcode {
+  let Types = [IntegerTypeClass];
+  let HasGroup = 1;
+}
+
 //===--===//
 // Jump opcodes
 //===--===//
@@ -401,6 +411,7 @@
   let Types = [NumberTypeClass];
   let HasGroup = 1;
 }
+def BitAnd : IntegerOpcode;
 def Div : Opcode {
   let Types = [NumberTypeClass];
   let HasGroup = 1;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -153,6 +153,23 @@
   return AddSubMulHelper(S, OpPC, Bits, LHS, RHS);
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS & RHS' on the stack
+template ::T>
+bool BitAnd(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  unsigned Bits = RHS.bitWidth();
+  T Result;
+  if (!T::bitAnd(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 /// 1) Pops the RHS from the stack.
 /// 2) Pops the LHS from the stack.
 /// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -217,6 +217,11 @@
 return false;
   }
 
+  static bool bitAnd(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V & B.V);
+return false;
+  }
+
   static bool neg(Integral A, Integral *R) {
 *R = -A;
 return false;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -220,6 +220,11 @@
   if (!this->emitStore(*T, BO))
 return false;
   return DiscardResult ? this->emitPopPtr(BO) : true;
+case BO_And:
+  return Discard(this->emitBitAnd(*T, BO));
+case BO_Or:
+case BO_LAnd:
+case BO_LOr:
 default:
   return this->bail(BO);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 62a5805 - [clang][Interp] Implement bitwise and operations

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T14:00:07+02:00
New Revision: 62a58050ba0afad5c1ca59195f10c6fdc0e0feaa

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

LOG: [clang][Interp] Implement bitwise and operations

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d504ff36bb99..820f2f56adaf 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -220,6 +220,11 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   if (!this->emitStore(*T, BO))
 return false;
   return DiscardResult ? this->emitPopPtr(BO) : true;
+case BO_And:
+  return Discard(this->emitBitAnd(*T, BO));
+case BO_Or:
+case BO_LAnd:
+case BO_LOr:
 default:
   return this->bail(BO);
 }

diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index b50a567d18c7..4e7fff63b4b1 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -217,6 +217,11 @@ template  class Integral final 
{
 return false;
   }
 
+  static bool bitAnd(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V & B.V);
+return false;
+  }
+
   static bool neg(Integral A, Integral *R) {
 *R = -A;
 return false;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 6ad3a6aeaa31..073c7db428b0 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -153,6 +153,23 @@ bool Mul(InterpState &S, CodePtr OpPC) {
   return AddSubMulHelper(S, OpPC, Bits, LHS, RHS);
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS & RHS' on the stack
+template ::T>
+bool BitAnd(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  unsigned Bits = RHS.bitWidth();
+  T Result;
+  if (!T::bitAnd(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 /// 1) Pops the RHS from the stack.
 /// 2) Pops the LHS from the stack.
 /// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index f47f6492fcd7..11d069ccd78d 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -59,6 +59,11 @@ def NumberTypeClass : TypeClass {
Uint32, Sint64, Uint64];
 }
 
+def IntegerTypeClass : TypeClass {
+  let Types = [Sint8, Uint8, Sint16, Uint16, Sint32,
+   Uint32, Sint64, Uint64];
+}
+
 def AluTypeClass : TypeClass {
   let Types = !listconcat(NumberTypeClass.Types, [Bool]);
 }
@@ -103,6 +108,11 @@ class AluOpcode : Opcode {
   let HasGroup = 1;
 }
 
+class IntegerOpcode : Opcode {
+  let Types = [IntegerTypeClass];
+  let HasGroup = 1;
+}
+
 
//===--===//
 // Jump opcodes
 
//===--===//
@@ -401,6 +411,7 @@ def Rem : Opcode {
   let Types = [NumberTypeClass];
   let HasGroup = 1;
 }
+def BitAnd : IntegerOpcode;
 def Div : Opcode {
   let Types = [NumberTypeClass];
   let HasGroup = 1;

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index f11107c0efb7..1e1ef49a2f39 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -261,3 +261,11 @@ namespace cond {
 #endif
 
 };
+
+namespace band {
+  static_assert((10 & 1) == 0, "");
+  static_assert((10 & 10) == 10, "");
+
+  static_assert((1337 & -1) == 1337, "");
+  static_assert((0 & gimme(12)) == 0, "");
+};



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


[PATCH] D135397: [clang][dataflow] Add support for a Top value in boolean formulas.

2022-10-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 467746.
ymandel marked an inline comment as done.
ymandel added a comment.

Adding back accidentally deleted test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135397

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
 #include "clang/Analysis/FlowSensitive/NoopAnalysis.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
@@ -166,7 +167,7 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const auto *S = CS->getStmt();
 if (auto *C = dyn_cast(S)) {
   if (auto *F = dyn_cast(C->getCalleeDecl())) {
 E.CalledFunctions.insert(F->getNameInfo().getAsString());
@@ -310,6 +311,9 @@
 }
 
 // Models an analysis that uses flow conditions.
+//
+// FIXME: Here and below: change class to final and final methods to override,
+// since we're marking them all as final.
 class SpecialBoolAnalysis
 : public DataflowAnalysis {
 public:
@@ -322,7 +326,7 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const auto *S = CS->getStmt();
 auto SpecialBoolRecordDecl = recordDecl(hasName("SpecialBool"));
 auto HasSpecialBoolType = hasType(SpecialBoolRecordDecl);
 
@@ -468,9 +472,8 @@
 class OptionalIntAnalysis
 : public DataflowAnalysis {
 public:
-  explicit OptionalIntAnalysis(ASTContext &Context, BoolValue &HasValueTop)
-  : DataflowAnalysis(Context),
-HasValueTop(HasValueTop) {}
+  explicit OptionalIntAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {}
 
   static NoopLattice initialElement() { return {}; }
 
@@ -478,22 +481,23 @@
 auto CS = Elt->getAs();
 if (!CS)
   return;
-auto S = CS->getStmt();
+const Stmt *S = CS->getStmt();
 auto OptionalIntRecordDecl = recordDecl(hasName("OptionalInt"));
 auto HasOptionalIntType = hasType(OptionalIntRecordDecl);
 
+SmallVector Matches = match(
+stmt(anyOf(cxxConstructExpr(HasOptionalIntType).bind("construct"),
+   cxxOperatorCallExpr(
+   callee(cxxMethodDecl(ofClass(OptionalIntRecordDecl
+   .bind("operator"))),
+*S, getASTContext());
 if (const auto *E = selectFirst(
-"call", match(cxxConstructExpr(HasOptionalIntType).bind("call"), *S,
-  getASTContext( {
+"construct", Matches)) {
   auto &ConstructorVal = *Env.createValue(E->getType());
   ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(false));
   Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), ConstructorVal);
-} else if (const auto *E = selectFirst(
-   "call",
-   match(cxxOperatorCallExpr(callee(cxxMethodDecl(ofClass(
- OptionalIntRecordDecl
- .bind("call"),
- *S, getASTContext( {
+} else if (const auto *E =
+   selectFirst("operator", Matches)) {
   assert(E->getNumArgs() > 0);
   auto *Object = E->getArg(0);
   assert(Object != nullptr);
@@ -516,7 +520,11 @@
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != "OptionalInt")
   return false;
 
-return Val1.getProperty("has_value") == Val2.getProperty("has_value");
+auto *Prop1  = Val1.getProperty("has_value");
+auto *Prop2 = Val2.getProperty("has_value");
+return Prop1 == Prop2 ||
+   (Prop1 != nullptr && Prop2 != nullptr && isa(Prop1) &&
+isa(Prop2));
   }
 
   bool merge(QualType Type, const Value &Val1, const Environment &Env1,
@@ -538,11 +54

[PATCH] D135397: [clang][dataflow] Add support for a Top value in boolean formulas.

2022-10-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked an inline comment as done.
ymandel added inline comments.



Comment at: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp:69
 
-TEST(SolverTest, UnitConflict) {
-  ConstraintContext Ctx;

gribozavr2 wrote:
> Why delete this test?
That was a mistake. I've added it back


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135397

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


[clang] ce4d5ae - [clang][Interp] Implement bitwise Or operations

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T14:15:08+02:00
New Revision: ce4d5ae9dcf64deade70f305b8d7ab8d0dc80102

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

LOG: [clang][Interp] Implement bitwise Or operations

Analogous to the bitAnd implementation, do the same for bitwise or.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 820f2f56adaf..6edf1c450fa3 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -223,6 +223,7 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
 case BO_And:
   return Discard(this->emitBitAnd(*T, BO));
 case BO_Or:
+  return Discard(this->emitBitOr(*T, BO));
 case BO_LAnd:
 case BO_LOr:
 default:

diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 4e7fff63b4b1..9ee9fd6d7fd8 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -222,6 +222,11 @@ template  class Integral final 
{
 return false;
   }
 
+  static bool bitOr(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V | B.V);
+return false;
+  }
+
   static bool neg(Integral A, Integral *R) {
 *R = -A;
 return false;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 073c7db428b0..c9a508448e31 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -170,6 +170,23 @@ bool BitAnd(InterpState &S, CodePtr OpPC) {
   return false;
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS | RHS' on the stack
+template ::T>
+bool BitOr(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  unsigned Bits = RHS.bitWidth();
+  T Result;
+  if (!T::bitOr(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 /// 1) Pops the RHS from the stack.
 /// 2) Pops the LHS from the stack.
 /// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 11d069ccd78d..767ab98f4fc4 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -412,6 +412,7 @@ def Rem : Opcode {
   let HasGroup = 1;
 }
 def BitAnd : IntegerOpcode;
+def BitOr : IntegerOpcode;
 def Div : Opcode {
   let Types = [NumberTypeClass];
   let HasGroup = 1;

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 1e1ef49a2f39..f0083e63f35d 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -269,3 +269,12 @@ namespace band {
   static_assert((1337 & -1) == 1337, "");
   static_assert((0 & gimme(12)) == 0, "");
 };
+
+namespace bitOr {
+  static_assert((10 | 1) == 11, "");
+  static_assert((10 | 10) == 10, "");
+
+  static_assert((1337 | -1) == -1, "");
+  static_assert((0 | gimme(12)) == 12, "");
+  static_assert((12 | true) == 13, "");
+};



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


[PATCH] D135361: [clang][Interp] Implement bitwise Or operations

2022-10-14 Thread Timm Bäder 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 rGce4d5ae9dcf6: [clang][Interp] Implement bitwise Or 
operations (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D135361?vs=465711&id=467747#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135361

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -269,3 +269,12 @@
   static_assert((1337 & -1) == 1337, "");
   static_assert((0 & gimme(12)) == 0, "");
 };
+
+namespace bitOr {
+  static_assert((10 | 1) == 11, "");
+  static_assert((10 | 10) == 10, "");
+
+  static_assert((1337 | -1) == -1, "");
+  static_assert((0 | gimme(12)) == 12, "");
+  static_assert((12 | true) == 13, "");
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -412,6 +412,7 @@
   let HasGroup = 1;
 }
 def BitAnd : IntegerOpcode;
+def BitOr : IntegerOpcode;
 def Div : Opcode {
   let Types = [NumberTypeClass];
   let HasGroup = 1;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -170,6 +170,23 @@
   return false;
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS | RHS' on the stack
+template ::T>
+bool BitOr(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  unsigned Bits = RHS.bitWidth();
+  T Result;
+  if (!T::bitOr(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 /// 1) Pops the RHS from the stack.
 /// 2) Pops the LHS from the stack.
 /// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -222,6 +222,11 @@
 return false;
   }
 
+  static bool bitOr(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V | B.V);
+return false;
+  }
+
   static bool neg(Integral A, Integral *R) {
 *R = -A;
 return false;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -223,6 +223,7 @@
 case BO_And:
   return Discard(this->emitBitAnd(*T, BO));
 case BO_Or:
+  return Discard(this->emitBitOr(*T, BO));
 case BO_LAnd:
 case BO_LOr:
 default:


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -269,3 +269,12 @@
   static_assert((1337 & -1) == 1337, "");
   static_assert((0 & gimme(12)) == 0, "");
 };
+
+namespace bitOr {
+  static_assert((10 | 1) == 11, "");
+  static_assert((10 | 10) == 10, "");
+
+  static_assert((1337 | -1) == -1, "");
+  static_assert((0 | gimme(12)) == 12, "");
+  static_assert((12 | true) == 13, "");
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -412,6 +412,7 @@
   let HasGroup = 1;
 }
 def BitAnd : IntegerOpcode;
+def BitOr : IntegerOpcode;
 def Div : Opcode {
   let Types = [NumberTypeClass];
   let HasGroup = 1;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -170,6 +170,23 @@
   return false;
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS | RHS' on the stack
+template ::T>
+bool BitOr(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  unsigned Bits = RHS.bitWidth();
+  T Result;
+  if (!T::bitOr(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 /// 1) Pops the RHS from the stack.
 /// 2) Pops the LHS from the stack.
 /// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -222,

[clang] 19e984e - Properly print unnamed TagDecl objects in diagnostics

2022-10-14 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-10-14T08:18:28-04:00
New Revision: 19e984ef8f49bc3ccced15621989fa9703b2cd5b

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

LOG: Properly print unnamed TagDecl objects in diagnostics

The diagnostics engine is very smart about being passed a NamedDecl to
print as part of a diagnostic; it gets the "right" form of the name,
quotes it properly, etc. However, the result of using an unnamed tag
declaration was to print '' instead of anything useful.

This patch causes us to print the same information we'd have gotten if
we had printed the type of the declaration rather than the name of it,
as that's the most relevant information we can display.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/DeclTemplate.h
clang/lib/AST/ASTDiagnostic.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/DeclTemplate.cpp
clang/lib/AST/NestedNameSpecifier.cpp
clang/lib/AST/TemplateName.cpp
clang/lib/CodeGen/CodeGenTypes.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/AST/ast-dump-record-definition-data-json.cpp
clang/test/ExtractAPI/enum.c
clang/test/Index/annotate-comments-typedef.m
clang/test/Index/c-index-api-loadTU-test.m
clang/test/Index/c-index-getCursor-test.m
clang/test/Index/print-type.c
clang/test/Index/print-type.cpp
clang/test/Index/targeted-annotation.c
clang/test/Index/targeted-cursor.c
clang/test/Index/usrs.m
clang/test/Sema/address-packed.c
clang/test/Sema/attr-flag-enum.c
clang/test/SemaCXX/attr-unused.cpp
clang/test/SemaCXX/lambda-expressions.cpp
clang/test/SemaCXX/ms-interface.cpp
clang/test/SemaObjCXX/arc-0x.mm
clang/test/Templight/templight-empty-entries-fix.cpp
clang/unittests/AST/ASTTraverserTest.cpp
llvm/utils/lit/lit/TestRunner.py

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 57838eafd6512..336572aede2a4 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -1640,7 +1640,7 @@ TEST_F(FindExplicitReferencesTest, All) {
   int (*$2^fptr)(int $3^a, int) = nullptr;
  }
)cpp",
-   "0: targets = {}\n"
+   "0: targets = {(unnamed)}\n"
"1: targets = {x}, decl\n"
"2: targets = {fptr}, decl\n"
"3: targets = {a}, decl\n"},

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index d566564ee7d07..1e05d1e425a28 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -291,7 +291,9 @@ class NamedDecl : public Decl {
 
   /// Pretty-print the unqualified name of this declaration. Can be overloaded
   /// by derived classes to provide a more user-friendly name when appropriate.
-  virtual void printName(raw_ostream &os) const;
+  virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const;
+  /// Calls printName() with the ASTContext printing policy from the decl.
+  void printName(raw_ostream &OS) const;
 
   /// Get the actual, stored name of the declaration, which may be a special
   /// name.
@@ -3654,6 +3656,8 @@ class TagDecl : public TypeDecl,
 return getExtInfo()->TemplParamLists[i];
   }
 
+  void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
+
   void setTemplateParameterListsInfo(ASTContext &Context,
  ArrayRef 
TPLists);
 

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 126d51133ac9d..ce83424dd2077 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -4100,7 +4100,7 @@ class DecompositionDecl final
 return llvm::makeArrayRef(getTrailingObjects(), 
NumBindings);
   }
 
-  void printName(raw_ostream &os) const override;
+  void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == Decomposition; }
@@ -4213,7 +4213,8 @@ class MSGuidDecl : public ValueDecl,
 
 public:
   /// Print this UUID in a human-readable format.
-  void printName(llvm::raw_ostream &OS) const override;
+  void printName(llvm::raw_ostream &OS,
+ const PrintingPolicy &Policy) const override;
 
   /// Get the decomposed parts of this declaration.
   Parts getParts() const { return PartVal; }
@@ -426

[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

2022-10-14 Thread Aaron Ballman 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 rG19e984ef8f49: Properly print unnamed TagDecl objects in 
diagnostics (authored by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

Files:
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/ASTDiagnostic.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/AST/NestedNameSpecifier.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/AST/ast-dump-record-definition-data-json.cpp
  clang/test/ExtractAPI/enum.c
  clang/test/Index/annotate-comments-typedef.m
  clang/test/Index/c-index-api-loadTU-test.m
  clang/test/Index/c-index-getCursor-test.m
  clang/test/Index/print-type.c
  clang/test/Index/print-type.cpp
  clang/test/Index/targeted-annotation.c
  clang/test/Index/targeted-cursor.c
  clang/test/Index/usrs.m
  clang/test/Sema/address-packed.c
  clang/test/Sema/attr-flag-enum.c
  clang/test/SemaCXX/attr-unused.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/ms-interface.cpp
  clang/test/SemaObjCXX/arc-0x.mm
  clang/test/Templight/templight-empty-entries-fix.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  llvm/utils/lit/lit/TestRunner.py

Index: llvm/utils/lit/lit/TestRunner.py
===
--- llvm/utils/lit/lit/TestRunner.py
+++ llvm/utils/lit/lit/TestRunner.py
@@ -1174,6 +1174,7 @@
 ('%/p', sourcedir.replace('\\', '/')),
 ('%/t', tmpBase.replace('\\', '/') + '.tmp'),
 ('%/T', tmpDir.replace('\\', '/')),
+('%/et',tmpName.replace('\\', '')),
 ])
 
 # "%{/[STpst]:regex_replacement}" should be normalized like "%/[STpst]" but we're
Index: clang/unittests/AST/ASTTraverserTest.cpp
===
--- clang/unittests/AST/ASTTraverserTest.cpp
+++ clang/unittests/AST/ASTTraverserTest.cpp
@@ -1011,7 +1011,7 @@
 | |-FieldDecl ''
 | |-FieldDecl ''
 | |-FieldDecl ''
-| `-CXXDestructorDecl '~'
+| `-CXXDestructorDecl '~(lambda at input.cc:9:3)'
 |-ImplicitCastExpr
 | `-DeclRefExpr 'a'
 |-DeclRefExpr 'b'
Index: clang/test/Templight/templight-empty-entries-fix.cpp
===
--- clang/test/Templight/templight-empty-entries-fix.cpp
+++ clang/test/Templight/templight-empty-entries-fix.cpp
@@ -5,13 +5,13 @@
 }
 
 // CHECK-LABEL: {{^---$}}
-// CHECK: {{^name:[ ]+'lambda at .*templight-empty-entries-fix.cpp:4:3'$}}
+// CHECK: {{^name:[ ]+'\(lambda at .*templight-empty-entries-fix.cpp:4:3\)'$}}
 // CHECK: {{^kind:[ ]+Memoization$}}
 // CHECK: {{^event:[ ]+Begin$}}
 // CHECK: {{^orig:[ ]+'.*templight-empty-entries-fix.cpp:4:3'$}}
 // CHECK: {{^poi:[ ]+'.*templight-empty-entries-fix.cpp:4:3'$}}
 // CHECK-LABEL: {{^---$}}
-// CHECK: {{^name:[ ]+'lambda at .*templight-empty-entries-fix.cpp:4:3'$}}
+// CHECK: {{^name:[ ]+'\(lambda at .*templight-empty-entries-fix.cpp:4:3\)'$}}
 // CHECK: {{^kind:[ ]+Memoization$}}
 // CHECK: {{^event:[ ]+End$}}
 // CHECK: {{^orig:[ ]+'.*templight-empty-entries-fix.cpp:4:3'$}}
@@ -225,37 +225,37 @@
 }
 
 // CHECK-LABEL: {{^---$}}
-// CHECK: {{^name:[ ]+unnamed struct$}}
+// CHECK: {{^name:[ ]+'\(unnamed struct at .*templight-empty-entries-fix.cpp:223:3\)'$}}
 // CHECK: {{^kind:[ ]+Memoization$}}
 // CHECK: {{^event:[ ]+Begin$}}
 // CHECK: {{^orig:[ ]+'.*templight-empty-entries-fix.cpp:223:3'$}}
 // CHECK: {{^poi:[ ]+'.*templight-empty-entries-fix.cpp:224:5'$}}
 // CHECK-LABEL: {{^---$}}
-// CHECK: {{^name:[ ]+unnamed struct$}}
+// CHECK: {{^name:[ ]+'\(unnamed struct at .*templight-empty-entries-fix.cpp:223:3\)'$}}
 // CHECK: {{^kind:[ ]+Memoization$}}
 // CHECK: {{^event:[ ]+End$}}
 // CHECK: {{^orig:[ ]+'.*templight-empty-entries-fix.cpp:223:3'$}}
 // CHECK: {{^poi:[ ]+'.*templight-empty-entries-fix.cpp:224:5'$}}
 // CHECK-LABEL: {{^---$}}
-// CHECK: {{^name:[ ]+unnamed struct$}}
+// CHECK: {{^name:[ ]+'\(unnamed struct at .*templight-empty-entries-fix.cpp:223:3\)'$}}
 // CHECK: {{^kind:[ ]+Memoization$}}
 // CHECK: {{^event:[ ]+Begin$}}
 // CHECK: {{^orig:[ ]+'.*templight-empty-entries-fix.cpp:223:3'$}}
 // CHECK: {{^poi:[ ]+'.*templight-empty-entries-fix.cpp:224:5'$}}
 // CHECK-LABEL: {{^---$}}
-// CHECK: {{^name:[ ]+unnamed struct$}}
+// CHECK: {{^name:[ ]+'\(unnamed struct at .*templight-empty-entries-fix.cpp:223:3\)'$}}
 // CHECK: {{^kind:[ ]+Memoization$}}
 // CHECK: {{^event:[ ]+End$}}
 // CHECK: {{^orig:[ ]+'.*templight-empty-entries-fix.cpp:223:3'$}}
 // CHECK: {{^poi:[ ]+'.*templight-empty-ent

[PATCH] D135097: Remove redundant option '-menable-unsafe-fp-math'.

2022-10-14 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 467749.

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

https://reviews.llvm.org/D135097

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/fp-options-to-fast-math-flags.c
  clang/test/CodeGen/func-attr.c
  clang/test/CodeGen/libcalls.c
  clang/test/CodeGenCUDA/propagate-metadata.cu
  clang/test/Driver/cl-options.c
  clang/test/Driver/fast-math.c
  clang/test/Driver/fp-model.c
  clang/test/Parser/fp-floatcontrol-syntax.cpp
  clang/unittests/Frontend/CompilerInvocationTest.cpp

Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -705,7 +705,7 @@
 //
 //   * -cl-unsafe-math-optimizations
 // * -cl-mad-enable
-// * -menable-unsafe-fp-math
+// * -funsafe-math-optimizations
 //   * -freciprocal-math
 
 TEST_F(CommandLineTest, ImpliedBoolOptionsNoFlagPresent) {
@@ -723,7 +723,8 @@
   ASSERT_THAT(GeneratedArgs,
   Not(Contains(StrEq("-cl-unsafe-math-optimizations";
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-mad-enable";
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-menable-unsafe-fp-math";
+  ASSERT_THAT(GeneratedArgs,
+  Not(Contains(StrEq("-funsafe-math-optimizations";
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math";
 }
 
@@ -745,13 +746,14 @@
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-unsafe-math-optimizations")));
   // Not generated - implied by the generated root flag.
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-mad-enable";
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-menable-unsafe-fp-math";
+  ASSERT_THAT(GeneratedArgs,
+  Not(Contains(StrEq("-funsafe-math-optimizations";
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math";
 }
 
 TEST_F(CommandLineTest, ImpliedBoolOptionsAllFlagsPresent) {
   const char *Args[] = {"-cl-unsafe-math-optimizations", "-cl-mad-enable",
-"-menable-unsafe-fp-math", "-freciprocal-math"};
+"-funsafe-math-optimizations", "-freciprocal-math"};
 
   ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
   ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath);
@@ -765,12 +767,13 @@
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-unsafe-math-optimizations")));
   // Not generated - implied by their generated parent.
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-mad-enable";
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-menable-unsafe-fp-math";
+  ASSERT_THAT(GeneratedArgs,
+  Not(Contains(StrEq("-funsafe-math-optimizations";
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math";
 }
 
 TEST_F(CommandLineTest, ImpliedBoolOptionsImpliedFlagsPresent) {
-  const char *Args[] = {"-cl-mad-enable", "-menable-unsafe-fp-math",
+  const char *Args[] = {"-cl-mad-enable", "-funsafe-math-optimizations",
 "-freciprocal-math"};
 
   ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
@@ -785,13 +788,13 @@
   Not(Contains(StrEq("-cl-unsafe-math-optimizations";
   // Generated - explicitly provided.
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-mad-enable")));
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-menable-unsafe-fp-math")));
+  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-funsafe-math-optimizations")));
   // Not generated - implied by its generated parent.
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math";
 }
 
 TEST_F(CommandLineTest, PresentAndNotImpliedGenerated) {
-  const char *Args[] = {"-cl-mad-enable", "-menable-unsafe-fp-math"};
+  const char *Args[] = {"-cl-mad-enable", "-funsafe-math-optimizations"};
 
   ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
 
@@ -799,7 +802,7 @@
 
   // Present options that were not implied are generated.
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-mad-enable")));
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-menable-unsafe-fp-math")));
+  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-funsafe-math-optimizations")));
 }
 
 // Diagnostic option.
Index: clang/test/Parser/fp-floatcontrol-syntax.cpp
===
--- clang/test/Parser/fp-floatcontrol-syntax.cpp
+++ clang/test/Parser/fp-floatcontrol-syntax.cpp
@@ -42,7 +42,7 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fdenormal-fp-math=preserve-sign,preserve-sign -fsyntax-only %s -DDEFAULT -verify
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only %s -ffp-contract=fast -DPRECISE -verify
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only %s -ffp-contract=off -frounding-mat

[PATCH] D135097: Remove redundant option '-menable-unsafe-fp-math'.

2022-10-14 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam marked an inline comment as done.
zahiraam added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:410-412
+- The driver option ``-menable-unsafe-fp-math`` has been removed. Passing it, 
will
+result in a hard error. To enable unsafe floating-point optimizations, the 
compiler
+options ``-funsafe-math-optimizations`` and ``-ffast-math`` are used instead.

MaskRay wrote:
> aaron.ballman wrote:
> > zahiraam wrote:
> > > aaron.ballman wrote:
> > > > Because we diagnose unknown driver flags as an error 
> > > > (https://godbolt.org/z/4xjzKh4Ej) and there's no deprecation period, I 
> > > > think we should put this under the potentially breaking changes 
> > > > section. In this case, I'm specifically worried about proprietary 
> > > > projects using the flag for optimization purposes (a lot of numerical 
> > > > analysis code is behind closed doors).
> > > > 
> > > > CC @MaskRay just to make sure there's agreement (we're still trying to 
> > > > figure out what constitutes a breaking change we want to be loud about 
> > > > in terms of driver flags).
> > > > 
> > > > Assuming Fangrui doesn't disagree, once this lands, please post an 
> > > > announcement about it into https://discourse.llvm.org/c/announce/46 
> > > > with the `clang` and `potentially-breaking` tags (an example of such a 
> > > > post is: 
> > > > https://discourse.llvm.org/t/clang-16-notice-of-potentially-breaking-changes/65562/
> > > >  though you wouldn't need all that lead-in text). 
> > > @aaron.ballman would it be worth adding a diagnostic for the option we 
> > > are removing?
> > If we're going to deprecate rather than remove, sure. But I think we're 
> > okay removing, and I think the default error diagnostic behavior will be 
> > sufficient.
> Since -menable-unsafe-fp-math was only accidentally exposed in 2020 and it's 
> clear not used in the wild, placing this under "Potentially Breaking Changes" 
> seems overkill to me (lengthy entries in release notes also discourage 
> readers).
> 
> > The driver option ``-menable-unsafe-fp-math`` has been removed. Passing it, 
> > will result in a hard error. 
> 
> I think `Passing it, will result in a hard error. ` can be removed as the 
> removal clearly indicates that passing it is an error:)
> 
> > the compiler options ``-funsafe-math-optimizations`` and ``-ffast-math`` 
> > are used instead.
> 
> Use xxx or xxx instead.
@MaskRay Thanks! 
I tend to agree about the "Potentially Breaking changes". 


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

https://reviews.llvm.org/D135097

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


[clang] e83bea4 - [clang][Interp][NFC] Add some tests for invalid array access

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T14:41:05+02:00
New Revision: e83bea40b6c45bf2a8d4983238da32b5d2be80fc

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

LOG: [clang][Interp][NFC] Add some tests for invalid array access

Added: 


Modified: 
clang/test/AST/Interp/arrays.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/arrays.cpp 
b/clang/test/AST/Interp/arrays.cpp
index 302c8b2a86cc..318793ff777a 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -98,3 +98,22 @@ struct fred {
 struct fred y [] = { [0] = { .s[0] = 'q' } };
 #endif
 #pragma clang diagnostic pop
+
+namespace indices {
+  constexpr int first[] = {1};
+  constexpr int firstValue = first[2]; // ref-error {{must be initialized by a 
constant expression}} \
+   // ref-note {{cannot refer to element 2 
of array of 1}} \
+   // expected-error {{must be initialized 
by a constant expression}} \
+   // expected-note {{cannot refer to 
element 2 of array of 1}}
+
+  constexpr int second[10] = {17};
+  constexpr int secondValue = second[10];// ref-error {{must be initialized by 
a constant expression}} \
+ // ref-note {{read of dereferenced 
one-past-the-end pointer}} \
+ // expected-error {{must be 
initialized by a constant expression}} \
+ // expected-note {{read of 
dereferenced one-past-the-end pointer}}
+
+  constexpr int negative = second[-2]; // ref-error {{must be initialized by a 
constant expression}} \
+   // ref-note {{cannot refer to element 
-2 of array of 10}} \
+   // expected-error {{must be initialized 
by a constant expression}} \
+   // expected-note {{cannot refer to 
element -2 of array of 10}}
+};



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


[clang] 6fad712 - [clang][Interp][NFC] Remove unused parameter from emitConst()

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T14:41:05+02:00
New Revision: 6fad7127cb990894cc2392c89152a36af7808736

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

LOG: [clang][Interp][NFC] Remove unused parameter from emitConst()

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 6edf1c450fa3..ad3348cee4e2 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -145,10 +145,8 @@ bool ByteCodeExprGen::VisitIntegerLiteral(const 
IntegerLiteral *LE) {
   if (DiscardResult)
 return true;
 
-  auto Val = LE->getValue();
-  QualType LitTy = LE->getType();
-  if (Optional T = classify(LitTy))
-return emitConst(*T, getIntWidth(LitTy), LE->getValue(), LE);
+  if (Optional T = classify(LE->getType()))
+return emitConst(*T, LE->getValue(), LE);
   return this->bail(LE);
 }
 
@@ -345,7 +343,7 @@ bool ByteCodeExprGen::VisitArrayInitIndexExpr(
 return false;
   QualType IndexType = E->getType();
   APInt Value(getIntWidth(IndexType), *ArrayIndex);
-  return this->emitConst(classifyPrim(IndexType), 0, Value, E);
+  return this->emitConst(classifyPrim(IndexType), Value, E);
 }
 
 template 
@@ -569,8 +567,8 @@ bool ByteCodeExprGen::dereferenceVar(
 }
 
 template 
-bool ByteCodeExprGen::emitConst(PrimType T, unsigned NumBits,
- const APInt &Value, const Expr *E) {
+bool ByteCodeExprGen::emitConst(PrimType T, const APInt &Value,
+ const Expr *E) {
   switch (T) {
   case PT_Sint8:
 return this->emitConstSint8(Value.getSExtValue(), E);
@@ -1092,8 +1090,7 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   } else if (const auto *ECD = dyn_cast(Decl)) {
 PrimType T = *classify(ECD->getType());
 
-return this->emitConst(T, getIntWidth(ECD->getType()), ECD->getInitVal(),
-   E);
+return this->emitConst(T, ECD->getInitVal(), E);
   }
 
   // References are implemented using pointers, so when we get here,

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index f55ac2ff433b..ffe8e8372543 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -232,15 +232,13 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   llvm::function_ref Indirect);
 
   /// Emits an APInt constant.
-  bool emitConst(PrimType T, unsigned NumBits, const llvm::APInt &Value,
- const Expr *E);
+  bool emitConst(PrimType T, const llvm::APInt &Value, const Expr *E);
 
   /// Emits an integer constant.
   template  bool emitConst(const Expr *E, T Value) {
 QualType Ty = E->getType();
-unsigned NumBits = getIntWidth(Ty);
-APInt WrappedValue(NumBits, Value, std::is_signed::value);
-return emitConst(*Ctx.classify(Ty), NumBits, WrappedValue, E);
+APInt WrappedValue(getIntWidth(Ty), Value, std::is_signed::value);
+return emitConst(*Ctx.classify(Ty), WrappedValue, E);
   }
 
   /// Returns the index of a global.



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


[clang] 5a85943 - [clang][Interp] Implement while and do-while loops

2022-10-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-14T14:41:05+02:00
New Revision: 5a859432f31716f780cd662741864ef1a77fc28a

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

LOG: [clang][Interp] Implement while and do-while loops

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

Added: 
clang/test/AST/Interp/loops.cpp

Modified: 
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 3aa659822bb8..3cdb87fcd7f6 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -153,6 +153,14 @@ bool ByteCodeStmtGen::visitStmt(const Stmt *S) {
 return visitReturnStmt(cast(S));
   case Stmt::IfStmtClass:
 return visitIfStmt(cast(S));
+  case Stmt::WhileStmtClass:
+return visitWhileStmt(cast(S));
+  case Stmt::DoStmtClass:
+return visitDoStmt(cast(S));
+  case Stmt::BreakStmtClass:
+return visitBreakStmt(cast(S));
+  case Stmt::ContinueStmtClass:
+return visitContinueStmt(cast(S));
   case Stmt::NullStmtClass:
 return true;
   default: {
@@ -262,6 +270,69 @@ bool ByteCodeStmtGen::visitIfStmt(const IfStmt 
*IS) {
   return true;
 }
 
+template 
+bool ByteCodeStmtGen::visitWhileStmt(const WhileStmt *S) {
+  const Expr *Cond = S->getCond();
+  const Stmt *Body = S->getBody();
+
+  LabelTy CondLabel = this->getLabel(); // Label before the condition.
+  LabelTy EndLabel = this->getLabel();  // Label after the loop.
+  LoopScope LS(this, EndLabel, CondLabel);
+
+  this->emitLabel(CondLabel);
+  if (!this->visitBool(Cond))
+return false;
+  if (!this->jumpFalse(EndLabel))
+return false;
+
+  if (!this->visitStmt(Body))
+return false;
+  if (!this->jump(CondLabel))
+return false;
+
+  this->emitLabel(EndLabel);
+
+  return true;
+}
+
+template 
+bool ByteCodeStmtGen::visitDoStmt(const DoStmt *S) {
+  const Expr *Cond = S->getCond();
+  const Stmt *Body = S->getBody();
+
+  LabelTy StartLabel = this->getLabel();
+  LabelTy EndLabel = this->getLabel();
+  LabelTy CondLabel = this->getLabel();
+  LoopScope LS(this, EndLabel, CondLabel);
+
+  this->emitLabel(StartLabel);
+  if (!this->visitStmt(Body))
+return false;
+  this->emitLabel(CondLabel);
+  if (!this->visitBool(Cond))
+return false;
+  if (!this->jumpTrue(StartLabel))
+return false;
+  this->emitLabel(EndLabel);
+  return true;
+}
+
+template 
+bool ByteCodeStmtGen::visitBreakStmt(const BreakStmt *S) {
+  if (!BreakLabel)
+return false;
+
+  return this->jump(*BreakLabel);
+}
+
+template 
+bool ByteCodeStmtGen::visitContinueStmt(const ContinueStmt *S) {
+  if (!ContinueLabel)
+return false;
+
+  return this->jump(*ContinueLabel);
+}
+
 template 
 bool ByteCodeStmtGen::visitVarDecl(const VarDecl *VD) {
   if (!VD->hasLocalStorage()) {

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h 
b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 3a9a74038ee3..49a7b79b1c4b 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -58,6 +58,10 @@ class ByteCodeStmtGen final : public 
ByteCodeExprGen {
   bool visitDeclStmt(const DeclStmt *DS);
   bool visitReturnStmt(const ReturnStmt *RS);
   bool visitIfStmt(const IfStmt *IS);
+  bool visitWhileStmt(const WhileStmt *S);
+  bool visitDoStmt(const DoStmt *S);
+  bool visitBreakStmt(const BreakStmt *S);
+  bool visitContinueStmt(const ContinueStmt *S);
 
   /// Compiles a variable declaration.
   bool visitVarDecl(const VarDecl *VD);

diff  --git a/clang/test/AST/Interp/loops.cpp b/clang/test/AST/Interp/loops.cpp
new file mode 100644
index ..30a38ca573b2
--- /dev/null
+++ b/clang/test/AST/Interp/loops.cpp
@@ -0,0 +1,189 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify 
%s
+// RUN: %clang_cc1 -std=c++14 -verify=ref %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 
-verify=expected-cpp20 %s
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s
+
+// ref-no-diagnostics
+// expected-no-diagnostics
+
+namespace WhileLoop {
+  constexpr int f() {
+int i = 0;
+while(false) {
+  i = i + 1;
+}
+return i;
+  }
+  static_assert(f() == 0, "");
+
+
+  constexpr int f2() {
+int i = 0;
+while(i != 5) {
+  i = i + 1;
+}
+return i;
+  }
+  static_assert(f2() == 5, "");
+
+  constexpr int f3() {
+int i = 0;
+while(true) {
+  i = i + 1;
+
+  if (i == 5)
+break;
+}
+return i;
+  }
+  static_assert(f3() == 5, "");
+
+  constexpr int f4() {
+int i = 0;
+while(i != 5) {
+
+  i = i + 1;
+  continue;
+  i = i - 1;
+}
+return i;
+  }
+  static_assert(f4() == 5, "");
+
+
+  constexpr int f5(

[PATCH] D135433: [clang][Interp] Implement while and do-while loops

2022-10-14 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
tbaeder marked an inline comment as done.
Closed by commit rG5a859432f317: [clang][Interp] Implement while and do-while 
loops (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D135433?vs=466259&id=467755#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135433

Files:
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/test/AST/Interp/loops.cpp

Index: clang/test/AST/Interp/loops.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/loops.cpp
@@ -0,0 +1,189 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify %s
+// RUN: %clang_cc1 -std=c++14 -verify=ref %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify=expected-cpp20 %s
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s
+
+// ref-no-diagnostics
+// expected-no-diagnostics
+
+namespace WhileLoop {
+  constexpr int f() {
+int i = 0;
+while(false) {
+  i = i + 1;
+}
+return i;
+  }
+  static_assert(f() == 0, "");
+
+
+  constexpr int f2() {
+int i = 0;
+while(i != 5) {
+  i = i + 1;
+}
+return i;
+  }
+  static_assert(f2() == 5, "");
+
+  constexpr int f3() {
+int i = 0;
+while(true) {
+  i = i + 1;
+
+  if (i == 5)
+break;
+}
+return i;
+  }
+  static_assert(f3() == 5, "");
+
+  constexpr int f4() {
+int i = 0;
+while(i != 5) {
+
+  i = i + 1;
+  continue;
+  i = i - 1;
+}
+return i;
+  }
+  static_assert(f4() == 5, "");
+
+
+  constexpr int f5(bool b) {
+int i = 0;
+
+while(true) {
+  if (!b) {
+if (i == 5)
+  break;
+  }
+
+  if (b) {
+while (i != 10) {
+  i = i + 1;
+  if (i == 8)
+break;
+
+  continue;
+}
+  }
+
+  if (b)
+break;
+
+  i = i + 1;
+  continue;
+}
+
+return i;
+  }
+  static_assert(f5(true) == 8, "");
+  static_assert(f5(false) == 5, "");
+
+#if 0
+  /// FIXME: This is an infinite loop, which should
+  ///   be rejected.
+  constexpr int f6() {
+while(true);
+  }
+#endif
+};
+
+namespace DoWhileLoop {
+
+  constexpr int f() {
+int i = 0;
+do {
+  i = i + 1;
+} while(false);
+return i;
+  }
+  static_assert(f() == 1, "");
+
+  constexpr int f2() {
+int i = 0;
+do {
+  i = i + 1;
+} while(i != 5);
+return i;
+  }
+  static_assert(f2() == 5, "");
+
+
+  constexpr int f3() {
+int i = 0;
+do {
+  i = i + 1;
+  if (i == 5)
+break;
+} while(true);
+return i;
+  }
+  static_assert(f3() == 5, "");
+
+  constexpr int f4() {
+int i = 0;
+do {
+  i = i + 1;
+  continue;
+  i = i - 1;
+} while(i != 5);
+return i;
+  }
+  static_assert(f4() == 5, "");
+
+  constexpr int f5(bool b) {
+int i = 0;
+
+do {
+  if (!b) {
+if (i == 5)
+  break;
+  }
+
+  if (b) {
+do {
+  i = i + 1;
+  if (i == 8)
+break;
+
+  continue;
+} while (i != 10);
+  }
+
+  if (b)
+break;
+
+  i = i + 1;
+  continue;
+} while(true);
+
+return i;
+  }
+  static_assert(f5(true) == 8, "");
+  static_assert(f5(false) == 5, "");
+
+  /// FIXME: This should be accepted in C++20 but is currently being rejected
+  ///   because the variable declaration doesn't have an initializier.
+#if __cplusplus >= 202002L
+  constexpr int f6() {
+int i;
+do {
+  i = 5;
+  break;
+} while (true);
+return i;
+  }
+  static_assert(f6() == 5, ""); // expected-cpp20-error {{not an integral constant}}
+#endif
+
+#if 0
+  /// FIXME: This is an infinite loop, which should
+  ///   be rejected.
+  constexpr int f7() {
+while(true);
+  }
+#endif
+};
Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -58,6 +58,10 @@
   bool visitDeclStmt(const DeclStmt *DS);
   bool visitReturnStmt(const ReturnStmt *RS);
   bool visitIfStmt(const IfStmt *IS);
+  bool visitWhileStmt(const WhileStmt *S);
+  bool visitDoStmt(const DoStmt *S);
+  bool visitBreakStmt(const BreakStmt *S);
+  bool visitContinueStmt(const ContinueStmt *S);
 
   /// Compiles a variable declaration.
   bool visitVarDecl(const VarDecl *VD);
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -153,6 +153,14 @@
 return visitReturnStmt(cast(S));
   case Stmt::IfStmtClass:
 return visitIfStmt(cast(S));
+  case Stmt::WhileStmtClass:
+return visitWhileS

[PATCH] D132855: [OpenMP] Extend the lit test for uses_allocators in target region

2022-10-14 Thread Animesh Kumar via Phabricator via cfe-commits
animeshk-amd updated this revision to Diff 467757.
animeshk-amd added a comment.

Another patch that landed after this patch introduced merge 
conflicts in the target_map_codegen_10.cpp with regards to the 
use of the `-no-opaque-pointers`. Those merge conflicts are
fixed in the revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132855

Files:
  clang/test/OpenMP/target_map_codegen_10.cpp
  clang/test/OpenMP/target_uses_allocators.c

Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -1,9 +1,8 @@
 // Test host codegen.
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50  -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50  -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -include-pch %t %s -emit-llvm -o - | FileCheck %s
 
-// expected-no-diagnostics
 #ifndef HEADER
 #define HEADER
 
@@ -39,6 +38,71 @@
   {}
   #pragma omp target uses_allocators(omp_pteam_mem_alloc) allocate(omp_pteam_mem_alloc: x) firstprivate(x)
   {}
+  #pragma omp target uses_allocators(omp_thread_mem_alloc) allocate(omp_thread_mem_alloc: x) firstprivate(x) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'target' directive}}
+  {}
 }
 
 #endif
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr null)
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr null)
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr inttoptr (i64 1 to ptr))
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr inttoptr (i64 1 to ptr))
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr inttoptr (i64 2 to ptr))
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr inttoptr (i64 2 to ptr))
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr inttoptr (i64 3 to ptr))
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr inttoptr (i64 3 to ptr))
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr inttoptr (i64 4 to ptr))
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr inttoptr (i64 4 to ptr))
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr inttoptr (i64 5 to ptr))
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr inttoptr (i64 5 to ptr))
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: stor

[clang] dcee874 - Fix the ExtractAPI tests

2022-10-14 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-10-14T08:58:16-04:00
New Revision: dcee874ee3900fe1617c7562c774e5405439f5c9

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

LOG: Fix the ExtractAPI tests

This should address the issues found by:
https://lab.llvm.org/buildbot/#/builders/139/builds/29568
https://lab.llvm.org/buildbot/#/builders/109/builds/48658

Added: 


Modified: 
clang/test/ExtractAPI/anonymous_record_no_typedef.c

Removed: 




diff  --git a/clang/test/ExtractAPI/anonymous_record_no_typedef.c 
b/clang/test/ExtractAPI/anonymous_record_no_typedef.c
index 6f7156ff1dec..e20abfdd86ab 100644
--- a/clang/test/ExtractAPI/anonymous_record_no_typedef.c
+++ b/clang/test/ExtractAPI/anonymous_record_no_typedef.c
@@ -128,13 +128,13 @@ struct Vehicle {
 "navigator": [
   {
 "kind": "identifier",
-"spelling": "Vehicle::(anonymous)"
+"spelling": "Vehicle::enum (unnamed)"
   }
 ],
-"title": "Vehicle::(anonymous)"
+"title": "Vehicle::enum (unnamed)"
   },
   "pathComponents": [
-"Vehicle::(anonymous)"
+"Vehicle::enum (unnamed)"
   ]
 },
 {
@@ -176,7 +176,7 @@ struct Vehicle {
 "title": "Bicycle"
   },
   "pathComponents": [
-"Vehicle::(anonymous)",
+"Vehicle::enum (unnamed)",
 "Bicycle"
   ]
 },
@@ -219,7 +219,7 @@ struct Vehicle {
 "title": "Car"
   },
   "pathComponents": [
-"Vehicle::(anonymous)",
+"Vehicle::enum (unnamed)",
 "Car"
   ]
 },



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


[PATCH] D134928: [Sema] Don't treat a non-null template argument as if it were null.

2022-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134928

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


[PATCH] D135772: Stop evaluating trailing requires clause after overload resolution

2022-10-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 467762.
erichkeane marked an inline comment as done.
erichkeane added a comment.

Thanks for the review @shafik


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

https://reviews.llvm.org/D135772

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -708,3 +708,60 @@
 // expected-note@#CMVT_REQ{{because 'sizeof(int) == arity' (4 == 5) evaluated to false}}
 } // namespace ConstrainedMemberVarTemplate 
 
+// These should not diagnose, where we were unintentionally doing so before by
+// checking trailing requires clause twice, yet not having the ability to the
+// 2nd time, since it was no longer a dependent variant.
+namespace InheritedFromPartialSpec {
+template
+constexpr bool Check = true;
+
+template
+struct Foo {
+  template
+Foo(U&&) requires (Check){}
+  template
+void MemFunc(U&&) requires (Check){}
+  template
+static void StaticMemFunc(U&&) requires (Check){}
+  ~Foo() requires (Check){}
+};
+
+template<>
+  struct Foo : Foo {
+using Foo::Foo;
+using Foo::MemFunc;
+using Foo::StaticMemFunc;
+  };
+
+void use() {
+  Foo F {1.1};
+  F.MemFunc(1.1);
+  Foo::StaticMemFunc(1.1);
+}
+
+template
+struct counted_iterator {
+  constexpr auto operator->() const noexcept requires false {
+return T::Invalid;
+  };
+};
+
+template
+concept __has_member_pointer = requires { typename _Ip::pointer; };
+
+template
+struct __iterator_traits_member_pointer_or_arrow_or_void { using type = void; };
+template<__has_member_pointer _Ip>
+struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> { using type = typename _Ip::pointer; };
+
+template
+  requires requires(_Ip& __i) { __i.operator->(); } && (!__has_member_pointer<_Ip>)
+struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {
+  using type = decltype(declval<_Ip&>().operator->());
+};
+
+
+void use2() {
+  __iterator_traits_member_pointer_or_arrow_or_void> f;
+}
+}// namespace InheritedFromPartialSpec 
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -14680,7 +14680,7 @@
   Method = cast(Best->Function);
   FoundDecl = Best->FoundDecl;
   CheckUnresolvedMemberAccess(UnresExpr, Best->FoundDecl);
-  if (DiagnoseUseOfDecl(Best->FoundDecl, UnresExpr->getNameLoc()))
+  if (DiagnoseUseOfOverloadedDecl(Best->FoundDecl, UnresExpr->getNameLoc()))
 break;
   // If FoundDecl is different from Method (such as if one is a template
   // and the other a specialization), make sure DiagnoseUseOfDecl is
@@ -14689,7 +14689,7 @@
   // DiagnoseUseOfDecl to accept both the FoundDecl and the decl
   // being used.
   if (Method != FoundDecl.getDecl() &&
-  DiagnoseUseOfDecl(Method, UnresExpr->getNameLoc()))
+  DiagnoseUseOfOverloadedDecl(Method, UnresExpr->getNameLoc()))
 break;
   Succeeded = true;
   break;
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -222,7 +222,8 @@
  const ObjCInterfaceDecl *UnknownObjCClass,
  bool ObjCPropertyAccess,
  bool AvoidPartialAvailabilityChecks,
- ObjCInterfaceDecl *ClassReceiver) {
+ ObjCInterfaceDecl *ClassReceiver,
+ bool SkipTrailingRequiresClause) {
   SourceLocation Loc = Locs.front();
   if (getLangOpts().CPlusPlus && isa(D)) {
 // If there were any diagnostics suppressed by template argument deduction,
@@ -281,7 +282,7 @@
 // See if this is a function with constraints that need to be satisfied.
 // Check this before deducing the return type, as it might instantiate the
 // definition.
-if (FD->getTrailingRequiresClause()) {
+if (!SkipTrailingRequiresClause && FD->getTrailingRequiresClause()) {
   ConstraintSatisfaction Satisfaction;
   if (CheckFunctionConstraints(FD, Satisfaction, Loc,
/*ForOverloadResolution*/ true))
@@ -6744,8 +6745,11 @@
 }
   }
 
+  SourceLocation ConstraintFailLoc = NakedFn->getBeginLoc();
+
   if (auto *DRE = dyn_cast(NakedFn)) {
 NDecl = DRE->getDecl();
+ConstraintFailLoc = DRE->getEndLoc();
 
 FunctionDecl *FDecl = dyn_cast(NDecl);
 if (FDecl && FDecl->getBuiltinID()) {
@@ -6761,8 +6765,10 @@
 nullptr, DRE->isNonOdrUse());
   }
 }
-  } else if (isa(NakedFn))
-NDecl = cast(NakedFn)->get

[PATCH] D120862: Sema: Allow scoped enums as source type for integral conversion.

2022-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D120862#3857372 , @shafik wrote:

> In D120862#3857340 , @pcc wrote:
>
>> Does that DR apply retroactively to C++17? I get the impression that 
>> "Status: C++20" means that the issue was only fixed in C++20, which would 
>> make this well-formed with `-std=c++17`.
>
> This was simply an oversite in the wording of the paper see discussion here 
> 
>  and this was never intended to work.
>
> We have some discretion about how far back to apply DRs and I believe as long 
> as applying them back does not cause major disruption we do CC @aaron.ballman

You're correct that "Status: C++20" means that the issue was fixed in C++20. 
And technically speaking, we only need to apply those changes in C++20 and 
later. However, the intent of the DR process is to fix mistakes in older 
language modes. ISO doesn't let us retroactively change a published standard, 
so we keep this side list of "oh you should also fix this stuff" with the 
intent that the fixes apply as far back as they're relevant. We try to follow 
that guidance whenever we can, but if a DR causes code to break and that turns 
out to be disruptive, we'll sometimes decide to not apply it farther back than 
the standard version it was fixed in. I don't think there's a problem applying 
that specific DR as far back as we can.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120862

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


[PATCH] D135097: Remove redundant option '-menable-unsafe-fp-math'.

2022-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: clang/docs/ReleaseNotes.rst:410-412
+- The driver option ``-menable-unsafe-fp-math`` has been removed. Passing it, 
will
+result in a hard error. To enable unsafe floating-point optimizations, the 
compiler
+options ``-funsafe-math-optimizations`` and ``-ffast-math`` are used instead.

zahiraam wrote:
> MaskRay wrote:
> > aaron.ballman wrote:
> > > zahiraam wrote:
> > > > aaron.ballman wrote:
> > > > > Because we diagnose unknown driver flags as an error 
> > > > > (https://godbolt.org/z/4xjzKh4Ej) and there's no deprecation period, 
> > > > > I think we should put this under the potentially breaking changes 
> > > > > section. In this case, I'm specifically worried about proprietary 
> > > > > projects using the flag for optimization purposes (a lot of numerical 
> > > > > analysis code is behind closed doors).
> > > > > 
> > > > > CC @MaskRay just to make sure there's agreement (we're still trying 
> > > > > to figure out what constitutes a breaking change we want to be loud 
> > > > > about in terms of driver flags).
> > > > > 
> > > > > Assuming Fangrui doesn't disagree, once this lands, please post an 
> > > > > announcement about it into https://discourse.llvm.org/c/announce/46 
> > > > > with the `clang` and `potentially-breaking` tags (an example of such 
> > > > > a post is: 
> > > > > https://discourse.llvm.org/t/clang-16-notice-of-potentially-breaking-changes/65562/
> > > > >  though you wouldn't need all that lead-in text). 
> > > > @aaron.ballman would it be worth adding a diagnostic for the option we 
> > > > are removing?
> > > If we're going to deprecate rather than remove, sure. But I think we're 
> > > okay removing, and I think the default error diagnostic behavior will be 
> > > sufficient.
> > Since -menable-unsafe-fp-math was only accidentally exposed in 2020 and 
> > it's clear not used in the wild, placing this under "Potentially Breaking 
> > Changes" seems overkill to me (lengthy entries in release notes also 
> > discourage readers).
> > 
> > > The driver option ``-menable-unsafe-fp-math`` has been removed. Passing 
> > > it, will result in a hard error. 
> > 
> > I think `Passing it, will result in a hard error. ` can be removed as the 
> > removal clearly indicates that passing it is an error:)
> > 
> > > the compiler options ``-funsafe-math-optimizations`` and ``-ffast-math`` 
> > > are used instead.
> > 
> > Use xxx or xxx instead.
> @MaskRay Thanks! 
> I tend to agree about the "Potentially Breaking changes". 
Great, that works for me. Thank you @MaskRay!


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

https://reviews.llvm.org/D135097

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


[PATCH] D134928: [Sema] Don't treat a non-null template argument as if it were null.

2022-10-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.

I would love it if the diagnostic had a little more info why it isn't, but this 
is probably good enough for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134928

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


[PATCH] D135919: [Clang] Set thread_local Itanium ABI guard variables before calling constructors.

2022-10-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

So this logically looks/sounds right to me (and I have no code concerns)...  
But I'm also notoriously bad at anything threading related.  I'd love it if one 
of the other reviewers could sanity check this for me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135919

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


[PATCH] D135931: [Attributes] Improve writing `ExprArgument` value.

2022-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135931

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


[PATCH] D135938: [X86] Add AVX-VNNI-INT8 instructions.

2022-10-14 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

I'm out of machines next two days. Sorry for late address in advance... I'll 
update next Monday. Thanks for review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135938

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


[PATCH] D135472: [ODRHash] Hash attributes on declarations.

2022-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D135472#3856596 , @vsapsai wrote:

> Given all the discussion about which attributes should be added to ODR hash, 
> I think it is useful at this point to have TableGen infrastructure to get 
> this information from Attr.td. So I'll work on that.

Thank you, I think that's a good approach for the moment. Once you have the 
basic framework in place, we can opt in the uncontroversial attributes (like, I 
think anything inheriting from `TypeAttr` or `DeclOrTypeAttr` should be 
automatically opted in and any `Argument` whose `Fake` flag is set should not 
contribute to the ODR hash) and then we can do a follow-up to figure out how to 
distinguish "definitely an ODR violation" attributes from "not an ODR violation 
but still something we want to find a way to alert users about".




Comment at: clang/lib/AST/ODRHash.cpp:479-480
+
+  llvm::copy_if(D->attrs(), std::back_inserter(HashableAttrs),
+[](const Attr *A) { return !A->isImplicit(); });
+}

ChuanqiXu wrote:
> aaron.ballman wrote:
> > ChuanqiXu wrote:
> > > aaron.ballman wrote:
> > > > ChuanqiXu wrote:
> > > > > vsapsai wrote:
> > > > > > vsapsai wrote:
> > > > > > > erichkeane wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > ChuanqiXu wrote:
> > > > > > > > > > vsapsai wrote:
> > > > > > > > > > > I'm not sure `isImplicit` is the best indicator of 
> > > > > > > > > > > attributes to check, so suggestions in this area are 
> > > > > > > > > > > welcome. I think we can start strict and relax some of 
> > > > > > > > > > > the checks if needed.
> > > > > > > > > > > 
> > > > > > > > > > > If people have strong opinions that some attributes 
> > > > > > > > > > > shouldn't be ignored, we can add them to the tests to 
> > > > > > > > > > > avoid regressions. Personally, I believe that alignment 
> > > > > > > > > > > and packed attributes should never be silently ignored.
> > > > > > > > > > Agreed. I feel `isImplicit` is enough for now.
> > > > > > > > > The tricky part is -- sometimes certain attributes add 
> > > > > > > > > additional implicit attributes and those implicit attributes 
> > > > > > > > > matter 
> > > > > > > > > (https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaDeclAttr.cpp#L9380).
> > > > > > > > >  And some attributes seem to just do the wrong thing 
> > > > > > > > > entirely: 
> > > > > > > > > https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaDeclAttr.cpp#L7344
> > > > > > > > > 
> > > > > > > > > So I think `isImplicit()` is a good approximation, but I'm 
> > > > > > > > > more wondering what the principle is for whether an attribute 
> > > > > > > > > should or should not be considered part of the ODR hash. Type 
> > > > > > > > > attributes, attributes that impact object layout, etc all 
> > > > > > > > > seem like they should almost certainly be part of ODR 
> > > > > > > > > hashing. Others are a bit more questionable though.
> > > > > > > > > 
> > > > > > > > > I think this is something that may need a per-attribute flag 
> > > > > > > > > in Attr.td so attributes can opt in or out of it because I'm 
> > > > > > > > > not certain what ODR issues could stem from 
> > > > > > > > > `[[maybe_unused]]` or `[[deprecated]]` disagreements across 
> > > > > > > > > module boundaries.
> > > > > > > > I don't think 'isImplicit' is particularly good.  I think the 
> > > > > > > > idea of auto-adding 'type' attributes and having the 'rest' be 
> > > > > > > > analyzed to figure out which are important.
> > > > > > > > 
> > > > > > > > Alternatively, I wonder if we're better off just adding ALL 
> > > > > > > > attributes and seeing what the fallout is. We can later decide 
> > > > > > > > when we don't want them to be ODR significant (which, might be 
> > > > > > > > OTHERWISE meaningful later!).
> > > > > > > One criteria to decide which attributes should be hashed is if 
> > > > > > > they affect IRGen. But that's not exhaustive and I'm not sure how 
> > > > > > > practical it is.
> > > > > > > 
> > > > > > > The rule I'm trying to follow right now is if declarations with 
> > > > > > > different attributes can be substituted instead of each other. 
> > > > > > > For example, structs with different memory layout cannot be 
> > > > > > > interchanged, so it is reasonable to reject them.
> > > > > > > 
> > > > > > > But maybe we should review attributes on case-by-case basis. For 
> > > > > > > example, for `[[deprecated]]` I think the best for developers is 
> > > > > > > not to complain about it but merge the attributes and then have 
> > > > > > > regular diagnostic about using a deprecated entity.
> > > > > > One option was to hash `isa` attributes as they are 
> > > > > > "sticky" and should be more significant, so shouldn't be ignored. 
> > > > > > But I don't think this argument is particularly convincing.
> > > > > > 
> > > > > > At this stage I think we can still a

[clang] 06da9b9 - [OpenMP] Extend the lit test for uses_allocators in target region

2022-10-14 Thread Animesh Kumar via cfe-commits

Author: Animesh Kumar
Date: 2022-10-14T19:12:33+05:30
New Revision: 06da9b94ae374f81a0898b01608c1c3529dfa29a

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

LOG: [OpenMP] Extend the lit test for uses_allocators in target region

This patch improves the LIT tests on the following :

1. The test on `uses_allocators` clause in the `target` region by
adding the respective CHECK lines. Allocator `omp_thread_mem_alloc`
is also added in the test.
2. The `defaultmap` clause wasn't being tested for the variable-
category `scalar` and the implicit-behavior `tofrom` with respect
to the OpenMP default version.

These improvements are inspired from SOLLVE tests.
SOLLVE repo: https://github.com/SOLLVE/sollve_vv

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/test/OpenMP/target_map_codegen_10.cpp
clang/test/OpenMP/target_uses_allocators.c

Removed: 




diff  --git a/clang/test/OpenMP/target_map_codegen_10.cpp 
b/clang/test/OpenMP/target_map_codegen_10.cpp
index e6fa9fe1825b7..f5201ec8305c9 100644
--- a/clang/test/OpenMP/target_map_codegen_10.cpp
+++ b/clang/test/OpenMP/target_map_codegen_10.cpp
@@ -3,12 +3,20 @@
 #define HEADER
 
 
///==///
-// RUN: %clang_cc1 -DCK11 -verify -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple 
powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck 
-allow-deprecated-dag-overlap  %s --check-prefix CK11
+
+// RUN: %clang_cc1 -DCK11 -verify -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple 
powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck 
-allow-deprecated-dag-overlap  %s --check-prefixes CK11,CK11_4
 // RUN: %clang_cc1 -DCK11 -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple 
powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o 
- | FileCheck -allow-deprecated-dag-overlap  %s  --check-prefix CK11
-// RUN: %clang_cc1 -DCK11 -verify -fopenmp -fopenmp-version=45 
-fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown 
-emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s  
--check-prefix CK11
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple 
powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o 
- | FileCheck -allow-deprecated-dag-overlap  %s  --check-prefixes CK11,CK11_4
+// RUN: %clang_cc1 -DCK11 -verify -fopenmp -fopenmp-version=45 
-fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown 
-emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s  
--check-prefixes CK11,CK11_4
 // RUN: %clang_cc1 -DCK11 -fopenmp -fopenmp-version=45 
-fopenmp-targets=i386-pc-linux-gnu -x c++ -std=c++11 -triple 
i386-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
-allow-deprecated-dag-overlap  %s  --check-prefix CK11
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 
-fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
-allow-deprecated-dag-overlap  %s  --check-prefixes CK11,CK11_4
+
+// RUN: %clang_cc1 -DCK11 -verify -fopenmp 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple 
powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck 
-allow-deprecated-dag-overlap %s --check-prefixes CK11,CK11_5
+// RUN: %clang_cc1 -DCK11 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ 
-triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s 
-emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s  --check-prefixes 
CK11,CK11_5
+// RUN: %clang_cc1 -DCK11 -verify -fopenmp -fopenmp-targets=i386-pc-linux-gnu 
-x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck 
-allow-deprecated-dag-overlap  %s  --check-prefixes CK11,CK11_5
+// RUN: %clang_cc1 -DCK11 -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ 
-std=c++11 -triple i386-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple 
i386-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck -allow-deprecated-dag-overlap  %s 

[PATCH] D132855: [OpenMP] Extend the lit test for uses_allocators in target region

2022-10-14 Thread Animesh Kumar 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 rG06da9b94ae37: [OpenMP] Extend the lit test for 
uses_allocators in target region (authored by animeshk-amd).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132855

Files:
  clang/test/OpenMP/target_map_codegen_10.cpp
  clang/test/OpenMP/target_uses_allocators.c

Index: clang/test/OpenMP/target_uses_allocators.c
===
--- clang/test/OpenMP/target_uses_allocators.c
+++ clang/test/OpenMP/target_uses_allocators.c
@@ -1,9 +1,8 @@
 // Test host codegen.
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50  -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50  -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -include-pch %t %s -emit-llvm -o - | FileCheck %s
 
-// expected-no-diagnostics
 #ifndef HEADER
 #define HEADER
 
@@ -39,6 +38,71 @@
   {}
   #pragma omp target uses_allocators(omp_pteam_mem_alloc) allocate(omp_pteam_mem_alloc: x) firstprivate(x)
   {}
+  #pragma omp target uses_allocators(omp_thread_mem_alloc) allocate(omp_thread_mem_alloc: x) firstprivate(x) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'target' directive}}
+  {}
 }
 
 #endif
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr null)
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr null)
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr inttoptr (i64 1 to ptr))
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr inttoptr (i64 1 to ptr))
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr inttoptr (i64 2 to ptr))
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr inttoptr (i64 2 to ptr))
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr inttoptr (i64 3 to ptr))
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr inttoptr (i64 3 to ptr))
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr inttoptr (i64 4 to ptr))
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr inttoptr (i64 4 to ptr))
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+// CHECK-NEXT: %.x..void.addr = call ptr @__kmpc_alloc(i32 %[[#R0]], i64 4, ptr inttoptr (i64 5 to ptr))
+// CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
+// CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr inttoptr (i64 5 to ptr))
+
+// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
+// CHECK-NEXT: store i64 %x, ptr %x.addr, align 8
+/

[PATCH] D135834: [PowerPC] Fix parameters for __builtin_crypto_vsbox

2022-10-14 Thread Amy Kwan via Phabricator via cfe-commits
amyk accepted this revision as: amyk.
amyk added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135834

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


[clang] 3a31970 - [C2x] Implement support for nullptr and nullptr_t

2022-10-14 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-10-14T10:06:02-04:00
New Revision: 3a31970ee2af24ffcfd4b6fc11ac9bdf4d4ef2e8

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

LOG: [C2x] Implement support for nullptr and nullptr_t

This introduces support for nullptr and nullptr_t in C2x mode. The
proposal accepted by WG14 is:
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3042.htm

Note, there are quite a few incompatibilities with the C++ feature in
some of the edge cases of this feature. Therefore, there are some FIXME
comments in tests for testing behavior that might change after WG14 has
resolved national body comments (a process we've not yet started). So
this implementation might change slightly depending on the resolution
of comments. This is called out explicitly in the release notes as
well.

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

Added: 
clang/test/C/C2x/n3042.c
clang/test/Sema/nullptr-prec2x.c
clang/test/Sema/nullptr.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/PrettyPrinter.h
clang/include/clang/AST/Type.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/TokenKinds.def
clang/lib/AST/Expr.cpp
clang/lib/AST/Type.cpp
clang/lib/Headers/stddef.h
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/C/C11/n1330.c
clang/test/Sema/static-assert.c
clang/www/c_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2a81877f27b71..246025ee0a282 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -452,6 +452,32 @@ C2x Feature Support
 typeof(Val) OtherVal; // type is '__attribute__((address_space(1))) const 
_Atomic int'
 typeof_unqual(Val) OtherValUnqual; // type is 'int'
 
+- Implemented `WG14 N3042 
`_,
+  Introduce the nullptr constant. This introduces a new type ``nullptr_t``,
+  declared in  which represents the type of the null pointer 
named
+  constant, ``nullptr``. This constant is implicitly convertible to any pointer
+  type and represents a type-safe null value.
+
+  Note, there are some known incompatibilities with this same feature in C++.
+  The following examples were discovered during implementation and are subject
+  to change depending on how national body comments are resolved by WG14 (C
+  status is based on standard requirements, not necessarily implementation
+  behavior):
+
+  .. code-block:: c
+
+nullptr_t null_val;
+(nullptr_t)nullptr;   // Rejected in C, accepted in C++, Clang accepts
+(void)(1 ? nullptr : 0);  // Rejected in C, accepted in C++, Clang rejects
+(void)(1 ? null_val : 0); // Rejected in C, accepted in C++, Clang rejects
+bool b1 = nullptr;// Accepted in C, rejected in C++, Clang rejects
+b1 = null_val;// Accepted in C, rejected in C++, Clang rejects
+null_val = 0; // Rejected in C, accepted in C++, Clang rejects
+
+void func(nullptr_t);
+func(0);  // Rejected in C, accepted in C++, Clang rejects
+
+
 C++ Language Changes in Clang
 -
 - Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=15`` 
option

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 104fd92784e74..12065828df102 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -761,6 +761,8 @@ class CXXBoolLiteralExpr : public Expr {
 /// The null pointer literal (C++11 [lex.nullptr])
 ///
 /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr.
+/// This also implements the null pointer literal in C2x (C2x 6.4.1) which is
+/// intended to have the same semantics as the feature in C++.
 class CXXNullPtrLiteralExpr : public Expr {
 public:
   CXXNullPtrLiteralExpr(QualType Ty, SourceLocation Loc)

diff  --git a/clang/include/clang/AST/PrettyPrinter.h 
b/clang/include/clang/AST/PrettyPrinter.h
index cb25b2750dd43..5aeaca7beda2f 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -65,7 +65,8 @@ struct PrintingPolicy {
 SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
 SuppressTemplateArgsInCXXConstructors(false),
 SuppressDefaultTemplateArgs(true), Bool(LO.Bool),
-Nullptr(LO.CPlusPlus11), Restrict(LO.C99), Alignof(LO.CPlusPlus11),
+Nullptr(LO.CPlusPlus11 || LO.C2x), 
NullptrTypeInNamespace(LO.CP

[PATCH] D135099: [C2x] Implement support for nullptr and nullptr_t

2022-10-14 Thread Aaron Ballman 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 rG3a31970ee2af: [C2x] Implement support for nullptr and 
nullptr_t (authored by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135099

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/PrettyPrinter.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/Expr.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Headers/stddef.h
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/C/C11/n1330.c
  clang/test/C/C2x/n3042.c
  clang/test/Sema/nullptr-prec2x.c
  clang/test/Sema/nullptr.c
  clang/test/Sema/static-assert.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1204,7 +1204,13 @@
 
   Introduce the nullptr constant
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3042.htm";>N3042
-  No
+  
+Partial
+  Parts of the implementation may be incorrect until WG14 has completed NB comment
+  resolution for incompatibilities with C++ that were discovered. The major use cases
+  and usage patterns should work well, though.
+
+  
 
 
   Memory layout of unions
Index: clang/test/Sema/static-assert.c
===
--- clang/test/Sema/static-assert.c
+++ clang/test/Sema/static-assert.c
@@ -1,11 +1,11 @@
-// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fms-compatibility -DMS -fsyntax-only -verify=expected,ms %s
-// RUN: %clang_cc1 -std=c99 -pedantic -fsyntax-only -verify=expected,ext %s
+// RUN: %clang_cc1 -std=c11 -Wgnu-folding-constant -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fms-compatibility -Wgnu-folding-constant -DMS -fsyntax-only -verify=expected,ms %s
+// RUN: %clang_cc1 -std=c99 -pedantic -Wgnu-folding-constant -fsyntax-only -verify=expected,ext %s
 // RUN: %clang_cc1 -xc++ -std=c++11 -pedantic -fsyntax-only -verify=expected,ext,cxx %s
 
 _Static_assert("foo", "string is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
 #ifndef __cplusplus
-// expected-error@-2 {{static assertion expression is not an integral constant expression}}
+// expected-warning@-2 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
 #endif
 
 _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
@@ -85,12 +85,12 @@
 _Static_assert(1.0 != 0, "");  // ext-warning {{'_Static_assert' is a C11 extension}}
 _Static_assert(__builtin_strlen("1"), "");  // ext-warning {{'_Static_assert' is a C11 extension}}
 #ifndef __cplusplus
-// ext-warning@-9 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
-// ext-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
-// ext-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
-// ext-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
-// ext-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
-// ext-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-9 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
 // __builtin_strlen(literal) is considered an integer constant expression
 // and doesn't cause a pedantic warning
 #endif
Index: clang/test/Sema/nullptr.c
===
--- /dev/null
+++ clang/test/Sema/nullptr.c
@@ -0,0 +1,107 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x -ffreestanding -Wno-null-conversion -Wno

[PATCH] D101526: [analyzer][StdLibraryFunctionsChecker] Add NoteTags for applied arg constraints

2022-10-14 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 467772.
martong marked 3 inline comments as done.
martong added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101526

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

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
@@ -239,6 +239,7 @@
   // State split should not happen here. I.e. x == 1 should not be evaluated
   // FALSE.
   __two_constrained_args(x, y);
+  //NOTE! Because of the second `clang_analyzer_eval` call we have two bug
   clang_analyzer_eval(x == 1); // \
   // report-warning{{TRUE}} \
   // bugpath-warning{{TRUE}} \
@@ -252,7 +253,6 @@
 int __arg_constrained_twice(int);
 void test_multiple_constraints_on_same_arg(int x) {
   __arg_constrained_twice(x);
-  // Check that both constraints are applied and only one branch is there.
   clang_analyzer_eval(x < 1 || x > 2); // \
   // report-warning{{TRUE}} \
   // bugpath-warning{{TRUE}} \
Index: clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries=true \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple i686-unknown-linux \
+// RUN:   -analyzer-output=text \
+// RUN:   -verify
+
+int __single_val_0(int);  // [0, 0]
+
+int test_note(int x, int y) {
+__single_val_0(x);  // expected-note{{Assuming the 1st arg is within the range [0, 0]}}
+return y / x;   // expected-warning{{Division by zero}} \
+// expected-note{{Division by zero}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -134,9 +134,18 @@
 
 virtual StringRef getName() const = 0;
 
+// Represents that in which context do we require a description of the
+// constraint.
+enum class DescritptionKind {
+  // The constraint is violated.
+  Violation,
+  // We assume that the constraint is satisfied.
+  Assumption
+};
+
 // Give a description that explains the constraint to the user. Used when
 // the bug is reported.
-virtual std::string describe(ProgramStateRef State,
+virtual std::string describe(DescritptionKind DK, ProgramStateRef State,
  const Summary &Summary) const {
   // There are some descendant classes that are not used as argument
   // constraints, e.g. ComparisonConstraint. In that case we can safely
@@ -174,7 +183,7 @@
 RangeConstraint(ArgNo ArgN, RangeKind Kind, const IntRangeVector &Ranges)
 : ValueConstraint(ArgN), Kind(Kind), Ranges(Ranges) {}
 
-std::string describe(ProgramStateRef State,
+std::string describe(DescritptionKind DK, ProgramStateRef State,
  const Summary &Summary) const override;
 
 const IntRangeVector &getRanges() const { return Ranges; }
@@ -244,7 +253,7 @@
 bool CannotBeNull = true;
 
   public:
-std::string describe(ProgramStateRef State,
+std::string describe(DescritptionKind DK, ProgramStateRef State,
  const Summary &Summary) const override;
 StringRef getName() const override { return "NonNull"; }
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
@@ -316,7 +325,7 @@
   return Result;
 }
 
-std::string describe(ProgramStateRef State,
+std::string describe(DescritptionKind DK, ProgramStateRef State,
  const Summary &Summary) const override;
 
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
@@ -704,9 +713,12 @@
 // Highlight the range of the argument that was violated.
 R->addRange(Call.getArgSourceRange(VC->getArgNo()));
 
-// Describe the argument constraint in a note.
-R->addNote(VC->describe(C.getState(), Summary), R->getLocation(),
-   Call.getArgSourceRange(VC->

[PATCH] D101526: [analyzer][StdLibraryFunctionsChecker] Add NoteTags for applied arg constraints

2022-10-14 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 467773.
martong added a comment.

- Changed to be more verbose: "arg" -> "argument"
- Fixed "less than" to "greater than"
- Added new tests
- Fixed typos


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101526

Files:
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

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
@@ -239,6 +239,7 @@
   // State split should not happen here. I.e. x == 1 should not be evaluated
   // FALSE.
   __two_constrained_args(x, y);
+  //NOTE! Because of the second `clang_analyzer_eval` call we have two bug
   clang_analyzer_eval(x == 1); // \
   // report-warning{{TRUE}} \
   // bugpath-warning{{TRUE}} \
@@ -252,7 +253,6 @@
 int __arg_constrained_twice(int);
 void test_multiple_constraints_on_same_arg(int x) {
   __arg_constrained_twice(x);
-  // Check that both constraints are applied and only one branch is there.
   clang_analyzer_eval(x < 1 || x > 2); // \
   // report-warning{{TRUE}} \
   // bugpath-warning{{TRUE}} \
Index: clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
+++ clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
@@ -15,7 +15,7 @@
 int __not_null(int *);
 void test_not_null(int *x) {
   __not_null(nullptr); // \
-  // expected-note{{The 1st arg should not be NULL}} \
+  // expected-note{{The 1st argument should not be NULL}} \
   // expected-warning{{}}
 }
 
@@ -29,21 +29,21 @@
   case 1: {
 char buf[9];
 __buf_size_arg_constraint_concrete(buf); // \
-// expected-note{{The size of the 1st arg should be equal to or less than the value of 10}} \
+// expected-note{{The size of the 1st argument should be equal to or greater than the value of 10}} \
 // expected-warning{{}}
 break;
   }
   case 2: {
 char buf[3];
 __buf_size_arg_constraint(buf, 4); // \
-// expected-note{{The size of the 1st arg should be equal to or less than the value of the 2nd arg}} \
+// expected-note{{The size of the 1st argument should be equal to or greater than the value of the 2nd arg}} \
 // expected-warning{{}}
 break;
   }
   case 3: {
 char buf[3];
 __buf_size_arg_constraint_mul(buf, 4, 2); // \
-// expected-note{{The size of the 1st arg should be equal to or less than the value of the 2nd arg times the 3rd arg}} \
+// expected-note{{The size of the 1st argument should be equal to or greater than the value of the 2nd argument times the 3rd argument}} \
 // expected-warning{{}}
 break;
   }
@@ -56,7 +56,7 @@
 int __range_1_2__4_5(int);// [1, 2], [4, 5]
 void test_range(int x) {
 __single_val_1(2); // \
-// expected-note{{The 1st arg should be within the range [1, 1]}} \
+// expected-note{{The 1st argument should be within the range [1, 1]}} \
 // expected-warning{{}}
 }
 // Do more specific check against the range strings.
Index: clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries=true \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple i686-unknown-linux \
+// RUN:   -analyzer-output=text \
+// RUN:   -verify
+
+template 
+void clang_analyzer_express(T x);
+void clang_analyzer_eval(bool);
+int clang_analyzer_getExtent(void *);
+
+
+// Check NotNullConstraint assumption notes.
+int __not_null(int *);
+int test_not_null_note(int *x, int y) {
+  __not_null(x);  // expected-note{{Assuming the 1st argument is not NULL}}
+  if (x)  // expected-note{{'x' is non-null}} \
+  // expected-note{{Taking true branch}}
+if (!y)   // expected-note{{Assuming 'y' is 0}} \
+  // expected-note{{Taking true branch}}
+  return 1 / y;   // expe

[PATCH] D101526: [analyzer][StdLibraryFunctionsChecker] Add NoteTags for applied arg constraints

2022-10-14 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D101526#3804623 , @NoQ wrote:

> Hi, looks great! I found a couple of typos and the amount of changes in tests 
> is suspiciously low. And I want to make sure that the promise to change "arg" 
> -> "argument" isn't lost (but I'll be happy if it's addressed in a follow-up 
> patch).

Ok, I've changed "arg" to "argument" in the latest update, plus added new test 
cases. Thanks for the review!




Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:755
   Result += getArgDesc(ArgN);
-  Result += " should not be NULL";
+  Result += DK == Violation ? " should not be NULL" : " is not NULL";
   return Result.c_str();

NoQ wrote:
> I suspect this needs to be covered by tests.
Okay, I've added further tests for the "not-null" and the 
"buffer-size-constraint" cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101526

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


[clang] 6ce8727 - [cmake] Remove LLVM_INCLUDE_GO_TESTS variable

2022-10-14 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-10-14T16:34:36+02:00
New Revision: 6ce87272487711c9f0ff408a037f5ca2e1ff5c5d

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

LOG: [cmake] Remove LLVM_INCLUDE_GO_TESTS variable

As pointed out by thakis in https://reviews.llvm.org/D135436#3858463,
this variable can be dropped now that the Go bindings have been
removed.

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake
clang/cmake/caches/Fuchsia.cmake
llvm/CMakeLists.txt
llvm/test/CMakeLists.txt
llvm/test/lit.site.cfg.py.in

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index d0bdeb3249797..7a09e4798309e 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -21,7 +21,6 @@ set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")
 set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
-set(LLVM_INCLUDE_GO_TESTS OFF CACHE BOOL "")
 set(LLVM_STATIC_LINK_CXX_STDLIB ON CACHE BOOL "")
 set(LLVM_USE_RELATIVE_PATHS_IN_FILES ON CACHE BOOL "")
 

diff  --git a/clang/cmake/caches/Fuchsia.cmake 
b/clang/cmake/caches/Fuchsia.cmake
index 1978195c267d9..7537bf8a3ee2b 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -16,7 +16,6 @@ set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")
 set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
-set(LLVM_INCLUDE_GO_TESTS OFF CACHE BOOL "")
 
 if(WIN32)
   set(LLVM_USE_CRT_RELEASE "MT" CACHE STRING "")

diff  --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index d5925f9ae6a82..5b493a7ebad55 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -702,7 +702,6 @@ endif(LLVM_BUILD_EXAMPLES)
 option(LLVM_BUILD_TESTS
   "Build LLVM unit tests. If OFF, just generate build targets." OFF)
 option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
-option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build 
targets." OFF)
 
 option(LLVM_BUILD_BENCHMARKS "Add LLVM benchmark targets to the list of default
 targets. If OFF, benchmarks still could be built using Benchmarks target." OFF)

diff  --git a/llvm/test/CMakeLists.txt b/llvm/test/CMakeLists.txt
index d98908c4f05bc..a38fb0a2408d4 100644
--- a/llvm/test/CMakeLists.txt
+++ b/llvm/test/CMakeLists.txt
@@ -10,7 +10,6 @@ llvm_canonicalize_cmake_booleans(
   LLVM_ENABLE_ZLIB
   LLVM_ENABLE_ZSTD
   LLVM_ENABLE_LIBXML2
-  LLVM_INCLUDE_GO_TESTS
   LLVM_LINK_LLVM_DYLIB
   LLVM_TOOL_LTO_BUILD
   LLVM_USE_INTEL_JITEVENTS

diff  --git a/llvm/test/lit.site.cfg.py.in b/llvm/test/lit.site.cfg.py.in
index 63cfddaa93087..5531732e16bc3 100644
--- a/llvm/test/lit.site.cfg.py.in
+++ b/llvm/test/lit.site.cfg.py.in
@@ -21,7 +21,6 @@ config.osx_sysroot = path(r"@CMAKE_OSX_SYSROOT@")
 config.ocamlfind_executable = "@OCAMLFIND@"
 config.have_ocamlopt = @HAVE_OCAMLOPT@
 config.ocaml_flags = "@OCAMLFLAGS@"
-config.include_go_tests = @LLVM_INCLUDE_GO_TESTS@
 config.ptxas_executable = "@PTXAS_EXECUTABLE@"
 config.enable_shared = @ENABLE_SHARED@
 config.enable_assertions = @ENABLE_ASSERTIONS@



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


[PATCH] D135919: [Clang] Set thread_local Itanium ABI guard variables before calling constructors.

2022-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135919

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


[PATCH] D135690: [ASTMatchers] Add matcher for functions that are effectively inline

2022-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D135690#3856863 , @Trass3r wrote:

> In D135690#3852362 , @aaron.ballman 
> wrote:
>
>> what's the need for adding this matcher? Do you plan to use it for some 
>> in-tree needs? We usually only add new matchers where there's an immediate 
>> need for them because of how expensive AST matchers are to compile (and each 
>> matcher adds a fair number of template instantiations to the final binary as 
>> well, so there's a bit of runtime cost too).
>
> Didn't realize it has a big cost. Looking inside the `AST_MATCHER` and 
> `REGISTER_MATCHER` macros I can't see any unique instantiations, should be 
> memoized?

IIRC, the cost may depend on the compiler. I know we had to enable `/bigobj` 
when building with MSVC because each template instantiation here was being 
added to its own section in the object file and we'd wind up with tens of 
thousands of sections.

> I created it a while ago for use in a clang-tidy check. Oddly I can't find 
> that code right now.
> It might have been for finding inline ctors/dtors: 
> https://github.com/llvm/llvm-project/issues/51577.
> https://chromium.googlesource.com/chromium/src/tools/clang/+/refs/heads/main/plugins/FindBadConstructsConsumer.cpp#495

I think it might make more sense to use a local matcher if you need it only for 
one clang-tidy check. If we find we need it in more checks or there's a wider 
need for it, we can hoist it up to ASTMatchers.h so it's exposed more generally 
at that time. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135690

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


[clang] 84a9ec2 - Remove redundant option -menable-unsafe-fp-math.

2022-10-14 Thread Zahira Ammarguellat via cfe-commits

Author: Zahira Ammarguellat
Date: 2022-10-14T10:55:29-04:00
New Revision: 84a9ec2ff1ee97fd7e8ed988f5e7b197aab84a7b

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

LOG: Remove redundant option -menable-unsafe-fp-math.

There are currently two options that are used to tell the compiler to perform
unsafe floating-point optimizations:
'-ffast-math' and '-funsafe-math-optimizations'.

'-ffast-math' is enabled by default. It automatically enables the driver option
'-menable-unsafe-fp-math'.
Below is a table illustrating the special operations enabled automatically by
'-ffast-math', '-funsafe-math-optimizations' and '-menable-unsafe-fp-math'
respectively.

Special Operations -ffast-math  -funsafe-math-optimizations 
-menable-unsafe-fp-math
MathErrno  0 1  1
FiniteMathOnly 1 0  0
AllowFPReassoc 1 1  1
NoSignedZero   1 1  1
AllowRecip 1 1  1
ApproxFunc 1 1  1
RoundingMath   0 0  0
UnsafeFPMath   1 0  1
FPContract fast  on on

'-ffast-math' enables '-fno-math-errno', '-ffinite-math-only',
'-funsafe-math-optimzations' and sets 'FpContract' to 'fast'. The driver option
'-menable-unsafe-fp-math' enables the same special options than
'-funsafe-math-optimizations'. This is redundant.
We propose to remove the driver option '-menable-unsafe-fp-math' and use
instead, the setting of the special operations to set the function attribute
'unsafe-fp-math'. This attribute will be enabled only if those special
operations are enabled and if 'FPContract' is either 'fast' or set to the
default value.

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

Added: 
clang/test/CodeGen/func-attr.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/fp-options-to-fast-math-flags.c
clang/test/CodeGen/libcalls.c
clang/test/CodeGenCUDA/propagate-metadata.cu
clang/test/Driver/cl-options.c
clang/test/Driver/fast-math.c
clang/test/Driver/fp-model.c
clang/test/Parser/fp-floatcontrol-syntax.cpp
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 246025ee0a282..d946b5d8216a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -598,6 +598,9 @@ Arm and AArch64 Support in Clang
 
 Floating Point Support in Clang
 ---
+- The driver option ``-menable-unsafe-fp-math`` has been removed. To enable
+  unsafe floating-point optimizations use ``-funsafe-math-optimizations`` or
+  ``-ffast-math`` instead.
 
 Internal API Changes
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 49a75cef2d348..ef8d6f59d0985 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1596,10 +1596,6 @@ defm fast_math : BoolFOption<"fast-math",
   PosFlag,
   NegFlag>;
-def menable_unsafe_fp_math : Flag<["-"], "menable-unsafe-fp-math">, 
Flags<[CC1Option]>,
-  HelpText<"Allow unsafe floating-point math optimizations which may decrease 
precision">,
-  MarshallingInfoFlag>,
-  ImpliedByAnyOf<[cl_unsafe_math_optimizations.KeyPath, ffast_math.KeyPath]>;
 defm math_errno : BoolFOption<"math-errno",
   LangOpts<"MathErrno">, DefaultFalse,
   PosFlag,
@@ -1879,7 +1875,10 @@ def fsanitize_undefined_strip_path_components_EQ : 
Joined<["-"], "fsanitize-unde
 } // end -f[no-]sanitize* flags
 
 def funsafe_math_optimizations : Flag<["-"], "funsafe-math-optimizations">,
-  Group;
+  Group, Flags<[CC1Option]>,
+  HelpText<"Allow unsafe floating-point math optimizations which may decrease 
precision">,
+  MarshallingInfoFlag>,
+  ImpliedByAnyOf<[cl_unsafe_math_optimizations.KeyPath, ffast_math.KeyPath]>;
 def fno_unsafe_math_optimizations : Flag<["-"], 
"fno-unsafe-math-optimizations">,
   Group;
 def fassociative_math : Flag<["-"], "fassociative-math">, Group;
@@ -1887,12 +1886,12 @@ def fno_associative_math : Flag<["-"], 
"fno-associative-math">, Group;
 defm reciprocal_math : BoolFOption<"reciprocal-math",
   LangOpts<"AllowRecip">, DefaultFalse,
   PosFlag,
+  [funsafe_math_optimizations.KeyPath]>,
   NegFlag>;
 defm approx_func : BoolFOption<"approx-func", LangOpts<"ApproxFunc">, 
DefaultFalse,
PosFlag

[PATCH] D135097: Remove redundant option '-menable-unsafe-fp-math'.

2022-10-14 Thread Zahira Ammarguellat via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
zahiraam marked an inline comment as done.
Closed by commit rG84a9ec2ff1ee: Remove redundant option 
-menable-unsafe-fp-math. (authored by zahiraam).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135097

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/fp-options-to-fast-math-flags.c
  clang/test/CodeGen/func-attr.c
  clang/test/CodeGen/libcalls.c
  clang/test/CodeGenCUDA/propagate-metadata.cu
  clang/test/Driver/cl-options.c
  clang/test/Driver/fast-math.c
  clang/test/Driver/fp-model.c
  clang/test/Parser/fp-floatcontrol-syntax.cpp
  clang/unittests/Frontend/CompilerInvocationTest.cpp

Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -705,7 +705,7 @@
 //
 //   * -cl-unsafe-math-optimizations
 // * -cl-mad-enable
-// * -menable-unsafe-fp-math
+// * -funsafe-math-optimizations
 //   * -freciprocal-math
 
 TEST_F(CommandLineTest, ImpliedBoolOptionsNoFlagPresent) {
@@ -723,7 +723,8 @@
   ASSERT_THAT(GeneratedArgs,
   Not(Contains(StrEq("-cl-unsafe-math-optimizations";
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-mad-enable";
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-menable-unsafe-fp-math";
+  ASSERT_THAT(GeneratedArgs,
+  Not(Contains(StrEq("-funsafe-math-optimizations";
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math";
 }
 
@@ -745,13 +746,14 @@
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-unsafe-math-optimizations")));
   // Not generated - implied by the generated root flag.
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-mad-enable";
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-menable-unsafe-fp-math";
+  ASSERT_THAT(GeneratedArgs,
+  Not(Contains(StrEq("-funsafe-math-optimizations";
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math";
 }
 
 TEST_F(CommandLineTest, ImpliedBoolOptionsAllFlagsPresent) {
   const char *Args[] = {"-cl-unsafe-math-optimizations", "-cl-mad-enable",
-"-menable-unsafe-fp-math", "-freciprocal-math"};
+"-funsafe-math-optimizations", "-freciprocal-math"};
 
   ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
   ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath);
@@ -765,12 +767,13 @@
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-unsafe-math-optimizations")));
   // Not generated - implied by their generated parent.
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-mad-enable";
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-menable-unsafe-fp-math";
+  ASSERT_THAT(GeneratedArgs,
+  Not(Contains(StrEq("-funsafe-math-optimizations";
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math";
 }
 
 TEST_F(CommandLineTest, ImpliedBoolOptionsImpliedFlagsPresent) {
-  const char *Args[] = {"-cl-mad-enable", "-menable-unsafe-fp-math",
+  const char *Args[] = {"-cl-mad-enable", "-funsafe-math-optimizations",
 "-freciprocal-math"};
 
   ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
@@ -785,13 +788,13 @@
   Not(Contains(StrEq("-cl-unsafe-math-optimizations";
   // Generated - explicitly provided.
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-mad-enable")));
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-menable-unsafe-fp-math")));
+  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-funsafe-math-optimizations")));
   // Not generated - implied by its generated parent.
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math";
 }
 
 TEST_F(CommandLineTest, PresentAndNotImpliedGenerated) {
-  const char *Args[] = {"-cl-mad-enable", "-menable-unsafe-fp-math"};
+  const char *Args[] = {"-cl-mad-enable", "-funsafe-math-optimizations"};
 
   ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
 
@@ -799,7 +802,7 @@
 
   // Present options that were not implied are generated.
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-mad-enable")));
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-menable-unsafe-fp-math")));
+  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-funsafe-math-optimizations")));
 }
 
 // Diagnostic option.
Index: clang/test/Parser/fp-floatcontrol-syntax.cpp
===
--- clang/test/Parser/fp-floatcontrol-syntax.cpp
+++ clang/test/Parser/fp-floatcontrol-syntax.cpp
@@ -42,7 +42,7 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fd

[PATCH] D131944: [analyzer] Remove pattern matching of lambda capture initializers

2022-10-14 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/test/Analysis/lambdas.cpp:226
+  [uniquePtr = MakeUniquePtr()] {}();
+  clang_analyzer_warnIfReached(); // expected-warning{{TRUE}}
+}

It should have said `REACHABLE`.
How does this pass? @isuckatcs 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131944

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


[PATCH] D135557: Add needsImplicitDefaultConstructor and friends

2022-10-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added subscribers: rjmccall, echristo, dblaikie, rsmith.
aaron.ballman added inline comments.



Comment at: clang/bindings/python/clang/cindex.py:1530
+
+def record_needs_implicit_default_constructor(self):
+"""Returns True if the cursor refers to a C++ record declaration

royjacobson wrote:
> anderslanglands wrote:
> > royjacobson wrote:
> > > anderslanglands wrote:
> > > > royjacobson wrote:
> > > > > aaron.ballman wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > I don't think we should expose any of the "needs" functions like 
> > > > > > > this -- those are internal implementation details of the class 
> > > > > > > and I don't think we want to calcify that into something we have 
> > > > > > > to support forever. As we add members to a class, we recalculate 
> > > > > > > whether the added member causes us to delete defaulted special 
> > > > > > > members (among other things), and the "needs" functions are 
> > > > > > > basically used when the class is completed to handle lazily 
> > > > > > > created special members. I'm pretty sure that lazy creation is 
> > > > > > > not mandated by the standard, which is why I think the "needs" 
> > > > > > > functions are more of an implementation detail.
> > > > > > CC @erichkeane and @royjacobson as folks who have been in this same 
> > > > > > area of the compiler to see if they agree or disagree with my 
> > > > > > assessment there.
> > > > > I think so. The 'needs_*' functions query `DeclaredSpecialMembers` 
> > > > > and I'm pretty sure it's modified when we add the implicit 
> > > > > definitions in the class completion code. So this looks a bit 
> > > > > suspicious. Is this API //meant// to be used with incomplete classes?
> > > > > For complete classes I think looking up the default/move/copy 
> > > > > constructor and calling `isImplicit()` is the way to do it.
> > > > > 
> > > > > About the 'is deleted' API - can't the same be done for those 
> > > > > functions as well so we have a smaller API? 
> > > > > 
> > > > > If this //is// meant to be used with incomplete classes for 
> > > > > efficiency that would be another thing, I guess.
> > > > > 
> > > > So the intended use case here is I'm using libclang to parse an 
> > > > existing C++ libray's headers and generate a C interface to it. To do 
> > > > that I need to know if I need to generate default constructors etc, 
> > > > which the needs* methods do for me (I believe). The alternative is I 
> > > > have to check manually whether all the constructors/assignment 
> > > > operators exist, then implement the implicit declaration rules myself 
> > > > correctly for each version of the standard, which I'd rather avoid.
> > > > 
> > > > Would putting a note in the doc comment about the behaviour differing 
> > > > when the class is being constructed as originally suggested work for 
> > > > everyone?
> > > Why is the `__is_default_constructible` builtin type trait not enough? Do 
> > > you have different behavior for user provided and implicit default 
> > > constructors?
> > > 
> > Can I evaluate that  from libclang somewhow? I can't modify the C++ 
> > libraries I'm wrapping. 
> > 
> > Basically, given:
> > ```
> > struct Foo { /* ... */ };
> > ```
> > 
> > I want to generate:
> > 
> > ```
> > typedef struct Foo_t;
> > 
> > Foo_t* Foo_ctor();
> > Foo_t* Foo_copy_ctor(Foo_t*);
> > /* etc... */
> > Foo_dtor(Foo_t*);
> > ```
> > 
> > In order to know which ones to generate for an arbitrary struct that may or 
> > may not have any combination of ctor/assignments defined, I need to know 
> > which ones exist and follow the implicit generation rules for the ones that 
> > don't. I can do this myself with a whole bunch of version-dependent logic, 
> > but I'd rather just rely on libclang since it already knows all this much 
> > better than I do.
> I looked a bit, and it seems they aren't, and that generally libclang doesn't 
> really know about Sema, so exporting the type traits is not that easy :/
> 
> I'm not sure what's the best way forward here, but I don't like the idea of 
> exporting those half baked internal API calls when there are actual 
> standardized and implemented type traits that perform the same goal.
CCing folks who may have more historical memory of the C APIs and whether 
they're expected to operate on a completed AST or are expected to work on an 
AST as it is under construction. My unverified belief is that these APIs are 
expected to work on a completed AST.

@echristo @dblaikie @rjmccall @rsmith

I'm also not certain of what the best path forward is here. I'm not comfortable 
exposing the needs* functions because they really are implementation details 
and I don't want to promise we'll support that API forever. But at the same 
time, the use case is reasonably compelling on the assumption you need to 
inspect the AST nodes as they're still under construction instead of inspecting 
them once the AST is completed. If t

[clang] 30b67c6 - [AArch64] Make ACLE intrinsics always available part1

2022-10-14 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2022-10-14T17:23:11+02:00
New Revision: 30b67c677c6baf0d6ef6c3051cf270133c43e4d2

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

LOG: [AArch64] Make ACLE intrinsics always available part1

A given arch feature might enabled by a pragma or a function attribute so in 
this cases would be nice to use intrinsics.
Today GCC offers the intrinsics without the march flag[1].
PR[2] for ACLE to clarify the intention and remove the need for -march flag for 
a given intrinsics.

This is going to be more useful when D127812 lands.

[1] https://godbolt.org/z/bxcMhav3z
[2] https://github.com/ARM-software/acle/pull/214

Reviewed By: dmgreen

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAArch64.def
clang/lib/Headers/arm_acle.h
clang/test/CodeGen/arm_acle.c
clang/test/CodeGen/builtins-arm64.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index 036df7435bfb..e6e375bc2b83 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -74,7 +74,7 @@ BUILTIN(__builtin_arm_dmb, "vUi", "nc")
 BUILTIN(__builtin_arm_dsb, "vUi", "nc")
 BUILTIN(__builtin_arm_isb, "vUi", "nc")
 
-BUILTIN(__builtin_arm_jcvt, "Zid", "nc")
+TARGET_BUILTIN(__builtin_arm_jcvt, "Zid", "nc", "v8.3a")
 
 // Prefetch
 BUILTIN(__builtin_arm_prefetch, "vvC*UiUiUiUi", "nc")
@@ -107,24 +107,24 @@ BUILTIN(__builtin_arm_tcancel, "vWUIi", "n")
 BUILTIN(__builtin_arm_ttest, "WUi", "nc")
 
 // Armv8.5-A FP rounding intrinsics
-BUILTIN(__builtin_arm_rint32zf, "ff", "")
-BUILTIN(__builtin_arm_rint32z, "dd", "")
-BUILTIN(__builtin_arm_rint64zf, "ff", "")
-BUILTIN(__builtin_arm_rint64z, "dd", "")
-BUILTIN(__builtin_arm_rint32xf, "ff", "")
-BUILTIN(__builtin_arm_rint32x, "dd", "")
-BUILTIN(__builtin_arm_rint64xf, "ff", "")
-BUILTIN(__builtin_arm_rint64x, "dd", "")
+TARGET_BUILTIN(__builtin_arm_rint32zf, "ff", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint32z, "dd", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint64zf, "ff", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint64z, "dd", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint32xf, "ff", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint32x, "dd", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint64xf, "ff", "", "v8.5a")
+TARGET_BUILTIN(__builtin_arm_rint64x, "dd", "", "v8.5a")
 
 // Armv8.5-A Random number generation intrinsics
-BUILTIN(__builtin_arm_rndr,   "iWUi*", "n")
-BUILTIN(__builtin_arm_rndrrs, "iWUi*", "n")
+TARGET_BUILTIN(__builtin_arm_rndr,   "iWUi*", "n", "rand")
+TARGET_BUILTIN(__builtin_arm_rndrrs, "iWUi*", "n", "rand")
 
 // Armv8.7-A load/store 64-byte intrinsics
-BUILTIN(__builtin_arm_ld64b, "vvC*WUi*", "n")
-BUILTIN(__builtin_arm_st64b, "vv*WUiC*", "n")
-BUILTIN(__builtin_arm_st64bv, "WUiv*WUiC*", "n")
-BUILTIN(__builtin_arm_st64bv0, "WUiv*WUiC*", "n")
+TARGET_BUILTIN(__builtin_arm_ld64b, "vvC*WUi*", "n", "ls64")
+TARGET_BUILTIN(__builtin_arm_st64b, "vv*WUiC*", "n", "ls64")
+TARGET_BUILTIN(__builtin_arm_st64bv, "WUiv*WUiC*", "n", "ls64")
+TARGET_BUILTIN(__builtin_arm_st64bv0, "WUiv*WUiC*", "n", "ls64")
 
 TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", 
ALL_MS_LANGUAGES, "")

diff  --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index ed3fc1de1fd4..d73b6bf82d69 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -589,122 +589,123 @@ __smusdx(int16x2_t __a, int16x2_t __b) {
 #endif
 
 /* 9.7 CRC32 intrinsics */
-#if defined(__ARM_FEATURE_CRC32) && __ARM_FEATURE_CRC32
-static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
+#if (defined(__ARM_FEATURE_CRC32) && __ARM_FEATURE_CRC32) ||   
\
+(defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE)
+static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__, 
target("crc")))
 __crc32b(uint32_t __a, uint8_t __b) {
   return __builtin_arm_crc32b(__a, __b);
 }
 
-static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__, 
target("crc")))
 __crc32h(uint32_t __a, uint16_t __b) {
   return __builtin_arm_crc32h(__a, __b);
 }
 
-static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__, 
target("crc")))
 __crc32w(uint32_t __a, uint32_t __b) {
   return __builtin_arm_crc32w(__a, __b);
 }
 
-static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
+static __inline__ uint32_t __attribute__((__always_inline__, __n

  1   2   3   >