[PATCH] D89490: Introduce __attribute__((darwin_abi))

2020-10-15 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.h:876
   SDValue LowerAAPCS_VASTART(SDValue Op, SelectionDAG &DAG) const;
+  SDValue LowerAAPCSFromDarwin_VASTART(SDValue Op, SelectionDAG &DAG) const;
   SDValue LowerDarwin_VASTART(SDValue Op, SelectionDAG &DAG) const;

aguinet wrote:
> mstorsjo wrote:
> > aguinet wrote:
> > > Same problem as with clang-format: clang-tidy suggests 
> > > "lowerAapcsFromDarwinVastart", which would mean modifying the whole file 
> > > for consistency. Should we set clang-tidy to ignore this file?
> > I think the churn generally isn't considered worth it regarding such 
> > things; such changes can be quite disruptive to downstream users (with a 
> > lot of non-upstream code) for little benefit. Same thing here, not sure 
> > what the policy is regarding annotations.
> I do agree that a big diff just for this is counter productive. There are few 
> places where we already have clang-format annotations, like 
> https://github.com/llvm/llvm-project/blob/master/llvm/lib/TextAPI/MachO/TextStub.cpp#L262
>  . Maybe we can add one here?
Sure, I guess that can be done.

Normally, I don't strictly follow what clang-format suggests blindly, but only 
selectively keep the bits that look sensible and don't unnecessarily munge 
otherwise untouched code. But annotations to avoid manually filtering it too 
much probably is better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89490

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


[PATCH] D89490: Introduce __attribute__((darwin_abi))

2020-10-15 Thread Adrien Guinet via Phabricator via cfe-commits
aguinet added inline comments.



Comment at: llvm/lib/AsmParser/LLParser.cpp:2147
+CC = CallingConv::Tail;
+break;
   case lltok::kw_cc: {

Again here this "big" diff is a result of clang-format. We can see that 
"kw_aarch64_sve_vector_pcs" has been "clang-formated" but not the rest. I would 
prefer just add a one-line diff and maybe also add annotations?



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.h:876
   SDValue LowerAAPCS_VASTART(SDValue Op, SelectionDAG &DAG) const;
+  SDValue LowerAAPCSFromDarwin_VASTART(SDValue Op, SelectionDAG &DAG) const;
   SDValue LowerDarwin_VASTART(SDValue Op, SelectionDAG &DAG) const;

mstorsjo wrote:
> aguinet wrote:
> > Same problem as with clang-format: clang-tidy suggests 
> > "lowerAapcsFromDarwinVastart", which would mean modifying the whole file 
> > for consistency. Should we set clang-tidy to ignore this file?
> I think the churn generally isn't considered worth it regarding such things; 
> such changes can be quite disruptive to downstream users (with a lot of 
> non-upstream code) for little benefit. Same thing here, not sure what the 
> policy is regarding annotations.
I do agree that a big diff just for this is counter productive. There are few 
places where we already have clang-format annotations, like 
https://github.com/llvm/llvm-project/blob/master/llvm/lib/TextAPI/MachO/TextStub.cpp#L262
 . Maybe we can add one here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89490

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


[PATCH] D89360: Treat constant contexts as being in the default rounding mode.

2020-10-15 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Probably there is an issue with code generation. The source:

  constexpr float func_01(float x, float y) {
return x + y;
  }
  
  float V1 = func_01(1.0F, 0x0.01p0F);

compiled with '-frounding-math' must produce dynamic initializer. It however is 
evaluated at compile time.




Comment at: clang/test/SemaCXX/rounding-math.cpp:5
+
+#define fold(x) (__builtin_constant_p(x) ? (x) : (x))
+

It is not used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89360

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


[PATCH] D89490: Introduce __attribute__((darwin_abi))

2020-10-15 Thread Adrien Guinet via Phabricator via cfe-commits
aguinet updated this revision to Diff 298548.
aguinet added a comment.

Fix one clang-tidy warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89490

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Specifiers.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/darwin_abi.c
  clang/test/CodeGen/darwin_abi_empty_structs.cpp
  clang/test/CodeGen/darwin_abi_vaarg.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/CodeGenCXX/darwinabi-returnthis.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/BinaryFormat/Dwarf.def
  llvm/include/llvm/IR/CallingConv.h
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/Target/AArch64/AArch64CallingConvention.cpp
  llvm/lib/Target/AArch64/AArch64FastISel.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
  llvm/test/CodeGen/AArch64/darwin_abi.ll
  llvm/test/CodeGen/AArch64/darwin_abi_vararg.ll

Index: llvm/test/CodeGen/AArch64/darwin_abi_vararg.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/darwin_abi_vararg.ll
@@ -0,0 +1,39 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=aarch64-pc-linux | FileCheck %s
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-pc-linux"
+
+%struct.__va_list = type { i8*, i8*, i8*, i32, i32 }
+
+define dso_local aarch64_darwincc void @foo(i32 %n, ...) local_unnamed_addr #0 {
+; CHECK-LABEL: foo:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sub sp, sp, #48 // =48
+; CHECK-NEXT:stp x29, x30, [sp, #32] // 16-byte Folded Spill
+; CHECK-NEXT:add x29, sp, #32 // =32
+; CHECK-NEXT:add x8, x29, #16 // =16
+; CHECK-NEXT:mov x1, sp
+; CHECK-NEXT:str xzr, [sp, #24]
+; CHECK-NEXT:str x8, [sp]
+; CHECK-NEXT:bl vfoo
+; CHECK-NEXT:ldp x29, x30, [sp, #32] // 16-byte Folded Reload
+; CHECK-NEXT:add sp, sp, #48 // =48
+; CHECK-NEXT:ret
+entry:
+  %va = alloca %struct.__va_list, align 8
+  %0 = bitcast %struct.__va_list* %va to i8*
+  call void @llvm.va_start(i8* nonnull %0)
+  call void @vfoo(i32 %n, %struct.__va_list* nonnull %va) #1
+  call void @llvm.va_end(i8* nonnull %0)
+  ret void
+}
+
+declare void @llvm.va_start(i8*) #1
+
+declare dso_local void @vfoo(i32, %struct.__va_list*) local_unnamed_addr #0
+
+declare void @llvm.va_end(i8*) #1
+
+attributes #0 = { nounwind "disable-tail-calls"="false" "frame-pointer"="non-leaf" "target-cpu"="generic" }
+attributes #1 = { nounwind }
Index: llvm/test/CodeGen/AArch64/darwin_abi.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/darwin_abi.ll
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=aarch64-pc-linux | FileCheck %s
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-pc-linux"
+
+define dso_local aarch64_darwincc signext i16 @f1(i16 signext %a) local_unnamed_addr #0 {
+; CHECK-LABEL: f1:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:add w8, w0, #1 // =1
+; CHECK-NEXT:sxth w0, w8
+; CHECK-NEXT:ret
+entry:
+  %add = add i16 %a, 1
+  ret i16 %add
+}
+
+define dso_local aarch64_darwincc zeroext i16 @f2(i16 zeroext %a) local_unnamed_addr #0 {
+; CHECK-LABEL: f2:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:add w8, w0, #1 // =1
+; CHECK-NEXT:and w0, w8, #0x
+; CHECK-NEXT:ret
+entry:
+  %add = add i16 %a, 1
+  ret i16 %add
+}
+
+attributes #0 = { norecurse nounwind readnone "disable-tail-calls"="false" "frame-pointer"="non-leaf" "target-cpu"="generic" }
Index: llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
===
--- llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
+++ llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
@@ -474,8 +474,8 @@
   uint64_t StackOffset = Handler.StackUsed;
   if (F.isVarArg()) {
 auto &Subtarget = MF.getSubtarget();
-if (!Subtarget.isTargetDarwin()) {
-// FIXME: we need to reimplement saveVarArgsRegisters from
+if (!Subtarget.isCallingConvDarwin(MF.getFunct

[PATCH] D89490: Introduce __attribute__((darwin_abi))

2020-10-15 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: llvm/lib/IR/AsmWriter.cpp:379
+Out << "aarch64_darwincc";
+break;
   case CallingConv::SPIR_FUNC: Out << "spir_func"; break;

aguinet wrote:
> mstorsjo wrote:
> > The new code here has a different indentation than the rest; the same in a 
> > couple other places throughout the patch.
> As clang-format changed that formatting for me, should I reformat the whole 
> switch-case to be "clang-format compatible", or should we set this section as 
> ignored?
As the manually laid out custom formatting here is kinda beneficial, I think 
it's preferred to keep it as is. If there are annotations to make clang-format 
stay off of it, that's probably good (but I don't know what our policy 
regarding use of such annotations is, if we have any).



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.h:876
   SDValue LowerAAPCS_VASTART(SDValue Op, SelectionDAG &DAG) const;
+  SDValue LowerAAPCSFromDarwin_VASTART(SDValue Op, SelectionDAG &DAG) const;
   SDValue LowerDarwin_VASTART(SDValue Op, SelectionDAG &DAG) const;

aguinet wrote:
> Same problem as with clang-format: clang-tidy suggests 
> "lowerAapcsFromDarwinVastart", which would mean modifying the whole file for 
> consistency. Should we set clang-tidy to ignore this file?
I think the churn generally isn't considered worth it regarding such things; 
such changes can be quite disruptive to downstream users (with a lot of 
non-upstream code) for little benefit. Same thing here, not sure what the 
policy is regarding annotations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89490

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


[PATCH] D89490: Introduce __attribute__((darwin_abi))

2020-10-15 Thread Adrien Guinet via Phabricator via cfe-commits
aguinet added inline comments.



Comment at: llvm/lib/IR/AsmWriter.cpp:379
+Out << "aarch64_darwincc";
+break;
   case CallingConv::SPIR_FUNC: Out << "spir_func"; break;

mstorsjo wrote:
> The new code here has a different indentation than the rest; the same in a 
> couple other places throughout the patch.
As clang-format changed that formatting for me, should I reformat the whole 
switch-case to be "clang-format compatible", or should we set this section as 
ignored?



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.h:876
   SDValue LowerAAPCS_VASTART(SDValue Op, SelectionDAG &DAG) const;
+  SDValue LowerAAPCSFromDarwin_VASTART(SDValue Op, SelectionDAG &DAG) const;
   SDValue LowerDarwin_VASTART(SDValue Op, SelectionDAG &DAG) const;

Same problem as with clang-format: clang-tidy suggests 
"lowerAapcsFromDarwinVastart", which would mean modifying the whole file for 
consistency. Should we set clang-tidy to ignore this file?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89490

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


[PATCH] D89332: [clang-tidy] performance-unnecessary-copy-initialization: Always allow std::function to be copied.

2020-10-15 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp:52
   AllowedTypes(
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {}
 

flx wrote:
> lebedev.ri wrote:
> > Just put it here?
> I tried this first, but this list  is substring matched against only on the 
> non-qualified type name, so std::function would not match anything and if we 
> added "function" here it would match many other types that contain the word 
> function.
I would personally say it's a bug, especially because i personally don't like 
hardcoded "choices" that are impossible to change.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89332

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


[PATCH] D89025: [RISCV] Add -mtune support

2020-10-15 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcfa7094e49cf: [RISCV] Add -mtune support (authored by Kito 
Cheng ).
Herald added a subscriber: NickHung.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89025

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/riscv-cpus.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/include/llvm/Support/RISCVTargetParser.def
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Support/TargetParser.cpp
  llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Index: llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
===
--- llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -75,13 +75,16 @@
 const RISCVSubtarget *
 RISCVTargetMachine::getSubtargetImpl(const Function &F) const {
   Attribute CPUAttr = F.getFnAttribute("target-cpu");
+  Attribute TuneAttr = F.getFnAttribute("tune-cpu");
   Attribute FSAttr = F.getFnAttribute("target-features");
 
   std::string CPU =
   CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
+  std::string TuneCPU =
+  TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
   std::string FS =
   FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
-  std::string Key = CPU + FS;
+  std::string Key = CPU + TuneCPU + FS;
   auto &I = SubtargetMap[Key];
   if (!I) {
 // This needs to be done before we create a new subtarget since any
@@ -98,7 +101,7 @@
   }
   ABIName = ModuleTargetABI->getString();
 }
-I = std::make_unique(TargetTriple, CPU, FS, ABIName, *this);
+I = std::make_unique(TargetTriple, CPU, TuneCPU, FS, ABIName, *this);
   }
   return I.get();
 }
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -71,13 +71,15 @@
   /// Initializes using the passed in CPU and feature strings so that we can
   /// use initializer lists for subtarget initialization.
   RISCVSubtarget &initializeSubtargetDependencies(const Triple &TT,
-  StringRef CPU, StringRef FS,
+  StringRef CPU,
+  StringRef TuneCPU,
+  StringRef FS,
   StringRef ABIName);
 
 public:
   // Initializes the data members to match that of the specified triple.
-  RISCVSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
- StringRef ABIName, const TargetMachine &TM);
+  RISCVSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
+ StringRef FS, StringRef ABIName, const TargetMachine &TM);
 
   // Parses features string setting specified subtarget options. The
   // definition of this function is auto-generated by tblgen.
Index: llvm/lib/Target/RISCV/RISCVSubtarget.cpp
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.cpp
+++ llvm/lib/Target/RISCV/RISCVSubtarget.cpp
@@ -30,13 +30,16 @@
 void RISCVSubtarget::anchor() {}
 
 RISCVSubtarget &RISCVSubtarget::initializeSubtargetDependencies(
-const Triple &TT, StringRef CPU, StringRef FS, StringRef ABIName) {
+const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS, StringRef ABIName) {
   // Determine default and user-specified characteristics
   bool Is64Bit = TT.isArch64Bit();
   std::string CPUName = std::string(CPU);
+  std::string TuneCPUName = std::string(TuneCPU);
   if (CPUName.empty())
 CPUName = Is64Bit ? "generic-rv64" : "generic-rv32";
-  ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
+  if (TuneCPUName.empty())
+TuneCPUName = CPUName;
+  ParseSubtargetFeatures(CPUName, TuneCPUName, FS);
   if (Is64Bit) {
 XLenVT = MVT::i64;
 XLen = 64;
@@ -47,11 +50,12 @@
   return *this;
 }
 
-RISCVSubtarget::RISCVSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
+RISCVSubtarget::RISCVSubtarget(const Triple &TT, StringRef CPU,
+   StringRef TuneCPU, StringRef FS,
StringRef ABIName, const TargetMachine &TM)
-: RISCVGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
+: RISCVGenSubtargetInfo(TT, CPU, TuneCPU, FS),
   UserReservedRegister(RISCV::NUM_TARGET_REGS),
-  FrameLowering(initializeSubtargetDependencies(TT, CPU, FS, ABIName)),
+  FrameLowering(initializeSubtargetDependenci

[clang] cfa7094 - [RISCV] Add -mtune support

2020-10-15 Thread Kito Cheng via cfe-commits

Author: Kito Cheng
Date: 2020-10-16T13:55:08+08:00
New Revision: cfa7094e49cfb7e37a84c0aa57c85c64c0581d17

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

LOG: [RISCV] Add -mtune support

 - The goal of this patch is improve option compatible with RISCV-V GCC,
   -mcpu support on GCC side will sent patch in next few days.

 - -mtune only affect the pipeline model and non-arch/extension related
   target feature, e.g. instruction fusion; in td file it called
   TuneFeatures, which is introduced by X86 back-end[1].

 - -mtune accept all valid option for -mcpu and extra alias processor
   option, e.g. `generic`, `rocket` and `sifive-7-series`, the purpose is
   option compatible with RISCV-V GCC.

 - Processor alias for -mtune will resolve according the current target arch,
   rv32 or rv64, e.g. `rocket` will resolve to `rocket-rv32` or `rocket-rv64`.

 - Interaction between -mcpu and -mtune:
   * -mtune has higher priority than -mcpu for pipeline model and
 TuneFeatures.

[1] https://reviews.llvm.org/D85165

Reviewed By: luismarques

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Basic/Targets/RISCV.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/riscv-cpus.c
clang/test/Misc/target-invalid-cpu-note.c
llvm/include/llvm/Support/RISCVTargetParser.def
llvm/include/llvm/Support/TargetParser.h
llvm/lib/Support/TargetParser.cpp
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
llvm/lib/Target/RISCV/RISCVSubtarget.cpp
llvm/lib/Target/RISCV/RISCVSubtarget.h
llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c896ca3ff95c..ab75ac0a65a3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2768,7 +2768,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[DriverOption,CC1O
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
-  HelpText<"Only supported on X86. Otherwise accepted for compatibility with 
GCC.">;
+  HelpText<"Only supported on X86 and RISC-V. Otherwise accepted for 
compatibility with GCC.">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
 def multiply__defined : Separate<["-"], "multiply_defined">;

diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 4ba703c8dd1a..5e17b7d51175 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -178,6 +178,17 @@ void RISCV32TargetInfo::fillValidCPUList(
   llvm::RISCV::fillValidCPUArchList(Values, false);
 }
 
+bool RISCV32TargetInfo::isValidTuneCPUName(StringRef Name) const {
+  return llvm::RISCV::checkTuneCPUKind(
+  llvm::RISCV::parseTuneCPUKind(Name, false),
+  /*Is64Bit=*/false);
+}
+
+void RISCV32TargetInfo::fillValidTuneCPUList(
+SmallVectorImpl &Values) const {
+  llvm::RISCV::fillValidTuneCPUArchList(Values, false);
+}
+
 bool RISCV64TargetInfo::isValidCPUName(StringRef Name) const {
   return llvm::RISCV::checkCPUKind(llvm::RISCV::parseCPUKind(Name),
/*Is64Bit=*/true);
@@ -187,3 +198,14 @@ void RISCV64TargetInfo::fillValidCPUList(
 SmallVectorImpl &Values) const {
   llvm::RISCV::fillValidCPUArchList(Values, true);
 }
+
+bool RISCV64TargetInfo::isValidTuneCPUName(StringRef Name) const {
+  return llvm::RISCV::checkTuneCPUKind(
+  llvm::RISCV::parseTuneCPUKind(Name, true),
+  /*Is64Bit=*/true);
+}
+
+void RISCV64TargetInfo::fillValidTuneCPUList(
+SmallVectorImpl &Values) const {
+  llvm::RISCV::fillValidTuneCPUArchList(Values, true);
+}

diff  --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 6db526da4c59..a4e6777a11e2 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -106,6 +106,8 @@ class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public 
RISCVTargetInfo {
 
   bool isValidCPUName(StringRef Name) const override;
   void fillValidCPUList(SmallVectorImpl &Values) const override;
+  bool isValidTuneCPUName(StringRef Name) const override;
+  void fillValidTuneCPUList(SmallVectorImpl &Values) const override;
 
   void setMaxAtomicWidth() override {
 MaxAtomicPromoteWidth = 128;
@@ -133,6 +135,8 @@ class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public 
RISCVTargetInfo {
 
   bool isValidCPUName(StringRef Name) const override;
   void fillValidCPUList(SmallVectorImpl &Values) const override;
+  bool isValidTuneCPUNam

[PATCH] D87981: [X86] AMX programming model prototype.

2020-10-15 Thread LuoYuanke via Phabricator via cfe-commits
LuoYuanke updated this revision to Diff 298546.
LuoYuanke added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87981

Files:
  clang/include/clang/Basic/BuiltinsX86_64.def
  clang/lib/Headers/amxintrin.h
  clang/test/CodeGen/AMX/amx_api.c
  llvm/include/llvm/CodeGen/LiveIntervalUnion.h
  llvm/include/llvm/CodeGen/LiveRegMatrix.h
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/CodeGen/TileShapeInfo.h
  llvm/include/llvm/CodeGen/VirtRegMap.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/IntrinsicsX86.td
  llvm/lib/CodeGen/InlineSpiller.cpp
  llvm/lib/CodeGen/LiveIntervalUnion.cpp
  llvm/lib/CodeGen/LiveRegMatrix.cpp
  llvm/lib/CodeGen/VirtRegMap.cpp
  llvm/lib/IR/Function.cpp
  llvm/lib/Target/X86/CMakeLists.txt
  llvm/lib/Target/X86/X86.h
  llvm/lib/Target/X86/X86ExpandPseudo.cpp
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86InstrAMX.td
  llvm/lib/Target/X86/X86InstrInfo.cpp
  llvm/lib/Target/X86/X86LowerAMXType.cpp
  llvm/lib/Target/X86/X86RegisterInfo.cpp
  llvm/lib/Target/X86/X86RegisterInfo.h
  llvm/lib/Target/X86/X86RegisterInfo.td
  llvm/lib/Target/X86/X86Subtarget.h
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/lib/Target/X86/X86TileConfig.cpp
  llvm/test/CodeGen/X86/AMX/amx-across-func.ll
  llvm/test/CodeGen/X86/AMX/amx-config.ll
  llvm/test/CodeGen/X86/AMX/amx-spill.ll
  llvm/test/CodeGen/X86/AMX/amx-type.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll
  llvm/utils/TableGen/IntrinsicEmitter.cpp

Index: llvm/utils/TableGen/IntrinsicEmitter.cpp
===
--- llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -197,25 +197,25 @@
 enum IIT_Info {
   // Common values should be encoded with 0-15.
   IIT_Done = 0,
-  IIT_I1   = 1,
-  IIT_I8   = 2,
-  IIT_I16  = 3,
-  IIT_I32  = 4,
-  IIT_I64  = 5,
-  IIT_F16  = 6,
-  IIT_F32  = 7,
-  IIT_F64  = 8,
-  IIT_V2   = 9,
-  IIT_V4   = 10,
-  IIT_V8   = 11,
-  IIT_V16  = 12,
-  IIT_V32  = 13,
-  IIT_PTR  = 14,
-  IIT_ARG  = 15,
+  IIT_I1 = 1,
+  IIT_I8 = 2,
+  IIT_I16 = 3,
+  IIT_I32 = 4,
+  IIT_I64 = 5,
+  IIT_F16 = 6,
+  IIT_F32 = 7,
+  IIT_F64 = 8,
+  IIT_V2 = 9,
+  IIT_V4 = 10,
+  IIT_V8 = 11,
+  IIT_V16 = 12,
+  IIT_V32 = 13,
+  IIT_PTR = 14,
+  IIT_ARG = 15,
 
   // Values from 16+ are only encodable with the inefficient encoding.
-  IIT_V64  = 16,
-  IIT_MMX  = 17,
+  IIT_V64 = 16,
+  IIT_MMX = 17,
   IIT_TOKEN = 18,
   IIT_METADATA = 19,
   IIT_EMPTYSTRUCT = 20,
@@ -226,7 +226,7 @@
   IIT_EXTEND_ARG = 25,
   IIT_TRUNC_ARG = 26,
   IIT_ANYPTR = 27,
-  IIT_V1   = 28,
+  IIT_V1 = 28,
   IIT_VARARG = 29,
   IIT_HALF_VEC_ARG = 30,
   IIT_SAME_VEC_WIDTH_ARG = 31,
Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -24,6 +24,7 @@
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   Expand Atomic instructions
+; CHECK-NEXT:   Lower AMX type for load/store
 ; CHECK-NEXT:   Module Verifier
 ; CHECK-NEXT:   Dominator Tree Construction
 ; CHECK-NEXT:   Basic Alias Analysis (stateless AA impl)
@@ -141,6 +142,7 @@
 ; CHECK-NEXT:   Lazy Machine Block Frequency Analysis
 ; CHECK-NEXT:   Machine Optimization Remark Emitter
 ; CHECK-NEXT:   Greedy Register Allocator
+; CHECK-NEXT:   Tile Register Configure
 ; CHECK-NEXT:   Virtual Register Rewriter
 ; CHECK-NEXT:   Stack Slot Coloring
 ; CHECK-NEXT:   Machine Copy Propagation Pass
Index: llvm/test/CodeGen/X86/O0-pipeline.ll
===
--- llvm/test/CodeGen/X86/O0-pipeline.ll
+++ llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -18,6 +18,7 @@
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
 ; CHECK-NEXT:   Expand Atomic instructions
+; CHECK-NEXT:   Lower AMX type for load/store
 ; CHECK-NEXT:   Module Verifier
 ; CHECK-NEXT:   Lower Garbage Collection Instructions
 ; CHECK-NEXT:   Shadow Stack GC Lowering
Index: llvm/test/CodeGen/X86/AMX/amx-type.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/AMX/amx-type.ll
@@ -0,0 +1,143 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -lower-amx-type %s -S | FileCheck %s
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.__tile_str = type { i16, i16, <256 x i32> }
+
+@buf = dso_local global [1024 x i8] zeroinitializer, align 16
+@buf2 = dso_local global [1024 x i8] zeroinitializer, align 16
+
+define dso_local void @test_l

[PATCH] D89523: PR44406: Follow behavior of array bound constant folding in more recent versions of GCC.

2020-10-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith marked 3 inline comments as done.
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:5939
+ElemTy = TryToFixInvalidVariablyModifiedType(ElemTy, Context,
+ SizeIsNegative, Oversized);
+if (ElemTy.isNull())

efriedma wrote:
> It's a little surprising to me that you need new code here... was this case 
> getting picked up by the SemaType code?
Yes, and it previously didn't work outside GNU mode: 
https://godbolt.org/z/ncqKvo

I suppose that means that it probably isn't important to handle this, but we 
have a test for the multi-level VLA -> constant array case and it seemed easy 
enough to make it work.



Comment at: clang/lib/Sema/SemaType.cpp:2278
   ArraySize, &SizeVal, Diagnoser,
-  (S.LangOpts.GNUMode || S.LangOpts.OpenCL) ? Sema::AllowFold
-: Sema::NoFold);
+  S.LangOpts.OpenCL ? Sema::AllowFold : Sema::NoFold);
   if (Diagnoser.IsVLA)

efriedma wrote:
> efriedma wrote:
> > We probably want some note to explain why OpenCL is special here... if you 
> > can't figure out easily, please leave a FIXME.
> Oh, I see you posted a separate patch for that.
For posterity, that's D89520.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89523

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


[PATCH] D89332: [clang-tidy] performance-unnecessary-copy-initialization: Always allow std::function to be copied.

2020-10-15 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp:409
+
+namespace std {
+

Could you add a nested inline namespace to better imitate what declarations 
look like in libc++?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89332

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


[PATCH] D14484: [clang-format] Formatting constructor initializer lists by putting them always on different lines

2020-10-15 Thread Andrew Somerville via Phabricator via cfe-commits
catskul added a comment.

In D14484#2246171 , @FStefanni wrote:

> Hi to all,
>
> I am also interested to this option, since match my personal style, but more 
> important, in my experience, this kind of formatting is very used.
> I hope it will be implemented in a near future.
>
> Which is the current status? Is someone going to support this?
>
> Regards.

@FStefanni it seems `ConstructorInitializerAllOnOneLineOrOnePerLine =  false` 
may do the trick per @MyDeveloperDay .

I tried this and had success so far. Try it out and see if it resolves your use 
case.

In D14484#1689271 , @MyDeveloperDay 
wrote:

> Looking at this I'm wondering if this Isn't at least partially handled by the 
> `BreakConstructorInitializersStyle`  in combination with 
> `ConstructorInitializerAllOnOneLineOrOnePerLine` style?
>
> I can't be exactly sure but I think BreakConstructorInitializersStyle  didn't 
> exist before 2017 D32479: clang-format: Introduce 
> BreakConstructorInitializers option  when 
> this original patch was submitted
>
>   BreakConstructorInitializers: BeforeComma
>   ConstructorInitializerAllOnOneLineOrOnePerLine: true
>   
>   SomeClass::Constructor() : aa(aaa), bb(bbb), cc(cc) {}
>   
>   SomeClass::Constructor()
>   : aa(a, aaa,
>aaa)
>   , bb(bbb)
>   , cc(cc) {}
>
>
>
>   BreakConstructorInitializers: BeforeComma
>   ConstructorInitializerAllOnOneLineOrOnePerLine: false
>   
>   SomeClass::Constructor()
>   : aa(aaa)
>   , bb(bbb)
>   , cc(cc) {}
>   
>   SomeClass::Constructor()
>   : aa(a, aaa,
>aaa)
>   , bb(bbb)
>   , cc(cc) {}
>
> At least the unit tests appear to be covered by using those styles?
>
> Nit: At a minimum, this patch would need to be rebased and be a full context 
> diff, can anyone see a  use case that can't be covered with what we have?
>
> Moving to "request changes" (really request to abandon if not necessary any 
> longer)




Repository:
  rL LLVM

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

https://reviews.llvm.org/D14484

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


[PATCH] D89523: PR44406: Follow behavior of array bound constant folding in more recent versions of GCC.

2020-10-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:2278
   ArraySize, &SizeVal, Diagnoser,
-  (S.LangOpts.GNUMode || S.LangOpts.OpenCL) ? Sema::AllowFold
-: Sema::NoFold);
+  S.LangOpts.OpenCL ? Sema::AllowFold : Sema::NoFold);
   if (Diagnoser.IsVLA)

efriedma wrote:
> We probably want some note to explain why OpenCL is special here... if you 
> can't figure out easily, please leave a FIXME.
Oh, I see you posted a separate patch for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89523

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


[PATCH] D89523: PR44406: Follow behavior of array bound constant folding in more recent versions of GCC.

2020-10-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Also update the documentation?  See 
https://clang.llvm.org/docs/UsersManual.html#differences-between-various-standard-modes
 .




Comment at: clang/lib/Sema/SemaDecl.cpp:5939
+ElemTy = TryToFixInvalidVariablyModifiedType(ElemTy, Context,
+ SizeIsNegative, Oversized);
+if (ElemTy.isNull())

It's a little surprising to me that you need new code here... was this case 
getting picked up by the SemaType code?



Comment at: clang/lib/Sema/SemaType.cpp:2278
   ArraySize, &SizeVal, Diagnoser,
-  (S.LangOpts.GNUMode || S.LangOpts.OpenCL) ? Sema::AllowFold
-: Sema::NoFold);
+  S.LangOpts.OpenCL ? Sema::AllowFold : Sema::NoFold);
   if (Diagnoser.IsVLA)

We probably want some note to explain why OpenCL is special here... if you 
can't figure out easily, please leave a FIXME.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89523

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


[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-15 Thread Jan Vesely via Phabricator via cfe-commits
jvesely added a comment.

In D89372#2332997 , @Anastasia wrote:

> In D89372#2332853 , @jvesely wrote:
>
>> `cl_khr_byte_addressable_stores` changes language semantics. without it, 
>> pointer dereferences of types smaller than 32 bits are illegal.
>
> Ok, does it mean that we are missing to diagnose this in the frontend? Btw I 
> do acknowledge that what you say makes sense but I don't think the 
> documentation support that:
> https://www.khronos.org/registry/OpenCL/sdk/2.2/docs/man/html/cl_khr_byte_addressable_store.html
>
> Am I just looking in the wrong place?

Since it's only an extension in ocl 1.0 that spec is a better place to look:

  9.9 Byte Addressable Stores 
  Section 6.8.m describes restrictions on built-in types char, uchar, char2, 
uchar2, short,
  and half. The OpenCL extension cl_khr_byte_addressable_store removes these
  restrictions.  An application that wants to be able to write to elements of a 
pointer (or struct) that
  are of type char, uchar, char2, uchar2, short, ushort and half will need to 
include
  the #pragma OPENCL EXTENSION cl_khr_byte_addressable_store :
  enable directive before any code that performs writes that may not be 
supported as per section
  6.8.m.
  
  6.8 Restrictions
  ...
  m. Built-in types that are less than 32-bits in size i.e. char, uchar, char2, 
uchar2,
  short, ushort, and half have the following restriction:
  Writes to a pointer (or arrays) of type char, uchar, char2, uchar2, short,
  ushort, and half or to elements of a struct that are of type char, uchar,
  char2, uchar2, short and ushort are not supported. Refer to section 9.9
  for additional information.



>> Even if all clang targets support this the macro should still be defined for 
>> backward compatibility.
>
> Ok, are you saying that all targets currently support this and we sould 
> always define it? In this case I would be more happy if we move them into the 
> internal header that we add implicitly anyway...

r600/r700/EG/NI targets have a bit wonky support byte-addressable stores 
(basically using 32bit atomic MSKOR), but I don't expect those targets to 
survive for long, and for now, they advertise support.
some out of tree backends might also benefit from the extension (like legup -- 
verilog backend), but I'm not sure if out of tree targets are worth 
considering, or if they indeed make use of this extension.
on a high-level, I could see a restriction to 32bit data paths be useful for 
FPGA targets.

moving the define it to header breaks OCL1.0 programs. Based on the specs 
above. those programs are required to include the following:

  #ifdef cl_khr_byte_addressable_store
  #pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
  #endif

Before they can dereference pointers to char/char2/short/... types (including 
array indexing and struct members).
so the `pragma` part needs to work, and the language level checks need to work 
if the extension is not enabled.

The same arguments also apply to `cles_khr_in64`. It's illegal to use int64 
types in embedded profile unless you first enable the extensions. Rather than 
removing it, `cles_khr_2d_image_array_writes` should be added to the extension 
list.

clang can always decide that OCL1.0 programs (even when compiled in cl-1.x 
mode) and embedded profile is unsupported.
I have no clue if there are many OCL programs that rely on those modes out 
there.
However, removing support for them is a significantly bigger change than 
cleaning up a few language-irrelevant extensions (actually, I'm not sure if 
clang ever supported OCL embedded mode).

>> it would be useful if the commit message or the description of this revision 
>> included a justification for each removed extension why it doesn't impact 
>> language semantics with spec references.
>
> Yes, this is a good suggestion in principle and we should try our best. 
> However I am not sure it is feasible for all of those, in particular this 
> documentation doesn't contain anything:
> https://man.opencl.org/cl_khr_context_abort.html
>
> Are you suggesting to leave this out? However I don't see any evidence that 
> this require either macro or pragma. I feel this is in rather incomplete 
> state. So I don't feel we can accomodate for all of these.

"incomplete specification" is imo a good reason to drop support for an 
extension. My argument is that explanation of legacy extensions should rely on 
the spec that introduced them, rather than the current 2.x/3.x which does an 
arguably poor job on backward compatibility.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89372

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


[PATCH] D89523: PR44406: Follow behavior of array bound constant folding in more recent versions of GCC.

2020-10-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added a reviewer: eli.friedman.
Herald added a project: clang.
rsmith requested review of this revision.

Old GCC used to aggressively fold VLAs to constant-bound arrays at block
scope in GNU mode. That's non-conforming, and more modern versions of
GCC only do this at file scope. Update Clang to do the same.

Also promote the warning for this from off-by-default to on-by-default
in all cases; more recent versions of GCC likewise warn on this by
default.

This is still slightly more permissive than GCC, as pointed out in
PR44406, as we still fold VLAs to constant arrays in structs, but that
seems justifiable given that we don't support VLA-in-struct (and don't
intend to ever support it), but GCC does.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89523

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CXX/basic/basic.types/p10.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CodeGen/vla.c
  clang/test/Misc/warning-flags.c
  clang/test/PCH/cxx-constexpr.cpp
  clang/test/Profile/misexpect-switch-default.c
  clang/test/Profile/misexpect-switch-nonconst.c
  clang/test/Profile/misexpect-switch-only-default-case.c
  clang/test/Profile/misexpect-switch.c
  clang/test/Sema/builtin-assume.c
  clang/test/Sema/builtins.c
  clang/test/Sema/complex-int.c
  clang/test/Sema/const-eval-64.c
  clang/test/Sema/const-eval.c
  clang/test/Sema/darwin-align-cast.c
  clang/test/Sema/decl-in-prototype.c
  clang/test/Sema/gnu-flags.c
  clang/test/Sema/i-c-e.c
  clang/test/Sema/offsetof-64.c
  clang/test/Sema/struct-decl.c
  clang/test/Sema/typedef-variable-type.c
  clang/test/Sema/vla.c
  clang/test/SemaCXX/anonymous-struct.cpp
  clang/test/SemaCXX/constant-expression.cpp
  clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
  clang/test/SemaCXX/i-c-e-cxx.cpp
  clang/test/SemaObjC/gcc-cast-ext.m

Index: clang/test/SemaObjC/gcc-cast-ext.m
===
--- clang/test/SemaObjC/gcc-cast-ext.m
+++ clang/test/SemaObjC/gcc-cast-ext.m
@@ -11,7 +11,7 @@
 
 // GCC allows pointer expressions in integer constant expressions.
 struct {
-  char control[((int)(char *)2)];
+  char control[((int)(char *)2)]; // expected-warning {{extension}}
 } xx;
 
 @implementation PBXDocBookmark // expected-warning {{method definition for 'autorelease' not found}}\
Index: clang/test/SemaCXX/i-c-e-cxx.cpp
===
--- clang/test/SemaCXX/i-c-e-cxx.cpp
+++ clang/test/SemaCXX/i-c-e-cxx.cpp
@@ -80,7 +80,7 @@
 #endif
 
 int PR8836test[(__typeof(sizeof(int)))&reinterpret_castPR8836*)0)->a))];
-// expected-warning@-1 {{folded to constant array as an extension}}
+// expected-warning@-1 0-1{{C99 feature}} expected-warning@-1 {{folded to constant array as an extension}}
 // expected-note@-2 {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
 
 const int nonconst = 1.0;
@@ -89,7 +89,7 @@
 #endif
 int arr[nonconst];
 #if __cplusplus <= 199711L
-// expected-warning@-2 {{folded to constant array as an extension}}
+// expected-warning@-2 0-1{{C99 feature}} expected-warning@-2 {{folded to constant array as an extension}}
 // expected-note@-3 {{initializer of 'nonconst' is not a constant expression}}
 #endif
 
Index: clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
===
--- clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
+++ clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
@@ -120,7 +120,7 @@
   extern "C" int strncmp(const char *, const char *, decltype(sizeof(0))) noexcept;
 
   // Check we recognized both as builtins.
-  typedef int arr[strcmp("bar", "foo") + 4 * strncmp("foo", "bar", 4)];
+  typedef int arr[strcmp("bar", "foo") + 4 * strncmp("foo", "bar", 4)]; // expected-warning {{variable length array}}
   typedef int arr[3];
 }
 
Index: clang/test/SemaCXX/constant-expression.cpp
===
--- clang/test/SemaCXX/constant-expression.cpp
+++ clang/test/SemaCXX/constant-expression.cpp
@@ -110,7 +110,7 @@
 const int recurse2 = recurse1; // expected-note {{here}}
 const int recurse1 = 1;
 int array1[recurse1]; // ok
-int array2[recurse2]; // expected-warning {{variable length array}} expected-warning {{integer constant expression}} expected-note {{initializer of 'recurse2' is not a constant expression}}
+int array2[recurse2]; // expected-warning 2{{variable length array}} expected-note {{initializer of 'recurse2' is not a constant expression}}
 
 namespace FloatConvert {
   typedef int a[(int)42.3];
Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -131,6 +131,9 @@
   typedef struct { // expected

[clang-tools-extra] cc175c2 - Support ObjC in IncludeInserter

2020-10-15 Thread Alexander Kornienko via cfe-commits

Author: Alexander Kornienko
Date: 2020-10-16T04:12:32+02:00
New Revision: cc175c2cc8e638462bab74e0781e06f9b6eb5017

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

LOG: Support ObjC in IncludeInserter

Update IncludeSorter/IncludeInserter to support objective-c google style (part 
1):

1) Correctly consider .mm/.m extensions
2) Correctly categorize category headers.
3) Add support for generated files to go in a separate section of imports

Reviewed By: alexfh, gribozavr2

Patch by Joe Turner.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
clang-tools-extra/clang-tidy/utils/IncludeSorter.h
clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp 
b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
index c9d018f076e7..f0e56a0af448 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
@@ -9,6 +9,7 @@
 #include "IncludeSorter.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include 
 
 namespace clang {
 namespace tidy {
@@ -36,6 +37,17 @@ StringRef MakeCanonicalName(StringRef Str, 
IncludeSorter::IncludeStyle Style) {
 return RemoveFirstSuffix(
 RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}), {"Test"});
   }
+  if (Style == IncludeSorter::IS_Google_ObjC) {
+StringRef Canonical =
+RemoveFirstSuffix(RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h",
+  ".hpp", ".mm", ".m"}),
+  {"_unittest", "_regtest", "_test", "Test"});
+
+// Objective-C categories have a `+suffix` format, but should be grouped
+// with the file they are a category of.
+return Canonical.substr(
+0, Canonical.find_first_of('+', Canonical.find_last_of('/')));
+  }
   return RemoveFirstSuffix(
   RemoveFirstSuffix(Str, {".cc", ".cpp", ".c", ".h", ".hpp"}),
   {"_unittest", "_regtest", "_test"});
@@ -65,7 +77,8 @@ DetermineIncludeKind(StringRef CanonicalFile, StringRef 
IncludeFile,
   || CanonicalInclude.endswith(CanonicalFile)) {
 return IncludeSorter::IK_MainTUInclude;
   }
-  if (Style == IncludeSorter::IS_Google) {
+  if ((Style == IncludeSorter::IS_Google) ||
+  (Style == IncludeSorter::IS_Google_ObjC)) {
 std::pair Parts = CanonicalInclude.split("/public/");
 std::string AltCanonicalInclude =
 Parts.first.str() + "/internal/" + Parts.second.str();
@@ -78,9 +91,32 @@ DetermineIncludeKind(StringRef CanonicalFile, StringRef 
IncludeFile,
   return IncludeSorter::IK_MainTUInclude;
 }
   }
+  if (Style == IncludeSorter::IS_Google_ObjC) {
+if (IncludeFile.endswith(".generated.h") ||
+IncludeFile.endswith(".proto.h") || IncludeFile.endswith(".pbobjc.h")) 
{
+  return IncludeSorter::IK_GeneratedInclude;
+}
+  }
   return IncludeSorter::IK_NonSystemInclude;
 }
 
+int compareHeaders(StringRef LHS, StringRef RHS,
+   IncludeSorter::IncludeStyle Style) {
+  if (Style == IncludeSorter::IncludeStyle::IS_Google_ObjC) {
+const std::pair &Mismatch =
+std::mismatch(LHS.begin(), LHS.end(), RHS.begin());
+if ((Mismatch.first != LHS.end()) && (Mismatch.second != RHS.end())) {
+  if ((*Mismatch.first == '.') && (*Mismatch.second == '+')) {
+return -1;
+  }
+  if ((*Mismatch.first == '+') && (*Mismatch.second == '.')) {
+return 1;
+  }
+}
+  }
+  return LHS.compare(RHS);
+}
+
 } // namespace
 
 IncludeSorter::IncludeSorter(const SourceManager *SourceMgr,
@@ -112,9 +148,16 @@ void IncludeSorter::AddInclude(StringRef FileName, bool 
IsAngled,
 
 Optional IncludeSorter::CreateIncludeInsertion(StringRef FileName,
   bool IsAngled) {
-  std::string IncludeStmt =
-  IsAngled ? llvm::Twine("#include <" + FileName + ">\n").str()
-   : llvm::Twine("#include \"" + FileName + "\"\n").str();
+  std::string IncludeStmt;
+  if (Style == IncludeStyle::IS_Google_ObjC) {
+IncludeStmt = IsAngled
+  ? llvm::Twine("#import <" + FileName + ">\n").str()
+  : llvm::Twine("#import \"" + FileName + "\"\n").str();
+  } else {
+IncludeStmt = IsAngled
+  ? llvm::Twine("#include <" + FileName + ">\n").str()
+  : llvm::Twine("#include \"" + FileName + "\"\n").str();
+  }
   if (SourceLocations.empty()) {
 // If there are no includes in this file, add it in the first line.
 // FIXME: insert after the file comment or the header guard, if present.
@@ -128,7 +171,7 @@ Op

[PATCH] D89276: Support ObjC in IncludeInserter

2020-10-15 Thread Alexander Kornienko via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcc175c2cc8e6: Support ObjC in IncludeInserter (authored by 
alexfh).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89276

Files:
  clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
  clang-tools-extra/clang-tidy/utils/IncludeSorter.h
  clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -28,8 +28,10 @@
 
 class IncludeInserterCheckBase : public ClangTidyCheck {
 public:
-  IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context)
-  : ClangTidyCheck(CheckName, Context) {}
+  IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context,
+   utils::IncludeSorter::IncludeStyle Style =
+   utils::IncludeSorter::IS_Google)
+  : ClangTidyCheck(CheckName, Context), Inserter(Style) {}
 
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
@@ -50,7 +52,7 @@
 
   virtual std::vector headersToInclude() const = 0;
 
-  utils::IncludeInserter Inserter{utils::IncludeSorter::IS_Google};
+  utils::IncludeInserter Inserter;
 };
 
 class NonSystemHeaderInserterCheck : public IncludeInserterCheckBase {
@@ -111,6 +113,42 @@
   }
 };
 
+class ObjCEarlyInAlphabetHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCEarlyInAlphabetHeaderInserterCheck(StringRef CheckName,
+ ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"a/header.h"};
+  }
+};
+
+class ObjCCategoryHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCCategoryHeaderInserterCheck(StringRef CheckName,
+  ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"clang_tidy/tests/insert_includes_test_header+foo.h"};
+  }
+};
+
+class ObjCGeneratedHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+  ObjCGeneratedHeaderInserterCheck(StringRef CheckName,
+   ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+  std::vector headersToInclude() const override {
+return {"clang_tidy/tests/generated_file.proto.h"};
+  }
+};
+
 template 
 std::string runCheckOnCode(StringRef Code, StringRef Filename) {
   std::vector Errors;
@@ -120,12 +158,20 @@
   {"clang_tidy/tests/"
"insert_includes_test_header.h",
"\n"},
+  // ObjC category.
+  {"clang_tidy/tests/"
+   "insert_includes_test_header+foo.h",
+   "\n"},
   // Non system headers
   {"a/header.h", "\n"},
   {"path/to/a/header.h", "\n"},
   {"path/to/z/header.h", "\n"},
   {"path/to/header.h", "\n"},
   {"path/to/header2.h", "\n"},
+  // Generated headers
+  {"clang_tidy/tests/"
+   "generated_file.proto.h",
+   "\n"},
   // Fake system headers.
   {"stdlib.h", "\n"},
   {"unistd.h", "\n"},
@@ -160,9 +206,9 @@
   int a = 0;
 })";
 
-  EXPECT_EQ(PostCode, runCheckOnCode(
-  PreCode, "clang_tidy/tests/"
-   "insert_includes_test_input2.cc"));
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
 }
 
 TEST(IncludeInserterTest, InsertMultipleIncludesAndDeduplicate) {
@@ -191,9 +237,9 @@
   int a = 0;
 })";
 
-  EXPECT_EQ(PostCode, runCheckOnCode(
-  PreCode, "clang_tidy/tests/"
-

[PATCH] D89441: RFC: Potential fixes to function-instrument=xray-never

2020-10-15 Thread Ian Levesque via Phabricator via cfe-commits
ianlevesque updated this revision to Diff 298534.
ianlevesque added a comment.

Apply the fix in XRayInstrumentation, add test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89441

Files:
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/test/CodeGen/AArch64/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/AArch64/xray-attribute-instrumentation.ll
===
--- llvm/test/CodeGen/AArch64/xray-attribute-instrumentation.ll
+++ llvm/test/CodeGen/AArch64/xray-attribute-instrumentation.ll
@@ -1,6 +1,7 @@
 ; RUN: llc -filetype=asm -o - -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s
 
 define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: foo:
 ; CHECK-LABEL: Lxray_sled_0:
 ; CHECK-NEXT:  b  #32
 ; CHECK-NEXT:  nop
@@ -24,8 +25,80 @@
 ; CHECK-LABEL: Ltmp1:
 ; CHECK-NEXT:  ret
 }
+
 ; CHECK-LABEL: xray_instr_map
 ; CHECK-LABEL: Lxray_sleds_start0
 ; CHECK:   .xword .Lxray_sled_0
 ; CHECK:   .xword .Lxray_sled_1
 ; CHECK-LABEL: Lxray_sleds_end0
+
+define i32 @bar() nounwind noinline uwtable "function-instrument"="xray-never" "function-instrument"="xray-always" {
+; CHECK-LABEL: bar:
+; CHECK-LABEL: Lxray_sled_2:
+; CHECK-NEXT:  b  #32
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-LABEL: Ltmp4:
+  ret i32 0
+; CHECK-LABEL: Lxray_sled_3:
+; CHECK-NEXT:  b  #32
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-LABEL: Ltmp5:
+; CHECK-NEXT:  ret
+}
+
+; CHECK-LABEL: xray_instr_map
+; CHECK-LABEL: Lxray_sleds_start1
+; CHECK:   .xword .Lxray_sled_2
+; CHECK:   .xword .Lxray_sled_3
+; CHECK-LABEL: Lxray_sleds_end1
+
+define i32 @instrumented() nounwind noinline uwtable "xray-instruction-threshold"="1" {
+; CHECK-LABEL: instrumented:
+; CHECK-LABEL: Lxray_sled_4:
+; CHECK-NEXT:  b  #32
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-LABEL: Ltmp8:
+  ret i32 0
+; CHECK-LABEL: Lxray_sled_5:
+; CHECK-NEXT:  b  #32
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop
+; CHECK-LABEL: Ltmp9:
+; CHECK-NEXT:  ret
+}
+
+; CHECK-LABEL: xray_instr_map
+; CHECK-LABEL: Lxray_sleds_start2
+; CHECK:   .xword .Lxray_sled_4
+; CHECK:   .xword .Lxray_sled_5
+; CHECK-LABEL: Lxray_sleds_end2
+
+define i32 @not_instrumented() nounwind noinline uwtable "xray-instruction-threshold"="1" "function-instrument"="xray-never" {
+; CHECK-LABEL: not_instrumented
+; CHECK-NOT: .Lxray_sled_6
+  ret i32 0
+; CHECK:  ret
+}
Index: llvm/lib/CodeGen/XRayInstrumentation.cpp
===
--- llvm/lib/CodeGen/XRayInstrumentation.cpp
+++ llvm/lib/CodeGen/XRayInstrumentation.cpp
@@ -147,6 +147,10 @@
   auto InstrAttr = F.getFnAttribute("function-instrument");
   bool AlwaysInstrument = InstrAttr.isStringAttribute() &&
   InstrAttr.getValueAsString() == "xray-always";
+  bool NeverInstrument = InstrAttr.isStringAttribute() &&
+ InstrAttr.getValueAsString() == "xray-never";
+  if (NeverInstrument && !AlwaysInstrument)
+return false;
   auto ThresholdAttr = F.getFnAttribute("xray-instruction-threshold");
   auto IgnoreLoopsAttr = F.getFnAttribute("xray-ignore-loops");
   unsigned int XRayThreshold = 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89488: FileManager: Shrink FileEntryRef to the size of a pointer

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith updated this revision to Diff 298530.
dexonsmith retitled this revision from "WIP: FileManager: Shrink FileEntryRef 
to the size of a pointer" to "FileManager: Shrink FileEntryRef to the size of a 
pointer".
dexonsmith added a comment.

Rebase on top of https://reviews.llvm.org/D89521 to further reduce noise. I 
think this is ready to go.


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

https://reviews.llvm.org/D89488

Files:
  clang/include/clang/Basic/FileManager.h
  clang/lib/Basic/FileManager.cpp
  clang/lib/Basic/SourceManager.cpp
  clang/unittests/Basic/FileManagerTest.cpp

Index: clang/unittests/Basic/FileManagerTest.cpp
===
--- clang/unittests/Basic/FileManagerTest.cpp
+++ clang/unittests/Basic/FileManagerTest.cpp
@@ -485,29 +485,34 @@
   // Set up a virtual file with a different size than FakeStatCache uses.
   const FileEntry *File = Manager.getVirtualFile("/tmp/test", /*Size=*/10, 0);
   ASSERT_TRUE(File);
-  FileEntryRef Ref("/tmp/test", *File);
-  EXPECT_TRUE(Ref.isValid());
-  EXPECT_EQ(Ref.getSize(), 10);
+  const FileEntry &FE = *File;
+  EXPECT_TRUE(FE.isValid());
+  EXPECT_EQ(FE.getSize(), 10);
 
   // Calling a second time should not affect the UID or size.
-  unsigned VirtualUID = Ref.getUID();
-  EXPECT_EQ(*expectedToOptional(Manager.getFileRef("/tmp/test")), Ref);
-  EXPECT_EQ(Ref.getUID(), VirtualUID);
-  EXPECT_EQ(Ref.getSize(), 10);
+  unsigned VirtualUID = FE.getUID();
+  EXPECT_EQ(
+  &FE,
+  &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry());
+  EXPECT_EQ(FE.getUID(), VirtualUID);
+  EXPECT_EQ(FE.getSize(), 10);
 
   // Bypass the file.
-  llvm::Optional BypassRef = Manager.getBypassFile(Ref);
+  llvm::Optional BypassRef =
+  Manager.getBypassFile(File->getLastRef());
   ASSERT_TRUE(BypassRef);
   EXPECT_TRUE(BypassRef->isValid());
-  EXPECT_EQ(BypassRef->getName(), Ref.getName());
+  EXPECT_EQ("/tmp/test", BypassRef->getName());
 
   // Check that it's different in the right ways.
   EXPECT_NE(&BypassRef->getFileEntry(), File);
   EXPECT_NE(BypassRef->getUID(), VirtualUID);
-  EXPECT_NE(BypassRef->getSize(), Ref.getSize());
+  EXPECT_NE(BypassRef->getSize(), FE.getSize());
 
   // The virtual file should still be returned when searching.
-  EXPECT_EQ(*expectedToOptional(Manager.getFileRef("/tmp/test")), Ref);
+  EXPECT_EQ(
+  &FE,
+  &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry());
 }
 
 } // anonymous namespace
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -707,7 +707,7 @@
 SourceManager::bypassFileContentsOverride(const FileEntry &File) {
   assert(isFileOverridden(&File));
   llvm::Optional BypassFile =
-  FileMgr.getBypassFile(FileEntryRef(File.getName(), File));
+  FileMgr.getBypassFile(File.getLastRef());
 
   // If the file can't be found in the FS, give up.
   if (!BypassFile)
Index: clang/lib/Basic/FileManager.cpp
===
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -212,11 +212,11 @@
   SeenFileInsertResult.first->second.getError());
 // Construct and return and FileEntryRef, unless it's a redirect to another
 // filename.
-SeenFileEntryOrRedirect Value = *SeenFileInsertResult.first->second;
+SeenFileTableValue Value = *SeenFileInsertResult.first->second;
 FileEntry *FE;
-if (LLVM_LIKELY(FE = Value.dyn_cast()))
-  return FileEntryRef(SeenFileInsertResult.first->first(), *FE);
-return getFileRef(*Value.get(), openFile, CacheFailure);
+if (LLVM_LIKELY(FE = Value.V.dyn_cast()))
+  return FileEntryRef(*SeenFileInsertResult.first);
+return FileEntryRef(*Value.V.get());
   }
 
   // We've not seen this before. Fill it in.
@@ -268,24 +268,24 @@
   // This occurs when one dir is symlinked to another, for example.
   FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()];
 
-  NamedFileEnt->second = &UFE;
-
-  // If the name returned by getStatValue is different than Filename, re-intern
-  // the name.
-  if (Status.getName() != Filename) {
-auto &NewNamedFileEnt =
-*SeenFileEntries.insert({Status.getName(), &UFE}).first;
-assert((*NewNamedFileEnt.second).get() == &UFE &&
+  if (Status.getName() == Filename) {
+// The name matches. Set the FileEntry.
+NamedFileEnt->second = SeenFileTableValue(UFE);
+  } else {
+// Name mismatch. We need a redirect. First grab the actual entry we want
+// to return.
+auto &Redirection =
+*SeenFileEntries.insert({Status.getName(), SeenFileTableValue(UFE)})
+ .first;
+assert(Redirection.second->V.get() == &UFE &&
"filename from getStatValue() refers to wrong file");
-InterndFileName = NewNamedFileEnt.first().data();
-// In additi

[PATCH] D89521: FileManager: Reorder declarations of FileEntry and FileEntryRef, NFC

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

This reduces noise in a future patch, but shouldn't change anything
otherwise.


https://reviews.llvm.org/D89521

Files:
  clang/include/clang/Basic/FileManager.h


Index: clang/include/clang/Basic/FileManager.h
===
--- clang/include/clang/Basic/FileManager.h
+++ clang/include/clang/Basic/FileManager.h
@@ -71,6 +71,37 @@
   const llvm::StringMapEntry> *Entry;
 };
 
+class FileEntry;
+
+/// A reference to a \c FileEntry that includes the name of the file as it was
+/// accessed by the FileManager's client.
+class FileEntryRef {
+public:
+  FileEntryRef() = delete;
+  FileEntryRef(StringRef Name, const FileEntry &Entry)
+  : Name(Name), Entry(&Entry) {}
+
+  const StringRef getName() const { return Name; }
+  const FileEntry &getFileEntry() const { return *Entry; }
+
+  inline bool isValid() const;
+  inline off_t getSize() const;
+  inline unsigned getUID() const;
+  inline const llvm::sys::fs::UniqueID &getUniqueID() const;
+  inline time_t getModificationTime() const;
+
+  friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS) {
+return LHS.Entry == RHS.Entry && LHS.Name == RHS.Name;
+  }
+  friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS) {
+return !(LHS == RHS);
+  }
+
+private:
+  StringRef Name;
+  const FileEntry *Entry;
+};
+
 /// Cached information about one file (either on disk
 /// or in the virtual file system).
 ///
@@ -126,41 +157,19 @@
   bool isOpenForTests() const { return File != nullptr; }
 };
 
-/// A reference to a \c FileEntry that includes the name of the file as it was
-/// accessed by the FileManager's client.
-class FileEntryRef {
-public:
-  FileEntryRef() = delete;
-  FileEntryRef(StringRef Name, const FileEntry &Entry)
-  : Name(Name), Entry(&Entry) {}
+bool FileEntryRef::isValid() const { return getFileEntry().isValid(); }
 
-  const StringRef getName() const { return Name; }
-
-  bool isValid() const { return Entry->isValid(); }
-
-  const FileEntry &getFileEntry() const { return *Entry; }
-
-  off_t getSize() const { return Entry->getSize(); }
+off_t FileEntryRef::getSize() const { return getFileEntry().getSize(); }
 
-  unsigned getUID() const { return Entry->getUID(); }
+unsigned FileEntryRef::getUID() const { return getFileEntry().getUID(); }
 
-  const llvm::sys::fs::UniqueID &getUniqueID() const {
-return Entry->getUniqueID();
-  }
+const llvm::sys::fs::UniqueID &FileEntryRef::getUniqueID() const {
+  return getFileEntry().getUniqueID();
+}
 
-  time_t getModificationTime() const { return Entry->getModificationTime(); }
-
-  friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS) {
-return LHS.Entry == RHS.Entry && LHS.Name == RHS.Name;
-  }
-  friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS) {
-return !(LHS == RHS);
-  }
-
-private:
-  StringRef Name;
-  const FileEntry *Entry;
-};
+time_t FileEntryRef::getModificationTime() const {
+  return getFileEntry().getModificationTime();
+}
 
 /// Implements support for file system lookup, file system caching,
 /// and directory search management.


Index: clang/include/clang/Basic/FileManager.h
===
--- clang/include/clang/Basic/FileManager.h
+++ clang/include/clang/Basic/FileManager.h
@@ -71,6 +71,37 @@
   const llvm::StringMapEntry> *Entry;
 };
 
+class FileEntry;
+
+/// A reference to a \c FileEntry that includes the name of the file as it was
+/// accessed by the FileManager's client.
+class FileEntryRef {
+public:
+  FileEntryRef() = delete;
+  FileEntryRef(StringRef Name, const FileEntry &Entry)
+  : Name(Name), Entry(&Entry) {}
+
+  const StringRef getName() const { return Name; }
+  const FileEntry &getFileEntry() const { return *Entry; }
+
+  inline bool isValid() const;
+  inline off_t getSize() const;
+  inline unsigned getUID() const;
+  inline const llvm::sys::fs::UniqueID &getUniqueID() const;
+  inline time_t getModificationTime() const;
+
+  friend bool operator==(const FileEntryRef &LHS, const FileEntryRef &RHS) {
+return LHS.Entry == RHS.Entry && LHS.Name == RHS.Name;
+  }
+  friend bool operator!=(const FileEntryRef &LHS, const FileEntryRef &RHS) {
+return !(LHS == RHS);
+  }
+
+private:
+  StringRef Name;
+  const FileEntry *Entry;
+};
+
 /// Cached information about one file (either on disk
 /// or in the virtual file system).
 ///
@@ -126,41 +157,19 @@
   bool isOpenForTests() const { return File != nullptr; }
 };
 
-/// A reference to a \c FileEntry that includes the name of the file as it was
-/// accessed by the FileManager's client.
-class FileEntryRef {
-public:
-  FileEntryRef() = delete;
-  FileEntryRef(StringRef Name, const FileEntry &Entry)
-  : Name(Name), Entry(&Entry) {}
+bool FileEntryRef:

[PATCH] D89520: Don't permit array bound constant folding in OpenCL.

2020-10-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added reviewers: Anastasia, bader, yaxunl.
Herald added subscribers: kerbowa, nhaehnle, jvesely.
Herald added a project: clang.
rsmith requested review of this revision.

Permitting non-standards-driven "do the best you can" constant-folding
of array bounds is permitted solely as a GNU compatibility feature. We
should not be doing it in any language mode that is attempting to be
conforming.

>From https://reviews.llvm.org/D20090 it appears the intent here was to
permit `__constant int` globals to be used in array bounds, but the
change in that patch only added half of the functionality necessary to
support that in the constant evaluator. This patch adds the other half
of the functionality and turns off constant folding for array bounds in
OpenCL.

I couldn't find any spec justification for accepting the kinds of cases
that D20090  accepts, so a reference to where 
in the OpenCL specification
this is permitted would be useful.

Note that this change also affects the code generation in one test:
because after 'const int n = 0' we now treat 'n' as a constant
expression with value 0, it's now a null pointer, so '(local int *)n'
forms a null pointer rather than a zero pointer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89520

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
  clang/test/SemaOpenCL/address-spaces.cl

Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -4,6 +4,13 @@
 
 __constant int ci = 1;
 
+// __constant ints are allowed in constant expressions.
+enum use_ci_in_enum { enumerator = ci };
+typedef int use_ci_in_array_bound[ci];
+
+// general constant folding of array bounds is not permitted
+typedef int folding_in_array_bounds[&ci + 3 - &ci]; // expected-error-re variable length arrays are not supported in OpenCL|array size is not a constant expression expected-note {{cannot refer to element 3}}
+
 __kernel void foo(__global int *gip) {
   __local int li;
   __local int lj = 2; // expected-error {{'__local' variable cannot have an initializer}}
Index: clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -104,7 +104,7 @@
 // NOOPT: @test_static_var_private.sp2 = internal addrspace(1) global i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), align 4
 // NOOPT: @test_static_var_private.sp3 = internal addrspace(1) global i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), align 4
 // NOOPT: @test_static_var_private.sp4 = internal addrspace(1) global i8 addrspace(5)* null, align 4
-// NOOPT: @test_static_var_private.sp5 = internal addrspace(1) global i8 addrspace(5)* null, align 4
+// NOOPT: @test_static_var_private.sp5 = internal addrspace(1) global i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), align 4
 // NOOPT: @test_static_var_private.SS1 = internal addrspace(1) global %struct.StructTy1 { i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), i8 addrspace(3)* addrspacecast (i8* null to i8 addrspace(3)*), i8 addrspace(4)* null, i8 addrspace(1)* null, i8* null }, align 8
 // NOOPT: @test_static_var_private.SS2 = internal addrspace(1) global %struct.StructTy2 zeroinitializer, align 8
 
@@ -123,7 +123,7 @@
 // NOOPT: @test_static_var_local.sp2 = internal addrspace(1) global i8 addrspace(3)* addrspacecast (i8* null to i8 addrspace(3)*), align 4
 // NOOPT: @test_static_var_local.sp3 = internal addrspace(1) global i8 addrspace(3)* addrspacecast (i8* null to i8 addrspace(3)*), align 4
 // NOOPT: @test_static_var_local.sp4 = internal addrspace(1) global i8 addrspace(3)* null, align 4
-// NOOPT: @test_static_var_local.sp5 = internal addrspace(1) global i8 addrspace(3)* null, align 4
+// NOOPT: @test_static_var_local.sp5 = internal addrspace(1) global i8 addrspace(3)* addrspacecast (i8* null to i8 addrspace(3)*), align 4
 // NOOPT: @test_static_var_local.SS1 = internal addrspace(1) global %struct.StructTy1 { i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), i8 addrspace(3)* addrspacecast (i8* null to i8 addrspace(3)*), i8 addrspace(4)* null, i8 addrspace(1)* null, i8* null }, align 8
 // NOOPT: @test_static_var_local.SS2 = internal addrspace(1) global %struct.StructTy2 zeroinitializer, align 8
 void test_static_var_local(void) {
@@ -142,7 +142,7 @@
 // NOOPT: store i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), i8 addrspace(5)* addrspace(5)* %sp1, align 4
 // NOOPT: store i8 addrspace(5)* addrspacecast (i8* null to i8 addrspace(5)*), i8 addrspace(5)* addrspace(5)* %sp2, align 4
 // NOOPT: store i8 addrspace(5)* null, i8 addrspace(5)* addrspace(5)* %sp3, align 4
-

[PATCH] D89177: [cmake] Add support for multiple distributions

2020-10-15 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In D89177#2332675 , @beanz wrote:

> In D89177#2332627 , @ldionne wrote:
>
>> That isn't what I meant. It's entirely okay for the runtimes to be driven 
>> via `AddExternalProject` like the runtimes build does, since that's akin to 
>> having a separate CMake invocation for each configuration. That's okay.
>>
>> What I'm saying is that if the next logical step is to also add support for 
>> multiple distributions in libc++'s build itself (e.g. adding 
>> `LIBCXX__ENABLE_SHARED` & al), then I don't think that's a 
>> good idea.
>
> Totally agree. That would be the path compiler-rt’s Darwin build goes, and it 
> is a frequent problem.

Agreed as well, and I have no plans of going down that path. The 
multi-configuration stuff @phosek and I were discussing is related to the 
support CMake already has for changing flags based on your build configuration 
(e.g. the `CMAKE__FLAGS_` variables), but something like 
`LIBCXX__ENABLE_SHARED` would be pretty different and is not a 
direction I plan on going in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89177

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


[clang] fc031d2 - Switch the default of VerifyIntegerConstantExpression from constant

2020-10-15 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-10-15T16:58:47-07:00
New Revision: fc031d29bea856f2b91a250fd81c5f9fb79dbe07

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

LOG: Switch the default of VerifyIntegerConstantExpression from constant
folding to not constant folding.

Constant folding of ICEs is done as a GCC compatibility measure, but new
code was picking it up, presumably by accident, due to the bad default.

While here, also switch the flag from a bool to an enum to make it more
obvious what it means at call sites. This highlighted a couple of places
where our behavior is different between C++11 and C++14 due to switching
from checking for an ICE to checking for a converted constant
expression (where there is no 'fold' codepath).

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaType.cpp
clang/test/SemaCXX/enum.cpp
clang/test/SemaCXX/new-delete.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b5f0c08300bf..52658715ee8c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11608,17 +11608,27 @@ class Sema final {
 virtual ~VerifyICEDiagnoser() {}
   };
 
+  enum AllowFoldKind {
+NoFold,
+AllowFold,
+  };
+
   /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE,
   /// and reports the appropriate diagnostics. Returns false on success.
   /// Can optionally return the value of the expression.
   ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
  VerifyICEDiagnoser &Diagnoser,
- bool AllowFold = true);
+ AllowFoldKind CanFold = NoFold);
   ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
  unsigned DiagID,
- bool AllowFold = true);
+ AllowFoldKind CanFold = NoFold);
   ExprResult VerifyIntegerConstantExpression(Expr *E,
- llvm::APSInt *Result = nullptr);
+ llvm::APSInt *Result = nullptr,
+ AllowFoldKind CanFold = NoFold);
+  ExprResult VerifyIntegerConstantExpression(Expr *E,
+ AllowFoldKind CanFold = NoFold) {
+return VerifyIntegerConstantExpression(E, nullptr, CanFold);
+  }
 
   /// VerifyBitField - verifies that a bit field expression is an ICE and has
   /// the correct width, and that the field type is valid.

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9a6682e837dd..8542c20ec069 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16418,7 +16418,7 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc,
 return BitWidth;
 
   llvm::APSInt Value;
-  ExprResult ICE = VerifyIntegerConstantExpression(BitWidth, &Value);
+  ExprResult ICE = VerifyIntegerConstantExpression(BitWidth, &Value, 
AllowFold);
   if (ICE.isInvalid())
 return ICE;
   BitWidth = ICE.get();
@@ -17536,6 +17536,8 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
 if (Enum->isDependentType() || Val->isTypeDependent())
   EltTy = Context.DependentTy;
 else {
+  // FIXME: We don't allow folding in C++11 mode for an enum with a fixed
+  // underlying type, but do allow it in all other contexts.
   if (getLangOpts().CPlusPlus11 && Enum->isFixed()) {
 // C++11 [dcl.enum]p5: If the underlying type is fixed, [...] the
 // constant-expression in the enumerator-definition shall be a 
converted
@@ -17549,8 +17551,9 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
 else
   Val = Converted.get();
   } else if (!Val->isValueDependent() &&
- !(Val = VerifyIntegerConstantExpression(Val,
- &EnumVal).get())) {
+ !(Val =
+   VerifyIntegerConstantExpression(Val, &EnumVal, 
AllowFold)
+   .get())) {
 // C99 6.7.2.2p2: Make sure we have an integer constant expression.
   } else {
 if (Enum->isComplete()) {

diff  --git a/clang/lib/Sema/SemaDeclAttr.c

[PATCH] D89484: [AMDGPU][HIP] Switch default DWARF version to 5

2020-10-15 Thread Tony Tye via Phabricator via cfe-commits
t-tye accepted this revision.
t-tye added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89484

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


[PATCH] D89488: WIP: FileManager: Shrink FileEntryRef to the size of a pointer

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith updated this revision to Diff 298517.
dexonsmith added a comment.

Peeled off the clangd change into https://reviews.llvm.org/D89514 and rebased.


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

https://reviews.llvm.org/D89488

Files:
  clang/include/clang/Basic/FileManager.h
  clang/lib/Basic/FileManager.cpp
  clang/lib/Basic/SourceManager.cpp
  clang/unittests/Basic/FileManagerTest.cpp

Index: clang/unittests/Basic/FileManagerTest.cpp
===
--- clang/unittests/Basic/FileManagerTest.cpp
+++ clang/unittests/Basic/FileManagerTest.cpp
@@ -485,29 +485,34 @@
   // Set up a virtual file with a different size than FakeStatCache uses.
   const FileEntry *File = Manager.getVirtualFile("/tmp/test", /*Size=*/10, 0);
   ASSERT_TRUE(File);
-  FileEntryRef Ref("/tmp/test", *File);
-  EXPECT_TRUE(Ref.isValid());
-  EXPECT_EQ(Ref.getSize(), 10);
+  const FileEntry &FE = *File;
+  EXPECT_TRUE(FE.isValid());
+  EXPECT_EQ(FE.getSize(), 10);
 
   // Calling a second time should not affect the UID or size.
-  unsigned VirtualUID = Ref.getUID();
-  EXPECT_EQ(*expectedToOptional(Manager.getFileRef("/tmp/test")), Ref);
-  EXPECT_EQ(Ref.getUID(), VirtualUID);
-  EXPECT_EQ(Ref.getSize(), 10);
+  unsigned VirtualUID = FE.getUID();
+  EXPECT_EQ(
+  &FE,
+  &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry());
+  EXPECT_EQ(FE.getUID(), VirtualUID);
+  EXPECT_EQ(FE.getSize(), 10);
 
   // Bypass the file.
-  llvm::Optional BypassRef = Manager.getBypassFile(Ref);
+  llvm::Optional BypassRef =
+  Manager.getBypassFile(File->getLastRef());
   ASSERT_TRUE(BypassRef);
   EXPECT_TRUE(BypassRef->isValid());
-  EXPECT_EQ(BypassRef->getName(), Ref.getName());
+  EXPECT_EQ("/tmp/test", BypassRef->getName());
 
   // Check that it's different in the right ways.
   EXPECT_NE(&BypassRef->getFileEntry(), File);
   EXPECT_NE(BypassRef->getUID(), VirtualUID);
-  EXPECT_NE(BypassRef->getSize(), Ref.getSize());
+  EXPECT_NE(BypassRef->getSize(), FE.getSize());
 
   // The virtual file should still be returned when searching.
-  EXPECT_EQ(*expectedToOptional(Manager.getFileRef("/tmp/test")), Ref);
+  EXPECT_EQ(
+  &FE,
+  &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry());
 }
 
 } // anonymous namespace
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -707,7 +707,7 @@
 SourceManager::bypassFileContentsOverride(const FileEntry &File) {
   assert(isFileOverridden(&File));
   llvm::Optional BypassFile =
-  FileMgr.getBypassFile(FileEntryRef(File.getName(), File));
+  FileMgr.getBypassFile(File.getLastRef());
 
   // If the file can't be found in the FS, give up.
   if (!BypassFile)
Index: clang/lib/Basic/FileManager.cpp
===
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -212,11 +212,11 @@
   SeenFileInsertResult.first->second.getError());
 // Construct and return and FileEntryRef, unless it's a redirect to another
 // filename.
-SeenFileEntryOrRedirect Value = *SeenFileInsertResult.first->second;
+SeenFileTableValue Value = *SeenFileInsertResult.first->second;
 FileEntry *FE;
-if (LLVM_LIKELY(FE = Value.dyn_cast()))
-  return FileEntryRef(SeenFileInsertResult.first->first(), *FE);
-return getFileRef(*Value.get(), openFile, CacheFailure);
+if (LLVM_LIKELY(FE = Value.V.dyn_cast()))
+  return FileEntryRef(*SeenFileInsertResult.first);
+return FileEntryRef(*Value.V.get());
   }
 
   // We've not seen this before. Fill it in.
@@ -268,24 +268,24 @@
   // This occurs when one dir is symlinked to another, for example.
   FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()];
 
-  NamedFileEnt->second = &UFE;
-
-  // If the name returned by getStatValue is different than Filename, re-intern
-  // the name.
-  if (Status.getName() != Filename) {
-auto &NewNamedFileEnt =
-*SeenFileEntries.insert({Status.getName(), &UFE}).first;
-assert((*NewNamedFileEnt.second).get() == &UFE &&
+  if (Status.getName() == Filename) {
+// The name matches. Set the FileEntry.
+NamedFileEnt->second = SeenFileTableValue(UFE);
+  } else {
+// Name mismatch. We need a redirect. First grab the actual entry we want
+// to return.
+auto &Redirection =
+*SeenFileEntries.insert({Status.getName(), SeenFileTableValue(UFE)})
+ .first;
+assert(Redirection.second->V.get() == &UFE &&
"filename from getStatValue() refers to wrong file");
-InterndFileName = NewNamedFileEnt.first().data();
-// In addition to re-interning the name, construct a redirecting seen file
-// entry, that will point to the name the filesystem actually wants to use.
-StringRef *Redirect = new (CanonicalNameStorag

[PATCH] D89514: clangd: Stop calling FileEntryRef::FileEntryRef

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added subscribers: usaxena95, ributzka, kadircet.
dexonsmith requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

In `ReplayPreamble::replay`, use `getFileRef` instead of `getFile`, and
then use that `FileEntryRef` later to avoid needing
`FileEntryRef::FileEntryRef`. The latter is going to become private to
`FileManager` in a later commit.


https://reviews.llvm.org/D89514

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


Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -170,10 +170,9 @@
 
   void replay() {
 for (const auto &Inc : Includes) {
-  const FileEntry *File = nullptr;
+  llvm::Optional File;
   if (Inc.Resolved != "")
-if (auto FE = SM.getFileManager().getFile(Inc.Resolved))
-  File = *FE;
+File = 
expectedToOptional(SM.getFileManager().getFileRef(Inc.Resolved));
 
   // Re-lex the #include directive to find its interesting parts.
   auto HashLoc = SM.getComposedLoc(SM.getMainFileID(), Inc.HashOffset);
@@ -211,17 +210,17 @@
   SynthesizedFilenameTok.setKind(tok::header_name);
   SynthesizedFilenameTok.setLiteralData(Inc.Written.data());
 
+  const FileEntry *FE = File ? &File->getFileEntry() : nullptr;
   llvm::StringRef WrittenFilename =
   llvm::StringRef(Inc.Written).drop_front().drop_back();
   Delegate->InclusionDirective(HashTok->location(), SynthesizedIncludeTok,
WrittenFilename, Inc.Written.front() == '<',
-   FileTok->range(SM).toCharRange(SM), File,
+   FileTok->range(SM).toCharRange(SM), FE,
"SearchPath", "RelPath",
/*Imported=*/nullptr, Inc.FileKind);
   if (File)
 // FIXME: Use correctly named FileEntryRef.
-Delegate->FileSkipped(FileEntryRef(File->getName(), *File),
-  SynthesizedFilenameTok, Inc.FileKind);
+Delegate->FileSkipped(*File, SynthesizedFilenameTok, Inc.FileKind);
   else {
 llvm::SmallString<1> UnusedRecovery;
 Delegate->FileNotFound(WrittenFilename, UnusedRecovery);


Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -170,10 +170,9 @@
 
   void replay() {
 for (const auto &Inc : Includes) {
-  const FileEntry *File = nullptr;
+  llvm::Optional File;
   if (Inc.Resolved != "")
-if (auto FE = SM.getFileManager().getFile(Inc.Resolved))
-  File = *FE;
+File = expectedToOptional(SM.getFileManager().getFileRef(Inc.Resolved));
 
   // Re-lex the #include directive to find its interesting parts.
   auto HashLoc = SM.getComposedLoc(SM.getMainFileID(), Inc.HashOffset);
@@ -211,17 +210,17 @@
   SynthesizedFilenameTok.setKind(tok::header_name);
   SynthesizedFilenameTok.setLiteralData(Inc.Written.data());
 
+  const FileEntry *FE = File ? &File->getFileEntry() : nullptr;
   llvm::StringRef WrittenFilename =
   llvm::StringRef(Inc.Written).drop_front().drop_back();
   Delegate->InclusionDirective(HashTok->location(), SynthesizedIncludeTok,
WrittenFilename, Inc.Written.front() == '<',
-   FileTok->range(SM).toCharRange(SM), File,
+   FileTok->range(SM).toCharRange(SM), FE,
"SearchPath", "RelPath",
/*Imported=*/nullptr, Inc.FileKind);
   if (File)
 // FIXME: Use correctly named FileEntryRef.
-Delegate->FileSkipped(FileEntryRef(File->getName(), *File),
-  SynthesizedFilenameTok, Inc.FileKind);
+Delegate->FileSkipped(*File, SynthesizedFilenameTok, Inc.FileKind);
   else {
 llvm::SmallString<1> UnusedRecovery;
 Delegate->FileNotFound(WrittenFilename, UnusedRecovery);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89488: WIP: FileManager: Shrink FileEntryRef to the size of a pointer

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith updated this revision to Diff 298508.
dexonsmith added a comment.

Removing some noise from the patch that I missed in the last update.


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

https://reviews.llvm.org/D89488

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang/include/clang/Basic/FileManager.h
  clang/lib/Basic/FileManager.cpp
  clang/lib/Basic/SourceManager.cpp
  clang/unittests/Basic/FileManagerTest.cpp

Index: clang/unittests/Basic/FileManagerTest.cpp
===
--- clang/unittests/Basic/FileManagerTest.cpp
+++ clang/unittests/Basic/FileManagerTest.cpp
@@ -485,29 +485,34 @@
   // Set up a virtual file with a different size than FakeStatCache uses.
   const FileEntry *File = Manager.getVirtualFile("/tmp/test", /*Size=*/10, 0);
   ASSERT_TRUE(File);
-  FileEntryRef Ref("/tmp/test", *File);
-  EXPECT_TRUE(Ref.isValid());
-  EXPECT_EQ(Ref.getSize(), 10);
+  const FileEntry &FE = *File;
+  EXPECT_TRUE(FE.isValid());
+  EXPECT_EQ(FE.getSize(), 10);
 
   // Calling a second time should not affect the UID or size.
-  unsigned VirtualUID = Ref.getUID();
-  EXPECT_EQ(*expectedToOptional(Manager.getFileRef("/tmp/test")), Ref);
-  EXPECT_EQ(Ref.getUID(), VirtualUID);
-  EXPECT_EQ(Ref.getSize(), 10);
+  unsigned VirtualUID = FE.getUID();
+  EXPECT_EQ(
+  &FE,
+  &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry());
+  EXPECT_EQ(FE.getUID(), VirtualUID);
+  EXPECT_EQ(FE.getSize(), 10);
 
   // Bypass the file.
-  llvm::Optional BypassRef = Manager.getBypassFile(Ref);
+  llvm::Optional BypassRef =
+  Manager.getBypassFile(File->getLastRef());
   ASSERT_TRUE(BypassRef);
   EXPECT_TRUE(BypassRef->isValid());
-  EXPECT_EQ(BypassRef->getName(), Ref.getName());
+  EXPECT_EQ("/tmp/test", BypassRef->getName());
 
   // Check that it's different in the right ways.
   EXPECT_NE(&BypassRef->getFileEntry(), File);
   EXPECT_NE(BypassRef->getUID(), VirtualUID);
-  EXPECT_NE(BypassRef->getSize(), Ref.getSize());
+  EXPECT_NE(BypassRef->getSize(), FE.getSize());
 
   // The virtual file should still be returned when searching.
-  EXPECT_EQ(*expectedToOptional(Manager.getFileRef("/tmp/test")), Ref);
+  EXPECT_EQ(
+  &FE,
+  &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry());
 }
 
 } // anonymous namespace
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -707,7 +707,7 @@
 SourceManager::bypassFileContentsOverride(const FileEntry &File) {
   assert(isFileOverridden(&File));
   llvm::Optional BypassFile =
-  FileMgr.getBypassFile(FileEntryRef(File.getName(), File));
+  FileMgr.getBypassFile(File.getLastRef());
 
   // If the file can't be found in the FS, give up.
   if (!BypassFile)
Index: clang/lib/Basic/FileManager.cpp
===
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -212,11 +212,11 @@
   SeenFileInsertResult.first->second.getError());
 // Construct and return and FileEntryRef, unless it's a redirect to another
 // filename.
-SeenFileEntryOrRedirect Value = *SeenFileInsertResult.first->second;
+SeenFileTableValue Value = *SeenFileInsertResult.first->second;
 FileEntry *FE;
-if (LLVM_LIKELY(FE = Value.dyn_cast()))
-  return FileEntryRef(SeenFileInsertResult.first->first(), *FE);
-return getFileRef(*Value.get(), openFile, CacheFailure);
+if (LLVM_LIKELY(FE = Value.V.dyn_cast()))
+  return FileEntryRef(*SeenFileInsertResult.first);
+return FileEntryRef(*Value.V.get());
   }
 
   // We've not seen this before. Fill it in.
@@ -268,24 +268,24 @@
   // This occurs when one dir is symlinked to another, for example.
   FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()];
 
-  NamedFileEnt->second = &UFE;
-
-  // If the name returned by getStatValue is different than Filename, re-intern
-  // the name.
-  if (Status.getName() != Filename) {
-auto &NewNamedFileEnt =
-*SeenFileEntries.insert({Status.getName(), &UFE}).first;
-assert((*NewNamedFileEnt.second).get() == &UFE &&
+  if (Status.getName() == Filename) {
+// The name matches. Set the FileEntry.
+NamedFileEnt->second = SeenFileTableValue(UFE);
+  } else {
+// Name mismatch. We need a redirect. First grab the actual entry we want
+// to return.
+auto &Redirection =
+*SeenFileEntries.insert({Status.getName(), SeenFileTableValue(UFE)})
+ .first;
+assert(Redirection.second->V.get() == &UFE &&
"filename from getStatValue() refers to wrong file");
-InterndFileName = NewNamedFileEnt.first().data();
-// In addition to re-interning the name, construct a redirecting seen file
-// entry, that will point to the name the filesystem actually wants to use.
-StringRef *Redi

[clang] 273c299 - [PM/CC1] Add -f[no-]split-cold-code CC1 option to toggle splitting

2020-10-15 Thread Saleem Abdulrasool via cfe-commits

Author: Vedant Kumar
Date: 2020-10-15T23:13:33Z
New Revision: 273c299d5d649a0222fbde03c9a41e41913751b4

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

LOG: [PM/CC1] Add -f[no-]split-cold-code CC1 option to toggle splitting

This patch adds -f[no-]split-cold-code CC1 options to clang. This allows
the splitting pass to be toggled on/off. The current method of passing
`-mllvm -hot-cold-split=true` to clang isn't ideal as it may not compose
correctly (say, with `-O0` or `-Oz`).

To implement the -fsplit-cold-code option, an attribute is applied to
functions to indicate that they may be considered for splitting. This
removes some complexity from the old/new PM pipeline builders, and
behaves as expected when LTO is enabled.

Co-authored by: Saleem Abdulrasool 
Differential Revision: https://reviews.llvm.org/D57265
Reviewed By: Aditya Kumar, Vedant Kumar
Reviewers: Teresa Johnson, Aditya Kumar, Fedor Sergeev, Philip Pfaffe, Vedant 
Kumar

Added: 
clang/test/CodeGen/split-cold-code.c
clang/test/Frontend/split-cold-code.c

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/Transforms/IPO/HotColdSplitting.h
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Transforms/IPO/HotColdSplitting.cpp
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
llvm/test/Other/X86/lto-hot-cold-split.ll
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-pgo.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Other/opt-O2-pipeline.ll
llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
llvm/test/Other/opt-O3-pipeline.ll
llvm/test/Other/opt-Os-pipeline.ll
llvm/test/Other/opt-hot-cold-split.ll
llvm/test/Other/pass-pipelines.ll
llvm/test/Transforms/CodeExtractor/extract-assume.ll
llvm/test/Transforms/HotColdSplit/X86/do-not-split.ll
llvm/test/Transforms/HotColdSplit/addr-taken.ll
llvm/test/Transforms/HotColdSplit/apply-noreturn-bonus.ll
llvm/test/Transforms/HotColdSplit/apply-penalty-for-inputs.ll
llvm/test/Transforms/HotColdSplit/apply-penalty-for-outputs.ll
llvm/test/Transforms/HotColdSplit/apply-successor-penalty.ll
llvm/test/Transforms/HotColdSplit/assumption-cache-invalidation.ll
llvm/test/Transforms/HotColdSplit/coldentrycount.ll
llvm/test/Transforms/HotColdSplit/delete-use-without-def-dbg-val.ll
llvm/test/Transforms/HotColdSplit/duplicate-phi-preds-crash.ll
llvm/test/Transforms/HotColdSplit/eh-pads.ll
llvm/test/Transforms/HotColdSplit/eh-typeid-for.ll
llvm/test/Transforms/HotColdSplit/forward-dfs-reaches-marked-block.ll
llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-1.ll
llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-2.ll
llvm/test/Transforms/HotColdSplit/mark-the-whole-func-cold.ll
llvm/test/Transforms/HotColdSplit/minsize.ll
llvm/test/Transforms/HotColdSplit/multiple-exits.ll
llvm/test/Transforms/HotColdSplit/noreturn.ll
llvm/test/Transforms/HotColdSplit/outline-cold-asm.ll
llvm/test/Transforms/HotColdSplit/outline-disjoint-diamonds.ll
llvm/test/Transforms/HotColdSplit/outline-if-then-else.ll
llvm/test/Transforms/HotColdSplit/outline-multiple-entry-region.ll
llvm/test/Transforms/HotColdSplit/outline-while-loop.ll
llvm/test/Transforms/HotColdSplit/phi-with-distinct-outlined-values.ll
llvm/test/Transforms/HotColdSplit/region-overlap.ll
llvm/test/Transforms/HotColdSplit/resume.ll
llvm/test/Transforms/HotColdSplit/retain-section.ll
llvm/test/Transforms/HotColdSplit/section-splitting-custom.ll
llvm/test/Transforms/HotColdSplit/section-splitting-default.ll
llvm/test/Transforms/HotColdSplit/split-cold-2.ll
llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
llvm/test/Transforms/HotColdSplit/split-out-dbg-val-of-arg.ll
llvm/test/Transforms/HotColdSplit/split-phis-in-exit-blocks.ll
llvm/test/Transforms/HotColdSplit/stale-assume-in-original-func.ll
llvm/test/Transforms/HotColdSplit/succ-block-with-self-edge.ll
llvm/test/Transforms/HotColdSplit/swifterror.ll
llvm/test/Transforms/HotColdSplit/transfer-debug-info.ll
llvm/test/Transforms/HotColdSplit/unwind.ll
llvm/test/Transforms/HotColdSplit/update-split-loop-metadata.ll

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll

llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.expected

llvm/test/tools/UpdateTestCh

[PATCH] D57265: [PM/CC1] Add -f[no-]split-cold-code CC1 options to toggle splitting

2020-10-15 Thread Saleem Abdulrasool via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG273c299d5d64: [PM/CC1] Add -f[no-]split-cold-code CC1 option 
to toggle splitting (authored by vsk, committed by compnerd).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57265

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/split-cold-code.c
  clang/test/Frontend/split-cold-code.c
  llvm/include/llvm/Transforms/IPO/HotColdSplitting.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Transforms/IPO/HotColdSplitting.cpp
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
  llvm/test/Other/X86/lto-hot-cold-split.ll
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-lto-defaults.ll
  llvm/test/Other/new-pm-pgo.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/opt-O2-pipeline.ll
  llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/opt-Os-pipeline.ll
  llvm/test/Other/opt-hot-cold-split.ll
  llvm/test/Other/pass-pipelines.ll
  llvm/test/Transforms/CodeExtractor/extract-assume.ll
  llvm/test/Transforms/HotColdSplit/X86/do-not-split.ll
  llvm/test/Transforms/HotColdSplit/addr-taken.ll
  llvm/test/Transforms/HotColdSplit/apply-noreturn-bonus.ll
  llvm/test/Transforms/HotColdSplit/apply-penalty-for-inputs.ll
  llvm/test/Transforms/HotColdSplit/apply-penalty-for-outputs.ll
  llvm/test/Transforms/HotColdSplit/apply-successor-penalty.ll
  llvm/test/Transforms/HotColdSplit/assumption-cache-invalidation.ll
  llvm/test/Transforms/HotColdSplit/coldentrycount.ll
  llvm/test/Transforms/HotColdSplit/delete-use-without-def-dbg-val.ll
  llvm/test/Transforms/HotColdSplit/duplicate-phi-preds-crash.ll
  llvm/test/Transforms/HotColdSplit/eh-pads.ll
  llvm/test/Transforms/HotColdSplit/eh-typeid-for.ll
  llvm/test/Transforms/HotColdSplit/forward-dfs-reaches-marked-block.ll
  llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-1.ll
  llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-2.ll
  llvm/test/Transforms/HotColdSplit/mark-the-whole-func-cold.ll
  llvm/test/Transforms/HotColdSplit/minsize.ll
  llvm/test/Transforms/HotColdSplit/multiple-exits.ll
  llvm/test/Transforms/HotColdSplit/noreturn.ll
  llvm/test/Transforms/HotColdSplit/outline-cold-asm.ll
  llvm/test/Transforms/HotColdSplit/outline-disjoint-diamonds.ll
  llvm/test/Transforms/HotColdSplit/outline-if-then-else.ll
  llvm/test/Transforms/HotColdSplit/outline-multiple-entry-region.ll
  llvm/test/Transforms/HotColdSplit/outline-while-loop.ll
  llvm/test/Transforms/HotColdSplit/phi-with-distinct-outlined-values.ll
  llvm/test/Transforms/HotColdSplit/region-overlap.ll
  llvm/test/Transforms/HotColdSplit/resume.ll
  llvm/test/Transforms/HotColdSplit/retain-section.ll
  llvm/test/Transforms/HotColdSplit/section-splitting-custom.ll
  llvm/test/Transforms/HotColdSplit/section-splitting-default.ll
  llvm/test/Transforms/HotColdSplit/split-cold-2.ll
  llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
  llvm/test/Transforms/HotColdSplit/split-out-dbg-val-of-arg.ll
  llvm/test/Transforms/HotColdSplit/split-phis-in-exit-blocks.ll
  llvm/test/Transforms/HotColdSplit/stale-assume-in-original-func.ll
  llvm/test/Transforms/HotColdSplit/succ-block-with-self-edge.ll
  llvm/test/Transforms/HotColdSplit/swifterror.ll
  llvm/test/Transforms/HotColdSplit/transfer-debug-info.ll
  llvm/test/Transforms/HotColdSplit/unwind.ll
  llvm/test/Transforms/HotColdSplit/update-split-loop-metadata.ll
  llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected

Index: llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected
===
--- llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected
+++ llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected
@@ -3,13 +3,13 @@
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.14.0"
 
-define void @foo(i32) {
+define void @foo(i32) "hot-cold-split" {
 ; CHECK-LABEL: @foo(
 ; CHECK-NEXT:[[TMP2:%.*]] = icmp eq i32 [[TMP0:%.*]], 0
 ; CHECK-NEXT:tail call void @_Z10sideeffectv()
 ; CHECK-NEXT:br i1 [[TMP2]], label [[CODERE

[PATCH] D89508: SourceManager: getFileEntryRefForID => getNonBuiltinFilenameForID, NFC

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



Comment at: clang/lib/Basic/SourceManager.cpp:729-730
   if (const SrcMgr::SLocEntry *Entry = getSLocEntryForFile(FID))
 if (auto *Content = Entry->getFile().getContentCache())
   if (Content && Content->OrigEntry)
+return Entry->getFile().getName();

These `if`s need to stay behind to detect whether the file is built-in.


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

https://reviews.llvm.org/D89508

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


[PATCH] D89488: WIP: FileManager: Shrink FileEntryRef to the size of a pointer

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith updated this revision to Diff 298503.
dexonsmith added a comment.

Rebased on top of https://reviews.llvm.org/D89508. Still some things to split 
apart, but the bug is fixed and this is a fair bit smaller.


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

https://reviews.llvm.org/D89488

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang/include/clang/Basic/FileManager.h
  clang/lib/Basic/FileManager.cpp
  clang/lib/Basic/SourceManager.cpp
  clang/unittests/Basic/FileManagerTest.cpp

Index: clang/unittests/Basic/FileManagerTest.cpp
===
--- clang/unittests/Basic/FileManagerTest.cpp
+++ clang/unittests/Basic/FileManagerTest.cpp
@@ -485,29 +485,34 @@
   // Set up a virtual file with a different size than FakeStatCache uses.
   const FileEntry *File = Manager.getVirtualFile("/tmp/test", /*Size=*/10, 0);
   ASSERT_TRUE(File);
-  FileEntryRef Ref("/tmp/test", *File);
-  EXPECT_TRUE(Ref.isValid());
-  EXPECT_EQ(Ref.getSize(), 10);
+  const FileEntry &FE = *File;
+  EXPECT_TRUE(FE.isValid());
+  EXPECT_EQ(FE.getSize(), 10);
 
   // Calling a second time should not affect the UID or size.
-  unsigned VirtualUID = Ref.getUID();
-  EXPECT_EQ(*expectedToOptional(Manager.getFileRef("/tmp/test")), Ref);
-  EXPECT_EQ(Ref.getUID(), VirtualUID);
-  EXPECT_EQ(Ref.getSize(), 10);
+  unsigned VirtualUID = FE.getUID();
+  EXPECT_EQ(
+  &FE,
+  &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry());
+  EXPECT_EQ(FE.getUID(), VirtualUID);
+  EXPECT_EQ(FE.getSize(), 10);
 
   // Bypass the file.
-  llvm::Optional BypassRef = Manager.getBypassFile(Ref);
+  llvm::Optional BypassRef =
+  Manager.getBypassFile(File->getLastRef());
   ASSERT_TRUE(BypassRef);
   EXPECT_TRUE(BypassRef->isValid());
-  EXPECT_EQ(BypassRef->getName(), Ref.getName());
+  EXPECT_EQ("/tmp/test", BypassRef->getName());
 
   // Check that it's different in the right ways.
   EXPECT_NE(&BypassRef->getFileEntry(), File);
   EXPECT_NE(BypassRef->getUID(), VirtualUID);
-  EXPECT_NE(BypassRef->getSize(), Ref.getSize());
+  EXPECT_NE(BypassRef->getSize(), FE.getSize());
 
   // The virtual file should still be returned when searching.
-  EXPECT_EQ(*expectedToOptional(Manager.getFileRef("/tmp/test")), Ref);
+  EXPECT_EQ(
+  &FE,
+  &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry());
 }
 
 } // anonymous namespace
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -707,7 +707,7 @@
 SourceManager::bypassFileContentsOverride(const FileEntry &File) {
   assert(isFileOverridden(&File));
   llvm::Optional BypassFile =
-  FileMgr.getBypassFile(FileEntryRef(File.getName(), File));
+  FileMgr.getBypassFile(File.getLastRef());
 
   // If the file can't be found in the FS, give up.
   if (!BypassFile)
Index: clang/lib/Basic/FileManager.cpp
===
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -212,11 +212,11 @@
   SeenFileInsertResult.first->second.getError());
 // Construct and return and FileEntryRef, unless it's a redirect to another
 // filename.
-SeenFileEntryOrRedirect Value = *SeenFileInsertResult.first->second;
+SeenFileTableValue Value = *SeenFileInsertResult.first->second;
 FileEntry *FE;
-if (LLVM_LIKELY(FE = Value.dyn_cast()))
-  return FileEntryRef(SeenFileInsertResult.first->first(), *FE);
-return getFileRef(*Value.get(), openFile, CacheFailure);
+if (LLVM_LIKELY(FE = Value.V.dyn_cast()))
+  return FileEntryRef(*SeenFileInsertResult.first);
+return FileEntryRef(*Value.V.get());
   }
 
   // We've not seen this before. Fill it in.
@@ -268,24 +268,24 @@
   // This occurs when one dir is symlinked to another, for example.
   FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()];
 
-  NamedFileEnt->second = &UFE;
-
-  // If the name returned by getStatValue is different than Filename, re-intern
-  // the name.
-  if (Status.getName() != Filename) {
-auto &NewNamedFileEnt =
-*SeenFileEntries.insert({Status.getName(), &UFE}).first;
-assert((*NewNamedFileEnt.second).get() == &UFE &&
+  if (Status.getName() == Filename) {
+// The name matches. Set the FileEntry.
+NamedFileEnt->second = SeenFileTableValue(UFE);
+  } else {
+// Name mismatch. We need a redirect. First grab the actual entry we want
+// to return.
+auto &Redirection =
+*SeenFileEntries.insert({Status.getName(), SeenFileTableValue(UFE)})
+ .first;
+assert(Redirection.second->V.get() == &UFE &&
"filename from getStatValue() refers to wrong file");
-InterndFileName = NewNamedFileEnt.first().data();
-// In addition to re-interning the name, construct a redirecting seen file
-// entry, that will point 

[PATCH] D74130: [clang] fix consteval call in default arguments

2020-10-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/Parse/Parser.h:2928
+  SmallVectorImpl &ParamInfo,
+  SourceLocation &EllipsisLoc, bool InConstantConstext = false);
   void ParseBracketDeclarator(Declarator &D);





Comment at: clang/include/clang/Sema/Sema.h:1145
+enum ImmediateInvocationEndScopeAction {
+  IIESA_Handle, ///< Immediate invocation can and should be handeled at the
+///< end of the scope.





Comment at: clang/include/clang/Sema/Sema.h:1147
+///< end of the scope.
+  IIESA_Propagate, ///< Immediate invocation cannot be handeled at the end
+   ///< of the scope and should be propagated to the outer





Comment at: clang/include/clang/Sema/Sema.h:4690
+  ExpressionEvaluationContextRecord::EK_Other,
+  bool IsLambdaParamScope = false);
   enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl };

Can you model this as an `ExpressionEvaluationContextRecord::ExpressionKind` 
instead of a new parameter?



Comment at: clang/lib/Sema/Sema.cpp:1026
 
+  HandleImmediateInvocations(ExprEvalContexts.back());
+

What do we need this for? If I'm understanding the patch correctly, I think the 
only way we should propagate immediate invocations upwards should be from the 
`ExpressionEvaluationContext` of a lambda default argument into the 
`ExpressionEvaluationContext` of the lambda itself, so it should never reach 
the top level.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:17045-17048
+  bool HasConstantInitializer = false;
+  if (auto *VD = dyn_cast(D))
+HasConstantInitializer = VD->isConstexpr() || VD->hasAttr();
+  isConstantEvaluatedOverride = HasConstantInitializer;

This needs a comment explaining what's going on: why are `constexpr` / 
`constinit` variables special here, but (for example) a variable of type `const 
int` is not?

Actually, I think this change might not be correct. Consider the following:

```
consteval void check(bool b) { if (!b) throw; }
constinit int x = true ? 1 : (check(false), 2);
```

This code is ill-formed: the immediate invocation of `check(false)` is not a 
constant expression. But I think with this code change, we won't require 
`check(false)` to be a constant expression, instead deferring to checking 
whether the initializer of `x` as a whole is a constant expression (which it 
is!). So we'll accept invalid code.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:17062
 ExitDeclaratorContext(S);
+  isConstantEvaluatedOverride = false;
 }

Do we need to restore the old value here, rather than resetting to `false`? In 
a case like:

```
consteval int g() { return 0; }
constexpr int a = ({ constexpr int b = 0; g(); });
```

it looks like we'd lose the 'override' flag at the end of the definition of `b`.

Generally I find the idea of using a global override flag like this to be 
dubious: there are a lot of ways in which we switch context during `Sema`, and 
we'd need to make sure we switch out this context at those times too. If we can 
avoid using a global state flag for this (for example by carrying this on the 
`ExpressionEvaluationContextRecord`, that'd be a lot less worrying.



Comment at: clang/lib/Sema/SemaExpr.cpp:16107-16109
+  if (IsLambdaParamScope)
+ExprEvalContexts.back().IIEndScopeAction =
+Sema::ExpressionEvaluationContextRecord::IIESA_Propagate;

I'm a little uncomfortable about assuming that the innermost 
`ExpressionEvaluationContext` surrounding a lambda parameter is always a 
context for the lambda expression itself -- that's making a lot of assumptions 
about what contexts might be added in the future.

Instead of propagating this information from the lambda parameter context to 
the (presumed) lambda context when we pop an expression evaluation context for 
a lambda parameter, could we pull out the `LambdaScopeInfo` for the current 
lambda (`getCurLambda()`) and store the information there, to be either 
diagnosed or dropped when we reach `ActOnStartOfLambdaDefinition`?



Comment at: clang/lib/Sema/SemaLambda.cpp:895-896
+  if (ParamInfo.getDeclSpec().getConstexprSpecifier() == CSK_consteval)
+ExprEvalContexts.back().IIEndScopeAction =
+ExpressionEvaluationContextRecord::IIESA_Drop;
+

We've already parsed the default arguments at this point; it would seem simpler 
to directly clear out the immediate invocation state from the 
`ExpressionEvaluationContextRecord` rather than asking it to do that at the end 
of the scope. This would also remove the need for the `IIESA_Drop` mode 
entirely; if you also change the `IsLambdaParamScope` flag into an 
`ExpressionKind` on the context record, that would remove the need for the 
`IIEndSco

[PATCH] D89407: [clang-tidy] Add scoped enum constants to identifier naming check

2020-10-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

I think will be good idea to add test for suffix/prefix too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89407

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


[PATCH] D89488: WIP: FileManager: Shrink FileEntryRef to the size of a pointer

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

In D89488#2332998 , @dexonsmith wrote:

> I'd still appreciate feedback on the direction, but 
> `clang/test/ClangScanDeps/modules-full.cpp` is failing (getting 
> `""` listed twice under `"file-deps"` for each translation unit) so 
> I'm marking this as needing changes.

Found the bug; it was pretty subtle. See https://reviews.llvm.org/D89508 for 
details.


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

https://reviews.llvm.org/D89488

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


[PATCH] D89508: SourceManager: getFileEntryRefForID => getNonBuiltinFilenameForID, NFC

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added reviewers: arphaman, Bigcheese.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

`SourceManager::getFileEntryRefForID`'s remaining callers just want the
filename component, which is coming from the `FileInfo`. Replace the API
with `getNonBuiltinFilenameForID`, which also removes another use of
`FileEntryRef::FileEntryRef` outside of `FileManager`.

Both callers are collecting file dependencies, and one of them relied on
this API to filter out built-ins (as exposed by
clang/test/ClangScanDeps/modules-full.cpp). It seems nice to continue
providing that service.


https://reviews.llvm.org/D89508

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Frontend/DependencyFile.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp


Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -77,15 +77,10 @@
   // Dependency generation really does want to go all the way to the
   // file entry for a source location to find out what is depended on.
   // We do not want #line markers to affect dependency generation!
-  Optional File =
-  SM.getFileEntryRefForID(SM.getFileID(SM.getExpansionLoc(Loc)));
-  if (!File)
-return;
-
-  StringRef FileName =
-  llvm::sys::path::remove_leading_dotslash(File->getName());
-
-  MDC.MainDeps.push_back(std::string(FileName));
+  if (Optional Filename =
+  SM.getNonBuiltinFilenameForID(SM.getFileID(SM.getExpansionLoc(Loc
+MDC.MainDeps.push_back(
+std::string(llvm::sys::path::remove_leading_dotslash(*Filename)));
 }
 
 void ModuleDepCollectorPP::InclusionDirective(
Index: clang/lib/Frontend/DependencyFile.cpp
===
--- clang/lib/Frontend/DependencyFile.cpp
+++ clang/lib/Frontend/DependencyFile.cpp
@@ -46,17 +46,12 @@
 // Dependency generation really does want to go all the way to the
 // file entry for a source location to find out what is depended on.
 // We do not want #line markers to affect dependency generation!
-Optional File =
-SM.getFileEntryRefForID(SM.getFileID(SM.getExpansionLoc(Loc)));
-if (!File)
-  return;
-
-StringRef Filename =
-llvm::sys::path::remove_leading_dotslash(File->getName());
-
-DepCollector.maybeAddDependency(Filename, /*FromModule*/false,
-isSystem(FileType),
-/*IsModuleFile*/false, /*IsMissing*/false);
+if (Optional Filename = SM.getNonBuiltinFilenameForID(
+SM.getFileID(SM.getExpansionLoc(Loc
+  DepCollector.maybeAddDependency(
+  llvm::sys::path::remove_leading_dotslash(*Filename),
+  /*FromModule*/ false, isSystem(FileType), /*IsModuleFile*/ false,
+  /*IsMissing*/ false);
   }
 
   void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok,
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -723,11 +723,12 @@
   const_cast(CC)->IsTransient = true;
 }
 
-Optional SourceManager::getFileEntryRefForID(FileID FID) const {
+Optional
+SourceManager::getNonBuiltinFilenameForID(FileID FID) const {
   if (const SrcMgr::SLocEntry *Entry = getSLocEntryForFile(FID))
 if (auto *Content = Entry->getFile().getContentCache())
   if (Content && Content->OrigEntry)
-return FileEntryRef(Entry->getFile().getName(), *Content->OrigEntry);
+return Entry->getFile().getName();
   return None;
 }
 
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -997,8 +997,11 @@
 return nullptr;
   }
 
-  /// Returns the FileEntryRef for the provided FileID.
-  Optional getFileEntryRefForID(FileID FID) const;
+  /// Returns the filename for the provided FileID, unless it's a built-in
+  /// buffer that's not represented by a filename.
+  ///
+  /// Returns None for non-files and built-in files.
+  Optional getNonBuiltinFilenameForID(FileID FID) const;
 
   /// Returns the FileEntry record for the provided SLocEntry.
   const FileEntry *getFileEntryForSLocEntry(const SrcMgr::SLocEntry &sloc) 
const


Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -77,15 +77,10 @@
   // Dependency generation really does want to go all the way to the
   //

[PATCH] D89507: SourceManager: Change SourceManager::isMainFile to take a FileEntry, NFC

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

`SourceManager::isMainFile` does not use the filename, so it doesn't
need the full `FileEntryRef`; in fact, it's misleading to take the name
because that makes it look relevant. Simplify the API, and in the
process remove some calls to `FileEntryRef::FileEntryRef` in the unit
tests (which were blocking making that private to `SourceManager`).


https://reviews.llvm.org/D89507

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/unittests/Basic/SourceManagerTest.cpp


Index: clang/unittests/Basic/SourceManagerTest.cpp
===
--- clang/unittests/Basic/SourceManagerTest.cpp
+++ clang/unittests/Basic/SourceManagerTest.cpp
@@ -509,10 +509,9 @@
   FileID MainFileID = SourceMgr.getOrCreateFileID(SourceFile, SrcMgr::C_User);
   SourceMgr.setMainFileID(MainFileID);
 
-  EXPECT_TRUE(SourceMgr.isMainFile(FileEntryRef("mainFile.cpp", *SourceFile)));
-  EXPECT_TRUE(
-  SourceMgr.isMainFile(FileEntryRef("anotherName.cpp", *SourceFile)));
-  EXPECT_FALSE(SourceMgr.isMainFile(FileEntryRef("mainFile.cpp", 
*SecondFile)));
+  EXPECT_TRUE(SourceMgr.isMainFile(*SourceFile));
+  EXPECT_TRUE(SourceMgr.isMainFile(*SourceFile));
+  EXPECT_FALSE(SourceMgr.isMainFile(*SecondFile));
 }
 
 #endif
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -2061,7 +2061,7 @@
   // some directives (e.g. #endif of a header guard) will never be seen.
   // Since this will lead to confusing errors, avoid the inclusion.
   if (Action == Enter && File && PreambleConditionalStack.isRecording() &&
-  SourceMgr.isMainFile(*File)) {
+  SourceMgr.isMainFile(File->getFileEntry())) {
 Diag(FilenameTok.getLocation(),
  diag::err_pp_including_mainfile_in_preamble);
 return {ImportAction::None};
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -343,12 +343,11 @@
   createExpansionLoc(SourceLocation(), SourceLocation(), SourceLocation(), 1);
 }
 
-bool SourceManager::isMainFile(FileEntryRef SourceFile) {
+bool SourceManager::isMainFile(const FileEntry &SourceFile) {
   assert(MainFileID.isValid() && "expected initialized SourceManager");
-  auto FE = getFileEntryRefForID(MainFileID);
-  if (!FE)
-return false;
-  return FE->getUID() == SourceFile.getUID();
+  if (auto *FE = getFileEntryForID(MainFileID))
+return FE->getUID() == SourceFile.getUID();
+  return false;
 }
 
 void SourceManager::initializeForReplay(const SourceManager &Old) {
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -814,7 +814,7 @@
   /// Returns true when the given FileEntry corresponds to the main file.
   ///
   /// The main file should be set prior to calling this function.
-  bool isMainFile(FileEntryRef SourceFile);
+  bool isMainFile(const FileEntry &SourceFile);
 
   /// Set the file ID for the precompiled preamble.
   void setPreambleFileID(FileID Preamble) {


Index: clang/unittests/Basic/SourceManagerTest.cpp
===
--- clang/unittests/Basic/SourceManagerTest.cpp
+++ clang/unittests/Basic/SourceManagerTest.cpp
@@ -509,10 +509,9 @@
   FileID MainFileID = SourceMgr.getOrCreateFileID(SourceFile, SrcMgr::C_User);
   SourceMgr.setMainFileID(MainFileID);
 
-  EXPECT_TRUE(SourceMgr.isMainFile(FileEntryRef("mainFile.cpp", *SourceFile)));
-  EXPECT_TRUE(
-  SourceMgr.isMainFile(FileEntryRef("anotherName.cpp", *SourceFile)));
-  EXPECT_FALSE(SourceMgr.isMainFile(FileEntryRef("mainFile.cpp", *SecondFile)));
+  EXPECT_TRUE(SourceMgr.isMainFile(*SourceFile));
+  EXPECT_TRUE(SourceMgr.isMainFile(*SourceFile));
+  EXPECT_FALSE(SourceMgr.isMainFile(*SecondFile));
 }
 
 #endif
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -2061,7 +2061,7 @@
   // some directives (e.g. #endif of a header guard) will never be seen.
   // Since this will lead to confusing errors, avoid the inclusion.
   if (Action == Enter && File && PreambleConditionalStack.isRecording() &&
-  SourceMgr.isMainFile(*File)) {
+  SourceMgr.isMainFile(File->getFileEntry())) {
 Diag(FilenameTok.getLocation(),
  diag::err_pp_including_mainfile_in_preamble);
 return {ImportAction::None};
Index: clang/lib/Basic/SourceManager.cpp
===

[PATCH] D89503: SourceManager: Factor out helpers for common SLocEntry lookup pattern, NFC

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

Add helpers `getSLocEntryOrNull`, which handles the `Invalid` logic around 
`getSLocEntry`, and `getSLocEntryForFile`, which also checks for 
`SLocEntry::isFile`, and use them to reduce repeated code.


https://reviews.llvm.org/D89503

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp

Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -725,15 +725,11 @@
 }
 
 Optional SourceManager::getFileEntryRefForID(FileID FID) const {
-  bool Invalid = false;
-  const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid);
-  if (Invalid || !Entry.isFile())
-return None;
-
-  const SrcMgr::ContentCache *Content = Entry.getFile().getContentCache();
-  if (!Content || !Content->OrigEntry)
-return None;
-  return FileEntryRef(Entry.getFile().getName(), *Content->OrigEntry);
+  if (const SrcMgr::SLocEntry *Entry = getSLocEntryForFile(FID))
+if (auto *Content = Entry->getFile().getContentCache())
+  if (Content && Content->OrigEntry)
+return FileEntryRef(Entry->getFile().getName(), *Content->OrigEntry);
+  return None;
 }
 
 StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const {
@@ -745,23 +741,16 @@
 
 llvm::Optional
 SourceManager::getBufferDataIfLoaded(FileID FID) const {
-  bool MyInvalid = false;
-  const SLocEntry &SLoc = getSLocEntry(FID, &MyInvalid);
-  if (!SLoc.isFile() || MyInvalid)
-return None;
-
-  return SLoc.getFile().getContentCache()->getBufferDataIfLoaded();
+  if (const SrcMgr::SLocEntry *Entry = getSLocEntryForFile(FID))
+return Entry->getFile().getContentCache()->getBufferDataIfLoaded();
+  return None;
 }
 
 llvm::Optional SourceManager::getBufferDataOrNone(FileID FID) const {
-  bool MyInvalid = false;
-  const SLocEntry &SLoc = getSLocEntry(FID, &MyInvalid);
-  if (!SLoc.isFile() || MyInvalid)
-return None;
-
-  if (auto B = SLoc.getFile().getContentCache()->getBufferOrNone(
-  Diag, getFileManager(), SourceLocation()))
-return B->getBuffer();
+  if (const SrcMgr::SLocEntry *Entry = getSLocEntryForFile(FID))
+if (auto B = Entry->getFile().getContentCache()->getBufferOrNone(
+Diag, getFileManager(), SourceLocation()))
+  return B->getBuffer();
   return None;
 }
 
@@ -1441,12 +1430,11 @@
 SourceManager::getFileCharacteristic(SourceLocation Loc) const {
   assert(Loc.isValid() && "Can't get file characteristic of invalid loc!");
   std::pair LocInfo = getDecomposedExpansionLoc(Loc);
-  bool Invalid = false;
-  const SLocEntry &SEntry = getSLocEntry(LocInfo.first, &Invalid);
-  if (Invalid || !SEntry.isFile())
+  const SLocEntry *SEntry = getSLocEntryForFile(LocInfo.first);
+  if (!SEntry)
 return C_User;
 
-  const SrcMgr::FileInfo &FI = SEntry.getFile();
+  const SrcMgr::FileInfo &FI = SEntry->getFile();
 
   // If there are no #line directives in this file, just return the whole-file
   // state.
@@ -1567,12 +1555,11 @@
   // Presumed locations are always for expansion points.
   std::pair LocInfo = getDecomposedExpansionLoc(Loc);
 
-  bool Invalid = false;
-  const SLocEntry &Entry = getSLocEntry(LocInfo.first, &Invalid);
-  if (Invalid || !Entry.isFile())
+  const SLocEntry *Entry = getSLocEntryForFile(LocInfo.first);
+  if (!Entry)
 return false;
 
-  const SrcMgr::FileInfo &FI = Entry.getFile();
+  const SrcMgr::FileInfo &FI = Entry->getFile();
 
   // Check if there is a line directive for this location.
   if (FI.hasLineDirectives())
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -972,13 +972,10 @@
   /// If there is an error opening this buffer the first time, return None.
   llvm::Optional
   getBufferOrNone(FileID FID, SourceLocation Loc = SourceLocation()) const {
-bool MyInvalid = false;
-const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid);
-if (MyInvalid || !Entry.isFile())
-  return None;
-
-return Entry.getFile().getContentCache()->getBufferOrNone(
-Diag, getFileManager(), Loc);
+if (auto *Entry = getSLocEntryForFile(FID))
+  return Entry->getFile().getContentCache()->getBufferOrNone(
+  Diag, getFileManager(), Loc);
+return None;
   }
 
   /// Return the buffer for the specified FileID.
@@ -994,15 +991,10 @@
 
   /// Returns the FileEntry record for the provided FileID.
   const FileEntry *getFileEntryForID(FileID FID) const {
-bool MyInvalid = false;
-const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid);
-if (MyInvalid || !Entry.isFile())
-  return nullptr;
-
-const SrcMgr::ContentCache *Content = Entry.getFile().g

[clang] 5a33859 - [CGBuiltin] Respect asm labels and redefine_extname for builtins with specialized emitting

2020-10-15 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2020-10-15T15:14:38-07:00
New Revision: 5a338599fbaa805587227779bde0a9986cb4646d

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

LOG: [CGBuiltin] Respect asm labels and redefine_extname for builtins with 
specialized emitting

rL131311 added `asm()` support for builtin functions, but `asm()` for builtins 
with
specialized emitting (e.g. memcpy, various math functions) still do not work.

This patch makes these functions work for `asm()` and `#pragma 
redefine_extname`.
glibc uses `asm()` to redirect internal libc function calls to hidden aliases.

Limitation: such a function is a builtin in clang, but will not be recognized as
a libcall in optimization passes because Clang does not annotate the renamed
function as a libcall.  In GCC -O1 or above, `abs` can be optimized out but we 
can't.
Additionally, we cannot redirect `__builtin_sin` to `real_sin` in the following 
example:

  double sin(double x) asm("real_sin");
  double f(double d) { return __builtin_sin(d); }

---

According to @rsmith, the following three statements cannot be simultaneously 
true:

(1) The frontend function foo has known, builtin semantics X.
(2) The symbol foo has known, builtin semantics X.
(3) It's not correct to lower a call to the frontend function foo to the symbol 
foo.

People do want (1) (if it is profitable to expand a memcpy, do it).
This also means that people do not want to add -fno-builtin-memcpy.
People do want (3): that is why they use asm("__GI_memcpy") in the first place.

So unfortunately we make a compromise by not refuting (2) (see the limitation 
above).
For most libcalls, there is a small loss because compilers don't synthesize 
them.
For the few glibc cares about, it uses `asm("memcpy = __GI_memcpy");` to make
the assembly level redirection.
(Changing function names (e.g. `__memcpy`) is a hit to ergonomics which is not 
acceptable).

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/asm-label.c
clang/test/CodeGen/redefine_extname.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 884fa1103163..90bfeefc9970 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1663,13 +1663,20 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
Result.Val.getFloat()));
   }
 
+  // If the builtin has been declared explicitly with an assembler label,
+  // disable the specialized emitting below. Ideally we should communicate the
+  // rename in IR, or at least avoid generating the intrinsic calls that are
+  // likely to get lowered to the renamed library functions.
+  const unsigned BuiltinIDIfNoAsmLabel =
+  FD->hasAttr() ? 0 : BuiltinID;
+
   // There are LLVM math intrinsics/instructions corresponding to math library
   // functions except the LLVM op will never set errno while the math library
   // might. Also, math builtins have the same semantics as their math library
   // twins. Thus, we can transform math library and builtin calls to their
   // LLVM counterparts if the call is marked 'const' (known to never set 
errno).
   if (FD->hasAttr()) {
-switch (BuiltinID) {
+switch (BuiltinIDIfNoAsmLabel) {
 case Builtin::BIceil:
 case Builtin::BIceilf:
 case Builtin::BIceill:
@@ -1946,7 +1953,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 }
   }
 
-  switch (BuiltinID) {
+  switch (BuiltinIDIfNoAsmLabel) {
   default: break;
   case Builtin::BI__builtin___CFStringMakeConstantString:
   case Builtin::BI__builtin___NSStringMakeConstantString:

diff  --git a/clang/test/CodeGen/asm-label.c b/clang/test/CodeGen/asm-label.c
index 7c7383fa41fc..093f31fc59c4 100644
--- a/clang/test/CodeGen/asm-label.c
+++ b/clang/test/CodeGen/asm-label.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple=i686-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s 
--check-prefix=LINUX
-// RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm %s -o - | FileCheck 
%s --check-prefix=DARWIN
+// RUN: %clang_cc1 -triple=i686-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,LINUX
+// RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm %s -o - | FileCheck 
%s --check-prefixes=CHECK,DARWIN
 
 char *strerror(int) asm("alias");
 int x __asm("foo");
@@ -17,3 +17,39 @@ int *test(void) {
 // DARWIN: @"\01bar" = internal global i32 0
 // DARWIN: @"\01foo" = global i32 0
 // DARWIN: declare i8* @"\01alias"(i32)
+
+extern void *memcpy(void *__restrict, const void *__restrict, unsigned long);
+extern __typeof(memcpy) memcpy asm("__GI_memcpy");
+void test_memcpy(voi

[PATCH] D88712: [CGBuiltin] Respect asm labels and redefine_extname for builtins with specialized emitting

2020-10-15 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5a338599fbaa: [CGBuiltin] Respect asm labels and 
redefine_extname for builtins with… (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88712

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/asm-label.c
  clang/test/CodeGen/redefine_extname.c

Index: clang/test/CodeGen/redefine_extname.c
===
--- clang/test/CodeGen/redefine_extname.c
+++ clang/test/CodeGen/redefine_extname.c
@@ -30,3 +30,9 @@
 int baz() { return foo_static(); }
 // CHECK-NOT: call i32 @bar_static()
 
+// Check that pragma redefine_extname applies to builtin functions.
+typedef unsigned long size_t;
+extern void *memcpy(void *, const void *, size_t);
+#pragma redefine_extname memcpy __GI_memcpy
+void *test_memcpy(void *dst, const void *src, size_t n) { return memcpy(dst, src, n); }
+// CHECK: call i8* @__GI_memcpy(
Index: clang/test/CodeGen/asm-label.c
===
--- clang/test/CodeGen/asm-label.c
+++ clang/test/CodeGen/asm-label.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple=i686-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=LINUX
-// RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm %s -o - | FileCheck %s --check-prefix=DARWIN
+// RUN: %clang_cc1 -triple=i686-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,LINUX
+// RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,DARWIN
 
 char *strerror(int) asm("alias");
 int x __asm("foo");
@@ -17,3 +17,39 @@
 // DARWIN: @"\01bar" = internal global i32 0
 // DARWIN: @"\01foo" = global i32 0
 // DARWIN: declare i8* @"\01alias"(i32)
+
+extern void *memcpy(void *__restrict, const void *__restrict, unsigned long);
+extern __typeof(memcpy) memcpy asm("__GI_memcpy");
+void test_memcpy(void *dst, void *src, unsigned long n) {
+  memcpy(dst, src, n);
+}
+// CHECK-LABEL: @test_memcpy(
+// LINUX: call i8* @__GI_memcpy(
+// LINUX:   declare i8* @__GI_memcpy(i8*, i8*, i32)
+// DARWIN:call i8* @"\01__GI_memcpy"(
+// DARWIN:  declare i8* @"\01__GI_memcpy"(i8*, i8*, i32)
+
+long lrint(double x) asm("__GI_lrint");
+long test_lrint(double x) {
+  return lrint(x);
+}
+// CHECK-LABEL: @test_lrint(
+// LINUX: call i32 @__GI_lrint(
+// LINUX:   declare i32 @__GI_lrint(double)
+// DARWIN:call i32 @"\01__GI_lrint"(
+// DARWIN:  declare i32 @"\01__GI_lrint"(double)
+
+/// NOTE: GCC can optimize out abs in -O1 or above. Clang does not
+/// communicate the mapping to the backend so the libcall cannot be eliminated.
+int abs(int x) asm("__GI_abs");
+long test_abs(int x) {
+  return abs(x);
+}
+// CHECK-LABEL: @test_abs(
+// LINUX: call i32 @__GI_abs(
+
+/// FIXME: test_sin should call real_sin instead.
+double sin(double x) asm("real_sin");
+double test_sin(double d) { return __builtin_sin(d); }
+// CHECK-LABEL: @test_sin(
+// LINUX: call double @llvm.sin.f64(
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1663,13 +1663,20 @@
Result.Val.getFloat()));
   }
 
+  // If the builtin has been declared explicitly with an assembler label,
+  // disable the specialized emitting below. Ideally we should communicate the
+  // rename in IR, or at least avoid generating the intrinsic calls that are
+  // likely to get lowered to the renamed library functions.
+  const unsigned BuiltinIDIfNoAsmLabel =
+  FD->hasAttr() ? 0 : BuiltinID;
+
   // There are LLVM math intrinsics/instructions corresponding to math library
   // functions except the LLVM op will never set errno while the math library
   // might. Also, math builtins have the same semantics as their math library
   // twins. Thus, we can transform math library and builtin calls to their
   // LLVM counterparts if the call is marked 'const' (known to never set errno).
   if (FD->hasAttr()) {
-switch (BuiltinID) {
+switch (BuiltinIDIfNoAsmLabel) {
 case Builtin::BIceil:
 case Builtin::BIceilf:
 case Builtin::BIceill:
@@ -1946,7 +1953,7 @@
 }
   }
 
-  switch (BuiltinID) {
+  switch (BuiltinIDIfNoAsmLabel) {
   default: break;
   case Builtin::BI__builtin___CFStringMakeConstantString:
   case Builtin::BI__builtin___NSStringMakeConstantString:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88712: [CGBuiltin] Respect asm labels and redefine_extname for builtins with specialized emitting

2020-10-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 298480.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Add an example about inconsistency. Elaborate on the limitation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88712

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/asm-label.c
  clang/test/CodeGen/redefine_extname.c

Index: clang/test/CodeGen/redefine_extname.c
===
--- clang/test/CodeGen/redefine_extname.c
+++ clang/test/CodeGen/redefine_extname.c
@@ -30,3 +30,9 @@
 int baz() { return foo_static(); }
 // CHECK-NOT: call i32 @bar_static()
 
+// Check that pragma redefine_extname applies to builtin functions.
+typedef unsigned long size_t;
+extern void *memcpy(void *, const void *, size_t);
+#pragma redefine_extname memcpy __GI_memcpy
+void *test_memcpy(void *dst, const void *src, size_t n) { return memcpy(dst, src, n); }
+// CHECK: call i8* @__GI_memcpy(
Index: clang/test/CodeGen/asm-label.c
===
--- clang/test/CodeGen/asm-label.c
+++ clang/test/CodeGen/asm-label.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple=i686-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=LINUX
-// RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm %s -o - | FileCheck %s --check-prefix=DARWIN
+// RUN: %clang_cc1 -triple=i686-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,LINUX
+// RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,DARWIN
 
 char *strerror(int) asm("alias");
 int x __asm("foo");
@@ -17,3 +17,39 @@
 // DARWIN: @"\01bar" = internal global i32 0
 // DARWIN: @"\01foo" = global i32 0
 // DARWIN: declare i8* @"\01alias"(i32)
+
+extern void *memcpy(void *__restrict, const void *__restrict, unsigned long);
+extern __typeof(memcpy) memcpy asm("__GI_memcpy");
+void test_memcpy(void *dst, void *src, unsigned long n) {
+  memcpy(dst, src, n);
+}
+// CHECK-LABEL: @test_memcpy(
+// LINUX: call i8* @__GI_memcpy(
+// LINUX:   declare i8* @__GI_memcpy(i8*, i8*, i32)
+// DARWIN:call i8* @"\01__GI_memcpy"(
+// DARWIN:  declare i8* @"\01__GI_memcpy"(i8*, i8*, i32)
+
+long lrint(double x) asm("__GI_lrint");
+long test_lrint(double x) {
+  return lrint(x);
+}
+// CHECK-LABEL: @test_lrint(
+// LINUX: call i32 @__GI_lrint(
+// LINUX:   declare i32 @__GI_lrint(double)
+// DARWIN:call i32 @"\01__GI_lrint"(
+// DARWIN:  declare i32 @"\01__GI_lrint"(double)
+
+/// NOTE: GCC can optimize out abs in -O1 or above. Clang does not
+/// communicate the mapping to the backend so the libcall cannot be eliminated.
+int abs(int x) asm("__GI_abs");
+long test_abs(int x) {
+  return abs(x);
+}
+// CHECK-LABEL: @test_abs(
+// LINUX: call i32 @__GI_abs(
+
+/// FIXME: test_sin should call real_sin instead.
+double sin(double x) asm("real_sin");
+double test_sin(double d) { return __builtin_sin(d); }
+// CHECK-LABEL: @test_sin(
+// LINUX: call double @llvm.sin.f64(
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1663,13 +1663,20 @@
Result.Val.getFloat()));
   }
 
+  // If the builtin has been declared explicitly with an assembler label,
+  // disable the specialized emitting below. Ideally we should communicate the
+  // rename in IR, or at least avoid generating the intrinsic calls that are
+  // likely to get lowered to the renamed library functions.
+  const unsigned BuiltinIDIfNoAsmLabel =
+  FD->hasAttr() ? 0 : BuiltinID;
+
   // There are LLVM math intrinsics/instructions corresponding to math library
   // functions except the LLVM op will never set errno while the math library
   // might. Also, math builtins have the same semantics as their math library
   // twins. Thus, we can transform math library and builtin calls to their
   // LLVM counterparts if the call is marked 'const' (known to never set errno).
   if (FD->hasAttr()) {
-switch (BuiltinID) {
+switch (BuiltinIDIfNoAsmLabel) {
 case Builtin::BIceil:
 case Builtin::BIceilf:
 case Builtin::BIceill:
@@ -1946,7 +1953,7 @@
 }
   }
 
-  switch (BuiltinID) {
+  switch (BuiltinIDIfNoAsmLabel) {
   default: break;
   case Builtin::BI__builtin___CFStringMakeConstantString:
   case Builtin::BI__builtin___NSStringMakeConstantString:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88712: [CGBuiltin] Respect asm labels and redefine_extname for builtins with specialized emitting

2020-10-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D88712#2333294 , @rsmith wrote:

> If the answer is that we consider (2) to be incorrect, but that this is only 
> a partial step in that direction, I think that's fine -- that's enough that 
> we can know where the bug is if / when people complain that we still generate 
> calls to `memcpy` even when we used an `asm` label to indicate the library 
> symbol was renamed to something else. In that light, this is really a 
> workaround rather than a fix: we can't easily stop the middle-end from 
> synthesizing calls to library functions with the wrong symbol, because we 
> don't have a good way to tell it those library functions were renamed, but we 
> can at least reduce the rate of incidence by avoiding generating the 
> intrinsic calls that are likely to get lowered to library functions.
>
> Given that understanding, should this:
>
>   double sin(double x) asm("real_sin");
>   double f(double d) { return __builtin_sin(d); }
>
> ... call the `sin` symbol or the `real_sin` symbol? I think with the current 
> patch it'll call the `sin` symbol, but calling `real_sin` seems correct.
>
> In any case, assuming the above understanding is right, this looks like a 
> step in the right direction.

Thanks for the review! For this example, GCC emits `real_sin` but we fail to do 
so. Added it to the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88712

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


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-15 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D85802#2333247 , @rsmith wrote:

> In D85802#2333105 , @leonardchan 
> wrote:
>
>> In D85802#2332895 , @phosek wrote:
>>
>>> In D85802#2332808 , @rnk wrote:
>>>
 Would "f[no-]fuchsia-c++-abi-extensions" (or shorter, -ffuchsia-c++-abi) 
 do the trick? I know it doesn't map well onto our current internal option 
 representation, but I don't think the internal representation is 
 particularly good. I'd rather limit the user-visible driver interface to 
 give us the flexibility to change the internal representation in the 
 future.
>>>
>>> For our use case yes, we could have `-f[no-]fuchsia-c++-abi` which would be 
>>> enabled by default when the target is Fuchsia.
>>
>> Will send out another patch that will use this instead. We can probably 
>> revert this in the meantime.
>
> Have you considered using a different target triple for the different C++ ABI 
> modes?

We didn't but that might be even better than introducing a custom flag. I see 
that Itanium is already in the list of environments 

 so we could most likely just use that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[clang] 5fbab40 - [MS] Apply `inreg` to AArch64 sret parms on instance methods

2020-10-15 Thread Reid Kleckner via cfe-commits

Author: Reid Kleckner
Date: 2020-10-15T14:54:42-07:00
New Revision: 5fbab4025eb57b12f2842ab188ff07a110708e1d

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

LOG: [MS] Apply `inreg` to AArch64 sret parms on instance methods

The documentation rules indicate that instance methods should return
large, trivially copyable aggregates via X1/X0 and not X8 as is normally
done when returning such structs from free functions:
https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=vs-2019#return-values

Fixes PR47836, a bug in the initial implementation of these rules.

I tried to simplify the logic a bit as well while I'm here.

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

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index cae79099dd6b..31e7e4c66901 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1070,11 +1070,7 @@ bool MicrosoftCXXABI::hasMostDerivedReturn(GlobalDecl 
GD) const {
   return isDeletingDtor(GD);
 }
 
-static bool IsSizeGreaterThan128(const CXXRecordDecl *RD) {
-  return RD->getASTContext().getTypeSize(RD->getTypeForDecl()) > 128;
-}
-
-static bool hasMicrosoftABIRestrictions(const CXXRecordDecl *RD) {
+static bool isCXX14Aggregate(const CXXRecordDecl *RD) {
   // For AArch64, we use the C++14 definition of an aggregate, so we also
   // check for:
   //   No private or protected non static data members.
@@ -1083,19 +1079,19 @@ static bool hasMicrosoftABIRestrictions(const 
CXXRecordDecl *RD) {
   // Additionally, we need to ensure that there is a trivial copy assignment
   // operator, a trivial destructor and no user-provided constructors.
   if (RD->hasProtectedFields() || RD->hasPrivateFields())
-return true;
+return false;
   if (RD->getNumBases() > 0)
-return true;
+return false;
   if (RD->isPolymorphic())
-return true;
+return false;
   if (RD->hasNonTrivialCopyAssignment())
-return true;
+return false;
   for (const CXXConstructorDecl *Ctor : RD->ctors())
 if (Ctor->isUserProvided())
-  return true;
+  return false;
   if (RD->hasNonTrivialDestructor())
-return true;
-  return false;
+return false;
+  return true;
 }
 
 bool MicrosoftCXXABI::classifyReturnType(CGFunctionInfo &FI) const {
@@ -1103,21 +1099,29 @@ bool MicrosoftCXXABI::classifyReturnType(CGFunctionInfo 
&FI) const {
   if (!RD)
 return false;
 
+  // Normally, the C++ concept of "is trivially copyable" is used to determine
+  // if a struct can be returned directly. However, as MSVC and the language
+  // have evolved, the definition of "trivially copyable" has changed, while 
the
+  // ABI must remain stable. AArch64 uses the C++14 concept of an "aggregate",
+  // while other ISAs use the older concept of "plain old data".
+  bool isTrivialForABI = RD->isPOD();
   bool isAArch64 = CGM.getTarget().getTriple().isAArch64();
-  bool isSimple = !isAArch64 || !hasMicrosoftABIRestrictions(RD);
-  bool isIndirectReturn =
-  isAArch64 ? (!RD->canPassInRegisters() ||
-   IsSizeGreaterThan128(RD))
-: !RD->isPOD();
-  bool isInstanceMethod = FI.isInstanceMethod();
-
-  if (isIndirectReturn || !isSimple || isInstanceMethod) {
+  if (isAArch64)
+isTrivialForABI = RD->canPassInRegisters() && isCXX14Aggregate(RD);
+
+  // MSVC always returns structs indirectly from C++ instance methods.
+  bool isIndirectReturn = !isTrivialForABI || FI.isInstanceMethod();
+
+  if (isIndirectReturn) {
 CharUnits Align = CGM.getContext().getTypeAlignInChars(FI.getReturnType());
 FI.getReturnInfo() = ABIArgInfo::getIndirect(Align, /*ByVal=*/false);
-FI.getReturnInfo().setSRetAfterThis(isInstanceMethod);
 
-FI.getReturnInfo().setInReg(isAArch64 &&
-!(isSimple && IsSizeGreaterThan128(RD)));
+// MSVC always passes `this` before the `sret` parameter.
+FI.getReturnInfo().setSRetAfterThis(FI.isInstanceMethod());
+
+// On AArch64, use the `inreg` attribute if the object is considered to not
+// be trivially copyable, or if this is an instance method struct return.
+FI.getReturnInfo().setInReg(isAArch64);
 
 return true;
   }

diff  --git a/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp 
b/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
index c490deea4c28..139fd88e6e09 100644
--- a/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
+++ b/clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
@@ -87,17 +87,20 @@ Small small_return() { return Small(); }
 // LINUX-LABEL: define void @_Z12small_return

[PATCH] D89362: [MS] Apply `inreg` to AArch64 sret parms on instance methods

2020-10-15 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5fbab4025eb5: [MS] Apply `inreg` to AArch64 sret parms on 
instance methods (authored by rnk).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89362

Files:
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp

Index: clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
@@ -87,17 +87,20 @@
 // LINUX-LABEL: define void @_Z12small_returnv(%struct.Small* noalias sret align 4 %agg.result)
 // WIN32: define dso_local i32 @"?small_return@@YA?AUSmall@@XZ"()
 // WIN64: define dso_local i32 @"?small_return@@YA?AUSmall@@XZ"()
+// WOA64: define dso_local i64 @"?small_return@@YA?AUSmall@@XZ"()
 
 Medium medium_return() { return Medium(); }
 // LINUX-LABEL: define void @_Z13medium_returnv(%struct.Medium* noalias sret align 4 %agg.result)
 // WIN32: define dso_local i64 @"?medium_return@@YA?AUMedium@@XZ"()
 // WIN64: define dso_local i64 @"?medium_return@@YA?AUMedium@@XZ"()
+// WOA64: define dso_local i64 @"?medium_return@@YA?AUMedium@@XZ"()
 
 // Returning structs that fit into a register but are not POD.
 SmallCpp11NotCpp03Pod small_non_pod_return() { return SmallCpp11NotCpp03Pod(); }
 // LINUX-LABEL: define void @_Z20small_non_pod_returnv(%struct.SmallCpp11NotCpp03Pod* noalias sret align 4 %agg.result)
 // WIN32: define dso_local void @"?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret align 4 %agg.result)
 // WIN64: define dso_local void @"?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret align 4 %agg.result)
+// WOA64: define dso_local void @"?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* inreg noalias sret align 4 %agg.result)
 
 SmallWithCtor small_with_ctor_return() { return SmallWithCtor(); }
 // LINUX-LABEL: define void @_Z22small_with_ctor_returnv(%struct.SmallWithCtor* noalias sret align 4 %agg.result)
@@ -106,23 +109,33 @@
 // FIXME: The 'sret' mark here doesn't seem to be enough to convince LLVM to
 // preserve the hidden sret pointer in R0 across the function.
 // WOA: define dso_local arm_aapcs_vfpcc void @"?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret align 4 %agg.result)
+// WOA64: define dso_local void @"?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* inreg noalias sret align 4 %agg.result)
+
+SmallWithDtor small_with_dtor_return() { return SmallWithDtor(); }
+// LINUX-LABEL: define void @_Z22small_with_dtor_returnv(%struct.SmallWithDtor* noalias sret align 4 %agg.result)
+// WIN32: define dso_local void @"?small_with_dtor_return@@YA?AUSmallWithDtor@@XZ"(%struct.SmallWithDtor* noalias sret align 4 %agg.result)
+// WIN64: define dso_local void @"?small_with_dtor_return@@YA?AUSmallWithDtor@@XZ"(%struct.SmallWithDtor* noalias sret align 4 %agg.result)
+// WOA64: define dso_local void @"?small_with_dtor_return@@YA?AUSmallWithDtor@@XZ"(%struct.SmallWithDtor* inreg noalias sret align 4 %agg.result)
 
 SmallWithVftable small_with_vftable_return() { return SmallWithVftable(); }
 // LINUX-LABEL: define void @_Z25small_with_vftable_returnv(%struct.SmallWithVftable* noalias sret align 4 %agg.result)
 // WIN32: define dso_local void @"?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret align 4 %agg.result)
 // WIN64: define dso_local void @"?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret align 8 %agg.result)
+// WOA64: define dso_local void @"?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* inreg noalias sret align 8 %agg.result)
 
 MediumWithCopyCtor medium_with_copy_ctor_return() { return MediumWithCopyCtor(); }
 // LINUX-LABEL: define void @_Z28medium_with_copy_ctor_returnv(%struct.MediumWithCopyCtor* noalias sret align 4 %agg.result)
 // WIN32: define dso_local void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret align 4 %agg.result)
 // WIN64: define dso_local void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret align 4 %agg.result)
 // WOA: define dso_local arm_aapcs_vfpcc void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret align 4 %agg.result)
+// WOA64: define dso_local void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* inreg noalias sret align 4 %agg.result)
 
 // Returning a large struct that doesn't fit into a register.
 Big b

[PATCH] D74130: [clang] fix consteval call in default arguements

2020-10-15 Thread Ronan Keryell via Phabricator via cfe-commits
keryell added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:16329
 
+  /// If we can't handle immediate invocations yet. add them to the outer 
scope.
+  /// This occurs for default argument of lambdas as we can't know if the 
lambda




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74130

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


[PATCH] D89362: [MS] Apply `inreg` to AArch64 sret parms on instance methods

2020-10-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

Makes a lot more sense now.  LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89362

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


[PATCH] D89362: [MS] Apply `inreg` to AArch64 sret parms on instance methods

2020-10-15 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 298473.
rnk added a comment.

- simplify some more


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89362

Files:
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp

Index: clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
@@ -87,17 +87,20 @@
 // LINUX-LABEL: define void @_Z12small_returnv(%struct.Small* noalias sret align 4 %agg.result)
 // WIN32: define dso_local i32 @"?small_return@@YA?AUSmall@@XZ"()
 // WIN64: define dso_local i32 @"?small_return@@YA?AUSmall@@XZ"()
+// WOA64: define dso_local i64 @"?small_return@@YA?AUSmall@@XZ"()
 
 Medium medium_return() { return Medium(); }
 // LINUX-LABEL: define void @_Z13medium_returnv(%struct.Medium* noalias sret align 4 %agg.result)
 // WIN32: define dso_local i64 @"?medium_return@@YA?AUMedium@@XZ"()
 // WIN64: define dso_local i64 @"?medium_return@@YA?AUMedium@@XZ"()
+// WOA64: define dso_local i64 @"?medium_return@@YA?AUMedium@@XZ"()
 
 // Returning structs that fit into a register but are not POD.
 SmallCpp11NotCpp03Pod small_non_pod_return() { return SmallCpp11NotCpp03Pod(); }
 // LINUX-LABEL: define void @_Z20small_non_pod_returnv(%struct.SmallCpp11NotCpp03Pod* noalias sret align 4 %agg.result)
 // WIN32: define dso_local void @"?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret align 4 %agg.result)
 // WIN64: define dso_local void @"?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret align 4 %agg.result)
+// WOA64: define dso_local void @"?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* inreg noalias sret align 4 %agg.result)
 
 SmallWithCtor small_with_ctor_return() { return SmallWithCtor(); }
 // LINUX-LABEL: define void @_Z22small_with_ctor_returnv(%struct.SmallWithCtor* noalias sret align 4 %agg.result)
@@ -106,23 +109,33 @@
 // FIXME: The 'sret' mark here doesn't seem to be enough to convince LLVM to
 // preserve the hidden sret pointer in R0 across the function.
 // WOA: define dso_local arm_aapcs_vfpcc void @"?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret align 4 %agg.result)
+// WOA64: define dso_local void @"?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* inreg noalias sret align 4 %agg.result)
+
+SmallWithDtor small_with_dtor_return() { return SmallWithDtor(); }
+// LINUX-LABEL: define void @_Z22small_with_dtor_returnv(%struct.SmallWithDtor* noalias sret align 4 %agg.result)
+// WIN32: define dso_local void @"?small_with_dtor_return@@YA?AUSmallWithDtor@@XZ"(%struct.SmallWithDtor* noalias sret align 4 %agg.result)
+// WIN64: define dso_local void @"?small_with_dtor_return@@YA?AUSmallWithDtor@@XZ"(%struct.SmallWithDtor* noalias sret align 4 %agg.result)
+// WOA64: define dso_local void @"?small_with_dtor_return@@YA?AUSmallWithDtor@@XZ"(%struct.SmallWithDtor* inreg noalias sret align 4 %agg.result)
 
 SmallWithVftable small_with_vftable_return() { return SmallWithVftable(); }
 // LINUX-LABEL: define void @_Z25small_with_vftable_returnv(%struct.SmallWithVftable* noalias sret align 4 %agg.result)
 // WIN32: define dso_local void @"?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret align 4 %agg.result)
 // WIN64: define dso_local void @"?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret align 8 %agg.result)
+// WOA64: define dso_local void @"?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* inreg noalias sret align 8 %agg.result)
 
 MediumWithCopyCtor medium_with_copy_ctor_return() { return MediumWithCopyCtor(); }
 // LINUX-LABEL: define void @_Z28medium_with_copy_ctor_returnv(%struct.MediumWithCopyCtor* noalias sret align 4 %agg.result)
 // WIN32: define dso_local void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret align 4 %agg.result)
 // WIN64: define dso_local void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret align 4 %agg.result)
 // WOA: define dso_local arm_aapcs_vfpcc void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret align 4 %agg.result)
+// WOA64: define dso_local void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* inreg noalias sret align 4 %agg.result)
 
 // Returning a large struct that doesn't fit into a register.
 Big big_return() { return Big(); }
 // LINUX-LABEL: define void @_Z10big_returnv(%struct.Big* noalias sret align 4 %agg.result)
 // WIN32: define dso_local void @"

[PATCH] D88712: [CGBuiltin] Respect asm labels and redefine_extname for builtins with specialized emitting

2020-10-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

If the answer is that we consider (2) to be incorrect, but that this is only a 
partial step in that direction, I think that's fine -- that's enough that we 
can know where the bug is if / when people complain that we still generate 
calls to `memcpy` even when we used an `asm` label to indicate the library 
symbol was renamed to something else. In that light, this is really a 
workaround rather than a fix: we can't easily stop the middle-end from 
synthesizing calls to library functions with the wrong symbol, because we don't 
have a good way to tell it those library functions were renamed, but we can at 
least reduce the rate of incidence by avoiding generating the intrinsic calls 
that are likely to get lowered to library functions.

Given that understanding, should this:

  double sin(double x) asm("real_sin");
  double f(double d) { return __builtin_sin(d); }

... call the `sin` symbol or the `real_sin` symbol? I think with the current 
patch it'll call the `sin` symbol, but calling `real_sin` seems correct.

In any case, assuming the above understanding is right, this looks like a step 
in the right direction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88712

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


[PATCH] D89498: HeaderSearch: Simplify use of FileEntryRef in HeaderSearch::LookupFile, NFC

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

Simplify `HeaderSearch::LookupFile`. Instead of deconstructing a
`FileEntryRef` into a name and `FileEntry` and then rebuilding it later,
use it as is. This helps to unblock making the constructor of
`FileEntryRef` private to `FileManager`.


https://reviews.llvm.org/D89498

Files:
  clang/lib/Lex/HeaderSearch.cpp


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -765,8 +765,7 @@
 
   // This is the header that MSVC's header search would have found.
   ModuleMap::KnownHeader MSSuggestedModule;
-  const FileEntry *MSFE_FE = nullptr;
-  StringRef MSFE_Name;
+  Optional MSFE;
 
   // Unless disabled, check to see if the file is in the #includer's
   // directory.  This cannot be based on CurDir, because each includer could be
@@ -841,8 +840,7 @@
 if (Diags.isIgnored(diag::ext_pp_include_search_ms, IncludeLoc)) {
   return FE;
 } else {
-  MSFE_FE = &FE->getFileEntry();
-  MSFE_Name = FE->getName();
+  MSFE = FE;
   if (SuggestedModule) {
 MSSuggestedModule = *SuggestedModule;
 *SuggestedModule = ModuleMap::KnownHeader();
@@ -854,9 +852,6 @@
 }
   }
 
-  Optional MSFE(MSFE_FE ? FileEntryRef(MSFE_Name, *MSFE_FE)
-  : Optional());
-
   CurDir = nullptr;
 
   // If this is a system #include, ignore the user #include locs.


Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -765,8 +765,7 @@
 
   // This is the header that MSVC's header search would have found.
   ModuleMap::KnownHeader MSSuggestedModule;
-  const FileEntry *MSFE_FE = nullptr;
-  StringRef MSFE_Name;
+  Optional MSFE;
 
   // Unless disabled, check to see if the file is in the #includer's
   // directory.  This cannot be based on CurDir, because each includer could be
@@ -841,8 +840,7 @@
 if (Diags.isIgnored(diag::ext_pp_include_search_ms, IncludeLoc)) {
   return FE;
 } else {
-  MSFE_FE = &FE->getFileEntry();
-  MSFE_Name = FE->getName();
+  MSFE = FE;
   if (SuggestedModule) {
 MSSuggestedModule = *SuggestedModule;
 *SuggestedModule = ModuleMap::KnownHeader();
@@ -854,9 +852,6 @@
 }
   }
 
-  Optional MSFE(MSFE_FE ? FileEntryRef(MSFE_Name, *MSFE_FE)
-  : Optional());
-
   CurDir = nullptr;
 
   // If this is a system #include, ignore the user #include locs.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e384e94 - Revert "[HIP] Change default --gpu-max-threads-per-block value to 1024"

2020-10-15 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2020-10-15T17:25:55-04:00
New Revision: e384e94fbe7c1d5c89fcdde33ffda04e9802c2ce

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

LOG: Revert "[HIP] Change default --gpu-max-threads-per-block value to 1024"

This reverts commit 187658b8a6112446d9e7797d495bc7542ac83905 due to
AMDGPU backend issues.

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
clang/test/CodeGenCUDA/kernel-amdgcn.cu

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 3132e7635418..9846809763f8 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -240,7 +240,7 @@ LANGOPT(CUDAHostDeviceConstexpr, 1, 1, "treating 
unattributed constexpr function
 LANGOPT(CUDADeviceApproxTranscendentals, 1, 0, "using approximate 
transcendental functions")
 LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code")
 LANGOPT(GPUAllowDeviceInit, 1, 0, "allowing device side global init functions 
for HIP")
-LANGOPT(GPUMaxThreadsPerBlock, 32, 1024, "default max threads per block for 
kernel launch bounds for HIP")
+LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for 
kernel launch bounds for HIP")
 
 LANGOPT(SYCL  , 1, 0, "SYCL")
 LANGOPT(SYCLIsDevice  , 1, 0, "Generate code for SYCL device")

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 31fbe393e8d2..83b97775b96c 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -9059,13 +9059,9 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes(
   assert(Max == 0 && "Max must be zero");
   } else if (IsOpenCLKernel || IsHIPKernel) {
 // By default, restrict the maximum size to a value specified by
-// --gpu-max-threads-per-block=n or its default value for HIP.
-const unsigned OpenCLDefaultMaxWorkGroupSize = 256;
-const unsigned DefaultMaxWorkGroupSize =
-IsOpenCLKernel ? OpenCLDefaultMaxWorkGroupSize
-   : M.getLangOpts().GPUMaxThreadsPerBlock;
+// --gpu-max-threads-per-block=n or its default value.
 std::string AttrVal =
-std::string("1,") + llvm::utostr(DefaultMaxWorkGroupSize);
+std::string("1,") + 
llvm::utostr(M.getLangOpts().GPUMaxThreadsPerBlock);
 F->addFnAttr("amdgpu-flat-work-group-size", AttrVal);
   }
 

diff  --git a/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu 
b/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
index 7a9fd2527272..5415bddffc89 100644
--- a/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
@@ -39,7 +39,7 @@ __global__ void num_vgpr_64() {
 // NAMD-NOT: "amdgpu-num-vgpr"
 // NAMD-NOT: "amdgpu-num-sgpr"
 
-// DEFAULT-DAG: attributes [[FLAT_WORK_GROUP_SIZE_DEFAULT]] = 
{{.*}}"amdgpu-flat-work-group-size"="1,1024"{{.*}}"uniform-work-group-size"="true"
+// DEFAULT-DAG: attributes [[FLAT_WORK_GROUP_SIZE_DEFAULT]] = 
{{.*}}"amdgpu-flat-work-group-size"="1,256"{{.*}}"uniform-work-group-size"="true"
 // MAX1024-DAG: attributes [[FLAT_WORK_GROUP_SIZE_DEFAULT]] = 
{{.*}}"amdgpu-flat-work-group-size"="1,1024"
 // CHECK-DAG: attributes [[FLAT_WORK_GROUP_SIZE_32_64]] = 
{{.*}}"amdgpu-flat-work-group-size"="32,64"
 // CHECK-DAG: attributes [[WAVES_PER_EU_2]] = {{.*}}"amdgpu-waves-per-eu"="2"

diff  --git a/clang/test/CodeGenCUDA/kernel-amdgcn.cu 
b/clang/test/CodeGenCUDA/kernel-amdgcn.cu
index 6066469f7647..135d3030480c 100644
--- a/clang/test/CodeGenCUDA/kernel-amdgcn.cu
+++ b/clang/test/CodeGenCUDA/kernel-amdgcn.cu
@@ -39,4 +39,4 @@ int main() {
   launch((void*)D.Empty());
   return 0;
 }
-// CHECK: attributes #[[ATTR]] = {{.*}}"amdgpu-flat-work-group-size"="1,1024"
+// CHECK: attributes #[[ATTR]] = {{.*}}"amdgpu-flat-work-group-size"="1,256"



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


[clang] 79829a4 - Revert "[clang] Add -fc++-abi= flag for specifying which C++ ABI to use"

2020-10-15 Thread Leonard Chan via cfe-commits

Author: Leonard Chan
Date: 2020-10-15T14:24:38-07:00
New Revision: 79829a47040512fe54001db839ac59146ca55aec

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

LOG: Revert "[clang] Add -fc++-abi= flag for specifying which C++ ABI to use"

This reverts commits 683b308c07bf827255fe1403056413f790e03729 and
8487bfd4e9ae186f9f588ef989d27a96cc2438c9.

We will go for a more restricted approach that does not give freedom to
everyone to change ABIs on whichever platform.

See the discussion on https://reviews.llvm.org/D85802.

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Basic/TargetCXXABI.h
clang/include/clang/Driver/Options.td
clang/lib/AST/ASTContext.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 
clang/include/clang/Basic/TargetCXXABI.def
clang/test/Frontend/invalid-cxx-abi.cpp



diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index e5c80866a0a9..3f4079e2569b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -39,7 +39,6 @@
 #include "clang/Basic/SanitizerBlacklist.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
-#include "clang/Basic/TargetCXXABI.h"
 #include "clang/Basic/XRayLists.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -698,11 +697,6 @@ class ASTContext : public RefCountedBase {
 return FullSourceLoc(Loc,SourceMgr);
   }
 
-  /// Return the C++ ABI kind that should be used. The C++ ABI can be overriden
-  /// at compile time with `-fc++-abi=`. If this is not provided, we instead 
use
-  /// the default ABI set by the target.
-  TargetCXXABI::Kind getCXXABIKind() const;
-
   /// All comments in this translation unit.
   RawCommentList Comments;
 

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index d87983ef5249..29bc19e5a84e 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -524,6 +524,4 @@ def err_drv_invalid_object_mode : Error<"OBJECT_MODE 
setting %0 is not recognize
 
 def err_drv_invalid_sve_vector_bits : Error<
   "'-msve-vector-bits' is not supported without SVE enabled">;
-
-def err_invalid_cxx_abi : Error<"invalid C++ ABI name '%0'">;
 }

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 147fab614308..84d25c359c55 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -18,7 +18,6 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Sanitizers.h"
-#include "clang/Basic/TargetCXXABI.h"
 #include "clang/Basic/Visibility.h"
 #include "llvm/ADT/FloatingPointMode.h"
 #include "llvm/ADT/StringRef.h"
@@ -295,10 +294,6 @@ class LangOptions : public LangOptionsBase {
   /// host code generation.
   std::string OMPHostIRFile;
 
-  /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
-  /// This overrides the default ABI used by the target.
-  llvm::Optional CXXABI;
-
   /// Indicates whether the front-end is explicitly told that the
   /// input is a header file (i.e. -x c-header).
   bool IsHeaderFile = false;

diff  --git a/clang/include/clang/Basic/TargetCXXABI.def 
b/clang/include/clang/Basic/TargetCXXABI.def
deleted file mode 100644
index 0ae0bb555f60..
--- a/clang/include/clang/Basic/TargetCXXABI.def
+++ /dev/null
@@ -1,129 +0,0 @@
-//===--- TargetCXXABI.def - Target C++ ABI database --- 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
-//
-//===--===//
-//
-// This file defines the various C++ ABI kinds used on 
diff erent platforms.
-// Users of this file must define the CXXABI macro to make use of this
-// information.
-//
-//===--===//
-
-#ifndef CXXABI
-#error Define the CXXABI macro to handle C++ ABI kinds.
-#endif
-
-#ifndef ITANIUM_CXXABI
-#define ITANIUM_CXXABI(Name, Str) CXXABI(Name, Str)
-#endif
-
-#ifndef MICROSOFT_CXXABI
-#define MICROSOFT_CXXABI(Name, Str) CXXABI(Name, Str)
-#endif
-
-/// The generic Itanium ABI is the standard ABI of most open-source
-/// and Unix-like platforms.  It is the primary 

[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D85802#2333105 , @leonardchan wrote:

> In D85802#2332895 , @phosek wrote:
>
>> In D85802#2332808 , @rnk wrote:
>>
>>> Would "f[no-]fuchsia-c++-abi-extensions" (or shorter, -ffuchsia-c++-abi) do 
>>> the trick? I know it doesn't map well onto our current internal option 
>>> representation, but I don't think the internal representation is 
>>> particularly good. I'd rather limit the user-visible driver interface to 
>>> give us the flexibility to change the internal representation in the future.
>>
>> For our use case yes, we could have `-f[no-]fuchsia-c++-abi` which would be 
>> enabled by default when the target is Fuchsia.
>
> Will send out another patch that will use this instead. We can probably 
> revert this in the meantime.

Have you considered using a different target triple for the different C++ ABI 
modes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D88676: [PPC][AIX] Add vector callee saved registers for AIX extended vector ABI and add clang and llvm option

2020-10-15 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L added a comment.

I am wondering can we split the option related changes to a separate patch for 
reviews? That would make current patch a bit easier to review and faster to be 
committed as two small pieces.

If it's possible, I am thinking we can try to split it up to the following two 
pieces:

1. Add option in the frontend and backend to be able to turn on extended vector 
ABI
2. Do the frame lowing in the backend




Comment at: clang/docs/ClangCommandLineReference.rst:2868
 
+Specify usage of volatile and nonvolatile vector registers, the extended 
vector ABI on AIX (AIX only).  The default AIX vector ABI is not yet supported. 
+

1. I am not sure if it's a good idea to put the supporting status also in the 
option description here. It looks a bit strange to me.

2. I would suggest something similar like this for the option description:


```
Only supported on AIX. Specifies whether to use both volatile and nonvolatile 
vector registers or volatile vector registers only. Defaults to `-mnovecnvol` 
when Altivec is enabled. 
```

3. We missed a `-` before `mnovecnvol`.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:531
+def err_aix_default_altivec_abi : Error<
+  "The default Altivec ABI on AIX is not yet supported, use the extended ABI 
option '-mvecnvol'">;
+

I would suggest:

```
The default Altivec ABI on AIX is not yet supported, use '-mvecnvol' for the 
extended Altivec ABI 
```



Comment at: clang/test/CodeGen/altivec.c:1
 // RUN: %clang_cc1 -target-feature +altivec -triple powerpc-unknown-unknown 
-emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -target-feature +altivec -mvecnvol -triple 
powerpc-unknown-aix -emit-llvm %s -o - | FileCheck %s

Can we also test how the driver react to these two options? It would serve as 
the LIT coverage for the code change in `clang/lib/Driver/ToolChains/Clang.cpp`.



Comment at: llvm/include/llvm/Target/TargetOptions.h:177
+/// volatile vector registers which is the default setting on AIX.
+unsigned AIXExtendedAltivecABI = 0;
+

Can we also use bitfield to indicate true and false here? The default value set 
to be `false` in ctor already, so we don't need assign `0` to it here.

```
unsigned AIXExtendedAltivecABI : 1;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88676

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


[PATCH] D89446: [WebAssembly] Prototype i8x16.popcnt

2020-10-15 Thread Thomas Lively via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
tlively marked an inline comment as done.
Closed by commit rG1992e30c2d75: [WebAssembly] Prototype i8x16.popcnt (authored 
by tlively).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89446

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
  llvm/test/MC/WebAssembly/simd-encodings.s

Index: llvm/test/MC/WebAssembly/simd-encodings.s
===
--- llvm/test/MC/WebAssembly/simd-encodings.s
+++ llvm/test/MC/WebAssembly/simd-encodings.s
@@ -367,6 +367,9 @@
 # CHECK: i8x16.avgr_u # encoding: [0xfd,0x7b]
 i8x16.avgr_u
 
+# CHECK: i8x16.popcnt # encoding: [0xfd,0x7c]
+i8x16.popcnt
+
 # CHECK: i16x8.abs # encoding: [0xfd,0x80,0x01]
 i16x8.abs
 
Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -75,6 +75,16 @@
   ret <16 x i8> %a
 }
 
+; CHECK-LABEL: popcnt_v16i8:
+; SIMD128-NEXT: .functype popcnt_v16i8 (v128) -> (v128){{$}}
+; SIMD128-NEXT: i8x16.popcnt $push[[R:[0-9]+]]=, $0{{$}}
+; SIMD128-NEXT: return $pop[[R]]{{$}}
+declare <16 x i8> @llvm.wasm.popcnt(<16 x i8>)
+define <16 x i8> @popcnt_v16i8(<16 x i8> %x) {
+ %a = call <16 x i8> @llvm.wasm.popcnt(<16 x i8> %x)
+ ret <16 x i8> %a
+}
+
 ; CHECK-LABEL: any_v16i8:
 ; SIMD128-NEXT: .functype any_v16i8 (v128) -> (i32){{$}}
 ; SIMD128-NEXT: i8x16.any_true $push[[R:[0-9]+]]=, $0{{$}}
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
===
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
@@ -785,6 +785,9 @@
 // All lanes true: all_true
 defm ALLTRUE : SIMDReduce;
 
+// Population count: popcnt
+defm POPCNT : SIMDUnary;
+
 // Reductions already return 0 or 1, so and 1, setne 0, and seteq 1
 // can be folded out
 foreach reduction =
Index: llvm/include/llvm/IR/IntrinsicsWebAssembly.td
===
--- llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -254,6 +254,11 @@
 [IntrWriteMem, IntrArgMemOnly],
 "", [SDNPMemOperand]>;
 
+// TODO: Replace this intrinsic with normal ISel patterns once popcnt is merged
+// to the proposal.
+def int_wasm_popcnt :
+  Intrinsic<[llvm_v16i8_ty], [llvm_v16i8_ty], [IntrNoMem, IntrSpeculatable]>;
+
 //===--===//
 // Thread-local storage intrinsics
 //===--===//
Index: clang/test/CodeGen/builtins-wasm.c
===
--- clang/test/CodeGen/builtins-wasm.c
+++ clang/test/CodeGen/builtins-wasm.c
@@ -538,6 +538,12 @@
   // WEBASSEMBLY-NEXT: ret
 }
 
+i8x16 popcnt(i8x16 x) {
+  return __builtin_wasm_popcnt_i8x16(x);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.popcnt(<16 x i8> %x)
+  // WEBASSEMBLY-NEXT: ret
+}
+
 int any_true_i8x16(i8x16 x) {
   return __builtin_wasm_any_true_i8x16(x);
   // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -16606,6 +16606,11 @@
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_dot);
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_popcnt_i8x16: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_popcnt);
+return Builder.CreateCall(Callee, {Vec});
+  }
   case WebAssembly::BI__builtin_wasm_any_true_i8x16:
   case WebAssembly::BI__builtin_wasm_any_true_i16x8:
   case WebAssembly::BI__builtin_wasm_any_true_i32x4:
Index: clang/include/clang/Basic/BuiltinsWebAssembly.def
===
--- clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -114,6 +114,8 @@
 TARGET_BUILTIN(__builtin_wasm_avgr_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_avgr_u_i16x8, "V8UsV8UsV8Us", "nc", "simd128")
 
+TARGET_BUILTIN(__builtin_wasm_popcnt_i8x16, "V16ScV16Sc", "nc", "simd128")
+
 TARGET_BUILTIN(__builtin_wasm_q15mulr_saturate_s_i8x16, "V8sV8sV8s", "nc", "

[clang] 1992e30 - [WebAssembly] Prototype i8x16.popcnt

2020-10-15 Thread Thomas Lively via cfe-commits

Author: Thomas Lively
Date: 2020-10-15T21:18:22Z
New Revision: 1992e30c2d751f6f1f6ad5190f84e37dece04f7f

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

LOG: [WebAssembly] Prototype i8x16.popcnt

As proposed at https://github.com/WebAssembly/simd/pull/379. Use a target
builtin and intrinsic rather than normal codegen patterns to make the
instruction opt-in until it is merged to the proposal and stabilized in engines.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-wasm.c
llvm/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
llvm/test/MC/WebAssembly/simd-encodings.s

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index 86348ff5fea7..f84ce92ffe7e 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -114,6 +114,8 @@ TARGET_BUILTIN(__builtin_wasm_max_u_i32x4, "V4UiV4UiV4Ui", 
"nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_avgr_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_avgr_u_i16x8, "V8UsV8UsV8Us", "nc", "simd128")
 
+TARGET_BUILTIN(__builtin_wasm_popcnt_i8x16, "V16ScV16Sc", "nc", "simd128")
+
 TARGET_BUILTIN(__builtin_wasm_q15mulr_saturate_s_i8x16, "V8sV8sV8s", "nc", 
"simd128")
 
 TARGET_BUILTIN(__builtin_wasm_bitselect, "V4iV4iV4iV4i", "nc", "simd128")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3f6977e16c4a..884fa1103163 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -16606,6 +16606,11 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_dot);
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_popcnt_i8x16: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_popcnt);
+return Builder.CreateCall(Callee, {Vec});
+  }
   case WebAssembly::BI__builtin_wasm_any_true_i8x16:
   case WebAssembly::BI__builtin_wasm_any_true_i16x8:
   case WebAssembly::BI__builtin_wasm_any_true_i32x4:

diff  --git a/clang/test/CodeGen/builtins-wasm.c 
b/clang/test/CodeGen/builtins-wasm.c
index d7e998fb997b..4b882700e3ac 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -538,6 +538,12 @@ i32x4 bitselect(i32x4 x, i32x4 y, i32x4 c) {
   // WEBASSEMBLY-NEXT: ret
 }
 
+i8x16 popcnt(i8x16 x) {
+  return __builtin_wasm_popcnt_i8x16(x);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.popcnt(<16 x i8> %x)
+  // WEBASSEMBLY-NEXT: ret
+}
+
 int any_true_i8x16(i8x16 x) {
   return __builtin_wasm_any_true_i8x16(x);
   // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)

diff  --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td 
b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
index 8298312491fa..7a701ec0e269 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -254,6 +254,11 @@ def int_wasm_store64_lane :
 [IntrWriteMem, IntrArgMemOnly],
 "", [SDNPMemOperand]>;
 
+// TODO: Replace this intrinsic with normal ISel patterns once popcnt is merged
+// to the proposal.
+def int_wasm_popcnt :
+  Intrinsic<[llvm_v16i8_ty], [llvm_v16i8_ty], [IntrNoMem, IntrSpeculatable]>;
+
 
//===--===//
 // Thread-local storage intrinsics
 
//===--===//

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td 
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
index ad3a756dc55b..5d72def798fd 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
@@ -785,6 +785,9 @@ defm ANYTRUE : SIMDReduce;
 // All lanes true: all_true
 defm ALLTRUE : SIMDReduce;
 
+// Population count: popcnt
+defm POPCNT : SIMDUnary;
+
 // Reductions already return 0 or 1, so and 1, setne 0, and seteq 1
 // can be folded out
 foreach reduction =

diff  --git a/llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll 
b/llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
index 39b59227a8be..7c0f43d2c67f 100644
--- a/llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ b/llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -75,6 +75,16 @@ define <16 x i8> @avgr_u_v16i8(<16 x i8> %x, <16 x i8> %y) {
   ret <16 x i8> %a
 }
 
+; CHECK-LABEL: popc

[PATCH] D89496: [Format/ObjC] Correctly handle base class with lightweight generics and protocol

2020-10-15 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: sammccall, MyDeveloperDay.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
benhamilton requested review of this revision.

ClangFormat does not correctly handle an Objective-C interface declaration
with both lightweight generics and a protocol conformance.

This simple example:

  @interface Foo : Bar  
  
  @end

means `Foo` extends `Bar` (a lightweight generic class whose type
parameter is `Baz`) and also conforms to the protocol `Blech`.

ClangFormat should not apply any changes to the above example, but
instead it currently formats it quite poorly:

  @interface Foo : Bar 
  
  
  @end
  

The bug is that `UnwrappedLineParser` assumes an open-angle bracket
after a base class name is a protocol list, but it can also be a
lightweight generic specification.

This diff fixes the bug by factoring out the logic to parse
lightweight generics so it can apply both to the declared class
as well as the base class.

Test Plan: New tests added. Ran tests with:

  % ninja FormatTests && ./tools/clang/unittests/Format/FormatTests
  Confirmed tests failed before diff and passed after diff.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89496

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestObjC.cpp

Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -328,6 +328,18 @@
"+ (id)init;\n"
"@end");
 
+  verifyFormat("@interface Foo> : Xyzzy   {\n"
+   "  int _i;\n"
+   "}\n"
+   "+ (id)init;\n"
+   "@end");
+
+  verifyFormat("@interface Foo : Bar  \n"
+   "@end");
+
+  verifyFormat("@interface Foo : Bar  \n"
+   "@end");
+
   verifyFormat("@interface Foo (HackStuff) {\n"
"  int _i;\n"
"}\n"
@@ -413,6 +425,10 @@
"f,\n"
"f> {\n"
"}");
+  verifyFormat("@interface g\n"
+   ": g \n"
+   "  \n"
+   "@end");
 }
 
 TEST_F(FormatTestObjC, FormatObjCImplementation) {
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -118,6 +118,7 @@
   // parses the record as a child block, i.e. if the class declaration is an
   // expression.
   void parseRecord(bool ParseAsExpr = false);
+  void parseObjCLightweightGenerics();
   void parseObjCMethod();
   void parseObjCProtocolList();
   void parseObjCUntilAtEnd();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2612,32 +2612,15 @@
   // @interface can be followed by a lightweight generic
   // specialization list, then either a base class or a category.
   if (FormatTok->Tok.is(tok::less)) {
-// Unlike protocol lists, generic parameterizations support
-// nested angles:
-//
-// @interface Foo> :
-// NSObject 
-//
-// so we need to count how many open angles we have left.
-unsigned NumOpenAngles = 1;
-do {
-  nextToken();
-  // Early exit in case someone forgot a close angle.
-  if (FormatTok->isOneOf(tok::semi, tok::l_brace) ||
-  FormatTok->Tok.isObjCAtKeyword(tok::objc_end))
-break;
-  if (FormatTok->Tok.is(tok::less))
-++NumOpenAngles;
-  else if (FormatTok->Tok.is(tok::greater)) {
-assert(NumOpenAngles > 0 && "'>' makes NumOpenAngles negative");
---NumOpenAngles;
-  }
-} while (!eof() && NumOpenAngles != 0);
-nextToken(); // Skip '>'.
+parseObjCLightweightGenerics();
   }
   if (FormatTok->Tok.is(tok::colon)) {
 nextToken();
 nextToken(); // base class name
+// The base class can also have lightweight generics applied to it.
+if (FormatTok->Tok.is(tok::less)) {
+  parseObjCLightweightGenerics();
+}
   } else if (FormatTok->Tok.is(tok::l_paren))
 // Skip category, if present.
 parseParens();
@@ -2658,6 +2641,32 @@
   parseObjCUntilAtEnd();
 }
 
+void UnwrappedLineParser::parseObjCLightweightGenerics() {
+  assert(FormatTok->Tok.is(tok::less));
+  // Unlike protocol lists, generic parameterizations support
+  // nested angles:
+  //
+  // @interface Foo> :
+  // NSObject 
+  //
+  // so we need to count how many open angles we have left.
+  unsigned NumOpenAngles = 1;
+  do {
+nextToken();
+// Early exit in case someone forgot a close angle.
+if (FormatTok->isOneOf(tok::semi, tok::l_brace) ||
+  

[PATCH] D89490: Introduce __attribute__((darwin_abi))

2020-10-15 Thread Adrien Guinet via Phabricator via cfe-commits
aguinet updated this revision to Diff 298461.
aguinet added a comment.

Update format + llvm tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89490

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Specifiers.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/darwin_abi.c
  clang/test/CodeGen/darwin_abi_empty_structs.cpp
  clang/test/CodeGen/darwin_abi_vaarg.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/CodeGenCXX/darwinabi-returnthis.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/BinaryFormat/Dwarf.def
  llvm/include/llvm/IR/CallingConv.h
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/Target/AArch64/AArch64CallingConvention.cpp
  llvm/lib/Target/AArch64/AArch64FastISel.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
  llvm/test/CodeGen/AArch64/darwin_abi.ll
  llvm/test/CodeGen/AArch64/darwin_abi_vararg.ll

Index: llvm/test/CodeGen/AArch64/darwin_abi_vararg.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/darwin_abi_vararg.ll
@@ -0,0 +1,39 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=aarch64-pc-linux | FileCheck %s
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-pc-linux"
+
+%struct.__va_list = type { i8*, i8*, i8*, i32, i32 }
+
+define dso_local aarch64_darwincc void @foo(i32 %n, ...) local_unnamed_addr #0 {
+; CHECK-LABEL: foo:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:sub sp, sp, #48 // =48
+; CHECK-NEXT:stp x29, x30, [sp, #32] // 16-byte Folded Spill
+; CHECK-NEXT:add x29, sp, #32 // =32
+; CHECK-NEXT:add x8, x29, #16 // =16
+; CHECK-NEXT:mov x1, sp
+; CHECK-NEXT:str xzr, [sp, #24]
+; CHECK-NEXT:str x8, [sp]
+; CHECK-NEXT:bl vfoo
+; CHECK-NEXT:ldp x29, x30, [sp, #32] // 16-byte Folded Reload
+; CHECK-NEXT:add sp, sp, #48 // =48
+; CHECK-NEXT:ret
+entry:
+  %va = alloca %struct.__va_list, align 8
+  %0 = bitcast %struct.__va_list* %va to i8*
+  call void @llvm.va_start(i8* nonnull %0)
+  call void @vfoo(i32 %n, %struct.__va_list* nonnull %va) #1
+  call void @llvm.va_end(i8* nonnull %0)
+  ret void
+}
+
+declare void @llvm.va_start(i8*) #1
+
+declare dso_local void @vfoo(i32, %struct.__va_list*) local_unnamed_addr #0
+
+declare void @llvm.va_end(i8*) #1
+
+attributes #0 = { nounwind "disable-tail-calls"="false" "frame-pointer"="non-leaf" "target-cpu"="generic" }
+attributes #1 = { nounwind }
Index: llvm/test/CodeGen/AArch64/darwin_abi.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/darwin_abi.ll
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=aarch64-pc-linux | FileCheck %s
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-pc-linux"
+
+define dso_local aarch64_darwincc signext i16 @f1(i16 signext %a) local_unnamed_addr #0 {
+; CHECK-LABEL: f1:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:add w8, w0, #1 // =1
+; CHECK-NEXT:sxth w0, w8
+; CHECK-NEXT:ret
+entry:
+  %add = add i16 %a, 1
+  ret i16 %add
+}
+
+define dso_local aarch64_darwincc zeroext i16 @f2(i16 zeroext %a) local_unnamed_addr #0 {
+; CHECK-LABEL: f2:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:add w8, w0, #1 // =1
+; CHECK-NEXT:and w0, w8, #0x
+; CHECK-NEXT:ret
+entry:
+  %add = add i16 %a, 1
+  ret i16 %add
+}
+
+attributes #0 = { norecurse nounwind readnone "disable-tail-calls"="false" "frame-pointer"="non-leaf" "target-cpu"="generic" }
Index: llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
===
--- llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
+++ llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
@@ -474,8 +474,8 @@
   uint64_t StackOffset = Handler.StackUsed;
   if (F.isVarArg()) {
 auto &Subtarget = MF.getSubtarget();
-if (!Subtarget.isTargetDarwin()) {
-// FIXME: we need to reimplement saveVarArgsRegisters from
+if (!Subtarget.isCallingConvDarwin(MF.getFunct

[PATCH] D89277: [clangd] Add $/dumpMemoryTree LSP extension

2020-10-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 298460.
kadircet added a comment.

- As discussed offline moving with compact version of the output, while 
preserving names starting with an `_` to be leaves.

This is also ready for an implementation-wise review now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89277

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/test/memory_tree.test

Index: clang-tools-extra/clangd/test/memory_tree.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/memory_tree.test
@@ -0,0 +1,81 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"void func() {}"}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"$/dumpMemoryTree","params":{}}
+# CHECK:"id": 1,
+# CHECK-NEXT:   "jsonrpc": "2.0",
+# CHECK-NEXT:   "result": {
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}},
+# CHECK-NEXT: "clangd_server": {
+# CHECK-NEXT:   "_self": {{[0-9]+}},
+# CHECK-NEXT:   "_total": {{[0-9]+}},
+# CHECK-NEXT:   "dynamic_index": {
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}},
+# CHECK-NEXT: "main_file": {
+# CHECK-NEXT:   "_self": {{[0-9]+}},
+# CHECK-NEXT:   "_total": {{[0-9]+}},
+# CHECK-NEXT:   "index": {
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}}
+# CHECK-NEXT:   },
+# CHECK-NEXT:   "symbols": {
+# CHECK-NEXT: "{{.*}}main.cpp": {
+# CHECK-NEXT:   "_self": {{[0-9]+}},
+# CHECK-NEXT:   "_total": {{[0-9]+}},
+# CHECK-NEXT:   "references": {
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}}
+# CHECK-NEXT:   },
+# CHECK-NEXT:   "relations": {
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}}
+# CHECK-NEXT:   },
+# CHECK-NEXT:   "symbols": {
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}}
+# CHECK-NEXT:   }
+# CHECK-NEXT: },
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}}
+# CHECK-NEXT:   }
+# CHECK-NEXT: },
+# CHECK-NEXT: "preamble": {
+# CHECK-NEXT:   "_self": {{[0-9]+}},
+# CHECK-NEXT:   "_total": {{[0-9]+}},
+# CHECK-NEXT:   "index": {
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}}
+# CHECK-NEXT:   },
+# CHECK-NEXT:   "symbols": {
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}}
+# CHECK-NEXT:   }
+# CHECK-NEXT: }
+# CHECK-NEXT:   },
+# CHECK-NEXT:   "tuscheduler": {
+# CHECK-NEXT: "{{.*}}main.cpp": {
+# CHECK-NEXT:   "_self": {{[0-9]+}},
+# CHECK-NEXT:   "_total": {{[0-9]+}},
+# CHECK-NEXT:   "ast": {
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}}
+# CHECK-NEXT:   },
+# CHECK-NEXT:   "preamble": {
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}}
+# CHECK-NEXT:   }
+# CHECK-NEXT: },
+# CHECK-NEXT: "_self": {{[0-9]+}},
+# CHECK-NEXT: "_total": {{[0-9]+}}
+# CHECK-NEXT:   }
+# CHECK-NEXT: }
+# CHECK-NEXT:   }
+---
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
+
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -24,6 +24,7 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/JSON.h"
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -141,6 +142,27 @@
   void onSemanticTokens(const SemanticTokensParams &, Callback);
   void onSemanticTokensDelta(const SemanticTokensDeltaParams &,
  Callback);
+  /// This is a clangd extension. Provides a json tree representing memory usage
+  /// hierarchy. Keys starting with an underscore(_) represent leaves, e.g.
+  /// _total or _self for memory usage of whole subtree or only that specific
+  /// node in bytes. All other keys represents children. An example:
+  ///   {
+  /// "_self": 0,
+  /// "_total": 8,
+  /// "child1": {
+  ///

[clang] 65cb4fd - [libTooling] Change `after` range-selector to operate only on source ranges

2020-10-15 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2020-10-15T20:58:30Z
New Revision: 65cb4fdd69f43b6c39a8e4ca27b509284b11d807

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

LOG: [libTooling] Change `after` range-selector to operate only on source ranges

Currently, `after` fails when applied to locations in macro arguments.  This
change projects the subrange into a file source range and then applies `after`.

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

Added: 


Modified: 
clang/lib/Tooling/Transformer/RangeSelector.cpp
clang/unittests/Tooling/RangeSelectorTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Transformer/RangeSelector.cpp 
b/clang/lib/Tooling/Transformer/RangeSelector.cpp
index 29b1a5b0372e..ce6f5fb9b444 100644
--- a/clang/lib/Tooling/Transformer/RangeSelector.cpp
+++ b/clang/lib/Tooling/Transformer/RangeSelector.cpp
@@ -116,11 +116,24 @@ RangeSelector transformer::after(RangeSelector Selector) {
 Expected SelectedRange = Selector(Result);
 if (!SelectedRange)
   return SelectedRange.takeError();
-if (SelectedRange->isCharRange())
-  return CharSourceRange::getCharRange(SelectedRange->getEnd());
-return CharSourceRange::getCharRange(Lexer::getLocForEndOfToken(
-SelectedRange->getEnd(), 0, Result.Context->getSourceManager(),
-Result.Context->getLangOpts()));
+SourceLocation End = SelectedRange->getEnd();
+if (SelectedRange->isTokenRange()) {
+  // We need to find the actual (exclusive) end location from which to
+  // create a new source range. However, that's not guaranteed to be valid,
+  // even if the token location itself is valid. So, we create a token 
range
+  // consisting only of the last token, then map that range back to the
+  // source file. If that succeeds, we have a valid location for the end of
+  // the generated range.
+  CharSourceRange Range = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(SelectedRange->getEnd()),
+  *Result.SourceManager, Result.Context->getLangOpts());
+  if (Range.isInvalid())
+return invalidArgumentError(
+"after: can't resolve sub-range to valid source range");
+  End = Range.getEnd();
+}
+
+return CharSourceRange::getCharRange(End);
   };
 }
 

diff  --git a/clang/unittests/Tooling/RangeSelectorTest.cpp 
b/clang/unittests/Tooling/RangeSelectorTest.cpp
index 64ddee7894eb..499c9a8cc666 100644
--- a/clang/unittests/Tooling/RangeSelectorTest.cpp
+++ b/clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -193,6 +193,65 @@ TEST(RangeSelectorTest, AfterOp) {
HasValue(EqualsCharSourceRange(ExpectedAfter)));
 }
 
+// Gets the spelling location `Length` characters after the start of AST node
+// `Id`.
+static SourceLocation getSpellingLocAfter(const MatchResult &Result,
+  StringRef Id, int Length) {
+  const auto *E = Result.Nodes.getNodeAs(Id);
+  assert(E != nullptr);
+  return Result.SourceManager->getSpellingLoc(E->getBeginLoc())
+  .getLocWithOffset(Length);
+}
+
+// Test with a range that is the entire macro arg, but does not end the
+// expansion itself.
+TEST(RangeSelectorTest, AfterOpInMacroArg) {
+  StringRef Code = R"cc(
+#define ISNULL(x) x == nullptr
+bool g() { int* y; return ISNULL(y); }
+  )cc";
+
+  TestMatch Match =
+  matchCode(Code, declRefExpr(to(namedDecl(hasName("y".bind("yvar"));
+  int YVarLen = 1;
+  SourceLocation After = getSpellingLocAfter(Match.Result, "yvar", YVarLen);
+  CharSourceRange Expected = CharSourceRange::getCharRange(After, After);
+  EXPECT_THAT_EXPECTED(after(node("yvar"))(Match.Result),
+   HasValue(EqualsCharSourceRange(Expected)));
+}
+
+// Test with a range that is the entire macro arg and ends the expansion 
itself.
+TEST(RangeSelectorTest, AfterOpInMacroArgEndsExpansion) {
+  StringRef Code = R"cc(
+#define ISNULL(x) nullptr == x
+bool g() { int* y; return ISNULL(y); }
+  )cc";
+
+  TestMatch Match =
+  matchCode(Code, declRefExpr(to(namedDecl(hasName("y".bind("yvar"));
+  int YVarLen = 1;
+  SourceLocation After = getSpellingLocAfter(Match.Result, "yvar", YVarLen);
+  CharSourceRange Expected = CharSourceRange::getCharRange(After, After);
+  EXPECT_THAT_EXPECTED(after(node("yvar"))(Match.Result),
+   HasValue(EqualsCharSourceRange(Expected)));
+}
+
+TEST(RangeSelectorTest, AfterOpInPartOfMacroArg) {
+  StringRef Code = R"cc(
+#define ISNULL(x) x == nullptr
+int* f(int*);
+bool g() { int* y; return ISNULL(f(y)); }
+  )cc";
+
+  TestMatch Match =
+  matchCode(Code, declRefExpr(to(namedDecl(hasName("y".bind("yvar"));
+  int YVarLen = 1;
+  SourceLocation After = getSpellingLocAfter(Match.Result,

[PATCH] D89468: [libTooling] Change `after` range-selector to operate only on source ranges

2020-10-15 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG65cb4fdd69f4: [libTooling] Change `after` range-selector to 
operate only on source ranges (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89468

Files:
  clang/lib/Tooling/Transformer/RangeSelector.cpp
  clang/unittests/Tooling/RangeSelectorTest.cpp

Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -193,6 +193,65 @@
HasValue(EqualsCharSourceRange(ExpectedAfter)));
 }
 
+// Gets the spelling location `Length` characters after the start of AST node
+// `Id`.
+static SourceLocation getSpellingLocAfter(const MatchResult &Result,
+  StringRef Id, int Length) {
+  const auto *E = Result.Nodes.getNodeAs(Id);
+  assert(E != nullptr);
+  return Result.SourceManager->getSpellingLoc(E->getBeginLoc())
+  .getLocWithOffset(Length);
+}
+
+// Test with a range that is the entire macro arg, but does not end the
+// expansion itself.
+TEST(RangeSelectorTest, AfterOpInMacroArg) {
+  StringRef Code = R"cc(
+#define ISNULL(x) x == nullptr
+bool g() { int* y; return ISNULL(y); }
+  )cc";
+
+  TestMatch Match =
+  matchCode(Code, declRefExpr(to(namedDecl(hasName("y".bind("yvar"));
+  int YVarLen = 1;
+  SourceLocation After = getSpellingLocAfter(Match.Result, "yvar", YVarLen);
+  CharSourceRange Expected = CharSourceRange::getCharRange(After, After);
+  EXPECT_THAT_EXPECTED(after(node("yvar"))(Match.Result),
+   HasValue(EqualsCharSourceRange(Expected)));
+}
+
+// Test with a range that is the entire macro arg and ends the expansion itself.
+TEST(RangeSelectorTest, AfterOpInMacroArgEndsExpansion) {
+  StringRef Code = R"cc(
+#define ISNULL(x) nullptr == x
+bool g() { int* y; return ISNULL(y); }
+  )cc";
+
+  TestMatch Match =
+  matchCode(Code, declRefExpr(to(namedDecl(hasName("y".bind("yvar"));
+  int YVarLen = 1;
+  SourceLocation After = getSpellingLocAfter(Match.Result, "yvar", YVarLen);
+  CharSourceRange Expected = CharSourceRange::getCharRange(After, After);
+  EXPECT_THAT_EXPECTED(after(node("yvar"))(Match.Result),
+   HasValue(EqualsCharSourceRange(Expected)));
+}
+
+TEST(RangeSelectorTest, AfterOpInPartOfMacroArg) {
+  StringRef Code = R"cc(
+#define ISNULL(x) x == nullptr
+int* f(int*);
+bool g() { int* y; return ISNULL(f(y)); }
+  )cc";
+
+  TestMatch Match =
+  matchCode(Code, declRefExpr(to(namedDecl(hasName("y".bind("yvar"));
+  int YVarLen = 1;
+  SourceLocation After = getSpellingLocAfter(Match.Result, "yvar", YVarLen);
+  CharSourceRange Expected = CharSourceRange::getCharRange(After, After);
+  EXPECT_THAT_EXPECTED(after(node("yvar"))(Match.Result),
+   HasValue(EqualsCharSourceRange(Expected)));
+}
+
 TEST(RangeSelectorTest, BetweenOp) {
   StringRef Code = R"cc(
 int f(int x, int y, int z) { return 3; }
Index: clang/lib/Tooling/Transformer/RangeSelector.cpp
===
--- clang/lib/Tooling/Transformer/RangeSelector.cpp
+++ clang/lib/Tooling/Transformer/RangeSelector.cpp
@@ -116,11 +116,24 @@
 Expected SelectedRange = Selector(Result);
 if (!SelectedRange)
   return SelectedRange.takeError();
-if (SelectedRange->isCharRange())
-  return CharSourceRange::getCharRange(SelectedRange->getEnd());
-return CharSourceRange::getCharRange(Lexer::getLocForEndOfToken(
-SelectedRange->getEnd(), 0, Result.Context->getSourceManager(),
-Result.Context->getLangOpts()));
+SourceLocation End = SelectedRange->getEnd();
+if (SelectedRange->isTokenRange()) {
+  // We need to find the actual (exclusive) end location from which to
+  // create a new source range. However, that's not guaranteed to be valid,
+  // even if the token location itself is valid. So, we create a token range
+  // consisting only of the last token, then map that range back to the
+  // source file. If that succeeds, we have a valid location for the end of
+  // the generated range.
+  CharSourceRange Range = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(SelectedRange->getEnd()),
+  *Result.SourceManager, Result.Context->getLangOpts());
+  if (Range.isInvalid())
+return invalidArgumentError(
+"after: can't resolve sub-range to valid source range");
+  End = Range.getEnd();
+}
+
+return CharSourceRange::getCharRange(End);
   };
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89031: [SVE] Add support to vectorize_width loop pragma for scalable vectors

2020-10-15 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added inline comments.



Comment at: clang/lib/Parse/ParsePragma.cpp:1096
   static_cast(Tok.getAnnotationValue());
-
   IdentifierInfo *PragmaNameInfo = Info->PragmaName.getIdentifierInfo();

nit: unrelated change?



Comment at: clang/lib/Sema/SemaStmtAttr.cpp:144
+  assert(ValueExpr && "Attribute must have a valid value expression.");
+  if (S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc()))
+return nullptr;

Is there a way to only accept `fixed_width/scalable` for targets that support 
it? Not sure if we have enough information here, but we might be able to reject 
it eg per target basis or something


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89031

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


[PATCH] D89446: [WebAssembly] Prototype i8x16.popcnt

2020-10-15 Thread Thomas Lively via Phabricator via cfe-commits
tlively marked an inline comment as done.
tlively added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsWebAssembly.def:117
 
+TARGET_BUILTIN(__builtin_wasm_popcnt, "V16ScV16Sc", "nc", "simd128")
+

aheejin wrote:
> - Even if there's only one vector type for a builtin, it seems others still 
> have type postfix attached.
> - Is the result also a vector? Does that mean this instruction count each 16 
> slot separately?
Yes, the it does a popcnt on each 1-byte lane individually.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89446

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


[PATCH] D89446: [WebAssembly] Prototype i8x16.popcnt

2020-10-15 Thread Thomas Lively via Phabricator via cfe-commits
tlively updated this revision to Diff 298457.
tlively added a comment.

- Update builtin function name


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89446

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
  llvm/test/MC/WebAssembly/simd-encodings.s

Index: llvm/test/MC/WebAssembly/simd-encodings.s
===
--- llvm/test/MC/WebAssembly/simd-encodings.s
+++ llvm/test/MC/WebAssembly/simd-encodings.s
@@ -367,6 +367,9 @@
 # CHECK: i8x16.avgr_u # encoding: [0xfd,0x7b]
 i8x16.avgr_u
 
+# CHECK: i8x16.popcnt # encoding: [0xfd,0x7c]
+i8x16.popcnt
+
 # CHECK: i16x8.abs # encoding: [0xfd,0x80,0x01]
 i16x8.abs
 
Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -75,6 +75,16 @@
   ret <16 x i8> %a
 }
 
+; CHECK-LABEL: popcnt_v16i8:
+; SIMD128-NEXT: .functype popcnt_v16i8 (v128) -> (v128){{$}}
+; SIMD128-NEXT: i8x16.popcnt $push[[R:[0-9]+]]=, $0{{$}}
+; SIMD128-NEXT: return $pop[[R]]{{$}}
+declare <16 x i8> @llvm.wasm.popcnt(<16 x i8>)
+define <16 x i8> @popcnt_v16i8(<16 x i8> %x) {
+ %a = call <16 x i8> @llvm.wasm.popcnt(<16 x i8> %x)
+ ret <16 x i8> %a
+}
+
 ; CHECK-LABEL: any_v16i8:
 ; SIMD128-NEXT: .functype any_v16i8 (v128) -> (i32){{$}}
 ; SIMD128-NEXT: i8x16.any_true $push[[R:[0-9]+]]=, $0{{$}}
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
===
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
@@ -785,6 +785,9 @@
 // All lanes true: all_true
 defm ALLTRUE : SIMDReduce;
 
+// Population count: popcnt
+defm POPCNT : SIMDUnary;
+
 // Reductions already return 0 or 1, so and 1, setne 0, and seteq 1
 // can be folded out
 foreach reduction =
Index: llvm/include/llvm/IR/IntrinsicsWebAssembly.td
===
--- llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -254,6 +254,11 @@
 [IntrWriteMem, IntrArgMemOnly],
 "", [SDNPMemOperand]>;
 
+// TODO: Replace this intrinsic with normal ISel patterns once popcnt is merged
+// to the proposal.
+def int_wasm_popcnt :
+  Intrinsic<[llvm_v16i8_ty], [llvm_v16i8_ty], [IntrNoMem, IntrSpeculatable]>;
+
 //===--===//
 // Thread-local storage intrinsics
 //===--===//
Index: clang/test/CodeGen/builtins-wasm.c
===
--- clang/test/CodeGen/builtins-wasm.c
+++ clang/test/CodeGen/builtins-wasm.c
@@ -538,6 +538,12 @@
   // WEBASSEMBLY-NEXT: ret
 }
 
+i8x16 popcnt(i8x16 x) {
+  return __builtin_wasm_popcnt_i8x16(x);
+  // WEBASSEMBLY: call <16 x i8> @llvm.wasm.popcnt(<16 x i8> %x)
+  // WEBASSEMBLY-NEXT: ret
+}
+
 int any_true_i8x16(i8x16 x) {
   return __builtin_wasm_any_true_i8x16(x);
   // WEBASSEMBLY: call i32 @llvm.wasm.anytrue.v16i8(<16 x i8> %x)
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -16606,6 +16606,11 @@
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_dot);
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_popcnt_i8x16: {
+Value *Vec = EmitScalarExpr(E->getArg(0));
+Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_popcnt);
+return Builder.CreateCall(Callee, {Vec});
+  }
   case WebAssembly::BI__builtin_wasm_any_true_i8x16:
   case WebAssembly::BI__builtin_wasm_any_true_i16x8:
   case WebAssembly::BI__builtin_wasm_any_true_i32x4:
Index: clang/include/clang/Basic/BuiltinsWebAssembly.def
===
--- clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -114,6 +114,8 @@
 TARGET_BUILTIN(__builtin_wasm_avgr_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_avgr_u_i16x8, "V8UsV8UsV8Us", "nc", "simd128")
 
+TARGET_BUILTIN(__builtin_wasm_popcnt_i8x16, "V16ScV16Sc", "nc", "simd128")
+
 TARGET_BUILTIN(__builtin_wasm_q15mulr_saturate_s_i8x16, "V8sV8sV8s", "nc", "simd128")
 
 TARGET_BUILTIN(__builtin_wasm_bitselect, "V4iV4iV4iV4i", "nc", "simd128")
___
cfe-commits mailing list
cf

[clang] 68f116a - PR47864: Fix assertion in pointer-to-member emission if there are

2020-10-15 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-10-15T13:51:51-07:00
New Revision: 68f116aa23434b577743307c487b2edf037fca4c

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

LOG: PR47864: Fix assertion in pointer-to-member emission if there are
multiple declarations of the same base class.

Added: 


Modified: 
clang/include/clang/AST/RecordLayout.h
clang/test/CodeGenCXX/pointers-to-data-members.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RecordLayout.h 
b/clang/include/clang/AST/RecordLayout.h
index 946fbd8f4ce2..dd18f9c49f84 100644
--- a/clang/include/clang/AST/RecordLayout.h
+++ b/clang/include/clang/AST/RecordLayout.h
@@ -248,6 +248,8 @@ class ASTRecordLayout {
   /// getBaseClassOffset - Get the offset, in chars, for the given base class.
   CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const {
 assert(CXXInfo && "Record layout does not have C++ specific info!");
+
+Base = Base->getDefinition();
 assert(CXXInfo->BaseOffsets.count(Base) && "Did not find base!");
 
 return CXXInfo->BaseOffsets[Base];
@@ -256,6 +258,8 @@ class ASTRecordLayout {
   /// getVBaseClassOffset - Get the offset, in chars, for the given base class.
   CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const {
 assert(CXXInfo && "Record layout does not have C++ specific info!");
+
+VBase = VBase->getDefinition();
 assert(CXXInfo->VBaseOffsets.count(VBase) && "Did not find base!");
 
 return CXXInfo->VBaseOffsets[VBase].VBaseOffset;

diff  --git a/clang/test/CodeGenCXX/pointers-to-data-members.cpp 
b/clang/test/CodeGenCXX/pointers-to-data-members.cpp
index f975035d0318..b08cdcc52c5b 100644
--- a/clang/test/CodeGenCXX/pointers-to-data-members.cpp
+++ b/clang/test/CodeGenCXX/pointers-to-data-members.cpp
@@ -258,3 +258,10 @@ union U {
 U u;
 // CHECK-GLOBAL: @_ZN11IndirectPDM1uE = global %"union.IndirectPDM::U" { 
%union.anon { i64 -1 } }, align 8
 }
+
+namespace PR47864 {
+  struct B;
+  struct B {};
+  struct D : B { int m; };
+  auto x = (int B::*)&D::m;
+}



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


[PATCH] D88712: [CGBuiltin] Respect asm labels and redefine_extname for builtins with specialized emitting

2020-10-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a subscriber: zatrazz.
MaskRay added a comment.

In D88712#2333030 , @rsmith wrote:

> I worry that we're chasing after the implementation details of GCC here. It 
> seems self-contradictory to say all three of these things at once:
>
> 1. The frontend function `foo` has known, builtin semantics X. (Eg, we'll use 
> those semantics in the frontend.)
> 2. The symbol `foo` has known, builtin semantics X. (Eg, we'll synthesize 
> calls to `foo` from the middle-end.)
> 3. It's not correct to lower a call to the frontend function `foo` to the 
> symbol `foo`.
>
> So, from a principled standpoint, which of the above do we not consider to be 
> correct in this situation?
>
> - If we don't consider (1) to be correct, then we need to stop treating `foo` 
> as a builtin everywhere -- we shouldn't be constant-evaluating calls to it, 
> in particular. That's problematic in principle, because the `asm` label might 
> be added after we've already seen the first declaration and added a 
> `BuiltinAttr` to it. If we want to go in this direction, I think we should 
> require a build that attaches an `asm` label to a builtin to also pass 
> `-fno-builtin-foo` rather than trying to un-builtin a builtin function after 
> the fact.
> - If we don't consider (2) to be correct, then we need to stop the middle-end 
> from inserting calls to the symbol `foo`, and get it to use the new symbol 
> instead. That'd be the "teach the target libcall info about this" approach, 
> which (as you point out) would be quite complex.
> - The status quo is that we don't consider (3) to be correct. If we take this 
> path, I suppose we could say that we make a best effort to use the renamed 
> symbol, but provide no guarantees. That seems unprincipled and will likely 
> continue to cause problems down the line, but maybe this gets us closest to 
> the observed GCC behavior?

It took me quite a while to understand the "take 2 out of the 3 guarantees" 
theorem;-)

I think people do want to keep (1) (if it is profitable to expand a memcpy, do 
it). This also means that people do not want to add -fno-builtin-memcpy.

People do want (3): that is why they use an `asm("__GI_memcpy")` in the first 
place.
The status quo is "we don't consider (3) to be correct." -> "we ignore 
asm("__GI_memcpy")". This makes the system consistent but it is unexpected.

So unfortunately we are making a compromise on (2): refuting it is difficult in 
both GCC and Clang.
For most libcalls, compilers don't generate them, so it is a small loss. For 
the few glibc cares about, it uses the `asm("memcpy = __GI_memcpy");` GNU as 
feature to make the second level redirection.
D88625  will do it on MC side.

We still have another choice: don't use `memcpy`, use `__memcpy` instead. 
However, that will be a hard hammer and according to @zatrazz people will 
complain 'with gcc this works as intended'...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88712

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


[PATCH] D89490: Introduce __attribute__((darwin_abi))

2020-10-15 Thread Adrien Guinet via Phabricator via cfe-commits
aguinet added a comment.

In D89490#2333073 , @mstorsjo wrote:

> I see that the llvm side of the patch lacks tests?

Sorry I forgot to add them indeed... I will push a patch with these.

About the formatting, git clang-format HEAD~1 did this, and it looks by the 
automated test that some issues are still there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89490

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


[PATCH] D88712: [CGBuiltin] Respect asm labels and redefine_extname for builtins with specialized emitting

2020-10-15 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

Disabling builtin handling when `asm` is enabled would be a major annoyance for 
NetBSD. The interaction between symbol renaming and TLI is complicated. There 
are cases where it would make perfect sense and others were it would be 
harmful. Example of the latter is the way SSP is implemented by inline 
functions that call a prototype renamed back to the original symbol name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88712

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


[PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2020-10-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: cfe/trunk/lib/Sema/SemaType.cpp:2067
+   S.LangOpts.GNUMode ||
+   S.LangOpts.OpenCL).isInvalid();
 }

This looks wrong to me. The OpenCL rules don't permit arbitrary constant 
folding in array bounds.

If OpenCL intends to permit reading from const globals of integral types in 
constant expressions (as C++ does but C does not), then the right way to handle 
that would be to change `CheckICE` to permit such cases, as it does in C++ 
mode, not to enable arbitrary constant folding in array bounds.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D20090

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


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-15 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D85802#2332895 , @phosek wrote:

> In D85802#2332808 , @rnk wrote:
>
>> Would "f[no-]fuchsia-c++-abi-extensions" (or shorter, -ffuchsia-c++-abi) do 
>> the trick? I know it doesn't map well onto our current internal option 
>> representation, but I don't think the internal representation is 
>> particularly good. I'd rather limit the user-visible driver interface to 
>> give us the flexibility to change the internal representation in the future.
>
> For our use case yes, we could have `-f[no-]fuchsia-c++-abi` which would be 
> enabled by default when the target is Fuchsia.

Will send out another patch that will use this instead. We can probably revert 
this in the meantime.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D89490: Introduce __attribute__((darwin_abi))

2020-10-15 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

I see that the llvm side of the patch lacks tests?




Comment at: llvm/lib/IR/AsmWriter.cpp:379
+Out << "aarch64_darwincc";
+break;
   case CallingConv::SPIR_FUNC: Out << "spir_func"; break;

The new code here has a different indentation than the rest; the same in a 
couple other places throughout the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89490

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


[clang] d1beb95 - [AMDGPU] gfx1032 target

2020-10-15 Thread Stanislav Mekhanoshin via cfe-commits

Author: Stanislav Mekhanoshin
Date: 2020-10-15T12:41:18-07:00
New Revision: d1beb95d1241ec50bdf19db351d273374a146a4a

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

LOG: [AMDGPU] gfx1032 target

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

Added: 


Modified: 
clang/include/clang/Basic/Cuda.h
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Basic/Targets/NVPTX.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/test/CodeGenOpenCL/amdgpu-features.cl
clang/test/Driver/amdgpu-macros.cl
clang/test/Driver/amdgpu-mcpu.cl
llvm/docs/AMDGPUUsage.rst
llvm/include/llvm/BinaryFormat/ELF.h
llvm/include/llvm/Support/TargetParser.h
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/lib/Support/TargetParser.cpp
llvm/lib/Target/AMDGPU/GCNProcessors.td
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
llvm/test/CodeGen/AMDGPU/elf-header-flags-mach.ll
llvm/test/CodeGen/AMDGPU/hsa-note-no-func.ll
llvm/test/MC/AMDGPU/gfx1030_err.s
llvm/test/MC/AMDGPU/gfx1030_new.s
llvm/test/MC/Disassembler/AMDGPU/gfx1030_dasm_new.txt
llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Cuda.h 
b/clang/include/clang/Basic/Cuda.h
index 417d40c28adf..501e47b0e2c2 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -80,6 +80,7 @@ enum class CudaArch {
   GFX1012,
   GFX1030,
   GFX1031,
+  GFX1032,
   LAST,
 };
 

diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 42db207b9ce5..0b3aebdfa15c 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -174,6 +174,7 @@ bool AMDGPUTargetInfo::initFeatureMap(
   // XXX - What does the member GPU mean if device name string passed here?
   if (isAMDGCN(getTriple())) {
 switch (llvm::AMDGPU::parseArchAMDGCN(CPU)) {
+case GK_GFX1032:
 case GK_GFX1031:
 case GK_GFX1030:
   Features["ci-insts"] = true;

diff  --git a/clang/lib/Basic/Targets/NVPTX.cpp 
b/clang/lib/Basic/Targets/NVPTX.cpp
index 3780f1cc250c..26c5b26beeef 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -205,6 +205,7 @@ void NVPTXTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   case CudaArch::GFX1012:
   case CudaArch::GFX1030:
   case CudaArch::GFX1031:
+  case CudaArch::GFX1032:
   case CudaArch::LAST:
 break;
   case CudaArch::UNUSED:

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index ab7ee8b33a0c..bcabc5398127 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -4645,6 +4645,7 @@ void CGOpenMPRuntimeGPU::processRequiresDirective(
   case CudaArch::GFX1012:
   case CudaArch::GFX1030:
   case CudaArch::GFX1031:
+  case CudaArch::GFX1032:
   case CudaArch::UNUSED:
   case CudaArch::UNKNOWN:
 break;
@@ -4710,6 +4711,7 @@ static std::pair 
getSMsBlocksPerSM(CodeGenModule &CGM) {
   case CudaArch::GFX1012:
   case CudaArch::GFX1030:
   case CudaArch::GFX1031:
+  case CudaArch::GFX1032:
   case CudaArch::UNUSED:
   case CudaArch::UNKNOWN:
 break;

diff  --git a/clang/test/CodeGenOpenCL/amdgpu-features.cl 
b/clang/test/CodeGenOpenCL/amdgpu-features.cl
index 5a814f36e564..a463c061114e 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features.cl
@@ -16,6 +16,7 @@
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1012 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1012 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1030 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1030 %s
 // RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1031 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1031 %s
+// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1032 -S -emit-llvm -o - %s | 
FileCheck --check-prefix=GFX1032 %s
 
 // GFX600-NOT: "target-features"
 // GFX601-NOT: "target-features"
@@ -30,5 +31,6 @@
 // GFX1012: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dot5-insts,+dot6-insts,+dpp,+flat-address-space,+gfx10-insts,+gfx8-insts,+gfx9-insts,+s-memrealtime"
 // GFX1030: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dot5-insts,+dot6-insts,+dpp,+flat-address-space,+gfx10-3-insts,+gfx10-insts,+gfx8-insts,+gfx9-insts,+s-memrealtime"
 // GFX1031: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dot5-insts,+dot6-insts,+dpp,+flat-address-space,+gfx10-3-insts,+gfx10-insts,+gfx8-insts,+gfx9-insts,+s-memrealtime"
+// GFX1032: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot2-insts,+dot5-insts,+dot6-i

[PATCH] D89484: [AMDGPU][HIP] Switch default DWARF version to 5

2020-10-15 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl accepted this revision.
kzhuravl added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89484

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


[clang] 3f738d1 - Reland "[WebAssembly] v128.load{8,16,32,64}_lane instructions"

2020-10-15 Thread Thomas Lively via cfe-commits

Author: Thomas Lively
Date: 2020-10-15T19:32:34Z
New Revision: 3f738d1f5e2d657993a51ca3fe56585268025d89

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

LOG: Reland "[WebAssembly] v128.load{8,16,32,64}_lane instructions"

This reverts commit 7c8385a352ba21cb388046290d93b53dc273cd9f with a typing fix
to an instruction selection pattern.

Added: 
llvm/test/CodeGen/WebAssembly/simd-load-lane-offset.ll

Modified: 
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-wasm.c
llvm/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
llvm/test/MC/WebAssembly/simd-encodings.s

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index 45e194c283b6..86348ff5fea7 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -171,8 +171,17 @@ TARGET_BUILTIN(__builtin_wasm_narrow_u_i8x16_i16x8, 
"V16UcV8UsV8Us", "nc", "simd
 TARGET_BUILTIN(__builtin_wasm_narrow_s_i16x8_i32x4, "V8sV4iV4i", "nc", 
"simd128")
 TARGET_BUILTIN(__builtin_wasm_narrow_u_i16x8_i32x4, "V8UsV4UiV4Ui", "nc", 
"simd128")
 
-TARGET_BUILTIN(__builtin_wasm_load32_zero, "V4ii*", "nU", "simd128")
-TARGET_BUILTIN(__builtin_wasm_load64_zero, "V2LLiLLi*", "nU", "simd128")
+TARGET_BUILTIN(__builtin_wasm_load32_zero, "V4ii*", "n", "simd128")
+TARGET_BUILTIN(__builtin_wasm_load64_zero, "V2LLiLLi*", "n", "simd128")
+
+TARGET_BUILTIN(__builtin_wasm_load8_lane, "V16ScSc*V16ScIi", "n", "simd128")
+TARGET_BUILTIN(__builtin_wasm_load16_lane, "V8ss*V8sIi", "n", "simd128")
+TARGET_BUILTIN(__builtin_wasm_load32_lane, "V4ii*V4iIi", "n", "simd128")
+TARGET_BUILTIN(__builtin_wasm_load64_lane, "V2LLiLLi*V2LLiIi", "n", "simd128")
+TARGET_BUILTIN(__builtin_wasm_store8_lane, "vSc*V16ScIi", "n", "simd128")
+TARGET_BUILTIN(__builtin_wasm_store16_lane, "vs*V8sIi", "n", "simd128")
+TARGET_BUILTIN(__builtin_wasm_store32_lane, "vi*V4iIi", "n", "simd128")
+TARGET_BUILTIN(__builtin_wasm_store64_lane, "vLLi*V2LLiIi", "n", "simd128")
 
 #undef BUILTIN
 #undef TARGET_BUILTIN

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 157dae2831f2..3f6977e16c4a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -16711,6 +16711,52 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_load64_zero);
 return Builder.CreateCall(Callee, {Ptr});
   }
+  case WebAssembly::BI__builtin_wasm_load8_lane:
+  case WebAssembly::BI__builtin_wasm_load16_lane:
+  case WebAssembly::BI__builtin_wasm_load32_lane:
+  case WebAssembly::BI__builtin_wasm_load64_lane:
+  case WebAssembly::BI__builtin_wasm_store8_lane:
+  case WebAssembly::BI__builtin_wasm_store16_lane:
+  case WebAssembly::BI__builtin_wasm_store32_lane:
+  case WebAssembly::BI__builtin_wasm_store64_lane: {
+Value *Ptr = EmitScalarExpr(E->getArg(0));
+Value *Vec = EmitScalarExpr(E->getArg(1));
+Optional LaneIdxConst =
+E->getArg(2)->getIntegerConstantExpr(getContext());
+assert(LaneIdxConst && "Constant arg isn't actually constant?");
+Value *LaneIdx = llvm::ConstantInt::get(getLLVMContext(), *LaneIdxConst);
+unsigned IntNo;
+switch (BuiltinID) {
+case WebAssembly::BI__builtin_wasm_load8_lane:
+  IntNo = Intrinsic::wasm_load8_lane;
+  break;
+case WebAssembly::BI__builtin_wasm_load16_lane:
+  IntNo = Intrinsic::wasm_load16_lane;
+  break;
+case WebAssembly::BI__builtin_wasm_load32_lane:
+  IntNo = Intrinsic::wasm_load32_lane;
+  break;
+case WebAssembly::BI__builtin_wasm_load64_lane:
+  IntNo = Intrinsic::wasm_load64_lane;
+  break;
+case WebAssembly::BI__builtin_wasm_store8_lane:
+  IntNo = Intrinsic::wasm_store8_lane;
+  break;
+case WebAssembly::BI__builtin_wasm_store16_lane:
+  IntNo = Intrinsic::wasm_store16_lane;
+  break;
+case WebAssembly::BI__builtin_wasm_store32_lane:
+  IntNo = Intrinsic::wasm_store32_lane;
+  break;
+case WebAssembly::BI__builtin_wasm_store64_lane:
+  IntNo = Intrinsic::wasm_store64_lane;
+  break;
+default:
+  llvm_unreachable("unexpected builtin ID");
+}
+Function *Callee = CGM.getIntrinsic(IntNo);
+return Builder.CreateCall(Callee, {Ptr, Vec, LaneIdx});
+  }
   case WebAssembly::BI__builtin_wasm_shuffle_v8x16: {
 Value *Ops[18];
 size_t OpIdx 

[PATCH] D89475: [SemaObjC] Fix composite pointer type calculation for `void*` and pointer to lifetime qualified ObjC pointer type

2020-10-15 Thread Erik Pilkington via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG351317167e2b: [SemaObjC] Fix composite pointer type 
calculation for `void*` and pointer to… (authored by erik.pilkington).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89475

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaObjCXX/arc-ptr-comparison.mm


Index: clang/test/SemaObjCXX/arc-ptr-comparison.mm
===
--- clang/test/SemaObjCXX/arc-ptr-comparison.mm
+++ clang/test/SemaObjCXX/arc-ptr-comparison.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only 
-fobjc-arc -verify %s
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only 
-fobjc-runtime-has-weak -fobjc-arc -verify %s
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only 
-verify -DNOARC %s
 #ifdef NOARC
 // expected-no-diagnostics
@@ -51,3 +51,17 @@
   return a == cv;
   return ca == v;
 }
+
+#ifndef NOARC
+int testDoublePtr(void *pv, void **ppv, A *__strong* pspa, A *__weak* pwpa, A 
*__strong** ppspa) {
+  return pv == pspa;
+  return pspa == pv;
+  return pv == pspa;
+  return pv == pwpa;
+  return pspa == pwpa; // expected-error {{comparison of distinct pointer 
types}}
+  return ppv == pspa; // expected-error {{comparison of distinct pointer 
types}}
+  return pspa == ppv; // expected-error {{comparison of distinct pointer 
types}}
+  return pv == ppspa;
+  return ppv == ppspa; // expected-error{{comparison of distinct pointer 
types}}
+}
+#endif
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -6552,12 +6552,16 @@
   // FIXME: In C, we merge __strong and none to __strong at the top level.
   if (Q1.getObjCGCAttr() == Q2.getObjCGCAttr())
 Quals.setObjCGCAttr(Q1.getObjCGCAttr());
+  else if (T1->isVoidPointerType() || T2->isVoidPointerType())
+assert(Steps.size() == 1);
   else
 return QualType();
 
   // Mismatched lifetime qualifiers never compatibly include each other.
   if (Q1.getObjCLifetime() == Q2.getObjCLifetime())
 Quals.setObjCLifetime(Q1.getObjCLifetime());
+  else if (T1->isVoidPointerType() || T2->isVoidPointerType())
+assert(Steps.size() == 1);
   else
 return QualType();
 


Index: clang/test/SemaObjCXX/arc-ptr-comparison.mm
===
--- clang/test/SemaObjCXX/arc-ptr-comparison.mm
+++ clang/test/SemaObjCXX/arc-ptr-comparison.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify %s
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -verify %s
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only -verify -DNOARC %s
 #ifdef NOARC
 // expected-no-diagnostics
@@ -51,3 +51,17 @@
   return a == cv;
   return ca == v;
 }
+
+#ifndef NOARC
+int testDoublePtr(void *pv, void **ppv, A *__strong* pspa, A *__weak* pwpa, A *__strong** ppspa) {
+  return pv == pspa;
+  return pspa == pv;
+  return pv == pspa;
+  return pv == pwpa;
+  return pspa == pwpa; // expected-error {{comparison of distinct pointer types}}
+  return ppv == pspa; // expected-error {{comparison of distinct pointer types}}
+  return pspa == ppv; // expected-error {{comparison of distinct pointer types}}
+  return pv == ppspa;
+  return ppv == ppspa; // expected-error{{comparison of distinct pointer types}}
+}
+#endif
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -6552,12 +6552,16 @@
   // FIXME: In C, we merge __strong and none to __strong at the top level.
   if (Q1.getObjCGCAttr() == Q2.getObjCGCAttr())
 Quals.setObjCGCAttr(Q1.getObjCGCAttr());
+  else if (T1->isVoidPointerType() || T2->isVoidPointerType())
+assert(Steps.size() == 1);
   else
 return QualType();
 
   // Mismatched lifetime qualifiers never compatibly include each other.
   if (Q1.getObjCLifetime() == Q2.getObjCLifetime())
 Quals.setObjCLifetime(Q1.getObjCLifetime());
+  else if (T1->isVoidPointerType() || T2->isVoidPointerType())
+assert(Steps.size() == 1);
   else
 return QualType();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3513171 - [SemaObjC] Fix composite pointer type calculation for `void*` and pointer to lifetime qualified ObjC pointer type

2020-10-15 Thread Erik Pilkington via cfe-commits

Author: Erik Pilkington
Date: 2020-10-15T15:21:01-04:00
New Revision: 351317167e2b28aad03f8e45e0ed0acbbff18c61

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

LOG: [SemaObjC] Fix composite pointer type calculation for `void*` and pointer 
to lifetime qualified ObjC pointer type

Fixes a regression introduced in 9a6f4d451ca7. rdar://70101809

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

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaObjCXX/arc-ptr-comparison.mm

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 8d5dccc19726..b96649597274 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6552,12 +6552,16 @@ QualType Sema::FindCompositePointerType(SourceLocation 
Loc,
   // FIXME: In C, we merge __strong and none to __strong at the top level.
   if (Q1.getObjCGCAttr() == Q2.getObjCGCAttr())
 Quals.setObjCGCAttr(Q1.getObjCGCAttr());
+  else if (T1->isVoidPointerType() || T2->isVoidPointerType())
+assert(Steps.size() == 1);
   else
 return QualType();
 
   // Mismatched lifetime qualifiers never compatibly include each other.
   if (Q1.getObjCLifetime() == Q2.getObjCLifetime())
 Quals.setObjCLifetime(Q1.getObjCLifetime());
+  else if (T1->isVoidPointerType() || T2->isVoidPointerType())
+assert(Steps.size() == 1);
   else
 return QualType();
 

diff  --git a/clang/test/SemaObjCXX/arc-ptr-comparison.mm 
b/clang/test/SemaObjCXX/arc-ptr-comparison.mm
index b3af26c1f847..0ea66c6643bd 100644
--- a/clang/test/SemaObjCXX/arc-ptr-comparison.mm
+++ b/clang/test/SemaObjCXX/arc-ptr-comparison.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only 
-fobjc-arc -verify %s
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only 
-fobjc-runtime-has-weak -fobjc-arc -verify %s
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only 
-verify -DNOARC %s
 #ifdef NOARC
 // expected-no-diagnostics
@@ -51,3 +51,17 @@ int testMixedQualComparisonRules(void *v, const void *cv, A 
*a, const A *ca) {
   return a == cv;
   return ca == v;
 }
+
+#ifndef NOARC
+int testDoublePtr(void *pv, void **ppv, A *__strong* pspa, A *__weak* pwpa, A 
*__strong** ppspa) {
+  return pv == pspa;
+  return pspa == pv;
+  return pv == pspa;
+  return pv == pwpa;
+  return pspa == pwpa; // expected-error {{comparison of distinct pointer 
types}}
+  return ppv == pspa; // expected-error {{comparison of distinct pointer 
types}}
+  return pspa == ppv; // expected-error {{comparison of distinct pointer 
types}}
+  return pv == ppspa;
+  return ppv == ppspa; // expected-error{{comparison of distinct pointer 
types}}
+}
+#endif



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


[PATCH] D88712: [CGBuiltin] Respect asm labels and redefine_extname for builtins with specialized emitting

2020-10-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I worry that we're chasing after the implementation details of GCC here. It 
seems self-contradictory to say all three of these things at once:

1. The frontend function `foo` has known, builtin semantics X. (Eg, we'll use 
those semantics in the frontend.)
2. The symbol `foo` has known, builtin semantics X. (Eg, we'll synthesize calls 
to `foo` from the middle-end.)
3. It's not correct to lower a call to the frontend function `foo` to the 
symbol `foo`.

So, from a principled standpoint, which of the above do we not consider to be 
correct in this situation?

- If we don't consider (1) to be correct, then we need to stop treating `foo` 
as a builtin everywhere -- we shouldn't be constant-evaluating calls to it, in 
particular. That's problematic in principle, because the `asm` label might be 
added after we've already seen the first declaration and added a `BuiltinAttr` 
to it. If we want to go in this direction, I think we should require a build 
that attaches an `asm` label to a builtin to also pass `-fno-builtin-foo` 
rather than trying to un-builtin a builtin function after the fact.
- If we don't consider (2) to be correct, then we need to stop the middle-end 
from inserting calls to the symbol `foo`, and get it to use the new symbol 
instead. That'd be the "teach the target libcall info about this" approach, 
which (as you point out) would be quite complex.
- The status quo is that we don't consider (3) to be correct. If we take this 
path, I suppose we could say that we make a best effort to use the renamed 
symbol, but provide no guarantees. That seems unprincipled and will likely 
continue to cause problems down the line, but maybe this gets us closest to the 
observed GCC behavior?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88712

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


[PATCH] D89445: clang/Basic: Remove ContentCache::getRawBuffer, NFC

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith updated this revision to Diff 298434.
dexonsmith added a comment.

Fix a compile error (I forgot to run `check-clang-tools` before).


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

https://reviews.llvm.org/D89445

Files:
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp

Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1468,7 +1468,7 @@
 if (PP->getHeaderSearchInfo()
 .getHeaderSearchOpts()
 .ValidateASTInputFilesContent) {
-  auto *MemBuff = Cache->getRawBuffer();
+  auto MemBuff = Cache->getBufferIfLoaded();
   if (MemBuff)
 ContentHash = hash_value(MemBuff->getBuffer());
   else
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -1542,7 +1542,7 @@
   = SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter));
 if (OverriddenBuffer && !ContentCache->BufferOverridden &&
 ContentCache->ContentsEntry == ContentCache->OrigEntry &&
-!ContentCache->getRawBuffer()) {
+!ContentCache->getBufferIfLoaded()) {
   auto Buffer = ReadBuffer(SLocEntryCursor, File->getName());
   if (!Buffer)
 return true;
Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -153,7 +153,7 @@
 
   // Check that the file's size is the same as in the file entry (which may
   // have come from a stat cache).
-  if (getRawBuffer()->getBufferSize() != (size_t)ContentsEntry->getSize()) {
+  if (Buffer->getBufferSize() != (size_t)ContentsEntry->getSize()) {
 if (Diag.isDiagnosticInFlight())
   Diag.SetDelayedDiagnostic(diag::err_file_modified,
 ContentsEntry->getName());
@@ -361,7 +361,7 @@
 Clone->BufferOverridden = Cache->BufferOverridden;
 Clone->IsFileVolatile = Cache->IsFileVolatile;
 Clone->IsTransient = Cache->IsTransient;
-Clone->setUnownedBuffer(Cache->getRawBuffer());
+Clone->setUnownedBuffer(Cache->getBufferIfLoaded());
 return Clone;
   };
 
@@ -474,7 +474,8 @@
 SourceManager::getFakeContentCacheForRecovery() const {
   if (!FakeContentCacheForRecovery) {
 FakeContentCacheForRecovery = std::make_unique();
-FakeContentCacheForRecovery->setUnownedBuffer(getFakeBufferForRecovery());
+FakeContentCacheForRecovery->setUnownedBuffer(
+getFakeBufferForRecovery()->getMemBufferRef());
   }
   return FakeContentCacheForRecovery.get();
 }
@@ -749,10 +750,7 @@
   if (!SLoc.isFile() || MyInvalid)
 return None;
 
-  if (const llvm::MemoryBuffer *Buf =
-  SLoc.getFile().getContentCache()->getRawBuffer())
-return Buf->getBuffer();
-  return None;
+  return SLoc.getFile().getContentCache()->getBufferDataIfLoaded();
 }
 
 llvm::Optional SourceManager::getBufferDataOrNone(FileID FID) const {
Index: clang/include/clang/Basic/SourceManager.h
===
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -194,9 +194,23 @@
 /// this content cache.  This is used for performance analysis.
 llvm::MemoryBuffer::BufferKind getMemoryBufferKind() const;
 
-/// Get the underlying buffer, returning NULL if the buffer is not
-/// yet available.
-const llvm::MemoryBuffer *getRawBuffer() const { return Buffer.get(); }
+/// Return the buffer, only if it has been loaded.
+/// specified FileID, returning None if it's not yet loaded.
+///
+/// \param FID The file ID whose contents will be returned.
+llvm::Optional getBufferIfLoaded() const {
+  if (Buffer)
+return Buffer->getMemBufferRef();
+  return None;
+}
+
+/// Return a StringRef to the source buffer data, only if it has already
+/// been loaded.
+llvm::Optional getBufferDataIfLoaded() const {
+  if (Buffer)
+return Buffer->getBuffer();
+  return None;
+}
 
 /// Set the buffer.
 void setBuffer(std::unique_ptr B) {
@@ -207,10 +221,10 @@
 /// Set the buffer to one that's not owned (or to nullptr).
 ///
 /// \pre Buffer cannot already be set.
-void setUnownedBuffer(const llvm::MemoryBuffer *B) {
+void setUnownedBuffer(llvm::Optional B) {
   assert(!Buffer && "Expected to be called right after construction");
   if (B)
-setBuffer(llvm::MemoryBuffer::getMemBuffer(B->getMemBufferRef()));
+setBuffer(llvm::MemoryBuffer::getMemBuffer(*B));
 }
 
   

[PATCH] D86097: [OpenMP][AMDGCN] Generate global variables and attributes for AMDGCN

2020-10-15 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam marked 3 inline comments as done.
saiislam added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeAMDGCN.cpp:175
+
+void CGOpenMPRuntimeAMDGCN::emitSPMDKernelWrapper(
+const OMPExecutableDirective &D, StringRef ParentName,

JonChesterfield wrote:
> The nvptx emitSPMDKernelWrapper does nothing and the amdgcn one appends some 
> metadata.
> 
> How about 'nvptx::generateMetadata(...)' that does nothing and 
> 'amdgcn::generateMetadata(...)` that does this stuff, called from the end of 
> emitSPMDKernel?
It will be then difficult to track what all things are being done differently 
in the two. So, the common code has been generalized and (no change in nvptx + 
some changes in amdgcn) has been used as specialization.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeAMDGCN.h:49
+
+  /// Allocate global variable for TransferMedium
+  llvm::GlobalVariable *

JonChesterfield wrote:
> I'm not convinced by this abstraction. It looks like amdgcn and nvptx want 
> almost exactly the same variable in each case. The difference appears to be 
> that nvptx uses internal linkage and amdgcn uses weak + externally 
> initialized, in which case we're better off with
> 
> `bool nvptx::needsExternalInitialization() {return false;}`
> `bool amdgpu::needsExternalInitialization() {return true;}`
> 
> Or, if the inline ternary is unappealing, amdgcn::NewGlobalVariable(...) that 
> passes the arguments to llvm::GlobalVariable while setting the two fields 
> that differ between the two.
> 
> 
I understand what you are suggesting. But, there are multiple such variables 
where linkage between nvptx and amdgcn are different. Also current style gives 
flexibility to a future implementation to define these variables in their own 
way.
What do you think?



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.h:175
 
+  /// Emit outlined function specialized for the Fork-Join
+  /// programming model for applicable target directives on the NVPTX device.

JonChesterfield wrote:
> Please put this back to the previous location so we can see whether it 
> changed in the diff
This movement changes them from private to protected.
I could have just added access specifiers and not move the definitions. It 
would have simplified the review, but it would have decreased the readability 
for future.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.h:217-249
+  /// Allocate global variable for TransferMedium
+  virtual llvm::GlobalVariable *
+  allocateTransferMediumGlobal(CodeGenModule &CGM, llvm::ArrayType *Ty,
+   StringRef TransferMediumName) = 0;
+
+  /// Allocate global variable for SharedStaticRD
+  virtual llvm::GlobalVariable *

ABataev wrote:
> Are all these required to be public?
Yes, they are being called from outside class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86097

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


[PATCH] D89488: WIP: FileManager: Shrink FileEntryRef to the size of a pointer

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith planned changes to this revision.
dexonsmith added a comment.

I'd still appreciate feedback on the direction, but 
`clang/test/ClangScanDeps/modules-full.cpp` is failing (getting `""` 
listed twice under `"file-deps"` for each translation unit) so I'm marking this 
as needing changes.


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

https://reviews.llvm.org/D89488

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


[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D89372#2332853 , @jvesely wrote:

> `cl_khr_byte_addressable_stores` changes language semantics. without it, 
> pointer dereferences of types smaller than 32 bits are illegal.

Ok, does it mean that we are missing to diagnose this in the frontend? Btw I do 
acknowledge that what you say makes sense but I don't think the documentation 
support that:
https://www.khronos.org/registry/OpenCL/sdk/2.2/docs/man/html/cl_khr_byte_addressable_store.html

Am I just looking in the wrong place?

> Even if all clang targets support this the macro should still be defined for 
> backward compatibility.

Ok, are you saying that all targets currently support this and we sould always 
define it? In this case I would be more happy if we move them into the internal 
header that we add implicitly anyway...

> it would be useful if the commit message or the description of this revision 
> included a justification for each removed extension why it doesn't impact 
> language semantics with spec references.

Yes, this is a good suggestion in principle and we should try our best. However 
I am not sure it is feasible for all of those, in particular this documentation 
doesn't contain anything:
https://man.opencl.org/cl_khr_context_abort.html

Are you suggesting to leave this out? However I don't see any evidence that 
this require either macro or pragma. I feel this is in rather incomplete state. 
So I don't feel we can accomodate for all of these.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89372

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


[PATCH] D89490: Introduce __attribute__((darwin_abi))

2020-10-15 Thread Adrien Guinet via Phabricator via cfe-commits
aguinet created this revision.
aguinet added reviewers: t.p.northover, mstorsjo, thegameg.
Herald added subscribers: llvm-commits, cfe-commits, arphaman, dexonsmith, 
steven_wu, hiraditya, kristof.beyls, krytarowski.
Herald added a reviewer: aaron.ballman.
Herald added projects: clang, LLVM.
aguinet requested review of this revision.

This patch introduces the "darwin_abi" function attribute, to be able to 
compile functions for the Apple ARM64 ABI when targeting other ARM64 OSes. For 
now, only Linux/ARM64 is supported/tested.

I explained the motivation behind this and some limitations in this mail on 
llvm-dev: http://lists.llvm.org/pipermail/llvm-dev/2020-October/145680.html . 
Please note that, in this mail, I call this attribute "apple_abi". I decided to 
change it to "darwin_abi", because everything Apple-related is called "darwin" 
in clang/llvm. That being said, I don't have any strong opinion on this, and 
will be willing to hear any argument in favoir of one or the other.

It does not allow to target all the differences that exist in the Darwin ARM64 
ABI against the standard AAPCS one (see [1] for the exhaustive list).

What I beleive is implemented:

- targeting the Darwin AAPCS ABI for C functions, especially those with 
variadic arguments. This means everything in section "Pass Arguments to 
Functions Correctly" and "Update Code that Passes Arguments to Variadic 
Functions" in [1].

- "The ABI requires the complete object (C1) and base-object (C2) constructors 
to return this to their callers. Similarly, the complete object (D1 
) and base-object (D2 
) destructors return this. This behavior matches 
the ARM 32-bit C++ ABI." (quoting [1]). I am not sure this would be useful to 
anyone, but that was not that hard to implement it, so I put it. The C++ 
support isn't complete in this patch though (see below), so maybe it's better 
to remove it.

- "When passing parameters to a function, Apple platforms ignore empty 
structures unless those structures have a nontrivial destructor or copy 
constructor. When passing such nontrivial structures, treat them as aggregates 
with one byte member in the generic manner." (quoting [1])

- properly forwarding variadic arguments from a "darwin_abi function" to a 
linux one using va_list, by zeroing the relevant fields in the linux va_list 
structure to make sure only stack arguments will be used (cf. discussions in 
the aforementioned ML thread)

What isn't implemented and isn't supported (quoting [1]):

- "The ABI provides a fixed layout of two size_t words for array cookies, with 
no extra alignment requirements. This behavior matches the ARM 32-bit C++ ABI." 
=> this would require allowing the "darwin_abi" to be set on class types, and I 
think the overall feature would make a non-trivial patch. I prefer doing the C 
ABI right and eventually implement this afterwards.

- "A pointer to a function declared as extern “C” isn’t interchangeable with a 
function declared as extern “c++”. This behavior differs from the ARM64 ABI, in 
which the functions are interchangeable." => I'm not sure to find where this is 
tested in clang, let alone this would be possible to be tested.

- My understanding is that we should keep the Itanium mangling, even for 
functions with the "darwin_abi" attributes, so I didn't implemented the 
mangling differences. For instance, if I understood correctly, setting the 
"ms_abi" on a C++ function doesn't use the MSVC mangling.

- Everything remaining in the "Handle C++ Differences" section in [1]

[1] 
https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
 for reference


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89490

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Specifiers.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/darwin_abi.c
  clang/test/CodeGen/darwin_abi_empty_structs.cpp
  clang/test/CodeGen/darwin_abi_vaarg.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/CodeGenCXX/darwinabi-returnthis.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/BinaryFormat/Dwarf.def
  llvm/include/llvm/IR/CallingConv.h
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/Target/AArch64/AArch64CallingConvention.cpp
  llvm/lib/Target/AArch64/AArch64FastISel.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
  llvm

[PATCH] D89276: Support ObjC in IncludeInserter

2020-10-15 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89276

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


[PATCH] D57265: [PM/CC1] Add -f[no-]split-cold-code CC1 options to toggle splitting

2020-10-15 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.

Thank you! LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57265

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


[PATCH] D89488: WIP: FileManager: Shrink FileEntryRef to the size of a pointer

2020-10-15 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added subscribers: usaxena95, ributzka, kadircet.
dexonsmith requested review of this revision.

This is a WIP patch to shrink FileEntryRef to the size of a pointer,
posting for early feedback in case someone has some. This pulled in more
changes than I expected, and I'll try to find some things to split off
and commit incrementally, but I think this concept is sound
(`BasicTests` passes, still have to build and test the rest of clang).


https://reviews.llvm.org/D89488

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang/include/clang/Basic/FileManager.h
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/FileManager.cpp
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Frontend/DependencyFile.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/unittests/Basic/FileManagerTest.cpp
  clang/unittests/Basic/SourceManagerTest.cpp

Index: clang/unittests/Basic/SourceManagerTest.cpp
===
--- clang/unittests/Basic/SourceManagerTest.cpp
+++ clang/unittests/Basic/SourceManagerTest.cpp
@@ -496,23 +496,26 @@
 
   std::unique_ptr Buf =
   llvm::MemoryBuffer::getMemBuffer(Source);
-  const FileEntry *SourceFile =
-  FileMgr.getVirtualFile("mainFile.cpp", Buf->getBufferSize(), 0);
-  SourceMgr.overrideFileContents(SourceFile, std::move(Buf));
+  auto SourceFile =
+  FileMgr.getVirtualFileRef("mainFile.cpp", Buf->getBufferSize(), 0);
+  SourceMgr.overrideFileContents(&SourceFile.getFileEntry(), std::move(Buf));
 
   std::unique_ptr Buf2 =
   llvm::MemoryBuffer::getMemBuffer(Source);
-  const FileEntry *SecondFile =
-  FileMgr.getVirtualFile("file2.cpp", Buf2->getBufferSize(), 0);
-  SourceMgr.overrideFileContents(SecondFile, std::move(Buf2));
+  auto SecondFile =
+  FileMgr.getVirtualFileRef("file2.cpp", Buf2->getBufferSize(), 0);
+  SourceMgr.overrideFileContents(&SecondFile.getFileEntry(), std::move(Buf2));
 
-  FileID MainFileID = SourceMgr.getOrCreateFileID(SourceFile, SrcMgr::C_User);
+  FileID MainFileID =
+  SourceMgr.getOrCreateFileID(&SourceFile.getFileEntry(), SrcMgr::C_User);
   SourceMgr.setMainFileID(MainFileID);
 
-  EXPECT_TRUE(SourceMgr.isMainFile(FileEntryRef("mainFile.cpp", *SourceFile)));
-  EXPECT_TRUE(
-  SourceMgr.isMainFile(FileEntryRef("anotherName.cpp", *SourceFile)));
-  EXPECT_FALSE(SourceMgr.isMainFile(FileEntryRef("mainFile.cpp", *SecondFile)));
+  auto MainAlias =
+  FileMgr.addAliasForFile("anotherName.cpp", SourceFile.getFileEntry());
+
+  EXPECT_TRUE(SourceMgr.isMainFile(SourceFile));
+  EXPECT_TRUE(SourceMgr.isMainFile(*MainAlias));
+  EXPECT_FALSE(SourceMgr.isMainFile(SecondFile));
 }
 
 #endif
Index: clang/unittests/Basic/FileManagerTest.cpp
===
--- clang/unittests/Basic/FileManagerTest.cpp
+++ clang/unittests/Basic/FileManagerTest.cpp
@@ -485,29 +485,34 @@
   // Set up a virtual file with a different size than FakeStatCache uses.
   const FileEntry *File = Manager.getVirtualFile("/tmp/test", /*Size=*/10, 0);
   ASSERT_TRUE(File);
-  FileEntryRef Ref("/tmp/test", *File);
-  EXPECT_TRUE(Ref.isValid());
-  EXPECT_EQ(Ref.getSize(), 10);
+  const FileEntry &FE = *File;
+  EXPECT_TRUE(FE.isValid());
+  EXPECT_EQ(FE.getSize(), 10);
 
   // Calling a second time should not affect the UID or size.
-  unsigned VirtualUID = Ref.getUID();
-  EXPECT_EQ(*expectedToOptional(Manager.getFileRef("/tmp/test")), Ref);
-  EXPECT_EQ(Ref.getUID(), VirtualUID);
-  EXPECT_EQ(Ref.getSize(), 10);
+  unsigned VirtualUID = FE.getUID();
+  EXPECT_EQ(
+  &FE,
+  &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry());
+  EXPECT_EQ(FE.getUID(), VirtualUID);
+  EXPECT_EQ(FE.getSize(), 10);
 
   // Bypass the file.
-  llvm::Optional BypassRef = Manager.getBypassFile(Ref);
+  llvm::Optional BypassRef =
+  Manager.getBypassFile(File->getLastRef());
   ASSERT_TRUE(BypassRef);
   EXPECT_TRUE(BypassRef->isValid());
-  EXPECT_EQ(BypassRef->getName(), Ref.getName());
+  EXPECT_EQ("/tmp/test", BypassRef->getName());
 
   // Check that it's different in the right ways.
   EXPECT_NE(&BypassRef->getFileEntry(), File);
   EXPECT_NE(BypassRef->getUID(), VirtualUID);
-  EXPECT_NE(BypassRef->getSize(), Ref.getSize());
+  EXPECT_NE(BypassRef->getSize(), FE.getSize());
 
   // The virtual file should still be returned when searching.
-  EXPECT_EQ(*expectedToOptional(Manager.getFileRef("/tmp/test")), Ref);
+  EXPECT_EQ(
+  &FE,
+  &expectedToOptional(Manager.getFileRef("/tmp/test"))->getFileEntry());
 }
 
 } // anonymous namespace
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -77,8 

[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-15 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D85802#2332808 , @rnk wrote:

> Would "f[no-]fuchsia-c++-abi-extensions" (or shorter, -ffuchsia-c++-abi) do 
> the trick? I know it doesn't map well onto our current internal option 
> representation, but I don't think the internal representation is particularly 
> good. I'd rather limit the user-visible driver interface to give us the 
> flexibility to change the internal representation in the future.

For our use case yes, we could have `-f[no-]fuchsia-c++-abi` which would be 
enabled by default when the target is Fuchsia.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D89453: Fix hidden-redecls.m test for some environments

2020-10-15 Thread Konstantin Schwarz via Phabricator via cfe-commits
kschwarz added a comment.

Yes, I'll commit it tomorrow, thanks for the review @akyrtzi!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89453

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


[PATCH] D57265: [PM/CC1] Add -f[no-]split-cold-code CC1 options to toggle splitting

2020-10-15 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 298425.
compnerd added a comment.
Herald added a subscriber: arichardson.

Passes locally now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57265

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/split-cold-code.c
  clang/test/Frontend/split-cold-code.c
  llvm/include/llvm/Transforms/IPO/HotColdSplitting.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Transforms/IPO/HotColdSplitting.cpp
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
  llvm/test/Other/X86/lto-hot-cold-split.ll
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-lto-defaults.ll
  llvm/test/Other/new-pm-pgo.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/opt-O2-pipeline.ll
  llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/opt-Os-pipeline.ll
  llvm/test/Other/opt-hot-cold-split.ll
  llvm/test/Other/pass-pipelines.ll
  llvm/test/Transforms/CodeExtractor/extract-assume.ll
  llvm/test/Transforms/HotColdSplit/X86/do-not-split.ll
  llvm/test/Transforms/HotColdSplit/addr-taken.ll
  llvm/test/Transforms/HotColdSplit/apply-noreturn-bonus.ll
  llvm/test/Transforms/HotColdSplit/apply-penalty-for-inputs.ll
  llvm/test/Transforms/HotColdSplit/apply-penalty-for-outputs.ll
  llvm/test/Transforms/HotColdSplit/apply-successor-penalty.ll
  llvm/test/Transforms/HotColdSplit/assumption-cache-invalidation.ll
  llvm/test/Transforms/HotColdSplit/coldentrycount.ll
  llvm/test/Transforms/HotColdSplit/delete-use-without-def-dbg-val.ll
  llvm/test/Transforms/HotColdSplit/duplicate-phi-preds-crash.ll
  llvm/test/Transforms/HotColdSplit/eh-pads.ll
  llvm/test/Transforms/HotColdSplit/eh-typeid-for.ll
  llvm/test/Transforms/HotColdSplit/forward-dfs-reaches-marked-block.ll
  llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-1.ll
  llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-2.ll
  llvm/test/Transforms/HotColdSplit/mark-the-whole-func-cold.ll
  llvm/test/Transforms/HotColdSplit/minsize.ll
  llvm/test/Transforms/HotColdSplit/multiple-exits.ll
  llvm/test/Transforms/HotColdSplit/noreturn.ll
  llvm/test/Transforms/HotColdSplit/outline-cold-asm.ll
  llvm/test/Transforms/HotColdSplit/outline-disjoint-diamonds.ll
  llvm/test/Transforms/HotColdSplit/outline-if-then-else.ll
  llvm/test/Transforms/HotColdSplit/outline-multiple-entry-region.ll
  llvm/test/Transforms/HotColdSplit/outline-while-loop.ll
  llvm/test/Transforms/HotColdSplit/phi-with-distinct-outlined-values.ll
  llvm/test/Transforms/HotColdSplit/region-overlap.ll
  llvm/test/Transforms/HotColdSplit/resume.ll
  llvm/test/Transforms/HotColdSplit/retain-section.ll
  llvm/test/Transforms/HotColdSplit/section-splitting-custom.ll
  llvm/test/Transforms/HotColdSplit/section-splitting-default.ll
  llvm/test/Transforms/HotColdSplit/split-cold-2.ll
  llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
  llvm/test/Transforms/HotColdSplit/split-out-dbg-val-of-arg.ll
  llvm/test/Transforms/HotColdSplit/split-phis-in-exit-blocks.ll
  llvm/test/Transforms/HotColdSplit/stale-assume-in-original-func.ll
  llvm/test/Transforms/HotColdSplit/succ-block-with-self-edge.ll
  llvm/test/Transforms/HotColdSplit/swifterror.ll
  llvm/test/Transforms/HotColdSplit/transfer-debug-info.ll
  llvm/test/Transforms/HotColdSplit/unwind.ll
  llvm/test/Transforms/HotColdSplit/update-split-loop-metadata.ll
  llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.expected
  
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected

Index: llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected
===
--- llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected
+++ llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected
@@ -3,13 +3,13 @@
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.14.0"
 
-define void @foo(i32) {
+define void @foo(i32) "hot-cold-split" {
 ; CHECK-LABEL: @foo(
 ; CHECK-NEXT:[[TMP2:%.*]] = icmp eq i32 [[TMP0:%.*]], 0
 ; CHECK-NEXT:tail call void @_Z10sideeffectv()
 ; CHECK-NEXT:br i1 [[TMP2]], label [[CODEREPL:%.*]], label [[EXIT:%.*]]
 ; CHECK:   codeRepl:
-; CHECK-NEXT:call void @foo.cold.1() [[ATTR2:#.*]]
+; CHECK-NEXT:call void 

[PATCH] D89360: Treat constant contexts as being in the default rounding mode.

2020-10-15 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

As C++ case is much more complicated and we need a ruleset based on essential 
properties rather than implementation viewpoint, I am convinced that the 
solution based on manifestly constant-evaluated property is the best. 
Thank you for the discussion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89360

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


[PATCH] D88498: [FPEnv] Apply dynamic rounding to function body only

2020-10-15 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Actually this solution also behaves wrong in some cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88498

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


[PATCH] D89372: [OpenCL] Remove unused extensions

2020-10-15 Thread Jan Vesely via Phabricator via cfe-commits
jvesely added a comment.

`cl_khr_byte_addressable_stores` changes language semantics. without it, 
pointer dereferences of types smaller than 32 bits are illegal.
Even if all clang targets support this the macro should still be defined for 
backward compatibility.

it would be useful if the commit message or the description of this revision 
included a justification for each removed extension why it doesn't impact 
language semantics with spec references.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89372

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


[PATCH] D89297: [clangd] Add a TestWorkspace utility

2020-10-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

This looks like a useful infra to have indeed, we currently don't have an easy 
way to setup a testcase that would require interactions between multiple files 
(e.g. a workspace), as you've noticed while working on callhierarchy tests 
(sorry for that).

A couple of suggestions from my side:

- Rather than enforcing files to come in header/source pairs, why not have a 
`isTU` flag. That way we can use the infra in a more flexible way.
- Instead of having a MockFS, maybe have a single `TestTU` with all the 
workspace files put into `AdditionalFiles`.  Later on when building an AST, you 
can just replace the `TestTU::Code` and build the source as if it is in the 
`workspace`.
- Background or FileIndex is not the point handling include resolution (or AST 
build process). In theory during the construction time, after populating all 
the `AdditionalFiles` in a `TestTU`, you can have a single `FileIndex` and 
populated it for each TU using the AST coming from `TestTU::build()` and 
preamble from `TestTU::preamble()`. Currently `TestTU::preamble()` doesn't take 
a callback, but you can change that to populate the `FileIndex` using preamble 
information.
- In addition to having a constructor that takes all the files(or just some 
base files) at once, it might be better to have an interface like:

  struct WorkspaceTest {
void addSource(FilePath, Code);  // These are just sourcefiles, ASTs can be 
built for them, but they won't be MainFiles during indexing.
void addMainFile(FilePath, Code); // These are entrypoints, will be marked 
as TU, and would be used for index builds.
std::unique_ptr index(); // Builds the index for whole 
forkspace, by indexing all the MainFiles and merging them under a single 
FileIndex.
ParsedAST ast(FilePath);
  };


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89297

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


[PATCH] D89478: AMDGPU: Make sure both cc1 and cc1as process -m[no-]code-object-v3

2020-10-15 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG67f189e93ce3: Make sure both cc1 and cc1as process 
-m[no-]code-object-v3 (authored by kzhuravl).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89478

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/amdgpu-features-as.s
  clang/test/Driver/amdgpu-features.c

Index: clang/test/Driver/amdgpu-features.c
===
--- clang/test/Driver/amdgpu-features.c
+++ clang/test/Driver/amdgpu-features.c
@@ -6,6 +6,10 @@
 // NO-CODE-OBJECT-V3: warning: argument '-mno-code-object-v3' is deprecated, use '-mllvm --amdhsa-code-object-version=2' instead [-Wdeprecated]
 // NO-CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=2"
 
+// RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx700 -mcode-object-v3 -mno-code-object-v3 -mcode-object-v3 %s 2>&1 | FileCheck --check-prefix=MUL-CODE-OBJECT-V3 %s
+// MUL-CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use '-mllvm --amdhsa-code-object-version=3' instead [-Wdeprecated]
+// MUL-CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3"
+
 // RUN: %clang -### -target amdgcn-amdhsa -mcpu=gfx900:xnack+ %s 2>&1 | FileCheck --check-prefix=XNACK %s
 // XNACK: "-target-feature" "+xnack"
 
Index: clang/test/Driver/amdgpu-features-as.s
===
--- /dev/null
+++ clang/test/Driver/amdgpu-features-as.s
@@ -0,0 +1,11 @@
+// RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx900 -mcode-object-v3 %s 2>&1 | FileCheck --check-prefix=CODE-OBJECT-V3 %s
+// CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use '-mllvm --amdhsa-code-object-version=3' instead [-Wdeprecated]
+// CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3"
+
+// RUN: %clang -### -target amdgcn-amd-amdhsa amdgcn -mcpu=gfx900 -mno-code-object-v3 %s 2>&1 | FileCheck --check-prefix=NO-CODE-OBJECT-V3 %s
+// NO-CODE-OBJECT-V3: warning: argument '-mno-code-object-v3' is deprecated, use '-mllvm --amdhsa-code-object-version=2' instead [-Wdeprecated]
+// NO-CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=2"
+
+// RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx900 -mcode-object-v3 -mno-code-object-v3 -mcode-object-v3 %s 2>&1 | FileCheck --check-prefix=MUL-CODE-OBJECT-V3 %s
+// MUL-CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use '-mllvm --amdhsa-code-object-version=3' instead [-Wdeprecated]
+// MUL-CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -1073,6 +1073,25 @@
   llvm_unreachable("Unknown Reloc::Model kind");
 }
 
+static void HandleAmdgcnLegacyOptions(const Driver &D,
+  const ArgList &Args,
+  ArgStringList &CmdArgs) {
+  if (auto *CodeObjArg = Args.getLastArg(options::OPT_mcode_object_v3_legacy,
+ options::OPT_mno_code_object_v3_legacy)) {
+if (CodeObjArg->getOption().getID() == options::OPT_mcode_object_v3_legacy) {
+  D.Diag(diag::warn_drv_deprecated_arg) << "-mcode-object-v3" <<
+"-mllvm --amdhsa-code-object-version=3";
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("--amdhsa-code-object-version=3");
+} else {
+  D.Diag(diag::warn_drv_deprecated_arg) << "-mno-code-object-v3" <<
+"-mllvm --amdhsa-code-object-version=2";
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("--amdhsa-code-object-version=2");
+}
+  }
+}
+
 void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
 const Driver &D, const ArgList &Args,
 ArgStringList &CmdArgs,
@@ -6122,6 +6141,8 @@
 }
   }
 
+  HandleAmdgcnLegacyOptions(D, Args, CmdArgs);
+
   // For all the host OpenMP offloading compile jobs we need to pass the targets
   // information using -fopenmp-targets= option.
   if (JA.isHostOffloading(Action::OFK_OpenMP)) {
@@ -7085,6 +7106,8 @@
 CmdArgs.push_back(SplitDebugName(JA, Args, Input, Output));
   }
 
+  HandleAmdgcnLegacyOptions(D, Args, CmdArgs);
+
   assert(Input.isFilename() && "Invalid input.");
   CmdArgs.push_back(Input.getFilename());
 
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -525,19 +525,6 @@
 CC1Args.push_back("hidden");
 CC1Args.push_back("-fapply-global-visibility-to-externs");
   }
-
-  if (Drive

[clang] 67f189e - Make sure both cc1 and cc1as process -m[no-]code-object-v3

2020-10-15 Thread Konstantin Zhuravlyov via cfe-commits

Author: Konstantin Zhuravlyov
Date: 2020-10-15T14:03:26-04:00
New Revision: 67f189e93ce3c25db74697551a77831a72b34929

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

LOG: Make sure both cc1 and cc1as process -m[no-]code-object-v3

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

Added: 
clang/test/Driver/amdgpu-features-as.s

Modified: 
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/amdgpu-features.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 72ecc8cd9f3b..5df7236f0223 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -525,19 +525,6 @@ void AMDGPUToolChain::addClangTargetOptions(
 CC1Args.push_back("hidden");
 CC1Args.push_back("-fapply-global-visibility-to-externs");
   }
-
-  if (DriverArgs.hasArg(options::OPT_mcode_object_v3_legacy)) {
-getDriver().Diag(diag::warn_drv_deprecated_arg) << "-mcode-object-v3" <<
-  "-mllvm --amdhsa-code-object-version=3";
-CC1Args.push_back("-mllvm");
-CC1Args.push_back("--amdhsa-code-object-version=3");
-  }
-  if (DriverArgs.hasArg(options::OPT_mno_code_object_v3_legacy)) {
-getDriver().Diag(diag::warn_drv_deprecated_arg) << "-mno-code-object-v3" <<
-  "-mllvm --amdhsa-code-object-version=2";
-CC1Args.push_back("-mllvm");
-CC1Args.push_back("--amdhsa-code-object-version=2");
-  }
 }
 
 StringRef

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 39fcf240449c..d69dce650d94 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1073,6 +1073,25 @@ static const char 
*RelocationModelName(llvm::Reloc::Model Model) {
   llvm_unreachable("Unknown Reloc::Model kind");
 }
 
+static void HandleAmdgcnLegacyOptions(const Driver &D,
+  const ArgList &Args,
+  ArgStringList &CmdArgs) {
+  if (auto *CodeObjArg = Args.getLastArg(options::OPT_mcode_object_v3_legacy,
+ 
options::OPT_mno_code_object_v3_legacy)) {
+if (CodeObjArg->getOption().getID() == 
options::OPT_mcode_object_v3_legacy) {
+  D.Diag(diag::warn_drv_deprecated_arg) << "-mcode-object-v3" <<
+"-mllvm --amdhsa-code-object-version=3";
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("--amdhsa-code-object-version=3");
+} else {
+  D.Diag(diag::warn_drv_deprecated_arg) << "-mno-code-object-v3" <<
+"-mllvm --amdhsa-code-object-version=2";
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("--amdhsa-code-object-version=2");
+}
+  }
+}
+
 void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
 const Driver &D, const ArgList &Args,
 ArgStringList &CmdArgs,
@@ -6122,6 +6141,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 }
   }
 
+  HandleAmdgcnLegacyOptions(D, Args, CmdArgs);
+
   // For all the host OpenMP offloading compile jobs we need to pass the 
targets
   // information using -fopenmp-targets= option.
   if (JA.isHostOffloading(Action::OFK_OpenMP)) {
@@ -7085,6 +7106,8 @@ void ClangAs::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(SplitDebugName(JA, Args, Input, Output));
   }
 
+  HandleAmdgcnLegacyOptions(D, Args, CmdArgs);
+
   assert(Input.isFilename() && "Invalid input.");
   CmdArgs.push_back(Input.getFilename());
 

diff  --git a/clang/test/Driver/amdgpu-features-as.s 
b/clang/test/Driver/amdgpu-features-as.s
new file mode 100644
index ..850afe701740
--- /dev/null
+++ b/clang/test/Driver/amdgpu-features-as.s
@@ -0,0 +1,11 @@
+// RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx900 -mcode-object-v3 %s 
2>&1 | FileCheck --check-prefix=CODE-OBJECT-V3 %s
+// CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use 
'-mllvm --amdhsa-code-object-version=3' instead [-Wdeprecated]
+// CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=3"
+
+// RUN: %clang -### -target amdgcn-amd-amdhsa amdgcn -mcpu=gfx900 
-mno-code-object-v3 %s 2>&1 | FileCheck --check-prefix=NO-CODE-OBJECT-V3 %s
+// NO-CODE-OBJECT-V3: warning: argument '-mno-code-object-v3' is deprecated, 
use '-mllvm --amdhsa-code-object-version=2' instead [-Wdeprecated]
+// NO-CODE-OBJECT-V3: "-mllvm" "--amdhsa-code-object-version=2"
+
+// RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx900 -mcode-object-v3 
-mno-code-object-v3 -mcode-object-v3 %s 2>&1 | FileCheck 
--check-prefix=MUL-CODE-OBJECT-V3 %s
+// MUL-CODE-OBJECT-V3: warning: argument '-mcode-object-v3' is deprecated, use 
'-mllv

[PATCH] D88106: [SyntaxTree] Provide iterator-like functions for Lists

2020-10-15 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 298420.
eduucaldas added a comment.

Linting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88106

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Tree.cpp

Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -311,91 +311,40 @@
   }
 }
 
-std::vector>
-syntax::List::getElementsAsNodesAndDelimiters() {
-  if (!getFirstChild())
-return {};
-
-  std::vector> Children;
-  syntax::Node *ElementWithoutDelimiter = nullptr;
-  for (auto *C = getFirstChild(); C; C = C->getNextSibling()) {
-switch (C->getRole()) {
-case syntax::NodeRole::ListElement: {
-  if (ElementWithoutDelimiter) {
-Children.push_back({ElementWithoutDelimiter, nullptr});
-  }
-  ElementWithoutDelimiter = C;
-  break;
-}
-case syntax::NodeRole::ListDelimiter: {
-  Children.push_back({ElementWithoutDelimiter, cast(C)});
-  ElementWithoutDelimiter = nullptr;
-  break;
-}
-default:
-  llvm_unreachable(
-  "A list can have only elements and delimiters as children.");
-}
-  }
+bool syntax::List::isElement(syntax::Node *N) {
+  return N && N->getRole() == NodeRole::ListElement;
+}
 
-  switch (getTerminationKind()) {
-  case syntax::List::TerminationKind::Separated: {
-Children.push_back({ElementWithoutDelimiter, nullptr});
-break;
-  }
-  case syntax::List::TerminationKind::Terminated:
-  case syntax::List::TerminationKind::MaybeTerminated: {
-if (ElementWithoutDelimiter) {
-  Children.push_back({ElementWithoutDelimiter, nullptr});
-}
-break;
-  }
-  }
+bool syntax::List::isDelimiter(syntax::Node *N) {
+  return N && N->getRole() == NodeRole::ListDelimiter;
+}
 
-  return Children;
+syntax::List::ElementAndDelimiterIterator
+syntax::List::getBeforeBeginWithElementAsNode() {
+  return ElementAndDelimiterIterator::makeBeforeBegin(this);
 }
 
-// Almost the same implementation of `getElementsAsNodesAndDelimiters` but
-// ignoring delimiters
-std::vector syntax::List::getElementsAsNodes() {
-  if (!getFirstChild())
-return {};
+syntax::List::ElementAndDelimiterIterator
+syntax::List::getBeginNode() {
+  return std::next(ElementAndDelimiterIterator::makeBeforeBegin(this));
+}
 
-  std::vector Children;
-  syntax::Node *ElementWithoutDelimiter = nullptr;
-  for (auto *C = getFirstChild(); C; C = C->getNextSibling()) {
-switch (C->getRole()) {
-case syntax::NodeRole::ListElement: {
-  if (ElementWithoutDelimiter) {
-Children.push_back(ElementWithoutDelimiter);
-  }
-  ElementWithoutDelimiter = C;
-  break;
-}
-case syntax::NodeRole::ListDelimiter: {
-  Children.push_back(ElementWithoutDelimiter);
-  ElementWithoutDelimiter = nullptr;
-  break;
-}
-default:
-  llvm_unreachable("A list has only elements or delimiters.");
-}
-  }
+syntax::List::ElementAndDelimiterIterator
+syntax::List::getEndNode() {
+  return ElementAndDelimiterIterator::makeEnd(this);
+}
 
-  switch (getTerminationKind()) {
-  case syntax::List::TerminationKind::Separated: {
-Children.push_back(ElementWithoutDelimiter);
-break;
-  }
-  case syntax::List::TerminationKind::Terminated:
-  case syntax::List::TerminationKind::MaybeTerminated: {
-if (ElementWithoutDelimiter) {
-  Children.push_back(ElementWithoutDelimiter);
-}
-break;
-  }
-  }
+std::vector>
+syntax::List::getElementsAsNodesAndDelimiters() {
+  return std::vector>(
+  getBeginNode(), getEndNode());
+}
 
+std::vector syntax::List::getElementsAsNodes() {
+  std::vector Children;
+  std::transform(
+  getBeginNode(), getEndNode(), std::back_inserter(Children),
+  [](ElementAndDelimiter ED) { return ED.element; });
   return Children;
 }
 
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -230,91 +230,77 @@
 // vector
 std::vector
 syntax::NestedNameSpecifier::getSpecifiers() {
-  auto SpecifiersAsNodes = getElementsAsNodes();
   std::vector Children;
-  for (const auto &Element : SpecifiersAsNodes) {
-Children.push_back(llvm::cast(Element));
-  }
+  for (auto C : getNodeRange())
+Children.push_back(cast(C.element));
+
   return Children;
 }
 
 std::vector>
 syntax::NestedNameSpecifier::getSpecifiersAndDoubleColons() {
-  auto SpecifiersAsNodesAndDoubleColons = getElementsAsNodesAndDelimiters();
   std::vector>
   Children;
-  for (const auto &SpecifierAndDoubleColon : SpecifiersAsNodesAndDoubleColons) {
-Children.push_back(
-{llvm::cast(SpecifierAndDoubleColon.element),
- SpecifierAndDoubleColon.delimiter});
-  }
+  for (auto C : ge

[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-15 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Would "f[no-]fuchsia-c++-abi-extensions" (or shorter, -ffuchsia-c++-abi) do the 
trick? I know it doesn't map well onto our current internal option 
representation, but I don't think the internal representation is particularly 
good. I'd rather limit the user-visible driver interface to give us the 
flexibility to change the internal representation in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D89475: [SemaObjC] Fix composite pointer type calculation for `void*` and pointer to lifetime qualified ObjC pointer type

2020-10-15 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D89475

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


[PATCH] D84362: [NFC] Refactor DiagnosticBuilder and PartialDiagnostic

2020-10-15 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/include/clang/Basic/PartialDiagnostic.h:66
+return *this;
+  }
+

yaxunl wrote:
> rjmccall wrote:
> > Why are these template operators necessary?  The LHS of the `<<` should 
> > convert to a base reference type just fine.
> There are lots of usage patterns expecting the derived class after streaming, 
> e.g.
> 
> ```
> void foo(PartialDiagnostic& PD);
> foo(PD << X << Y);
> ```
I see.  You could also just do this in the base operators by just making them 
templates, e.g.

```
template 
std::enable_if_t, const 
Diagnostic &>
operator<<(const Diagnostic &D, ...) {
}
```

That way you'd never have these forwarding problems — but it would be more 
boilerplate for each operator, so maybe it's a wash.


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

https://reviews.llvm.org/D84362

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


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-10-15 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D85802#2332766 , @rnk wrote:

> In D85802#2331403 , @leonardchan 
> wrote:
>
>> Perhaps we can add some mechanism in Clang that determines which ABIs are 
>> supported for specific platforms? That is, when targetting Linux, Clang will 
>> diagnose an error if using `-fc++-abi=microsoft`. This could cover the case 
>> where a specific platform can support multiple ABIs, but those ABIs won't be 
>> supported by other platforms.
>
> Right, but the simplest code is the code that doesn't exist: if the option 
> doesn't exist, there's no need to diagnose anything. The rest of the "C++ 
> ABIs" aren't really their own C++ ABIs, they are just a reflection of the 
> target triple.
>
> What is the actual use case? I read the RFC, but ever since I became a 
> manager, my reading comprehension level dropped back to grade school, and I 
> apologize for that. As I understood it, you need a flag that enables all the 
> Itanium ABI extensions (relative vtables, and others) used in Fuchsia, at 
> once. A single relative vtable ABI flag isn't sufficient (would it be?).

We want to use Fuchsia C++ ABI by default when targeting Fuchsia. Fuchsia C++ 
ABI is a derivate of Itanium C++ ABI with various performance optimizations 
(similar to other derivative C++ ABIs like WebAssembly), and we plan on further 
evolving it, for example always using relative vtables. The problem is that we 
occasionally need to integrate code built with Clang with code produced by 
other compilers that don't support Fuchsia C++ ABI like GCC, so we would like 
to have an option to switch back to Itanium C++ ABI as the "legacy compatible" 
C++ ABI.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


  1   2   >