[PATCH] D89158: [NewPM] Run all EP callbacks under -O0

2020-10-25 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 300575.
aeubanks added a comment.

rebase
add assert for O0


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89158

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/bpf-O0.c
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/test/CodeGen/BPF/optnone-2.ll
  llvm/test/Other/new-pm-O0-ep-callbacks.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -94,7 +94,7 @@
 cl::Hidden);
 static cl::opt PipelineStartEPPipeline(
 "passes-ep-pipeline-start",
-cl::desc("A textual description of the function pass pipeline inserted at "
+cl::desc("A textual description of the module pass pipeline inserted at "
  "the PipelineStart extension point into default pipelines"),
 cl::Hidden);
 static cl::opt OptimizerLastEPPipeline(
Index: llvm/test/Other/new-pm-O0-ep-callbacks.ll
===
--- /dev/null
+++ llvm/test/Other/new-pm-O0-ep-callbacks.ll
@@ -0,0 +1,24 @@
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-late-loop-optimizations=no-op-loop -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-loop-optimizer-end=no-op-loop -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-scalar-optimizer-late=no-op-function -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-cgscc-optimizer-late=no-op-cgscc -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-vectorizer-start=no-op-function -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-pipeline-start=no-op-module -passes='default' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-optimizer-last=no-op-function -passes='default' 2>&1 < %s | FileCheck %s
+
+; CHECK: Running pass: NoOp
+
+declare void @bar() local_unnamed_addr
+
+define void @foo(i32 %n) local_unnamed_addr {
+entry:
+  br label %loop
+loop:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
+  %iv.next = add i32 %iv, 1
+  tail call void @bar()
+  %cmp = icmp eq i32 %iv, %n
+  br i1 %cmp, label %exit, label %loop
+exit:
+  ret void
+}
Index: llvm/test/CodeGen/BPF/optnone-2.ll
===
--- llvm/test/CodeGen/BPF/optnone-2.ll
+++ llvm/test/CodeGen/BPF/optnone-2.ll
@@ -1,5 +1,5 @@
 ; RUN: opt < %s -passes='default' | llc -march=bpfel -filetype=asm -o /dev/null -
-; TODO: add -O0 once that's supported
+; RUN: opt < %s -passes='default' | llc -march=bpfel -filetype=asm -o /dev/null -
 
 ; IR generated by
 ; $ cat /tmp/a.c
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -1653,6 +1653,49 @@
   return MPM;
 }
 
+void PassBuilder::runRegisteredEPCallbacks(ModulePassManager ,
+   OptimizationLevel Level,
+   bool DebugLogging) {
+  assert(Level == OptimizationLevel::O0 &&
+ "runRegisteredEPCallbacks should only be used with O0");
+  for (auto  : PipelineStartEPCallbacks)
+C(MPM);
+  if (!LateLoopOptimizationsEPCallbacks.empty()) {
+LoopPassManager LPM(DebugLogging);
+for (auto  : LateLoopOptimizationsEPCallbacks)
+  C(LPM, Level);
+MPM.addPass(createModuleToFunctionPassAdaptor(
+createFunctionToLoopPassAdaptor(std::move(LPM;
+  }
+  if (!LoopOptimizerEndEPCallbacks.empty()) {
+LoopPassManager LPM(DebugLogging);
+for (auto  : LoopOptimizerEndEPCallbacks)
+  C(LPM, Level);
+MPM.addPass(createModuleToFunctionPassAdaptor(
+createFunctionToLoopPassAdaptor(std::move(LPM;
+  }
+  if (!ScalarOptimizerLateEPCallbacks.empty()) {
+FunctionPassManager FPM(DebugLogging);
+for (auto  : ScalarOptimizerLateEPCallbacks)
+  C(FPM, Level);
+MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+  }
+  if (!CGSCCOptimizerLateEPCallbacks.empty()) {
+CGSCCPassManager CGPM(DebugLogging);
+for (auto  : CGSCCOptimizerLateEPCallbacks)
+  C(CGPM, Level);
+MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
+  }
+  if (!VectorizerStartEPCallbacks.empty()) {
+FunctionPassManager FPM(DebugLogging);
+for (auto  : VectorizerStartEPCallbacks)
+  C(FPM, Level);
+MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+  }
+  for (auto  : OptimizerLastEPCallbacks)
+C(MPM, Level);
+}
+
 AAManager PassBuilder::buildDefaultAAPipeline() {
   

[PATCH] D90129: Source location for -Wignored-qualifiers on lambda trailing return type

2020-10-25 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:3092-3094
+SourceLocation Loc = D.getIdentifierLoc();
+if (Loc.isInvalid())
+  Loc = FTI.getRParenLoc();

I'm open to always using the `RParenLoc`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90129

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


[PATCH] D90129: Source location for -Wignored-qualifiers on lambda trailing return type

2020-10-25 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert created this revision.
aaronpuchert added reviewers: aaron.ballman, rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
aaronpuchert requested review of this revision.

We don't have a source location for trailing return types at the moment,
and the current fallback (the identifier location) doesn't work for
lambdas. So instead we take the location of the right paranthesis, which
seems as close to the trailing return type as we can get.

Fixes PR47732.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90129

Files:
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/return.cpp


Index: clang/test/SemaCXX/return.cpp
===
--- clang/test/SemaCXX/return.cpp
+++ clang/test/SemaCXX/return.cpp
@@ -65,6 +65,10 @@
 trailing_return_type() -> // expected-warning {{'const' type qualifier on 
return type has no effect}}
 const int;
 
+auto trailing_return_type_lambda =
+[](const int ) -> // expected-warning {{'const' type qualifier on return 
type has no effect}}
+const int { return x; };
+
 const int ret_array()[4]; // expected-error {{cannot return array}}
 }
 
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -3084,12 +3084,16 @@
 static void diagnoseRedundantReturnTypeQualifiers(Sema , QualType RetTy,
   Declarator ,
   unsigned FunctionChunkIndex) 
{
-  if (D.getTypeObject(FunctionChunkIndex).Fun.hasTrailingReturnType()) {
+  const DeclaratorChunk::FunctionTypeInfo  =
+  D.getTypeObject(FunctionChunkIndex).Fun;
+  if (FTI.hasTrailingReturnType()) {
 // FIXME: TypeSourceInfo doesn't preserve location information for
 // qualifiers.
+SourceLocation Loc = D.getIdentifierLoc();
+if (Loc.isInvalid())
+  Loc = FTI.getRParenLoc();
 S.diagnoseIgnoredQualifiers(diag::warn_qual_return_type,
-RetTy.getLocalCVRQualifiers(),
-D.getIdentifierLoc());
+RetTy.getLocalCVRQualifiers(), Loc);
 return;
   }
 


Index: clang/test/SemaCXX/return.cpp
===
--- clang/test/SemaCXX/return.cpp
+++ clang/test/SemaCXX/return.cpp
@@ -65,6 +65,10 @@
 trailing_return_type() -> // expected-warning {{'const' type qualifier on return type has no effect}}
 const int;
 
+auto trailing_return_type_lambda =
+[](const int ) -> // expected-warning {{'const' type qualifier on return type has no effect}}
+const int { return x; };
+
 const int ret_array()[4]; // expected-error {{cannot return array}}
 }
 
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -3084,12 +3084,16 @@
 static void diagnoseRedundantReturnTypeQualifiers(Sema , QualType RetTy,
   Declarator ,
   unsigned FunctionChunkIndex) {
-  if (D.getTypeObject(FunctionChunkIndex).Fun.hasTrailingReturnType()) {
+  const DeclaratorChunk::FunctionTypeInfo  =
+  D.getTypeObject(FunctionChunkIndex).Fun;
+  if (FTI.hasTrailingReturnType()) {
 // FIXME: TypeSourceInfo doesn't preserve location information for
 // qualifiers.
+SourceLocation Loc = D.getIdentifierLoc();
+if (Loc.isInvalid())
+  Loc = FTI.getRParenLoc();
 S.diagnoseIgnoredQualifiers(diag::warn_qual_return_type,
-RetTy.getLocalCVRQualifiers(),
-D.getIdentifierLoc());
+RetTy.getLocalCVRQualifiers(), Loc);
 return;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 180548c - [X86] VEX/EVEX prefix doesn't work for inline assembly.

2020-10-25 Thread via cfe-commits

Author: Liu, Chen3
Date: 2020-10-26T08:37:45+08:00
New Revision: 180548c5c7848f82ceac5d6a3528a8cb14c20fed

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

LOG: [X86] VEX/EVEX prefix doesn't work for inline assembly.

For now, we lost the encoding information if we using inline assembly.
The encoding for the inline assembly will keep default even if we add
the vex/evex prefix.

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

Added: 
clang/test/CodeGen/X86/att-inline-asm-prefix.c

Modified: 
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp

Removed: 




diff  --git a/clang/test/CodeGen/X86/att-inline-asm-prefix.c 
b/clang/test/CodeGen/X86/att-inline-asm-prefix.c
new file mode 100644
index ..9bd0d937d86e
--- /dev/null
+++ b/clang/test/CodeGen/X86/att-inline-asm-prefix.c
@@ -0,0 +1,25 @@
+// RUN:%clang_cc1 %s -ferror-limit 0 -triple=x86_64-pc -target-feature 
+avx512f -target-feature +avx2 -target-feature +avx512vl -S -o -  | FileCheck 
%s -check-prefix CHECK
+
+// This test is to check if the prefix in inline assembly is correctly
+// preserved.
+
+void check_inline_prefix(void) {
+  __asm__ (
+// CHECK: vcvtps2pd %xmm0, %xmm1
+// CHECK: {vex} vcvtps2pd %xmm0, %xmm1
+// CHECK: {vex2} vcvtps2pd %xmm0, %xmm1
+// CHECK: {vex3} vcvtps2pd %xmm0, %xmm1
+// CHECK: {evex} vcvtps2pd %xmm0, %xmm1
+// CHECK: movl $1, (%rax)
+// CHECK: {disp8}  movl $1, (%rax)
+// CHECK: {disp32} movl $1, (%rax)
+"vcvtps2pd %xmm0, %xmm1\n\t"
+"{vex} vcvtps2pd %xmm0, %xmm1\n\t"
+"{vex2} vcvtps2pd %xmm0, %xmm1\n\t"
+"{vex3} vcvtps2pd %xmm0, %xmm1\n\t"
+"{evex} vcvtps2pd %xmm0, %xmm1\n\t"
+"movl $1, (%rax)\n\t"
+"{disp8} movl $1, (%rax)\n\t"
+"{disp32} movl $1, (%rax)\n\t"
+  );
+}

diff  --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp 
b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index f13f9cb76437..122702a28f48 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -83,6 +83,7 @@ class X86AsmParser : public MCTargetAsmParser {
   enum VEXEncoding {
 VEXEncoding_Default,
 VEXEncoding_VEX,
+VEXEncoding_VEX2,
 VEXEncoding_VEX3,
 VEXEncoding_EVEX,
   };
@@ -2818,8 +2819,10 @@ bool X86AsmParser::ParseInstruction(ParseInstructionInfo 
, StringRef Name,
 return Error(Parser.getTok().getLoc(), "Expected '}'");
   Parser.Lex(); // Eat curly.
 
-  if (Prefix == "vex" || Prefix == "vex2")
+  if (Prefix == "vex")
 ForcedVEXEncoding = VEXEncoding_VEX;
+  else if (Prefix == "vex2")
+ForcedVEXEncoding = VEXEncoding_VEX2;
   else if (Prefix == "vex3")
 ForcedVEXEncoding = VEXEncoding_VEX3;
   else if (Prefix == "evex")
@@ -3837,6 +3840,7 @@ unsigned X86AsmParser::checkTargetMatchPredicate(MCInst 
) {
 return Match_Unsupported;
 
   if ((ForcedVEXEncoding == VEXEncoding_VEX ||
+   ForcedVEXEncoding == VEXEncoding_VEX2 ||
ForcedVEXEncoding == VEXEncoding_VEX3) &&
   (MCID.TSFlags & X86II::EncodingMask) != X86II::VEX)
 return Match_Unsupported;
@@ -3879,10 +3883,16 @@ bool X86AsmParser::MatchAndEmitATTInstruction(SMLoc 
IDLoc, unsigned ,
 
   MCInst Inst;
 
-  // If VEX3 encoding is forced, we need to pass the USE_VEX3 flag to the
-  // encoder.
-  if (ForcedVEXEncoding == VEXEncoding_VEX3)
+  // If VEX/EVEX encoding is forced, we need to pass the USE_* flag to the
+  // encoder and printer.
+  if (ForcedVEXEncoding == VEXEncoding_VEX)
+Prefixes |= X86::IP_USE_VEX;
+  else if (ForcedVEXEncoding == VEXEncoding_VEX2)
+Prefixes |= X86::IP_USE_VEX2;
+  else if (ForcedVEXEncoding == VEXEncoding_VEX3)
 Prefixes |= X86::IP_USE_VEX3;
+  else if (ForcedVEXEncoding == VEXEncoding_EVEX)
+Prefixes |= X86::IP_USE_EVEX;
 
   // Set encoded flags for {disp8} and {disp32}.
   if (ForcedDispEncoding == DispEncoding_Disp8)

diff  --git a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h 
b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
index b6e8d4813d4c..8b8fccfb5a41 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
@@ -55,15 +55,18 @@ namespace X86 {
   /// The constants to describe instr prefixes if there are
   enum IPREFIXES {
 IP_NO_PREFIX = 0,
-IP_HAS_OP_SIZE = 1,
-IP_HAS_AD_SIZE = 2,
-IP_HAS_REPEAT_NE = 4,
-IP_HAS_REPEAT = 8,
-IP_HAS_LOCK = 16,
-IP_HAS_NOTRACK = 32,
-IP_USE_VEX3 = 64,
-IP_USE_DISP8 = 128,
-IP_USE_DISP32 = 256,
+IP_HAS_OP_SIZE =   1U << 0,
+IP_HAS_AD_SIZE =   1U << 1,
+IP_HAS_REPEAT_NE = 1U << 2,
+IP_HAS_REPEAT =1U << 3,
+IP_HAS_LOCK =  1U << 4,
+

[PATCH] D90009: [X86] VEX/EVEX prefix doesn't work for inline assembly.

2020-10-25 Thread LiuChen 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 rG180548c5c784: [X86] VEX/EVEX prefix doesnt work for 
inline assembly. (authored by LiuChen3).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90009

Files:
  clang/test/CodeGen/X86/att-inline-asm-prefix.c
  llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
  llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp

Index: llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp
===
--- llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp
+++ llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp
@@ -346,6 +346,21 @@
 O << "\trepne\t";
   else if (Flags & X86::IP_HAS_REPEAT)
 O << "\trep\t";
+
+  // These all require a pseudo prefix
+  if (Flags & X86::IP_USE_VEX)
+O << "\t{vex}";
+  else if (Flags & X86::IP_USE_VEX2)
+O << "\t{vex2}";
+  else if (Flags & X86::IP_USE_VEX3)
+O << "\t{vex3}";
+  else if (Flags & X86::IP_USE_EVEX)
+O << "\t{evex}";
+
+  if (Flags & X86::IP_USE_DISP8)
+O << "\t{disp8}";
+  else if (Flags & X86::IP_USE_DISP32)
+O << "\t{disp32}";
 }
 
 void X86InstPrinterCommon::printVKPair(const MCInst *MI, unsigned OpNo,
Index: llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
===
--- llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
+++ llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
@@ -55,15 +55,18 @@
   /// The constants to describe instr prefixes if there are
   enum IPREFIXES {
 IP_NO_PREFIX = 0,
-IP_HAS_OP_SIZE = 1,
-IP_HAS_AD_SIZE = 2,
-IP_HAS_REPEAT_NE = 4,
-IP_HAS_REPEAT = 8,
-IP_HAS_LOCK = 16,
-IP_HAS_NOTRACK = 32,
-IP_USE_VEX3 = 64,
-IP_USE_DISP8 = 128,
-IP_USE_DISP32 = 256,
+IP_HAS_OP_SIZE =   1U << 0,
+IP_HAS_AD_SIZE =   1U << 1,
+IP_HAS_REPEAT_NE = 1U << 2,
+IP_HAS_REPEAT =1U << 3,
+IP_HAS_LOCK =  1U << 4,
+IP_HAS_NOTRACK =   1U << 5,
+IP_USE_VEX =   1U << 6,
+IP_USE_VEX2 =  1U << 7,
+IP_USE_VEX3 =  1U << 8,
+IP_USE_EVEX =  1U << 9,
+IP_USE_DISP8 = 1U << 10,
+IP_USE_DISP32 =1U << 11,
   };
 
   enum OperandType : unsigned {
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -83,6 +83,7 @@
   enum VEXEncoding {
 VEXEncoding_Default,
 VEXEncoding_VEX,
+VEXEncoding_VEX2,
 VEXEncoding_VEX3,
 VEXEncoding_EVEX,
   };
@@ -2818,8 +2819,10 @@
 return Error(Parser.getTok().getLoc(), "Expected '}'");
   Parser.Lex(); // Eat curly.
 
-  if (Prefix == "vex" || Prefix == "vex2")
+  if (Prefix == "vex")
 ForcedVEXEncoding = VEXEncoding_VEX;
+  else if (Prefix == "vex2")
+ForcedVEXEncoding = VEXEncoding_VEX2;
   else if (Prefix == "vex3")
 ForcedVEXEncoding = VEXEncoding_VEX3;
   else if (Prefix == "evex")
@@ -3837,6 +3840,7 @@
 return Match_Unsupported;
 
   if ((ForcedVEXEncoding == VEXEncoding_VEX ||
+   ForcedVEXEncoding == VEXEncoding_VEX2 ||
ForcedVEXEncoding == VEXEncoding_VEX3) &&
   (MCID.TSFlags & X86II::EncodingMask) != X86II::VEX)
 return Match_Unsupported;
@@ -3879,10 +3883,16 @@
 
   MCInst Inst;
 
-  // If VEX3 encoding is forced, we need to pass the USE_VEX3 flag to the
-  // encoder.
-  if (ForcedVEXEncoding == VEXEncoding_VEX3)
+  // If VEX/EVEX encoding is forced, we need to pass the USE_* flag to the
+  // encoder and printer.
+  if (ForcedVEXEncoding == VEXEncoding_VEX)
+Prefixes |= X86::IP_USE_VEX;
+  else if (ForcedVEXEncoding == VEXEncoding_VEX2)
+Prefixes |= X86::IP_USE_VEX2;
+  else if (ForcedVEXEncoding == VEXEncoding_VEX3)
 Prefixes |= X86::IP_USE_VEX3;
+  else if (ForcedVEXEncoding == VEXEncoding_EVEX)
+Prefixes |= X86::IP_USE_EVEX;
 
   // Set encoded flags for {disp8} and {disp32}.
   if (ForcedDispEncoding == DispEncoding_Disp8)
Index: clang/test/CodeGen/X86/att-inline-asm-prefix.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/att-inline-asm-prefix.c
@@ -0,0 +1,25 @@
+// RUN:%clang_cc1 %s -ferror-limit 0 -triple=x86_64-pc -target-feature +avx512f -target-feature +avx2 -target-feature +avx512vl -S -o -  | FileCheck %s -check-prefix CHECK
+
+// This test is to check if the prefix in inline assembly is correctly
+// preserved.
+
+void check_inline_prefix(void) {
+  __asm__ (
+// CHECK: vcvtps2pd %xmm0, %xmm1
+// CHECK: {vex} vcvtps2pd %xmm0, %xmm1
+// CHECK: {vex2} vcvtps2pd %xmm0, %xmm1
+// CHECK: {vex3} vcvtps2pd %xmm0, %xmm1
+// CHECK: {evex} vcvtps2pd %xmm0, 

[PATCH] D90010: clang-tidy: Reduce number of stderr write calls

2020-10-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D90010#2352556 , @njames93 wrote:

> Isn't `llvm::errs()` buffered, negating most of the benefit here.

+1 to this (the patch description doesn't explain any specific motivation 
either - whether it's performance (runtime? memory usage? etc?) or something 
else, and how the performance aspect has been quantified)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90010

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


[PATCH] D89184: Support complex target features combinations

2020-10-25 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added a comment.

Hi, @echristo. What's your opinion here?


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

https://reviews.llvm.org/D89184

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


[PATCH] D86844: [LoopDeletion] Allows deletion of possibly infinite side-effect free loops

2020-10-25 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel updated this revision to Diff 300559.
atmnpatel added a comment.

Added word back in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86844

Files:
  clang/test/Misc/loop-opt-setup.c
  llvm/include/llvm/Transforms/Utils/LoopUtils.h
  llvm/lib/Transforms/Scalar/LoopDeletion.cpp
  llvm/lib/Transforms/Utils/LoopUtils.cpp
  llvm/test/Other/loop-deletion-printer.ll
  llvm/test/Other/loop-pm-invalidation.ll
  llvm/test/Transforms/LICM/2003-02-27-PreheaderProblem.ll
  llvm/test/Transforms/LoopDeletion/2017-07-11-incremental-dt.ll
  llvm/test/Transforms/LoopDeletion/basic-remark.ll
  llvm/test/Transforms/LoopDeletion/diundef.ll
  llvm/test/Transforms/LoopDeletion/invalidation.ll
  llvm/test/Transforms/LoopDeletion/multiple-exit-conditions.ll
  llvm/test/Transforms/LoopDeletion/multiple-exits.ll
  llvm/test/Transforms/LoopDeletion/mustprogress.ll
  llvm/test/Transforms/LoopDeletion/unreachable-loops.ll
  llvm/test/Transforms/LoopDeletion/use-in-unreachable.ll
  llvm/test/Transforms/SCCP/calltest.ll
  llvm/test/Transforms/SimpleLoopUnswitch/pr37888.ll

Index: llvm/test/Transforms/SimpleLoopUnswitch/pr37888.ll
===
--- llvm/test/Transforms/SimpleLoopUnswitch/pr37888.ll
+++ llvm/test/Transforms/SimpleLoopUnswitch/pr37888.ll
@@ -7,7 +7,7 @@
 
 target triple = "x86_64-unknown-linux-gnu"
 
-define void @pr37888() {
+define void @pr37888() willreturn {
 ; CHECK-LABEL: define void @pr37888()
 entry:
   %tobool = icmp ne i16 undef, 0
Index: llvm/test/Transforms/SCCP/calltest.ll
===
--- llvm/test/Transforms/SCCP/calltest.ll
+++ llvm/test/Transforms/SCCP/calltest.ll
@@ -4,7 +4,7 @@
 %empty = type {}
 declare %empty @has_side_effects()
 
-define double @test_0(i32 %param) {
+define double @test_0(i32 %param) willreturn {
 ; CHECK-LABEL: @test_0(
 ; CHECK-NOT: br
 entry:
Index: llvm/test/Transforms/LoopDeletion/use-in-unreachable.ll
===
--- llvm/test/Transforms/LoopDeletion/use-in-unreachable.ll
+++ llvm/test/Transforms/LoopDeletion/use-in-unreachable.ll
@@ -3,7 +3,7 @@
 ; Checking that possible users of instruction from the loop in
 ; unreachable blocks are handled.
 
-define i64 @foo() {
+define i64 @foo() willreturn {
 entry:
   br label %invloop
 ; CHECK-LABEL-NOT: invloop
Index: llvm/test/Transforms/LoopDeletion/unreachable-loops.ll
===
--- llvm/test/Transforms/LoopDeletion/unreachable-loops.ll
+++ llvm/test/Transforms/LoopDeletion/unreachable-loops.ll
@@ -216,7 +216,7 @@
 ; Show recursive deletion of loops. Since we start with subloops and progress outward 
 ; to parent loop, we first delete the loop L2. Now loop L1 becomes a non-loop since it's backedge
 ; from L2's preheader to L1's exit block is never taken. So, L1 gets deleted as well.
-define void @test8(i64 %n) {
+define void @test8(i64 %n) #0 {
 ; CHECK-LABEL: test8
 ; CHECK-LABEL: entry:
 ; CHECK-NEXT: br label %exit
@@ -318,7 +318,7 @@
 ; deleted.
 ; In the next iteration, since L2 is never executed and has no subloops, we delete
 ; L2 as well. Finally, the outermost loop L1 is deleted.
-define void @test11(i64 %n) {
+define void @test11(i64 %n) #0 {
 ; CHECK-LABEL: test11
 ; CHECK-LABEL: entry:
 ; CHECK-NEXT: br label %exit
@@ -355,7 +355,7 @@
 
 
 ; 2 edges from a single exiting block to the exit block.
-define i64 @test12(i64 %n){
+define i64 @test12(i64 %n) #0 {
 ;CHECK-LABEL: @test12
 ; CHECK-NOT: L1:
 ; CHECK-NOT: L1Latch:
@@ -392,7 +392,7 @@
 }
 
 ; multiple edges to exit block from the same exiting blocks
-define i64 @test13(i64 %n) {
+define i64 @test13(i64 %n) #0 {
 ; CHECK-LABEL: @test13
 ; CHECK-NOT: L1:
 ; CHECK-NOT: L1Latch:
@@ -433,3 +433,5 @@
   %y.phi = phi i64 [ 10, %L1Block ], [ 10, %L1Block ], [ %y.next, %L1 ], [ 30, %L1Latch ], [ 30, %L1Latch ]
   ret i64 %y.phi
 }
+
+attributes #0 = { willreturn }
Index: llvm/test/Transforms/LoopDeletion/mustprogress.ll
===
--- /dev/null
+++ llvm/test/Transforms/LoopDeletion/mustprogress.ll
@@ -0,0 +1,241 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes
+; RUN: opt < %s -loop-deletion -S | FileCheck %s
+
+;; Original C Code:
+;;  void unknown_tripcount_mustprogress_attr_mustprogress_loopmd(int a, int b) {
+;;for (; a < b;) ;
+;;for (;;) ;
+;;  }
+
+define void @unknown_tripcount_mustprogress_attr_mustprogress_loopmd(i32 %a, i32 %b) #0 {
+; CHECK: Function Attrs: mustprogress
+; CHECK-LABEL: define {{[^@]+}}@unknown_tripcount_mustprogress_attr_mustprogress_loopmd
+; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) [[ATTR0:#.*]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:br label [[FOR_END:%.*]]
+; CHECK:   for.end:
+; 

[PATCH] D90127: [clang][NFC] Rearrange Comment Token and Lexer fields to reduce padding

2020-10-25 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added a reviewer: gribozavr2.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
njames93 requested review of this revision.

Rearrange the fields to reduce the size of the classes


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90127

Files:
  clang/include/clang/AST/CommentLexer.h
  clang/lib/AST/CommentLexer.cpp


Index: clang/lib/AST/CommentLexer.cpp
===
--- clang/lib/AST/CommentLexer.cpp
+++ clang/lib/AST/CommentLexer.cpp
@@ -740,11 +740,10 @@
 
 Lexer::Lexer(llvm::BumpPtrAllocator , DiagnosticsEngine ,
  const CommandTraits , SourceLocation FileLoc,
- const char *BufferStart, const char *BufferEnd,
- bool ParseCommands)
+ const char *BufferStart, const char *BufferEnd, bool 
ParseCommands)
 : Allocator(Allocator), Diags(Diags), Traits(Traits),
-  BufferStart(BufferStart), BufferEnd(BufferEnd), FileLoc(FileLoc),
-  BufferPtr(BufferStart), CommentState(LCS_BeforeComment), 
State(LS_Normal),
+  BufferStart(BufferStart), BufferEnd(BufferEnd), BufferPtr(BufferStart),
+  FileLoc(FileLoc), CommentState(LCS_BeforeComment), State(LS_Normal),
   ParseCommands(ParseCommands) {}
 
 void Lexer::lex(Token ) {
Index: clang/include/clang/AST/CommentLexer.h
===
--- clang/include/clang/AST/CommentLexer.h
+++ clang/include/clang/AST/CommentLexer.h
@@ -66,9 +66,6 @@
   /// tokens.
   unsigned Length;
 
-  /// Contains text value associated with a token.
-  const char *TextPtr;
-
   /// Integer value associated with a token.
   ///
   /// If the token is a known command, contains command ID and TextPtr is
@@ -76,6 +73,9 @@
   /// contains the length of the string that starts at TextPtr.
   unsigned IntVal;
 
+  /// Contains text value associated with a token.
+  const char *TextPtr;
+
 public:
   SourceLocation getLocation() const LLVM_READONLY { return Loc; }
   void setLocation(SourceLocation SL) { Loc = SL; }
@@ -232,7 +232,6 @@
 
   const char *const BufferStart;
   const char *const BufferEnd;
-  SourceLocation FileLoc;
 
   const char *BufferPtr;
 
@@ -240,7 +239,13 @@
   /// to newline or BufferEnd, for C comments points to star in '*/'.
   const char *CommentEnd;
 
-  enum LexerCommentState {
+  /// If State is LS_VerbatimBlock, contains the name of verbatim end
+  /// command, including command marker.
+  SmallString<16> VerbatimBlockEndCommandName;
+
+  SourceLocation FileLoc;
+
+  enum LexerCommentState : uint8_t {
 LCS_BeforeComment,
 LCS_InsideBCPLComment,
 LCS_InsideCComment,
@@ -250,7 +255,7 @@
   /// Low-level lexer state, track if we are inside or outside of comment.
   LexerCommentState CommentState;
 
-  enum LexerState {
+  enum LexerState : uint8_t {
 /// Lexing normal comment text
 LS_Normal,
 
@@ -276,10 +281,6 @@
   /// Current lexing mode.
   LexerState State;
 
-  /// If State is LS_VerbatimBlock, contains the name of verbatim end
-  /// command, including command marker.
-  SmallString<16> VerbatimBlockEndCommandName;
-
   /// If true, the commands, html tags, etc will be parsed and reported as
   /// separate tokens inside the comment body. If false, the comment text will
   /// be parsed into text and newline tokens.


Index: clang/lib/AST/CommentLexer.cpp
===
--- clang/lib/AST/CommentLexer.cpp
+++ clang/lib/AST/CommentLexer.cpp
@@ -740,11 +740,10 @@
 
 Lexer::Lexer(llvm::BumpPtrAllocator , DiagnosticsEngine ,
  const CommandTraits , SourceLocation FileLoc,
- const char *BufferStart, const char *BufferEnd,
- bool ParseCommands)
+ const char *BufferStart, const char *BufferEnd, bool ParseCommands)
 : Allocator(Allocator), Diags(Diags), Traits(Traits),
-  BufferStart(BufferStart), BufferEnd(BufferEnd), FileLoc(FileLoc),
-  BufferPtr(BufferStart), CommentState(LCS_BeforeComment), State(LS_Normal),
+  BufferStart(BufferStart), BufferEnd(BufferEnd), BufferPtr(BufferStart),
+  FileLoc(FileLoc), CommentState(LCS_BeforeComment), State(LS_Normal),
   ParseCommands(ParseCommands) {}
 
 void Lexer::lex(Token ) {
Index: clang/include/clang/AST/CommentLexer.h
===
--- clang/include/clang/AST/CommentLexer.h
+++ clang/include/clang/AST/CommentLexer.h
@@ -66,9 +66,6 @@
   /// tokens.
   unsigned Length;
 
-  /// Contains text value associated with a token.
-  const char *TextPtr;
-
   /// Integer value associated with a token.
   ///
   /// If the token is a known command, contains command ID and TextPtr is
@@ -76,6 +73,9 @@
   /// contains the length of the string that starts at TextPtr.
   unsigned IntVal;
 
+  /// Contains text value associated with a token.
+  const char *TextPtr;
+
 public:
   SourceLocation 

[PATCH] D90116: [clangd] Escape Unicode characters to fix Windows builds

2020-10-25 Thread Daniel Martín via Phabricator via cfe-commits
danielmartin added a comment.

Using explicit UTF-8 string literals is a possible solution, but it makes the 
code a bit less readable. Another possible solution is to save the source file 
using UTF-8 with BOM, but this is confusing outside the Microsoft world (and 
it's very easy to remove the BOM by mistake).

I think passing `/utf-8` to MSVC is the best solution for good interoperability 
with Clang.

> I am not sure if there's a way to change that for clang/gcc. I I believe they 
> both require plain ascii or utf-8 anyways.

Clang enforces UTF-8 everywhere so there's no need for additional 
configuration. Clang can also accept source files encoded in UTF-8 with BOM. 
I'm not sure about GCC, I think you need to enforce the encoding manually like 
in MSVC (see the `-finput-charset` and `-fexec-charset` options).

I recommend reading this article about how MSVC interprets the encoding of 
source files, the casuistic is a bit complex: 
https://devblogs.microsoft.com/cppblog/new-options-for-managing-character-sets-in-the-microsoft-cc-compiler/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90116

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


[PATCH] D87216: [NewPM] Support --print-before/after in NPM

2020-10-25 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 300555.
aeubanks added a comment.

move map into PassInstrumentationCallbacks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87216

Files:
  llvm/include/llvm/IR/PassInstrumentation.h
  llvm/include/llvm/IR/PrintPasses.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
  llvm/lib/CodeGen/MachinePassManager.cpp
  llvm/lib/IR/CMakeLists.txt
  llvm/lib/IR/LegacyPassManager.cpp
  llvm/lib/IR/PassInstrumentation.cpp
  llvm/lib/IR/PassTimingInfo.cpp
  llvm/lib/IR/PrintPasses.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/test/CodeGen/Generic/print-after.ll
  llvm/test/Other/loop-pass-printer.ll
  llvm/test/Other/print-before-after.ll
  llvm/unittests/IR/PassBuilderCallbacksTest.cpp
  llvm/utils/gn/secondary/llvm/lib/IR/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/IR/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/IR/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/IR/BUILD.gn
@@ -60,6 +60,7 @@
 "PassManager.cpp",
 "PassRegistry.cpp",
 "PassTimingInfo.cpp",
+"PrintPasses.cpp",
 "ProfileSummary.cpp",
 "SafepointIRVerifier.cpp",
 "Statepoint.cpp",
Index: llvm/unittests/IR/PassBuilderCallbacksTest.cpp
===
--- llvm/unittests/IR/PassBuilderCallbacksTest.cpp
+++ llvm/unittests/IR/PassBuilderCallbacksTest.cpp
@@ -338,13 +338,12 @@
   this->runBeforeSkippedPass(P, IR);
 });
 Callbacks.registerBeforeNonSkippedPassCallback(
-[this](StringRef P, llvm::Any IR) {
+[this](StringRef P, StringRef, llvm::Any IR) {
   this->runBeforeNonSkippedPass(P, IR);
 });
 Callbacks.registerAfterPassCallback(
-[this](StringRef P, llvm::Any IR, const PreservedAnalyses ) {
-  this->runAfterPass(P, IR, PA);
-});
+[this](StringRef P, StringRef, llvm::Any IR,
+   const PreservedAnalyses ) { this->runAfterPass(P, IR, PA); });
 Callbacks.registerAfterPassInvalidatedCallback(
 [this](StringRef P, const PreservedAnalyses ) {
   this->runAfterPassInvalidated(P, PA);
Index: llvm/test/Other/print-before-after.ll
===
--- /dev/null
+++ llvm/test/Other/print-before-after.ll
@@ -0,0 +1,33 @@
+; RUN: not --crash opt < %s -disable-output -passes='no-op-module' -print-before=bleh 2>&1 | FileCheck %s --check-prefix=NONE --allow-empty
+; RUN: not --crash opt < %s -disable-output -passes='no-op-module' -print-after=bleh 2>&1 | FileCheck %s --check-prefix=NONE --allow-empty
+; RUN: opt < %s -disable-output -passes='no-op-module' -print-before=no-op-function 2>&1 | FileCheck %s --check-prefix=NONE --allow-empty
+; RUN: opt < %s -disable-output -passes='no-op-module' -print-after=no-op-function 2>&1 | FileCheck %s --check-prefix=NONE --allow-empty
+; RUN: opt < %s -disable-output -passes='no-op-module,no-op-function' -print-before=no-op-module 2>&1 | FileCheck %s --check-prefix=ONCE
+; RUN: opt < %s -disable-output -passes='no-op-module,no-op-function' -print-after=no-op-module 2>&1 | FileCheck %s --check-prefix=ONCE
+; RUN: opt < %s -disable-output -passes='no-op-function' -print-before=no-op-function 2>&1 | FileCheck %s --check-prefix=ONCE
+; RUN: opt < %s -disable-output -passes='no-op-function' -print-after=no-op-function 2>&1 | FileCheck %s --check-prefix=ONCE
+; RUN: opt < %s -disable-output -passes='no-op-module,no-op-function' -print-before=no-op-function --print-module-scope 2>&1 | FileCheck %s --check-prefix=TWICE
+; RUN: opt < %s -disable-output -passes='no-op-module,no-op-function' -print-after=no-op-function --print-module-scope 2>&1 | FileCheck %s --check-prefix=TWICE
+
+; NONE-NOT: @foo
+; NONE-NOT: @bar
+
+; ONCE: @foo
+; ONCE: @bar
+; ONCE-NOT: @foo
+; ONCE-NOT: @bar
+
+; TWICE: @foo
+; TWICE: @bar
+; TWICE: @foo
+; TWICE: @bar
+; TWICE-NOT: @foo
+; TWICE-NOT: @bar
+
+define void @foo() {
+  ret void
+}
+
+define void @bar() {
+  ret void
+}
Index: llvm/test/Other/loop-pass-printer.ll
===
--- llvm/test/Other/loop-pass-printer.ll
+++ llvm/test/Other/loop-pass-printer.ll
@@ -1,23 +1,23 @@
 ; This test checks -print-after/before on loop passes
 ; Besides of the loop itself it should be dumping loop pre-header and exits.
 ;
-; RUN: opt -enable-new-pm=0 < %s 2>&1 -disable-output \
+; RUN: opt < %s 2>&1 -disable-output \
 ; RUN: 	   -loop-deletion -print-before=loop-deletion \
 ; RUN:	   | FileCheck %s -check-prefix=DEL
 ; RUN: opt < %s 2>&1 -disable-output \
-; RUN: 	   -passes='loop(loop-deletion)' -print-before-all \
+; RUN: 	   

[PATCH] D90010: clang-tidy: Reduce number of stderr write calls

2020-10-25 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Isn't `llvm::errs()` buffered, negating most of the benefit here.
Also using std::string here is bad, its potentially going to allocate and 
reallocate memory each time it grows.
It would be better off using an `llvm::SmallString` and looking at what could 
potentially be outputted, I'd suggest you'd want a buffer size of at least 256 
bytes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90010

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


[PATCH] D82278: Fix traversal over CXXConstructExpr in Syntactic mode

2020-10-25 Thread Stephen Kelly via Phabricator via cfe-commits
steveire marked 2 inline comments as done.
steveire added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp:80
   auto Matches =
-  match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
+  match(traverse(TK_AsIs, expr(hasDescendant(typeLoc().bind("t", *E,
+*Result.Context);

aaron.ballman wrote:
> While I believe the change is necessary here, it's not obvious to me what 
> "hints" tell me this behavior is correct for the given matchers. None of the 
> matchers look like they're going to care about implicit nodes, so how am I to 
> know that AsIs is correct or not as a reviewer? As it stands, I sort of feel 
> like I have to take it on faith that this change is correct and it looks a 
> little suspicious because the code using the matcher is creating a fix-it at 
> what now may be the location of an implicit node.
I don't know if I was wrong about it being required before, or if it was 
required before, but the change to this file is not required now.



Comment at: clang/lib/AST/Expr.cpp:3001
 Expr *A = C->getArg(0);
-if (A->getSourceRange() == SR || !isa(C))
+if (A->getSourceRange() == SR || C->isElidable()) {
   E = A;

ymandel wrote:
> aaron.ballman wrote:
> > Looks like the change introduced new curly braces for a single-line if.
> Why is it necessary to check isElidable?  I think the logic here is subtle 
> (since the AST doesn't explicitly tag implicit expressions), so please add an 
> explanatory comment.
The `ignoringElidableConstructorCall` does it this way. I'm afraid I don't know 
more than that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82278

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


[PATCH] D82278: Fix traversal over CXXConstructExpr in Syntactic mode

2020-10-25 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 300550.
steveire added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82278

Files:
  clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ParentMapContext.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2088,6 +2088,98 @@
 
   EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource,
  staticAssertDecl(has(integerLiteral());
+
+  Code = R"cpp(
+
+struct OneParamCtor {
+  explicit OneParamCtor(int);
+};
+struct TwoParamCtor {
+  explicit TwoParamCtor(int, int);
+};
+
+void varDeclCtors() {
+  {
+  auto var1 = OneParamCtor(5);
+  auto var2 = TwoParamCtor(6, 7);
+  }
+  {
+  OneParamCtor var3(5);
+  TwoParamCtor var4(6, 7);
+  }
+  int i = 0;
+  {
+  auto var5 = OneParamCtor(i);
+  auto var6 = TwoParamCtor(i, 7);
+  }
+  {
+  OneParamCtor var7(i);
+  TwoParamCtor var8(i, 7);
+  }
+}
+
+)cpp";
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_AsIs, varDecl(hasName("var1"), hasInitializer(hasDescendant(
+ cxxConstructExpr()));
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_AsIs, varDecl(hasName("var2"), hasInitializer(hasDescendant(
+ cxxConstructExpr()));
+  EXPECT_TRUE(matches(
+  Code, traverse(TK_AsIs, varDecl(hasName("var3"),
+  hasInitializer(cxxConstructExpr());
+  EXPECT_TRUE(matches(
+  Code, traverse(TK_AsIs, varDecl(hasName("var4"),
+  hasInitializer(cxxConstructExpr());
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_AsIs, varDecl(hasName("var5"), hasInitializer(hasDescendant(
+ cxxConstructExpr()));
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_AsIs, varDecl(hasName("var6"), hasInitializer(hasDescendant(
+ cxxConstructExpr()));
+  EXPECT_TRUE(matches(
+  Code, traverse(TK_AsIs, varDecl(hasName("var7"),
+  hasInitializer(cxxConstructExpr());
+  EXPECT_TRUE(matches(
+  Code, traverse(TK_AsIs, varDecl(hasName("var8"),
+  hasInitializer(cxxConstructExpr());
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   varDecl(hasName("var1"), hasInitializer(cxxConstructExpr());
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   varDecl(hasName("var2"), hasInitializer(cxxConstructExpr());
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   varDecl(hasName("var3"), hasInitializer(cxxConstructExpr());
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   varDecl(hasName("var4"), hasInitializer(cxxConstructExpr());
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   varDecl(hasName("var5"), hasInitializer(cxxConstructExpr());
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   varDecl(hasName("var6"), hasInitializer(cxxConstructExpr());
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   varDecl(hasName("var7"), hasInitializer(cxxConstructExpr());
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   varDecl(hasName("var8"), hasInitializer(cxxConstructExpr());
 }
 
 template 
@@ -2293,21 +2385,20 @@
  forFunction(functionDecl(hasName("func2"),
   langCxx20OrLater()));
 
-  EXPECT_TRUE(matches(
-  Code,
-  traverse(
-  TK_IgnoreUnlessSpelledInSource,
-  returnStmt(forFunction(functionDecl(hasName("func3"))),
- hasReturnValue(cxxFunctionalCastExpr(
- hasSourceExpression(integerLiteral(equals(42))),
-  langCxx20OrLater()));
+  EXPECT_TRUE(
+  matches(Code,
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   returnStmt(forFunction(functionDecl(hasName("func3"))),
+  hasReturnValue(cxxConstructExpr(hasArgument(
+  0, integerLiteral(equals(42))),
+  

[PATCH] D89296: [clangd] Implement call hierarchy (incoming calls)

2020-10-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Note, testing this with vscode requires this vscode-clangd patch 
 applied.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89296

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


[clang] b296c64 - Thread safety analysis: Nullability improvements in TIL, NFCI

2020-10-25 Thread Aaron Puchert via cfe-commits

Author: Aaron Puchert
Date: 2020-10-25T19:37:16+01:00
New Revision: b296c64e64a0bc600538c8bc67d4ccc2564e3c72

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

LOG: Thread safety analysis: Nullability improvements in TIL, NFCI

The constructor of Project asserts that the contained ValueDecl is not
null, use that in the ThreadSafetyAnalyzer. In the case of LiteralPtr
it's the other way around.

Also dyn_cast<> is sufficient if we know something isn't null.

Added: 


Modified: 
clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
clang/lib/Analysis/ThreadSafety.cpp
clang/lib/Analysis/ThreadSafetyCommon.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
index c26d2ed99dd2..77a800c28754 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
@@ -634,7 +634,9 @@ typename V::R_SExpr Literal::traverse(V , typename 
V::R_Ctx Ctx) {
 /// At compile time, pointer literals are represented by symbolic names.
 class LiteralPtr : public SExpr {
 public:
-  LiteralPtr(const ValueDecl *D) : SExpr(COP_LiteralPtr), Cvdecl(D) {}
+  LiteralPtr(const ValueDecl *D) : SExpr(COP_LiteralPtr), Cvdecl(D) {
+assert(D && "ValueDecl must not be null");
+  }
   LiteralPtr(const LiteralPtr &) = default;
 
   static bool classof(const SExpr *E) { return E->opcode() == COP_LiteralPtr; }

diff  --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index ef90fa175a6d..65d410a65ba4 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1279,9 +1279,8 @@ bool ThreadSafetyAnalyzer::inCurrentScope(const 
CapabilityExpr ) {
   if (const auto *P = dyn_cast(SExp)) {
 if (!CurrentMethod)
   return false;
-const auto *VD = P->clangDecl();
-if (VD)
-  return VD->getDeclContext() == CurrentMethod->getDeclContext();
+const ValueDecl *VD = P->clangDecl();
+return VD->getDeclContext() == CurrentMethod->getDeclContext();
   }
 
   return false;

diff  --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp 
b/clang/lib/Analysis/ThreadSafetyCommon.cpp
index 1b8c55e56d47..0c5d1857cc2b 100644
--- a/clang/lib/Analysis/ThreadSafetyCommon.cpp
+++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp
@@ -185,7 +185,7 @@ CapabilityExpr SExprBuilder::translateAttrExpr(const Expr 
*AttrExp,
 return CapabilityExpr(nullptr, false);
 
   // Hack to deal with smart pointers -- strip off top-level pointer casts.
-  if (const auto *CE = dyn_cast_or_null(E)) {
+  if (const auto *CE = dyn_cast(E)) {
 if (CE->castOpcode() == til::CAST_objToPtr)
   return CapabilityExpr(CE->expr(), Neg);
   }
@@ -274,7 +274,7 @@ til::SExpr *SExprBuilder::translateDeclRefExpr(const 
DeclRefExpr *DRE,
   const auto *VD = cast(DRE->getDecl()->getCanonicalDecl());
 
   // Function parameters require substitution and/or renaming.
-  if (const auto *PV = dyn_cast_or_null(VD)) {
+  if (const auto *PV = dyn_cast(VD)) {
 unsigned I = PV->getFunctionScopeIndex();
 const DeclContext *D = PV->getDeclContext();
 if (Ctx && Ctx->FunArgs) {



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


[PATCH] D89296: [clangd] Implement call hierarchy (incoming calls)

2020-10-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
Herald added subscribers: llvm-commits, cfe-commits, usaxena95, kadircet, 
arphaman, mgorny.
Herald added projects: clang, LLVM.
nridge retitled this revision from "[clangd] Implement call hierarchy (incoming 
callers)" to "[clangd] Implement call hierarchy (incoming calls)".
nridge updated this revision to Diff 298933.
nridge added a comment.
nridge updated this revision to Diff 300548.
nridge published this revision for review.
Herald added subscribers: MaskRay, ilya-biryukov.

- Rebased on top of upstream changes
- Rebased on top of TestWorkspace changes
- Merged D89298  into this patch
- Split index changes out to D89670 
- Added more tests


nridge added a comment.

Keeping in the draft state for now, as I still need to address this comment 
from the issue discussion 
:

> The request still has a progressToken attached to it, I presume(it is unclear 
> from the spec) it is preserved between prepare and subsequent requests. So we 
> can keep a mapping in ClangdServer and stash symbolIDs.


nridge added a comment.

Add and use CallHierarchyItem.data


nridge added a comment.

In D89296#2337788 , @nridge wrote:

> Keeping in the draft state for now, as I still need to address this comment 
> from the issue discussion 
> :
>
>> The request still has a progressToken attached to it, I presume(it is 
>> unclear from the spec) it is preserved between prepare and subsequent 
>> requests. So we can keep a mapping in ClangdServer and stash symbolIDs.

The protocol has since been amended to introduce a `data` field to 
`CallHierarchyItem` in which we can stash the SymbolID, making this workaround 
unnecessary.

The updated patch uses the `data` field, and should be ready for review.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89296

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/test/initialize-params.test
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
@@ -44,6 +44,7 @@
 "ASTTests.cpp",
 "Annotations.cpp",
 "BackgroundIndexTests.cpp",
+"CallHierarchyTests.cpp",
 "CanonicalIncludesTests.cpp",
 "ClangdLSPServerTests.cpp",
 "ClangdTests.cpp",
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -156,7 +156,8 @@
 
 std::unique_ptr TestTU::index() const {
   auto AST = build();
-  auto Idx = std::make_unique(/*UseDex=*/true);
+  auto Idx = std::make_unique(/*UseDex=*/true,
+ /*CollectMainFileRefs=*/true);
   Idx->updatePreamble(testPath(Filename), /*Version=*/"null",
   AST.getASTContext(), AST.getPreprocessorPtr(),
   AST.getCanonicalIncludes());
Index: clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
@@ -0,0 +1,272 @@
+//===-- CallHierarchyTests.cpp  ---*- C++ -*---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Annotations.h"
+#include "Compiler.h"
+#include "Matchers.h"
+#include "ParsedAST.h"
+#include "SyncAPI.h"
+#include "TestFS.h"
+#include "TestTU.h"
+#include "TestWorkspace.h"
+#include "XRefs.h"
+#include "index/FileIndex.h"
+#include "index/SymbolCollector.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/Index/IndexingAction.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/ScopedPrinter.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {

[PATCH] D84604: Thread safety analysis: Consider global variables in scope

2020-10-25 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 rG5250a03a9959: Thread safety analysis: Consider global 
variables in scope (authored by aaronpuchert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84604

Files:
  clang/lib/Analysis/ThreadSafety.cpp
  clang/test/SemaCXX/warn-thread-safety-analysis.cpp
  clang/test/SemaCXX/warn-thread-safety-negative.cpp

Index: clang/test/SemaCXX/warn-thread-safety-negative.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-negative.cpp
+++ clang/test/SemaCXX/warn-thread-safety-negative.cpp
@@ -21,6 +21,12 @@
   void AssertReaderHeld() ASSERT_SHARED_LOCK();
 };
 
+class SCOPED_LOCKABLE MutexLock {
+public:
+  MutexLock(Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu);
+  MutexLock(Mutex *mu, bool adopt) EXCLUSIVE_LOCKS_REQUIRED(mu);
+  ~MutexLock() UNLOCK_FUNCTION();
+};
 
 namespace SimpleTest {
 
@@ -77,10 +83,43 @@
 mu.Unlock();
 baz();   // no warning -- !mu in set.
   }
+
+  void test4() {
+MutexLock lock(); // expected-warning {{acquiring mutex 'mu' requires negative capability '!mu'}}
+  }
 };
 
 }  // end namespace SimpleTest
 
+Mutex globalMutex;
+
+namespace ScopeTest {
+
+void f() EXCLUSIVE_LOCKS_REQUIRED(!globalMutex);
+void fq() EXCLUSIVE_LOCKS_REQUIRED(!::globalMutex);
+
+namespace ns {
+  Mutex globalMutex;
+  void f() EXCLUSIVE_LOCKS_REQUIRED(!globalMutex);
+  void fq() EXCLUSIVE_LOCKS_REQUIRED(!ns::globalMutex);
+}
+
+void testGlobals() EXCLUSIVE_LOCKS_REQUIRED(!ns::globalMutex) {
+  f(); // expected-warning {{calling function 'f' requires negative capability '!globalMutex'}}
+  fq();// expected-warning {{calling function 'fq' requires negative capability '!globalMutex'}}
+  ns::f();
+  ns::fq();
+}
+
+void testNamespaceGlobals() EXCLUSIVE_LOCKS_REQUIRED(!globalMutex) {
+  f();
+  fq();
+  ns::f();  // expected-warning {{calling function 'f' requires negative capability '!globalMutex'}}
+  ns::fq(); // expected-warning {{calling function 'fq' requires negative capability '!globalMutex'}}
+}
+
+}  // end namespace ScopeTest
+
 namespace DoubleAttribute {
 
 struct Foo {
Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5036,7 +5036,8 @@
 }
 
 extern const char *deque_log_msg(void) __attribute__((requires_capability(Logger)));
-void logger_entry(void) __attribute__((requires_capability(Logger))) {
+void logger_entry(void) __attribute__((requires_capability(Logger)))
+__attribute__((requires_capability(!FlightControl))) {
   const char *msg;
 
   while ((msg = deque_log_msg())) {
@@ -5044,13 +5045,13 @@
   }
 }
 
-void spawn_fake_logger_thread(void) {
+void spawn_fake_logger_thread(void) __attribute__((requires_capability(!FlightControl))) {
   acquire(Logger);
   logger_entry();
   release(Logger);
 }
 
-int main(void) {
+int main(void) __attribute__((requires_capability(!FlightControl))) {
   spawn_fake_flight_control_thread();
   spawn_fake_logger_thread();
 
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -1266,13 +1266,24 @@
 }
 
 bool ThreadSafetyAnalyzer::inCurrentScope(const CapabilityExpr ) {
-  if (!CurrentMethod)
+  const threadSafety::til::SExpr *SExp = CapE.sexpr();
+  assert(SExp && "Null expressions should be ignored");
+
+  // Global variables are always in scope.
+  if (const auto *LP = dyn_cast(SExp)) {
+const ValueDecl *VD = LP->clangDecl();
+return VD->isDefinedOutsideFunctionOrMethod();
+  }
+
+  // Members are in scope from methods of the same class.
+  if (const auto *P = dyn_cast(SExp)) {
+if (!CurrentMethod)
   return false;
-  if (const auto *P = dyn_cast_or_null(CapE.sexpr())) {
 const auto *VD = P->clangDecl();
 if (VD)
   return VD->getDeclContext() == CurrentMethod->getDeclContext();
   }
+
   return false;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5250a03 - Thread safety analysis: Consider global variables in scope

2020-10-25 Thread Aaron Puchert via cfe-commits

Author: Aaron Puchert
Date: 2020-10-25T19:32:26+01:00
New Revision: 5250a03a9959c2701a8338fe1a1ffa8bd93d6173

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

LOG: Thread safety analysis: Consider global variables in scope

Instead of just mutex members we also consider mutex globals.
Unsurprisingly they are always in scope. Now the paper [1] says that

> The scope of a class member is assumed to be its enclosing class,
> while the scope of a global variable is the translation unit in
> which it is defined.

But I don't think we should limit this to TUs where a definition is
available - a declaration is enough to acquire the mutex, and if a mutex
is really limited in scope to a translation unit, it should probably be
only declared there.

The previous attempt in 9dcc82f34ea was causing false positives because
I wrongly assumed that LiteralPtrs were always globals, which they are
not. This should be fixed now.

[1] 
https://static.googleusercontent.com/media/research.google.com/en/us/pubs/archive/42958.pdf

Fixes PR46354.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/Analysis/ThreadSafety.cpp
clang/test/SemaCXX/warn-thread-safety-analysis.cpp
clang/test/SemaCXX/warn-thread-safety-negative.cpp

Removed: 




diff  --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 64e0da9e64b1..ef90fa175a6d 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1266,13 +1266,24 @@ ClassifyDiagnostic(const AttrTy *A) {
 }
 
 bool ThreadSafetyAnalyzer::inCurrentScope(const CapabilityExpr ) {
-  if (!CurrentMethod)
+  const threadSafety::til::SExpr *SExp = CapE.sexpr();
+  assert(SExp && "Null expressions should be ignored");
+
+  // Global variables are always in scope.
+  if (const auto *LP = dyn_cast(SExp)) {
+const ValueDecl *VD = LP->clangDecl();
+return VD->isDefinedOutsideFunctionOrMethod();
+  }
+
+  // Members are in scope from methods of the same class.
+  if (const auto *P = dyn_cast(SExp)) {
+if (!CurrentMethod)
   return false;
-  if (const auto *P = dyn_cast_or_null(CapE.sexpr())) {
 const auto *VD = P->clangDecl();
 if (VD)
   return VD->getDeclContext() == CurrentMethod->getDeclContext();
   }
+
   return false;
 }
 

diff  --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp 
b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
index 91bd15def577..d1520b1decbd 100644
--- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5036,7 +5036,8 @@ void spawn_fake_flight_control_thread(void) {
 }
 
 extern const char *deque_log_msg(void) 
__attribute__((requires_capability(Logger)));
-void logger_entry(void) __attribute__((requires_capability(Logger))) {
+void logger_entry(void) __attribute__((requires_capability(Logger)))
+__attribute__((requires_capability(!FlightControl))) {
   const char *msg;
 
   while ((msg = deque_log_msg())) {
@@ -5044,13 +5045,13 @@ void logger_entry(void) 
__attribute__((requires_capability(Logger))) {
   }
 }
 
-void spawn_fake_logger_thread(void) {
+void spawn_fake_logger_thread(void) 
__attribute__((requires_capability(!FlightControl))) {
   acquire(Logger);
   logger_entry();
   release(Logger);
 }
 
-int main(void) {
+int main(void) __attribute__((requires_capability(!FlightControl))) {
   spawn_fake_flight_control_thread();
   spawn_fake_logger_thread();
 

diff  --git a/clang/test/SemaCXX/warn-thread-safety-negative.cpp 
b/clang/test/SemaCXX/warn-thread-safety-negative.cpp
index 456fe16e6574..d7db5f402d11 100644
--- a/clang/test/SemaCXX/warn-thread-safety-negative.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-negative.cpp
@@ -21,6 +21,12 @@ class LOCKABLE Mutex {
   void AssertReaderHeld() ASSERT_SHARED_LOCK();
 };
 
+class SCOPED_LOCKABLE MutexLock {
+public:
+  MutexLock(Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu);
+  MutexLock(Mutex *mu, bool adopt) EXCLUSIVE_LOCKS_REQUIRED(mu);
+  ~MutexLock() UNLOCK_FUNCTION();
+};
 
 namespace SimpleTest {
 
@@ -77,10 +83,43 @@ class Foo {
 mu.Unlock();
 baz();   // no warning -- !mu in set.
   }
+
+  void test4() {
+MutexLock lock(); // expected-warning {{acquiring mutex 'mu' requires 
negative capability '!mu'}}
+  }
 };
 
 }  // end namespace SimpleTest
 
+Mutex globalMutex;
+
+namespace ScopeTest {
+
+void f() EXCLUSIVE_LOCKS_REQUIRED(!globalMutex);
+void fq() EXCLUSIVE_LOCKS_REQUIRED(!::globalMutex);
+
+namespace ns {
+  Mutex globalMutex;
+  void f() EXCLUSIVE_LOCKS_REQUIRED(!globalMutex);
+  void fq() EXCLUSIVE_LOCKS_REQUIRED(!ns::globalMutex);
+}
+
+void testGlobals() EXCLUSIVE_LOCKS_REQUIRED(!ns::globalMutex) {
+  f(); 

[PATCH] D90116: [clangd] Escape Unicode characters to fix Windows builds

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

I think we should update cmake rules to explicitly tell the compilers that the 
source code language is utf8.

https://docs.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=vs-2019
 seems to be the way for MSVC.
I am not sure if there's a way to change that for clang/gcc. I I believe they 
both require plain ascii or utf-8 anyways.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90116

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


[PATCH] D84604: Thread safety analysis: Consider global variables in scope

2020-10-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri resigned from this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

Thanks.
Note that i didn't check that this doesn't cause any new false-positives




Comment at: clang/test/SemaCXX/warn-thread-safety-negative.cpp:87-89
+  void test4() {
+MutexLock lock(); // expected-warning {{acquiring mutex 'mu' requires 
negative capability '!mu'}}
+  }

aaronpuchert wrote:
> lebedev.ri wrote:
> > aaronpuchert wrote:
> > > @lebedev.ri, I think that's pretty much your case. On my original change, 
> > > this would have also warned about `scope`, not just `mu`.
> > I think i'm missing the point here.
> > I originally reverted this because the diagnostics i was seeing were pretty 
> > unambiguously )to me) bogus.
> > But the only test change since then ensures that diagnostic is emitted in 
> > some case,
> > there are no tests to ensure it is not emitted in some cases.
> > So either my revert was wrong, or this still is either issuing seemingly 
> > bogus diagnostic,
> > or lacks test coverage that it doesn't issue said diagnostic.
> > 
> > Which one is it?
> This test fails on the original, reverted change as follows:
> 
> ```
> error: 'warning' diagnostics seen but not expected: 
>   File [...]/clang/test/SemaCXX/warn-thread-safety-negative.cpp Line 88: 
> acquiring mutex 'lock' requires negative capability '!lock'
> 1 error generated.
> ```
> 
> Maybe you're not familiar with the `-verify` mechanism: it doesn't just check 
> that the expected errors/warnings/notes are emitted, it also checks that 
> nothing more is emitted.
> This test fails on the original, reverted change as follows:

Perfect, thanks for checking/confirming!

> Maybe you're not familiar with the -verify mechanism: it doesn't just check 
> that the expected errors/warnings/notes are emitted, it also checks that 
> nothing more is emitted.

I was aware of that, but did not recall that detail until now. Thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84604

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


[PATCH] D84604: Thread safety analysis: Consider global variables in scope

2020-10-25 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: clang/test/SemaCXX/warn-thread-safety-negative.cpp:87-89
+  void test4() {
+MutexLock lock(); // expected-warning {{acquiring mutex 'mu' requires 
negative capability '!mu'}}
+  }

lebedev.ri wrote:
> aaronpuchert wrote:
> > @lebedev.ri, I think that's pretty much your case. On my original change, 
> > this would have also warned about `scope`, not just `mu`.
> I think i'm missing the point here.
> I originally reverted this because the diagnostics i was seeing were pretty 
> unambiguously )to me) bogus.
> But the only test change since then ensures that diagnostic is emitted in 
> some case,
> there are no tests to ensure it is not emitted in some cases.
> So either my revert was wrong, or this still is either issuing seemingly 
> bogus diagnostic,
> or lacks test coverage that it doesn't issue said diagnostic.
> 
> Which one is it?
This test fails on the original, reverted change as follows:

```
error: 'warning' diagnostics seen but not expected: 
  File [...]/clang/test/SemaCXX/warn-thread-safety-negative.cpp Line 88: 
acquiring mutex 'lock' requires negative capability '!lock'
1 error generated.
```

Maybe you're not familiar with the `-verify` mechanism: it doesn't just check 
that the expected errors/warnings/notes are emitted, it also checks that 
nothing more is emitted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84604

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


[PATCH] D86844: [LoopDeletion] Allows deletion of possibly infinite side-effect free loops

2020-10-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: llvm/lib/Transforms/Scalar/LoopDeletion.cpp:60
+// Make sure all exiting blocks produce the same incoming value for the
+// block. If there are different incoming values for different exiting
 // blocks, then it is impossible to statically determine which value should

Nit: add the word back.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86844

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


[PATCH] D90116: [clangd] Escape Unicode characters to fix Windows builds

2020-10-25 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added a comment.

I have face this problem long time ago.
This happens only:

- on non-English Windows (and could be fixed via system settings: Control Panel 
-> Clock,Language,and Region -> Region and Language -> Administrative 
->Language for non-Unicode programs -> Change system locale -> English).
- with Visual Studio Compiler

Seems, there are other places in LLVM with this problem (unsure that this is a 
complete list):
https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp#L53
https://github.com/llvm/llvm-project/blob/master/llvm/unittests/Support/JSONTest.cpp#L240


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90116

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


[PATCH] D84604: Thread safety analysis: Consider global variables in scope

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



Comment at: clang/test/SemaCXX/warn-thread-safety-negative.cpp:87-89
+  void test4() {
+MutexLock lock(); // expected-warning {{acquiring mutex 'mu' requires 
negative capability '!mu'}}
+  }

aaronpuchert wrote:
> @lebedev.ri, I think that's pretty much your case. On my original change, 
> this would have also warned about `scope`, not just `mu`.
I think i'm missing the point here.
I originally reverted this because the diagnostics i was seeing were pretty 
unambiguously )to me) bogus.
But the only test change since then ensures that diagnostic is emitted in some 
case,
there are no tests to ensure it is not emitted in some cases.
So either my revert was wrong, or this still is either issuing seemingly bogus 
diagnostic,
or lacks test coverage that it doesn't issue said diagnostic.

Which one is it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84604

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


[PATCH] D84604: Thread safety analysis: Consider global variables in scope

2020-10-25 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:1275
+const ValueDecl *VD = LP->clangDecl();
+return VD->isDefinedOutsideFunctionOrMethod();
+  }

aaron.ballman wrote:
> Hmm, I've not seen that function used a whole lot before, but looking at the 
> implementation of it, I think it does what we need it to do here. FWIW, I was 
> expecting something more like this:
> ```
> if (const DeclContext *DC = VD->getLexicalDeclContext())
>   return !DC->getRedeclContext()->isFunctionOrMethod();
> ```
> But I'm not certain if this would ever give a different answer from your 
> approach.
Never seen it before as well, but it does a `DC = DC->getParent()` loop, so 
there is probably a difference. Think about `DC` being a local struct or 
Objective-C block declaration.



Comment at: clang/test/SemaCXX/warn-thread-safety-negative.cpp:87-89
+  void test4() {
+MutexLock lock(); // expected-warning {{acquiring mutex 'mu' requires 
negative capability '!mu'}}
+  }

@lebedev.ri, I think that's pretty much your case. On my original change, this 
would have also warned about `scope`, not just `mu`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84604

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


[PATCH] D90123: [Sema] Improve notes for value category mismatch in overloading

2020-10-25 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:4927
 // Note that the function case is not possible here.
-if (DeclType->isRValueReferenceType() && LValRefType) {
-  // FIXME: This is the wrong BadConversionSequence. The problem is binding
-  // an rvalue reference to a (non-function) lvalue, not binding an lvalue
-  // reference to an rvalue!
-  ICS.setBad(BadConversionSequence::lvalue_ref_to_rvalue, Init, DeclType);
+if (isRValRef && LValRefType) {
+  ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType);

No functional change here, I was just using the existing prefetched value.



Comment at: clang/lib/Sema/SemaOverload.cpp:4928
+if (isRValRef && LValRefType) {
+  ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType);
   return ICS;

One might think that this should be `rvalue_ref_to_lvalue`, but we have a 
user-defined conversion here, so probably not.



Comment at: clang/lib/Sema/SemaOverload.cpp:10465-10473
-} else if (ToTy->isLValueReferenceType() && !FromExpr->isLValue() &&
-   ToTy.getNonReferenceType().getCanonicalType() ==
-   FromTy.getNonReferenceType().getCanonicalType()) {
-  S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_lvalue)
-  << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << 
FnDesc
-  << (unsigned)isObjectArgument << I + 1
-  << (FromExpr ? FromExpr->getSourceRange() : SourceRange());

We are in the middle of an if-else cascade that is only setting 
`BaseToDerivedConversion`, where I think this doesn't belong. So I moved it 
directly after the qualifier mismatch handling.



Comment at: clang/test/SemaCXX/overload-member-call.cpp:86-87
 
+void ref() &&;   // expected-note {{expects an r-value for object 
argument}} expected-note {{requires 0 arguments, but 1 was provided}}
+void ref(int) &; // expected-note {{expects an l-value for object 
argument}} expected-note {{requires 1 argument, but 0 were provided}}
+

The respective first note was "no known conversion from 'test1::A' to 
'test1::A' for object argument", which is silly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90123

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


[PATCH] D90101: [Clang][OpenMP][WIP] Avoid unnecessary privatization of mapper array when there is no user defined mapper

2020-10-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

4 tests seem to fail still, otherwise this LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90101

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


[PATCH] D90123: [Sema] Improve notes for value category mismatch in overloading

2020-10-25 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert created this revision.
aaronpuchert added reviewers: aaron.ballman, rsmith.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.
aaronpuchert requested review of this revision.

When an overloaded member function has a ref-qualifier, like:

class X {

  void f() &&;
  void f(int) &;

};

we would print strange notes when the ref-qualifier doesn't fit the value
category:

X x;
x.f();
X().f(0);

would both print a note "no known conversion from 'X' to 'X' for object
argument" on their relevant overload instead of pointing out the
mismatch in value category.

At first I thought the solution is easy: just use the FailureKind member
of the BadConversionSequence struct. But it turns out that we weren't
properly setting this for function arguments. So I went through
TryReferenceInit to make sure we're doing that right, and found a number
of notes in the existing tests that improved as well.

Fixes PR47791.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90123

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/drs/dr1xx.cpp
  clang/test/CXX/drs/dr6xx.cpp
  clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp
  clang/test/SemaCXX/overload-member-call.cpp
  clang/test/SemaCXX/rval-references-examples.cpp

Index: clang/test/SemaCXX/rval-references-examples.cpp
===
--- clang/test/SemaCXX/rval-references-examples.cpp
+++ clang/test/SemaCXX/rval-references-examples.cpp
@@ -13,7 +13,7 @@
 
   ~unique_ptr() { delete ptr; }
 
-  unique_ptr =(unique_ptr &) { // expected-note{{candidate function not viable: no known conversion from 'unique_ptr' to 'unique_ptr &&' for 1st argument}}
+  unique_ptr =(unique_ptr &) { // expected-note{{candidate function not viable: expects an r-value for 1st argument}}
 if (this == )
   return *this;
 
Index: clang/test/SemaCXX/overload-member-call.cpp
===
--- clang/test/SemaCXX/overload-member-call.cpp
+++ clang/test/SemaCXX/overload-member-call.cpp
@@ -83,6 +83,9 @@
 void baz(A ); // expected-note {{candidate function not viable: 1st argument ('const test1::A') would lose const qualifier}}
 void baz(int i); // expected-note {{candidate function not viable: no known conversion from 'const test1::A' to 'int' for 1st argument}} 
 
+void ref() &&;   // expected-note {{expects an r-value for object argument}} expected-note {{requires 0 arguments, but 1 was provided}}
+void ref(int) &; // expected-note {{expects an l-value for object argument}} expected-note {{requires 1 argument, but 0 were provided}}
+
 // PR 11857
 void foo(int n); // expected-note {{candidate function not viable: requires single argument 'n', but 2 arguments were provided}}
 void foo(unsigned n = 10); // expected-note {{candidate function not viable: allows at most single argument 'n', but 2 arguments were provided}}
@@ -103,6 +106,9 @@
 
 a.rab(); //expected-error {{no matching member function for call to 'rab'}}
 a.zab(3, 4, 5); //expected-error {{no matching member function for call to 'zab'}}
+
+a.ref();// expected-error {{no matching member function for call to 'ref'}}
+A().ref(1); // expected-error {{no matching member function for call to 'ref'}}
   }
 }
 
Index: clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp
===
--- clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp
+++ clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp
@@ -7,7 +7,7 @@
 namespace ClassTemplateParamNotForwardingRef {
   // This is not a forwarding reference.
   template struct A { // expected-note {{candidate}}
-A(T&&); // expected-note {{no known conversion from 'int' to 'int &&'}}
+A(T&&); // expected-note {{expects an r-value}}
   };
   int n;
   A a = n; // expected-error {{no viable constructor or deduction guide}}
@@ -53,8 +53,8 @@
   X xy2 = f0(lvalue());
 }
 
-template X f1(const T&&); // expected-note{{candidate function [with T = int] not viable: no known conversion from 'int' to 'const int &&' for 1st argument}} \
-// expected-note{{candidate function [with T = Y] not viable: no known conversion from 'Y' to 'const Y &&' for 1st argument}}
+template X f1(const T&&); // expected-note{{candidate function [with T = int] not viable: expects an r-value for 1st argument}} \
+// expected-note{{candidate function [with T = Y] not viable: expects an r-value for 1st argument}}
 
 void test_f1() {
   X xi0 = f1(prvalue());
@@ -67,7 +67,7 @@
 
 namespace std_example {
   template  int f(T&&); 
-  template  int g(const T&&); // expected-note{{candidate function [with T = int] not viable: no known conversion from 'int' to 'const int &&' for 1st argument}}
+  template  

[PATCH] D90121: Add a consumer to diagnostics engine

2020-10-25 Thread Kirill Dmitrenko via Phabricator via cfe-commits
dmikis created this revision.
dmikis added reviewers: djasper, bkramer, krasimir.
dmikis added a project: clang-format.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.
dmikis requested review of this revision.

Otherwise problems like trying to format readonly file in-place led to crashes.

I've added reviewers by looking at `git blame` and other reviews to the changed 
file, so may have missed someone.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90121

Files:
  clang/tools/clang-format/CMakeLists.txt
  clang/tools/clang-format/ClangFormat.cpp


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/Format/Format.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
@@ -410,9 +411,11 @@
 IntrusiveRefCntPtr InMemoryFileSystem(
 new llvm::vfs::InMemoryFileSystem);
 FileManager Files(FileSystemOptions(), InMemoryFileSystem);
+IntrusiveRefCntPtr DiagOpts(new DiagnosticOptions());
+TextDiagnosticPrinter DiagnosticsConsumer(errs(), &*DiagOpts);
 DiagnosticsEngine Diagnostics(
-IntrusiveRefCntPtr(new DiagnosticIDs),
-new DiagnosticOptions);
+IntrusiveRefCntPtr(new DiagnosticIDs), &*DiagOpts,
+, false);
 SourceManager Sources(Diagnostics, Files);
 FileID ID = createInMemoryFile(AssumedFileName, Code.get(), Sources, Files,
InMemoryFileSystem.get());
Index: clang/tools/clang-format/CMakeLists.txt
===
--- clang/tools/clang-format/CMakeLists.txt
+++ clang/tools/clang-format/CMakeLists.txt
@@ -7,6 +7,7 @@
 set(CLANG_FORMAT_LIB_DEPS
   clangBasic
   clangFormat
+  clangFrontend
   clangRewrite
   clangToolingCore
   )


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/Format/Format.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
@@ -410,9 +411,11 @@
 IntrusiveRefCntPtr InMemoryFileSystem(
 new llvm::vfs::InMemoryFileSystem);
 FileManager Files(FileSystemOptions(), InMemoryFileSystem);
+IntrusiveRefCntPtr DiagOpts(new DiagnosticOptions());
+TextDiagnosticPrinter DiagnosticsConsumer(errs(), &*DiagOpts);
 DiagnosticsEngine Diagnostics(
-IntrusiveRefCntPtr(new DiagnosticIDs),
-new DiagnosticOptions);
+IntrusiveRefCntPtr(new DiagnosticIDs), &*DiagOpts,
+, false);
 SourceManager Sources(Diagnostics, Files);
 FileID ID = createInMemoryFile(AssumedFileName, Code.get(), Sources, Files,
InMemoryFileSystem.get());
Index: clang/tools/clang-format/CMakeLists.txt
===
--- clang/tools/clang-format/CMakeLists.txt
+++ clang/tools/clang-format/CMakeLists.txt
@@ -7,6 +7,7 @@
 set(CLANG_FORMAT_LIB_DEPS
   clangBasic
   clangFormat
+  clangFrontend
   clangRewrite
   clangToolingCore
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 576d436 - Correct LIT test failure detected on buildbot after mibintc committed rG2e204e23911b: [clang] Enable support for #pragma STDC FENV_ACCESS D87528

2020-10-25 Thread Melanie Blower via cfe-commits

Author: Melanie Blower
Date: 2020-10-25T08:10:34-07:00
New Revision: 576d436c828f84f18277e4675e6e5337d2b77fde

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

LOG: Correct LIT test failure detected on buildbot after mibintc committed 
rG2e204e23911b: [clang] Enable support for #pragma STDC FENV_ACCESS D87528

Added: 


Modified: 
clang/test/Parser/pragma-fenv_access.c

Removed: 




diff  --git a/clang/test/Parser/pragma-fenv_access.c 
b/clang/test/Parser/pragma-fenv_access.c
index c789f3313132..3c003d124286 100644
--- a/clang/test/Parser/pragma-fenv_access.c
+++ b/clang/test/Parser/pragma-fenv_access.c
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -ffp-exception-behavior=strict -DSTRICT -fsyntax-only 
-verify %s
-// RUN: %clang_cc1 -x c++ -DCPP -DSTRICT -ffp-exception-behavior=strict 
-fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffp-exception-behavior=strict 
-DSTRICT -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -x c++ -DCPP -DSTRICT 
-ffp-exception-behavior=strict -fsyntax-only -verify %s
 #ifdef CPP
 #define CONST constexpr
 #else



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


[PATCH] D87528: Enable '#pragma STDC FENV_ACCESS' in frontend

2020-10-25 Thread Melanie Blower 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 rG2e204e23911b: [clang] Enable support for #pragma STDC 
FENV_ACCESS (authored by mibintc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87528

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/ScopeInfo.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/CXX/expr/expr.const/p2-0x.cpp
  clang/test/CodeGen/fp-floatcontrol-pragma.cpp
  clang/test/CodeGen/pragma-fenv_access.c
  clang/test/Parser/fp-floatcontrol-syntax.cpp
  clang/test/Parser/pragma-fenv_access.c
  clang/test/Preprocessor/pragma_unknown.c

Index: clang/test/Preprocessor/pragma_unknown.c
===
--- clang/test/Preprocessor/pragma_unknown.c
+++ clang/test/Preprocessor/pragma_unknown.c
@@ -16,15 +16,6 @@
 // CHECK: {{^}}#pragma STDC FP_CONTRACT DEFAULT{{$}}
 // CHECK: {{^}}#pragma STDC FP_CONTRACT IN_BETWEEN{{$}}
 
-#pragma STDC FENV_ACCESS ON  // expected-warning {{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
-#pragma STDC FENV_ACCESS OFF
-#pragma STDC FENV_ACCESS DEFAULT
-#pragma STDC FENV_ACCESS IN_BETWEEN   // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS ON{{$}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS OFF{{$}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS DEFAULT{{$}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS IN_BETWEEN{{$}}
-
 #pragma STDC CX_LIMITED_RANGE ON
 #pragma STDC CX_LIMITED_RANGE OFF
 #pragma STDC CX_LIMITED_RANGE DEFAULT 
Index: clang/test/Parser/pragma-fenv_access.c
===
--- /dev/null
+++ clang/test/Parser/pragma-fenv_access.c
@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -ffp-exception-behavior=strict -DSTRICT -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c++ -DCPP -DSTRICT -ffp-exception-behavior=strict -fsyntax-only -verify %s
+#ifdef CPP
+#define CONST constexpr
+#else
+#define CONST const
+#endif
+
+#pragma STDC FENV_ACCESS IN_BETWEEN   // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
+
+#pragma STDC FENV_ACCESS OFF
+
+float func_04(int x, float y) {
+  if (x)
+return y + 2;
+  #pragma STDC FENV_ACCESS ON // expected-error{{'#pragma STDC FENV_ACCESS' can only appear at file scope or at the start of a compound statement}}
+  return x + y;
+}
+
+#pragma STDC FENV_ACCESS ON
+int main() {
+  CONST float one = 1.0F ;
+  CONST float three = 3.0F ;
+  CONST float four = 4.0F ;
+  CONST float frac_ok = one/four;
+#if !defined(CPP)
+//expected-note@+2 {{declared here}}
+#endif
+  CONST float frac = one/three;
+  CONST double d = one;
+  CONST int not_too_big = 255;
+  CONST float fnot_too_big = not_too_big;
+  CONST int too_big = 0x7ff0;
+#if defined(CPP)
+//expected-warning@+2{{implicit conversion}}
+#endif
+  CONST float fbig = too_big; // inexact
+#if !defined(CPP)
+#define static_assert _Static_assert
+#endif
+enum {
+  e1 = (int)one, e3 = (int)three, e4 = (int)four, e_four_quarters = (int)(frac_ok * 4)
+};
+static_assert(e1 == 1  && e3 == 3 && e4 == 4 && e_four_quarters == 1, "");
+enum {
+#if !defined(CPP)
+// expected-error@+2 {{not an integer constant expression}} expected-note@+2 {{is not a constant expression}}
+#endif
+  e_three_thirds = (int)(frac * 3)
+};
+  if (one <= four)  return 0;
+  return -1;
+}
Index: clang/test/Parser/fp-floatcontrol-syntax.cpp
===
--- clang/test/Parser/fp-floatcontrol-syntax.cpp
+++ clang/test/Parser/fp-floatcontrol-syntax.cpp
@@ -26,19 +26,13 @@
 double a = 0.0;
 double b = 1.0;
 
-//FIXME At some point this warning will be removed, until then
-//  document the warning
-#ifdef FAST
-// expected-warning@+1{{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
-#pragma STDC FENV_ACCESS ON
-#else
-#pragma STDC FENV_ACCESS ON // expected-warning{{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
-#endif
 #ifdef STRICT
 #pragma float_control(precise, off) // expected-error {{'#pragma 

[clang] 2e204e2 - [clang] Enable support for #pragma STDC FENV_ACCESS

2020-10-25 Thread Melanie Blower via cfe-commits

Author: Melanie Blower
Date: 2020-10-25T06:46:25-07:00
New Revision: 2e204e23911b1f8bd1463535da40c6e48747a138

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

LOG: [clang] Enable support for #pragma STDC FENV_ACCESS

Reviewers: rjmccall, rsmith, sepavloff

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

Added: 
clang/test/CodeGen/pragma-fenv_access.c
clang/test/Parser/pragma-fenv_access.c

Modified: 
clang/docs/UsersManual.rst
clang/include/clang/AST/Decl.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ExprConstant.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/Parse/ParsePragma.cpp
clang/lib/Parse/ParseStmt.cpp
clang/lib/Sema/ScopeInfo.cpp
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/CXX/expr/expr.const/p2-0x.cpp
clang/test/CodeGen/fp-floatcontrol-pragma.cpp
clang/test/Parser/fp-floatcontrol-syntax.cpp
clang/test/Preprocessor/pragma_unknown.c

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 9726a25f7f63..5d18435aab6c 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1386,7 +1386,7 @@ Note that floating-point operations performed as part of 
constant initialization
Details:
 
* ``precise`` Disables optimizations that are not value-safe on 
floating-point data, although FP contraction (FMA) is enabled 
(``-ffp-contract=fast``).  This is the default behavior.
-   * ``strict`` Enables ``-frounding-math`` and 
``-ffp-exception-behavior=strict``, and disables contractions (FMA).  All of 
the ``-ffast-math`` enablements are disabled.
+   * ``strict`` Enables ``-frounding-math`` and 
``-ffp-exception-behavior=strict``, and disables contractions (FMA).  All of 
the ``-ffast-math`` enablements are disabled. Enables ``STDC FENV_ACCESS``: by 
default ``FENV_ACCESS`` is disabled. This option setting behaves as though 
``#pragma STDC FENV_ACESS ON`` appeared at the top of the source file.
* ``fast`` Behaves identically to specifying both ``-ffast-math`` and 
``ffp-contract=fast``
 
Note: If your command line specifies multiple instances
@@ -1408,6 +1408,44 @@ Note that floating-point operations performed as part of 
constant initialization
* ``strict`` The compiler ensures that all transformations strictly 
preserve the floating point exception semantics of the original code.
 
 
+.. _fp-constant-eval:
+
+A note about Floating Point Constant Evaluation
+^^^
+
+In C, the only place floating point operations are guaranteed to be evaluated
+during translation is in the initializers of variables of static storage
+duration, which are all notionally initialized before the program begins
+executing (and thus before a non-default floating point environment can be
+entered).  But C++ has many more contexts where floating point constant
+evaluation occurs.  Specifically: for static/thread-local variables,
+first try evaluating the initializer in a constant context, including in the
+constant floating point environment (just like in C), and then, if that fails,
+fall back to emitting runtime code to perform the initialization (which might
+in general be in a 
diff erent floating point environment).
+
+Consider this example when compiled with ``-frounding-math``
+
+   .. code-block:: console
+
+constexpr float func_01(float x, float y) {
+  return x + y;
+}
+float V1 = func_01(1.0F, 0x0.01p0F);
+
+The C++ rule is that initializers for static storage duration variables are
+first evaluated during translation (therefore, in the default rounding mode),
+and only evaluated at runtime (and therefore in the runtime rounding mode) if
+the compile-time evaluation fails. This is in line with the C rules;
+C11 F.8.5 says: *All computation for automatic initialization is done (as if)
+at execution time; thus, it is affected by any operative modes and raises
+floating-point exceptions as required by IEC 60559 (provided the state for the
+FENV_ACCESS pragma is ‘‘on’’). All computation for initialization of objects
+that have static or thread storage duration is done (as if) at translation
+time.* C++ generalizes this by adding another phase of initialization
+(at runtime) if the 

[PATCH] D90116: [clangd] Escape Unicode characters to fix Windows builds

2020-10-25 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 300535.
kbobyrev added a comment.

Use u8 string literals.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90116

Files:
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/Diagnostics.cpp


Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -545,7 +545,7 @@
 
   OS << R;
   if (R.size() != Code.size())
-OS << "…";
+OS << u8"\u2026"; // Unicode Horizontal Ellipsis.
 }
 
 /// Fills \p D with all information, except the location-related bits.
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -86,7 +86,7 @@
   /// A visual indicator to prepend to the completion label to indicate whether
   /// completion result would trigger an #include insertion or not.
   struct IncludeInsertionIndicator {
-std::string Insert = "•";
+std::string Insert = u8"\u2022"; // Unicode Bullet.
 std::string NoInsert = " ";
   } IncludeIndicator;
 


Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -545,7 +545,7 @@
 
   OS << R;
   if (R.size() != Code.size())
-OS << "…";
+OS << u8"\u2026"; // Unicode Horizontal Ellipsis.
 }
 
 /// Fills \p D with all information, except the location-related bits.
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -86,7 +86,7 @@
   /// A visual indicator to prepend to the completion label to indicate whether
   /// completion result would trigger an #include insertion or not.
   struct IncludeInsertionIndicator {
-std::string Insert = "•";
+std::string Insert = u8"\u2022"; // Unicode Bullet.
 std::string NoInsert = " ";
   } IncludeIndicator;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84604: Thread safety analysis: Consider global variables in scope

2020-10-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

Please can you point me where you've added the negative test for the 
false-positive issue that caused the revert last time?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84604

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


[PATCH] D84604: Thread safety analysis: Consider global variables in scope

2020-10-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM




Comment at: clang/lib/Analysis/ThreadSafety.cpp:1275
+const ValueDecl *VD = LP->clangDecl();
+return VD->isDefinedOutsideFunctionOrMethod();
+  }

Hmm, I've not seen that function used a whole lot before, but looking at the 
implementation of it, I think it does what we need it to do here. FWIW, I was 
expecting something more like this:
```
if (const DeclContext *DC = VD->getLexicalDeclContext())
  return !DC->getRedeclContext()->isFunctionOrMethod();
```
But I'm not certain if this would ever give a different answer from your 
approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84604

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


[PATCH] D80499: Remove obsolete ignore*() matcher uses

2020-10-25 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a subscriber: alexfh.
steveire added a comment.

@alexfh This change is based on the behavior of AST Matchers being changed to 
ignore invisible/implicit AST nodes by default. As the default was not changed 
in the end, this patch would need to be updated to add 
`traverse(TK_IgnoreUnlessSpelledInSource)` wrapping around the matchers.

Before I update the patch to add that, do you have any feedback?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80499

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


[PATCH] D90116: [clangd] Escape Unicode characters to fix Windows builds

2020-10-25 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added reviewers: kadircet, sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman.
Herald added a project: clang.
kbobyrev requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90116

Files:
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/Diagnostics.cpp


Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -545,7 +545,7 @@
 
   OS << R;
   if (R.size() != Code.size())
-OS << "…";
+OS << "\u2026"; // Unicode Horizontal Ellipsis.
 }
 
 /// Fills \p D with all information, except the location-related bits.
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -86,7 +86,7 @@
   /// A visual indicator to prepend to the completion label to indicate whether
   /// completion result would trigger an #include insertion or not.
   struct IncludeInsertionIndicator {
-std::string Insert = "•";
+std::string Insert = "\u2022"; // Unicode Bullet.
 std::string NoInsert = " ";
   } IncludeIndicator;
 


Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -545,7 +545,7 @@
 
   OS << R;
   if (R.size() != Code.size())
-OS << "…";
+OS << "\u2026"; // Unicode Horizontal Ellipsis.
 }
 
 /// Fills \p D with all information, except the location-related bits.
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -86,7 +86,7 @@
   /// A visual indicator to prepend to the completion label to indicate whether
   /// completion result would trigger an #include insertion or not.
   struct IncludeInsertionIndicator {
-std::string Insert = "•";
+std::string Insert = "\u2022"; // Unicode Bullet.
 std::string NoInsert = " ";
   } IncludeIndicator;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D89851: [clangd] Separate final_result into a different message; NFC

2020-10-25 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 300528.
kbobyrev added a comment.

Rebase on top of master, use proto2 syntax.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89851

Files:
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/server/Server.cpp


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -109,7 +109,7 @@
   ++Sent;
 });
 LookupReply LastMessage;
-LastMessage.set_final_result(true);
+LastMessage.mutable_result()->set_has_more(true);
 Reply->Write(LastMessage);
 SPAN_ATTACH(Tracer, "Sent", Sent);
 SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
@@ -142,7 +142,7 @@
   ++Sent;
 });
 FuzzyFindReply LastMessage;
-LastMessage.set_final_result(HasMore);
+LastMessage.mutable_result()->set_has_more(HasMore);
 Reply->Write(LastMessage);
 SPAN_ATTACH(Tracer, "Sent", Sent);
 SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
@@ -173,7 +173,7 @@
   ++Sent;
 });
 RefsReply LastMessage;
-LastMessage.set_final_result(HasMore);
+LastMessage.mutable_result()->set_has_more(HasMore);
 Reply->Write(LastMessage);
 SPAN_ATTACH(Tracer, "Sent", Sent);
 SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
@@ -207,7 +207,7 @@
   ++Sent;
 });
 RelationsReply LastMessage;
-LastMessage.set_final_result(true);
+LastMessage.mutable_result()->set_has_more(true);
 Reply->Write(LastMessage);
 SPAN_ATTACH(Tracer, "Sent", Sent);
 SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
Index: clang-tools-extra/clangd/index/remote/Index.proto
===
--- clang-tools-extra/clangd/index/remote/Index.proto
+++ clang-tools-extra/clangd/index/remote/Index.proto
@@ -12,12 +12,14 @@
 
 message LookupRequest { repeated string ids = 1; }
 
+message FinalResult { optional bool has_more = 1; }
+
 // The response is a stream of symbol messages and the terminating message
 // indicating the end of stream.
 message LookupReply {
   oneof kind {
 Symbol stream_result = 1;
-bool final_result = 2;
+FinalResult result = 2;
   }
 }
 
@@ -36,7 +38,7 @@
 message FuzzyFindReply {
   oneof kind {
 Symbol stream_result = 1;
-bool final_result = 2; // HasMore
+FinalResult result = 2;
   }
 }
 
@@ -51,7 +53,7 @@
 message RefsReply {
   oneof kind {
 Ref stream_result = 1;
-bool final_result = 2; // HasMore
+FinalResult result = 2;
   }
 }
 
@@ -116,7 +118,7 @@
 message RelationsReply {
   oneof kind {
 Relation stream_result = 1;
-bool final_result = 2; // HasMore
+FinalResult result = 2;
   }
 }
 
Index: clang-tools-extra/clangd/index/remote/Client.cpp
===
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -52,7 +52,7 @@
 unsigned FailedToParse = 0;
 while (Reader->Read()) {
   if (!Reply.has_stream_result()) {
-FinalResult = Reply.final_result();
+FinalResult = Reply.result().has_more();
 continue;
   }
   auto Response = ProtobufMarshaller->fromProtobuf(Reply.stream_result());


Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -109,7 +109,7 @@
   ++Sent;
 });
 LookupReply LastMessage;
-LastMessage.set_final_result(true);
+LastMessage.mutable_result()->set_has_more(true);
 Reply->Write(LastMessage);
 SPAN_ATTACH(Tracer, "Sent", Sent);
 SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
@@ -142,7 +142,7 @@
   ++Sent;
 });
 FuzzyFindReply LastMessage;
-LastMessage.set_final_result(HasMore);
+LastMessage.mutable_result()->set_has_more(HasMore);
 Reply->Write(LastMessage);
 SPAN_ATTACH(Tracer, "Sent", Sent);
 SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
@@ -173,7 +173,7 @@
   ++Sent;
 });
 RefsReply LastMessage;
-LastMessage.set_final_result(HasMore);
+LastMessage.mutable_result()->set_has_more(HasMore);
 Reply->Write(LastMessage);
 SPAN_ATTACH(Tracer, "Sent", Sent);
 SPAN_ATTACH(Tracer, "Failed to send", FailedToSend);
@@ -207,7 +207,7 @@
   ++Sent;
 });
 RelationsReply LastMessage;
-LastMessage.set_final_result(true);
+LastMessage.mutable_result()->set_has_more(true);
 Reply->Write(LastMessage);
 SPAN_ATTACH(Tracer, "Sent", Sent);
 

[clang] f81f09b - [c++20] For P0732R2: Support string literal operator templates.

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

Author: Richard Smith
Date: 2020-10-25T00:34:15-07:00
New Revision: f81f09ba8950a199af88e5a622155fb9801b11b7

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

LOG: [c++20] For P0732R2: Support string literal operator templates.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaLookup.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p5.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 18f115003f38..ed409b93545e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3889,7 +3889,7 @@ class Sema final {
 /// The lookup found an overload set of literal operator templates,
 /// which expect the character type and characters of the spelling of the
 /// string literal token to be passed as template arguments.
-LOLR_StringTemplate
+LOLR_StringTemplatePack,
   };
 
   SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D,
@@ -3997,12 +3997,11 @@ class Sema final {
   CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
 
   bool checkLiteralOperatorId(const CXXScopeSpec , const UnqualifiedId );
-  LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult ,
-ArrayRef ArgTys,
-bool AllowRaw,
-bool AllowTemplate,
-bool AllowStringTemplate,
-bool DiagnoseMissing);
+  LiteralOperatorLookupResult
+  LookupLiteralOperator(Scope *S, LookupResult , ArrayRef ArgTys,
+bool AllowRaw, bool AllowTemplate,
+bool AllowStringTemplate, bool DiagnoseMissing,
+StringLiteral *StringLit = nullptr);
   bool isKnownName(StringRef name);
 
   /// Status of the function emission on the CUDA/HIP/OpenMP host/device attrs.

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 6589b37338e9..bc119725e4a0 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -15522,6 +15522,18 @@ checkLiteralOperatorTemplateParameterList(Sema 
,
 SemaRef.Context.hasSameType(PmDecl->getType(), SemaRef.Context.CharTy))
   return false;
 
+// C++20 [over.literal]p5:
+//   A string literal operator template is a literal operator template
+//   whose template-parameter-list comprises a single non-type
+//   template-parameter of class type.
+//
+// As a DR resolution, we also allow placeholders for deduced class
+// template specializations.
+if (SemaRef.getLangOpts().CPlusPlus20 &&
+!PmDecl->isTemplateParameterPack() &&
+(PmDecl->getType()->isRecordType() ||
+ PmDecl->getType()->getAs()))
+  return false;
   } else if (TemplateParams->size() == 2) {
 TemplateTypeParmDecl *PmType =
 dyn_cast(TemplateParams->getParam(0));
@@ -15578,6 +15590,8 @@ bool Sema::CheckLiteralOperatorDeclaration(FunctionDecl 
*FnDecl) {
   // template  type operator "" name() and
   // template  type operator "" name() are the only valid
   // template signatures, and the only valid signatures with no parameters.
+  //
+  // C++20 also allows template  type operator "" name().
   if (TpDecl) {
 if (FnDecl->param_size() != 0) {
   Diag(FnDecl->getLocation(),

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6bc838a1acd5..13db8362e065 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1758,7 +1758,7 @@ static ExprResult BuildCookedLiteralOperatorCall(Sema , 
Scope *Scope,
   LookupResult R(S, OpName, UDSuffixLoc, Sema::LookupOrdinaryName);
   if (S.LookupLiteralOperator(Scope, R, llvm::makeArrayRef(ArgTy, Args.size()),
   /*AllowRaw*/ false, /*AllowTemplate*/ false,
-  /*AllowStringTemplate*/ false,
+  /*AllowStringTemplatePack*/ false,
   /*DiagnoseMissing*/ true) == Sema::LOLR_Error)
 return ExprError();
 
@@ -1863,9 +1863,9 @@ Sema::ActOnStringLiteral(ArrayRef StringToks, 
Scope *UDLScope) {
 
   LookupResult R(*this, OpName, UDSuffixLoc, LookupOrdinaryName);
   switch (LookupLiteralOperator(UDLScope, R, ArgTy,
-/*AllowRaw*/ false, /*AllowTemplate*/ false,
-/*AllowStringTemplate*/ true,
-/*DiagnoseMissing*/ true)) {
+/*AllowRaw*/ false, /*AllowTemplate*/ true,
+