[clang] 1cb0e01 - [DebugInfo][DWARF5]: Added support for debuginfo generation for defaulted parameters

2020-03-02 Thread Sourabh Singh Tomar via cfe-commits

Author: Awanish Pandey
Date: 2020-03-03T13:09:53+05:30
New Revision: 1cb0e01e42ca5e9de44d9b7cb03d23552a9a9ae1

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

LOG: [DebugInfo][DWARF5]: Added support for debuginfo generation for defaulted 
parameters

This patch adds support for dwarf emission/dumping part of debuginfo
generation for defaulted parameters.

Reviewers: probinson, aprantl, dblaikie

Reviewed By: aprantl, dblaikie

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

Added: 
clang/test/CodeGenCXX/debug-info-template-parameter.cpp

Modified: 
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-template-parameter.cpp 
b/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
new file mode 100644
index ..95e7a187fe10
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -0,0 +1,29 @@
+// Test for DebugInfo for Defaulted parameters for C++ templates
+// Supported: -O0, standalone DI
+
+// RUN: %clang_cc1 -dwarf-version=5  -emit-llvm -triple x86_64-linux-gnu %s -o 
- \
+// RUN:   -O0 -disable-llvm-passes \
+// RUN:   -debug-info-kind=standalone \
+// RUN: | FileCheck %s
+
+// CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F1_TYPE:[0-9]+]]
+// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}})
+// CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
value: i32 6)
+
+// CHECK: DILocalVariable(name: "f2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
+// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: 
![[F2_TYPE:[0-9]+]]
+// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]]}
+// CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}}, 
defaulted: true)
+// CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, 
defaulted: true, value: i32 3)
+
+template 
+class foo {
+};
+
+int main() {
+  foo f1;
+  foo<> f2;
+  return 0;
+}

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp 
b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index def2dc0e0889..134ef74b2704 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1045,6 +1045,8 @@ void DwarfUnit::constructTemplateTypeParameterDIE(
 addType(ParamDIE, TP->getType());
   if (!TP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
+  if (TP->isDefault() && (DD->getDwarfVersion() >= 5))
+addFlag(ParamDIE, dwarf::DW_AT_default_value);
 }
 
 void DwarfUnit::constructTemplateValueParameterDIE(
@@ -1057,6 +1059,8 @@ void DwarfUnit::constructTemplateValueParameterDIE(
 addType(ParamDIE, VP->getType());
   if (!VP->getName().empty())
 addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
+  if (VP->isDefault() && (DD->getDwarfVersion() >= 5))
+addFlag(ParamDIE, dwarf::DW_AT_default_value);
   if (Metadata *Val = VP->getValue()) {
 if (ConstantInt *CI = mdconst::dyn_extract(Val))
   addConstantValue(ParamDIE, CI, VP->getType());



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


[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM with a few small comments, please address those before landing.




Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:262
+  }
+  assert(Spelling->size() == 1);
+  if (auto Err = DeclarationCleanups.add(tooling::Replacement(

kadircet wrote:
> why assert on this and not delete the whole Spelling that produced the 
> virtual keyword ?
> 
> e.g.
> 
> 
> ```
> #define STUPID_MACRO(X) virtual
> struct F {
> STUPID_MACRO(BLA BLA) void foo();
> }
> ```
> 
> 
sorry for not explicitly asking in the previous one, could you also add a test 
for this case?



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:244
+SourceRange SpecRange{FD->getBeginLoc(), FD->getLocation()};
+bool HasNoErrors = false;
+

double negation is bad(this already looks confusing, sounds like we start in an 
errorful state?) I think we should rather have `HadErrors`



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:2205
+  };)cpp",
+" void A::foo() {}\n",},
+  {R"cpp(

you also need to delete the comma just before the `}`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429



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


[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-02 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 247794.
PaulkaToast marked 11 inline comments as done.
Herald added subscribers: jfb, arphaman.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers not provided by the compiler within
+llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // Not allowed because it is part of system libc
+   #include// Allowed because it is provided by the compiler
+   #include "internal/stdio.h"   // Allowed because it is NOT part of system libc
+
+
+This check is necesary because accidentally including sytem libc headers can
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose `FILE *` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime
+because they are ABI incompatible.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-02 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added a comment.

In D75332#1897487 , @njames93 wrote:

> The test cases need fixing as they are causing the build to fail.


Done.

> Also would it be wise to add a .clang-tidy file to libc/ to enable this 
> module for that subdirectory?

Yes, this will be done in a separate patch. Thanks for pointing it out!

In D75332#1897868 , @Eugene.Zelenko 
wrote:

> Please mention new module in docs/clang-tidy/index.rst and Release Notes (new 
> modules section is above new checks one and please add subsubsection).


Done.

In D75332#1899201 , @MaskRay wrote:

> I am of the feeling that this check should not be llvm-libc specific. It is a 
> general need that certain system headers are not desired. This patch can 
> provide a general mechanism (some whitelists and blacklists).


Please see my reply to aaron.




Comment at: 
clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp:40
+SrcMgr::CharacteristicKind FileType) {
+  if (SrcMgr::isSystem(FileType)) {
+if (!SM.isInMainFile(HashLoc)) {

aaron.ballman wrote:
> njames93 wrote:
> > abrachet wrote:
> > > Could you whitelist the freestanding/compiler provided headers like 
> > > stddef, stdatomic...
> > Or have a user configurable whitelist 
> It should be configurable and named something other than whitelist. I'd 
> recommend `AllowedHeaders` or something along those lines.
Maintaining a list of acceptable and blacklisted headers would produce a fair 
bit of maintenance burden. We have a specific use-case in mind here for 
llvm-libc which is to avoid use of system libc headers that aren't provided by 
the compiler. I've added a check to allow for compiler provided headers without 
necessitating a black/white list. 

If a general check is desirable then my suggestion is to pull out [[ 
https://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-system-includes.html
 | fuchsia-restrict-system-includes ]] which already implements the features 
mentioned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75332



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


[PATCH] D75491: [CodeGenObjC] Privatize some ObjC metadata symbols

2020-03-02 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.

LGTM.


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

https://reviews.llvm.org/D75491



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


[PATCH] D75494: [PowerPC] Delete PPCMachObjectWriter and triple for darwin

2020-03-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 247784.
MaskRay added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75494

Files:
  clang/test/Driver/darwin-arch-default.c
  clang/test/Driver/darwin-header-search-libstdcxx.cpp
  clang/test/Tooling/ms-asm-no-target.cpp
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/PowerPC/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
  llvm/unittests/BinaryFormat/MachOTest.cpp
  llvm/utils/gn/secondary/llvm/lib/Target/PowerPC/MCTargetDesc/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/Target/PowerPC/MCTargetDesc/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Target/PowerPC/MCTargetDesc/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Target/PowerPC/MCTargetDesc/BUILD.gn
@@ -58,7 +58,6 @@
 "PPCMCCodeEmitter.cpp",
 "PPCMCExpr.cpp",
 "PPCMCTargetDesc.cpp",
-"PPCMachObjectWriter.cpp",
 "PPCPredicates.cpp",
 "PPCXCOFFObjectWriter.cpp",
   ]
Index: llvm/unittests/BinaryFormat/MachOTest.cpp
===
--- llvm/unittests/BinaryFormat/MachOTest.cpp
+++ llvm/unittests/BinaryFormat/MachOTest.cpp
@@ -58,8 +58,6 @@
   CHECK_CPUTYPE("arm64-apple-darwin", MachO::CPU_TYPE_ARM64);
   CHECK_CPUTYPE("arm64e-apple-darwin", MachO::CPU_TYPE_ARM64);
   CHECK_CPUTYPE("arm64_32-apple-darwin", MachO::CPU_TYPE_ARM64_32);
-  CHECK_CPUTYPE("powerpc-apple-darwin", MachO::CPU_TYPE_POWERPC);
-  CHECK_CPUTYPE("powerpc64-apple-darwin", MachO::CPU_TYPE_POWERPC64);
 
   {
 // Not a mach-o.
@@ -101,8 +99,6 @@
   CHECK_CPUSUBTYPE("arm64-apple-darwin", MachO::CPU_SUBTYPE_ARM64_ALL);
   CHECK_CPUSUBTYPE("arm64e-apple-darwin", MachO::CPU_SUBTYPE_ARM64E);
   CHECK_CPUSUBTYPE("arm64_32-apple-darwin", MachO::CPU_SUBTYPE_ARM64_32_V8);
-  CHECK_CPUSUBTYPE("powerpc-apple-darwin", MachO::CPU_SUBTYPE_POWERPC_ALL);
-  CHECK_CPUSUBTYPE("powerpc64-apple-darwin", MachO::CPU_SUBTYPE_POWERPC_ALL);
 
   {
 // Not a mach-o.
Index: llvm/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
===
--- llvm/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
+++ /dev/null
@@ -1,380 +0,0 @@
-//===-- PPCMachObjectWriter.cpp - PPC Mach-O Writer ---===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "MCTargetDesc/PPCFixupKinds.h"
-#include "MCTargetDesc/PPCMCTargetDesc.h"
-#include "llvm/ADT/Twine.h"
-#include "llvm/BinaryFormat/MachO.h"
-#include "llvm/MC/MCAsmLayout.h"
-#include "llvm/MC/MCAssembler.h"
-#include "llvm/MC/MCContext.h"
-#include "llvm/MC/MCMachObjectWriter.h"
-#include "llvm/MC/MCSectionMachO.h"
-#include "llvm/MC/MCValue.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/Format.h"
-
-using namespace llvm;
-
-namespace {
-class PPCMachObjectWriter : public MCMachObjectTargetWriter {
-  bool recordScatteredRelocation(MachObjectWriter *Writer,
- const MCAssembler ,
- const MCAsmLayout ,
- const MCFragment *Fragment,
- const MCFixup , MCValue Target,
- unsigned Log2Size, uint64_t );
-
-  void RecordPPCRelocation(MachObjectWriter *Writer, const MCAssembler ,
-   const MCAsmLayout ,
-   const MCFragment *Fragment, const MCFixup ,
-   MCValue Target, uint64_t );
-
-public:
-  PPCMachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype)
-  : MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype) {}
-
-  void recordRelocation(MachObjectWriter *Writer, MCAssembler ,
-const MCAsmLayout , const MCFragment *Fragment,
-const MCFixup , MCValue Target,
-uint64_t ) override {
-if (Writer->is64Bit()) {
-  report_fatal_error("Relocation emission for MachO/PPC64 unimplemented.");
-} else
-  RecordPPCRelocation(Writer, Asm, Layout, Fragment, Fixup, Target,
-  FixedValue);
-  }
-};
-}
-
-/// computes the log2 of the size of the relocation,
-/// used for relocation_info::r_length.
-static unsigned getFixupKindLog2Size(unsigned Kind) {
-  switch (Kind) {
-  default:
-report_fatal_error("log2size(FixupKind): Unhandled fixup kind!");
-  case FK_PCRel_1:
-  case FK_Data_1:
-return 0;
-  case FK_PCRel_2:
- 

[PATCH] D74669: [clang-tidy] New check: bugprone-suspicious-include

2020-03-02 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs marked 2 inline comments as done.
jroelofs added a comment.

In D74669#1902107 , @njames93 wrote:

> Adding the parent revision means you don't need to have those changes in this 
> patch.


IIUC, that is what I've already done:

https://reviews.llvm.org/D74669 is `git show c4dd6f5903e -U999`
https://reviews.llvm.org/D75489 is `git show 0cda7e0b9ed -U999`

where `c4dd6f5903e` is the parent of `0cda7e0b9ed`.

The suggestion to switch over to `;`s as delimiters is what's causing this diff 
to still touch so many files.




Comment at: 
clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h:24
+/// extensions of header files (The filename extensions should not contain
+/// "." prefix). "h;hh;hpp;hxx" by default.
+//

";h;hh;hpp;hxx"



Comment at: 
clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h:25
+/// extensions of header files (The filename extensions should not contain
+/// "." prefix). "h;hh;hpp;hxx" by default.
+///

";h;hh;hpp;hxx"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74669



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


[PATCH] D74104: Remove test dependency on the presence of an assembler

2020-03-02 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74104



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


[PATCH] D75491: [CodeGenObjC] Privatize some ObjC metadata symbols

2020-03-02 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak accepted this revision.
ahatanak added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D75491



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


[PATCH] D75492: [clang-tidy]: modernize-use-using: don't diagnose typedefs in `extern "C"` DeclContexts

2020-03-02 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

See also https://llvm.org/PR35924.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75492



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


[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 247779.
njames93 added a comment.

- Addressed comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2068,6 +2068,80 @@
   };)cpp",
   "Foo::Foo(int z) __attribute__((weak)) : bar(2){}\n",
   },
+  // Virt specifiers.
+  {
+  R"cpp(
+struct A {
+  virtual void f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() ;
+};)cpp",
+  " void A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual virtual void virtual f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual virtual void virtual foo() ;
+};)cpp",
+  "  void  A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() override ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final override ;
+};)cpp",
+  "void B::foo()   {}\n",
+  },
   };
   for (const auto  : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2081,6 +2155,8 @@
   llvm::StringMap EditedFiles;
   ExtraFiles["Test.cpp"] = "";
   FileName = "Test.hpp";
+  ExtraArgs.push_back("-DVIRTUAL=virtual");
+  ExtraArgs.push_back("-DOVER=override");
 
   struct {
 llvm::StringRef Test;
@@ -2118,6 +2194,39 @@
   #define TARGET foo
   void TARGET();)cpp",
"void TARGET(){ return; }"},
+  {R"cpp(#define VIRT virtual
+  struct A {
+VIRT void f^oo() {}
+  };)cpp",
+   R"cpp(#define VIRT virtual
+  struct A {
+VIRT void foo() ;
+  };)cpp",
+" void A::foo() {}\n",},
+  {R"cpp(
+  struct A {
+VIRTUAL void f^oo() {}
+  };)cpp",
+   R"cpp(
+  struct A {
+VIRTUAL void foo() ;
+  };)cpp",
+" void A::foo() {}\n",},
+  {R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void fo^o() OVER {}
+  };)cpp",
+   R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void foo() OVER ;
+  };)cpp",
+"void B::foo()  {}\n",},
   };
   for (const auto  : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2229,6 +2338,49 @@
 << Case.TestHeader;
   }
 }
+
+TEST_F(DefineOutlineTest, FailsMacroSpecifier) {
+  FileName = "Test.hpp";
+  ExtraFiles["Test.cpp"] = "";
+  ExtraArgs.push_back("-DFINALOVER=final override");
+
+  std::pair Cases[] = {
+  {
+  R"cpp(
+  #define VIRT virtual void
+  struct A {
+VIRT fo^o() {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `virtual` specifier."},
+  {
+  R"cpp(
+  #define OVERFINAL final override
+  struct A {
+virtual void foo() {}
+  };
+  struct B : A {
+void fo^o() OVERFINAL {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `override` specifier.\ndefine outline: Can't move out of line "
+  "as function has a macro `final` specifier."},
+  {
+  R"cpp(
+  struct A {
+virtual void foo() {}
+  };
+  struct B : A {
+void fo^o() FINALOVER 

[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

I'm finally happy with the semantic checks here. Thanks for the guidance on 
where to look for the hooks.

- attributed variable must be at global scope
- all initializers are rejected
- default constructors must be trivial (to reduce the scope of this patch)
- extern variables rejected as they can't meaningfully have a definition
- attribute on a declaration following a normal definition in C rejected

Patch is a bit bigger than I hoped for but quite self contained. Everything is 
guarded by a test on the attribute.

@Quuxplusone does restricting this to trivial default construction resolve your 
concerns?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361



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


[PATCH] D75215: [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.

2020-03-02 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 247774.
akhuang added a comment.

Add FlagNonTrivial to fwd declared records in CGDebugInfo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75215

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-flag-nontrivial.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/function-options.ll

Index: llvm/test/DebugInfo/COFF/function-options.ll
===
--- llvm/test/DebugInfo/COFF/function-options.ll
+++ llvm/test/DebugInfo/COFF/function-options.ll
@@ -1,10 +1,8 @@
-; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s
-; RUN: llc < %s | llvm-mc -filetype=obj --triple=x86_64-windows | llvm-readobj - --codeview | FileCheck %s
+; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s
 ;
 ; Command to generate function-options.ll
 ; $ clang++ function-options.cpp -S -emit-llvm -g -gcodeview -o function-options.ll
 ;
-;
 ; #define DEFINE_FUNCTION(T) \
 ;   T Func_##T(T ) { return arg; }
 ;
@@ -32,7 +30,11 @@
 ; class DClass : public BClass {}; // Note: MSVC yields one compiler-generated ctor for DClass while clang doesn't.
 ; DEFINE_FUNCTION(DClass); // Expect: FO = CxxReturnUdt
 ;
-; class FClass { static int x; };
+; class FClass {
+;   static int x;
+;   AClass Member_AClass(AClass &);
+;   BClass Member_BClass(BClass &);
+; };
 ; DEFINE_FUNCTION(FClass); // Expect FO = None
 ; 
 ; struct AStruct {};
@@ -54,7 +56,7 @@
 ; CHECK: CodeViewTypes [
 ; CHECK:   Section: .debug$T ({{.*}})
 ; CHECK:   Magic: 0x4
-; CHECK:   Procedure ([[SP1:.*]]) {
+; CHECK:   Procedure ([[SP_A:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: AClass ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -66,10 +68,10 @@
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: AClass (AClass&) ([[SP1]])
+; CHECK: FunctionType: AClass (AClass&) ([[SP_A]])
 ; CHECK: Name: Func_AClass
 ; CHECK:   }
-; CHECK:   Procedure ([[SP2:.*]]) {
+; CHECK:   Procedure ([[SP_B:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: BClass ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -79,11 +81,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (BClass&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF1:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_B:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION (0x1009)
 ; CHECK: ReturnType: void (0x3)
 ; CHECK: ClassType: BClass ({{.*}})
-; CHECK: ThisType: BClass* const ({{.*}})
+; CHECK: ThisType: BClass* {{.*}}
 ; CHECK: CallingConvention: NearC (0x0)
 ; CHECK: FunctionOptions [ (0x2)
 ; CHECK:   Constructor (0x2)
@@ -97,17 +99,17 @@
 ; CHECK: OneMethod {
 ; CHECK:   TypeLeafKind: LF_ONEMETHOD (0x1511)
 ; CHECK:   AccessSpecifier: Private (0x1)
-; CHECK:   Type: void BClass::() ([[MF1]])
+; CHECK:   Type: void BClass::() ([[CTOR_B]])
 ; CHECK:   Name: BClass
 ; CHECK: }
 ; CHECK:   }
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: BClass (BClass&) ([[SP2]])
+; CHECK: FunctionType: BClass (BClass&) ([[SP_B]])
 ; CHECK: Name: Func_BClass
 ; CHECK:   }
-; CHECK:   Procedure ([[SP3:.*]]) {
+; CHECK:   Procedure ([[SP_C1:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: C1Class ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -116,11 +118,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (C1Class&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF2:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_C1:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION (0x1009)
 ; CHECK: ReturnType: void (0x3)
 ; CHECK: ClassType: C1Class ({{.*}})
-; CHECK: ThisType: C1Class* const ({{.*}})
+; CHECK: ThisType: C1Class* {{.*}}
 ; CHECK: CallingConvention: NearC (0x0)
 ; CHECK: FunctionOptions [ (0x0)
 ; CHECK: ]
@@ -133,17 +135,17 @@
 ; CHECK: OneMethod {
 ; CHECK:   TypeLeafKind: LF_ONEMETHOD (0x1511)
 ; CHECK:   AccessSpecifier: Public (0x3)
-; CHECK:   Type: void C1Class::() ([[MF2]])
+; CHECK:   Type: void C1Class::() ([[CTOR_C1]])
 ; CHECK:   Name: C1Class
 ; CHECK: }
 ; CHECK:   }
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: C1Class (C1Class&) ([[SP3]])
+; CHECK: FunctionType: C1Class (C1Class&) ([[SP_C1]])
 ; CHECK: Name: Func_C1Class
 ; CHECK:   }
-; CHECK:   Procedure ([[SP4:.*]]) {
+; CHECK:   Procedure ([[SP_C2:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: C2Class ({{.*}})
 ; CHECK: 

[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield updated this revision to Diff 247776.
JonChesterfield added a comment.

- Error on redeclaration with loader_uninit in C


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/DeclBase.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-loader-uninitialized.c
  clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-loader-uninitialized.c
  clang/test/Sema/attr-loader-uninitialized.cpp

Index: clang/test/Sema/attr-loader-uninitialized.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-loader-uninitialized.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int good __attribute__((loader_uninitialized));
+
+const int still_cant_be_const __attribute__((loader_uninitialized));
+// expected-error@-1 {{default initialization of an object of const type}}
+extern int external_rejected __attribute__((loader_uninitialized));
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute cannot have external linkage}}
+
+int noargs __attribute__((loader_uninitialized(0)));
+// expected-error@-1 {{'loader_uninitialized' attribute takes no arguments}} 
+
+void func() __attribute__((loader_uninitialized))
+// expected-warning@-1 {{'loader_uninitialized' attribute only applies to global variables}}
+{
+  int local __attribute__((loader_uninitialized));
+  // expected-warning@-1 {{'loader_uninitialized' attribute only applies to global variables}}
+
+  static int sl __attribute__((loader_uninitialized));
+}
+
+struct s {
+  __attribute__((loader_uninitialized)) int field;
+  // expected-warning@-1 {{'loader_uninitialized' attribute only applies to global variables}}
+
+  static __attribute__((loader_uninitialized)) int sfield;
+
+} __attribute__((loader_uninitialized));
+// expected-warning@-1 {{'loader_uninitialized' attribute only applies to global variables}}
+
+int redef_attr_first __attribute__((loader_uninitialized));
+int redef_attr_first;
+// expected-error@-1 {{redefinition of 'redef_attr_first'}}
+// expected-note@-3 {{previous definition is here}}
+
+int redef_attr_second; 
+int redef_attr_second __attribute__((loader_uninitialized)); 
+// expected-warning@-1 {{attribute declaration must precede definition}}
+// expected-note@-3 {{previous definition is here}}
+// expected-error@-3 {{redefinition of 'redef_attr_second'}}
+// expected-note@-5 {{previous definition is here}}
+
+int init_rejected __attribute__((loader_uninitialized)) = 42;
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute cannot have an initializer}}
+
+struct trivial {};
+
+trivial default_ok __attribute__((loader_uninitialized));
+trivial value_rejected  __attribute__((loader_uninitialized)) {};
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute cannot have an initializer}}
+
+struct nontrivial
+{
+  nontrivial() {}
+};
+
+nontrivial needs_trivial_ctor __attribute__((loader_uninitialized));
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute must have a trivial default constructor}}
Index: clang/test/Sema/attr-loader-uninitialized.c
===
--- /dev/null
+++ clang/test/Sema/attr-loader-uninitialized.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+// See also attr-loader-uninitialized.cpp
+
+int good __attribute__((loader_uninitialized));
+
+int init_rejected __attribute__((loader_uninitialized)) = 42;
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute cannot have an initializer}}
+
+int declaration_then_uninit_ok;
+int declaration_then_uninit_ok __attribute__((loader_uninitialized));
+
+int definition_then_uninit_rejected = 0;
+int definition_then_uninit_rejected __attribute__((loader_uninitialized));
+// expected-error@-1 {{redeclaration cannot add 'loader_uninitialized' attribute}}
+// expected-note@-3 {{previous definition is here}}
+
+int tentative_repeated_ok __attribute__((loader_uninitialized));
+int tentative_repeated_ok __attribute__((loader_uninitialized));
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -65,6 +65,7 @@
 // CHECK-NEXT: InitPriority (SubjectMatchRule_variable)
 // CHECK-NEXT: InternalLinkage (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
 // CHECK-NEXT: LTOVisibilityPublic 

[PATCH] D66831: [ObjC] Fix type checking for qualified id block parameters.

2020-03-02 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Thanks for that explanation; that makes sense. Do you think that the 
`@interface J : I` would also ideally be an error then?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66831



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


[PATCH] D75215: [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.

2020-03-02 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a comment.

In D75215#1899224 , @rnk wrote:

> Now that I've gone this far... maybe we should just say `isNonTrivial() || 
> isFwdDecl()` -> mark it CxxReturnUdt. Something like that.


I just tried this but apparently it ends up marking things as CxxReturnUdt when 
the struct is trivial but not required to be complete--

So it seems like adding the NonTrivial flag to undefined forward declared 
functions would work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75215



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


[PATCH] D66831: [ObjC] Fix type checking for qualified id block parameters.

2020-03-02 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In D66831#1901972 , @smeenai wrote:

> I'm not very familiar with Objective-C semantics. Does saying `@interface J : 
> I ` mean we're overriding the conformance being specified by `@interface I 
> `? In that case, the Clang 10 error makes sense to me.


`@interface J : I ` isn't overriding the conformance specified by 
`@interface I `, it adds conformance to Q.

In D66831#1901972 , @smeenai wrote:

> In practice though, classes like `UIImage` are declared as inheriting from 
> `NSObject`, so passing a `UIImage *` to a block with a 
> parameter of type `id` gives an error with Clang 10.


I didn't try your example in a debugger but I believe we should warn here 
because code invoking the block is not guaranteed to call it with `UIImage *`, 
only with `id`. And using `UIImage *` inside the block is dangerous. 
To expand on your example

  @protocol P
  @end
  
  @protocol Q
  - (void)specificMethod;
  @end
  
  @interface I 
  @end
  
  @interface J : I 
  - (void)specificMethod;
  @end
  
  void f(void (^block)(id)) {
I *i = [I new];
block(i);
  }
  
  void g() {
f(^(J *j){
  [j specificMethod];  // not recognized selector
});
  }

According to this explanation `@interface J : I` should also cause errors but I 
think it works because assigning to/from `id` is somewhat hand-wavy 
and not very strict.

Also consider specifying protocols the other way around

  @protocol P
  @end
  
  @protocol Q
  @end
  
  @interface I 
  @end
  
  @interface J : I 
  @end
  
  void f(void (^)(J *));
  void g() {
f(^(id p){});
f(^(id q){});
  }

I think it shouldn't be an error but clang-9 complains.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66831



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


[PATCH] D74669: [clang-tidy] New check: bugprone-suspicious-include

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Adding the parent revision means you don't need to have those changes in this 
patch. It will cause issues down the line. best thing is to run a diff from 
this to the parent and just include those changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74669



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


[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 247766.
njames93 added a comment.

- Tweaked format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2068,6 +2068,80 @@
   };)cpp",
   "Foo::Foo(int z) __attribute__((weak)) : bar(2){}\n",
   },
+  // Virt specifiers.
+  {
+  R"cpp(
+struct A {
+  virtual void f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() ;
+};)cpp",
+  " void A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual virtual void virtual f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual virtual void virtual foo() ;
+};)cpp",
+  "  void  A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() override ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final override ;
+};)cpp",
+  "void B::foo()   {}\n",
+  },
   };
   for (const auto  : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2081,6 +2155,8 @@
   llvm::StringMap EditedFiles;
   ExtraFiles["Test.cpp"] = "";
   FileName = "Test.hpp";
+  ExtraArgs.push_back("-DVIRTUAL=virtual");
+  ExtraArgs.push_back("-DOVER=override");
 
   struct {
 llvm::StringRef Test;
@@ -2118,6 +2194,39 @@
   #define TARGET foo
   void TARGET();)cpp",
"void TARGET(){ return; }"},
+  {R"cpp(#define VIRT virtual
+  struct A {
+VIRT void f^oo() {}
+  };)cpp",
+   R"cpp(#define VIRT virtual
+  struct A {
+VIRT void foo() ;
+  };)cpp",
+" void A::foo() {}\n",},
+  {R"cpp(
+  struct A {
+VIRTUAL void f^oo() {}
+  };)cpp",
+   R"cpp(
+  struct A {
+VIRTUAL void foo() ;
+  };)cpp",
+" void A::foo() {}\n",},
+  {R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void fo^o() OVER {}
+  };)cpp",
+   R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void foo() OVER ;
+  };)cpp",
+"void B::foo()  {}\n",},
   };
   for (const auto  : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2229,6 +2338,49 @@
 << Case.TestHeader;
   }
 }
+
+TEST_F(DefineOutlineTest, FailsMacroSpecifier) {
+  FileName = "Test.hpp";
+  ExtraFiles["Test.cpp"] = "";
+  ExtraArgs.push_back("-DFINALOVER=final override");
+
+  std::pair Cases[] = {
+  {
+  R"cpp(
+  #define VIRT virtual void
+  struct A {
+VIRT fo^o() {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `virtual` specifier."},
+  {
+  R"cpp(
+  #define OVERFINAL final override
+  struct A {
+virtual void foo() {}
+  };
+  struct B : A {
+void fo^o() OVERFINAL {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `override` specifier.\ndefine outline: Can't move out of line "
+  "as function has a macro `final` specifier."},
+  {
+  R"cpp(
+  struct A {
+virtual void foo() {}
+  };
+  struct B : A {
+void fo^o() FINALOVER {}
+  

[PATCH] D74669: [clang-tidy] New check: bugprone-suspicious-include

2020-03-02 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs updated this revision to Diff 247764.
jroelofs added a comment.

implement review feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74669

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
  clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/a
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/a.cpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/a.hpp
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/c.c
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/c.cc
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/c.cxx
  clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-include.cpp
@@ -0,0 +1,21 @@
+// RUN: %check_clang_tidy %s bugprone-suspicious-include %t -- -- -isystem %S/Inputs/Headers -fmodules
+
+// CHECK-MESSAGES: [[@LINE+4]]:11: warning: suspicious #include of file with '.cpp' extension
+// CHECK-MESSAGES: [[@LINE+3]]:11: note: did you mean to include 'a'?
+// CHECK-MESSAGES: [[@LINE+2]]:11: note: did you mean to include 'a.h'?
+// CHECK-MESSAGES: [[@LINE+1]]:11: note: did you mean to include 'a.hpp'?
+#include "a.cpp"
+
+#include "b.h"
+
+// CHECK-MESSAGES: [[@LINE+1]]:10: warning: suspicious #import of file with '.c' extension
+#import "c.c"
+
+// CHECK-MESSAGES: [[@LINE+1]]:16: warning: suspicious #include_next of file with '.c' extension
+#include_next 
+
+// CHECK-MESSAGES: [[@LINE+1]]:13: warning: suspicious #include of file with '.cc' extension
+# include  
+
+// CHECK-MESSAGES: [[@LINE+1]]:14: warning: suspicious #include of file with '.cxx' extension
+#  include  
Index: clang-tools-extra/clang-tidy/utils/HeaderGuard.h
===
--- clang-tools-extra/clang-tidy/utils/HeaderGuard.h
+++ clang-tools-extra/clang-tidy/utils/HeaderGuard.h
@@ -18,11 +18,12 @@
 
 /// Finds and fixes header guards.
 /// The check supports these options:
-///   - `HeaderFileExtensions`: a comma-separated list of filename extensions of
-/// header files (The filename extension should not contain "." prefix).
-/// ",h,hh,hpp,hxx" by default.
+///   - `HeaderFileExtensions`: a semicolon-separated list of filename
+/// extensions of header files (The filename extension should not contain
+/// "." prefix). ";h;hh;hpp;hxx" by default.
+///
 /// For extension-less header files, using an empty string or leaving an
-/// empty string between "," if there are other filename extensions.
+/// empty string between ";" if there are other filename extensions.
 class HeaderGuardCheck : public ClangTidyCheck {
 public:
   HeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
@@ -30,7 +31,7 @@
 RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
 "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
 utils::parseFileExtensions(RawStringHeaderFileExtensions,
-   HeaderFileExtensions, ',');
+   HeaderFileExtensions, ';');
   }
   void registerPPCallbacks(const SourceManager , Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
Index: clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
===
--- clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
+++ clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
@@ -11,6 +11,7 @@
 
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 
@@ -34,12 +35,23 @@
 
 /// Returns recommended default value for the list 

[PATCH] D75489: [clang-tidy] Generalize HeaderFileExtensions.{h, cpp}. NFC

2020-03-02 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs updated this revision to Diff 247762.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75489

Files:
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.cpp
  clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h

Index: clang-tools-extra/clang-tidy/utils/HeaderGuard.h
===
--- clang-tools-extra/clang-tidy/utils/HeaderGuard.h
+++ clang-tools-extra/clang-tidy/utils/HeaderGuard.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H
 
 #include "../ClangTidy.h"
-#include "../utils/HeaderFileExtensionsUtils.h"
+#include "../utils/FileExtensionsUtils.h"
 
 namespace clang {
 namespace tidy {
@@ -29,8 +29,8 @@
   : ClangTidyCheck(Name, Context),
 RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
 "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
-utils::parseHeaderFileExtensions(RawStringHeaderFileExtensions,
- HeaderFileExtensions, ',');
+utils::parseFileExtensions(RawStringHeaderFileExtensions,
+   HeaderFileExtensions, ',');
   }
   void registerPPCallbacks(const SourceManager , Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
@@ -54,7 +54,7 @@
 
 private:
   std::string RawStringHeaderFileExtensions;
-  utils::HeaderFileExtensionsSet HeaderFileExtensions;
+  utils::FileExtensionsSet HeaderFileExtensions;
 };
 
 } // namespace utils
Index: clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
===
--- clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
+++ clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
@@ -273,13 +273,13 @@
 }
 
 bool HeaderGuardCheck::shouldSuggestEndifComment(StringRef FileName) {
-  return utils::isHeaderFileExtension(FileName, HeaderFileExtensions);
+  return utils::isFileExtension(FileName, HeaderFileExtensions);
 }
 
 bool HeaderGuardCheck::shouldFixHeaderGuard(StringRef FileName) { return true; }
 
 bool HeaderGuardCheck::shouldSuggestToAddHeaderGuard(StringRef FileName) {
-  return utils::isHeaderFileExtension(FileName, HeaderFileExtensions);
+  return utils::isFileExtension(FileName, HeaderFileExtensions);
 }
 
 std::string HeaderGuardCheck::formatEndIf(StringRef HeaderGuard) {
Index: clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-//===--- HeaderFileExtensionsUtils.cpp - clang-tidy--*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "HeaderFileExtensionsUtils.h"
-#include "clang/Basic/CharInfo.h"
-#include "llvm/Support/Path.h"
-
-namespace clang {
-namespace tidy {
-namespace utils {
-
-bool isExpansionLocInHeaderFile(
-SourceLocation Loc, const SourceManager ,
-const HeaderFileExtensionsSet ) {
-  SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
-  return isHeaderFileExtension(SM.getFilename(ExpansionLoc),
-   HeaderFileExtensions);
-}
-
-bool isPresumedLocInHeaderFile(
-SourceLocation Loc, SourceManager ,
-const HeaderFileExtensionsSet ) {
-  PresumedLoc PresumedLocation = SM.getPresumedLoc(Loc);
-  return isHeaderFileExtension(PresumedLocation.getFilename(),
-   HeaderFileExtensions);
-}
-
-bool isSpellingLocInHeaderFile(
-SourceLocation Loc, SourceManager ,
-const HeaderFileExtensionsSet ) {
-  SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
-  return isHeaderFileExtension(SM.getFilename(SpellingLoc),
-   HeaderFileExtensions);
-}
-
-bool 

[PATCH] D75483: [Sema] Fix a crash when attaching comments to an implicit decl

2020-03-02 Thread Erik Pilkington via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG29a4239d31c6: [Sema] Fix a crash when attaching comments to 
an implicit decl (authored by erik.pilkington).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75483

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/Sema/warn-documentation.m


Index: clang/test/Sema/warn-documentation.m
===
--- clang/test/Sema/warn-documentation.m
+++ clang/test/Sema/warn-documentation.m
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation 
-Wdocumentation-pedantic -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -fsyntax-only -fblocks -Wno-objc-root-class 
-Wdocumentation -Wdocumentation-pedantic -verify %s
 
 @class NSString;
 
@@ -318,3 +319,10 @@
 // expected-warning@-1 {{'\return' command used in a comment that is not 
attached to a function or method declaration}}
 VoidBlockTypeCall ^e; ///< \return none
 // expected-warning@-1 {{'\return' command used in a comment that is not 
attached to a function or method declaration}}
+
+#ifdef __cplusplus
+@interface HasAnonNamespace @end
+@implementation HasAnonNamespace
+namespace {}
+@end
+#endif
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -474,10 +474,20 @@
   if (Comments.empty() || Decls.empty())
 return;
 
-  // See if there are any new comments that are not attached to a decl.
-  // The location doesn't have to be precise - we care only about the file.
-  const FileID File =
-  SourceMgr.getDecomposedLoc((*Decls.begin())->getLocation()).first;
+  FileID File;
+  for (Decl *D : Decls) {
+SourceLocation Loc = D->getLocation();
+if (Loc.isValid()) {
+  // See if there are any new comments that are not attached to a decl.
+  // The location doesn't have to be precise - we care only about the file.
+  File = SourceMgr.getDecomposedLoc(Loc).first;
+  break;
+}
+  }
+
+  if (File.isInvalid())
+return;
+
   auto CommentsInThisFile = Comments.getCommentsInFile(File);
   if (!CommentsInThisFile || CommentsInThisFile->empty() ||
   CommentsInThisFile->rbegin()->second->isAttached())


Index: clang/test/Sema/warn-documentation.m
===
--- clang/test/Sema/warn-documentation.m
+++ clang/test/Sema/warn-documentation.m
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation -Wdocumentation-pedantic -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation -Wdocumentation-pedantic -verify %s
 
 @class NSString;
 
@@ -318,3 +319,10 @@
 // expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
 VoidBlockTypeCall ^e; ///< \return none
 // expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
+
+#ifdef __cplusplus
+@interface HasAnonNamespace @end
+@implementation HasAnonNamespace
+namespace {}
+@end
+#endif
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -474,10 +474,20 @@
   if (Comments.empty() || Decls.empty())
 return;
 
-  // See if there are any new comments that are not attached to a decl.
-  // The location doesn't have to be precise - we care only about the file.
-  const FileID File =
-  SourceMgr.getDecomposedLoc((*Decls.begin())->getLocation()).first;
+  FileID File;
+  for (Decl *D : Decls) {
+SourceLocation Loc = D->getLocation();
+if (Loc.isValid()) {
+  // See if there are any new comments that are not attached to a decl.
+  // The location doesn't have to be precise - we care only about the file.
+  File = SourceMgr.getDecomposedLoc(Loc).first;
+  break;
+}
+  }
+
+  if (File.isInvalid())
+return;
+
   auto CommentsInThisFile = Comments.getCommentsInFile(File);
   if (!CommentsInThisFile || CommentsInThisFile->empty() ||
   CommentsInThisFile->rbegin()->second->isAttached())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75492: [modernize-use-using] Don't diagnose typedefs in `extern "C"` DeclContexts

2020-03-02 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv created this revision.
george.burgess.iv added a reviewer: aaron.ballman.

If code is shared between C and C++, converting a `typedef` to a `using` isn't 
possible. Being more conservative about emitting these lints in `extern "C"` 
blocks seems like a good compromise to me.


https://reviews.llvm.org/D75492

Files:
  clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
@@ -278,3 +278,7 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: using EnumT2_CheckTypedefImpactFromAnotherFile = enum { ea2, 
eb2 };
 
+extern "C" {
+typedef int Type;
+// No messages expected, since this code may be shared verbatim with C.
+}
Index: clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -48,6 +48,9 @@
   if (StartLoc.isMacroID() && IgnoreMacros)
 return;
 
+  if (MatchedDecl->getDeclContext()->isExternCContext())
+return;
+
   static const char *UseUsingWarning = "use 'using' instead of 'typedef'";
 
   // Warn at StartLoc but do not fix if there is macro or array.


Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
@@ -278,3 +278,7 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: using EnumT2_CheckTypedefImpactFromAnotherFile = enum { ea2, eb2 };
 
+extern "C" {
+typedef int Type;
+// No messages expected, since this code may be shared verbatim with C.
+}
Index: clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -48,6 +48,9 @@
   if (StartLoc.isMacroID() && IgnoreMacros)
 return;
 
+  if (MatchedDecl->getDeclContext()->isExternCContext())
+return;
+
   static const char *UseUsingWarning = "use 'using' instead of 'typedef'";
 
   // Warn at StartLoc but do not fix if there is macro or array.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 29a4239 - [Sema] Fix a crash when attaching comments to an implicit decl

2020-03-02 Thread Erik Pilkington via cfe-commits

Author: Erik Pilkington
Date: 2020-03-02T16:49:53-08:00
New Revision: 29a4239d31c6d8ccc557afbe0999aa096ca95cc6

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

LOG: [Sema] Fix a crash when attaching comments to an implicit decl

When an implicitly generated decl was the first entry in the group, we
attempted to lookup comments with an empty FileID, leading to crashes. Avoid
this by trying to use the other declarations in the group, and then bailing out
if none are valid.

rdar://59919733
Differential revision: https://reviews.llvm.org/D75483

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/test/Sema/warn-documentation.m

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index bc4f2b491e11..93a8aab7c068 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -474,10 +474,20 @@ void 
ASTContext::attachCommentsToJustParsedDecls(ArrayRef Decls,
   if (Comments.empty() || Decls.empty())
 return;
 
-  // See if there are any new comments that are not attached to a decl.
-  // The location doesn't have to be precise - we care only about the file.
-  const FileID File =
-  SourceMgr.getDecomposedLoc((*Decls.begin())->getLocation()).first;
+  FileID File;
+  for (Decl *D : Decls) {
+SourceLocation Loc = D->getLocation();
+if (Loc.isValid()) {
+  // See if there are any new comments that are not attached to a decl.
+  // The location doesn't have to be precise - we care only about the file.
+  File = SourceMgr.getDecomposedLoc(Loc).first;
+  break;
+}
+  }
+
+  if (File.isInvalid())
+return;
+
   auto CommentsInThisFile = Comments.getCommentsInFile(File);
   if (!CommentsInThisFile || CommentsInThisFile->empty() ||
   CommentsInThisFile->rbegin()->second->isAttached())

diff  --git a/clang/test/Sema/warn-documentation.m 
b/clang/test/Sema/warn-documentation.m
index c713d5b07f85..5d60a52ae6fe 100644
--- a/clang/test/Sema/warn-documentation.m
+++ b/clang/test/Sema/warn-documentation.m
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation 
-Wdocumentation-pedantic -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -fsyntax-only -fblocks -Wno-objc-root-class 
-Wdocumentation -Wdocumentation-pedantic -verify %s
 
 @class NSString;
 
@@ -318,3 +319,10 @@ @interface CheckFunctionBlockPointerVars {
 // expected-warning@-1 {{'\return' command used in a comment that is not 
attached to a function or method declaration}}
 VoidBlockTypeCall ^e; ///< \return none
 // expected-warning@-1 {{'\return' command used in a comment that is not 
attached to a function or method declaration}}
+
+#ifdef __cplusplus
+@interface HasAnonNamespace @end
+@implementation HasAnonNamespace
+namespace {}
+@end
+#endif



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


[PATCH] D75465: [clang-format] Do not merge target-name and : for C# attributes

2020-03-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:281
   Style.ColumnLimit = 10;
-  verifyFormat(R"([assembly:InternalsVisibleTo(
+  verifyFormat(R"([assembly: InternalsVisibleTo(
 "SomeAssembly, PublicKey=SomePublicKeyThatExceedsTheColumnLimit")])",

isn't the space after the `:` a regression?
Looking at
https://docs.microsoft.com/en-us/dotnet/standard/assembly/set-attributes
it looks like such attributes are spelled `[assembly:Blah]`

How is an example where such an attribute is not the last thing in the file?

I'm not entirely clear on which edit caused this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75465



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


[PATCH] D75491: [CodeGenObjC] Privatize some ObjC metadata symbols

2020-03-02 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.
erik.pilkington added reviewers: rjmccall, ahatanak, vsk.
Herald added subscribers: ributzka, dexonsmith, jkorous.

Nobody needs these symbols, so there isn't any benefit in including them. This 
saves some code-size in Objective-C binaries.

Partially reverts: https://reviews.llvm.org/D61454

rdar://56579760


https://reviews.llvm.org/D75491

Files:
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/test/CodeGenObjC/class-stubs.m
  clang/test/CodeGenObjC/exceptions-asm-attribute.m
  clang/test/CodeGenObjC/metadata-symbols-64.m
  clang/test/CodeGenObjC/metadata_symbols.m
  clang/test/CodeGenObjC/non-lazy-classes.m
  clang/test/CodeGenObjC/sections.m

Index: clang/test/CodeGenObjC/sections.m
===
--- clang/test/CodeGenObjC/sections.m
+++ clang/test/CodeGenObjC/sections.m
@@ -61,15 +61,15 @@
 // CHECK-ELF: !{{[0-9]+}} = !{i32 1, !"Objective-C Image Info Section", !"objc_imageinfo"}
 
 // CHECK-MACHO: @"_OBJC_$_CLASS_METHODS_I" = internal {{.*}}, section "__DATA, __objc_const"
-// CHECK-MACHO: @"OBJC_CLASSLIST_SUP_REFS_$_" = internal {{.*}}, section "__DATA,__objc_superrefs,regular,no_dead_strip"
+// CHECK-MACHO: @"OBJC_CLASSLIST_SUP_REFS_$_" = private {{.*}}, section "__DATA,__objc_superrefs,regular,no_dead_strip"
 // CHECK-MACHO: @OBJC_SELECTOR_REFERENCES_ = internal {{.*}}, section "__DATA,__objc_selrefs,literal_pointers,no_dead_strip"
 // CHECK-MACHO: @"OBJC_CLASSLIST_REFERENCES_$_" = internal {{.*}}, section "__DATA,__objc_classrefs,regular,no_dead_strip"
 // CHECK-MACHO: @_objc_msgSend_fixup_class = {{.*}}, section "__DATA,__objc_msgrefs,coalesced"
 // CHECK-MACHO: @"_OBJC_LABEL_PROTOCOL_$_P" = {{.*}}, section "__DATA,__objc_protolist,coalesced,no_dead_strip"
 // CHECK-MACHO: @"_OBJC_PROTOCOL_REFERENCE_$_P" = {{.*}}, section "__DATA,__objc_protorefs,coalesced,no_dead_strip"
-// CHECK-MACHO: @"OBJC_LABEL_CLASS_$" = internal {{.*}}, section "__DATA,__objc_classlist,regular,no_dead_strip"
-// CHECK-MACHO: @"OBJC_LABEL_NONLAZY_CLASS_$" = internal {{.*}}, section "__DATA,__objc_nlclslist,regular,no_dead_strip"
-// CHECK-MACHO: @"OBJC_LABEL_CATEGORY_$" = internal {{.*}}, section "__DATA,__objc_catlist,regular,no_dead_strip"
-// CHECK-MACHO: @"OBJC_LABEL_NONLAZY_CATEGORY_$" = internal {{.*}}, section "__DATA,__objc_nlcatlist,regular,no_dead_strip"
+// CHECK-MACHO: @"OBJC_LABEL_CLASS_$" = private {{.*}}, section "__DATA,__objc_classlist,regular,no_dead_strip"
+// CHECK-MACHO: @"OBJC_LABEL_NONLAZY_CLASS_$" = private {{.*}}, section "__DATA,__objc_nlclslist,regular,no_dead_strip"
+// CHECK-MACHO: @"OBJC_LABEL_CATEGORY_$" = private {{.*}}, section "__DATA,__objc_catlist,regular,no_dead_strip"
+// CHECK-MACHO: @"OBJC_LABEL_NONLAZY_CATEGORY_$" = private {{.*}}, section "__DATA,__objc_nlcatlist,regular,no_dead_strip"
 // CHECK-MACHO: !{{[0-9]+}} = !{i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"}
 
Index: clang/test/CodeGenObjC/non-lazy-classes.m
===
--- clang/test/CodeGenObjC/non-lazy-classes.m
+++ clang/test/CodeGenObjC/non-lazy-classes.m
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -Wno-objc-root-class -emit-llvm -o - %s | FileCheck %s
 
-// CHECK: @"OBJC_LABEL_NONLAZY_CLASS_$" = internal global [3 x {{.*}}]{{.*}}@"OBJC_CLASS_$_A"{{.*}},{{.*}}@"OBJC_CLASS_$_D"{{.*}},{{.*}}"OBJC_CLASS_$_E"{{.*}} section "__DATA,__objc_nlclslist,regular,no_dead_strip", align 8
-// CHECK: @"OBJC_LABEL_NONLAZY_CATEGORY_$" = internal global [2 x {{.*}}] {{.*}}@"_OBJC_$_CATEGORY_A_$_Cat"{{.*}},{{.*}}@"_OBJC_$_CATEGORY_E_$_MyCat"{{.*}}, section "__DATA,__objc_nlcatlist,regular,no_dead_strip", align 8
+// CHECK: @"OBJC_LABEL_NONLAZY_CLASS_$" = private global [3 x {{.*}}]{{.*}}@"OBJC_CLASS_$_A"{{.*}},{{.*}}@"OBJC_CLASS_$_D"{{.*}},{{.*}}"OBJC_CLASS_$_E"{{.*}} section "__DATA,__objc_nlclslist,regular,no_dead_strip", align 8
+// CHECK: @"OBJC_LABEL_NONLAZY_CATEGORY_$" = private global [2 x {{.*}}] {{.*}}@"_OBJC_$_CATEGORY_A_$_Cat"{{.*}},{{.*}}@"_OBJC_$_CATEGORY_E_$_MyCat"{{.*}}, section "__DATA,__objc_nlcatlist,regular,no_dead_strip", align 8
 
 @interface A @end
 @implementation A
Index: clang/test/CodeGenObjC/metadata_symbols.m
===
--- clang/test/CodeGenObjC/metadata_symbols.m
+++ clang/test/CodeGenObjC/metadata_symbols.m
@@ -14,7 +14,7 @@
 // CHECK-X86_64: @"OBJC_EHTYPE_$_EH1" = weak global {{.*}}, align 8
 // CHECK-X86_64: @"OBJC_EHTYPE_$_EH2" = external global
 // CHECK-X86_64: @"OBJC_EHTYPE_$_EH3" = global {{.*}}, section "__DATA,__objc_const", align 8
-// CHECK-X86_64: @"OBJC_LABEL_CLASS_$" = internal global {{.*}}, section "__DATA,__objc_classlist,regular,no_dead_strip", align 8
+// CHECK-X86_64: @"OBJC_LABEL_CLASS_$" = private global {{.*}}, section "__DATA,__objc_classlist,regular,no_dead_strip", align 8
 // CHECK-X86_64: define internal void @"\01-[A 

[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese updated this revision to Diff 247755.
Bigcheese added a comment.

Cleaned up the test to not reference unused paths.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75395

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Modules/fsystem-module.m


Index: clang/test/Modules/fsystem-module.m
===
--- /dev/null
+++ clang/test/Modules/fsystem-module.m
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t.dir
+// RUN: mkdir %t.dir
+
+// -fsystem-module requires -emit-module
+// RUN: not %clang_cc1 -fsyntax-only -fsystem-module %s 2>&1 | grep 
"-emit-module"
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning.pcm
+
+// RUN: %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module \
+// RUN:   -Wsystem-headers
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1905,6 +1905,11 @@
   Opts.ModulesEmbedAllFiles = Args.hasArg(OPT_fmodules_embed_all_files);
   Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
   Opts.UseTemporary = !Args.hasArg(OPT_fno_temp_file);
+  Opts.IsSystemModule = Args.hasArg(OPT_fsystem_module);
+
+  if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
+Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
+   << "-emit-module";
 
   Opts.CodeCompleteOpts.IncludeMacros
 = Args.hasArg(OPT_code_completion_macros);
@@ -2061,12 +2066,16 @@
 DashX = IK;
 }
 
+bool IsSystem = false;
+
 // The -emit-module action implicitly takes a module map.
 if (Opts.ProgramAction == frontend::GenerateModule &&
-IK.getFormat() == InputKind::Source)
+IK.getFormat() == InputKind::Source) {
   IK = IK.withFormat(InputKind::ModuleMap);
+  IsSystem = Opts.IsSystemModule;
+}
 
-Opts.Inputs.emplace_back(std::move(Inputs[i]), IK);
+Opts.Inputs.emplace_back(std::move(Inputs[i]), IK, IsSystem);
   }
 
   return DashX;
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -297,6 +297,9 @@
   /// Should a temporary file be used during compilation.
   unsigned UseTemporary : 1;
 
+  /// When using -emit-module, treat the modulemap as a system module.
+  unsigned IsSystemModule : 1;
+
   CodeCompleteOptions CodeCompleteOpts;
 
   /// Specifies the output format of the AST.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1445,6 +1445,8 @@
 def fmodule_name : Separate<["-"], "fmodule-name">, Alias;
 def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
   Flags<[CC1Option]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  HelpText<"Build this module as a system module. Only used with 
-emit-module">;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
   Group, Flags<[DriverOption,CC1Option]>, MetaVarName<"">,
   HelpText<"Load this module map file">;


Index: clang/test/Modules/fsystem-module.m
===
--- /dev/null
+++ clang/test/Modules/fsystem-module.m
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t.dir
+// RUN: mkdir %t.dir
+
+// -fsystem-module requires -emit-module
+// RUN: not %clang_cc1 -fsyntax-only -fsystem-module %s 2>&1 | grep "-emit-module"
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning.pcm
+
+// RUN: %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module \
+// RUN:   -Wsystem-headers
Index: clang/lib/Frontend/CompilerInvocation.cpp

[PATCH] D75465: [clang-format] Do not merge target-name and : for C# attributes

2020-03-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:281
   Style.ColumnLimit = 10;
-  verifyFormat(R"([assembly:InternalsVisibleTo(
+  verifyFormat(R"([assembly: InternalsVisibleTo(
 "SomeAssembly, PublicKey=SomePublicKeyThatExceedsTheColumnLimit")])",

krasimir wrote:
> isn't the space after the `:` a regression?
> Looking at
> https://docs.microsoft.com/en-us/dotnet/standard/assembly/set-attributes
> it looks like such attributes are spelled `[assembly:Blah]`
> 
> How is an example where such an attribute is not the last thing in the file?
> 
> I'm not entirely clear on which edit caused this.
The space maybe is coming from
[[ 
https://github.com/llvm/llvm-project/blob/ff9f4b5489cda4d9b31595b54ec0296dc012588d/clang/lib/Format/TokenAnnotator.h#L177
 | TokenAnnotator.spaceRequiredBetween ]], which may need to be adjusted for C#.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75465



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


[PATCH] D73649: [CodeComplete] Member completion for concept-constrained types.

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

> I'm not sure that I'm qualified to approve this patch (this is my first time 
> looking at clang's completion code)

I feel the same way about writing the code :-)
Thanks for the comments! I'll get another review from someone who's stared into 
this abyss before, too.




Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4772
+// FIXME: it some of this machinery could be used for non-concept tparms too,
+// enabling completion for type parameters based on other uses of that param.
+class ConceptInfo {

nridge wrote:
> Very interesting idea :)
> 
> A hypothetical "infer constraints based on usage" code action could share the 
> same infrastructure as well.
Yup. There'd need to be some differences - this code uses Scope which is 
available during parsing but not after, a code action would need to use AST 
walking, which is available after parsing but not during :-)

This is pretty hypothetical/far out/needs prototyping, so I wouldn't try to 
solve any of the layering/API problems now.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4839
+  // that T is attached to in order to gather the relevant constraints.
+  ConceptInfo(const TemplateTypeParmType , Scope *S) {
+auto *TemplatedEntity = getTemplatedEntity(BaseType.getDecl(), S);

nridge wrote:
> Minor observation: based on the current usage of this class, we know at 
> construction time which `AccessOperator` we want. We could potentially pass 
> that in and use it to do less work in the constructor (filtering members 
> earlier). However, it's not clear that this is worth it, we'd only be 
> avoiding a small amount of work.
Yeah, I don't think this is worth the complexity, but added a comment to the 
class.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4856
+private:
+  // Infer members of T, given that the expression E (dependent on T) is true.
+  void believe(const Expr *E, const TemplateTypeParmType *T) {

nridge wrote:
> "given that the expression E is valid"?
E comes from concept constraints, we actually know that E is not only valid but 
its value is exactly `true`.

In particular, knowing that E is *valid* doesn't tell us anything at all about 
T if E is a ConceptSpecializationExpr like `Integral`, as we'd get from a 
`requires Integral` clause or an `Integral auto foo` parameter. (Note that 
`Integral` is a valid expression with the value `false`)



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4860
+  return;
+if (auto *CSE = llvm::dyn_cast(E)) {
+  // If the concept is

njames93 wrote:
> nridge wrote:
> > clang-tidy gives me an `'auto *CSE' can be declared as 'const auto *CSE'` 
> > here, and several similar diagnostics below.
> > 
> > Not sure if that's something we want to obey, or alter our configuration to 
> > silence it.
> That warning will go away next time the bot updates the version of clang tidy 
> it uses. It was decided to reduce the constraints on diagnosing that check 
> inside llvm but that hasn't reached the pre merge bot. 
Indeed, I'm no longer seeing these locally. Thanks!



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4901
+if (!Req->isDependent())
+  continue; // Can't tell us anything about T.
+if (auto *TR = llvm::dyn_cast(Req)) {

nridge wrote:
> Are we sure a dependent requirement can't tell us anything about `T`?
> 
> For example, a constraint with a dependent return type requirement might 
> still give us a useful member name and arguments. Even a call expression with 
> dependent arguments could give us a useful member name.
> 
> Or am I misunderstanding what `Requirement::isDependent()` signifies?
I think you're reading this backwards, a *non-dependent* requirement can't tell 
us anything about T, because it doesn't depend on T!

This isn't terribly important except that it takes care of a few cases at once 
(e.g. all requirements below must have an expr rather than an error, because 
constraints with an error aren't dependent)



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4972
+
+// In T::foo::bar, `foo` must be a type.
+bool VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {

nridge wrote:
> It would be nice if the test exercised this case.
Oops, this was actually broken because VisitNestedNameSpecifier doesn't seem to 
be a thing :-(
Fixed to use TraverseNestedNameSpecifierLoc and added a test.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5004
+return;
+  auto  = Outer->Results[Name.getAsIdentifierInfo()];
+  Result.Name = Name.getAsIdentifierInfo();

nridge wrote:
> What if there is already a result for this name?
Right, it's doing some arbitrary clobber/merge thing :-(

Fixed: now if we get a conflict we pick either the new or the old one, where 
more info is better.



[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield updated this revision to Diff 247753.
JonChesterfield added a comment.

- error on extern variables, minor cleanup


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/DeclBase.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-loader-uninitialized.c
  clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-loader-uninitialized.cpp

Index: clang/test/Sema/attr-loader-uninitialized.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-loader-uninitialized.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int good __attribute__((loader_uninitialized));
+
+const int still_cant_be_const __attribute__((loader_uninitialized));
+// expected-error@-1 {{default initialization of an object of const type}}
+extern int external_rejected __attribute__((loader_uninitialized));
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute cannot have external linkage}}
+
+int noargs __attribute__((loader_uninitialized(0)));
+// expected-error@-1 {{'loader_uninitialized' attribute takes no arguments}} 
+
+void func() __attribute__((loader_uninitialized))
+// expected-warning@-1 {{'loader_uninitialized' attribute only applies to global variables}}
+{
+  int local __attribute__((loader_uninitialized));
+  // expected-warning@-1 {{'loader_uninitialized' attribute only applies to global variables}}
+
+  static int sl __attribute__((loader_uninitialized));
+}
+
+struct s {
+  __attribute__((loader_uninitialized)) int field;
+  // expected-warning@-1 {{'loader_uninitialized' attribute only applies to global variables}}
+
+  static __attribute__((loader_uninitialized)) int sfield;
+
+} __attribute__((loader_uninitialized));
+// expected-warning@-1 {{'loader_uninitialized' attribute only applies to global variables}}
+
+int redef_attr_first __attribute__((loader_uninitialized));
+int redef_attr_first;
+// expected-error@-1 {{redefinition of 'redef_attr_first'}}
+// expected-note@-3 {{previous definition is here}}
+
+int redef_attr_second; 
+int redef_attr_second __attribute__((loader_uninitialized)); 
+// expected-warning@-1 {{attribute declaration must precede definition}}
+// expected-note@-3 {{previous definition is here}}
+// expected-error@-3 {{redefinition of 'redef_attr_second'}}
+// expected-note@-5 {{previous definition is here}}
+
+int init_rejected __attribute__((loader_uninitialized)) = 42;
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute cannot have an initializer}}
+
+struct trivial {};
+
+trivial default_ok __attribute__((loader_uninitialized));
+trivial value_rejected  __attribute__((loader_uninitialized)) {};
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute cannot have an initializer}}
+
+struct nontrivial
+{
+  nontrivial() {}
+};
+
+nontrivial needs_trivial_ctor __attribute__((loader_uninitialized));
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute must have a trivial default constructor}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -65,6 +65,7 @@
 // CHECK-NEXT: InitPriority (SubjectMatchRule_variable)
 // CHECK-NEXT: InternalLinkage (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
 // CHECK-NEXT: LTOVisibilityPublic (SubjectMatchRule_record)
+// CHECK-NEXT: LoaderUninitialized (SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: Lockable (SubjectMatchRule_record)
 // CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block)
 // CHECK-NEXT: MSStruct (SubjectMatchRule_record)
Index: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: @defn = global i32 undef
+int defn  [[clang::loader_uninitialized]];
+
+// CHECK: @_ZL11defn_static = internal global i32 undef
+static int defn_static [[clang::loader_uninitialized]] __attribute__((used));
+
+// CHECK: @_ZZ4funcvE4data = internal global i32 undef
+int* func(void)
+{
+  static int data [[clang::loader_uninitialized]];
+  return 
+}
+
+class trivial
+{
+  float x;
+};
+
+// CHECK: @ut = global %class.trivial undef
+trivial ut 

[PATCH] D73649: [CodeComplete] Member completion for concept-constrained types.

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 247751.
sammccall marked 27 inline comments as done.
sammccall added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73649

Files:
  clang/include/clang/Sema/Scope.h
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/concepts.cpp

Index: clang/test/CodeCompletion/concepts.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/concepts.cpp
@@ -0,0 +1,59 @@
+template  concept convertible_to = true;
+template  concept same_as = true;
+template  concept integral = true;
+
+template 
+concept W = requires(A a, B b) {
+  { b.www } noexcept -> integral;
+};
+
+template  concept X = requires(T t) {
+  t.xxx(42);
+  typename T::xxx_t;
+  T::xyz::member;
+};
+
+template 
+concept Y = requires(T t, U u) { t.yyy(u); };
+
+template 
+concept Z = requires(T t) {
+  { t.zzz() } -> same_as;
+  requires W;
+};
+
+// Concept constraints in all three slots require X, Y, Z, and ad-hoc stuff.
+template 
+requires Y && requires(T *t) { { t->aaa() } -> convertible_to; }
+void foo(T t) requires Z || requires(T ) { t.bbb(); t->bb(); } {
+  t.x;
+  t->x;
+  T::x;
+
+  // RUN: %clang_cc1 -std=c++2a -code-completion-with-fixits -code-completion-at=%s:29:5 %s \
+  // RUN: | FileCheck %s -check-prefix=DOT -implicit-check-not=xxx_t
+  // DOT: Pattern : [#convertible_to#]aaa()
+  // DOT: Pattern : bb() (requires fix-it: {{.*}} to "->")
+  // DOT: Pattern : bbb()
+  // DOT: Pattern : [#integral#]www
+  // DOT: Pattern : xxx(<#int#>)
+  // FIXME: it would be nice to have int instead of U here.
+  // DOT: Pattern : yyy(<#U#>)
+  // DOT: Pattern : [#int#]zzz()
+
+  // RUN: %clang_cc1 -std=c++2a -code-completion-with-fixits -code-completion-at=%s:30:6 %s \
+  // RUN: | FileCheck %s -check-prefix=ARROW -implicit-check-not=xxx_t
+  // ARROW: Pattern : [#convertible_to#]aaa() (requires fix-it: {{.*}} to ".")
+  // ARROW: Pattern : bb()
+  // ARROW: Pattern : bbb() (requires fix-it
+  // ARROW: Pattern : [#integral#]www (requires fix-it
+  // ARROW: Pattern : xxx(<#int#>) (requires fix-it
+  // ARROW: Pattern : yyy(<#U#>) (requires fix-it
+  // ARROW: Pattern : [#int#]zzz() (requires fix-it
+
+  // RUN: %clang_cc1 -std=c++2a -code-completion-with-fixits -code-completion-at=%s:31:6 %s \
+  // RUN: | FileCheck %s -check-prefix=COLONS -implicit-check-not=yyy
+  // COLONS: Pattern : xxx_t
+  // COLONS: Pattern : xyz
+}
+
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -9,6 +9,7 @@
 //  This file defines the code-completion semantic actions.
 //
 //===--===//
+#include "clang/AST/ASTConcept.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
@@ -16,8 +17,11 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
 #include "clang/AST/ExprObjC.h"
+#include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/QualTypeNames.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/Specifiers.h"
@@ -4746,6 +4750,364 @@
   return nullptr;
 }
 
+namespace {
+// Collects completion-relevant information about a concept-constrainted type T.
+// In particular, examines the constraint expressions to find members of T.
+//
+// The design is very simple: we walk down each constraint looking for
+// expressions of the form T.foo().
+// If we're extra lucky, the return type is specified.
+// We don't do any clever handling of && or || in constraint expressions, we
+// take members from both branches.
+//
+// For example, given:
+//   template  concept X = requires (T t, string& s) { t.print(s); };
+//   template  void foo(U u) { u.^ }
+// We want to suggest the inferred member function 'print(string)'.
+// We see that u has type U, so X holds.
+// X requires t.print(s) to be valid, where t has type U (substituted for T).
+// By looking at the CallExpr we find the signature of print().
+//
+// While we tend to know in advance which kind of members (access via . -> ::)
+// we want, it's simpler just to gather them all and post-filter.
+//
+// FIXME: some of this machinery could be used for non-concept type-parms too,
+// enabling completion for type parameters based on other uses of that param.
+//
+// FIXME: there are other cases where a type can be constrained by a concept,
+// e.g. inside `if constexpr(ConceptSpecializationExpr) { ... }`
+class ConceptInfo {
+public:
+  // Describes a likely member of a type, inferred by concept constraints.
+  // Offered as a code completion for 

[PATCH] D75489: [clang-tidy] Generalize HeaderFileExtensions.{h, cpp}. NFC

2020-03-02 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs created this revision.
jroelofs added reviewers: njames93, aaron.ballman.
Herald added subscribers: cfe-commits, xazax.hun, mgorny.
Herald added a project: clang.
jroelofs added a child revision: D74669: [clang-tidy] New check: 
bugprone-suspicious-include.
jroelofs marked an inline comment as done.
jroelofs added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h:14
 #include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallSet.h"

this belongs in the other patch.


Splitting this out from https://reviews.llvm.org/D74669


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75489

Files:
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.cpp
  clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h

Index: clang-tools-extra/clang-tidy/utils/HeaderGuard.h
===
--- clang-tools-extra/clang-tidy/utils/HeaderGuard.h
+++ clang-tools-extra/clang-tidy/utils/HeaderGuard.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H
 
 #include "../ClangTidy.h"
-#include "../utils/HeaderFileExtensionsUtils.h"
+#include "../utils/FileExtensionsUtils.h"
 
 namespace clang {
 namespace tidy {
@@ -29,8 +29,8 @@
   : ClangTidyCheck(Name, Context),
 RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
 "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
-utils::parseHeaderFileExtensions(RawStringHeaderFileExtensions,
- HeaderFileExtensions, ',');
+utils::parseFileExtensions(RawStringHeaderFileExtensions,
+   HeaderFileExtensions, ',');
   }
   void registerPPCallbacks(const SourceManager , Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
@@ -54,7 +54,7 @@
 
 private:
   std::string RawStringHeaderFileExtensions;
-  utils::HeaderFileExtensionsSet HeaderFileExtensions;
+  utils::FileExtensionsSet HeaderFileExtensions;
 };
 
 } // namespace utils
Index: clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
===
--- clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
+++ clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
@@ -273,13 +273,13 @@
 }
 
 bool HeaderGuardCheck::shouldSuggestEndifComment(StringRef FileName) {
-  return utils::isHeaderFileExtension(FileName, HeaderFileExtensions);
+  return utils::isFileExtension(FileName, HeaderFileExtensions);
 }
 
 bool HeaderGuardCheck::shouldFixHeaderGuard(StringRef FileName) { return true; }
 
 bool HeaderGuardCheck::shouldSuggestToAddHeaderGuard(StringRef FileName) {
-  return utils::isHeaderFileExtension(FileName, HeaderFileExtensions);
+  return utils::isFileExtension(FileName, HeaderFileExtensions);
 }
 
 std::string HeaderGuardCheck::formatEndIf(StringRef HeaderGuard) {
Index: clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-//===--- HeaderFileExtensionsUtils.cpp - clang-tidy--*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "HeaderFileExtensionsUtils.h"
-#include "clang/Basic/CharInfo.h"
-#include "llvm/Support/Path.h"
-
-namespace clang {
-namespace tidy {
-namespace utils {
-
-bool isExpansionLocInHeaderFile(
-SourceLocation Loc, const SourceManager ,
-const HeaderFileExtensionsSet ) {
-  SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
-  return isHeaderFileExtension(SM.getFilename(ExpansionLoc),
-   HeaderFileExtensions);
-}
-
-bool isPresumedLocInHeaderFile(
-SourceLocation Loc, SourceManager ,
-const 

[PATCH] D75489: [clang-tidy] Generalize HeaderFileExtensions.{h, cpp}. NFC

2020-03-02 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs marked an inline comment as done.
jroelofs added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h:14
 #include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallSet.h"

this belongs in the other patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75489



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


[PATCH] D66831: [ObjC] Fix type checking for qualified id block parameters.

2020-03-02 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Sorry for the late feedback here – we're in the process of testing with Clang 
10 and noticed a behavior change caused by this commit.

Consider the following piece of code:

  @protocol P
  @end
  
  @protocol Q
  @end
  
  @interface I 
  @end
  
  @interface J : I 
  @end
  
  void f(void (^)(id));
  void g() {
f(^(J *j){});
  }

Clang 9 would accept it, whereas Clang 10 complains about incompatible block 
pointer types. If I change the declaration of `J` to instead be:

  @interface J : I

Both Clang 9 and Clang 10 accept it.

I'm not very familiar with Objective-C semantics. Does saying `@interface J : I 
` mean we're overriding the conformance being specified by `@interface I 
`? In that case, the Clang 10 error makes sense to me.

In practice though, classes like `UIImage` are declared as inheriting from 
`NSObject`, so passing a `UIImage *` to a block with a 
parameter of type `id` gives an error with Clang 10.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66831



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


[PATCH] D75215: [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.

2020-03-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

BTW, I am curious to know if this helps V8 PDB size. IIRC you said there were 
some PDBs in Chrome that have this problem a lot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75215



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


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D75395#1901859 , @Bigcheese wrote:

> In D75395#1901778 , @dexonsmith 
> wrote:
>
> > > This is used when
> > >  converting an implicit build to an explicit build to match the
> > >  systemness the implicit build would have had for a given module.
> >
> > I had another thought.  What if for the explicitly built "system" modules:
> >
> > - If `-Wsystem-headers` is on, leave them as user modules in the explicit 
> > build.
> > - If `-Wsystem-headers` is off, turn off all diagnostics in the explicit 
> > build.
> >
> >   Does that give the right semantics, or is there something subtly 
> > different?
>
>
> I considered this, but decided against it because I wanted the implicit and 
> explicit builds to be as similar as possible, and reduce the amount of 
> changes made to the original command line. There's a lot of code in Clang 
> dealing with system files, and I'm not 100% sure that -Wno-everything would 
> be equivalent.


Okay, SGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75395



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


[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield updated this revision to Diff 247745.
JonChesterfield marked 2 inline comments as done.
JonChesterfield added a comment.

- Reduce scope to trivial default constructed types


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/DeclBase.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-loader-uninitialized.c
  clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-loader-uninitialized.cpp

Index: clang/test/Sema/attr-loader-uninitialized.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-loader-uninitialized.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int good __attribute__((loader_uninitialized));
+
+const int still_cant_be_const __attribute__((loader_uninitialized)); // expected-error {{default initialization of an object of const type}}
+extern int external_should_be_rejected __attribute__((loader_uninitialized));
+
+int noargs __attribute__((loader_uninitialized(0))); // expected-error {{'loader_uninitialized' attribute takes no arguments}} 
+
+void func() __attribute__((loader_uninitialized)) // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
+{
+  int local __attribute__((loader_uninitialized)); // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
+
+  static int sl __attribute__((loader_uninitialized));
+}
+
+struct s {
+  __attribute__((loader_uninitialized)) int field; // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
+
+  static __attribute__((loader_uninitialized)) int sfield;
+
+} __attribute__((loader_uninitialized)); // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
+
+int redef_attr_first __attribute__((loader_uninitialized));
+int redef_attr_first;
+// expected-error@-1 {{redefinition of 'redef_attr_first'}}
+// expected-note@-3 {{previous definition is here}}
+
+int redef_attr_second; 
+int redef_attr_second __attribute__((loader_uninitialized)); 
+// expected-warning@-1 {{attribute declaration must precede definition}}
+// expected-note@-3 {{previous definition is here}}
+// expected-error@-3 {{redefinition of 'redef_attr_second'}}
+// expected-note@-5 {{previous definition is here}}
+
+int init_rejected __attribute__((loader_uninitialized)) = 42;
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute cannot have an initializer}}
+
+struct trivial {};
+
+trivial default_ok __attribute__((loader_uninitialized));
+trivial value_rejected  __attribute__((loader_uninitialized)) {};
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute cannot have an initializer}}
+
+struct nontrivial
+{
+  nontrivial() {}
+};
+
+nontrivial needs_trivial_ctor __attribute__((loader_uninitialized));
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute must have a trivial default constructor}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -65,6 +65,7 @@
 // CHECK-NEXT: InitPriority (SubjectMatchRule_variable)
 // CHECK-NEXT: InternalLinkage (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
 // CHECK-NEXT: LTOVisibilityPublic (SubjectMatchRule_record)
+// CHECK-NEXT: LoaderUninitialized (SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: Lockable (SubjectMatchRule_record)
 // CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block)
 // CHECK-NEXT: MSStruct (SubjectMatchRule_record)
Index: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++11 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: @_ZZ4funcvE4data = internal global i32 undef
+int* func(void)
+{
+  static int data [[clang::loader_uninitialized]];
+  return 
+}
+
+// No code emitted
+extern int extern_unhelpful_but_harmless [[clang::loader_uninitialized]];
+
+// CHECK: @defn = global i32 undef
+int defn  [[clang::loader_uninitialized]];
+
+// CHECK: @_ZL11defn_static = internal global i32 undef
+static int defn_static [[clang::loader_uninitialized]] __attribute__((used));
+
+class trivial
+{
+  float x;
+};

[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

I've continued thinking about / experimenting with this. Curiously - `X x;` and 
`X x{};` are considered distinct by clang. The current patch will only accept 
the former. I'll add some tests for that.

I think there's a reasonable chance that the developers who want to elide the 
runtime cost of zero initialising will usually also want to avoid dynamic 
initialisation. That suggests we could accept only trivially default 
constructible classes, where the undef initializer is correct in that one 
cannot determine whether a no-op constructor actually ran or not. If we go with 
that, then the more complicated question of exactly how this should interact 
with user-controlled disabling of dynamic initialization can be postponed until 
that feature is introduced. This patch is then reasonably self contained.

This patch is strongly related to the linker script approach, or equivalent 
asm. It's target-dependent how the uninitialised data gets represented, e.g. 
x64 will put it in bss anyway. Opencl's __local is similarly uninitialised, and 
gets annotated with an address space that maps onto magic in llc and/or the 
loader.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361



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


[PATCH] D75486: [SVE] Make CompositeType not inherit from Type

2020-03-02 Thread Christopher Tetreault via Phabricator via cfe-commits
ctetreau created this revision.
Herald added subscribers: llvm-commits, cfe-commits, kerbowa, psnobl, rkruppe, 
hiraditya, tschuett, nhaehnle, jvesely, arsenm.
Herald added a reviewer: efriedma.
Herald added projects: clang, LLVM.

This patch is a work in progress

Make CompositeType not inherit from Type. Instead, Vecotr, Array, and
Struct Types directly inherit from Type. This is in preparation for the
introduction of distinct Fixed and Scalable Vector Types


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75486

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/unittests/CodeGen/CodeGenExternalTest.cpp
  llvm/include/llvm/IR/Constants.h
  llvm/include/llvm/IR/DerivedTypes.h
  llvm/include/llvm/IR/GetElementPtrTypeIterator.h
  llvm/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/CodeGen/Analysis.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/FuzzMutate/Operations.cpp
  llvm/lib/IR/ConstantFold.cpp
  llvm/lib/IR/Constants.cpp
  llvm/lib/IR/Core.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Linker/IRMover.cpp
  llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp
  llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
  llvm/lib/Transforms/IPO/GlobalOpt.cpp
  llvm/lib/Transforms/IPO/StripSymbols.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/lib/Transforms/Utils/FunctionComparator.cpp
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3130,7 +3130,7 @@
   unsigned N = 1;
   Type *EltTy = T;
 
-  while (isa(EltTy)) {
+  while (CompositeType::is(EltTy)) {
 if (auto *ST = dyn_cast(EltTy)) {
   // Check that struct is homogeneous.
   for (const auto *Ty : ST->elements())
@@ -3139,7 +3139,7 @@
   N *= ST->getNumElements();
   EltTy = *ST->element_begin();
 } else {
-  auto *SeqT = cast(EltTy);
+  auto *SeqT = cast(CompositeType::get(EltTy));
   N *= SeqT->getNumElements();
   EltTy = SeqT->getElementType();
 }
Index: llvm/lib/Transforms/Utils/FunctionComparator.cpp
===
--- llvm/lib/Transforms/Utils/FunctionComparator.cpp
+++ llvm/lib/Transforms/Utils/FunctionComparator.cpp
@@ -478,8 +478,8 @@
 
   case Type::ArrayTyID:
   case Type::VectorTyID: {
-auto *STyL = cast(TyL);
-auto *STyR = cast(TyR);
+auto *STyL = cast(CompositeType::get(TyL));
+auto *STyR = cast(CompositeType::get(TyR));
 if (STyL->getNumElements() != STyR->getNumElements())
   return cmpNumbers(STyL->getNumElements(), STyR->getNumElements());
 return cmpTypes(STyL->getElementType(), STyR->getElementType());
Index: llvm/lib/Transforms/Scalar/SROA.cpp
===
--- llvm/lib/Transforms/Scalar/SROA.cpp
+++ llvm/lib/Transforms/Scalar/SROA.cpp
@@ -3511,7 +3511,8 @@
   (DL.getTypeAllocSize(Ty) - Offset) < Size)
 return nullptr;
 
-  if (SequentialType *SeqTy = dyn_cast(Ty)) {
+  if (SequentialType *SeqTy = dyn_cast_or_null(
+  CompositeType::get(Ty, CompositeType::is(Ty {
 Type *ElementTy = SeqTy->getElementType();
 uint64_t ElementSize = DL.getTypeAllocSize(ElementTy);
 uint64_t NumSkippedElements = Offset / ElementSize;
Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1934,7 +1934,8 @@
 if (J > 0) {
   if (J == 1) {
 CurTy = Op1->getSourceElementType();
-  } else if (auto *CT = dyn_cast(CurTy)) {
+  } else if (auto *CT =
+ CompositeType::get(CurTy, CompositeType::is(CurTy))) {
 CurTy = CT->getTypeAtIndex(Op1->getOperand(J));
   } else {
 CurTy = nullptr;
Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2428,9 +2428,9 @@
 // This can enhance SROA and other transforms that want type-safe pointers.
 unsigned NumZeros = 0;
 while (SrcElTy != DstElTy &&
-   isa(SrcElTy) && !SrcElTy->isPointerTy() &&
+   CompositeType::is(SrcElTy) && !SrcElTy->isPointerTy() &&

[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp:23
+// CHECK: @nominally_value_init = global i32 undef
+int nominally_value_init  [[clang::loader_uninitialized]] = 4;
+

rjmccall wrote:
> JonChesterfield wrote:
> > rjmccall wrote:
> > > Quuxplusone wrote:
> > > > rjmccall wrote:
> > > > > JonChesterfield wrote:
> > > > > > Quuxplusone wrote:
> > > > > > > This test case is identical to line 36 of 
> > > > > > > clang/test/Sema/attr-loader-uninitialized.cpp, where you say you 
> > > > > > > don't want it to compile at all.
> > > > > > > 
> > > > > > > I think you need a clearer idea of how this interacts with 
> > > > > > > initializers. Is it merely supposed to eliminate the 
> > > > > > > //zero-initialization// that happens before the user-specified 
> > > > > > > construction/initialization, or is it supposed to compete with 
> > > > > > > the user-specified construction/initialization?
> > > > > > > 
> > > > > > > That is, for
> > > > > > > 
> > > > > > > nontrivial unt [[clang::loader_uninitialized]];
> > > > > > > 
> > > > > > > is it merely supposed to call `unt::unt()` on a chunk of undef 
> > > > > > > memory (instead of the usual chunk of zeroed memory), or is it 
> > > > > > > supposed to skip the constructor entirely? And for
> > > > > > > 
> > > > > > > int x [[clang::loader_uninitialized]] = foo();
> > > > > > > 
> > > > > > > is it merely supposed to call `foo()` and assign the result to a 
> > > > > > > chunk of undef memory (instead of the usual chunk of zeroed 
> > > > > > > memory), or is it supposed to skip the initialization entirely?
> > > > > > I think you commented while the first working piece of sema landed. 
> > > > > > My thinking is relatively clear but my understanding of clang's 
> > > > > > semantic analysis is a work in progress!
> > > > > > 
> > > > > > Initializers (`= foo()`) are straightforward. Error on the basis 
> > > > > > that the attribute effectively means `= undef`, and one should not 
> > > > > > have two initializers. A test case is now added for that (and now 
> > > > > > passes).
> > > > > > 
> > > > > > The codegen I want for a default constructed global marked with 
> > > > > > this variable is:
> > > > > > - global variable allocated, with undef as the original value
> > > > > > - default constructor call synthesized
> > > > > > - said default constructor set up for invocation from crt, before 
> > > > > > main, writing over the undef value
> > > > > > 
> > > > > > Where the default constructor can be optimized as usual, e.g. if it 
> > > > > > always writes a constant, we can init with that constant instead of 
> > > > > > the undef and elide the constructor.
> > > > > > 
> > > > > > I don't have that actually working yet - the constructor call is 
> > > > > > not being emitted, so we just have the undef global.
> > > > > > 
> > > > > > I think it's important to distinguish between the values of the 
> > > > > > bits when the program is loaded and whether constructor/destructors 
> > > > > > are called, as one could want any combination of the two.
> > > > > I think Arthur is suggesting that it would be useful to allow the 
> > > > > attribute to be used in conjunction with an initializer in C++, since 
> > > > > if the initializer has to be run dynamically, we can still 
> > > > > meaningfully suppress the static zero-initialization.   That is, 
> > > > > we've accepted that it's useful to do this when 
> > > > > *default-initializing* a global, but it's actually useful when doing 
> > > > > *any* kind of dynamic initialization.
> > > > > 
> > > > > Maybe we can leave it as an error in C++ when the initializer is a 
> > > > > constant expression.  Although that might be unnecessarily brittle if 
> > > > > e.g. the constructor is `constexpr` in one library version but not 
> > > > > another.
> > > > No, that's exctly what I mean. You seem to be holding two contradictory 
> > > > ideas simultaneously:
> > > > 
> > > > [[loader_uninitialized]] X x = X{};  // two initializers, therefore 
> > > > error
> > > > 
> > > > [[loader_uninitialized]] X x {}; // one initializer plus one 
> > > > constructor, therefore fine
> > > > 
> > > > In C++, these two declarations have identical semantics. It doesn't 
> > > > make sense to say that one of them "calls a constructor" and the other 
> > > > one "has an initializer." They're literally the same thing.
> > > > 
> > > > Similarly in both C99 and C++ with plain old ints:
> > > > 
> > > > [[loader_uninitialized]] int x = foo();
> > > > 
> > > > This means "call foo and dynamically initialize x with the result," 
> > > > just as surely as
> > > > 
> > > > [[loader_uninitialized]] X x = X();
> > > > 
> > > > means "call X::X and dynamically initialize x with the result." Having 
> > > > one rule for dynamic initializers of primitive types and a separate 
> > > > rule for dynamic initializers of class types 

[PATCH] D75483: [Sema] Fix a crash when attaching comments to an implicit decl

2020-03-02 Thread Jan Korous via Phabricator via cfe-commits
jkorous accepted this revision.
jkorous added a comment.
This revision is now accepted and ready to land.

Thanks a bunch for fixing this!

That also means we can skip all the implicit declarations from the `for (const 
Decl *D : Decls) {` just a couple lines below your fix since implicit 
declaration can hardly have a doc comment attached... I'll send a patch.


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

https://reviews.llvm.org/D75483



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


[PATCH] D73852: [clang] detect switch fallthrough marked by a comment (PR43465)

2020-03-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D73852#1901836 , @aaron.ballman 
wrote:

> FYI: it was reverted by Luboš in c61401b89742f230b7e6a2cc0548fbf7442e906d 
> 


Thank you, Luboš, and sorry for the process problems here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73852



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


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese added a comment.

In D75395#1901778 , @dexonsmith wrote:

> > This is used when
> >  converting an implicit build to an explicit build to match the
> >  systemness the implicit build would have had for a given module.
>
> I had another thought.  What if for the explicitly built "system" modules:
>
> - If `-Wsystem-headers` is on, leave them as user modules in the explicit 
> build.
> - If `-Wsystem-headers` is off, turn off all diagnostics in the explicit 
> build.
>
>   Does that give the right semantics, or is there something subtly different?


I considered this, but decided against it because I wanted the implicit and 
explicit builds to be as similar as possible, and reduce the amount of changes 
made to the original command line. There's a lot of code in Clang dealing with 
system files, and I'm not 100% sure that -Wno-everything would be equivalent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75395



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


[PATCH] D75483: [Sema] Fix a crash when attaching comments to an implicit decl

2020-03-02 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.
erik.pilkington added a reviewer: jkorous.
Herald added subscribers: ributzka, dexonsmith.

When an implicitly generated decl was the first entry in the group, we 
attempted to lookup comments with an empty FileID, leading to crashes. Avoid 
this by trying to use the other declarations in a group, then bailing out if 
none are valid.

rdar://59919733


https://reviews.llvm.org/D75483

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/Sema/warn-documentation.m


Index: clang/test/Sema/warn-documentation.m
===
--- clang/test/Sema/warn-documentation.m
+++ clang/test/Sema/warn-documentation.m
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation 
-Wdocumentation-pedantic -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -fsyntax-only -fblocks -Wno-objc-root-class 
-Wdocumentation -Wdocumentation-pedantic -verify %s
 
 @class NSString;
 
@@ -318,3 +319,10 @@
 // expected-warning@-1 {{'\return' command used in a comment that is not 
attached to a function or method declaration}}
 VoidBlockTypeCall ^e; ///< \return none
 // expected-warning@-1 {{'\return' command used in a comment that is not 
attached to a function or method declaration}}
+
+#ifdef __cplusplus
+@interface HasAnonNamespace @end
+@implementation HasAnonNamespace
+namespace {}
+@end
+#endif
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -474,10 +474,20 @@
   if (Comments.empty() || Decls.empty())
 return;
 
-  // See if there are any new comments that are not attached to a decl.
-  // The location doesn't have to be precise - we care only about the file.
-  const FileID File =
-  SourceMgr.getDecomposedLoc((*Decls.begin())->getLocation()).first;
+  FileID File;
+  for (Decl *D : Decls) {
+SourceLocation Loc = D->getLocation();
+if (Loc.isValid()) {
+  // See if there are any new comments that are not attached to a decl.
+  // The location doesn't have to be precise - we care only about the file.
+  File = SourceMgr.getDecomposedLoc(Loc).first;
+  break;
+}
+  }
+
+  if (File.isInvalid())
+return;
+
   auto CommentsInThisFile = Comments.getCommentsInFile(File);
   if (!CommentsInThisFile || CommentsInThisFile->empty() ||
   CommentsInThisFile->rbegin()->second->isAttached())


Index: clang/test/Sema/warn-documentation.m
===
--- clang/test/Sema/warn-documentation.m
+++ clang/test/Sema/warn-documentation.m
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation -Wdocumentation-pedantic -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation -Wdocumentation-pedantic -verify %s
 
 @class NSString;
 
@@ -318,3 +319,10 @@
 // expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
 VoidBlockTypeCall ^e; ///< \return none
 // expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}}
+
+#ifdef __cplusplus
+@interface HasAnonNamespace @end
+@implementation HasAnonNamespace
+namespace {}
+@end
+#endif
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -474,10 +474,20 @@
   if (Comments.empty() || Decls.empty())
 return;
 
-  // See if there are any new comments that are not attached to a decl.
-  // The location doesn't have to be precise - we care only about the file.
-  const FileID File =
-  SourceMgr.getDecomposedLoc((*Decls.begin())->getLocation()).first;
+  FileID File;
+  for (Decl *D : Decls) {
+SourceLocation Loc = D->getLocation();
+if (Loc.isValid()) {
+  // See if there are any new comments that are not attached to a decl.
+  // The location doesn't have to be precise - we care only about the file.
+  File = SourceMgr.getDecomposedLoc(Loc).first;
+  break;
+}
+  }
+
+  if (File.isInvalid())
+return;
+
   auto CommentsInThisFile = Comments.getCommentsInFile(File);
   if (!CommentsInThisFile || CommentsInThisFile->empty() ||
   CommentsInThisFile->rbegin()->second->isAttached())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73852: [clang] detect switch fallthrough marked by a comment (PR43465)

2020-03-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D73852#1901793 , @rsmith wrote:

> In any case, none of this has any bearing on whether this patch has had 
> sufficient review. It hasn't, so it needs to be reverted for now.


FYI: it was reverted by Luboš in c61401b89742f230b7e6a2cc0548fbf7442e906d 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73852



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


[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp:23
+// CHECK: @nominally_value_init = global i32 undef
+int nominally_value_init  [[clang::loader_uninitialized]] = 4;
+

JonChesterfield wrote:
> rjmccall wrote:
> > Quuxplusone wrote:
> > > rjmccall wrote:
> > > > JonChesterfield wrote:
> > > > > Quuxplusone wrote:
> > > > > > This test case is identical to line 36 of 
> > > > > > clang/test/Sema/attr-loader-uninitialized.cpp, where you say you 
> > > > > > don't want it to compile at all.
> > > > > > 
> > > > > > I think you need a clearer idea of how this interacts with 
> > > > > > initializers. Is it merely supposed to eliminate the 
> > > > > > //zero-initialization// that happens before the user-specified 
> > > > > > construction/initialization, or is it supposed to compete with the 
> > > > > > user-specified construction/initialization?
> > > > > > 
> > > > > > That is, for
> > > > > > 
> > > > > > nontrivial unt [[clang::loader_uninitialized]];
> > > > > > 
> > > > > > is it merely supposed to call `unt::unt()` on a chunk of undef 
> > > > > > memory (instead of the usual chunk of zeroed memory), or is it 
> > > > > > supposed to skip the constructor entirely? And for
> > > > > > 
> > > > > > int x [[clang::loader_uninitialized]] = foo();
> > > > > > 
> > > > > > is it merely supposed to call `foo()` and assign the result to a 
> > > > > > chunk of undef memory (instead of the usual chunk of zeroed 
> > > > > > memory), or is it supposed to skip the initialization entirely?
> > > > > I think you commented while the first working piece of sema landed. 
> > > > > My thinking is relatively clear but my understanding of clang's 
> > > > > semantic analysis is a work in progress!
> > > > > 
> > > > > Initializers (`= foo()`) are straightforward. Error on the basis that 
> > > > > the attribute effectively means `= undef`, and one should not have 
> > > > > two initializers. A test case is now added for that (and now passes).
> > > > > 
> > > > > The codegen I want for a default constructed global marked with this 
> > > > > variable is:
> > > > > - global variable allocated, with undef as the original value
> > > > > - default constructor call synthesized
> > > > > - said default constructor set up for invocation from crt, before 
> > > > > main, writing over the undef value
> > > > > 
> > > > > Where the default constructor can be optimized as usual, e.g. if it 
> > > > > always writes a constant, we can init with that constant instead of 
> > > > > the undef and elide the constructor.
> > > > > 
> > > > > I don't have that actually working yet - the constructor call is not 
> > > > > being emitted, so we just have the undef global.
> > > > > 
> > > > > I think it's important to distinguish between the values of the bits 
> > > > > when the program is loaded and whether constructor/destructors are 
> > > > > called, as one could want any combination of the two.
> > > > I think Arthur is suggesting that it would be useful to allow the 
> > > > attribute to be used in conjunction with an initializer in C++, since 
> > > > if the initializer has to be run dynamically, we can still meaningfully 
> > > > suppress the static zero-initialization.   That is, we've accepted that 
> > > > it's useful to do this when *default-initializing* a global, but it's 
> > > > actually useful when doing *any* kind of dynamic initialization.
> > > > 
> > > > Maybe we can leave it as an error in C++ when the initializer is a 
> > > > constant expression.  Although that might be unnecessarily brittle if 
> > > > e.g. the constructor is `constexpr` in one library version but not 
> > > > another.
> > > No, that's exctly what I mean. You seem to be holding two contradictory 
> > > ideas simultaneously:
> > > 
> > > [[loader_uninitialized]] X x = X{};  // two initializers, therefore 
> > > error
> > > 
> > > [[loader_uninitialized]] X x {}; // one initializer plus one 
> > > constructor, therefore fine
> > > 
> > > In C++, these two declarations have identical semantics. It doesn't make 
> > > sense to say that one of them "calls a constructor" and the other one 
> > > "has an initializer." They're literally the same thing.
> > > 
> > > Similarly in both C99 and C++ with plain old ints:
> > > 
> > > [[loader_uninitialized]] int x = foo();
> > > 
> > > This means "call foo and dynamically initialize x with the result," just 
> > > as surely as
> > > 
> > > [[loader_uninitialized]] X x = X();
> > > 
> > > means "call X::X and dynamically initialize x with the result." Having 
> > > one rule for dynamic initializers of primitive types and a separate rule 
> > > for dynamic initializers of class types doesn't work.
> > > 
> > > Furthermore, "dynamic initialization" can be promoted to compile-time:
> > > 
> > > [[loader_uninitialized]] int x = 42;
> > > [[loader_uninitialized]] std::string_view x = "hello world";
> > > 

[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp:23
+// CHECK: @nominally_value_init = global i32 undef
+int nominally_value_init  [[clang::loader_uninitialized]] = 4;
+

Quuxplusone wrote:
> rjmccall wrote:
> > JonChesterfield wrote:
> > > Quuxplusone wrote:
> > > > This test case is identical to line 36 of 
> > > > clang/test/Sema/attr-loader-uninitialized.cpp, where you say you don't 
> > > > want it to compile at all.
> > > > 
> > > > I think you need a clearer idea of how this interacts with 
> > > > initializers. Is it merely supposed to eliminate the 
> > > > //zero-initialization// that happens before the user-specified 
> > > > construction/initialization, or is it supposed to compete with the 
> > > > user-specified construction/initialization?
> > > > 
> > > > That is, for
> > > > 
> > > > nontrivial unt [[clang::loader_uninitialized]];
> > > > 
> > > > is it merely supposed to call `unt::unt()` on a chunk of undef memory 
> > > > (instead of the usual chunk of zeroed memory), or is it supposed to 
> > > > skip the constructor entirely? And for
> > > > 
> > > > int x [[clang::loader_uninitialized]] = foo();
> > > > 
> > > > is it merely supposed to call `foo()` and assign the result to a chunk 
> > > > of undef memory (instead of the usual chunk of zeroed memory), or is it 
> > > > supposed to skip the initialization entirely?
> > > I think you commented while the first working piece of sema landed. My 
> > > thinking is relatively clear but my understanding of clang's semantic 
> > > analysis is a work in progress!
> > > 
> > > Initializers (`= foo()`) are straightforward. Error on the basis that the 
> > > attribute effectively means `= undef`, and one should not have two 
> > > initializers. A test case is now added for that (and now passes).
> > > 
> > > The codegen I want for a default constructed global marked with this 
> > > variable is:
> > > - global variable allocated, with undef as the original value
> > > - default constructor call synthesized
> > > - said default constructor set up for invocation from crt, before main, 
> > > writing over the undef value
> > > 
> > > Where the default constructor can be optimized as usual, e.g. if it 
> > > always writes a constant, we can init with that constant instead of the 
> > > undef and elide the constructor.
> > > 
> > > I don't have that actually working yet - the constructor call is not 
> > > being emitted, so we just have the undef global.
> > > 
> > > I think it's important to distinguish between the values of the bits when 
> > > the program is loaded and whether constructor/destructors are called, as 
> > > one could want any combination of the two.
> > I think Arthur is suggesting that it would be useful to allow the attribute 
> > to be used in conjunction with an initializer in C++, since if the 
> > initializer has to be run dynamically, we can still meaningfully suppress 
> > the static zero-initialization.   That is, we've accepted that it's useful 
> > to do this when *default-initializing* a global, but it's actually useful 
> > when doing *any* kind of dynamic initialization.
> > 
> > Maybe we can leave it as an error in C++ when the initializer is a constant 
> > expression.  Although that might be unnecessarily brittle if e.g. the 
> > constructor is `constexpr` in one library version but not another.
> No, that's exctly what I mean. You seem to be holding two contradictory ideas 
> simultaneously:
> 
> [[loader_uninitialized]] X x = X{};  // two initializers, therefore error
> 
> [[loader_uninitialized]] X x {}; // one initializer plus one constructor, 
> therefore fine
> 
> In C++, these two declarations have identical semantics. It doesn't make 
> sense to say that one of them "calls a constructor" and the other one "has an 
> initializer." They're literally the same thing.
> 
> Similarly in both C99 and C++ with plain old ints:
> 
> [[loader_uninitialized]] int x = foo();
> 
> This means "call foo and dynamically initialize x with the result," just as 
> surely as
> 
> [[loader_uninitialized]] X x = X();
> 
> means "call X::X and dynamically initialize x with the result." Having one 
> rule for dynamic initializers of primitive types and a separate rule for 
> dynamic initializers of class types doesn't work.
> 
> Furthermore, "dynamic initialization" can be promoted to compile-time:
> 
> [[loader_uninitialized]] int x = 42;
> [[loader_uninitialized]] std::string_view x = "hello world";
> 
> It wouldn't make semantic sense to say that one of these has "two 
> initializers" and the other has "one initializer," because both of the 
> initializations end up happening at compile time and getting put into .data.
> Similarly in both C99 and C++ with plain old ints:

C does not allow non-constant initialization of global variables.

Let  me try to explain what we're thinking here.  If the variable provides both 

[PATCH] D73852: [clang] detect switch fallthrough marked by a comment (PR43465)

2020-03-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D73852#1901699 , @llunak wrote:

> In D73852#1901186 , @rsmith wrote:
>
> > We shouldn't enable the warning under -Wextra in language modes where 
> > there's no standard way to suppress it.
>
>
> That may be true, but that is not what the bugreport is about, it explicitly 
> mentions flex. There are codebases that explicitly use 
> -Wimplicit-fallthrough, and flex generates the same code even for C++. So 
> either Clang needs to handle it, or flex needs to change (which may be 
> non-trivial if https://bugs.llvm.org/show_bug.cgi?id=43465#c24 is right), or 
> codebases using flex will need to either special-case Clang or live with the 
> warning.


... or turn off the warning for generated code. As noted on that bug, 
`-Wimplicit-fallthrough` enforces a particular coding style, so users should 
expect to need to not enable it in generated code that doesn't follow that 
style. You might need to turn off (eg) `-Windent` or `-Wparentheses` in 
flex-generated code too.

In any case, none of this has any bearing on whether this patch has had 
sufficient review. It hasn't, so it needs to be reverted for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73852



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


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese marked 2 inline comments as done.
Bigcheese added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1912
+Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
+   << "-emit-module";
 

bruno wrote:
> What happens when we use this with implicit modules? It will just be ignored? 
> If so, users might think that using `-fsystem-module` might help them get rid 
> of some warnings/errors, when in fact it won't.
It's an error unless you also pass -emit-module. If you also have implicit 
modules enabled while explicitly building a module then those modules will be 
treated as normal, but I don't think there's a huge cause for confusion there. 
The only way to use it is when explicitly building a module, so it's clear 
which module it applies to.



Comment at: clang/test/Modules/fsystem-module.m:1
+// RUN: rm -rf %t
+// RUN: rm -rf %t-saved

bruno wrote:
> Is this really needed given you are only using `%t-saved` below?
It's not, that's a leftover from the test I based this one on. I'll clean it up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75395



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-03-02 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Reverted in 80bf137fa132ea33204e98bbefa924afe9258a4e 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73242



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


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1448
   Flags<[CC1Option]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  HelpText<"Build this module as a system module. Only used with 
-emit-module">;

bruno wrote:
> I wonder if `-isystem-module` wouldn't be better since it's kinda similar 
> with `-isystem` for headers, but for modules.
FWIW, I prefer `-fsystem-module`.  I would expect `-i*` to be modifying search 
paths, and this option does not do that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75395



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


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

> This is used when
>  converting an implicit build to an explicit build to match the
>  systemness the implicit build would have had for a given module.

I had another thought.  What if for the explicitly built "system" modules:

- If `-Wsystem-headers` is on, leave them as user modules in the explicit build.
- If `-Wsystem-headers` is off, turn off all diagnostics in the explicit build.

Does that give the right semantics, or is there something subtly different?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75395



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


[clang] eb812ef - Explicitly include when using assert

2020-03-02 Thread Joerg Sonnenberger via cfe-commits

Author: Joerg Sonnenberger
Date: 2020-03-02T22:45:28+01:00
New Revision: eb812efa12fb82ca338794fa18b610ca9581aef5

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

LOG: Explicitly include  when using assert

Depending on the OS used, a module-enabled build can fail due to the
special handling  gets as textual header.

Added: 


Modified: 
clang/lib/AST/CommentCommandTraits.cpp
llvm/lib/Support/APSInt.cpp
llvm/lib/Support/FormatVariadic.cpp
llvm/lib/Support/IntEqClasses.cpp
llvm/lib/Support/IntervalMap.cpp
llvm/lib/Support/KnownBits.cpp
llvm/lib/Support/PrettyStackTrace.cpp
llvm/lib/Support/Regex.cpp
llvm/lib/Support/StringPool.cpp
llvm/lib/Support/Triple.cpp
llvm/lib/Support/VersionTuple.cpp
llvm/lib/TableGen/TableGenBackend.cpp
llvm/lib/Target/AArch64/AArch64StackOffset.h
llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
llvm/utils/TableGen/CodeGenHwModes.h
llvm/utils/TableGen/CodeGenInstruction.h

Removed: 




diff  --git a/clang/lib/AST/CommentCommandTraits.cpp 
b/clang/lib/AST/CommentCommandTraits.cpp
index b306fcbb154f..bdc0dd47fb7d 100644
--- a/clang/lib/AST/CommentCommandTraits.cpp
+++ b/clang/lib/AST/CommentCommandTraits.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/AST/CommentCommandTraits.h"
 #include "llvm/ADT/STLExtras.h"
+#include 
 
 namespace clang {
 namespace comments {

diff  --git a/llvm/lib/Support/APSInt.cpp b/llvm/lib/Support/APSInt.cpp
index 7c48880f96ea..6805e06df333 100644
--- a/llvm/lib/Support/APSInt.cpp
+++ b/llvm/lib/Support/APSInt.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/StringRef.h"
+#include 
 
 using namespace llvm;
 

diff  --git a/llvm/lib/Support/FormatVariadic.cpp 
b/llvm/lib/Support/FormatVariadic.cpp
index f9e89f69b528..0d61fae22323 100644
--- a/llvm/lib/Support/FormatVariadic.cpp
+++ b/llvm/lib/Support/FormatVariadic.cpp
@@ -6,6 +6,7 @@
 
//===--===//
 
 #include "llvm/Support/FormatVariadic.h"
+#include 
 
 using namespace llvm;
 

diff  --git a/llvm/lib/Support/IntEqClasses.cpp 
b/llvm/lib/Support/IntEqClasses.cpp
index 4a976dcefc65..ebb02e6c01e5 100644
--- a/llvm/lib/Support/IntEqClasses.cpp
+++ b/llvm/lib/Support/IntEqClasses.cpp
@@ -18,6 +18,7 @@
 
//===--===//
 
 #include "llvm/ADT/IntEqClasses.h"
+#include 
 
 using namespace llvm;
 

diff  --git a/llvm/lib/Support/IntervalMap.cpp 
b/llvm/lib/Support/IntervalMap.cpp
index f15c7c9403c3..674e0f962fa1 100644
--- a/llvm/lib/Support/IntervalMap.cpp
+++ b/llvm/lib/Support/IntervalMap.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "llvm/ADT/IntervalMap.h"
+#include 
 
 namespace llvm {
 namespace IntervalMapImpl {

diff  --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp
index 8f3f4aa8caea..2f1cff7914bc 100644
--- a/llvm/lib/Support/KnownBits.cpp
+++ b/llvm/lib/Support/KnownBits.cpp
@@ -12,6 +12,7 @@
 
//===--===//
 
 #include "llvm/Support/KnownBits.h"
+#include 
 
 using namespace llvm;
 

diff  --git a/llvm/lib/Support/PrettyStackTrace.cpp 
b/llvm/lib/Support/PrettyStackTrace.cpp
index bfb238cc8539..30a12f65966a 100644
--- a/llvm/lib/Support/PrettyStackTrace.cpp
+++ b/llvm/lib/Support/PrettyStackTrace.cpp
@@ -22,6 +22,7 @@
 #include "llvm/Support/raw_ostream.h"
 
 #include 
+#include 
 #include 
 #include 
 #include 

diff  --git a/llvm/lib/Support/Regex.cpp b/llvm/lib/Support/Regex.cpp
index 615e48a5df7e..f065adadc62b 100644
--- a/llvm/lib/Support/Regex.cpp
+++ b/llvm/lib/Support/Regex.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
+#include 
 #include 
 
 // Important this comes last because it defines "_REGEX_H_". At least on

diff  --git a/llvm/lib/Support/StringPool.cpp b/llvm/lib/Support/StringPool.cpp
index 82351017b8cc..27465389 100644
--- a/llvm/lib/Support/StringPool.cpp
+++ b/llvm/lib/Support/StringPool.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Support/StringPool.h"
 #include "llvm/ADT/StringRef.h"
+#include 
 
 using namespace llvm;
 

diff  --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp
index e09abd24eb5b..79f31efefb78 100644
--- a/llvm/lib/Support/Triple.cpp
+++ b/llvm/lib/Support/Triple.cpp
@@ -14,6 +14,7 @@
 #include "llvm/Support/Host.h"
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/Support/TargetParser.h"
+#include 
 #include 
 using namespace llvm;
 

diff  --git a/llvm/lib/Support/VersionTuple.cpp 
b/llvm/lib/Support/VersionTuple.cpp
index 

[PATCH] D75139: [hexagon] Pickup the default crt and libs when the musl target is selected

2020-03-02 Thread Sid Manning via Phabricator via cfe-commits
sidneym updated this revision to Diff 247724.
sidneym added a comment.

address clang-tidy issues


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75139

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/test/Driver/hexagon-toolchain-elf.c

Index: clang/test/Driver/hexagon-toolchain-elf.c
===
--- clang/test/Driver/hexagon-toolchain-elf.c
+++ clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,3 +597,70 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK084 %s
 // CHECK084:  "-fno-use-init-array"
+// -
+// Passing --musl
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   -fuse-ld=lld \
+// RUN:   --sysroot=/hexagon \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK085 %s
+// CHECK085-NOT:  /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK085:  "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK085:  "/hexagon{{/|}}lib{{/|}}crt1.o"
+// CHECK085:  "-lclang_rt.builtins-hexagon" "-lc"
+// -
+// Passing --musl --shared
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -shared \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK086 %s
+// CHECK086-NOT:-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1
+// CHECK086:"/hexagon{{/|}}lib{{/|}}Scrt1.o"
+// CHECK086:"-lclang_rt.builtins-hexagon" "-lc"
+// CHECK086-NOT:/hexagon{{/|}}lib{{/|}}crt1.o
+// -
+// Passing --musl -nostdlib
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostdlib \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK087 %s
+// CHECK087:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK087-NOT:   /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK087-NOT:   /hexagon{{/|}}lib{{/|}}crt1.o
+// CHECK087-NOT:   -lclang_rt.builtins-hexagon
+// CHECK087-NOT:   -lc
+// -
+// Passing --musl -nostartfiles
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostartfiles \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK088 %s
+// CHECK088:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK088-NOT:   /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK088-NOT:   /hexagon{{/|}}lib{{/|}}crt1.o
+// CHECK088:   "-lclang_rt.builtins-hexagon" "-lc"
+// -
+// Passing --musl -nodefaultlibs
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nodefaultlibs \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK089 %s
+// CHECK089:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK089:   "/hexagon{{/|}}lib{{/|}}crt1.o"
+// CHECK089-NOT:   -lclang_rt.builtins-hexagon
+// CHECK089-NOT:   -lc
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -264,18 +264,39 @@
 UseG0 = G.getValue() == 0;
   }
 
-  //
-  //
-  //
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 
+  if (HTC.getTriple().isMusl()) {
+if (!Args.hasArg(options::OPT_shared, options::OPT_static))
+  CmdArgs.push_back("-dynamic-linker=/lib/ld-musl-hexagon.so.1");
+
+if (!Args.hasArg(options::OPT_shared, options::OPT_nostartfiles,
+ 

[PATCH] D75479: [clangd] go-to-def on names in comments etc that are used nearby.

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: nridge.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay, ilya-biryukov.
Herald added a project: clang.

This is intended as a companion to (and is inspired by) D72874 
 which attempts to
resolve these cases using the index.
The intent is we'd try this strategy after the AST-based approach but before the
index-based (I think local usages would be more reliable than index matches).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75479

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -38,6 +38,7 @@
 namespace {
 
 using ::testing::ElementsAre;
+using ::testing::Eq;
 using ::testing::IsEmpty;
 using ::testing::Matcher;
 using ::testing::UnorderedElementsAreArray;
@@ -342,7 +343,7 @@
   R"cpp(// Symbol concatenated inside macro (not supported)
int *pi;
#define POINTER(X) p ## X;
-   int i = *POINTER(^i);
+   int x = *POINTER(^i);
   )cpp",
 
   R"cpp(// Forward class declaration
@@ -855,6 +856,88 @@
   ElementsAre(Sym("foo", FooWithoutHeader.range(;
 }
 
+TEST(LocateSymbol, NearbyTokenSmoke) {
+  auto T = Annotations(R"cpp(
+// prints e^rr and crashes
+void die(const char* [[err]]);
+  )cpp");
+  auto AST = TestTU::withCode(T.code()).build();
+  // We don't pass an index, so can't hit index-based fallback.
+  EXPECT_THAT(locateSymbolAt(AST, T.point()),
+  ElementsAre(Sym("err", T.range(;
+}
+
+TEST(LocateSymbol, NearbyIdentifier) {
+  const char *Tests[] = {
+R"cpp(
+  // regular identifiers (won't trigger)
+  int hello;
+  int y = he^llo;
+)cpp",
+R"cpp(
+  // disabled preprocessor sections
+  int [[hello]];
+  #if 0
+  int y = ^hello;
+  #endif
+)cpp",
+R"cpp(
+  // comments
+  // he^llo, world
+  int [[hello]];
+)cpp",
+R"cpp(
+  // string literals
+  int [[hello]];
+  const char* greeting = "h^ello, world";
+)cpp",
+
+R"cpp(
+  // can refer to macro invocations (even if they expand to nothing)
+  #define INT int
+  [[INT]] x;
+  // I^NT
+)cpp",
+
+R"cpp(
+  // prefer nearest occurrence
+  int hello;
+  int x = hello;
+  // h^ello
+  int y = [[hello]];
+  int z = hello;
+)cpp",
+
+R"cpp(
+  // short identifiers find near results
+  int [[hi]];
+  // h^i
+)cpp",
+R"cpp(
+  // short identifiers don't find far results
+  int hi;
+
+
+
+  // h^i
+)cpp",
+  };
+  for (const char* Test : Tests) {
+Annotations T(Test);
+auto AST = TestTU::withCode(T.code()).build();
+const auto  = AST.getSourceManager();
+llvm::Optional Nearby;
+if (const auto*Tok = findNearbyIdentifier(
+cantFail(sourceLocationInMainFile(SM, T.point())), AST.getTokens()))
+  Nearby = halfOpenToRange(SM, CharSourceRange::getCharRange(
+   Tok->location(), Tok->endLocation()));
+if (T.ranges().empty())
+  EXPECT_THAT(Nearby, Eq(llvm::None)) << Test;
+else
+  EXPECT_THAT(Nearby, T.range()) << Test;
+  }
+}
+
 TEST(FindReferences, WithinAST) {
   const char *Tests[] = {
   R"cpp(// Local variable
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -26,6 +26,10 @@
 #include 
 
 namespace clang {
+namespace syntax {
+class Token;
+class TokenBuffer;
+} // namespace syntax
 namespace clangd {
 class ParsedAST;
 
@@ -49,6 +53,13 @@
 std::vector locateSymbolAt(ParsedAST , Position Pos,
   const SymbolIndex *Index = nullptr);
 
+// If SpellingLoc points at a "word" that does not correspond to an expanded
+// token (e.g. in a comment, a string, or a PP disabled region), then try to
+// find a close occurrence of that word that does.
+// (This is for internal use by locateSymbolAt, and is exposed for testing).
+const syntax::Token *findNearbyIdentifier(SourceLocation SpellingLoc,
+  const syntax::TokenBuffer );
+
 /// Get all document links
 std::vector getDocumentLinks(ParsedAST );
 
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -28,6 +28,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/Type.h"
+#include "clang/Basic/CharInfo.h"
 #include "clang/Basic/LLVM.h"
 

[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Hi Michael, thanks for improving this.




Comment at: clang/include/clang/Driver/Options.td:1448
   Flags<[CC1Option]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  HelpText<"Build this module as a system module. Only used with 
-emit-module">;

I wonder if `-isystem-module` wouldn't be better since it's kinda similar with 
`-isystem` for headers, but for modules.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1912
+Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
+   << "-emit-module";
 

What happens when we use this with implicit modules? It will just be ignored? 
If so, users might think that using `-fsystem-module` might help them get rid 
of some warnings/errors, when in fact it won't.



Comment at: clang/test/Modules/fsystem-module.m:1
+// RUN: rm -rf %t
+// RUN: rm -rf %t-saved

Is this really needed given you are only using `%t-saved` below?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75395



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


[PATCH] D72874: [clangd] Add a textual fallback for go-to-definition

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D72874#1901606 , @nridge wrote:

> The "dependent code" use case is a pretty important one in my eyes.
>
> In one of the codebases I work on, we have a fair amount of code like this:


Yep, fair enough. And I don't think that this is so bad for say 
`DependentDeclRefExpr`, where we're already doing heuristic stuff (and the user 
can reasonably understand that we might).
I'm more concerned that it might trigger at arbitrary times, like say on 
`[[^noreturn]] void abort();`.

But we can distinguish these cases! `SelectionTree` recognizes 
`DependentDeclRefExpr` and friends even if `targetDecl` can't resolve them. So 
I think we can use a whitelist: the AST part of locateSymbol reports the type 
of node that owned TouchedIdentifier, and if it's one of the types we want to 
use textual fallback for, then we go ahead with the fallback code (in addition 
to the cases I mentioned where the touched word doesn't turn out to be a real 
identifier).
We can even try to glean more info, e.g. if it's a 
`CXXDependentScopeMemberExpr` then we can filter out non-member index results.

(Tactically I think it makes sense to add the basic fallback logic, and follow 
up with the dependent-code entrypoints, but up to you)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72874



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


[clang] c61401b - Revert "[clang] detect switch fallthrough marked by a comment (PR43465)"

2020-03-02 Thread Luboš Luňák via cfe-commits

Author: Luboš Luňák
Date: 2020-03-02T22:33:25+01:00
New Revision: c61401b89742f230b7e6a2cc0548fbf7442e906d

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

LOG: Revert "[clang] detect switch fallthrough marked by a comment (PR43465)"

This reverts commit 398b4ed87d488b42032c8d0304324dce76ba9b66.
As requested in https://bugs.llvm.org/show_bug.cgi?id=43465#c37 .

Added: 


Modified: 
clang/lib/Sema/AnalysisBasedWarnings.cpp

Removed: 
clang/test/Sema/fallthrough-comment.c



diff  --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index a162ff091efd..04611dadde66 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -1148,11 +1148,6 @@ namespace {
   continue;
 }
 
-if (isFollowedByFallThroughComment(LastStmt)) {
-  ++AnnotatedCnt;
-  continue; // Fallthrough comment, good.
-}
-
 ++UnannotatedCnt;
   }
   return !!UnannotatedCnt;
@@ -1213,41 +1208,10 @@ namespace {
   return nullptr;
 }
 
-bool isFollowedByFallThroughComment(const Stmt *Statement) {
-  // Try to detect whether the fallthough is marked by a comment like
-  // /*FALLTHOUGH*/.
-  bool Invalid;
-  const char *SourceData = S.getSourceManager().getCharacterData(
-  Statement->getEndLoc(), );
-  if (Invalid)
-return false;
-  const char *LineStart = SourceData;
-  for (;;) {
-LineStart = strchr(LineStart, '\n');
-if (LineStart == nullptr)
-  return false;
-++LineStart; // Start of next line.
-const char *LineEnd = strchr(LineStart, '\n');
-StringRef Line(LineStart,
-   LineEnd ? LineEnd - LineStart : strlen(LineStart));
-if (LineStart == LineEnd ||
-Line.find_first_not_of(" \t\r") == StringRef::npos)
-  continue; // Whitespace-only line.
-if (!FallthroughRegex.isValid())
-  FallthroughRegex =
-  llvm::Regex("(/\\*[ \\t]*fall(s | |-)?thr(ough|u)\\.?[ 
\\t]*\\*/)"
-  "|(//[ \\t]*fall(s | |-)?thr(ough|u)\\.?[ \\t]*)",
-  llvm::Regex::IgnoreCase);
-assert(FallthroughRegex.isValid());
-return FallthroughRegex.match(Line);
-  }
-}
-
 bool FoundSwitchStatements;
 AttrStmts FallthroughStmts;
 Sema 
 llvm::SmallPtrSet ReachableBlocks;
-llvm::Regex FallthroughRegex;
   };
 } // anonymous namespace
 

diff  --git a/clang/test/Sema/fallthrough-comment.c 
b/clang/test/Sema/fallthrough-comment.c
deleted file mode 100644
index 85d1257932f6..
--- a/clang/test/Sema/fallthrough-comment.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c11 -verify -Wimplicit-fallthrough %s
-
-int fallthrough_comment(int n) {
-  switch (n) {
-  case 0:
-n++;
-// FALLTHROUGH
-  case 1:
-n++;
-
-/*fall-through.*/
-
-  case 2:
-n++;
-  case 3: // expected-warning{{unannotated fall-through between switch 
labels}} expected-note{{insert '__attribute__((fallthrough));' to silence this 
warning}} expected-note{{insert 'break;' to avoid fall-through}}
-n++;
-break;
-  }
-  return n;
-}



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


[PATCH] D73852: [clang] detect switch fallthrough marked by a comment (PR43465)

2020-03-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Per http://llvm.org/PR43465#c37, this patch has not had proper review and we 
have not established consensus that we want this. Please revert for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73852



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


[PATCH] D73852: [clang] detect switch fallthrough marked by a comment (PR43465)

2020-03-02 Thread Luboš Luňák via Phabricator via cfe-commits
llunak added a comment.

In D73852#1901186 , @rsmith wrote:

> We shouldn't enable the warning under -Wextra in language modes where there's 
> no standard way to suppress it.


That may be true, but that is not what the bugreport is about, it explicitly 
mentions flex. There are codebases that explicitly use -Wimplicit-fallthrough, 
and flex generates the same code even for C++. So either Clang needs to handle 
it, or flex needs to change (which may be non-trivial if 
https://bugs.llvm.org/show_bug.cgi?id=43465#c24 is right), or codebases using 
flex will need to either special-case Clang or live with the warning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73852



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


[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield marked 2 inline comments as done.
JonChesterfield added inline comments.



Comment at: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp:23
+// CHECK: @nominally_value_init = global i32 undef
+int nominally_value_init  [[clang::loader_uninitialized]] = 4;
+

Quuxplusone wrote:
> rjmccall wrote:
> > JonChesterfield wrote:
> > > Quuxplusone wrote:
> > > > This test case is identical to line 36 of 
> > > > clang/test/Sema/attr-loader-uninitialized.cpp, where you say you don't 
> > > > want it to compile at all.
> > > > 
> > > > I think you need a clearer idea of how this interacts with 
> > > > initializers. Is it merely supposed to eliminate the 
> > > > //zero-initialization// that happens before the user-specified 
> > > > construction/initialization, or is it supposed to compete with the 
> > > > user-specified construction/initialization?
> > > > 
> > > > That is, for
> > > > 
> > > > nontrivial unt [[clang::loader_uninitialized]];
> > > > 
> > > > is it merely supposed to call `unt::unt()` on a chunk of undef memory 
> > > > (instead of the usual chunk of zeroed memory), or is it supposed to 
> > > > skip the constructor entirely? And for
> > > > 
> > > > int x [[clang::loader_uninitialized]] = foo();
> > > > 
> > > > is it merely supposed to call `foo()` and assign the result to a chunk 
> > > > of undef memory (instead of the usual chunk of zeroed memory), or is it 
> > > > supposed to skip the initialization entirely?
> > > I think you commented while the first working piece of sema landed. My 
> > > thinking is relatively clear but my understanding of clang's semantic 
> > > analysis is a work in progress!
> > > 
> > > Initializers (`= foo()`) are straightforward. Error on the basis that the 
> > > attribute effectively means `= undef`, and one should not have two 
> > > initializers. A test case is now added for that (and now passes).
> > > 
> > > The codegen I want for a default constructed global marked with this 
> > > variable is:
> > > - global variable allocated, with undef as the original value
> > > - default constructor call synthesized
> > > - said default constructor set up for invocation from crt, before main, 
> > > writing over the undef value
> > > 
> > > Where the default constructor can be optimized as usual, e.g. if it 
> > > always writes a constant, we can init with that constant instead of the 
> > > undef and elide the constructor.
> > > 
> > > I don't have that actually working yet - the constructor call is not 
> > > being emitted, so we just have the undef global.
> > > 
> > > I think it's important to distinguish between the values of the bits when 
> > > the program is loaded and whether constructor/destructors are called, as 
> > > one could want any combination of the two.
> > I think Arthur is suggesting that it would be useful to allow the attribute 
> > to be used in conjunction with an initializer in C++, since if the 
> > initializer has to be run dynamically, we can still meaningfully suppress 
> > the static zero-initialization.   That is, we've accepted that it's useful 
> > to do this when *default-initializing* a global, but it's actually useful 
> > when doing *any* kind of dynamic initialization.
> > 
> > Maybe we can leave it as an error in C++ when the initializer is a constant 
> > expression.  Although that might be unnecessarily brittle if e.g. the 
> > constructor is `constexpr` in one library version but not another.
> No, that's exctly what I mean. You seem to be holding two contradictory ideas 
> simultaneously:
> 
> [[loader_uninitialized]] X x = X{};  // two initializers, therefore error
> 
> [[loader_uninitialized]] X x {}; // one initializer plus one constructor, 
> therefore fine
> 
> In C++, these two declarations have identical semantics. It doesn't make 
> sense to say that one of them "calls a constructor" and the other one "has an 
> initializer." They're literally the same thing.
> 
> Similarly in both C99 and C++ with plain old ints:
> 
> [[loader_uninitialized]] int x = foo();
> 
> This means "call foo and dynamically initialize x with the result," just as 
> surely as
> 
> [[loader_uninitialized]] X x = X();
> 
> means "call X::X and dynamically initialize x with the result." Having one 
> rule for dynamic initializers of primitive types and a separate rule for 
> dynamic initializers of class types doesn't work.
> 
> Furthermore, "dynamic initialization" can be promoted to compile-time:
> 
> [[loader_uninitialized]] int x = 42;
> [[loader_uninitialized]] std::string_view x = "hello world";
> 
> It wouldn't make semantic sense to say that one of these has "two 
> initializers" and the other has "one initializer," because both of the 
> initializations end up happening at compile time and getting put into .data.
I'm under the impression that the constructs are:
```
X x = X{};  // default construct an X and then call the copy constructor at x
X x {}; // 

[PATCH] D75373: [Clang] Fix Hurd toolchain class hierarchy

2020-03-02 Thread Alexandre Ganea via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7e77cf473ac9: [Clang] Fix Hurd toolchain test on a two-stage 
build with ThinLTO (authored by aganea).

Changed prior to commit:
  https://reviews.llvm.org/D75373?vs=247542=247715#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75373

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  clang/lib/Driver/ToolChains/Hurd.cpp
  clang/lib/Driver/ToolChains/Hurd.h
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h

Index: clang/lib/Driver/ToolChains/Linux.h
===
--- clang/lib/Driver/ToolChains/Linux.h
+++ clang/lib/Driver/ToolChains/Linux.h
@@ -42,7 +42,9 @@
 llvm::opt::ArgStringList ) const override;
   virtual std::string computeSysRoot() const;
 
-  virtual std::string getDynamicLinker(const llvm::opt::ArgList ) const;
+  std::string getDynamicLinker(const llvm::opt::ArgList ) const override;
+
+  void addExtraOpts(llvm::opt::ArgStringList ) const override;
 
   std::vector ExtraOpts;
 
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -1007,3 +1007,8 @@
 return llvm::DenormalMode::getIEEE();
   }
 }
+
+void Linux::addExtraOpts(llvm::opt::ArgStringList ) const {
+  for (const auto  : ExtraOpts)
+CmdArgs.push_back(Opt.c_str());
+}
Index: clang/lib/Driver/ToolChains/Hurd.h
===
--- clang/lib/Driver/ToolChains/Hurd.h
+++ clang/lib/Driver/ToolChains/Hurd.h
@@ -27,9 +27,11 @@
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
 
-  virtual std::string computeSysRoot() const;
+  std::string computeSysRoot() const;
 
-  virtual std::string getDynamicLinker(const llvm::opt::ArgList ) const;
+  std::string getDynamicLinker(const llvm::opt::ArgList ) const override;
+
+  void addExtraOpts(llvm::opt::ArgStringList ) const override;
 
   std::vector ExtraOpts;
 
Index: clang/lib/Driver/ToolChains/Hurd.cpp
===
--- clang/lib/Driver/ToolChains/Hurd.cpp
+++ clang/lib/Driver/ToolChains/Hurd.cpp
@@ -61,8 +61,7 @@
   return Triple.isArch32Bit() ? "lib" : "lib64";
 }
 
-Hurd::Hurd(const Driver , const llvm::Triple ,
-   const ArgList )
+Hurd::Hurd(const Driver , const llvm::Triple , const ArgList )
 : Generic_ELF(D, Triple, Args) {
   std::string SysRoot = computeSysRoot();
   path_list  = getFilePaths();
@@ -170,3 +169,8 @@
 
   addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
 }
+
+void Hurd::addExtraOpts(llvm::opt::ArgStringList ) const {
+  for (const auto  : ExtraOpts)
+CmdArgs.push_back(Opt.c_str());
+}
Index: clang/lib/Driver/ToolChains/Gnu.h
===
--- clang/lib/Driver/ToolChains/Gnu.h
+++ clang/lib/Driver/ToolChains/Gnu.h
@@ -356,6 +356,12 @@
   void addClangTargetOptions(const llvm::opt::ArgList ,
  llvm::opt::ArgStringList ,
  Action::OffloadKind DeviceOffloadKind) const override;
+
+  virtual std::string getDynamicLinker(const llvm::opt::ArgList ) const {
+return {};
+  }
+
+  virtual void addExtraOpts(llvm::opt::ArgStringList ) const {}
 };
 
 } // end namespace toolchains
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -309,7 +309,7 @@
   }
 }
 
-static bool getPIE(const ArgList , const toolchains::Linux ) {
+static bool getPIE(const ArgList , const ToolChain ) {
   if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
   Args.hasArg(options::OPT_r) || Args.hasArg(options::OPT_static_pie))
 return false;
@@ -317,17 +317,16 @@
   Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
options::OPT_nopie);
   if (!A)
-return ToolChain.isPIEDefault();
+return TC.isPIEDefault();
   return A->getOption().matches(options::OPT_pie);
 }
 
-static bool getStaticPIE(const ArgList ,
- const toolchains::Linux ) {
+static bool getStaticPIE(const ArgList , const 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  = ToolChain.getDriver();
+const Driver  = TC.getDriver();
 const llvm::opt::OptTable  = D.getOpts();
 const char *StaticPIEName = 

[PATCH] D75447: [clangd] Make use of token buffers in semantic highlighting

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:162
+[&](const syntax::Token ) { return Tok.location() < Loc; });
+assert(Tok);
+

`&& Tok->location() == Loc`, right?

(I think this would make a nice method 
`TokenBuffer::spelledTokenAt(SourceLocation) -> const Token*`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75447



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


[PATCH] D75139: [hexagon] Pickup the default crt and libs when the musl target is selected

2020-03-02 Thread Sid Manning via Phabricator via cfe-commits
sidneym updated this revision to Diff 247711.
sidneym added a comment.

Update testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75139

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/test/Driver/hexagon-toolchain-elf.c

Index: clang/test/Driver/hexagon-toolchain-elf.c
===
--- clang/test/Driver/hexagon-toolchain-elf.c
+++ clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,3 +597,70 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK084 %s
 // CHECK084:  "-fno-use-init-array"
+// -
+// Passing --musl
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   -fuse-ld=lld \
+// RUN:   --sysroot=/hexagon \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK085 %s
+// CHECK085-NOT:  /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK085:  "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK085:  "/hexagon{{/|}}lib{{/|}}crt1.o"
+// CHECK085:  "-lclang_rt.builtins-hexagon" "-lc"
+// -
+// Passing --musl --shared
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -shared \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK086 %s
+// CHECK086-NOT:-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1
+// CHECK086:"/hexagon{{/|}}lib{{/|}}Scrt1.o"
+// CHECK086:"-lclang_rt.builtins-hexagon" "-lc"
+// CHECK086-NOT:/hexagon{{/|}}lib{{/|}}crt1.o
+// -
+// Passing --musl -nostdlib
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostdlib \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK087 %s
+// CHECK087:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK087-NOT:   /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK087-NOT:   /hexagon{{/|}}lib{{/|}}crt1.o
+// CHECK087-NOT:   -lclang_rt.builtins-hexagon
+// CHECK087-NOT:   -lc
+// -
+// Passing --musl -nostartfiles
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostartfiles \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK088 %s
+// CHECK088:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK088-NOT:   /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK088-NOT:   /hexagon{{/|}}lib{{/|}}crt1.o
+// CHECK088:   "-lclang_rt.builtins-hexagon" "-lc"
+// -
+// Passing --musl -nodefaultlibs
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nodefaultlibs \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK089 %s
+// CHECK089:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// CHECK089:   "/hexagon{{/|}}lib{{/|}}crt1.o"
+// CHECK089-NOT:   -lclang_rt.builtins-hexagon
+// CHECK089-NOT:   -lc
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -264,18 +264,41 @@
 UseG0 = G.getValue() == 0;
   }
 
-  //
-  //
-  //
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 
+  if (HTC.getTriple().isMusl()) {
+if (!Args.hasArg(options::OPT_shared, options::OPT_static))
+  CmdArgs.push_back("-dynamic-linker=/lib/ld-musl-hexagon.so.1");
+
+if (!Args.hasArg(options::OPT_shared,
+ options::OPT_nostartfiles,
+

[clang] 7e77cf4 - [Clang] Fix Hurd toolchain test on a two-stage build with ThinLTO

2020-03-02 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2020-03-02T15:42:33-05:00
New Revision: 7e77cf473ac9d8f8b65db017d660892f1c8f4b75

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

LOG: [Clang] Fix Hurd toolchain test on a two-stage build with ThinLTO

A two-stage ThinLTO build previously failed the clang/test/Driver/hurd.c test 
because of a static_cast in "tools::gnutools::Linker::ConstructJob()" which 
wrongly converted an instance of "clang::driver::toolchains::Hurd" into that of 
"clang::driver::toolchains::Linux". ThinLTO would later devirtualize the 
"ToolChain.getDynamicLinker(Args)" call and use "Linux::getDynamicLinker()" 
instead, causing the test to generate a wrong "-dynamic-linker" linker flag 
(/lib/ld-linux.so.2 instead of /lib/ld.so)

Fixes PR45061.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index c356657541fa..d20d62987589 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -309,7 +309,7 @@ static const char *getLDMOption(const llvm::Triple , 
const ArgList ) {
   }
 }
 
-static bool getPIE(const ArgList , const toolchains::Linux ) {
+static bool getPIE(const ArgList , const ToolChain ) {
   if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
   Args.hasArg(options::OPT_r) || Args.hasArg(options::OPT_static_pie))
 return false;
@@ -317,17 +317,16 @@ static bool getPIE(const ArgList , const 
toolchains::Linux ) {
   Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
options::OPT_nopie);
   if (!A)
-return ToolChain.isPIEDefault();
+return TC.isPIEDefault();
   return A->getOption().matches(options::OPT_pie);
 }
 
-static bool getStaticPIE(const ArgList ,
- const toolchains::Linux ) {
+static bool getStaticPIE(const ArgList , const 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  = ToolChain.getDriver();
+const Driver  = TC.getDriver();
 const llvm::opt::OptTable  = D.getOpts();
 const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
 const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
@@ -346,8 +345,12 @@ void tools::gnutools::Linker::ConstructJob(Compilation , 
const JobAction ,
const InputInfoList ,
const ArgList ,
const char *LinkingOutput) const {
-  const toolchains::Linux  =
-  static_cast(getToolChain());
+  // FIXME: The Linker class constructor takes a ToolChain and not a
+  // Generic_ELF, so the static_cast might return a reference to a invalid
+  // instance (see PR45061). Ideally, the Linker constructor needs to take a
+  // Generic_ELF instead.
+  const toolchains::Generic_ELF  =
+  static_cast(getToolChain());
   const Driver  = ToolChain.getDriver();
 
   const llvm::Triple  = getToolChain().getEffectiveTriple();
@@ -418,8 +421,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation , 
const JobAction ,
   if (isAndroid)
   CmdArgs.push_back("--warn-shared-textrel");
 
-  for (const auto  : ToolChain.ExtraOpts)
-CmdArgs.push_back(Opt.c_str());
+  ToolChain.addExtraOpts(CmdArgs);
 
   CmdArgs.push_back("--eh-frame-hdr");
 

diff  --git a/clang/lib/Driver/ToolChains/Gnu.h 
b/clang/lib/Driver/ToolChains/Gnu.h
index 083f74c05477..fa50b56bf954 100644
--- a/clang/lib/Driver/ToolChains/Gnu.h
+++ b/clang/lib/Driver/ToolChains/Gnu.h
@@ -356,6 +356,12 @@ class LLVM_LIBRARY_VISIBILITY Generic_ELF : public 
Generic_GCC {
   void addClangTargetOptions(const llvm::opt::ArgList ,
  llvm::opt::ArgStringList ,
  Action::OffloadKind DeviceOffloadKind) const 
override;
+
+  virtual std::string getDynamicLinker(const llvm::opt::ArgList ) const {
+return {};
+  }
+
+  virtual void addExtraOpts(llvm::opt::ArgStringList ) const {}
 };
 
 } // end namespace toolchains

diff  --git a/clang/lib/Driver/ToolChains/Hurd.cpp 
b/clang/lib/Driver/ToolChains/Hurd.cpp
index 72286bd09f13..ce1806c4043b 100644
--- a/clang/lib/Driver/ToolChains/Hurd.cpp
+++ b/clang/lib/Driver/ToolChains/Hurd.cpp
@@ -61,8 +61,7 @@ static StringRef 

[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp:23
+// CHECK: @nominally_value_init = global i32 undef
+int nominally_value_init  [[clang::loader_uninitialized]] = 4;
+

rjmccall wrote:
> JonChesterfield wrote:
> > Quuxplusone wrote:
> > > This test case is identical to line 36 of 
> > > clang/test/Sema/attr-loader-uninitialized.cpp, where you say you don't 
> > > want it to compile at all.
> > > 
> > > I think you need a clearer idea of how this interacts with initializers. 
> > > Is it merely supposed to eliminate the //zero-initialization// that 
> > > happens before the user-specified construction/initialization, or is it 
> > > supposed to compete with the user-specified construction/initialization?
> > > 
> > > That is, for
> > > 
> > > nontrivial unt [[clang::loader_uninitialized]];
> > > 
> > > is it merely supposed to call `unt::unt()` on a chunk of undef memory 
> > > (instead of the usual chunk of zeroed memory), or is it supposed to skip 
> > > the constructor entirely? And for
> > > 
> > > int x [[clang::loader_uninitialized]] = foo();
> > > 
> > > is it merely supposed to call `foo()` and assign the result to a chunk of 
> > > undef memory (instead of the usual chunk of zeroed memory), or is it 
> > > supposed to skip the initialization entirely?
> > I think you commented while the first working piece of sema landed. My 
> > thinking is relatively clear but my understanding of clang's semantic 
> > analysis is a work in progress!
> > 
> > Initializers (`= foo()`) are straightforward. Error on the basis that the 
> > attribute effectively means `= undef`, and one should not have two 
> > initializers. A test case is now added for that (and now passes).
> > 
> > The codegen I want for a default constructed global marked with this 
> > variable is:
> > - global variable allocated, with undef as the original value
> > - default constructor call synthesized
> > - said default constructor set up for invocation from crt, before main, 
> > writing over the undef value
> > 
> > Where the default constructor can be optimized as usual, e.g. if it always 
> > writes a constant, we can init with that constant instead of the undef and 
> > elide the constructor.
> > 
> > I don't have that actually working yet - the constructor call is not being 
> > emitted, so we just have the undef global.
> > 
> > I think it's important to distinguish between the values of the bits when 
> > the program is loaded and whether constructor/destructors are called, as 
> > one could want any combination of the two.
> I think Arthur is suggesting that it would be useful to allow the attribute 
> to be used in conjunction with an initializer in C++, since if the 
> initializer has to be run dynamically, we can still meaningfully suppress the 
> static zero-initialization.   That is, we've accepted that it's useful to do 
> this when *default-initializing* a global, but it's actually useful when 
> doing *any* kind of dynamic initialization.
> 
> Maybe we can leave it as an error in C++ when the initializer is a constant 
> expression.  Although that might be unnecessarily brittle if e.g. the 
> constructor is `constexpr` in one library version but not another.
No, that's exctly what I mean. You seem to be holding two contradictory ideas 
simultaneously:

[[loader_uninitialized]] X x = X{};  // two initializers, therefore error

[[loader_uninitialized]] X x {}; // one initializer plus one constructor, 
therefore fine

In C++, these two declarations have identical semantics. It doesn't make sense 
to say that one of them "calls a constructor" and the other one "has an 
initializer." They're literally the same thing.

Similarly in both C99 and C++ with plain old ints:

[[loader_uninitialized]] int x = foo();

This means "call foo and dynamically initialize x with the result," just as 
surely as

[[loader_uninitialized]] X x = X();

means "call X::X and dynamically initialize x with the result." Having one rule 
for dynamic initializers of primitive types and a separate rule for dynamic 
initializers of class types doesn't work.

Furthermore, "dynamic initialization" can be promoted to compile-time:

[[loader_uninitialized]] int x = 42;
[[loader_uninitialized]] std::string_view x = "hello world";

It wouldn't make semantic sense to say that one of these has "two initializers" 
and the other has "one initializer," because both of the initializations end up 
happening at compile time and getting put into .data.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361



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


[PATCH] D72874: [clangd] Add a textual fallback for go-to-definition

2020-03-02 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks for all the comments Sam! I'll have a detailed look tomorrow, but I 
wanted to follow up on this:

In D72874#1901383 , @sammccall wrote:

> I think having this trigger where the identifier is an actual token in the 
> program is a surprisingly invasive change and runs a strong risk of confusing 
> users (who can't distinguish these textual heuristics from normal go-to-def 
> behaviour, and rely on its accuracy), and we shouldn't do it without a lot 
> more testing.


The "dependent code" use case is a pretty important one in my eyes.

In one of the codebases I work on, we have a fair amount of code like this:

  template 
  void foo(T t) {
 // ...
 t.someUniqueMethodName();
 // ...
 t.someOtherUniqueMethodName();
 // ...
  }

The code is in practice only instantiated with a handful of types for T (often 
just two). (But we don't have a way to express this in the code at this time.) 
Being able to invoke go-to-definition at e.g. `someUniqueMethodName` and get 
the definition sites of the corresponding handful of methods, as opposed to 
nothing at all, is something I'd really like to get working. I'm open to 
suggestions to how we can test this better, or scope the behaviour more 
narrowly to avoid other unintended results for real tokens.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72874



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


[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp:23
+// CHECK: @nominally_value_init = global i32 undef
+int nominally_value_init  [[clang::loader_uninitialized]] = 4;
+

JonChesterfield wrote:
> Quuxplusone wrote:
> > This test case is identical to line 36 of 
> > clang/test/Sema/attr-loader-uninitialized.cpp, where you say you don't want 
> > it to compile at all.
> > 
> > I think you need a clearer idea of how this interacts with initializers. Is 
> > it merely supposed to eliminate the //zero-initialization// that happens 
> > before the user-specified construction/initialization, or is it supposed to 
> > compete with the user-specified construction/initialization?
> > 
> > That is, for
> > 
> > nontrivial unt [[clang::loader_uninitialized]];
> > 
> > is it merely supposed to call `unt::unt()` on a chunk of undef memory 
> > (instead of the usual chunk of zeroed memory), or is it supposed to skip 
> > the constructor entirely? And for
> > 
> > int x [[clang::loader_uninitialized]] = foo();
> > 
> > is it merely supposed to call `foo()` and assign the result to a chunk of 
> > undef memory (instead of the usual chunk of zeroed memory), or is it 
> > supposed to skip the initialization entirely?
> I think you commented while the first working piece of sema landed. My 
> thinking is relatively clear but my understanding of clang's semantic 
> analysis is a work in progress!
> 
> Initializers (`= foo()`) are straightforward. Error on the basis that the 
> attribute effectively means `= undef`, and one should not have two 
> initializers. A test case is now added for that (and now passes).
> 
> The codegen I want for a default constructed global marked with this variable 
> is:
> - global variable allocated, with undef as the original value
> - default constructor call synthesized
> - said default constructor set up for invocation from crt, before main, 
> writing over the undef value
> 
> Where the default constructor can be optimized as usual, e.g. if it always 
> writes a constant, we can init with that constant instead of the undef and 
> elide the constructor.
> 
> I don't have that actually working yet - the constructor call is not being 
> emitted, so we just have the undef global.
> 
> I think it's important to distinguish between the values of the bits when the 
> program is loaded and whether constructor/destructors are called, as one 
> could want any combination of the two.
I think Arthur is suggesting that it would be useful to allow the attribute to 
be used in conjunction with an initializer in C++, since if the initializer has 
to be run dynamically, we can still meaningfully suppress the static 
zero-initialization.   That is, we've accepted that it's useful to do this when 
*default-initializing* a global, but it's actually useful when doing *any* kind 
of dynamic initialization.

Maybe we can leave it as an error in C++ when the initializer is a constant 
expression.  Although that might be unnecessarily brittle if e.g. the 
constructor is `constexpr` in one library version but not another.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361



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


[clang] 0858eeb - Revert "Add default paths to support musl target"

2020-03-02 Thread Sid Manning via cfe-commits

Author: Sid Manning
Date: 2020-03-02T14:09:52-06:00
New Revision: 0858eebd2a48b931f2ef1dfa23042980bd6a773d

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

LOG: Revert "Add default paths to support musl target"

This reverts commit 637767665141ae48c7a0558903bb29e03bf5ad6f.
Need to fix the testcase.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/test/Driver/hexagon-toolchain-elf.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index c069eefde9af..88523cd4bb1c 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -264,41 +264,18 @@ constructHexagonLinkArgs(Compilation , const JobAction 
,
 UseG0 = G.getValue() == 0;
   }
 
+  
//
+  //
+  
//
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 
-  if (HTC.getTriple().isMusl()) {
-if (!Args.hasArg(options::OPT_shared, options::OPT_static))
-  CmdArgs.push_back("-dynamic-linker=/lib/ld-musl-hexagon.so.1");
-
-if (!Args.hasArg(options::OPT_shared,
- options::OPT_nostartfiles,
- options::OPT_nostdlib))
-  CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/crt1.o"));
-else if (Args.hasArg(options::OPT_shared) &&
- !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib))
-  CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/Scrt1.o"));
-
-CmdArgs.push_back(
-Args.MakeArgString(StringRef("-L") + D.SysRoot + "/lib"));
-Args.AddAllArgs(CmdArgs,
-{options::OPT_T_Group, options::OPT_e, options::OPT_s,
- options::OPT_t, options::OPT_u_Group});
-AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
-
-if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
-  CmdArgs.push_back("-lclang_rt.builtins-hexagon");
-  CmdArgs.push_back("-lc");
-}
-
-return;
-  }
-
   
//
   // moslib
   
//
   std::vector OsLibs;
   bool HasStandalone = false;
+
   for (const Arg *A : Args.filtered(options::OPT_moslib_EQ)) {
 A->claim();
 OsLibs.emplace_back(A->getValue());

diff  --git a/clang/test/Driver/hexagon-toolchain-elf.c 
b/clang/test/Driver/hexagon-toolchain-elf.c
index 24daac05d612..0a6c86424955 100644
--- a/clang/test/Driver/hexagon-toolchain-elf.c
+++ b/clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,69 +597,3 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK084 %s
 // CHECK084:  "-fno-use-init-array"
-// 
-
-// Passing --musl
-// 
-
-// RUN: %clang -### -target hexagon-unknown-linux-musl \
-// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
-// RUN:   -mcpu=hexagonv60 \
-// RUN:   --sysroot=/hexagon \
-// RUN:   %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK085 %s
-// CHECK085-NOT:  /hexagon{{/|}}lib{{/|}}Scrt1.o
-// CHECK085:  "/hexagon{{/|}}lib{{/|}}crt1.o"
-// CHECK085:  "-lclang_rt.builtins-hexagon" "-lc"
-// CHECK085:  "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
-// 
-
-// Passing --musl --shared
-// 
-
-// RUN: %clang -### -target hexagon-unknown-linux-musl \
-// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
-// RUN:   -mcpu=hexagonv60 \
-// RUN:   --sysroot=/hexagon -shared \
-// RUN:   %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK086 %s
-// CHECK086:"/hexagon{{/|}}lib{{/|}}Scrt1.o"
-// CHECK086:"-lclang_rt.builtins-hexagon" "-lc"
-// CHECK086-NOT:/hexagon{{/|}}lib{{/|}}crt1.o
-// CHECK086-NOT:-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1
-// 
-
-// Passing --musl -nostdlib
-// 
-
-// RUN: %clang -### -target hexagon-unknown-linux-musl \
-// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
-// RUN:   -mcpu=hexagonv60 \
-// RUN:   --sysroot=/hexagon -nostdlib \
-// RUN:   %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK087 %s
-// CHECK087-NOT:   

[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-02 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> The main reason we couldn't remove the header file is because of the 
> short-forms/overloaded intrinsics

How are you planning to handle them with your current approach?

Anyway, that isn't really relevant to the question of why we need to `#define 
svld1_u8(...) __builtin_sve_svld1_u8(__VA_ARGS__)`, as opposed to just making 
svld1_u8 an intrinsic.

> I wouldn't know of a way to create overloaded intrinsics without having to 
> manually do the usual arithmetic conversions similar to how this is currently 
> done for some overloaded builtins like SemaBuiltinAtomicOverloaded in 
> SemaChecking.cpp.

The current Builtins.def infrastructure isn't really designed around it, but it 
would be possible to add overloaded intrinsics.  Currently, when a builtin name 
is looked up, we create one FunctionDecl.  But we could change it to 
make/return a list of FunctionDecls, instead, and pass them to standard 
overload resolution.

> I also wonder if this problem isn't better solved using pre-compiled modules 
> at some point?

Sort of?  I mean, yes, loading a precompiled module is somewhat cheaper than 
parsing C.  But it still isn't free, it doesn't really change the fact that the 
indirection isn't doing anything useful, and we're still making 
preprocessing/diagnostics more complicated by using defines.


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

https://reviews.llvm.org/D75298



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


[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield marked 4 inline comments as done.
JonChesterfield added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:4367
+This is useful for variables that are always written to before use where the
+default zero initialization provided by the toolchain loader is expensive.
+  }];

rjmccall wrote:
> How about:
> 
> > The ``loader_uninitialized`` attribute can be placed on global variables to
> > indicate that the variable does not need to be zero initialized by the 
> > loader.
> > On most targets, zero-initialization does not incur any additional cost.
> > For example, most general purpose operating systems deliberately ensure
> > that all memory is properly initialized in order to avoid leaking privileged
> > information from the kernel or other programs.  However, some targets
> > do not make this guarantee, and on these targets, avoiding an unnecessary
> > zero-initialization can have a significant impact on load times and/or code
> > size.
> >
> > A declaration with this attribute is a non-tentative definition just as if 
> > it
> > provided an initializer.   Variables with this attribute are considered to 
> > be
> > uninitialized in the same sense as a local variable, and the programs must
> > write to them before reading from them.  If the variable's type is a C++ 
> > class
> > type with a non-trivial default constructor, or an array thereof, this 
> > attribute
> > only suppresses the static zero-initialization of the variable, not the 
> > dynamic
> > initialization provided by executing the default constructor.
That's a lot better! Thank you. Updated the patch to use your wording verbatim.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7436
+  case ParsedAttr::AT_LoaderUninitialized:
+handleLoaderUninitializedAttr(S, D, AL);
+break;

aaron.ballman wrote:
> rjmccall wrote:
> > JonChesterfield wrote:
> > > aaron.ballman wrote:
> > > > If you don't need any custom semantic checking, you can remove that 
> > > > function and instead call 
> > > > `handleSimpleAttribute(S, D, AL);`
> > > I think this patch does need some custom semantic checking, I just 
> > > haven't been able to work out how to implement it. Specifically, the 
> > > attribute is an initializer, so
> > > 
> > > `int foo __attribute__((loader_uninitialised)) = some_value;`
> > > 
> > > should be a warning, as the = some_value is going to be ignored.
> > This should be an error, not a warning, unless there's a specific need to 
> > be lenient.
> Agreed that this should be an error rather than a warning.
> 
> Not 100% certain, but I suspect you'll need to add that checking to 
> `Sema::AddInitializerToDecl()` because I'm guessing that the initializer has 
> not been processed by the time the attributes are being applied to the 
> variable declaration. You can check `VarDecl::hasInit()` within 
> `handleLoaderUninitializedAttr()` to see if that specific declaration has an 
> initializer, but I'm betting that gives you the wrong answer.
Nice, Yes, that's much better - I should have searched for the opencl `__local` 
handling. As you suspected, hasInit() just returns true at that point.



Comment at: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp:23
+// CHECK: @nominally_value_init = global i32 undef
+int nominally_value_init  [[clang::loader_uninitialized]] = 4;
+

Quuxplusone wrote:
> This test case is identical to line 36 of 
> clang/test/Sema/attr-loader-uninitialized.cpp, where you say you don't want 
> it to compile at all.
> 
> I think you need a clearer idea of how this interacts with initializers. Is 
> it merely supposed to eliminate the //zero-initialization// that happens 
> before the user-specified construction/initialization, or is it supposed to 
> compete with the user-specified construction/initialization?
> 
> That is, for
> 
> nontrivial unt [[clang::loader_uninitialized]];
> 
> is it merely supposed to call `unt::unt()` on a chunk of undef memory 
> (instead of the usual chunk of zeroed memory), or is it supposed to skip the 
> constructor entirely? And for
> 
> int x [[clang::loader_uninitialized]] = foo();
> 
> is it merely supposed to call `foo()` and assign the result to a chunk of 
> undef memory (instead of the usual chunk of zeroed memory), or is it supposed 
> to skip the initialization entirely?
I think you commented while the first working piece of sema landed. My thinking 
is relatively clear but my understanding of clang's semantic analysis is a work 
in progress!

Initializers (`= foo()`) are straightforward. Error on the basis that the 
attribute effectively means `= undef`, and one should not have two 
initializers. A test case is now added for that (and now passes).

The codegen I want for a default constructed global marked with this variable 
is:
- global variable allocated, with undef as the original value
- default constructor call synthesized
- said 

[clang] 375437a - [OPENMP50]Support 'destroy' clause on 'depobj' directives.

2020-03-02 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-03-02T14:40:53-05:00
New Revision: 375437ab92a879629cd6abef057428f3572514c2

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

LOG: [OPENMP50]Support 'destroy' clause on 'depobj' directives.

Added basic support (parsing/sema/serialization) for 'destroy' clause in
depobj directives.

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/depobj_ast_print.cpp
clang/test/OpenMP/depobj_messages.cpp
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 5d78e9015b0f..fa727837a802 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -6693,6 +6693,46 @@ class OMPOrderClause final : public OMPClause {
   }
 };
 
+/// This represents 'destroy' clause in the '#pragma omp depobj'
+/// directive.
+///
+/// \code
+/// #pragma omp depobj(a) destroy
+/// \endcode
+/// In this example directive '#pragma omp depobj' has 'destroy' clause.
+class OMPDestroyClause final : public OMPClause {
+public:
+  /// Build 'destroy' clause.
+  ///
+  /// \param StartLoc Starting location of the clause.
+  /// \param EndLoc Ending location of the clause.
+  OMPDestroyClause(SourceLocation StartLoc, SourceLocation EndLoc)
+  : OMPClause(OMPC_destroy, StartLoc, EndLoc) {}
+
+  /// Build an empty clause.
+  OMPDestroyClause()
+  : OMPClause(OMPC_destroy, SourceLocation(), SourceLocation()) {}
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == OMPC_destroy;
+  }
+};
+
 /// This class implements a simple visitor for OMPClause
 /// subclasses.
 template class Ptr, typename RetTy>

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index ceb49b48f77a..3dc9af4b8042 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3159,6 +3159,11 @@ bool 
RecursiveASTVisitor::VisitOMPNogroupClause(OMPNogroupClause *) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::VisitOMPDestroyClause(OMPDestroyClause *) {
+  return true;
+}
+
 template 
 template 
 bool RecursiveASTVisitor::VisitOMPClauseList(T *Node) {

diff  --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index 2954f7bf3df9..388204c3c193 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -276,6 +276,7 @@ OPENMP_CLAUSE(allocate, OMPAllocateClause)
 OPENMP_CLAUSE(nontemporal, OMPNontemporalClause)
 OPENMP_CLAUSE(order, OMPOrderClause)
 OPENMP_CLAUSE(depobj, OMPDepobjClause)
+OPENMP_CLAUSE(destroy, OMPDestroyClause)
 
 // Clauses allowed for OpenMP directive 'parallel'.
 OPENMP_PARALLEL_CLAUSE(if)
@@ -1084,6 +1085,7 @@ OPENMP_FLUSH_CLAUSE(release)
 
 // Clauses allowed for OpenMP directive 'depobj'.
 OPENMP_DEPOBJ_CLAUSE(depend)
+OPENMP_DEPOBJ_CLAUSE(destroy)
 
 #undef OPENMP_DEPOBJ_CLAUSE
 #undef OPENMP_FLUSH_CLAUSE

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 67680892e22a..9a3fc9585c98 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10344,6 +10344,9 @@ class Sema final {
   /// Called on well-formed 'relaxed' clause.
   OMPClause *ActOnOpenMPRelaxedClause(SourceLocation StartLoc,
   SourceLocation EndLoc);
+  /// Called on well-formed 'destroy' clause.
+  OMPClause *ActOnOpenMPDestroyClause(SourceLocation StartLoc,
+  SourceLocation EndLoc);
   /// Called on well-formed 'threads' clause.
   OMPClause *ActOnOpenMPThreadsClause(SourceLocation StartLoc,
   SourceLocation EndLoc);

diff  --git 

[PATCH] D75139: [hexagon] Pickup the default crt and libs when the musl target is selected

2020-03-02 Thread Sid Manning via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG637767665141: Add default paths to support musl target 
(authored by sidneym).

Changed prior to commit:
  https://reviews.llvm.org/D75139?vs=247251=247701#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75139

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/test/Driver/hexagon-toolchain-elf.c

Index: clang/test/Driver/hexagon-toolchain-elf.c
===
--- clang/test/Driver/hexagon-toolchain-elf.c
+++ clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,3 +597,69 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK084 %s
 // CHECK084:  "-fno-use-init-array"
+// -
+// Passing --musl
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK085 %s
+// CHECK085-NOT:  /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK085:  "/hexagon{{/|}}lib{{/|}}crt1.o"
+// CHECK085:  "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK085:  "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// -
+// Passing --musl --shared
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -shared \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK086 %s
+// CHECK086:"/hexagon{{/|}}lib{{/|}}Scrt1.o"
+// CHECK086:"-lclang_rt.builtins-hexagon" "-lc"
+// CHECK086-NOT:/hexagon{{/|}}lib{{/|}}crt1.o
+// CHECK086-NOT:-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1
+// -
+// Passing --musl -nostdlib
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostdlib \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK087 %s
+// CHECK087-NOT:   /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK087-NOT:   /hexagon{{/|}}lib{{/|}}crt1.o
+// CHECK087-NOT:   -lclang_rt.builtins-hexagon
+// CHECK087-NOT:   -lc
+// CHECK087:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// -
+// Passing --musl -nostartfiles
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostartfiles \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK088 %s
+// CHECK088-NOT:   /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK088-NOT:   /hexagon{{/|}}lib{{/|}}crt1.o
+// CHECK088:   "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK088:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// -
+// Passing --musl -nodefaultlibs
+// -
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nodefaultlibs \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK089 %s
+// CHECK089:   "/hexagon{{/|}}lib{{/|}}crt1.o"
+// CHECK089-NOT:   -lclang_rt.builtins-hexagon
+// CHECK089-NOT:   -lc
+// CHECK089:   "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -264,18 +264,41 @@
 UseG0 = G.getValue() == 0;
   }
 
-  //
-  //
-  //
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 
+  if (HTC.getTriple().isMusl()) {
+if (!Args.hasArg(options::OPT_shared, options::OPT_static))
+  

[clang] 6377676 - Add default paths to support musl target

2020-03-02 Thread Sid Manning via cfe-commits

Author: Sid Manning
Date: 2020-03-02T13:39:42-06:00
New Revision: 637767665141ae48c7a0558903bb29e03bf5ad6f

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

LOG: Add default paths to support musl target

Pickup the default crt and libs when the target is musl.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/test/Driver/hexagon-toolchain-elf.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 88523cd4bb1c..c069eefde9af 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -264,18 +264,41 @@ constructHexagonLinkArgs(Compilation , const JobAction 
,
 UseG0 = G.getValue() == 0;
   }
 
-  
//
-  //
-  
//
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 
+  if (HTC.getTriple().isMusl()) {
+if (!Args.hasArg(options::OPT_shared, options::OPT_static))
+  CmdArgs.push_back("-dynamic-linker=/lib/ld-musl-hexagon.so.1");
+
+if (!Args.hasArg(options::OPT_shared,
+ options::OPT_nostartfiles,
+ options::OPT_nostdlib))
+  CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/crt1.o"));
+else if (Args.hasArg(options::OPT_shared) &&
+ !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib))
+  CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/lib/Scrt1.o"));
+
+CmdArgs.push_back(
+Args.MakeArgString(StringRef("-L") + D.SysRoot + "/lib"));
+Args.AddAllArgs(CmdArgs,
+{options::OPT_T_Group, options::OPT_e, options::OPT_s,
+ options::OPT_t, options::OPT_u_Group});
+AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
+
+if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+  CmdArgs.push_back("-lclang_rt.builtins-hexagon");
+  CmdArgs.push_back("-lc");
+}
+
+return;
+  }
+
   
//
   // moslib
   
//
   std::vector OsLibs;
   bool HasStandalone = false;
-
   for (const Arg *A : Args.filtered(options::OPT_moslib_EQ)) {
 A->claim();
 OsLibs.emplace_back(A->getValue());

diff  --git a/clang/test/Driver/hexagon-toolchain-elf.c 
b/clang/test/Driver/hexagon-toolchain-elf.c
index 0a6c86424955..24daac05d612 100644
--- a/clang/test/Driver/hexagon-toolchain-elf.c
+++ b/clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,3 +597,69 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK084 %s
 // CHECK084:  "-fno-use-init-array"
+// 
-
+// Passing --musl
+// 
-
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK085 %s
+// CHECK085-NOT:  /hexagon{{/|}}lib{{/|}}Scrt1.o
+// CHECK085:  "/hexagon{{/|}}lib{{/|}}crt1.o"
+// CHECK085:  "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK085:  "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
+// 
-
+// Passing --musl --shared
+// 
-
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -shared \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK086 %s
+// CHECK086:"/hexagon{{/|}}lib{{/|}}Scrt1.o"
+// CHECK086:"-lclang_rt.builtins-hexagon" "-lc"
+// CHECK086-NOT:/hexagon{{/|}}lib{{/|}}crt1.o
+// CHECK086-NOT:-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1
+// 
-
+// Passing --musl -nostdlib
+// 
-
+// RUN: %clang -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   -mcpu=hexagonv60 \
+// RUN:   --sysroot=/hexagon -nostdlib \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK087 %s
+// CHECK087-NOT:   

[PATCH] D75387: [Sema] Look through OpaqueValueExpr when checking implicit conversions

2020-03-02 Thread Erik Pilkington via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe392dcd5708b: [Sema] Look through OpaqueValueExpr when 
checking implicit conversions (authored by erik.pilkington).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75387

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaObjC/signed-char-bool-conversion.m


Index: clang/test/SemaObjC/signed-char-bool-conversion.m
===
--- clang/test/SemaObjC/signed-char-bool-conversion.m
+++ clang/test/SemaObjC/signed-char-bool-conversion.m
@@ -69,6 +69,11 @@
   b = local.nested->unsigned_bf2; // expected-warning{{implicit conversion 
from integral type 'unsigned int' to 'BOOL'}}
 }
 
+void t4(BoolProp *bp) {
+  BOOL local = YES;
+  bp.p = 1 ? local : NO; // no warning
+}
+
 __attribute__((objc_root_class))
 @interface BFIvar {
   struct has_bf bf;
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -11587,7 +11587,16 @@
   if (E->isTypeDependent() || E->isValueDependent())
 return;
 
-  if (const auto *UO = dyn_cast(E))
+  Expr *SourceExpr = E;
+  // Examine, but don't traverse into the source expression of an
+  // OpaqueValueExpr, since it may have multiple parents and we don't want to
+  // emit duplicate diagnostics. Its fine to examine the form or attempt to
+  // evaluate it in the context of checking the specific conversion to T 
though.
+  if (auto *OVE = dyn_cast(E))
+if (auto *Src = OVE->getSourceExpr())
+  SourceExpr = Src;
+
+  if (const auto *UO = dyn_cast(SourceExpr))
 if (UO->getOpcode() == UO_Not &&
 UO->getSubExpr()->isKnownToHaveBooleanValue())
   S.Diag(UO->getBeginLoc(), diag::warn_bitwise_negation_bool)
@@ -11596,21 +11605,20 @@
 
   // For conditional operators, we analyze the arguments as if they
   // were being fed directly into the output.
-  if (isa(E)) {
-ConditionalOperator *CO = cast(E);
+  if (auto *CO = dyn_cast(SourceExpr)) {
 CheckConditionalOperator(S, CO, CC, T);
 return;
   }
 
   // Check implicit argument conversions for function calls.
-  if (CallExpr *Call = dyn_cast(E))
+  if (CallExpr *Call = dyn_cast(SourceExpr))
 CheckImplicitArgumentConversions(S, Call, CC);
 
   // Go ahead and check any implicit conversions we might have skipped.
   // The non-canonical typecheck is just an optimization;
   // CheckImplicitConversion will filter out dead implicit conversions.
-  if (E->getType() != T)
-CheckImplicitConversion(S, E, T, CC, nullptr, IsListInit);
+  if (SourceExpr->getType() != T)
+CheckImplicitConversion(S, SourceExpr, T, CC, nullptr, IsListInit);
 
   // Now continue drilling into this expression.
 


Index: clang/test/SemaObjC/signed-char-bool-conversion.m
===
--- clang/test/SemaObjC/signed-char-bool-conversion.m
+++ clang/test/SemaObjC/signed-char-bool-conversion.m
@@ -69,6 +69,11 @@
   b = local.nested->unsigned_bf2; // expected-warning{{implicit conversion from integral type 'unsigned int' to 'BOOL'}}
 }
 
+void t4(BoolProp *bp) {
+  BOOL local = YES;
+  bp.p = 1 ? local : NO; // no warning
+}
+
 __attribute__((objc_root_class))
 @interface BFIvar {
   struct has_bf bf;
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -11587,7 +11587,16 @@
   if (E->isTypeDependent() || E->isValueDependent())
 return;
 
-  if (const auto *UO = dyn_cast(E))
+  Expr *SourceExpr = E;
+  // Examine, but don't traverse into the source expression of an
+  // OpaqueValueExpr, since it may have multiple parents and we don't want to
+  // emit duplicate diagnostics. Its fine to examine the form or attempt to
+  // evaluate it in the context of checking the specific conversion to T though.
+  if (auto *OVE = dyn_cast(E))
+if (auto *Src = OVE->getSourceExpr())
+  SourceExpr = Src;
+
+  if (const auto *UO = dyn_cast(SourceExpr))
 if (UO->getOpcode() == UO_Not &&
 UO->getSubExpr()->isKnownToHaveBooleanValue())
   S.Diag(UO->getBeginLoc(), diag::warn_bitwise_negation_bool)
@@ -11596,21 +11605,20 @@
 
   // For conditional operators, we analyze the arguments as if they
   // were being fed directly into the output.
-  if (isa(E)) {
-ConditionalOperator *CO = cast(E);
+  if (auto *CO = dyn_cast(SourceExpr)) {
 CheckConditionalOperator(S, CO, CC, T);
 return;
   }
 
   // Check implicit argument conversions for function calls.
-  if (CallExpr *Call = dyn_cast(E))
+  if (CallExpr *Call = dyn_cast(SourceExpr))
 CheckImplicitArgumentConversions(S, Call, CC);
 
   // Go ahead and check any implicit conversions we might 

[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield updated this revision to Diff 247696.
JonChesterfield marked 2 inline comments as done.
JonChesterfield added a comment.

- Reject initialisers, update doc to recommended string


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/DeclBase.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-loader-uninitialized.c
  clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-loader-uninitialized.cpp

Index: clang/test/Sema/attr-loader-uninitialized.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-loader-uninitialized.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int good __attribute__((loader_uninitialized));
+
+const int still_cant_be_const __attribute__((loader_uninitialized)); // expected-error {{default initialization of an object of const type}}
+extern int external_should_be_rejected __attribute__((loader_uninitialized));
+
+int noargs __attribute__((loader_uninitialized(0))); // expected-error {{'loader_uninitialized' attribute takes no arguments}} 
+
+void func() __attribute__((loader_uninitialized)) // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
+{
+  int local __attribute__((loader_uninitialized)); // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
+
+  static int sl __attribute__((loader_uninitialized));
+}
+
+struct s {
+  __attribute__((loader_uninitialized)) int field; // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
+
+  static __attribute__((loader_uninitialized)) int sfield;
+
+} __attribute__((loader_uninitialized)); // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
+
+int redef_attr_first __attribute__((loader_uninitialized));
+int redef_attr_first;
+// expected-error@-1 {{redefinition of 'redef_attr_first'}}
+// expected-note@-3 {{previous definition is here}}
+
+int redef_attr_second; 
+int redef_attr_second __attribute__((loader_uninitialized)); 
+// expected-warning@-1 {{attribute declaration must precede definition}}
+// expected-note@-3 {{previous definition is here}}
+// expected-error@-3 {{redefinition of 'redef_attr_second'}}
+// expected-note@-5 {{previous definition is here}}
+
+int init_rejected __attribute__((loader_uninitialized)) = 42;
+// expected-error@-1 {{variable with 'loader_uninitialized' attribute cannot have an initializer}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -65,6 +65,7 @@
 // CHECK-NEXT: InitPriority (SubjectMatchRule_variable)
 // CHECK-NEXT: InternalLinkage (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
 // CHECK-NEXT: LTOVisibilityPublic (SubjectMatchRule_record)
+// CHECK-NEXT: LoaderUninitialized (SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: Lockable (SubjectMatchRule_record)
 // CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block)
 // CHECK-NEXT: MSStruct (SubjectMatchRule_record)
Index: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++11 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: @_ZZ4funcvE4data = internal global i32 undef
+int* func(void)
+{
+  static int data [[clang::loader_uninitialized]];
+  return 
+}
+
+// No code emitted
+extern int extern_unhelpful_but_harmless [[clang::loader_uninitialized]];
+
+// CHECK: @defn = global i32 undef
+int defn  [[clang::loader_uninitialized]];
+
+// CHECK: @_ZL11defn_static = internal global i32 undef
+static int defn_static [[clang::loader_uninitialized]] __attribute__((used));
+
+class trivial
+{
+  float x;
+};
+
+// CHECK: @ut = global %class.trivial undef
+trivial ut [[clang::loader_uninitialized]];
+
+struct nontrivial
+{
+  nontrivial() : x(3.14) {}
+  double x;
+};
+
+// CHECK: @unt = global %struct.nontrivial undef
+nontrivial unt [[clang::loader_uninitialized]];
+
+// CHECK: @arr = global [32 x double] undef, align 16
+double arr[32] __attribute__((loader_uninitialized));
+
+// Defining as arr2[] [[clang..]] raises the error: attribute cannot be applied to types
+// CHECK: 

[PATCH] D75447: [clangd] Make use of token buffers in semantic highlighting

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 247695.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75447

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -128,40 +129,41 @@
   return Result;
 }
 
+// For a macro usage `DUMP(foo)`, we want:
+//  - DUMP --> "macro"
+//  - foo --> "variable".
+SourceLocation getHighlightableSpellingToken(SourceLocation L,
+ const SourceManager ) {
+  if (L.isFileID())
+return SM.isWrittenInMainFile(L) ? L : SourceLocation{};
+  // Tokens expanded from the macro body contribute no highlightings.
+  if (!SM.isMacroArgExpansion(L))
+return {};
+  // Tokens expanded from macro args are potentially highlightable.
+  return getHighlightableSpellingToken(SM.getImmediateSpellingLoc(L), SM);
+}
+
 /// Consumes source locations and maps them to text ranges for highlightings.
 class HighlightingsBuilder {
 public:
-  HighlightingsBuilder(const SourceManager ,
-   const LangOptions )
-  : SourceMgr(SourceMgr), LangOpts(LangOpts) {}
+  HighlightingsBuilder(const ParsedAST )
+  : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
+LangOpts(AST.getLangOpts()) {}
 
   void addToken(HighlightingToken T) { Tokens.push_back(T); }
 
   void addToken(SourceLocation Loc, HighlightingKind Kind) {
+Loc = getHighlightableSpellingToken(Loc, SourceMgr);
 if (Loc.isInvalid())
   return;
-if (Loc.isMacroID()) {
-  // Only intereseted in highlighting arguments in macros (DEF_X(arg)).
-  if (!SourceMgr.isMacroArgExpansion(Loc))
-return;
-  Loc = SourceMgr.getSpellingLoc(Loc);
-}
-
-// Non top level decls that are included from a header are not filtered by
-// topLevelDecls. (example: method declarations being included from
-// another file for a class from another file).
-// There are also cases with macros where the spelling loc will not be in
-// the main file and the highlighting would be incorrect.
-if (!isInsideMainFile(Loc, SourceMgr))
-  return;
-
-auto Range = getTokenRange(SourceMgr, LangOpts, Loc);
-if (!Range) {
-  // R should always have a value, if it doesn't something is very wrong.
-  elog("Tried to add semantic token with an invalid range");
-  return;
-}
-Tokens.push_back(HighlightingToken{Kind, *Range});
+const auto *Tok = llvm::partition_point(
+TB.spelledTokens(SourceMgr.getMainFileID()),
+[&](const syntax::Token ) { return Tok.location() < Loc; });
+assert(Tok);
+
+auto Range = halfOpenToRange(SourceMgr,
+ Tok->range(SourceMgr).toCharRange(SourceMgr));
+Tokens.push_back(HighlightingToken{Kind, std::move(Range)});
   }
 
   std::vector collect(ParsedAST ) && {
@@ -211,6 +213,7 @@
   }
 
 private:
+  const syntax::TokenBuffer 
   const SourceManager 
   const LangOptions 
   std::vector Tokens;
@@ -311,7 +314,7 @@
 std::vector getSemanticHighlightings(ParsedAST ) {
   auto  = AST.getASTContext();
   // Add highlightings for AST nodes.
-  HighlightingsBuilder Builder(AST.getSourceManager(), C.getLangOpts());
+  HighlightingsBuilder Builder(AST);
   // Highlight 'decltype' and 'auto' as their underlying types.
   CollectExtraHighlightings(Builder).TraverseAST(C);
   // Highlight all decls and references coming from the AST.


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -128,40 +129,41 @@
   return Result;
 }
 
+// For a macro usage `DUMP(foo)`, we want:
+//  - DUMP --> "macro"
+//  - foo --> "variable".
+SourceLocation getHighlightableSpellingToken(SourceLocation L,
+ const SourceManager ) {
+  if (L.isFileID())
+return SM.isWrittenInMainFile(L) ? L : SourceLocation{};
+  // Tokens expanded from the macro body contribute no highlightings.
+  if 

[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp:23
+// CHECK: @nominally_value_init = global i32 undef
+int nominally_value_init  [[clang::loader_uninitialized]] = 4;
+

This test case is identical to line 36 of 
clang/test/Sema/attr-loader-uninitialized.cpp, where you say you don't want it 
to compile at all.

I think you need a clearer idea of how this interacts with initializers. Is it 
merely supposed to eliminate the //zero-initialization// that happens before 
the user-specified construction/initialization, or is it supposed to compete 
with the user-specified construction/initialization?

That is, for

nontrivial unt [[clang::loader_uninitialized]];

is it merely supposed to call `unt::unt()` on a chunk of undef memory (instead 
of the usual chunk of zeroed memory), or is it supposed to skip the constructor 
entirely? And for

int x [[clang::loader_uninitialized]] = foo();

is it merely supposed to call `foo()` and assign the result to a chunk of undef 
memory (instead of the usual chunk of zeroed memory), or is it supposed to skip 
the initialization entirely?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-03-02 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added inline comments.



Comment at: clang/test/CodeGenCXX/lto-visibility-inference.cpp:73
   c1->f();
-  // ITANIUM-NOT: type.test{{.*}}!"_ZTS2C2"
+  // ITANIUM: type.test{{.*}}!"_ZTS2C2"
   // MS: type.test{{.*}}!"?AUC2@@"

tejohnson wrote:
> evgeny777 wrote:
> > tejohnson wrote:
> > > evgeny777 wrote:
> > > > tejohnson wrote:
> > > > > evgeny777 wrote:
> > > > > > What caused this and other changes in this file?
> > > > > Because we now will insert type tests for non-hidden vtables. This is 
> > > > > enabled by the changes to LTO to interpret these based on the 
> > > > > vcall_visibility metadata.
> > > > The results of this test case
> > > > ```
> > > > %clang_cc1 -flto -triple x86_64-pc-windows-msvc -std=c++11 
> > > > -fms-extensions -fwhole-program-vtables -flto-visibility-public-std 
> > > > -emit-llvm -o - %s | FileCheck --check-prefix=MS 
> > > > --check-prefix=MS-NOSTD %s
> > > > ```
> > > > look not correct to me. I think you shouldn't generate type tests for 
> > > > standard library classes with  `-flto-visibility-public-std`. Currently 
> > > > if this flag is given, clang doesn't do this either even with 
> > > > `-fvisibility=hidden`
> > > The associated vtables would get the vcall_visibility public metadata, so 
> > > the type tests themselves aren't problematic. I tend to think that an 
> > > application using such options should simply stick with 
> > > -fvisibility=hidden to get WPD and not use the new LTO option to convert 
> > > all public vcall_visibility metadata to hidden.
> > > The associated vtables would get the vcall_visibility public metadata, so 
> > > the type tests themselves aren't problematic. I tend to think that an 
> > > application using such options should simply stick with 
> > > -fvisibility=hidden to get WPD and not use the new LTO option to convert 
> > > all public vcall_visibility metadata to hidden.
> > 
> > I see two issues here:
> > 1) It's not always good option to force hidden visibility for everything. 
> > For instance I work on proprietary platform which demands public visibility 
> > for certain symbols in order for dynamic loader to work properly. In this 
> > context your patch does a great job.
> > 
> > 2) Standard library is almost never LTOed so in general we can't narrow 
> > std::* vtables visibility to linkage unit
> > 
> > Is there anything which prevents from implementing the same functionality 
> > with new -lto-whole-program-visibility option (i.e without forcing hidden 
> > visibility)? In other words the following looks good to me:
> > 
> > ```
> > # Compile with lto/devirtualization support
> > clang -flto=thin -flto-visibility-public-std -fwhole-program-vtables -c 
> > *.cpp
> > 
> > # Link: everything is devirtualized except standard library classes virtual 
> > methods
> > clang -Wl,-lto-whole-program-visibility -fuse-ld=lld *.o
> > ```
> Ok, thanks for the info. I will go ahead and change the code to not insert 
> the type tests in this case to support this usage.
> 
> Ultimately, I would like to decouple the existence of the type tests from 
> visibility implications. I'm working on another change to delay 
> lowering/removal of type tests until after indirect call promotion, so we can 
> use them in other cases (streamlined indirect call promotion checks against 
> the vtable instead of the function pointers, also useful if we want to 
> implement speculative devirtualization based on WPD info). In those cases we 
> need the type tests, either to locate information in the summary, or to get 
> the address point offset for a vtable address compare. In that case it would 
> be helpful to have the type tests in this type of code as well. So we'll need 
> another way to communicate down to WPD that they should never be 
> devirtualized. But I don't think it makes sense to design this support until 
> there is a concrete use case and need. In the meantime I will change the code 
> to be conservative and not insert the type tests in this case.
Note that `-flto-visibility-public-std` is a cc1-only option and only used on 
Windows, and further that `-lto-whole-program-visibility` as implemented 
doesn't really make sense on Windows because the classes with public visibility 
are going to be marked dllimport/dllexport/uuid (COM), and 
`-lto-whole-program-visibility` corresponds to flags such as `--version-script` 
or the absence of `-shared` in which the linker automatically relaxes the 
visibility of some symbols, while there is no such concept of relaxing symbol 
visibility on Windows.

 I would be inclined to remove this support and either let the public 
visibility automatically derive from the absence of 
`-lto-whole-program-visibility` at link time in COFF links or omit the IR 
needed to support `lto-whole-program-visibility` on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71913




[PATCH] D75474: [clangd] Get rid of getTokenRange helper

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov, mgorny.
Herald added a project: clang.
kadircet added a parent revision: D75447: [clangd] Make use of token buffers in 
semantic highlighting.
kadircet added a parent revision: D75446: [clang][Syntax] Handle macro 
arguments in spelledForExpanded.

There's only one caller left in CollectMacros, which doesn't have
access to TokenBuffers. I believe we should just stop computing ranges in there,
and collect offsets instead. Later on we can convert them to Ranges when we've
got access to TokenBuffers. As those ranges are never used without a ParsedAST.
But leaving it out for now to keep the patch minimal.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75474

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -152,7 +152,12 @@
 llvm::Optional makeLocation(ASTContext , SourceLocation TokLoc,
   llvm::StringRef TUPath) {
   const SourceManager  = AST.getSourceManager();
-  const FileEntry *F = SourceMgr.getFileEntryForID(SourceMgr.getFileID(TokLoc));
+  auto Tok = syntax::tokenize(syntax::FileRange(SourceMgr, TokLoc, 1),
+  SourceMgr, AST.getLangOpts());
+  if (Tok.empty())
+return None;
+  auto Range = Tok.front().range(SourceMgr);
+  const FileEntry *F = SourceMgr.getFileEntryForID(Range.file());
   if (!F)
 return None;
   auto FilePath = getCanonicalPath(F, SourceMgr);
@@ -160,14 +165,10 @@
 log("failed to get path!");
 return None;
   }
-  if (auto Range =
-  getTokenRange(AST.getSourceManager(), AST.getLangOpts(), TokLoc)) {
-Location L;
-L.uri = URIForFile::canonicalize(*FilePath, TUPath);
-L.range = *Range;
-return L;
-  }
-  return None;
+  Location L;
+  L.uri = URIForFile::canonicalize(*FilePath, TUPath);
+  L.range = halfOpenToRange(SourceMgr, Range.toCharRange(SourceMgr));
+  return L;
 }
 
 } // namespace
@@ -351,11 +352,11 @@
 class ReferenceFinder : public index::IndexDataConsumer {
 public:
   struct Reference {
-SourceLocation Loc;
+syntax::Token Tok;
 index::SymbolRoleSet Role;
   };
 
-  ReferenceFinder(ASTContext , Preprocessor ,
+  ReferenceFinder(const ParsedAST ,
   const std::vector )
   : AST(AST) {
 for (const NamedDecl *D : TargetDecls)
@@ -364,13 +365,17 @@
 
   std::vector take() && {
 llvm::sort(References, [](const Reference , const Reference ) {
-  return std::tie(L.Loc, L.Role) < std::tie(R.Loc, R.Role);
+  auto LTok = L.Tok.location();
+  auto RTok = R.Tok.location();
+  return std::tie(LTok, L.Role) < std::tie(RTok, R.Role);
 });
 // We sometimes see duplicates when parts of the AST get traversed twice.
 References.erase(std::unique(References.begin(), References.end(),
  [](const Reference , const Reference ) {
-   return std::tie(L.Loc, L.Role) ==
-  std::tie(R.Loc, R.Role);
+   auto LTok = L.Tok.location();
+   auto RTok = R.Tok.location();
+   return std::tie(LTok, L.Role) ==
+  std::tie(RTok, R.Role);
  }),
  References.end());
 return std::move(References);
@@ -382,22 +387,27 @@
SourceLocation Loc,
index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
 assert(D->isCanonicalDecl() && "expect D to be a canonical declaration");
+if (!CanonicalTargets.count(D))
+  return true;
+const auto  = AST.getTokens();
 const SourceManager  = AST.getSourceManager();
-Loc = SM.getFileLoc(Loc);
-if (isInsideMainFile(Loc, SM) && CanonicalTargets.count(D))
-  References.push_back({Loc, Roles});
+auto Toks = TB.spelledForExpanded(TB.expandedTokens(Loc));
+if (!Toks || Toks->empty() ||
+!isInsideMainFile(Toks->front().location(), SM))
+  return true;
+References.push_back({Toks->front(), Roles});
 return true;
   }
 
 private:
   llvm::SmallSet CanonicalTargets;
   std::vector References;
-  const ASTContext 
+  const ParsedAST 
 };
 
 std::vector
 findRefs(const std::vector , ParsedAST ) {
-  ReferenceFinder RefFinder(AST.getASTContext(), AST.getPreprocessor(), Decls);
+  ReferenceFinder RefFinder(AST, Decls);
   

[PATCH] D75423: [OpenCL] Mark pointers to constant address space as invariant

2020-03-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D75423#1901407 , @yaxunl wrote:

> In D75423#1901362 , @rjmccall wrote:
>
> > Okay, then I have no problem taking a patch for this into IRGen.  But I 
> > think it should be fine to do this by adding the invariant-load metadata 
> > when loading from an l-value instead of injecting invariant-groups into 
> > l-value emission.
>
>
> The pointer to constant may be casted to a generic pointer then loaded. If we 
> only mark load from pointer to constant, we loses information.


A lot of those conversions don't go through `EmitLValue`.

Doing this at this level in `EmitLValue` both complicates the code and will 
introduce a lot of redundant intrinsic calls.  If you need to do it, you should 
do it at the root where a pointer is being turned into an LValue.


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

https://reviews.llvm.org/D75423



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


[PATCH] D75194: [clang-format] Do not merge very long C# automatic properties

2020-03-02 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe planned changes to this revision.
jbcoe added a comment.

I will try to handle this in unwrapped line parser.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75194



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


[PATCH] D75473: [clang-format] parse C# object initialisers

2020-03-02 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe created this revision.
jbcoe added a reviewer: krasimir.
jbcoe added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Treat C# object initializers as braced lists.

Allow lambdas inside C# braced lists.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75473

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -537,6 +537,14 @@
  Colour = Colours.Yellow,
  } };)",
Style);
+
+  // Lambdas can be supplied as initialiser arguments.
+  verifyFormat(R"(//
+private Transformer _transformer = new X.Y {
+Filler = (Shape shape) => { return new Transform.Fill(shape, RED); },
+Scaler = (Shape shape) => { return new Transform.Resize(shape, 0.1); },
+};)",
+   Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNamedArguments) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1623,6 +1623,17 @@
   // FIXME: Once we have an expression parser in the UnwrappedLineParser,
   // replace this by using parseAssigmentExpression() inside.
   do {
+if (Style.isCSharp()) {
+  if (FormatTok->is(TT_JsFatArrow)) {
+nextToken();
+// Fat arrows can be followed by simple expressions or by child blocks
+// in curly braces.
+if (FormatTok->is(tok::l_brace)) {
+  parseChildBlock();
+  continue;
+}
+  }
+}
 if (Style.Language == FormatStyle::LK_JavaScript) {
   if (FormatTok->is(Keywords.kw_function) ||
   FormatTok->startsSequence(Keywords.kw_async, Keywords.kw_function)) {
@@ -1946,7 +1957,7 @@
  DeclarationScopeStack.size() > 1);
 parseBlock(/*MustBeDeclaration=*/true, AddLevel);
 // Munch the semicolon after a namespace. This is more common than one 
would
-// think. Puttin the semicolon into its own line is very ugly.
+// think. Putting the semicolon into its own line is very ugly.
 if (FormatTok->Tok.is(tok::semi))
   nextToken();
 addUnwrappedLine();
@@ -1957,6 +1968,22 @@
 void UnwrappedLineParser::parseNew() {
   assert(FormatTok->is(tok::kw_new) && "'new' expected");
   nextToken();
+
+  if (Style.isCSharp()) {
+do {
+  if (FormatTok->is(tok::l_brace))
+parseBracedList();
+
+  if (FormatTok->is(tok::l_paren))
+parseParens();
+
+  if (FormatTok->isOneOf(tok::semi, tok::comma))
+return;
+
+  nextToken();
+} while (!eof());
+  }
+
   if (Style.Language != FormatStyle::LK_Java)
 return;
 


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -537,6 +537,14 @@
  Colour = Colours.Yellow,
  } };)",
Style);
+
+  // Lambdas can be supplied as initialiser arguments.
+  verifyFormat(R"(//
+private Transformer _transformer = new X.Y {
+Filler = (Shape shape) => { return new Transform.Fill(shape, RED); },
+Scaler = (Shape shape) => { return new Transform.Resize(shape, 0.1); },
+};)",
+   Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNamedArguments) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1623,6 +1623,17 @@
   // FIXME: Once we have an expression parser in the UnwrappedLineParser,
   // replace this by using parseAssigmentExpression() inside.
   do {
+if (Style.isCSharp()) {
+  if (FormatTok->is(TT_JsFatArrow)) {
+nextToken();
+// Fat arrows can be followed by simple expressions or by child blocks
+// in curly braces.
+if (FormatTok->is(tok::l_brace)) {
+  parseChildBlock();
+  continue;
+}
+  }
+}
 if (Style.Language == FormatStyle::LK_JavaScript) {
   if (FormatTok->is(Keywords.kw_function) ||
   FormatTok->startsSequence(Keywords.kw_async, Keywords.kw_function)) {
@@ -1946,7 +1957,7 @@
  DeclarationScopeStack.size() > 1);
 parseBlock(/*MustBeDeclaration=*/true, AddLevel);
 // Munch the semicolon after a namespace. This is more common than one would
-// think. Puttin the semicolon into its own line is very ugly.
+// think. Putting the semicolon into its own line is very ugly.
 if (FormatTok->Tok.is(tok::semi))
   nextToken();
 

[PATCH] D75402: [HIP] Make sure, unused hip-pinned-shadow global var is kept within device code

2020-03-02 Thread Mahesha S via Phabricator via cfe-commits
hsmhsm updated this revision to Diff 247689.
hsmhsm added a comment.

Take care review comments by hliao.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75402

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGenCUDA/hip-pinned-shadow.cu


Index: clang/test/CodeGenCUDA/hip-pinned-shadow.cu
===
--- clang/test/CodeGenCUDA/hip-pinned-shadow.cu
+++ clang/test/CodeGenCUDA/hip-pinned-shadow.cu
@@ -4,6 +4,8 @@
 // RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPDEV %s
 // RUN: %clang_cc1 -triple x86_64 -std=c++11 \
 // RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPHOST %s
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 -fvisibility 
hidden -fapply-global-visibility-to-externs \
+// RUN: -O3 -emit-llvm -o - -x hip %s | FileCheck 
-check-prefixes=HIPDEVUNSED %s
 
 struct textureReference {
   int a;
@@ -21,3 +23,5 @@
 // HIPDEV-NOT: declare{{.*}}void @_ZN7textureIfLi2ELi1EEC1Ev
 // HIPHOST:  define{{.*}}@_ZN7textureIfLi2ELi1EEC1Ev
 // HIPHOST:  call i32 @__hipRegisterVar{{.*}}@tex{{.*}}i32 0, i32 4, i32 0, 
i32 0)
+// HIPDEVUNSED: @tex = external addrspace(1) global %struct.texture
+// HIPDEVUNSED-NOT: declare{{.*}}void @_ZN7textureIfLi2ELi1EEC1Ev
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1037,7 +1037,7 @@
   void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
 
   /// Add a global to a list to be added to the llvm.used metadata.
-  void addUsedGlobal(llvm::GlobalValue *GV);
+  void addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck = false);
 
   /// Add a global to a list to be added to the llvm.compiler.used metadata.
   void addCompilerUsedGlobal(llvm::GlobalValue *GV);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1916,9 +1916,9 @@
   }
 }
 
-void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {
-  assert(!GV->isDeclaration() &&
- "Only globals with definition can force usage.");
+void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck) {
+  assert(SkipCheck || (!GV->isDeclaration() &&
+   "Only globals with definition can force usage."));
   LLVMUsed.emplace_back(GV);
 }
 
@@ -4071,9 +4071,17 @@
 }
   }
 
-  if (!IsHIPPinnedShadowVar)
+  // HIPPinnedShadowVar should remain in the final code object irrespective of
+  // whether it is used or not within the code. Add it to used list, so that
+  // it will not get eliminated when it is unused. Also, it is an extern var
+  // within device code, and it should *not* get initialized within device 
code.
+  if (IsHIPPinnedShadowVar)
+addUsedGlobal(GV, /*SkipCheck=*/true);
+  else
 GV->setInitializer(Init);
-  if (emitter) emitter->finalize(GV);
+
+  if (emitter)
+emitter->finalize(GV);
 
   // If it is safe to mark the global 'constant', do so now.
   GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&


Index: clang/test/CodeGenCUDA/hip-pinned-shadow.cu
===
--- clang/test/CodeGenCUDA/hip-pinned-shadow.cu
+++ clang/test/CodeGenCUDA/hip-pinned-shadow.cu
@@ -4,6 +4,8 @@
 // RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPDEV %s
 // RUN: %clang_cc1 -triple x86_64 -std=c++11 \
 // RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPHOST %s
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 -fvisibility hidden -fapply-global-visibility-to-externs \
+// RUN: -O3 -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPDEVUNSED %s
 
 struct textureReference {
   int a;
@@ -21,3 +23,5 @@
 // HIPDEV-NOT: declare{{.*}}void @_ZN7textureIfLi2ELi1EEC1Ev
 // HIPHOST:  define{{.*}}@_ZN7textureIfLi2ELi1EEC1Ev
 // HIPHOST:  call i32 @__hipRegisterVar{{.*}}@tex{{.*}}i32 0, i32 4, i32 0, i32 0)
+// HIPDEVUNSED: @tex = external addrspace(1) global %struct.texture
+// HIPDEVUNSED-NOT: declare{{.*}}void @_ZN7textureIfLi2ELi1EEC1Ev
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1037,7 +1037,7 @@
   void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
 
   /// Add a global to a list to be added to the llvm.used metadata.
-  void addUsedGlobal(llvm::GlobalValue *GV);
+  void addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck = false);
 
   /// Add a global to a list to be added to the llvm.compiler.used metadata.
   void addCompilerUsedGlobal(llvm::GlobalValue *GV);
Index: 

[clang] e392dcd - [Sema] Look through OpaqueValueExpr when checking implicit conversions

2020-03-02 Thread Erik Pilkington via cfe-commits

Author: Erik Pilkington
Date: 2020-03-02T11:24:36-08:00
New Revision: e392dcd5708b3bb188ff4043b09ae151472a7632

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

LOG: [Sema] Look through OpaqueValueExpr when checking implicit conversions

Specifically, this fixes a false-positive in -Wobjc-signed-char-bool.
rdar://57372317

Differential revision: https://reviews.llvm.org/D75387

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaObjC/signed-char-bool-conversion.m

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2a66303d6d9a..cda6910364e5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -11587,7 +11587,16 @@ static void AnalyzeImplicitConversions(Sema , Expr 
*OrigE, SourceLocation CC,
   if (E->isTypeDependent() || E->isValueDependent())
 return;
 
-  if (const auto *UO = dyn_cast(E))
+  Expr *SourceExpr = E;
+  // Examine, but don't traverse into the source expression of an
+  // OpaqueValueExpr, since it may have multiple parents and we don't want to
+  // emit duplicate diagnostics. Its fine to examine the form or attempt to
+  // evaluate it in the context of checking the specific conversion to T 
though.
+  if (auto *OVE = dyn_cast(E))
+if (auto *Src = OVE->getSourceExpr())
+  SourceExpr = Src;
+
+  if (const auto *UO = dyn_cast(SourceExpr))
 if (UO->getOpcode() == UO_Not &&
 UO->getSubExpr()->isKnownToHaveBooleanValue())
   S.Diag(UO->getBeginLoc(), diag::warn_bitwise_negation_bool)
@@ -11596,21 +11605,20 @@ static void AnalyzeImplicitConversions(Sema , Expr 
*OrigE, SourceLocation CC,
 
   // For conditional operators, we analyze the arguments as if they
   // were being fed directly into the output.
-  if (isa(E)) {
-ConditionalOperator *CO = cast(E);
+  if (auto *CO = dyn_cast(SourceExpr)) {
 CheckConditionalOperator(S, CO, CC, T);
 return;
   }
 
   // Check implicit argument conversions for function calls.
-  if (CallExpr *Call = dyn_cast(E))
+  if (CallExpr *Call = dyn_cast(SourceExpr))
 CheckImplicitArgumentConversions(S, Call, CC);
 
   // Go ahead and check any implicit conversions we might have skipped.
   // The non-canonical typecheck is just an optimization;
   // CheckImplicitConversion will filter out dead implicit conversions.
-  if (E->getType() != T)
-CheckImplicitConversion(S, E, T, CC, nullptr, IsListInit);
+  if (SourceExpr->getType() != T)
+CheckImplicitConversion(S, SourceExpr, T, CC, nullptr, IsListInit);
 
   // Now continue drilling into this expression.
 

diff  --git a/clang/test/SemaObjC/signed-char-bool-conversion.m 
b/clang/test/SemaObjC/signed-char-bool-conversion.m
index 6945d86fc26d..183f60fafcd5 100644
--- a/clang/test/SemaObjC/signed-char-bool-conversion.m
+++ b/clang/test/SemaObjC/signed-char-bool-conversion.m
@@ -69,6 +69,11 @@ void t3(struct has_bf *bf) {
   b = local.nested->unsigned_bf2; // expected-warning{{implicit conversion 
from integral type 'unsigned int' to 'BOOL'}}
 }
 
+void t4(BoolProp *bp) {
+  BOOL local = YES;
+  bp.p = 1 ? local : NO; // no warning
+}
+
 __attribute__((objc_root_class))
 @interface BFIvar {
   struct has_bf bf;



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


[clang] c112e94 - [OPENMP50]Add basic support for depobj construct.

2020-03-02 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-03-02T13:10:32-05:00
New Revision: c112e941a0c5d3b3423272c3f0024cdf6b50e44e

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

LOG: [OPENMP50]Add basic support for depobj construct.

Added basic parsing/sema/serialization support for depobj directive.

Added: 
clang/test/OpenMP/depobj_ast_print.cpp
clang/test/OpenMP/depobj_messages.cpp

Modified: 
clang/include/clang-c/Index.h
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/AST/StmtOpenMP.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtOpenMP.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/OpenMP/allocate_allocator_messages.cpp
clang/test/OpenMP/flush_messages.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index efb96f3cc5b6..9d4930a3887a 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2574,7 +2574,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPParallelMasterDirective  = 285,
 
-  CXCursor_LastStmt = CXCursor_OMPParallelMasterDirective,
+  /** OpenMP depobj directive.
+   */
+  CXCursor_OMPDepobjDirective = 286,
+
+  CXCursor_LastStmt = CXCursor_OMPDepobjDirective,
 
   /**
* Cursor that represents the translation unit itself.

diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 453c068bbeb0..5d78e9015b0f 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -4108,6 +4108,92 @@ class OMPFlushClause final
   }
 };
 
+/// This represents implicit clause 'depobj' for the '#pragma omp depobj'
+/// directive.
+/// This clause does not exist by itself, it can be only as a part of 'omp
+/// depobj' directive. This clause is introduced to keep the original structure
+/// of \a OMPExecutableDirective class and its derivatives and to use the
+/// existing infrastructure of clauses with the list of variables.
+///
+/// \code
+/// #pragma omp depobj(a) destroy
+/// \endcode
+/// In this example directive '#pragma omp depobj' has implicit clause 'depobj'
+/// with the depobj 'a'.
+class OMPDepobjClause final : public OMPClause {
+  friend class OMPClauseReader;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// Chunk size.
+  Expr *Depobj = nullptr;
+
+  /// Build clause with number of variables \a N.
+  ///
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc,
+  SourceLocation EndLoc)
+  : OMPClause(OMPC_depobj, StartLoc, EndLoc), LParenLoc(LParenLoc) {}
+
+  /// Build an empty clause.
+  ///
+  explicit OMPDepobjClause()
+  : OMPClause(OMPC_depobj, SourceLocation(), SourceLocation()) {}
+
+  void setDepobj(Expr *E) { Depobj = E; }
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+public:
+  /// Creates clause.
+  ///
+  /// \param C AST context.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  /// \param Depobj depobj expression associated with the 'depobj' directive.
+  static OMPDepobjClause *Create(const ASTContext , SourceLocation StartLoc,
+ SourceLocation LParenLoc,
+ SourceLocation EndLoc, Expr *Depobj);
+
+  /// Creates an empty clause.
+  ///
+  /// \param C AST context.
+  static OMPDepobjClause *CreateEmpty(const ASTContext );
+
+  /// Returns depobj expression associated with the clause.
+  Expr *getDepobj() { return 

[PATCH] D74500: clang: Treat ieee mode as the default for denormal-fp-math

2020-03-02 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added inline comments.



Comment at: llvm/include/llvm/ADT/FloatingPointMode.h:48
 
-  DenormalMode() = default;
-  DenormalMode(DenormalModeKind Out, DenormalModeKind In) :
+  constexpr DenormalMode() = default;
+  constexpr DenormalMode(DenormalModeKind Out, DenormalModeKind In) :

Can these constexpr diffs be separated out as an NFC preliminary commit?


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

https://reviews.llvm.org/D74500



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


[PATCH] D73720: [Analyzer] Use note tags to track container begin and and changes

2020-03-02 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus requested changes to this revision.
Szelethus added a comment.
This revision now requires changes to proceed.

Apologies -- I'd definitely prefer to address the debug related changes in a 
separate pack, similarly to D74541 .


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

https://reviews.llvm.org/D73720



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


[PATCH] D74541: [Analyzer] Use note tags to track iterator increments and decrements

2020-03-02 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

See my related comment here: D73720#1901453 
.


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

https://reviews.llvm.org/D74541



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


[PATCH] D73720: [Analyzer] Use note tags to track container begin and and changes

2020-03-02 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D73720#1874014 , 
@baloghadamsoftware wrote:

> In case of multiple container-related bugs only mark the container 
> interesting on the correct bug path. Also a typo fixed.


~~Uh-oh, I'm not sure why this would ever be an issue? Interestingness is a 
property of a given `BugReport`, not the `BugReporter` class. How can this 
interfere with one another?~~

Okay I see what the issue is. `DebugContainerModeling` normally doesn't emit a 
report, only adds notes on interesting containers. Though it still makes me 
wonder whether this is the right approach.

First, I think changes to the `DebugContainerModeling` seems to spawn a 
different discussion, and separating it to a different patch might make for a 
satisfying splitting point. The rest of the patch seems to be ready to land in 
my opinion. Also, this functionality seems to be duplicated in 
`DebugIteratorModeling` in D74541 , is this 
intended?

Second, that issue may be more appropriately solved by introducing a new debug 
interestingness kind (D65723 ), and just make 
the parameters of `clang_analyzer_express` interesting in the debug sense. If 
we did that, `DebugContainerModeling` could ask whether the symbol is 
debug-interesting instead of the `SourceRange` hackery. WDYT?


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

https://reviews.llvm.org/D73720



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


[PATCH] D75423: [OpenCL] Mark pointers to constant address space as invariant

2020-03-02 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 247688.
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

revised by John's comments.


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

https://reviews.llvm.org/D75423

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGenOpenCL/invariant.cl
  clang/test/CodeGenOpenCL/printf.cl

Index: clang/test/CodeGenOpenCL/printf.cl
===
--- clang/test/CodeGenOpenCL/printf.cl
+++ clang/test/CodeGenOpenCL/printf.cl
@@ -12,25 +12,25 @@
 
 
 // ALL-LABEL: @test_printf_float2(
-// FP64: %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([7 x i8], [7 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %0)
+// FP64: %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([7 x i8], [7 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float>
 
 
-// NOFP64:  call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([7 x i8], [7 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %0)
+// NOFP64:  call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([7 x i8], [7 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float>
 kernel void test_printf_float2(float2 arg) {
   printf("%v2hlf", arg);
 }
 
 // ALL-LABEL: @test_printf_half2(
-// FP64:  %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str.1, i32 0, i32 0), <2 x half> %0)
+// FP64:  %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str.1, i32 0, i32 0), <2 x half>
 
-// NOFP64:  %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str.1, i32 0, i32 0), <2 x half> %0)
+// NOFP64:  %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str.1, i32 0, i32 0), <2 x half>
 kernel void test_printf_half2(half2 arg) {
   printf("%v2hf", arg);
 }
 
 #ifdef cl_khr_fp64
 // FP64-LABEL: @test_printf_double2(
-// FP64: call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str.2, i32 0, i32 0), <2 x double> %0)
+// FP64: call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str.2, i32 0, i32 0), <2 x double>
 kernel void test_printf_double2(double2 arg) {
   printf("%v2lf", arg);
 }
Index: clang/test/CodeGenOpenCL/invariant.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/invariant.cl
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -O3 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple spir -O3 -emit-llvm -o - %s | FileCheck %s
+
+typedef struct {
+  int a;
+  char b;
+} X;
+
+constant X x = {0, 'a'};
+
+constant char* constant p = &(x.b);
+
+constant X* foo();
+
+// CHECK-LABEL: test1
+// CHECK: llvm.invariant.start
+char test1() {
+  return x.b;
+}
+
+// CHECK-LABEL: test2
+// CHECK: llvm.invariant.start
+char test2() {
+  return *p;
+}
+
+// CHECK-LABEL: test3
+// CHECK: llvm.invariant.start
+char test3(constant X *x) {
+  constant char *p = &(x->b);
+  return *p;
+}
+
+// CHECK-LABEL: test4
+// CHECK: llvm.invariant.start
+char test4() {
+  return foo()->b;
+}
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -4070,7 +4070,7 @@
 llvm::GlobalVariable *GV);
 
   // Emit an @llvm.invariant.start call for the given memory region.
-  void EmitInvariantStart(llvm::Constant *Addr, CharUnits Size);
+  void EmitInvariantStart(llvm::Value *Addr, CharUnits Size);
 
   /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++
   /// variable with global storage.
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -262,7 +262,17 @@
   const BinOpInfo );
 
   Value *EmitLoadOfLValue(LValue LV, SourceLocation Loc) {
-return CGF.EmitLoadOfLValue(LV, Loc).getScalarVal();
+auto *V = CGF.EmitLoadOfLValue(LV, Loc).getScalarVal();
+// Mark a pointer to OpenCL constant address space as invariant.
+auto QT = LV.getType();
+if (QT->isPointerType()) {
+  auto PointeeTy = QT->getPointeeType();
+  if (PointeeTy.getAddressSpace() == LangAS::opencl_constant) {
+

[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7436
+  case ParsedAttr::AT_LoaderUninitialized:
+handleLoaderUninitializedAttr(S, D, AL);
+break;

rjmccall wrote:
> JonChesterfield wrote:
> > aaron.ballman wrote:
> > > If you don't need any custom semantic checking, you can remove that 
> > > function and instead call 
> > > `handleSimpleAttribute(S, D, AL);`
> > I think this patch does need some custom semantic checking, I just haven't 
> > been able to work out how to implement it. Specifically, the attribute is 
> > an initializer, so
> > 
> > `int foo __attribute__((loader_uninitialised)) = some_value;`
> > 
> > should be a warning, as the = some_value is going to be ignored.
> This should be an error, not a warning, unless there's a specific need to be 
> lenient.
Agreed that this should be an error rather than a warning.

Not 100% certain, but I suspect you'll need to add that checking to 
`Sema::AddInitializerToDecl()` because I'm guessing that the initializer has 
not been processed by the time the attributes are being applied to the variable 
declaration. You can check `VarDecl::hasInit()` within 
`handleLoaderUninitializedAttr()` to see if that specific declaration has an 
initializer, but I'm betting that gives you the wrong answer.



Comment at: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp:14
+// CHECK: @tentative = global i32 undef
+int tentative  [[clang::loader_uninitialized]];
+

JonChesterfield wrote:
> aaron.ballman wrote:
> > What should happen with redeclarations? e.g., in C:
> > ```
> > int a;
> > 
> > int foo() { return a; }
> > 
> > int a __attribute__((loader_uninitialized));
> > ```
> > (This would be a useful test case to add.)
> > 
> > Also, I'd like to see a test case where the attributed global is an array.
> Ah, yes. I was thinking about tentative definitions before changing this test 
> to C++. Fixed the name to be less misleading.
> 
> C++ just rejects it. Multiple definitions => error. Added test to sema.
> 
> C accepts it in either order. Which I believe it should. Either one is a 
> tentative definition, and the other provides an actual definition (of undef), 
> or the definition (of undef) is followed by a redeclaration.
> 
> This leaves the hole that while the following is rightly rejected in C for 
> having multiple definitions:
> ```int a __attr__(...);
> int a = 10;```
> 
> This is erroneously accepted, with the attribute ignored:
> ```int a = 10;
> int a __attr__(...);```
> 
> 
> 
> 
> This is erroneously accepted, with the attribute ignored:

I think you will probably want to add another case to `mergeDeclAttribute()` 
following the similar patterns there so that you can reject when you need to 
merge declarations that should not be merged.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361



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


[PATCH] D31343: Add an attribute plugin example

2020-03-02 Thread John Brawn via Phabricator via cfe-commits
john.brawn marked 2 inline comments as done.
john.brawn added inline comments.



Comment at: clang/examples/Attribute/Attribute.cpp:35
+Spellings.push_back({ParsedAttr::AS_GNU, "example"});
+Spellings.push_back({ParsedAttr::AS_CXX11, "::example"});
+Spellings.push_back({ParsedAttr::AS_CXX11, "plugin::example"});

aaron.ballman wrote:
> This is not a valid spelling for an attribute (we should probably assert that 
> an attribute-scoped-token does not have an empty scope).
"::example" is actually how an unscoped spelling is specified - normalizeName 
in Basic/Attributes.cpp adds a "::" to the start if there's no scope, and the 
tablegen-generated getAttrKind expects it as well.



Comment at: clang/examples/Attribute/Attribute.cpp:42
+// This attribute appertains to functions only.
+if (!D || !isa(D)) {
+  S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type_str)

aaron.ballman wrote:
> I don't think `D` can ever be null, can it?
I don't know, but this is how the auto-generated diagAppertainsToDecl functions 
do it.


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

https://reviews.llvm.org/D31343



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


[PATCH] D75356: [Analyzer][StreamChecker] Introduction of stream error state handling.

2020-03-02 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:50-68
+struct StreamErrorState {
+  // The error state of an opened stream.
+  // EofError: EOF condition (feof returns true)
+  // OtherError: other (non-EOF) error (ferror returns true)
+  // AnyError: EofError or OtherError
+  enum Kind { EofError, OtherError, AnyError } K;
+

balazske wrote:
> Szelethus wrote:
> > Shouldn't we merge this with `StreamState`?
> The intention was that the error state is only stored when the stream is 
> opened (in opened state). Additionally it exists in the map only if there is 
> error, so no "NoError" kind is needed. This is only to save memory, if it is 
> not relevant I can move the error information into `StreamState` (that will 
> contain two enums then).
I personally wouldn't worry about memory consumption in this case too much, 
considering how much information needs to be store for simple expressions, 
stream objects are relatively few and far in between, even on projects that use 
them a lot.

Having one more enum in `StreamState` would be better in this case then! :)



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:92-125
+class MakeRetVal {
+  const CallExpr *CE = nullptr;
+  std::unique_ptr RetVal;
+  SymbolRef RetSym;
+
+public:
+  MakeRetVal(const CallEvent , CheckerContext )

balazske wrote:
> Szelethus wrote:
> > Do you have other patches that really crave the need for this class? Why 
> > isn't `CallEvent::getReturnValue` sufficient? This is a legitimate 
> > question, I really don't know. :)
> This is an "interesting" solution for the problem that there is need for a 
> function with 3 return values. The constructor performs the task of the 
> function: Create a conjured value (and get the various objects for it). The 
> output values are RetVal and RetSym, and the success state, and the call expr 
> that is computed here anyway. It could be computed independently but if the 
> value was retrieved once it is better to store it for later use. (I did not 
> check how costly that operation is.)
> 
> I had some experience that using only `getReturnValue` and make constraints 
> on that does not work as intended, and the reason can be that we need to bind 
> a value for the call expr otherwise it is an unknown (undefined?) value (and 
> not the conjured symbol)?
I suspect that `getReturnValue` might only work in `postCall`, but I'm not sure.

I think instead of this class, a function returning a `std::tuple` would be 
nicer, with `std::tie` on the call site. You seem to use all 3 returns values 
in the functions that instantiate `MakeRetVal` anyways :).

In `StdLibraryFunctionsChecker`'s `evalCall`, the return value is 
[[https://github.com/llvm/llvm-project/blob/master/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp#L403|explicitly
 constructed]], and further constraints on it are only imposed in `postCall`. I 
wonder why that is. @martong, any idea why we don't `apply` the constraints for 
pure functions in `evalCall?`



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:383
+  // Record the failed status, only if failed.
+  // fseek clears the EOF flag, sets only error flag.
+  StateFailed = StateFailed->set(RV.getRetSym(),

According to the C'98 standard 
[[http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf|§7.19.9.2.5]]:
> After determining the new position, a successful call to the fseek function 
> undoes any effects of the `ungetc` function on the stream, clears the 
> end-of-file indicator for the stream, and then establishes the new position. 
> After a successful fseek call, the next operation on an update stream may be 
> either input or output.

So it definitely doesn't clear the `EOF` flag on failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75356



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


[PATCH] D75402: [HIP] Make sure, unused hip-pinned-shadow global var is kept within device code

2020-03-02 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D75402#1901370 , @hsmhsm wrote:

> In D75402#1901361 , @hliao wrote:
>
> > BTW, why that variable cannot have an initializer? Suppose that initializer 
> > is a trivial one, initializing to 0, would that cause any issue in the 
> > compilation?
>
>
> Initialization makes the global extern var declaration to become a global 
> definition. And. moreover, it is not a new change from my side, I just happen 
> to add a comment.


This kind of variable is supposed to be an external variable which is 
initialized by runtime at run time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75402



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


[PATCH] D75423: [OpenCL] Mark pointers to constant address space as invariant

2020-03-02 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D75423#1901362 , @rjmccall wrote:

> Okay, then I have no problem taking a patch for this into IRGen.  But I think 
> it should be fine to do this by adding the invariant-load metadata when 
> loading from an l-value instead of injecting invariant-groups into l-value 
> emission.


The pointer to constant may be casted to a generic pointer then loaded. If we 
only mark load from pointer to constant, we loses information.


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

https://reviews.llvm.org/D75423



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


[PATCH] D72874: [clangd] Add a textual fallback for go-to-definition

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/SourceCode.cpp:313
 
 SourceLocation getBeginningOfIdentifier(const Position ,
 const SourceManager ,

sammccall wrote:
> @kadircet is working on getting rid of this function because creating raw 
> lexers is is wasteful and not actually very powerful. Mostly we're moving to 
> syntax::TokenBuffer, which records actual lexed tokens, but that doesn't 
> apply here.
> 
> The examples in the tests seem like they'd be covered by something *really* 
> simple, like enclosing identifier chars:
> 
> ```
> unsigned Begin, End;
> for (Begin = Offset; Begin > 0 && isIdentifierBody(Code[Begin-1]); 
> --BeginEnd) {}
> for (End = Offset; End < Code.size() && isIdentifierBody(Code[End]); ++End) {}
> return Code.slice(Begin, End);
> ```
> 
> (Lexer::isIdentifierBodyChar requires langopts but just passes through 
> DollarIdents to isIdentifierBody, and I don't think we care much about 
> identifiers with $ in them.)
> 
> If we really want to do something more subtle here, we should check it in 
> SourceCodeTests.
> Mostly we're moving to syntax::TokenBuffer, which records actual lexed 
> tokens, but that doesn't apply here.

Oops, this isn't true - token buffer's expanded token stream has "real" tokens, 
but the spelled token streams use the raw lexer. You can just use 
spelledIdentifierTouching(), I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72874



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


[PATCH] D75469: Add C standard upgrade in clang-11 release note

2020-03-02 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 247682.
nickdesaulniers added a comment.

- s/following/next/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75469

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -545,6 +545,12 @@
   return getelementpointer_inbounds(base, offset);
 }
 
+Changes deferred to Clang-11 release
+
+
+- The next release of clang (clang-11) will upgrade the default C language
+  standard used if not specified via command line from gnu11 to gnu17.
+
 
 Additional Information
 ==


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -545,6 +545,12 @@
   return getelementpointer_inbounds(base, offset);
 }
 
+Changes deferred to Clang-11 release
+
+
+- The next release of clang (clang-11) will upgrade the default C language
+  standard used if not specified via command line from gnu11 to gnu17.
+
 
 Additional Information
 ==
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75469: Add C standard upgrade in clang-11 release note

2020-03-02 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

pushed: 
https://github.com/llvm/llvm-project/commit/001c8aac80e3924c33a4cc644cca58401c72fe6b


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75469



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


[PATCH] D72874: [clangd] Add a textual fallback for go-to-definition

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/SourceCode.cpp:313
 
 SourceLocation getBeginningOfIdentifier(const Position ,
 const SourceManager ,

sammccall wrote:
> sammccall wrote:
> > @kadircet is working on getting rid of this function because creating raw 
> > lexers is is wasteful and not actually very powerful. Mostly we're moving 
> > to syntax::TokenBuffer, which records actual lexed tokens, but that doesn't 
> > apply here.
> > 
> > The examples in the tests seem like they'd be covered by something *really* 
> > simple, like enclosing identifier chars:
> > 
> > ```
> > unsigned Begin, End;
> > for (Begin = Offset; Begin > 0 && isIdentifierBody(Code[Begin-1]); 
> > --BeginEnd) {}
> > for (End = Offset; End < Code.size() && isIdentifierBody(Code[End]); ++End) 
> > {}
> > return Code.slice(Begin, End);
> > ```
> > 
> > (Lexer::isIdentifierBodyChar requires langopts but just passes through 
> > DollarIdents to isIdentifierBody, and I don't think we care much about 
> > identifiers with $ in them.)
> > 
> > If we really want to do something more subtle here, we should check it in 
> > SourceCodeTests.
> > Mostly we're moving to syntax::TokenBuffer, which records actual lexed 
> > tokens, but that doesn't apply here.
> 
> Oops, this isn't true - token buffer's expanded token stream has "real" 
> tokens, but the spelled token streams use the raw lexer. You can just use 
> spelledIdentifierTouching(), I think.
> You can just use spelledIdentifierTouching(), I think.
Sorry disregard this, obviously it doesn't work in comments etc. Need more 
coffee...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72874



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


  1   2   3   >