[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-03-21 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

@NoQ, why does the following trigger a null-dereference warning? 
(https://godbolt.org/z/Kxox8qd16)

  void g(std::unique_ptr a) {
A *aptr = a.get();
if (!aptr) {}
a->foo();
  }

When `a->foo()` is called, the constraint `!aptr` is no longer valid and so 
`InnerPointerVal` corresponding to `a` is no longer constrained to be null.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[clang] 874bdc8 - [Driver] Clean up Debian multiarch /usr/include/ madness

2021-03-21 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-03-21T22:40:38-07:00
New Revision: 874bdc8e61662b5f39a9626b9132e0979fae556f

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

LOG: [Driver] Clean up Debian multiarch /usr/include/ madness

Debian multiarch additionally adds /usr/include/ and somehow
Android borrowed the idea. (Note /usr//include is already an
include dir...). On Debian, we should just assume a GCC installation is
available and use its triple.

Added: 

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/arm-linux-gnueabi/crt1.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/arm-linux-gnueabi/crti.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/arm-linux-gnueabi/crtn.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/arm-linux-gnueabihf/crt1.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/arm-linux-gnueabihf/crti.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/arm-linux-gnueabihf/crtn.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/armeb-linux-gnueabi/crt1.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/armeb-linux-gnueabi/crti.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/armeb-linux-gnueabi/crtn.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/armeb-linux-gnueabihf/crt1.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/armeb-linux-gnueabihf/crti.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/armeb-linux-gnueabihf/crtn.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/gcc/arm-linux-gnueabi/10/crtbegin.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/gcc/arm-linux-gnueabihf/10/crtbegin.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/gcc/armeb-linux-gnueabi/10/crtbegin.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/lib/gcc/armeb-linux-gnueabihf/10/crtbegin.o

clang/test/Driver/Inputs/multilib_arm_linux_tree/usr/include/arm-linux-gnueabihf/.keep

clang/test/Driver/Inputs/multilib_arm_linux_tree/usr/include/armeb-linux-gnueabi/.keep

clang/test/Driver/Inputs/multilib_arm_linux_tree/usr/include/armeb-linux-gnueabihf/.keep

Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/arm-multilibs.c

Removed: 

clang/test/Driver/Inputs/multilib_armeb_linux_tree/usr/include/armeb-linux-gnueabi/.keep

clang/test/Driver/Inputs/multilib_armebhf_linux_tree/usr/include/armeb-linux-gnueabihf/.keep

clang/test/Driver/Inputs/multilib_armhf_linux_tree/usr/include/arm-linux-gnueabihf/.keep



diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index c554047beac3..972044fb615e 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2999,8 +2999,6 @@ Generic_GCC::addGCCLibStdCxxIncludePaths(const 
llvm::opt::ArgList ,
   const Multilib  = GCCInstallation.getMultilib();
   const std::string Triple = getMultiarchTriple(
   getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot);
-  const std::string TargetMultiarchTriple =
-  getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
   const GCCVersion  = GCCInstallation.getVersion();
 
   // Try /../$triple/include/c++/$version then /../include/c++/$version.

diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index cbfa5152bc8e..e889791d19b2 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -604,172 +604,16 @@ void Linux::AddClangSystemIncludeArgs(const ArgList 
,
 return;
   }
 
-  // Implement generic Debian multiarch support.
-  const StringRef X86_64MultiarchIncludeDirs[] = {
-  "/usr/include/x86_64-linux-gnu",
-
-  // FIXME: These are older forms of multiarch. It's not clear that they're
-  // in use in any released version of Debian, so we should consider
-  // removing them.
-  "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"};
-  const StringRef X86MultiarchIncludeDirs[] = {
-  "/usr/include/i386-linux-gnu",
-
-  // FIXME: These are older forms of multiarch. It's not clear that they're
-  // in use in any released version of Debian, so we should consider
-  // removing them.
-  "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu",
-  "/usr/include/i486-linux-gnu"};
-  const StringRef AArch64MultiarchIncludeDirs[] = {
-  "/usr/include/aarch64-linux-gnu"};
-  const StringRef ARMMultiarchIncludeDirs[] = {
-  "/usr/include/arm-linux-gnueabi"};
-  const StringRef ARMHFMultiarchIncludeDirs[] = {
-  "/usr/include/arm-linux-gnueabihf"};
-  const StringRef ARMEBMultiarchIncludeDirs[] = {
-  "/usr/include/armeb-linux-gnueabi"};
-  

[PATCH] D98923: [Driver] Pass -fexperimental-strict-floating-point to cc1 if it is specified

2021-03-21 Thread Jim Lin via Phabricator via cfe-commits
Jim abandoned this revision.
Jim added a comment.

In D98923#2638061 , @craig.topper 
wrote:

> Isn't OPT_fexperimental_strict_floating_point marked as a CC1Option in 
> Options.td. Can the driver even recognize it?
>
> Can you use -Xclang -fexperimental-strict-floating-point for your use case?

Hi, Thanks your suggestion, I would use -Xclang 
-fexperimental-strict-floating-point  for my test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98923

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


[PATCH] D96110: [X86] Pass to transform tdpbf16ps intrinsics to scalar operation.

2021-03-21 Thread Bing Yu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG113f077f808f: [X86] Pass to transform tdpbf16ps intrinsics 
to scalar operation. (authored by yubing).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96110

Files:
  llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp
  llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll

Index: llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
===
--- llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
+++ llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
@@ -97,8 +97,8 @@
   ret void
 }
 
-define dso_local void @test_amx_dp(i16 signext %row, i16 signext %col, i16 signext %k, <256 x i32> %c, <256 x i32> %a, <256 x i32> %b, <256 x i32>* %vptr) #0 {
-; CHECK-LABEL: @test_amx_dp(
+define dso_local void @test_amx_dpbssd(i16 signext %row, i16 signext %col, i16 signext %k, <256 x i32> %c, <256 x i32> %a, <256 x i32> %b, <256 x i32>* %vptr) #0 {
+; CHECK-LABEL: @test_amx_dpbssd(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:[[A_AMX:%.*]] = bitcast <256 x i32> [[A:%.*]] to x86_amx
 ; CHECK-NEXT:[[B_AMX:%.*]] = bitcast <256 x i32> [[B:%.*]] to x86_amx
@@ -172,6 +172,84 @@
   ret void
 }
 
+define dso_local void @test_amx_dpbf16ps(i16 signext %row, i16 signext %col, i16 signext %k, <256 x i32> %c, <256 x i32> %a, <256 x i32> %b, <256 x i32>* %vptr) #0 {
+; CHECK-LABEL: @test_amx_dpbf16ps(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[A_AMX:%.*]] = bitcast <256 x i32> [[A:%.*]] to x86_amx
+; CHECK-NEXT:[[B_AMX:%.*]] = bitcast <256 x i32> [[B:%.*]] to x86_amx
+; CHECK-NEXT:[[C_AMX:%.*]] = bitcast <256 x i32> [[C:%.*]] to x86_amx
+; CHECK-NEXT:[[TMP0:%.*]] = lshr i16 [[COL:%.*]], 2
+; CHECK-NEXT:[[TMP1:%.*]] = lshr i16 [[K:%.*]], 2
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_ROWS_HEADER:%.*]]
+; CHECK:   tdpbf16ps.scalarize.rows.header:
+; CHECK-NEXT:[[TDPBF16PS_SCALARIZE_ROWS_IV:%.*]] = phi i16 [ 0, [[ENTRY:%.*]] ], [ [[TDPBF16PS_SCALARIZE_ROWS_STEP:%.*]], [[TDPBF16PS_SCALARIZE_ROWS_LATCH:%.*]] ]
+; CHECK-NEXT:[[VEC_C_PHI_ROW:%.*]] = phi <256 x i32> [ [[C]], [[ENTRY]] ], [ [[TMP21:%.*]], [[TDPBF16PS_SCALARIZE_ROWS_LATCH]] ]
+; CHECK-NEXT:[[VEC_D_PHI_ROW:%.*]] = phi <256 x i32> [ zeroinitializer, [[ENTRY]] ], [ [[TMP23:%.*]], [[TDPBF16PS_SCALARIZE_ROWS_LATCH]] ]
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_ROWS_BODY:%.*]]
+; CHECK:   tdpbf16ps.scalarize.rows.body:
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_COLS_HEADER:%.*]]
+; CHECK:   tdpbf16ps.scalarize.cols.header:
+; CHECK-NEXT:[[TDPBF16PS_SCALARIZE_COLS_IV:%.*]] = phi i16 [ 0, [[TDPBF16PS_SCALARIZE_ROWS_BODY]] ], [ [[TDPBF16PS_SCALARIZE_COLS_STEP:%.*]], [[TDPBF16PS_SCALARIZE_COLS_LATCH:%.*]] ]
+; CHECK-NEXT:[[VEC_C_PHI_COL:%.*]] = phi <256 x i32> [ [[VEC_C_PHI_ROW]], [[TDPBF16PS_SCALARIZE_ROWS_BODY]] ], [ [[TMP21]], [[TDPBF16PS_SCALARIZE_COLS_LATCH]] ]
+; CHECK-NEXT:[[VEC_D_PHI_COL:%.*]] = phi <256 x i32> [ [[VEC_D_PHI_ROW]], [[TDPBF16PS_SCALARIZE_ROWS_BODY]] ], [ [[TMP23]], [[TDPBF16PS_SCALARIZE_COLS_LATCH]] ]
+; CHECK-NEXT:[[TMP2:%.*]] = mul i16 [[TDPBF16PS_SCALARIZE_ROWS_IV]], 16
+; CHECK-NEXT:[[TMP3:%.*]] = add i16 [[TMP2]], [[TDPBF16PS_SCALARIZE_COLS_IV]]
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_COLS_BODY:%.*]]
+; CHECK:   tdpbf16ps.scalarize.cols.body:
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_INNER_HEADER:%.*]]
+; CHECK:   tdpbf16ps.scalarize.inner.header:
+; CHECK-NEXT:[[TDPBF16PS_SCALARIZE_INNER_IV:%.*]] = phi i16 [ 0, [[TDPBF16PS_SCALARIZE_COLS_BODY]] ], [ [[TDPBF16PS_SCALARIZE_INNER_STEP:%.*]], [[TDPBF16PS_SCALARIZE_INNER_LATCH:%.*]] ]
+; CHECK-NEXT:[[VEC_C_INNER_PHI:%.*]] = phi <256 x i32> [ [[VEC_C_PHI_COL]], [[TDPBF16PS_SCALARIZE_COLS_BODY]] ], [ [[TMP21]], [[TDPBF16PS_SCALARIZE_INNER_LATCH]] ]
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_INNER_BODY:%.*]]
+; CHECK:   tdpbf16ps.scalarize.inner.body:
+; CHECK-NEXT:[[TMP4:%.*]] = mul i16 [[TDPBF16PS_SCALARIZE_ROWS_IV]], 16
+; CHECK-NEXT:[[TMP5:%.*]] = add i16 [[TMP4]], [[TDPBF16PS_SCALARIZE_INNER_IV]]
+; CHECK-NEXT:[[TMP6:%.*]] = mul i16 [[TDPBF16PS_SCALARIZE_INNER_IV]], 16
+; CHECK-NEXT:[[TMP7:%.*]] = add i16 [[TMP6]], [[TDPBF16PS_SCALARIZE_COLS_IV]]
+; CHECK-NEXT:[[TMP8:%.*]] = extractelement <256 x i32> [[VEC_C_INNER_PHI]], i16 [[TMP3]]
+; CHECK-NEXT:[[TMP9:%.*]] = bitcast i32 [[TMP8]] to float
+; CHECK-NEXT:[[TMP10:%.*]] = extractelement <256 x i32> [[A]], i16 [[TMP5]]
+; CHECK-NEXT:[[TMP11:%.*]] = bitcast i32 [[TMP10]] to <2 x i16>
+; CHECK-NEXT:[[TMP12:%.*]] = extractelement <256 x i32> [[B]], i16 [[TMP7]]
+; CHECK-NEXT:[[TMP13:%.*]] = bitcast i32 [[TMP12]] to <2 x i16>
+; CHECK-NEXT:[[TMP14:%.*]] = shufflevector <2 x i16> [[TMP11]], <2 x i16> zeroinitializer, <4 x i32> 
+; CHECK-NEXT:[[TMP15:%.*]] = bitcast <4 x i16> [[TMP14]] to <2 x 

[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-03-21 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 332193.
RedDocMD added a comment.

Added some more tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,10 +306,64 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is null}}
 // expected-note@-1 {{Taking true branch}}
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
 // expected-note@-1{{Dereference of null smart pointer 'P'}}
   }
 }
+
+void getShouldNotAlwaysLeaveANote() {
+	std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
+	A *a = P.get(); 
+	P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void derefInElseBranchOnUnknownInnerPtr(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  if (RP) {// expected-note {{Assuming 'RP' is null}}
+   // expected-note@-1 {{Taking false branch}}
+return;
+  }
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void derefInElseBranchShouldNotAlwaysLeaveNote(std::unique_ptr P) {
+  A *RP = P.get();
+  if (P) { // expected-note {{Assuming smart pointer 'P' is null}}
+   // expected-note@-1 {{Taking false branch}}
+return;
+  }
+  P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveNoteWhenPtrNotUsed(std::unique_ptr P) {
+  A *a = P.get(); 
+  if (!P) { // expected-note {{Taking true branch}}
+// expected-note@-1 {{Assuming smart pointer 'P' is null}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithWhileLoop(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  while (!RP) {// expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithForLoop(std::unique_ptr P) {
+  for (A *RP = P.get(); !RP;) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+// expected-note@-2 {{Obtained null inner pointer from 'P'}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -457,8 +457,22 @@
 
   State = State->BindExpr(Call.getOriginExpr(), C.getLocationContext(),
   InnerPointerVal);
-  // TODO: Add NoteTag, for how the raw pointer got using 'get' method.
-  C.addTransition(State);
+
+  C.addTransition(State, C.getNoteTag([ThisRegion, InnerPointerVal,
+   State](PathSensitiveBugReport ,
+  llvm::raw_ostream ) {
+if (() != smartptr::getNullDereferenceBugType() ||
+!BR.isInteresting(ThisRegion))
+  return;
+if (!BR.isInteresting(InnerPointerVal) || !BR.isInteresting(InnerPointerVal.getAsSymbol()))
+  return;
+if (ThisRegion->canPrintPretty()) {
+  OS << "Obtained null inner pointer from";
+  checkAndPrettyPrintRegion(OS, ThisRegion);
+} else {
+  OS << "Obtained null inner pointer here";
+}
+  }));
 }
 
 bool SmartPtrModeling::handleAssignOp(const CallEvent ,
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
===
--- 

[PATCH] D96110: [X86] Pass to transform tdpbf16ps intrinsics to scalar operation.

2021-03-21 Thread Bing Yu via Phabricator via cfe-commits
yubing updated this revision to Diff 332190.
yubing added a comment.

Rebase after https://reviews.llvm.org/D98773 is merged.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96110

Files:
  llvm/lib/Target/X86/X86LowerAMXIntrinsics.cpp
  llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll

Index: llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
===
--- llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
+++ llvm/test/CodeGen/X86/AMX/amx-low-intrinsics.ll
@@ -97,8 +97,8 @@
   ret void
 }
 
-define dso_local void @test_amx_dp(i16 signext %row, i16 signext %col, i16 signext %k, <256 x i32> %c, <256 x i32> %a, <256 x i32> %b, <256 x i32>* %vptr) #0 {
-; CHECK-LABEL: @test_amx_dp(
+define dso_local void @test_amx_dpbssd(i16 signext %row, i16 signext %col, i16 signext %k, <256 x i32> %c, <256 x i32> %a, <256 x i32> %b, <256 x i32>* %vptr) #0 {
+; CHECK-LABEL: @test_amx_dpbssd(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:[[A_AMX:%.*]] = bitcast <256 x i32> [[A:%.*]] to x86_amx
 ; CHECK-NEXT:[[B_AMX:%.*]] = bitcast <256 x i32> [[B:%.*]] to x86_amx
@@ -172,6 +172,84 @@
   ret void
 }
 
+define dso_local void @test_amx_dpbf16ps(i16 signext %row, i16 signext %col, i16 signext %k, <256 x i32> %c, <256 x i32> %a, <256 x i32> %b, <256 x i32>* %vptr) #0 {
+; CHECK-LABEL: @test_amx_dpbf16ps(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[A_AMX:%.*]] = bitcast <256 x i32> [[A:%.*]] to x86_amx
+; CHECK-NEXT:[[B_AMX:%.*]] = bitcast <256 x i32> [[B:%.*]] to x86_amx
+; CHECK-NEXT:[[C_AMX:%.*]] = bitcast <256 x i32> [[C:%.*]] to x86_amx
+; CHECK-NEXT:[[TMP0:%.*]] = lshr i16 [[COL:%.*]], 2
+; CHECK-NEXT:[[TMP1:%.*]] = lshr i16 [[K:%.*]], 2
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_ROWS_HEADER:%.*]]
+; CHECK:   tdpbf16ps.scalarize.rows.header:
+; CHECK-NEXT:[[TDPBF16PS_SCALARIZE_ROWS_IV:%.*]] = phi i16 [ 0, [[ENTRY:%.*]] ], [ [[TDPBF16PS_SCALARIZE_ROWS_STEP:%.*]], [[TDPBF16PS_SCALARIZE_ROWS_LATCH:%.*]] ]
+; CHECK-NEXT:[[VEC_C_PHI_ROW:%.*]] = phi <256 x i32> [ [[C]], [[ENTRY]] ], [ [[TMP21:%.*]], [[TDPBF16PS_SCALARIZE_ROWS_LATCH]] ]
+; CHECK-NEXT:[[VEC_D_PHI_ROW:%.*]] = phi <256 x i32> [ zeroinitializer, [[ENTRY]] ], [ [[TMP23:%.*]], [[TDPBF16PS_SCALARIZE_ROWS_LATCH]] ]
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_ROWS_BODY:%.*]]
+; CHECK:   tdpbf16ps.scalarize.rows.body:
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_COLS_HEADER:%.*]]
+; CHECK:   tdpbf16ps.scalarize.cols.header:
+; CHECK-NEXT:[[TDPBF16PS_SCALARIZE_COLS_IV:%.*]] = phi i16 [ 0, [[TDPBF16PS_SCALARIZE_ROWS_BODY]] ], [ [[TDPBF16PS_SCALARIZE_COLS_STEP:%.*]], [[TDPBF16PS_SCALARIZE_COLS_LATCH:%.*]] ]
+; CHECK-NEXT:[[VEC_C_PHI_COL:%.*]] = phi <256 x i32> [ [[VEC_C_PHI_ROW]], [[TDPBF16PS_SCALARIZE_ROWS_BODY]] ], [ [[TMP21]], [[TDPBF16PS_SCALARIZE_COLS_LATCH]] ]
+; CHECK-NEXT:[[VEC_D_PHI_COL:%.*]] = phi <256 x i32> [ [[VEC_D_PHI_ROW]], [[TDPBF16PS_SCALARIZE_ROWS_BODY]] ], [ [[TMP23]], [[TDPBF16PS_SCALARIZE_COLS_LATCH]] ]
+; CHECK-NEXT:[[TMP2:%.*]] = mul i16 [[TDPBF16PS_SCALARIZE_ROWS_IV]], 16
+; CHECK-NEXT:[[TMP3:%.*]] = add i16 [[TMP2]], [[TDPBF16PS_SCALARIZE_COLS_IV]]
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_COLS_BODY:%.*]]
+; CHECK:   tdpbf16ps.scalarize.cols.body:
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_INNER_HEADER:%.*]]
+; CHECK:   tdpbf16ps.scalarize.inner.header:
+; CHECK-NEXT:[[TDPBF16PS_SCALARIZE_INNER_IV:%.*]] = phi i16 [ 0, [[TDPBF16PS_SCALARIZE_COLS_BODY]] ], [ [[TDPBF16PS_SCALARIZE_INNER_STEP:%.*]], [[TDPBF16PS_SCALARIZE_INNER_LATCH:%.*]] ]
+; CHECK-NEXT:[[VEC_C_INNER_PHI:%.*]] = phi <256 x i32> [ [[VEC_C_PHI_COL]], [[TDPBF16PS_SCALARIZE_COLS_BODY]] ], [ [[TMP21]], [[TDPBF16PS_SCALARIZE_INNER_LATCH]] ]
+; CHECK-NEXT:br label [[TDPBF16PS_SCALARIZE_INNER_BODY:%.*]]
+; CHECK:   tdpbf16ps.scalarize.inner.body:
+; CHECK-NEXT:[[TMP4:%.*]] = mul i16 [[TDPBF16PS_SCALARIZE_ROWS_IV]], 16
+; CHECK-NEXT:[[TMP5:%.*]] = add i16 [[TMP4]], [[TDPBF16PS_SCALARIZE_INNER_IV]]
+; CHECK-NEXT:[[TMP6:%.*]] = mul i16 [[TDPBF16PS_SCALARIZE_INNER_IV]], 16
+; CHECK-NEXT:[[TMP7:%.*]] = add i16 [[TMP6]], [[TDPBF16PS_SCALARIZE_COLS_IV]]
+; CHECK-NEXT:[[TMP8:%.*]] = extractelement <256 x i32> [[VEC_C_INNER_PHI]], i16 [[TMP3]]
+; CHECK-NEXT:[[TMP9:%.*]] = bitcast i32 [[TMP8]] to float
+; CHECK-NEXT:[[TMP10:%.*]] = extractelement <256 x i32> [[A]], i16 [[TMP5]]
+; CHECK-NEXT:[[TMP11:%.*]] = bitcast i32 [[TMP10]] to <2 x i16>
+; CHECK-NEXT:[[TMP12:%.*]] = extractelement <256 x i32> [[B]], i16 [[TMP7]]
+; CHECK-NEXT:[[TMP13:%.*]] = bitcast i32 [[TMP12]] to <2 x i16>
+; CHECK-NEXT:[[TMP14:%.*]] = shufflevector <2 x i16> [[TMP11]], <2 x i16> zeroinitializer, <4 x i32> 
+; CHECK-NEXT:[[TMP15:%.*]] = bitcast <4 x i16> [[TMP14]] to <2 x float>
+; CHECK-NEXT:[[TMP16:%.*]] = shufflevector <2 x i16> 

[PATCH] D66038: [Support] heavyweight_hardware_concurrency uses affinity when counting cores fails, and never returns 0

2021-03-21 Thread Lupe Serrano via Phabricator via cfe-commits
serranolupe091 accepted this revision.
serranolupe091 added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: dexonsmith.

hardware_concurrency


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66038

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


[PATCH] D96316: [ASTMatcher] Add AST Matcher support for C++20 coroutine keywords

2021-03-21 Thread Chuanqi Xu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG55486161fa0b: [ASTMatcher] Add AST Matcher support for C++20 
coroutine keywords (authored by ChuanqiXu).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D96316?vs=329923=332189#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96316

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -510,6 +510,83 @@
   varDecl(hasName("lPtrDecay";
 }
 
+TEST(Matcher, MatchesCoroutine) {
+  FileContentMappings M;
+  M.push_back(std::make_pair("/coro_header", R"cpp(
+namespace std {
+namespace experimental {
+
+template 
+struct void_t_imp {
+  using type = void;
+};
+template 
+using void_t = typename void_t_imp::type;
+
+template 
+struct traits_sfinae_base {};
+
+template 
+struct traits_sfinae_base> {
+  using promise_type = typename T::promise_type;
+};
+
+template 
+struct coroutine_traits : public traits_sfinae_base {};
+}}  // namespace std::experimental
+struct awaitable {
+  bool await_ready() noexcept;
+  template 
+  void await_suspend(F) noexcept;
+  void await_resume() noexcept;
+} a;
+struct promise {
+  void get_return_object();
+  awaitable initial_suspend();
+  awaitable final_suspend() noexcept;
+  awaitable yield_value(int); // expected-note 2{{candidate}}
+  void return_value(int); // expected-note 2{{here}}
+  void unhandled_exception();
+};
+template 
+struct std::experimental::coroutine_traits { using promise_type = promise; };
+namespace std {
+namespace experimental {
+template 
+struct coroutine_handle {
+  static coroutine_handle from_address(void *) noexcept;
+};
+}} // namespace std::experimental
+)cpp"));
+  StringRef CoReturnCode = R"cpp(
+#include 
+void check_match_co_return() {
+  co_return 1;
+}
+)cpp";
+  EXPECT_TRUE(matchesConditionally(CoReturnCode, 
+   coreturnStmt(isExpansionInMainFile()), 
+   true, {"-std=c++20", "-I/"}, M));
+  StringRef CoAwaitCode = R"cpp(
+#include 
+void check_match_co_await() {
+  co_await a;
+}
+)cpp";
+  EXPECT_TRUE(matchesConditionally(CoAwaitCode, 
+   coawaitExpr(isExpansionInMainFile()), 
+   true, {"-std=c++20", "-I/"}, M));
+  StringRef CoYieldCode = R"cpp(
+#include 
+void check_match_co_yield() {
+  co_yield 1.0;
+}
+)cpp";
+  EXPECT_TRUE(matchesConditionally(CoYieldCode, 
+   coyieldExpr(isExpansionInMainFile()), 
+   true, {"-std=c++20", "-I/"}, M));
+}
+
 TEST(Matcher, isClassMessage) {
   EXPECT_TRUE(matchesObjC(
   "@interface NSString +(NSString *) stringWithFormat; @end "
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -166,11 +166,14 @@
   REGISTER_MATCHER(complexType);
   REGISTER_MATCHER(compoundLiteralExpr);
   REGISTER_MATCHER(compoundStmt);
+  REGISTER_MATCHER(coawaitExpr);
   REGISTER_MATCHER(conditionalOperator);
   REGISTER_MATCHER(constantArrayType);
   REGISTER_MATCHER(constantExpr);
   REGISTER_MATCHER(containsDeclaration);
   REGISTER_MATCHER(continueStmt);
+  REGISTER_MATCHER(coreturnStmt);
+  REGISTER_MATCHER(coyieldExpr);
   REGISTER_MATCHER(cudaKernelCallExpr);
   REGISTER_MATCHER(cxxBindTemporaryExpr);
   REGISTER_MATCHER(cxxBoolLiteral);
@@ -214,6 +217,7 @@
   REGISTER_MATCHER(decltypeType);
   REGISTER_MATCHER(deducedTemplateSpecializationType);
   REGISTER_MATCHER(defaultStmt);
+  REGISTER_MATCHER(dependentCoawaitExpr);
   REGISTER_MATCHER(dependentSizedArrayType);
   REGISTER_MATCHER(designatedInitExpr);
   REGISTER_MATCHER(designatorCountIs);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -883,6 +883,7 @@
 const internal::VariadicDynCastAllOfMatcher doStmt;
 const internal::VariadicDynCastAllOfMatcher breakStmt;
 const internal::VariadicDynCastAllOfMatcher continueStmt;
+const internal::VariadicDynCastAllOfMatcher coreturnStmt;
 const internal::VariadicDynCastAllOfMatcher returnStmt;
 const 

[clang] 5548616 - [ASTMatcher] Add AST Matcher support for C++20 coroutine keywords

2021-03-21 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2021-03-22T10:27:46+08:00
New Revision: 55486161fa0bc29519bf53f0e6302b14d8de5578

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

LOG: [ASTMatcher] Add AST Matcher support for C++20 coroutine keywords

Summary: Try to enable the support for C++20 coroutine keywords for AST
Matchers.

Reviewers: sammccall, njames93, aaron.ballman

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 0d2570bcd58f..b8fb27b126fc 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1337,6 +1337,16 @@ Node Matchers
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtcoawaitExprMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CoawaitExpr.html;>CoawaitExpr...
+Matches co_await 
expressions.
+
+Given
+  co_await 1;
+coawaitExpr()
+  matches 'co_await 1'
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtcompoundLiteralExprMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CompoundLiteralExpr.html;>CompoundLiteralExpr...
 Matches 
compound (i.e. non-scalar) literals
 
@@ -1383,6 +1393,26 @@ Node Matchers
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtcoreturnStmtMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CoreturnStmt.html;>CoreturnStmt...
+Matches co_return 
statements.
+
+Given
+  while (true) { co_return; }
+coreturnStmt()
+  matches 'co_return'
+
+
+
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtcoyieldExprMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CoyieldExpr.html;>CoyieldExpr...
+Matches co_yield 
expressions.
+
+Given
+  co_yield 1;
+coyieldExpr()
+  matches 'co_yield 1'
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtcudaKernelCallExprMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CUDAKernelCallExpr.html;>CUDAKernelCallExpr...
 Matches CUDA 
kernel call expression.
 
@@ -1698,6 +1728,11 @@ Node Matchers
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtdependentCoawaitExprMatcherhttps://clang.llvm.org/doxygen/classclang_1_1DependentCoawaitExpr.html;>DependentCoawaitExpr...
+Matches 
co_await expressions where the type of the promise is dependent
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtdesignatedInitExprMatcherhttps://clang.llvm.org/doxygen/classclang_1_1DesignatedInitExpr.html;>DesignatedInitExpr...
 Matches C99 
designated initializer expressions [C99 6.7.8].
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 64e8cecf4822..fd0e9d6d7c1f 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2162,6 +2162,17 @@ extern const internal::VariadicDynCastAllOfMatcher breakStmt;
 extern const internal::VariadicDynCastAllOfMatcher
 continueStmt;
 
+/// Matches co_return statements.
+///
+/// Given
+/// \code
+///   while (true) { co_return; }
+/// \endcode
+/// coreturnStmt()
+///   matches 'co_return'
+extern const internal::VariadicDynCastAllOfMatcher
+coreturnStmt;
+
 /// Matches return statements.
 ///
 /// Given
@@ -2379,6 +2390,30 @@ extern const internal::VariadicDynCastAllOfMatcher
 extern const internal::VariadicDynCastAllOfMatcher
 compoundLiteralExpr;
 
+/// Matches co_await expressions.
+///
+/// Given
+/// \code
+///   co_await 1;
+/// \endcode
+/// coawaitExpr()
+///   matches 'co_await 1'
+extern const internal::VariadicDynCastAllOfMatcher
+coawaitExpr;
+/// Matches co_await expressions where the type of the promise is dependent
+extern const internal::VariadicDynCastAllOfMatcher
+dependentCoawaitExpr;
+/// Matches co_yield expressions.
+///
+/// Given
+/// \code
+///   co_yield 1;
+/// \endcode
+/// coyieldExpr()
+///   matches 'co_yield 1'
+extern const internal::VariadicDynCastAllOfMatcher
+coyieldExpr;
+
 /// Matches nullptr literal.
 extern const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiteralExpr;

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index b20a60425661..c2001070de55 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -883,6 +883,7 @@ const internal::VariadicDynCastAllOfMatcher whileStmt;
 const internal::VariadicDynCastAllOfMatcher 

[PATCH] D98902: [Clang][OpenMP][NVPTX] Fixed failure in openmp-offload-gpu.c if the system has CUDA

2021-03-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D98902#2636308 , @jdoerfert wrote:

> @tra, so you think we should not do this? The user will see a link error late 
> I assume, might be better.

I think @tra 's point is we should not do that for CUDA code. This change only 
affects OpenMP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98902

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


[PATCH] D99005: [clang] WIP: Implement P2266

2021-03-21 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 332187.
mizvekov added a comment.

small cleanup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

Files:
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-14.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp
  clang/test/CXX/special/class.copy/p33-0x.cpp
  clang/test/SemaCXX/coroutine-rvo.cpp

Index: clang/test/SemaCXX/coroutine-rvo.cpp
===
--- clang/test/SemaCXX/coroutine-rvo.cpp
+++ clang/test/SemaCXX/coroutine-rvo.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only
+// RUN: %clang_cc1 -verify -std=c++17 -fcoroutines-ts -fsyntax-only %s
 
 namespace std::experimental {
 template  struct coroutine_handle {
@@ -39,10 +39,14 @@
 };
 
 struct MoveOnly {
-  MoveOnly() {};
+  MoveOnly() = default;
   MoveOnly(const MoveOnly&) = delete;
-  MoveOnly(MoveOnly&&) noexcept {};
-  ~MoveOnly() {};
+  MoveOnly(MoveOnly &&) = default;
+};
+
+struct NoCopyNoMove {
+  NoCopyNoMove() = default;
+  NoCopyNoMove(const NoCopyNoMove &) = delete;
 };
 
 template 
@@ -52,18 +56,93 @@
 auto final_suspend() noexcept { return suspend_never{}; }
 auto get_return_object() { return task{}; }
 static void unhandled_exception() {}
-void return_value(T&& value) {}
+void return_value(T &) {} // expected-note 4{{passing argument}}
   };
 };
 
-task f() {
-  MoveOnly value;
+task local2val() {
+  NoCopyNoMove value;
+  co_return value;
+}
+
+task local2ref() {
+  NoCopyNoMove value;
+  co_return value; // expected-error {{non-const lvalue reference to type 'NoCopyNoMove' cannot bind to a temporary of type 'NoCopyNoMove'}}
+}
+
+// We need the move constructor for construction of the coroutine.
+task param2val(MoveOnly value) {
   co_return value;
 }
 
-int main() {
-  f();
-  return 0;
+task lvalue2val(NoCopyNoMove ) {
+  co_return value; // expected-error {{rvalue reference to type 'NoCopyNoMove' cannot bind to lvalue of type 'NoCopyNoMove'}}
+}
+
+task rvalue2val(NoCopyNoMove &) {
+  co_return value;
+}
+
+task lvalue2ref(NoCopyNoMove ) {
+  co_return value;
+}
+
+task rvalue2ref(NoCopyNoMove &) {
+  co_return value; // expected-error {{non-const lvalue reference to type 'NoCopyNoMove' cannot bind to a temporary of type 'NoCopyNoMove'}}
+}
+
+struct To {
+  operator MoveOnly() &&;
+};
+task conversion_operator() {
+  To t;
+  co_return t;
+}
+
+struct Construct {
+  Construct(MoveOnly);
+};
+task converting_constructor() {
+  MoveOnly w;
+  co_return w;
 }
 
-// expected-no-diagnostics
+struct Derived : MoveOnly {};
+task derived2base() {
+  Derived result;
+  co_return result;
+}
+
+struct RetThis {
+  task foo() && {
+co_return *this; // expected-error {{rvalue reference to type 'RetThis' cannot bind to lvalue of type 'RetThis'}}
+  }
+};
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+template 
+struct template_return_task {
+  struct promise_type {
+auto initial_suspend() { return suspend_never{}; }
+auto final_suspend() noexcept { return suspend_never{}; }
+auto get_return_object() { return template_return_task{}; }
+static void unhandled_exception();
+template 
+void return_value(U &) {
+  static_assert(is_same::value);
+}
+  };
+};
+
+template_return_task param2template(MoveOnly value) {
+  co_return value; // We should deduce U = MoveOnly.
+}
+
+template_return_task lvalue2template(NoCopyNoMove ) {
+  co_return value; // We should deduce U = NoCopyNoMove&.
+}
Index: clang/test/CXX/special/class.copy/p33-0x.cpp
===
--- clang/test/CXX/special/class.copy/p33-0x.cpp
+++ clang/test/CXX/special/class.copy/p33-0x.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++2b -fsyntax-only -verify=expected %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fsyntax-only -verify=expected %s
 class X {
   X(const X&);
 
Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-14.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-14.cpp
+++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-14.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -verify -std=c++1y %s
+// RUN: %clang_cc1 -verify -std=c++2b -verify=expected,cxx2b %s
+// RUN: %clang_cc1 -verify -std=c++14 -verify=expected,cxx14 %s
 
 namespace std {
   

[PATCH] D99005: [clang] WIP: Implement P2266

2021-03-21 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 332186.
mizvekov added a comment.

small cleanup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-14.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp
  clang/test/CXX/special/class.copy/p33-0x.cpp
  clang/test/SemaCXX/coroutine-rvo.cpp

Index: clang/test/SemaCXX/coroutine-rvo.cpp
===
--- clang/test/SemaCXX/coroutine-rvo.cpp
+++ clang/test/SemaCXX/coroutine-rvo.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only
+// RUN: %clang_cc1 -verify -std=c++17 -fcoroutines-ts -fsyntax-only %s
 
 namespace std::experimental {
 template  struct coroutine_handle {
@@ -39,10 +39,14 @@
 };
 
 struct MoveOnly {
-  MoveOnly() {};
+  MoveOnly() = default;
   MoveOnly(const MoveOnly&) = delete;
-  MoveOnly(MoveOnly&&) noexcept {};
-  ~MoveOnly() {};
+  MoveOnly(MoveOnly &&) = default;
+};
+
+struct NoCopyNoMove {
+  NoCopyNoMove() = default;
+  NoCopyNoMove(const NoCopyNoMove &) = delete;
 };
 
 template 
@@ -52,18 +56,93 @@
 auto final_suspend() noexcept { return suspend_never{}; }
 auto get_return_object() { return task{}; }
 static void unhandled_exception() {}
-void return_value(T&& value) {}
+void return_value(T &) {} // expected-note 4{{passing argument}}
   };
 };
 
-task f() {
-  MoveOnly value;
+task local2val() {
+  NoCopyNoMove value;
+  co_return value;
+}
+
+task local2ref() {
+  NoCopyNoMove value;
+  co_return value; // expected-error {{non-const lvalue reference to type 'NoCopyNoMove' cannot bind to a temporary of type 'NoCopyNoMove'}}
+}
+
+// We need the move constructor for construction of the coroutine.
+task param2val(MoveOnly value) {
   co_return value;
 }
 
-int main() {
-  f();
-  return 0;
+task lvalue2val(NoCopyNoMove ) {
+  co_return value; // expected-error {{rvalue reference to type 'NoCopyNoMove' cannot bind to lvalue of type 'NoCopyNoMove'}}
+}
+
+task rvalue2val(NoCopyNoMove &) {
+  co_return value;
+}
+
+task lvalue2ref(NoCopyNoMove ) {
+  co_return value;
+}
+
+task rvalue2ref(NoCopyNoMove &) {
+  co_return value; // expected-error {{non-const lvalue reference to type 'NoCopyNoMove' cannot bind to a temporary of type 'NoCopyNoMove'}}
+}
+
+struct To {
+  operator MoveOnly() &&;
+};
+task conversion_operator() {
+  To t;
+  co_return t;
+}
+
+struct Construct {
+  Construct(MoveOnly);
+};
+task converting_constructor() {
+  MoveOnly w;
+  co_return w;
 }
 
-// expected-no-diagnostics
+struct Derived : MoveOnly {};
+task derived2base() {
+  Derived result;
+  co_return result;
+}
+
+struct RetThis {
+  task foo() && {
+co_return *this; // expected-error {{rvalue reference to type 'RetThis' cannot bind to lvalue of type 'RetThis'}}
+  }
+};
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+template 
+struct template_return_task {
+  struct promise_type {
+auto initial_suspend() { return suspend_never{}; }
+auto final_suspend() noexcept { return suspend_never{}; }
+auto get_return_object() { return template_return_task{}; }
+static void unhandled_exception();
+template 
+void return_value(U &) {
+  static_assert(is_same::value);
+}
+  };
+};
+
+template_return_task param2template(MoveOnly value) {
+  co_return value; // We should deduce U = MoveOnly.
+}
+
+template_return_task lvalue2template(NoCopyNoMove ) {
+  co_return value; // We should deduce U = NoCopyNoMove&.
+}
Index: clang/test/CXX/special/class.copy/p33-0x.cpp
===
--- clang/test/CXX/special/class.copy/p33-0x.cpp
+++ clang/test/CXX/special/class.copy/p33-0x.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++2b -fsyntax-only -verify=expected %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fsyntax-only -verify=expected %s
 class X {
   X(const X&);
 
Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-14.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-14.cpp
+++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-14.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -verify -std=c++1y %s
+// RUN: %clang_cc1 -verify -std=c++2b -verify=expected,cxx2b %s
+// RUN: %clang_cc1 -verify -std=c++14 

[PATCH] D69218: [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level)

2021-03-21 Thread Nikita Kniazev via Phabricator via cfe-commits
nick added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:3812-3821
 AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
 hasType,
 AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, TypedefNameDecl,
-ValueDecl),
+ValueDecl, CXXBaseSpecifier),
 internal::Matcher, InnerMatcher, 0) {
   QualType QT = internal::getUnderlyingType(Node);
   if (!QT.isNull())

njames93 wrote:
> I don't think the change to this matcher is warranted.
> The `hasType` matcher that accepts a DeclarationMatcher already has support 
> for cxxBaseSpecifier.
> However overloading the matcher that takes a QualType matcher doesn't make 
> sense as base specifiers have no qualifications.
What should I use in D69000 then? It is been a very long time since I developed 
and published these patches, but D69000 definitely requires this matcher, 
without it I get:

```
llvm-project\clang\include\clang\ASTMatchers\ASTMatchersInternal.h(1569): error 
C2338: right polymorphic conversion
llvm-project\clang-tools-extra\clang-tidy\modernize\DeprecatedIteratorBaseCheck.cpp(200):
 note: see reference to function template instantiation 
'clang::ast_matchers::internal::PolymorphicMatcher),clang::ast_matchers::internal::Matcher>::operator
 clang::ast_matchers::internal::Matcher(void) 
const' being compiled
llvm-project\clang-tools-extra\clang-tidy\modernize\DeprecatedIteratorBaseCheck.cpp(192):
 note: see reference to function template instantiation 
'clang::ast_matchers::internal::PolymorphicMatcher),clang::ast_matchers::internal::Matcher>::operator
 clang::ast_matchers::internal::Matcher(void) 
const' being compiled
```



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

https://reviews.llvm.org/D69218

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


[PATCH] D99005: [clang] WIP: Implement P2266

2021-03-21 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 332184.
mizvekov added a comment.

Changed:

- Implemented co_return as per Aaron's suggestion.
- Imported coroutine tests from D68845 .
- Test tags shortened: cxxYY_cxxZZ means every version from YY to ZZ, instead 
of cxxAA_BB_CC_DD.
- Existing test on decltype(auto) updated to also run on c++2b.
- Change one of the test cases to just instantiate the relevant template, as 
per Arthur.

Still missing:
Making this run on all tests:

- A lot of tests are running in only one old standard. Changing everything here 
would generate too much noise.
- Some simplifications:
  - Aggregate common code for adding the implicit cast.
  - PerformMoveOrCopyInitialization can be changed to PerformCopyInitialization 
in the cases where AllowNRVO is false.
  - Can easily skip adding the implicit cast if expr was already a xvalue.
  - getCopyElisionCandidate needs refactoring IMHO. It is doing too much in one 
function, and this patch makes it worse. There are a lot of calls to it 
sprinkled around in the same sequence. Some problems:
- On the current code, we want two things out of it: "Can we perform copy 
elision" AND "Can we perform implicit move". We end up calling it twice for 
that, with two parameters, instead of once returning both answers.
- With this patch, now we need to call it even before we have the function 
return type available, then decide this type based on it, and then call it 
again to figure out if we can do copy elision. I will try to propose some way 
to improve that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-14.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp
  clang/test/CXX/special/class.copy/p33-0x.cpp
  clang/test/SemaCXX/coroutine-rvo.cpp

Index: clang/test/SemaCXX/coroutine-rvo.cpp
===
--- clang/test/SemaCXX/coroutine-rvo.cpp
+++ clang/test/SemaCXX/coroutine-rvo.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only
+// RUN: %clang_cc1 -verify -std=c++17 -fcoroutines-ts -fsyntax-only %s
 
 namespace std::experimental {
 template  struct coroutine_handle {
@@ -39,10 +39,14 @@
 };
 
 struct MoveOnly {
-  MoveOnly() {};
+  MoveOnly() = default;
   MoveOnly(const MoveOnly&) = delete;
-  MoveOnly(MoveOnly&&) noexcept {};
-  ~MoveOnly() {};
+  MoveOnly(MoveOnly &&) = default;
+};
+
+struct NoCopyNoMove {
+  NoCopyNoMove() = default;
+  NoCopyNoMove(const NoCopyNoMove &) = delete;
 };
 
 template 
@@ -52,18 +56,93 @@
 auto final_suspend() noexcept { return suspend_never{}; }
 auto get_return_object() { return task{}; }
 static void unhandled_exception() {}
-void return_value(T&& value) {}
+void return_value(T &) {} // expected-note 4{{passing argument}}
   };
 };
 
-task f() {
-  MoveOnly value;
+task local2val() {
+  NoCopyNoMove value;
+  co_return value;
+}
+
+task local2ref() {
+  NoCopyNoMove value;
+  co_return value; // expected-error {{non-const lvalue reference to type 'NoCopyNoMove' cannot bind to a temporary of type 'NoCopyNoMove'}}
+}
+
+// We need the move constructor for construction of the coroutine.
+task param2val(MoveOnly value) {
   co_return value;
 }
 
-int main() {
-  f();
-  return 0;
+task lvalue2val(NoCopyNoMove ) {
+  co_return value; // expected-error {{rvalue reference to type 'NoCopyNoMove' cannot bind to lvalue of type 'NoCopyNoMove'}}
+}
+
+task rvalue2val(NoCopyNoMove &) {
+  co_return value;
+}
+
+task lvalue2ref(NoCopyNoMove ) {
+  co_return value;
+}
+
+task rvalue2ref(NoCopyNoMove &) {
+  co_return value; // expected-error {{non-const lvalue reference to type 'NoCopyNoMove' cannot bind to a temporary of type 'NoCopyNoMove'}}
+}
+
+struct To {
+  operator MoveOnly() &&;
+};
+task conversion_operator() {
+  To t;
+  co_return t;
+}
+
+struct Construct {
+  Construct(MoveOnly);
+};
+task converting_constructor() {
+  MoveOnly w;
+  co_return w;
 }
 
-// expected-no-diagnostics
+struct Derived : MoveOnly {};
+task derived2base() {
+  Derived result;
+  co_return result;
+}
+
+struct RetThis {
+  task foo() && {
+co_return *this; // expected-error {{rvalue reference to type 'RetThis' cannot bind to lvalue of type 'RetThis'}}
+  }
+};
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+template 
+struct template_return_task {
+  struct promise_type {
+auto initial_suspend() { return suspend_never{}; }
+auto 

[PATCH] D97699: [analyzer] Add InvalidPtrChecker

2021-03-21 Thread Zurab Tsinadze via Phabricator via cfe-commits
zukatsinadze added inline comments.



Comment at: clang/docs/analyzer/checkers.rst:2103-2104
+puts(envp[i]);
+// envp may no longer point to the current environment
+// this program has unanticipated behavior.
+  }

zukatsinadze wrote:
> Charusso wrote:
> > NoQ wrote:
> > > It's very important to explain whether the "unanticipated behavior" is an 
> > > entirely psychological concept ("most people don't understand how this 
> > > works but this can occasionally also be a valid solution if you know what 
> > > you're doing") or a 100% clear indication of a bug ("such code can never 
> > > be correct", eg. it instantly causes undefined behavior, or the written 
> > > value can never be read later so there's absolutely no point in writing 
> > > it, or something like that).
> > The standard terminology is very vague, like that:
> > ```
> > The getenv function returns a pointer to a string associated with the 
> > matched list member. The string pointed to shall not be modified by the 
> > program but may be overwritten by a subsequent call to the getenv function.
> > ```
> > What the hell.   I think it is about table-doubling and reallocating the 
> > entire environment pointer table at some point which makes sense in case of 
> > the non-getter function calls. For the getters I think another processes 
> > could overwrite the `environ` pointer between two getter calls and problem 
> > could occur because of such table-doubling. To resolve the issue we need to 
> > call `strdup()` and create a copy of the current environment entry instead 
> > of having a pointer to it as I see.
> > 
> > @zukatsinadze it would be great to see a real reference with real issues in 
> > real world software. Is the true evil the multiple chained getter calls?
> > 
> > it would be great to see a real reference with real issues in real world 
> > software
> 
> I've attached some results up in the thread. Checker gave several valuable 
> reports on several projects if that's what you mean.
> 
> >  Is the true evil the multiple chained getter calls?
> 
> Besides SEI CERT, there are many other reputable resources stating the same 
> problem with getenv.
> 
> https://www.ibm.com/support/knowledgecenter/SSLTBW_2.2.0/com.ibm.zos.v2r2.bpxbd00/getenv.htm
> https://www.keil.com/support/man/docs/armlib/armlib_chr1359122850667.htm
> https://pubs.opengroup.org/onlinepubs/009696799/functions/getenv.html
> https://pubs.opengroup.org/onlinepubs/7908799/xsh/getenv.html
> https://www.gnu.org/software/libc/manual/html_node/Environment-Access.html
> https://man7.org/linux/man-pages/man3/getenv.3p.html
Actual problem is that getenv is returning a pointer to its internal static 
buffer instead of giving pointer to environ, that's why the string will change 
with a subsequent call.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97699

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


[clang] 74933ef - [Driver] Detect Debian hack g++-multiarch-incdir.diff to simplify addLibStdCXXIncludePaths call sites

2021-03-21 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-03-21T17:33:31-07:00
New Revision: 74933efeb6ba78804602d62954618ab1836d7df8

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

LOG: [Driver] Detect Debian hack g++-multiarch-incdir.diff to simplify 
addLibStdCXXIncludePaths call sites

Added: 


Modified: 
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Gnu.h
clang/lib/Driver/ToolChains/Haiku.cpp
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/lib/Driver/ToolChains/Linux.cpp
clang/lib/Driver/ToolChains/Myriad.cpp
clang/lib/Driver/ToolChains/NetBSD.cpp
clang/lib/Driver/ToolChains/RISCVToolchain.cpp
clang/lib/Driver/ToolChains/Solaris.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index d59bb6f8c3b0..c508af655ac2 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -409,8 +409,8 @@ void FreeBSD::addLibCxxIncludePaths(const 
llvm::opt::ArgList ,
 void FreeBSD::addLibStdCxxIncludePaths(
 const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const {
-  addLibStdCXXIncludePaths(getDriver().SysRoot, "/usr/include/c++/4.2", "", "",
-   "", "", DriverArgs, CC1Args);
+  addLibStdCXXIncludePaths(getDriver().SysRoot + "/usr/include/c++/4.2", "", 
"",
+   DriverArgs, CC1Args);
 }
 
 void FreeBSD::AddCXXStdlibLibArgs(const ArgList ,

diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 426ab8c4aad4..c554047beac3 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2945,51 +2945,44 @@ Generic_GCC::addLibCxxIncludePaths(const 
llvm::opt::ArgList ,
 return;
 }
 
-bool Generic_GCC::addLibStdCXXIncludePaths(
-Twine IncludeDir, StringRef Triple, Twine IncludeSuffix,
-const llvm::opt::ArgList ,
-llvm::opt::ArgStringList ) const {
+bool Generic_GCC::addLibStdCXXIncludePaths(Twine IncludeDir, StringRef Triple,
+   Twine IncludeSuffix,
+   const llvm::opt::ArgList 
,
+   llvm::opt::ArgStringList ,
+   bool DetectDebian) const {
   if (!getVFS().exists(IncludeDir))
 return false;
 
   // GPLUSPLUS_INCLUDE_DIR
   addSystemInclude(DriverArgs, CC1Args, IncludeDir);
-  // GPLUSPLUS_TOOL_INCLUDE_DIR
-  addSystemInclude(DriverArgs, CC1Args,
-   IncludeDir + "/" + Triple + IncludeSuffix);
+  // GPLUSPLUS_TOOL_INCLUDE_DIR. If Triple is not empty, add a target-dependent
+  // include directory.
+  if (!Triple.empty()) {
+if (DetectDebian) {
+  // Debian native gcc has an awful patch g++-multiarch-incdir.
diff  which
+  // uses include/x86_64-linux-gnu/c++/10$IncludeSuffix instead of
+  // include/c++/10/x86_64-linux-gnu$IncludeSuffix.
+  std::string Dir = IncludeDir.str();
+  StringRef Include =
+  llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir));
+  std::string Path =
+  (Include + "/" + Triple + Dir.substr(Include.size()) + IncludeSuffix)
+  .str();
+  if (getVFS().exists(Path))
+addSystemInclude(DriverArgs, CC1Args, Path);
+  else
+addSystemInclude(DriverArgs, CC1Args,
+ IncludeDir + "/" + Triple + IncludeSuffix);
+} else {
+  addSystemInclude(DriverArgs, CC1Args,
+   IncludeDir + "/" + Triple + IncludeSuffix);
+}
+  }
   // GPLUSPLUS_BACKWARD_INCLUDE_DIR
   addSystemInclude(DriverArgs, CC1Args, IncludeDir + "/backward");
   return true;
 }
 
-/// Helper to add the variant paths of a libstdc++ installation.
-bool Generic_GCC::addLibStdCXXIncludePaths(
-Twine Base, Twine Suffix, StringRef GCCTriple, StringRef 
GCCMultiarchTriple,
-StringRef TargetMultiarchTriple, Twine IncludeSuffix,
-const ArgList , ArgStringList ) const {
-  if (!getVFS().exists(Base + Suffix))
-return false;
-
-  addSystemInclude(DriverArgs, CC1Args, Base + Suffix);
-
-  // The vanilla GCC layout of libstdc++ headers uses a triple subdirectory. If
-  // that path exists or we have neither a GCC nor target multiarch triple, use
-  // this vanilla search path.
-  if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) ||
-  getVFS().exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) {
-addSystemInclude(DriverArgs, CC1Args,
- Base + Suffix + "/" + GCCTriple + IncludeSuffix);
-  } else {
-// Otherwise try to use multiarch naming schemes which have normalized the
-// triples and put the triple before the suffix.
- 

[PATCH] D99031: [clang-format] Fix CompactNamespaces corner case when AllowShortLambdasOnASingleLine/BraceWrapping.BeforeLambdaBody are set

2021-03-21 Thread Ahmed Mahdy via Phabricator via cfe-commits
aybassiouny added a comment.

> How about verifyFormat? Would that fail without your patch?

@HazardyKnusperkeks sorry, but not sure that I understand your point. Are you 
suggesting to use verifyFormat in my UT instead of EXPECT_EQ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99031

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


[PATCH] D97699: [analyzer] Add InvalidPtrChecker

2021-03-21 Thread Zurab Tsinadze via Phabricator via cfe-commits
zukatsinadze added inline comments.



Comment at: clang/docs/analyzer/checkers.rst:2103-2104
+puts(envp[i]);
+// envp may no longer point to the current environment
+// this program has unanticipated behavior.
+  }

Charusso wrote:
> NoQ wrote:
> > It's very important to explain whether the "unanticipated behavior" is an 
> > entirely psychological concept ("most people don't understand how this 
> > works but this can occasionally also be a valid solution if you know what 
> > you're doing") or a 100% clear indication of a bug ("such code can never be 
> > correct", eg. it instantly causes undefined behavior, or the written value 
> > can never be read later so there's absolutely no point in writing it, or 
> > something like that).
> The standard terminology is very vague, like that:
> ```
> The getenv function returns a pointer to a string associated with the matched 
> list member. The string pointed to shall not be modified by the program but 
> may be overwritten by a subsequent call to the getenv function.
> ```
> What the hell.   I think it is about table-doubling and reallocating the 
> entire environment pointer table at some point which makes sense in case of 
> the non-getter function calls. For the getters I think another processes 
> could overwrite the `environ` pointer between two getter calls and problem 
> could occur because of such table-doubling. To resolve the issue we need to 
> call `strdup()` and create a copy of the current environment entry instead of 
> having a pointer to it as I see.
> 
> @zukatsinadze it would be great to see a real reference with real issues in 
> real world software. Is the true evil the multiple chained getter calls?
> 
> it would be great to see a real reference with real issues in real world 
> software

I've attached some results up in the thread. Checker gave several valuable 
reports on several projects if that's what you mean.

>  Is the true evil the multiple chained getter calls?

Besides SEI CERT, there are many other reputable resources stating the same 
problem with getenv.

https://www.ibm.com/support/knowledgecenter/SSLTBW_2.2.0/com.ibm.zos.v2r2.bpxbd00/getenv.htm
https://www.keil.com/support/man/docs/armlib/armlib_chr1359122850667.htm
https://pubs.opengroup.org/onlinepubs/009696799/functions/getenv.html
https://pubs.opengroup.org/onlinepubs/7908799/xsh/getenv.html
https://www.gnu.org/software/libc/manual/html_node/Environment-Access.html
https://man7.org/linux/man-pages/man3/getenv.3p.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97699

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


[PATCH] D69218: [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level)

2021-03-21 Thread Nathan James via Phabricator via cfe-commits
njames93 requested changes to this revision.
njames93 added inline comments.
This revision now requires changes to proceed.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:3812-3821
 AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
 hasType,
 AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, TypedefNameDecl,
-ValueDecl),
+ValueDecl, CXXBaseSpecifier),
 internal::Matcher, InnerMatcher, 0) {
   QualType QT = internal::getUnderlyingType(Node);
   if (!QT.isNull())

I don't think the change to this matcher is warranted.
The `hasType` matcher that accepts a DeclarationMatcher already has support for 
cxxBaseSpecifier.
However overloading the matcher that takes a QualType matcher doesn't make 
sense as base specifiers have no qualifications.


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

https://reviews.llvm.org/D69218

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


[PATCH] D99005: [clang] WIP: Implement P2266

2021-03-21 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D99005#2640415 , @mizvekov wrote:

> We should expect the test above to work, by binding value to the rvalue 
> reference in task's promise, right?

Precisely, we don't want to do any initialization at all. (There will be an 
initialization for the parameters in `BuildCallExpr`.)

Implicit move just means that we're converting the lvalue to an xvalue.

On second thought, since @Quuxplusone's proposal makes things so simple you can 
just do this right yourself: instead of the initialization just do the cast, as 
D68845  does it. That's it.

Then let's see what we can get for C++20. If the proposal is accepted and gets 
DR status for `co_return` we might not need my change at all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

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


[PATCH] D99005: [clang] WIP: Implement P2266

2021-03-21 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D99005#2640121 , @aaronpuchert 
wrote:

> With my previous comment I meant that it's better if you leave out the 
> `co_return` bits for now because it's wrong anyway. We can't use 
> `PerformMoveOrCopyInitialization`. It would just generate merge conflicts.

Okay, I think I see now what you mean.
For example this:

  struct task { 
struct promise_type {
  ...
  void return_value(T &) {}
};  
  };
  task local2val() {
NoCopyNoMove value;
co_return value;
   }

We should expect the test above to work, by binding value to the rvalue 
reference in task's promise, right?
Hmm, my natural course of action here would have been to figure out what is 
wrong and fix it.
I thought this would be good to have implemented before the committee decides 
on it.
@Quuxplusone thoughts? Is coroutine support optional here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

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


[clang] 6a4fbf1 - [test] Add test for cross compiling on Linux

2021-03-21 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-03-21T15:37:35-07:00
New Revision: 6a4fbf14ef1027be79703c0ca415eaedd4e1c7c7

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

LOG: [test] Add test for cross compiling on Linux

Added: 
clang/test/Driver/Inputs/debian_multiarch_tree/lib/aarch64-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib/i386-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib/x86_64-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib32/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib64/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/include/c++/10/aarch64-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/include/c++/10/backward/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/lib/crt1.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/lib/crti.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/lib/crtn.o
clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/10/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/10/backward/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/x86_64-linux-gnu/c++/10/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/x86_64-linux-gnu/c++/10/32/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/aarch64-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc-cross/aarch64-linux-gnu/10/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc-cross/aarch64-linux-gnu/10/crtbeginT.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc-cross/aarch64-linux-gnu/10/crtend.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/x86_64-linux-gnu/10/32/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/x86_64-linux-gnu/10/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/x86_64-linux-gnu/10/crtend.o
clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/i386-linux-gnu/crt1.o
clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/i386-linux-gnu/crti.o
clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/i386-linux-gnu/crtn.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/x86_64-linux-gnu/crt1.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/x86_64-linux-gnu/crti.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/x86_64-linux-gnu/crtn.o
clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib32/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib64/.keep
clang/test/Driver/linux-cross.cpp

Modified: 


Removed: 




diff  --git 
a/clang/test/Driver/Inputs/debian_multiarch_tree/lib/aarch64-linux-gnu/.keep 
b/clang/test/Driver/Inputs/debian_multiarch_tree/lib/aarch64-linux-gnu/.keep
new file mode 100644
index ..e69de29bb2d1

diff  --git 
a/clang/test/Driver/Inputs/debian_multiarch_tree/lib/i386-linux-gnu/.keep 
b/clang/test/Driver/Inputs/debian_multiarch_tree/lib/i386-linux-gnu/.keep
new file mode 100644
index ..e69de29bb2d1

diff  --git 
a/clang/test/Driver/Inputs/debian_multiarch_tree/lib/x86_64-linux-gnu/.keep 
b/clang/test/Driver/Inputs/debian_multiarch_tree/lib/x86_64-linux-gnu/.keep
new file mode 100644
index ..e69de29bb2d1

diff  --git a/clang/test/Driver/Inputs/debian_multiarch_tree/lib32/.keep 
b/clang/test/Driver/Inputs/debian_multiarch_tree/lib32/.keep
new file mode 100644
index ..e69de29bb2d1

diff  --git a/clang/test/Driver/Inputs/debian_multiarch_tree/lib64/.keep 
b/clang/test/Driver/Inputs/debian_multiarch_tree/lib64/.keep
new file mode 100644
index ..e69de29bb2d1

diff  --git 
a/clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/include/c++/10/aarch64-linux-gnu/.keep
 
b/clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/include/c++/10/aarch64-linux-gnu/.keep
new file mode 100644
index ..e69de29bb2d1

diff  --git 
a/clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/include/c++/10/backward/.keep
 
b/clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/include/c++/10/backward/.keep
new file mode 100644
index ..e69de29bb2d1

diff  --git 
a/clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/lib/crt1.o
 
b/clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/lib/crt1.o
new file mode 100644
index ..e69de29bb2d1

diff  --git 
a/clang/test/Driver/Inputs/debian_multiarch_tree/usr/aarch64-linux-gnu/lib/crti.o
 

[clang] 72ac988 - [test] Delete obsoleted debian_multiarch_tree and ubuntu_13.04_multiarch_tree

2021-03-21 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-03-21T15:37:34-07:00
New Revision: 72ac988dc73a99f4b6647bdf3432134afdc3af43

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

LOG: [test] Delete obsoleted debian_multiarch_tree and 
ubuntu_13.04_multiarch_tree

They are quite outdated. Delete them to avoid unnecessary test churn.

Added: 


Modified: 
clang/test/Driver/linux-header-search.cpp
clang/test/Driver/linux-ld.c

Removed: 
clang/test/Driver/Inputs/debian_multiarch_tree/lib/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib/i386-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib/i386-linux-gnu/libtest.so
clang/test/Driver/Inputs/debian_multiarch_tree/lib/mips-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib/mipsel-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib/powerpc-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib/powerpc64-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/lib/powerpc64le-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib/sparc-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib/sparc64-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/lib/x86_64-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/4.5/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/4.5/backward/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/4.5/i686-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/4.5/mips-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/4.5/mipsel-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/4.5/powerpc-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/4.5/powerpc64-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/4.5/sparc-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/4.5/sparc64-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/c++/4.5/x86_64-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/i386-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/mips-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/mipsel-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/powerpc-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/powerpc64-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/sparc-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/sparc64-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/include/x86_64-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/i686-linux-gnu/4.5/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/mips-linux-gnu/4.5/64/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/mips-linux-gnu/4.5/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/mips-linux-gnu/4.5/n32/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/mipsel-linux-gnu/4.5/64/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/mipsel-linux-gnu/4.5/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/mipsel-linux-gnu/4.5/n32/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/powerpc-linux-gnu/4.5/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/powerpc64-linux-gnu/4.5/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/powerpc64le-linux-gnu/4.5/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/sparc-linux-gnu/4.5/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/sparc64-linux-gnu/4.5/crtbegin.o

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/x86_64-linux-gnu/4.5/crtbegin.o
clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/i386-linux-gnu/.keep
clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/mips-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/mipsel-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/powerpc-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/powerpc64-linux-gnu/.keep

clang/test/Driver/Inputs/debian_multiarch_tree/usr/lib/powerpc64le-linux-gnu/.keep

[PATCH] D97699: [analyzer] Add InvalidPtrChecker

2021-03-21 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D97699#2601804 , @NoQ wrote:

> Why are you even tracking `reg_$0`? It's obvious from the structure of 
> the symbol that it's an environment pointer, there's no need to keep it in 
> maps.

`envp` is confusable with `argv`: `int main(int argc, char *argv[], char 
*envp[])` so we obtain `envp`'s region from `main()` to match it later.




Comment at: clang/docs/analyzer/checkers.rst:2103-2104
+puts(envp[i]);
+// envp may no longer point to the current environment
+// this program has unanticipated behavior.
+  }

NoQ wrote:
> It's very important to explain whether the "unanticipated behavior" is an 
> entirely psychological concept ("most people don't understand how this works 
> but this can occasionally also be a valid solution if you know what you're 
> doing") or a 100% clear indication of a bug ("such code can never be 
> correct", eg. it instantly causes undefined behavior, or the written value 
> can never be read later so there's absolutely no point in writing it, or 
> something like that).
The standard terminology is very vague, like that:
```
The getenv function returns a pointer to a string associated with the matched 
list member. The string pointed to shall not be modified by the program but may 
be overwritten by a subsequent call to the getenv function.
```
What the hell.   I think it is about table-doubling and reallocating the 
entire environment pointer table at some point which makes sense in case of the 
non-getter function calls. For the getters I think another processes could 
overwrite the `environ` pointer between two getter calls and problem could 
occur because of such table-doubling. To resolve the issue we need to call 
`strdup()` and create a copy of the current environment entry instead of having 
a pointer to it as I see.

@zukatsinadze it would be great to see a real reference with real issues in 
real world software. Is the true evil the multiple chained getter calls?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97699

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-03-21 Thread Florian Hahn via Phabricator via cfe-commits
fhahn requested changes to this revision.
fhahn added reviewers: rjmccall, rsmith, erichkeane.
fhahn added a comment.
This revision now requires changes to proceed.

Thanks for the patch! I think this also needs changes in code-gen & code-gen 
tests.




Comment at: clang/include/clang/Sema/Sema.h:11667
+  // CheckMatrixCast - check type constraints for matrices.
+  // We allow casting in between matrices of the same dimensions i.e. when
+  // they have the same number of rows and columns.

nit: casting beween



Comment at: clang/include/clang/Sema/Sema.h:11669
+  // they have the same number of rows and columns.
+  // returns true if the cast is invalid
+  bool CheckMatrixCast(SourceRange R, QualType MatrixTy, QualType Tr,

nit: should be a full sentence and also go in the previous row?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D97107: Replace func name with regex for update test scripts

2021-03-21 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

Looks like this has broken update_analyze_test_checks.py.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97107

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


[PATCH] D99005: [clang] WIP: Implement P2266

2021-03-21 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D99005#2639977 , @Quuxplusone wrote:

> Conspicuously missing: tests for `decltype(auto)` return types, tests for 
> `co_return`.

Though the first comment warns you that this is a work in progress and I just 
didn't get around to doing it yet ;)

Though `decltype` I had tested manually, co_return I have just begun testing at 
all.

I believe the `decltype` tests should go into the other file relevant to the 
pertinent section. One problem with leaving them here is that it would be extra 
noise for the tests for the older standards which don't even support the 
keyword at all.

> Personally I'd rather see these new p2266-related tests go in a separate test 
> file, not appended to the existing file, so as to keep each test file 
> relatively simpler and shorter. (But I don't know that those-in-charge would 
> agree.)

They go into files named after section / paragraph, and I haven't come across 
examples where they were split yet, but I haven't looked specifically for this.

In D99005#2640121 , @aaronpuchert 
wrote:

> With my previous comment I meant that it's better if you leave out the 
> `co_return` bits for now because it's wrong anyway. We can't use 
> `PerformMoveOrCopyInitialization`. It would just generate merge conflicts.

I am using `PerformMoveOrCopyInitialization` with AllowNRVO always false for 
co_return, which effectively makes it a `PerformCopyInitialization` (just 
replacing them instead was one of the WIP cleanups I mentioned).
I am new with this part of the code here, so maybe this is obvious, but why is 
it broken? Do you have any examples of test cases where this would fail?
Would this patch here cause any regressions?
Right now this is passing the test suite, and seems to be reporting the correct 
results for the tests you created for D68845 .
Remember, here we just want to evaluate the solution proposed for P2266 
 by testing this at large, in order to build 
support for it to be accepted into the standard.
Just waiting for it to be accepted first before implementing it would be too 
late :)




Comment at: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp:5
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_14_17_20,cxx11_14_17 %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_14_17_20,cxx11_14_17 %s
 

Quuxplusone wrote:
> These labels seem to be getting unwieldy. I propose that you rename 
> `cxx11_14_17` to `cxx17` and `cxx11_14_17_20` to `cxx17_20`.
> 
> (There are no cases where C++11, '14, '17's behavior differ.)
> 
> So then we'll have `cxx17`, `cxx17_20`, `cxx20`, `cxx20_2b`, and `cxx2b`.
> IMHO it might even be nice to eliminate the overlapping labels; just, when a 
> message is expected in two out of three modes, write two expectations.
> ```
>   B1(B1 &&) = delete;
> // cxx20-note@-1 {{'B1' has been explicitly marked deleted here}}
> // cxx2b-note@-2 {{'B1' has been explicitly marked deleted here}}
> ```
> What do you think? (This could also be severed into its own earlier commit.)
I like the idea of shortening the labels. Duplicating the warnings if it can be 
avoided easily, not so much. DRY is my mantra :D

Though what you said about severing this into an earlier commit, I think 
something may need to be done about it anyway.
So right now the tests are all over the place about which standard they are 
running, and none are testing c++2b at all...
I think we might need to gather input on this. Just changing every test to run 
every standard might be too much, so we could need a less obvious criteria.



Comment at: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp:325
+  MoveOnly&& rr = test_3a(static_cast(w)); // cxx11_14_17_20-note 
{{in instantiation of function template specialization}}
+}
+

Quuxplusone wrote:
> FWIW here I would prefer
> ```
> template MoveOnly& test_3a(MoveOnly&);
> template MoveOnly&& test_3a(MoveOnly&&);
> ```
> with an expected error on the second line. The parameter-ness of `w` seems 
> like a red herring in your version.
Sure, sounds good.



Comment at: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp:335
+  try {
+throw x; // cxx11_14_17_20-error {{call to implicitly-deleted copy 
constructor}}
+  } catch(...) {}

Quuxplusone wrote:
> I believe this is incorrect; `throw x` here shouldn't implicit-move because 
> `x`'s scope exceeds the nearest enclosing try-block.
Err, you are right, my bad, this is an easy fix...



Comment at: clang/test/CXX/special/class.copy/p33-0x.cpp:3
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fsyntax-only 
-verify=expected,cxx11 %s
+// cxx2b-no-diagnostics
 class X {

Quuxplusone wrote:

[clang] be87321 - [clang][Codegen] EmitBranchOnBoolExpr(): emit prof branch counts even at -O0

2021-03-21 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-03-21T23:24:27+03:00
New Revision: be8732128029530a0b8671af3a47ce6085039fa2

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

LOG: [clang][Codegen] EmitBranchOnBoolExpr(): emit prof branch counts even at 
-O0

This restores the original behaviour before i unadvertedly broke it in
e3a470162738871bba982416748ae5f5e3572947 and clang/test/Profile/ caught it.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 1c538262737d..fd708849e609 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1774,27 +1774,27 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr 
*Cond,
   llvm::MDNode *Weights = nullptr;
   llvm::MDNode *Unpredictable = nullptr;
 
-  // If optimizing, lower unpredictability/probability knowledge about cond.
-  if (CGM.getCodeGenOpts().OptimizationLevel != 0) {
-// If the branch has a condition wrapped by __builtin_unpredictable,
-// create metadata that specifies that the branch is unpredictable.
-if (auto *Call = dyn_cast(Cond->IgnoreImpCasts())) {
-  auto *FD = dyn_cast_or_null(Call->getCalleeDecl());
-  if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
-llvm::MDBuilder MDHelper(getLLVMContext());
-Unpredictable = MDHelper.createUnpredictable();
-  }
+  // If the branch has a condition wrapped by __builtin_unpredictable,
+  // create metadata that specifies that the branch is unpredictable.
+  // Don't bother if not optimizing because that metadata would not be used.
+  auto *Call = dyn_cast(Cond->IgnoreImpCasts());
+  if (Call && CGM.getCodeGenOpts().OptimizationLevel != 0) {
+auto *FD = dyn_cast_or_null(Call->getCalleeDecl());
+if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
+  llvm::MDBuilder MDHelper(getLLVMContext());
+  Unpredictable = MDHelper.createUnpredictable();
 }
+  }
 
-// If there is a Likelihood knowledge for the cond, lower it.
-llvm::Value *NewCondV = emitCondLikelihoodViaExpectIntrinsic(CondV, LH);
-if (CondV != NewCondV)
-  CondV = NewCondV;
-else {
-  // Otherwise, lower profile counts.
-  uint64_t CurrentCount = std::max(getCurrentProfileCount(), TrueCount);
-  Weights = createProfileWeights(TrueCount, CurrentCount - TrueCount);
-}
+  // If there is a Likelihood knowledge for the cond, lower it.
+  // Note that if not optimizing this won't emit anything.
+  llvm::Value *NewCondV = emitCondLikelihoodViaExpectIntrinsic(CondV, LH);
+  if (CondV != NewCondV)
+CondV = NewCondV;
+  else {
+// Otherwise, lower profile counts. Note that we do this even at -O0.
+uint64_t CurrentCount = std::max(getCurrentProfileCount(), TrueCount);
+Weights = createProfileWeights(TrueCount, CurrentCount - TrueCount);
   }
 
   Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights, Unpredictable);



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


[PATCH] D69218: [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level)

2021-03-21 Thread Nikita Kniazev via Phabricator via cfe-commits
nick added a comment.

Could you please commit the patch for me? I do not have commit rights.


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

https://reviews.llvm.org/D69218

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


[clang] e3a4701 - [clang][CodeGen] Lower Likelihood attributes to @llvm.expect intrin instead of branch weights

2021-03-21 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-03-21T22:50:21+03:00
New Revision: e3a470162738871bba982416748ae5f5e3572947

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

LOG: [clang][CodeGen] Lower Likelihood attributes to @llvm.expect intrin 
instead of branch weights

08196e0b2e1f8aaa8a854585335c17ba479114df exposed LowerExpectIntrinsic's
internal implementation detail in the form of
LikelyBranchWeight/UnlikelyBranchWeight options to the outside.

While this isn't incorrect from the results viewpoint,
this is suboptimal from the layering viewpoint,
and causes confusion - should transforms also use those weights,
or should they use something else, D98898?

So go back to status quo by making LikelyBranchWeight/UnlikelyBranchWeight
internal again, and fixing all the code that used it directly,
which currently is only clang codegen, thankfully,
to emit proper @llvm.expect intrinsics instead.

Added: 


Modified: 
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp
clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 38f3aa941415e..fb719efb1a35d 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -821,8 +821,11 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt ,
 llvm::BasicBlock *ExitBlock = LoopExit.getBlock();
 if (ConditionScope.requiresCleanups())
   ExitBlock = createBasicBlock("while.exit");
-llvm::MDNode *Weights = createProfileOrBranchWeightsForLoop(
-S.getCond(), getProfileCount(S.getBody()), S.getBody());
+llvm::MDNode *Weights =
+createProfileWeightsForLoop(S.getCond(), getProfileCount(S.getBody()));
+if (!Weights && CGM.getCodeGenOpts().OptimizationLevel)
+  BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
+  BoolCondVal, Stmt::getLikelihood(S.getBody()));
 Builder.CreateCondBr(BoolCondVal, LoopBody, ExitBlock, Weights);
 
 if (ExitBlock != LoopExit.getBlock()) {
@@ -1008,8 +1011,11 @@ void CodeGenFunction::EmitForStmt(const ForStmt ,
 // C99 6.8.5p2/p4: The first substatement is executed if the expression
 // compares unequal to 0.  The condition must be a scalar type.
 llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
-llvm::MDNode *Weights = createProfileOrBranchWeightsForLoop(
-S.getCond(), getProfileCount(S.getBody()), S.getBody());
+llvm::MDNode *Weights =
+createProfileWeightsForLoop(S.getCond(), getProfileCount(S.getBody()));
+if (!Weights && CGM.getCodeGenOpts().OptimizationLevel)
+  BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
+  BoolCondVal, Stmt::getLikelihood(S.getBody()));
 
 if (llvm::ConstantInt *C = dyn_cast(BoolCondVal))
   if (C->isOne())
@@ -1094,8 +1100,11 @@ CodeGenFunction::EmitCXXForRangeStmt(const 
CXXForRangeStmt ,
   // The body is executed if the expression, contextually converted
   // to bool, is true.
   llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
-  llvm::MDNode *Weights = createProfileOrBranchWeightsForLoop(
-  S.getCond(), getProfileCount(S.getBody()), S.getBody());
+  llvm::MDNode *Weights =
+  createProfileWeightsForLoop(S.getCond(), getProfileCount(S.getBody()));
+  if (!Weights && CGM.getCodeGenOpts().OptimizationLevel)
+BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
+BoolCondVal, Stmt::getLikelihood(S.getBody()));
   Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights);
 
   if (ExitBlock != LoopExit.getBlock()) {
@@ -1369,7 +1378,7 @@ void CodeGenFunction::EmitCaseStmtRange(const CaseStmt ,
 // this case.
 (*SwitchWeights)[0] += ThisCount;
   } else if (SwitchLikelihood)
-Weights = createBranchWeights(LH);
+Cond = emitCondLikelihoodViaExpectIntrinsic(Cond, LH);
 
   Builder.CreateCondBr(Cond, CaseDest, FalseDest, Weights);
 

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index a00ae74fa165f..1c538262737dd 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1764,31 +1764,39 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr 
*Cond,
 return;
   }
 
-  // If the branch has a condition wrapped by __builtin_unpredictable,
-  // create metadata that specifies that the branch is unpredictable.
-  // Don't bother if not optimizing because that metadata would not be used.
-  llvm::MDNode *Unpredictable = nullptr;
-  auto *Call = dyn_cast(Cond->IgnoreImpCasts());
-  if 

[clang] 37d6be9 - Revert "[BranchProbability] move options for 'likely' and 'unlikely'"

2021-03-21 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-03-21T22:50:21+03:00
New Revision: 37d6be90524ca1659521ab879aaae5e5501f1e97

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

LOG: Revert "[BranchProbability] move options for 'likely' and 'unlikely'"

Upon reviewing D98898 i've come to realization that these are
implementation detail of LowerExpectIntrinsicPass,
and they should not be exposed to outside of it.

This reverts commit ee8b53815ddf6f6f94ade0068903cd5ae843fafa.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.cpp
llvm/include/llvm/Support/BranchProbability.h
llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
llvm/lib/Support/BranchProbability.cpp
llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 18927b46958c8..a00ae74fa165f 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -42,8 +42,8 @@
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Operator.h"
-#include "llvm/Support/BranchProbability.h"
 #include "llvm/Support/CRC.h"
+#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
 #include "llvm/Transforms/Utils/PromoteMemToReg.h"
 using namespace clang;
 using namespace CodeGen;

diff  --git a/llvm/include/llvm/Support/BranchProbability.h 
b/llvm/include/llvm/Support/BranchProbability.h
index f977c70221a5d..6c7ad1fe2a52c 100644
--- a/llvm/include/llvm/Support/BranchProbability.h
+++ b/llvm/include/llvm/Support/BranchProbability.h
@@ -13,7 +13,6 @@
 #ifndef LLVM_SUPPORT_BRANCHPROBABILITY_H
 #define LLVM_SUPPORT_BRANCHPROBABILITY_H
 
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/DataTypes.h"
 #include 
 #include 
@@ -22,9 +21,6 @@
 
 namespace llvm {
 
-extern cl::opt LikelyBranchWeight;
-extern cl::opt UnlikelyBranchWeight;
-
 class raw_ostream;
 
 // This class represents Branch Probability as a non-negative fraction that is

diff  --git a/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h 
b/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
index 4e47ff70d5574..22b2e649e4d48 100644
--- a/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
+++ b/llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h
@@ -17,6 +17,7 @@
 
 #include "llvm/IR/Function.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/Support/CommandLine.h"
 
 namespace llvm {
 
@@ -31,6 +32,8 @@ struct LowerExpectIntrinsicPass : 
PassInfoMixin {
   PreservedAnalyses run(Function , FunctionAnalysisManager &);
 };
 
+extern cl::opt LikelyBranchWeight;
+extern cl::opt UnlikelyBranchWeight;
 }
 
 #endif

diff  --git a/llvm/lib/Support/BranchProbability.cpp 
b/llvm/lib/Support/BranchProbability.cpp
index d93d9cffb9f73..60d5478a90529 100644
--- a/llvm/lib/Support/BranchProbability.cpp
+++ b/llvm/lib/Support/BranchProbability.cpp
@@ -19,20 +19,6 @@
 
 using namespace llvm;
 
-// These default values are chosen to represent an extremely skewed outcome for
-// a condition, but they leave some room for interpretation by later passes.
-//
-// If the documentation for __builtin_expect() was made explicit that it should
-// only be used in extreme cases, we could make this ratio higher. As it 
stands,
-// programmers may be using __builtin_expect() / llvm.expect to annotate that a
-// branch is only mildly likely or unlikely to be taken.
-cl::opt llvm::LikelyBranchWeight(
-"likely-branch-weight", cl::Hidden, cl::init(2000),
-cl::desc("Weight of the branch likely to be taken (default = 2000)"));
-cl::opt llvm::UnlikelyBranchWeight(
-"unlikely-branch-weight", cl::Hidden, cl::init(1),
-cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
-
 constexpr uint32_t BranchProbability::D;
 
 raw_ostream ::print(raw_ostream ) const {

diff  --git a/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp 
b/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
index d862fcfe8ce56..da13075dfee26 100644
--- a/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
@@ -24,7 +24,6 @@
 #include "llvm/IR/Metadata.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
-#include "llvm/Support/BranchProbability.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Transforms/Scalar.h"
 
@@ -35,6 +34,25 @@ using namespace llvm;
 STATISTIC(ExpectIntrinsicsHandled,
   "Number of 'expect' intrinsic instructions handled");
 
+// These default values are chosen to represent an extremely skewed outcome for
+// a condition, but they leave some room for interpretation by later passes.
+//
+// If the documentation for __builtin_expect() was made explicit that it should
+// only be used in extreme 

[clang] bcaca36 - [Driver] Gnu.cpp: fix libstdc++ search path for multilib

2021-03-21 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-03-21T12:01:44-07:00
New Revision: bcaca360f8b64d267c787a5f3088e73420e78f53

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

LOG: [Driver] Gnu.cpp: fix libstdc++ search path for multilib

With this change, on Debian x86-64 (with a MULTILIB_OSDIRNAMES local patch
../lib64 -> ../lib; this does not matter because /usr/lib64/crt{1,i,n}.o do not 
exist),
`clang++ --target=aarch64-linux-gnu a.cc 
-Wl,--dynamic-linker=/usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 
-Wl,-rpath,/usr/aarch64-linux-gnu/lib`
built executable can run under qemu-user. Previously this failed with
`/usr/lib/gcc-cross/aarch64-linux-gnu/10/../../../../include/c++/10/iostream:38:10:
 fatal error: 'bits/c++config.h' file not found`

On Arch Linux, due to the MULTILIB_OSDIRNAMES patch and the existence of
/usr/lib64/crt{1,i,n}.o, clang driver may pick
/usr/lib64/crt{1,i,n}.o and cause a linker error. -B can work around the 
problem.
`clang++ --target=aarch64-linux-gnu -B /usr/aarch64-linux-gnu/lib a.cc 
-Wl,--dynamic-linker=/usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 
-Wl,-rpath,/usr/aarch64-linux-gnu/lib64:/usr/aarch64-linux-gnu/lib`

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Gnu.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index b5efa587f8dc..426ab8c4aad4 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2945,6 +2945,23 @@ Generic_GCC::addLibCxxIncludePaths(const 
llvm::opt::ArgList ,
 return;
 }
 
+bool Generic_GCC::addLibStdCXXIncludePaths(
+Twine IncludeDir, StringRef Triple, Twine IncludeSuffix,
+const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ) const {
+  if (!getVFS().exists(IncludeDir))
+return false;
+
+  // GPLUSPLUS_INCLUDE_DIR
+  addSystemInclude(DriverArgs, CC1Args, IncludeDir);
+  // GPLUSPLUS_TOOL_INCLUDE_DIR
+  addSystemInclude(DriverArgs, CC1Args,
+   IncludeDir + "/" + Triple + IncludeSuffix);
+  // GPLUSPLUS_BACKWARD_INCLUDE_DIR
+  addSystemInclude(DriverArgs, CC1Args, IncludeDir + "/backward");
+  return true;
+}
+
 /// Helper to add the variant paths of a libstdc++ installation.
 bool Generic_GCC::addLibStdCXXIncludePaths(
 Twine Base, Twine Suffix, StringRef GCCTriple, StringRef 
GCCMultiarchTriple,
@@ -2965,13 +2982,8 @@ bool Generic_GCC::addLibStdCXXIncludePaths(
   } else {
 // Otherwise try to use multiarch naming schemes which have normalized the
 // triples and put the triple before the suffix.
-//
-// GCC surprisingly uses *both* the GCC triple with a multilib suffix and
-// the target triple, so we support that here.
 addSystemInclude(DriverArgs, CC1Args,
  Base + "/" + GCCMultiarchTriple + Suffix + IncludeSuffix);
-addSystemInclude(DriverArgs, CC1Args,
- Base + "/" + TargetMultiarchTriple + Suffix);
   }
 
   addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward");
@@ -2992,16 +3004,23 @@ Generic_GCC::addGCCLibStdCxxIncludePaths(const 
llvm::opt::ArgList ,
   StringRef InstallDir = GCCInstallation.getInstallPath();
   StringRef TripleStr = GCCInstallation.getTriple().str();
   const Multilib  = GCCInstallation.getMultilib();
-  const std::string GCCMultiarchTriple = getMultiarchTriple(
+  const std::string Triple = getMultiarchTriple(
   getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot);
   const std::string TargetMultiarchTriple =
   getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
   const GCCVersion  = GCCInstallation.getVersion();
 
   // The primary search for libstdc++ supports multiarch variants.
+  if (addLibStdCXXIncludePaths(
+  LibDir.str() + "/../" + Triple + "/include/c++/" + Version.Text,
+  TripleStr, Multilib.includeSuffix(), DriverArgs, CC1Args))
+return true;
+
+  // Debian host g++ needs this for
+  // 
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/{c++/10,x86_64-linux-gnu/c++/10,c++/10/backward}
+  // FIXME Some other toolchains incorrectly rely on this hierarchy.
   if (addLibStdCXXIncludePaths(LibDir.str() + "/../include",
-   "/c++/" + Version.Text, TripleStr,
-   GCCMultiarchTriple, TargetMultiarchTriple,
+   "/c++/" + Version.Text, TripleStr, Triple, "",
Multilib.includeSuffix(), DriverArgs, CC1Args))
 return true;
 

diff  --git a/clang/lib/Driver/ToolChains/Gnu.h 
b/clang/lib/Driver/ToolChains/Gnu.h
index 90d3bafc1f00..aa03c6ed6a05 100644
--- a/clang/lib/Driver/ToolChains/Gnu.h
+++ b/clang/lib/Driver/ToolChains/Gnu.h
@@ -351,6 +351,12 @@ class 

[PATCH] D98638: [RFC][Coroutine] Force stack allocation after await_suspend() call

2021-03-21 Thread Xun Li via Phabricator via cfe-commits
lxfind added a comment.

@bruno  Thanks for the review!




Comment at: clang/lib/CodeGen/CGCoroutine.cpp:221
 CGF.EmitBlock(RealSuspendBlock);
+  } else if (ForcestackStart) {
+Builder.CreateCall(

bruno wrote:
> ChuanqiXu wrote:
> > lxfind wrote:
> > > ChuanqiXu wrote:
> > > > ChuanqiXu wrote:
> > > > > can we rewrite it into:
> > > > > ```
> > > > > else if (SuspendRet != nullptr && 
> > > > > SuspendRet->getType()->isClassType()) {
> > > > >  // generate:
> > > > >  // llvm.coro.forcestack(SuspendRet)
> > > > > }
> > > > > ```
> > > > Sorry I find we can't did it directly. As you said, we need to traverse 
> > > > down SuspendRet. And I still think we should did it only at CodeGen 
> > > > part since it looks not so hard. I guess we could make it in above 
> > > > 10~15 lines of codes.
> > > Traversing down AST isn't the hard part. The hard part is to search the 
> > > emitted IR, and look for the temporary alloca used to store the returned 
> > > handle.
> > Yes, I get your point. If we want to traverse the emitted IR, we could only 
> > search for the use-chain backward, which is also very odd. Let's see if 
> > there is other ways to modify the ASTNodes to make it more naturally.
> I'm curious whether did you consider annotating instructions with some new 
> custom metadata instead of using intrinsics? If so, what would be the 
> tradeoff? For example, if you could conditionally attach metadata some 
> "begin" metadata here:
> 
> `auto *SaveCall = Builder.CreateCall(CoroSave, {NullPtr});`
> 
> and "end" metadata here:
> 
> `auto *SuspendResult = Builder.CreateCall(CoroSuspend, {SaveCall, 
> Builder.getInt1(IsFinalSuspend)});`
The "end" part could probably be done through metadata. But I'm not sure how to 
do it for the "begin" part. The "begin" part needs to happen after the emission 
of S.getAwaitSuspendCallExpr().



Comment at: llvm/lib/Transforms/Coroutines/CoroFrame.cpp:2085
+if (auto *II = dyn_cast())
+  if (II->getIntrinsicID() == llvm::Intrinsic::coro_forcestack_begin) {
+assert(II->getNumUses() == 1 &&

bruno wrote:
> Do such intrinsics never get removed? What happens when this hits a backend?
They are added to the list of DeadInstructions after collected. So they will 
all be removed at the end of the pass.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98638

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


[PATCH] D55212: Handle alloc_size attribute on function pointers

2021-03-21 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.
Herald added a subscriber: jdoerfert.

I completely forgot about this patch. @aaron.ballman are you still happy for me 
to commit this?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55212

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-03-21 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha created this revision.
SaurabhJha added a reviewer: fhahn.
Herald added a subscriber: tschuett.
SaurabhJha requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

[Matrix] Implement explicit type conversions for MatrixType.
Bugzilla ticket is here: https://bugs.llvm.org/show_bug.cgi?id=47141


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/matrix-cast.c
  clang/test/SemaCXX/matrix-casts.cpp

Index: clang/test/SemaCXX/matrix-casts.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/matrix-casts.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -std=c++11 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+
+  (void)reinterpret_cast(m1);
+  (void)(ix4x4) m1;
+  (void)reinterpret_cast(m2);
+  (void)(sx4x4) m1;
+  (void)reinterpret_cast(m3); // expected-error {{reinterpret_cast from matrix 'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') to matrix 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') of different size}}
+  (void)(ix5x5) m3;  // expected-error {{-style cast from matrix 'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') to matrix 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') of different size}}
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_10x10 __attribute__((matrix_type(10, 10)));
+
+void f2() {
+  float2_8x8 m1;
+  double_8x8 m2;
+  signed_int_12x12 m3;
+  unsigned_int_12x12 m4;
+
+  (void)reinterpret_cast(m1); // expected-error {{reinterpret_cast from matrix 'float2_8x8' (aka 'float __attribute__((matrix_type(8, 8)))') to matrix 'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') of different size}}
+  (void)(double_10x10) m1;  // expected-error {{C-style cast from matrix 'float2_8x8' (aka 'float __attribute__((matrix_type(8, 8)))') to matrix 'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') of different size}}
+  (void)reinterpret_cast(m2);
+  (void)(float2_8x8) m2;
+  (void)reinterpret_cast(m3);
+  (void)(unsigned_int_12x12) m3;
+  (void)reinterpret_cast(m4);
+  (void)(signed_int_12x12) m4;
+  (void)reinterpret_cast(m3); // expected-error {{reinterpret_cast from matrix 'signed_int_12x12' (aka 'int __attribute__((matrix_type(12, 12)))') to matrix 'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') of different size}}
+  (void)(unsigned_int_10x10) m3;  // expected-error {{C-style cast from matrix 'signed_int_12x12' (aka 'int __attribute__((matrix_type(12, 12)))') to matrix 'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') of different size}}
+}
\ No newline at end of file
Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+
+  m2 = (ix4x4)m1;
+  m3 = (sx4x4)m2;
+  m4 = (ix5x5)m3; // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and 'sx4x4' \
+(aka 'short __attribute__((matrix_type(4, 4)))') of different size}}
+  m5 = (ix5x5)m4; // expected-error {{assigning to 'fx5x5' (aka \
+'float __attribute__((matrix_type(5, 5)))') from incompatible type 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))')}}
+  m4 = (ix5x5)m5;
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 

[PATCH] D99031: [clang-format] Fix CompactNamespaces corner case when AllowShortLambdasOnASingleLine/BraceWrapping.BeforeLambdaBody are set

2021-03-21 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.

Looks good. How about `verifyFormat`? Would that fail without your patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99031

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


[PATCH] D99031: [clang-format] Fix CompactNamespaces corner case when AllowShortLambdasOnASingleLine/BraceWrapping.BeforeLambdaBody are set

2021-03-21 Thread Francois JEAN via Phabricator via cfe-commits
Wawha accepted this revision.
Wawha added a comment.
This revision is now accepted and ready to land.

Thank you for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99031

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


[PATCH] D98775: [AST] Add introspection support for Decls

2021-03-21 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 332160.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98775

Files:
  clang/include/clang/Tooling/NodeIntrospection.h
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
  clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
  clang/unittests/Introspection/IntrospectionTest.cpp

Index: clang/unittests/Introspection/IntrospectionTest.cpp
===
--- clang/unittests/Introspection/IntrospectionTest.cpp
+++ clang/unittests/Introspection/IntrospectionTest.cpp
@@ -42,7 +42,7 @@
 
 #define STRING_LOCATION_PAIR(INSTANCE, LOC) Pair(#LOC, INSTANCE->LOC)
 
-TEST(Introspection, SourceLocations) {
+TEST(Introspection, SourceLocations_Stmt) {
   auto AST = buildASTFromCode("void foo() {} void bar() { foo(); }", "foo.cpp",
   std::make_shared());
   auto  = AST->getASTContext();
@@ -79,3 +79,69 @@
   EXPECT_THAT(ExpectedRanges, UnorderedElementsAre(STRING_LOCATION_PAIR(
   FooCall, getSourceRange(;
 }
+
+TEST(Introspection, SourceLocations_Decl) {
+  auto AST =
+  buildASTFromCode(R"cpp(
+namespace ns1 {
+namespace ns2 {
+template  struct Foo {};
+template  struct Bar {
+  struct Nested {
+template 
+Foo method(int i, bool b) const noexcept(true);
+  };
+};
+} // namespace ns2
+} // namespace ns1
+
+template 
+template 
+ns1::ns2::Foo ns1::ns2::Bar::Nested::method(int i, bool b) const
+noexcept(true) {}
+)cpp",
+   "foo.cpp", std::make_shared());
+  auto  = AST->getASTContext();
+  auto  = *Ctx.getTranslationUnitDecl();
+
+  auto BoundNodes = ast_matchers::match(
+  decl(hasDescendant(
+  cxxMethodDecl(hasName("method"), isDefinition()).bind("method"))),
+  TU, Ctx);
+
+  EXPECT_EQ(BoundNodes.size(), 1u);
+
+  const auto *MethodDecl = BoundNodes[0].getNodeAs("method");
+
+  auto Result = NodeIntrospection::GetLocations(MethodDecl);
+
+  if (Result.LocationAccessors.empty() && Result.RangeAccessors.empty()) {
+return;
+  }
+
+  auto ExpectedLocations =
+  FormatExpected(Result.LocationAccessors);
+
+  EXPECT_THAT(ExpectedLocations,
+  UnorderedElementsAre(
+  STRING_LOCATION_PAIR(MethodDecl, getBeginLoc()),
+  STRING_LOCATION_PAIR(MethodDecl, getBodyRBrace()),
+  STRING_LOCATION_PAIR(MethodDecl, getEllipsisLoc()),
+  STRING_LOCATION_PAIR(MethodDecl, getInnerLocStart()),
+  STRING_LOCATION_PAIR(MethodDecl, getLocation()),
+  STRING_LOCATION_PAIR(MethodDecl, getOuterLocStart()),
+  STRING_LOCATION_PAIR(MethodDecl, getPointOfInstantiation()),
+  STRING_LOCATION_PAIR(MethodDecl, getTypeSpecEndLoc()),
+  STRING_LOCATION_PAIR(MethodDecl, getTypeSpecStartLoc()),
+  STRING_LOCATION_PAIR(MethodDecl, getEndLoc(;
+
+  auto ExpectedRanges = FormatExpected(Result.RangeAccessors);
+
+  EXPECT_THAT(
+  ExpectedRanges,
+  UnorderedElementsAre(
+  STRING_LOCATION_PAIR(MethodDecl, getExceptionSpecSourceRange()),
+  STRING_LOCATION_PAIR(MethodDecl, getParametersSourceRange()),
+  STRING_LOCATION_PAIR(MethodDecl, getReturnTypeSourceRange()),
+  STRING_LOCATION_PAIR(MethodDecl, getSourceRange(;
+}
Index: clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
===
--- clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
+++ clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
@@ -177,6 +177,9 @@
 NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) {
   return {};
 }
+NodeLocationAccessors NodeIntrospection::GetLocations(clang::Decl const *) {
+  return {};
+}
 NodeLocationAccessors
 NodeIntrospection::GetLocations(clang::DynTypedNode const &) {
   return {};
Index: clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
===
--- clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
+++ clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
@@ -26,7 +26,8 @@
   isDefinition(),
   isSameOrDerivedFrom(
   // TODO: Extend this with other clades
-  namedDecl(hasName("clang::Stmt")).bind("nodeClade")),
+  namedDecl(hasAnyName("clang::Stmt", "clang::Decl"))
+  .bind("nodeClade")),
   optionally(isDerivedFrom(cxxRecordDecl().bind("derivedFrom"
   .bind("className"),
   this);
Index: clang/lib/Tooling/CMakeLists.txt
===
--- clang/lib/Tooling/CMakeLists.txt
+++ clang/lib/Tooling/CMakeLists.txt
@@ -40,6 +40,9 @@
 NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) 

[PATCH] D98146: OpaquePtr: Turn inalloca into a type attribute

2021-03-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/IR/Attributes.cpp:490
 if (Type *Ty = getValueAsType()) {
-  raw_string_ostream OS(Result);
+  // FIXME: This should never be null
   Result += '(';

dblaikie wrote:
> arsenm wrote:
> > dblaikie wrote:
> > > Is it? Could you replace this with an assertion instead? 
> > It should never be null, but it is in some cases (I think there are some 
> > situations still where callsite attributes are missing byval)
> Any chance of clarifying why it is sometimes null today in the comment?
This turned out to be down to one unit test passing null to the create 
function, so I've just deleted it



Comment at: llvm/test/Bitcode/inalloca-upgrade.test:1-7
+RUN: llvm-dis %p/Inputs/inalloca-upgrade.bc -o - | FileCheck %s
+
+Make sure we upgrade old-style IntAttribute inalloca records to a
+fully typed version correctly.
+
+CHECK: call void @bar({ i32*, i8 }* inalloca({ i32*, i8 }) %ptr)
+CHECK: invoke void @bar({ i32*, i8 }* inalloca({ i32*, i8 }) %ptr)

dblaikie wrote:
> arsenm wrote:
> > dblaikie wrote:
> > > Isn't this tested by all the compatibility tests already? (since they 
> > > contain the old-style inalloca, and verify that when read in it's 
> > > upgraded to the new-style) Though I don't mind terribly having a separate 
> > > test, but each file/tool execution does add up & it's nice to keep them 
> > > to a minimum when test coverage isn't otherwise compromised.
> > I was following along with byval, which has its own test like this. I also 
> > generally hate the all-in-one style of testing features that are really 
> > unrelated. It makes it harder to know what actually broke when one fails.
> A single file with many tests for different features related to, say, bitcode 
> compatibility, seems good to me.
> 
> If the failures are hard to read - there are various FileCheck features which 
> can be used to help improve the failure modes (using CHECK-LABEL to isolate 
> one checking area from another, so they don't bleed together/get cause the 
> failure point to drift a long way from the initial problem).
> 
> Having every individual test in a separate file may significantly slow down 
> test execution (especially on Windows, where process overhead is higher, if I 
> recall correctly) and I think it reduces the chance of finding and grouping 
> related tests together - leading to a proliferation of subtly overlapping 
> tests rather than a more systematic approach to how a feature is tested. 
> (though that's always challenging - different people think in different 
> groupings, etc, naming is challenging, etc)
If you need to debug the failure, having it be as small as possible is helpful. 
At least for a text test, you can extract a single function and start from 
there. For binary tests like this, you're out of luck so I think it's more 
important to minimize these


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

https://reviews.llvm.org/D98146

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


[PATCH] D98814: [CUDA][HIP] Mark device var used by host only

2021-03-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 332157.
yaxunl marked an inline comment as done.
yaxunl added a comment.

revised by Artem's comments


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

https://reviews.llvm.org/D98814

Files:
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/test/CodeGenCUDA/host-used-device-var.cu


Index: clang/test/CodeGenCUDA/host-used-device-var.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -0,0 +1,46 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
+// RUN:   | FileCheck %s
+
+#include "Inputs/cuda.h"
+
+// Check device variables used by neither host nor device functioins are not 
kept.
+
+// CHECK-NOT: @v1
+__device__ int v1;
+
+// CHECK-NOT: @v2
+__constant__ int v2;
+
+// CHECK-NOT: @_ZL2v3
+static __device__ int v3;
+
+// Check device variables used by host functions are kept.
+
+// CHECK-DAG: @u1
+__device__ int u1;
+
+// CHECK-DAG: @u2
+__constant__ int u2;
+
+// Check host-used static device var is in llvm.compiler.used.
+// CHECK-DAG: @_ZL2u3
+static __device__ int u3;
+
+// Check device-used static device var is not in llvm.compiler.used.
+// CHECK-DAG: @_ZL2u4
+static __device__ int u4;
+
+// Check device variables with used attribute are always kept.
+// CHECK-DAG: @u5
+__device__ __attribute__((used)) int u5;
+
+int fun1() {
+  return u1 + u2 + u3;
+}
+
+__global__ void kern1(int **x) {
+  *x = 
+}
+// CHECK: @llvm.compiler.used = {{[^@]*}} @_ZL2u3 {{[^@]*}} @u1 {{[^@]*}} @u2 
{{[^@]*}} @u5
Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -1084,6 +1084,28 @@
 llvm::Function *CGNVCUDARuntime::finalizeModule() {
   if (CGM.getLangOpts().CUDAIsDevice) {
 transformManagedVars();
+
+// Mark ODR-used device variables as compiler used to prevent it from being
+// eliminated by optimization. This is necessary for device variables
+// ODR-used by host functions. Sema correctly marks them as ODR-used no
+// matter whether they are ODR-used by device or host functions.
+//
+// We do not need to do this if the variable has used attribute since it
+// has already been added.
+//
+// Static device variables have been externalized at this point, therefore
+// variables with LLVM private or internal linkage need not be added.
+for (auto & : DeviceVars) {
+  auto Kind = Info.Flags.getKind();
+  if (!Info.Var->isDeclaration() &&
+  !llvm::GlobalValue::isLocalLinkage(Info.Var->getLinkage()) &&
+  (Kind == DeviceVarFlags::Variable ||
+   Kind == DeviceVarFlags::Surface ||
+   Kind == DeviceVarFlags::Texture) &&
+  Info.D->isUsed() && !Info.D->hasAttr()) {
+CGM.addCompilerUsedGlobal(Info.Var);
+  }
+}
 return nullptr;
   }
   return makeModuleCtorFunction();


Index: clang/test/CodeGenCUDA/host-used-device-var.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -0,0 +1,46 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -x hip %s \
+// RUN:   -std=c++11 -O3 -mllvm -amdgpu-internalize-symbols -emit-llvm -o - \
+// RUN:   | FileCheck %s
+
+#include "Inputs/cuda.h"
+
+// Check device variables used by neither host nor device functioins are not kept.
+
+// CHECK-NOT: @v1
+__device__ int v1;
+
+// CHECK-NOT: @v2
+__constant__ int v2;
+
+// CHECK-NOT: @_ZL2v3
+static __device__ int v3;
+
+// Check device variables used by host functions are kept.
+
+// CHECK-DAG: @u1
+__device__ int u1;
+
+// CHECK-DAG: @u2
+__constant__ int u2;
+
+// Check host-used static device var is in llvm.compiler.used.
+// CHECK-DAG: @_ZL2u3
+static __device__ int u3;
+
+// Check device-used static device var is not in llvm.compiler.used.
+// CHECK-DAG: @_ZL2u4
+static __device__ int u4;
+
+// Check device variables with used attribute are always kept.
+// CHECK-DAG: @u5
+__device__ __attribute__((used)) int u5;
+
+int fun1() {
+  return u1 + u2 + u3;
+}
+
+__global__ void kern1(int **x) {
+  *x = 
+}
+// CHECK: @llvm.compiler.used = {{[^@]*}} @_ZL2u3 {{[^@]*}} @u1 {{[^@]*}} @u2 {{[^@]*}} @u5
Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -1084,6 +1084,28 @@
 llvm::Function *CGNVCUDARuntime::finalizeModule() {
   if (CGM.getLangOpts().CUDAIsDevice) {
 transformManagedVars();
+
+// Mark ODR-used device variables as compiler used to prevent it from being
+// eliminated by optimization. This is necessary for device variables
+// ODR-used by host 

[PATCH] D98814: [CUDA][HIP] Mark device var used by host only

2021-03-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/CGCUDANV.cpp:1102
+  Info.D->isUsed() && !Info.D->hasAttr()) {
+CGM.addCompilerUsedGlobal(Info.Var);
+  }

tra wrote:
> Do we want to limit it further to only externally-visible variables?
> I think we already externalize the variables we want to be visible across 
> host/device boundary.
> If the variable is not visible, there's no point keeping it around as the 
> runtime will not be able to find it in the GPU binary.
Good point. Will do


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

https://reviews.llvm.org/D98814

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


[PATCH] D99005: [clang] WIP: Implement P2266

2021-03-21 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

With my previous comment I meant that it's better if you leave out the 
`co_return` bits for now because it's wrong anyway. We can't use 
`PerformMoveOrCopyInitialization`. It would just generate merge conflicts.

I'll probably just update my change once the committee made up its mind. I can 
rebase it on top of this if it needs to be dependent on C++20 vs C++2b.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99005

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


[PATCH] D69218: [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level)

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

LGTM, thank you!


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

https://reviews.llvm.org/D69218

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


[PATCH] D69218: [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level)

2021-03-21 Thread Nikita Kniazev via Phabricator via cfe-commits
nick updated this revision to Diff 332151.
nick added a comment.

Lint fixes


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

https://reviews.llvm.org/D69218

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp

Index: clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -297,6 +297,17 @@
   EXPECT_TRUE(matches("int b[7];", M));
 }
 
+TEST_F(RegistryTest, CXXBaseSpecifier) {
+  // TODO: rewrite with top-level cxxBaseSpecifier matcher when available
+  DeclarationMatcher ClassHasAnyDirectBase =
+  constructMatcher("cxxRecordDecl",
+   constructMatcher("hasDirectBase",
+constructMatcher("cxxBaseSpecifier")))
+  .getTypedMatcher();
+  EXPECT_TRUE(matches("class X {}; class Y : X {};", ClassHasAnyDirectBase));
+  EXPECT_TRUE(notMatches("class X {};", ClassHasAnyDirectBase));
+}
+
 TEST_F(RegistryTest, CXXCtorInitializer) {
   Matcher CtorDecl = constructMatcher(
   "cxxConstructorDecl",
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -320,6 +320,15 @@
 varDecl(hasType(pointsTo(ClassX);
 }
 
+TEST(HasType, TakesQualTypeMatcherAndMatchesCXXBaseSpecifier) {
+  TypeMatcher ClassX = hasDeclaration(recordDecl(hasName("X")));
+  CXXBaseSpecifierMatcher BaseClassX = cxxBaseSpecifier(hasType(ClassX));
+  DeclarationMatcher ClassHasBaseClassX =
+  cxxRecordDecl(hasDirectBase(BaseClassX));
+  EXPECT_TRUE(matches("class X {}; class Y : X {};", ClassHasBaseClassX));
+  EXPECT_TRUE(notMatches("class Z {}; class Y : Z {};", ClassHasBaseClassX));
+}
+
 TEST(HasType, TakesDeclMatcherAndMatchesExpr) {
   DeclarationMatcher ClassX = recordDecl(hasName("X"));
   EXPECT_TRUE(
@@ -337,6 +346,15 @@
 notMatches("class X {}; void y() { X *x; }", varDecl(hasType(ClassX;
 }
 
+TEST(HasType, TakesDeclMatcherAndMatchesCXXBaseSpecifier) {
+  DeclarationMatcher ClassX = recordDecl(hasName("X"));
+  CXXBaseSpecifierMatcher BaseClassX = cxxBaseSpecifier(hasType(ClassX));
+  DeclarationMatcher ClassHasBaseClassX =
+  cxxRecordDecl(hasDirectBase(BaseClassX));
+  EXPECT_TRUE(matches("class X {}; class Y : X {};", ClassHasBaseClassX));
+  EXPECT_TRUE(notMatches("class Z {}; class Y : Z {};", ClassHasBaseClassX));
+}
+
 TEST(HasType, MatchesTypedefDecl) {
   EXPECT_TRUE(matches("typedef int X;", typedefDecl(hasType(asString("int");
   EXPECT_TRUE(matches("typedef const int T;",
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -4400,6 +4400,13 @@
 return;
   }
 
+  DeclarationMatcher ClassHasAnyDirectBase =
+  cxxRecordDecl(hasDirectBase(cxxBaseSpecifier()));
+  EXPECT_TRUE(notMatches("class X {};", ClassHasAnyDirectBase));
+  EXPECT_TRUE(matches("class X {}; class Y : X {};", ClassHasAnyDirectBase));
+  EXPECT_TRUE(matches("class X {}; class Y : public virtual X {};",
+  ClassHasAnyDirectBase));
+
   EXPECT_TRUE(matches(
   R"cc(
 class Base {};
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -172,6 +172,7 @@
   REGISTER_MATCHER(containsDeclaration);
   REGISTER_MATCHER(continueStmt);
   REGISTER_MATCHER(cudaKernelCallExpr);
+  REGISTER_MATCHER(cxxBaseSpecifier);
   REGISTER_MATCHER(cxxBindTemporaryExpr);
   REGISTER_MATCHER(cxxBoolLiteral);
   REGISTER_MATCHER(cxxCatchStmt);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -756,6 +756,7 @@
 const internal::VariadicDynCastAllOfMatcher parmVarDecl;
 const internal::VariadicDynCastAllOfMatcher
 accessSpecDecl;
+const internal::VariadicAllOfMatcher cxxBaseSpecifier;
 const internal::VariadicAllOfMatcher cxxCtorInitializer;
 const internal::VariadicAllOfMatcher templateArgument;
 const internal::VariadicAllOfMatcher templateArgumentLoc;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h

[PATCH] D69218: [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level)

2021-03-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:329
+  EXPECT_TRUE(matches("class X {}; class Y : X {};", ClassHasBaseClassX));
+  EXPECT_TRUE(notMatches("class Z {}; class Y : Z {};", ClassHasBaseClassX));
+}

nick wrote:
> aaron.ballman wrote:
> > I'd like to see another test along these lines:
> > ```
> > struct Base {};
> > struct Intermediate : Base {};
> > struct Derived : Intermediate {};
> > ```
> > Where we test that `Derived` does not have a direct base relationship with 
> > `Base`, but does with `hasAnyBase`.
> I do not understand why it should be here. The point of this test is to 
> ensure that `hasType` can be used inside `cxxBaseSpecifier`.  The support was 
> added in D79063 without a test and I just fill the gaps. 
> 
Oh shoot, good point, we already *have* those tests. :-)


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

https://reviews.llvm.org/D69218

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


[PATCH] D69218: [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level)

2021-03-21 Thread Nikita Kniazev via Phabricator via cfe-commits
nick added inline comments.



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:329
+  EXPECT_TRUE(matches("class X {}; class Y : X {};", ClassHasBaseClassX));
+  EXPECT_TRUE(notMatches("class Z {}; class Y : Z {};", ClassHasBaseClassX));
+}

aaron.ballman wrote:
> I'd like to see another test along these lines:
> ```
> struct Base {};
> struct Intermediate : Base {};
> struct Derived : Intermediate {};
> ```
> Where we test that `Derived` does not have a direct base relationship with 
> `Base`, but does with `hasAnyBase`.
I do not understand why it should be here. The point of this test is to ensure 
that `hasType` can be used inside `cxxBaseSpecifier`.  The support was added in 
D79063 without a test and I just fill the gaps. 



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

https://reviews.llvm.org/D69218

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


[PATCH] D69218: [ASTMatchers] Add `cxxBaseSpecifier` matcher (non-top-level)

2021-03-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/ASTMatchers/Dynamic/Registry.cpp:182
   REGISTER_MATCHER(cxxConversionDecl);
+  REGISTER_MATCHER(cxxBaseSpecifier);
   REGISTER_MATCHER(cxxCtorInitializer);

Please keep this list sorted alphabetically.



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:329
+  EXPECT_TRUE(matches("class X {}; class Y : X {};", ClassHasBaseClassX));
+  EXPECT_TRUE(notMatches("class Z {}; class Y : Z {};", ClassHasBaseClassX));
+}

I'd like to see another test along these lines:
```
struct Base {};
struct Intermediate : Base {};
struct Derived : Intermediate {};
```
Where we test that `Derived` does not have a direct base relationship with 
`Base`, but does with `hasAnyBase`.


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

https://reviews.llvm.org/D69218

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


[PATCH] D99018: [clang][flang] Moke the definition of `-module-dir` restricted to Flang

2021-03-21 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a subscriber: protze.joachim.
awarzynski added a comment.

Thank you for reviewing!

In D99018#2639680 , @MaskRay wrote:

> Thanks. I do not know why `FlangOption and FC1 Options` needs be in 
> `clang/include/clang/Driver/Options.td` but perhaps that is how things work:)

Options.td is where all options for `clangDriver` (the library) are defined. 
Since `flang` is implemented in terms of `clangDriver`, all options end up 
here. AFAIK,  there is no mechanism to have separate `Options.td` files for 
Flang and Clang. But since there is meant to be only one driver library in 
llvm-project, I think that this is fine. Instead, IMHO, we should aim for 
producing separate files for e.g. `clang -cc1` and `flang -fc1` (to have a 
clearer separation from the compiler and frontend drivers).

The extra flags: `FlangOption`, `FC1Option` and `FlangOnlyOption`, were added 
to enable _some_ filtering of the options. In particular, for making sure that 
`clang -help` doesn't contain any Flang-only options.

Btw, here's an RFC 
 in which I 
discussed some of these issues.

CC @protze.joachim - this is somewhat related to what you brought up here: 
https://reviews.llvm.org/D95460.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99018

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-03-21 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 332148.
RedDocMD marked an inline comment as done.
RedDocMD added a comment.

Re-formatted file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp


Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,10 +306,44 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is null}}
 // expected-note@-1 {{Taking true branch}}
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' 
[alpha.cplusplus.SmartPtr]}}
 // expected-note@-1{{Dereference of null smart pointer 'P'}}
   }
 }
+
+void getShouldNotAlwaysLeaveANote() {
+   std::unique_ptr P; // expected-note {{Default constructed smart 
pointer 'P' is null}}
+   A *a = P.get(); 
+   P->foo(); // expected-warning {{Dereference of null smart pointer 'P' 
[alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveNoteWhenPtrNotUsed(std::unique_ptr P) {
+  A *a = P.get(); 
+  if (!P) { // expected-note {{Taking true branch}}
+// expected-note@-1 {{Assuming smart pointer 'P' is null}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' 
[alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithWhileLoop(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  while (!RP) {// expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' 
[alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithForLoop(std::unique_ptr P) {
+  for (A *RP = P.get(); !RP;) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+// expected-note@-2 {{Obtained null inner pointer from 'P'}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' 
[alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -457,8 +457,22 @@
 
   State = State->BindExpr(Call.getOriginExpr(), C.getLocationContext(),
   InnerPointerVal);
-  // TODO: Add NoteTag, for how the raw pointer got using 'get' method.
-  C.addTransition(State);
+
+  C.addTransition(State, C.getNoteTag([ThisRegion, InnerPointerVal,
+   State](PathSensitiveBugReport ,
+  llvm::raw_ostream ) {
+if (() != smartptr::getNullDereferenceBugType() ||
+!BR.isInteresting(ThisRegion))
+  return;
+if (!BR.isInteresting(InnerPointerVal) || 
!BR.isInteresting(InnerPointerVal.getAsSymbol()))
+  return;
+if (ThisRegion->canPrintPretty()) {
+  OS << "Obtained null inner pointer from";
+  checkAndPrettyPrintRegion(OS, ThisRegion);
+} else {
+  OS << "Obtained null inner pointer here";
+}
+  }));
 }
 
 bool SmartPtrModeling::handleAssignOp(const CallEvent ,
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
@@ -87,6 +87,8 @@
   auto R = std::make_unique(NullDereferenceBugType,
 OS.str(), ErrNode);
   R->markInteresting(DerefRegion);
+  const Expr *BugExpr = Call.getOriginExpr();
+  bugreporter::trackExpressionValue(ErrNode, BugExpr, *R);
   C.emitReport(std::move(R));
 }
 


Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,10 +306,44 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // 

[clang] 2288a75 - [Driver] Linux.cpp: add -internal-isystem lib/../$triple/include

2021-03-21 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-03-21T00:56:03-07:00
New Revision: 2288a75d9eceeabdffcd72789d97386ee10962fb

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

LOG: [Driver] Linux.cpp: add -internal-isystem lib/../$triple/include

With this change, for `#include `, `clang --target=aarch64-linux-gnu`
will read 
`/usr/lib/gcc/aarch64-linux-gnu/10/../../../../aarch64-linux-gnu/include/ar.h`
(on Debian gcc->gcc-cross)
instead of `/usr/include/ar.h`. Some glibc headers (e.g. gnu/stubs.h) are 
different across architectures.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/linux-header-search.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 078579669634..b5efa587f8dc 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2867,13 +2867,19 @@ void Generic_GCC::AddMultiarchPaths(const Driver ,
 void Generic_GCC::AddMultilibIncludeArgs(const ArgList ,
  ArgStringList ) const {
   // Add include directories specific to the selected multilib set and 
multilib.
-  if (GCCInstallation.isValid()) {
-const auto  = Multilibs.includeDirsCallback();
-if (Callback) {
-  for (const auto  : Callback(GCCInstallation.getMultilib()))
-addExternCSystemIncludeIfExists(
-DriverArgs, CC1Args, GCCInstallation.getInstallPath() + Path);
-}
+  if (!GCCInstallation.isValid())
+return;
+  // gcc TOOL_INCLUDE_DIR.
+  const llvm::Triple  = GCCInstallation.getTriple();
+  std::string LibPath(GCCInstallation.getParentLibPath());
+  addSystemInclude(DriverArgs, CC1Args,
+   Twine(LibPath) + "/../" + GCCTriple.str() + "/include");
+
+  const auto  = Multilibs.includeDirsCallback();
+  if (Callback) {
+for (const auto  : Callback(GCCInstallation.getMultilib()))
+  addExternCSystemIncludeIfExists(DriverArgs, CC1Args,
+  GCCInstallation.getInstallPath() + Path);
   }
 }
 

diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 6599f46d0d52..0e8da0fea2a7 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -574,9 +574,14 @@ void Linux::AddClangSystemIncludeArgs(const ArgList 
,
   if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
 return;
 
-  if (!DriverArgs.hasArg(options::OPT_nostdlibinc))
+  if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
+// LOCAL_INCLUDE_DIR
 addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
+// TOOL_INCLUDE_DIR
+AddMultilibIncludeArgs(DriverArgs, CC1Args);
+  }
 
+  // Note: in gcc, GCC_INCLUDE_DIR (private headers) precedes 
LOCAL_INCLUDE_DIR.
   SmallString<128> ResourceDirInclude(D.ResourceDir);
   llvm::sys::path::append(ResourceDirInclude, "include");
   if (!DriverArgs.hasArg(options::OPT_nobuiltininc) &&
@@ -599,11 +604,6 @@ void Linux::AddClangSystemIncludeArgs(const ArgList 
,
 return;
   }
 
-  // Lacking those, try to detect the correct set of system includes for the
-  // target triple.
-
-  AddMultilibIncludeArgs(DriverArgs, CC1Args);
-
   // Implement generic Debian multiarch support.
   const StringRef X86_64MultiarchIncludeDirs[] = {
   "/usr/include/x86_64-linux-gnu",

diff  --git a/clang/test/Driver/linux-header-search.cpp 
b/clang/test/Driver/linux-header-search.cpp
index 4aed02f9c15d..3560bd009277 100644
--- a/clang/test/Driver/linux-header-search.cpp
+++ b/clang/test/Driver/linux-header-search.cpp
@@ -188,7 +188,8 @@
 // CHECK-DEBIAN-X86: "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/i686-linux-gnu/4.5/../../../../include/c++/4.5/i686-linux-gnu"
 // CHECK-DEBIAN-X86: "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/i686-linux-gnu/4.5/../../../../include/c++/4.5/backward"
 // CHECK-DEBIAN-X86: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
-// CHECK-DEBIAN-X86: "-internal-isystem" "[[RESOURCE_DIR]]{{/|}}include"
+// CHECK-DEBIAN-X86-SAME: {{^}} "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/i686-linux-gnu/4.5/../../../../i686-linux-gnu/include"
+// CHECK-DEBIAN-X86-SAME: {{^}} "-internal-isystem" 
"[[RESOURCE_DIR]]{{/|}}include"
 // CHECK-DEBIAN-X86: "-internal-externc-isystem" 
"[[SYSROOT]]/usr/include/i386-linux-gnu"
 // CHECK-DEBIAN-X86: "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-DEBIAN-X86: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
@@ -204,7 +205,8 @@
 // CHECK-DEBIAN-X86-64: "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/x86_64-linux-gnu/4.5/../../../../include/c++/4.5/x86_64-linux-gnu"
 // CHECK-DEBIAN-X86-64: "-internal-isystem" 

[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-03-21 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD marked an inline comment as done.
RedDocMD added inline comments.



Comment at: clang/test/Analysis/smart-ptr-text-output.cpp:317
 
 void getShouldNotAlwaysLeaveANote() {
std::unique_ptr P; // expected-note {{Default constructed smart 
pointer 'P' is null}}

NoQ wrote:
> Looks like your git history is acting up. Your patch adds this test right? 
> Are there more proposed changes in the cpp files that aren't currently 
> highlighted for a similar reason?
> 
> I'll try to play with your patch locally once this is fixed ^.^
Yeah I seem to have tripped over the single commit rule. It should be fixed now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-03-21 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 332147.
RedDocMD added a comment.

Fixed up the git history


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp


Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,10 +306,44 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is null}}
 // expected-note@-1 {{Taking true branch}}
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' 
[alpha.cplusplus.SmartPtr]}}
 // expected-note@-1{{Dereference of null smart pointer 'P'}}
   }
 }
+
+void getShouldNotAlwaysLeaveANote() {
+   std::unique_ptr P; // expected-note {{Default constructed smart 
pointer 'P' is null}}
+   A *a = P.get(); 
+   P->foo(); // expected-warning {{Dereference of null smart pointer 'P' 
[alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+}
+
+void getShouldNotLeaveNoteWhenPtrNotUsed(std::unique_ptr P) {
+  A *a = P.get(); 
+  if (!P) { // expected-note {{Taking true branch}}
+// expected-note@-1 {{Assuming smart pointer 'P' is null}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' 
[alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithWhileLoop(std::unique_ptr P) {
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
+  while (!RP) {// expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' 
[alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
+
+void getShouldLeaveANoteWithForLoop(std::unique_ptr P) {
+  for (A *RP = P.get(); !RP;) { // expected-note {{Assuming 'RP' is null}}
+// expected-note@-1 {{Loop condition is true.  Entering loop body}}
+// expected-note@-2 {{Obtained null inner pointer from 'P'}}
+P->foo(); // expected-warning {{Dereference of null smart pointer 'P' 
[alpha.cplusplus.SmartPtr]}}
+// expected-note@-1{{Dereference of null smart pointer 'P'}}
+  }
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -457,8 +457,22 @@
 
   State = State->BindExpr(Call.getOriginExpr(), C.getLocationContext(),
   InnerPointerVal);
-  // TODO: Add NoteTag, for how the raw pointer got using 'get' method.
-  C.addTransition(State);
+
+  C.addTransition(State, C.getNoteTag([ThisRegion, InnerPointerVal,
+   State](PathSensitiveBugReport ,
+  llvm::raw_ostream ) {
+if (() != smartptr::getNullDereferenceBugType() ||
+!BR.isInteresting(ThisRegion))
+  return;
+if (!BR.isInteresting(InnerPointerVal) || 
!BR.isInteresting(InnerPointerVal.getAsSymbol()))
+  return;
+if (ThisRegion->canPrintPretty()) {
+  OS << "Obtained null inner pointer from";
+  checkAndPrettyPrintRegion(OS, ThisRegion);
+} else {
+  OS << "Obtained null inner pointer here";
+}
+  }));
 }
 
 bool SmartPtrModeling::handleAssignOp(const CallEvent ,
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
@@ -87,6 +87,8 @@
   auto R = std::make_unique(NullDereferenceBugType,
 OS.str(), ErrNode);
   R->markInteresting(DerefRegion);
+  const Expr *BugExpr = Call.getOriginExpr();
+  bugreporter::trackExpressionValue(ErrNode, BugExpr, *R);
   C.emitReport(std::move(R));
 }
 


Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -306,10 +306,44 @@
 };
 
 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr P) {
-  A *RP = P.get();
+  A *RP = P.get(); // expected-note {{Obtained null inner pointer from 'P'}}
   if (!RP) { // expected-note {{Assuming 'RP' is