[PATCH] D102479: [clang][driver] Treat unkonwn -flto= values as -flto

2021-05-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 346058.
Herald added subscribers: steven_wu, hiraditya.

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

https://reviews.llvm.org/D102479

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/thinlto-backend-option.ll
  clang/test/Driver/autocomplete.c


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -72,7 +72,9 @@
 // FFPALL-NEXT: off
 // FFPALL-NEXT: on
 // RUN: %clang --autocomplete=-flto= | FileCheck %s -check-prefix=FLTOALL
-// FLTOALL: full
+// FLTOALL: auto
+// FLTOALL-NEXT: full
+// FLTOALL-NEXT: jobserver
 // FLTOALL-NEXT: thin
 // RUN: %clang --autocomplete=-fveclib= | FileCheck %s -check-prefix=FVECLIBALL
 // FVECLIBALL: Accelerate
Index: clang/test/CodeGen/thinlto-backend-option.ll
===
--- clang/test/CodeGen/thinlto-backend-option.ll
+++ clang/test/CodeGen/thinlto-backend-option.ll
@@ -12,6 +12,3 @@
 ; RUN: llvm-lto -thinlto -o %t %t.o
 ; RUN: not %clang_cc1 -x ir %t.o -fthinlto-index=%t.thinlto.bc -mllvm 
-nonexistent -emit-obj -o /dev/null 2>&1 | FileCheck %s -check-prefix=UNKNOWN
 ; UNKNOWN: clang (LLVM option parsing): Unknown command line argument 
'-nonexistent'
-
-; RUN: not %clang_cc1 -flto=thinfoo 2>&1 | FileCheck %s -check-prefix=INVALID
-; INVALID: error: invalid value 'thinfoo' in '-flto=thinfoo'
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1707,8 +1707,7 @@
 StringRef S = A->getValue();
 if (S == "thin")
   Opts.PrepareForThinLTO = true;
-else if (S != "full")
-  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << S;
+// -flto=full and invalid values are handled elsewhere.
   }
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != Language::LLVM_IR)
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -609,6 +609,8 @@
 
   LTOMode = llvm::StringSwitch(LTOName)
 .Case("full", LTOK_Full)
+.Case("auto", LTOK_Full)  // GCC compatibility
+.Case("jobserver", LTOK_Full) // GCC compatibility
 .Case("thin", LTOK_Thin)
 .Default(LTOK_Unknown);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1949,7 +1949,7 @@
 def fapple_link_rtlib : Flag<["-"], "fapple-link-rtlib">, Group,
   HelpText<"Force linking the clang builtins runtime library">;
 def flto_EQ : Joined<["-"], "flto=">, Flags<[CoreOption, CC1Option]>, 
Group,
-  HelpText<"Set LTO mode to either 'full' or 'thin'">, Values<"thin,full">;
+  HelpText<"Set LTO mode to either 'full' or 'thin'">, 
Values<"thin,full,auto,jobserver">;
 def flto : Flag<["-"], "flto">, Flags<[CoreOption, CC1Option]>, Group,
   HelpText<"Enable LTO in 'full' mode">;
 def fno_lto : Flag<["-"], "fno-lto">, Flags<[CoreOption, CC1Option]>, 
Group,
@@ -4244,8 +4244,6 @@
 defm branch_count_reg : BooleanFFlag<"branch-count-reg">, 
Group;
 defm default_inline : BooleanFFlag<"default-inline">, 
Group;
 defm fat_lto_objects : BooleanFFlag<"fat-lto-objects">, 
Group;
-def : Flag<["-"], "flto=auto">, Group;
-def : Flag<["-"], "flto=jobserver">, 
Group;
 defm float_store : BooleanFFlag<"float-store">, 
Group;
 defm friend_injection : BooleanFFlag<"friend-injection">, 
Group;
 defm function_attribute_list : BooleanFFlag<"function-attribute-list">, 
Group;


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -72,7 +72,9 @@
 // FFPALL-NEXT: off
 // FFPALL-NEXT: on
 // RUN: %clang --autocomplete=-flto= | FileCheck %s -check-prefix=FLTOALL
-// FLTOALL: full
+// FLTOALL: auto
+// FLTOALL-NEXT: full
+// FLTOALL-NEXT: jobserver
 // FLTOALL-NEXT: thin
 // RUN: %clang --autocomplete=-fveclib= | FileCheck %s -check-prefix=FVECLIBALL
 // FVECLIBALL: Accelerate
Index: clang/test/CodeGen/thinlto-backend-option.ll
===
--- clang/test/CodeGen/thinlto-backend-option.ll
+++ clang/test/CodeGen/thinlto-backend-option.ll
@@ -12,6 +12,3 @@
 ; RUN: llvm-lto -thinlto -o %t %t.o
 ; RUN: not %clang_cc1 -x ir %t.o -fthinlto-index=%t.thinlto.bc -mllvm -nonexistent -emit-obj -o /dev/null 2>&1 | FileCheck %s -check-prefix=UNKNOWN
 ; UNKNOWN: clang (LLVM option parsing): Unknown command 

[PATCH] D102670: [clang-offload-bundler] Add sections and set section flags using one llvm-objcopy invocation

2021-05-17 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev created this revision.
sdmitriev added reviewers: ABataev, jdoerfert.
Herald added a reviewer: alexshap.
Herald added a subscriber: abrachet.
sdmitriev requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

llvm-objcopy has been changed to support adding a section and updating section 
flags
in one run (D90438 ), so we can now change 
clang-offload-bundler to run llvm-objcopy
tool only once when creating fat object.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102670

Files:
  clang/test/Driver/clang-offload-bundler.c
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp


Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -578,11 +578,7 @@
 // We will use llvm-objcopy to add target objects sections to the output
 // fat object. These sections should have 'exclude' flag set which tells
 // link editor to remove them from linker inputs when linking executable or
-// shared library. llvm-objcopy currently does not support adding new
-// section and changing flags for the added section in one invocation, and
-// because of that we have to run it two times. First run adds sections and
-// the second changes flags.
-// TODO: change it to one run once llvm-objcopy starts supporting that.
+// shared library.
 
 // Find llvm-objcopy in order to create the bundle binary.
 ErrorOr Objcopy = sys::findProgramByName(
@@ -600,14 +596,8 @@
 // Temporary files that need to be removed.
 TempFileHandlerRAII TempFiles;
 
-// Create an intermediate temporary file to save object after the first
-// llvm-objcopy run.
-Expected IntermediateObjOrErr = TempFiles.Create(None);
-if (!IntermediateObjOrErr)
-  return IntermediateObjOrErr.takeError();
-StringRef IntermediateObj = *IntermediateObjOrErr;
-
-// Compose llvm-objcopy command line for add target objects' sections.
+// Compose llvm-objcopy command line for add target objects' sections with
+// appropriate flags.
 BumpPtrAllocator Alloc;
 StringSaver SS{Alloc};
 SmallVector ObjcopyArgs{"llvm-objcopy"};
@@ -627,20 +617,11 @@
   ObjcopyArgs.push_back(SS.save(Twine("--add-section=") +
 OFFLOAD_BUNDLER_MAGIC_STR + TargetNames[I] 
+
 "=" + InputFile));
-}
-ObjcopyArgs.push_back(InputFileNames[HostInputIndex]);
-ObjcopyArgs.push_back(IntermediateObj);
-
-if (Error Err = executeObjcopy(*Objcopy, ObjcopyArgs))
-  return Err;
-
-// And run llvm-objcopy for the second time to update section flags.
-ObjcopyArgs.resize(1);
-for (unsigned I = 0; I < NumberOfInputs; ++I)
   ObjcopyArgs.push_back(SS.save(Twine("--set-section-flags=") +
 OFFLOAD_BUNDLER_MAGIC_STR + TargetNames[I] 
+
 "=readonly,exclude"));
-ObjcopyArgs.push_back(IntermediateObj);
+}
+ObjcopyArgs.push_back(InputFileNames[HostInputIndex]);
 ObjcopyArgs.push_back(OutputFileNames.front());
 
 if (Error Err = executeObjcopy(*Objcopy, ObjcopyArgs))
Index: clang/test/Driver/clang-offload-bundler.c
===
--- clang/test/Driver/clang-offload-bundler.c
+++ clang/test/Driver/clang-offload-bundler.c
@@ -274,8 +274,7 @@
 
 // RUN: clang-offload-bundler -type=o 
-targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu
 -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o -### 2>&1 \
 // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o 
-DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix 
CK-OBJ-CMD
-// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]={{.*}}" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]"
 "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" 
"[[INOBJ1]]" "[[TEMPOBJ:.*]]"
-// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=readonly,exclude"
 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=readonly,exclude"
 "[[TEMPOBJ]]" "[[OUTOBJ]]"
+// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]={{.*}}" 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" 
"--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]"
 
"--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=readonly,exclude"
 "--a

[PATCH] D102469: [sanitizer] Reduce redzone size for small size global objects

2021-05-17 Thread Zhiwei Chen via Phabricator via cfe-commits
condy marked an inline comment as done.
condy added inline comments.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:2556-2559
+  // Reduce redzone size for small size objects, e.g. int, char[1]. MinRZ is at
+  // least 32 bytes, optimize when SizeInBytes is less than half of MinRZ.
+  if (SizeInBytes < MinRZ / 2) {
+RZ = MinRZ - SizeInBytes;

vitalybuka wrote:
> 
Updated


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102469

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


[PATCH] D102469: [sanitizer] Reduce redzone size for small size global objects

2021-05-17 Thread Zhiwei Chen via Phabricator via cfe-commits
condy updated this revision to Diff 346055.
condy added a comment.

Update as suggected


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102469

Files:
  clang/test/CodeGen/asan-globals-alias.cpp
  clang/test/CodeGen/asan-globals-odr.cpp
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/asan-static-odr.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  
llvm/test/Instrumentation/AddressSanitizer/AMDGPU/adaptive_constant_global_redzones.ll
  llvm/test/Instrumentation/AddressSanitizer/AMDGPU/adaptive_global_redzones.ll
  llvm/test/Instrumentation/AddressSanitizer/adaptive_global_redzones.ll
  llvm/test/Instrumentation/AddressSanitizer/debug-info-global-var.ll
  llvm/test/Instrumentation/AddressSanitizer/global_cstring_darwin.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_array.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_windows.ll
  llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
  llvm/test/Instrumentation/AddressSanitizer/local_alias.ll
  llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll

Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -8,13 +8,13 @@
 ; CHECK: $"??_C@_04JIHMPGLA@asdf?$AA@" = comdat any
 
 ; CHECK: @"??_C@_04JIHMPGLA@asdf?$AA@" =
-; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [59 x i8] }
-; CHECK-SAME: { [5 x i8] c"asdf\00", [59 x i8] zeroinitializer }, comdat, align 32
+; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [27 x i8] }
+; CHECK-SAME: { [5 x i8] c"asdf\00", [27 x i8] zeroinitializer }, comdat, align 32
 
 ; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
-; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [59 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 64, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
+; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [27 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
+; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
 ; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
 ; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
 ; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
Index: llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
+++ llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll
@@ -11,15 +11,15 @@
 @c = internal global [2 x i32] zeroinitializer, align 4
 @d = unnamed_addr global [2 x i32] zeroinitializer, align 4
 
-; NOALIAS:  @__asan_global_a = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @a to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
-; NOALIAS-NEXT: @__asan_global_b = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @b to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.2 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 -1 }
-; NOALIAS-NEXT: @__asan_global_c = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @c to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.3 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 -1 }
-; NOALIAS-NEXT: @__asan_global_d = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [56 x i8] }* @d to i64), i64 8, i64 64, i64 ptrtoint ([2 x i8]* @___asan_gen_.4 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
+; NOALIAS:  @__asan_global_a = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [24 x i8] }* @a to i64), i64 8, i64 32, i64 ptrtoint ([2 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }
+; NOALIAS-NEXT: @__asan_global_b = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [24 x i8] }* @b to i64), i64 8, i64 32, i64 ptrtoint ([2 x i8]* @___asan_gen_.2 to i64), i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 -1 }
+; NOALIAS-NEXT: @__asan_global_c = private global { i64, i64, i64, i64, i64, i64, i64, i64 } { i64 ptrtoint ({ [2 x i32], [24 x i8] }* @c to i64), i64 8,

[PATCH] D102159: [index][analyzer][ctu] Eliminate white spaces in the CTU lookup name.

2021-05-17 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie abandoned this revision.
OikawaKirie added a comment.

It seems impossible and not so reasonable to eliminate all white space 
characters in the USR as mentioned in the test case of revision D102669 
.
This patch is split to revision D102669  to 
fix the wrongly parsed CTU index file and revision D102614 
 to handle the member pointer type mentioned 
here.
Please continue with these two following revisions and I will close this one.

Thanks to all reviewers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102159

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


[PATCH] D102669: [analyzer][ctu] Fix wrong 'multiple definitions' errors caused by space characters in lookup names when parsing the ctu index file

2021-05-17 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie created this revision.
OikawaKirie added reviewers: gamesh411, martong, hgabii.
OikawaKirie added a project: clang.
Herald added subscribers: steakhal, ASDenysPetrov, dkrupp, donat.nagy, 
Szelethus, arphaman, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware, xazax.hun.
OikawaKirie requested review of this revision.
Herald added a subscriber: cfe-commits.

This error was found when analyzing MySQL with CTU enabled.

When there are space characters in the lookup name, the current delimiter 
searching strategy will make the file path wrongly parsed.
And when two lookup names have the same prefix before their first space 
characters, a 'multiple definitions' error will be wrongly reported.

e.g. The lookup names for the two lambda exprs in the test case are 
`c:@S@G@F@G#@Sa@F@operator int (*)(char)#1` and `c:@S@G@F@G#@Sa@F@operator bool 
(*)(char)#1` respectively. And their prefixes are both 
`c:@S@G@F@G#@Sa@F@operator` when using the first space character as the 
delimiter.

This patch solves the problem by replacing `find` with `rfind` for the 
delimiter, as the chance of file paths having space characters seems to be far 
less than the lookup name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102669

Files:
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/test/Analysis/Inputs/ctu-lookup-name-with-space.cpp
  clang/test/Analysis/ctu-lookup-name-with-space.cpp


Index: clang/test/Analysis/ctu-lookup-name-with-space.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-lookup-name-with-space.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+
+// RUN: cp %s %t/trigger.cpp
+// RUN: cp %S/Inputs/ctu-lookup-name-with-space.cpp %t/importee.cpp
+// RUN: echo '"%t/importee.cpp" : ["g++", "-c", "%t/importee.cpp"]' > 
%t/invocations.yaml
+// RUN: echo '[{"directory": "%t", "command": "g++ -c %t/importee.cpp", 
"file": "%t/importee.cpp"}, {"directory": "%t", "command": "g++ -c 
%t/trigger.cpp", "file": "%t/trigger.cpp"}]' > %t/compile_commands.json
+
+// RUN: %clang_extdef_map -p %t %t/importee.cpp > %t/externalDefMap.txt
+
+// RUN: cd %t && %clang_cc1 -fsyntax-only -analyze \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=. \
+// RUN:   -analyzer-config ctu-invocation-list=invocations.yaml \
+// RUN:   trigger.cpp 2>&1 | FileCheck importee.cpp
+
+// RUN: cd %t && %clang_cc1 -fsyntax-only -analyze \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=. \
+// RUN:   -analyzer-config ctu-invocation-list=invocations.yaml \
+// RUN:   -verify trigger.cpp
+
+int importee(int);
+
+void trigger() {
+  importee(0); // expected-warn...@importee.cpp:13 {{Division by zero}}
+}
Index: clang/test/Analysis/Inputs/ctu-lookup-name-with-space.cpp
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-lookup-name-with-space.cpp
@@ -0,0 +1,14 @@
+void f(int (*)(char));
+void f(bool (*)(char));
+
+struct G {
+  G() {
+// CHECK-NOT: error: multiple definitions are found for the same key in 
index
+f([](char) -> int { return 42; });
+f([](char) -> bool { return true; });
+  }
+};
+
+int importee(int X) {
+  return 1 / X;
+}
Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -157,7 +157,7 @@
   unsigned LineNo = 1;
   while (std::getline(ExternalMapFile, Line)) {
 StringRef LineRef{Line};
-const size_t Delimiter = LineRef.find(' ');
+const size_t Delimiter = LineRef.rfind(' ');
 if (Delimiter > 0 && Delimiter != std::string::npos) {
   StringRef LookupName = LineRef.substr(0, Delimiter);
 


Index: clang/test/Analysis/ctu-lookup-name-with-space.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-lookup-name-with-space.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+
+// RUN: cp %s %t/trigger.cpp
+// RUN: cp %S/Inputs/ctu-lookup-name-with-space.cpp %t/importee.cpp
+// RUN: echo '"%t/importee.cpp" : ["g++", "-c", "%t/importee.cpp"]' > %t/invocations.yaml
+// RUN: echo '[{"directory": "%t", "command": "g++ -c %t/importee.cpp", "file": "%t/importee.cpp"}, {"directory": "%t", "command": "g++ -c %t/trigger.cpp", "file": "%t/trigger.cpp"}]' > %t/compile_commands.json
+
+// RUN: %clang_extdef_map -p %t %t/importee.cpp > %t/externalDefMap.txt
+
+// RUN: cd %t && %clang_cc1 -fsyntax-only -analyze \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=. \
+// RUN:   -analyzer-config ctu-invocation-list=invocations.yaml \
+// R

[clang] 797ad70 - [Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 1

2021-05-17 Thread Ten Tzen via cfe-commits

Author: Ten Tzen
Date: 2021-05-17T22:42:17-07:00
New Revision: 797ad701522988e212495285dade8efac41a24d4

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

LOG: [Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 1

This patch is the Part-1 (FE Clang) implementation of HW Exception handling.

This new feature adds the support of Hardware Exception for Microsoft Windows
SEH (Structured Exception Handling).
This is the first step of this project; only X86_64 target is enabled in this 
patch.

Compiler options:
For clang-cl.exe, the option is -EHa, the same as MSVC.
For clang.exe, the extra option is -fasync-exceptions,
plus -triple x86_64-windows -fexceptions and -fcxx-exceptions as usual.

NOTE:: Without the -EHa or -fasync-exceptions, this patch is a NO-DIFF change.

The rules for C code:
For C-code, one way (MSVC approach) to achieve SEH -EHa semantic is to follow
three rules:
* First, no exception can move in or out of _try region., i.e., no "potential
  faulty instruction can be moved across _try boundary.
* Second, the order of exceptions for instructions 'directly' under a _try
  must be preserved (not applied to those in callees).
* Finally, global states (local/global/heap variables) that can be read
  outside of _try region must be updated in memory (not just in register)
  before the subsequent exception occurs.

The impact to C++ code:
Although SEH is a feature for C code, -EHa does have a profound effect on C++
side. When a C++ function (in the same compilation unit with option -EHa ) is
called by a SEH C function, a hardware exception occurs in C++ code can also
be handled properly by an upstream SEH _try-handler or a C++ catch(...).
As such, when that happens in the middle of an object's life scope, the dtor
must be invoked the same way as C++ Synchronous Exception during unwinding
process.

Design:
A natural way to achieve the rules above in LLVM today is to allow an EH edge
added on memory/computation instruction (previous iload/istore idea) so that
exception path is modeled in Flow graph preciously. However, tracking every
single memory instruction and potential faulty instruction can create many
Invokes, complicate flow graph and possibly result in negative performance
impact for downstream optimization and code generation. Making all
optimizations be aware of the new semantic is also substantial.

This design does not intend to model exception path at instruction level.
Instead, the proposed design tracks and reports EH state at BLOCK-level to
reduce the complexity of flow graph and minimize the performance-impact on CPP
code under -EHa option.

One key element of this design is the ability to compute State number at
block-level. Our algorithm is based on the following rationales:

A _try scope is always a SEME (Single Entry Multiple Exits) region as jumping
into a _try is not allowed. The single entry must start with a seh_try_begin()
invoke with a correct State number that is the initial state of the SEME.
Through control-flow, state number is propagated into all blocks. Side exits
marked by seh_try_end() will unwind to parent state based on existing
SEHUnwindMap[].
Note side exits can ONLY jump into parent scopes (lower state number).
Thus, when a block succeeds various states from its predecessors, the lowest
State triumphs others.  If some exits flow to unreachable, propagation on those
paths terminate, not affecting remaining blocks.
For CPP code, object lifetime region is usually a SEME as SEH _try.
However there is one rare exception: jumping into a lifetime that has Dtor but
has no Ctor is warned, but allowed:

Warning: jump bypasses variable with a non-trivial destructor

In that case, the region is actually a MEME (multiple entry multiple exits).
Our solution is to inject a eha_scope_begin() invoke in the side entry block to
ensure a correct State.

Implementation:
Part-1: Clang implementation described below.

Two intrinsic are created to track CPP object scopes; eha_scope_begin() and 
eha_scope_end().
_scope_begin() is immediately added after ctor() is called and EHStack is 
pushed.
So it must be an invoke, not a call. With that it's also guaranteed an
EH-cleanup-pad is created regardless whether there exists a call in this scope.
_scope_end is added before dtor(). These two intrinsics make the computation of
Block-State possible in downstream code gen pass, even in the presence of
ctor/dtor inlining.

Two intrinsic, seh_try_begin() and seh_try_end(), are added for C-code to mark
_try boundary and to prevent from exceptions being moved across _try boundary.
All memory instructions inside a _try are considered as 'volatile' to assure
2nd and 3rd rules for C-code above. This is a little sub-optimized. But it's
acceptable as the amount of code directly under _try is very small.

Part-2 (will be in Part-2 patch): LLVM implementation 

[PATCH] D102654: [DebugInfo][test] Check specific func name to ignore codegen differences

2021-05-17 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102654

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


[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

2021-05-17 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D96033#2764946 , 
@hubert.reinterpretcast wrote:

>> If that works on your platform I will happily open a review for the changes.
>
> From the behaviour observed in the 64-bit build, the 32-bit case might not 
> fail similarly. I need to see if I can get a 32-bit build going. For now, the 
> patch would be welcome (without changing from `UNSUPPORTED` to `XFAIL`).

The 32-bit case fails elsewhere:

  clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> Not yet implemented!
  UNREACHABLE executed at 
/home/hstong/.Nrtphome/.Liodine/llcrossbld/dev/llvm-project/llvm/lib/Object/XCOFFObjectFile.cpp:219!
  IOT/Abort trap (core dumped)

So, I don't think the 32-bit and 64-bit cases are going to be synchronized.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96033

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


[PATCH] D102663: Bug 49633 - Added warning for static inline global and namespaced declarations for c++17+

2021-05-17 Thread Serberoth via Phabricator via cfe-commits
serberoth created this revision.
serberoth added reviewers: erik.pilkington, rsmith, TH3CHARLie, fixing bugs in 
llvm.
serberoth requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Bug 49633 - Added a warning for global and namespace declared variables that 
are declared as both static and inline when using C++17 and above.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102663

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Sema/c17-global-static-inline.cpp


Index: clang/test/Sema/c17-global-static-inline.cpp
===
--- /dev/null
+++ clang/test/Sema/c17-global-static-inline.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++17 %s -verify
+
+static inline int should_warn; // expected-warning{{variable 'should_warn' 
declared as both inline and with static storage declaration}}
+
+namespace TestNamespace {
+
+static inline int NamespacedShouldWarn; // expected-warning{{variable 
'NamespacedShouldWarn' declared as both inline and with static storage 
declaration}}
+
+};
+
+static constexpr inline const volatile float f = 0.0f; // 
expected-warning{{variable 'f' declared as both inline and with static storage 
declaration}}
+
+static inline int TestFunction(int s, int e, int n) {
+  int m = (n - s) / (e - s);
+  return m * m * m * (m * (m * 6 - 15) + 10);
+}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -84,7 +84,7 @@
 constexpr auto &[i] = n; // expected-error {{cannot be declared 
'constexpr'}}
   }
 
-  static constexpr inline thread_local auto &[j1] = n; // expected-error 
{{cannot be declared with 'constexpr inline' specifiers}}
+  static constexpr inline thread_local auto &[j1] = n; // expected-error 
{{cannot be declared with 'constexpr inline' specifiers}} 
expected-warning{{variable 'j1' declared as both inline and with static storage 
declaration}}
   static thread_local auto &[j2] = n; // expected-warning {{declared with 
'static thread_local' specifiers is a C++20 extension}}
 
   inline auto &[k] = n; // expected-error {{cannot be declared 'inline'}}
Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
+++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
@@ -4,7 +4,7 @@
 A() -> A;
 A(int) -> A;
 
-static constexpr inline const volatile A a = {}; // ok, specifiers are 
permitted
+static constexpr inline const volatile A a = {}; // expected-warning{{variable 
'a' declared as both inline and with static storage declaration}}
 A b;
 A c [[]] {};
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -7124,6 +7124,11 @@
   Diag(D.getDeclSpec().getInlineSpecLoc(),
diag::err_inline_declaration_block_scope) << Name
 << FixItHint::CreateRemoval(D.getDeclSpec().getInlineSpecLoc());
+} else if (SC == SC_Static && DC->isFileContext() &&
+   getLangOpts().CPlusPlus17) {
+  // static inline declarations in the global or namespace scope should get
+  // a warning indicating they are contradictory in nature.
+  Diag(D.getIdentifierLoc(), diag::warn_cxx17_static_inline) << Name;
 } else {
   Diag(D.getDeclSpec().getInlineSpecLoc(),
getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_inline_variable
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1466,6 +1466,10 @@
 def warn_cxx14_compat_inline_variable : Warning<
   "inline variables are incompatible with C++ standards before C++17">,
   DefaultIgnore, InGroup;
+def warn_cxx17_static_inline : Warning<
+  "variable %0 declared as both inline and with static storage declaration">,
+  InGroup;
+
 
 def warn_inline_namespace_reopened_noninline : Warning<
   "inline namespace reopened as a non-inline namespace">,


Index: clang/test/Sema/c17-global-static-inline.cpp
===
--- /dev/null
+++ clang/test/Sema/c17-global-static-inline.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++17 %s -verify
+
+static inline int should_warn; // expected-warning{{variable 'should_warn' declared as both inline and with static storage declaration}}
+
+namespace TestNamespace {
+
+static inline int NamespacedSho

[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2021-05-17 Thread Greg Clayton via Phabricator via cfe-commits
clayborg added inline comments.



Comment at: llvm/trunk/lib/Support/PrettyStackTrace.cpp:92-93
+#elif defined(__APPLE__) && HAVE_CRASHREPORTER_INFO
+extern "C" const char *__crashreporter_info__
+__attribute__((visibility("hidden"))) = 0;
 asm(".desc ___crashreporter_info__, 0x10");

lol, if we still need the ___crashreporter_info__ symbol to be around, then it 
should be visible so that ReportCrash can find it... 


Repository:
  rL LLVM

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

https://reviews.llvm.org/D27683

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


[PATCH] D97669: [clang][AVR] Add avr-libc/include to clang system include paths

2021-05-17 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a reviewer: efriedma.
benshi001 added a subscriber: efriedma.
benshi001 added a comment.

@efriedma

Could you please help me review this patch? It relates to the one you have 
reviewed for me, and is also about wrong mangled function name in c++ on AVR.

The previous patch has correctly handled __UINT8/16/32/64_TYPE__,but current 
clang-avr still be wrong at int8/16/32/64_t, the underlying cause is the 
system's stdint.h is used first, which it should be avr-libc's stdint.h going 
first. (avr-g++ does so)

The patch fixes that issue, which add avr-libc to clang-avr toolchain's include 
path.

Thanks for your help!!


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

https://reviews.llvm.org/D97669

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


[PATCH] D102568: [Driver] Delete -mimplicit-it=

2021-05-17 Thread Khem Raj via Phabricator via cfe-commits
raj.khem accepted this revision.
raj.khem added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102568

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


[PATCH] D102638: [NFC] Pass GV value type instead of pointer type to GetOrCreateLLVMGlobal

2021-05-17 Thread Arthur Eubanks 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 rG9f7d552cff8d: [NFC] Pass GV value type instead of pointer 
type to GetOrCreateLLVMGlobal (authored by aeubanks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102638

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h

Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,11 +1477,10 @@
   const FunctionDecl *FD);
   void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD);
 
-  llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
-llvm::PointerType *PTy,
-const VarDecl *D,
-ForDefinition_t IsForDefinition
-  = NotForDefinition);
+  llvm::Constant *
+  GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
+unsigned AddrSpace, const VarDecl *D,
+ForDefinition_t IsForDefinition = NotForDefinition);
 
   bool GetCPUAndFeaturesAttributes(GlobalDecl GD,
llvm::AttrBuilder &AttrBuilder);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2808,9 +2808,7 @@
   GlobalDecl(cast(VD)),
   /*ForVTable=*/false);
   else
-Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
-llvm::PointerType::getUnqual(DeclTy),
-nullptr);
+Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), DeclTy, 0, nullptr);
 
   auto *F = cast(Aliasee);
   F->setLinkage(llvm::Function::ExternalWeakLinkage);
@@ -3772,9 +3770,9 @@
 }
 
 /// GetOrCreateLLVMGlobal - If the specified mangled name is not in the module,
-/// create and return an llvm GlobalVariable with the specified type.  If there
-/// is something in the module with the specified name, return it potentially
-/// bitcasted to the right type.
+/// create and return an llvm GlobalVariable with the specified type and address
+/// space. If there is something in the module with the specified name, return
+/// it potentially bitcasted to the right type.
 ///
 /// If D is non-null, it specifies a decl that correspond to this.  This is used
 /// to set the attributes on the global when it is first created.
@@ -3783,9 +3781,8 @@
 /// type Ty will be returned, not conversion of a variable with the same
 /// mangled name but some other type.
 llvm::Constant *
-CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
- llvm::PointerType *Ty,
- const VarDecl *D,
+CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
+ unsigned AddrSpace, const VarDecl *D,
  ForDefinition_t IsForDefinition) {
   // Lookup the entry, lazily creating it if necessary.
   llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
@@ -3802,7 +3799,7 @@
 if (LangOpts.OpenMP && !LangOpts.OpenMPSimd && D)
   getOpenMPRuntime().registerTargetGlobalVariable(D, Entry);
 
-if (Entry->getType() == Ty)
+if (Entry->getValueType() == Ty && Entry->getAddressSpace() == AddrSpace)
   return Entry;
 
 // If there are two attempts to define the same mangled name, issue an
@@ -3826,22 +3823,24 @@
 }
 
 // Make sure the result is of the correct type.
-if (Entry->getType()->getAddressSpace() != Ty->getAddressSpace())
-  return llvm::ConstantExpr::getAddrSpaceCast(Entry, Ty);
+if (Entry->getType()->getAddressSpace() != AddrSpace) {
+  return llvm::ConstantExpr::getAddrSpaceCast(Entry,
+  Ty->getPointerTo(AddrSpace));
+}
 
 // (If global is requested for a definition, we always need to create a new
 // global, not just return a bitcast.)
 if (!IsForDefinition)
-  return llvm::ConstantExpr::getBitCast(Entry, Ty);
+  return llvm::ConstantExpr::getBitCast(Entry, Ty->getPointerTo(AddrSpace));
   }
 
-  auto AddrSpace = GetGlobalVarAddressSpace(D);
-  auto TargetAddrSpace = getContext().getTargetAddressSpace(AddrSpace);
+  auto DAddrSpace = GetGlobalVarAddressSpace(D);
+  auto TargetAddrSpace = getContext().getTargetAddressSpace(DAddrSpace);
 
   auto *GV = new llvm::GlobalVariable(
-  getModule(), Ty->getElementType(), false,
-  ll

[clang] 9f7d552 - [NFC] Pass GV value type instead of pointer type to GetOrCreateLLVMGlobal

2021-05-17 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2021-05-17T18:41:17-07:00
New Revision: 9f7d552cff8d62250461ef396d9d4ffab4ecd378

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

LOG: [NFC] Pass GV value type instead of pointer type to GetOrCreateLLVMGlobal

For opaque pointers, to avoid PointerType::getElementType().

Reviewed By: dblaikie

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

Added: 


Modified: 
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index cc9be87961e7..e5286761ee81 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -2939,9 +2939,8 @@ llvm::Constant *CodeGenModule::getNSConcreteGlobalBlock() 
{
   if (NSConcreteGlobalBlock)
 return NSConcreteGlobalBlock;
 
-  NSConcreteGlobalBlock = GetOrCreateLLVMGlobal("_NSConcreteGlobalBlock",
-Int8PtrTy->getPointerTo(),
-nullptr);
+  NSConcreteGlobalBlock =
+  GetOrCreateLLVMGlobal("_NSConcreteGlobalBlock", Int8PtrTy, 0, nullptr);
   configureBlocksRuntimeObject(*this, NSConcreteGlobalBlock);
   return NSConcreteGlobalBlock;
 }
@@ -2950,9 +2949,8 @@ llvm::Constant *CodeGenModule::getNSConcreteStackBlock() {
   if (NSConcreteStackBlock)
 return NSConcreteStackBlock;
 
-  NSConcreteStackBlock = GetOrCreateLLVMGlobal("_NSConcreteStackBlock",
-   Int8PtrTy->getPointerTo(),
-   nullptr);
+  NSConcreteStackBlock =
+  GetOrCreateLLVMGlobal("_NSConcreteStackBlock", Int8PtrTy, 0, nullptr);
   configureBlocksRuntimeObject(*this, NSConcreteStackBlock);
   return NSConcreteStackBlock;
 }

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index b408ea30e423..8ce33c3124ca 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2808,9 +2808,7 @@ ConstantAddress CodeGenModule::GetWeakRefReference(const 
ValueDecl *VD) {
   GlobalDecl(cast(VD)),
   /*ForVTable=*/false);
   else
-Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
-llvm::PointerType::getUnqual(DeclTy),
-nullptr);
+Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), DeclTy, 0, nullptr);
 
   auto *F = cast(Aliasee);
   F->setLinkage(llvm::Function::ExternalWeakLinkage);
@@ -3772,9 +3770,9 @@ bool CodeGenModule::isTypeConstant(QualType Ty, bool 
ExcludeCtor) {
 }
 
 /// GetOrCreateLLVMGlobal - If the specified mangled name is not in the module,
-/// create and return an llvm GlobalVariable with the specified type.  If there
-/// is something in the module with the specified name, return it potentially
-/// bitcasted to the right type.
+/// create and return an llvm GlobalVariable with the specified type and 
address
+/// space. If there is something in the module with the specified name, return
+/// it potentially bitcasted to the right type.
 ///
 /// If D is non-null, it specifies a decl that correspond to this.  This is 
used
 /// to set the attributes on the global when it is first created.
@@ -3783,9 +3781,8 @@ bool CodeGenModule::isTypeConstant(QualType Ty, bool 
ExcludeCtor) {
 /// type Ty will be returned, not conversion of a variable with the same
 /// mangled name but some other type.
 llvm::Constant *
-CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
- llvm::PointerType *Ty,
- const VarDecl *D,
+CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
+ unsigned AddrSpace, const VarDecl *D,
  ForDefinition_t IsForDefinition) {
   // Lookup the entry, lazily creating it if necessary.
   llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
@@ -3802,7 +3799,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName,
 if (LangOpts.OpenMP && !LangOpts.OpenMPSimd && D)
   getOpenMPRuntime().registerTargetGlobalVariable(D, Entry);
 
-if (Entry->getType() == Ty)
+if (Entry->getValueType() == Ty && Entry->getAddressSpace() == AddrSpace)
   return Entry;
 
 // If there are two attempts to define the same mangled name, issue an
@@ -3826,22 +3823,24 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName,
 }
 
 // Make sure the result is of the correct type.
-if (Entry->getType()->getAddressSpace() != Ty->getAddressSpace())
-  return llvm::ConstantExpr::g

[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

2021-05-17 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D96033#2762182 , @v.g.vassilev 
wrote:

> That patch should probably get us to a point where we can mark the test as 
> `XFAIL: system-aix`

I've applied that patch to my 64-bit LLVM build and it does cause the object 
writer to be used (which generates the "64-bit XCOFF object files" error seen 
before).

> If that works on your platform I will happily open a review for the changes.

From the behaviour observed in the 64-bit build, the 32-bit case might not fail 
similarly. I need to see if I can get a 32-bit build going. For now, the patch 
would be welcome (without changing from `UNSUPPORTED` to `XFAIL`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96033

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


[PATCH] D102558: [Utils] Check for generated functions inline if possible

2021-05-17 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: 
clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected:100
+  }
+}

ggeorgakoudis wrote:
> The checks for the outlined function are missing?
Good catch. It turns out functions that showed up in 
line2spell_and_mangled_list multiple times confused the script. I needed to 
skip duplicates. Fixed now.



Comment at: 
clang/test/utils/update_cc_test_checks/Inputs/lots-of-generated-funcs.c.lots-of-generated.expected:8
+// OMP-NEXT:  entry:
+// OMP-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1:[0-9]+]], i32 0, void (i32*, 
i32*, ...)* bitcast (void (i32*, i32*)* @.omp_outlined. to void (i32*, i32*, 
...)*))
+// OMP-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*)* @.omp_outlined..1 to void (i32*, i32*, ...)*))

ggeorgakoudis wrote:
> Checks for .ompu_outlined. are missing
same as above :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102558

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


[PATCH] D102558: [Utils] Check for generated functions inline if possible

2021-05-17 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 346030.
jdoerfert marked 4 inline comments as done.
jdoerfert added a comment.

Skip duplicates in the line2spell_and_mangled_list as that causes functions to 
be missed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102558

Files:
  clang/test/utils/update_cc_test_checks/Inputs/generated-funcs-regex.c.expected
  
clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected
  clang/test/utils/update_cc_test_checks/Inputs/lots-of-generated-funcs.c
  
clang/test/utils/update_cc_test_checks/Inputs/lots-of-generated-funcs.c.lots-of-generated.expected
  
clang/test/utils/update_cc_test_checks/Inputs/lots-of-generated-funcs.c.no-lots-of-generated.expected
  clang/test/utils/update_cc_test_checks/lots-of-generated-funcs.test
  llvm/utils/UpdateTestChecks/common.py
  llvm/utils/update_cc_test_checks.py
  llvm/utils/update_test_checks.py

Index: llvm/utils/update_test_checks.py
===
--- llvm/utils/update_test_checks.py
+++ llvm/utils/update_test_checks.py
@@ -138,6 +138,9 @@
   '--include-generated-funcs',
   True)
 
+# TODO: use common.get_total_function_order to avoid adding new functions at the end but
+#   instead place them in order between existing ones. See the CC script.
+
 if include_generated_funcs:
   # Generate the appropriate checks for each function.  We need to emit
   # these in the order according to the generated output so that CHECK-LABEL
Index: llvm/utils/update_cc_test_checks.py
===
--- llvm/utils/update_cc_test_checks.py
+++ llvm/utils/update_cc_test_checks.py
@@ -305,8 +305,9 @@
   lambda args: ti.args.include_generated_funcs,
   '--include-generated-funcs',
   True)
+total_function_order = common.get_total_function_order(filecheck_run_list, builder.func_order())
 
-if include_generated_funcs:
+if include_generated_funcs and not total_function_order:
   # Generate the appropriate checks for each function.  We need to emit
   # these in the order according to the generated output so that CHECK-LABEL
   # works properly.  func_order provides that.
@@ -337,6 +338,62 @@
check_generator(my_output_lines,
prefixes, func))
 else:
+  trailing_functions = []
+  # If we might have generated functions we need to place them in the right position now,
+  # trailing ones are kept separate though.
+  if include_generated_funcs:
+seen_mangled = set()
+total_order_idx = 0
+for line in line2spell_and_mangled_list.keys():
+  to_be_added = []
+  for spell, mangled in line2spell_and_mangled_list[line]:
+if mangled not in total_function_order or mangled in seen_mangled:
+  continue
+seen_mangled.add(mangled)
+
+# Figure out where this existing function is in the total order. All functions we
+# skipped are inserted before this one.
+index = total_function_order.index(mangled)
+while total_order_idx < index:
+  to_be_added.append(total_function_order[total_order_idx])
+  total_order_idx += 1
+# Account for the function itself (spell, mangled)
+total_order_idx += 1
+  # Reverse the order to match total order again before we insert the functions
+  # in the current line.
+  to_be_added.reverse()
+  for tba in to_be_added:
+line2spell_and_mangled_list[line].insert(0, ('', tba))
+
+# All functions we have not handled yet are added to the end.
+while total_order_idx < len(total_function_order):
+  func = total_function_order[total_order_idx]
+  trailing_functions.append(func)
+  total_order_idx += 1
+
+  def handle_functions_on_line(output_lines, line, args, spell, mangled, added, include_line):
+# One line may contain multiple function declarations.
+# Skip if the mangled name has been added before.
+# The line number may come from an included file,
+# we simply require the spelling name to appear on the line
+# to exclude functions from other files.
+if mangled in added or (spell and spell not in line):
+  return
+if args.functions is None or any(re.search(regex, spell) for regex in args.functions):
+  last_line = output_lines[-1].strip()
+  while last_line == '//':
+# Remove the comment line since we 

[PATCH] D102558: [Utils] Check for generated functions inline if possible

2021-05-17 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis added inline comments.



Comment at: 
clang/test/utils/update_cc_test_checks/Inputs/generated-funcs.c.generated.expected:100
+  }
+}

The checks for the outlined function are missing?



Comment at: 
clang/test/utils/update_cc_test_checks/Inputs/lots-of-generated-funcs.c.lots-of-generated.expected:8
+// OMP-NEXT:  entry:
+// OMP-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1:[0-9]+]], i32 0, void (i32*, 
i32*, ...)* bitcast (void (i32*, i32*)* @.omp_outlined. to void (i32*, i32*, 
...)*))
+// OMP-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*)* @.omp_outlined..1 to void (i32*, i32*, ...)*))

Checks for .ompu_outlined. are missing



Comment at: 
clang/test/utils/update_cc_test_checks/Inputs/lots-of-generated-funcs.c.lots-of-generated.expected:47
+// OMP-NEXT:  entry:
+// OMP-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*)* @.omp_outlined..3 to void (i32*, i32*, ...)*))
+// OMP-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*)* @.omp_outlined..4 to void (i32*, i32*, ...)*))

Checks for .omp_outlined..3 are missing



Comment at: 
clang/test/utils/update_cc_test_checks/Inputs/lots-of-generated-funcs.c.lots-of-generated.expected:86
+// OMP-NEXT:  entry:
+// OMP-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*)* @.omp_outlined..6 to void (i32*, i32*, ...)*))
+// OMP-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*)* @.omp_outlined..7 to void (i32*, i32*, ...)*))

Checks for .omp_outlined..6 are missing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102558

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


[PATCH] D101849: [OpenMP][NFC] Refactor Clang OpenMP tests using update_cc_test_checks

2021-05-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D101849#2764798 , @jdoerfert wrote:

> In D101849#2764703 , @mikerice 
> wrote:
>
>>> // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -O1 -fopenmp-simd 
>>> -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK10
>>
>> Is there a good reason to run this with -O1?  Doing so makes it super 
>> sensitive to which llvm passes run and now this test fails for us now with 
>> x86 as well.
>
> One of the O1  was introduced by 
> 6e8248fdad5fc59306beb286a3089fe401460826 and I cannot really tell why we 
> would need it.
> @ABataev do you remember if the O1 
>  was needed?
> If not I'd suggest to remove the O1 
>  run line or add 
> -disable-llvm-optzns to the run line.
> If it is needed, we can have a simple parallel for test with manual check 
> lines.

No, it is not required. Most probably, needed to simplify test checks, nothing 
else.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101849

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


[PATCH] D101849: [OpenMP][NFC] Refactor Clang OpenMP tests using update_cc_test_checks

2021-05-17 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a subscriber: ABataev.
jdoerfert added a comment.

In D101849#2764703 , @mikerice wrote:

>> // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -O1 -fopenmp-simd 
>> -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK10
>
> Is there a good reason to run this with -O1?  Doing so makes it super 
> sensitive to which llvm passes run and now this test fails for us now with 
> x86 as well.

One of the O1  was introduced by 
6e8248fdad5fc59306beb286a3089fe401460826 and I cannot really tell why we would 
need it.
@ABataev do you remember if the O1  
was needed?
If not I'd suggest to remove the O1 
 run line or add 
-disable-llvm-optzns to the run line.
If it is needed, we can have a simple parallel for test with manual check lines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101849

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


[PATCH] D102640: [ASTimporter] Remove decl from lookup only if it has decl context

2021-05-17 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

This is a good catch, thank you for fixing this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102640

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


[PATCH] D102654: [DebugInfo][test] Check specific func name to ignore codegen differences

2021-05-17 Thread Jinsong Ji via Phabricator via cfe-commits
jsji marked an inline comment as done.
jsji added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-line.cpp:149
 
-// CHECK-LABEL: define
+// CHECK-LABEL: f11
 __complex double f11() {

dblaikie wrote:
> Probably flesh that out a bit. Maybe `define{{.*}}f11`?
Good idea.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102654

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


[PATCH] D102654: [DebugInfo][test] Check specific func name to ignore codegen differences

2021-05-17 Thread Jinsong Ji via Phabricator via cfe-commits
jsji updated this revision to Diff 346011.
jsji added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102654

Files:
  clang/test/CodeGenCXX/debug-info-line.cpp


Index: clang/test/CodeGenCXX/debug-info-line.cpp
===
--- clang/test/CodeGenCXX/debug-info-line.cpp
+++ clang/test/CodeGenCXX/debug-info-line.cpp
@@ -146,7 +146,7 @@
 (fn(),   //
  bar())};
 
-// CHECK-LABEL: define
+// CHECK-LABEL: define{{.*}}f11
 __complex double f11() {
   __complex double f;
 // CHECK: store {{.*}} !dbg [[DBG_F11:!.*]]


Index: clang/test/CodeGenCXX/debug-info-line.cpp
===
--- clang/test/CodeGenCXX/debug-info-line.cpp
+++ clang/test/CodeGenCXX/debug-info-line.cpp
@@ -146,7 +146,7 @@
 (fn(),   //
  bar())};
 
-// CHECK-LABEL: define
+// CHECK-LABEL: define{{.*}}f11
 __complex double f11() {
   __complex double f;
 // CHECK: store {{.*}} !dbg [[DBG_F11:!.*]]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102531: PR45881: Properly use CXXThisOverride for templated lambda

2021-05-17 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 346010.
ychen added a comment.

- Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102531

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
  clang/test/SemaCXX/cxx2a-lambda-decltype-this.cpp

Index: clang/test/SemaCXX/cxx2a-lambda-decltype-this.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-lambda-decltype-this.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -emit-llvm-only %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -fdelayed-template-parsing %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -fms-extensions %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s
+
+namespace PR45881 {
+struct A {
+void f();
+};
+int id(A*);
+void A::f() {
+auto z = [*this](auto z2, decltype(z2(this)) z3){};
+z(id,3);
+}
+
+struct B {
+void f();
+};
+void B::f() {
+auto z = [](){return 0;};
+z.template operator()();
+}
+
+struct C {
+void f();
+};
+void C::f() {
+auto z = [](){return 0;};
+z.template operator()();
+}
+} // namespace PR45881
Index: clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
===
--- clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -298,3 +298,13 @@
 
 } // namespace PR32831
 
+namespace PR45881 {
+struct A {
+void f();
+};
+int id(A*);
+void A::f() {
+auto z = [*this](auto z2, decltype(z2(this)) z3){};
+z(id,3);
+}
+} // namespace PR45881
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2858,9 +2858,24 @@
   return Sema::TDK_Incomplete;
 }
 
-TemplateArgumentLoc DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
-TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
-HasDefaultArg);
+TemplateArgumentLoc DefArg;
+{
+  Qualifiers ThisTypeQuals;
+  CXXRecordDecl *ThisContext = nullptr;
+  if (auto *Rec = dyn_cast(TD->getDeclContext()))
+if (Rec->isLambda())
+  if (auto *Method = dyn_cast(Rec->getDeclContext())) {
+ThisContext = Method->getParent();
+ThisTypeQuals = Method->getMethodQualifiers();
+  }
+
+  Sema::CXXThisScopeRAII ThisScope(S, ThisContext, ThisTypeQuals,
+   S.getLangOpts().CPlusPlus17);
+
+  DefArg = S.SubstDefaultTemplateArgumentIfAvailable(
+  TD, TD->getLocation(), TD->getSourceRange().getEnd(), Param, Builder,
+  HasDefaultArg);
+}
 
 // If there was no default argument, deduction is incomplete.
 if (DefArg.getArgument().isNull()) {
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5090,7 +5090,11 @@
 for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
   TemplateArgLists.addOuterTemplateArguments(None);
 
-Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
+bool ForLambdaCallOperator = false;
+if (const auto *Rec = dyn_cast(Template->getDeclContext()))
+  ForLambdaCallOperator = Rec->isLambda();
+Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext(),
+   !ForLambdaCallOperator);
 ArgType =
 SemaRef.SubstType(ArgType, TemplateArgLists,
   Param->getDefaultArgumentLoc(), Param->getDeclName());
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1119,11 +1119,10 @@
 }
   }
 
-  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which can
-  // happen during instantiation of its nested generic lambda call operator)
-  if (isLambdaCallOperator(CurDC)) {
-assert(CurLSI && "While computing 'this' capture-type for a generic "
- "lambda, we must have a corresponding LambdaScopeInfo");
+  // 2) We've run out of ScopeInfos but check 1. if CurDC is a lambda (which
+  //can happen during instantiation of its nested generic lambda call
+  //operator); 2. if we're in a lambda scope (lambda body).
+  if (CurLSI && isLambdaCallOperator(CurDC)) {
 assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) &&
"While computing 'this' capture-type for a generic lambda, when we "
"run out of enclosing LSI's, yet the enclosing D

[PATCH] D102547: [clang][AVR] Redefine [u]int16_t to be compatible with avr-gcc

2021-05-17 Thread Ben Shi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb99e2c56166a: [clang][AVR] Redefine [u]int16_t to be 
compatible with avr-gcc (authored by benshi001).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102547

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/AVR.h
  clang/lib/Frontend/InitPreprocessor.cpp


Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -216,6 +216,11 @@
   if (TypeWidth == 64)
 Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
 
+  // Use the target specified int16 type when appropriate. Some MCU targets
+  // (such as AVR) have definition of [u]int16_t to [un]signed int.
+  if (TypeWidth == 16)
+Ty = IsSigned ? TI.getInt16Type() : TI.getUInt16Type();
+
   const char *Prefix = IsSigned ? "__INT" : "__UINT";
 
   DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
Index: clang/lib/Basic/Targets/AVR.h
===
--- clang/lib/Basic/Targets/AVR.h
+++ clang/lib/Basic/Targets/AVR.h
@@ -52,6 +52,7 @@
 IntPtrType = SignedInt;
 Char16Type = UnsignedInt;
 WIntType = SignedInt;
+Int16Type = SignedInt;
 Char32Type = UnsignedLong;
 SigAtomicType = SignedChar;
 resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
Index: clang/lib/Basic/Targets/AVR.cpp
===
--- clang/lib/Basic/Targets/AVR.cpp
+++ clang/lib/Basic/Targets/AVR.cpp
@@ -309,8 +309,6 @@
   Builder.defineMacro("__AVR__");
   Builder.defineMacro("__ELF__");
   Builder.defineMacro("__flash", "__attribute__((address_space(1)))");
-  Builder.defineMacro("__UINT16_TYPE__", "unsigned int");
-  Builder.defineMacro("__INT16_TYPE__", "int");
 
   if (!this->CPU.empty()) {
 auto It = llvm::find_if(
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -98,6 +98,7 @@
   Char16Type = UnsignedShort;
   Char32Type = UnsignedInt;
   Int64Type = SignedLongLong;
+  Int16Type = SignedShort;
   SigAtomicType = SignedInt;
   ProcessIDType = SignedInt;
   UseSignedCharForObjCBool = true;
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -129,9 +129,9 @@
 Float128
   };
 protected:
-  IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
-  WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
-  ProcessIDType;
+  IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType, WIntType,
+  Char16Type, Char32Type, Int64Type, Int16Type, SigAtomicType,
+  ProcessIDType;
 
   /// Whether Objective-C's built-in boolean type should be signed char.
   ///
@@ -351,6 +351,10 @@
   IntType getUInt64Type() const {
 return getCorrespondingUnsignedType(Int64Type);
   }
+  IntType getInt16Type() const { return Int16Type; }
+  IntType getUInt16Type() const {
+return getCorrespondingUnsignedType(Int16Type);
+  }
   IntType getSigAtomicType() const { return SigAtomicType; }
   IntType getProcessIDType() const { return ProcessIDType; }
 


Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -216,6 +216,11 @@
   if (TypeWidth == 64)
 Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
 
+  // Use the target specified int16 type when appropriate. Some MCU targets
+  // (such as AVR) have definition of [u]int16_t to [un]signed int.
+  if (TypeWidth == 16)
+Ty = IsSigned ? TI.getInt16Type() : TI.getUInt16Type();
+
   const char *Prefix = IsSigned ? "__INT" : "__UINT";
 
   DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
Index: clang/lib/Basic/Targets/AVR.h
===
--- clang/lib/Basic/Targets/AVR.h
+++ clang/lib/Basic/Targets/AVR.h
@@ -52,6 +52,7 @@
 IntPtrType = SignedInt;
 Char16Type = UnsignedInt;
 WIntType = SignedInt;
+Int16Type = SignedInt;
 Char32Type = UnsignedLong;
 SigAtomicType = SignedChar;
 resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
Index: clang/lib/Basic/Targets/AVR.cpp
===
--- clang/lib/Basic/Targets/AVR.cpp
+++ clang/lib/Basic/Targets/AVR.cpp
@@ -309,8 +309,6 @@
   Builder.defineMacro("__AVR__");
   Builder.defineMacro(

[clang] b99e2c5 - [clang][AVR] Redefine [u]int16_t to be compatible with avr-gcc

2021-05-17 Thread Ben Shi via cfe-commits

Author: Ben Shi
Date: 2021-05-18T07:06:12+08:00
New Revision: b99e2c56166a3a74ac9c49512c584d5b158ac9c6

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

LOG: [clang][AVR] Redefine [u]int16_t to be compatible with avr-gcc

Reviewed By: efriedma

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

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/AVR.cpp
clang/lib/Basic/Targets/AVR.h
clang/lib/Frontend/InitPreprocessor.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 532ff4554656c..b55a99051cfbd 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -129,9 +129,9 @@ struct TransferrableTargetInfo {
 Float128
   };
 protected:
-  IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
-  WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
-  ProcessIDType;
+  IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType, WIntType,
+  Char16Type, Char32Type, Int64Type, Int16Type, SigAtomicType,
+  ProcessIDType;
 
   /// Whether Objective-C's built-in boolean type should be signed char.
   ///
@@ -351,6 +351,10 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   IntType getUInt64Type() const {
 return getCorrespondingUnsignedType(Int64Type);
   }
+  IntType getInt16Type() const { return Int16Type; }
+  IntType getUInt16Type() const {
+return getCorrespondingUnsignedType(Int16Type);
+  }
   IntType getSigAtomicType() const { return SigAtomicType; }
   IntType getProcessIDType() const { return ProcessIDType; }
 

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 2f200a9bb3e8a..e73b4a3a40c74 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -98,6 +98,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), 
Triple(T) {
   Char16Type = UnsignedShort;
   Char32Type = UnsignedInt;
   Int64Type = SignedLongLong;
+  Int16Type = SignedShort;
   SigAtomicType = SignedInt;
   ProcessIDType = SignedInt;
   UseSignedCharForObjCBool = true;

diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index 86fda19869a86..e87b7338c4d6e 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -309,8 +309,6 @@ void AVRTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("__AVR__");
   Builder.defineMacro("__ELF__");
   Builder.defineMacro("__flash", "__attribute__((address_space(1)))");
-  Builder.defineMacro("__UINT16_TYPE__", "unsigned int");
-  Builder.defineMacro("__INT16_TYPE__", "int");
 
   if (!this->CPU.empty()) {
 auto It = llvm::find_if(

diff  --git a/clang/lib/Basic/Targets/AVR.h b/clang/lib/Basic/Targets/AVR.h
index 94f006ee1b8a6..89a80ca6a39a3 100644
--- a/clang/lib/Basic/Targets/AVR.h
+++ b/clang/lib/Basic/Targets/AVR.h
@@ -52,6 +52,7 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public 
TargetInfo {
 IntPtrType = SignedInt;
 Char16Type = UnsignedInt;
 WIntType = SignedInt;
+Int16Type = SignedInt;
 Char32Type = UnsignedLong;
 SigAtomicType = SignedChar;
 resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 41b08ed56134a..163c77b04c139 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -216,6 +216,11 @@ static void DefineExactWidthIntType(TargetInfo::IntType Ty,
   if (TypeWidth == 64)
 Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
 
+  // Use the target specified int16 type when appropriate. Some MCU targets
+  // (such as AVR) have definition of [u]int16_t to [un]signed int.
+  if (TypeWidth == 16)
+Ty = IsSigned ? TI.getInt16Type() : TI.getUInt16Type();
+
   const char *Prefix = IsSigned ? "__INT" : "__UINT";
 
   DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);



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


[PATCH] D101793: [clang][AST] Improve AST Reader/Writer memory footprint

2021-05-17 Thread Wei Wang via Phabricator via cfe-commits
weiwang added a comment.

In D101793#2760639 , @yaxunl wrote:

> I think the root cause might be duplicated decls are added to 
> Sema::DeclsToCheckForDeferredDiags defined in
>
> https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Sema/Sema.h#L1789
>
> When compiling source codes, a decl is added only once. However if modules 
> are imported, duplicate decls may be added.
>
> We need to avoid adding duplicate decls to 
> Sema::DeclsToCheckForDeferredDiags. However we cannot simply change it to a 
> set since the order is important, otherwise the error message for later code 
> may show up earlier, causing confusion for users. I would suggest to change 
> its type to SetVector, which keeps the order and also avoids duplicates.

Thanks for the suggestion! It does make more sense to use SetVector here. I 
will try this and report back.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101793

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


[PATCH] D101849: [OpenMP][NFC] Refactor Clang OpenMP tests using update_cc_test_checks

2021-05-17 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

> // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -O1 -fopenmp-simd 
> -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK10

Is there a good reason to run this with -O1?  Doing so makes it super sensitive 
to which llvm passes run and now this test fails for us now with x86 as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101849

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


[PATCH] D102638: [NFC] Pass GV value type instead of pointer type to GetOrCreateLLVMGlobal

2021-05-17 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102638

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


[PATCH] D100671: [ADT] Factor out in_place_t and expose in Optional ctor

2021-05-17 Thread Scott Linder 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 rGaf5247c9347d: [ADT] Factor out in_place_t and expose in 
Optional ctor (authored by scott.linder).

Changed prior to commit:
  https://reviews.llvm.org/D100671?vs=345475&id=346003#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100671

Files:
  clang/include/clang/Basic/DirectoryEntry.h
  llvm/include/llvm/ADT/Optional.h
  llvm/include/llvm/ADT/STLForwardCompat.h
  llvm/unittests/ADT/OptionalTest.cpp

Index: llvm/unittests/ADT/OptionalTest.cpp
===
--- llvm/unittests/ADT/OptionalTest.cpp
+++ llvm/unittests/ADT/OptionalTest.cpp
@@ -195,6 +195,14 @@
   EXPECT_EQ(0u, NonDefaultConstructible::Destructions);
 }
 
+TEST(OptionalTest, InPlaceConstructionNonDefaultConstructibleTest) {
+  NonDefaultConstructible::ResetCounts();
+  { Optional A{in_place, 1}; }
+  EXPECT_EQ(0u, NonDefaultConstructible::CopyConstructions);
+  EXPECT_EQ(0u, NonDefaultConstructible::CopyAssignments);
+  EXPECT_EQ(1u, NonDefaultConstructible::Destructions);
+}
+
 TEST(OptionalTest, GetValueOr) {
   Optional A;
   EXPECT_EQ(42, A.getValueOr(42));
@@ -214,6 +222,11 @@
   MultiArgConstructor &operator=(const MultiArgConstructor &) = delete;
   MultiArgConstructor &operator=(MultiArgConstructor &&) = delete;
 
+  friend bool operator==(const MultiArgConstructor &LHS,
+ const MultiArgConstructor &RHS) {
+return LHS.x == RHS.x && LHS.y == RHS.y;
+  }
+
   static unsigned Destructions;
   ~MultiArgConstructor() {
 ++Destructions;
@@ -244,6 +257,34 @@
   EXPECT_EQ(1u, MultiArgConstructor::Destructions);
 }
 
+TEST(OptionalTest, InPlaceConstructionMultiArgConstructorTest) {
+  MultiArgConstructor::ResetCounts();
+  {
+Optional A{in_place, 1, 2};
+EXPECT_TRUE(A.hasValue());
+EXPECT_EQ(1, A->x);
+EXPECT_EQ(2, A->y);
+Optional B{in_place, 5, false};
+EXPECT_TRUE(B.hasValue());
+EXPECT_EQ(5, B->x);
+EXPECT_EQ(-5, B->y);
+EXPECT_EQ(0u, MultiArgConstructor::Destructions);
+  }
+  EXPECT_EQ(2u, MultiArgConstructor::Destructions);
+}
+
+TEST(OptionalTest, InPlaceConstructionAndEmplaceEquivalentTest) {
+  MultiArgConstructor::ResetCounts();
+  {
+Optional A{in_place, 1, 2};
+Optional B;
+B.emplace(1, 2);
+EXPECT_EQ(0u, MultiArgConstructor::Destructions);
+ASSERT_EQ(A, B);
+  }
+  EXPECT_EQ(2u, MultiArgConstructor::Destructions);
+}
+
 struct MoveOnly {
   static unsigned MoveConstructions;
   static unsigned Destructions;
@@ -391,6 +432,15 @@
   EXPECT_EQ(0u, Immovable::Destructions);
 }
 
+TEST(OptionalTest, ImmovableInPlaceConstruction) {
+  Immovable::ResetCounts();
+  Optional A{in_place, 4};
+  EXPECT_TRUE((bool)A);
+  EXPECT_EQ(4, A->val);
+  EXPECT_EQ(1u, Immovable::Constructions);
+  EXPECT_EQ(0u, Immovable::Destructions);
+}
+
 // Craft a class which is_trivially_copyable, but not
 // is_trivially_copy_constructible.
 struct NonTCopy {
Index: llvm/include/llvm/ADT/STLForwardCompat.h
===
--- llvm/include/llvm/ADT/STLForwardCompat.h
+++ llvm/include/llvm/ADT/STLForwardCompat.h
@@ -44,6 +44,25 @@
 struct disjunction
 : std::conditional>::type {};
 
+struct in_place_t // NOLINT(readability-identifier-naming)
+{
+  explicit in_place_t() = default;
+};
+/// \warning This must not be odr-used, as it cannot be made \c inline in C++14.
+constexpr in_place_t in_place; // NOLINT(readability-identifier-naming)
+
+template 
+struct in_place_type_t // NOLINT(readability-identifier-naming)
+{
+  explicit in_place_type_t() = default;
+};
+
+template 
+struct in_place_index_t // NOLINT(readability-identifier-naming)
+{
+  explicit in_place_index_t() = default;
+};
+
 //===--===//
 // Features from C++20
 //===--===//
Index: llvm/include/llvm/ADT/Optional.h
===
--- llvm/include/llvm/ADT/Optional.h
+++ llvm/include/llvm/ADT/Optional.h
@@ -17,6 +17,7 @@
 
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/None.h"
+#include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/type_traits.h"
 #include 
@@ -30,8 +31,6 @@
 
 namespace optional_detail {
 
-struct in_place_t {};
-
 /// Storage for any type.
 //
 // The specialization condition intentionally uses
@@ -245,13 +244,16 @@
   constexpr Optional() {}
   constexpr Optional(NoneType) {}
 
-  constexpr Optional(const T &y) : Storage(optional_detail::in_place_t{}, y) {}
+  constexpr Optional(const T &y) : Storage(in_place, y) {}
   constexpr Optional(const Optional &O) = default;
 
-  constexpr Optional(T &&y)
-  : Storage(opti

[clang] af5247c - [ADT] Factor out in_place_t and expose in Optional ctor

2021-05-17 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2021-05-17T22:25:39Z
New Revision: af5247c9347dcf1e30443786bdddf23ca705867a

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

LOG: [ADT] Factor out in_place_t and expose in Optional ctor

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

Added: 


Modified: 
clang/include/clang/Basic/DirectoryEntry.h
llvm/include/llvm/ADT/Optional.h
llvm/include/llvm/ADT/STLForwardCompat.h
llvm/unittests/ADT/OptionalTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DirectoryEntry.h 
b/clang/include/clang/Basic/DirectoryEntry.h
index e0f4ae28321a3..edb8031a20b80 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -120,8 +120,7 @@ template  class MapEntryOptionalStorage {
   MapEntryOptionalStorage() : MaybeRef(optional_none_tag()) {}
 
   template 
-  explicit MapEntryOptionalStorage(llvm::optional_detail::in_place_t,
-   ArgTypes &&...Args)
+  explicit MapEntryOptionalStorage(llvm::in_place_t, ArgTypes &&...Args)
   : MaybeRef(std::forward(Args)...) {}
 
   void reset() { MaybeRef = optional_none_tag(); }

diff  --git a/llvm/include/llvm/ADT/Optional.h 
b/llvm/include/llvm/ADT/Optional.h
index 67bd1f5f1a542..cdbf2e3532419 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -17,6 +17,7 @@
 
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/None.h"
+#include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/type_traits.h"
 #include 
@@ -30,8 +31,6 @@ class raw_ostream;
 
 namespace optional_detail {
 
-struct in_place_t {};
-
 /// Storage for any type.
 //
 // The specialization condition intentionally uses
@@ -245,13 +244,16 @@ template  class Optional {
   constexpr Optional() {}
   constexpr Optional(NoneType) {}
 
-  constexpr Optional(const T &y) : Storage(optional_detail::in_place_t{}, y) {}
+  constexpr Optional(const T &y) : Storage(in_place, y) {}
   constexpr Optional(const Optional &O) = default;
 
-  constexpr Optional(T &&y)
-  : Storage(optional_detail::in_place_t{}, std::move(y)) {}
+  constexpr Optional(T &&y) : Storage(in_place, std::move(y)) {}
   constexpr Optional(Optional &&O) = default;
 
+  template 
+  constexpr Optional(in_place_t, ArgTypes &&...Args)
+  : Storage(in_place, std::forward(Args)...) {}
+
   Optional &operator=(T &&y) {
 Storage = std::move(y);
 return *this;

diff  --git a/llvm/include/llvm/ADT/STLForwardCompat.h 
b/llvm/include/llvm/ADT/STLForwardCompat.h
index 83ce6d3f68694..440b29df260ca 100644
--- a/llvm/include/llvm/ADT/STLForwardCompat.h
+++ b/llvm/include/llvm/ADT/STLForwardCompat.h
@@ -44,6 +44,25 @@ template 
 struct disjunction
 : std::conditional>::type {};
 
+struct in_place_t // NOLINT(readability-identifier-naming)
+{
+  explicit in_place_t() = default;
+};
+/// \warning This must not be odr-used, as it cannot be made \c inline in 
C++14.
+constexpr in_place_t in_place; // NOLINT(readability-identifier-naming)
+
+template 
+struct in_place_type_t // NOLINT(readability-identifier-naming)
+{
+  explicit in_place_type_t() = default;
+};
+
+template 
+struct in_place_index_t // NOLINT(readability-identifier-naming)
+{
+  explicit in_place_index_t() = default;
+};
+
 
//===--===//
 // Features from C++20
 
//===--===//

diff  --git a/llvm/unittests/ADT/OptionalTest.cpp 
b/llvm/unittests/ADT/OptionalTest.cpp
index 2c5d65f80d977..debeb78e8fab7 100644
--- a/llvm/unittests/ADT/OptionalTest.cpp
+++ b/llvm/unittests/ADT/OptionalTest.cpp
@@ -195,6 +195,14 @@ TEST(OptionalTest, NullCopyConstructionTest) {
   EXPECT_EQ(0u, NonDefaultConstructible::Destructions);
 }
 
+TEST(OptionalTest, InPlaceConstructionNonDefaultConstructibleTest) {
+  NonDefaultConstructible::ResetCounts();
+  { Optional A{in_place, 1}; }
+  EXPECT_EQ(0u, NonDefaultConstructible::CopyConstructions);
+  EXPECT_EQ(0u, NonDefaultConstructible::CopyAssignments);
+  EXPECT_EQ(1u, NonDefaultConstructible::Destructions);
+}
+
 TEST(OptionalTest, GetValueOr) {
   Optional A;
   EXPECT_EQ(42, A.getValueOr(42));
@@ -214,6 +222,11 @@ struct MultiArgConstructor {
   MultiArgConstructor &operator=(const MultiArgConstructor &) = delete;
   MultiArgConstructor &operator=(MultiArgConstructor &&) = delete;
 
+  friend bool operator==(const MultiArgConstructor &LHS,
+ const MultiArgConstructor &RHS) {
+return LHS.x == RHS.x && LHS.y == RHS.y;
+  }
+
   static unsigned Destructions;
   ~MultiArgConstructor() {
 ++Destructions;
@@ -244,6 +257,34 @@ TEST(OptionalTest, Emplace) {
   EXPECT_EQ(1u,

[PATCH] D102654: [DebugInfo][test] Check specific func name to ignore codegen differences

2021-05-17 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-line.cpp:149
 
-// CHECK-LABEL: define
+// CHECK-LABEL: f11
 __complex double f11() {

Probably flesh that out a bit. Maybe `define{{.*}}f11`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102654

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


[PATCH] D102286: [HWASan] Build separate LAM runtime on x86_64.

2021-05-17 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

> Looks like the same issue I fixed in https://reviews.llvm.org/rGd97bab651185. 
>  Let me know if you have the issue after that commit.

Thanks, that resolved the build issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102286

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


[PATCH] D102654: [DebugInfo][test] Check specific func name to ignore codegen differences

2021-05-17 Thread Jinsong Ji via Phabricator via cfe-commits
jsji created this revision.
jsji added reviewers: PowerPC, dblaikie, shchenz.
jsji requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We use `CHECK-LABEL: define` to divide input stream into functions,
this works well on most platforms.

But there are cases that some platforms (eg: AIX) may have different
codegen , especially for global constructor and descructors.

On AIX, the codegen will have two more functions: __dtor_b,
__finalize_b, which will fail the test.

The fix is to use specific function name so that we can safely ignore
those unrelated codegen differences.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102654

Files:
  clang/test/CodeGenCXX/debug-info-line.cpp


Index: clang/test/CodeGenCXX/debug-info-line.cpp
===
--- clang/test/CodeGenCXX/debug-info-line.cpp
+++ clang/test/CodeGenCXX/debug-info-line.cpp
@@ -146,7 +146,7 @@
 (fn(),   //
  bar())};
 
-// CHECK-LABEL: define
+// CHECK-LABEL: f11
 __complex double f11() {
   __complex double f;
 // CHECK: store {{.*}} !dbg [[DBG_F11:!.*]]


Index: clang/test/CodeGenCXX/debug-info-line.cpp
===
--- clang/test/CodeGenCXX/debug-info-line.cpp
+++ clang/test/CodeGenCXX/debug-info-line.cpp
@@ -146,7 +146,7 @@
 (fn(),   //
  bar())};
 
-// CHECK-LABEL: define
+// CHECK-LABEL: f11
 __complex double f11() {
   __complex double f;
 // CHECK: store {{.*}} !dbg [[DBG_F11:!.*]]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102650: Old work on P0388. For reference in D102645. Not for review / commit.

2021-05-17 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added a reviewer: urnathan.
Herald added a subscriber: jfb.
rsmith requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102650

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp

Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -3243,6 +3243,19 @@
   !PreviousToQualsIncludeConst)
 return false;
 
+  // The following wording is from C++20, where the result of the conversion
+  // is T3, not T2.
+  //   -- if [...] P1,i [...] is "array of unknown bound of", P3,i is
+  //  "array of unknown bound of"
+  if (FromType->isIncompleteArrayType() && !ToType->isIncompleteArrayType())
+return false;
+
+  //   -- if the resulting P3,i is different from P1,i [...], then const is
+  //  added to every cv 3_k for 0 < k < i.
+  if (!CStyle && FromType->isConstantArrayType() &&
+  ToType->isIncompleteArrayType() && !PreviousToQualsIncludeConst)
+return false;
+
   // Keep track of whether all prior cv-qualifiers in the "to" type
   // include const.
   PreviousToQualsIncludeConst =
@@ -4128,12 +4141,15 @@
 CompareQualificationConversions(Sema &S,
 const StandardConversionSequence& SCS1,
 const StandardConversionSequence& SCS2) {
-  // C++ 13.3.3.2p3:
+  // C++ [over.ics.rank]p3:
   //  -- S1 and S2 differ only in their qualification conversion and
-  // yield similar types T1 and T2 (C++ 4.4), respectively, and the
-  // cv-qualification signature of type T1 is a proper subset of
-  // the cv-qualification signature of type T2, and S1 is not the
+  // yield similar types T1 and T2 (C++ 4.4), respectively, [...]
+  // [C++98]
+  // [...] and the cv-qualification signature of type T1 is a proper subset
+  // of the cv-qualification signature of type T2, and S1 is not the
   // deprecated string literal array-to-pointer conversion (4.2).
+  // [C++2a]
+  // [...] where T1 can be converted to T2 by a qualification conversion.
   if (SCS1.First != SCS2.First || SCS1.Second != SCS2.Second ||
   SCS1.Third != SCS2.Third || SCS1.Third != ICK_Qualification)
 return ImplicitConversionSequence::Indistinguishable;
@@ -4154,79 +4170,35 @@
   if (UnqualT1 == UnqualT2)
 return ImplicitConversionSequence::Indistinguishable;
 
-  ImplicitConversionSequence::CompareKind Result
-= ImplicitConversionSequence::Indistinguishable;
+  // Don't ever prefer a standard conversion sequence that uses the deprecated
+  // string literal array to pointer conversion.
+  bool CanPick1 = !SCS1.DeprecatedStringLiteralToCharPtr;
+  bool CanPick2 = !SCS2.DeprecatedStringLiteralToCharPtr;
 
   // Objective-C++ ARC:
   //   Prefer qualification conversions not involving a change in lifetime
-  //   to qualification conversions that do not change lifetime.
-  if (SCS1.QualificationIncludesObjCLifetime !=
-  SCS2.QualificationIncludesObjCLifetime) {
-Result = SCS1.QualificationIncludesObjCLifetime
-   ? ImplicitConversionSequence::Worse
-   : ImplicitConversionSequence::Better;
-  }
-
-  while (S.Context.UnwrapSimilarTypes(T1, T2)) {
-// Within each iteration of the loop, we check the qualifiers to
-// determine if this still looks like a qualification
-// conversion. Then, if all is well, we unwrap one more level of
-// pointers or pointers-to-members and do it all again
-// until there are no more pointers or pointers-to-members left
-// to unwrap. This essentially mimics what
-// IsQualificationConversion does, but here we're checking for a
-// strict subset of qualifiers.
-if (T1.getQualifiers().withoutObjCLifetime() ==
-T2.getQualifiers().withoutObjCLifetime())
-  // The qualifiers are the same, so this doesn't tell us anything
-  // about how the sequences rank.
-  // ObjC ownership quals are omitted above as they interfere with
-  // the ARC overload rule.
-  ;
-else if (T2.isMoreQualifiedThan(T1)) {
-  // T1 has fewer qualifiers, so it could be the better sequence.
-  if (Result == ImplicitConversionSequence::Worse)
-// Neither has qualifiers that are a subset of the other's
-// qualifiers.
-return ImplicitConversionSequence::Indistinguishable;
-
-  Result = ImplicitConversionSequence::Better;
-} else if (T1.isMoreQualifiedThan(T2)) {
-  // T2 has fewer qualifiers, so it could be the better sequence.
-  if (Re

[PATCH] D102647: [Driver][test] Don't assume integrated-as

2021-05-17 Thread Jinsong Ji via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG82b52812471c: [Driver][test] Don't assume integrated-as 
(authored by jsji).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102647

Files:
  clang/test/Driver/clang_f_opts.c


Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -516,10 +516,10 @@
 
 // RUN: %clang -### -S -fdebug-compilation-dir . %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // RUN: %clang -### -S -fdebug-compilation-dir=. %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -fdebug-compilation-dir . -x assembler %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -fdebug-compilation-dir=. -x assembler %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -fdebug-compilation-dir . -x assembler %s 
2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -fdebug-compilation-dir=. -x assembler %s 
2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // RUN: %clang -### -S -ffile-compilation-dir=. %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck 
-check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -ffile-compilation-dir=. -x assembler %s 
2>&1 | FileCheck -check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
 // CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir=."
 // CHECK-DEBUG-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
 


Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -516,10 +516,10 @@
 
 // RUN: %clang -### -S -fdebug-compilation-dir . %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // RUN: %clang -### -S -fdebug-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -fdebug-compilation-dir . -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -fdebug-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -fdebug-compilation-dir . -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -fdebug-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // RUN: %clang -### -S -ffile-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
 // CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir=."
 // CHECK-DEBUG-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 82b5281 - [Driver][test] Don't assume integrated-as

2021-05-17 Thread Jinsong Ji via cfe-commits

Author: Jinsong Ji
Date: 2021-05-17T20:24:21Z
New Revision: 82b52812471ca4e7228714aab15110bb740669d0

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

LOG: [Driver][test] Don't assume integrated-as

The tests of fdebug-compilation-dir and -ffile-compilation-dir for `-x
assembler` are assuming integrated-as.
If the platform set the no-itegrated-as by default (eg: AIX for now), then this 
test will
fail.

Add the -integrated-as to aviod relying on the platform defaults.

Reviewed By: thakis

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

Added: 


Modified: 
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index 6077058ad5b2..a255f68713ae 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -516,10 +516,10 @@
 
 // RUN: %clang -### -S -fdebug-compilation-dir . %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // RUN: %clang -### -S -fdebug-compilation-dir=. %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -fdebug-compilation-dir . -x assembler %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -fdebug-compilation-dir=. -x assembler %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -fdebug-compilation-dir . -x assembler %s 
2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -fdebug-compilation-dir=. -x assembler %s 
2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // RUN: %clang -### -S -ffile-compilation-dir=. %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck 
-check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -ffile-compilation-dir=. -x assembler %s 
2>&1 | FileCheck -check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
 // CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir=."
 // CHECK-DEBUG-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
 



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


[PATCH] D102015: [clang CodeGen] Don't crash on large atomic function parameter.

2021-05-17 Thread Eli Friedman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG698568b74c93: [clang CodeGen] Don't crash on large 
atomic function parameter. (authored by efriedma).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102015

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGen/big-atomic-ops.c
  clang/test/CodeGenCXX/atomic.cpp


Index: clang/test/CodeGenCXX/atomic.cpp
===
--- clang/test/CodeGenCXX/atomic.cpp
+++ clang/test/CodeGenCXX/atomic.cpp
@@ -15,3 +15,13 @@
   }
   void f(Ptr *a) { a->f(); }
 }
+
+namespace DelegatingParameter {
+  // Check that we're delegating the complete ctor to the base
+  // ctor, and that doesn't crash.
+  // CHECK-LABEL: define void @_ZN19DelegatingParameter1SC1EU7_AtomicNS_1ZE
+  // CHECK: call void @_ZN19DelegatingParameter1SC2EU7_AtomicNS_1ZE
+  struct Z { int z[100]; };
+  struct S { S(_Atomic Z); };
+  S::S(_Atomic Z) {}
+}
Index: clang/test/CodeGen/big-atomic-ops.c
===
--- clang/test/CodeGen/big-atomic-ops.c
+++ clang/test/CodeGen/big-atomic-ops.c
@@ -311,4 +311,10 @@
   // CHECK: }
 }
 
+// Check this doesn't crash
+// CHECK: @test_atomic_array_param(
+void test_atomic_array_param(_Atomic(struct foo) a) {
+  test_atomic_array_param(a);
+}
+
 #endif
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2473,7 +2473,7 @@
 // Push a destructor cleanup for this parameter if the ABI requires it.
 // Don't push a cleanup in a thunk for a method that will also emit a
 // cleanup.
-if (hasAggregateEvaluationKind(Ty) && !CurFuncIsThunk &&
+if (Ty->isRecordType() && !CurFuncIsThunk &&
 Ty->castAs()->getDecl()->isParamDestroyedInCallee()) {
   if (QualType::DestructionKind DtorKind =
   D.needsDestruction(getContext())) {
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -3712,7 +3712,7 @@
   }
 
   // Deactivate the cleanup for the callee-destructed param that was pushed.
-  if (hasAggregateEvaluationKind(type) && !CurFuncIsThunk &&
+  if (type->isRecordType() && !CurFuncIsThunk &&
   type->castAs()->getDecl()->isParamDestroyedInCallee() &&
   param->needsDestruction(getContext())) {
 EHScopeStack::stable_iterator cleanup =
@@ -4283,7 +4283,7 @@
   // In the Microsoft C++ ABI, aggregate arguments are destructed by the 
callee.
   // However, we still have to push an EH-only cleanup in case we unwind before
   // we make it to the call.
-  if (HasAggregateEvalKind &&
+  if (type->isRecordType() &&
   type->castAs()->getDecl()->isParamDestroyedInCallee()) {
 // If we're using inalloca, use the argument memory.  Otherwise, use a
 // temporary.


Index: clang/test/CodeGenCXX/atomic.cpp
===
--- clang/test/CodeGenCXX/atomic.cpp
+++ clang/test/CodeGenCXX/atomic.cpp
@@ -15,3 +15,13 @@
   }
   void f(Ptr *a) { a->f(); }
 }
+
+namespace DelegatingParameter {
+  // Check that we're delegating the complete ctor to the base
+  // ctor, and that doesn't crash.
+  // CHECK-LABEL: define void @_ZN19DelegatingParameter1SC1EU7_AtomicNS_1ZE
+  // CHECK: call void @_ZN19DelegatingParameter1SC2EU7_AtomicNS_1ZE
+  struct Z { int z[100]; };
+  struct S { S(_Atomic Z); };
+  S::S(_Atomic Z) {}
+}
Index: clang/test/CodeGen/big-atomic-ops.c
===
--- clang/test/CodeGen/big-atomic-ops.c
+++ clang/test/CodeGen/big-atomic-ops.c
@@ -311,4 +311,10 @@
   // CHECK: }
 }
 
+// Check this doesn't crash
+// CHECK: @test_atomic_array_param(
+void test_atomic_array_param(_Atomic(struct foo) a) {
+  test_atomic_array_param(a);
+}
+
 #endif
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2473,7 +2473,7 @@
 // Push a destructor cleanup for this parameter if the ABI requires it.
 // Don't push a cleanup in a thunk for a method that will also emit a
 // cleanup.
-if (hasAggregateEvaluationKind(Ty) && !CurFuncIsThunk &&
+if (Ty->isRecordType() && !CurFuncIsThunk &&
 Ty->castAs()->getDecl()->isParamDestroyedInCallee()) {
   if (QualType::DestructionKind DtorKind =
   D.needsDestruction(getContext())) {
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -3712,7 +3712,7 @@
   }
 
   // Deactivate the cleanup for the callee-destructed par

[clang] 698568b - [clang CodeGen] Don't crash on large atomic function parameter.

2021-05-17 Thread Eli Friedman via cfe-commits

Author: Eli Friedman
Date: 2021-05-17T13:18:23-07:00
New Revision: 698568b74c93ab6d9374adc8bdc6e60fbcf41ff1

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

LOG: [clang CodeGen] Don't crash on large atomic function parameter.

I wouldn't recommend writing code like the testcase; a function
parameter isn't atomic, so using an atomic type doesn't really make
sense.  But it's valid, so clang shouldn't crash on it.

The code was assuming hasAggregateEvaluationKind(Ty) implies Ty is a
RecordType, which isn't true.  Just use isRecordType() instead.

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

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/test/CodeGen/big-atomic-ops.c
clang/test/CodeGenCXX/atomic.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index b665e6758e3dd..241479de58571 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3712,7 +3712,7 @@ void CodeGenFunction::EmitDelegateCallArg(CallArgList 
&args,
   }
 
   // Deactivate the cleanup for the callee-destructed param that was pushed.
-  if (hasAggregateEvaluationKind(type) && !CurFuncIsThunk &&
+  if (type->isRecordType() && !CurFuncIsThunk &&
   type->castAs()->getDecl()->isParamDestroyedInCallee() &&
   param->needsDestruction(getContext())) {
 EHScopeStack::stable_iterator cleanup =
@@ -4283,7 +4283,7 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, 
const Expr *E,
   // In the Microsoft C++ ABI, aggregate arguments are destructed by the 
callee.
   // However, we still have to push an EH-only cleanup in case we unwind before
   // we make it to the call.
-  if (HasAggregateEvalKind &&
+  if (type->isRecordType() &&
   type->castAs()->getDecl()->isParamDestroyedInCallee()) {
 // If we're using inalloca, use the argument memory.  Otherwise, use a
 // temporary.

diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 10781dbb51834..22bd8d14b87a8 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2473,7 +2473,7 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, 
ParamValue Arg,
 // Push a destructor cleanup for this parameter if the ABI requires it.
 // Don't push a cleanup in a thunk for a method that will also emit a
 // cleanup.
-if (hasAggregateEvaluationKind(Ty) && !CurFuncIsThunk &&
+if (Ty->isRecordType() && !CurFuncIsThunk &&
 Ty->castAs()->getDecl()->isParamDestroyedInCallee()) {
   if (QualType::DestructionKind DtorKind =
   D.needsDestruction(getContext())) {

diff  --git a/clang/test/CodeGen/big-atomic-ops.c 
b/clang/test/CodeGen/big-atomic-ops.c
index c584ffcf7cf75..0dc43caa64723 100644
--- a/clang/test/CodeGen/big-atomic-ops.c
+++ b/clang/test/CodeGen/big-atomic-ops.c
@@ -311,4 +311,10 @@ void atomic_init_foo()
   // CHECK: }
 }
 
+// Check this doesn't crash
+// CHECK: @test_atomic_array_param(
+void test_atomic_array_param(_Atomic(struct foo) a) {
+  test_atomic_array_param(a);
+}
+
 #endif

diff  --git a/clang/test/CodeGenCXX/atomic.cpp 
b/clang/test/CodeGenCXX/atomic.cpp
index f40cb6d6ad14d..e5ecf0cbf74b7 100644
--- a/clang/test/CodeGenCXX/atomic.cpp
+++ b/clang/test/CodeGenCXX/atomic.cpp
@@ -15,3 +15,13 @@ namespace PR11411 {
   }
   void f(Ptr *a) { a->f(); }
 }
+
+namespace DelegatingParameter {
+  // Check that we're delegating the complete ctor to the base
+  // ctor, and that doesn't crash.
+  // CHECK-LABEL: define void @_ZN19DelegatingParameter1SC1EU7_AtomicNS_1ZE
+  // CHECK: call void @_ZN19DelegatingParameter1SC2EU7_AtomicNS_1ZE
+  struct Z { int z[100]; };
+  struct S { S(_Atomic Z); };
+  S::S(_Atomic Z) {}
+}



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


[PATCH] D102647: [Driver][test] Don't assume integrated-as

2021-05-17 Thread Jinsong Ji via Phabricator via cfe-commits
jsji added a comment.

In D102647#2764376 , @thakis wrote:

> Are there any platforms left that don't default to integrated as? Which ones? 
> Is there a tracking bug for switching them?

Thanks! Oh, I should have mentioned that in description, this is exposed on AIX 
testing.
AIX doesn't default to integrated as for now. There is no tracking but yet, but 
we have internal tracking for switching.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102647

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 345977.
hctim added a comment.

Let's submit the "adding archs" part of the patch first, then land this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/aligned-new.cpp
  compiler-rt/test/scudo/alignment.c
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/double-free.cpp
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/lit.site.cfg.py.in
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/options.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preinit.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/quarantine.c
  compiler-rt/test/scudo/random_shuffle.cpp
  compiler-rt/test/scudo/realloc.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/sized-delete.cpp
  compiler-rt/test/scudo/sizes.cpp
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  compiler-rt/test/scudo/standalone/aligned-new.cpp
  compiler-rt/test/scudo/standalone/alignment.c
  compiler-rt/test/scudo/standalone/dealloc-race.c
  compiler-rt/test/scudo/standalone/double-free.cpp
  compiler-rt/test/scudo/standalone/fsanitize.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
  compiler-rt/test/scudo/standalone/lit.cfg.py
  compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
  compiler-rt/test/scudo/standalone/malloc.cpp
  compiler-rt/test/scudo/standalone/memalign.c
  compiler-rt/test/scudo/standalone/mismatch.cpp
  compiler-rt/test/scudo/standalone/options.cpp
  compiler-rt/test/scudo/standalone/preinit.c
  compiler-rt/test/scudo/standalone/preload.cpp
  compiler-rt/test/scudo/standalone/random_shuffle.cpp
  compiler-rt/test/scudo/standalone/sized-delete.cpp
  compiler-rt/test/scudo/standalone/stats.c
  compiler-rt/test/scudo/standalone/tsd_destruction.c
  compiler-rt/test/scudo/stats.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ /dev/null
@@ -1,8 +0,0 @@
-UNSUPPORTED: android
-
-Verify that various functions are *not* present in the minimal binary. Presence
-of those symbols in the minimal runtime would mean that the split code made it
-back into the core Sanitizer runtime library.
-
-RUN: nm %shared_minlibscudo | not grep Symbolizer
-RUN: nm %shared_minlibscudo | not grep Coverage
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- /dev/null
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,43 +0,0 @@
-// RUN: %clang_scudo %s -o %t
-// RUN: %run %t 2>&1
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-// Some of glibc's own thread local data is destroyed after a user's thread
-// local destructors are called, via __libc_thread_freeres. This might involve
-// calling free, as is the case for strerror_thread_freeres.
-// If there is no prior heap operation in the thread, this free would end up
-// initializing some thread specific data that would never be destroyed
-// properly, while still being deallocated when the TLS goes away. As a result,
-// a program could SEGV, usually in
-// __sanitizer::AllocatorGlobalStats::Unregister, where one of the doubly
-// linked list links would refer to a now unmapped memory area.
-
-// This test reproduces those circumstances. Success means executing without
-// a segmentation fault.
-
-const int kNumThreads = 16;
-pthread_t tid[kNumThreads];
-
-void *thread_fu

[PATCH] D102647: [Driver][test] Don't assume integrated-as

2021-05-17 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Are there any platforms left that don't default to integrated as? Which ones? 
Is there a tracking bug for switching them?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102647

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 345975.
vitalybuka added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/aligned-new.cpp
  compiler-rt/test/scudo/alignment.c
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/double-free.cpp
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/lit.site.cfg.py.in
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/options.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preinit.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/quarantine.c
  compiler-rt/test/scudo/random_shuffle.cpp
  compiler-rt/test/scudo/realloc.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/sized-delete.cpp
  compiler-rt/test/scudo/sizes.cpp
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  compiler-rt/test/scudo/standalone/aligned-new.cpp
  compiler-rt/test/scudo/standalone/alignment.c
  compiler-rt/test/scudo/standalone/dealloc-race.c
  compiler-rt/test/scudo/standalone/double-free.cpp
  compiler-rt/test/scudo/standalone/fsanitize.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
  compiler-rt/test/scudo/standalone/lit.cfg.py
  compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
  compiler-rt/test/scudo/standalone/malloc.cpp
  compiler-rt/test/scudo/standalone/memalign.c
  compiler-rt/test/scudo/standalone/mismatch.cpp
  compiler-rt/test/scudo/standalone/options.cpp
  compiler-rt/test/scudo/standalone/preinit.c
  compiler-rt/test/scudo/standalone/preload.cpp
  compiler-rt/test/scudo/standalone/random_shuffle.cpp
  compiler-rt/test/scudo/standalone/sized-delete.cpp
  compiler-rt/test/scudo/standalone/stats.c
  compiler-rt/test/scudo/standalone/tsd_destruction.c
  compiler-rt/test/scudo/stats.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ /dev/null
@@ -1,8 +0,0 @@
-UNSUPPORTED: android
-
-Verify that various functions are *not* present in the minimal binary. Presence
-of those symbols in the minimal runtime would mean that the split code made it
-back into the core Sanitizer runtime library.
-
-RUN: nm %shared_minlibscudo | not grep Symbolizer
-RUN: nm %shared_minlibscudo | not grep Coverage
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- /dev/null
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,43 +0,0 @@
-// RUN: %clang_scudo %s -o %t
-// RUN: %run %t 2>&1
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-// Some of glibc's own thread local data is destroyed after a user's thread
-// local destructors are called, via __libc_thread_freeres. This might involve
-// calling free, as is the case for strerror_thread_freeres.
-// If there is no prior heap operation in the thread, this free would end up
-// initializing some thread specific data that would never be destroyed
-// properly, while still being deallocated when the TLS goes away. As a result,
-// a program could SEGV, usually in
-// __sanitizer::AllocatorGlobalStats::Unregister, where one of the doubly
-// linked list links would refer to a now unmapped memory area.
-
-// This test reproduces those circumstances. Success means executing without
-// a segmentation fault.
-
-const int kNumThreads = 16;
-pthread_t tid[kNumThreads];
-
-void *thread_func(void *arg) {
-  u

[PATCH] D100276: [clang] p1099 3/5: using Enum::member

2021-05-17 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan updated this revision to Diff 345973.

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

https://reviews.llvm.org/D100276

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p3.cpp
  clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7-cxx20.cpp
  clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7.cpp
  clang/test/SemaCXX/enum-scoped.cpp

Index: clang/test/SemaCXX/enum-scoped.cpp
===
--- clang/test/SemaCXX/enum-scoped.cpp
+++ clang/test/SemaCXX/enum-scoped.cpp
@@ -301,8 +301,8 @@
   int E::*p; // expected-error {{does not point into a class}}
   using E::f; // expected-error {{no member named 'f'}}
 
-  using E::a; // expected-error {{using declaration cannot refer to a scoped enumerator}}
-  E b = a; // expected-error {{undeclared}}
+  using E::a; // expected-warning {{using declaration naming a scoped enumerator is a C++20 extension}}
+  E b = a;
 }
 
 namespace test11 {
Index: clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7.cpp
===
--- clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7.cpp
+++ clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7.cpp
@@ -1,4 +1,11 @@
 // RUN: %clang_cc1 -std=c++11 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
 
 enum class EC { ec };
-using EC::ec; // expected-error {{using declaration cannot refer to a scoped enumerator}}
+using EC::ec;
+#if __cplusplus < 202002
+// expected-warning@-2 {{using declaration naming a scoped enumerator is a C++20 extension}}
+#else
+// expected-no-diagnostics
+#endif
Index: clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7-cxx20.cpp
===
--- /dev/null
+++ clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7-cxx20.cpp
@@ -0,0 +1,271 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+// p1099 'using SCOPEDENUM::MEMBER;'
+
+namespace Zero {
+namespace Bob {
+enum class Kevin {
+  Stuart,
+  AlsoStuart
+#if __cplusplus >= 202002L
+// expected-note@-3{{target of using declaration}}
+// expected-note@-3{{target of using declaration}}
+#endif
+};
+} // namespace Bob
+
+using Bob::Kevin::Stuart;
+#if __cplusplus < 202002L
+// expected-warning@-2{{using declaration naming a scoped enumerator is a C++20 extension}}
+#else
+using Bob::Kevin::Stuart;
+
+auto b = Stuart;
+
+namespace Foo {
+int Stuart;   // expected-note{{conflicting declaration}}
+using Bob::Kevin::Stuart; // expected-error{{target of using declaration conflicts}}
+
+using Bob::Kevin::AlsoStuart; // expected-note{{using declaration}}
+int AlsoStuart;   // expected-error{{declaration conflicts with target}}
+} // namespace Foo
+#endif
+
+} // namespace Zero
+
+namespace One {
+
+// derived from [namespace.udecl]/3
+enum class button { up,
+down };
+struct S {
+  using button::up;
+#if __cplusplus < 202002L
+  // expected-warning@-2{{a C++20 extension}}
+  // expected-error@-3{{using declaration in class}}
+#else
+  button b = up;
+#endif
+};
+
+#if __cplusplus >= 202002L
+// some more
+struct T : S {
+  button c = up;
+};
+#endif
+enum E2 { e2 };
+} // namespace One
+
+namespace Two {
+enum class E1 { e1 };
+
+struct S {
+  using One::e2;
+#if __cplusplus < 202002L
+  // expected-error@-2{{using declaration in class}}
+#else
+  One::E2 c = e2;
+#endif
+};
+
+} // namespace Two
+
+namespace Three {
+
+enum E3 { e3 };
+struct e3;
+
+struct S {
+  using Three::e3; // expected-error{{using declaration in class}}
+
+  enum class E4 { e4 };
+  enum E5 { e5 };
+};
+
+using S::e5;
+using S::E4::e4;
+#if __cplusplus < 202002L
+// expected-error@-3{{using declaration cannot refer to class member}}
+// expected-note@-4{{use a constexpr variable instead}}
+// expected-warning@-4{{a C++20 extension}}
+// expected-error@-5{{using declaration cannot refer to class member}}
+// expected-note@-6{{use a constexpr variable instead}}
+#else
+auto a = e4;
+auto b = e5;
+#endif
+} // namespace Three
+
+namespace Four {
+
+template 
+struct TPL {
+  enum class E1 { e1 };
+  struct IN {
+enum class E2 { e2 };
+  };
+
+protected:
+  enum class E3 { e3 }; // expected-note{{declared protected here}}
+};
+
+using TPL::E1::e1;
+#if __cplusplus < 202002L
+// expected-warning@-2{{a C++20 extension}}
+// expected-error@-3{{using declaration cannot refer to class member}}
+// expected-note@-4{{use a constexpr variable instead}}
+#else
+using TPL::IN::E2::e2;
+
+auto a = e1;
+auto b = e2;
+#endif
+
+enum class E4 { e4 };
+template 
+struct DER : TPL {
+  using TPL::E1::e1;
+#if __cplusplus < 202002L
+  // expected-warning@-

[PATCH] D102592: [sanitizer] Caught global buffer underflow for first variable

2021-05-17 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

You are adding a new global to every translation unit.

- Private linkage would not allow them to be merged, this can have significant 
binary size and RAM overhead.
- There is no guarantee that any of these globals will end up to the left of 
any sanitized globals. With -fdata-sections, the linker is free to reorder.
- It is also not referenced from anything, so -gc-sections is likely to kill it.

It looks like this will only work in very limited circumstances.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102592

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


[PATCH] D102647: [Driver][test] Don't assume integrated-as

2021-05-17 Thread Jinsong Ji via Phabricator via cfe-commits
jsji created this revision.
jsji added reviewers: PowerPC, thakis, MaskRay, phosek, hubert.reinterpretcast.
jsji requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The tests of fdebug-compilation-dir and -ffile-compilation-dir for `-x
assembler` are assuming integrated-as.
If the platform set the no-itegrated-as by default, then this test will
fail.

Add the -integrated-as to aviod relying on the platform defaults.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102647

Files:
  clang/test/Driver/clang_f_opts.c


Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -516,10 +516,10 @@
 
 // RUN: %clang -### -S -fdebug-compilation-dir . %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // RUN: %clang -### -S -fdebug-compilation-dir=. %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -fdebug-compilation-dir . -x assembler %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -fdebug-compilation-dir=. -x assembler %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -fdebug-compilation-dir . -x assembler %s 
2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -fdebug-compilation-dir=. -x assembler %s 
2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // RUN: %clang -### -S -ffile-compilation-dir=. %s 2>&1 | FileCheck 
-check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck 
-check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -ffile-compilation-dir=. -x assembler %s 
2>&1 | FileCheck -check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
 // CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir=."
 // CHECK-DEBUG-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
 


Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -516,10 +516,10 @@
 
 // RUN: %clang -### -S -fdebug-compilation-dir . %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // RUN: %clang -### -S -fdebug-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -fdebug-compilation-dir . -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -fdebug-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -fdebug-compilation-dir . -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -fdebug-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
 // RUN: %clang -### -S -ffile-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
-// RUN: %clang -### -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
+// RUN: %clang -### -integrated-as -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
 // CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir=."
 // CHECK-DEBUG-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: compiler-rt/cmake/config-ix.cmake:338
 set(ALL_SCUDO_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} 
${MIPS64} ${PPC64})
-set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})
+set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} 
${MIPS32} ${MIPS64} ${PPC64})
 if(APPLE)

I would recommend to change this line in a separate patch after this one


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 345967.
vitalybuka added a comment.

clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/aligned-new.cpp
  compiler-rt/test/scudo/alignment.c
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/double-free.cpp
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/lit.site.cfg.py.in
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/options.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preinit.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/quarantine.c
  compiler-rt/test/scudo/random_shuffle.cpp
  compiler-rt/test/scudo/realloc.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/sized-delete.cpp
  compiler-rt/test/scudo/sizes.cpp
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  compiler-rt/test/scudo/standalone/aligned-new.cpp
  compiler-rt/test/scudo/standalone/alignment.c
  compiler-rt/test/scudo/standalone/dealloc-race.c
  compiler-rt/test/scudo/standalone/double-free.cpp
  compiler-rt/test/scudo/standalone/fsanitize.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
  compiler-rt/test/scudo/standalone/lit.cfg.py
  compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
  compiler-rt/test/scudo/standalone/malloc.cpp
  compiler-rt/test/scudo/standalone/memalign.c
  compiler-rt/test/scudo/standalone/mismatch.cpp
  compiler-rt/test/scudo/standalone/options.cpp
  compiler-rt/test/scudo/standalone/preinit.c
  compiler-rt/test/scudo/standalone/preload.cpp
  compiler-rt/test/scudo/standalone/random_shuffle.cpp
  compiler-rt/test/scudo/standalone/sized-delete.cpp
  compiler-rt/test/scudo/standalone/stats.c
  compiler-rt/test/scudo/standalone/tsd_destruction.c
  compiler-rt/test/scudo/stats.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ /dev/null
@@ -1,8 +0,0 @@
-UNSUPPORTED: android
-
-Verify that various functions are *not* present in the minimal binary. Presence
-of those symbols in the minimal runtime would mean that the split code made it
-back into the core Sanitizer runtime library.
-
-RUN: nm %shared_minlibscudo | not grep Symbolizer
-RUN: nm %shared_minlibscudo | not grep Coverage
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- /dev/null
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,43 +0,0 @@
-// RUN: %clang_scudo %s -o %t
-// RUN: %run %t 2>&1
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-// Some of glibc's own thread local data is destroyed after a user's thread
-// local destructors are called, via __libc_thread_freeres. This might involve
-// calling free, as is the case for strerror_thread_freeres.
-// If there is no prior heap operation in the thread, this free would end up
-// initializing some thread specific data that would never be destroyed
-// properly, while still being deallocated when the TLS goes away. As a result,
-// a program could SEGV, usually in
-// __sanitizer::AllocatorGlobalStats::Unregister, where one of the doubly
-// linked list links would refer to a now unmapped memory area.
-
-// This test reproduces those circumstances. Success means executing without
-// a segmentation fault.
-
-const int kNumThreads = 16;
-pthread_t tid[kNumThreads];
-
-void *thread_func(void *arg) 

[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

Would you mind to clang-format entire existing compiler-rt/test/scudo/
and than rebase this patch on top?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

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


[clang] 3a0b6dc - Revert "[Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable"

2021-05-17 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2021-05-17T12:16:10-07:00
New Revision: 3a0b6dc3e84bb91c0dbd721b1931e4a0ff396142

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

LOG: Revert "[Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable"

This reverts commit 14dfb3831c425c7f22540a2160424224008c257e.

More false positives, see D100581.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp
clang/test/CodeGen/2007-10-30-Volatile.c
clang/test/CodeGen/X86/x86_32-xsave.c
clang/test/CodeGen/X86/x86_64-xsave.c
clang/test/CodeGen/builtins-arm.c
clang/test/CodeGen/builtins-riscv.c
clang/test/FixIt/fixit.cpp
clang/test/Misc/warning-wall.c
clang/test/Sema/shift.c
clang/test/Sema/vector-gcc-compat.c
clang/test/Sema/vector-gcc-compat.cpp
clang/test/SemaCXX/goto.cpp
clang/test/SemaCXX/shift.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaObjC/foreach.m

Removed: 
clang/test/Sema/warn-unused-but-set-parameters.c
clang/test/Sema/warn-unused-but-set-variables.c
clang/test/SemaCXX/warn-unused-but-set-parameters-cpp.cpp
clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp



diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 35088f845da4d..f6a4fbb1e04c8 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -725,7 +725,6 @@ def UnusedMemberFunction : 
DiagGroup<"unused-member-function",
 def UnusedLabel : DiagGroup<"unused-label">;
 def UnusedLambdaCapture : DiagGroup<"unused-lambda-capture">;
 def UnusedParameter : DiagGroup<"unused-parameter">;
-def UnusedButSetParameter : DiagGroup<"unused-but-set-parameter">;
 def UnusedResult : DiagGroup<"unused-result">;
 def PotentiallyEvaluatedExpression : 
DiagGroup<"potentially-evaluated-expression">;
 def UnevaluatedExpression : DiagGroup<"unevaluated-expression",
@@ -735,7 +734,6 @@ def UnusedValue : DiagGroup<"unused-value", 
[UnusedComparison, UnusedResult,
 def UnusedConstVariable : DiagGroup<"unused-const-variable">;
 def UnusedVariable : DiagGroup<"unused-variable",
[UnusedConstVariable]>;
-def UnusedButSetVariable : DiagGroup<"unused-but-set-variable">;
 def UnusedLocalTypedef : DiagGroup<"unused-local-typedef">;
 def UnusedPropertyIvar :  DiagGroup<"unused-property-ivar">;
 def UnusedGetterReturnValue : DiagGroup<"unused-getter-return-value">;
@@ -877,7 +875,7 @@ def Unused : DiagGroup<"unused",
 // UnusedMemberFunction, (clean-up llvm before 
enabling)
 UnusedPrivateField, UnusedLambdaCapture,
 UnusedLocalTypedef, UnusedValue, UnusedVariable,
-UnusedButSetVariable, UnusedPropertyIvar]>,
+UnusedPropertyIvar]>,
 DiagCategory<"Unused Entity Issue">;
 
 // Format settings.
@@ -929,7 +927,6 @@ def Extra : DiagGroup<"extra", [
 MissingMethodReturnType,
 SignCompare,
 UnusedParameter,
-UnusedButSetParameter,
 NullPointerArithmetic,
 EmptyInitStatement,
 StringConcatation,

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 982606e4f6ca5..9dd9b1b5118b5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -310,12 +310,8 @@ def note_riscv_repeated_interrupt_attribute : Note<
   "repeated RISC-V 'interrupt' attribute is here">;
 def warn_unused_parameter : Warning<"unused parameter %0">,
   InGroup, DefaultIgnore;
-def warn_unused_but_set_parameter : Warning<"parameter %0 set but not used">,
-  InGroup, DefaultIgnore;
 def warn_unused_variable : Warning<"unused variable %0">,
   InGroup, DefaultIgnore;
-def warn_unused_but_set_variable : Warning<"variable %0 set but not used">,
-  InGroup, DefaultIgnore;
 def warn_unused_local_typedef : Warning<
   "unused %select{typedef|type alias}0 %1">,
   InGroup, DefaultIgnore;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 160760577c5bf..b6143d1d31789 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1514,11 +1514,6 @@ class Sema final {
 
   bool WarnedStackExhausted = false;
 
-  /// Increment when we find a reference; decrement when we find an ignored
-  /// assignment.  Ultimately the value is 0 if every reference is an ignored
-  /// assignment.
-

[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2021-05-17 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

This warning seems to have a lot of false positives on things like reference 
arguments that are used as output parameters. For example here is a small 
sample of output from a stage2 build of part of LLVM:

  In file included from ../llvm/lib/BinaryFormat/Minidump.cpp:9:
  In file included from ../llvm/include/llvm/BinaryFormat/Minidump.h:21:
  In file included from ../llvm/include/llvm/ADT/BitmaskEnum.h:16:
  ../llvm/include/llvm/Support/MathExtras.h:822:9: warning: variable 
'Overflowed' set but not used [-Wunused-but-set-variable]
bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy;
  ^
  ../llvm/include/llvm/Support/MathExtras.h:936:72: warning: parameter 'Result' 
set but not used [-Wunused-but-set-parameter]
  std::enable_if_t::value, T> MulOverflow(T X, T Y, T 
&Result) {
 ^
  In file included from ../llvm/lib/BinaryFormat/Minidump.cpp:9:
  In file included from ../llvm/include/llvm/BinaryFormat/Minidump.h:22:
  In file included from ../llvm/include/llvm/ADT/DenseMapInfo.h:20:
  ../llvm/include/llvm/ADT/StringRef.h:511:37: warning: parameter 'Result' set 
but not used [-Wunused-but-set-parameter]
  getAsInteger(unsigned Radix, T &Result) const {
  ^
  ../llvm/include/llvm/ADT/StringRef.h:522:37: warning: parameter 'Result' set 
but not used [-Wunused-but-set-parameter]
  getAsInteger(unsigned Radix, T &Result) const {
  ^
  ../llvm/include/llvm/ADT/StringRef.h:545:39: warning: parameter 'Result' set 
but not used [-Wunused-but-set-parameter]
  consumeInteger(unsigned Radix, T &Result) {
^
  ../llvm/include/llvm/ADT/StringRef.h:556:39: warning: parameter 'Result' set 
but not used [-Wunused-but-set-parameter]
  consumeInteger(unsigned Radix, T &Result) {
^
  6 warnings generated.

Could you please take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100581

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


[PATCH] D99439: Update @llvm.powi to handle different int sizes for the exponent

2021-05-17 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp:581
RTLIB::POWI_F128,
RTLIB::POWI_PPCF128);
   if (!TLI.getLibcallName(LC)) {

bjope wrote:
> efriedma wrote:
> > bjope wrote:
> > > efriedma wrote:
> > > > This is missing a diagnostic for the exponent.  We don't want to 
> > > > silently miscompile if someone uses an exponent that isn't supported by 
> > > > the target.
> > > Not sure exactly what you suggest. Is that a general comment for all 
> > > places in SelectionDAG where we may emit calls to RTLIB::POWI or what 
> > > makes this SoftenFloatRes special?
> > > 
> > > If we end up using mismatching types in the call, wouldn't that being 
> > > detected as ICE elsewhere? Only reason I made changes to this function in 
> > > the first place was due to the historical assert above regarding the type 
> > > of the exponent in FPOWI. Maybe I should just drop that assert instead? 
> > > This is the only place where that is checked, but I figure that the 
> > > SoftenFloatRes legalization is just one out of many places where FPOWI is 
> > > legalized and lowered into libcalls to RTLIB::POWI.
> > It's a general issue with emitting calls to RTLIB::POWI; the second 
> > parameter to the call has to have type "int", to match the definition in 
> > libgcc/compiler-rt.  I guess there are a few other places that also emit 
> > calls to these functions.
> > 
> > > If we end up using mismatching types in the call, wouldn't that being 
> > > detected as ICE elsewhere?
> > 
> > In SelectionDAG, function/pointer types don't exist; the callee of a 
> > function call is just a integer.  So we'd never detect mismatched types; 
> > we'd just silently emit a call using the wrong calling convention.
> One interesting thing when trying to add checks verifying that 
> `DAG.getLibInfo().getIntSize() == Node->getOperand(1 + 
> Offset).getValueType().getSizeInBits())` in LegalizeDAG some RISCV (64-bit) 
> test cases fail. Looks like type legalization is promoting the exponent by 
> replacing
> 
> ```
>   t5: i64,ch = CopyFromReg t0, Register:i64 %1
> t6: i32 = truncate t5
>   t7: f32 = fpowi t3, t6
> 
> ```
> by
> 
> ```
>   t5: i64,ch = CopyFromReg t0, Register:i64 %1
> t13: i64 = sign_extend_inreg t5, ValueType:ch:i32
>   t7: f32 = fpowi t3, t13
> ```
> I kind of suspect that promoting the exponent for FPOWI always would be 
> incorrect, if the idea is that the type always should match with sizeof(int).
> 
> In this case RISCV would lower the fpowi to a libcall like this
> 
> ```
>   t5: i64,ch = CopyFromReg t0, Register:i64 %1
> t13: i64 = sign_extend_inreg t5, ValueType:ch:i32
>   t20: ch,glue = CopyToReg t18, Register:i64 $x11, t13, t18:1
>   t23: ch,glue = RISCVISD::CALL t20, TargetExternalSymbol:i64'__powisf2' 
> [TF=2], Register:i64 $x10, Register:i64 $x11, RegisterMask:Untyped, t20:1
> ```
> using a 64-bit argument for the call, while the callee expects a 32-bit int. 
> Depending on the calling conventions for RISCV64 I suppose this might work by 
> coincidence, or it is a bad miscompile.
> 
> Not sure exactly how to deal with that when considering this patch. I was 
> kind of aiming at fixing problems for 16-bit targets. Maybe we need to deal 
> with DAGTypeLegalizer::PromoteIntOp_FPOWI first, turning it into a fault 
> situation. And to do that one need to handle FPOWI for RISCV in some sort of 
> way to make the 32-bit exponent legal first?
We probably end up getting lucky due to the RISCV calling convention... but 
it's ugly.

I think the right solution here is to force type legalization to generate the 
call (when we try to legalize the integer operand), instead of waiting for 
LegalizeDAG.  That should allow the call lowering code to use the right calling 
convention.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99439

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


[PATCH] D102241: [clang] p1099 4/5: using enum EnumTag

2021-05-17 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan updated this revision to Diff 345960.
urnathan added a comment.

rebased, trying to resolve bot failure, again


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

https://reviews.llvm.org/D102241

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/DeclNodes.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Index/IndexSymbol.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Index/IndexSymbol.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/AST/ast-dump-using-enum.cpp
  clang/test/SemaCXX/cxx20-using-enum.cpp
  clang/tools/libclang/CIndex.cpp

Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -6540,6 +6540,7 @@
   }
 
   case Decl::Using:
+  case Decl::UsingEnum:
 return MakeCursorOverloadedDeclRef(cast(D), D->getLocation(),
TU);
 
Index: clang/test/SemaCXX/cxx20-using-enum.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-using-enum.cpp
@@ -0,0 +1,233 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+// p1099 'using enum ELABORATED-ENUM-SPECIFIER ;'
+
+namespace One {
+namespace Bob {
+enum A { a, // expected-note{{declared here}}
+ b,
+ c };
+class C; // expected-note{{previous use}}
+enum class D : int;
+enum class D { d,
+   e,
+   f };
+enum class D : int;
+} // namespace Bob
+
+using enum Bob::A;
+#if __cplusplus < 202002
+// expected-warning@-2{{is a C++20 extension}}
+#endif
+using enum Bob::B; // expected-error{{no enum named 'B'}}
+#if __cplusplus < 202002
+// expected-warning@-2{{is a C++20 extension}}
+#endif
+using enum Bob::C; // expected-error{{tag type that does not match}}
+#if __cplusplus < 202002
+// expected-warning@-2{{is a C++20 extension}}
+#endif
+auto v = a;
+
+A g; // expected-error{{unknown type name 'A'}}
+
+int A;
+
+using enum Bob::D;
+#if __cplusplus < 202002
+// expected-warning@-2{{is a C++20 extension}}
+#endif
+} // namespace One
+
+namespace Two {
+namespace Kevin {
+enum class B { d,
+   e,
+   f };
+}
+
+using enum Kevin::B;
+#if __cplusplus < 202002
+// expected-warning@-2{{is a C++20 extension}}
+#endif
+auto w = e;
+
+} // namespace Two
+
+#if __cplusplus >= 202002
+// Now only check c++20 onwards
+
+namespace Three {
+namespace Stuart {
+enum class C : int; // expected-note{{declared here}}
+}
+
+using enum Stuart::C; // expected-error{{is incomplete}}
+} // namespace Three
+
+namespace Four {
+class Dave {
+public:
+  enum D { a,
+   b,
+   c };
+
+private:
+  enum class E { d, // expected-note{{declared private here}}
+ e,
+ f };
+};
+
+using enum Dave::D;
+using enum Dave::E; // expected-error{{is a private member}}
+
+} // namespace Four
+
+namespace Five {
+enum class A { b,
+   c };
+class Dave {
+public:
+  using enum A;
+  A f = b;
+};
+
+} // namespace Five
+
+namespace Six {
+template  class TPL;
+template <> class TPL {
+public:
+  enum A { a };
+};
+
+template  class USR {
+  using enum TPL::B; // expected-error{{cannot name a dependent type}}
+  using enum TPL::A;
+};
+} // namespace Six
+
+// Now instantiate things
+namespace Seven {
+namespace Stuart {
+enum class A { a,
+   b,
+   c };
+}
+
+static_assert(!int(Stuart::A::a));
+constexpr int Bar() {
+  using enum Stuart::A;
+  return int(b);
+}
+static_assert(Bar() == 1);
+
+template  constexpr int Foo() {
+  using enum Stuart::A;
+  return int(b) + I;
+}
+
+static_assert(Foo<10>() == 11);
+
+template  struct C {
+  using enum Stuart::A;
+  static constexpr int V = int(c) + I;
+
+  enum class D { d,
+ e,
+ f };
+  using enum D;
+
+  static cons

[PATCH] D100276: [clang] p1099 3/5: using Enum::member

2021-05-17 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan updated this revision to Diff 345959.
urnathan edited the summary of this revision.
urnathan added a comment.

rebased, trying to resolve patch 4's bot fail


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

https://reviews.llvm.org/D100276

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p3.cpp
  clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7-cxx20.cpp
  clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7.cpp
  clang/test/SemaCXX/enum-scoped.cpp

Index: clang/test/SemaCXX/enum-scoped.cpp
===
--- clang/test/SemaCXX/enum-scoped.cpp
+++ clang/test/SemaCXX/enum-scoped.cpp
@@ -301,8 +301,8 @@
   int E::*p; // expected-error {{does not point into a class}}
   using E::f; // expected-error {{no member named 'f'}}
 
-  using E::a; // expected-error {{using declaration cannot refer to a scoped enumerator}}
-  E b = a; // expected-error {{undeclared}}
+  using E::a; // expected-warning {{using declaration naming a scoped enumerator is a C++20 extension}}
+  E b = a;
 }
 
 namespace test11 {
Index: clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7.cpp
===
--- clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7.cpp
+++ clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7.cpp
@@ -1,4 +1,11 @@
 // RUN: %clang_cc1 -std=c++11 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
 
 enum class EC { ec };
-using EC::ec; // expected-error {{using declaration cannot refer to a scoped enumerator}}
+using EC::ec;
+#if __cplusplus < 202002
+// expected-warning@-2 {{using declaration naming a scoped enumerator is a C++20 extension}}
+#else
+// expected-no-diagnostics
+#endif
Index: clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7-cxx20.cpp
===
--- /dev/null
+++ clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p7-cxx20.cpp
@@ -0,0 +1,271 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+
+// p1099 'using SCOPEDENUM::MEMBER;'
+
+namespace Zero {
+namespace Bob {
+enum class Kevin {
+  Stuart,
+  AlsoStuart
+#if __cplusplus >= 202002L
+// expected-note@-3{{target of using declaration}}
+// expected-note@-3{{target of using declaration}}
+#endif
+};
+} // namespace Bob
+
+using Bob::Kevin::Stuart;
+#if __cplusplus < 202002L
+// expected-warning@-2{{using declaration naming a scoped enumerator is a C++20 extension}}
+#else
+using Bob::Kevin::Stuart;
+
+auto b = Stuart;
+
+namespace Foo {
+int Stuart;   // expected-note{{conflicting declaration}}
+using Bob::Kevin::Stuart; // expected-error{{target of using declaration conflicts}}
+
+using Bob::Kevin::AlsoStuart; // expected-note{{using declaration}}
+int AlsoStuart;   // expected-error{{declaration conflicts with target}}
+} // namespace Foo
+#endif
+
+} // namespace Zero
+
+namespace One {
+
+// derived from [namespace.udecl]/3
+enum class button { up,
+down };
+struct S {
+  using button::up;
+#if __cplusplus < 202002L
+  // expected-warning@-2{{a C++20 extension}}
+  // expected-error@-3{{using declaration in class}}
+#else
+  button b = up;
+#endif
+};
+
+#if __cplusplus >= 202002L
+// some more
+struct T : S {
+  button c = up;
+};
+#endif
+enum E2 { e2 };
+} // namespace One
+
+namespace Two {
+enum class E1 { e1 };
+
+struct S {
+  using One::e2;
+#if __cplusplus < 202002L
+  // expected-error@-2{{using declaration in class}}
+#else
+  One::E2 c = e2;
+#endif
+};
+
+} // namespace Two
+
+namespace Three {
+
+enum E3 { e3 };
+struct e3;
+
+struct S {
+  using Three::e3; // expected-error{{using declaration in class}}
+
+  enum class E4 { e4 };
+  enum E5 { e5 };
+};
+
+using S::e5;
+using S::E4::e4;
+#if __cplusplus < 202002L
+// expected-error@-3{{using declaration cannot refer to class member}}
+// expected-note@-4{{use a constexpr variable instead}}
+// expected-warning@-4{{a C++20 extension}}
+// expected-error@-5{{using declaration cannot refer to class member}}
+// expected-note@-6{{use a constexpr variable instead}}
+#else
+auto a = e4;
+auto b = e5;
+#endif
+} // namespace Three
+
+namespace Four {
+
+template 
+struct TPL {
+  enum class E1 { e1 };
+  struct IN {
+enum class E2 { e2 };
+  };
+
+protected:
+  enum class E3 { e3 }; // expected-note{{declared protected here}}
+};
+
+using TPL::E1::e1;
+#if __cplusplus < 202002L
+// expected-warning@-2{{a C++20 extension}}
+// expected-error@-3{{using declaration cannot refer to class member}}
+// expected-note@-4{{use a constexpr variable instead}}
+#else
+using TPL::IN::E2::e2;
+
+auto a = e1;
+auto b = e2;
+#endif
+
+enum c

[PATCH] D102469: [sanitizer] Reduce redzone size for small size global objects

2021-05-17 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:2556-2559
+  // Reduce redzone size for small size objects, e.g. int, char[1]. MinRZ is at
+  // least 32 bytes, optimize when SizeInBytes is less than half of MinRZ.
+  if (SizeInBytes < MinRZ / 2) {
+RZ = MinRZ - SizeInBytes;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102469

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


[PATCH] D101777: [clang] p1099 1/5: [NFC] Break out BaseUsingDecl from UsingDecl

2021-05-17 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan updated this revision to Diff 345957.
urnathan added a comment.

rebased onto 3cdd05e519dd 
, (trying 
to fix patch 4's precommit failure)


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

https://reviews.llvm.org/D101777

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Basic/DeclNodes.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Sema/SemaAccess.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/tools/libclang/CIndex.cpp

Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -6540,7 +6540,7 @@
   }
 
   case Decl::Using:
-return MakeCursorOverloadedDeclRef(cast(D), D->getLocation(),
+return MakeCursorOverloadedDeclRef(cast(D), D->getLocation(),
TU);
 
   case Decl::UsingShadow:
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -1870,7 +1870,7 @@
   Diag(KWLoc, diag::err_using_decl_conflict_reverse);
   Diag(Shadow->getTargetDecl()->getLocation(),
diag::note_using_decl_target);
-  Diag(Shadow->getUsingDecl()->getLocation(), diag::note_using_decl) << 0;
+  Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl) << 0;
   // Recover by ignoring the old declaration.
   PrevDecl = PrevClassTemplate = nullptr;
 }
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -3732,7 +3732,7 @@
   // A shadow declaration that's created by a resolved using declaration
   // is not hidden by the same using declaration.
   if (isa(ND) && isa(D) &&
-  cast(ND)->getUsingDecl() == D)
+  cast(ND)->getIntroducer() == D)
 continue;
 
   // We've found a declaration that hides this one.
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -6992,7 +6992,7 @@
   : S(S), UseLoc(UseLoc) {
 bool DiagnosedMultipleConstructedBases = false;
 CXXRecordDecl *ConstructedBase = nullptr;
-UsingDecl *ConstructedBaseUsing = nullptr;
+BaseUsingDecl *ConstructedBaseIntroducer = nullptr;
 
 // Find the set of such base class subobjects and check that there's a
 // unique constructed subobject.
@@ -7016,18 +7016,18 @@
   //   of type B, the program is ill-formed.
   if (!ConstructedBase) {
 ConstructedBase = DConstructedBase;
-ConstructedBaseUsing = D->getUsingDecl();
+ConstructedBaseIntroducer = D->getIntroducer();
   } else if (ConstructedBase != DConstructedBase &&
  !Shadow->isInvalidDecl()) {
 if (!DiagnosedMultipleConstructedBases) {
   S.Diag(UseLoc, diag::err_ambiguous_inherited_constructor)
   << Shadow->getTargetDecl();
-  S.Diag(ConstructedBaseUsing->getLocation(),
-   diag::note_ambiguous_inherited_constructor_using)
+  S.Diag(ConstructedBaseIntroducer->getLocation(),
+ diag::note_ambiguous_inherited_constructor_using)
   << ConstructedBase;
   DiagnosedMultipleConstructedBases = true;
 }
-S.Diag(D->getUsingDecl()->getLocation(),
+S.Diag(D->getIntroducer()->getLocation(),
diag::note_ambiguous_inherited_constructor_using)
 << DConstructedBase;
   }
@@ -11625,7 +11625,7 @@
 
 /// Determines whether to create a using shadow decl for a particular
 /// decl, given the set of decls existing prior to this using lookup.
-bool Sema::CheckUsingShadowDecl(UsingDecl *Using, NamedDecl *Orig,
+bool Sema::CheckUsingShadowDecl(BaseUsingDecl *BUD, NamedDecl *Orig,
 const LookupResult &Previous,
 UsingShadowDecl *&PrevShadow) {
   // Diagnose finding a decl which is not from a base class of the
@@ -11647,35 +11647,36 @@
   // specialization.  The UsingShadowDecl in D then points directly
   // to A::foo, which will look well-formed when we instantiate.
   // The right solution is to not collapse the shadow-decl chain.
-  if (!getLangOpts().CPlusPlus11 && CurContext->isRecord()) {
-DeclContext *OrigDC = Orig->getDeclContext();
-
-// Handle enums and anonymous structs.
-if (isa(OrigDC)) OrigDC = OrigDC->getParent();
-CXXRecordDecl *OrigRec = cast(Or

[PATCH] D102286: [HWASan] Build separate LAM runtime on x86_64.

2021-05-17 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

In D102286#2764203 , @gulfem wrote:

> We started seeing test failures in our Windows builds in Fuchsia after this 
> patch.
>
>   FAILED: 
> compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
>  
>   C:\b\s\w\ir\x\w\staging\llvm_build\.\bin\clang++.exe 
> --target=aarch64-unknown-linux-gnu --sysroot=C:/b/s/w/ir/x/w/cipd/linux  
> -DHWASAN_WITH_INTERCEPTORS=1 -D_DEBUG -D__STDC_CONSTANT_MACROS 
> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
> -IC:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/.. 
> --target=aarch64-unknown-linux-gnu -fPIC -fvisibility-inlines-hidden 
> -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
> -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
> -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default 
> -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor 
> -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation 
> -fdiagnostics-color -ffunction-sections -fdata-sections 
> -ffile-prefix-map=C:/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins=../staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins
>  -ffile-prefix-map=C:/b/s/w/ir/x/w/llvm-project/= -no-canonical-prefixes 
> -Wall -std=c++14 -Wno-unused-parameter -O2 -g -DNDEBUG-fPIC -fno-builtin 
> -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector 
> -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only 
> -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -fPIC 
> -ffreestanding -DHWASAN_ALIASING_MODE -UNDEBUG -MD -MT 
> compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
>  -MF 
> compiler-rt\lib\hwasan\CMakeFiles\RTHwasanAliases.aarch64.dir\hwasan_interceptors.cpp.o.d
>  -o 
> compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
>  -c 
> C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
>   In file included from 
> C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp:18:
>   C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan.h:41:6: error: 
> Aliasing mode is only supported on x86_64
>
> The error message to the full build:
> https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/build/stdout
>
> The CMake commands:
> https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/configure/execution_details
>
> @morehouse do you have any idea?

Looks like the same issue I fixed in https://reviews.llvm.org/rGd97bab651185.  
Let me know if you have the issue after that commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102286

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


[PATCH] D101327: [Clang][Driver] validate sysregs for -mstack-protector-guard-reg=

2021-05-17 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers abandoned this revision.
nickdesaulniers added a comment.

I don't plan to land this; I wrote it in case it comes up in code review.  
llvm's codegen will `report_fatal_error` for garbage sysregs.  If it comes up 
again in the future, this phab review will still exist for reference, but I 
suggest we only add what's needed in that case, not all possible sysregs since 
most make sense in this context I suspect.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101327

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


[PATCH] D100919: [AArch64] Support customizing stack protector guard

2021-05-17 Thread Nick Desaulniers 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 rG0f417789192e: [AArch64] Support customizing stack protector 
guard (authored by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100919

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/stack-protector-guard.c
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
  llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll

Index: llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
@@ -0,0 +1,105 @@
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=0 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NO-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=8 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-POSITIVE-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=-8 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NEGATIVE-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=1 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NPOT-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=-1 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NPOT-NEG-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=257 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-257-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=-257 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-MINUS-257-OFFSET %s
+
+; XFAIL
+; RUN: not --crash llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=32761 -o - 2>&1 | \
+; RUN: FileCheck --check-prefix=CHECK-BAD-OFFSET %s
+; RUN: not --crash llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=-4096 -o - 2>&1 | \
+; RUN: FileCheck --check-prefix=CHECK-BAD-OFFSET %s
+; RUN: not --crash llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=4097 -o - 2>&1 | \
+; RUN: FileCheck --check-prefix=CHECK-BAD-OFFSET %s
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; Verify that we `mrs` from `SP_EL0` twice, rather than load from
+; __stack_chk_guard.
+define dso_local void @foo(i64 %t) local_unnamed_addr #0 {
+; CHECK-LABEL:   foo:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT:stp x29, x30, [sp, #-16]! // 16-byte Folded Spill
+; CHECK-NEXT:mov x29, sp
+; CHECK-NEXT:sub sp, sp, #16 // =16
+; CHECK-NEXT:.cfi_def_cfa w29, 16
+; CHECK-NEXT:.cfi_offset w30, -8
+; CHECK-NEXT:.cfi_offset w29, -16
+; CHECK-NEXT:mrs x8, SP_EL0
+; CHECK-NO-OFFSET:   ldr x8, [x8]
+; CHECK-POSITIVE-OFFSET: ldr x8, [x8, #8]
+; CHECK-NEGATIVE-OFFSET: ldur x8, [x8, #-8]
+; CHECK-NPOT-OFFSET: ldur x8, [x8, #1]
+; CHECK-NPOT-NEG-OFFSET: ldur x8, [x8, #-1]
+; CHECK-257-OFFSET:  add x8, x8, #257
+; CHECK-257-OFFSET-NEXT: ldr x8, [x8]
+; CHECK-MINUS-257-OFFSET:  sub x8, x8, #257
+; CHECK-MINUS-257-OFFSET-NEXT: ldr x8, [x8]
+; CHECK-NEXT:lsl x9, x0, #2
+; CHECK-NEXT:add x9, x9, #15 // =15
+; CHECK-NEXT:and x9, x9, #0xfff0
+; CHECK-NEXT:stur x8, [x29, #-8]
+; CHECK-NEXT:mov x8, sp
+; CHECK-NEXT:sub x0, x8, x9
+; CHECK-NEXT:mov sp, x0
+; CHECK-NEXT:bl baz
+; CHECK-NEXT:ldur x8, [x29, #-8]
+; CHECK-NEXT:mrs x9, SP_EL0
+; CHECK-NO-OFFSET:   ldr x9, [x9]
+; CHECK-POSITIVE-OFFSET: ldr x9, [x9, #8]
+; CHECK-NEGATIVE-OFFSET: ldur x9, [x9, #-8]
+; CHECK-NPOT-OFFSET: ldur x9, [x9, #1]
+; CHECK-NPOT-NEG-OFFSET: ldur x9, [x9, #-1]
+; CHECK-257-OFFSET:  add x9, x9, #257
+; CHECK-257-OFFSET-NEXT: ldr x9, [x9]
+; CHECK-MINUS-257-OFFSET: 

[clang] 0f41778 - [AArch64] Support customizing stack protector guard

2021-05-17 Thread Nick Desaulniers via cfe-commits

Author: Nick Desaulniers
Date: 2021-05-17T11:49:22-07:00
New Revision: 0f417789192e74f9d2fad0f6aee4efc394257176

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

LOG: [AArch64] Support customizing stack protector guard

Follow up to D88631 but for aarch64; the Linux kernel uses the command
line flags:

1. -mstack-protector-guard=sysreg
2. -mstack-protector-guard-reg=sp_el0
3. -mstack-protector-guard-offset=0

to use the system register sp_el0 for the stack canary, enabling the
kernel to have a unique stack canary per task (like a thread, but not
limited to userspace as the kernel can preempt itself).

Address pr/47341 for aarch64.

Fixes: https://github.com/ClangBuiltLinux/linux/issues/289
Signed-off-by: Nick Desaulniers 

Reviewed By: xiangzhangllvm, DavidSpickett, dmgreen

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

Added: 
llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll

Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/stack-protector-guard.c
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 901013033ba6a..c77c34a8a57d6 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -364,8 +364,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// other styles we may implement in the future.
   std::string StackProtectorGuard;
 
-  /// The TLS base register when StackProtectorGuard is "tls".
+  /// The TLS base register when StackProtectorGuard is "tls", or register used
+  /// to store the stack canary for "sysreg".
   /// On x86 this can be "fs" or "gs".
+  /// On AArch64 this can only be "sp_el0".
   std::string StackProtectorGuardReg;
 
   /// Path to ignorelist file specifying which objects

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 303b5b95e76d7..31239d29ddf1c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3410,7 +3410,7 @@ def mstack_protector_guard_EQ : Joined<["-"], 
"mstack-protector-guard=">, Group<
   MarshallingInfoString>;
 def mstack_protector_guard_offset_EQ : Joined<["-"], 
"mstack-protector-guard-offset=">, Group, Flags<[CC1Option]>,
   HelpText<"Use the given offset for addressing the stack-protector guard">,
-  MarshallingInfoInt, "INT_MAX">;
+  MarshallingInfoInt, "INT_MAX", 
"int">;
 def mstack_protector_guard_reg_EQ : Joined<["-"], 
"mstack-protector-guard-reg=">, Group, Flags<[CC1Option]>,
   HelpText<"Use the given reg for addressing the stack-protector guard">,
   MarshallingInfoString, [{"none"}]>;

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 837ffd0950753..989210ca53907 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -559,10 +559,11 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.UniqueBasicBlockSectionNames =
   CodeGenOpts.UniqueBasicBlockSectionNames;
   Options.StackProtectorGuard =
-  llvm::StringSwitch(CodeGenOpts
-  .StackProtectorGuard)
+  llvm::StringSwitch(
+  CodeGenOpts.StackProtectorGuard)
   .Case("tls", llvm::StackProtectorGuards::TLS)
   .Case("global", llvm::StackProtectorGuards::Global)
+  .Case("sysreg", llvm::StackProtectorGuards::SysReg)
   .Default(llvm::StackProtectorGuards::None);
   Options.StackProtectorGuardOffset = CodeGenOpts.StackProtectorGuardOffset;
   Options.StackProtectorGuardReg = CodeGenOpts.StackProtectorGuardReg;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index fe0f57d4c4791..7d4dfdc46492d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3102,25 +3102,28 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
 }
   }
 
-  // First support "tls" and "global" for X86 target.
-  // TODO: Support "sysreg" for AArch64.
   const std::string &TripleStr = EffectiveTriple.getTriple();
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_EQ)) {
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
-if (Value != "tls" && Value != "global") {
+if (EffectiveTriple.isX86() && Value != "tls" && Value != "global") {
   D.Diag(diag::err_drv

[PATCH] D102286: [HWASan] Build separate LAM runtime on x86_64.

2021-05-17 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

We started seeing test failures in our Windows builds in Fuchsia after this 
patch.

  FAILED: 
compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
 
  C:\b\s\w\ir\x\w\staging\llvm_build\.\bin\clang++.exe 
--target=aarch64-unknown-linux-gnu --sysroot=C:/b/s/w/ir/x/w/cipd/linux  
-DHWASAN_WITH_INTERCEPTORS=1 -D_DEBUG -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-IC:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/.. 
--target=aarch64-unknown-linux-gnu -fPIC -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type 
-Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wstring-conversion -Wmisleading-indentation -fdiagnostics-color 
-ffunction-sections -fdata-sections 
-ffile-prefix-map=C:/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins=../staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins
 -ffile-prefix-map=C:/b/s/w/ir/x/w/llvm-project/= -no-canonical-prefixes -Wall 
-std=c++14 -Wno-unused-parameter -O2 -g -DNDEBUG-fPIC -fno-builtin 
-fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector 
-fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only 
-Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -fPIC 
-ffreestanding -DHWASAN_ALIASING_MODE -UNDEBUG -MD -MT 
compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
 -MF 
compiler-rt\lib\hwasan\CMakeFiles\RTHwasanAliases.aarch64.dir\hwasan_interceptors.cpp.o.d
 -o 
compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o
 -c C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
  In file included from 
C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp:18:
  C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan.h:41:6: error: 
Aliasing mode is only supported on x86_64

The error message to the full build:
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/build/stdout

The CMake commands:
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/configure/execution_details

@morehouse do you have any idea?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102286

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


[PATCH] D100919: [AArch64] Support customizing stack protector guard

2021-05-17 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers marked an inline comment as done.
nickdesaulniers added a comment.

Appreciate the reviews; ++beers_owed;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100919

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


[PATCH] D100919: [AArch64] Support customizing stack protector guard

2021-05-17 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers marked 3 inline comments as done.
nickdesaulniers added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp:1954
+  // than 23760.
+  // It might be nice to use AArch64::MOVi32imm here, which would get
+  // expanded in PreSched2 after PostRA, but our lone scratch Reg already

dmgreen wrote:
> It may be possible to do something earlier, where a we add the MOVi32imm 
> earlier before registry allocation and use that as the register for the ldr 
> offset. That would keep it simpler than trying to find scratch registers, and 
> may be optimized better by the pipeline.
Sure; added that as a comment; hopefully we wont need it, but "never say never 
(again)."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100919

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


[PATCH] D100919: [AArch64] Support customizing stack protector guard

2021-05-17 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 345949.
nickdesaulniers added a comment.

- braces, typo fix, add comment about additional approaches


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100919

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/stack-protector-guard.c
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
  llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll

Index: llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll
@@ -0,0 +1,105 @@
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=0 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NO-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=8 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-POSITIVE-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=-8 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NEGATIVE-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=1 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NPOT-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=-1 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NPOT-NEG-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=257 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-257-OFFSET %s
+; RUN: llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=-257 -verify-machineinstrs -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-MINUS-257-OFFSET %s
+
+; XFAIL
+; RUN: not --crash llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=32761 -o - 2>&1 | \
+; RUN: FileCheck --check-prefix=CHECK-BAD-OFFSET %s
+; RUN: not --crash llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=-4096 -o - 2>&1 | \
+; RUN: FileCheck --check-prefix=CHECK-BAD-OFFSET %s
+; RUN: not --crash llc %s --stack-protector-guard=sysreg \
+; RUN:   --stack-protector-guard-reg=sp_el0 \
+; RUN:   --stack-protector-guard-offset=4097 -o - 2>&1 | \
+; RUN: FileCheck --check-prefix=CHECK-BAD-OFFSET %s
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; Verify that we `mrs` from `SP_EL0` twice, rather than load from
+; __stack_chk_guard.
+define dso_local void @foo(i64 %t) local_unnamed_addr #0 {
+; CHECK-LABEL:   foo:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT:stp x29, x30, [sp, #-16]! // 16-byte Folded Spill
+; CHECK-NEXT:mov x29, sp
+; CHECK-NEXT:sub sp, sp, #16 // =16
+; CHECK-NEXT:.cfi_def_cfa w29, 16
+; CHECK-NEXT:.cfi_offset w30, -8
+; CHECK-NEXT:.cfi_offset w29, -16
+; CHECK-NEXT:mrs x8, SP_EL0
+; CHECK-NO-OFFSET:   ldr x8, [x8]
+; CHECK-POSITIVE-OFFSET: ldr x8, [x8, #8]
+; CHECK-NEGATIVE-OFFSET: ldur x8, [x8, #-8]
+; CHECK-NPOT-OFFSET: ldur x8, [x8, #1]
+; CHECK-NPOT-NEG-OFFSET: ldur x8, [x8, #-1]
+; CHECK-257-OFFSET:  add x8, x8, #257
+; CHECK-257-OFFSET-NEXT: ldr x8, [x8]
+; CHECK-MINUS-257-OFFSET:  sub x8, x8, #257
+; CHECK-MINUS-257-OFFSET-NEXT: ldr x8, [x8]
+; CHECK-NEXT:lsl x9, x0, #2
+; CHECK-NEXT:add x9, x9, #15 // =15
+; CHECK-NEXT:and x9, x9, #0xfff0
+; CHECK-NEXT:stur x8, [x29, #-8]
+; CHECK-NEXT:mov x8, sp
+; CHECK-NEXT:sub x0, x8, x9
+; CHECK-NEXT:mov sp, x0
+; CHECK-NEXT:bl baz
+; CHECK-NEXT:ldur x8, [x29, #-8]
+; CHECK-NEXT:mrs x9, SP_EL0
+; CHECK-NO-OFFSET:   ldr x9, [x9]
+; CHECK-POSITIVE-OFFSET: ldr x9, [x9, #8]
+; CHECK-NEGATIVE-OFFSET: ldur x9, [x9, #-8]
+; CHECK-NPOT-OFFSET: ldur x9, [x9, #1]
+; CHECK-NPOT-NEG-OFFSET: ldur x9, [x9, #-1]
+; CHECK-257-OFFSET:  add x9, x9, #257
+; CHECK-257-OFFSET-NEXT: ldr x9, [x9]
+; CHECK-MINUS-257-OFFSET:  sub x9, x9, #257
+; CHECK-MINUS-257-OFFSET-NEXT: ldr x9, [x9]
+; CHECK-NEXT:cmp x9, x8
+;

[PATCH] D102643: [analyzer][Z3][NFC] Use GTEST_SKIP instead of hacks

2021-05-17 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: bkramer, martong, NoQ, Szelethus, mikhail.ramalho.
Herald added subscribers: ASDenysPetrov, dkrupp, donat.nagy, a.sidorin, 
rnkovacs, szepet, baloghadamsoftware, xazax.hun, whisperity.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Since @bkramer bumped gtest to 1.10.0 I think it's a good time to clean up some 
of my hacks.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102643

Files:
  clang/unittests/StaticAnalyzer/FalsePositiveRefutationBRVisitorTest.cpp


Index: clang/unittests/StaticAnalyzer/FalsePositiveRefutationBRVisitorTest.cpp
===
--- clang/unittests/StaticAnalyzer/FalsePositiveRefutationBRVisitorTest.cpp
+++ clang/unittests/StaticAnalyzer/FalsePositiveRefutationBRVisitorTest.cpp
@@ -19,13 +19,6 @@
 #include "llvm/Config/llvm-config.h"
 #include "gtest/gtest.h"
 
-// FIXME: Use GTEST_SKIP() instead if GTest is updated to version 1.10.0
-#ifdef LLVM_WITH_Z3
-#define SKIP_WITHOUT_Z3
-#else
-#define SKIP_WITHOUT_Z3 return
-#endif
-
 namespace clang {
 namespace ento {
 namespace {
@@ -109,7 +102,7 @@
 "-Xclang", "-analyzer-config", "-Xclang", "crosscheck-with-z3=true"};
 
 TEST(FalsePositiveRefutationBRVisitor, UnSatInTheMiddleNoReport) {
-  SKIP_WITHOUT_Z3;
+  GTEST_SKIP() << "Requires the LLVM_WITH_Z3 cmake option.";
   constexpr auto Code = R"(
  void reachedWithContradiction();
  void reachedWithNoContradiction();
@@ -140,7 +133,7 @@
 }
 
 TEST(FalsePositiveRefutationBRVisitor, UnSatAtErrorNodeWithNewSymbolNoReport) {
-  SKIP_WITHOUT_Z3;
+  GTEST_SKIP() << "Requires the LLVM_WITH_Z3 cmake option.";
   constexpr auto Code = R"(
 void reportIfCanBeTrue(bool);
 void reachedWithNoContradiction();
@@ -172,7 +165,7 @@
 
 TEST(FalsePositiveRefutationBRVisitor,
  UnSatAtErrorNodeDueToRefinedConstraintNoReport) {
-  SKIP_WITHOUT_Z3;
+  GTEST_SKIP() << "Requires the LLVM_WITH_Z3 cmake option.";
   constexpr auto Code = R"(
 void reportIfCanBeTrue(bool);
 void reachedWithNoContradiction();


Index: clang/unittests/StaticAnalyzer/FalsePositiveRefutationBRVisitorTest.cpp
===
--- clang/unittests/StaticAnalyzer/FalsePositiveRefutationBRVisitorTest.cpp
+++ clang/unittests/StaticAnalyzer/FalsePositiveRefutationBRVisitorTest.cpp
@@ -19,13 +19,6 @@
 #include "llvm/Config/llvm-config.h"
 #include "gtest/gtest.h"
 
-// FIXME: Use GTEST_SKIP() instead if GTest is updated to version 1.10.0
-#ifdef LLVM_WITH_Z3
-#define SKIP_WITHOUT_Z3
-#else
-#define SKIP_WITHOUT_Z3 return
-#endif
-
 namespace clang {
 namespace ento {
 namespace {
@@ -109,7 +102,7 @@
 "-Xclang", "-analyzer-config", "-Xclang", "crosscheck-with-z3=true"};
 
 TEST(FalsePositiveRefutationBRVisitor, UnSatInTheMiddleNoReport) {
-  SKIP_WITHOUT_Z3;
+  GTEST_SKIP() << "Requires the LLVM_WITH_Z3 cmake option.";
   constexpr auto Code = R"(
  void reachedWithContradiction();
  void reachedWithNoContradiction();
@@ -140,7 +133,7 @@
 }
 
 TEST(FalsePositiveRefutationBRVisitor, UnSatAtErrorNodeWithNewSymbolNoReport) {
-  SKIP_WITHOUT_Z3;
+  GTEST_SKIP() << "Requires the LLVM_WITH_Z3 cmake option.";
   constexpr auto Code = R"(
 void reportIfCanBeTrue(bool);
 void reachedWithNoContradiction();
@@ -172,7 +165,7 @@
 
 TEST(FalsePositiveRefutationBRVisitor,
  UnSatAtErrorNodeDueToRefinedConstraintNoReport) {
-  SKIP_WITHOUT_Z3;
+  GTEST_SKIP() << "Requires the LLVM_WITH_Z3 cmake option.";
   constexpr auto Code = R"(
 void reportIfCanBeTrue(bool);
 void reachedWithNoContradiction();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102280: [analyzer] Engine: fix crash with SEH __leave keyword

2021-05-17 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGebcf030efc5e: [analyzer] Engine: fix crash with SEH __leave 
keyword (authored by AbbasSabra, committed by steakhal).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102280

Files:
  clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
  clang/test/Analysis/ms-seh.cpp


Index: clang/test/Analysis/ms-seh.cpp
===
--- /dev/null
+++ clang/test/Analysis/ms-seh.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple 
x86_64-pc-windows-msvc19.11.0 -fms-extensions -verify %s
+
+void clang_analyzer_warnIfReached();
+int filter();
+
+void try_except_leave() {
+  __try {
+__leave;// no-crash
+clang_analyzer_warnIfReached(); // no-warning
+  } __except (filter()) {
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
Index: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -349,6 +349,7 @@
 HandleBranch(cast(Term)->getCond(), Term, B, Pred);
 return;
 
+  case Stmt::SEHLeaveStmtClass:
   case Stmt::ContinueStmtClass:
   case Stmt::BreakStmtClass:
   case Stmt::GotoStmtClass:


Index: clang/test/Analysis/ms-seh.cpp
===
--- /dev/null
+++ clang/test/Analysis/ms-seh.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-pc-windows-msvc19.11.0 -fms-extensions -verify %s
+
+void clang_analyzer_warnIfReached();
+int filter();
+
+void try_except_leave() {
+  __try {
+__leave;// no-crash
+clang_analyzer_warnIfReached(); // no-warning
+  } __except (filter()) {
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
Index: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -349,6 +349,7 @@
 HandleBranch(cast(Term)->getCond(), Term, B, Pred);
 return;
 
+  case Stmt::SEHLeaveStmtClass:
   case Stmt::ContinueStmtClass:
   case Stmt::BreakStmtClass:
   case Stmt::GotoStmtClass:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ebcf030 - [analyzer] Engine: fix crash with SEH __leave keyword

2021-05-17 Thread Balazs Benics via cfe-commits

Author: Abbas Sabra
Date: 2021-05-17T20:10:26+02:00
New Revision: ebcf030efc5ef149e423f8fa2ca705b590a129ed

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

LOG: [analyzer] Engine: fix crash with SEH __leave keyword

MSVC has a `try-except` statement.
This statement could containt a `__leave` keyword, which is similar to
`goto` to the end of the try block. The semantic of this keyword is not
implemented.

We should at least parse such code without crashing.

https://docs.microsoft.com/en-us/cpp/cpp/try-except-statement?view=msvc-160

Patch By: AbbasSabra!

Reviewed By: steakhal

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

Added: 
clang/test/Analysis/ms-seh.cpp

Modified: 
clang/lib/StaticAnalyzer/Core/CoreEngine.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
index 70deb13a8e1ae..ae45ae5aa02f3 100644
--- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -349,6 +349,7 @@ void CoreEngine::HandleBlockExit(const CFGBlock * B, 
ExplodedNode *Pred) {
 HandleBranch(cast(Term)->getCond(), Term, B, Pred);
 return;
 
+  case Stmt::SEHLeaveStmtClass:
   case Stmt::ContinueStmtClass:
   case Stmt::BreakStmtClass:
   case Stmt::GotoStmtClass:

diff  --git a/clang/test/Analysis/ms-seh.cpp b/clang/test/Analysis/ms-seh.cpp
new file mode 100644
index 0..a2f01f8080746
--- /dev/null
+++ b/clang/test/Analysis/ms-seh.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple 
x86_64-pc-windows-msvc19.11.0 -fms-extensions -verify %s
+
+void clang_analyzer_warnIfReached();
+int filter();
+
+void try_except_leave() {
+  __try {
+__leave;// no-crash
+clang_analyzer_warnIfReached(); // no-warning
+  } __except (filter()) {
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}



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


[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2021-05-17 Thread Arthur Eubanks via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG14dfb3831c42: [Clang] -Wunused-but-set-parameter and 
-Wunused-but-set-variable (authored by mbenfield, committed by aeubanks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100581

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp
  clang/test/CodeGen/2007-10-30-Volatile.c
  clang/test/CodeGen/X86/x86_32-xsave.c
  clang/test/CodeGen/X86/x86_64-xsave.c
  clang/test/CodeGen/builtins-arm.c
  clang/test/CodeGen/builtins-riscv.c
  clang/test/FixIt/fixit.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/shift.c
  clang/test/Sema/vector-gcc-compat.c
  clang/test/Sema/vector-gcc-compat.cpp
  clang/test/Sema/warn-unused-but-set-parameters.c
  clang/test/Sema/warn-unused-but-set-variables.c
  clang/test/SemaCXX/goto.cpp
  clang/test/SemaCXX/shift.cpp
  clang/test/SemaCXX/sizeless-1.cpp
  clang/test/SemaCXX/warn-unused-but-set-parameters-cpp.cpp
  clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
  clang/test/SemaObjC/foreach.m

Index: clang/test/SemaObjC/foreach.m
===
--- clang/test/SemaObjC/foreach.m
+++ clang/test/SemaObjC/foreach.m
@@ -1,4 +1,4 @@
-/* RUN: %clang_cc1 -Wall -fsyntax-only -verify -std=c89 -pedantic %s
+/* RUN: %clang_cc1 -Wall -Wno-unused-but-set-variable -fsyntax-only -verify -std=c89 -pedantic %s
  */
 
 @class NSArray;
Index: clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fblocks -fsyntax-only -Wunused-but-set-variable -verify %s
+
+struct S {
+  int i;
+};
+
+struct __attribute__((warn_unused)) SWarnUnused {
+  int j;
+};
+
+int f0() {
+  int y; // expected-warning{{variable 'y' set but not used}}
+  y = 0;
+
+  int z __attribute__((unused));
+  z = 0;
+
+  // In C++, don't warn for structs. (following gcc's behavior)
+  struct S s;
+  struct S t;
+  s = t;
+
+  // Unless it's marked with the warn_unused attribute.
+  struct SWarnUnused swu; // expected-warning{{variable 'swu' set but not used}}
+  struct SWarnUnused swu2;
+  swu = swu2;
+
+  int x;
+  x = 0;
+  return x + 5;
+}
+
+void f1(void) {
+  (void)^() {
+int y; // expected-warning{{variable 'y' set but not used}}
+y = 0;
+
+int x;
+x = 0;
+return x;
+  };
+}
+
+void f2() {
+  // Don't warn for either of these cases.
+  constexpr int x = 2;
+  const int y = 1;
+  char a[x];
+  char b[y];
+}
Index: clang/test/SemaCXX/warn-unused-but-set-parameters-cpp.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unused-but-set-parameters-cpp.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fblocks -fsyntax-only -Wunused-but-set-parameter -verify %s
+
+int f0(int x,
+   int y, // expected-warning{{parameter 'y' set but not used}}
+   int z __attribute__((unused))) {
+  y = 0;
+  return x;
+}
+
+void f1(void) {
+  (void)^(int x,
+  int y, // expected-warning{{parameter 'y' set but not used}}
+  int z __attribute__((unused))) {
+y = 0;
+return x;
+  };
+}
+
+struct S {
+  int i;
+};
+
+// In C++, don't warn for a struct (following gcc).
+void f3(struct S s) {
+  struct S t;
+  s = t;
+}
+
+// Make sure this doesn't warn.
+struct A {
+  int i;
+  A(int j) : i(j) {}
+};
Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++98 %s
-// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++11 %s
-// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++17 %s
-// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=gnu++17 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wno-unused-but-set-variable -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++98 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wno-unused-but-set-variable -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -s

[clang] 14dfb38 - [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2021-05-17 Thread Arthur Eubanks via cfe-commits

Author: Michael Benfield
Date: 2021-05-17T11:02:26-07:00
New Revision: 14dfb3831c425c7f22540a2160424224008c257e

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

LOG: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

These are intended to mimic warnings available in gcc.

Reviewed By: aeubanks

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

Added: 
clang/test/Sema/warn-unused-but-set-parameters.c
clang/test/Sema/warn-unused-but-set-variables.c
clang/test/SemaCXX/warn-unused-but-set-parameters-cpp.cpp
clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp
clang/test/CodeGen/2007-10-30-Volatile.c
clang/test/CodeGen/X86/x86_32-xsave.c
clang/test/CodeGen/X86/x86_64-xsave.c
clang/test/CodeGen/builtins-arm.c
clang/test/CodeGen/builtins-riscv.c
clang/test/FixIt/fixit.cpp
clang/test/Misc/warning-wall.c
clang/test/Sema/shift.c
clang/test/Sema/vector-gcc-compat.c
clang/test/Sema/vector-gcc-compat.cpp
clang/test/SemaCXX/goto.cpp
clang/test/SemaCXX/shift.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaObjC/foreach.m

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index f6a4fbb1e04c..35088f845da4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -725,6 +725,7 @@ def UnusedMemberFunction : 
DiagGroup<"unused-member-function",
 def UnusedLabel : DiagGroup<"unused-label">;
 def UnusedLambdaCapture : DiagGroup<"unused-lambda-capture">;
 def UnusedParameter : DiagGroup<"unused-parameter">;
+def UnusedButSetParameter : DiagGroup<"unused-but-set-parameter">;
 def UnusedResult : DiagGroup<"unused-result">;
 def PotentiallyEvaluatedExpression : 
DiagGroup<"potentially-evaluated-expression">;
 def UnevaluatedExpression : DiagGroup<"unevaluated-expression",
@@ -734,6 +735,7 @@ def UnusedValue : DiagGroup<"unused-value", 
[UnusedComparison, UnusedResult,
 def UnusedConstVariable : DiagGroup<"unused-const-variable">;
 def UnusedVariable : DiagGroup<"unused-variable",
[UnusedConstVariable]>;
+def UnusedButSetVariable : DiagGroup<"unused-but-set-variable">;
 def UnusedLocalTypedef : DiagGroup<"unused-local-typedef">;
 def UnusedPropertyIvar :  DiagGroup<"unused-property-ivar">;
 def UnusedGetterReturnValue : DiagGroup<"unused-getter-return-value">;
@@ -875,7 +877,7 @@ def Unused : DiagGroup<"unused",
 // UnusedMemberFunction, (clean-up llvm before 
enabling)
 UnusedPrivateField, UnusedLambdaCapture,
 UnusedLocalTypedef, UnusedValue, UnusedVariable,
-UnusedPropertyIvar]>,
+UnusedButSetVariable, UnusedPropertyIvar]>,
 DiagCategory<"Unused Entity Issue">;
 
 // Format settings.
@@ -927,6 +929,7 @@ def Extra : DiagGroup<"extra", [
 MissingMethodReturnType,
 SignCompare,
 UnusedParameter,
+UnusedButSetParameter,
 NullPointerArithmetic,
 EmptyInitStatement,
 StringConcatation,

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9dd9b1b5118b..982606e4f6ca 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -310,8 +310,12 @@ def note_riscv_repeated_interrupt_attribute : Note<
   "repeated RISC-V 'interrupt' attribute is here">;
 def warn_unused_parameter : Warning<"unused parameter %0">,
   InGroup, DefaultIgnore;
+def warn_unused_but_set_parameter : Warning<"parameter %0 set but not used">,
+  InGroup, DefaultIgnore;
 def warn_unused_variable : Warning<"unused variable %0">,
   InGroup, DefaultIgnore;
+def warn_unused_but_set_variable : Warning<"variable %0 set but not used">,
+  InGroup, DefaultIgnore;
 def warn_unused_local_typedef : Warning<
   "unused %select{typedef|type alias}0 %1">,
   InGroup, DefaultIgnore;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b6143d1d3178..160760577c5b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1514,6 +1514,11 @@ class Sema final {
 
   bool WarnedStackExhausted = false;
 
+  /// Increment when we find a reference; decrement when we find an ignored
+  /// assignment.  Ultimately the value is 0 if every reference is an igno

[PATCH] D102592: [sanitizer] Caught global buffer underflow for first variable

2021-05-17 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

Would you mind to add compiler-rt/test/asan which triggers this one?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102592

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


[PATCH] D102568: [Driver] Delete -mimplicit-it=

2021-05-17 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers accepted this revision.
nickdesaulniers added a comment.
This revision is now accepted and ready to land.

Seems fine to me; the only reference in all of Android that looks problematic 
might be building libaom for windows: 
https://android.googlesource.com/platform/external/libaom/+/refs/heads/master/libaom/build/cmake/aom_configure.cmake#158,
 which I don't think we do for Android. Should be an easy fix either way 
(replace `-mimplicit-it=always` with `-Wa,-wmimplicit-it=always`). The linux 
kernel already uses `-Wa,-mimplicit-it`. Also, GCC rejects the option: 
https://godbolt.org/z/8rxjY9dPj.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102568

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


[PATCH] D102547: [clang][AVR] Redefine [u]int16_t to be compatible with avr-gcc

2021-05-17 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM, thanks.


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

https://reviews.llvm.org/D102547

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 345939.
hctim added a comment.

Add arm32 to supported.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/aligned-new.cpp
  compiler-rt/test/scudo/alignment.c
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/double-free.cpp
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/lit.site.cfg.py.in
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/options.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preinit.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/quarantine.c
  compiler-rt/test/scudo/random_shuffle.cpp
  compiler-rt/test/scudo/realloc.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/sized-delete.cpp
  compiler-rt/test/scudo/sizes.cpp
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  compiler-rt/test/scudo/standalone/aligned-new.cpp
  compiler-rt/test/scudo/standalone/alignment.c
  compiler-rt/test/scudo/standalone/dealloc-race.c
  compiler-rt/test/scudo/standalone/double-free.cpp
  compiler-rt/test/scudo/standalone/fsanitize.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
  compiler-rt/test/scudo/standalone/lit.cfg.py
  compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
  compiler-rt/test/scudo/standalone/malloc.cpp
  compiler-rt/test/scudo/standalone/memalign.c
  compiler-rt/test/scudo/standalone/mismatch.cpp
  compiler-rt/test/scudo/standalone/options.cpp
  compiler-rt/test/scudo/standalone/preinit.c
  compiler-rt/test/scudo/standalone/preload.cpp
  compiler-rt/test/scudo/standalone/random_shuffle.cpp
  compiler-rt/test/scudo/standalone/sized-delete.cpp
  compiler-rt/test/scudo/standalone/stats.c
  compiler-rt/test/scudo/standalone/tsd_destruction.c
  compiler-rt/test/scudo/stats.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ /dev/null
@@ -1,8 +0,0 @@
-UNSUPPORTED: android
-
-Verify that various functions are *not* present in the minimal binary. Presence
-of those symbols in the minimal runtime would mean that the split code made it
-back into the core Sanitizer runtime library.
-
-RUN: nm %shared_minlibscudo | not grep Symbolizer
-RUN: nm %shared_minlibscudo | not grep Coverage
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- /dev/null
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,42 +0,0 @@
-// RUN: %clang_scudo %s -o %t
-// RUN: %run %t 2>&1
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-// Some of glibc's own thread local data is destroyed after a user's thread
-// local destructors are called, via __libc_thread_freeres. This might involve
-// calling free, as is the case for strerror_thread_freeres.
-// If there is no prior heap operation in the thread, this free would end up 
-// initializing some thread specific data that would never be destroyed
-// properly, while still being deallocated when the TLS goes away. As a result,
-// a program could SEGV, usually in
-// __sanitizer::AllocatorGlobalStats::Unregister, where one of the doubly
-// linked list links would refer to a now unmapped memory area.
-
-// This test reproduces those circumstances. Success means executing without
-// a segmentation fault.
-
-const int kNumThreads = 16;
-pthread_t tid[kNumThreads];
-
-void *thread_func(void *arg

[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Kostya Kortchinsky via Phabricator via cfe-commits
cryptoad accepted this revision.
cryptoad added a comment.
This revision is now accepted and ready to land.

I think this is good, with the additional arch




Comment at: compiler-rt/cmake/config-ix.cmake:338
 set(ALL_SCUDO_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} 
${MIPS64} ${PPC64})
-set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})
+set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${MIPS32} 
${MIPS64} ${PPC64})
 if(APPLE)

${ARM32} as well please


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

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


[PATCH] D91466: [WIP][clang][Fuchsia] Support HWASan for Fuchsia

2021-05-17 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 345931.
leonardchan added a comment.

Update to some feedback from first round of reviews. Minor refactoring of code 
that can be shared between the linux and fuchsia implementations. Still need to 
discuss refactoring the hwasan threads implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91466

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/hwasan/CMakeLists.txt
  compiler-rt/lib/hwasan/hwasan.cpp
  compiler-rt/lib/hwasan/hwasan.h
  compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
  compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
  compiler-rt/lib/hwasan/hwasan_interceptors.cpp
  compiler-rt/lib/hwasan/hwasan_interface_internal.h
  compiler-rt/lib/hwasan/hwasan_linux.cpp
  compiler-rt/lib/hwasan/hwasan_poisoning.cpp
  compiler-rt/lib/hwasan/hwasan_thread.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_fuchsia.h
  compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp

Index: compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
===
--- compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
@@ -54,6 +54,10 @@
   return false;
 }
 
+// This is mainly used by hwasan for online symbolization. This isn't needed
+// since hwasan can always just dump stack frames for offline symbolization.
+bool Symbolizer::SymbolizeFrame(uptr addr, FrameInfo *info) { return false; }
+
 // This is used in some places for suppression checking, which we
 // don't really support for Fuchsia.  It's also used in UBSan to
 // identify a PC location to a function name, so we always fill in
Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_fuchsia.h
===
--- /dev/null
+++ compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_fuchsia.h
@@ -0,0 +1,25 @@
+//===-- sanitizer_platform_limits_fuchsia.h ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of Sanitizer common code.
+//
+// Sizes and layouts of platform-specific Fuchsia data structures.
+//===--===//
+
+#ifndef SANITIZER_PLATFORM_LIMITS_FUCHSIA_H
+#define SANITIZER_PLATFORM_LIMITS_FUCHSIA_H
+
+#if SANITIZER_FUCHSIA
+
+namespace __sanitizer {
+struct __sanitizer_struct_mallinfo {};
+}  // namespace __sanitizer
+
+#endif  // SANITIZER_FUCHSIA
+
+#endif
Index: compiler-rt/lib/hwasan/hwasan_thread.cpp
===
--- compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -51,12 +51,18 @@
   // ScopedTaggingDisable needs GetCurrentThread to be set up.
   ScopedTaggingDisabler disabler;
 
+#if !SANITIZER_FUCHSIA
   uptr tls_size;
   uptr stack_size;
   GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, &tls_begin_,
&tls_size);
   stack_top_ = stack_bottom_ + stack_size;
   tls_end_ = tls_begin_ + tls_size;
+#else
+  __sanitizer::GetThreadStackTopAndBottom(true, &stack_top_,
+  &stack_bottom_);
+  tls_end_ = tls_begin_ = 0;
+#endif
 
   if (stack_bottom_) {
 int local;
Index: compiler-rt/lib/hwasan/hwasan_poisoning.cpp
===
--- compiler-rt/lib/hwasan/hwasan_poisoning.cpp
+++ compiler-rt/lib/hwasan/hwasan_poisoning.cpp
@@ -22,6 +22,10 @@
 uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) {
   CHECK(IsAligned(p, kShadowAlignment));
   CHECK(IsAligned(size, kShadowAlignment));
+#if SANITIZER_FUCHSIA
+  __sanitizer_fill_shadow(p, size, tag,
+  common_flags()->clear_shadow_mmap_threshold);
+#else
   uptr shadow_start = MemToShadow(p);
   uptr shadow_size = MemToShadowSize(size);
 
@@ -40,6 +44,7 @@
   } else {
 internal_memset((void *)shadow_start, tag, shadow_size);
   }
+#endif
   return AddTagToPointer(p, tag);
 }
 
Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -242,18 +242,6 @@
   return p >= kHighMemStart || (p >= kLowMemStart && p <= kLowMemEnd);
 }
 
-static void HwasanAtExit(void) {
-  if (common_flags()->print_module_map)
-DumpProcessMap();
-  if (flags()->print_stats && (flags()->atexit || hwasan_report_count > 0))
-ReportStats();
-  if (hwasan

[PATCH] D102640: [ASTimporter] Remove decl from lookup only if it has decl context

2021-05-17 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: teemperor, shafik, balazske, a.sidorin, martong.
Herald added subscribers: whisperity, rnkovacs.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In the case of `TypedefDecl`s we set the `DeclContext` after we imported it.
It turns out, it could lead to null pointer dereferences during the cleanup 
part of a failed import.

This patch demonstrates this issue and fixes it by checking if the DeclContext 
is available or not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102640

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5225,6 +5225,40 @@
   EXPECT_TRUE(ImportedOK);
 }
 
+TEST_P(ErrorHandlingTest, ODRViolationWithinTypedefDecls) {
+  // Importing `z` should fail - instead of crashing - due to an ODR violation.
+  // The `bar::e` typedef sets it's DeclContext after the import is done.
+  // However, if the importation fails, it will be left as a nullptr.
+  // During the cleanup of the failed import, we should check whether the
+  // DeclContext is null or not - instead of dereferencing that 
unconditionally.
+  constexpr auto ToTUCode = R"(
+  namespace X {
+struct bar {
+  int odr_violation;
+};
+  })";
+  constexpr auto FromTUCode = R"(
+  namespace X {
+enum b {};
+struct bar {
+  typedef b e;
+  static e d;
+};
+  }
+  int z = X::bar::d;
+  )";
+  Decl *ToTU = getToTuDecl(ToTUCode, Lang_CXX11);
+  static_cast(ToTU);
+  Decl *FromTU = getTuDecl(FromTUCode, Lang_CXX11);
+  auto *FromZ =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("z")));
+  ASSERT_TRUE(FromZ);
+  ASSERT_TRUE(FromZ->hasInit());
+
+  auto *ImportedZ = Import(FromZ, Lang_CXX11);
+  EXPECT_FALSE(ImportedZ);
+}
+
 // An error should be set for a class if it had a previous import with an error
 // from another TU.
 TEST_P(ErrorHandlingTest,
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -8383,7 +8383,11 @@
   // traverse of the 'to' context).
   auto PosF = ImportedFromDecls.find(ToD);
   if (PosF != ImportedFromDecls.end()) {
-SharedState->removeDeclFromLookup(ToD);
+// In the case of TypedefNameDecl we create the Decl first and only
+// then we import and set its DeclContext. So, the DC might not be set
+// when we reach here.
+if (ToD->getDeclContext())
+  SharedState->removeDeclFromLookup(ToD);
 ImportedFromDecls.erase(PosF);
   }
 


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5225,6 +5225,40 @@
   EXPECT_TRUE(ImportedOK);
 }
 
+TEST_P(ErrorHandlingTest, ODRViolationWithinTypedefDecls) {
+  // Importing `z` should fail - instead of crashing - due to an ODR violation.
+  // The `bar::e` typedef sets it's DeclContext after the import is done.
+  // However, if the importation fails, it will be left as a nullptr.
+  // During the cleanup of the failed import, we should check whether the
+  // DeclContext is null or not - instead of dereferencing that unconditionally.
+  constexpr auto ToTUCode = R"(
+  namespace X {
+struct bar {
+  int odr_violation;
+};
+  })";
+  constexpr auto FromTUCode = R"(
+  namespace X {
+enum b {};
+struct bar {
+  typedef b e;
+  static e d;
+};
+  }
+  int z = X::bar::d;
+  )";
+  Decl *ToTU = getToTuDecl(ToTUCode, Lang_CXX11);
+  static_cast(ToTU);
+  Decl *FromTU = getTuDecl(FromTUCode, Lang_CXX11);
+  auto *FromZ =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("z")));
+  ASSERT_TRUE(FromZ);
+  ASSERT_TRUE(FromZ->hasInit());
+
+  auto *ImportedZ = Import(FromZ, Lang_CXX11);
+  EXPECT_FALSE(ImportedZ);
+}
+
 // An error should be set for a class if it had a previous import with an error
 // from another TU.
 TEST_P(ErrorHandlingTest,
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -8383,7 +8383,11 @@
   // traverse of the 'to' context).
   auto PosF = ImportedFromDecls.find(ToD);
   if (PosF != ImportedFromDecls.end()) {
-SharedState->removeDeclFromLookup(ToD);
+// In the case of TypedefNameDecl we create the Decl first and only
+// then we import and set its DeclContext. So, the DC might not be set
+// when

[PATCH] D102585: [M68k] Support inline asm operands w/ simple constraints

2021-05-17 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

LGTM but please review the linter warnings.




Comment at: clang/lib/Basic/Targets/M68k.cpp:145
   case 'd': // data register
-  case 'f': // floating point register
 info.setAllowsRegister();

did you mean to drop support for `'f'`?



Comment at: llvm/test/CodeGen/M68k/inline-asm.ll:36
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 -32769)
+  call void asm sideeffect "move.l $0, %d1", "^Cj"(i32 32768)
+  ret void

You probably should add tests for all newly added constraints with valid input.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102585

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


[PATCH] D102492: [clang][AST] Add support for BindingDecl to ASTImporter.

2021-05-17 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:873
+  MatchVerifier Verifier;
+  testImport("int a[2] = {1, 2};"
+ "auto [declToImport, x] = a;",

Can we add a larger variety of tests? Given how simple the `BindingDecl` case 
seems to be I don't expect any surprises but it would be good to verify that 
cases like mixed types, references and bit-fields work as expected. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102492

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


[PATCH] D102556: [HIP] Fix spack detection

2021-05-17 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rG18cb17ce4cd5: [HIP] Fix spack detection (authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D102556?vs=345643&id=345925#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102556

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/ROCm.h
  clang/test/Driver/rocm-detect.hip


Index: clang/test/Driver/rocm-detect.hip
===
--- clang/test/Driver/rocm-detect.hip
+++ clang/test/Driver/rocm-detect.hip
@@ -61,12 +61,15 @@
 // RUN:%s 2>&1 | FileCheck -check-prefixes=SPACK-SET %s
 
 // Test invalid SPACK ROCm installation missing hip and rocm-device-libs 
packages.
+// The message about SPACK is emitted only if -v is specified.
 
 // RUN: rm -rf %T/rocm-spack/hip-*
 // RUN: rm -rf %T/rocm-spack/rocm-device-libs-*
 // RUN: 
%T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### 
-v \
 // RUN:   -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=SPACK-MISS %s
+// RUN: 
%T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang 
--version 2>&1 \
+// RUN:   | FileCheck -check-prefixes=SPACK-MISS-SILENT %s
 
 // GFX902-DEFAULTLIBS: error: cannot find ROCm device library for gfx902. 
Provide its path via --rocm-path or --rocm-device-lib-path, or pass -nogpulib 
to build without ROCm device library
 
@@ -90,8 +93,8 @@
 // SPACK-SAME: "-internal-isystem" 
"[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
 
 // SPACK-MULT: InstalledDir: 
[[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
-// SPACK-MULT-DAG: Expecting one SPACK package hip-4.0.0 at [[DIR]] but found 
more
-// SPACK-MULT-DAG: Expecting one SPACK package rocm-device-libs-4.0.0 at 
[[DIR]] but found more
+// SPACK-MULT-DAG: Cannot use SPACK package hip-4.0.0 at [[DIR]] due to 
multiple installations for the same version
+// SPACK-MULT-DAG: Cannot use SPACK package rocm-device-libs-4.0.0 at [[DIR]] 
due to multiple installations for the same version
 // SPACK-MULT-NOT: Found HIP installation: 
[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
 // SPACK-MULT-NOT: "-mlink-builtin-bitcode" 
"[[DIR]]/rocm-device-libs-4.0.0-6wnyzz4hgl3hr7uswasnagt7j2adctbs/amdgcn/bitcode/hip.bc"
 // SPACK-MULT-NOT: "-internal-isystem" 
"[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
@@ -103,8 +106,12 @@
 // SPACK-SET-SAME: "-internal-isystem" "[[DIR]]/hip-4.0.0-abcd/include"
 
 // SPACK-MISS: InstalledDir: 
[[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
-// SPACK-MISS-DAG: Expecting SPACK package hip-4.0.0 at [[DIR]] but not found
-// SPACK-MISS-DAG: Expecting SPACK package rocm-device-libs-4.0.0 at [[DIR]] 
but not found
+// SPACK-MISS-DAG: SPACK package hip-4.0.0 not found at [[DIR]]
+// SPACK-MISS-DAG: SPACK package rocm-device-libs-4.0.0 not found at [[DIR]]
 // SPACK-MISS-NOT: Found HIP installation: 
[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
 // SPACK-MISS-NOT: "-mlink-builtin-bitcode" 
"[[DIR]]/rocm-device-libs-4.0.0-6wnyzz4hgl3hr7uswasnagt7j2adctbs/amdgcn/bitcode/hip.bc"
 // SPACK-MISS-NOT: "-internal-isystem" 
"[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
+
+// SPACK-MISS-SILENT-NOT: SPACK package hip-{{.*}} not found at
+// SPACK-MISS-SILENT-NOT: SPACK package rocm-device-libs-{{.*}} not found at
+// SPACK-MISS-SILENT-NOT: Found HIP installation
Index: clang/lib/Driver/ToolChains/ROCm.h
===
--- clang/lib/Driver/ToolChains/ROCm.h
+++ clang/lib/Driver/ToolChains/ROCm.h
@@ -110,6 +110,7 @@
   // Cache ROCm installation search paths.
   SmallVector ROCmSearchDirs;
   bool PrintROCmSearchDirs;
+  bool Verbose;
 
   bool allGenericLibsValid() const {
 return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() && !HIP.empty() &&
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -58,19 +58,16 @@
 llvm::sys::path::append(PackagePath, SubDirs[0]);
 return PackagePath;
   }
-  if (SubDirs.size() == 0) {
-unsigned DiagID = D.getDiags().getCustomDiagID(
-DiagnosticsEngine::Error,
-"Expecting SPACK package %0 at %1 but not found");
-D.Diag(DiagID) << Prefix << Cand.Path;
+  if (SubDirs.size() == 0 && Verbose) {
+llvm::errs() << "SPACK package " << Prefix << " not found at " << Cand.Path
+ << '\n';
 return {};
   }
 
-  assert(SubDirs.size() > 1);
-  unsigned DiagID = D.getDiags().getCustomDiagID(
-  DiagnosticsEngine::Error,
-  "Ex

[clang] 18cb17c - [HIP] Fix spack detection

2021-05-17 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-05-17T13:24:05-04:00
New Revision: 18cb17ce4cd54b9971550840b6f0b872de0d4c8c

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

LOG: [HIP] Fix spack detection

Missing or duplicate spack package should not cause error, since
users may only installed llvm/clang package, or users may installed
duplicate HIP package but will use environment variable or compiler
option to choose HIP path.

The message about missing or duplicate spack package is informational,
therefore should be emitted only when -v is specified.

Reviewed by: Artem Belevich

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/ROCm.h
clang/test/Driver/rocm-detect.hip

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 4da1239dce84..639f3598a1d9 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -58,19 +58,16 @@ RocmInstallationDetector::findSPACKPackage(const Candidate 
&Cand,
 llvm::sys::path::append(PackagePath, SubDirs[0]);
 return PackagePath;
   }
-  if (SubDirs.size() == 0) {
-unsigned DiagID = D.getDiags().getCustomDiagID(
-DiagnosticsEngine::Error,
-"Expecting SPACK package %0 at %1 but not found");
-D.Diag(DiagID) << Prefix << Cand.Path;
+  if (SubDirs.size() == 0 && Verbose) {
+llvm::errs() << "SPACK package " << Prefix << " not found at " << Cand.Path
+ << '\n';
 return {};
   }
 
-  assert(SubDirs.size() > 1);
-  unsigned DiagID = D.getDiags().getCustomDiagID(
-  DiagnosticsEngine::Error,
-  "Expecting one SPACK package %0 at %1 but found more");
-  D.Diag(DiagID) << Prefix << Cand.Path;
+  if (SubDirs.size() > 1 && Verbose) {
+llvm::errs() << "Cannot use SPACK package " << Prefix << " at " << 
Cand.Path
+ << " due to multiple installations for the same version\n";
+  }
   return {};
 }
 
@@ -305,6 +302,7 @@ RocmInstallationDetector::RocmInstallationDetector(
 const Driver &D, const llvm::Triple &HostTriple,
 const llvm::opt::ArgList &Args, bool DetectHIPRuntime, bool 
DetectDeviceLib)
 : D(D) {
+  Verbose = Args.hasArg(options::OPT_v);
   RocmPathArg = Args.getLastArgValue(clang::driver::options::OPT_rocm_path_EQ);
   PrintROCmSearchDirs =
   Args.hasArg(clang::driver::options::OPT_print_rocm_search_dirs);

diff  --git a/clang/lib/Driver/ToolChains/ROCm.h 
b/clang/lib/Driver/ToolChains/ROCm.h
index 35fb24a225e4..bb482be68260 100644
--- a/clang/lib/Driver/ToolChains/ROCm.h
+++ b/clang/lib/Driver/ToolChains/ROCm.h
@@ -110,6 +110,7 @@ class RocmInstallationDetector {
   // Cache ROCm installation search paths.
   SmallVector ROCmSearchDirs;
   bool PrintROCmSearchDirs;
+  bool Verbose;
 
   bool allGenericLibsValid() const {
 return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() && !HIP.empty() &&

diff  --git a/clang/test/Driver/rocm-detect.hip 
b/clang/test/Driver/rocm-detect.hip
index 68ae1edb4eb2..f1fa1fc636dc 100644
--- a/clang/test/Driver/rocm-detect.hip
+++ b/clang/test/Driver/rocm-detect.hip
@@ -61,12 +61,15 @@
 // RUN:%s 2>&1 | FileCheck -check-prefixes=SPACK-SET %s
 
 // Test invalid SPACK ROCm installation missing hip and rocm-device-libs 
packages.
+// The message about SPACK is emitted only if -v is specified.
 
 // RUN: rm -rf %T/rocm-spack/hip-*
 // RUN: rm -rf %T/rocm-spack/rocm-device-libs-*
 // RUN: 
%T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### 
-v \
 // RUN:   -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=SPACK-MISS %s
+// RUN: 
%T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang 
--version 2>&1 \
+// RUN:   | FileCheck -check-prefixes=SPACK-MISS-SILENT %s
 
 // GFX902-DEFAULTLIBS: error: cannot find ROCm device library for gfx902. 
Provide its path via --rocm-path or --rocm-device-lib-path, or pass -nogpulib 
to build without ROCm device library
 
@@ -90,8 +93,8 @@
 // SPACK-SAME: "-internal-isystem" 
"[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
 
 // SPACK-MULT: InstalledDir: 
[[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
-// SPACK-MULT-DAG: Expecting one SPACK package hip-4.0.0 at [[DIR]] but found 
more
-// SPACK-MULT-DAG: Expecting one SPACK package rocm-device-libs-4.0.0 at 
[[DIR]] but found more
+// SPACK-MULT-DAG: Cannot use SPACK package hip-4.0.0 at [[DIR]] due to 
multiple installations for the same version
+// SPACK-MULT-DAG: Cannot use SPACK package rocm-device-libs-4.0.0 at [[DIR]] 
due to multiple installations for the same version
 // SPACK-MULT-NOT: Found HIP installation: 
[

[PATCH] D101561: [Prototype] Introduce attribute for ignoring C++ ABI

2021-05-17 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks abandoned this revision.
aeubanks added a comment.

turns out this didn't have a good enough impact to pursue


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101561

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


[PATCH] D102488: [clang][deps] Prune unused header search paths

2021-05-17 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 345922.
jansvoboda11 added a comment.

Make PCM parsing lazier


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102488

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/Inputs/header-search-pruning/a/a.h
  clang/test/ClangScanDeps/Inputs/header-search-pruning/b/b.h
  clang/test/ClangScanDeps/Inputs/header-search-pruning/cdb.json
  clang/test/ClangScanDeps/Inputs/header-search-pruning/mod.h
  clang/test/ClangScanDeps/Inputs/header-search-pruning/module.modulemap
  clang/test/ClangScanDeps/header-search-pruning.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -163,6 +163,11 @@
 "'-fmodule-file=', '-o', '-fmodule-map-file='."),
 llvm::cl::init(false), llvm::cl::cat(DependencyScannerCategory));
 
+static llvm::cl::opt OptimizeArgs(
+"optimize-args",
+llvm::cl::desc("Whether to optimize command-line arguments of modules."),
+llvm::cl::init(false), llvm::cl::cat(DependencyScannerCategory));
+
 llvm::cl::opt
 NumThreads("j", llvm::cl::Optional,
llvm::cl::desc("Number of worker threads to use (default: use "
@@ -357,7 +362,26 @@
 
 private:
   StringRef lookupPCMPath(ModuleID MID) {
-return Modules[IndexedModuleID{MID, 0}].ImplicitModulePCMPath;
+auto PCMPath = PCMPaths.insert({IndexedModuleID{MID, 0}, ""});
+if (PCMPath.second)
+  PCMPath.first->second = constructPCMPath(lookupModuleDeps(MID));
+return PCMPath.first->second;
+  }
+
+  /// Construct a path where to put the explicitly built PCM - essentially the
+  /// path to implicitly built PCM with the context hash replaced by the final
+  /// (potentially modified) context hash.
+  std::string constructPCMPath(const ModuleDeps &MD) const {
+const std::string &ImplicitPCMPath = MD.ImplicitModulePCMPath;
+StringRef Filename = llvm::sys::path::filename(ImplicitPCMPath);
+StringRef ImplicitContextHashPath =
+llvm::sys::path::parent_path(ImplicitPCMPath);
+StringRef ModuleCachePath =
+llvm::sys::path::parent_path(ImplicitContextHashPath);
+
+SmallString<64> ExplicitPCMPath = ModuleCachePath;
+llvm::sys::path::append(ExplicitPCMPath, MD.ID.ContextHash, Filename);
+return std::string(ExplicitPCMPath);
   }
 
   const ModuleDeps &lookupModuleDeps(ModuleID MID) {
@@ -395,6 +419,8 @@
   std::mutex Lock;
   std::unordered_map
   Modules;
+  std::unordered_map
+  PCMPaths;
   std::vector Inputs;
 };
 
@@ -554,7 +580,7 @@
   SharedStream DependencyOS(llvm::outs());
 
   DependencyScanningService Service(ScanMode, Format, ReuseFileManager,
-SkipExcludedPPRanges);
+SkipExcludedPPRanges, OptimizeArgs);
   llvm::ThreadPool Pool(llvm::hardware_concurrency(NumThreads));
   std::vector> WorkerTools;
   for (unsigned I = 0; I < Pool.getThreadCount(); ++I)
Index: clang/test/ClangScanDeps/header-search-pruning.cpp
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-pruning.cpp
@@ -0,0 +1,87 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: cp -r %S/Inputs/header-search-pruning/* %t
+// RUN: cp %S/header-search-pruning.cpp %t/header-search-pruning.cpp
+// RUN: sed -e "s|DIR|%t|g" -e "s|DEFINES|-DINCLUDE_A|g" %S/Inputs/header-search-pruning/cdb.json > %t/cdb_a.json
+// RUN: sed -e "s|DIR|%t|g" -e "s|DEFINES|-DINCLUDE_B|g" %S/Inputs/header-search-pruning/cdb.json > %t/cdb_b.json
+// RUN: sed -e "s|DIR|%t|g" -e "s|DEFINES|-DINCLUDE_A -DINCLUDE_B|g" %S/Inputs/header-search-pruning/cdb.json > %t/cdb_ab.json
+//
+// RUN: clang-scan-deps -compilation-database %t/cdb_a.json -format experimental-full -optimize-args >> %t/result_a.json
+// RUN: cat %t/result_a.json | sed 's/\\/\//g' | FileCheck --check-prefixes=CHECK_A %s
+//
+// RUN: clang-scan-deps -compilation-database %t/cdb_b.json -format experimental-full -optimize-args >> %t/result_b.json
+// RUN: cat %t/result_b.json | sed 's/\\/\//g' | FileCheck --

[PATCH] D102638: [NFC] Pass GV value type instead of pointer type to GetOrCreateLLVMGlobal

2021-05-17 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks created this revision.
aeubanks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For opaque pointers, to avoid PointerType::getElementType().


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102638

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h

Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,11 +1477,10 @@
   const FunctionDecl *FD);
   void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD);
 
-  llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
-llvm::PointerType *PTy,
-const VarDecl *D,
-ForDefinition_t IsForDefinition
-  = NotForDefinition);
+  llvm::Constant *
+  GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
+unsigned AddrSpace, const VarDecl *D,
+ForDefinition_t IsForDefinition = NotForDefinition);
 
   bool GetCPUAndFeaturesAttributes(GlobalDecl GD,
llvm::AttrBuilder &AttrBuilder);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2808,9 +2808,7 @@
   GlobalDecl(cast(VD)),
   /*ForVTable=*/false);
   else
-Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
-llvm::PointerType::getUnqual(DeclTy),
-nullptr);
+Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), DeclTy, 0, nullptr);
 
   auto *F = cast(Aliasee);
   F->setLinkage(llvm::Function::ExternalWeakLinkage);
@@ -3772,9 +3770,9 @@
 }
 
 /// GetOrCreateLLVMGlobal - If the specified mangled name is not in the module,
-/// create and return an llvm GlobalVariable with the specified type.  If there
-/// is something in the module with the specified name, return it potentially
-/// bitcasted to the right type.
+/// create and return an llvm GlobalVariable with the specified type and address
+/// space. If there is something in the module with the specified name, return
+/// it potentially bitcasted to the right type.
 ///
 /// If D is non-null, it specifies a decl that correspond to this.  This is used
 /// to set the attributes on the global when it is first created.
@@ -3783,9 +3781,8 @@
 /// type Ty will be returned, not conversion of a variable with the same
 /// mangled name but some other type.
 llvm::Constant *
-CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
- llvm::PointerType *Ty,
- const VarDecl *D,
+CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
+ unsigned AddrSpace, const VarDecl *D,
  ForDefinition_t IsForDefinition) {
   // Lookup the entry, lazily creating it if necessary.
   llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
@@ -3802,7 +3799,7 @@
 if (LangOpts.OpenMP && !LangOpts.OpenMPSimd && D)
   getOpenMPRuntime().registerTargetGlobalVariable(D, Entry);
 
-if (Entry->getType() == Ty)
+if (Entry->getValueType() == Ty && Entry->getAddressSpace() == AddrSpace)
   return Entry;
 
 // If there are two attempts to define the same mangled name, issue an
@@ -3826,22 +3823,24 @@
 }
 
 // Make sure the result is of the correct type.
-if (Entry->getType()->getAddressSpace() != Ty->getAddressSpace())
-  return llvm::ConstantExpr::getAddrSpaceCast(Entry, Ty);
+if (Entry->getType()->getAddressSpace() != AddrSpace) {
+  return llvm::ConstantExpr::getAddrSpaceCast(Entry,
+  Ty->getPointerTo(AddrSpace));
+}
 
 // (If global is requested for a definition, we always need to create a new
 // global, not just return a bitcast.)
 if (!IsForDefinition)
-  return llvm::ConstantExpr::getBitCast(Entry, Ty);
+  return llvm::ConstantExpr::getBitCast(Entry, Ty->getPointerTo(AddrSpace));
   }
 
-  auto AddrSpace = GetGlobalVarAddressSpace(D);
-  auto TargetAddrSpace = getContext().getTargetAddressSpace(AddrSpace);
+  auto DAddrSpace = GetGlobalVarAddressSpace(D);
+  auto TargetAddrSpace = getContext().getTargetAddressSpace(DAddrSpace);
 
   auto *GV = new llvm::GlobalVariable(
-  getModule(), Ty->getElementType(), false,
-  llvm::GlobalValue::ExternalLinkage, nullptr, MangledName, nullptr,
-  llvm::GlobalVariable::NotThreadLocal, TargetAdd

[PATCH] D100768: [Clang][OpenMP] Remove the mandatory flush for capture for OpenMP 5.1

2021-05-17 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 345917.
tianshilei1992 added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100768

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/atomic_capture_codegen.cpp

Index: clang/test/OpenMP/atomic_capture_codegen.cpp
===
--- clang/test/OpenMP/atomic_capture_codegen.cpp
+++ clang/test/OpenMP/atomic_capture_codegen.cpp
@@ -1,11 +1,19 @@
 
 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -target-cpu core2 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-50 %s
 
 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 -fopenmp-simd -x c -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -x c -triple x86_64-apple-darwin10 -target-cpu core2 -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp-simd -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 -fopenmp -fopenmp-version=51 -x c -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c -triple x86_64-apple-darwin10 -target-cpu core2 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -target-cpu core2 -fopenmp-simd -fopenmp-version=51 -x c -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c -triple x86_64-apple-darwin10 -target-cpu core2 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c -triple x86_64-apple-darwin10 -target-cpu core2 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
 #ifndef HEADER
@@ -343,7 +351,7 @@
 // CHECK: [[IM_CAST:%.+]] = fptrunc double [[NEW_IM]] to float
 // CHECK: store float [[RE_CAST]], float* getelementptr inbounds ({ float, float }, { float, float }* @{{.+}}, i32 0, i32 0),
 // CHECK: store float [[IM_CAST]], float* getelementptr inbounds ({ float, float }, { float, float }* @{{.+}}, i32 0, i32 1),
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic capture seq_cst
   {cdx = cdx - cdv; cfv = cdx;}
 // CHECK: [[BV:%.+]] = load i8, i8* @{{.+}}
@@ -393,7 +401,7 @@
 // CHECK: br i1 [[SUCCESS_FAIL]], label %[[EXIT:.+]], label %[[CONT]]
 // CHECK: [[EXIT]]
 // CHECK: store i8 [[NEW]], i8* @{{.+}},
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic capture, seq_cst
   {cx = cx >> ucv; cv = cx;}
 // CHECK: [[SV:%.+]]  = load i16, i16* @{{.+}},
@@ -436,7 +444,7 @@
 // CHECK: [[OLD:%.+]] = atomicrmw or i32* @{{.+}}, i32 [[EXPR]] seq_cst, align 4
 // CHECK: [[DESIRED:%.+]] = or i32 [[EXPR]], [[OLD]]
 // CHECK: store i32 [[DESIRED]], i32* @{{.+}},
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic seq_cst, capture
   {uix = iv | uix; uiv = uix;}
 // CHECK: [[EXPR:%.+]] = load i32, i32* @{{.+}}
@@ -904,7 +912,7 @@
 // CHECK: [[EXIT]]
 // CHECK: [[NEW_VAL:%.+]] = trunc i64 [[CONV]] to i32
 // CHECK: store i32 [[NEW_VAL]], i32* @{{.+}},
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic capture release
   {bfx4.b /= ldv; iv = bfx4.b;}
 // CHECK: [[EXPR:%.+]] = load x86_fp80, x86_fp80* @{{.+}}
@@ -937,7 +945,7 @@
 // CHECK: [[EXIT]]
 // CHECK: [[NEW_VAL_I32:%.+]] = trunc i64 [[NEW_VAL]] to i32
 // CHECK: store i32 [[NEW_VAL_I32]], i32* @{{.+}},
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic capture acquire
   iv = bfx4_packed.b += ldv;
 // CHECK: load i64, i64*
@@ -963,7 +971,7 @@
 // CHECK: br i1 [[FAIL_SUCCESS]], label %[[EXIT:.+]], label %[[CONT]]
 // CHECK: [[EXIT]]
 // CHECK: store float [[X]], float* @{{.+}},
-// CHECK: call{{.*}} @__kmpc_flush(
+// CHECK-50: call{{.*}} @__kmpc_flush(
 #pragma omp atomic capture acq_rel
   {fv = float2x.x; float2x.x = ulv - float2x.x;}
 // CHECK: [[EXPR:%.+]] = load double, double* @{{.+}},
@@ -973,7 +981,7 @@
 // CHECK: [[NEW_VAL:%.+]] = fptosi double [[DIV]] to i32
 // CHECK: call void @llvm.write_register.i32([[R

[PATCH] D100124: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX redux.sync instructions

2021-05-17 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf226e28a880f: [Clang][NVPTX] Add NVPTX intrinsics and 
builtins for CUDA PTX redux.sync… (authored by steffenlarsen, committed by tra).

Changed prior to commit:
  https://reviews.llvm.org/D100124?vs=339169&id=345915#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100124

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/test/CodeGenCUDA/redux-builtins.cu
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/redux-sync.ll

Index: llvm/test/CodeGen/NVPTX/redux-sync.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/redux-sync.ll
@@ -0,0 +1,65 @@
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_80 -mattr=+ptx70 | FileCheck %s
+
+declare i32 @llvm.nvvm.redux.sync.umin(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_min_u32
+define i32 @redux_sync_min_u32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.min.u32
+  %val = call i32 @llvm.nvvm.redux.sync.umin(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.umax(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_max_u32
+define i32 @redux_sync_max_u32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.max.u32
+  %val = call i32 @llvm.nvvm.redux.sync.umax(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.add(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_add_s32
+define i32 @redux_sync_add_s32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.add.s32
+  %val = call i32 @llvm.nvvm.redux.sync.add(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.min(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_min_s32
+define i32 @redux_sync_min_s32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.min.s32
+  %val = call i32 @llvm.nvvm.redux.sync.min(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.max(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_max_s32
+define i32 @redux_sync_max_s32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.max.s32
+  %val = call i32 @llvm.nvvm.redux.sync.max(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.and(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_and_b32
+define i32 @redux_sync_and_b32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.and.b32
+  %val = call i32 @llvm.nvvm.redux.sync.and(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.xor(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_xor_b32
+define i32 @redux_sync_xor_b32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.xor.b32
+  %val = call i32 @llvm.nvvm.redux.sync.xor(i32 %src, i32 %mask)
+  ret i32 %val
+}
+
+declare i32 @llvm.nvvm.redux.sync.or(i32, i32)
+; CHECK-LABEL: .func{{.*}}redux_sync_or_b32
+define i32 @redux_sync_or_b32(i32 %src, i32 %mask) {
+  ; CHECK: redux.sync.or.b32
+  %val = call i32 @llvm.nvvm.redux.sync.or(i32 %src, i32 %mask)
+  ret i32 %val
+}
Index: llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
===
--- llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
+++ llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
@@ -274,6 +274,22 @@
 defm MATCH_ALLP_SYNC_64 : MATCH_ALLP_SYNC;
 
+multiclass REDUX_SYNC {
+  def : NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src, Int32Regs:$mask),
+  "redux.sync." # BinOp # "." # PTXType # " $dst, $src, $mask;",
+  [(set Int32Regs:$dst, (Intrin Int32Regs:$src, Int32Regs:$mask))]>,
+Requires<[hasPTX70, hasSM80]>;
+}
+
+defm REDUX_SYNC_UMIN : REDUX_SYNC<"min", "u32", int_nvvm_redux_sync_umin>;
+defm REDUX_SYNC_UMAX : REDUX_SYNC<"max", "u32", int_nvvm_redux_sync_umax>;
+defm REDUX_SYNC_ADD : REDUX_SYNC<"add", "s32", int_nvvm_redux_sync_add>;
+defm REDUX_SYNC_MIN : REDUX_SYNC<"min", "s32", int_nvvm_redux_sync_min>;
+defm REDUX_SYNC_MAX : REDUX_SYNC<"max", "s32", int_nvvm_redux_sync_max>;
+defm REDUX_SYNC_AND : REDUX_SYNC<"and", "b32", int_nvvm_redux_sync_and>;
+defm REDUX_SYNC_XOR : REDUX_SYNC<"xor", "b32", int_nvvm_redux_sync_xor>;
+defm REDUX_SYNC_OR : REDUX_SYNC<"or", "b32", int_nvvm_redux_sync_or>;
+
 } // isConvergent = true
 
 //---
Index: llvm/include/llvm/IR/IntrinsicsNVVM.td
===
--- llvm/include/llvm/IR/IntrinsicsNVVM.td
+++ llvm/include/llvm/IR/IntrinsicsNVVM.td
@@ -4204,6 +4204,49 @@
   Intrinsic<[llvm_i64_ty, llvm_i1_ty], [llvm_i32_ty, llvm_i64_ty],
 [IntrInaccessibleMemOnly, IntrConvergent], "llvm.nvvm.match.all.sync.i64p">;
 
+//
+// REDUX.SYNC
+//
+// redux.sync.min.u32 dst, src, membermask;
+def int_nvvm_redux_sync_umin : GCCBuiltin<"__nvvm_redux_sync_umin">,
+  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
+[IntrConvergent, IntrInaccessibleMemOnly]>;
+
+// redux.sync.max.u32 dst, src, membermask;
+d

[PATCH] D100394: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX cp.async instructions

2021-05-17 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG02c2468864bb: [Clang][NVPTX] Add NVPTX intrinsics and 
builtins for CUDA PTX cp.async… (authored by nyalloc, committed by tra).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100394

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/test/CodeGen/builtins-nvptx.c
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  llvm/test/CodeGen/NVPTX/async-copy.ll
  llvm/test/CodeGen/NVPTX/mbarrier.ll

Index: llvm/test/CodeGen/NVPTX/mbarrier.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/mbarrier.ll
@@ -0,0 +1,145 @@
+; RUN: llc < %s -march=nvptx -mcpu=sm_80 | FileCheck %s -check-prefix=CHECK_PTX32
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_80 | FileCheck %s -check-prefix=CHECK_PTX64
+
+declare void @llvm.nvvm.mbarrier.init(i64* %a, i32 %b)
+declare void @llvm.nvvm.mbarrier.init.shared(i64 addrspace(3)* %a, i32 %b)
+
+; CHECK-LABEL: barrierinit
+define void @barrierinit(i64* %a, i32 %b) {
+; CHECK_PTX32: mbarrier.init.b64 [%r{{[0-9]+}}], %r{{[0-9]+}};
+; CHECK_PTX64: mbarrier.init.b64 [%rd{{[0-9]+}}], %r{{[0-9]+}};
+  tail call void @llvm.nvvm.mbarrier.init(i64* %a, i32 %b)
+  ret void
+}
+
+; CHECK-LABEL: barrierinitshared
+define void @barrierinitshared(i64 addrspace(3)* %a, i32 %b) {
+; CHECK_PTX32: mbarrier.init.shared.b64 [%r{{[0-9]+}}], %r{{[0-9]+}};
+; CHECK_PTX64: mbarrier.init.shared.b64 [%rd{{[0-9]+}}], %r{{[0-9]+}};
+  tail call void @llvm.nvvm.mbarrier.init.shared(i64 addrspace(3)* %a, i32 %b)
+  ret void
+}
+
+declare void @llvm.nvvm.mbarrier.inval(i64* %a)
+declare void @llvm.nvvm.mbarrier.inval.shared(i64 addrspace(3)* %a)
+
+; CHECK-LABEL: barrierinval
+define void @barrierinval(i64* %a) {
+; CHECK_PTX32: mbarrier.inval.b64 [%r{{[0-1]+}}];
+; CHECK_PTX64: mbarrier.inval.b64 [%rd{{[0-1]+}}];
+  tail call void @llvm.nvvm.mbarrier.inval(i64* %a)
+  ret void
+}
+
+; CHECK-LABEL: barrierinvalshared
+define void @barrierinvalshared(i64 addrspace(3)* %a) {
+; CHECK_PTX32: mbarrier.inval.shared.b64 [%r{{[0-1]+}}];
+; CHECK_PTX64: mbarrier.inval.shared.b64 [%rd{{[0-1]+}}];
+  tail call void @llvm.nvvm.mbarrier.inval.shared(i64 addrspace(3)* %a)
+  ret void
+}
+
+declare i64 @llvm.nvvm.mbarrier.arrive(i64* %a)
+declare i64 @llvm.nvvm.mbarrier.arrive.shared(i64 addrspace(3)* %a)
+
+; CHECK-LABEL: barrierarrive
+define void @barrierarrive(i64* %a) {
+; CHECK_PTX32: mbarrier.arrive.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}];
+; CHECK_PTX64: mbarrier.arrive.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}];
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive(i64* %a)
+  ret void
+}
+
+; CHECK-LABEL: barrierarriveshared
+define void @barrierarriveshared(i64 addrspace(3)* %a) {
+; CHECK_PTX32: mbarrier.arrive.shared.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}];
+; CHECK_PTX64: mbarrier.arrive.shared.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}];
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive.shared(i64 addrspace(3)* %a)
+  ret void
+}
+
+declare i64 @llvm.nvvm.mbarrier.arrive.noComplete(i64* %a, i32 %b)
+declare i64 @llvm.nvvm.mbarrier.arrive.noComplete.shared(i64 addrspace(3)* %a, i32 %b)
+
+; CHECK-LABEL: barrierarrivenoComplete
+define void @barrierarrivenoComplete(i64* %a, i32 %b) {
+; CHECK_PTX32: mbarrier.arrive.noComplete.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}], %r{{[0-9]+}};
+; CHECK_PTX64: mbarrier.arrive.noComplete.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}], %r{{[0-9]+}};
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive.noComplete(i64* %a, i32 %b)
+  ret void
+}
+
+; CHECK-LABEL: barrierarrivenoCompleteshared
+define void @barrierarrivenoCompleteshared(i64 addrspace(3)* %a, i32 %b) {
+; CHECK_PTX32: mbarrier.arrive.noComplete.shared.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}], %r{{[0-9]+}};
+; CHECK_PTX64: mbarrier.arrive.noComplete.shared.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}], %r{{[0-9]+}};
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive.noComplete.shared(i64 addrspace(3)* %a, i32 %b)
+  ret void
+}
+
+declare i64 @llvm.nvvm.mbarrier.arrive.drop(i64* %a)
+declare i64 @llvm.nvvm.mbarrier.arrive.drop.shared(i64 addrspace(3)* %a)
+
+; CHECK-LABEL: barrierarrivedrop
+define void @barrierarrivedrop(i64* %a) {
+; CHECK_PTX32: mbarrier.arrive_drop.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}];
+; CHECK_PTX64: mbarrier.arrive_drop.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}];
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive.drop(i64* %a)
+  ret void
+}
+
+; CHECK-LABEL: barrierarrivedropshared
+define void @barrierarrivedropshared(i64 addrspace(3)* %a) {
+; CHECK_PTX32: mbarrier.arrive_drop.shared.b64 %rd{{[0-9]+}}, [%r{{[0-9]+}}];
+; CHECK_PTX64: mbarrier.arrive_drop.shared.b64 %rd{{[0-9]+}}, [%rd{{[0-9]+}}];
+  %ret = tail call i64 @llvm.nvvm.mbarrier.arrive.drop.shared(i64 addrspace(3)* %a)
+  ret void
+}
+
+declare i64 @llvm.nvvm.mba

[clang] f226e28 - [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX redux.sync instructions

2021-05-17 Thread Artem Belevich via cfe-commits

Author: Steffen Larsen
Date: 2021-05-17T09:46:59-07:00
New Revision: f226e28a880f8e40b1bfd4c77b9768a667372d22

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

LOG: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX redux.sync 
instructions

Adds NVPTX builtins and intrinsics for the CUDA PTX `redux.sync` instructions
for `sm_80` architecture or newer.

PTX ISA description of `redux.sync`:
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-redux-sync

Authored-by: Steffen Larsen 

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

Added: 
clang/test/CodeGenCUDA/redux-builtins.cu
llvm/test/CodeGen/NVPTX/redux-sync.ll

Modified: 
clang/include/clang/Basic/BuiltinsNVPTX.def
llvm/include/llvm/IR/IntrinsicsNVVM.td
llvm/lib/Target/NVPTX/NVPTXIntrinsics.td

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 3feea854df819..98f3c659b7cec 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -456,6 +456,16 @@ TARGET_BUILTIN(__nvvm_match_any_sync_i64, "WiUiWi", "", 
PTX60)
 TARGET_BUILTIN(__nvvm_match_all_sync_i32p, "UiUiUii*", "", PTX60)
 TARGET_BUILTIN(__nvvm_match_all_sync_i64p, "WiUiWii*", "", PTX60)
 
+// Redux
+TARGET_BUILTIN(__nvvm_redux_sync_add, "iii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_min, "iii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_max, "iii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_umin, "UiUii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_umax, "UiUii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_and, "iii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_xor, "iii", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_redux_sync_or, "iii", "", AND(SM_80,PTX70))
+
 // Membar
 
 BUILTIN(__nvvm_membar_cta, "v", "")

diff  --git a/clang/test/CodeGenCUDA/redux-builtins.cu 
b/clang/test/CodeGenCUDA/redux-builtins.cu
new file mode 100644
index 0..bdcd00b567f70
--- /dev/null
+++ b/clang/test/CodeGenCUDA/redux-builtins.cu
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 "-triple" "nvptx-nvidia-cuda" "-target-feature" "+ptx70" 
"-target-cpu" "sm_80" -emit-llvm -fcuda-is-device -o - %s | FileCheck %s
+// RUN: %clang_cc1 "-triple" "nvptx64-nvidia-cuda" "-target-feature" "+ptx70" 
"-target-cpu" "sm_80" -emit-llvm -fcuda-is-device -o - %s | FileCheck %s
+
+// CHECK: define{{.*}} void @_Z6kernelPi(i32* %out)
+__attribute__((global)) void kernel(int *out) {
+  int a = 1;
+  unsigned int b = 5;
+  int i = 0;
+
+  out[i++] = __nvvm_redux_sync_add(a, 0xFF);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.add
+
+  out[i++] = __nvvm_redux_sync_add(b, 0x01);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.add
+
+  out[i++] = __nvvm_redux_sync_min(a, 0x0F);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.min
+
+  out[i++] = __nvvm_redux_sync_umin(b, 0xF0);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.umin
+
+  out[i++] = __nvvm_redux_sync_max(a, 0xF0);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.max
+
+  out[i++] = __nvvm_redux_sync_umax(b, 0x0F);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.umax
+
+  out[i++] = __nvvm_redux_sync_and(a, 0xF0);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.and
+
+  out[i++] = __nvvm_redux_sync_and(b, 0x0F);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.and
+
+  out[i++] = __nvvm_redux_sync_xor(a, 0x10);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.xor
+
+  out[i++] = __nvvm_redux_sync_xor(b, 0x01);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.xor
+
+  out[i++] = __nvvm_redux_sync_or(a, 0xFF);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.or
+
+  out[i++] = __nvvm_redux_sync_or(b, 0xFF);
+  // CHECK: call i32 @llvm.nvvm.redux.sync.or
+
+  // CHECK: ret void
+}

diff  --git a/llvm/include/llvm/IR/IntrinsicsNVVM.td 
b/llvm/include/llvm/IR/IntrinsicsNVVM.td
index fa66a4a779e19..71e31b14f4c3b 100644
--- a/llvm/include/llvm/IR/IntrinsicsNVVM.td
+++ b/llvm/include/llvm/IR/IntrinsicsNVVM.td
@@ -4204,6 +4204,49 @@ def int_nvvm_match_all_sync_i64p :
   Intrinsic<[llvm_i64_ty, llvm_i1_ty], [llvm_i32_ty, llvm_i64_ty],
 [IntrInaccessibleMemOnly, IntrConvergent], 
"llvm.nvvm.match.all.sync.i64p">;
 
+//
+// REDUX.SYNC
+//
+// redux.sync.min.u32 dst, src, membermask;
+def int_nvvm_redux_sync_umin : GCCBuiltin<"__nvvm_redux_sync_umin">,
+  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
+[IntrConvergent, IntrInaccessibleMemOnly]>;
+
+// redux.sync.max.u32 dst, src, membermask;
+def int_nvvm_redux_sync_umax : GCCBuiltin<"__nvvm_redux_sync_umax">,
+  Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
+[IntrConvergent, IntrInaccessibleMemOnly]>;
+
+// redux.

[clang] 02c2468 - [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX cp.async instructions

2021-05-17 Thread Artem Belevich via cfe-commits

Author: Stuart Adams
Date: 2021-05-17T09:46:59-07:00
New Revision: 02c2468864bbb37f7b279aff84961815c1500b6c

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

LOG: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX cp.async 
instructions

Adds NVPTX builtins and intrinsics for the CUDA PTX `cp.async` instructions for
`sm_80` architecture or newer.

PTX ISA description of `cp.async`:
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-asynchronous-copy
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-cp-async-mbarrier-arrive

Authored-by: Stuart Adams 
Co-Authored-by: Alexander Johnston 

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

Added: 
llvm/test/CodeGen/NVPTX/async-copy.ll
llvm/test/CodeGen/NVPTX/mbarrier.ll

Modified: 
clang/include/clang/Basic/BuiltinsNVPTX.def
clang/test/CodeGen/builtins-nvptx.c
llvm/include/llvm/IR/IntrinsicsNVVM.td
llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
llvm/lib/Target/NVPTX/NVPTXIntrinsics.td

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index b225ddcfa3fa0..3feea854df819 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -462,6 +462,29 @@ BUILTIN(__nvvm_membar_cta, "v", "")
 BUILTIN(__nvvm_membar_gl, "v", "")
 BUILTIN(__nvvm_membar_sys, "v", "")
 
+// mbarrier
+
+TARGET_BUILTIN(__nvvm_mbarrier_init, "vWi*i", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_init_shared, "vWi*3i", "", AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_mbarrier_inval, "vWi*", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_inval_shared, "vWi*3", "", AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_mbarrier_arrive, "WiWi*", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_shared, "WiWi*3", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_noComplete, "WiWi*i", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_noComplete_shared, "WiWi*3i", "", 
AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_drop, "WiWi*", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_drop_shared, "WiWi*3", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_drop_noComplete, "WiWi*i", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_arrive_drop_noComplete_shared, "WiWi*3i", "", 
AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_mbarrier_test_wait, "bWi*Wi", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_mbarrier_test_wait_shared, "bWi*3Wi", "", 
AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_mbarrier_pending_count, "iWi", "", AND(SM_80,PTX70))
+
 // Memcpy, Memset
 
 BUILTIN(__nvvm_memcpy, "vUc*Uc*zi","")
@@ -726,6 +749,21 @@ TARGET_BUILTIN(__imma_m8n8k32_mma_s4, "vi*iC*iC*iC*IiIi", 
"", AND(SM_75,PTX63))
 TARGET_BUILTIN(__imma_m8n8k32_mma_u4, "vi*iC*iC*iC*IiIi", "", AND(SM_75,PTX63))
 TARGET_BUILTIN(__imma_m8n8k32_st_c_i32, "vi*iC*UiIi", "", AND(SM_75,PTX63))
 
+// Async Copy
+TARGET_BUILTIN(__nvvm_cp_async_mbarrier_arrive, "vWi*", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_mbarrier_arrive_shared, "vWi*3", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_mbarrier_arrive_noinc, "vWi*", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_mbarrier_arrive_noinc_shared, "vWi*3", "", 
AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_cp_async_ca_shared_global_4, "vv*3vC*1", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_ca_shared_global_8, "vv*3vC*1", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_ca_shared_global_16, "vv*3vC*1", "", 
AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_cg_shared_global_16, "vv*3vC*1", "", 
AND(SM_80,PTX70))
+
+TARGET_BUILTIN(__nvvm_cp_async_commit_group, "v", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_wait_group, "vIi", "", AND(SM_80,PTX70))
+TARGET_BUILTIN(__nvvm_cp_async_wait_all, "v", "", AND(SM_80,PTX70))
+
 #undef BUILTIN
 #undef TARGET_BUILTIN
 #pragma pop_macro("AND")

diff  --git a/clang/test/CodeGen/builtins-nvptx.c 
b/clang/test/CodeGen/builtins-nvptx.c
index 913da5d7b73b9..ec0f74291ad47 100644
--- a/clang/test/CodeGen/builtins-nvptx.c
+++ b/clang/test/CodeGen/builtins-nvptx.c
@@ -1,4 +1,10 @@
 // REQUIRES: nvptx-registered-target
+// RUN: %clang_cc1 -ffp-contract=off -triple nvptx-unknown-unknown -target-cpu 
sm_80 -target-feature +ptx70 \
+// RUN:-fcuda-is-device -S -emit-llvm -o - -x cuda %s \
+// RUN:   | FileCheck -check-prefix=CHECK -check-prefix=CHECK_PTX70_SM80 
-check-prefix=LP32 %s
+// RUN: %clang_cc1 -ffp-contract=off -triple nvptx64-unknown-unknown 
-target-cpu sm_80 -target-feature +ptx70 \
+// RUN:-fcuda-is-device -S -emit-llvm -o - 

[PATCH] D102556: [HIP] Fix spack detection

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



Comment at: clang/test/Driver/rocm-detect.hip:115
+
+// SPACK-MISS-SILENT-NOT: SPACK package hip-4.0.0 not found at
+// SPACK-MISS-SILENT-NOT: SPACK package rocm-device-libs-4.0.0 not found at

tra wrote:
> Nit: I'd match the version with a regex. Otherwise this test would continue 
> passing even if compiler were to report `hip-some.other.version not found` 
will do


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

https://reviews.llvm.org/D102556

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


[PATCH] D102286: [HWASan] Build separate LAM runtime on x86_64.

2021-05-17 Thread Matt Morehouse 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 rG5f58322368b0: [HWASan] Build separate LAM runtime on x86_64. 
(authored by morehouse).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102286

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  compiler-rt/lib/hwasan/CMakeLists.txt
  compiler-rt/lib/hwasan/hwasan.h
  compiler-rt/lib/hwasan/hwasan_allocator.h
  compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
  compiler-rt/lib/hwasan/hwasan_linux.cpp

Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -76,7 +76,7 @@
 uptr kHighMemStart;
 uptr kHighMemEnd;
 
-uptr kAliasRegionStart;  // Always 0 on non-x86.
+uptr kAliasRegionStart;  // Always 0 when aliases aren't used.
 
 static void PrintRange(uptr start, uptr end, const char *name) {
   Printf("|| [%p, %p] || %.*s ||\n", (void *)start, (void *)end, 10, name);
@@ -125,33 +125,50 @@
   if (internal_iserror(internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0),
&local_errno) &&
   local_errno == EINVAL) {
-#if SANITIZER_ANDROID || defined(__x86_64__)
+#  if SANITIZER_ANDROID || defined(HWASAN_ALIASING_MODE)
 // Some older Android kernels have the tagged pointer ABI on
 // unconditionally, and hence don't have the tagged-addr prctl while still
 // allow the ABI.
 // If targeting Android and the prctl is not around we assume this is the
 // case.
 return;
-#else
+#  else
 if (flags()->fail_without_syscall_abi) {
   Printf(
   "FATAL: "
   "HWAddressSanitizer requires a kernel with tagged address ABI.\n");
   Die();
 }
-#endif
+#  endif
   }
 
   // Turn on the tagged address ABI.
   if ((internal_iserror(internal_prctl(PR_SET_TAGGED_ADDR_CTRL,
PR_TAGGED_ADDR_ENABLE, 0, 0, 0)) ||
-   !internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0)) &&
-  flags()->fail_without_syscall_abi) {
-Printf(
-"FATAL: HWAddressSanitizer failed to enable tagged address syscall "
-"ABI.\nSuggest check `sysctl abi.tagged_addr_disabled` "
-"configuration.\n");
-Die();
+   !internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0))) {
+#  if defined(__x86_64__) && !defined(HWASAN_ALIASING_MODE)
+// Try the new prctl API for Intel LAM.  The API is based on a currently
+// unsubmitted patch to the Linux kernel (as of May 2021) and is thus
+// subject to change.  Patch is here:
+// https://lore.kernel.org/linux-mm/20210205151631.43511-12-kirill.shute...@linux.intel.com/
+int tag_bits = kTagBits;
+int tag_shift = kAddressTagShift;
+if (!internal_iserror(
+internal_prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE,
+   reinterpret_cast(&tag_bits),
+   reinterpret_cast(&tag_shift), 0))) {
+  CHECK_EQ(tag_bits, kTagBits);
+  CHECK_EQ(tag_shift, kAddressTagShift);
+  return;
+}
+#  endif  // defined(__x86_64__) && !defined(HWASAN_ALIASING_MODE)
+if (flags()->fail_without_syscall_abi) {
+  Printf(
+  "FATAL: HWAddressSanitizer failed to enable tagged address syscall "
+  "ABI.\nSuggest check `sysctl abi.tagged_addr_disabled` "
+  "configuration.\n");
+  Die();
+}
   }
 #undef PR_SET_TAGGED_ADDR_CTRL
 #undef PR_GET_TAGGED_ADDR_CTRL
@@ -181,7 +198,7 @@
   // High memory starts where allocated shadow allows.
   kHighMemStart = ShadowToMem(kHighShadowStart);
 
-#if defined(__x86_64__)
+#  if defined(HWASAN_ALIASING_MODE)
   constexpr uptr kAliasRegionOffset = 1ULL << (kTaggableRegionCheckShift - 1);
   kAliasRegionStart =
   __hwasan_shadow_memory_dynamic_address + kAliasRegionOffset;
@@ -191,7 +208,7 @@
   CHECK_EQ(
   (kAliasRegionStart + kAliasRegionOffset - 1) >> kTaggableRegionCheckShift,
   __hwasan_shadow_memory_dynamic_address >> kTaggableRegionCheckShift);
-#endif
+#  endif
 
   // Check the sanity of the defined memory ranges (there might be gaps).
   CHECK_EQ(kHighMemStart % GetMmapGranularity(), 0);
@@ -236,9 +253,11 @@
 }
 
 bool MemIsApp(uptr p) {
-#if !defined(__x86_64__)  // Memory outside the alias range has non-zero tags.
+// Memory outside the alias range has non-zero tags.
+#  if !defined(HWASAN_ALIASING_MODE)
   CHECK(GetTagFromPointer(p) == 0);
-#endif
+#  endif
+
   return p >= kHighMemStart || (p >= kLowMemStart && p <= kLowMemEnd);
 }
 
Index: compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
===
--- compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
+++ compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
@@ -119,12 +119,12 @@
 void InitShadowGOT() {}
 
 uptr FindDynamicS

[clang] 5f58322 - [HWASan] Build separate LAM runtime on x86_64.

2021-05-17 Thread Matt Morehouse via cfe-commits

Author: Matt Morehouse
Date: 2021-05-17T09:19:06-07:00
New Revision: 5f58322368b070b63fe2b2559a54f646cb97e2c4

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

LOG: [HWASan] Build separate LAM runtime on x86_64.

Since we have both aliasing mode and Intel LAM on x86_64, we need to
choose the mode at either run time or compile time.  This patch
implements the plumbing to build both and choose between them at
compile time.

Reviewed By: vitalybuka, eugenis

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
compiler-rt/lib/hwasan/CMakeLists.txt
compiler-rt/lib/hwasan/hwasan.h
compiler-rt/lib/hwasan/hwasan_allocator.h
compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cpp
compiler-rt/lib/hwasan/hwasan_linux.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index e8fdb08137864..b74a9fe3eb927 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -816,8 +816,12 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
 }
 if (SanArgs.needsTsanRt() && SanArgs.linkRuntimes())
   SharedRuntimes.push_back("tsan");
-if (SanArgs.needsHwasanRt() && SanArgs.linkRuntimes())
-  SharedRuntimes.push_back("hwasan");
+if (SanArgs.needsHwasanRt() && SanArgs.linkRuntimes()) {
+  if (SanArgs.needsHwasanAliasesRt())
+SharedRuntimes.push_back("hwasan_aliases");
+  else
+SharedRuntimes.push_back("hwasan");
+}
   }
 
   // The stats_client library is also statically linked into DSOs.
@@ -847,9 +851,15 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
   }
 
   if (!SanArgs.needsSharedRt() && SanArgs.needsHwasanRt() && 
SanArgs.linkRuntimes()) {
-StaticRuntimes.push_back("hwasan");
-if (SanArgs.linkCXXRuntimes())
-  StaticRuntimes.push_back("hwasan_cxx");
+if (SanArgs.needsHwasanAliasesRt()) {
+  StaticRuntimes.push_back("hwasan_aliases");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("hwasan_aliases_cxx");
+} else {
+  StaticRuntimes.push_back("hwasan");
+  if (SanArgs.linkCXXRuntimes())
+StaticRuntimes.push_back("hwasan_cxx");
+}
   }
   if (SanArgs.needsDfsanRt() && SanArgs.linkRuntimes())
 StaticRuntimes.push_back("dfsan");

diff  --git a/compiler-rt/lib/hwasan/CMakeLists.txt 
b/compiler-rt/lib/hwasan/CMakeLists.txt
index 707cbb44233fe..547b26f0033d6 100644
--- a/compiler-rt/lib/hwasan/CMakeLists.txt
+++ b/compiler-rt/lib/hwasan/CMakeLists.txt
@@ -93,6 +93,24 @@ add_compiler_rt_object_libraries(RTHwasan_dynamic
   CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
   DEFS ${HWASAN_DEFINITIONS})
 
+# Compile a 
diff erent runtime for x86 aliasing mode.
+set(HWASAN_ALIASES_RTL_CFLAGS ${HWASAN_RTL_CFLAGS})
+list(APPEND HWASAN_ALIASES_RTL_CFLAGS -DHWASAN_ALIASING_MODE)
+set(HWASAN_ALIASES_DYNAMIC_CFLAGS ${HWASAN_DYNAMIC_CFLAGS})
+list(APPEND HWASAN_ALIASES_DYNAMIC_CFLAGS -DHWASAN_ALIASING_MODE)
+add_compiler_rt_object_libraries(RTHwasanAliases
+  ARCHS ${HWASAN_SUPPORTED_ARCH}
+  SOURCES ${HWASAN_RTL_SOURCES}
+  ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
+  CFLAGS ${HWASAN_ALIASES_RTL_CFLAGS}
+  DEFS ${HWASAN_DEFINITIONS})
+add_compiler_rt_object_libraries(RTHwasanAliases_dynamic
+  ARCHS ${HWASAN_SUPPORTED_ARCH}
+  SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
+  ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
+  CFLAGS ${HWASAN_ALIASES_DYNAMIC_CFLAGS}
+  DEFS ${HWASAN_DEFINITIONS})
+
 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
 add_compiler_rt_object_libraries(RTHwasan_dynamic_version_script_dummy
   ARCHS ${HWASAN_SUPPORTED_ARCH}
@@ -100,47 +118,61 @@ 
add_compiler_rt_object_libraries(RTHwasan_dynamic_version_script_dummy
   CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
   DEFS ${HWASAN_DEFINITIONS})
 
-foreach(arch ${HWASAN_SUPPORTED_ARCH})
-  add_compiler_rt_runtime(clang_rt.hwasan
+# If use_aliases is TRUE, adds the HWASan runtime built with alias support.
+# Otherwise adds the runtime without alias support.
+function(add_hwasan_runtimes arch use_aliases)
+  set(hwasan_object_lib RTHwasan)
+  set(hwasan_object_dyn_lib RTHwasan_dynamic)
+  set(hwasan_runtime clang_rt.hwasan)
+  set(hwasan_rtl_flags ${HWASAN_RTL_CFLAGS})
+  set(hwasan_dyn_flags ${HWASAN_DYNAMIC_CFLAGS})
+  if(use_aliases)
+set(hwasan_object_lib RTHwasanAliases)
+set(hwasan_object_dyn_lib RTHwasanAliases_dynamic)
+set(hwasan_runtime clang_rt.hwasan_aliases)
+set(hwasan_rtl_flags ${HWASAN_ALIASES_RTL_CFLAGS})
+set(hwasan_dyn_flags ${HWASAN_ALIASES_DYNAMIC_CFLAGS})
+  endif()
+  add_compiler_rt_runtime(${hwasan_runtime}
 STATIC
 ARCHS ${arch}
-OBJECT_LIBS RTHwasan

[PATCH] D102556: [HIP] Fix spack detection

2021-05-17 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM with a test nit.




Comment at: clang/test/Driver/rocm-detect.hip:115
+
+// SPACK-MISS-SILENT-NOT: SPACK package hip-4.0.0 not found at
+// SPACK-MISS-SILENT-NOT: SPACK package rocm-device-libs-4.0.0 not found at

Nit: I'd match the version with a regex. Otherwise this test would continue 
passing even if compiler were to report `hip-some.other.version not found` 


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

https://reviews.llvm.org/D102556

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 345906.
hctim marked 2 inline comments as done.
hctim added a comment.

Address Kostya's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo.so
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-fuchsia/libclang_rt.scudo_standalone.so
  clang/test/Driver/fuchsia.c
  clang/test/Driver/sanitizer-ld.c
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp
  compiler-rt/test/scudo/CMakeLists.txt
  compiler-rt/test/scudo/aligned-new.cpp
  compiler-rt/test/scudo/alignment.c
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/double-free.cpp
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/lit.site.cfg.py.in
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/options.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preinit.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/quarantine.c
  compiler-rt/test/scudo/random_shuffle.cpp
  compiler-rt/test/scudo/realloc.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/sized-delete.cpp
  compiler-rt/test/scudo/sizes.cpp
  compiler-rt/test/scudo/standalone/CMakeLists.txt
  compiler-rt/test/scudo/standalone/aligned-new.cpp
  compiler-rt/test/scudo/standalone/alignment.c
  compiler-rt/test/scudo/standalone/dealloc-race.c
  compiler-rt/test/scudo/standalone/double-free.cpp
  compiler-rt/test/scudo/standalone/fsanitize.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/overflow.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/quarantine.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/realloc.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/rss.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/secondary.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/sizes.cpp
  compiler-rt/test/scudo/standalone/lit-unmigrated/threads.c
  compiler-rt/test/scudo/standalone/lit-unmigrated/valloc.c
  compiler-rt/test/scudo/standalone/lit.cfg.py
  compiler-rt/test/scudo/standalone/lit.site.cfg.py.in
  compiler-rt/test/scudo/standalone/malloc.cpp
  compiler-rt/test/scudo/standalone/memalign.c
  compiler-rt/test/scudo/standalone/mismatch.cpp
  compiler-rt/test/scudo/standalone/options.cpp
  compiler-rt/test/scudo/standalone/preinit.c
  compiler-rt/test/scudo/standalone/preload.cpp
  compiler-rt/test/scudo/standalone/random_shuffle.cpp
  compiler-rt/test/scudo/standalone/sized-delete.cpp
  compiler-rt/test/scudo/standalone/stats.c
  compiler-rt/test/scudo/standalone/tsd_destruction.c
  compiler-rt/test/scudo/stats.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ /dev/null
@@ -1,8 +0,0 @@
-UNSUPPORTED: android
-
-Verify that various functions are *not* present in the minimal binary. Presence
-of those symbols in the minimal runtime would mean that the split code made it
-back into the core Sanitizer runtime library.
-
-RUN: nm %shared_minlibscudo | not grep Symbolizer
-RUN: nm %shared_minlibscudo | not grep Coverage
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- /dev/null
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,42 +0,0 @@
-// RUN: %clang_scudo %s -o %t
-// RUN: %run %t 2>&1
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-// Some of glibc's own thread local data is destroyed after a user's thread
-// local destructors are called, via __libc_thread_freeres. This might involve
-// calling free, as is the case for strerror_thread_freeres.
-// If there is no prior heap operation in the thread, this free would end up 
-// initializing some thread specific data that would never be destroyed
-// properly, while still being deallocated when the TLS goes away. As a result,
-// a program could SEGV, usually in
-// __sanitizer::AllocatorGlobalStats::Unregister, where one of the doubly
-// linked list links would refer to a now unmapped memory area.
-
-// This test reproduces those circumstances. Success means executing without
-// a segmentation fault.
-
-const int kNumThreads = 16;
-pthread_t tid[k

[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 2 inline comments as done.
hctim added a comment.

In D102543#2763749 , @cryptoad wrote:

> I think one of the remaining things to address is the supported architectures:
>
>   set(ALL_SCUDO_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} 
> ${MIPS64} ${PPC64})
>   set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})
>
> I am unclear as to whether or not there are consumers for the missing ones, 
> but if there are we might break -fsanitize=scudo for them.
> We have fallback for non-x86/arm processors in 
> https://github.com/llvm/llvm-project/blob/e0921655b1ff8d4ba7c14be59252fe05b705920e/compiler-rt/lib/scudo/standalone/checksum.cpp#L79
>  , the rest looks fine so I think adding them should work.

Sure, I've added them but I don't have anything to test with. Well - I'm sure 
they'll let us know if they break.




Comment at: compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp:42
+  if (Allocator.canReturnNull()) { 
\
+errno = EINVAL;
\
+return nullptr;
\

cryptoad wrote:
> I don't think errno carry over to  C++, there seems to be no sign of it in 
> https://en.cppreference.com/w/cpp/memory/new/operator_new
Removed.



Comment at: compiler-rt/test/scudo/standalone/lit.cfg.py:21
 c_flags = ([config.target_cflags] +
-   ["-pthread",
-   "-fPIE",
-   "-pie",
-   "-O0",
-   "-UNDEBUG",
-   "-ldl",
-   "-Wl,--gc-sections"])
+   ["-pthread", "-fPIE", "-pie", "-O0", "-UNDEBUG", "-ldl",
+"-Wl,--gc-sections"])

cryptoad wrote:
> -ldl might not be necessary anymore without the sanitizer dependencies?
Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

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


[PATCH] D102306: Add gfx1034

2021-05-17 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl added a subscriber: t-tye.
kzhuravl added a comment.

In D102306#2760806 , @tra wrote:

> In D102306#2760775 , @msearles 
> wrote:
>
>> In D102306#2758166 , 
>> @JonChesterfield wrote:
>>
>>> Is there documentation for the mapping from product names to gfx numbers?
>>
>> See the Processors section of https://llvm.org/docs/AMDGPUUsage.html
>
> It appears to be missing some GPUs. None of WX series are listed, for example.

+ @t-tye

@t-tye usually updates product names as they become available.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102306

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


[PATCH] D102543: [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.

2021-05-17 Thread Kostya Kortchinsky via Phabricator via cfe-commits
cryptoad added a comment.

I think one of the remaining things to address is the supported architectures:

  set(ALL_SCUDO_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} 
${MIPS64} ${PPC64})
  set(ALL_SCUDO_STANDALONE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})

I am unclear as to whether or not there are consumers for the missing ones, but 
if there are we might break -fsanitize=scudo for them.
We have fallback for non-x86/arm processors in 
https://github.com/llvm/llvm-project/blob/e0921655b1ff8d4ba7c14be59252fe05b705920e/compiler-rt/lib/scudo/standalone/checksum.cpp#L79
 , the rest looks fine so I think adding them should work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102543

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


[clang] e092165 - [AIX] Implement AIX special bitfield related alignment rules

2021-05-17 Thread Xiangling Liao via cfe-commits

Author: Xiangling Liao
Date: 2021-05-17T11:30:29-04:00
New Revision: e0921655b1ff8d4ba7c14be59252fe05b705920e

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

LOG: [AIX] Implement AIX special bitfield related alignment rules

1.[bool, char, short] bitfields have the same alignment as unsigned int
2.Adjust alignment on typedef field decls/honor align attribute
3.Fix alignment for scoped enum class
4.Long long bitfield has 4bytes alignment and StorageUnitSize under 32 bit
  compile mode

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

Added: 
clang/test/Layout/aix-bitfield-alignment.c
clang/test/Layout/aix-bitfield-alignment.cpp

Modified: 
clang/lib/AST/RecordLayoutBuilder.cpp

Removed: 




diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 8a25b5cbd84a..beb111e2e971 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1528,12 +1528,17 @@ void 
ItaniumRecordLayoutBuilder::LayoutWideBitField(uint64_t FieldSize,
   UpdateAlignment(TypeAlign);
 }
 
+static bool isAIXLayout(const ASTContext &Context) {
+  return Context.getTargetInfo().getTriple().getOS() == llvm::Triple::AIX;
+}
+
 void ItaniumRecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
   bool FieldPacked = Packed || D->hasAttr();
   uint64_t FieldSize = D->getBitWidthValue(Context);
   TypeInfo FieldInfo = Context.getTypeInfo(D->getType());
   uint64_t StorageUnitSize = FieldInfo.Width;
   unsigned FieldAlign = FieldInfo.Align;
+  bool AlignIsRequired = FieldInfo.AlignIsRequired;
 
   // UnfilledBitsInLastUnit is the 
diff erence between the end of the
   // last allocated bitfield (i.e. the first bit offset available for
@@ -1611,9 +1616,33 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const 
FieldDecl *D) {
 }
   }
 
+  if (isAIXLayout(Context)) {
+if (StorageUnitSize < Context.getTypeSize(Context.UnsignedIntTy)) {
+  // On AIX, [bool, char, short] bitfields have the same alignment
+  // as [unsigned].
+  StorageUnitSize = Context.getTypeSize(Context.UnsignedIntTy);
+} else if (StorageUnitSize > Context.getTypeSize(Context.UnsignedIntTy) &&
+   Context.getTargetInfo().getTriple().isArch32Bit() &&
+   FieldSize <= 32) {
+  // Under 32-bit compile mode, the bitcontainer is 32 bits if a single
+  // long long bitfield has length no greater than 32 bits.
+  StorageUnitSize = 32;
+
+  if (!AlignIsRequired)
+FieldAlign = 32;
+}
+
+if (FieldAlign < StorageUnitSize) {
+  // The bitfield alignment should always be greater than or equal to
+  // bitcontainer size.
+  FieldAlign = StorageUnitSize;
+}
+  }
+
   // If the field is wider than its declared type, it follows
-  // 
diff erent rules in all cases.
-  if (FieldSize > StorageUnitSize) {
+  // 
diff erent rules in all cases, except on AIX.
+  // On AIX, wide bitfield follows the same rules as normal bitfield.
+  if (FieldSize > StorageUnitSize && !isAIXLayout(Context)) {
 LayoutWideBitField(FieldSize, StorageUnitSize, FieldPacked, D);
 return;
   }

diff  --git a/clang/test/Layout/aix-bitfield-alignment.c 
b/clang/test/Layout/aix-bitfield-alignment.c
new file mode 100644
index ..a736695cc603
--- /dev/null
+++ b/clang/test/Layout/aix-bitfield-alignment.c
@@ -0,0 +1,234 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK32 %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK32 %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+
+struct A {
+  unsigned char c : 2;
+} A;
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct A
+// CHECK-NEXT:  0:0-1 |   unsigned char c
+// CHECK-NEXT:   sizeof=4, {{(dsize=4, )?}}align=4, 
preferredalign=4
+
+struct B {
+  char c;
+  int : 0;
+} B;
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct B
+// CHECK-NEXT:  0 |   char c
+// CHECK-NEXT:4:- |   int
+// CHECK-NEXT:   sizeof=4, {{(dsize=4, )?}}align=4, 
preferredalign=4
+
+struct C {
+  signed int a1 : 6;
+  signed char a2 : 4;
+ 

[PATCH] D87029: [AIX] Implement AIX special bitfield related alignment rules

2021-05-17 Thread Xiangling Liao 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 rGe0921655b1ff: [AIX] Implement AIX special bitfield related 
alignment rules (authored by Xiangling_L).

Changed prior to commit:
  https://reviews.llvm.org/D87029?vs=345530&id=345898#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87029

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/Layout/aix-bitfield-alignment.c
  clang/test/Layout/aix-bitfield-alignment.cpp

Index: clang/test/Layout/aix-bitfield-alignment.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-bitfield-alignment.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK %s
+
+struct A {
+  bool b : 3;
+};
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct A
+// CHECK-NEXT:  0:0-2 |   _Bool b
+// CHECK-NEXT:| [sizeof=4, dsize=4, align=4, preferredalign=4,
+// CHECK-NEXT:|  nvsize=4, nvalign=4, preferrednvalign=4]
+
+enum class Bool : bool { False = 0,
+ True = 1 };
+
+struct B {
+  Bool b : 1;
+};
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct B
+// CHECK-NEXT:  0:0-0 |   enum Bool b
+// CHECK-NEXT:| [sizeof=4, dsize=4, align=4, preferredalign=4,
+// CHECK-NEXT:|  nvsize=4, nvalign=4, preferrednvalign=4]
+
+enum LL : unsigned long long { val = 1 };
Index: clang/test/Layout/aix-bitfield-alignment.c
===
--- /dev/null
+++ clang/test/Layout/aix-bitfield-alignment.c
@@ -0,0 +1,234 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK32 %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK32 %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
+// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+
+struct A {
+  unsigned char c : 2;
+} A;
+
+int a = sizeof(A);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct A
+// CHECK-NEXT:  0:0-1 |   unsigned char c
+// CHECK-NEXT:   sizeof=4, {{(dsize=4, )?}}align=4, preferredalign=4
+
+struct B {
+  char c;
+  int : 0;
+} B;
+
+int b = sizeof(B);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct B
+// CHECK-NEXT:  0 |   char c
+// CHECK-NEXT:4:- |   int
+// CHECK-NEXT:   sizeof=4, {{(dsize=4, )?}}align=4, preferredalign=4
+
+struct C {
+  signed int a1 : 6;
+  signed char a2 : 4;
+  short int a3 : 2;
+  int a4 : 2;
+  signed long a5 : 5;
+  long long int a6 : 6;
+  unsigned long a7 : 8;
+} C;
+
+int c = sizeof(C);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct C
+// CHECK-NEXT:  0:0-5 |   int a1
+// CHECK-NEXT:  0:6-9 |   signed char a2
+// CHECK-NEXT:  1:2-3 |   short a3
+// CHECK-NEXT:  1:4-5 |   int a4
+// CHECK-NEXT: 1:6-10 |   long a5
+// CHECK-NEXT:  2:3-8 |   long long a6
+// CHECK32: 4:0-7 |   unsigned long a7
+// CHECK32:  sizeof=8, {{(dsize=8, )?}}align=4, preferredalign=4
+// CHECK64: 3:1-8 |   unsigned long a7
+// CHECK64:  sizeof=8, {{(dsize=8, )?}}align=8, preferredalign=8
+
+#pragma align(packed)
+struct C1 {
+  signed int a1 : 6;
+  signed char a2 : 4;
+  short int a3 : 2;
+  int a4 : 2;
+  signed long a5 : 5;
+  long long int a6 : 6;
+  unsigned long a7 : 8;
+} C1;
+#pragma align(reset)
+
+int c1 = sizeof(C1);
+
+// CHECK:  *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct C1
+// CHECK-NEXT:  0:0-5 |   int a1
+// CHECK-NEXT:  0:6-9 |   signed char a2
+// CHECK-NEXT:  1:2-3 |   short a3
+// CHECK-NEXT:  1:4-5 |   int a4
+// CHECK-NEXT: 1:6-10 |   long a5
+// CHECK-NEXT:  2:3-8 |   long long a6
+// CHECK-NEXT:  3:1-8 |   unsigned long a7
+// CHECK-NEXT:   sizeof=5, {{(dsize=5, )?}}align=1, preferredalign=1
+
+#pragma pac

[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2021-05-17 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.
Herald added subscribers: llvm-commits, kristina.
Herald added a project: LLVM.



Comment at: llvm/trunk/lib/Support/PrettyStackTrace.cpp:93
+extern "C" const char *__crashreporter_info__
+__attribute__((visibility("hidden"))) = 0;
 asm(".desc ___crashreporter_info__, 0x10");

As far as I can tell, making this a hidden symbol makes the `.desc 
___crashreporter_info__, 0x10` (ie REFERENCED_DYNAMICALLY) not have any effect:

```
% cat crashref.cc
extern "C" const char *__crashreporter_info__  
__attribute__((visibility("hidden"))) = 0;
asm(".desc ___crashreporter_info__, 0x10");
int main() {}
% clang crashref.cc
% nm -m a.out
00014000 (__DATA,__common) non-external (was a private external) 
___crashreporter_info__
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
00013fb0 (__TEXT,__text) external _main
 (undefined) external dyld_stub_binder (from libSystem)
% strip -r a.out
% nm -m a.out
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
```

It does have an effect without it:
```
% cat crashref.cc
extern "C" const char *__crashreporter_info__ = 0;
asm(".desc ___crashreporter_info__, 0x10");
int main() {}
% clang crashref.cc
% nm -m a.out
00014000 (__DATA,__common) [referenced dynamically] external 
___crashreporter_info__
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
00013fb0 (__TEXT,__text) external _main
 (undefined) external dyld_stub_binder (from libSystem)
% strip -r a.out
% nm -m a.out
00014000 (__DATA,__common) [referenced dynamically] external 
___crashreporter_info__
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
```

Is that intentional? Should we just remove the `.desc` line?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D27683

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


  1   2   >