[PATCH] D48346: [X86] Rewrite the add/mul/or/and reduction intrinsics to make better use of other intrinsics and remove undef shuffle indices.

2018-06-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added a reviewer: RKSimon.
Herald added a subscriber: cfe-commits.

Similar to what was done to max/min recently.

These already reduced the vector width to 256 and 128 bit as we go unlike the 
original max/min code.


Repository:
  rC Clang

https://reviews.llvm.org/D48346

Files:
  lib/Headers/avx512fintrin.h
  test/CodeGen/avx512-reduceIntrin.c

Index: test/CodeGen/avx512-reduceIntrin.c
===
--- test/CodeGen/avx512-reduceIntrin.c
+++ test/CodeGen/avx512-reduceIntrin.c
@@ -3,408 +3,477 @@
 #include 
 
 long long test_mm512_reduce_add_epi64(__m512i __W){
-  // CHECK: %shuffle.i = shufflevector <8 x i64> %__W, <8 x i64> undef, <4 x i32> 
-  // CHECK: %shuffle1.i = shufflevector <8 x i64> %__W, <8 x i64> undef, <4 x i32> 
-  // CHECK: %add.i = add <4 x i64> %shuffle.i, %shuffle1.i
-  // CHECK: %shuffle2.i = shufflevector <4 x i64> %add.i, <4 x i64> undef, <2 x i32> 
-  // CHECK: %shuffle3.i = shufflevector <4 x i64> %add.i, <4 x i64> undef, <2 x i32> 
-  // CHECK: %add4.i = add <2 x i64> %shuffle2.i, %shuffle3.i
-  // CHECK: %shuffle6.i = shufflevector <2 x i64> %add4.i, <2 x i64> undef, <2 x i32> 
-  // CHECK: %add7.i = add <2 x i64> %shuffle6.i, %add4.i
-  // CHECK: %vecext.i = extractelement <2 x i64> %add7.i, i32 0
-  // CHECK: ret i64 %vecext.i
+// CHECK-LABEL: @test_mm512_reduce_add_epi64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SHUFFLE_I:%.*]] = shufflevector <8 x i64> [[__W:%.*]], <8 x i64> undef, <4 x i32> 
+// CHECK-NEXT:[[SHUFFLE3_I:%.*]] = shufflevector <8 x i64> [[__W]], <8 x i64> undef, <4 x i32> 
+// CHECK-NEXT:[[ADD_I:%.*]] = add <4 x i64> [[SHUFFLE_I]], [[SHUFFLE3_I]]
+// CHECK-NEXT:[[SHUFFLE6_I:%.*]] = shufflevector <4 x i64> [[ADD_I]], <4 x i64> undef, <2 x i32> 
+// CHECK-NEXT:[[SHUFFLE9_I:%.*]] = shufflevector <4 x i64> [[ADD_I]], <4 x i64> undef, <2 x i32> 
+// CHECK-NEXT:[[ADD10_I:%.*]] = add <2 x i64> [[SHUFFLE6_I]], [[SHUFFLE9_I]]
+// CHECK-NEXT:[[SHUFFLE11_I:%.*]] = shufflevector <2 x i64> [[ADD10_I]], <2 x i64> undef, <2 x i32> 
+// CHECK-NEXT:[[ADD12_I:%.*]] = add <2 x i64> [[SHUFFLE11_I]], [[ADD10_I]]
+// CHECK-NEXT:[[VECEXT_I:%.*]] = extractelement <2 x i64> [[ADD12_I]], i32 0
+// CHECK-NEXT:ret i64 [[VECEXT_I]]
   return _mm512_reduce_add_epi64(__W);
 }
 
 long long test_mm512_reduce_mul_epi64(__m512i __W){
-  // CHECK: %shuffle.i = shufflevector <8 x i64> %__W, <8 x i64> undef, <4 x i32> 
-  // CHECK: %shuffle1.i = shufflevector <8 x i64> %__W, <8 x i64> undef, <4 x i32> 
-  // CHECK: %mul.i = mul <4 x i64> %shuffle.i, %shuffle1.i
-  // CHECK: %shuffle2.i = shufflevector <4 x i64> %mul.i, <4 x i64> undef, <2 x i32> 
-  // CHECK: %shuffle3.i = shufflevector <4 x i64> %mul.i, <4 x i64> undef, <2 x i32> 
-  // CHECK: %mul4.i = mul <2 x i64> %shuffle2.i, %shuffle3.i
-  // CHECK: %shuffle6.i = shufflevector <2 x i64> %mul4.i, <2 x i64> undef, <2 x i32> 
-  // CHECK: %mul7.i = mul <2 x i64> %shuffle6.i, %mul4.i
-  // CHECK: %vecext.i = extractelement <2 x i64> %mul7.i, i32 0
-  // CHECK: ret i64 %vecext.i
+// CHECK-LABEL: @test_mm512_reduce_mul_epi64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SHUFFLE_I:%.*]] = shufflevector <8 x i64> [[__W:%.*]], <8 x i64> undef, <4 x i32> 
+// CHECK-NEXT:[[SHUFFLE3_I:%.*]] = shufflevector <8 x i64> [[__W]], <8 x i64> undef, <4 x i32> 
+// CHECK-NEXT:[[MUL_I:%.*]] = mul <4 x i64> [[SHUFFLE_I]], [[SHUFFLE3_I]]
+// CHECK-NEXT:[[SHUFFLE6_I:%.*]] = shufflevector <4 x i64> [[MUL_I]], <4 x i64> undef, <2 x i32> 
+// CHECK-NEXT:[[SHUFFLE9_I:%.*]] = shufflevector <4 x i64> [[MUL_I]], <4 x i64> undef, <2 x i32> 
+// CHECK-NEXT:[[MUL10_I:%.*]] = mul <2 x i64> [[SHUFFLE6_I]], [[SHUFFLE9_I]]
+// CHECK-NEXT:[[SHUFFLE11_I:%.*]] = shufflevector <2 x i64> [[MUL10_I]], <2 x i64> undef, <2 x i32> 
+// CHECK-NEXT:[[MUL12_I:%.*]] = mul <2 x i64> [[SHUFFLE11_I]], [[MUL10_I]]
+// CHECK-NEXT:[[VECEXT_I:%.*]] = extractelement <2 x i64> [[MUL12_I]], i32 0
+// CHECK-NEXT:ret i64 [[VECEXT_I]]
   return _mm512_reduce_mul_epi64(__W); 
 }
 
 long long test_mm512_reduce_or_epi64(__m512i __W){
-  // CHECK: %shuffle.i = shufflevector <8 x i64> %__W, <8 x i64> undef, <4 x i32> 
-  // CHECK: %shuffle1.i = shufflevector <8 x i64> %__W, <8 x i64> undef, <4 x i32> 
-  // CHECK: %or.i = or <4 x i64> %shuffle.i, %shuffle1.i
-  // CHECK: %shuffle2.i = shufflevector <4 x i64> %or.i, <4 x i64> undef, <2 x i32> 
-  // CHECK: %shuffle3.i = shufflevector <4 x i64> %or.i, <4 x i64> undef, <2 x i32> 
-  // CHECK: %or4.i = or <2 x i64> %shuffle2.i, %shuffle3.i 
-  // CHECK: %shuffle6.i = shufflevector <2 x i64> %or4.i, <2 x i64> undef, <2 x i32> 
-  // CHECK: %or7.i = or <2 x i64> %shuffle6.i, %or4.i
-  // CHECK: %vecext.i = extractelement <2 x i64> %or7.i, i32 0
-  // CHECK: ret i64 %vecext.i
+// CHECK-LABEL: @test_mm512_reduce_or_epi64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SHUFFLE_I:%.*]] = shuffle

r335088 - Add a test to verify the x86 intrinsic headers compile cleanly with no warnings or errors.

2018-06-19 Thread Douglas Yung via cfe-commits
Author: dyung
Date: Tue Jun 19 18:05:09 2018
New Revision: 335088

URL: http://llvm.org/viewvc/llvm-project?rev=335088&view=rev
Log:
Add a test to verify the x86 intrinsic headers compile cleanly with no warnings 
or errors.


Added:
cfe/trunk/test/Headers/x86-intrinsics-headers-clean.cpp

Added: cfe/trunk/test/Headers/x86-intrinsics-headers-clean.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/x86-intrinsics-headers-clean.cpp?rev=335088&view=auto
==
--- cfe/trunk/test/Headers/x86-intrinsics-headers-clean.cpp (added)
+++ cfe/trunk/test/Headers/x86-intrinsics-headers-clean.cpp Tue Jun 19 18:05:09 
2018
@@ -0,0 +1,14 @@
+// Make sure the intrinsic headers compile cleanly with no warnings or errors.
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wsystem-headers \
+// RUN:   -fsyntax-only -x c++ -Wno-ignored-attributes -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wsystem-headers \
+// RUN:   -fsyntax-only -x c++ -Wno-ignored-attributes -target-feature +f16c \
+// RUN:   -verify %s
+
+// expected-no-diagnostics
+
+// Dont' include mm_malloc.h. It's system specific.
+#define __MM_MALLOC_H
+
+#include 


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


[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 152006.
emmettneyman added a comment.

- actually fixed error statement


Repository:
  rC Clang

https://reviews.llvm.org/D48106

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangLLVMProtoFuzzer.cpp
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
  tools/clang-fuzzer/handle-cxx/handle_cxx.cpp
  tools/clang-fuzzer/handle-llvm/CMakeLists.txt
  tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  tools/clang-fuzzer/handle-llvm/handle_llvm.h
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  tools/clang-fuzzer/proto-to-llvm/CMakeLists.txt
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp

Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
===
--- tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
@@ -1,32 +1,31 @@
-//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//==-- loop_proto_to_llvm_main.cpp - Driver for protobuf-LLVM conversion==//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===--===//
 //
-// Implements a simple driver to print a C++ program from a protobuf with loops.
+// Implements a simple driver to print a LLVM program from a protobuf with loops
 //
 //===--===//
 
-// This is a copy and will be updated later to introduce changes
 
 #include 
 #include 
 #include 
 #include 
 
-#include "proto_to_cxx.h"
+#include "loop_proto_to_llvm.h"
 
 int main(int argc, char **argv) {
   for (int i = 1; i < argc; i++) {
 std::fstream in(argv[i]);
 std::string str((std::istreambuf_iterator(in)),
 std::istreambuf_iterator());
-std::cout << "// " << argv[i] << std::endl;
-std::cout << clang_fuzzer::LoopProtoToCxx(
+std::cout << ";; " << argv[i] << std::endl;
+std::cout << clang_fuzzer::LoopProtoToLLVM(
 reinterpret_cast(str.data()), str.size());
   }
 }
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
@@ -0,0 +1,23 @@
+//==-- loop_proto_to_llvm.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines functions for converting between protobufs and LLVM IR.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class LoopFunction;
+
+std::string LoopFunctionToLLVMString(const LoopFunction &input);
+std::string LoopProtoToLLVM(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -0,0 +1,156 @@
+//==-- loop_proto_to_llvm.cpp - Protobuf-C++ conversion
+//-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and LLVM IR.
+//
+//
+//===--===//
+
+#include "loop_proto_to_llvm.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls
+std::string BinopToString(std::ostream &os, const BinaryOp &x);
+std::string StateSeqToString(std::ostream &os, const StatementSeq &x);
+
+// Counter variable to generate new LLVM IR variable names and wrapper function
+std::string get_var() {
+  static int ctr = 0;
+  return "%var" + std::to_string(ctr++);
+}
+
+// Proto to LLVM.
+
+std::string ConstToString(const Const &x) {
+  return std::to_string(x.val());
+}
+std::string VarRefToString(std::ostream &os, const VarRef &x) {
+  std::string arr;
+  switch(x.arr()) {
+  case VarRef::ARR_A:
+arr = "%a";
+b

[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman added a comment.

In https://reviews.llvm.org/D48106#1137224, @morehouse wrote:

> Looks like `exit(0)` is still there.


oops, forgot to `:w`


Repository:
  rC Clang

https://reviews.llvm.org/D48106



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


[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

Looks like `exit(0)` is still there.


Repository:
  rC Clang

https://reviews.llvm.org/D48106



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


[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 152005.
emmettneyman added a comment.

- removed unnecessary comment and fixed exit statement


Repository:
  rC Clang

https://reviews.llvm.org/D48106

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangLLVMProtoFuzzer.cpp
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
  tools/clang-fuzzer/handle-cxx/handle_cxx.cpp
  tools/clang-fuzzer/handle-llvm/CMakeLists.txt
  tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  tools/clang-fuzzer/handle-llvm/handle_llvm.h
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  tools/clang-fuzzer/proto-to-llvm/CMakeLists.txt
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp

Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
===
--- tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
@@ -1,32 +1,31 @@
-//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//==-- loop_proto_to_llvm_main.cpp - Driver for protobuf-LLVM conversion==//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===--===//
 //
-// Implements a simple driver to print a C++ program from a protobuf with loops.
+// Implements a simple driver to print a LLVM program from a protobuf with loops
 //
 //===--===//
 
-// This is a copy and will be updated later to introduce changes
 
 #include 
 #include 
 #include 
 #include 
 
-#include "proto_to_cxx.h"
+#include "loop_proto_to_llvm.h"
 
 int main(int argc, char **argv) {
   for (int i = 1; i < argc; i++) {
 std::fstream in(argv[i]);
 std::string str((std::istreambuf_iterator(in)),
 std::istreambuf_iterator());
-std::cout << "// " << argv[i] << std::endl;
-std::cout << clang_fuzzer::LoopProtoToCxx(
+std::cout << ";; " << argv[i] << std::endl;
+std::cout << clang_fuzzer::LoopProtoToLLVM(
 reinterpret_cast(str.data()), str.size());
   }
 }
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
@@ -0,0 +1,23 @@
+//==-- loop_proto_to_llvm.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines functions for converting between protobufs and LLVM IR.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class LoopFunction;
+
+std::string LoopFunctionToLLVMString(const LoopFunction &input);
+std::string LoopProtoToLLVM(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -0,0 +1,156 @@
+//==-- loop_proto_to_llvm.cpp - Protobuf-C++ conversion
+//-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and LLVM IR.
+//
+//
+//===--===//
+
+#include "loop_proto_to_llvm.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls
+std::string BinopToString(std::ostream &os, const BinaryOp &x);
+std::string StateSeqToString(std::ostream &os, const StatementSeq &x);
+
+// Counter variable to generate new LLVM IR variable names and wrapper function
+std::string get_var() {
+  static int ctr = 0;
+  return "%var" + std::to_string(ctr++);
+}
+
+// Proto to LLVM.
+
+std::string ConstToString(const Const &x) {
+  return std::to_string(x.val());
+}
+std::string VarRefToString(std::ostream &os, const VarRef &x) {
+  std::string arr;
+  switch(x.arr()) {
+  case VarRef::ARR_A:
+

[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse accepted this revision.
morehouse added inline comments.
This revision is now accepted and ready to land.



Comment at: tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:50
+  errs() << "error: opt level must be between 0 and 3.\n";
+  std::exit(0);
+  }

`exit(1)` will indicate an abnormal exit.  (here and below)



Comment at: tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:64
+  SMDiagnostic Err;
+  // Create a new Context
+  LLVMContext Context;

This comment is unnecessary.  Clearly a new Context is being created on the 
next line.


Repository:
  rC Clang

https://reviews.llvm.org/D48106



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


r335086 - [X86] Undefine _mm512_mask_reduce_operator macro in avx512fintrin.h before redefining it.

2018-06-19 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Tue Jun 19 17:31:39 2018
New Revision: 335086

URL: http://llvm.org/viewvc/llvm-project?rev=335086&view=rev
Log:
[X86] Undefine _mm512_mask_reduce_operator macro in avx512fintrin.h before 
redefining it.

Modified:
cfe/trunk/lib/Headers/avx512fintrin.h

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=335086&r1=335085&r2=335086&view=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Tue Jun 19 17:31:39 2018
@@ -9689,6 +9689,7 @@ _mm512_mask_reduce_min_epu32(__mmask16 _
   __V = _mm512_mask_mov_epi32(_mm512_set1_epi32(~0U), __M, __V);
   _mm512_mask_reduce_operator(min_epu32);
 }
+#undef _mm512_mask_reduce_operator
 
 #define _mm512_mask_reduce_operator(op) \
   __m256d __t1 = _mm512_extractf64x4_pd(__V, 0); \


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


[PATCH] D48342: [libcxx] Optimize vectors construction of trivial types from an iterator range with const-ness mismatch.

2018-06-19 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Related change is https://reviews.llvm.org/D8109 For me the performance 
improvement was a twice faster execution on a dirty benchmark that doesn't 
exclude set up and tear down.


https://reviews.llvm.org/D48342



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


[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 152003.
emmettneyman added a comment.

- minor changes to improve readability and style


Repository:
  rC Clang

https://reviews.llvm.org/D48106

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangLLVMProtoFuzzer.cpp
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
  tools/clang-fuzzer/handle-cxx/handle_cxx.cpp
  tools/clang-fuzzer/handle-llvm/CMakeLists.txt
  tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  tools/clang-fuzzer/handle-llvm/handle_llvm.h
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  tools/clang-fuzzer/proto-to-llvm/CMakeLists.txt
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp

Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
===
--- tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
@@ -1,32 +1,31 @@
-//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//==-- loop_proto_to_llvm_main.cpp - Driver for protobuf-LLVM conversion==//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===--===//
 //
-// Implements a simple driver to print a C++ program from a protobuf with loops.
+// Implements a simple driver to print a LLVM program from a protobuf with loops
 //
 //===--===//
 
-// This is a copy and will be updated later to introduce changes
 
 #include 
 #include 
 #include 
 #include 
 
-#include "proto_to_cxx.h"
+#include "loop_proto_to_llvm.h"
 
 int main(int argc, char **argv) {
   for (int i = 1; i < argc; i++) {
 std::fstream in(argv[i]);
 std::string str((std::istreambuf_iterator(in)),
 std::istreambuf_iterator());
-std::cout << "// " << argv[i] << std::endl;
-std::cout << clang_fuzzer::LoopProtoToCxx(
+std::cout << ";; " << argv[i] << std::endl;
+std::cout << clang_fuzzer::LoopProtoToLLVM(
 reinterpret_cast(str.data()), str.size());
   }
 }
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
@@ -0,0 +1,23 @@
+//==-- loop_proto_to_llvm.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines functions for converting between protobufs and LLVM IR.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class LoopFunction;
+
+std::string LoopFunctionToLLVMString(const LoopFunction &input);
+std::string LoopProtoToLLVM(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -0,0 +1,156 @@
+//==-- loop_proto_to_llvm.cpp - Protobuf-C++ conversion
+//-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and LLVM IR.
+//
+//
+//===--===//
+
+#include "loop_proto_to_llvm.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls
+std::string BinopToString(std::ostream &os, const BinaryOp &x);
+std::string StateSeqToString(std::ostream &os, const StatementSeq &x);
+
+// Counter variable to generate new LLVM IR variable names and wrapper function
+std::string get_var() {
+  static int ctr = 0;
+  return "%var" + std::to_string(ctr++);
+}
+
+// Proto to LLVM.
+
+std::string ConstToString(const Const &x) {
+  return std::to_string(x.val());
+}
+std::string VarRefToString(std::ostream &os, const VarRef &x) {
+  std::string arr;
+  switch(x.arr()) {
+  case VarRef::ARR_A:
+ar

[PATCH] D48342: [libcxx] Optimize vectors construction of trivial types from an iterator range with const-ness mismatch.

2018-06-19 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: mclow.lists, EricWF.
Herald added a subscriber: christof.

We already have a specialization that will use memcpy for construction
of trivial types from an iterator range like

  std::vector(int *, int *);

But if we have const-ness mismatch like

  std::vector(const int *, const int *);

we would use a slow path that copies each element individually. This change
enables the optimal specialization for const-ness mismatch. Fixes PR37574.

rdar://problem/40485845


https://reviews.llvm.org/D48342

Files:
  libcxx/include/memory
  
libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_different_value_type.pass.cpp

Index: libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_different_value_type.pass.cpp
===
--- /dev/null
+++ libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_different_value_type.pass.cpp
@@ -0,0 +1,29 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  vector(InputIter first, InputIter last);
+
+// Initialize a vector with a different value type. Make sure initialization
+// is performed with each element value, not with a memory blob.
+
+#include 
+#include 
+#include 
+#include 
+
+int main()
+{
+int array[3] = {0, 1, 2};
+std::vector v(array, array + 3);
+assert(std::fabs(v[0] - 0.0f) < FLT_EPSILON);
+assert(std::fabs(v[1] - 1.0f) < FLT_EPSILON);
+assert(std::fabs(v[2] - 2.0f) < FLT_EPSILON);
+}
Index: libcxx/include/memory
===
--- libcxx/include/memory
+++ libcxx/include/memory
@@ -1399,6 +1399,13 @@
 {
 };
 
+template 
+struct __has_construct_missing
+: integral_constant::value>
+{
+};
+
 template 
 auto
 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
@@ -1467,14 +1474,26 @@
 {
 };
 
+template 
+struct __has_construct_missing
+: false_type
+{
+};
+
 #else  // _LIBCPP_HAS_NO_VARIADICS
 
 template 
 struct __has_construct
 : false_type
 {
 };
 
+template 
+struct __has_construct_missing
+: false_type
+{
+};
+
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
 template 
@@ -1622,7 +1641,7 @@
 typename enable_if
 <
 (is_same >::value
-|| !__has_construct::value) &&
+|| __has_construct_missing::value) &&
  is_trivially_move_constructible<_Tp>::value,
 void
 >::type
@@ -1646,23 +1665,27 @@
 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
 }
 
-template 
+template 
 _LIBCPP_INLINE_VISIBILITY
 static
 typename enable_if
 <
-(is_same >::value
-|| !__has_construct::value) &&
- is_trivially_move_constructible<_Tp>::value,
+(is_same
+ <
+typename _VSTD::remove_const::type,
+typename _VSTD::remove_const<_SourceTp>::type
+ >::value
+|| __has_construct_missing::value) &&
+ is_trivially_move_constructible<_DestTp>::value,
 void
 >::type
-__construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
+__construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2)
 {
-typedef typename remove_const<_Tp>::type _Vp;
+typedef typename remove_const<_DestTp>::type _Vp;
 ptrdiff_t _Np = __end1 - __begin1;
 if (_Np > 0)
 {
-_VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
+_VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_DestTp));
 __begin2 += _Np;
 }
 }
@@ -1686,7 +1709,7 @@
 typename enable_if
 <
 (is_same >::value
-|| !__has_construct::value) &&
+|| __has_construct_missing::value) &&
  is_trivially_move_constructible<_Tp>::value,
 void
 >::type
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48341: [clang-doc] Adding a second reduce pass

2018-06-19 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: ioeric, lebedev.ri.
juliehockett added a project: clang-tools-extra.

The first reduce pass combines all duplicate info data into one representation 
of that declaration info. This second pass iterates through the output of that 
first pass in order to streamline the outputted documentation.

The result of this pass is that all Function and Enum infos are absorbed into 
the info of their enclosing scope (i.e. the class or namespace in which they 
are defined). Namespace and Record infos are passed along to the final output, 
but the second pass creates a reference to each in its parent scope. As a 
result, the top-level final outputs are Namespaces and Records (and any 
declarations internal to functions are discarded).


https://reviews.llvm.org/D48341

Files:
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/test/clang-doc/yaml-comments.cpp
  clang-tools-extra/test/clang-doc/yaml-namespace.cpp
  clang-tools-extra/test/clang-doc/yaml-record.cpp

Index: clang-tools-extra/test/clang-doc/yaml-record.cpp
===
--- clang-tools-extra/test/clang-doc/yaml-record.cpp
+++ clang-tools-extra/test/clang-doc/yaml-record.cpp
@@ -1,250 +1,301 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
 // RUN: echo "" > %t/compile_flags.txt
-// RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-doc -doxygen -p %t %t/test.cpp -output=%t/docs
-// RUN: cat %t/docs/A.yaml | FileCheck %s --check-prefix=CHECK-A
-// RUN: cat %t/docs/Bc.yaml | FileCheck %s --check-prefix=CHECK-BC
-// RUN: cat %t/docs/B.yaml | FileCheck %s --check-prefix=CHECK-B
-// RUN: cat %t/docs/C.yaml | FileCheck %s --check-prefix=CHECK-C
-// RUN: cat %t/docs/D.yaml | FileCheck %s --check-prefix=CHECK-D
-// RUN: cat %t/docs/E.yaml | FileCheck %s --check-prefix=CHECK-E
-// RUN: cat %t/docs/E/ProtectedMethod.yaml | FileCheck %s --check-prefix=CHECK-EPM
-// RUN: cat %t/docs/E/E.yaml | FileCheck %s --check-prefix=CHECK-ECON
-// RUN: cat %t/docs/E/'~E.yaml' | FileCheck %s --check-prefix=CHECK-EDES
-// RUN: cat %t/docs/F.yaml | FileCheck %s --check-prefix=CHECK-F
-// RUN: cat %t/docs/X.yaml | FileCheck %s --check-prefix=CHECK-X
-// RUN: cat %t/docs/X/Y.yaml | FileCheck %s --check-prefix=CHECK-Y
-// RUN: cat %t/docs/H.yaml | FileCheck %s --check-prefix=CHECK-H
-// RUN: cat %t/docs/H/I.yaml | FileCheck %s --check-prefix=CHECK-I
-
-union A { int X; int Y; };
-
-// CHECK-A: ---
-// CHECK-A-NEXT: USR: 'ACE81AFA6627B4CEF2B456FB6E1252925674AF7E'
-// CHECK-A-NEXT: Name:'A'
-// CHECK-A-NEXT: DefLocation: 
-// CHECK-A-NEXT:   LineNumber:  21
-// CHECK-A-NEXT:   Filename:'{{.*}}'
-// CHECK-A-NEXT: TagType: Union
-// CHECK-A-NEXT: Members: 
-// CHECK-A-NEXT:   - Type:
-// CHECK-A-NEXT:   Name:'int'
-// CHECK-A-NEXT: Name:'X'
-// CHECK-A-NEXT:   - Type:
-// CHECK-A-NEXT:   Name:'int'
-// CHECK-A-NEXT: Name:'Y'
-// CHECK-A-NEXT: ...
+// RUN: cp "%s" "%t/{{.*}}.cpp"
+// RUN: clang-doc -doxygen -p %t %t/{{.*}}.cpp -output=%t/docs
+// RUN: cat %t/docs/GlobalNamespace.yaml | FileCheck %s --check-prefix=CHECK-G
+// RUN: cat %t/docs/Records.yaml | FileCheck %s --check-prefix=CHECK-R
+// RUN: cat %t/docs/Records/A.yaml | FileCheck %s --check-prefix=CHECK-A
+// RUN: cat %t/docs/Records/C.yaml | FileCheck %s --check-prefix=CHECK-C
+// RUN: cat %t/docs/Records/D.yaml | FileCheck %s --check-prefix=CHECK-D
+// RUN: cat %t/docs/Records/E.yaml | FileCheck %s --check-prefix=CHECK-E
+// RUN: cat %t/docs/Records/F.yaml | FileCheck %s --check-prefix=CHECK-F
+// RUN: cat %t/docs/Records/X.yaml | FileCheck %s --check-prefix=CHECK-X
+// RUN: cat %t/docs/Records/X/Y.yaml | FileCheck %s --check-prefix=CHECK-Y
 
+namespace Records {
 
-enum B { X, Y };
+union A {
+  int X;
+  int Y;
+};
 
-// CHECK-B: ---
-// CHECK-B-NEXT: USR: 'FC07BD34D5E77782C263FA97929EA8753740'
-// CHECK-B-NEXT: Name:'B'
-// CHECK-B-NEXT: DefLocation: 
-// CHECK-B-NEXT:   LineNumber:  40
-// CHECK-B-NEXT:   Filename:'{{.*}}'
-// CHECK-B-NEXT: Members: 
-// CHECK-B-NEXT:   - 'X'
-// CHECK-B-NEXT:   - 'Y'
-// CHECK-B-NEXT: ...
+//CHECK-A: ---
+//CHECK-A-NEXT: USR: '4CEF2DF0745C555B511A58908105E0C50EADA718'
+//CHECK-A-NEXT: Name:'A'
+//CHECK-A-NEXT: Namespace:   
+//CHECK-A-NEXT:   - Type:Namespace
+//CHECK-A-NEXT: Name:'Records'
+//CHECK-A-NEXT: USR: '910F55DBF9BF4C7A75A12A4AB871C1B2AE4E7F48'
+//CHECK-A-NEXT: DefLocation: 
+//CHECK-A-NEXT:   LineNumber:  18
+//CHECK-A-NEXT:   Filename:'{{.*}}'
+//CHECK-A-NEXT: TagType: Union
+//CHECK-A-NEXT: Members: 
+//CHECK-A-NEXT:   - Type:

[PATCH] D48100: Append new attributes to the end of an AttributeList.

2018-06-19 Thread Michael Kruse via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC335084: Append new attributes to the end of an 
AttributeList. (authored by Meinersbur, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48100?vs=151378&id=151998#toc

Repository:
  rC Clang

https://reviews.llvm.org/D48100

Files:
  include/clang/Sema/AttributeList.h
  lib/AST/ItaniumMangle.cpp
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderDecl.cpp
  test/Index/annotate-comments-availability-attrs.cpp
  test/Index/complete-with-annotations.cpp
  test/Misc/ast-print-pragmas.cpp
  test/PCH/pragma-loop.cpp
  test/Parser/pragma-loop-safety.cpp
  test/Parser/pragma-loop.cpp
  test/Parser/pragma-unroll.cpp
  test/Sema/attr-availability-tvos.c
  test/Sema/attr-availability.c
  test/Sema/attr-coldhot.c
  test/Sema/attr-disable-tail-calls.c
  test/Sema/attr-long-call.c
  test/Sema/attr-micromips.c
  test/Sema/attr-notail.c
  test/Sema/attr-ownership.c
  test/Sema/attr-ownership.cpp
  test/Sema/attr-print.c
  test/Sema/attr-swiftcall.c
  test/Sema/attr-target-mv.c
  test/Sema/attr-visibility.c
  test/Sema/internal_linkage.c
  test/Sema/mips-interrupt-attr.c
  test/Sema/ms_abi-sysv_abi.c
  test/Sema/nullability.c
  test/Sema/stdcall-fastcall.c
  test/SemaCXX/attr-print.cpp
  test/SemaCXX/attr-swiftcall.cpp
  test/SemaCXX/decl-microsoft-call-conv.cpp
  test/SemaCXX/ms-uuid.cpp
  test/SemaOpenCL/address-spaces.cl
  test/SemaTemplate/attributes.cpp

Index: lib/AST/ItaniumMangle.cpp
===
--- lib/AST/ItaniumMangle.cpp
+++ lib/AST/ItaniumMangle.cpp
@@ -707,10 +707,8 @@
   if (FD->hasAttr()) {
 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
 Out << "Ua9enable_ifI";
-// FIXME: specific_attr_iterator iterates in reverse order. Fix that and use
-// it here.
-for (AttrVec::const_reverse_iterator I = FD->getAttrs().rbegin(),
- E = FD->getAttrs().rend();
+for (AttrVec::const_iterator I = FD->getAttrs().begin(),
+ E = FD->getAttrs().end();
  I != E; ++I) {
   EnableIfAttr *EIA = dyn_cast(*I);
   if (!EIA)
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -6189,24 +6189,6 @@
   return nullptr;
 }
 
-// specific_attr_iterator iterates over enable_if attributes in reverse, and
-// enable_if is order-sensitive. As a result, we need to reverse things
-// sometimes. Size of 4 elements is arbitrary.
-static SmallVector
-getOrderedEnableIfAttrs(const FunctionDecl *Function) {
-  SmallVector Result;
-  if (!Function->hasAttrs())
-return Result;
-
-  const auto &FuncAttrs = Function->getAttrs();
-  for (Attr *Attr : FuncAttrs)
-if (auto *EnableIf = dyn_cast(Attr))
-  Result.push_back(EnableIf);
-
-  std::reverse(Result.begin(), Result.end());
-  return Result;
-}
-
 static bool
 convertArgsForAvailabilityChecks(Sema &S, FunctionDecl *Function, Expr *ThisArg,
  ArrayRef Args, Sema::SFINAETrap &Trap,
@@ -6280,9 +6262,9 @@
 
 EnableIfAttr *Sema::CheckEnableIf(FunctionDecl *Function, ArrayRef Args,
   bool MissingImplicitThis) {
-  SmallVector EnableIfAttrs =
-  getOrderedEnableIfAttrs(Function);
-  if (EnableIfAttrs.empty())
+  auto EnableIfAttrs = Function->specific_attrs();
+
+  if (EnableIfAttrs.begin() == EnableIfAttrs.end())
 return nullptr;
 
   SFINAETrap Trap(*this);
@@ -6292,7 +6274,7 @@
   if (!convertArgsForAvailabilityChecks(
   *this, Function, /*ThisArg=*/nullptr, Args, Trap,
   /*MissingImplicitThis=*/true, DiscardedThis, ConvertedArgs))
-return EnableIfAttrs[0];
+return *EnableIfAttrs.begin();
 
   for (auto *EIA : EnableIfAttrs) {
 APValue Result;
@@ -8943,24 +8925,21 @@
 return Cand1Attr ? Comparison::Better : Comparison::Worse;
   }
 
-  // FIXME: The next several lines are just
-  // specific_attr_iterator but going in declaration order,
-  // instead of reverse order which is how they're stored in the AST.
-  auto Cand1Attrs = getOrderedEnableIfAttrs(Cand1);
-  auto Cand2Attrs = getOrderedEnableIfAttrs(Cand2);
-
-  // It's impossible for Cand1 to be better than (or equal to) Cand2 if Cand1
-  // has fewer enable_if attributes than Cand2.
-  if (Cand1Attrs.size() < Cand2Attrs.size())
-return Comparison::Worse;
+  auto Cand1Attrs = Cand1->specific_attrs();
+  auto Cand2Attrs = Cand2->specific_attrs();
 
   auto Cand1I = Cand1Attrs.begin();
   llvm::FoldingSetNodeID Cand1ID, Cand2ID;
-  for (auto &Cand2A : Cand2Attrs) {
+  for (auto Cand2A : Cand2Attrs) {
 Cand1ID.clear();
 Cand2ID.clear();
 
-auto &Cand1A = *Cand1I++;
+// It's impossible for Cand1 to be better than (or equal to) Cand2 if Cand1
+// has fewer enable_if attributes than Cand2.
+

[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

If you haven't already, please apply for commit access:  
https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access.

That way you can land this after it's accepted.




Comment at: tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:23
+#include "llvm/IR/Module.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Verifier.h"

This should come before llvm/IR/Module.h.



Comment at: tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:35
+
+void getOptLevel(const std::vector &ExtraArgs,
+  CodeGenOpt::Level &OLvl) {

Can make this static to avoid future namespace collisions.



Comment at: tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:48
+default:
+  errs() << "error: opt level must be between 0 and 3.\n";
+  return;

Maybe exit() as well on error?  (here and below)

Exiting will cause the fuzz target to fail, so you can debug more easily.  
Otherwise, these error messages could go unnoticed.



Comment at: tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:58
+  // Create a new Context
+  LLVMContext Context;
+  // Parse ExtraArgs to set the optimization level

It's easier to follow if you move this closer to where Context is first used.



Comment at: tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:66
+  std::unique_ptr M = parseIR(MemoryBufferRef(S, "IR"), Err,
+  Context, true);
+  if (!M) {

You can actually omit the last argument here since you're using the default.



Comment at: tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:81
+  std::string CPUStr = getCPUStr();
+  std::string FeaturesStr = getFeaturesStr();
+

Easier to follow if you move these two lines closer to where `CPUStr` and 
`FeaturesStr` are used.



Comment at: tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:105
+  raw_null_ostream OS;
+  MachineModuleInfo *MMI = new MachineModuleInfo(Target.get());
+  Target->addPassesToEmitFile(PM, OS, nullptr, TargetMachine::CGFT_ObjectFile,

I believe you can avoid creating the MMI here since it looks like 
addPassesToEmitFile will do it for you.


Repository:
  rC Clang

https://reviews.llvm.org/D48106



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


[PATCH] D48296: clang-cl: Emit normal narrowing diagnostics for initializer lists if -fmsc-version is at least 1900 (i.e. MSVC2015).

2018-06-19 Thread Nico Weber via Phabricator via cfe-commits
thakis closed this revision.
thakis added a comment.

r335082, thanks!


https://reviews.llvm.org/D48296



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


r335082 - clang-cl: Emit narrowing diag for initializer lists if -fmsc-version is at least 1900 (i.e. MSVC2015).

2018-06-19 Thread Nico Weber via cfe-commits
Author: nico
Date: Tue Jun 19 16:19:34 2018
New Revision: 335082

URL: http://llvm.org/viewvc/llvm-project?rev=335082&view=rev
Log:
clang-cl: Emit narrowing diag for initializer lists if -fmsc-version is at 
least 1900 (i.e. MSVC2015).

Diagnostics for narrowing conversions in initializer lists are currently
DefaultIgnored in Microsoft mode. But MSVC 2015 did add warnings about
narrowing conversions (C2397), so clang-cl can remove its special case code if
MSCompatibilityVersion is new enough.

(In MSVC, C2397 is just a warning and in clang it's default-mapped to an error,
but it can be remapped, and disabled with -Wno-c++11-narrowing, so that should
be fine.)

Fixes PR37314.
https://reviews.llvm.org/D48296

Added:
cfe/trunk/test/SemaCXX/ms-initlist-narrowing.cpp
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=335082&r1=335081&r2=335082&view=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Jun 19 16:19:34 2018
@@ -8331,6 +8331,11 @@ void InitializationSequence::dump() cons
   dump(llvm::errs());
 }
 
+static bool NarrowingErrs(const LangOptions &L) {
+  return L.CPlusPlus11 &&
+ (!L.MicrosoftExt || L.isCompatibleWithMSVC(LangOptions::MSVC2015));
+}
+
 static void DiagnoseNarrowingInInitList(Sema &S,
 const ImplicitConversionSequence &ICS,
 QualType PreNarrowingType,
@@ -8364,35 +8369,34 @@ static void DiagnoseNarrowingInInitList(
 // This was a floating-to-integer conversion, which is always considered a
 // narrowing conversion even if the value is a constant and can be
 // represented exactly as an integer.
-S.Diag(PostInit->getLocStart(),
-   (S.getLangOpts().MicrosoftExt || !S.getLangOpts().CPlusPlus11)
-   ? diag::warn_init_list_type_narrowing
-   : diag::ext_init_list_type_narrowing)
-  << PostInit->getSourceRange()
-  << PreNarrowingType.getLocalUnqualifiedType()
-  << EntityType.getLocalUnqualifiedType();
+S.Diag(PostInit->getLocStart(), NarrowingErrs(S.getLangOpts())
+? diag::ext_init_list_type_narrowing
+: diag::warn_init_list_type_narrowing)
+<< PostInit->getSourceRange()
+<< PreNarrowingType.getLocalUnqualifiedType()
+<< EntityType.getLocalUnqualifiedType();
 break;
 
   case NK_Constant_Narrowing:
 // A constant value was narrowed.
 S.Diag(PostInit->getLocStart(),
-   (S.getLangOpts().MicrosoftExt || !S.getLangOpts().CPlusPlus11)
-   ? diag::warn_init_list_constant_narrowing
-   : diag::ext_init_list_constant_narrowing)
-  << PostInit->getSourceRange()
-  << ConstantValue.getAsString(S.getASTContext(), ConstantType)
-  << EntityType.getLocalUnqualifiedType();
+   NarrowingErrs(S.getLangOpts())
+   ? diag::ext_init_list_constant_narrowing
+   : diag::warn_init_list_constant_narrowing)
+<< PostInit->getSourceRange()
+<< ConstantValue.getAsString(S.getASTContext(), ConstantType)
+<< EntityType.getLocalUnqualifiedType();
 break;
 
   case NK_Variable_Narrowing:
 // A variable's value may have been narrowed.
 S.Diag(PostInit->getLocStart(),
-   (S.getLangOpts().MicrosoftExt || !S.getLangOpts().CPlusPlus11)
-   ? diag::warn_init_list_variable_narrowing
-   : diag::ext_init_list_variable_narrowing)
-  << PostInit->getSourceRange()
-  << PreNarrowingType.getLocalUnqualifiedType()
-  << EntityType.getLocalUnqualifiedType();
+   NarrowingErrs(S.getLangOpts())
+   ? diag::ext_init_list_variable_narrowing
+   : diag::warn_init_list_variable_narrowing)
+<< PostInit->getSourceRange()
+<< PreNarrowingType.getLocalUnqualifiedType()
+<< EntityType.getLocalUnqualifiedType();
 break;
   }
 

Added: cfe/trunk/test/SemaCXX/ms-initlist-narrowing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms-initlist-narrowing.cpp?rev=335082&view=auto
==
--- cfe/trunk/test/SemaCXX/ms-initlist-narrowing.cpp (added)
+++ cfe/trunk/test/SemaCXX/ms-initlist-narrowing.cpp Tue Jun 19 16:19:34 2018
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions 
-fms-compatibility-version=19.0 -std=c++11
+
+int ai[] = { 1, 2.0 };  // expected-error {{type 'double' cannot be narrowed 
to 'int' in initializer list}} expected-note {{silence}}
+
+template
+struct Agg {
+  T t;
+};
+
+void f(int i) {
+  // Constant expression.
+  Agg f8 = {1E50};  // expected-error {{constant expression evaluates 
to 1.00e+50 whic

r335081 - Recommit r335063: [Darwin] Add a warning for missing include path for libstdc++

2018-06-19 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jun 19 15:47:53 2018
New Revision: 335081

URL: http://llvm.org/viewvc/llvm-project?rev=335081&view=rev
Log:
Recommit r335063: [Darwin] Add a warning for missing include path for libstdc++

The recommit ensures that the tests that failed on bots don't trigger the 
warning.

Xcode 10 removes support for libstdc++, but the users just get a confusing
include not file warning when including an STL header (when building for iOS6
which uses libstdc++ by default for example).
This patch adds a new warning that lets the user know that the libstdc++ include
path was not found to ensure that the user is more aware of why the error 
occurs.

rdar://40830462

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

Added:
cfe/trunk/test/Frontend/warning-stdlibcxx-darwin.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
cfe/trunk/test/CodeGenCXX/apple-kext-guard-variable.cpp
cfe/trunk/test/Misc/backend-stack-frame-diagnostics.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=335081&r1=335080&r2=335081&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Tue Jun 19 
15:47:53 2018
@@ -236,4 +236,9 @@ def err_invalid_vfs_overlay : Error<
 
 def warn_option_invalid_ocl_version : Warning<
   "OpenCL version %0 does not support the option '%1'">, InGroup;
+
+def warn_stdlibcxx_not_found : Warning<
+  "include path for stdlibc++ headers not found; pass '-std=libc++' on the "
+  "command line to use the libc++ standard library instead">,
+  InGroup>;
 }

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=335081&r1=335080&r2=335081&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Tue Jun 19 15:47:53 2018
@@ -272,6 +272,8 @@ public:
   
   FileManager &getFileMgr() const { return FileMgr; }
 
+  DiagnosticsEngine &getDiags() const { return Diags; }
+
   /// Interface for setting the file search paths.
   void SetSearchPaths(const std::vector &dirs,
   unsigned angledDirIdx, unsigned systemDirIdx,

Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=335081&r1=335080&r2=335081&view=diff
==
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Tue Jun 19 15:47:53 2018
@@ -14,6 +14,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Config/config.h" // C_INCLUDE_DIRS
+#include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/HeaderSearch.h"
@@ -55,11 +56,13 @@ public:
 
   /// AddPath - Add the specified path to the specified group list, prefixing
   /// the sysroot if used.
-  void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
+  /// Returns true if the path exists, false if it was ignored.
+  bool AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
 
   /// AddUnmappedPath - Add the specified path to the specified group list,
   /// without performing any sysroot remapping.
-  void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
+  /// Returns true if the path exists, false if it was ignored.
+  bool AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework);
 
   /// AddSystemHeaderPrefix - Add the specified prefix to the system header
@@ -70,10 +73,9 @@ public:
 
   /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
   ///  libstdc++.
-  void AddGnuCPlusPlusIncludePaths(StringRef Base,
-   StringRef ArchDir,
-   StringRef Dir32,
-   StringRef Dir64,
+  /// Returns true if the \p Base path was found, false if it does not exist.
+  bool AddGnuCPlusPlusIncludePaths(StringRef Base, StringRef ArchDir,
+   StringRef Dir32, StringRef Dir64,
const llvm::Triple &triple);
 
   /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a 
MinGW
@@ -88,7 +90,8 @@ public:
 
   // AddDefaultCPlusPlusIncludePaths -  Add paths that should be searched when
   //  compiling c++.
-  void AddDefaultCPlusPlusIncludePaths(const llv

[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 151986.
emmettneyman added a comment.

- made changes to handle_llvm.cpp in response to reviewer comments


Repository:
  rC Clang

https://reviews.llvm.org/D48106

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangLLVMProtoFuzzer.cpp
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
  tools/clang-fuzzer/handle-cxx/handle_cxx.cpp
  tools/clang-fuzzer/handle-llvm/CMakeLists.txt
  tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  tools/clang-fuzzer/handle-llvm/handle_llvm.h
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  tools/clang-fuzzer/proto-to-llvm/CMakeLists.txt
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
  tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp

Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
===
--- tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm_main.cpp
@@ -1,32 +1,31 @@
-//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//==-- loop_proto_to_llvm_main.cpp - Driver for protobuf-LLVM conversion==//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===--===//
 //
-// Implements a simple driver to print a C++ program from a protobuf with loops.
+// Implements a simple driver to print a LLVM program from a protobuf with loops
 //
 //===--===//
 
-// This is a copy and will be updated later to introduce changes
 
 #include 
 #include 
 #include 
 #include 
 
-#include "proto_to_cxx.h"
+#include "loop_proto_to_llvm.h"
 
 int main(int argc, char **argv) {
   for (int i = 1; i < argc; i++) {
 std::fstream in(argv[i]);
 std::string str((std::istreambuf_iterator(in)),
 std::istreambuf_iterator());
-std::cout << "// " << argv[i] << std::endl;
-std::cout << clang_fuzzer::LoopProtoToCxx(
+std::cout << ";; " << argv[i] << std::endl;
+std::cout << clang_fuzzer::LoopProtoToLLVM(
 reinterpret_cast(str.data()), str.size());
   }
 }
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.h
@@ -0,0 +1,23 @@
+//==-- loop_proto_to_llvm.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines functions for converting between protobufs and LLVM IR.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class LoopFunction;
+
+std::string LoopFunctionToLLVMString(const LoopFunction &input);
+std::string LoopProtoToLLVM(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -0,0 +1,156 @@
+//==-- loop_proto_to_llvm.cpp - Protobuf-C++ conversion
+//-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and LLVM IR.
+//
+//
+//===--===//
+
+#include "loop_proto_to_llvm.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls
+std::string BinopToString(std::ostream &os, const BinaryOp &x);
+std::string StateSeqToString(std::ostream &os, const StatementSeq &x);
+
+// Counter variable to generate new LLVM IR variable names and wrapper function
+std::string get_var() {
+  static int ctr = 0;
+  return "%var" + std::to_string(ctr++);
+}
+
+// Proto to LLVM.
+
+std::string ConstToString(const Const &x) {
+  return std::to_string(x.val());
+}
+std::string VarRefToString(std::ostream &os, const VarRef &x) {
+  std::string arr;
+  switch(x.arr()) {
+  case VarR

[PATCH] D47358: : Implement {un, }synchronized_pool_resource.

2018-06-19 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone updated this revision to Diff 151984.
Quuxplusone added a comment.
Herald added a subscriber: mgrang.

Bugfix and shrink {un,}synchronized_pool_resource.

The old implementation was severely broken in two ways:

- It accidentally sometimes trusted the user's `bytes` and `align` arguments to 
`do_deallocate`, which didn't match the `bytes` and `alignment` stored in the 
actual ad-hoc chunk header. The new test case catches this bug.

- It relied on pointer comparison (undefined behavior) to test whether the 
user-supplied pointer belonged to each chunk in turn. Fortunately this is 
unnecessary. The new code follows Boost.Container by keeping just one list of 
"vacancies" per pool (not one per chunk, as I'd been doing). The new code is 
faster (deallocation is now `O(1)` not `O(chunks-in-this-pool)`), smaller 
(there are `O(pools)` free-list pointers instead of `O(chunks)`), and avoids 
undefined behavior.


Repository:
  rCXX libc++

https://reviews.llvm.org/D47358

Files:
  include/experimental/memory_resource
  src/experimental/memory_resource.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.ctor/ctor_does_not_allocate.pass.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.ctor/sync_with_default_resource.pass.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.ctor/unsync_with_default_resource.pass.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/equality.pass.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/sync_allocate.pass.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/sync_allocate_overaligned_request.pass.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/sync_allocate_reuse_blocks.pass.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/sync_deallocate_matches_allocate.pass.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/unsync_allocate.pass.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/unsync_allocate_overaligned_request.pass.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/unsync_allocate_reuse_blocks.pass.cpp
  
test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/unsync_deallocate_matches_allocate.pass.cpp
  test/std/experimental/memory/memory.resource.pool/pool_options.pass.cpp
  test/support/count_new.hpp

Index: test/support/count_new.hpp
===
--- test/support/count_new.hpp
+++ test/support/count_new.hpp
@@ -211,6 +211,11 @@
 return disable_checking || n != delete_called;
 }
 
+bool checkDeleteCalledGreaterThan(int n) const
+{
+return disable_checking || delete_called > n;
+}
+
 bool checkAlignedNewCalledEq(int n) const
 {
 return disable_checking || n == aligned_new_called;
Index: test/std/experimental/memory/memory.resource.pool/pool_options.pass.cpp
===
--- /dev/null
+++ test/std/experimental/memory/memory.resource.pool/pool_options.pass.cpp
@@ -0,0 +1,26 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// REQUIRES: c++experimental
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// UNSUPPORTED: apple-clang-7
+
+// 
+
+// struct pool_options
+
+#include 
+#include 
+
+int main()
+{
+const std::experimental::pmr::pool_options p;
+assert(p.max_blocks_per_chunk == 0);
+assert(p.largest_required_pool_block == 0);
+}
Index: test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/unsync_deallocate_matches_allocate.pass.cpp
===
--- /dev/null
+++ test/std/experimental/memory/memory.resource.pool/memory.resource.pool.mem/unsync_deallocate_matches_allocate.pass.cpp
@@ -0,0 +1,110 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// REQUIRES: c++experimental
+// UNSUPPORTED: c++98, c++03
+
+// 
+
+// class unsynchronized_pool_resource
+
+#include 
+#include 
+#include 
+
+struct allocation_record {
+size_t bytes;
+size_t align;
+explicit allocation_record(size_t b, size_t a) : bytes(b), align(a) {}
+bool operator==(cons

[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman added inline comments.



Comment at: tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:71
+return val_var;
+  }
+}

morehouse wrote:
> Is it still possible for the protobuf to not have a constant, a binOp, or a 
> varRef?
Right now, since the protobufs use `oneof`, it is possible for the protobuf to 
not have a constant binOp, or varRef. For now, I'll generate "dummy" code for 
this case. 

Then, I'll submit a new patch that eliminates the use of `oneof` for both 
`cxx_proto.proto` and `cxx_loop_proto` so that "dummy" code isn't necessary.


Repository:
  rC Clang

https://reviews.llvm.org/D48106



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


[PATCH] D47111: : Implement monotonic_buffer_resource.

2018-06-19 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone updated this revision to Diff 151983.
Quuxplusone added a comment.

Minor cosmetic changes.


Repository:
  rCXX libc++

https://reviews.llvm.org/D47111

Files:
  include/experimental/memory_resource
  src/experimental/memory_resource.cpp
  
test/libcxx/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_in_geometric_progression.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.ctor/copy_move.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.ctor/with_default_resource.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.ctor/without_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_deallocate.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_exception_safety.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_from_initial_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_from_underaligned_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_from_zero_sized_buffer.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_in_geometric_progression.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_overaligned_request.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_with_initial_size.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/equality.pass.cpp
  
test/std/experimental/memory/memory.resource.monotonic.buffer/nothing_to_do.pass.cpp

Index: test/std/experimental/memory/memory.resource.monotonic.buffer/nothing_to_do.pass.cpp
===
--- /dev/null
+++ test/std/experimental/memory/memory.resource.monotonic.buffer/nothing_to_do.pass.cpp
@@ -0,0 +1,13 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+int main()
+{
+}
Index: test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/equality.pass.cpp
===
--- /dev/null
+++ test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/equality.pass.cpp
@@ -0,0 +1,62 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// REQUIRES: c++experimental
+// UNSUPPORTED: c++98, c++03
+
+// 
+
+// class monotonic_buffer_resource
+
+#include 
+#include 
+#include 
+#include 
+
+struct assert_on_compare : public std::experimental::pmr::memory_resource
+{
+protected:
+virtual void * do_allocate(size_t, size_t)
+{ assert(false); }
+
+virtual void do_deallocate(void *, size_t, size_t)
+{ assert(false); }
+
+virtual bool do_is_equal(std::experimental::pmr::memory_resource const &) const noexcept
+{ assert(false); }
+};
+
+int main()
+{
+// Same object
+{
+std::experimental::pmr::monotonic_buffer_resource r1;
+std::experimental::pmr::monotonic_buffer_resource r2;
+assert(r1 == r1);
+assert(r1 != r2);
+
+std::experimental::pmr::memory_resource & p1 = r1;
+std::experimental::pmr::memory_resource & p2 = r2;
+assert(p1 == p1);
+assert(p1 != p2);
+assert(p1 == r1);
+assert(r1 == p1);
+assert(p1 != r2);
+assert(r2 != p1);
+}
+// Different types
+{
+std::experimental::pmr::monotonic_buffer_resource mono1;
+std::experimental::pmr::memory_resource & r1 = mono1;
+assert_on_compare c;
+std::experimental::pmr::memory_resource & r2 = c;
+assert(r1 != r2);
+assert(!(r1 == r2));
+}
+}
Index: test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_with_initial_size.pass.cpp
===
--- /dev/null
+++ test/std/experimental/memory/memory.resource.monotonic.buffer/monotonic.buffer.mem/allocate_with_initial_size.pass.cpp
@@ -0,0 +1,51 @@
+//===-

[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman added inline comments.



Comment at: tools/clang-fuzzer/handle-llvm/\:113
+
+  legacy::PassManager PM;
+  TargetLibraryInfoImpl TLII(Triple(M->getTargetTriple()));

morehouse wrote:
> Any reason not to use the newer PassManager?
Clang (`llc`) and the `llvm-isel-fuzzer` both still use the legacy PassManager. 
The newer PassManager has a new interface that doesn't use `Module`s.


Repository:
  rC Clang

https://reviews.llvm.org/D48106



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


[PATCH] D46919: [libclang] Deprecate CXPrintingPolicy_IncludeTagDefinition

2018-06-19 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 151979.
jdenny added a comment.

Rebased.  Ping.


https://reviews.llvm.org/D46919

Files:
  include/clang-c/Index.h
  include/clang/AST/PrettyPrinter.h
  lib/AST/DeclPrinter.cpp
  lib/AST/TypePrinter.cpp
  tools/c-index-test/c-index-test.c

Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -99,8 +99,6 @@
CXPrintingPolicy_SuppressSpecifiers},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSTAGKEYWORD",
CXPrintingPolicy_SuppressTagKeyword},
-  {"CINDEXTEST_PRINTINGPOLICY_INCLUDETAGDEFINITION",
-   CXPrintingPolicy_IncludeTagDefinition},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSSCOPE",
CXPrintingPolicy_SuppressScope},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSUNWRITTENSCOPE",
Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -454,7 +454,7 @@
 OS << '(';
 
   PrintingPolicy InnerPolicy(Policy);
-  InnerPolicy.IncludeTagDefinition = false;
+  InnerPolicy.State.PrintOwnedTagDecl = false;
   TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
 
   OS << "::*";
@@ -1054,9 +1054,9 @@
 }
 
 void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition) {
+  if (Policy.State.PrintOwnedTagDecl) {
 PrintingPolicy SubPolicy = Policy;
-SubPolicy.IncludeTagDefinition = false;
+SubPolicy.State.PrintOwnedTagDecl = false;
 D->print(OS, SubPolicy, Indentation);
 spaceBeforePlaceHolder(OS);
 return;
@@ -1209,35 +1209,34 @@
 
 void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
 raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl()) {
+  if (Policy.State.PrintOwnedTagDecl && T->getOwnedTagDecl()) {
 TagDecl *OwnedTagDecl = T->getOwnedTagDecl();
 assert(OwnedTagDecl->getTypeForDecl() == T->getNamedType().getTypePtr() &&
"OwnedTagDecl expected to be a declaration for the type");
 PrintingPolicy SubPolicy = Policy;
-SubPolicy.IncludeTagDefinition = false;
+SubPolicy.State.PrintOwnedTagDecl = false;
 OwnedTagDecl->print(OS, SubPolicy, Indentation);
 spaceBeforePlaceHolder(OS);
 return;
   }
 
   // The tag definition will take care of these.
-  if (!Policy.IncludeTagDefinition)
-  {
+  if (!Policy.State.PrintOwnedTagDecl) {
 OS << TypeWithKeyword::getKeywordName(T->getKeyword());
 if (T->getKeyword() != ETK_None)
   OS << " ";
 NestedNameSpecifier *Qualifier = T->getQualifier();
 if (Qualifier)
   Qualifier->print(OS, Policy);
   }
-  
+
   ElaboratedTypePolicyRAII PolicyRAII(Policy);
   printBefore(T->getNamedType(), OS);
 }
 
 void TypePrinter::printElaboratedAfter(const ElaboratedType *T,
 raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl())
+  if (Policy.State.PrintOwnedTagDecl && T->getOwnedTagDecl())
 return;
   ElaboratedTypePolicyRAII PolicyRAII(Policy);
   printAfter(T->getNamedType(), OS);
Index: lib/AST/DeclPrinter.cpp
===
--- lib/AST/DeclPrinter.cpp
+++ lib/AST/DeclPrinter.cpp
@@ -178,12 +178,12 @@
   for ( ; Begin != End; ++Begin) {
 if (isFirst) {
   if(TD)
-SubPolicy.IncludeTagDefinition = true;
+SubPolicy.State.PrintOwnedTagDecl = true;
   SubPolicy.SuppressSpecifiers = false;
   isFirst = false;
 } else {
   if (!isFirst) Out << ", ";
-  SubPolicy.IncludeTagDefinition = false;
+  SubPolicy.State.PrintOwnedTagDecl = false;
   SubPolicy.SuppressSpecifiers = true;
 }
 
@@ -849,7 +849,7 @@
   }
   PrintingPolicy SubPolicy(Policy);
   SubPolicy.SuppressSpecifiers = false;
-  SubPolicy.IncludeTagDefinition = false;
+  SubPolicy.State.PrintOwnedTagDecl = false;
   Init->printPretty(Out, nullptr, SubPolicy, Indentation);
   if ((D->getInitStyle() == VarDecl::CallInit) && !isa(Init))
 Out << ")";
Index: include/clang/AST/PrettyPrinter.h
===
--- include/clang/AST/PrettyPrinter.h
+++ include/clang/AST/PrettyPrinter.h
@@ -93,14 +93,7 @@
   /// \endcode
   bool SuppressTagKeyword : 1;
 
-  /// When true, include the body of a tag definition.
-  ///
-  /// This is used to place the definition of a struct
-  /// in the middle of another declaration as with:
-  ///
-  /// \code
-  /// typedef struct { int x, y; } Point;
-  /// \endcode
+  /// This flag is deprecated and no longer has any effect.
   bool IncludeTagDefinition : 1;
 
   /// Suppresses printing of scope specifiers.
@@ -225,6 +218,25 @@
   /// When true, print the fully qualified name of function declarations.
   /// This is the opposite of SuppressSco

[PATCH] D48296: clang-cl: Emit normal narrowing diagnostics for initializer lists if -fmsc-version is at least 1900 (i.e. MSVC2015).

2018-06-19 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

In https://reviews.llvm.org/D48296#1136095, @thakis wrote:

> Thanks! I'd keep it DefaultIgnored: I'd be annoyed if I'd get these by 
> default in C++98 mode.


Got it, for some reason I'd forgotten they show up in C++98. I'd argue that the 
warnings are valuable, at least for helping people transition to C++11, but 
that behavior change is a separate discussion.


https://reviews.llvm.org/D48296



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


r335073 - Revert r335063 as it causes bot failures

2018-06-19 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jun 19 12:43:07 2018
New Revision: 335073

URL: http://llvm.org/viewvc/llvm-project?rev=335073&view=rev
Log:
Revert r335063 as it causes bot failures

Removed:
cfe/trunk/test/Frontend/warning-stdlibcxx-darwin.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/lib/Frontend/InitHeaderSearch.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=335073&r1=335072&r2=335073&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Tue Jun 19 
12:43:07 2018
@@ -236,9 +236,4 @@ def err_invalid_vfs_overlay : Error<
 
 def warn_option_invalid_ocl_version : Warning<
   "OpenCL version %0 does not support the option '%1'">, InGroup;
-
-def warn_stdlibcxx_not_found : Warning<
-  "include path for stdlibc++ headers not found; pass '-std=libc++' on the "
-  "command line to use the libc++ standard library instead">,
-  InGroup>;
 }

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=335073&r1=335072&r2=335073&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Tue Jun 19 12:43:07 2018
@@ -272,8 +272,6 @@ public:
   
   FileManager &getFileMgr() const { return FileMgr; }
 
-  DiagnosticsEngine &getDiags() const { return Diags; }
-
   /// Interface for setting the file search paths.
   void SetSearchPaths(const std::vector &dirs,
   unsigned angledDirIdx, unsigned systemDirIdx,

Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=335073&r1=335072&r2=335073&view=diff
==
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Tue Jun 19 12:43:07 2018
@@ -14,7 +14,6 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Config/config.h" // C_INCLUDE_DIRS
-#include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/HeaderSearch.h"
@@ -56,13 +55,11 @@ public:
 
   /// AddPath - Add the specified path to the specified group list, prefixing
   /// the sysroot if used.
-  /// Returns true if the path exists, false if it was ignored.
-  bool AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
+  void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
 
   /// AddUnmappedPath - Add the specified path to the specified group list,
   /// without performing any sysroot remapping.
-  /// Returns true if the path exists, false if it was ignored.
-  bool AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
+  void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework);
 
   /// AddSystemHeaderPrefix - Add the specified prefix to the system header
@@ -73,9 +70,10 @@ public:
 
   /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
   ///  libstdc++.
-  /// Returns true if the \p Base path was found, false if it does not exist.
-  bool AddGnuCPlusPlusIncludePaths(StringRef Base, StringRef ArchDir,
-   StringRef Dir32, StringRef Dir64,
+  void AddGnuCPlusPlusIncludePaths(StringRef Base,
+   StringRef ArchDir,
+   StringRef Dir32,
+   StringRef Dir64,
const llvm::Triple &triple);
 
   /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a 
MinGW
@@ -90,8 +88,7 @@ public:
 
   // AddDefaultCPlusPlusIncludePaths -  Add paths that should be searched when
   //  compiling c++.
-  void AddDefaultCPlusPlusIncludePaths(const LangOptions &LangOpts,
-   const llvm::Triple &triple,
+  void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts);
 
   /// AddDefaultSystemIncludePaths - Adds the default system include paths so
@@ -115,7 +112,7 @@ static bool CanPrefixSysroot(StringRef P
 #endif
 }
 
-bool InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
+void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework) {
   // Add the path with sysroot prepended, if desired and this is a system 
header
   // gro

[PATCH] D47401: [X86] Rewrite the max and min reduction intrinsics to make better use of other functions and to reduce width to 256 and 128 bits were possible.

2018-06-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Fast-isel tests were added for previous codegen in r335068 and updated for new 
codegen in r335071.

One addtiional observation I didn't catch before. The epi32 and epu32 min/max 
intrinsics were doing a 64-bit element extract as the final step previously 
because they just did a [0] on _m128i which is really __v2di. It didn't 
functionally matter because it would be truncated after the extract. The new 
code uses [0] on a __v4si type so we get a 32-bit extract.


Repository:
  rL LLVM

https://reviews.llvm.org/D47401



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


[PATCH] D48259: [clang-format] Fix bug with UT_Always when there is less than one full tab

2018-06-19 Thread Guillaume Reymond via Phabricator via cfe-commits
guigu added inline comments.



Comment at: lib/Format/WhitespaceManager.cpp:678
 // Indent with tabs only when there's at least one full tab.
-if (FirstTabWidth + Style.TabWidth <= Spaces) {
+if (Style.TabWidth <= Spaces) {
   Spaces -= FirstTabWidth;

klimek wrote:
> Why is this not just if (FirstTabWidth <= Spaces) then?
Actually, that was my first way of fixing it. 

```
if (FirstTabWidth <= Spaces && Spaces > 1) // to avoid converting a single 
space to a tab
```

Doing so will produce a correct output but introduce what I thought could be an 
unwanted change : whitespace less than **TabWidth** might get converted to a 
tab.
The comment above the test seems to indicate that this behavior was not 
originally wanted, that's why I changed my mind. 

But after thinking it over, I think my fix attempt also introduce an unwanted 
change. I misinterpreted the original goal of this option.
I went back to the official documentation and it says

> Use tabs whenever we need to fill whitespace that spans at least from one tab 
> stop to the next one

This is clearly not what this code is doing. I can land another patch for a 
more appropriate fix but I wonder if this option should stay like this. Aren't 
people expecting the formatting to use as much tab as possible with UT_Always ?

Unless I'm mistaken, the following example (**TabWidth** of 4)


```
int a = 42;
int aa = 42;
int aaa = 42;
int  = 42;
```
would become (following what's written in the documentation)

```
int a= 42;
int aa   = 42;
int aaa  = 42;
int  = 42; 
// only spaces since there's never enough whitespace to span a full tab stop
```
And this is what I would expect:

```
int a= 42; // int a\t = 42;
int aa   = 42; // int aa\t = 42;
int aaa  = 42; // int aaa\t = 42;
int  = 42; // int  = 42;
```



Comment at: unittests/Format/FormatTest.cpp:9372
+  FormatStyle::UseTabStyle OldTabStyle = Alignment.UseTab;
+  unsigned OldTabWidth = Alignment.TabWidth;
+  Alignment.UseTab = FormatStyle::UT_Always;

klimek wrote:
> Instead of doing the save/restore dance, just put it at the end of a test or 
> create a new test (or alternatively create a new style as copy and then 
> change the settings on that).
I guess a new test would be better since the unit tests are really lacking 
toward using tabs.


Repository:
  rC Clang

https://reviews.llvm.org/D48259



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


[PATCH] D35110: [Analyzer] Constraint Manager Negates Difference

2018-06-19 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

I tested all parts of the Iterator Checkers, all tests passed.


https://reviews.llvm.org/D35110



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


[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman added inline comments.



Comment at: tools/clang-fuzzer/handle-llvm/\:62
+  initializeScavengerTestPass(*Registry);
+
+}

morehouse wrote:
> Does this initialization need to happen every time the fuzzer generates a new 
> input, or can we call this from `LLVMFuzzerInitialize()` instead?
I was following the pattern from `handle_cxx.cpp` in which the initialization 
calls were made every time a new input was generated. However looking at the 
documentation and at `llvm-isel-fuzzer.cpp`, it seems like putting it in 
`LLVMFuzzerInitialize()` makes more sense. I will make this change in the next 
commit.


Repository:
  rC Clang

https://reviews.llvm.org/D48106



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


[PATCH] D46485: Add python tool to dump and construct header maps

2018-06-19 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: utils/hmaptool/hmaptool:1
+#!/usr/bin/env python
+

Have you checked this works with both python2 and python3?



Comment at: utils/hmaptool/hmaptool:81
+path,))
+if strtable[-1] != '\0':
+raise SystemExit("error: %s: invalid string table in 
headermap" % (

You'll get an `IndexError` here if `strtable_size` is `0`.


https://reviews.llvm.org/D46485



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


[PATCH] D48291: [analyzer][UninitializedObjectChecker] Fixed captured lambda variable name

2018-06-19 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:685
+
+  if (CXXParent && CXXParent->isLambda()) {
+CXXRecordDecl::capture_const_iterator CapturedVar =

Szelethus wrote:
> george.karpenkov wrote:
> > CXXParent is guaranteed to be non-null at this stage, otherwise dyn_cast 
> > fails
> I found this on 
> http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates:
> 
> >dyn_cast<>:
> >
> >The dyn_cast<> operator is a “checking cast” operation. It checks to see 
> > if the operand is of the specified type, and if so, returns a pointer to it 
> > (this operator does not work with references). If the operand is not of the 
> > correct type, a null pointer is returned.
> 
> So I guess this should be alright.
Oops sorry my bad.


Repository:
  rC Clang

https://reviews.llvm.org/D48291



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


[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added inline comments.



Comment at: tools/clang-fuzzer/handle-llvm/CMakeLists.txt:5
+  handle_llvm.cpp
+  )

emmettneyman wrote:
> morehouse wrote:
> > There's fewer libraries linked here than in `handle-cxx/` (not saying this 
> > is wrong, but it could be).  Do you get link errors if you build 
> > `clang-llvm-proto-fuzzer` with shared libraries?
> It builds without any errors both with all the libraries from `handle-cxx/` 
> linked in and without any of the libraries linked in (as I have here). Which 
> is preferred?
I prefer what you have here, if shared libraries are OK.


Repository:
  rC Clang

https://reviews.llvm.org/D48106



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


[PATCH] D48297: [Darwin] Add a warning for missing include path for libstdc++

2018-06-19 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL335063: [Darwin] Add a warning for missing include path for 
libstdc++ (authored by arphaman, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48297?vs=151944&id=151946#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48297

Files:
  cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
  cfe/trunk/include/clang/Lex/HeaderSearch.h
  cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
  cfe/trunk/test/Frontend/warning-stdlibcxx-darwin.cpp

Index: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
===
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Config/config.h" // C_INCLUDE_DIRS
+#include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/HeaderSearch.h"
@@ -55,11 +56,13 @@
 
   /// AddPath - Add the specified path to the specified group list, prefixing
   /// the sysroot if used.
-  void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
+  /// Returns true if the path exists, false if it was ignored.
+  bool AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
 
   /// AddUnmappedPath - Add the specified path to the specified group list,
   /// without performing any sysroot remapping.
-  void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
+  /// Returns true if the path exists, false if it was ignored.
+  bool AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework);
 
   /// AddSystemHeaderPrefix - Add the specified prefix to the system header
@@ -70,10 +73,9 @@
 
   /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
   ///  libstdc++.
-  void AddGnuCPlusPlusIncludePaths(StringRef Base,
-   StringRef ArchDir,
-   StringRef Dir32,
-   StringRef Dir64,
+  /// Returns true if the \p Base path was found, false if it does not exist.
+  bool AddGnuCPlusPlusIncludePaths(StringRef Base, StringRef ArchDir,
+   StringRef Dir32, StringRef Dir64,
const llvm::Triple &triple);
 
   /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
@@ -88,7 +90,8 @@
 
   // AddDefaultCPlusPlusIncludePaths -  Add paths that should be searched when
   //  compiling c++.
-  void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
+  void AddDefaultCPlusPlusIncludePaths(const LangOptions &LangOpts,
+   const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts);
 
   /// AddDefaultSystemIncludePaths - Adds the default system include paths so
@@ -112,23 +115,22 @@
 #endif
 }
 
-void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
+bool InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework) {
   // Add the path with sysroot prepended, if desired and this is a system header
   // group.
   if (HasSysroot) {
 SmallString<256> MappedPathStorage;
 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
 if (CanPrefixSysroot(MappedPathStr)) {
-  AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
-  return;
+  return AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
 }
   }
 
-  AddUnmappedPath(Path, Group, isFramework);
+  return AddUnmappedPath(Path, Group, isFramework);
 }
 
-void InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
+bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework) {
   assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
 
@@ -150,7 +152,7 @@
   if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
 IncludePath.push_back(
   std::make_pair(Group, DirectoryLookup(DE, Type, isFramework)));
-return;
+return true;
   }
 
   // Check to see if this is an apple-style headermap (which are not allowed to
@@ -162,23 +164,24 @@
 IncludePath.push_back(
   std::make_pair(Group,
  DirectoryLookup(HM, Type, Group == IndexHeaderMap)));
-return;
+return true;
   }
 }
   }
 
   if (Verbose)
 llvm::errs() << "ignoring nonexistent directory \""
  << MappedPathStr << "\"\n";
+  return false;
 }
 
-void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
+bool InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,

r335063 - [Darwin] Add a warning for missing include path for libstdc++

2018-06-19 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jun 19 10:56:03 2018
New Revision: 335063

URL: http://llvm.org/viewvc/llvm-project?rev=335063&view=rev
Log:
[Darwin] Add a warning for missing include path for libstdc++

Xcode 10 removes support for libstdc++, but the users just get a confusing
include not file warning when including an STL header (when building for iOS6
which uses libstdc++ by default for example).
This patch adds a new warning that lets the user know that the libstdc++ include
path was not found to ensure that the user is more aware of why the error 
occurs.

rdar://40830462

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

Added:
cfe/trunk/test/Frontend/warning-stdlibcxx-darwin.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/lib/Frontend/InitHeaderSearch.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=335063&r1=335062&r2=335063&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Tue Jun 19 
10:56:03 2018
@@ -236,4 +236,9 @@ def err_invalid_vfs_overlay : Error<
 
 def warn_option_invalid_ocl_version : Warning<
   "OpenCL version %0 does not support the option '%1'">, InGroup;
+
+def warn_stdlibcxx_not_found : Warning<
+  "include path for stdlibc++ headers not found; pass '-std=libc++' on the "
+  "command line to use the libc++ standard library instead">,
+  InGroup>;
 }

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=335063&r1=335062&r2=335063&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Tue Jun 19 10:56:03 2018
@@ -272,6 +272,8 @@ public:
   
   FileManager &getFileMgr() const { return FileMgr; }
 
+  DiagnosticsEngine &getDiags() const { return Diags; }
+
   /// Interface for setting the file search paths.
   void SetSearchPaths(const std::vector &dirs,
   unsigned angledDirIdx, unsigned systemDirIdx,

Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=335063&r1=335062&r2=335063&view=diff
==
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Tue Jun 19 10:56:03 2018
@@ -14,6 +14,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Config/config.h" // C_INCLUDE_DIRS
+#include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/HeaderSearch.h"
@@ -55,11 +56,13 @@ public:
 
   /// AddPath - Add the specified path to the specified group list, prefixing
   /// the sysroot if used.
-  void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
+  /// Returns true if the path exists, false if it was ignored.
+  bool AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
 
   /// AddUnmappedPath - Add the specified path to the specified group list,
   /// without performing any sysroot remapping.
-  void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
+  /// Returns true if the path exists, false if it was ignored.
+  bool AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework);
 
   /// AddSystemHeaderPrefix - Add the specified prefix to the system header
@@ -70,10 +73,9 @@ public:
 
   /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
   ///  libstdc++.
-  void AddGnuCPlusPlusIncludePaths(StringRef Base,
-   StringRef ArchDir,
-   StringRef Dir32,
-   StringRef Dir64,
+  /// Returns true if the \p Base path was found, false if it does not exist.
+  bool AddGnuCPlusPlusIncludePaths(StringRef Base, StringRef ArchDir,
+   StringRef Dir32, StringRef Dir64,
const llvm::Triple &triple);
 
   /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a 
MinGW
@@ -88,7 +90,8 @@ public:
 
   // AddDefaultCPlusPlusIncludePaths -  Add paths that should be searched when
   //  compiling c++.
-  void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
+  void AddDefaultCPlusPlusIncludePaths(const LangOptions &LangOpts,
+   const llvm::Triple &triple,
const HeaderSearchOptions &

[PATCH] D48318: [analyzer][UninitializedObjectChecker] Drop lambda support

2018-06-19 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus abandoned this revision.
Szelethus added a comment.

Turns out I was very wrong on this one. Lambdas should be ignored as data 
members, but not in general.

Sorry about the spam, I think I should've sit longer on this one. I'll submit 
another patch tomorrow that will correctly explain my current way of thinking 
on this issue.


Repository:
  rC Clang

https://reviews.llvm.org/D48318



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


[PATCH] D48297: [Darwin] Add a warning for missing include path for libstdc++

2018-06-19 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D48297



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


[PATCH] D48106: implemented proto to llvm

2018-06-19 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman added inline comments.



Comment at: tools/clang-fuzzer/handle-llvm/CMakeLists.txt:5
+  handle_llvm.cpp
+  )

morehouse wrote:
> There's fewer libraries linked here than in `handle-cxx/` (not saying this is 
> wrong, but it could be).  Do you get link errors if you build 
> `clang-llvm-proto-fuzzer` with shared libraries?
It builds without any errors both with all the libraries from `handle-cxx/` 
linked in and without any of the libraries linked in (as I have here). Which is 
preferred?


Repository:
  rC Clang

https://reviews.llvm.org/D48106



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


[PATCH] D48297: [Darwin] Add a warning for missing include path for libstdc++

2018-06-19 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 151944.
arphaman marked 3 inline comments as done.
arphaman added a comment.

Addressed review comments


https://reviews.llvm.org/D48297

Files:
  include/clang/Basic/DiagnosticFrontendKinds.td
  include/clang/Lex/HeaderSearch.h
  lib/Frontend/InitHeaderSearch.cpp
  test/Frontend/warning-stdlibcxx-darwin.cpp

Index: test/Frontend/warning-stdlibcxx-darwin.cpp
===
--- /dev/null
+++ test/Frontend/warning-stdlibcxx-darwin.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -cc1 -triple arm64-apple-ios6.0.0 -isysroot %S/doesnotexist %s 2>&1 | FileCheck %s
+// RUN: %clang -cc1 -triple arm64-apple-ios6.0.0 -isysroot %S/doesnotexist -stdlib=libc++ %s -verify
+// CHECK: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead
+
+// expected-no-diagnostics
Index: lib/Frontend/InitHeaderSearch.cpp
===
--- lib/Frontend/InitHeaderSearch.cpp
+++ lib/Frontend/InitHeaderSearch.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Config/config.h" // C_INCLUDE_DIRS
+#include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/HeaderSearch.h"
@@ -55,11 +56,13 @@
 
   /// AddPath - Add the specified path to the specified group list, prefixing
   /// the sysroot if used.
-  void AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
+  /// Returns true if the path exists, false if it was ignored.
+  bool AddPath(const Twine &Path, IncludeDirGroup Group, bool isFramework);
 
   /// AddUnmappedPath - Add the specified path to the specified group list,
   /// without performing any sysroot remapping.
-  void AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
+  /// Returns true if the path exists, false if it was ignored.
+  bool AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework);
 
   /// AddSystemHeaderPrefix - Add the specified prefix to the system header
@@ -70,10 +73,9 @@
 
   /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
   ///  libstdc++.
-  void AddGnuCPlusPlusIncludePaths(StringRef Base,
-   StringRef ArchDir,
-   StringRef Dir32,
-   StringRef Dir64,
+  /// Returns true if the \p Base path was found, false if it does not exist.
+  bool AddGnuCPlusPlusIncludePaths(StringRef Base, StringRef ArchDir,
+   StringRef Dir32, StringRef Dir64,
const llvm::Triple &triple);
 
   /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
@@ -88,7 +90,8 @@
 
   // AddDefaultCPlusPlusIncludePaths -  Add paths that should be searched when
   //  compiling c++.
-  void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
+  void AddDefaultCPlusPlusIncludePaths(const LangOptions &LangOpts,
+   const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts);
 
   /// AddDefaultSystemIncludePaths - Adds the default system include paths so
@@ -112,23 +115,22 @@
 #endif
 }
 
-void InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
+bool InitHeaderSearch::AddPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework) {
   // Add the path with sysroot prepended, if desired and this is a system header
   // group.
   if (HasSysroot) {
 SmallString<256> MappedPathStorage;
 StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
 if (CanPrefixSysroot(MappedPathStr)) {
-  AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
-  return;
+  return AddUnmappedPath(IncludeSysroot + Path, Group, isFramework);
 }
   }
 
-  AddUnmappedPath(Path, Group, isFramework);
+  return AddUnmappedPath(Path, Group, isFramework);
 }
 
-void InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
+bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
bool isFramework) {
   assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
 
@@ -150,7 +152,7 @@
   if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) {
 IncludePath.push_back(
   std::make_pair(Group, DirectoryLookup(DE, Type, isFramework)));
-return;
+return true;
   }
 
   // Check to see if this is an apple-style headermap (which are not allowed to
@@ -162,23 +164,24 @@
 IncludePath.push_back(
   std::make_pair(Group,
  DirectoryLookup(HM, Type, Group == IndexHeaderMap)));
-return;
+return true;
   }
 }
   }
 
   if (Ve

[PATCH] D48297: [Darwin] Add a warning for missing include path for libstdc++

2018-06-19 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman marked 3 inline comments as done.
arphaman added inline comments.



Comment at: lib/Frontend/InitHeaderSearch.cpp:374-377
+  IsBaseFound = AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
+"powerpc-apple-darwin10", "",
+"ppc64", triple);
+  IsBaseFound &= AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",

vsapsai wrote:
> Why are you using `&=` here instead of `|=`? I haven't tested but I expect 
> that either 4.2.1 will work or 4.0.0, you don't need both of them.
Good catch, fixed.



Comment at: lib/Frontend/InitHeaderSearch.cpp:404
 }
+if (!IsBaseFound && !LangOpts.CUDA)
+  Headers.getDiags().Report(SourceLocation(),

vsapsai wrote:
> What is so special about CUDA? Is it OK to emit the warning for OpenCL, for 
> instance?
We're looking to warn for pure C++/ObjC++, so I will disable it for other 
language dialects.



Comment at: test/Frontend/warning-stdlibcxx-darwin.cpp:1-2
+// RUN: %clang -cc1 -triple arm64-apple-ios6.0.0 -isysroot %S/doesnotexist %s 
2>&1 | FileCheck %s
+// CHECK: include path for stdlibc++ headers not found; pass '-std=libc++' on 
the command line to use the libc++ standard library instead

vsapsai wrote:
> Do you think there is a value in adding a test that does exactly what the 
> warning suggests and verifies there are no warnings?
Good call.


Repository:
  rC Clang

https://reviews.llvm.org/D48297



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


[PATCH] D48325: [analyzer][UninitializedObjectChecker] Support for MemberPointerTypes

2018-06-19 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 151943.
Szelethus added a comment.

Accidently added the pointer `MemberPointer` objects twice, fixed that.


https://reviews.llvm.org/D48325

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object-ptr-ref.cpp


Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -416,14 +416,12 @@
 
 #ifdef PEDANTIC
 struct PointerToMemberFunctionTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  void (UsefulFunctions::*f)(void); // no-note
+  void (UsefulFunctions::*f)(void); // expected-note{{uninitialized field 
'this->f'}}
   PointerToMemberFunctionTest1() {}
 };
 
 void fPointerToMemberFunctionTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberFunctionTest1(); // no-warning
+  PointerToMemberFunctionTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberFunctionTest2 {
@@ -460,14 +458,12 @@
 }
 
 struct PointerToMemberDataTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  int UsefulFunctions::*d; // no-note
+  int UsefulFunctions::*d; // expected-note{{uninitialized field 'this->d'}}
   PointerToMemberDataTest1() {}
 };
 
 void fPointerToMemberDataTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberDataTest1(); // no-warning
+  PointerToMemberDataTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberDataTest2 {
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -389,15 +389,14 @@
   continue;
 }
 
-if (T->isMemberPointerType()) {
-  if (isMemberPointerUninit(FR, LocalChain))
+if (T->isPointerType() || T->isReferenceType()) {
+  if (isPointerOrReferenceUninit(FR, LocalChain))
 ContainsUninitField = true;
   continue;
 }
 
-// If this is a pointer or reference type.
-if (T->isPointerType() || T->isReferenceType()) {
-  if (isPointerOrReferenceUninit(FR, LocalChain))
+if (T->isMemberPointerType()) {
+  if (isMemberPointerUninit(FR, LocalChain))
 ContainsUninitField = true;
   continue;
 }
@@ -521,6 +520,10 @@
   }
 }
 
+if (T->isMemberPointerType()) {
+  return isMemberPointerUninit(FR, LocalChain);
+}
+
 if (T->isArrayType()) {
   IsAnyFieldInitialized = true;
   return false;
@@ -543,7 +546,12 @@
 FieldChainInfo LocalChain) 
{
   assert(FR->getDecl()->getType()->isMemberPointerType() &&
  "This function only checks regions that hold MemberPointerTypes!");
-  // TODO: Implement support for MemberPointerTypes.
+
+  SVal V = State->getSVal(FR);
+  if (V.isUndef())
+return addFieldToUninits({LocalChain, FR});
+
+  IsAnyFieldInitialized = true;
   return false;
 }
 


Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -416,14 +416,12 @@
 
 #ifdef PEDANTIC
 struct PointerToMemberFunctionTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  void (UsefulFunctions::*f)(void); // no-note
+  void (UsefulFunctions::*f)(void); // expected-note{{uninitialized field 'this->f'}}
   PointerToMemberFunctionTest1() {}
 };
 
 void fPointerToMemberFunctionTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberFunctionTest1(); // no-warning
+  PointerToMemberFunctionTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberFunctionTest2 {
@@ -460,14 +458,12 @@
 }
 
 struct PointerToMemberDataTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  int UsefulFunctions::*d; // no-note
+  int UsefulFunctions::*d; // expected-note{{uninitialized field 'this->d'}}
   PointerToMemberDataTest1() {}
 };
 
 void fPointerToMemberDataTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberDataTest1(); // no-warning
+  PointerToMemberDataTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberDataTest2 {
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -389,15 +389,14 @@
   continue;
 }
 
-if (T->isMemberPointerType()) {
-  if (isMemberPointerUni

[PATCH] D48188: [SPIR] Prevent SPIR targets from using half conversion intrinsics

2018-06-19 Thread Stephen McGroarty via Phabricator via cfe-commits
smcgro added a comment.

That's great @SjoerdMeijer , thanks for the review. I don't have commit access 
to clang so if there are no more reviews then it would be great if someone 
could commit this for me, thanks.


https://reviews.llvm.org/D48188



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


[PATCH] D48188: [SPIR] Prevent SPIR targets from using half conversion intrinsics

2018-06-19 Thread Stephen McGroarty via Phabricator via cfe-commits
smcgro updated this revision to Diff 151938.
smcgro added a comment.

Added a function parameter to one of the functions


https://reviews.llvm.org/D48188

Files:
  lib/Basic/Targets/SPIR.h
  test/CodeGen/spir-half-type.cpp

Index: test/CodeGen/spir-half-type.cpp
===
--- /dev/null
+++ test/CodeGen/spir-half-type.cpp
@@ -0,0 +1,146 @@
+// RUN: %clang_cc1 -O0 -triple spir -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir64 -emit-llvm %s -o - | FileCheck %s
+
+// This file tests that using the _Float16 type with the spir target will not
+// use the llvm intrinsics but instead will use the half arithmetic
+// instructions directly.
+
+// Previously attempting to use a constant _Float16 with a comparison
+// instruction when the target is spir or spir64 lead to an assert being hit.
+bool fcmp_const() {
+  _Float16 a = 0.0f16;
+  const _Float16 b = 1.0f16;
+
+  // CHECK-NOT: llvm.convert.to.fp16
+  // CHECK-NOT: llvm.convert.from.fp16
+
+  // CHECK: [[REG1:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp olt half [[REG1]], 0xH3C00
+
+  // CHECK: [[REG2:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp olt half [[REG2]], 0xH4000
+
+  // CHECK: [[REG3:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp ogt half [[REG3]], 0xH3C00
+
+  // CHECK: [[REG4:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp ogt half [[REG4]], 0xH4200
+
+  // CHECK: [[REG5:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp oeq half [[REG5]], 0xH3C00
+
+  // CHECK: [[REG7:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp oeq half [[REG7]], 0xH4400
+
+  // CHECK: [[REG8:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp une half [[REG8]], 0xH3C00
+
+  // CHECK: [[REG9:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp une half [[REG9]], 0xH4500
+
+  // CHECK: [[REG10:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp ole half [[REG10]], 0xH3C00
+
+  // CHECK: [[REG11:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp ole half [[REG11]], 0xH4600
+
+  // CHECK: [[REG12:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp oge half [[REG12]], 0xH3C00
+
+  // CHECK: [[REG13:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: fcmp oge half [[REG13]], 0xH4700
+  return a < b || a < 2.0f16 || a > b || a > 3.0f16 || a == b || a == 4.0f16 ||
+ a != b || a != 5.0f16 || a <= b || a <= 6.0f16 || a >= b ||
+ a >= 7.0f16;
+}
+
+bool fcmp() {
+  _Float16 a = 0.0f16;
+  _Float16 b = 1.0f16;
+
+  // CHECK-NOT: llvm.convert.to.fp16
+  // CHECK-NOT: llvm.convert.from.fp16
+  // CHECK: [[REG1:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: [[REG2:%.*]] = load half, half* %b, align 2
+  // CHECK-NEXT: fcmp olt half [[REG1]], [[REG2]]
+
+  // CHECK: [[REG3:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: [[REG4:%.*]] = load half, half* %b, align 2
+  // CHECK-NEXT: fcmp ogt half [[REG3]], [[REG4]]
+
+  // CHECK: [[REG5:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: [[REG6:%.*]] = load half, half* %b, align 2
+  // CHECK-NEXT: fcmp oeq half [[REG5]], [[REG6]]
+
+  // CHECK: [[REG7:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: [[REG8:%.*]] = load half, half* %b, align 2
+  // CHECK-NEXT: fcmp une half [[REG7]], [[REG8]]
+
+  // CHECK: [[REG7:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: [[REG8:%.*]] = load half, half* %b, align 2
+  // CHECK-NEXT: fcmp ole half [[REG7]], [[REG8]]
+
+  // CHECK: [[REG7:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: [[REG8:%.*]] = load half, half* %b, align 2
+  // CHECK-NEXT: fcmp oge half [[REG7]], [[REG8]]
+  return a < b || a > b || a == b || a != b || a <= b || a >= b;
+}
+
+_Float16 fadd() {
+  _Float16 a = 1.0f16;
+  const _Float16 b = 2.0f16;
+
+  // CHECK-NOT: llvm.convert.to.fp16
+  // CHECK-NOT: llvm.convert.from.fp16
+
+  // CHECK: [[REG1:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: [[REG2:%.*]] = fadd half [[REG1]], 0xH4000
+  // CHECK-NEXT: [[REG3:%.*]] = fadd half [[REG2]], 0xH4200
+  // CHECK-NEXT: ret half [[REG3]]
+  return a + b + 3.0f16;
+}
+
+_Float16 fsub() {
+  _Float16 a = 1.0f16;
+  const _Float16 b = 2.0f16;
+
+  // CHECK-NOT: llvm.convert.to.fp16
+  // CHECK-NOT: llvm.convert.from.fp16
+
+  // CHECK: [[REG1:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: [[REG2:%.*]] = fsub half [[REG1]], 0xH4000
+  // CHECK-NEXT: [[REG3:%.*]] = fsub half [[REG2]], 0xH4200
+  // CHECK-NEXT: ret half [[REG3]]
+  return a - b - 3.0f16;
+}
+
+// CHECK: define spir_func half @_Z4fmulDF16_(half %arg)
+_Float16 fmul(_Float16 arg) {
+  _Float16 a = 1.0f16;
+  const _Float16 b = 2.0f16;
+
+  // CHECK-NOT: llvm.convert.to.fp16
+  // CHECK-NOT: llvm.convert.from.fp16
+
+  // CHECK: [[REG1:%.*]] = load half, half* %a, align 2
+  // CHECK-NEXT: [[REG2:%.*]] = load half, half* %arg.addr, align 2
+  // CHECK-NEXT: [[REG3:%.*]] = fmul half [[REG1]], [[REG2]]
+  // CHECK-NEXT:

[PATCH] D45616: [X86] Lower _mm[256|512]_cmp[.]_mask intrinsics to native llvm IR

2018-06-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper requested changes to this revision.
craig.topper added inline comments.
This revision now requires changes to proceed.



Comment at: test/CodeGen/avx-builtins.c:241
   // CHECK-LABEL: test_mm_cmp_sd
-  // CHECK: call <2 x double> @llvm.x86.sse2.cmp.sd(<2 x double> %{{.*}}, <2 x 
double> %{{.*}}, i8 13)
+  // CHECK: [[CMP:%.*]] = fcmp oge <2 x double> %{{.*}}, %{{.*}}
   return _mm_cmp_sd(A, B, _CMP_GE_OS);

This doesn't look right. This is a scalar instructino it shoudl only be 
comparing a single double. There should be insertelementss and extractelements.



Comment at: test/CodeGen/avx512f-builtins.c:7449
   // CHECK-LABEL: @test_mm_cmp_round_ss_mask
-  // CHECK: @llvm.x86.avx512.mask.cmp
+  // CHECK: fcmp uge <4 x float> %{{.*}}, %{{.*}}
+  // CHECK: shufflevector <4 x i1> %{{.*}}, <4 x i1> zeroinitializer, <8 x 
i32> 

I don't think this is right either.


https://reviews.llvm.org/D45616



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


[PATCH] D48325: [analyzer][UninitializedObjectChecker] Support for MemberPointerTypes

2018-06-19 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, rnkovacs.
Herald added subscribers: cfe-commits, mikhail.ramalho, a.sidorin, szepet, 
whisperity.

Repository:
  rC Clang

https://reviews.llvm.org/D48325

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object-ptr-ref.cpp


Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -416,14 +416,12 @@
 
 #ifdef PEDANTIC
 struct PointerToMemberFunctionTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  void (UsefulFunctions::*f)(void); // no-note
+  void (UsefulFunctions::*f)(void); // expected-note{{uninitialized field 
'this->f'}}
   PointerToMemberFunctionTest1() {}
 };
 
 void fPointerToMemberFunctionTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberFunctionTest1(); // no-warning
+  PointerToMemberFunctionTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberFunctionTest2 {
@@ -460,14 +458,12 @@
 }
 
 struct PointerToMemberDataTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  int UsefulFunctions::*d; // no-note
+  int UsefulFunctions::*d; // expected-note{{uninitialized field 'this->d'}}
   PointerToMemberDataTest1() {}
 };
 
 void fPointerToMemberDataTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberDataTest1(); // no-warning
+  PointerToMemberDataTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberDataTest2 {
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -389,15 +389,14 @@
   continue;
 }
 
-if (T->isMemberPointerType()) {
-  if (isMemberPointerUninit(FR, LocalChain))
+if (T->isPointerType() || T->isReferenceType()) {
+  if (isPointerOrReferenceUninit(FR, LocalChain))
 ContainsUninitField = true;
   continue;
 }
 
-// If this is a pointer or reference type.
-if (T->isPointerType() || T->isReferenceType()) {
-  if (isPointerOrReferenceUninit(FR, LocalChain))
+if (T->isMemberPointerType()) {
+  if (isMemberPointerUninit(FR, LocalChain))
 ContainsUninitField = true;
   continue;
 }
@@ -521,6 +520,12 @@
   }
 }
 
+if (T->isMemberPointerType()) {
+  if (isMemberPointerUninit(FR, LocalChain))
+return addFieldToUninits({LocalChain, FR, /*IsDereferenced*/ true});
+  return false;
+}
+
 if (T->isArrayType()) {
   IsAnyFieldInitialized = true;
   return false;
@@ -543,7 +548,12 @@
 FieldChainInfo LocalChain) 
{
   assert(FR->getDecl()->getType()->isMemberPointerType() &&
  "This function only checks regions that hold MemberPointerTypes!");
-  // TODO: Implement support for MemberPointerTypes.
+
+  SVal V = State->getSVal(FR);
+  if (V.isUndef())
+return addFieldToUninits({LocalChain, FR});
+
+  IsAnyFieldInitialized = true;
   return false;
 }
 


Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -416,14 +416,12 @@
 
 #ifdef PEDANTIC
 struct PointerToMemberFunctionTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  void (UsefulFunctions::*f)(void); // no-note
+  void (UsefulFunctions::*f)(void); // expected-note{{uninitialized field 'this->f'}}
   PointerToMemberFunctionTest1() {}
 };
 
 void fPointerToMemberFunctionTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberFunctionTest1(); // no-warning
+  PointerToMemberFunctionTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberFunctionTest2 {
@@ -460,14 +458,12 @@
 }
 
 struct PointerToMemberDataTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  int UsefulFunctions::*d; // no-note
+  int UsefulFunctions::*d; // expected-note{{uninitialized field 'this->d'}}
   PointerToMemberDataTest1() {}
 };
 
 void fPointerToMemberDataTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberDataTest1(); // no-warning
+  PointerToMemberDataTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberDataTest2 {
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/Static

[PATCH] D48291: [analyzer][UninitializedObjectChecker] Fixed captured lambda variable name

2018-06-19 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:685
+
+  if (CXXParent && CXXParent->isLambda()) {
+CXXRecordDecl::capture_const_iterator CapturedVar =

george.karpenkov wrote:
> CXXParent is guaranteed to be non-null at this stage, otherwise dyn_cast fails
I found this on 
http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates:

>dyn_cast<>:
>
>The dyn_cast<> operator is a “checking cast” operation. It checks to see 
> if the operand is of the specified type, and if so, returns a pointer to it 
> (this operator does not work with references). If the operand is not of the 
> correct type, a null pointer is returned.

So I guess this should be alright.


Repository:
  rC Clang

https://reviews.llvm.org/D48291



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


[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-06-19 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan accepted this revision.
ebevhan added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Sema/SemaExpr.cpp:1248
+  bool RHSFixed = RHSType->isFixedPointType();
+
+  if (LHSFixed && RHSFixed) {

leonardchan wrote:
> ebevhan wrote:
> > leonardchan wrote:
> > > leonardchan wrote:
> > > > ebevhan wrote:
> > > > > ebevhan wrote:
> > > > > > leonardchan wrote:
> > > > > > > leonardchan wrote:
> > > > > > > > ebevhan wrote:
> > > > > > > > > ebevhan wrote:
> > > > > > > > > > leonardchan wrote:
> > > > > > > > > > > ebevhan wrote:
> > > > > > > > > > > > leonardchan wrote:
> > > > > > > > > > > > > ebevhan wrote:
> > > > > > > > > > > > > > I don't see how these semantics work properly. The 
> > > > > > > > > > > > > > specification requires that operations be done in 
> > > > > > > > > > > > > > the full precision of both types. You cannot 
> > > > > > > > > > > > > > convert the types before performing the operation 
> > > > > > > > > > > > > > like this, since the operation will not be done in 
> > > > > > > > > > > > > > full precision in that case.
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > > The operator semantics of Embedded-C require the 
> > > > > > > > > > > > > > operand types of binary operators to be different. 
> > > > > > > > > > > > > > It's only when you've performed the operation that 
> > > > > > > > > > > > > > you are allowed to convert the result to the 
> > > > > > > > > > > > > > resulting type.
> > > > > > > > > > > > > Initially the idea was to convert both sides to fixed 
> > > > > > > > > > > > > point types, then perform standard binary operations 
> > > > > > > > > > > > > between the fixed point types.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > For the example, a `fract * int` would have the int 
> > > > > > > > > > > > > converted to a fixed point type by left shifting it 
> > > > > > > > > > > > > by the scale of the fract, multiplying, then right 
> > > > > > > > > > > > > shifting by the scale again to get the resulting 
> > > > > > > > > > > > > fract. The only unhandled thing is overflow, but the 
> > > > > > > > > > > > > precision of the fract remains the same. The operands 
> > > > > > > > > > > > > would also be casted up beforehand so there was 
> > > > > > > > > > > > > enough space to store the result, which was casted 
> > > > > > > > > > > > > down back to the original fract after performing the 
> > > > > > > > > > > > > right shift by the scale.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > Operations between fixed point types would follow a 
> > > > > > > > > > > > > similar process of casting both operands to the 
> > > > > > > > > > > > > higher rank fixed point type, and depending on the 
> > > > > > > > > > > > > operation, more underlying shifting and casting would 
> > > > > > > > > > > > > be done to retain full precision of the higher ranked 
> > > > > > > > > > > > > type.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > Though I will admit that I did not realize until now 
> > > > > > > > > > > > > that multiplying a fixed point type by an integer 
> > > > > > > > > > > > > does not require shifting the integer.
> > > > > > > > > > > > I see how you've reasoned; this is how C normally 
> > > > > > > > > > > > works. The `fract` is of higher rank than `int` and 
> > > > > > > > > > > > therefore is the 'common type' of the operation. 
> > > > > > > > > > > > However, even though it is higher rank there is no 
> > > > > > > > > > > > guarantee that you can perform the operation without 
> > > > > > > > > > > > overflowing. And overflow matters here; the spec says 
> > > > > > > > > > > > that it must be done in the full precision (integral + 
> > > > > > > > > > > > fractional) of both types.
> > > > > > > > > > > > 
> > > > > > > > > > > > > The only unhandled thing is overflow, but the 
> > > > > > > > > > > > > precision of the fract remains the same. The operands 
> > > > > > > > > > > > > would also be casted up beforehand so there was 
> > > > > > > > > > > > > enough space to store the result, which was casted 
> > > > > > > > > > > > > down back to the original fract after performing the 
> > > > > > > > > > > > > right shift by the scale.
> > > > > > > > > > > > 
> > > > > > > > > > > > The precision remains the same (and while it doesn't 
> > > > > > > > > > > > have to be the same to perform an operation, it makes 
> > > > > > > > > > > > the implementation more regular; things like addition 
> > > > > > > > > > > > and subtraction 'just work'), but you cannot perform a 
> > > > > > > > > > > > conversion to `fract` *before* the operation itself, 
> > > > > > > > > > > > since if you do, there's nothing to 'cast up'. Casting 
> > > > > > > > > > > > up is needed for things like `fract * fract` to prevent 
> > > > > > > > > > > > overflow, but for `fract * int` you need to cast to a 
> > > > > > > > > > > > type that can fit both all values o

[PATCH] D47953: [builtin] Add bitfield support for __builtin_dump_struct

2018-06-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:1250
+  if (Info.IsSigned) {
+unsigned HighBits = Info.StorageSize - Info.Offset - Info.Size;
+if (HighBits)

What happens if this overflows due to being < 0?


Repository:
  rC Clang

https://reviews.llvm.org/D47953



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


[PATCH] D47367: [ASTImporter] Add ms compatibility to tests

2018-06-19 Thread Gabor Marton via Phabricator via cfe-commits
martong requested review of this revision.
martong added a comment.

Ping.


Repository:
  rC Clang

https://reviews.llvm.org/D47367



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


[PATCH] D48100: Append new attributes to the end of an AttributeList.

2018-06-19 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, thank you for this!


Repository:
  rC Clang

https://reviews.llvm.org/D48100



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


[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-06-19 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 151919.
leonardchan marked 2 inline comments as done.

Repository:
  rC Clang

https://reviews.llvm.org/D46915

Files:
  include/clang-c/Index.h
  include/clang/AST/ASTContext.h
  include/clang/AST/Expr.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Basic/StmtNodes.td
  include/clang/Basic/TargetInfo.h
  include/clang/Driver/Options.td
  include/clang/Lex/LiteralSupport.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTDumper.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/AST/Type.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/LiteralSupport.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Frontend/fixed_point.c
  test/Frontend/fixed_point_bit_widths.c
  test/Frontend/fixed_point_declarations.c
  test/Frontend/fixed_point_errors.c
  test/Frontend/fixed_point_same_fbits.c
  tools/libclang/CIndex.cpp
  tools/libclang/CXCursor.cpp

Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -305,6 +305,10 @@
 K = CXCursor_IntegerLiteral;
 break;
 
+  case Stmt::FixedPointLiteralClass:
+K = CXCursor_FixedPointLiteral;
+break;
+
   case Stmt::FloatingLiteralClass:
 K = CXCursor_FloatingLiteral;
 break;
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -5061,6 +5061,8 @@
 return cxstring::createRef("VariableRef");
   case CXCursor_IntegerLiteral:
   return cxstring::createRef("IntegerLiteral");
+  case CXCursor_FixedPointLiteral:
+  return cxstring::createRef("FixedPointLiteral");
   case CXCursor_FloatingLiteral:
   return cxstring::createRef("FloatingLiteral");
   case CXCursor_ImaginaryLiteral:
Index: test/Frontend/fixed_point_same_fbits.c
===
--- /dev/null
+++ test/Frontend/fixed_point_same_fbits.c
@@ -0,0 +1,28 @@
+// RUN: %clang -ffixed-point -S -emit-llvm -o - %s | FileCheck %s -check-prefix=DEFAULT
+// RUN: %clang -ffixed-point -fsame-fbits -S -emit-llvm -o - %s | FileCheck %s -check-prefix=SAME
+
+/* The scale for unsigned fixed point types should be the same as that of signed
+ * fixed point types when -fsame-fbits is enabled. */
+
+void func() {
+  unsigned short _Accum u_short_accum = 0.5uhk;
+  unsigned _Accum u_accum = 0.5uk;
+  unsigned long _Accum u_long_accum = 0.5ulk;
+  unsigned short _Fract u_short_fract = 0.5uhr;
+  unsigned _Fract u_fract = 0.5ur;
+  unsigned long _Fract u_long_fract = 0.5ulr;
+
+// DEFAULT: store i16 128, i16* %u_short_accum, align 2
+// DEFAULT: store i32 32768, i32* %u_accum, align 4
+// DEFAULT: store i64 2147483648, i64* %u_long_accum, align 8
+// DEFAULT: store i8  -128, i8* %u_short_fract, align 1
+// DEFAULT: store i16 -32768, i16* %u_fract, align 2
+// DEFAULT: store i32 -2147483648, i32* %u_long_fract, align 4
+
+// SAME: store i16 64, i16* %u_short_accum, align 2
+// SAME: store i32 16384, i32* %u_accum, align 4
+// SAME: store i64 1073741824, i64* %u_long_accum, align 8
+// SAME: store i8  64, i8* %u_short_fract, align 1
+// SAME: store i16 16384, i16* %u_fract, align 2
+// SAME: store i32 1073741824, i32* %u_long_fract, align 4
+}
Index: test/Frontend/fixed_point_errors.c
===
--- test/Frontend/fixed_point_errors.c
+++ test/Frontend/fixed_point_errors.c
@@ -78,6 +78,50 @@
 _Sat int i;   // expected-error{{'_Sat' specifier is only valid on '_Fract' or '_Accum', not 'int'}}
 _Sat _Sat _Fract fract;   // expected-warning{{duplicate '_Sat' declaration specifier}}
 
+
+/* Literals that cannot fit into types */
+signed short _Accum s_short_accum = 256.0hk;// expected-error{{this value is too large for this fixed point type}}
+unsigned short _Accum u_short_accum = 256.0uhk; // expected-error{{this value is too large for this fixed point type}}
+signed _Accum s_accum = 65536.0k;   // expected-error{{this value is too large for this fixed point type}}
+unsigned _Accum u_accum = 65536.0uk;// expected-error{{this value is too large for this fixed point type}}
+signed long _Accum s_long_accum = 4294967296.0lk;   // expected-error{{this value is too large for this fixed point type}}
+unsigned long _Accum u_long_accum = 4294967296.0ulk; 

[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-06-19 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan marked an inline comment as done.
leonardchan added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:1248
+  bool RHSFixed = RHSType->isFixedPointType();
+
+  if (LHSFixed && RHSFixed) {

ebevhan wrote:
> leonardchan wrote:
> > leonardchan wrote:
> > > ebevhan wrote:
> > > > ebevhan wrote:
> > > > > leonardchan wrote:
> > > > > > leonardchan wrote:
> > > > > > > ebevhan wrote:
> > > > > > > > ebevhan wrote:
> > > > > > > > > leonardchan wrote:
> > > > > > > > > > ebevhan wrote:
> > > > > > > > > > > leonardchan wrote:
> > > > > > > > > > > > ebevhan wrote:
> > > > > > > > > > > > > I don't see how these semantics work properly. The 
> > > > > > > > > > > > > specification requires that operations be done in the 
> > > > > > > > > > > > > full precision of both types. You cannot convert the 
> > > > > > > > > > > > > types before performing the operation like this, 
> > > > > > > > > > > > > since the operation will not be done in full 
> > > > > > > > > > > > > precision in that case.
> > > > > > > > > > > > > 
> > > > > > > > > > > > > The operator semantics of Embedded-C require the 
> > > > > > > > > > > > > operand types of binary operators to be different. 
> > > > > > > > > > > > > It's only when you've performed the operation that 
> > > > > > > > > > > > > you are allowed to convert the result to the 
> > > > > > > > > > > > > resulting type.
> > > > > > > > > > > > Initially the idea was to convert both sides to fixed 
> > > > > > > > > > > > point types, then perform standard binary operations 
> > > > > > > > > > > > between the fixed point types.
> > > > > > > > > > > > 
> > > > > > > > > > > > For the example, a `fract * int` would have the int 
> > > > > > > > > > > > converted to a fixed point type by left shifting it by 
> > > > > > > > > > > > the scale of the fract, multiplying, then right 
> > > > > > > > > > > > shifting by the scale again to get the resulting fract. 
> > > > > > > > > > > > The only unhandled thing is overflow, but the precision 
> > > > > > > > > > > > of the fract remains the same. The operands would also 
> > > > > > > > > > > > be casted up beforehand so there was enough space to 
> > > > > > > > > > > > store the result, which was casted down back to the 
> > > > > > > > > > > > original fract after performing the right shift by the 
> > > > > > > > > > > > scale.
> > > > > > > > > > > > 
> > > > > > > > > > > > Operations between fixed point types would follow a 
> > > > > > > > > > > > similar process of casting both operands to the higher 
> > > > > > > > > > > > rank fixed point type, and depending on the operation, 
> > > > > > > > > > > > more underlying shifting and casting would be done to 
> > > > > > > > > > > > retain full precision of the higher ranked type.
> > > > > > > > > > > > 
> > > > > > > > > > > > Though I will admit that I did not realize until now 
> > > > > > > > > > > > that multiplying a fixed point type by an integer does 
> > > > > > > > > > > > not require shifting the integer.
> > > > > > > > > > > I see how you've reasoned; this is how C normally works. 
> > > > > > > > > > > The `fract` is of higher rank than `int` and therefore is 
> > > > > > > > > > > the 'common type' of the operation. However, even though 
> > > > > > > > > > > it is higher rank there is no guarantee that you can 
> > > > > > > > > > > perform the operation without overflowing. And overflow 
> > > > > > > > > > > matters here; the spec says that it must be done in the 
> > > > > > > > > > > full precision (integral + fractional) of both types.
> > > > > > > > > > > 
> > > > > > > > > > > > The only unhandled thing is overflow, but the precision 
> > > > > > > > > > > > of the fract remains the same. The operands would also 
> > > > > > > > > > > > be casted up beforehand so there was enough space to 
> > > > > > > > > > > > store the result, which was casted down back to the 
> > > > > > > > > > > > original fract after performing the right shift by the 
> > > > > > > > > > > > scale.
> > > > > > > > > > > 
> > > > > > > > > > > The precision remains the same (and while it doesn't have 
> > > > > > > > > > > to be the same to perform an operation, it makes the 
> > > > > > > > > > > implementation more regular; things like addition and 
> > > > > > > > > > > subtraction 'just work'), but you cannot perform a 
> > > > > > > > > > > conversion to `fract` *before* the operation itself, 
> > > > > > > > > > > since if you do, there's nothing to 'cast up'. Casting up 
> > > > > > > > > > > is needed for things like `fract * fract` to prevent 
> > > > > > > > > > > overflow, but for `fract * int` you need to cast to a 
> > > > > > > > > > > type that can fit both all values of the int and all 
> > > > > > > > > > > values of the fract, and *then* you can cast up before 
> > > > > > > > > > > doing the multiplication.
> > > > > > > > > > > 
> > > > > > > > > > > > Operations between fixed point types would follow a 
> >

[PATCH] D47698: [ASTImporter] import macro source locations

2018-06-19 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

This patch is really useful and LGTM!
Just found some minor things.




Comment at: lib/AST/ASTImporter.cpp:7058
+const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
+SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc());
+SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart());

Let's say we import a `SourceLocation` with `ASTImporter::Import(SourceLocation 
FromLoc)`.
That calls into `ASTImporter::Import(FileID FromID)` where we again import 
other source locations.
Could the initial `FromLoc` be equal with any of these locations 
(`FromEx.getSpellingLoc()`, `FromEx.getExpansionLocStart()`) ?
My understanding is that this is not possible because we cannot have recursive 
macros, but please confirm.



Comment at: unittests/AST/ASTImporterTest.cpp:1521
 
+static void CompareSourceLocs(SourceLocation Loc1, SourceLocation Loc2,
+  SourceManager &SM1, SourceManager &SM2) {

Perhaps it would be more concise and less error prone to use a `FullSourceLoc` 
which wraps one simple `SourceLocation` and a `SourceManager`.



Comment at: unittests/AST/ASTImporterTest.cpp:1557
+  SourceManager &FromSM = FromD->getASTContext().getSourceManager();
+  CompareSourceRanges(ToD->getSourceRange(), FromD->getSourceRange(), ToSM,
+  FromSM);

```
CompareSourceRanges(FullSourceRange{ToD->getSourceRange(), ToSM}, ..
```
?


Repository:
  rC Clang

https://reviews.llvm.org/D47698



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


r335050 - Implement semantic checking for __builtin_signbit.

2018-06-19 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Jun 19 07:59:11 2018
New Revision: 335050

URL: http://llvm.org/viewvc/llvm-project?rev=335050&view=rev
Log:
Implement semantic checking for __builtin_signbit.

r242675 changed the signature for the signbit builtin but did not introduce 
proper semantic checking to ensure the arguments are as-expected. This patch 
groups the signbit builtin along with the other fp classification builtins. 
Fixes PR28172.

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/builtins.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=335050&r1=335049&r2=335050&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Jun 19 07:59:11 2018
@@ -972,6 +972,9 @@ Sema::CheckBuiltinFunctionCall(FunctionD
   case Builtin::BI__builtin_isinf_sign:
   case Builtin::BI__builtin_isnan:
   case Builtin::BI__builtin_isnormal:
+  case Builtin::BI__builtin_signbit:
+  case Builtin::BI__builtin_signbitf:
+  case Builtin::BI__builtin_signbitl:
 if (SemaBuiltinFPClassification(TheCall, 1))
   return ExprError();
 break;
@@ -4592,15 +4595,19 @@ bool Sema::SemaBuiltinFPClassification(C
 diag::err_typecheck_call_invalid_unary_fp)
   << OrigArg->getType() << OrigArg->getSourceRange();
 
-  // If this is an implicit conversion from float -> float or double, remove 
it.
+  // If this is an implicit conversion from float -> float, double, or
+  // long double, remove it.
   if (ImplicitCastExpr *Cast = dyn_cast(OrigArg)) {
 // Only remove standard FloatCasts, leaving other casts inplace
 if (Cast->getCastKind() == CK_FloatingCast) {
   Expr *CastArg = Cast->getSubExpr();
   if (CastArg->getType()->isSpecificBuiltinType(BuiltinType::Float)) {
-  assert((Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) 
||
-  Cast->getType()->isSpecificBuiltinType(BuiltinType::Float)) 
&&
-   "promotion from float to either float or double is the only 
expected cast here");
+assert(
+(Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) ||
+ Cast->getType()->isSpecificBuiltinType(BuiltinType::Float) ||
+ Cast->getType()->isSpecificBuiltinType(BuiltinType::LongDouble)) 
&&
+"promotion from float to either float, double, or long double is "
+"the only expected cast here");
 Cast->setSubExpr(nullptr);
 TheCall->setArg(NumArgs-1, CastArg);
   }

Modified: cfe/trunk/test/Sema/builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins.c?rev=335050&r1=335049&r2=335050&view=diff
==
--- cfe/trunk/test/Sema/builtins.c (original)
+++ cfe/trunk/test/Sema/builtins.c Tue Jun 19 07:59:11 2018
@@ -253,3 +253,26 @@ void test21(const int *ptr) {
   __sync_fetch_and_add(ptr, 1); // expected-error{{address argument to atomic 
builtin cannot be const-qualified ('const int *' invalid)}}
   __atomic_fetch_add(ptr, 1, 0);  // expected-error {{address argument to 
atomic operation must be a pointer to non-const type ('const int *' invalid)}}
 }
+
+void test22(void) {
+  (void)__builtin_signbit(); // expected-error{{too few arguments to function 
call, expected 1, have 0}}
+  (void)__builtin_signbit(1.0, 2.0, 3.0); // expected-error{{too many 
arguments to function call, expected 1, have 3}}
+  (void)__builtin_signbit(1); // expected-error {{floating point 
classification requires argument of floating point type (passed in 'int')}}
+  (void)__builtin_signbit(1.0);
+  (void)__builtin_signbit(1.0f);
+  (void)__builtin_signbit(1.0L);
+
+  (void)__builtin_signbitf(); // expected-error{{too few arguments to function 
call, expected 1, have 0}}
+  (void)__builtin_signbitf(1.0, 2.0, 3.0); // expected-error{{too many 
arguments to function call, expected 1, have 3}}
+  (void)__builtin_signbitf(1);
+  (void)__builtin_signbitf(1.0);
+  (void)__builtin_signbitf(1.0f);
+  (void)__builtin_signbitf(1.0L);
+
+  (void)__builtin_signbitl(); // expected-error{{too few arguments to function 
call, expected 1, have 0}}
+  (void)__builtin_signbitl(1.0, 2.0, 3.0); // expected-error{{too many 
arguments to function call, expected 1, have 3}}
+  (void)__builtin_signbitl(1);
+  (void)__builtin_signbitl(1.0);
+  (void)__builtin_signbitl(1.0f);
+  (void)__builtin_signbitl(1.0L);
+}


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


r335049 - Reverting due to line ending changes; will reapply after addressing that.

2018-06-19 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Jun 19 07:53:20 2018
New Revision: 335049

URL: http://llvm.org/viewvc/llvm-project?rev=335049&view=rev
Log:
Reverting due to line ending changes; will reapply after addressing that.

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/builtins.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=335049&r1=335048&r2=335049&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Jun 19 07:53:20 2018
@@ -772,409 +772,406 @@ static bool SemaBuiltinReserveRWPipe(Sem
   }
 
   // Since return type of reserve_read/write_pipe built-in function is
-  // reserve_id_t, which is not defined in the builtin def file , we used int
-  // as return type and need to override the return type of these functions.
-  Call->setType(S.Context.OCLReserveIDTy);
-
-  return false;
-}
-
-// Performs a semantic analysis on {work_group_/sub_group_
-///_}commit_{read/write}_pipe
-// \param S Reference to the semantic analyzer.
-// \param Call The call to the builtin function to be analyzed.
-// \return True if a semantic error was found, false otherwise.
-static bool SemaBuiltinCommitRWPipe(Sema &S, CallExpr *Call) {
-  if (checkArgCount(S, Call, 2))
-return true;
-
-  if (checkOpenCLPipeArg(S, Call))
-return true;
-
-  // Check reserve_id_t.
-  if (!Call->getArg(1)->getType()->isReserveIDT()) {
-S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_invalid_arg)
-<< Call->getDirectCallee() << S.Context.OCLReserveIDTy
-<< Call->getArg(1)->getType() << Call->getArg(1)->getSourceRange();
-return true;
-  }
-
-  return false;
-}
-
-// Performs a semantic analysis on the call to built-in Pipe
-//Query Functions.
-// \param S Reference to the semantic analyzer.
-// \param Call The call to the builtin function to be analyzed.
-// \return True if a semantic error was found, false otherwise.
-static bool SemaBuiltinPipePackets(Sema &S, CallExpr *Call) {
-  if (checkArgCount(S, Call, 1))
-return true;
-
-  if (!Call->getArg(0)->getType()->isPipeType()) {
-S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_first_arg)
-<< Call->getDirectCallee() << Call->getArg(0)->getSourceRange();
-return true;
-  }
-
-  return false;
-}
-
-// OpenCL v2.0 s6.13.9 - Address space qualifier functions.
-// Performs semantic analysis for the to_global/local/private call.
-// \param S Reference to the semantic analyzer.
-// \param BuiltinID ID of the builtin function.
-// \param Call A pointer to the builtin call.
-// \return True if a semantic error has been found, false otherwise.
-static bool SemaOpenCLBuiltinToAddr(Sema &S, unsigned BuiltinID,
-CallExpr *Call) {
-  if (Call->getNumArgs() != 1) {
-S.Diag(Call->getLocStart(), diag::err_opencl_builtin_to_addr_arg_num)
-<< Call->getDirectCallee() << Call->getSourceRange();
-return true;
-  }
-
-  auto RT = Call->getArg(0)->getType();
-  if (!RT->isPointerType() || RT->getPointeeType()
-  .getAddressSpace() == LangAS::opencl_constant) {
-S.Diag(Call->getLocStart(), diag::err_opencl_builtin_to_addr_invalid_arg)
-<< Call->getArg(0) << Call->getDirectCallee() << 
Call->getSourceRange();
-return true;
-  }
-
-  RT = RT->getPointeeType();
-  auto Qual = RT.getQualifiers();
-  switch (BuiltinID) {
-  case Builtin::BIto_global:
-Qual.setAddressSpace(LangAS::opencl_global);
-break;
-  case Builtin::BIto_local:
-Qual.setAddressSpace(LangAS::opencl_local);
-break;
-  case Builtin::BIto_private:
-Qual.setAddressSpace(LangAS::opencl_private);
-break;
-  default:
-llvm_unreachable("Invalid builtin function");
-  }
-  Call->setType(S.Context.getPointerType(S.Context.getQualifiedType(
-  RT.getUnqualifiedType(), Qual)));
-
-  return false;
-}
-
-// Emit an error and return true if the current architecture is not in the list
-// of supported architectures.
-static bool
-CheckBuiltinTargetSupport(Sema &S, unsigned BuiltinID, CallExpr *TheCall,
-  ArrayRef SupportedArchs) {
-  llvm::Triple::ArchType CurArch =
-  S.getASTContext().getTargetInfo().getTriple().getArch();
-  if (llvm::is_contained(SupportedArchs, CurArch))
-return false;
-  S.Diag(TheCall->getLocStart(), diag::err_builtin_target_unsupported)
-  << TheCall->getSourceRange();
-  return true;
-}
-
-ExprResult
-Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
-   CallExpr *TheCall) {
-  ExprResult TheCallResult(TheCall);
-
-  // Find out if any arguments are required to be integer constant expressions.
-  unsigned ICEArguments = 0;
-  ASTContext::GetBuiltinTypeError Error;
-  Context.GetBuiltinType(BuiltinID, Error, &ICEArguments);
-  if (Error != ASTContext

[PATCH] D47435: Add __builtin_signbit semantic checking

2018-06-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've committed in r335048; if @rsmith has concerns, they can be address post 
commit.


https://reviews.llvm.org/D47435



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


r335048 - Implement semantic checking for __builtin_signbit.

2018-06-19 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Jun 19 07:36:04 2018
New Revision: 335048

URL: http://llvm.org/viewvc/llvm-project?rev=335048&view=rev
Log:
Implement semantic checking for __builtin_signbit.

r242675 changed the signature for the signbit builtin but did not introduce 
proper semantic checking to ensure the arguments are as-expected. This patch 
groups the signbit builtin along with the other fp classification builtins. 
Fixes PR28172.

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/builtins.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=335048&r1=335047&r2=335048&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Jun 19 07:36:04 2018
@@ -772,406 +772,409 @@ static bool SemaBuiltinReserveRWPipe(Sem
   }
 
   // Since return type of reserve_read/write_pipe built-in function is
-  // reserve_id_t, which is not defined in the builtin def file , we used int
-  // as return type and need to override the return type of these functions.
-  Call->setType(S.Context.OCLReserveIDTy);
-
-  return false;
-}
-
-// Performs a semantic analysis on {work_group_/sub_group_
-///_}commit_{read/write}_pipe
-// \param S Reference to the semantic analyzer.
-// \param Call The call to the builtin function to be analyzed.
-// \return True if a semantic error was found, false otherwise.
-static bool SemaBuiltinCommitRWPipe(Sema &S, CallExpr *Call) {
-  if (checkArgCount(S, Call, 2))
-return true;
-
-  if (checkOpenCLPipeArg(S, Call))
-return true;
-
-  // Check reserve_id_t.
-  if (!Call->getArg(1)->getType()->isReserveIDT()) {
-S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_invalid_arg)
-<< Call->getDirectCallee() << S.Context.OCLReserveIDTy
-<< Call->getArg(1)->getType() << Call->getArg(1)->getSourceRange();
-return true;
-  }
-
-  return false;
-}
-
-// Performs a semantic analysis on the call to built-in Pipe
-//Query Functions.
-// \param S Reference to the semantic analyzer.
-// \param Call The call to the builtin function to be analyzed.
-// \return True if a semantic error was found, false otherwise.
-static bool SemaBuiltinPipePackets(Sema &S, CallExpr *Call) {
-  if (checkArgCount(S, Call, 1))
-return true;
-
-  if (!Call->getArg(0)->getType()->isPipeType()) {
-S.Diag(Call->getLocStart(), diag::err_opencl_builtin_pipe_first_arg)
-<< Call->getDirectCallee() << Call->getArg(0)->getSourceRange();
-return true;
-  }
-
-  return false;
-}
-
-// OpenCL v2.0 s6.13.9 - Address space qualifier functions.
-// Performs semantic analysis for the to_global/local/private call.
-// \param S Reference to the semantic analyzer.
-// \param BuiltinID ID of the builtin function.
-// \param Call A pointer to the builtin call.
-// \return True if a semantic error has been found, false otherwise.
-static bool SemaOpenCLBuiltinToAddr(Sema &S, unsigned BuiltinID,
-CallExpr *Call) {
-  if (Call->getNumArgs() != 1) {
-S.Diag(Call->getLocStart(), diag::err_opencl_builtin_to_addr_arg_num)
-<< Call->getDirectCallee() << Call->getSourceRange();
-return true;
-  }
-
-  auto RT = Call->getArg(0)->getType();
-  if (!RT->isPointerType() || RT->getPointeeType()
-  .getAddressSpace() == LangAS::opencl_constant) {
-S.Diag(Call->getLocStart(), diag::err_opencl_builtin_to_addr_invalid_arg)
-<< Call->getArg(0) << Call->getDirectCallee() << 
Call->getSourceRange();
-return true;
-  }
-
-  RT = RT->getPointeeType();
-  auto Qual = RT.getQualifiers();
-  switch (BuiltinID) {
-  case Builtin::BIto_global:
-Qual.setAddressSpace(LangAS::opencl_global);
-break;
-  case Builtin::BIto_local:
-Qual.setAddressSpace(LangAS::opencl_local);
-break;
-  case Builtin::BIto_private:
-Qual.setAddressSpace(LangAS::opencl_private);
-break;
-  default:
-llvm_unreachable("Invalid builtin function");
-  }
-  Call->setType(S.Context.getPointerType(S.Context.getQualifiedType(
-  RT.getUnqualifiedType(), Qual)));
-
-  return false;
-}
-
-// Emit an error and return true if the current architecture is not in the list
-// of supported architectures.
-static bool
-CheckBuiltinTargetSupport(Sema &S, unsigned BuiltinID, CallExpr *TheCall,
-  ArrayRef SupportedArchs) {
-  llvm::Triple::ArchType CurArch =
-  S.getASTContext().getTargetInfo().getTriple().getArch();
-  if (llvm::is_contained(SupportedArchs, CurArch))
-return false;
-  S.Diag(TheCall->getLocStart(), diag::err_builtin_target_unsupported)
-  << TheCall->getSourceRange();
-  return true;
-}
-
-ExprResult
-Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
-   CallExpr *TheCall) {
-  ExprResult TheCallResult(TheCall);
-
-  // Find out

[PATCH] D47720: [DebugInfo] Inline for without DebugLocation

2018-06-19 Thread Anastasis via Phabricator via cfe-commits
gramanas added a comment.

ping! should I commit this?


Repository:
  rC Clang

https://reviews.llvm.org/D47720



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


[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-06-19 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a comment.

Just a couple more comments and then I think it looks good.

We can discuss the conversion and comparison issues in later patches.




Comment at: include/clang/AST/ASTContext.h:1951
+  unsigned char getFixedPointScale(const QualType &Ty) const;
+  unsigned char getFixedPointIBits(const QualType &Ty) const;
+

These can probably take `QualType` directly.



Comment at: include/clang/Basic/TargetInfo.h:99
+  // sign if SameFBits is set.
+  unsigned char ShortAccumFBits;
+  unsigned char AccumFBits;

Could these and their accessors be called 'Scale' like in ASTContext? Only a 
consistency nit.



Comment at: lib/Sema/SemaExpr.cpp:1248
+  bool RHSFixed = RHSType->isFixedPointType();
+
+  if (LHSFixed && RHSFixed) {

leonardchan wrote:
> leonardchan wrote:
> > ebevhan wrote:
> > > ebevhan wrote:
> > > > leonardchan wrote:
> > > > > leonardchan wrote:
> > > > > > ebevhan wrote:
> > > > > > > ebevhan wrote:
> > > > > > > > leonardchan wrote:
> > > > > > > > > ebevhan wrote:
> > > > > > > > > > leonardchan wrote:
> > > > > > > > > > > ebevhan wrote:
> > > > > > > > > > > > I don't see how these semantics work properly. The 
> > > > > > > > > > > > specification requires that operations be done in the 
> > > > > > > > > > > > full precision of both types. You cannot convert the 
> > > > > > > > > > > > types before performing the operation like this, since 
> > > > > > > > > > > > the operation will not be done in full precision in 
> > > > > > > > > > > > that case.
> > > > > > > > > > > > 
> > > > > > > > > > > > The operator semantics of Embedded-C require the 
> > > > > > > > > > > > operand types of binary operators to be different. It's 
> > > > > > > > > > > > only when you've performed the operation that you are 
> > > > > > > > > > > > allowed to convert the result to the resulting type.
> > > > > > > > > > > Initially the idea was to convert both sides to fixed 
> > > > > > > > > > > point types, then perform standard binary operations 
> > > > > > > > > > > between the fixed point types.
> > > > > > > > > > > 
> > > > > > > > > > > For the example, a `fract * int` would have the int 
> > > > > > > > > > > converted to a fixed point type by left shifting it by 
> > > > > > > > > > > the scale of the fract, multiplying, then right shifting 
> > > > > > > > > > > by the scale again to get the resulting fract. The only 
> > > > > > > > > > > unhandled thing is overflow, but the precision of the 
> > > > > > > > > > > fract remains the same. The operands would also be casted 
> > > > > > > > > > > up beforehand so there was enough space to store the 
> > > > > > > > > > > result, which was casted down back to the original fract 
> > > > > > > > > > > after performing the right shift by the scale.
> > > > > > > > > > > 
> > > > > > > > > > > Operations between fixed point types would follow a 
> > > > > > > > > > > similar process of casting both operands to the higher 
> > > > > > > > > > > rank fixed point type, and depending on the operation, 
> > > > > > > > > > > more underlying shifting and casting would be done to 
> > > > > > > > > > > retain full precision of the higher ranked type.
> > > > > > > > > > > 
> > > > > > > > > > > Though I will admit that I did not realize until now that 
> > > > > > > > > > > multiplying a fixed point type by an integer does not 
> > > > > > > > > > > require shifting the integer.
> > > > > > > > > > I see how you've reasoned; this is how C normally works. 
> > > > > > > > > > The `fract` is of higher rank than `int` and therefore is 
> > > > > > > > > > the 'common type' of the operation. However, even though it 
> > > > > > > > > > is higher rank there is no guarantee that you can perform 
> > > > > > > > > > the operation without overflowing. And overflow matters 
> > > > > > > > > > here; the spec says that it must be done in the full 
> > > > > > > > > > precision (integral + fractional) of both types.
> > > > > > > > > > 
> > > > > > > > > > > The only unhandled thing is overflow, but the precision 
> > > > > > > > > > > of the fract remains the same. The operands would also be 
> > > > > > > > > > > casted up beforehand so there was enough space to store 
> > > > > > > > > > > the result, which was casted down back to the original 
> > > > > > > > > > > fract after performing the right shift by the scale.
> > > > > > > > > > 
> > > > > > > > > > The precision remains the same (and while it doesn't have 
> > > > > > > > > > to be the same to perform an operation, it makes the 
> > > > > > > > > > implementation more regular; things like addition and 
> > > > > > > > > > subtraction 'just work'), but you cannot perform a 
> > > > > > > > > > conversion to `fract` *before* the operation itself, since 
> > > > > > > > > > if you do, there's nothing to 'cast up'. Casting up is 
> > > > > > > > > > needed for things like `fract * fract` to prevent o

[PATCH] D46190: For a referenced declaration, mark any associated usings as referenced.

2018-06-19 Thread Carlos Alberto Enciso via Phabricator via cfe-commits
CarlosAlbertoEnciso added a comment.

rsmith Thanks very much for your review. I will address them.


https://reviews.llvm.org/D46190



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


[PATCH] D46190: For a referenced declaration, mark any associated usings as referenced.

2018-06-19 Thread Carlos Alberto Enciso via Phabricator via cfe-commits
CarlosAlbertoEnciso added a comment.

@probinson Thanks very much for your review. I will address them.


https://reviews.llvm.org/D46190



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


[PATCH] D48322: [Sema] Discarded statment should be an evaluatable context

2018-06-19 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.
erik.pilkington added a reviewer: rsmith.

The constexpr evaluator was erroring out because these templates weren't 
defined. Despite being used in a discarded statement, we still need to 
constexpr evaluate them, which means that we need to instantiate them.

Fixes https://llvm.org/PR37585

Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D48322

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/constant-expression-cxx1z.cpp


Index: clang/test/SemaCXX/constant-expression-cxx1z.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx1z.cpp
+++ clang/test/SemaCXX/constant-expression-cxx1z.cpp
@@ -46,3 +46,16 @@
   const int &r = 0;
   constexpr int n = r;
 }
+
+namespace PR37585 {
+template  struct S { static constexpr bool value = true; };
+template  constexpr bool f() { return true; }
+template  constexpr bool v = true;
+
+void test() {
+  if constexpr (true) {}
+  else if constexpr (f()) {}
+  else if constexpr (S::value) {}
+  else if constexpr (v) {}
+}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14143,13 +14143,13 @@
   switch (SemaRef.ExprEvalContexts.back().Context) {
 case Sema::ExpressionEvaluationContext::Unevaluated:
 case Sema::ExpressionEvaluationContext::UnevaluatedAbstract:
-case Sema::ExpressionEvaluationContext::DiscardedStatement:
   // Expressions in this context are never evaluated.
   return false;
 
 case Sema::ExpressionEvaluationContext::UnevaluatedList:
 case Sema::ExpressionEvaluationContext::ConstantEvaluated:
 case Sema::ExpressionEvaluationContext::PotentiallyEvaluated:
+case Sema::ExpressionEvaluationContext::DiscardedStatement:
   // Expressions in this context could be evaluated.
   return true;
 


Index: clang/test/SemaCXX/constant-expression-cxx1z.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx1z.cpp
+++ clang/test/SemaCXX/constant-expression-cxx1z.cpp
@@ -46,3 +46,16 @@
   const int &r = 0;
   constexpr int n = r;
 }
+
+namespace PR37585 {
+template  struct S { static constexpr bool value = true; };
+template  constexpr bool f() { return true; }
+template  constexpr bool v = true;
+
+void test() {
+  if constexpr (true) {}
+  else if constexpr (f()) {}
+  else if constexpr (S::value) {}
+  else if constexpr (v) {}
+}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14143,13 +14143,13 @@
   switch (SemaRef.ExprEvalContexts.back().Context) {
 case Sema::ExpressionEvaluationContext::Unevaluated:
 case Sema::ExpressionEvaluationContext::UnevaluatedAbstract:
-case Sema::ExpressionEvaluationContext::DiscardedStatement:
   // Expressions in this context are never evaluated.
   return false;
 
 case Sema::ExpressionEvaluationContext::UnevaluatedList:
 case Sema::ExpressionEvaluationContext::ConstantEvaluated:
 case Sema::ExpressionEvaluationContext::PotentiallyEvaluated:
+case Sema::ExpressionEvaluationContext::DiscardedStatement:
   // Expressions in this context could be evaluated.
   return true;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47401: [X86] Rewrite the max and min reduction intrinsics to make better use of other functions and to reduce width to 256 and 128 bits were possible.

2018-06-19 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.

OK, if the llvm side tests are incoming I'm happy with this patch


https://reviews.llvm.org/D47401



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


[PATCH] D48318: [analyzer][UninitializedObjectChecker] Drop lambda support

2018-06-19 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

> [...]lambda misuse in not really an uninitialized value problem.

I guess you can make the argument that it its. Even then, in my opinion this 
checker is overkill for lambdas.

- If the captured variable has a non-default constructor, 
`UninitializedValueChecker` will analyze it,
- if the captured variable has a default constructor, or if `Pedantic` is 
disabled and all fields are uninitialized, we probably don't want to warn for 
them anyways,
- if the captured variable is primitive (`BuiltinType` or `EnumeralType`) we 
can just easily iterate over the captured fields to check whether they are 
undefined, and make a decision whether to warn for them or not.

My point is, a standalone `cplusplus.LambdaMisuse` checker would be a lot more 
fitting to handle these cases.

But I'd love to hear your thoughts on this one! This functionality could 
totally be squeezed into the checker (with better warning messages), if we were 
to come to the conclusion that it should be.


Repository:
  rC Clang

https://reviews.llvm.org/D48318



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


[PATCH] D45616: [X86] Lower _mm[256|512]_cmp[.]_mask intrinsics to native llvm IR

2018-06-19 Thread Gabor Buella via Phabricator via cfe-commits
GBuella updated this revision to Diff 151884.
GBuella added a comment.

Added `__builtin_ia32_cmpsd_mask` & `__builtin_ia32_cmpss_mask`.


https://reviews.llvm.org/D45616

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/avx-builtins.c
  test/CodeGen/avx-cmp-builtins.c
  test/CodeGen/avx2-builtins.c
  test/CodeGen/avx512f-builtins.c
  test/CodeGen/avx512vl-builtins.c

Index: test/CodeGen/avx512vl-builtins.c
===
--- test/CodeGen/avx512vl-builtins.c
+++ test/CodeGen/avx512vl-builtins.c
@@ -1073,53 +1073,168 @@
 
 __mmask8 test_mm256_cmp_ps_mask(__m256 __A, __m256 __B) {
   // CHECK-LABEL: @test_mm256_cmp_ps_mask
-  // CHECK: call <8 x i1> @llvm.x86.avx512.mask.cmp.ps.256
+  // CHECK: fcmp oeq <8 x float> %{{.*}}, %{{.*}}
   return (__mmask8)_mm256_cmp_ps_mask(__A, __B, 0);
 }
 
+__mmask8 test_mm256_cmp_ps_mask_true_uq(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_true_uq
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_TRUE_UQ);
+}
+
+__mmask8 test_mm256_cmp_ps_mask_true_us(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_true_us
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_TRUE_US);
+}
+
+__mmask8 test_mm256_cmp_ps_mask_false_oq(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_false_oq
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_FALSE_OQ);
+}
+
+__mmask8 test_mm256_cmp_ps_mask_false_os(__m256 __A, __m256 __B) {
+  // CHECK-LABEL: @test_mm256_cmp_ps_mask_false_os
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm256_cmp_ps_mask(__A, __B, _CMP_FALSE_OS);
+}
+
 __mmask8 test_mm256_mask_cmp_ps_mask(__mmask8 m, __m256 __A, __m256 __B) {
   // CHECK-LABEL: @test_mm256_mask_cmp_ps_mask
-  // CHECK: [[CMP:%.*]] = call <8 x i1> @llvm.x86.avx512.mask.cmp.ps.256
-  // CHECK: and <8 x i1> [[CMP]], {{.*}}
+  // CHECK: fcmp oeq <8 x float> %{{.*}}, %{{.*}}
+  // CHECK: and <8 x i1> %{{.*}}, %{{.*}}
   return _mm256_mask_cmp_ps_mask(m, __A, __B, 0);
 }
 
 __mmask8 test_mm_cmp_ps_mask(__m128 __A, __m128 __B) {
   // CHECK-LABEL: @test_mm_cmp_ps_mask
-  // CHECK: call <4 x i1> @llvm.x86.avx512.mask.cmp.ps.128
+  // CHECK: fcmp oeq <4 x float> %{{.*}}, %{{.*}}
   return (__mmask8)_mm_cmp_ps_mask(__A, __B, 0);
 }
 
+__mmask8 test_mm_cmp_ps_mask_true_uq(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_true_uq
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_TRUE_UQ);
+}
+
+__mmask8 test_mm_cmp_ps_mask_true_us(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_true_us
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_TRUE_US);
+}
+
+__mmask8 test_mm_cmp_ps_mask_false_oq(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_false_oq
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_FALSE_OQ);
+}
+
+__mmask8 test_mm_cmp_ps_mask_false_os(__m128 __A, __m128 __B) {
+  // CHECK-LABEL: @test_mm_cmp_ps_mask_false_os
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm_cmp_ps_mask(__A, __B, _CMP_FALSE_OS);
+}
+
 __mmask8 test_mm_mask_cmp_ps_mask(__mmask8 m, __m128 __A, __m128 __B) {
   // CHECK-LABEL: @test_mm_mask_cmp_ps_mask
-  // CHECK: [[CMP:%.*]] = call <4 x i1> @llvm.x86.avx512.mask.cmp.ps.128
-  // CHECK: and <4 x i1> [[CMP]], {{.*}}
+  // CHECK: fcmp oeq <4 x float> %{{.*}}, %{{.*}}
+  // CHECK: shufflevector <8 x i1> %{{.*}}, <8 x i1> %{{.*}}, <4 x i32> 
+  // CHECK: and <4 x i1> %{{.*}}, %{{.*}}
   return _mm_mask_cmp_ps_mask(m, __A, __B, 0);
 }
 
 __mmask8 test_mm256_cmp_pd_mask(__m256d __A, __m256d __B) {
   // CHECK-LABEL: @test_mm256_cmp_pd_mask
-  // CHECK: call <4 x i1> @llvm.x86.avx512.mask.cmp.pd.256
+  // CHECK: fcmp oeq <4 x double> %{{.*}}, %{{.*}}
   return (__mmask8)_mm256_cmp_pd_mask(__A, __B, 0);
 }
 
+__mmask8 test_mm256_cmp_pd_mask_true_uq(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_true_uq
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_pd_mask(__A, __B, _CMP_TRUE_UQ);
+}
+
+__mmask8 test_mm256_cmp_pd_mask_true_us(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_true_us
+  // CHECK-NOT: call
+  // CHECK: ret i8 -1
+  return (__mmask8)_mm256_cmp_pd_mask(__A, __B, _CMP_TRUE_US);
+}
+
+__mmask8 test_mm256_cmp_pd_mask_false_oq(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_false_oq
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm256_cmp_pd_mask(__A, __B, _CMP_FALSE_OQ);
+}
+
+__mmask8 test_mm256_cmp_pd_mask_false_os(__m256d __A, __m256d __B) {
+  // CHECK-LABEL: @test_mm256_cmp_pd_mask_false_os
+  // CHECK-NOT: call
+  // CHECK: ret i8 0
+  return (__mmask8)_mm256_cmp_pd_mask(__A, __B, _CMP_FALSE_OS);
+}

[PATCH] D47946: [ASTmporter] Fix infinite recursion on function import with struct definition in parameters

2018-06-19 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: rnkovacs.

LGTM, just found some minor things.




Comment at: unittests/AST/ASTImporterTest.cpp:174
 TranslationUnitDecl *TUDecl = nullptr;
+std::unique_ptr Importer;
+

Now that the `Importer` is moved under the `TU` struct it is not that trivial 
so I think we should add a few more comments to it.
Something like:
```
Represents a "From" translation unit and holds an importer object which we use 
to import from this translation unit.
```

Also there is an invariant which should be forced: the "To" and the "From" 
context of the `Importer` must remain the same throughout the life time of any 
`TU` object. We can achieve that with an assert in `lazyInitImporter`.

(What's more, the different objects all should have the same "To" contexts, but 
that could be checked only in the `TestBase` and looks more difficult, so for 
this patch we could skip that. )



Comment at: unittests/AST/ASTImporterTest.cpp:190
+Unit->getASTContext(), Unit->getFileManager(), false));
+  }
+}

I think, if there is an existing `Importer` then we should assert whether that 
has a `ToAST`which is equal to the parameter.


https://reviews.llvm.org/D47946



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


[PATCH] D47687: [Sema] Missing -Wlogical-op-parentheses warnings in macros (PR18971)

2018-06-19 Thread Xing via Phabricator via cfe-commits
Higuoxing added a comment.

Sorry, It seems a little bit difficult for me to add a proper fix-it hint for 
expressions in macros, because I cannot find the exact position of the last 
char of the token on right hand side of operator. Any suggestion?

Actually, in gcc, it will emit warning for everything without a fix-it hint, 
let alone expressions in nested macros... I think that our warning note is 
enough for us to diagnose the lacking parentheses, as you see in my inline 
comment

  llvm/tools/clang/test/Sema/parentheses.c:109:15: note: place parentheses 
around the '&&' expression to silence this warning
VOID_CAST(i && i || i); // expected-warning {{'&&' within '||'}} \
  ~~^~~~
  llvm/tools/clang/test/Sema/parentheses.c:17:34: note: expanded from macro 
'VOID_CAST'
  #define VOID_CAST(cond) ( (void)(cond) )
   ^~~~

So, it depends on you whether the parentheses checking in macros should be 
reserved. Both OK for me... Thanks for your reviewing :)


https://reviews.llvm.org/D47687



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


[PATCH] D48291: [analyzer][UninitializedObjectChecker] Fixed captured lambda variable name

2018-06-19 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

Thanks for the review!

I spend some time thinking about the support for lambda functions, and I start 
to think that checking for lambda misuse shouldn't be the responsibility of 
this checker. I created a new revision for that discussion, I wouldn't like to 
abandon this one until I heard what you think of this! :)
https://reviews.llvm.org/D48318




Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:687
+CXXRecordDecl::capture_const_iterator CapturedVar =
+std::find_if(CXXParent->captures_begin(), CXXParent->captures_end(),
+ [&Field](const LambdaCapture &L) {

george.karpenkov wrote:
> Could we just use a for-each here? Sorry for being opinionated, I'm pretty 
> sure it would be both shorter and more readable.
Great idea! :) I completely agree, to be honest I scratched my head too while I 
wrote it down.


Repository:
  rC Clang

https://reviews.llvm.org/D48291



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


[PATCH] D48318: [analyzer][UninitializedObjectChecker] Drop lambda support

2018-06-19 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, rnkovacs, dkrupp.
Herald added subscribers: cfe-commits, mikhail.ramalho, a.sidorin, szepet, 
whisperity.

After some thinking, I don't think this checker should support lambdas.

Reason 1.: While this is due to the analyzer not being smart enough just yet, 
the checker doesn't find uninitialized variables that were captured but value, 
but it does find find them if they were captured by reference. I think this 
makes little sense -- capturing by reference could be intentional, if the 
lambda function assigns a value to it, while capturing an undefined variable by 
value almost never makes sense. This could be fixed, but...

Reason 2.: I don't think lambda misuse should be the responsibility of this 
checker. It just doesn't make sense, as lambda misuse in not really an 
uninitialized value problem. It should rather be handled by a standalone lambda 
checker.


Repository:
  rC Clang

https://reviews.llvm.org/D48318

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object.cpp

Index: test/Analysis/cxx-uninitialized-object.cpp
===
--- test/Analysis/cxx-uninitialized-object.cpp
+++ test/Analysis/cxx-uninitialized-object.cpp
@@ -736,6 +736,9 @@
 // Lambda tests.
 //===--===//
 
+// The checker no longer checks uninitialized captured lambda variables, these
+// test are mainly no-crash test.
+
 template 
 struct LambdaTest1 {
   Callable functor;
@@ -755,12 +758,12 @@
 struct LambdaTest2 {
   Callable functor;
 
-  LambdaTest2(const Callable &functor, int) : functor(functor) {} // expected-warning{{1 uninitialized field}}
+  LambdaTest2(const Callable &functor, int) : functor(functor) {}
 };
 
 void fLambdaTest2() {
   int b;
-  auto equals = [&b](int a) { return a == b; }; // expected-note{{uninitialized field 'this->functor.'}}
+  auto equals = [&b](int a) { return a == b; };
   LambdaTest2(equals, int());
 }
 #else
@@ -782,16 +785,16 @@
 namespace LT3Detail {
 
 struct RecordType {
-  int x; // expected-note{{uninitialized field 'this->functor..x'}}
-  int y; // expected-note{{uninitialized field 'this->functor..y'}}
+  int x;
+  int y;
 };
 
 } // namespace LT3Detail
 template 
 struct LambdaTest3 {
   Callable functor;
 
-  LambdaTest3(const Callable &functor, int) : functor(functor) {} // expected-warning{{2 uninitialized fields}}
+  LambdaTest3(const Callable &functor, int) : functor(functor) {}
 };
 
 void fLambdaTest3() {
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -202,6 +202,11 @@
   // Note that we don't have a method for arrays -- the elements of an array are
   // often left uninitialized intentionally even when it is of a C++ record
   // type, so we'll assume that an array is always initialized.
+  //
+  // We'll also ignore lambdas, as lambda data members may contain uninitialized
+  // captured variables, but checking for them (and lambda misuse in general)
+  // shouldn't be the resposibility of this checker.
+  //
   // TODO: Add a support for nonloc::LocAsInteger.
 };
 
@@ -373,6 +378,13 @@
 if (LocalChain.contains(FR))
   return false;
 
+if (const auto *CXXRD = T->getAsCXXRecordDecl()) {
+  if (CXXRD->isLambda()) {
+IsAnyFieldInitialized = true;
+continue;
+  }
+}
+
 if (T->isStructureOrClassType()) {
   if (isNonUnionUninit(FR, {LocalChain, FR}))
 ContainsUninitField = true;
@@ -518,6 +530,13 @@
 
 const QualType T = R->getValueType();
 
+if (const auto *CXXRD = T->getAsCXXRecordDecl()) {
+  if (CXXRD->isLambda()) {
+IsAnyFieldInitialized = true;
+return false;
+  }
+}
+
 if (T->isStructureOrClassType())
   return isNonUnionUninit(R, {LocalChain, FR});
 
@@ -610,22 +629,6 @@
 // "uninitialized field 'this->x'", but we can't refer to 'x' directly,
 // we need an explicit namespace resolution whether the uninit field was
 // 'D1::x' or 'D2::x'.
-//
-// TODO: If a field in the fieldchain is a captured lambda parameter, this
-// function constructs an empty string for it:
-//
-//   template  struct A {
-// Callable c;
-// A(const Callable &c, int) : c(c) {}
-//   };
-//
-//   int b; // say that this isn't zero initialized
-//   auto alwaysTrue = [&b](int a) { return true; };
-//
-// A call with these parameters: A::A(alwaysTrue, int())
-// will emit a note with the message "uninitialized field: 'this->c.'". If
-// possible, the lambda parameter name should be retrieved or be replaced with a
-// "" or something similar.
 void FieldChainInfo::print(llvm::raw_ostream &Out) const {
   if (Chain.isEmp

[PATCH] D47670: [analyzer] [NFC] Remove unused Extensive diagnostic setting, rename AlternateExtensive to Extensive.

2018-06-19 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D47670#1135497, @george.karpenkov wrote:

> @alexfh apologies, fixed.


Thank you1


Repository:
  rC Clang

https://reviews.llvm.org/D47670



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


[PATCH] D48290: [clangd] Use workspace root path as hint path for resolving URIs in workspace/symbol

2018-06-19 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL335035: [clangd] Use workspace root path as hint path for 
resolving URIs in… (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D48290

Files:
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/FindSymbols.cpp
  clang-tools-extra/trunk/clangd/FindSymbols.h
  clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
  clang-tools-extra/trunk/unittests/clangd/TestFS.cpp
  clang-tools-extra/trunk/unittests/clangd/URITests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/URITests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/URITests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/URITests.cpp
@@ -144,7 +144,7 @@
   "/(x)/y/ z");
   EXPECT_THAT(resolveOrDie(parseOrDie("file:///c:/x/y/z")), "c:/x/y/z");
 #endif
-  EXPECT_EQ(resolveOrDie(parseOrDie("unittest:a"), testPath("x")),
+  EXPECT_EQ(resolveOrDie(parseOrDie("unittest:///a"), testPath("x")),
 testPath("a"));
 }
 
Index: clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
@@ -40,13 +40,18 @@
 ClangdServer::Options optsForTests() {
   auto ServerOpts = ClangdServer::optsForTest();
   ServerOpts.BuildDynamicSymbolIndex = true;
+  ServerOpts.URISchemes = {"unittest", "file"};
   return ServerOpts;
 }
 
 class WorkspaceSymbolsTest : public ::testing::Test {
 public:
   WorkspaceSymbolsTest()
-  : Server(CDB, FSProvider, DiagConsumer, optsForTests()) {}
+  : Server(CDB, FSProvider, DiagConsumer, optsForTests()) {
+// Make sure the test root directory is created.
+FSProvider.Files[testPath("unused")] = "";
+Server.setRootPath(testRoot());
+  }
 
 protected:
   MockFSProvider FSProvider;
Index: clang-tools-extra/trunk/unittests/clangd/TestFS.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/TestFS.cpp
+++ clang-tools-extra/trunk/unittests/clangd/TestFS.cpp
@@ -66,15 +66,21 @@
   return Path.str();
 }
 
-/// unittest: is a scheme that refers to files relative to testRoot()
+/// unittest: is a scheme that refers to files relative to testRoot().
+/// URI body is a path relative to testRoot() e.g. unittest:///x.h for
+/// /clangd-test/x.h.
 class TestScheme : public URIScheme {
 public:
   static const char *Scheme;
 
   llvm::Expected
   getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
   llvm::StringRef HintPath) const override {
 assert(HintPath.startswith(testRoot()));
+if (!Body.consume_front("/"))
+  return llvm::make_error(
+  "Body of an unittest: URI must start with '/'",
+  llvm::inconvertibleErrorCode());
 llvm::SmallString<16> Path(Body.begin(), Body.end());
 llvm::sys::path::native(Path);
 return testPath(Path);
Index: clang-tools-extra/trunk/clangd/FindSymbols.cpp
===
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp
@@ -95,8 +95,8 @@
 } // namespace
 
 llvm::Expected>
-getWorkspaceSymbols(StringRef Query, int Limit,
-const SymbolIndex *const Index) {
+getWorkspaceSymbols(StringRef Query, int Limit, const SymbolIndex *const Index,
+StringRef HintPath) {
   std::vector Result;
   if (Query.empty() || !Index)
 return Result;
@@ -116,7 +116,7 @@
 Req.MaxCandidateCount = Limit;
   TopN Top(Req.MaxCandidateCount);
   FuzzyMatcher Filter(Req.Query);
-  Index->fuzzyFind(Req, [&Top, &Filter](const Symbol &Sym) {
+  Index->fuzzyFind(Req, [HintPath, &Top, &Filter](const Symbol &Sym) {
 // Prefer the definition over e.g. a function declaration in a header
 auto &CD = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
 auto Uri = URI::parse(CD.FileURI);
@@ -126,9 +126,7 @@
   CD.FileURI, Sym.Name));
   return;
 }
-// FIXME: Passing no HintPath here will work for "file" and "test" schemes
-// because they don't use it but this might not work for other custom ones.
-auto Path = URI::resolve(*Uri);
+auto Path = URI::resolve(*Uri, HintPath);
 if (!Path) {
   log(llvm::formatv("Workspace symbol: Could not resolve path for URI "
 "'{0}' for symbol '{1}'.",
Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -115,10 +115,15 @@
 }
 
 void ClangdServer::setRootPath(PathRef RootPath) {
-  s

[clang-tools-extra] r335035 - [clangd] Use workspace root path as hint path for resolving URIs in workspace/symbol

2018-06-19 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Jun 19 02:33:53 2018
New Revision: 335035

URL: http://llvm.org/viewvc/llvm-project?rev=335035&view=rev
Log:
[clangd] Use workspace root path as hint path for resolving URIs in 
workspace/symbol

Summary:
Some URI schemes require a hint path to be provided, and workspace root
path seems to be a good fit.

Reviewers: sammccall, malaperle

Reviewed By: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/FindSymbols.cpp
clang-tools-extra/trunk/clangd/FindSymbols.h
clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestFS.cpp
clang-tools-extra/trunk/unittests/clangd/URITests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=335035&r1=335034&r2=335035&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Jun 19 02:33:53 2018
@@ -115,10 +115,15 @@ ClangdServer::ClangdServer(GlobalCompila
 }
 
 void ClangdServer::setRootPath(PathRef RootPath) {
-  std::string NewRootPath = llvm::sys::path::convert_to_slash(
-  RootPath, llvm::sys::path::Style::posix);
-  if (llvm::sys::fs::is_directory(NewRootPath))
-this->RootPath = NewRootPath;
+  auto FS = FSProvider.getFileSystem();
+  auto Status = FS->status(RootPath);
+  if (!Status)
+log("Failed to get status for RootPath " + RootPath + ": " +
+Status.getError().message());
+  else if (Status->isDirectory())
+this->RootPath = RootPath;
+  else
+log("The provided RootPath " + RootPath + " is not a directory.");
 }
 
 void ClangdServer::addDocument(PathRef File, StringRef Contents,
@@ -446,7 +451,8 @@ void ClangdServer::onFileEvent(const Did
 
 void ClangdServer::workspaceSymbols(
 StringRef Query, int Limit, Callback> CB) {
-  CB(clangd::getWorkspaceSymbols(Query, Limit, Index));
+  CB(clangd::getWorkspaceSymbols(Query, Limit, Index,
+ RootPath ? *RootPath : ""));
 }
 
 std::vector>

Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=335035&r1=335034&r2=335035&view=diff
==
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original)
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Tue Jun 19 02:33:53 2018
@@ -95,8 +95,8 @@ struct ScoredSymbolGreater {
 } // namespace
 
 llvm::Expected>
-getWorkspaceSymbols(StringRef Query, int Limit,
-const SymbolIndex *const Index) {
+getWorkspaceSymbols(StringRef Query, int Limit, const SymbolIndex *const Index,
+StringRef HintPath) {
   std::vector Result;
   if (Query.empty() || !Index)
 return Result;
@@ -116,7 +116,7 @@ getWorkspaceSymbols(StringRef Query, int
 Req.MaxCandidateCount = Limit;
   TopN Top(Req.MaxCandidateCount);
   FuzzyMatcher Filter(Req.Query);
-  Index->fuzzyFind(Req, [&Top, &Filter](const Symbol &Sym) {
+  Index->fuzzyFind(Req, [HintPath, &Top, &Filter](const Symbol &Sym) {
 // Prefer the definition over e.g. a function declaration in a header
 auto &CD = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
 auto Uri = URI::parse(CD.FileURI);
@@ -126,9 +126,7 @@ getWorkspaceSymbols(StringRef Query, int
   CD.FileURI, Sym.Name));
   return;
 }
-// FIXME: Passing no HintPath here will work for "file" and "test" schemes
-// because they don't use it but this might not work for other custom ones.
-auto Path = URI::resolve(*Uri);
+auto Path = URI::resolve(*Uri, HintPath);
 if (!Path) {
   log(llvm::formatv("Workspace symbol: Could not resolve path for URI "
 "'{0}' for symbol '{1}'.",

Modified: clang-tools-extra/trunk/clangd/FindSymbols.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.h?rev=335035&r1=335034&r2=335035&view=diff
==
--- clang-tools-extra/trunk/clangd/FindSymbols.h (original)
+++ clang-tools-extra/trunk/clangd/FindSymbols.h Tue Jun 19 02:33:53 2018
@@ -27,9 +27,11 @@ class SymbolIndex;
 /// "::". For example, "std::" will list all children of the std namespace and
 /// "::" alone will list all children of the global namespace.
 /// \p Limit limits the number of results returned (0 means no limit).
+/// \p HintPath This is used when resolving URIs. If empty, URI resolution can
+/// fail if a hint path is required for the scheme of a specific URI.
 llvm::Expected>
 getWorkspaceSymbols(llvm::StringRef Query, int Limi

[PATCH] D48290: [clangd] Use workspace root path as hint path for resolving URIs in workspace/symbol

2018-06-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 151877.
ioeric added a comment.

- Require '/' in front of unittest: body


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48290

Files:
  clangd/ClangdServer.cpp
  clangd/FindSymbols.cpp
  clangd/FindSymbols.h
  unittests/clangd/FindSymbolsTests.cpp
  unittests/clangd/TestFS.cpp
  unittests/clangd/URITests.cpp

Index: unittests/clangd/URITests.cpp
===
--- unittests/clangd/URITests.cpp
+++ unittests/clangd/URITests.cpp
@@ -144,7 +144,7 @@
   "/(x)/y/ z");
   EXPECT_THAT(resolveOrDie(parseOrDie("file:///c:/x/y/z")), "c:/x/y/z");
 #endif
-  EXPECT_EQ(resolveOrDie(parseOrDie("unittest:a"), testPath("x")),
+  EXPECT_EQ(resolveOrDie(parseOrDie("unittest:///a"), testPath("x")),
 testPath("a"));
 }
 
Index: unittests/clangd/TestFS.cpp
===
--- unittests/clangd/TestFS.cpp
+++ unittests/clangd/TestFS.cpp
@@ -66,15 +66,21 @@
   return Path.str();
 }
 
-/// unittest: is a scheme that refers to files relative to testRoot()
+/// unittest: is a scheme that refers to files relative to testRoot().
+/// URI body is a path relative to testRoot() e.g. unittest:///x.h for
+/// /clangd-test/x.h.
 class TestScheme : public URIScheme {
 public:
   static const char *Scheme;
 
   llvm::Expected
   getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
   llvm::StringRef HintPath) const override {
 assert(HintPath.startswith(testRoot()));
+if (!Body.consume_front("/"))
+  return llvm::make_error(
+  "Body of an unittest: URI must start with '/'",
+  llvm::inconvertibleErrorCode());
 llvm::SmallString<16> Path(Body.begin(), Body.end());
 llvm::sys::path::native(Path);
 return testPath(Path);
Index: unittests/clangd/FindSymbolsTests.cpp
===
--- unittests/clangd/FindSymbolsTests.cpp
+++ unittests/clangd/FindSymbolsTests.cpp
@@ -40,13 +40,18 @@
 ClangdServer::Options optsForTests() {
   auto ServerOpts = ClangdServer::optsForTest();
   ServerOpts.BuildDynamicSymbolIndex = true;
+  ServerOpts.URISchemes = {"unittest", "file"};
   return ServerOpts;
 }
 
 class WorkspaceSymbolsTest : public ::testing::Test {
 public:
   WorkspaceSymbolsTest()
-  : Server(CDB, FSProvider, DiagConsumer, optsForTests()) {}
+  : Server(CDB, FSProvider, DiagConsumer, optsForTests()) {
+// Make sure the test root directory is created.
+FSProvider.Files[testPath("unused")] = "";
+Server.setRootPath(testRoot());
+  }
 
 protected:
   MockFSProvider FSProvider;
Index: clangd/FindSymbols.h
===
--- clangd/FindSymbols.h
+++ clangd/FindSymbols.h
@@ -27,9 +27,11 @@
 /// "::". For example, "std::" will list all children of the std namespace and
 /// "::" alone will list all children of the global namespace.
 /// \p Limit limits the number of results returned (0 means no limit).
+/// \p HintPath This is used when resolving URIs. If empty, URI resolution can
+/// fail if a hint path is required for the scheme of a specific URI.
 llvm::Expected>
 getWorkspaceSymbols(llvm::StringRef Query, int Limit,
-const SymbolIndex *const Index);
+const SymbolIndex *const Index, llvm::StringRef HintPath);
 
 } // namespace clangd
 } // namespace clang
Index: clangd/FindSymbols.cpp
===
--- clangd/FindSymbols.cpp
+++ clangd/FindSymbols.cpp
@@ -95,8 +95,8 @@
 } // namespace
 
 llvm::Expected>
-getWorkspaceSymbols(StringRef Query, int Limit,
-const SymbolIndex *const Index) {
+getWorkspaceSymbols(StringRef Query, int Limit, const SymbolIndex *const Index,
+StringRef HintPath) {
   std::vector Result;
   if (Query.empty() || !Index)
 return Result;
@@ -116,7 +116,7 @@
 Req.MaxCandidateCount = Limit;
   TopN Top(Req.MaxCandidateCount);
   FuzzyMatcher Filter(Req.Query);
-  Index->fuzzyFind(Req, [&Top, &Filter](const Symbol &Sym) {
+  Index->fuzzyFind(Req, [HintPath, &Top, &Filter](const Symbol &Sym) {
 // Prefer the definition over e.g. a function declaration in a header
 auto &CD = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
 auto Uri = URI::parse(CD.FileURI);
@@ -126,9 +126,7 @@
   CD.FileURI, Sym.Name));
   return;
 }
-// FIXME: Passing no HintPath here will work for "file" and "test" schemes
-// because they don't use it but this might not work for other custom ones.
-auto Path = URI::resolve(*Uri);
+auto Path = URI::resolve(*Uri, HintPath);
 if (!Path) {
   log(llvm::formatv("Workspace symbol: Could not resolve path for URI "
 "'{0}' for symbol '{1}'.",
Index: clangd/ClangdServer.cpp

[PATCH] D33537: [clang-tidy] Exception Escape Checker

2018-06-19 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 151876.
baloghadamsoftware added a comment.

Typo fixed.


https://reviews.llvm.org/D33537

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tidy/bugprone/ExceptionEscapeCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-exception-escape.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-exception-escape.cpp

Index: test/clang-tidy/bugprone-exception-escape.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-exception-escape.cpp
@@ -0,0 +1,265 @@
+// RUN: %check_clang_tidy %s bugprone-exception-escape %t -- -extra-arg=-std=c++11 -config="{CheckOptions: [{key: bugprone-exception-escape.IgnoredExceptions, value: 'ignored1,ignored2'}, {key: bugprone-exception-escape.FunctionsThatShouldNotThrow, value: 'enabled1,enabled2,enabled3'}]}" --
+
+struct throwing_destructor {
+  ~throwing_destructor() {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function '~throwing_destructor' which should not throw exceptions
+throw 1;
+  }
+};
+
+struct throwing_move_constructor {
+  throwing_move_constructor(throwing_move_constructor&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function 'throwing_move_constructor' which should not throw exceptions
+throw 1;
+  }
+};
+
+struct throwing_move_assignment {
+  throwing_move_assignment& operator=(throwing_move_assignment&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: an exception may be thrown in function 'operator=' which should not throw exceptions
+throw 1;
+  }
+};
+
+void throwing_noexcept() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_noexcept' which should not throw exceptions
+  throw 1;
+}
+
+void throwing_throw_nothing() throw() {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_throw_nothing' which should not throw exceptions
+  throw 1;
+}
+
+void throw_and_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch' which should not throw exceptions
+  try {
+throw 1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_some(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch_some' which should not throw exceptions
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_each(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch_each' which should not throw exceptions
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(double &) {
+  }
+}
+
+void throw_and_catch_all(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch_all' which should not throw exceptions
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(...) {
+  }
+}
+
+void throw_and_rethrow() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_rethrow' which should not throw exceptions
+  try {
+throw 1;
+  } catch(int &) {
+throw;
+  }
+}
+
+void throw_catch_throw() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_throw' which should not throw exceptions
+  try {
+throw 1;
+  } catch(int &) {
+throw 2;
+  }
+}
+
+void throw_catch_rethrow_the_rest(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_rethrow_the_rest' which should not throw exceptions
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(...) {
+throw;
+  }
+}
+
+class base {};
+class derived: public base {};
+
+void throw_derived_catch_base() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base' which should not throw exceptions
+  try {
+throw derived();
+  } catch(base &) {
+  }
+}
+
+void try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'try_nested_try' which should not throw exceptions
+  try {
+try {
+  if (n) throw 1;
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void bad_try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'bad_try_nested_try' which should not throw exceptions
+  try {
+if (n) throw 1;
+try {
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void try_nested_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exc

[PATCH] D48290: [clangd] Use workspace root path as hint path for resolving URIs in workspace/symbol

2018-06-19 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: unittests/clangd/TestFS.cpp:93
 return URI(Scheme, /*Authority=*/"",
-   llvm::sys::path::convert_to_slash(Body));
+   StringRef(llvm::sys::path::convert_to_slash(Body)).ltrim('/'));
   }

ioeric wrote:
> sammccall wrote:
> > why this change?
> The `consume_front` above would not consume the second slash in 
> `/clangd-test/x.h` which results in "/x.h" in the body, but that doesn't work 
> with `testPath()` which requires a relative path. That's why I added a 
> requirement that the body should be relative path.
can we switch back to that path being represented by `unittest:/x.h` rather 
than `unittest:x.h`? 
That looks more like the URI schemes we use in practice.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48290



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


[PATCH] D48290: [clangd] Use workspace root path as hint path for resolving URIs in workspace/symbol

2018-06-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 151869.
ioeric marked 3 inline comments as done.
ioeric added a comment.

- Address review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48290

Files:
  clangd/ClangdServer.cpp
  clangd/FindSymbols.cpp
  clangd/FindSymbols.h
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/FindSymbolsTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp
  unittests/clangd/TestFS.cpp

Index: unittests/clangd/TestFS.cpp
===
--- unittests/clangd/TestFS.cpp
+++ unittests/clangd/TestFS.cpp
@@ -66,7 +66,8 @@
   return Path.str();
 }
 
-/// unittest: is a scheme that refers to files relative to testRoot()
+/// unittest: is a scheme that refers to files relative to testRoot().
+/// URI body is a path relative to testRoot().
 class TestScheme : public URIScheme {
 public:
   static const char *Scheme;
@@ -89,7 +90,7 @@
   llvm::inconvertibleErrorCode());
 
 return URI(Scheme, /*Authority=*/"",
-   llvm::sys::path::convert_to_slash(Body));
+   StringRef(llvm::sys::path::convert_to_slash(Body)).ltrim('/'));
   }
 };
 
Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -379,7 +379,7 @@
   TestFileName = testPath("x.cpp");
   runSymbolCollector("class Foo {};", /*Main=*/"");
   EXPECT_THAT(Symbols, UnorderedElementsAre(
-   AllOf(QName("Foo"), DeclURI("unittest:///x.h";
+   AllOf(QName("Foo"), DeclURI("unittest:x.h";
 }
 
 TEST_F(SymbolCollectorTest, InvalidURIScheme) {
Index: unittests/clangd/FindSymbolsTests.cpp
===
--- unittests/clangd/FindSymbolsTests.cpp
+++ unittests/clangd/FindSymbolsTests.cpp
@@ -40,13 +40,18 @@
 ClangdServer::Options optsForTests() {
   auto ServerOpts = ClangdServer::optsForTest();
   ServerOpts.BuildDynamicSymbolIndex = true;
+  ServerOpts.URISchemes = {"unittest", "file"};
   return ServerOpts;
 }
 
 class WorkspaceSymbolsTest : public ::testing::Test {
 public:
   WorkspaceSymbolsTest()
-  : Server(CDB, FSProvider, DiagConsumer, optsForTests()) {}
+  : Server(CDB, FSProvider, DiagConsumer, optsForTests()) {
+// Make sure the test root directory is created.
+FSProvider.Files[testPath("unused")] = "";
+Server.setRootPath(testRoot());
+  }
 
 protected:
   MockFSProvider FSProvider;
Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -104,7 +104,7 @@
   Req.Query = "";
   bool SeenSymbol = false;
   M.fuzzyFind(Req, [&](const Symbol &Sym) {
-EXPECT_EQ(Sym.CanonicalDeclaration.FileURI, "unittest:///f.h");
+EXPECT_EQ(Sym.CanonicalDeclaration.FileURI, "unittest:f.h");
 SeenSymbol = true;
   });
   EXPECT_TRUE(SeenSymbol);
Index: clangd/FindSymbols.h
===
--- clangd/FindSymbols.h
+++ clangd/FindSymbols.h
@@ -27,9 +27,11 @@
 /// "::". For example, "std::" will list all children of the std namespace and
 /// "::" alone will list all children of the global namespace.
 /// \p Limit limits the number of results returned (0 means no limit).
+/// \p HintPath This is used when resolving URIs. If empty, URI resolution can
+/// fail if a hint path is required for the scheme of a specific URI.
 llvm::Expected>
 getWorkspaceSymbols(llvm::StringRef Query, int Limit,
-const SymbolIndex *const Index);
+const SymbolIndex *const Index, llvm::StringRef HintPath);
 
 } // namespace clangd
 } // namespace clang
Index: clangd/FindSymbols.cpp
===
--- clangd/FindSymbols.cpp
+++ clangd/FindSymbols.cpp
@@ -95,8 +95,8 @@
 } // namespace
 
 llvm::Expected>
-getWorkspaceSymbols(StringRef Query, int Limit,
-const SymbolIndex *const Index) {
+getWorkspaceSymbols(StringRef Query, int Limit, const SymbolIndex *const Index,
+StringRef HintPath) {
   std::vector Result;
   if (Query.empty() || !Index)
 return Result;
@@ -116,7 +116,7 @@
 Req.MaxCandidateCount = Limit;
   TopN Top(Req.MaxCandidateCount);
   FuzzyMatcher Filter(Req.Query);
-  Index->fuzzyFind(Req, [&Top, &Filter](const Symbol &Sym) {
+  Index->fuzzyFind(Req, [HintPath, &Top, &Filter](const Symbol &Sym) {
 // Prefer the definition over e.g. a function declaration in a header
 auto &CD = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
 auto Uri = URI::parse(CD.FileURI);
@@ -126,9 +126,7 @@
   CD.FileURI, Sym.Name));
   return;
 }
-// FIXME: Passing no HintPath here will work for "file" and "test" schemes
-// 

[PATCH] D48290: [clangd] Use workspace root path as hint path for resolving URIs in workspace/symbol

2018-06-19 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/ClangdServer.cpp:119
+  auto FS = FSProvider.getFileSystem();
+  auto Status = FS->status(RootPath);
+  if (!Status)

sammccall wrote:
> why validate it?
This is the current behavior, except `llvm::sys::fs::is_directory` only works 
for real file system.



Comment at: unittests/clangd/TestFS.cpp:93
 return URI(Scheme, /*Authority=*/"",
-   llvm::sys::path::convert_to_slash(Body));
+   StringRef(llvm::sys::path::convert_to_slash(Body)).ltrim('/'));
   }

sammccall wrote:
> why this change?
The `consume_front` above would not consume the second slash in 
`/clangd-test/x.h` which results in "/x.h" in the body, but that doesn't work 
with `testPath()` which requires a relative path. That's why I added a 
requirement that the body should be relative path.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48290



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


r335030 - [analyzer] Made a buildbot happy.

2018-06-19 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Tue Jun 19 01:35:02 2018
New Revision: 335030

URL: http://llvm.org/viewvc/llvm-project?rev=335030&view=rev
Log:
[analyzer] Made a buildbot happy.

Since `isPrimitiveType` was only used in an assert, a builbot with `-Werror`
and no asserts enabled failed to build it as it was unused.

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp?rev=335030&r1=335029&r2=335030&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp Tue 
Jun 19 01:35:02 2018
@@ -384,15 +384,17 @@ bool FindUninitializedFields::isNonUnion
   continue;
 }
 
-assert(isPrimitiveType(T) && "Non-primitive type! "
- "At this point FR must be primitive!");
+if (isPrimitiveType(T)) {
+  SVal V = State->getSVal(FieldVal);
 
-SVal V = State->getSVal(FieldVal);
-
-if (isPrimitiveUninit(V)) {
-  if (addFieldToUninits({LocalChain, FR}))
-ContainsUninitField = true;
+  if (isPrimitiveUninit(V)) {
+if (addFieldToUninits({LocalChain, FR}))
+  ContainsUninitField = true;
+  }
+  continue;
 }
+
+llvm_unreachable("All cases are handled!");
   }
 
   // Checking bases.


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


[PATCH] D48315: [Frontend] Share global completions cache

2018-06-19 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: ilya-biryukov, arphaman, erikjv.

Append ASTUnit cache with global completions cache. In case of multiple 
translation units for the same file reduces the memory consumption and save 
completions cache generation time.


https://reviews.llvm.org/D48315

Files:
  include/clang/Frontend/ASTUnit.h
  lib/Frontend/ASTUnit.cpp

Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -400,6 +400,7 @@
   llvm::DenseMap CompletionTypes;
   CodeCompletionContext CCContext(CodeCompletionContext::CCC_TopLevel);
 
+  std::vector CachedCompletionResults;
   for (auto &R : Results) {
 switch (R.Kind) {
 case Result::RK_Declaration: {
@@ -518,11 +519,15 @@
   }
 
   // Save the current top-level hash value.
-  CompletionCacheTopLevelHashValue = CurrentTopLevelHashValue;
+  StringRef MainFilePath = getMainFileName();
+  std::lock_guard Lock(CacheMutex);
+  ASTUnitCacheMap[MainFilePath].CachedCompletionResults = std::move(CachedCompletionResults);
+  ASTUnitCacheMap[MainFilePath].CompletionCacheTopLevelHashValue = CurrentTopLevelHashValue;
 }
 
 void ASTUnit::ClearCachedCompletionResults() {
-  CachedCompletionResults.clear();
+  std::lock_guard Lock(CacheMutex);
+  ASTUnitCacheMap[getMainFileName()].CachedCompletionResults.clear();
   CachedCompletionTypes.clear();
   CachedCompletionAllocator = nullptr;
 }
@@ -1430,7 +1435,7 @@
   // entities the last time we rebuilt the preamble, clear out the completion
   // cache.
   if (NewPreambleTopLevelHashValue != PreambleTopLevelHashValue) {
-CompletionCacheTopLevelHashValue = 0;
+ASTUnitCacheMap[MainFilePath].CompletionCacheTopLevelHashValue = 0;
 PreambleTopLevelHashValue = NewPreambleTopLevelHashValue;
   }
 
@@ -1891,11 +1896,16 @@
   bool Result =
   Parse(std::move(PCHContainerOps), std::move(OverrideMainBuffer), VFS);
 
-  // If we're caching global code-completion results, and the top-level
-  // declarations have changed, clear out the code-completion cache.
-  if (!Result && ShouldCacheCodeCompletionResults &&
-  CurrentTopLevelHashValue != CompletionCacheTopLevelHashValue)
-CacheCodeCompletionResults();
+  {
+std::lock_guard Lock(CacheMutex);
+// If we're caching global code-completion results, and the top-level
+// declarations have changed, clear out the code-completion cache.
+if (!Result && ShouldCacheCodeCompletionResults &&
+CurrentTopLevelHashValue !=
+ASTUnitCacheMap[MainFilePath].CompletionCacheTopLevelHashValue) {
+  CacheCodeCompletionResults();
+}
+  }
 
   // We now need to clear out the completion info related to this translation
   // unit; it'll be recreated if necessary.
@@ -2077,70 +2087,72 @@
   llvm::StringSet HiddenNames;
   using Result = CodeCompletionResult;
   SmallVector AllResults;
-  for (ASTUnit::cached_completion_iterator
-C = AST.cached_completion_begin(),
- CEnd = AST.cached_completion_end();
-   C != CEnd; ++C) {
-// If the context we are in matches any of the contexts we are
-// interested in, we'll add this result.
-if ((C->ShowInContexts & InContexts) == 0)
-  continue;
 
-// If we haven't added any results previously, do so now.
-if (!AddedResult) {
-  CalculateHiddenNames(Context, Results, NumResults, S.Context,
-   HiddenNames);
-  AllResults.insert(AllResults.end(), Results, Results + NumResults);
-  AddedResult = true;
-}
+  {
+std::lock_guard Lock(ASTUnit::getCacheMutex());
+for (ASTUnit::cached_completion_iterator C = AST.cached_completion_begin(),
+ CEnd = AST.cached_completion_end();
+ C != CEnd; ++C) {
+  // If the context we are in matches any of the contexts we are
+  // interested in, we'll add this result.
+  if ((C->ShowInContexts & InContexts) == 0)
+continue;
 
-// Determine whether this global completion result is hidden by a local
-// completion result. If so, skip it.
-if (C->Kind != CXCursor_MacroDefinition &&
-HiddenNames.count(C->Completion->getTypedText()))
-  continue;
+  // If we haven't added any results previously, do so now.
+  if (!AddedResult) {
+CalculateHiddenNames(Context, Results, NumResults, S.Context,
+ HiddenNames);
+AllResults.insert(AllResults.end(), Results, Results + NumResults);
+AddedResult = true;
+  }
+
+  // Determine whether this global completion result is hidden by a local
+  // completion result. If so, skip it.
+  if (C->Kind != CXCursor_MacroDefinition &&
+  HiddenNames.count(C->Completion->getTypedText()))
+continue;
 
-// Adjust priority based on similar type classes.
-unsigned Priority = C->Priority;
-CodeCompletionString *Completion = C->Completion;
-if 

[PATCH] D33537: [clang-tidy] Exception Escape Checker

2018-06-19 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added inline comments.



Comment at: test/clang-tidy/bugprone-exception-escape.cpp:178
+void indirect_implicit() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in 
function 'indirect_implicit' which should not throw exceptions
+  implicit_int_thrower();

dberris wrote:
> Can we make the warning more accurate here? Something like:
> 
> ```
> warning: call to 'implicit_int_thrower' may throw an exception and propagate 
> through noexcept function 'indirect_implicit'
> ```
> 
> It would be helpful to diagnose the point at which the exception may be 
> thrown from within the function (if it's an operator, a function call, etc.) 
> that doesn't have exceptions handled. If you can highlight not just the line 
> number but the actual expression in which the uncaught exception may 
> propagate, it would make this warning much better.
> 
> If you think it's worth it (or if it's feasible), having a FixIt hint to wrap 
> a block of statements where exceptions may propagate in a `try { ... } catch 
> (...) { ... }` block would turn this warning from a good warning, to a great 
> warning -- potentially something that could be automatically applied by a 
> tool as well.
I think this is a good future improvement. However, I tried to make the first 
version as small as possible, and then enhance it incrementally. Even the 
current code is too big for a Clang-Tidy check.


https://reviews.llvm.org/D33537



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


[PATCH] D48285: [analyzer]{UninitializedObjectChecker] Added "NotesAsWarnings" flag

2018-06-19 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

In https://reviews.llvm.org/D48285#1135480, @xazax.hun wrote:

> I wonder if this could be done when plist is emitted generally, independent 
> of any checks.


Well, there's `-analyzer-config notes-as-events=true`. By the time plist files 
are generated, every warning is just regarded as an event (as far as I know).




Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:696
 void ento::registerUninitializedObjectChecker(CheckerManager &Mgr) {
   auto Chk = Mgr.registerChecker();
   Chk->IsPedantic = Mgr.getAnalyzerOptions().getBooleanOption(

NoQ wrote:
> george.karpenkov wrote:
> > registerChecker passes through arguments to the constructor. Could we use 
> > that instead of mutable fields?
> Really? Yay. I never noticed that. I think currently all checkers that need 
> options use mutable fields for that purpose, and everybody thought it was 
> intended to work this way.
> 
> I'm not super worried about fields being mutable because all checker 
> callbacks are `const` (so you're still protected from mutating them in all of 
> your code), but that'd definitely make the code look better.
Well, I didn't really find that to be the case. Even if it was, 
`getBooleanOption(StringRef, /*DefaultVal*/ bool, const ento::CheckerBase *);` 
depends on the constructed checker, so I don't think I can pull this off.

There actually is a way to get boolean options without having to pass the 
checker as an argument, but then it wouldn't be a checker specific option:
`-analyzer-config Pedantic=true`
instead of
`-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true`.


https://reviews.llvm.org/D48285



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


[PATCH] D48285: [analyzer]{UninitializedObjectChecker] Added "NotesAsWarnings" flag

2018-06-19 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 151866.
Szelethus added a comment.

In https://reviews.llvm.org/D48285#1136059, @NoQ wrote:

> Also, great, and can i has tests?^^
>
> Like a simple code snippet with two `// RUN: ... -analyzer-output=text` lines 
> and different expected-warnings/notes under `#if`s.


I intended to, but forgot `git add`. Whoops. I didn't find a satisfying way to 
add it to the existing tests without surrounding the entire file with `#if`, so 
I added a new test file instead.


https://reviews.llvm.org/D48285

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp

Index: test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp
===
--- /dev/null
+++ test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject -analyzer-config alpha.cplusplus.UninitializedObject:NotesAsWarnings=true -std=c++11 -verify %s
+
+class NotesAsWarningsTest {
+  int a;
+  int b;
+  int dontGetFilteredByNonPedanticMode = 0;
+
+public:
+  NotesAsWarningsTest() {} // expected-warning{{uninitialized field 'this->a'}}
+  // expected-warning@-1{{uninitialized field 'this->b'}}
+};
+
+void fNotesAsWarningsTest() {
+  NotesAsWarningsTest();
+}
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -10,10 +10,19 @@
 // This file defines a checker that reports uninitialized fields in objects
 // created after a constructor call.
 //
-// This checker has an option "Pedantic" (boolean). If its not set or is set to
-// false, the checker won't emit warnings for objects that don't have at least
-// one initialized field. This may be set with
-// `-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true`.
+// This checker has two options:
+//   - "Pedantic" (boolean). If its not set or is set to false, the checker
+// won't emit warnings for objects that don't have at least one initialized
+// field. This may be set with
+//
+//  `-analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true`.
+//
+//   - "NotesAsWarnings" (boolean). If set to true, the checker will emit a
+// warning for each uninitalized field, as opposed to emitting one warning
+// per constructor call, and listing the uninitialized fields that belongs
+// to it in notes. Defaults to false.
+//
+//  `-analyzer-config alpha.cplusplus.UninitializedObject:NotesAsWarnings=true`.
 //
 //===--===//
 
@@ -32,7 +41,9 @@
   std::unique_ptr BT_uninitField;
 
 public:
-  bool IsPedantic; // Will be initialized when registering the checker.
+  // These fields will be initialized when registering the checker.
+  bool IsPedantic;
+  bool ShouldConvertNotesToWarnings;
 
   UninitializedObjectChecker()
   : BT_uninitField(new BuiltinBug(this, "Uninitialized fields")) {}
@@ -216,6 +227,9 @@
   return T->isBuiltinType() || T->isEnumeralType();
 }
 
+/// Constructs a note message for a given FieldChainInfo object.
+void printNoteMessage(llvm::raw_ostream &Out, const FieldChainInfo &Chain);
+
 } // end of anonymous namespace
 
 //===--===//
@@ -264,6 +278,23 @@
 LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
 CallSite, Context.getSourceManager(), Node->getLocationContext());
 
+  // For Plist consumers that don't support notes just yet, we'll convert notes
+  // to warnings.
+  if (ShouldConvertNotesToWarnings) {
+for (const auto &Chain : UninitFields) {
+  SmallString<100> WarningBuf;
+  llvm::raw_svector_ostream WarningOS(WarningBuf);
+
+  printNoteMessage(WarningOS, Chain);
+
+  auto Report = llvm::make_unique(
+  *BT_uninitField, WarningOS.str(), Node, LocUsedForUniqueing,
+  Node->getLocationContext()->getDecl());
+  Context.emitReport(std::move(Report));
+}
+return;
+  }
+
   SmallString<100> WarningBuf;
   llvm::raw_svector_ostream WarningOS(WarningBuf);
   WarningOS << UninitFields.size() << " uninitialized field"
@@ -274,29 +305,16 @@
   *BT_uninitField, WarningOS.str(), Node, LocUsedForUniqueing,
   Node->getLocationContext()->getDecl());
 
-  // TODO: As of now, one warning is emitted per constructor call, and the
-  // uninitialized fields are listed in notes. Until there's a better support
-  // for notes avaible, a note-less version of this checker should be
-  // implemented.
-  for (const auto &FieldChain : UninitFields) {
+  for (const auto &Chain : UninitFields) {
 SmallString<200> NoteBuf;
 llvm::raw_svector_ostream NoteOS(NoteBuf);
 
-if (FieldC

[PATCH] D48314: [Frontend] Cache preamble-related data

2018-06-19 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: ilya-biryukov, arphaman, erikjv.

In case two translation units are created for the same file - reuse preamble 
data to reduce memory and save time on extra preamble generation.


https://reviews.llvm.org/D48314

Files:
  include/clang/Frontend/ASTUnit.h
  lib/Frontend/ASTUnit.cpp

Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -214,6 +214,9 @@
   return llvm::MemoryBuffer::getMemBufferCopy(Buffer->getBuffer(), FilePath);
 }
 
+std::recursive_mutex ASTUnit::CacheMutex;
+llvm::StringMap ASTUnit::ASTUnitCacheMap;
+
 struct ASTUnit::ASTWriterData {
   SmallString<128> Buffer;
   llvm::BitstreamWriter Stream;
@@ -253,6 +256,16 @@
 getDiagnostics().getClient()->EndSourceFile();
   }
 
+  std::lock_guard Lock(CacheMutex);
+  StringRef MainFilePath = getMainFileName();
+  if (ASTUnitCacheMap.find(MainFilePath) == ASTUnitCacheMap.end())
+return;
+
+  if (ASTUnitCacheMap[MainFilePath].getRefCount() == 1)
+ASTUnitCacheMap.erase(MainFilePath);
+  else
+ASTUnitCacheMap[MainFilePath].Release();
+
   clearFileLevelDecls();
 
   // Free the buffers associated with remapped files. We are required to
@@ -264,13 +277,18 @@
 for (const auto &RB : PPOpts.RemappedFileBuffers)
   delete RB.second;
   }
-
-  ClearCachedCompletionResults();
-
+  
   if (getenv("LIBCLANG_OBJTRACKING"))
 fprintf(stderr, "--- %u translation units\n", --ActiveASTUnitObjects);
 }
 
+void ASTUnit::initCache() {
+  std::lock_guard Lock(CacheMutex);
+  StringRef MainFilePath = getMainFileName();
+
+  ASTUnitCacheMap[MainFilePath].Retain();
+}
+
 void ASTUnit::setPreprocessor(std::shared_ptr PP) {
   this->PP = std::move(PP);
 }
@@ -841,6 +859,8 @@
   // Tell the diagnostic client that we have started a source file.
   AST->getDiagnostics().getClient()->BeginSourceFile(PP.getLangOpts(), &PP);
 
+  AST->initCache();
+
   return AST;
 }
 
@@ -1079,7 +1099,10 @@
 return true;
 
   auto CCInvocation = std::make_shared(*Invocation);
+  auto MainFilePath = getMainFileName();
   if (OverrideMainBuffer) {
+std::lock_guard Lock(CacheMutex);
+auto &Preamble = ASTUnitCacheMap[MainFilePath].Preamble;
 assert(Preamble &&
"No preamble was built, but OverrideMainBuffer is not null");
 IntrusiveRefCntPtr OldVFS = VFS;
@@ -1147,7 +1170,8 @@
 UserFilesAreVolatile);
   if (!OverrideMainBuffer) {
 checkAndRemoveNonDriverDiags(StoredDiagnostics);
-TopLevelDeclsInPreamble.clear();
+std::lock_guard Lock(CacheMutex);
+ASTUnitCacheMap[MainFilePath].TopLevelDeclsInPreamble.clear();
   }
 
   // Create a file manager object to provide access to and cache the filesystem.
@@ -1180,11 +1204,16 @@
   if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
 goto error;
 
-  if (SavedMainFileBuffer)
-TranslateStoredDiagnostics(getFileManager(), getSourceManager(),
-   PreambleDiagnostics, StoredDiagnostics);
-  else
-PreambleSrcLocCache.clear();
+  {
+std::lock_guard Lock(CacheMutex);
+if (SavedMainFileBuffer) {
+  TranslateStoredDiagnostics(
+  getFileManager(), getSourceManager(),
+  ASTUnitCacheMap[MainFilePath].PreambleDiagnostics, StoredDiagnostics);
+} else {
+  ASTUnitCacheMap[MainFilePath].PreambleSrcLocCache.clear();
+}
+  }
 
   if (!Act->Execute())
 goto error;
@@ -1295,38 +1324,41 @@
   if (!Bounds.Size)
 return nullptr;
 
-  if (Preamble) {
-if (Preamble->CanReuse(PreambleInvocationIn, MainFileBuffer.get(), Bounds,
-   VFS.get())) {
-  // Okay! We can re-use the precompiled preamble.
-
-  // Set the state of the diagnostic object to mimic its state
-  // after parsing the preamble.
-  getDiagnostics().Reset();
-  ProcessWarningOptions(getDiagnostics(),
-PreambleInvocationIn.getDiagnosticOpts());
-  getDiagnostics().setNumWarnings(NumWarningsInPreamble);
-
-  PreambleRebuildCounter = 1;
-  return MainFileBuffer;
-} else {
-  Preamble.reset();
-  PreambleDiagnostics.clear();
-  TopLevelDeclsInPreamble.clear();
-  PreambleSrcLocCache.clear();
-  PreambleRebuildCounter = 1;
+  {
+std::lock_guard Lock(CacheMutex);
+auto &Preamble = ASTUnitCacheMap[MainFilePath].Preamble;
+if (Preamble) {
+  if (Preamble->CanReuse(PreambleInvocationIn, MainFileBuffer.get(), Bounds,
+ VFS.get())) {
+// Okay! We can re-use the precompiled preamble.
+
+// Set the state of the diagnostic object to mimic its state
+// after parsing the preamble.
+getDiagnostics().Reset();
+ProcessWarningOptions(getDiagnostics(),
+  PreambleInvocationIn.getDiagnosticOpts());
+getDiagnostics().setNumWarnings(NumWarnin

[PATCH] D48290: [clangd] Use workspace root path as hint path for resolving URIs in workspace/symbol

2018-06-19 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/ClangdServer.cpp:119
+  auto FS = FSProvider.getFileSystem();
+  auto Status = FS->status(RootPath);
+  if (!Status)

why validate it?



Comment at: clangd/FindSymbols.h:30
 /// \p Limit limits the number of results returned (0 means no limit).
+/// \p RootPath Root path of the workspace. This is used as the hint path when
+/// resolving URIs.

Change to HintPath? There's no reason to couple this code to the fact that it's 
the workspace root in clangdserver.



Comment at: clangd/FindSymbols.h:30
 /// \p Limit limits the number of results returned (0 means no limit).
+/// \p RootPath Root path of the workspace. This is used as the hint path when
+/// resolving URIs.

sammccall wrote:
> Change to HintPath? There's no reason to couple this code to the fact that 
> it's the workspace root in clangdserver.
you sometimes pass "" here, so we should document the semantics of that



Comment at: unittests/clangd/TestFS.cpp:70
+/// unittest: is a scheme that refers to files relative to testRoot().
+/// URI body is relative path to testRoot().
 class TestScheme : public URIScheme {

is a path relative to testRoot()



Comment at: unittests/clangd/TestFS.cpp:93
 return URI(Scheme, /*Authority=*/"",
-   llvm::sys::path::convert_to_slash(Body));
+   StringRef(llvm::sys::path::convert_to_slash(Body)).ltrim('/'));
   }

why this change?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48290



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


[PATCH] D48188: [SPIR] Prevent SPIR targets from using half conversion intrinsics

2018-06-19 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer accepted this revision.
SjoerdMeijer added a comment.
This revision is now accepted and ready to land.

Looks OK to me.




Comment at: test/CodeGen/spir-half-type.cpp:89
+
+_Float16 fadd() {
+  _Float16 a = 1.0f16;

Nit: let one of these functions take a _Float16 function argument?


https://reviews.llvm.org/D48188



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


[PATCH] D48266: [Driver] Add -fno-digraphs

2018-06-19 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes updated this revision to Diff 151858.
jtbandes marked an inline comment as done.
jtbandes added a comment.

Added an error when language standard doesn't support digraphs.

Still keeping `-fdigraphs` as a cc1 option because then I can distinguish 
explicitly-enabled/disabled from the absence of a flag. I can also check 
whether digraphs are supported using the LangStandard/LangOpts in the 
CompilerInstance rather than hard-coding an incompatibility with -std=c89.


Repository:
  rC Clang

https://reviews.llvm.org/D48266

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Lexer/digraph.c

Index: test/Lexer/digraph.c
===
--- test/Lexer/digraph.c
+++ test/Lexer/digraph.c
@@ -1,6 +1,17 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -DDIGRAPHS=1 -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -DDIGRAPHS=1 -fno-digraphs -fdigraphs -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -fno-digraphs -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -fdigraphs -fno-digraphs -fsyntax-only -verify -ffreestanding %s
+
+// RUN: not %clang_cc1 -std=c89 -fdigraphs -fsyntax-only -ffreestanding %s 2>&1 | FileCheck -check-prefix=CHECK1 %s
+// RUN: not %clang_cc1 -std=c89 -fno-digraphs -fsyntax-only -ffreestanding %s 2>&1 | FileCheck -check-prefix=CHECK2 %s
+
+// CHECK1: error: invalid argument '-fdigraphs' not allowed with '-std=c89'
+// CHECK2: error: invalid argument '-fno-digraphs' not allowed with '-std=c89'
 
+#if DIGRAPHS
+
+// expected-no-diagnostics
 %:include 
 
 %:ifndef BUFSIZE
@@ -14,3 +25,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// expected-error@+1 {{expected ')'}} expected-note@+1{{to match this '('}}
+void copy(char d<::>);
+
+// expected-error@+1 {{expected function body}}
+void copy() <% %>
+
+#endif
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2080,6 +2080,7 @@
   DiagnosticsEngine &Diags) {
   // FIXME: Cleanup per-file based stuff.
   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
+  const Arg *LangStdArg;
   if (const Arg *A = Args.getLastArg(OPT_std_EQ)) {
 LangStd = llvm::StringSwitch(A->getValue())
 #define LANGSTANDARD(id, name, lang, desc, features) \
@@ -2117,6 +2118,7 @@
 } else {
   // Valid standard, check to make sure language and standard are
   // compatible.
+  LangStdArg = A;
   const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
   if (!IsInputCompatibleWithStandard(IK, Std)) {
 Diags.Report(diag::err_drv_argument_not_allowed_with)
@@ -2147,8 +2149,10 @@
   Diags.Report(diag::err_drv_invalid_value)
 << A->getAsString(Args) << A->getValue();
 }
-else
+else {
   LangStd = OpenCLLangStd;
+  LangStdArg = A;
+}
   }
 
   Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
@@ -2174,6 +2178,16 @@
   Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,
   Opts.GNUKeywords);
 
+  if (const Arg* A = Args.getLastArg(OPT_fdigraphs, OPT_fno_digraphs)) {
+// Prevent the user from enabling or disabling digraphs when they are not supported.
+if (!Opts.Digraphs && LangStdArg)
+  Diags.Report(diag::err_drv_argument_not_allowed_with)
+  << A->getSpelling() << LangStdArg->getAsString(Args);
+
+if (A->getOption().matches(OPT_fno_digraphs))
+  Opts.Digraphs = 0;
+  }
+
   if (Args.hasArg(OPT_fno_operator_names))
 Opts.CXXOperatorNames = 0;
 
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3970,6 +3970,7 @@
   // Forward -f (flag) options which we can pass directly.
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
+  Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1334,6 +1334,10 @@
 def fno_diagnostics_show_option : Flag<["-"], "fno-diagnostics-show-option">, Group;
 def fno_diagnostics_show_note_include_stack : Flag<["-"], "fno-diagnostics-show-note-include-stack">,
 Flags<[CC1Option]>, Group;
+def fdigraphs : Flag<["-