[PATCH] D106518: [RISCV] Disable EEW=64 for index values when XLEN=32.

2021-07-23 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:680
   foreach type = TypeList in {
-foreach eew_list = EEWList in {
+foreach eew_list = Xlen32EEWList in {
   defvar eew = eew_list[0];

HsiangKai wrote:
> There is no need to define `Xlen32EEWList`. You could use `EEWList[0-2]` for 
> the purpose.
Done, thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106518

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


[PATCH] D106285: [Analyzer][solver] Fix inconsistent equivalence class data

2021-07-23 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106285

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


[PATCH] D95588: [RISCV] Implement the MC layer support of P extension

2021-07-23 Thread Jim Lin via Phabricator via cfe-commits
Jim marked 8 inline comments as done.
Jim added inline comments.



Comment at: llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp:442
+
+if (STI.getFeatureBits()[RISCV::FeatureExtZpsfoperand] &&
+!STI.getFeatureBits()[RISCV::Feature64Bit]) {

jrtc27 wrote:
> The table is called RISCV32POnly but you're checking for Zpsfoperand 
> (whatever that mouthful of an extension is). Which is it?
Rename RISCV32POnly to RISCV32Zpsfoperand. 
This is for the instruction with even/odd paired-register operands on RV32. 

In RISCV32Zpsfoperand, two kinds of instruction defined for the same 
instruction in spec, one for RV32 with even/odd paired-register operands 
defined in RISCV32Zpsfoperand table , the other one for RV64 with normal GPR 
operands.





Comment at: llvm/lib/Target/RISCV/RISCV.td:186-188
+   [FeatureExtZpsfoperand,
+FeatureExtZpn,
+FeatureExtZprvsfextra]>;

jrtc27 wrote:
> These aren't correct? RV64 doesn't have Zpsfoperand and RV32 doesn't have 
> Zprvsfextra.
RV64 has Zpsfoperand extension that just has normal GPRs as operands (RV32 has 
even/odd paired-register operand).

RV32 doesn't have Zprvsfextra. All of instruction in Zprvsfextra are defined in 
Predicates = [HasStdExtZprvsfextra, IsRV64].

If P is enabled, it means Zpn+Zpsfoperand enabled on RV32, and 
Zpn+Zpsfoperand+Zprvsfextra enabled on RV64.



Comment at: llvm/lib/Target/RISCV/RISCVRegisterInfo.td:216
+// Dummy zero register for pairing with X0.
+def ZERO : RISCVReg<0, "0">;
+

jrtc27 wrote:
> Ew, this is a gross quirk of the register pair instructions. ZERO is not a 
> good name for it though, that's the ABI name for x0 so already taken and is 
> pretty confusing. I assume LLVM doesn't like it if you create a register pair 
> that is (X0, X0)?
Rename it to REG_PAIR_WITH_X0.



Comment at: llvm/lib/Target/RISCV/RISCVRegisterInfo.td:226-228
+def GPRPair : RegisterClass<"RISCV", [untyped], 64, (add GPRPairs)> {
+  let Size = 64;
+}

jrtc27 wrote:
> IMO the register class should be GPR32Pair not GPRPair unless you also make 
> it have a sensible interpretation for RV32 (which seems like a waste of time)
Rename it to GPR32Pair.



Comment at: llvm/lib/Target/RISCV/RISCVRegisterInfo.td:69
 
+def sub_lo : SubRegIndex<32>;
+def sub_hi : SubRegIndex<32, 32>;

jrtc27 wrote:
> Jim wrote:
> > Jim wrote:
> > > luismarques wrote:
> > > > jrtc27 wrote:
> > > > > This assumes RV32, and is not clear it applies to register pairs
> > > > What's the best way to address this?
> > > sub_lo and sub_hi are only used for GPRPair register class to extract a 
> > > register from pair registers on RV32.
> > Do you mean that sub_lo and sub_hi only used on RV32? Does it need to 
> > rename or ..?
> Yes, these should have names that make it clear they're for each half of a 
> 2*32-bit register pair. Otherwise it sounds like they're the 32-bit hi and lo 
> halves of the 64-bit registers on RV64.
Rename it to gpr_pair_lo and gpr_pair_hi


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95588

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


[clang-tools-extra] 8b0cc4a - [clang-tidy] Improve "common type" diagnostic output in 'bugprone-easily-swappable-parameters'

2021-07-23 Thread via cfe-commits

Author: Whisperity
Date: 2021-07-23T10:26:22+02:00
New Revision: 8b0cc4a65dd435096bf64651693f5c9c3e2fee3b

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

LOG: [clang-tidy] Improve "common type" diagnostic output in 
'bugprone-easily-swappable-parameters'

Make the check handle cases of the "common type" involved in the mix
being non-trivial, e.g. pointers, references, attributes, these things
coming from typedefs, etc.

This results in clearer diagnostics that have more coverage in their
explanation, such as saying `const int &` as common type instead of
`int`.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index 3cb4734e553b0..afcdca226911d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -469,18 +469,18 @@ struct MixData {
 return *this;
   }
 
-  /// Add the specified qualifiers to the common type in the Mix.
-  MixData qualify(Qualifiers Quals, const ASTContext &Ctx) const {
+  template  MixData withCommonTypeTransformed(F &&Func) const {
 if (CommonType.isNull())
   return *this;
 
-QualType NewCommonType = Ctx.getQualifiedType(CommonType, Quals);
+QualType NewCommonType = Func(CommonType);
 
 if (CreatedFromOneWayConversion) {
   MixData M{Flags, Conversion};
   M.CommonType = NewCommonType;
   return M;
 }
+
 return {Flags, NewCommonType, Conversion, ConversionRTL};
   }
 };
@@ -544,13 +544,13 @@ struct MixableParameterRange {
 /// Helper enum for the recursive calls in the modelling that toggle what kinds
 /// of implicit conversions are to be modelled.
 enum class ImplicitConversionModellingMode : unsigned char {
-  /// No implicit conversions are modelled.
+  ///< No implicit conversions are modelled.
   None,
 
-  /// The full implicit conversion sequence is modelled.
+  ///< The full implicit conversion sequence is modelled.
   All,
 
-  /// Only model a unidirectional implicit conversion and within it only one
+  ///< Only model a unidirectional implicit conversion and within it only one
   /// standard conversion sequence.
   OneWaySingleStandardOnly
 };
@@ -570,17 +570,30 @@ static inline bool isUselessSugar(const Type *T) {
   return isa(T);
 }
 
+namespace {
+
+struct NonCVRQualifiersResult {
+  /// True if the types are qualified in a way that even after equating or
+  /// removing local CVR qualification, even if the unqualified types
+  /// themselves would mix, the qualified ones don't, because there are some
+  /// other local qualifiers that are not equal.
+  bool HasMixabilityBreakingQualifiers;
+
+  /// The set of equal qualifiers between the two types.
+  Qualifiers CommonQualifiers;
+};
+
+} // namespace
+
 /// Returns if the two types are qualified in a way that ever after equating or
 /// removing local CVR qualification, even if the unqualified types would mix,
 /// the qualified ones don't, because there are some other local qualifiers
 /// that aren't equal.
-static bool hasNonCVRMixabilityBreakingQualifiers(const ASTContext &Ctx,
-  QualType LType,
-  QualType RType) {
-  LLVM_DEBUG(
-  llvm::dbgs() << ">>> hasNonCVRMixabilityBreakingQualifiers for LType:\n";
-  LType.dump(llvm::dbgs(), Ctx); llvm::dbgs() << "\nand RType:\n";
-  RType.dump(llvm::dbgs(), Ctx); llvm::dbgs() << '\n';);
+static NonCVRQualifiersResult
+getNonCVRQualifiers(const ASTContext &Ctx, QualType LType, QualType RType) {
+  LLVM_DEBUG(llvm::dbgs() << ">>> getNonCVRQualifiers for LType:\n";
+ LType.dump(llvm::dbgs(), Ctx); llvm::dbgs() << "\nand RType:\n";
+ RType.dump(llvm::dbgs(), Ctx); llvm::dbgs() << '\n';);
   Qualifiers LQual = LType.getLocalQualifiers(),
  RQual = RType.getLocalQualifiers();
 
@@ -588,20 +601,24 @@ static bool hasNonCVRMixabilityBreakingQualifiers(const 
ASTContext &Ctx,
   LQual.removeCVRQualifiers();
   RQual.removeCVRQualifiers();
 
-  Qualifiers CommonQuals = Qualifiers::removeCommonQualifiers(LQual, RQual);
-  (void)CommonQuals;
+  NonCVRQualifiersResult Ret;
+  Ret.CommonQualifiers = Qualifiers::removeCommonQualifiers(LQual, RQual);
 
   LLVM_DE

[PATCH] D106442: [clang-tidy] Improve "common type" diagnostic output in 'bugprone-easily-swappable-parameters'

2021-07-23 Thread Whisperity via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8b0cc4a65dd4: [clang-tidy] Improve "common type" 
diagnostic output in 'bugprone-easily… (authored by whisperity).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106442

Files:
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-qualifiermixing.cpp
@@ -114,13 +114,19 @@
 // CHECK-MESSAGES: :[[@LINE-3]]:29: note: the last parameter in the range is 'Source'
 // CHECK-MESSAGES: :[[@LINE-4]]:26: note: 'const T *' and 'T *' parameters accept and bind the same kind of values
 
+void attributedParam1TypedefRef(
+const __attribute__((address_space(256))) int &OneR,
+__attribute__((address_space(256))) MyInt1 &TwoR) {}
+// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: 2 adjacent parameters of 'attributedParam1TypedefRef' of similar type are
+// CHECK-MESSAGES: :[[@LINE-3]]:52: note: the first parameter in the range is 'OneR'
+// CHECK-MESSAGES: :[[@LINE-3]]:49: note: the last parameter in the range is 'TwoR'
+// CHECK-MESSAGES: :[[@LINE-5]]:5: note: after resolving type aliases, the common type of 'const __attribute__((address_space(256))) int &' and '__attribute__((address_space(256))) MyInt1 &' is '__attribute__((address_space(256))) int &'
+// CHECK-MESSAGES: :[[@LINE-5]]:5: note: 'const __attribute__((address_space(256))) int &' and '__attribute__((address_space(256))) MyInt1 &' parameters accept and bind the same kind of values
+
 void attributedParam2(__attribute__((address_space(256))) int *One,
   const __attribute__((address_space(256))) MyInt1 *Two) {}
 // CHECK-MESSAGES: :[[@LINE-2]]:23: warning: 2 adjacent parameters of 'attributedParam2' of similar type are
 // CHECK-MESSAGES: :[[@LINE-3]]:64: note: the first parameter in the range is 'One'
 // CHECK-MESSAGES: :[[@LINE-3]]:73: note: the last parameter in the range is 'Two'
-// CHECK-MESSAGES: :[[@LINE-5]]:23: note: after resolving type aliases, the common type of '__attribute__((address_space(256))) int *' and 'const __attribute__((address_space(256))) MyInt1 *' is 'int'
+// CHECK-MESSAGES: :[[@LINE-5]]:23: note: after resolving type aliases, '__attribute__((address_space(256))) int *' and 'const __attribute__((address_space(256))) MyInt1 *' share a common type
 // CHECK-MESSAGES: :[[@LINE-5]]:23: note: '__attribute__((address_space(256))) int *' and 'const __attribute__((address_space(256))) MyInt1 *' parameters accept and bind the same kind of values
-// FIXME: The last diagnostic line is a bit bad: the common type should be a
-// pointer type -- it is not clear right now, how it would be possible to
-// properly wire a logic in that fixes it.
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
@@ -242,8 +242,7 @@
 // CHECK-MESSAGES: :[[@LINE-4]]:37: note: 'int' and 'ICRTy' parameters accept and bind the same kind of values
 // CHECK-MESSAGES: :[[@LINE-5]]:30: note: after resolving type aliases, 'int' and 'MyIntCRTy' are the same
 // CHECK-MESSAGES: :[[@LINE-6]]:52: note: 'int' and 'MyIntCRTy' parameters accept and bind the same kind of values
-// CHECK-MESSAGES: :[[@LINE-7]]:37: note: after resolving type aliases, the common type of 'ICRTy' and 'MyIntCRTy' is 'int'
-// CHECK-MESSAGES: :[[@LINE-8]]:52: note: 'ICRTy' and 'MyIntCRTy' parameters accept and bind the same kind of values
+// CHECK-MESSAGES: :[[@LINE-7]]:37: note: after resolving type aliases, the common type of 'ICRTy' and 'MyIntCRTy' is 'const int &'
 
 short const typedef int unsigned Eldritch;
 typedef const unsigned short Holy;
@@ -358,10 +357,20 @@
 // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: 2 adjacent parameters of 'attributedParam1Typedef' of similar type are
 // CHECK-MESSAGES: :[[@LINE-3]]:77: note: the first parameter in the range is 'One'
 // CHECK-MESSAGES: :[[@LINE-3]]:80: note: the last parameter in the range is 'Two'
-// CHECK-MESSAGES: :[[@LINE-5]]:30: note: after resolving type aliases, the common type of 'const __attribute__((address_space(256))) int *' and 'const __attribute__((address_space(256))) MyInt1 *'

[clang] 91bc85b - [MS] Preserve base register %esi around movs[bwl]

2021-07-23 Thread via cfe-commits

Author: namazso
Date: 2021-07-23T16:28:32+08:00
New Revision: 91bc85b1ebaaa4e61058c24b556d6f0569a9b091

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

LOG: [MS] Preserve base register %esi around movs[bwl]

fix for behavior reported in https://bugs.llvm.org/show_bug.cgi?id=51100 
workaround for root cause https://bugs.llvm.org/show_bug.cgi?id=16830

similar to https://reviews.llvm.org/D101338

Reviewed By: craig.topper

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

Added: 


Modified: 
clang/lib/Headers/intrin.h
clang/test/CodeGen/ms-intrinsics.c

Removed: 




diff  --git a/clang/lib/Headers/intrin.h b/clang/lib/Headers/intrin.h
index 2b4e1b75e404b..ff8eb8fca2687 100644
--- a/clang/lib/Headers/intrin.h
+++ b/clang/lib/Headers/intrin.h
@@ -451,24 +451,47 @@ unsigned char _InterlockedCompareExchange128_rel(__int64 
volatile *_Destination,
 static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
   unsigned char const *__src,
   size_t __n) {
-  __asm__ __volatile__("rep movsb" : "+D"(__dst), "+S"(__src), "+c"(__n)
-   : : "memory");
+#if defined(__x86_64__)
+  __asm__ __volatile__("rep movsb"
+   : "+D"(__dst), "+S"(__src), "+c"(__n)
+   :
+   : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsb\nxchg %%esi, %1"
+   : "+D"(__dst), "+r"(__src), "+c"(__n)
+   :
+   : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst,
   unsigned long const *__src,
   size_t __n) {
+#if defined(__x86_64__)
   __asm__ __volatile__("rep movsl"
: "+D"(__dst), "+S"(__src), "+c"(__n)
:
: "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsl\nxchg %%esi, %1"
+   : "+D"(__dst), "+r"(__src), "+c"(__n)
+   :
+   : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
   unsigned short const *__src,
   size_t __n) {
+#if defined(__x86_64__)
   __asm__ __volatile__("rep movsw"
: "+D"(__dst), "+S"(__src), "+c"(__n)
:
: "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsw\nxchg %%esi, %1"
+   : "+D"(__dst), "+r"(__src), "+c"(__n)
+   :
+   : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
   unsigned long __x,

diff  --git a/clang/test/CodeGen/ms-intrinsics.c 
b/clang/test/CodeGen/ms-intrinsics.c
index 9f608158b1673..92bcc2cea2f63 100644
--- a/clang/test/CodeGen/ms-intrinsics.c
+++ b/clang/test/CodeGen/ms-intrinsics.c
@@ -36,7 +36,7 @@ void test__movsb(unsigned char *Dest, unsigned char *Src, 
size_t Count) {
   return __movsb(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsb
-// CHECK-I386:   call { i8*, i8*, i32 } asm sideeffect "rep movsb", 
"={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8* 
%Src, i32 %Count)
+// CHECK-I386:   tail call { i8*, i8*, i32 } asm sideeffect "xchg %esi, 
$1\0Arep movsb\0Axchg %esi, $1", 
"={di},=r,={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8* 
%Src, i32 %Count)
 // CHECK-I386:   ret void
 // CHECK-I386: }
 
@@ -62,7 +62,7 @@ void test__movsw(unsigned short *Dest, unsigned short *Src, 
size_t Count) {
   return __movsw(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsw
-// CHECK-I386:   call { i16*, i16*, i32 } asm sideeffect "rep movsw", 
"={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i16* %Dest, 
i16* %Src, i32 %Count)
+// CHECK-I386:   tail call { i16*, i16*, i32 } asm sideeffect "xchg %esi, 
$1\0Arep movsw\0Axchg %esi, $1", 
"={di},=r,={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i16* %Dest, i16* 
%Src, i32 %Count)
 // CHECK-I386:   ret void
 // CHECK-I386: }
 
@@ -88,7 +88,7 @@ void test__movsd(unsigned long *Dest, unsigned long *Src, 
size_t Count) {
   return __movsd(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsd
-// CHECK-I386:   call { i32*, i32*, i32 } asm sideeffect "rep movsl", 
"={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %Dest, 
i32* %Src, i32 %Count)
+// CHECK-I

[PATCH] D106210: [MS] Preserve base register %esi around movs[bwl]

2021-07-23 Thread Pengfei Wang 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 rG91bc85b1ebaa: [MS] Preserve base register %esi around 
movs[bwl] (authored by namazso, committed by pengfei).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106210

Files:
  clang/lib/Headers/intrin.h
  clang/test/CodeGen/ms-intrinsics.c


Index: clang/test/CodeGen/ms-intrinsics.c
===
--- clang/test/CodeGen/ms-intrinsics.c
+++ clang/test/CodeGen/ms-intrinsics.c
@@ -36,7 +36,7 @@
   return __movsb(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsb
-// CHECK-I386:   call { i8*, i8*, i32 } asm sideeffect "rep movsb", 
"={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8* 
%Src, i32 %Count)
+// CHECK-I386:   tail call { i8*, i8*, i32 } asm sideeffect "xchg %esi, 
$1\0Arep movsb\0Axchg %esi, $1", 
"={di},=r,={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8* 
%Src, i32 %Count)
 // CHECK-I386:   ret void
 // CHECK-I386: }
 
@@ -62,7 +62,7 @@
   return __movsw(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsw
-// CHECK-I386:   call { i16*, i16*, i32 } asm sideeffect "rep movsw", 
"={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i16* %Dest, 
i16* %Src, i32 %Count)
+// CHECK-I386:   tail call { i16*, i16*, i32 } asm sideeffect "xchg %esi, 
$1\0Arep movsw\0Axchg %esi, $1", 
"={di},=r,={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i16* %Dest, i16* 
%Src, i32 %Count)
 // CHECK-I386:   ret void
 // CHECK-I386: }
 
@@ -88,7 +88,7 @@
   return __movsd(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsd
-// CHECK-I386:   call { i32*, i32*, i32 } asm sideeffect "rep movsl", 
"={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %Dest, 
i32* %Src, i32 %Count)
+// CHECK-I386:   tail call { i32*, i32*, i32 } asm sideeffect "xchg %esi, 
$1\0Arep movsl\0Axchg %esi, $1", 
"={di},=r,={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i32* %Dest, i32* 
%Src, i32 %Count)
 // CHECK-I386:   ret void
 // CHECK-I386: }
 
Index: clang/lib/Headers/intrin.h
===
--- clang/lib/Headers/intrin.h
+++ clang/lib/Headers/intrin.h
@@ -451,24 +451,47 @@
 static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
   unsigned char const *__src,
   size_t __n) {
-  __asm__ __volatile__("rep movsb" : "+D"(__dst), "+S"(__src), "+c"(__n)
-   : : "memory");
+#if defined(__x86_64__)
+  __asm__ __volatile__("rep movsb"
+   : "+D"(__dst), "+S"(__src), "+c"(__n)
+   :
+   : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsb\nxchg %%esi, %1"
+   : "+D"(__dst), "+r"(__src), "+c"(__n)
+   :
+   : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst,
   unsigned long const *__src,
   size_t __n) {
+#if defined(__x86_64__)
   __asm__ __volatile__("rep movsl"
: "+D"(__dst), "+S"(__src), "+c"(__n)
:
: "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsl\nxchg %%esi, %1"
+   : "+D"(__dst), "+r"(__src), "+c"(__n)
+   :
+   : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
   unsigned short const *__src,
   size_t __n) {
+#if defined(__x86_64__)
   __asm__ __volatile__("rep movsw"
: "+D"(__dst), "+S"(__src), "+c"(__n)
:
: "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsw\nxchg %%esi, %1"
+   : "+D"(__dst), "+r"(__src), "+c"(__n)
+   :
+   : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
   unsigned long __x,


Index: clang/test/CodeGen/ms-intrinsics.c
===
--- clang/test/CodeGen/ms-intrinsics.c
+++ clang/test/CodeGen/ms-intrinsics.c
@@ -36,7 +36,7 @@
   return __movsb(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsb
-// CHECK-I386:   call { i8*, i8*, i32 } asm sideeffect "rep movsb", "={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8

[PATCH] D106210: [MS] Preserve base register %esi around movs[bwl]

2021-07-23 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added a comment.

Happened to see it. I thought Craig might miss it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106210

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


[PATCH] D106583: [clang] SIGSEGV at DeduceTemplateArgumentsByTypeMatch

2021-07-23 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added a comment.

@erichkeane, could you look at the added LIT test. Is it suitable or require 
additional modifications?

BTW: There are several failed tests but they seems to be a known issue (see bug 
51117 ).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106583

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


[PATCH] D106639: [clangd] Adjust compile flags to contain only the requested file as input

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman, mgrang.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Depends on D106527 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106639

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp

Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -59,7 +59,7 @@
   Argv.push_back(FullFilename);
 
   auto Mangler = CommandMangler::forTests();
-  Mangler.adjust(Inputs.CompileCommand.CommandLine);
+  Mangler.adjust(Inputs.CompileCommand.CommandLine, FullFilename);
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.Directory = testRoot();
   Inputs.Contents = Code;
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -43,7 +43,7 @@
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
   std::vector Cmd = {"clang++", "--", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
"-isysroot", testPath("fake/sysroot"), "--",
@@ -54,7 +54,7 @@
   auto Mangler = CommandMangler::forTests();
   Mangler.ResourceDir = testPath("fake/resources");
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, Contains("-resource-dir=" + testPath("fake/resources")));
 }
 
@@ -63,7 +63,7 @@
   Mangler.Sysroot = testPath("fake/sysroot");
 
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(llvm::join(Cmd, " "),
   HasSubstr("-isysroot " + testPath("fake/sysroot")));
 }
@@ -73,19 +73,19 @@
   Mangler.ClangPath = testPath("fake/clang");
 
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("fake/clang++"), Cmd.front());
 
   Cmd = {"unknown-binary", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("fake/unknown-binary"), Cmd.front());
 
   Cmd = {testPath("path/clang++"), "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("path/clang++"), Cmd.front());
 
   Cmd = {"foo/unknown-binary", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ("foo/unknown-binary", Cmd.front());
 }
 
@@ -128,7 +128,7 @@
   auto Mangler = CommandMangler::forTests();
   Mangler.ClangPath = testPath("fake/clang");
   std::vector Cmd = {(TempDir + "/bin/foo").str(), "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   // Directory based on resolved symlink, basename preserved.
   EXPECT_EQ((TempDir + "/lib/foo").str(), Cmd.front());
 
@@ -145,13 +145,13 @@
   Mangler.ClangPath = testPath("fake/clang");
   // Driver found on PATH.
   Cmd = {"foo", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   // Found the symlink and resolved the path as above.
   EXPECT_EQ((TempDir + "/lib/foo").str(), Cmd.front());
 
   // Symlink not resolved with -no-canonical-prefixes.
   Cmd = {"foo", "-no-canonical-prefixes", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ((TempDir + "/bin/foo").str(), Cmd.front());
 }
 #endif
@@ -170,7 +170,7 @@
   Argv = tooling::getInsertArgumentAdjuster("--hello")(Argv, "");
 });
 WithContextValue WithConfig(Config::Key, std::move(Cfg));
-Mangler.adjust(Cmd);
+Mangler.adjust(Cmd, "foo.cc");
   }
   // Edits are applied in given order and before other mangling and they always
   // go before filename.
Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -48,7 +48,7 @@
 #
 # ERR: ASTWorker building file {{.*}}foo.c version 0 with command
 # ERR: [{{.*}}clangd-test2]
-# ERR: clang -c -Wall -Werror {{.*}} -- foo.c
+# ERR: clang -c -Wall -Werror {

[PATCH] D106434: [OpenCL] Add cl_khr_integer_dot_product

2021-07-23 Thread Sven van Haastregt 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 rG989bedec7a6a: [OpenCL] Add cl_khr_integer_dot_product 
(authored by svenvh).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106434

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Headers/opencl-c.h
  clang/lib/Sema/OpenCLBuiltins.td
  clang/test/Headers/opencl-c-header.cl

Index: clang/test/Headers/opencl-c-header.cl
===
--- clang/test/Headers/opencl-c-header.cl
+++ clang/test/Headers/opencl-c-header.cl
@@ -126,6 +126,15 @@
 #if cl_khr_extended_bit_ops != 1
 #error "Incorrectly defined cl_khr_extended_bit_ops"
 #endif
+#if cl_khr_integer_dot_product != 1
+#error "Incorrectly defined cl_khr_integer_dot_product"
+#endif
+#if __opencl_c_integer_dot_product_input_4x8bit != 1
+#error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit"
+#endif
+#if __opencl_c_integer_dot_product_input_4x8bit_packed != 1
+#error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit_packed"
+#endif
 
 #else
 
@@ -153,6 +162,15 @@
 #ifdef cl_khr_extended_bit_ops
 #error "Incorrect cl_khr_extended_bit_ops define"
 #endif
+#ifdef cl_khr_integer_dot_product
+#error "Incorrect cl_khr_integer_dot_product define"
+#endif
+#ifdef __opencl_c_integer_dot_product_input_4x8bit
+#error "Incorrect __opencl_c_integer_dot_product_input_4x8bit define"
+#endif
+#ifdef __opencl_c_integer_dot_product_input_4x8bit_packed
+#error "Incorrect __opencl_c_integer_dot_product_input_4x8bit_packed define"
+#endif
 
 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 
Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -1749,6 +1749,31 @@
   def : Builtin<"bit_reverse", [AIGenTypeN, AIGenTypeN], Attr.Const>;
 }
 
+// Section 42.3 - cl_khr_integer_dot_product
+let Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit"> in {
+  def : Builtin<"dot", [UInt, VectorType, VectorType], Attr.Const>;
+  def : Builtin<"dot", [Int, VectorType, VectorType], Attr.Const>;
+  def : Builtin<"dot", [Int, VectorType, VectorType], Attr.Const>;
+  def : Builtin<"dot", [Int, VectorType, VectorType], Attr.Const>;
+
+  def : Builtin<"dot_acc_sat", [UInt, VectorType, VectorType, UInt], Attr.Const>;
+  def : Builtin<"dot_acc_sat", [Int, VectorType, VectorType, Int], Attr.Const>;
+  def : Builtin<"dot_acc_sat", [Int, VectorType, VectorType, Int], Attr.Const>;
+  def : Builtin<"dot_acc_sat", [Int, VectorType, VectorType, Int], Attr.Const>;
+}
+
+let Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit_packed"> in {
+  def : Builtin<"dot_4x8packed_uu_uint", [UInt, UInt, UInt], Attr.Const>;
+  def : Builtin<"dot_4x8packed_ss_int", [Int, UInt, UInt], Attr.Const>;
+  def : Builtin<"dot_4x8packed_us_int", [Int, UInt, UInt], Attr.Const>;
+  def : Builtin<"dot_4x8packed_su_int", [Int, UInt, UInt], Attr.Const>;
+
+  def : Builtin<"dot_acc_sat_4x8packed_uu_uint", [UInt, UInt, UInt, UInt], Attr.Const>;
+  def : Builtin<"dot_acc_sat_4x8packed_ss_int", [Int, UInt, UInt, Int], Attr.Const>;
+  def : Builtin<"dot_acc_sat_4x8packed_us_int", [Int, UInt, UInt, Int], Attr.Const>;
+  def : Builtin<"dot_acc_sat_4x8packed_su_int", [Int, UInt, UInt, Int], Attr.Const>;
+}
+
 //
 // Arm extensions.
 let Extension = ArmIntegerDotProductInt8 in {
Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -16251,6 +16251,30 @@
 ulong16 __ovld __cnfn bit_reverse(ulong16);
 #endif // cl_khr_extended_bit_ops
 
+#if defined(__opencl_c_integer_dot_product_input_4x8bit)
+uint __ovld __cnfn dot(uchar4, uchar4);
+int __ovld __cnfn dot(char4, char4);
+int __ovld __cnfn dot(uchar4, char4);
+int __ovld __cnfn dot(char4, uchar4);
+
+uint __ovld __cnfn dot_acc_sat(uchar4, uchar4, uint);
+int __ovld __cnfn dot_acc_sat(char4, char4, int);
+int __ovld __cnfn dot_acc_sat(uchar4, char4, int);
+int __ovld __cnfn dot_acc_sat(char4, uchar4, int);
+#endif // __opencl_c_integer_dot_product_input_4x8bit
+
+#if defined(__opencl_c_integer_dot_product_input_4x8bit_packed)
+uint __ovld __cnfn dot_4x8packed_uu_uint(uint, uint);
+int __ovld __cnfn dot_4x8packed_ss_int(uint, uint);
+int __ovld __cnfn dot_4x8packed_us_int(uint, uint);
+int __ovld __cnfn dot_4x8packed_su_int(uint, uint);
+
+uint __ovld __cnfn dot_acc_sat_4x8packed_uu_uint(uint, uint, uint);
+int __ovld __cnfn dot_acc_sat_4x8packed_ss_int(uint, uint, int);
+int __ovld __cnfn dot_acc_sat_4x8packed_us_int(uint, uint, int);
+int __ovld __cnfn dot_acc_sat_4x8packed_su_int(uint, uint, i

[clang] 989bede - [OpenCL] Add cl_khr_integer_dot_product

2021-07-23 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-07-23T10:10:16+01:00
New Revision: 989bedec7a6ae95a0db865f23677047f78dc9257

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

LOG: [OpenCL] Add cl_khr_integer_dot_product

Add the builtins defined by Section 42 "Integer dot product" in
the OpenCL Extension Specification.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Headers/opencl-c.h
clang/lib/Sema/OpenCLBuiltins.td
clang/test/Headers/opencl-c-header.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index ebc4b7a47925..1dc52ec75e03 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -22,6 +22,10 @@
 #define cl_khr_subgroup_shuffle_relative 1
 #define cl_khr_subgroup_clustered_reduce 1
 #define cl_khr_extended_bit_ops 1
+#define cl_khr_integer_dot_product 1
+#define __opencl_c_integer_dot_product_input_4x8bit 1
+#define __opencl_c_integer_dot_product_input_4x8bit_packed 1
+
 #endif // defined(__SPIR__)
 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 5b3cd05d4426..4be57058b33f 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -16251,6 +16251,30 @@ long16 __ovld __cnfn bit_reverse(long16);
 ulong16 __ovld __cnfn bit_reverse(ulong16);
 #endif // cl_khr_extended_bit_ops
 
+#if defined(__opencl_c_integer_dot_product_input_4x8bit)
+uint __ovld __cnfn dot(uchar4, uchar4);
+int __ovld __cnfn dot(char4, char4);
+int __ovld __cnfn dot(uchar4, char4);
+int __ovld __cnfn dot(char4, uchar4);
+
+uint __ovld __cnfn dot_acc_sat(uchar4, uchar4, uint);
+int __ovld __cnfn dot_acc_sat(char4, char4, int);
+int __ovld __cnfn dot_acc_sat(uchar4, char4, int);
+int __ovld __cnfn dot_acc_sat(char4, uchar4, int);
+#endif // __opencl_c_integer_dot_product_input_4x8bit
+
+#if defined(__opencl_c_integer_dot_product_input_4x8bit_packed)
+uint __ovld __cnfn dot_4x8packed_uu_uint(uint, uint);
+int __ovld __cnfn dot_4x8packed_ss_int(uint, uint);
+int __ovld __cnfn dot_4x8packed_us_int(uint, uint);
+int __ovld __cnfn dot_4x8packed_su_int(uint, uint);
+
+uint __ovld __cnfn dot_acc_sat_4x8packed_uu_uint(uint, uint, uint);
+int __ovld __cnfn dot_acc_sat_4x8packed_ss_int(uint, uint, int);
+int __ovld __cnfn dot_acc_sat_4x8packed_us_int(uint, uint, int);
+int __ovld __cnfn dot_acc_sat_4x8packed_su_int(uint, uint, int);
+#endif // __opencl_c_integer_dot_product_input_4x8bit_packed
+
 #if defined(cl_intel_subgroups)
 // Intel-Specific Sub Group Functions
 float   __ovld __conv intel_sub_group_shuffle( float  x, uint c );

diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 63def2bce8c2..cd704fe395a9 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1749,6 +1749,31 @@ let Extension = FuncExtKhrExtendedBitOps in {
   def : Builtin<"bit_reverse", [AIGenTypeN, AIGenTypeN], Attr.Const>;
 }
 
+// Section 42.3 - cl_khr_integer_dot_product
+let Extension = 
FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit"> in {
+  def : Builtin<"dot", [UInt, VectorType, VectorType], 
Attr.Const>;
+  def : Builtin<"dot", [Int, VectorType, VectorType], 
Attr.Const>;
+  def : Builtin<"dot", [Int, VectorType, VectorType], 
Attr.Const>;
+  def : Builtin<"dot", [Int, VectorType, VectorType], 
Attr.Const>;
+
+  def : Builtin<"dot_acc_sat", [UInt, VectorType, VectorType, UInt], Attr.Const>;
+  def : Builtin<"dot_acc_sat", [Int, VectorType, VectorType, 
Int], Attr.Const>;
+  def : Builtin<"dot_acc_sat", [Int, VectorType, VectorType, Int], Attr.Const>;
+  def : Builtin<"dot_acc_sat", [Int, VectorType, VectorType, Int], Attr.Const>;
+}
+
+let Extension = 
FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit_packed"> in {
+  def : Builtin<"dot_4x8packed_uu_uint", [UInt, UInt, UInt], Attr.Const>;
+  def : Builtin<"dot_4x8packed_ss_int", [Int, UInt, UInt], Attr.Const>;
+  def : Builtin<"dot_4x8packed_us_int", [Int, UInt, UInt], Attr.Const>;
+  def : Builtin<"dot_4x8packed_su_int", [Int, UInt, UInt], Attr.Const>;
+
+  def : Builtin<"dot_acc_sat_4x8packed_uu_uint", [UInt, UInt, UInt, UInt], 
Attr.Const>;
+  def : Builtin<"dot_acc_sat_4x8packed_ss_int", [Int, UInt, UInt, Int], 
Attr.Const>;
+  def : Builtin<"dot_acc_sat_4x8packed_us_int", [Int, UInt, UInt, Int], 
Attr.Const>;
+  def : Builtin<"dot_acc_sat_4x8packed_su_int", [Int, UInt, UInt, Int], 
Attr.Const>;
+}
+
 //
 // Arm extensions.
 let Extension = ArmIntegerDotProductInt8 in {

diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/c

[PATCH] D106562: [clangd] Get rid of arg adjusters in CommandMangler

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 361132.
kadircet added a comment.

- Also get rid of the insertion adjuster


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106562

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/CompilerTests.cpp

Index: clang-tools-extra/clangd/unittests/CompilerTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompilerTests.cpp
+++ clang-tools-extra/clangd/unittests/CompilerTests.cpp
@@ -8,6 +8,8 @@
 
 #include "Compiler.h"
 #include "TestTU.h"
+#include "clang/Frontend/DependencyOutputOptions.h"
+#include "clang/Frontend/FrontendOptions.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -56,6 +58,50 @@
   TU.build(); // no-crash
 }
 
+TEST(BuildCompilerInvocation, DropsShowIncludes) {
+  MockFS FS;
+  IgnoreDiagnostics Diags;
+  TestTU TU;
+
+  TU.ExtraArgs = {"-Xclang", "--show-includes"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+
+  TU.ExtraArgs = {"/showIncludes", "--driver-mode=cl"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+
+  TU.ExtraArgs = {"/showIncludes:user", "--driver-mode=cl"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+}
+
+TEST(BuildCompilerInvocation, DropsPlugins) {
+  MockFS FS;
+  IgnoreDiagnostics Diags;
+  TestTU TU;
+
+  TU.ExtraArgs = {"-Xclang", "-load",
+  "-Xclang", "plugins.so",
+  "-Xclang", "-plugin",
+  "-Xclang", "my_plugin",
+  "-Xclang", "-plugin-arg-my_plugin",
+  "-Xclang", "foo=bar",
+  "-Xclang", "-add-plugin",
+  "-Xclang", "my_plugin2"};
+  auto &Opts = buildCompilerInvocation(TU.inputs(FS), Diags)->getFrontendOpts();
+  EXPECT_THAT(Opts.Plugins, IsEmpty());
+  EXPECT_THAT(Opts.PluginArgs, IsEmpty());
+  EXPECT_THAT(Opts.AddPluginActions, IsEmpty());
+  EXPECT_EQ(Opts.ProgramAction, frontend::ActionKind::ParseSyntaxOnly);
+  EXPECT_TRUE(Opts.ActionName.empty());
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -41,11 +41,9 @@
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "-Xclang", "-load",
-  "-Xclang", "plugin",  "-MF",
-  "dep", "--",  "foo.cc"};
+  std::vector Cmd = {"clang++", "--", "foo.cc"};
   Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"), "-fsyntax-only",
+  EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
"-isysroot", testPath("fake/sysroot"), "--",
"foo.cc"));
@@ -69,38 +67,6 @@
   HasSubstr("-isysroot " + testPath("fake/sysroot")));
 }
 
-TEST(CommandMangler, StripPlugins) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang++", "-Xclang", "-load",
-  "-Xclang", "plugin",  "foo.cc"};
-  Mangler.adjust(Cmd);
-  for (const char* Stripped : {"-Xclang", "-load", "plugin"})
-EXPECT_THAT(Cmd, Not(Contains(Stripped)));
-}
-
-TEST(CommandMangler, StripOutput) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang++", "-MF", "dependency", "-c",
-  "foo.cc"};
-  Mangler.adjust(Cmd);
-  for (const char* Stripped : {"-MF", "dependency"})
-EXPECT_THAT(Cmd, Not(Contains(Stripped)));
-}
-
-TEST(CommandMangler, StripShowIncludes) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang-cl", "/showIncludes", "foo.cc"};
-  Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, Not(Contains("/showIncludes")));
-}
-
-TEST(CommandMangler, StripShowIncludesUser) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang-cl", "/showIncludes:user", "foo.cc"};
-  Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, Not(Contains("/showIncludes:user")));
-}
-
 TE

[PATCH] D106527: [clangd] Canonicalize compile flags before applying edits

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 361133.
kadircet marked 3 inline comments as done.
kadircet added a comment.

- Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106527

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -11,6 +11,7 @@
 #include "TestFS.h"
 #include "support/Context.h"
 
+#include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/FileSystem.h"
@@ -165,13 +166,15 @@
 for (char &C : Arg)
   C = llvm::toUpper(C);
 });
-Cfg.CompileFlags.Edits.push_back(
-[](std::vector &Argv) { Argv.push_back("--hello"); });
+Cfg.CompileFlags.Edits.push_back([](std::vector &Argv) {
+  Argv = tooling::getInsertArgumentAdjuster("--hello")(Argv, "");
+});
 WithContextValue WithConfig(Config::Key, std::move(Cfg));
 Mangler.adjust(Cmd);
   }
-  // Edits are applied in given order and before other mangling.
-  EXPECT_THAT(Cmd, ElementsAre(_, "FOO.CC", "--hello"));
+  // Edits are applied in given order and before other mangling and they always
+  // go before filename.
+  EXPECT_THAT(Cmd, ElementsAre(_, "--hello", "--", "FOO.CC"));
 }
 
 static std::string strip(llvm::StringRef Arg, llvm::StringRef Argv) {
@@ -335,9 +338,8 @@
 }
 
 TEST(PrintArgvTest, All) {
-  std::vector Args = {
-  "one", "two", "thr ee", "f\"o\"ur", "fi\\ve", "$"
-  };
+  std::vector Args = {"one",  "two","thr ee",
+   "f\"o\"ur", "fi\\ve", "$"};
   const char *Expected = R"(one two "thr ee" "f\"o\"ur" "fi\\ve" $)";
   EXPECT_EQ(Expected, printArgv(Args));
 }
Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -133,8 +133,9 @@
   Opts.ContextProvider = [](PathRef P) {
 Config C;
 if (P.endswith("foo.cpp"))
-  C.CompileFlags.Edits.push_back(
-  [](std::vector &Argv) { Argv.push_back("-Done=two"); });
+  C.CompileFlags.Edits.push_back([](std::vector &Argv) {
+Argv = tooling::getInsertArgumentAdjuster("-Done=two")(Argv, "");
+  });
 if (P.endswith("baz.cpp"))
   C.Index.Background = Config::BackgroundPolicy::Skip;
 return Context::current().derive(Config::Key, std::move(C));
Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -48,7 +48,7 @@
 #
 # ERR: ASTWorker building file {{.*}}foo.c version 0 with command
 # ERR: [{{.*}}clangd-test2]
-# ERR: clang -c foo.c -Wall -Werror
+# ERR: clang -c -Wall -Werror {{.*}} -- foo.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -9,11 +9,14 @@
 #include "CompileCommands.h"
 #include "Config.h"
 #include "support/Logger.h"
+#include "support/Trace.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Debug.h"
@@ -187,11 +190,33 @@
   return Result;
 }
 
-CommandMangler CommandMangler::forTests() {
-  return CommandMangler();
-}
+CommandMangler CommandMangler::forTests() { return CommandMangler(); }
 
 void CommandMangler::adjust(std::vector &Cmd) const {
+  trace::Span S("AdjustCompileFlags");
+  auto &OptTable = clang::driver::getDriverOptTable();
+  // OriginalArgs needs to outlive ArgList.
+  llvm::SmallVector OriginalArgs;
+  OriginalArgs.reserve(Cmd.size());
+  for (const std::string &S : Cmd)
+OriginalArgs.push_back(S.c_str());
+  // ParseArgs propagates missig arg/opt counts on error, but preserves
+  // everything it could parse in ArgList. So we just ignore those counts.
+  unsigned IgnoredCount;
+  auto ArgList = OptTable.ParseArgs(Original

[PATCH] D106527: [clangd] Canonicalize compile flags before applying edits

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 6 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:210
+  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
+// In theory there might be more than one input, but clangd can't deal with
+// them anyway.

sammccall wrote:
> More than one input is a really annoying error to diagnose, would we want to 
> detect and log it here? Downside is this code runs *really* often.
I agree that it is gonna be somewhat noisy. But I think it is gonna effect 2 
different workflows:
- User hits a file with compile flags containing multiple inputs, notices 
clangd doesn't work, tries to resolve the problem and looks at the logs. since 
they are not working on the file it is not gonna be noisy in this case and 
really helpful.
- They are just going to ignore clangd being broken and move on, In this case 
we'll really turn the logs into garbage but I don't think user will care.

So maybe we can make it vlog instead, and ensure it only shows up to users that 
care?



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:210
+  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
+// In theory there might be more than one input, but clangd can't deal with
+// them anyway.

sammccall wrote:
> kadircet wrote:
> > sammccall wrote:
> > > More than one input is a really annoying error to diagnose, would we want 
> > > to detect and log it here? Downside is this code runs *really* often.
> > I agree that it is gonna be somewhat noisy. But I think it is gonna effect 
> > 2 different workflows:
> > - User hits a file with compile flags containing multiple inputs, notices 
> > clangd doesn't work, tries to resolve the problem and looks at the logs. 
> > since they are not working on the file it is not gonna be noisy in this 
> > case and really helpful.
> > - They are just going to ignore clangd being broken and move on, In this 
> > case we'll really turn the logs into garbage but I don't think user will 
> > care.
> > 
> > So maybe we can make it vlog instead, and ensure it only shows up to users 
> > that care?
> Another option would be to delete all the OPT_INPUTs and append the actual 
> filename (CompileCommand::Filename)
> 
> This seems like it would define this class of errors out of existence, maybe?
> 
> Layering doesn't make it easy to do that right here, though :-\
yes this sounds great indeed, send out as a separate follow-up in D106639.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:221
 
-  // Check whether the flag exists, either as -flag or -flag=*
-  auto Has = [&](llvm::StringRef Flag) {
-for (llvm::StringRef Arg : Cmd) {
-  if (Arg.consume_front(Flag) && (Arg.empty() || Arg[0] == '='))
-return true;
-}
-return false;
-  };
-
   // clangd should not write files to disk, including dependency files
   // requested on the command line.

sammccall wrote:
> These are copies of the rendered arg list, i think many of them we could 
> replace with calls to ArgList.erase before rendering the arg list.
> (e.g. syntax-only... if we erased -save-temps and turned off color 
> diagnostics in Compiler.cpp, I think that covers everything)
> 
> ... but wait, is "rendering the arglist" even possible?
> 
> (I want to expand the scope of this patch unneccesarily, but it might be a 
> way to offset the extra costs...)
send out D106562 to get rid of these.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:232
+  if (ResourceDir &&
+  !ArgList.hasArgNoClaim(driver::options::OPT_resource_dir,
+ driver::options::OPT_resource_dir_EQ))

sammccall wrote:
> Technically the hasArgNoClaim is stale, we've applied edits to the command 
> since then. Probably fine though, not much use for setting resource-dir. 
> (maybe we should even drop this check)
> 
> hasArgNoClaim is probably cheaper than the old scan we were doing, but its 
> impl is crazy: not a simple scan, but also not a simple lookup.
keeping the `Has` behaviour just to minimize the impact, happy to drop the 
check as a follow-up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106527

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


[PATCH] D91950: [clang-format] Add BreakBeforeInlineASMColon configuration

2021-07-23 Thread Anastasiia Lukianenko via Phabricator via cfe-commits
anastasiia_lukianenko updated this revision to Diff 361134.

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

https://reviews.llvm.org/D91950

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -3795,12 +3795,16 @@
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
   verifyFormat("asm(\"nop\" ::: \"memory\");");
+
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeInlineASMColon = true;
   verifyFormat(
   "asm(\"movq\\t%%rbx, %%rsi\\n\\t\"\n"
   "\"cpuid\\n\\t\"\n"
   "\"xchgq\\t%%rbx, %%rsi\\n\\t\"\n"
   ": \"=a\"(*rEAX), \"=S\"(*rEBX), \"=c\"(*rECX), \"=d\"(*rEDX)\n"
-  ": \"a\"(value));");
+  ": \"a\"(value));",
+  Style);
   EXPECT_EQ(
   "void NS_InvokeByIndex(void *that, unsigned int methodIndex) {\n"
   "  __asm {\n"
@@ -6240,6 +6244,43 @@
 format(Input, Style));
 }
 
+TEST_F(FormatTest, BreakBeforeInlineASMColon) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakStringLiterals = false;
+  Style.BreakBeforeInlineASMColon = false;
+  /* Test the behaviour with long lines */
+  Style.ColumnLimit = 40;
+  verifyFormat("asm volatile(\"lng\",\n"
+   " : : val);",
+   Style);
+  verifyFormat("asm volatile(\"lng\",\n"
+   " : val1 : val2);",
+   Style);
+  Style.ColumnLimit = 80;
+  verifyFormat("asm volatile(\"string\", : : val);", Style);
+  verifyFormat("asm volatile(\"string\", : val1 : val2);", Style);
+
+  Style.BreakBeforeInlineASMColon = true;
+  verifyFormat("asm volatile(\"string\",\n"
+   " :\n"
+   " : val);",
+   Style);
+  verifyFormat("asm volatile(\"string\",\n"
+   " : val1\n"
+   " : val2);",
+   Style);
+  /* Test the behaviour with long lines */
+  Style.ColumnLimit = 40;
+  verifyFormat("asm volatile(\"lng\",\n"
+   " :\n"
+   " : val);",
+   Style);
+  verifyFormat("asm volatile(\"lng\",\n"
+   " : val1\n"
+   " : val2);",
+   Style);
+}
+
 TEST_F(FormatTest, BreakConstructorInitializersAfterColon) {
   FormatStyle Style = getLLVMStyle();
   Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
@@ -21194,15 +21235,18 @@
   // A list of several ASM symbolic names.
   verifyFormat(R"(asm("mov %[e], %[d]" : [d] "=rm"(d), [e] "rm"(*e));)");
 
+  // ASM symbolic names in inline ASM with no outputs.
+  verifyFormat(R"(asm("mov %[e], %[d]" : : [d] "=rm"(d), [e] "rm"(*e));)");
+
+  format::FormatStyle Style = format::getLLVMStyle();
+  Style.BreakBeforeInlineASMColon = true;
   // ASM symbolic names in inline ASM with inputs and outputs.
   verifyFormat(R"(//
 asm("cmoveq %1, %2, %[result]"
 : [result] "=r"(result)
 : "r"(test), "r"(new), "[result]"(old));
-)");
-
-  // ASM symbolic names in inline ASM with no outputs.
-  verifyFormat(R"(asm("mov %[e], %[d]" : : [d] "=rm"(d), [e] "rm"(*e));)");
+)",
+   Style);
 }
 
 TEST_F(FormatTest, GuessedLanguageWithInlineAsmClobbers) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3602,6 +3602,9 @@
   const FormatToken &Left = *Right.Previous;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
+  if (Line.startsWith(tok::kw_asm) && Right.is(TT_InlineASMColon) &&
+  Style.BreakBeforeInlineASMColon)
+return true;
 
   if (Style.isCSharp()) {
 if (Right.is(TT_CSharpNamedArgumentColon) ||
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -612,6 +612,9 @@
 Style.BreakInheritanceList == FormatStyle::BILS_BeforeColon)
   Style.BreakInheritanceList = FormatStyle::BILS_BeforeComma;
 
+IO.mapOptional("BreakBeforeInlineASMColon",
+   Style.BreakBeforeInlineASMColon);
+
 IO.mapOptional("BreakBeforeTernaryOperators",
Style.BreakBeforeTernaryOperators);
 
@@ -1006,6 +1009,7 @@
   LLVMStyle.BinPackParameters = true;
   LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
   LLVMStyle.BreakBeforeConceptDeclarations = true;
+  LLVMStyle.BreakBe

[PATCH] D106639: [clangd] Adjust compile flags to contain only the requested file as input

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 361135.
kadircet added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106639

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp

Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -59,7 +59,7 @@
   Argv.push_back(FullFilename);
 
   auto Mangler = CommandMangler::forTests();
-  Mangler.adjust(Inputs.CompileCommand.CommandLine);
+  Mangler.adjust(Inputs.CompileCommand.CommandLine, FullFilename);
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.Directory = testRoot();
   Inputs.Contents = Code;
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -43,7 +43,7 @@
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
   std::vector Cmd = {"clang++", "--", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
"-isysroot", testPath("fake/sysroot"), "--",
@@ -54,7 +54,7 @@
   auto Mangler = CommandMangler::forTests();
   Mangler.ResourceDir = testPath("fake/resources");
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, Contains("-resource-dir=" + testPath("fake/resources")));
 }
 
@@ -63,7 +63,7 @@
   Mangler.Sysroot = testPath("fake/sysroot");
 
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(llvm::join(Cmd, " "),
   HasSubstr("-isysroot " + testPath("fake/sysroot")));
 }
@@ -73,19 +73,19 @@
   Mangler.ClangPath = testPath("fake/clang");
 
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("fake/clang++"), Cmd.front());
 
   Cmd = {"unknown-binary", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("fake/unknown-binary"), Cmd.front());
 
   Cmd = {testPath("path/clang++"), "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("path/clang++"), Cmd.front());
 
   Cmd = {"foo/unknown-binary", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ("foo/unknown-binary", Cmd.front());
 }
 
@@ -128,7 +128,7 @@
   auto Mangler = CommandMangler::forTests();
   Mangler.ClangPath = testPath("fake/clang");
   std::vector Cmd = {(TempDir + "/bin/foo").str(), "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   // Directory based on resolved symlink, basename preserved.
   EXPECT_EQ((TempDir + "/lib/foo").str(), Cmd.front());
 
@@ -145,13 +145,13 @@
   Mangler.ClangPath = testPath("fake/clang");
   // Driver found on PATH.
   Cmd = {"foo", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   // Found the symlink and resolved the path as above.
   EXPECT_EQ((TempDir + "/lib/foo").str(), Cmd.front());
 
   // Symlink not resolved with -no-canonical-prefixes.
   Cmd = {"foo", "-no-canonical-prefixes", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ((TempDir + "/bin/foo").str(), Cmd.front());
 }
 #endif
@@ -170,7 +170,7 @@
   Argv = tooling::getInsertArgumentAdjuster("--hello")(Argv, "");
 });
 WithContextValue WithConfig(Config::Key, std::move(Cfg));
-Mangler.adjust(Cmd);
+Mangler.adjust(Cmd, "foo.cc");
   }
   // Edits are applied in given order and before other mangling and they always
   // go before filename.
Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -48,7 +48,7 @@
 #
 # ERR: ASTWorker building file {{.*}}foo.c version 0 with command
 # ERR: [{{.*}}clangd-test2]
-# ERR: clang -c -Wall -Werror {{.*}} -- foo.c
+# ERR: clang -c -Wall -Werror {{.*}} -- {{.*}}foo.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
==

[PATCH] D106640: [clangd] Make dex iterator peek() and reachedEnd() nonvirtual

2021-07-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kbobyrev.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This is not polished but worth checking if it's a speedup
Hopefully correct: passes all tests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106640

Files:
  clang-tools-extra/clangd/index/dex/Iterator.cpp
  clang-tools-extra/clangd/index/dex/Iterator.h
  clang-tools-extra/clangd/index/dex/PostingList.cpp
  clang-tools-extra/clangd/unittests/DexTests.cpp

Index: clang-tools-extra/clangd/unittests/DexTests.cpp
===
--- clang-tools-extra/clangd/unittests/DexTests.cpp
+++ clang-tools-extra/clangd/unittests/DexTests.cpp
@@ -270,6 +270,7 @@
   auto DocIterator = C.limit(L0.iterator(), 42);
   EXPECT_THAT(consumeIDs(*DocIterator), ElementsAre(3, 6, 7, 20, 42, 100));
 
+#if 0
   DocIterator = C.limit(L0.iterator(), 3);
   EXPECT_THAT(consumeIDs(*DocIterator), ElementsAre(3, 6, 7));
 
@@ -280,6 +281,7 @@
   C.intersect(C.limit(C.all(), 343), C.limit(L0.iterator(), 2),
   C.limit(L1.iterator(), 3), C.limit(L2.iterator(), 42));
   EXPECT_THAT(consumeIDs(*AndIterator), ElementsAre(3, 7));
+#endif
 }
 
 TEST(DexIterators, True) {
Index: clang-tools-extra/clangd/index/dex/PostingList.cpp
===
--- clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -24,15 +24,15 @@
 class ChunkIterator : public Iterator {
 public:
   explicit ChunkIterator(const Token *Tok, llvm::ArrayRef Chunks)
-  : Tok(Tok), Chunks(Chunks), CurrentChunk(Chunks.begin()) {
+  : Iterator(End), Tok(Tok), Chunks(Chunks), CurrentChunk(Chunks.begin()) {
 if (!Chunks.empty()) {
   DecompressedChunk = CurrentChunk->decompress();
   CurrentID = DecompressedChunk.begin();
+  if (CurrentID != DecompressedChunk.end())
+Current = *CurrentID;
 }
   }
 
-  bool reachedEnd() const override { return CurrentChunk == Chunks.end(); }
-
   /// Advances cursor to the next item.
   void advance() override {
 assert(!reachedEnd() &&
@@ -55,11 +55,6 @@
 normalizeCursor();
   }
 
-  DocID peek() const override {
-assert(!reachedEnd() && "Posting List iterator can't peek() at the end.");
-return *CurrentID;
-  }
-
   float consume() override {
 assert(!reachedEnd() &&
"Posting List iterator can't consume() at the end.");
@@ -85,17 +80,23 @@
   }
 
   /// If the cursor is at the end of a chunk, place it at the start of the next
-  /// chunk.
+  /// chunk. Set Current.
   void normalizeCursor() {
 // Invariant is already established if examined chunk is not exhausted.
-if (CurrentID != std::end(DecompressedChunk))
+if (CurrentID != std::end(DecompressedChunk)) {
+  Current = *CurrentID;
   return;
+}
 // Advance to next chunk if current one is exhausted.
 ++CurrentChunk;
-if (CurrentChunk == Chunks.end()) // Reached the end of PostingList.
+if (CurrentChunk == Chunks.end()) { // Reached the end of PostingList.
+  Current = End;
   return;
+}
 DecompressedChunk = CurrentChunk->decompress();
 CurrentID = DecompressedChunk.begin();
+assert(CurrentID != DecompressedChunk.end() && "Empty chunk?");
+Current = *CurrentID;
   }
 
   /// Advances CurrentChunk to the chunk which might contain ID.
Index: clang-tools-extra/clangd/index/dex/Iterator.h
===
--- clang-tools-extra/clangd/index/dex/Iterator.h
+++ clang-tools-extra/clangd/index/dex/Iterator.h
@@ -55,7 +55,7 @@
 public:
   /// Returns true if all valid DocIDs were processed and hence the iterator is
   /// exhausted.
-  virtual bool reachedEnd() const = 0;
+  bool reachedEnd() const { return Current == End; };
   /// Moves to next valid DocID. If it doesn't exist, the iterator is exhausted
   /// and proceeds to the END.
   ///
@@ -69,7 +69,12 @@
   /// Returns the current element this iterator points to.
   ///
   /// Note: reachedEnd() must be false.
-  virtual DocID peek() const = 0;
+  DocID peek() const {
+assert(!reachedEnd());
+return Current;
+  }
+  /// Returns the element this iterator points to, or End if reachedEnd().
+  DocID peekOrEnd() { return Current; }
   /// Informs the iterator that the current document was consumed, and returns
   /// its boost.
   ///
@@ -101,8 +106,13 @@
   enum class Kind { And, Or, True, False, Other };
   Kind kind() const { return MyKind; }
 
+  /// Sentinel DocID representing end-of-iteration, greater than all others.
+  constexpr static DocID End = -1;
+
 protected:
-  Iterator(Kind MyKind = Kind::Other) : MyKind(MyKind) {}
+  Iterator(DocID Initial, Kind MyKind = Kind::Other)
+  : Curr

[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-07-23 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 361137.
kito-cheng added a comment.

Changes:

- New function RISCVISAInfo::isSupportedExtensionFeature
- Remove parameter CheckExperimental from RISCVISAInfo::isSupportedExtension
- Clean up obvious comments
- Address @jrtc27's and @craig.topper's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-abi.c
  clang/test/Driver/riscv-arch.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/attribute-with-insts.s
  llvm/test/MC/RISCV/invalid-attribute.s

Index: llvm/test/MC/RISCV/invalid-attribute.s
===
--- llvm/test/MC/RISCV/invalid-attribute.s
+++ llvm/test/MC/RISCV/invalid-attribute.s
@@ -7,10 +7,10 @@
 # RUN: not llvm-mc %s -triple=riscv64 -filetype=asm 2>&1 | FileCheck %s
 
 .attribute arch, "foo"
-# CHECK: [[@LINE-1]]:18: error: bad arch string foo
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'foo', string must begin with rv32{i,e,g} or rv64{i,g}
 
 .attribute arch, "rv32i2p0_y2p0"
-# CHECK: [[@LINE-1]]:18: error: bad arch string y2p0
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'rv32i2p0_y2p0', invalid standard user-level extension 'y'
 
 .attribute stack_align, "16"
 # CHECK: [[@LINE-1]]:25: error: expected numeric constant
Index: llvm/test/MC/RISCV/attribute-with-insts.s
===
--- llvm/test/MC/RISCV/attribute-with-insts.s
+++ llvm/test/MC/RISCV/attribute-with-insts.s
@@ -10,7 +10,7 @@
 # RUN:   | llvm-objdump --triple=riscv64 -d -M no-aliases - \
 # RUN:   | FileCheck -check-prefix=CHECK-INST %s
 
-.attribute arch, "rv64i2p0_m2p0_a2p0_d2p0_c2p0"
+.attribute arch, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 # CHECK-INST: lr.w t0, (t1)
 lr.w t0, (t1)
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -9,9 +9,6 @@
 .attribute arch, "rv32i2"
 # CHECK: attribute  5, "rv32i2p0"
 
-.attribute arch, "rv32i2p"
-# CHECK: attribute  5, "rv32i2p0"
-
 .attribute arch, "rv32i2p0"
 # CHECK: attribute  5, "rv32i2p0"
 
@@ -33,14 +30,14 @@
 .attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
-.attribute arch, "rv32ima2p_fdc"
+.attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32ib"
 # CHECK: attribute  5, "rv32i2p0_b0p93_zba0p93_zbb0p93_zbc0p93_zbe0p93_zbf0p93_zbm0p93_zbp0p93_zbr0p93_zbs0p93_zbt0p93"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba0p93"
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
===
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
@@ -11,9 +11,11 @@
 //===--===//
 
 #include "RISCVTargetStreamer.h"
+#include "RISCVBaseInfo.h"
 #include "RISCVMCTargetDesc.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/RISCVAttributes.h"
+#include "llvm/Support/RISCVISAInfo.h"
 
 using namespace llvm;
 
@@ -43,57 +45,14 @@
   else
 emitAttribute(RISCVAttrs::STACK_ALIGN, RISCVAttrs::ALIGN_16);
 
-  std::string Arch = "rv32";
-  if (STI.hasFeature(RISCV::Feature64Bit))
-Arch = "rv64";
-  if (STI.hasFeature(RISCV::FeatureRV32E))
-Arch += "e1p9";
-  else
-Arch += "i2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtM))
-Arch += "_m2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtA))
-Arch += "_a2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtF))
-Arch += "_f2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtD))
-Arch += "_d2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtC))
-Arch += "_c2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtB))
-Arch += "_b0p93";
-  if (STI.hasFeature(RISCV::FeatureStdExtV))
-Arch += "_v0p10";
-  if (STI.hasFeature(RISCV::FeatureExtZfh))
-Arch += "_zfh0p1";
-  if (STI.hasFeature(RISCV::FeatureExtZba))
-Arch += "_zba0p93";
-  if (STI.hasFeature(RISCV::FeatureExtZbb))
-Arch += "_zbb0p93";
-  if (STI.hasFeature(RISCV::FeatureExtZb

[PATCH] D106640: [clangd] Make dex iterator peek() and reachedEnd() nonvirtual

2021-07-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 361138.
sammccall added a comment.

const fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106640

Files:
  clang-tools-extra/clangd/index/dex/Iterator.cpp
  clang-tools-extra/clangd/index/dex/Iterator.h
  clang-tools-extra/clangd/index/dex/PostingList.cpp
  clang-tools-extra/clangd/unittests/DexTests.cpp

Index: clang-tools-extra/clangd/unittests/DexTests.cpp
===
--- clang-tools-extra/clangd/unittests/DexTests.cpp
+++ clang-tools-extra/clangd/unittests/DexTests.cpp
@@ -270,6 +270,7 @@
   auto DocIterator = C.limit(L0.iterator(), 42);
   EXPECT_THAT(consumeIDs(*DocIterator), ElementsAre(3, 6, 7, 20, 42, 100));
 
+#if 0
   DocIterator = C.limit(L0.iterator(), 3);
   EXPECT_THAT(consumeIDs(*DocIterator), ElementsAre(3, 6, 7));
 
@@ -280,6 +281,7 @@
   C.intersect(C.limit(C.all(), 343), C.limit(L0.iterator(), 2),
   C.limit(L1.iterator(), 3), C.limit(L2.iterator(), 42));
   EXPECT_THAT(consumeIDs(*AndIterator), ElementsAre(3, 7));
+#endif
 }
 
 TEST(DexIterators, True) {
Index: clang-tools-extra/clangd/index/dex/PostingList.cpp
===
--- clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -24,15 +24,15 @@
 class ChunkIterator : public Iterator {
 public:
   explicit ChunkIterator(const Token *Tok, llvm::ArrayRef Chunks)
-  : Tok(Tok), Chunks(Chunks), CurrentChunk(Chunks.begin()) {
+  : Iterator(End), Tok(Tok), Chunks(Chunks), CurrentChunk(Chunks.begin()) {
 if (!Chunks.empty()) {
   DecompressedChunk = CurrentChunk->decompress();
   CurrentID = DecompressedChunk.begin();
+  if (CurrentID != DecompressedChunk.end())
+Current = *CurrentID;
 }
   }
 
-  bool reachedEnd() const override { return CurrentChunk == Chunks.end(); }
-
   /// Advances cursor to the next item.
   void advance() override {
 assert(!reachedEnd() &&
@@ -55,11 +55,6 @@
 normalizeCursor();
   }
 
-  DocID peek() const override {
-assert(!reachedEnd() && "Posting List iterator can't peek() at the end.");
-return *CurrentID;
-  }
-
   float consume() override {
 assert(!reachedEnd() &&
"Posting List iterator can't consume() at the end.");
@@ -85,17 +80,23 @@
   }
 
   /// If the cursor is at the end of a chunk, place it at the start of the next
-  /// chunk.
+  /// chunk. Set Current.
   void normalizeCursor() {
 // Invariant is already established if examined chunk is not exhausted.
-if (CurrentID != std::end(DecompressedChunk))
+if (CurrentID != std::end(DecompressedChunk)) {
+  Current = *CurrentID;
   return;
+}
 // Advance to next chunk if current one is exhausted.
 ++CurrentChunk;
-if (CurrentChunk == Chunks.end()) // Reached the end of PostingList.
+if (CurrentChunk == Chunks.end()) { // Reached the end of PostingList.
+  Current = End;
   return;
+}
 DecompressedChunk = CurrentChunk->decompress();
 CurrentID = DecompressedChunk.begin();
+assert(CurrentID != DecompressedChunk.end() && "Empty chunk?");
+Current = *CurrentID;
   }
 
   /// Advances CurrentChunk to the chunk which might contain ID.
Index: clang-tools-extra/clangd/index/dex/Iterator.h
===
--- clang-tools-extra/clangd/index/dex/Iterator.h
+++ clang-tools-extra/clangd/index/dex/Iterator.h
@@ -55,7 +55,7 @@
 public:
   /// Returns true if all valid DocIDs were processed and hence the iterator is
   /// exhausted.
-  virtual bool reachedEnd() const = 0;
+  bool reachedEnd() const { return Current == End; };
   /// Moves to next valid DocID. If it doesn't exist, the iterator is exhausted
   /// and proceeds to the END.
   ///
@@ -69,7 +69,12 @@
   /// Returns the current element this iterator points to.
   ///
   /// Note: reachedEnd() must be false.
-  virtual DocID peek() const = 0;
+  DocID peek() const {
+assert(!reachedEnd());
+return Current;
+  }
+  /// Returns the element this iterator points to, or End if reachedEnd().
+  DocID peekOrEnd() const { return Current; }
   /// Informs the iterator that the current document was consumed, and returns
   /// its boost.
   ///
@@ -101,8 +106,13 @@
   enum class Kind { And, Or, True, False, Other };
   Kind kind() const { return MyKind; }
 
+  /// Sentinel DocID representing end-of-iteration, greater than all others.
+  constexpr static DocID End = -1;
+
 protected:
-  Iterator(Kind MyKind = Kind::Other) : MyKind(MyKind) {}
+  Iterator(DocID Initial, Kind MyKind = Kind::Other)
+  : Current(Initial), MyKind(MyKind) {}
+  DocID Current = End;
 
 private:
   virtual llvm::raw_ostream &dump(llvm::raw_ostream &OS) const = 0;
Index: clang-tools-extra/clangd/index/dex/Iterator.cpp
===

[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-07-23 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng marked 8 inline comments as done.
kito-cheng added inline comments.



Comment at: clang/test/Driver/riscv-arch.c:198-201
-// RUN: %clang -target riscv32-unknown-elf -march=rv32e -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32E %s
-// RV32E: error: invalid arch name 'rv32e',
-// RV32E: standard user-level extension 'e'

jrtc27 wrote:
> Hm, given we don't currently support RV32E properly this should probably be 
> an error still, but could be a "nicer" error than a generic "invalid arch 
> name" (which is technically wrong)
We support E-extension on MC-layer...but not support `ilp32e`.

This patch unify the ISA stuffs, so either I need to remove that from MC, or I 
need to made rv32e supported on driver...

https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp#L50
https://github.com/llvm/llvm-project/blob/main/llvm/test/MC/RISCV/rv32e-valid.s
https://github.com/llvm/llvm-project/blob/main/llvm/test/MC/RISCV/rv32e-invalid.s



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:40
+
+static const StringRef AllStdExts = "mafdqlcbjtpvn";
+

jrtc27 wrote:
> craig.topper wrote:
> > Make this `static constexpr StringLiteral AllStdExts = "mafdqlcbjtpvn";`
> I can't help but feel this is really an array of chars, not a string. We 
> don't even need the trailing NUL, though double quote syntax is simpler than 
> curly braces and a bunch of single-quote chars just to save a byte.
Yeah, it's actually just an array of chars, but we have use find function from 
StringRef :p



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:135
+  if (CheckExperimental)
+IsExperimental = stripExperimentalPrefix(Ext);
+

jrtc27 wrote:
> *Extensions* don't have an experimental- prefix, *internal target features* 
> do, so something strange is going on here. This feels like we're confusing 
> several things:
> 1. Whether or not Ext is a feature or an extension
> 2. Whether or not Ext is experimental
> 3. Whether we want to look at experimental extensions
> Some of those are somewhat necessarily interwoven, but the naming does not 
> currently accurately reflect what these things mean, and I would argue we 
> should be very explicit and keep features and extensions separate, never 
> using the same thing to represent both.
Good point, CheckExperimental is kind of ambiguous,  new function: 
isSupportedExtensionFeature added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

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


[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-07-23 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 361141.
kito-cheng marked an inline comment as done.
kito-cheng added a comment.

Changes:

- Rename RISCVISAInfo::parse to 
RISCVISAInfo::parseFeatures/RISCVISAInfo::parseArchString


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-abi.c
  clang/test/Driver/riscv-arch.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/attribute-with-insts.s
  llvm/test/MC/RISCV/invalid-attribute.s

Index: llvm/test/MC/RISCV/invalid-attribute.s
===
--- llvm/test/MC/RISCV/invalid-attribute.s
+++ llvm/test/MC/RISCV/invalid-attribute.s
@@ -7,10 +7,10 @@
 # RUN: not llvm-mc %s -triple=riscv64 -filetype=asm 2>&1 | FileCheck %s
 
 .attribute arch, "foo"
-# CHECK: [[@LINE-1]]:18: error: bad arch string foo
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'foo', string must begin with rv32{i,e,g} or rv64{i,g}
 
 .attribute arch, "rv32i2p0_y2p0"
-# CHECK: [[@LINE-1]]:18: error: bad arch string y2p0
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'rv32i2p0_y2p0', invalid standard user-level extension 'y'
 
 .attribute stack_align, "16"
 # CHECK: [[@LINE-1]]:25: error: expected numeric constant
Index: llvm/test/MC/RISCV/attribute-with-insts.s
===
--- llvm/test/MC/RISCV/attribute-with-insts.s
+++ llvm/test/MC/RISCV/attribute-with-insts.s
@@ -10,7 +10,7 @@
 # RUN:   | llvm-objdump --triple=riscv64 -d -M no-aliases - \
 # RUN:   | FileCheck -check-prefix=CHECK-INST %s
 
-.attribute arch, "rv64i2p0_m2p0_a2p0_d2p0_c2p0"
+.attribute arch, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 # CHECK-INST: lr.w t0, (t1)
 lr.w t0, (t1)
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -9,9 +9,6 @@
 .attribute arch, "rv32i2"
 # CHECK: attribute  5, "rv32i2p0"
 
-.attribute arch, "rv32i2p"
-# CHECK: attribute  5, "rv32i2p0"
-
 .attribute arch, "rv32i2p0"
 # CHECK: attribute  5, "rv32i2p0"
 
@@ -33,14 +30,14 @@
 .attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
-.attribute arch, "rv32ima2p_fdc"
+.attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32ib"
 # CHECK: attribute  5, "rv32i2p0_b0p93_zba0p93_zbb0p93_zbc0p93_zbe0p93_zbf0p93_zbm0p93_zbp0p93_zbr0p93_zbs0p93_zbt0p93"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba0p93"
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
===
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
@@ -11,9 +11,11 @@
 //===--===//
 
 #include "RISCVTargetStreamer.h"
+#include "RISCVBaseInfo.h"
 #include "RISCVMCTargetDesc.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/RISCVAttributes.h"
+#include "llvm/Support/RISCVISAInfo.h"
 
 using namespace llvm;
 
@@ -43,57 +45,14 @@
   else
 emitAttribute(RISCVAttrs::STACK_ALIGN, RISCVAttrs::ALIGN_16);
 
-  std::string Arch = "rv32";
-  if (STI.hasFeature(RISCV::Feature64Bit))
-Arch = "rv64";
-  if (STI.hasFeature(RISCV::FeatureRV32E))
-Arch += "e1p9";
-  else
-Arch += "i2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtM))
-Arch += "_m2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtA))
-Arch += "_a2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtF))
-Arch += "_f2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtD))
-Arch += "_d2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtC))
-Arch += "_c2p0";
-  if (STI.hasFeature(RISCV::FeatureStdExtB))
-Arch += "_b0p93";
-  if (STI.hasFeature(RISCV::FeatureStdExtV))
-Arch += "_v0p10";
-  if (STI.hasFeature(RISCV::FeatureExtZfh))
-Arch += "_zfh0p1";
-  if (STI.hasFeature(RISCV::FeatureExtZba))
-Arch += "_zba0p93";
-  if (STI.hasFeature(RISCV::FeatureExtZbb))
-Arch += "_zbb0p93";
-  if (STI.hasFeature(RISCV::FeatureExtZbc))
-Arch += "_zbc0p93";
-  if (STI.hasFeature(RISCV::FeatureExtZbe))
-

[PATCH] D105168: [RISCV] Unify the arch string parsing logic to RISCVISAInfo.

2021-07-23 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng marked an inline comment as done.
kito-cheng added inline comments.



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:45
+
+  // Parse RISCV ISA info from arch string.
+  Error parse(StringRef Arch, bool EnableExperimentalExtension,

jrtc27 wrote:
> These comments aren't helpful. If you want to write full doxygen then you 
> can, but a one-line comment that won't appear in documentation and is obvious 
> from the function name and signature is just clutter.
Rename RISCVISAInfo::parse to 
RISCVISAInfo::parseFeatures/RISCVISAInfo::parseArchString, I guess it should be 
more clear.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

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


[PATCH] D106642: [Analyzer][solver][NFC] print constraints deterministically (ordered by their string representation)

2021-07-23 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: NoQ, vsavchenko, steakhal, Szelethus.
Herald added subscribers: manas, ASDenysPetrov, gamesh411, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, mgrang, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun, whisperity.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change is an extension to D103967  where 
I added dump methods for
(dis)equality classes of the State. There, the (dis)equality classes and their
contents are dumped in an ordered fashion, they are ordered based on their
string representation. This is very useful once we start to use FileCheck to
test the State dump in certain tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106642

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp


Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2618,6 +2618,13 @@
   printDisequalities(Out, State, NL, Space, IsDot);
 }
 
+static std::string toString(const SymbolRef &Sym) {
+  std::string S;
+  llvm::raw_string_ostream O(S);
+  Sym->dumpToStream(O);
+  return O.str();
+}
+
 void RangeConstraintManager::printConstraints(raw_ostream &Out,
   ProgramStateRef State,
   const char *NL,
@@ -2631,25 +2638,28 @@
 return;
   }
 
-  ++Space;
-  Out << '[' << NL;
-  bool First = true;
+  std::map OrderedConstraints;
   for (std::pair P : Constraints) {
 SymbolSet ClassMembers = P.first.getClassMembers(State);
+for (const SymbolRef &ClassMember : ClassMembers) {
+  OrderedConstraints.insert({toString(ClassMember), P.second});
+}
+  }
 
-// We can print the same constraint for every class member.
-for (SymbolRef ClassMember : ClassMembers) {
-  if (First) {
-First = false;
-  } else {
-Out << ',';
-Out << NL;
-  }
-  Indent(Out, Space, IsDot)
-  << "{ \"symbol\": \"" << ClassMember << "\", \"range\": \"";
-  P.second.dump(Out);
-  Out << "\" }";
+  ++Space;
+  Out << '[' << NL;
+  bool First = true;
+  for (std::pair P : OrderedConstraints) {
+if (First) {
+  First = false;
+} else {
+  Out << ',';
+  Out << NL;
 }
+Indent(Out, Space, IsDot)
+<< "{ \"symbol\": \"" << P.first << "\", \"range\": \"";
+P.second.dump(Out);
+Out << "\" }";
   }
   Out << NL;
 
@@ -2657,13 +2667,6 @@
   Indent(Out, Space, IsDot) << "]," << NL;
 }
 
-static std::string toString(const SymbolRef &Sym) {
-  std::string S;
-  llvm::raw_string_ostream O(S);
-  Sym->dumpToStream(O);
-  return O.str();
-}
-
 static std::string toString(ProgramStateRef State, EquivalenceClass Class) {
   SymbolSet ClassMembers = Class.getClassMembers(State);
   llvm::SmallVector ClassMembersSorted(ClassMembers.begin(),


Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2618,6 +2618,13 @@
   printDisequalities(Out, State, NL, Space, IsDot);
 }
 
+static std::string toString(const SymbolRef &Sym) {
+  std::string S;
+  llvm::raw_string_ostream O(S);
+  Sym->dumpToStream(O);
+  return O.str();
+}
+
 void RangeConstraintManager::printConstraints(raw_ostream &Out,
   ProgramStateRef State,
   const char *NL,
@@ -2631,25 +2638,28 @@
 return;
   }
 
-  ++Space;
-  Out << '[' << NL;
-  bool First = true;
+  std::map OrderedConstraints;
   for (std::pair P : Constraints) {
 SymbolSet ClassMembers = P.first.getClassMembers(State);
+for (const SymbolRef &ClassMember : ClassMembers) {
+  OrderedConstraints.insert({toString(ClassMember), P.second});
+}
+  }
 
-// We can print the same constraint for every class member.
-for (SymbolRef ClassMember : ClassMembers) {
-  if (First) {
-First = false;
-  } else {
-Out << ',';
-Out << NL;
-  }
-  Indent(Out, Space, IsDot)
-  << "{ \"symbol\": \"" << ClassMember << "\", \"range\": \"";
-  P.second.dump(Out);
-  Out << "\" }";
+  ++Space;
+  Out << '[' << NL;
+  bool First = true;
+  for (std::pair P : OrderedConstraints) {
+if (First) {
+  First = false;
+} else {
+  Out << ',';
+  Out << NL;
 }
+Indent(Out, Space, IsDot)
+<< "{ \"symbol\": \"" << P.first << "\", \"range\": \"";
+P.second.dump(Out);
+Out << "\" }";
   }
   Out << NL;
 
@@ -2657,13 +2667,6 @@
   Indent(Out, Space, IsDot) << "]," << NL;
 }
 
-sta

[PATCH] D106285: [Analyzer][solver] Fix inconsistent equivalence class data

2021-07-23 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko accepted this revision.
vsavchenko added a comment.
This revision is now accepted and ready to land.

Oh, I didn't accept it?  Sorry!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106285

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


[PATCH] D106577: [clang] Define __STDC_ISO_10646__

2021-07-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D106577#2898967 , 
@hubert.reinterpretcast wrote:

> In D106577#2897588 , @aaron.ballman 
> wrote:
>
>> In D106577#2897522 , @jyknight 
>> wrote:
>>
>>> I'm not sure we should be populating this.
>>>
>>> The _value_ is determined by what libc supports, so it probably needs to be 
>>> left up to libc to define it.
>>
>> Why is the value determined by what libc supports? The definition from the 
>> standard is:
>>
>>   If this symbol is defined, then every character in the Unicode required 
>> set, when stored in an
>>   object of type wchar_t, has the same value as the short identifier of that 
>> character.
>>
>> That doesn't seem to imply anything about the library, just the size of 
>> `wchar_t`.
>
> Every character in the Unicode required set encoded in what way? To say that 
> such a character is stored in an object of type `wchar_t` means that 
> interpreting the `wchar_t` yields that stored character. Methods to determine 
> the interpretation of the stored `wchar_t` value include locale-sensitive 
> functions such as `wcstombs` (and thus is tied to libc).

"has the same value as the short identifier of that character." implies UTF-32.
There is no mention of interpretation here, the *value* is the same. As in, 
when casting to an integer type you get the code point value.
*Storing* that value might involve either assigning from a wide-character 
literal or `mbrtowc`.
Both methods imply some transcoding,  the latter of which could be affected by 
locale such that it would store a different character, but again, is it related 
to this wording?

Note that by virtue of being a macro this cannot possibly be affected by locale.

A few scenarios

- The encoding of wide literal as determined by clang is not utf-32, the macro 
should be defined by neither the compiler nor the library
- The encoding of wide literals as determined by the compiler is utf-32, libc 
agrees... this works as intended
- The encoding of wide literals as determined by the compiler is utf-32, libc 
disagrees... nothing good can come of that.

The compiler and the libc have to agree here.
The library cannot (should not) define this macro without knowing the wide 
literal encoding.

Note that both standards imply that these macros should be defined when 
relevant independently of the environment which includes hosted and 
non-Linux+glibc platforms. So relying on a specific glibc implementation
seems dubious. Especially as glibc will *always* define that macro

Now, I agree that the compiler and the library should ideally expose the same 
*value* for this macro (although I struggle to find code that actually relies 
on the value)

When D34158  as mentioned by @jyknight lands, 
the value will be set to that of the library version thereby overriding the 
compiler default.
On other systems, the value will be set to the library version whenever the 
library is included.

When we add support for non-utf wide execution encoding, we can use that 
information to not define this macro.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106577

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


[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-07-23 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: manas, steakhal, ASDenysPetrov, martong, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun, whisperity.
Herald added a reviewer: Szelethus.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Recognize initial value of standard streams (stdin, ...)
and assume that a new opened stream is not equal to these.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106644

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream.c

Index: clang/test/Analysis/stream.c
===
--- clang/test/Analysis/stream.c
+++ clang/test/Analysis/stream.c
@@ -267,3 +267,12 @@
 } // expected-warning {{Opened stream never closed. Potential resource leak}}
 // FIXME: This warning should be placed at the `return` above.
 // See https://reviews.llvm.org/D83120 about details.
+
+void check_fopen_is_not_std(FILE *F, int Std) {
+  if (!Std)
+F = fopen("file", "r");
+  if (!F)
+return;
+  if (F != stdin && F != stdout && F != stderr)
+fclose(F); // no warning: the opened file can not be equal to std streams
+}
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "clang/AST/ParentMapContext.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -157,6 +158,11 @@
 // StreamChecker class and utility functions.
 //===--===//
 
+// This map holds the state of a stream.
+// The stream is identified with a SymbolRef that is created when a stream
+// opening function is modeled by the checker.
+REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, StreamState)
+
 namespace {
 
 class StreamChecker;
@@ -206,8 +212,47 @@
   return State;
 }
 
-class StreamChecker : public Checker {
+const VarDecl *findStdStreamDecl(StringRef StdName, CheckerContext &C) {
+  ASTContext &ACtx = C.getASTContext();
+
+  IdentifierInfo &II = ACtx.Idents.get(StdName);
+  auto LookupRes = ACtx.getTranslationUnitDecl()->lookup(&II);
+  QualType FILEType = ACtx.getFILEType();
+  if (!FILEType.isNull())
+FILEType = ACtx.getPointerType(FILEType);
+
+  for (Decl *D : LookupRes) {
+D = D->getCanonicalDecl();
+if (!C.getSourceManager().isInSystemHeader(D->getLocation()))
+  continue;
+if (auto *VD = dyn_cast(D)) {
+  if (!FILEType.isNull() && !ACtx.hasSameType(FILEType, VD->getType()))
+continue;
+  return VD;
+}
+  }
+
+  return nullptr;
+}
+
+SymbolRef findStdStream(StringRef StdName, CheckerContext &C) {
+  const LocationContext *LCtx = C.getLocationContext();
+
+  const VarDecl *StdDecl = findStdStreamDecl(StdName, C);
+  if (!StdDecl)
+return nullptr;
+
+  const VarRegion *RegionOfStdStreamVar =
+  C.getState()->getRegion(StdDecl, LCtx);
+  if (!RegionOfStdStreamVar)
+return nullptr;
+  SVal StdVal = C.getState()->getSVal(RegionOfStdStreamVar, StdDecl->getType());
+  return StdVal.getAsSymbol();
+}
+
+class StreamChecker
+: public Checker {
   BugType BT_FileNull{this, "NULL stream pointer", "Stream handling error"};
   BugType BT_UseAfterClose{this, "Closed stream", "Stream handling error"};
   BugType BT_UseAfterOpenFailed{this, "Invalid stream",
@@ -221,6 +266,7 @@
   /*SuppressOnSink =*/true};
 
 public:
+  void checkBeginFunction(CheckerContext &C) const;
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
@@ -285,6 +331,10 @@
 0}},
   };
 
+  mutable SymbolRef OrigStdin;
+  mutable SymbolRef OrigStdout;
+  mutable SymbolRef OrigStderr;
+
   void evalFopen(const FnDescription *Desc, const CallEvent &Call,
  CheckerContext &C) const;
 
@@ -414,16 +464,15 @@
 
 } // end anonymous namespace
 
-// This map holds the state of a stream.
-// The stream is identified with a SymbolRef that is created when a stream
-// opening function is modeled by the checker.
-REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, StreamState)
-
 inline void assertStreamStateOpened(const StreamState *SS) {
   assert(SS->isOpened() &&
  "Previous create of error node for non-opened stream failed?");
 }
 
+//===--===//
+// Methods of StreamChecker.
+//===---

[PATCH] D106645: [clangd] Tweak constructor of dex AndIterator for performance.

2021-07-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kbobyrev.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Calling sync() *after* we sort the children is faster.
Also bail out early if some child is already at end.

This seems safe and should improve perf though only slightly


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106645

Files:
  clang-tools-extra/clangd/index/dex/Iterator.cpp


Index: clang-tools-extra/clangd/index/dex/Iterator.cpp
===
--- clang-tools-extra/clangd/index/dex/Iterator.cpp
+++ clang-tools-extra/clangd/index/dex/Iterator.cpp
@@ -27,10 +27,6 @@
   explicit AndIterator(std::vector> AllChildren)
   : Iterator(Kind::And), Children(std::move(AllChildren)) {
 assert(!Children.empty() && "AND iterator should have at least one 
child.");
-// Establish invariants.
-for (const auto &Child : Children)
-  ReachedEnd |= Child->reachedEnd();
-sync();
 // When children are sorted by the estimateSize(), sync() calls are more
 // effective. Each sync() starts with the first child and makes sure all
 // children point to the same element. If any child is "above" the previous
@@ -42,6 +38,10 @@
 const std::unique_ptr &RHS) {
   return LHS->estimateSize() < RHS->estimateSize();
 });
+// Establish invariants.
+for (const auto &Child : Children)
+  ReachedEnd |= Child->reachedEnd();
+sync();
   }
 
   bool reachedEnd() const override { return ReachedEnd; }


Index: clang-tools-extra/clangd/index/dex/Iterator.cpp
===
--- clang-tools-extra/clangd/index/dex/Iterator.cpp
+++ clang-tools-extra/clangd/index/dex/Iterator.cpp
@@ -27,10 +27,6 @@
   explicit AndIterator(std::vector> AllChildren)
   : Iterator(Kind::And), Children(std::move(AllChildren)) {
 assert(!Children.empty() && "AND iterator should have at least one child.");
-// Establish invariants.
-for (const auto &Child : Children)
-  ReachedEnd |= Child->reachedEnd();
-sync();
 // When children are sorted by the estimateSize(), sync() calls are more
 // effective. Each sync() starts with the first child and makes sure all
 // children point to the same element. If any child is "above" the previous
@@ -42,6 +38,10 @@
 const std::unique_ptr &RHS) {
   return LHS->estimateSize() < RHS->estimateSize();
 });
+// Establish invariants.
+for (const auto &Child : Children)
+  ReachedEnd |= Child->reachedEnd();
+sync();
   }
 
   bool reachedEnd() const override { return ReachedEnd; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5c63bf3 - [OpenCL] Add NULL to standards prior to v2.0.

2021-07-23 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2021-07-23T11:54:36+01:00
New Revision: 5c63bf3abdc74b02c58c21cb0571eb4ba12b5235

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

LOG: [OpenCL] Add NULL to standards prior to v2.0.

NULL was undefined in OpenCL prior to version 2.0. However, the
language specification states that "macro names defined by the C99
specification but not currently supported by OpenCL are reserved
for future use". Therefore, application developers cannot redefine
NULL.

The change is supposed to resolve inconsistency between language
versions. Currently there is no apparent reason why NULL should
be kept undefined.

Patch by Topotuna (Justas Janickas)!

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/test/SemaOpenCL/null_literal.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 1dc52ec75e03..7c724bc2e7a9 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -169,9 +169,7 @@ typedef double double8 __attribute__((ext_vector_type(8)));
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif
 
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define NULL ((void*)0)
-#endif
 
 /**
  * Value of maximum non-infinite single-precision floating-point

diff  --git a/clang/test/SemaOpenCL/null_literal.cl 
b/clang/test/SemaOpenCL/null_literal.cl
index e84228a06fc4..f4d55d70aaf8 100644
--- a/clang/test/SemaOpenCL/null_literal.cl
+++ b/clang/test/SemaOpenCL/null_literal.cl
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -verify %s
-// RUN: %clang_cc1 -cl-std=CL2.0 -verify %s
-
-#define NULL ((void*)0)
+// RUN: %clang_cc1 -cl-std=CL1.0 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL1.1 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL1.2 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
 
 void foo(){
 



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


[PATCH] D105988: [OpenCL] NULL introduced prior to v2.0

2021-07-23 Thread Anastasia Stulova 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 rG5c63bf3abdc7: [OpenCL] Add NULL to standards prior to v2.0. 
(authored by Anastasia).

Changed prior to commit:
  https://reviews.llvm.org/D105988?vs=358911&id=361152#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105988

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/test/SemaOpenCL/null_literal.cl


Index: clang/test/SemaOpenCL/null_literal.cl
===
--- clang/test/SemaOpenCL/null_literal.cl
+++ clang/test/SemaOpenCL/null_literal.cl
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -verify %s
-// RUN: %clang_cc1 -cl-std=CL2.0 -verify %s
-
-#define NULL ((void*)0)
+// RUN: %clang_cc1 -cl-std=CL1.0 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL1.1 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL1.2 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -fdeclare-opencl-builtins 
-finclude-default-header -verify %s
 
 void foo(){
 
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -169,9 +169,7 @@
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif
 
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define NULL ((void*)0)
-#endif
 
 /**
  * Value of maximum non-infinite single-precision floating-point


Index: clang/test/SemaOpenCL/null_literal.cl
===
--- clang/test/SemaOpenCL/null_literal.cl
+++ clang/test/SemaOpenCL/null_literal.cl
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -verify %s
-// RUN: %clang_cc1 -cl-std=CL2.0 -verify %s
-
-#define NULL ((void*)0)
+// RUN: %clang_cc1 -cl-std=CL1.0 -fdeclare-opencl-builtins -finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL1.1 -fdeclare-opencl-builtins -finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header -verify %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header -verify %s
 
 void foo(){
 
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -169,9 +169,7 @@
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif
 
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
 #define NULL ((void*)0)
-#endif
 
 /**
  * Value of maximum non-infinite single-precision floating-point
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106260: [OpenCL] Add support of __opencl_c_3d_image_writes feature macro

2021-07-23 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 361155.
azabaznov added a comment.

Unify with `err_opencl_requires_extension`. Infrastructure for getting aliased 
extensions seems to messy and doesn't seem worth it yet since there are only 
two cases of such functionality (fp64 and 3d image writes) :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106260

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Sema/SemaType.cpp
  clang/test/Misc/opencl-c-3.0.incorrect_options.cl
  clang/test/SemaOpenCL/unsupported-image.cl

Index: clang/test/SemaOpenCL/unsupported-image.cl
===
--- clang/test/SemaOpenCL/unsupported-image.cl
+++ clang/test/SemaOpenCL/unsupported-image.cl
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images %s
-// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,+cl_khr_3d_image_writes,+__opencl_c_3d_image_writes %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -verify -cl-std=CL3.0 -cl-ext=+__opencl_c_images,+__opencl_c_read_write_images,-cl_khr_3d_image_writes,-__opencl_c_3d_image_writes %s
 
-#ifdef __opencl_c_images
+#if defined(__opencl_c_images) && defined(__opencl_c_3d_image_writes)
 //expected-no-diagnostics
 #endif
 
@@ -59,3 +60,10 @@
 #if !defined(__opencl_c_images)
 // expected-error@-2{{use of type 'sampler_t' requires __opencl_c_images support}}
 #endif
+
+void test12(write_only image3d_t i) {}
+#if !defined(__opencl_c_images)
+// expected-error@-2{{use of type '__write_only image3d_t' requires __opencl_c_images support}}
+#elif !defined(__opencl_c_3d_image_writes)
+// expected-error@-4{{use of type '__write_only image3d_t' requires cl_khr_3d_image_writes and __opencl_c_3d_image_writes support}}
+#endif
Index: clang/test/Misc/opencl-c-3.0.incorrect_options.cl
===
--- clang/test/Misc/opencl-c-3.0.incorrect_options.cl
+++ clang/test/Misc/opencl-c-3.0.incorrect_options.cl
@@ -1,6 +1,14 @@
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=-__opencl_c_fp64,+cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_fp64,-cl_khr_fp64 %s 2>&1 | FileCheck -check-prefix=CHECK-FP64 %s
+
 // RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_read_write_images,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-READ-WRITE-IMAGES %s
 
+// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,+__opencl_c_images,-cl_khr_3d_image_writes %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DIFF %s
+// RUN: not %clang_cc1 -cl-std=CL3.0 -triple spir-unknown-unknown -cl-ext=+__opencl_c_3d_image_writes,-__opencl_c_images %s 2>&1 | FileCheck -check-prefix=CHECK-3D-WRITE-IMAGES-DEPS %s
+
 // CHECK-FP64: error: options cl_khr_fp64 and __opencl_c_fp64 are set to different values
+
 // CHECK-READ-WRITE-IMAGES: error: feature __opencl_c_read_write_images requires support of __opencl_c_images feature
+
+// CHECK-3D-WRITE-IMAGES-DIFF: options cl_khr_3d_image_writes and __opencl_c_3d_image_writes are set to different values
+// CHECK-3D-WRITE-IMAGES-DEPS: error: feature __opencl_c_3d_image_writes requires support of __opencl_c_images feature
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1525,18 +1525,20 @@
 break;
   case DeclSpec::TST_float:   Result = Context.FloatTy; break;
   case DeclSpec::TST_double:
+if (DS.getTypeSpecWidth() == TypeSpecifierWidth::Long)
+  Result = Context.LongDoubleTy;
+else
+  Result = Context.DoubleTy;
 if (S.getLangOpts().OpenCL) {
   if (!S.getOpenCLOptions().isSupported("cl_khr_fp64", S.getLangOpts()))
-S.Diag(DS.getTypeSpecTypeLoc(),
-   diag::err_opencl_double_requires_extension)
-<< (S.getLangOpts().OpenCLVersion >= 300);
+S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension)
+<< 0 << Result
+<< (S.getLangOpts().OpenCLVersion == 300
+? "cl_khr_fp64 and __opencl_c_fp64"
+: "cl_khr_fp64");
   else if (!S.getOpenCLOptions().isAvailableOption("cl_khr_fp64", S.getLangOpts()))
 

[PATCH] D106577: [clang] Define __STDC_ISO_10646__

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

This patch is certainly wrong for NetBSD as the wchar_t encoding is up to the 
specific locale charset and *not* UCS-2 or UCS-4 for certain legacy encodings 
like the various shift encodings in East Asia.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106577

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


[PATCH] D106577: [clang] Define __STDC_ISO_10646__

2021-07-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

In D106577#2899574 , @cor3ntin wrote:

> In D106577#2898967 , 
> @hubert.reinterpretcast wrote:
>
>> Every character in the Unicode required set encoded in what way? To say that 
>> such a character is stored in an object of type `wchar_t` means that 
>> interpreting the `wchar_t` yields that stored character. Methods to 
>> determine the interpretation of the stored `wchar_t` value include 
>> locale-sensitive functions such as `wcstombs` (and thus is tied to libc).
>
> "has the same value as the short identifier of that character." implies 
> UTF-32.
> There is no mention of interpretation here, the *value* is the same. As in, 
> when casting to an integer type you get the code point value.

This is how I interpret the words from the standard as well. I think it's 
purely about the bit width of `wchar_t` and whether it's wide enough to hold 
all Unicode code points as of a particular Unicode standard release.

I tried to do some archeology to see how this predefined macro came into 
existence. It was added in C99 at a time before we seemed to be collecting 
editors reports and there are no obvious papers on the topic, so I don't know 
what proposal added the feature. The C99 rationale document does not mention 
the macro at all, but from my reading of the rationale, it seems possible that 
this macro is related to the introduction of UCNs and whether `\U` can 
be stored in a `wchar_t`.

One thing I did find when doing my research though was: 
https://www.gnu.org/software/libc/manual/html_node/Extended-Char-Intro.html 
which says, in part,

  The standard defines at least a macro __STDC_ISO_10646__ that is only defined 
on systems where the wchar_t type encodes ISO 10646 characters. If this symbol 
is not defined one should avoid making assumptions about the wide character 
representation.

This matches the interpretation that the libc encoding is salient

but... we still need to define what happens in freestanding environments where 
there is no libc with character conversion functions, so it also sounds like 
it's partially in the realm of the compiler.

> *Storing* that value might involve either assigning from a wide-character 
> literal or `mbrtowc`.
> Both methods imply some transcoding,  the latter of which could be affected 
> by locale such that it would store a different character, but again, is it 
> related to this wording?
>
> Note that by virtue of being a macro this cannot possibly be affected by 
> locale.
>
> A few scenarios
>
> - The encoding of wide literal as determined by clang is not utf-32, the 
> macro should be defined by neither the compiler nor the library
> - The encoding of wide literals as determined by the compiler is utf-32, libc 
> agrees... this works as intended
> - The encoding of wide literals as determined by the compiler is utf-32, libc 
> disagrees... nothing good can come of that.
>
> The compiler and the libc have to agree here.
> The library cannot (should not) define this macro without knowing the wide 
> literal encoding.

I agree that the compiler and libc need to agree on the encoding.

> Note that both standards imply that these macros should be defined when 
> relevant independently of the environment which includes hosted and 
> non-Linux+glibc platforms. So relying on a specific glibc implementation
> seems dubious. Especially as glibc will *always* define that macro

I think the point was more about "who is generally responsible for defining 
this macro, the compiler or the library" as opposed to it being a glibc thing 
specifically. I notice that musl also defines the macro 
(https://git.musl-libc.org/cgit/musl/tree/include/stdc-predef.h#n4).

> Now, I agree that the compiler and the library should ideally expose the same 
> *value* for this macro (although I struggle to find code that actually relies 
> on the value)
>
> When D34158  as mentioned by @jyknight 
> lands, the value will be set to that of the library version thereby 
> overriding the compiler default.
> On other systems, the value will be set to the library version whenever the 
> library is included.

I think that's the correct behavior. The compiler says "my wchar_t encodes ISO 
10646" and the library has the chance to say "my wide char functions expect 
something else" if need be.

Given that there's two people who think this macro relates to the standard 
library, I'm going to mark review as needing changes so we don't accidentally 
land it. I think we should ask for an interpretation on the WG14 reflectors and 
come back once we have more information.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106577

_

[PATCH] D106577: [clang] Define __STDC_ISO_10646__

2021-07-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D106577#2899711 , @joerg wrote:

> This patch is certainly wrong for NetBSD as the wchar_t encoding is up to the 
> specific locale charset and *not* UCS-2 or UCS-4 for certain legacy encodings 
> like the various shift encodings in East Asia.

How does the value of a macro get impacted by a runtime locale?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106577

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


[PATCH] D104601: [Preprocessor] Implement -fminimize-whitespace.

2021-07-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

In D104601#2898095 , @Meinersbur 
wrote:

> Because of how large the switch construct would have been, I created a new 
> function `types::isDerivedFromC` together with the other functions. These 
> commonly have default-cases so compilers would not warn when `Types.def` is 
> amended, but `isDerivedFromC` can be found between other functions that would 
> need to be updated.

Thank you, I think that turned out cleanly!




Comment at: clang/lib/Driver/Types.cpp:173
+  case TY_ObjCXX:
+  case TY_RenderScript:
+  case TY_PP_CHeader:

Heh, I had to go look this one up. TIL... :-D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104601

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


[PATCH] D106285: [Analyzer][solver] Fix inconsistent equivalence class data

2021-07-23 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D106285#2899545 , @vsavchenko 
wrote:

> Oh, I didn't accept it?  Sorry!

No problem, thanks for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106285

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


[PATCH] D106394: [clang][pp] adds '#pragma include_instead'

2021-07-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:304
+
+def pp_pragma_include_instead_not_sysheader : Error<
+  "'#pragma clang include_instead' cannot be used outside of system headers">,

Can you prefix the diagnostic identifiers with `err_`? We're not super 
consistent in this file, but it's helpful when reading the use of the 
diagnostic to know whether it's an error or not.



Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:303
   InGroup>;
+def pp_pragma_include_instead_not_sysheader : Warning<
+  "'#pragma include_instead' ignored outside of system headers">,

cjdb wrote:
> aaron.ballman wrote:
> > Design-wise, do we want this one to be an error instead of a warning? I 
> > don't have strong feelings one way or the other, but making it an error 
> > ensures no one finds creative ways to use it outside of a system header by 
> > accident (and we can relax the restriction later if there are reasons to do 
> > so).
> I'd prefer it to be an error, but I wasn't confident that would be accepted 
> (same applies to all your comments re warn vs err). If you're game, I'll make 
> the change.
I would prefer errors here -- the goal of this feature is to prevent 
programmers from doing things we know are going to be a maintenance burden, so 
I think we should be restrictive here. If users find the restrictions too 
onerous and have a good reason for us to relax them, we can definitely consider 
it then.



Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:306
+  InGroup,
+  ShowInSystemHeader;
+def pp_pragma_include_instead_unexpected_token : Warning<

cjdb wrote:
> aaron.ballman wrote:
> > O.o... why do we need to show this one in system headers if the diagnostic 
> > can only trigger outside of a system header?
> Mostly because I'm scared that there's some toggle that would accidentally 
> make the diagnostic observable in a system header and wanted to test the 
> behaviour.
You can remove the `ShowInSystemHeader` bits now because these are all errors 
(at least, I'm 99% sure you can remove it).



Comment at: clang/include/clang/Basic/DiagnosticLexKinds.td:307-310
+def pp_pragma_include_instead_unexpected_token : Warning<
+  "'#pragma include_instead' expects '%0' as its next token; got '%1' 
instead">,
+  InGroup,
+  ShowInSystemHeader;

cjdb wrote:
> aaron.ballman wrote:
> > No need for a new warning -- I think we can use existing diagnostics for 
> > this (like `err_pp_expects_filename`). Also, I think syntax issues should 
> > be diagnosed as an error instead of a warning -- we expect a particular 
> > syntactic form and it's reasonable for us to enforce that users get it 
> > right.
> Hmm... the syntax is `#pragma clang include_instead(header)`. This is 
> diagnosing the lack of `(` or `)`, not a missing filename. Perhaps there's 
> already a diagnostic for that?
There is: `diag::err_expected` (and some related ones in 
DiagnosticCommonKinds.td).



Comment at: clang/lib/Lex/PPLexerChange.cpp:316
+const StringRef Filename = Include.getKey();
+const auto &IncludeInfo = Include.getValue();
+const HeaderFileInfo &Info = HeaderInfo.getFileInfo(IncludeInfo.File);

cjdb wrote:
> aaron.ballman wrote:
> > Please spell out the type.
> The type's currently a private type (that was by design). Do you want me to 
> make it a public type or pull it out into `namespace clang`?
`PreprocessorLexer` already friends `Preprocessor`, so you can name it directly 
here (though please change the local variable name to be something different 
from the type name while you're at it).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106394

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


[clang] 44fa31f - [Analyzer][solver] Fix inconsistent equivalence class data

2021-07-23 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2021-07-23T14:25:32+02:00
New Revision: 44fa31fa6da0c573ed972ec1d932c4ca3fb52f8f

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

LOG: [Analyzer][solver] Fix inconsistent equivalence class data

https://bugs.llvm.org/show_bug.cgi?id=51109

When we merged two classes, `*this` became an obsolete representation of
the new `State`. This is b/c the member relations had changed during the
previous merge of another member of the same class in a way that `*this`
had no longer any members. (`mergeImpl` might keep the member relations
to `Other` and could dissolve `*this`.)

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

Added: 
clang/test/Analysis/solver-sym-simplification-no-crash2.c

Modified: 
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 9f64be7a5309..de86fc685b07 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -600,9 +600,10 @@ class EquivalenceClass : public llvm::FoldingSetNode {
   areEqual(ProgramStateRef State, SymbolRef First, SymbolRef Second);
 
   /// Iterate over all symbols and try to simplify them.
-  LLVM_NODISCARD ProgramStateRef simplify(SValBuilder &SVB,
-  RangeSet::Factory &F,
-  ProgramStateRef State);
+  LLVM_NODISCARD static inline ProgramStateRef simplify(SValBuilder &SVB,
+RangeSet::Factory &F,
+ProgramStateRef State,
+EquivalenceClass 
Class);
 
   void dumpToStream(ProgramStateRef State, raw_ostream &os) const;
   LLVM_DUMP_METHOD void dump(ProgramStateRef State) const {
@@ -1696,7 +1697,7 @@ bool ConstraintAssignor::assignSymExprToConst(const 
SymExpr *Sym,
   ClassMembersTy Members = State->get();
   for (std::pair ClassToSymbolSet : Members) {
 EquivalenceClass Class = ClassToSymbolSet.first;
-State = Class.simplify(Builder, RangeFactory, State);
+State = EquivalenceClass::simplify(Builder, RangeFactory, State, Class);
 if (!State)
   return false;
 SimplifiedClasses.insert(Class);
@@ -1710,7 +1711,7 @@ bool ConstraintAssignor::assignSymExprToConst(const 
SymExpr *Sym,
 EquivalenceClass Class = ClassConstraint.first;
 if (SimplifiedClasses.count(Class)) // Already simplified.
   continue;
-State = Class.simplify(Builder, RangeFactory, State);
+State = EquivalenceClass::simplify(Builder, RangeFactory, State, Class);
 if (!State)
   return false;
   }
@@ -2090,18 +2091,17 @@ inline Optional 
EquivalenceClass::areEqual(ProgramStateRef State,
 // class to this class. This way, we simplify not just the symbols but the
 // classes as well: we strive to keep the number of the classes to be the
 // absolute minimum.
-LLVM_NODISCARD ProgramStateRef EquivalenceClass::simplify(
-SValBuilder &SVB, RangeSet::Factory &F, ProgramStateRef State) {
-  SymbolSet ClassMembers = getClassMembers(State);
+LLVM_NODISCARD ProgramStateRef
+EquivalenceClass::simplify(SValBuilder &SVB, RangeSet::Factory &F,
+   ProgramStateRef State, EquivalenceClass Class) {
+  SymbolSet ClassMembers = Class.getClassMembers(State);
   for (const SymbolRef &MemberSym : ClassMembers) {
 SymbolRef SimplifiedMemberSym = ento::simplify(State, MemberSym);
 if (SimplifiedMemberSym && MemberSym != SimplifiedMemberSym) {
-  EquivalenceClass ClassOfSimplifiedSym =
-  EquivalenceClass::find(State, SimplifiedMemberSym);
   // The simplified symbol should be the member of the original Class,
   // however, it might be in another existing class at the moment. We
   // have to merge these classes.
-  State = merge(F, State, ClassOfSimplifiedSym);
+  State = merge(F, State, MemberSym, SimplifiedMemberSym);
   if (!State)
 return nullptr;
 }

diff  --git a/clang/test/Analysis/solver-sym-simplification-no-crash2.c 
b/clang/test/Analysis/solver-sym-simplification-no-crash2.c
new file mode 100644
index ..7963c1462e32
--- /dev/null
+++ b/clang/test/Analysis/solver-sym-simplification-no-crash2.c
@@ -0,0 +1,23 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify
+
+// Here, we test that symbol simplification in the solver does not produce any
+// crashes.
+// https://bugs.llvm.org/show_bug.cgi?id=51109
+
+// expected-no-diagnostics
+
+int a, b, c, d;
+void f(

[PATCH] D106285: [Analyzer][solver] Fix inconsistent equivalence class data

2021-07-23 Thread Gabor Marton 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 rG44fa31fa6da0: [Analyzer][solver] Fix inconsistent 
equivalence class data (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106285

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/solver-sym-simplification-no-crash2.c


Index: clang/test/Analysis/solver-sym-simplification-no-crash2.c
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-no-crash2.c
@@ -0,0 +1,23 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify
+
+// Here, we test that symbol simplification in the solver does not produce any
+// crashes.
+// https://bugs.llvm.org/show_bug.cgi?id=51109
+
+// expected-no-diagnostics
+
+int a, b, c, d;
+void f() {
+  a = -1;
+  d = b * a;
+  a = d / c;
+  if (a < 7 / b)
+return;
+  if (d *a / c < 7 / b)
+return;
+  if (b == 1 && c == -1)
+return;
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -600,9 +600,10 @@
   areEqual(ProgramStateRef State, SymbolRef First, SymbolRef Second);
 
   /// Iterate over all symbols and try to simplify them.
-  LLVM_NODISCARD ProgramStateRef simplify(SValBuilder &SVB,
-  RangeSet::Factory &F,
-  ProgramStateRef State);
+  LLVM_NODISCARD static inline ProgramStateRef simplify(SValBuilder &SVB,
+RangeSet::Factory &F,
+ProgramStateRef State,
+EquivalenceClass 
Class);
 
   void dumpToStream(ProgramStateRef State, raw_ostream &os) const;
   LLVM_DUMP_METHOD void dump(ProgramStateRef State) const {
@@ -1696,7 +1697,7 @@
   ClassMembersTy Members = State->get();
   for (std::pair ClassToSymbolSet : Members) {
 EquivalenceClass Class = ClassToSymbolSet.first;
-State = Class.simplify(Builder, RangeFactory, State);
+State = EquivalenceClass::simplify(Builder, RangeFactory, State, Class);
 if (!State)
   return false;
 SimplifiedClasses.insert(Class);
@@ -1710,7 +1711,7 @@
 EquivalenceClass Class = ClassConstraint.first;
 if (SimplifiedClasses.count(Class)) // Already simplified.
   continue;
-State = Class.simplify(Builder, RangeFactory, State);
+State = EquivalenceClass::simplify(Builder, RangeFactory, State, Class);
 if (!State)
   return false;
   }
@@ -2090,18 +2091,17 @@
 // class to this class. This way, we simplify not just the symbols but the
 // classes as well: we strive to keep the number of the classes to be the
 // absolute minimum.
-LLVM_NODISCARD ProgramStateRef EquivalenceClass::simplify(
-SValBuilder &SVB, RangeSet::Factory &F, ProgramStateRef State) {
-  SymbolSet ClassMembers = getClassMembers(State);
+LLVM_NODISCARD ProgramStateRef
+EquivalenceClass::simplify(SValBuilder &SVB, RangeSet::Factory &F,
+   ProgramStateRef State, EquivalenceClass Class) {
+  SymbolSet ClassMembers = Class.getClassMembers(State);
   for (const SymbolRef &MemberSym : ClassMembers) {
 SymbolRef SimplifiedMemberSym = ento::simplify(State, MemberSym);
 if (SimplifiedMemberSym && MemberSym != SimplifiedMemberSym) {
-  EquivalenceClass ClassOfSimplifiedSym =
-  EquivalenceClass::find(State, SimplifiedMemberSym);
   // The simplified symbol should be the member of the original Class,
   // however, it might be in another existing class at the moment. We
   // have to merge these classes.
-  State = merge(F, State, ClassOfSimplifiedSym);
+  State = merge(F, State, MemberSym, SimplifiedMemberSym);
   if (!State)
 return nullptr;
 }


Index: clang/test/Analysis/solver-sym-simplification-no-crash2.c
===
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-no-crash2.c
@@ -0,0 +1,23 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify
+
+// Here, we test that symbol simplification in the solver does not produce any
+// crashes.
+// https://bugs.llvm.org/show_bug.cgi?id=51109
+
+// expected-no-diagnostics
+
+int a, b, c, d;
+void f() {
+  a = -1;
+  d = b * a;
+  a = d / c;
+  if (a < 7 / b)
+return;
+  if (d *a / c < 7 / b)
+return;
+  if (b == 1 && c == -1)
+return;
+}
Index

[PATCH] D106654: [clangd] Avoid range-loop init-list lifetime subtleties.

2021-07-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

The original code appears to be OK per the spec, but we've had 3 reports of
crashes with certain unofficial builds of clangd that look a lot like old
compilers (GCC 5.4?) getting lifetime rules wrong.

Fixes https://github.com/clangd/clangd/issues/800


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106654

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


Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -285,9 +285,12 @@
 /*ErrorMsg*/ std::string &)>
 Parser;
   };
-  for (const auto &Entry : {CDBFile{&CompileCommandsJson, parseJSON},
-CDBFile{&BuildCompileCommandsJson, parseJSON},
-CDBFile{&CompileFlagsTxt, parseFixed}}) {
+  CDBFile Files[] = {
+  {&CompileCommandsJson, parseJSON},
+  {&BuildCompileCommandsJson, parseJSON},
+  {&CompileFlagsTxt, parseFixed},
+  };
+  for (const auto &Entry : Files) {
 bool Active = ActiveCachedFile == Entry.File;
 auto Loaded = Entry.File->load(FS, Active);
 switch (Loaded.Result) {


Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -285,9 +285,12 @@
 /*ErrorMsg*/ std::string &)>
 Parser;
   };
-  for (const auto &Entry : {CDBFile{&CompileCommandsJson, parseJSON},
-CDBFile{&BuildCompileCommandsJson, parseJSON},
-CDBFile{&CompileFlagsTxt, parseFixed}}) {
+  CDBFile Files[] = {
+  {&CompileCommandsJson, parseJSON},
+  {&BuildCompileCommandsJson, parseJSON},
+  {&CompileFlagsTxt, parseFixed},
+  };
+  for (const auto &Entry : Files) {
 bool Active = ActiveCachedFile == Entry.File;
 auto Loaded = Entry.File->load(FS, Active);
 switch (Loaded.Result) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106527: [clangd] Canonicalize compile flags before applying edits

2021-07-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

Still LG




Comment at: clang-tools-extra/clangd/CompileCommands.cpp:250
 auto It = llvm::find(Cmd, "--");
 for (std::string &Arg : ToAppend)
   Cmd.insert(It++, std::move(Arg));

hmm, why isn't this `Cmd.insert(It, ToAppend.begin(), ToAppend.end())` instead 
of the loop, to avoid shuffling the tail elements?

Or in fact `Cmd.insert(It, std::make_move_iterator(ToAppend.begin()), 
std::make_move_iterator(ToAppend.end()));`?



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:256
+bool FollowSymlink =
+!ArgList.hasArgNoClaim(driver::options::OPT_no_canonical_prefixes);
 Cmd.front() =

you reverted the others to Has but keps the ArgList reference here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106527

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


[PATCH] D106375: Thread safety analysis: Mock getter for private mutexes can be undefined

2021-07-23 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D106375#2896484 , @aaron.ballman 
wrote:

> LGTM! It took me a minute to convince myself it wasn't really an ODR use (the 
> argument goes through the usual expression evaluation parsing and sema bits), 
> but because the arguments to these attributes never wind up being used in 
> codegen, they're not really a use as far as the ODR is concerned.

Right, the standard doesn't know about our attributes. My reasoning was that 
they are basically an unevaluated context like a `sizeof` expression.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106375

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


[clang] 0e64a52 - Thread safety analysis: Mock getter for private mutexes can be undefined

2021-07-23 Thread Aaron Puchert via cfe-commits

Author: Aaron Puchert
Date: 2021-07-23T14:46:02+02:00
New Revision: 0e64a525c12a0822683d3bdc51b6294b5265f860

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

LOG: Thread safety analysis: Mock getter for private mutexes can be undefined

Usage in an annotation is no odr-use, so I think there needs to be no
definition. Upside is that in practice one will get linker errors if it
is actually odr-used instead of calling a function that returns 0.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ThreadSafetyAnalysis.rst

Removed: 




diff  --git a/clang/docs/ThreadSafetyAnalysis.rst 
b/clang/docs/ThreadSafetyAnalysis.rst
index 651229f01d03..69046ba18b8c 100644
--- a/clang/docs/ThreadSafetyAnalysis.rst
+++ b/clang/docs/ThreadSafetyAnalysis.rst
@@ -640,8 +640,8 @@ mutex.  For example:
 Mutex mu;
 
   public:
-// For thread safety analysis only.  Does not actually return mu.
-Mutex* getMu() RETURN_CAPABILITY(mu) { return 0; }
+// For thread safety analysis only.  Does not need to be defined.
+Mutex* getMu() RETURN_CAPABILITY(mu);
 
 void doSomething() REQUIRES(mu);
   };



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


[PATCH] D106375: Thread safety analysis: Mock getter for private mutexes can be undefined

2021-07-23 Thread Aaron Puchert 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 rG0e64a525c12a: Thread safety analysis: Mock getter for 
private mutexes can be undefined (authored by aaronpuchert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106375

Files:
  clang/docs/ThreadSafetyAnalysis.rst


Index: clang/docs/ThreadSafetyAnalysis.rst
===
--- clang/docs/ThreadSafetyAnalysis.rst
+++ clang/docs/ThreadSafetyAnalysis.rst
@@ -640,8 +640,8 @@
 Mutex mu;
 
   public:
-// For thread safety analysis only.  Does not actually return mu.
-Mutex* getMu() RETURN_CAPABILITY(mu) { return 0; }
+// For thread safety analysis only.  Does not need to be defined.
+Mutex* getMu() RETURN_CAPABILITY(mu);
 
 void doSomething() REQUIRES(mu);
   };


Index: clang/docs/ThreadSafetyAnalysis.rst
===
--- clang/docs/ThreadSafetyAnalysis.rst
+++ clang/docs/ThreadSafetyAnalysis.rst
@@ -640,8 +640,8 @@
 Mutex mu;
 
   public:
-// For thread safety analysis only.  Does not actually return mu.
-Mutex* getMu() RETURN_CAPABILITY(mu) { return 0; }
+// For thread safety analysis only.  Does not need to be defined.
+Mutex* getMu() RETURN_CAPABILITY(mu);
 
 void doSomething() REQUIRES(mu);
   };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105904: [clangd] Support `#pragma mark` in the outline

2021-07-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/CollectMacros.cpp:23
+  bool IsGroup = false;
+  // "-\s+" or "" after an initial trim. The former is
+  // considered a group, the latter just a mark. We need to include a name

Interpretation of the marks belongs with the rest of the DocumentSymbol code 
too, I think - until we have some evidence that this is structure we want to 
share.



Comment at: clang-tools-extra/clangd/CollectMacros.cpp:67
+
+DocumentSymbol PragmaMark::toSymbol(const SourceManager &SM) const {
+  DocumentSymbol Sym;

This code belongs with the rest of the DocumentSymbol code



Comment at: clang-tools-extra/clangd/CollectMacros.h:106
+struct PragmaMark {
+  SourceLocation Loc;
+  std::string Text;

Line number is enough, right?
Column is not interesting, and pragma marks expanded from macros are not 
possible (and wouldn't be in the main file for our purposes)



Comment at: clang-tools-extra/clangd/CollectMacros.h:115
+std::unique_ptr
+collectPragmaMarksCallback(const SourceManager &, std::vector 
&Out);
+

this should be tested in CollectMacrosTests.cpp or ParsedASTTests.cpp
(It's fine to test via TestTU though, and this will let you test both the 
preamble and non-preamble case)



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:535
+/// by range.
+std::vector mergePragmas(std::vector &Syms,
+ std::vector 
&Pragmas,

FWIW the flow control/how we make progress seem hard to follow here to me.

In particular I think I'm struggling with the statefulness of "is there an open 
mark group".

Possible simplifications:
 - define a dummy root symbol, which seems clearer than the vector + 
range
 - avoid reverse-sorting the list of pragma symbols, and just consume from the 
front of an ArrayRef instead
 - make the outer loop over pragmas, rather than symbols. It would first check 
if the pragma belongs directly here or not, and if so, loop over symbols to 
work out which should become children. This seems very likely to be efficient 
enough in practice (few pragmas, or most children are grouped into pragmas)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105904

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


[PATCH] D106375: Thread safety analysis: Mock getter for private mutexes can be undefined

2021-07-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D106375#2899827 , @aaronpuchert 
wrote:

> In D106375#2896484 , @aaron.ballman 
> wrote:
>
>> LGTM! It took me a minute to convince myself it wasn't really an ODR use 
>> (the argument goes through the usual expression evaluation parsing and sema 
>> bits), but because the arguments to these attributes never wind up being 
>> used in codegen, they're not really a use as far as the ODR is concerned.
>
> Right, the standard doesn't know about our attributes. My reasoning was that 
> they are basically an unevaluated context like a `sizeof` expression.

Nonstandard attributes are wholly up to the implementation for what their 
semantic effects are, so they can be unevaluated *or* constant evaluated *or* 
runtime evaluated depending on need. I mostly just needed to make sure we 
weren't accidentally marking these uses as ODR uses, and happily, we weren't.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106375

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


[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-07-23 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:215-236
+const VarDecl *findStdStreamDecl(StringRef StdName, CheckerContext &C) {
+  ASTContext &ACtx = C.getASTContext();
+
+  IdentifierInfo &II = ACtx.Idents.get(StdName);
+  auto LookupRes = ACtx.getTranslationUnitDecl()->lookup(&II);
+  QualType FILEType = ACtx.getFILEType();
+  if (!FILEType.isNull())

Would it be possible to reuse (i.e put in a common place) the 
StdLibraryFunctionChecker's `lookupTy`? That also handles the cases when 
FILEType is null or when we have a `typedef struct FILE FILE;`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106644

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


[PATCH] D106583: [clang] SIGSEGV at DeduceTemplateArgumentsByTypeMatch

2021-07-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a subscriber: rjmccall.
erichkeane added a comment.
This revision is now accepted and ready to land.

That test is fine, though the errors are quite jarring!  I'm surprised how 
confused we get!

This looks acceptable to me, but I'm not sufficiently an expert in this code to 
accept right away.  Please give @rsmith (or perhaps @rjmccall ) at least 24 hrs 
after this to take a look before pushing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106583

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


[PATCH] D106562: [clangd] Get rid of arg adjusters in CommandMangler

2021-07-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

This raises the question "is it safe to move functionality from CommandMangler 
to buildCompilerInvocation for convenience, are they always called on the same 
codepaths?"

I think from our brief investigation the answer is yes, but:

- this expectation should probably be documented on CommandMangler and/or 
buildCompilerInvocation
- *neither* of them are called when background indexing, which should probably 
be a fixme on the static indexer




Comment at: clang-tools-extra/clangd/CompileCommands.cpp:225
+auto It = llvm::find(Cmd, "--");
+for (std::string &Arg : ToAppend)
+  Cmd.insert(It++, std::move(Arg));

oops, might have left this comment on the wrong patch

use range insert to save shuffling the tail over and over and 
std::make_move_iterator() to avoid copies?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106562

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


[PATCH] D106315: [HIP] Preserve ASAN bitcode library functions

2021-07-23 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D106315#2898536 , @tra wrote:

> LGTM in general.
>
> One question -- does it have to be a function calling other functions just 
> for the sake of preserving them?
> Can it be a flat array of pointers to the functions you need to keep around?

Yes that's possible. However that would require FE to know these functions and 
declare them, whereas the current approach leave the concern to the device 
library.


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

https://reviews.llvm.org/D106315

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


[PATCH] D106639: [clangd] Adjust compile flags to contain only the requested file as input

2021-07-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:216
+for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT)) {
+  // Driver name is also considered an input, don't strip that away.
+  if (Input->getIndex() == 0)

Is this because we're not meant to be parsing argv0?
Maybe check that and fix that here if so, or leave a FIXME if we don't want to 
check now?



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:226
+   [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx); });
+Cmd.insert(Cmd.end(), {"--", File.str()});
   }

nit: Fairly sure this is copying File twice, init-lists are dumb. maybe just 
two push_backs instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106639

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


[PATCH] D106654: [clangd] Avoid range-loop init-list lifetime subtleties.

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks! it is unfortunate that history won't remember what an adventure it was 
to figure out the issue :D




Comment at: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp:288
   };
-  for (const auto &Entry : {CDBFile{&CompileCommandsJson, parseJSON},
-CDBFile{&BuildCompileCommandsJson, parseJSON},
-CDBFile{&CompileFlagsTxt, parseFixed}}) {
+  CDBFile Files[] = {
+  {&CompileCommandsJson, parseJSON},

nit: I'd make it `static const` just to make sure they are not going away this 
time + it will save up some stack space.

nit: Maybe also get rid of the struct's name ? (`static const struct { ... } 
Files[] = { ... };`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106654

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


[clang-tools-extra] a0987e3 - [clangd] Improve performance of dex by 45-60%

2021-07-23 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2021-07-23T15:28:35+02:00
New Revision: a0987e350ccce4fb9c3cbaf56732be1def5f810f

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

LOG: [clangd] Improve performance of dex by 45-60%

Take full advantage of AND's iterator children size estimation: use early reset
in sync() and prevent large overhead. The idea is that the children at the
beginning of the list are smaller and cheaper to advance. Very large children
negate the effect of this performance optimisation and hence should be
advanced only when absolutely necessary. By reducing the number of large
iterators' updates, we increase the performance by a large margin.

This change was tested on a comprehensive query dataset. The performance
boost increases with the average length of the query, on small queries it is
close to 45% but the longer they go the closer it gets to 60% and beyond.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/index/dex/Iterator.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/dex/Iterator.cpp 
b/clang-tools-extra/clangd/index/dex/Iterator.cpp
index 77e8175ca4b6..8b37403ff406 100644
--- a/clang-tools-extra/clangd/index/dex/Iterator.cpp
+++ b/clang-tools-extra/clangd/index/dex/Iterator.cpp
@@ -104,11 +104,19 @@ class AndIterator : public Iterator {
 // In this case, just terminate the process.
 if (ReachedEnd)
   return;
+// Cache the result so that peek() is not called again as it may be
+// quite expensive in AND with large subtrees.
+auto Candidate = Child->peek();
 // If any child goes beyond given ID (i.e. ID is not the common item),
 // all children should be advanced to the next common item.
-if (Child->peek() > SyncID) {
-  SyncID = Child->peek();
+if (Candidate > SyncID) {
+  SyncID = Candidate;
   NeedsAdvance = true;
+  // Reset and try to sync again. Sync starts with the first child as
+  // this is the cheapest (smallest size estimate). This way advanceTo
+  // is called on the large posting lists once the sync point is very
+  // likely.
+  break;
 }
   }
 } while (NeedsAdvance);



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


[PATCH] D106528: [clangd] Improve performance of dex by 45-60%

2021-07-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa0987e350ccc: [clangd] Improve performance of dex by 45-60% 
(authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106528

Files:
  clang-tools-extra/clangd/index/dex/Iterator.cpp


Index: clang-tools-extra/clangd/index/dex/Iterator.cpp
===
--- clang-tools-extra/clangd/index/dex/Iterator.cpp
+++ clang-tools-extra/clangd/index/dex/Iterator.cpp
@@ -104,11 +104,19 @@
 // In this case, just terminate the process.
 if (ReachedEnd)
   return;
+// Cache the result so that peek() is not called again as it may be
+// quite expensive in AND with large subtrees.
+auto Candidate = Child->peek();
 // If any child goes beyond given ID (i.e. ID is not the common item),
 // all children should be advanced to the next common item.
-if (Child->peek() > SyncID) {
-  SyncID = Child->peek();
+if (Candidate > SyncID) {
+  SyncID = Candidate;
   NeedsAdvance = true;
+  // Reset and try to sync again. Sync starts with the first child as
+  // this is the cheapest (smallest size estimate). This way advanceTo
+  // is called on the large posting lists once the sync point is very
+  // likely.
+  break;
 }
   }
 } while (NeedsAdvance);


Index: clang-tools-extra/clangd/index/dex/Iterator.cpp
===
--- clang-tools-extra/clangd/index/dex/Iterator.cpp
+++ clang-tools-extra/clangd/index/dex/Iterator.cpp
@@ -104,11 +104,19 @@
 // In this case, just terminate the process.
 if (ReachedEnd)
   return;
+// Cache the result so that peek() is not called again as it may be
+// quite expensive in AND with large subtrees.
+auto Candidate = Child->peek();
 // If any child goes beyond given ID (i.e. ID is not the common item),
 // all children should be advanced to the next common item.
-if (Child->peek() > SyncID) {
-  SyncID = Child->peek();
+if (Candidate > SyncID) {
+  SyncID = Candidate;
   NeedsAdvance = true;
+  // Reset and try to sync again. Sync starts with the first child as
+  // this is the cheapest (smallest size estimate). This way advanceTo
+  // is called on the large posting lists once the sync point is very
+  // likely.
+  break;
 }
   }
 } while (NeedsAdvance);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106654: [clangd] Avoid range-loop init-list lifetime subtleties.

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp:288
   };
-  for (const auto &Entry : {CDBFile{&CompileCommandsJson, parseJSON},
-CDBFile{&BuildCompileCommandsJson, parseJSON},
-CDBFile{&CompileFlagsTxt, parseFixed}}) {
+  CDBFile Files[] = {
+  {&CompileCommandsJson, parseJSON},

kadircet wrote:
> nit: I'd make it `static const` just to make sure they are not going away 
> this time + it will save up some stack space.
> 
> nit: Maybe also get rid of the struct's name ? (`static const struct { ... } 
> Files[] = { ... };`)
as discussed, `CachedFile` entries are actually pointers to members, so NVM the 
`static`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106654

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


[PATCH] D95159: [ASTReader] Allow controlling separately whether validation should be disabled for a PCH vs a module file

2021-07-23 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

@bnbarham 
I think you mean a patch like this, is it right?  I'd like to fix the test in a 
pre-commit and then re-push my patch

   git diff
  diff --git a/clang/test/Index/preamble-reparse-changed-module.m 
b/clang/test/Index/preamble-reparse-changed-module.m
  index 1c63e802ce0c..fc336c6e0670 100644
  --- a/clang/test/Index/preamble-reparse-changed-module.m
  +++ b/clang/test/Index/preamble-reparse-changed-module.m
  @@ -1,6 +1,7 @@
   // REQUIRES: shell
  
  -// RUN: mkdir -p %t/mod
  +// RUN: rm -rf %t
  +// RUN: mkdir %t/mod
   // RUN: touch %t/empty.h
   // RUN: cp %S/Inputs/preamble-reparse-changed-module/module.modulemap %t/mod
   // RUN: cp %S/Inputs/preamble-reparse-changed-module/head.h %t/mod


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95159

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


[clang-tools-extra] 253b814 - [clangd] Avoid range-loop init-list lifetime subtleties.

2021-07-23 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-07-23T15:33:04+02:00
New Revision: 253b8145dedbe8d10792f44b4af7f52dbecd527f

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

LOG: [clangd] Avoid range-loop init-list lifetime subtleties.

The original code appears to be OK per the spec, but we've had 3 reports of
crashes with certain unofficial builds of clangd that look a lot like old
compilers (GCC 5.4?) getting lifetime rules wrong.

Fixes https://github.com/clangd/clangd/issues/800

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

Added: 


Modified: 
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index d830190bfdfd..73f19abaeb9d 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -276,7 +276,7 @@ bool 
DirectoryBasedGlobalCompilationDatabase::DirectoryCache::load(
   // For these, we know the files they read and cache their metadata so we can
   // cheaply validate whether they've changed, and hot-reload if they have.
   // (As a bonus, these are also VFS-clean)!
-  struct CDBFile {
+  struct {
 CachedFile *File;
 // Wrapper for {Fixed,JSON}CompilationDatabase::loadFromBuffer.
 llvm::function_ref(
@@ -284,10 +284,12 @@ bool 
DirectoryBasedGlobalCompilationDatabase::DirectoryCache::load(
 /*Data*/ llvm::StringRef,
 /*ErrorMsg*/ std::string &)>
 Parser;
+  } Files[] = {
+  {&CompileCommandsJson, parseJSON},
+  {&BuildCompileCommandsJson, parseJSON},
+  {&CompileFlagsTxt, parseFixed},
   };
-  for (const auto &Entry : {CDBFile{&CompileCommandsJson, parseJSON},
-CDBFile{&BuildCompileCommandsJson, parseJSON},
-CDBFile{&CompileFlagsTxt, parseFixed}}) {
+  for (const auto &Entry : Files) {
 bool Active = ActiveCachedFile == Entry.File;
 auto Loaded = Entry.File->load(FS, Active);
 switch (Loaded.Result) {



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


[PATCH] D106654: [clangd] Avoid range-loop init-list lifetime subtleties.

2021-07-23 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG253b8145dedb: [clangd] Avoid range-loop init-list lifetime 
subtleties. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D106654?vs=361165&id=361177#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106654

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


Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -276,7 +276,7 @@
   // For these, we know the files they read and cache their metadata so we can
   // cheaply validate whether they've changed, and hot-reload if they have.
   // (As a bonus, these are also VFS-clean)!
-  struct CDBFile {
+  struct {
 CachedFile *File;
 // Wrapper for {Fixed,JSON}CompilationDatabase::loadFromBuffer.
 llvm::function_ref(
@@ -284,10 +284,12 @@
 /*Data*/ llvm::StringRef,
 /*ErrorMsg*/ std::string &)>
 Parser;
+  } Files[] = {
+  {&CompileCommandsJson, parseJSON},
+  {&BuildCompileCommandsJson, parseJSON},
+  {&CompileFlagsTxt, parseFixed},
   };
-  for (const auto &Entry : {CDBFile{&CompileCommandsJson, parseJSON},
-CDBFile{&BuildCompileCommandsJson, parseJSON},
-CDBFile{&CompileFlagsTxt, parseFixed}}) {
+  for (const auto &Entry : Files) {
 bool Active = ActiveCachedFile == Entry.File;
 auto Loaded = Entry.File->load(FS, Active);
 switch (Loaded.Result) {


Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -276,7 +276,7 @@
   // For these, we know the files they read and cache their metadata so we can
   // cheaply validate whether they've changed, and hot-reload if they have.
   // (As a bonus, these are also VFS-clean)!
-  struct CDBFile {
+  struct {
 CachedFile *File;
 // Wrapper for {Fixed,JSON}CompilationDatabase::loadFromBuffer.
 llvm::function_ref(
@@ -284,10 +284,12 @@
 /*Data*/ llvm::StringRef,
 /*ErrorMsg*/ std::string &)>
 Parser;
+  } Files[] = {
+  {&CompileCommandsJson, parseJSON},
+  {&BuildCompileCommandsJson, parseJSON},
+  {&CompileFlagsTxt, parseFixed},
   };
-  for (const auto &Entry : {CDBFile{&CompileCommandsJson, parseJSON},
-CDBFile{&BuildCompileCommandsJson, parseJSON},
-CDBFile{&CompileFlagsTxt, parseFixed}}) {
+  for (const auto &Entry : Files) {
 bool Active = ActiveCachedFile == Entry.File;
 auto Loaded = Entry.File->load(FS, Active);
 switch (Loaded.Result) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106654: [clangd] Avoid range-loop init-list lifetime subtleties.

2021-07-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp:288
   };
-  for (const auto &Entry : {CDBFile{&CompileCommandsJson, parseJSON},
-CDBFile{&BuildCompileCommandsJson, parseJSON},
-CDBFile{&CompileFlagsTxt, parseFixed}}) {
+  CDBFile Files[] = {
+  {&CompileCommandsJson, parseJSON},

kadircet wrote:
> kadircet wrote:
> > nit: I'd make it `static const` just to make sure they are not going away 
> > this time + it will save up some stack space.
> > 
> > nit: Maybe also get rid of the struct's name ? (`static const struct { ... 
> > } Files[] = { ... };`)
> as discussed, `CachedFile` entries are actually pointers to members, so NVM 
> the `static`.
There are pointers to members in here! The fact that `static const` even 
compiles is a massive footgun :-(
We should write a clang-tidy check for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106654

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


[PATCH] D95159: [ASTReader] Allow controlling separately whether validation should be disabled for a PCH vs a module file

2021-07-23 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

Whoops, shouldn't mess with the mkdir line

diff --git a/clang/test/Index/preamble-reparse-changed-module.m 
b/clang/test/Index/preamble-reparse-changed-module.m
index 1c63e802ce0c..349ed0db27d0 100644

- a/clang/test/Index/preamble-reparse-changed-module.m

+++ b/clang/test/Index/preamble-reparse-changed-module.m
@@ -1,5 +1,6 @@
 // REQUIRES: shell

+// RUN: rm -rf %t
 // RUN: mkdir -p %t/mod
 // RUN: touch %t/empty.h
 // RUN: cp %S/Inputs/preamble-reparse-changed-module/module.modulemap %t/mod


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95159

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


[PATCH] D106645: [clangd] Tweak constructor of dex AndIterator for performance.

2021-07-23 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

I am extremely confused, but this is actually 4.5% slower than the updated 
(improved performance with D106528 ) 
baseline. Now, this actually works (2.2-2.5% faster):

  ❯ git diff
  diff --git a/clang-tools-extra/clangd/index/dex/Iterator.cpp 
b/clang-tools-extra/clangd/index/dex/Iterator.cpp
  index 8b37403ff406..ea90e35c32a4 100644
  --- a/clang-tools-extra/clangd/index/dex/Iterator.cpp
  +++ b/clang-tools-extra/clangd/index/dex/Iterator.cpp
  @@ -29,8 +29,8 @@ public:
   assert(!Children.empty() && "AND iterator should have at least one 
child.");
   // Establish invariants.
   for (const auto &Child : Children)
  -  ReachedEnd |= Child->reachedEnd();
  -sync();
  +  if ((ReachedEnd |= Child->reachedEnd()))
  +return;
   // When children are sorted by the estimateSize(), sync() calls are more
   // effective. Each sync() starts with the first child and makes sure all
   // children point to the same element. If any child is "above" the 
previous
  @@ -42,6 +42,7 @@ public:
   const std::unique_ptr &RHS) {
 return LHS->estimateSize() < RHS->estimateSize();
   });
  +sync();
 }
  
 bool reachedEnd() const override { return ReachedEnd; }

Some other "obvious" optimizatinons, e.g.

  ❯ git diff
  diff --git a/clang-tools-extra/clangd/index/dex/Iterator.cpp 
b/clang-tools-extra/clangd/index/dex/Iterator.cpp
  index 8b37403ff406..d0f3bd1597ac 100644
  --- a/clang-tools-extra/clangd/index/dex/Iterator.cpp
  +++ b/clang-tools-extra/clangd/index/dex/Iterator.cpp
  @@ -89,8 +89,7 @@ private:
 /// Restores class invariants: each child will point to the same element 
after
 /// sync.
 void sync() {
  -ReachedEnd |= Children.front()->reachedEnd();
  -if (ReachedEnd)
  +if (ReachedEnd || (ReachedEnd |= Children.front()->reachedEnd()))
 return;
   auto SyncID = Children.front()->peek();
   // Indicates whether any child needs to be advanced to new SyncID.

Surprisingly slow down the queries, too, in an insignificant manner.

I think, at this point it's really the matter of assembly output in an 
extremely hot loop.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106645

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


[PATCH] D106562: [clangd] Get rid of arg adjusters in CommandMangler

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 361182.
kadircet marked an inline comment as done.
kadircet added a comment.

Use move_iterator instead of inserting in a loop.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106562

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/CompilerTests.cpp

Index: clang-tools-extra/clangd/unittests/CompilerTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompilerTests.cpp
+++ clang-tools-extra/clangd/unittests/CompilerTests.cpp
@@ -8,6 +8,8 @@
 
 #include "Compiler.h"
 #include "TestTU.h"
+#include "clang/Frontend/DependencyOutputOptions.h"
+#include "clang/Frontend/FrontendOptions.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -56,6 +58,50 @@
   TU.build(); // no-crash
 }
 
+TEST(BuildCompilerInvocation, DropsShowIncludes) {
+  MockFS FS;
+  IgnoreDiagnostics Diags;
+  TestTU TU;
+
+  TU.ExtraArgs = {"-Xclang", "--show-includes"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+
+  TU.ExtraArgs = {"/showIncludes", "--driver-mode=cl"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+
+  TU.ExtraArgs = {"/showIncludes:user", "--driver-mode=cl"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+}
+
+TEST(BuildCompilerInvocation, DropsPlugins) {
+  MockFS FS;
+  IgnoreDiagnostics Diags;
+  TestTU TU;
+
+  TU.ExtraArgs = {"-Xclang", "-load",
+  "-Xclang", "plugins.so",
+  "-Xclang", "-plugin",
+  "-Xclang", "my_plugin",
+  "-Xclang", "-plugin-arg-my_plugin",
+  "-Xclang", "foo=bar",
+  "-Xclang", "-add-plugin",
+  "-Xclang", "my_plugin2"};
+  auto &Opts = buildCompilerInvocation(TU.inputs(FS), Diags)->getFrontendOpts();
+  EXPECT_THAT(Opts.Plugins, IsEmpty());
+  EXPECT_THAT(Opts.PluginArgs, IsEmpty());
+  EXPECT_THAT(Opts.AddPluginActions, IsEmpty());
+  EXPECT_EQ(Opts.ProgramAction, frontend::ActionKind::ParseSyntaxOnly);
+  EXPECT_TRUE(Opts.ActionName.empty());
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -41,11 +41,9 @@
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "-Xclang", "-load",
-  "-Xclang", "plugin",  "-MF",
-  "dep", "--",  "foo.cc"};
+  std::vector Cmd = {"clang++", "--", "foo.cc"};
   Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"), "-fsyntax-only",
+  EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
"-isysroot", testPath("fake/sysroot"), "--",
"foo.cc"));
@@ -69,38 +67,6 @@
   HasSubstr("-isysroot " + testPath("fake/sysroot")));
 }
 
-TEST(CommandMangler, StripPlugins) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang++", "-Xclang", "-load",
-  "-Xclang", "plugin",  "foo.cc"};
-  Mangler.adjust(Cmd);
-  for (const char* Stripped : {"-Xclang", "-load", "plugin"})
-EXPECT_THAT(Cmd, Not(Contains(Stripped)));
-}
-
-TEST(CommandMangler, StripOutput) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang++", "-MF", "dependency", "-c",
-  "foo.cc"};
-  Mangler.adjust(Cmd);
-  for (const char* Stripped : {"-MF", "dependency"})
-EXPECT_THAT(Cmd, Not(Contains(Stripped)));
-}
-
-TEST(CommandMangler, StripShowIncludes) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang-cl", "/showIncludes", "foo.cc"};
-  Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, Not(Contains("/showIncludes")));
-}
-
-TEST(CommandMangler, StripShowIncludesUser) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang-cl", "/showIncludes:user", "foo.cc"};
-  Mangler.adjust(Cmd);
-  EXPECT_THAT

[PATCH] D106562: [clangd] Get rid of arg adjusters in CommandMangler

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:225
+auto It = llvm::find(Cmd, "--");
+for (std::string &Arg : ToAppend)
+  Cmd.insert(It++, std::move(Arg));

sammccall wrote:
> oops, might have left this comment on the wrong patch
> 
> use range insert to save shuffling the tail over and over and 
> std::make_move_iterator() to avoid copies?
yeah the main reason this is a loop is because I didn't know about 
`make_move_iterator`, switching to a range insert instead, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106562

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


[PATCH] D106527: [clangd] Canonicalize compile flags before applying edits

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 361183.
kadircet marked 2 inline comments as done.
kadircet added a comment.

Change occurence of ArgList usage for canonical prefixes to `Has`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106527

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -11,6 +11,7 @@
 #include "TestFS.h"
 #include "support/Context.h"
 
+#include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/FileSystem.h"
@@ -165,13 +166,15 @@
 for (char &C : Arg)
   C = llvm::toUpper(C);
 });
-Cfg.CompileFlags.Edits.push_back(
-[](std::vector &Argv) { Argv.push_back("--hello"); });
+Cfg.CompileFlags.Edits.push_back([](std::vector &Argv) {
+  Argv = tooling::getInsertArgumentAdjuster("--hello")(Argv, "");
+});
 WithContextValue WithConfig(Config::Key, std::move(Cfg));
 Mangler.adjust(Cmd);
   }
-  // Edits are applied in given order and before other mangling.
-  EXPECT_THAT(Cmd, ElementsAre(_, "FOO.CC", "--hello"));
+  // Edits are applied in given order and before other mangling and they always
+  // go before filename.
+  EXPECT_THAT(Cmd, ElementsAre(_, "--hello", "--", "FOO.CC"));
 }
 
 static std::string strip(llvm::StringRef Arg, llvm::StringRef Argv) {
@@ -335,9 +338,8 @@
 }
 
 TEST(PrintArgvTest, All) {
-  std::vector Args = {
-  "one", "two", "thr ee", "f\"o\"ur", "fi\\ve", "$"
-  };
+  std::vector Args = {"one",  "two","thr ee",
+   "f\"o\"ur", "fi\\ve", "$"};
   const char *Expected = R"(one two "thr ee" "f\"o\"ur" "fi\\ve" $)";
   EXPECT_EQ(Expected, printArgv(Args));
 }
Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -133,8 +133,9 @@
   Opts.ContextProvider = [](PathRef P) {
 Config C;
 if (P.endswith("foo.cpp"))
-  C.CompileFlags.Edits.push_back(
-  [](std::vector &Argv) { Argv.push_back("-Done=two"); });
+  C.CompileFlags.Edits.push_back([](std::vector &Argv) {
+Argv = tooling::getInsertArgumentAdjuster("-Done=two")(Argv, "");
+  });
 if (P.endswith("baz.cpp"))
   C.Index.Background = Config::BackgroundPolicy::Skip;
 return Context::current().derive(Config::Key, std::move(C));
Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -48,7 +48,7 @@
 #
 # ERR: ASTWorker building file {{.*}}foo.c version 0 with command
 # ERR: [{{.*}}clangd-test2]
-# ERR: clang -c foo.c -Wall -Werror
+# ERR: clang -c -Wall -Werror {{.*}} -- foo.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -9,11 +9,14 @@
 #include "CompileCommands.h"
 #include "Config.h"
 #include "support/Logger.h"
+#include "support/Trace.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Debug.h"
@@ -188,11 +191,33 @@
   return Result;
 }
 
-CommandMangler CommandMangler::forTests() {
-  return CommandMangler();
-}
+CommandMangler CommandMangler::forTests() { return CommandMangler(); }
 
 void CommandMangler::adjust(std::vector &Cmd) const {
+  trace::Span S("AdjustCompileFlags");
+  auto &OptTable = clang::driver::getDriverOptTable();
+  // OriginalArgs needs to outlive ArgList.
+  llvm::SmallVector OriginalArgs;
+  OriginalArgs.reserve(Cmd.size());
+  for (const std::string &S : Cmd)
+OriginalArgs.push_back(S.c_str());
+  // ParseArgs propagates missig arg/opt counts on error, but preserves
+  // everything it could parse in ArgList. So we just ignore those counts.
+  unsigned IgnoredCount;
+  au

[PATCH] D105876: OMPIRBuilder for Interop directive

2021-07-23 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 361186.
sriharikrishna added a comment.

OMPIRBuilder for Interop directive. Squashed commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105876

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/interop_irbuilder.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2173,6 +2173,96 @@
   return Builder.CreateCall(Fn, Args, Name);
 }
 
+CallInst *OpenMPIRBuilder::createOMPInteropInit(const LocationDescription &Loc,
+Value *InteropVar,
+omp::OMPInteropType InteropType,
+Value *Device,
+Value *NumDependences,
+Value *DependenceAddress,
+bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  Constant *InteropTypeVal =
+  ConstantInt::get(Int64, (int)InteropType);
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,   InteropVar,InteropTypeVal,
+  Device, NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_interop_init);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropDestroy(
+const LocationDescription &Loc, Value *InteropVar, Value *Device,
+Value *NumDependences, Value *DependenceAddress,
+bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_interop_destroy);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription &Loc,
+   Value *InteropVar,
+   Value *Device,
+   Value *NumDependences,
+   Value *DependenceAddress,
+   bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_interop_use);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
 CallInst *OpenMPIRBuilder::createCach

[clang] 9a977da - Fix __hip_fabin visibility

2021-07-23 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-07-23T10:14:29-04:00
New Revision: 9a977daaf6b19c6ff7a53afbe8ece2cb7011dd9e

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

LOG: Fix __hip_fabin visibility

In -fgpu-rdc case, fat binary is embedded as global variable __hip_fatbin.
It needs to have protected visibility to avoid conflict between shared
libraries.

Reviewed by: Siu Chi Chan

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

Fixes: SWDEV-292290

Added: 


Modified: 
clang/lib/Driver/ToolChains/HIP.cpp
clang/test/Driver/hip-toolchain-rdc.hip

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/HIP.cpp 
b/clang/lib/Driver/ToolChains/HIP.cpp
index 28d4e5ddad10..8c85cc755adb 100644
--- a/clang/lib/Driver/ToolChains/HIP.cpp
+++ b/clang/lib/Driver/ToolChains/HIP.cpp
@@ -180,6 +180,7 @@ void 
AMDGCN::Linker::constructGenerateObjFileFromHIPFatBinary(
   // in several main host machines.
   ObjStream << "#   HIP Object Generator\n";
   ObjStream << "# *** Automatically generated by Clang ***\n";
+  ObjStream << "  .protected __hip_fatbin\n";
   ObjStream << "  .type __hip_fatbin,@object\n";
   ObjStream << "  .section .hip_fatbin,\"a\",@progbits\n";
   ObjStream << "  .globl __hip_fatbin\n";

diff  --git a/clang/test/Driver/hip-toolchain-rdc.hip 
b/clang/test/Driver/hip-toolchain-rdc.hip
index 6a60686e3a95..abcc14538486 100644
--- a/clang/test/Driver/hip-toolchain-rdc.hip
+++ b/clang/test/Driver/hip-toolchain-rdc.hip
@@ -14,6 +14,7 @@
 // RUN: 2>&1 | FileCheck %s
 
 // check code object alignment in dumped llvm-mc input
+// CHECK: .protected __hip_fatbin
 // CHECK: .p2align 12
 
 // emit objects for host side path



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


[PATCH] D106571: [HIP] Fix visibility of __hip_fatbin

2021-07-23 Thread Yaxun Liu 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 rG9a977daaf6b1: Fix __hip_fabin visibility (authored by 
yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106571

Files:
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/hip-toolchain-rdc.hip


Index: clang/test/Driver/hip-toolchain-rdc.hip
===
--- clang/test/Driver/hip-toolchain-rdc.hip
+++ clang/test/Driver/hip-toolchain-rdc.hip
@@ -14,6 +14,7 @@
 // RUN: 2>&1 | FileCheck %s
 
 // check code object alignment in dumped llvm-mc input
+// CHECK: .protected __hip_fatbin
 // CHECK: .p2align 12
 
 // emit objects for host side path
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -180,6 +180,7 @@
   // in several main host machines.
   ObjStream << "#   HIP Object Generator\n";
   ObjStream << "# *** Automatically generated by Clang ***\n";
+  ObjStream << "  .protected __hip_fatbin\n";
   ObjStream << "  .type __hip_fatbin,@object\n";
   ObjStream << "  .section .hip_fatbin,\"a\",@progbits\n";
   ObjStream << "  .globl __hip_fatbin\n";


Index: clang/test/Driver/hip-toolchain-rdc.hip
===
--- clang/test/Driver/hip-toolchain-rdc.hip
+++ clang/test/Driver/hip-toolchain-rdc.hip
@@ -14,6 +14,7 @@
 // RUN: 2>&1 | FileCheck %s
 
 // check code object alignment in dumped llvm-mc input
+// CHECK: .protected __hip_fatbin
 // CHECK: .p2align 12
 
 // emit objects for host side path
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -180,6 +180,7 @@
   // in several main host machines.
   ObjStream << "#   HIP Object Generator\n";
   ObjStream << "# *** Automatically generated by Clang ***\n";
+  ObjStream << "  .protected __hip_fatbin\n";
   ObjStream << "  .type __hip_fatbin,@object\n";
   ObjStream << "  .section .hip_fatbin,\"a\",@progbits\n";
   ObjStream << "  .globl __hip_fatbin\n";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106639: [clangd] Adjust compile flags to contain only the requested file as input

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 361193.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- push_back instead of insert
- don't parse argv[0] rather than skipping it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106639

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp

Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -59,7 +59,7 @@
   Argv.push_back(FullFilename);
 
   auto Mangler = CommandMangler::forTests();
-  Mangler.adjust(Inputs.CompileCommand.CommandLine);
+  Mangler.adjust(Inputs.CompileCommand.CommandLine, FullFilename);
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.Directory = testRoot();
   Inputs.Contents = Code;
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -43,7 +43,7 @@
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
   std::vector Cmd = {"clang++", "--", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
"-isysroot", testPath("fake/sysroot"), "--",
@@ -54,7 +54,7 @@
   auto Mangler = CommandMangler::forTests();
   Mangler.ResourceDir = testPath("fake/resources");
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, Contains("-resource-dir=" + testPath("fake/resources")));
 }
 
@@ -63,7 +63,7 @@
   Mangler.Sysroot = testPath("fake/sysroot");
 
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(llvm::join(Cmd, " "),
   HasSubstr("-isysroot " + testPath("fake/sysroot")));
 }
@@ -73,19 +73,19 @@
   Mangler.ClangPath = testPath("fake/clang");
 
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("fake/clang++"), Cmd.front());
 
   Cmd = {"unknown-binary", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("fake/unknown-binary"), Cmd.front());
 
   Cmd = {testPath("path/clang++"), "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("path/clang++"), Cmd.front());
 
   Cmd = {"foo/unknown-binary", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ("foo/unknown-binary", Cmd.front());
 }
 
@@ -128,7 +128,7 @@
   auto Mangler = CommandMangler::forTests();
   Mangler.ClangPath = testPath("fake/clang");
   std::vector Cmd = {(TempDir + "/bin/foo").str(), "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   // Directory based on resolved symlink, basename preserved.
   EXPECT_EQ((TempDir + "/lib/foo").str(), Cmd.front());
 
@@ -145,13 +145,13 @@
   Mangler.ClangPath = testPath("fake/clang");
   // Driver found on PATH.
   Cmd = {"foo", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   // Found the symlink and resolved the path as above.
   EXPECT_EQ((TempDir + "/lib/foo").str(), Cmd.front());
 
   // Symlink not resolved with -no-canonical-prefixes.
   Cmd = {"foo", "-no-canonical-prefixes", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ((TempDir + "/bin/foo").str(), Cmd.front());
 }
 #endif
@@ -170,7 +170,7 @@
   Argv = tooling::getInsertArgumentAdjuster("--hello")(Argv, "");
 });
 WithContextValue WithConfig(Config::Key, std::move(Cfg));
-Mangler.adjust(Cmd);
+Mangler.adjust(Cmd, "foo.cc");
   }
   // Edits are applied in given order and before other mangling and they always
   // go before filename.
Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -48,7 +48,7 @@
 #
 # ERR: ASTWorker building file {{.*}}foo.c version 0 with command
 # ERR: [{{.*}}clangd-test2]
-# ERR: clang -c -Wall -Werror {{.*}} -- foo.c
+# ERR: clang -c -Wall -Werror {{.*}} -- {{.*}}foo.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}

[PATCH] D106664: [clang][docs] Fix typos in Options.td and regen ClangCommandLineReference.rst.

2021-07-23 Thread Frederic Cambus via Phabricator via cfe-commits
fcambus created this revision.
Herald added a subscriber: dang.
fcambus requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix a couple of typos in Options.td and regenerate 
ClangCommandLineReference.rst.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106664

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1004,7 +1004,7 @@
"offloading languages CUDA and HIP: 'hash' (ID's generated by 
hashing "
"file path and command line options) | 'random' (ID's generated as "
"random numbers) | 'none' (disabled). Default is 'hash'. This 
option "
-   "will be overriden by option '-cuid=[ID]' if it is specified." >;
+   "will be overridden by option '-cuid=[ID]' if it is specified." >;
 def libomptarget_amdgcn_bc_path_EQ : Joined<["--"], 
"libomptarget-amdgcn-bc-path=">, Group,
   HelpText<"Path to libomptarget-amdgcn bitcode library">;
 def libomptarget_nvptx_bc_path_EQ : Joined<["--"], 
"libomptarget-nvptx-bc-path=">, Group,
@@ -2678,10 +2678,10 @@
 def dA : Flag<["-"], "dA">, Alias;
 defm visibility_from_dllstorageclass : 
BoolFOption<"visibility-from-dllstorageclass",
   LangOpts<"VisibilityFromDLLStorageClass">, DefaultFalse,
-  PosFlag,
+  PosFlag,
   NegFlag>;
 def fvisibility_dllexport_EQ : Joined<["-"], "fvisibility-dllexport=">, 
Group, Flags<[CC1Option]>,
-  HelpText<"The visibility for dllexport defintions 
[-fvisibility-from-dllstorageclass]">,
+  HelpText<"The visibility for dllexport definitions 
[-fvisibility-from-dllstorageclass]">,
   MarshallingInfoVisibility, 
"DefaultVisibility">,
   ShouldParseIf;
 def fvisibility_nodllstorageclass_EQ : Joined<["-"], 
"fvisibility-nodllstorageclass=">, Group, Flags<[CC1Option]>,
Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -263,7 +263,7 @@
 
 .. option:: -fuse-cuid=
 
-Method to generate ID's for compilation units for single source offloading 
languages CUDA and HIP: 'hash' (ID's generated by hashing file path and command 
line options) \| 'random' (ID's generated as random numbers) \| 'none' 
(disabled). Default is 'hash'. This option will be overriden by option 
'-cuid=\[ID\]' if it is specified.
+Method to generate ID's for compilation units for single source offloading 
languages CUDA and HIP: 'hash' (ID's generated by hashing file path and command 
line options) \| 'random' (ID's generated as random numbers) \| 'none' 
(disabled). Default is 'hash'. This option will be overridden by option 
'-cuid=\[ID\]' if it is specified.
 
 .. option:: --gcc-toolchain=, -gcc-toolchain 
 
@@ -2497,7 +2497,7 @@
 
 .. option:: -fvisibility-dllexport=
 
-The visibility for dllexport defintions \[-fvisibility-from-dllstorageclass\]
+The visibility for dllexport definitions \[-fvisibility-from-dllstorageclass\]
 
 .. option:: -fvisibility-externs-dllimport=
 
@@ -2509,7 +2509,7 @@
 
 .. option:: -fvisibility-from-dllstorageclass, 
-fno-visibility-from-dllstorageclass
 
-Set the visiblity of symbols in the generated code from their DLL storage class
+Set the visibility of symbols in the generated code from their DLL storage 
class
 
 .. option:: -fvisibility-global-new-delete-hidden
 


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1004,7 +1004,7 @@
"offloading languages CUDA and HIP: 'hash' (ID's generated by hashing "
"file path and command line options) | 'random' (ID's generated as "
"random numbers) | 'none' (disabled). Default is 'hash'. This option "
-   "will be overriden by option '-cuid=[ID]' if it is specified." >;
+   "will be overridden by option '-cuid=[ID]' if it is specified." >;
 def libomptarget_amdgcn_bc_path_EQ : Joined<["--"], "libomptarget-amdgcn-bc-path=">, Group,
   HelpText<"Path to libomptarget-amdgcn bitcode library">;
 def libomptarget_nvptx_bc_path_EQ : Joined<["--"], "libomptarget-nvptx-bc-path=">, Group,
@@ -2678,10 +2678,10 @@
 def dA : Flag<["-"], "dA">, Alias;
 defm visibility_from_dllstorageclass : BoolFOption<"visibility-from-dllstorageclass",
   LangOpts<"VisibilityFromDLLStorageClass">, DefaultFalse,
-  PosFlag,
+  PosFlag,
   NegFlag>;
 def fvisibility_dllexport_EQ : Joined<["-"], "fvisibility-dllexport=">, Group, Flags<[CC1Option]>,
-  HelpText<"The visibility for dllexport defintions [-fvisibility-from-dllstorageclass]">,
+  HelpText<"The visibility for dllexport definitions [-fvisibility-from-dllstorageclass

[PATCH] D106562: [clangd] Get rid of arg adjusters in CommandMangler

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 361195.
kadircet added a comment.

- Add FIXME for using CommandMangler and buildCompilerInvocation in 
clangd-indexer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106562

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/CompilerTests.cpp

Index: clang-tools-extra/clangd/unittests/CompilerTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompilerTests.cpp
+++ clang-tools-extra/clangd/unittests/CompilerTests.cpp
@@ -8,6 +8,8 @@
 
 #include "Compiler.h"
 #include "TestTU.h"
+#include "clang/Frontend/DependencyOutputOptions.h"
+#include "clang/Frontend/FrontendOptions.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -56,6 +58,50 @@
   TU.build(); // no-crash
 }
 
+TEST(BuildCompilerInvocation, DropsShowIncludes) {
+  MockFS FS;
+  IgnoreDiagnostics Diags;
+  TestTU TU;
+
+  TU.ExtraArgs = {"-Xclang", "--show-includes"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+
+  TU.ExtraArgs = {"/showIncludes", "--driver-mode=cl"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+
+  TU.ExtraArgs = {"/showIncludes:user", "--driver-mode=cl"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+}
+
+TEST(BuildCompilerInvocation, DropsPlugins) {
+  MockFS FS;
+  IgnoreDiagnostics Diags;
+  TestTU TU;
+
+  TU.ExtraArgs = {"-Xclang", "-load",
+  "-Xclang", "plugins.so",
+  "-Xclang", "-plugin",
+  "-Xclang", "my_plugin",
+  "-Xclang", "-plugin-arg-my_plugin",
+  "-Xclang", "foo=bar",
+  "-Xclang", "-add-plugin",
+  "-Xclang", "my_plugin2"};
+  auto &Opts = buildCompilerInvocation(TU.inputs(FS), Diags)->getFrontendOpts();
+  EXPECT_THAT(Opts.Plugins, IsEmpty());
+  EXPECT_THAT(Opts.PluginArgs, IsEmpty());
+  EXPECT_THAT(Opts.AddPluginActions, IsEmpty());
+  EXPECT_EQ(Opts.ProgramAction, frontend::ActionKind::ParseSyntaxOnly);
+  EXPECT_TRUE(Opts.ActionName.empty());
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -41,11 +41,9 @@
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "-Xclang", "-load",
-  "-Xclang", "plugin",  "-MF",
-  "dep", "--",  "foo.cc"};
+  std::vector Cmd = {"clang++", "--", "foo.cc"};
   Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"), "-fsyntax-only",
+  EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
"-isysroot", testPath("fake/sysroot"), "--",
"foo.cc"));
@@ -69,38 +67,6 @@
   HasSubstr("-isysroot " + testPath("fake/sysroot")));
 }
 
-TEST(CommandMangler, StripPlugins) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang++", "-Xclang", "-load",
-  "-Xclang", "plugin",  "foo.cc"};
-  Mangler.adjust(Cmd);
-  for (const char* Stripped : {"-Xclang", "-load", "plugin"})
-EXPECT_THAT(Cmd, Not(Contains(Stripped)));
-}
-
-TEST(CommandMangler, StripOutput) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang++", "-MF", "dependency", "-c",
-  "foo.cc"};
-  Mangler.adjust(Cmd);
-  for (const char* Stripped : {"-MF", "dependency"})
-EXPECT_THAT(Cmd, Not(Contains(Stripped)));
-}
-
-TEST(CommandMangler, StripShowIncludes) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang-cl", "/showIncludes", "foo.cc"};
-  Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, Not(Contains("/showIncludes")));
-}
-
-TEST(CommandMangler, StripShowIncludesUser) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang-cl", "/showIncludes:user", "foo.cc"};
-

[PATCH] D105876: OMPIRBuilder for Interop directive

2021-07-23 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:6330-6331
+  if (const auto *C = S.getSingleClause()) {
+llvm::Value *InteropvarPtr =
+EmitLValue(C->getInteropVar()).getPointer(*this);
+llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown;

This code is common for all `if-else` braches, move out of the conditional 
blocks?



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:6335-6336
+  InteropType = llvm::omp::OMPInteropType::Target;
+else if (C->getIsTargetSync())
+  InteropType = llvm::omp::OMPInteropType::TargetSync;
+OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType, 
Device,

Can we have anything else rather than `C->getIsTargetSync()` here? If no, then 
it should look like this:
```
if (C->getIsTarget()) {
  InteropType = llvm::omp::OMPInteropType::Target;
} else {
  assert(C->getIsTargetSync() && "Expected ...");
  InteropType = llvm::omp::OMPInteropType::TargetSync;
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105876

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


[clang] 44dbbe6 - [HIP] Preserve ASAN bitcode library functions

2021-07-23 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-07-23T10:35:52-04:00
New Revision: 44dbbe61060acac4d0991a15decac4c909e26844

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

LOG: [HIP] Preserve ASAN bitcode library functions

Address sanitizer passes may generate call of ASAN bitcode library
functions after bitcode linking in lld, therefore lld cannot add
those symbols since it does not know they will be used later.

To solve this issue, clang emits a reference to a bicode library
function which calls all ASAN functions which need to be
preserved. This basically force all ASAN functions to be
linked in.

Reviewed by: Artem Belevich

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

Added: 
clang/test/CodeGenCUDA/amdgpu-asan.cu

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/Driver.cpp
clang/test/Driver/hip-sanitize-options.hip

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index fc1d8d924349..9b40b88ea3c9 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -523,6 +523,22 @@ void CodeGenModule::Release() {
   !Context.getTargetInfo().getTriple().isOSEmscripten()) {
 EmitMainVoidAlias();
   }
+
+  // Emit reference of __amdgpu_device_library_preserve_asan_functions to
+  // preserve ASAN functions in bitcode libraries.
+  if (LangOpts.Sanitize.has(SanitizerKind::Address) && getTriple().isAMDGPU()) 
{
+auto *FT = llvm::FunctionType::get(VoidTy, {});
+auto *F = llvm::Function::Create(
+FT, llvm::GlobalValue::ExternalLinkage,
+"__amdgpu_device_library_preserve_asan_functions", &getModule());
+auto *Var = new llvm::GlobalVariable(
+getModule(), FT->getPointerTo(),
+/*isConstant=*/true, llvm::GlobalValue::WeakAnyLinkage, F,
+"__amdgpu_device_library_preserve_asan_functions_ptr", nullptr,
+llvm::GlobalVariable::NotThreadLocal);
+addCompilerUsedGlobal(Var);
+  }
+
   emitLLVMUsed();
   if (SanStats)
 SanStats->finish();

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index cbc853370e89..9714c3c42e84 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2973,12 +2973,9 @@ class OffloadingActionBuilder final {
 // a fat binary containing all the code objects for 
diff erent GPU's.
 // The fat binary is then an input to the host action.
 for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I) {
-  if (GPUSanitize || C.getDriver().isUsingLTO(/*IsOffload=*/true)) {
-// When GPU sanitizer is enabled, since we need to link in the
-// the sanitizer runtime library after the sanitize pass, we have
-// to skip the backend and assemble phases and use lld to link
-// the bitcode. The same happens if users request to use LTO
-// explicitly.
+  if (C.getDriver().isUsingLTO(/*IsOffload=*/true)) {
+// When LTO is enabled, skip the backend and assemble phases and
+// use lld to link the bitcode.
 ActionList AL;
 AL.push_back(CudaDeviceActions[I]);
 // Create a link action to link device IR with device library
@@ -2986,7 +2983,7 @@ class OffloadingActionBuilder final {
 CudaDeviceActions[I] =
 C.MakeAction(AL, types::TY_Image);
   } else {
-// When GPU sanitizer is not enabled, we follow the conventional
+// When LTO is not enabled, we follow the conventional
 // compiler phases, including backend and assemble phases.
 ActionList AL;
 auto BackendAction = C.getDriver().ConstructPhaseAction(

diff  --git a/clang/test/CodeGenCUDA/amdgpu-asan.cu 
b/clang/test/CodeGenCUDA/amdgpu-asan.cu
new file mode 100644
index ..fab0d48ef3c9
--- /dev/null
+++ b/clang/test/CodeGenCUDA/amdgpu-asan.cu
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
+// RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
+// RUN:   -x hip | FileCheck -check-prefix=ASAN %s
+
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
+// RUN:   -fcuda-is-device -target-cpu gfx906 -x hip \
+// RUN:   | FileCheck %s
+
+// REQUIRES: amdgpu-registered-target
+
+// ASAN-DAG: declare void @__amdgpu_device_library_preserve_asan_functions()
+// ASAN-DAG: @__amdgpu_device_library_preserve_asan_functions_ptr = weak 
addrspace(1) constant void ()* @__amdgpu_device_library_preserve_asan_functions
+// ASAN-DAG: @llvm.compiler.used = 
{{.*}}@__amdgpu_device_library_preserve_asan_functions_ptr
+
+// CHECK-NOT: @__amdgpu_device_library_preserve_asan_functions_ptr

diff  --git a/clang/test/Driver/hip-s

[PATCH] D106315: [HIP] Preserve ASAN bitcode library functions

2021-07-23 Thread Yaxun Liu 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 rG44dbbe61060a: [HIP] Preserve ASAN bitcode library functions 
(authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D106315?vs=359917&id=361202#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106315

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/Driver.cpp
  clang/test/CodeGenCUDA/amdgpu-asan.cu
  clang/test/Driver/hip-sanitize-options.hip


Index: clang/test/Driver/hip-sanitize-options.hip
===
--- clang/test/Driver/hip-sanitize-options.hip
+++ clang/test/Driver/hip-sanitize-options.hip
@@ -34,7 +34,7 @@
 // CHECK-NOT: {{"[^"]*lld(\.exe){0,1}".* ".*hip.bc"}}
 // CHECK: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* 
"-fsanitize=address"}}
 
-// NORDC: {{"[^"]*clang[^"]*".* "-fcuda-is-device".* "-fsanitize=address".*}} 
"-o" "[[OUT:[^"]*.bc]]"
+// NORDC: {{"[^"]*clang[^"]*".* "-emit-obj".* "-fcuda-is-device".* 
"-fsanitize=address".*}} "-o" "[[OUT:[^"]*.o]]"
 // NORDC: {{"[^"]*lld(\.exe){0,1}".*}} "[[OUT]]" {{".*asanrtl.bc" ".*hip.bc"}}
 // NORDC: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* 
"-fsanitize=address"}}
 
Index: clang/test/CodeGenCUDA/amdgpu-asan.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/amdgpu-asan.cu
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
+// RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
+// RUN:   -x hip | FileCheck -check-prefix=ASAN %s
+
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
+// RUN:   -fcuda-is-device -target-cpu gfx906 -x hip \
+// RUN:   | FileCheck %s
+
+// REQUIRES: amdgpu-registered-target
+
+// ASAN-DAG: declare void @__amdgpu_device_library_preserve_asan_functions()
+// ASAN-DAG: @__amdgpu_device_library_preserve_asan_functions_ptr = weak 
addrspace(1) constant void ()* @__amdgpu_device_library_preserve_asan_functions
+// ASAN-DAG: @llvm.compiler.used = 
{{.*}}@__amdgpu_device_library_preserve_asan_functions_ptr
+
+// CHECK-NOT: @__amdgpu_device_library_preserve_asan_functions_ptr
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2973,12 +2973,9 @@
 // a fat binary containing all the code objects for different GPU's.
 // The fat binary is then an input to the host action.
 for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I) {
-  if (GPUSanitize || C.getDriver().isUsingLTO(/*IsOffload=*/true)) {
-// When GPU sanitizer is enabled, since we need to link in the
-// the sanitizer runtime library after the sanitize pass, we have
-// to skip the backend and assemble phases and use lld to link
-// the bitcode. The same happens if users request to use LTO
-// explicitly.
+  if (C.getDriver().isUsingLTO(/*IsOffload=*/true)) {
+// When LTO is enabled, skip the backend and assemble phases and
+// use lld to link the bitcode.
 ActionList AL;
 AL.push_back(CudaDeviceActions[I]);
 // Create a link action to link device IR with device library
@@ -2986,7 +2983,7 @@
 CudaDeviceActions[I] =
 C.MakeAction(AL, types::TY_Image);
   } else {
-// When GPU sanitizer is not enabled, we follow the conventional
+// When LTO is not enabled, we follow the conventional
 // compiler phases, including backend and assemble phases.
 ActionList AL;
 auto BackendAction = C.getDriver().ConstructPhaseAction(
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -523,6 +523,22 @@
   !Context.getTargetInfo().getTriple().isOSEmscripten()) {
 EmitMainVoidAlias();
   }
+
+  // Emit reference of __amdgpu_device_library_preserve_asan_functions to
+  // preserve ASAN functions in bitcode libraries.
+  if (LangOpts.Sanitize.has(SanitizerKind::Address) && getTriple().isAMDGPU()) 
{
+auto *FT = llvm::FunctionType::get(VoidTy, {});
+auto *F = llvm::Function::Create(
+FT, llvm::GlobalValue::ExternalLinkage,
+"__amdgpu_device_library_preserve_asan_functions", &getModule());
+auto *Var = new llvm::GlobalVariable(
+getModule(), FT->getPointerTo(),
+/*isConstant=*/true, llvm::GlobalValue::WeakAnyLinkage, F,
+"__amdgpu_device_library_preserve_asan_functions_ptr", nullptr,
+llvm::GlobalVariable::NotThreadLoc

[PATCH] D105904: [clangd] Support `#pragma mark` in the outline

2021-07-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 361208.
dgoldman marked 3 inline comments as done.
dgoldman added a comment.

Fixes for review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105904

Files:
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang/include/clang/Lex/PPCallbacks.h

Index: clang/include/clang/Lex/PPCallbacks.h
===
--- clang/include/clang/Lex/PPCallbacks.h
+++ clang/include/clang/Lex/PPCallbacks.h
@@ -492,6 +492,11 @@
 Second->PragmaComment(Loc, Kind, Str);
   }
 
+  void PragmaMark(SourceLocation Loc, StringRef Trivia) override {
+First->PragmaMark(Loc, Trivia);
+Second->PragmaMark(Loc, Trivia);
+  }
+
   void PragmaDetectMismatch(SourceLocation Loc, StringRef Name,
 StringRef Value) override {
 First->PragmaDetectMismatch(Loc, Name, Value);
Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -1027,6 +1027,105 @@
 AllOf(WithName("-pur"), WithKind(SymbolKind::Method));
 }
 
+TEST(DocumentSymbolsTest, PragmaMarkGroups) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $DogDef[[@interface Dog
+  @end]]
+
+  $DogImpl[[@implementation Dog
+
+  + (id)sharedDoggo { return 0; }
+
+  #pragma $Overrides[[mark - Overrides
+
+  - (id)init {
+return self;
+  }
+  - (void)bark {}]]
+
+  #pragma $Specifics[[mark - Dog Specifics
+
+  - (int)isAGoodBoy {
+return 1;
+  }]]
+  @]]end  // FIXME: Why doesn't this include the 'end'?
+
+  #pragma $End[[mark - End
+]]
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+  getSymbols(TU.build()),
+  ElementsAre(
+  AllOf(WithName("Dog"), SymRange(Main.range("DogDef"))),
+  AllOf(WithName("Dog"), SymRange(Main.range("DogImpl")),
+Children(AllOf(WithName("+sharedDoggo"),
+   WithKind(SymbolKind::Method)),
+ AllOf(WithName("Overrides"),
+   SymRange(Main.range("Overrides")),
+   Children(AllOf(WithName("-init"),
+  WithKind(SymbolKind::Method)),
+AllOf(WithName("-bark"),
+  WithKind(SymbolKind::Method,
+ AllOf(WithName("Dog Specifics"),
+   SymRange(Main.range("Specifics")),
+   Children(AllOf(WithName("-isAGoodBoy"),
+  WithKind(SymbolKind::Method)),
+  AllOf(WithName("End"), SymRange(Main.range("End");
+}
+
+TEST(DocumentSymbolsTest, PragmaMarkGroupsNoNesting) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  #pragma mark Helpers
+  void helpA(id obj) {}
+
+  #pragma mark -
+  #pragma mark Core
+
+  void coreMethod() {}
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(getSymbols(TU.build()),
+  ElementsAre(AllOf(WithName("Helpers")), AllOf(WithName("helpA")),
+  AllOf(WithName("(unnamed group)")),
+  AllOf(WithName("Core")),
+  AllOf(WithName("coreMethod";
+}
+
+TEST(DocumentSymbolsTest, SymbolsAreSorted) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  @interface MYObject
+  @end
+
+  void someFunctionAbove() {}
+
+  @implementation MYObject
+  - (id)init { return self; }
+
+  void someHelperFunction() {}
+
+  - (void)retain {}
+  - (void)release {}
+  @end
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(getSymbols(TU.build()),
+  ElementsAre(AllOf(WithName("MYObject")),
+  AllOf(WithName("someFunctionAbove")),
+  // FIXME: This should be nested under MYObject below.
+  AllOf(WithName("someHelperFunction")),
+  AllOf(WithName("MYObject"),
+Children(AllOf(WithName("-init"))

[PATCH] D105904: [clangd] Support `#pragma mark` in the outline

2021-07-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman added inline comments.



Comment at: clang-tools-extra/clangd/CollectMacros.h:106
+struct PragmaMark {
+  SourceLocation Loc;
+  std::string Text;

sammccall wrote:
> Line number is enough, right?
> Column is not interesting, and pragma marks expanded from macros are not 
> possible (and wouldn't be in the main file for our purposes)
No, I think the column is useful, ideally we would point directly to the text 
that the user has although currently we point to the mark symbol.



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:535
+/// by range.
+std::vector mergePragmas(std::vector &Syms,
+ std::vector 
&Pragmas,

sammccall wrote:
> FWIW the flow control/how we make progress seem hard to follow here to me.
> 
> In particular I think I'm struggling with the statefulness of "is there an 
> open mark group".
> 
> Possible simplifications:
>  - define a dummy root symbol, which seems clearer than the vector + 
> range
>  - avoid reverse-sorting the list of pragma symbols, and just consume from 
> the front of an ArrayRef instead
>  - make the outer loop over pragmas, rather than symbols. It would first 
> check if the pragma belongs directly here or not, and if so, loop over 
> symbols to work out which should become children. This seems very likely to 
> be efficient enough in practice (few pragmas, or most children are grouped 
> into pragmas)
> define a dummy root symbol, which seems clearer than the vector + 
> range

I guess? Then we'd take in a `DocumentSymbol & and a ArrayRef 
& (or just by value and then return it as well). The rest would be the same 
though

> In particular I think I'm struggling with the statefulness of "is there an 
> open mark group".

We need to track the current open group if there is one in order to move 
children to it.

> make the outer loop over pragmas, rather than symbols. It would first check 
> if the pragma belongs directly here or not, and if so, loop over symbols to 
> work out which should become children. This seems very likely to be efficient 
> enough in practice (few pragmas, or most children are grouped into pragmas)

The important thing here is knowing where the pragma mark ends - if it doesn't, 
it actually gets all of the children. So we'd have to peak at the next pragma 
mark, add all symbols before it to us as children, and then potentially recurse 
to nest it inside of a symbol. I'll try it out and see if it's simpler.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105904

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


[PATCH] D106669: [clangd] Unify compiler invocation creation

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Background-indexing is fine, because it uses GlobalCompilationDatabase
to fetch the compile commands (hence uses CommandMangler), and creates
invocation through buildCompilerInvocation.

Depends on D106639 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106669

Files:
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/indexer/IndexerMain.cpp
  clang-tools-extra/clangd/test/indexer.test

Index: clang-tools-extra/clangd/test/indexer.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/indexer.test
@@ -0,0 +1,5 @@
+# RUN: rm -rf %t.cpp
+# RUN: touch %t.cpp
+# RUN: clangd-indexer %t.cpp -- -Xclang -verify --save-temps -- 2>&1 | FileCheck %s
+# CHECK-NOT: error: no expected directives found: consider use of 'expected-no-diagnostics'
+# RUN: not ls %t.ii
Index: clang-tools-extra/clangd/indexer/IndexerMain.cpp
===
--- clang-tools-extra/clangd/indexer/IndexerMain.cpp
+++ clang-tools-extra/clangd/indexer/IndexerMain.cpp
@@ -10,6 +10,8 @@
 //
 //===--===//
 
+#include "CompileCommands.h"
+#include "Compiler.h"
 #include "index/IndexAction.h"
 #include "index/Merge.h"
 #include "index/Ref.h"
@@ -23,6 +25,7 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Signals.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -82,6 +85,15 @@
 /*IncludeGraphCallback=*/nullptr);
   }
 
+  bool runInvocation(std::shared_ptr Invocation,
+ FileManager *Files,
+ std::shared_ptr PCHContainerOps,
+ DiagnosticConsumer *DiagConsumer) override {
+prepareInvocationForClangd(*Invocation);
+return tooling::FrontendActionFactory::runInvocation(
+std::move(Invocation), Files, std::move(PCHContainerOps), DiagConsumer);
+  }
+
   // Awkward: we write the result in the destructor, because the executor
   // takes ownership so it's the easiest way to get our data back out.
   ~IndexActionFactory() {
@@ -135,7 +147,8 @@
   clang::clangd::IndexFileIn Data;
   auto Err = Executor->get()->execute(
   std::make_unique(Data),
-  clang::tooling::getStripPluginsAdjuster());
+  clang::tooling::ArgumentsAdjuster(
+  clang::clangd::CommandMangler::detect()));
   if (Err) {
 clang::clangd::elog("{0}", std::move(Err));
   }
Index: clang-tools-extra/clangd/Compiler.h
===
--- clang-tools-extra/clangd/Compiler.h
+++ clang-tools-extra/clangd/Compiler.h
@@ -61,6 +61,10 @@
   FeatureModuleSet *FeatureModules = nullptr;
 };
 
+/// Clears \p CI from options that are not supported by clangd, like codegen or
+/// plugins.
+void prepareInvocationForClangd(CompilerInvocation &CI);
+
 /// Builds compiler invocation that could be used to build AST or preamble.
 std::unique_ptr
 buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
Index: clang-tools-extra/clangd/Compiler.cpp
===
--- clang-tools-extra/clangd/Compiler.cpp
+++ clang-tools-extra/clangd/Compiler.cpp
@@ -9,6 +9,7 @@
 #include "Compiler.h"
 #include "support/Logger.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Serialization/PCHContainerOperations.h"
 #include "llvm/ADT/StringRef.h"
@@ -41,6 +42,44 @@
   IgnoreDiagnostics::log(DiagLevel, Info);
 }
 
+void prepareInvocationForClangd(CompilerInvocation &CI) {
+  // Disable "clang -verify" diagnostics, they are rarely useful in clangd, and
+  // our compiler invocation set-up doesn't seem to work with it (leading
+  // assertions in VerifyDiagnosticConsumer).
+  CI.getDiagnosticOpts().VerifyDiagnostics = false;
+  CI.getDiagnosticOpts().ShowColors = false;
+
+  // Disable any dependency outputting, we don't want to generate files or write
+  // to stdout/stderr.
+  CI.getDependencyOutputOpts().ShowIncludesDest = ShowIncludesDestination::None;
+  CI.getDependencyOutputOpts().OutputFile.clear();
+  CI.getDependencyOutputOpts().HeaderIncludeOutputFile.clear();
+  CI.getDependencyOutputOpts().DOTOutputFile.clear();
+  CI.getDependencyOutputOpts().ModuleDependencyOutputDir.clear();
+
+  // Disable any pch generation/usage operations. Since serialized preamble
+  // format is unstable, using an incompatible one might result in unexpected
+  // behav

[PATCH] D105555: [PoC][RISCV][Clang] Compute the default target-abi if it's empty.

2021-07-23 Thread Zakk Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 361216.
khchen added a comment.

address arichardson's comment, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D10

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/CodeGen/RISCV/riscv-metadata.c
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Support/TargetParser.cpp

Index: llvm/lib/Support/TargetParser.cpp
===
--- llvm/lib/Support/TargetParser.cpp
+++ llvm/lib/Support/TargetParser.cpp
@@ -331,5 +331,20 @@
   return true;
 }
 
+StringRef computeDefaultABIFromArch(const llvm::RISCVISAInfo &ISAInfo,
+bool Is64Bit) {
+  bool HasD = ISAInfo.hasExtension("d");
+  if (!Is64Bit) {
+if (HasD)
+  return "ilp32d";
+if (ISAInfo.hasExtension("e"))
+  return "ilp32e";
+return "ilp32";
+  }
+  if (HasD)
+return "lp64d";
+  return "lp64";
+}
+
 } // namespace RISCV
 } // namespace llvm
Index: llvm/include/llvm/Support/TargetParser.h
===
--- llvm/include/llvm/Support/TargetParser.h
+++ llvm/include/llvm/Support/TargetParser.h
@@ -17,8 +17,9 @@
 // FIXME: vector is used because that's what clang uses for subtarget feature
 // lists, but SmallVector would probably be better
 #include "llvm/ADT/Triple.h"
-#include "llvm/Support/ARMTargetParser.h"
 #include "llvm/Support/AArch64TargetParser.h"
+#include "llvm/Support/ARMTargetParser.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include 
 
 namespace llvm {
@@ -174,6 +175,8 @@
 void fillValidTuneCPUArchList(SmallVectorImpl &Values, bool IsRV64);
 bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector &Features);
 StringRef resolveTuneCPUAlias(StringRef TuneCPU, bool IsRV64);
+StringRef computeDefaultABIFromArch(const llvm::RISCVISAInfo &ISAInfo,
+bool IsRV64);
 
 } // namespace RISCV
 
Index: clang/test/CodeGen/RISCV/riscv-metadata.c
===
--- clang/test/CodeGen/RISCV/riscv-metadata.c
+++ clang/test/CodeGen/RISCV/riscv-metadata.c
@@ -1,14 +1,28 @@
+// RUN: %clang_cc1 -triple riscv32 -emit-llvm -o - %s | FileCheck -check-prefix=EMPTY-ILP32 %s
+// RUN: %clang_cc1 -triple riscv32 -emit-llvm -target-feature +f -target-feature +d -o - %s | FileCheck -check-prefix=EMPTY-ILP32D %s
 // RUN: %clang_cc1 -triple riscv32 -target-abi ilp32 -emit-llvm -o - %s | FileCheck -check-prefix=ILP32 %s
 // RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm -o - %s | FileCheck -check-prefix=ILP32F %s
 // RUN: %clang_cc1 -triple riscv32 -target-feature +d -target-abi ilp32d -emit-llvm -o - %s | FileCheck -check-prefix=ILP32D %s
+// RUN: %clang_cc1 -triple riscv64 -emit-llvm -o - %s | FileCheck -check-prefix=EMPTY-LP64 %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d -emit-llvm -o - %s | FileCheck -check-prefix=EMPTY-LP64D %s
 // RUN: %clang_cc1 -triple riscv64 -target-abi lp64 -emit-llvm -o - %s | FileCheck -check-prefix=LP64 %s
 // RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-abi lp64f -emit-llvm -o - %s | FileCheck -check-prefix=LP64F %s
 // RUN: %clang_cc1 -triple riscv64 -target-feature +d -target-abi lp64d -emit-llvm -o - %s | FileCheck -check-prefix=LP64D %s
 
+// Test expected behavior when giving -target-cpu
+// This cc1 test is similar to clang with -march=rv32ifd -mcpu=sifive-e31, default abi is ilp32d
+// RUN: %clang_cc1 -triple riscv32 -emit-llvm -target-feature +f -target-feature +d -target-cpu sifive-e31 -o - %s | FileCheck -check-prefix=EMPTY-ILP32D %s
+// This cc1 test is similar to clang with -march=rv64i -mcpu=sifive-u74, default abi is lp64
+// RUN: %clang_cc1 -triple riscv64 -emit-llvm -o - -target-cpu sifive-u74 %s | FileCheck -check-prefix=EMPTY-LP64 %s
+
+// EMPTY-ILP32: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32"}
+// EMPTY-ILP32D: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32d"}
 // ILP32: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32"}
 // ILP32F: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32f"}
 // ILP32D: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32d"}
 
+// EMPTY-LP64: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64"}
+// EMPTY-LP64D: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64d"}
 // LP64: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64"}
 // LP64F: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64f"}
 // LP64D: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64d"}
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -197,22 +197,9 @@
 // Ignore parsing error, just go 3rd step.
 consumeError(std::move(E));
   } else {
-bool HasD = ISAInfo.hasExtension("d");
 unsign

[PATCH] D105555: [PoC][RISCV][Clang] Compute the default target-abi if it's empty.

2021-07-23 Thread Zakk Chen via Phabricator via cfe-commits
khchen marked an inline comment as done.
khchen added a comment.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D10

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


[PATCH] D105555: [RISCV][Clang] Compute the default target-abi if it's empty.

2021-07-23 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.cpp:235
+bool Is64Bit = getTriple().getArch() == llvm::Triple::riscv64;
+ABI = llvm::RISCV::computeDefaultABIFromArch(ISAInfo, Is64Bit).str();
+  }

The ISAInfo includes XLen



Comment at: clang/lib/Driver/ToolChains/Arch/RISCV.cpp:202
+return llvm::RISCV::computeDefaultABIFromArch(ISAInfo,
+  /*IsRV64=*/XLen == 64);
   }

Ditto (it's literally on the line above!)



Comment at: llvm/lib/Support/TargetParser.cpp:336
+bool Is64Bit) {
+  bool HasD = ISAInfo.hasExtension("d");
+  if (!Is64Bit) {

I'm not personally a fan of having HasD but using ISAInfo.hasExtension("e") in 
the if. I get why it's done, but I think consistency would be better. 
Personally I'd just inline the ISAInfo.hasExtension("d"), it's not worth a 
local variable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D10

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


[PATCH] D105555: [RISCV][Clang] Compute the default target-abi if it's empty.

2021-07-23 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.cpp:233
+  // Use the explicitly target-feature to compute default ABI.
+  if (getABI().empty()) {
+bool Is64Bit = getTriple().getArch() == llvm::Triple::riscv64;

I don't think using the getter makes sense. Currently it's entirely equivalent 
to just reading ABI so serves little purpose, but in theory there could be 
additional logic added to it (like asserting it's not empty) that would break 
this. Given you already assume the name of the field below by assigning to it, 
just read ABI directly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D10

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


[PATCH] D106535: [clangd] Use CommandMangler in TestTU

2021-07-23 Thread Kadir Cetinkaya 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 rGd2a6ec8eae75: [clangd] Use CommandMangler in TestTU 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106535

Files:
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang/lib/Frontend/CreateInvocationFromCommandLine.cpp


Index: clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
===
--- clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
+++ clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
@@ -10,15 +10,17 @@
 //
 
//===--===//
 
-#include "clang/Frontend/Utils.h"
 #include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Driver/Action.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
-#include "clang/Driver/Action.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/Utils.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Host.h"
 using namespace clang;
@@ -37,7 +39,10 @@
   SmallVector Args(ArgList.begin(), ArgList.end());
 
   // FIXME: Find a cleaner way to force the driver into restricted modes.
-  Args.push_back("-fsyntax-only");
+  Args.insert(
+  llvm::find_if(
+  Args, [](const char *Elem) { return llvm::StringRef(Elem) == "--"; 
}),
+  "-fsyntax-only");
 
   // FIXME: We shouldn't have to pass in the path info.
   driver::Driver TheDriver(Args[0], llvm::sys::getDefaultTargetTriple(), 
*Diags,
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "TestTU.h"
+#include "CompileCommands.h"
 #include "Compiler.h"
 #include "Diagnostics.h"
 #include "TestFS.h"
@@ -56,6 +57,9 @@
   // Put the file name at the end -- this allows the extra arg (-xc++) to
   // override the language setting.
   Argv.push_back(FullFilename);
+
+  auto Mangler = CommandMangler::forTests();
+  Mangler.adjust(Inputs.CompileCommand.CommandLine);
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.Directory = testRoot();
   Inputs.Contents = Code;


Index: clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
===
--- clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
+++ clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
@@ -10,15 +10,17 @@
 //
 //===--===//
 
-#include "clang/Frontend/Utils.h"
 #include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Driver/Action.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
-#include "clang/Driver/Action.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/Utils.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Host.h"
 using namespace clang;
@@ -37,7 +39,10 @@
   SmallVector Args(ArgList.begin(), ArgList.end());
 
   // FIXME: Find a cleaner way to force the driver into restricted modes.
-  Args.push_back("-fsyntax-only");
+  Args.insert(
+  llvm::find_if(
+  Args, [](const char *Elem) { return llvm::StringRef(Elem) == "--"; }),
+  "-fsyntax-only");
 
   // FIXME: We shouldn't have to pass in the path info.
   driver::Driver TheDriver(Args[0], llvm::sys::getDefaultTargetTriple(), *Diags,
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "TestTU.h"
+#include "CompileCommands.h"
 #include "Compiler.h"
 #include "Diagnostics.h"
 #include "TestFS.h"
@@ -56,6 +57,9 @@
   // Put the file name at the end -- this allows the extra arg (-xc++) to
   // override the language setting.
   Argv.push_back(FullFilename);
+
+  auto Mangler = CommandMangler::forTests();
+  Mangler.adjust(Inputs.CompileCommand.CommandLine);
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.Directory = testRoot();
   Inputs.Contents = Code;
___

[clang] d2a6ec8 - [clangd] Use CommandMangler in TestTU

2021-07-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-07-23T17:15:05+02:00
New Revision: d2a6ec8eae75b60081e081eeb37022839f4f2d04

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

LOG: [clangd] Use CommandMangler in TestTU

This makes testing setup look closer to production.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/TestTU.cpp
clang/lib/Frontend/CreateInvocationFromCommandLine.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/TestTU.cpp 
b/clang-tools-extra/clangd/unittests/TestTU.cpp
index cb258a5ccb549..052603ce6851a 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.cpp
+++ b/clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "TestTU.h"
+#include "CompileCommands.h"
 #include "Compiler.h"
 #include "Diagnostics.h"
 #include "TestFS.h"
@@ -56,6 +57,9 @@ ParseInputs TestTU::inputs(MockFS &FS) const {
   // Put the file name at the end -- this allows the extra arg (-xc++) to
   // override the language setting.
   Argv.push_back(FullFilename);
+
+  auto Mangler = CommandMangler::forTests();
+  Mangler.adjust(Inputs.CompileCommand.CommandLine);
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.Directory = testRoot();
   Inputs.Contents = Code;

diff  --git a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp 
b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
index ff0aa6faf33f6..2e23ebfdf1602 100644
--- a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
+++ b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
@@ -10,15 +10,17 @@
 //
 
//===--===//
 
-#include "clang/Frontend/Utils.h"
 #include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Driver/Action.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
-#include "clang/Driver/Action.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/Tool.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/Utils.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Host.h"
 using namespace clang;
@@ -37,7 +39,10 @@ std::unique_ptr 
clang::createInvocationFromCommandLine(
   SmallVector Args(ArgList.begin(), ArgList.end());
 
   // FIXME: Find a cleaner way to force the driver into restricted modes.
-  Args.push_back("-fsyntax-only");
+  Args.insert(
+  llvm::find_if(
+  Args, [](const char *Elem) { return llvm::StringRef(Elem) == "--"; 
}),
+  "-fsyntax-only");
 
   // FIXME: We shouldn't have to pass in the path info.
   driver::Driver TheDriver(Args[0], llvm::sys::getDefaultTargetTriple(), 
*Diags,



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


[clang-tools-extra] 1c0d008 - [clangd] Get rid of arg adjusters in CommandMangler

2021-07-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-07-23T17:15:06+02:00
New Revision: 1c0d0085bcaaf27cc8d9492eb3c5c05058e54b8e

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

LOG: [clangd] Get rid of arg adjusters in CommandMangler

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

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/CompileCommands.h
clang-tools-extra/clangd/Compiler.cpp
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
clang-tools-extra/clangd/unittests/CompilerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index e749720b83a1..ffc66303c9fc 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -12,6 +12,8 @@
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Debug.h"
@@ -20,6 +22,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
+#include 
 #include 
 #include 
 
@@ -202,14 +205,9 @@ void CommandMangler::adjust(std::vector &Cmd) 
const {
 return false;
   };
 
-  // clangd should not write files to disk, including dependency files
-  // requested on the command line.
-  Cmd = tooling::getClangStripDependencyFileAdjuster()(Cmd, "");
-  // Strip plugin related command line arguments. Clangd does
-  // not support plugins currently. Therefore it breaks if
-  // compiler tries to load plugins.
-  Cmd = tooling::getStripPluginsAdjuster()(Cmd, "");
-  Cmd = tooling::getClangSyntaxOnlyAdjuster()(Cmd, "");
+  llvm::erase_if(Cmd, [](llvm::StringRef Elem) {
+return Elem.startswith("--save-temps") || Elem.startswith("-save-temps");
+  });
 
   std::vector ToAppend;
   if (ResourceDir && !Has("-resource-dir"))
@@ -223,8 +221,8 @@ void CommandMangler::adjust(std::vector &Cmd) 
const {
   }
 
   if (!ToAppend.empty()) {
-Cmd = tooling::getInsertArgumentAdjuster(
-std::move(ToAppend), tooling::ArgumentInsertPosition::END)(Cmd, "");
+Cmd.insert(llvm::find(Cmd, "--"), 
std::make_move_iterator(ToAppend.begin()),
+   std::make_move_iterator(ToAppend.end()));
   }
 
   if (!Cmd.empty()) {

diff  --git a/clang-tools-extra/clangd/CompileCommands.h 
b/clang-tools-extra/clangd/CompileCommands.h
index 6e958d271c87..759472413fda 100644
--- a/clang-tools-extra/clangd/CompileCommands.h
+++ b/clang-tools-extra/clangd/CompileCommands.h
@@ -25,6 +25,10 @@ namespace clangd {
 //  - forcing the use of clangd's builtin headers rather than clang's
 //  - resolving argv0 as cc1 expects
 //  - injecting -isysroot flags on mac as the system clang does
+// FIXME: This is currently not used in all code paths that create invocations.
+// Make use of these adjusters and buildCompilerInvocation in clangd-indexer as
+// well. It should be possible to hook it up by overriding RunInvocation in
+// FrontendActionFactory.
 struct CommandMangler {
   // Absolute path to clang.
   llvm::Optional ClangPath;

diff  --git a/clang-tools-extra/clangd/Compiler.cpp 
b/clang-tools-extra/clangd/Compiler.cpp
index a7e48934ddaf..f2fb4489f105 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -64,6 +64,7 @@ buildCompilerInvocation(const ParseInputs &Inputs, 
clang::DiagnosticConsumer &D,
   // our compiler invocation set-up doesn't seem to work with it (leading
   // assertions in VerifyDiagnosticConsumer).
   CI->getDiagnosticOpts().VerifyDiagnostics = false;
+  CI->getDiagnosticOpts().ShowColors = false;
 
   // Disable any dependency outputting, we don't want to generate files or 
write
   // to stdout/stderr.
@@ -90,6 +91,12 @@ buildCompilerInvocation(const ParseInputs &Inputs, 
clang::DiagnosticConsumer &D,
   CI->getHeaderSearchOpts().ModuleFormat =
   PCHContainerOperations().getRawReader().getFormat().str();
 
+  CI->getFrontendOpts().Plugins.clear();
+  CI->getFrontendOpts().AddPluginActions.clear();
+  CI->getFrontendOpts().PluginArgs.clear();
+  CI->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly;
+  CI->getFrontendOpts().ActionName.clear();
+
   return CI;
 }
 

diff  --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp 
b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
index 7fb2ae7664fa..f5727305b465 100644
--- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -41,11 +41,9 @@ TEST(CommandMangler, Everything) {
  

[PATCH] D106562: [clangd] Get rid of arg adjusters in CommandMangler

2021-07-23 Thread Kadir Cetinkaya 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 rG1c0d0085bcaa: [clangd] Get rid of arg adjusters in 
CommandMangler (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106562

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/CompilerTests.cpp

Index: clang-tools-extra/clangd/unittests/CompilerTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompilerTests.cpp
+++ clang-tools-extra/clangd/unittests/CompilerTests.cpp
@@ -8,6 +8,8 @@
 
 #include "Compiler.h"
 #include "TestTU.h"
+#include "clang/Frontend/DependencyOutputOptions.h"
+#include "clang/Frontend/FrontendOptions.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -56,6 +58,50 @@
   TU.build(); // no-crash
 }
 
+TEST(BuildCompilerInvocation, DropsShowIncludes) {
+  MockFS FS;
+  IgnoreDiagnostics Diags;
+  TestTU TU;
+
+  TU.ExtraArgs = {"-Xclang", "--show-includes"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+
+  TU.ExtraArgs = {"/showIncludes", "--driver-mode=cl"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+
+  TU.ExtraArgs = {"/showIncludes:user", "--driver-mode=cl"};
+  EXPECT_THAT(buildCompilerInvocation(TU.inputs(FS), Diags)
+  ->getDependencyOutputOpts()
+  .ShowIncludesDest,
+  ShowIncludesDestination::None);
+}
+
+TEST(BuildCompilerInvocation, DropsPlugins) {
+  MockFS FS;
+  IgnoreDiagnostics Diags;
+  TestTU TU;
+
+  TU.ExtraArgs = {"-Xclang", "-load",
+  "-Xclang", "plugins.so",
+  "-Xclang", "-plugin",
+  "-Xclang", "my_plugin",
+  "-Xclang", "-plugin-arg-my_plugin",
+  "-Xclang", "foo=bar",
+  "-Xclang", "-add-plugin",
+  "-Xclang", "my_plugin2"};
+  auto &Opts = buildCompilerInvocation(TU.inputs(FS), Diags)->getFrontendOpts();
+  EXPECT_THAT(Opts.Plugins, IsEmpty());
+  EXPECT_THAT(Opts.PluginArgs, IsEmpty());
+  EXPECT_THAT(Opts.AddPluginActions, IsEmpty());
+  EXPECT_EQ(Opts.ProgramAction, frontend::ActionKind::ParseSyntaxOnly);
+  EXPECT_TRUE(Opts.ActionName.empty());
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -41,11 +41,9 @@
   Mangler.ClangPath = testPath("fake/clang");
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
-  std::vector Cmd = {"clang++", "-Xclang", "-load",
-  "-Xclang", "plugin",  "-MF",
-  "dep", "--",  "foo.cc"};
+  std::vector Cmd = {"clang++", "--", "foo.cc"};
   Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"), "-fsyntax-only",
+  EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
"-isysroot", testPath("fake/sysroot"), "--",
"foo.cc"));
@@ -69,38 +67,6 @@
   HasSubstr("-isysroot " + testPath("fake/sysroot")));
 }
 
-TEST(CommandMangler, StripPlugins) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang++", "-Xclang", "-load",
-  "-Xclang", "plugin",  "foo.cc"};
-  Mangler.adjust(Cmd);
-  for (const char* Stripped : {"-Xclang", "-load", "plugin"})
-EXPECT_THAT(Cmd, Not(Contains(Stripped)));
-}
-
-TEST(CommandMangler, StripOutput) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang++", "-MF", "dependency", "-c",
-  "foo.cc"};
-  Mangler.adjust(Cmd);
-  for (const char* Stripped : {"-MF", "dependency"})
-EXPECT_THAT(Cmd, Not(Contains(Stripped)));
-}
-
-TEST(CommandMangler, StripShowIncludes) {
-  auto Mangler = CommandMangler::forTests();
-  std::vector Cmd = {"clang-cl", "/showIncludes", "foo.cc"};
-  Mangler.adjust(Cmd);
-  EXPECT_THAT(Cmd, Not(Contains("/showIncludes")));
-}
-
-TEST(CommandMangler, StripShowIncludesUser) {
-  auto Mangler = CommandMangler::

[clang-tools-extra] 7cc8a8e - [clangd] Canonicalize compile flags before applying edits

2021-07-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-07-23T17:15:06+02:00
New Revision: 7cc8a8e3849dc4044cc799e2c1f6cc241b851b70

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

LOG: [clangd] Canonicalize compile flags before applying edits

Pushes input for the compile action to the end while separating with a
`--` before applying other manglings. This ensures edits that effect only the
arguments that come after them works, like changing parse language via -x.

Fixes https://github.com/clangd/clangd/issues/555.

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

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/test/did-change-configuration-params.test
clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index ffc66303c9fc4..ba21e81d3fb52 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -9,11 +9,14 @@
 #include "CompileCommands.h"
 #include "Config.h"
 #include "support/Logger.h"
+#include "support/Trace.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Debug.h"
@@ -188,11 +191,33 @@ CommandMangler CommandMangler::detect() {
   return Result;
 }
 
-CommandMangler CommandMangler::forTests() {
-  return CommandMangler();
-}
+CommandMangler CommandMangler::forTests() { return CommandMangler(); }
 
 void CommandMangler::adjust(std::vector &Cmd) const {
+  trace::Span S("AdjustCompileFlags");
+  auto &OptTable = clang::driver::getDriverOptTable();
+  // OriginalArgs needs to outlive ArgList.
+  llvm::SmallVector OriginalArgs;
+  OriginalArgs.reserve(Cmd.size());
+  for (const std::string &S : Cmd)
+OriginalArgs.push_back(S.c_str());
+  // ParseArgs propagates missig arg/opt counts on error, but preserves
+  // everything it could parse in ArgList. So we just ignore those counts.
+  unsigned IgnoredCount;
+  auto ArgList = OptTable.ParseArgs(OriginalArgs, IgnoredCount, IgnoredCount);
+
+  // Move the inputs to the end, separated via `--` from flags. This ensures
+  // modifications done in the following steps apply in more cases (like 
setting
+  // -x, which only affects inputs that come after it).
+  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
+// In theory there might be more than one input, but clangd can't deal with
+// them anyway.
+if (auto *Input = ArgList.getLastArg(driver::options::OPT_INPUT)) {
+  Cmd.insert(Cmd.end(), {"--", Input->getAsString(ArgList)});
+  Cmd.erase(Cmd.begin() + Input->getIndex());
+}
+  }
+
   for (auto &Edit : Config::current().CompileFlags.Edits)
 Edit(Cmd);
 
@@ -215,7 +240,7 @@ void CommandMangler::adjust(std::vector &Cmd) 
const {
 
   // Don't set `-isysroot` if it is already set or if `--sysroot` is set.
   // `--sysroot` is a superset of the `-isysroot` argument.
-  if (Sysroot && !Has("-isysroot") && !Has("--sysroot")) {
+  if (Sysroot && !Has("--sysroot") && !Has("-isysroot")) {
 ToAppend.push_back("-isysroot");
 ToAppend.push_back(*Sysroot);
   }

diff  --git 
a/clang-tools-extra/clangd/test/did-change-configuration-params.test 
b/clang-tools-extra/clangd/test/did-change-configuration-params.test
index 19d41d0812e23..e90e26c0d3a7a 100644
--- a/clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ b/clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -48,7 +48,7 @@
 #
 # ERR: ASTWorker building file {{.*}}foo.c version 0 with command
 # ERR: [{{.*}}clangd-test2]
-# ERR: clang -c foo.c -Wall -Werror
+# ERR: clang -c -Wall -Werror {{.*}} -- foo.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---

diff  --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp 
b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
index de8ff2b4a14e1..79da2f059a8c2 100644
--- a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -133,8 +133,9 @@ TEST_F(BackgroundIndexTest, Config) {
   Opts.ContextProvider = [](PathRef P) {
 Config C;
 if (P.endswith("foo.cpp"))
-  C.CompileFlags.Edits.push_back(
-  [](std::vector &Argv) { Argv.push_back("-Done=two"); });
+  C.CompileFlags.Edits.push_back([](std::vector &Argv) {
+Argv = tooling::getInsertArgum

[clang-tools-extra] ba5dd94 - [clangd] Adjust compile flags to contain only the requested file as input

2021-07-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-07-23T17:15:06+02:00
New Revision: ba5dd945ad9124f24452987be64040a6ea6cd25e

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

LOG: [clangd] Adjust compile flags to contain only the requested file as input

Depends on D106527.

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

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/CompileCommands.h
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/test/did-change-configuration-params.test
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index ba21e81d3fb52..4c1646ed9e05c 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -13,6 +13,7 @@
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -193,7 +194,8 @@ CommandMangler CommandMangler::detect() {
 
 CommandMangler CommandMangler::forTests() { return CommandMangler(); }
 
-void CommandMangler::adjust(std::vector &Cmd) const {
+void CommandMangler::adjust(std::vector &Cmd,
+llvm::StringRef File) const {
   trace::Span S("AdjustCompileFlags");
   auto &OptTable = clang::driver::getDriverOptTable();
   // OriginalArgs needs to outlive ArgList.
@@ -204,18 +206,27 @@ void CommandMangler::adjust(std::vector 
&Cmd) const {
   // ParseArgs propagates missig arg/opt counts on error, but preserves
   // everything it could parse in ArgList. So we just ignore those counts.
   unsigned IgnoredCount;
-  auto ArgList = OptTable.ParseArgs(OriginalArgs, IgnoredCount, IgnoredCount);
+  // Drop the executable name, as ParseArgs doesn't expect it. This means
+  // indices are actually of by one between ArgList and OriginalArgs.
+  auto ArgList =
+  OptTable.ParseArgs(llvm::makeArrayRef(OriginalArgs).drop_front(),
+ IgnoredCount, IgnoredCount);
 
   // Move the inputs to the end, separated via `--` from flags. This ensures
   // modifications done in the following steps apply in more cases (like 
setting
   // -x, which only affects inputs that come after it).
   if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
-// In theory there might be more than one input, but clangd can't deal with
-// them anyway.
-if (auto *Input = ArgList.getLastArg(driver::options::OPT_INPUT)) {
-  Cmd.insert(Cmd.end(), {"--", Input->getAsString(ArgList)});
-  Cmd.erase(Cmd.begin() + Input->getIndex());
-}
+// Drop all the inputs and only add one for the current file.
+llvm::SmallVector IndicesToDrop;
+for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
+  IndicesToDrop.push_back(Input->getIndex());
+llvm::sort(IndicesToDrop);
+llvm::for_each(llvm::reverse(IndicesToDrop),
+   // +1 to account for the executable name in Cmd[0] that
+   // doesn't exist in ArgList.
+   [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
+Cmd.push_back("--");
+Cmd.push_back(File.str());
   }
 
   for (auto &Edit : Config::current().CompileFlags.Edits)
@@ -265,7 +276,7 @@ CommandMangler::operator 
clang::tooling::ArgumentsAdjuster() && {
   return [Mangler = std::make_shared(std::move(*this))](
  const std::vector &Args, llvm::StringRef File) {
 auto Result = Args;
-Mangler->adjust(Result);
+Mangler->adjust(Result, File);
 return Result;
   };
 }

diff  --git a/clang-tools-extra/clangd/CompileCommands.h 
b/clang-tools-extra/clangd/CompileCommands.h
index 759472413fdaf..50c1a3571ec42 100644
--- a/clang-tools-extra/clangd/CompileCommands.h
+++ b/clang-tools-extra/clangd/CompileCommands.h
@@ -12,6 +12,7 @@
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
 #include 
 #include 
 #include 
@@ -46,7 +47,7 @@ struct CommandMangler {
   //  - on mac, find clang and isysroot by querying the `xcrun` launcher
   static CommandMangler detect();
 
-  void adjust(std::vector &Cmd) const;
+  void adjust(std::vector &Cmd, llvm::StringRef File) const;
   explicit operator clang::tooling::ArgumentsAdjuster() &&;
 
 private:

diff  --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index 73f19abae

[PATCH] D106527: [clangd] Canonicalize compile flags before applying edits

2021-07-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7cc8a8e3849d: [clangd] Canonicalize compile flags before 
applying edits (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106527

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -11,6 +11,7 @@
 #include "TestFS.h"
 #include "support/Context.h"
 
+#include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/FileSystem.h"
@@ -165,13 +166,15 @@
 for (char &C : Arg)
   C = llvm::toUpper(C);
 });
-Cfg.CompileFlags.Edits.push_back(
-[](std::vector &Argv) { Argv.push_back("--hello"); });
+Cfg.CompileFlags.Edits.push_back([](std::vector &Argv) {
+  Argv = tooling::getInsertArgumentAdjuster("--hello")(Argv, "");
+});
 WithContextValue WithConfig(Config::Key, std::move(Cfg));
 Mangler.adjust(Cmd);
   }
-  // Edits are applied in given order and before other mangling.
-  EXPECT_THAT(Cmd, ElementsAre(_, "FOO.CC", "--hello"));
+  // Edits are applied in given order and before other mangling and they always
+  // go before filename.
+  EXPECT_THAT(Cmd, ElementsAre(_, "--hello", "--", "FOO.CC"));
 }
 
 static std::string strip(llvm::StringRef Arg, llvm::StringRef Argv) {
@@ -335,9 +338,8 @@
 }
 
 TEST(PrintArgvTest, All) {
-  std::vector Args = {
-  "one", "two", "thr ee", "f\"o\"ur", "fi\\ve", "$"
-  };
+  std::vector Args = {"one",  "two","thr ee",
+   "f\"o\"ur", "fi\\ve", "$"};
   const char *Expected = R"(one two "thr ee" "f\"o\"ur" "fi\\ve" $)";
   EXPECT_EQ(Expected, printArgv(Args));
 }
Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -133,8 +133,9 @@
   Opts.ContextProvider = [](PathRef P) {
 Config C;
 if (P.endswith("foo.cpp"))
-  C.CompileFlags.Edits.push_back(
-  [](std::vector &Argv) { Argv.push_back("-Done=two"); });
+  C.CompileFlags.Edits.push_back([](std::vector &Argv) {
+Argv = tooling::getInsertArgumentAdjuster("-Done=two")(Argv, "");
+  });
 if (P.endswith("baz.cpp"))
   C.Index.Background = Config::BackgroundPolicy::Skip;
 return Context::current().derive(Config::Key, std::move(C));
Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -48,7 +48,7 @@
 #
 # ERR: ASTWorker building file {{.*}}foo.c version 0 with command
 # ERR: [{{.*}}clangd-test2]
-# ERR: clang -c foo.c -Wall -Werror
+# ERR: clang -c -Wall -Werror {{.*}} -- foo.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/CompileCommands.cpp
===
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -9,11 +9,14 @@
 #include "CompileCommands.h"
 #include "Config.h"
 #include "support/Logger.h"
+#include "support/Trace.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Debug.h"
@@ -188,11 +191,33 @@
   return Result;
 }
 
-CommandMangler CommandMangler::forTests() {
-  return CommandMangler();
-}
+CommandMangler CommandMangler::forTests() { return CommandMangler(); }
 
 void CommandMangler::adjust(std::vector &Cmd) const {
+  trace::Span S("AdjustCompileFlags");
+  auto &OptTable = clang::driver::getDriverOptTable();
+  // OriginalArgs needs to outlive ArgList.
+  llvm::SmallVector OriginalArgs;
+  OriginalArgs.reserve(Cmd.size());
+  for (const std::string &S : Cmd)
+OriginalArgs.push_back(S.c_str());
+  // ParseArgs propagates missig arg/opt counts on error, but preserves
+  // everything it could parse in ArgList. So we just ignore those counts.
+  unsigned IgnoredCount;

[PATCH] D106639: [clangd] Adjust compile flags to contain only the requested file as input

2021-07-23 Thread Kadir Cetinkaya 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 rGba5dd945ad91: [clangd] Adjust compile flags to contain only 
the requested file as input (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106639

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang-tools-extra/clangd/CompileCommands.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp

Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -59,7 +59,7 @@
   Argv.push_back(FullFilename);
 
   auto Mangler = CommandMangler::forTests();
-  Mangler.adjust(Inputs.CompileCommand.CommandLine);
+  Mangler.adjust(Inputs.CompileCommand.CommandLine, FullFilename);
   Inputs.CompileCommand.Filename = FullFilename;
   Inputs.CompileCommand.Directory = testRoot();
   Inputs.Contents = Code;
Index: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -43,7 +43,7 @@
   Mangler.ResourceDir = testPath("fake/resources");
   Mangler.Sysroot = testPath("fake/sysroot");
   std::vector Cmd = {"clang++", "--", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, ElementsAre(testPath("fake/clang++"),
"-resource-dir=" + testPath("fake/resources"),
"-isysroot", testPath("fake/sysroot"), "--",
@@ -54,7 +54,7 @@
   auto Mangler = CommandMangler::forTests();
   Mangler.ResourceDir = testPath("fake/resources");
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(Cmd, Contains("-resource-dir=" + testPath("fake/resources")));
 }
 
@@ -63,7 +63,7 @@
   Mangler.Sysroot = testPath("fake/sysroot");
 
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_THAT(llvm::join(Cmd, " "),
   HasSubstr("-isysroot " + testPath("fake/sysroot")));
 }
@@ -73,19 +73,19 @@
   Mangler.ClangPath = testPath("fake/clang");
 
   std::vector Cmd = {"clang++", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("fake/clang++"), Cmd.front());
 
   Cmd = {"unknown-binary", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("fake/unknown-binary"), Cmd.front());
 
   Cmd = {testPath("path/clang++"), "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ(testPath("path/clang++"), Cmd.front());
 
   Cmd = {"foo/unknown-binary", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ("foo/unknown-binary", Cmd.front());
 }
 
@@ -128,7 +128,7 @@
   auto Mangler = CommandMangler::forTests();
   Mangler.ClangPath = testPath("fake/clang");
   std::vector Cmd = {(TempDir + "/bin/foo").str(), "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   // Directory based on resolved symlink, basename preserved.
   EXPECT_EQ((TempDir + "/lib/foo").str(), Cmd.front());
 
@@ -145,13 +145,13 @@
   Mangler.ClangPath = testPath("fake/clang");
   // Driver found on PATH.
   Cmd = {"foo", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   // Found the symlink and resolved the path as above.
   EXPECT_EQ((TempDir + "/lib/foo").str(), Cmd.front());
 
   // Symlink not resolved with -no-canonical-prefixes.
   Cmd = {"foo", "-no-canonical-prefixes", "foo.cc"};
-  Mangler.adjust(Cmd);
+  Mangler.adjust(Cmd, "foo.cc");
   EXPECT_EQ((TempDir + "/bin/foo").str(), Cmd.front());
 }
 #endif
@@ -170,7 +170,7 @@
   Argv = tooling::getInsertArgumentAdjuster("--hello")(Argv, "");
 });
 WithContextValue WithConfig(Config::Key, std::move(Cfg));
-Mangler.adjust(Cmd);
+Mangler.adjust(Cmd, "foo.cc");
   }
   // Edits are applied in given order and before other mangling and they always
   // go before filename.
Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -48,7 +48,7 @@
 #
 # ERR: ASTWorker building file {{.*}}foo.c version 0 with command
 # ERR: [{{.*}}clangd-test2]
-# ERR: clang -c -Wall -Werror {{.*}} -- foo.c
+# ERR: clang -c -Wall -Werror {{.*

[PATCH] D98214: [clang-format] Fix aligning with linebreaks

2021-07-23 Thread Alexey Utkin via Phabricator via cfe-commits
baramin added a comment.

We have a regression after the fix:
CPP-25899  CLion formatting 
does not match what clang-format produces

if

  AlignConsecutiveAssignments: Consecutive

Additional two spaces before `=` were added to indentation while formatting

  void SomeFunc()
  {
  using DcgmNs::Timelib::FromLegacyTimestamp;
  using DcgmNs::Timelib::ToLegacyTimestamp;
  using DcgmNs::Utils::GetMaxAge;
  using namespace std::chrono;
  newWatcher.maxAgeUsec   = ToLegacyTimestamp(GetMaxAge(
FromLegacyTimestamp(monitorFrequencyUsec), 
seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));
  newWatcher.isSubscribed = subscribeForUpdates ? 1 : 0;
  }




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98214

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


[PATCH] D106642: [Analyzer][solver][NFC] print constraints deterministically (ordered by their string representation)

2021-07-23 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Thanks!

You got me thinking whether two symbols can have the same dump. We definitely 
don't want this to happen but there's also no reason to believe it doesn't, 
given that this wouldn't affect any actual behavior or any tests. Can we add an 
assert here that the symbol is always freshly added? In this case we'd at least 
know when that happens.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106642

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


[PATCH] D106262: [clang][analyzer] Use generic note tag in alpha.unix.Stream .

2021-07-23 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:236-242
+  const BugMessageMap BugMessages = {
+  {&BT_FileNull, "Assuming opening the stream fails here"},
+  {&BT_UseAfterClose, "Stream closed here"},
+  {&BT_UseAfterOpenFailed, "Assuming opening the stream fails here"},
+  {&BT_IndeterminatePosition, "Assuming this stream operation fails"},
+  {&BT_StreamEof, "Assuming stream reaches end-of-file here"},
+  {&BT_ResourceLeak, "Stream opened here"}};

Well this looks odd: for both `BT_StreamEof` AND `BT_IndeterminatePosition` we 
want to display a `NoteTag` for a failed `fseek`, for one you print "Assuming 
stream reaches end-of-file here", for the other, "Assuming this stream 
operation fails". This seems to contradict your comment in the fseek evaluating 
function:

```
If fseek failed, assume that the file position becomes indeterminate in any 
case.
```

Also, these `BugTypes` should be responsible for the *error message*, not the 
`NoteTag` message. I'd prefer if we mapped an enum to these strings 
(`NoteTagMsgKind`?), pass that as well to `constructNoteTag`, and allow the 
caller to decide that for which `BugTypes` the `NoteTag` is worth displaying 
for.

I think such a 4-argument `constructNoteTag` would capture best what we want 
here.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:387-391
+  /// Create a NoteTag to display a note if a later bug report is generated.
+  /// The `BT` should contain all bug types that could be caused by the
+  /// operation at this location.
+  /// If later on the path a problematic event (reported bug) happens with the
+  /// same type, the last place is found with a note tag with that bug type.

How about:

Create a `NoteTag` describing an stream operation (whether stream opening 
succeeds or fails, stream reaches EOF, etc).
As not all operations are interesting for all types of stream bugs (the stream 
being at an indeterminate file position is irrelevant to whether it leaks or 
not), callers can specify in `BT` for which `BugType`s should this note be 
displayed for.
Only the `NoteTag` closest to the error location will be added to the bug 
report.



Comment at: clang/test/Analysis/stream-note.c:51
+void check_note_fopen_fail() {
+  FILE *F = fopen("file", "r"); // expected-note {{Assuming opening the stream 
fails here}} expected-note {{Assuming pointer value is null}} expected-note 
{{'F' initialized here}}
+  fclose(F);// expected-warning {{Stream pointer might be 
NULL}}

I'd prefer an individual line for these `expected-.*` directives. Its down to 
personal preference, but I find that far easier to read.



Comment at: clang/test/Analysis/stream-note.c:36-41
-  FILE *F = fopen("file", "r"); // expected-note {{Stream opened here}}
+  FILE *F = fopen("file", "r");
   if (!F)
 // expected-note@-1 {{'F' is non-null}}
 // expected-note@-2 {{Taking false branch}}
 return;
-  F = freopen(0, "w", F); // expected-note {{Stream reopened here}}

Szelethus wrote:
> I think I preferred this, honestly.
Hmmm... I've given this some thought, and yes, I the stream misuse can indeed 
be captured starting from the last `freopen` call. The specialized message for 
reopen was nice, but I guess no actual information was lost by this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106262

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


[PATCH] D106535: [clangd] Use CommandMangler in TestTU

2021-07-23 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

One of your 4 commits in 
https://github.com/llvm/llvm-project/compare/f86570cd5241...ba5dd945ad91 broke 
check-clangd on arm macs:

http://45.33.8.238/macm1/14648/step_9.txt

Please take a look, and revert for now if it takes a while to fix. (And 
consider spreading out commits a bit, so it's clearer which one is to blame.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106535

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


[PATCH] D105904: [clangd] Support `#pragma mark` in the outline

2021-07-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 361246.
dgoldman added a comment.

Add in suggested algorithm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105904

Files:
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang/include/clang/Lex/PPCallbacks.h

Index: clang/include/clang/Lex/PPCallbacks.h
===
--- clang/include/clang/Lex/PPCallbacks.h
+++ clang/include/clang/Lex/PPCallbacks.h
@@ -492,6 +492,11 @@
 Second->PragmaComment(Loc, Kind, Str);
   }
 
+  void PragmaMark(SourceLocation Loc, StringRef Trivia) override {
+First->PragmaMark(Loc, Trivia);
+Second->PragmaMark(Loc, Trivia);
+  }
+
   void PragmaDetectMismatch(SourceLocation Loc, StringRef Name,
 StringRef Value) override {
 First->PragmaDetectMismatch(Loc, Name, Value);
Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -1027,6 +1027,105 @@
 AllOf(WithName("-pur"), WithKind(SymbolKind::Method));
 }
 
+TEST(DocumentSymbolsTest, PragmaMarkGroups) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $DogDef[[@interface Dog
+  @end]]
+
+  $DogImpl[[@implementation Dog
+
+  + (id)sharedDoggo { return 0; }
+
+  #pragma $Overrides[[mark - Overrides
+
+  - (id)init {
+return self;
+  }
+  - (void)bark {}]]
+
+  #pragma $Specifics[[mark - Dog Specifics
+
+  - (int)isAGoodBoy {
+return 1;
+  }]]
+  @]]end  // FIXME: Why doesn't this include the 'end'?
+
+  #pragma $End[[mark - End
+]]
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+  getSymbols(TU.build()),
+  ElementsAre(
+  AllOf(WithName("Dog"), SymRange(Main.range("DogDef"))),
+  AllOf(WithName("Dog"), SymRange(Main.range("DogImpl")),
+Children(AllOf(WithName("+sharedDoggo"),
+   WithKind(SymbolKind::Method)),
+ AllOf(WithName("Overrides"),
+   SymRange(Main.range("Overrides")),
+   Children(AllOf(WithName("-init"),
+  WithKind(SymbolKind::Method)),
+AllOf(WithName("-bark"),
+  WithKind(SymbolKind::Method,
+ AllOf(WithName("Dog Specifics"),
+   SymRange(Main.range("Specifics")),
+   Children(AllOf(WithName("-isAGoodBoy"),
+  WithKind(SymbolKind::Method)),
+  AllOf(WithName("End"), SymRange(Main.range("End");
+}
+
+TEST(DocumentSymbolsTest, PragmaMarkGroupsNoNesting) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  #pragma mark Helpers
+  void helpA(id obj) {}
+
+  #pragma mark -
+  #pragma mark Core
+
+  void coreMethod() {}
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(getSymbols(TU.build()),
+  ElementsAre(AllOf(WithName("Helpers")), AllOf(WithName("helpA")),
+  AllOf(WithName("(unnamed group)")),
+  AllOf(WithName("Core")),
+  AllOf(WithName("coreMethod";
+}
+
+TEST(DocumentSymbolsTest, SymbolsAreSorted) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  @interface MYObject
+  @end
+
+  void someFunctionAbove() {}
+
+  @implementation MYObject
+  - (id)init { return self; }
+
+  void someHelperFunction() {}
+
+  - (void)retain {}
+  - (void)release {}
+  @end
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(getSymbols(TU.build()),
+  ElementsAre(AllOf(WithName("MYObject")),
+  AllOf(WithName("someFunctionAbove")),
+  // FIXME: This should be nested under MYObject below.
+  AllOf(WithName("someHelperFunction")),
+  AllOf(WithName("MYObject"),
+Children(AllOf(WithName("-init")),
+  

[PATCH] D105904: [clangd] Support `#pragma mark` in the outline

2021-07-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman added inline comments.



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:535
+/// by range.
+std::vector mergePragmas(std::vector &Syms,
+ std::vector 
&Pragmas,

dgoldman wrote:
> sammccall wrote:
> > FWIW the flow control/how we make progress seem hard to follow here to me.
> > 
> > In particular I think I'm struggling with the statefulness of "is there an 
> > open mark group".
> > 
> > Possible simplifications:
> >  - define a dummy root symbol, which seems clearer than the vector 
> > + range
> >  - avoid reverse-sorting the list of pragma symbols, and just consume from 
> > the front of an ArrayRef instead
> >  - make the outer loop over pragmas, rather than symbols. It would first 
> > check if the pragma belongs directly here or not, and if so, loop over 
> > symbols to work out which should become children. This seems very likely to 
> > be efficient enough in practice (few pragmas, or most children are grouped 
> > into pragmas)
> > define a dummy root symbol, which seems clearer than the vector + 
> > range
> 
> I guess? Then we'd take in a `DocumentSymbol & and a 
> ArrayRef & (or just by value and then return it as well). 
> The rest would be the same though
> 
> > In particular I think I'm struggling with the statefulness of "is there an 
> > open mark group".
> 
> We need to track the current open group if there is one in order to move 
> children to it.
> 
> > make the outer loop over pragmas, rather than symbols. It would first check 
> > if the pragma belongs directly here or not, and if so, loop over symbols to 
> > work out which should become children. This seems very likely to be 
> > efficient enough in practice (few pragmas, or most children are grouped 
> > into pragmas)
> 
> The important thing here is knowing where the pragma mark ends - if it 
> doesn't, it actually gets all of the children. So we'd have to peak at the 
> next pragma mark, add all symbols before it to us as children, and then 
> potentially recurse to nest it inside of a symbol. I'll try it out and see if 
> it's simpler.
> 
> 
I've implemented your suggestion. I don't think it's simpler, but LMK, maybe it 
can be improved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105904

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


[PATCH] D105904: [clangd] Support `#pragma mark` in the outline

2021-07-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 361247.
dgoldman added a comment.

minor comment fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105904

Files:
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang/include/clang/Lex/PPCallbacks.h

Index: clang/include/clang/Lex/PPCallbacks.h
===
--- clang/include/clang/Lex/PPCallbacks.h
+++ clang/include/clang/Lex/PPCallbacks.h
@@ -492,6 +492,11 @@
 Second->PragmaComment(Loc, Kind, Str);
   }
 
+  void PragmaMark(SourceLocation Loc, StringRef Trivia) override {
+First->PragmaMark(Loc, Trivia);
+Second->PragmaMark(Loc, Trivia);
+  }
+
   void PragmaDetectMismatch(SourceLocation Loc, StringRef Name,
 StringRef Value) override {
 First->PragmaDetectMismatch(Loc, Name, Value);
Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -1027,6 +1027,105 @@
 AllOf(WithName("-pur"), WithKind(SymbolKind::Method));
 }
 
+TEST(DocumentSymbolsTest, PragmaMarkGroups) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $DogDef[[@interface Dog
+  @end]]
+
+  $DogImpl[[@implementation Dog
+
+  + (id)sharedDoggo { return 0; }
+
+  #pragma $Overrides[[mark - Overrides
+
+  - (id)init {
+return self;
+  }
+  - (void)bark {}]]
+
+  #pragma $Specifics[[mark - Dog Specifics
+
+  - (int)isAGoodBoy {
+return 1;
+  }]]
+  @]]end  // FIXME: Why doesn't this include the 'end'?
+
+  #pragma $End[[mark - End
+]]
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+  getSymbols(TU.build()),
+  ElementsAre(
+  AllOf(WithName("Dog"), SymRange(Main.range("DogDef"))),
+  AllOf(WithName("Dog"), SymRange(Main.range("DogImpl")),
+Children(AllOf(WithName("+sharedDoggo"),
+   WithKind(SymbolKind::Method)),
+ AllOf(WithName("Overrides"),
+   SymRange(Main.range("Overrides")),
+   Children(AllOf(WithName("-init"),
+  WithKind(SymbolKind::Method)),
+AllOf(WithName("-bark"),
+  WithKind(SymbolKind::Method,
+ AllOf(WithName("Dog Specifics"),
+   SymRange(Main.range("Specifics")),
+   Children(AllOf(WithName("-isAGoodBoy"),
+  WithKind(SymbolKind::Method)),
+  AllOf(WithName("End"), SymRange(Main.range("End");
+}
+
+TEST(DocumentSymbolsTest, PragmaMarkGroupsNoNesting) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  #pragma mark Helpers
+  void helpA(id obj) {}
+
+  #pragma mark -
+  #pragma mark Core
+
+  void coreMethod() {}
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(getSymbols(TU.build()),
+  ElementsAre(AllOf(WithName("Helpers")), AllOf(WithName("helpA")),
+  AllOf(WithName("(unnamed group)")),
+  AllOf(WithName("Core")),
+  AllOf(WithName("coreMethod";
+}
+
+TEST(DocumentSymbolsTest, SymbolsAreSorted) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  @interface MYObject
+  @end
+
+  void someFunctionAbove() {}
+
+  @implementation MYObject
+  - (id)init { return self; }
+
+  void someHelperFunction() {}
+
+  - (void)retain {}
+  - (void)release {}
+  @end
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(getSymbols(TU.build()),
+  ElementsAre(AllOf(WithName("MYObject")),
+  AllOf(WithName("someFunctionAbove")),
+  // FIXME: This should be nested under MYObject below.
+  AllOf(WithName("someHelperFunction")),
+  AllOf(WithName("MYObject"),
+Children(AllOf(WithName("-init")),
+   

[clang-tools-extra] 04e21fb - Revert "[clangd] Adjust compile flags to contain only the requested file as input"

2021-07-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-07-23T17:58:11+02:00
New Revision: 04e21fbc44c145d5599ef8db9aaf66b159107f33

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

LOG: Revert "[clangd] Adjust compile flags to contain only the requested file 
as input"

This reverts commit ba5dd945ad9124f24452987be64040a6ea6cd25e.

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/CompileCommands.h
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/test/did-change-configuration-params.test
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index 4c1646ed9e05c..ba21e81d3fb52 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -13,7 +13,6 @@
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
-#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -194,8 +193,7 @@ CommandMangler CommandMangler::detect() {
 
 CommandMangler CommandMangler::forTests() { return CommandMangler(); }
 
-void CommandMangler::adjust(std::vector &Cmd,
-llvm::StringRef File) const {
+void CommandMangler::adjust(std::vector &Cmd) const {
   trace::Span S("AdjustCompileFlags");
   auto &OptTable = clang::driver::getDriverOptTable();
   // OriginalArgs needs to outlive ArgList.
@@ -206,27 +204,18 @@ void CommandMangler::adjust(std::vector &Cmd,
   // ParseArgs propagates missig arg/opt counts on error, but preserves
   // everything it could parse in ArgList. So we just ignore those counts.
   unsigned IgnoredCount;
-  // Drop the executable name, as ParseArgs doesn't expect it. This means
-  // indices are actually of by one between ArgList and OriginalArgs.
-  auto ArgList =
-  OptTable.ParseArgs(llvm::makeArrayRef(OriginalArgs).drop_front(),
- IgnoredCount, IgnoredCount);
+  auto ArgList = OptTable.ParseArgs(OriginalArgs, IgnoredCount, IgnoredCount);
 
   // Move the inputs to the end, separated via `--` from flags. This ensures
   // modifications done in the following steps apply in more cases (like 
setting
   // -x, which only affects inputs that come after it).
   if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
-// Drop all the inputs and only add one for the current file.
-llvm::SmallVector IndicesToDrop;
-for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
-  IndicesToDrop.push_back(Input->getIndex());
-llvm::sort(IndicesToDrop);
-llvm::for_each(llvm::reverse(IndicesToDrop),
-   // +1 to account for the executable name in Cmd[0] that
-   // doesn't exist in ArgList.
-   [&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
-Cmd.push_back("--");
-Cmd.push_back(File.str());
+// In theory there might be more than one input, but clangd can't deal with
+// them anyway.
+if (auto *Input = ArgList.getLastArg(driver::options::OPT_INPUT)) {
+  Cmd.insert(Cmd.end(), {"--", Input->getAsString(ArgList)});
+  Cmd.erase(Cmd.begin() + Input->getIndex());
+}
   }
 
   for (auto &Edit : Config::current().CompileFlags.Edits)
@@ -276,7 +265,7 @@ CommandMangler::operator 
clang::tooling::ArgumentsAdjuster() && {
   return [Mangler = std::make_shared(std::move(*this))](
  const std::vector &Args, llvm::StringRef File) {
 auto Result = Args;
-Mangler->adjust(Result, File);
+Mangler->adjust(Result);
 return Result;
   };
 }

diff  --git a/clang-tools-extra/clangd/CompileCommands.h 
b/clang-tools-extra/clangd/CompileCommands.h
index 50c1a3571ec42..759472413fdaf 100644
--- a/clang-tools-extra/clangd/CompileCommands.h
+++ b/clang-tools-extra/clangd/CompileCommands.h
@@ -12,7 +12,6 @@
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringRef.h"
 #include 
 #include 
 #include 
@@ -47,7 +46,7 @@ struct CommandMangler {
   //  - on mac, find clang and isysroot by querying the `xcrun` launcher
   static CommandMangler detect();
 
-  void adjust(std::vector &Cmd, llvm::StringRef File) const;
+  void adjust(std::vector &Cmd) const;
   explicit operator clang::tooling::ArgumentsAdjuster() &&;
 
 private:

diff  --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index 1c66062fb9b3f..73f19aba

[clang-tools-extra] e7590d7 - Revert "[clangd] Canonicalize compile flags before applying edits"

2021-07-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-07-23T18:20:52+02:00
New Revision: e7590d748adfa6afb67c4fb4f72c6f7eeb812734

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

LOG: Revert "[clangd] Canonicalize compile flags before applying edits"

This reverts commit 7cc8a8e3849dc4044cc799e2c1f6cc241b851b70.

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/test/did-change-configuration-params.test
clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index ba21e81d3fb52..ffc66303c9fc4 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -9,14 +9,11 @@
 #include "CompileCommands.h"
 #include "Config.h"
 #include "support/Logger.h"
-#include "support/Trace.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Debug.h"
@@ -191,33 +188,11 @@ CommandMangler CommandMangler::detect() {
   return Result;
 }
 
-CommandMangler CommandMangler::forTests() { return CommandMangler(); }
+CommandMangler CommandMangler::forTests() {
+  return CommandMangler();
+}
 
 void CommandMangler::adjust(std::vector &Cmd) const {
-  trace::Span S("AdjustCompileFlags");
-  auto &OptTable = clang::driver::getDriverOptTable();
-  // OriginalArgs needs to outlive ArgList.
-  llvm::SmallVector OriginalArgs;
-  OriginalArgs.reserve(Cmd.size());
-  for (const std::string &S : Cmd)
-OriginalArgs.push_back(S.c_str());
-  // ParseArgs propagates missig arg/opt counts on error, but preserves
-  // everything it could parse in ArgList. So we just ignore those counts.
-  unsigned IgnoredCount;
-  auto ArgList = OptTable.ParseArgs(OriginalArgs, IgnoredCount, IgnoredCount);
-
-  // Move the inputs to the end, separated via `--` from flags. This ensures
-  // modifications done in the following steps apply in more cases (like 
setting
-  // -x, which only affects inputs that come after it).
-  if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
-// In theory there might be more than one input, but clangd can't deal with
-// them anyway.
-if (auto *Input = ArgList.getLastArg(driver::options::OPT_INPUT)) {
-  Cmd.insert(Cmd.end(), {"--", Input->getAsString(ArgList)});
-  Cmd.erase(Cmd.begin() + Input->getIndex());
-}
-  }
-
   for (auto &Edit : Config::current().CompileFlags.Edits)
 Edit(Cmd);
 
@@ -240,7 +215,7 @@ void CommandMangler::adjust(std::vector &Cmd) 
const {
 
   // Don't set `-isysroot` if it is already set or if `--sysroot` is set.
   // `--sysroot` is a superset of the `-isysroot` argument.
-  if (Sysroot && !Has("--sysroot") && !Has("-isysroot")) {
+  if (Sysroot && !Has("-isysroot") && !Has("--sysroot")) {
 ToAppend.push_back("-isysroot");
 ToAppend.push_back(*Sysroot);
   }

diff  --git 
a/clang-tools-extra/clangd/test/did-change-configuration-params.test 
b/clang-tools-extra/clangd/test/did-change-configuration-params.test
index e90e26c0d3a7a..19d41d0812e23 100644
--- a/clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ b/clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -48,7 +48,7 @@
 #
 # ERR: ASTWorker building file {{.*}}foo.c version 0 with command
 # ERR: [{{.*}}clangd-test2]
-# ERR: clang -c -Wall -Werror {{.*}} -- foo.c
+# ERR: clang -c foo.c -Wall -Werror
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---

diff  --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp 
b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
index 79da2f059a8c2..de8ff2b4a14e1 100644
--- a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -133,9 +133,8 @@ TEST_F(BackgroundIndexTest, Config) {
   Opts.ContextProvider = [](PathRef P) {
 Config C;
 if (P.endswith("foo.cpp"))
-  C.CompileFlags.Edits.push_back([](std::vector &Argv) {
-Argv = tooling::getInsertArgumentAdjuster("-Done=two")(Argv, "");
-  });
+  C.CompileFlags.Edits.push_back(
+  [](std::vector &Argv) { Argv.push_back("-Done=two"); });
 if (P.endswith("baz.cpp"))
   C.Index.Background = Config::BackgroundPolicy::Skip;
 return Context::current().derive(Config::Key, std::move(C));

diff  --git a/clang-tools-extra/clangd/unittests/Compile

[PATCH] D106347: [PoC][RISCV] Encode arch information in a new module flag meatadata 'riscv-isa-features'.

2021-07-23 Thread Zakk Chen via Phabricator via cfe-commits
khchen added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:835
+llvm::RISCVISAInfo::filterISAStrings(Features);
+std::vector Ops;
+if (Features.empty()) {

jrtc27 wrote:
> Why is this building a list? Just use a string so it's in the same format as 
> the function attributes? We already have parsers for that. Yes, it means you 
> do a small amount of redundant work but having a single format in the IR for 
> representing the same thing in every place is better than having multiple 
> different ways of representing the same thing.
Because I think maybe the merge behavior `AppendUnique` is the best way to 
merge two module with different value of metadata flag, and it requires a 
metadata node with operands list.
Personally, I did not like to to have a new merge behavior to merge two 
target-features string, but maybe there is another better merging behavior I 
never thought,

In addition, some target features are not related to extension information, for 
example, +relax, +save-restore. Should we really need to record those 
unnecessary information in module?

What do you think?







Comment at: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp:187
+dyn_cast_or_null(M.getModuleFlag("riscv-isa-features"));
+if (STI->getFeatureString().empty() && ISAFeatureNodes) {
+  std::vector Features;

jrtc27 wrote:
> This doesn't make sense. The module flag should have been parsed and applied 
> to the subtarget long ago. And an empty feature string means no features, not 
> that they're missing. The fact that you need to change this code here is a 
> sign that code elsewhere is wrong.
What's excepted elf attribute if llc with -mattr=+f,+d but the 
riscv-isa-features module flag is +a,+c+m?
I think it will be +f, +d, so we need to make sure -mattr is empty before use 
the module flag.  Does it make sense?

> The module flag should have been parsed and applied to the subtarget long 
> ago. 
Sorry, I didn't understand it. The module flag `riscv-isa-features` is not 
applied to subtarget, I only use it to generate the correct extension 
.attribute. 

Maybe I misunderstood something?




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106347

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


[PATCH] D106302: Implement P1937 consteval in unevaluated contexts

2021-07-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/SemaCXX/cxx2a-consteval.cpp:612
+static_assert(is_same::value);
+
+} // namespace unevaluated

aaron.ballman wrote:
> cor3ntin wrote:
> > cor3ntin wrote:
> > > aaron.ballman wrote:
> > > > Here's an interesting test case:
> > > > ```
> > > > #include 
> > > > 
> > > > struct S {
> > > >   virtual void f();
> > > > };
> > > > 
> > > > struct D : S {
> > > >   void f() override;
> > > > };
> > > > 
> > > > consteval S *get_s() { return nullptr; }
> > > > 
> > > > void func() {
> > > >   (void)typeid(*get_s());
> > > > }
> > > > ```
> > > > `typeid` still needs to evaluate its operand (due to the polymorphic 
> > > > return type of `*get_s()`), and so you should get a diagnostic about 
> > > > evaluating the side effects by calling `get_s()`. I think this then 
> > > > runs into https://eel.is/c++draft/expr.const#13.sentence-3 and we 
> > > > should diagnose?
> > > Not sure!
> > > Also, in the context of this pr, the question is also whether 
> > > `decltype(typeid(*get_s()))` should be ill-formed I think
> > Actually, I'm reading the wording again and I really don't know anymore.
> > `get_s()` is a constant expression, right?
> > `*get_s()` is not, I think but is that relevant here
> > 
> > I played with a bunch of things in the code but the more I look at it the 
> > less I'm convinced an action is needed.
> The changes to `Sema::CheckForImmediateInvocation()` to check for an 
> unevaluated context and https://eel.is/c++draft/expr.const#13.sentence-3 that 
> say an immediate invocation shall be a constant expression are what got me 
> thinking about this code snippet in the first place. I was trying to decide 
> whether `isUnevaluatedContext()` is correct or not because with `typeid`, it 
> is potentially evaluated (so sometimes it's unevaluated).
> 
> Interestingly, everyone comes up with a different answer: 
> https://godbolt.org/z/TqjGh1he6 and I don't (yet) know who is correct.
@rsmith Can you enlighten us here?
My take is that `get_s()` is a constant expression and therefore an immediate 
invocation. independently of what `*get_s()` does but I'm not sure if that's a 
correct reading.  

Thanks a lot!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106302

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


[PATCH] D106577: [clang] Define __STDC_ISO_10646__

2021-07-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D106577#2899715 , @aaron.ballman 
wrote:

> In D106577#2899711 , @joerg wrote:
>
>> This patch is certainly wrong for NetBSD as the wchar_t encoding is up to 
>> the specific locale charset and *not* UCS-2 or UCS-4 for certain legacy 
>> encodings like the various shift encodings in East Asia.
>
> How does the value of a macro get impacted by a runtime locale?

More importantly, given that clang unconditionally encodes wide strings as 
UTF-32, how can, for example `towupper(L'α')` produce a sensible result?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106577

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


  1   2   >