r354502 - [Clang Driver] Add support for "-static-pie" argument to the Clang driver.

2019-02-20 Thread Siva Chandra via cfe-commits
Author: sivachandra
Date: Wed Feb 20 11:07:04 2019
New Revision: 354502

URL: http://llvm.org/viewvc/llvm-project?rev=354502&view=rev
Log:
[Clang Driver] Add support for "-static-pie" argument to the Clang driver.

Summary: This change mimics GCC's support for the "-static-pie" argument.

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/test/Driver/linux-ld.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=354502&r1=354501&r2=354502&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Feb 20 11:07:04 2019
@@ -2508,6 +2508,7 @@ def pthread : Flag<["-"], "pthread">, Fl
 def no_pthread : Flag<["-"], "no-pthread">, Flags<[CC1Option]>;
 def p : Flag<["-"], "p">;
 def pie : Flag<["-"], "pie">;
+def static_pie : Flag<["-"], "static-pie">;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;
 def remap : Flag<["-"], "remap">;
 def rewrite_objc : Flag<["-"], "rewrite-objc">, 
Flags<[DriverOption,CC1Option]>,

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=354502&r1=354501&r2=354502&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Wed Feb 20 11:07:04 2019
@@ -1137,19 +1137,22 @@ static void AddLibgcc(const llvm::Triple
   bool isCygMing = Triple.isOSCygMing();
   bool IsIAMCU = Triple.isOSIAMCU();
   bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) ||
-  Args.hasArg(options::OPT_static);
+  Args.hasArg(options::OPT_static) ||
+  Args.hasArg(options::OPT_static_pie);
 
   bool SharedLibgcc = Args.hasArg(options::OPT_shared_libgcc);
   bool UnspecifiedLibgcc = !StaticLibgcc && !SharedLibgcc;
 
   // Gcc adds libgcc arguments in various ways:
   //
-  // gcc : -lgcc --as-needed -lgcc_s --no-as-needed
-  // g++ :   -lgcc_s   -lgcc
-  // gcc shared:   -lgcc_s   -lgcc
-  // g++ shared:   -lgcc_s   -lgcc
-  // gcc static: -lgcc -lgcc_eh
-  // g++ static: -lgcc -lgcc_eh
+  // gcc : -lgcc --as-needed -lgcc_s --no-as-needed
+  // g++ :   -lgcc_s   -lgcc
+  // gcc shared:   -lgcc_s   -lgcc
+  // g++ shared:   -lgcc_s   -lgcc
+  // gcc static: -lgcc -lgcc_eh
+  // g++ static: -lgcc -lgcc_eh
+  // gcc static-pie: -lgcc -lgcc_eh
+  // g++ static-pie: -lgcc -lgcc_eh
   //
   // Also, certain targets need additional adjustments.
 

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=354502&r1=354501&r2=354502&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Wed Feb 20 11:07:04 2019
@@ -333,6 +333,7 @@ void tools::gnutools::Linker::ConstructJ
   const bool isAndroid = ToolChain.getTriple().isAndroid();
   const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU();
   const bool IsPIE = getPIE(Args, ToolChain);
+  const bool IsStaticPIE = Args.hasArg(options::OPT_static_pie);
   const bool HasCRTBeginEndFiles =
   ToolChain.getTriple().hasEnvironment() ||
   (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies);
@@ -353,6 +354,12 @@ void tools::gnutools::Linker::ConstructJ
   if (IsPIE)
 CmdArgs.push_back("-pie");
 
+  if (IsStaticPIE) {
+CmdArgs.push_back("-static");
+CmdArgs.push_back("-pie");
+CmdArgs.push_back("--no-dynamic-linker");
+  }
+
   if (Args.hasArg(options::OPT_rdynamic))
 CmdArgs.push_back("-export-dynamic");
 
@@ -402,7 +409,7 @@ void tools::gnutools::Linker::ConstructJ
 if (Args.hasArg(options::OPT_rdynamic))
   CmdArgs.push_back("-export-dynamic");
 
-if (!Args.hasArg(options::OPT_shared)) {
+if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE) {
   const std::string Loader =
   D.DyldPrefix + ToolChain.getDynamicLinker(Args);
   CmdArgs.push_back("-dynamic-linker");
@@ -421,6 +428,8 @@ void tools::gnutools::Linker::ConstructJ
   crt1 = "gcrt1.o";
 else if (IsPIE)
   crt1 = "Scrt1.o";
+else if (IsStaticPIE)
+  crt1 = "rcrt1.o";
 else
   crt

r361312 - Let -static-pie win if it is specified along with -pie or -static.

2019-05-21 Thread Siva Chandra via cfe-commits
Author: sivachandra
Date: Tue May 21 14:09:05 2019
New Revision: 361312

URL: http://llvm.org/viewvc/llvm-project?rev=361312&view=rev
Log:
Let -static-pie win if it is specified along with -pie or -static.

Also, disallow specifying -no-pie/-nopie along with -static-pie.

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/test/Driver/linux-ld.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=361312&r1=361311&r2=361312&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Tue May 21 14:09:05 
2019
@@ -458,4 +458,5 @@ def warn_drv_libstdcxx_not_found : Warni
   "command line to use the libc++ standard library instead">,
   InGroup>;
 
+def err_drv_cannot_mix_options : Error<"cannot specify '%1' along with '%0'">;
 }

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=361312&r1=361311&r2=361312&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Tue May 21 14:09:05 2019
@@ -311,7 +311,7 @@ static const char *getLDMOption(const ll
 
 static bool getPIE(const ArgList &Args, const toolchains::Linux &ToolChain) {
   if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
-  Args.hasArg(options::OPT_r))
+  Args.hasArg(options::OPT_r) || Args.hasArg(options::OPT_static_pie))
 return false;
 
   Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
@@ -321,6 +321,26 @@ static bool getPIE(const ArgList &Args,
   return A->getOption().matches(options::OPT_pie);
 }
 
+static bool getStaticPIE(const ArgList &Args,
+ const toolchains::Linux &ToolChain) {
+  bool HasStaticPIE = Args.hasArg(options::OPT_static_pie);
+  // -no-pie is an alias for -nopie. So, handling -nopie takes care of
+  // -no-pie as well.
+  if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
+const Driver &D = ToolChain.getDriver();
+const llvm::opt::OptTable &Opts = D.getOpts();
+const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
+const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
+D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
+  }
+  return HasStaticPIE;
+}
+
+static bool getStatic(const ArgList &Args) {
+  return Args.hasArg(options::OPT_static) &&
+  !Args.hasArg(options::OPT_static_pie);
+}
+
 void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
@@ -336,7 +356,8 @@ void tools::gnutools::Linker::ConstructJ
   const bool isAndroid = ToolChain.getTriple().isAndroid();
   const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU();
   const bool IsPIE = getPIE(Args, ToolChain);
-  const bool IsStaticPIE = Args.hasArg(options::OPT_static_pie);
+  const bool IsStaticPIE = getStaticPIE(Args, ToolChain);
+  const bool IsStatic = getStatic(Args);
   const bool HasCRTBeginEndFiles =
   ToolChain.getTriple().hasEnvironment() ||
   (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies);
@@ -408,7 +429,7 @@ void tools::gnutools::Linker::ConstructJ
 return;
   }
 
-  if (Args.hasArg(options::OPT_static)) {
+  if (IsStatic) {
 if (Arch == llvm::Triple::arm || Arch == llvm::Triple::armeb ||
 Arch == llvm::Triple::thumb || Arch == llvm::Triple::thumbeb)
   CmdArgs.push_back("-Bstatic");
@@ -418,7 +439,7 @@ void tools::gnutools::Linker::ConstructJ
 CmdArgs.push_back("-shared");
   }
 
-  if (!Args.hasArg(options::OPT_static)) {
+  if (!IsStatic) {
 if (Args.hasArg(options::OPT_rdynamic))
   CmdArgs.push_back("-export-dynamic");
 
@@ -465,7 +486,7 @@ void tools::gnutools::Linker::ConstructJ
   }
   if (P.empty()) {
 const char *crtbegin;
-if (Args.hasArg(options::OPT_static))
+if (IsStatic)
   crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o";
 else if (Args.hasArg(options::OPT_shared))
   crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o";
@@ -520,7 +541,7 @@ void tools::gnutools::Linker::ConstructJ
 
   if (!Args.hasArg(options::OPT_nostdlib)) {
 if (!Args.hasArg(options::OPT_nodefaultlibs)) {
-  if (Args.hasArg(options::OPT_static) || IsStaticPIE)
+  if (IsStatic || IsStaticPIE)
 CmdArgs.push_back("--start-group");
 
   if (NeedsSanitizerDeps)
@@ -556,7 +577,7 @@ void tools::gnutoo

Re: [Lldb-commits] Upcoming upgrade of LLVM buildbot

2020-10-13 Thread Siva Chandra via cfe-commits
On Mon, Oct 12, 2020 at 10:01 PM Galina Kistanova via lldb-commits
 wrote:
> If somebody else could move their AnnotatedCommand bots to the staging area, 
> that would be much appreciated.

I moved the libc bots to staging to now.

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


Re: [PATCH] D97736: [Driver] Add a experimental option to link to LLVM libc.

2021-03-13 Thread Siva Chandra via cfe-commits
On Sat, Mar 13, 2021 at 9:36 AM Eric Christopher  wrote:

>
>
> On Fri, Mar 5, 2021 at 1:15 AM Siva Chandra via Phabricator <
> revi...@reviews.llvm.org> wrote:
>
>> sivachandra added a comment.
>>
>> In D97736#2605535 , @phosek
>> wrote:
>>
>> > Have you considered using an input linker script? We could generate
>> `libc.so` that could look something like:
>> >
>> >   INPUT(libllvmlibc.a /lib/libc.so)
>> >
>> > We would need to pass `--sysroot` to the linker for this to work. The
>> driver could remain completely agnostic of whether you're using LLVM libc
>> or not.
>>
>> Yes, that was also considered. Those downstream users who have the
>> flexibility to do it that way should be able to do it that way. However,
>> not all downstream users or normal clang users will have that liberty [1].
>> Another point to note is that we will have to do this with all libc
>> components like `libc.so`, `libm.so` etc.
>>
>> [1] I think all of this can be done. For example, we can set all this up
>> when building a distribution. However, I am not sure this is worth it when
>> we know this is a transient phase. Soon, when LLVM libc is complete enough,
>> a more appropriate option would be the one which allows choosing a libc as
>> Eric pointed out.
>>
>
> To be clear I'm not a fan of a "pick your libc" option as opposed to just
> naming the compiled llvm libc as perhaps libc.[a,so,etc] similar to other
> platforms. I think we'd need a good reason to diverge here.
>

The reason is that LLVM libc is not a libc until it can be one. This option
is being added so that one can use LLVM libc as a source of alternate
implementations. Once LLVM libc can actually be a full libc, this option is
not required. Also, from that point in time, the LLVM libc binary should be
given the conventional libc. name as you suggest.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Fix printf config not working (PR #66834)

2023-09-20 Thread Siva Chandra via cfe-commits


@@ -112,6 +112,16 @@ add_libc_unittest(
 LibcMemoryHelpers
 )
 
+if(LIBC_CONF_PRINTF_DISABLE_FLOAT)

sivachandra wrote:

I do not think this pattern is how the copts are to be used. In this particular 
case, I think the right way would be to split `sprintf_test` into 
`sprintf_basic_test`, `sprintf_float_test`, `sprintf_index_mode_test`, 
`sprintf_write_int_test` etc. Then, test targets should be added as follows:

```
add_libc_test(
  sprintf_basic_test
  ...
)

if(NOT LIBC_CONF_PRINTF_DISABLE_FLOAT)
  add_fp_unittest(
sprintf_float_test
  )
endif()

# Other conditionals on config options
```

There could be some compile opts that need to be inherited by the tests [1]. 
Even in such a case, the test source code should not directly use those 
internal copts - they are internal implementation details unrelated to the 
tests.

[1] - We do not have such a mechanism set up currently. We can add it when 
required. It will be required if the tests are calling internal implementation 
functions and not the entrypoints. We do have such tests but they are typically 
testing common infrastructure components not affected by config options.

https://github.com/llvm/llvm-project/pull/66834
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Fix printf config not working (PR #66834)

2023-09-20 Thread Siva Chandra via cfe-commits


@@ -112,6 +112,16 @@ add_libc_unittest(
 LibcMemoryHelpers
 )
 
+if(LIBC_CONF_PRINTF_DISABLE_FLOAT)

sivachandra wrote:

I do not think this pattern is how the copts are to be used. In this particular 
case, I think the right way would be to split `sprintf_test` into 
`sprintf_basic_test`, `sprintf_float_test`, `sprintf_index_mode_test`, 
`sprintf_write_int_test` etc. Then, test targets should be added as follows:

```
add_libc_test(
  sprintf_basic_test
  ...
)

if(NOT LIBC_CONF_PRINTF_DISABLE_FLOAT)
  add_fp_unittest(
sprintf_float_test
  )
endif()

# Other conditionals on config options
```

There could be some compile opts that need to be inherited by the tests [1]. 
Even in such a case, the test source code should not directly use those 
internal copts - they are internal implementation details unrelated to the 
tests.

[1] - We do not have such a mechanism set up currently. We can add it when 
required. It will be required if the tests are calling internal implementation 
functions and not the entrypoints. We do have such tests but they are typically 
testing common infrastructure components not affected by config options.

https://github.com/llvm/llvm-project/pull/66834
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread Siva Chandra via cfe-commits


@@ -439,10 +442,6 @@ if(LLVM_LIBC_FULL_BUILD)
 libc.src.stdio.getc_unlocked
 libc.src.stdio.getchar
 libc.src.stdio.getchar_unlocked
-libc.src.stdio.printf

sivachandra wrote:

I think it was removed because it is listed on line 130 also.

https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread Siva Chandra via cfe-commits


@@ -9,15 +9,57 @@
 #ifndef LLVM_LIBC_SRC_STDIO_SCANF_CORE_VFSCANF_INTERNAL_H
 #define LLVM_LIBC_SRC_STDIO_SCANF_CORE_VFSCANF_INTERNAL_H
 
+#include "src/__support/File/file.h"
 #include "src/__support/arg_list.h"
+#include "src/stdio/scanf_core/reader.h"
+#include "src/stdio/scanf_core/scanf_main.h"
 
 #include 
 
 namespace __llvm_libc {
+
+namespace internal {
+#ifndef LIBC_COPT_SCANF_USE_SYSTEM_FILE
+LIBC_INLINE int getc(void *f) {
+  unsigned char c;
+  auto result = reinterpret_cast<__llvm_libc::File *>(f)->read_unlocked(&c, 1);
+  size_t r = result.value;
+  if (result.has_error() || r != 1) {
+return '\0';
+  }
+  return c;
+}
+
+LIBC_INLINE void ungetc(int c, void *f) {
+  reinterpret_cast<__llvm_libc::File *>(f)->ungetc(c);
+}
+
+LIBC_INLINE int ferror_unlocked(FILE *f) {
+  return reinterpret_cast<__llvm_libc::File *>(f)->error_unlocked();
+}
+#else  // defined(LIBC_COPT_PRINTF_USE_SYSTEM_FILE)

sivachandra wrote:

Same.

https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread Siva Chandra via cfe-commits

https://github.com/sivachandra commented:

Few nits, but otherwise OK.

https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread Siva Chandra via cfe-commits

https://github.com/sivachandra edited 
https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread Siva Chandra via cfe-commits

https://github.com/sivachandra commented:

Few nits, but otherwise OK.

https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread Siva Chandra via cfe-commits

https://github.com/sivachandra edited 
https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread Siva Chandra via cfe-commits


@@ -220,6 +220,20 @@ add_libc_test(
 libc.src.stdio.vprintf
 )
 
+
+if(LLVM_LIBC_FULL_BUILD)
+  # In fullbuild mode, fscanf's tests use the internal FILE for other 
functions.
+  list(APPEND fscanf_test_deps
+   libc.src.stdio.fclose
+   libc.src.stdio.ferror
+   libc.src.stdio.fopen
+   libc.src.stdio.fwrite
+  )
+else()
+# Else in overlay mode they use the system's FILE.
+ set(fscanf_test_copts "-DLIBC_COPT_SCANF_USE_SYSTEM_FILE")

sivachandra wrote:

This opt should likely be named as `LIBC_COPT_STDIO_USE_SYSTEM_FILE` and shared 
between `printf`, `scanf` and all other stdio pieces which can work with both 
system file or libc's own file.

https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread Siva Chandra via cfe-commits


@@ -9,15 +9,57 @@
 #ifndef LLVM_LIBC_SRC_STDIO_SCANF_CORE_VFSCANF_INTERNAL_H
 #define LLVM_LIBC_SRC_STDIO_SCANF_CORE_VFSCANF_INTERNAL_H
 
+#include "src/__support/File/file.h"
 #include "src/__support/arg_list.h"
+#include "src/stdio/scanf_core/reader.h"
+#include "src/stdio/scanf_core/scanf_main.h"
 
 #include 
 
 namespace __llvm_libc {
+
+namespace internal {
+#ifndef LIBC_COPT_SCANF_USE_SYSTEM_FILE

sivachandra wrote:

Nit: Add a line before and after.

https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread Siva Chandra via cfe-commits


@@ -439,10 +442,6 @@ if(LLVM_LIBC_FULL_BUILD)
 libc.src.stdio.getc_unlocked
 libc.src.stdio.getchar
 libc.src.stdio.getchar_unlocked
-libc.src.stdio.printf

sivachandra wrote:

I think it was removed because it is listed on line 130 also.

https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] remove common libc tuners (PR #66136)

2023-09-13 Thread Siva Chandra via cfe-commits

https://github.com/sivachandra updated 
https://github.com/llvm/llvm-project/pull/66136:

>From d1a9fda20a2be37385b44dcbf2f73b1890fa7d78 Mon Sep 17 00:00:00 2001
From: Siva Chandra Reddy 
Date: Tue, 12 Sep 2023 05:42:37 +
Subject: [PATCH 1/3] [libc][NFC] Make entrypoint alias targets real library
 targets.

This is part of a libc wide CMake cleanup which aims to eliminate
certain explicitly duplicated logic which is available in CMake-3.20.
This change in particular makes the entrypoint aliases real library
targets so that they can be treated as normal library targets by other
libc build rules.
---
 libc/cmake/modules/LLVMLibCObjectRules.cmake | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake 
b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 709acd9ad614fbe..006b8949b6fd0a1 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -559,6 +559,8 @@ function(create_entrypoint_object fq_target_name)
 return()
   endif()
 
+  set(internal_target_name ${fq_target_name}.__internal__)
+
   if(ADD_ENTRYPOINT_OBJ_ALIAS)
 # Alias targets help one add aliases to other entrypoint object targets.
 # One can use alias targets setup OS/machine independent entrypoint 
targets.
@@ -586,10 +588,23 @@ function(create_entrypoint_object fq_target_name)
   message(FATAL_ERROR "The aliasee of an entrypoint alias should be an 
entrypoint.")
 endif()
 
-add_custom_target(${fq_target_name})
-add_dependencies(${fq_target_name} ${fq_dep_name})
+# add_custom_target(${fq_target_name})
 get_target_property(object_file ${fq_dep_name} "OBJECT_FILE")
 get_target_property(object_file_raw ${fq_dep_name} "OBJECT_FILE_RAW")
+add_library(
+  ${internal_target_name}
+  EXCLUDE_FROM_ALL
+  OBJECT
+  ${object_file_raw}
+)
+add_dependencies(${internal_target_name} ${fq_dep_name})
+add_library(
+  ${fq_target_name}
+  EXCLUDE_FROM_ALL
+  OBJECT
+  ${object_file}
+)
+add_dependencies(${fq_target_name} ${fq_dep_name} ${internal_target_name})
 set_target_properties(
   ${fq_target_name}
   PROPERTIES
@@ -619,7 +634,6 @@ function(create_entrypoint_object fq_target_name)
 "${ADD_ENTRYPOINT_OBJ_FLAGS}"
 ${ADD_ENTRYPOINT_OBJ_COMPILE_OPTIONS}
   )
-  set(internal_target_name ${fq_target_name}.__internal__)
   set(include_dirs ${LIBC_SOURCE_DIR} ${LIBC_INCLUDE_DIR})
   get_fq_deps_list(fq_deps_list ${ADD_ENTRYPOINT_OBJ_DEPENDS})
   set(full_deps_list ${fq_deps_list} libc.src.__support.common)

>From f0475c5918f4f645e45f05f8e07f472e9fd94559 Mon Sep 17 00:00:00 2001
From: Siva Chandra Reddy 
Date: Tue, 12 Sep 2023 16:30:50 +
Subject: [PATCH 2/3] [libc][NFC] Remove stray comment.

---
 libc/cmake/modules/LLVMLibCObjectRules.cmake | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake 
b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 006b8949b6fd0a1..4d5835cc6b4d809 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -588,7 +588,6 @@ function(create_entrypoint_object fq_target_name)
   message(FATAL_ERROR "The aliasee of an entrypoint alias should be an 
entrypoint.")
 endif()
 
-# add_custom_target(${fq_target_name})
 get_target_property(object_file ${fq_dep_name} "OBJECT_FILE")
 get_target_property(object_file_raw ${fq_dep_name} "OBJECT_FILE_RAW")
 add_library(

>From 1eeb5e0eda3bdcf6d4eec6e1afac5c6c3f45 Mon Sep 17 00:00:00 2001
From: Siva Chandra Reddy 
Date: Mon, 11 Sep 2023 22:17:32 +
Subject: [PATCH 3/3] [libc] Remove common_libc_tuners.cmake and move options
 into config.json.

The name has been changed to adhere to the config option naming format.
The necessary build changes to use the new option have also been made.
---
 libc/CMakeLists.txt  |  2 --
 libc/cmake/modules/LLVMLibCObjectRules.cmake |  2 ++
 libc/common_libc_tuners.cmake| 14 --
 libc/config/config.json  |  6 ++
 libc/docs/configure.rst  |  2 ++
 libc/src/string/CMakeLists.txt   |  9 +
 libc/src/string/string_utils.h   |  4 ++--
 7 files changed, 21 insertions(+), 18 deletions(-)
 delete mode 100644 libc/common_libc_tuners.cmake

diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 12fff25c197e2d9..cf90919c20fd969 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -64,8 +64,6 @@ add_compile_definitions(LIBC_NAMESPACE=${LIBC_NAMESPACE})
 # Flags to pass down to the compiler while building the libc functions.
 set(LIBC_COMPILE_OPTIONS_DEFAULT "" CACHE STRING "Architecture to tell clang 
to optimize for (e.g. -march=... or -mcpu=...)")
 
-include(common_libc_tuners.cmake)
-
 list(APPEND LIBC_COMPILE_OPTIONS_DEFAULT ${LIBC_COMMON_TUNE_OPTIONS})
 
 # Check

[clang] remove common libc tuners (PR #66136)

2023-09-13 Thread Siva Chandra via cfe-commits

https://github.com/sivachandra closed 
https://github.com/llvm/llvm-project/pull/66136
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21666: [Tooling] Add optional argument to getFullyQualifiedName to prepend "::".

2016-06-23 Thread Siva Chandra via cfe-commits
sivachandra created this revision.
sivachandra added reviewers: rnk, saugustine.
sivachandra added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

http://reviews.llvm.org/D21666

Files:
  include/clang/AST/NestedNameSpecifier.h
  include/clang/Tooling/Core/QualTypeNames.h
  lib/AST/NestedNameSpecifier.cpp
  lib/Tooling/Core/QualTypeNames.cpp
  unittests/Tooling/QualTypeNamesTest.cpp

Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -14,6 +14,7 @@
 namespace {
 struct TypeNameVisitor : TestVisitor {
   llvm::StringMap ExpectedQualTypeNames;
+  bool WithGlobalNsPrefix = false;
 
   // ValueDecls are the least-derived decl with both a qualtype and a
   // name.
@@ -26,7 +27,8 @@
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
   std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context);
+  TypeName::getFullyQualifiedName(VD->getType(), *Context,
+  WithGlobalNsPrefix);
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -179,6 +181,27 @@
   "  TX CheckTX;"
   "  struct A { typedef int X; };"
   "}");
+
+  TypeNameVisitor GlobalNsPrefix;
+  GlobalNsPrefix.WithGlobalNsPrefix = true;
+  GlobalNsPrefix.ExpectedQualTypeNames["IntVal"] = "int";
+  GlobalNsPrefix.ExpectedQualTypeNames["BoolVal"] = "bool";
+  GlobalNsPrefix.ExpectedQualTypeNames["XVal"] = "::A::B::X";
+  GlobalNsPrefix.ExpectedQualTypeNames["IntAliasVal"] = "::A::B::Alias";
+  GlobalNsPrefix.runOver(
+  "namespace A {"
+  "  namespace B {"
+  "int IntVal;"
+  "bool BoolVal;"
+  "struct X {};"
+  "X XVal;"
+  "template  class CCC { };"
+  "template \n"
+  "using Alias = CCC;\n"
+  "Alias IntAliasVal;\n"
+  "  }"
+  "}"
+  );
 }
 
 }  // end anonymous namespace
Index: lib/Tooling/Core/QualTypeNames.cpp
===
--- lib/Tooling/Core/QualTypeNames.cpp
+++ lib/Tooling/Core/QualTypeNames.cpp
@@ -30,7 +30,8 @@
 /// \param[in] QT - the type for which the fully qualified type will be
 /// returned.
 /// \param[in] Ctx - the ASTContext to be used.
-static QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx);
+static QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx,
+  bool WithGlobalNsPrefix);
 
 /// \brief Create a NestedNameSpecifier for Namesp and its enclosing
 /// scopes.
@@ -90,7 +91,8 @@
 }
 
 static bool getFullyQualifiedTemplateArgument(const ASTContext &Ctx,
-  TemplateArgument &Arg) {
+  TemplateArgument &Arg,
+  bool WithGlobalNsPrefix) {
   bool Changed = false;
 
   // Note: we do not handle TemplateArgument::Expression, to replace it
@@ -105,7 +107,7 @@
   } else if (Arg.getKind() == TemplateArgument::Type) {
 QualType SubTy = Arg.getAsType();
 // Check if the type needs more desugaring and recurse.
-QualType QTFQ = getFullyQualifiedType(SubTy, Ctx);
+QualType QTFQ = getFullyQualifiedType(SubTy, Ctx, WithGlobalNsPrefix);
 if (QTFQ != SubTy) {
   Arg = TemplateArgument(QTFQ);
   Changed = true;
@@ -115,7 +117,8 @@
 }
 
 static const Type *getFullyQualifiedTemplateType(const ASTContext &Ctx,
- const Type *TypePtr) {
+ const Type *TypePtr,
+ bool WithGlobalNsPrefix) {
   // DependentTemplateTypes exist within template declarations and
   // definitions. Therefore we shouldn't encounter them at the end of
   // a translation unit. If we do, the caller has made an error.
@@ -130,7 +133,8 @@
   // Cheap to copy and potentially modified by
   // getFullyQualifedTemplateArgument.
   TemplateArgument Arg(*I);
-  MightHaveChanged |= getFullyQualifiedTemplateArgument(Ctx, Arg);
+  MightHaveChanged |= getFullyQualifiedTemplateArgument(
+  Ctx, Arg, WithGlobalNsPrefix);
   FQArgs.push_back(Arg);
 }
 
@@ -160,7 +164,8 @@
 // cheap to copy and potentially modified by
 // getFullyQualifedTemplateArgument
 TemplateArgument Arg(TemplateArgs[I]);
-MightHaveChanged |= getFullyQualifiedTemplateArgument(Ctx, Arg);
+MightHaveChanged |= getFullyQualifiedTemplateArgument(
+Ctx, Arg, WithGlobalNsPrefix);
 FQArgs.push_back(Arg);
   }
 
@@ -337,13 +342,14 @@
 
 /// \brief Return the fully qualified type, including fully-qualified
 /// versions of any template

Re: [PATCH] D21666: [Tooling] Add optional argument to getFullyQualifiedName to prepend "::".

2016-06-24 Thread Siva Chandra via cfe-commits
sivachandra updated this revision to Diff 61821.
sivachandra added a comment.

A little adjustment.


http://reviews.llvm.org/D21666

Files:
  include/clang/AST/NestedNameSpecifier.h
  include/clang/Tooling/Core/QualTypeNames.h
  lib/AST/NestedNameSpecifier.cpp
  lib/Tooling/Core/QualTypeNames.cpp
  unittests/Tooling/QualTypeNamesTest.cpp

Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -14,6 +14,7 @@
 namespace {
 struct TypeNameVisitor : TestVisitor {
   llvm::StringMap ExpectedQualTypeNames;
+  bool WithGlobalNsPrefix = false;
 
   // ValueDecls are the least-derived decl with both a qualtype and a
   // name.
@@ -26,7 +27,8 @@
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
   std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context);
+  TypeName::getFullyQualifiedName(VD->getType(), *Context,
+  WithGlobalNsPrefix);
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -179,6 +181,30 @@
   "  TX CheckTX;"
   "  struct A { typedef int X; };"
   "}");
+
+  TypeNameVisitor GlobalNsPrefix;
+  GlobalNsPrefix.WithGlobalNsPrefix = true;
+  GlobalNsPrefix.ExpectedQualTypeNames["IntVal"] = "int";
+  GlobalNsPrefix.ExpectedQualTypeNames["BoolVal"] = "bool";
+  GlobalNsPrefix.ExpectedQualTypeNames["XVal"] = "::A::B::X";
+  GlobalNsPrefix.ExpectedQualTypeNames["IntAliasVal"] = "::A::B::Alias";
+  GlobalNsPrefix.ExpectedQualTypeNames["ZVal"] = "::A::B::Y::Z";
+  GlobalNsPrefix.runOver(
+  "namespace A {\n"
+  "  namespace B {\n"
+  "int IntVal;\n"
+  "bool BoolVal;\n"
+  "struct X {};\n"
+  "X XVal;\n"
+  "template  class CCC { };\n"
+  "template \n"
+  "using Alias = CCC;\n"
+  "Alias IntAliasVal;\n"
+  "struct Y { struct Z {}; };\n"
+  "Y::Z ZVal;\n"
+  "  }"
+  "}"
+  );
 }
 
 }  // end anonymous namespace
Index: lib/Tooling/Core/QualTypeNames.cpp
===
--- lib/Tooling/Core/QualTypeNames.cpp
+++ lib/Tooling/Core/QualTypeNames.cpp
@@ -30,7 +30,8 @@
 /// \param[in] QT - the type for which the fully qualified type will be
 /// returned.
 /// \param[in] Ctx - the ASTContext to be used.
-static QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx);
+static QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx,
+  bool WithGlobalNsPrefix);
 
 /// \brief Create a NestedNameSpecifier for Namesp and its enclosing
 /// scopes.
@@ -90,7 +91,8 @@
 }
 
 static bool getFullyQualifiedTemplateArgument(const ASTContext &Ctx,
-  TemplateArgument &Arg) {
+  TemplateArgument &Arg,
+  bool WithGlobalNsPrefix) {
   bool Changed = false;
 
   // Note: we do not handle TemplateArgument::Expression, to replace it
@@ -105,7 +107,7 @@
   } else if (Arg.getKind() == TemplateArgument::Type) {
 QualType SubTy = Arg.getAsType();
 // Check if the type needs more desugaring and recurse.
-QualType QTFQ = getFullyQualifiedType(SubTy, Ctx);
+QualType QTFQ = getFullyQualifiedType(SubTy, Ctx, WithGlobalNsPrefix);
 if (QTFQ != SubTy) {
   Arg = TemplateArgument(QTFQ);
   Changed = true;
@@ -115,7 +117,8 @@
 }
 
 static const Type *getFullyQualifiedTemplateType(const ASTContext &Ctx,
- const Type *TypePtr) {
+ const Type *TypePtr,
+ bool WithGlobalNsPrefix) {
   // DependentTemplateTypes exist within template declarations and
   // definitions. Therefore we shouldn't encounter them at the end of
   // a translation unit. If we do, the caller has made an error.
@@ -130,7 +133,8 @@
   // Cheap to copy and potentially modified by
   // getFullyQualifedTemplateArgument.
   TemplateArgument Arg(*I);
-  MightHaveChanged |= getFullyQualifiedTemplateArgument(Ctx, Arg);
+  MightHaveChanged |= getFullyQualifiedTemplateArgument(
+  Ctx, Arg, WithGlobalNsPrefix);
   FQArgs.push_back(Arg);
 }
 
@@ -160,7 +164,8 @@
 // cheap to copy and potentially modified by
 // getFullyQualifedTemplateArgument
 TemplateArgument Arg(TemplateArgs[I]);
-MightHaveChanged |= getFullyQualifiedTemplateArgument(Ctx, Arg);
+MightHaveChanged |= getFullyQualifiedTemplateArgument(
+Ctx, Arg, WithGlobalNsPrefix);
 FQArgs.push_back(Arg);
   }
 
@@ -337,13 +342,14 @@
 
 /// \brief 

Re: [PATCH] D21666: [Tooling] Add optional argument to getFullyQualifiedName to prepend "::".

2016-06-24 Thread Siva Chandra via cfe-commits
sivachandra added inline comments.


Comment at: lib/Tooling/Core/QualTypeNames.cpp:405
@@ -398,3 +404,3 @@
   // is not the global scope.
   Prefix = createNestedNameSpecifierForScopeOf(Ctx, QT.getTypePtr(),
true /*FullyQualified*/);

I think that can eliminate the need for the Prepend method. Let me dig a little 
more and get back.


http://reviews.llvm.org/D21666



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


Re: [PATCH] D21666: [Tooling] Add optional argument to getFullyQualifiedName to prepend "::".

2016-06-24 Thread Siva Chandra via cfe-commits
sivachandra updated this revision to Diff 61837.
sivachandra added a comment.

Address comments.


http://reviews.llvm.org/D21666

Files:
  include/clang/Tooling/Core/QualTypeNames.h
  lib/Tooling/Core/QualTypeNames.cpp
  unittests/Tooling/QualTypeNamesTest.cpp

Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -14,6 +14,7 @@
 namespace {
 struct TypeNameVisitor : TestVisitor {
   llvm::StringMap ExpectedQualTypeNames;
+  bool WithGlobalNsPrefix = false;
 
   // ValueDecls are the least-derived decl with both a qualtype and a
   // name.
@@ -26,7 +27,8 @@
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
   std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context);
+  TypeName::getFullyQualifiedName(VD->getType(), *Context,
+  WithGlobalNsPrefix);
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -179,6 +181,30 @@
   "  TX CheckTX;"
   "  struct A { typedef int X; };"
   "}");
+
+  TypeNameVisitor GlobalNsPrefix;
+  GlobalNsPrefix.WithGlobalNsPrefix = true;
+  GlobalNsPrefix.ExpectedQualTypeNames["IntVal"] = "int";
+  GlobalNsPrefix.ExpectedQualTypeNames["BoolVal"] = "bool";
+  GlobalNsPrefix.ExpectedQualTypeNames["XVal"] = "::A::B::X";
+  GlobalNsPrefix.ExpectedQualTypeNames["IntAliasVal"] = "::A::B::Alias";
+  GlobalNsPrefix.ExpectedQualTypeNames["ZVal"] = "::A::B::Y::Z";
+  GlobalNsPrefix.runOver(
+  "namespace A {\n"
+  "  namespace B {\n"
+  "int IntVal;\n"
+  "bool BoolVal;\n"
+  "struct X {};\n"
+  "X XVal;\n"
+  "template  class CCC { };\n"
+  "template \n"
+  "using Alias = CCC;\n"
+  "Alias IntAliasVal;\n"
+  "struct Y { struct Z {}; };\n"
+  "Y::Z ZVal;\n"
+  "  }"
+  "}"
+  );
 }
 
 }  // end anonymous namespace
Index: lib/Tooling/Core/QualTypeNames.cpp
===
--- lib/Tooling/Core/QualTypeNames.cpp
+++ lib/Tooling/Core/QualTypeNames.cpp
@@ -30,16 +30,19 @@
 /// \param[in] QT - the type for which the fully qualified type will be
 /// returned.
 /// \param[in] Ctx - the ASTContext to be used.
-static QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx);
+static QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx,
+  bool WithGlobalNsPrefix);
 
 /// \brief Create a NestedNameSpecifier for Namesp and its enclosing
 /// scopes.
 ///
 /// \param[in] Ctx - the AST Context to be used.
 /// \param[in] Namesp - the NamespaceDecl for which a NestedNameSpecifier
 /// is requested.
 static NestedNameSpecifier *createNestedNameSpecifier(
-const ASTContext &Ctx, const NamespaceDecl *Namesp);
+const ASTContext &Ctx,
+const NamespaceDecl *Namesp,
+bool WithGlobalNsPrefix);
 
 /// \brief Create a NestedNameSpecifier for TagDecl and its enclosing
 /// scopes.
@@ -50,16 +53,19 @@
 /// \param[in] FullyQualify - Convert all template arguments into fully
 /// qualified names.
 static NestedNameSpecifier *createNestedNameSpecifier(
-const ASTContext &Ctx, const TypeDecl *TD, bool FullyQualify);
+const ASTContext &Ctx, const TypeDecl *TD,
+bool FullyQualify, bool WithGlobalNsPrefix);
 
 static NestedNameSpecifier *createNestedNameSpecifierForScopeOf(
-const ASTContext &Ctx, const Decl *decl, bool FullyQualified);
+const ASTContext &Ctx, const Decl *decl,
+bool FullyQualified, bool WithGlobalNsPrefix);
 
 static NestedNameSpecifier *getFullyQualifiedNestedNameSpecifier(
-const ASTContext &Ctx, NestedNameSpecifier *scope);
+const ASTContext &Ctx, NestedNameSpecifier *scope, bool WithGlobalNsPrefix);
 
 static bool getFullyQualifiedTemplateName(const ASTContext &Ctx,
-  TemplateName &TName) {
+  TemplateName &TName,
+  bool WithGlobalNsPrefix) {
   bool Changed = false;
   NestedNameSpecifier *NNS = nullptr;
 
@@ -71,15 +77,17 @@
 
   if (QTName && !QTName->hasTemplateKeyword()) {
 NNS = QTName->getQualifier();
-NestedNameSpecifier *QNNS = getFullyQualifiedNestedNameSpecifier(Ctx, NNS);
+NestedNameSpecifier *QNNS = getFullyQualifiedNestedNameSpecifier(
+Ctx, NNS, WithGlobalNsPrefix);
 if (QNNS != NNS) {
   Changed = true;
   NNS = QNNS;
 } else {
   NNS = nullptr;
 }
   } else {
-NNS = createNestedNameSpecifierForScopeOf(Ctx, ArgTDecl, true);
+NNS = createNestedNameSpecifierForScopeOf(
+Ctx, ArgTDecl, true, WithGlobalNsPrefix);
   }
   if (NNS) {
 TName = Ctx.getQualifiedTempla

Re: [PATCH] D21666: [Tooling] Add optional argument to getFullyQualifiedName to prepend "::".

2016-06-24 Thread Siva Chandra via cfe-commits
sivachandra added a comment.

PTAL



Comment at: lib/Tooling/Core/QualTypeNames.cpp:435
@@ -399,1 +434,3 @@
+  // Create a nested name specifier if needed.
   Prefix = createNestedNameSpecifierForScopeOf(Ctx, QT.getTypePtr(),
+   true /*FullyQualified*/,

WithGlobalNsPrefix has been added to every function in this file :)

This eliminates the need for the Prepend function. 


http://reviews.llvm.org/D21666



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


Re: [PATCH] D21666: [Tooling] Add optional argument to getFullyQualifiedName to prepend "::".

2016-06-24 Thread Siva Chandra via cfe-commits
sivachandra updated this revision to Diff 61851.
sivachandra added a comment.

Improve global type handling.


http://reviews.llvm.org/D21666

Files:
  include/clang/Tooling/Core/QualTypeNames.h
  lib/Tooling/Core/QualTypeNames.cpp
  unittests/Tooling/QualTypeNamesTest.cpp

Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -14,6 +14,7 @@
 namespace {
 struct TypeNameVisitor : TestVisitor {
   llvm::StringMap ExpectedQualTypeNames;
+  bool WithGlobalNsPrefix = false;
 
   // ValueDecls are the least-derived decl with both a qualtype and a
   // name.
@@ -26,7 +27,8 @@
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
   std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context);
+  TypeName::getFullyQualifiedName(VD->getType(), *Context,
+  WithGlobalNsPrefix);
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -179,6 +181,42 @@
   "  TX CheckTX;"
   "  struct A { typedef int X; };"
   "}");
+
+  TypeNameVisitor GlobalNsPrefix;
+  GlobalNsPrefix.WithGlobalNsPrefix = true;
+  GlobalNsPrefix.ExpectedQualTypeNames["IntVal"] = "int";
+  GlobalNsPrefix.ExpectedQualTypeNames["BoolVal"] = "bool";
+  GlobalNsPrefix.ExpectedQualTypeNames["XVal"] = "::A::B::X";
+  GlobalNsPrefix.ExpectedQualTypeNames["IntAliasVal"] = "::A::B::Alias";
+  GlobalNsPrefix.ExpectedQualTypeNames["ZVal"] = "::A::B::Y::Z";
+  GlobalNsPrefix.ExpectedQualTypeNames["GlobalZVal"] = "::Z";
+  GlobalNsPrefix.ExpectedQualTypeNames["CheckK"] = "D::aStruct";
+  GlobalNsPrefix.runOver(
+  "namespace A {\n"
+  "  namespace B {\n"
+  "int IntVal;\n"
+  "bool BoolVal;\n"
+  "struct X {};\n"
+  "X XVal;\n"
+  "template  class CCC { };\n"
+  "template \n"
+  "using Alias = CCC;\n"
+  "Alias IntAliasVal;\n"
+  "struct Y { struct Z {}; };\n"
+  "Y::Z ZVal;\n"
+  "  }\n"
+  "}\n"
+  "struct Z {};\n"
+  "Z GlobalZVal;\n"
+  "namespace {\n"
+  "  namespace D {\n"
+  "namespace {\n"
+  "  class aStruct {};\n"
+  "  aStruct CheckK;\n"
+  "}\n"
+  "  }\n"
+  "}\n"
+  );
 }
 
 }  // end anonymous namespace
Index: lib/Tooling/Core/QualTypeNames.cpp
===
--- lib/Tooling/Core/QualTypeNames.cpp
+++ lib/Tooling/Core/QualTypeNames.cpp
@@ -30,16 +30,23 @@
 /// \param[in] QT - the type for which the fully qualified type will be
 /// returned.
 /// \param[in] Ctx - the ASTContext to be used.
-static QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx);
+/// \param[in] WithGlobalNsPrefix - Indicate whether the global namespace
+/// specifier "::" should be prepended or not.
+static QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx,
+  bool WithGlobalNsPrefix);
 
 /// \brief Create a NestedNameSpecifier for Namesp and its enclosing
 /// scopes.
 ///
 /// \param[in] Ctx - the AST Context to be used.
 /// \param[in] Namesp - the NamespaceDecl for which a NestedNameSpecifier
 /// is requested.
+/// \param[in] WithGlobalNsPrefix - Indicate whether the global namespace
+/// specifier "::" should be prepended or not.
 static NestedNameSpecifier *createNestedNameSpecifier(
-const ASTContext &Ctx, const NamespaceDecl *Namesp);
+const ASTContext &Ctx,
+const NamespaceDecl *Namesp,
+bool WithGlobalNsPrefix);
 
 /// \brief Create a NestedNameSpecifier for TagDecl and its enclosing
 /// scopes.
@@ -49,17 +56,22 @@
 /// requested.
 /// \param[in] FullyQualify - Convert all template arguments into fully
 /// qualified names.
+/// \param[in] WithGlobalNsPrefix - Indicate whether the global namespace
+/// specifier "::" should be prepended or not.
 static NestedNameSpecifier *createNestedNameSpecifier(
-const ASTContext &Ctx, const TypeDecl *TD, bool FullyQualify);
+const ASTContext &Ctx, const TypeDecl *TD,
+bool FullyQualify, bool WithGlobalNsPrefix);
 
 static NestedNameSpecifier *createNestedNameSpecifierForScopeOf(
-const ASTContext &Ctx, const Decl *decl, bool FullyQualified);
+const ASTContext &Ctx, const Decl *decl,
+bool FullyQualified, bool WithGlobalNsPrefix);
 
 static NestedNameSpecifier *getFullyQualifiedNestedNameSpecifier(
-const ASTContext &Ctx, NestedNameSpecifier *scope);
+const ASTContext &Ctx, NestedNameSpecifier *scope, bool WithGlobalNsPrefix);
 
 static bool getFullyQualifiedTemplateName(const ASTContext &Ctx,
-  TemplateName &TName) {
+  TemplateName &TName,
+

Re: [PATCH] D21666: [Tooling] Add optional argument to getFullyQualifiedName to prepend "::".

2016-06-28 Thread Siva Chandra via cfe-commits
sivachandra added a comment.

Ping.


http://reviews.llvm.org/D21666



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


r274185 - [Tooling] Add optional argument to getFullyQualifiedName to prepend "::".

2016-06-29 Thread Siva Chandra via cfe-commits
Author: sivachandra
Date: Wed Jun 29 17:38:59 2016
New Revision: 274185

URL: http://llvm.org/viewvc/llvm-project?rev=274185&view=rev
Log:
[Tooling] Add optional argument to getFullyQualifiedName to prepend "::".

Reviewers: rsmith, saugustine, rnk

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D21666

Modified:
cfe/trunk/include/clang/Tooling/Core/QualTypeNames.h
cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp

Modified: cfe/trunk/include/clang/Tooling/Core/QualTypeNames.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/QualTypeNames.h?rev=274185&r1=274184&r2=274185&view=diff
==
--- cfe/trunk/include/clang/Tooling/Core/QualTypeNames.h (original)
+++ cfe/trunk/include/clang/Tooling/Core/QualTypeNames.h Wed Jun 29 17:38:59 
2016
@@ -69,8 +69,11 @@ namespace TypeName {
 /// \param[in] QT - the type for which the fully qualified name will be
 /// returned.
 /// \param[in] Ctx - the ASTContext to be used.
+/// \param[in] WithGlobalNsPrefix - If true, then the global namespace
+/// specifier "::" will be prepended to the fully qualified name.
 std::string getFullyQualifiedName(QualType QT,
-  const ASTContext &Ctx);
+  const ASTContext &Ctx,
+  bool WithGlobalNsPrefix = false);
 }  // end namespace TypeName
 }  // end namespace clang
 #endif  // LLVM_CLANG_TOOLING_CORE_QUALTYPENAMES_H

Modified: cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp?rev=274185&r1=274184&r2=274185&view=diff
==
--- cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp (original)
+++ cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp Wed Jun 29 17:38:59 2016
@@ -30,7 +30,10 @@ namespace TypeName {
 /// \param[in] QT - the type for which the fully qualified type will be
 /// returned.
 /// \param[in] Ctx - the ASTContext to be used.
-static QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx);
+/// \param[in] WithGlobalNsPrefix - Indicate whether the global namespace
+/// specifier "::" should be prepended or not.
+static QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx,
+  bool WithGlobalNsPrefix);
 
 /// \brief Create a NestedNameSpecifier for Namesp and its enclosing
 /// scopes.
@@ -38,8 +41,12 @@ static QualType getFullyQualifiedType(Qu
 /// \param[in] Ctx - the AST Context to be used.
 /// \param[in] Namesp - the NamespaceDecl for which a NestedNameSpecifier
 /// is requested.
+/// \param[in] WithGlobalNsPrefix - Indicate whether the global namespace
+/// specifier "::" should be prepended or not.
 static NestedNameSpecifier *createNestedNameSpecifier(
-const ASTContext &Ctx, const NamespaceDecl *Namesp);
+const ASTContext &Ctx,
+const NamespaceDecl *Namesp,
+bool WithGlobalNsPrefix);
 
 /// \brief Create a NestedNameSpecifier for TagDecl and its enclosing
 /// scopes.
@@ -49,17 +56,22 @@ static NestedNameSpecifier *createNested
 /// requested.
 /// \param[in] FullyQualify - Convert all template arguments into fully
 /// qualified names.
+/// \param[in] WithGlobalNsPrefix - Indicate whether the global namespace
+/// specifier "::" should be prepended or not.
 static NestedNameSpecifier *createNestedNameSpecifier(
-const ASTContext &Ctx, const TypeDecl *TD, bool FullyQualify);
+const ASTContext &Ctx, const TypeDecl *TD,
+bool FullyQualify, bool WithGlobalNsPrefix);
 
 static NestedNameSpecifier *createNestedNameSpecifierForScopeOf(
-const ASTContext &Ctx, const Decl *decl, bool FullyQualified);
+const ASTContext &Ctx, const Decl *decl,
+bool FullyQualified, bool WithGlobalNsPrefix);
 
 static NestedNameSpecifier *getFullyQualifiedNestedNameSpecifier(
-const ASTContext &Ctx, NestedNameSpecifier *scope);
+const ASTContext &Ctx, NestedNameSpecifier *scope, bool 
WithGlobalNsPrefix);
 
 static bool getFullyQualifiedTemplateName(const ASTContext &Ctx,
-  TemplateName &TName) {
+  TemplateName &TName,
+  bool WithGlobalNsPrefix) {
   bool Changed = false;
   NestedNameSpecifier *NNS = nullptr;
 
@@ -71,7 +83,8 @@ static bool getFullyQualifiedTemplateNam
 
   if (QTName && !QTName->hasTemplateKeyword()) {
 NNS = QTName->getQualifier();
-NestedNameSpecifier *QNNS = getFullyQualifiedNestedNameSpecifier(Ctx, NNS);
+NestedNameSpecifier *QNNS = getFullyQualifiedNestedNameSpecifier(
+Ctx, NNS, WithGlobalNsPrefix);
 if (QNNS != NNS) {
   Changed = true;
   NNS = QNNS;
@@ -79,7 +92,8 @@ static bool getFullyQualifiedTemplateNam
   NNS = nullptr;

Re: [PATCH] D21666: [Tooling] Add optional argument to getFullyQualifiedName to prepend "::".

2016-06-29 Thread Siva Chandra via cfe-commits
sivachandra added a comment.

Thanks for the review; Committed.


http://reviews.llvm.org/D21666



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