[PATCH] D67940: [BPF] Preserve and make bitfield access relocatable

2019-09-23 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 221466.
yonghong-song added a comment.
Herald added a subscriber: ormris.

fix a bug like `foo(..., bar(), value)` where `value` is set in function 
`bar`. This is not right and depends on compiler optimization as there is not 
guarantee that arguments are evaluated from left to right. The new code looks 
like ` a = bar(); foo(..., a, value)` ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67940

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-preserve-bitfield-info-2.c
  clang/test/CodeGen/builtin-preserve-bitfield-info.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
  llvm/lib/Target/BPF/BPFCORE.h
  llvm/lib/Target/BPF/BTF.h
  llvm/lib/Target/BPF/BTFDebug.cpp
  llvm/lib/Target/BPF/BTFDebug.h
  llvm/test/CodeGen/BPF/CORE/intrinsic-bitfield.ll
  llvm/test/CodeGen/BPF/CORE/intrinsic-struct.ll
  llvm/test/CodeGen/BPF/CORE/offset-reloc-bitfield.ll

Index: llvm/test/CodeGen/BPF/CORE/offset-reloc-bitfield.ll
===
--- /dev/null
+++ llvm/test/CodeGen/BPF/CORE/offset-reloc-bitfield.ll
@@ -0,0 +1,112 @@
+; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+; Source code:
+;   struct s {
+; int a;
+; int b1:8;
+; int b2:3;
+; int b3:4;
+;   };
+;
+;   #define _(x, y) __builtin_preserve_bitfield_info((x), (y))
+;   void process(void *);
+;   unsigned test(struct s *arg) {
+; unsigned info1, info2;
+; void *p1, *p2;
+;
+; p1 = _(arg->b2, );
+; p2 = _(arg->b3, );
+; process(p1);
+; process(p2);
+; // the last 16 bit is the offset, so
+; // return value should be 8 + 11 = 19
+; // At -O2, compiler should do this optimization.
+; return (info1 & 0x) + (info2 & 0x);
+;   }
+
+%struct.s = type { i32, i16 }
+
+; Function Attrs: nounwind
+define dso_local i32 @test(%struct.s* %arg) local_unnamed_addr #0 !dbg !7 {
+entry:
+  call void @llvm.dbg.value(metadata %struct.s* %arg, metadata !20, metadata !DIExpression()), !dbg !26
+  %0 = tail call i16* @llvm.preserve.struct.access.index.p0i16.p0s_struct.ss(%struct.s* %arg, i32 1, i32 2, i32 1), !dbg !27, !llvm.preserve.access.index !12
+  %1 = bitcast i16* %0 to i8*, !dbg !27
+  call void @llvm.dbg.value(metadata i32 -2147287032, metadata !21, metadata !DIExpression()), !dbg !26
+  call void @llvm.dbg.value(metadata i8* %1, metadata !23, metadata !DIExpression()), !dbg !26
+  %2 = tail call i16* @llvm.preserve.struct.access.index.p0i16.p0s_struct.ss(%struct.s* %arg, i32 1, i32 3, i32 1), !dbg !28, !llvm.preserve.access.index !12
+  %3 = bitcast i16* %2 to i8*, !dbg !28
+  call void @llvm.dbg.value(metadata i32 -2147221493, metadata !22, metadata !DIExpression()), !dbg !26
+  call void @llvm.dbg.value(metadata i8* %3, metadata !25, metadata !DIExpression()), !dbg !26
+  tail call void @process(i8* %1) #4, !dbg !29
+  tail call void @process(i8* %3) #4, !dbg !30
+  ret i32 19, !dbg !31
+}
+
+; CHECK-LABEL:   test
+; CHECK: r1 = 4
+; CHECK: r{{[0-9]+}} += r1
+; CHECK: r0 = 19
+; CHECK: exit
+;
+; CHECK: .ascii  ".text" # string offset=40
+; CHECK: .ascii  "0:1"   # string offset=83
+; CHECK: .ascii  "2$3"   # string offset=87
+; CHECK:.long   16  # OffsetReloc
+; CHECK-NEXT:   .long   40  # Offset reloc section string offset=40
+; CHECK-NEXT:   .long   1
+; CHECK-NEXT:   .long   .Ltmp{{[0-9]+}}
+; CHECK-NEXT:   .long   2
+; CHECK-NEXT:   .long   83
+; CHECK-NEXT:   .long   87
+
+; Function Attrs: nounwind readnone
+declare i16* @llvm.preserve.struct.access.index.p0i16.p0s_struct.ss(%struct.s*, i32, i32, i32) #1
+
+declare dso_local void @process(i8*) local_unnamed_addr #2
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata) #3
+
+attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone }
+attributes #2 = { 

r372688 - [ASTImporter] 3rd attempt to fix Windows buildbot test errors

2019-09-23 Thread Gabor Marton via cfe-commits
Author: martong
Date: Mon Sep 23 22:50:02 2019
New Revision: 372688

URL: http://llvm.org/viewvc/llvm-project?rev=372688=rev
Log:
[ASTImporter] 3rd attempt to fix Windows buildbot test errors

Modified:
cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp

Modified: cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp?rev=372688=372687=372688=diff
==
--- cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp Mon Sep 23 
22:50:02 2019
@@ -30,9 +30,9 @@ using internal::BindableMatcher;
 
 struct Function {
   using DeclTy = FunctionDecl;
-  static constexpr auto *Prototype = "void X(char*, char);";
+  static constexpr auto *Prototype = "void X(int);";
   static constexpr auto *ConflictingPrototype = "void X(double);";
-  static constexpr auto *Definition = "void X(char *a, char b) {}";
+  static constexpr auto *Definition = "void X(int a) {}";
   static constexpr auto *ConflictingDefinition = "void X(double a) {}";
   BindableMatcher getPattern() {
 return functionDecl(hasName("X"), unless(isImplicit()));
@@ -582,7 +582,8 @@ ASTIMPORTER_ODR_INSTANTIATE_TYPED_TEST_C
 
 INSTANTIATE_TEST_CASE_P(
 ODRViolationTests, FunctionConservative,
-DefaultTestValuesForRunOptions, );
+// These tests fail on Windows.
+::testing::Values(ArgVector{"-target", "x86_64-pc-linux-gnu"}), );
 INSTANTIATE_TEST_CASE_P(
 ODRViolationTests, TypedefConservative,
 DefaultTestValuesForRunOptions, );
@@ -624,7 +625,8 @@ INSTANTIATE_TEST_CASE_P(
 
 INSTANTIATE_TEST_CASE_P(
 ODRViolationTests, FunctionLiberal,
-DefaultTestValuesForRunOptions, );
+// These tests fail on Windows.
+::testing::Values(ArgVector{"-target", "x86_64-pc-linux-gnu"}), );
 INSTANTIATE_TEST_CASE_P(
 ODRViolationTests, TypedefLiberal,
 DefaultTestValuesForRunOptions, );


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


r372687 - Revert "[static analyzer] Define __clang_analyzer__ macro in driver"

2019-09-23 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Mon Sep 23 20:21:22 2019
New Revision: 372687

URL: http://llvm.org/viewvc/llvm-project?rev=372687=rev
Log:
Revert "[static analyzer] Define __clang_analyzer__ macro in driver"

This reverts commit fbd13570b0d5f92ef2cf6bcfe7cc2f6178500187.

Removed:
cfe/trunk/test/Analysis/misc-driver.c
Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/Analysis/misc-ps.m

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=372687=372686=372687=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Sep 23 20:21:22 2019
@@ -3896,10 +3896,8 @@ void Clang::ConstructJob(Compilation ,
   if (Args.hasArg(options::OPT_municode))
 CmdArgs.push_back("-DUNICODE");
 
-  if (isa(JA)) {
+  if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
-CmdArgs.push_back("-D__clang_analyzer__");
-  }
 
   // Enable compatilibily mode to avoid analyzer-config related errors.
   // Since we can't access frontend flags through hasArg, let's manually 
iterate

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=372687=372686=372687=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Sep 23 20:21:22 2019
@@ -990,6 +990,10 @@ static void InitializePredefinedMacros(c
   else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
 Builder.defineMacro("__SSP_ALL__", "3");
 
+  // Define a macro that exists only when using the static analyzer.
+  if (FEOpts.ProgramAction == frontend::RunAnalysis)
+Builder.defineMacro("__clang_analyzer__");
+
   if (LangOpts.FastRelaxedMath)
 Builder.defineMacro("__FAST_RELAXED_MATH__");
 

Removed: cfe/trunk/test/Analysis/misc-driver.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-driver.c?rev=372686=auto
==
--- cfe/trunk/test/Analysis/misc-driver.c (original)
+++ cfe/trunk/test/Analysis/misc-driver.c (removed)
@@ -1,5 +0,0 @@
-// RUN: %clang --analyze %s
-
-#ifndef __clang_analyzer__
-#error __clang_analyzer__ not defined
-#endif

Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=372687=372686=372687=diff
==
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Mon Sep 23 20:21:22 2019
@@ -2,6 +2,10 @@
 // RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 
-analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-store=region 
-verify -fblocks -Wno-unreachable-code -Wno-null-dereference 
-Wno-objc-root-class %s
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-store=region 
-verify -fblocks -Wno-unreachable-code -Wno-null-dereference 
-Wno-objc-root-class %s
 
+#ifndef __clang_analyzer__
+#error __clang_analyzer__ not defined
+#endif
+
 typedef struct objc_ivar *Ivar;
 typedef struct objc_selector *SEL;
 typedef signed char BOOL;


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


r372685 - Revert "[static analyzer][test] Test directly that driver sets D__clang_analyzer__"

2019-09-23 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Mon Sep 23 20:19:20 2019
New Revision: 372685

URL: http://llvm.org/viewvc/llvm-project?rev=372685=rev
Log:
Revert "[static analyzer][test] Test directly that driver sets 
D__clang_analyzer__"

This reverts commit c7541903d72765a38808e9973572a8d50c9d94fb.

Modified:
cfe/trunk/test/Analysis/misc-driver.c

Modified: cfe/trunk/test/Analysis/misc-driver.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-driver.c?rev=372685=372684=372685=diff
==
--- cfe/trunk/test/Analysis/misc-driver.c (original)
+++ cfe/trunk/test/Analysis/misc-driver.c Mon Sep 23 20:19:20 2019
@@ -1,2 +1,5 @@
-// RUN: %clang -### --analyze %s 2>&1 | FileCheck %s
-// CHECK: -D__clang_analyzer__
+// RUN: %clang --analyze %s
+
+#ifndef __clang_analyzer__
+#error __clang_analyzer__ not defined
+#endif


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


Re: r372679 - [static analyzer] Define __clang_analyzer__ macro in driver

2019-09-23 Thread Jan Korous via cfe-commits
Well, those were not fixups in the sense that I was aware of anything broken...

Anyway, I don't see a quick fix for clang-tidy so I'm going to revert.

> On Sep 23, 2019, at 8:00 PM, Nico Weber  wrote:
> 
> Even after all the fixup attempts, there's still a failing clang-tools-extra 
> test:
> 
> ninja: Entering directory `out/gn'
> [0/2] ACTION 
> //clang-tools-extra/test:check-clang-tools(//llvm/utils/gn/build/toolchain:unix)
> -- Testing: 787 tests, 64 threads --
> Testing: 0 .. 10
> FAIL: Clang Tools :: clang-tidy/clang-tidy-__clang_analyzer__macro.cpp (112 
> of 787)
>  TEST 'Clang Tools :: 
> clang-tidy/clang-tidy-__clang_analyzer__macro.cpp' FAILED 
> Script:
> --
> : 'RUN: at line 1';   clang-tidy 
> /usr/local/google/home/thakis/src/llvm-project/clang-tools-extra/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
>  -checks=-*,modernize-use-nullptr -- | count 0
> --
> Exit Code: 1
> 
> Command Output (stderr):
> --
> 1 error generated.
> Error while processing 
> /usr/local/google/home/thakis/src/llvm-project/clang-tools-extra/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp.
> Found compiler error(s).
> Expected 0 lines, got 3.
> 
> --
> 
> 
> Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
> Testing Time: 4.11s
> 
> Failing Tests (1):
> Clang Tools :: clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
> 
> 
> On Mon, Sep 23, 2019 at 8:31 PM Jan Korous via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Author: jkorous
> Date: Mon Sep 23 17:33:47 2019
> New Revision: 372679
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=372679=rev 
> 
> Log:
> [static analyzer] Define __clang_analyzer__ macro in driver
> 
> Differential Revision: https://reviews.llvm.org/D67938 
> 
> 
> Added:
> cfe/trunk/test/Analysis/misc-driver.c
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> cfe/trunk/lib/Frontend/InitPreprocessor.cpp
> cfe/trunk/test/Analysis/misc-ps.m
> 
> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=372679=372678=372679=diff
>  
> 
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Sep 23 17:33:47 2019
> @@ -3896,8 +3896,10 @@ void Clang::ConstructJob(Compilation ,
>if (Args.hasArg(options::OPT_municode))
>  CmdArgs.push_back("-DUNICODE");
> 
> -  if (isa(JA))
> +  if (isa(JA)) {
>  RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
> +CmdArgs.push_back("-D__clang_analyzer__");
> +  }
> 
>// Enable compatilibily mode to avoid analyzer-config related errors.
>// Since we can't access frontend flags through hasArg, let's manually 
> iterate
> 
> Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=372679=372678=372679=diff
>  
> 
> ==
> --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
> +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Sep 23 17:33:47 2019
> @@ -990,10 +990,6 @@ static void InitializePredefinedMacros(c
>else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
>  Builder.defineMacro("__SSP_ALL__", "3");
> 
> -  // Define a macro that exists only when using the static analyzer.
> -  if (FEOpts.ProgramAction == frontend::RunAnalysis)
> -Builder.defineMacro("__clang_analyzer__");
> -
>if (LangOpts.FastRelaxedMath)
>  Builder.defineMacro("__FAST_RELAXED_MATH__");
> 
> 
> Added: cfe/trunk/test/Analysis/misc-driver.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-driver.c?rev=372679=auto
>  
> 
> ==
> --- cfe/trunk/test/Analysis/misc-driver.c (added)
> +++ cfe/trunk/test/Analysis/misc-driver.c Mon Sep 23 17:33:47 2019
> @@ -0,0 +1,5 @@
> +// RUN: %clang --analyze %s
> +
> +#ifndef __clang_analyzer__
> +#error __clang_analyzer__ not defined
> +#endif
> 
> Modified: cfe/trunk/test/Analysis/misc-ps.m
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=372679=372678=372679=diff
>  
> 
> ==
> --- 

Re: r372679 - [static analyzer] Define __clang_analyzer__ macro in driver

2019-09-23 Thread Nico Weber via cfe-commits
Even after all the fixup attempts, there's still a failing
clang-tools-extra test:

ninja: Entering directory `out/gn'
[0/2] ACTION
//clang-tools-extra/test:check-clang-tools(//llvm/utils/gn/build/toolchain:unix)
-- Testing: 787 tests, 64 threads --
Testing: 0 .. 10
FAIL: Clang Tools :: clang-tidy/clang-tidy-__clang_analyzer__macro.cpp (112
of 787)
 TEST 'Clang Tools ::
clang-tidy/clang-tidy-__clang_analyzer__macro.cpp' FAILED

Script:
--
: 'RUN: at line 1';   clang-tidy
/usr/local/google/home/thakis/src/llvm-project/clang-tools-extra/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
-checks=-*,modernize-use-nullptr -- | count 0
--
Exit Code: 1

Command Output (stderr):
--
1 error generated.
Error while processing
/usr/local/google/home/thakis/src/llvm-project/clang-tools-extra/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp.
Found compiler error(s).
Expected 0 lines, got 3.

--


Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
Testing Time: 4.11s

Failing Tests (1):
Clang Tools :: clang-tidy/clang-tidy-__clang_analyzer__macro.cpp


On Mon, Sep 23, 2019 at 8:31 PM Jan Korous via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: jkorous
> Date: Mon Sep 23 17:33:47 2019
> New Revision: 372679
>
> URL: http://llvm.org/viewvc/llvm-project?rev=372679=rev
> Log:
> [static analyzer] Define __clang_analyzer__ macro in driver
>
> Differential Revision: https://reviews.llvm.org/D67938
>
> Added:
> cfe/trunk/test/Analysis/misc-driver.c
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> cfe/trunk/lib/Frontend/InitPreprocessor.cpp
> cfe/trunk/test/Analysis/misc-ps.m
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=372679=372678=372679=diff
>
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Sep 23 17:33:47 2019
> @@ -3896,8 +3896,10 @@ void Clang::ConstructJob(Compilation ,
>if (Args.hasArg(options::OPT_municode))
>  CmdArgs.push_back("-DUNICODE");
>
> -  if (isa(JA))
> +  if (isa(JA)) {
>  RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
> +CmdArgs.push_back("-D__clang_analyzer__");
> +  }
>
>// Enable compatilibily mode to avoid analyzer-config related errors.
>// Since we can't access frontend flags through hasArg, let's manually
> iterate
>
> Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=372679=372678=372679=diff
>
> ==
> --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
> +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Sep 23 17:33:47 2019
> @@ -990,10 +990,6 @@ static void InitializePredefinedMacros(c
>else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
>  Builder.defineMacro("__SSP_ALL__", "3");
>
> -  // Define a macro that exists only when using the static analyzer.
> -  if (FEOpts.ProgramAction == frontend::RunAnalysis)
> -Builder.defineMacro("__clang_analyzer__");
> -
>if (LangOpts.FastRelaxedMath)
>  Builder.defineMacro("__FAST_RELAXED_MATH__");
>
>
> Added: cfe/trunk/test/Analysis/misc-driver.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-driver.c?rev=372679=auto
>
> ==
> --- cfe/trunk/test/Analysis/misc-driver.c (added)
> +++ cfe/trunk/test/Analysis/misc-driver.c Mon Sep 23 17:33:47 2019
> @@ -0,0 +1,5 @@
> +// RUN: %clang --analyze %s
> +
> +#ifndef __clang_analyzer__
> +#error __clang_analyzer__ not defined
> +#endif
>
> Modified: cfe/trunk/test/Analysis/misc-ps.m
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=372679=372678=372679=diff
>
> ==
> --- cfe/trunk/test/Analysis/misc-ps.m (original)
> +++ cfe/trunk/test/Analysis/misc-ps.m Mon Sep 23 17:33:47 2019
> @@ -2,10 +2,6 @@
>  // RUN: %clang_analyze_cc1 -triple i386-apple-darwin10
> -analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-store=region
> -verify -fblocks -Wno-unreachable-code -Wno-null-dereference
> -Wno-objc-root-class %s
>  // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10
> -analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-store=region
> -verify -fblocks -Wno-unreachable-code -Wno-null-dereference
> -Wno-objc-root-class %s
>
> -#ifndef __clang_analyzer__
> -#error __clang_analyzer__ not defined
> -#endif
> -
>  typedef struct objc_ivar *Ivar;
>  typedef struct objc_selector *SEL;
>  typedef signed char BOOL;
>
>
> ___
> cfe-commits mailing 

[PATCH] D67947: [HIP] Support new kernel launching API

2019-09-23 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.

https://reviews.llvm.org/D67947

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  lib/CodeGen/CGCUDANV.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaCUDA.cpp
  test/CodeGenCUDA/Inputs/cuda.h
  test/CodeGenCUDA/kernel-call.cu

Index: test/CodeGenCUDA/kernel-call.cu
===
--- test/CodeGenCUDA/kernel-call.cu
+++ test/CodeGenCUDA/kernel-call.cu
@@ -3,14 +3,17 @@
 // RUN: %clang_cc1 -target-sdk-version=9.2  -emit-llvm %s -o - \
 // RUN: | FileCheck %s --check-prefixes=CUDA-NEW,CHECK
 // RUN: %clang_cc1 -x hip -emit-llvm %s -o - \
-// RUN: | FileCheck %s --check-prefixes=HIP,CHECK
-
+// RUN: | FileCheck %s --check-prefixes=HIP-OLD,CHECK
+// RUN: %clang_cc1 -fhip-new-launch-api -x hip -emit-llvm %s -o - \
+// RUN: | FileCheck %s --check-prefixes=HIP-NEW,CHECK
 
 #include "Inputs/cuda.h"
 
 // CHECK-LABEL: define{{.*}}g1
-// HIP: call{{.*}}hipSetupArgument
-// HIP: call{{.*}}hipLaunchByPtr
+// HIP-OLD: call{{.*}}hipSetupArgument
+// HIP-OLD: call{{.*}}hipLaunchByPtr
+// HIP-NEW: call{{.*}}__hipPopCallConfiguration
+// HIP-NEW: call{{.*}}hipLaunchKernelByPtr
 // CUDA-OLD: call{{.*}}cudaSetupArgument
 // CUDA-OLD: call{{.*}}cudaLaunch
 // CUDA-NEW: call{{.*}}__cudaPopCallConfiguration
@@ -19,7 +22,8 @@
 
 // CHECK-LABEL: define{{.*}}main
 int main(void) {
-  // HIP: call{{.*}}hipConfigureCall
+  // HIP-OLD: call{{.*}}hipConfigureCall
+  // HIP-NEW: call{{.*}}__hipPushCallConfiguration
   // CUDA-OLD: call{{.*}}cudaConfigureCall
   // CUDA-NEW: call{{.*}}__cudaPushCallConfiguration
   // CHECK: icmp
Index: test/CodeGenCUDA/Inputs/cuda.h
===
--- test/CodeGenCUDA/Inputs/cuda.h
+++ test/CodeGenCUDA/Inputs/cuda.h
@@ -14,12 +14,21 @@
   __host__ __device__ dim3(unsigned x, unsigned y = 1, unsigned z = 1) : x(x), y(y), z(z) {}
 };
 
-typedef struct cudaStream *cudaStream_t;
-typedef enum cudaError {} cudaError_t;
 #ifdef __HIP__
+typedef struct hipStream *hipStream_t;
+typedef enum hipError {} hipError_t;
 int hipConfigureCall(dim3 gridSize, dim3 blockSize, size_t sharedSize = 0,
- cudaStream_t stream = 0);
+ hipStream_t stream = 0);
+extern "C" hipError_t __hipPushCallConfiguration(dim3 gridSize, dim3 blockSize,
+ size_t sharedSize = 0,
+ hipStream_t stream = 0);
+extern "C" hipError_t hipLaunchKernelByPtr(const void *func, dim3 gridDim,
+   dim3 blockDim, void **args,
+   size_t sharedMem,
+   hipStream_t stream);
 #else
+typedef struct cudaStream *cudaStream_t;
+typedef enum cudaError {} cudaError_t;
 extern "C" int cudaConfigureCall(dim3 gridSize, dim3 blockSize,
  size_t sharedSize = 0,
  cudaStream_t stream = 0);
Index: lib/Sema/SemaCUDA.cpp
===
--- lib/Sema/SemaCUDA.cpp
+++ lib/Sema/SemaCUDA.cpp
@@ -821,7 +821,8 @@
 
 std::string Sema::getCudaConfigureFuncName() const {
   if (getLangOpts().HIP)
-return "hipConfigureCall";
+return getLangOpts().HIPUseNewLaunchAPI ? "__hipPushCallConfiguration"
+: "hipConfigureCall";
 
   // New CUDA kernel launch sequence.
   if (CudaFeatureEnabled(Context.getTargetInfo().getSDKVersion(),
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2514,6 +2514,7 @@
 Opts.CUDADeviceApproxTranscendentals = 1;
 
   Opts.GPURelocatableDeviceCode = Args.hasArg(OPT_fgpu_rdc);
+  Opts.HIPUseNewLaunchAPI = Args.hasArg(OPT_fhip_new_launch_api);
 
   if (Opts.ObjC) {
 if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4774,6 +4774,10 @@
   // Forward -cl options to -cc1
   RenderOpenCLOptions(Args, CmdArgs);
 
+  if (Args.hasFlag(options::OPT_fhip_new_launch_api,
+   options::OPT_fno_hip_new_launch_api, false))
+CmdArgs.push_back("-fhip-new-launch-api");
+
   if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
Index: lib/CodeGen/CGCUDANV.cpp
===
--- lib/CodeGen/CGCUDANV.cpp
+++ lib/CodeGen/CGCUDANV.cpp
@@ -240,7 +240,8 @@
 
   EmittedKernels.push_back({CGF.CurFn, CGF.CurFuncDecl});
   if 

r372683 - [static analyzer][test] Test directly that driver sets D__clang_analyzer__

2019-09-23 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Mon Sep 23 19:06:59 2019
New Revision: 372683

URL: http://llvm.org/viewvc/llvm-project?rev=372683=rev
Log:
[static analyzer][test] Test directly that driver sets D__clang_analyzer__

Follow-up to fbd13570b0d

Modified:
cfe/trunk/test/Analysis/misc-driver.c

Modified: cfe/trunk/test/Analysis/misc-driver.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-driver.c?rev=372683=372682=372683=diff
==
--- cfe/trunk/test/Analysis/misc-driver.c (original)
+++ cfe/trunk/test/Analysis/misc-driver.c Mon Sep 23 19:06:59 2019
@@ -1,5 +1,2 @@
-// RUN: %clang --analyze %s
-
-#ifndef __clang_analyzer__
-#error __clang_analyzer__ not defined
-#endif
+// RUN: %clang -### --analyze %s 2>&1 | FileCheck %s
+// CHECK: -D__clang_analyzer__


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


[PATCH] D63978: Clang Interface Stubs merger plumbing for Driver

2019-09-23 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 221453.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63978

Files:
  clang/include/clang/Driver/Action.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Phases.h
  clang/include/clang/Driver/ToolChain.h
  clang/include/clang/Driver/Types.def
  clang/lib/Driver/Action.cpp
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/Phases.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/InterfaceStubs.cpp
  clang/lib/Driver/ToolChains/InterfaceStubs.h
  clang/lib/Driver/Types.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/conflict-type.ifs
  clang/test/InterfaceStubs/driver-test.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/func.ifs
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/hidden-class-inheritance.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/merge-conflict-test.cpp
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/object.ifs
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp
  clang/test/lit.cfg.py

Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -26,7 +26,7 @@
 
 # suffixes: A list of file extensions to treat as test files.
 config.suffixes = ['.c', '.cpp', '.cppm', '.m', '.mm', '.cu',
-   '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs']
+   '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs']
 
 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
 # subdirectories contain auxiliary inputs for various tests in their parent
@@ -61,7 +61,7 @@
 tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir]
 
 tools = [
-'c-index-test', 'clang-diff', 'clang-format', 'clang-tblgen', 'opt',
+'c-index-test', 'clang-diff', 'clang-format', 'clang-tblgen', 'opt', 'llvm-ifs',
 ToolSubst('%clang_extdef_map', command=FindTool(
 'clang-extdef-mapping'), unresolved='ignore'),
 ]
Index: clang/test/InterfaceStubs/weak.cpp
===
--- clang/test/InterfaceStubs/weak.cpp
+++ clang/test/InterfaceStubs/weak.cpp
@@ -1,6 +1,5 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-ifs-v1 %s | \
+// RUN: %clang -c -target x86_64-linux-gnu -o - -emit-interface-stubs %s | \
 // RUN: FileCheck %s
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- clang/test/InterfaceStubs/visibility.cpp
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -1,26 +1,20 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-ifs-v1 -fvisibility=hidden \
-// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+// RUN: -c -fvisibility=hidden %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-ifs-v1 -fvisibility=hidden \
-// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+// RUN: -c -fvisibility=hidden %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
 
-// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-ifs-v1 %s | \
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -c %s | \
 // RUN: FileCheck --check-prefix=CHECK-CMD %s
 
-// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-ifs-v1 %s | \
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -c %s | \
 // RUN: FileCheck --check-prefix=CHECK-CMD %s
 
-// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-ifs-v1 %s | \
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -c %s | \
 // RUN: FileCheck --check-prefix=CHECK-CMD2 %s
 
-// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
-// RUN: -interface-stub-version=experimental-ifs-v1 %s | \
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs -c %s | \
 // RUN: FileCheck --check-prefix=CHECK-CMD2 %s
 

[PATCH] D67122: [UBSan][clang][compiler-rt] Applying non-zero offset to nullptr is undefined behaviour

2019-09-23 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Did you run it with the linux kernel? It could be interesting

cc @nickdesaulniers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67122



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


[PATCH] D67932: [analyzer] Fix accidentally skipping the call during inlined defensive check suppression.

2019-09-23 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ marked an inline comment as done.
NoQ added a comment.

Yeah, i think we should avoid such peeking and instead try to do everything in 
one pass. I.e., if we need to peek at the node above us, just make a visitor 
that delays the decision until it has precisely the information it needs. I 
guess i'll be slooowly moving in this direction.

Also every time i see special handling of `DeclRefExpr`s i get pretty worried. 
It usually means that this code almost never works.




Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1912-1922
 /// Find the ExplodedNode where the lvalue (the value of 'Ex')
 /// was computed.
 static const ExplodedNode* findNodeForExpression(const ExplodedNode *N,
  const Expr *Inner) {
   while (N) {
 if (N->getStmtForDiagnostics() == Inner)
   return N;

Szelethus wrote:
> > When `bugreporter::trackExpressionValue()` is invoked on a `DeclRefExpr`, 
> > it tries to do most of its computations over the node in which this 
> > `DeclRefExpr` is computed, rather than on the error node (or whatever node 
> > is stuffed into it). I'm quite confused about the idea behind it and i 
> > highly doubt that it actually works correctly, but one reason why we can't 
> > simply use the error node may be that the binding to that variable might 
> > have already disappeared from the state by the time the bug is found.
> 
> So, its possible that this function, and its uses in `trackExpressionValue` 
> is completely unnecessary?
Of course it's necessary! Why would you ever write a system of mutually 
recursive visitors and then never implement an ad-hoc visitor within one of 
these visitors that allows you to quadratically visit nodes while you visit 
nodes, before actually visiting them in the real visitor? (/sarcasm)


Repository:
  rC Clang

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

https://reviews.llvm.org/D67932



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


r372681 - Support for DWARF-5 C++ language tags.

2019-09-23 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Mon Sep 23 17:38:49 2019
New Revision: 372681

URL: http://llvm.org/viewvc/llvm-project?rev=372681=rev
Log:
Support for DWARF-5 C++ language tags.

This patch provides support for DW_LANG_C_plus_plus_11,
DW_LANG_C_plus_plus_14 tags in the Clang C++ frontend.

Patch by Sourabh Singh Tomar!
Differential Revision: https://reviews.llvm.org/D67613

Reapplies r372663 after adapting a failing test in the LLDB testsuite.

Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/AST/JSONNodeDumper.cpp
cfe/trunk/lib/AST/TextNodeDumper.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaModule.cpp
cfe/trunk/test/Modules/ModuleDebugInfo.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=372681=372680=372681=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Sep 23 17:38:49 2019
@@ -42,6 +42,7 @@
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/iterator_range.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/PointerLikeTypeTraits.h"
@@ -2941,8 +2942,10 @@ public:
   /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
   /// from the dwarf standard.
   enum LanguageIDs {
-lang_c = /* DW_LANG_C */ 0x0002,
-lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
+lang_c = llvm::dwarf::DW_LANG_C,
+lang_cxx = llvm::dwarf::DW_LANG_C_plus_plus,
+lang_cxx_11 = llvm::dwarf::DW_LANG_C_plus_plus_11,
+lang_cxx_14 = llvm::dwarf::DW_LANG_C_plus_plus_14
   };
 
 private:

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=372681=372680=372681=diff
==
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Mon Sep 23 17:38:49 2019
@@ -1001,12 +1001,19 @@ void DeclPrinter::VisitCXXRecordDecl(CXX
 
 void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
   const char *l;
-  if (D->getLanguage() == LinkageSpecDecl::lang_c)
+  switch (D->getLanguage()) {
+  case LinkageSpecDecl::lang_c:
 l = "C";
-  else {
-assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
-   "unknown language in linkage specification");
+break;
+  case LinkageSpecDecl::lang_cxx_14:
+l = "C++14";
+break;
+  case LinkageSpecDecl::lang_cxx_11:
+l = "C++11";
+break;
+  case LinkageSpecDecl::lang_cxx:
 l = "C++";
+break;
   }
 
   Out << "extern \"" << l << "\" ";

Modified: cfe/trunk/lib/AST/JSONNodeDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/JSONNodeDumper.cpp?rev=372681=372680=372681=diff
==
--- cfe/trunk/lib/AST/JSONNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/JSONNodeDumper.cpp Mon Sep 23 17:38:49 2019
@@ -850,6 +850,12 @@ void JSONNodeDumper::VisitLinkageSpecDec
   switch (LSD->getLanguage()) {
   case LinkageSpecDecl::lang_c: Lang = "C"; break;
   case LinkageSpecDecl::lang_cxx: Lang = "C++"; break;
+  case LinkageSpecDecl::lang_cxx_11:
+Lang = "C++11";
+break;
+  case LinkageSpecDecl::lang_cxx_14:
+Lang = "C++14";
+break;
   }
   JOS.attribute("language", Lang);
   attributeOnlyIfTrue("hasBraces", LSD->hasBraces());

Modified: cfe/trunk/lib/AST/TextNodeDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TextNodeDumper.cpp?rev=372681=372680=372681=diff
==
--- cfe/trunk/lib/AST/TextNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/TextNodeDumper.cpp Mon Sep 23 17:38:49 2019
@@ -1766,6 +1766,12 @@ void TextNodeDumper::VisitLinkageSpecDec
   case LinkageSpecDecl::lang_cxx:
 OS << " C++";
 break;
+  case LinkageSpecDecl::lang_cxx_11:
+OS << " C++11";
+break;
+  case LinkageSpecDecl::lang_cxx_14:
+OS << " C++14";
+break;
   }
 }
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=372681=372680=372681=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Sep 23 17:38:49 2019
@@ -561,6 +561,10 @@ void CGDebugInfo::CreateCompileUnit() {
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
+else if (LO.CPlusPlus14)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
+else if (LO.CPlusPlus11)
+  LangTag 

r372680 - [static analyzer] Remove --analyze-auto

2019-09-23 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Mon Sep 23 17:37:25 2019
New Revision: 372680

URL: http://llvm.org/viewvc/llvm-project?rev=372680=rev
Log:
[static analyzer] Remove --analyze-auto

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

Modified:
cfe/trunk/docs/ClangCommandLineReference.rst
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/Types.cpp

Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=372680=372679=372680=diff
==
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Mon Sep 23 17:37:25 2019
@@ -86,8 +86,6 @@ Pass  to the target offloading tool
 
 Run the static analyzer
 
-.. option:: --analyze-auto
-
 .. option:: --analyzer-no-default-checks
 
 .. option:: --analyzer-output

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=372680=372679=372680=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Sep 23 17:37:25 2019
@@ -2762,7 +2762,6 @@ def _mhwdiv : Separate<["--"], "mhwdiv">
 def _CLASSPATH_EQ : Joined<["--"], "CLASSPATH=">, Alias;
 def _CLASSPATH : Separate<["--"], "CLASSPATH">, Alias;
 def _all_warnings : Flag<["--"], "all-warnings">, Alias;
-def _analyze_auto : Flag<["--"], "analyze-auto">, Flags<[DriverOption]>;
 def _analyzer_no_default_checks : Flag<["--"], "analyzer-no-default-checks">, 
Flags<[DriverOption]>;
 def _analyzer_output : JoinedOrSeparate<["--"], "analyzer-output">, 
Flags<[DriverOption]>,
   HelpText<"Static analyzer report output format 
(html|plist|plist-multi-file|plist-html|text).">;

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=372680=372679=372680=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Sep 23 17:37:25 2019
@@ -287,8 +287,7 @@ phases::ID Driver::getFinalPhase(const D
  (PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||
  (PhaseArg = DAL.getLastArg(options::OPT__migrate)) ||
  (PhaseArg = DAL.getLastArg(options::OPT_emit_iterface_stubs)) ||
- (PhaseArg = DAL.getLastArg(options::OPT__analyze,
-options::OPT__analyze_auto)) ||
+ (PhaseArg = DAL.getLastArg(options::OPT__analyze)) ||
  (PhaseArg = DAL.getLastArg(options::OPT_emit_ast))) {
 FinalPhase = phases::Compile;
 
@@ -3501,7 +3500,7 @@ Action *Driver::ConstructPhaseAction(
 if (Args.hasArg(options::OPT_rewrite_legacy_objc))
   return C.MakeAction(Input,
 types::TY_RewrittenLegacyObjC);
-if (Args.hasArg(options::OPT__analyze, options::OPT__analyze_auto))
+if (Args.hasArg(options::OPT__analyze))
   return C.MakeAction(Input, types::TY_Plist);
 if (Args.hasArg(options::OPT__migrate))
   return C.MakeAction(Input, types::TY_Remap);

Modified: cfe/trunk/lib/Driver/Types.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Types.cpp?rev=372680=372679=372680=diff
==
--- cfe/trunk/lib/Driver/Types.cpp (original)
+++ cfe/trunk/lib/Driver/Types.cpp Mon Sep 23 17:37:25 2019
@@ -328,7 +328,7 @@ void types::getCompilationPhases(const c
DAL.getLastArg(options::OPT_rewrite_legacy_objc) ||
DAL.getLastArg(options::OPT__migrate) ||
DAL.getLastArg(options::OPT_emit_iterface_stubs) ||
-   DAL.getLastArg(options::OPT__analyze, options::OPT__analyze_auto) ||
+   DAL.getLastArg(options::OPT__analyze) ||
DAL.getLastArg(options::OPT_emit_ast))
 llvm::copy_if(PhaseList, std::back_inserter(P),
   [](phases::ID Phase) { return Phase <= phases::Compile; });


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


r372679 - [static analyzer] Define __clang_analyzer__ macro in driver

2019-09-23 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Mon Sep 23 17:33:47 2019
New Revision: 372679

URL: http://llvm.org/viewvc/llvm-project?rev=372679=rev
Log:
[static analyzer] Define __clang_analyzer__ macro in driver

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

Added:
cfe/trunk/test/Analysis/misc-driver.c
Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/Analysis/misc-ps.m

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=372679=372678=372679=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Sep 23 17:33:47 2019
@@ -3896,8 +3896,10 @@ void Clang::ConstructJob(Compilation ,
   if (Args.hasArg(options::OPT_municode))
 CmdArgs.push_back("-DUNICODE");
 
-  if (isa(JA))
+  if (isa(JA)) {
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
+CmdArgs.push_back("-D__clang_analyzer__");
+  }
 
   // Enable compatilibily mode to avoid analyzer-config related errors.
   // Since we can't access frontend flags through hasArg, let's manually 
iterate

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=372679=372678=372679=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Sep 23 17:33:47 2019
@@ -990,10 +990,6 @@ static void InitializePredefinedMacros(c
   else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
 Builder.defineMacro("__SSP_ALL__", "3");
 
-  // Define a macro that exists only when using the static analyzer.
-  if (FEOpts.ProgramAction == frontend::RunAnalysis)
-Builder.defineMacro("__clang_analyzer__");
-
   if (LangOpts.FastRelaxedMath)
 Builder.defineMacro("__FAST_RELAXED_MATH__");
 

Added: cfe/trunk/test/Analysis/misc-driver.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-driver.c?rev=372679=auto
==
--- cfe/trunk/test/Analysis/misc-driver.c (added)
+++ cfe/trunk/test/Analysis/misc-driver.c Mon Sep 23 17:33:47 2019
@@ -0,0 +1,5 @@
+// RUN: %clang --analyze %s
+
+#ifndef __clang_analyzer__
+#error __clang_analyzer__ not defined
+#endif

Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=372679=372678=372679=diff
==
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Mon Sep 23 17:33:47 2019
@@ -2,10 +2,6 @@
 // RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 
-analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-store=region 
-verify -fblocks -Wno-unreachable-code -Wno-null-dereference 
-Wno-objc-root-class %s
 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,alpha.core,osx.cocoa.AtSync -analyzer-store=region 
-verify -fblocks -Wno-unreachable-code -Wno-null-dereference 
-Wno-objc-root-class %s
 
-#ifndef __clang_analyzer__
-#error __clang_analyzer__ not defined
-#endif
-
 typedef struct objc_ivar *Ivar;
 typedef struct objc_selector *SEL;
 typedef signed char BOOL;


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


[PATCH] D66046: Add new tautological compare warning for bitwise-or with a non-zero constant

2019-09-23 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D66046#1634055 , @sylvestre.ledru 
wrote:

> You should also probably add a note in the release notes (maybe for the 
> others changes too)
>  thanks for the work btw!


+1


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

https://reviews.llvm.org/D66046



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


[PATCH] D67613: [DWARF-5] Support for DWARF-5 C++ language tags

2019-09-23 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

I reverted this in r372672 because it caused a test failure in LLDB: 
http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/1748/


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67613



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


r372672 - Revert "Support for DWARF-5 C++ language tags."

2019-09-23 Thread Jonas Devlieghere via cfe-commits
Author: jdevlieghere
Date: Mon Sep 23 16:49:36 2019
New Revision: 372672

URL: http://llvm.org/viewvc/llvm-project?rev=372672=rev
Log:
Revert "Support for DWARF-5 C++ language tags."

This reverts commit bf9c8ffb54943c6d77398adbedddf05ef9724007.

Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/AST/JSONNodeDumper.cpp
cfe/trunk/lib/AST/TextNodeDumper.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaModule.cpp
cfe/trunk/test/Modules/ModuleDebugInfo.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=372672=372671=372672=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Sep 23 16:49:36 2019
@@ -42,7 +42,6 @@
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/iterator_range.h"
-#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/PointerLikeTypeTraits.h"
@@ -2942,10 +2941,8 @@ public:
   /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
   /// from the dwarf standard.
   enum LanguageIDs {
-lang_c = llvm::dwarf::DW_LANG_C,
-lang_cxx = llvm::dwarf::DW_LANG_C_plus_plus,
-lang_cxx_11 = llvm::dwarf::DW_LANG_C_plus_plus_11,
-lang_cxx_14 = llvm::dwarf::DW_LANG_C_plus_plus_14
+lang_c = /* DW_LANG_C */ 0x0002,
+lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
   };
 
 private:

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=372672=372671=372672=diff
==
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Mon Sep 23 16:49:36 2019
@@ -1001,19 +1001,12 @@ void DeclPrinter::VisitCXXRecordDecl(CXX
 
 void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
   const char *l;
-  switch (D->getLanguage()) {
-  case LinkageSpecDecl::lang_c:
+  if (D->getLanguage() == LinkageSpecDecl::lang_c)
 l = "C";
-break;
-  case LinkageSpecDecl::lang_cxx_14:
-l = "C++14";
-break;
-  case LinkageSpecDecl::lang_cxx_11:
-l = "C++11";
-break;
-  case LinkageSpecDecl::lang_cxx:
+  else {
+assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
+   "unknown language in linkage specification");
 l = "C++";
-break;
   }
 
   Out << "extern \"" << l << "\" ";

Modified: cfe/trunk/lib/AST/JSONNodeDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/JSONNodeDumper.cpp?rev=372672=372671=372672=diff
==
--- cfe/trunk/lib/AST/JSONNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/JSONNodeDumper.cpp Mon Sep 23 16:49:36 2019
@@ -850,12 +850,6 @@ void JSONNodeDumper::VisitLinkageSpecDec
   switch (LSD->getLanguage()) {
   case LinkageSpecDecl::lang_c: Lang = "C"; break;
   case LinkageSpecDecl::lang_cxx: Lang = "C++"; break;
-  case LinkageSpecDecl::lang_cxx_11:
-Lang = "C++11";
-break;
-  case LinkageSpecDecl::lang_cxx_14:
-Lang = "C++14";
-break;
   }
   JOS.attribute("language", Lang);
   attributeOnlyIfTrue("hasBraces", LSD->hasBraces());

Modified: cfe/trunk/lib/AST/TextNodeDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TextNodeDumper.cpp?rev=372672=372671=372672=diff
==
--- cfe/trunk/lib/AST/TextNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/TextNodeDumper.cpp Mon Sep 23 16:49:36 2019
@@ -1766,12 +1766,6 @@ void TextNodeDumper::VisitLinkageSpecDec
   case LinkageSpecDecl::lang_cxx:
 OS << " C++";
 break;
-  case LinkageSpecDecl::lang_cxx_11:
-OS << " C++11";
-break;
-  case LinkageSpecDecl::lang_cxx_14:
-OS << " C++14";
-break;
   }
 }
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=372672=372671=372672=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Sep 23 16:49:36 2019
@@ -561,10 +561,6 @@ void CGDebugInfo::CreateCompileUnit() {
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
-else if (LO.CPlusPlus14)
-  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11)
-  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
 else
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
   } else if (LO.ObjC) {
@@ -882,8 +878,6 @@ llvm::DIType *CGDebugInfo::CreateType(co
 

[PATCH] D67865: [clang-tidy] Finds uses of OSRead* calls on macOS that may mask unexpected behavior due to unaligned reads

2019-09-23 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach updated this revision to Diff 221433.
dmaclach added a comment.

Updated based on review


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

https://reviews.llvm.org/D67865

Files:
  clang-tidy/objc/AvoidOSReadCheck.cpp
  clang-tidy/objc/AvoidOSReadCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-osread.rst
  test/clang-tidy/objc-avoid-osread.m

Index: test/clang-tidy/objc-avoid-osread.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-osread.m
@@ -0,0 +1,35 @@
+// RUN: %check_clang_tidy %s objc-avoid-osread %t
+
+void f() {
+  const char *buff = "";
+  OSReadBigInt(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadBigInt(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadLittleInt(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadBigInt16(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadBigInt32(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadBigInt64(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadLittleInt16(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadLittleInt32(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadLittleInt64(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadSwapInt16(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadSwapInt32(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadSwapInt64(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  _OSReadInt16(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  _OSReadInt32(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  _OSReadInt64(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+}
Index: docs/clang-tidy/checks/objc-avoid-osread.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-osread.rst
@@ -0,0 +1,40 @@
+.. title:: clang-tidy - objc-avoid-osread
+
+objc-avoid-osread
+=
+
+Finds usages of ``OSRead{Big|Little}Int{16|32|64}`` and associated functions which
+should be avoided due to potential unaligned read problems.
+
+This check will detect following function invocations:
+
+- ``OSReadBigInt``
+- ``OSReadLittleInt``
+- ``OSReadBigInt16``
+- ``OSReadBigInt32``
+- ``OSReadBigInt64``
+- ``OSReadLittleInt16``
+- ``OSReadLittleInt32``
+- ``OSReadLittleInt64``
+- ``OSReadSwapInt16``
+- ``OSReadSwapInt3``
+- ``OSReadSwapInt64``
+- ``_OSReadInt16``
+- ``_OSReadInt32``
+- ``_OSReadInt64``
+
+The ``OSRead{Big|Little}Int{16|32|64}`` functions from ``libkern/OSByteOrder.h`` have
+undocumented dependencies on aligned reads due to type punning by casting through a 
+pointer:
+
+.. code:: c
+
+   

[PATCH] D67940: [BPF] Preserve and make bitfield access relocatable

2019-09-23 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song created this revision.
yonghong-song added reviewers: ast, eli.friedman.
Herald added subscribers: llvm-commits, cfe-commits, jdoerfert, hiraditya.
Herald added projects: clang, LLVM.

Previous work for BPF CO-RE (compile once, run everywhere)
tries to record structure, union and array accesses
in order to make addresses relocatable. Bitfield is
not handled as you cannot really take an address of
a bitfield.

Internally, for any bitfield access, llvm will generate
a GEP to the first bitfield for a contiguous run of
bitfields, and then perform proper load and bit 
manipulation from that address.

In this patch, a clang intrinsic is introduced:

  void * __builtin_preserve_bitfield_info(expr, unsigned *buf)

Given a bitfield access, the builtin will return the 
address of the first bitfield for the contiguous run 
of bitfields. The "buf" will have

  . the signness of the bitfield
  . the size of bitfield
  . the offset within the contiguous run of bitfields

These information will be sufficient for bpf program
to retrieve or assign the bitfield values.

The BPF backend will generate an offset relocation
for the leading bitfield and also record all bitfield
accesses happening in this group. So if structure changed
outside the bitfield group, relocation will handle it. 
If the structure changes inside the bitfield group,
the bpf loader may reject the program if it deems previous
bitfield extraction might get the wrong result.

For the case of bitfield access without
__builtin_preserve_bitfield_info() to get an address,
__builtin_preserve_access_index() can be used to enclose
the code. The same offset relocation will be generated.

Please see added tests on how to use the new intrinsic and 
what the new offset relocation looks like.

TODO: due to IR intrinsic __builtin_preserve_struct_access_index()
signature change, most existing CORE tests failed. Will fix it later.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67940

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-preserve-bitfield-info-2.c
  clang/test/CodeGen/builtin-preserve-bitfield-info.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
  llvm/lib/Target/BPF/BPFCORE.h
  llvm/lib/Target/BPF/BTF.h
  llvm/lib/Target/BPF/BTFDebug.cpp
  llvm/lib/Target/BPF/BTFDebug.h
  llvm/test/CodeGen/BPF/CORE/intrinsic-bitfield.ll
  llvm/test/CodeGen/BPF/CORE/intrinsic-struct.ll
  llvm/test/CodeGen/BPF/CORE/offset-reloc-bitfield.ll

Index: llvm/test/CodeGen/BPF/CORE/offset-reloc-bitfield.ll
===
--- /dev/null
+++ llvm/test/CodeGen/BPF/CORE/offset-reloc-bitfield.ll
@@ -0,0 +1,112 @@
+; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+; Source code:
+;   struct s {
+; int a;
+; int b1:8;
+; int b2:3;
+; int b3:4;
+;   };
+;
+;   #define _(x, y) __builtin_preserve_bitfield_info((x), (y))
+;   void process(void *);
+;   unsigned test(struct s *arg) {
+; unsigned info1, info2;
+; void *p1, *p2;
+;
+; p1 = _(arg->b2, );
+; p2 = _(arg->b3, );
+; process(p1);
+; process(p2);
+; // the last 16 bit is the offset, so
+; // return value should be 8 + 11 = 19
+; // At -O2, compiler should do this optimization.
+; return (info1 & 0x) + (info2 & 0x);
+;   }
+
+%struct.s = type { i32, i16 }
+
+; Function Attrs: nounwind
+define dso_local i32 @test(%struct.s* %arg) local_unnamed_addr #0 !dbg !7 {
+entry:
+  call void @llvm.dbg.value(metadata %struct.s* %arg, metadata !20, metadata !DIExpression()), !dbg !26
+  %0 = tail call i16* @llvm.preserve.struct.access.index.p0i16.p0s_struct.ss(%struct.s* %arg, i32 1, i32 2, i32 1), !dbg !27, !llvm.preserve.access.index !12
+  %1 = bitcast i16* %0 to i8*, !dbg !27
+  call void @llvm.dbg.value(metadata i32 -2147287032, metadata !21, metadata !DIExpression()), !dbg !26
+  call void @llvm.dbg.value(metadata i8* %1, metadata !23, metadata !DIExpression()), !dbg !26
+  %2 = tail call i16* @llvm.preserve.struct.access.index.p0i16.p0s_struct.ss(%struct.s* %arg, i32 1, i32 3, i32 1), !dbg !28, !llvm.preserve.access.index !12
+  %3 = bitcast i16* %2 to i8*, !dbg !28
+  call void @llvm.dbg.value(metadata i32 -2147221493, metadata !22, metadata !DIExpression()), !dbg !26
+  call void @llvm.dbg.value(metadata i8* %3, metadata !25, metadata !DIExpression()), !dbg !26
+  tail call void @process(i8* %1) #4, !dbg !29
+  tail call void @process(i8* %3) #4, !dbg !30
+  ret i32 19, !dbg !31
+}
+
+; CHECK-LABEL:   test

[PATCH] D63932: [GlobalDCE] Dead Virtual Function Elimination

2019-09-23 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
ostannard added a comment.

> This makes the IR self-contained, which is good, but it also make the 
> interpretation of the IR modal, which isn't great. It means that suddenly the 
> rules of interpretation of what is valid to do or not changes according to 
> this module flag.

I think the original version was better from that perspective - most compiler 
passes only need to check for one value of the attribute, and only the linker 
needed to care about the difference between link-unit and public visibility. Do 
you think we should go back to that design, or do you have a different idea?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63932



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


[PATCH] D67865: [clang-tidy] Finds uses of OSRead* calls on macOS that may mask unexpected behavior due to unaligned reads

2019-09-23 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/clang-tidy/checks/objc-avoid-osread.rst:26
+
+The OSRead* functions from libkern/OSByteOrder.h have undocumented 
dependencies on aligned reads due to type punning by casting through a pointer:
+

Please highlight OSRead* and libkern/OSByteOrder.h with double back-ticks. 
Please also make lines no more then 80 characters long.


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

https://reviews.llvm.org/D67865



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


[PATCH] D67932: [analyzer] Fix accidentally skipping the call during inlined defensive check suppression.

2019-09-23 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Hmm, so before this patch, we just used `LVNode` everywhere and ignored 
`InputNode`. It may not have made much sense, but its still not as confusing as 
using both if the creation of `LVNode` is unnecessary overall. Could we just 
remove it?




Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1912-1922
 /// Find the ExplodedNode where the lvalue (the value of 'Ex')
 /// was computed.
 static const ExplodedNode* findNodeForExpression(const ExplodedNode *N,
  const Expr *Inner) {
   while (N) {
 if (N->getStmtForDiagnostics() == Inner)
   return N;

> When `bugreporter::trackExpressionValue()` is invoked on a `DeclRefExpr`, it 
> tries to do most of its computations over the node in which this 
> `DeclRefExpr` is computed, rather than on the error node (or whatever node is 
> stuffed into it). I'm quite confused about the idea behind it and i highly 
> doubt that it actually works correctly, but one reason why we can't simply 
> use the error node may be that the binding to that variable might have 
> already disappeared from the state by the time the bug is found.

So, its possible that this function, and its uses in `trackExpressionValue` is 
completely unnecessary?



Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:2007-2009
+  // Note that LVNode may be too late; the lvalue may have been 
computed
+  // before the inlined call was evaluated. InputNode may as well be
+  // too late, because the symbol is already dead; this, however,

Too late in terms of too close to the root of the `ExplodedGraph`, or the other 
way around? This is a bitconfusing since visitors are inspecting the graph in 
reverse.


Repository:
  rC Clang

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

https://reviews.llvm.org/D67932



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


r372668 - [NFCI] Return PathSensitiveBugReport where appropriate

2019-09-23 Thread Alex Langford via cfe-commits
Author: xiaobai
Date: Mon Sep 23 15:24:47 2019
New Revision: 372668

URL: http://llvm.org/viewvc/llvm-project?rev=372668=rev
Log:
[NFCI] Return PathSensitiveBugReport where appropriate

Some compilers have trouble converting unique_ptr to
unique_ptr causing some functions to fail to compile.
Changing the return type of the functions that fail to compile does not
appear to have any issues.
I ran into this issue building with clang 3.8 on Ubuntu 16.04.

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp?rev=372668=372667=372668=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp Mon Sep 
23 15:24:47 2019
@@ -113,8 +113,10 @@ private:
   const ExplodedNode *getAllocationNode(const ExplodedNode *N, SymbolRef Sym,
 CheckerContext ) const;
 
-  std::unique_ptr generateAllocatedDataNotReleasedReport(
-  const AllocationPair , ExplodedNode *N, CheckerContext ) const;
+  std::unique_ptr
+  generateAllocatedDataNotReleasedReport(const AllocationPair ,
+ ExplodedNode *N,
+ CheckerContext ) const;
 
   /// Mark an AllocationPair interesting for diagnostic reporting.
   void markInteresting(PathSensitiveBugReport *R,
@@ -467,7 +469,7 @@ MacOSKeychainAPIChecker::getAllocationNo
   return AllocNode;
 }
 
-std::unique_ptr
+std::unique_ptr
 MacOSKeychainAPIChecker::generateAllocatedDataNotReleasedReport(
 const AllocationPair , ExplodedNode *N, CheckerContext ) const {
   const ADFunctionInfo  = FunctionsToTrack[AP.second->AllocatorIdx];

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp?rev=372668=372667=372668=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp Mon Sep 23 
15:24:47 2019
@@ -35,11 +35,11 @@ public:
 
   void checkPreCall(const CallEvent , CheckerContext ) const;
 
-  std::unique_ptr
+  std::unique_ptr
   genReportNullAttrNonNull(const ExplodedNode *ErrorN,
const Expr *ArgE,
unsigned IdxOfArg) const;
-  std::unique_ptr
+  std::unique_ptr
   genReportReferenceToNullPointer(const ExplodedNode *ErrorN,
   const Expr *ArgE) const;
 };
@@ -179,7 +179,7 @@ void NonNullParamChecker::checkPreCall(c
   C.addTransition(state);
 }
 
-std::unique_ptr
+std::unique_ptr
 NonNullParamChecker::genReportNullAttrNonNull(const ExplodedNode *ErrorNode,
   const Expr *ArgE,
   unsigned IdxOfArg) const {
@@ -204,7 +204,8 @@ NonNullParamChecker::genReportNullAttrNo
   return R;
 }
 
-std::unique_ptr 
NonNullParamChecker::genReportReferenceToNullPointer(
+std::unique_ptr
+NonNullParamChecker::genReportReferenceToNullPointer(
 const ExplodedNode *ErrorNode, const Expr *ArgE) const {
   if (!BTNullRefArg)
 BTNullRefArg.reset(new BuiltinBug(this, "Dereference of null pointer"));


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


[PATCH] D67613: [DWARF-5] Support for DWARF-5 C++ language tags

2019-09-23 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

/srv/llvm-buildbot-srcatch/llvm-build-dir/clang-x86_64-debian-fast/llvm.src/tools/clang/tools/extra/modularize/Modularize.cpp:583:13:
 warning: enumeration values 'lang_cxx_11' and 'lang_cxx_14' not handled in 
switch [-Wswitch]
1 warning generated.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67613



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


[PATCH] D67865: [clang-tidy] Finds uses of OSRead* calls on macOS that may mask unexpected behavior due to unaligned reads

2019-09-23 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach marked 5 inline comments as done.
dmaclach added inline comments.



Comment at: clang-tidy/objc/AvoidOSReadCheck.cpp:21
+void AvoidOSReadCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee((functionDecl(hasAnyName(

Eugene.Zelenko wrote:
> Please add check if language is Objective-C.
So this isn't specific to Objective C, and applies to all C based languages. 
This is more Darwin specific. I based this CL on the AvoidSpinlockCheck which 
is very similar in this respect. If we want to do clean up on this later we 
should probably do them together.



Comment at: docs/clang-tidy/checks/objc-avoid-osread.rst:6
+
+Finds usages of ``OSRead{Big|Little}Int{16|32|64}`` and associated functions 
which
+should be avoided due to potential unaligned read problems.

Eugene.Zelenko wrote:
> Please synchronize with sentence in Release Notes.
Done. I coped this version into the release notes.


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

https://reviews.llvm.org/D67865



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


[PATCH] D67865: [clang-tidy] Finds uses of OSRead* calls on macOS that may mask unexpected behavior due to unaligned reads

2019-09-23 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach updated this revision to Diff 221420.
dmaclach added a comment.

Fixed up review comments.


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

https://reviews.llvm.org/D67865

Files:
  clang-tidy/objc/AvoidOSReadCheck.cpp
  clang-tidy/objc/AvoidOSReadCheck.h
  clang-tidy/objc/CMakeLists.txt
  clang-tidy/objc/ObjCTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/objc-avoid-osread.rst
  test/clang-tidy/objc-avoid-osread.m

Index: test/clang-tidy/objc-avoid-osread.m
===
--- /dev/null
+++ test/clang-tidy/objc-avoid-osread.m
@@ -0,0 +1,35 @@
+// RUN: %check_clang_tidy %s objc-avoid-osread %t
+
+void f() {
+  const char *buff = "";
+  OSReadBigInt(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadBigInt(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadLittleInt(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadBigInt16(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadBigInt32(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadBigInt64(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadLittleInt16(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadLittleInt32(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadLittleInt64(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadSwapInt16(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadSwapInt32(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  OSReadSwapInt64(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  _OSReadInt16(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  _OSReadInt32(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+  _OSReadInt64(buff, 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use memcpy and OSSwap{Big|Little}ToHostInt{16|32|64} instead of OSRead* calls to avoid potential unaligned read issues [objc-avoid-osread]
+}
Index: docs/clang-tidy/checks/objc-avoid-osread.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/objc-avoid-osread.rst
@@ -0,0 +1,37 @@
+.. title:: clang-tidy - objc-avoid-osread
+
+objc-avoid-osread
+=
+
+Finds usages of ``OSRead{Big|Little}Int{16|32|64}`` and associated functions which
+should be avoided due to potential unaligned read problems.
+
+This check will detect following function invocations:
+
+- ``OSReadBigInt``
+- ``OSReadLittleInt``
+- ``OSReadBigInt16``
+- ``OSReadBigInt32``
+- ``OSReadBigInt64``
+- ``OSReadLittleInt16``
+- ``OSReadLittleInt32``
+- ``OSReadLittleInt64``
+- ``OSReadSwapInt16``
+- ``OSReadSwapInt3``
+- ``OSReadSwapInt64``
+- ``_OSReadInt16``
+- ``_OSReadInt32``
+- ``_OSReadInt64``
+
+The OSRead* functions from libkern/OSByteOrder.h have undocumented dependencies on aligned reads due to type punning by casting through a pointer:
+
+.. code:: c
+
+   OS_INLINE uint64_t _OSReadInt64(const 

r372664 - [Diagnostics] Warn for enum constants in bool context (-Wint-in-bool-context; GCC compatibility)

2019-09-23 Thread David Bolvansky via cfe-commits
Author: xbolva00
Date: Mon Sep 23 15:09:49 2019
New Revision: 372664

URL: http://llvm.org/viewvc/llvm-project?rev=372664=rev
Log:
[Diagnostics] Warn for enum constants in bool context (-Wint-in-bool-context; 
GCC compatibility)

Extracted from D63082.


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/warn-int-in-bool-context.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=372664=372663=372664=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Sep 23 15:09:49 
2019
@@ -5720,6 +5720,9 @@ def warn_precedence_conditional : Warnin
 def note_precedence_conditional_first : Note<
   "place parentheses around the '?:' expression to evaluate it first">;
 
+def warn_enum_constant_in_bool_context : Warning<
+  "converting the enum constant to a boolean">,
+  InGroup;
 def warn_left_shift_in_bool_context : Warning<
   "converting the result of '<<' to a boolean; did you mean '(%0) != 0'?">,
   InGroup;
@@ -6156,6 +6159,10 @@ def warn_comparison_of_mixed_enum_types
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,
   InGroup;
+def warn_conditional_mixed_enum_types : Warning<
+  "enumeration type mismatch in conditional expression"
+  "%diff{ ($ and $)|}0,1">,
+  InGroup;
 def warn_comparison_of_mixed_enum_types_switch : Warning<
   "comparison of two values with different enumeration types in switch 
statement"
   "%diff{ ($ and $)|}0,1">,

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=372664=372663=372664=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 23 15:09:49 2019
@@ -11297,10 +11297,22 @@ inline QualType Sema::CheckLogicalOperan
   if (LHS.get()->getType()->isVectorType() || 
RHS.get()->getType()->isVectorType())
 return CheckVectorLogicalOperands(LHS, RHS, Loc);
 
+  bool EnumConstantInBoolContext = false;
+  for (const ExprResult  : {LHS, RHS}) {
+if (const auto *DREHS = dyn_cast(HS.get())) {
+  const auto *ECDHS = dyn_cast(DREHS->getDecl());
+  if (ECDHS && ECDHS->getInitVal() != 0 && ECDHS->getInitVal() != 1)
+EnumConstantInBoolContext = true;
+}
+  }
+
+  if (EnumConstantInBoolContext)
+Diag(Loc, diag::warn_enum_constant_in_bool_context);
+
   // Diagnose cases where the user write a logical and/or but probably meant a
   // bitwise one.  We do this when the LHS is a non-bool integer and the RHS
   // is a constant.
-  if (LHS.get()->getType()->isIntegerType() &&
+  if (!EnumConstantInBoolContext && LHS.get()->getType()->isIntegerType() &&
   !LHS.get()->getType()->isBooleanType() &&
   RHS.get()->getType()->isIntegerType() && !RHS.get()->isValueDependent() 
&&
   // Don't warn in macros or template instantiations.

Modified: cfe/trunk/test/Sema/warn-int-in-bool-context.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-int-in-bool-context.c?rev=372664=372663=372664=diff
==
--- cfe/trunk/test/Sema/warn-int-in-bool-context.c (original)
+++ cfe/trunk/test/Sema/warn-int-in-bool-context.c Mon Sep 23 15:09:49 2019
@@ -14,7 +14,13 @@ typedef bool boolean;
 typedef _Bool boolean;
 #endif
 
-int test(int a) {
+enum num {
+  zero,
+  one,
+  two,
+};
+
+int test(int a, enum num n) {
   boolean r;
   r = (1 << 3); // expected-warning {{converting the result of '<<' to a 
boolean; did you mean '(1 << 3) != 0'?}}
   r = TWO << 7; // expected-warning {{converting the result of '<<' to a 
boolean; did you mean '(2 << 7) != 0'?}}
@@ -26,6 +32,26 @@ int test(int a) {
   if (a << TWO) // expected-warning {{converting the result of '<<' to a 
boolean; did you mean '(a << 2) != 0'?}}
 return a;
 
+  if (n || two)
+// expected-warning@-1 {{converting the enum constant to a boolean}}
+return a;
+
+  if (n == one || two)
+// expected-warning@-1 {{converting the enum constant to a boolean}}
+return a;
+
+  if (r && two)
+// expected-warning@-1 {{converting the enum constant to a boolean}}
+return a;
+
+  if (two && r)
+// expected-warning@-1 {{converting the enum constant to a boolean}}
+return a;
+
+  if (n == one && two)
+// expected-warning@-1 {{converting the enum constant to a boolean}}
+return a;
+
   // Don't warn in macros.
   return SHIFT(1, a);
 }


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


[PATCH] D67613: [DWARF-5] Support for DWARF-5 C++ language tags

2019-09-23 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372663: Support for DWARF-5 C++ language tags. (authored by 
adrian, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67613?vs=220613=221418#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D67613

Files:
  cfe/trunk/include/clang/AST/DeclCXX.h
  cfe/trunk/lib/AST/DeclPrinter.cpp
  cfe/trunk/lib/AST/JSONNodeDumper.cpp
  cfe/trunk/lib/AST/TextNodeDumper.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/lib/Sema/SemaModule.cpp
  cfe/trunk/test/Modules/ModuleDebugInfo.cpp

Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -561,6 +561,10 @@
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
+else if (LO.CPlusPlus14)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
+else if (LO.CPlusPlus11)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
 else
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
   } else if (LO.ObjC) {
@@ -878,6 +882,8 @@
 static bool hasCXXMangling(const TagDecl *TD, llvm::DICompileUnit *TheCU) {
   switch (TheCU->getSourceLanguage()) {
   case llvm::dwarf::DW_LANG_C_plus_plus:
+  case llvm::dwarf::DW_LANG_C_plus_plus_11:
+  case llvm::dwarf::DW_LANG_C_plus_plus_14:
 return true;
   case llvm::dwarf::DW_LANG_ObjC_plus_plus:
 return isa(TD) || isa(TD);
Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -5132,7 +5132,9 @@
 // EmitLinkageSpec - Emit all declarations in a linkage spec.
 void CodeGenModule::EmitLinkageSpec(const LinkageSpecDecl *LSD) {
   if (LSD->getLanguage() != LinkageSpecDecl::lang_c &&
-  LSD->getLanguage() != LinkageSpecDecl::lang_cxx) {
+  LSD->getLanguage() != LinkageSpecDecl::lang_cxx &&
+  LSD->getLanguage() != LinkageSpecDecl::lang_cxx_11 &&
+  LSD->getLanguage() != LinkageSpecDecl::lang_cxx_14) {
 ErrorUnsupported(LSD, "linkage spec");
 return;
   }
Index: cfe/trunk/lib/AST/TextNodeDumper.cpp
===
--- cfe/trunk/lib/AST/TextNodeDumper.cpp
+++ cfe/trunk/lib/AST/TextNodeDumper.cpp
@@ -1766,6 +1766,12 @@
   case LinkageSpecDecl::lang_cxx:
 OS << " C++";
 break;
+  case LinkageSpecDecl::lang_cxx_11:
+OS << " C++11";
+break;
+  case LinkageSpecDecl::lang_cxx_14:
+OS << " C++14";
+break;
   }
 }
 
Index: cfe/trunk/lib/AST/JSONNodeDumper.cpp
===
--- cfe/trunk/lib/AST/JSONNodeDumper.cpp
+++ cfe/trunk/lib/AST/JSONNodeDumper.cpp
@@ -850,6 +850,12 @@
   switch (LSD->getLanguage()) {
   case LinkageSpecDecl::lang_c: Lang = "C"; break;
   case LinkageSpecDecl::lang_cxx: Lang = "C++"; break;
+  case LinkageSpecDecl::lang_cxx_11:
+Lang = "C++11";
+break;
+  case LinkageSpecDecl::lang_cxx_14:
+Lang = "C++14";
+break;
   }
   JOS.attribute("language", Lang);
   attributeOnlyIfTrue("hasBraces", LSD->hasBraces());
Index: cfe/trunk/lib/AST/DeclPrinter.cpp
===
--- cfe/trunk/lib/AST/DeclPrinter.cpp
+++ cfe/trunk/lib/AST/DeclPrinter.cpp
@@ -1001,12 +1001,19 @@
 
 void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
   const char *l;
-  if (D->getLanguage() == LinkageSpecDecl::lang_c)
+  switch (D->getLanguage()) {
+  case LinkageSpecDecl::lang_c:
 l = "C";
-  else {
-assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
-   "unknown language in linkage specification");
+break;
+  case LinkageSpecDecl::lang_cxx_14:
+l = "C++14";
+break;
+  case LinkageSpecDecl::lang_cxx_11:
+l = "C++11";
+break;
+  case LinkageSpecDecl::lang_cxx:
 l = "C++";
+break;
   }
 
   Out << "extern \"" << l << "\" ";
Index: cfe/trunk/lib/Sema/SemaModule.cpp
===
--- cfe/trunk/lib/Sema/SemaModule.cpp
+++ cfe/trunk/lib/Sema/SemaModule.cpp
@@ -31,6 +31,8 @@
 ExternCLoc = LSD->getBeginLoc();
   break;
 case LinkageSpecDecl::lang_cxx:
+case LinkageSpecDecl::lang_cxx_11:
+case LinkageSpecDecl::lang_cxx_14:
   break;
 }
 DC = LSD->getParent();
Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -13982,6 +13982,10 @@
 Language = LinkageSpecDecl::lang_c;
   else if (Lang == "C++")
 

r372663 - Support for DWARF-5 C++ language tags.

2019-09-23 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Mon Sep 23 15:01:49 2019
New Revision: 372663

URL: http://llvm.org/viewvc/llvm-project?rev=372663=rev
Log:
Support for DWARF-5 C++ language tags.

This patch provides support for DW_LANG_C_plus_plus_11,
DW_LANG_C_plus_plus_14 tags in the Clang C++ frontend.

Patch by Sourabh Singh Tomar!
Differential Revision: https://reviews.llvm.org/D67613

Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/AST/JSONNodeDumper.cpp
cfe/trunk/lib/AST/TextNodeDumper.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaModule.cpp
cfe/trunk/test/Modules/ModuleDebugInfo.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=372663=372662=372663=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Sep 23 15:01:49 2019
@@ -42,6 +42,7 @@
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/iterator_range.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/PointerLikeTypeTraits.h"
@@ -2941,8 +2942,10 @@ public:
   /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
   /// from the dwarf standard.
   enum LanguageIDs {
-lang_c = /* DW_LANG_C */ 0x0002,
-lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
+lang_c = llvm::dwarf::DW_LANG_C,
+lang_cxx = llvm::dwarf::DW_LANG_C_plus_plus,
+lang_cxx_11 = llvm::dwarf::DW_LANG_C_plus_plus_11,
+lang_cxx_14 = llvm::dwarf::DW_LANG_C_plus_plus_14
   };
 
 private:

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=372663=372662=372663=diff
==
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Mon Sep 23 15:01:49 2019
@@ -1001,12 +1001,19 @@ void DeclPrinter::VisitCXXRecordDecl(CXX
 
 void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
   const char *l;
-  if (D->getLanguage() == LinkageSpecDecl::lang_c)
+  switch (D->getLanguage()) {
+  case LinkageSpecDecl::lang_c:
 l = "C";
-  else {
-assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
-   "unknown language in linkage specification");
+break;
+  case LinkageSpecDecl::lang_cxx_14:
+l = "C++14";
+break;
+  case LinkageSpecDecl::lang_cxx_11:
+l = "C++11";
+break;
+  case LinkageSpecDecl::lang_cxx:
 l = "C++";
+break;
   }
 
   Out << "extern \"" << l << "\" ";

Modified: cfe/trunk/lib/AST/JSONNodeDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/JSONNodeDumper.cpp?rev=372663=372662=372663=diff
==
--- cfe/trunk/lib/AST/JSONNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/JSONNodeDumper.cpp Mon Sep 23 15:01:49 2019
@@ -850,6 +850,12 @@ void JSONNodeDumper::VisitLinkageSpecDec
   switch (LSD->getLanguage()) {
   case LinkageSpecDecl::lang_c: Lang = "C"; break;
   case LinkageSpecDecl::lang_cxx: Lang = "C++"; break;
+  case LinkageSpecDecl::lang_cxx_11:
+Lang = "C++11";
+break;
+  case LinkageSpecDecl::lang_cxx_14:
+Lang = "C++14";
+break;
   }
   JOS.attribute("language", Lang);
   attributeOnlyIfTrue("hasBraces", LSD->hasBraces());

Modified: cfe/trunk/lib/AST/TextNodeDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TextNodeDumper.cpp?rev=372663=372662=372663=diff
==
--- cfe/trunk/lib/AST/TextNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/TextNodeDumper.cpp Mon Sep 23 15:01:49 2019
@@ -1766,6 +1766,12 @@ void TextNodeDumper::VisitLinkageSpecDec
   case LinkageSpecDecl::lang_cxx:
 OS << " C++";
 break;
+  case LinkageSpecDecl::lang_cxx_11:
+OS << " C++11";
+break;
+  case LinkageSpecDecl::lang_cxx_14:
+OS << " C++14";
+break;
   }
 }
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=372663=372662=372663=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Sep 23 15:01:49 2019
@@ -561,6 +561,10 @@ void CGDebugInfo::CreateCompileUnit() {
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
+else if (LO.CPlusPlus14)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
+else if (LO.CPlusPlus11)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
 else
   LangTag = 

[PATCH] D67935: Add `#pragma clang deprecated`, used to deprecate macros

2019-09-23 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.
erik.pilkington added reviewers: rsmith, aaron.ballman.
Herald added subscribers: ributzka, dexonsmith, jkorous.
Herald added a project: clang.

This patch adds support for `#pragma clang deprecated`, which emits a 
deprecated warning whenever it is encountered. This is intended to be used to 
deprecate macros, but it seems like it could be useful for deprecating include 
files as well (rather than `#warning`). This is similar to `#pragma GCC 
warning`, but that can't emit a diagnostic under `-Wdeprecated`, so these 
warnings wouldn't be controlled by traditional deprecation disabling methods. 
(`-Wno-deprecated`, `#pragma clang diagnostic ignored`).

rdar://problem/50356322 clang should provide a pragma to allow us to deprecate 
macros


Repository:
  rC Clang

https://reviews.llvm.org/D67935

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/Pragma.cpp
  clang/test/Lexer/pragma-deprecated.c

Index: clang/test/Lexer/pragma-deprecated.c
===
--- /dev/null
+++ clang/test/Lexer/pragma-deprecated.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -verify -Wdeprecated-pragma %s
+
+#define STR(x) #x
+#define DEPRECATED_MACRO(entity, message) \
+  _Pragma(STR(clang deprecated(entity, message)))
+
+#define FOO DEPRECATED_MACRO("foo", "use bar") 43
+
+__attribute__((deprecated))
+int f();
+
+int main() {
+  return FOO; // expected-warning{{'foo' is deprecated: use bar}}
+}
+
+// expected-warning@+1{{'"flerp.h"' is deprecated: use "flarp.h" instead}}
+#pragma clang deprecated("\"flerp.h\"", "use \"flarp.h\" instead")
+
+// expected-warning@+1{{'flerp' is deprecated}}
+#pragma clang deprecated("flerp")
+
+// expected-error@+1 {{expected '('}}
+#pragma clang deprecated
+// expected-error@+1 {{expected string literal in #pragma clang deprecated}}
+#pragma clang deprecated(43)
+// expected-error@+1 {{expected string literal in #pragma clang deprecated}}
+#pragma clang deprecated ("foo", 33)
+// expected-error@+1 {{expected ')'}}
+#pragma clang deprecated ("foo", "bar"
+// expected-warning@+2 {{extra tokens at end of #pragma directive}}
+// expected-warning@+1 {{'foo' is deprecated: bar}}
+#pragma clang deprecated ("foo", "bar") baz
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1517,6 +1517,59 @@
   }
 };
 
+/// Handle '#pragma clang deprecated'. The syntax is:
+///
+/// \code
+///   #pragma clang deprecated("entity", "message")
+/// \endcode
+///
+/// The message is optional. This is used to deprecate macros (via _Pragma), or
+/// files.
+struct PragmaDeprecatedHandler : public PragmaHandler {
+  PragmaDeprecatedHandler() : PragmaHandler("deprecated") {}
+
+  void HandlePragma(Preprocessor , PragmaIntroducer Introducer,
+Token ) override {
+SourceLocation Loc = NameTok.getLocation();
+std::string EntityString, MessageString;
+Token Tok;
+
+PP.Lex(Tok);
+if (Tok.isNot(tok::l_paren)) {
+  PP.Diag(Loc, diag::err_expected) << tok::l_paren;
+  return;
+}
+
+PP.Lex(Tok);
+if (!PP.FinishLexStringLiteral(Tok, EntityString,
+   "#pragma clang deprecated",
+   /*AllowMacroExpansion=*/true))
+  return;
+
+if (Tok.is(tok::comma)) {
+  PP.Lex(Tok);
+  if (!PP.FinishLexStringLiteral(Tok, MessageString,
+ "#pragma clang deprecated",
+ /*AllowMacroExpansion=*/true))
+return;
+}
+
+if (Tok.isNot(tok::r_paren)) {
+  PP.Diag(Loc, diag::err_expected) << tok::r_paren;
+  return;
+}
+
+PP.Lex(Tok);
+if (Tok.isNot(tok::eod))
+  PP.Diag(Loc, diag::ext_pp_extra_tokens_at_eol) << "pragma";
+
+unsigned DiagID = MessageString.empty() ? diag::warn_pragma_deprecated
+: diag::warn_pragma_deprecated_msg;
+DiagnosticBuilder Builder = PP.Diag(Loc, DiagID)
+<< EntityString << MessageString;
+  }
+};
+
 /// Handle the clang \#pragma module import extension. The syntax is:
 /// \code
 ///   #pragma clang module import some.module.name
@@ -1858,6 +1911,7 @@
   AddPragmaHandler("clang", new PragmaDiagnosticHandler("clang"));
   AddPragmaHandler("clang", new PragmaARCCFCodeAuditedHandler());
   AddPragmaHandler("clang", new PragmaAssumeNonNullHandler());
+  AddPragmaHandler("clang", new PragmaDeprecatedHandler);
 
   // #pragma clang module ...
   auto *ModuleHandler = new PragmaNamespace("module");
Index: clang/include/clang/Basic/DiagnosticLexKinds.td
===
--- clang/include/clang/Basic/DiagnosticLexKinds.td
+++ 

[PATCH] D67932: [analyzer] Fix accidentally skipping the call during inlined defensive check suppression.

2019-09-23 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a_sidorin, rnkovacs, Szelethus, 
baloghadamsoftware, Charusso.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, szepet.
Herald added a project: clang.

Got myself distracted with a tiny fix for the inlined defensive check 
suppression.

When `bugreporter::trackExpressionValue()` is invoked on a `DeclRefExpr`, it 
tries to do most of its computations over the node in which this `DeclRefExpr` 
is computed, rather than on the error node (or whatever node is stuffed into 
it). I'm quite confused about the idea behind it and i highly doubt that it 
actually works correctly, but one reason why we can't simply use the error node 
may be that the binding to that variable might have already disappeared from 
the state by the time the bug is found.

This time i noticed that for the inlined defensive checks visitor the 
`DeclRefExpr` node is in fact sometimes too //early//: the call in which the 
inlined defensive check has happened might have not been entered yet.

Therefore i change the visitor to be fine with tracking dead symbols (which it 
is totally capable of - the collapse point for the symbol is still 
well-defined), and fire it up directly on the error node. I still use 
"`LVState`" to find out which value should we be tracking, so there shouldn't 
be any problems with accidentally loading an ill-formed value from a dead 
variable.

I hope it's one tiny piece of understanding that'll bring us to a better 
architecture of this code.


Repository:
  rC Clang

https://reviews.llvm.org/D67932

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/NSContainers.m


Index: clang/test/Analysis/NSContainers.m
===
--- clang/test/Analysis/NSContainers.m
+++ clang/test/Analysis/NSContainers.m
@@ -2,6 +2,8 @@
 
 void clang_analyzer_eval(int);
 
+#define nil ((id)0)
+
 typedef unsigned long NSUInteger;
 typedef signed char BOOL;
 typedef struct _NSZone NSZone;
@@ -310,3 +312,14 @@
   // here either.
   [subviews addObject:view]; // no-warning
 }
+
+NSString *getStringFromString(NSString *string) {
+  if (!string)
+return nil;
+  return @"New String";
+}
+void testInlinedDefensiveCheck(NSMutableDictionary *dict, id obj) {
+  // The check in getStringFromString() is not a good indication
+  // that 'obj' can be nil in this context.
+  dict[obj] = getStringFromString(obj); // no-warning
+}
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1601,9 +1601,6 @@
   AnalyzerOptions  = N->getState()->getAnalysisManager().options;
   if (!Options.ShouldSuppressInlinedDefensiveChecks)
 IsSatisfied = true;
-
-  assert(N->getState()->isNull(V).isConstrainedTrue() &&
- "The visitor only tracks the cases where V is constrained to 0");
 }
 
 void SuppressInlineDefensiveChecksVisitor::Profile(
@@ -1634,13 +1631,12 @@
 
   // Check if in the previous state it was feasible for this value
   // to *not* be null.
-  if (!Pred->getState()->isNull(V).isConstrainedTrue()) {
+  if (!Pred->getState()->isNull(V).isConstrainedTrue() &&
+  Succ->getState()->isNull(V).isConstrainedTrue()) {
 IsSatisfied = true;
 
-assert(Succ->getState()->isNull(V).isConstrainedTrue());
-
 // Check if this is inlined defensive checks.
-const LocationContext *CurLC =Succ->getLocationContext();
+const LocationContext *CurLC = Succ->getLocationContext();
 const LocationContext *ReportLC = BR.getErrorNode()->getLocationContext();
 if (CurLC != ReportLC && !CurLC->isParentOf(ReportLC)) {
   BR.markInvalid("Suppress IDC", CurLC);
@@ -2007,11 +2003,16 @@
 
   // Add visitor, which will suppress inline defensive checks.
   if (auto DV = V.getAs())
-if (!DV->isZeroConstant() && LVState->isNull(*DV).isConstrainedTrue() 
&&
-EnableNullFPSuppression)
+if (!DV->isZeroConstant() && EnableNullFPSuppression) {
+  // Note that LVNode may be too late; the lvalue may have been 
computed
+  // before the inlined call was evaluated. InputNode may as well be
+  // too late, because the symbol is already dead; this, however,
+  // is fine because we can still find the node in which it
+  // collapsed to null previously.
   report.addVisitor(
-  std::make_unique(*DV,
-  LVNode));
+  std::make_unique(
+  *DV, InputNode));
+}
 
   if (auto KV = V.getAs())
 report.addVisitor(std::make_unique(


Index: clang/test/Analysis/NSContainers.m
===
--- clang/test/Analysis/NSContainers.m

[PATCH] D65841: [Driver] Switch -stdlib++-isystem test to -###-verbatim

2019-09-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65841



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


[PATCH] D67774: [Mangle] Add flag to asm labels to disable global prefixing

2019-09-23 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:734
+// TODO: Make it possible to specify this in source.
+BoolArgument<"LiteralLabel">
+  ];

`LiteralLabel` is an unfortunate name for this property because 
`getLiteralLabel` sounds like it ought to return a string.  How about 
`IsLiteralLabel`?

Also there's a "fake" flag to make it clear that this argument isn't 
(currently) written in source, so this should be 
`BoolArgument<"IsLiteralLabel", /*optional*/ 0, /*fake*/ 1>`.

Comment suggestion:

  IsLiteralLabel specifies whether the label is literal (i.e. suppresses the 
global C symbol prefix) or not.



Comment at: clang/include/clang/Basic/Attr.td:740
+[{
+bool equivalent(AsmLabelAttr *Other) const {
+  return getLabel() == Other->getLabel() && getLiteralLabel() == 
Other->getLiteralLabel();

`isEquivalent`, please.



Comment at: clang/include/clang/Basic/AttrDocs.td:2579
+  }];
+}
+

Oh, thank you for adding documentation.  I think the prefixing thing probably 
ought to be explained here; here's a suggestion for some wording:

  This attribute can be used on a function or variable to specify its symbol 
name.

  On some targets, all C symbols are prefixed by default with a single 
character, typically ``_``.  This was done historically to distinguish them 
from symbols used by other languages.  (This prefix is also added to the 
standard Itanium C++ ABI prefix on "mangled" symbol names, so that e.g. on such 
targets the true symbol name for a C++ variable declared as ``int cppvar;`` 
would be ``__Z6cppvar``; note the two underscores.)  This prefix is *not* added 
to the symbol names specified by the ``asm`` attribute; programmers wishing to 
match a C symbol name must compensate for this.

  For example, consider the following C code:

  

  Clang's implementation of this attribute is compatible with GCC's, 
`documented here `_.

  While it is possible to use this attribute to name a special symbol used 
internally by the compiler, such as an LLVM intrinsic, this is neither 
recommended nor supported and may cause the compiler to crash or miscompile.  
Users who wish to gain access to intrinsic behavior are strongly encouraged to 
request new builtin functions.



Comment at: clang/lib/AST/Mangle.cpp:130
+  return;
+}
+

This is actually backwards, right?  A literal label is one that doesn't get the 
global prefix and therefore potentially needs the `\01` prefix to suppress it.


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

https://reviews.llvm.org/D67774



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


[PATCH] D67739: [WebAssembly] Let users know that wasm64 does not exist

2019-09-23 Thread Thomas Lively via Phabricator via cfe-commits
tlively planned changes to this revision.
tlively added a comment.

It sounds reasonable to check this from the backend instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67739



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


[PATCH] D67837: [CUDA][HIP] Fix assertion in Sema::markKnownEmitted with -fopenmp

2019-09-23 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Okay.  And it's okay to fall down to the code below when functions are used in 
both ways this way?


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

https://reviews.llvm.org/D67837



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


[PATCH] D63640: [clang] Improve Serialization/Imporing/Dumping of APValues

2019-09-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked an inline comment as done.
aaron.ballman added inline comments.



Comment at: clang/include/clang/AST/APValue.h:618
   }
+  const CXXRecordDecl **getMemberPointerPathPtr();
 };

Tyker wrote:
> aaron.ballman wrote:
> > We're horribly inconsistent in this class, but because the other private 
> > member functions go with it, this should probably be 
> > `GetMemberPointerPathPtr()`. Maybe rename the get/setLValue methods from 
> > above as well?
> > We're horribly inconsistent in this class
> 
> this class has many flaws. but is far too broadly used to fix.
Agreed -- I wasn't suggesting to fix the whole class, but just the new APIs 
that we add to the class. It looks like the private functions most consistently 
use a capital letter in this class, unfortunately. Best to stick with the local 
convention when in conflict.



Comment at: clang/include/clang/AST/ASTContext.h:275
-  /// Used to cleanups APValues stored in the AST.
-  mutable llvm::SmallVector APValueCleanups;
-

Tyker wrote:
> aaron.ballman wrote:
> > Tyker wrote:
> > > aaron.ballman wrote:
> > > > Why are you getting rid of this? It seems like we would still want 
> > > > these cleaned up.
> > > when i added APValueCleanups i wasn't aware that there were a generic 
> > > system to handle this. but with this patch APValue a cleaned up using the 
> > > generic ASTContext::addDestruction.
> > I don't see any new calls to `addDestruction()` though. Have I missed 
> > something?
> the modification to use `addDestruction()` was made in a previous revision 
> (https://reviews.llvm.org/D63376).
> the use is currently on master in `ConstantExpr::MoveIntoResult` in the 
> RSK_APValue case of the switch.
> this is just a removing an unused member.
> 
Ahhh, thank you for the explanation, I was missing that context.



Comment at: clang/include/clang/AST/PrettyPrinter.h:203
 
+  /// Wether null pointers should be printed as nullptr or as NULL.
+  unsigned UseNullptr : 1;

Wether -> Whether



Comment at: clang/lib/AST/APValue.cpp:748
 
+APValue::LValuePathEntry *APValue::getLValuePathPtr() {
+  return ((LV *)(char *)Data.buffer)->getPath();

Tyker wrote:
> aaron.ballman wrote:
> > Tyker wrote:
> > > aaron.ballman wrote:
> > > > Can this function be marked `const`?
> > > this function gives access to non-const internal data. this function is 
> > > private so the impact is quite limited.
> > That makes it harder to call this helper from a constant context. I think 
> > there should be overloads (one `const`, one not) to handle this.
> this helper is not intended to be used outside of importing and 
> serialization. it is logically part of initialization.
> normal users are intended to use `ArrayRef 
> APValue::getLValuePath() const`
Nothing about this API suggests that. The name looks like a generic getter. 
Perhaps a more descriptive name and some comments would help?



Comment at: clang/lib/AST/APValue.cpp:537
 
-  if (const ValueDecl *VD = Base.dyn_cast())
+  if (const ValueDecl *VD = Base.dyn_cast())
 Out << *VD;

Since you're touching the code anyway, this can be `const auto *`.



Comment at: clang/lib/AST/APValue.cpp:599
 Out << '[' << Path[I].getAsArrayIndex() << ']';
-ElemTy = Ctx.getAsArrayType(ElemTy)->getElementType();
+ElemTy = cast(ElemTy)->getElementType();
   }

Are you sure this doesn't change behavior? See the implementation of 
`ASTContext::getAsArrayType()`. Same question applies below.



Comment at: clang/lib/AST/APValue.cpp:614
   case APValue::Array: {
-const ArrayType *AT = Ctx.getAsArrayType(Ty);
+const ArrayType *AT = cast(Ty);
 QualType ElemTy = AT->getElementType();

`const auto *` and same question about behavior changes.



Comment at: clang/test/ASTMerge/APValue/APValue.cpp:1
+
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -emit-pch %s -o %t.pch

Tyker wrote:
> aaron.ballman wrote:
> > Can remove the spurious newline. Also, it seems this file was added with 
> > svn properties, was that intentional (we don't usually do that, FWIW)?
> it wasn't intentional, i added via `git add` i don't think i did anything 
> weird. is it a problem ?
No idea; I'm on a platform where file modes are ignored. You should probably 
drop the svn property.



Comment at: clang/test/ASTMerge/APValue/APValue.cpp:2-3
+
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -emit-pch %s -o %t.pch
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -ast-merge %t.pch -ast-dump-all | 
FileCheck %s
+

Tyker wrote:
> aaron.ballman wrote:
> > no need for `-x c++` is there? This is already a C++ compilation unit.
> i don't know if it is normal. but i am getting an error hen i am not using 
> `-x c++`
> `error: invalid argument 

[PATCH] D66951: [ASTImporter] Add comprehensive tests for ODR violation handling strategies

2019-09-23 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

2nd attempt to fix the windows build errors: 372646


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66951



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


r372646 - [ASTImporter] 2nd attempt to fix Windows buildbot test errors

2019-09-23 Thread Gabor Marton via cfe-commits
Author: martong
Date: Mon Sep 23 12:49:45 2019
New Revision: 372646

URL: http://llvm.org/viewvc/llvm-project?rev=372646=rev
Log:
[ASTImporter] 2nd attempt to fix Windows buildbot test errors

Modified:
cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp

Modified: cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp?rev=372646=372645=372646=diff
==
--- cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp Mon Sep 23 
12:49:45 2019
@@ -30,9 +30,9 @@ using internal::BindableMatcher;
 
 struct Function {
   using DeclTy = FunctionDecl;
-  static constexpr auto *Prototype = "void X(long);";
+  static constexpr auto *Prototype = "void X(char*, char);";
   static constexpr auto *ConflictingPrototype = "void X(double);";
-  static constexpr auto *Definition = "void X(long a) {}";
+  static constexpr auto *Definition = "void X(char *a, char b) {}";
   static constexpr auto *ConflictingDefinition = "void X(double a) {}";
   BindableMatcher getPattern() {
 return functionDecl(hasName("X"), unless(isImplicit()));


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


[PATCH] D67774: [Mangle] Add flag to asm labels to disable global prefixing

2019-09-23 Thread Vedant Kumar via Phabricator via cfe-commits
vsk updated this revision to Diff 221391.
vsk marked 3 inline comments as done.
vsk added a comment.

- Address latest review feedback.


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

https://reviews.llvm.org/D67774

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/Mangle.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/unittests/AST/DeclTest.cpp
  lldb/source/Symbol/ClangASTContext.cpp

Index: lldb/source/Symbol/ClangASTContext.cpp
===
--- lldb/source/Symbol/ClangASTContext.cpp
+++ lldb/source/Symbol/ClangASTContext.cpp
@@ -8300,8 +8300,8 @@
 cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(*getASTContext()));
 
   if (mangled_name != nullptr) {
-cxx_method_decl->addAttr(
-clang::AsmLabelAttr::CreateImplicit(*getASTContext(), mangled_name));
+cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
+*getASTContext(), mangled_name, /*literal=*/true));
   }
 
   // Populate the method decl with parameter decls
Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -10,12 +10,16 @@
 //
 //===--===//
 
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Mangle.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Tooling/Tooling.h"
 #include "gtest/gtest.h"
 
 using namespace clang::ast_matchers;
 using namespace clang::tooling;
+using namespace clang;
 
 TEST(Decl, CleansUpAPValues) {
   MatchFinder Finder;
@@ -56,3 +60,49 @@
   "constexpr _Complex __uint128_t c = 0x;",
   Args));
 }
+
+TEST(Decl, AsmLabelAttr) {
+  // Create two method decls: `f` and `g`.
+  StringRef Code = R"(
+struct S {
+  void f() {}
+  void g() {}
+};
+  )";
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code, {"-target", "i386-apple-darwin"});
+  ASTContext  = AST->getASTContext();
+  DiagnosticsEngine  = AST->getDiagnostics();
+  SourceManager  = AST->getSourceManager();
+  FileID MainFileID = SM.getMainFileID();
+
+  // Find the method decls within the AST.
+  SmallVector Decls;
+  AST->findFileRegionDecls(MainFileID, Code.find('{'), 0, Decls);
+  ASSERT_TRUE(Decls.size() == 1);
+  CXXRecordDecl *DeclS = cast(Decls[0]);
+  NamedDecl *DeclF = *DeclS->method_begin();
+  NamedDecl *DeclG = *(++DeclS->method_begin());
+
+  // Attach asm labels to the decls: one literal, and one subject to global
+  // prefixing.
+  DeclF->addAttr(::new (Ctx) AsmLabelAttr(Ctx, SourceLocation(), "foo",
+  /*LiteralLabel=*/true));
+  DeclG->addAttr(::new (Ctx) AsmLabelAttr(Ctx, SourceLocation(), "goo",
+  /*LiteralLabel=*/false));
+
+  // Mangle the decl names.
+  std::string MangleF, MangleG;
+  MangleContext *MC = ItaniumMangleContext::create(Ctx, Diags);
+  {
+llvm::raw_string_ostream OS(MangleF);
+MC->mangleName(DeclF, OS);
+  }
+  {
+llvm::raw_string_ostream OS(MangleG);
+MC->mangleName(DeclG, OS);
+  }
+
+  ASSERT_TRUE(0 == MangleF.compare("foo"));
+  ASSERT_TRUE(0 == MangleG.compare("\x01goo"));
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2766,7 +2766,7 @@
 
   if (AsmLabelAttr *NewA = New->getAttr()) {
 if (AsmLabelAttr *OldA = Old->getAttr()) {
-  if (OldA->getLabel() != NewA->getLabel()) {
+  if (!OldA->equivalent(NewA)) {
 // This redeclaration changes __asm__ label.
 Diag(New->getLocation(), diag::err_different_asm_label);
 Diag(OldA->getLocation(), diag::note_previous_declaration);
@@ -6983,8 +6983,8 @@
   }
 }
 
-NewVD->addAttr(::new (Context)
-   AsmLabelAttr(Context, SE->getStrTokenLoc(0), Label));
+NewVD->addAttr(::new (Context) AsmLabelAttr(Context, SE->getStrTokenLoc(0),
+Label, /*LiteralLabel=*/false));
   } else if (!ExtnameUndeclaredIdentifiers.empty()) {
 llvm::DenseMap::iterator I =
   ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier());
@@ -8882,8 +8882,9 @@
   if (Expr *E = (Expr*) D.getAsmLabel()) {
 // The parser guarantees this is a string.
 StringLiteral *SE = cast(E);
-NewFD->addAttr(::new (Context) AsmLabelAttr(Context, SE->getStrTokenLoc(0),
-SE->getString()));
+NewFD->addAttr(::new (Context)
+   AsmLabelAttr(Context, SE->getStrTokenLoc(0),
+SE->getString(), /*LiteralLabel=*/false));
   } else if (!ExtnameUndeclaredIdentifiers.empty()) {
 llvm::DenseMap::iterator I =
   

[PATCH] D64671: [clang-tidy] New check: misc-init-local-variables

2019-09-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


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

https://reviews.llvm.org/D64671



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


[PATCH] D63640: [clang] Improve Serialization/Imporing/Dumping of APValues

2019-09-23 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 221384.
Tyker marked 12 inline comments as done.
Tyker retitled this revision from "[clang] Improve Serialization/Imporing of 
APValues" to "[clang] Improve Serialization/Imporing/Dumping of APValues".
Tyker edited the summary of this revision.
Tyker added a comment.

fixed some changes.
see comments for others.


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

https://reviews.llvm.org/D63640

Files:
  clang/include/clang/AST/APValue.h
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTImporter.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/PrettyPrinter.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/AST/APValue.cpp
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/AST/ast-dump-color.cpp
  clang/test/ASTMerge/APValue/APValue.cpp

Index: clang/test/ASTMerge/APValue/APValue.cpp
===
--- /dev/null
+++ clang/test/ASTMerge/APValue/APValue.cpp
@@ -0,0 +1,209 @@
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -emit-pch %s -o %t.pch
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -ast-merge %t.pch -ast-dump-all | FileCheck %s
+
+#ifndef EMIT
+#define EMIT
+
+namespace Integer {
+
+constexpr int Unique_Int = int(6789);
+//CHECK:  VarDecl {{.*}} Unique_Int
+//CHECK-NEXT: ConstantExpr {{.*}} 'int' 6789
+
+constexpr __uint128_t Unique_Int128 = ((__uint128_t)0x75f17d6b3588f843 << 64) | 0xb13dea7c9c324e51;
+//CHECK:  VarDecl {{.*}} Unique_Int128 
+//CHECK-NEXT: ConstantExpr {{.*}} 'unsigned __int128' 156773562844924187900898496343692168785
+
+}
+
+namespace FloatingPoint {
+
+constexpr double Unique_Double = double(567890.67890);
+//CHECK:  VarDecl {{.*}} Unique_Double
+//CHECK-NEXT: ConstantExpr {{.*}} 'double' 5.678907e+05
+
+}
+
+// FIXME: Add test for FixedPoint, ComplexInt, ComplexFloat, AddrLabelDiff.
+
+namespace Struct {
+
+struct B {
+  int i;
+  double d;
+};
+
+constexpr B Basic_Struct = B{1, 0.7};
+//CHECK:  VarDecl {{.*}} Basic_Struct
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Struct::B' {1, 7.00e-01}
+
+struct C {
+  int i = 9;
+};
+
+struct A : B {
+  int i;
+  double d;
+  C c;
+};
+
+constexpr A Advanced_Struct = A{Basic_Struct, 1, 79.789, {}};
+//CHECK:  VarDecl {{.*}} Advanced_Struct
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Struct::A' {{[{][{]}}1, 7.00e-01}, 1, 7.978900e+01, {9}}
+
+}
+
+namespace Vector {
+
+using v4si = int __attribute__((__vector_size__(16)));
+
+constexpr v4si Vector_Int = (v4si){8, 2, 3};
+//CHECK:  VarDecl {{.*}} Vector_Int
+//CHECK-NEXT: ConstantExpr {{.*}} 'Vector::v4si':'__attribute__((__vector_size__(4 * sizeof(int int' {8, 2, 3, 0}
+
+}
+
+namespace Array {
+
+constexpr int Array_Int[] = {1, 2, 3, 4, 5, 6};
+//CHECK:  VarDecl {{.*}} Array_Int
+//CHECK-NEXT: ConstantExpr {{.*}} 'const int [6]' {1, 2, 3, 4, 5, 6}
+
+struct A {
+  int i = 789;
+  double d = 67890.09876;
+};
+
+constexpr A Array2_Struct[][3] = {{{}, {-45678, 9.8}, {9}}, {{}}};
+//CHECK:  VarDecl {{.*}} Array2_Struct
+//CHECK-NEXT: ConstantExpr {{.*}} 'Array::A const [2][3]' {{[{][{]}}{789, 6.789010e+04}, {-45678, 9.80e+00}, {9, 6.789010e+04}}, {{[{][{]}}789, 6.789010e+04}, {789, 6.789010e+04}, {789, 6.789010e+04}}}
+
+using v4si = int __attribute__((__vector_size__(16)));
+
+constexpr v4si Array_Vector[] = {{1, 2, 3, 4}, {4, 5, 6, 7}};
+//CHECK:  VarDecl {{.*}} Array_Vector
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Array::v4si [2]' {{[{][{]}}1, 2, 3, 4}, {4, 5, 6, 7}}
+
+}
+
+namespace Union {
+
+struct A {
+  int i = 6789;
+  float f = 987.9876;
+};
+
+union U {
+  int i;
+  A a{567890, 9876.5678f};
+};
+
+constexpr U Unique_Union1 = U{0};
+//CHECK:  VarDecl {{.*}} Unique_Union
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Union::U' {.i = 0}
+
+constexpr U Unique_Union2 = U{};
+//CHECK:  VarDecl {{.*}} Unique_Union
+//CHECK-NEXT: ConstantExpr {{.*}} 'const Union::U' {.a = {567890, 9.876567e+03}}
+
+}
+
+namespace MemberPointer{
+
+struct A {
+  struct B {
+struct C {
+  struct D {
+struct E {
+  struct F {
+struct G {
+  int i;
+};
+  };
+};
+  };
+};
+  };
+};
+
+constexpr auto MemberPointer1 = ::B::C::D::E::F::G::i;
+//CHECK:  VarDecl {{.*}} MemberPointer1
+//CHECK-NEXT: ConstantExpr {{.*}} 'int MemberPointer::A::B::C::D::E::F::G::*' ::i
+
+struct A1 {
+  struct B1 {
+int f() const {
+  return 0;
+}
+  };
+
+};
+
+constexpr auto MemberPointer2 = ::B1::f;
+//CHECK:  VarDecl {{.*}} MemberPointer2
+//CHECK-NEXT: ConstantExpr {{.*}} 'int (MemberPointer::A1::B1::*)() const' ::f
+
+}
+
+namespace std {
+  

[PATCH] D63640: [clang] Improve Serialization/Imporing/Dumping of APValues

2019-09-23 Thread Tyker via Phabricator via cfe-commits
Tyker added inline comments.



Comment at: clang/include/clang/AST/APValue.h:618
   }
+  const CXXRecordDecl **getMemberPointerPathPtr();
 };

aaron.ballman wrote:
> We're horribly inconsistent in this class, but because the other private 
> member functions go with it, this should probably be 
> `GetMemberPointerPathPtr()`. Maybe rename the get/setLValue methods from 
> above as well?
> We're horribly inconsistent in this class

this class has many flaws. but is far too broadly used to fix.



Comment at: clang/include/clang/AST/APValue.h:512
   }
-  void setVector(const APValue *E, unsigned N) {
+  void ReserveVector(unsigned N) {
 assert(isVector() && "Invalid accessor");

aaron.ballman wrote:
> aaron.ballman wrote:
> > `reserveVector` per naming conventions
> This was marked as done but is still an issue.
sorry



Comment at: clang/include/clang/AST/ASTContext.h:275
-  /// Used to cleanups APValues stored in the AST.
-  mutable llvm::SmallVector APValueCleanups;
-

aaron.ballman wrote:
> Tyker wrote:
> > aaron.ballman wrote:
> > > Why are you getting rid of this? It seems like we would still want these 
> > > cleaned up.
> > when i added APValueCleanups i wasn't aware that there were a generic 
> > system to handle this. but with this patch APValue a cleaned up using the 
> > generic ASTContext::addDestruction.
> I don't see any new calls to `addDestruction()` though. Have I missed 
> something?
the modification to use `addDestruction()` was made in a previous revision 
(https://reviews.llvm.org/D63376).
the use is currently on master in `ConstantExpr::MoveIntoResult` in the 
RSK_APValue case of the switch.
this is just a removing an unused member.




Comment at: clang/include/clang/AST/TextNodeDumper.h:149
 
-  const ASTContext *Context;
+  const ASTContext *Context = nullptr;
 

aaron.ballman wrote:
> Tyker wrote:
> > aaron.ballman wrote:
> > > Good catch -- this pointed out a bug in the class that I've fixed in 
> > > r372323, so you'll need to rebase.
> > i took a look at the revision. there is a big difference is the quality of 
> > output between APValue::dump and APValue::printPretty. i think it is 
> > possible to come quite close to printPretty's output even without the 
> > ASTContext. this would require having a default PrintingPolicy and 
> > improving dump
> > 
> > in this patch i was relying on the -ast-dump output for testing. i would 
> > need to find an other testing strategy or make the improvement to 
> > APValue::dump first.
> > there is a big difference is the quality of output between APValue::dump 
> > and APValue::printPretty.
> 
> Yes, there is.
> 
> > i think it is possible to come quite close to printPretty's output even 
> > without the ASTContext. this would require having a default PrintingPolicy 
> > and improving dump
> 
> That would be much-appreciated! When I looked at it, it seemed like it may 
> not be plausible because `Stmt` does not track which `ASTContext` it is 
> associated with the same way that `Decl` does, and changing that seemed 
> likely to cause a huge amount of interface churn.
> 
> > in this patch i was relying on the -ast-dump output for testing. i would 
> > need to find an other testing strategy or make the improvement to 
> > APValue::dump first.
> 
> The issue resolved by r372323 was that we would crash on certain kinds of AST 
> dumps. Specifically, the default AST dumper is often used during a debugging 
> session to dump AST node information within the debugger. It was trivial to 
> get that to crash before r372323, but with that revision, we no longer crash 
> but get slightly uglier output (which is acceptable because it's still 
> human-readable output).
> 
> I'm sorry for causing extra pain for you here, but I didn't want the fix from 
> this review to accidentally become an enshrined part of the API because it's 
> very easy to forget about this use case when working on AST dumping 
> functionality.
no worries, i wrote the original bug. i added APValue::dumpPretty which has 
almost the same output as APValue::printPretty but doesn't need an ASTContext. 
and is used for TextNodeDumper.



Comment at: clang/lib/AST/APValue.cpp:748
 
+APValue::LValuePathEntry *APValue::getLValuePathPtr() {
+  return ((LV *)(char *)Data.buffer)->getPath();

aaron.ballman wrote:
> Tyker wrote:
> > aaron.ballman wrote:
> > > Can this function be marked `const`?
> > this function gives access to non-const internal data. this function is 
> > private so the impact is quite limited.
> That makes it harder to call this helper from a constant context. I think 
> there should be overloads (one `const`, one not) to handle this.
this helper is not intended to be used outside of importing and serialization. 
it is logically part of initialization.
normal users are intended to use `ArrayRef 

[PATCH] D38446: update comments in clang-format.py for python3 compatibility

2019-09-23 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

I'm not python expert but as this is a comment I don't see any issue. LGTM


Repository:
  rC Clang

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

https://reviews.llvm.org/D38446



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


[PATCH] D67843: DisableFormat also now disables SortIncludes

2019-09-23 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a subscriber: klimek.
MyDeveloperDay added a comment.

I basically agree with all the comments, I agree with you that I doubt its ever 
used in SortIncludes:true and DisableFormat:true, I just saw this as a hole 
that probably based on Myrums  Law (https://www.hyrumslaw.com/) means someone 
somewhere is already using this fact and we could come unstuck.

I have to admit I am surprised that BasedOnStyle:none really turns everything 
off, I should go back and check that as I've not seen why that is the case (I'm 
sure you correct)

I also have to admit the project I work on doesn't have a "BasedOnStyle" in our 
.clang-format, but actually this cause me out when developing a new setting 
which needed to be true by default (these seemed nowhere for me to set the 
default)

I think I like the idea of SortIncludes being turned off if not specifically 
turned on if thats possible, otherwise I'd say this patch LG but I'd check with 
@klimek as to what he thinks.


Repository:
  rC Clang

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

https://reviews.llvm.org/D67843



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


[PATCH] D67647: [Consumed] Refactor handleCall to take function argument list. NFC.

2019-09-23 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Sounds good - thanks!




Comment at: llvm/include/llvm/ADT/iterator_range.h:27-33
+template 
+constexpr bool is_random_iterator() {
+  return std::is_same<
+typename std::iterator_traits::iterator_category,
+std::random_access_iterator_tag>::value;
+}
+

Is this how the C++ standard is doing things these days? Or is it usually done 
with variable templates?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67647



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


[PATCH] D67843: DisableFormat also now disables SortIncludes

2019-09-23 Thread Sam Maier via Phabricator via cfe-commits
SamMaier added a comment.

In D67843#1679529 , @thakis wrote:

> 4. Make it so that if DisableFormat is explicitly set to true and 
> SortIncludes isn't explicitly set, then it disables SortIncludes. Or, put a 
> different way, when DisableFormat is set, set SortIncludes to false at that 
> point. Then an explicit `DisableFormat: true; SortIncludes: true` would still 
> work.
>
>   MyDeveloperDay, would you find that intuitive?
>
>   I think the patch as-is is fine as I said, but if folks want to sort 
> includes without formatting, that might be another option.


I wasn't sure about this since I didn't see any way of distinguishing an 
explicitly set Style attribute vs an inherited Style attribute from a 
BasedOnStyle. If there's an easy way to distinguish those two, I'm sure this is 
the preferred method.


Repository:
  rC Clang

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

https://reviews.llvm.org/D67843



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


[PATCH] D67843: DisableFormat also now disables SortIncludes

2019-09-23 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

4. Make it so that if DisableFormat is explicitly set to true and SortIncludes 
isn't explicitly set, then it disables SortIncludes. Or, put a different way, 
when DisableFormat is set, set SortIncludes to false at that point. Then an 
explicit `DisableFormat: true; SortIncludes: true` would still work.

MyDeveloperDay, would you find that intuitive?

I think the patch as-is is fine as I said, but if folks want to sort includes 
without formatting, that might be another option.


Repository:
  rC Clang

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

https://reviews.llvm.org/D67843



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


[PATCH] D67509: [CUDA][HIP] Fix hostness of defaulted constructor

2019-09-23 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D67509#1678394 , @yaxunl wrote:

> A reduced test case is
>
>   struct A {
> A();
>   };
>  
>   template 
>   struct B
>   {
> T a;
> constexpr B() = default;
>   };
>  
>   B x;
>  
>
>
> `B::B()` got implicit `__host__ __device__`  attrs due to constexpr before 
> entering Sema::inferCUDATargetForImplicitSpecialMember.
>  In Sema::inferCUDATargetForImplicitSpecialMember, the inferred hostness of 
> `B::B()` is host since `A::A()` is host. This causes discrepancy between 
> the inferred hostness and the existing hostness.


On one hand `inferCUDATargetForImplicitSpecialMember` is correct here. 
On the other hand, `constexpr` being implicitly `__host__ __device__` also 
works OK, with the error popping up only if we need to instantiate the B on 
device side.

So, what we want is:

  __host__ void f() {B x;} // This should compile
  __device__ void f() {B x;} // This should produce an error.
  
  struct foo {
__host__ foo() { B x; } // should compile
__device__ foo() { B x; } // ???
  };

We could remove the implicit '__device__' attribute from the function. This 
should make `__device__ foo()` fail to compile regardless of whether `struct 
foo` is instantiated on device.
Or we can keep the defaulted constexpr function as `__host__ __device__` and 
catch the error only if/when `struct foo` is instantiated on device side.

NVCC (and clang as it is right now) appear to follow the latter -- there's no 
error if we don't generate code for the function.
https://godbolt.org/z/aVhvVn

For the sake of avoiding surprises, I think we should preserve this behavior 
and just relax the assertion here. We should be OK to infer stricter set of 
attributes, but not to relax them.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67509



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


[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Michael Liao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372640: [Sema] Fix the atomic expr rebuilding order. 
(authored by hliao, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67924?vs=221375=221378#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D67924

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/lib/Sema/TreeTransform.h
  cfe/trunk/test/AST/atomic-expr.cpp

Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -4637,9 +4637,12 @@
MultiExprArg ArgExprs, SourceLocation RParenLoc,
Expr *ExecConfig = nullptr,
bool IsExecConfig = false);
-  ExprResult BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
- SourceLocation RParenLoc, MultiExprArg Args,
- AtomicExpr::AtomicOp Op);
+  enum class AtomicArgumentOrder { API, AST };
+  ExprResult
+  BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
+  SourceLocation RParenLoc, MultiExprArg Args,
+  AtomicExpr::AtomicOp Op,
+  AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API);
   ExprResult
   BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc,
 ArrayRef Arg, SourceLocation RParenLoc,
Index: cfe/trunk/test/AST/atomic-expr.cpp
===
--- cfe/trunk/test/AST/atomic-expr.cpp
+++ cfe/trunk/test/AST/atomic-expr.cpp
@@ -3,17 +3,58 @@
 template
 void pr43370() {
   int arr[2];
-  __atomic_store_n(arr, 0, 0);
+  __atomic_store_n(arr, 0, 5);
 }
+
+template
+void foo() {
+  int arr[2];
+  (void)__atomic_compare_exchange_n(arr, arr, 1, 0, 3, 4);
+}
+
 void useage(){
   pr43370();
+  foo();
 }
 
 // CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}} <{{[^,]+}}, line:7:1> line:4:6 pr43370
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
 // CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:4:6 used pr43370
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
+
+// CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}}  line:10:6 foo
+// CHECK: AtomicExpr
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:37> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:53> 'int' 3
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:42> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:56> 'int' 4
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:47> 'int' 1
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:50> 'int' 0
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:10:6 used foo
+// CHECK: AtomicExpr
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:37> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:53> 'int' 3
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:42> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:56> 'int' 4
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:47> 'int' 1
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:50> 'int' 0
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -4473,7 +4473,8 @@
 
 ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
  SourceLocation RParenLoc, MultiExprArg Args,
- AtomicExpr::AtomicOp Op) {
+ AtomicExpr::AtomicOp Op,
+ AtomicArgumentOrder ArgOrder) {
   // All the non-OpenCL operations 

[PATCH] D65917: [clang-tidy] Added check for the Google style guide's category method naming rule.

2019-09-23 Thread David Gatwood via Phabricator via cfe-commits
dgatwood marked an inline comment as done.
dgatwood added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/google/RequireCategoryMethodPrefixesCheck.cpp:23
+  Finder->addMatcher(objcMethodDecl(hasDeclContext(
+  objcCategoryDecl())).bind(CustomCategoryMethodIdentifier), this);
+}

stephanemoore wrote:
> dgatwood wrote:
> > stephanemoore wrote:
> > > Technically category method prefixing is only strictly enforced on 
> > > classes that are shared:
> > > "If a class is not shared with other projects, categories extending it 
> > > may omit name prefixes and method name prefixes."
> > > https://github.com/google/styleguide/blob/gh-pages/objcguide.md#category-naming
> > > 
> > > With that in mind, perhaps we should match on categories on classes that 
> > > extend classes that are declared in system headers? I think you can 
> > > accomplish that by adding a custom inner matcher in `objcCategoryDecl` 
> > > which pulls out the Objective-C interface using 
> > > [clang::ObjCCategoryDecl::getClassInterface](https://clang.llvm.org/doxygen/classclang_1_1ObjCCategoryDecl.html#acdb14eeca277cfa745a4e8e842312008)
> > >  and then add `isExpansionInSystemHeader` as an inner matcher on the 
> > > custom inner matcher. WDYT? Let me know if you need help putting together.
> > Requiring users to specify which classes should be covered by this checker 
> > doesn't scale well.  System classes are a tiny fraction of the shared code 
> > that we bring in.  Proto classes alone probably outnumber system framework 
> > classes 10:1, plus all the shared code from other internal framework teams. 
> >  A list of every shared class that we bring in would be massive, and 
> > generating it programmatically would be relatively expensive.  The same 
> > problem exists for a list of prefixes to protect.
> > 
> > Also with that approach, a mistake by a person or script that maintains 
> > such a list would result in **not** getting warnings.  Silent failures are 
> > the worst kind of failure, because you don't even know that something is 
> > going wrong.  By contrast, if you require the user to specify a list of 
> > prefixes to ignore, as this patch does, then any mistake by someone 
> > maintaining the lest results in getting **extra** warnings, which makes it 
> > obvious that something is wrong and needs to be fixed.
> > 
> > I realize that ostensibly a team could own some code that is also shared, 
> > and it could have the same prefix as their app.  But there's no real reason 
> > to care about that case.  After all, if someone changes the shared code and 
> > it breaks the category, it's the same team, so their tests should catch the 
> > breakage, unlike changes made by some far-flung team on the other side of 
> > the world.  Also, if they break their own code, they also have permission 
> > to fix that breakage without additional approvals.  So that edge case is 
> > largely academic; if anybody asks for a way to not ignore specific classes 
> > that have an exempt prefix, we can certainly add that feature later pretty 
> > easily, but I really doubt anybody would bother to use it.  :-)
> > Requiring users to specify which classes should be covered by this checker 
> > doesn't scale well.
> 
> I am not convinced that listing exemptions scales well either. In 
> [D51832](https://reviews.llvm.org/D51832), we abandoned a growing list of 
> exemptions that were being used to enforce naming conventions. I am worried 
> that a list of exempt prefixes will also end up growing in a similar fashion.
> 
> > System classes are a tiny fraction of the shared code that we bring in.
> 
> That is true.
> 
> However, system classes generally have the most breadth and are the most 
> sensitive (for example, there was a recent bug introduced when someone 
> declared a category on `UIImageView` with an unprefixed getter named 
> `animationDuration` which overrode the actual 
> [`animationDuration`](https://developer.apple.com/documentation/uikit/uiimageview/1621058-animationduration?language=objc)
>  property on `UIImageView`).
> 
> > Proto classes alone probably outnumber system framework classes 10:1, plus 
> > all the shared code from other internal framework teams.
> 
> That is true but proto classes and internal shared code also tend to have 
> much more limited scope.
> 
> My concern with the check in its current form is that it has a strong 
> potential to be noisy by default. That is, if you enable this check without 
> specifying any exempt prefixes then it will warn for _any category_, 
> including categories on classes that are not shared which do not require a 
> prefix. Moreover, the check provides no option to exempt classes that do not 
> have prefixes at all (prefixes are only required for classes that are shared 
> per [Google Objective-C class naming 
> guidelines](https://github.com/google/styleguide/blob/gh-pages/objcguide.md#class-names)).
> 
> Generated Objective-C Protocol 

[PATCH] D67843: DisableFormat also now disables SortIncludes

2019-09-23 Thread Sam Maier via Phabricator via cfe-commits
SamMaier added a comment.

In D67843#1677983 , @MyDeveloperDay 
wrote:

> I assume the intention was that users could have DisableFormat=true and 
> SortIncludes=true when they want to sort the includes but not perform any 
> additional formatting in the code.
>
> I think by making this change you make it impossible to run clang-format 
> through a codebase with the sole intention of just sorting the headers. 
> (which I could see as potentially useful isolated functionality)..
>
> If SortIncludes is false by default? (which you are making it not for no 
> style so I'm unclear what it would be now if you running without a 
> BasedOnStyle setting (uninitialized?)) then you don't need to supply both 
> unless you are using LLVM style or one of the other styles that turn it on.
>
> Are you sure this is the right change?


This is from my experience with Chromium's use of clang-format.

People intuitively use DisableFormat: true to (they think) turn off formatting 
for that subdirectory. The Chromium project has 10 instances of this 
(https://cs.chromium.org/search/?q=file:.clang-format+DisableFormat:%5CWtrue=package:chromium=cs).
 The "correct" thing to do here is to specify BasedOnStyle: none if they 
actually want no formatting. If you don't provide a BasedOnStyle, the 
DefaultFallbackStyle is LLVM, which means that SortIncludes is always true 
unless directly overridden.

I see 3 options:

1. Take this change as is. This breaks the ability to only sort includes 
without doing any other formatting. I'm not sure how much sort includes only is 
used, but my guess would be not often. It makes DisableFormat actually disable 
all formatting.
2. Don't change anything. This means that DisableFormat does not disable all 
formatting, despite the docs 
(https://clang.llvm.org/docs/ClangFormatStyleOptions.html) stating it "disables 
formatting completely". The only real way to disable formatting for a directory 
is to use BasedOnStyle: none, or to specify SortIncludes: false, which both are 
pretty unintuitive IMO.
3. Change the default fallback to something else if there is a .clang-format 
file with no BasedOnStyle. This could have farther reaching consequences which 
could affect more users who depend on clang-format just applying LLVM style 
even if they don't specify it.


Repository:
  rC Clang

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

https://reviews.llvm.org/D67843



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


r372640 - [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Michael Liao via cfe-commits
Author: hliao
Date: Mon Sep 23 11:48:06 2019
New Revision: 372640

URL: http://llvm.org/viewvc/llvm-project?rev=372640=rev
Log:
[Sema] Fix the atomic expr rebuilding order.

Summary:
- Rearrange the atomic expr order to the API order when rebuilding
  atomic expr during template instantiation.

Reviewers: erichkeane

Subscribers: jfb, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/AST/atomic-expr.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=372640=372639=372640=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Sep 23 11:48:06 2019
@@ -4637,9 +4637,12 @@ public:
MultiExprArg ArgExprs, SourceLocation RParenLoc,
Expr *ExecConfig = nullptr,
bool IsExecConfig = false);
-  ExprResult BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
- SourceLocation RParenLoc, MultiExprArg Args,
- AtomicExpr::AtomicOp Op);
+  enum class AtomicArgumentOrder { API, AST };
+  ExprResult
+  BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
+  SourceLocation RParenLoc, MultiExprArg Args,
+  AtomicExpr::AtomicOp Op,
+  AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API);
   ExprResult
   BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc,
 ArrayRef Arg, SourceLocation RParenLoc,

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=372640=372639=372640=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 23 11:48:06 2019
@@ -4473,7 +4473,8 @@ ExprResult Sema::SemaAtomicOpsOverloaded
 
 ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
  SourceLocation RParenLoc, MultiExprArg Args,
- AtomicExpr::AtomicOp Op) {
+ AtomicExpr::AtomicOp Op,
+ AtomicArgumentOrder ArgOrder) {
   // All the non-OpenCL operations take one of the following forms.
   // The OpenCL operations take the __c11 forms with one extra argument for
   // synchronization scope.
@@ -4754,19 +4755,56 @@ ExprResult Sema::BuildAtomicExpr(SourceR
 IsPassedByAddress = true;
   }
 
+  SmallVector APIOrderedArgs;
+  if (ArgOrder == Sema::AtomicArgumentOrder::AST) {
+APIOrderedArgs.push_back(Args[0]);
+switch (Form) {
+case Init:
+case Load:
+  APIOrderedArgs.push_back(Args[1]); // Val1/Order
+  break;
+case LoadCopy:
+case Copy:
+case Arithmetic:
+case Xchg:
+  APIOrderedArgs.push_back(Args[2]); // Val1
+  APIOrderedArgs.push_back(Args[1]); // Order
+  break;
+case GNUXchg:
+  APIOrderedArgs.push_back(Args[2]); // Val1
+  APIOrderedArgs.push_back(Args[3]); // Val2
+  APIOrderedArgs.push_back(Args[1]); // Order
+  break;
+case C11CmpXchg:
+  APIOrderedArgs.push_back(Args[2]); // Val1
+  APIOrderedArgs.push_back(Args[4]); // Val2
+  APIOrderedArgs.push_back(Args[1]); // Order
+  APIOrderedArgs.push_back(Args[3]); // OrderFail
+  break;
+case GNUCmpXchg:
+  APIOrderedArgs.push_back(Args[2]); // Val1
+  APIOrderedArgs.push_back(Args[4]); // Val2
+  APIOrderedArgs.push_back(Args[5]); // Weak
+  APIOrderedArgs.push_back(Args[1]); // Order
+  APIOrderedArgs.push_back(Args[3]); // OrderFail
+  break;
+}
+  } else
+APIOrderedArgs.append(Args.begin(), Args.end());
+
   // The first argument's non-CV pointer type is used to deduce the type of
   // subsequent arguments, except for:
   //  - weak flag (always converted to bool)
   //  - memory order (always converted to int)
   //  - scope  (always converted to int)
-  for (unsigned i = 0; i != Args.size(); ++i) {
+  for (unsigned i = 0; i != APIOrderedArgs.size(); ++i) {
 QualType Ty;
 if (i < NumVals[Form] + 1) {
   switch (i) {
   case 0:
 // The first argument is always a pointer. It has a fixed type.
 // It is always dereferenced, a nullptr is undefined.
-CheckNonNullArgument(*this, Args[i], ExprRange.getBegin());
+CheckNonNullArgument(*this, APIOrderedArgs[i], ExprRange.getBegin());
 // Nothing else to do: we already know all we want about this pointer.
 continue;
   case 1:
@@ -4778,14 +4816,16 @@ ExprResult 

[PATCH] D64991: [analyzer][WIP] Implement a primitive reaching definitions analysis

2019-09-23 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 221355.
Szelethus added a comment.

The following words are echoing in my ears as I'm knowingly going completely 
against them:

In D45532#1083670 , @NoQ wrote:

> I'm asking for this because it's, like, actually difficult and painful to 
> understand formal information in large chunks. One-solution-at-a-time would 
> have been so much easier. It is really a bad idea to start by presenting a 
> working solution; the great idea is to present a small non-working solution 
> with a reasonable idea behind it, and then extend it "in place" as much as it 
> seems necessary. It is very comfortable when parts of the patch with 
> different "status" (main ideas, corner-case fixes, heuristics, refactoring) 
> stay in separate patches.
>
> Essentially every part of the solution that you implement, if you think it 
> might deserve a separate discussion, also deserves a separate patch. It is 
> reasonable to split the work into logical chunks before you start it. It's 
> very unlikely that you have a single idea that takes 500 non-trivial lines of 
> code to express. Splitting up ideas so that they were easy to grasp is an 
> invaluable effort.


I'll keep this revision as more of a bag of ideas, and create a series of 
patches when I got the core of this figured out. This algorithm is very hard to 
implement, and its easier for me to not bother with splitting up my entire work 
when I'm still shooting at a moving target. Several of my ideas required me to 
make huge refactorings, and as the code grows, my overall desire for the 
finished algorithm changes as well.

With that said.

I made the following changes:

- Added support for record, but not much in terms of C++ classes.
  - Fields of a record are identified with a (variable, chain of fields) pair, 
e.g. `Var.a.x.b` would be represented with (`Var`,  `FieldDecl`s of `[a, x, 
b]`).
  - A `Definition` of a record object doesn't contain `Definition`s of its 
fields -- instead, whenever a `Definition` of a record object is added to a GEN 
set, a helper function creates adds `Definition`s for its fields. This is 
convenient, else we'd need to flatten `Definition`s later on. For the example 
mentioned earlier, we really need an entry separately for `Var`, `Var.a`, 
`Var.a.x`, `Var.a.x.b` in order for the analyzer to conveniently ask for 
reaching definitions later down the line.
- Added/corrected plenty of test cases.
- Haven't really touched variable invalidation.
- Decorated the code with a ton of `TODO`s, but not much documentation just yet.

There are a couple things I'm worrying about, especially those that @xazax.hun 
mentioned in the inlines. I'm still confident that actual writes to a variable 
may only be assignments and variable definitions, but they can be esoteric 
enough, e.g. `(a, b) = 5`, `retrieveWhateverObject() = {9, 5, "remember the 
vasa"}`. For now, performance doesn't really concern me, but eventually I'll 
need to move the matchers to a builder class. Invalidation propagation (as 
discussed on mailing list 
) hide in them a 
variety of tricky edge cases. All of these combined create a desire for a 
thought-out, easily extensible way to create GEN sets.

So, here are my ideas.

- Overall code structure
  - Create a builder object, stored in the calculator itself, which would store 
the expensive-to-create matchers.
  - Make assignment an event to which a variety of rules may be assigned to, so 
special cases like  `(a, b) = 5`, `retrieveWhateverObject() = {9, 5, "remember 
the vasa"}`, assignment to `this`, and whatever pitfalls Objective-.* languages 
have may be more easily handled.
  - GEN sets store the outgoing, or in other words, last definition to each 
variable, but this information is not enough. The way I described 
 how I plan to 
make this algorithm semi-intraprocedural with the use of visitors in a nutshell 
works by the analyzer trying to prove that an invalidation really does write a 
variable, or can be discarded. However, in the same block, for the same 
variable, multiple invalidations of the same variable may occur. So, instead of 
storing the last definition, we should store all invalidations up to the first 
write. Later, the analyzer could remove these definitions directly, and ask the 
calculator to regenerate the KILL sets and recalculate the reaching definitions 
sets.
- Invalidation
  - Research type based alias analysis 
, until then, 
ignore aliases, and just invalidate objects of the same type.
  - The example below highlights how the function call on line 2 is a 
definition of `i`, because `ptr` might point to it, but may not be a definition 
of `j`. Buuut, with the use of `goto`, it is possible 
. This 

[PATCH] D64671: [clang-tidy] New check: misc-init-local-variables

2019-09-23 Thread Jussi Pakkanen via Phabricator via cfe-commits
jpakkane updated this revision to Diff 221376.
jpakkane added a comment.

Added MathHeader documentation.


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

https://reviews.llvm.org/D64671

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-init-variables.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/cppcoreguidelines-init-variables.cpp

Index: clang-tools-extra/test/clang-tidy/cppcoreguidelines-init-variables.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/cppcoreguidelines-init-variables.cpp
@@ -0,0 +1,80 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t
+
+// Ensure that function declarations are not changed.
+void some_func(int x, double d, bool b, const char *p);
+
+// Ensure that function arguments are not changed
+int identity_function(int x) {
+  return x;
+}
+
+int do_not_modify_me;
+
+static int should_not_be_initialized;
+extern int should_not_be_initialized2;
+
+typedef struct {
+  int unaltered1;
+  int unaltered2;
+} UnusedStruct;
+
+typedef int my_int_type;
+#define MACRO_INT int
+#define FULL_DECLARATION() int macrodecl;
+
+template 
+void template_test_function() {
+  T t;
+  int uninitialized;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'uninitialized' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  int uninitialized = 0;{{$}}
+}
+
+void init_unit_tests() {
+  int x;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'x' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  int x = 0;{{$}}
+  my_int_type myint;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'myint' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  my_int_type myint = 0;{{$}}
+
+  MACRO_INT macroint;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'macroint' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  MACRO_INT macroint = 0;{{$}}
+  FULL_DECLARATION();
+
+  int x0 = 1, x1, x2 = 2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'x1' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  int x0 = 1, x1 = 0, x2 = 2;{{$}}
+  int y0, y1 = 1, y2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'y0' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: variable 'y2' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  int y0 = 0, y1 = 1, y2 = 0;{{$}}
+  int hasval = 42;
+
+  float f;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'f' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  float f = NAN;{{$}}
+  float fval = 85.0;
+  double d;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: variable 'd' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  double d = NAN;{{$}}
+  double dval = 99.0;
+
+  bool b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'b' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  bool b = 0;{{$}}
+  bool bval = true;
+
+  const char *ptr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'ptr' is not initialized [cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  const char *ptr = nullptr;{{$}}
+  const char *ptrval = "a string";
+
+  UnusedStruct u;
+
+  static int does_not_need_an_initializer;
+  extern int does_not_need_an_initializer2;
+  int parens(42);
+  int braces{42};
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -193,6 +193,7 @@
cppcoreguidelines-avoid-magic-numbers (redirects to readability-magic-numbers) 
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-explicit-virtual-functions (redirects to modernize-use-override) 
+   cppcoreguidelines-init-variables
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-macro-usage
cppcoreguidelines-narrowing-conversions
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-init-variables.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-init-variables.rst
@@ -0,0 +1,51 @@
+.. title:: clang-tidy - cppcoreguidelines-init-variables
+
+cppcoreguidelines-init-variables

[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 221375.
hliao added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67924

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/atomic-expr.cpp

Index: clang/test/AST/atomic-expr.cpp
===
--- clang/test/AST/atomic-expr.cpp
+++ clang/test/AST/atomic-expr.cpp
@@ -3,17 +3,58 @@
 template
 void pr43370() {
   int arr[2];
-  __atomic_store_n(arr, 0, 0);
+  __atomic_store_n(arr, 0, 5);
 }
+
+template
+void foo() {
+  int arr[2];
+  (void)__atomic_compare_exchange_n(arr, arr, 1, 0, 3, 4);
+}
+
 void useage(){
   pr43370();
+  foo();
 }
 
 // CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}} <{{[^,]+}}, line:7:1> line:4:6 pr43370
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
 // CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:4:6 used pr43370
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
+
+// CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}}  line:10:6 foo
+// CHECK: AtomicExpr
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:37> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:53> 'int' 3
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:42> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:56> 'int' 4
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:47> 'int' 1
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:50> 'int' 0
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:10:6 used foo
+// CHECK: AtomicExpr
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:37> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:53> 'int' 3
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:42> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:56> 'int' 4
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:47> 'int' 1
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:50> 'int' 0
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3308,14 +3308,14 @@
   ///
   /// By default, performs semantic analysis to build the new expression.
   /// Subclasses may override this routine to provide different behavior.
-  ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
-   MultiExprArg SubExprs,
+  ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs,
AtomicExpr::AtomicOp Op,
SourceLocation RParenLoc) {
 // Use this for all of the locations, since we don't know the difference
 // between the call and the expr at this point.
 SourceRange Range{BuiltinLoc, RParenLoc};
-return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op);
+return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
+ Sema::AtomicArgumentOrder::AST);
   }
 
 private:
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4473,7 +4473,8 @@
 
 ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
  SourceLocation RParenLoc, MultiExprArg Args,
- AtomicExpr::AtomicOp Op) {
+ AtomicExpr::AtomicOp Op,
+ AtomicArgumentOrder ArgOrder) {
   // All the non-OpenCL operations take one of the following forms.
   // The OpenCL operations take the __c11 forms with one extra argument for
   // synchronization scope.
@@ -4754,19 +4755,56 @@
 IsPassedByAddress = true;
   }
 
+  SmallVector APIOrderedArgs;
+  if (ArgOrder == 

[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 221374.
hliao added a comment.

add test case for compare_exchange.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67924

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/atomic-expr.cpp

Index: clang/test/AST/atomic-expr.cpp
===
--- clang/test/AST/atomic-expr.cpp
+++ clang/test/AST/atomic-expr.cpp
@@ -3,17 +3,58 @@
 template
 void pr43370() {
   int arr[2];
-  __atomic_store_n(arr, 0, 0);
+  __atomic_store_n(arr, 0, 5);
 }
+
+template
+void foo() {
+  int arr[2];
+  (void)__atomic_compare_exchange_n(arr, arr, 1, 0, 3, 4);
+}
+
 void useage(){
   pr43370();
+  foo();
 }
 
 // CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}} <{{[^,]+}}, line:7:1> line:4:6 pr43370
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
 // CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:4:6 used pr43370
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
+
+// CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}}  line:10:6 foo
+// CHECK: AtomicExpr
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:37> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:53> 'int' 3
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:42> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:56> 'int' 4
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:47> 'int' 1
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:50> 'int' 0
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:10:6 used foo
+// CHECK: AtomicExpr
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:37> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:53> 'int' 3
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:42> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:56> 'int' 4
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:47> 'int' 1
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:50> 'int' 0
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3308,14 +3308,15 @@
   ///
   /// By default, performs semantic analysis to build the new expression.
   /// Subclasses may override this routine to provide different behavior.
-  ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
-   MultiExprArg SubExprs,
+  ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs,
AtomicExpr::AtomicOp Op,
SourceLocation RParenLoc) {
 // Use this for all of the locations, since we don't know the difference
 // between the call and the expr at this point.
 SourceRange Range{BuiltinLoc, RParenLoc};
-return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op);
+return getSema().BuildAtomicExpr(
+Range, Range, RParenLoc, SubExprs, Op,
+/*AtomicArgumentOrder*/ Sema::AtomicArgumentOrder::AST);
   }
 
 private:
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4473,7 +4473,8 @@
 
 ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
  SourceLocation RParenLoc, MultiExprArg Args,
- AtomicExpr::AtomicOp Op) {
+ AtomicExpr::AtomicOp Op,
+ AtomicArgumentOrder ArgOrder) {
   // All the non-OpenCL operations take one of the following forms.
   // The OpenCL operations take the __c11 forms with one extra argument for
   // synchronization scope.
@@ -4754,19 +4755,56 @@
 IsPassedByAddress = true;
   }
 
+  SmallVector APIOrderedArgs;
+  if 

[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Seems your test changes have disappeared as well?  Otherwise, 1 comment then 
I'm ok with this.




Comment at: clang/lib/Sema/TreeTransform.h:3319
+Range, Range, RParenLoc, SubExprs, Op,
+/*AtomicArgumentOrder*/ Sema::AtomicArgumentOrder::AST);
   }

The comment is no longer necessary, since the enum describes the purpose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67924



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


r372635 - [OPENMP]Use standard parsing for 'match' clause, NFC.

2019-09-23 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Sep 23 11:13:31 2019
New Revision: 372635

URL: http://llvm.org/viewvc/llvm-project?rev=372635=rev
Log:
[OPENMP]Use standard parsing for 'match' clause, NFC.

Reused standard clauses parsing scheme for parsing/matching 'match'
clause in 'declare variant' directive.

Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/include/clang/Basic/OpenMPKinds.h
cfe/trunk/lib/AST/ASTTypeTraits.cpp
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=372635=372634=372635=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon Sep 23 11:13:31 2019
@@ -2844,6 +2844,7 @@ bool RecursiveASTVisitor::Trave
   case OMPC_threadprivate:
   case OMPC_uniform:
   case OMPC_device_type:
+  case OMPC_match:
   case OMPC_unknown:
 break;
   }

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=372635=372634=372635=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Mon Sep 23 11:13:31 2019
@@ -194,6 +194,9 @@
 #ifndef OPENMP_DEVICE_TYPE_KIND
 #define OPENMP_DEVICE_TYPE_KIND(Name)
 #endif
+#ifndef OPENMP_DECLARE_VARIANT_CLAUSE
+#define OPENMP_DECLARE_VARIANT_CLAUSE(Name)
+#endif
 
 // OpenMP directives.
 OPENMP_DIRECTIVE(threadprivate)
@@ -959,6 +962,10 @@ OPENMP_DEVICE_TYPE_KIND(host)
 OPENMP_DEVICE_TYPE_KIND(nohost)
 OPENMP_DEVICE_TYPE_KIND(any)
 
+// Clauses allowed for OpenMP directive 'declare variant'.
+OPENMP_DECLARE_VARIANT_CLAUSE(match)
+
+#undef OPENMP_DECLARE_VARIANT_CLAUSE
 #undef OPENMP_DEVICE_TYPE_KIND
 #undef OPENMP_ALLOCATE_CLAUSE
 #undef OPENMP_DECLARE_MAPPER_CLAUSE

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.h?rev=372635=372634=372635=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.h (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.h Mon Sep 23 11:13:31 2019
@@ -36,6 +36,7 @@ enum OpenMPClauseKind {
   OMPC_threadprivate,
   OMPC_uniform,
   OMPC_device_type,
+  OMPC_match,
   OMPC_unknown
 };
 

Modified: cfe/trunk/lib/AST/ASTTypeTraits.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTTypeTraits.cpp?rev=372635=372634=372635=diff
==
--- cfe/trunk/lib/AST/ASTTypeTraits.cpp (original)
+++ cfe/trunk/lib/AST/ASTTypeTraits.cpp Mon Sep 23 11:13:31 2019
@@ -117,6 +117,7 @@ ASTNodeKind ASTNodeKind::getFromNode(con
   case OMPC_threadprivate:
   case OMPC_uniform:
   case OMPC_device_type:
+  case OMPC_match:
   case OMPC_unknown:
 llvm_unreachable("unexpected OpenMP clause kind");
   }

Modified: cfe/trunk/lib/AST/OpenMPClause.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/OpenMPClause.cpp?rev=372635=372634=372635=diff
==
--- cfe/trunk/lib/AST/OpenMPClause.cpp (original)
+++ cfe/trunk/lib/AST/OpenMPClause.cpp Mon Sep 23 11:13:31 2019
@@ -44,6 +44,7 @@ OMPClause::child_range OMPClause::used_c
   case OMPC_threadprivate:
   case OMPC_uniform:
   case OMPC_device_type:
+  case OMPC_match:
   case OMPC_unknown:
 break;
   }
@@ -129,6 +130,7 @@ const OMPClauseWithPreInit *OMPClauseWit
   case OMPC_dynamic_allocators:
   case OMPC_atomic_default_mem_order:
   case OMPC_device_type:
+  case OMPC_match:
 break;
   }
 
@@ -206,6 +208,7 @@ const OMPClauseWithPostUpdate *OMPClause
   case OMPC_dynamic_allocators:
   case OMPC_atomic_default_mem_order:
   case OMPC_device_type:
+  case OMPC_match:
 break;
   }
 

Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=372635=372634=372635=diff
==
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Mon Sep 23 11:13:31 2019
@@ -56,6 +56,7 @@ OpenMPClauseKind clang::getOpenMPClauseK
 #include "clang/Basic/OpenMPKinds.def"
   .Case("uniform", OMPC_uniform)
   .Case("device_type", OMPC_device_type)
+  .Case("match", OMPC_match)
   .Default(OMPC_unknown);
 }
 
@@ -74,6 +75,8 @@ const char *clang::getOpenMPClauseName(O
 

[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 221369.
hliao added a comment.

revised


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67924

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/atomic-expr.cpp

Index: clang/test/AST/atomic-expr.cpp
===
--- clang/test/AST/atomic-expr.cpp
+++ clang/test/AST/atomic-expr.cpp
@@ -3,7 +3,7 @@
 template
 void pr43370() {
   int arr[2];
-  __atomic_store_n(arr, 0, 0);
+  __atomic_store_n(arr, 0, 5);
 }
 void useage(){
   pr43370();
@@ -13,7 +13,13 @@
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
 // CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:4:6 used pr43370
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3308,14 +3308,15 @@
   ///
   /// By default, performs semantic analysis to build the new expression.
   /// Subclasses may override this routine to provide different behavior.
-  ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
-   MultiExprArg SubExprs,
+  ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs,
AtomicExpr::AtomicOp Op,
SourceLocation RParenLoc) {
 // Use this for all of the locations, since we don't know the difference
 // between the call and the expr at this point.
 SourceRange Range{BuiltinLoc, RParenLoc};
-return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op);
+return getSema().BuildAtomicExpr(
+Range, Range, RParenLoc, SubExprs, Op,
+/*AtomicArgumentOrder*/ Sema::AtomicArgumentOrder::AST);
   }
 
 private:
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4473,7 +4473,8 @@
 
 ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
  SourceLocation RParenLoc, MultiExprArg Args,
- AtomicExpr::AtomicOp Op) {
+ AtomicExpr::AtomicOp Op,
+ AtomicArgumentOrder ArgOrder) {
   // All the non-OpenCL operations take one of the following forms.
   // The OpenCL operations take the __c11 forms with one extra argument for
   // synchronization scope.
@@ -4754,19 +4755,56 @@
 IsPassedByAddress = true;
   }
 
+  SmallVector APIOrderedArgs;
+  if (ArgOrder == Sema::AtomicArgumentOrder::AST) {
+APIOrderedArgs.push_back(Args[0]);
+switch (Form) {
+case Init:
+case Load:
+  APIOrderedArgs.push_back(Args[1]); // Val1/Order
+  break;
+case LoadCopy:
+case Copy:
+case Arithmetic:
+case Xchg:
+  APIOrderedArgs.push_back(Args[2]); // Val1
+  APIOrderedArgs.push_back(Args[1]); // Order
+  break;
+case GNUXchg:
+  APIOrderedArgs.push_back(Args[2]); // Val1
+  APIOrderedArgs.push_back(Args[3]); // Val2
+  APIOrderedArgs.push_back(Args[1]); // Order
+  break;
+case C11CmpXchg:
+  APIOrderedArgs.push_back(Args[2]); // Val1
+  APIOrderedArgs.push_back(Args[4]); // Val2
+  APIOrderedArgs.push_back(Args[1]); // Order
+  APIOrderedArgs.push_back(Args[3]); // OrderFail
+  break;
+case GNUCmpXchg:
+  APIOrderedArgs.push_back(Args[2]); // Val1
+  APIOrderedArgs.push_back(Args[4]); // Val2
+  APIOrderedArgs.push_back(Args[5]); // Weak
+  APIOrderedArgs.push_back(Args[1]); // Order
+  APIOrderedArgs.push_back(Args[3]); // OrderFail
+  break;
+}
+  } else
+APIOrderedArgs.append(Args.begin(), Args.end());
+
   // The first argument's non-CV pointer type is used to deduce the type of
   // subsequent arguments, except for:
   //  - weak flag (always converted to bool)
   //  - memory order (always converted to int)
   //  - scope  (always converted to int)
-  for (unsigned i = 0; i != Args.size(); ++i) {
+  for (unsigned i = 0; i != APIOrderedArgs.size(); ++i) {
 QualType Ty;
 if (i < NumVals[Form] + 1) {
   switch (i) {
   case 0:
 // The first 

[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Also, can you add a test for GNUCmpXchg in both situations (inside a template, 
and outside)? It is the most complicated, and would best reflect the issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67924



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


[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

It kinda stinks that we have to do this at such a late step.  I'd have much 
preferred doing this as a part of the rebuild, but it appears that the 'form' 
takes quite a bit to calculate.  Also, I'd likely have preferred that the 
initial reordering happened in codegen instead of this early, though perhaps 
thats too large of a change to do here.

I think then we're stuck with this reordering step.

That said, I'm not a fan at all of doing this parameter as a bool, particularly 
one with an ambiguous name.  Can you introduce an enum like "enum class 
AtomicArgumentOrder { API, AST}" that makes it more clear?

Additionally, ReArgs is a confusing name, how about APIOrderedArgs?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67924



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


[PATCH] D59754: [Sema] Add c++2a designated initializer warnings

2019-09-23 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D59754#1665601 , @thakis wrote:

> Another question about this, sorry. Do you know _why_ C++20 is more 
> restrictive than C99 wrt "mixture of designated and non-designated 
> initializers in the same initializer list is a C99 extension"? Is there some 
> interaction with other C++ features that makes the C99 behavior difficult in 
> C++20?


The design paper P0329R0 
 describes 
this behavior but doesn't give much rationale. According to the minutes and my 
recollections, this was part of the design as presented and didn't really 
receive any pushback at any stage of the feature design and discussion. I think 
generally the feeling was that there was insufficient motivation for adding 
that level of complexity (much like with the restriction to single-level 
designators and lack of support for array designators).


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59754



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


[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 221365.
hliao added a comment.

Add parameter name for that default argument.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67924

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/atomic-expr.cpp

Index: clang/test/AST/atomic-expr.cpp
===
--- clang/test/AST/atomic-expr.cpp
+++ clang/test/AST/atomic-expr.cpp
@@ -3,7 +3,7 @@
 template
 void pr43370() {
   int arr[2];
-  __atomic_store_n(arr, 0, 0);
+  __atomic_store_n(arr, 0, 5);
 }
 void useage(){
   pr43370();
@@ -13,7 +13,13 @@
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
 // CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:4:6 used pr43370
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3315,7 +3315,8 @@
 // Use this for all of the locations, since we don't know the difference
 // between the call and the expr at this point.
 SourceRange Range{BuiltinLoc, RParenLoc};
-return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op);
+return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
+ /*NeedRearrangeArgs*/ true);
   }
 
 private:
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4473,7 +4473,8 @@
 
 ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
  SourceLocation RParenLoc, MultiExprArg Args,
- AtomicExpr::AtomicOp Op) {
+ AtomicExpr::AtomicOp Op,
+ bool NeedRearrangeArgs) {
   // All the non-OpenCL operations take one of the following forms.
   // The OpenCL operations take the __c11 forms with one extra argument for
   // synchronization scope.
@@ -4754,19 +4755,56 @@
 IsPassedByAddress = true;
   }
 
+  SmallVector ReArgs;
+  if (NeedRearrangeArgs) {
+ReArgs.push_back(Args[0]);
+switch (Form) {
+case Init:
+case Load:
+  ReArgs.push_back(Args[1]); // Val1/Order
+  break;
+case LoadCopy:
+case Copy:
+case Arithmetic:
+case Xchg:
+  ReArgs.push_back(Args[2]); // Val1
+  ReArgs.push_back(Args[1]); // Order
+  break;
+case GNUXchg:
+  ReArgs.push_back(Args[2]); // Val1
+  ReArgs.push_back(Args[3]); // Val2
+  ReArgs.push_back(Args[1]); // Order
+  break;
+case C11CmpXchg:
+  ReArgs.push_back(Args[2]); // Val1
+  ReArgs.push_back(Args[4]); // Val2
+  ReArgs.push_back(Args[1]); // Order
+  ReArgs.push_back(Args[3]); // OrderFail
+  break;
+case GNUCmpXchg:
+  ReArgs.push_back(Args[2]); // Val1
+  ReArgs.push_back(Args[4]); // Val2
+  ReArgs.push_back(Args[5]); // Weak
+  ReArgs.push_back(Args[1]); // Order
+  ReArgs.push_back(Args[3]); // OrderFail
+  break;
+}
+  } else
+ReArgs.append(Args.begin(), Args.end());
+
   // The first argument's non-CV pointer type is used to deduce the type of
   // subsequent arguments, except for:
   //  - weak flag (always converted to bool)
   //  - memory order (always converted to int)
   //  - scope  (always converted to int)
-  for (unsigned i = 0; i != Args.size(); ++i) {
+  for (unsigned i = 0; i != ReArgs.size(); ++i) {
 QualType Ty;
 if (i < NumVals[Form] + 1) {
   switch (i) {
   case 0:
 // The first argument is always a pointer. It has a fixed type.
 // It is always dereferenced, a nullptr is undefined.
-CheckNonNullArgument(*this, Args[i], ExprRange.getBegin());
+CheckNonNullArgument(*this, ReArgs[i], ExprRange.getBegin());
 // Nothing else to do: we already know all we want about this pointer.
 continue;
   case 1:
@@ -4780,12 +4818,12 @@
 else if (Form == Copy || Form == Xchg) {
   if (IsPassedByAddress)
 // The value pointer is always dereferenced, a nullptr is undefined.
-CheckNonNullArgument(*this, Args[i], 

[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D67924#1679409 , @erichkeane wrote:

> Yikes, good catch!
>
> Would we be better off instead to just modify how the other switch loads the 
> value?  Presumably something like, "if (NeedsRearrangeArgs) 
> SubExprs.append(Args.begin(), Args.end()); else /*the switch*/.


Loop from L4762 will check "value" arguments assuming the API order as well. 
That's why arguments are arranged so that the value checking logic also check 
the correct arguments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67924



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


[PATCH] D66951: [ASTImporter] Add comprehensive tests for ODR violation handling strategies

2019-09-23 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Trying to fix in svn commit 372633.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66951



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


r372633 - [ASTImporter] Attempt to fix Windows buildbot test errors

2019-09-23 Thread Gabor Marton via cfe-commits
Author: martong
Date: Mon Sep 23 10:29:08 2019
New Revision: 372633

URL: http://llvm.org/viewvc/llvm-project?rev=372633=rev
Log:
[ASTImporter] Attempt to fix Windows buildbot test errors

Modified:
cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp

Modified: cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp?rev=372633=372632=372633=diff
==
--- cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterODRStrategiesTest.cpp Mon Sep 23 
10:29:08 2019
@@ -30,9 +30,9 @@ using internal::BindableMatcher;
 
 struct Function {
   using DeclTy = FunctionDecl;
-  static constexpr auto *Prototype = "void X(int);";
+  static constexpr auto *Prototype = "void X(long);";
   static constexpr auto *ConflictingPrototype = "void X(double);";
-  static constexpr auto *Definition = "void X(int a) {}";
+  static constexpr auto *Definition = "void X(long a) {}";
   static constexpr auto *ConflictingDefinition = "void X(double a) {}";
   BindableMatcher getPattern() {
 return functionDecl(hasName("X"), unless(isImplicit()));


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


[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:3319
+return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
+ true);
   }

When passing a bool, use the comment syntax /*paramname=*/ to make it clear 
whats happening.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67924



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


[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Yikes, good catch!

Would we be better off instead to just modify how the other switch loads the 
value?  Presumably something like, "if (NeedsRearrangeArgs) 
SubExprs.append(Args.begin(), Args.end()); else /*the switch*/.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67924



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


[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Michael Liao via Phabricator via cfe-commits
hliao created this revision.
hliao added a reviewer: erichkeane.
Herald added subscribers: cfe-commits, jfb.
Herald added a project: clang.
hliao added a comment.

The current BuildAtomicExpr expects the arguments to be in the API order 
instead of the AST order. If RebuildAtomicExpr uses the same BuildAtomicExpr, 
it needs to ensure the order of arguments are in API order; otherwise, 
arguments (especially the one with memory order) will be misplaced.


- Rearrange the atomic expr order to the API order when rebuilding atomic expr 
during template instantiation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67924

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/atomic-expr.cpp

Index: clang/test/AST/atomic-expr.cpp
===
--- clang/test/AST/atomic-expr.cpp
+++ clang/test/AST/atomic-expr.cpp
@@ -3,7 +3,7 @@
 template
 void pr43370() {
   int arr[2];
-  __atomic_store_n(arr, 0, 0);
+  __atomic_store_n(arr, 0, 5);
 }
 void useage(){
   pr43370();
@@ -13,7 +13,13 @@
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
 // CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:4:6 used pr43370
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
+// CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 0x{{[0-9a-f]+}} 'arr' 'int [2]'
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
+// CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3315,7 +3315,8 @@
 // Use this for all of the locations, since we don't know the difference
 // between the call and the expr at this point.
 SourceRange Range{BuiltinLoc, RParenLoc};
-return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op);
+return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
+ true);
   }
 
 private:
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4473,7 +4473,8 @@
 
 ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
  SourceLocation RParenLoc, MultiExprArg Args,
- AtomicExpr::AtomicOp Op) {
+ AtomicExpr::AtomicOp Op,
+ bool NeedRearrangeArgs) {
   // All the non-OpenCL operations take one of the following forms.
   // The OpenCL operations take the __c11 forms with one extra argument for
   // synchronization scope.
@@ -4754,19 +4755,56 @@
 IsPassedByAddress = true;
   }
 
+  SmallVector ReArgs;
+  if (NeedRearrangeArgs) {
+ReArgs.push_back(Args[0]);
+switch (Form) {
+case Init:
+case Load:
+  ReArgs.push_back(Args[1]); // Val1/Order
+  break;
+case LoadCopy:
+case Copy:
+case Arithmetic:
+case Xchg:
+  ReArgs.push_back(Args[2]); // Val1
+  ReArgs.push_back(Args[1]); // Order
+  break;
+case GNUXchg:
+  ReArgs.push_back(Args[2]); // Val1
+  ReArgs.push_back(Args[3]); // Val2
+  ReArgs.push_back(Args[1]); // Order
+  break;
+case C11CmpXchg:
+  ReArgs.push_back(Args[2]); // Val1
+  ReArgs.push_back(Args[4]); // Val2
+  ReArgs.push_back(Args[1]); // Order
+  ReArgs.push_back(Args[3]); // OrderFail
+  break;
+case GNUCmpXchg:
+  ReArgs.push_back(Args[2]); // Val1
+  ReArgs.push_back(Args[4]); // Val2
+  ReArgs.push_back(Args[5]); // Weak
+  ReArgs.push_back(Args[1]); // Order
+  ReArgs.push_back(Args[3]); // OrderFail
+  break;
+}
+  } else
+ReArgs.append(Args.begin(), Args.end());
+
   // The first argument's non-CV pointer type is used to deduce the type of
   // subsequent arguments, except for:
   //  - weak flag (always converted to bool)
   //  - memory order (always converted to int)
   //  - scope  (always converted to int)
-  for (unsigned i = 0; i != Args.size(); ++i) {
+  for (unsigned i = 0; i != ReArgs.size(); ++i) {
 QualType Ty;
 if (i < NumVals[Form] + 1) {
   switch (i) {
   case 0:
 // The first argument is always a pointer. It has a fixed type.
 // It is always dereferenced, a nullptr is undefined.
-CheckNonNullArgument(*this, Args[i], ExprRange.getBegin());
+CheckNonNullArgument(*this, ReArgs[i], ExprRange.getBegin());
  

[PATCH] D67924: [Sema] Fix the atomic expr rebuilding order.

2019-09-23 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

The current BuildAtomicExpr expects the arguments to be in the API order 
instead of the AST order. If RebuildAtomicExpr uses the same BuildAtomicExpr, 
it needs to ensure the order of arguments are in API order; otherwise, 
arguments (especially the one with memory order) will be misplaced.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67924



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


r372631 - NFC: Fix a poorly-written test

2019-09-23 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Mon Sep 23 10:16:55 2019
New Revision: 372631

URL: http://llvm.org/viewvc/llvm-project?rev=372631=rev
Log:
NFC: Fix a poorly-written test

The author of r364954 foolishly forgot that == binds tighter than ?:

Modified:
cfe/trunk/test/SemaCXX/constexpr-builtin-bit-cast.cpp

Modified: cfe/trunk/test/SemaCXX/constexpr-builtin-bit-cast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constexpr-builtin-bit-cast.cpp?rev=372631=372630=372631=diff
==
--- cfe/trunk/test/SemaCXX/constexpr-builtin-bit-cast.cpp (original)
+++ cfe/trunk/test/SemaCXX/constexpr-builtin-bit-cast.cpp Mon Sep 23 10:16:55 
2019
@@ -61,13 +61,13 @@ void test_record() {
 
   constexpr int_splicer splice{0x0C05FEFE, 0xCAFEBABE};
 
-  static_assert(bit_cast(splice) == LITTLE_END
-? 0xCAFEBABE0C05FEFE
-: 0x0C05FEFECAFEBABE);
-
-  static_assert(bit_cast(0xCAFEBABE0C05FEFE).x == LITTLE_END
-? 0x0C05FEFE
-: 0xCAFEBABE);
+  static_assert(bit_cast(splice) == (LITTLE_END
+ ? 
0xCAFEBABE0C05FEFE
+ : 
0x0C05FEFECAFEBABE));
+
+  static_assert(bit_cast(0xCAFEBABE0C05FEFE).x == (LITTLE_END
+? 
0x0C05FEFE
+: 
0xCAFEBABE));
 
   static_assert(round_trip(splice));
   static_assert(round_trip(splice));
@@ -220,7 +220,7 @@ void backtrace() {
 void test_array_fill() {
   constexpr unsigned char a[4] = {1, 2};
   constexpr unsigned int i = bit_cast(a);
-  static_assert(i == LITTLE_END ? 0x0201 : 0x0102, ""); // 
expected-warning {{converting the result of '?:' with integer constants to a 
boolean always evaluates to 'true'}}
+  static_assert(i == (LITTLE_END ? 0x0201 : 0x0102));
 }
 
 typedef decltype(nullptr) nullptr_t;


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


[clang-tools-extra] r372627 - [Clang-doc] NFC: Fixed link to llvm bugs in documentation

2019-09-23 Thread Shaurya Gupta via cfe-commits
Author: sureyeaah
Date: Mon Sep 23 09:55:13 2019
New Revision: 372627

URL: http://llvm.org/viewvc/llvm-project?rev=372627=rev
Log:
[Clang-doc] NFC: Fixed link to llvm bugs in documentation

Modified:
clang-tools-extra/trunk/docs/clang-doc.rst

Modified: clang-tools-extra/trunk/docs/clang-doc.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-doc.rst?rev=372627=372626=372627=diff
==
--- clang-tools-extra/trunk/docs/clang-doc.rst (original)
+++ clang-tools-extra/trunk/docs/clang-doc.rst Mon Sep 23 09:55:13 2019
@@ -12,7 +12,7 @@ source code and comments.
 
 The tool is in a very early development stage, so you might encounter bugs and
 crashes. Submitting reports with information about how to reproduce the issue
-to `the LLVM bugtracker `_ will definitely help the
+to `the LLVM bugtracker `_ will definitely help the
 project. If you have any ideas or suggestions, please to put a feature request
 there.
 


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


Re: [PATCH] D66951: [ASTImporter] Add comprehensive tests for ODR violation handling strategies

2019-09-23 Thread Gábor Márton via cfe-commits
Thanks, for reaching out to me.

I am looking into it.

Gabor

On Mon, Sep 23, 2019 at 5:44 PM Simon Pilgrim via Phabricator <
revi...@reviews.llvm.org> wrote:

> RKSimon added a comment.
>
> @martong This is failing on windows buildbots:
> http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/19808
>
>
> Repository:
>   rL LLVM
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D66951/new/
>
> https://reviews.llvm.org/D66951
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67613: [DWARF-5] Support for DWARF-5 C++ language tags

2019-09-23 Thread Sourabh Singh Tomar via Phabricator via cfe-commits
SouraVX added a comment.

In D67613#1674597 , @aprantl wrote:

> Please be sure the watch the lldb (and other debugger) bots after committing 
> this..


Could you please commit these changes.
Thanks!


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

https://reviews.llvm.org/D67613



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


[PATCH] D67899: Fix __is_fundamental to accept nullptr_t

2019-09-23 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver closed this revision.
zoecarver added a comment.

Resolved by rL372624 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67899



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


[PATCH] D61634: [clang/llvm] Allow efficient implementation of libc's memory functions in C/C++

2019-09-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D61634#1635595 , @tejohnson wrote:

> I had some time to work on this finally late last week. I decided the most 
> straightforward thing was to implement the necessary interface changes to the 
> TLI analysis to make it require a Function (without any changes yet to how 
> that analysis operates). See D66428  that I 
> just mailed for review. That takes care of the most widespread changes needed 
> for this migration, and afterwards we can change the analysis to look at the 
> function attributes and make a truly per-function TLI.


D66428  went in a few weeks ago at r371284, 
and I just mailed the follow on patch D67923  
which will adds the support into the TLI analysis to use the Function to 
override the available builtins (with some of the code stubbed out since we 
don't yet have those per-Function attributes finalized).

@gchatelet where are you at on finalizing this patch? Also, I mentioned this 
offline but to follow up here: I think we will want an attribute to represent 
-fno-builtins (so that it doesn't need to be expanded out into the full list of 
individual no-builtin-{func} attributes, which would be both more verbose and 
less efficient, as well as being less backward compatible when new builtin 
funcs are added).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61634



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


r372624 - Fix __is_fundamental to accept nullptr_t

2019-09-23 Thread Zoe Carver via cfe-commits
Author: zoecarver
Date: Mon Sep 23 09:02:46 2019
New Revision: 372624

URL: http://llvm.org/viewvc/llvm-project?rev=372624=rev
Log:
Fix __is_fundamental to accept nullptr_t

Summary: This patch updates the __is_fundamental builtin type trait to 
return true for nullptr_t.

Reviewers: rsmith, EricWF, efriedma, craig.topper, erichkeane

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/test/SemaCXX/type-traits.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=372624=372623=372624=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Sep 23 09:02:46 2019
@@ -6353,6 +6353,7 @@ inline bool QualType::isCForbiddenLValue
 /// \returns True for types specified in C++0x [basic.fundamental].
 inline bool Type::isFundamentalType() const {
   return isVoidType() ||
+ isNullPtrType() ||
  // FIXME: It's really annoying that we don't have an
  // 'isArithmeticType()' which agrees with the standard definition.
  (isArithmeticType() && !isEnumeralType());

Modified: cfe/trunk/test/SemaCXX/type-traits.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-traits.cpp?rev=372624=372623=372624=diff
==
--- cfe/trunk/test/SemaCXX/type-traits.cpp (original)
+++ cfe/trunk/test/SemaCXX/type-traits.cpp Mon Sep 23 09:02:46 2019
@@ -802,6 +802,7 @@ void is_fundamental()
   int t23[T(__is_fundamental(unsigned long))];
   int t24[T(__is_fundamental(void))];
   int t25[T(__is_fundamental(cvoid))];
+  int t26[T(__is_fundamental(decltype(nullptr)))];
 
   int t30[F(__is_fundamental(Union))];
   int t31[F(__is_fundamental(UnionAr))];


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


r372623 - [OPENMP]Fix PR43355: DO not emit target calls if only -fopenmp-targets

2019-09-23 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Sep 23 08:53:51 2019
New Revision: 372623

URL: http://llvm.org/viewvc/llvm-project?rev=372623=rev
Log:
[OPENMP]Fix PR43355: DO not emit target calls if only -fopenmp-targets
is not provided.

We should not emit any target-dependent code if only -fopenmp flag is
used and device targets are not provided to prevent compiler crash.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=372623=372622=372623=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Mon Sep 23 08:53:51 2019
@@ -2815,6 +2815,8 @@ llvm::Function *CGOpenMPRuntime::emitThr
 bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
  llvm::GlobalVariable 
*Addr,
  bool PerformInit) {
+  if (CGM.getLangOpts().OMPTargetTriples.empty())
+return false;
   Optional Res =
   OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);
   if (!Res || *Res == OMPDeclareTargetDeclAttr::MT_Link ||
@@ -9718,6 +9720,8 @@ CGOpenMPRuntime::registerTargetFirstpriv
 
 void CGOpenMPRuntime::registerTargetGlobalVariable(const VarDecl *VD,
llvm::Constant *Addr) {
+  if (CGM.getLangOpts().OMPTargetTriples.empty())
+return;
   llvm::Optional Res =
   OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);
   if (!Res) {

Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=372623=372622=372623=diff
==
--- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Mon Sep 23 08:53:51 2019
@@ -7,6 +7,15 @@
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc 
-fopenmp-version=50 -DOMP5
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device 
-fopenmp-host-ir-file-path %t-ppc-host.bc -o - -fopenmp-version=50 -DOMP5 | 
FileCheck %s --check-prefix DEV5
 
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-emit-llvm %s -o - -fopenmp-version=50 -DOMP5 | FileCheck %s --check-prefix 
KMPC-ONLY
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-emit-llvm-bc %s -o %t-ppc-host.bc -fopenmp-version=50 -DOMP5
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - 
-fopenmp-version=50 -DOMP5 | FileCheck %s --check-prefix KMPC-ONLY
+
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o 
-| FileCheck %s --check-prefix KMPC-ONLY
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc 
-emit-pch -o %t
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc 
-include-pch %t -verify -o - | FileCheck %s --check-prefix KMPC-ONLY
+
 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - -fopenmp-version=50 -DOMP5 | FileCheck %s --check-prefix 
SIMD-ONLY
 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm-bc %s -o %t-ppc-host.bc -fopenmp-version=50 -DOMP5
 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - 
-fopenmp-version=50 -DOMP5 | FileCheck %s --check-prefix SIMD-ONLY
@@ -19,6 +28,7 @@
 // expected-no-diagnostics
 
 // SIMD-ONLY-NOT: {{__kmpc|__tgt}}
+// KMPC-ONLY-NOT: __tgt
 
 // CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base|virtual_}}
 // CHECK-DAG: Bake


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


r372621 - Fix __is_signed builtin

2019-09-23 Thread Zoe Carver via cfe-commits
Author: zoecarver
Date: Mon Sep 23 08:41:20 2019
New Revision: 372621

URL: http://llvm.org/viewvc/llvm-project?rev=372621=rev
Log:
Fix __is_signed builtin

Summary: This patch fixes the __is_signed builtin type trait to work with 
floating point types and enums. Now, the builtin will return true if it is 
passed a floating point type and false for an enum type.

Reviewers: EricWF, rsmith, erichkeane, craig.topper, efriedma

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/docs/LanguageExtensions.rst
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/type-traits.cpp

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=372621=372620=372621=diff
==
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Mon Sep 23 08:41:20 2019
@@ -1161,10 +1161,7 @@ The following type trait primitives are
 * ``__is_sealed`` (Microsoft):
   Synonym for ``__is_final``.
 * ``__is_signed`` (C++, Embarcadero):
-  Note that this currently returns true for enumeration types if the underlying
-  type is signed, and returns false for floating-point types, in violation of
-  the requirements for ``std::is_signed``. This behavior is likely to change in
-  a future version of Clang.
+  Returns false for enumeration types, and returns true for floating-point 
types. Note, before Clang 10, returned true for enumeration types if the 
underlying type was signed, and returned false for floating-point types.
 * ``__is_standard_layout`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_trivial`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_trivially_assignable`` (C++, GNU, Microsoft)

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=372621=372620=372621=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Sep 23 08:41:20 2019
@@ -4605,7 +4605,9 @@ static bool EvaluateUnaryTypeTrait(Sema
   return RD->hasAttr();
 return false;
   case UTT_IsSigned:
-return T->isSignedIntegerType();
+// Enum types should always return false.
+// Floating points should always return true.
+return !T->isEnumeralType() && (T->isFloatingType() || 
T->isSignedIntegerType());
   case UTT_IsUnsigned:
 return T->isUnsignedIntegerType();
 

Modified: cfe/trunk/test/SemaCXX/type-traits.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-traits.cpp?rev=372621=372620=372621=diff
==
--- cfe/trunk/test/SemaCXX/type-traits.cpp (original)
+++ cfe/trunk/test/SemaCXX/type-traits.cpp Mon Sep 23 08:41:20 2019
@@ -12,6 +12,7 @@ typedef NonPOD NonPODArMB[10][2];
 
 // PODs
 enum Enum { EV };
+enum SignedEnum : signed int { };
 struct POD { Enum e; int i; float f; NonPOD* p; };
 struct Empty {};
 struct IncompleteStruct;
@@ -56,14 +57,14 @@ struct HasInheritedCons : HasDefaultCons
 struct HasNoInheritedCons : HasCons {};
 struct HasCopyAssign { HasCopyAssign operator =(const HasCopyAssign&); };
 struct HasMoveAssign { HasMoveAssign operator =(const HasMoveAssign&&); };
-struct HasNoThrowMoveAssign { 
+struct HasNoThrowMoveAssign {
   HasNoThrowMoveAssign& operator=(
 const HasNoThrowMoveAssign&&) throw(); };
-struct HasNoExceptNoThrowMoveAssign { 
+struct HasNoExceptNoThrowMoveAssign {
   HasNoExceptNoThrowMoveAssign& operator=(
-const HasNoExceptNoThrowMoveAssign&&) noexcept; 
+const HasNoExceptNoThrowMoveAssign&&) noexcept;
 };
-struct HasThrowMoveAssign { 
+struct HasThrowMoveAssign {
   HasThrowMoveAssign& operator=(const HasThrowMoveAssign&&)
 #if __cplusplus <= 201402L
   throw(POD);
@@ -73,7 +74,7 @@ struct HasThrowMoveAssign {
 };
 
 
-struct HasNoExceptFalseMoveAssign { 
+struct HasNoExceptFalseMoveAssign {
   HasNoExceptFalseMoveAssign& operator=(
 const HasNoExceptFalseMoveAssign&&) noexcept(false); };
 struct HasMoveCtor { HasMoveCtor(const HasMoveCtor&&); };
@@ -82,17 +83,17 @@ struct HasMemberMoveAssign { HasMoveAssi
 struct HasStaticMemberMoveCtor { static HasMoveCtor member; };
 struct HasStaticMemberMoveAssign { static HasMoveAssign member; };
 struct HasMemberThrowMoveAssign { HasThrowMoveAssign member; };
-struct HasMemberNoExceptFalseMoveAssign { 
+struct HasMemberNoExceptFalseMoveAssign {
   HasNoExceptFalseMoveAssign member; };
 struct HasMemberNoThrowMoveAssign { HasNoThrowMoveAssign member; };
-struct HasMemberNoExceptNoThrowMoveAssign { 
+struct HasMemberNoExceptNoThrowMoveAssign {
   HasNoExceptNoThrowMoveAssign member; };
 
-struct HasDefaultTrivialCopyAssign { 
+struct HasDefaultTrivialCopyAssign {
   

[PATCH] D38446: update comments in clang-format.py for python3 compatibility

2019-09-23 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

@MyDeveloperDay, added you on the assumption that you are interested in all 
things about `clang-format`. Hope the change is relevant, let me know if not.


Repository:
  rC Clang

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

https://reviews.llvm.org/D38446



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


[PATCH] D67897: Fix __is_signed builtin

2019-09-23 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver closed this revision.
zoecarver added a comment.

Resolved by rL372621 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67897



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


[PATCH] D67919: [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-09-23 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 marked an inline comment as done.
xbolva00 added inline comments.



Comment at: test/Sema/warn-conditional-emum-types-mismatch.c:19
+
+int get_flag_anon_enum(int cond) {
+  return cond ? A : C;

Gcc warns here, but Clang does not warn when A != C..

So not sure here..


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

https://reviews.llvm.org/D67919



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


[PATCH] D66951: [ASTImporter] Add comprehensive tests for ODR violation handling strategies

2019-09-23 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

@martong This is failing on windows buildbots: 
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/19808


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66951



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


[PATCH] D67501: [clang-tidy] Fix relative path in header-filter.

2019-09-23 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D67501#1679050 , @xyb wrote:

> `-normalized-header-filter`. I'd like this idea. Any objections?


Having two solution for filter is unfortunate - making both discoverable and 
documenting why we need them is hard.
If there are important use-cases that can't be served otherwise, I guess 
there's no way to avoid it.

However, if there are workaround (even if they're slightly annoying), it's much 
simpler to have a single option.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67501



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


[PATCH] D67919: [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-09-23 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 221346.
xbolva00 added a comment.

Added test file.


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

https://reviews.llvm.org/D67919

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Sema/warn-conditional-emum-types-mismatch.c


Index: test/Sema/warn-conditional-emum-types-mismatch.c
===
--- test/Sema/warn-conditional-emum-types-mismatch.c
+++ test/Sema/warn-conditional-emum-types-mismatch.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify  %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
+
+enum ro { A = 0x10 };
+enum rw { B = 0xFF };
+enum { C = 0x1A};
+
+int get_flag(int cond) {
+  return cond ? A : B; 
+  #ifdef __cplusplus
+  // expected-warning@-2 {{enumeration type mismatch in conditional expression 
('ro' and 'rw')}}
+  #else 
+  // expected-no-diagnostics'
+  #endif
+}
+
+int get_flag_anon_enum(int cond) {
+  return cond ? A : C;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -11256,6 +11256,34 @@
   return true;
 }
 
+static void checkConditionalWithEnumTypes(Sema , SourceLocation Loc,
+  Expr *LHS, Expr *RHS) {
+  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
+  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
+
+  const EnumType *LHSEnumType = LHSStrippedType->getAs();
+  if (!LHSEnumType)
+return;
+  const EnumType *RHSEnumType = RHSStrippedType->getAs();
+  if (!RHSEnumType)
+return;
+
+  // Ignore anonymous enums.
+  if (!LHSEnumType->getDecl()->getIdentifier() &&
+  !LHSEnumType->getDecl()->getTypedefNameForAnonDecl())
+return;
+  if (!RHSEnumType->getDecl()->getIdentifier() &&
+  !RHSEnumType->getDecl()->getTypedefNameForAnonDecl())
+return;
+
+  if (S.Context.hasSameUnqualifiedType(LHSStrippedType, RHSStrippedType))
+return;
+
+  S.Diag(Loc, diag::warn_conditional_mixed_enum_types)
+  << LHSStrippedType << RHSStrippedType << LHS->getSourceRange()
+  << RHS->getSourceRange();
+}
+
 static void DiagnoseIntInBoolContext(Sema , Expr *E) {
   E = E->IgnoreParenImpCasts();
   SourceLocation ExprLoc = E->getExprLoc();
@@ -11754,6 +11782,8 @@
   bool Suspicious = false;
   CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious);
   CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious);
+  checkConditionalWithEnumTypes(S, E->getBeginLoc(), E->getTrueExpr(),
+E->getFalseExpr());
 
   if (T->isBooleanType())
 DiagnoseIntInBoolContext(S, E);
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6156,6 +6156,10 @@
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,
   InGroup;
+def warn_conditional_mixed_enum_types : Warning<
+  "enumeration type mismatch in conditional expression"
+  "%diff{ ($ and $)|}0,1">,
+  InGroup;
 def warn_comparison_of_mixed_enum_types_switch : Warning<
   "comparison of two values with different enumeration types in switch 
statement"
   "%diff{ ($ and $)|}0,1">,


Index: test/Sema/warn-conditional-emum-types-mismatch.c
===
--- test/Sema/warn-conditional-emum-types-mismatch.c
+++ test/Sema/warn-conditional-emum-types-mismatch.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wenum-compare %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify  %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wenum-compare %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify %s
+
+enum ro { A = 0x10 };
+enum rw { B = 0xFF };
+enum { C = 0x1A};
+
+int get_flag(int cond) {
+  return cond ? A : B; 
+  #ifdef __cplusplus
+  // expected-warning@-2 {{enumeration type mismatch in conditional expression ('ro' and 'rw')}}
+  #else 
+  // expected-no-diagnostics'
+  #endif
+}
+
+int get_flag_anon_enum(int cond) {
+  return cond ? A : C;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -11256,6 +11256,34 @@
   return true;
 }
 
+static void checkConditionalWithEnumTypes(Sema , SourceLocation Loc,
+  Expr *LHS, Expr *RHS) {
+  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
+  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
+
+  const EnumType *LHSEnumType = LHSStrippedType->getAs();
+  if (!LHSEnumType)
+return;
+  const EnumType *RHSEnumType 

[PATCH] D67826: [clangd] A helper to find explicit references and their names

2019-09-23 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 221345.
ilya-biryukov marked 18 inline comments as done.
ilya-biryukov added a comment.
Herald added subscribers: jfb, mgrang.

- Add simple tests
- Address other comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67826

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/FindTarget.h
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -9,6 +9,9 @@
 
 #include "Selection.h"
 #include "TestTU.h"
+#include "clang/AST/Decl.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
@@ -464,6 +467,188 @@
   EXPECT_DECLS("ObjCObjectTypeLoc");
 }
 
+class FindExplicitReferencesTest : public ::testing::Test {
+protected:
+  struct AllRefs {
+std::string AnnotatedCode;
+std::string DumpedReferences;
+  };
+
+  /// Parses \p Code, finds function '::foo' and annotates its body with results
+  /// of findExplicitReferecnces.
+  /// See actual tests for examples of annotation format.
+  AllRefs annotateReferencesInFoo(llvm::StringRef Code) {
+TestTU TU;
+TU.Code = Code;
+
+auto AST = TU.build();
+auto  = llvm::cast(findDecl(AST, "foo"));
+
+std::vector Refs;
+findExplicitReferences(Func.getBody(), [](ReferenceLoc R) {
+  Refs.push_back(std::move(R));
+});
+
+auto  = AST.getSourceManager();
+llvm::sort(Refs, [&](const ReferenceLoc , const ReferenceLoc ) {
+  return SM.isBeforeInTranslationUnit(L.NameLoc, R.NameLoc);
+});
+
+std::string AnnotatedCode;
+unsigned NextOffset = 0;
+for (unsigned I = 0; I < Refs.size(); ++I) {
+  auto  = Refs[I];
+
+  SourceLocation Pos = R.NameLoc;
+  assert(Pos.isValid());
+  if (Pos.isMacroID()) // FIXME: figure out how to show macro locations.
+Pos = SM.getExpansionLoc(Pos);
+  assert(Pos.isFileID());
+
+  FileID File;
+  unsigned Offset;
+  std::tie(File, Offset) = SM.getDecomposedLoc(Pos);
+  if (File == SM.getMainFileID()) {
+// Print the reference in a source code.
+assert(NextOffset <= Offset);
+AnnotatedCode += Code.substr(NextOffset, Offset - NextOffset);
+AnnotatedCode += "$" + std::to_string(I) + "^";
+
+NextOffset = Offset;
+  }
+}
+AnnotatedCode += Code.substr(NextOffset);
+
+std::string DumpedReferences;
+for (unsigned I = 0; I < Refs.size(); ++I)
+  DumpedReferences += llvm::formatv("{0}: {1}\n", I, Refs[I]);
+
+return AllRefs{std::move(AnnotatedCode), std::move(DumpedReferences)};
+  }
+};
+
+TEST_F(FindExplicitReferencesTest, All) {
+  std::pair Cases[] =
+  {
+  // Simple expressions.
+  {R"cpp(
+int global;
+int func();
+void foo(int param) {
+  $0^global = $1^param + $2^func();
+}
+)cpp",
+   "0: targets = {global}\n"
+   "1: targets = {param}\n"
+   "2: targets = {func}\n"},
+  {R"cpp(
+struct X { int a; };
+void foo(X x) {
+  $0^x.$1^a = 10;
+}
+)cpp",
+   "0: targets = {x}\n"
+   "1: targets = {X::a}\n"},
+  // Namespaces and aliases.
+  {R"cpp(
+  namespace ns {}
+  namespace alias = ns;
+  void foo() {
+using namespace $0^ns;
+using namespace $1^alias;
+  }
+)cpp",
+   "0: targets = {ns}\n"
+   "1: targets = {alias}\n"},
+  // Using declarations.
+  {R"cpp(
+  namespace ns { int global; }
+  void foo() {
+using $0^ns::$1^global;
+  }
+)cpp",
+   "0: targets = {ns}\n"
+   "1: targets = {ns::global}, qualifier = 'ns::'\n"},
+  // Simple types.
+  {R"cpp(
+ struct Struct { int a; };
+ using Typedef = int;
+ void foo() {
+   $0^Struct x;
+   $1^Typedef y;
+   static_cast<$2^Struct*>(0);
+ }
+   )cpp",
+   "0: targets = {Struct}\n"
+   "1: targets = {Typedef}\n"
+   "2: targets = {Struct}\n"},
+  // Name qualifiers.
+  {R"cpp(
+ namespace a { namespace b { struct S { typedef int type; }; } }
+ void foo() {
+   $0^a::$1^b::$2^S x;
+   using namespace $3^a::$4^b;
+   $5^S::$6^type y;
+ }
+)cpp",
+   "0: targets = {a}\n"
+   "1: targets = {a::b}, qualifier = 'a::'\n"
+   "2: targets = {a::b::S}, qualifier = 'a::b::'\n"
+   "3: targets = 

[PATCH] D67826: [clangd] A helper to find explicit references and their names

2019-09-23 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Added some tests too. More tests for dependent constructs are still missing, 
but please take a look at what we have for now.




Comment at: clang-tools-extra/clangd/FindTarget.cpp:373
+   DeclRelation::TemplateInstantiation)) &&
+ "namedTarget handles templates on its own");
+  auto Decls = allTargetDecls(N);

kadircet wrote:
> what is `namedTarget` ?
Used to be called this before. Fixed, thanks.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:376
+
+  // We prefer to return template instantiation, but fallback to template
+  // pattern if instantiation is not available.

kadircet wrote:
> can we simplify this by populating two vectors, Instantiations and Patterns, 
> and then returning the patterns iff instantiations are empty?
Did something very similar. PTAL.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:381
+  llvm::find_if(Decls, [&](std::pair D) {
+if (D.second & ~Mask)
+  return false;

kadircet wrote:
> why do we discard aliases(specifically underlying decls) ? for example if we 
> have `vector` I believe decl(`template<> std::vector`) will be 
> marked with both TemplateInst and Underlying right ?
For `^vector`, we get `vector(TemplateInstantiation)` and 
`vector(TemplatePattern)`.
No `Underlying`.

Added a relevant test-case.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:391
+  for (auto  : Decls) {
+if (D.second & ~Mask)
+  continue;

kadircet wrote:
> same here for ignoring underlying decls
As mentioned in the previous comment, we want to discard underlying. Underlying 
decl was not written in the source code, therefore should not be returned by 
this function.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:399
+Optional refInDecl(const Decl *D) {
+  struct Visitor : ConstDeclVisitor {
+llvm::Optional Ref;

kadircet wrote:
> these three(usingdirective,using,namespacealias) decls are the only ones that 
> can have a nestednamespecifier.
> 
> Are we sure these are the only ones that can reference a decl? For example 
> what about a `ConstructorDecl` with initializers referencing `FieldDecl`s, I 
> believe this function should rather return multiple locations in such cases.
This function is non-recursive and `ConstructorInitializer` is a separate node 
under `ConsturctorDecl`.
Any reference to fields are owned (and reported when `ConstructorInitializer` 
is visited)

There might be more decls that I missed here, though, hopefully we'll find and 
add them later.

It's a bit hard to get all cases on the first try.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:409
+void VisitUsingDecl(const UsingDecl *D) {
+  Ref = ReferenceLoc{D->getQualifierLoc(), D->getUsingLoc(),
+ explicitReferenceTargets(DynTypedNode::create(*D),

kadircet wrote:
> I think `getUsingLoc` will return the location for `using` keyword, not the 
> name location. Maybe use `getLocation` ?
Thanks for spotting this! This was supposed to be a temporary placeholder until 
I figure out a proper location.
But I forgot about it.

Fixed and added a test.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:426
+
+Optional refInExpr(const Expr *E) {
+  struct Visitor : ConstStmtVisitor {

kadircet wrote:
> again I believe this list is non-exhaustive, e.g. designatedinitilaizers. and 
> again this also needs to return a vector instead.
Added a FIXME to add more exhaustive handling.
I'll make sure to fix it soon, but would want to first land non-exhaustive 
version.

I would try avoiding returning more than one element here. For designated 
initializers we seem to have multiple designators. Since this function is 
non-recursive, it should not return those.

Instead we would require our clients (i.e. our visitor) to call a separate 
function for each of the designators.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:432
+  Ref = ReferenceLoc{
+  E->getQualifierLoc(), E->getNameInfo().getLoc(), {E->getDecl()}};
+}

kadircet wrote:
> I believe it is better to return `getFoundDecl` then `getDecl`, the former 
> respects using declarations.
Good point. Done. Added a test too.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:548
+  bool TraverseElaboratedTypeLoc(ElaboratedTypeLoc L) {
+// ElaboratedTypeLoc will reports information for its inner type loc.
+// Otherwise we loose information about inner types loc's qualifier.

kadircet wrote:
> why not just traversenestednamespecifier and `visitNode(L)` instead of 
> calling the base::traverse ?
To avoid re-implementing the traversal logic. `Base::Traverse` does exactly 
that, we shouldn't re-implement traversal 

[PATCH] D67919: [Diagnostics] Warn if enumeration type mismatch in conditional expression

2019-09-23 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 created this revision.
xbolva00 added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Useful warning
- GCC compatibility


Repository:
  rC Clang

https://reviews.llvm.org/D67919

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp


Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -11256,6 +11256,34 @@
   return true;
 }
 
+static void checkConditionalWithEnumTypes(Sema , SourceLocation Loc,
+  Expr *LHS, Expr *RHS) {
+  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
+  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
+
+  const EnumType *LHSEnumType = LHSStrippedType->getAs();
+  if (!LHSEnumType)
+return;
+  const EnumType *RHSEnumType = RHSStrippedType->getAs();
+  if (!RHSEnumType)
+return;
+
+  // Ignore anonymous enums.
+  if (!LHSEnumType->getDecl()->getIdentifier() &&
+  !LHSEnumType->getDecl()->getTypedefNameForAnonDecl())
+return;
+  if (!RHSEnumType->getDecl()->getIdentifier() &&
+  !RHSEnumType->getDecl()->getTypedefNameForAnonDecl())
+return;
+
+  if (S.Context.hasSameUnqualifiedType(LHSStrippedType, RHSStrippedType))
+return;
+
+  S.Diag(Loc, diag::warn_conditional_mixed_enum_types)
+  << LHSStrippedType << RHSStrippedType << LHS->getSourceRange()
+  << RHS->getSourceRange();
+}
+
 static void DiagnoseIntInBoolContext(Sema , Expr *E) {
   E = E->IgnoreParenImpCasts();
   SourceLocation ExprLoc = E->getExprLoc();
@@ -11754,6 +11782,8 @@
   bool Suspicious = false;
   CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious);
   CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious);
+  checkConditionalWithEnumTypes(S, E->getBeginLoc(), E->getTrueExpr(),
+E->getFalseExpr());
 
   if (T->isBooleanType())
 DiagnoseIntInBoolContext(S, E);
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6156,6 +6156,10 @@
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,
   InGroup;
+def warn_conditional_mixed_enum_types : Warning<
+  "enumeration type mismatch in conditional expression"
+  "%diff{ ($ and $)|}0,1">,
+  InGroup;
 def warn_comparison_of_mixed_enum_types_switch : Warning<
   "comparison of two values with different enumeration types in switch 
statement"
   "%diff{ ($ and $)|}0,1">,


Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -11256,6 +11256,34 @@
   return true;
 }
 
+static void checkConditionalWithEnumTypes(Sema , SourceLocation Loc,
+  Expr *LHS, Expr *RHS) {
+  QualType LHSStrippedType = LHS->IgnoreParenImpCasts()->getType();
+  QualType RHSStrippedType = RHS->IgnoreParenImpCasts()->getType();
+
+  const EnumType *LHSEnumType = LHSStrippedType->getAs();
+  if (!LHSEnumType)
+return;
+  const EnumType *RHSEnumType = RHSStrippedType->getAs();
+  if (!RHSEnumType)
+return;
+
+  // Ignore anonymous enums.
+  if (!LHSEnumType->getDecl()->getIdentifier() &&
+  !LHSEnumType->getDecl()->getTypedefNameForAnonDecl())
+return;
+  if (!RHSEnumType->getDecl()->getIdentifier() &&
+  !RHSEnumType->getDecl()->getTypedefNameForAnonDecl())
+return;
+
+  if (S.Context.hasSameUnqualifiedType(LHSStrippedType, RHSStrippedType))
+return;
+
+  S.Diag(Loc, diag::warn_conditional_mixed_enum_types)
+  << LHSStrippedType << RHSStrippedType << LHS->getSourceRange()
+  << RHS->getSourceRange();
+}
+
 static void DiagnoseIntInBoolContext(Sema , Expr *E) {
   E = E->IgnoreParenImpCasts();
   SourceLocation ExprLoc = E->getExprLoc();
@@ -11754,6 +11782,8 @@
   bool Suspicious = false;
   CheckConditionalOperand(S, E->getTrueExpr(), T, CC, Suspicious);
   CheckConditionalOperand(S, E->getFalseExpr(), T, CC, Suspicious);
+  checkConditionalWithEnumTypes(S, E->getBeginLoc(), E->getTrueExpr(),
+E->getFalseExpr());
 
   if (T->isBooleanType())
 DiagnoseIntInBoolContext(S, E);
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6156,6 +6156,10 @@
   "comparison of two values with different enumeration types"
   "%diff{ ($ and $)|}0,1">,
   InGroup;
+def warn_conditional_mixed_enum_types : Warning<
+  "enumeration type mismatch in conditional expression"
+  "%diff{ ($ and $)|}0,1">,
+  InGroup;
 def warn_comparison_of_mixed_enum_types_switch : Warning<
   "comparison of two values 

[PATCH] D67837: [CUDA][HIP] Fix assertion in Sema::markKnownEmitted with -fopenmp

2019-09-23 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 221341.
yaxunl added a comment.

revised by John's comments


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

https://reviews.llvm.org/D67837

Files:
  lib/Sema/Sema.cpp
  test/SemaCUDA/openmp-static-func.cu


Index: test/SemaCUDA/openmp-static-func.cu
===
--- /dev/null
+++ test/SemaCUDA/openmp-static-func.cu
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:-verify -fopenmp %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:-verify -fopenmp -x hip %s
+// expected-no-diagnostics
+
+// Tests there is no assertion in Sema::markKnownEmitted when fopenmp is used
+// with CUDA/HIP host compilation.
+
+static void f() {}
+
+static void g() { f(); }
+
+static void h() { g(); }
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -1503,8 +1503,12 @@
 const llvm::function_ref IsKnownEmitted) {
   // Nothing to do if we already know that FD is emitted.
   if (IsKnownEmitted(S, OrigCallee)) {
-assert(!S.DeviceCallGraph.count(OrigCallee));
-return;
+// CUDA/HIP and OpenMP both put functions in DeviceCallGraph. A function
+// not sure to be emitted by one language may be found sure to be emitted
+// by another language. In that case, we will iterate the call graph and
+// mark all the callees. Otherwise, do nothing.
+if (!S.DeviceCallGraph.count(OrigCallee))
+  return;
   }
 
   // We've just discovered that OrigCallee is known-emitted.  Walk our call
@@ -1520,8 +1524,6 @@
   Seen.insert(OrigCallee);
   while (!Worklist.empty()) {
 CallInfo C = Worklist.pop_back_val();
-assert(!IsKnownEmitted(S, C.Callee) &&
-   "Worklist should not contain known-emitted functions.");
 S.DeviceKnownEmittedFns[C.Callee] = {C.Caller, C.Loc};
 emitDeferredDiags(S, C.Callee, C.Caller);
 


Index: test/SemaCUDA/openmp-static-func.cu
===
--- /dev/null
+++ test/SemaCUDA/openmp-static-func.cu
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:-verify -fopenmp %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:-verify -fopenmp -x hip %s
+// expected-no-diagnostics
+
+// Tests there is no assertion in Sema::markKnownEmitted when fopenmp is used
+// with CUDA/HIP host compilation.
+
+static void f() {}
+
+static void g() { f(); }
+
+static void h() { g(); }
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -1503,8 +1503,12 @@
 const llvm::function_ref IsKnownEmitted) {
   // Nothing to do if we already know that FD is emitted.
   if (IsKnownEmitted(S, OrigCallee)) {
-assert(!S.DeviceCallGraph.count(OrigCallee));
-return;
+// CUDA/HIP and OpenMP both put functions in DeviceCallGraph. A function
+// not sure to be emitted by one language may be found sure to be emitted
+// by another language. In that case, we will iterate the call graph and
+// mark all the callees. Otherwise, do nothing.
+if (!S.DeviceCallGraph.count(OrigCallee))
+  return;
   }
 
   // We've just discovered that OrigCallee is known-emitted.  Walk our call
@@ -1520,8 +1524,6 @@
   Seen.insert(OrigCallee);
   while (!Worklist.empty()) {
 CallInfo C = Worklist.pop_back_val();
-assert(!IsKnownEmitted(S, C.Callee) &&
-   "Worklist should not contain known-emitted functions.");
 S.DeviceKnownEmittedFns[C.Callee] = {C.Caller, C.Loc};
 emitDeferredDiags(S, C.Callee, C.Caller);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63640: [clang] Improve Serialization/Imporing of APValues

2019-09-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/AST/APValue.h:537-540
+private:
+  void setLValueEmptyPath(LValueBase B, const CharUnits , unsigned Size,
+  bool OnePastTheEnd, bool IsNullPtr);
+  LValuePathEntry *getLValuePathPtr();

Rather than add this private bit in the middle of the public interface, you can 
move this to the existing private parts.



Comment at: clang/include/clang/AST/APValue.h:618
   }
+  const CXXRecordDecl **getMemberPointerPathPtr();
 };

We're horribly inconsistent in this class, but because the other private member 
functions go with it, this should probably be `GetMemberPointerPathPtr()`. 
Maybe rename the get/setLValue methods from above as well?



Comment at: clang/include/clang/AST/APValue.h:512
   }
-  void setVector(const APValue *E, unsigned N) {
+  void ReserveVector(unsigned N) {
 assert(isVector() && "Invalid accessor");

aaron.ballman wrote:
> `reserveVector` per naming conventions
This was marked as done but is still an issue.



Comment at: clang/include/clang/AST/ASTContext.h:275
-  /// Used to cleanups APValues stored in the AST.
-  mutable llvm::SmallVector APValueCleanups;
-

Tyker wrote:
> aaron.ballman wrote:
> > Why are you getting rid of this? It seems like we would still want these 
> > cleaned up.
> when i added APValueCleanups i wasn't aware that there were a generic system 
> to handle this. but with this patch APValue a cleaned up using the generic 
> ASTContext::addDestruction.
I don't see any new calls to `addDestruction()` though. Have I missed something?



Comment at: clang/include/clang/AST/TextNodeDumper.h:149
 
-  const ASTContext *Context;
+  const ASTContext *Context = nullptr;
 

Tyker wrote:
> aaron.ballman wrote:
> > Good catch -- this pointed out a bug in the class that I've fixed in 
> > r372323, so you'll need to rebase.
> i took a look at the revision. there is a big difference is the quality of 
> output between APValue::dump and APValue::printPretty. i think it is possible 
> to come quite close to printPretty's output even without the ASTContext. this 
> would require having a default PrintingPolicy and improving dump
> 
> in this patch i was relying on the -ast-dump output for testing. i would need 
> to find an other testing strategy or make the improvement to APValue::dump 
> first.
> there is a big difference is the quality of output between APValue::dump and 
> APValue::printPretty.

Yes, there is.

> i think it is possible to come quite close to printPretty's output even 
> without the ASTContext. this would require having a default PrintingPolicy 
> and improving dump

That would be much-appreciated! When I looked at it, it seemed like it may not 
be plausible because `Stmt` does not track which `ASTContext` it is associated 
with the same way that `Decl` does, and changing that seemed likely to cause a 
huge amount of interface churn.

> in this patch i was relying on the -ast-dump output for testing. i would need 
> to find an other testing strategy or make the improvement to APValue::dump 
> first.

The issue resolved by r372323 was that we would crash on certain kinds of AST 
dumps. Specifically, the default AST dumper is often used during a debugging 
session to dump AST node information within the debugger. It was trivial to get 
that to crash before r372323, but with that revision, we no longer crash but 
get slightly uglier output (which is acceptable because it's still 
human-readable output).

I'm sorry for causing extra pain for you here, but I didn't want the fix from 
this review to accidentally become an enshrined part of the API because it's 
very easy to forget about this use case when working on AST dumping 
functionality.



Comment at: clang/lib/AST/APValue.cpp:748
 
+APValue::LValuePathEntry *APValue::getLValuePathPtr() {
+  return ((LV *)(char *)Data.buffer)->getPath();

Tyker wrote:
> aaron.ballman wrote:
> > Can this function be marked `const`?
> this function gives access to non-const internal data. this function is 
> private so the impact is quite limited.
That makes it harder to call this helper from a constant context. I think there 
should be overloads (one `const`, one not) to handle this.



Comment at: clang/test/ASTMerge/APValue/APValue.cpp:1
+
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -emit-pch %s -o %t.pch

Can remove the spurious newline. Also, it seems this file was added with svn 
properties, was that intentional (we don't usually do that, FWIW)?



Comment at: clang/test/ASTMerge/APValue/APValue.cpp:2-3
+
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -emit-pch %s -o %t.pch
+// RUN: %clang_cc1 -x c++ -std=gnu++2a -ast-merge %t.pch -ast-dump-all | 
FileCheck %s
+

no need for `-x c++` is 

[PATCH] D67897: Fix __is_signed builtin

2019-09-23 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver marked an inline comment as done.
zoecarver added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:1165
   Note that this currently returns true for enumeration types if the underlying
-  type is signed, and returns false for floating-point types, in violation of
-  the requirements for ``std::is_signed``. This behavior is likely to change in
-  a future version of Clang.
+  type is signed, and returns true for floating-point types.
 * ``__is_standard_layout`` (C++, GNU, Microsoft, Embarcadero)

rsmith wrote:
> rsmith wrote:
> > I'd just drop the second half of this sentence, and keep the "likely to 
> > change" warning for the non-conformance for enumeration types until that's 
> > fixed. (We already have an introductory sentence that says we follow the 
> > standard-specified behavior for traits marked (C++) unless otherwise 
> > specified.)
> Now that this does the standard thing, you can delete this text entirely, or 
> add a "before Clang 10, returned true for enumeration types if the underlying 
> type was signed, and returned false for floating-point types".
I'll add that text before committing. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67897



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


[PATCH] D67385: Pass -mcmodel to LTO plugin

2019-09-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D67385#1679127 , @khchen wrote:

> @tejohnson when I run the `clang -flto -Wl,-plugin-opt=-help` command, it 
> shows the
>
>   --code-model=   - Choose code model
>  =tiny-   Tiny code model
>  =small   -   Small code model
>  =kernel  -   Kernel code model
>  =medium  -   Medium code model
>  =large   -   Large code model
>
>   so I think the clang driver need to pass this info to LTO codegen, does it 
> make sense?


This is an internal LLVM option, that can be used to override the mcmodel set 
in the Module IR when the code was compiled into Bitcode. I don't think it 
makes sense to have the clang driver automatically set this internal option for 
the plugin, overridding what was set when the code was compiled, it can be set 
manually via a -plugin-opt if one needs to override for debugging etc. Why 
isn't the code model module flag in the Bitcode sufficient for your LTO case?


Repository:
  rC Clang

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

https://reviews.llvm.org/D67385



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


[PATCH] D67385: Pass -mcmodel to LTO plugin

2019-09-23 Thread Kuan Hsu Chen via Phabricator via cfe-commits
khchen added a comment.

@tejohnson when I run the `clang -flto -Wl,-plugin-opt=-help` command, it shows 
the

  --code-model=   - Choose code model
=tiny-   Tiny code model
=small   -   Small code model
=kernel  -   Kernel code model
=medium  -   Medium code model
=large   -   Large code model

so I think the clang driver need to pass this info to LTO codegen, does it make 
sense?


Repository:
  rC Clang

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

https://reviews.llvm.org/D67385



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


[clang-tools-extra] r372617 - [clangd] Simplify the callside of URI::resolve, NFC.

2019-09-23 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Sep 23 07:39:37 2019
New Revision: 372617

URL: http://llvm.org/viewvc/llvm-project?rev=372617=rev
Log:
[clangd] Simplify the callside of URI::resolve, NFC.

Summary:
- Add a overrloded URI::resolve, which accepts a string URI;
- also fixed some callside that don't check the error;

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/FindSymbols.cpp
clang-tools-extra/trunk/clangd/IncludeFixer.cpp
clang-tools-extra/trunk/clangd/URI.cpp
clang-tools-extra/trunk/clangd/URI.h
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=372617=372616=372617=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon Sep 23 07:39:37 2019
@@ -318,11 +318,8 @@ struct CodeCompletionBuilder {
 // Turn absolute path into a literal string that can be #included.
 auto Inserted = [&](llvm::StringRef Header)
 -> llvm::Expected> {
-  auto DeclaringURI =
-  URI::parse(C.IndexResult->CanonicalDeclaration.FileURI);
-  if (!DeclaringURI)
-return DeclaringURI.takeError();
-  auto ResolvedDeclaring = URI::resolve(*DeclaringURI, FileName);
+  auto ResolvedDeclaring =
+  URI::resolve(C.IndexResult->CanonicalDeclaration.FileURI, FileName);
   if (!ResolvedDeclaring)
 return ResolvedDeclaring.takeError();
   auto ResolvedInserted = toHeaderFile(Header, FileName);

Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=372617=372616=372617=diff
==
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original)
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Mon Sep 23 07:39:37 2019
@@ -43,18 +43,11 @@ llvm::Expected symbolToLocatio
   llvm::StringRef HintPath) {
   // Prefer the definition over e.g. a function declaration in a header
   auto  = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
-  auto Uri = URI::parse(CD.FileURI);
-  if (!Uri) {
-return llvm::make_error(
-formatv("Could not parse URI '{0}' for symbol '{1}'.", CD.FileURI,
-Sym.Name),
-llvm::inconvertibleErrorCode());
-  }
-  auto Path = URI::resolve(*Uri, HintPath);
+  auto Path = URI::resolve(CD.FileURI, HintPath);
   if (!Path) {
 return llvm::make_error(
-formatv("Could not resolve path for URI '{0}' for symbol '{1}'.",
-Uri->toString(), Sym.Name),
+formatv("Could not resolve path for symbol '{0}': {1}",
+Sym.Name, llvm::toString(Path.takeError())),
 llvm::inconvertibleErrorCode());
   }
   Location L;

Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=372617=372616=372617=diff
==
--- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original)
+++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Mon Sep 23 07:39:37 2019
@@ -144,10 +144,8 @@ std::vector IncludeFixer::fixIncomp
 std::vector IncludeFixer::fixesForSymbols(const SymbolSlab ) const {
   auto Inserted = [&](const Symbol , llvm::StringRef Header)
   -> llvm::Expected> {
-auto DeclaringURI = URI::parse(Sym.CanonicalDeclaration.FileURI);
-if (!DeclaringURI)
-  return DeclaringURI.takeError();
-auto ResolvedDeclaring = URI::resolve(*DeclaringURI, File);
+auto ResolvedDeclaring =
+URI::resolve(Sym.CanonicalDeclaration.FileURI, File);
 if (!ResolvedDeclaring)
   return ResolvedDeclaring.takeError();
 auto ResolvedInserted = toHeaderFile(Header, File);

Modified: clang-tools-extra/trunk/clangd/URI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/URI.cpp?rev=372617=372616=372617=diff
==
--- clang-tools-extra/trunk/clangd/URI.cpp (original)
+++ clang-tools-extra/trunk/clangd/URI.cpp Mon Sep 23 07:39:37 2019
@@ -183,6 +183,17 @@ llvm::Expected URI::parse(llvm::Str
   return U;
 }
 
+llvm::Expected URI::resolve(llvm::StringRef FileURI,
+ llvm::StringRef HintPath) {
+  auto Uri = URI::parse(FileURI);
+  if (!Uri)
+return Uri.takeError();
+  auto Path = URI::resolve(*Uri, 

[PATCH] D67916: [clangd] Simplify the callside of URI::resolve, NFC.

2019-09-23 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372617: [clangd] Simplify the callside of URI::resolve, NFC. 
(authored by hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67916?vs=221326=221330#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D67916

Files:
  clang-tools-extra/trunk/clangd/CodeComplete.cpp
  clang-tools-extra/trunk/clangd/FindSymbols.cpp
  clang-tools-extra/trunk/clangd/IncludeFixer.cpp
  clang-tools-extra/trunk/clangd/URI.cpp
  clang-tools-extra/trunk/clangd/URI.h
  clang-tools-extra/trunk/clangd/index/Background.cpp
  clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.cpp

Index: clang-tools-extra/trunk/clangd/CodeComplete.cpp
===
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp
@@ -318,11 +318,8 @@
 // Turn absolute path into a literal string that can be #included.
 auto Inserted = [&](llvm::StringRef Header)
 -> llvm::Expected> {
-  auto DeclaringURI =
-  URI::parse(C.IndexResult->CanonicalDeclaration.FileURI);
-  if (!DeclaringURI)
-return DeclaringURI.takeError();
-  auto ResolvedDeclaring = URI::resolve(*DeclaringURI, FileName);
+  auto ResolvedDeclaring =
+  URI::resolve(C.IndexResult->CanonicalDeclaration.FileURI, FileName);
   if (!ResolvedDeclaring)
 return ResolvedDeclaring.takeError();
   auto ResolvedInserted = toHeaderFile(Header, FileName);
Index: clang-tools-extra/trunk/clangd/index/Background.cpp
===
--- clang-tools-extra/trunk/clangd/index/Background.cpp
+++ clang-tools-extra/trunk/clangd/index/Background.cpp
@@ -69,13 +69,7 @@
   llvm::StringRef resolve(llvm::StringRef FileURI) {
 auto I = URIToPathCache.try_emplace(FileURI);
 if (I.second) {
-  auto U = URI::parse(FileURI);
-  if (!U) {
-elog("Failed to parse URI {0}: {1}", FileURI, U.takeError());
-assert(false && "Failed to parse URI");
-return "";
-  }
-  auto Path = URI::resolve(*U, HintPath);
+  auto Path = URI::resolve(FileURI, HintPath);
   if (!Path) {
 elog("Failed to resolve URI {0}: {1}", FileURI, Path.takeError());
 assert(false && "Failed to resolve URI");
Index: clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.cpp
===
--- clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.cpp
+++ clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.cpp
@@ -24,16 +24,6 @@
 namespace clangd {
 namespace {
 
-llvm::Optional uriToAbsolutePath(llvm::StringRef URI, PathRef HintPath) {
-  auto U = URI::parse(URI);
-  if (!U)
-return llvm::None;
-  auto AbsolutePath = URI::resolve(*U, HintPath);
-  if (!AbsolutePath)
-return llvm::None;
-  return *AbsolutePath;
-}
-
 /// A helper class to cache BackgroundIndexStorage operations and keep the
 /// inverse dependency mapping.
 class BackgroundIndexLoader {
@@ -79,9 +69,11 @@
 
   LS.Shard = std::move(Shard);
   for (const auto  : *LS.Shard->Sources) {
-auto AbsPath = uriToAbsolutePath(It.getKey(), StartSourceFile);
-if (!AbsPath)
+auto AbsPath = URI::resolve(It.getKey(), StartSourceFile);
+if (!AbsPath) {
+  elog("Failed to resolve URI: {0}", AbsPath.takeError());
   continue;
+}
 // A shard contains only edges for non main-file sources.
 if (*AbsPath != StartSourceFile) {
   Edges.push_back(*AbsPath);
Index: clang-tools-extra/trunk/clangd/URI.cpp
===
--- clang-tools-extra/trunk/clangd/URI.cpp
+++ clang-tools-extra/trunk/clangd/URI.cpp
@@ -183,6 +183,17 @@
   return U;
 }
 
+llvm::Expected URI::resolve(llvm::StringRef FileURI,
+ llvm::StringRef HintPath) {
+  auto Uri = URI::parse(FileURI);
+  if (!Uri)
+return Uri.takeError();
+  auto Path = URI::resolve(*Uri, HintPath);
+  if (!Path)
+return Path.takeError();
+  return *Path;
+}
+
 llvm::Expected URI::create(llvm::StringRef AbsolutePath,
 llvm::StringRef Scheme) {
   if (!llvm::sys::path::is_absolute(AbsolutePath))
Index: clang-tools-extra/trunk/clangd/FindSymbols.cpp
===
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp
@@ -43,18 +43,11 @@
   llvm::StringRef HintPath) {
   // Prefer the definition over e.g. a function declaration in a header
   auto  = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
-  auto Uri = URI::parse(CD.FileURI);
-  if (!Uri) 

[PATCH] D67916: [clangd] Simplify the callside of URI::resolve, NFC.

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

LGTM, thanks!




Comment at: clang-tools-extra/clangd/FindSymbols.cpp:48
   if (!Path) {
 return llvm::make_error(
+formatv("Could not resolve path for URI '{0}' for symbol '{1}': {2}",

hokein wrote:
> kadircet wrote:
> > `return make_string_error(...` ?
> > 
> > Also the error string regarding `CD.FileURI` should be contained in 
> > `Path.takeError` maybe just print:
> > `Could not resolve path for symbol '{0}': {1}, Sym.Name, Path.takeError()` ?
> `make_string_error` is an internal helper in `URI.cpp` only.
ah I see, when I searched for `make_string_error`, there were too many 
references so I assumed it was a generic helper, but apparently every file has 
an internal implementation ...

Whatever that can be an adventure for another day...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67916



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


[PATCH] D67916: [clangd] Simplify the callside of URI::resolve, NFC.

2019-09-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:48
   if (!Path) {
 return llvm::make_error(
+formatv("Could not resolve path for URI '{0}' for symbol '{1}': {2}",

kadircet wrote:
> `return make_string_error(...` ?
> 
> Also the error string regarding `CD.FileURI` should be contained in 
> `Path.takeError` maybe just print:
> `Could not resolve path for symbol '{0}': {1}, Sym.Name, Path.takeError()` ?
`make_string_error` is an internal helper in `URI.cpp` only.



Comment at: clang-tools-extra/clangd/URI.cpp:190
+  if (!Uri)
+return make_string_error(llvm::toString(Uri.takeError()));
+  auto Path = URI::resolve(*Uri, HintPath);

kadircet wrote:
> why not just `Uri.takeError` ?
> 
> same below for `Path.takeError`
good point. The code was changed back and forth a few times.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67916



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


[PATCH] D67916: [clangd] Simplify the callside of URI::resolve, NFC.

2019-09-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 221326.
hokein marked 7 inline comments as done.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67916

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/URI.cpp
  clang-tools-extra/clangd/URI.h
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp

Index: clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
===
--- clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
+++ clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
@@ -24,16 +24,6 @@
 namespace clangd {
 namespace {
 
-llvm::Optional uriToAbsolutePath(llvm::StringRef URI, PathRef HintPath) {
-  auto U = URI::parse(URI);
-  if (!U)
-return llvm::None;
-  auto AbsolutePath = URI::resolve(*U, HintPath);
-  if (!AbsolutePath)
-return llvm::None;
-  return *AbsolutePath;
-}
-
 /// A helper class to cache BackgroundIndexStorage operations and keep the
 /// inverse dependency mapping.
 class BackgroundIndexLoader {
@@ -79,9 +69,11 @@
 
   LS.Shard = std::move(Shard);
   for (const auto  : *LS.Shard->Sources) {
-auto AbsPath = uriToAbsolutePath(It.getKey(), StartSourceFile);
-if (!AbsPath)
+auto AbsPath = URI::resolve(It.getKey(), StartSourceFile);
+if (!AbsPath) {
+  elog("Failed to resolve URI: {0}", AbsPath.takeError());
   continue;
+}
 // A shard contains only edges for non main-file sources.
 if (*AbsPath != StartSourceFile) {
   Edges.push_back(*AbsPath);
Index: clang-tools-extra/clangd/index/Background.cpp
===
--- clang-tools-extra/clangd/index/Background.cpp
+++ clang-tools-extra/clangd/index/Background.cpp
@@ -69,13 +69,7 @@
   llvm::StringRef resolve(llvm::StringRef FileURI) {
 auto I = URIToPathCache.try_emplace(FileURI);
 if (I.second) {
-  auto U = URI::parse(FileURI);
-  if (!U) {
-elog("Failed to parse URI {0}: {1}", FileURI, U.takeError());
-assert(false && "Failed to parse URI");
-return "";
-  }
-  auto Path = URI::resolve(*U, HintPath);
+  auto Path = URI::resolve(FileURI, HintPath);
   if (!Path) {
 elog("Failed to resolve URI {0}: {1}", FileURI, Path.takeError());
 assert(false && "Failed to resolve URI");
Index: clang-tools-extra/clangd/URI.h
===
--- clang-tools-extra/clangd/URI.h
+++ clang-tools-extra/clangd/URI.h
@@ -63,6 +63,10 @@
   static llvm::Expected resolve(const URI ,
  llvm::StringRef HintPath = "");
 
+  /// Same as above, in addition it parses the \p FileURI using URI::parse.
+  static llvm::Expected resolve(llvm::StringRef FileURI,
+ llvm::StringRef HintPath = "");
+
   /// Resolves \p AbsPath into a canonical path of its URI, by converting
   /// \p AbsPath to URI and resolving the URI to get th canonical path.
   /// This ensures that paths with the same URI are resolved into consistent
Index: clang-tools-extra/clangd/URI.cpp
===
--- clang-tools-extra/clangd/URI.cpp
+++ clang-tools-extra/clangd/URI.cpp
@@ -183,6 +183,17 @@
   return U;
 }
 
+llvm::Expected URI::resolve(llvm::StringRef FileURI,
+ llvm::StringRef HintPath) {
+  auto Uri = URI::parse(FileURI);
+  if (!Uri)
+return Uri.takeError();
+  auto Path = URI::resolve(*Uri, HintPath);
+  if (!Path)
+return Path.takeError();
+  return *Path;
+}
+
 llvm::Expected URI::create(llvm::StringRef AbsolutePath,
 llvm::StringRef Scheme) {
   if (!llvm::sys::path::is_absolute(AbsolutePath))
Index: clang-tools-extra/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -144,10 +144,8 @@
 std::vector IncludeFixer::fixesForSymbols(const SymbolSlab ) const {
   auto Inserted = [&](const Symbol , llvm::StringRef Header)
   -> llvm::Expected> {
-auto DeclaringURI = URI::parse(Sym.CanonicalDeclaration.FileURI);
-if (!DeclaringURI)
-  return DeclaringURI.takeError();
-auto ResolvedDeclaring = URI::resolve(*DeclaringURI, File);
+auto ResolvedDeclaring =
+URI::resolve(Sym.CanonicalDeclaration.FileURI, File);
 if (!ResolvedDeclaring)
   return ResolvedDeclaring.takeError();
 auto ResolvedInserted = toHeaderFile(Header, File);
Index: clang-tools-extra/clangd/FindSymbols.cpp

r372614 - [docs] Fix some typos in InternalsManual

2019-09-23 Thread Sven van Haastregt via cfe-commits
Author: svenvh
Date: Mon Sep 23 07:24:29 2019
New Revision: 372614

URL: http://llvm.org/viewvc/llvm-project?rev=372614=rev
Log:
[docs] Fix some typos in InternalsManual

Modified:
cfe/trunk/docs/InternalsManual.rst

Modified: cfe/trunk/docs/InternalsManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/InternalsManual.rst?rev=372614=372613=372614=diff
==
--- cfe/trunk/docs/InternalsManual.rst (original)
+++ cfe/trunk/docs/InternalsManual.rst Mon Sep 23 07:24:29 2019
@@ -859,7 +859,7 @@ benefits:
 
 There are unfortunately exceptions to this general approach, such as:
 
-  * A the first declaration of a redeclarable entity maintains a pointer to the
+  * The first declaration of a redeclarable entity maintains a pointer to the
 most recent declaration of that entity, which naturally needs to change as
 more declarations are parsed.
   * Name lookup tables in declaration contexts change after the namespace
@@ -1913,7 +1913,7 @@ declarations like enums, classes, etc. i
 Therefore, we filter the lookup results and consider only those which have the
 same visibility as the declaration we currently import.
 
-We consider two declarations in two anonymous namsepaces to have the same
+We consider two declarations in two anonymous namespaces to have the same
 visibility only if they are imported from the same AST context.
 
 Strategies to Handle Conflicting Names
@@ -2134,7 +2134,7 @@ about them.
 
 Finally, this is not just a problem for semantic analysis.  The code generator
 and other clients have to be able to fold constants (e.g., to initialize global
-variables) and has to handle a superset of what C99 allows.  Further, these
+variables) and have to handle a superset of what C99 allows.  Further, these
 clients can benefit from extended information.  For example, we know that
 "``foo() || 1``" always evaluates to ``true``, but we can't replace the
 expression with ``true`` because it has side effects.


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


[PATCH] D67888: [clang-format] NFC clang-format the clang-format unit tests

2019-09-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added a comment.
This revision is now accepted and ready to land.

Thanks!


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

https://reviews.llvm.org/D67888



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


  1   2   >