[PATCH] D115611: [X86][BF16] delete `typedef unsigned short __bfloat16`

2021-12-12 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe created this revision.
Herald added a subscriber: pengfei.
FreddyYe requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The name `__bfloat` may mislead its real type is bfloat16, but in
fact it's not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115611

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/avx512bf16intrin.h
  clang/lib/Headers/avx512vlbf16intrin.h
  clang/test/CodeGen/X86/avx512bf16-builtins.c
  clang/test/CodeGen/X86/avx512vlbf16-builtins.c


Index: clang/test/CodeGen/X86/avx512vlbf16-builtins.c
===
--- clang/test/CodeGen/X86/avx512vlbf16-builtins.c
+++ clang/test/CodeGen/X86/avx512vlbf16-builtins.c
@@ -162,7 +162,7 @@
   return _mm256_mask_dpbf16_ps(D, U, A, B);
 }
 
-__bfloat16 test_mm_cvtness_sbh(float A) {
+short test_mm_cvtness_sbh(float A) {
   // CHECK-LABEL: @test_mm_cvtness_sbh
   // CHECK: @llvm.x86.avx512bf16.mask.cvtneps2bf16.128
   // CHECK: ret i16 %{{.*}}
Index: clang/test/CodeGen/X86/avx512bf16-builtins.c
===
--- clang/test/CodeGen/X86/avx512bf16-builtins.c
+++ clang/test/CodeGen/X86/avx512bf16-builtins.c
@@ -4,9 +4,9 @@
 
 #include 
 
-float test_mm_cvtsbh_ss(__bfloat16 A) {
+float test_mm_cvtsbh_ss(short A) {
   // CHECK-LABEL: @test_mm_cvtsbh_ss
-  // CHECK: zext i16 %{{.*}} to i32
+  // CHECK: sext i16 %{{.*}} to i32
   // CHECK: shl i32 %{{.*}}, 16
   // CHECK: bitcast i32 %{{.*}} to float
   // CHECK: ret float %{{.*}}
Index: clang/lib/Headers/avx512vlbf16intrin.h
===
--- clang/lib/Headers/avx512vlbf16intrin.h
+++ clang/lib/Headers/avx512vlbf16intrin.h
@@ -413,7 +413,7 @@
 ///A float data.
 /// \returns A bf16 data whose sign field and exponent field keep unchanged,
 ///and fraction field is truncated to 7 bits.
-static __inline__ __bfloat16 __DEFAULT_FN_ATTRS128 _mm_cvtness_sbh(float __A) {
+static __inline__ short __DEFAULT_FN_ATTRS128 _mm_cvtness_sbh(float __A) {
   __v4sf __V = {__A, 0, 0, 0};
   __v8hi __R = __builtin_ia32_cvtneps2bf16_128_mask(
   (__v4sf)__V, (__v8hi)_mm_undefined_si128(), (__mmask8)-1);
Index: clang/lib/Headers/avx512bf16intrin.h
===
--- clang/lib/Headers/avx512bf16intrin.h
+++ clang/lib/Headers/avx512bf16intrin.h
@@ -15,7 +15,6 @@
 
 typedef short __m512bh __attribute__((__vector_size__(64), __aligned__(64)));
 typedef short __m256bh __attribute__((__vector_size__(32), __aligned__(32)));
-typedef unsigned short __bfloat16;
 
 #define __DEFAULT_FN_ATTRS512 \
   __attribute__((__always_inline__, __nodebug__, __target__("avx512bf16"), \
@@ -33,7 +32,7 @@
 ///A bfloat data.
 /// \returns A float data whose sign field and exponent field keep unchanged,
 ///and fraction field is extended to 23 bits.
-static __inline__ float __DEFAULT_FN_ATTRS _mm_cvtsbh_ss(__bfloat16 __A) {
+static __inline__ float __DEFAULT_FN_ATTRS _mm_cvtsbh_ss(short __A) {
   return __builtin_ia32_cvtsbf162ss_32(__A);
 }
 
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -12479,8 +12479,8 @@
 const CallExpr *E,
 ArrayRef Ops) {
   llvm::Type *Int32Ty = CGF.Builder.getInt32Ty();
-  Value *ZeroExt = CGF.Builder.CreateZExt(Ops[0], Int32Ty);
-  Value *Shl = CGF.Builder.CreateShl(ZeroExt, 16);
+  Value *SignExt = CGF.Builder.CreateSExt(Ops[0], Int32Ty);
+  Value *Shl = CGF.Builder.CreateShl(SignExt, 16);
   llvm::Type *ResultType = CGF.ConvertType(E->getType());
   Value *BitCast = CGF.Builder.CreateBitCast(Shl, ResultType);
   return BitCast;


Index: clang/test/CodeGen/X86/avx512vlbf16-builtins.c
===
--- clang/test/CodeGen/X86/avx512vlbf16-builtins.c
+++ clang/test/CodeGen/X86/avx512vlbf16-builtins.c
@@ -162,7 +162,7 @@
   return _mm256_mask_dpbf16_ps(D, U, A, B);
 }
 
-__bfloat16 test_mm_cvtness_sbh(float A) {
+short test_mm_cvtness_sbh(float A) {
   // CHECK-LABEL: @test_mm_cvtness_sbh
   // CHECK: @llvm.x86.avx512bf16.mask.cvtneps2bf16.128
   // CHECK: ret i16 %{{.*}}
Index: clang/test/CodeGen/X86/avx512bf16-builtins.c
===
--- clang/test/CodeGen/X86/avx512bf16-builtins.c
+++ clang/test/CodeGen/X86/avx512bf16-builtins.c
@@ -4,9 +4,9 @@
 
 #include 
 
-float test_mm_cvtsbh_ss(__bfloat16 A) {
+float test_mm_cvtsbh_ss(short A) {
   // CHECK-LABEL: @test_mm_cvtsbh_ss
-  // CHECK: zext i16 %{{.*}} to i32
+  // CHECK: sext i16 %{{.*}} to i32
   // CHECK: shl i32 %{{.*}}, 16
   // CHECK: bitcast i32 %{{.*}} to float
   // CHECK: ret float %{{.*}}
Index: 

[PATCH] D115503: [DebugInfo][Clang] record the access flag for class/struct/union types.

2021-12-12 Thread ChenZheng via Phabricator via cfe-commits
shchenz accepted this revision as: shchenz.
shchenz added a comment.
This revision is now accepted and ready to land.

Thanks for fixing this. LGTM. Please wait for @dblaikie comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115503

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


[PATCH] D115503: [DebugInfo][Clang] record the access flag for class/struct/union types.

2021-12-12 Thread ChenZheng via Phabricator via cfe-commits
shchenz added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-access.cpp:28
 
+class C {
+public:

Esme wrote:
> dblaikie wrote:
> > shchenz wrote:
> > > Will we generate a redundant flag if we define a private type in the 
> > > class or a public type in the struct/union? Maybe we could add a case for 
> > > that too.
> > How',s this compare to member variables? Do we always put the access level 
> > on members even when it's the default? Perhaps the Flag handling code could 
> > be generalized and used between both these cases & if one of them gets 
> > fixed in favor of not explicitly specifying the default, both would benefit.
> Member variables use the same Flag handling code, i.e. getAccessFlag(), which 
> returns 0 if the access specifier equals the default for the containing type.
> Therefore for both cases we will not record the access flag when it's the 
> default.
> The case where the default access is not explicitly specified is added now.
Good to know `getAccessFlag()` already takes care of this case. Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115503

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


[PATCH] D115503: [DebugInfo][Clang] record the access flag for class/struct/union types.

2021-12-12 Thread Esme Yi via Phabricator via cfe-commits
Esme added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-access.cpp:28
 
+class C {
+public:

dblaikie wrote:
> shchenz wrote:
> > Will we generate a redundant flag if we define a private type in the class 
> > or a public type in the struct/union? Maybe we could add a case for that 
> > too.
> How',s this compare to member variables? Do we always put the access level on 
> members even when it's the default? Perhaps the Flag handling code could be 
> generalized and used between both these cases & if one of them gets fixed in 
> favor of not explicitly specifying the default, both would benefit.
Member variables use the same Flag handling code, i.e. getAccessFlag(), which 
returns 0 if the access specifier equals the default for the containing type.
Therefore for both cases we will not record the access flag when it's the 
default.
The case where the default access is not explicitly specified is added now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115503

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


[PATCH] D115503: [DebugInfo][Clang] record the access flag for class/struct/union types.

2021-12-12 Thread Esme Yi via Phabricator via cfe-commits
Esme updated this revision to Diff 393805.
Esme added a comment.

Add a case to show that the default access flag is not recorded.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115503

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-access.cpp


Index: clang/test/CodeGenCXX/debug-info-access.cpp
===
--- clang/test/CodeGenCXX/debug-info-access.cpp
+++ clang/test/CodeGenCXX/debug-info-access.cpp
@@ -25,6 +25,43 @@
   void priv_default();
 };
 
+class C {
+public:
+  // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "D",{{.*}} 
flags: DIFlagPublic | DIFlagTypePassByValue,
+  struct D {
+  };
+protected:
+  // CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "E",{{.*}} flags: 
DIFlagProtected | DIFlagTypePassByValue,
+  union E {
+  };
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "J",{{.*}} 
flags: DIFlagTypePassByValue,
+  struct J {
+  };
+public:
+  D d;
+  E e;
+  J j;
+};
+
+struct F {
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "G",{{.*}} flags: 
DIFlagPrivate | DIFlagTypePassByValue,
+  union G {
+  };
+public:
+  G g;
+};
+
+union H {
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "I",{{.*}} flags: 
DIFlagPrivate | DIFlagTypePassByValue,
+  class I {
+  };
+public:
+  I i;
+};
+
 union U {
   // CHECK-DAG: !DISubprogram(name: "union_pub_default",{{.*}} line: 
[[@LINE+1]],{{.*}} flags: DIFlagPrototyped,
   void union_pub_default();
@@ -33,7 +70,6 @@
   int union_priv;
 };
 
-
 // CHECK: !DISubprogram(name: "free",
 // CHECK-SAME:  flags: DIFlagPrototyped,
 // CHECK-SAME:  spFlags: DISPFlagDefinition
@@ -42,3 +78,6 @@
 U u;
 A a;
 B b;
+C c;
+F f;
+H h;
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3633,6 +3633,9 @@
 // Record exports it symbols to the containing structure.
 if (CXXRD->isAnonymousStructOrUnion())
 Flags |= llvm::DINode::FlagExportSymbols;
+
+Flags |= getAccessFlag(CXXRD->getAccess(),
+   dyn_cast(CXXRD->getDeclContext()));
   }
 
   llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);


Index: clang/test/CodeGenCXX/debug-info-access.cpp
===
--- clang/test/CodeGenCXX/debug-info-access.cpp
+++ clang/test/CodeGenCXX/debug-info-access.cpp
@@ -25,6 +25,43 @@
   void priv_default();
 };
 
+class C {
+public:
+  // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "D",{{.*}} flags: DIFlagPublic | DIFlagTypePassByValue,
+  struct D {
+  };
+protected:
+  // CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "E",{{.*}} flags: DIFlagProtected | DIFlagTypePassByValue,
+  union E {
+  };
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "J",{{.*}} flags: DIFlagTypePassByValue,
+  struct J {
+  };
+public:
+  D d;
+  E e;
+  J j;
+};
+
+struct F {
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "G",{{.*}} flags: DIFlagPrivate | DIFlagTypePassByValue,
+  union G {
+  };
+public:
+  G g;
+};
+
+union H {
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "I",{{.*}} flags: DIFlagPrivate | DIFlagTypePassByValue,
+  class I {
+  };
+public:
+  I i;
+};
+
 union U {
   // CHECK-DAG: !DISubprogram(name: "union_pub_default",{{.*}} line: [[@LINE+1]],{{.*}} flags: DIFlagPrototyped,
   void union_pub_default();
@@ -33,7 +70,6 @@
   int union_priv;
 };
 
-
 // CHECK: !DISubprogram(name: "free",
 // CHECK-SAME:  flags: DIFlagPrototyped,
 // CHECK-SAME:  spFlags: DISPFlagDefinition
@@ -42,3 +78,6 @@
 U u;
 A a;
 B b;
+C c;
+F f;
+H h;
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3633,6 +3633,9 @@
 // Record exports it symbols to the containing structure.
 if (CXXRD->isAnonymousStructOrUnion())
 Flags |= llvm::DINode::FlagExportSymbols;
+
+Flags |= getAccessFlag(CXXRD->getAccess(),
+   dyn_cast(CXXRD->getDeclContext()));
   }
 
   llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115610: [C++20] [Modules] Don't create multiple global module fragment

2021-12-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu created this revision.
ChuanqiXu added reviewers: rsmith, aaron.ballman, urnathan, erichkeane, 
hubert.reinterpretcast.
ChuanqiXu added a project: clang.
ChuanqiXu requested review of this revision.
Herald added a subscriber: cfe-commits.

Since the serialization code would recognize modules by names and the name of 
all global module fragment is ``, so that the serialization code would 
complain for the same module.

This patch fixes this by using a global module fragment cache in Sema. Before 
this patch, the compiler would fail on an assertion complaining the duplicated 
modules.

Test Plan: check-all, an internal module library


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115610

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaModule.cpp
  clang/test/CXX/module/module.unit/p7/Inputs/h8.h
  clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
  clang/test/CXX/module/module.unit/p7/t8.cpp


Index: clang/test/CXX/module/module.unit/p7/t8.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/t8.cpp
@@ -0,0 +1,7 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %S/Inputs/m8.cppm 
-I%S/Inputs -o %t/m8.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%S/Inputs/ 
-fprebuilt-module-path=%t %s -verify
+// expected-no-diagnostics
+export module t8;
+import m8;
Index: clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
===
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
@@ -0,0 +1,8 @@
+module;
+#include "h8.h"
+export module m8;
+
+extern "C++" {
+void bar();
+}
+
Index: clang/test/CXX/module/module.unit/p7/Inputs/h8.h
===
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/Inputs/h8.h
@@ -0,0 +1,4 @@
+#ifndef H8
+#define H8
+void foo();
+#endif
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -704,19 +704,24 @@
 
 Module *Sema::PushGlobalModuleFragment(SourceLocation BeginLoc,
bool IsImplicit) {
-  ModuleMap  = PP.getHeaderSearchInfo().getModuleMap();
-  Module *GlobalModule =
-  Map.createGlobalModuleFragmentForModuleUnit(BeginLoc, 
getCurrentModule());
-  assert(GlobalModule && "module creation should not fail");
+  // We shouldn't create new global module fragment if there is already
+  // one.
+  if (!GlobalModuleFragmentCache) {
+ModuleMap  = PP.getHeaderSearchInfo().getModuleMap();
+GlobalModuleFragmentCache = Map.createGlobalModuleFragmentForModuleUnit(
+BeginLoc, getCurrentModule());
+  }
+
+  assert(GlobalModuleFragmentCache && "module creation should not fail");
 
   // Enter the scope of the global module.
-  ModuleScopes.push_back({BeginLoc, GlobalModule,
+  ModuleScopes.push_back({BeginLoc, GlobalModuleFragmentCache,
   /*ModuleInterface=*/false,
   /*ImplicitGlobalModuleFragment=*/IsImplicit,
-  /*VisibleModuleSet*/{}});
-  VisibleModules.setVisible(GlobalModule, BeginLoc);
+  /*VisibleModuleSet*/ {}});
+  VisibleModules.setVisible(GlobalModuleFragmentCache, BeginLoc);
 
-  return GlobalModule;
+  return GlobalModuleFragmentCache;
 }
 
 void Sema::PopGlobalModuleFragment() {
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -2213,6 +2213,8 @@
   };
   /// The modules we're currently parsing.
   llvm::SmallVector ModuleScopes;
+  /// The gloabl module fragment of the current tranlation unit.
+  clang::Module *GlobalModuleFragmentCache = nullptr;
 
   /// Namespace definitions that we will export when they finish.
   llvm::SmallPtrSet DeferredExportedNamespaces;


Index: clang/test/CXX/module/module.unit/p7/t8.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/t8.cpp
@@ -0,0 +1,7 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %S/Inputs/m8.cppm -I%S/Inputs -o %t/m8.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%S/Inputs/ -fprebuilt-module-path=%t %s -verify
+// expected-no-diagnostics
+export module t8;
+import m8;
Index: clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
===
--- /dev/null
+++ clang/test/CXX/module/module.unit/p7/Inputs/m8.cppm
@@ -0,0 +1,8 @@
+module;
+#include "h8.h"
+export module m8;
+
+extern "C++" {
+void bar();
+}
+
Index: clang/test/CXX/module/module.unit/p7/Inputs/h8.h
===
--- 

[PATCH] D115503: [DebugInfo][Clang] record the access flag for class/struct/union types.

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



Comment at: clang/test/CodeGenCXX/debug-info-access.cpp:28
 
+class C {
+public:

shchenz wrote:
> Will we generate a redundant flag if we define a private type in the class or 
> a public type in the struct/union? Maybe we could add a case for that too.
How',s this compare to member variables? Do we always put the access level on 
members even when it's the default? Perhaps the Flag handling code could be 
generalized and used between both these cases & if one of them gets fixed in 
favor of not explicitly specifying the default, both would benefit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115503

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


[PATCH] D113372: [Driver] Add CLANG_DEFAULT_PIE_ON_LINUX to emulate GCC --enable-default-pie

2021-12-12 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

Last update introduced a lot of unrelated changes? But the actual intended 
change seems fine now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113372

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


[PATCH] D115441: [X86][MS] Add 80bit long double support for Windows

2021-12-12 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Thanks @mstorsjo for the inputs.

> However outside of the core OS, any function in the CRT, that uses long 
> doubles, is going to be wrong

Good point! I didn't think much on the CRT library. But I think this is not a 
blocking issue, given

1. The option is off by default. So it's not destructive for the code that 
using default CRT.
2. For users who use this option, they should have knowledge of the difference 
on long double type. There're 2 use scenarios I can think out:
  - Users who have their own CRT libraries. This is the case for our downstream 
compiler.
  - Users who are using freestanding environment or using CRT with their own 
implementation of long double functions.

> In GCC on Windows (and clang in mingw mode), long double is always 80 bit on 
> x86. (On i386, sizeof(long double) == 12, while on x86_64 it's 16.)

How about the alignment? I can see on the i386 Linux case, the alignment is 4, 
I assume it is also 4 for GCC on Windows, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115441

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


[PATCH] D115503: [DebugInfo][Clang] record the access flag for class/struct/union types.

2021-12-12 Thread ChenZheng via Phabricator via cfe-commits
shchenz added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-access.cpp:28
 
+class C {
+public:

Will we generate a redundant flag if we define a private type in the class or a 
public type in the struct/union? Maybe we could add a case for that too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115503

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


[PATCH] D70401: [WIP][RISCV] Implement ilp32e ABI

2021-12-12 Thread Zixuan Wu via Phabricator via cfe-commits
zixuan-wu added a subscriber: pcwang-thead.
zixuan-wu added a comment.

In D70401#3175266 , @khchen wrote:

>> Is it (D70401 ) good enough to solve or 
>> complete rv32e issue?
>
> It need to
>
> 1. disallow ilp32e ABI with D ISA extension. 
> https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/3f81fae0412bb9ad4002a4ade508be7aa5e1599b/riscv-cc.adoc#ilp32e-calling-convention
> 2. emit predefined marco in header (`__riscv_e`)
> 3. markSuperRegs for X16-X31
> 4. update tests after rebase on main.

Nice. If no body objects, @pcwang-thead will take this task and re-draft a 
review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70401

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


[PATCH] D115503: [DebugInfo][Clang] record the access flag for class/struct/union types.

2021-12-12 Thread Esme Yi via Phabricator via cfe-commits
Esme updated this revision to Diff 393789.
Esme retitled this revision from "[DebugInfo] emit DW_AT_accessibility 
attribute for class/struct/union types." to "[DebugInfo][Clang] record the 
access flag for class/struct/union types.".
Esme added a comment.

Thanks! @dblaikie 
Separate into Clang part and LLVM part.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115503

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-access.cpp


Index: clang/test/CodeGenCXX/debug-info-access.cpp
===
--- clang/test/CodeGenCXX/debug-info-access.cpp
+++ clang/test/CodeGenCXX/debug-info-access.cpp
@@ -25,6 +25,38 @@
   void priv_default();
 };
 
+class C {
+public:
+  // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "D",{{.*}} 
flags: DIFlagPublic | DIFlagTypePassByValue,
+  struct D {
+  };
+protected:
+  //CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "E",{{.*}} flags: 
DIFlagProtected | DIFlagTypePassByValue,
+  union E {
+  };
+public:
+  D d;
+  E e;
+};
+
+struct F {
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "G",{{.*}} flags: 
DIFlagPrivate | DIFlagTypePassByValue,
+  union G {
+  };
+public:
+  G g;
+};
+
+union H {
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "I",{{.*}} flags: 
DIFlagPrivate | DIFlagTypePassByValue,
+  class I {
+  };
+public:
+  I i;
+};
+
 union U {
   // CHECK-DAG: !DISubprogram(name: "union_pub_default",{{.*}} line: 
[[@LINE+1]],{{.*}} flags: DIFlagPrototyped,
   void union_pub_default();
@@ -33,7 +65,6 @@
   int union_priv;
 };
 
-
 // CHECK: !DISubprogram(name: "free",
 // CHECK-SAME:  flags: DIFlagPrototyped,
 // CHECK-SAME:  spFlags: DISPFlagDefinition
@@ -42,3 +73,6 @@
 U u;
 A a;
 B b;
+C c;
+F f;
+H h;
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3633,6 +3633,9 @@
 // Record exports it symbols to the containing structure.
 if (CXXRD->isAnonymousStructOrUnion())
 Flags |= llvm::DINode::FlagExportSymbols;
+
+Flags |= getAccessFlag(CXXRD->getAccess(),
+   dyn_cast(CXXRD->getDeclContext()));
   }
 
   llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);


Index: clang/test/CodeGenCXX/debug-info-access.cpp
===
--- clang/test/CodeGenCXX/debug-info-access.cpp
+++ clang/test/CodeGenCXX/debug-info-access.cpp
@@ -25,6 +25,38 @@
   void priv_default();
 };
 
+class C {
+public:
+  // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "D",{{.*}} flags: DIFlagPublic | DIFlagTypePassByValue,
+  struct D {
+  };
+protected:
+  //CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "E",{{.*}} flags: DIFlagProtected | DIFlagTypePassByValue,
+  union E {
+  };
+public:
+  D d;
+  E e;
+};
+
+struct F {
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "G",{{.*}} flags: DIFlagPrivate | DIFlagTypePassByValue,
+  union G {
+  };
+public:
+  G g;
+};
+
+union H {
+private:
+  // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "I",{{.*}} flags: DIFlagPrivate | DIFlagTypePassByValue,
+  class I {
+  };
+public:
+  I i;
+};
+
 union U {
   // CHECK-DAG: !DISubprogram(name: "union_pub_default",{{.*}} line: [[@LINE+1]],{{.*}} flags: DIFlagPrototyped,
   void union_pub_default();
@@ -33,7 +65,6 @@
   int union_priv;
 };
 
-
 // CHECK: !DISubprogram(name: "free",
 // CHECK-SAME:  flags: DIFlagPrototyped,
 // CHECK-SAME:  spFlags: DISPFlagDefinition
@@ -42,3 +73,6 @@
 U u;
 A a;
 B b;
+C c;
+F f;
+H h;
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3633,6 +3633,9 @@
 // Record exports it symbols to the containing structure.
 if (CXXRD->isAnonymousStructOrUnion())
 Flags |= llvm::DINode::FlagExportSymbols;
+
+Flags |= getAccessFlag(CXXRD->getAccess(),
+   dyn_cast(CXXRD->getDeclContext()));
   }
 
   llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115430: [Clang][RISCV] Fix upper bound of RISC-V V type in debug info

2021-12-12 Thread Haocong Lu via Phabricator via cfe-commits
Luhaocong updated this revision to Diff 393788.
Luhaocong added a comment.

re-upload with full context


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115430

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/RISCV/riscv-v-debuginfo.c


Index: clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
===
--- clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
+++ clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
@@ -9,7 +9,7 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, 
DW_OP_con
-// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_mul))
+// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_mul, DW_OP_constu, 1, 
DW_OP_minus))
 
 __rvv_int16mf2_t f2(__rvv_int16mf2_t arg_0, __rvv_int16mf2_t arg_1, int64_t 
arg_2) {
   __rvv_int16mf2_t ret;
@@ -17,7 +17,7 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, 
DW_OP_con
-// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_div))
+// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_div, DW_OP_constu, 1, 
DW_OP_minus))
 
 __rvv_int32mf2_t f3(__rvv_int32mf2_t arg_0, __rvv_int32mf2_t arg_1, int64_t 
arg_2) {
   __rvv_int32mf2_t ret;
@@ -25,4 +25,4 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, 
DW_OP_con
-// DEBUGINFO: stu, 4, DW_OP_div, DW_OP_constu, 2, DW_OP_div))
+// DEBUGINFO: stu, 4, DW_OP_div, DW_OP_constu, 2, DW_OP_div, DW_OP_constu, 1, 
DW_OP_minus))
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -768,7 +768,7 @@
   }
 
   // Element count = (VLENB / SEW) x LMUL
-  SmallVector Expr(
+  SmallVector Expr(
   // The DW_OP_bregx operation has two operands: a register which is
   // specified by an unsigned LEB128 number, followed by a signed 
LEB128
   // offset.
@@ -782,6 +782,8 @@
 Expr.push_back(llvm::dwarf::DW_OP_div);
   else
 Expr.push_back(llvm::dwarf::DW_OP_mul);
+  // Element max index = count - 1
+  Expr.append({llvm::dwarf::DW_OP_constu, 1, llvm::dwarf::DW_OP_minus});
 
   auto *LowerBound =
   llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(


Index: clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
===
--- clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
+++ clang/test/CodeGen/RISCV/riscv-v-debuginfo.c
@@ -9,7 +9,7 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, DW_OP_con
-// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_mul))
+// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_mul, DW_OP_constu, 1, DW_OP_minus))
 
 __rvv_int16mf2_t f2(__rvv_int16mf2_t arg_0, __rvv_int16mf2_t arg_1, int64_t arg_2) {
   __rvv_int16mf2_t ret;
@@ -17,7 +17,7 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, DW_OP_con
-// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_div))
+// DEBUGINFO: stu, 2, DW_OP_div, DW_OP_constu, 2, DW_OP_div, DW_OP_constu, 1, DW_OP_minus))
 
 __rvv_int32mf2_t f3(__rvv_int32mf2_t arg_0, __rvv_int32mf2_t arg_1, int64_t arg_2) {
   __rvv_int32mf2_t ret;
@@ -25,4 +25,4 @@
 }
 
 // !DISubrange(lowerBound: 0, upperBound: !DIExpression(DW_OP_bregx, 7202, 0, DW_OP_con
-// DEBUGINFO: stu, 4, DW_OP_div, DW_OP_constu, 2, DW_OP_div))
+// DEBUGINFO: stu, 4, DW_OP_div, DW_OP_constu, 2, DW_OP_div, DW_OP_constu, 1, DW_OP_minus))
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -768,7 +768,7 @@
   }
 
   // Element count = (VLENB / SEW) x LMUL
-  SmallVector Expr(
+  SmallVector Expr(
   // The DW_OP_bregx operation has two operands: a register which is
   // specified by an unsigned LEB128 number, followed by a signed LEB128
   // offset.
@@ -782,6 +782,8 @@
 Expr.push_back(llvm::dwarf::DW_OP_div);
   else
 Expr.push_back(llvm::dwarf::DW_OP_mul);
+  // Element max index = count - 1
+  Expr.append({llvm::dwarf::DW_OP_constu, 1, llvm::dwarf::DW_OP_minus});
 
   auto *LowerBound =
   llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115430: [Clang][RISCV] Fix upper bound of RISC-V V type in debug info

2021-12-12 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

Could you re-upload diff with full context? You can create that via `git 
format-patch -1 -U999` or `git diff -U99 > mypatch.patch`.

[1] 
https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115430

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


[PATCH] D115604: [Support] Expand `<@>` as the base directory in response files.

2021-12-12 Thread Jack Andersen via Phabricator via cfe-commits
jackoalan updated this revision to Diff 393785.
jackoalan added a comment.

Test coverage for more than one `<@>` per arg.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115604

Files:
  clang/docs/UsersManual.rst
  llvm/lib/Support/CommandLine.cpp
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -784,9 +784,9 @@
 TEST(CommandLineTest, ResponseFiles) {
   vfs::InMemoryFileSystem FS;
 #ifdef _WIN32
-  const char *TestRoot = "C:\\";
+  StringRef TestRoot = "C:\\";
 #else
-  const char *TestRoot = "/";
+  StringRef TestRoot = "/";
 #endif
   FS.setCurrentWorkingDirectory(TestRoot);
 
@@ -796,8 +796,11 @@
  llvm::MemoryBuffer::getMemBuffer("-option_1 -option_2\n"
   "@incdir/resp2\n"
   "-option_3=abcd\n"
-  "@incdir/resp3\n"
-  "-option_4=efjk\n"));
+  "@<@>/incdir/resp3\n"
+  "-option_4=efjk\n"
+  "-option_5=<@>\n"
+  "-option_6=<@>/sub\n"
+  "-option_7=<@>/sub1,<@>/sub2\n"));
 
   // Directory for included file.
   llvm::StringRef IncDir = "incdir";
@@ -807,14 +810,17 @@
   llvm::sys::path::append(IncludedFileName2, IncDir, "resp2");
   FS.addFile(IncludedFileName2, 0,
  MemoryBuffer::getMemBuffer("-option_21 -option_22\n"
-"-option_23=abcd\n"));
+"-option_23=abcd\n"
+"-option_24=<@>\n"
+"-option_25=<@>/sub1,<@>/sub2\n"));
 
   // Create second included response file of second level.
   llvm::SmallString<128> IncludedFileName3;
   llvm::sys::path::append(IncludedFileName3, IncDir, "resp3");
   FS.addFile(IncludedFileName3, 0,
  MemoryBuffer::getMemBuffer("-option_31 -option_32\n"
-"-option_33=abcd\n"));
+"-option_33=abcd\n"
+"-option_34=<@>\n"));
 
   // Prepare 'file' with reference to response file.
   SmallString<128> IncRef;
@@ -828,13 +834,27 @@
   llvm::StringSaver Saver(A);
   ASSERT_TRUE(llvm::cl::ExpandResponseFiles(
   Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, true,
-  /*CurrentDir=*/StringRef(TestRoot), FS));
-  EXPECT_THAT(Argv, testing::Pointwise(
-StringEquality(),
-{"test/test", "-flag_1", "-option_1", "-option_2",
- "-option_21", "-option_22", "-option_23=abcd",
- "-option_3=abcd", "-option_31", "-option_32",
- "-option_33=abcd", "-option_4=efjk", "-flag_2"}));
+  /*CurrentDir=*/TestRoot, FS));
+
+  std::string ExpectedOption24 = ("-option_24=" + TestRoot + "incdir").str();
+  std::string ExpectedOption25 =
+  ("-option_25=" + TestRoot + "incdir/sub1," + TestRoot + "incdir/sub2")
+  .str();
+  std::string ExpectedOption34 = ("-option_34=" + TestRoot + "incdir").str();
+  std::string ExpectedOption5 = ("-option_5=" + TestRoot).str();
+  std::string ExpectedOption6 = ("-option_6=" + TestRoot + "sub").str();
+  std::string ExpectedOption7 =
+  ("-option_7=" + TestRoot + "sub1," + TestRoot + "sub2").str();
+
+  EXPECT_THAT(
+  Argv, testing::Pointwise(
+StringEquality(),
+{"test/test", "-flag_1", "-option_1", "-option_2", "-option_21",
+ "-option_22", "-option_23=abcd", ExpectedOption24.c_str(),
+ ExpectedOption25.c_str(), "-option_3=abcd", "-option_31",
+ "-option_32", "-option_33=abcd", ExpectedOption34.c_str(),
+ "-option_4=efjk", ExpectedOption5.c_str(),
+ ExpectedOption6.c_str(), ExpectedOption7.c_str(), "-flag_2"}));
 }
 
 TEST(CommandLineTest, RecursiveResponseFiles) {
@@ -1045,15 +1065,17 @@
   TempFile ConfigFile(TestCfg, "",
   "# Comment\n"
   "-option_1\n"
+  "-option_2=<@>/dir1\n"
   "@subconfig\n"
-  "-option_3=abcd\n"
-  "-option_4=\\\n"
+  "-option_5=abcd\n"
+  "-option_6=\\\n"
   "cdef\n");
 
   llvm::SmallString<128> TestCfg2;
   llvm::sys::path::append(TestCfg2, TestDir.path(), "subconfig");
   TempFile ConfigFile2(TestCfg2, "",
-

[PATCH] D113372: [Driver] Add CLANG_DEFAULT_PIE_ON_LINUX to emulate GCC --enable-default-pie

2021-12-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 393782.
MaskRay retitled this revision from "[Driver] Add CLANG_DEFAULT_PIE to emulate 
GCC --enable-default-pie" to "[Driver] Add CLANG_DEFAULT_PIE_ON_LINUX to 
emulate GCC --enable-default-pie".
MaskRay edited the summary of this revision.
MaskRay added a comment.

CLANG_DEFAULT_PIE => CLANG_DEFAULT_PIE_ON_LINUX

I have fixed all test/Driver tests in a separate commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113372

Files:
  clang/CMakeLists.txt
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Config/config.h.cmake
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/default-pie.c
  clang/test/Driver/fsanitize.c
  clang/test/Driver/linux-ld.c
  clang/test/lit.cfg.py
  clang/test/lit.site.cfg.py.in
  llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
  utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h

Index: utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h
===
--- utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h
+++ utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h
@@ -22,6 +22,9 @@
 /* Bug report URL. */
 #define BUG_REPORT_URL "https://bugs.llvm.org/;
 
+/* Default to -fPIE and -pie. */
+#define CLANG_DEFAULT_PIE_ON_LINUX 0
+
 /* Default linker to use. */
 #define CLANG_DEFAULT_LINKER ""
 
Index: llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
+++ llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
@@ -9,6 +9,7 @@
   output = "$target_gen_dir/config.h"
   values = [
 "BUG_REPORT_URL=https://bugs.llvm.org/;,
+"CLANG_DEFAULT_PIE_ON_LINUX=0",
 "CLANG_DEFAULT_LINKER=",
 "CLANG_DEFAULT_STD_C=",
 "CLANG_DEFAULT_STD_CXX=",
Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -22,6 +22,7 @@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
 config.clang_arcmt = @CLANG_ENABLE_ARCMT@
+config.clang_default_pie_on_linux = "@CLANG_DEFAULT_PIE_ON_LINUX@"
 config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"
 config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
 config.clang_staticanalyzer_z3 = "@LLVM_WITH_Z3@"
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -121,6 +121,9 @@
 if config.has_plugins and config.llvm_plugin_ext:
 config.available_features.add('plugins')
 
+if config.clang_default_pie_on_linux == '1':
+config.available_features.add('default-pie-on-linux')
+
 # Set available features we allow tests to conditionalize on.
 #
 if config.clang_default_cxx_stdlib != '':
Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -1,4 +1,4 @@
-// UNSUPPORTED: system-windows
+// UNSUPPORTED: system-windows, default-pie-on-linux
 // General tests that ld invocations on Linux targets sane. Note that we use
 // sysroot to make these tests independent of the host system.
 //
Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -1,3 +1,4 @@
+// UNSUPPORTED: default-pie-on-linux
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-trap=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-trap=undefined -fno-sanitize-trap=signed-integer-overflow %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP2
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
Index: clang/test/Driver/default-pie.c
===
--- /dev/null
+++ clang/test/Driver/default-pie.c
@@ -0,0 +1,7 @@
+// REQUIRES: default-pie
+/// Test -DCLANG_DEFAULT_PIE_ON_LINUX=on.
+
+// RUN: %clang -### --target=aarch64-linux-gnu %s 2>&1 | FileCheck %s --check-prefix=PIE2
+
+// PIE2: "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie"
+// PIE2: "-pie"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -663,7 +663,7 @@
 }
 
 bool Linux::isPIEDefault(const llvm::opt::ArgList ) const {
-  return getTriple().isAndroid() || getTriple().isMusl() ||
+  return 

[clang] 5fadb39 - [Driver][test] Make some tests work with CLANG_DEFAULT_PIE_ON_LINUX=on

2021-12-12 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-12-12T16:28:33-08:00
New Revision: 5fadb39e9bc2ceb8bd887b174fc73647920caf79

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

LOG: [Driver][test] Make some tests work with CLANG_DEFAULT_PIE_ON_LINUX=on

Also delete some cross-linux.c tests which are covered by linux-cross.cpp

Added: 


Modified: 
clang/test/Driver/cross-linux.c
clang/test/Driver/env.c
clang/test/Driver/gcc-toolchain.cpp
clang/test/Driver/linux-as.c
clang/test/Driver/mips-as.c
clang/test/Driver/mips-mti.cpp
clang/test/Driver/mips-reduced-toolchain.cpp
clang/test/Driver/ppc-abi.c
clang/test/Driver/riscv32-toolchain.c
clang/test/Driver/riscv64-toolchain.c

Removed: 




diff  --git a/clang/test/Driver/cross-linux.c b/clang/test/Driver/cross-linux.c
index 59f5a97d2d9d2..6bd7de52d4aa4 100644
--- a/clang/test/Driver/cross-linux.c
+++ b/clang/test/Driver/cross-linux.c
@@ -31,75 +31,3 @@
 // RUN:   --gcc-toolchain=%S/Inputs/basic_cross_linux_tree/usr \
 // RUN:   --target=i386-unknown-linux-gnu -m64 \
 // RUN:   | FileCheck --check-prefix=CHECK-X86-64 %s
-//
-// RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
-// RUN:   --gcc-toolchain=%S/Inputs/multilib_32bit_linux_tree/usr \
-// RUN:   --target=i386-unknown-linux \
-// RUN:   --rtlib=platform \
-// RUN:   --sysroot=%S/Inputs/basic_linux_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-MULTI32-I386 %s
-// CHECK-MULTI32-I386: "-cc1" "-triple" "i386-unknown-linux"
-// CHECK-MULTI32-I386: 
"{{.*}}/Inputs/multilib_32bit_linux_tree/usr/lib/gcc/i386-unknown-linux/10.2.0/../../../../i386-unknown-linux/bin{{/|}}as"
 "--32"
-// CHECK-MULTI32-I386: 
"{{.*}}/Inputs/multilib_32bit_linux_tree/usr/lib/gcc/i386-unknown-linux/10.2.0/../../../../i386-unknown-linux/bin{{/|}}ld"
-// CHECK-MULTI32-I386: "--sysroot=[[sysroot:.*/Inputs/basic_linux_tree]]"
-// CHECK-MULTI32-I386: "-m" "elf_i386"
-// CHECK-MULTI32-I386: "crti.o" 
"[[gcc_install:.*/Inputs/multilib_32bit_linux_tree/usr/lib/gcc/i386-unknown-linux/10.2.0]]{{/|}}crtbegin.o"
-// CHECK-MULTI32-I386: "-L[[gcc_install]]"
-// CHECK-MULTI32-I386: 
"-L[[gcc_install]]/../../../../i386-unknown-linux/lib/../lib32"
-// CHECK-MULTI32-I386: "-L[[gcc_install]]/../../../../i386-unknown-linux/lib"
-// CHECK-MULTI32-I386: "-L[[sysroot]]/lib"
-// CHECK-MULTI32-I386: "-L[[sysroot]]/usr/lib"
-//
-// RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
-// RUN:   --gcc-toolchain=%S/Inputs/multilib_32bit_linux_tree/usr \
-// RUN:   --target=x86_64-unknown-linux \
-// RUN:   --rtlib=platform \
-// RUN:   --sysroot=%S/Inputs/basic_linux_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-MULTI32-X86-64 %s
-// CHECK-MULTI32-X86-64: "-cc1" "-triple" "x86_64-unknown-linux"
-// CHECK-MULTI32-X86-64: 
"{{.*}}/Inputs/multilib_32bit_linux_tree/usr/lib/gcc/i386-unknown-linux/10.2.0/../../../../i386-unknown-linux/bin{{/|}}as"
 "--64"
-// CHECK-MULTI32-X86-64: 
"{{.*}}/Inputs/multilib_32bit_linux_tree/usr/lib/gcc/i386-unknown-linux/10.2.0/../../../../i386-unknown-linux/bin{{/|}}ld"
-// CHECK-MULTI32-X86-64: "--sysroot=[[sysroot:.*/Inputs/basic_linux_tree]]"
-// CHECK-MULTI32-X86-64: "-m" "elf_x86_64"
-// CHECK-MULTI32-X86-64: "crti.o" 
"[[gcc_install:.*/Inputs/multilib_32bit_linux_tree/usr/lib/gcc/i386-unknown-linux/10.2.0]]/64{{/|}}crtbegin.o"
-// CHECK-MULTI32-X86-64: "-L[[gcc_install]]/64"
-// CHECK-MULTI32-X86-64: 
"-L[[gcc_install]]/../../../../i386-unknown-linux/lib/../lib64"
-// CHECK-MULTI32-X86-64: "-L[[gcc_install]]/../../../../i386-unknown-linux/lib"
-// CHECK-MULTI32-X86-64: "-L[[sysroot]]/lib"
-// CHECK-MULTI32-X86-64: "-L[[sysroot]]/usr/lib"
-//
-// RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
-// RUN:   --gcc-toolchain=%S/Inputs/multilib_64bit_linux_tree/usr \
-// RUN:   --target=i386-unknown-linux \
-// RUN:   --rtlib=platform \
-// RUN:   --sysroot=%S/Inputs/basic_linux_tree \
-// RUN:   | FileCheck --check-prefix=CHECK-MULTI64-I386 %s
-// CHECK-MULTI64-I386: "-cc1" "-triple" "i386-unknown-linux"
-// CHECK-MULTI64-I386: 
"{{.*}}/Inputs/multilib_64bit_linux_tree/usr/lib/gcc/x86_64-unknown-linux/10.2.0/../../../../x86_64-unknown-linux/bin{{/|}}as"
 "--32"
-// CHECK-MULTI64-I386: 
"{{.*}}/Inputs/multilib_64bit_linux_tree/usr/lib/gcc/x86_64-unknown-linux/10.2.0/../../../../x86_64-unknown-linux/bin{{/|}}ld"
-// CHECK-MULTI64-I386: "--sysroot=[[sysroot:.*/Inputs/basic_linux_tree]]"
-// CHECK-MULTI64-I386: "-m" "elf_i386"
-// CHECK-MULTI64-I386: "crti.o" 
"[[gcc_install:.*/Inputs/multilib_64bit_linux_tree/usr/lib/gcc/x86_64-unknown-linux/10.2.0]]/32{{/|}}crtbegin.o"
-// CHECK-MULTI64-I386: "-L[[gcc_install]]/32"
-// CHECK-MULTI64-I386: 
"-L[[gcc_install]]/../../../../x86_64-unknown-linux/lib/../lib32"
-// 

[PATCH] D113372: [Driver] Add CLANG_DEFAULT_PIE to emulate GCC --enable-default-pie

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



Comment at: clang/CMakeLists.txt:230
 
+option(CLANG_DEFAULT_PIE "Default to -fPIE and -pie (Linux only)" OFF)
+if(CLANG_DEFAULT_PIE)

joerg wrote:
> This option should really be called something like CLANG_DEFAULT_PIE_ON_LINUX 
> or so. It should be explicit from the name that it only effects that 
> toolchain and not all the various toolchains that support PIE.
This name is fine with me. This ecosystem variety probably only happens for 
Linux and other operations systems probably can just switch unconditionally 
(with possibly gated on an os version).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113372

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


[PATCH] D115604: [Support] Expand `<@>` as the base directory in response files.

2021-12-12 Thread Jack Andersen via Phabricator via cfe-commits
jackoalan updated this revision to Diff 393781.
jackoalan added a comment.

Fix ResponseFiles test for Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115604

Files:
  clang/docs/UsersManual.rst
  llvm/lib/Support/CommandLine.cpp
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -784,9 +784,9 @@
 TEST(CommandLineTest, ResponseFiles) {
   vfs::InMemoryFileSystem FS;
 #ifdef _WIN32
-  const char *TestRoot = "C:\\";
+  StringRef TestRoot = "C:\\";
 #else
-  const char *TestRoot = "/";
+  StringRef TestRoot = "/";
 #endif
   FS.setCurrentWorkingDirectory(TestRoot);
 
@@ -796,8 +796,10 @@
  llvm::MemoryBuffer::getMemBuffer("-option_1 -option_2\n"
   "@incdir/resp2\n"
   "-option_3=abcd\n"
-  "@incdir/resp3\n"
-  "-option_4=efjk\n"));
+  "@<@>/incdir/resp3\n"
+  "-option_4=efjk\n"
+  "-option_5=<@>\n"
+  "-option_6=<@>/sub\n"));
 
   // Directory for included file.
   llvm::StringRef IncDir = "incdir";
@@ -807,14 +809,16 @@
   llvm::sys::path::append(IncludedFileName2, IncDir, "resp2");
   FS.addFile(IncludedFileName2, 0,
  MemoryBuffer::getMemBuffer("-option_21 -option_22\n"
-"-option_23=abcd\n"));
+"-option_23=abcd\n"
+"-option_24=<@>\n"));
 
   // Create second included response file of second level.
   llvm::SmallString<128> IncludedFileName3;
   llvm::sys::path::append(IncludedFileName3, IncDir, "resp3");
   FS.addFile(IncludedFileName3, 0,
  MemoryBuffer::getMemBuffer("-option_31 -option_32\n"
-"-option_33=abcd\n"));
+"-option_33=abcd\n"
+"-option_34=<@>\n"));
 
   // Prepare 'file' with reference to response file.
   SmallString<128> IncRef;
@@ -828,13 +832,21 @@
   llvm::StringSaver Saver(A);
   ASSERT_TRUE(llvm::cl::ExpandResponseFiles(
   Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, true,
-  /*CurrentDir=*/StringRef(TestRoot), FS));
-  EXPECT_THAT(Argv, testing::Pointwise(
-StringEquality(),
-{"test/test", "-flag_1", "-option_1", "-option_2",
- "-option_21", "-option_22", "-option_23=abcd",
- "-option_3=abcd", "-option_31", "-option_32",
- "-option_33=abcd", "-option_4=efjk", "-flag_2"}));
+  /*CurrentDir=*/TestRoot, FS));
+
+  std::string ExpectedOption24 = ("-option_24=" + TestRoot + "incdir").str();
+  std::string ExpectedOption34 = ("-option_34=" + TestRoot + "incdir").str();
+  std::string ExpectedOption5 = ("-option_5=" + TestRoot).str();
+  std::string ExpectedOption6 = ("-option_6=" + TestRoot + "sub").str();
+
+  EXPECT_THAT(
+  Argv, testing::Pointwise(
+StringEquality(),
+{"test/test", "-flag_1", "-option_1", "-option_2", "-option_21",
+ "-option_22", "-option_23=abcd", ExpectedOption24.c_str(),
+ "-option_3=abcd", "-option_31", "-option_32",
+ "-option_33=abcd", ExpectedOption34.c_str(), "-option_4=efjk",
+ ExpectedOption5.c_str(), ExpectedOption6.c_str(), "-flag_2"}));
 }
 
 TEST(CommandLineTest, RecursiveResponseFiles) {
@@ -1045,15 +1057,17 @@
   TempFile ConfigFile(TestCfg, "",
   "# Comment\n"
   "-option_1\n"
+  "-option_2=<@>/dir1\n"
   "@subconfig\n"
-  "-option_3=abcd\n"
-  "-option_4=\\\n"
+  "-option_5=abcd\n"
+  "-option_6=\\\n"
   "cdef\n");
 
   llvm::SmallString<128> TestCfg2;
   llvm::sys::path::append(TestCfg2, TestDir.path(), "subconfig");
   TempFile ConfigFile2(TestCfg2, "",
-   "-option_2\n"
+   "-option_3\n"
+   "-option_4=<@>/dir2\n"
"\n"
"   # comment\n");
 
@@ -1071,11 +1085,15 @@
   bool Result = llvm::cl::readConfigFile(ConfigFile.path(), Saver, Argv);
 
   EXPECT_TRUE(Result);
-  EXPECT_EQ(Argv.size(), 4U);
+  EXPECT_EQ(Argv.size(), 6U);
   EXPECT_STREQ(Argv[0], "-option_1");
-  EXPECT_STREQ(Argv[1], "-option_2");
-  

[PATCH] D115604: [Support] Expand `<@>` as the base directory in response files.

2021-12-12 Thread Jack Andersen via Phabricator via cfe-commits
jackoalan updated this revision to Diff 393777.
jackoalan added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add entry to user manual explaining the `<@>` token.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115604

Files:
  clang/docs/UsersManual.rst
  llvm/lib/Support/CommandLine.cpp
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -796,8 +796,10 @@
  llvm::MemoryBuffer::getMemBuffer("-option_1 -option_2\n"
   "@incdir/resp2\n"
   "-option_3=abcd\n"
-  "@incdir/resp3\n"
-  "-option_4=efjk\n"));
+  "@<@>/incdir/resp3\n"
+  "-option_4=efjk\n"
+  "-option_5=<@>\n"
+  "-option_6=<@>/sub\n"));
 
   // Directory for included file.
   llvm::StringRef IncDir = "incdir";
@@ -807,14 +809,16 @@
   llvm::sys::path::append(IncludedFileName2, IncDir, "resp2");
   FS.addFile(IncludedFileName2, 0,
  MemoryBuffer::getMemBuffer("-option_21 -option_22\n"
-"-option_23=abcd\n"));
+"-option_23=abcd\n"
+"-option_24=<@>\n"));
 
   // Create second included response file of second level.
   llvm::SmallString<128> IncludedFileName3;
   llvm::sys::path::append(IncludedFileName3, IncDir, "resp3");
   FS.addFile(IncludedFileName3, 0,
  MemoryBuffer::getMemBuffer("-option_31 -option_32\n"
-"-option_33=abcd\n"));
+"-option_33=abcd\n"
+"-option_34=<@>\n"));
 
   // Prepare 'file' with reference to response file.
   SmallString<128> IncRef;
@@ -829,12 +833,14 @@
   ASSERT_TRUE(llvm::cl::ExpandResponseFiles(
   Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, true,
   /*CurrentDir=*/StringRef(TestRoot), FS));
-  EXPECT_THAT(Argv, testing::Pointwise(
-StringEquality(),
-{"test/test", "-flag_1", "-option_1", "-option_2",
- "-option_21", "-option_22", "-option_23=abcd",
- "-option_3=abcd", "-option_31", "-option_32",
- "-option_33=abcd", "-option_4=efjk", "-flag_2"}));
+  EXPECT_THAT(
+  Argv, testing::Pointwise(
+StringEquality(),
+{"test/test", "-flag_1", "-option_1", "-option_2", "-option_21",
+ "-option_22", "-option_23=abcd", "-option_24=/incdir",
+ "-option_3=abcd", "-option_31", "-option_32",
+ "-option_33=abcd", "-option_34=/incdir", "-option_4=efjk",
+ "-option_5=/", "-option_6=/sub", "-flag_2"}));
 }
 
 TEST(CommandLineTest, RecursiveResponseFiles) {
@@ -1045,15 +1051,17 @@
   TempFile ConfigFile(TestCfg, "",
   "# Comment\n"
   "-option_1\n"
+  "-option_2=<@>/dir1\n"
   "@subconfig\n"
-  "-option_3=abcd\n"
-  "-option_4=\\\n"
+  "-option_5=abcd\n"
+  "-option_6=\\\n"
   "cdef\n");
 
   llvm::SmallString<128> TestCfg2;
   llvm::sys::path::append(TestCfg2, TestDir.path(), "subconfig");
   TempFile ConfigFile2(TestCfg2, "",
-   "-option_2\n"
+   "-option_3\n"
+   "-option_4=<@>/dir2\n"
"\n"
"   # comment\n");
 
@@ -1071,11 +1079,15 @@
   bool Result = llvm::cl::readConfigFile(ConfigFile.path(), Saver, Argv);
 
   EXPECT_TRUE(Result);
-  EXPECT_EQ(Argv.size(), 4U);
+  EXPECT_EQ(Argv.size(), 6U);
   EXPECT_STREQ(Argv[0], "-option_1");
-  EXPECT_STREQ(Argv[1], "-option_2");
-  EXPECT_STREQ(Argv[2], "-option_3=abcd");
-  EXPECT_STREQ(Argv[3], "-option_4=cdef");
+  EXPECT_STREQ(Argv[1],
+   ("-option_2=" + TestDir.path() + "/dir1").str().c_str());
+  EXPECT_STREQ(Argv[2], "-option_3");
+  EXPECT_STREQ(Argv[3],
+   ("-option_4=" + TestDir.path() + "/dir2").str().c_str());
+  EXPECT_STREQ(Argv[4], "-option_5=abcd");
+  EXPECT_STREQ(Argv[5], "-option_6=cdef");
 }
 
 TEST(CommandLineTest, PositionalEatArgsError) {
Index: llvm/lib/Support/CommandLine.cpp
===
--- llvm/lib/Support/CommandLine.cpp

[PATCH] D108366: [clang][deps] Make resource directory deduction configurable

2021-12-12 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

This change causes a test regression on Gentoo (where 
`CLANG_RESOURCE_DIR="../../../../lib/clang/${clang_version}"`):

  FAIL: Clang :: ClangScanDeps/resource_directory.c (1961 of 29550)
   TEST 'Clang :: ClangScanDeps/resource_directory.c' 
FAILED 
  Script:
  --
  : 'RUN: at line 3';   rm -rf 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp
 && mkdir 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp
  : 'RUN: at line 4';   cp 
/var/tmp/portage/sys-devel/clang-14.0.0./work/clang/test/ClangScanDeps/Inputs/resource_directory/*
 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp
  : 'RUN: at line 8';   sed -e "s|CLANG|/our/custom/bin/clang|g" -e 
"s|DIR|/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp|g"

/var/tmp/portage/sys-devel/clang-14.0.0./work/clang/test/ClangScanDeps/Inputs/resource_directory/cdb.json.template
 > 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp/cdb_path.json
  : 'RUN: at line 10';   
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/bin/clang-scan-deps
 -compilation-database 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp/cdb_path.json
 --format experimental-full--resource-dir-recipe modify-compiler-path > 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp/result_path.json
  : 'RUN: at line 12';   cat 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp/result_path.json
 | sed 's:\?:/:g' | /usr/lib/llvm/14/bin/FileCheck 
/var/tmp/portage/sys-devel/clang-14.0.0./work/clang/test/ClangScanDeps/resource_directory.c
 --check-prefix=CHECK-PATH
  : 'RUN: at line 18';   chmod +x 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp/compiler
  : 'RUN: at line 19';   sed -e 
"s|CLANG|/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp/compiler|g"
 -e 
"s|DIR|/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp|g"

/var/tmp/portage/sys-devel/clang-14.0.0./work/clang/test/ClangScanDeps/Inputs/resource_directory/cdb.json.template
 > 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp/cdb_invocation.json
  : 'RUN: at line 21';   
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/bin/clang-scan-deps
 -compilation-database 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp/cdb_invocation.json
 --format experimental-full--resource-dir-recipe invoke-compiler > 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp/result_invocation.json
  : 'RUN: at line 23';   cat 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp/result_invocation.json
 | sed 's:\?:/:g' | /usr/lib/llvm/14/bin/FileCheck 
/var/tmp/portage/sys-devel/clang-14.0.0./work/clang/test/ClangScanDeps/resource_directory.c
 --check-prefix=CHECK-INVOCATION
  --
  Exit Code: 1
  
  Command Output (stderr):
  --
  + : 'RUN: at line 3'
  + rm -rf 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp
  + mkdir 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp
  + : 'RUN: at line 4'
  + cp 
/var/tmp/portage/sys-devel/clang-14.0.0./work/clang/test/ClangScanDeps/Inputs/resource_directory/cdb.json.template
 
/var/tmp/portage/sys-devel/clang-14.0.0./work/clang/test/ClangScanDeps/Inputs/resource_directory/compiler
 
/var/tmp/portage/sys-devel/clang-14.0.0./work/clang/test/ClangScanDeps/Inputs/resource_directory/mod.h
 
/var/tmp/portage/sys-devel/clang-14.0.0./work/clang/test/ClangScanDeps/Inputs/resource_directory/module.modulemap
 
/var/tmp/portage/sys-devel/clang-14.0.0./work/clang/test/ClangScanDeps/Inputs/resource_directory/tu.c
 
/var/tmp/portage/sys-devel/clang-14.0.0./work/x/y/clang-abi_x86_32.x86/test/ClangScanDeps/Output/resource_directory.c.tmp
  + : 'RUN: at line 8'
  + sed -e 

[PATCH] D115441: [X86][MS] Add 80bit long double support for Windows

2021-12-12 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D115441#3187009 , @rnk wrote:

> I seem to recall assuming that Windows `long double` was 64-bits in many, 
> many places. Unfortunately, I have no idea where that could've happened.

Nothing comes to mind for me about that - in _most_ cases, Windows is kinda 
oblivious to `long double`, as nothing in Windows public API uses that type.

However outside of the core OS, any function in the CRT, that uses long 
doubles, is going to be wrong; in the C99 runtime, there's plenty of `long 
double` functions - a separate `-l` suffixed version of most math functions, 
but also more important conversion functions like `strtold`.

> Something that comes to mind immediately is the MSVC name mangler. I don't 
> think that's a blocking issue, but it's something you should be aware of if 
> you want to promote this flag's usage.

Oh, right, I have no familiarity with those aspects and what might break there.

> @mstorsjo, can you advise what GCC does here? I've forgotten how this is 
> supposed to work.

In GCC on Windows (and clang in mingw mode), `long double` is always 80 bit on 
x86. (On i386, `sizeof(long double) == 12`, while on x86_64 it's 16.)

Regarding the initial FPU state, I think the statically linked CRT startup bits 
differ from MSVC in this aspect, so the x87 state is initialized in 80 bit mode.

Then for runtime functions, mingw handles this by providing their own 
(statically linked) reimplementation of essentially all functions that touch 
long doubles. For math and similar, it's pretty straightforward, but for 
printf, it's a bit of a mess since we'd otherwise want to use UCRT's (otherwise 
standards compliant) printfs, but whenever long doubles are involved (very 
rarely in practice, but libc++'s testsuite do exercise them) the mingw provided 
version has to be used.

For mingw on arm (32 and 64) I haven't wanted to introduce any further deviance 
from MSVC, so there it's all identical to plain double.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115441

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


[PATCH] D115168: [clang-format] [PR49298] Sort includes pass will sort inside raw strings

2021-12-12 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG05bea533d1fc: [clang-format] [PR49298] Sort includes pass 
will sort inside raw strings (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115168

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -1045,6 +1045,153 @@
   EXPECT_EQ(Unsorted, sort(Unsorted, "input.cpp", 0));
 }
 
+TEST_F(SortIncludesTest, DisableRawStringLiteralSorting) {
+
+  EXPECT_EQ("const char *t = R\"(\n"
+"#include \n"
+"#include \n"
+")\";",
+sort("const char *t = R\"(\n"
+ "#include \n"
+ "#include \n"
+ ")\";",
+ "test.cxx", 0));
+  EXPECT_EQ("const char *t = R\"x(\n"
+"#include \n"
+"#include \n"
+")x\";",
+sort("const char *t = R\"x(\n"
+ "#include \n"
+ "#include \n"
+ ")x\";",
+ "test.cxx", 0));
+  EXPECT_EQ("const char *t = R\"xyz(\n"
+"#include \n"
+"#include \n"
+")xyz\";",
+sort("const char *t = R\"xyz(\n"
+ "#include \n"
+ "#include \n"
+ ")xyz\";",
+ "test.cxx", 0));
+
+  EXPECT_EQ("#include \n"
+"#include \n"
+"const char *t = R\"(\n"
+"#include \n"
+"#include \n"
+")\";\n"
+"#include \n"
+"#include \n"
+"const char *t = R\"x(\n"
+"#include \n"
+"#include \n"
+")x\";\n"
+"#include \n"
+"#include \n"
+"const char *t = R\"xyz(\n"
+"#include \n"
+"#include \n"
+")xyz\";\n"
+"#include \n"
+"#include ",
+sort("#include \n"
+ "#include \n"
+ "const char *t = R\"(\n"
+ "#include \n"
+ "#include \n"
+ ")\";\n"
+ "#include \n"
+ "#include \n"
+ "const char *t = R\"x(\n"
+ "#include \n"
+ "#include \n"
+ ")x\";\n"
+ "#include \n"
+ "#include \n"
+ "const char *t = R\"xyz(\n"
+ "#include \n"
+ "#include \n"
+ ")xyz\";\n"
+ "#include \n"
+ "#include ",
+ "test.cc", 4));
+
+  EXPECT_EQ("const char *t = R\"AMZ029amz(\n"
+"#include \n"
+"#include \n"
+")AMZ029amz\";",
+sort("const char *t = R\"AMZ029amz(\n"
+ "#include \n"
+ "#include \n"
+ ")AMZ029amz\";",
+ "test.cxx", 0));
+
+  EXPECT_EQ("const char *t = R\"-AMZ029amz(\n"
+"#include \n"
+"#include \n"
+")-AMZ029amz\";",
+sort("const char *t = R\"-AMZ029amz(\n"
+ "#include \n"
+ "#include \n"
+ ")-AMZ029amz\";",
+ "test.cxx", 0));
+
+  EXPECT_EQ("const char *t = R\"AMZ029amz-(\n"
+"#include \n"
+"#include \n"
+")AMZ029amz-\";",
+sort("const char *t = R\"AMZ029amz-(\n"
+ "#include \n"
+ "#include \n"
+ ")AMZ029amz-\";",
+ "test.cxx", 0));
+
+  EXPECT_EQ("const char *t = R\"AM|029amz-(\n"
+"#include \n"
+"#include \n"
+")AM|029amz-\";",
+sort("const char *t = R\"AM|029amz-(\n"
+ "#include \n"
+ "#include \n"
+ ")AM|029amz-\";",
+ "test.cxx", 0));
+
+  EXPECT_EQ("const char *t = R\"AM[029amz-(\n"
+"#include \n"
+"#include \n"
+")AM[029amz-\";",
+sort("const char *t = R\"AM[029amz-(\n"
+ "#include \n"
+ "#include \n"
+ ")AM[029amz-\";",
+ "test.cxx", 0));
+
+  EXPECT_EQ("const char *t = R\"AM]029amz-(\n"
+"#include \n"
+"#include \n"
+")AM]029amz-\";",
+sort("const char *t = R\"AM]029amz-(\n"
+ "#include \n"
+ "#include \n"
+ ")AM]029amz-\";",
+ "test.cxx", 0));
+
+#define X "AMZ029amz{}+!%*=_:;',.<>|/?#~-$"
+
+  EXPECT_EQ("const char *t = R\"" X "(\n"
+"#include \n"
+"#include 

[clang] 05bea53 - [clang-format] [PR49298] Sort includes pass will sort inside raw strings

2021-12-12 Thread via cfe-commits

Author: mydeveloperday
Date: 2021-12-12T17:00:43Z
New Revision: 05bea533d1fc1bcd63ccb84df9d0edab9701ad70

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

LOG: [clang-format] [PR49298] Sort includes pass will sort inside raw strings

https://github.com/llvm/llvm-project/issues/48642

clang-format does not respect raw string literals when sorting includes

```
const char *RawStr = R"(
)";
```

Running clang-format over with SortIncludes enabled transforms this code to:

```
const char *RawStr = R"(
)";
```
The following code tries to minimize this impact during IncludeSorting, by 
treating R"( and )" as equivalent of // clang-format off/on

Reviewed By: HazardyKnusperkeks, curdeius

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

Fixes #48642

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/unittests/Format/SortIncludesTest.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 17de1075aeaa4..8fb1fa4d618fc 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2586,12 +2586,31 @@ tooling::Replacements sortCppIncludes(const FormatStyle 
, StringRef Code,
   bool MainIncludeFound = false;
   bool FormattingOff = false;
 
+  llvm::Regex RawStringRegex(
+  "R\"(([\\[A-Za-z0-9_{}#<>%:;.?*+/^&\\$|~!=,'\\-]|])*)\\(");
+  SmallVector RawStringMatches;
+  std::string RawStringTermination = ")\"";
+
   for (;;) {
 auto Pos = Code.find('\n', SearchFrom);
 StringRef Line =
 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
 
 StringRef Trimmed = Line.trim();
+
+// #includes inside raw string literals need to be ignored.
+// or we will sort the contents of the string.
+// Skip past until we think we are at the rawstring literal close.
+if (RawStringRegex.match(Trimmed, )) {
+  std::string CharSequence = RawStringMatches[1].str();
+  RawStringTermination = ")" + CharSequence + "\"";
+  FormattingOff = true;
+}
+
+if (Trimmed.contains(RawStringTermination)) {
+  FormattingOff = false;
+}
+
 if (Trimmed == "// clang-format off" || Trimmed == "/* clang-format off 
*/")
   FormattingOff = true;
 else if (Trimmed == "// clang-format on" ||

diff  --git a/clang/unittests/Format/SortIncludesTest.cpp 
b/clang/unittests/Format/SortIncludesTest.cpp
index 4efeb96124bf4..1d215af715382 100644
--- a/clang/unittests/Format/SortIncludesTest.cpp
+++ b/clang/unittests/Format/SortIncludesTest.cpp
@@ -1045,6 +1045,153 @@ TEST_F(SortIncludesTest, 
DisableFormatDisablesIncludeSorting) {
   EXPECT_EQ(Unsorted, sort(Unsorted, "input.cpp", 0));
 }
 
+TEST_F(SortIncludesTest, DisableRawStringLiteralSorting) {
+
+  EXPECT_EQ("const char *t = R\"(\n"
+"#include \n"
+"#include \n"
+")\";",
+sort("const char *t = R\"(\n"
+ "#include \n"
+ "#include \n"
+ ")\";",
+ "test.cxx", 0));
+  EXPECT_EQ("const char *t = R\"x(\n"
+"#include \n"
+"#include \n"
+")x\";",
+sort("const char *t = R\"x(\n"
+ "#include \n"
+ "#include \n"
+ ")x\";",
+ "test.cxx", 0));
+  EXPECT_EQ("const char *t = R\"xyz(\n"
+"#include \n"
+"#include \n"
+")xyz\";",
+sort("const char *t = R\"xyz(\n"
+ "#include \n"
+ "#include \n"
+ ")xyz\";",
+ "test.cxx", 0));
+
+  EXPECT_EQ("#include \n"
+"#include \n"
+"const char *t = R\"(\n"
+"#include \n"
+"#include \n"
+")\";\n"
+"#include \n"
+"#include \n"
+"const char *t = R\"x(\n"
+"#include \n"
+"#include \n"
+")x\";\n"
+"#include \n"
+"#include \n"
+"const char *t = R\"xyz(\n"
+"#include \n"
+"#include \n"
+")xyz\";\n"
+"#include \n"
+"#include ",
+sort("#include \n"
+ "#include \n"
+ "const char *t = R\"(\n"
+ "#include \n"
+ "#include \n"
+ ")\";\n"
+ "#include \n"
+ "#include \n"
+ "const char *t = R\"x(\n"
+ "#include \n"
+ "#include \n"
+ ")x\";\n"
+ "#include \n"
+ "#include \n"
+ "const char *t = R\"xyz(\n"
+ "#include \n"
+ "#include \n"
+ ")xyz\";\n"
+ "#include \n"
+ 

[PATCH] D115103: Leak Sanitizer port to Windows

2021-12-12 Thread Clemens Wasser via Phabricator via cfe-commits
clemenswasser updated this revision to Diff 393750.
clemenswasser added a comment.
Herald added subscribers: luke957, s.egerton, simoncook.

Implement ProcessGlobalRegions
Fix Interceptors for Windows


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

https://reviews.llvm.org/D115103

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/lsan/CMakeLists.txt
  compiler-rt/lib/lsan/lsan.h
  compiler-rt/lib/lsan/lsan_allocator.h
  compiler-rt/lib/lsan/lsan_common.cpp
  compiler-rt/lib/lsan/lsan_common.h
  compiler-rt/lib/lsan/lsan_common_win.cpp
  compiler-rt/lib/lsan/lsan_interceptors.cpp
  compiler-rt/lib/lsan/lsan_win.cpp
  compiler-rt/lib/lsan/lsan_win.h

Index: compiler-rt/lib/lsan/lsan_win.h
===
--- /dev/null
+++ compiler-rt/lib/lsan/lsan_win.h
@@ -0,0 +1,41 @@
+//=-- lsan_win.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 LeakSanitizer.
+// Standalone LSan RTL code common to Windows systems.
+//
+//===-===//
+
+#ifndef LSAN_WINDOWS_H
+#define LSAN_WINDOWS_H
+
+#include "lsan_thread.h"
+#include "sanitizer_common/sanitizer_platform.h"
+
+#if !SANITIZER_WINDOWS
+#  error "lsan_win.h is used only on Windows systems (SANITIZER_WINDOWS)"
+#endif
+
+namespace __sanitizer {
+struct DTLS;
+}
+
+namespace __lsan {
+
+class ThreadContext final : public ThreadContextLsanBase {
+ public:
+  explicit ThreadContext(int tid);
+  void OnStarted(void *arg) override;
+};
+
+void ThreadStart(u32 tid, tid_t os_id,
+ ThreadType thread_type = ThreadType::Regular);
+
+}  // namespace __lsan
+
+#endif  // LSAN_WINDOWS_H
Index: compiler-rt/lib/lsan/lsan_win.cpp
===
--- /dev/null
+++ compiler-rt/lib/lsan/lsan_win.cpp
@@ -0,0 +1,106 @@
+//=-- lsan_win.cpp ---===//
+//
+// 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 LeakSanitizer.
+// Standalone LSan RTL code common to POSIX-like systems.
+//
+//===-===//
+
+#include "sanitizer_common/sanitizer_platform.h"
+
+#if SANITIZER_WINDOWS
+#  include "lsan.h"
+#  include "lsan_allocator.h"
+#  include "sanitizer_common/sanitizer_stacktrace.h"
+#  include "sanitizer_common/sanitizer_tls_get_addr.h"
+
+namespace __lsan {
+
+ThreadContext::ThreadContext(int tid) : ThreadContextLsanBase(tid) {}
+
+struct OnStartedArgs {
+  uptr stack_begin;
+  uptr stack_end;
+  uptr cache_begin;
+  uptr cache_end;
+  uptr tls_begin;
+  uptr tls_end;
+};
+
+void ThreadContext::OnStarted(void *arg) {
+  auto args = reinterpret_cast(arg);
+  stack_begin_ = args->stack_begin;
+  stack_end_ = args->stack_end;
+  cache_begin_ = args->cache_begin;
+  cache_end_ = args->cache_end;
+}
+
+void ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type) {
+  OnStartedArgs args;
+  uptr stack_size = 0;
+  uptr tls_size = 0;
+  GetThreadStackAndTls(tid == kMainTid, _begin, _size,
+   _begin, _size);
+  args.stack_end = args.stack_begin + stack_size;
+  args.tls_end = args.tls_begin + tls_size;
+  GetAllocatorCacheRange(_begin, _end);
+  ThreadContextLsanBase::ThreadStart(tid, os_id, thread_type, );
+}
+
+bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
+   uptr *tls_begin, uptr *tls_end, uptr *cache_begin,
+   uptr *cache_end, DTLS **dtls) {
+  ThreadContext *context = static_cast(
+  GetThreadRegistryLocked()->FindThreadContextByOsIDLocked(os_id));
+  if (!context)
+return false;
+  *stack_begin = context->stack_begin();
+  *stack_end = context->stack_end();
+  *cache_begin = context->cache_begin();
+  *cache_end = context->cache_end();
+  *dtls = 0;
+  return true;
+}
+
+void InitializeMainThread() {
+  u32 tid = ThreadCreate(kMainTid, true);
+  CHECK_EQ(tid, kMainTid);
+  ThreadStart(tid, GetTid());
+}
+
+static void OnStackUnwind(const SignalContext , const void *,
+  BufferedStackTrace *stack) {
+  stack->Unwind(StackTrace::GetNextInstructionPc(sig.pc), sig.bp, sig.context,
+common_flags()->fast_unwind_on_fatal);
+}
+
+void LsanOnDeadlySignal(int signo, void *siginfo, void *context) {
+