[PATCH] D46300: [Clang] Implement function attribute no_stack_protector.

2018-05-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 145988.
manojgupta added a comment.

Updated test case for error msg with arguments.
Updated the documentation.


Repository:
  rC Clang

https://reviews.llvm.org/D46300

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/stack-protector.c
  test/Sema/no_stack_protector.c

Index: test/Sema/no_stack_protector.c
===
--- /dev/null
+++ test/Sema/no_stack_protector.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void __attribute__((no_stack_protector)) foo() {}
+int __attribute__((no_stack_protector)) var; // expected-warning {{'no_stack_protector' attribute only applies to functions}}
+void  __attribute__((no_stack_protector(2))) bar() {} // expected-error {{'no_stack_protector' attribute takes no arguments}}
Index: test/CodeGen/stack-protector.c
===
--- test/CodeGen/stack-protector.c
+++ test/CodeGen/stack-protector.c
@@ -22,6 +22,14 @@
   printf("%s\n", a);
 }
 
+// DEF: define {{.*}}void @test2(i8* %msg) #[[B:.*]] {
+__attribute__((no_stack_protector))
+void test2(const char *msg) {
+  char a[strlen(msg) + 1];
+  strcpy(a, msg);
+  printf("%s\n", a);
+}
+
 // NOSSP-NOT: attributes #[[A]] = {{.*}} ssp
 // SSP: attributes #[[A]] = {{.*}} ssp{{ }}
 // SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong
@@ -33,3 +41,15 @@
 // SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp{{ }}
 // SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong
 // SAFESTACK-SSPREQ: attributes #[[A]] = {{.*}} safestack sspreq
+
+// NOSSP-NOT: attributes #[[B]] = {{.*}} ssp
+// SSP-NOT: attributes #[[B]] = {{.*}} ssp{{ }}
+// SSPSTRONG-NOT: attributes #[[B]] = {{.*}} sspstrong
+// SSPREQ-NOT: attributes #[[B]] = {{.*}} sspreq
+
+// SAFESTACK-SSP: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSP-NOT: attributes #[[B]] = {{.*}} safestack ssp{{ }}
+// SAFESTACK-SSPSTRONG: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPSTRONG-NOT: attributes #[[B]] = {{.*}} safestack sspstrong
+// SAFESTACK-SSPREQ: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPREQ-NOT: attributes #[[B]] = {{.*}} safestack sspreq
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6230,6 +6230,10 @@
   case AttributeList::AT_NoInstrumentFunction: // Interacts with -pg.
 handleSimpleAttribute(S, D, AL);
 break;
+  case AttributeList::AT_NoStackProtector:
+// Interacts with -fstack-protector options.
+handleSimpleAttribute(S, D, AL);
+break;
   case AttributeList::AT_StdCall:
   case AttributeList::AT_CDecl:
   case AttributeList::AT_FastCall:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1142,12 +1142,14 @@
   if (!hasUnwindExceptions(LangOpts))
 B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (LangOpts.getStackProtector() == LangOptions::SSPOn)
-B.addAttribute(llvm::Attribute::StackProtect);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
-B.addAttribute(llvm::Attribute::StackProtectStrong);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
-B.addAttribute(llvm::Attribute::StackProtectReq);
+  if (!D || !D->hasAttr()) {
+if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+  B.addAttribute(llvm::Attribute::StackProtect);
+else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
+  B.addAttribute(llvm::Attribute::StackProtectStrong);
+else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
+  B.addAttribute(llvm::Attribute::StackProtectReq);
+  }
 
   if (!D) {
 // If we don't have a declaration to control inlining, the function isn't
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -2740,6 +2740,28 @@
   }];
 }
 
+def NoStackProtectorDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``__attribute__((no_stack_protector))`` attribute which disables
+the stack protector on the specified function. This attribute is useful for
+selectively disabling the stack protector on some functions when building with
+``-fstack-protector`` compiler option.
+
+For example, it disables the stack protector for the function ``foo`` but function
+``bar`` will still be built with the stack protector with the ``-fstack-protector``
+option.
+
+.. code-block:: c
+
+int __attribute__((no_stack_protector))
+foo (int x); // stack protection will be disabled for foo.
+
+int bar(int y); // bar can be built with the stack protector.
+
+}];
+}
+

[PATCH] D46300: [Clang] Implement function attribute no_stack_protector.

2018-05-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D46300



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


[PATCH] D46300: [Clang] Implement function attribute no_stack_protector.

2018-05-09 Thread Manoj Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC331925: [Clang] Implement function attribute 
no_stack_protector. (authored by manojgupta, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46300?vs=145988&id=146008#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46300

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/stack-protector.c
  test/Sema/no_stack_protector.c

Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -2740,6 +2740,28 @@
   }];
 }
 
+def NoStackProtectorDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``__attribute__((no_stack_protector))`` attribute which disables
+the stack protector on the specified function. This attribute is useful for
+selectively disabling the stack protector on some functions when building with
+``-fstack-protector`` compiler option.
+
+For example, it disables the stack protector for the function ``foo`` but function
+``bar`` will still be built with the stack protector with the ``-fstack-protector``
+option.
+
+.. code-block:: c
+
+int __attribute__((no_stack_protector))
+foo (int x); // stack protection will be disabled for foo.
+
+int bar(int y); // bar can be built with the stack protector.
+
+}];
+}
+
 def NotTailCalledDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1495,6 +1495,12 @@
   let Documentation = [NotTailCalledDocs];
 }
 
+def NoStackProtector : InheritableAttr {
+  let Spellings = [Clang<"no_stack_protector">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [NoStackProtectorDocs];
+}
+
 def NoThrow : InheritableAttr {
   let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
   let Subjects = SubjectList<[Function]>;
Index: test/Sema/no_stack_protector.c
===
--- test/Sema/no_stack_protector.c
+++ test/Sema/no_stack_protector.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void __attribute__((no_stack_protector)) foo() {}
+int __attribute__((no_stack_protector)) var; // expected-warning {{'no_stack_protector' attribute only applies to functions}}
+void  __attribute__((no_stack_protector(2))) bar() {} // expected-error {{'no_stack_protector' attribute takes no arguments}}
Index: test/CodeGen/stack-protector.c
===
--- test/CodeGen/stack-protector.c
+++ test/CodeGen/stack-protector.c
@@ -22,6 +22,14 @@
   printf("%s\n", a);
 }
 
+// DEF: define {{.*}}void @test2(i8* %msg) #[[B:.*]] {
+__attribute__((no_stack_protector))
+void test2(const char *msg) {
+  char a[strlen(msg) + 1];
+  strcpy(a, msg);
+  printf("%s\n", a);
+}
+
 // NOSSP-NOT: attributes #[[A]] = {{.*}} ssp
 // SSP: attributes #[[A]] = {{.*}} ssp{{ }}
 // SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong
@@ -33,3 +41,15 @@
 // SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp{{ }}
 // SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong
 // SAFESTACK-SSPREQ: attributes #[[A]] = {{.*}} safestack sspreq
+
+// NOSSP-NOT: attributes #[[B]] = {{.*}} ssp
+// SSP-NOT: attributes #[[B]] = {{.*}} ssp{{ }}
+// SSPSTRONG-NOT: attributes #[[B]] = {{.*}} sspstrong
+// SSPREQ-NOT: attributes #[[B]] = {{.*}} sspreq
+
+// SAFESTACK-SSP: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSP-NOT: attributes #[[B]] = {{.*}} safestack ssp{{ }}
+// SAFESTACK-SSPSTRONG: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPSTRONG-NOT: attributes #[[B]] = {{.*}} safestack sspstrong
+// SAFESTACK-SSPREQ: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPREQ-NOT: attributes #[[B]] = {{.*}} safestack sspreq
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1142,12 +1142,14 @@
   if (!hasUnwindExceptions(LangOpts))
 B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (LangOpts.getStackProtector() == LangOptions::SSPOn)
-B.addAttribute(llvm::Attribute::StackProtect);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
-B.addAttribute(llvm::Attribute::StackProtectStrong);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
-B.addAttribute(llvm::Attribute::StackProtectReq);
+  if (!D || !D->hasAttr()) {
+if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+  B.addAttribute(llvm::Attribute::StackProtect);
+else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
+  B.addAttribute(llvm::A

[PATCH] D51440: [ToolChains] Link to compiler-rt with -L + -l when possible

2018-08-29 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Just a minor comment regarding test cases: Since you are adding both -L/path/ 
and -l,  the test cases should be updated to  check for the -L/path/ 
argument as well.


Repository:
  rC Clang

https://reviews.llvm.org/D51440



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


[PATCH] D51440: [ToolChains] Link to compiler-rt with -L + -l when possible

2018-08-29 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

In https://reviews.llvm.org/D51440#1217910, @mstorsjo wrote:

> In https://reviews.llvm.org/D51440#1217839, @manojgupta wrote:
>
> > Just a minor comment regarding test cases: Since you are adding both 
> > -L/path/ and -l,  the test cases should be updated to  check for 
> > the -L/path/ argument as well.
>
>
> I guess I could do that, although we don't know the path in the test, so we 
> can only check for `-L.*`.


You can add a testcase that passes a known path via -resource-dir=path argument 
similar to --sysroot argument.


Repository:
  rC Clang

https://reviews.llvm.org/D51440



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


[PATCH] D51713: Support -fno-omit-frame-pointer with -pg.

2018-09-12 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

What is the call generated with -pg for AMR32, __gnu_mcount_nc or _mount? 
__gnu_mcount_nc  with "-pg" is known to be broken ( 
https://bugs.llvm.org/show_bug.cgi?id=33845)


Repository:
  rC Clang

https://reviews.llvm.org/D51713



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


[PATCH] D51713: Support -fno-omit-frame-pointer with -pg.

2018-09-12 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

In https://reviews.llvm.org/D51713#1232497, @srhines wrote:

> In https://reviews.llvm.org/D51713#1232414, @manojgupta wrote:
>
> > What is the call generated with -pg for AMR32, __gnu_mcount_nc or _mount? 
> > __gnu_mcount_nc  with "-pg" is known to be broken ( 
> > https://bugs.llvm.org/show_bug.cgi?id=33845)
>
>
> I CCed myself on that issue as we are trying to do a better job of supporting 
> code coverage, but I don't think this bug is relevant for this patch.
>
> Unless there are any additional reviews, I will likely submit this patch in a 
> few hours.


Yes, Submitting this patch is totally fine, I just wanted to warn you about the 
potential issue you may run into with "-pg" and ARM32.


Repository:
  rC Clang

https://reviews.llvm.org/D51713



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


[PATCH] D34357: [Clang] Handle interaction of -pg and no_instrument_function attribute.

2017-06-19 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.

Disable generation of counting-function attribute if no_instrument_function
attribute is present in function.
Interaction between -pg and no_instrument_function is the desired behavior
and matches gcc as well.
This is required for fixing a crash in Linux kernel when function tracing
is enabled.

Fixes PR33515.


https://reviews.llvm.org/D34357

Files:
  lib/CodeGen/CodeGenFunction.cpp
  test/CodeGen/mcount.c


Index: test/CodeGen/mcount.c
===
--- test/CodeGen/mcount.c
+++ test/CodeGen/mcount.c
@@ -1,18 +1,18 @@
 // RUN: %clang_cc1 -pg -triple i386-unknown-unknown -emit-llvm -o - %s | 
FileCheck %s
 // RUN: %clang_cc1 -pg -triple i386-unknown-unknown -emit-llvm -O2 -o - %s | 
FileCheck %s
-// RUN: %clang_cc1 -pg -triple powerpc-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple powerpc64-unknown-gnu-linux -emit-llvm -o - %s 
| FileCheck -check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple powerpc64le-unknown-gnu-linux -emit-llvm -o - 
%s | FileCheck -check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple i386-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple x86_64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple arm-netbsd-eabi -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple aarch64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple mips-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple powerpc-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple powerpc64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple powerpc64le-netbsd -emit-llvm -o - %s | 
FileCheck -check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple sparc-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECK-PREFIXED %s
-// RUN: %clang_cc1 -pg -triple sparc64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECK-PREFIXED %s
+// RUN: %clang_cc1 -pg -triple powerpc-unknown-gnu-linux -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple powerpc64-unknown-gnu-linux -emit-llvm -o - %s 
| FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple powerpc64le-unknown-gnu-linux -emit-llvm -o - 
%s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple i386-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple x86_64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple arm-netbsd-eabi -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple aarch64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple mips-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple powerpc-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple powerpc64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple powerpc64le-netbsd -emit-llvm -o - %s | 
FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple sparc-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple sparc64-netbsd -emit-llvm -o - %s | FileCheck 
-check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s -check-prefix=NO-MCOUNT
 
 int bar(void) {
@@ -23,10 +23,17 @@
   return bar();
 }
 
-int main(void) {
+int __attribute__((no_instrument_function)) no_instrument(void) {
   return foo();
 }
 
-// CHECK: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="mcount"{{.*}} }
-// CHECK-PREFIXED: attributes #{{[0-9]+}} = { 
{{.*}}"counting-function"="_mcount"{{.*}} }
+int main(void) {
+  return no_instrument();
+}
+
+// CHECK: attributes #0 = { {{.*}}"counting-function"="mcount"{{.*}} }
+// CHECK: attributes #1 = { {{.*}} }
+// CHECK-PREFIXED: attributes #0 = { {{.*}}"counting-function"="_mcount"{{.*}} 
}
+// CHECK-PREFIXED: attributes #1 = { {{.*}} }
 // NO-MCOUNT-NOT: attributes #{{[0-9]}} = { {{.*}}"counting-function"={{.*}} }
+// NO-MCOUNT1-NOT: attributes #1 = { {{.*}}"counting-function"={{.*}} }
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -887,8 +887,10 @@
   if (CGM.g

[PATCH] D34357: [Clang] Handle interaction of -pg and no_instrument_function attribute.

2017-06-19 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Thanks for the quick review.


https://reviews.llvm.org/D34357



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


[PATCH] D34426: [Driver] Do not increment ActionCount for precompiled headers.

2017-06-20 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.

If a .h file is specifed as input, it gets compiled to a PCH file.
Handle the PCH Action and do not throw the error:
"cannot specify -o when generating multiple output files"

This fixes PR33533.


https://reviews.llvm.org/D34426

Files:
  lib/Driver/Driver.cpp


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -76,6 +76,7 @@
 #if LLVM_ON_UNIX
 #include  // getpid
 #endif
+#include 
 
 using namespace clang::driver;
 using namespace clang;
@@ -2759,7 +2760,7 @@
   if (FinalOutput) {
 unsigned NumOutputs = 0;
 for (const Action *A : C.getActions())
-  if (A->getType() != types::TY_Nothing)
+  if (A->getType() != types::TY_Nothing && A->getType() != types::TY_PCH)
 ++NumOutputs;
 
 if (NumOutputs > 1) {


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -76,6 +76,7 @@
 #if LLVM_ON_UNIX
 #include  // getpid
 #endif
+#include 
 
 using namespace clang::driver;
 using namespace clang;
@@ -2759,7 +2760,7 @@
   if (FinalOutput) {
 unsigned NumOutputs = 0;
 for (const Action *A : C.getActions())
-  if (A->getType() != types::TY_Nothing)
+  if (A->getType() != types::TY_Nothing && A->getType() != types::TY_PCH)
 ++NumOutputs;
 
 if (NumOutputs > 1) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34426: [Driver] Do not increment ActionCount for precompiled headers.

2017-06-20 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 103280.

https://reviews.llvm.org/D34426

Files:
  lib/Driver/Driver.cpp


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -2759,7 +2759,7 @@
   if (FinalOutput) {
 unsigned NumOutputs = 0;
 for (const Action *A : C.getActions())
-  if (A->getType() != types::TY_Nothing)
+  if (A->getType() != types::TY_Nothing && A->getType() != types::TY_PCH)
 ++NumOutputs;
 
 if (NumOutputs > 1) {


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -2759,7 +2759,7 @@
   if (FinalOutput) {
 unsigned NumOutputs = 0;
 for (const Action *A : C.getActions())
-  if (A->getType() != types::TY_Nothing)
+  if (A->getType() != types::TY_Nothing && A->getType() != types::TY_PCH)
 ++NumOutputs;
 
 if (NumOutputs > 1) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34426: [Driver] Do not increment ActionCount for precompiled headers.

2017-06-20 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

I am not sure what is the expected behavior. Maybe clang is doing the right 
thing in rejecting. 
But, this creates an issue in ChromeOS land where a package fails to build with 
clang (https://bugs.chromium.org/p/chromium/issues/detail?id=735206).


https://reviews.llvm.org/D34426



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


[PATCH] D43995: Do not generate calls to fentry with __attribute__((no_instrument_function))

2018-03-01 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.
manojgupta added reviewers: hfinkel, rengolin, srhines, chandlerc.

Currently only calls to mcount were suppressed with
no_instrument_function attribute.
Linux kernel requires that calls to fentry should also not be
generated.
This is an extended fix for PR PR33515.


Repository:
  rC Clang

https://reviews.llvm.org/D43995

Files:
  lib/CodeGen/CodeGenFunction.cpp
  test/CodeGen/fentry.c


Index: test/CodeGen/fentry.c
===
--- test/CodeGen/fentry.c
+++ test/CodeGen/fentry.c
@@ -7,5 +7,12 @@
   return 0;
 }
 
-//CHECK: attributes #{{[0-9]+}} = { {{.*}}"fentry-call"="true"{{.*}} }
-//NOPG-NOT: attributes #{{[0-9]+}} = { {{.*}}"fentry-call"{{.*}} }
+int __attribute__((no_instrument_function)) no_instrument(void) {
+  return foo();
+}
+
+//CHECK: attributes #0 = { {{.*}}"fentry-call"="true"{{.*}} }
+//CHECK: attributes #1 = { {{.*}} }
+//CHECK-NOT: attributes #1 = { {{.*}}"fentry-call"="true"{{.*}} }
+//NOPG-NOT: attributes #0 = { {{.*}}"fentry-call"{{.*}} }
+//NOPG-NOT: attributes #1 = { {{.*}}"fentry-call"{{.*}} }
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1016,10 +1016,12 @@
   // The attribute "counting-function" is set to mcount function name which is
   // architecture dependent.
   if (CGM.getCodeGenOpts().InstrumentForProfiling) {
-if (CGM.getCodeGenOpts().CallFEntry)
-  Fn->addFnAttr("fentry-call", "true");
-else {
-  if (!CurFuncDecl || !CurFuncDecl->hasAttr()) {
+// Calls to fentry/mcount should not be generated if function has
+// the no_instrument_function attribute.
+if (!CurFuncDecl || !CurFuncDecl->hasAttr()) {
+  if (CGM.getCodeGenOpts().CallFEntry)
+Fn->addFnAttr("fentry-call", "true");
+  else {
 Fn->addFnAttr("instrument-function-entry-inlined",
   getTarget().getMCountName());
   }


Index: test/CodeGen/fentry.c
===
--- test/CodeGen/fentry.c
+++ test/CodeGen/fentry.c
@@ -7,5 +7,12 @@
   return 0;
 }
 
-//CHECK: attributes #{{[0-9]+}} = { {{.*}}"fentry-call"="true"{{.*}} }
-//NOPG-NOT: attributes #{{[0-9]+}} = { {{.*}}"fentry-call"{{.*}} }
+int __attribute__((no_instrument_function)) no_instrument(void) {
+  return foo();
+}
+
+//CHECK: attributes #0 = { {{.*}}"fentry-call"="true"{{.*}} }
+//CHECK: attributes #1 = { {{.*}} }
+//CHECK-NOT: attributes #1 = { {{.*}}"fentry-call"="true"{{.*}} }
+//NOPG-NOT: attributes #0 = { {{.*}}"fentry-call"{{.*}} }
+//NOPG-NOT: attributes #1 = { {{.*}}"fentry-call"{{.*}} }
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1016,10 +1016,12 @@
   // The attribute "counting-function" is set to mcount function name which is
   // architecture dependent.
   if (CGM.getCodeGenOpts().InstrumentForProfiling) {
-if (CGM.getCodeGenOpts().CallFEntry)
-  Fn->addFnAttr("fentry-call", "true");
-else {
-  if (!CurFuncDecl || !CurFuncDecl->hasAttr()) {
+// Calls to fentry/mcount should not be generated if function has
+// the no_instrument_function attribute.
+if (!CurFuncDecl || !CurFuncDecl->hasAttr()) {
+  if (CGM.getCodeGenOpts().CallFEntry)
+Fn->addFnAttr("fentry-call", "true");
+  else {
 Fn->addFnAttr("instrument-function-entry-inlined",
   getTarget().getMCountName());
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43995: Do not generate calls to fentry with __attribute__((no_instrument_function))

2018-03-02 Thread Manoj Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326639: Do not generate calls to fentry with 
__attribute__((no_instrument_function)) (authored by manojgupta, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43995?vs=136670&id=136874#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43995

Files:
  lib/CodeGen/CodeGenFunction.cpp
  test/CodeGen/fentry.c


Index: test/CodeGen/fentry.c
===
--- test/CodeGen/fentry.c
+++ test/CodeGen/fentry.c
@@ -7,5 +7,12 @@
   return 0;
 }
 
-//CHECK: attributes #{{[0-9]+}} = { {{.*}}"fentry-call"="true"{{.*}} }
-//NOPG-NOT: attributes #{{[0-9]+}} = { {{.*}}"fentry-call"{{.*}} }
+int __attribute__((no_instrument_function)) no_instrument(void) {
+  return foo();
+}
+
+//CHECK: attributes #0 = { {{.*}}"fentry-call"="true"{{.*}} }
+//CHECK: attributes #1 = { {{.*}} }
+//CHECK-NOT: attributes #1 = { {{.*}}"fentry-call"="true"{{.*}} }
+//NOPG-NOT: attributes #0 = { {{.*}}"fentry-call"{{.*}} }
+//NOPG-NOT: attributes #1 = { {{.*}}"fentry-call"{{.*}} }
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1016,10 +1016,12 @@
   // The attribute "counting-function" is set to mcount function name which is
   // architecture dependent.
   if (CGM.getCodeGenOpts().InstrumentForProfiling) {
-if (CGM.getCodeGenOpts().CallFEntry)
-  Fn->addFnAttr("fentry-call", "true");
-else {
-  if (!CurFuncDecl || !CurFuncDecl->hasAttr()) {
+// Calls to fentry/mcount should not be generated if function has
+// the no_instrument_function attribute.
+if (!CurFuncDecl || !CurFuncDecl->hasAttr()) {
+  if (CGM.getCodeGenOpts().CallFEntry)
+Fn->addFnAttr("fentry-call", "true");
+  else {
 Fn->addFnAttr("instrument-function-entry-inlined",
   getTarget().getMCountName());
   }


Index: test/CodeGen/fentry.c
===
--- test/CodeGen/fentry.c
+++ test/CodeGen/fentry.c
@@ -7,5 +7,12 @@
   return 0;
 }
 
-//CHECK: attributes #{{[0-9]+}} = { {{.*}}"fentry-call"="true"{{.*}} }
-//NOPG-NOT: attributes #{{[0-9]+}} = { {{.*}}"fentry-call"{{.*}} }
+int __attribute__((no_instrument_function)) no_instrument(void) {
+  return foo();
+}
+
+//CHECK: attributes #0 = { {{.*}}"fentry-call"="true"{{.*}} }
+//CHECK: attributes #1 = { {{.*}} }
+//CHECK-NOT: attributes #1 = { {{.*}}"fentry-call"="true"{{.*}} }
+//NOPG-NOT: attributes #0 = { {{.*}}"fentry-call"{{.*}} }
+//NOPG-NOT: attributes #1 = { {{.*}}"fentry-call"{{.*}} }
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1016,10 +1016,12 @@
   // The attribute "counting-function" is set to mcount function name which is
   // architecture dependent.
   if (CGM.getCodeGenOpts().InstrumentForProfiling) {
-if (CGM.getCodeGenOpts().CallFEntry)
-  Fn->addFnAttr("fentry-call", "true");
-else {
-  if (!CurFuncDecl || !CurFuncDecl->hasAttr()) {
+// Calls to fentry/mcount should not be generated if function has
+// the no_instrument_function attribute.
+if (!CurFuncDecl || !CurFuncDecl->hasAttr()) {
+  if (CGM.getCodeGenOpts().CallFEntry)
+Fn->addFnAttr("fentry-call", "true");
+  else {
 Fn->addFnAttr("instrument-function-entry-inlined",
   getTarget().getMCountName());
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-06-07 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.
manojgupta added reviewers: t.p.northover, efriedma, jyknight, chandlerc, rnk, 
srhines, void.

Support for this option is needed for building Linux kernel.
This is a very frequently requested feature by kernel developers.

More details : https://lkml.org/lkml/2018/4/4/601

GCC option description for -fdelete-null-pointer-checks:
This Assume that programs cannot safely dereference null pointers,
and that no code or data element resides at address zero.

-fno-delete-null-pointer-checks is the inverse of this implying that
null pointer dereferencing is not undefined.

This feature is implemented in as the function attribute
"null-pointer-is-valid"="true".
This CL only adds the attribute on the function. Another corresponding LLVM
change updates the optimizations to not treat null pointer dereferencing
as undefined if the attribute is present.


Repository:
  rC Clang

https://reviews.llvm.org/D47894

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/delete-null-pointer-checks.c
  test/Driver/clang_f_opts.c

Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -348,7 +348,6 @@
 // RUN: -fwhole-program   \
 // RUN: -fcaller-saves\
 // RUN: -freorder-blocks  \
-// RUN: -fdelete-null-pointer-checks  \
 // RUN: -ffat-lto-objects \
 // RUN: -fmerge-constants \
 // RUN: -finline-small-functions  \
@@ -414,7 +413,6 @@
 // CHECK-WARNING-DAG: optimization flag '-fwhole-program' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
 // CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
-// CHECK-WARNING-DAG: optimization flag '-fdelete-null-pointer-checks' is not supported
 // CHECK-WARNING-DAG: optimization flag '-ffat-lto-objects' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fmerge-constants' is not supported
 // CHECK-WARNING-DAG: optimization flag '-finline-small-functions' is not supported
@@ -526,3 +524,10 @@
 // RUN: %clang -### -S -fno-merge-all-constants -fmerge-all-constants %s 2>&1 | FileCheck -check-prefix=CHECK-MERGE-ALL-CONSTANTS %s
 // CHECK-NO-MERGE-ALL-CONSTANTS-NOT: "-fmerge-all-constants"
 // CHECK-MERGE-ALL-CONSTANTS: "-fmerge-all-constants"
+
+// RUN: %clang -### -S -fdelete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fno-delete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NO-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fdelete-null-pointer-checks -fno-delete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NO-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fno-delete-null-pointer-checks -fdelete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NULL-POINTER-CHECKS %s
+// CHECK-NO-NULL-POINTER-CHECKS: "-fno-delete-null-pointer-checks"
+// CHECK-NULL-POINTER-CHECKS-NOT: "-fno-delete-null-pointer-checks"
Index: test/CodeGen/delete-null-pointer-checks.c
===
--- /dev/null
+++ test/CodeGen/delete-null-pointer-checks.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck -check-prefix=NULL-POINTER-INVALID  %s
+// RUN: %clang_cc1 -emit-llvm -o - %s -fno-delete-null-pointer-checks | FileCheck -check-prefix=NULL-POINTER-VALID  %s
+
+int test1(int a) {
+  return a;
+}
+
+// NULL-POINTER-INVALID-NOT: attributes #0 = {{.*}} "null-pointer-is-valid"="true"
+// NULL-POINTER-VALID: attributes #0 = {{.*}} "null-pointer-is-valid"="true"
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -742,6 +742,7 @@
  OPT_fno_unique_section_names, true);
 
   Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
+  Opts.NullPointerIsValid = Args.hasArg(OPT_fno_delete_null_pointer_checks);
 
   Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
 
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3382,6 +3382,10 @@
options::OPT_fno_merge_all_constants, false))
 CmdArgs.push_back("-fmerge-all-constants");
 
+  if (Args.hasFlag(options::OPT_fno_delete_null_pointer_checks,
+   options::OPT_fdel

[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-06-07 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

In https://reviews.llvm.org/D47894#1125406, @efriedma wrote:

> Does IR generation need any special handling for this?  We add nonnull 
> attributes in various places.


My interpretation is adding nonnull attributes is fine as long is it is not 
derived from a pointer dereference. 
E.g. addresses from alloca can be treated non-null.


Repository:
  rC Clang

https://reviews.llvm.org/D47894



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


[PATCH] D53608: [builtins] Build float128 soft float builtins for x86_64.

2018-10-23 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.
manojgupta added reviewers: efriedma, joerg.
Herald added subscribers: Sanitizers, llvm-commits, delcypher, mgorny.

float128 builtins are currently not built for x86_64.
This causes linker to complain baout missing symbols when linking
glibc 2.27 with float128 support.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D53608

Files:
  lib/builtins/CMakeLists.txt
  lib/builtins/fp_lib.h


Index: lib/builtins/fp_lib.h
===
--- lib/builtins/fp_lib.h
+++ lib/builtins/fp_lib.h
@@ -103,11 +103,12 @@
 COMPILER_RT_ABI fp_t __adddf3(fp_t a, fp_t b);
 
 #elif defined QUAD_PRECISION
-#if __LDBL_MANT_DIG__ == 113
+// __LDBL_MANT_DIG__ is set to 64 for x86_64.
+#if __LDBL_MANT_DIG__ == 113 || defined(__x86_64__)
 #define CRT_LDBL_128BIT
 typedef __uint128_t rep_t;
 typedef __int128_t srep_t;
-typedef long double fp_t;
+typedef __float128 fp_t;
 #define REP_C (__uint128_t)
 // Note: Since there is no explicit way to tell compiler the constant is a
 // 128-bit integer, we let the constant be casted to 128-bit integer
Index: lib/builtins/CMakeLists.txt
===
--- lib/builtins/CMakeLists.txt
+++ lib/builtins/CMakeLists.txt
@@ -232,6 +232,7 @@
 
 if (NOT MSVC)
   set(x86_64_SOURCES
+  ${GENERIC_TF_SOURCES}
   x86_64/floatdidf.c
   x86_64/floatdisf.c
   x86_64/floatdixf.c


Index: lib/builtins/fp_lib.h
===
--- lib/builtins/fp_lib.h
+++ lib/builtins/fp_lib.h
@@ -103,11 +103,12 @@
 COMPILER_RT_ABI fp_t __adddf3(fp_t a, fp_t b);
 
 #elif defined QUAD_PRECISION
-#if __LDBL_MANT_DIG__ == 113
+// __LDBL_MANT_DIG__ is set to 64 for x86_64.
+#if __LDBL_MANT_DIG__ == 113 || defined(__x86_64__)
 #define CRT_LDBL_128BIT
 typedef __uint128_t rep_t;
 typedef __int128_t srep_t;
-typedef long double fp_t;
+typedef __float128 fp_t;
 #define REP_C (__uint128_t)
 // Note: Since there is no explicit way to tell compiler the constant is a
 // 128-bit integer, we let the constant be casted to 128-bit integer
Index: lib/builtins/CMakeLists.txt
===
--- lib/builtins/CMakeLists.txt
+++ lib/builtins/CMakeLists.txt
@@ -232,6 +232,7 @@
 
 if (NOT MSVC)
   set(x86_64_SOURCES
+  ${GENERIC_TF_SOURCES}
   x86_64/floatdidf.c
   x86_64/floatdisf.c
   x86_64/floatdixf.c
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53608: [builtins] Build float128 soft float builtins for x86_64.

2018-10-23 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added inline comments.



Comment at: lib/builtins/fp_lib.h:107
+// __LDBL_MANT_DIG__ is set to 64 for x86_64.
+#if __LDBL_MANT_DIG__ == 113 || defined(__x86_64__)
 #define CRT_LDBL_128BIT

I really don't know  the accurate set of checks that should be used here, 
Please advise,



Comment at: lib/builtins/fp_lib.h:111
 typedef __int128_t srep_t;
-typedef long double fp_t;
+typedef __float128 fp_t;
 #define REP_C (__uint128_t)

Changed long double to  __float128 on Eli's advice in PR39376.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D53608



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


[PATCH] D53608: [builtins] Build float128 soft float builtins for x86_64.

2018-10-23 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 170756.
manojgupta added a comment.

Added checked for defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D53608

Files:
  lib/builtins/CMakeLists.txt
  lib/builtins/fp_lib.h


Index: lib/builtins/fp_lib.h
===
--- lib/builtins/fp_lib.h
+++ lib/builtins/fp_lib.h
@@ -103,11 +103,16 @@
 COMPILER_RT_ABI fp_t __adddf3(fp_t a, fp_t b);
 
 #elif defined QUAD_PRECISION
-#if __LDBL_MANT_DIG__ == 113
+// __LDBL_MANT_DIG__ is set to 64 for x86_64.
+#if __LDBL_MANT_DIG__ == 113 || defined(__x86_64__)
 #define CRT_LDBL_128BIT
 typedef __uint128_t rep_t;
 typedef __int128_t srep_t;
+#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
+typedef __float128 fp_t;
+#else
 typedef long double fp_t;
+#endif
 #define REP_C (__uint128_t)
 // Note: Since there is no explicit way to tell compiler the constant is a
 // 128-bit integer, we let the constant be casted to 128-bit integer
Index: lib/builtins/CMakeLists.txt
===
--- lib/builtins/CMakeLists.txt
+++ lib/builtins/CMakeLists.txt
@@ -232,6 +232,7 @@
 
 if (NOT MSVC)
   set(x86_64_SOURCES
+  ${GENERIC_TF_SOURCES}
   x86_64/floatdidf.c
   x86_64/floatdisf.c
   x86_64/floatdixf.c


Index: lib/builtins/fp_lib.h
===
--- lib/builtins/fp_lib.h
+++ lib/builtins/fp_lib.h
@@ -103,11 +103,16 @@
 COMPILER_RT_ABI fp_t __adddf3(fp_t a, fp_t b);
 
 #elif defined QUAD_PRECISION
-#if __LDBL_MANT_DIG__ == 113
+// __LDBL_MANT_DIG__ is set to 64 for x86_64.
+#if __LDBL_MANT_DIG__ == 113 || defined(__x86_64__)
 #define CRT_LDBL_128BIT
 typedef __uint128_t rep_t;
 typedef __int128_t srep_t;
+#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
+typedef __float128 fp_t;
+#else
 typedef long double fp_t;
+#endif
 #define REP_C (__uint128_t)
 // Note: Since there is no explicit way to tell compiler the constant is a
 // 128-bit integer, we let the constant be casted to 128-bit integer
Index: lib/builtins/CMakeLists.txt
===
--- lib/builtins/CMakeLists.txt
+++ lib/builtins/CMakeLists.txt
@@ -232,6 +232,7 @@
 
 if (NOT MSVC)
   set(x86_64_SOURCES
+  ${GENERIC_TF_SOURCES}
   x86_64/floatdidf.c
   x86_64/floatdisf.c
   x86_64/floatdixf.c
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53608: [builtins] Build float128 soft float builtins for x86_64.

2018-10-23 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added inline comments.



Comment at: lib/builtins/fp_lib.h:111
 typedef __int128_t srep_t;
-typedef long double fp_t;
+typedef __float128 fp_t;
 #define REP_C (__uint128_t)

efriedma wrote:
> manojgupta wrote:
> > Changed long double to  __float128 on Eli's advice in PR39376.
> You need to guard this with an ifdef; clang doesn't supports __float128 on 
> every target, even if long double is an 128-bit IEEE float.
> 
> For reasons I don't really understand, there are apparently two different 
> macros for this; `#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)` 
> should do the right thing.
Thanks Eli. I also found out that GCC 4.9 does not seem to have these defined 
even though it supports __float128.
https://godbolt.org/z/ReVm8j



Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D53608



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


[PATCH] D53608: [builtins] Build float128 soft float builtins for x86_64.

2018-10-23 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

I am also getting these tests failures because of missing __trunctfxf2 and 
__extendxftf2. These are provided by libgcc but compiler-rt does not seem to 
have an implementation for them.

  Builtins-x86_64-linux :: compiler_rt_logbl_test.c
  Builtins-x86_64-linux :: divtc3_test.c
  Builtins-x86_64-linux :: floattitf_test.c
  Builtins-x86_64-linux :: floatuntitf_test.c

compiler_rt_logbl_test.c:26: error: undefined reference to '__trunctfxf2'
compiler_rt_logbl_test.c:26: error: undefined reference to '__extendxftf2'


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D53608



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


[PATCH] D53608: [builtins] Build float128 soft float builtins for x86_64.

2018-10-24 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Took another look and seems like long double is hardcoded in many of the 
builtins. So I think the current patch needs to rename a lot of places using 
long double to __float128 type.

Some examples where I think __float128 type (propagating the type in fp_lib.h) 
should be used instead of long double:

./extenddftf2.c:  COMPILER_RT_ABI long double __extenddftf2(double a) {
./trunctfsf2.c:  COMPILER_RT_ABI float __trunctfsf2(long double a) {
./extendsftf2.c:  COMPILER_RT_ABI long double __extendsftf2(float a) {

@efriedma what do you think?


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D53608



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


[PATCH] D53608: [builtins] Build float128 soft float builtins for x86_64.

2019-03-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

In D53608#1423692 , @LuoYuanke wrote:

> Hi
>  What's the status for __float128 support? Has it already been finished?


Sorry, haven't looked at time for a while. Consider this change abandoned for 
now :(


Repository:
  rCRT Compiler Runtime

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

https://reviews.llvm.org/D53608



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


[PATCH] D59264: [Driver] Support compiler-rt crtbegin.o/crtend.o for Linux

2019-03-13 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added subscribers: manojgupta, llozano.
manojgupta added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:447
   const char *crtbegin;
-  if (Args.hasArg(options::OPT_static))
-crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o";
-  else if (Args.hasArg(options::OPT_shared))
-crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o";
-  else if (IsPIE || IsStaticPIE)
-crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbeginS.o";
-  else
-crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbegin.o";
-
-  if (HasCRTBeginEndFiles)
+  if (ToolChain.GetRuntimeLibType(Args) == ToolChain::RLT_CompilerRT &&
+  !isAndroid) {

This is currently unconditional on using compiler-rt. Given that compiler-rt 
provides the crt*.o files only under the CMake flag COMPILER_RT_BUILD_CRT, 
shouldn't there be an equivalent clang CMake flag to conditionally enable this.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59264



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


[PATCH] D59264: [Driver] Support compiler-rt crtbegin.o/crtend.o for Linux

2019-03-13 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:447
   const char *crtbegin;
-  if (Args.hasArg(options::OPT_static))
-crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o";
-  else if (Args.hasArg(options::OPT_shared))
-crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o";
-  else if (IsPIE || IsStaticPIE)
-crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbeginS.o";
-  else
-crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbegin.o";
-
-  if (HasCRTBeginEndFiles)
+  if (ToolChain.GetRuntimeLibType(Args) == ToolChain::RLT_CompilerRT &&
+  !isAndroid) {

phosek wrote:
> manojgupta wrote:
> > This is currently unconditional on using compiler-rt. Given that 
> > compiler-rt provides the crt*.o files only under the CMake flag 
> > COMPILER_RT_BUILD_CRT, shouldn't there be an equivalent clang CMake flag to 
> > conditionally enable this.
> `COMPILER_RT_BUILD_CRT` is `ON` by default now in D28791, but even if we 
> change that, I think this logic should be independent since you should be 
> able to build Clang separately from compiler-rt.
Since it is possible to build compiler-rt without CRT files, I believe that 
clang should also be able to use compiler-rt without compiler-rt provided CRT 
files.
Using them unconditionally will also break the case of using newer clang with 
older compiler-rt.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59264



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


[PATCH] D60472: [AArch64][PowerPC][Driver] Allow setting crypto feature through -mcrypto for ARM/AArch64

2019-04-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added inline comments.



Comment at: clang/include/clang/Driver/Options.td:2218
 Group;
-def mpower8_crypto : Flag<["-"], "mcrypto">,
-Group;
-def mnopower8_crypto : Flag<["-"], "mno-crypto">,
-Group;
+def mcrypto : Flag<["-"], "mcrypto">, Group,
+HelpText<"Add use of cryptographic instructions (ARM/PowerPC only)">;

Can you move it out of ppc specific options area to more generic options 
location e.g. like hard-float?



Comment at: clang/include/clang/Driver/Options.td:2219
+def mcrypto : Flag<["-"], "mcrypto">, Group,
+HelpText<"Add use of cryptographic instructions (ARM/PowerPC only)">;
+def mnocrypto : Flag<["-"], "mno-crypto">, Group,

ARM/AArch64/PowerPC



Comment at: clang/include/clang/Driver/Options.td:2221
+def mnocrypto : Flag<["-"], "mno-crypto">, Group,
+HelpText<"Disallow use of cryptographic instructions (ARM/PowerPC only)">;
 def mdirect_move : Flag<["-"], "mdirect-move">,

ARM/AArch64/PowerPC



Comment at: clang/lib/Driver/ToolChains/Arch/AArch64.cpp:192
+  // En/disable crypto
+  if (Arg *A = Args.getLastArg(options::OPT_mcrypto, options::OPT_mnocrypto,
+   options::OPT_mgeneral_regs_only)) {

I believe this should be merged with the code for OPT_mgeneral_regs_only 
otherwise  the next if statement  for mgeneral-regs-only  would force "-crypto" 
.

if (A->getOption().matches(OPT_mgeneral_regs_only)))
..// disable crypto, neon etc.
else if (A->getOption().matches(options::OPT_mcrypto))
// enable crypto
...

Please also add tests when mgeneral-regs-only is specified with "-mcrypto"  
before/after.



Comment at: clang/lib/Driver/ToolChains/Arch/ARM.cpp:453
+  if (Arg *A = Args.getLastArg(options::OPT_mcrypto, options::OPT_mnocrypto)) {
+if (A->getOption().matches(options::OPT_mcrypto) && ABI != 
arm::FloatABI::Soft)
+  Features.push_back("+crypto");

Please add a test for interaction with soft-float ABI option.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60472



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


[PATCH] D60472: [AArch64][PowerPC][Driver] Allow setting crypto feature through -mcrypto for ARM/AArch64

2019-04-10 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

The motivation for this change is to make "crypto" setting an additive option 
e.g. like "-mavx" used in many media packages.  Some packages in Chrome want to 
enable crypto conditionally for a few files to allow crypto feature to be used 
based on runtime cpu detection. They set "-march=armv8+crypto" flag but it gets 
overridden by the global "-march=armv8a" flag set by the build system in Chrome 
OS because the target cpu does not support crypto causing compile-time errors. 
Ability to specify "-mcrypto"  standalone makes it an additive option and 
ensures that it it is not lost. i.e. this will help in decoupling  "-mcrypto" 
from "-march" so that they could be set independently. The current additive 
alternate is  '-Xclang -target-feature -Xclang "+crypto" ' which is ugly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60472



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


[PATCH] D60472: [AArch64][PowerPC][Driver] Allow setting crypto feature through -mcrypto for ARM/AArch64

2019-04-10 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

In D60472#1461351 , @peter.smith wrote:

>




> Is that not a limitation of the build system? I'd expect a package to be able 
> to locally override a global default rather than vice-versa. Although crypto 
> might be the area of concern here and there may be a conveniently named 
> option for PPC, where does this stop? Crypto is not the only architectural 
> extension, for example see 
> https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html . To maintain a 
> consistent interface we'd need command line options for all the extensions. 
> May I encourage you to reply to the RFC on command line options that I 
> mentioned earlier if it doesn't work for you? I think the extensions need to 
> be considered as a whole and not just individually.

While it partly is a build system issue, another problem is enabling crypto via 
"-march" requires picking an architecture as well. So even if it could override 
the global default, it would also override the global "-march" as well. If the 
global "-march" was a better/higher option, it does not make sense to override 
it e.g. "-march=armv8-a+crypto" overriding "-march=armv8.3-a" is not helpful 
since it will disable 8.3 features.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60472



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


[PATCH] D60472: [AArch64][PowerPC][Driver] Allow setting crypto feature through -mcrypto for ARM/AArch64

2019-04-10 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

In D60472#1461351 , @peter.smith wrote:

>




> Is that not a limitation of the build system? I'd expect a package to be able 
> to locally override a global default rather than vice-versa. Although crypto 
> might be the area of concern here and there may be a conveniently named 
> option for PPC, where does this stop? Crypto is not the only architectural 
> extension, for example see 
> https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html . To maintain a 
> consistent interface we'd need command line options for all the extensions. 
> May I encourage you to reply to the RFC on command line options that I 
> mentioned earlier if it doesn't work for you? I think the extensions need to 
> be considered as a whole and not just individually.

I'll also read the RFC and respond.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60472



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


[PATCH] D52248: [SEMA] ignore duplicate declaration specifiers from typeof exprs

2018-09-19 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

As per https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80868, I thought GCC also 
emits this error but only with -pedantic. So probably should keep this error 
but under -Wextra or another appropriate group?


Repository:
  rC Clang

https://reviews.llvm.org/D52248



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


[PATCH] D52248: [SEMA] ignore duplicate declaration specifiers from typeof exprs

2018-09-20 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

lgtm. But someone more familiar with these code paths should approve.


Repository:
  rC Clang

https://reviews.llvm.org/D52248



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


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-07-15 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

@dankm are you still working on this patch?


Repository:
  rC Clang

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

https://reviews.llvm.org/D49466



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


[PATCH] D48680: Add missing visibility annotation for __base

2019-07-16 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

@pcc can you please submit this patch if there are no objections?


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D48680



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


[PATCH] D52524: Add -Wno-poison-system-directories flag

2019-08-14 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

In D52524#1621468 , @thakis wrote:

> Couldn't cross build users just pass -nostdsysteminc to tell clang to not 
> look in system header locations?


My understanding is "-nostdsysteminc " does not block users from passing 
include paths from host that are outside sysroot. i.e. clang --sysroot=/foo 
-nostdsysteminc  -I/usr/include still works.
This warning is to catch this behavior.
This is an actual problem in Chrome OS where building some third party packages 
do not respect cross-compilation.


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

https://reviews.llvm.org/D52524



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


[PATCH] D52524: Add -Wno-poison-system-directories flag

2019-08-14 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

In D52524#1630767 , @thakis wrote:

> Wouldn't those projects just move to also disabling the warning by passing 
> -Wno-poison-system-directories? If there are projects that are actively 
> adding -I/usr/include, that means they're consciously fighting the build 
> system and you've kind of already lost, no? Can't you tell them to not use 
> -I/usr/include?


Most of the time, those packages are not exactly fighting cross-compilation 
(e.g. samba), just they just have a broken build system that adds I/usr/include 
when building them. This warning will help catch bad includes whenever someone 
imports a new package or upgrade to a newer version from upstream.
Note: in Chrome OS, packages are built using their native build system e.g. 
LLVM is built with cmake, tensorflow is built with bazel etc.


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

https://reviews.llvm.org/D52524



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


[PATCH] D52524: Add -Wno-poison-system-directories flag

2019-08-14 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticGroups.td:1071
+// cross-compiling.
+def PoisonSystemDirectories : DiagGroup<"poison-system-directories">;
+

Please verify that the warning is not enabled by default.


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

https://reviews.llvm.org/D52524



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


[PATCH] D52524: Add -Wno-poison-system-directories flag

2019-08-19 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added inline comments.



Comment at: clang/test/Frontend/warning-poison-system-directories.c:12
+// Missing target but included sysroot still causes the warning.
+// RUN: %clang -Wpoison-system-directories -I/usr/include --sysroot 
%S/Inputs/sysroot_x86_64_cross_linux_tree -c -o - %s 2> %t.2.stderr
+// RUN: FileCheck -check-prefix=WARN < %t.2.stderr %s

Thanks, Can you also add a test for  -Werror=poison-system-directories .


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

https://reviews.llvm.org/D52524



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


[PATCH] D52524: Add -Wno-poison-system-directories flag

2019-08-19 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added reviewers: rtrieu, aaron.ballman.
manojgupta added a comment.

Thanks,

Adding a few more reviewers since I am not very familiar with this part of 
clang.
Please also update the patch description as suggested by @thakis


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

https://reviews.llvm.org/D52524



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


[PATCH] D48680: Add missing visibility annotation for __base

2019-06-24 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

@ldionne Does Peter's example answer your questions?


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D48680



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


[PATCH] D48680: Add missing visibility annotation for __base

2019-05-28 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.
Herald added a subscriber: libcxx-commits.

Hi Peter and Marshall,

Yunlian has moved to a different project. Can you let me know what is missing 
in this patch so that it can be submitted.


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D48680



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


[PATCH] D52524: Add -Wpoison-system-directories warning

2019-09-12 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta closed this revision.
manojgupta added a comment.

Submitted as https://reviews.llvm.org/rL371785.
Thanks for the patch!


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

https://reviews.llvm.org/D52524



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


[PATCH] D46300: [Clang] Implement function attribute no_stack_protector.

2018-04-30 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.
manojgupta added reviewers: aaron.ballman, rsmith, rnk, void.

This attribute tells clang to skip this function from stack protector
when -stack-protector option is passed.
GCC option for this is:
__attribute__((__optimize__("no-stack-protector"))) and the
equivalent clang syntax would be: __attribute__((no_stack_protector))

This is used in Linux kernel to selectively disable stack protector
in certain functions.


Repository:
  rC Clang

https://reviews.llvm.org/D46300

Files:
  include/clang/Basic/Attr.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/stack-protector.c


Index: test/CodeGen/stack-protector.c
===
--- test/CodeGen/stack-protector.c
+++ test/CodeGen/stack-protector.c
@@ -22,6 +22,14 @@
   printf("%s\n", a);
 }
 
+// DEF: define {{.*}}void @test2(i8* %msg) #[[B:.*]] {
+__attribute__((no_stack_protector))
+void test2(const char *msg) {
+  char a[strlen(msg) + 1];
+  strcpy(a, msg);
+  printf("%s\n", a);
+}
+
 // NOSSP-NOT: attributes #[[A]] = {{.*}} ssp
 // SSP: attributes #[[A]] = {{.*}} ssp{{ }}
 // SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong
@@ -33,3 +41,15 @@
 // SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp{{ }}
 // SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong
 // SAFESTACK-SSPREQ: attributes #[[A]] = {{.*}} safestack sspreq
+
+// NOSSP-NOT: attributes #[[B]] = {{.*}} ssp
+// SSP-NOT: attributes #[[B]] = {{.*}} ssp{{ }}
+// SSPSTRONG-NOT: attributes #[[B]] = {{.*}} sspstrong
+// SSPREQ-NOT: attributes #[[B]] = {{.*}} sspreq
+
+// SAFESTACK-SSP: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSP-NOT: attributes #[[B]] = {{.*}} safestack ssp{{ }}
+// SAFESTACK-SSPSTRONG: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPSTRONG-NOT: attributes #[[B]] = {{.*}} safestack sspstrong
+// SAFESTACK-SSPREQ: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPREQ-NOT: attributes #[[B]] = {{.*}} safestack sspreq
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6230,6 +6230,10 @@
   case AttributeList::AT_NoInstrumentFunction: // Interacts with -pg.
 handleSimpleAttribute(S, D, AL);
 break;
+  case AttributeList::AT_NoStackProtector:
+// Interacts with -fstack-protector options.
+handleSimpleAttribute(S, D, AL);
+break;
   case AttributeList::AT_StdCall:
   case AttributeList::AT_CDecl:
   case AttributeList::AT_FastCall:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1142,12 +1142,14 @@
   if (!hasUnwindExceptions(LangOpts))
 B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (LangOpts.getStackProtector() == LangOptions::SSPOn)
-B.addAttribute(llvm::Attribute::StackProtect);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
-B.addAttribute(llvm::Attribute::StackProtectStrong);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
-B.addAttribute(llvm::Attribute::StackProtectReq);
+  if (!D || !D->hasAttr()) {
+if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+  B.addAttribute(llvm::Attribute::StackProtect);
+else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
+  B.addAttribute(llvm::Attribute::StackProtectStrong);
+else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
+  B.addAttribute(llvm::Attribute::StackProtectReq);
+  }
 
   if (!D) {
 // If we don't have a declaration to control inlining, the function isn't
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1490,6 +1490,12 @@
   let Documentation = [NotTailCalledDocs];
 }
 
+def NoStackProtector : InheritableAttr {
+  let Spellings = [GCC<"no_stack_protector">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];
+}
+
 def NoThrow : InheritableAttr {
   let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
   let Subjects = SubjectList<[Function]>;


Index: test/CodeGen/stack-protector.c
===
--- test/CodeGen/stack-protector.c
+++ test/CodeGen/stack-protector.c
@@ -22,6 +22,14 @@
   printf("%s\n", a);
 }
 
+// DEF: define {{.*}}void @test2(i8* %msg) #[[B:.*]] {
+__attribute__((no_stack_protector))
+void test2(const char *msg) {
+  char a[strlen(msg) + 1];
+  strcpy(a, msg);
+  printf("%s\n", a);
+}
+
 // NOSSP-NOT: attributes #[[A]] = {{.*}} ssp
 // SSP: attributes #[[A]] = {{.*}} ssp{{ }}
 // SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong
@@ -33,3 +41,15 @@
 // SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp{{ }}
 // SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong
 // SAFES

[PATCH] D46300: [Clang] Implement function attribute no_stack_protector.

2018-05-07 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 145514.
manojgupta added a comment.

Added docs, Sema test case for the attribute.


Repository:
  rC Clang

https://reviews.llvm.org/D46300

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/stack-protector.c
  test/Sema/no_stack_protector.c

Index: test/Sema/no_stack_protector.c
===
--- /dev/null
+++ test/Sema/no_stack_protector.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void __attribute__((no_stack_protector)) foo() {}
+int __attribute__((no_stack_protector)) var; // expected-warning {{'no_stack_protector' attribute only applies to functions}}
Index: test/CodeGen/stack-protector.c
===
--- test/CodeGen/stack-protector.c
+++ test/CodeGen/stack-protector.c
@@ -22,6 +22,14 @@
   printf("%s\n", a);
 }
 
+// DEF: define {{.*}}void @test2(i8* %msg) #[[B:.*]] {
+__attribute__((no_stack_protector))
+void test2(const char *msg) {
+  char a[strlen(msg) + 1];
+  strcpy(a, msg);
+  printf("%s\n", a);
+}
+
 // NOSSP-NOT: attributes #[[A]] = {{.*}} ssp
 // SSP: attributes #[[A]] = {{.*}} ssp{{ }}
 // SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong
@@ -33,3 +41,15 @@
 // SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp{{ }}
 // SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong
 // SAFESTACK-SSPREQ: attributes #[[A]] = {{.*}} safestack sspreq
+
+// NOSSP-NOT: attributes #[[B]] = {{.*}} ssp
+// SSP-NOT: attributes #[[B]] = {{.*}} ssp{{ }}
+// SSPSTRONG-NOT: attributes #[[B]] = {{.*}} sspstrong
+// SSPREQ-NOT: attributes #[[B]] = {{.*}} sspreq
+
+// SAFESTACK-SSP: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSP-NOT: attributes #[[B]] = {{.*}} safestack ssp{{ }}
+// SAFESTACK-SSPSTRONG: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPSTRONG-NOT: attributes #[[B]] = {{.*}} safestack sspstrong
+// SAFESTACK-SSPREQ: attributes #[[B]] = {{.*}} safestack
+// SAFESTACK-SSPREQ-NOT: attributes #[[B]] = {{.*}} safestack sspreq
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -6230,6 +6230,10 @@
   case AttributeList::AT_NoInstrumentFunction: // Interacts with -pg.
 handleSimpleAttribute(S, D, AL);
 break;
+  case AttributeList::AT_NoStackProtector:
+// Interacts with -fstack-protector options.
+handleSimpleAttribute(S, D, AL);
+break;
   case AttributeList::AT_StdCall:
   case AttributeList::AT_CDecl:
   case AttributeList::AT_FastCall:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1142,12 +1142,14 @@
   if (!hasUnwindExceptions(LangOpts))
 B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (LangOpts.getStackProtector() == LangOptions::SSPOn)
-B.addAttribute(llvm::Attribute::StackProtect);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
-B.addAttribute(llvm::Attribute::StackProtectStrong);
-  else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
-B.addAttribute(llvm::Attribute::StackProtectReq);
+  if (!D || !D->hasAttr()) {
+if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+  B.addAttribute(llvm::Attribute::StackProtect);
+else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
+  B.addAttribute(llvm::Attribute::StackProtectStrong);
+else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
+  B.addAttribute(llvm::Attribute::StackProtectReq);
+  }
 
   if (!D) {
 // If we don't have a declaration to control inlining, the function isn't
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -2740,6 +2740,27 @@
   }];
 }
 
+def NoStackProtectorDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``__attribute__((no_stack_protector))`` attribute to disable
+stack protector on the specified functions. This attribute is useful for
+selectively disabling stack protector on some functions when building with
+-fstack-protector compiler options.
+
+For example, it disables stack protector for the function foo but function bar
+will still be built with stack protector with -fstack-protector option.
+
+.. code-block:: c
+
+int __attribute__((no_stack_protector))
+foo (int); // stack protection will be disabled for foo.
+
+int bar(int a); // bar can be built with stack protector.
+
+}];
+}
+
 def NotTailCalledDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: include/clang/Basic/Attr.td
===
--

[PATCH] D46300: [Clang] Implement function attribute no_stack_protector.

2018-05-07 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added inline comments.



Comment at: include/clang/Basic/Attr.td:1494
+def NoStackProtector : InheritableAttr {
+  let Spellings = [GCC<"no_stack_protector">];
+  let Subjects = SubjectList<[Function]>;

aaron.ballman wrote:
> This is not a GCC attribute, so this should use the Clang spelling.
> 
> However, why spell the attribute this way rather than use the GCC spelling 
> (`optimize("no-stack-protector")`?
Thanks, I have changed it to use Clang spelling.

Regarding __attribute__((optimize("..."))), it is a generic facility in GCC 
that works for many optimizer flags.
Clang currently does not support this syntax currently instead preferring its 
own version for some options e.g. -O0. 
e.g.  
```
__attribute__((optimize("O0")))  // clang version is __attribute__((optnone)) 
```
If we want to support the GCC syntax, future expectation would be support more 
flags under this syntax. Is that the path we want to take (I do not know the 
history related to previous syntax decisions but better GCC compatibility will 
be a nice thing to have) 


Repository:
  rC Clang

https://reviews.llvm.org/D46300



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


[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-07-10 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 154895.
manojgupta added a comment.

Do not generate calls with "nonnull" attribute with 
"-fno-delete-null-pointer-checks".
The warnings are still generated when nullptr is passed to a function with 
nonnull
attribute.


Repository:
  rC Clang

https://reviews.llvm.org/D47894

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/delete-null-pointer-checks.c
  test/CodeGen/nonnull.c
  test/CodeGen/vla.c
  test/CodeGenCXX/address-space-ref.cpp
  test/CodeGenCXX/constructors.cpp
  test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp
  test/CodeGenCXX/temporaries.cpp
  test/Driver/clang_f_opts.c
  test/Sema/nonnull.c

Index: test/Sema/nonnull.c
===
--- test/Sema/nonnull.c
+++ test/Sema/nonnull.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fno-delete-null-pointer-checks -verify %s
 // rdar://9584012
 
 typedef struct {
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -348,7 +348,6 @@
 // RUN: -fwhole-program   \
 // RUN: -fcaller-saves\
 // RUN: -freorder-blocks  \
-// RUN: -fdelete-null-pointer-checks  \
 // RUN: -ffat-lto-objects \
 // RUN: -fmerge-constants \
 // RUN: -finline-small-functions  \
@@ -414,7 +413,6 @@
 // CHECK-WARNING-DAG: optimization flag '-fwhole-program' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
 // CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
-// CHECK-WARNING-DAG: optimization flag '-fdelete-null-pointer-checks' is not supported
 // CHECK-WARNING-DAG: optimization flag '-ffat-lto-objects' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fmerge-constants' is not supported
 // CHECK-WARNING-DAG: optimization flag '-finline-small-functions' is not supported
@@ -526,3 +524,10 @@
 // RUN: %clang -### -S -fno-merge-all-constants -fmerge-all-constants %s 2>&1 | FileCheck -check-prefix=CHECK-MERGE-ALL-CONSTANTS %s
 // CHECK-NO-MERGE-ALL-CONSTANTS-NOT: "-fmerge-all-constants"
 // CHECK-MERGE-ALL-CONSTANTS: "-fmerge-all-constants"
+
+// RUN: %clang -### -S -fdelete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fno-delete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NO-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fdelete-null-pointer-checks -fno-delete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NO-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fno-delete-null-pointer-checks -fdelete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NULL-POINTER-CHECKS %s
+// CHECK-NO-NULL-POINTER-CHECKS: "-fno-delete-null-pointer-checks"
+// CHECK-NULL-POINTER-CHECKS-NOT: "-fno-delete-null-pointer-checks"
Index: test/CodeGenCXX/temporaries.cpp
===
--- test/CodeGenCXX/temporaries.cpp
+++ test/CodeGenCXX/temporaries.cpp
@@ -1,52 +1,53 @@
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -std=c++11 | FileCheck %s -check-prefixes=CHECK-COMMON,CHECK-NONNULL
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -std=c++11 -fno-delete-null-pointer-checks | FileCheck %s -check-prefixes=CHECK-COMMON,CHECK-NO-NULL
 
 namespace PR16263 {
   const unsigned int n = 1234;
   extern const int &r = (const int&)n;
-  // CHECK: @_ZGRN7PR162631rE_ = internal constant i32 1234,
-  // CHECK: @_ZN7PR162631rE = constant i32* @_ZGRN7PR162631rE_,
+  // CHECK-COMMON: @_ZGRN7PR162631rE_ = internal constant i32 1234,
+  // CHECK-COMMON: @_ZN7PR162631rE = constant i32* @_ZGRN7PR162631rE_,
 
   extern const int &s = reinterpret_cast(n);
-  // CHECK: @_ZN7PR16263L1nE = internal constant i32 1234, align 4
-  // CHECK: @_ZN7PR162631sE = constant i32* @_ZN7PR16263L1nE, align 8
+  // CHECK-COMMON: @_ZN7PR16263L1nE = internal constant i32 1234, align 4
+  // CHECK-COMMON: @_ZN7PR162631sE = constant i32* @_ZN7PR16263L1nE, align 8
 
   struct A { int n; };
   struct B { int n; };
   struct C : A, B {};
   extern const A &&a = (A&&)(A&&)(C&&)(C{});
-  // CHECK: @_ZGRN7PR162631aE_ = internal global {{.*}} zeroinitializer,
-  // CHECK: @_ZN7PR162631aE = constant {{.*}} bitcast ({{.*}}* @_ZGRN

[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-07-11 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

@efriedma @jyknight Does the change match your expectations where warnings are 
still generated but codeGen does not emit nonnull attribute?




Comment at: test/Sema/nonnull.c:2
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fno-delete-null-pointer-checks -verify %s
 // rdar://9584012

All warnings are still issued if nullptr is passed to function nonnull 
attribute.


Repository:
  rC Clang

https://reviews.llvm.org/D47894



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


[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-07-13 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Ping!


Repository:
  rC Clang

https://reviews.llvm.org/D47894



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


[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-07-17 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 155891.
manojgupta added a comment.

Added helper text, updated tests.


Repository:
  rC Clang

https://reviews.llvm.org/D47894

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/delete-null-pointer-checks.c
  test/CodeGen/nonnull.c
  test/CodeGen/vla.c
  test/CodeGenCXX/address-space-ref.cpp
  test/CodeGenCXX/constructors.cpp
  test/CodeGenCXX/temporaries.cpp
  test/Driver/clang_f_opts.c
  test/Sema/nonnull.c

Index: test/Sema/nonnull.c
===
--- test/Sema/nonnull.c
+++ test/Sema/nonnull.c
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // rdar://9584012
+//
+// Verify All warnings are still issued with the option -fno-delete-null-pointer-checks
+// if nullptr is passed to function with nonnull attribute.
+// RUN: %clang_cc1 -fsyntax-only -fno-delete-null-pointer-checks -verify %s
 
 typedef struct {
 	char *str;
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -348,7 +348,6 @@
 // RUN: -fwhole-program   \
 // RUN: -fcaller-saves\
 // RUN: -freorder-blocks  \
-// RUN: -fdelete-null-pointer-checks  \
 // RUN: -ffat-lto-objects \
 // RUN: -fmerge-constants \
 // RUN: -finline-small-functions  \
@@ -414,7 +413,6 @@
 // CHECK-WARNING-DAG: optimization flag '-fwhole-program' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
 // CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
-// CHECK-WARNING-DAG: optimization flag '-fdelete-null-pointer-checks' is not supported
 // CHECK-WARNING-DAG: optimization flag '-ffat-lto-objects' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fmerge-constants' is not supported
 // CHECK-WARNING-DAG: optimization flag '-finline-small-functions' is not supported
@@ -526,3 +524,10 @@
 // RUN: %clang -### -S -fno-merge-all-constants -fmerge-all-constants %s 2>&1 | FileCheck -check-prefix=CHECK-MERGE-ALL-CONSTANTS %s
 // CHECK-NO-MERGE-ALL-CONSTANTS-NOT: "-fmerge-all-constants"
 // CHECK-MERGE-ALL-CONSTANTS: "-fmerge-all-constants"
+
+// RUN: %clang -### -S -fdelete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fno-delete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NO-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fdelete-null-pointer-checks -fno-delete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NO-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fno-delete-null-pointer-checks -fdelete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NULL-POINTER-CHECKS %s
+// CHECK-NO-NULL-POINTER-CHECKS: "-fno-delete-null-pointer-checks"
+// CHECK-NULL-POINTER-CHECKS-NOT: "-fno-delete-null-pointer-checks"
Index: test/CodeGenCXX/temporaries.cpp
===
--- test/CodeGenCXX/temporaries.cpp
+++ test/CodeGenCXX/temporaries.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -std=c++11 | FileCheck %s -check-prefixes=CHECK,NULL-INVALID
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -std=c++11 -fno-delete-null-pointer-checks | FileCheck %s -check-prefixes=CHECK,NULL-VALID
 
 namespace PR16263 {
   const unsigned int n = 1234;
@@ -347,7 +348,8 @@
   struct D;
   D& zed(B);
   void foobar() {
-// CHECK: call nonnull %"struct.PR6648::D"* @_ZN6PR66483zedENS_1BE
+// NULL-INVALID: call nonnull %"struct.PR6648::D"* @_ZN6PR66483zedENS_1BE
+// NULL-VALID: call %"struct.PR6648::D"* @_ZN6PR66483zedENS_1BE
 zed(foo);
   }
 }
Index: test/CodeGenCXX/constructors.cpp
===
--- test/CodeGenCXX/constructors.cpp
+++ test/CodeGenCXX/constructors.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s --implicit-check-not=should_not_appear_in_output
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s --implicit-check-not=should_not_appear_in_output --check-prefixes=CHECK,NULL-INVALID
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -fno-delete-null-pointer-checks -o - | FileCheck %s --implicit-check-not=should_not_appea

[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-07-18 Thread Manoj Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC337433: [clang]: Add support for 
"-fno-delete-null-pointer-checks" (authored by manojgupta, committed 
by ).

Changed prior to commit:
  https://reviews.llvm.org/D47894?vs=155891&id=156195#toc

Repository:
  rC Clang

https://reviews.llvm.org/D47894

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/delete-null-pointer-checks.c
  test/CodeGen/nonnull.c
  test/CodeGen/vla.c
  test/CodeGenCXX/address-space-ref.cpp
  test/CodeGenCXX/constructors.cpp
  test/CodeGenCXX/temporaries.cpp
  test/Driver/clang_f_opts.c
  test/Sema/nonnull.c

Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -746,6 +746,8 @@
 
   Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
 
+  Opts.NullPointerIsValid = Args.hasArg(OPT_fno_delete_null_pointer_checks);
+
   Opts.ProfileSampleAccurate = Args.hasArg(OPT_fprofile_sample_accurate);
 
   Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ);
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1734,6 +1734,8 @@
 FuncAttrs.addAttribute("less-precise-fpmad",
llvm::toStringRef(CodeGenOpts.LessPreciseFPMAD));
 
+if (CodeGenOpts.NullPointerIsValid)
+  FuncAttrs.addAttribute("null-pointer-is-valid", "true");
 if (!CodeGenOpts.FPDenormalMode.empty())
   FuncAttrs.addAttribute("denormal-fp-math", CodeGenOpts.FPDenormalMode);
 
@@ -1867,7 +1869,8 @@
 }
 if (TargetDecl->hasAttr())
   RetAttrs.addAttribute(llvm::Attribute::NoAlias);
-if (TargetDecl->hasAttr())
+if (TargetDecl->hasAttr() &&
+!CodeGenOpts.NullPointerIsValid)
   RetAttrs.addAttribute(llvm::Attribute::NonNull);
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute("no_caller_saved_registers");
@@ -1974,7 +1977,8 @@
 if (!PTy->isIncompleteType() && PTy->isConstantSizeType())
   RetAttrs.addDereferenceableAttr(getContext().getTypeSizeInChars(PTy)
 .getQuantity());
-else if (getContext().getTargetAddressSpace(PTy) == 0)
+else if (getContext().getTargetAddressSpace(PTy) == 0 &&
+ !CodeGenOpts.NullPointerIsValid)
   RetAttrs.addAttribute(llvm::Attribute::NonNull);
   }
 
@@ -2083,7 +2087,8 @@
   if (!PTy->isIncompleteType() && PTy->isConstantSizeType())
 Attrs.addDereferenceableAttr(getContext().getTypeSizeInChars(PTy)
.getQuantity());
-  else if (getContext().getTargetAddressSpace(PTy) == 0)
+  else if (getContext().getTargetAddressSpace(PTy) == 0 &&
+   !CodeGenOpts.NullPointerIsValid)
 Attrs.addAttribute(llvm::Attribute::NonNull);
 }
 
@@ -2343,7 +2348,8 @@
 
 if (const ParmVarDecl *PVD = dyn_cast(Arg)) {
   if (getNonNullAttr(CurCodeDecl, PVD, PVD->getType(),
- PVD->getFunctionScopeIndex()))
+ PVD->getFunctionScopeIndex()) &&
+  !CGM.getCodeGenOpts().NullPointerIsValid)
 AI->addAttr(llvm::Attribute::NonNull);
 
   QualType OTy = PVD->getOriginalType();
@@ -2362,7 +2368,8 @@
 Attrs.addDereferenceableAttr(
   getContext().getTypeSizeInChars(ETy).getQuantity()*ArrSize);
 AI->addAttrs(Attrs);
-  } else if (getContext().getTargetAddressSpace(ETy) == 0) {
+  } else if (getContext().getTargetAddressSpace(ETy) == 0 &&
+ !CGM.getCodeGenOpts().NullPointerIsValid) {
 AI->addAttr(llvm::Attribute::NonNull);
   }
 }
@@ -2372,7 +2379,8 @@
 // we can't use the dereferenceable attribute, but in addrspace(0)
 // we know that it must be nonnull.
 if (ArrTy->getSizeModifier() == VariableArrayType::Static &&
-!getContext().getTargetAddressSpace(ArrTy->getElementType()))
+!getContext().getTargetAddressSpace(ArrTy->getElementType()) &&
+!CGM.getCodeGenOpts().NullPointerIsValid)
   AI->addAttr(llvm::Attribute::NonNull);
   }
 
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3348,6 +3348,10 @@
options::OPT_fno_merge_all_constants, false))
 CmdArgs.push_back("-fmerge-all-constants");
 
+  if (Args.hasFlag(options::OPT_fno_delete_null_pointer_checks,
+   options::OPT_fdelete_null_pointer_

[PATCH] D71082: Allow system header to provide their own implementation of some builtin

2020-04-07 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

I opened https://github.com/ClangBuiltLinux/linux/issues/979 to see if we can 
fix this in Linux kernel.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71082



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


[PATCH] D78862: [IR] Convert null-pointer-is-valid into an enum attribute

2020-04-28 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

@nikic Thanks for the work.

In D78862#2003684 , @arsenm wrote:

> FWIW I think this attribute should be replaced with a data layout property, 
> so this would eventually be removed


@arsenm  Is there any work planned on moving to data layout? Moving to data 
layout may affect cross TU inlining e.g. LTO where 1 TU is compiled with 
`-fno-delete-null-pointer-checks` and other TU is not. There might be other 
potential impact that we might not know yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78862



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


[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.
manojgupta added reviewers: MaskRay, abidh, kristof.beyls.
Herald added subscribers: luke957, StephenFan, s.egerton, simoncook, ki.stfu.
Herald added a project: All.
manojgupta requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead.
Herald added a project: clang.

Refactor baremetal driver code to reduce the bespoke
additions and base class overrides.
This lets us use the per target runtimes like other clang
targets. E.g. clang -target armv7m-cros-none-eabi will now
be able to use the runtimes installed at
/lib/armv7m-cros-none-eabi instead of the hardcoded
path /lib/baremetal.
The older code paths should still continue to work as before if
/lib/ does not exist.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131225

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/armv7m-vendor-none-eabi/libclang_rt.builtins.a
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/print-libgcc-file-name-clangrt.c

Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -48,3 +48,9 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s
 // CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: --target=armv7m-vendor-none-eabi \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET %s
+// CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET: libclang_rt.builtins.a
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -31,6 +31,20 @@
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
 // CHECK-V6M-LIBINC-NOT: "-internal-isystem"
 
+// RUN: %clang -no-canonical-prefixes -rtlib=compiler-rt %s -### -o %t.o 2>&1 \
+// RUN: -target armv7m-vendor-none-eabi \
+// RUN: --sysroot=%S/Inputs/baremetal_arm \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7M-PER-TARGET %s
+// CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
+// CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
+// CHECK-ARMV7M-PER-TARGET: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
+// CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
+// CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
+// CHECK-ARMV7M-PER-TARGET: "-o" "{{.*}}.o"
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target armv6m-none-eabi \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.h
===
--- clang/lib/Driver/ToolChains/BareMetal.h
+++ clang/lib/Driver/ToolChains/BareMetal.h
@@ -25,19 +25,11 @@
 const llvm::opt::ArgList &Args);
   ~BareMetal() override = default;
 
-  static bool handlesTarget(const llvm::Triple &Triple);
-
   void findMultilibs(const Driver &D, const llvm::Triple &Triple,
  const llvm::opt::ArgList &Args);
 
 protected:
   Tool *buildLinker() const override;
-
-  std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args,
-  StringRef Component,
-  FileType Type = ToolChain::FT_Static,
-  bool AddArch = true) const override;
-
 public:
   bool useIntegratedAs() const override { return true; }
   bool isCrossCompiling() const override { return true; }
@@ -50,8 +42,6 @@
 
   StringRef getOSLibName() const override { return "baremetal"; }
 
-  std::string getCompilerRTPath() const override;
-
   RuntimeLibType GetDefaultRuntimeLibType() const override {
 return ToolChain::RLT_CompilerRT;
   }
@@ -61,7 +51,6 @@
 
   const char *getDefaultLinker() const override { return "ld.lld"; }
 
-  std::string getRuntimesDir() const;
   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args) const override;
   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===

[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-08 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added inline comments.



Comment at: clang/include/clang/Driver/ToolChain.h:384
 
+  /// IsBareMetal - Does this tool chain is a baremetal target.
+  static bool IsBareMetal(const llvm::Triple &);

barannikov88 wrote:
> Is this a correct sentence? (My English is poor.)
> 
I'll fix it. Somehow I forgot to check them.



Comment at: clang/include/clang/Driver/ToolChain.h:388
+  /// IsRISCVBareMetal - Does this tool chain is a riscv baremetal target.
+  static bool IsRISCVBareMetal(const llvm::Triple &);
+

barannikov88 wrote:
> The ToolChain class is an interface class. It is strange to see such kind of 
> methods here. `IsBareMetal` should at least be virtual and overridden in 
> concrete implementation of baremetal toolchains. `IsRISCVBareMetal` should 
> not be here at all.
> What was wrong with the previous implementation that made you move the 
> methods here?
There is a need to check for IsBareMetal and variants. They can't be made 
virtual since the checks need to happen before instantiating ToolChain class. I 
think moving them to Triple class (Triple.h) is a clearer option.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131225

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


[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-08 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 450894.
manojgupta added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Moved Baremetal triple related code to Triple.h.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131225

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/armv7m-vendor-none-eabi/libclang_rt.builtins.a
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/print-libgcc-file-name-clangrt.c
  llvm/include/llvm/ADT/Triple.h

Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -912,6 +912,57 @@
 return Env == Triple::GNUX32 || Env == Triple::MuslX32;
   }
 
+  /// Tests if the target is {arm,thumb}-none-none-{eabi,eabihf}.
+  bool isARMBareMetal() const {
+if (getArch() != Triple::arm && getArch() != Triple::thumb)
+  return false;
+
+if (getVendor() != Triple::UnknownVendor)
+  return false;
+
+if (getOS() != Triple::UnknownOS)
+  return false;
+
+if (getEnvironment() != Triple::EABI &&
+getEnvironment() != Triple::EABIHF)
+  return false;
+
+return true;
+  }
+
+  /// Tests if the target is aarch64-none-elf.
+  bool isAArch64BareMetal() const {
+if (getArch() != Triple::aarch64)
+  return false;
+
+if (getVendor() != Triple::UnknownVendor)
+  return false;
+
+if (getOS() != Triple::UnknownOS)
+  return false;
+
+return getEnvironmentName() == "elf";
+  }
+
+  /// Tests if the target is riscv-none-none-elf.
+  bool isRISCVBareMetal() const {
+if (getArch() != Triple::riscv32 && getArch() != llvm::Triple::riscv64)
+  return false;
+
+if (getVendor() != Triple::UnknownVendor)
+  return false;
+
+if (getOS() != Triple::UnknownOS)
+  return false;
+
+return getEnvironmentName() == "elf";
+  }
+
+  /// Tests if this is a bare metal target.
+  bool isBareMetal() const {
+return isARMBareMetal() || isAArch64BareMetal() || isRISCVBareMetal();
+  }
+
   /// Tests whether the target supports comdat
   bool supportsCOMDAT() const {
 return !(isOSBinFormatMachO() || isOSBinFormatXCOFF());
Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -48,3 +48,9 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s
 // CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: --target=armv7m-vendor-none-eabi \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET %s
+// CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET: libclang_rt.builtins.a
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -31,6 +31,20 @@
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
 // CHECK-V6M-LIBINC-NOT: "-internal-isystem"
 
+// RUN: %clang -no-canonical-prefixes -rtlib=compiler-rt %s -### -o %t.o 2>&1 \
+// RUN: -target armv7m-vendor-none-eabi \
+// RUN: --sysroot=%S/Inputs/baremetal_arm \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7M-PER-TARGET %s
+// CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
+// CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
+// CHECK-ARMV7M-PER-TARGET: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
+// CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
+// CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
+// CHECK-ARMV7M-PER-TARGET: "-o" "{{.*}}.o"
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target armv6m-none-eabi \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.h
===
--- clang/lib/Driver/ToolChains/BareMetal.h
+++ clang/lib/Driver/ToolChains/BareMetal.h
@@ -25,19 +25,11 @@
 const llvm::opt::ArgList &Args);
   ~BareMetal() override = default;
 
-  static bool handlesTarget(const llvm::Triple &Triple);
-
   void findMultilibs(const Driver &D, const 

[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-08 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added inline comments.



Comment at: clang/include/clang/Driver/ToolChain.h:388
+  /// IsRISCVBareMetal - Does this tool chain is a riscv baremetal target.
+  static bool IsRISCVBareMetal(const llvm::Triple &);
+

barannikov88 wrote:
> barannikov88 wrote:
> > manojgupta wrote:
> > > barannikov88 wrote:
> > > > The ToolChain class is an interface class. It is strange to see such 
> > > > kind of methods here. `IsBareMetal` should at least be virtual and 
> > > > overridden in concrete implementation of baremetal toolchains. 
> > > > `IsRISCVBareMetal` should not be here at all.
> > > > What was wrong with the previous implementation that made you move the 
> > > > methods here?
> > > There is a need to check for IsBareMetal and variants. They can't be made 
> > > virtual since the checks need to happen before instantiating ToolChain 
> > > class. I think moving them to Triple class (Triple.h) is a clearer option.
> > > I think moving them to Triple class (Triple.h) is a clearer option.
> > Is the triple is all that is necessary to decide whether the target is bare 
> > metal or not?
> > Sounds interesting, but one may argue that Triple should not know about 
> > toolchains (like it should not know about C data type bit widths, for 
> > example).
> > What if just add a few switch-cases to Driver::getToolChain as for every 
> > other toolchain? Retaining the former static method 
> > 'BareMetalToolChain::handlesTarget' is still better in my opinion.
> > They can't be made virtual since the checks need to happen before 
> > instantiating ToolChain class. 
> 
> This is kind of two different things. It can be made virtual. The name of the 
> method `IsBareMetal` of the `ToolChain` class suggests that it is checking 
> whether //this concrete instance// of the ToolChain is baremetal. This 
> (virtual) method could be used in getCompilerRTPath, for example.
> To //instantiate// BareMetalToolchain you need another function (like the 
> former BareMetalToolChain::handlesTarget, or the suggested approach with 
> Triple). For these instantiations `IsBareMetal` will return true, and false 
> for all other instantiations which are not bare metal.
> 
>Is the triple is all that is necessary to decide whether the target is bare 
>metal or not?

At least for baremetal, from what I see, triple seems to be the way how 
baremetal toolchain is decided in practice.

Examples: 
1. https://gitweb.gentoo.org/proj/crossdev.git/tree/crossdev#n331 ( 
# Bare metal targets*-newlib|*-elf|*-eabi|*-rtems*)
2. https://elinux.org/images/1/15/Anatomy_of_Cross-Compilation_Toolchains.pdf ( 
arm-foo-none-eabi, bare-metal toolchain targeting the ARM architecture, from
vendor foo )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131225

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


[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-08 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 450898.
manojgupta added a comment.
Herald added a subscriber: hiraditya.

Moved defs to Triple.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131225

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/armv7m-vendor-none-eabi/libclang_rt.builtins.a
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/print-libgcc-file-name-clangrt.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp

Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -1932,6 +1932,52 @@
   }
 }
 
+bool Triple::isARMBareMetal() const {
+  if (getArch() != llvm::Triple::arm && getArch() != Triple::thumb)
+return false;
+
+  if (getVendor() != llvm::Triple::UnknownVendor)
+return false;
+
+  if (getOS() != llvm::Triple::UnknownOS)
+return false;
+
+  if (getEnvironment() != llvm::Triple::EABI &&
+  getEnvironment() != llvm::Triple::EABIHF)
+return false;
+
+  return true;
+}
+
+bool Triple::isAArch64BareMetal() const {
+  if (getArch() != llvm::Triple::aarch64)
+return false;
+
+  if (getVendor() != llvm::Triple::UnknownVendor)
+return false;
+
+  if (getOS() != llvm::Triple::UnknownOS)
+return false;
+
+  return getEnvironmentName() == "elf";
+}
+
+bool Triple::isRISCVBareMetal() const {
+  if (getArch() != llvm::Triple::riscv32 && getArch() != llvm::Triple::riscv64)
+return false;
+
+  if (getVendor() != llvm::Triple::UnknownVendor)
+return false;
+
+  if (getOS() != llvm::Triple::UnknownOS)
+return false;
+
+  return getEnvironmentName() == "elf";
+}
+
+bool Triple::isBareMetal() const {
+  return isARMBareMetal() || isAArch64BareMetal() || isRISCVBareMetal();
+}
 // HLSL triple environment orders are relied on in the front end
 static_assert(Triple::Vertex - Triple::Pixel == 1,
   "incorrect HLSL stage order");
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -912,6 +912,18 @@
 return Env == Triple::GNUX32 || Env == Triple::MuslX32;
   }
 
+  /// Tests if the target is {arm,thumb}-none-none-{eabi,eabihf}.
+  bool isARMBareMetal() const;
+
+  /// Tests if the target is aarch64-none-elf.
+  bool isAArch64BareMetal() const;
+
+  /// Tests if the target is riscv-none-none-elf.
+  bool isRISCVBareMetal() const;
+
+  /// Tests if this is a bare metal target.
+  bool isBareMetal() const;
+
   /// Tests whether the target supports comdat
   bool supportsCOMDAT() const {
 return !(isOSBinFormatMachO() || isOSBinFormatXCOFF());
Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -48,3 +48,9 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s
 // CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: --target=armv7m-vendor-none-eabi \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET %s
+// CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET: libclang_rt.builtins.a
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -31,6 +31,20 @@
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
 // CHECK-V6M-LIBINC-NOT: "-internal-isystem"
 
+// RUN: %clang -no-canonical-prefixes -rtlib=compiler-rt %s -### -o %t.o 2>&1 \
+// RUN: -target armv7m-vendor-none-eabi \
+// RUN: --sysroot=%S/Inputs/baremetal_arm \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7M-PER-TARGET %s
+// CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
+// CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
+// CHECK-ARMV7M-PER-TARGET: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
+// CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
+// CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
+// CHECK-ARMV7M-PER-TARGET: "-o" "{{.*}}.o"
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>

[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-08 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 450908.
manojgupta added a comment.

Address style nits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131225

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/armv7m-vendor-none-eabi/libclang_rt.builtins.a
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/print-libgcc-file-name-clangrt.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp

Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -1932,6 +1932,52 @@
   }
 }
 
+bool Triple::isARMBareMetal() const {
+  if (getArch() != llvm::Triple::arm && getArch() != Triple::thumb)
+return false;
+
+  if (getVendor() != llvm::Triple::UnknownVendor)
+return false;
+
+  if (getOS() != llvm::Triple::UnknownOS)
+return false;
+
+  if (getEnvironment() != llvm::Triple::EABI &&
+  getEnvironment() != llvm::Triple::EABIHF)
+return false;
+
+  return true;
+}
+
+bool Triple::isAArch64BareMetal() const {
+  if (getArch() != llvm::Triple::aarch64)
+return false;
+
+  if (getVendor() != llvm::Triple::UnknownVendor)
+return false;
+
+  if (getOS() != llvm::Triple::UnknownOS)
+return false;
+
+  return getEnvironmentName() == "elf";
+}
+
+bool Triple::isRISCVBareMetal() const {
+  if (getArch() != llvm::Triple::riscv32 && getArch() != llvm::Triple::riscv64)
+return false;
+
+  if (getVendor() != llvm::Triple::UnknownVendor)
+return false;
+
+  if (getOS() != llvm::Triple::UnknownOS)
+return false;
+
+  return getEnvironmentName() == "elf";
+}
+
+bool Triple::isBareMetal() const {
+  return isARMBareMetal() || isAArch64BareMetal() || isRISCVBareMetal();
+}
 // HLSL triple environment orders are relied on in the front end
 static_assert(Triple::Vertex - Triple::Pixel == 1,
   "incorrect HLSL stage order");
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -912,6 +912,18 @@
 return Env == Triple::GNUX32 || Env == Triple::MuslX32;
   }
 
+  /// Tests if the target is {arm,thumb}-none-none-{eabi,eabihf}.
+  bool isARMBareMetal() const;
+
+  /// Tests if the target is aarch64-none-elf.
+  bool isAArch64BareMetal() const;
+
+  /// Tests if the target is riscv-none-none-elf.
+  bool isRISCVBareMetal() const;
+
+  /// Tests if this is a bare metal target.
+  bool isBareMetal() const;
+
   /// Tests whether the target supports comdat
   bool supportsCOMDAT() const {
 return !(isOSBinFormatMachO() || isOSBinFormatXCOFF());
Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -48,3 +48,9 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s
 // CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: --target=armv7m-vendor-none-eabi \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET %s
+// CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET: libclang_rt.builtins.a
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -31,6 +31,20 @@
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
 // CHECK-V6M-LIBINC-NOT: "-internal-isystem"
 
+// RUN: %clang -no-canonical-prefixes -rtlib=compiler-rt %s -### -o %t.o 2>&1 \
+// RUN: -target armv7m-vendor-none-eabi \
+// RUN: --sysroot=%S/Inputs/baremetal_arm \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7M-PER-TARGET %s
+// CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
+// CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
+// CHECK-ARMV7M-PER-TARGET: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
+// CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
+// CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
+// CHECK-ARMV7M-PER-TARGET: "-o" "{{.*}}.o"
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target armv6m-none-eabi 

[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-08 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 450910.
manojgupta added a comment.

Address more style lints.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131225

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/armv7m-vendor-none-eabi/libclang_rt.builtins.a
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/print-libgcc-file-name-clangrt.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp

Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -1932,6 +1932,51 @@
   }
 }
 
+bool Triple::isARMBareMetal() const {
+  if (getArch() != arm && getArch() != thumb)
+return false;
+
+  if (getVendor() != UnknownVendor)
+return false;
+
+  if (getOS() != UnknownOS)
+return false;
+
+  if (getEnvironment() != EABI && getEnvironment() != EABIHF)
+return false;
+
+  return true;
+}
+
+bool Triple::isAArch64BareMetal() const {
+  if (getArch() != aarch64)
+return false;
+
+  if (getVendor() != UnknownVendor)
+return false;
+
+  if (getOS() != UnknownOS)
+return false;
+
+  return getEnvironmentName() == "elf";
+}
+
+bool Triple::isRISCVBareMetal() const {
+  if (getArch() != riscv32 && getArch() != riscv64)
+return false;
+
+  if (getVendor() != UnknownVendor)
+return false;
+
+  if (getOS() != UnknownOS)
+return false;
+
+  return getEnvironmentName() == "elf";
+}
+
+bool Triple::isBareMetal() const {
+  return isARMBareMetal() || isAArch64BareMetal() || isRISCVBareMetal();
+}
 // HLSL triple environment orders are relied on in the front end
 static_assert(Triple::Vertex - Triple::Pixel == 1,
   "incorrect HLSL stage order");
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -912,6 +912,18 @@
 return Env == Triple::GNUX32 || Env == Triple::MuslX32;
   }
 
+  /// Tests if the target is {arm,thumb}-none-none-{eabi,eabihf}.
+  bool isARMBareMetal() const;
+
+  /// Tests if the target is aarch64-none-elf.
+  bool isAArch64BareMetal() const;
+
+  /// Tests if the target is riscv-none-none-elf.
+  bool isRISCVBareMetal() const;
+
+  /// Tests if this is a bare metal target.
+  bool isBareMetal() const;
+
   /// Tests whether the target supports comdat
   bool supportsCOMDAT() const {
 return !(isOSBinFormatMachO() || isOSBinFormatXCOFF());
Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -48,3 +48,9 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s
 // CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: --target=armv7m-vendor-none-eabi \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET %s
+// CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET: libclang_rt.builtins.a
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -31,6 +31,20 @@
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
 // CHECK-V6M-LIBINC-NOT: "-internal-isystem"
 
+// RUN: %clang -no-canonical-prefixes -rtlib=compiler-rt %s -### -o %t.o 2>&1 \
+// RUN: -target armv7m-vendor-none-eabi \
+// RUN: --sysroot=%S/Inputs/baremetal_arm \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7M-PER-TARGET %s
+// CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
+// CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
+// CHECK-ARMV7M-PER-TARGET: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
+// CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
+// CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
+// CHECK-ARMV7M-PER-TARGET: "-o" "{{.*}}.o"
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target armv6m-none-eabi \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.h
===
--- clang/l

[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-08 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added inline comments.



Comment at: clang/lib/Driver/ToolChains/BareMetal.cpp:228-237
+  case ToolChain::RLT_CompilerRT: {
+const std::string fileName = getCompilerRT(Args, "builtins");
+std::string baseName = llvm::sys::path::filename(fileName).str();
+llvm::StringRef baseNameRef(baseName);
+baseNameRef.consume_front("lib");
+baseNameRef.consume_back(".a");
 CmdArgs.push_back(

barannikov88 wrote:
> There are a few style issues.
> * `return` is usually within the braces
> * Variable names should start with capital letter
> * Looks like std::string could be avoided completely in favor of `StringRef` 
> and `Twine`
> 
> Same applies to ConstructJob below, there are also redundant braces in `for` 
> statement.
Addressed most.
std::string is needed initially to avoid dangling storage issue:

warning: object backing the pointer will be destroyed at the end of the 
full-expression [-Wdangling-gsl]


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131225

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


[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 451222.
manojgupta added a comment.

Address maskray comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131225

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/armv7m-vendor-none-eabi/libclang_rt.builtins.a
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/print-libgcc-file-name-clangrt.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp

Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -1932,6 +1932,45 @@
   }
 }
 
+bool Triple::isARMBareMetal() const {
+  if (getArch() != arm && getArch() != thumb)
+return false;
+  if (getVendor() != UnknownVendor)
+return false;
+  if (getOS() != UnknownOS)
+return false;
+  if (getEnvironment() != EABI && getEnvironment() != EABIHF)
+return false;
+
+  return true;
+}
+
+bool Triple::isAArch64BareMetal() const {
+  if (getArch() != aarch64)
+return false;
+  if (getVendor() != UnknownVendor)
+return false;
+  if (getOS() != UnknownOS)
+return false;
+
+  return getEnvironmentName() == "elf";
+}
+
+bool Triple::isRISCVBareMetal() const {
+  if (getArch() != riscv32 && getArch() != riscv64)
+return false;
+  if (getVendor() != UnknownVendor)
+return false;
+  if (getOS() != UnknownOS)
+return false;
+
+  return getEnvironmentName() == "elf";
+}
+
+bool Triple::isBareMetal() const {
+  return isARMBareMetal() || isAArch64BareMetal() || isRISCVBareMetal();
+}
+
 // HLSL triple environment orders are relied on in the front end
 static_assert(Triple::Vertex - Triple::Pixel == 1,
   "incorrect HLSL stage order");
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -912,6 +912,18 @@
 return Env == Triple::GNUX32 || Env == Triple::MuslX32;
   }
 
+  /// Tests if the target is {arm,thumb}-none-none-{eabi,eabihf}.
+  bool isARMBareMetal() const;
+
+  /// Tests if the target is aarch64-none-elf.
+  bool isAArch64BareMetal() const;
+
+  /// Tests if the target is riscv-none-none-elf.
+  bool isRISCVBareMetal() const;
+
+  /// Tests if this is a bare metal target.
+  bool isBareMetal() const;
+
   /// Tests whether the target supports comdat
   bool supportsCOMDAT() const {
 return !(isOSBinFormatMachO() || isOSBinFormatXCOFF());
Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -48,3 +48,9 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s
 // CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: --target=armv7m-vendor-none-eabi \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET %s
+// CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET: libclang_rt.builtins.a
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -31,6 +31,20 @@
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
 // CHECK-V6M-LIBINC-NOT: "-internal-isystem"
 
+// RUN: %clang -no-canonical-prefixes -rtlib=compiler-rt %s -### -o %t.o 2>&1 \
+// RUN: -target armv7m-vendor-none-eabi \
+// RUN: --sysroot=%S/Inputs/baremetal_arm \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7M-PER-TARGET %s
+// CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
+// CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
+// CHECK-ARMV7M-PER-TARGET: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
+// CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
+// CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
+// CHECK-ARMV7M-PER-TARGET: "-o" "{{.*}}.o"
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target armv6m-none-eabi \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.h
===
--- clang/lib/Driver/To

[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 451325.
manojgupta added a comment.

Fix clang-format complains.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131225

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/armv7m-vendor-none-eabi/libclang_rt.builtins.a
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/print-libgcc-file-name-clangrt.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp

Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -1932,6 +1932,45 @@
   }
 }
 
+bool Triple::isARMBareMetal() const {
+  if (getArch() != arm && getArch() != thumb)
+return false;
+  if (getVendor() != UnknownVendor)
+return false;
+  if (getOS() != UnknownOS)
+return false;
+  if (getEnvironment() != EABI && getEnvironment() != EABIHF)
+return false;
+
+  return true;
+}
+
+bool Triple::isAArch64BareMetal() const {
+  if (getArch() != aarch64)
+return false;
+  if (getVendor() != UnknownVendor)
+return false;
+  if (getOS() != UnknownOS)
+return false;
+
+  return getEnvironmentName() == "elf";
+}
+
+bool Triple::isRISCVBareMetal() const {
+  if (getArch() != riscv32 && getArch() != riscv64)
+return false;
+  if (getVendor() != UnknownVendor)
+return false;
+  if (getOS() != UnknownOS)
+return false;
+
+  return getEnvironmentName() == "elf";
+}
+
+bool Triple::isBareMetal() const {
+  return isARMBareMetal() || isAArch64BareMetal() || isRISCVBareMetal();
+}
+
 // HLSL triple environment orders are relied on in the front end
 static_assert(Triple::Vertex - Triple::Pixel == 1,
   "incorrect HLSL stage order");
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -912,6 +912,18 @@
 return Env == Triple::GNUX32 || Env == Triple::MuslX32;
   }
 
+  /// Tests if the target is {arm,thumb}-none-none-{eabi,eabihf}.
+  bool isARMBareMetal() const;
+
+  /// Tests if the target is aarch64-none-elf.
+  bool isAArch64BareMetal() const;
+
+  /// Tests if the target is riscv-none-none-elf.
+  bool isRISCVBareMetal() const;
+
+  /// Tests if this is a bare metal target.
+  bool isBareMetal() const;
+
   /// Tests whether the target supports comdat
   bool supportsCOMDAT() const {
 return !(isOSBinFormatMachO() || isOSBinFormatXCOFF());
Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -48,3 +48,9 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s
 // CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: --target=armv7m-vendor-none-eabi \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET %s
+// CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET: libclang_rt.builtins.a
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -31,6 +31,20 @@
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
 // CHECK-V6M-LIBINC-NOT: "-internal-isystem"
 
+// RUN: %clang -no-canonical-prefixes -rtlib=compiler-rt %s -### -o %t.o 2>&1 \
+// RUN: -target armv7m-vendor-none-eabi \
+// RUN: --sysroot=%S/Inputs/baremetal_arm \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7M-PER-TARGET %s
+// CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
+// CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
+// CHECK-ARMV7M-PER-TARGET: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
+// CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
+// CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
+// CHECK-ARMV7M-PER-TARGET: "-o" "{{.*}}.o"
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target armv6m-none-eabi \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.h
===
--- clang/lib/Driver/

[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 451352.
manojgupta added a comment.

Going back to older handlesTarget() style in Baremetal.
Apparently RISCV can be both Baremetal or RISCVToolchain for the
same tuple. I do not know of the nuances so trying not to disturb that for
now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131225

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/armv7m-vendor-none-eabi/libclang_rt.builtins.a
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/print-libgcc-file-name-clangrt.c

Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -48,3 +48,9 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s
 // CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: --target=armv7m-vendor-none-eabi \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET %s
+// CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET: libclang_rt.builtins.a
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -31,6 +31,20 @@
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
 // CHECK-V6M-LIBINC-NOT: "-internal-isystem"
 
+// RUN: %clang -no-canonical-prefixes -rtlib=compiler-rt %s -### -o %t.o 2>&1 \
+// RUN: -target armv7m-vendor-none-eabi \
+// RUN: --sysroot=%S/Inputs/baremetal_arm \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7M-PER-TARGET %s
+// CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
+// CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
+// CHECK-ARMV7M-PER-TARGET: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
+// CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
+// CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
+// CHECK-ARMV7M-PER-TARGET: "-o" "{{.*}}.o"
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target armv6m-none-eabi \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.h
===
--- clang/lib/Driver/ToolChains/BareMetal.h
+++ clang/lib/Driver/ToolChains/BareMetal.h
@@ -1,4 +1,5 @@
-//===--- BareMetal.h - Bare Metal Tool and ToolChain -*- C++ -*-===//
+//===--- BareMetal.h - Bare Metal Tool and ToolChain -*- C++
+//-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -33,13 +34,9 @@
 protected:
   Tool *buildLinker() const override;
 
-  std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args,
-  StringRef Component,
-  FileType Type = ToolChain::FT_Static,
-  bool AddArch = true) const override;
-
 public:
   bool useIntegratedAs() const override { return true; }
+  bool isBareMetal() const override { return true; }
   bool isCrossCompiling() const override { return true; }
   bool isPICDefault() const override { return false; }
   bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
@@ -50,8 +47,6 @@
 
   StringRef getOSLibName() const override { return "baremetal"; }
 
-  std::string getCompilerRTPath() const override;
-
   RuntimeLibType GetDefaultRuntimeLibType() const override {
 return ToolChain::RLT_CompilerRT;
   }
@@ -61,12 +56,13 @@
 
   const char *getDefaultLinker() const override { return "ld.lld"; }
 
-  std::string getRuntimesDir() const;
-  void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
- llvm::opt::ArgStringList &CC1Args) const override;
-  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
- llvm::opt::ArgStringList &CC1Args,
- Action::OffloadKind DeviceOffloadKind) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::Ar

[PATCH] D131225: Driver: Refactor and support per target dirs in baremetal

2022-08-10 Thread Manoj Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG06fc5a771462: Driver: Refactor and support per target dirs 
in baremetal (authored by manojgupta).

Changed prior to commit:
  https://reviews.llvm.org/D131225?vs=451352&id=451517#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131225

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/armv7m-vendor-none-eabi/libclang_rt.builtins.a
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/print-libgcc-file-name-clangrt.c

Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -48,3 +48,9 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s
 // CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: --target=armv7m-vendor-none-eabi \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET %s
+// CHECK-CLANGRT-ARM-BAREMETAL-PER-TARGET: libclang_rt.builtins.a
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -31,6 +31,20 @@
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
 // CHECK-V6M-LIBINC-NOT: "-internal-isystem"
 
+// RUN: %clang -no-canonical-prefixes -rtlib=compiler-rt %s -### -o %t.o 2>&1 \
+// RUN: -target armv7m-vendor-none-eabi \
+// RUN: --sysroot=%S/Inputs/baremetal_arm \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7M-PER-TARGET %s
+// CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
+// CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
+// CHECK-ARMV7M-PER-TARGET: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
+// CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
+// CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
+// CHECK-ARMV7M-PER-TARGET: "-o" "{{.*}}.o"
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target armv6m-none-eabi \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.h
===
--- clang/lib/Driver/ToolChains/BareMetal.h
+++ clang/lib/Driver/ToolChains/BareMetal.h
@@ -1,4 +1,4 @@
-//===--- BareMetal.h - Bare Metal Tool and ToolChain -*- C++ -*-===//
+//===--- BareMetal.h - Bare Metal Tool and ToolChain *- C++-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -33,13 +33,9 @@
 protected:
   Tool *buildLinker() const override;
 
-  std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args,
-  StringRef Component,
-  FileType Type = ToolChain::FT_Static,
-  bool AddArch = true) const override;
-
 public:
   bool useIntegratedAs() const override { return true; }
+  bool isBareMetal() const override { return true; }
   bool isCrossCompiling() const override { return true; }
   bool isPICDefault() const override { return false; }
   bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
@@ -50,8 +46,6 @@
 
   StringRef getOSLibName() const override { return "baremetal"; }
 
-  std::string getCompilerRTPath() const override;
-
   RuntimeLibType GetDefaultRuntimeLibType() const override {
 return ToolChain::RLT_CompilerRT;
   }
@@ -61,12 +55,13 @@
 
   const char *getDefaultLinker() const override { return "ld.lld"; }
 
-  std::string getRuntimesDir() const;
-  void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
- llvm::opt::ArgStringList &CC1Args) const override;
-  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
- llvm::opt::ArgStringList &CC1Args,
- Action::OffloadKind DeviceOffloadKind) const override;
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringL

[PATCH] D121328: Disable -Wmissing-prototypes for internal linkage functions that aren't explicitly marked "static"""

2022-03-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

For the background, we had hit this in Chrome OS when building bluetooth code.

This is the one of structs hitting the issue where the warning got promoted to 
an error:

typedef struct {

private:

  static std::string AppendCapability(std::string& result, bool append,
  const std::string& name) {
   
  }

} btav_a2dp_codec_config_t;

Previously this was a warning that was suppressed in this code upstream using 
-Wno-non-c-typedef-for-linkage  but now it turns into a non-suppressible error.

The exact code actually comes from aosp, but this is the Chrome OS public 
accessible copy:
https://chromium.googlesource.com/aosp/platform/packages/modules/Bluetooth/+/main/system/include/hardware/bt_av.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121328

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


[PATCH] D123300: [Clang] Enable opaque pointers by default

2022-04-14 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

We noticed a new crash that still repros at head.

clang -target armv7a-linux-gnueabihf -march=armv8a -mthumb -c -O2 file.cc

llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10135: llvm::Value 
*llvm::VPTransformState::get(llvm::VPValue *, unsigned int): Assertion 
`(isa(Def->getDef()) || 
isa(Def->getDef())) && "unexpected recipe found to be 
invariant"' failed.

   C
  struct b;
  struct c {
using a = b *;
  };
  struct d {
d(c::a);
  };
  struct g;
  struct i {
typedef g *a;
  };
  struct g {
typedef i::a e;
e f;
  } * h;
  struct o {
typedef g ::e e;
  };
  struct p;
  struct H {
typedef g &a;
  };
  template  struct q;
  template  struct q {
static bq *bu(H::a r) {
  g &j = r;
  h = &j;
  return h;
}
  };
  struct s : g {
e cf() { return q::bu(*this); }
  };
  struct t {
s ck;
  };
  template  struct K {
typedef cg bf;
typedef typename bf::ce ce;
struct cs {
  cs(bf) {}
  t cp;
} co;
K() : co(bf()) {
  typename ce::e k = co.cp.ck.cf();
  k->f = k;
}
  };
  struct L {
typedef K a;
  };
  struct p {
typedef o ce;
  };
  struct b : L::a {};
  struct M {
int l;
using m = b;
d n{new m[l]};
  };
  void u() { new M; }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123300

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


[PATCH] D122895: [C89/C2x] Improve diagnostics around strict prototypes in C

2022-04-28 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Some of our users are not very happy with the churn probably caused by this 
change where the declaration has the "void" argument but the later definition 
does not have explicit "void".

  void foo(void);
  
  void foo() 
  {
  }

GCC  does not warn about this usage: https://godbolt.org/z/zPP8qjc98

Any opinions?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122895

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


[PATCH] D122895: [C89/C2x] Improve diagnostics around strict prototypes in C

2022-04-29 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

  Is disabling the pedantic warning an option for your users?

Disabling it wholesale is not an option since they actually want this warning  
(the older version). But we agreed to disable it specifically for the code 
where the warning was getting fired.
One instance is https://review.coreboot.org/c/coreboot/+/63936 .

I have been fixing our codebase to clean this and clean the instances. But it 
takes a lot of time and effort. Plus it takes a long time to clean one failure 
before I can find others  (public CLs) 
https://chromium-review.googlesource.com/q/Wstrict-prototypes+owner:manojgupta


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122895

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


[PATCH] D122895: [C89/C2x] Improve diagnostics around strict prototypes in C

2022-04-29 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

  Basically, I'm wondering if you'd be able to enable -fno-knr-function?

Thanks. this looks promising. Any ideas when  -fno-knr-function support was 
added?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122895

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


[PATCH] D122895: [C89/C2x] Improve diagnostics around strict prototypes in C

2022-04-29 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Unless I  probably mis-interpreted something, -fno-knr-functions does not 
suppress the warning:  https://godbolt.org/z/rbEfbbb33


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122895

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


[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-30 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

We are finding a lot of failures in our ToT builds with this change. here is an 
example for a configure script:

$ cat tent.c
int  main ()
{
 tgetent(0,0);
 return 0;
}
$ bin/clang -c tent.c -Wno-error
tent.c:3:2: error: call to undeclared function 'tgetent'; ISO C99 and later do 
not support implicit function declarations [-Wimplicit-function-declaration]
 tgetent(0,0);
 ^
1 error generated.

It feels very surprising that Wno-error does not suppress this warning. Is that 
expected?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122983

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


[PATCH] D122895: [C89/C2x] Improve diagnostics around strict prototypes in C

2022-04-30 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Tried locally but I still see the warning with -fno-knr-functions. It also says 
that the argument is unused.

bin/clang --version
clang version 15.0.0 (https://github.com/llvm/llvm-project.git 
a9d68a5524dea113cace5983697786599cbdce9a 
)
Target: x86_64-unknown-linux-gnu

$ cat pr.c
void foo(void);

void foo() 
{
}
$ bin/clang -c pr.c -Wstrict-prototypes -fno-knr-functions
clang-14: warning: argument unused during compilation: '-fno-knr-functions' 
[-Wunused-command-line-argument]
pr.c:3:9: warning: a function declaration without a prototype is deprecated in 
all versions of C [-Wstrict-prototypes]
void foo()

  ^
   void

1 warning generated.

It works if -fno-knr-functions is passed with Xclang .  Is it intentional that 
-fno-knr-functions is only a cc1 option? That makes it very hard for us to 
enable it.

$ bin/clang -c pr.c -Wstrict-prototypes -Xclang -fno-knr-functions (no warnings)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122895

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


[PATCH] D122895: [C89/C2x] Improve diagnostics around strict prototypes in C

2022-04-30 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Following behavior is also surprising:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122895

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


[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-30 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Hmm, the commit message says that Wno-error should work but this is not really 
the case :(.

> (they can disable the warning or use -Wno-error to downgrade the
> error


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122983

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


[PATCH] D87901: [Driver] Filter out /gcc and /gcc-cross if they do not exists

2020-09-26 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:1949
+  // Maybe filter out /gcc and /gcc-cross.
+  GCCDirExists = D.getVFS().exists(LibDir + "/gcc");
+  GCCCrossDirExists = D.getVFS().exists(LibDir + "/gcc-cross");

Since these are class fields, please initialize these to false in beginning of 
the function. Otherwise, it might be tempting to use them elsewhere where they 
may not be initialized.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87901

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


[PATCH] D87143: Check whether Gentoo-specific configuration directory exists

2020-09-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a reviewer: mgorny.
manojgupta added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2537-2538
 const SmallVectorImpl &CandidateBiarchTriples) {
+  if (!D.getVFS().exists(GentooConfigDir))
+return false;
+

I think it should be D.SysRoot + GentooConfigDir. Otherwise, there is no way to 
test a Gentoo configuration tests on a non-Gentoo machine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87143

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


[PATCH] D87143: Check whether Gentoo-specific configuration directory exists

2020-09-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta accepted this revision.
manojgupta added a comment.
This revision is now accepted and ready to land.

Looks ok to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87143

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


[PATCH] D89327: fixes compiler-rt bug when printing libgcc for baremetal

2020-10-14 Thread Manoj Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG18432bea7648: [Driver]: fix compiler-rt path when printing 
libgcc for baremetal (authored by cjdb, committed by manojgupta).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D89327?vs=297924&id=298180#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89327

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  clang/test/Driver/print-libgcc-file-name-clangrt.c


Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -42,3 +42,9 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-ABI %s
 // CHECK-CLANGRT-ARM-ABI: libclang_rt.builtins-armhf.a
+
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: --target=armv7m-none-eabi \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM-BAREMETAL %s
+// CHECK-CLANGRT-ARM-BAREMETAL: libclang_rt.builtins-armv7m.a
Index: clang/lib/Driver/ToolChains/BareMetal.h
===
--- clang/lib/Driver/ToolChains/BareMetal.h
+++ clang/lib/Driver/ToolChains/BareMetal.h
@@ -23,7 +23,7 @@
 public:
   BareMetal(const Driver &D, const llvm::Triple &Triple,
 const llvm::opt::ArgList &Args);
-  ~BareMetal() override;
+  ~BareMetal() override = default;
 
   static bool handlesTarget(const llvm::Triple &Triple);
 protected:
@@ -37,6 +37,14 @@
   bool isPICDefaultForced() const override { return false; }
   bool SupportsProfiling() const override { return false; }
 
+  StringRef getOSLibName() const override { return "baremetal"; }
+
+  std::string getCompilerRTPath() const override;
+  std::string getCompilerRTBasename(const llvm::opt::ArgList &Args,
+StringRef Component,
+FileType Type = ToolChain::FT_Static,
+bool AddArch = true) const override;
+
   RuntimeLibType GetDefaultRuntimeLibType() const override {
 return ToolChain::RLT_CompilerRT;
   }
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -35,8 +35,6 @@
 getProgramPaths().push_back(getDriver().Dir);
 }
 
-BareMetal::~BareMetal() {}
-
 /// Is the triple {arm,thumb}-none-none-{eabi,eabihf} ?
 static bool isARMBareMetal(const llvm::Triple &Triple) {
   if (Triple.getArch() != llvm::Triple::arm &&
@@ -64,6 +62,13 @@
   return new tools::baremetal::Linker(*this);
 }
 
+std::string BareMetal::getCompilerRTPath() const { return getRuntimesDir(); }
+
+std::string BareMetal::getCompilerRTBasename(const llvm::opt::ArgList &,
+ StringRef, FileType, bool) const {
+  return ("libclang_rt.builtins-" + getTriple().getArchName() + ".a").str();
+}
+
 std::string BareMetal::getRuntimesDir() const {
   SmallString<128> Dir(getDriver().ResourceDir);
   llvm::sys::path::append(Dir, "lib", "baremetal");
Index: clang/include/clang/Driver/ToolChain.h
===
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -419,10 +419,10 @@
   getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component,
  FileType Type = ToolChain::FT_Static) const;
 
-  std::string getCompilerRTBasename(const llvm::opt::ArgList &Args,
-StringRef Component,
-FileType Type = ToolChain::FT_Static,
-bool AddArch = true) const;
+  virtual std::string
+  getCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component,
+FileType Type = ToolChain::FT_Static,
+bool AddArch = true) const;
 
   // Returns target specific runtime path if it exists.
   virtual Optional getRuntimePath() const;
@@ -435,7 +435,7 @@
   std::string getArchSpecificLibPath() const;
 
   // Returns  part of above.
-  StringRef getOSLibName() const;
+  virtual StringRef getOSLibName() const;
 
   /// needsProfileRT - returns true if instrumentation profile is on.
   static bool needsProfileRT(const llvm::opt::ArgList &Args);


Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang

[PATCH] D92176: Don't use sysroot/include when sysroot is empty.

2020-11-26 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

lgtm but not an expert in this area.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92176

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


[PATCH] D52524: Add -Wpoison-system-directories warning

2021-05-20 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

An earlier version did check for library directories [1]. I am not exactly sure 
why was it removed, maybe it didn't work. So if anyone is willing to test that, 
please apply the diff and try.

[1] Diff https://reviews.llvm.org/D52524?id=215958


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

https://reviews.llvm.org/D52524

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


[PATCH] D99517: Implemented [[clang::musttail]] attribute for guaranteed tail calls.

2021-08-09 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Please also see https://bugs.llvm.org/show_bug.cgi?id=51416


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

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


[PATCH] D112091: libfuzzer: All building libfuzzer for ARM32

2021-10-28 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

@kcc do you have any concerns?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112091

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


[PATCH] D97894: [Driver] Drop $sysroot/usr special case from Gentoo gcc-config detection

2021-03-03 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Thanks @MaskRay for this clean up. I can't speak for all of Gentoo but please 
give me a couple of days to at least test this on Chrome OS.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97894

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


[PATCH] D97894: [Driver] Drop $sysroot/usr special case from Gentoo gcc-config detection

2021-03-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

In Chrome OS, we currently both "-B" and "--prefix". "-B" points to binutils 
bin directory and the "--prefix" has the binutils directory + target suffix. 
Should we drop "-B" and still get the same behavior?

Sample invocation: '/usr/bin/clang++' '--sysroot=/usr/x86_64-cros-linux-gnu 
'-fcrash-diagnostics-dir=/tmp/clang_crash_diagnostics' '-fcommon' 
'-fstack-protector-strong' '-fPIE' '-pie' '-D_FORTIFY_SOURCE=2' 
'-fno-omit-frame-pointer' 
'--prefix=../../../../../../usr/libexec/gcc/x86_64-cros-linux-gnu/x86_64-cros-linux-gnu-'
 'foo.o' '-o' 'main' 
'-B../../../../../../usr/libexec/gcc/x86_64-cros-linux-gnu' '-target' 
'x86_64-cros-linux-gnu'

I am not yet able to test this change in Chrome OS thoroughly yet because of 
some CQ issues. But manually checking the command lines for a few common cases 
does not show any difference so far.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97894

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


[PATCH] D97894: [Driver] Drop $sysroot/usr special case from Gentoo gcc-config detection

2021-03-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

> With the special rule, it is: if --gcc-toolchain is $sysroot/usr, suppress 
> sysroot GCC detection as well.
>
> Clang -B and --gcc-toolchain have some weird behaviors. Hope you can share 
> your opinions on 
> https://lists.llvm.org/pipermail/cfe-dev/2021-March/067827.html

Sure, I have replied on the thread with chrome os usage explanation. I also 
noticed that we also use "--gcc-toolchain" as well so the whole lot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97894

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


[PATCH] D97993: [Driver] Suppress GCC detection under -B for non-Android

2021-03-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

I am not sure of the rationale or upside of this change and why do we want to 
drop gcc detection? GCC does not need to do the GCC detection because it has 
the needed information at configure time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97993

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


[PATCH] D97902: [Driver] Clarify --gcc-toolchain

2021-03-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

thanks, this is much needed documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97902

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


[PATCH] D97993: [Driver] Suppress GCC detection under -B for non-Android

2021-03-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Thanks for explaining that it only affects "-B". While I believe that this 
change won't affect us in Chrome OS, I think it should be reviewed and approved 
by a few Linux distro contributors since there is already known reliance e.g. 
Android on the current behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97993

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


[PATCH] D97993: [Driver] Suppress GCC detection under -B for non-Android

2021-03-05 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Another concern is people generally want clang to work out of box without any 
special arguments.  As a user, after installing clang's distro package or 
building from source, I expect that basic compilation should work out-of-box 
which includes gcc detection.
i.e. "clang foo.cpp -o foo" should just work in most cases.

If a user now needs to pass "-gcc-toolchain" to find gcc libraries when it just 
used to work, that is most likely not desirable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97993

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


[PATCH] D97993: [Driver] Suppress GCC detection under -B for non-Android

2021-03-05 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a subscriber: tstellar.
manojgupta added a comment.

Thanks for the clarification. I do not have any objections but I feel that am 
not the right person to approve this change.
@tstellar can you please review it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97993

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


[PATCH] D97894: [Driver] Drop $sysroot/usr special case from Gentoo gcc-config detection

2021-03-11 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta accepted this revision.
manojgupta added a comment.

@MaskRay I have verified that Chrome OS builds are not affected by this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97894

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


[PATCH] D113779: [Clang] Add mfp16, mfp16fml and mdotprod flags for ARM target features.

2021-11-15 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Yes, the current approach of "-march=+feature" is terrible and does not 
work with developers who want flexibility of features. This being pitched as a 
feature imo is akin to promoting a design bug as a feature. 
Any additive or subtractive alternative is welcome.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113779

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


[PATCH] D112091: libfuzzer: All building libfuzzer for ARM32

2021-11-17 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a reviewer: morehouse.
manojgupta added a comment.

Matt, do you think you can review this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112091

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


[PATCH] D112091: libfuzzer: All building libfuzzer for ARM32

2021-11-18 Thread Manoj Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2782cb8da0b3: libfuzzer: All building libfuzzer for ARM32 
(authored by manojgupta).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112091

Files:
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake


Index: compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
===
--- compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -38,7 +38,7 @@
 endif()
 
 if(OS_NAME MATCHES "Linux")
-  set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${S390X})
+  set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${S390X})
 elseif (OS_NAME MATCHES "Windows")
   set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64})
 elseif(OS_NAME MATCHES "Android")


Index: compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
===
--- compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -38,7 +38,7 @@
 endif()
 
 if(OS_NAME MATCHES "Linux")
-  set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${S390X})
+  set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${S390X})
 elseif (OS_NAME MATCHES "Windows")
   set(ALL_FUZZER_SUPPORTED_ARCH ${X86} ${X86_64})
 elseif(OS_NAME MATCHES "Android")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113779: [Clang] Add mfp16, mfp16fml and mdotprod flags for ARM target features.

2021-11-18 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

> More subjective: for most users this whole -march business is abstracted away 
> in build systems, so they won't have to deal with this, that's why this isn't 
> so much of an improvement.



> If we want a better user experience set options, there are probably other 
> things that are more important, like checking legal/illegal architecture 
> combinations.



> So, in summary, we prefer not to go ahead with this. And the precedent that 
> was mentioned, -mcrc, should probably be deprecated.

I'd argue the contrary that the current way of -march=isa+feature is broken. I 
am yet to see a build system that understands or processes the values inside 
march arguments. And this blocks users from choosing custom hw features without 
resorting to terrible hacks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113779

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


[PATCH] D114312: libfuzzer: Disable broken tests for arm

2021-11-19 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.
manojgupta added reviewers: morehouse, metzman.
Herald added a subscriber: kristof.beyls.
manojgupta requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

libfuzzer was recently enabled for Arm32 in D112091 
.
A few tests apparently do not work with arm32 so disable them.
The list of tests was obtained from
https://lab.llvm.org/buildbot/#/builders/190/builds/513


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114312

Files:
  compiler-rt/test/fuzzer/acquire-crash-state.test
  compiler-rt/test/fuzzer/compressed.test
  compiler-rt/test/fuzzer/msan-custom-mutator.test
  compiler-rt/test/fuzzer/msan-param-unpoison.test
  compiler-rt/test/fuzzer/msan.test
  compiler-rt/test/fuzzer/sigint.test
  compiler-rt/test/fuzzer/value-profile-div.test


Index: compiler-rt/test/fuzzer/value-profile-div.test
===
--- compiler-rt/test/fuzzer/value-profile-div.test
+++ compiler-rt/test/fuzzer/value-profile-div.test
@@ -1,5 +1,5 @@
 UNSUPPORTED: ios
-UNSUPPORTED: aarch64
+UNSUPPORTED: arm, aarch64
 CHECK: AddressSanitizer: {{FPE|int-divide-by-zero}}
 RUN: %cpp_compiler %S/DivTest.cpp -fsanitize-coverage=trace-div -o %t-DivTest
 RUN: not %run %t-DivTest -seed=1 -use_value_profile=1 -runs=1000 2>&1 | 
FileCheck %s
Index: compiler-rt/test/fuzzer/sigint.test
===
--- compiler-rt/test/fuzzer/sigint.test
+++ compiler-rt/test/fuzzer/sigint.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 
 # Check that libFuzzer exits gracefully under SIGINT with MSan.
 RUN: rm -rf %t
Index: compiler-rt/test/fuzzer/msan.test
===
--- compiler-rt/test/fuzzer/msan.test
+++ compiler-rt/test/fuzzer/msan.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 RUN: %msan_compiler %S/SimpleTestStdio.cpp -o %t
 RUN: not %run %t -seed=1 -runs=1000 2>&1 | FileCheck %s 
--check-prefix=NO-REPORT
 
Index: compiler-rt/test/fuzzer/msan-param-unpoison.test
===
--- compiler-rt/test/fuzzer/msan-param-unpoison.test
+++ compiler-rt/test/fuzzer/msan-param-unpoison.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 RUN: %msan_compiler %S/MsanParamUnpoison.cpp -o %t
 RUN: %run %t -seed=1 -runs=1000 2>&1 | FileCheck %s
 
Index: compiler-rt/test/fuzzer/msan-custom-mutator.test
===
--- compiler-rt/test/fuzzer/msan-custom-mutator.test
+++ compiler-rt/test/fuzzer/msan-custom-mutator.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 RUN: %msan_compiler %S/MsanCustomMutator.cpp -o %t
 RUN: %run %t -seed=1 -runs=1000 2>&1 | FileCheck %s
 
Index: compiler-rt/test/fuzzer/compressed.test
===
--- compiler-rt/test/fuzzer/compressed.test
+++ compiler-rt/test/fuzzer/compressed.test
@@ -2,7 +2,7 @@
 REQUIRES: zlib
 # zlib is "supported" on i386 even when only for x86_64, explicitly make i386
 # unsupported by this test.
-UNSUPPORTED: i386
+UNSUPPORTED: i386, arm
 # Custom mutator should find this bug, w/o custom -- no chance.
 RUN: %cpp_compiler %S/CompressedTest.cpp -o %t-CompressedTestCustom 
-DCUSTOM_MUTATOR -lz
 RUN: %cpp_compiler %S/CompressedTest.cpp -o %t-CompressedTestPlain -lz
Index: compiler-rt/test/fuzzer/acquire-crash-state.test
===
--- compiler-rt/test/fuzzer/acquire-crash-state.test
+++ compiler-rt/test/fuzzer/acquire-crash-state.test
@@ -1,3 +1,4 @@
+UNSUPPORTED: arm
 RUN: %cpp_compiler %S/AcquireCrashStateTest.cpp -o %t
 RUN: %run %t 2>&1 | FileCheck %s
 CHECK-NOT: fuzz target exited


Index: compiler-rt/test/fuzzer/value-profile-div.test
===
--- compiler-rt/test/fuzzer/value-profile-div.test
+++ compiler-rt/test/fuzzer/value-profile-div.test
@@ -1,5 +1,5 @@
 UNSUPPORTED: ios
-UNSUPPORTED: aarch64
+UNSUPPORTED: arm, aarch64
 CHECK: AddressSanitizer: {{FPE|int-divide-by-zero}}
 RUN: %cpp_compiler %S/DivTest.cpp -fsanitize-coverage=trace-div -o %t-DivTest
 RUN: not %run %t-DivTest -seed=1 -use_value_profile=1 -runs=1000 2>&1 | FileCheck %s
Index: compiler-rt/test/fuzzer/sigint.test
===
--- compiler-rt/test/fuzzer/sigint.test
+++ compiler-rt/test/fuzzer/sigint.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 
 # Check that libFuzzer exits gracefully under SIGINT with MSan.
 RUN: rm -rf %t
Index: compiler-rt/test/fuzzer/msan.test
===
--- compiler-rt/test/fuzzer/msan.test
+++ compiler-rt/test/fuzzer/msan.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 RUN: %msan_compi

[PATCH] D114312: libfuzzer: Disable broken tests for arm

2021-11-22 Thread Manoj Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e67276d984d: libfuzzer: Disable broken tests for arm 
(authored by manojgupta).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114312

Files:
  compiler-rt/test/fuzzer/acquire-crash-state.test
  compiler-rt/test/fuzzer/compressed.test
  compiler-rt/test/fuzzer/msan-custom-mutator.test
  compiler-rt/test/fuzzer/msan-param-unpoison.test
  compiler-rt/test/fuzzer/msan.test
  compiler-rt/test/fuzzer/sigint.test
  compiler-rt/test/fuzzer/value-profile-div.test


Index: compiler-rt/test/fuzzer/value-profile-div.test
===
--- compiler-rt/test/fuzzer/value-profile-div.test
+++ compiler-rt/test/fuzzer/value-profile-div.test
@@ -1,5 +1,5 @@
 UNSUPPORTED: ios
-UNSUPPORTED: aarch64
+UNSUPPORTED: arm, aarch64
 CHECK: AddressSanitizer: {{FPE|int-divide-by-zero}}
 RUN: %cpp_compiler %S/DivTest.cpp -fsanitize-coverage=trace-div -o %t-DivTest
 RUN: not %run %t-DivTest -seed=1 -use_value_profile=1 -runs=1000 2>&1 | 
FileCheck %s
Index: compiler-rt/test/fuzzer/sigint.test
===
--- compiler-rt/test/fuzzer/sigint.test
+++ compiler-rt/test/fuzzer/sigint.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 
 # Check that libFuzzer exits gracefully under SIGINT with MSan.
 RUN: rm -rf %t
Index: compiler-rt/test/fuzzer/msan.test
===
--- compiler-rt/test/fuzzer/msan.test
+++ compiler-rt/test/fuzzer/msan.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 RUN: %msan_compiler %S/SimpleTestStdio.cpp -o %t
 RUN: not %run %t -seed=1 -runs=1000 2>&1 | FileCheck %s 
--check-prefix=NO-REPORT
 
Index: compiler-rt/test/fuzzer/msan-param-unpoison.test
===
--- compiler-rt/test/fuzzer/msan-param-unpoison.test
+++ compiler-rt/test/fuzzer/msan-param-unpoison.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 RUN: %msan_compiler %S/MsanParamUnpoison.cpp -o %t
 RUN: %run %t -seed=1 -runs=1000 2>&1 | FileCheck %s
 
Index: compiler-rt/test/fuzzer/msan-custom-mutator.test
===
--- compiler-rt/test/fuzzer/msan-custom-mutator.test
+++ compiler-rt/test/fuzzer/msan-custom-mutator.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 RUN: %msan_compiler %S/MsanCustomMutator.cpp -o %t
 RUN: %run %t -seed=1 -runs=1000 2>&1 | FileCheck %s
 
Index: compiler-rt/test/fuzzer/compressed.test
===
--- compiler-rt/test/fuzzer/compressed.test
+++ compiler-rt/test/fuzzer/compressed.test
@@ -2,7 +2,7 @@
 REQUIRES: zlib
 # zlib is "supported" on i386 even when only for x86_64, explicitly make i386
 # unsupported by this test.
-UNSUPPORTED: i386
+UNSUPPORTED: i386, arm
 # Custom mutator should find this bug, w/o custom -- no chance.
 RUN: %cpp_compiler %S/CompressedTest.cpp -o %t-CompressedTestCustom 
-DCUSTOM_MUTATOR -lz
 RUN: %cpp_compiler %S/CompressedTest.cpp -o %t-CompressedTestPlain -lz
Index: compiler-rt/test/fuzzer/acquire-crash-state.test
===
--- compiler-rt/test/fuzzer/acquire-crash-state.test
+++ compiler-rt/test/fuzzer/acquire-crash-state.test
@@ -1,3 +1,4 @@
+UNSUPPORTED: arm
 RUN: %cpp_compiler %S/AcquireCrashStateTest.cpp -o %t
 RUN: %run %t 2>&1 | FileCheck %s
 CHECK-NOT: fuzz target exited


Index: compiler-rt/test/fuzzer/value-profile-div.test
===
--- compiler-rt/test/fuzzer/value-profile-div.test
+++ compiler-rt/test/fuzzer/value-profile-div.test
@@ -1,5 +1,5 @@
 UNSUPPORTED: ios
-UNSUPPORTED: aarch64
+UNSUPPORTED: arm, aarch64
 CHECK: AddressSanitizer: {{FPE|int-divide-by-zero}}
 RUN: %cpp_compiler %S/DivTest.cpp -fsanitize-coverage=trace-div -o %t-DivTest
 RUN: not %run %t-DivTest -seed=1 -use_value_profile=1 -runs=1000 2>&1 | FileCheck %s
Index: compiler-rt/test/fuzzer/sigint.test
===
--- compiler-rt/test/fuzzer/sigint.test
+++ compiler-rt/test/fuzzer/sigint.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 
 # Check that libFuzzer exits gracefully under SIGINT with MSan.
 RUN: rm -rf %t
Index: compiler-rt/test/fuzzer/msan.test
===
--- compiler-rt/test/fuzzer/msan.test
+++ compiler-rt/test/fuzzer/msan.test
@@ -1,4 +1,5 @@
 REQUIRES: msan
+UNSUPPORTED: arm
 RUN: %msan_compiler %S/SimpleTestStdio.cpp -o %t
 RUN: not %run %t -seed=1 -runs=1000 2>&1 | FileCheck %s --check-prefix=NO-REPORT
 
Index: compiler-rt/test/fuzzer/msan-param-unpoison.test
===
--- c

[PATCH] D136712: Define _GNU_SOURCE for arm baremetal in C++ mode.

2022-10-25 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.
manojgupta added reviewers: abidh, tomhughes.
Herald added subscribers: kristof.beyls, ki.stfu, dschuff.
Herald added a project: All.
manojgupta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This matches other C++ drivers e.g. Linux that define
_GNU_SOURCE. This lets clang compiler more code by default
without explicitly passing _GNU_SOURCE on command line.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136712

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/test/Driver/arm-baremetal-defines.cpp


Index: clang/test/Driver/arm-baremetal-defines.cpp
===
--- /dev/null
+++ clang/test/Driver/arm-baremetal-defines.cpp
@@ -0,0 +1,13 @@
+// RUN: %clangxx --target=arm-none-eabi -march=armv7-m %s -emit-llvm -S -c -o 
- 2>&1 | FileCheck %s
+
+// ECHO: {{.*}} "-cc1" {{.*}}mipsel-nacl-defines.c
+
+// CHECK: __ELF__defined
+#ifdef __ELF__
+void __ELF__defined() {}
+#endif
+
+// CHECK: _GNU_SOURCEdefined
+#ifdef _GNU_SOURCE
+void _GNU_SOURCEdefined() {}
+#endif
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -692,8 +692,11 @@
   // For bare-metal none-eabi.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   (getTriple().getEnvironment() == llvm::Triple::EABI ||
-   getTriple().getEnvironment() == llvm::Triple::EABIHF))
+   getTriple().getEnvironment() == llvm::Triple::EABIHF)) {
 Builder.defineMacro("__ELF__");
+if (Opts.CPlusPlus)
+  Builder.defineMacro("_GNU_SOURCE");
+  }
 
   // Target properties.
   Builder.defineMacro("__REGISTER_PREFIX__", "");


Index: clang/test/Driver/arm-baremetal-defines.cpp
===
--- /dev/null
+++ clang/test/Driver/arm-baremetal-defines.cpp
@@ -0,0 +1,13 @@
+// RUN: %clangxx --target=arm-none-eabi -march=armv7-m %s -emit-llvm -S -c -o - 2>&1 | FileCheck %s
+
+// ECHO: {{.*}} "-cc1" {{.*}}mipsel-nacl-defines.c
+
+// CHECK: __ELF__defined
+#ifdef __ELF__
+void __ELF__defined() {}
+#endif
+
+// CHECK: _GNU_SOURCEdefined
+#ifdef _GNU_SOURCE
+void _GNU_SOURCEdefined() {}
+#endif
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -692,8 +692,11 @@
   // For bare-metal none-eabi.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   (getTriple().getEnvironment() == llvm::Triple::EABI ||
-   getTriple().getEnvironment() == llvm::Triple::EABIHF))
+   getTriple().getEnvironment() == llvm::Triple::EABIHF)) {
 Builder.defineMacro("__ELF__");
+if (Opts.CPlusPlus)
+  Builder.defineMacro("_GNU_SOURCE");
+  }
 
   // Target properties.
   Builder.defineMacro("__REGISTER_PREFIX__", "");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136712: Define _GNU_SOURCE for arm baremetal in C++ mode.

2022-10-25 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 470611.
manojgupta added a comment.

Removed c++ limitation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136712

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/test/Driver/arm-baremetal-defines.cpp


Index: clang/test/Driver/arm-baremetal-defines.cpp
===
--- /dev/null
+++ clang/test/Driver/arm-baremetal-defines.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang --target=arm-none-eabi -march=armv7-m %s -emit-llvm -S -c -o - 
2>&1 | FileCheck %s
+
+// CHECK: __ELF__defined
+#ifdef __ELF__
+void __ELF__defined() {}
+#endif
+
+// CHECK: _GNU_SOURCEdefined
+#ifdef _GNU_SOURCE
+void _GNU_SOURCEdefined() {}
+#endif
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -692,8 +692,10 @@
   // For bare-metal none-eabi.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   (getTriple().getEnvironment() == llvm::Triple::EABI ||
-   getTriple().getEnvironment() == llvm::Triple::EABIHF))
+   getTriple().getEnvironment() == llvm::Triple::EABIHF)) {
 Builder.defineMacro("__ELF__");
+Builder.defineMacro("_GNU_SOURCE");
+  }
 
   // Target properties.
   Builder.defineMacro("__REGISTER_PREFIX__", "");


Index: clang/test/Driver/arm-baremetal-defines.cpp
===
--- /dev/null
+++ clang/test/Driver/arm-baremetal-defines.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang --target=arm-none-eabi -march=armv7-m %s -emit-llvm -S -c -o - 2>&1 | FileCheck %s
+
+// CHECK: __ELF__defined
+#ifdef __ELF__
+void __ELF__defined() {}
+#endif
+
+// CHECK: _GNU_SOURCEdefined
+#ifdef _GNU_SOURCE
+void _GNU_SOURCEdefined() {}
+#endif
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -692,8 +692,10 @@
   // For bare-metal none-eabi.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   (getTriple().getEnvironment() == llvm::Triple::EABI ||
-   getTriple().getEnvironment() == llvm::Triple::EABIHF))
+   getTriple().getEnvironment() == llvm::Triple::EABIHF)) {
 Builder.defineMacro("__ELF__");
+Builder.defineMacro("_GNU_SOURCE");
+  }
 
   // Target properties.
   Builder.defineMacro("__REGISTER_PREFIX__", "");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136712: Define _GNU_SOURCE for arm baremetal in C++ mode.

2022-10-28 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added reviewers: MaskRay, efriedma.
manojgupta added subscribers: MaskRay, efriedma.
manojgupta added a comment.
Herald added a subscriber: StephenFan.

I am not sure who is a good reviewer for this. Starting with @MaskRay and 
@efriedma


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136712

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


[PATCH] D136712: Define _GNU_SOURCE for arm baremetal in C++ mode.

2022-10-28 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

@tomhughes has more details on this but if we do not define it in clang itself, 
we'll need to define it for every package manually at build time since the 
usage goes deep inside newlib headers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136712

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


  1   2   >