[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-08-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:440
+  State, {std::make_pair(CC->getCXXThisVal(), ArgVal)},
+  C.getLocationContext(), PSK_DirectEscapeOnCall, );
 

RedDocMD wrote:
> It seems to me that this pointer escape doesn't work.
> For the following code:
> ```lang=cpp
> void foo() {
> auto ptr = std::unique_ptr(new int(13));
> // Leak warning emitted here
> }
> ```
> the exploded graph shows the SVal for `new int(13)` as allocated instead of 
> escaped (which eventually triggers the warning).
It shouldn't work in this case. The variable is local. Write to a local 
variable doesn't constitute an escape because access to a local variable from 
elsewhere is impossible.

I believe we should explicitly tell `MallocChecker` that memory is released, 
given that we know that this is exactly what happens. We could do this 
similarly to how `InnerPointerChecker` tells `MallocChecker` that 
`std::string::c_str()` is released when the string is destroyed.

Another solution would be to force an escape by calling `escapeValue()` 
directly. That'll definitely notify all checkers that the raw pointer value 
should be dropped but that wouldn't allow us to ultimately find use-after-free 
of that value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

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


[PATCH] D107720: [analyzer] Cleanup a FIXME in SValBuilder.cpp

2021-08-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Looks correct.

Tests pls? I think that's one of the places where `clang_analyzer_dump()` is 
appropriate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107720

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


[PATCH] D107433: [RISCV] Half-precision for vget/vset.

2021-08-08 Thread Zakk Chen via Phabricator via cfe-commits
khchen accepted this revision.
khchen 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/D107433/new/

https://reviews.llvm.org/D107433

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


[PATCH] D107433: [RISCV] Half-precision for vget/vset.

2021-08-08 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai updated this revision to Diff 365065.
HsiangKai added a comment.

Update test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107433

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics/vget.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vset.c

Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vset.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics/vset.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vset.c
@@ -1,6 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // REQUIRES: riscv-registered-target
-// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d -target-feature +experimental-v \
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +experimental-v -target-feature +experimental-zfh \
 // RUN:   -disable-O0-optnone -emit-llvm %s -o - | opt -S -mem2reg | FileCheck --check-prefix=CHECK-RV64 %s
 
 #include 
@@ -544,3 +545,57 @@
 vfloat64m8_t test_vset_v_f64m4_f64m8(vfloat64m8_t dest, vfloat64m4_t val) {
   return vset_v_f64m4_f64m8(dest, 1, val);
 }
+
+// CHECK-RV64-LABEL: @test_vset_v_f16m1_f16m2(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv8f16.nxv4f16( [[DEST:%.*]],  [[VAL:%.*]], i64 0)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vfloat16m2_t test_vset_v_f16m1_f16m2 (vfloat16m2_t dest, vfloat16m1_t val) {
+  return vset_v_f16m1_f16m2(dest, 0, val);
+}
+
+// CHECK-RV64-LABEL: @test_vset_v_f16m1_f16m4(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv16f16.nxv4f16( [[DEST:%.*]],  [[VAL:%.*]], i64 0)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vfloat16m4_t test_vset_v_f16m1_f16m4 (vfloat16m4_t dest, vfloat16m1_t val) {
+  return vset_v_f16m1_f16m4(dest, 0, val);
+}
+
+// CHECK-RV64-LABEL: @test_vset_v_f16m2_f16m4(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv16f16.nxv8f16( [[DEST:%.*]],  [[VAL:%.*]], i64 0)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vfloat16m4_t test_vset_v_f16m2_f16m4 (vfloat16m4_t dest, vfloat16m2_t val) {
+  return vset_v_f16m2_f16m4(dest, 0, val);
+}
+
+// CHECK-RV64-LABEL: @test_vset_v_f16m1_f16m8(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv32f16.nxv4f16( [[DEST:%.*]],  [[VAL:%.*]], i64 0)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vfloat16m8_t test_vset_v_f16m1_f16m8 (vfloat16m8_t dest, vfloat16m1_t val) {
+  return vset_v_f16m1_f16m8(dest, 0, val);
+}
+
+// CHECK-RV64-LABEL: @test_vset_v_f16m2_f16m8(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv32f16.nxv8f16( [[DEST:%.*]],  [[VAL:%.*]], i64 0)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vfloat16m8_t test_vset_v_f16m2_f16m8 (vfloat16m8_t dest, vfloat16m2_t val) {
+  return vset_v_f16m2_f16m8(dest, 0, val);
+}
+
+// CHECK-RV64-LABEL: @test_vset_v_f16m4_f16m8(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv32f16.nxv16f16( [[DEST:%.*]],  [[VAL:%.*]], i64 0)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vfloat16m8_t test_vset_v_f16m4_f16m8 (vfloat16m8_t dest, vfloat16m4_t val) {
+  return vset_v_f16m4_f16m8(dest, 0, val);
+}
Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vget.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics/vget.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vget.c
@@ -1,6 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // REQUIRES: riscv-registered-target
-// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d -target-feature +experimental-v \
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +experimental-v -target-feature +experimental-zfh \
 // RUN:   -disable-O0-optnone -emit-llvm %s -o - | opt -S -mem2reg | FileCheck --check-prefix=CHECK-RV64 %s
 
 #include 
@@ -544,3 +545,57 @@
 vfloat64m4_t test_vget_v_f64m8_f64m4(vfloat64m8_t src) {
   return vget_v_f64m8_f64m4(src, 1);
 }
+
+// CHECK-RV64-LABEL: @test_vget_v_f16m2_f16m1(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.extract.nxv4f16.nxv8f16( [[SRC:%.*]], i64 0)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t test_vget_v_f16m2_f16m1 (vfloat16m2_t src) {
+  return vget_v_f16m2_f16m1(src, 0);
+}
+
+// CHECK-RV64-LABEL: @test_vget_v_f16m4_f16m1(
+// CHECK-RV64-NEXT:  entry:
+// CHECK-RV64-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.extract.nxv4f16.nxv16f16( [[SRC:%.*]], i64 0)
+// CHECK-RV64-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t 

[PATCH] D107723: [Clang] Moved warning of warnReturnTypestateForUnconsumableType back to SemaDeclAttr

2021-08-08 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 365064.

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

https://reviews.llvm.org/D107723

Files:
  clang/include/clang/Analysis/Analyses/Consumed.h
  clang/lib/Analysis/Consumed.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaCXX/warn-consumed-parsing.cpp

Index: clang/test/SemaCXX/warn-consumed-parsing.cpp
===
--- clang/test/SemaCXX/warn-consumed-parsing.cpp
+++ clang/test/SemaCXX/warn-consumed-parsing.cpp
@@ -6,16 +6,6 @@
 #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
 #define TEST_TYPESTATE(state)   __attribute__ ((test_typestate(state)))
 
-// FIXME: This test is here because the warning is issued by the Consumed
-//analysis, not SemaDeclAttr.  The analysis won't run after an error
-//has been issued.  Once the attribute propagation for template
-//instantiation has been fixed, this can be moved somewhere else and the
-//definition can be removed.
-int returnTypestateForUnconsumable() RETURN_TYPESTATE(consumed); // expected-warning {{return state set for an unconsumable type 'int'}}
-int returnTypestateForUnconsumable() {
-  return 0;
-}
-
 class AttrTester0 {
   void consumes()   __attribute__ ((set_typestate())); // expected-error {{'set_typestate' attribute takes one argument}}
   bool testUnconsumed() __attribute__ ((test_typestate())); // expected-error {{'test_typestate' attribute takes one argument}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -1190,17 +1190,14 @@
 return;
   }
 
-  // FIXME: This check is currently being done in the analysis.  It can be
-  //enabled here only after the parser propagates attributes at
-  //template specialization definition, not declaration.
-  //QualType ReturnType = cast(D)->getType();
-  //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
-  //
-  //if (!RD || !RD->hasAttr()) {
-  //S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
-  //  ReturnType.getAsString();
-  //return;
-  //}
+  QualType ReturnType = cast(D)->getType();
+  const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
+
+  if (!RD || !RD->hasAttr()) {
+S.Diag(AL.getLoc(), diag::warn_return_typestate_for_unconsumable_type)
+<< ReturnType.getAsString();
+return;
+  }
 
   D->addAttr(::new (S.Context) ParamTypestateAttr(S.Context, AL, ParamState));
 }
@@ -1222,30 +1219,27 @@
 return;
   }
 
-  // FIXME: This check is currently being done in the analysis.  It can be
-  //enabled here only after the parser propagates attributes at
-  //template specialization definition, not declaration.
-  //QualType ReturnType;
-  //
-  //if (const ParmVarDecl *Param = dyn_cast(D)) {
-  //  ReturnType = Param->getType();
-  //
-  //} else if (const CXXConstructorDecl *Constructor =
-  // dyn_cast(D)) {
-  //  ReturnType = Constructor->getThisType()->getPointeeType();
-  //
-  //} else {
-  //
-  //  ReturnType = cast(D)->getCallResultType();
-  //}
-  //
-  //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
-  //
-  //if (!RD || !RD->hasAttr()) {
-  //S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
-  //  ReturnType.getAsString();
-  //return;
-  //}
+  QualType ReturnType;
+
+  if (const ParmVarDecl *Param = dyn_cast(D)) {
+ReturnType = Param->getType();
+
+  } else if (const CXXConstructorDecl *Constructor =
+ dyn_cast(D)) {
+ReturnType = Constructor->getThisType()->getPointeeType();
+
+  } else {
+
+ReturnType = cast(D)->getCallResultType();
+  }
+
+  const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
+
+  if (!RD || !RD->hasAttr()) {
+S.Diag(AL.getLoc(), diag::warn_return_typestate_for_unconsumable_type)
+<< ReturnType.getAsString();
+return;
+  }
 
   D->addAttr(::new (S.Context) ReturnTypestateAttr(S.Context, AL, ReturnState));
 }
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2109,14 +2109,6 @@
 Warnings.emplace_back(std::move(Warning), OptionalNotes());
   }
 
-  void warnReturnTypestateForUnconsumableType(SourceLocation Loc,
-  StringRef TypeName) override {
-PartialDiagnosticAt Warning(Loc, S.PDiag(
-  diag::warn_return_typestate_for_unconsumable_type) << TypeName);
-
-Warnings.emplace_back(std::move(Warning), OptionalNotes());
-  }
-
   void warnReturnTypestateMismatch(SourceLocation Loc, StringRef ExpectedState,
StringRef ObservedState) override {
 
Index: 

[PATCH] D107723: [Clang] Moved warning of warnReturnTypestateForUnconsumableType back to SemaDeclAttr

2021-08-08 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 365062.

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

https://reviews.llvm.org/D107723

Files:
  clang/include/clang/Analysis/Analyses/Consumed.h
  clang/lib/Analysis/Consumed.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaCXX/warn-consumed-parsing.cpp

Index: clang/test/SemaCXX/warn-consumed-parsing.cpp
===
--- clang/test/SemaCXX/warn-consumed-parsing.cpp
+++ clang/test/SemaCXX/warn-consumed-parsing.cpp
@@ -6,16 +6,6 @@
 #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
 #define TEST_TYPESTATE(state)   __attribute__ ((test_typestate(state)))
 
-// FIXME: This test is here because the warning is issued by the Consumed
-//analysis, not SemaDeclAttr.  The analysis won't run after an error
-//has been issued.  Once the attribute propagation for template
-//instantiation has been fixed, this can be moved somewhere else and the
-//definition can be removed.
-int returnTypestateForUnconsumable() RETURN_TYPESTATE(consumed); // expected-warning {{return state set for an unconsumable type 'int'}}
-int returnTypestateForUnconsumable() {
-  return 0;
-}
-
 class AttrTester0 {
   void consumes()   __attribute__ ((set_typestate())); // expected-error {{'set_typestate' attribute takes one argument}}
   bool testUnconsumed() __attribute__ ((test_typestate())); // expected-error {{'test_typestate' attribute takes one argument}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -1190,17 +1190,14 @@
 return;
   }
 
-  // FIXME: This check is currently being done in the analysis.  It can be
-  //enabled here only after the parser propagates attributes at
-  //template specialization definition, not declaration.
-  //QualType ReturnType = cast(D)->getType();
-  //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
-  //
-  //if (!RD || !RD->hasAttr()) {
-  //S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
-  //  ReturnType.getAsString();
-  //return;
-  //}
+  QualType ReturnType = cast(D)->getType();
+  const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
+
+  if (!RD || !RD->hasAttr()) {
+S.Diag(AL.getLoc(), diag::warn_return_typestate_for_unconsumable_type)
+<< ReturnType.getAsString();
+return;
+  }
 
   D->addAttr(::new (S.Context) ParamTypestateAttr(S.Context, AL, ParamState));
 }
@@ -1222,30 +1219,27 @@
 return;
   }
 
-  // FIXME: This check is currently being done in the analysis.  It can be
-  //enabled here only after the parser propagates attributes at
-  //template specialization definition, not declaration.
-  //QualType ReturnType;
-  //
-  //if (const ParmVarDecl *Param = dyn_cast(D)) {
-  //  ReturnType = Param->getType();
-  //
-  //} else if (const CXXConstructorDecl *Constructor =
-  // dyn_cast(D)) {
-  //  ReturnType = Constructor->getThisType()->getPointeeType();
-  //
-  //} else {
-  //
-  //  ReturnType = cast(D)->getCallResultType();
-  //}
-  //
-  //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
-  //
-  //if (!RD || !RD->hasAttr()) {
-  //S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
-  //  ReturnType.getAsString();
-  //return;
-  //}
+  QualType ReturnType;
+
+  if (const ParmVarDecl *Param = dyn_cast(D)) {
+ReturnType = Param->getType();
+
+  } else if (const CXXConstructorDecl *Constructor =
+ dyn_cast(D)) {
+ReturnType = Constructor->getThisType()->getPointeeType();
+
+  } else {
+
+ReturnType = cast(D)->getCallResultType();
+  }
+
+  const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
+
+  if (!RD || !RD->hasAttr()) {
+S.Diag(Attr.getLoc(), diag::warn_return_typestate_for_unconsumable_type)
+<< ReturnType.getAsString();
+return;
+  }
 
   D->addAttr(::new (S.Context) ReturnTypestateAttr(S.Context, AL, ReturnState));
 }
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2109,14 +2109,6 @@
 Warnings.emplace_back(std::move(Warning), OptionalNotes());
   }
 
-  void warnReturnTypestateForUnconsumableType(SourceLocation Loc,
-  StringRef TypeName) override {
-PartialDiagnosticAt Warning(Loc, S.PDiag(
-  diag::warn_return_typestate_for_unconsumable_type) << TypeName);
-
-Warnings.emplace_back(std::move(Warning), OptionalNotes());
-  }
-
   void warnReturnTypestateMismatch(SourceLocation Loc, StringRef ExpectedState,
StringRef ObservedState) override {
 
Index: 

[PATCH] D107723: [Clang] Moved warning of warnReturnTypestateForUnconsumableType back to SemaDeclAttr

2021-08-08 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 365061.

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

https://reviews.llvm.org/D107723

Files:
  clang/include/clang/Analysis/Analyses/Consumed.h
  clang/lib/Analysis/Consumed.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaCXX/warn-consumed-parsing.cpp

Index: clang/test/SemaCXX/warn-consumed-parsing.cpp
===
--- clang/test/SemaCXX/warn-consumed-parsing.cpp
+++ clang/test/SemaCXX/warn-consumed-parsing.cpp
@@ -6,16 +6,6 @@
 #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
 #define TEST_TYPESTATE(state)   __attribute__ ((test_typestate(state)))
 
-// FIXME: This test is here because the warning is issued by the Consumed
-//analysis, not SemaDeclAttr.  The analysis won't run after an error
-//has been issued.  Once the attribute propagation for template
-//instantiation has been fixed, this can be moved somewhere else and the
-//definition can be removed.
-int returnTypestateForUnconsumable() RETURN_TYPESTATE(consumed); // expected-warning {{return state set for an unconsumable type 'int'}}
-int returnTypestateForUnconsumable() {
-  return 0;
-}
-
 class AttrTester0 {
   void consumes()   __attribute__ ((set_typestate())); // expected-error {{'set_typestate' attribute takes one argument}}
   bool testUnconsumed() __attribute__ ((test_typestate())); // expected-error {{'test_typestate' attribute takes one argument}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -1190,17 +1190,14 @@
 return;
   }
 
-  // FIXME: This check is currently being done in the analysis.  It can be
-  //enabled here only after the parser propagates attributes at
-  //template specialization definition, not declaration.
-  //QualType ReturnType = cast(D)->getType();
-  //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
-  //
-  //if (!RD || !RD->hasAttr()) {
-  //S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
-  //  ReturnType.getAsString();
-  //return;
-  //}
+  QualType ReturnType = cast(D)->getType();
+  const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
+  
+  if (!RD || !RD->hasAttr()) {
+ S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
+   ReturnType.getAsString();
+ return;
+  }
 
   D->addAttr(::new (S.Context) ParamTypestateAttr(S.Context, AL, ParamState));
 }
@@ -1222,30 +1219,27 @@
 return;
   }
 
-  // FIXME: This check is currently being done in the analysis.  It can be
-  //enabled here only after the parser propagates attributes at
-  //template specialization definition, not declaration.
-  //QualType ReturnType;
-  //
-  //if (const ParmVarDecl *Param = dyn_cast(D)) {
-  //  ReturnType = Param->getType();
-  //
-  //} else if (const CXXConstructorDecl *Constructor =
-  // dyn_cast(D)) {
-  //  ReturnType = Constructor->getThisType()->getPointeeType();
-  //
-  //} else {
-  //
-  //  ReturnType = cast(D)->getCallResultType();
-  //}
-  //
-  //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
-  //
-  //if (!RD || !RD->hasAttr()) {
-  //S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
-  //  ReturnType.getAsString();
-  //return;
-  //}
+  QualType ReturnType;
+
+  if (const ParmVarDecl *Param = dyn_cast(D)) {
+ReturnType = Param->getType();
+
+  } else if (const CXXConstructorDecl *Constructor =
+ dyn_cast(D)) {
+ReturnType = Constructor->getThisType()->getPointeeType();
+
+  } else {
+
+ReturnType = cast(D)->getCallResultType();
+  }
+
+  const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
+  
+  if (!RD || !RD->hasAttr()) {
+ S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
+   ReturnType.getAsString();
+ return;
+  }
 
   D->addAttr(::new (S.Context) ReturnTypestateAttr(S.Context, AL, ReturnState));
 }
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2109,14 +2109,6 @@
 Warnings.emplace_back(std::move(Warning), OptionalNotes());
   }
 
-  void warnReturnTypestateForUnconsumableType(SourceLocation Loc,
-  StringRef TypeName) override {
-PartialDiagnosticAt Warning(Loc, S.PDiag(
-  diag::warn_return_typestate_for_unconsumable_type) << TypeName);
-
-Warnings.emplace_back(std::move(Warning), OptionalNotes());
-  }
-
   void warnReturnTypestateMismatch(SourceLocation Loc, StringRef ExpectedState,
StringRef ObservedState) override {
 
Index: 

[PATCH] D107723: [Clang] Moved warning of warnReturnTypestateForUnconsumableType back to SemaDeclAttr

2021-08-08 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 365060.

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

https://reviews.llvm.org/D107723

Files:
  clang/include/clang/Analysis/Analyses/Consumed.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/Consumed.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaCXX/warn-consumed-parsing.cpp

Index: clang/test/SemaCXX/warn-consumed-parsing.cpp
===
--- clang/test/SemaCXX/warn-consumed-parsing.cpp
+++ clang/test/SemaCXX/warn-consumed-parsing.cpp
@@ -6,16 +6,6 @@
 #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
 #define TEST_TYPESTATE(state)   __attribute__ ((test_typestate(state)))
 
-// FIXME: This test is here because the warning is issued by the Consumed
-//analysis, not SemaDeclAttr.  The analysis won't run after an error
-//has been issued.  Once the attribute propagation for template
-//instantiation has been fixed, this can be moved somewhere else and the
-//definition can be removed.
-int returnTypestateForUnconsumable() RETURN_TYPESTATE(consumed); // expected-warning {{return state set for an unconsumable type 'int'}}
-int returnTypestateForUnconsumable() {
-  return 0;
-}
-
 class AttrTester0 {
   void consumes()   __attribute__ ((set_typestate())); // expected-error {{'set_typestate' attribute takes one argument}}
   bool testUnconsumed() __attribute__ ((test_typestate())); // expected-error {{'test_typestate' attribute takes one argument}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -1190,17 +1190,14 @@
 return;
   }
 
-  // FIXME: This check is currently being done in the analysis.  It can be
-  //enabled here only after the parser propagates attributes at
-  //template specialization definition, not declaration.
-  //QualType ReturnType = cast(D)->getType();
-  //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
-  //
-  //if (!RD || !RD->hasAttr()) {
-  //S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
-  //  ReturnType.getAsString();
-  //return;
-  //}
+  QualType ReturnType = cast(D)->getType();
+  const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
+  
+  if (!RD || !RD->hasAttr()) {
+ S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
+   ReturnType.getAsString();
+ return;
+  }
 
   D->addAttr(::new (S.Context) ParamTypestateAttr(S.Context, AL, ParamState));
 }
@@ -1222,30 +1219,27 @@
 return;
   }
 
-  // FIXME: This check is currently being done in the analysis.  It can be
-  //enabled here only after the parser propagates attributes at
-  //template specialization definition, not declaration.
-  //QualType ReturnType;
-  //
-  //if (const ParmVarDecl *Param = dyn_cast(D)) {
-  //  ReturnType = Param->getType();
-  //
-  //} else if (const CXXConstructorDecl *Constructor =
-  // dyn_cast(D)) {
-  //  ReturnType = Constructor->getThisType()->getPointeeType();
-  //
-  //} else {
-  //
-  //  ReturnType = cast(D)->getCallResultType();
-  //}
-  //
-  //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
-  //
-  //if (!RD || !RD->hasAttr()) {
-  //S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
-  //  ReturnType.getAsString();
-  //return;
-  //}
+  QualType ReturnType;
+
+  if (const ParmVarDecl *Param = dyn_cast(D)) {
+ReturnType = Param->getType();
+
+  } else if (const CXXConstructorDecl *Constructor =
+ dyn_cast(D)) {
+ReturnType = Constructor->getThisType()->getPointeeType();
+
+  } else {
+
+ReturnType = cast(D)->getCallResultType();
+  }
+
+  const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
+  
+  if (!RD || !RD->hasAttr()) {
+ S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
+   ReturnType.getAsString();
+ return;
+  }
 
   D->addAttr(::new (S.Context) ReturnTypestateAttr(S.Context, AL, ReturnState));
 }
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2109,14 +2109,6 @@
 Warnings.emplace_back(std::move(Warning), OptionalNotes());
   }
 
-  void warnReturnTypestateForUnconsumableType(SourceLocation Loc,
-  StringRef TypeName) override {
-PartialDiagnosticAt Warning(Loc, S.PDiag(
-  diag::warn_return_typestate_for_unconsumable_type) << TypeName);
-
-Warnings.emplace_back(std::move(Warning), OptionalNotes());
-  }
-
   void warnReturnTypestateMismatch(SourceLocation Loc, StringRef ExpectedState,

[PATCH] D107723: Moved warning of warnReturnTypestateForUnconsumableType back to SemaDeclAttr

2021-08-08 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit created this revision.
Herald added a reviewer: aaron.ballman.
gAlfonso-bit requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107723

Files:
  clang/include/clang/Analysis/Analyses/Consumed.h
  clang/lib/Analysis/Consumed.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaCXX/warn-consumed-parsing.cpp

Index: clang/test/SemaCXX/warn-consumed-parsing.cpp
===
--- clang/test/SemaCXX/warn-consumed-parsing.cpp
+++ clang/test/SemaCXX/warn-consumed-parsing.cpp
@@ -6,16 +6,6 @@
 #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
 #define TEST_TYPESTATE(state)   __attribute__ ((test_typestate(state)))
 
-// FIXME: This test is here because the warning is issued by the Consumed
-//analysis, not SemaDeclAttr.  The analysis won't run after an error
-//has been issued.  Once the attribute propagation for template
-//instantiation has been fixed, this can be moved somewhere else and the
-//definition can be removed.
-int returnTypestateForUnconsumable() RETURN_TYPESTATE(consumed); // expected-warning {{return state set for an unconsumable type 'int'}}
-int returnTypestateForUnconsumable() {
-  return 0;
-}
-
 class AttrTester0 {
   void consumes()   __attribute__ ((set_typestate())); // expected-error {{'set_typestate' attribute takes one argument}}
   bool testUnconsumed() __attribute__ ((test_typestate())); // expected-error {{'test_typestate' attribute takes one argument}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -1190,17 +1190,14 @@
 return;
   }
 
-  // FIXME: This check is currently being done in the analysis.  It can be
-  //enabled here only after the parser propagates attributes at
-  //template specialization definition, not declaration.
-  //QualType ReturnType = cast(D)->getType();
-  //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
-  //
-  //if (!RD || !RD->hasAttr()) {
-  //S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
-  //  ReturnType.getAsString();
-  //return;
-  //}
+  QualType ReturnType = cast(D)->getType();
+  const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
+  
+  if (!RD || !RD->hasAttr()) {
+ S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
+   ReturnType.getAsString();
+ return;
+  }
 
   D->addAttr(::new (S.Context) ParamTypestateAttr(S.Context, AL, ParamState));
 }
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2109,14 +2109,6 @@
 Warnings.emplace_back(std::move(Warning), OptionalNotes());
   }
 
-  void warnReturnTypestateForUnconsumableType(SourceLocation Loc,
-  StringRef TypeName) override {
-PartialDiagnosticAt Warning(Loc, S.PDiag(
-  diag::warn_return_typestate_for_unconsumable_type) << TypeName);
-
-Warnings.emplace_back(std::move(Warning), OptionalNotes());
-  }
-
   void warnReturnTypestateMismatch(SourceLocation Loc, StringRef ExpectedState,
StringRef ObservedState) override {
 
Index: clang/lib/Analysis/Consumed.cpp
===
--- clang/lib/Analysis/Consumed.cpp
+++ clang/lib/Analysis/Consumed.cpp
@@ -1206,12 +1206,6 @@
   if (const ReturnTypestateAttr *RTSAttr = D->getAttr()) {
 const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
 if (!RD || !RD->hasAttr()) {
-  // FIXME: This should be removed when template instantiation propagates
-  //attributes at template specialization definition, not
-  //declaration. When it is removed the test needs to be enabled
-  //in SemaDeclAttr.cpp.
-  WarningsHandler.warnReturnTypestateForUnconsumableType(
-  RTSAttr->getLocation(), ReturnType.getAsString());
   ExpectedReturnState = CS_None;
 } else
   ExpectedReturnState = mapReturnTypestateAttrState(RTSAttr);
Index: clang/include/clang/Analysis/Analyses/Consumed.h
===
--- clang/include/clang/Analysis/Analyses/Consumed.h
+++ clang/include/clang/Analysis/Analyses/Consumed.h
@@ -89,16 +89,6 @@
 StringRef ExpectedState,
 StringRef ObservedState) {}
 
-// FIXME: This can be removed when the attr propagation fix for templated
-//classes lands.
-/// Warn about return typestates set for 

[PATCH] D107720: [analyzer] Cleanup a FIXME in SValBuilder.cpp

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

This change follows up on a FIXME submitted with D105974 
. This change simply let's the reference case 
fall through to return a concrete 'true'
instead of a nonloc pointer of appropriate length set to NULL.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107720

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp


Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: We could encounter a reference here,
-  //try returning a concrete 'true' since it might
-  //be easier on the solver.
   // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
   //and `getIntWithPtrWidth()` functions to prevent future
   //confusion
-  const llvm::APSInt  = Ty->isReferenceType()
- ? BasicVals.getZeroWithPtrWidth()
- : BasicVals.getZeroWithTypeSize(Ty);
-  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+  if (!Ty->isReferenceType())
+return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
+  CastTy);
 }
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);


Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: We could encounter a reference here,
-  //try returning a concrete 'true' since it might
-  //be easier on the solver.
   // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
   //and `getIntWithPtrWidth()` functions to prevent future
   //confusion
-  const llvm::APSInt  = Ty->isReferenceType()
- ? BasicVals.getZeroWithPtrWidth()
- : BasicVals.getZeroWithTypeSize(Ty);
-  return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+  if (!Ty->isReferenceType())
+return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
+  CastTy);
 }
 // Non-symbolic memory regions are always true.
 return makeTruthVal(true, CastTy);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D91311: Add new 'preferred_name' attribute.

2021-08-08 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Oh, I should say I wasn't able to get this behavior to be exposed in a 
diagnostic in my limited testing - and attempting to add diagnostic cases 
caused me to lose the reproduction in the ast dumping, perhaps because I added 
some AST that tickled/fixed the disparity somehow, though I'm pretty sure I 
avoided actually instantiating the definition of the template...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91311

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


[PATCH] D91311: Add new 'preferred_name' attribute.

2021-08-08 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

While looking into some debug info issues* I've come across what I think are 
some inconsistencies in the handling of this attribute - @rsmith mind taking a 
look?

Firstly, it looks like something isn't handled when it comes to templates where 
only the declaration of a template with a preferred name is instantiated, but 
not the definition:

  template
  struct t1;
  using t1i = t1;
  template
  struct
  #ifdef PREF
  __attribute__((__preferred_name__(t1i)))
  #endif
  t1 {
  };
  
  template
  struct t2 {
  };
  int main() {
t2 v1;
  #ifdef DEF
t1i v2;
  #else
t1 v2; // just leave this here so AST dump is similar with/without 
the t1i definition
  #endif
  }

Compile with `-DPREF -Xclang -ast-dump` and compare the output with/without 
`-DDEF`. With the definition, the ast dump uses the preferred name when 
printing the use of `t1i` as `t2`'s template argument, without the definition 
it dumps as the raw `t1` instead:

  CXXConstructorDecl 0x10d9cd48  col:8 implicit constexpr t2 'void 
(const t2 &)' inline default trivial noexcept-unevaluated 0x10d9cd48

  CXXConstructorDecl 0x120cb0f8  col:8 implicit constexpr t2 'void 
(const t2> &)' inline default trivial noexcept-unevaluated 0x120cb0f8

(unrelated to this, but related to how I came across this: I think it might be 
desirable to have a PrintingPolicy to turn off using the preferred name, 
specifically so we can use this when rendering a template name in DWARF - so 
the name is consistent with the `DW_TAG_template_type_parameter` - better 
chance of cross-compiler compatibility, etc - I've considered going the other 
way, and using the preferred name in the `DW_TAG_template_type_parameter` but 
worry that'll cause even more divergence between compilers & make things more 
difficult for the consumer (but they could support it, if they looked through 
typedefs/alias templates when doing structural equivalence between template 
descriptions in DWARF (which they kind of have to do anyway, because there's a 
bunch of other ways that names aren't exactly the same all the time - which, 
maybe that's a reason not to worry about the use of preferred names in the 
textual description today? Since the names aren't directly matchable anyway... 
- I haven't tested that too much to see how much divergence there is ignored by 
existing consumers))

- The preferred name shows up in template type parameters - but that then 
mismatches with the `DW_TAG_template_type_parameter` which uses the underlying 
type. I have been experimenting with a patch to use the preferred type even 
there, but that might cause more significant/problematic mismatch between DWARF 
produced by different compilers, unless they're able to look through 
typedefs/alias templates when structurally comparing two type descriptions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91311

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


[PATCH] D105981: [AMDGPU][OpenMP] Support linking of math libraries

2021-08-08 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

It's been pointed out to me that -lm is a linker flag so it's weird to require 
it at compile time. I haven't thought of a good fix for that yet.

We don't need to splice in ocml for each compilation unit, so can move the 
test+splice into the link phase, except that amdgcn doesn't have a very well 
defined link phase as it keeps everything in IR. We could look for -c or 
equivalent, i.e. only check for ocml when building an executable, and not when 
compiling a translation unit to IR.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105981

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


[PATCH] D107719: [Clang] Resolve FIXMEs in Types.h

2021-08-08 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 365046.

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

https://reviews.llvm.org/D107719

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2785,7 +2785,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -3450,10 +3450,6 @@
 protected:
   friend class ASTContext;
 
-  /// The element type of the matrix.
-  // FIXME: Appears to be unused? There is also MatrixType::ElementType...
-  QualType ElementType;
-
   /// Number of rows and columns.
   unsigned NumRows;
   unsigned NumColumns;


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2785,7 +2785,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -3450,10 +3450,6 @@
 protected:
   friend class ASTContext;
 
-  /// The element type of the matrix.
-  // FIXME: Appears to be unused? There is also MatrixType::ElementType...
-  QualType ElementType;
-
   /// Number of rows and columns.
   unsigned NumRows;
   unsigned NumColumns;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107719: [Clang] Resolve FIXMEs in Types.h

2021-08-08 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 365045.

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

https://reviews.llvm.org/D107719

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -31,6 +31,7 @@
 #include "clang/Basic/AddressSpaces.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Linkage.h"
@@ -2011,9 +2012,10 @@
 
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!getLangOpts().CPlusPlus && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2036,7 +2038,6 @@
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
 return IT->isSigned();
 
-
   return false;
 }
 
@@ -2058,9 +2059,10 @@
 
   if (const auto *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!getLangOpts().CPlusPlus && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2785,7 +2787,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -24,6 +24,7 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/Basic/PartialDiagnostic.h"
@@ -3450,10 +3451,6 @@
 protected:
   friend class ASTContext;
 
-  /// The element type of the matrix.
-  // FIXME: Appears to be unused? There is also MatrixType::ElementType...
-  QualType ElementType;
-
   /// Number of rows and columns.
   unsigned NumRows;
   unsigned NumColumns;
@@ -6989,9 +6986,8 @@
BT->getKind() <= BuiltinType::Int128;
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-return IsEnumDeclComplete(ET->getDecl()) &&
-  !IsEnumDeclScoped(ET->getDecl());
+// In C++, enum types are never integer types.
+return !getLangOpts().CPlusPlus && IsEnumDeclComplete(ET->getDecl());
   }
   return isExtIntType();
 }


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -31,6 +31,7 @@
 #include "clang/Basic/AddressSpaces.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Linkage.h"
@@ -2011,9 +2012,10 @@
 
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!getLangOpts().CPlusPlus && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2036,7 +2038,6 @@
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
 return IT->isSigned();
 
-
   return false;
 }
 
@@ -2058,9 +2059,10 @@
 
   if (const auto *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!getLangOpts().CPlusPlus && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = 

[PATCH] D107719: [Clang] Resolve FIXMEs in Types.h

2021-08-08 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 365044.

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

https://reviews.llvm.org/D107719

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -31,6 +31,7 @@
 #include "clang/Basic/AddressSpaces.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Linkage.h"
@@ -2011,9 +2012,10 @@
 
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2058,9 +2060,10 @@
 
   if (const auto *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2785,7 +2788,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -24,6 +24,7 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/Basic/PartialDiagnostic.h"
@@ -3450,10 +3451,6 @@
 protected:
   friend class ASTContext;
 
-  /// The element type of the matrix.
-  // FIXME: Appears to be unused? There is also MatrixType::ElementType...
-  QualType ElementType;
-
   /// Number of rows and columns.
   unsigned NumRows;
   unsigned NumColumns;
@@ -6989,9 +6986,8 @@
BT->getKind() <= BuiltinType::Int128;
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-return IsEnumDeclComplete(ET->getDecl()) &&
-  !IsEnumDeclScoped(ET->getDecl());
+// In C++, enum types are never integer types.
+return !isCPlusPlus() && IsEnumDeclComplete(ET->getDecl());
   }
   return isExtIntType();
 }


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -31,6 +31,7 @@
 #include "clang/Basic/AddressSpaces.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Linkage.h"
@@ -2011,9 +2012,10 @@
 
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2058,9 +2060,10 @@
 
   if (const auto *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2785,7 +2788,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/include/clang/AST/Type.h

[PATCH] D107719: [Clang] Resolve FIXMEs in Types.h

2021-08-08 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 365043.

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

https://reviews.llvm.org/D107719

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2011,9 +2011,10 @@
 
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2058,9 +2059,10 @@
 
   if (const auto *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2785,7 +2787,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -24,6 +24,7 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/Basic/PartialDiagnostic.h"
@@ -3450,10 +3451,6 @@
 protected:
   friend class ASTContext;
 
-  /// The element type of the matrix.
-  // FIXME: Appears to be unused? There is also MatrixType::ElementType...
-  QualType ElementType;
-
   /// Number of rows and columns.
   unsigned NumRows;
   unsigned NumColumns;
@@ -6989,9 +6986,8 @@
BT->getKind() <= BuiltinType::Int128;
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-return IsEnumDeclComplete(ET->getDecl()) &&
-  !IsEnumDeclScoped(ET->getDecl());
+// In C++, enum types are never integer types.
+return !isCPlusPlus() && IsEnumDeclComplete(ET->getDecl());
   }
   return isExtIntType();
 }


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2011,9 +2011,10 @@
 
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2058,9 +2059,10 @@
 
   if (const auto *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2785,7 +2787,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -24,6 +24,7 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/Basic/PartialDiagnostic.h"
@@ -3450,10 +3451,6 @@
 protected:
   friend class ASTContext;
 
-  /// The element type of the matrix.
-  // FIXME: Appears to be unused? There is also 

[PATCH] D107719: [Clang] Resolve FIXMEs in Types.h

2021-08-08 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 365042.

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

https://reviews.llvm.org/D107719

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2011,9 +2011,10 @@
 
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2058,9 +2059,10 @@
 
   if (const auto *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2785,7 +2787,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -24,6 +24,7 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/Basic/PartialDiagnostic.h"
@@ -3450,10 +3451,6 @@
 protected:
   friend class ASTContext;
 
-  /// The element type of the matrix.
-  // FIXME: Appears to be unused? There is also MatrixType::ElementType...
-  QualType ElementType;
-
   /// Number of rows and columns.
   unsigned NumRows;
   unsigned NumColumns;
@@ -6989,9 +6986,9 @@
BT->getKind() <= BuiltinType::Int128;
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-return IsEnumDeclComplete(ET->getDecl()) &&
-  !IsEnumDeclScoped(ET->getDecl());
+// In C++, enum types are never integer types.
+return !isCPlusPlus() && IsEnumDeclComplete(ET->getDecl()) &&
+   !IsEnumDeclScoped(ET->getDecl());
   }
   return isExtIntType();
 }


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2011,9 +2011,10 @@
 
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2058,9 +2059,10 @@
 
   if (const auto *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2785,7 +2787,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -24,6 +24,7 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/Linkage.h"
 #include "clang/Basic/PartialDiagnostic.h"
@@ -3450,10 +3451,6 @@
 protected:
   friend class ASTContext;
 
-  /// The element type of the matrix.
-  // FIXME: Appears to 

[PATCH] D107719: [Clang] Resolve FIXMEs in Types.h

2021-08-08 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit created this revision.
gAlfonso-bit added projects: LLVM, clang.
gAlfonso-bit requested review of this revision.
Herald added a subscriber: cfe-commits.

This includes removing ObjectiveC Object Pointers from the list of specifiers, 
as well as checking for C++ instead of using Scoped Enums as a workaround.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107719

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2011,9 +2011,10 @@
 
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2058,9 +2059,10 @@
 
   if (const auto *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2785,7 +2787,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -3450,10 +3450,6 @@
 protected:
   friend class ASTContext;
 
-  /// The element type of the matrix.
-  // FIXME: Appears to be unused? There is also MatrixType::ElementType...
-  QualType ElementType;
-
   /// Number of rows and columns.
   unsigned NumRows;
   unsigned NumColumns;
@@ -6989,9 +6985,9 @@
BT->getKind() <= BuiltinType::Int128;
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-return IsEnumDeclComplete(ET->getDecl()) &&
-  !IsEnumDeclScoped(ET->getDecl());
+// In C++, enum types are never integer types.
+return !isCPlusPlus() && IsEnumDeclComplete(ET->getDecl()) &&
+   !IsEnumDeclScoped(ET->getDecl());
   }
   return isExtIntType();
 }


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2011,9 +2011,10 @@
 
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2058,9 +2059,10 @@
 
   if (const auto *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
-// FIXME: In C++, enum types are never integer types.
-if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+// In C++, enum types are never integer types.
+if (!isCPlusPlus() && ET->getDecl()->isComplete())
   return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+return false;
   }
 
   if (const ExtIntType *IT = dyn_cast(CanonicalType))
@@ -2785,7 +2787,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -3450,10 +3450,6 @@
 protected:
   friend class ASTContext;
 
-  /// The element type of the matrix.
-  // FIXME: Appears to be unused? There is also MatrixType::ElementType...
-  QualType ElementType;
-
   /// Number of rows and columns.
   unsigned NumRows;
   unsigned NumColumns;
@@ -6989,9 +6985,9 @@
BT->getKind() <= BuiltinType::Int128;
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as 

[clang-tools-extra] c5c3cdb - [clangd] Populate-switch triggers when the whole condition is selected.

2021-08-08 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-08-08T21:06:08+02:00
New Revision: c5c3cdb9c92895a63993cee70d2dd776ff9519c3

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

LOG: [clangd] Populate-switch triggers when the whole condition is selected.

This allows vscode to find it as a diagnostic quickfix for -Wswitch.

While here, group the code into chunks and add a couple more comments.

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
index bae80cdecf590..40af43fef4aaf 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/PopulateSwitch.cpp
@@ -88,47 +88,39 @@ bool PopulateSwitch::prepare(const Selection ) {
   if (!CA)
 return false;
 
-  const Stmt *CAStmt = CA->ASTNode.get();
-  if (!CAStmt)
-return false;
-
-  // Go up a level if we see a compound statement.
-  // switch (value) {}
-  //^^
-  if (isa(CAStmt)) {
-CA = CA->Parent;
-if (!CA)
-  return false;
-
-CAStmt = CA->ASTNode.get();
-if (!CAStmt)
+  // Support targeting
+  //  - the switch statement itself (keyword, parens)
+  //  - the whole expression (possibly wrapped in implicit casts)
+  //  - the outer body (typically CompoundStmt)
+  // Selections *within* the expression or body don't trigger.
+  // direct child (the 
+  Switch = CA->ASTNode.get();
+  if (!Switch) {
+if (const SelectionTree::Node *Parent = CA->outerImplicit().Parent)
+  Switch = Parent->ASTNode.get();
+if (!Switch)
   return false;
   }
-
-  DeclCtx = >getDeclContext();
-  Switch = dyn_cast(CAStmt);
-  if (!Switch)
-return false;
-
-  Body = dyn_cast(Switch->getBody());
+  // Body need not be a CompoundStmt! But that's all we support editing.
+  Body = llvm::dyn_cast_or_null(Switch->getBody());
   if (!Body)
 return false;
+  DeclCtx = >getDeclContext();
 
+  // Examine the condition of the switch statement to see if it's an enum.
   const Expr *Cond = Switch->getCond();
   if (!Cond)
 return false;
-
   // Ignore implicit casts, since enums implicitly cast to integer types.
   Cond = Cond->IgnoreParenImpCasts();
-
   EnumT = Cond->getType()->getAsAdjusted();
   if (!EnumT)
 return false;
-
   EnumD = EnumT->getDecl();
   if (!EnumD || EnumD->isDependentType())
 return false;
 
+  // Finally, check which cases exist and which are covered.
   // We trigger if there are any values in the enum that aren't covered by the
   // switch.
 

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
index 41518108a4f8d..13277c99cc314 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/PopulateSwitchTests.cpp
@@ -95,6 +95,12 @@ TEST_F(PopulateSwitchTest, Test) {
   R""(enum Enum {A}; switch (^A) {})"",
   R""(enum Enum {A}; switch (A) {case A:break;})"",
   },
+  {
+  // Selection of whole switch condition
+  Function,
+  R""(enum Enum {A}; switch ([[A]]) {})"",
+  R""(enum Enum {A}; switch (A) {case A:break;})"",
+  },
   {
   // Selection in switch body
   Function,



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


[PATCH] D107304: [clangd][query-driver] Extract GCC version from the driver output

2021-08-08 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX abandoned this revision.
ArcsinX added a comment.

As I can see, no chances for this to get approved. So. closing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107304

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


[PATCH] D107684: [NFC][AVR][clang] Add test for D107672

2021-08-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/avr-toolchain.c:17
+// RUN: %clang %s -### -no-canonical-prefixes -target avr --sysroot 
%S/Inputs/basic_avr_tree/usr/lib 2>&1 | FileCheck -check-prefix CC1D %s
+// CC1D: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-internal-isystem" 
{{".*avr/include"}}

Please use the pattern in linux-cross.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107684

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


[PATCH] D107718: [cuda] Mark builtin texture/surface reference variable as 'externally_initialized'.

2021-08-08 Thread Michael Liao via Phabricator via cfe-commits
hliao created this revision.
hliao added reviewers: tra, yaxunl.
Herald added a reviewer: a.sidorin.
hliao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- They need to be preserved even if there's no reference within the device code 
as the host code may need to initialize them based on the application logic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107718

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCUDA/surface.cu
  clang/test/CodeGenCUDA/texture.cu


Index: clang/test/CodeGenCUDA/texture.cu
===
--- clang/test/CodeGenCUDA/texture.cu
+++ clang/test/CodeGenCUDA/texture.cu
@@ -19,8 +19,8 @@
 };
 
 // On the device side, texture references are represented as `i64` handles.
-// DEVICE: @tex ={{.*}} addrspace(1) global i64 undef, align 4
-// DEVICE: @norm ={{.*}} addrspace(1) global i64 undef, align 4
+// DEVICE: @tex ={{.*}} addrspace(1) externally_initialized global i64 undef, 
align 4
+// DEVICE: @norm ={{.*}} addrspace(1) externally_initialized global i64 undef, 
align 4
 // On the host side, they remain in the original type.
 // HOST: @tex = internal global %struct.texture
 // HOST: @norm = internal global %struct.texture
Index: clang/test/CodeGenCUDA/surface.cu
===
--- clang/test/CodeGenCUDA/surface.cu
+++ clang/test/CodeGenCUDA/surface.cu
@@ -19,7 +19,7 @@
 };
 
 // On the device side, surface references are represented as `i64` handles.
-// DEVICE: @surf ={{.*}} addrspace(1) global i64 undef, align 4
+// DEVICE: @surf ={{.*}} addrspace(1) externally_initialized global i64 undef, 
align 4
 // On the host side, they remain in the original type.
 // HOST: @surf = internal global %struct.surface
 // HOST: @0 = private unnamed_addr constant [5 x i8] c"surf\00"
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4438,7 +4438,9 @@
   if (GV && LangOpts.CUDA) {
 if (LangOpts.CUDAIsDevice) {
   if (Linkage != llvm::GlobalValue::InternalLinkage &&
-  (D->hasAttr() || D->hasAttr()))
+  (D->hasAttr() || D->hasAttr() ||
+   D->getType()->isCUDADeviceBuiltinSurfaceType() ||
+   D->getType()->isCUDADeviceBuiltinTextureType()))
 GV->setExternallyInitialized(true);
 } else {
   getCUDARuntime().internalizeDeviceSideVar(D, Linkage);


Index: clang/test/CodeGenCUDA/texture.cu
===
--- clang/test/CodeGenCUDA/texture.cu
+++ clang/test/CodeGenCUDA/texture.cu
@@ -19,8 +19,8 @@
 };
 
 // On the device side, texture references are represented as `i64` handles.
-// DEVICE: @tex ={{.*}} addrspace(1) global i64 undef, align 4
-// DEVICE: @norm ={{.*}} addrspace(1) global i64 undef, align 4
+// DEVICE: @tex ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4
+// DEVICE: @norm ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4
 // On the host side, they remain in the original type.
 // HOST: @tex = internal global %struct.texture
 // HOST: @norm = internal global %struct.texture
Index: clang/test/CodeGenCUDA/surface.cu
===
--- clang/test/CodeGenCUDA/surface.cu
+++ clang/test/CodeGenCUDA/surface.cu
@@ -19,7 +19,7 @@
 };
 
 // On the device side, surface references are represented as `i64` handles.
-// DEVICE: @surf ={{.*}} addrspace(1) global i64 undef, align 4
+// DEVICE: @surf ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4
 // On the host side, they remain in the original type.
 // HOST: @surf = internal global %struct.surface
 // HOST: @0 = private unnamed_addr constant [5 x i8] c"surf\00"
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4438,7 +4438,9 @@
   if (GV && LangOpts.CUDA) {
 if (LangOpts.CUDAIsDevice) {
   if (Linkage != llvm::GlobalValue::InternalLinkage &&
-  (D->hasAttr() || D->hasAttr()))
+  (D->hasAttr() || D->hasAttr() ||
+   D->getType()->isCUDADeviceBuiltinSurfaceType() ||
+   D->getType()->isCUDADeviceBuiltinTextureType()))
 GV->setExternallyInitialized(true);
 } else {
   getCUDARuntime().internalizeDeviceSideVar(D, Linkage);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107682: [AVR][clang] Improve search for avr-libc installation path

2021-08-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/avr-toolchain.c:1
 // A basic clang -cc1 command-line.
 

MaskRay wrote:
> You can UNSUPPORT windows if you don't want to wrestle with \ and / path 
> separators.
UNSUPPORTED: system-windows


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

https://reviews.llvm.org/D107682

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


[PATCH] D107682: [AVR][clang] Improve search for avr-libc installation path

2021-08-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/AVR.cpp:460
+  if (llvm::sys::fs::is_directory(Path))
+return Optional(Path);
+  Path = GCCParent + "/../avr";

`return Path;`



Comment at: clang/test/Driver/avr-toolchain.c:1
 // A basic clang -cc1 command-line.
 

You can UNSUPPORT windows if you don't want to wrestle with \ and / path 
separators.


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

https://reviews.llvm.org/D107682

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


[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-08-08 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:440
+  State, {std::make_pair(CC->getCXXThisVal(), ArgVal)},
+  C.getLocationContext(), PSK_DirectEscapeOnCall, );
 

It seems to me that this pointer escape doesn't work.
For the following code:
```lang=cpp
void foo() {
auto ptr = std::unique_ptr(new int(13));
// Leak warning emitted here
}
```
the exploded graph shows the SVal for `new int(13)` as allocated instead of 
escaped (which eventually triggers the warning).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

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


[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-08-08 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 365031.
RedDocMD added a comment.

Further pointer escape


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -753,10 +753,13 @@
 *Call, *this);
 
   ExplodedNodeSet DstInvalidated;
-  StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
-  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
-   I != E; ++I)
-defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  // StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
+  // for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E =
+  // DstPreCall.end();
+  //  I != E; ++I)
+  //   defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  getCheckerManager().runCheckersForEvalCall(DstInvalidated, DstPreCall, *Call,
+ *this, CallOpts);
 
   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
  *Call, *this);
Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -664,14 +664,11 @@
 for (const auto  : EvalCallCheckers) {
   // TODO: Support the situation when the call doesn't correspond
   // to any Expr.
-  ProgramPoint L = ProgramPoint::getProgramPoint(
-  Call.getOriginExpr(), ProgramPoint::PostStmtKind,
-  Pred->getLocationContext(), EvalCallChecker.Checker);
   bool evaluated = false;
   { // CheckerContext generates transitions(populates checkDest) on
 // destruction, so introduce the scope to make sure it gets properly
 // populated.
-CheckerContext C(B, Eng, Pred, L);
+CheckerContext C(B, Eng, Pred, Call.getProgramPoint());
 evaluated = EvalCallChecker(Call, C);
   }
   assert(!(evaluated && anyEvaluated)
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -46,6 +46,8 @@
   bool isBoolConversionMethod(const CallEvent ) const;
 
 public:
+  SmartPtrModeling(CheckerManager ) : ChkMgr(ChkMgr) {}
+
   // Whether the checker should model for null dereferences of smart pointers.
   DefaultBool ModelSmartPtrDereference;
   bool evalCall(const CallEvent , CheckerContext ) const;
@@ -92,6 +94,7 @@
   const CallDescription StdMakeUniqueCall{{"std", "make_unique"}};
   const CallDescription StdMakeUniqueForOverwriteCall{
   {"std", "make_unique_for_overwrite"}};
+  CheckerManager 
 };
 } // end of anonymous namespace
 
@@ -139,7 +142,7 @@
 
   if (RD->getDeclName().isIdentifier()) {
 StringRef Name = RD->getName();
-return Name == "shared_ptr" || Name == "unique_ptr" || Name == "weak_ptr";
+return llvm::is_contained(STD_PTR_NAMES, Name);
   }
   return false;
 }
@@ -157,20 +160,6 @@
 } // namespace ento
 } // namespace clang
 
-// If a region is removed all of the subregions need to be removed too.
-static TrackedRegionMapTy
-removeTrackedSubregions(TrackedRegionMapTy RegionMap,
-TrackedRegionMapTy::Factory ,
-const MemRegion *Region) {
-  if (!Region)
-return RegionMap;
-  for (const auto  : RegionMap) {
-if (E.first->isSubRegionOf(Region))
-  RegionMap = RegionMapFactory.remove(RegionMap, E.first);
-  }
-  return RegionMap;
-}
-
 static ProgramStateRef updateSwappedRegion(ProgramStateRef State,
const MemRegion *Region,
const SVal *RegionInnerPointerVal) {
@@ -275,6 +264,29 @@
  smartptr::isStdSmartPtr(Call.getArgExpr(1));
 }
 
+ProgramStateRef
+invalidateInnerPointer(const MemRegion *ThisRegion, ProgramStateRef State,
+   const CallEvent , CheckerContext ) {
+  const auto *InnerPtrVal = State->get(ThisRegion);
+  if (InnerPtrVal) {
+State = State->invalidateRegions(*InnerPtrVal, nullptr, C.blockCount(),
+ C.getLocationContext(), true);
+
+const QualType  = getInnerPointerType(Call, C);
+const auto *RD = Type->getAsCXXRecordDecl();
+if (!RD)
+  return State;
+const auto *DD = RD->getDestructor();
+
+const auto InnerDestrCall =
+

[PATCH] D106585: Fix clang debug info irgen of i128 enums

2021-08-08 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D106585#2905916 , @rnk wrote:

> In D106585#2905663 , @dblaikie 
> wrote:
>
>> In D106585#2902588 , @dblaikie 
>> wrote:
>>
>>> Preserving existing behavior sounds OK - maybe some comment about that it 
>>> might be good to remove so the next person who looks at it knows there's 
>>> something not-quite-fully-reasoned here (& the comment about GCC's 
>>> representation choice still seems off - GCC does use the signedness of the 
>>> enumerators, not only the enumeration).
>>
>> @rnk - any thoughts on the comments? (the existing comment about GCC's 
>> emission seems incorrect to me (or subtly correct, but probably easy to 
>> misunderstand) - GCC does use different DWARF encodings for negative 
>> enumerators, depending on the enumerator) And seems like a comment about how 
>> this is maybe confusing/in need of some more touch-up might be handy for the 
>> next reader? (specifically that the current DWARF backend ignores the 
>> "isUnsigned" flag entirely, and relies on the signedness of the enumerator's 
>> underlying type instead - so maybe we could remove the isUnsigned flag?)
>
> I wasn't aware that the backend ignored this info. If that's the case, then I 
> think we can carry the signedness over from the enumerator, update the enum2 
> IRgen test, and someone can update the DWARF backend later if they want to 
> match GCC more closely. I think C and GCC's behavior is driven by a desire to 
> make enumerators behave as close as possible to an integer literal macro 
> definition, which could explain the per-enumerator signedness, similar to how 
> certain ways of spelling a literal affect its type.

Yeah, perhaps that's the motivation, though it seems like somewhat of a lost 
cause, I think? Since there are lots of spellings of an enumerator value where 
this property wouldn't be preserved (a call to a constexpr function, for 
instance) - so it seems to me that the value would be better off using the 
domain of the enumeration rather than something about how an enumerator was 
spelled.

Ah well, hopefully this discussion here will be findable if/when someone wants 
to look into it more in the future. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106585

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


[PATCH] D105263: [X86] AVX512FP16 instructions enabling 1/6

2021-08-08 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:3471
+  ContainsFloatAtOffset(IRType, IROffset + 4, getDataLayout()))
+return llvm::FixedVectorType::get(llvm::Type::getHalfTy(getVMContext()), 
4);
+

LuoYuanke wrote:
> For 2 float, return <2xfloat> to be compatible to previous ABI?
It is already handled in line 3456.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105263

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


[PATCH] D105263: [X86] AVX512FP16 instructions enabling 1/6

2021-08-08 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:3471
+  ContainsFloatAtOffset(IRType, IROffset + 4, getDataLayout()))
+return llvm::FixedVectorType::get(llvm::Type::getHalfTy(getVMContext()), 
4);
+

For 2 float, return <2xfloat> to be compatible to previous ABI?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105263

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


[PATCH] D97753: [clang-tidy] Add a check for enforcing minimum length for variable names

2021-08-08 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- updated this revision to Diff 365016.
0x8000- added a comment.

Updated documentation for all options.


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

https://reviews.llvm.org/D97753

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/VariableLengthCheck.cpp
  clang-tools-extra/clang-tidy/readability/VariableLengthCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-variable-length.rst
  clang-tools-extra/test/clang-tidy/checkers/readability-variable-length.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-variable-length.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-variable-length.cpp
@@ -0,0 +1,72 @@
+// RUN: %check_clang_tidy %s readability-variable-length %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: readability-variable-length.IgnoredVariableNames, value: "^[xy]$"}]}' \
+// RUN: --
+
+struct myexcept
+{
+   int val;
+};
+
+struct simpleexcept
+{
+   int other;
+};
+
+void doIt();
+
+void tooShortVariableNames(int z)
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: parameter name 'z' is too short, expected at least 3 characters [readability-variable-length]
+{
+   int i = 5;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable name 'i' is too short, expected at least 3 characters [readability-variable-length]
+
+   int jj = z;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable name 'jj' is too short, expected at least 3 characters [readability-variable-length]
+
+   for (int m = 0; m < 5; ++ m)
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: loop variable name 'm' is too short, expected at least 2 characters [readability-variable-length]
+   {
+  doIt();
+   }
+
+   try
+   {
+  doIt();
+   }
+   catch (const myexcept& x)
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: exception variable name 'x' is too short, expected at least 2 characters [readability-variable-length]
+   {
+  doIt();
+   }
+}
+
+void longEnoughVariableNames(int n) // argument 'n' ignored by configuration
+{
+   int var = 5;
+
+   for (int i = 0; i < 42; ++ i) // 'i' is default allowed, for historical reasons
+   {
+  doIt();
+   }
+
+   for (int kk = 0; kk < 42; ++ kk)
+   {
+  doIt();
+   }
+
+   try
+   {
+  doIt();
+   }
+   catch (const simpleexcept& e) // ignored via default configuration
+   {
+  doIt();
+   }
+   catch (const myexcept& ex)
+   {
+  doIt();
+   }
+
+   int x = 5;  // ignored by configuration
+}
Index: clang-tools-extra/docs/clang-tidy/checks/readability-variable-length.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability-variable-length.rst
@@ -0,0 +1,122 @@
+.. title:: clang-tidy - readability-variable-length
+
+readability-variable-length
+===
+
+This check finds variables and function parameters whose length are too short.
+The desired name length is configurable.
+
+Special cases are supported for loop counters and for exception variable names.
+
+Options
+---
+
+The following options are described below:
+
+ - :option:`MinimumVariableNameLength`, :option:`IgnoredVariableNames`
+ - :option:`MinimumParameterNameLength`, :option:`IgnoredParameterNames`
+ - :option:`MinimumLoopCounterNameLength`, :option:`IgnoredLoopCounterNames`
+ - :option:`MinimumExceptionNameLength`, :option:`IgnoredExceptionVariableNames`
+
+.. option:: MinimumVariableNameLength
+
+All variables (other than loop counter, exception names and function
+parameters) are expected to have at least a length of
+`MinimumVariableNameLength` (default is `3`). Setting it to `0` or `1`
+disables the check entirely.
+
+
+.. code-block:: c++
+
+ int doubler(int x)   // warns that x is too short
+ {
+return 2 * x;
+ }
+
+This check does not have any fix suggestions in the general case since
+variable names have semantic value.
+
+.. option:: IgnoredVariableNames
+
+Specifies a regular expression for variable names that are
+to be ignored. The default value is empty, thus no names are ignored.
+
+.. option:: MinimumParameterNameLength
+
+All function parameter names are expected to have a length of at least
+`MinimumParameterNameLength` (default is `3`). Setting it to `0` or `1`
+disables the check entirely.
+
+
+.. code-block:: c++
+
+  int i = 42;// warns that 'i' is too short
+
+This check does not have any fix suggestions in the general case since
+variable names have semantic value.
+
+.. option:: IgnoredParameterNames
+
+Specifies a regular expression for parameters that are to be ignored.
+The default 

[PATCH] D54943: WIP [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2021-08-08 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- added a comment.

In D54943#2933179 , @JonasToth wrote:

> In D54943#2633408 , @tiagoma wrote:
>
>> Can we get this in? I work in Microsoft Office and we have been using this 
>> checker and it works great! There are a couple of issues with it and I would 
>> like to contribute fixes.
>
> YES. I WILL WORK ON THIS NOW.

Great news Jonas! Thank you!

> After s much time has passed I think i have finally time again to bring 
> this check over the line. I will invest at least every sunday from now on, 
> until its done :)
>
> This is my initial work-list I would like to fix before this check can be 
> merged:
>
> - rebase to current master (obviously)
> - fix `clang-apply-replacements` duplication that comes from fixes in 
> templates (multiple instantiations create `const`-fix at the same position. 
> but because the warning message contains different type names,  they are not 
> deduplicated)
> - go through the review again and check if there are missing comments to 
> address
> - improve the documentation and give some hints on possible issues

These all seem to handle the fix-it portion. Would it be possible to split that 
into a follow-up review?

I am using tidy from CI and as a 'live-linter' from [n]vim. If I get a warning, 
it's easy to go to the line and type the six characters. In fact I don't even 
know the keystroke sequence that would instruct the editor to apply a fix-it :)

Obviously fix-its are not helping in CI, either - what is important is 
reporting at least one location and then the review gets rejected and 
subsequently revised.

I'm not saying I won't ever use the fix-its, but for now detection and 
reporting cover 100% of my use cases.

Thank you again for getting the energy and the time to work on this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

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


[PATCH] D54943: WIP [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2021-08-08 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In D54943#2633408 , @tiagoma wrote:

> Can we get this in? I work in Microsoft Office and we have been using this 
> checker and it works great! There are a couple of issues with it and I would 
> like to contribute fixes.

Hey,

YES. I WILL WORK ON THIS NOW.

After s much time has passed I think i have finally time again to bring 
this check over the line. I will invest at least every sunday from now on, 
until its done :)

This is my initial work-list I would like to fix before this check can be 
merged:

- rebase to current master (obviously)
- fix `clang-apply-replacements` duplication that comes from fixes in templates 
(multiple instantiations create `const`-fix at the same position. but because 
the warning message contains different type names,  they are not deduplicated)
- go through the review again and check if there are missing comments to address
- improve the documentation and give some hints on possible issues

I think from this point on the check is ready to be improved, as there will be 
only false positive/false negatives left.

What I observed during the initial development time was, that llvm's orcjit 
tests failed (i believe with a crash) after a full-llvm-transformation.
This is most likely UB from casting/`std::launder`or so? Given the interest in 
general for this checker, we should provide some warnings that this can happen 
and maybe figure out what the issues is (I failed so far).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

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


[PATCH] D107049: [clang-repl] Re-implement clang-interpreter as a test case.

2021-08-08 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 365005.
v.g.vassilev added a comment.

Try to appease the windows pre-merge bot.


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

https://reviews.llvm.org/D107049

Files:
  clang/docs/ClangFormattedStatus.rst
  clang/examples/CMakeLists.txt
  clang/examples/clang-interpreter/CMakeLists.txt
  clang/examples/clang-interpreter/README.txt
  clang/examples/clang-interpreter/Test.cxx
  clang/examples/clang-interpreter/main.cpp
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/CMakeLists.txt
  clang/test/Misc/interpreter.c
  clang/test/lit.cfg.py
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -14,10 +14,14 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclGroup.h"
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/Support/TargetSelect.h"
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -53,6 +57,92 @@
   EXPECT_EQ(1U, DeclsSize(R2.TUPart));
 }
 
+// This function isn't referenced outside its translation unit, but it
+// can't use the "static" keyword because its address is used for
+// GetMainExecutable (since some platforms don't support taking the
+// address of main, and some platforms can't implement GetMainExecutable
+// without being given the address of a function in the main executable).
+std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
+  return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
+}
+
+static std::string MakeResourcesPath() {
+  // Dir is bin/ or lib/, depending on where BinaryPath is.
+  void *MainAddr = (void *)(intptr_t)GetExecutablePath;
+  std::string BinaryPath = GetExecutablePath(/*Argv0=*/nullptr, MainAddr);
+
+  // build/tools/clang/unittests/Interpreter/Executable -> build/
+  llvm::StringRef Dir = llvm::sys::path::parent_path(BinaryPath);
+
+  Dir = llvm::sys::path::parent_path(Dir);
+  Dir = llvm::sys::path::parent_path(Dir);
+  Dir = llvm::sys::path::parent_path(Dir);
+  Dir = llvm::sys::path::parent_path(Dir);
+  SmallString<128> P(Dir);
+  llvm::sys::path::append(P, Twine("lib") + CLANG_LIBDIR_SUFFIX, "clang",
+  CLANG_VERSION_STRING);
+
+  return std::string(P.str());
+}
+
+#ifdef _MSC_VER
+// Tell the windows linker to export the type_info symbol required by exceptions
+#pragma comment(linker, "/export:??_7type_info@@6B@")
+#endif // _MSC_VER
+TEST(InterpreterTest, CatchException) {
+  llvm::InitializeNativeTarget();
+  llvm::InitializeNativeTargetAsmPrinter();
+
+  {
+auto J = llvm::orc::LLJITBuilder().create();
+if (!J) {
+  // The platform does not support JITs.
+  llvm::consumeError(J.takeError());
+  return;
+}
+  }
+  const char ExceptionCode[] =
+  R"(
+#include 
+#include 
+
+static void ThrowerAnError(const char* Name) {
+  throw std::runtime_error(Name);
+}
+
+int main(int argc, const char** argv) {
+  // FIXME: Somehow when we build this test in release mode argc is not 0.
+  // printf("%d\n", argc);
+  // for (int I = 0; I < argc; ++I)
+  //   printf("arg[%d]='%s'\n", I, argv[I]);
+
+  try {
+ThrowerAnError("In JIT");
+  } catch (const std::exception& E) {
+printf("Caught: '%s'\n", E.what());
+  } catch (...) {
+printf("Unknown exception\n");
+  }
+  ThrowerAnError("From JIT");
+  return 0;
+}
+)";
+  std::string ResourceDir = MakeResourcesPath();
+  std::unique_ptr Interp =
+  createInterpreter({"-resource-dir", ResourceDir.c_str()});
+  // Adjust the resource-dir
+  llvm::cantFail(Interp->ParseAndExecute(ExceptionCode));
+#if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST && !defined(_WIN32)
+  testing::internal::CaptureStdout();
+  auto Main = (int (*)(...))llvm::cantFail(Interp->getSymbolAddress("main"));
+  // Compiling this file with exceptions on is problematic on some platforms.
+  // Instead we expect std::terminate to be called upon thrown exception.
+  EXPECT_DEATH(Main(), "terminate called after throwing an instance of '.*'");
+#endif
+  std::string CapturedStdOut = testing::internal::GetCapturedStdout();
+  EXPECT_EQ(CapturedStdOut, "Caught: 'In JIT'\n");
+}
+
 static std::string DeclToString(Decl *D) {
   return llvm::cast(D)->getQualifiedNameAsString();
 }
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++